proofed-cli 0.1.3 → 0.2.0

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 (65) hide show
  1. package/README.md +176 -122
  2. package/dist/action/requests.js +130 -0
  3. package/dist/{server.js → action/server.js} +17 -3
  4. package/dist/changes.js +7 -1
  5. package/dist/{args.js → check/args.js} +31 -3
  6. package/dist/check/cache.js +89 -0
  7. package/dist/{check.js → check/check.js} +86 -40
  8. package/dist/{doctor.js → check/doctor.js} +55 -19
  9. package/dist/check/help.js +139 -0
  10. package/dist/{list.js → check/list.js} +27 -15
  11. package/dist/{pipeline.js → check/pipeline.js} +106 -68
  12. package/dist/{render.js → check/render.js} +22 -15
  13. package/dist/check/run.js +277 -0
  14. package/dist/check/targetfilter.js +10 -0
  15. package/dist/check/textcheck.js +162 -0
  16. package/dist/env.js +6 -0
  17. package/dist/fix/agent.js +21 -0
  18. package/dist/fix/claude.js +30 -0
  19. package/dist/fix/codex.js +71 -0
  20. package/dist/fix/fixsetup.js +76 -0
  21. package/dist/fix/fixtarget.js +48 -0
  22. package/dist/fix/models.js +67 -0
  23. package/dist/github.js +62 -14
  24. package/dist/integrations/claude-stop.js +104 -0
  25. package/dist/integrations/cli.js +63 -0
  26. package/dist/integrations/mcp.js +130 -0
  27. package/dist/kane/creditmeter.js +104 -0
  28. package/dist/kane/kane.js +131 -0
  29. package/dist/kane/kaneauth.js +84 -0
  30. package/dist/kane/kaneversion.js +13 -0
  31. package/dist/paths.js +32 -0
  32. package/dist/process.js +65 -0
  33. package/dist/proofed.js +34 -16
  34. package/dist/{live.js → report/live.js} +1 -1
  35. package/dist/{livefile.js → report/livefile.js} +1 -1
  36. package/dist/{report.js → report/report.js} +105 -125
  37. package/dist/report/reportdata.js +120 -0
  38. package/dist/{result.js → report/result.js} +12 -7
  39. package/dist/{runfile.js → report/runfile.js} +2 -2
  40. package/dist/report/runresult.js +5 -0
  41. package/dist/scenarios.js +41 -19
  42. package/dist/secrets.js +74 -0
  43. package/dist/{cdp.js → targets/cdp.js} +20 -6
  44. package/dist/targets/chrome.js +98 -0
  45. package/dist/{clip.js → targets/clip.js} +21 -11
  46. package/dist/{precheck.js → targets/precheck.js} +53 -20
  47. package/dist/targets/preparetarget.js +350 -0
  48. package/dist/{recorder.js → targets/recorder.js} +154 -19
  49. package/dist/{serve.js → targets/serve.js} +9 -13
  50. package/dist/{target.js → targets/target.js} +42 -7
  51. package/dist/targets/targetchecks.js +139 -0
  52. package/dist/timing.js +25 -0
  53. package/dist/types.js +1 -0
  54. package/dist/which.js +26 -13
  55. package/docs/cli.md +370 -0
  56. package/package.json +10 -5
  57. package/dist/cache.js +0 -48
  58. package/dist/chrome.js +0 -77
  59. package/dist/help.js +0 -133
  60. package/dist/kane.js +0 -75
  61. package/dist/kaneauth.js +0 -48
  62. package/dist/models.js +0 -44
  63. package/dist/requests.js +0 -58
  64. package/dist/run.js +0 -173
  65. /package/dist/{deps.js → targets/deps.js} +0 -0
package/README.md CHANGED
@@ -1,21 +1,21 @@
1
1
  <div align="center">
2
2
 
3
- <img src="site/public/favicon.svg" width="64" alt="">
3
+ <img src="https://raw.githubusercontent.com/t1dem/proofed/main/site/public/favicon.svg" width="64" alt="">
4
4
 
5
5
  # Proofed
6
6
 
7
- **Every pull request, run in Chrome before you merge it.**
7
+ **Check the user flows a pull request touches before you merge it.**
8
8
 
9
- Kane CLI runs the user flows a pull request touches and posts the recording on the PR.<br>
10
- When a flow breaks, Claude Code fixes it, and the fix is pushed only after Kane has watched it pass.
9
+ Kane CLI runs the user flows a pull request touches. Proofed posts local recordings or cloud recording notes on the PR.<br>
10
+ When a flow breaks, Claude Code or OpenAI Codex fixes it, and the fix is pushed only after Kane has watched it pass.
11
11
 
