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
@@ -1,79 +1,34 @@
1
- import { MARKER, OLD_MARKER } from "./github.js";
2
- import { BLANK_PAGE, FAILED_CHECK_ACTION, FAILED_CHECK_REASON, runMarker } from "./runfile.js";
3
- import { describeFixer } from "./models.js";
4
- import { nothingAsked } from "./requests.js";
5
- import { creditsOf, scenarioDoubted, unchecked } from "./run.js";
6
- const DATA_RE = /<!-- proofed:data (.*?) -->/s;
1
+ import { checkedWhere } from "../fix/fixtarget.js";
2
+ import { gitPath } from "../paths.js";
3
+ import { MARKER, OLD_MARKER } from "../github.js";
4
+ import { BLANK_PAGE, FAILED_CHECK_ACTION, FAILED_CHECK_REASON } from "./runfile.js";
5
+ import { DEFAULT_FIXER, describeFixer, providerLabel, providerOf } from "../fix/models.js";
6
+ import { DESCRIPTION_DOUBTED, DESCRIPTION_UNCHECKED, descriptionCheckNote, isDescriptionScenario } from "../action/requests.js";
7
+ import { creditsOf, scenarioDoubted, unchecked } from "./runresult.js";
8
+ import { addRun, collectReportData, COMMENT_LIMIT, compactReportData, dataComment, kaneSteps, MAX_STEPS, oneLine, runMarker, } from "./reportdata.js";
9
+ export { addRun, alreadyReported, dataComment, outcomeOf, postsNew, readReportData, readRunKey, runMarker } from "./reportdata.js";
10
+ // Claude keeps its old label: installed workflows filter edits by this exact text.
7
11
  export const FIX_BOX = "Fix with Claude";
8
- const COMMENT_LIMIT = 65_536;
9
- const HISTORY_SIZE = 8;
10
- const MAX_STEPS = 30;
11
- const MAX_STEP = 200;
12
- export function readReportData(body) {
13
- const raw = DATA_RE.exec(body)?.[1];
14
- if (!raw)
15
- return undefined;
16
- try {
17
- return JSON.parse(raw);
18
- }
19
- catch {
20
- return undefined;
21
- }
22
- }
23
- // A push of the very commit the report is about: the Proofed app pushing Claude's fix, which the fix
24
- // run checked and reported before it ended. Any other push brings a new commit, and a /proofed
25
- // comment always runs, whatever the commit.
26
- export const alreadyReported = (action, headSha, report) => action === "synchronize" && report?.sha === headSha;
27
- export const fixRequested = (body) => body.includes(`- [x] **${FIX_BOX}**`);
12
+ export const fixRequested = (body) => /^- \[x\] \*\*Fix with (?:Claude|Codex)\*\*/m.test(body);
28
13
  export const WORKING = "⏳ **Claude is working on a fix**";
29
- // JSON inside an HTML comment: "--" would end the comment early, so escape it.
30
- export const dataComment = (data) => `<!-- proofed:data ${JSON.stringify(data).replaceAll("--", "\\u002d\\u002d")} -->`;
31
- const STATES = { failed: "failing", error: "blocked", passed: "passing", fixed: "passing", unsure: "passing" };
32
- // Reports from before `open` was kept name only the failures.
33
- export function outcomeOf(data) {
34
- const last = data.history?.at(-1);
35
- const state = last?.sha === data.sha ? STATES[last.state] : data.failures.length > 0 ? "failing" : "passing";
36
- return { state, open: [...(data.open ?? data.failures.map((f) => f.id))].sort() };
37
- }
38
- // GitHub notifies on a new comment, not on an edit. So a report is posted anew when someone should hear
39
- // of it: the first report, a run a person asked for or a fix that ended (`notify`), or an outcome that
40
- // changed. A push that finds the same as the current report only updates it.
41
- export function postsNew(current, next, notify) {
42
- if (notify || current === undefined)
43
- return true;
44
- const was = readReportData(current);
45
- const now = readReportData(next);
46
- if (!was || !now)
47
- return true;
48
- // A fix's report keeps its before and after: the next commit gets its own.
49
- if (was.sha !== now.sha && was.history?.at(-1)?.state === "fixed")
50
- return true;
51
- const [a, b] = [outcomeOf(was), outcomeOf(now)];
52
- return a.state !== b.state || a.open.join("\n") !== b.open.join("\n");
53
- }
54
- const LIVE_LINES = new RegExp(`\\n\\n(?:- \\[[ x]\\] \\*\\*${FIX_BOX}\\*\\*|${WORKING.replaceAll("*", "\\*")})[^\\n]*`, "g");
14
+ export const FIX_BOX_LINE = /^- \[[ x]\] \*\*Fix with (?:Claude|Codex)\*\*[^\n]*/m;
15
+ // The event and current comment may differ by the checkbox tick itself.
16
+ export const sameFixRequest = (current, requested) => {
17
+ const untick = (body) => body.replace(FIX_BOX_LINE, (line) => line.replace("[x]", "[ ]"));
18
+ return current !== undefined && untick(current) === untick(requested);
19
+ };
20
+ const LIVE_LINES = /\n\n(?:- \[[ x]\] \*\*Fix with (?:Claude|Codex)\*\*|⏳ \*\*(?:Claude|Codex) is working on a fix\*\*)[^\n]*/g;
21
+ const OMISSION_NOTE = "_Some report details were omitted to fit GitHub's comment limit._";
22
+ const OMITTED_REQUEST = "Proofed couldn't keep the failed ad hoc request in this report. Run the check again to retry it.";
55
23
  // A report a newer one replaced: without the fix box, so nobody ticks a stale one, or a "working" line
