@webpieces/pr-gate 0.4.826 → 0.4.828

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 (49) hide show
  1. package/package.json +3 -3
  2. package/src/dashboard/checklist-comment-renderer.js +8 -6
  3. package/src/dashboard/checklist-comment-renderer.js.map +1 -1
  4. package/src/dashboard/checklist-comment-row.d.ts +6 -0
  5. package/src/dashboard/checklist-comment-row.js +6 -0
  6. package/src/dashboard/checklist-comment-row.js.map +1 -1
  7. package/src/dashboard/dashboard.d.ts +11 -0
  8. package/src/dashboard/dashboard.js +24 -6
  9. package/src/dashboard/dashboard.js.map +1 -1
  10. package/src/scripts/commands/await-reviews-command.d.ts +3 -3
  11. package/src/scripts/commands/await-reviews-command.js +24 -20
  12. package/src/scripts/commands/await-reviews-command.js.map +1 -1
  13. package/src/scripts/commands/finish-upsert-pr-command.js +27 -31
  14. package/src/scripts/commands/finish-upsert-pr-command.js.map +1 -1
  15. package/src/scripts/commands/review-upsert-pr-command.d.ts +3 -8
  16. package/src/scripts/commands/review-upsert-pr-command.js +15 -17
  17. package/src/scripts/commands/review-upsert-pr-command.js.map +1 -1
  18. package/src/scripts/commands/write-review-command.d.ts +29 -15
  19. package/src/scripts/commands/write-review-command.js +62 -29
  20. package/src/scripts/commands/write-review-command.js.map +1 -1
  21. package/src/scripts/commands/write-review-fixes-command.d.ts +5 -1
  22. package/src/scripts/commands/write-review-fixes-command.js +6 -5
  23. package/src/scripts/commands/write-review-fixes-command.js.map +1 -1
  24. package/src/scripts/workflow/checklist-scanner.d.ts +47 -22
  25. package/src/scripts/workflow/checklist-scanner.js +77 -34
  26. package/src/scripts/workflow/checklist-scanner.js.map +1 -1
  27. package/src/scripts/workflow/provenance-enforcer.d.ts +2 -2
  28. package/src/scripts/workflow/provenance-enforcer.js +5 -5
  29. package/src/scripts/workflow/provenance-enforcer.js.map +1 -1
  30. package/src/scripts/workflow/review-report.d.ts +26 -8
  31. package/src/scripts/workflow/review-report.js +61 -39
  32. package/src/scripts/workflow/review-report.js.map +1 -1
  33. package/src/scripts/workflow/review-round-state.d.ts +87 -22
  34. package/src/scripts/workflow/review-round-state.js +252 -104
  35. package/src/scripts/workflow/review-round-state.js.map +1 -1
  36. package/src/scripts/workflow/review-round-text.d.ts +37 -0
  37. package/src/scripts/workflow/review-round-text.js +87 -0
  38. package/src/scripts/workflow/review-round-text.js.map +1 -0
  39. package/src/scripts/workflow/review-stage-receipt.d.ts +7 -19
  40. package/src/scripts/workflow/review-stage-receipt.js +7 -31
  41. package/src/scripts/workflow/review-stage-receipt.js.map +1 -1
  42. package/src/scripts/workflow/reviewer-briefing-builder.js +0 -1
  43. package/src/scripts/workflow/reviewer-briefing-builder.js.map +1 -1
  44. package/src/scripts/workflow/reviewer-verdict-gate.d.ts +14 -26
  45. package/src/scripts/workflow/reviewer-verdict-gate.js +38 -51
  46. package/src/scripts/workflow/reviewer-verdict-gate.js.map +1 -1
  47. package/src/scripts/workflow/verdict-provenance.d.ts +10 -10
  48. package/src/scripts/workflow/verdict-provenance.js +25 -23
  49. package/src/scripts/workflow/verdict-provenance.js.map +1 -1
@@ -4,10 +4,10 @@ import { ChecklistScan } from './checklist-scanner';
4
4
  * The gate `wp-finish-upsert-pr` runs before it parses summary.json: REFUSE the PR while any applicable
5
5
  * checklist is not clear, and say — per checklist — which of three different things went wrong.
6
6
  *
7
- * It is its own class, not a private method on the command, for two reasons. It is the one piece of finish
8
- * that both MUTATES the branch (it retires red verdicts) and produces the text an AI acts on, so it is the
9
- * piece most worth asserting on directly; and the command it came out of is already the largest file in this
10
- * package, against a hard `@webpieces/max-file-lines` limit.
7
+ * It is its own class, not a private method on the command, for two reasons. It produces the text an AI acts
8
+ * on, so it is the piece most worth asserting on directly; and the command it came out of is already the
9
+ * largest file in this package, against a hard `@webpieces/max-file-lines` limit. It never moves or deletes
10
+ * a verdict: every round's verdict is its own file and stays on disk (issue #1053).
11
11
  *
12
12
  * THE BUG THIS EXISTS TO FIX. The message used to be one bucket and one imperative — "You MUST run these N
13
13
  * reviewer subagent(s)" — for three unrelated states. Handed to an agent, the literal, obedient response for
@@ -16,8 +16,9 @@ import { ChecklistScan } from './checklist-scanner';
16
16
  * never printed at all. Three states, three actions, in this order:
17
17
  *
18
18
  * 1. UNREADABLE (`scan.formatErrors`) -> fix four characters of JSON. Not a reviewer problem.
19
- * 2. REFUSED (CK_FAIL) -> fix the finding (or get a HUMAN override). Not a missing step.
20
- * 3. NEVER RAN (the rest) -> spawn the subagent. The ONLY case where that is the right move.
19
+ * 2. ORANGE (CK_ORANGE) -> the final round's must-fix: fix it, record the fix. Never a reviewer.
20
+ * 3. REFUSED (CK_FAIL) -> fix the finding (or get a HUMAN override). Not a missing step.
21
+ * 4. NEVER RAN (the rest) -> spawn the subagent. The ONLY case where that is the right move.
21
22
  *
22
23
  * `@injectable(bindingScopeValues.Singleton)` so it is injected by type and drawn in the DI design.
23
24
  */
