@webpieces/pr-gate 0.4.824 → 0.4.826

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 (33) hide show
  1. package/package.json +3 -3
  2. package/src/scripts/commands/await-reviews-command.js +1 -1
  3. package/src/scripts/commands/await-reviews-command.js.map +1 -1
  4. package/src/scripts/commands/finish-upsert-pr-command.js +16 -7
  5. package/src/scripts/commands/finish-upsert-pr-command.js.map +1 -1
  6. package/src/scripts/commands/review-upsert-pr-command.js +1 -1
  7. package/src/scripts/commands/review-upsert-pr-command.js.map +1 -1
  8. package/src/scripts/commands/write-review-command.d.ts +23 -1
  9. package/src/scripts/commands/write-review-command.js +48 -2
  10. package/src/scripts/commands/write-review-command.js.map +1 -1
  11. package/src/scripts/commands/write-review-fixes-command.js +3 -0
  12. package/src/scripts/commands/write-review-fixes-command.js.map +1 -1
  13. package/src/scripts/pr-gate-app.d.ts +3 -1
  14. package/src/scripts/pr-gate-app.js +4 -0
  15. package/src/scripts/pr-gate-app.js.map +1 -1
  16. package/src/scripts/workflow/checklist-scanner.d.ts +29 -3
  17. package/src/scripts/workflow/checklist-scanner.js +51 -5
  18. package/src/scripts/workflow/checklist-scanner.js.map +1 -1
  19. package/src/scripts/workflow/hotfix-finish-preparer.js +1 -1
  20. package/src/scripts/workflow/hotfix-finish-preparer.js.map +1 -1
  21. package/src/scripts/workflow/review-report.js +4 -0
  22. package/src/scripts/workflow/review-report.js.map +1 -1
  23. package/src/scripts/workflow/review-round-state.d.ts +14 -0
  24. package/src/scripts/workflow/review-round-state.js +24 -1
  25. package/src/scripts/workflow/review-round-state.js.map +1 -1
  26. package/src/scripts/workflow/review-stage-receipt.d.ts +14 -1
  27. package/src/scripts/workflow/review-stage-receipt.js +21 -1
  28. package/src/scripts/workflow/review-stage-receipt.js.map +1 -1
  29. package/src/scripts/workflow/verdict-provenance.d.ts +6 -0
  30. package/src/scripts/workflow/verdict-provenance.js +8 -2
  31. package/src/scripts/workflow/verdict-provenance.js.map +1 -1
  32. package/src/scripts/wp-write-review.js +7 -0
  33. package/src/scripts/wp-write-review.js.map +1 -1
@@ -10,6 +10,8 @@ const diff_basis_1 = require("./diff-basis");
10
10
  const pr_context_writer_1 = require("./pr-context-writer");
11
11
  const checklist_scope_hasher_1 = require("./checklist-scope-hasher");
12
12
  const verdict_provenance_1 = require("./verdict-provenance");
13
+ const review_stage_receipt_1 = require("./review-stage-receipt");
14
+ const review_round_state_1 = require("./review-round-state");
13
15
  /** How a caller wants the scan filtered. Data-only (per CLAUDE.md). */