56
24
  // that would never end, and with a marker that nothing reads as the PR's report.
57
25
  export const outdated = (body) => body.replaceAll(MARKER, OLD_MARKER).replace(LIVE_LINES, "");
58
- // A re-run on the same commit replaces its entry. Re-checking a commit Claude pushed keeps it a fix.
59
- export function addRun(history = [], run) {
60
- const last = history.at(-1);
61
- if (last?.sha !== run.sha)
62
- return [...history, run].slice(-HISTORY_SIZE);
63
- const state = last.state === "fixed" && run.state === "passed" ? "fixed" : run.state;
64
- return [...history.slice(0, -1), { sha: run.sha, state }].slice(-HISTORY_SIZE);
65
- }
66
26
  const quote = (text = "") => text
67
27
  .trim()
68
28
  .split("\n")
69
29
  .map((l) => `> ${l}`)
70
30
  .join("\n");
71
31
  const short = (sha) => sha.slice(0, 7);
72
- // Kane's and Claude's words on one line, cut to `max` characters.
73
- const oneLine = (text = "", max = 300) => {
74
- const line = text.replace(/\s+/g, " ").trim();
75
- return line.length > max ? `${line.slice(0, max - 1)}…` : line;
76
- };
77
32
  // Inside <details> and tables GitHub would take "<Cart>" for a tag and drop it.
78
33
  const html = (text) => text.replaceAll("<", "&lt;");
79
34
  const cell = (text) => html(oneLine(text)).replaceAll("|", "\\|");
@@ -83,7 +38,7 @@ function clip(links, width = 720) {
83
38
  if (!links?.gif)
84
39
  return "";
85
40
  const video = links.mp4 ? `\n\n[Watch as video](${links.mp4})` : "";
86
- return `\n\n<img src="${links.gif}" width="${width}" alt="Kane's run in the browser">${video}`;
41
+ return `\n\n<img src="${links.gif}" width="${width}" alt="Kane's run">${video}`;
87
42
  }
88
43
  // Only a still and no recording: the screenshot of a page that crashed on load (precheck.ts).
89
44
  const isScreenshot = (links) => !!links?.jpg && !links.gif && !links.mp4;
@@ -93,28 +48,13 @@ function screenshot(links, url) {
93
48
  return "";
94
49
  return `\n\n<img src="${links.jpg}" width="720" alt="${SCREENSHOT_ALT}">\n\n<sub>This is what a user sees on opening ${code(url)}.</sub>`;
95
50
  }
96
- // The before/after table needs the video and a picture; the GIF only stands in for a missing still.
97
- function storedClip(links) {
98
- if (!links?.mp4 && !links?.jpg && !links?.gif)
99
- return undefined;
100
- return links.jpg ? { mp4: links.mp4, jpg: links.jpg } : { mp4: links.mp4, gif: links.gif };
101
- }
102
51
  function still(links) {
103
52
  const src = links?.jpg ?? links?.gif;
104
53
  if (!src)
105
54
  return "";
106
- const img = `<img src="${src}" width="360" alt="${isScreenshot(links) ? SCREENSHOT_ALT : "Kane's run in the browser"}">`;
55
+ const img = `<img src="${src}" width="360" alt="${isScreenshot(links) ? SCREENSHOT_ALT : "Kane's run"}">`;
107
56
  return links?.mp4 ? `<a href="${links.mp4}">${img}</a>` : img;
108
57
  }
