@capagents/forgeqe 3.1.2 → 3.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (170) hide show
  1. package/HOW_TO_USE.md +5003 -2077
  2. package/README.md +155 -449
  3. package/dist/docs-site/docs/app-theme.css +30 -9
  4. package/dist/docs-site/docs/architecture/index.html +45 -515
  5. package/dist/docs-site/docs/architecture-reference/index.html +1781 -0
  6. package/dist/docs-site/docs/area-api/index.html +257 -116
  7. package/dist/docs-site/docs/area-automated-tests/index.html +1229 -419
  8. package/dist/docs-site/docs/area-browser/index.html +167 -125
  9. package/dist/docs-site/docs/area-data/index.html +178 -188
  10. package/dist/docs-site/docs/area-desktop/index.html +329 -282
  11. package/dist/docs-site/docs/area-mobile/index.html +138 -86
  12. package/dist/docs-site/docs/area-operations/index.html +567 -393
  13. package/dist/docs-site/docs/area-pull-requests/index.html +114 -32
  14. package/dist/docs-site/docs/area-quality/index.html +111 -49
  15. package/dist/docs-site/docs/area-release/index.html +180 -65
  16. package/dist/docs-site/docs/area-setup/index.html +742 -339
  17. package/dist/docs-site/docs/area-systems/index.html +32 -48
  18. package/dist/docs-site/docs/area-test-cases/index.html +387 -154
  19. package/dist/docs-site/docs/containers/index.html +87 -101
  20. package/dist/docs-site/docs/cost-architecture/index.html +4 -3
  21. package/dist/docs-site/docs/custom-agents-first-run/index.html +108 -50
  22. package/dist/docs-site/docs/desktop/index.html +277 -297
  23. package/dist/docs-site/docs/desktop-ci/index.html +15 -5
  24. package/dist/docs-site/docs/docs-tabs.js +56 -0
  25. package/dist/docs-site/docs/evidence/index.html +50 -49
  26. package/dist/docs-site/docs/feature-test-prompts/index.html +34 -24
  27. package/dist/docs-site/docs/get-started/index.html +464 -168
  28. package/dist/docs-site/docs/graphify/index.html +8 -7
  29. package/dist/docs-site/docs/guardrails/index.html +20 -4
  30. package/dist/docs-site/docs/index.html +4 -3
  31. package/dist/docs-site/docs/mobile/index.html +96 -76
  32. package/dist/docs-site/docs/model-routing/index.html +44 -18
  33. package/dist/docs-site/docs/overview/index.html +23 -7
  34. package/dist/docs-site/docs/product-graph/index.html +13 -12
  35. package/dist/docs-site/docs/product-knowledge/index.html +16 -5
  36. package/dist/docs-site/docs/product-views/index.html +7 -6
  37. package/dist/docs-site/docs/reference/index.html +95 -65
  38. package/dist/docs-site/docs/search.js +1 -1
  39. package/dist/docs-site/docs/using/index.html +444 -126
  40. package/dist/docs-site/docs/web-app/index.html +54 -51
  41. package/dist/forgeqe.js +1822 -1822
  42. package/dist/web/assets/Agent-3pV8Rwap.js +8 -0
  43. package/dist/web/assets/AgentWork-DAnmH0My.js +2 -0
  44. package/dist/web/assets/ApiTests-DW4MRFzG.js +10 -0
  45. package/dist/web/assets/Browse-Bd0ZZfc2.js +1 -0
  46. package/dist/web/assets/Chat-DnBUm_97.js +3 -0
  47. package/dist/web/assets/CommandPalette-B1O9aDTk.js +1 -0
  48. package/dist/web/assets/Compare-1v7_ca7z.js +1 -0
  49. package/dist/web/assets/Cost-CWrc4McH.js +1 -0
  50. package/dist/web/assets/Data-rWSiG4Cq.js +6 -0
  51. package/dist/web/assets/Desktop-3x6EQqos.js +1 -0
  52. package/dist/web/assets/DesktopReview-cSA10Rm3.js +1 -0
  53. package/dist/web/assets/Evidence-CKy3o7cw.js +1 -0
  54. package/dist/web/assets/{Explore-ObkEpUyS.js → Explore-CMAxWE_8.js} +2 -2
  55. package/dist/web/assets/Features-haQchkhA.js +1 -0
  56. package/dist/web/assets/{Flags-0-RniPJm.js → Flags-BaQjYi_t.js} +2 -2
  57. package/dist/web/assets/Flaky-DUuC0qTn.js +1 -0
  58. package/dist/web/assets/Impact-CP0H8ygo.js +3 -0
  59. package/dist/web/assets/Jobs-cYxoYd3i.js +5 -0
  60. package/dist/web/assets/KindPage-DWW8gN5_.js +6 -0
  61. package/dist/web/assets/Migration-Bsm7WU1d.js +2 -0
  62. package/dist/web/assets/PageAgent-c95zT2PJ.js +1 -0
  63. package/dist/web/assets/Product-BQSiR28a.js +7 -0
  64. package/dist/web/assets/Production-CAv0Vtoy.js +1 -0
  65. package/dist/web/assets/Quality-aQPaPYQc.js +1 -0
  66. package/dist/web/assets/Readiness-CkknP87n.js +1 -0
  67. package/dist/web/assets/Record-09IsC9U-.js +1 -0
  68. package/dist/web/assets/Regression-BL4MfN47.js +5 -0
  69. package/dist/web/assets/RelationGraph-Dg4fqt7l.js +1 -0
  70. package/dist/web/assets/Reports-CMV1l-iS.js +2 -0
  71. package/dist/web/assets/Response-DTBFBeKB.js +9 -0
  72. package/dist/web/assets/Responsive-DBRQ9FUO.js +3 -0
  73. package/dist/web/assets/RunDiff-CMDrnsA3.js +1 -0
  74. package/dist/web/assets/Runs-Dkeu6_vZ.js +2 -0
  75. package/dist/web/assets/Settings-KjKm8h-_.js +21 -0
  76. package/dist/web/assets/{Steps-D-YG0eJy.js → Steps-HYHK9psI.js} +1 -1
  77. package/dist/web/assets/TestCases-Cv6-OSv0.js +1 -0
  78. package/dist/web/assets/TestData-DbEfNlUE.js +2 -0
  79. package/dist/web/assets/TestDebt-DzHQIU4X.js +1 -0
  80. package/dist/web/assets/TestManagement-BgRTGHMT.js +1 -0
  81. package/dist/web/assets/Tosca-DZpHAtnH.js +3 -0
  82. package/dist/web/assets/WhatsNew-jp0c4WSV.js +1 -0
  83. package/dist/web/assets/coverage-BB9BLjGz.js +5 -0
  84. package/dist/web/assets/{dataParts-DbeCj9ga.js → dataParts-DEPK4eQE.js} +2 -2
  85. package/dist/web/assets/{diff-BStuTmsN.js → diff-CcNwLCX6.js} +1 -1
  86. package/dist/web/assets/{families-BBFFrUlo.js → families-gkpkloLT.js} +1 -1
  87. package/dist/web/assets/filters-C7phIFfd.js +1 -0
  88. package/dist/web/assets/fold-i73P-EDV.js +1 -0
  89. package/dist/web/assets/head-BtTqyLlj.js +1 -0
  90. package/dist/web/assets/{highlight-BcFZIf59.js → highlight-DZI39CzZ.js} +1 -1
  91. package/dist/web/assets/index-ClFOh63x.css +2 -0
  92. package/dist/web/assets/index-YGWJEkAT.js +64 -0
  93. package/dist/web/assets/input-C2vQ9O3a.js +1 -0
  94. package/dist/web/assets/logos-BmbNTDu2.js +1 -0
  95. package/dist/web/assets/palette-XFlqvgZl.js +1 -0
  96. package/dist/web/assets/{paletteCommands-Co-RlQ8q.js → paletteCommands-DsbD2ASU.js} +1 -1
  97. package/dist/web/assets/parts-DEVx2Sea.js +1 -0
  98. package/dist/web/assets/productParts-Bi-XjszL.js +1 -0
  99. package/dist/web/assets/qualityParts-Dbu01g7G.js +1 -0
  100. package/dist/web/assets/{recordTest-Cez2sDJO.js → recordTest--Wr40QdN.js} +1 -1
  101. package/dist/web/assets/route-Dg53WdFu.js +1 -0
  102. package/dist/web/index.html +6 -7
  103. package/docs/ARCHITECTURE.md +50 -563
  104. package/docs/ARCHITECTURE_REFERENCE.md +1484 -0
  105. package/docs/CONTAINERS.md +87 -87
  106. package/docs/CUSTOM_AGENTS_FIRST_RUN.md +125 -43
  107. package/docs/DESKTOP-CI.md +18 -3
  108. package/docs/DESKTOP.md +298 -297
  109. package/docs/MOBILE.md +103 -71
  110. package/docs/MODEL_ROUTING.md +48 -15
  111. package/docs/WEB_APP.md +49 -44
  112. package/docs/feature-test-prompts.md +29 -16
  113. package/docs/user-guide.html +5263 -2453
  114. package/guardrails/README.md +22 -2
  115. package/knowledge/README.md +15 -2
  116. package/package.json +1 -1
  117. package/prompts/brain.md +1 -0
  118. package/py/forgeqe_engine/recordsession.py +100 -24
  119. package/dist/web/assets/Agent-CPhmZdFX.js +0 -8
  120. package/dist/web/assets/AgentWork-BXdN9xgi.js +0 -2
  121. package/dist/web/assets/ApiTests-Do3xLjfB.js +0 -10
  122. package/dist/web/assets/Browse-WVkJT6Bs.js +0 -2
  123. package/dist/web/assets/Chat-CDc9UcQX.js +0 -3
  124. package/dist/web/assets/CommandPalette-BAZm62lV.js +0 -1
  125. package/dist/web/assets/Compare-Br6n9T9L.js +0 -1
  126. package/dist/web/assets/Cost-BBUyBu3Y.js +0 -1
  127. package/dist/web/assets/Data-Ch2DPEWp.js +0 -6
  128. package/dist/web/assets/Desktop-Qzoq-cQv.js +0 -1
  129. package/dist/web/assets/DesktopReview-CF_jQYAM.js +0 -1
  130. package/dist/web/assets/Evidence-C72Lj5_Q.js +0 -1
  131. package/dist/web/assets/Features-CQzNo_WP.js +0 -1
  132. package/dist/web/assets/Flaky-BPJvNLCA.js +0 -1
  133. package/dist/web/assets/Impact-CfccsL_k.js +0 -3
  134. package/dist/web/assets/Jobs-T6m4zhDy.js +0 -5
  135. package/dist/web/assets/KindPage-BDUvWe2p.js +0 -6
  136. package/dist/web/assets/Migration-Dqeh4x5u.js +0 -2
  137. package/dist/web/assets/PageAgent-DNjzIgeY.js +0 -1
  138. package/dist/web/assets/Product-nYV_scOV.js +0 -7
  139. package/dist/web/assets/Production-CGSbEWVa.js +0 -1
  140. package/dist/web/assets/Quality-BIypojZm.js +0 -1
  141. package/dist/web/assets/Readiness-BlRjwJRg.js +0 -1
  142. package/dist/web/assets/Record-v2KLI-_Z.js +0 -1
  143. package/dist/web/assets/Regression-B-jSt4Jz.js +0 -5
  144. package/dist/web/assets/RelationGraph-8J98lOVG.js +0 -1
  145. package/dist/web/assets/Reports-GI4u6SyW.js +0 -2
  146. package/dist/web/assets/Response-mhBThq2b.js +0 -9
  147. package/dist/web/assets/Responsive-DXu7Ra7K.js +0 -3
  148. package/dist/web/assets/RunDiff-D0SHDNp0.js +0 -1
  149. package/dist/web/assets/Runs-C1Gjdi9M.js +0 -2
  150. package/dist/web/assets/Settings-BGGeuvyF.js +0 -21
  151. package/dist/web/assets/TestCases-DC4w77eQ.js +0 -1
  152. package/dist/web/assets/TestData-CvKWRVVV.js +0 -2
  153. package/dist/web/assets/TestDebt-D8YzN29_.js +0 -1
  154. package/dist/web/assets/TestManagement-C5cDCqrD.js +0 -1
  155. package/dist/web/assets/Tosca-BGUv3RiJ.js +0 -3
  156. package/dist/web/assets/WhatsNew-B_Gyuv8O.js +0 -1
  157. package/dist/web/assets/coverage-BMP6ELFJ.js +0 -5
  158. package/dist/web/assets/filters-CnAMr286.js +0 -1
  159. package/dist/web/assets/fold-D_O_VZui.js +0 -1
  160. package/dist/web/assets/head-CRo48rPt.js +0 -1
  161. package/dist/web/assets/index-B3JsM7tv.js +0 -64
  162. package/dist/web/assets/index-CafApcbZ.css +0 -2
  163. package/dist/web/assets/input-CtzK50ZF.js +0 -1
  164. package/dist/web/assets/line-icons-rdF8DYDJ.js +0 -1
  165. package/dist/web/assets/logos-D4oVWzqa.js +0 -1
  166. package/dist/web/assets/palette-DAaGSao7.js +0 -1
  167. package/dist/web/assets/parts-D357Wolo.js +0 -1
  168. package/dist/web/assets/productParts-B8oHRCJF.js +0 -1
  169. package/dist/web/assets/qualityParts-BLkmIfDY.js +0 -1
  170. package/dist/web/assets/route-BloYJWgw.js +0 -1
