@webpieces/pr-gate 0.4.836 → 0.4.838
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 +6 -4
- package/src/scripts/commands/cleanup-command.d.ts +2 -1
- package/src/scripts/commands/cleanup-command.js +13 -12
- package/src/scripts/commands/cleanup-command.js.map +1 -1
- package/src/scripts/commands/finish-upsert-pr-command.js +5 -3
- package/src/scripts/commands/finish-upsert-pr-command.js.map +1 -1
- package/src/scripts/commands/human-post-pr-command.d.ts +2 -1
- package/src/scripts/commands/human-post-pr-command.js +3 -2
- package/src/scripts/commands/human-post-pr-command.js.map +1 -1
- package/src/scripts/commands/land-pr-command.d.ts +2 -1
- package/src/scripts/commands/land-pr-command.js +12 -9
- package/src/scripts/commands/land-pr-command.js.map +1 -1
- package/src/scripts/commands/reap-worktree-command.d.ts +2 -1
- package/src/scripts/commands/reap-worktree-command.js +4 -2
- package/src/scripts/commands/reap-worktree-command.js.map +1 -1
- package/src/scripts/commands/sync-main-command.js +2 -1
- package/src/scripts/commands/sync-main-command.js.map +1 -1
- package/src/scripts/commands/upsert-hotfix-pr-command.d.ts +2 -1
- package/src/scripts/commands/upsert-hotfix-pr-command.js +2 -1
- package/src/scripts/commands/upsert-hotfix-pr-command.js.map +1 -1
- package/src/scripts/commands/worktree-cleanup.d.ts +1 -1
- package/src/scripts/commands/worktree-cleanup.js +11 -11
- package/src/scripts/commands/worktree-cleanup.js.map +1 -1
- package/src/scripts/commands/write-review-command.js +13 -10
- package/src/scripts/commands/write-review-command.js.map +1 -1
- package/src/scripts/commands/write-review-fixes-command.js +3 -2
- package/src/scripts/commands/write-review-fixes-command.js.map +1 -1
- package/src/scripts/pr-gate-cli-app.js +2 -1
- package/src/scripts/pr-gate-cli-app.js.map +1 -1
- package/src/scripts/workflow/build-affected.d.ts +2 -1
- package/src/scripts/workflow/build-affected.js +2 -1
- package/src/scripts/workflow/build-affected.js.map +1 -1
- package/src/scripts/workflow/cleanTmp.d.ts +2 -1
- package/src/scripts/workflow/cleanTmp.js +3 -2
- package/src/scripts/workflow/cleanTmp.js.map +1 -1
- package/src/scripts/workflow/diff-materializer.js +2 -1
- package/src/scripts/workflow/diff-materializer.js.map +1 -1
- package/src/scripts/workflow/gate-log-file.js +5 -4
- package/src/scripts/workflow/gate-log-file.js.map +1 -1
- package/src/scripts/workflow/generated-artifact-registry.js +2 -1
- package/src/scripts/workflow/generated-artifact-registry.js.map +1 -1
- package/src/scripts/workflow/hotfix-redirect.d.ts +1 -1
- package/src/scripts/workflow/hotfix-redirect.js +2 -1
- package/src/scripts/workflow/hotfix-redirect.js.map +1 -1
- package/src/scripts/workflow/landed-tree-resolver.d.ts +1 -1
- package/src/scripts/workflow/landed-tree-resolver.js +2 -2
- package/src/scripts/workflow/landed-tree-resolver.js.map +1 -1
- package/src/scripts/workflow/landed-worktree-reaper.d.ts +1 -1
- package/src/scripts/workflow/landed-worktree-reaper.js +2 -1
- package/src/scripts/workflow/landed-worktree-reaper.js.map +1 -1
- package/src/scripts/workflow/merge-end.d.ts +1 -1
- package/src/scripts/workflow/merge-end.js +6 -5
- package/src/scripts/workflow/merge-end.js.map +1 -1
- package/src/scripts/workflow/merge-info-index.d.ts +1 -1
- package/src/scripts/workflow/merge-info-index.js +5 -4
- package/src/scripts/workflow/merge-info-index.js.map +1 -1
- package/src/scripts/workflow/merge-start.d.ts +1 -1
- package/src/scripts/workflow/merge-start.js +11 -9
- package/src/scripts/workflow/merge-start.js.map +1 -1
- package/src/scripts/workflow/merge-state.d.ts +1 -1
- package/src/scripts/workflow/merge-state.js +3 -2
- package/src/scripts/workflow/merge-state.js.map +1 -1
- package/src/scripts/workflow/provenance-enforcer.js +5 -4
- package/src/scripts/workflow/provenance-enforcer.js.map +1 -1
- package/src/scripts/workflow/push-dev-state.d.ts +1 -1
- package/src/scripts/workflow/push-dev-state.js +4 -2
- package/src/scripts/workflow/push-dev-state.js.map +1 -1
- package/src/scripts/workflow/review-round-state.d.ts +2 -1
- package/src/scripts/workflow/review-round-state.js +22 -20
- package/src/scripts/workflow/review-round-state.js.map +1 -1
- package/src/scripts/workflow/review-stage-receipt.js +2 -1
- package/src/scripts/workflow/review-stage-receipt.js.map +1 -1
- package/src/scripts/workflow/reviewer-briefing-builder.js +2 -1
- package/src/scripts/workflow/reviewer-briefing-builder.js.map +1 -1
- package/src/scripts/workflow/reviewer-identity.d.ts +1 -1
- package/src/scripts/workflow/reviewer-identity.js +8 -7
- package/src/scripts/workflow/reviewer-identity.js.map +1 -1
- package/src/scripts/workflow/reviewer-verdict-gate.js +2 -1
- package/src/scripts/workflow/reviewer-verdict-gate.js.map +1 -1
- package/src/scripts/workflow/run-update.d.ts +1 -1
- package/src/scripts/workflow/run-update.js +4 -4
- package/src/scripts/workflow/run-update.js.map +1 -1
- package/src/scripts/workflow/verdict-provenance.d.ts +2 -1
- package/src/scripts/workflow/verdict-provenance.js +10 -7
- package/src/scripts/workflow/verdict-provenance.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reviewer-identity.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/reviewer-identity.ts"],"names":[],"mappings":";;;;AAAA,
|
|
1
|
+
{"version":3,"file":"reviewer-identity.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/reviewer-identity.ts"],"names":[],"mappings":";;;;AAAA,8DAA0D;AAC1D,sEAA6F;AAC7F,yCAA2D;AAC3D,6DAAwD;AAExD;;;;GAIG;AACH,MAAM,WAAW,GAAG,CAAC,YAAY,EAAE,wBAAwB,EAAE,kBAAkB,EAAE,iBAAiB,CAAU,CAAC;AAE7G,8CAA8C;AAC9C,MAAa,gBAAgB;IACzB,OAAO,CAAS;IAChB,SAAS,CAAS;IAClB,OAAO,CAAS;IAChB,SAAS,CAAS;IAElB,yDAAyD;IACzD,YAAY,OAAe,EAAE,SAAiB,EAAE,OAAe,EAAE,SAAiB;QAC9E,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E,EAAE,EAAE,CAAC,CAAC;IAC9D,CAAC;IAEO,kBAAkB,CAAC,WAAmB,EAAE,MAAc;QAC1D,OAAO,GAAG,qCAAgB,iBAAiB,MAAM,uEAAuE;cAClH,iFAAiF,WAAW,mBAAmB;cAC/G,sGAAsG;cACtG,qGAAqG;cACrG,mCAAmC,CAAC;IAC9C,CAAC;IAEO,gBAAgB,CAAC,WAAmB,EAAE,UAA6B;QACvE,OAAO,GAAG,qCAAgB,oDAAoD,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,kBAAkB;cAC/G,mEAAmE,WAAW,mCAAmC;cACjH,sDAAsD;cACtD,qFAAqF;cACrF,YAAY,qCAAgB,gBAAgB,WAAW,kBAAkB;cACzE,qGAAqG,CAAC;IAChH,CAAC;CACJ,CAAA;AA9BY,4DAAwB;mCAAxB,wBAAwB;IADpC,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAEA,+CAA0B;GADtD,wBAAwB,CA8BpC","sourcesContent":["import { InformAiError } from '@webpieces/tooling-common';\nimport { ReviewIdentityStampService, WRITE_REVIEW_BIN } from '@webpieces/repo-workflow-core';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { HARNESS_TERMINAL } from './verdict-provenance';\n\n/**\n * Env vars whose presence means an AI harness launched this process. Any one of them and there MUST be a\n * hook stamp — a harness-launched submission without one either bypassed the hook or ran where the hook is\n * not installed, and neither can say who is calling.\n */\nconst HARNESS_ENV = ['CLAUDECODE', 'CLAUDE_CODE_SESSION_ID', 'CODEX_SESSION_ID', 'CODEX_THREAD_ID'] as const;\n\n/** WHO is submitting a verdict. Data-only. */\nexport class ReviewerIdentity {\n harness: string;\n sessionId: string;\n agentId: string;\n agentType: string;\n\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(harness: string, sessionId: string, agentId: string, agentType: string) {\n this.harness = harness;\n this.sessionId = sessionId;\n this.agentId = agentId;\n this.agentType = agentType;\n }\n}\n\n/**\n * Answers \"who is running `wp-write-review`?\" — and REFUSES the coordinating agent (issue #863).\n *\n * The mechanism, per harness, and why it is not the environment:\n * - CLAUDE CODE: a Bash child inherits `CLAUDE_CODE_SESSION_ID`, which is the PARENT session's id inside\n * a subagent too, and there is no agent id in the env at all. Env cannot tell a reviewer from its\n * coordinator.\n * - CODEX: `CODEX_SESSION_ID` / `CODEX_THREAD_ID` are exported, but nothing documents — and nothing here\n * has measured — that a spawned subagent gets its own thread id instead of the coordinator's.\n * - BOTH: the PreToolUse hook payload carries `agent_id`, empty for the main loop and set for a subagent,\n * on the same key in both harnesses. So the hook writes a {@link ReviewIdentityStamp} for each\n * checklist a `wp-write-review` command names, just before the command runs, and this consumes it.\n *\n * The plain-terminal story: with NO harness env and no stamp, the caller is a HUMAN at a terminal. That is\n * a legitimate reviewer, and the verdict is recorded with harness `terminal`. CI never submits verdicts —\n * `.webpieces/` is not in the repo, so there is nothing for CI to read or write here.\n *\n * NOT tamper-proof: an agent can scrub its env AND invoke the bin some way the hook does not recognise, or\n * forge a stamp file. That is deliberate, visible forgery in the transcript — the bar the rest of reviewer\n * provenance sets — rather than the one ordinary file write it used to take.\n *\n * `@injectable(bindingScopeValues.Singleton)` so it is injected by type and drawn in the DI design.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class ReviewerIdentityResolver {\n constructor(private readonly stamps: ReviewIdentityStampService) {}\n\n resolve(cwd: string, checklistId: string, env: NodeJS.ProcessEnv = process.env): ReviewerIdentity {\n const stamp = this.stamps.take(cwd, checklistId);\n if (stamp !== null) {\n if (this.stamps.isCoordinator(stamp)) throw new InformAiError(this.coordinatorRefusal(checklistId, stamp.aiType));\n return new ReviewerIdentity(stamp.aiType, stamp.sessionId, stamp.agentId, stamp.agentType);\n }\n const inHarness = HARNESS_ENV.filter((name: string): boolean => (env[name] ?? '').trim() !== '');\n if (inHarness.length > 0) throw new InformAiError(this.unstampedRefusal(checklistId, inHarness));\n return new ReviewerIdentity(HARNESS_TERMINAL, '', '', '');\n }\n\n private coordinatorRefusal(checklistId: string, aiType: string): string {\n return `${WRITE_REVIEW_BIN} REFUSED: the ${aiType} harness reports this call comes from the COORDINATING agent, not a\\n`\n + `reviewer subagent. The coordinator may never submit a reviewer's verdict for \"${checklistId}\" — not by this\\n`\n + 'bin, and not by writing the file (wp-finish-upsert-pr rejects a verdict this bin did not write).\\n\\n'\n + 'Spawn the reviewer subagent pnpm wp-review-upsert-pr names and hand it the instructions file; the\\n'\n + 'reviewer submits its own verdict.';\n }\n\n private unstampedRefusal(checklistId: string, harnessEnv: readonly string[]): string {\n return `${WRITE_REVIEW_BIN} REFUSED: this process runs under an AI harness (${harnessEnv.join(', ')} set), but the\\n`\n + `webpieces PreToolUse hook left no identity stamp for checklist \"${checklistId}\", so nothing can say whether a\\n`\n + 'reviewer subagent or the coordinator is calling.\\n\\n'\n + `Run it as a plain Bash command the hook can read, naming the checklist literally:\\n`\n + ` pnpm ${WRITE_REVIEW_BIN} --checklist ${checklistId} <<'EOF' … EOF\\n`\n + 'If it already was, the webpieces hooks are not installed in this harness: pnpm wp-install-ai-hooks.';\n }\n}\n"]}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ReviewerVerdictGate = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const rules_config_1 = require("@webpieces/rules-config");
|
|
6
|
+
const tooling_common_1 = require("@webpieces/tooling-common");
|
|
6
7
|
const inversify_1 = require("inversify");
|
|
7
8
|
const verdict_provenance_1 = require("./verdict-provenance");
|
|
8
9
|
/**
|
|
@@ -49,7 +50,7 @@ let ReviewerVerdictGate = class ReviewerVerdictGate {
|
|
|
49
50
|
const answered = new Set([...refused, ...oranges].map((r) => r.id));
|
|
50
51
|
const neverRan = scan.outstanding.filter((r) => !answered.has(r.id));
|
|
51
52
|
const refusals = refused.map((req) => this.reviewJsonService.refusalError(req, this.reviewJsonService.resolveVerdict(req, scan.results), scan.summaryPath));
|
|
52
|
-
throw new
|
|
53
|
+
throw new tooling_common_1.InformAiError(this.headline(scan, refused, oranges, neverRan)
|
|
53
54
|
+ this.unreadableSection(scan)
|
|
54
55
|
+ this.orangeSection(scan, oranges)
|
|
55
56
|
+ this.refusedSection(refusals)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reviewer-verdict-gate.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/reviewer-verdict-gate.ts"],"names":[],"mappings":";;;;AAAA,0DAEiC;AACjC,yCAA2D;AAE3D,6DAA0F;AAE1F;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEI,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IAEP;IACA;IAFrB,YACqB,iBAAoC,EACpC,YAA0C;QAD1C,sBAAiB,GAAjB,iBAAiB,CAAmB;QACpC,iBAAY,GAAZ,YAAY,CAA8B;IAC5D,CAAC;IAEJ;;;OAGG;IACH,sBAAsB,CAAC,IAAmB;QACtC,IAAI,IAAI,CAAC,WAAW,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO;QAC1C,qGAAqG;QACrG,kGAAkG;QAClG,gGAAgG;QAChG,MAAM,OAAO,GAAG,IAAI,CAAC,iBAAiB,CAAC,iBAAiB,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QACzF,MAAM,OAAO,GAAG,IAAI,CAAC,iBAAiB,CAAC,gBAAgB,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QACxF,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAoB,EAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAC/F,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAoB,EAAW,EAAE,CAAC,CAAC,QAAQ,CAAC,GAAG,CAA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AAO,CAAC,CAAC,WAAW,MAAM,CAAC,CAAC,QAAQ,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;cAC5H,4GAA4G;cAC5G,iHAAiH,CAAC;IAC5H,CAAC;IAED;;;;OAIG;IACK,eAAe,CAAC,IAAmB,EAAE,QAAsC;QAC/E,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,EAAE,CAAC;QACrC,OAAO,wGAAwG;cACzG,GAAG,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,QAAQ,EAAE,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;IACtF,CAAC;IAED,yGAAyG;IACzG,0GAA0G;IAC1G,2BAA2B;IACnB,MAAM,CAAC,UAAmB,EAAE,SAAkB;QAClD,IAAI,SAAS,IAAI,CAAC,UAAU,EAAE,CAAC;YAC3B,OAAO,oGAAoG;kBACrG,yDAAyD,CAAC;QACpE,CAAC;QACD,IAAI,UAAU,EAAE,CAAC;YACb,OAAO,sGAAsG;kBACvG,oGAAoG,CAAC;QAC/G,CAAC;QACD,OAAO,yCAAyC;cAC1C,0GAA0G;cAC1G,oDAAoD,CAAC;IAC/D,CAAC;CACJ,CAAA;AAxJY,kDAAmB;8BAAnB,mBAAmB;IAD/B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGG,gCAAiB;QACtB,2CAA4B;GAHtD,mBAAmB,CAwJ/B","sourcesContent":["import {\n ChecklistInstructionsService, InformAiError, RequiredChecklist, ReviewJsonService,\n} from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { ChecklistScan } from './checklist-scanner';\nimport { STANDING_REJECTED, STANDING_STALE, VerdictStanding } from './verdict-provenance';\n\n/**\n * The gate `wp-finish-upsert-pr` runs before it parses summary.json: REFUSE the PR while any applicable\n * checklist is not clear, and say — per checklist — which of three different things went wrong.\n *\n * It is its own class, not a private method on the command, for two reasons. It produces the text an AI acts\n * on, so it is the piece most worth asserting on directly; and the command it came out of is already the\n * largest file in this package, against a hard `@webpieces/max-file-lines` limit. It never moves or deletes\n * a verdict: every round's verdict is its own file and stays on disk (issue #1053).\n *\n * THE BUG THIS EXISTS TO FIX. The message used to be one bucket and one imperative — \"You MUST run these N\n * reviewer subagent(s)\" — for three unrelated states. Handed to an agent, the literal, obedient response for\n * a checklist that had ALREADY REFUSED was to spawn the reviewer again; it re-read the same unchanged code,\n * refused again, and the loop cost a full subagent run per pass while the reviewer's actual finding was\n * never printed at all. Three states, three actions, in this order:\n *\n * 1. UNREADABLE (`scan.formatErrors`) -> fix four characters of JSON. Not a reviewer problem.\n * 2. ORANGE (CK_ORANGE) -> the final round's must-fix: fix it, record the fix. Never a reviewer.\n * 3. REFUSED (CK_FAIL) -> fix the finding (or get a HUMAN override). Not a missing step.\n * 4. NEVER RAN (the rest) -> spawn the subagent. The ONLY case where that is the right move.\n *\n * `@injectable(bindingScopeValues.Singleton)` so it is injected by type and drawn in the DI design.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class ReviewerVerdictGate {\n constructor(\n private readonly reviewJsonService: ReviewJsonService,\n private readonly instructions: ChecklistInstructionsService,\n ) {}\n\n /**\n * Refuse the PR while ANY applicable checklist still owes a passing verdict — naming exactly what each\n * one needs. No-op for a repo with no applicable checklists.\n */\n assertEveryReviewerRan(scan: ChecklistScan): void {\n if (scan.outstanding.length === 0) return;\n // The split is computed from the verdicts the SCAN already loaded, never from a second read of disk:\n // a re-read here could disagree with the set that produced `outstanding`, and a checklist that is\n // \"outstanding\" per one read and \"clear\" per another belongs to neither section of the message.\n const refused = this.reviewJsonService.refusedChecklists(scan.outstanding, scan.results);\n const oranges = this.reviewJsonService.orangeChecklists(scan.outstanding, scan.results);\n const answered = new Set([...refused, ...oranges].map((r: RequiredChecklist): string => r.id));\n const neverRan = scan.outstanding.filter((r: RequiredChecklist): boolean => !answered.has(r.id));\n const refusals = refused.map((req: RequiredChecklist): string =>\n this.reviewJsonService.refusalError(req, this.reviewJsonService.resolveVerdict(req, scan.results), scan.summaryPath));\n throw new InformAiError(\n this.headline(scan, refused, oranges, neverRan)\n + this.unreadableSection(scan)\n + this.orangeSection(scan, oranges)\n + this.refusedSection(refusals)\n + this.discountedSection(scan, neverRan)\n + this.neverRanSection(scan, neverRan)\n + this.footer(refused.length > 0, oranges.length > 0),\n );\n }\n\n /**\n * Say plainly how many REFUSED and how many never ran.\n *\n * The old headline said all of them \"have no passing verdict yet\", which is technically true of a refusal\n * and reads as though nobody had looked. It is the sentence that framed a decision as an omission.\n */\n // eslint-disable-next-line @typescript-eslint/max-params\n private headline(\n scan: ChecklistScan, refused: readonly RequiredChecklist[], oranges: readonly RequiredChecklist[], neverRan: readonly RequiredChecklist[],\n ): string {\n const lines = [\n `⛔ NO PR — ${scan.outstanding.length} of ${scan.applicable.length} review checklist(s) that apply to this branch are not clear:`,\n ];\n if (oranges.length > 0) {\n lines.push(` • ${oranges.length} ORANGE — a final-round must-fix with no recorded fix yet: ${this.instructions.names(oranges)}`);\n }\n if (refused.length > 0) {\n lines.push(` • ${refused.length} REFUSED — a reviewer ran, judged this change, and said no: ${this.instructions.names(refused)}`);\n }\n if (neverRan.length > 0) {\n lines.push(` • ${neverRan.length} never ran — no verdict has been written yet: ${this.instructions.names(neverRan)}`);\n }\n return lines.join('\\n') + this.skippedNote(scan) + '\\n\\n';\n }\n\n /**\n * The optional checklists nobody ran, stated OUT LOUD on the refusal.\n *\n * They are not why the PR is being refused and this block says so — but a message that lists only what\n * blocked reads as \"everything else was reviewed\", and here that is false: those reviews were declined,\n * not passed. The one moment a human is looking at the review state is the moment to be honest about\n * which reviews did not happen, and it is also the prompt an AI needs to offer them again if the human\n * has changed their mind now that something else came back red.\n */\n private skippedNote(scan: ChecklistScan): string {\n if (scan.optionalNotRun.length === 0) return '';\n return `\\n (Not blocking: ${scan.optionalNotRun.length} OPTIONAL checklist(s) were not run — `\n + `${this.instructions.names(scan.optionalNotRun)}. They do not have to run; re-run\\n`\n + ' pnpm wp-review-upsert-pr if you now want to offer them.)';\n }\n\n // Unreadable verdict files come FIRST. A reviewer that wrote its verdict in the removed `success` format\n // is otherwise indistinguishable from one that never ran, and the AI would go re-run a subagent instead\n // of correcting four characters of JSON.\n private unreadableSection(scan: ChecklistScan): string {\n if (scan.formatErrors.length === 0) return '';\n return `${scan.formatErrors.length} verdict file(s) are in an UNREADABLE format:\\n\\n`\n + scan.formatErrors.map((e: string): string => ` • ${e}`).join('\\n') + '\\n\\n';\n }\n\n /**\n * The ORANGES (issue #1053) — above the refusals and everything that says to spawn, because the one move\n * an orange must never get is a reviewer: the round cap is spent. Fixed code plus a recorded fix is the\n * only way past it, and after that finish proceeds and stamps the orange with its resolution.\n */\n private orangeSection(scan: ChecklistScan, oranges: readonly RequiredChecklist[]): string {\n if (oranges.length === 0) return '';\n const findings = oranges.map((req: RequiredChecklist): string =>\n ` • ${this.reviewJsonService.orangeError(req, this.reviewJsonService.resolveVerdict(req, scan.results))}`);\n return '🟠 ORANGE — the FINAL review round found these, and nobody will review them again. Do NOT spawn a\\n'\n + ' reviewer: fix each finding, commit, and record the fixes with pnpm wp-write-review-fixes.\\n\\n'\n + findings.join('\\n') + '\\n';\n }\n\n /**\n * The refusals — above anything that says to spawn a subagent, because a spawn instruction is the\n * one line an agent acts on first, and acting on it here IS the loop.\n */\n private refusedSection(refusals: readonly string[]): string {\n if (refusals.length === 0) return '';\n return '⛔ REFUSED — these reviewers ALREADY ANSWERED. Re-spawning one against unchanged code only buys\\n'\n + ' the same answer: fix what it found (or get a HUMAN to authorize an override), THEN review again.\\n\\n'\n + refusals.map((r: string): string => ` • ${r}`).join('\\n\\n') + '\\n\\n';\n }\n\n /**\n * Verdict files that EXIST but do not count (issue #863), each with why — printed before the spawn\n * list so the reader does not mistake them for reviewers that never ran, and so a hand-written verdict\n * is named as what it is. REJECTED: no `wp-write-review` provenance, or edited after submission — a\n * coordinator writing a reviewer's verdict lands here, and that is the forgery this gate exists to\n * refuse. STALE: the checklist's in-scope files changed since it was submitted.\n */\n private discountedSection(scan: ChecklistScan, neverRan: readonly RequiredChecklist[]): string {\n const owed = new Set(neverRan.map((r: RequiredChecklist): string => r.id));\n const discounted = scan.standings.filter((s: VerdictStanding): boolean => owed.has(s.checklistId)\n && (s.standing === STANDING_REJECTED || s.standing === STANDING_STALE));\n if (discounted.length === 0) return '';\n return '🚫 NOT COUNTED — these verdict files exist, but they are not a current review:\\n\\n'\n + discounted.map((s: VerdictStanding): string => ` • ${s.checklistId} — ${s.standing.toUpperCase()}: ${s.reason}`).join('\\n')\n + '\\n A reviewer SUBAGENT must submit a fresh verdict with pnpm wp-write-review. Do NOT write or copy the\\n'\n + ' file yourself: the bin refuses the coordinating agent, and this gate rejects a verdict it did not write.\\n\\n';\n }\n\n /**\n * The reviewers that genuinely never ran — LAST, and listing ONLY these. When there are none this block\n * is absent entirely, which is the whole point: the \"You MUST run these N reviewer subagent(s)\"\n * imperative must not appear at all on a run whose only problem is a refusal.\n */\n private neverRanSection(scan: ChecklistScan, neverRan: readonly RequiredChecklist[]): string {\n if (neverRan.length === 0) return '';\n return '❓ NO VERDICT YET — nothing that counts has been submitted for these, so they must actually be run:\\n\\n'\n + `${this.instructions.render(neverRan, scan.summaryPath, scan.context)}\\n\\n`;\n }\n\n // Re-running stage 2 is normally optional. It stops being optional after a refusal, because the only way\n // past one is to CHANGE the code — which is exactly the condition that makes the extracted diff and every\n // reviewer briefing stale.\n private footer(anyRefused: boolean, anyOrange: boolean): string {\n if (anyOrange && !anyRefused) {\n return 'Fix every orange finding, commit, record the fixes with pnpm wp-write-review-fixes, then re-run:\\n'\n + 'pnpm wp-finish-upsert-pr. No further review round runs.';\n }\n if (anyRefused) {\n return 'Fix every finding, commit the remediation, record it with pnpm wp-write-review-fixes, then re-run:\\n'\n + 'pnpm wp-review-upsert-pr. The repository round budget decides whether a focused re-review remains.';\n }\n return 'Then re-run: pnpm wp-finish-upsert-pr\\n'\n + '(Each reviewer\\'s generated instructions file is already written — re-running pnpm wp-review-upsert-pr\\n'\n + ' is only needed if the code changed since it ran.)';\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"reviewer-verdict-gate.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/reviewer-verdict-gate.ts"],"names":[],"mappings":";;;;AAAA,0DAA6G;AAC7G,8DAA0D;AAC1D,yCAA2D;AAE3D,6DAA0F;AAE1F;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEI,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IAEP;IACA;IAFrB,YACqB,iBAAoC,EACpC,YAA0C;QAD1C,sBAAiB,GAAjB,iBAAiB,CAAmB;QACpC,iBAAY,GAAZ,YAAY,CAA8B;IAC5D,CAAC;IAEJ;;;OAGG;IACH,sBAAsB,CAAC,IAAmB;QACtC,IAAI,IAAI,CAAC,WAAW,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO;QAC1C,qGAAqG;QACrG,kGAAkG;QAClG,gGAAgG;QAChG,MAAM,OAAO,GAAG,IAAI,CAAC,iBAAiB,CAAC,iBAAiB,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QACzF,MAAM,OAAO,GAAG,IAAI,CAAC,iBAAiB,CAAC,gBAAgB,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QACxF,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAoB,EAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAC/F,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAoB,EAAW,EAAE,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,C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,CAAC,QAAQ,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;cAC5H,4GAA4G;cAC5G,iHAAiH,CAAC;IAC5H,CAAC;IAED;;;;OAIG;IACK,eAAe,CAAC,IAAmB,EAAE,QAAsC;QAC/E,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,EAAE,CAAC;QACrC,OAAO,wGAAwG;cACzG,GAAG,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,QAAQ,EAAE,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;IACtF,CAAC;IAED,yGAAyG;IACzG,0GAA0G;IAC1G,2BAA2B;IACnB,MAAM,CAAC,UAAmB,EAAE,SAAkB;QAClD,IAAI,SAAS,IAAI,CAAC,UAAU,EAAE,CAAC;YAC3B,OAAO,oGAAoG;kBACrG,yDAAyD,CAAC;QACpE,CAAC;QACD,IAAI,UAAU,EAAE,CAAC;YACb,OAAO,sGAAsG;kBACvG,oGAAoG,CAAC;QAC/G,CAAC;QACD,OAAO,yCAAyC;cAC1C,0GAA0G;cAC1G,oDAAoD,CAAC;IAC/D,CAAC;CACJ,CAAA;AAxJY,kDAAmB;8BAAnB,mBAAmB;IAD/B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGG,gCAAiB;QACtB,2CAA4B;GAHtD,mBAAmB,CAwJ/B","sourcesContent":["import { ChecklistInstructionsService, RequiredChecklist, ReviewJsonService } from '@webpieces/rules-config';\nimport { InformAiError } from '@webpieces/tooling-common';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { ChecklistScan } from './checklist-scanner';\nimport { STANDING_REJECTED, STANDING_STALE, VerdictStanding } from './verdict-provenance';\n\n/**\n * The gate `wp-finish-upsert-pr` runs before it parses summary.json: REFUSE the PR while any applicable\n * checklist is not clear, and say — per checklist — which of three different things went wrong.\n *\n * It is its own class, not a private method on the command, for two reasons. It produces the text an AI acts\n * on, so it is the piece most worth asserting on directly; and the command it came out of is already the\n * largest file in this package, against a hard `@webpieces/max-file-lines` limit. It never moves or deletes\n * a verdict: every round's verdict is its own file and stays on disk (issue #1053).\n *\n * THE BUG THIS EXISTS TO FIX. The message used to be one bucket and one imperative — \"You MUST run these N\n * reviewer subagent(s)\" — for three unrelated states. Handed to an agent, the literal, obedient response for\n * a checklist that had ALREADY REFUSED was to spawn the reviewer again; it re-read the same unchanged code,\n * refused again, and the loop cost a full subagent run per pass while the reviewer's actual finding was\n * never printed at all. Three states, three actions, in this order:\n *\n * 1. UNREADABLE (`scan.formatErrors`) -> fix four characters of JSON. Not a reviewer problem.\n * 2. ORANGE (CK_ORANGE) -> the final round's must-fix: fix it, record the fix. Never a reviewer.\n * 3. REFUSED (CK_FAIL) -> fix the finding (or get a HUMAN override). Not a missing step.\n * 4. NEVER RAN (the rest) -> spawn the subagent. The ONLY case where that is the right move.\n *\n * `@injectable(bindingScopeValues.Singleton)` so it is injected by type and drawn in the DI design.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class ReviewerVerdictGate {\n constructor(\n private readonly reviewJsonService: ReviewJsonService,\n private readonly instructions: ChecklistInstructionsService,\n ) {}\n\n /**\n * Refuse the PR while ANY applicable checklist still owes a passing verdict — naming exactly what each\n * one needs. No-op for a repo with no applicable checklists.\n */\n assertEveryReviewerRan(scan: ChecklistScan): void {\n if (scan.outstanding.length === 0) return;\n // The split is computed from the verdicts the SCAN already loaded, never from a second read of disk:\n // a re-read here could disagree with the set that produced `outstanding`, and a checklist that is\n // \"outstanding\" per one read and \"clear\" per another belongs to neither section of the message.\n const refused = this.reviewJsonService.refusedChecklists(scan.outstanding, scan.results);\n const oranges = this.reviewJsonService.orangeChecklists(scan.outstanding, scan.results);\n const answered = new Set([...refused, ...oranges].map((r: RequiredChecklist): string => r.id));\n const neverRan = scan.outstanding.filter((r: RequiredChecklist): boolean => !answered.has(r.id));\n const refusals = refused.map((req: RequiredChecklist): string =>\n this.reviewJsonService.refusalError(req, this.reviewJsonService.resolveVerdict(req, scan.results), scan.summaryPath));\n throw new InformAiError(\n this.headline(scan, refused, oranges, neverRan)\n + this.unreadableSection(scan)\n + this.orangeSection(scan, oranges)\n + this.refusedSection(refusals)\n + this.discountedSection(scan, neverRan)\n + this.neverRanSection(scan, neverRan)\n + this.footer(refused.length > 0, oranges.length > 0),\n );\n }\n\n /**\n * Say plainly how many REFUSED and how many never ran.\n *\n * The old headline said all of them \"have no passing verdict yet\", which is technically true of a refusal\n * and reads as though nobody had looked. It is the sentence that framed a decision as an omission.\n */\n // eslint-disable-next-line @typescript-eslint/max-params\n private headline(\n scan: ChecklistScan, refused: readonly RequiredChecklist[], oranges: readonly RequiredChecklist[], neverRan: readonly RequiredChecklist[],\n ): string {\n const lines = [\n `⛔ NO PR — ${scan.outstanding.length} of ${scan.applicable.length} review checklist(s) that apply to this branch are not clear:`,\n ];\n if (oranges.length > 0) {\n lines.push(` • ${oranges.length} ORANGE — a final-round must-fix with no recorded fix yet: ${this.instructions.names(oranges)}`);\n }\n if (refused.length > 0) {\n lines.push(` • ${refused.length} REFUSED — a reviewer ran, judged this change, and said no: ${this.instructions.names(refused)}`);\n }\n if (neverRan.length > 0) {\n lines.push(` • ${neverRan.length} never ran — no verdict has been written yet: ${this.instructions.names(neverRan)}`);\n }\n return lines.join('\\n') + this.skippedNote(scan) + '\\n\\n';\n }\n\n /**\n * The optional checklists nobody ran, stated OUT LOUD on the refusal.\n *\n * They are not why the PR is being refused and this block says so — but a message that lists only what\n * blocked reads as \"everything else was reviewed\", and here that is false: those reviews were declined,\n * not passed. The one moment a human is looking at the review state is the moment to be honest about\n * which reviews did not happen, and it is also the prompt an AI needs to offer them again if the human\n * has changed their mind now that something else came back red.\n */\n private skippedNote(scan: ChecklistScan): string {\n if (scan.optionalNotRun.length === 0) return '';\n return `\\n (Not blocking: ${scan.optionalNotRun.length} OPTIONAL checklist(s) were not run — `\n + `${this.instructions.names(scan.optionalNotRun)}. They do not have to run; re-run\\n`\n + ' pnpm wp-review-upsert-pr if you now want to offer them.)';\n }\n\n // Unreadable verdict files come FIRST. A reviewer that wrote its verdict in the removed `success` format\n // is otherwise indistinguishable from one that never ran, and the AI would go re-run a subagent instead\n // of correcting four characters of JSON.\n private unreadableSection(scan: ChecklistScan): string {\n if (scan.formatErrors.length === 0) return '';\n return `${scan.formatErrors.length} verdict file(s) are in an UNREADABLE format:\\n\\n`\n + scan.formatErrors.map((e: string): string => ` • ${e}`).join('\\n') + '\\n\\n';\n }\n\n /**\n * The ORANGES (issue #1053) — above the refusals and everything that says to spawn, because the one move\n * an orange must never get is a reviewer: the round cap is spent. Fixed code plus a recorded fix is the\n * only way past it, and after that finish proceeds and stamps the orange with its resolution.\n */\n private orangeSection(scan: ChecklistScan, oranges: readonly RequiredChecklist[]): string {\n if (oranges.length === 0) return '';\n const findings = oranges.map((req: RequiredChecklist): string =>\n ` • ${this.reviewJsonService.orangeError(req, this.reviewJsonService.resolveVerdict(req, scan.results))}`);\n return '🟠 ORANGE — the FINAL review round found these, and nobody will review them again. Do NOT spawn a\\n'\n + ' reviewer: fix each finding, commit, and record the fixes with pnpm wp-write-review-fixes.\\n\\n'\n + findings.join('\\n') + '\\n';\n }\n\n /**\n * The refusals — above anything that says to spawn a subagent, because a spawn instruction is the\n * one line an agent acts on first, and acting on it here IS the loop.\n */\n private refusedSection(refusals: readonly string[]): string {\n if (refusals.length === 0) return '';\n return '⛔ REFUSED — these reviewers ALREADY ANSWERED. Re-spawning one against unchanged code only buys\\n'\n + ' the same answer: fix what it found (or get a HUMAN to authorize an override), THEN review again.\\n\\n'\n + refusals.map((r: string): string => ` • ${r}`).join('\\n\\n') + '\\n\\n';\n }\n\n /**\n * Verdict files that EXIST but do not count (issue #863), each with why — printed before the spawn\n * list so the reader does not mistake them for reviewers that never ran, and so a hand-written verdict\n * is named as what it is. REJECTED: no `wp-write-review` provenance, or edited after submission — a\n * coordinator writing a reviewer's verdict lands here, and that is the forgery this gate exists to\n * refuse. STALE: the checklist's in-scope files changed since it was submitted.\n */\n private discountedSection(scan: ChecklistScan, neverRan: readonly RequiredChecklist[]): string {\n const owed = new Set(neverRan.map((r: RequiredChecklist): string => r.id));\n const discounted = scan.standings.filter((s: VerdictStanding): boolean => owed.has(s.checklistId)\n && (s.standing === STANDING_REJECTED || s.standing === STANDING_STALE));\n if (discounted.length === 0) return '';\n return '🚫 NOT COUNTED — these verdict files exist, but they are not a current review:\\n\\n'\n + discounted.map((s: VerdictStanding): string => ` • ${s.checklistId} — ${s.standing.toUpperCase()}: ${s.reason}`).join('\\n')\n + '\\n A reviewer SUBAGENT must submit a fresh verdict with pnpm wp-write-review. Do NOT write or copy the\\n'\n + ' file yourself: the bin refuses the coordinating agent, and this gate rejects a verdict it did not write.\\n\\n';\n }\n\n /**\n * The reviewers that genuinely never ran — LAST, and listing ONLY these. When there are none this block\n * is absent entirely, which is the whole point: the \"You MUST run these N reviewer subagent(s)\"\n * imperative must not appear at all on a run whose only problem is a refusal.\n */\n private neverRanSection(scan: ChecklistScan, neverRan: readonly RequiredChecklist[]): string {\n if (neverRan.length === 0) return '';\n return '❓ NO VERDICT YET — nothing that counts has been submitted for these, so they must actually be run:\\n\\n'\n + `${this.instructions.render(neverRan, scan.summaryPath, scan.context)}\\n\\n`;\n }\n\n // Re-running stage 2 is normally optional. It stops being optional after a refusal, because the only way\n // past one is to CHANGE the code — which is exactly the condition that makes the extracted diff and every\n // reviewer briefing stale.\n private footer(anyRefused: boolean, anyOrange: boolean): string {\n if (anyOrange && !anyRefused) {\n return 'Fix every orange finding, commit, record the fixes with pnpm wp-write-review-fixes, then re-run:\\n'\n + 'pnpm wp-finish-upsert-pr. No further review round runs.';\n }\n if (anyRefused) {\n return 'Fix every finding, commit the remediation, record it with pnpm wp-write-review-fixes, then re-run:\\n'\n + 'pnpm wp-review-upsert-pr. The repository round budget decides whether a focused re-review remains.';\n }\n return 'Then re-run: pnpm wp-finish-upsert-pr\\n'\n + '(Each reviewer\\'s generated instructions file is already written — re-running pnpm wp-review-upsert-pr\\n'\n + ' is only needed if the code changed since it ran.)';\n }\n}\n"]}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RunUpdate = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const
|
|
5
|
+
const repo_workflow_core_1 = require("@webpieces/repo-workflow-core");
|
|
6
6
|
const inversify_1 = require("inversify");
|
|
7
7
|
const git_readAiBranchName_1 = require("./git-readAiBranchName");
|
|
8
8
|
const merge_state_1 = require("./merge-state");
|
|
@@ -30,11 +30,11 @@ let RunUpdate = class RunUpdate {
|
|
|
30
30
|
// for the PR flow, which pushes exactly once from wp-finish-upsert-pr (see MergeEndOptions).
|
|
31
31
|
// eslint-disable-next-line @typescript-eslint/max-params
|
|
32
32
|
async runUpdateFromMain(repoRoot, verb, finishCommand, pushRemote) {
|
|
33
|
-
(0,
|
|
33
|
+
(0, repo_workflow_core_1.logBranchMutation)(repoRoot, new repo_workflow_core_1.BranchMutationEvent(verb, 'START'));
|
|
34
34
|
const outcome = await this.runUpdate(repoRoot, verb, finishCommand, pushRemote);
|
|
35
|
-
const end = new
|
|
35
|
+
const end = new repo_workflow_core_1.BranchMutationEvent(verb, 'END');
|
|
36
36
|
end.outcome = outcome;
|
|
37
|
-
(0,
|
|
37
|
+
(0, repo_workflow_core_1.logBranchMutation)(repoRoot, end);
|
|
38
38
|
return outcome;
|
|
39
39
|
}
|
|
40
40
|
// eslint-disable-next-line @typescript-eslint/max-params
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-update.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/run-update.ts"],"names":[],"mappings":";;;;AAAA,
|
|
1
|
+
{"version":3,"file":"run-update.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/run-update.ts"],"names":[],"mapp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;GAL9B,SAAS,CAkDrB","sourcesContent":["import { MutationVerb, BranchMutationEvent, logBranchMutation } from '@webpieces/repo-workflow-core';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { AiBranchName } from './git-readAiBranchName';\nimport { MergeState } from './merge-state';\nimport { MergeStart, MergeContext } from './merge-start';\nimport { MergeEnd, MergeEndOptions } from './merge-end';\n\nexport type UpdateOutcome = 'finalized' | 'conflict' | 'unvalidatedResume';\n\n// The shared \"sync this feature branch from main\" engine — a thin composition of the two lifecycle\n// primitives (merge-START brings main in, merge-END finalizes). INTERNAL, not a bin: `wp-start-update`\n// (standalone) and `wp-start-upsert-pr` (PR flow) both call it. It NEVER creates a PR and NEVER\n// process.exits; it RETURNS an outcome so each caller prints the handoff that fits its context.\n@injectable(bindingScopeValues.Singleton)\nexport class RunUpdate {\n constructor(\n private readonly aiBranchName: AiBranchName,\n private readonly mergeState: MergeState,\n private readonly mergeStart: MergeStart,\n private readonly mergeEnd: MergeEnd,\n ) {}\n\n // `finishCommand` is the command the AI is told to run after resolving conflicts (standalone passes\n // `wp-finish-update`, PR flow passes `wp-finish-upsert-pr`). `verb` is the invoking bin, threaded so\n // every branch mutation is recorded in the branch-mutation log (BranchMutationLog.branchMutationLogPath\n // resolves it for THIS tree — it is per-worktree). `pushRemote` is false\n // for the PR flow, which pushes exactly once from wp-finish-upsert-pr (see MergeEndOptions).\n // eslint-disable-next-line @typescript-eslint/max-params\n async runUpdateFromMain(repoRoot: string, verb: MutationVerb, finishCommand: string, pushRemote: boolean): Promise<UpdateOutcome> {\n logBranchMutation(repoRoot, new BranchMutationEvent(verb, 'START'));\n const outcome = await this.runUpdate(repoRoot, verb, finishCommand, pushRemote);\n const end = new BranchMutationEvent(verb, 'END');\n end.outcome = outcome;\n logBranchMutation(repoRoot, end);\n return outcome;\n }\n\n // eslint-disable-next-line @typescript-eslint/max-params\n private async runUpdate(repoRoot: string, verb: MutationVerb, finishCommand: string, pushRemote: boolean): Promise<UpdateOutcome> {\n const home = this.mergeState.mergeDirFor(repoRoot, this.aiBranchName.getFeatureName());\n\n // Resume path: an in-progress merge is the `merge-<n>/` run dir that holds a marker.\n const activeDir = this.mergeState.findActiveMergeRunDir(home);\n if (activeDir) {\n const existing = this.mergeState.readMergeMarker(activeDir);\n if (existing === null || !existing.validated) return 'unvalidatedResume';\n // Already validated → just finalize the branch swap (reads THIS run dir's marker).\n await this.mergeEnd.mergeEnd(\n repoRoot, verb, activeDir,\n new MergeContext(existing.currentBranch, existing.squashBranch, existing.backupBranch, existing.prNumber),\n new MergeEndOptions(null, pushRemote),\n );\n return 'finalized';\n }\n\n // Fresh update: mergeStart picks the slot number, creates its own `merge-<n>/` run dir, and\n // returns that path for merge-END to finalize against.\n const result = await this.mergeStart.mergeStart(repoRoot, verb, home, finishCommand);\n if (result.status === 'conflict' || result.context === null) {\n return 'conflict';\n }\n await this.mergeEnd.mergeEnd(repoRoot, verb, result.runDir, result.context, new MergeEndOptions(null, pushRemote));\n return 'finalized';\n }\n}\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { AtomicFile
|
|
1
|
+
import { AtomicFile } from '@webpieces/tooling-common';
|
|
2
|
+
import { ChecklistResult, ReviewJsonService } from '@webpieces/rules-config';
|
|
2
3
|
/** `harness` for a verdict submitted from a plain terminal — a HUMAN reviewer, with no AI harness at all. */
|
|
3
4
|
export declare const HARNESS_TERMINAL = "terminal";
|
|
4
5
|
/** A verdict exactly as `wp-write-review` accepts it — the five fields and nothing else. Data-only. */
|
|
@@ -5,7 +5,10 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const crypto = tslib_1.__importStar(require("crypto"));
|
|
6
6
|
const fs = tslib_1.__importStar(require("fs"));
|
|
7
7
|
const path = tslib_1.__importStar(require("path"));
|
|
8
|
+
const tooling_common_1 = require("@webpieces/tooling-common");
|
|
9
|
+
const to_error_1 = require("@webpieces/tooling-common/to-error");
|
|
8
10
|
const rules_config_1 = require("@webpieces/rules-config");
|
|
11
|
+
const repo_workflow_core_1 = require("@webpieces/repo-workflow-core");
|
|
9
12
|
const inversify_1 = require("inversify");
|
|
10
13
|
/** `harness` for a verdict submitted from a plain terminal — a HUMAN reviewer, with no AI harness at all. */
|
|
11
14
|
exports.HARNESS_TERMINAL = 'terminal';
|
|
@@ -52,7 +55,7 @@ class VerdictProvenance {
|
|
|
52
55
|
round; // the N of review-round<N>-<id>.json — which review round this verdict belongs to
|
|
53
56
|
// eslint-disable-next-line @typescript-eslint/max-params
|
|
54
57
|
constructor(checklistId, harness, sessionId, agentId, agentType, headSha, scopeHash) {
|
|
55
|
-
this.writer =
|
|
58
|
+
this.writer = repo_workflow_core_1.WRITE_REVIEW_BIN;
|
|
56
59
|
this.checklistId = checklistId;
|
|
57
60
|
this.harness = harness;
|
|
58
61
|
this.sessionId = sessionId;
|
|
@@ -158,7 +161,7 @@ let VerdictProvenanceService = class VerdictProvenanceService {
|
|
|
158
161
|
return record;
|
|
159
162
|
}
|
|
160
163
|
catch (err) {
|
|
161
|
-
const error = (0,
|
|
164
|
+
const error = (0, to_error_1.toError)(err);
|
|
162
165
|
void error;
|
|
163
166
|
return null;
|
|
164
167
|
}
|
|
@@ -177,17 +180,17 @@ let VerdictProvenanceService = class VerdictProvenanceService {
|
|
|
177
180
|
if (record === null) {
|
|
178
181
|
const file = this.provenancePath(summaryPath, id, round);
|
|
179
182
|
const why = fs.existsSync(file) ? `${path.basename(file)} is unreadable` : `no ${path.basename(file)}`;
|
|
180
|
-
return reject(`${verdictFile} was not submitted through pnpm ${
|
|
183
|
+
return reject(`${verdictFile} was not submitted through pnpm ${repo_workflow_core_1.WRITE_REVIEW_BIN} (${why}) — a hand-written verdict is not a review`);
|
|
181
184
|
}
|
|
182
|
-
if (record.writer !==
|
|
183
|
-
return reject(`${path.basename(this.provenancePath(summaryPath, id, round))} was not written by ${
|
|
185
|
+
if (record.writer !== repo_workflow_core_1.WRITE_REVIEW_BIN || record.checklistId !== id || record.round !== round) {
|
|
186
|
+
return reject(`${path.basename(this.provenancePath(summaryPath, id, round))} was not written by ${repo_workflow_core_1.WRITE_REVIEW_BIN} for this checklist and round`);
|
|
184
187
|
}
|
|
185
188
|
if (record.agentId.trim() === '' && record.harness !== exports.HARNESS_TERMINAL) {
|
|
186
189
|
return reject(`${verdictFile} was submitted by the coordinating agent, not a reviewer subagent`);
|
|
187
190
|
}
|
|
188
191
|
const submitted = new SubmittedVerdict(id, result.status, result.agent, result.model, result.output);
|
|
189
192
|
if (this.canonicalHash(submitted) !== record.verdictHash) {
|
|
190
|
-
return reject(`${verdictFile} was EDITED after ${
|
|
193
|
+
return reject(`${verdictFile} was EDITED after ${repo_workflow_core_1.WRITE_REVIEW_BIN} wrote it — a verdict is the reviewer's words, not a draft`);
|
|
191
194
|
}
|
|
192
195
|
if (currentScopeHash !== '' && record.scopeHash !== currentScopeHash) {
|
|
193
196
|
return new VerdictStanding(id, exports.STANDING_STALE, result.status, record.headSha, `in-scope files CHANGED since the verdict was written at ${this.short(record.headSha)}`);
|
|
@@ -207,6 +210,6 @@ exports.VerdictProvenanceService = VerdictProvenanceService;
|
|
|
207
210
|
exports.VerdictProvenanceService = VerdictProvenanceService = tslib_1.__decorate([
|
|
208
211
|
(0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton),
|
|
209
212
|
tslib_1.__metadata("design:paramtypes", [rules_config_1.ReviewJsonService,
|
|
210
|
-
|
|
213
|
+
tooling_common_1.AtomicFile])
|
|
211
214
|
], VerdictProvenanceService);
|
|
212
215
|
//# sourceMappingURL=verdict-provenance.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verdict-provenance.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/verdict-provenance.ts"],"names":[],"mappings":";;;;AAAA,uDAAiC;AACjC,+CAAyB;AACzB,mDAA6B;AAC7B,0DAEiC;AACjC,yCAA2D;AAE3D,6GAA6G;AAChG,QAAA,gBAAgB,GAAG,UAAU,CAAC;AAE3C,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MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QACjG,CAAC;QACD,OAAO,IAAI,eAAe,CAAC,EAAE,EAAE,wBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,EAC1E,kCAAkC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IACxE,CAAC;IAED,6EAA6E;IAC7E,KAAK,CAAC,GAAW;QACb,OAAO,GAAG,KAAK,EAAE,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC1D,CAAC;IAED,kFAAkF;IAC1E,GAAG,CAAC,KAAc;QACtB,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;IAClD,CAAC;CACJ,CAAA;AAnGY,4DAAwB;mCAAxB,wBAAwB;IADpC,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGG,gCAAiB;QACxB,yBAAU;GAHlC,wBAAwB,CAmGpC","sourcesContent":["import * as crypto from 'crypto';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport {\n AtomicFile, ChecklistResult, ReviewJsonService, WRITE_REVIEW_BIN, toError,\n} from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\n\n/** `harness` for a verdict submitted from a plain terminal — a HUMAN reviewer, with no AI harness at all. */\nexport const HARNESS_TERMINAL = 'terminal';\n\nconst WHAT_THIS_IS =\n 'PROVENANCE — written by pnpm wp-write-review beside the verdict it submitted, never by an AI. It records ' +\n 'WHO submitted that verdict (harness, session, agent — as the harness reported them to the PreToolUse ' +\n 'hook), WHICH commit and in-scope diff the reviewer was briefed on, and a hash of the verdict itself. ' +\n 'wp-finish-upsert-pr rejects a verdict with no provenance, or one edited after submission. Do not ' +\n 'hand-edit or copy it: that is forging a review.';\n\n/** A verdict exactly as `wp-write-review` accepts it — the five fields and nothing else. Data-only. */\nexport class SubmittedVerdict {\n id: string;\n status: string;\n agent: string;\n model: string;\n output: string;\n\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(id: string, status: string, agent: string, model: string, output: string) {\n this.id = id;\n this.status = status;\n this.agent = agent;\n this.model = model;\n this.output = output;\n }\n}\n\n/**\n * The record `wp-write-review` writes to `review-round<N>-<id>.provenance.json`. Data-only; field names are\n * the JSON keys, `_WHAT_THIS_IS` first so a reader learns what the file is before anything it might act on.\n */\nexport class VerdictProvenance {\n // webpieces-disable naming-convention -- the leading underscore marks a note-to-the-reader key, not data\n _WHAT_THIS_IS = WHAT_THIS_IS;\n writer: string; // always WRITE_REVIEW_BIN — a record naming anything else was not written by it\n checklistId: string;\n harness: string; // 'claude-code' | 'codex' | HARNESS_TERMINAL\n sessionId: string;\n agentId: string; // the SUBAGENT that submitted; '' only for HARNESS_TERMINAL\n agentType: string;\n headSha: string; // the commit stage ② briefed this reviewer on\n scopeHash: string; // ChecklistScopeHasher's hash of this checklist's in-scope diff at that commit\n status: string; // the status as submitted\n verdictHash: string; // VerdictProvenanceService.canonicalHash of the verdict as submitted\n writtenAt: string;\n round: number; // the N of review-round<N>-<id>.json — which review round this verdict belongs to\n\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(checklistId: string, harness: string, sessionId: string, agentId: string, agentType: string, headSha: string, scopeHash: string) {\n this.writer = WRITE_REVIEW_BIN;\n this.checklistId = checklistId;\n this.harness = harness;\n this.sessionId = sessionId;\n this.agentId = agentId;\n this.agentType = agentType;\n this.headSha = headSha;\n this.scopeHash = scopeHash;\n this.status = '';\n this.verdictHash = '';\n this.writtenAt = '';\n this.round = 0;\n }\n}\n\n/** A live verdict that stands: submitted through the bin and judged the in-scope diff as it is NOW. */\nexport const STANDING_CURRENT = 'current';\n/** Submitted through the bin, but the checklist's in-scope diff has changed since — it judged other code. */\nexport const STANDING_STALE = 'stale';\n/** No bin provenance, or edited after submission: not a reviewer's verdict at all. */\nexport const STANDING_REJECTED = 'rejected';\n/**\n * Would be STALE, but still COUNTS: staleness never triggers a re-review (issue #1053) — a green, yellow or\n * orange verdict stands whatever round it came from — and a human override for its checklist always wins\n * (issue #1051). The reason says which, and is printed verbatim.\n */\nexport const STANDING_CARRIED = 'carried';\n\n/**\n * How ONE existing verdict file stands against the branch as it is now. Data-only. Carried on the\n * checklist scan so stage ② (which briefs) and stage ③ (which blocks) read one answer.\n */\nexport class VerdictStanding {\n checklistId: string;\n standing: string; // STANDING_CURRENT | STANDING_STALE | STANDING_REJECTED | STANDING_CARRIED\n status: string; // the verdict's own green | yellow | orange | red\n fromSha: string; // the commit it was briefed on ('' when rejected)\n reason: string; // why — printed verbatim\n\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(checklistId: string, standing: string, status: string, fromSha: string, reason: string) {\n this.checklistId = checklistId;\n this.standing = standing;\n this.status = status;\n this.fromSha = fromSha;\n this.reason = reason;\n }\n}\n\n/**\n * Writes a submitted verdict WITH its provenance, and judges an existing verdict against it (issue #863).\n *\n * This is what closes the forgery the issue measured: a Codex coordinator wrote five `review-<id>.json`\n * files itself and the gate accepted them, because nothing distinguished a reviewer's verdict from a file\n * that merely had the right shape. Now a verdict counts only when `wp-write-review` wrote it — which it does\n * only for a caller the harness identified as a subagent — and only while it still says exactly what was\n * submitted.\n *\n * `@injectable(bindingScopeValues.Singleton)` so it is injected by type and drawn in the DI design.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class VerdictProvenanceService {\n constructor(\n private readonly reviewJsonService: ReviewJsonService,\n private readonly atomicFile: AtomicFile,\n ) {}\n\n /** `review-round<N>-<id>.provenance.json`, beside the verdict of the same round. */\n provenancePath(summaryPath: string, checklistId: string, round: number): string {\n return path.join(path.dirname(summaryPath), `review-round${round}-${checklistId}.provenance.json`);\n }\n\n /**\n * sha256 over the five fields in a FIXED order, so formatting, key order and whitespace outside the\n * values cannot move it — only a change to what the verdict SAYS can.\n */\n canonicalHash(verdict: SubmittedVerdict): string {\n const canonical = JSON.stringify([verdict.id, verdict.status, verdict.agent, verdict.model, verdict.output]);\n return crypto.createHash('sha256').update(canonical).digest('hex');\n }\n\n /** Write the verdict, then its provenance, both for `provenance.round`. Returns the verdict path. */\n write(summaryPath: string, verdict: SubmittedVerdict, provenance: VerdictProvenance): string {\n const verdictPath = this.reviewJsonService.checklistResultPath(summaryPath, verdict.id, provenance.round);\n provenance.status = verdict.status;\n provenance.verdictHash = this.canonicalHash(verdict);\n provenance.writtenAt = new Date().toISOString();\n this.atomicFile.writeJsonAtomic(verdictPath, verdict);\n this.atomicFile.writeJsonAtomic(this.provenancePath(summaryPath, verdict.id, provenance.round), provenance);\n return verdictPath;\n }\n\n /** The provenance for one checklist's verdict in one round, or null when there is none (or it is unreadable). */\n read(summaryPath: string, checklistId: string, round: number): VerdictProvenance | null {\n const file = this.provenancePath(summaryPath, checklistId, round);\n if (!fs.existsSync(file)) return null;\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: an unreadable record is treated as no record, which REJECTS the verdict\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n // webpieces-disable no-any-unknown -- opaque parsed JSON, narrowed field-by-field below\n const raw = JSON.parse(fs.readFileSync(file, 'utf8')) as Record<string, unknown>;\n const record = new VerdictProvenance(\n this.str(raw['checklistId']), this.str(raw['harness']), this.str(raw['sessionId']),\n this.str(raw['agentId']), this.str(raw['agentType']), this.str(raw['headSha']), this.str(raw['scopeHash']));\n record.writer = this.str(raw['writer']);\n record.status = this.str(raw['status']);\n record.verdictHash = this.str(raw['verdictHash']);\n record.writtenAt = this.str(raw['writtenAt']);\n record.round = typeof raw['round'] === 'number' && Number.isInteger(raw['round']) ? raw['round'] as number : 0;\n return record;\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n return null;\n }\n }\n\n /**\n * How one parsed verdict stands. `currentScopeHash` is this checklist's scope hash NOW ('' when it\n * could not be computed, which never marks anything stale).\n */\n // eslint-disable-next-line @typescript-eslint/max-params\n assess(summaryPath: string, result: ChecklistResult, currentScopeHash: string): VerdictStanding {\n const id = result.id;\n const round = result.round;\n const verdictFile = path.basename(this.reviewJsonService.checklistResultPath(summaryPath, id, round));\n const record = this.read(summaryPath, id, round);\n const reject = (reason: string): VerdictStanding => new VerdictStanding(id, STANDING_REJECTED, result.status, '', reason);\n if (record === null) {\n const file = this.provenancePath(summaryPath, id, round);\n const why = fs.existsSync(file) ? `${path.basename(file)} is unreadable` : `no ${path.basename(file)}`;\n return reject(`${verdictFile} was not submitted through pnpm ${WRITE_REVIEW_BIN} (${why}) — a hand-written verdict is not a review`);\n }\n if (record.writer !== WRITE_REVIEW_BIN || record.checklistId !== id || record.round !== round) {\n return reject(`${path.basename(this.provenancePath(summaryPath, id, round))} was not written by ${WRITE_REVIEW_BIN} for this checklist and round`);\n }\n if (record.agentId.trim() === '' && record.harness !== HARNESS_TERMINAL) {\n return reject(`${verdictFile} was submitted by the coordinating agent, not a reviewer subagent`);\n }\n const submitted = new SubmittedVerdict(id, result.status, result.agent, result.model, result.output);\n if (this.canonicalHash(submitted) !== record.verdictHash) {\n return reject(`${verdictFile} was EDITED after ${WRITE_REVIEW_BIN} wrote it — a verdict is the reviewer's words, not a draft`);\n }\n if (currentScopeHash !== '' && record.scopeHash !== currentScopeHash) {\n return new VerdictStanding(id, STANDING_STALE, result.status, record.headSha,\n `in-scope files CHANGED since the verdict was written at ${this.short(record.headSha)}`);\n }\n return new VerdictStanding(id, STANDING_CURRENT, result.status, record.headSha,\n `in-scope files unchanged since ${this.short(record.headSha)}`);\n }\n\n /** The first 8 characters of a sha, the way every banner line prints one. */\n short(sha: string): string {\n return sha === '' ? '(unknown sha)' : sha.slice(0, 8);\n }\n\n // webpieces-disable no-any-unknown -- one opaque JSON value, narrowed to a string\n private str(value: unknown): string {\n return typeof value === 'string' ? value : '';\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"verdict-provenance.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr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ACnI,CAAC;QACD,IAAI,gBAAgB,KAAK,EAAE,IAAI,MAAM,CAAC,SAAS,KAAK,gBAAgB,EAAE,CAAC;YACnE,OAAO,IAAI,eAAe,CAAC,EAAE,EAAE,sBAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,EACxE,2DAA2D,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;QACjG,CAAC;QACD,OAAO,IAAI,eAAe,CAAC,EAAE,EAAE,wBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,EAC1E,kCAAkC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IACxE,CAAC;IAED,6EAA6E;IAC7E,KAAK,CAAC,GAAW;QACb,OAAO,GAAG,KAAK,EAAE,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC1D,CAAC;IAED,kFAAkF;IAC1E,GAAG,CAAC,KAAc;QACtB,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;IAClD,CAAC;CACJ,CAAA;AAnGY,4DAAwB;mCAAxB,wBAAwB;IADpC,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGG,gCAAiB;QACxB,2BAAU;GAHlC,wBAAwB,CAmGpC","sourcesContent":["import * as crypto from 'crypto';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport { AtomicFile } from '@webpieces/tooling-common';\nimport { toError } from '@webpieces/tooling-common/to-error';\nimport { ChecklistResult, ReviewJsonService } from '@webpieces/rules-config';\nimport { WRITE_REVIEW_BIN } from '@webpieces/repo-workflow-core';\nimport { injectable, bindingScopeValues } from 'inversify';\n\n/** `harness` for a verdict submitted from a plain terminal — a HUMAN reviewer, with no AI harness at all. */\nexport const HARNESS_TERMINAL = 'terminal';\n\nconst WHAT_THIS_IS =\n 'PROVENANCE — written by pnpm wp-write-review beside the verdict it submitted, never by an AI. It records ' +\n 'WHO submitted that verdict (harness, session, agent — as the harness reported them to the PreToolUse ' +\n 'hook), WHICH commit and in-scope diff the reviewer was briefed on, and a hash of the verdict itself. ' +\n 'wp-finish-upsert-pr rejects a verdict with no provenance, or one edited after submission. Do not ' +\n 'hand-edit or copy it: that is forging a review.';\n\n/** A verdict exactly as `wp-write-review` accepts it — the five fields and nothing else. Data-only. */\nexport class SubmittedVerdict {\n id: string;\n status: string;\n agent: string;\n model: string;\n output: string;\n\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(id: string, status: string, agent: string, model: string, output: string) {\n this.id = id;\n this.status = status;\n this.agent = agent;\n this.model = model;\n this.output = output;\n }\n}\n\n/**\n * The record `wp-write-review` writes to `review-round<N>-<id>.provenance.json`. Data-only; field names are\n * the JSON keys, `_WHAT_THIS_IS` first so a reader learns what the file is before anything it might act on.\n */\nexport class VerdictProvenance {\n // webpieces-disable naming-convention -- the leading underscore marks a note-to-the-reader key, not data\n _WHAT_THIS_IS = WHAT_THIS_IS;\n writer: string; // always WRITE_REVIEW_BIN — a record naming anything else was not written by it\n checklistId: string;\n harness: string; // 'claude-code' | 'codex' | HARNESS_TERMINAL\n sessionId: string;\n agentId: string; // the SUBAGENT that submitted; '' only for HARNESS_TERMINAL\n agentType: string;\n headSha: string; // the commit stage ② briefed this reviewer on\n scopeHash: string; // ChecklistScopeHasher's hash of this checklist's in-scope diff at that commit\n status: string; // the status as submitted\n verdictHash: string; // VerdictProvenanceService.canonicalHash of the verdict as submitted\n writtenAt: string;\n round: number; // the N of review-round<N>-<id>.json — which review round this verdict belongs to\n\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(checklistId: string, harness: string, sessionId: string, agentId: string, agentType: string, headSha: string, scopeHash: string) {\n this.writer = WRITE_REVIEW_BIN;\n this.checklistId = checklistId;\n this.harness = harness;\n this.sessionId = sessionId;\n this.agentId = agentId;\n this.agentType = agentType;\n this.headSha = headSha;\n this.scopeHash = scopeHash;\n this.status = '';\n this.verdictHash = '';\n this.writtenAt = '';\n this.round = 0;\n }\n}\n\n/** A live verdict that stands: submitted through the bin and judged the in-scope diff as it is NOW. */\nexport const STANDING_CURRENT = 'current';\n/** Submitted through the bin, but the checklist's in-scope diff has changed since — it judged other code. */\nexport const STANDING_STALE = 'stale';\n/** No bin provenance, or edited after submission: not a reviewer's verdict at all. */\nexport const STANDING_REJECTED = 'rejected';\n/**\n * Would be STALE, but still COUNTS: staleness never triggers a re-review (issue #1053) — a green, yellow or\n * orange verdict stands whatever round it came from — and a human override for its checklist always wins\n * (issue #1051). The reason says which, and is printed verbatim.\n */\nexport const STANDING_CARRIED = 'carried';\n\n/**\n * How ONE existing verdict file stands against the branch as it is now. Data-only. Carried on the\n * checklist scan so stage ② (which briefs) and stage ③ (which blocks) read one answer.\n */\nexport class VerdictStanding {\n checklistId: string;\n standing: string; // STANDING_CURRENT | STANDING_STALE | STANDING_REJECTED | STANDING_CARRIED\n status: string; // the verdict's own green | yellow | orange | red\n fromSha: string; // the commit it was briefed on ('' when rejected)\n reason: string; // why — printed verbatim\n\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(checklistId: string, standing: string, status: string, fromSha: string, reason: string) {\n this.checklistId = checklistId;\n this.standing = standing;\n this.status = status;\n this.fromSha = fromSha;\n this.reason = reason;\n }\n}\n\n/**\n * Writes a submitted verdict WITH its provenance, and judges an existing verdict against it (issue #863).\n *\n * This is what closes the forgery the issue measured: a Codex coordinator wrote five `review-<id>.json`\n * files itself and the gate accepted them, because nothing distinguished a reviewer's verdict from a file\n * that merely had the right shape. Now a verdict counts only when `wp-write-review` wrote it — which it does\n * only for a caller the harness identified as a subagent — and only while it still says exactly what was\n * submitted.\n *\n * `@injectable(bindingScopeValues.Singleton)` so it is injected by type and drawn in the DI design.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class VerdictProvenanceService {\n constructor(\n private readonly reviewJsonService: ReviewJsonService,\n private readonly atomicFile: AtomicFile,\n ) {}\n\n /** `review-round<N>-<id>.provenance.json`, beside the verdict of the same round. */\n provenancePath(summaryPath: string, checklistId: string, round: number): string {\n return path.join(path.dirname(summaryPath), `review-round${round}-${checklistId}.provenance.json`);\n }\n\n /**\n * sha256 over the five fields in a FIXED order, so formatting, key order and whitespace outside the\n * values cannot move it — only a change to what the verdict SAYS can.\n */\n canonicalHash(verdict: SubmittedVerdict): string {\n const canonical = JSON.stringify([verdict.id, verdict.status, verdict.agent, verdict.model, verdict.output]);\n return crypto.createHash('sha256').update(canonical).digest('hex');\n }\n\n /** Write the verdict, then its provenance, both for `provenance.round`. Returns the verdict path. */\n write(summaryPath: string, verdict: SubmittedVerdict, provenance: VerdictProvenance): string {\n const verdictPath = this.reviewJsonService.checklistResultPath(summaryPath, verdict.id, provenance.round);\n provenance.status = verdict.status;\n provenance.verdictHash = this.canonicalHash(verdict);\n provenance.writtenAt = new Date().toISOString();\n this.atomicFile.writeJsonAtomic(verdictPath, verdict);\n this.atomicFile.writeJsonAtomic(this.provenancePath(summaryPath, verdict.id, provenance.round), provenance);\n return verdictPath;\n }\n\n /** The provenance for one checklist's verdict in one round, or null when there is none (or it is unreadable). */\n read(summaryPath: string, checklistId: string, round: number): VerdictProvenance | null {\n const file = this.provenancePath(summaryPath, checklistId, round);\n if (!fs.existsSync(file)) return null;\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: an unreadable record is treated as no record, which REJECTS the verdict\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n // webpieces-disable no-any-unknown -- opaque parsed JSON, narrowed field-by-field below\n const raw = JSON.parse(fs.readFileSync(file, 'utf8')) as Record<string, unknown>;\n const record = new VerdictProvenance(\n this.str(raw['checklistId']), this.str(raw['harness']), this.str(raw['sessionId']),\n this.str(raw['agentId']), this.str(raw['agentType']), this.str(raw['headSha']), this.str(raw['scopeHash']));\n record.writer = this.str(raw['writer']);\n record.status = this.str(raw['status']);\n record.verdictHash = this.str(raw['verdictHash']);\n record.writtenAt = this.str(raw['writtenAt']);\n record.round = typeof raw['round'] === 'number' && Number.isInteger(raw['round']) ? raw['round'] as number : 0;\n return record;\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n return null;\n }\n }\n\n /**\n * How one parsed verdict stands. `currentScopeHash` is this checklist's scope hash NOW ('' when it\n * could not be computed, which never marks anything stale).\n */\n // eslint-disable-next-line @typescript-eslint/max-params\n assess(summaryPath: string, result: ChecklistResult, currentScopeHash: string): VerdictStanding {\n const id = result.id;\n const round = result.round;\n const verdictFile = path.basename(this.reviewJsonService.checklistResultPath(summaryPath, id, round));\n const record = this.read(summaryPath, id, round);\n const reject = (reason: string): VerdictStanding => new VerdictStanding(id, STANDING_REJECTED, result.status, '', reason);\n if (record === null) {\n const file = this.provenancePath(summaryPath, id, round);\n const why = fs.existsSync(file) ? `${path.basename(file)} is unreadable` : `no ${path.basename(file)}`;\n return reject(`${verdictFile} was not submitted through pnpm ${WRITE_REVIEW_BIN} (${why}) — a hand-written verdict is not a review`);\n }\n if (record.writer !== WRITE_REVIEW_BIN || record.checklistId !== id || record.round !== round) {\n return reject(`${path.basename(this.provenancePath(summaryPath, id, round))} was not written by ${WRITE_REVIEW_BIN} for this checklist and round`);\n }\n if (record.agentId.trim() === '' && record.harness !== HARNESS_TERMINAL) {\n return reject(`${verdictFile} was submitted by the coordinating agent, not a reviewer subagent`);\n }\n const submitted = new SubmittedVerdict(id, result.status, result.agent, result.model, result.output);\n if (this.canonicalHash(submitted) !== record.verdictHash) {\n return reject(`${verdictFile} was EDITED after ${WRITE_REVIEW_BIN} wrote it — a verdict is the reviewer's words, not a draft`);\n }\n if (currentScopeHash !== '' && record.scopeHash !== currentScopeHash) {\n return new VerdictStanding(id, STANDING_STALE, result.status, record.headSha,\n `in-scope files CHANGED since the verdict was written at ${this.short(record.headSha)}`);\n }\n return new VerdictStanding(id, STANDING_CURRENT, result.status, record.headSha,\n `in-scope files unchanged since ${this.short(record.headSha)}`);\n }\n\n /** The first 8 characters of a sha, the way every banner line prints one. */\n short(sha: string): string {\n return sha === '' ? '(unknown sha)' : sha.slice(0, 8);\n }\n\n // webpieces-disable no-any-unknown -- one opaque JSON value, narrowed to a string\n private str(value: unknown): string {\n return typeof value === 'string' ? value : '';\n }\n}\n"]}
|