109
- // The last `keep` steps Kane finished, each cut to MAX_STEP characters.
110
- function kaneSteps(steps, keep = MAX_STEPS) {
111
- const done = steps.filter((s) => s.status !== "running" && s.remark);
112
- const from = Math.max(done.length - keep, 0);
113
- return {
114
- from: from + 1,
115
- steps: done.slice(from).map((s) => ({ failed: s.status === "failed", text: oneLine(s.remark, MAX_STEP) })),
116
- };
117
- }
118
58
  function stepList(steps) {
119
59
  const { from, steps: kept } = kaneSteps(steps);
120
60
  if (kept.length === 0)
@@ -129,6 +69,28 @@ function attemptList(fix) {
129
69
  const items = tries.map((t, i) => `${i + 1}. ${html(oneLine([t.summary, t.result].filter(Boolean).join(" ")))}`);
130
70
  return `\n\n<details><summary>${tries.length} attempts</summary>\n\n${items.join("\n")}\n\n</details>`;
131
71
  }
72
+ function gaveUpSummary(fix) {
73
+ return `**Tried ${fix.attempts} times with ${describeFixer(fix)} and couldn't make it pass.** Nothing was pushed.`;
74
+ }
75
+ // Add the attempted fix to the original report without recomputing its check results.
76
+ export function withGaveUpAttempt(body, fix, attemptNote) {
77
+ const summary = gaveUpSummary(fix);
78
+ const passed = attemptNote ? `\n\n${html(attemptNote)}` : "";
79
+ const details = `${summary} Last attempt: ${html(oneLine(fix.summary))}${passed}${attemptList(fix)}`;
80
+ const place = (text) => FIX_BOX_LINE.test(body)
81
+ ? body.replace(FIX_BOX_LINE, () => text)
82
+ : body.replace(/(### Proofed\n\n[^\n]*)/, (_, headline) => `${headline}\n\n${text}`);
83
+ const shortNote = "**The fix failed.** Nothing was pushed.";
84
+ for (const note of [details, summary + passed, summary, shortNote]) {
85
+ const edited = place(note);
86
+ if (edited.length <= COMMENT_LIMIT)
87
+ return edited;
88
+ }
89
+ const shortened = body.replace(OMISSION_NOTE, shortNote).replace(/^- \[x\] (\*\*Fix with (?:Claude|Codex)\*\*)/m, "- [ ] $1");
90
+ if (FIX_BOX_LINE.test(body) || shortened !== body)
91
+ return shortened;
92
+ return body.replace(/(<sub>Run by Kane CLI on [^\n]+)<br>Comment <code>\/proofed<\/code> to check again[^\n]*<\/sub>(?=\n)/, `$1</sub>\n\n${shortNote}`);
93
+ }
132
94
  function whatChanged(fix) {
133
95
  const files = fix.changes ?? [];
134
96
  const listed = files.slice(0, 5).map((f) => `\`${f.file}\` (+${f.added} −${f.removed})`).join(", ");
@@ -137,20 +99,21 @@ function whatChanged(fix) {
137
99
  return text ? `\n\n**What changed:** ${text}` : "";
138
100
  }
139
101
  function writtenSection(written, results, clips) {
102
+ const provider = providerLabel(written.provider ?? "claude");
140
103
  if (written.status === "failed")
141
104
  return "Proofed tried to add scenarios for this app's main flows, but the scenarios couldn't be written this time.";
142
105
  const kept = written.kept.flatMap(({ id, about }) => results.filter((r) => r.scenario.id === id).map((r) => ({ r, about })));
143
106
  const dropped = written.dropped.map((d) => `- **${html(d.name)}**: ${html(oneLine(d.why, 200))}`).join("\n");
144
107
  if (kept.length === 0) {
145
108
  return dropped
146
- ? `Claude wrote ${written.dropped.length === 1 ? "a scenario" : `${written.dropped.length} scenarios`} for this app, but Kane didn't see ${written.dropped.length === 1 ? "it" : "any of them"} pass, so none were added:\n\n${dropped}`
147
- : "Claude didn't find a flow it could write a scenario for without guessing, so none were added.";
109
+ ? `${provider} wrote ${written.dropped.length === 1 ? "a scenario" : `${written.dropped.length} scenarios`} for this app, but Kane didn't see ${written.dropped.length === 1 ? "it" : "any of them"} pass, so none were added:\n\n${dropped}`
110
+ : `${provider} didn't find a flow it could write a scenario for without guessing, so none were added.`;
148
111
  }
149
- const folder = kept[0].r.scenario.file.split("/").slice(0, -1).join("/");
112
+ const folder = gitPath(kept[0].r.scenario.file).split("/").slice(0, -1).join("/");
150
113
  const commit = written.commit ? ` in ${commitRef(written.commit, written.commitUrl)}` : "";
151
- const intro = `**Claude wrote ${kept.length === 1 ? "a scenario" : `${kept.length} scenarios`} for this app**, and Proofed added ${kept.length === 1 ? "it" : "them"} to this PR${commit}. ` +
152
- `Kane ran each one in Chrome and saw it pass. They are plain Markdown in \`${folder}/\`: edit or delete them like any other file.`;
153
- const items = kept.map(({ r, about }) => `**✓ ${r.scenario.name}** · \`${r.scenario.file.split("/").at(-1)}\`<br>${html(oneLine(about, 200))}${clip(clips.get(r.scenario.id), 560)}`);
114
+ const intro = `**${provider} wrote ${kept.length === 1 ? "a scenario" : `${kept.length} scenarios`} for this app**, and Proofed added ${kept.length === 1 ? "it" : "them"} to this PR${commit}. ` +
115
+ `Kane ran each one and saw it pass. They are plain Markdown in \`${folder}/\`: edit or delete them like any other file.`;
116
+ const items = kept.map(({ r, about }) => `**✓ ${r.scenario.name}** · \`${gitPath(r.scenario.file).split("/").at(-1)}\`<br>${html(oneLine(about, 200))}${clip(clips.get(r.scenario.id), 560)}`);
154
117
  const droppedNote = dropped ? `\n\nDropped, since Kane didn't see ${written.dropped.length === 1 ? "it" : "them"} pass:\n\n${dropped}` : "";
155
118
  return `${intro}\n\n${items.join("\n\n")}${droppedNote}`;
156
119
  }
@@ -195,9 +158,13 @@ export function buildReport(input) {
195
158
  }
196
159
  return body;
197
160
  }
198
- function compose({ sha, results: all, skipped, clips, runUrl, fixEnabled, fix, asked, previous, repoUrl, runKey, written }, { stepList: withSteps, storedSteps }) {
199
- const unasked = all.filter(nothingAsked);
200
- const results = all.filter((r) => !nothingAsked(r));
161
+ function compose({ sha, results: all, skipped, clips, runUrl, fixEnabled, fixer = DEFAULT_FIXER, fix, asked, previous, repoUrl, runKey, written, fixSetup }, { stepList: withSteps, storedSteps }) {
162
+ const previousNote = previous?.descriptionNote;
163
+ const carryNote = fix && !all.some((r) => isDescriptionScenario(r.scenario));
164
+ const descriptionNote = all.map(descriptionCheckNote).find((note) => note)
165
+ ?? (carryNote && (previousNote === DESCRIPTION_DOUBTED || previousNote === DESCRIPTION_UNCHECKED) ? previousNote : undefined)
166
+ ?? (carryNote && previous?.failures.some((f) => isDescriptionScenario(f) && f.failedCheck === "scenario_doubted") ? DESCRIPTION_DOUBTED : undefined);
167
+ const results = all.filter((r) => !descriptionCheckNote(r));
201
168
  const failed = results.filter((r) => r.outcome === "failed");
202
169
  const errored = results.filter((r) => r.outcome === "error");
203
170
  const unsure = results.filter((r) => r.outcome === "unsure");
@@ -211,6 +178,7 @@ function compose({ sha, results: all, skipped, clips, runUrl, fixEnabled, fix, a
211
178
  : [];
212
179
  const isRepaired = (r) => repaired.some((x) => x.after === r);
213
180
  const isWritten = (r) => written?.status === "written" && written.kept.some((k) => k.id === r.scenario.id);
181
+ const where = checkedWhere(results.map((r) => r.scenario));
214
182
  const headline = results.length === 0
215
183
  ? "This PR doesn't touch the files of any scenario, so there was nothing to run."
216
184
  : failed.length > 0
@@ -219,26 +187,33 @@ function compose({ sha, results: all, skipped, clips, runUrl, fixEnabled, fix, a
219
187
  ? `Kane couldn't finish ${errored.length} of ${results.length} scenarios. Nothing points at the code yet.`
220
188
  : unsure.length > 0
221
189
  ? passed.length > 0
222
- ? `**${passed.length} of ${results.length}** scenarios pass in a real browser; ${unsure.length} ${unsure.length === 1 ? "wasn't" : "weren't"} checked.`
190
+ ? `**${passed.length} of ${results.length}** scenarios pass ${where}; ${unsure.length} ${unsure.length === 1 ? "wasn't" : "weren't"} checked.`
223
191
  : results.length === 1
224
192
  ? "The affected scenario wasn't checked."
225
193
  : `None of the ${results.length} affected scenarios were checked.`
226
194
  : results.length === 1
227
- ? "The affected scenario passes in a real browser."
228
- : `All ${results.length} affected scenarios pass in a real browser.`;
195
+ ? `The affected scenario passes ${where}.`
196
+ : `All ${results.length} affected scenarios pass ${where}.`;
229
197
  const sections = [`${MARKER}\n### Proofed\n\n${headline}`];
198
+ const recordingNote = all.find((r) => r.scenario.resolvedTarget?.execution === "cloud" && r.recordingNote)?.recordingNote;
199
+ if (recordingNote) {
200
+ sections.push(`<sub>${html(oneLine(recordingNote.replace(" is at kaneReport.", " is available in TestMu.")))}</sub>`);
201
+ }
202
+ const summary = [...sections];
230
203
  if (results.length >= 4) {
231
204
  const tag = (r) => r.outcome === "error"
232
205
  ? ": couldn't finish"
233
206
  : unchecked(r)
234
207
  ? ": not checked"
235
208
  : r.outcome === "unsure"
236
- ? ": the test may be wrong"
209
+ ? ": not checked"
237
210
  : isRepaired(r)
238
211
  ? ": fixed"
239
212
  : "";
240
213
  const mark = (r) => (r.outcome === "failed" ? "✗" : r.outcome === "passed" ? "✓" : "⚠");
241
- sections.push([...failed, ...errored, ...unsure, ...passed].map((r) => `- ${mark(r)} ${r.scenario.name}${tag(r)}`).join("\n"));
214
+ const list = [...failed, ...errored, ...unsure, ...passed].map((r) => `- ${mark(r)} ${r.scenario.name}${tag(r)}`).join("\n");
215
+ sections.push(list);
216
+ summary.push(list);
242
217
  }
243
218
  if (written)
244
219
  sections.push(writtenSection(written, passed, clips));
@@ -247,7 +222,7 @@ function compose({ sha, results: all, skipped, clips, runUrl, fixEnabled, fix, a
247
222
  sections.push(`**Fixed${commit}** by ${describeFixer(fix)}, after ${fix.attempts} attempt${fix.attempts > 1 ? "s" : ""}.${whatChanged(fix)}${attemptList(fix)}`);
248
223
  }
249
224
  else if (fix?.status === "gave-up") {
250
- sections.push(`**Tried ${fix.attempts} times with ${describeFixer(fix)} and couldn't make it pass.** Nothing was pushed. Last attempt: ${fix.summary}` +
225
+ sections.push(`${gaveUpSummary(fix)} Last attempt: ${fix.summary}` +
251
226
  attemptList(fix));
252
227
  }
253
228
  if (fix && previous) {
@@ -270,18 +245,21 @@ function compose({ sha, results: all, skipped, clips, runUrl, fixEnabled, fix, a
270
245
  (withSteps ? stepList(r.steps) : "") +
271
246
  (r.end?.test_url ? `\n\n[Kane's step-by-step report](${r.end.test_url})` : ""));
272
247
  }
248
+ const provider = providerLabel(providerOf(fixer.model));
273
249
  if (failed.length > 0 && fixEnabled && fix?.status !== "gave-up") {
274
- sections.push(`- [ ] **${FIX_BOX}** — Claude Code gets the failure, the steps and the diff, pushes a fix to this branch, and Proofed checks again.`);
250
+ sections.push(fixSetup
251
+ ? `> ${fixSetup.note}`
252
+ : `- [ ] **Fix with ${provider}**: ${provider} gets the failure, the steps and the diff, Kane checks the rebuild, and only a verified fix is pushed to this branch.`);
275
253
  }
276
254
  for (const r of errored) {
277
- sections.push(`#### ⚠ ${r.scenario.name}: Kane couldn't finish, even after a retry\n\n${quote(r.error)}` +
255
+ sections.push(`#### ⚠ ${r.scenario.name}: Kane couldn't finish\n\n${quote(r.error)}` +
278
256
  clip(clips.get(r.scenario.id), 560) +
279
257
  `\n\nThis is about the test run, not your code. Re-run the check to try again.`);
280
258
  }
281
259
  for (const r of unsure) {
282
260
  sections.push((unchecked(r)
283
261
  ? `#### ⚠ ${r.scenario.name}: not checked\n\n${quote(r.end?.reason)}\n\nKane called it a pass, but none of its steps checked the page, so this says nothing about the code either way.`
284
- : `#### ⚠ ${r.scenario.name}: the test may be wrong, not the code\n\n${quote(r.end?.reason)}` +
262
+ : `#### ⚠ ${r.scenario.name}: not checked\n\n${quote(r.end?.reason ?? r.error)}` +
285
263
  (r.end?.verdict?.suggestion ? `\n\n**Kane suggests:** ${r.end.verdict.suggestion}` : "")) +
286
264
  clip(clips.get(r.scenario.id), 560));
287
265
  }
@@ -292,37 +270,39 @@ function compose({ sha, results: all, skipped, clips, runUrl, fixEnabled, fix, a
292
270
  }
293
271
  if (skipped.length > 0)
294
272
  sections.push(`<sub>Not affected by this diff: ${skipped.join(", ")}</sub>`);
295
- if (unasked.length > 0)
296
- sections.push("<sub>The PR description didn't name anything Kane could check in the browser.</sub>");
273
+ if (descriptionNote)
274
+ sections.push(`<sub>${descriptionNote}</sub>`);
297
275
  const state = failed.length > 0 ? "failed" : errored.length > 0 ? "error" : fix?.status === "fixed" ? "fixed" : unsure.length > 0 ? "unsure" : "passed";
298
276
  const history = addRun(previous?.history, { sha, state });
299
277
  const open = [...failed, ...errored, ...unsure].map((r) => r.scenario.id);
300
- // Not kept for the fixer: its final check would only spend credits finding nothing to check again.
301
- const rerun = asked?.filter((s) => !unasked.some((r) => r.scenario.id === s.id));
302
- const data = {
303
- sha,
304
- ...(rerun?.length && { asked: rerun }),
305
- failures: failed.map((r) => ({
306
- id: r.scenario.id,
307
- name: r.scenario.name,
308
- file: r.scenario.file,
309
- objective: r.scenario.objective,
310
- reason: r.end?.reason ?? "",
311
- diagnosis: r.end?.verdict?.root_cause ?? r.end?.summary ?? "",
312
- ...(scenarioDoubted(r) && { failedCheck: "scenario_doubted" }),
313
- steps: kaneSteps(r.steps, storedSteps).steps.map((s) => `${s.failed ? "✗" : "·"} ${s.text}`),
314
- clip: storedClip(clips.get(r.scenario.id)),
315
- })),
316
- history,
317
- ...(open.length && { open }),
318
- };
319
- const footer = [`Run by Kane CLI on ${short(sha)}`, credits > 0 && `${Math.round(credits)} credits`, runUrl && `[logs](${runUrl})`]
278
+ const data = collectReportData({ sha, failed, open, asked, descriptionNote, clips, storedSteps, history });
279
+ const footer = [`Run by Kane CLI on ${short(sha)}`, credits > 0 && `${Math.round(credits)} credits (Kane estimate)`, runUrl && `[logs](${runUrl})`]
320
280
  .filter(Boolean)
321
281
  .join(" · ");
322
- const canFix = failed.length > 0 && fixEnabled;
282
+ const canFix = failed.length > 0 && fixEnabled && (!fixSetup || fixSetup.comment);
323
283
  const hint = canFix
324
- ? "Comment <code>/proofed</code> to check again or <code>/proofed fix</code> to have Claude fix it."
284
+ ? `Comment <code>/proofed</code> to check again or <code>/proofed fix</code> to have ${provider} fix it.`
325
285
  : "Comment <code>/proofed</code> to check again.";
326
286
  const lines = [footer, history.length > 1 && historyLine(history, repoUrl), hint].filter(Boolean).join("<br>");
327
- return `${sections.join("\n\n")}\n\n<sub>${lines}</sub>\n${dataComment(data)}${runKey ? `\n${runMarker(runKey)}` : ""}`;
287
+ const marker = runKey ? `\n${runMarker(runKey)}` : "";
288
+ const body = `${sections.join("\n\n")}\n\n<sub>${lines}</sub>\n${dataComment(data)}${marker}`;
289
+ if (storedSteps > 0 || body.length <= COMMENT_LIMIT)
290
+ return body;
291
+ for (const compact of compactReportData(data)) {
292
+ const hasRequest = (id) => compact.asked?.some((s) => s.id === id);
293
+ const notes = [OMISSION_NOTE];
294
+ if (data.failures.some((f) => !f.file && !hasRequest(f.id)))
295
+ notes.push(OMITTED_REQUEST);
296
+ if (canFix && compact.failures.some((f) => f.file || hasRequest(f.id))) {
297
+ notes.push("Comment `/proofed fix` to fix the scenarios kept in this report.");
298
+ }
299
+ const tail = `\n\n${notes.join("\n\n")}\n${dataComment(compact)}${marker}`;
300
+ const remaining = COMMENT_LIMIT - tail.length;
301
+ if (remaining >= summary[0].length) {
302
+ const visible = summary.join("\n\n");
303
+ const cut = visible.length <= remaining ? visible.length : visible.lastIndexOf("\n", remaining);
304
+ return visible.slice(0, Math.max(cut, summary[0].length)).trimEnd() + tail;
305
+ }
306
+ }
307
+ return [summary[0], OMISSION_NOTE, ...(data.failures.some((f) => !f.file) ? [OMITTED_REQUEST] : [])].join("\n\n");
328
308
  }
@@ -0,0 +1,120 @@
1
+ import { checkedAt } from "../fix/fixtarget.js";
2
+ import { isDescriptionScenario } from "../action/requests.js";
3
+ import { scenarioDoubted } from "./runresult.js";
4
+ export { readRunKey, runMarker } from "./runfile.js";
5
+ const DATA_RE = /<!-- proofed:data (.*?) -->/s;
6
+ export const COMMENT_LIMIT = 65_536;
7
+ const HISTORY_SIZE = 8;
8
+ export const MAX_STEPS = 30;
9
+ const MAX_STEP = 200;
10
+ export function readReportData(body) {
11
+ const raw = DATA_RE.exec(body)?.[1];
12
+ if (!raw)
13
+ return undefined;
14
+ try {
15
+ return JSON.parse(raw);
16
+ }
17
+ catch {
18
+ return undefined;
19
+ }
20
+ }
21
+ // A push of the very commit the report is about: the Proofed app pushing the fixer's fix, which the fix
22
+ // run checked and reported before it ended. Any other push brings a new commit, and a /proofed
23
+ // comment always runs, whatever the commit.
24
+ export const alreadyReported = (action, headSha, report) => action === "synchronize" && report?.sha === headSha;
25
+ // JSON inside an HTML comment: "--" would end the comment early, so escape it.
26
+ export const dataComment = (data) => `<!-- proofed:data ${JSON.stringify(data).replaceAll("--", "\\u002d\\u002d")} -->`;
27
+ const STATES = { failed: "failing", error: "blocked", passed: "passing", fixed: "passing", unsure: "passing" };
28
+ // Reports from before `open` was kept name only the failures.
29
+ export function outcomeOf(data) {
30
+ const last = data.history?.at(-1);
31
+ const state = last?.sha === data.sha ? STATES[last.state] : data.failures.length > 0 ? "failing" : "passing";
32
+ return { state, open: [...(data.open ?? data.failures.map((f) => f.id))].sort() };
33
+ }
34
+ // GitHub notifies on a new comment, not on an edit. So a report is posted anew when someone should hear
35
+ // of it: the first report, a run a person asked for or a fix that ended (`notify`), or an outcome that
36
+ // changed. A push that finds the same as the current report only updates it.
37
+ export function postsNew(current, next, notify) {
38
+ if (notify || current === undefined)
39
+ return true;
40
+ const was = readReportData(current);
41
+ const now = readReportData(next);
42
+ if (!was || !now)
43
+ return true;
44
+ // A fix's report keeps its before and after: the next commit gets its own.
45
+ if (was.sha !== now.sha && was.history?.at(-1)?.state === "fixed")
46
+ return true;
47
+ const [a, b] = [outcomeOf(was), outcomeOf(now)];
48
+ return a.state !== b.state || a.open.join("\n") !== b.open.join("\n");
49
+ }
50
+ // A re-run on the same commit replaces its entry. Re-checking a commit Claude pushed keeps it a fix.
51
+ export function addRun(history = [], run) {
52
+ const last = history.at(-1);
53
+ if (last?.sha !== run.sha)
54
+ return [...history, run].slice(-HISTORY_SIZE);
55
+ const state = last.state === "fixed" && run.state === "passed" ? "fixed" : run.state;
56
+ return [...history.slice(0, -1), { sha: run.sha, state }].slice(-HISTORY_SIZE);
57
+ }
58
+ // Kane's and the fixer's words on one line, cut to `max` characters.
59
+ export const oneLine = (text = "", max = 300) => {
60
+ const line = text.replace(/\s+/g, " ").trim();
61
+ return line.length > max ? `${line.slice(0, max - 1)}…` : line;
62
+ };
63
+ // The before/after table needs the video and a picture; the GIF only stands in for a missing still.
64
+ function storedClip(links) {
65
+ if (!links?.mp4 && !links?.jpg && !links?.gif)
66
+ return undefined;
67
+ return links.jpg ? { mp4: links.mp4, jpg: links.jpg } : { mp4: links.mp4, gif: links.gif };
68
+ }
69
+ // The last `keep` steps Kane finished, each cut to MAX_STEP characters.
70
+ export function kaneSteps(steps, keep = MAX_STEPS) {
71
+ const done = steps.filter((s) => s.status !== "running" && s.remark);
72
+ const from = Math.max(done.length - keep, 0);
73
+ return {
74
+ from: from + 1,
75
+ steps: done.slice(from).map((s) => ({ failed: s.status === "failed", text: oneLine(s.remark, MAX_STEP) })),
76
+ };
77
+ }
78
+ export function collectReportData({ sha, failed, open, asked, descriptionNote, clips, storedSteps, history, }) {
79
+ const rerun = asked?.filter((s) => !descriptionNote || !isDescriptionScenario(s));
80
+ return {
81
+ sha,
82
+ ...(rerun?.length && { asked: rerun }),
83
+ ...(descriptionNote && { descriptionNote }),
84
+ failures: failed.map((r) => ({
85
+ id: r.scenario.id,
86
+ name: r.scenario.name,
87
+ file: r.scenario.file,
88
+ objective: r.scenario.objective,
89
+ checkedAt: checkedAt(r.scenario),
90
+ reason: r.end?.reason ?? "",
91
+ diagnosis: r.end?.verdict?.root_cause ?? r.end?.summary ?? "",
92
+ ...(scenarioDoubted(r) && { failedCheck: "scenario_doubted" }),
93
+ steps: kaneSteps(r.steps, storedSteps).steps.map((s) => `${s.failed ? "✗" : "·"} ${s.text}`),
94
+ clip: storedClip(clips.get(r.scenario.id)),
95
+ })),
96
+ history,
97
+ ...(open.length && { open }),
98
+ };
99
+ }
100
+ // Try these in order to keep as much metadata as the comment limit allows.
101
+ export function compactReportData(data) {
102
+ const { asked: requests, failures, ...outcome } = data;
103
+ // File objectives can be re-read. Keep the ad hoc objectives once, in the replay data.
104
+ const asked = requests?.filter((s) => failures.some((f) => !f.file && f.id === s.id && f.objective === s.objective)) ?? [];
105
+ const replay = asked.length ? { asked } : {};
106
+ const compact = failures.map((f) => ({ ...f, objective: "", steps: [] }));
107
+ const bare = compact.map(({ id, name, file, failedCheck }) => ({
108
+ id, name, file, failedCheck, objective: "", steps: [], reason: "", diagnosis: "",
109
+ }));
110
+ const { open: _open, ...historyOnly } = outcome;
111
+ // Keep valid metadata for the whole report even when the failure records won't fit.
112
+ return [
113
+ { ...outcome, ...replay, failures: compact },
114
+ { ...outcome, ...replay, failures: bare.filter((f) => f.file || asked.some((s) => s.id === f.id)) },
115
+ { ...outcome, failures: bare.filter((f) => f.file) },
116
+ ...(asked.length ? [{ ...historyOnly, asked, failures: bare.filter((f) => !f.file && asked.some((s) => s.id === f.id)) }] : []),
117
+ { ...outcome, failures: [] },
118
+ { ...historyOnly, failures: [] },
119
+ ];
120
+ }
@@ -1,11 +1,12 @@
1
1
  // The result of `proofed check` as one JSON document: what `--json` prints, what <out>/result.json
2
2
  // holds, and what the terminal views draw from. Its names are the CLI's contract with coding agents.
3
3
  import { resolve } from "node:path";
4
- import { creditsOf, scenarioDoubted, unchecked } from "./run.js";
4
+ import { creditsOf, scenarioDoubted, unchecked } from "./runresult.js";
5
5
  import { FAILED_CHECK_ACTION } from "./runfile.js";
6
6
  export const outcomeOf = (r) => (r.outcome === "unsure" ? "not_checked" : r.outcome);
7
- // Shell-safe as typed.
8
- export const quote = (s) => (/^[\w@%+=:,./-]+$/.test(s) ? s : `'${s.replace(/'/g, `'\\''`)}'`);
7
+ // Commands shown to Windows developers target PowerShell, the default terminal.
8
+ export const quote = (s, platform = process.platform) => /^[\w@%+=:,./-]+$/.test(s) ? s
9
+ : platform === "win32" ? `'${s.replaceAll("'", "''")}'` : `'${s.replace(/'/g, `'\\''`)}'`;
9
10
  // The same check again, as it was asked for.
10
11
  export const sameCommand = (ctx, selection = ctx.selection) => ["proofed check", ...(ctx.text !== undefined ? [quote(ctx.text)] : selection ? [selection] : []), ...ctx.flags].join(" ");
11
12
  export function rerunCommand(ids, ctx) {
@@ -16,7 +17,7 @@ const round = (n) => Math.round(n * 100) / 100;
16
17
  const names = (docs) => docs.map((d) => d.name).join(", ");
17
18
  export function scenarioDoc(item, ctx) {
18
19
  const { scenario: s } = item;
19
- const head = { id: s.id, name: s.name, ...(s.file && { file: s.file }) };
20
+ const head = { ...(s.resolvedTarget && { target: s.resolvedTarget }), id: s.id, name: s.name, ...(s.file && { file: s.file }) };
20
21
  const rerun = rerunCommand([s.id], ctx);
21
22
  if ("estimate" in item) {
22
23
  return { ...head, outcome: "would_run", cached: false, objective: s.objective, steps: [], credits: 0, estimatedCredits: item.estimate, rerun };
@@ -43,11 +44,13 @@ export function scenarioDoc(item, ctx) {
43
44
  const reason = outcome === "passed" ? r.end?.summary || r.end?.reason : r.end?.reason || r.error;
44
45
  return {
45
46
  ...head,
47
+ ...(r.recordingNote && { recordingNote: r.recordingNote }),
48
+ ...(r.end?.test_url && { kaneReport: r.end.test_url }),
46
49
  outcome,
47
50
  cached: false,
48
51
  objective: s.objective,
49
52
  ...(reason && { reason }),
50
- ...(outcome === "not_checked" && { notChecked: unchecked(r) ? "nothing_asserted" : "scenario_doubted" }),
53
+ ...(outcome === "not_checked" && { notChecked: r.notChecked ?? (unchecked(r) ? "nothing_asserted" : "scenario_doubted") }),
51
54
  ...(outcome !== "passed" && verdict?.root_cause && { diagnosis: verdict.root_cause }),
52
55
  ...(scenarioDoubted(r) && { failedCheck: "scenario_doubted" }),
53
56
  ...(scenarioDoubted(r) ? { suggestion: FAILED_CHECK_ACTION } : outcome !== "passed" && verdict?.suggestion && { suggestion: verdict.suggestion }),
@@ -59,6 +62,8 @@ export function scenarioDoc(item, ctx) {
59
62
  ...(r.pageError && { pageError: r.pageError }),
60
63
  ...(r.clip && { clip: { ...(r.clip.mp4 && { mp4: resolve(r.clip.mp4) }), jpg: resolve(r.clip.jpg) } }),
61
64
  credits: round(creditsOf(r)),
65
+ creditsSource: "kane_estimate",
66
+ ...(r.accountBalance && { accountBalance: r.accountBalance }),
62
67
  ...(r.seconds !== undefined && { seconds: r.seconds }),
63
68
  rerun,
64
69
  };
@@ -78,7 +83,7 @@ export function buildDoc(input) {
78
83
  const broken = scenarios.filter((d) => d.outcome !== "passed" && d.outcome !== "would_run");
79
84
  const rerun = rerunCommand(broken.map((d) => d.id), input.rerun);
80
85
  const cached = scenarios.filter((d) => d.cached).length;
81
- const estimatedCredits = round(input.estimatedCredits);
86
+ const estimatedCredits = input.estimatedCredits === null ? null : round(input.estimatedCredits);
82
87
  let summary;
83
88
  let next;
84
89
  if (input.idle) {
@@ -86,7 +91,7 @@ export function buildDoc(input) {
86
91
  }
87
92
  else if (input.dryRun) {
88
93
  const would = of("would_run").length;
89
- summary = `Would run ${would} scenario(s) for about ${estimatedCredits} credits${cached ? `; ${cached} cached pass(es) cost nothing` : ""}`;
94
+ summary = `Would run ${would} scenario(s) ${estimatedCredits === null ? "at a cost Kane reports only after a first run" : `for about ${estimatedCredits} credits`}${cached ? `; ${cached} cached pass(es) cost nothing` : ""}`;
90
95
  next = would ? `Run it for real: ${sameCommand(input.rerun)}` : "Nothing would run.";
91
96
  }
92
97
  else if (counts.failed > 0) {
@@ -1,11 +1,11 @@
1
1
  // The reason of a scenario Kane called passed without asserting anything; the dashboard words such a
2
2
  // scenario as "not checked" by it.
3
3
  export const NOTHING_CHECKED = "Kane finished without checking anything on the page.";
4
- // The reason of a scenario whose start page crashed on load, so Kane never ran (src/precheck.ts).
4
+ // The reason of a scenario whose start page crashed on load, so Kane never ran (src/targets/precheck.ts).
5
5
  export const BLANK_PAGE = "The page is blank: it crashed while loading, before anything could be checked.";
6
6
  export const RUN_FILE = "run.json";
7
7
  export const runMarker = (key) => `<!-- proofed:run ${key} -->`;
8
8
  export const readRunKey = (body) => /<!-- proofed:run (pr-\d+\/[\w.-]+) -->/.exec(body)?.[1];
9
9
  // A refuted check stays a failure even when Kane blames the scenario. Consumers share the next step.
10
- export const FAILED_CHECK_REASON = "The scenario's check did not hold on the page, on two runs in a row. Kane believes the scenario is out of date.";
10
+ export const FAILED_CHECK_REASON = "The scenario's check did not hold on the page. Kane believes the scenario is out of date.";
11
11
  export const FAILED_CHECK_ACTION = "If the change in the app was intended, update the scenario; otherwise fix the app.";
@@ -0,0 +1,5 @@
1
+ // An unsure run where Kane said "passed": nothing was checked, as opposed to Kane doubting the test.
2
+ export const unchecked = (r) => r.outcome === "unsure" && r.end?.status === "passed" && !r.notChecked;
3
+ export const scenarioDoubted = (r) => r.outcome === "failed" && r.end?.verdict?.family === "automation_bug";
4
+ // All the credits a scenario took, the runs before the last one included.
5
+ export const creditsOf = (r) => (r.end?.credits_consumed ?? 0) + (r.earlierCredits ?? 0);