14
16
  class ChecklistScanOptions {
15
17
  /**
@@ -32,7 +34,14 @@ class ChecklistScanOptions {
32
34
  * visible act by a caller that takes responsibility for writing it later — not an omission.
33
35
  */
34
36
  contextStage;
35
- constructor(filterAlreadyReviewed = false, contextStage = 'stage-scan') {
37
+ /**
38
+ * `commands.pr-gate.maxReviewerRounds`, as the caller's validated config states it. REQUIRED and first:
39
+ * once the budget is spent a STALE green or yellow is CARRIED rather than owed (issue #1051), so a scan
40
+ * that did not know the budget would demand a review round the gate will never brief.
41
+ */
42
+ maxReviewerRounds;
43
+ constructor(maxReviewerRounds, filterAlreadyReviewed = false, contextStage = 'stage-scan') {
44
+ this.maxReviewerRounds = maxReviewerRounds;
36
45
  this.filterAlreadyReviewed = filterAlreadyReviewed;
37
46
  this.contextStage = contextStage;
38
47
  }
@@ -121,7 +130,9 @@ class ChecklistScan {
121
130
  * its checklist's in-scope diff is unchanged — it carries), STALE (in-scope diff changed since — re-brief)
122
131
  * or REJECTED (no bin provenance, or edited after submission — it is not a review). A REJECTED verdict,
123
132
  * and a STALE green or yellow one, is left OUT of `results`, so it is owed like one that never ran; a
124
- * stale RED stays in `results` and keeps refusing. Empty under suppression.
133
+ * stale RED stays in `results` and keeps refusing. CARRIED (issue #1051) is a green or yellow that would
134
+ * be STALE but still counts — the reviewer-round budget is spent, or a human override for it stands.
135
+ * Empty under suppression.
125
136
  */
126
137
  standings;
127
138
  /** checklist id → ChecklistScopeHasher's hash of its in-scope diff NOW. Recorded in the stage-② receipt. */
@@ -187,10 +198,12 @@ let ChecklistScanner = class ChecklistScanner {
187
198
  homeConfig;
188
199
  scopeHasher;
189
200
  verdictProvenance;
201
+ receipts;
202
+ rounds;
190
203
  constructor(aiBranchName, checklistDetector, diffScope, diffBasisResolver, prContextWriter, reviewJsonService,
191
204
  // Injected BY TYPE (no Symbol token, per CLAUDE.md) so the ONE reviewer kill switch is read in the
192
205
  // ONE place that computes what a branch owes — see the suppression note on `scan`.
193
- homeConfig, scopeHasher, verdictProvenance) {
206
+ homeConfig, scopeHasher, verdictProvenance, receipts, rounds) {
194
207
  this.aiBranchName = aiBranchName;
195
208
  this.checklistDetector = checklistDetector;
196
209
  this.diffScope = diffScope;
@@ -200,6 +213,8 @@ let ChecklistScanner = class ChecklistScanner {
200
213
  this.homeConfig = homeConfig;
201
214
  this.scopeHasher = scopeHasher;
202
215
  this.verdictProvenance = verdictProvenance;
216
+ this.receipts = receipts;
217
+ this.rounds = rounds;
203
218
  }
204
219
  /**
205
220
  * `defined` is the caller's ALREADY-VALIDATED `prGate.checklists`. The scanner deliberately does not load
@@ -238,7 +253,9 @@ let ChecklistScanner = class ChecklistScanner {
238
253
  const applicable = matched;
239
254
  const scopeHashes = this.scopeHasher.hashes(repoRoot, basis, applicable);
240
255
  const loaded = this.reviewJsonService.loadChecklistResults(summaryPath, applicable);
241
- const standings = this.standingsOf(summaryPath, loaded, scopeHashes);
256
+ const capSpent = this.rounds.capSpent(summaryPath, this.receipts.read(repoRoot, featureName), opts.maxReviewerRounds);
257
+ const standings = this.standingsOf(summaryPath, loaded, scopeHashes)
258
+ .map((s) => this.carried(s, loaded, capSpent, opts.maxReviewerRounds));
242
259
  const results = this.liveResults(loaded, standings);
243
260
  const stillOwed = this.reviewJsonService.pendingChecklists(applicable, results);
244
261
  const owedIds = new Set(stillOwed.map((r) => r.id));
@@ -262,6 +279,33 @@ let ChecklistScanner = class ChecklistScanner {
262
279
  .filter((r) => r.problem === '')
263
280
  .map((r) => this.verdictProvenance.assess(summaryPath, r, scopeHashes[r.id] ?? ''));
264
281
  }
282
+ /**
283
+ * A STALE green or yellow that must NOT be owed again (issue #1051), re-stood as CARRIED with the reason.
284
+ *
285
+ * 1. A human override for the checklist stands. Staleness is judged BEFORE the verdict is resolved, so
286
+ * without this a stale verdict read as "never ran" and the override written for it was never looked
287
+ * at — the human's in-session decision was shadowed by a hash comparison.
288
+ * 2. The reviewer-round budget is spent. The round planner never briefs a reviewer again, so a stale
289
+ * verdict demanded here is a review nobody can ever supply: with `maxReviewerRounds: 1`, the author's
290
+ * remediation commit marked every OTHER checklist stale and the branch could not be finished.
291
+ *
292
+ * A RED is never carried here: it keeps refusing until a fresh verdict, a recorded author remediation
293
+ * after the cap, or a human override clears it. A REJECTED verdict is never carried: it is not a review.
294
+ */
295
+ // eslint-disable-next-line @typescript-eslint/max-params
296
+ carried(s, loaded, capSpent, maxRounds) {
297
+ if (s.standing !== verdict_provenance_1.STANDING_STALE || s.status === rules_config_1.VERDICT_RED)
298
+ return s;
299
+ const result = loaded.find((r) => r.id === s.checklistId);
300
+ const override = result?.override ?? null;
301
+ if (override !== null && override.problem === '') {
302
+ return new verdict_provenance_1.VerdictStanding(s.checklistId, verdict_provenance_1.STANDING_CARRIED, s.status, s.fromSha, `${s.reason}, but a human override (authorized by ${override.authorizedBy}) stands — the verdict counts`);
303
+ }
304
+ if (!capSpent)
305
+ return s;
306
+ return new verdict_provenance_1.VerdictStanding(s.checklistId, verdict_provenance_1.STANDING_CARRIED, s.status, s.fromSha, `${s.reason}; CARRIED FORWARD without re-review — all ${maxRounds} reviewer round(s) are spent, `
307
+ + 'so no further round runs on this branch');
308
+ }
265
309
  /**
266
310
  * The verdicts that still COUNT. A rejected one never does. A stale green or yellow judged code that
267
311
  * has since changed, so it is owed again; a stale RED still refuses — a refusal is not lifted by
@@ -318,6 +362,8 @@ exports.ChecklistScanner = ChecklistScanner = tslib_1.__decorate([
318
362
  rules_config_1.ReviewJsonService,
319
363
  rules_config_1.HomeConfigService,
320
364
  checklist_scope_hasher_1.ChecklistScopeHasher,
321
- verdict_provenance_1.VerdictProvenanceService])
365
+ verdict_provenance_1.VerdictProvenanceService,
366
+ review_stage_receipt_1.ReviewStageReceiptService,
367
+ review_round_state_1.ReviewRoundStateService])
322
368
  ], ChecklistScanner);
323
369
  //# sourceMappingURL=checklist-scanner.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"checklist-scanner.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/checklist-scanner.ts"],"names":[],"mappings":";;;;AAAA,0DAGiC;AACjC,yCAA2D;AAC3D,iEAAsD;AACtD,6DAA0E;AAC1E,6CAA4D;AAC5D,2DAAsD;AACtD,qEAAgE;AAChE,6DAE8B;AAE9B,uEAAuE;AACvE,MAAa,oBAAoB;IAC7B;;;;OAIG;IACH,qBAAqB,CAAU;IAC/B;;;;;;;;;;;;OAYG;IACH,YAAY,CAAS;IAErB,YAAY,qBAAqB,GAAG,KAAK,EAAE,YAAY,GAAG,YAAY;QAClE,IAAI,CAAC,qBAAqB,GAAG,qBAAqB,CAAC;QACnD,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACrC,CAAC;CACJ;AA1BD,oDA0BC;AAED;;;;;;GAMG;AACH,MAAa,aAAa;IACtB,OAAO,CAAwB,CAAM,IAAI;IACzC,UAAU,CAAsB,CAAK,IAAI;IACzC,QAAQ,CAAsB,CAAO,mEAAmE;IACxG,WAAW,CAAsB,CAAI,uCAAuC;IAC5E,OAAO,CAAyB,CAAK,wCAAwC;IAC7E,WAAW,CAAS,CAAkB,yDAAyD;IAC/F,SAAS,CAAS,CAAmB,iCAAiC;IACtE,wGAAwG;IACxG,+FAA+F;IAC/F,6EAA6E;IAC7E,MAAM,CAAkB;IACxB,qGAAqG;IACrG,qGAAqG;IACrG,4EAA4E;IAC5E,YAAY,CAAW;IACvB;;;;OAIG;IACH,KAAK,CAA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CAAC;QACpF,OAAO,SAAS,CAAC,MAAM,CAAC,CAAC,CAAoB,EAAW,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACnF,CAAC;IAED;;;;;;;;;OASG;IACK,YAAY,CAAC,QAAgB,EAAE,IAAY;QAC/C,IAAI,IAAI,KAAK,EAAE;YAAE,OAAO,EAAE,CAAC;QAC3B,MAAM,IAAI,GAAG,IAAI,kCAAmB,EAAE,CAAC;QACvC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC;QAC7B,oFAAoF;QACpF,OAAO,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;IAC3E,CAAC;CACJ,CAAA;AAlJY,4CAAgB;2BAAhB,gBAAgB;IAD5B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGF,mCAAY;QACP,sCAAiB;QACzB,wBAAS;QACD,8BAAiB;QACnB,mCAAe;QACb,gCAAiB;QAGxB,gCAAiB;QAChB,6CAAoB;QACd,6CAAwB;GAZvD,gBAAgB,CAkJ5B","sourcesContent":["import {\n ChangedFilesOptions, ChecklistDefinition, ChecklistResult, ChecklistReviewContext, DiffScope,\n HomeConfigService, RequiredChecklist, ReviewJsonService, VERDICT_RED, summaryJsonPath,\n} from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { AiBranchName } from './git-readAiBranchName';\nimport { ChecklistDetector, ChecklistRoster } from './checklist-detector';\nimport { DiffBasis, DiffBasisResolver } from './diff-basis';\nimport { PrContextWriter } from './pr-context-writer';\nimport { ChecklistScopeHasher } from './checklist-scope-hasher';\nimport {\n STANDING_REJECTED, STANDING_STALE, VerdictProvenanceService, VerdictStanding,\n} from './verdict-provenance';\n\n/** How a caller wants the scan filtered. Data-only (per CLAUDE.md). */\nexport class ChecklistScanOptions {\n /**\n * false — `outstanding` is every applicable checklist (what `wp-review-upsert-pr` LISTS).\n * true — `outstanding` drops the ones already carrying a passing/overridden verdict, leaving only what\n * still owes review (what `wp-finish-upsert-pr` BLOCKS on).\n */\n filterAlreadyReviewed: boolean;\n /**\n * Which per-stage snapshot this scan should persist ('stage3-finish', …), or '' for \"do not write\n * pr-context.json here\".\n *\n * '' exists for stage ②, which cannot write yet: the context records `diffDir`, and the diff has not\n * been materialized at scan time. Letting the scan write anyway meant stage ② wrote the file twice,\n * ~60 lines apart, the first time with an empty diffDir. Now it writes once, after materializing.\n *\n * The DEFAULT is deliberately non-empty, so writing is what you get by NOT thinking about it. A\n * reviewer block that lost its diff command because nobody had written pr-context.json is a bug this\n * codebase has already shipped once (see PrContextWriter's docstring); opting out must be an explicit,\n * visible act by a caller that takes responsibility for writing it later — not an omission.\n */\n contextStage: string;\n\n constructor(filterAlreadyReviewed = false, contextStage = 'stage-scan') {\n this.filterAlreadyReviewed = filterAlreadyReviewed;\n this.contextStage = contextStage;\n }\n}\n\n/**\n * The answer to \"what review does this branch owe?\", in the X → N → Z terms the commands report:\n * X = `defined` — every checklist in pr-gate.checklists\n * N = `applicable` — those whose patterns matched (or that have no patterns, so always run)\n * Z = `outstanding` — of N, those still owing a verdict (only when filterAlreadyReviewed)\n * Data-only.\n */\nexport class ChecklistScan {\n defined: ChecklistDefinition[]; // X\n applicable: RequiredChecklist[]; // N\n reviewed: RequiredChecklist[]; // N − Z: already have a passing/warned/overridden review-<id>.json\n outstanding: RequiredChecklist[]; // Z (== applicable when not filtering)\n context: ChecklistReviewContext; // fork-point sha + pr-context.json path\n summaryPath: string; // the branch's summary.json; verdict files sit beside it\n forkPoint: string; // '' when no fork point resolved\n // ALL X, matched or not, with why — what the PR comment publishes as its roster. Skipped checklists are\n // absent from `applicable` by construction, and recovering them downstream would mean a second\n // changed-file computation with different semantics (see the class comment).\n roster: ChecklistRoster;\n // Verdict files that exist but cannot be read as a verdict (e.g. still using the removed `success`).\n // Carried on the SCAN because wp-finish-upsert-pr refuses on missing reviewers before it ever parses\n // summary.json — a complaint raised only in there would never reach the AI.\n formatErrors: string[];\n /**\n * The basis the matching ACTUALLY ran against. Carried out so a caller that materializes the diff\n * (stage ②) reuses the identical range instead of resolving its own — two independent resolutions is\n * exactly how the changed-file set and the printed `git diff` command came to disagree.\n */\n basis: DiffBasis;\n changedFiles: string[]; // the full changed-file set the matching ran against\n /**\n * The verdict files the scan ALREADY read, carried out rather than dropped.\n *\n * `outstanding` answers \"who still owes a verdict?\" but not \"why\" — and the two reasons demand opposite\n * actions from the reader: a reviewer that never ran must be SPAWNED, a reviewer that ran and REFUSED\n * must not be (it will refuse again; the finding has to be fixed first). Telling them apart means\n * resolving each checklist's verdict, and without the results here every caller either re-reads the same\n * files off disk — a second read that can disagree with this one — or merges the two cases into one\n * message, which is exactly the loop this field exists to break.\n */\n results: ChecklistResult[];\n /**\n * The OPTIONAL (`required: false`) applicable checklists carrying no verdict file — i.e. nobody ran them.\n *\n * Deliberately NOT in `outstanding` when filtering: that is the exemption that makes `required: false`\n * mean something. Carried out as its own set rather than merely subtracted, because both readers need it\n * BY NAME and neither can recover it from what is left: stage ② offers exactly these to the human, and\n * the PR dashboard must publish them as \"not run\" rather than let a shorter roster imply everything\n * passed. An optional checklist that ran and went RED is absent from here and stays in `outstanding`.\n */\n optionalNotRun: RequiredChecklist[];\n /**\n * TRUE when either this machine's `experimental.turnOffAllReviewers` switch is on or the project sets\n * `commands.pr-gate.reviewerAgents: 0`, and therefore when `applicable`, `reviewed`,\n * `outstanding`, `results`, `optionalNotRun` and `formatErrors` above are ALL EMPTY BY DECREE rather\n * than because nothing matched. Those two states are indistinguishable from the empty lists alone,\n * and telling them apart is the entire reason this field exists: an unreviewed PR must never render\n * as a reviewed one.\n *\n * `defined`, `roster`, `basis`, `changedFiles` and `context` are deliberately left INTACT under\n * suppression, so every reader can still say WHAT was switched off — including which REQUIRED\n * checklists would otherwise have run.\n *\n * See `HOME_KEY_TURN_OFF_ALL_REVIEWERS` in rules-config for the flag's contract; it is an\n * `experimental.*` flag, so only a human ever ends it.\n */\n reviewersDisabled: boolean;\n /**\n * The checklists that WOULD have been `applicable` had the reviewers not been suppressed — required\n * ones included. EMPTY on every ordinary run, and empty is not ambiguous there because\n * `reviewersDisabled` is false.\n *\n * Carried by NAME and not as a count because every reader needs a different slice of it: stage ②\n * prints them so a human can see exactly which required reviewer was killed, the dashboard names them\n * in the 1st comment, and the compact PR body needs only `.length`. Recomputing any of that\n * downstream would mean a second changed-file computation that can disagree with this one.\n */\n suppressed: RequiredChecklist[];\n /**\n * How every EXISTING verdict file stands (issue #863): CURRENT (submitted through `wp-write-review` and\n * its checklist's in-scope diff is unchanged — it carries), STALE (in-scope diff changed since — re-brief)\n * or REJECTED (no bin provenance, or edited after submission — it is not a review). A REJECTED verdict,\n * and a STALE green or yellow one, is left OUT of `results`, so it is owed like one that never ran; a\n * stale RED stays in `results` and keeps refusing. Empty under suppression.\n */\n standings: VerdictStanding[];\n /** checklist id → ChecklistScopeHasher's hash of its in-scope diff NOW. Recorded in the stage-② receipt. */\n scopeHashes: Record<string, string>;\n\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(\n defined: ChecklistDefinition[],\n applicable: RequiredChecklist[],\n reviewed: RequiredChecklist[],\n outstanding: RequiredChecklist[],\n context: ChecklistReviewContext,\n summaryPath: string,\n forkPoint: string,\n roster: ChecklistRoster,\n formatErrors: string[],\n // REQUIRED, and placed BEFORE the defaulted tail deliberately. A defaulted `reviewersDisabled =\n // false` would let every existing construction keep compiling while asserting, silently, that no\n // reviewer was switched off — the widening-by-omission `.claude/rules/no-backwards-compat.md`\n // rejects, and on the one field whose whole job is to stop an unreviewed PR reading as reviewed.\n reviewersDisabled: boolean,\n suppressed: RequiredChecklist[],\n basis: DiffBasis = new DiffBasis(),\n changedFiles: string[] = [],\n // Defaulted so a caller that only cares about the X/N/Z counts (and every existing test construction)\n // stays a one-liner; the scanner itself always passes the real set.\n results: ChecklistResult[] = [],\n optionalNotRun: RequiredChecklist[] = [],\n ) {\n this.defined = defined;\n this.applicable = applicable;\n this.reviewed = reviewed;\n this.outstanding = outstanding;\n this.context = context;\n this.summaryPath = summaryPath;\n this.forkPoint = forkPoint;\n this.roster = roster;\n this.formatErrors = formatErrors;\n this.reviewersDisabled = reviewersDisabled;\n this.suppressed = suppressed;\n this.basis = basis;\n this.changedFiles = changedFiles;\n this.results = results;\n this.optionalNotRun = optionalNotRun;\n this.standings = [];\n this.scopeHashes = {};\n }\n}\n\n/**\n * The ONE computation of which reviewer subagents a branch owes, shared by `wp-review-upsert-pr` (which lists) and\n * `wp-finish-upsert-pr` (which blocks). They previously each assembled this from the same parts in slightly\n * different ways, and any divergence means the command that reports and the command that gates disagree.\n *\n * Two properties are deliberate and load-bearing:\n *\n * 1. **The base is the FORK POINT of main, computed directly** — never `DiffScope.resolveBase`, which\n * overlays `NX_BASE`/`NX_HEAD` from the environment. That made review coverage depend on an env var.\n * It now arrives via {@link DiffBasisResolver}, which injects ForkPoint; same sha, one resolution.\n * 2. **UNCOMMITTED work counts.** `getChangedFiles` is called with NO head, which is the branch of it that\n * diffs base → WORKING TREE and unions in untracked files. Passing a head would diff commit-to-commit and\n * silently miss staged, unstaged and untracked changes — so a checklist matching only uncommitted files\n * would never fire and its reviewer would never be listed.\n * 3. **The range and the command it prints are the SAME basis.** Property 2 used to be true of the file set\n * only: reviewers were handed `git diff <base> HEAD`, which on a dirty tree covers a different range and\n * prints nothing. Both now derive from one {@link DiffBasis}, carried on the scan so a materializing\n * caller cannot re-resolve and drift.\n *\n * `@injectable(bindingScopeValues.Singleton)` so it is injected by type and drawn in the DI design.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class ChecklistScanner {\n constructor(\n private readonly aiBranchName: AiBranchName,\n private readonly checklistDetector: ChecklistDetector,\n private readonly diffScope: DiffScope,\n private readonly diffBasisResolver: DiffBasisResolver,\n private readonly prContextWriter: PrContextWriter,\n private readonly reviewJsonService: ReviewJsonService,\n // Injected BY TYPE (no Symbol token, per CLAUDE.md) so the ONE reviewer kill switch is read in the\n // ONE place that computes what a branch owes — see the suppression note on `scan`.\n private readonly homeConfig: HomeConfigService,\n private readonly scopeHasher: ChecklistScopeHasher,\n private readonly verdictProvenance: VerdictProvenanceService,\n ) {}\n\n /**\n * `defined` is the caller's ALREADY-VALIDATED `prGate.checklists`. The scanner deliberately does not load\n * config itself: `loadAndValidate` is the one gate on the checklist set (it rejects a non-array\n * `checklists`, including the removed `{ doc }` manifest shape, and verifies every guidance doc and\n * reviewer-agent file exists), both callers already run it for other fields, and keeping the read out of\n * here leaves this a function of its inputs rather than of the filesystem.\n */\n scan(repoRoot: string, defined: ChecklistDefinition[], opts: ChecklistScanOptions): ChecklistScan {\n const featureName = this.aiBranchName.getFeatureName();\n const summaryPath = summaryJsonPath(repoRoot, featureName);\n // ONE basis for the file set, the reproduce command and any downstream materialization. The fork\n // point still comes from ForkPoint (never DiffScope.resolveBase) — DiffBasisResolver injects it.\n const basis = this.diffBasisResolver.resolve(repoRoot);\n const base = basis.base;\n // ONE changed-file computation feeds both the roster (all X) and the applicable set (N). `detect` is\n // pure and defined as the roster minus its empty entries, so the two cannot disagree about a match.\n const changedFiles = this.changedFiles(repoRoot, base);\n const roster = new ChecklistRoster(\n this.checklistDetector.roster(defined, changedFiles), changedFiles.length, base !== '');\n const matched = this.checklistDetector.toRequired(this.checklistDetector.detect(defined, changedFiles));\n // THE ONE CHOKE POINT for both reviewer opt-outs. Suppressing HERE — rather than in\n // `wp-review-upsert-pr` and again in `wp-finish-upsert-pr` — is what keeps the command that LISTS\n // and the command that BLOCKS in agreement by construction, which is this class's whole reason for\n // existing. A second check in either command would be a second answer to one question.\n const context = opts.contextStage === ''\n ? this.prContextWriter.contextFor(repoRoot, featureName, basis)\n : this.prContextWriter.ensure(repoRoot, featureName, basis, opts.contextStage, changedFiles);\n const homeConfig = this.homeConfig.load();\n const projectDisabled = defined.some((d: ChecklistDefinition): boolean => d.reviewer.maxAgents === 0);\n if (homeConfig.turnOffAllReviewers || projectDisabled) {\n // EMPTY: applicable, reviewed, outstanding, formatErrors, results, optionalNotRun. INTACT:\n // defined, roster, basis, changedFiles, context — so every downstream reader can still say\n // WHAT was suppressed, which is the difference between an honest record and a silent one.\n return new ChecklistScan(\n defined, [], [], [], context, summaryPath, base, roster, [], true, matched, basis,\n changedFiles, [], []);\n }\n const applicable = matched;\n const scopeHashes = this.scopeHasher.hashes(repoRoot, basis, applicable);\n const loaded = this.reviewJsonService.loadChecklistResults(summaryPath, applicable);\n const standings = this.standingsOf(summaryPath, loaded, scopeHashes);\n const results = this.liveResults(loaded, standings);\n const stillOwed = this.reviewJsonService.pendingChecklists(applicable, results);\n const owedIds = new Set(stillOwed.map((r: RequiredChecklist): string => r.id));\n // NOT `!owedIds.has(...)`-with-the-optional-exemption-folded-in: an optional checklist nobody ran is\n // neither reviewed nor blocking, and calling it \"reviewed\" would put a ✓ on the dashboard for a review\n // that never happened.\n const reviewed = applicable.filter((r: RequiredChecklist): boolean => !owedIds.has(r.id));\n const optionalNotRun = this.reviewJsonService.optionalWithoutVerdict(applicable, results);\n const scan = new ChecklistScan(\n defined,\n applicable,\n reviewed,\n opts.filterAlreadyReviewed ? this.blocking(stillOwed, optionalNotRun) : applicable,\n context,\n summaryPath,\n base,\n roster,\n this.reviewJsonService.checklistFormatErrors(applicable, results),\n false,\n [],\n basis,\n changedFiles,\n results,\n optionalNotRun,\n );\n scan.standings = standings;\n scan.scopeHashes = scopeHashes;\n return scan;\n }\n\n /**\n * Judge every READABLE verdict against its bin provenance and the in-scope diff as it is now. A file\n * with a format problem is left to the format complaint, which names the fix; it is not assessed.\n */\n // eslint-disable-next-line @typescript-eslint/max-params\n private standingsOf(\n summaryPath: string, loaded: readonly ChecklistResult[], scopeHashes: Record<string, string>,\n ): VerdictStanding[] {\n return loaded\n .filter((r: ChecklistResult): boolean => r.problem === '')\n .map((r: ChecklistResult): VerdictStanding =>\n this.verdictProvenance.assess(summaryPath, r, scopeHashes[r.id] ?? ''));\n }\n\n /**\n * The verdicts that still COUNT. A rejected one never does. A stale green or yellow judged code that\n * has since changed, so it is owed again; a stale RED still refuses — a refusal is not lifted by\n * changing other code in its scope, only by a fresh verdict — and it is re-briefed anyway because it\n * is red.\n */\n private liveResults(loaded: readonly ChecklistResult[], standings: readonly VerdictStanding[]): ChecklistResult[] {\n const dropped = new Set(standings\n .filter((s: VerdictStanding): boolean =>\n s.standing === STANDING_REJECTED || (s.standing === STANDING_STALE && s.status !== VERDICT_RED))\n .map((s: VerdictStanding): string => s.checklistId));\n return loaded.filter((r: ChecklistResult): boolean => !dropped.has(r.id));\n }\n\n /**\n * What `wp-finish-upsert-pr` actually REFUSES on: everything still owing a verdict, minus the optional\n * checklists nobody ran.\n *\n * The subtraction happens HERE — in the one place `outstanding` is computed — and not in the gate, so\n * there is a single answer to \"does this branch owe review?\". When the gate did its own filtering, the\n * command that lists and the command that blocks were two implementations of the same question, which is\n * exactly the divergence this class's docstring exists to prevent.\n */\n private blocking(stillOwed: readonly RequiredChecklist[], optionalNotRun: readonly RequiredChecklist[]): RequiredChecklist[] {\n const skipped = new Set(optionalNotRun.map((r: RequiredChecklist): string => r.id));\n return stillOwed.filter((r: RequiredChecklist): boolean => !skipped.has(r.id));\n }\n\n /**\n * Every file changed since the fork point, INCLUDING uncommitted and untracked ones. Two non-default\n * options, both load-bearing:\n *\n * `tsOnly:false` — the default drops every *.sql / Dockerfile / .env* file a checklist most wants\n * to key on, which would silently shrink the set a reviewer is pointed at.\n * `includeDeletions:true` — the default is `--diff-filter=d`, so a DELETED file is invisible. A PR that\n * deletes a migration, an auth check or a terraform rule changed exactly what a\n * checklist exists to catch, and under the default no checklist fires at all.\n */\n private changedFiles(repoRoot: string, base: string): string[] {\n if (base === '') return [];\n const opts = new ChangedFilesOptions();\n opts.tsOnly = false;\n opts.includeDeletions = true;\n // No head argument — see the class comment. This is what includes the working tree.\n return this.diffScope.getChangedFiles(repoRoot, base, undefined, opts);\n }\n}\n"]}
1
+ {"version":3,"file":"checklist-scanner.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/checklist-scanner.ts"],"names":[],"mappings":";;;;AAAA,0DAGiC;AACjC,yCAA2D;AAC3D,iEAAsD;AACtD,6DAA0E;AAC1E,6CAA4D;AAC5D,2DAAsD;AACtD,qEAAgE;AAChE,6DAE8B;AAC9B,iEAAmE;AACnE,6DAA+D;AAE/D,uEAAuE;AACvE,MAAa,oBAAoB;IAC7B;;;;OAIG;IACH,qBAAqB,CAAU;IAC/B;;;;;;;;;;;;OAYG;IACH,YAAY,CAAS;IACrB;;;;OAIG;IACH,iBAAiB,CAAS;IAE1B,YAAY,iBAAyB,EAAE,qBAAqB,GAAG,KAAK,EAAE,YAAY,GAAG,YAAY;QAC7F,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;QAC3C,IAAI,CAAC,qBAAqB,GAAG,qBAAqB,CAAC;QACnD,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACrC,CAAC;CACJ;AAjCD,oDAiCC;AAED;;;;;;GAMG;AACH,MAAa,aAAa;IACtB,OAAO,CAAwB,CAAM,IAAI;IACzC,UAAU,CAAsB,CAAK,IAAI;IACzC,QAAQ,CAAsB,CAAO,mEAAmE;IACxG,WAAW,CAAsB,CAAI,uCAAuC;IAC5E,OAAO,CAAyB,CAAK,wCAAwC;IAC7E,WAAW,CAAS,CAAkB,yDAAyD;IAC/F,SAAS,CAAS,CAAmB,iCAAiC;IACtE,wGAAwG;IACxG,+FAA+F;IAC/F,6EAA6E;IAC7E,MAAM,CAAkB;IACxB,qGAAqG;IACrG,qGAAqG;IACrG,4EAA4E;IAC5E,YAAY,CAAW;IACvB;;;;OAIG;IACH,KAAK,CAAY;IACjB,YAAY,CAAW,CAAc,qDAAqD;IAC1F;;;;;;;;;OASG;IACH,OAAO,CAAoB;IAC3B;;;;;;;;OAQG;IACH,cAAc,CAA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CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACpF,OAAO,SAAS,CAAC,MAAM,CAAC,CAAC,CAAoB,EAAW,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACnF,CAAC;IAED;;;;;;;;;OASG;IACK,YAAY,CAAC,QAAgB,EAAE,IAAY;QAC/C,IAAI,IAAI,KAAK,EAAE;YAAE,OAAO,EAAE,CAAC;QAC3B,MAAM,IAAI,GAAG,IAAI,kCAAmB,EAAE,CAAC;QACvC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC;QAC7B,oFAAoF;QACpF,OAAO,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;IAC3E,CAAC;CACJ,CAAA;AAlLY,4CAAgB;2BAAhB,gBAAgB;IAD5B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGF,mCAAY;QACP,sCAAiB;QACzB,wBAAS;QACD,8BAAiB;QACnB,mCAAe;QACb,gCAAiB;QAGxB,gCAAiB;QAChB,6CAAoB;QACd,6CAAwB;QACjC,gDAAyB;QAC3B,4CAAuB;GAd3C,gBAAgB,CAkL5B","sourcesContent":["import {\n ChangedFilesOptions, ChecklistDefinition, ChecklistResult, ChecklistReviewContext, DiffScope,\n HomeConfigService, RequiredChecklist, ReviewJsonService, VERDICT_RED, summaryJsonPath,\n} from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { AiBranchName } from './git-readAiBranchName';\nimport { ChecklistDetector, ChecklistRoster } from './checklist-detector';\nimport { DiffBasis, DiffBasisResolver } from './diff-basis';\nimport { PrContextWriter } from './pr-context-writer';\nimport { ChecklistScopeHasher } from './checklist-scope-hasher';\nimport {\n STANDING_CARRIED, STANDING_REJECTED, STANDING_STALE, VerdictProvenanceService, VerdictStanding,\n} from './verdict-provenance';\nimport { ReviewStageReceiptService } from './review-stage-receipt';\nimport { ReviewRoundStateService } from './review-round-state';\n\n/** How a caller wants the scan filtered. Data-only (per CLAUDE.md). */\nexport class ChecklistScanOptions {\n /**\n * false — `outstanding` is every applicable checklist (what `wp-review-upsert-pr` LISTS).\n * true — `outstanding` drops the ones already carrying a passing/overridden verdict, leaving only what\n * still owes review (what `wp-finish-upsert-pr` BLOCKS on).\n */\n filterAlreadyReviewed: boolean;\n /**\n * Which per-stage snapshot this scan should persist ('stage3-finish', …), or '' for \"do not write\n * pr-context.json here\".\n *\n * '' exists for stage ②, which cannot write yet: the context records `diffDir`, and the diff has not\n * been materialized at scan time. Letting the scan write anyway meant stage ② wrote the file twice,\n * ~60 lines apart, the first time with an empty diffDir. Now it writes once, after materializing.\n *\n * The DEFAULT is deliberately non-empty, so writing is what you get by NOT thinking about it. A\n * reviewer block that lost its diff command because nobody had written pr-context.json is a bug this\n * codebase has already shipped once (see PrContextWriter's docstring); opting out must be an explicit,\n * visible act by a caller that takes responsibility for writing it later — not an omission.\n */\n contextStage: string;\n /**\n * `commands.pr-gate.maxReviewerRounds`, as the caller's validated config states it. REQUIRED and first:\n * once the budget is spent a STALE green or yellow is CARRIED rather than owed (issue #1051), so a scan\n * that did not know the budget would demand a review round the gate will never brief.\n */\n maxReviewerRounds: number;\n\n constructor(maxReviewerRounds: number, filterAlreadyReviewed = false, contextStage = 'stage-scan') {\n this.maxReviewerRounds = maxReviewerRounds;\n this.filterAlreadyReviewed = filterAlreadyReviewed;\n this.contextStage = contextStage;\n }\n}\n\n/**\n * The answer to \"what review does this branch owe?\", in the X → N → Z terms the commands report:\n * X = `defined` — every checklist in pr-gate.checklists\n * N = `applicable` — those whose patterns matched (or that have no patterns, so always run)\n * Z = `outstanding` — of N, those still owing a verdict (only when filterAlreadyReviewed)\n * Data-only.\n */\nexport class ChecklistScan {\n defined: ChecklistDefinition[]; // X\n applicable: RequiredChecklist[]; // N\n reviewed: RequiredChecklist[]; // N − Z: already have a passing/warned/overridden review-<id>.json\n outstanding: RequiredChecklist[]; // Z (== applicable when not filtering)\n context: ChecklistReviewContext; // fork-point sha + pr-context.json path\n summaryPath: string; // the branch's summary.json; verdict files sit beside it\n forkPoint: string; // '' when no fork point resolved\n // ALL X, matched or not, with why — what the PR comment publishes as its roster. Skipped checklists are\n // absent from `applicable` by construction, and recovering them downstream would mean a second\n // changed-file computation with different semantics (see the class comment).\n roster: ChecklistRoster;\n // Verdict files that exist but cannot be read as a verdict (e.g. still using the removed `success`).\n // Carried on the SCAN because wp-finish-upsert-pr refuses on missing reviewers before it ever parses\n // summary.json — a complaint raised only in there would never reach the AI.\n formatErrors: string[];\n /**\n * The basis the matching ACTUALLY ran against. Carried out so a caller that materializes the diff\n * (stage ②) reuses the identical range instead of resolving its own — two independent resolutions is\n * exactly how the changed-file set and the printed `git diff` command came to disagree.\n */\n basis: DiffBasis;\n changedFiles: string[]; // the full changed-file set the matching ran against\n /**\n * The verdict files the scan ALREADY read, carried out rather than dropped.\n *\n * `outstanding` answers \"who still owes a verdict?\" but not \"why\" — and the two reasons demand opposite\n * actions from the reader: a reviewer that never ran must be SPAWNED, a reviewer that ran and REFUSED\n * must not be (it will refuse again; the finding has to be fixed first). Telling them apart means\n * resolving each checklist's verdict, and without the results here every caller either re-reads the same\n * files off disk — a second read that can disagree with this one — or merges the two cases into one\n * message, which is exactly the loop this field exists to break.\n */\n results: ChecklistResult[];\n /**\n * The OPTIONAL (`required: false`) applicable checklists carrying no verdict file — i.e. nobody ran them.\n *\n * Deliberately NOT in `outstanding` when filtering: that is the exemption that makes `required: false`\n * mean something. Carried out as its own set rather than merely subtracted, because both readers need it\n * BY NAME and neither can recover it from what is left: stage ② offers exactly these to the human, and\n * the PR dashboard must publish them as \"not run\" rather than let a shorter roster imply everything\n * passed. An optional checklist that ran and went RED is absent from here and stays in `outstanding`.\n */\n optionalNotRun: RequiredChecklist[];\n /**\n * TRUE when either this machine's `experimental.turnOffAllReviewers` switch is on or the project sets\n * `commands.pr-gate.reviewerAgents: 0`, and therefore when `applicable`, `reviewed`,\n * `outstanding`, `results`, `optionalNotRun` and `formatErrors` above are ALL EMPTY BY DECREE rather\n * than because nothing matched. Those two states are indistinguishable from the empty lists alone,\n * and telling them apart is the entire reason this field exists: an unreviewed PR must never render\n * as a reviewed one.\n *\n * `defined`, `roster`, `basis`, `changedFiles` and `context` are deliberately left INTACT under\n * suppression, so every reader can still say WHAT was switched off — including which REQUIRED\n * checklists would otherwise have run.\n *\n * See `HOME_KEY_TURN_OFF_ALL_REVIEWERS` in rules-config for the flag's contract; it is an\n * `experimental.*` flag, so only a human ever ends it.\n */\n reviewersDisabled: boolean;\n /**\n * The checklists that WOULD have been `applicable` had the reviewers not been suppressed — required\n * ones included. EMPTY on every ordinary run, and empty is not ambiguous there because\n * `reviewersDisabled` is false.\n *\n * Carried by NAME and not as a count because every reader needs a different slice of it: stage ②\n * prints them so a human can see exactly which required reviewer was killed, the dashboard names them\n * in the 1st comment, and the compact PR body needs only `.length`. Recomputing any of that\n * downstream would mean a second changed-file computation that can disagree with this one.\n */\n suppressed: RequiredChecklist[];\n /**\n * How every EXISTING verdict file stands (issue #863): CURRENT (submitted through `wp-write-review` and\n * its checklist's in-scope diff is unchanged — it carries), STALE (in-scope diff changed since — re-brief)\n * or REJECTED (no bin provenance, or edited after submission — it is not a review). A REJECTED verdict,\n * and a STALE green or yellow one, is left OUT of `results`, so it is owed like one that never ran; a\n * stale RED stays in `results` and keeps refusing. CARRIED (issue #1051) is a green or yellow that would\n * be STALE but still counts — the reviewer-round budget is spent, or a human override for it stands.\n * Empty under suppression.\n */\n standings: VerdictStanding[];\n /** checklist id → ChecklistScopeHasher's hash of its in-scope diff NOW. Recorded in the stage-② receipt. */\n scopeHashes: Record<string, string>;\n\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(\n defined: ChecklistDefinition[],\n applicable: RequiredChecklist[],\n reviewed: RequiredChecklist[],\n outstanding: RequiredChecklist[],\n context: ChecklistReviewContext,\n summaryPath: string,\n forkPoint: string,\n roster: ChecklistRoster,\n formatErrors: string[],\n // REQUIRED, and placed BEFORE the defaulted tail deliberately. A defaulted `reviewersDisabled =\n // false` would let every existing construction keep compiling while asserting, silently, that no\n // reviewer was switched off — the widening-by-omission `.claude/rules/no-backwards-compat.md`\n // rejects, and on the one field whose whole job is to stop an unreviewed PR reading as reviewed.\n reviewersDisabled: boolean,\n suppressed: RequiredChecklist[],\n basis: DiffBasis = new DiffBasis(),\n changedFiles: string[] = [],\n // Defaulted so a caller that only cares about the X/N/Z counts (and every existing test construction)\n // stays a one-liner; the scanner itself always passes the real set.\n results: ChecklistResult[] = [],\n optionalNotRun: RequiredChecklist[] = [],\n ) {\n this.defined = defined;\n this.applicable = applicable;\n this.reviewed = reviewed;\n this.outstanding = outstanding;\n this.context = context;\n this.summaryPath = summaryPath;\n this.forkPoint = forkPoint;\n this.roster = roster;\n this.formatErrors = formatErrors;\n this.reviewersDisabled = reviewersDisabled;\n this.suppressed = suppressed;\n this.basis = basis;\n this.changedFiles = changedFiles;\n this.results = results;\n this.optionalNotRun = optionalNotRun;\n this.standings = [];\n this.scopeHashes = {};\n }\n}\n\n/**\n * The ONE computation of which reviewer subagents a branch owes, shared by `wp-review-upsert-pr` (which lists) and\n * `wp-finish-upsert-pr` (which blocks). They previously each assembled this from the same parts in slightly\n * different ways, and any divergence means the command that reports and the command that gates disagree.\n *\n * Two properties are deliberate and load-bearing:\n *\n * 1. **The base is the FORK POINT of main, computed directly** — never `DiffScope.resolveBase`, which\n * overlays `NX_BASE`/`NX_HEAD` from the environment. That made review coverage depend on an env var.\n * It now arrives via {@link DiffBasisResolver}, which injects ForkPoint; same sha, one resolution.\n * 2. **UNCOMMITTED work counts.** `getChangedFiles` is called with NO head, which is the branch of it that\n * diffs base → WORKING TREE and unions in untracked files. Passing a head would diff commit-to-commit and\n * silently miss staged, unstaged and untracked changes — so a checklist matching only uncommitted files\n * would never fire and its reviewer would never be listed.\n * 3. **The range and the command it prints are the SAME basis.** Property 2 used to be true of the file set\n * only: reviewers were handed `git diff <base> HEAD`, which on a dirty tree covers a different range and\n * prints nothing. Both now derive from one {@link DiffBasis}, carried on the scan so a materializing\n * caller cannot re-resolve and drift.\n *\n * `@injectable(bindingScopeValues.Singleton)` so it is injected by type and drawn in the DI design.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class ChecklistScanner {\n constructor(\n private readonly aiBranchName: AiBranchName,\n private readonly checklistDetector: ChecklistDetector,\n private readonly diffScope: DiffScope,\n private readonly diffBasisResolver: DiffBasisResolver,\n private readonly prContextWriter: PrContextWriter,\n private readonly reviewJsonService: ReviewJsonService,\n // Injected BY TYPE (no Symbol token, per CLAUDE.md) so the ONE reviewer kill switch is read in the\n // ONE place that computes what a branch owes — see the suppression note on `scan`.\n private readonly homeConfig: HomeConfigService,\n private readonly scopeHasher: ChecklistScopeHasher,\n private readonly verdictProvenance: VerdictProvenanceService,\n private readonly receipts: ReviewStageReceiptService,\n private readonly rounds: ReviewRoundStateService,\n ) {}\n\n /**\n * `defined` is the caller's ALREADY-VALIDATED `prGate.checklists`. The scanner deliberately does not load\n * config itself: `loadAndValidate` is the one gate on the checklist set (it rejects a non-array\n * `checklists`, including the removed `{ doc }` manifest shape, and verifies every guidance doc and\n * reviewer-agent file exists), both callers already run it for other fields, and keeping the read out of\n * here leaves this a function of its inputs rather than of the filesystem.\n */\n scan(repoRoot: string, defined: ChecklistDefinition[], opts: ChecklistScanOptions): ChecklistScan {\n const featureName = this.aiBranchName.getFeatureName();\n const summaryPath = summaryJsonPath(repoRoot, featureName);\n // ONE basis for the file set, the reproduce command and any downstream materialization. The fork\n // point still comes from ForkPoint (never DiffScope.resolveBase) — DiffBasisResolver injects it.\n const basis = this.diffBasisResolver.resolve(repoRoot);\n const base = basis.base;\n // ONE changed-file computation feeds both the roster (all X) and the applicable set (N). `detect` is\n // pure and defined as the roster minus its empty entries, so the two cannot disagree about a match.\n const changedFiles = this.changedFiles(repoRoot, base);\n const roster = new ChecklistRoster(\n this.checklistDetector.roster(defined, changedFiles), changedFiles.length, base !== '');\n const matched = this.checklistDetector.toRequired(this.checklistDetector.detect(defined, changedFiles));\n // THE ONE CHOKE POINT for both reviewer opt-outs. Suppressing HERE — rather than in\n // `wp-review-upsert-pr` and again in `wp-finish-upsert-pr` — is what keeps the command that LISTS\n // and the command that BLOCKS in agreement by construction, which is this class's whole reason for\n // existing. A second check in either command would be a second answer to one question.\n const context = opts.contextStage === ''\n ? this.prContextWriter.contextFor(repoRoot, featureName, basis)\n : this.prContextWriter.ensure(repoRoot, featureName, basis, opts.contextStage, changedFiles);\n const homeConfig = this.homeConfig.load();\n const projectDisabled = defined.some((d: ChecklistDefinition): boolean => d.reviewer.maxAgents === 0);\n if (homeConfig.turnOffAllReviewers || projectDisabled) {\n // EMPTY: applicable, reviewed, outstanding, formatErrors, results, optionalNotRun. INTACT:\n // defined, roster, basis, changedFiles, context — so every downstream reader can still say\n // WHAT was suppressed, which is the difference between an honest record and a silent one.\n return new ChecklistScan(\n defined, [], [], [], context, summaryPath, base, roster, [], true, matched, basis,\n changedFiles, [], []);\n }\n const applicable = matched;\n const scopeHashes = this.scopeHasher.hashes(repoRoot, basis, applicable);\n const loaded = this.reviewJsonService.loadChecklistResults(summaryPath, applicable);\n const capSpent = this.rounds.capSpent(summaryPath, this.receipts.read(repoRoot, featureName), opts.maxReviewerRounds);\n const standings = this.standingsOf(summaryPath, loaded, scopeHashes)\n .map((s: VerdictStanding): VerdictStanding => this.carried(s, loaded, capSpent, opts.maxReviewerRounds));\n const results = this.liveResults(loaded, standings);\n const stillOwed = this.reviewJsonService.pendingChecklists(applicable, results);\n const owedIds = new Set(stillOwed.map((r: RequiredChecklist): string => r.id));\n // NOT `!owedIds.has(...)`-with-the-optional-exemption-folded-in: an optional checklist nobody ran is\n // neither reviewed nor blocking, and calling it \"reviewed\" would put a ✓ on the dashboard for a review\n // that never happened.\n const reviewed = applicable.filter((r: RequiredChecklist): boolean => !owedIds.has(r.id));\n const optionalNotRun = this.reviewJsonService.optionalWithoutVerdict(applicable, results);\n const scan = new ChecklistScan(\n defined,\n applicable,\n reviewed,\n opts.filterAlreadyReviewed ? this.blocking(stillOwed, optionalNotRun) : applicable,\n context,\n summaryPath,\n base,\n roster,\n this.reviewJsonService.checklistFormatErrors(applicable, results),\n false,\n [],\n basis,\n changedFiles,\n results,\n optionalNotRun,\n );\n scan.standings = standings;\n scan.scopeHashes = scopeHashes;\n return scan;\n }\n\n /**\n * Judge every READABLE verdict against its bin provenance and the in-scope diff as it is now. A file\n * with a format problem is left to the format complaint, which names the fix; it is not assessed.\n */\n // eslint-disable-next-line @typescript-eslint/max-params\n private standingsOf(\n summaryPath: string, loaded: readonly ChecklistResult[], scopeHashes: Record<string, string>,\n ): VerdictStanding[] {\n return loaded\n .filter((r: ChecklistResult): boolean => r.problem === '')\n .map((r: ChecklistResult): VerdictStanding =>\n this.verdictProvenance.assess(summaryPath, r, scopeHashes[r.id] ?? ''));\n }\n\n /**\n * A STALE green or yellow that must NOT be owed again (issue #1051), re-stood as CARRIED with the reason.\n *\n * 1. A human override for the checklist stands. Staleness is judged BEFORE the verdict is resolved, so\n * without this a stale verdict read as \"never ran\" and the override written for it was never looked\n * at — the human's in-session decision was shadowed by a hash comparison.\n * 2. The reviewer-round budget is spent. The round planner never briefs a reviewer again, so a stale\n * verdict demanded here is a review nobody can ever supply: with `maxReviewerRounds: 1`, the author's\n * remediation commit marked every OTHER checklist stale and the branch could not be finished.\n *\n * A RED is never carried here: it keeps refusing until a fresh verdict, a recorded author remediation\n * after the cap, or a human override clears it. A REJECTED verdict is never carried: it is not a review.\n */\n // eslint-disable-next-line @typescript-eslint/max-params\n private carried(s: VerdictStanding, loaded: readonly ChecklistResult[], capSpent: boolean, maxRounds: number): VerdictStanding {\n if (s.standing !== STANDING_STALE || s.status === VERDICT_RED) return s;\n const result = loaded.find((r: ChecklistResult): boolean => r.id === s.checklistId);\n const override = result?.override ?? null;\n if (override !== null && override.problem === '') {\n return new VerdictStanding(s.checklistId, STANDING_CARRIED, s.status, s.fromSha,\n `${s.reason}, but a human override (authorized by ${override.authorizedBy}) stands — the verdict counts`);\n }\n if (!capSpent) return s;\n return new VerdictStanding(s.checklistId, STANDING_CARRIED, s.status, s.fromSha,\n `${s.reason}; CARRIED FORWARD without re-review — all ${maxRounds} reviewer round(s) are spent, `\n + 'so no further round runs on this branch');\n }\n\n /**\n * The verdicts that still COUNT. A rejected one never does. A stale green or yellow judged code that\n * has since changed, so it is owed again; a stale RED still refuses — a refusal is not lifted by\n * changing other code in its scope, only by a fresh verdict — and it is re-briefed anyway because it\n * is red.\n */\n private liveResults(loaded: readonly ChecklistResult[], standings: readonly VerdictStanding[]): ChecklistResult[] {\n const dropped = new Set(standings\n .filter((s: VerdictStanding): boolean =>\n s.standing === STANDING_REJECTED || (s.standing === STANDING_STALE && s.status !== VERDICT_RED))\n .map((s: VerdictStanding): string => s.checklistId));\n return loaded.filter((r: ChecklistResult): boolean => !dropped.has(r.id));\n }\n\n /**\n * What `wp-finish-upsert-pr` actually REFUSES on: everything still owing a verdict, minus the optional\n * checklists nobody ran.\n *\n * The subtraction happens HERE — in the one place `outstanding` is computed — and not in the gate, so\n * there is a single answer to \"does this branch owe review?\". When the gate did its own filtering, the\n * command that lists and the command that blocks were two implementations of the same question, which is\n * exactly the divergence this class's docstring exists to prevent.\n */\n private blocking(stillOwed: readonly RequiredChecklist[], optionalNotRun: readonly RequiredChecklist[]): RequiredChecklist[] {\n const skipped = new Set(optionalNotRun.map((r: RequiredChecklist): string => r.id));\n return stillOwed.filter((r: RequiredChecklist): boolean => !skipped.has(r.id));\n }\n\n /**\n * Every file changed since the fork point, INCLUDING uncommitted and untracked ones. Two non-default\n * options, both load-bearing:\n *\n * `tsOnly:false` — the default drops every *.sql / Dockerfile / .env* file a checklist most wants\n * to key on, which would silently shrink the set a reviewer is pointed at.\n * `includeDeletions:true` — the default is `--diff-filter=d`, so a DELETED file is invisible. A PR that\n * deletes a migration, an auth check or a terraform rule changed exactly what a\n * checklist exists to catch, and under the default no checklist fires at all.\n */\n private changedFiles(repoRoot: string, base: string): string[] {\n if (base === '') return [];\n const opts = new ChangedFilesOptions();\n opts.tsOnly = false;\n opts.includeDeletions = true;\n // No head argument — see the class comment. This is what includes the working tree.\n return this.diffScope.getChangedFiles(repoRoot, base, undefined, opts);\n }\n}\n"]}
@@ -73,7 +73,7 @@ let HotfixFinishPreparer = class HotfixFinishPreparer {
73
73
  throw new rules_config_1.InformAiError('Hotfix HEAD changed while compilation/tests were running. Re-run pnpm wp-finish-upsert-pr so the build receipt covers the exact commit pushed.');
74
74
  }
75
75
  const config = (0, rules_config_1.loadAndValidate)(repoRoot).prGate;
76
- const scan = this.checklistScanner.scan(repoRoot, config.checklists, new checklist_scanner_1.ChecklistScanOptions(false, ''));
76
+ const scan = this.checklistScanner.scan(repoRoot, config.checklists, new checklist_scanner_1.ChecklistScanOptions(config.maxReviewerRounds, false, ''));
77
77
  if (!scan.basis.unresolved) {
78
78
  this.materializer.materialize(repoRoot, featureName, scan.basis, scan.changedFiles, config.reviewDiffExclude);
79
79
  this.prContextWriter.ensure(repoRoot, featureName, scan.basis, 'stage3-hotfix', scan.changedFiles, this.materializer.diffDirFor(repoRoot, featureName));
@@ -1 +1 @@
1
- {"version":3,"file":"hotfix-finish-preparer.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/hotfix-finish-preparer.ts"],"names":[],"mappings":";;;;AAAA,iDAA0C;AAC1C,0DAAwI;AACxI,yCAA2D;AAC3D,iEAAsD;AACtD,qDAAmE;AACnE,+DAA0D;AAC1D,qDAAgD;AAChD,2DAA4F;AAC5F,2DAAuD;AACvD,yCAAqC;AACrC,+CAA6C;AAC7C,2CAAwD;AACxD,+CAA2C;AAC3C,2DAAsD;AACtD,+DAA6E;AAE7E,MAAa,iBAAiB;IAEb;IACA;IACA;IACA;IACA;IALb,YACa,WAAmB,EAC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,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;QAC3E,OAAO,MAAM,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IACnE,CAAC;CACJ,CAAA;AAnDY,oDAAoB;+BAApB,oBAAoB;IADhC,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGA,6BAAc;QAChB,mCAAY;QACjB,kBAAO;QACG,gCAAiB;QACrB,8BAAa;QACT,uCAAiB;QACxB,wBAAU;QACZ,oBAAQ;QACA,oCAAgB;QACpB,oCAAgB;QACb,mCAAe;QACZ,wCAAkB;GAblD,oBAAoB,CAmDhC","sourcesContent":["import { spawnSync } from 'child_process';\nimport { BranchIdentity, InformAiError, PrSummary, ReviewJsonService, loadAndValidate, summaryJsonPath } from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { AiBranchName } from './git-readAiBranchName';\nimport { BuildAffected, BuildGateOptions } from './build-affected';\nimport { BuildArtifactGate } from './build-artifact-gate';\nimport { FINISH_STAGE } from './build-gate-log';\nimport { ChecklistScan, ChecklistScanOptions, ChecklistScanner } from './checklist-scanner';\nimport { DiffMaterializer } from './diff-materializer';\nimport { GitExec } from './git-exec';\nimport { MergeContext } from './merge-start';\nimport { MergeEnd, MergeEndOptions } from './merge-end';\nimport { MergeState } from './merge-state';\nimport { PrContextWriter } from './pr-context-writer';\nimport { ProvenanceEnforcer, ProvenanceReport } from './provenance-enforcer';\n\nexport class HotfixFinishState {\n constructor(\n readonly featureName: string,\n readonly currentBranch: string,\n readonly review: PrSummary,\n readonly scan: ChecklistScan,\n readonly provenance: ProvenanceReport,\n ) {}\n}\n\n/** Validates and builds the emergency flow before FinishUpsertPrCommand publishes anything. */\n@injectable(bindingScopeValues.Singleton)\nexport class HotfixFinishPreparer {\n constructor(\n private readonly branchIdentity: BranchIdentity,\n private readonly aiBranchName: AiBranchName,\n private readonly gitExec: GitExec,\n private readonly reviewJsonService: ReviewJsonService,\n private readonly buildAffected: BuildAffected,\n private readonly buildArtifactGate: BuildArtifactGate,\n private readonly mergeState: MergeState,\n private readonly mergeEnd: MergeEnd,\n private readonly checklistScanner: ChecklistScanner,\n private readonly materializer: DiffMaterializer,\n private readonly prContextWriter: PrContextWriter,\n private readonly provenanceEnforcer: ProvenanceEnforcer,\n ) {}\n\n async prepare(repoRoot: string): Promise<HotfixFinishState> {\n await this.finalizeMerge(repoRoot);\n this.gitExec.assertCleanTree(repoRoot);\n const featureName = this.aiBranchName.getFeatureName();\n const review = this.reviewJsonService.loadSummaryJson(summaryJsonPath(repoRoot, featureName), []);\n const headBefore = this.gitOut(repoRoot, ['rev-parse', 'HEAD']);\n await this.buildAffected.runBuildGate(repoRoot, new BuildGateOptions('🛠️ Hotfix build gate (build + test only)', 'pnpm wp-finish-upsert-pr', 'Hotfix build failed — no PR created/updated.', FINISH_STAGE));\n this.buildArtifactGate.assertBuildLeftNothingUncommitted(repoRoot);\n this.gitExec.assertCleanTree(repoRoot);\n if (headBefore === '' || this.gitOut(repoRoot, ['rev-parse', 'HEAD']) !== headBefore) {\n throw new InformAiError('Hotfix HEAD changed while compilation/tests were running. Re-run pnpm wp-finish-upsert-pr so the build receipt covers the exact commit pushed.');\n }\n const config = loadAndValidate(repoRoot).prGate;\n const scan = this.checklistScanner.scan(repoRoot, config.checklists, new ChecklistScanOptions(false, ''));\n if (!scan.basis.unresolved) {\n this.materializer.materialize(repoRoot, featureName, scan.basis, scan.changedFiles, config.reviewDiffExclude);\n this.prContextWriter.ensure(repoRoot, featureName, scan.basis, 'stage3-hotfix', scan.changedFiles, this.materializer.diffDirFor(repoRoot, featureName));\n }\n const currentBranch = this.branchIdentity.current();\n const provenance = this.provenanceEnforcer.enforce([], currentBranch, repoRoot, config);\n return new HotfixFinishState(featureName, currentBranch, review, scan, provenance);\n }\n\n private async finalizeMerge(repoRoot: string): Promise<void> {\n const home = this.mergeState.mergeDirFor(repoRoot, this.aiBranchName.getFeatureName());\n const activeDir = this.mergeState.findActiveMergeRunDir(home);\n const marker = activeDir ? this.mergeState.readMergeMarker(activeDir) : null;\n if (!activeDir || !marker || marker.validated) return;\n await this.mergeEnd.mergeEnd(repoRoot, 'wp-finish-upsert-pr', activeDir, new MergeContext(marker.currentBranch, marker.squashBranch, marker.backupBranch, marker.prNumber), new MergeEndOptions(marker.conflictedFiles, false));\n }\n\n private gitOut(repoRoot: string, args: string[]): string {\n const result = spawnSync('git', args, { cwd: repoRoot, encoding: 'utf8' });\n return result.status === 0 ? (result.stdout ?? '').trim() : '';\n }\n}\n"]}
1
+ {"version":3,"file":"hotfix-finish-preparer.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/hotfix-finish-preparer.ts"],"names":[],"mappings":";;;;AAAA,iDAA0C;AAC1C,0DAAwI;AACxI,yCAA2D;AAC3D,iEAAsD;AACtD,qDAAmE;AACnE,+DAA0D;AAC1D,qDAAgD;AAChD,2DAA4F;AAC5F,2DAAuD;AACvD,yCAAqC;AACrC,+CAA6C;AAC7C,2CAAwD;AACxD,+CAA2C;AAC3C,2DAAsD;AACtD,+DAA6E;AAE7E,MAAa,iBAAiB;IAEb;IACA;IACA;IACA;IACA;IALb,YACa,WAAmB,EACnB,aAAqB,EACrB,MAAiB,EACjB,IAAmB,EACnB,UAA4B;QAJ5B,gBAAW,GAAX,WAAW,CAAQ;QACnB,kBAAa,GAAb,aAAa,CAAQ;QACrB,WAAM,GAAN,MAAM,CAAW;QACjB,SAAI,GAAJ,IAAI,CAAe;QACnB,eAAU,GAAV,UAAU,CAAkB;IACtC,CAAC;CACP;AARD,8CAQC;AAED,+FAA+F;AAExF,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IAER;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IAZrB,YACqB,cAA8B,EAC9B,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,gCAAiB;QACrB,8BAAa;QACT,uCAAiB;QACxB,wBAAU;QACZ,oBAAQ;QACA,oCAAgB;QACpB,oCAAgB;QACb,mCAAe;QACZ,wCAAkB;GAblD,oBAAoB,CAmDhC","sourcesContent":["import { spawnSync } from 'child_process';\nimport { BranchIdentity, InformAiError, PrSummary, ReviewJsonService, loadAndValidate, summaryJsonPath } from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { AiBranchName } from './git-readAiBranchName';\nimport { BuildAffected, BuildGateOptions } from './build-affected';\nimport { BuildArtifactGate } from './build-artifact-gate';\nimport { FINISH_STAGE } from './build-gate-log';\nimport { ChecklistScan, ChecklistScanOptions, ChecklistScanner } from './checklist-scanner';\nimport { DiffMaterializer } from './diff-materializer';\nimport { GitExec } from './git-exec';\nimport { MergeContext } from './merge-start';\nimport { MergeEnd, MergeEndOptions } from './merge-end';\nimport { MergeState } from './merge-state';\nimport { PrContextWriter } from './pr-context-writer';\nimport { ProvenanceEnforcer, ProvenanceReport } from './provenance-enforcer';\n\nexport class HotfixFinishState {\n constructor(\n readonly featureName: string,\n readonly currentBranch: string,\n readonly review: PrSummary,\n readonly scan: ChecklistScan,\n readonly provenance: ProvenanceReport,\n ) {}\n}\n\n/** Validates and builds the emergency flow before FinishUpsertPrCommand publishes anything. */\n@injectable(bindingScopeValues.Singleton)\nexport class HotfixFinishPreparer {\n constructor(\n private readonly branchIdentity: BranchIdentity,\n private readonly aiBranchName: AiBranchName,\n private readonly gitExec: GitExec,\n private readonly reviewJsonService: ReviewJsonService,\n private readonly buildAffected: BuildAffected,\n private readonly buildArtifactGate: BuildArtifactGate,\n private readonly mergeState: MergeState,\n private readonly mergeEnd: MergeEnd,\n private readonly checklistScanner: ChecklistScanner,\n private readonly materializer: DiffMaterializer,\n private readonly prContextWriter: PrContextWriter,\n private readonly provenanceEnforcer: ProvenanceEnforcer,\n ) {}\n\n async prepare(repoRoot: string): Promise<HotfixFinishState> {\n await this.finalizeMerge(repoRoot);\n this.gitExec.assertCleanTree(repoRoot);\n const featureName = this.aiBranchName.getFeatureName();\n const review = this.reviewJsonService.loadSummaryJson(summaryJsonPath(repoRoot, featureName), []);\n const headBefore = this.gitOut(repoRoot, ['rev-parse', 'HEAD']);\n await this.buildAffected.runBuildGate(repoRoot, new BuildGateOptions('🛠️ Hotfix build gate (build + test only)', 'pnpm wp-finish-upsert-pr', 'Hotfix build failed — no PR created/updated.', FINISH_STAGE));\n this.buildArtifactGate.assertBuildLeftNothingUncommitted(repoRoot);\n this.gitExec.assertCleanTree(repoRoot);\n if (headBefore === '' || this.gitOut(repoRoot, ['rev-parse', 'HEAD']) !== headBefore) {\n throw new InformAiError('Hotfix HEAD changed while compilation/tests were running. Re-run pnpm wp-finish-upsert-pr so the build receipt covers the exact commit pushed.');\n }\n const config = loadAndValidate(repoRoot).prGate;\n const scan = this.checklistScanner.scan(repoRoot, config.checklists, new ChecklistScanOptions(config.maxReviewerRounds, false, ''));\n if (!scan.basis.unresolved) {\n this.materializer.materialize(repoRoot, featureName, scan.basis, scan.changedFiles, config.reviewDiffExclude);\n this.prContextWriter.ensure(repoRoot, featureName, scan.basis, 'stage3-hotfix', scan.changedFiles, this.materializer.diffDirFor(repoRoot, featureName));\n }\n const currentBranch = this.branchIdentity.current();\n const provenance = this.provenanceEnforcer.enforce([], currentBranch, repoRoot, config);\n return new HotfixFinishState(featureName, currentBranch, review, scan, provenance);\n }\n\n private async finalizeMerge(repoRoot: string): Promise<void> {\n const home = this.mergeState.mergeDirFor(repoRoot, this.aiBranchName.getFeatureName());\n const activeDir = this.mergeState.findActiveMergeRunDir(home);\n const marker = activeDir ? this.mergeState.readMergeMarker(activeDir) : null;\n if (!activeDir || !marker || marker.validated) return;\n await this.mergeEnd.mergeEnd(repoRoot, 'wp-finish-upsert-pr', activeDir, new MergeContext(marker.currentBranch, marker.squashBranch, marker.backupBranch, marker.prNumber), new MergeEndOptions(marker.conflictedFiles, false));\n }\n\n private gitOut(repoRoot: string, args: string[]): string {\n const result = spawnSync('git', args, { cwd: repoRoot, encoding: 'utf8' });\n return result.status === 0 ? (result.stdout ?? '').trim() : '';\n }\n}\n"]}
@@ -210,6 +210,10 @@ let ReviewReport = class ReviewReport {
210
210
  if (standing === undefined) {
211
211
  return ` ✓ ${r.id} — already reviewed on this branch; verdict STANDS, do NOT re-spawn (review-${r.id}.json)`;
212
212
  }
213
+ if (standing.standing === verdict_provenance_1.STANDING_CARRIED) {
214
+ return ` ✓ ${r.id} — carried ${standing.status.toUpperCase()} from ${this.short(standing.fromSha)}: `
215
+ + `${standing.reason}; verdict STANDS, do NOT re-spawn`;
216
+ }
213
217
  return ` ✓ ${r.id} — carried ${standing.status.toUpperCase()} from ${this.short(standing.fromSha)}, `
214
218
  + `in-scope files unchanged; verdict STANDS, do NOT re-spawn`;
215
219
  }