|
1 | | -# G4 Integration Instructions (embed this at the top of your Copilot Chat context) |
2 | | - |
3 | | -Enforce G4 flow: session → get_tools → find_tool → [DOM if needed] → build → attach_session → call. |
4 | | - |
5 | | -Follow these steps **in order**—do not skip or reorder: |
6 | | - |
7 | | -1. **Ensure a session - HIGH PRIORITY - MUST FOLLOW all steps** |
8 | | - • Prompt the user for `driver_binaries` (default: `http://localhost:4444/wd/hub`) and `driver` (default: `ChromeDriver`). |
9 | | - • Call the `start_g4_session` tool with those values. |
10 | | - • Save the returned `session` ID. |
11 | | - |
12 | | -2. **Discover your tool** |
13 | | - - Call the **get_tools** tool (no arguments). |
14 | | - - From its response, select the tool name that best matches the user’s action. |
15 | | - |
16 | | -3. **Fetch its schema** |
17 | | - - Call the **find_tool** tool with that exact tool name. |
18 | | - - Parse its JSON response to extract the `inputSchema`. |
19 | | - |
20 | | -4. **Handle element-interaction tools** |
21 | | - If your selected tool requires interacting with page elements: |
22 | | - a. Call the **get_application_dom** tool (no arguments). |
23 | | - b. Parse its response and **extract the locator**(s) needed for your action. |
24 | | - c. Insert the locator value into your payload under the appropriate field name. |
25 | | - |
26 | | -5. **Build your request payload** |
27 | | - - From the schema in Step 3, identify **all required** properties. |
28 | | - - If any required field is missing, **prompt the user** for its value (including expected type). |
29 | | - - Construct a JSON object that: |
30 | | - • Includes **every** required field (with user-provided or default values) |
31 | | - • Converts **all** field names to snake_case |
32 | | - |
33 | | -6. **Attach your session** |
34 | | - - Add the saved `session` ID into your payload under the `session` field. |
35 | | - |
36 | | -7. **Invoke the tool** |
37 | | - - Call the `tools/call` endpoint (or invoke the corresponding tool) with your completed JSON body. |
| 1 | +* **Token:** Always read G4_API_KEY from project-root .env (ask user if missing) and cache as token. |
| 2 | +* **Open AI:** Always read OPENAI_API_KEY from project-root .env (ask user if missing) and cache as OPENAI_API_KEY. |
| 3 | +* **Open AI:** Always read OPENAI_URI from project-root .env (ask user if missing) and cache as OPENAI_URI. |
| 4 | +* **Open AI:** Always read OPENAI_MODEL from project-root .env (ask user if missing) and cache as OPENAI_MODEL. |
| 5 | +* **Session:** If no driver_session, call start_g4_session with .env defaults: driver=ENV:WEB_DRIVER, driver_binaries=ENV:WEB_DRIVER_REPOSITORY, token=ENV:G4_API_KEY; save the returned session id. |
| 6 | + |
| 7 | +* **Sequence (every call):** |
| 8 | + |
| 9 | + 1. get_tools |
| 10 | + 2. find_tool **must include** tool_name |
| 11 | + 3. (get_locator|get_application_dom if needed) |
| 12 | + 4. build inputs per schema **must ask user** for missing mandatory fields |
| 13 | + 5. add token |
| 14 | + 6. add driver_session (if not start_g4_session) |
| 15 | + 7. call |
| 16 | + |
| 17 | +* **Required params:** For all tools, inputs **must include** token. |
| 18 | +* **Required params:** For all tools **except** start_g4_session, inputs **must include** driver_session. |
| 19 | +* If the schema from find_tool does **not** define these fields, add them. |
| 20 | +* **DOM discipline (page tools): For any tool that interacts with a page/UI:**: |
| 21 | + |
| 22 | + 1. Call get_locator with { intent, action, hints, constraints, driver_session, token }. |
| 23 | + 2. Use only the returned primary locator (or an explicit provided fallback). Never guess. |
| 24 | + 3. **If OpenAI is available** (`OPENAI_API_KEY`, `OPENAI_URI`, `OPENAI_MODEL` exist): |
| 25 | + → Call `get_locator` and use **only** its returned primary locator. |
| 26 | + → Do **not** call `get_application_dom`. |
| 27 | + 4. **If OpenAI is NOT available**: |
| 28 | + → Do **not** call `get_locator`. |
| 29 | + → Call `get_application_dom` `get_application_dom`** and use its returned DOM—following the **`policy`** field—to analyze the page and **deterministically derive the locator** (no guessing). |
| 30 | + 5. **If no valid locator can be derived** (ambiguous/missing): |
| 31 | + → **Ask the user** to provide a locator (type in PascalCase + value) or a minimal DOM snippet. |
| 32 | + |
| 33 | +* When calling `start_g4_rule`, if the rule definition includes `on_element` |
| 34 | + |
| 35 | + 1. You **must also include** the `locator` field. |
| 36 | + 2. `locator` **must explicitly declare the locator type**, not just the value. |
| 37 | + 3. Locator type names **must be PascalCase** (e.g. `Xpath`, `CssSelector`, `Id`, `Name`, `ClassName`, `AccessibilityId`). |
| 38 | + * **DO NOT** `XPath`, `css`, `cssSelector` |
| 39 | + * **DO** `Xpath`, `CssSelector` |
| 40 | + 4. If `locator` is missing, invalid, or ambiguously cased → **ask the user**. Do **not** guess. |
| 41 | + 5. If the locator was produced by `get_locator` or derived from `get_application_dom`, **preserve the locator type exactly** (PascalCase). |
| 42 | + |
| 43 | +* **Hard stop**: A `start_g4_rule` call that contains `on_element` **without** a valid `locator` is **invalid** and must **not** be executed. |
| 44 | +* **Self-check before sending:** Verify: tool exists, inputs match schema, driver_session+token present (if required). If any check fails **fix or ask**—don’t call. |
| 45 | +* **No guessing:** Never invent tool names, parameters, or locators. If policy/schema/DOM info is missing or ambiguous, ask the user. |
0 commit comments