12
- [**Break it yourself**](https://proofed.neptunescodm.workers.dev/try) · [Dashboard demo](https://proofed.neptunescodm.workers.dev/app?demo) · [Demo store](https://github.com/t1dem/proofed-demo-store) · [Install on GitHub](https://proofed.neptunescodm.workers.dev/install)
12
+ [Website](https://proofed.neptunescodm.workers.dev) · [**Break it yourself**](https://proofed.neptunescodm.workers.dev/try) · [Dashboard demo](https://proofed.neptunescodm.workers.dev/app?demo) · [Install on GitHub](https://proofed.neptunescodm.workers.dev/install) · [CLI](#locally-and-from-an-ai-agent)
13
13
 
14
14
  <sub>Built for the Kane CLI hackathon, November 2026.</sub>
15
15
 
16
16
  <br>
17
17
 
18
- <img src="docs/devices.png" width="880" alt="The Proofed dashboard in a browser and on a phone: pull requests grouped into Needs you, Kane is checking, Claude is fixing and Passed">
18
+ <img src="https://raw.githubusercontent.com/t1dem/proofed/main/docs/devices.png" width="880" alt="The Proofed dashboard in a browser and on a phone: pull requests grouped into Needs you, Kane is checking, Claude is fixing and Passed">
19
19
 
20
20
  </div>
21
21
 
@@ -40,13 +40,7 @@ When a flow breaks, Claude Code fixes it, and the fix is pushed only after Kane
40
40
 
41
41
  ## For judges
42
42
 
43
- - **[Break it yourself](https://proofed.neptunescodm.workers.dev/try)**, no account. Pick one of four prepared pull requests and watch Kane catch the break and Claude fix it on the real [demo store](https://github.com/t1dem/proofed-demo-store). A run takes 8 to 14 minutes, one at a time, 3 per visitor a day.
44
- - **[Dashboard demo](https://proofed.neptunescodm.workers.dev/app?demo)**, no sign-in. `sample-coffee-store` in it is made up and labelled "Sample data"; the rest is copied from GitHub.
45
- - **Proofed checks itself.** Every pull request here runs five dashboard scenarios through Kane, for example [#25](https://github.com/t1dem/proofed/pull/25#issuecomment-6897255024).
46
-
47
- <img src="docs/try-run.jpg" alt="A finished run on /try: Kane caught a break, Claude fixed it, Kane confirmed. The fix and a before and after comparison of the page.">
48
-
49
- If you'd rather read than wait, all four changes have already run:
43
+ Four pull requests on the [demo store](https://github.com/t1dem/proofed-demo-store) each break one flow. All four have already run:
50
44
 
51
45
  | PR | What Kane found | What happened next |
52
46
  |---|---|---|
@@ -55,18 +49,52 @@ If you'd rather read than wait, all four changes have already run:
55
49
  | [#11](https://github.com/t1dem/proofed-demo-store/pull/11) | The + button in the bag leaves the quantity at 1 | Fixed on the first attempt ([`9999a0d`](https://github.com/t1dem/proofed-demo-store/commit/9999a0d)), 8.5 minutes |
56
50
  | [#12](https://github.com/t1dem/proofed-demo-store/pull/12) | A €44.50 bag ships free | Fixed on the first attempt ([`f54f1b5`](https://github.com/t1dem/proofed-demo-store/commit/f54f1b5)), 8.5 minutes |
57
51
 
52
+ To watch one run live, open [Break it yourself](https://proofed.neptunescodm.workers.dev/try). It needs no account and takes 8 to 14 minutes.
53
+
54
+ <img src="https://raw.githubusercontent.com/t1dem/proofed/main/docs/try-run.jpg" alt="A finished run on /try: Kane caught a break, Claude fixed it, Kane confirmed. The fix and a before and after comparison of the page.">
55
+
56
+ To run Proofed on your machine, with a signed-in [Kane CLI](https://www.npmjs.com/package/@testmuai/kane-cli), Node 22.18+, Chrome, ffmpeg and pnpm (`npm install -g pnpm`):
57
+
58
+ ```sh
59
+ git clone https://github.com/t1dem/proofed-demo-store
60
+ cd proofed-demo-store
61
+ npx proofed-cli check "the promo code welcome10 takes 10% off"
62
+ ```
63
+
64
+ The [dashboard demo](https://proofed.neptunescodm.workers.dev/app?demo) needs no sign-in. In [demo-store #11](https://github.com/t1dem/proofed-demo-store/pull/11#issuecomment-6897672103), Kane caught a broken quantity button, Claude fixed it, and Kane confirmed both affected scenarios passed. Proofed also checks its own pull requests.
65
+
66
+ ### Bugs from real projects
67
+
68
+ Nine merged pull requests from open-source projects, each of which shipped a bug that was fixed upstream later. Each one is replayed in a copy of its repository with Proofed added. On every replay Kane caught the bug, Codex GPT-6.2 Sol at medium effort fixed it, and Kane checked the fix before it was pushed to the PR.
69
+
70
+ | Pull request | Target | What broke | Replay with Proofed | Fixed upstream |
71
+ |---|---|---|---|---|
72
+ | [omni-tools #32](https://github.com/iib0011/omni-tools/pull/32) | Web | The numbers 1, 2 and 4 on separate lines add up to 0 instead of 7 | [Caught, fixed on the first attempt](https://github.com/t1dem/omni-tools/pull/1) | [#428](https://github.com/iib0011/omni-tools/pull/428), 567 days later |
73
+ | [frontend-mini-challenges #264](https://github.com/sadanandpai/frontend-mini-challenges/pull/264) | Web | Delete leaves the todo item in the list | [Caught, fixed on the first attempt](https://github.com/t1dem/frontend-mini-challenges/pull/1) | [#338](https://github.com/sadanandpai/frontend-mini-challenges/pull/338), 28 days later |
74
+ | [Excalidraw #11974](https://github.com/excalidraw/excalidraw/pull/11974) | Web | The main menu stays open after a click on the canvas | [Caught, fixed on the first attempt](https://github.com/t1dem/excalidraw/pull/1) | [#12053](https://github.com/excalidraw/excalidraw/pull/12053), 12 days later |
75
+ | [OpenCalc #520](https://github.com/Darkempire78/OpenCalc/pull/520) | Android emulator | A decimal point typed into the first number of 2×0.5 is ignored | [Caught, fixed on the second attempt](https://github.com/t1dem/OpenCalc/pull/1) | [#538](https://github.com/Darkempire78/OpenCalc/pull/538), 81 days later |
76
+ | [Quillpad #396](https://github.com/quillpad/quillpad/pull/396) | Android emulator | Back in a note sends the app to the background instead of the notes list | [Caught, fixed on the first attempt](https://github.com/t1dem/quillpad/pull/1) | [#406](https://github.com/quillpad/quillpad/pull/406), 24 days later |
77
+ | [AnkiDroid #20889](https://github.com/ankidroid/Anki-Android/pull/20889) | Android emulator | A deck picked in the card browser search doesn't change the deck filter | [Caught, fixed on the first attempt](https://github.com/t1dem/Anki-Android/pull/1) | [#23110](https://github.com/ankidroid/Anki-Android/pull/23110), 180 days later |
78
+ | [Zettlr #6001](https://github.com/Zettlr/Zettlr/pull/6001) | Electron | A blank line between paragraphs loses its ¶ mark | [Caught, fixed on the first attempt](https://github.com/t1dem/Zettlr/pull/1) | [#6024](https://github.com/Zettlr/Zettlr/pull/6024), 7 days later |
79
+ | [Zettlr #6031](https://github.com/Zettlr/Zettlr/pull/6031) | Electron | Typing an empty Pandoc span turns off the highlighting in the note | [Caught, fixed on the first attempt](https://github.com/t1dem/zettlr-pandoc/pull/1) | [#6448](https://github.com/Zettlr/Zettlr/pull/6448), 211 days later |
80
+ | [MarkText #5276](https://github.com/marktext/marktext/pull/5276) | Electron | A folded heading unfolds after switching tabs | [Caught, fixed on the first attempt](https://github.com/t1dem/marktext/pull/1) | [#6060](https://github.com/marktext/marktext/pull/6060), 24 days later |
81
+
82
+ The web replays ran on GitHub's Ubuntu runners. The Android and Electron replays ran on a self-hosted Apple Silicon Mac, Android on an Android 14 emulator.
83
+
58
84
  ## How it works
59
85
 
60
86
  <picture>
61
- <source media="(prefers-color-scheme: dark)" srcset="docs/flow-dark.svg">
62
- <img src="docs/flow-light.svg" alt="Pull request, then Kane runs the flows it touches in Chrome, then a report with clips on the PR. If a flow broke, Claude fixes it and Kane re-checks; the fix is pushed on a pass, otherwise Claude tries again, up to 3 times.">
87
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/t1dem/proofed/main/docs/flow-dark.svg">
88
+ <img src="https://raw.githubusercontent.com/t1dem/proofed/main/docs/flow-light.svg" alt="Pull request, then Kane runs the flows it touches in Chrome, then a report with clips on the PR. If a flow broke, Claude fixes it and Kane re-checks; the fix is pushed on a pass, otherwise Claude tries again, up to 3 times.">
63
89
  </picture>
64
90
 
65
91
  - Only the scenarios whose `paths` the diff touches run.
66
- - A start page that crashes on load fails at once, with the browser's error and a screenshot, at no Kane credits.
67
- - Kane doesn't record video, so Proofed records Chrome itself. The clip cuts the waiting, shows where Kane clicked and zooms in on what it checks.
68
- - When Kane blames the test rather than the code, the scenario shows as "not checked", never as a pass.
69
- - Nothing is pushed until Kane has seen a fix pass. The commit's `Fixed-by:` line names the model.
92
+ - For web, a start page that crashes on load fails at once, with the browser's error and a screenshot, at no Kane credits.
93
+ - For web, Kane doesn't record video, so Proofed records Chrome itself. The clip cuts the waiting, shows where Kane clicked and zooms in on what it checks.
94
+ - When Kane blames the test without a failed assertion, the scenario shows as "not checked". A failed check that Kane blames on the scenario runs a second time; two failures stay failed.
95
+ - A fix starts when someone ticks **Fix with Claude** or **Fix with Codex**, or on its own with [Fix automatically](#fix-automatically) on.
96
+ - Each attempt rebuilds and re-checks the broken flows and affected neighbors. The final check reuses the last attempt's results on the same tree and rebuilds only when scenarios still need to run, before committing and pushing.
97
+ - The fix commit's `Fixed-by:` line names the model.
70
98
 
71
99
  ## Scenarios
72
100
 
@@ -83,6 +111,8 @@ Open the bag, type the promo code welcome10 in lowercase and apply it.
83
111
  Check that the discount is −€9.10, shipping is Free and the total is €81.90.
84
112
  ```
85
113
 
114
+ Put the exact text the page should show in quotes in the last check (`Check that the total is "€81.90".`): Proofed then compares it with the page itself ([Text checks](#text-checks-and-uncertain-passes)).
115
+
86
116
  ## Commands
87
117
 
88
118
  Comment on a PR. Only people with write access can run them.
@@ -91,27 +121,37 @@ Comment on a PR. Only people with write access can run them.
91
121
  |---|---|
92
122
  | `/proofed` | Check the PR again |
93
123
  | `/proofed <what to check>` | Kane checks just that, e.g. `/proofed the kettle goes into the bag at €45.00` |
94
- | `/proofed fix` | Same as ticking **Fix with Claude** |
95
- | `/proofed fix opus high` | This one fix with another model and effort |
124
+ | `/proofed fix` | Fix with the repository's selected provider and model |
125
+ | `/proofed fix opus high` | This one fix with Claude Opus at high effort |
126
+ | `/proofed fix sol high` | This one fix with Codex GPT-6.2 Sol at high effort |
127
+ | `/proofed fix codex` | This one fix with Codex GPT-6.2 Sol |
96
128
 
97
- The repo's model is set in the [dashboard](https://proofed.neptunescodm.workers.dev/app). Without it, fixes use Haiku 5.5 at xhigh effort.
129
+ The repo's provider, model and effort are set in the [dashboard](https://proofed.neptunescodm.workers.dev/app), under Settings in the repo's model menu. The two icons switch between Claude and Codex. Without a choice, fixes use Claude Haiku 5.5 at xhigh effort. The same choice writes scenarios on the setup PR.
98
130
 
99
- ## Locally and from an AI agent
131
+ ## Fix automatically
132
+
133
+ By default a fix waits for someone to tick **Fix with Claude** or **Fix with Codex**. With **Fix automatically** on, it starts as soon as Kane sees a scenario fail. It doesn't start:
134
+
135
+ - on draft pull requests,
136
+ - on pushes by bots, so the fixer's own commit doesn't start another fix,
137
+ - on a run Kane marked "not checked".
138
+
139
+ In the [dashboard](https://proofed.neptunescodm.workers.dev/app), open Settings, click the model menu in the repo's row (it reads like "Haiku 5.5 · xhigh") and turn on **Fix automatically** at the bottom. Or with the GitHub CLI:
140
+
141
+ ```sh
142
+ gh variable set PROOFED_AUTOFIX --body true --repo owner/repo # on
143
+ gh variable delete PROOFED_AUTOFIX --repo owner/repo # off
144
+ ```
100
145
 
101
- `proofed check` runs the same check on your machine, against the change you haven't pushed yet: the scenarios its files touch, in Chrome, with Kane CLI. A coding agent can run it before it says a UI change is done.
146
+ ## Locally and from an AI agent
102
147
 
103
- It needs Node 22.18 or later, Chrome, [Kane CLI](https://www.npmjs.com/package/@testmuai/kane-cli) signed in (`kane-cli login`) and ffmpeg for the clips.
148
+ `proofed check` runs the same check on your machine, against the change you haven't pushed yet: the scenarios its files touch, with Kane CLI on their configured targets. A coding agent can run it before it says a UI change is done.
104
149
 
105
- Install the registry package with one manager:
150
+ Web checks need Node 22.18 or later, Chrome, [Kane CLI](https://www.npmjs.com/package/@testmuai/kane-cli) signed in (`kane-cli login`) and ffmpeg for the clips.
106
151
 
107
- | | npm | pnpm | bun |
108
- |---|---|---|---|
109
- | Install | `npm install -g proofed-cli` | `pnpm add -g proofed-cli` | `bun add -g proofed-cli` |
110
- | Run without installing | `npx proofed-cli` | `pnpm dlx proofed-cli` | `bunx proofed-cli` |
111
- | Update | `npm install -g proofed-cli@latest` | `pnpm add -g proofed-cli@latest` | `bun add -g proofed-cli@latest` |
112
- | Uninstall | `npm uninstall -g proofed-cli` | `pnpm remove -g proofed-cli` | `bun remove -g proofed-cli` |
152
+ Install it with `npm install -g proofed-cli` (or `pnpm add -g`, `bun add -g`), or run it once with `npx proofed-cli`.
113
153
 
114
- The command is `proofed`; `proofed doctor` says what else is missing. It runs on Node 22.18 or later with any of the three, bun included, and an older Node gets an error that says so. The package is built JavaScript with no dependencies and no install scripts. From a clone, `npm link` runs the TypeScript source instead.
154
+ The command is `proofed`. Run `proofed doctor` to see what's missing. The package ships built JavaScript and has no install scripts. From a clone, `npm link` runs the TypeScript source instead.
115
155
 
116
156
  In the app's repo:
117
157
 
@@ -121,80 +161,75 @@ In the app's repo:
121
161
  | `proofed list` | Every scenario, whether the change touches it and whether its pass is cached |
122
162
  | `proofed check` | Runs the scenarios the change touches; `proofed check "the cart total updates"` checks just that |
123
163
 
124
- The change is everything since the merge base with the default branch (`origin/HEAD`, else `origin/main`, or `--base`), uncommitted and untracked files included. The URL and the commands that install, build and serve the app come from `--url`, `--install`, `--build` and `--serve`, then `PROOFED_URL`, `PROOFED_INSTALL`, `PROOFED_BUILD` and `PROOFED_SERVE`, then `.proofed/config.json`, then the Proofed step of the repo's workflow. In a repo that already runs Proofed on its PRs, `proofed check` needs no flags. Before anything is built, the check asks TestMu, through `kane-cli balance` (free), whether it accepts the login or the `LT_USERNAME` and `LT_ACCESS_KEY` the runs would use; if not, it stops at once with exit 3: `kane_not_signed_in` with `kane-cli login` as the fix, or `kane_keys_rejected` when the keys are wrong or expired. If the app isn't running, Proofed starts it and stops it at the end: it installs the dependencies first when `node_modules` is missing or older than `package.json` or the lockfile (with the install command found as above, else the app's package manager), then builds, then serves. If something already answers at the URL and a build is configured, the check stops rather than test what may be an old build; `--reuse` tests it anyway.
164
+ In a repo that already runs Proofed on its PRs, `proofed check` needs no flags. `--dry-run` shows what would run and the credit estimate, for free. How the check finds the app, the exit codes, the JSON output and a sample run are in [docs/cli.md](https://github.com/t1dem/proofed/blob/main/docs/cli.md).
125
165
 
126
- A passed scenario isn't run again until its file, the URL, the base commit or a changed file in its `paths` changes. `--dry-run` shows what would run and the credit estimate, for free. In a terminal the scenarios update in place; in a pipe each event is one line, with a "still running" line at least every 30 seconds. From a real run on the demo store with the free shipping threshold changed to €60. Kane blamed the scenario, so the check ran twice, and the credits are for both runs. Paths are relative, and the credits in the "failed" line (56.8 in that run) are rounded as the CLI rounds them now:
166
+ For an agent, add this to the app's `AGENTS.md` or `CLAUDE.md`:
127
167
 
128
- ```
129
- Proofed: checking 1 of 3 scenario(s), --only, at http://localhost:4173.
130
- Estimate: about 30 Kane credits.
131
- Time: about 1 to 4 minutes per scenario, 3 at a time, so 1 to 4 minutes in all. Do not interrupt: let it finish.
132
- Building the app: pnpm build
133
- Starting the app: pnpm preview --port 4173
134
- Started the app in 1 s (build from --build, serve from --serve); its output is in .proofed-out/serve.log
135
- [0:01] started free-shipping: Free shipping from €50
136
- [0:26] still running: free-shipping 0:25 at "Step 3"
137
- [0:51] still running: free-shipping 0:50 at "Step 9"
138
- [1:16] still running: free-shipping 1:15 at "assert: shipping is now Free and the total is €51.00."
139
- [1:41] still running: free-shipping 1:40 at "assert: shipping is now Free and the total is €51.00."
140
- [1:45] retrying free-shipping: the check failed, but Kane blames the scenario; running it once more to be sure
141
- [2:11] still running: free-shipping 2:10 at "Step 3"
142
- [2:36] still running: free-shipping 2:35 at "Step 8"
143
- [3:01] still running: free-shipping 3:00 at "Step 10"
144
- [3:26] still running: free-shipping 3:25 at "assert: shipping is now Free and the total is €51.00."
145
- [3:51] failed free-shipping: Free shipping from €50 (3:50, 56.9 credits)
146
-
147
- ✗ Free shipping from €50 failed after 3:50
148
- Kane saw Final verification failed: "shipping is now Free and the total is €51.00."
149
- Why The scenario's check did not hold on the page, on two runs in a row. Kane believes the scenario is out of date.
150
- Kane thinks The test used the wrong free-shipping cutoff. After Paper Filters was increased, the basket subtotal was €51.00, which is still below the displayed €60.00 threshold, so the €4.90 shipping charge was correct.
151
- Next If the change in the app was intended, update the scenario; otherwise fix the app.
152
- Failed step assert: shipping is now Free and the total is €51.00.
153
- Clip .proofed-out/free-shipping/clip.mp4
154
- Scenario .proofed/scenarios/free-shipping.md
155
-
156
- ✗ 1 failed · 56.9 credits · 3m 52s
157
- Credits are Kane's report; balance may drop slightly more.
158
- 1 of 1 broke: Free shipping from €50
159
- Re-run what broke: proofed check --only free-shipping --url http://localhost:4173 --serve 'pnpm preview --port 4173' --build 'pnpm build'
168
+ ```md
169
+ ## Checking UI changes
170
+
171
+ Run the one command the task needs; `proofed check` checks its own setup first.
172
+ - Check the change: `proofed check --json`. One scenario: `proofed check --only <id> --json`.
173
+ - A behavior no scenario covers: `proofed check "<what>" --json`.
174
+ - To plan without spending credits, add `--dry-run`: it shows what would run and `estimatedCredits`.
175
+ - Only to ask which scenarios a change touches and their cost: `proofed list --json`.
176
+ - Only for setup questions: `proofed doctor --json`.
177
+ Allow at least 10 minutes for a check. stdout is one JSON document; progress is on stderr.
178
+ Exit 0: passed or nothing ran. On `failed`, read `reason` and `diagnosis`, fix and run `rerun`.
179
+ `failedCheck: "scenario_doubted"` is Kane's opinion: review the scenario's expectations.
180
+ `not_checked` is not a pass. On `error`, retry `rerun` once. Exit 3: follow `error.fix`.
181
+ Checks spend Kane credits; planning does not. Use `--no-retry` when another attempt is forbidden.
160
182
  ```
161
183
 
162
- A first run is estimated at 30 Kane credits per scenario. Later estimates use the last reported cost. Credits are what Kane reported for the runs; the account balance can drop slightly more. An interrupted run can spend credits before Kane reports them.
184
+ ### MCP and the Claude Code Stop hook
163
185
 
164
- `--json` prints one JSON document on stdout and the progress on stderr. Every run also writes it to `.proofed-out/result.json`, next to the clips; the folder has its own `.gitignore`. The exit code is 0 when everything checked passed, 1 when a scenario failed, 2 when nothing failed but something wasn't checked, 3 when the check couldn't start (the message says why and how to fix it; running it again unchanged won't help) and 130 on Ctrl-C or a closed terminal, which stops Kane, Chrome and the app first.
186
+ Start your editor or MCP client in the app's repository root. In Claude Code, add this to the project's `.mcp.json`.
165
187
 
166
- `failedCheck: "scenario_doubted"` means a scenario's check failed, but Kane believes it is out of date. `diagnosis` is Kane's opinion; `suggestion` and `next` say to update the scenario if the app change was intended, otherwise fix the app. Such a failure is run a second time before it is reported, at the scenario's cost again, and the second run is the result: Kane gives the same verdict when it misreads a page that is fine, and a misreading rarely repeats. A check that fails both times is a failure (exit 1). `notChecked: "scenario_doubted"` is used when Kane doubted the scenario without a failed check (exit 2).
188
+ ```json
189
+ {"mcpServers":{"proofed":{"command":"npx","args":["-y","proofed-cli","mcp"]}}}
190
+ ```
167
191
 
168
- For an agent, add this to the app's `AGENTS.md` or `CLAUDE.md`:
192
+ For Codex, add this to `config.toml`.
169
193
 
170
- ```md
171
- ## Checking UI changes
194
+ ```toml
195
+ [mcp_servers.proofed]
196
+ command = "npx"
197
+ args = ["-y", "proofed-cli", "mcp"]
198
+ tool_timeout_sec = 900
199
+ ```
200
+
201
+ To run affected checks automatically when Claude Code is about to stop, add this to `.claude/settings.json`.
172
202
 
173
- After changing UI code, run `proofed check --json` with a timeout of at least 10 minutes, and
174
- don't interrupt it. stdout is one JSON document. Exit 0: everything checked passed.
175
- - `failed`: read `reason` and `diagnosis`, fix the cause, run `rerun`.
176
- With `failedCheck: "scenario_doubted"`, diagnosis is Kane's opinion. If the app change was
177
- intended, update the scenario; otherwise fix the app.
178
- - `not_checked` is not a pass: fix the scenario or tell the user why Kane doubts it.
179
- - `error`: run its `rerun` command once more. Exit 3: do what `error.fix` says.
180
- Each run costs Kane credits; `proofed check --dry-run --json` shows what would run, for free.
181
- To check one thing without a scenario: `proofed check "the cart total updates" --json`.
203
+ ```json
204
+ {
205
+ "hooks": {
206
+ "Stop": [
207
+ {"hooks": [{"type": "command", "command": "npx -y proofed-cli hook claude-stop", "timeout": 900}]}
208
+ ]
209
+ }
210
+ }
182
211
  ```
183
212
 
213
+ `proofed_list`, `proofed_doctor` and dry runs are free. Checks spend Kane credits unless the pass is cached. The Stop hook asks Claude to continue after a failure, up to three times per session. See [agent setup and behavior](docs/cli.md#mcp-and-the-claude-code-stop-hook).
214
+
184
215
  ## Setup
185
216
 
186
- 1. Sign in at [proofed.neptunescodm.workers.dev](https://proofed.neptunescodm.workers.dev/app) and save your TestMu and Claude keys.
217
+ 1. Sign in at [proofed.neptunescodm.workers.dev](https://proofed.neptunescodm.workers.dev/app) and save your TestMu keys and a Claude token or OpenAI API key.
187
218
  2. Install the GitHub App on a repo. Proofed opens a PR with the workflow and puts the keys into the repo's secrets.
188
- 3. On that PR, Claude writes up to five scenarios for the app's main flows. Only the ones Kane saw pass are committed.
219
+ 3. On that PR, the selected provider writes up to five scenarios for the app's main flows. Only the ones Kane saw pass are committed.
189
220
 
190
- A scenario takes 1 to 4 minutes. The first-run estimate is 30 Kane credits. A fix attempt re-runs only the scenarios that broke.
221
+ One-click setup detects Gradle Android apps and configures checks on real cloud devices. This setup is not yet verified on a real device plan.
222
+
223
+ A web scenario takes 1 to 4 minutes and is estimated at 30 Kane credits the first time. Mobile and desktop costs are unknown without history. A fix attempt re-runs the broken scenarios and affected neighboring scenarios before pushing.
191
224
 
192
225
  <details>
193
226
  <summary><b>Setting it up by hand</b></summary>
194
227
 
195
228
  <br>
196
229
 
197
- Add `LT_USERNAME` and `LT_ACCESS_KEY` (TestMu: Settings → Keys) and `CLAUDE_CODE_OAUTH_TOKEN` (from `claude setup-token`) to the repo secrets, then add one workflow. The whole file, working, is [proofed-demo-store's](https://github.com/t1dem/proofed-demo-store/blob/main/.github/workflows/proofed.yml); the part that matters:
230
+ Add `LT_USERNAME` and `LT_ACCESS_KEY` (TestMu: Settings → Keys) and either `CLAUDE_CODE_OAUTH_TOKEN` (from `claude setup-token`) or `CODEX_API_KEY` (an OpenAI API key) to the repo secrets. If you use Codex, choose a Codex model in Proofed's repository settings or set the repository Actions variable `PROOFED_PROVIDER` to `codex` before running the workflow.
231
+
232
+ Then add one workflow. The whole file, working, is [proofed-demo-store's](https://github.com/t1dem/proofed-demo-store/blob/main/.github/workflows/proofed.yml); the part that matters:
198
233
 
199
234
  ```yaml
200
235
  on:
@@ -208,7 +243,7 @@ jobs:
208
243
  runs-on: ubuntu-latest
209
244
  concurrency:
210
245
  group: proofed-${{ github.event.pull_request.number || github.event.issue.number }}
211
- # A new push cancels a stale check, but not the push of Claude's fix: that run waits for the fix run.
246
+ # A new push cancels a stale check, but not the push of the fix: that run waits for the fix run.
212
247
  cancel-in-progress: ${{ github.event_name == 'pull_request' && github.actor != 'proofed-by-kane[bot]' }}
213
248
  steps:
214
249
  - uses: t1dem/proofed@main
@@ -220,66 +255,85 @@ jobs:
220
255
  lt-username: ${{ secrets.LT_USERNAME }}
221
256
  lt-access-key: ${{ secrets.LT_ACCESS_KEY }}
222
257
  claude-code-oauth-token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
258
+ codex-api-key: ${{ secrets.CODEX_API_KEY }}
223
259
  vars: ${{ toJSON(vars) }}
224
260
  ```
225
261
 
226
262
  - `vars` hands the action every Actions variable of the repo, so a new setting from the dashboard works without editing the workflow.
227
- - `id-token: write` lets the fixer push Claude's commit as the Proofed GitHub App, so your other workflows run on the fix commit without waiting for approval. Without it the fix is pushed with `GITHUB_TOKEN`.
263
+ - `id-token: write` lets the fixer push the fix commit as the Proofed GitHub App, so your other workflows run on the fix commit without waiting for approval. Without it the fix is pushed with `GITHUB_TOKEN`.
228
264
  - Clips go to a `proofed-clips` branch of the same repo, so the GIFs render in the comment with no storage of your own, in private repos too.
229
- - In `/proofed fix <model> <effort>`, `haiku`, `sonnet`, `opus` and `fable` mean the latest version, `opus 5.1` picks a version, and a full ID like `claude-opus-5-1` is used as written. Effort is `low`, `medium`, `high`, `xhigh` or `max`.
265
+ - Claude aliases: `haiku`, `sonnet`, `opus`, `fable`. A version such as `opus 5.1` and full Claude IDs are accepted. Effort: `low`, `medium`, `high`, `xhigh`, `max`.
266
+ - Codex aliases: `sol`, `terra`, `astra`, `luna`. Full IDs: `gpt-6.2-sol`, `gpt-6.1-sol`, `gpt-6.1-terra`, `gpt-6-astra`, `gpt-6-luna`. Effort: `low`, `medium`, `high`, `xhigh`, `max`; Sol, Terra and Astra also accept `ultra`.
267
+ - Actions variables `PROOFED_PROVIDER`, `PROOFED_MODEL`, `PROOFED_EFFORT` and `PROOFED_AUTOFIX` store the menu choice. The provider can be inferred from the model. Existing Claude workflows and their checkbox label keep working. To enable Codex in an installed workflow, add `codex-api-key: ${{ secrets.CODEX_API_KEY }}` and let its edited-comment condition match `- [x] **Fix with Codex**` as well as `- [x] **Fix with Claude**`.
268
+ - Codex CLI is installed only for Codex runs. `codex exec` reads `CODEX_API_KEY`; local runs can also use `codex login`. Its workspace-write sandbox blocks command network access and writes outside the workspace, and Proofed restores changes to scenarios and workflows before checking a fix.
269
+ - The checkout keeps no token in `.git/config` (`persist-credentials: false`); the push hands the token to git itself. Claude and Codex start without the job's tokens. A change that still contains one is discarded before it is built or checked, and the agent's answer is masked before it reaches the PR or the dashboard.
230
270
 
231
271
  </details>
232
272
 
273
+ ## Mobile and desktop apps
274
+
275
+ A scenario can set `target: ios`, `android` or `desktop`; scenarios without it stay web checks.
276
+
277
+ - **Local iOS and Android** need an Apple Silicon Mac (macOS arm64), a built app, Kane's managed dependencies and one device you booted yourself, picked by `device` and `os_version`. GitHub Actions can use a self-hosted `[self-hosted, macOS, ARM64]` runner. `proofed doctor --target ios` (or `android`) lists what is missing and installs nothing.
278
+ - **Cloud iOS and Android** run on real TestMu devices from Linux, macOS or Windows. The plan must include real-device automation. These runs give Kane's screenshots, without a Proofed MP4.
279
+ - **Desktop** is experimental and covers one Electron Chromium window: give `launch` (or `app`) and `cdp_endpoint`. Native menus, OS file dialogs, Safari, Tauri and WKWebView are not supported.
280
+ - **Fixing** uses the same checkbox and auto-fix setting on every target. Set `build` to produce the artifact in `app`, or the desktop code started by `launch`. Each check installs, uploads or launches the rebuild. `url` and `serve` are needed only for web scenarios. Pre-uploaded `APP…` IDs and desktop endpoints without a launch command or app path cannot verify a rebuild, so the report says why fixing didn't run.
281
+
282
+ Commands and Android cloud, self-hosted Android and macOS Electron Actions examples: [docs/cli.md](https://github.com/t1dem/proofed/blob/main/docs/cli.md#github-actions-examples).
283
+ Real-run verification by target and host is listed in [Platform support](https://github.com/t1dem/proofed/blob/main/docs/cli.md#platform-support).
284
+
233
285
  ## Limits
234
286
 
235
287
  - **Kane's verdict on the same failure varies.** On [#6](https://github.com/t1dem/proofed-demo-store/pull/6) the check that [#9](https://github.com/t1dem/proofed-demo-store/pull/9) reports as a break came back twice as "the test may be wrong". Without a failed check, Proofed shows such a run as not confirmed and starts no fix. A failed `assert:` that Kane blames on the scenario is run a second time, and stays a failure when it fails again.
236
- - **Fixes need Claude's usage limit to have room.** On [#7](https://github.com/t1dem/proofed-demo-store/pull/7) and [#8](https://github.com/t1dem/proofed-demo-store/pull/8) it ran out: Kane caught the break, no fix followed, and the report says so.
288
+ - **Fixes need room in the selected provider's usage limit.** On [#7](https://github.com/t1dem/proofed-demo-store/pull/7) and [#8](https://github.com/t1dem/proofed-demo-store/pull/8) it ran out: Kane caught the break, no fix followed, and the report says so.
237
289
  - **Only flows with a scenario are checked.** A scenario whose `paths` miss a file isn't picked when that file changes.
238
290
  - **Slow next to unit tests.** One to four minutes of Kane per scenario, plus a build and a re-check per fix attempt.
239
291
 
240
- ## What running Kane in CI took
292
+ ## What we ran into with Kane CLI
241
293
 
242
- Each fix is a few lines, found by a run that went wrong.
294
+ What went wrong in real runs, and what Proofed does about it.
243
295
 
244
- | What went wrong | What Proofed does | Where |
296
+ | What happened | What Proofed does | Where |
245
297
  |---|---|---|
246
- | Asked something vague, Kane waited and reported a pass | A pass with no `assert` step counts as "not checked" | `src/run.ts` |
247
- | Kane routed around a broken button and passed | Kane is told to do each step once, with no other way to the goal | `src/run.ts` |
248
- | A run was still going after 361 seconds | A 360-second wall-clock limit over Kane's own `--timeout 300` | `src/kane.ts` |
249
- | Kane's children outlived a plain kill and held the output open | Kane runs in its own process group, killed as a whole | `src/kane.ts` |
250
- | On a page that was fine, Kane reported a heading as not visible and blamed the scenario | A failed check Kane blames on the scenario is run a second time; the second run is the result | `src/run.ts` |
251
- | In 13 of 36 parallel starts, a scenario exited within seconds | One `kane-cli login` before the scenarios, and one retry; the retry always reached a verdict | `action.yml`, `src/run.ts` |
298
+ | Asked something vague, Kane waited and reported a pass | A pass with no `assert` step counts as "not checked" | `src/check/run.ts` |
299
+ | Kane routed around a broken button and passed | Kane is told to do each step once, with no other way to the goal | `src/check/run.ts` |
300
+ | A run was still going after 361 seconds | A 360-second wall-clock limit over Kane's own `--timeout 300`; `timeout_minutes` in a scenario raises both | `src/kane/kane.ts` |
301
+ | Kane's children outlived a plain kill and held the output open | Kane runs in its own process group, killed as a whole | `src/kane/kane.ts` |
302
+ | On a page that was fine, Kane reported a heading as not visible and blamed the scenario | A failed check Kane blames on the scenario is run a second time; two failures stay failed; a failure followed by a pass is not checked | `src/check/run.ts` |
303
+ | In 13 of 36 parallel starts, a scenario exited within seconds | One `kane-cli login` before the scenarios, and one retry; the retry always reached a verdict | `action.yml`, `src/check/run.ts` |
252
304
 
253
- ## Code
305
+ ### Text checks and uncertain passes
254
306
 
255
- Node 22.18+ runs the checkout's TypeScript directly. The GitHub Action needs no build or package install.
256
- `pnpm build` emits the CLI and its imports to `dist/` for npm. `npm pack` builds it automatically.
257
- `pnpm typecheck` and `pnpm test` check the source. `pnpm check:package` builds a tarball, checks its
258
- contents, installs it into a temporary prefix and runs its version and help. It removes its temp files.
307
+ For web runs, Proofed compares Kane's pass on the scenario's last check with the page text. It costs no Kane credits.
259
308
 
260
- To release, confirm the version in `package.json` (currently `0.1.3`); published versions cannot be reused. From a clean checkout with Node 22.18+:
309
+ - **What is compared.** Text in quotes anywhere in the last check, such as `Check that the total is "€81.90".` Without quotes, only the shape `Check that A contains B.` (or `shows`, `lists`, `includes`), and only for a side of two or more words that reads like on-screen text: `Check that Vos outils favoris contains Générateur de token.` compares both names, `Check that the favorites section contains Token generator.` compares only `Token generator`.
310
+ - **When.** Proofed reads the page as Kane starts the assert for that check and again as it finishes it. A text counts as missing only when both reads lack it.
311
+ - **What is read.** All visible text in the document, not just the part in view: open shadow roots, same-origin frames, input values and placeholders, the chosen option of a select, image `alt`, `aria-label` and `title`, SVG text and CSS `content`. Case, spaces and quote or dash styles don't matter.
312
+ - **What a contradiction does.** A missing text turns Kane's pass into "not checked", and the reason names the text. Nothing is ever turned into a failure.
313
+ - **What is left to Kane.** Negative checks ("no longer", "not"), other wordings, colours, layout, and whether the text is in the right place. A page with a visible canvas, video, embedded object, cross-origin frame, registered custom element without an open shadow root, or CSS counter can't contradict Kane, since its text may not be readable. Images and icons don't stop the comparison, so a check whose text exists only as pixels in an image can end up "not checked".
261
314
 
262
- ```sh
263
- pnpm install --frozen-lockfile
264
- npm login --registry=https://registry.npmjs.org/
265
- npm whoami --registry=https://registry.npmjs.org/
266
- npm publish --access public --registry=https://registry.npmjs.org/
267
- npm view proofed-cli@0.1.3 version bin engines dist.tarball --registry=https://registry.npmjs.org/
268
- npx --yes proofed-cli@0.1.3 --version
269
- npx --yes proofed-cli@0.1.3 --help
270
- ```
315
+ If a failed assert is retried because Kane doubts the scenario, two failures stay failed. A failure followed by a pass is "not checked", and both runs' reasons are kept.
316
+
317
+ ### Credit figures
318
+
319
+ `credits` is Kane's own estimate, retries included, and is labelled as an estimate in the terminal, the reports and the dashboard (`creditsSource: "kane_estimate"` in JSON). An interrupted run can spend credits before Kane reports any cost.
320
+
321
+ Proofed can also read the free `kane-cli balance` before and after a scenario and report the account's debit as `accountBalance`. That figure covers the whole account: other activity on the account can contribute to it, so attribution to the scenario is unknown. Proofed drops it when it detects overlapping Proofed runs on the same machine; it cannot detect remote account activity.
322
+ ## Code
323
+
324
+ Node 22.18+ runs the checkout's TypeScript directly, so the GitHub Action needs no build or package install. `pnpm build` emits the CLI and its imports to `dist/` for npm; `npm pack` builds it automatically. `pnpm typecheck` and `pnpm test` check the source. `pnpm check:package` builds a tarball, checks its contents, installs it into a temporary prefix and runs its version and help, then removes its temp files.
325
+
326
+ Releasing to npm is manual: [docs/release.md](https://github.com/t1dem/proofed/blob/main/docs/release.md).
271
327
 
272
- Use the chosen version in the last three commands. `npm publish` runs typecheck, tests and the package
273
- check before packing a fresh build. Complete npm's sign-in and two-factor prompts when asked.
274
- Publishing is manual; no release workflow runs on pushes or pull requests.
328
+ Before deploying the Worker, run `pnpm exec wrangler d1 migrations apply proofed --remote` from `site/`. This applies migration `0008_codex_key.sql` before the Worker needs the `codex_key` column. Then run `pnpm deploy` from `site/`.
275
329
 
276
330
  | File | What it does |
277
331
  |---|---|
278
- | `src/cli.ts` | The PR check |
279
- | `src/fix.ts` | The fix loop |
280
- | `src/run.ts` | One scenario: Chrome, recorder, Kane, clip |
281
- | `src/generate.ts` | The setup PR's first scenarios |
282
- | `src/mode.ts` | Decides what an event asks for |
332
+ | `src/action/cli.ts` | The PR check |
333
+ | `src/fix/fix.ts` | The fix loop |
334
+ | `src/check/run.ts` | One scenario: target preparation, recording, Kane, clip |
335
+ | `src/fix/generate.ts` | The setup PR's first scenarios |
336
+ | `src/action/mode.ts` | Decides what an event asks for |
283
337
  | `site/` | The dashboard, `/try` and the Cloudflare Worker behind them |
284
338
 
285
339
  ## License
@@ -0,0 +1,130 @@
1
+ import { baseRev } from "../changes.js";
2
+ import { env } from "../env.js";
3
+ import { effortsFor, isEffort, parseModel } from "../fix/models.js";
4
+ import { scenarioDoubted } from "../report/runresult.js";
5
+ import { loadScenariosOr } from "../scenarios.js";
6
+ import { checkedAt, scenarioTarget } from "../fix/fixtarget.js";
7
+ import { resolveScenarioTarget, TARGET_KEYS } from "../targets/target.js";
8
+ // "/proofed" in a PR comment re-runs the check, which also gives a PR opened before Proofed was
9
+ // added its first run. "/proofed <what to check>" has Kane check just that. A slash command,
10
+ // not "@proofed": that name belongs to someone else on GitHub and would mention them.
11
+ const COMMAND = /(?:^|\s)\/proofed\b([\s\S]*)/i;
12
+ export function parseCommand(comment) {
13
+ const match = COMMAND.exec(comment);
14
+ return match ? match[1].trim() : undefined;
15
+ }
16
+ // "/proofed fix [model] [effort]" has the fixer fix the broken scenarios, with that model this once.
17
+ // Only the first line counts, so a note under the command doesn't become part of the model name.
18
+ export function parseFix(command) {
19
+ const words = (command.split("\n")[0] ?? "").trim().split(/\s+/).filter(Boolean);
20
+ if (words[0]?.toLowerCase() !== "fix")
21
+ return undefined;
22
+ const rest = words.slice(1);
23
+ const last = rest.at(-1)?.toLowerCase() ?? "";
24
+ const effort = isEffort(last) ? last : undefined;
25
+ const modelWords = effort ? rest.slice(0, -1) : rest;
26
+ if (modelWords.length === 0)
27
+ return { effort };
28
+ const choice = parseModel(modelWords);
29
+ if ("error" in choice)
30
+ return choice;
31
+ if (effort && !effortsFor(choice.model).includes(effort))
32
+ return { error: `The model \`${choice.model}\` doesn't support \`${effort}\` effort.` };
33
+ return { model: choice.model, effort };
34
+ }
35
+ // What the PR description asks to have checked. HTML comments (PR templates) are dropped, and a
36
+ // long description is a changelog rather than a request, so it's left alone.
37
+ export function descriptionRequest(body) {
38
+ const text = (body ?? "").replace(/<!--[\s\S]*?-->/g, "").trim();
39
+ return text && text.length <= 1500 ? text : undefined;
40
+ }
41
+ // Any short description becomes a request, and many ask for nothing ("Will be closed, not merged.").
42
+ // Left to itself Kane then improvises: it signs in, ends up on GitHub's OAuth page, and the report
43
+ // says the test may be wrong. A /proofed comment is always a request, so it gets no such way out.
44
+ const MAY_ASK_NOTHING = "If the text above doesn't describe something a user can see or do in this app, stop right away " +
45
+ "without clicking anything: there is nothing to check. Never sign in, and never leave the app's own pages to get there.";
46
+ const descriptionId = /^asked-in-description(?:-\d+)?$/;
47
+ export const isDescriptionScenario = (s) => !s.file && descriptionId.test(s.id);
48
+ export const DESCRIPTION_DOUBTED = "Kane couldn't verify what the PR description asks.";
49
+ export const DESCRIPTION_UNCHECKED = "The PR description didn't name anything Kane could check.";
50
+ // The description is best effort. An unconfirmed result only gets a line under the report.
51
+ export function descriptionCheckNote(r) {
52
+ if (!isDescriptionScenario(r.scenario) || r.requestUnavailable)
53
+ return;
54
+ if (scenarioDoubted(r))
55
+ return DESCRIPTION_DOUBTED;
56
+ if (r.outcome === "unsure")
57
+ return DESCRIPTION_UNCHECKED;
58
+ }
59
+ const NAMES = {
60
+ description: "What the PR description asks",
61
+ comment: "What the /proofed comment asks",
62
+ terminal: "What you asked to check",
63
+ };
64
+ // "terminal": `proofed check "<text>"`, run by a person or a coding agent on their own machine.
65
+ export function askedScenario(where, text, target = resolveScenarioTarget({}, {}, process.env, process.cwd())) {
66
+ const scenario = {
67
+ id: where === "terminal" ? "asked" : `asked-in-${where}`,
68
+ file: "",
69
+ name: NAMES[where],
70
+ paths: [],
71
+ url: "/",
72
+ objective: "",
73
+ };
74
+ const location = target.kind === "web" ? "in the browser" : checkedAt({ ...scenario, resolvedTarget: target });
75
+ scenario.objective =
76
+ (where === "terminal"
77
+ ? `The developer of this app asked for this to be checked:\n\n${text}\n\n`
78
+ : `The author of this pull request asked for this to be checked:\n\n${text}\n\n`) +
79
+ `Open the app and check exactly that ${location}, the way a user would. It passes only if what they ` +
80
+ `asked about actually works; the ${target.kind === "web" ? "page" : "app"} loading is not enough.` +
81
+ (where === "description" ? ` ${MAY_ASK_NOTHING}` : "");
82
+ return scenario;
83
+ }
84
+ // File scenarios and requests share the output directory, which may be case-insensitive.
85
+ export function avoidFileId(request, files) {
86
+ if (request.file)
87
+ return request;
88
+ const fileIds = new Set(files.map((s) => s.id.toLowerCase()));
89
+ if (!fileIds.has(request.id))
90
+ return request;
91
+ const stem = request.id.replace(/-\d+$/, "");
92
+ let suffix = 2;
93
+ while (fileIds.has(`${stem}-${suffix}`))
94
+ suffix++;
95
+ return { ...request, id: `${stem}-${suffix}` };
96
+ }
97
+ export function askedScenarioFromFile(where, text, source) {
98
+ const scenario = { ...askedScenario(where, text, scenarioTarget(source)), targetScenarioId: source.id };
99
+ for (const key of TARGET_KEYS)
100
+ if (source[key])
101
+ scenario[key] = source[key];
102
+ return scenario;
103
+ }
104
+ // Reports store the generated objective. Recover the original request only if the check's
105
+ // generator can reproduce that objective with the current target settings.
106
+ export function replayAskedScenario(stored) {
107
+ const where = descriptionId.test(stored.id) ? "description" : /^asked-in-comment(?:-\d+)?$/.test(stored.id) ? "comment" : undefined;
108
+ if (!where || stored.file !== "" || stored.url !== "/" || typeof stored.objective !== "string")
109
+ return;
110
+ let template;
111
+ if (stored.targetScenarioId !== undefined) {
112
+ const { PROOFED_BASE_REF: ref, PROOFED_BASE_SHA: sha } = process.env;
113
+ const rev = ref && sha ? baseRev({ ref, sha }) : sha;
114
+ // Read target settings from the checkout before replaying a request from a report.
115
+ const source = loadScenariosOr(env("PROOFED_SCENARIOS", ".proofed/scenarios"), rev).find((s) => s.id === stored.targetScenarioId);
116
+ if (!source)
117
+ return;
118
+ template = askedScenarioFromFile(where, "", source);
119
+ }
120
+ else
121
+ template = askedScenario(where, "");
122
+ const boundary = template.objective.indexOf("\n\n") + 2;
123
+ const prefix = template.objective.slice(0, boundary);
124
+ const suffix = template.objective.slice(boundary);
125
+ if (!stored.objective.startsWith(prefix) || !stored.objective.endsWith(suffix))
126
+ return;
127
+ const request = stored.objective.slice(prefix.length, -suffix.length);
128
+ if (request.trim())
129
+ return { ...template, id: stored.id, objective: `${prefix}${request}${suffix}` };
130
+ }