@webpieces/pr-gate 0.4.897 → 0.4.898
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webpieces/pr-gate",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.898",
|
|
4
4
|
"description": "Gated PR system: 3-point squash-merge, merge validation gate, and red/yellow/green PR dashboard. Standalone scripts, no Nx dependency required.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -16,18 +16,18 @@
|
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@inversifyjs/binding-decorators": "1.1.5",
|
|
19
|
-
"@webpieces/hook-runtime": "0.4.
|
|
20
|
-
"@webpieces/rules-config": "0.4.
|
|
19
|
+
"@webpieces/hook-runtime": "0.4.898",
|
|
20
|
+
"@webpieces/rules-config": "0.4.898",
|
|
21
21
|
"inversify": "7.10.4",
|
|
22
22
|
"reflect-metadata": "0.2.2",
|
|
23
|
-
"@webpieces/tooling-common": "0.4.
|
|
24
|
-
"@webpieces/repo-workflow-core": "0.4.
|
|
23
|
+
"@webpieces/tooling-common": "0.4.898",
|
|
24
|
+
"@webpieces/repo-workflow-core": "0.4.898"
|
|
25
25
|
},
|
|
26
26
|
"publishConfig": {
|
|
27
27
|
"access": "public"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@webpieces/tooling-testkit": "0.4.
|
|
30
|
+
"@webpieces/tooling-testkit": "0.4.898"
|
|
31
31
|
},
|
|
32
32
|
"types": "./src/index.d.ts",
|
|
33
33
|
"bin": {
|
|
@@ -67,14 +67,17 @@ export declare class ProvenanceEnforcer {
|
|
|
67
67
|
* The verdict exists but nothing can prove WHICH branch its reviewer looked at — or, in the one case
|
|
68
68
|
* below, provenance never found the session's transcripts AT ALL and this is not about reviewers.
|
|
69
69
|
*
|
|
70
|
-
* The
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
70
|
+
* The re-spawn warning stays, scoped to what is TRUE: a round's verdict is never overwritten
|
|
71
|
+
* (wp-write-review refuses a second one), so a re-spawn into this round records nothing. What the
|
|
72
|
+
* message no longer says is that the reviewer is unrecoverable (issue #1211). It used to, and that was
|
|
73
|
+
* false for the case that hit it: the reviewer HAD read the diff (relative to its repo-root cwd) and HAD
|
|
74
|
+
* submitted through wp-write-review — provenance just did not look at either. Both are credit channels
|
|
75
|
+
* now, so when this prints, the message names exactly which proofs were missing, and that a reviewer
|
|
76
|
+
* which reads the diff dir or submits through wp-write-review in a later round IS credited.
|
|
75
77
|
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
+
* The cwd option stays too: a reviewer stamped with a pinned worktree cwd on this branch is credited
|
|
79
|
+
* on the stamp alone. It is GATED on having found the session, because it was printed for a completely
|
|
80
|
+
* different fault and sent two debugging rounds in the wrong direction: see {@link transcriptRootProblem}.
|
|
78
81
|
*/
|
|
79
82
|
private unattributedMessage;
|
|
80
83
|
/**
|
|
@@ -165,28 +165,33 @@ let ProvenanceEnforcer = class ProvenanceEnforcer {
|
|
|
165
165
|
* The verdict exists but nothing can prove WHICH branch its reviewer looked at — or, in the one case
|
|
166
166
|
* below, provenance never found the session's transcripts AT ALL and this is not about reviewers.
|
|
167
167
|
*
|
|
168
|
-
* The
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
-
*
|
|
168
|
+
* The re-spawn warning stays, scoped to what is TRUE: a round's verdict is never overwritten
|
|
169
|
+
* (wp-write-review refuses a second one), so a re-spawn into this round records nothing. What the
|
|
170
|
+
* message no longer says is that the reviewer is unrecoverable (issue #1211). It used to, and that was
|
|
171
|
+
* false for the case that hit it: the reviewer HAD read the diff (relative to its repo-root cwd) and HAD
|
|
172
|
+
* submitted through wp-write-review — provenance just did not look at either. Both are credit channels
|
|
173
|
+
* now, so when this prints, the message names exactly which proofs were missing, and that a reviewer
|
|
174
|
+
* which reads the diff dir or submits through wp-write-review in a later round IS credited.
|
|
173
175
|
*
|
|
174
|
-
*
|
|
175
|
-
*
|
|
176
|
+
* The cwd option stays too: a reviewer stamped with a pinned worktree cwd on this branch is credited
|
|
177
|
+
* on the stamp alone. It is GATED on having found the session, because it was printed for a completely
|
|
178
|
+
* different fault and sent two debugging rounds in the wrong direction: see {@link transcriptRootProblem}.
|
|
176
179
|
*/
|
|
177
180
|
unattributedMessage(unattributed, context) {
|
|
178
181
|
const head = `these reviewers WROTE a verdict for this branch that provenance cannot attribute to them: ${unattributed.join(', ')}\n` +
|
|
179
|
-
` Do NOT re-spawn them
|
|
180
|
-
`
|
|
182
|
+
` Do NOT re-spawn them into this round: a round's verdict is never overwritten (wp-write-review refuses\n` +
|
|
183
|
+
` a second one), so a re-spawn records nothing and cannot change the outcome.\n`;
|
|
181
184
|
const rootProblem = this.transcriptRootProblem();
|
|
182
185
|
if (rootProblem !== '')
|
|
183
186
|
return head + rootProblem;
|
|
184
187
|
return head +
|
|
185
|
-
`
|
|
186
|
-
` (${context.verdictPaths[unattributed[0]] ?? '<verdict path>'})
|
|
187
|
-
`
|
|
188
|
-
` pnpm wp-review
|
|
189
|
-
`
|
|
188
|
+
` WHY: each one's harness branch stamp is not ${context.branch}, and its transcript holds none of the\n` +
|
|
189
|
+
` three branch-specific proofs — it never named its verdict (${context.verdictPaths[unattributed[0]] ?? '<verdict path>'}),\n` +
|
|
190
|
+
` never read the extracted diff (${context.diffDir}, absolute or relative to its own cwd),\n` +
|
|
191
|
+
` and no pnpm wp-write-review call of its own matches the agent this branch's verdict provenance records.\n` +
|
|
192
|
+
` It is not unrecoverable: a reviewer in a later round that reads that diff dir or submits through\n` +
|
|
193
|
+
` pnpm wp-write-review IS credited wherever it was spawned from, and so is one spawned by a Claude Code\n` +
|
|
194
|
+
` session whose cwd IS the worktree holding ${context.branch}.`;
|
|
190
195
|
}
|
|
191
196
|
/**
|
|
192
197
|
* The transcript ROOT is wrong — said so, instead of blaming the reviewers. '' when it is not.
|
|
@@ -221,13 +226,20 @@ let ProvenanceEnforcer = class ProvenanceEnforcer {
|
|
|
221
226
|
*/
|
|
222
227
|
contextFor(repoRoot, required, branch) {
|
|
223
228
|
const featureName = this.aiBranchName.getFeatureName();
|
|
229
|
+
const summaryPath = (0, rules_config_1.summaryJsonPath)(repoRoot, featureName);
|
|
224
230
|
const docPaths = {};
|
|
225
231
|
const verdictPaths = {};
|
|
232
|
+
const submittedBy = {};
|
|
226
233
|
for (const req of required) {
|
|
227
234
|
docPaths[req.id] = req.doc.trim() === '' ? '' : path.resolve(repoRoot, req.doc);
|
|
228
|
-
verdictPaths[req.id] = this.reviewJsonService.latestChecklistResultPath(
|
|
235
|
+
verdictPaths[req.id] = this.reviewJsonService.latestChecklistResultPath(summaryPath, req.id);
|
|
236
|
+
// WHO wp-write-review recorded as this branch's submitter — what ties a transcript's
|
|
237
|
+
// `wp-write-review --checklist <id>` call to THIS branch (see ReviewerContext.submittedBy).
|
|
238
|
+
const record = this.verdictProvenance.read(summaryPath, req.id, this.reviewJsonService.latestVerdictRound(summaryPath, req.id));
|
|
239
|
+
if (record !== null && record.agentId.trim() !== '')
|
|
240
|
+
submittedBy[req.id] = record.agentId;
|
|
229
241
|
}
|
|
230
|
-
return new rules_config_1.ReviewerContext(branch, path.join((0, rules_config_1.prDirFor)(repoRoot, featureName), 'diff'), docPaths, verdictPaths);
|
|
242
|
+
return new rules_config_1.ReviewerContext(branch, path.join((0, rules_config_1.prDirFor)(repoRoot, featureName), 'diff'), docPaths, verdictPaths, submittedBy);
|
|
231
243
|
}
|
|
232
244
|
/**
|
|
233
245
|
* Write this round's audit record: `.webpieces/pr-review/<featureSlug>/provenance.json`, linking each
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provenance-enforcer.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workfl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BAAkB,CAkQ9B","sourcesContent":["import { spawnSync } from 'child_process';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport { prDirFor, summaryJsonPath, RequiredChecklist, PrGateConfig, ReviewJsonService, SubagentProvenanceService, PROVENANCE_OK, PROVENANCE_MISSING, PROVENANCE_SKIPPED, ProvenanceResult, ReviewerEvidence, ReviewerContext, ExpectedReviewer, ReviewProvenanceService, ProvenanceWriteRequest, ReviewerTranscript, ReviewerPaths, OfferedContext, ReviewerInstructionsService } from '@webpieces/rules-config';\nimport { InformAiError, claudeConfigDir, CLAUDE_CONFIG_DIR_ENV } from '@webpieces/tooling-common';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { AiBranchName } from './git-readAiBranchName';\nimport { VerdictProvenanceService } from './verdict-provenance';\n\n/**\n * The provenance outcome: whether each reviewer was VERIFIED to have run (the integrity check, which\n * blocks) plus what each one actually read (the quality signal, which is published). Data-only.\n */\nexport class ProvenanceReport {\n verified: boolean;\n evidence: ReviewerEvidence[];\n\n constructor(verified: boolean, evidence: ReviewerEvidence[]) {\n this.verified = verified;\n this.evidence = evidence;\n }\n}\n\n/**\n * Proves each checklist verdict came from an independently-run reviewer subagent, and records what\n * each one read.\n *\n * Split out of FinishUpsertPrCommand when that file crossed the 700-line cap, and it is the right seam\n * twice over: this is a self-contained integrity check with its own spec\n * (`finish-provenance-record.spec.ts`), and that spec previously had to reach through\n * `command as unknown as { enforceProvenance(...) }` to get at it. Now `enforce` is simply public.\n *\n * `@injectable(bindingScopeValues.Singleton)` so it is drawn in the DI design and injected by type.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class ProvenanceEnforcer {\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(\n private readonly aiBranchName: AiBranchName,\n private readonly provenance: SubagentProvenanceService,\n private readonly provenanceRecord: ReviewProvenanceService,\n private readonly reviewerInstructions: ReviewerInstructionsService,\n private readonly reviewJsonService: ReviewJsonService,\n private readonly verdictProvenance: VerdictProvenanceService,\n ) {}\n\n /**\n * Archive this round's provenance.json alongside the archived summary.json, so an archived review keeps\n * the transcript links belonging to the round that produced it — a record overwritten by the NEXT\n * round audits nothing.\n *\n * Here rather than in the command because this class owns the record; the command only knows WHEN to\n * archive, not what the record is.\n */\n archiveRecord(prDir: string): void {\n this.provenanceRecord.archive(prDir);\n }\n\n // HEAD sha for the audit record. Failure-tolerant ('' rather than a throw): a missing sha degrades\n // the audit trail, and refusing a PR over it would be the wrong trade — see writeProvenanceRecord.\n private gitOut(args: string[]): string {\n const result = spawnSync('git', args, { encoding: 'utf8' });\n return result.status === 0 ? (result.stdout ?? '').trim() : '';\n }\n\n // Enforce that EACH matched checklist was reviewed by a real reviewer SUBAGENT — the coding agent may\n // not self-certify. Not by one of a particular NAME: see SubagentProvenanceService.isReviewerRun. One run may cover several checklists, because `reviewerAgents` is a\n // required CAP and grouping under it is what the repo configured. A verified set passes silently; any\n // missing reviewer throws so the PR does not open.\n //\n // No Claude session id (Codex, a plain terminal) is NOT a pass on integrity any more (issue #863): by\n // the time this runs the checklist scan has already REJECTED every verdict that `wp-write-review` did\n // not write for a reviewer subagent. What is skipped is only the transcript evidence, and the audit\n // record is filled from the bin's provenance instead — so a Codex reviewer's identity is recorded too.\n // eslint-disable-next-line @typescript-eslint/max-params\n enforce(required: readonly RequiredChecklist[], branch: string, repoRoot: string, config: PrGateConfig): ProvenanceReport {\n const report = new ProvenanceReport(true, []); // no reviewers to verify ⇒ vacuously verified\n // Defense in depth: the scanner normally hands finish an empty set under this project policy, but\n // provenance must never resurrect a reviewer requirement if a caller still passes matched checklists.\n const enforced = config.reviewer.maxAgents === 0 ? [] : required;\n const expected = enforced\n .filter((r: RequiredChecklist): boolean => r.reviewer.agentName.trim() !== '')\n .map((r: RequiredChecklist): ExpectedReviewer => new ExpectedReviewer(r.id, r.reviewer.agentName.trim()));\n const context = this.contextFor(repoRoot, enforced, branch);\n // verifyReviewers short-circuits to OK on an empty set, so this runs unconditionally: a repo with no\n // checklists still gets a provenance record naming the session and the main agent's own transcript.\n const result = this.provenance.verifyReviewers(expected, context);\n report.verified = result.status === PROVENANCE_OK;\n if (result.status === PROVENANCE_SKIPPED) process.stderr.write(`⚠️ ${result.detail}\\n`);\n const skipped = result.status === PROVENANCE_SKIPPED;\n report.evidence = skipped\n ? this.binEvidence(repoRoot, expected)\n : this.provenance.evidenceFor(context, expected, result.agentIds);\n // Bin evidence says WHO submitted, not what they read, so it cannot be judged blind.\n const blind = skipped ? [] : this.blindReviewers(report.evidence, config);\n // BEFORE the throw below, deliberately. A refused round is the one most worth auditing, and a record\n // that only ever appeared on success could not answer what the reviewers did the time it was refused.\n this.writeProvenanceRecord(repoRoot, enforced, result, report.evidence);\n this.refuse(result, blind, context);\n return report;\n }\n\n /**\n * Evidence from `review-round<N>-<id>.provenance.json` when there are no Claude transcripts to read: the harness,\n * session and agent `wp-write-review` recorded. Read-counters stay at zero — the bin cannot know them.\n */\n private binEvidence(repoRoot: string, expected: readonly ExpectedReviewer[]): ReviewerEvidence[] {\n const summaryPath = summaryJsonPath(repoRoot, this.aiBranchName.getFeatureName());\n const out: ReviewerEvidence[] = [];\n for (const want of expected) {\n const record = this.verdictProvenance.read(summaryPath, want.checklistId, this.reviewJsonService.latestVerdictRound(summaryPath, want.checklistId));\n if (record === null) continue;\n out.push(new ReviewerEvidence(\n want.checklistId, record.agentType === '' ? want.agentType : record.agentType, record.agentId));\n }\n return out;\n }\n\n /**\n * Refuse — with an instruction that matches WHICH failure this is.\n *\n * The count is the number of CHECKLISTS at fault, not the number of message paragraphs. It used to be\n * `errors.length`, which printed \"1 checklist(s) require …\" above a list of seven names.\n *\n * The split matters more than the count. A checklist with no verdict file needs a reviewer spawned. A\n * checklist WITH one needs the opposite: the reviewer already ran, the verdict is on disk, and only the\n * attribution failed — so telling an agent to \"spawn each as its OWN subagent\" makes it overwrite seven\n * verdicts with runs that are stamped identically and refused identically. That is a loop that destroys\n * evidence on every iteration, and it is what the previous single message guaranteed.\n *\n * The BLOCK decision is the STATUS, not the length of `missing`. Those agree today — but a\n * `PROVENANCE_MISSING` that arrived carrying no names would otherwise be a silent pass: reported\n * unverified and refused by nothing. Refusing on the status makes the unverified verdict block whatever\n * else is true, and `detail` carries the wording when there are no names to word it from.\n */\n private refuse(result: ProvenanceResult, blind: readonly string[], context: ReviewerContext): void {\n const missing = result.missing;\n const neverRan = missing.filter((t: string): boolean => !fs.existsSync(context.verdictPaths[t] ?? ''));\n const unattributed = missing.filter((t: string): boolean => fs.existsSync(context.verdictPaths[t] ?? ''));\n const paragraphs: string[] = [];\n if (result.status === PROVENANCE_MISSING && missing.length === 0) paragraphs.push(result.detail);\n if (neverRan.length > 0) {\n paragraphs.push(\n 'no reviewer subagent ran on this branch for these checklists (spawn the reviewer agent that ' +\n `pnpm wp-review-upsert-pr names — do not self-certify): ${neverRan.join(', ')}`);\n }\n if (unattributed.length > 0) paragraphs.push(this.unattributedMessage(unattributed, context));\n if (blind.length > 0) {\n paragraphs.push(`these reviewers wrote a verdict without opening the diff (pr-gate.requireDiffEvidence is on): ${blind.join(', ')}`);\n }\n if (paragraphs.length === 0) return;\n // The UNION, because one checklist can be both unattributed and blind, and counting the paragraphs\n // is what printed \"1 checklist(s) require …\" above a list of seven names. Floored at 1 so the\n // nameless-MISSING case above cannot announce \"0 checklist(s) failed\" and then refuse.\n const atFault = Math.max(new Set([...missing, ...blind]).size, 1);\n throw new InformAiError(\n `${atFault} checklist(s) failed the reviewer-provenance check — fix, then re-run pnpm wp-finish-upsert-pr:\\n\\n` +\n paragraphs.map((e: string): string => ` • ${e}`).join('\\n\\n'));\n }\n\n /**\n * The verdict exists but nothing can prove WHICH branch its reviewer looked at — or, in the one case\n * below, provenance never found the session's transcripts AT ALL and this is not about reviewers.\n *\n * The cwd paragraph is reachable when a session rooted in the PRIMARY CLONE spawns reviewers for a\n * branch that lives in a linked worktree: the harness stamps record 0 from the spawning session's cwd\n * (the Agent tool has no cwd parameter), so every respawn is stamped identically and re-spawning\n * cannot change the outcome. Saying so is the whole point of that message — the remedy is a session\n * rooted in the worktree, or a reviewer that names this branch's own files.\n *\n * It is GATED on having found the session, because it was printed for a completely different fault\n * and sent two debugging rounds in the wrong direction: see {@link transcriptRootProblem}.\n */\n private unattributedMessage(unattributed: readonly string[], context: ReviewerContext): string {\n const head = `these reviewers WROTE a verdict for this branch that provenance cannot attribute to them: ${unattributed.join(', ')}\\n` +\n ` Do NOT re-spawn them. A re-spawn overwrites the verdict file it already wrote, so that loop destroys\\n` +\n ` the verdicts and cannot change the outcome.\\n`;\n const rootProblem = this.transcriptRootProblem();\n if (rootProblem !== '') return head + rootProblem;\n return head +\n ` A reviewer is attributed when it names this branch's own files: its verdict\\n` +\n ` (${context.verdictPaths[unattributed[0]] ?? '<verdict path>'}) or the extracted diff (${context.diffDir}).\\n` +\n ` It is stamped with the cwd of the session that spawned it, so if the reviewers ran before\\n` +\n ` pnpm wp-review-upsert-pr materialized that diff, re-run this from a Claude Code session whose\\n` +\n ` cwd IS the worktree holding ${context.branch} — that is the only cwd the harness will stamp on them.`;\n }\n\n /**\n * The transcript ROOT is wrong — said so, instead of blaming the reviewers. '' when it is not.\n *\n * The test is exact rather than heuristic: the main agent's transcript is located by SESSION ID alone,\n * with no cwd, branch or stamping involved, so a known session id with no transcript anywhere can only\n * mean nothing was searched in the right place. That is a transcript-location problem, and it is not\n * something a reviewer did.\n *\n * It happened, and the cost was the whole point of gating the other message: on a machine with\n * `$CLAUDE_CONFIG_DIR` relocated, provenance searched a hardcoded `~/.claude`, found neither the\n * reviewers' transcripts nor the main agent's, and refused every PR with advice about cwd stamping,\n * worktrees and primary clones — none of which was involved. Two debugging rounds went into that\n * before `provenance.json`'s empty `mainTranscript` settled it.\n */\n private transcriptRootProblem(): string {\n const session = this.provenanceRecord.sessionId();\n if (session === '' || this.provenanceRecord.mainTranscript() !== '') return '';\n const configured = claudeConfigDir.configuredDir();\n return ` Provenance found NO transcripts at all for session ${session} — not even the main agent's own — under:\\n` +\n claudeConfigDir.projectsRoots().map((root: string): string => ` ${root}\\n`).join('') +\n ` $${CLAUDE_CONFIG_DIR_ENV}=${configured === '' ? '<unset>' : configured}. This is a transcript-LOCATION problem, not a\\n` +\n ` reviewer problem — your reviewers' verdicts are intact and must not be re-run. Point this command at the\\n` +\n ` config dir that session wrote to.`;\n }\n\n /**\n * WHERE this branch's review materials live — the paths BOTH provenance passes compare against.\n *\n * One object for crediting and for evidence: they ask different questions of the same files, and\n * building the paths twice is how the two could drift apart.\n */\n private contextFor(repoRoot: string, required: readonly RequiredChecklist[], branch: string): ReviewerContext {\n const featureName = this.aiBranchName.getFeatureName();\n const docPaths: Record<string, string> = {};\n const verdictPaths: Record<string, string> = {};\n for (const req of required) {\n docPaths[req.id] = req.doc.trim() === '' ? '' : path.resolve(repoRoot, req.doc);\n verdictPaths[req.id] = this.reviewJsonService.latestChecklistResultPath(summaryJsonPath(repoRoot, featureName), req.id);\n }\n return new ReviewerContext(branch, path.join(prDirFor(repoRoot, featureName), 'diff'), docPaths, verdictPaths);\n }\n\n /**\n * Write this round's audit record: `.webpieces/pr-review/<featureSlug>/provenance.json`, linking each\n * verdict to the transcript of the subagent that produced it.\n *\n * `<featureSlug>`, not `<branch>`: the dir is named by `AiBranchName.getFeatureName()`, which\n * dash-sanitizes the branch. Calling it `<branch>` is what led a bug reporter to conclude the gate\n * must be comparing a dash-form name against a slash-form git branch — see\n * ProvenanceWriteRequest.featureSlug, whose field carried the same mislabel.\n *\n * A SEPARATE file rather than a field inside summary.json / review-round<N>-<id>.json, for two reasons. The\n * reviewer cannot supply this itself — a subagent's environment exposes the PARENT session id and no\n * agent id, so a self-reported transcript link would be invented — and keeping the AI-authored files\n * byte-untouched means nothing in the record can be mistaken for something a reviewer claimed about\n * itself. Every path here is derived by the tooling from the harness's own artifacts.\n *\n * Never fatal: an unwritable record is a lost audit trail, not a reason to refuse a PR.\n */\n // eslint-disable-next-line @typescript-eslint/max-params\n private writeProvenanceRecord(repoRoot: string, required: readonly RequiredChecklist[], result: ProvenanceResult, evidence: readonly ReviewerEvidence[]): void {\n const featureName = this.aiBranchName.getFeatureName();\n const prDir = prDirFor(repoRoot, featureName);\n const request = new ProvenanceWriteRequest(prDir, featureName, this.gitOut(['rev-parse', 'HEAD']), result.status);\n request.offered = new OfferedContext(\n path.join(prDir, 'diff'), this.reviewerInstructions.instructionsDirFor(repoRoot, featureName));\n request.reviewers = evidence.map((e: ReviewerEvidence): ReviewerTranscript =>\n new ReviewerTranscript(e, this.reviewerPathsFor(repoRoot, featureName, required, e.checklistId)));\n const written = this.provenanceRecord.write(request);\n if (written !== '') process.stdout.write(` transcript provenance → ${written}\\n`);\n }\n\n // Where ONE checklist's verdict, instructions and doc live — keyed by the checklist id, never by the\n // agent type, which every checklist now shares.\n // eslint-disable-next-line @typescript-eslint/max-params\n private reviewerPathsFor(repoRoot: string, featureName: string, required: readonly RequiredChecklist[], checklistId: string): ReviewerPaths {\n const req = required.find((r: RequiredChecklist): boolean => r.id === checklistId);\n const doc = req !== undefined && req.doc.trim() !== '' ? path.resolve(repoRoot, req.doc) : '';\n return new ReviewerPaths(\n this.reviewJsonService.latestChecklistResultPath(summaryJsonPath(repoRoot, featureName), checklistId),\n this.reviewerInstructions.pathFor(repoRoot, featureName, checklistId),\n doc,\n );\n }\n\n /**\n * The reviewers that wrote a verdict without opening the diff — WARNED about (default) or returned for\n * {@link refuse} to block on (opt-in).\n *\n * Default-warn because the signal is derived from undocumented Claude Code transcript internals: if the\n * format shifts, a blocking check wedges every PR in every consumer repo with no self-service recovery.\n * `requireDiffEvidence` lets a repo that has watched the warning promote it deliberately.\n *\n * Returns the checklist ids rather than a finished sentence so the caller can count CHECKLISTS at fault —\n * a name can appear in this list and in `missing`, and it must be one checklist in the total, not two.\n */\n private blindReviewers(evidence: readonly ReviewerEvidence[], config: PrGateConfig): string[] {\n const blind = evidence.filter((e: ReviewerEvidence): boolean => !e.readDiff);\n if (blind.length === 0) return [];\n const names = blind.map((e: ReviewerEvidence): string => e.checklistId);\n if (config.requireDiffEvidence) return names;\n process.stderr.write(\n `\\n⚠️ ${blind.length} reviewer(s) wrote a verdict with no record of opening the extracted diff: ${names.join(', ')}\\n` +\n ' Published on the PR as a note. Not blocking — set pr-gate.requireDiffEvidence:true to make it one.\\n');\n return [];\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"provenance-enforcer.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/provenance-enforcer.ts"],"names":[],"mappings":";;;;AAAA,iDAA0C;AAC1C,+CAAyB;AACzB,mDAA6B;AAC7B,0DAAkZ;AAClZ,8DAAkG;AAClG,yCAA2D;AAC3D,iEAAsD;AACtD,6DAAgE;AAEhE;;;GAGG;AACH,MAAa,gBAAgB;IACzB,QAAQ,CAAU;IAClB,QAAQ,CAAqB;IAE7B,YAAY,QAAiB,EAAE,QAA4B;QACvD,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC7B,CAAC;CACJ;AARD,4CAQC;AAED;;;;;;;;;;GAUG;AAEI,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAGN;IACA;IACA;IACA;IACA;IACA;IAPrB,yDAAyD;IACzD,YACqB,YAA0B,EAC1B,UAAqC,EACrC,gBAAyC,EACzC,oBAAiD,EACjD,iBAAoC,EACpC,iBAA2C;QAL3C,iBAAY,GAAZ,YAAY,CAAc;QAC1B,eAAU,GAAV,UAAU,CAA2B;QACrC,qBAAgB,GAAhB,gBAAgB,CAAyB;QACzC,yBAAoB,GAApB,oBAAoB,CAA6B;QACjD,sBAAiB,GAAjB,iBAAiB,CAAmB;QACpC,sBAAiB,GAAjB,iBAAiB,CAA0B;IAC7D,CAAC;IAEJ;;;;;;;OAOG;IACH,aAAa,CAAC,KAAa;QACvB,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACzC,CAAC;IAED,mGAAmG;IACnG,mGAAmG;IAC3F,MAAM,C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C;IAED;;;;;;;;;;OAUG;IACK,cAAc,CAAC,QAAqC,EAAE,MAAoB;QAC9E,MAAM,KAAK,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAmB,EAAW,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;QAC7E,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,EAAE,CAAC;QAClC,MAAM,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAmB,EAAU,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC;QACxE,IAAI,MAAM,CAAC,mBAAmB;YAAE,OAAO,KAAK,CAAC;QAC7C,OAAO,CAAC,MAAM,CAAC,KAAK,CAChB,SAAS,KAAK,CAAC,MAAM,8EAA8E,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI;YACvH,yGAAyG,CAAC,CAAC;QAC/G,OAAO,EAAE,CAAC;IACd,CAAC;CACJ,CAAA;AA7QY,gDAAkB;6BAAlB,kBAAkB;IAD9B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAIF,mCAAY;QACd,wCAAyB;QACnB,sCAAuB;QACnB,0CAA2B;QAC9B,gCAAiB;QACjB,6CAAwB;GARvD,kBAAkB,CA6Q9B","sourcesContent":["import { spawnSync } from 'child_process';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport { prDirFor, summaryJsonPath, RequiredChecklist, PrGateConfig, ReviewJsonService, SubagentProvenanceService, PROVENANCE_OK, PROVENANCE_MISSING, PROVENANCE_SKIPPED, ProvenanceResult, ReviewerEvidence, ReviewerContext, ExpectedReviewer, ReviewProvenanceService, ProvenanceWriteRequest, ReviewerTranscript, ReviewerPaths, OfferedContext, ReviewerInstructionsService } from '@webpieces/rules-config';\nimport { InformAiError, claudeConfigDir, CLAUDE_CONFIG_DIR_ENV } from '@webpieces/tooling-common';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { AiBranchName } from './git-readAiBranchName';\nimport { VerdictProvenanceService } from './verdict-provenance';\n\n/**\n * The provenance outcome: whether each reviewer was VERIFIED to have run (the integrity check, which\n * blocks) plus what each one actually read (the quality signal, which is published). Data-only.\n */\nexport class ProvenanceReport {\n verified: boolean;\n evidence: ReviewerEvidence[];\n\n constructor(verified: boolean, evidence: ReviewerEvidence[]) {\n this.verified = verified;\n this.evidence = evidence;\n }\n}\n\n/**\n * Proves each checklist verdict came from an independently-run reviewer subagent, and records what\n * each one read.\n *\n * Split out of FinishUpsertPrCommand when that file crossed the 700-line cap, and it is the right seam\n * twice over: this is a self-contained integrity check with its own spec\n * (`finish-provenance-record.spec.ts`), and that spec previously had to reach through\n * `command as unknown as { enforceProvenance(...) }` to get at it. Now `enforce` is simply public.\n *\n * `@injectable(bindingScopeValues.Singleton)` so it is drawn in the DI design and injected by type.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class ProvenanceEnforcer {\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(\n private readonly aiBranchName: AiBranchName,\n private readonly provenance: SubagentProvenanceService,\n private readonly provenanceRecord: ReviewProvenanceService,\n private readonly reviewerInstructions: ReviewerInstructionsService,\n private readonly reviewJsonService: ReviewJsonService,\n private readonly verdictProvenance: VerdictProvenanceService,\n ) {}\n\n /**\n * Archive this round's provenance.json alongside the archived summary.json, so an archived review keeps\n * the transcript links belonging to the round that produced it — a record overwritten by the NEXT\n * round audits nothing.\n *\n * Here rather than in the command because this class owns the record; the command only knows WHEN to\n * archive, not what the record is.\n */\n archiveRecord(prDir: string): void {\n this.provenanceRecord.archive(prDir);\n }\n\n // HEAD sha for the audit record. Failure-tolerant ('' rather than a throw): a missing sha degrades\n // the audit trail, and refusing a PR over it would be the wrong trade — see writeProvenanceRecord.\n private gitOut(args: string[]): string {\n const result = spawnSync('git', args, { encoding: 'utf8' });\n return result.status === 0 ? (result.stdout ?? '').trim() : '';\n }\n\n // Enforce that EACH matched checklist was reviewed by a real reviewer SUBAGENT — the coding agent may\n // not self-certify. Not by one of a particular NAME: see SubagentProvenanceService.isReviewerRun. One run may cover several checklists, because `reviewerAgents` is a\n // required CAP and grouping under it is what the repo configured. A verified set passes silently; any\n // missing reviewer throws so the PR does not open.\n //\n // No Claude session id (Codex, a plain terminal) is NOT a pass on integrity any more (issue #863): by\n // the time this runs the checklist scan has already REJECTED every verdict that `wp-write-review` did\n // not write for a reviewer subagent. What is skipped is only the transcript evidence, and the audit\n // record is filled from the bin's provenance instead — so a Codex reviewer's identity is recorded too.\n // eslint-disable-next-line @typescript-eslint/max-params\n enforce(required: readonly RequiredChecklist[], branch: string, repoRoot: string, config: PrGateConfig): ProvenanceReport {\n const report = new ProvenanceReport(true, []); // no reviewers to verify ⇒ vacuously verified\n // Defense in depth: the scanner normally hands finish an empty set under this project policy, but\n // provenance must never resurrect a reviewer requirement if a caller still passes matched checklists.\n const enforced = config.reviewer.maxAgents === 0 ? [] : required;\n const expected = enforced\n .filter((r: RequiredChecklist): boolean => r.reviewer.agentName.trim() !== '')\n .map((r: RequiredChecklist): ExpectedReviewer => new ExpectedReviewer(r.id, r.reviewer.agentName.trim()));\n const context = this.contextFor(repoRoot, enforced, branch);\n // verifyReviewers short-circuits to OK on an empty set, so this runs unconditionally: a repo with no\n // checklists still gets a provenance record naming the session and the main agent's own transcript.\n const result = this.provenance.verifyReviewers(expected, context);\n report.verified = result.status === PROVENANCE_OK;\n if (result.status === PROVENANCE_SKIPPED) process.stderr.write(`⚠️ ${result.detail}\\n`);\n const skipped = result.status === PROVENANCE_SKIPPED;\n report.evidence = skipped\n ? this.binEvidence(repoRoot, expected)\n : this.provenance.evidenceFor(context, expected, result.agentIds);\n // Bin evidence says WHO submitted, not what they read, so it cannot be judged blind.\n const blind = skipped ? [] : this.blindReviewers(report.evidence, config);\n // BEFORE the throw below, deliberately. A refused round is the one most worth auditing, and a record\n // that only ever appeared on success could not answer what the reviewers did the time it was refused.\n this.writeProvenanceRecord(repoRoot, enforced, result, report.evidence);\n this.refuse(result, blind, context);\n return report;\n }\n\n /**\n * Evidence from `review-round<N>-<id>.provenance.json` when there are no Claude transcripts to read: the harness,\n * session and agent `wp-write-review` recorded. Read-counters stay at zero — the bin cannot know them.\n */\n private binEvidence(repoRoot: string, expected: readonly ExpectedReviewer[]): ReviewerEvidence[] {\n const summaryPath = summaryJsonPath(repoRoot, this.aiBranchName.getFeatureName());\n const out: ReviewerEvidence[] = [];\n for (const want of expected) {\n const record = this.verdictProvenance.read(summaryPath, want.checklistId, this.reviewJsonService.latestVerdictRound(summaryPath, want.checklistId));\n if (record === null) continue;\n out.push(new ReviewerEvidence(\n want.checklistId, record.agentType === '' ? want.agentType : record.agentType, record.agentId));\n }\n return out;\n }\n\n /**\n * Refuse — with an instruction that matches WHICH failure this is.\n *\n * The count is the number of CHECKLISTS at fault, not the number of message paragraphs. It used to be\n * `errors.length`, which printed \"1 checklist(s) require …\" above a list of seven names.\n *\n * The split matters more than the count. A checklist with no verdict file needs a reviewer spawned. A\n * checklist WITH one needs the opposite: the reviewer already ran, the verdict is on disk, and only the\n * attribution failed — so telling an agent to \"spawn each as its OWN subagent\" makes it overwrite seven\n * verdicts with runs that are stamped identically and refused identically. That is a loop that destroys\n * evidence on every iteration, and it is what the previous single message guaranteed.\n *\n * The BLOCK decision is the STATUS, not the length of `missing`. Those agree today — but a\n * `PROVENANCE_MISSING` that arrived carrying no names would otherwise be a silent pass: reported\n * unverified and refused by nothing. Refusing on the status makes the unverified verdict block whatever\n * else is true, and `detail` carries the wording when there are no names to word it from.\n */\n private refuse(result: ProvenanceResult, blind: readonly string[], context: ReviewerContext): void {\n const missing = result.missing;\n const neverRan = missing.filter((t: string): boolean => !fs.existsSync(context.verdictPaths[t] ?? ''));\n const unattributed = missing.filter((t: string): boolean => fs.existsSync(context.verdictPaths[t] ?? ''));\n const paragraphs: string[] = [];\n if (result.status === PROVENANCE_MISSING && missing.length === 0) paragraphs.push(result.detail);\n if (neverRan.length > 0) {\n paragraphs.push(\n 'no reviewer subagent ran on this branch for these checklists (spawn the reviewer agent that ' +\n `pnpm wp-review-upsert-pr names — do not self-certify): ${neverRan.join(', ')}`);\n }\n if (unattributed.length > 0) paragraphs.push(this.unattributedMessage(unattributed, context));\n if (blind.length > 0) {\n paragraphs.push(`these reviewers wrote a verdict without opening the diff (pr-gate.requireDiffEvidence is on): ${blind.join(', ')}`);\n }\n if (paragraphs.length === 0) return;\n // The UNION, because one checklist can be both unattributed and blind, and counting the paragraphs\n // is what printed \"1 checklist(s) require …\" above a list of seven names. Floored at 1 so the\n // nameless-MISSING case above cannot announce \"0 checklist(s) failed\" and then refuse.\n const atFault = Math.max(new Set([...missing, ...blind]).size, 1);\n throw new InformAiError(\n `${atFault} checklist(s) failed the reviewer-provenance check — fix, then re-run pnpm wp-finish-upsert-pr:\\n\\n` +\n paragraphs.map((e: string): string => ` • ${e}`).join('\\n\\n'));\n }\n\n /**\n * The verdict exists but nothing can prove WHICH branch its reviewer looked at — or, in the one case\n * below, provenance never found the session's transcripts AT ALL and this is not about reviewers.\n *\n * The re-spawn warning stays, scoped to what is TRUE: a round's verdict is never overwritten\n * (wp-write-review refuses a second one), so a re-spawn into this round records nothing. What the\n * message no longer says is that the reviewer is unrecoverable (issue #1211). It used to, and that was\n * false for the case that hit it: the reviewer HAD read the diff (relative to its repo-root cwd) and HAD\n * submitted through wp-write-review — provenance just did not look at either. Both are credit channels\n * now, so when this prints, the message names exactly which proofs were missing, and that a reviewer\n * which reads the diff dir or submits through wp-write-review in a later round IS credited.\n *\n * The cwd option stays too: a reviewer stamped with a pinned worktree cwd on this branch is credited\n * on the stamp alone. It is GATED on having found the session, because it was printed for a completely\n * different fault and sent two debugging rounds in the wrong direction: see {@link transcriptRootProblem}.\n */\n private unattributedMessage(unattributed: readonly string[], context: ReviewerContext): string {\n const head = `these reviewers WROTE a verdict for this branch that provenance cannot attribute to them: ${unattributed.join(', ')}\\n` +\n ` Do NOT re-spawn them into this round: a round's verdict is never overwritten (wp-write-review refuses\\n` +\n ` a second one), so a re-spawn records nothing and cannot change the outcome.\\n`;\n const rootProblem = this.transcriptRootProblem();\n if (rootProblem !== '') return head + rootProblem;\n return head +\n ` WHY: each one's harness branch stamp is not ${context.branch}, and its transcript holds none of the\\n` +\n ` three branch-specific proofs — it never named its verdict (${context.verdictPaths[unattributed[0]] ?? '<verdict path>'}),\\n` +\n ` never read the extracted diff (${context.diffDir}, absolute or relative to its own cwd),\\n` +\n ` and no pnpm wp-write-review call of its own matches the agent this branch's verdict provenance records.\\n` +\n ` It is not unrecoverable: a reviewer in a later round that reads that diff dir or submits through\\n` +\n ` pnpm wp-write-review IS credited wherever it was spawned from, and so is one spawned by a Claude Code\\n` +\n ` session whose cwd IS the worktree holding ${context.branch}.`;\n }\n\n /**\n * The transcript ROOT is wrong — said so, instead of blaming the reviewers. '' when it is not.\n *\n * The test is exact rather than heuristic: the main agent's transcript is located by SESSION ID alone,\n * with no cwd, branch or stamping involved, so a known session id with no transcript anywhere can only\n * mean nothing was searched in the right place. That is a transcript-location problem, and it is not\n * something a reviewer did.\n *\n * It happened, and the cost was the whole point of gating the other message: on a machine with\n * `$CLAUDE_CONFIG_DIR` relocated, provenance searched a hardcoded `~/.claude`, found neither the\n * reviewers' transcripts nor the main agent's, and refused every PR with advice about cwd stamping,\n * worktrees and primary clones — none of which was involved. Two debugging rounds went into that\n * before `provenance.json`'s empty `mainTranscript` settled it.\n */\n private transcriptRootProblem(): string {\n const session = this.provenanceRecord.sessionId();\n if (session === '' || this.provenanceRecord.mainTranscript() !== '') return '';\n const configured = claudeConfigDir.configuredDir();\n return ` Provenance found NO transcripts at all for session ${session} — not even the main agent's own — under:\\n` +\n claudeConfigDir.projectsRoots().map((root: string): string => ` ${root}\\n`).join('') +\n ` $${CLAUDE_CONFIG_DIR_ENV}=${configured === '' ? '<unset>' : configured}. This is a transcript-LOCATION problem, not a\\n` +\n ` reviewer problem — your reviewers' verdicts are intact and must not be re-run. Point this command at the\\n` +\n ` config dir that session wrote to.`;\n }\n\n /**\n * WHERE this branch's review materials live — the paths BOTH provenance passes compare against.\n *\n * One object for crediting and for evidence: they ask different questions of the same files, and\n * building the paths twice is how the two could drift apart.\n */\n private contextFor(repoRoot: string, required: readonly RequiredChecklist[], branch: string): ReviewerContext {\n const featureName = this.aiBranchName.getFeatureName();\n const summaryPath = summaryJsonPath(repoRoot, featureName);\n const docPaths: Record<string, string> = {};\n const verdictPaths: Record<string, string> = {};\n const submittedBy: Record<string, string> = {};\n for (const req of required) {\n docPaths[req.id] = req.doc.trim() === '' ? '' : path.resolve(repoRoot, req.doc);\n verdictPaths[req.id] = this.reviewJsonService.latestChecklistResultPath(summaryPath, req.id);\n // WHO wp-write-review recorded as this branch's submitter — what ties a transcript's\n // `wp-write-review --checklist <id>` call to THIS branch (see ReviewerContext.submittedBy).\n const record = this.verdictProvenance.read(summaryPath, req.id, this.reviewJsonService.latestVerdictRound(summaryPath, req.id));\n if (record !== null && record.agentId.trim() !== '') submittedBy[req.id] = record.agentId;\n }\n return new ReviewerContext(branch, path.join(prDirFor(repoRoot, featureName), 'diff'), docPaths, verdictPaths, submittedBy);\n }\n\n /**\n * Write this round's audit record: `.webpieces/pr-review/<featureSlug>/provenance.json`, linking each\n * verdict to the transcript of the subagent that produced it.\n *\n * `<featureSlug>`, not `<branch>`: the dir is named by `AiBranchName.getFeatureName()`, which\n * dash-sanitizes the branch. Calling it `<branch>` is what led a bug reporter to conclude the gate\n * must be comparing a dash-form name against a slash-form git branch — see\n * ProvenanceWriteRequest.featureSlug, whose field carried the same mislabel.\n *\n * A SEPARATE file rather than a field inside summary.json / review-round<N>-<id>.json, for two reasons. The\n * reviewer cannot supply this itself — a subagent's environment exposes the PARENT session id and no\n * agent id, so a self-reported transcript link would be invented — and keeping the AI-authored files\n * byte-untouched means nothing in the record can be mistaken for something a reviewer claimed about\n * itself. Every path here is derived by the tooling from the harness's own artifacts.\n *\n * Never fatal: an unwritable record is a lost audit trail, not a reason to refuse a PR.\n */\n // eslint-disable-next-line @typescript-eslint/max-params\n private writeProvenanceRecord(repoRoot: string, required: readonly RequiredChecklist[], result: ProvenanceResult, evidence: readonly ReviewerEvidence[]): void {\n const featureName = this.aiBranchName.getFeatureName();\n const prDir = prDirFor(repoRoot, featureName);\n const request = new ProvenanceWriteRequest(prDir, featureName, this.gitOut(['rev-parse', 'HEAD']), result.status);\n request.offered = new OfferedContext(\n path.join(prDir, 'diff'), this.reviewerInstructions.instructionsDirFor(repoRoot, featureName));\n request.reviewers = evidence.map((e: ReviewerEvidence): ReviewerTranscript =>\n new ReviewerTranscript(e, this.reviewerPathsFor(repoRoot, featureName, required, e.checklistId)));\n const written = this.provenanceRecord.write(request);\n if (written !== '') process.stdout.write(` transcript provenance → ${written}\\n`);\n }\n\n // Where ONE checklist's verdict, instructions and doc live — keyed by the checklist id, never by the\n // agent type, which every checklist now shares.\n // eslint-disable-next-line @typescript-eslint/max-params\n private reviewerPathsFor(repoRoot: string, featureName: string, required: readonly RequiredChecklist[], checklistId: string): ReviewerPaths {\n const req = required.find((r: RequiredChecklist): boolean => r.id === checklistId);\n const doc = req !== undefined && req.doc.trim() !== '' ? path.resolve(repoRoot, req.doc) : '';\n return new ReviewerPaths(\n this.reviewJsonService.latestChecklistResultPath(summaryJsonPath(repoRoot, featureName), checklistId),\n this.reviewerInstructions.pathFor(repoRoot, featureName, checklistId),\n doc,\n );\n }\n\n /**\n * The reviewers that wrote a verdict without opening the diff — WARNED about (default) or returned for\n * {@link refuse} to block on (opt-in).\n *\n * Default-warn because the signal is derived from undocumented Claude Code transcript internals: if the\n * format shifts, a blocking check wedges every PR in every consumer repo with no self-service recovery.\n * `requireDiffEvidence` lets a repo that has watched the warning promote it deliberately.\n *\n * Returns the checklist ids rather than a finished sentence so the caller can count CHECKLISTS at fault —\n * a name can appear in this list and in `missing`, and it must be one checklist in the total, not two.\n */\n private blindReviewers(evidence: readonly ReviewerEvidence[], config: PrGateConfig): string[] {\n const blind = evidence.filter((e: ReviewerEvidence): boolean => !e.readDiff);\n if (blind.length === 0) return [];\n const names = blind.map((e: ReviewerEvidence): string => e.checklistId);\n if (config.requireDiffEvidence) return names;\n process.stderr.write(\n `\\n⚠️ ${blind.length} reviewer(s) wrote a verdict with no record of opening the extracted diff: ${names.join(', ')}\\n` +\n ' Published on the PR as a note. Not blocking — set pr-gate.requireDiffEvidence:true to make it one.\\n');\n return [];\n }\n}\n"]}
|