proofed-cli 0.0.0-stage → 0.1.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 t1dem
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,281 @@
1
- # Temporary Holding Version
1
+ <div align="center">
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ <img src="site/public/favicon.svg" width="64" alt="">
4
+
5
+ # Proofed
6
+
7
+ **Every pull request, run in Chrome before you merge it.**
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.
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)
13
+
14
+ <sub>Built for the Kane CLI hackathon, November 2026.</sub>
15
+
16
+ <br>
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">
19
+
20
+ </div>
21
+
22
+ <br>
23
+
24
+ <table>
25
+ <tr>
26
+ <th width="50%">✗ Kane catches the break</th>
27
+ <th width="50%">✓ Kane confirms Claude's fix</th>
28
+ </tr>
29
+ <tr>
30
+ <td><img src="https://github.com/t1dem/proofed-demo-store/raw/proofed-clips/pr-12/c1aaa79-43757307941/free-shipping.gif" alt="Kane opens the bag: a €44.50 order ships free"></td>
31
+ <td><img src="https://github.com/t1dem/proofed-demo-store/raw/proofed-clips/pr-12/f54f1b5-43757307941/free-shipping.gif" alt="Kane opens the bag after the fix: shipping is €4.90, then Free above €50"></td>
32
+ </tr>
33
+ <tr>
34
+ <td>A €44.50 bag ships free, though free shipping starts at €50.</td>
35
+ <td>Claude changed one line in <code>src/pricing.ts</code>. Shipping is €4.90 again.</td>
36
+ </tr>
37
+ </table>
38
+
39
+ <p align="center"><sub>From <a href="https://github.com/t1dem/proofed-demo-store/pull/12">demo-store #12</a>: 8.5 minutes from opening the pull request to the fixed report.</sub></p>
40
+
41
+ ## For judges
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:
50
+
51
+ | PR | What Kane found | What happened next |
52
+ |---|---|---|
53
+ | [#5](https://github.com/t1dem/proofed-demo-store/pull/5) | The promo code `welcome10` in lowercase is rejected | Fixed on the first attempt ([`c242f6c`](https://github.com/t1dem/proofed-demo-store/commit/c242f6c)) |
54
+ | [#9](https://github.com/t1dem/proofed-demo-store/pull/9) | The confirmation page charges €13.00 instead of €17.90 | Kane rejected the first attempt, the second passed ([`f9fa5a6`](https://github.com/t1dem/proofed-demo-store/commit/f9fa5a6)) |
55
+ | [#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
+ | [#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
+
58
+ ## How it works
59
+
60
+ <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.">
63
+ </picture>
64
+
65
+ - 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.
70
+
71
+ ## Scenarios
72
+
73
+ One Markdown file per flow in `.proofed/scenarios/`, in plain English. `paths` says which files it guards; without it, the scenario runs on every PR.
74
+
75
+ ```md
76
+ ---
77
+ name: Promo code total
78
+ paths: [src/pricing.ts, src/pages/Cart.tsx]
79
+ url: /
80
+ ---
81
+ Add Ethiopia Guji to the bag twice and the Hand Grinder once.
82
+ Open the bag, type the promo code welcome10 in lowercase and apply it.
83
+ Check that the discount is −€9.10, shipping is Free and the total is €81.90.
84
+ ```
85
+
86
+ ## Commands
87
+
88
+ Comment on a PR. Only people with write access can run them.
89
+
90
+ | Comment | What happens |
91
+ |---|---|
92
+ | `/proofed` | Check the PR again |
93
+ | `/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 |
96
+
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.
98
+
99
+ ## Locally and from an AI agent
100
+
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.
102
+
103
+ It needs Node 24 or later, Chrome, [Kane CLI](https://www.npmjs.com/package/@testmuai/kane-cli) signed in (`kane-cli login`) and ffmpeg for the clips.
104
+
105
+ Install the registry package with one manager:
106
+
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` |
113
+
114
+ The command is `proofed`; `proofed doctor` says what else is missing. It runs on Node 24 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.
115
+
116
+ In the app's repo:
117
+
118
+ | Command | What it does |
119
+ |---|---|
120
+ | `proofed doctor` | Checks Node, Git, the scenarios, Kane CLI and its login, credits, Chrome, ffmpeg and the app, each with a fix |
121
+ | `proofed list` | Every scenario, whether the change touches it and whether its pass is cached |
122
+ | `proofed check` | Runs the scenarios the change touches; `proofed check "the cart total updates"` checks just that |
123
+
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 build and serve the app come from `--url`, `--build` and `--serve`, then `PROOFED_URL`, `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. If the app isn't running, Proofed builds and starts it, and stops it at the end. 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.
125
+
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. Shown with the current CLI wording and first-run estimate; paths are relative:
127
+
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 "click: Clicking Add House Espresso to bag"
137
+ [0:51] still running: free-shipping 0:50 at "Step 7"
138
+ [1:16] still running: free-shipping 1:15 at "Step 11"
139
+ [1:41] still running: free-shipping 1:41 at "assert: shipping is now Free and the total is €51.00."
140
+ [2:01] failed free-shipping: Free shipping from €50 (2:00, 27.4 credits)
141
+
142
+ ✗ Free shipping from €50 failed after 2:00
143
+ Kane saw Final verification failed: "shipping is now Free and the total is €51.00."
144
+ Why The scenario's check did not hold on the page. Kane believes the scenario is out of date.
145
+ Kane thinks The test used the wrong free-shipping threshold. The cart subtotal after adding one more Paper Filters was €51.00, which is still below the €60.00 threshold shown by the store.
146
+ Next If the change in the app was intended, update the scenario; otherwise fix the app.
147
+ Failed step assert: shipping is now Free and the total is €51.00.
148
+ Clip .proofed-out/free-shipping/clip.mp4
149
+ Scenario .proofed/scenarios/free-shipping.md
150
+
151
+ ✗ 1 failed · 27.4 credits · 2m 2s
152
+ Credits are Kane's report; balance may drop slightly more.
153
+ 1 of 1 broke: Free shipping from €50
154
+ Re-run what broke: proofed check --only free-shipping --url http://localhost:4173 --serve 'pnpm preview --port 4173' --build 'pnpm build'
155
+ ```
156
+
157
+ 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.
158
+
159
+ `--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) and 130 on Ctrl-C or a closed terminal, which stops Kane, Chrome and the app first.
160
+
161
+ `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. This stays a failure (exit 1). `notChecked: "scenario_doubted"` is used when Kane doubted the scenario without a failed check (exit 2).
162
+
163
+ For an agent, add this to the app's `AGENTS.md` or `CLAUDE.md`:
164
+
165
+ ```md
166
+ ## Checking UI changes
167
+
168
+ After changing UI code, run `proofed check --json` with a timeout of at least 10 minutes, and
169
+ don't interrupt it. stdout is one JSON document. Exit 0: everything checked passed.
170
+ - `failed`: read `reason` and `diagnosis`, fix the cause, run `rerun`.
171
+ With `failedCheck: "scenario_doubted"`, diagnosis is Kane's opinion. If the app change was
172
+ intended, update the scenario; otherwise fix the app.
173
+ - `not_checked` is not a pass: fix the scenario or tell the user why Kane doubts it.
174
+ - `error`: run its `rerun` command once more. Exit 3: do what `error.fix` says.
175
+ Each run costs Kane credits; `proofed check --dry-run --json` shows what would run, for free.
176
+ To check one thing without a scenario: `proofed check "the cart total updates" --json`.
177
+ ```
178
+
179
+ ## Setup
180
+
181
+ 1. Sign in at [proofed.neptunescodm.workers.dev](https://proofed.neptunescodm.workers.dev/app) and save your TestMu and Claude keys.
182
+ 2. Install the GitHub App on a repo. Proofed opens a PR with the workflow and puts the keys into the repo's secrets.
183
+ 3. On that PR, Claude writes up to five scenarios for the app's main flows. Only the ones Kane saw pass are committed.
184
+
185
+ 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.
186
+
187
+ <details>
188
+ <summary><b>Setting it up by hand</b></summary>
189
+
190
+ <br>
191
+
192
+ 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:
193
+
194
+ ```yaml
195
+ on:
196
+ pull_request:
197
+ issue_comment:
198
+ types: [created, edited]
199
+ permissions: { contents: write, pull-requests: write, issues: write, statuses: write, id-token: write }
200
+ jobs:
201
+ proofed:
202
+ if: # PR events, /proofed comments from people with write access, and a ticked box (see the demo store)
203
+ runs-on: ubuntu-latest
204
+ concurrency:
205
+ group: proofed-${{ github.event.pull_request.number || github.event.issue.number }}
206
+ # A new push cancels a stale check, but not the push of Claude's fix: that run waits for the fix run.
207
+ cancel-in-progress: ${{ github.event_name == 'pull_request' && github.actor != 'proofed-by-kane[bot]' }}
208
+ steps:
209
+ - uses: t1dem/proofed@main
210
+ with:
211
+ url: http://localhost:4173
212
+ install: npm ci
213
+ build: npm run build
214
+ serve: npm run preview
215
+ lt-username: ${{ secrets.LT_USERNAME }}
216
+ lt-access-key: ${{ secrets.LT_ACCESS_KEY }}
217
+ claude-code-oauth-token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
218
+ vars: ${{ toJSON(vars) }}
219
+ ```
220
+
221
+ - `vars` hands the action every Actions variable of the repo, so a new setting from the dashboard works without editing the workflow.
222
+ - `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`.
223
+ - 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.
224
+ - 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`.
225
+
226
+ </details>
227
+
228
+ ## Limits
229
+
230
+ - **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:` stays a failure even when Kane blames the scenario.
231
+ - **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.
232
+ - **Only flows with a scenario are checked.** A scenario whose `paths` miss a file isn't picked when that file changes.
233
+ - **Slow next to unit tests.** One to four minutes of Kane per scenario, plus a build and a re-check per fix attempt.
234
+
235
+ ## What running Kane in CI took
236
+
237
+ Each fix is a few lines, found by a run that went wrong.
238
+
239
+ | What went wrong | What Proofed does | Where |
240
+ |---|---|---|
241
+ | Asked something vague, Kane waited and reported a pass | A pass with no `assert` step counts as "not checked" | `src/run.ts` |
242
+ | 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` |
243
+ | A run was still going after 361 seconds | A 360-second wall-clock limit over Kane's own `--timeout 300` | `src/kane.ts` |
244
+ | 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` |
245
+ | 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` |
246
+
247
+ ## Code
248
+
249
+ Node 24+ runs the checkout's TypeScript directly. The GitHub Action needs no build or package install.
250
+ `pnpm build` emits the CLI and its imports to `dist/` for npm. `npm pack` builds it automatically.
251
+ `pnpm typecheck` and `pnpm test` check the source. `pnpm check:package` builds a tarball, checks its
252
+ contents, installs it into a temporary prefix and runs its version and help. It removes its temp files.
253
+
254
+ To release, confirm the version in `package.json` (currently `0.1.0`); published versions cannot be reused. From a clean checkout with Node 24+:
255
+
256
+ ```sh
257
+ pnpm install --frozen-lockfile
258
+ npm login --registry=https://registry.npmjs.org/
259
+ npm whoami --registry=https://registry.npmjs.org/
260
+ npm publish --access public --registry=https://registry.npmjs.org/
261
+ npm view proofed-cli@0.1.0 version bin engines dist.tarball --registry=https://registry.npmjs.org/
262
+ npx --yes proofed-cli@0.1.0 --version
263
+ npx --yes proofed-cli@0.1.0 --help
264
+ ```
265
+
266
+ Use the chosen version in the last three commands. `npm publish` runs typecheck, tests and the package
267
+ check before packing a fresh build. Complete npm's sign-in and two-factor prompts when asked.
268
+ Publishing is manual; no release workflow runs on pushes or pull requests.
269
+
270
+ | File | What it does |
271
+ |---|---|
272
+ | `src/cli.ts` | The PR check |
273
+ | `src/fix.ts` | The fix loop |
274
+ | `src/run.ts` | One scenario: Chrome, recorder, Kane, clip |
275
+ | `src/generate.ts` | The setup PR's first scenarios |
276
+ | `src/mode.ts` | Decides what an event asks for |
277
+ | `site/` | The dashboard, `/try` and the Cloudflare Worker behind them |
278
+
279
+ ## License
280
+
281
+ [MIT](LICENSE)
@@ -0,0 +1,11 @@
1
+ const checkNode = (version = process.versions.node) => {
2
+ if (process.versions.bun) {
3
+ console.error("proofed: Node 24 or newer is required. Install Node 24+ from https://nodejs.org/ and put node on PATH. Run proofed without --bun.");
4
+ process.exit(3);
5
+ }
6
+ if (Number(version.split(".")[0]) >= 24) return;
7
+ console.error(`proofed: Node 24 or newer is required (found ${version}). Install Node 24+ from https://nodejs.org/ and run this command again.`);
8
+ process.exit(3);
9
+ };
10
+
11
+ module.exports = checkNode;
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env node
2
+ require("./node-version.cjs")();
3
+
4
+ const { existsSync } = require("node:fs");
5
+ const { pathToFileURL } = require("node:url");
6
+ const { resolve } = require("node:path");
7
+
8
+ // A checkout must use its source, even when an earlier build is still on disk.
9
+ const entry = existsSync(resolve(__dirname, "../src")) ? "../src/proofed.ts" : "../dist/proofed.js";
10
+
11
+ import(pathToFileURL(resolve(__dirname, entry)).href).catch((error) => {
12
+ console.error(`proofed: ${error.message}`);
13
+ process.exitCode = 3;
14
+ });
package/dist/args.js ADDED
@@ -0,0 +1,156 @@
1
+ import { parseArgs } from "node:util";
2
+ // A mistake in how proofed was called. Always one line, with the closest valid alternative.
3
+ export class UsageError extends Error {
4
+ }
5
+ const COMMON = {
6
+ json: { type: "boolean" },
7
+ help: { type: "boolean", short: "h" },
8
+ scenarios: { type: "string" },
9
+ out: { type: "string" },
10
+ };
11
+ const APP = {
12
+ url: { type: "string" },
13
+ serve: { type: "string" },
14
+ build: { type: "string" },
15
+ };
16
+ export const FLAGS = {
17
+ check: {
18
+ ...COMMON,
19
+ ...APP,
20
+ base: { type: "string" },
21
+ only: { type: "string" },
22
+ all: { type: "boolean" },
23
+ "dry-run": { type: "boolean" },
24
+ "no-cache": { type: "boolean" },
25
+ headed: { type: "boolean" },
26
+ reuse: { type: "boolean" },
27
+ concurrency: { type: "string" },
28
+ "serve-timeout": { type: "string" },
29
+ verbose: { type: "boolean" },
30
+ },
31
+ list: { ...COMMON, base: { type: "string" }, url: { type: "string" } },
32
+ doctor: { ...COMMON, ...APP },
33
+ };
34
+ export const COMMANDS = Object.keys(FLAGS);
35
+ const isCommand = (word) => Object.hasOwn(FLAGS, word);
36
+ // Edit distance, for "did you mean".
37
+ function distance(a, b) {
38
+ let row = Array.from({ length: b.length + 1 }, (_, i) => i);
39
+ for (let i = 1; i <= a.length; i++) {
40
+ const next = [i];
41
+ for (let j = 1; j <= b.length; j++) {
42
+ next[j] = Math.min(row[j] + 1, next[j - 1] + 1, row[j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1));
43
+ }
44
+ row = next;
45
+ }
46
+ return row[b.length];
47
+ }
48
+ export const closest = (word, options) => options.reduce((best, o) => (distance(word, o) < distance(word, best) ? o : best), options[0]);
49
+ const flagNames = (command) => Object.keys(FLAGS[command]).map((name) => `--${name}`);
50
+ function unknownCommand(word) {
51
+ return new UsageError(`Unknown command "${word}". Did you mean: proofed ${closest(word, COMMANDS)}?`);
52
+ }
53
+ export function parse(argv) {
54
+ const [first, ...rest] = argv;
55
+ if (first === undefined || first === "--help" || first === "-h")
56
+ return { kind: "help" };
57
+ if (first === "--version" || first === "-v" || first === "-V")
58
+ return { kind: "version" };
59
+ if (first === "help") {
60
+ const topic = rest[0];
61
+ if (topic === undefined)
62
+ return { kind: "help" };
63
+ if (isCommand(topic))
64
+ return { kind: "help", command: topic };
65
+ throw unknownCommand(topic);
66
+ }
67
+ if (first.startsWith("-")) {
68
+ const name = first.split("=")[0];
69
+ if (flagNames("check").includes(name))
70
+ throw new UsageError(`Flags go after the command: proofed check ${first}`);
71
+ throw new UsageError(`Unknown flag ${first}. Did you mean: proofed ${closest(name, ["--help", "--version"])}?`);
72
+ }
73
+ if (!isCommand(first))
74
+ throw unknownCommand(first);
75
+ return { kind: "run", command: first, ...parseFlags(first, rest) };
76
+ }
77
+ function parseFlags(command, args) {
78
+ const spec = FLAGS[command];
79
+ const { values, tokens } = parseArgs({ args, options: FLAGS[command], strict: false, allowPositionals: true, tokens: true });
80
+ const positionals = [];
81
+ for (const t of tokens) {
82
+ if (t.kind === "positional")
83
+ positionals.push(t.value);
84
+ if (t.kind !== "option")
85
+ continue;
86
+ const type = spec[t.name]?.type;
87
+ if (!type) {
88
+ const known = flagNames(command);
89
+ const elsewhere = COMMANDS.filter((c) => c !== command && flagNames(c).includes(t.rawName));
90
+ throw new UsageError(elsewhere.length
91
+ ? `proofed ${command} has no ${t.rawName}; it belongs to proofed ${elsewhere[0]}.`
92
+ : `Unknown flag ${t.rawName} for proofed ${command}. Did you mean: ${closest(t.rawName, known)}?`);
93
+ }
94
+ if (type === "string" && (t.value === undefined || (t.inlineValue !== true && t.value.startsWith("--")))) {
95
+ throw new UsageError(`${t.rawName} needs a value, e.g. ${t.rawName} ${EXAMPLES[t.name] ?? "<value>"}`);
96
+ }
97
+ if (type === "boolean" && t.inlineValue)
98
+ throw new UsageError(`${t.rawName} takes no value.`);
99
+ }
100
+ const str = (name) => {
101
+ const v = values[name];
102
+ return typeof v === "string" ? v.trim() : undefined;
103
+ };
104
+ const on = (name) => values[name] === true;
105
+ const count = (name) => {
106
+ const raw = str(name);
107
+ if (raw === undefined)
108
+ return undefined;
109
+ const n = Number(raw);
110
+ if (!Number.isInteger(n) || n < 1)
111
+ throw new UsageError(`--${name} takes a whole number of 1 or more, not "${raw}".`);
112
+ return n;
113
+ };
114
+ const onlyRaw = str("only");
115
+ const only = onlyRaw?.split(",").map((s) => s.trim()).filter(Boolean);
116
+ if (onlyRaw !== undefined && !only?.length)
117
+ throw new UsageError("--only needs scenario ids, e.g. --only free-shipping,checkout");
118
+ const flags = {
119
+ json: on("json"),
120
+ help: on("help"),
121
+ scenarios: str("scenarios"),
122
+ out: str("out"),
123
+ url: str("url"),
124
+ serve: str("serve"),
125
+ build: str("build"),
126
+ base: str("base"),
127
+ only,
128
+ all: on("all"),
129
+ dryRun: on("dry-run"),
130
+ noCache: on("no-cache"),
131
+ headed: on("headed"),
132
+ reuse: on("reuse"),
133
+ verbose: on("verbose"),
134
+ concurrency: count("concurrency"),
135
+ serveTimeout: count("serve-timeout"),
136
+ };
137
+ const text = positionals.join(" ").trim() || undefined;
138
+ if (text && command !== "check")
139
+ throw new UsageError(`proofed ${command} takes no text. To have Kane check it: proofed check "${text}"`);
140
+ if (flags.only && flags.all)
141
+ throw new UsageError("Use either --only or --all, not both.");
142
+ if (text && (flags.only || flags.all))
143
+ throw new UsageError(`Text runs on its own; drop ${flags.only ? "--only" : "--all"}: proofed check "${text}"`);
144
+ return { flags, text };
145
+ }
146
+ const EXAMPLES = {
147
+ url: "http://localhost:5173",
148
+ serve: '"npm run dev"',
149
+ build: '"npm run build"',
150
+ base: "origin/main",
151
+ only: "free-shipping,checkout",
152
+ out: ".proofed-out",
153
+ scenarios: ".proofed/scenarios",
154
+ concurrency: "3",
155
+ "serve-timeout": "60",
156
+ };
package/dist/cache.js ADDED
@@ -0,0 +1,48 @@
1
+ // Passes Proofed doesn't pay for twice. A coding agent runs the check again after each fix, and a
2
+ // scenario it didn't touch would cost another 20 to 30 credits to come out the same. A pass stays
3
+ // good while its scenario file, its start URL, the commit the change is measured from and the
4
+ // changed files in its `paths` (every changed file, when it has none) stay as they were. Only
5
+ // passes are kept; everything else runs again.
6
+ import { createHash } from "node:crypto";
7
+ import { readFileSync, writeFileSync } from "node:fs";
8
+ import { matchesGlob } from "node:path";
9
+ export const CACHE_FILE = "cache.json";
10
+ // The demo-store runs reported 27 to 30 credits without accounting for the balance change.
11
+ export const DEFAULT_CREDITS = 30;
12
+ export function readCache(file) {
13
+ try {
14
+ const data = JSON.parse(readFileSync(file, "utf8"));
15
+ if (data.version === 1)
16
+ return { version: 1, passes: data.passes ?? {}, last: data.last ?? {} };
17
+ }
18
+ catch {
19
+ // Missing or unreadable: start over, the worst case is paying for a run again.
20
+ }
21
+ return { version: 1, passes: {}, last: {} };
22
+ }
23
+ export const writeCache = (file, cache) => writeFileSync(file, `${JSON.stringify(cache, null, 2)}\n`);
24
+ export const estimate = (cache, id) => cache.last[id]?.credits ?? DEFAULT_CREDITS;
25
+ // The changed files a scenario depends on.
26
+ export const relevantChanges = (s, changed) => s.paths.length ? changed.filter((f) => s.paths.some((glob) => matchesGlob(f, glob))) : changed;
27
+ const readOrUndefined = (file) => {
28
+ try {
29
+ return readFileSync(file);
30
+ }
31
+ catch {
32
+ return undefined; // Deleted in the change.
33
+ }
34
+ };
35
+ // `base`: the commit the change is measured from (mergeBaseOf).
36
+ export function cacheKey(s, startUrl, changed, read = readOrUndefined, base = "") {
37
+ const hash = createHash("sha256");
38
+ // Length-prefixed, so no two different lists of parts hash the same.
39
+ const add = (part) => hash.update(`${typeof part === "string" ? Buffer.byteLength(part) : part.length}:`).update(part);
40
+ add(read(s.file) ?? s.objective);
41
+ add(startUrl);
42
+ add(base);
43
+ for (const file of relevantChanges(s, changed).toSorted()) {
44
+ add(file);
45
+ add(read(file) ?? "\0deleted");
46
+ }
47
+ return hash.digest("hex");
48
+ }
package/dist/cdp.js ADDED
@@ -0,0 +1,46 @@
1
+ // A minimal Chrome DevTools Protocol client over the browser websocket.
2
+ // Only the events Proofed listens to are typed.
3
+ export async function connectCdp(endpoint) {
4
+ const { webSocketDebuggerUrl } = (await (await fetch(`${endpoint}/json/version`)).json());
5
+ const ws = new WebSocket(webSocketDebuggerUrl);
6
+ await new Promise((resolve, reject) => {
7
+ ws.onopen = () => resolve();
8
+ ws.onerror = () => reject(new Error("Could not connect to Chrome over CDP"));
9
+ });
10
+ let lastId = 0;
11
+ const pending = new Map();
12
+ const listeners = new Map();
13
+ ws.onmessage = (event) => {
14
+ const m = JSON.parse(String(event.data));
15
+ if (m.id !== undefined) {
16
+ const p = pending.get(m.id);
17
+ pending.delete(m.id);
18
+ if (m.error)
19
+ p?.reject(new Error(m.error.message));
20
+ else
21
+ p?.resolve(m.result);
22
+ }
23
+ else if (m.method) {
24
+ for (const fn of listeners.get(m.method) ?? [])
25
+ fn(m.params, m.sessionId);
26
+ }
27
+ };
28
+ ws.onclose = () => {
29
+ for (const p of pending.values())
30
+ p.reject(new Error("CDP connection closed"));
31
+ pending.clear();
32
+ };
33
+ return {
34
+ send(method, params = {}, sessionId) {
35
+ const id = ++lastId;
36
+ ws.send(JSON.stringify({ id, method, params, ...(sessionId && { sessionId }) }));
37
+ return new Promise((resolve, reject) => pending.set(id, { resolve: (v) => resolve(v), reject }));
38
+ },
39
+ on(method, fn) {
40
+ const set = listeners.get(method) ?? new Set();
41
+ set.add(fn);
42
+ listeners.set(method, set);
43
+ },
44
+ close: () => ws.close(),
45
+ };
46
+ }
@@ -0,0 +1,59 @@
1
+ // What the local change is, for `proofed check`: every file that differs between the merge base
2
+ // with the base branch and the working tree (committed, staged or not) plus new files git doesn't
3
+ // ignore. A coding agent's edits are usually uncommitted, so the PR check's base...HEAD isn't enough.
4
+ import { execFileSync } from "node:child_process";
5
+ import { realpathSync } from "node:fs";
6
+ import { join, relative } from "node:path";
7
+ import { SetupError } from "./setuperror.js";
8
+ // A repo with an unignored node_modules lists megabytes of untracked names; the default is 1 MB.
9
+ const git = (cwd, ...args) => execFileSync("git", args, { cwd, encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], maxBuffer: 256 * 1024 * 1024 });
10
+ const tries = (fn) => {
11
+ try {
12
+ return fn().trim();
13
+ }
14
+ catch {
15
+ return undefined;
16
+ }
17
+ };
18
+ export const BASES = ["origin/HEAD", "origin/main", "origin/master", "main", "master"];
19
+ // The remote's default branch as origin/HEAD names it, else the usual names.
20
+ export function findBase(cwd, asked) {
21
+ if (tries(() => git(cwd, "rev-parse", "--is-inside-work-tree")) !== "true") {
22
+ if (asked)
23
+ throw new SetupError("not_a_git_repo", `--base ${asked} needs a git repository, and ${cwd} isn't one.`, "Run proofed in the app's repository, or drop --base.");
24
+ return { why: "not a git repository" };
25
+ }
26
+ if (asked) {
27
+ if (tries(() => git(cwd, "rev-parse", "--verify", "--quiet", `${asked}^{commit}`)))
28
+ return { rev: asked };
29
+ throw new SetupError("base_not_found", `--base ${asked} is not a commit or branch here.`, `Pick an existing one, e.g. --base ${defaultBase(cwd) ?? "main"}, or run git fetch first.`);
30
+ }
31
+ const rev = defaultBase(cwd);
32
+ return rev ? { rev } : { why: `no base branch (tried ${BASES.join(", ")})` };
33
+ }
34
+ function defaultBase(cwd) {
35
+ const head = tries(() => git(cwd, "symbolic-ref", "--quiet", "--short", "refs/remotes/origin/HEAD"));
36
+ if (head)
37
+ return head;
38
+ return BASES.slice(1).find((rev) => tries(() => git(cwd, "rev-parse", "--verify", "--quiet", `${rev}^{commit}`)));
39
+ }
40
+ // Real paths: git reports /private/var/… for a temp folder the shell calls /var/….
41
+ export function repoRoot(cwd) {
42
+ const root = tries(() => git(cwd, "rev-parse", "--show-toplevel"));
43
+ return root ? realpathSync(root) : undefined;
44
+ }
45
+ // The commit the local change is measured from. A cached pass is keyed on it too: after a pull or
46
+ // a rebase the code under a scenario's `paths` can differ without being part of the local change.
47
+ export const mergeBaseOf = (cwd, base) => tries(() => git(cwd, "merge-base", base, "HEAD")) ?? tries(() => git(cwd, "rev-parse", "--verify", "--quiet", `${base}^{commit}`)) ?? base;
48
+ // Paths relative to `cwd`, like the scenarios' `paths` and file names.
49
+ export function localChanges(cwd, base) {
50
+ const root = realpathSync(git(cwd, "rev-parse", "--show-toplevel").trim());
51
+ const here = realpathSync(cwd);
52
+ // -z: without it git quotes and escapes a name such as café.ts, and it matches no path.
53
+ const names = (s) => s.split("\0").filter(Boolean);
54
+ const files = new Set([
55
+ ...names(git(root, "diff", "--name-only", "--no-renames", "-z", mergeBaseOf(cwd, base))),
56
+ ...names(git(root, "ls-files", "--others", "--exclude-standard", "--full-name", "-z")),
57
+ ]);
58
+ return [...files].map((f) => relative(here, join(root, f))).sort();
59
+ }