@@ -28,10 +29,6 @@ export declare class ReviewerVerdictGate {
28
29
  /**
29
30
  * Refuse the PR while ANY applicable checklist still owes a passing verdict — naming exactly what each
30
31
  * one needs. No-op for a repo with no applicable checklists.
31
- *
32
- * SIDE EFFECT, deliberately: every REFUSED checklist's verdict file is RETIRED to review-<id>.json.old on
33
- * the way out (see {@link retireAndReport}). Only red verdicts are ever moved — a green, yellow or
34
- * overridden one is reused across finish attempts and retiring it would force a needless subagent re-run.
35
32
  */
36
33
  assertEveryReviewerRan(scan: ChecklistScan): void;
37
34
  /**
@@ -53,7 +50,13 @@ export declare class ReviewerVerdictGate {
53
50
  private skippedNote;
54
51
  private unreadableSection;
55
52
  /**
56
- * The refusals — SECOND, above anything that says to spawn a subagent, because a spawn instruction is the
53
+ * The ORANGES (issue #1053) — above the refusals and everything that says to spawn, because the one move
54
+ * an orange must never get is a reviewer: the round cap is spent. Fixed code plus a recorded fix is the
55
+ * only way past it, and after that finish proceeds and stamps the orange with its resolution.
56
+ */
57
+ private orangeSection;
58
+ /**
59
+ * The refusals — above anything that says to spawn a subagent, because a spawn instruction is the
57
60
  * one line an agent acts on first, and acting on it here IS the loop.
58
61
  */
59
62
  private refusedSection;
@@ -71,20 +74,5 @@ export declare class ReviewerVerdictGate {
71
74
  * imperative must not appear at all on a run whose only problem is a refusal.
72
75
  */
73
76
  private neverRanSection;
74
- /**
75
- * Retire ONE refused checklist's verdict and render the refusal that reports it.
76
- *
77
- * ORDER IS LOAD-BEARING. The verdict is resolved from the already-loaded results, so the finding is in
78
- * hand before the file moves; the move then happens; and only then is the message rendered, because it
79
- * names the archive path and must not claim a move that did not happen.
80
- *
81
- * The move is NON-FATAL. A finish that died after retiring a verdict would leave the AI with a red
82
- * verdict gone from the live path and no message saying where it went or why the PR was refused — a
83
- * silent gap, and the worst possible outcome for a feature whose entire purpose is a durable record. So a
84
- * failed move warns and the refusal is reported without an archive path (the file is then still live,
85
- * which the un-archived wording of `refusalError` describes correctly).
86
- */
87
- private retireAndReport;
88
- private archiveOrWarn;
89
77
  private footer;
90
78
  }
@@ -9,10 +9,10 @@ const verdict_provenance_1 = require("./verdict-provenance");
9
9
  * The gate `wp-finish-upsert-pr` runs before it parses summary.json: REFUSE the PR while any applicable
10
10
  * checklist is not clear, and say — per checklist — which of three different things went wrong.
11
11
  *
12
- * It is its own class, not a private method on the command, for two reasons. It is the one piece of finish
13
- * that both MUTATES the branch (it retires red verdicts) and produces the text an AI acts on, so it is the
14
- * piece most worth asserting on directly; and the command it came out of is already the largest file in this
15
- * package, against a hard `@webpieces/max-file-lines` limit.
12
+ * It is its own class, not a private method on the command, for two reasons. It produces the text an AI acts
13
+ * on, so it is the piece most worth asserting on directly; and the command it came out of is already the
14
+ * largest file in this package, against a hard `@webpieces/max-file-lines` limit. It never moves or deletes
15
+ * a verdict: every round's verdict is its own file and stays on disk (issue #1053).
16
16
  *
17
17
  * THE BUG THIS EXISTS TO FIX. The message used to be one bucket and one imperative — "You MUST run these N
18
18
  * reviewer subagent(s)" — for three unrelated states. Handed to an agent, the literal, obedient response for
@@ -21,8 +21,9 @@ const verdict_provenance_1 = require("./verdict-provenance");
21
21
  * never printed at all. Three states, three actions, in this order:
22
22
  *
23
23
  * 1. UNREADABLE (`scan.formatErrors`) -> fix four characters of JSON. Not a reviewer problem.
24
- * 2. REFUSED (CK_FAIL) -> fix the finding (or get a HUMAN override). Not a missing step.
25
- * 3. NEVER RAN (the rest) -> spawn the subagent. The ONLY case where that is the right move.
24
+ * 2. ORANGE (CK_ORANGE) -> the final round's must-fix: fix it, record the fix. Never a reviewer.
25
+ * 3. REFUSED (CK_FAIL) -> fix the finding (or get a HUMAN override). Not a missing step.
26
+ * 4. NEVER RAN (the rest) -> spawn the subagent. The ONLY case where that is the right move.
26
27
  *
27
28
  * `@injectable(bindingScopeValues.Singleton)` so it is injected by type and drawn in the DI design.
28
29
  */
@@ -36,10 +37,6 @@ let ReviewerVerdictGate = class ReviewerVerdictGate {
36
37
  /**
37
38
  * Refuse the PR while ANY applicable checklist still owes a passing verdict — naming exactly what each
38
39
  * one needs. No-op for a repo with no applicable checklists.
39
- *
40
- * SIDE EFFECT, deliberately: every REFUSED checklist's verdict file is RETIRED to review-<id>.json.old on
41
- * the way out (see {@link retireAndReport}). Only red verdicts are ever moved — a green, yellow or
42
- * overridden one is reused across finish attempts and retiring it would force a needless subagent re-run.
43
40
  */
44
41
  assertEveryReviewerRan(scan) {
45
42
  if (scan.outstanding.length === 0)
@@ -48,17 +45,17 @@ let ReviewerVerdictGate = class ReviewerVerdictGate {
48
45
  // a re-read here could disagree with the set that produced `outstanding`, and a checklist that is
49
46
  // "outstanding" per one read and "clear" per another belongs to neither section of the message.
50
47
  const refused = this.reviewJsonService.refusedChecklists(scan.outstanding, scan.results);
51
- const refusedIds = new Set(refused.map((r) => r.id));
52
- const neverRan = scan.outstanding.filter((r) => !refusedIds.has(r.id));
53
- // Rendered BEFORE the throw and, per checklist, with the verdict resolved before its file is moved —
54
- // the message quotes the reviewer's own words, so losing them to the move would defeat the point.
55
- const refusals = refused.map((req) => this.retireAndReport(scan, req));
56
- throw new rules_config_1.InformAiError(this.headline(scan, refused, neverRan)
48
+ const oranges = this.reviewJsonService.orangeChecklists(scan.outstanding, scan.results);
49
+ const answered = new Set([...refused, ...oranges].map((r) => r.id));
50
+ const neverRan = scan.outstanding.filter((r) => !answered.has(r.id));
51
+ const refusals = refused.map((req) => this.reviewJsonService.refusalError(req, this.reviewJsonService.resolveVerdict(req, scan.results), scan.summaryPath));
52
+ throw new rules_config_1.InformAiError(this.headline(scan, refused, oranges, neverRan)
57
53
  + this.unreadableSection(scan)
54
+ + this.orangeSection(scan, oranges)
58
55
  + this.refusedSection(refusals)
59
56
  + this.discountedSection(scan, neverRan)
60
57
  + this.neverRanSection(scan, neverRan)
61
- + this.footer(refused.length > 0));
58
+ + this.footer(refused.length > 0, oranges.length > 0));
62
59
  }
63
60
  /**
64
61
  * Say plainly how many REFUSED and how many never ran.
@@ -66,10 +63,14 @@ let ReviewerVerdictGate = class ReviewerVerdictGate {
66
63
  * The old headline said all of them "have no passing verdict yet", which is technically true of a refusal
67
64
  * and reads as though nobody had looked. It is the sentence that framed a decision as an omission.
68
65
  */
69
- headline(scan, refused, neverRan) {
66
+ // eslint-disable-next-line @typescript-eslint/max-params
67
+ headline(scan, refused, oranges, neverRan) {
70
68
  const lines = [
71
69
  `⛔ NO PR — ${scan.outstanding.length} of ${scan.applicable.length} review checklist(s) that apply to this branch are not clear:`,
72
70
  ];
71
+ if (oranges.length > 0) {
72
+ lines.push(` • ${oranges.length} ORANGE — a final-round must-fix with no recorded fix yet: ${this.instructions.names(oranges)}`);
73
+ }
73
74
  if (refused.length > 0) {
74
75
  lines.push(` • ${refused.length} REFUSED — a reviewer ran, judged this change, and said no: ${this.instructions.names(refused)}`);
75
76
  }
@@ -104,7 +105,20 @@ let ReviewerVerdictGate = class ReviewerVerdictGate {
104
105
  + scan.formatErrors.map((e) => ` • ${e}`).join('\n') + '\n\n';
105
106
  }
106
107
  /**
107
- * The refusals — SECOND, above anything that says to spawn a subagent, because a spawn instruction is the
108
+ * The ORANGES (issue #1053) — above the refusals and everything that says to spawn, because the one move
109
+ * an orange must never get is a reviewer: the round cap is spent. Fixed code plus a recorded fix is the
110
+ * only way past it, and after that finish proceeds and stamps the orange with its resolution.
111
+ */
112
+ orangeSection(scan, oranges) {
113
+ if (oranges.length === 0)
114
+ return '';
115
+ const findings = oranges.map((req) => ` • ${this.reviewJsonService.orangeError(req, this.reviewJsonService.resolveVerdict(req, scan.results))}`);
116
+ return '🟠 ORANGE — the FINAL review round found these, and nobody will review them again. Do NOT spawn a\n'
117
+ + ' reviewer: fix each finding, commit, and record the fixes with pnpm wp-write-review-fixes.\n\n'
118
+ + findings.join('\n') + '\n';
119
+ }
120
+ /**
121
+ * The refusals — above anything that says to spawn a subagent, because a spawn instruction is the
108
122
  * one line an agent acts on first, and acting on it here IS the loop.
109
123
  */
110
124
  refusedSection(refusals) {
@@ -143,41 +157,14 @@ let ReviewerVerdictGate = class ReviewerVerdictGate {
143
157
  return '❓ NO VERDICT YET — nothing that counts has been submitted for these, so they must actually be run:\n\n'
144
158
  + `${this.instructions.render(neverRan, scan.summaryPath, scan.context)}\n\n`;
145
159
  }
146
- /**
147
- * Retire ONE refused checklist's verdict and render the refusal that reports it.
148
- *
149
- * ORDER IS LOAD-BEARING. The verdict is resolved from the already-loaded results, so the finding is in
150
- * hand before the file moves; the move then happens; and only then is the message rendered, because it
151
- * names the archive path and must not claim a move that did not happen.
152
- *
153
- * The move is NON-FATAL. A finish that died after retiring a verdict would leave the AI with a red
154
- * verdict gone from the live path and no message saying where it went or why the PR was refused — a
155
- * silent gap, and the worst possible outcome for a feature whose entire purpose is a durable record. So a
156
- * failed move warns and the refusal is reported without an archive path (the file is then still live,
157
- * which the un-archived wording of `refusalError` describes correctly).
158
- */
159
- retireAndReport(scan, req) {
160
- const verdict = this.reviewJsonService.resolveVerdict(req, scan.results);
161
- return this.reviewJsonService.refusalError(req, verdict, scan.summaryPath, this.archiveOrWarn(scan.summaryPath, req.id));
162
- }
163
- // The archive path, or '' when there was nothing to move or the move failed (see retireAndReport).
164
- archiveOrWarn(summaryPath, checklistId) {
165
- // webpieces-disable no-unmanaged-exceptions -- chokepoint: a failed archive must never swallow the refusal it belongs to
166
- // eslint-disable-next-line @webpieces/no-unmanaged-exceptions
167
- try {
168
- return this.reviewJsonService.archiveChecklistResult(summaryPath, checklistId);
169
- }
170
- catch (err) {
171
- const error = (0, rules_config_1.toError)(err);
172
- process.stderr.write(`⚠️ Could not retire the refused verdict for "${checklistId}" (non-fatal — the refusal is still `
173
- + `reported below): ${error.message}\n`);
174
- return '';
175
- }
176
- }
177
160
  // Re-running stage 2 is normally optional. It stops being optional after a refusal, because the only way
178
161
  // past one is to CHANGE the code — which is exactly the condition that makes the extracted diff and every
179
162
  // reviewer briefing stale.
180
- footer(anyRefused) {
163
+ footer(anyRefused, anyOrange) {
164
+ if (anyOrange && !anyRefused) {
165
+ return 'Fix every orange finding, commit, record the fixes with pnpm wp-write-review-fixes, then re-run:\n'
166
+ + 'pnpm wp-finish-upsert-pr. No further review round runs.';
167
+ }
181
168
  if (anyRefused) {
182
169
  return 'Fix every finding, commit the remediation, record it with pnpm wp-write-review-fixes, then re-run:\n'
183
170
  + 'pnpm wp-review-upsert-pr. The repository round budget decides whether a focused re-review remains.';
@@ -1 +1 @@
1
- {"version":3,"file":"reviewer-verdict-gate.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/reviewer-verdict-gate.ts"],"names":[],"mappings":";;;;AAAA,0DAGiC;AACjC,yCAA2D;AAE3D,6DAA0F;AAE1F;;;;;;;;;;;;;;;;;;;;GAoBG;AAEI,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IAEP;IACA;IAFrB,YACqB,iBAAoC,EACpC,YAA0C;QAD1C,sBAAiB,GAAjB,iBAAiB,CAAmB;QACpC,iBAAY,GAAZ,YAAY,CAA8B;IAC5D,CAAC;IAEJ;;;;;;;OAOG;IACH,s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,gCAAiB;QACtB,2CAA4B;GAHtD,mBAAmB,CAqK/B","sourcesContent":["import {\n ChecklistInstructionsService, InformAiError, RequiredChecklist, ReviewJsonService,\n toError,\n} from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { ChecklistScan } from './checklist-scanner';\nimport { STANDING_REJECTED, STANDING_STALE, VerdictStanding } from './verdict-provenance';\n\n/**\n * The gate `wp-finish-upsert-pr` runs before it parses summary.json: REFUSE the PR while any applicable\n * checklist is not clear, and say — per checklist — which of three different things went wrong.\n *\n * It is its own class, not a private method on the command, for two reasons. It is the one piece of finish\n * that both MUTATES the branch (it retires red verdicts) and produces the text an AI acts on, so it is the\n * piece most worth asserting on directly; and the command it came out of is already the largest file in this\n * package, against a hard `@webpieces/max-file-lines` limit.\n *\n * THE BUG THIS EXISTS TO FIX. The message used to be one bucket and one imperative — \"You MUST run these N\n * reviewer subagent(s)\" — for three unrelated states. Handed to an agent, the literal, obedient response for\n * a checklist that had ALREADY REFUSED was to spawn the reviewer again; it re-read the same unchanged code,\n * refused again, and the loop cost a full subagent run per pass while the reviewer's actual finding was\n * never printed at all. Three states, three actions, in this order:\n *\n * 1. UNREADABLE (`scan.formatErrors`) -> fix four characters of JSON. Not a reviewer problem.\n * 2. REFUSED (CK_FAIL) -> fix the finding (or get a HUMAN override). Not a missing step.\n * 3. NEVER RAN (the rest) -> spawn the subagent. The ONLY case where that is the right move.\n *\n * `@injectable(bindingScopeValues.Singleton)` so it is injected by type and drawn in the DI design.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class ReviewerVerdictGate {\n constructor(\n private readonly reviewJsonService: ReviewJsonService,\n private readonly instructions: ChecklistInstructionsService,\n ) {}\n\n /**\n * Refuse the PR while ANY applicable checklist still owes a passing verdict — naming exactly what each\n * one needs. No-op for a repo with no applicable checklists.\n *\n * SIDE EFFECT, deliberately: every REFUSED checklist's verdict file is RETIRED to review-<id>.json.old on\n * the way out (see {@link retireAndReport}). Only red verdicts are ever moved — a green, yellow or\n * overridden one is reused across finish attempts and retiring it would force a needless subagent re-run.\n */\n assertEveryReviewerRan(scan: ChecklistScan): void {\n if (scan.outstanding.length === 0) return;\n // The split is computed from the verdicts the SCAN already loaded, never from a second read of disk:\n // a re-read here could disagree with the set that produced `outstanding`, and a checklist that is\n // \"outstanding\" per one read and \"clear\" per another belongs to neither section of the message.\n const refused = this.reviewJsonService.refusedChecklists(scan.outstanding, scan.results);\n const refusedIds = new Set(refused.map((r: RequiredChecklist): string => r.id));\n const neverRan = scan.outstanding.filter((r: RequiredChecklist): boolean => !refusedIds.has(r.id));\n // Rendered BEFORE the throw and, per checklist, with the verdict resolved before its file is moved —\n // the message quotes the reviewer's own words, so losing them to the move would defeat the point.\n const refusals = refused.map((req: RequiredChecklist): string => this.retireAndReport(scan, req));\n throw new InformAiError(\n this.headline(scan, refused, neverRan)\n + this.unreadableSection(scan)\n + this.refusedSection(refusals)\n + this.discountedSection(scan, neverRan)\n + this.neverRanSection(scan, neverRan)\n + this.footer(refused.length > 0),\n );\n }\n\n /**\n * Say plainly how many REFUSED and how many never ran.\n *\n * The old headline said all of them \"have no passing verdict yet\", which is technically true of a refusal\n * and reads as though nobody had looked. It is the sentence that framed a decision as an omission.\n */\n private headline(scan: ChecklistScan, refused: readonly RequiredChecklist[], neverRan: readonly RequiredChecklist[]): string {\n const lines = [\n `⛔ NO PR — ${scan.outstanding.length} of ${scan.applicable.length} review checklist(s) that apply to this branch are not clear:`,\n ];\n if (refused.length > 0) {\n lines.push(` • ${refused.length} REFUSED — a reviewer ran, judged this change, and said no: ${this.instructions.names(refused)}`);\n }\n if (neverRan.length > 0) {\n lines.push(` • ${neverRan.length} never ran — no verdict has been written yet: ${this.instructions.names(neverRan)}`);\n }\n return lines.join('\\n') + this.skippedNote(scan) + '\\n\\n';\n }\n\n /**\n * The optional checklists nobody ran, stated OUT LOUD on the refusal.\n *\n * They are not why the PR is being refused and this block says so — but a message that lists only what\n * blocked reads as \"everything else was reviewed\", and here that is false: those reviews were declined,\n * not passed. The one moment a human is looking at the review state is the moment to be honest about\n * which reviews did not happen, and it is also the prompt an AI needs to offer them again if the human\n * has changed their mind now that something else came back red.\n */\n private skippedNote(scan: ChecklistScan): string {\n if (scan.optionalNotRun.length === 0) return '';\n return `\\n (Not blocking: ${scan.optionalNotRun.length} OPTIONAL checklist(s) were not run — `\n + `${this.instructions.names(scan.optionalNotRun)}. They do not have to run; re-run\\n`\n + ' pnpm wp-review-upsert-pr if you now want to offer them.)';\n }\n\n // Unreadable verdict files come FIRST. A reviewer that wrote its verdict in the removed `success` format\n // is otherwise indistinguishable from one that never ran, and the AI would go re-run a subagent instead\n // of correcting four characters of JSON.\n private unreadableSection(scan: ChecklistScan): string {\n if (scan.formatErrors.length === 0) return '';\n return `${scan.formatErrors.length} verdict file(s) are in an UNREADABLE format:\\n\\n`\n + scan.formatErrors.map((e: string): string => ` • ${e}`).join('\\n') + '\\n\\n';\n }\n\n /**\n * The refusals — SECOND, above anything that says to spawn a subagent, because a spawn instruction is the\n * one line an agent acts on first, and acting on it here IS the loop.\n */\n private refusedSection(refusals: readonly string[]): string {\n if (refusals.length === 0) return '';\n return '⛔ REFUSED — these reviewers ALREADY ANSWERED. Re-spawning one against unchanged code only buys\\n'\n + ' the same answer: fix what it found (or get a HUMAN to authorize an override), THEN review again.\\n\\n'\n + refusals.map((r: string): string => ` • ${r}`).join('\\n\\n') + '\\n\\n';\n }\n\n /**\n * Verdict files that EXIST but do not count (issue #863), each with why — printed before the spawn\n * list so the reader does not mistake them for reviewers that never ran, and so a hand-written verdict\n * is named as what it is. REJECTED: no `wp-write-review` provenance, or edited after submission — a\n * coordinator writing a reviewer's verdict lands here, and that is the forgery this gate exists to\n * refuse. STALE: the checklist's in-scope files changed since it was submitted.\n */\n private discountedSection(scan: ChecklistScan, neverRan: readonly RequiredChecklist[]): string {\n const owed = new Set(neverRan.map((r: RequiredChecklist): string => r.id));\n const discounted = scan.standings.filter((s: VerdictStanding): boolean => owed.has(s.checklistId)\n && (s.standing === STANDING_REJECTED || s.standing === STANDING_STALE));\n if (discounted.length === 0) return '';\n return '🚫 NOT COUNTED — these verdict files exist, but they are not a current review:\\n\\n'\n + discounted.map((s: VerdictStanding): string => ` • ${s.checklistId} — ${s.standing.toUpperCase()}: ${s.reason}`).join('\\n')\n + '\\n A reviewer SUBAGENT must submit a fresh verdict with pnpm wp-write-review. Do NOT write or copy the\\n'\n + ' file yourself: the bin refuses the coordinating agent, and this gate rejects a verdict it did not write.\\n\\n';\n }\n\n /**\n * The reviewers that genuinely never ran — LAST, and listing ONLY these. When there are none this block\n * is absent entirely, which is the whole point: the \"You MUST run these N reviewer subagent(s)\"\n * imperative must not appear at all on a run whose only problem is a refusal.\n */\n private neverRanSection(scan: ChecklistScan, neverRan: readonly RequiredChecklist[]): string {\n if (neverRan.length === 0) return '';\n return '❓ NO VERDICT YET — nothing that counts has been submitted for these, so they must actually be run:\\n\\n'\n + `${this.instructions.render(neverRan, scan.summaryPath, scan.context)}\\n\\n`;\n }\n\n /**\n * Retire ONE refused checklist's verdict and render the refusal that reports it.\n *\n * ORDER IS LOAD-BEARING. The verdict is resolved from the already-loaded results, so the finding is in\n * hand before the file moves; the move then happens; and only then is the message rendered, because it\n * names the archive path and must not claim a move that did not happen.\n *\n * The move is NON-FATAL. A finish that died after retiring a verdict would leave the AI with a red\n * verdict gone from the live path and no message saying where it went or why the PR was refused — a\n * silent gap, and the worst possible outcome for a feature whose entire purpose is a durable record. So a\n * failed move warns and the refusal is reported without an archive path (the file is then still live,\n * which the un-archived wording of `refusalError` describes correctly).\n */\n private retireAndReport(scan: ChecklistScan, req: RequiredChecklist): string {\n const verdict = this.reviewJsonService.resolveVerdict(req, scan.results);\n return this.reviewJsonService.refusalError(\n req, verdict, scan.summaryPath, this.archiveOrWarn(scan.summaryPath, req.id));\n }\n\n // The archive path, or '' when there was nothing to move or the move failed (see retireAndReport).\n private archiveOrWarn(summaryPath: string, checklistId: string): string {\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: a failed archive must never swallow the refusal it belongs to\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n return this.reviewJsonService.archiveChecklistResult(summaryPath, checklistId);\n } catch (err: unknown) {\n const error = toError(err);\n process.stderr.write(\n `⚠️ Could not retire the refused verdict for \"${checklistId}\" (non-fatal — the refusal is still `\n + `reported below): ${error.message}\\n`);\n return '';\n }\n }\n\n // Re-running stage 2 is normally optional. It stops being optional after a refusal, because the only way\n // past one is to CHANGE the code — which is exactly the condition that makes the extracted diff and every\n // reviewer briefing stale.\n private footer(anyRefused: boolean): string {\n if (anyRefused) {\n return 'Fix every finding, commit the remediation, record it with pnpm wp-write-review-fixes, then re-run:\\n'\n + 'pnpm wp-review-upsert-pr. The repository round budget decides whether a focused re-review remains.';\n }\n return 'Then re-run: pnpm wp-finish-upsert-pr\\n'\n + '(Each reviewer\\'s generated instructions file is already written — re-running pnpm wp-review-upsert-pr\\n'\n + ' is only needed if the code changed since it ran.)';\n }\n}\n"]}
1
+ {"version":3,"file":"reviewer-verdict-gate.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/reviewer-verdict-gate.ts"],"names":[],"mappings":";;;;AAAA,0DAEiC;AACjC,yCAA2D;AAE3D,6DAA0F;AAE1F;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEI,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IAEP;IACA;IAFrB,YACqB,iBAAoC,EACpC,YAA0C;QAD1C,sBAAiB,GAAjB,iBAAiB,CAAmB;QACpC,iBAAY,GAAZ,YAAY,CAA8B;IAC5D,CAAC;IAEJ;;;OAGG;IACH,sBAAsB,CAAC,IAAmB;QACtC,IAAI,IAAI,CAAC,WAAW,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO;QAC1C,qGAAqG;QACrG,kGAAkG;QAClG,gGAAgG;QAChG,MAAM,OAAO,GAAG,IAAI,CAAC,iBAAiB,CAAC,iBAAiB,CAAC,IAAI,CAAC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CAAC;IAC/D,CAAC;CACJ,CAAA;AAxJY,kDAAmB;8BAAnB,mBAAmB;IAD/B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGG,gCAAiB;QACtB,2CAA4B;GAHtD,mBAAmB,CAwJ/B","sourcesContent":["import {\n ChecklistInstructionsService, InformAiError, RequiredChecklist, ReviewJsonService,\n} from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { ChecklistScan } from './checklist-scanner';\nimport { STANDING_REJECTED, STANDING_STALE, VerdictStanding } from './verdict-provenance';\n\n/**\n * The gate `wp-finish-upsert-pr` runs before it parses summary.json: REFUSE the PR while any applicable\n * checklist is not clear, and say — per checklist — which of three different things went wrong.\n *\n * It is its own class, not a private method on the command, for two reasons. It produces the text an AI acts\n * on, so it is the piece most worth asserting on directly; and the command it came out of is already the\n * largest file in this package, against a hard `@webpieces/max-file-lines` limit. It never moves or deletes\n * a verdict: every round's verdict is its own file and stays on disk (issue #1053).\n *\n * THE BUG THIS EXISTS TO FIX. The message used to be one bucket and one imperative — \"You MUST run these N\n * reviewer subagent(s)\" — for three unrelated states. Handed to an agent, the literal, obedient response for\n * a checklist that had ALREADY REFUSED was to spawn the reviewer again; it re-read the same unchanged code,\n * refused again, and the loop cost a full subagent run per pass while the reviewer's actual finding was\n * never printed at all. Three states, three actions, in this order:\n *\n * 1. UNREADABLE (`scan.formatErrors`) -> fix four characters of JSON. Not a reviewer problem.\n * 2. ORANGE (CK_ORANGE) -> the final round's must-fix: fix it, record the fix. Never a reviewer.\n * 3. REFUSED (CK_FAIL) -> fix the finding (or get a HUMAN override). Not a missing step.\n * 4. NEVER RAN (the rest) -> spawn the subagent. The ONLY case where that is the right move.\n *\n * `@injectable(bindingScopeValues.Singleton)` so it is injected by type and drawn in the DI design.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class ReviewerVerdictGate {\n constructor(\n private readonly reviewJsonService: ReviewJsonService,\n private readonly instructions: ChecklistInstructionsService,\n ) {}\n\n /**\n * Refuse the PR while ANY applicable checklist still owes a passing verdict — naming exactly what each\n * one needs. No-op for a repo with no applicable checklists.\n */\n assertEveryReviewerRan(scan: ChecklistScan): void {\n if (scan.outstanding.length === 0) return;\n // The split is computed from the verdicts the SCAN already loaded, never from a second read of disk:\n // a re-read here could disagree with the set that produced `outstanding`, and a checklist that is\n // \"outstanding\" per one read and \"clear\" per another belongs to neither section of the message.\n const refused = this.reviewJsonService.refusedChecklists(scan.outstanding, scan.results);\n const oranges = this.reviewJsonService.orangeChecklists(scan.outstanding, scan.results);\n const answered = new Set([...refused, ...oranges].map((r: RequiredChecklist): string => r.id));\n const neverRan = scan.outstanding.filter((r: RequiredChecklist): boolean => !answered.has(r.id));\n const refusals = refused.map((req: RequiredChecklist): string =>\n this.reviewJsonService.refusalError(req, this.reviewJsonService.resolveVerdict(req, scan.results), scan.summaryPath));\n throw new InformAiError(\n this.headline(scan, refused, oranges, neverRan)\n + this.unreadableSection(scan)\n + this.orangeSection(scan, oranges)\n + this.refusedSection(refusals)\n + this.discountedSection(scan, neverRan)\n + this.neverRanSection(scan, neverRan)\n + this.footer(refused.length > 0, oranges.length > 0),\n );\n }\n\n /**\n * Say plainly how many REFUSED and how many never ran.\n *\n * The old headline said all of them \"have no passing verdict yet\", which is technically true of a refusal\n * and reads as though nobody had looked. It is the sentence that framed a decision as an omission.\n */\n // eslint-disable-next-line @typescript-eslint/max-params\n private headline(\n scan: ChecklistScan, refused: readonly RequiredChecklist[], oranges: readonly RequiredChecklist[], neverRan: readonly RequiredChecklist[],\n ): string {\n const lines = [\n `⛔ NO PR — ${scan.outstanding.length} of ${scan.applicable.length} review checklist(s) that apply to this branch are not clear:`,\n ];\n if (oranges.length > 0) {\n lines.push(` • ${oranges.length} ORANGE — a final-round must-fix with no recorded fix yet: ${this.instructions.names(oranges)}`);\n }\n if (refused.length > 0) {\n lines.push(` • ${refused.length} REFUSED — a reviewer ran, judged this change, and said no: ${this.instructions.names(refused)}`);\n }\n if (neverRan.length > 0) {\n lines.push(` • ${neverRan.length} never ran — no verdict has been written yet: ${this.instructions.names(neverRan)}`);\n }\n return lines.join('\\n') + this.skippedNote(scan) + '\\n\\n';\n }\n\n /**\n * The optional checklists nobody ran, stated OUT LOUD on the refusal.\n *\n * They are not why the PR is being refused and this block says so — but a message that lists only what\n * blocked reads as \"everything else was reviewed\", and here that is false: those reviews were declined,\n * not passed. The one moment a human is looking at the review state is the moment to be honest about\n * which reviews did not happen, and it is also the prompt an AI needs to offer them again if the human\n * has changed their mind now that something else came back red.\n */\n private skippedNote(scan: ChecklistScan): string {\n if (scan.optionalNotRun.length === 0) return '';\n return `\\n (Not blocking: ${scan.optionalNotRun.length} OPTIONAL checklist(s) were not run — `\n + `${this.instructions.names(scan.optionalNotRun)}. They do not have to run; re-run\\n`\n + ' pnpm wp-review-upsert-pr if you now want to offer them.)';\n }\n\n // Unreadable verdict files come FIRST. A reviewer that wrote its verdict in the removed `success` format\n // is otherwise indistinguishable from one that never ran, and the AI would go re-run a subagent instead\n // of correcting four characters of JSON.\n private unreadableSection(scan: ChecklistScan): string {\n if (scan.formatErrors.length === 0) return '';\n return `${scan.formatErrors.length} verdict file(s) are in an UNREADABLE format:\\n\\n`\n + scan.formatErrors.map((e: string): string => ` • ${e}`).join('\\n') + '\\n\\n';\n }\n\n /**\n * The ORANGES (issue #1053) — above the refusals and everything that says to spawn, because the one move\n * an orange must never get is a reviewer: the round cap is spent. Fixed code plus a recorded fix is the\n * only way past it, and after that finish proceeds and stamps the orange with its resolution.\n */\n private orangeSection(scan: ChecklistScan, oranges: readonly RequiredChecklist[]): string {\n if (oranges.length === 0) return '';\n const findings = oranges.map((req: RequiredChecklist): string =>\n ` • ${this.reviewJsonService.orangeError(req, this.reviewJsonService.resolveVerdict(req, scan.results))}`);\n return '🟠 ORANGE — the FINAL review round found these, and nobody will review them again. Do NOT spawn a\\n'\n + ' reviewer: fix each finding, commit, and record the fixes with pnpm wp-write-review-fixes.\\n\\n'\n + findings.join('\\n') + '\\n';\n }\n\n /**\n * The refusals — above anything that says to spawn a subagent, because a spawn instruction is the\n * one line an agent acts on first, and acting on it here IS the loop.\n */\n private refusedSection(refusals: readonly string[]): string {\n if (refusals.length === 0) return '';\n return '⛔ REFUSED — these reviewers ALREADY ANSWERED. Re-spawning one against unchanged code only buys\\n'\n + ' the same answer: fix what it found (or get a HUMAN to authorize an override), THEN review again.\\n\\n'\n + refusals.map((r: string): string => ` • ${r}`).join('\\n\\n') + '\\n\\n';\n }\n\n /**\n * Verdict files that EXIST but do not count (issue #863), each with why — printed before the spawn\n * list so the reader does not mistake them for reviewers that never ran, and so a hand-written verdict\n * is named as what it is. REJECTED: no `wp-write-review` provenance, or edited after submission — a\n * coordinator writing a reviewer's verdict lands here, and that is the forgery this gate exists to\n * refuse. STALE: the checklist's in-scope files changed since it was submitted.\n */\n private discountedSection(scan: ChecklistScan, neverRan: readonly RequiredChecklist[]): string {\n const owed = new Set(neverRan.map((r: RequiredChecklist): string => r.id));\n const discounted = scan.standings.filter((s: VerdictStanding): boolean => owed.has(s.checklistId)\n && (s.standing === STANDING_REJECTED || s.standing === STANDING_STALE));\n if (discounted.length === 0) return '';\n return '🚫 NOT COUNTED — these verdict files exist, but they are not a current review:\\n\\n'\n + discounted.map((s: VerdictStanding): string => ` • ${s.checklistId} — ${s.standing.toUpperCase()}: ${s.reason}`).join('\\n')\n + '\\n A reviewer SUBAGENT must submit a fresh verdict with pnpm wp-write-review. Do NOT write or copy the\\n'\n + ' file yourself: the bin refuses the coordinating agent, and this gate rejects a verdict it did not write.\\n\\n';\n }\n\n /**\n * The reviewers that genuinely never ran — LAST, and listing ONLY these. When there are none this block\n * is absent entirely, which is the whole point: the \"You MUST run these N reviewer subagent(s)\"\n * imperative must not appear at all on a run whose only problem is a refusal.\n */\n private neverRanSection(scan: ChecklistScan, neverRan: readonly RequiredChecklist[]): string {\n if (neverRan.length === 0) return '';\n return '❓ NO VERDICT YET — nothing that counts has been submitted for these, so they must actually be run:\\n\\n'\n + `${this.instructions.render(neverRan, scan.summaryPath, scan.context)}\\n\\n`;\n }\n\n // Re-running stage 2 is normally optional. It stops being optional after a refusal, because the only way\n // past one is to CHANGE the code — which is exactly the condition that makes the extracted diff and every\n // reviewer briefing stale.\n private footer(anyRefused: boolean, anyOrange: boolean): string {\n if (anyOrange && !anyRefused) {\n return 'Fix every orange finding, commit, record the fixes with pnpm wp-write-review-fixes, then re-run:\\n'\n + 'pnpm wp-finish-upsert-pr. No further review round runs.';\n }\n if (anyRefused) {\n return 'Fix every finding, commit the remediation, record it with pnpm wp-write-review-fixes, then re-run:\\n'\n + 'pnpm wp-review-upsert-pr. The repository round budget decides whether a focused re-review remains.';\n }\n return 'Then re-run: pnpm wp-finish-upsert-pr\\n'\n + '(Each reviewer\\'s generated instructions file is already written — re-running pnpm wp-review-upsert-pr\\n'\n + ' is only needed if the code changed since it ran.)';\n }\n}\n"]}
@@ -11,8 +11,8 @@ export declare class SubmittedVerdict {
11
11
  constructor(id: string, status: string, agent: string, model: string, output: string);
12
12
  }
13
13
  /**
14
- * The record `wp-write-review` writes to `review-<id>.provenance.json`. Data-only; field names are the JSON
15
- * keys, `_WHAT_THIS_IS` first so a reader learns what the file is before anything it might act on.
14
+ * The record `wp-write-review` writes to `review-round<N>-<id>.provenance.json`. Data-only; field names are
15
+ * the JSON keys, `_WHAT_THIS_IS` first so a reader learns what the file is before anything it might act on.
16
16
  */
17
17
  export declare class VerdictProvenance {
18
18
  _WHAT_THIS_IS: string;
@@ -37,9 +37,9 @@ export declare const STANDING_STALE = "stale";
37
37
  /** No bin provenance, or edited after submission: not a reviewer's verdict at all. */
38
38
  export declare const STANDING_REJECTED = "rejected";
39
39
  /**
40
- * Would be STALE, but still COUNTS (issue #1051): either the reviewer-round budget is spent, so no review
41
- * round can ever re-judge it and demanding one would deadlock the branch, or a human override for its
42
- * checklist stands. The reason says which, and is printed verbatim.
40
+ * Would be STALE, but still COUNTS: staleness never triggers a re-review (issue #1053) — a green, yellow or
41
+ * orange verdict stands whatever round it came from — and a human override for its checklist always wins
42
+ * (issue #1051). The reason says which, and is printed verbatim.
43
43
  */
44
44
  export declare const STANDING_CARRIED = "carried";
45
45
  /**
@@ -69,17 +69,17 @@ export declare class VerdictProvenanceService {
69
69
  private readonly reviewJsonService;
70
70
  private readonly atomicFile;
71
71
  constructor(reviewJsonService: ReviewJsonService, atomicFile: AtomicFile);
72
- /** `review-<id>.provenance.json`, beside the verdict. */
73
- provenancePath(summaryPath: string, checklistId: string): string;
72
+ /** `review-round<N>-<id>.provenance.json`, beside the verdict of the same round. */
73
+ provenancePath(summaryPath: string, checklistId: string, round: number): string;
74
74
  /**
75
75
  * sha256 over the five fields in a FIXED order, so formatting, key order and whitespace outside the
76
76
  * values cannot move it — only a change to what the verdict SAYS can.
77
77
  */
78
78
  canonicalHash(verdict: SubmittedVerdict): string;
79
- /** Write the verdict, then its provenance. Returns the verdict path. */
79
+ /** Write the verdict, then its provenance, both for `provenance.round`. Returns the verdict path. */
80
80
  write(summaryPath: string, verdict: SubmittedVerdict, provenance: VerdictProvenance): string;
81
- /** The provenance for one checklist, or null when there is none (or it is unreadable). */
82
- read(summaryPath: string, checklistId: string): VerdictProvenance | null;
81
+ /** The provenance for one checklist's verdict in one round, or null when there is none (or it is unreadable). */
82
+ read(summaryPath: string, checklistId: string, round: number): VerdictProvenance | null;
83
83
  /**
84
84
  * How one parsed verdict stands. `currentScopeHash` is this checklist's scope hash NOW ('' when it
85
85
  * could not be computed, which never marks anything stale).
@@ -32,8 +32,8 @@ class SubmittedVerdict {
32
32
  }
33
33
  exports.SubmittedVerdict = SubmittedVerdict;
34
34
  /**
35
- * The record `wp-write-review` writes to `review-<id>.provenance.json`. Data-only; field names are the JSON
36
- * keys, `_WHAT_THIS_IS` first so a reader learns what the file is before anything it might act on.
35
+ * The record `wp-write-review` writes to `review-round<N>-<id>.provenance.json`. Data-only; field names are
36
+ * the JSON keys, `_WHAT_THIS_IS` first so a reader learns what the file is before anything it might act on.
37
37
  */
38
38
  class VerdictProvenance {
39
39
  // webpieces-disable naming-convention -- the leading underscore marks a note-to-the-reader key, not data
@@ -49,7 +49,7 @@ class VerdictProvenance {
49
49
  status; // the status as submitted
50
50
  verdictHash; // VerdictProvenanceService.canonicalHash of the verdict as submitted
51
51
  writtenAt;
52
- round;
52
+ round; // the N of review-round<N>-<id>.json — which review round this verdict belongs to
53
53
  // eslint-disable-next-line @typescript-eslint/max-params
54
54
  constructor(checklistId, harness, sessionId, agentId, agentType, headSha, scopeHash) {
55
55
  this.writer = rules_config_1.WRITE_REVIEW_BIN;
@@ -74,9 +74,9 @@ exports.STANDING_STALE = 'stale';
74
74
  /** No bin provenance, or edited after submission: not a reviewer's verdict at all. */
75
75
  exports.STANDING_REJECTED = 'rejected';
76
76
  /**
77
- * Would be STALE, but still COUNTS (issue #1051): either the reviewer-round budget is spent, so no review
78
- * round can ever re-judge it and demanding one would deadlock the branch, or a human override for its
79
- * checklist stands. The reason says which, and is printed verbatim.
77
+ * Would be STALE, but still COUNTS: staleness never triggers a re-review (issue #1053) — a green, yellow or
78
+ * orange verdict stands whatever round it came from — and a human override for its checklist always wins
79
+ * (issue #1051). The reason says which, and is printed verbatim.
80
80
  */
81
81
  exports.STANDING_CARRIED = 'carried';
82
82
  /**
@@ -86,7 +86,7 @@ exports.STANDING_CARRIED = 'carried';
86
86
  class VerdictStanding {
87
87
  checklistId;
88
88
  standing; // STANDING_CURRENT | STANDING_STALE | STANDING_REJECTED | STANDING_CARRIED
89
- status; // the verdict's own green | yellow | red
89
+ status; // the verdict's own green | yellow | orange | red
90
90
  fromSha; // the commit it was briefed on ('' when rejected)
91
91
  reason; // why — printed verbatim
92
92
  // eslint-disable-next-line @typescript-eslint/max-params
@@ -117,9 +117,9 @@ let VerdictProvenanceService = class VerdictProvenanceService {
117
117
  this.reviewJsonService = reviewJsonService;
118
118
  this.atomicFile = atomicFile;
119
119
  }
120
- /** `review-<id>.provenance.json`, beside the verdict. */
121
- provenancePath(summaryPath, checklistId) {
122
- return path.join(path.dirname(summaryPath), `review-${checklistId}.provenance.json`);
120
+ /** `review-round<N>-<id>.provenance.json`, beside the verdict of the same round. */
121
+ provenancePath(summaryPath, checklistId, round) {
122
+ return path.join(path.dirname(summaryPath), `review-round${round}-${checklistId}.provenance.json`);
123
123
  }
124
124
  /**
125
125
  * sha256 over the five fields in a FIXED order, so formatting, key order and whitespace outside the
@@ -129,19 +129,19 @@ let VerdictProvenanceService = class VerdictProvenanceService {
129
129
  const canonical = JSON.stringify([verdict.id, verdict.status, verdict.agent, verdict.model, verdict.output]);
130
130
  return crypto.createHash('sha256').update(canonical).digest('hex');
131
131
  }
132
- /** Write the verdict, then its provenance. Returns the verdict path. */
132
+ /** Write the verdict, then its provenance, both for `provenance.round`. Returns the verdict path. */
133
133
  write(summaryPath, verdict, provenance) {
134
- const verdictPath = this.reviewJsonService.checklistResultPath(summaryPath, verdict.id);
134
+ const verdictPath = this.reviewJsonService.checklistResultPath(summaryPath, verdict.id, provenance.round);
135
135
  provenance.status = verdict.status;
136
136
  provenance.verdictHash = this.canonicalHash(verdict);
137
137
  provenance.writtenAt = new Date().toISOString();
138
138
  this.atomicFile.writeJsonAtomic(verdictPath, verdict);
139
- this.atomicFile.writeJsonAtomic(this.provenancePath(summaryPath, verdict.id), provenance);
139
+ this.atomicFile.writeJsonAtomic(this.provenancePath(summaryPath, verdict.id, provenance.round), provenance);
140
140
  return verdictPath;
141
141
  }
142
- /** The provenance for one checklist, or null when there is none (or it is unreadable). */
143
- read(summaryPath, checklistId) {
144
- const file = this.provenancePath(summaryPath, checklistId);
142
+ /** The provenance for one checklist's verdict in one round, or null when there is none (or it is unreadable). */
143
+ read(summaryPath, checklistId, round) {
144
+ const file = this.provenancePath(summaryPath, checklistId, round);
145
145
  if (!fs.existsSync(file))
146
146
  return null;
147
147
  // webpieces-disable no-unmanaged-exceptions -- chokepoint: an unreadable record is treated as no record, which REJECTS the verdict
@@ -170,22 +170,24 @@ let VerdictProvenanceService = class VerdictProvenanceService {
170
170
  // eslint-disable-next-line @typescript-eslint/max-params
171
171
  assess(summaryPath, result, currentScopeHash) {
172
172
  const id = result.id;
173
- const record = this.read(summaryPath, id);
173
+ const round = result.round;
174
+ const verdictFile = path.basename(this.reviewJsonService.checklistResultPath(summaryPath, id, round));
175
+ const record = this.read(summaryPath, id, round);
174
176
  const reject = (reason) => new VerdictStanding(id, exports.STANDING_REJECTED, result.status, '', reason);
175
177
  if (record === null) {
176
- const file = this.provenancePath(summaryPath, id);
178
+ const file = this.provenancePath(summaryPath, id, round);
177
179
  const why = fs.existsSync(file) ? `${path.basename(file)} is unreadable` : `no ${path.basename(file)}`;
178
- return reject(`review-${id}.json was not submitted through pnpm ${rules_config_1.WRITE_REVIEW_BIN} (${why}) — a hand-written verdict is not a review`);
180
+ return reject(`${verdictFile} was not submitted through pnpm ${rules_config_1.WRITE_REVIEW_BIN} (${why}) — a hand-written verdict is not a review`);
179
181
  }
180
- if (record.writer !== rules_config_1.WRITE_REVIEW_BIN || record.checklistId !== id) {
181
- return reject(`review-${id}.provenance.json was not written by ${rules_config_1.WRITE_REVIEW_BIN} for this checklist`);
182
+ if (record.writer !== rules_config_1.WRITE_REVIEW_BIN || record.checklistId !== id || record.round !== round) {
183
+ return reject(`${path.basename(this.provenancePath(summaryPath, id, round))} was not written by ${rules_config_1.WRITE_REVIEW_BIN} for this checklist and round`);
182
184
  }
183
185
  if (record.agentId.trim() === '' && record.harness !== exports.HARNESS_TERMINAL) {
184
- return reject(`review-${id}.json was submitted by the coordinating agent, not a reviewer subagent`);
186
+ return reject(`${verdictFile} was submitted by the coordinating agent, not a reviewer subagent`);
185
187
  }
186
188
  const submitted = new SubmittedVerdict(id, result.status, result.agent, result.model, result.output);
187
189
  if (this.canonicalHash(submitted) !== record.verdictHash) {
188
- return reject(`review-${id}.json was EDITED after ${rules_config_1.WRITE_REVIEW_BIN} wrote it — a verdict is the reviewer's words, not a draft`);
190
+ return reject(`${verdictFile} was EDITED after ${rules_config_1.WRITE_REVIEW_BIN} wrote it — a verdict is the reviewer's words, not a draft`);
189
191
  }
190
192
  if (currentScopeHash !== '' && record.scopeHash !== currentScopeHash) {
191
193
  return new VerdictStanding(id, exports.STANDING_STALE, result.status, record.headSha, `in-scope files CHANGED since the verdict was written at ${this.short(record.headSha)}`);
@@ -1 +1 @@
1
- {"version":3,"file":"verdict-provenance.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/verdict-provenance.ts"],"names":[],"mappings":";;;;AAAA,uDAAiC;AACjC,+CAAyB;AACzB,mDAA6B;AAC7B,0DAEiC;AACjC,yCAA2D;AAE3D,6GAA6G;AAChG,QAAA,gBAAgB,GAAG,UAAU,CAAC;AAE3C,MAAM,YAAY,GACd,2GAA2G;IAC3G,uGAAuG;IACvG,uGAAuG;IACvG,mGAAmG;IACnG,iDAAiD,CAAC;AAEtD,uGAAuG;AACvG,MAAa,gBAAgB;IACzB,EAAE,CAAS;IACX,MAAM,CAAS;IACf,KAAK,CAAS;IACd,KAAK,CAAS;IACd,MAAM,CAAS;IAEf,yDAAyD;IACzD,YAAY,EAAU,EAAE,MAAc,EAAE,KAAa,EAAE,KAAa,EAAE,MAAc;QAChF,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;CACJ;AAfD,4CAeC;AAED;;;GAGG;AACH,MAAa,iBAAiB;IAC1B,yGAAyG;IACzG,aAAa,GAAG,YAAY,CAAC;IAC7B,MAAM,CAAS,CAAU,gFAAgF;IACzG,WAAW,CAAS;IACpB,OAAO,CAAS,CAAS,6CAA6C;IACtE,SAAS,CAAS;IAClB,OAAO,CAAS,CAAS,4DAA4D;IACrF,SAAS,CAAS;IAClB,OAAO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AC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QACjG,CAAC;QACD,OAAO,IAAI,eAAe,CAAC,EAAE,EAAE,wBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,EAC1E,kCAAkC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IACxE,CAAC;IAED,6EAA6E;IAC7E,KAAK,CAAC,GAAW;QACb,OAAO,GAAG,KAAK,EAAE,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC1D,CAAC;IAED,kFAAkF;IAC1E,GAAG,CAAC,KAAc;QACtB,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;IAClD,CAAC;CACJ,CAAA;AAjGY,4DAAwB;mCAAxB,wBAAwB;IADpC,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGG,gCAAiB;QACxB,yBAAU;GAHlC,wBAAwB,CAiGpC","sourcesContent":["import * as crypto from 'crypto';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport {\n AtomicFile, ChecklistResult, ReviewJsonService, WRITE_REVIEW_BIN, toError,\n} from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\n\n/** `harness` for a verdict submitted from a plain terminal — a HUMAN reviewer, with no AI harness at all. */\nexport const HARNESS_TERMINAL = 'terminal';\n\nconst WHAT_THIS_IS =\n 'PROVENANCE — written by pnpm wp-write-review beside the verdict it submitted, never by an AI. It records ' +\n 'WHO submitted that verdict (harness, session, agent — as the harness reported them to the PreToolUse ' +\n 'hook), WHICH commit and in-scope diff the reviewer was briefed on, and a hash of the verdict itself. ' +\n 'wp-finish-upsert-pr rejects a verdict with no provenance, or one edited after submission. Do not ' +\n 'hand-edit or copy it: that is forging a review.';\n\n/** A verdict exactly as `wp-write-review` accepts it — the five fields and nothing else. Data-only. */\nexport class SubmittedVerdict {\n id: string;\n status: string;\n agent: string;\n model: string;\n output: string;\n\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(id: string, status: string, agent: string, model: string, output: string) {\n this.id = id;\n this.status = status;\n this.agent = agent;\n this.model = model;\n this.output = output;\n }\n}\n\n/**\n * The record `wp-write-review` writes to `review-<id>.provenance.json`. Data-only; field names are the JSON\n * keys, `_WHAT_THIS_IS` first so a reader learns what the file is before anything it might act on.\n */\nexport class VerdictProvenance {\n // webpieces-disable naming-convention -- the leading underscore marks a note-to-the-reader key, not data\n _WHAT_THIS_IS = WHAT_THIS_IS;\n writer: string; // always WRITE_REVIEW_BIN — a record naming anything else was not written by it\n checklistId: string;\n harness: string; // 'claude-code' | 'codex' | HARNESS_TERMINAL\n sessionId: string;\n agentId: string; // the SUBAGENT that submitted; '' only for HARNESS_TERMINAL\n agentType: string;\n headSha: string; // the commit stage ② briefed this reviewer on\n scopeHash: string; // ChecklistScopeHasher's hash of this checklist's in-scope diff at that commit\n status: string; // the status as submitted\n verdictHash: string; // VerdictProvenanceService.canonicalHash of the verdict as submitted\n writtenAt: string;\n round: number;\n\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(checklistId: string, harness: string, sessionId: string, agentId: string, agentType: string, headSha: string, scopeHash: string) {\n this.writer = WRITE_REVIEW_BIN;\n this.checklistId = checklistId;\n this.harness = harness;\n this.sessionId = sessionId;\n this.agentId = agentId;\n this.agentType = agentType;\n this.headSha = headSha;\n this.scopeHash = scopeHash;\n this.status = '';\n this.verdictHash = '';\n this.writtenAt = '';\n this.round = 0;\n }\n}\n\n/** A live verdict that stands: submitted through the bin and judged the in-scope diff as it is NOW. */\nexport const STANDING_CURRENT = 'current';\n/** Submitted through the bin, but the checklist's in-scope diff has changed since — it judged other code. */\nexport const STANDING_STALE = 'stale';\n/** No bin provenance, or edited after submission: not a reviewer's verdict at all. */\nexport const STANDING_REJECTED = 'rejected';\n/**\n * Would be STALE, but still COUNTS (issue #1051): either the reviewer-round budget is spent, so no review\n * round can ever re-judge it and demanding one would deadlock the branch, or a human override for its\n * checklist stands. The reason says which, and is printed verbatim.\n */\nexport const STANDING_CARRIED = 'carried';\n\n/**\n * How ONE existing verdict file stands against the branch as it is now. Data-only. Carried on the\n * checklist scan so stage ② (which briefs) and stage ③ (which blocks) read one answer.\n */\nexport class VerdictStanding {\n checklistId: string;\n standing: string; // STANDING_CURRENT | STANDING_STALE | STANDING_REJECTED | STANDING_CARRIED\n status: string; // the verdict's own green | yellow | red\n fromSha: string; // the commit it was briefed on ('' when rejected)\n reason: string; // why — printed verbatim\n\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(checklistId: string, standing: string, status: string, fromSha: string, reason: string) {\n this.checklistId = checklistId;\n this.standing = standing;\n this.status = status;\n this.fromSha = fromSha;\n this.reason = reason;\n }\n}\n\n/**\n * Writes a submitted verdict WITH its provenance, and judges an existing verdict against it (issue #863).\n *\n * This is what closes the forgery the issue measured: a Codex coordinator wrote five `review-<id>.json`\n * files itself and the gate accepted them, because nothing distinguished a reviewer's verdict from a file\n * that merely had the right shape. Now a verdict counts only when `wp-write-review` wrote it — which it does\n * only for a caller the harness identified as a subagent — and only while it still says exactly what was\n * submitted.\n *\n * `@injectable(bindingScopeValues.Singleton)` so it is injected by type and drawn in the DI design.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class VerdictProvenanceService {\n constructor(\n private readonly reviewJsonService: ReviewJsonService,\n private readonly atomicFile: AtomicFile,\n ) {}\n\n /** `review-<id>.provenance.json`, beside the verdict. */\n provenancePath(summaryPath: string, checklistId: string): string {\n return path.join(path.dirname(summaryPath), `review-${checklistId}.provenance.json`);\n }\n\n /**\n * sha256 over the five fields in a FIXED order, so formatting, key order and whitespace outside the\n * values cannot move it — only a change to what the verdict SAYS can.\n */\n canonicalHash(verdict: SubmittedVerdict): string {\n const canonical = JSON.stringify([verdict.id, verdict.status, verdict.agent, verdict.model, verdict.output]);\n return crypto.createHash('sha256').update(canonical).digest('hex');\n }\n\n /** Write the verdict, then its provenance. Returns the verdict path. */\n write(summaryPath: string, verdict: SubmittedVerdict, provenance: VerdictProvenance): string {\n const verdictPath = this.reviewJsonService.checklistResultPath(summaryPath, verdict.id);\n provenance.status = verdict.status;\n provenance.verdictHash = this.canonicalHash(verdict);\n provenance.writtenAt = new Date().toISOString();\n this.atomicFile.writeJsonAtomic(verdictPath, verdict);\n this.atomicFile.writeJsonAtomic(this.provenancePath(summaryPath, verdict.id), provenance);\n return verdictPath;\n }\n\n /** The provenance for one checklist, or null when there is none (or it is unreadable). */\n read(summaryPath: string, checklistId: string): VerdictProvenance | null {\n const file = this.provenancePath(summaryPath, checklistId);\n if (!fs.existsSync(file)) return null;\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: an unreadable record is treated as no record, which REJECTS the verdict\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n // webpieces-disable no-any-unknown -- opaque parsed JSON, narrowed field-by-field below\n const raw = JSON.parse(fs.readFileSync(file, 'utf8')) as Record<string, unknown>;\n const record = new VerdictProvenance(\n this.str(raw['checklistId']), this.str(raw['harness']), this.str(raw['sessionId']),\n this.str(raw['agentId']), this.str(raw['agentType']), this.str(raw['headSha']), this.str(raw['scopeHash']));\n record.writer = this.str(raw['writer']);\n record.status = this.str(raw['status']);\n record.verdictHash = this.str(raw['verdictHash']);\n record.writtenAt = this.str(raw['writtenAt']);\n record.round = typeof raw['round'] === 'number' && Number.isInteger(raw['round']) ? raw['round'] as number : 0;\n return record;\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n return null;\n }\n }\n\n /**\n * How one parsed verdict stands. `currentScopeHash` is this checklist's scope hash NOW ('' when it\n * could not be computed, which never marks anything stale).\n */\n // eslint-disable-next-line @typescript-eslint/max-params\n assess(summaryPath: string, result: ChecklistResult, currentScopeHash: string): VerdictStanding {\n const id = result.id;\n const record = this.read(summaryPath, id);\n const reject = (reason: string): VerdictStanding => new VerdictStanding(id, STANDING_REJECTED, result.status, '', reason);\n if (record === null) {\n const file = this.provenancePath(summaryPath, id);\n const why = fs.existsSync(file) ? `${path.basename(file)} is unreadable` : `no ${path.basename(file)}`;\n return reject(`review-${id}.json was not submitted through pnpm ${WRITE_REVIEW_BIN} (${why}) — a hand-written verdict is not a review`);\n }\n if (record.writer !== WRITE_REVIEW_BIN || record.checklistId !== id) {\n return reject(`review-${id}.provenance.json was not written by ${WRITE_REVIEW_BIN} for this checklist`);\n }\n if (record.agentId.trim() === '' && record.harness !== HARNESS_TERMINAL) {\n return reject(`review-${id}.json was submitted by the coordinating agent, not a reviewer subagent`);\n }\n const submitted = new SubmittedVerdict(id, result.status, result.agent, result.model, result.output);\n if (this.canonicalHash(submitted) !== record.verdictHash) {\n return reject(`review-${id}.json was EDITED after ${WRITE_REVIEW_BIN} wrote it — a verdict is the reviewer's words, not a draft`);\n }\n if (currentScopeHash !== '' && record.scopeHash !== currentScopeHash) {\n return new VerdictStanding(id, STANDING_STALE, result.status, record.headSha,\n `in-scope files CHANGED since the verdict was written at ${this.short(record.headSha)}`);\n }\n return new VerdictStanding(id, STANDING_CURRENT, result.status, record.headSha,\n `in-scope files unchanged since ${this.short(record.headSha)}`);\n }\n\n /** The first 8 characters of a sha, the way every banner line prints one. */\n short(sha: string): string {\n return sha === '' ? '(unknown sha)' : sha.slice(0, 8);\n }\n\n // webpieces-disable no-any-unknown -- one opaque JSON value, narrowed to a string\n private str(value: unknown): string {\n return typeof value === 'string' ? value : '';\n }\n}\n"]}
1
+ {"version":3,"file":"verdict-provenance.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/verdict-provenance.ts"],"names":[],"mappings":";;;;AAAA,uDAAiC;AACjC,+CAAyB;AACzB,mDAA6B;AAC7B,0DAEiC;AACjC,yCAA2D;AAE3D,6GAA6G;AAChG,QAAA,gBAAgB,GAAG,UAAU,CAAC;AAE3C,MAAM,YAAY,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OAAO,CAAC,EAAE,CAAC,CAAC;QACjG,CAAC;QACD,OAAO,IAAI,eAAe,CAAC,EAAE,EAAE,wBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,EAC1E,kCAAkC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IACxE,CAAC;IAED,6EAA6E;IAC7E,KAAK,CAAC,GAAW;QACb,OAAO,GAAG,KAAK,EAAE,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC1D,CAAC;IAED,kFAAkF;IAC1E,GAAG,CAAC,KAAc;QACtB,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;IAClD,CAAC;CACJ,CAAA;AAnGY,4DAAwB;mCAAxB,wBAAwB;IADpC,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGG,gCAAiB;QACxB,yBAAU;GAHlC,wBAAwB,CAmGpC","sourcesContent":["import * as crypto from 'crypto';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport {\n AtomicFile, ChecklistResult, ReviewJsonService, WRITE_REVIEW_BIN, toError,\n} from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\n\n/** `harness` for a verdict submitted from a plain terminal — a HUMAN reviewer, with no AI harness at all. */\nexport const HARNESS_TERMINAL = 'terminal';\n\nconst WHAT_THIS_IS =\n 'PROVENANCE — written by pnpm wp-write-review beside the verdict it submitted, never by an AI. It records ' +\n 'WHO submitted that verdict (harness, session, agent — as the harness reported them to the PreToolUse ' +\n 'hook), WHICH commit and in-scope diff the reviewer was briefed on, and a hash of the verdict itself. ' +\n 'wp-finish-upsert-pr rejects a verdict with no provenance, or one edited after submission. Do not ' +\n 'hand-edit or copy it: that is forging a review.';\n\n/** A verdict exactly as `wp-write-review` accepts it — the five fields and nothing else. Data-only. */\nexport class SubmittedVerdict {\n id: string;\n status: string;\n agent: string;\n model: string;\n output: string;\n\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(id: string, status: string, agent: string, model: string, output: string) {\n this.id = id;\n this.status = status;\n this.agent = agent;\n this.model = model;\n this.output = output;\n }\n}\n\n/**\n * The record `wp-write-review` writes to `review-round<N>-<id>.provenance.json`. Data-only; field names are\n * the JSON keys, `_WHAT_THIS_IS` first so a reader learns what the file is before anything it might act on.\n */\nexport class VerdictProvenance {\n // webpieces-disable naming-convention -- the leading underscore marks a note-to-the-reader key, not data\n _WHAT_THIS_IS = WHAT_THIS_IS;\n writer: string; // always WRITE_REVIEW_BIN — a record naming anything else was not written by it\n checklistId: string;\n harness: string; // 'claude-code' | 'codex' | HARNESS_TERMINAL\n sessionId: string;\n agentId: string; // the SUBAGENT that submitted; '' only for HARNESS_TERMINAL\n agentType: string;\n headSha: string; // the commit stage ② briefed this reviewer on\n scopeHash: string; // ChecklistScopeHasher's hash of this checklist's in-scope diff at that commit\n status: string; // the status as submitted\n verdictHash: string; // VerdictProvenanceService.canonicalHash of the verdict as submitted\n writtenAt: string;\n round: number; // the N of review-round<N>-<id>.json — which review round this verdict belongs to\n\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(checklistId: string, harness: string, sessionId: string, agentId: string, agentType: string, headSha: string, scopeHash: string) {\n this.writer = WRITE_REVIEW_BIN;\n this.checklistId = checklistId;\n this.harness = harness;\n this.sessionId = sessionId;\n this.agentId = agentId;\n this.agentType = agentType;\n this.headSha = headSha;\n this.scopeHash = scopeHash;\n this.status = '';\n this.verdictHash = '';\n this.writtenAt = '';\n this.round = 0;\n }\n}\n\n/** A live verdict that stands: submitted through the bin and judged the in-scope diff as it is NOW. */\nexport const STANDING_CURRENT = 'current';\n/** Submitted through the bin, but the checklist's in-scope diff has changed since — it judged other code. */\nexport const STANDING_STALE = 'stale';\n/** No bin provenance, or edited after submission: not a reviewer's verdict at all. */\nexport const STANDING_REJECTED = 'rejected';\n/**\n * Would be STALE, but still COUNTS: staleness never triggers a re-review (issue #1053) — a green, yellow or\n * orange verdict stands whatever round it came from — and a human override for its checklist always wins\n * (issue #1051). The reason says which, and is printed verbatim.\n */\nexport const STANDING_CARRIED = 'carried';\n\n/**\n * How ONE existing verdict file stands against the branch as it is now. Data-only. Carried on the\n * checklist scan so stage ② (which briefs) and stage ③ (which blocks) read one answer.\n */\nexport class VerdictStanding {\n checklistId: string;\n standing: string; // STANDING_CURRENT | STANDING_STALE | STANDING_REJECTED | STANDING_CARRIED\n status: string; // the verdict's own green | yellow | orange | red\n fromSha: string; // the commit it was briefed on ('' when rejected)\n reason: string; // why — printed verbatim\n\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(checklistId: string, standing: string, status: string, fromSha: string, reason: string) {\n this.checklistId = checklistId;\n this.standing = standing;\n this.status = status;\n this.fromSha = fromSha;\n this.reason = reason;\n }\n}\n\n/**\n * Writes a submitted verdict WITH its provenance, and judges an existing verdict against it (issue #863).\n *\n * This is what closes the forgery the issue measured: a Codex coordinator wrote five `review-<id>.json`\n * files itself and the gate accepted them, because nothing distinguished a reviewer's verdict from a file\n * that merely had the right shape. Now a verdict counts only when `wp-write-review` wrote it — which it does\n * only for a caller the harness identified as a subagent — and only while it still says exactly what was\n * submitted.\n *\n * `@injectable(bindingScopeValues.Singleton)` so it is injected by type and drawn in the DI design.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class VerdictProvenanceService {\n constructor(\n private readonly reviewJsonService: ReviewJsonService,\n private readonly atomicFile: AtomicFile,\n ) {}\n\n /** `review-round<N>-<id>.provenance.json`, beside the verdict of the same round. */\n provenancePath(summaryPath: string, checklistId: string, round: number): string {\n return path.join(path.dirname(summaryPath), `review-round${round}-${checklistId}.provenance.json`);\n }\n\n /**\n * sha256 over the five fields in a FIXED order, so formatting, key order and whitespace outside the\n * values cannot move it — only a change to what the verdict SAYS can.\n */\n canonicalHash(verdict: SubmittedVerdict): string {\n const canonical = JSON.stringify([verdict.id, verdict.status, verdict.agent, verdict.model, verdict.output]);\n return crypto.createHash('sha256').update(canonical).digest('hex');\n }\n\n /** Write the verdict, then its provenance, both for `provenance.round`. Returns the verdict path. */\n write(summaryPath: string, verdict: SubmittedVerdict, provenance: VerdictProvenance): string {\n const verdictPath = this.reviewJsonService.checklistResultPath(summaryPath, verdict.id, provenance.round);\n provenance.status = verdict.status;\n provenance.verdictHash = this.canonicalHash(verdict);\n provenance.writtenAt = new Date().toISOString();\n this.atomicFile.writeJsonAtomic(verdictPath, verdict);\n this.atomicFile.writeJsonAtomic(this.provenancePath(summaryPath, verdict.id, provenance.round), provenance);\n return verdictPath;\n }\n\n /** The provenance for one checklist's verdict in one round, or null when there is none (or it is unreadable). */\n read(summaryPath: string, checklistId: string, round: number): VerdictProvenance | null {\n const file = this.provenancePath(summaryPath, checklistId, round);\n if (!fs.existsSync(file)) return null;\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: an unreadable record is treated as no record, which REJECTS the verdict\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n // webpieces-disable no-any-unknown -- opaque parsed JSON, narrowed field-by-field below\n const raw = JSON.parse(fs.readFileSync(file, 'utf8')) as Record<string, unknown>;\n const record = new VerdictProvenance(\n this.str(raw['checklistId']), this.str(raw['harness']), this.str(raw['sessionId']),\n this.str(raw['agentId']), this.str(raw['agentType']), this.str(raw['headSha']), this.str(raw['scopeHash']));\n record.writer = this.str(raw['writer']);\n record.status = this.str(raw['status']);\n record.verdictHash = this.str(raw['verdictHash']);\n record.writtenAt = this.str(raw['writtenAt']);\n record.round = typeof raw['round'] === 'number' && Number.isInteger(raw['round']) ? raw['round'] as number : 0;\n return record;\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n return null;\n }\n }\n\n /**\n * How one parsed verdict stands. `currentScopeHash` is this checklist's scope hash NOW ('' when it\n * could not be computed, which never marks anything stale).\n */\n // eslint-disable-next-line @typescript-eslint/max-params\n assess(summaryPath: string, result: ChecklistResult, currentScopeHash: string): VerdictStanding {\n const id = result.id;\n const round = result.round;\n const verdictFile = path.basename(this.reviewJsonService.checklistResultPath(summaryPath, id, round));\n const record = this.read(summaryPath, id, round);\n const reject = (reason: string): VerdictStanding => new VerdictStanding(id, STANDING_REJECTED, result.status, '', reason);\n if (record === null) {\n const file = this.provenancePath(summaryPath, id, round);\n const why = fs.existsSync(file) ? `${path.basename(file)} is unreadable` : `no ${path.basename(file)}`;\n return reject(`${verdictFile} was not submitted through pnpm ${WRITE_REVIEW_BIN} (${why}) — a hand-written verdict is not a review`);\n }\n if (record.writer !== WRITE_REVIEW_BIN || record.checklistId !== id || record.round !== round) {\n return reject(`${path.basename(this.provenancePath(summaryPath, id, round))} was not written by ${WRITE_REVIEW_BIN} for this checklist and round`);\n }\n if (record.agentId.trim() === '' && record.harness !== HARNESS_TERMINAL) {\n return reject(`${verdictFile} was submitted by the coordinating agent, not a reviewer subagent`);\n }\n const submitted = new SubmittedVerdict(id, result.status, result.agent, result.model, result.output);\n if (this.canonicalHash(submitted) !== record.verdictHash) {\n return reject(`${verdictFile} was EDITED after ${WRITE_REVIEW_BIN} wrote it — a verdict is the reviewer's words, not a draft`);\n }\n if (currentScopeHash !== '' && record.scopeHash !== currentScopeHash) {\n return new VerdictStanding(id, STANDING_STALE, result.status, record.headSha,\n `in-scope files CHANGED since the verdict was written at ${this.short(record.headSha)}`);\n }\n return new VerdictStanding(id, STANDING_CURRENT, result.status, record.headSha,\n `in-scope files unchanged since ${this.short(record.headSha)}`);\n }\n\n /** The first 8 characters of a sha, the way every banner line prints one. */\n short(sha: string): string {\n return sha === '' ? '(unknown sha)' : sha.slice(0, 8);\n }\n\n // webpieces-disable no-any-unknown -- one opaque JSON value, narrowed to a string\n private str(value: unknown): string {\n return typeof value === 'string' ? value : '';\n }\n}\n"]}