@@ -0,0 +1,1484 @@
1
+ # Architecture reference
2
+
3
+ For contributors: how ForgeQE is built. For what it does and how to use it, see [How ForgeQE works](ARCHITECTURE.md).
4
+
5
+ ForgeQE is a Bun CLI that starts other processes and talks to each through a fixed channel. The Bun CLI owns the terminal shell (OpenTUI), config, profiles, and ForgeQE's tools. ForgeQE's agent (Atlas, agent id `forgeqe`) and Quill, the coding agent (`forgeqe-test`), run on the agent runtime: an `opencode serve` process pinned at `OPENCODE_VERSION` (1.19.5). Python engines drive Chrome, Windows apps, Android and iOS apps, and the team's databases. There is no FastAPI server. ForgeQE keeps no database of its own except the optional Neo4j graph store, which holds the product graph and BASAL's scenario graphs. The databases it reads, and writes to when one is marked writable and the user confirms, are the ones `databases:` names.
6
+
7
+ | Process | Started by | Talks to the rest by | Where it lives |
8
+ |---------|------------|----------------------|----------------|
9
+ | CLI and terminal shell (`forgeqe`, Bun, OpenTUI) | the launcher (`bin/forgeqe.js`, `py/forgeqe_cli/launcher.py`) | serves ForgeQE's tools over MCP Streamable HTTP on 127.0.0.1 with a bearer token (`localToolServer`, `src/mcp/server.ts`); `forgeqe mcp` serves them on stdio | `src/cli/index.ts`, `src/tui` |
10
+ | Agent runtime (`<runtime> serve --hostname=127.0.0.1 --port=0`) | `openSession` (`src/code/runtime.ts`), one per session: Atlas, each Quill, healing or review job, and the other `forgeqe-*` model agents | config in `OPENCODE_CONFIG_CONTENT`; ForgeQE drives it with the SDK over HTTP and its event stream; it calls ForgeQE's tools as a remote MCP entry, and starts other systems' MCP servers (npx or uvx, or remote), Playwright MCP for `live`, and the agents' shell commands | `~/.forgeqe/tools/agent-runtime-<version>/forgeqe-runtime`; its data in `~/.forgeqe/runtime` |
11
+ | Web app (`forgeqe web`) | the person | `Bun.serve` on 127.0.0.1 with a token: the React app (`web/`, built into `dist/web`) and `/api/*` JSON; one child `forgeqe chat --jsonl` per chat (argument array, JSON lines on stdin and stdout, the page long-polls the events); page jobs as child `forgeqe <args>` through `createCliRunner`, which asks the page through `channelAsk` lines; Talk as a WebSocket at `/api/voice` after a single-use ticket | `src/web/server.ts`, `src/web/chat.ts`, `src/web/cli.ts` |
12
+ | Jobs service (`forgeqe jobs serve`) | `src/jobs/client.ts`, detached so it outlives the shell | HTTP on 127.0.0.1 with a token; its address and token in `~/.forgeqe/jobs/<hash>.service.json (a 16-hex hash of the project)`; each job is its own `forgeqe <args>` child (`src/jobs/runner.ts`) | `src/jobs` |
13
+ | Browser engine (`python -m forgeqe_engine run`) | `runEngine` (`src/engine/bridge.ts`) | stdin: the request JSON, later `stop` or `continue <id> yes\|no`; stdout: JSON events (log, memory, step, result, usage, call, continue?, sign_in_waiting, done); stderr: logs. Other subcommands: `record`, `login`, `code`, `doctor`, `token`, `probe`, `video` | `py/forgeqe_engine`, `~/.forgeqe/engine/.venv` |
14
+ | Copilot gateway (`python -m forgeqe_engine copilot-gateway`) | `src/copilot.ts`, for `github_copilot` profiles | OpenAI-style HTTP on 127.0.0.1 with a one-time key, used by the browser engine, the desktop and mobile agents and the agent runtime | `py/forgeqe_engine/copilot_gateway.py` |
15
+ | Entra ID gateway | `entraGateway` (`src/entra.ts`), for `auth: entra` profiles | an in-process `Bun.serve` on 127.0.0.1 that adds a token to each request; tokens come from `python -m forgeqe_engine token` | `src/entra.ts` |
16
+ | Desktop engine (`python -m forgeqe_desktop serve`) | `src/desktop/bridge.ts` | JSON request on stdin, JSON line events on stdout; drives UFO², pywinauto or agent-desktop's native executable | `py/forgeqe_desktop`, `~/.forgeqe/desktop/.venv` |
17
+ | Mobile engine (`python -m forgeqe_mobile serve`) | `src/mobile/run.ts` | the desktop engine's protocol (`runEngine` in `src/desktop/bridge.ts`); talks to Appium (a local one started by `ensureAppium` with Node on 127.0.0.1), Maestro, or a cloud hub | `py/forgeqe_mobile`, the browser engine's Python |
18
+ | Data engine (`python -m forgeqe_data serve`) | `src/data/bridge.ts` | JSON request on stdin, JSON line events on stdout; SQLAlchemy, sqlglot and DB-GPT | `py/forgeqe_data`, `~/.forgeqe/data/.venv` |
19
+ | Speech worker (`python -I -X utf8 -c <BOOTSTRAP> <py dir> serve …`) | `forgeqe web` (`createSpeechWorker`, `src/speech/worker.ts`) | JSON requests on stdin, replies on stdout | `py/forgeqe_speech`, `~/.forgeqe/speech/.venv` |
20
+ | Graphify (`python -I -X utf8 graphify_bridge.py <request> <result>`) | `forgeqe knowledge build` (`src/product/graphify.ts`) | a request file in, a result file out, in ForgeQE's cache | `py/forgeqe_knowledge`, `~/.forgeqe/knowledge/.venv` |
21
+ | Tosca reader (`python -m forgeqe_tosca …`) and the pytest collector (`-p forgeqe_testmgmt.pytest_collect`) | `src/tosca/reader.ts`; test discovery (`src/testmgmt/discover.ts`) | arguments in, JSON or text out | `py/forgeqe_tosca`, `py/forgeqe_testmgmt` |
22
+ | Neo4j (optional) | `forgeqe graph setup`: Docker (`NEO4J_IMAGE`, pinned by digest) or a native archive | Bolt on 127.0.0.1:7688 | `src/graph` |
23
+ | Containers (optional) | `forgeqe services`, `containers.workspace`, `browser.provider: docker` | Docker or Podman: a test run's services; the workspace the agents' shell and tests run in (`SHELL`, `runTestCommand`); Chromium in a Playwright image behind a token-checked CDP gateway on 127.0.0.1 | `src/containers`, docs/CONTAINERS.md |
24
+ | Test commands and replays | `runTestCommand` (`src/code/testrun.ts`), `replayRun` (`src/code/replay.ts`) | `sh -c` on macOS and Linux, `cmd.exe` on Windows; the Playwright replay runner under Bun | the repository |
25
+
26
+ A browser run writes `.forgeqe/reports/<run-id>/`: `run.json`, `workflow.yaml`, `trace.md`, `steps.json`, `steps/`, `report.html`, `video.mp4`, `accessibility.json`, `network.json`, `resume.json` (after a failure or cut-off) and `failure.png`.
27
+
28
+ The single-view map of subagents, tools, and capabilities is [`forgeqe-architecture.html`](../forgeqe-architecture.html) (`forgeqe docs --open`). Suite `report.html` includes the browser agent's token counts, and a cost in the machine's currency when the profile has a price.
29
+
30
+ Every agent prompt is a Markdown file, `prompts/<name>.md`. A project overrides one in `.forgeqe/prompts/`, a user in `~/.forgeqe/prompts/`, and `{{> name}}` includes another prompt (`src/prompts.ts`). The browser engine's prompts come from the same files, with its built-in text as the fallback (`prompt_text`).
31
+
32
+ ## Engine (`py/forgeqe_engine`)
33
+
34
+ Copied from test-agent-nexus and trimmed to what a CLI run needs:
35
+
36
+ | Module | From nexus | Contents |
37
+ |--------|------------|----------|
38
+ | `service.py` | nexus browser service | `RunRequest`, `run_browser_task` (memory replay, Agent construction fallbacks, the step callbacks, timeout and stop handling, one `_save` for every way a run ends), error-recovery system prompt, `MemoryRun`, artifact writing |
39
+ | `llm.py` | nexus browser service | LLM construction (azure, openai, openai_compatible, ollama; `auth: entra` for azure and openai_compatible; GitHub Copilot through the Copilot gateway as an openai_compatible profile), model-call timing, token usage |
40
+ | `browser.py` | nexus browser service | Chrome launch kwargs, waiting for a page to settle, browser and agent shutdown, the browser profile recorded in `run.json` |
41
+ | `settings.py` | nexus browser service | Fast-mode tuning, headless mode, the default-login block |
42
+ | `urls.py` | nexus browser service | Start URL normalisation and the allowed-hosts checks |
43
+ | `loops.py` | nexus browser service | Progress checks, the repeated-control nudge then stop, and the resume point after a failure |
44
+ | `capture.py` | new | Live capture for the test the run becomes: what each action changed on the page (`install_effects` wraps the agent's `tools.act`), the control a user acts on (`actionable_node`), locators checked on the live page (`verify_locators`: role and name through Chrome's accessibility tree, the rest in the page), the element and section behind each check (`locate_check`), and `click_selector`, a real mouse click on a CSS-selected element |
45
+ | `summary.py` | nexus browser service | Result markdown (the agent's own final answer and the checks it recorded; no filtering of what it read), fallback summaries, failure trace and screenshot, the judge's verdict |
46
+ | `workflow_yaml.py` | `browser_workflow_yaml.py` | `forgeqe-v2-compact` steps from history (or the live trace after a stop), semantic locators, execution metadata |
47
+ | `cli.py` | new | The stdin/stdout protocol above, and the `login`, `record`, `code`, `doctor`, `token`, `probe`, `video` and `copilot-gateway` subcommands |
48
+ | `memory.py` | new | Page memory: element facts from the engine library's DOM, ranked locators with confidence, element identity across visits, recorded flows, prompt hints. Locators follow Playwright: `playwright_role_ok` (no link role for an `<a>` without `href`), `strip_icons` (icon-font characters out of names and text; such a name becomes a `role_pattern`), a `scope` (the nearest ancestor id) for a css locator scoped to a repeating item, and the `frame` an element sits in |
49
+ | `userlike.py` | new | The agent clicks as a user can: the library's occlusion check raises `Covered` with what covers the element instead of clicking it from JavaScript, and script clicks (`this.click()` through `Runtime.callFunctionOn`) and page typing (`_type_to_page`) it still makes are recorded. `install_effects` puts `take()` on each action; `_record_memory_results` keeps `covered_by` for the click that then worked, and `bypass` and `frame` on the step |
50
+ | `replay.py` | new | Replays a recorded flow through the engine library's `Tools` and writes the hand-off task for the agent |
51
+ | `logins.py` | new | Saved logins: the engine library's `sensitive_data` per domain, TOTP codes, session files (load, split by host, save when changed), and the interactive `login` command |
52
+ | `report.py` | new | `CaseReport` (per-step verdicts through the engine library's `output_model_schema`) and `steps.json` with step screenshots |
53
+ | `checks.py` | new | `record_check`, the browser agent's action for each result the goal asks to verify: `expected` and the exact `text` on the page, refused when the page (visible text or form values, over CDP) does not show it; `service.py` registers it on the agent's `Tools`, adds `CHECKS_SYSTEM_MESSAGE`, and on success passes the checks to `run.json` and `workflow.yaml` `checks` |
54
+ | `diagnostics.py` | new | Console errors, uncaught exceptions, failed and slow requests, accessibility checks (axe-core when ForgeQE passes its script, else built-in checks), web vitals, network capture and visual captures per page, over CDP |
55
+ | `skills.py` | new | Browser skills: `choose_skills` (one structured model call picks at most 3 by name and description; never raises) and `skills_block` (the chosen skills' text under a header, within `skills_max_chars`). `run_browser_task` appends the block to the extended system prompt and records what it decided in `run.json` `skills`; the choice's tokens are added to the run's usage |
56
+ | `brand.py`, `brand_assets.py` | new | ForgeQE start page and overlay in a visible browser; the icon made by `scripts/brand.py` from `assets/forgeqe-icon.png` |
57
+
58
+ The table lists the modules of a browser run. The package also holds, among others:
59
+
60
+ - `copilot_gateway.py`: the GitHub Copilot gateway.
61
+ - `proceed.py`: asking a person whether a run goes on past a limit.
62
+ - `video.py`: videos of recordings, replays and desktop runs.
63
+ - `recordsession.py`, `webrecord.py`, `webrecord_page.py`: recording by hand.
64
+ - `flowmatch.py`: the start a task shares with another task on the host.
65
+ - `network.py`: `NetworkCapture`, the app's API calls.
66
+ - `api_step.py`: `api_request` steps.
67
+ - `otp.py`, `passkey.py`: one-time codes and security keys.
68
+ - `persona.py`: accessibility runs as a persona.
69
+ - `browserdoctor.py`, `browserlaunch.py`, `dynamic.py`, `lenient_json.py`, `model_params.py`, `neutral_log.py`, `observe.py`, `probe.py`, `prompts.py`, `pwlaunch.mjs`, `stdio.py`, `suggest.py`, `systemcerts.py`, `varying.py`.
70
+
71
+ **Saved logins.** The request carries each login's name, domains, and environment variable names; values cross stdin only for logins remembered this session (`values`), and are never logged. `use_logins` builds the engine library's domain-scoped `sensitive_data` (`{domain: {shop_username: …, shop_password: …, shop_bu_2fa_code: <TOTP secret>}}`), so the model sees placeholders, the engine fills values only on matching domains, masks them in page text, and turns `bu_2fa_code` into a fresh pyotp code when typed. Session files for the run's logins are merged into `Browser(storage_state=…)`. Because the agent closes the browser when `run()` returns, `_on_step_end` saves each login's cookies and origins (`_cdp_get_storage_state`, split by host) whenever they change, mode 0600, with a `.gitignore` in the folder. Page memory records `text_env` / `totp_env` instead of values, so replays and the handoff to the coding agent (`process.env.X`) use the current secrets.
72
+
73
+ **Session logins** (`src/sessionLogins.ts`). Credentials the user gives in a message or test case become a login through the `logins` tool's `remember` action: the site and its sign-in hosts as domains, `FORGEQE_<NAME>_USERNAME` / `_PASSWORD` / `_TOTP` as env names, a session file in the sessions folder (`.forgeqe/sessions`, or `~/.forgeqe/sessions` without a `forgeqe.yaml`), and the values held in ForgeQE's process only. `executeRun` sends `allLogins(config)` (forgeqe.yaml's plus these, a remembered one replacing a configured one of the same name) and passes the goal through `redactSecrets`, which replaces each remembered password or secret with "(the password of saved login NAME)". `runTestCommand` puts the values under their env names for ForgeQE's own test runs and redacts them from the output. The brain's notes list remembered logins; its prompt says to remember credentials before the first run and never put them in goals.
74
+
75
+ **Step budget.** `max_steps` is a checkpoint, not a wall.
76
+
77
+ - The library's `run()` gets `3 × max_steps` (`STEP_EXTENSIONS` = 2), so its budget warning (at 75%) and forced last-step `done` come at the cap.
78
+ - At each multiple of `max_steps`, `_on_step_end` looks at the last 10 steps (`step_outcomes`: the step's actions ran without an error and the agent's own evaluation at the next step did not call it a failure).
79
+ - It carries on when at least 3 worked (`making_progress`), logging "Reached N steps and still making progress".
80
+ - Otherwise it stops the agent, and the summary starts "Stopped at N steps: the last 10 steps made no progress."
81
+ - When a person can be asked (the request's `ask_to_continue`), a run that reaches its step or time limit emits `continue?` and waits up to `ANSWER_SECONDS` (600 s) for `continue <id> yes|no` on stdin (`proceed.py`). Yes gives it as much again; no, or no answer, ends it as the limit always did. The wait does not count against the run's time.
82
+
83
+ **Page loading.** `_on_step_start` calls `settle_page` before every step after the first.
84
+
85
+ - It reads `location.href`, `document.readyState`, and the body's text length over CDP every 0.25 s.
86
+ - It stops when the page is `complete`, or `interactive` with content, or after 8 s (3 s while the tab stays `about:blank`).
87
+ - It logs a debug line when it waited a second or more.
88
+ - Why: the library switches to a tab a click opened 50 ms after the click and waits at most 0.3 s before reading the page, so a heavy page used to be read blank and cost a step.
89
+
90
+ The agent's own note actions (`write_file`, `replace_file`, `read_file`) are in `READ_ONLY_ACTIONS`, so they are neither recorded nor stop a replay.
91
+
92
+ **Repeated controls.** `_control_loop_exceeded` counts the same click, input, search, or select (by element index or text) in the last 8 steps. The first time one reaches 4, the agent is not stopped: `_install_nudges` wraps the library's `_inject_loop_detection_nudge`, which runs after the library clears its per-step context, and the next step's prompt gets "you have done `click "One way"` 4 times… work out why the earlier attempts did not stick… take a different approach". Counting restarts after the nudge; reaching 4 again stops the run ("…after the agent had already been told to change approach"). With a library that has no such hook, the first loop stops the run as before.
93
+
94
+ **Resuming a failed run.**
95
+
96
+ - Each recorded step keeps the agent step it came from (`MemoryRun.step_of`; 0 for replayed steps and the opening navigate).
97
+ - On a failure other than a user stop, `resume_point` picks the step where the run went wrong: where a repeated-control loop began, where the last progress window of a stalled run began, or the trailing streak of failed steps.
98
+ - `resume_steps` keeps the recorded steps from before it (not only navigation and waits). They go to `resume.json` in the run folder and under `resume` in the task's flow file. A later success removes them.
99
+ - Replay picks, in order: the request's `resume` (from `browser_run`'s `resume_from`), the task's successful flow, the task's `resume`.
100
+ - `handoff_task(kind="resume")` tells the agent where the earlier run went wrong and to take a different approach there.
101
+ - A run that failed because an expected result did not hold (`outcome: assertion_failed`) keeps the steps up to that check instead (`assertion_resume`), marked `assertion: true`. `MemoryRun.first_failed_check` finds the earliest check recorded with `holds: false`, by the flow steps done and the agent step when it was recorded.
102
+ - The next run replays them, and the handoff tells the agent to check that result again on the page as it is, record it as not holding if it still does not, and not to redo the steps or try other ways to make it true. That is what a reproduce run or a rerun of a failing case needs: the way to the failing check, not another exploration.
103
+ - The resume also keeps that check (`check`: expected, and the text the page showed instead) unless a passing check of the run found the same text.
104
+ - With `checks_first` and `replay: verify`, `reproduced_by_check` lets the run look for that text right after the replay with no model. Found: the run ends `assertion_failed` with 0 tokens (trace source `memory_reproduced`) and keeps the resume. Not found: the agent takes over with the handoff above.
105
+
106
+ **Checkpoints.**
107
+
108
+ - After each step `_on_step_end` calls `MemoryRun.checkpoint()`. The steps so far (`resume_steps` with no cut-off) go to `checkpoints/<flow file name>` in the memory folder (a separate folder, so `recent_flows` never lists them) with the run id and `interrupted: true`. The same data goes to the run folder's `resume.json`, and page memory is flushed.
109
+ - `MemoryRun.finish` removes the checkpoint when this run or the run it picked up wrote it, except for a stopped run. `_write_artifacts` removes the checkpoint `resume.json` from a run that did not fail and was not stopped.
110
+ - The lookup takes the checkpoint after the task's successful flow and before its saved `resume`, as `kind="interrupted"`. `handoff_task` then says the earlier run was cut off and to carry on without repeating the steps.
111
+ - Stopped runs report tokens from the library's token counter, since `history.usage` is only filled when `run()` returns.
112
+ - Session-login values are also set in the engine process's environment (one process per run), so a replayed sign-in step finds them by env name.
113
+
114
+ **Session log** (`src/sessionLog.ts`). `main()` opens one log per session for the commands that run something (`startSessionLog`, in the logs folder next to `sessions`). Lines are `<ISO time> <kind> <JSON>`:
115
+
116
+ | Kind | Written by | Contents |
117
+ |------|------------|----------|
118
+ | `session` | `startSessionLog` | versions, argv, profile, browser and memory settings, login names |
119
+ | `agent.ask` / `agent.turn` | `ask` in `brain/index.ts` | written after the turn, so credentials the message gave are remembered and redacted |
120
+ | `agent.event` | `openBrain` | the agent runtime's events |
121
+ | `tool.call` / `tool.result` | `createMcpServer` | each call, with duration |
122
+ | `tool.event` | the tools | what a tool reports while it runs: the coding and healing agents' reads, commands, edits, and test runs, suites, cards; browser run events are left to `engine.event` |
123
+ | `engine.request` / `engine.event` / `engine.log` / `engine.exit` | `runEngine` | `engine.log` is every stderr line |
124
+ | `run.done` | `executeRun` | the run's result |
125
+ | `error` | any | an error |
126
+
127
+ - `serialize` hides fields named like `api_key`, `password`, `token`, or `values`, and clips strings at 8,000 characters (200,000 with `--debug`).
128
+ - `redactForLog` replaces remembered login values, secret-looking environment variables (name parts KEY, TOKEN, SECRET, PASSWORD, PAT, CREDENTIALS, values of 8+ characters), and API keys from `llms.json`.
129
+ - `--debug` / `FORGEQE_DEBUG` also sets the engine's logging level to debug; debug-level engine events go to the log only.
130
+ - `bundleLogs` (`forgeqe logs bundle`, `/logs`) stages the log, the run folders named by `out_dir` / `runDir` / `run_dir` in it (text files redacted, screenshots only with `shots`), `forgeqe.yaml`, profiles without keys, and versions, then `tar -czf`s them.
131
+
132
+ **Updating** (`src/update.ts`, `forgeqe update`). `findInstalls` walks PATH for `forgeqe` executables, resolves pyenv shims with `pyenv which`, and classifies each by what it resolves to:
133
+
134
+ | Kind | Found as | Update commands |
135
+ |------|----------|-----------------|
136
+ | bun | a package folder named `@capagents/forgeqe` under `.bun` | `bun pm cache rm`, then `bun add -g …@version --no-cache` |
137
+ | npm | that package folder elsewhere | `npm install -g …@version --prefer-online` |
138
+ | pip | a script whose shebang is a Python that imports `forgeqe_cli` | `<python> -m pip install --upgrade --no-cache-dir forgeqe-cli==version` |
139
+
140
+ - `latestVersion` reads the registry's `latest` tag with a cache-busting query.
141
+ - `npmReady` needs the version document and a HEAD of the tarball to answer 200; `pypiReady` needs the PyPI version JSON. Both registries accept an upload minutes before they serve it.
142
+ - `update` waits for them (`waitUntil`, every 15 s, 20 minutes by default), runs the commands, and reads the installs again to confirm.
143
+ - `scripts/publish.sh` waits the same way after uploading before it prints `Done`.
144
+
145
+ **Step verdicts.** When the goal came from a test case with steps, `CASE_REPORT_INSTRUCTION` goes into the system prompt and `output_model_schema=CaseReport` makes the engine library's `done` action return `{summary, steps: [{step, status, actual}]}`; `history.structured_output` becomes `case_report` in the result. If the Agent rejects the schema, the run continues without it.
146
+
147
+ **Finishing and the judge.** `_GOAL_VERIFICATION_SYSTEM_MESSAGE` is added to every agent's system prompt except a persona's run: `done` with success only when every field holds exactly what the goal asked for (pre-filled or extra values in multi-value fields removed), every setting the goal names is applied through the page's own controls and shown by the page, and findings are read from the page, items a list already shows are read from it in one step, and a tab that looks blank right after opening is still loading. The engine library's judge (`use_judge`) is off by default: `browser.judge: true` (passed to the engine as `BROWSER_USE_USE_JUDGE`, `src/run.ts`) turns it on, and it then makes one model call over the steps and screenshots. It was turned off because it failed completed runs whose answer came from one screenshot (five result scores) instead of one step per item, and ForgeQE's agent then retried with ever stricter goals. When the agent says success and the judge's verdict is false, the run fails with the judge's `failure_reason` ahead of the agent's report; the verdict goes into `run.json` as `judge`. A judge call that errors leaves the agent's result as it was.
148
+
149
+ **Window and video.** `window_launch_kwargs` sizes a local browser from `browser.viewport`: the page when headless, the window with `browser.window: viewport`. Otherwise a visible window opens screen-sized (the engine library's default) and, before the first page, `maximize_window` sets `windowState: maximized` over CDP. With `browser.video` on (the default), the browser is started before the replay or the agent, and `start_video` starts the library's recording watchdog on `<run>/video.mp4`; `stop_video` finishes it before the browser closes, and `run_with_events` adds it to the run's files. The watchdog encodes Chrome's screencast frames at 30 fps as they arrive, so the video's timing follows how often the page repaints, not the clock. The encoder (`browser-use[video]`: imageio with ffmpeg, numpy) is installed with the engine, and added to an engine set up before it. The report lists `video.mp4` among the run's files and plays it on the Artifacts tab.
150
+
151
+ **Videos of recordings, replays and desktop runs.** These have no browser-use agent, so `py/forgeqe_engine/video.py` makes their videos itself, with the ffmpeg that the pinned `imageio-ffmpeg` ships inside the package. It finds that binary in the package's own `binaries` folder, never on PATH or through `IMAGEIO_FFMPEG_EXE`, and starts it with an argument list and system settings only. Frames reach ffmpeg on stdin as raw RGB of a fixed size, letterboxed when a picture's size changes, so nothing a page shows reaches its command line. `FrameVideo` writes in real time at 5 fps, repeating the latest picture while nothing changes, and stops after an hour. A video that could not be finished is removed.
152
+ - *Recording by hand* (`browser.video`): `recordsession.py` runs the page's screencast over its own DevTools connection, follows the tester from tab to tab, and holds the video while the recording is paused. The file is `<run>/video.mp4`. Making a typed value a secret in the review removes the recording's videos, since a value cannot be taken out of a video's pictures.
153
+ - *Replays* (the `forgeqe code` replay check, and a recording's re-runs on the Record page): the Playwright runner keeps screencast frames as `<ms>.jpg`, at most one per tenth of a second, plus a closing screenshot so the video lasts as long as the replay. `python -m forgeqe_engine video` turns them into `replay/<setup>.mp4` (`src/engine/video.ts`) and the frames are removed. A re-run keeps only its last pass's video, as `tries/video.mp4`. Steps played in a person's own tab (a block) are never filmed; the recording's own video already shows them.
154
+ - *Desktop runs* (`desktop.video`, default on): `serve` films the main screen with Pillow's `ImageGrab` while a replay, explore or recording runs, and finishes `<run>/video.mp4` before `run.json` is written, so the desktop report plays it. A computer whose screen cannot be read (no display, or macOS without Screen Recording permission) runs without a video and says so.
155
+
156
+ **Browser profile.** At the end of the first step (or before writing a trust-mode replay), `browser_profile` reads how the browser was set up: the engine's driver, channel and executable, headless, the default switches removed, extra HTTP headers (none), `Browser.getVersion`, and from the page `navigator.userAgent`, `navigator.webdriver`, language, time zone, and viewport. It goes into `run.json` as `browser`, and the handoff shows it so the coding agent can compare its test's browser with it.
157
+
158
+ **Timeline.** `build_timeline` writes `steps.json` from the history (and the replayed steps): URL, title, the model's evaluation, memory and next goal, each action with its error, start time (`t0`) and duration, the part of it spent waiting for the model (`model_ms`, from wrapping `llm.ainvoke` and overlapping the calls with the step's `step_start_time`/`step_end_time`), and a JPEG of the page (max 1280 wide) under `steps/`, subject to `report.screenshots`. Each action on an element carries `box`: the element's `absolute_position` from the DOM snapshot the model saw, minus the page's scroll, as fractions of the viewport, so the report can outline it on that step's screenshot. Timeouts, stops, and crashes still write it from the partial history.
159
+
160
+ **Diagnostics.** `Diagnostics` registers `Runtime.consoleAPICalled`, `Runtime.exceptionThrown` and `Log.entryAdded` on the engine library's CDP client (cdp-use allows one handler per event, and the engine library's own watchdogs don't use these three; `Network.responseReceived` belongs to the downloads watchdog, so failed and slow requests come from the page's resource timing entries, `responseStatus` and duration, at each sample). It samples at every step start and end and after each replayed step. Each new page (by URL without the hash, up to 25) is checked once: `Accessibility.getFullAXTree` for unnamed buttons, links, fields and images, heading order and the document title, plus a page script for `lang`, text contrast (WCAG ratios, skipping text over images) and zoom-blocking viewports, with up to five examples each from `DOM.getOuterHTML`. When ForgeQE passes axe-core's script (`axeCoreScript`, `src/run.ts`), its WCAG rules (`wcag2a`, `wcag2aa` by default) run instead of these built-in page checks. `Diagnostics` also records web vitals per page, the app's API calls through `NetworkCapture` (`network.py`), and visual captures when they are configured. A request counts as slow from 3 s. `assign_problems` attaches each event to the step it happened in (by `t0`), at most 25 per step; `run.json` gets the totals as `diagnostics`, and the pages go to `accessibility.json`. `report.accessibility: false` skips the page checks.
161
+
162
+ **Overlay.** With a visible browser and `browser.overlay` on, `brand.Overlay` puts a `<forgeqe-overlay>` element on each page.
163
+
164
+ - It is a shadow root (page CSS can't reach it) with an edge glow, a bottom bar and a transparent blocker.
165
+ - The bar shows the icon, the step from `step_text` (its intent from `next_goal`, or the "next goal" sentence in the model's memory, and its actions in words from `plain_action`, never raw tool parameters), and a Thinking / Acting / From memory chip.
166
+ - Window capture listeners, added before the page's scripts, drop trusted mouse, wheel and key events while it is locked.
167
+ - It locks in `_on_step_end` and replay's gaps between steps, and unlocks in `_on_new_step` (which the engine library calls after the model answers and before the actions run) and around each replayed action, so the agent's own CDP input always gets through.
168
+ - Each page gets it from `Page.addScriptToEvaluateOnNewDocument` on its own target (the engine library's `_cdp_add_init_script` covers only the focused one), with the current text baked in and the lock off, since a page can load halfway through a step's actions.
169
+ - The host carries the library's DOM-exclude attribute (left out of the DOM the model reads) and `aria-hidden`, and is attached outside `<body>`, so the accessibility checks skip it.
170
+ - `brand.install()` wraps `ScreenshotWatchdog.on_ScreenshotEvent` to hide it for every screenshot (the model's and the report's), and replaces the about:blank watchdog's animation, which loads a logo from the library's CDN, with a start page.
171
+ - The status bar's icon is raw pixels on a canvas, so a page's `img-src` policy can't block it or log an error; the start page only appears on about:blank, which has no policy.
172
+ - Headless runs skip all of it.
173
+
174
+ Left out: Mongo persistence, LangGraph, and Scrum Studio. Nexus's Mongo site memory and compact replay are replaced by the file-based page memory below.
175
+
176
+ The model decides everything about navigation. With no pinned URL the browser starts blank and the agent opens the site itself, even when the goal names one. Nexus's `_infer_initial_url_from_goal` regex is removed, and the engine library's own URL guessing from the task (`directly_open_url`) is turned off. Only a pinned start URL (`--url`, `start_url`, or the `start_url` argument the agent passes when the user named a page) is opened before the agent's first step.
177
+
178
+ `fd 1` inside the engine is redirected to stderr at start-up, so library prints cannot corrupt the event stream.
179
+
180
+ ## The path a test follows (`capture.py`)
181
+
182
+ A passed run becomes a test, so the run records the path that worked, checked while the page is still there, not every attempt.
183
+
184
+ **What changed.** `install_effects` wraps the agent's `tools.act`. Around each click, key press, script, and `click_selector` it takes a fingerprint of what a user could notice (address, visible text, element count, open menus and dialogs, form values, selected and pressed states) and polls for up to 1.5 s for a change. `_record_memory_results` leaves an action that changed nothing out of the flow (a click on a decorative node, a retry that missed, a script that only read the page) and lists it in `run.json` `memory.left_out`; fills and selects always stay. A script that did change the page stays, marked `scripted`, and the handoff asks for the page's own control instead.
185
+
186
+ **The control, and locators checked on the live page.** Before the step's actions run (the library's new-step callback comes before `multi_act`), `_point_at_controls` re-points each element action from the node under the pointer to the control a user acts on (an icon inside a label or button becomes the label or button) and `verify_locators` checks each candidate on the live page: role and name through `Accessibility.queryAXTree` (the accessible names Playwright's `getByRole` uses), ids, CSS, attributes, text, and XPath in the page. A locator is `verified` when it finds exactly that element (or something inside it). Verified locators come first, so `best_locator` is one that worked.
187
+
188
+ **Real clicks, not scripts.** The agent's prompt (`CAPTURE_SYSTEM_MESSAGE`) asks it to act only through browser actions, and `click_selector` gives it a real mouse click (scroll into view, refuse when covered, `Input.dispatchMouseEvent`) on an element it found by CSS, captured like any click.
189
+
190
+ **Checks with their element.** `record_check` finds the smallest visible element showing the text and the section it sits in, each with verified locators (`element`, `container` in `workflow.yaml` `checks`), and takes `dynamic` for live data (today's date, a price, a count).
191
+
192
+ The handoff lists the path with ✓ on verified locators, says how many actions were left out, gives each check its locator and section, and leaves out page memory when every step and check is verified. Quill is told to use ✓ locators as given and not to look for those elements again.
193
+
194
+ ## Page memory (`memory.py`, `replay.py`)
195
+
196
+ Files under `memory.dir` (default `.forgeqe/memory` next to `forgeqe.yaml`, or `~/.forgeqe/memory` when there is no config file), written atomically at the end of a run:
197
+
198
+ - `pages/<host>/<path>.json`: one per page template. The key is host (plus port) and path; segments that are numbers or look generated become `*`, and the query string is dropped. Each element stores tag, role, accessible name, text, stable attributes (never `value`), its locators, `best`, `confidence`, visit and use counts, and `first_seen` / `last_seen` / `last_used` / `last_updated`. Pages keep at most 400 elements; past that, elements never used and least recently seen go first.
199
+ - `flows/<goal>-<hash>.json`: keyed by the normalised goal and start URL. It holds the steps of the last successful run, each with the element's top locators and a fingerprint, plus pass, fail, and replay counts.
200
+ - `checkpoints/<flow file name>`: the steps so far of a run that was cut off (see Checkpoints).
201
+ - `rules/<host>.json`: the browser agent's rulebook for a site, learned when a run passed although an action failed on the way, and given to every later run that starts there (`siteRulesFile`, `src/code/rulebook.ts`).
202
+ - `scribe-notes.json`: written by the coding side (`src/code/notes.ts`), not the engine: per repository, Quill's notes from its reading turn and the tests jobs wrote there.
203
+
204
+ **Observe.** Before each agent step, `_on_new_step` passes the engine library's `selector_map` (`EnhancedDOMTreeNode`s) to `MemoryStore.observe`. For every element it builds the locator candidates, counts how many elements on the page each one matches, and merges them into the page file. An element keeps its identity across visits through a strong locator (test id, id, name, role, label, placeholder, href), then its XPath, then a hash of tag and anchor text. An XPath match counts only when the role and accessible name (or text) agree too, because sites reuse one popup container for different widgets; an element whose label changed becomes a new entry. When replay resolves a step on a different entry than the one recorded, `record_stale` marks the recorded entry's dead locators as missed and failed, and the flow is saved against the new entry. `flow_step` lists the locators that matched on the page at that moment ahead of those only seen on earlier visits.
205
+
206
+ **Confidence** is `100 × base × uniqueness × stability × reliability`, clamped to 1–99:
207
+
208
+ | Factor | Value |
209
+ |--------|-------|
210
+ | base | by kind: test id .96, id .90, role .88, name .86, label .84, placeholder .82, alt .78, href .74, title .72, text .70, CSS .50, XPath .30; ×0.4 when the value looks generated |
211
+ | uniqueness | 1 when it matches one element, else 0.5 / (matches − 1) |
212
+ | stability | (0.75 + 0.25 × min(seen, 4) / 4) × seen / (seen + missed) |
213
+ | reliability | (successes + 1) / (successes + failures + 1) |
214
+
215
+ **Record.** `_on_step_end` pairs each action's result with the element it targeted. It records success or failure against the element and the locator, and adds non-read-only actions to the run's flow. At the end, a complete run replaces the flow's steps, a failed run only counts a failure, and a stopped run leaves the flow alone.
216
+
217
+ **Replay.** Before the agent is built, `replay_flow` runs the stored steps with `Tools().act`, the same actions the agent would call.
218
+
219
+ - What it replays, in order: the exact goal's flow, a failed run's `resume` steps, a cut-off run's checkpoint, or an edited case's unchanged steps.
220
+ - A goal with none of these gets the start it shares with another task on the host (`MemoryStore.shared_start`, kind `shared`). `flowmatch.shared_start` (`py/forgeqe_engine/flowmatch.py`, no model) ranks the host's passing flows by the content words their goals share with this one, and of the three most similar keeps the longest leading run of steps this task may borrow.
221
+ - A step is borrowed when this goal names its control or the value it types; when it signs in with a saved secret (and the click that submits that sign-in); when it clears a cookie banner or pop-up; or, while the flow is still in its opening, when another recorded task on the host took the same step without a value.
222
+ - Values another task typed, page scripts, uploads and API calls are never borrowed. A flow that opens another URL than this task's start is not used. The first step that fails these rules ends what is borrowed.
223
+ - `handoff_task(kind="shared")` names the task they came from and tells the agent to check the page fits and carry on.
224
+ - `prompt_hints` still lists the steps of up to 2 recent flows of other tasks and the controls that worked there.
225
+ - Element steps take a fresh snapshot (retrying briefly while the page loads) and resolve the element by the store's current best locator, then the step's own locators, then the fingerprint.
226
+ - Read-only actions (`extract`, `find_text`, `done`, …) are skipped.
227
+ - Replay stops at a step it cannot resolve or restore: password fields, file uploads, tab switches, `evaluate`.
228
+ - An `api_request` step is replayed with the same call in the page's session (`register_api_request` on replay's own tools), and stands only when the server answers with the recorded status (`api_mismatch`); otherwise replay stops there and the agent judges the answer.
229
+ - `handoff_task` then tells the agent what was already done: check and finish (`verify`), or continue from the stopped step. `trust` returns success with no agent only when every step of this same task ran.
230
+ - Replayed steps are emitted as `step` events with `"source": "memory"`, before any agent steps.
231
+ - A replayed step whose recorded locators no longer match anything on the page, but that still resolved through another locator, is recorded as a heal (`{step, line, label, stale, used}`). When replay stops and the agent then finishes the case, `run.json` notes `repaired` with the step and reason. Both go under `memory` in `run.json` for the report.
232
+
233
+ **Parallel runs.** `flush` and `save_flow_result` hold an `fcntl` lock on `<memory>/.lock`. Each page file has a `revision` counter. If the file on disk has moved on since this run loaded it, the run merges instead of overwriting: every visit, match, miss, success, and failure counter becomes the saved value plus this run's own change, elements this run never saw keep the saved copy, and the revision becomes one past the higher of the two. Two runs on the same page (a suite with `parallel` above 1) therefore both count.
234
+
235
+ **Hints.** `prompt_hints` adds the last successful steps on the same host, and the controls those runs actually used, to the agent's extended system prompt, capped at 2,500 characters, and tells the agent to act on them in one turn. The system prompt cannot name an element's index, which changes with every page load, so on its own it left the agent reading the whole element list anyway.
236
+
237
+ **Known controls per step.** `_install_known_controls` wraps the library agent's `_prepare_context`.
238
+
239
+ - After the library has built the step's page message, `MemoryStore.observe` records the page once (the snapshot is shared with the step callback through `step_seen`, so a step is observed once).
240
+ - `MemoryStore.known_controls` adds a context message naming up to 10 controls on this page that earlier runs acted on with success, each with its index in this step's element list (`[12] Email address * (textbox, worked 2×)`), and tells the agent to act on them by index in this turn.
241
+ - A page memory has never acted on adds nothing.
242
+ - Context messages are the library's own per-step channel (its loop nudge uses it), cleared before each step.
243
+
244
+ **In-run history.** Fast mode passes `max_history_items=8` and turns message compaction off. Each later step of an exploration keeps the first step and the most recent ones, instead of resending the whole transcript or pausing for a summary model call. `BROWSER_USE_MAX_HISTORY_ITEMS` overrides the cap (minimum 6, which is the engine library's own floor).
245
+
246
+ **Workflow steps.** `compact_step` gives each workflow step its `best_locator` and ranked `locators` (with `css`/`attr` where the locator needs them), `evaluate` steps their `code`, and every step the browser agent's `note`, which the handoff passes to the coding agent. `_on_step_end` passes `agent_note(model_output)` (the step's evaluation, memory, and next goal, each once) to `_record_memory_results`, which stores it on each flow step that step recorded; flows keep it, so replayed steps carry the note of the run that first took them. The engine writes no test script: the coding agent writes the test in the repository's language, and ForgeQE runs it.
247
+
248
+ ## Bridge (`src/engine`)
249
+
250
+ The launchers (`bin/forgeqe.js` for npm, `py/forgeqe_cli/launcher.py` for pip) use a Bun 1.3+ (`MIN_BUN`) from `FORGEQE_BUN`, the Bun npm installed (npm launcher only), PATH or `~/.bun/bin`. Otherwise they download the pinned `BUN_VERSION` from Bun's GitHub releases into `~/.forgeqe/tools/bun-<version>` after checking it against `SHASUMS256.txt`. Both pin the same version (a test checks this). The npm launcher runs the checkout's `src/index.ts`, else the package's bundle `dist/forgeqe.js`; a thin package fetches its version's bundle into `~/.forgeqe/pkg`, through the licence service when one is configured (`forgeqe activate`). The pip launcher runs the checkout's `src/index.ts` (unless `FORGEQE_FROM_REGISTRY=1`), else `bun x @capagents/forgeqe@<its version>`.
251
+
252
+ `src/tools.ts` downloads a release archive into `~/.forgeqe/tools/<name>-<version>`, checks its SHA-256 (from the release's checksum file, or the digest GitHub's release API records), unpacks it with `tar` (System32's bsdtar on Windows, which reads zip), and removes older versions. uv and the agent runtime use it; the launchers carry their own copy for Bun because they run before any TypeScript. `code/runtime.ts` uses the runtime from `code.runtime` (formerly `code.opencode`), else `opencode` on PATH, else `~/.opencode/bin`, else a copy ForgeQE downloaded. Failing those, it downloads the pinned `OPENCODE_VERSION` from the `anomalyco/opencode` release, checks it against `OPENCODE_SHA256` (a test checks the pins), and keeps it as `~/.forgeqe/tools/agent-runtime-<version>/forgeqe-runtime` (`RUNTIME_TOOL`, `RUNTIME_BIN`; `adoptLegacyRuntime` moves a copy an earlier ForgeQE kept as `opencode-<version>`). Its version matches the agent runtime SDK in `package.json`. `forgeqe setup` calls it, and so does every command that can start the agent.
253
+
254
+ `setup.ts` finds or creates the engine environment: `FORGEQE_PYTHON` when that Python passes the engine check (otherwise it logs why and skips it), else `~/.forgeqe/engine/.venv`, which is rebuilt when its engine check fails (created with `uv venv --python ">=3.11,<3.14"`, `cpython-3.13-windows-x86_64-none` on Windows x64 (`enginePythonRequest`), or a system Python 3.11–3.13 `-m venv` when no uv can be found or downloaded). uv is the system one, else the pinned `UV_VERSION` downloaded from uv's GitHub releases into `~/.forgeqe/tools/uv-<version>` (checked against its `.sha256`, unpacked with `tar`, which on Windows is System32's bsdtar). A downloaded uv keeps the Pythons it fetches in `~/.forgeqe/tools/python`. It installs the engine's pinned Python libraries and records the version in `installed.json`, so later runs skip setup. When Google Chrome is missing it installs Chromium through Playwright.
255
+
256
+ `bridge.ts` spawns the engine with `PYTHONPATH` pointing at the packaged `py/`, sends the request (goal, profile, start URL, headed, max steps, allowed hosts, extra system prompt, browser skills with `skills_pick` and `skills_max_chars`), and maps events:
257
+
258
+ | Engine event | Transcript |
259
+ |--------------|------------|
260
+ | `log` | grey line |
261
+ | `memory` | `↻` line, e.g. `Replaying 4 remembered steps` |
262
+ | `step` | step counter, the model's next goal; `(memory)` for replayed steps |
263
+ | `result` | ✓ / ✗ per action, e.g. `click "Search": element not found` |
264
+ | `usage` | token counter |
265
+ | `call` | one model call's time and tokens, for the usage ledger |
266
+ | `continue?` | the run reached its step or time limit; ForgeQE asks the person and writes `continue <id> yes\|no` |
267
+ | `sign_in_waiting` | the run waits for a push approval (a login's name and seconds) |
268
+ | `done` | final status, summary, artifact list, memory counts (`Memory` row in the summary) |
269
+
270
+ Esc or `/stop` writes `stop`; the engine stops the agent and still writes artifacts from the live trace. An engine still running `STOP_GRACE_MS` (30 s) later gets SIGTERM, then SIGKILL `KILL_AFTER_MS` (10 s) after that, and the run reports stopped with a note that its artifacts may be incomplete. `executeRun` also gives the bridge a hard deadline (`engineDeadlineMs`: twice `browser.timeout_seconds` plus five minutes), because the engine's own timeout covers only the agent, not browser start-up, skill choice (itself capped at 60 s), or memory replay; a run past it is stopped the same way and reported as failed.
271
+
272
+ **Environment.** The engine is spawned with an allow-list (`allowListEnv` in `src/childEnv.ts`): system settings (PATH, HOME, locale, display, temp folders, proxies, certificates, Windows system variables), `BROWSER_USE_*`, `FORGEQE_ENGINE_*`, Python and uv settings, the key variable of the profile the run uses (the active one, or the router's pick for `browser`), and the saved logins' variables. Other secrets in the terminal, such as tracker tokens, never reach the browser agent.
273
+
274
+ ## ForgeQE's agent (`src/brain`, `src/mcp`)
275
+
276
+ Every message in the shell and every `forgeqe run "<request>"` goes to one agent runtime session running the `forgeqe` agent (Atlas). Nothing is parsed before it: the agent decides whether the text is a browser goal, test case references, a test to write, or a pipeline task, and asks (outcome `needs_input`) when it cannot tell. The slash commands are session controls and shortcuts (`COMMANDS` in `src/commands.ts`: `/stop`, `/headed`, `/model`, `/profile`, `/details`, `/theme`, `/paste`, `/logs`, `/skills`, `/init`, `/rerun`, `/record`, `/runs`, `/reports`, `/jobs`, `/db`, `/doctor`, `/settings`, `/docs`, `/clear`, `/help`, `/exit` and a few more). Any other line, including one starting with `/` that is not one of them, is text for the agent.
277
+
278
+ How a message reaches the tools:
279
+
280
+ 1. The shell or `forgeqe run` calls `openBrain`.
281
+ 2. `openBrain` starts an agent runtime session for the `forgeqe` agent, with its prompt and the environment notes.
282
+ 3. The agent calls `forgeqe_*` tools over MCP (Streamable HTTP, bearer token).
283
+ 4. `createMcpServer`, in the same process, runs `TOOLS` (`browser_run`, `run_test_cases`, …).
284
+ 5. The tools report `ToolEvent`s back to the shell.
285
+
286
+ | Module | Contents |
287
+ |--------|----------|
288
+ | `brain/prompt.ts` | `brainPrompt()`: the agent's instructions from `prompts/brain.md` (with routing on, the session gets the router's core part and the capability index instead, `src/mcp/routing.ts`); `splitReply` and `visibleReply` for the reply's hidden trailer. See below |
289
+ | `brain/index.ts` | `openBrain` starts the MCP server on 127.0.0.1 with a random token (`localToolServer`), then an agent runtime session with the prompt, the session notes, the schema, and the server as a remote MCP entry (6 h tool timeout). `ask` returns the reply and outcome, `abort` stops the session and every running tool call. `brainUnavailable` is why it cannot run (no model set up and no `code.model`, or no agent runtime); callers then run the text as one browser goal. `sessionSetup` picks the working directory and whether passed runs become tests from `--repo`, `--no-code`, and `code.repo` (default: tests in the current folder) |
290
+ | `mcp/tools.ts` | `TOOLS` and `environmentNotes`. See below |
291
+ | `cases/save.ts` | `save_test_cases` and the case modules. See below |
292
+ | `mcp/commands.ts` | `COMMAND_TOOLS`: `write_test`, `heal_tests`, `monitor`, `logins`, `forgeqe_setup`. See below |
293
+ | `card.ts` | `Card` (`status`, `title`, `stats`, `body`) and `cardText`. `codeCard`, `healCard`, and `roundCard` build cards from the same lines as the terminal summaries |
294
+ | `mcp/server.ts` | JSON-RPC for MCP by hand. See below |
295
+ | `mcp/git.ts` | `pushBranch`: finds the default branch (`symbolic-ref refs/remotes/<remote>/HEAD`, else `ls-remote --symref`), refuses it and `main`/`master`, checks the name with `git check-ref-format`, and runs `git push --set-upstream <remote> HEAD:refs/heads/<name>` without force. `setCiSecret`: `gh secret set NAME` with the value on stdin, or `az pipelines variable create\|update --secret true` with the value in `AZURE_DEVOPS_EXT_PIPELINE_VAR_<NAME>`; the value is scrubbed from any error |
296
+ | `auth/mcpOAuth.ts` | Browser sign-in to an MCP server (`oauthSignIn`). See below |
297
+ | `web/signins.ts` | Settings' sign-in for every system but Copilot: `signIn` with the page as its terminal (one job at a time, an id of `SIGNIN_SYSTEMS` only, answers only to the question waiting, typed secrets scrubbed from lines, links only https). Routes `/api/signin`, `/api/signin/answer`, `/api/signin/cancel`, `/api/signout` |
298
+ | `mcp/external.ts` | `externalMcp` turns `sources:`, `integrations:` and `mcp:` into agent runtime MCP entries. See below |
299
+ | `cases/dashboards.ts` | `createAdoDashboard` for the `create_ado_dashboard` tool. See below |
300
+ | `cases/adopr.ts` | `createAdoPullRequest` for the `create_ado_pull_request` tool, since the default MCP tool groups leave out `repositories` and `query_api` only reads: `branchRef` checks each branch against git's ref-name rules before anything is sent, the repository is read by name or id, both refs must exist (`refs?filter=heads/…`), an active pull request between the same refs is returned (`existing: true`) instead of a second one, then it POSTs `pullrequests` with a default title of "Merge <source> into <target>" |
301
+ | `cases/wiki.ts` | `writeAdoWikiPage` for the `write_ado_wiki_page` tool, since the MCP server's wiki tools need an existing wiki: picks the named wiki or the project wiki, creating `<Project>.wiki` (`type: projectWiki`, project id from `_apis/projects`) when the project has none, PUTs missing parent pages empty, then PUTs the page with `If-Match` set to its ETag when it already exists. Code wikis get `versionDescriptor` for their first published branch |
302
+ | `cases/api.ts` | `queryApi` for the `query_api` tool: GET under the Azure DevOps organization (and its `vsrm`/`vssps`/`almsearch`/`feeds`/`vsaex` hosts, with `api-version=7.1` added) or the Jira site, and Xray Cloud GraphQL queries (mutations refused). Absolute URLs on other hosts are refused, so credentials only go to their own system. Answers over 40,000 characters are cut |
303
+
304
+ **`brain/prompt.ts`.**
305
+
306
+ - `brainPrompt()` reads `prompts/brain.md`. It covers the tools (every CLI command is one, so the agent uses the tool instead of telling the user to run a command), how to choose a source, find vs run, signing in, writing tests (`write_test`; small hand edits verified with `run_test`), the CI pipeline procedure, fixing broken tests (`heal_tests`), running existing repo tests (`find_tests` then `run_tests`, never without the user's confirmation; sprint dates only from `sprint`), monitoring, ForgeQE's own docs and setup, and the rules (no secret values, push only with `push_branch`, stay in the working directory).
307
+ - The reply is plain text, so it streams to the shell as it is written (the runtime's `message.part.delta` events, relayed as `stream` events).
308
+ - It ends with a hidden line `<!--forgeqe {"outcome": done \| failed \| needs_input, "next": […]}-->` that `splitReply` reads and `visibleReply` holds back while the reply streams.
309
+
310
+ **`mcp/tools.ts`.**
311
+
312
+ - `TOOLS` is `browser_run` and the core tools, followed by every tool module (`COMMAND_TOOLS`, `REPO_TEST_TOOLS`, `CASE_TOOLS`, `API_TOOLS`, `DESKTOP_TOOLS`, `MOBILE_TOOLS`, `DATA_TOOLS`, `APP_TOOLS`, … from `src/mcp/*tools.ts`).
313
+ - `environmentNotes`: working directory, run and memory folders, configured test case systems, suite defaults, timeouts, the profile, and the names, never values, of keys set in the environment.
314
+ - Each tool reports `ToolEvent`s (run-start/event/done, suite-start/event/done, info, `agent` for a nested coding or healing session's events, `card` for a result panel) to whoever shows them.
315
+ - `ToolContext` carries `session` (`shell`, `once` for `forgeqe run`, `server` for `forgeqe mcp`), `waitForUser` and `ask` when a person can answer, and `openSession` so tests can script the nested agent runtime sessions.
316
+ - `browser_run` takes `purpose` (`test` or `task`). `taskReason` treats a `task`, or a run that starts on, ends on, or names a configured source system's host (Azure DevOps, Jira, Confluence, TestRail, Zephyr, qTest, Xray), as a task: it writes `task.json` (`TASK_FILE`) in the run folder, returns no `write_test` next step, and `write_test` refuses that folder.
317
+ - `browser_run` also takes `resume_from` (a failed run's folder or name, read by `loadResume` in `run.ts`) and, after a failure with resume steps, returns them with a `next_step` naming the folder; the brain's prompt says to retry with it and say what to do differently.
318
+
319
+ **`cases/save.ts`.** On unless `sources.save_cases: false`; `environmentNotes` tells the agent which.
320
+
321
+ - `save_test_cases`: `saveAdoCases` creates Test Case work items (`adoStepsXml` writes `Microsoft.VSTS.TCM.Steps` the way `adoCases` reads it) linked to the story with `TestedBy-Reverse` in its area and iteration. `saveJiraCases` creates issues (type Test by default) with the steps in the description and an issue link.
322
+ - Both reuse a case already linked to the story under the same title, then compare with the story's scope (`cases/scope.ts`: `test_cases` maps an area path or project to a plan, suite, area or JQL filter, values checked before they reach WIQL or JQL, at most `MAX_SCOPE` cases read, steps only for the `shortlist`). The same steps are `reuse`; a case adding steps is `extends` with its `insert`. Nothing is written to an existing case there.
323
+ - `planLinks` checks ids, type and project before `link_test_case` or `update_test_case`'s `story` asks; `insertSteps` applies an `insert`.
324
+ - Other systems: `saveTestrailCases`, `saveZephyrCases`, Xray mode in `saveJiraCases` (`createXrayTest`, `setXraySteps` in `cases/xray.ts`).
325
+ - Cases with no story: `saveAdoCasesInArea` and `saveJiraCasesInProject`. `existingCases` serves `check_test_cases`' `against`.
326
+ - Related modules:
327
+ - `cases/fields.ts` checks `new_cases`; `cases/adodata.ts` writes shared steps references and parameters.
328
+ - `cases/staleness.ts` reads a story's history; `cases/retire.ts` retires a case; `cases/jirareadiness.ts` is release readiness for Jira.
329
+ - `cases/caseindex.ts` keeps a project's index of scope cases' steps; `cases/bulk.ts` prepares several changes for one question (apply_case_changes and the web gateway `web/testcases.ts`); `cases/targets.ts` names a case's system by its id.
330
+ - `cases/changelog.ts`, `cases/trace.ts` and `cases/proposals.ts` keep the project's change log, criteria trace and pending proposals.
331
+ - `cases/requirementsfile.ts` reads Requirements Agent's requirements.json; `cases/scopecheck.ts` checks the settings Settings saves and tries a test_cases line.
332
+
333
+ **`mcp/commands.ts`.** `COMMAND_TOOLS`, one tool per CLI command.
334
+
335
+ - `write_test` runs the coding loop (`runCodeAgent`) and `heal_tests` runs `runHeal`, forwarding their events as `agent` events and ending with a card. Each opens its own agent runtime server on port 0, so it nests inside the brain's session.
336
+ - `monitor`: `round` (one `runMonitor --once`, refused while a background monitor uses the folder), `start`/`stop`/`status` (background monitors, only in `shell` and `server` sessions), `test_alerts`.
337
+ - `logins`: `remember` (session logins), list (configured and remembered), clear (a saved session, and a remembered login's credentials and session file), and `sign_in` through `signIn` and `ctx.waitForUser` (refused without it).
338
+ - `forgeqe_setup`: profiles, MCP servers, `docsAbout` (README and HOW_TO_USE split at headings and scored against the topic, since the agent's `external_directory` rule keeps it out of the package folder), `install_engine`, `init`, `skills` (`op` list, show, or new: `newSkill` into the project's or the user's skills folder).
339
+
340
+ **`mcp/server.ts`.**
341
+
342
+ - `initialize` (protocol 2025-06-18, 2025-03-26, 2024-11-05, with `instructions`), `ping`, `tools/list`, `tools/call`, `notifications/cancelled`.
343
+ - `serveHttp`: Streamable HTTP on 127.0.0.1. It checks the bearer token in constant time (`tokenMatches`) and refuses requests whose `Origin` is not this machine (`originAllowed`), so a web page cannot call the tools.
344
+ - Tool calls answer as an event stream with a progress notification every 10 s and a keep-alive every 15 s, so the agent runtime's per-call timeout (which resets on progress) never fires during a long suite.
345
+ - `serveStdio`: newline-delimited JSON-RPC for `forgeqe mcp`; closing stdin aborts running calls.
346
+ - `localToolServer`: a server over HTTP with a fresh token and the agent runtime's MCP entry for it, used by the brain, the healing session and Quill's tool servers.
347
+
348
+ **`auth/mcpOAuth.ts`.** `oauthSignIn` runs these steps:
349
+
350
+ 1. Protected-resource metadata (RFC 9728).
351
+ 2. Authorization server metadata (RFC 8414, issuer checked, S256 required).
352
+ 3. Dynamic client registration as a public client (RFC 7591).
353
+ 4. The authorization page with PKCE, `state` and `resource`.
354
+ 5. The code on a one-time `Bun.serve` listener on `127.0.0.1:0` (`/callback`, state compared in constant time, plain-text page).
355
+ 6. Token exchange.
356
+
357
+ Every endpoint must be https. The grant is one credential-store entry (`FORGEQE_MCP_OAUTH_<SYSTEM>`), with `mcp:<system>` in auth.json. `refreshMcpSignIns` runs when a session opens (`openBrain`), for `forgeqe mcp list` and when the web app starts: it clears `FORGEQE_<SYSTEM>_MCP_OAUTH`, then exports a current access token (renewed within a minute of expiry) only for the server the settings name now (`oauthResource`, `auth/oauthNames.ts`). `external.ts` and `integrations.ts` use that variable when no token variable is set.
358
+
359
+ **`mcp/external.ts`.** Secrets are `{env:NAME}` references that the agent runtime substitutes. Values that must be derived (base64 of `forgeqe:<PAT>` for Azure DevOps, of `email:token` for Rovo) are put in `FORGEQE_*` variables of ForgeQE's own environment before the agent runtime server starts. A system whose server can't start here (no npx or uvx, missing token, Azure DevOps Server, Rovo on Server/DC) is listed with the reason. The servers get a 120 s timeout, which also covers the first `npx`/`uvx` download.
360
+
361
+ | Server | Started as | Credentials and notes |
362
+ |--------|------------|-----------------------|
363
+ | `azure_devops` | `npx -y @azure-devops/mcp@2.11.0 <org> -a pat\|azcli -d <every group in ADO_GROUPS>` | `hints` from `adoHints`: each prefix's words and keywords, and the `mcp_domains` prefixes on every turn |
364
+ | `atlassian` | `uvx mcp-atlassian` with `JIRA_URL`, `TOOLSETS=all` | `JIRA_USERNAME` + `JIRA_API_TOKEN` or `JIRA_PERSONAL_TOKEN`, plus `CONFLUENCE_*` when `sources.confluence` is set |
365
+ | `atlassian` (hosted) | Rovo at `mcp.atlassian.com/v2/mcp` | Basic auth; also covers Confluence on the same site |
366
+ | `confluence` | `uvx mcp-atlassian` for Confluence alone | when Jira's server doesn't cover it |
367
+ | `github` | GitHub's hosted server (`GITHUB_MCP_URL`) | Bearer `{env:FORGEQE_GITHUB_MCP_TOKEN}`; every toolset unless `sources.github.toolsets` names some; on when `sources.github` is set or the working folder has a GitHub remote |
368
+ | `gitlab` | remote `<url>/api/v4/mcp` | Bearer `{env:token_env}` |
369
+ | `postman` | remote `mcp.postman.com` or `mcp.eu.postman.com` | |
370
+ | `browserstack`, `sentry` | `npx`, or the vendor's hosted server after a browser sign-in when no key is set | credentials as `{env:}` references |
371
+ | `azure` | `npx` | `--read-only` by default, `--namespace` per service |
372
+ | `dataverse`, `aws`, `gcp`, `testmu` | the vendors' own servers | credentials as `{env:}` references |
373
+ | every `mcp:` server | as configured | replaces a built-in one of the same name |
374
+
375
+ `integrations:` is read by `mcp/integrations.ts`: `integrationsConfig` checks each block and `integrationServers` gives its servers.
376
+
377
+ **`cases/dashboards.ts`.** Microsoft's Azure DevOps MCP server has no dashboard or saved-query tools, so `createAdoDashboard`:
378
+
379
+ 1. Runs each widget's WIQL once (`$top=1`), so a bad query fails before anything is written.
380
+ 2. Saves it under `Shared Queries/ForgeQE` (creating the folder, PATCHing a query of the same name).
381
+ 3. POSTs the dashboard (`7.1-preview.3`, team-scoped when a team is given): count tiles (`QueryScalarWidget`, `{queryId, queryName}`) across the top, then work item lists (`WitViewWidget`, `{query: {queryId, queryName}}`) and markdown two to a row.
382
+
383
+ Widget `settings` are JSON strings, as the API requires.
384
+
385
+ After the session opens, `openBrain` reads `client.mcp.status()` and reports each external server as connected, failed (with the error), or needing a browser sign-in; skipped systems are reported with their reason. The agent's session notes list the servers and say that a server whose tools are missing did not connect, so the agent falls back to `query_api`.
386
+
387
+ Tools take structured arguments. `run_test_cases` and `find_test_cases` get a list of `CaseSelector`s (`{source: azure_devops \| jira \| xray \| testrail \| zephyr \| qtest \| file \| text, ids, plan, suite, run, cycle, folder, jql, paths, text}`) that `casesFrom` reads directly, so the model's choice of source is never re-parsed.
388
+
389
+ **Permissions.** These rules are guard rails, not a sandbox.
390
+
391
+ - `bash` is `agentBashPermission`: what `BASH_PERMISSION` allows (everything but `git push` in its spellings, `gh repo delete*` and container commands, each also wrapped in another command), except:
392
+ - Azure DevOps, Jira, Xray and Confluence REST paths,
393
+ - database clients (`DB_CLIENTS`),
394
+ - commands that end processes,
395
+ - ForgeQE's engine folder,
396
+ - any of ForgeQE's secrets by name,
397
+ - ForgeQE's install folder (`selfPathDeny`),
398
+ - `.forgeqe/agents`.
399
+ - The agent runtime matches each command of a chain on its own and applies the last matching rule.
400
+ - `edit` is `ask`: `onPermission` allows it except for files the coding agent wrote in this turn (`editDecision`, `src/brain/coded.ts`). The custom agents' folder is denied.
401
+ - `webfetch` is `ask`, decided by `decideFetch` (`src/brain/webfetch.ts`).
402
+ - `forgeqe_*` tools are allowed.
403
+ - `external_directory` allows the run, memory and working folders.
404
+ - Tool calls to `forgeqe_*` are hidden from the `⚙` lines because their `ToolEvent`s already render richer output (browser steps, suite cards).
405
+
406
+ **Callers.**
407
+
408
+ - **The TUI** opens the brain on the first message and keeps it for the session, so follow-up answers and "write a test for that run" have context.
409
+ - `/profile` (or Tab) switches the model in the same session before the next message (`Brain.setModel`: one agent runtime holds every usable profile, and each prompt names its model), with a one-line note to the agent.
410
+ - A profile the session does not offer (a custom agent's, `code.model`, one that could not answer when it opened) closes it and keeps the turns so far. The next agent session's first prompt is `carryOver(turns, text)`: the last 4 turns and the earlier turns about the new message in full, every other turn as one line (`chooseTurns`, `src/docs/history.ts`), with remembered secrets redacted. Switching models does not lose the conversation.
411
+ - It renders `card` events as result panels and `agent` events as `⚙` and test lines with their own token counter.
412
+ - Its `waitForUser` pushes the prompt into the transcript and opens a **Your turn** dialog (Done, continue / Cancel); opening another dialog or Esc settles it as cancelled.
413
+ - **`forgeqe run`** opens the brain for one request, prints tool events (cards as `cardText`) and the reply as plain lines, waits for Enter in `waitForUser` when stdin is a terminal, and exits 0 done, 1 failed, 2 stopped, 3 needs input. `forgeqe run --direct` and a missing agent runtime run `browser_run` directly.
414
+ - **`forgeqe mcp`** serves the same `TOOLS` on stdio and logs `ToolEvent`s to stderr; it has no `waitForUser`.
415
+ - **`forgeqe chat --jsonl`** (`src/chat/jsonl.ts`) is the TUI's agent for a program. The web app runs one per chat.
416
+ - Like the TUI, it opens the brain on the first message, keeps it for every message, runs with `session: "shell"`, runs Tier 0 requests as recorded before asking the agent, and continues an earlier conversation with `carryOver` (`--carry-over FILE`, with its own reason sentence).
417
+ - Like `forgeqe run`, it takes its flags (`repoFlag`, `memoryFlags`, …) and writes one session log.
418
+ - Like `forgeqe mcp`, it is a machine interface, with stdout claimed for the protocol and every other print sent to stderr.
419
+ - It writes each `CodeEvent` and `ToolEvent` unchanged as a JSON line (`agent`, `tool`), turns `ask` and `waitForUser` into `ask` and `wait` lines answered on stdin, ends every turn with one `turn_done`, and passes every outgoing string through `redactSecrets` and the values of `privateEnvNames` and profile keys. The protocol is in HOW_TO_USE.md.
420
+ - `forgeqe start`, `forgeqe mcp`, and `forgeqe chat` stop background monitors when they return, because `src/index.ts` calls `process.exit`.
421
+
422
+ ## Tool scope (`src/mcp/scope.ts`, `src/capabilities`)
423
+
424
+ Every model call carries the definitions of the tools the agent has, so the agent does not get every tool on every turn. The registry (`capabilities/registry.ts`) groups the tools into capabilities. Each capability has its tools, the requirements it needs (a model, a runtime, an app kind, a tracker), and keywords.
425
+
426
+ | Module | Contents |
427
+ |--------|----------|
428
+ | `mcp/scope.ts` | `CapabilityScope`, one per agent session. See below |
429
+ | `mcp/discover.ts` | `discoverTools` asks every server for its tools (initialize, tools/list) as the runtime starts it: a local command through `spawnPlan` (an argument list; cmd.exe quoting on Windows) with its `{env:}` values filled in and ForgeQE's private variables left out, or a remote address (streamable HTTP, JSON or SSE). The list is kept in `~/.forgeqe/cache/mcp-tools/<hash>.json` (mode 0600) for `LIST_TTL_MS` (a week); the hash is of what the server runs and the names of its variables, never a value or the server's name. `serverGroups` groups each list; a server that does not answer is left out, so its tools stay on |
430
+ | `mcp/toolgroups.ts` | `groupTools` makes a server's groups from its tool names alone. Words of a name are split (snake and camel case), made singular, and verbs and fillers dropped; two words that only ever come together are one ("pull request"). A server whose tools mostly share a first word is split by it; otherwise, and for a prefix group over `MAX_GROUP` tools or `MAX_GROUP_TOKENS`, each tool goes to the rarest word at least 3 of them share, then the rest to words 2 share, the remainder to a catch-all whose keywords are its members' words. Keywords are the group's word or phrase, phrases from its names, plurals, and `SPELLED` (wit: work item); broad words (`WEAK`) are never one alone. A server under `SMALL_SERVER_TOKENS` is one group, always on. `ServerHints` only add titles, keywords and the always-on groups (`mcp/adogroups.ts` for Azure DevOps) |
431
+ | `mcp/lazy.ts` | Other systems' servers started only when a turn needs them. `deferrable` names the servers with tool groups; `openBrain` gives the runtime their entries with `enabled: false` (`deferredConfig`), so a chat starts none of them and signs in nowhere. `ServerStarter.ensure` runs after `beginTurn` and after `use_capabilities` added groups: each server whose group is on (`serverOfGroup`: the server that prefixes all its tools) is started once through the runtime (`connectMcp`, `client.mcp.connect`; the runtime restarts a server asked twice), with "Connecting to …" and connected or why not (`statusWhy`, one line). A failed one is not asked again in that chat. A server without groups (not listed, or `FORGEQE_TOOL_SCOPE=off`) starts with the chat, as its tools are on every turn |
432
+ | `mcp/captools.ts` | `use_capabilities`: adds capabilities for the rest of the session |
433
+ | `mcp/routing.ts` | `createRouter` passes every ForgeQE tool that runs to `scope.used` |
434
+ | `brain/index.ts` | `ask` starts each turn with `beginTurn` and prompts with its switches. When `use_capabilities` added capabilities during the turn, it continues the same request with them, at most `MAX_SCOPE_CONTINUATIONS` (2) times. `FORGEQE_TOOL_SCOPE=off` (or `FORGEQE_ROUTING=off`) turns the scope off |
435
+ | `mcp/server.ts` | With a scope, `tools/list` returns `listedTools`, the server advertises `listChanged`, and after a call that added capabilities it sends `notifications/tools/list_changed`. `forgeqe mcp --all-tools` serves without a scope |
436
+ | `context.ts`, `agents.ts` | `forgeqe context`: the fixed context and what each capability adds. Budgets: 10540 tokens for the forgeqe agent's fixed context (`AGENTS` in `src/agents.ts`), 2500 per capability (`CAPABILITY_TOOL_BUDGET`) |
437
+
438
+ **`mcp/scope.ts`.**
439
+
440
+ - `beginTurn(text)` picks the turn's capabilities and returns the per-prompt `tools` switches (`forgeqe_<tool>: true|false`).
441
+ - The picks are: the core (`setup-help`, `test-apps`), `agent.capabilities.always`, the ones `use_capabilities` asked for, those used in the last `STICKY_TURNS` (3) turns, and up to `MAX_PICKED` (4) from `scoreRequest`.
442
+ - `scoreRequest` makes no model call: it matches keywords and tool names, URLs (the browser), issue keys (test cases), and the names of the active environment's apps (by kind).
443
+ - A capability whose required apps or system are missing (`usableCapabilities`) is not picked from words alone, and nothing is picked from `agent.capabilities.off`. When nothing matches, `browser-goals` is the fallback.
444
+ - `request` (from `use_capabilities`) refuses unknown and switched-off ids and queues the added ones in `takePending`.
445
+ - `listedTools` is the list for MCP clients. `capabilityIndex` is the short list of capabilities in the agent's prompt.
446
+ - Other MCP servers' `ToolGroup`s are switched the same way:
447
+ - `always` ones every turn;
448
+ - a group whose keywords match the request as whole words (they do not count against `MAX_PICKED`; when the request names a system, by a group's `system` words such as "github" or "azure devops", only that system's groups);
449
+ - the ones `use_capabilities` asked for;
450
+ - one whose tool ran in the last turns (`used` takes the runtime name, from `onToolResult`).
451
+ - `toggles` adds a switch per tool of each group. opencode applies a prompt's `tools` to MCP tools by name, so a switched-off group's definitions are not sent (tests/brain-groups.e2e.test.ts).
452
+
453
+ The tools stay registered with the agent runtime for the whole session; only the switches change, so the conversation is never restarted. `tests/scope.test.ts` covers routing, gating, sticky turns, config, hostile ids, and the MCP list change. `tests/brain.e2e.test.ts` checks against the real agent runtime that a turn sees only its tools and that `use_capabilities` continues the request.
454
+
455
+ ## Quill, the coding agent (`src/code`)
456
+
457
+ The test-writing loop used by `forgeqe code`, by `forgeqe suite` with a repo, and by the `write_test` tool, which is how ForgeQE's agent writes tests in the shell and `forgeqe run`. It uses the agent runtime SDK and the runtime binary that `code/runtime.ts` finds.
458
+
459
+ The loop:
460
+
461
+ 1. `handoff.ts` turns the run folder into `handoff.md`.
462
+ 2. A Quill session (`forgeqe-test` agent) writes the test file and reports the command.
463
+ 3. ForgeQE runs the command (`testrun.ts`) and watches for a browser.
464
+ 4. A failure goes back to Quill as a fix prompt with the exit code and output.
465
+ 5. An exit 0 with a browser goes to `review.ts` (the `forgeqe-review` agent, read-only); its issues go back to Quill.
466
+
467
+ | Module | Contents |
468
+ |--------|----------|
469
+ | `handoff.ts` | Builds `handoff.md`. See below |
470
+ | `prompt.ts` | `testAgentPrompt()` (`prompts/test-agent.md`, which includes `prompts/test-rules.md`, shared with healing and the reviewer: browser set up like ForgeQE's, the debugging steps when the test's page differs, generic page objects, data in tests, rules not values, pop-ups handled wherever they appear, every A/B version of a page handled). The test agent's instructions: start from the notes, port the replay script, assert the handoff's checks and nothing else, never guess locators, reuse and extend page objects, do not run the test (ForgeQE runs it), look at the live page with the `live_browser_*` tools once a step has failed. The result JSON schema `RESULT_SCHEMA` (`status`, `blocked_reason`, `remote_browser`, `test_file`, `test_name`, `command`, `reused`, `changed`, `notes`, `lessons`, `tried`). The prepare prompt (notes of at most 25 lines), the first (with the repo notes, naming the live browser's output folder when it is on), fix (the short output plus the saved log and page snapshot), missing-command, no-browser, blocked-challenge, stall, loop, and review-fix prompts |
471
+ | `review.ts` | The `forgeqe-review` agent: prompt (`prompts/test-reviewer.md`), `REVIEW_SCHEMA` (`approved`, `summary`, `issues[{file, problem, fix}]`), and `openReviewer`, a second, read-only Quill session opened on the first passing run and kept for later attempts. `reviewPrompt` inlines the checks from the handoff and the changed files (`changedFiles`: up to 12,000 characters each, 40,000 in all), so the reviewer reads nothing again. It may load Quill's skills and judges the test against their conventions too |
472
+ | `runtime.ts` | Maps the `llms.json` profile to an agent runtime provider, builds the config, starts the agent runtime server, and drives one session over the SDK. See below |
473
+ | `livebrowser.ts` | `liveBrowser(runDir)`: the `live` MCP server for the agent, Microsoft's Playwright MCP (`npx -y @playwright/mcp@0.0.84 --config …`), with a config written to `<run>/live-browser/config.json` from `run.json` `browser` (channel or executable, headless, viewport, locale, time zone, user agent) and snapshots and screenshots saved in that folder. `null` without `npx`. The loop switches its tools (`live_*`) on per prompt once a step fails |
474
+ | `pagefacts.ts` | What a step met that a test handles differently: `frameSelector` for a step's frame, `isAdStep` (an ad host's frame, or `#google_vignette`), and `AD_HOSTS` / `AD_ROUTE` for blocking them. `handoff.ts` renders `covered_by`, `bypass` and `frame` under each step and adds "What covered the page before a click", "Ads on these pages", and "State the run started with" (from `run.json` `sessions_restored`); `replay.ts` skips ad steps and reaches frame steps through `frameLocator` |
475
+ | `replay.ts` | The replay check. See below |
476
+ | `testrun.ts` | Runs the reported command. See below |
477
+ | `loop.ts` (retries) | Each failed attempt (a failed run, a run that opened no browser, a rejected review) adds a `Tried` entry: Quill's `tried` items from its result (else its notes), the failure, and `failureFacts` of the output (the last "waiting for" locator of Playwright's call log, and the element that "intercepts pointer events"), with `again` when an earlier entry failed on the same locator. `nextAttemptPrompt` renders them with `triedSection`; `runHeal` keeps the same list from each test's `reason` and passes it to `healNextPrompt`. The attempt log uses the `tried` items too |
478
+ | `rulebook.ts` | Rules Quill learned (`lessons` in its report, kept only when the job then passed after a failed attempt or a reviewer's change) go to the repository's `.forgeqe/scribe-rules.json` (`RULEBOOK_FILE`) and are given to every later attempt, job and healing session there |
479
+ | `notes.ts` | `scribe-notes.json` in `memory.dir`: per repository, the reading turn's notes (`saveNotes`), when they were written, and up to 15 tests jobs wrote there (`addWrittenTest` on approval). `readNotes` returns nothing past 30 days; `notesSection` renders them for the first prompt |
480
+ | `worktree.ts` | The working tree before the job (`git status --porcelain -uall` with a hash of each file, and a copy of each file up to 5 MB, plus ForgeQE's `forgeqe.yaml` and `llms.json`); the paths the job changed since then; putting back files the job deleted or uncommitted edits it reverted to the committed version; and the protected paths in the form the agent runtime matches them |
481
+ | `loop.ts` | The attempt loop. See below |
482
+
483
+ **`handoff.ts`.** Builds `handoff.md` from `run.json`, `workflow.yaml`, and the page-memory files for every page the run visited:
484
+
485
+ - the result and final URL, labelled as one run's live data, and the judge's reasoning;
486
+ - the browser the run used (`run.json` `browser`);
487
+ - steps in order with values and the JavaScript the agent ran, each group led by the browser agent's note from that step (`process.env.NAME` for secrets);
488
+ - best and ranked locators with confidence: at most `MAX_LOCATORS` = 4, those under `MIN_CONFIDENCE` = 30% dropped unless nothing else is left;
489
+ - a table of each page's other elements: up to `MAX_ELEMENTS` = 8 of `MAX_PAGES` = 4 pages; elements whose best locator a step used are left out, the rest need an interaction or 70% confidence; no table when nothing is left; the table is skipped when a replay pass has page snapshots;
490
+ - the browser agent's checks (`workflow.yaml` `checks`), each with the locator the replay matched on the last page when the counts agree.
491
+
492
+ **`runtime.ts`.**
493
+
494
+ - With `resume`, `openSession` reopens that session with `session.get` (the runtime keeps sessions on disk, so their messages survive a restart) and sets `resumed`; when it is gone, a new one is created.
495
+ - `FailedCommands` counts each exact shell command the agent runs that exits non-zero. At `stallAfter` failures of one command the turn is aborted and `prompt()` returns `stalled` (`command`, `count`, the last 40 lines of output). `resetStall()` clears the counts.
496
+ - `RepeatedLooks` (`REPEAT_AFTER` 6), `RepeatedEdits` (`EDIT_AFTER` 8, `FAILED_EDITS_AFTER` 3) and `RepeatedPlans` (`PLAN_REPEAT_AFTER` 4: the same plan written again with nothing done between) stop a turn the same way.
497
+ - `READ_AGENT` (`forgeqe-read`) has the test agent's instructions with `edit` and `live_*` denied; the config builder takes it in `agents`, and a prompt picks it with `agent`.
498
+ - `PromptOptions` also carries `structured` (off: no JSON answer) and `tools` (per-prompt switches, used only for `live_*`: the agent runtime keeps them for later prompts, and `true` would override the agent's path rules for file tools).
499
+
500
+ **`replay.ts`.**
501
+
502
+ - `replayScript(steps)` turns `workflow.yaml` into `flow.mjs`, one `step(n, action, run)` per recorded step, with each locator rebuilt from its type and value (`locatorExpr`), text typed with `pressSequentially`, secrets read with `env(NAME)` and one-time codes made with `totp(NAME)`. Actions with no Playwright equivalent are marked "not replayed". `alternatives.mjs` holds each step's other locators.
503
+ - `ensurePlaywright` installs `playwright-core` (`PLAYWRIGHT_VERSION`) with Bun into `~/.forgeqe/tools` and removes older versions.
504
+ - `replayRun` writes a runner that launches the run's browser (`replayOptions`: channel or executable, headless, viewport, locale, time zone, user agent, extra headers) and runs each step with a 10 s timeout.
505
+ - After each step that worked, it keeps an aria snapshot of each page (by host and path, the latest one). The final page's is taken once two snapshots a second apart agree, up to 6 s, since a page can change its URL at once and re-render later. They are written as `<setup>-page-N.aria.yml` in `ReplayPass.pages`.
506
+ - On a failure it saves a screenshot and an aria snapshot, counts the other locators' matches, and records console errors, failed requests, and HTTP errors. Three failures in a row stop it.
507
+ - It runs under Bun with the session logins' env, 180 s per pass.
508
+ - The first pass uses Playwright's default launch. If it does not reach the run's final page (host and path), a second pass leaves out `--enable-automation` and adds `--disable-blink-features=AutomationControlled`.
509
+ - `replaySection` renders the handoff section: the page snapshots listed; each pass, the failed steps with Playwright's reason, the page, the open dialogs from the snapshot, the other locators' matches, and the saved files; and the launch settings to copy when only the second pass got through. A pass whose failed steps were followed by steps that all worked and that reached the final page (`reachedPastFailures`) reads as a working script with those steps to judge, and `replayFailed` is false for it, so the live browser stays off.
510
+ - After the last step the runner looks up each recorded check on the page (`findCheck`: a visible exact heading, then exact text, then a looser heading or text, then a form field holding the value) and returns its locator, match count, and up to 3 containers in `ReplayPass.checks`.
511
+ - For a heading match, `sectionOf` adds `section` (the element `aria-labelledby` the heading, else the `section`/`article`/region it heads, else the element after it or after its only-child wrapper) with a stable locator (test id, id, or `aria-label`, else empty) and its visible link and list item counts.
512
+
513
+ **`testrun.ts`.**
514
+
515
+ - Runs the reported command in the repo: `sh -c` on macOS and Linux, `cmd.exe /d /s /c` on Windows, or the argument list ForgeQE built (a migrated test). It runs in the project's workspace container when `containers.workspace` covers the repo.
516
+ - The environment is the terminal's without ForgeQE's secrets (`privateEnvNames`), plus the session logins' variables, `CI=1`, `PLAYWRIGHT_HTML_OPEN=never`, `FORGEQE_REPORT=0` and no colour, with a timeout.
517
+ - `promptOutput` makes the prompt's copy of a failed run: `withoutPageDumps` takes out each "Aria snapshot:" block Playwright puts in a failed assertion, then `headAndTail` keeps the first 8,000 and the last 4,000 characters. The full output goes to `<run>/test-runs/attempt-N.log` and the first page dump to `attempt-N-page.aria.yml`.
518
+ - While it runs it samples the process tree (`ps -A -o pid=,ppid=,args=` every 250 ms; `Get-CimInstance Win32_Process` every 1.5 s on Windows) for browsers at or below the command that carry an automation switch (`--remote-debugging-pipe`, `--remote-debugging-port`, `-juggler-pipe`, `--inspector-pipe`, `-marionette`) and returns them as `browsers`.
519
+
520
+ **`loop.ts`.**
521
+
522
+ - **Attempts and stops.** The attempt loop and stop handling.
523
+ - **Replay** (`code.replay`, on by default): `replayRun` runs while Quill reads the repo, then the handoff is rebuilt with the replay and the result goes to `code.json` `replay`. Skipped when `canReplay` finds no step beyond navigation and no checks.
524
+ - **Reading turn** (`READ_AGENT`, no structured answer, with or without a replay). Skipped when `readNotes` has notes for the repo, which go into the first prompt instead. Its reply is saved as the notes.
525
+ - **Live browser** (`code.live_browser`, on by default). Its tools are off until the replay or a test run fails, a stall, a no-browser run, or a blocked report, and the prompt that switches them on says so.
526
+ - **Stall guard** (`code.stall_after`, default 5; counts reset after each ForgeQE test run).
527
+ - **Loop guards.** `code.repeat_after`, default 6: `RepeatedLooks`, look-ups whose answer is unchanged. `code.edit_after`, default 8: `RepeatedEdits`, edits to files already changed, and `FAILED_EDITS_AFTER` (3) edits that failed on lines the file no longer has. `RepeatedPlans` (`PLAN_REPEAT_AFTER`, 4). All reset after each test run. Each kind of loop gets `loopPrompt` once, then the job stops. A stop's notes say whether a test ever ran and which files were left changed (`stopFacts`), and its `test` event has `ran: false`.
528
+ - **`code.json`.** The run folder is recreated if it is gone, and a failed write is reported without changing the result.
529
+ - **Resuming.** `scribe-session.json` in the run folder (session id, repo, stage `reading`/`writing`, whether the live browser is on) is written when the session opens, updated as the job goes, and removed when the job ends with a result. After a stop, a crash, or a `ProviderAuthError`/`APIError` it stays, and a rerun for the same run and repo passes it as `openSession`'s `resume`. The session file also keeps the files the job changed (`changed`, saved after every edit, read back by `carriedPaths`).
530
+ - A rerun of a job that stopped while writing opens a fresh session whose first message is `brief(carriedOnTask)`.
531
+ - One that stopped while reading reopens its session with `RESUMED_NOTE` plus the first prompt.
532
+ - Either skips the reading turn and takes `savedReplay` when the replay finished.
533
+ - **`brief`** (the job's target or existing test, environment, notes, plan, `planFindings`, handoff, attempts and files) also starts every later attempt and the session after a raised budget (`BUDGET_RAISED`).
534
+
535
+ **Config.** The whole agent runtime config is passed through the environment, so nothing is written into the repo. Keys are `{env:NAME}` references, never values. Profile mapping:
536
+
537
+ | Profile | Agent runtime provider | Model |
538
+ |---------|-------------------|-------|
539
+ | `azure` | `azure`, `baseURL: <endpoint origin>/openai/v1` (Responses API, `api-key` header) | `azure/<deployment>` |
540
+ | `openai` | `openai`, `baseURL` when set | `openai/<model>` |
541
+ | `openai_compatible`, `ollama` | `forgeqe` via `@ai-sdk/openai-compatible` and the profile's `base_url` | `forgeqe/<model>` |
542
+ | `github_copilot` | the Copilot gateway (`python -m forgeqe_engine copilot-gateway` on 127.0.0.1) as an `openai_compatible` profile (`engineRoute`) | `forgeqe/<model>` |
543
+
544
+ - A profile with `auth: entra` reaches the runtime through a local gateway that adds an Entra ID token to each request (`entraGateway`); the runtime holds no key.
545
+ - A chat's runtime holds every usable profile at once (`switchableProfiles`, `providerSet`: a second endpoint of the same provider becomes `fq-<name>`), so the model changes without a new session.
546
+ - `code.model` skips the mapping and uses the agent runtime's own provider setup. `code.model` with `github-copilot/…` is refused.
547
+
548
+ The `forgeqe-test` agent is a primary agent with its own prompt and permissions:
549
+
550
+ - `edit`: allowed, except ForgeQE's files and folders (`.forgeqe/`, `forgeqe.yaml`, `llms.json`, the run and memory directories). The agent runtime matches edit patterns against the path relative to the git worktree root (or the filesystem root outside git), so the patterns are built the same way
551
+ - `bash`: allowed, except `git push*` (and its `git -C`/`-c` spellings), `gh repo delete*`, container commands (`docker`, `podman`, `nerdctl`, `docker-compose`, `podman-compose`), package installs (`INSTALL_PERMISSION`: ForgeQE installs packages itself, `installPackages` in `deps.ts`), commands that name ForgeQE's paths, and commands that throw away uncommitted work (`git clean*`, `git reset --hard*`, `git stash*`, `git restore*`, `git checkout -- *`, `git checkout .*`), each also when wrapped in another command. Shell rules cannot catch every spelling, so after each attempt `restoreRemoved` also puts back ForgeQE's files (`forgeqe.yaml`, `llms.json`) when the job changed them, not only when it deleted them; healing does the same at the end of its job, with the same edit and shell rules
552
+ - `webfetch`: allowed
553
+ - `question`: denied
554
+ - `external_directory`: allowed for the run and memory directories and the skill folders; anything else is `ask`, which ForgeQE declines ("Stay inside the repository.")
555
+ - `doom_loop`: `ask`, which ForgeQE declines with "You are repeating the same call. Try a different approach."
556
+
557
+ The session's MCP servers:
558
+
559
+ - `live`: Playwright MCP, when `code.live_browser` is on.
560
+ - `code`: code-graph tools, when the repository's code graph is available.
561
+ - `data`: database tools, when `databases:` names one.
562
+ - `request`: `requestTools`, for packages, commands and changes a person approves.
563
+
564
+ The repo path is resolved with `realpath` (macOS `/var` is `/private/var`), and both forms are allowed.
565
+
566
+ **Events.** `event.subscribe` streams the session. Tool parts become `⚙` lines with repo-relative paths (`edit tests/login.spec.ts`, `bash npx playwright test …`). Finished text parts become the agent's thoughts, and `step-finish` tokens feed the token counter. Permission requests the config does not settle are declined straight away (`declineMessage` tells the model why), so the session never waits for a person and nothing outside the config is granted: not paths outside the repository, not repeated identical calls, and not the runtime's own "ask" defaults such as reading `.env` files. A session given `onPermission` (ForgeQE's agent, custom agents) has those requests answered by it instead.
567
+
568
+ **Environment and secrets.**
569
+
570
+ - `openSession` starts the runtime itself (`startServer`: `<runtime> serve --hostname=127.0.0.1 --port=0`) with an explicit environment (`serverEnv`), never by changing `process.env`.
571
+ - That environment is the terminal's without ForgeQE's own secrets (`privateEnvNames`: every profile's key variable, tracker and alert credentials, variables `mcp:` servers reference) except those its config references as `{env:NAME}`, plus the values ForgeQE derives for MCP servers (`secrets`, e.g. base64 of email:token).
572
+ - The runtime's data, config, state, cache and temporary folders point into `~/.forgeqe/runtime` (`runtimeFolders`); the commands and MCP servers it starts get the person's own values back.
573
+ - A runtime plugin (`hideEnvPlugin`, the runtime's `shell.env` hook) blanks all of those secrets, and `OPENCODE_CONFIG_CONTENT`, in every shell command the agents run, so a prompt injected by a page under test cannot read the model key or tracker tokens. Saved-login variables stay visible: the tests read them.
574
+ - A second plugin (`pausePlugin`) holds every tool call while Talk has paused the turn.
575
+ - With `containers.workspace`, `SHELL` points at the workspace's script, so the agents' commands run in the project's container.
576
+
577
+ **Result.** Each prompt sends `format: {type: "json_schema"}`, and the model answers through the agent runtime's `StructuredOutput` tool. The result is read from the `message.updated` event (`info.structured`, or `info.error`), not from `session.messages`: in the pinned agent runtime that endpoint returns BadRequest for any session that used `format`.
578
+
579
+ **Loop.** ForgeQE does not trust the model's claim that the test passes. Quill does not run the test; it reports the command and ForgeQE runs it.
580
+
581
+ | When | ForgeQE |
582
+ |------|---------|
583
+ | a non-zero exit or a timeout | sends a fix prompt with the command, exit code, the short output (`promptOutput`), and the paths of the full log and the page snapshot |
584
+ | an exit 0 with no browser under the command | sends the no-browser prompt, unless the agent reported `remote_browser` |
585
+ | a missing command | sends a reminder |
586
+ | a failure whose output matches the previous one apart from numbers (`failureKey`) | sends the repeated-failure prompt (look at the failing step before changing code); a third one in a row ends the loop as `failed` with the output in the notes |
587
+ | a stalled turn (one command failed `stall_after` times inside it) | sends the stall prompt with the command and its output once; a second stall ends the loop as `failed` with that output in the notes |
588
+ | a passing run with a browser | sends it to the reviewer, with the paths this job changed and the paths the user already had uncommitted, so it never asks for the user's work or ForgeQE's files to be removed; its issues go back as the next prompt |
589
+ | the first `blocked` report | sends the blocked-challenge prompt (compare the test's browser with the handoff's "Browser ForgeQE used" and fix the difference); a second one ends the loop as `blocked` |
590
+
591
+ After every agent turn, files that existed before the job and are now gone or reverted are put back, `handoff.md` is rewritten if missing, and the next prompt says what was restored. So are the agent's changes to package files (`restoreDeps`) and to the test-runner config the whole suite shares (`restoreTestConfig`, `deps.ts`: `playwright.config.*`, `cypress.config.*`, `wdio.conf.*`, Nightwatch's config, `.runsettings`; never through a link; a repository with none keeps the one the agent sets up). Browser options a test needs go in its own file (a top-level `test.use` in a Playwright spec), and a change the suite needs goes through `request_change`, which a person approves. Each of these counts as an attempt.
592
+
593
+ The loop ends:
594
+
595
+ - when a passing run is approved (`passed`);
596
+ - after `max_attempts` (`failed`);
597
+ - when the reviewer gives no verdict (`failed`);
598
+ - on `ProviderAuthError`, `APIError`, `ContextOverflowError`, or `ContentFilterError` (`failed`);
599
+ - on Esc (`stopped`, which aborts the session).
600
+
601
+ Both servers are closed in every case, and the reviewer's tokens are added to the result's usage.
602
+
603
+ The `forgeqe-review` agent overrides the permissions key by key (`AgentSpec.permission`): `edit`, `webfetch`, and `task` denied, and `bash` denied except `git diff*`, `git status*`, `git log*`, `git show*`, and `ls*`.
604
+
605
+ ## Skills (`src/skills`)
606
+
607
+ Agent Skills folders (`<name>/SKILL.md`: YAML frontmatter with `name`, `description`, and ForgeQE's `agents`, then Markdown) that ForgeQE's agent, Quill, and the browser agent use. `skills:` in `forgeqe.yaml` becomes `SkillsConfig` (`enabled`, `projectDir`, `userDir`, `dirs`, `disable`, `external`, `browserMaxChars`).
608
+
609
+ | Module | Contents |
610
+ |--------|----------|
611
+ | `registry.ts` | `skillRoots` in precedence order, lowest first: prebuilt (`skills/` in the package), external (only with `external`: `~/.claude/skills`, `~/.agents/skills`, and the repo's `.claude`/`.agents` skills), user (`$FORGEQE_HOME/skills`), project (`.forgeqe/skills` next to `forgeqe.yaml`, and the repo's own), then each `dirs` folder. `loadSkills` reads every `<root>/<name>/SKILL.md`, validates it (name lowercase words joined by hyphens, at most 64 characters, the same as the folder; description present, at most 1,024 characters; `agents` from `forgeqe`/`scribe`/`browser`, default `forgeqe` and `scribe`; file at most 100 KB), and reports a broken one in `problems` instead of failing. A later source replaces a skill of the same name and records `overrides`; `disable` then moves skills to `disabled`. `skillsFor(reg, agent)` filters by audience. `linkSkills` makes a temporary folder of links (junctions on Windows) to the chosen skill folders, one per name; `remove` unlinks them and never follows them |
612
+ | `select.ts` | `browserSkills(cfg, goal, names?)`: with names (ForgeQE's agent, `--skill`), `skills_pick: "given"` with only those browser skills (unknown names returned for a warning; `[]` means none); without, `"choose"` with every browser skill's name, description, and body. `rememberChoice` keeps the engine's choice per goal for the life of the process, so monitor rounds and repeated cases send `"given"`; it is kept only when the engine actually chose (`run.json` has `skills`) |
613
+ | `scaffold.ts` | `newSkill` writes a `SKILL.md` template (the body hints at the agent it is for) and refuses an existing one; `setSkillDisabled` edits `skills.disable` through a YAML `Document`, so comments survive, and drops the key when the list is empty; `ignoredNote` warns when git would not commit a new project skill |
614
+ | `view.ts` | `skillsOverview` (per agent: name, source and what it replaces, description; disabled; problems; folders read) and `skillDetail`, shared by `forgeqe skills` and `/skills` |
615
+
616
+ **Agent runtime.**
617
+
618
+ - `openSession(…, skills)` keeps the skills whose `agents` include an audience of the session's agents (`AgentSpec.skills`: `forgeqe` for the brain; `scribe` for `forgeqe-test`, `forgeqe-read`, `forgeqe-review`, `forgeqe-test-plan`, `forgeqe-heal`, `forgeqe-migrate`, `forgeqe-tosca`, `forgeqe-find`, `forgeqe-pr-review` and `forgeqe-api`; none for every other agent `src/agents.ts` lists). It links them with `linkSkills` and passes the folder as `skills.paths`.
619
+ - Each agent's `skill` permission is `{"*": "deny", <name>: "allow", …}` for its audience, or `"deny"` with none, so the runtime's built-in skills and a repo's `.opencode/skills` stay unloadable and out of the listing the model chooses from.
620
+ - `OPENCODE_DISABLE_EXTERNAL_SKILLS=1` and `OPENCODE_DISABLE_CLAUDE_CODE_SKILLS=1` turn off the runtime's own discovery of `~/.claude/skills`, `~/.agents/skills`, and the project's.
621
+ - The links folder and each skill folder (and their real paths) are added to `external_directory` and made read-only: added to the session's protected paths, or, for a session without them, passed as `readOnly` (edit and bash denied for those paths only).
622
+ - ForgeQE's agent keeps write access to user and project skills, so it can change one when asked; built-in and global skills stay read-only for it too.
623
+ - Completed `skill` tool calls show as "Using skill NAME" and are collected in `skillsUsed`, which `runCodeAgent` and `runHeal` put on their results.
624
+ - `SKILL_RULE` in each agent's prompt says to load a skill whose description fits the job and that the prompt wins where they disagree.
625
+
626
+ **Browser runs.** `environmentNotes` lists the browser skills for ForgeQE's agent, and `browser_run` and `run_test_cases` take `skills` (names). `executeRun` calls `browserSkills` and sends the result in the engine request; the engine chooses (`choose_skills`) or uses them, adds the text within `skills_max_chars`, logs "Skills for this run: …" (and the ones left out for size), and writes `skills` to `run.json` only when it decided, so a replay that finished without the agent leaves the choice open. `run.done` in the session log, `RunResult.skills`, and the report's case header carry them; a case's Quill skills go to `CaseResult.code.skills`.
627
+
628
+ ## Healing (`src/heal`)
629
+
630
+ `forgeqe heal` repairs a repo's existing tests after the app changed, and reports app bugs instead of hiding them. Like the coding loop, ForgeQE decides what passed by running the commands itself.
631
+
632
+ The loop:
633
+
634
+ 1. ForgeQE runs the test command once as a baseline (`testrun.ts`). If it passes, the result is clean and no model is used.
635
+ 2. If it fails, a Quill session (`forgeqe-heal` agent) gets MCP tools: `browser_run`, `run_details`, `run_test`, `page_memory`, plus the `data` and `request` servers.
636
+ 3. It replies with `tests[]`, each `healed`, `app_bug` or `not_healed`, with its own command.
637
+ 4. ForgeQE runs each healed test. One that fails gets the still-failing prompt.
638
+ 5. When all pass, ForgeQE runs the whole command. If it fails, the agent gets the remaining prompt.
639
+ 6. When the whole command passes, the result is `passed`. Otherwise the next attempt starts, up to `code.max_attempts`.
640
+
641
+ | Module | Contents |
642
+ |--------|----------|
643
+ | `prompt.ts` | The heal agent's procedure (`prompts/heal.md`): failing tests only; re-run each one's flow with `browser_run` as a plain-language goal; a passing run means the test is out of date, so read `run_details` and update the locators where they live (page objects); a run that fails at the same step means an app bug, and the test is left alone; never delete, skip, loosen, or slow down a test; verify with `run_test`. `HEAL_SCHEMA`: `{tests: [{name, file, status, command, reason, run_dir}], changed, notes, suite_command}`. The find-command, first, still-failing, remaining, and missing-tests prompts |
644
+ | `loop.ts` | `runHeal`. See below |
645
+ | `report.ts` | `healMarkdown` (verdict table, files changed, browser runs, test output before and after) and `formatHeal`, the terminal summary (✓ confirmed, ? healed but not confirmed, ! app bug, ✗ not healed) |
646
+
647
+ **`loop.ts`.**
648
+
649
+ - The command is the argument, `code.test_command`, or `suite_command` from a first prompt that asks the agent to find it.
650
+ - The heal session gets its own `localToolServer` with only the four tools above (`HEAL_TOOLS`), a `data` server with the databases' read tools when `databases:` names one, and a `request` server (`agentRequests`) for packages, commands and shared-config changes a person approves (`code.requests`).
651
+ - Browser runs are written inside the heal folder (`export.out_dir` is pointed there), and their folders are recorded from `run-done` events.
652
+ - Tests are merged by name across replies. A healed test counts only after ForgeQE runs its command; a healed test with no command is sent back.
653
+ - The whole command runs after every attempt whose tests all pass, and once more at the end if tests were confirmed since.
654
+ - The loop ends when the whole command passes (`passed`), when a reply heals nothing new (`failed` if the command still fails), after `max_attempts`, on the same fatal errors as the coding loop, or on stop.
655
+ - `heal.json` and `heal.md` are written in every case.
656
+
657
+ In the shell and `forgeqe run`, ForgeQE's agent calls the `heal_tests` tool, which runs `runHeal`, so "the login tests broke, fix them" goes through the same loop and the same checks as `forgeqe heal`. `heal/loop.ts` loads `src/mcp/tools.ts` with a dynamic `import()` when healing starts (`openAgent`), because `tools.ts` loads this module through its tool modules.
658
+
659
+ ## Finding and running existing tests (`src/code/find.ts`, `src/mcp/repotests.ts`, `src/cases/sprints.ts`)
660
+
661
+ "Run all tests related to login" and "run the tests added this sprint" select tests that already exist in the repo. Quill decides which tests match by reading them. ForgeQE confirms the selection with the framework's own list command, and nothing runs until the user agrees.
662
+
663
+ The flow:
664
+
665
+ 1. The request comes with a time range (since, until) or a sprint picked from Azure DevOps or Jira through `ctx.ask`.
666
+ 2. A read-only Quill session (`forgeqe-find`) answers with `tests[]`, `related[]`, `list_command` and `run_command`.
667
+ 3. ForgeQE runs `list_command` and gives the listing back to Quill. If Quill changes the selection, ForgeQE lists again, at most 3 times. It stops when Quill answers `list_matches` with nothing changed.
668
+ 4. ForgeQE writes `selection.json` and shows a card.
669
+ 5. `run_tests` asks "Run N tests?" through `ctx.ask`. On Run, ForgeQE runs `run_command`.
670
+ 6. ForgeQE reads the JUnit XML or TRX results into `results.json` and a card per test.
671
+
672
+ **`code/find.ts`**
673
+
674
+ - `FIND_AGENT` (`forgeqe-find`): `edit`, `webfetch` and `task` denied; `bash` denied except `git log/show/diff/blame/ls-files/rev-parse/status` and `ls`. The session is routed as `planning`.
675
+ - Its prompt:
676
+ - work out the frameworks;
677
+ - decide each test from its body and the helpers it calls (a name alone neither includes nor excludes it);
678
+ - a time range means tests added in it, from git history, including new functions in existing files (tests only modified go under `related`);
679
+ - one test per entry;
680
+ - the two commands.
681
+ - `FIND_SCHEMA`: `{framework, tests: [{name, file, reason, added}], related, list_command, run_command, results_file, list_matches, notes}`.
682
+ - `findTests`:
683
+ - opens the session with `readDirs` set to the repo only;
684
+ - gives it today's date, the shell, the range, and the JUnit and TRX paths inside a new `<export.out_dir>/tests/<time>/` folder;
685
+ - runs `list_command` with `runTestCommand` (`LIST_TIMEOUT_SECONDS`, 180 s), only when `listCommandAllowed` passes: one test runner of `LIST_RUNNER`, a listing flag of `LIST_FLAG`, no shell syntax. Any other list command is reported and not run;
686
+ - feeds the listing back, at most `LIST_ROUNDS` (3) times, until Quill confirms an unchanged selection (`listed`);
687
+ - writes `selection.json`.
688
+ - `runSelection`:
689
+ - deletes stale result files and runs `run_command` with `code.test_timeout_seconds`;
690
+ - collects the fresh `.xml`/`.trx` files (the given file, or a folder one level deep) and parses them with `parseResults`: JUnit `testcase` at any depth with `failure`/`error`/`skipped`; TRX `UnitTestResult` outcomes and `hh:mm:ss` durations. Without results the exit code decides;
691
+ - runs failed tests again (`flaky.retries`, default 1) through `retryCommand`: Playwright `--last-failed`, pytest `--lf`, Jest `--onlyFailures`, else the whole command for up to 20 tests. A test that then passes is `flaky`;
692
+ - records each result in the repository's `.forgeqe/test-history.json` (`recordResults`, `src/code/history.ts`). A quarantined test's failure does not fail the run. `flaky.quarantine` (`suggest`, `auto` or `off`) decides whether ForgeQE offers quarantine or applies it;
693
+ - writes `output.log` and `results.json` in the selection's folder.
694
+ - `selectionCard` and `resultsCard` draw the cards.
695
+
696
+ **`mcp/repotests.ts`**: `REPO_TEST_TOOLS`, appended to `TOOLS`.
697
+
698
+ | Tool | What it does |
699
+ |------|--------------|
700
+ | `list_sprints` | The recent sprints, or all of them |
701
+ | `find_tests` | Validates dates and resolves `sprint`: a name through `findSprint`, else `ask` offers up to eight `recentSprints` through `ctx.ask`, or returns them as `needs_choice` when there is no `ask`. Runs `findTests` and emits the selection card |
702
+ | `run_tests` | Loads the selection and asks **Run N tests? / Don't run** through `ctx.ask`. Without `ask` (`forgeqe mcp`, or `forgeqe run` without a terminal) it returns `needs_confirmation` until called with `confirmed: true`. Failures come back with a `heal_tests` suggestion, and flaky tests with a `quarantine_tests` suggestion |
703
+ | `flaky_tests` | Each test's recent trail and pass rate from the history |
704
+ | `quarantine_tests` | Puts tests in quarantine or releases them, after asking (`needs_confirmation` without `ask`). A quarantined test that passes `RELEASE_AFTER` runs in a row is offered for release |
705
+
706
+ **`cases/sprints.ts`**
707
+
708
+ - Azure DevOps: `work/teamsettings/iterations` (the project's default team, or `team`).
709
+ - Jira: agile `board?type=scrum` (by project or board, up to five boards), then `board/{id}/sprint`, paged.
710
+ - Both become `Sprint {system, name, start, end, state: current | past | future, where}`. A system that fails is reported in `errors`.
711
+ - `recentSprints` keeps each team's or board's current sprint, its three latest past ones, and the next one.
712
+
713
+ **`ctx.ask`** is how a tool puts a choice to the user.
714
+
715
+ - The TUI opens an **ask** dialog and pushes the question's `lines` into the transcript. Options are stacked vertically when there are more than three or they do not fit. Ids are prefixed `ask:` so they never collide with the stop and close choices. Esc, another dialog, or Ctrl+C resolve `null`.
716
+ - `forgeqe run` prints numbered options when stdin is a terminal.
717
+ - The brain prompt routes repo tests to `find_tests` and test cases in test management systems to `run_test_cases`. It forbids running a selection any other way or without that confirmation.
718
+
719
+ ## Test cases and suites (`src/cases`, `src/suite`)
720
+
721
+ Every source becomes the same `TestCase`: id, title, source, link, description, preconditions, steps (`action`, `data`, `expected`), start URL, tags, and a `ref` with what write-back needs (work item, test point, plan, issue key).
722
+
723
+ | Module | Reads | Writes back |
724
+ |--------|-------|-------------|
725
+ | `files.ts` | text (`---` blocks), CSV (RFC 4180; step rows continue a case), YAML/JSON, Gherkin (Background, Outline × Examples, Then → expected) | nothing |
726
+ | `ado.ts` | `workitemsbatch` for ids; `testplan` suites and test points with `x-ms-continuationtoken` paging; the Steps XML (fast-xml-parser, order kept), shared steps through `compref`, parameter rows from `LocalDataSource` | a test run per plan: create with the point ids, set each result's outcome and comment, complete the run. Cases read by id: a work-item comment |
727
+ | `jira.ts` | Cloud: `/rest/api/3/search/jql` (`nextPageToken`), ADF descriptions. Server/DC: `/rest/api/2/search` (`startAt`), bearer PAT | an issue comment (ADF on Cloud) |
728
+ | `xray.ts` | Cloud: token from `/api/v2/authenticate`, then GraphQL `getTests` / `getTestPlans`. Server/DC: `/rest/raven/1.0/api/test` and `testPlanTests` JQL | an import per plan: a Test Execution with statuses, step statuses and actual results, comments, and `failure.png` as evidence |
729
+ | `testrail.ts` | `get_case`, `get_tests/<run>`, `get_plan`, `get_cases/<project>&suite_id=` (paged by `_links.next`); separated steps or the text template | `add_results_for_cases` on the source run, or `add_run` per suite; `custom_step_results`; `add_attachment_to_result` for `failure.png` |
730
+ | `zephyr.ts` | Zephyr Scale Cloud v2: `testcases/<key>`, `teststeps` (call-to-test inlined to depth 2), `testexecutions?testCycle=`, `testcases?folderId=` | `testexecutions` per case with `testScriptResults`, in the source cycle or a new `testcycles` per project |
731
+ | `qtest.ts` | `test-cases/<id>?expandSteps=true`, `test-runs?parentId=&parentType=test-cycle\|test-suite` | `test-runs/<id>/auto-test-logs` with `test_step_logs`; cases read by id get a new test cycle and test runs |
732
+ | `github.ts` | GitHub issues as cases (`github:owner/repo#12`, `github:#12,#13`, `github:label=…`, `github:q=…`), signed in with `sources.github.token_env` or the GitHub CLI's token | an issue comment |
733
+ | `servicenow.ts` | ServiceNow Test Management tests and their steps through the Table API (`test_table`, `step_table` and `step_parent` are settings) | nothing |
734
+ | `confluence.ts` | Cloud: `api/v2/pages/<id>?body-format=storage`, CQL through `rest/api/search`. Server/DC: `rest/api/content`. Storage format to text with table cells kept apart | nothing; for the `read_confluence` tool |
735
+ | `bugs.ts` | nothing | with `sources.bugs`, in Jira, Azure DevOps or GitHub: per failed case, find an open bug by the case's fingerprint label or tag (JQL `labels = … AND statusCategory != Done`, or WIQL `Tags CONTAINS … AND State NOT IN (…)`); comment "Still failing" on it, or create one (ADF or ReproSteps HTML, labels or tags, area path, screenshot attachment, "Relates" link or `TestedBy-Forward` relation to the test case). A passed case notes on its open bug that it passes again |
736
+
737
+ **Write-back.** Every write-back includes the step verdicts. When a system rejects them, it retries once without the step details. Each `WriteBack` carries the `caseId` it is about, so the report shows it with that case.
738
+
739
+ **Loading.**
740
+
741
+ - `http.ts` is the one HTTP helper. Tokens come from the environment variables `sources:` names. Errors show the method, host, path and status, never a credential.
742
+ - For `forgeqe suite` and `forgeqe cases`, `refTarget` (`refKind`) picks a source in this order:
743
+ 1. the reference's prefix (`ado:`, `jira:`, `xray:`, `testrail:`, `zephyr:`, `qtest:`, `github:`, `servicenow:`);
744
+ 2. an existing file;
745
+ 3. ids or links that exactly one configured system settles (`resolveId`). An id several systems could hold is an error that asks which;
746
+ 4. plain text.
747
+ - The agent's tools skip this and pass structured selectors to `casesFrom`.
748
+ - `loadCases` adds `~2`, `~3` to repeated ids.
749
+
750
+ **Goals and handoff.** `goalFor` turns a case into the agent's goal: numbered steps, each with its data and "Expected: …", and an instruction to check every expected result and fail the task if any is not met. `caseMarkdown` goes into the coding handoff (from `testcase.json` in the run folder) and asks Quill to name the test `<id> <title>`.
751
+
752
+ **`runSuite`.**
753
+
754
+ - Each case gets a run folder `NN-<id>`, and `executeRun` runs with a pool of `parallel` workers.
755
+ - A data-driven case (`each:`, `--each`) becomes one case per row before anything runs. Its test is written once, from the first row that gets that far.
756
+ - With a repo, a passed case is queued for the coding agent as soon as its browser run ends. Its worker awaits that job before taking the next case, so each case is explored, handed off and coded before the next one starts. The queue is one promise, so coding jobs never overlap.
757
+ - A case that is not coded records `codeSkipped` with the reason.
758
+ - A case whose failure is a functional defect files its bug as soon as its run ends (on one device), so the test written for it can name the bug.
759
+ - The first case of a new defect runs once more in `<case>/reproduce/` (`defects.reproduce`, on by default) to see whether it repeats.
760
+ - Results are posted back, and the remaining bugs filed, after every case finishes. Stopped cases are skipped.
761
+
762
+ **Suite reports** (`report.ts`):
763
+
764
+ - `junit.xml`: failed → `<failure>`, error → `<error>`, stopped → `<skipped>`; step verdicts and posted links in `system-out`.
765
+ - `report.html`: `src/report/data.ts` turns the results into `ReportData`:
766
+ - step verdicts, and the `steps.json` timeline with screenshots as data URIs up to a 40 MB budget;
767
+ - failed cases first;
768
+ - small text files such as the trace and workflow;
769
+ - posted records;
770
+ - each run folder's `run.json` (page memory with heals and repairs, browser diagnostics) and `accessibility.json`;
771
+ - the case's group and requirements, usage and cost;
772
+ - history from the sibling `.forgeqe/reports/suites/*/suite.json`. From that history it finds each failed case's last passing run folder (next to its `suite.json`, else where it was written) for the "last good vs now" screenshot of the same URL path, and each memory-replayed case's last run with no replay, as the baseline for page memory savings.
773
+
774
+ `src/report/html.ts` injects the data as `window.__FORGEQE_REPORT__` into `src/report/template.html`, a React app from `report-ui/` built into one file by `bun run build:report`. Every single run writes one too.
775
+ - `suite.json`, the terminal summary, and the GitHub job summary (appended to `GITHUB_STEP_SUMMARY` when set).
776
+
777
+ The `run_test_cases` tool calls the same `runSuite`. It passes the working directory, and `runCodeAgent` as the coder when the session writes tests, so the agent never calls `write_test` for those cases afterwards. The shell renders a suite card. There is no pipeline template: the agent writes pipelines to fit each repository, and they call `forgeqe suite`.
778
+
779
+ ## Environments (`src/environments.ts`)
780
+
781
+ `env.yaml` lists the environments and their apps. It is named by `environments.file`, or `environments.dir` holds one file per environment.
782
+
783
+ - Any layout is read: `environments:` maps, top-level maps, or lists. All become the same `Environment`: `apps` by kind (web, api, desktop, mobile), `variables`, and `secrets` as names of environment variables.
784
+ - The active environment is `--env` or `FORGEQE_ENV`, else forgeqe.yaml's default, else env.yaml's. The `use_environment` tool switches it.
785
+ - `withEnvironment` gives a config for one tool call's `env`.
786
+ - `exportEnvironment` puts these into the environment of the tests ForgeQE runs: `FORGEQE_ACTIVE_ENV`, `FORGEQE_APP_<APP>_URL`, `_PATH` and `_ID`, `FORGEQE_VAR_<NAME>`, `FORGEQE_DATA_<NAME>` and `FORGEQE_CLOUD_*`. Never secrets, and no value that holds a line break.
787
+ - `environmentBrief` is what each agent is told: ForgeQE's agent gets every app, the browser agent its hosts, and Quill the names to read so a test runs in every environment.
788
+
789
+ ## Desktop apps (`src/desktop`, `py/forgeqe_desktop`)
790
+
791
+ `python -m forgeqe_desktop serve` takes JSON-lines requests from `src/desktop/bridge.ts`, as the browser engine does.
792
+
793
+ - **Explore** runs UFO² in-process (`ufo_runner.py`, at a pinned commit, `UFO_COMMIT`) with the profile's model. Only UI actions are allowed, Win-key chords are refused, and the action trace becomes a `forgeqe-desktop-v1` workflow (`record.py`).
794
+ - **Replay** (`replay.py`) needs no model. It runs on the driver `desktop.driver` names:
795
+ - `pywinauto` (`pywinauto_driver.py`, Windows);
796
+ - agent-desktop (`agentdesktop_driver.py`, macOS, Linux and Windows, headless; `desktop.headed` allows physical input);
797
+ - `auto`, the default: pywinauto on Windows, agent-desktop elsewhere.
798
+
799
+ Replay handles timeouts, retries, `wait_for` and `dismiss`, `expect_image` (`visual.py`), heal by numbered choice (`heal.py`), and checks of the outcome (`checks.py`). Each run records `video.mp4` unless `desktop.video` is off.
800
+ - **Recording by hand** (`handrecord.py`, `handhooks.py`) uses Windows hooks and UI Automation.
801
+ - **Changes from chat:** `src/desktop/edit.ts` makes fixed-shape changes, validates them, shows the diff, and keeps a backup.
802
+ - **Before a run:** `session.py` refuses a session that cannot be driven (session 0, locked, no screen), and `forgeqe desktop doctor` reports it.
803
+
804
+ The full file list is in [Desktop code](#desktop-code), and unattended runs are in [DESKTOP-CI.md](DESKTOP-CI.md).
805
+
806
+ ### Desktop code
807
+
808
+ | File | Contents |
809
+ |---|---|
810
+ | `src/desktop/command.ts` | `forgeqe desktop`: setup, apps, doctor, validate, explore, record, replay (folders, `--data`, `--junit`, `--update-baselines`); heal acceptance |
811
+ | `src/desktop/junit.ts` | JUnit XML for a suite |
812
+ | `src/desktop/edit.ts` | Changes to a workflow from chat: shapes, applied with comments kept, validated, diff, backup |
813
+ | `src/desktop/run.ts` | Explore and replay as the CLI and the agent's tools run them; variables, CSV rows, workflow paths |
814
+ | `src/mcp/desktoptools.ts` | ForgeQE's agent's `test_apps`, `desktop_explore`, `desktop_record`, `desktop_replay`, `desktop_edit_workflow` |
815
+ | `src/desktop/bridge.ts` | Starts `python -m forgeqe_desktop serve`, passes events on, records model calls in the usage ledger |
816
+ | `src/desktop/setup.ts` | The desktop environment, the pinned UFO checkout (`ufoCommit`), `desktopDoctor` |
817
+ | `scripts/ufo-bump.ts` | Pins a new UFO commit in every place that names it |
818
+ | `ci/desktop-runner/` | `prepare-runner.ps1` and the nightly workflow example for unattended runs |
819
+ | `src/desktop/report.ts` | `report.html` for a run |
820
+ | `py/forgeqe_desktop/service.py` | `serve`: the JSON-lines protocol, replay and explore runs, `run.json` |
821
+ | `py/forgeqe_desktop/workflow.py` | Load, validate and save workflows; variables and secrets; the key-chord grammar |
822
+ | `py/forgeqe_desktop/apps.py` | `desktop.apps`: the app allowlist and the argument array a launch uses |
823
+ | `py/forgeqe_desktop/models.py` | The profile through the `openai` SDK; image checks |
824
+ | `py/forgeqe_desktop/ufo_bridge.py` | UFO's model blocks, and the `forgeqe` model service |
825
+ | `py/forgeqe_desktop/ufo_runner.py` | UFO's config, the action trace and key guard, running UFO in-process |
826
+ | `py/forgeqe_desktop/record.py` | Trace to workflow steps |
827
+ | `py/forgeqe_desktop/replay.py` | Runs a workflow on a `Driver`: timeouts, retries, `wait_for`, dismissing dialogs, heal and stop |
828
+ | `py/forgeqe_desktop/handrecord.py` | Recording by hand: clicks, typing, chords and checks as steps; secrets |
829
+ | `py/forgeqe_desktop/handhooks.py` | The Windows hooks and UI Automation lookups that feed it |
830
+ | `py/forgeqe_desktop/visual.py` | `expect_image`: baselines, pixel comparison, diff images |
831
+ | `py/forgeqe_desktop/session.py` | Whether this Windows session can be driven (service, locked, no screen) |
832
+ | `py/forgeqe_desktop/heal.py` | One model call to re-find a moved control |
833
+ | `py/forgeqe_desktop/memory.py` | App memory: an explore replays what earlier ones did before calling the model, and a heal found once is reused (mobile too) |
834
+ | `py/forgeqe_desktop/checks.py` | One model call for checks of the outcome, kept only when on screen |
835
+ | `py/forgeqe_desktop/pywinauto_driver.py` | The Windows `Driver` |
836
+
837
+ Tests: `bun test tests/desktop.test.ts`, and `<engine-python> -m pytest tests/desktop -q` (needs `openai==1.66.2`
838
+ and PyYAML; they use a fake driver and a fake UFO, so they run on any OS).
839
+
840
+ ## Mobile apps (`src/mobile`, `py/forgeqe_mobile`)
841
+
842
+ `forgeqe-mobile-v1` shares the desktop engine's workflow validation, replay, heal, checks and visual code.
843
+
844
+ - **Appium:** `appium_driver.py` is a W3C WebDriver client over HTTP, with locators quoted as XPath literals. It drives replay and the model's explore loop (`explore.py`). `src/mobile/setup.ts` installs Appium for devices on this computer.
845
+ - **Maestro:** `maestro.py` turns a workflow into a Maestro flow, with secrets as `MAESTRO_<NAME>` environment variables. It checks a team's own flows against an allowlist and runs `maestro test` with an argument list.
846
+ - **TestMu AI:** `hyperexecute.py` writes a HyperExecute project and runs its CLI, scrubbing the access key from the output and the run folder. `src/mobile/run.ts` uploads builds (`forgeqe mobile upload`).
847
+ - **Devices:** `src/mobile/devices.ts` checks a run's devices against the cloud's own list (TestMu AI, BrowserStack) before it starts.
848
+ - **Recording by hand:** `record.py` takes the Record page's commands (`mobileRecordCommand`, `src/mobile/record.ts`) as JSON lines, and keeps locators it built and proved unique (`locators.py`).
849
+
850
+ The full file list is in [Mobile code](#mobile-code).
851
+
852
+ ### Mobile code
853
+
854
+ | File | Contents |
855
+ |---|---|
856
+ | `src/mobile/command.ts` | `forgeqe mobile`: apps, doctor, explore, replay (folders, `--data`, `--junit`, `--driver`), maestro, flow, validate |
857
+ | `src/mobile/run.ts` | Requests to the mobile engine, its environment, Maestro flow paths, the doctor |
858
+ | `src/mcp/mobiletools.ts` | ForgeQE's agent's `mobile_explore`, `mobile_replay`, `mobile_maestro` |
859
+ | `py/forgeqe_mobile/appium_driver.py` | The Appium driver: W3C WebDriver over HTTP, the replay `Driver` |
860
+ | `py/forgeqe_mobile/maestro.py` | Workflows as Maestro flows, the allowlist for team flows, running `maestro test` |
861
+ | `py/forgeqe_mobile/hyperexecute.py` | Maestro on TestMu: the HyperExecute project and running its CLI |
862
+ | `py/forgeqe_mobile/explore.py` | The model's action loop on Appium |
863
+ | `py/forgeqe_mobile/record.py` | Recording by hand: the screen's controls and their locators, the page's commands as steps |
864
+ | `py/forgeqe_mobile/locators.py` | How a recorded control is found again: ranked candidates, unique on the screen, fallbacks |
865
+ | `py/forgeqe_mobile/webview.py` | A web page inside the app: the element at a spot, its web locators, their queries |
866
+ | `py/forgeqe_mobile/magiclink.py` | Magic links: the logins with a mailbox, the newest link read and opened on the device |
867
+ | `src/mobile/record.ts` | The commands the Record page may send a mobile recording, checked |
868
+ | `src/mobile/setup.ts` | `forgeqe mobile setup`: the pinned Appium and drivers, finding the SDK and Java, starting Appium here |
869
+ | `py/forgeqe_mobile/service.py` | `serve`: replay, explore and maestro runs, `run.json` |
870
+ | `py/forgeqe_mobile/apps.py` | The mobile app allowlist and its capabilities |
871
+
872
+ The rest is shared with the desktop engine: `forgeqe_desktop.workflow` validates both formats, and `replay.py`,
873
+ `heal.py`, `checks.py` and `visual.py` run on either driver. `memory.py` (app memory, under `<memory dir>/mobile/`) lets an explore replay what earlier explores of the app did before it calls the model, and a replay reuse a target an earlier heal found.
874
+
875
+ Tests: `<engine-python> -m pytest tests/desktop/test_mobile.py -q` (a fake Appium server and a stand-in Maestro; any
876
+ OS), and `bun test tests/mobile.test.ts`.
877
+
878
+ ## App memory (`py/forgeqe_desktop/memory.py`)
879
+
880
+ Mobile and desktop explores keep what they did, as page memory does for the browser. They write under `<memory dir>/mobile/` and `<memory dir>/desktop/`, from the request's `memory: {dir}`, which `src/mobile/run.ts` and `src/desktop/bridge.ts` send when `memory.enabled`.
881
+
882
+ | File | Contents |
883
+ |------|----------|
884
+ | `flows/<app>/<goal>-<hash>.json` | The workflow of a goal's last passing explore. After a failed one, the action steps it got through, under `resume` |
885
+ | `controls/<app>.json` | Each control explores acted on, with how often it worked |
886
+ | `heals/<app>.json` | The target a heal found for a control that was not found |
887
+
888
+ **Before the model is called**, `replay_known` asks `AppMemory.plan` what to replay, in this order:
889
+
890
+ 1. the goal's passing workflow (`exact`);
891
+ 2. its `resume` steps;
892
+ 3. the start it shares with another goal's workflow in the app (`flowmatch.shared_start`, with workflow steps described by `describe_step`; checks, images and closing are never borrowed).
893
+
894
+ It replays them through `forgeqe_desktop.replay.replay` with `keep_open=True`, so the app stays open where replay got to.
895
+
896
+ - An `exact` workflow whose `expect` checks all hold ends the explore with no model call at all.
897
+ - Otherwise mobile's explore loop starts after the replayed steps, with a note of what was replayed (`memory_note`), and each on-screen control that worked before is marked `worked_before`.
898
+ - Desktop hands UFO the goal with the same note and the names of the controls that worked. The saved workflow is the replayed steps followed by UFO's.
899
+
900
+ **Heals.** Replay (`run_replay`, mobile and desktop) wraps its heal in `remembered_heal`: the target an earlier heal found is tried first, with no model, and what the model finds is kept. With heal off, no remembered target is used either.
901
+
902
+ `run.json` carries `memory: {kind, replayed, flow}`.
903
+
904
+ ## Memory across every kind of run
905
+
906
+ - **API scenario plans** (`src/api/plancache.ts`): `api_scenarios` from cases or text keeps each plan under `<memory dir>/api/plans/<hash>.json`. The key is a hash of the cases' titles, descriptions, preconditions, steps and expected results (or the text) and the set's operations. The same input reuses the plan with no model call, replacing its earlier scenarios in the set. `fresh: true` plans again.
907
+ - **Registry plans of every tool** (`src/registry`):
908
+ - `indexRuns` also indexes mobile and desktop explores (tool `mobile_explore` / `desktop_explore`, keyed by goal and app) and API runs (`api/<set>/runs/*`: `run_api_contracts` / `run_api_scenarios`, known as "the API contracts" of a set).
909
+ - `plans.args` holds the tool's arguments. It was added in place; the schema version stays 1, so older versions still open the file.
910
+ - `runTier0` (`src/registry/run.ts`) calls the plan's own tool and writes the reply from its result. The tools still ask before they operate a device or change data. The shell and `forgeqe run` both route through it.
911
+ - **Measurement:** `forgeqe memory stats` (`src/memorystats.ts`) counts, per area, the runs that reused history, those that needed no model, steps replayed and model steps, the API plans kept, and the requests the registry answered without the agent. The **memory gate** is the tests that fail when known work reaches the model.
912
+
913
+ ## Containers (`src/containers`)
914
+
915
+ `containers:` in forgeqe.yaml declares services (`config.ts`). It refuses any setting outside the fixed list, an image without an exact version, a port bound to an address other than 127.0.0.1, and a mount option.
916
+
917
+ - **`run.ts`** finds docker or podman and builds `run` arguments:
918
+ - ForgeQE's labels;
919
+ - `--security-opt no-new-privileges` and `--pids-limit`;
920
+ - `--publish 127.0.0.1:…`;
921
+ - `--env NAME` for secrets;
922
+ - `:ro` mounts.
923
+
924
+ It checks mounts as uploads are checked (inside the project; nothing hidden, key-named or linked). It waits for a TCP or HTTP ready check. Docker's port proxy accepts connections before the service listens, so a TCP connection counts only when it stays open. It scrubs secrets from logs and errors, and tracks the containers it started, which the CLI removes on exit.
925
+ - **`mock.ts`** makes WireMock stubs from `network.json` or a contract set.
926
+ - **`compose.ts`** translates docker-compose services into forgeqe.yaml services, refusing settings that widen what a container reaches. `startOrder` (`config.ts`) orders services by `depends_on`. Every container joins the project network `forgeqe-<key>` under its service name.
927
+ - **`tests.ts`** is a `runTestCommand` for `run_tests` with `containers.tests`:
928
+ - it runs the confirmed command with `sh -c` in the image, with the repository mounted at its own path and `--user` this machine's user;
929
+ - it passes only the environment's FORGEQE_* variables, the saved-login variables, and the listed env and secrets, by name;
930
+ - the repository's credential files are covered (`masks.ts`);
931
+ - `docker top` finds the browsers the test launched.
932
+ - **`workspace.ts`** is `containers.workspace`:
933
+ - `loadConfig` registers it for the repository (`active.ts`). Nothing starts until `openSession` or `runTestCommand` asks for it;
934
+ - then one container per process and project waits (`sleep infinity`) with the repository, the home volume `forgeqe-<key>-home` and the project network;
935
+ - `openSession` sets the agent runtime's `SHELL` to a script that runs `exec --workdir "$PWD" … sh -c "$2"` in it, refuses a folder outside the repository, and adds `workspaceNote` to the agents' instructions. ForgeQE's own agent passes `hostShell`;
936
+ - `runTestCommand` sends a run in a covered folder to the workspace's runner (`tests.ts`, same image and home volume) unless `host` or `FORGEQE_HOST_RUN=1`.
937
+ - **`browser.ts`** is `browser.provider: docker`:
938
+ - `startDockerBrowser` runs Microsoft's Playwright image with `BROWSER_SERVER` (Node.js, no packages) mounted read-only;
939
+ - it starts Chromium on 127.0.0.1:9222 inside, headless or on Xvfb, and a gateway on 9223 that pipes a connection only when the path starts with the random token (constant-time compare) and any `Origin` is local. The token goes to the runtime by name;
940
+ - ForgeQE waits for `/<token>/json/version` and returns `ws://127.0.0.1:<port>/<token>/devtools/browser/<id>`;
941
+ - `run.ts` starts one per browser run and gives the engine `FORGEQE_BROWSER_CDP_URL` (`docker_browser_launch_kwargs`);
942
+ - the coding loop starts one per job when the provider is docker or `run.json` says the run used one. The replay connects with `connectOverCDP` (`FORGEQE_REPLAY_CDP`, one pass), and the live browser's MCP server reads `PLAYWRIGHT_MCP_CDP_ENDPOINT` from `{env:FORGEQE_LIVE_CDP_URL}`.
943
+ - **The agent's tools** are `services` and `mock_service` in `src/mcp/containertools.ts`, and the CLI is `forgeqe services` (`command.ts`).
944
+ - **The agents' shell:** `BASH_PERMISSION` denies docker, podman, nerdctl and compose commands for the agent and Quill.
945
+ - **Tests:** `tests/containers.test.ts` and `tests/workspace.test.ts` use a fake runtime. `workspace.test.ts` also runs the gateway against a stand-in browser and the agent runtime against the workspace's script. `tests/containers.live.test.ts` uses real Docker and is skipped without it.
946
+
947
+ ### Containers code
948
+
949
+ | File | Contents |
950
+ |---|---|
951
+ | `src/containers/config.ts` | `containers:` in forgeqe.yaml: services, images, ports, env, secrets, mounts, ready checks |
952
+ | `src/containers/run.ts` | The runtime (docker or podman), `run` arguments, mount and secret checks, start and wait, status, logs, stop, the session's containers |
953
+ | `src/containers/mock.ts` | WireMock stubs from run traffic and from contract sets; values from JSON schemas |
954
+ | `src/containers/compose.ts` | docker-compose files as services: what is translated, ignored, left out or refused |
955
+ | `src/containers/tests.ts` | `run_tests` in a container: arguments, environment, mounts, output, browsers from `docker top` |
956
+ | `src/containers/workspace.ts` | `containers.workspace`: the container, its home volume, the agent's shell script, its test runner |
957
+ | `src/containers/active.ts` | The registered workspaces, by repository: `runTestCommand` and `openSession` look them up |
958
+ | `src/containers/masks.ts` | The repository's credential files and folders, covered in every container that mounts it |
959
+ | `src/containers/browser.ts` | `browser.provider: docker`: the browser container, its token gateway, the endpoint |
960
+ | `src/containers/command.ts` | `forgeqe services` |
961
+ | `skills/testcontainers/SKILL.md` | Quill's Testcontainers skill |
962
+ | `src/mcp/containertools.ts` | The agent's `services` and `mock_service` |
963
+
964
+ Tests: `bun test tests/containers.test.ts tests/workspace.test.ts`, which use a fake runtime that records each command
965
+ (`workspace.test.ts` also runs the gateway against a stand-in browser, and the agent runtime against the workspace's
966
+ script). `tests/containers.live.test.ts` uses real Docker.
967
+
968
+ ## Databases, test data and data flows (`src/data`, `py/forgeqe_data`)
969
+
970
+ `databases:` in forgeqe.yaml, or in the active environment of env.yaml, names the databases (`config.ts`, `DB_ENGINES`): Postgres, CockroachDB, Redshift, MySQL, MariaDB, SQL Server, Oracle, SQLite, DuckDB, Snowflake, MongoDB and Kafka.
971
+
972
+ - An entry holds names of environment variables, never secrets (`url_env`, `password_env`), or `auth: azure` / `aws_iam` for a token.
973
+ - `privateEnvNames` collects every `*Env` value, so these variables never reach model-run shells or test commands.
974
+
975
+ `python -m forgeqe_data serve` takes one JSON-line request from `src/data/bridge.ts`, as the browser and desktop engines do. It runs in its own environment (`~/.forgeqe/data/.venv`, set up by `setup.ts`), because DB-GPT pins libraries at versions the browser engine does not run with. Each request's environment holds only the variables of the databases it names.
976
+
977
+ - **Reading:** `schema.py` keeps a catalog per database (`.forgeqe/data/<db>/catalog.json`) and links a question to the tables it needs. `vector.py` adds DB-GPT's schema index for a database marked `vector: true`, with a local embedding model.
978
+ - **The guard:** `guard.py` parses every statement with sqlglot in the database's dialect.
979
+ - A read is exactly one SELECT, SHOW, DESCRIBE or EXPLAIN SELECT.
980
+ - A write is one INSERT, or one UPDATE or DELETE with a WHERE clause, and only on a database marked `writable`.
981
+ - `connect.py` opens reads in a read-only session where the database has one, and always rolls them back.
982
+ - `mongo.py` checks MongoDB operations the same way.
983
+ - **Test data:** `testdata.py` makes rows from a spec (`src/data/testdata.ts` reads it inside the working folder). `subset.py` takes a masked subset of another database. Inserted rows are kept as a batch that can be removed again. `hooks.ts` inserts a case's or a suite's `data:` before it runs, and removes it afterwards.
984
+ - **Data flows:** `flows.py` checks the hops listed in `flows.yaml` (beside forgeqe.yaml), from a source table to a target table, by batch or in real time. `streams.py` reads Kafka topics and HTTP APIs as hops. `flowreport.ts` writes `flows.json` and `report.html` to `<reports>/flows-<time>/`, and `flowado.ts` posts the results as an Azure DevOps test run.
985
+ - **Remembered queries:** `examples.ts` keeps the SQL the user approved, in `.forgeqe/data/<db>/examples.jsonl`. It gives the SQL back with the schema when a new question is like an old one.
986
+ - **The agent's tools** are `databases`, `database_schema`, `run_sql`, `generate_test_data`, `test_data_batches` and `request_test_data` (`src/mcp/datatools.ts`), and `data_flows`, `check_flows`, `trace_record` and `read_mapping_file` (`src/mcp/flowtools.ts`). A write, an insert or a removal asks the user first.
987
+ - **Other agents:** Quill, Mender and Link get `agentDataTools(<their name>)`, which always passes `confirmed: false` and no `ask`, so they cannot write to a database. `AGENT_DATA_TOOLS` is the same list for the web app.
988
+ - **The CLI** is `forgeqe data`, `forgeqe db` (and `/db` in the shell) and `forgeqe flows` (`command.ts`, `dbcommand.ts`), with no model.
989
+
990
+ ## Model router (`src/router`)
991
+
992
+ With more than one profile in `llms.json`, `llm.routing` (`off`, `shadow` or `auto`) gives each area of work the profile it needs. `forgeqe init` writes `off` (the template's default), and a project without the key is `off` too. [MODEL_ROUTING.md](MODEL_ROUTING.md) is the user's guide.
993
+
994
+ | Module | Contents |
995
+ |--------|----------|
996
+ | `config.ts` | The six areas (`agent`, `browser`, `coding`, `review`, `analysis`, `planning`), each with its rating bar and whether it needs images or tool calls. `parseRouting` reads `llm.routing`, `llm.routes`, `llm.strategy`, `llm.fallback` and `llm.agents`, and stops ForgeQE at start on an unknown area, agent or strategy, or a name that is not a profile |
997
+ | `agents.ts` | `AGENT_MODELS`: each agent (`forgeqe`, `engine`, `forgeqe-test`, `forgeqe-heal`, …) with its label and the area it routes in. `llm.agents` gives an agent its own profile, used ahead of the router whatever `llm.routing` says; only `--profile` overrides it |
998
+ | `facts.ts` | `profileFacts`: window, images, tool calls, reasoning, release date and price, from `llms.json`, the live check, and the public model lists. `probeProfile` runs `python -m forgeqe_engine probe` (`py/forgeqe_engine/probe.py`) with the profile on stdin and only that profile's key (or Entra variables) in its environment. The probe makes two calls through the browser agent's own client: a structured "Reply with ok set to true", and a 16-pixel red square generated in code, to learn whether the model takes images. It has a 60 s limit (240 s for a GitHub Copilot profile) |
999
+ | `profile.ts` | `rateModels`: the `forgeqe-model-profile` agent (edit, bash and webfetch denied) on the active profile gets `profileRequest`, which is each model's facts and answer time, never a key, an endpoint or an account. It returns a tier and 1–5 ratings per area. `sanitizeProfile` keeps only configured profile names, known areas and tiers, ratings rounded and held to 1–5, and a reason of at most 200 characters without control characters or `<` `>`. This happens to the reply and again on every read of `.forgeqe/model-profile.json`. The file's `fingerprint` (each profile's name, provider, model, deployment and endpoint) makes ForgeQE rate the models again when the profiles change |
1000
+ | `route.ts` | See below |
1001
+
1002
+ **`route.ts`.**
1003
+
1004
+ - `routedConfig(cfg, area)` is called at each call site.
1005
+ - The router stays out for `--profile` / `WP_LLM_PROFILE`, for an agent's own profile in `llm.agents`, and for `code.model` (all areas but `browser`).
1006
+ - `knowledge` checks and rates the models once per process, and only when two or more profiles have a key.
1007
+ - `choose` rules out a model with no key, a failed check, no images for `browser`, no tools, or too small a window.
1008
+ - Among the models rated at the area's bar it picks by `llm.strategy` (`strategyFor`):
1009
+ - `balanced` (the default): the lead areas (`agent`, `planning`) get the most capable, the others the best value (`pricePenalties`: one rating point worth up to `RATING_WORTH`× the price);
1010
+ - `capability`: the most capable everywhere;
1011
+ - `cost`: the cheapest everywhere.
1012
+
1013
+ With none at the bar, it picks the best rated.
1014
+ - A picked model must have its key and pass its live check. Otherwise the next one that does is used, a GitHub Copilot profile first, unless `llm.fallback: false`.
1015
+ - Each pick goes to the session log as `model.route`, and its kind (`router`, `pinned`, `fallback`, `active`, `escalated`) to the usage ledger. In `shadow` it is only logged.
1016
+ - `escalate` gives a root-cause analysis one stronger model.
1017
+ - `routeTable` is `forgeqe models --routes` (`--profile-models` checks and rates again).
1018
+
1019
+ ForgeQE's agent is routed once, when its session opens (`brain/index.ts`), so its prompt cache survives. With routing on, any profile in `llms.json` that has a key can receive prompts, page content, screenshots and code excerpts, and each gets the live check. `llm.routing: off`, a single profile, or a pin per area in `llm.routes` keeps the work on one deployment. `tests/router.test.ts` covers the router.
1020
+
1021
+ ## Generated code (`src/provenance.ts`)
1022
+
1023
+ When a Quill job passes, `code/loop.ts` calls `markJob`, which marks what ForgeQE wrote in the repository.
1024
+
1025
+ - A file it created starts with a comment header, `Generated with ForgeQE · fq:<id> · run <run>` (`code.header`, on by default). The `fq:` id is a hash of the file without the header, so `verify` tells whether the file changed since.
1026
+ - Every file it created or edited is recorded in `<repo>/.forgeqe/generated.jsonl`, one line per run, with the lines it added as short hashes.
1027
+ - `measure` (`forgeqe generated`) counts how much of the code ForgeQE wrote and how much of that is still there.
1028
+ - The `generated_attribution` tool (`src/mcp/provenancetools.ts`) gives the pull request footer and commit trailer with the runs' `fq:` ids (`attributionText`).
1029
+
1030
+ ## Every other command, from the shell (`src/mcp/clitools.ts`)
1031
+
1032
+ `forgeqe_command` runs the forgeqe commands no other tool covers: `context`, `guardrails`, `models`, `generated`, `docs`, `prompts`, `eval domain`, `skills`, `bi`, `notify test`, `desktop` / `mobile` doctor, `update`, and the rest of `COMMANDS`.
1033
+
1034
+ - `planCommand` takes the words as a list and matches them against an allowlist of shapes. Each shape has known words, arguments of a kind, and known flags:
1035
+ - `name` matches `[A-Za-z0-9._-]`;
1036
+ - `file` is resolved with `realpath` inside the working or reports folders and outside hidden folders;
1037
+ - `text` is one line.
1038
+ - A `read` shape runs at once, unless a value holds shell syntax.
1039
+ - A `change` shape (it changes files, installs, costs model calls, or sends something out) is put to the user first through `ctx.ask`, or needs `confirmed: true` where nothing can ask. `models --routes` is a `change` shape, because it may check and rate the models.
1040
+ - `runForgeqe` spawns `forgeqe` with an argument array, `shell: false`, the session's `--config` and `--profile`, and a time limit per shape.
1041
+
1042
+ ## Reports for every kind of run (`src/report/runs.ts`, `src/report/collect.ts`, `src/api/report.ts`)
1043
+
1044
+ The team report (`forgeqe bi build`, `/report` in the shell through `src/report/command.ts`) counts every kind of run, not only suites and monitor rounds.
1045
+
1046
+ - **`runs.ts`:** `otherRuns` reads these as suites, from the files each run already writes, so older runs count too, up to 500 of each kind:
1047
+ - single browser runs (`<reports>/<time>/run.json`);
1048
+ - desktop and mobile runs (`desktop-*`, `mobile-*`);
1049
+ - exploratory testing (`explore/*/exploration.json`);
1050
+ - API runs (`api/<set>/runs/*`).
1051
+ - **`api/report.ts`:** an API contract or scenario run writes `suite.json` and `report.html` next to `results.json`. Each contract or scenario is a case, and its checks or calls are the steps.
1052
+ - **`collect.ts`:**
1053
+ - `exportReports` (`forgeqe bi export`, `/report export`) writes this machine's runs and readiness reports, with the user and machine, to one bundle: `<reports>/shared/forgeqe-reports-<user>-<machine>-<time>.json` (`<reports>` is `export.out_dir`, by default `.forgeqe/reports`).
1054
+ - `collectReports` reads the bundles in `<reports>/collected/`, `bi.collect` and `--from` beside the local runs.
1055
+ - A bundle is someone else's file, so it is parsed as data, skipped above 64 MB, and its values only become table cells.
1056
+ - A run seen twice (the same machine, scope and folder) counts once: this machine's own copy first, then the newest bundle's.
1057
+
1058
+ ## Monitoring (`src/monitor`)
1059
+
1060
+ `forgeqe monitor` is `runSuite` on a timer, plus memory between rounds of which checks are failing, plus alerts.
1061
+
1062
+ A round:
1063
+
1064
+ 1. `loadCases(monitor.checks)`, then `runSuite` with `out_dir` set to `monitor.out_dir` (default `<reports>/monitor`), coding off, replay `verify`, and write-back off (`monitor.write_back`).
1065
+ 2. The case results, plus the `forgeqe-monitor` pseudo-check as passed, go to `decide(state.json, outcomes, now, fail_after, remind_every)`. If loading or running throws (a source down, no cases), only `forgeqe-monitor` is reported, as an error.
1066
+ 3. `decide` returns alerts: `failing`, `still_failing` or `recovered`.
1067
+ 4. `sendAlerts` sends them to the Teams webhook (an Adaptive Card) and SMTP (nodemailer).
1068
+ 5. The round saves `state.json` and `<round>/alerts.json`, and prunes rounds beyond `keep`.
1069
+
1070
+ | Module | Contents |
1071
+ |--------|----------|
1072
+ | `state.ts` | `decide` is pure. A failure starts or extends a failing streak (`since`, `failures`). The first alert goes out when the streak reaches `fail_after`, a `still_failing` reminder every `remind_every` after the last alert, and `recovered` on a pass after an alert (a streak that never alerted recovers silently). Stopped checks keep their state. A round that could not run reports only the `forgeqe-monitor` pseudo-check and keeps the others (`keepOthers`). `state.json` is written through a temp file and a rename |
1073
+ | `alerts.ts` | One `AlertMessage` per round, made a `Notice` by `monitorNotice`: a line per check with its failing step, a test case link, an Open report action, and at most 5 `failure.png` attachments. `teamsPayload` and `emailContent` wrap it for the channels below |
1074
+ | `run.ts` | `monitorRound` (load, run, decide, save, alert, prune), `runMonitor` (a lock file with the pid, `.monitor.lock`, refuses a second live monitor on the folder; rounds start `every` apart, or at once after an overrun; `--once` returns 0/1/2), `pruneRounds`, `formatRound`, `roundCard`, and `sendTestAlert` |
1075
+ | `background.ts` | Monitors started by the `monitor` tool: `runMonitor` with its own `AbortController` inside the process, one per `out_dir` (a second in the same process is refused, and `lockMonitor` is checked first so another process's monitor is too). Each round is emitted as a card, and a monitor that ends on an error emits a "Monitor stopped" card. `stopBackgroundMonitors` aborts and waits for them |
1076
+
1077
+ **Channels** (`src/notify/notice.ts`, shared with suite, readiness and eval notices):
1078
+
1079
+ - `teamsCard`: a `message` with one Adaptive Card 1.4 attachment, full width, which classic incoming webhooks and Workflows webhooks both accept.
1080
+ - `noticeEmail`: subject `[ForgeQE] <title>`, text and HTML, and the attachments.
1081
+ - `smtpTransport`: nodemailer, `secure` for port 465 by default, STARTTLS when the server offers it, auth only when the username variable is set, and 20–30 s timeouts.
1082
+ - `sendNotice` sends to each channel independently and removes the webhook URL and the SMTP password from errors.
1083
+
1084
+ **Rounds and folders.** Rounds are ordinary suite folders, so `report.html` gets trends and flaky checks from the sibling rounds' `suite.json`. `runDirectory` creates each run or suite folder itself and adds `-2`, `-3` when a folder for that second exists, so back-to-back rounds and parallel tool calls never share one.
1085
+
1086
+ **From the shell** the brain can run a round, start a background monitor that lives as long as the shell, set up `monitor:` in `forgeqe.yaml`, and test the alerts. Monitoring that outlives the shell is a service, cron, a job of the jobs service, or a scheduled pipeline running `forgeqe monitor --once` with `state.json` cached.
1087
+
1088
+ **Signing in.** `signIn` in `src/logins.ts` drives the engine's `login` command. When the engine says the browser is open it calls `wait`, and sends `save` (true) or `stop` (false, or on abort). `forgeqe login` wraps it with readline and Ctrl-C; the `logins` tool passes `ctx.waitForUser`.
1089
+
1090
+ ## Telemetry (`src/privacy.ts`)
1091
+
1092
+ `withoutTelemetry(env)` is part of every child's environment:
1093
+
1094
+ - the engine and `forgeqe setup`, through `allowListEnv`;
1095
+ - the test command and replay, through `withoutNames`, which also drops ForgeQE's own secrets;
1096
+ - the agent runtime server, through `serverEnv`.
1097
+
1098
+ It drops `OTEL_EXPORTER_OTLP_*` and forces the opt-outs on (`NO_TELEMETRY_ENV`):
1099
+
1100
+ | Process | Variables | Effect |
1101
+ |---------|-----------|--------|
1102
+ | Engine | `ANONYMIZED_TELEMETRY=false`, and the library's cloud-sync and cost-calculation switches off | No PostHog client, no cloud sync, no LiteLLM price download |
1103
+ | Agent runtime | Its auto-update, share, and model-catalogue switches off, and `experimental.openTelemetry: false` in the config | No update check, no share links, bundled model catalog, no AI SDK spans |
1104
+ | Copilot gateway | `enable_session_telemetry=False` on every Copilot session (`py/forgeqe_engine/copilot_gateway.py`) | No session telemetry to GitHub, which the Copilot SDK otherwise sends for a signed-in user |
1105
+ | test command | `DO_NOT_TRACK=1`, `OTEL_SDK_DISABLED=true`, and the Next.js, Nuxt, Astro, Gatsby, Storybook, Turborepo, Angular, .NET, and Cypress opt-outs | Framework CLIs a test may start stay quiet |
1106
+
1107
+ In the engine:
1108
+
1109
+ - `cli.py` maps each `FORGEQE_ENGINE_<NAME>` to the setting the engine reads, and sets the telemetry variables again with `os.environ.update`, so an engine started by hand behaves the same.
1110
+ - `brand.install()` replaces the about:blank watchdog's animation, which loads a logo from the library's CDN, with ForgeQE's start page, which loads nothing.
1111
+ - Chrome runs with the engine library's defaults (`--disable-background-networking`, `--metrics-recording-only`, `--no-pings`, `--disable-sync`, …).
1112
+
1113
+ ## Profiles and the offline test double
1114
+
1115
+ `loadConfig` reads the profiles in `llms.json` and picks the active one in this order: `--profile`, `WP_LLM_PROFILE`, `llm.active`, `default`, the first profile.
1116
+
1117
+ - With none, the active profile is `""` and its provider `none`. `missingKey` and `noAgentModel` return `NO_MODEL_SET_UP`, which the shell, `forgeqe run`, and the tools show instead of running.
1118
+ - Entries with provider `mock`, `default: mock`, and `llm.active: mock` that older templates wrote are ignored.
1119
+
1120
+ That is the active profile. With `llm.routing: auto`, each area of work can run on another profile from `llms.json`, which the [model router](#model-router-srcrouter) picks per call site (`routedConfig`).
1121
+
1122
+ - `--profile` (or `WP_LLM_PROFILE`), then an agent's own profile in `llm.agents`, then `code.model` and pins in `llm.routes` override the router.
1123
+ - With `off` (the default when the key is missing), every call uses the active profile.
1124
+ - The router never considers `mock` or a profile with provider `none`.
1125
+
1126
+ `mock` is a test double, not a profile users see. It exists only when asked for by name (`--profile mock` or `WP_LLM_PROFILE=mock`).
1127
+
1128
+ - It never starts the Python engine. `src/engine/mock.ts` speaks the engine's stdin/stdout protocol: it opens the pinned URL and finishes, or fails when there is none.
1129
+ - `runEngine` runs it in the engine's place, so offline runs and the test suite go through the same bridge, events, and reports as live runs, without Python, a browser, or an API key.
1130
+ - Its result has `driver: "synthetic"`, so it never becomes a test.
1131
+
1132
+ ## The web app server (`src/web`)
1133
+
1134
+ `forgeqe web` is one Bun process that serves the web app and the gateway it calls.
1135
+
1136
+ | Aspect | Details |
1137
+ |--------|---------|
1138
+ | What it is | `serveWeb` (`src/web/server.ts`) serves the built app (`WEB_DIST`) and the gateway under `/api/…`. `createWebApi` sends each route to its gateway module (`chat.ts`, `jobs.ts`, `testmgmt.ts`, `basal.ts`, `tosca.ts`, `responsive.ts` and the others) |
1139
+ | Process | The `forgeqe web` process, on 127.0.0.1 only, with a random bearer token that the printed address carries as `#token=…`. `hostAllowed` and `webOriginAllowed` check every request |
1140
+ | Talks to the rest | Each chat is a child `forgeqe chat --jsonl` (`createChatHub`, `chat.ts`), started with an argument array. The person's messages go to its stdin as JSON lines, and its stdout lines become the chat's events, which the page reads by long poll. A page that runs a command gets one child `forgeqe` at a time through `createCliRunner` (`cli.ts`), which asks the page only through `channelAsk` |
1141
+ | Files | Chats in `.forgeqe/chats/<id>.json`, each with its task record `<id>.task.json` (`taskrecord.ts`). Settings changes in `.forgeqe/audit/settings.jsonl`. Recent projects and sidebar pins in `~/.forgeqe/web.json` (`kept.ts`) |
1142
+
1143
+ ## The jobs service (`src/jobs`)
1144
+
1145
+ The jobs service runs ForgeQE commands on a schedule, in a process that outlives the shell.
1146
+
1147
+ | Aspect | Details |
1148
+ |--------|---------|
1149
+ | What it is | `forgeqe jobs serve` (`serveJobs`, `src/jobs/service.ts`). A job is one ForgeQE command of `JOB_COMMANDS`, checked by `jobArgs` (`command.ts`). It runs every `every` (at least `MIN_EVERY_MS`, one minute), on a five-field cron expression, or only when asked (`schedule.ts`) |
1150
+ | Process | A detached process that `ensureJobs` (`client.ts`) starts when it is not running. `JobRunner` (`runner.ts`) starts each run as its own `forgeqe <args>` child with an argument list: at most `parallel` at once, never two of one job, a 6 h default timeout and a 24 h maximum |
1151
+ | Talks to the rest | HTTP on 127.0.0.1 with a random bearer token compared in constant time; browser origins are refused. Its clients are the CLI, the shell, the agent's `jobs` tool (`src/mcp/jobtools.ts`) and the Jobs page (`src/web/jobs.ts`). Failures, recoveries and ends go to the notify channels |
1152
+ | Files | `.forgeqe/jobs/`: `<id>/job.json`, `<id>/runs/<run>/run.json` and `output.log`, `events.jsonl` (`store.ts`). The service's port, pid and token are in `~/.forgeqe/jobs/<hash>.service.json`, where the hash is the first 16 hex characters of the SHA-256 of the jobs folder (`serviceFile`) |
1153
+
1154
+ ## Talk and the speech worker (`src/voice`, `src/speech`, `py/forgeqe_speech`)
1155
+
1156
+ Talk lets a person speak to a chat and hear its replies. Speech runs only on this computer.
1157
+
1158
+ | Aspect | Details |
1159
+ |--------|---------|
1160
+ | What it is | `createVoiceRoutes` (`src/voice/routes.ts`) and `createVoiceSession` (`session.ts`). `answers.ts` reads spoken answers by code, and `spokenText` (`spoken.ts`) cleans what is said |
1161
+ | Process | Talk runs inside `forgeqe web`. Speech is one Python child of the gateway (`createSpeechWorker`, `src/speech/worker.ts`: `python -I -X utf8 -c <BOOTSTRAP> <py dir> serve …`), running Kokoro (ONNX Runtime), faster-whisper, Silero VAD and Smart Turn |
1162
+ | Talks to the rest | Routes behind the gateway's token: `GET /api/voice`, `POST /api/voice/setup` (only with `confirm: true`), `/api/voice/warm` and `/api/voice/ticket`. A ticket is single use, valid for `TICKET_MS` (60 s), and kept only as its SHA-256. It opens the WebSocket `/api/voice/session`, which takes 16 kHz PCM16 audio and JSON messages of `clientMessage`'s shapes, at most `MAX_SESSIONS` (4) at once. A session reaches a chat only through the chat hub's start, send and steer. The speech worker takes one JSON line and answers with one |
1163
+ | Files | Set up only after a person agrees to its size (`src/speech/setup.ts`): the pinned `SPEECH_PACKAGES` in `~/.forgeqe/speech/.venv`, and the model files in `~/.forgeqe/speech/models`, each kept only when its pinned size and SHA-256 match (`models.ts`) |
1164
+
1165
+ ## Test management (`src/testmgmt`)
1166
+
1167
+ Test management lists every test case and automated test ForgeQE knows, and links the two.
1168
+
1169
+ | Aspect | Details |
1170
+ |--------|---------|
1171
+ | What it is | `catalogue.ts` joins stores that already exist and keeps no second copy: synced plans (`plans.ts`), tests found with each framework's own list command (`discover.ts`), the mapping in `.forgeqe/test-cases.json`, suite reports, packs and ForgeQE's tags. Links are in `links.ts` (proposals from `forgeqe-test-linker`), suites in `suites.ts` (rules proposed by `forgeqe-suite-builder`), tags in `tags.ts`, and tracker write-back (Azure DevOps, Jira, Xray) in `writeback.ts` |
1172
+ | Process | The calling process: `forgeqe testmgmt sync\|schedule` (`command.ts`), the gateway `src/web/testmgmt.ts` (`/api/testmgmt/…`), or the agent's `test_inventory` tool |
1173
+ | Talks to the rest | The gateway runs suites and syncs as child `forgeqe suite` and `forgeqe testmgmt sync` processes (`createCliRunner`). A scheduled sync is a job of the jobs service whose only arguments are `testmgmt sync` (`SYNC_ARGS`, `schedule.ts`) |
1174
+ | Files | `.forgeqe/testmgmt/`: `tests.json`, `links.json`, `suites.json`, `tags.json`. The git-ignored `.forgeqe/testmgmt-cache/`: `plans/<source>-<hash>.json`, `discovered.json`, `stories.json` |
1175
+
1176
+ ## BASAL (`src/basal`)
1177
+
1178
+ BASAL is business testing. It turns a business question and its sources into a test, in stages:
1179
+
1180
+ 1. a scenario (`understand`);
1181
+ 2. a strategy;
1182
+ 3. a cast of personas (`cast.ts`);
1183
+ 4. rehearsal rounds (`rehearse.ts`);
1184
+ 5. after a person approves, `act` (`act.ts`);
1185
+ 6. a verdict (`judge`, `oracle.ts`).
1186
+
1187
+ | Aspect | Details |
1188
+ |--------|---------|
1189
+ | What it is | The model work is the `forgeqe-basal` agent (`think.ts`), and `check.ts` checks every answer |
1190
+ | Process | In process, from `forgeqe basal …` (`command.ts`), the agent's `basal` tool (`BASAL_OPS`, `src/mcp/basaltools.ts`, with no approve op), and the gateway `src/web/basal.ts` (`/api/basal`, where each stage is a job the page polls). Approving needs the test's id typed |
1191
+ | Talks to the rest | Act hands each journey to `browser_run`, `mobile_explore` or `desktop_explore`, and API steps to the workbench's `sendCall`. The product graph gives context, and the graph store the cast's search |
1192
+ | Files | `.forgeqe/basal/tests/<id>/` (`store.ts`): `request.json`, `sources.json`, `scenario.json`, `strategy.json`, `personas/`, `rounds/NN.json`, `handovers.jsonl`, `verdict.json`. Written through a temporary file at mode 0600, never through a link |
1193
+
1194
+ ## The graph store (`src/graph`)
1195
+
1196
+ The graph store is ForgeQE's Neo4j. It holds the product graph and BASAL's scenario graphs (`LAYERS`: `product`, `scenario`).
1197
+
1198
+ | Aspect | Details |
1199
+ |--------|---------|
1200
+ | What it is | `graph.store` is `auto` (Neo4j when it answers, else the JSON snapshot), `neo4j` or `json`. The default address is `bolt://127.0.0.1:7688` (`DEFAULT_BOLT_PORT`, `config.ts`) |
1201
+ | Process | Callers reach it in their own process through `neo4j-driver` (`neo4j.ts`). Opening it never installs anything |
1202
+ | Talks to the rest | Cypher is written in code with parameters only. Labels are fixed (`FQNode`, `FQ_EDGE`, `FQMeta`), and every node carries its project. The callers are `syncAfterBuild` after `forgeqe knowledge build`, BASAL and the product tools. Without Neo4j they use the product graph's JSON (`store.ts`) |
1203
+ | Setup | `forgeqe graph setup` (`command.ts`, `setup.ts`), after a person agrees. Docker first: container `forgeqe-neo4j` from `NEO4J_IMAGE`, pinned by digest, with the volume `forgeqe-neo4j-data`. Else a native Neo4j `NEO4J_VERSION` and a Temurin JRE, pinned by SHA-256, in `~/.forgeqe/tools/`, with data in `~/.forgeqe/neo4j` |
1204
+ | Secrets | The password is in the credential store under `graph.neo4j.password_env` (default `FORGEQE_NEO4J_PASSWORD`) |
1205
+ | Embeddings | `graph.embedding` (1536 dimensions by default) covers nodes and facts only (`embed.ts`) |
1206
+
1207
+ ## Product knowledge and Graphify (`src/product`)
1208
+
1209
+ `forgeqe knowledge` (`command.ts`: `build`, `ask`, `search`, `flow`, `path`, `gaps`, `history`, `export`, `import` and more) builds and queries the product graph.
1210
+
1211
+ | Aspect | Details |
1212
+ |--------|---------|
1213
+ | What it is | `buildProductGraph` (`build.ts`) reads each repository of `product.repos` through `structure.ts` and joins them with their HTTP and SQL links. The model's readings (`understand.ts`) go in `graph/understanding.json`. A build given a store syncs into Neo4j |
1214
+ | Process | The calling process. Code structure comes from Graphify, pinned at `GRAPHIFY_VERSION` and run as a Python child (`py/forgeqe_knowledge/graphify_bridge.py`, `-I`, an argument array, `graphifyEnv`, a 30-minute limit) |
1215
+ | Talks to the rest | Agents use `product_knowledge` (`src/mcp/producttools.ts`) and `knowledge_agent`. The web app reads `/api/knowledge/…` and starts `forgeqe knowledge build` as its own process (`src/web/knowledgegraph.ts`) |
1216
+ | Files | The knowledge folder is `knowledge.dir`: by default `.forgeqe/knowledge`, or `~/.forgeqe/knowledge` without a config file. `graph/` holds `product-graph.json`, `repos/`, `docs/`, `meta.json`, `history.jsonl`, `findings.json` and the rest; `product/` holds the pages people read. Graphify is installed into `~/.forgeqe/knowledge/.venv` (`ensureGraphify`, `graphify.ts`), with its cache in `~/.forgeqe/cache/product-graph` (`FORGEQE_PRODUCT_CACHE_DIR` overrides) |
1217
+
1218
+ ## Responsive preview (`src/responsive`)
1219
+
1220
+ Responsive runs one page on several devices in ForgeQE's own headless browser.
1221
+
1222
+ | Aspect | Details |
1223
+ |--------|---------|
1224
+ | What it is | `engine.ts` runs the steps and the built-in checks (`sideways`, `small_text`, `small_targets`, `broken_images`). The `forgeqe-responsive` model (no tools) reads the prompt, plans the steps and judges the person's own checks (`agent.ts`, `review.ts`) |
1225
+ | Process | Run by the gateway (`src/web/responsive.ts`, `/api/responsive…`), one session at a time. The browser is a Bun child (`spawnTransport`, `session.ts`) running the fixed source `responsiveRunnerSource` (`runner.ts`). It drives one headless Chromium with an isolated context per device, or a cloud's browser (`cloud.ts`), with `STEP_MS` (8 s) per step and `NAV_MS` (30 s) per page load |
1226
+ | Talks to the rest | JSON-line commands on the runner's stdin, answers on its stdout |
1227
+ | Files | Runs in `<reports>/responsive/<rsp-…>/`: `run.json`, `log.jsonl`, `shots/` (`runs.ts`). Saved prompts in `.forgeqe/responsive/flows/<name>.json` (`flows.ts`). The runner is written to `~/.forgeqe/tools/responsive/runner.mjs` (`runner-device-<DEVICE_PLAYWRIGHT>.mjs` for real devices), and the real-device Playwright goes in `~/.forgeqe/tools/responsive/playwright-device-<version>` |
1228
+
1229
+ ## Custom agents (`src/customagents`)
1230
+
1231
+ A custom agent is a team's own agent, defined by a manifest and run only in its approved version.
1232
+
1233
+ | Aspect | Details |
1234
+ |--------|---------|
1235
+ | What it is | A manifest in `.forgeqe/agents/<id>.yaml` (`~/.forgeqe/agents` without a config file, `load.ts`), checked by `resolveAgent` (`manifest.ts`). What runs is the approved copy in `.forgeqe/agents/.releases/<id>/` (`lifecycle.ts`), with `pinned-<digest>.json` for what it knows (`pinned.ts`) |
1236
+ | Process | A run opens ForgeQE's own agent session (`openBrain`, from `run.ts`). `policy.ts` and `actions.ts` check every tool call |
1237
+ | Talks to the rest | `forgeqe agent …`; Atlas's `custom_agent` tool, and `hand_to_agent` and `request_approval` between agents (`src/mcp/agenttools.ts`); the gateway (`/api/custom-agents`, `/api/agent-builder`; `src/web/customagents.ts`, `builder.ts`); signed webhooks at `POST /hooks/github\|azure-devops` (`outside.ts`); and schedules, each a job running `forgeqe agent run <id> --unattended` (`schedules.ts`) |
1238
+ | Files | Builder sessions in `.forgeqe/agents/.drafts/`. Runs and `memory.json` in `.forgeqe/agent-runs/<id>/`. Waiting approvals in `.forgeqe/agent-approvals/<agent>/<id>.json`. Packages in `~/.forgeqe/agent-library/` |
1239
+
1240
+ ## Evidence (`src/evidence`)
1241
+
1242
+ Evidence tests AI agents from the records of their runs.
1243
+
1244
+ | Aspect | Details |
1245
+ |--------|---------|
1246
+ | What it is | A run is judged against the agent's approved contract (`contract.ts`, `judge.ts`), its scenarios (`scenarios.ts`) and its labelled runs (`measure.ts`) |
1247
+ | Process | `forgeqe evidence` (`cmdEvidence`, `command.ts`) runs in the CLI process. `record --from forgeqe\|otlp\|langfuse\|langsmith\|jsonlog` reads runs. `receive` is a local OTLP receiver (`startReceiver`, `receiver.ts`): `Bun.serve` on 127.0.0.1, port `OTLP_PORT` (4318), path `/v1/traces`, with a bearer token. The harness (`harness.ts`) and the build check (`buildcheck.ts`) start the agent under test and the verify commands as child processes with argument arrays |
1248
+ | Talks to the rest | The web app uses `src/web/evidence.ts` (`/api/evidence`). ForgeQE's agent has no Evidence tool beyond `forgeqe_command`'s `bi --evidence` |
1249
+ | Files | `.forgeqe/evidence/` (`store.ts`): `runs/<id>.json`; `contracts/`, `scenarios/`, `harness/` and `verify/`, each with an `.approved/` copy; `verdicts/`, `judged/`, `findings/`; and the append-only logs `overrules.jsonl`, `attempts.jsonl`, `grades.jsonl`, `learn.jsonl`, `governance.jsonl`, `releases.jsonl`, `drafts.jsonl`, `fixes.jsonl` and `harness.jsonl` |
1250
+
1251
+ ## Migration (`src/migrate`)
1252
+
1253
+ `forgeqe migrate` moves a repository's tests to another framework or language.
1254
+
1255
+ | Aspect | Details |
1256
+ |--------|---------|
1257
+ | What it is | Code works out the plan with no model (`plan.ts`, ids of `PLAN_ID`'s shape, `mig-YYYYMMDD-HHMMSS-xxxx`). `scan.ts` and `stacks.ts` detect the stack, and the target comes from `targets.ts`. Only a person confirms a plan. ForgeQE runs each migrated test itself and proves by mutation that it checks something (`mutate.ts`) |
1258
+ | Process | `runMigrate` (`loop.ts`) runs in the calling process and opens a coding session as `forgeqe-migrate`, which writes one file at a time |
1259
+ | Talks to the rest | `forgeqe migrate` (`cmdMigrate`) and the agent's `migrate_tests` tool. The Migration page (`src/web/migrate.ts`) starts `migrate run\|verify\|fix <plan>` as jobs of the jobs service |
1260
+ | Files | A plan in `.forgeqe/migrations/<plan>/`: `plan.json`, `run.lock`, `result.json`, `migrate.md`, `events.jsonl`, `logs/`. Project target profiles in `.forgeqe/migrate-targets/<id>.yaml`, with approved copies in `.approved/`. Confirmations by the plan's digest in `~/.forgeqe/migrations/confirmed/`. Sources from outside the project in `~/.forgeqe/migrations/workspaces/<id>/` (`workspace.ts`) |
1261
+
1262
+ ## Tosca (`src/tosca`, `py/forgeqe_tosca`)
1263
+
1264
+ `forgeqe tosca` converts Tosca test cases from a `.tsu` export into Playwright, Cypress, Selenium or WebdriverIO tests. It is separate from migration.
1265
+
1266
+ | Aspect | Details |
1267
+ |--------|---------|
1268
+ | What it is | A Python reader turns the export into `summary.json` and, per case, `cases/<id>/ntir.json` and `source.md`. Plans and confirmations work as migration's (`plan.ts`). The run (`loop.ts`) opens a coding session as `forgeqe-tosca` (Bridge) |
1269
+ | Process | The reader is a Python child, `python -m forgeqe_tosca read <file.tsu> --out <dir>`, started by `reader.ts` with an argument list; it needs only the standard library. The run is in the calling process |
1270
+ | Talks to the rest | `forgeqe tosca` (`cmdTosca`) and the agent's `convert_tosca` tool. The Tosca page (`src/web/tosca.ts`) starts `tosca run\|fix <plan>` as jobs. Its assistant is `src/web/toscaAssistant.ts` with `src/tosca/assistant.ts`. `publishToscaPr` (`publish.ts`) commits in a temporary git worktree |
1271
+ | Files | A plan in `.forgeqe/tosca/<plan>/`: `plan.json`, `read/`, `data.json`, `run.lock`, `result.json`, `tosca.md`, `logs/`. A case's test data in `<target>/tosca-data/<case>.json`. Confirmations in `~/.forgeqe/tosca/confirmed/`, assistant conversations in `~/.forgeqe/tosca-assistant/<hash>/`, and secret uses in `~/.forgeqe/tosca-secrets/<hash>/` |
1272
+
1273
+ ## Regression packs (`src/pack`)
1274
+
1275
+ A regression pack is the set of tests a release's changes can break. It is saved by name, with why each test is in: linked, changed, covers, risk or smoke.
1276
+
1277
+ | Aspect | Details |
1278
+ |--------|---------|
1279
+ | What it is | `collect.ts` and `sources.ts` gather the changes from commits, pull requests and work items. `plan.ts` builds the pack and lists the changes no test covers |
1280
+ | Process | In process, from `forgeqe pack build\|run\|list\|show\|triage\|heal\|pipeline` and the tools `build_regression_pack`, `run_regression_pack`, `list_regression_packs` and `edit_regression_pack` (`src/mcp/packtools.ts`). The gateway `src/web/packs.ts` starts `forgeqe pack …` through `createCliRunner` |
1281
+ | Talks to the rest | A run happens on this computer, on TestMu AI, or in CI (`pipeline.ts`). `init.ts` writes `.github/workflows/forgeqe-pack.yml` or `pipelines/forgeqe-pack.yml` into the test repository. `heal` passes the triaged failures to `heal_tests` |
1282
+ | Files | The pack as `.forgeqe/packs/<name>.json` in the test repository, with its last 20 runs. Each run in `<export.out_dir>/packs/<name>/<time>/`, with `triage.json` and `triage.md` (`triage.ts`) |
1283
+
1284
+ ## API testing (`src/api`)
1285
+
1286
+ API testing writes and runs contracts and scenarios against an API.
1287
+
1288
+ | Aspect | Details |
1289
+ |--------|---------|
1290
+ | What it is | Contracts come from a description, recorded traffic or a Postman collection (`spec.ts`, `traffic.ts`, `postman.ts`, `plan.ts`), and `run.ts` runs them with `fetch`, or `grpcurl` for gRPC. The other kinds of run are scenarios (`scenario.ts`, plans cached by `plancache.ts`), load (`load.ts`), security probes (`fuzz.ts`), healing (`heal.ts`), mocks (`mock.ts`), and coded tests written by Link (`write.ts`) |
1291
+ | Process | ForgeQE's own process. The browser-page fallback (`browserfetch.ts`) gives the call to a Bun child on stdin |
1292
+ | Talks to the rest | The agent's tools in `src/mcp/apitools.ts` (`api_contracts`, `run_api_contracts`, `api_scenarios`, `run_api_scenarios`, `run_api_load`, `run_api_security` and others). The CLI `forgeqe api` (`contracts`, `scenarios`, `run`, `heal`, `load`, `security`, `mock`, `tests`, `list`). The gateway `src/web/apitests.ts` (`apiView`, `apiWorkbench`, and `apiArgs` for child `forgeqe api` runs) |
1293
+ | Files | A set in `<reports>/api/<set>/`: `contracts.json`, `api.md`, `history/`, `data.json`. Each run in `runs/<time>/`: `results.json`, `junit.xml`, `suite.json`, `report.html`, and the scenario, load and security files. Scenario plans in `<memory dir>/api/plans/<hash>.json`. Descriptions picked on the page in `.forgeqe/specs/<name>` |
1294
+
1295
+ ## Artifacts
1296
+
1297
+ `<reports>` is `export.out_dir`, by default `.forgeqe/reports`. `.forgeqe` is the folder beside `forgeqe.yaml` (`projectDir`). `~/.forgeqe` is `FORGEQE_HOME`, else `~/.forgeqe`.
1298
+
1299
+ **In a run folder** (`<reports>/<time>/`, or a suite's `NN-<id>/`):
1300
+
1301
+ | File | Contents |
1302
+ |------|----------|
1303
+ | `run.json` | Result, summary, usage, visited URLs, page memory (replayed, heals, repaired), browser diagnostics, the judge's verdict (`judge`), how the browser was set up (`browser`), and the browser skills added to the prompt (`skills`) |
1304
+ | `accessibility.json`, `performance.json`, `visual.json`, `localization.json` | The quality checks of the pages visited |
1305
+ | `network.json` | The app's API calls, with credentials dropped and secrets redacted (`api.capture`) |
1306
+ | `workflow.yaml` | `forgeqe-v2-compact` steps for replay or audit |
1307
+ | `trace.md` | Task, results, failure trace |
1308
+ | `failure.png` (or `.jpg`) | Last screenshot of a failed run |
1309
+ | `steps.json`, `steps/NN.jpg` | The step timeline and a screenshot per step |
1310
+ | `video.mp4` | A video of the run (`browser.video`, `desktop.video`; on by default) |
1311
+ | `resume.json` | A cut-off or failed run's steps, for `resume_from` |
1312
+ | `persona-findings.json` | What a persona run noticed |
1313
+ | `report.html` | The run's own report |
1314
+ | `handoff.md` | What the coding agent was given (only with a repo) |
1315
+ | `code.json` | Coding result: status, attempts, test file, command, reused, changed, last test output, tokens |
1316
+ | `scribe-session.json` | Quill's session for a job that stopped before it finished, reopened by a rerun |
1317
+ | `testcase.json` | The test case a suite ran in this folder |
1318
+ | `reproduce/` | A new defect's second run |
1319
+
1320
+ **Under `<reports>`:**
1321
+
1322
+ | Location | Contents |
1323
+ |----------|----------|
1324
+ | `suites/<time>/` (`suite.out_dir`) | `junit.xml`, `report.html`, `suite.json` above the case folders |
1325
+ | `monitor/` (`monitor.out_dir`) | `state.json` (which checks are failing and since when) and `.monitor.lock`; each round `<time>/` with its suite files and `alerts.json` (what it alerted and whether it was sent) |
1326
+ | `heal/<time>/` | `heal.json`, `heal.md`, and the browser runs it made |
1327
+ | `tests/<time>/` | `selection.json`, `results.xml` or `results.trx`, `results.json`, `output.log` |
1328
+ | `desktop-*`, `mobile-*`, `explore/<name>/exploration.json` | Desktop, mobile and exploratory runs |
1329
+ | `api/<set>/` | `contracts.json`, `api.md`, `history/`, `data.json`, and `runs/<run>/` with `results.json`, `junit.xml`, `suite.json`, `report.html` |
1330
+ | `flows-<time>/` | A data flow check: `flows.json`, `report.html` |
1331
+ | `packs/<name>/<time>/` | A pack run, with `triage.json` and `triage.md` |
1332
+ | `responsive/<rsp-…>/` | `run.json`, `log.jsonl`, `shots/` |
1333
+ | `shared/forgeqe-reports-<user>-<machine>-<time>.json` | A team report bundle from `forgeqe bi export` or `/report export` |
1334
+ | `collected/` | Teammates' bundles |
1335
+
1336
+ **In `.forgeqe/`** (beside `forgeqe.yaml`, or in the repository where noted):
1337
+
1338
+ | Location | Contents |
1339
+ |----------|----------|
1340
+ | `model-profile.json` | The model router's live checks and ratings, checked on every read and made again when the profiles change (`~/.forgeqe` without a config file) |
1341
+ | `generated.jsonl` (repository) | Per Quill run, its `fq:` id and the files and lines it wrote |
1342
+ | `test-history.json` (repository) | Test results history and quarantine |
1343
+ | `scribe-rules.json` (repository) | Quill's rulebook |
1344
+ | `packs/<name>.json` (test repository) | Regression packs and their last 20 runs |
1345
+ | `test-cases.json` | The mapping of test cases to tests |
1346
+ | `memory/` (`memory.dir`) | Page memory, `scribe-notes.json`, `mobile/`, `desktop/`, `api/plans/` (`~/.forgeqe/memory` without a config file) |
1347
+ | `sessions/`, `logs/` | Saved browser sessions and session logs (`~/.forgeqe/…` without a config file) |
1348
+ | `knowledge/` (`knowledge.dir`) | The product graph (`graph/`) and pages (`product/`) |
1349
+ | `data/<db>/catalog.json`, `data/<db>/examples.jsonl`, `data/requests.jsonl` | Schema catalogs, approved queries, test data requests (`~/.forgeqe/data/catalogs` without a config file) |
1350
+ | `chats/<id>.json` and `<id>.task.json`, `terminal-chats/` | Web and terminal chats |
1351
+ | `inbox/` (the agent's folder) | Files dropped into a chat, kept 14 days |
1352
+ | `audit/settings.jsonl` | The audit of the web app's changes |
1353
+ | `jobs/` | Jobs, their runs, `events.jsonl` |
1354
+ | `testmgmt/`, `testmgmt-cache/` | Test management records, and git-ignored snapshots |
1355
+ | `agents/` (with `.releases/` and `.drafts/`), `agent-runs/`, `agent-approvals/` | Custom agents |
1356
+ | `basal/tests/<id>/` | BASAL tests |
1357
+ | `evidence/` | Evidence runs, contracts, verdicts and logs |
1358
+ | `migrations/<plan>/`, `migrate-targets/` | Migrations and target profiles |
1359
+ | `tosca/<plan>/` | Tosca plans |
1360
+ | `responsive/flows/` | Saved Responsive prompts |
1361
+ | `specs/`, `documents/`, `blocks/`, `cases-index/` | API descriptions, uploaded documents, recorded blocks, the case index |
1362
+ | `skills/`, `prompts/`, `guardrails/` | The project's skills, prompt overrides and guardrails |
1363
+ | `business-personas/`, `personas/` | Business personas and accessibility personas |
1364
+ | `visual-baselines/`, `pipelines/`, `theme/`, `setup.json` | Visual baselines, watched pipelines' state, an uploaded logo, skipped setup items |
1365
+
1366
+ **In `~/.forgeqe/`:**
1367
+
1368
+ | Location | Contents |
1369
+ |----------|----------|
1370
+ | `auth.json`, `credentials.json` | What is saved, and the file store used only where there is no OS credential store |
1371
+ | `engine/.venv`, `data/.venv`, `knowledge/.venv`, `speech/.venv`, `speech/models/` | Python environments of the engines, Graphify and speech, and the speech models |
1372
+ | `desktop/` | The UFO checkout and desktop setup |
1373
+ | `tools/` | Downloaded tools: the agent runtime, uv, Neo4j, the JRE, the responsive runner |
1374
+ | `runtime/` | The agent runtime's own files |
1375
+ | `cache/` | `product-graph`, `product-repos`, `doc-index`, `mcp-tools`, `fx-ecb.json` |
1376
+ | `usage/YYYY-MM.jsonl`, `prices.json` | The usage ledger and model prices |
1377
+ | `jobs/<hash>.service.json` | The jobs service's port, pid and token |
1378
+ | `web.json` | Recent projects and sidebar pins |
1379
+ | `secrets/<hash>.json` | Vault connections |
1380
+ | `neo4j/` | Native Neo4j data |
1381
+ | `migrations/confirmed/`, `migrations/workspaces/` | Migration confirmations and workspaces |
1382
+ | `tosca/confirmed/`, `tosca-assistant/`, `tosca-secrets/` | Tosca confirmations, assistant conversations and secret uses |
1383
+ | `agent-library/` | Custom agent packages |
1384
+
1385
+ ## Tests
1386
+
1387
+ `tests/` holds over 450 test files. The lists below are the core ones. Run `bun test` and `<engine-python> -m pytest tests/engine tests/desktop` for all of them. Tests that need the agent runtime, the engine, Docker, Windows or an emulator are skipped without them.
1388
+
1389
+ **The engine and the bridge**
1390
+
1391
+ - `bun test`: config, commands, TUI, mock loop, bridge (with stub engines), memory readers and `forgeqe memory`.
1392
+ - `tests/engine.e2e.test.ts` runs the real engine and Chrome against a local site with a local OpenAI-compatible model server. It is skipped when the engine is not installed.
1393
+ - Its second run replays the first from memory and checks the model is called once.
1394
+ - Its last test passes that real run to the real agent runtime.
1395
+ - It runs a two-case suite in two real browsers and checks page memory counted both.
1396
+ - It signs in with a saved login and TOTP (the model never sees the values), checks the session file, that `workflow.yaml` holds `text_env` / `totp_env` instead of values, and that the next run starts signed in.
1397
+ - It runs a page where clicking "One way" resets the date: a model that takes the nudge finishes; one that ignores it is stopped with its resume steps saved, and a retry with `resume_from` replays the cookie click and needs two model calls.
1398
+ - `<engine-python> -m pytest tests/engine`: the engine directly, with a scripted model, including `test_memory.py` (locators, confidence, identity, flows, secrets), and replay, trust mode, and self-healing against real Chrome.
1399
+ - `test_brand.py` checks the overlay in real Chrome: the start page, trusted CDP clicks and keys dropped while locked and let through while acting, the unlocked state and step text on a page loaded mid-step, and a clean screenshot and DOM for the model.
1400
+ - `test_step_notes.py`: the agent's note built from its own fields and stored on the flow steps a step recorded, `evaluate` steps with their code.
1401
+ - `test_page_settle.py`: the judge off by default and on by setting, `page_settled`, `settle_page` waiting for a new tab and giving up on one that stays blank, and note actions as read-only.
1402
+ - `test_resume.py`: `resume_point`, `resume_steps`, the loop start and nudge text, `_install_nudges` draining after the library's hook, resume steps in the flow file, the resume hand-off, checkpoints (kept apart from flows, cleared only by their own run, kept by a stopped run), and the hand-off after a cut-off run.
1403
+ - `test_session_logins.py`: remembered values as placeholders on every sign-in domain, env values still working, `step_outcomes`, and `making_progress`.
1404
+ - `test_skills.py`: `choose_skills` order, the cap of 3, errors and an empty catalogue without a model call; `skills_block` within `skills_max_chars`; the request fields.
1405
+ - `WP_E2E_HEADED=1` runs the bun e2e test in a visible browser, with the overlay on.
1406
+
1407
+ **Quill and replay**
1408
+
1409
+ - `tests/code.test.ts`:
1410
+ - provider mapping, permissions and handoff contents;
1411
+ - the loop with a scripted session: fail then pass, missing command, a stalled command asked once to change approach and then stopping the job, the live browser's MCP server and config from `run.json`, the replay running while Quill reads the repo as the read-only agent, the reading turn and its notes with the replay off, a check's section in the handoff, the live browser switched on by a failed replay or a failed test, the same failure stopping the job on its third time, fatal error, stop;
1412
+ - `FailedCommands`, the read-only agent's permissions, and the trimmed handoff (weak locators dropped, step elements left out of the page tables);
1413
+ - the handoff's notes before each group of steps, once per step, and the JavaScript shown;
1414
+ - resuming: a stopped job keeps `scribe-session.json` and a finished one removes it, a rerun reopens the session with the saved replay and a carry-on prompt, and a gone session starts fresh.
1415
+ - `tests/code.e2e.test.ts`, against the real agent runtime:
1416
+ - the reading turn has no write or structured-answer tools;
1417
+ - a local OpenAI-compatible model writes a failing test, gets ForgeQE's failure output, and fixes it; the key arrives through `{env:}`;
1418
+ - a session reopens by id after the runtime restarted and finds its earlier messages;
1419
+ - Quill's skill listing has only the registry's skills for it, an allowed skill's text arrives, and a disabled skill, the repo's `.opencode` and `.claude` skills, the runtime's built-in skill, and `~/.claude/skills` stay out unless `external` adds them through the registry.
1420
+ - `tests/replay.test.ts`: the script and locators built from a workflow, and the two launch setups. Against a local site in Chrome:
1421
+ - a click a cookie dialog covers (Playwright's reason, the dialog, the other locators' matches, the rest of the flow still run);
1422
+ - a control hidden from `navigator.webdriver` (the second launch gets through and the handoff says the setup is the difference);
1423
+ - a run that only opened a page whose heading checks come back with their sections (by the element after the heading, the section it heads, and `aria-labelledby`).
1424
+
1425
+ **Test cases, suites and sources**
1426
+
1427
+ - `tests/cases.test.ts`: every file format, goals, the handoff, and Azure DevOps, Jira (Cloud and Server) and Xray (Cloud and Server) against local fake APIs that check paging, auth headers and the write-back calls.
1428
+ - `tests/suite.test.ts`: the worker pool, serial coding, reports, exit codes, stop, write-back, and the job summary.
1429
+ - `tests/sources.test.ts`: TestRail, Zephyr Scale and qTest reading and write-back (paging, step results, retries without them, new runs and cycles); bugs in Jira and Azure DevOps (create with screenshot and links, comment while failing, note on pass); Confluence reading and its MCP wiring; parsing of `logins:`, `report:` and the new sources; the login commands; session notes without secret values; and `report.html`.
1430
+ - `tests/repotests.test.ts`:
1431
+ - `parseResults` on JUnit and TRX;
1432
+ - `find_tests` with a scripted Quill: the read-only agent, the listing fed back, a corrected list command listed again, nothing found, mock profile and bad dates refused;
1433
+ - `run_tests` declined (nothing runs), confirmed (per-test card from JUnit, the heal suggestion), and without `ask` (`needs_confirmation`, then `confirmed: true`, exit code only);
1434
+ - sprints from fake Azure DevOps and Jira APIs: paging, the pick through `ask`, cancel, `needs_choice`, a name matched.
1435
+
1436
+ **The agent, MCP and the CLI**
1437
+
1438
+ - `tests/integrations.test.ts`: `sources:` MCP switches and `mcp:` parsing, the Azure DevOps and Jira server entries for each auth mode and every reason a server is skipped (secret values never in the config), overrides, and `query_api` against fake APIs (auth headers, api-version, host restriction, mutation refusal, cutting).
1439
+ - `tests/brain.e2e.test.ts`, through the real agent runtime:
1440
+ - a local stdio server, a remote HTTP server that checks its bearer token, and a broken server: the `{env:}` values arrive, both tools are callable, the broken server is reported, and no secret reaches the model;
1441
+ - against a scripted local model: the agent chooses `forgeqe_browser_run` over MCP, both forms of `git push` are refused, and a follow-up message runs a suite.
1442
+ - `tests/mcp.test.ts`: the MCP server over HTTP (auth, initialize, list, progress, cancel, errors) and stdio, environment notes without secret values, `pushBranch` against a bare remote whose default branch is `trunk`, and `setCiSecret` with fake `gh` and `az`.
1443
+ - `tests/cli.test.ts`: `forgeqe run` through the real agent runtime (tool lines, reply, exit 3 for needs input); `forgeqe mcp` over stdio with the mock profile; and `forgeqe monitor --test-alerts` and `--once` with the mock profile against a fake Teams webhook.
1444
+ - `tests/commands.test.ts`: the command tools called as the agent calls them:
1445
+ - `write_test` with a scripted session (agent events, the card, the mock profile refused);
1446
+ - `heal_tests` clean and healed;
1447
+ - `monitor` round and status, `start` refused in a `once` session, start/status/stop in a `shell` session (a round card, a second start and a one-off round refused, the lock released);
1448
+ - `test_alerts` against a fake webhook;
1449
+ - `logins` list/clear and `sign_in` without a person;
1450
+ - `page_memory` flows and clear;
1451
+ - `forgeqe_setup` profiles, MCP servers, docs by topic, and init.
1452
+
1453
+ **Healing and monitoring**
1454
+
1455
+ - `tests/heal.test.ts`: the healing loop with a scripted session that calls ForgeQE's tools over the real MCP server (only the four heal tools are listed; the browser run lands in the heal folder): nothing to heal, healed and confirmed, an app bug left failing, a healed test that still fails or has no command, finding the command, `code.test_command`, a missing report, a fatal error, and stop.
1456
+ - `tests/monitor.test.ts`: `decide` sequences (fail_after, flaky, reminders, recovery, stopped, a round that could not run); duration and `monitor:` parsing; rounds through the real `runSuite` with state carried over; report links, attachments, `alerts.json`, pruning; the loop and `--once` exit codes; the lock against a live pid; the Teams card against a fake webhook; email through nodemailer to a local fake SMTP server (login, recipients, subject, screenshot); and secrets scrubbed from errors.
1457
+ - `tests/tui.test.tsx` renders a monitor round's card in the transcript, and checks the **Your turn** dialog holds a tool until **Done, continue**.
1458
+
1459
+ **Sessions, logins, updates and resuming**
1460
+
1461
+ - `tests/update.test.ts`: bun and pip installs found in PATH order; waiting while the registry 404s, then the cache-skipping commands per install; `--check` running nothing; a release never served failing with a retry hint.
1462
+ - `tests/sessionLog.test.ts`: the session header and events with remembered passwords, secret environment variables, and inline API keys replaced; tool calls and results; the bundle's contents without screenshots or keys; `/logs`.
1463
+ - `tests/resume.test.ts`: resume steps in the run result, `loadResume` by folder or run name, and `browser_run` returning the retry and passing `resume_from`.
1464
+ - `tests/sessionLogins.test.ts`: remembered logins (domains from a URL, hosts, and wildcards; the engine payload with values; no process env), redaction next to punctuation and in carried-over turns, a remembered login replacing a configured one in the notes, ForgeQE's test runs getting the env names with the output redacted, and the `logins` tool's remember/list/clear without the password in any result.
1465
+
1466
+ **Skills**
1467
+
1468
+ - `tests/skills.test.ts`:
1469
+ - `skills:` parsing, and the prebuilt skills loading cleanly;
1470
+ - precedence and `overrides` across user, project, the repo's own folder, and `dirs`; the repo's `.claude` skills only with `external`;
1471
+ - the default and opt-in `agents`; `disable` and unknown names;
1472
+ - every validation problem (including the unquoted `: ` hint);
1473
+ - the per-agent `skill` permission and `skills.paths` in the runtime config;
1474
+ - links readable through and removed without touching the skill;
1475
+ - `browserSkills` given and chosen, unknown names, and the remembered choice;
1476
+ - the engine request through a stub engine and `skills` back on the result;
1477
+ - the skills catalogue in the environment notes;
1478
+ - `newSkill`, `setSkillDisabled` keeping comments, and `ignoredNote`;
1479
+ - the overview and `/skills`, and `forgeqe skills new/show/disable/enable/check` end to end.
1480
+
1481
+ **Desktop, mobile and tool scope**
1482
+
1483
+ - `tests/desktop.test.ts`, `tests/mobile.test.ts`, `tests/scope.test.ts`, `tests/capabilities.test.ts`: the desktop and mobile commands and tools, workflow edits, uploads, and the tool scope.
1484
+ - `<engine-python> -m pytest tests/desktop`: the desktop and mobile engines against fake drivers, a fake Appium server and a stand-in Maestro (any OS). The `*_live` tests need Windows or an emulator.