@webpieces/pr-gate 0.4.826 → 0.4.827

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
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ReviewRoundStateService = exports.ReviewRemediation = exports.RemediationResponse = exports.ReviewRoundPlan = exports.ROUND_ACTION_FINISH = exports.ROUND_ACTION_RECORD = exports.ROUND_ACTION_FIX = exports.ROUND_ACTION_RESUME = exports.ROUND_ACTION_REVIEW = void 0;
3
+ exports.ReviewRoundStateService = exports.ReviewRemediation = exports.RemediationResponse = exports.RoundSnapshot = exports.ReviewRoundPlan = exports.ROUND_ACTION_FINISH = exports.ROUND_ACTION_RECORD = exports.ROUND_ACTION_FIX = exports.ROUND_ACTION_RESUME = exports.ROUND_ACTION_REVIEW = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const fs = tslib_1.__importStar(require("fs"));
6
6
  const path = tslib_1.__importStar(require("path"));
@@ -14,6 +14,10 @@ exports.ROUND_ACTION_RESUME = 'resume';
14
14
  exports.ROUND_ACTION_FIX = 'fix';
15
15
  exports.ROUND_ACTION_RECORD = 'record';
16
16
  exports.ROUND_ACTION_FINISH = 'finish';
17
+ /** Every round-numbered file of a branch's review lives beside summary.json under this prefix (issue #1053). */
18
+ const ROUND_FILE = /^review-round(\d+)-(.+)\.json$/;
19
+ const FIXES_ID = 'fixes';
20
+ const PROVENANCE_SUFFIX = '.provenance';
17
21
  class ReviewRoundPlan {
18
22
  action;
19
23
  round;
@@ -21,16 +25,38 @@ class ReviewRoundPlan {
21
25
  basis;
22
26
  changedFiles;
23
27
  redChecklistIds;
24
- constructor(action, round, maxRounds, basis, changedFiles = [], redChecklistIds = []) {
28
+ /** The final round's ORANGE checklists — must-fix, never re-reviewed (issue #1053). */
29
+ orangeChecklistIds;
30
+ // eslint-disable-next-line @typescript-eslint/max-params
31
+ constructor(action, round, maxRounds, basis, changedFiles = [], redChecklistIds = [], orangeChecklistIds = []) {
25
32
  this.action = action;
26
33
  this.round = round;
27
34
  this.maxRounds = maxRounds;
28
35
  this.basis = basis;
29
36
  this.changedFiles = changedFiles;
30
37
  this.redChecklistIds = redChecklistIds;
38
+ this.orangeChecklistIds = orangeChecklistIds;
31
39
  }
32
40
  }
33
41
  exports.ReviewRoundPlan = ReviewRoundPlan;
42
+ /**
43
+ * Where a branch's review stands, DERIVED from the round-numbered files on disk plus the stage-② receipt
44
+ * (issue #1053). There is no separate round counter: `round` is the highest round any file or briefing
45
+ * names. Data-only.
46
+ */
47
+ class RoundSnapshot {
48
+ round; // 0 = no round has started
49
+ roster; // the checklists briefed in `round`
50
+ headSha; // the commit `round` was briefed on
51
+ complete; // every checklist on the roster has a verdict in `round`
52
+ constructor(round, roster, headSha, complete) {
53
+ this.round = round;
54
+ this.roster = roster;
55
+ this.headSha = headSha;
56
+ this.complete = complete;
57
+ }
58
+ }
59
+ exports.RoundSnapshot = RoundSnapshot;
34
60
  class RemediationResponse {
35
61
  checklistId;
36
62
  resolution;
@@ -42,6 +68,7 @@ class RemediationResponse {
42
68
  }
43
69
  }
44
70
  exports.RemediationResponse = RemediationResponse;
71
+ /** The author's recorded fixes for one completed round: `review-round<N>-fixes.json`. Data-only. */
45
72
  class ReviewRemediation {
46
73
  agent;
47
74
  model;
@@ -49,6 +76,7 @@ class ReviewRemediation {
49
76
  toHead;
50
77
  responses;
51
78
  writtenAt;
79
+ // eslint-disable-next-line @typescript-eslint/max-params
52
80
  constructor(agent, model, fromHead, toHead, responses) {
53
81
  this.agent = agent;
54
82
  this.model = model;
@@ -59,7 +87,20 @@ class ReviewRemediation {
59
87
  }
60
88
  }
61
89
  exports.ReviewRemediation = ReviewRemediation;
62
- /** Immutable per-round verdict history plus the author-remediation records between rounds. */
90
+ /**
91
+ * The reviewer rounds of one branch, read from their round-numbered files (issue #1053).
92
+ *
93
+ * `commands.pr-gate.maxReviewerRounds` is a HARD CEILING, not a quota: 1 round means 1 round. Three rules
94
+ * follow from it, and everything here exists to hold them:
95
+ *
96
+ * 1. Every verdict is `review-round<N>-<id>.json` (+ `.provenance.json`), every author fix record is
97
+ * `review-round<N>-fixes.json`, and nothing is ever overwritten. The live verdict of a checklist is its
98
+ * highest round; the round the branch is on is the highest round any file names.
99
+ * 2. A new round starts ONLY when the previous round has a RED and rounds remain, and it re-briefs only
100
+ * those reds. A green or yellow stands whatever changes afterwards — staleness never re-reviews.
101
+ * 3. The final round has no red. Its blocking color is ORANGE: the author fixes it best effort, records the
102
+ * fix, and ships with the finding and its claimed fix stamped on the dashboard.
103
+ */
63
104
  let ReviewRoundStateService = class ReviewRoundStateService {
64
105
  reviewJson;
65
106
  provenance;
@@ -69,93 +110,134 @@ let ReviewRoundStateService = class ReviewRoundStateService {
69
110
  this.provenance = provenance;
70
111
  this.atomicFile = atomicFile;
71
112
  }
72
- roundDir(summaryPath, round) {
73
- return path.join(path.dirname(summaryPath), 'rounds', String(round));
113
+ /** The author's recorded fixes for one round: `review-round<N>-fixes.json`, beside summary.json. */
114
+ fixesPath(summaryPath, round) {
115
+ return path.join(path.dirname(summaryPath), `review-round${round}-${FIXES_ID}.json`);
74
116
  }
75
- archiveVerdict(summaryPath, checklistId, round) {
76
- const dir = this.roundDir(summaryPath, round);
77
- fs.mkdirSync(dir, { recursive: true });
78
- fs.copyFileSync(this.reviewJson.checklistResultPath(summaryPath, checklistId), path.join(dir, `review-${checklistId}.json`));
79
- fs.copyFileSync(this.provenance.provenancePath(summaryPath, checklistId), path.join(dir, `review-${checklistId}.provenance.json`));
117
+ /** The highest round any round-numbered file names, or 0. */
118
+ highestRound(summaryPath) {
119
+ let highest = 0;
120
+ for (const name of this.roundFiles(summaryPath)) {
121
+ const match = ROUND_FILE.exec(name);
122
+ if (match !== null)
123
+ highest = Math.max(highest, Number(match[1]));
124
+ }
125
+ return highest;
80
126
  }
81
- roundComplete(summaryPath, receipt) {
82
- if (receipt.round < 1 || receipt.reviewersBriefed.length === 0)
83
- return false;
84
- return receipt.reviewersBriefed.every((id) => fs.existsSync(path.join(this.roundDir(summaryPath, receipt.round), `review-${id}.json`)));
127
+ /** Every checklist that has a verdict in ANY round on this branch. */
128
+ verdictChecklistIds(summaryPath) {
129
+ const ids = new Set();
130
+ for (const name of this.roundFiles(summaryPath)) {
131
+ const id = this.verdictIdOf(name);
132
+ if (id !== '')
133
+ ids.add(id);
134
+ }
135
+ return [...ids].sort();
85
136
  }
86
- /**
87
- * TRUE once the repository's reviewer-round budget is SPENT: the latest global round is complete and it
88
- * was the last one `maxReviewerRounds` allows. From then on {@link plan} never briefs a reviewer again,
89
- * so nothing downstream may demand one either (issue #1051) — with `maxReviewerRounds: 1` that is what
90
- * "review → fix → submit" means. The scan uses it to CARRY every non-red verdict forward instead of
91
- * marking it STALE, whatever changes afterwards (remediation commits, summary edits, gate re-runs).
92
- */
93
- capSpent(summaryPath, receipt, maxRounds) {
94
- return receipt !== null && receipt.round >= maxRounds && this.roundComplete(summaryPath, receipt);
137
+ /** Where the branch's review stands — see {@link RoundSnapshot}. */
138
+ snapshot(summaryPath, receipt) {
139
+ const briefed = receipt !== null && receipt.reviewersBriefed.length > 0 ? receipt.round : 0;
140
+ const round = Math.max(this.highestRound(summaryPath), briefed);
141
+ if (round < 1)
142
+ return new RoundSnapshot(0, [], '', false);
143
+ if (receipt !== null && receipt.round === round) {
144
+ return new RoundSnapshot(round, receipt.reviewersBriefed.slice(), receipt.headSha, this.everyVerdictIn(summaryPath, receipt.reviewersBriefed, round));
145
+ }
146
+ // The receipt names an older round (or is gone): the files are the record, so the roster is exactly
147
+ // the checklists that have a verdict in this round, and the reviewed HEAD is what their provenance says.
148
+ const roster = this.roundFiles(summaryPath)
149
+ .filter((name) => name.startsWith(`review-round${round}-`))
150
+ .map((name) => this.verdictIdOf(name))
151
+ .filter((id) => id !== '')
152
+ .sort();
153
+ const headSha = roster.length === 0 ? '' : this.provenance.read(summaryPath, roster[0], round)?.headSha ?? '';
154
+ return new RoundSnapshot(round, roster, headSha, roster.length > 0);
95
155
  }
96
156
  /**
97
- * How many times ONE checklist has been reviewed on this branch: the global rounds 1..`throughRound` whose
98
- * immutable snapshot holds a verdict for it (`wp-write-review` archives every submission there). A
99
- * re-submission inside one round overwrites that round's snapshot, so it is one review, not two.
157
+ * TRUE once a review round has started on this branch. From then on the checklist set is FROZEN (issue
158
+ * #1053): finish judges only the checklists that were briefed, never ones a later commit newly triggers.
100
159
  */
101
- reviewCount(summaryPath, checklistId, throughRound) {
102
- let count = 0;
103
- for (let round = 1; round <= throughRound; round++) {
104
- if (fs.existsSync(path.join(this.roundDir(summaryPath, round), `review-${checklistId}.json`)))
105
- count++;
106
- }
107
- return count;
160
+ roundStarted(summaryPath, receipt) {
161
+ return this.snapshot(summaryPath, receipt).round >= 1;
108
162
  }
109
- redChecklistIds(summaryPath, receipt) {
110
- if (!this.roundComplete(summaryPath, receipt))
163
+ /** The frozen checklist set: every checklist briefed in any round — see {@link roundStarted}. */
164
+ briefedChecklistIds(summaryPath, receipt) {
165
+ const ids = new Set(this.verdictChecklistIds(summaryPath));
166
+ if (receipt !== null && receipt.round >= 1)
167
+ for (const id of receipt.reviewersBriefed)
168
+ ids.add(id);
169
+ return [...ids].sort();
170
+ }
171
+ /** Does `checklistId` already have a verdict in `round`? A round's verdict is never overwritten. */
172
+ hasVerdict(summaryPath, checklistId, round) {
173
+ return fs.existsSync(this.reviewJson.checklistResultPath(summaryPath, checklistId, round));
174
+ }
175
+ /** The roster checklists whose verdict in the snapshot's round is `status`. */
176
+ checklistIdsWithStatus(summaryPath, snap, status) {
177
+ if (!snap.complete)
111
178
  return [];
112
- return receipt.reviewersBriefed.filter((id) => {
113
- const raw = this.readObject(path.join(this.roundDir(summaryPath, receipt.round), `review-${id}.json`));
114
- return raw !== null && raw['status'] === rules_config_1.VERDICT_RED;
179
+ return snap.roster.filter((id) => {
180
+ const raw = this.readObject(this.reviewJson.checklistResultPath(summaryPath, id, snap.round));
181
+ return raw !== null && raw['status'] === status;
115
182
  });
116
183
  }
117
- remediationPath(summaryPath, round) {
118
- return path.join(this.roundDir(summaryPath, round), 'review-fixes.json');
119
- }
184
+ /** What stage ② does next. See the class comment for the three rules it holds. */
120
185
  plan(repoRoot, summaryPath, receipt, maxRounds, fullBasis) {
121
- if (receipt === null || receipt.round < 1) {
186
+ const snap = this.snapshot(summaryPath, receipt);
187
+ if (snap.round < 1)
122
188
  return new ReviewRoundPlan(exports.ROUND_ACTION_REVIEW, 1, maxRounds, fullBasis);
123
- }
124
- if (!this.roundComplete(summaryPath, receipt)) {
125
- if (receipt.headSha !== fullBasis.headSha) {
126
- throw new rules_config_1.InformAiError(`Global reviewer round ${receipt.round} of ${maxRounds} is still active at `
127
- + `${receipt.headSha.slice(0, 8)}. Finish that fixed roster before changing the reviewed HEAD.`);
189
+ if (!snap.complete) {
190
+ if (snap.headSha !== fullBasis.headSha) {
191
+ throw new rules_config_1.InformAiError(`Reviewer round ${snap.round} of ${maxRounds} is still active at `
192
+ + `${snap.headSha.slice(0, 8)}. Finish that fixed roster before changing the reviewed HEAD.`);
128
193
  }
129
- return new ReviewRoundPlan(exports.ROUND_ACTION_RESUME, receipt.round, maxRounds, fullBasis);
194
+ return new ReviewRoundPlan(exports.ROUND_ACTION_RESUME, snap.round, maxRounds, fullBasis);
130
195
  }
131
- const reds = this.redChecklistIds(summaryPath, receipt);
132
- if (reds.length === 0)
133
- return new ReviewRoundPlan(exports.ROUND_ACTION_FINISH, receipt.round, maxRounds, fullBasis);
134
- if (receipt.headSha === fullBasis.headSha) {
135
- return new ReviewRoundPlan(exports.ROUND_ACTION_FIX, receipt.round, maxRounds, fullBasis, [], reds);
196
+ const reds = this.checklistIdsWithStatus(summaryPath, snap, rules_config_1.VERDICT_RED);
197
+ const oranges = this.checklistIdsWithStatus(summaryPath, snap, rules_config_1.VERDICT_ORANGE);
198
+ // No red, or no round left: nothing is ever re-reviewed. Oranges are the author's to fix and record.
199
+ if (reds.length === 0 || snap.round >= maxRounds) {
200
+ return new ReviewRoundPlan(exports.ROUND_ACTION_FINISH, snap.round, maxRounds, fullBasis, [], reds, oranges);
136
201
  }
137
- const remediation = this.validRemediation(repoRoot, summaryPath, receipt);
138
- if (remediation === null) {
139
- return new ReviewRoundPlan(exports.ROUND_ACTION_RECORD, receipt.round, maxRounds, fullBasis, [], reds);
202
+ if (snap.headSha === fullBasis.headSha) {
203
+ return new ReviewRoundPlan(exports.ROUND_ACTION_FIX, snap.round, maxRounds, fullBasis, [], reds, oranges);
140
204
  }
141
- if (receipt.round >= maxRounds) {
142
- return new ReviewRoundPlan(exports.ROUND_ACTION_FINISH, receipt.round, maxRounds, fullBasis, [], reds);
205
+ if (this.validFixes(repoRoot, summaryPath, snap) === null) {
206
+ return new ReviewRoundPlan(exports.ROUND_ACTION_RECORD, snap.round, maxRounds, fullBasis, [], reds, oranges);
143
207
  }
144
- const basis = new diff_basis_1.DiffBasis(receipt.headSha, fullBasis.headSha, false, [], `git diff ${receipt.headSha} ${fullBasis.headSha}`, `git diff ${receipt.headSha} ${fullBasis.headSha} -- <file>`, fullBasis.hashMainHead);
145
- const changed = this.git(repoRoot, ['diff', '--name-only', receipt.headSha, fullBasis.headSha])
208
+ const basis = new diff_basis_1.DiffBasis(snap.headSha, fullBasis.headSha, false, [], `git diff ${snap.headSha} ${fullBasis.headSha}`, `git diff ${snap.headSha} ${fullBasis.headSha} -- <file>`, fullBasis.hashMainHead);
209
+ const changed = this.git(repoRoot, ['diff', '--name-only', snap.headSha, fullBasis.headSha])
146
210
  .split('\n').filter((f) => f.trim() !== '');
147
- return new ReviewRoundPlan(exports.ROUND_ACTION_REVIEW, receipt.round + 1, maxRounds, basis, changed, reds);
211
+ return new ReviewRoundPlan(exports.ROUND_ACTION_REVIEW, snap.round + 1, maxRounds, basis, changed, reds, oranges);
148
212
  }
213
+ /**
214
+ * Record the author's fixes for the latest completed round — one response per RED (a round that is not
215
+ * the last) or ORANGE (the final round) — as `review-round<N>-fixes.json`.
216
+ *
217
+ * A record that still HOLDS is never overwritten. One that no longer holds — its `toHead` left HEAD's
218
+ * history, which every `wp-start-upsert-pr` squash-update does — is kept beside it as
219
+ * `review-round<N>-fixes.json.superseded-<k>` and a fresh record is written, so re-recording is always
220
+ * the way past a stale record and nothing is ever lost.
221
+ */
149
222
  writeRemediation(repoRoot, summaryPath, receipt, json) {
150
- if (!this.roundComplete(summaryPath, receipt)) {
223
+ const snap = this.snapshot(summaryPath, receipt);
224
+ if (!snap.complete) {
151
225
  throw new rules_config_1.InformAiError('wp-write-review-fixes: the active reviewer round is not complete yet.');
152
226
  }
227
+ const blocking = this.blockingIds(summaryPath, snap);
228
+ if (blocking.length === 0) {
229
+ throw new rules_config_1.InformAiError(`wp-write-review-fixes: round ${snap.round} has no red or orange verdict to fix.`);
230
+ }
231
+ const out = this.fixesPath(summaryPath, snap.round);
232
+ const holding = this.validFixes(repoRoot, summaryPath, snap);
233
+ if (holding !== null) {
234
+ throw new rules_config_1.InformAiError(`wp-write-review-fixes: the fixes for round ${snap.round} are already recorded in ${out}, and `
235
+ + `that record still holds (its fixed commit ${holding.toHead.slice(0, 8)} is in HEAD's history), so it is not `
236
+ + 'overwritten. Nothing more to record: re-run pnpm wp-review-upsert-pr, or pnpm wp-finish-upsert-pr after the last round.');
237
+ }
153
238
  this.assertClean(repoRoot);
154
239
  const currentHead = this.git(repoRoot, ['rev-parse', 'HEAD']);
155
- const reds = this.redChecklistIds(summaryPath, receipt);
156
- if (reds.length === 0)
157
- throw new rules_config_1.InformAiError('wp-write-review-fixes: the completed round has no red verdict to remediate.');
158
- if (currentHead === receipt.headSha || this.git(repoRoot, ['diff', '--name-only', receipt.headSha, currentHead]) === '') {
240
+ if (currentHead === snap.headSha || this.git(repoRoot, ['diff', '--name-only', snap.headSha, currentHead]) === '') {
159
241
  throw new rules_config_1.InformAiError('wp-write-review-fixes: remediation must contain a committed, non-empty delta after the reviewed HEAD.');
160
242
  }
161
243
  const raw = this.parseObject(json, 'wp-write-review-fixes: input must be one JSON object.');
@@ -163,66 +245,79 @@ let ReviewRoundStateService = class ReviewRoundStateService {
163
245
  const model = this.requiredText(raw, 'model');
164
246
  const responses = this.responses(raw['responses']);
165
247
  const ids = responses.map((r) => r.checklistId);
166
- const unknown = ids.filter((id) => !reds.includes(id));
167
- const missing = reds.filter((id) => !ids.includes(id));
248
+ const unknown = ids.filter((id) => !blocking.includes(id));
249
+ const missing = blocking.filter((id) => !ids.includes(id));
168
250
  if (unknown.length > 0 || missing.length > 0) {
169
- throw new rules_config_1.InformAiError(`wp-write-review-fixes: responses must cover exactly the red checklist(s). `
251
+ throw new rules_config_1.InformAiError(`wp-write-review-fixes: responses must cover exactly the red/orange checklist(s) of round ${snap.round}. `
170
252
  + `Unknown: ${unknown.join(', ') || '(none)'}. Missing: ${missing.join(', ') || '(none)'}.`);
171
253
  }
172
- const record = new ReviewRemediation(agent, model, receipt.headSha, currentHead, responses);
173
- const out = this.remediationPath(summaryPath, receipt.round);
174
- this.atomicFile.writeJsonAtomic(out, record);
254
+ this.supersede(out);
255
+ this.atomicFile.writeJsonAtomic(out, new ReviewRemediation(agent, model, snap.headSha, currentHead, responses));
175
256
  return out;
176
257
  }
177
- validRemediation(repoRoot, summaryPath, receipt) {
178
- const raw = this.readObject(this.remediationPath(summaryPath, receipt.round));
179
- if (raw === null)
258
+ /**
259
+ * Keep a record that no longer holds beside the new one, as `<file>.superseded-<k>` — a name no round
260
+ * scan reads, so it is history and never a live record.
261
+ */
262
+ supersede(file) {
263
+ if (!fs.existsSync(file))
264
+ return;
265
+ let k = 1;
266
+ while (fs.existsSync(`${file}.superseded-${k}`))
267
+ k++;
268
+ fs.renameSync(file, `${file}.superseded-${k}`);
269
+ }
270
+ /**
271
+ * The round's recorded fixes, or null when there are none that still hold: written from the reviewed
272
+ * HEAD, to a later commit that is still in HEAD's history, covering exactly the round's red/orange set.
273
+ */
274
+ validFixes(repoRoot, summaryPath, snap) {
275
+ const record = this.readFixes(repoRoot, summaryPath, snap.round);
276
+ if (record === null || record.fromHead !== snap.headSha)
180
277
  return null;
181
- const currentHead = this.git(repoRoot, ['rev-parse', 'HEAD']);
182
- const responses = this.responsesOrEmpty(raw['responses']);
183
- const reds = this.redChecklistIds(summaryPath, receipt);
184
- const ids = responses.map((r) => r.checklistId);
185
- if (this.text(raw['agent']) === '' || this.text(raw['model']) === ''
186
- || raw['fromHead'] !== receipt.headSha || raw['toHead'] !== currentHead
187
- || currentHead === receipt.headSha || reds.some((id) => !ids.includes(id))
188
- || ids.some((id) => !reds.includes(id)))
278
+ const blocking = this.blockingIds(summaryPath, snap);
279
+ const ids = record.responses.map((r) => r.checklistId);
280
+ if (blocking.some((id) => !ids.includes(id)) || ids.some((id) => !blocking.includes(id)))
189
281
  return null;
190
- return new ReviewRemediation(this.text(raw['agent']), this.text(raw['model']), receipt.headSha, currentHead, responses);
282
+ return record;
191
283
  }
192
- capRemediations(repoRoot, summaryPath, receipt, maxRounds) {
284
+ /**
285
+ * checklist id → the dashboard stamp for every ORANGE whose fix the author recorded (issue #1053):
286
+ * "orange at <fromHead>, author-fixed in <toHead>, not re-reviewed: <resolution>". An orange with no
287
+ * valid record is absent, and so still blocks.
288
+ */
289
+ orangeFixes(repoRoot, summaryPath, results) {
193
290
  const out = {};
194
- if (receipt === null || !this.capSpent(summaryPath, receipt, maxRounds))
195
- return out;
196
- const remediation = this.validRemediation(repoRoot, summaryPath, receipt);
197
- if (remediation === null)
198
- return out;
199
- for (const response of remediation.responses) {
200
- out[response.checklistId] = `Author-remediated after review cap; NOT re-reviewed. ${response.resolution} `
201
- + `(${remediation.fromHead.slice(0, 8)}..${remediation.toHead.slice(0, 8)})`;
291
+ for (const result of results) {
292
+ if (result.status !== rules_config_1.VERDICT_ORANGE || result.problem !== '')
293
+ continue;
294
+ const record = this.readFixes(repoRoot, summaryPath, result.round);
295
+ const response = record?.responses.find((r) => r.checklistId === result.id);
296
+ if (record === null || response === undefined)
297
+ continue;
298
+ out[result.id] = `orange at ${record.fromHead.slice(0, 8)}, author-fixed in ${record.toHead.slice(0, 8)}, `
299
+ + `not re-reviewed: ${response.resolution}`;
202
300
  }
203
301
  return out;
204
302
  }
205
- auditTrail(summaryPath, checklistId, receipt) {
206
- if (receipt === null || receipt.round < 1)
207
- return '';
303
+ auditTrail(summaryPath, checklistId, maxRounds) {
208
304
  const lines = [];
209
- for (let round = 1; round <= receipt.round; round++) {
210
- const dir = this.roundDir(summaryPath, round);
211
- const verdict = this.readObject(path.join(dir, `review-${checklistId}.json`));
212
- const record = this.readObject(path.join(dir, `review-${checklistId}.provenance.json`));
305
+ const highest = this.highestRound(summaryPath);
306
+ for (let round = 1; round <= highest; round++) {
307
+ const verdict = this.readObject(this.reviewJson.checklistResultPath(summaryPath, checklistId, round));
213
308
  if (verdict !== null) {
214
- lines.push(`#### Reviewer round ${round} of ${receipt.maxReviewerRounds}`);
215
- lines.push(`Reviewed SHA: ${this.text(record?.['headSha']) || '(unknown)'}`);
309
+ lines.push(`#### Reviewer round ${round} of ${maxRounds}`);
310
+ lines.push(`Reviewed SHA: ${this.provenance.read(summaryPath, checklistId, round)?.headSha || '(unknown)'}`);
216
311
  lines.push(`Status: ${this.text(verdict['status']).toUpperCase()}`);
217
312
  lines.push('', this.text(verdict['output']), '');
218
313
  }
219
- const remediation = this.readObject(this.remediationPath(summaryPath, round));
314
+ const remediation = this.readObject(this.fixesPath(summaryPath, round));
220
315
  if (remediation !== null && Array.isArray(remediation['responses'])) {
221
316
  const response = remediation['responses'].find((entry) => typeof entry === 'object' && entry !== null && !Array.isArray(entry)
222
317
  && entry['checklistId'] === checklistId);
223
318
  if (typeof response === 'object' && response !== null && !Array.isArray(response)) {
224
319
  const raw = response;
225
- lines.push(`#### Author remediation after round ${round}`);
320
+ lines.push(`#### Author fix after round ${round}`);
226
321
  lines.push(`Range: ${this.text(remediation['fromHead'])}..${this.text(remediation['toHead'])}`);
227
322
  lines.push('', this.text(raw['resolution']), '');
228
323
  }
@@ -230,6 +325,42 @@ let ReviewRoundStateService = class ReviewRoundStateService {
230
325
  }
231
326
  return lines.join('\n').trim();
232
327
  }
328
+ blockingIds(summaryPath, snap) {
329
+ return [
330
+ ...this.checklistIdsWithStatus(summaryPath, snap, rules_config_1.VERDICT_RED),
331
+ ...this.checklistIdsWithStatus(summaryPath, snap, rules_config_1.VERDICT_ORANGE),
332
+ ];
333
+ }
334
+ /** A round's fix record, provided its `toHead` is still in HEAD's history; else null. */
335
+ readFixes(repoRoot, summaryPath, round) {
336
+ const raw = this.readObject(this.fixesPath(summaryPath, round));
337
+ if (raw === null)
338
+ return null;
339
+ const responses = this.responsesOrEmpty(raw['responses']);
340
+ const fromHead = this.text(raw['fromHead']);
341
+ const toHead = this.text(raw['toHead']);
342
+ if (this.text(raw['agent']) === '' || this.text(raw['model']) === '' || responses.length === 0
343
+ || fromHead === '' || toHead === '' || fromHead === toHead || !this.isAncestorOfHead(repoRoot, toHead))
344
+ return null;
345
+ return new ReviewRemediation(this.text(raw['agent']), this.text(raw['model']), fromHead, toHead, responses);
346
+ }
347
+ everyVerdictIn(summaryPath, roster, round) {
348
+ return roster.length > 0 && roster.every((id) => this.hasVerdict(summaryPath, id, round));
349
+ }
350
+ /** `review-round<N>-<id>.json` → `<id>`; '' for the fixes record, a provenance file, or anything else. */
351
+ verdictIdOf(name) {
352
+ const match = ROUND_FILE.exec(name);
353
+ if (match === null)
354
+ return '';
355
+ const id = match[2];
356
+ return id === FIXES_ID || id.endsWith(PROVENANCE_SUFFIX) ? '' : id;
357
+ }
358
+ roundFiles(summaryPath) {
359
+ const dir = path.dirname(summaryPath);
360
+ if (!fs.existsSync(dir))
361
+ return [];
362
+ return fs.readdirSync(dir).filter((name) => ROUND_FILE.test(name));
363
+ }
233
364
  responses(value) {
234
365
  const responses = this.responsesOrEmpty(value);
235
366
  if (responses.length === 0)
@@ -301,6 +432,23 @@ let ReviewRoundStateService = class ReviewRoundStateService {
301
432
  if (status !== '')
302
433
  throw new rules_config_1.InformAiError('wp-write-review-fixes: commit every remediation and leave no staged, unstaged, or untracked files first.');
303
434
  }
435
+ /**
436
+ * `git merge-base --is-ancestor`: exit 0 = yes, 1 = no. A `sha` git does not know (exit 128 with
437
+ * "Not a valid commit name") is also no — the commit is gone from this clone, so it is not in HEAD's
438
+ * history. Anything else is a real failure and refuses.
439
+ */
440
+ isAncestorOfHead(repoRoot, sha) {
441
+ const result = (0, child_process_1.spawnSync)('git', ['merge-base', '--is-ancestor', sha, 'HEAD'], { cwd: repoRoot, encoding: 'utf8' });
442
+ if (result.status === 0)
443
+ return true;
444
+ if (result.status === 1 || /not a valid (commit|object) name/i.test(result.stderr ?? ''))
445
+ return false;
446
+ const detail = (result.stderr ?? '').trim() || result.error?.message || `exit ${result.status ?? 'unknown'}`;
447
+ const message = `Review-round Git command failed: git merge-base --is-ancestor ${sha} HEAD\n${detail}`;
448
+ if (result.error !== undefined)
449
+ throw new rules_config_1.InformAiError(message, { cause: result.error });
450
+ throw new rules_config_1.InformAiError(message);
451
+ }
304
452
  git(repoRoot, args) {
305
453
  const result = (0, child_process_1.spawnSync)('git', args, { cwd: repoRoot, encoding: 'utf8' });
306
454
  if (result.status === 0)