@webpieces/pr-gate 0.4.718 → 0.4.720
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 +4 -5
- package/src/dashboard/checklist-comment-renderer.js +2 -4
- package/src/dashboard/checklist-comment-renderer.js.map +1 -1
- package/src/dashboard/dashboard.js +0 -2
- package/src/dashboard/dashboard.js.map +1 -1
- package/src/scripts/commands/finish-upsert-pr-command.js +9 -10
- package/src/scripts/commands/finish-upsert-pr-command.js.map +1 -1
- package/src/scripts/commands/review-upsert-pr-command.d.ts +2 -2
- package/src/scripts/commands/review-upsert-pr-command.js +5 -5
- package/src/scripts/commands/review-upsert-pr-command.js.map +1 -1
- package/src/scripts/pr-gate-app.d.ts +2 -13
- package/src/scripts/pr-gate-app.js +1 -20
- package/src/scripts/pr-gate-app.js.map +1 -1
- package/src/scripts/workflow/build-affected.d.ts +28 -1
- package/src/scripts/workflow/build-affected.js +38 -3
- package/src/scripts/workflow/build-affected.js.map +1 -1
- package/src/scripts/workflow/checklist-scanner.d.ts +21 -24
- package/src/scripts/workflow/checklist-scanner.js +35 -40
- package/src/scripts/workflow/checklist-scanner.js.map +1 -1
- package/src/scripts/workflow/review-report.d.ts +3 -3
- package/src/scripts/workflow/review-report.js +3 -3
- package/src/scripts/workflow/review-report.js.map +1 -1
- package/src/scripts/workflow/reviewer-verdict-gate.js +2 -2
- package/src/scripts/workflow/reviewer-verdict-gate.js.map +1 -1
- package/src/scripts/commands/authorize-command.d.ts +0 -82
- package/src/scripts/commands/authorize-command.js +0 -205
- package/src/scripts/commands/authorize-command.js.map +0 -1
- package/src/scripts/commands/check-auth-command.d.ts +0 -33
- package/src/scripts/commands/check-auth-command.js +0 -99
- package/src/scripts/commands/check-auth-command.js.map +0 -1
- package/src/scripts/workflow/authorization-context-resolver.d.ts +0 -63
- package/src/scripts/workflow/authorization-context-resolver.js +0 -107
- package/src/scripts/workflow/authorization-context-resolver.js.map +0 -1
- package/src/scripts/wp-authorize.d.ts +0 -2
- package/src/scripts/wp-authorize.js +0 -22
- package/src/scripts/wp-authorize.js.map +0 -1
- package/src/scripts/wp-check-auth.d.ts +0 -2
- package/src/scripts/wp-check-auth.js +0 -16
- package/src/scripts/wp-check-auth.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pr-gate-app.js","sourceRoot":"","sources":["../../../../../../packages/tooling/pr-gate/src/scripts/pr-gate-app.ts"],"names":[],"mappings":";;;;AAAA,0DAAyD;AACzD,yCAA2D;AAC3D,0EAAqE;AACrE,4EAAuE;AACvE,gFAA0E;AAC1E,kFAA4E;AAC5E,gEAA4D;AAE5D,wFAAkF;AAClF,gEAA2D;AAC3D,kEAA6D;AAC7D,oEAAgE;AAChE,sEAAiE;AACjE,kFAAmG;AACnG,4EAAuE;AACvE,4DAAsE;AACtE,kEAA6E;AAC7E,gFAAgG;AAChG,8DAA8D;AAC9D,0DAAoE;AAEpE;;;;;GAKG;AAGI,IAAM,SAAS,GAAf,MAAM,SAAS;IAEG;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IAjBrB,YACqB,kBAAsC,EACtC,mBAAwC,EACxC,oBAA0C,EAC1C,qBAA4C,EAC5C,cAA8B,EAC9B,wBAAkD,EAClD,aAA4B,EAC5B,cAA8B,EAC9B,gBAAkC,EAClC,gBAAkC,EAClC,qBAA4C,EAC5C,mBAAwC,EACxC,YAA0B,EAC1B,cAA8B,EAC9B,oBAA0C,EAC1C,iBAAoC,EACpC,cAA8B;QAhB9B,uBAAkB,GAAlB,kBAAkB,CAAoB;QACtC,wBAAmB,GAAnB,mBAAmB,CAAqB;QACxC,yBAAoB,GAApB,oBAAoB,CAAsB;QAC1C,0BAAqB,GAArB,qBAAqB,CAAuB;QAC5C,mBAAc,GAAd,cAAc,CAAgB;QAC9B,6BAAwB,GAAxB,wBAAwB,CAA0B;QAClD,kBAAa,GAAb,aAAa,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,gBAAgB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;IAED,6FAA6F;IAC7F,SAAS,CAAC,IAAe;QACrB,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;IAED,+GAA+G;IAC/G,OAAO;QACH,OAAO,IAAI,CAAC,cAAc,CAAC,GAAG,EAAE,CAAC;IACrC,CAAC;CACJ,CAAA;AA3IY,8BAAS;oBAAT,SAAS;IAFrB,IAAA,6BAAc,GAAE;IAChB,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGI,yCAAkB;QACjB,2CAAmB;QAClB,8CAAoB;QACnB,gDAAqB;QAC5B,gCAAc;QACJ,sDAAwB;QACnC,+BAAa;QACZ,iCAAc;QACZ,oCAAgB;QAChB,qCAAgB;QACX,gDAAqB;QACvB,2CAAmB;QAC1B,4BAAY;QACV,iCAAc;QACR,8CAAoB;QACvB,kCAAiB;QACpB,6BAAc;GAlB1C,SAAS,CA2IrB","sourcesContent":["import { DocumentDesign } from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { StartUpdateCommand } from './commands/start-update-command';\nimport { FinishUpdateCommand } from './commands/finish-update-command';\nimport { StartUpsertPrCommand } from './commands/start-upsert-pr-command';\nimport { FinishUpsertPrCommand } from './commands/finish-upsert-pr-command';\nimport { CleanupCommand } from './commands/cleanup-command';\nimport { CleanupOptions } from './commands/cleanup-options';\nimport { CheckoutCleanMainCommand } from './commands/checkout-clean-main-command';\nimport { LandPrCommand } from './commands/land-pr-command';\nimport { CheckPrCommand } from './commands/check-pr-command';\nimport { AuthorizeCommand } from './commands/authorize-command';\nimport { CheckAuthCommand } from './commands/check-auth-command';\nimport { ReviewUpsertPrCommand, ReviewUpsertPrOptions } from './commands/review-upsert-pr-command';\nimport { ReapWorktreeCommand } from './commands/reap-worktree-command';\nimport { BuildCommand, BuildOptions } from './commands/build-command';\nimport { PushDevCommand, PushDevOptions } from './commands/push-dev-command';\nimport { FinishPushDevCommand, FinishPushDevOptions } from './commands/finish-push-dev-command';\nimport { PushDevStateStore } from './workflow/push-dev-state';\nimport { CliArgSet, RepoRootFinder } from '@webpieces/rules-config';\n\n/**\n * The pr-gate application root. `container.get(PrGateApp)` resolves the entire workflow DAG (the command\n * classes → the injected git/merge/dashboard services). `@DocumentDesign` marks it the\n * top-of-DAG the DI-design analyzer roots on, so `role:app` pr-gate draws its design. Each `bin/*`\n * entry resolves THIS and calls the matching command method.\n */\n@DocumentDesign()\n@injectable(bindingScopeValues.Singleton)\nexport class PrGateApp {\n constructor(\n private readonly startUpdateCommand: StartUpdateCommand,\n private readonly finishUpdateCommand: FinishUpdateCommand,\n private readonly startUpsertPrCommand: StartUpsertPrCommand,\n private readonly finishUpsertPrCommand: FinishUpsertPrCommand,\n private readonly cleanupCommand: CleanupCommand,\n private readonly checkoutCleanMainCommand: CheckoutCleanMainCommand,\n private readonly landPrCommand: LandPrCommand,\n private readonly checkPrCommand: CheckPrCommand,\n private readonly authorizeCommand: AuthorizeCommand,\n private readonly checkAuthCommand: CheckAuthCommand,\n private readonly reviewUpsertPrCommand: ReviewUpsertPrCommand,\n private readonly reapWorktreeCommand: ReapWorktreeCommand,\n private readonly buildCommand: BuildCommand,\n private readonly pushDevCommand: PushDevCommand,\n private readonly finishPushDevCommand: FinishPushDevCommand,\n private readonly pushDevStateStore: PushDevStateStore,\n private readonly repoRootFinder: RepoRootFinder,\n ) {}\n\n /**\n * Refuse `command` while a `wp-push-dev --resolve` is half-finished.\n *\n * Enforced HERE, at the one place every bin funnels through, rather than in each command: a resolve\n * parks the checkout on a throwaway branch, so every command below would act on a branch that is not\n * the one it thinks it is. Putting the check in nine constructors is nine chances to forget it in the\n * tenth. PushDevStateStore owns the blocked list AND renders the hint from it, so the two cannot drift.\n */\n private assertNoResolveInProgress(command: string): void {\n if (!this.pushDevStateStore.isBlockedDuringResolve(command)) return;\n this.pushDevStateStore.assertIdle(this.repoRootFinder.resolveRepoRoot(process.cwd()), command);\n }\n\n /** `wp-push-dev`: publish a DISPOSABLE copy of this branch for the shared dev environment. No PR, no build. */\n pushDev(opts: PushDevOptions = new PushDevOptions()): Promise<void> {\n return this.pushDevCommand.run(opts);\n }\n\n /** `wp-finish-push-dev`: commit a resolved dev composition and publish it (conflict path only). */\n finishPushDev(opts: FinishPushDevOptions = new FinishPushDevOptions()): Promise<void> {\n return this.finishPushDevCommand.run(opts);\n }\n\n /**\n * INTERNAL (`wp-reap-worktree.js`, no `bin` entry): remove ONE named worktree and its branch.\n * `wp-land-pr` spawns it with cwd = the primary clone so the tree it just landed from can be\n * reaped by a process that is not standing in it.\n */\n reapWorktree(args: string[]): Promise<void> {\n return this.reapWorktreeCommand.run(args);\n }\n\n /**\n * `wp-build`: run this repo's ONE configured build (`commands.pr-gate.buildCommand`) — the same\n * command, resolved by the same resolver, that the PR gate's build stage runs. Not blocked during a\n * `wp-push-dev --resolve`: it mutates nothing and reads no branch state.\n */\n build(opts: BuildOptions): Promise<void> {\n return this.buildCommand.run(opts);\n }\n\n /** `wp-start-update`: 3-point squash-update from main (no PR). */\n startUpdate(): Promise<void> {\n this.assertNoResolveInProgress('wp-start-update');\n return this.startUpdateCommand.run();\n }\n\n /** `wp-finish-update`: validate + finalize a resolved 3-point merge (no PR). */\n finishUpdate(): Promise<void> {\n this.assertNoResolveInProgress('wp-finish-update');\n return this.finishUpdateCommand.run();\n }\n\n /** `wp-start-upsert-pr`: update from main (3-point merge), hand off review.json. No build gate, no push. */\n startUpsertPr(): Promise<void> {\n this.assertNoResolveInProgress('wp-start-upsert-pr');\n return this.startUpsertPrCommand.run();\n }\n\n /** `wp-finish-upsert-pr`: finalize merge, authoritative build gate, dashboard, create/update PR. */\n finishUpsertPr(): Promise<void> {\n this.assertNoResolveInProgress('wp-finish-upsert-pr');\n return this.finishUpsertPrCommand.run();\n }\n\n /**\n * `wp-cleanup`: reap what is provably merged AND every zero-commit husk, then report the rest with\n * the exact flags that take it. `options` carries what argv said — see CleanupOptions.\n */\n cleanup(options: CleanupOptions): Promise<void> {\n this.assertNoResolveInProgress('wp-cleanup');\n return this.cleanupCommand.run(options);\n }\n\n /**\n * `wp-checkout-clean-main`: go to main, fast-forward it, reap dead worktrees and branches, and sweep\n * the orphan directories a project move leaves behind. Replaces `git checkout main && git pull\n * origin main` outright — see CheckoutCleanMainCommand for why the old pair must stop being accepted\n * rather than surviving beside this.\n */\n checkoutCleanMain(): Promise<void> {\n this.assertNoResolveInProgress('wp-checkout-clean-main');\n return this.checkoutCleanMainCommand.run();\n }\n\n /** `wp-land-pr`: squash-merge this branch's PR into main with the compact commit body. */\n landPr(): Promise<void> {\n this.assertNoResolveInProgress('wp-land-pr');\n return this.landPrCommand.run();\n }\n\n /**\n * `wp-review-upsert-pr`: STAGE ② — validate the 3-point merge, run the build gate, extract this\n * branch's diff, and brief the reviewer subagents. Unlike the report-only command it replaces, this CAN\n * fail — before any reviewer is spawned, so a broken branch costs no reviewer tokens.\n */\n reviewUpsertPr(opts: ReviewUpsertPrOptions = new ReviewUpsertPrOptions()): Promise<void> {\n this.assertNoResolveInProgress('wp-review-upsert-pr');\n return this.reviewUpsertPrCommand.run(opts);\n }\n\n /**\n * `wp-authorize`: HUMAN ONLY — sign an authorization allowing one review checklist to be overridden.\n * Reads from /dev/tty, so an agent cannot drive it. See AuthorizeCommand for why that is the mechanism.\n */\n authorize(args: CliArgSet): void {\n this.authorizeCommand.run(args);\n }\n\n /** `wp-check-auth`: read-only verification of those authorizations — the half agents run. */\n checkAuth(args: CliArgSet): void {\n this.checkAuthCommand.run(args);\n }\n\n /** `wp-check-pr`: READ-ONLY CI check — verify the PR body carries a valid HMAC gate token for its head sha. */\n checkPr(): Promise<void> {\n return this.checkPrCommand.run();\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"pr-gate-app.js","sourceRoot":"","sources":["../../../../../../packages/tooling/pr-gate/src/scripts/pr-gate-app.ts"],"names":[],"mappings":";;;;AAAA,0DA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OAAO,IAAI,CAAC,qBAAqB,CAAC,GAAG,EAAE,CAAC;IAC5C,CAAC;IAED;;;OAGG;IACH,OAAO,CAAC,OAAuB;QAC3B,IAAI,CAAC,yBAAyB,CAAC,YAAY,CAAC,CAAC;QAC7C,OAAO,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC5C,CAAC;IAED;;;;;OAKG;IACH,iBAAiB;QACb,IAAI,CAAC,yBAAyB,CAAC,wBAAwB,CAAC,CAAC;QACzD,OAAO,IAAI,CAAC,wBAAwB,CAAC,GAAG,EAAE,CAAC;IAC/C,CAAC;IAED,0FAA0F;IAC1F,MAAM;QACF,IAAI,CAAC,yBAAyB,CAAC,YAAY,CAAC,CAAC;QAC7C,OAAO,IAAI,CAAC,aAAa,CAAC,GAAG,EAAE,CAAC;IACpC,CAAC;IAED;;;;OAIG;IACH,cAAc,CAAC,OAA8B,IAAI,gDAAqB,EAAE;QACpE,IAAI,CAAC,yBAAyB,CAAC,qBAAqB,CAAC,CAAC;QACtD,OAAO,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAChD,CAAC;IAED,+GAA+G;IAC/G,OAAO;QACH,OAAO,IAAI,CAAC,cAAc,CAAC,GAAG,EAAE,CAAC;IACrC,CAAC;CACJ,CAAA;AA5HY,8BAAS;oBAAT,SAAS;IAFrB,IAAA,6BAAc,GAAE;IAChB,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGI,yCAAkB;QACjB,2CAAmB;QAClB,8CAAoB;QACnB,gDAAqB;QAC5B,gCAAc;QACJ,sDAAwB;QACnC,+BAAa;QACZ,iCAAc;QACP,gDAAqB;QACvB,2CAAmB;QAC1B,4BAAY;QACV,iCAAc;QACR,8CAAoB;QACvB,kCAAiB;QACpB,6BAAc;GAhB1C,SAAS,CA4HrB","sourcesContent":["import { DocumentDesign } from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { StartUpdateCommand } from './commands/start-update-command';\nimport { FinishUpdateCommand } from './commands/finish-update-command';\nimport { StartUpsertPrCommand } from './commands/start-upsert-pr-command';\nimport { FinishUpsertPrCommand } from './commands/finish-upsert-pr-command';\nimport { CleanupCommand } from './commands/cleanup-command';\nimport { CleanupOptions } from './commands/cleanup-options';\nimport { CheckoutCleanMainCommand } from './commands/checkout-clean-main-command';\nimport { LandPrCommand } from './commands/land-pr-command';\nimport { CheckPrCommand } from './commands/check-pr-command';\nimport { ReviewUpsertPrCommand, ReviewUpsertPrOptions } from './commands/review-upsert-pr-command';\nimport { ReapWorktreeCommand } from './commands/reap-worktree-command';\nimport { BuildCommand, BuildOptions } from './commands/build-command';\nimport { PushDevCommand, PushDevOptions } from './commands/push-dev-command';\nimport { FinishPushDevCommand, FinishPushDevOptions } from './commands/finish-push-dev-command';\nimport { PushDevStateStore } from './workflow/push-dev-state';\nimport { RepoRootFinder } from '@webpieces/rules-config';\n\n/**\n * The pr-gate application root. `container.get(PrGateApp)` resolves the entire workflow DAG (the command\n * classes → the injected git/merge/dashboard services). `@DocumentDesign` marks it the\n * top-of-DAG the DI-design analyzer roots on, so `role:app` pr-gate draws its design. Each `bin/*`\n * entry resolves THIS and calls the matching command method.\n */\n@DocumentDesign()\n@injectable(bindingScopeValues.Singleton)\nexport class PrGateApp {\n constructor(\n private readonly startUpdateCommand: StartUpdateCommand,\n private readonly finishUpdateCommand: FinishUpdateCommand,\n private readonly startUpsertPrCommand: StartUpsertPrCommand,\n private readonly finishUpsertPrCommand: FinishUpsertPrCommand,\n private readonly cleanupCommand: CleanupCommand,\n private readonly checkoutCleanMainCommand: CheckoutCleanMainCommand,\n private readonly landPrCommand: LandPrCommand,\n private readonly checkPrCommand: CheckPrCommand,\n private readonly reviewUpsertPrCommand: ReviewUpsertPrCommand,\n private readonly reapWorktreeCommand: ReapWorktreeCommand,\n private readonly buildCommand: BuildCommand,\n private readonly pushDevCommand: PushDevCommand,\n private readonly finishPushDevCommand: FinishPushDevCommand,\n private readonly pushDevStateStore: PushDevStateStore,\n private readonly repoRootFinder: RepoRootFinder,\n ) {}\n\n /**\n * Refuse `command` while a `wp-push-dev --resolve` is half-finished.\n *\n * Enforced HERE, at the one place every bin funnels through, rather than in each command: a resolve\n * parks the checkout on a throwaway branch, so every command below would act on a branch that is not\n * the one it thinks it is. Putting the check in nine constructors is nine chances to forget it in the\n * tenth. PushDevStateStore owns the blocked list AND renders the hint from it, so the two cannot drift.\n */\n private assertNoResolveInProgress(command: string): void {\n if (!this.pushDevStateStore.isBlockedDuringResolve(command)) return;\n this.pushDevStateStore.assertIdle(this.repoRootFinder.resolveRepoRoot(process.cwd()), command);\n }\n\n /** `wp-push-dev`: publish a DISPOSABLE copy of this branch for the shared dev environment. No PR, no build. */\n pushDev(opts: PushDevOptions = new PushDevOptions()): Promise<void> {\n return this.pushDevCommand.run(opts);\n }\n\n /** `wp-finish-push-dev`: commit a resolved dev composition and publish it (conflict path only). */\n finishPushDev(opts: FinishPushDevOptions = new FinishPushDevOptions()): Promise<void> {\n return this.finishPushDevCommand.run(opts);\n }\n\n /**\n * INTERNAL (`wp-reap-worktree.js`, no `bin` entry): remove ONE named worktree and its branch.\n * `wp-land-pr` spawns it with cwd = the primary clone so the tree it just landed from can be\n * reaped by a process that is not standing in it.\n */\n reapWorktree(args: string[]): Promise<void> {\n return this.reapWorktreeCommand.run(args);\n }\n\n /**\n * `wp-build`: run this repo's ONE configured build (`commands.pr-gate.buildCommand`) — the same\n * command, resolved by the same resolver, that the PR gate's build stage runs. Not blocked during a\n * `wp-push-dev --resolve`: it mutates nothing and reads no branch state.\n */\n build(opts: BuildOptions): Promise<void> {\n return this.buildCommand.run(opts);\n }\n\n /** `wp-start-update`: 3-point squash-update from main (no PR). */\n startUpdate(): Promise<void> {\n this.assertNoResolveInProgress('wp-start-update');\n return this.startUpdateCommand.run();\n }\n\n /** `wp-finish-update`: validate + finalize a resolved 3-point merge (no PR). */\n finishUpdate(): Promise<void> {\n this.assertNoResolveInProgress('wp-finish-update');\n return this.finishUpdateCommand.run();\n }\n\n /** `wp-start-upsert-pr`: update from main (3-point merge), hand off review.json. No build gate, no push. */\n startUpsertPr(): Promise<void> {\n this.assertNoResolveInProgress('wp-start-upsert-pr');\n return this.startUpsertPrCommand.run();\n }\n\n /** `wp-finish-upsert-pr`: finalize merge, authoritative build gate, dashboard, create/update PR. */\n finishUpsertPr(): Promise<void> {\n this.assertNoResolveInProgress('wp-finish-upsert-pr');\n return this.finishUpsertPrCommand.run();\n }\n\n /**\n * `wp-cleanup`: reap what is provably merged AND every zero-commit husk, then report the rest with\n * the exact flags that take it. `options` carries what argv said — see CleanupOptions.\n */\n cleanup(options: CleanupOptions): Promise<void> {\n this.assertNoResolveInProgress('wp-cleanup');\n return this.cleanupCommand.run(options);\n }\n\n /**\n * `wp-checkout-clean-main`: go to main, fast-forward it, reap dead worktrees and branches, and sweep\n * the orphan directories a project move leaves behind. Replaces `git checkout main && git pull\n * origin main` outright — see CheckoutCleanMainCommand for why the old pair must stop being accepted\n * rather than surviving beside this.\n */\n checkoutCleanMain(): Promise<void> {\n this.assertNoResolveInProgress('wp-checkout-clean-main');\n return this.checkoutCleanMainCommand.run();\n }\n\n /** `wp-land-pr`: squash-merge this branch's PR into main with the compact commit body. */\n landPr(): Promise<void> {\n this.assertNoResolveInProgress('wp-land-pr');\n return this.landPrCommand.run();\n }\n\n /**\n * `wp-review-upsert-pr`: STAGE ② — validate the 3-point merge, run the build gate, extract this\n * branch's diff, and brief the reviewer subagents. Unlike the report-only command it replaces, this CAN\n * fail — before any reviewer is spawned, so a broken branch costs no reviewer tokens.\n */\n reviewUpsertPr(opts: ReviewUpsertPrOptions = new ReviewUpsertPrOptions()): Promise<void> {\n this.assertNoResolveInProgress('wp-review-upsert-pr');\n return this.reviewUpsertPrCommand.run(opts);\n }\n\n /** `wp-check-pr`: READ-ONLY CI check — verify the PR body carries a valid HMAC gate token for its head sha. */\n checkPr(): Promise<void> {\n return this.checkPrCommand.run();\n }\n}\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { BuildsLog } from '@webpieces/rules-config';
|
|
2
|
+
import { CodexGuardPresence } from '@webpieces/ai-hook-rules';
|
|
2
3
|
import { BuildGateLog } from './build-gate-log';
|
|
3
4
|
import { StageOutputLog } from './stage-output-log';
|
|
4
5
|
/**
|
|
@@ -13,12 +14,18 @@ export declare class BuildGateOptions {
|
|
|
13
14
|
stage: string;
|
|
14
15
|
constructor(label: string, rerunCommand: string, failureHeadline: string, stage: string);
|
|
15
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* The rule name the guard-presence refusal is reported under, so it is greppable from a transcript the
|
|
19
|
+
* same way `too-many-concurrent-builds` is.
|
|
20
|
+
*/
|
|
21
|
+
export declare const CODEX_GUARDS_NEVER_RAN = "codex-guards-never-ran";
|
|
16
22
|
/** Runs the authoritative nx-affected build gate for wp-review-upsert-pr and wp-finish-upsert-pr. */
|
|
17
23
|
export declare class BuildAffected {
|
|
18
24
|
private readonly buildLog;
|
|
19
25
|
private readonly buildsLog;
|
|
20
26
|
private readonly stageConsole;
|
|
21
|
-
|
|
27
|
+
private readonly guardPresence;
|
|
28
|
+
constructor(buildLog: BuildGateLog, buildsLog: BuildsLog, stageConsole: StageOutputLog, guardPresence: CodexGuardPresence);
|
|
22
29
|
/**
|
|
23
30
|
* Resolve the exact build command this gate will run: the project's configured
|
|
24
31
|
* PrGateConfig.buildCommand, or the default affected-ci command when none is set.
|
|
@@ -40,6 +47,26 @@ export declare class BuildAffected {
|
|
|
40
47
|
* because a log file was busy.
|
|
41
48
|
*/
|
|
42
49
|
runBuildGate(repoRoot: string, opts: BuildGateOptions): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Refuse when this is a Codex session in which NOT ONE guard has run.
|
|
52
|
+
*
|
|
53
|
+
* ─── Why it lives at the build, and why in THIS method ───────────────────────────────────────────
|
|
54
|
+
* `runBuildGate` is the single chokepoint every build reaches — `wp-build`, stage ② and stage ③ —
|
|
55
|
+
* so one call here is the whole wiring. It runs BEFORE the command is resolved and before the
|
|
56
|
+
* ledger row opens, because a session that was never guarded should cost nothing, not a full build
|
|
57
|
+
* followed by a refusal to believe it.
|
|
58
|
+
*
|
|
59
|
+
* The build is the right MOMENT because it is where a session's work is first claimed as verified.
|
|
60
|
+
* An unguarded Codex session that never builds has produced nothing anyone is about to trust; one
|
|
61
|
+
* that builds is asking for exactly that trust, on the strength of guards that never ran.
|
|
62
|
+
*
|
|
63
|
+
* ─── Safe to call unconditionally ────────────────────────────────────────────────────────────────
|
|
64
|
+
* Outside a Codex session `check()` is a no-op that returns ok — Claude Code sessions, CI, and a
|
|
65
|
+
* human at a terminal all pass straight through, which is why this needs no flag and no config key
|
|
66
|
+
* to sit on the shared path. The cures come from the verdict as `Option`s; this method contributes
|
|
67
|
+
* the throw and nothing else, so the two halves cannot drift into two different stories.
|
|
68
|
+
*/
|
|
69
|
+
private assertGuardsRan;
|
|
43
70
|
/**
|
|
44
71
|
* The failure text: this gate's own headline, then the pointer at the log the build already wrote.
|
|
45
72
|
*
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BuildAffected = exports.BuildGateOptions = void 0;
|
|
3
|
+
exports.BuildAffected = exports.CODEX_GUARDS_NEVER_RAN = exports.BuildGateOptions = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const rules_config_1 = require("@webpieces/rules-config");
|
|
6
|
+
const ai_hook_rules_1 = require("@webpieces/ai-hook-rules");
|
|
6
7
|
const inversify_1 = require("inversify");
|
|
7
8
|
const build_gate_log_1 = require("./build-gate-log");
|
|
8
9
|
const stage_output_log_1 = require("./stage-output-log");
|
|
@@ -32,15 +33,22 @@ class BuildGateOptions {
|
|
|
32
33
|
}
|
|
33
34
|
}
|
|
34
35
|
exports.BuildGateOptions = BuildGateOptions;
|
|
36
|
+
/**
|
|
37
|
+
* The rule name the guard-presence refusal is reported under, so it is greppable from a transcript the
|
|
38
|
+
* same way `too-many-concurrent-builds` is.
|
|
39
|
+
*/
|
|
40
|
+
exports.CODEX_GUARDS_NEVER_RAN = 'codex-guards-never-ran';
|
|
35
41
|
/** Runs the authoritative nx-affected build gate for wp-review-upsert-pr and wp-finish-upsert-pr. */
|
|
36
42
|
let BuildAffected = class BuildAffected {
|
|
37
43
|
buildLog;
|
|
38
44
|
buildsLog;
|
|
39
45
|
stageConsole;
|
|
40
|
-
|
|
46
|
+
guardPresence;
|
|
47
|
+
constructor(buildLog, buildsLog, stageConsole, guardPresence) {
|
|
41
48
|
this.buildLog = buildLog;
|
|
42
49
|
this.buildsLog = buildsLog;
|
|
43
50
|
this.stageConsole = stageConsole;
|
|
51
|
+
this.guardPresence = guardPresence;
|
|
44
52
|
}
|
|
45
53
|
/**
|
|
46
54
|
* Resolve the exact build command this gate will run: the project's configured
|
|
@@ -66,6 +74,7 @@ let BuildAffected = class BuildAffected {
|
|
|
66
74
|
* because a log file was busy.
|
|
67
75
|
*/
|
|
68
76
|
async runBuildGate(repoRoot, opts) {
|
|
77
|
+
this.assertGuardsRan(repoRoot);
|
|
69
78
|
const buildCommand = this.resolveBuildCommand(repoRoot);
|
|
70
79
|
// TWO lines on the happy path — the command, then the result. The old framing spent a banner and a
|
|
71
80
|
// paragraph explaining how to reproduce a build that was about to pass anyway; that explanation is
|
|
@@ -91,6 +100,31 @@ let BuildAffected = class BuildAffected {
|
|
|
91
100
|
throw new rules_config_1.CliExitError(buildCode, this.failureText(opts, buildCommand, logPath));
|
|
92
101
|
this.stageConsole.say(this.buildLog.successMessage(logPath));
|
|
93
102
|
}
|
|
103
|
+
/**
|
|
104
|
+
* Refuse when this is a Codex session in which NOT ONE guard has run.
|
|
105
|
+
*
|
|
106
|
+
* ─── Why it lives at the build, and why in THIS method ───────────────────────────────────────────
|
|
107
|
+
* `runBuildGate` is the single chokepoint every build reaches — `wp-build`, stage ② and stage ③ —
|
|
108
|
+
* so one call here is the whole wiring. It runs BEFORE the command is resolved and before the
|
|
109
|
+
* ledger row opens, because a session that was never guarded should cost nothing, not a full build
|
|
110
|
+
* followed by a refusal to believe it.
|
|
111
|
+
*
|
|
112
|
+
* The build is the right MOMENT because it is where a session's work is first claimed as verified.
|
|
113
|
+
* An unguarded Codex session that never builds has produced nothing anyone is about to trust; one
|
|
114
|
+
* that builds is asking for exactly that trust, on the strength of guards that never ran.
|
|
115
|
+
*
|
|
116
|
+
* ─── Safe to call unconditionally ────────────────────────────────────────────────────────────────
|
|
117
|
+
* Outside a Codex session `check()` is a no-op that returns ok — Claude Code sessions, CI, and a
|
|
118
|
+
* human at a terminal all pass straight through, which is why this needs no flag and no config key
|
|
119
|
+
* to sit on the shared path. The cures come from the verdict as `Option`s; this method contributes
|
|
120
|
+
* the throw and nothing else, so the two halves cannot drift into two different stories.
|
|
121
|
+
*/
|
|
122
|
+
assertGuardsRan(repoRoot) {
|
|
123
|
+
const verdict = this.guardPresence.check(repoRoot);
|
|
124
|
+
if (verdict.ok)
|
|
125
|
+
return;
|
|
126
|
+
throw new rules_config_1.RuleFailError(exports.CODEX_GUARDS_NEVER_RAN, verdict.reason, undefined, undefined, [...verdict.cures]);
|
|
127
|
+
}
|
|
94
128
|
/**
|
|
95
129
|
* The failure text: this gate's own headline, then the pointer at the log the build already wrote.
|
|
96
130
|
*
|
|
@@ -110,6 +144,7 @@ exports.BuildAffected = BuildAffected = tslib_1.__decorate([
|
|
|
110
144
|
(0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton),
|
|
111
145
|
tslib_1.__metadata("design:paramtypes", [build_gate_log_1.BuildGateLog,
|
|
112
146
|
rules_config_1.BuildsLog,
|
|
113
|
-
stage_output_log_1.StageOutputLog
|
|
147
|
+
stage_output_log_1.StageOutputLog,
|
|
148
|
+
ai_hook_rules_1.CodexGuardPresence])
|
|
114
149
|
], BuildAffected);
|
|
115
150
|
//# sourceMappingURL=build-affected.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build-affected.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/build-affected.ts"],"names":[],"mappings":";;;;AAAA,0DAEiC;AACjC,yCAA2D;AAC3D,qDAAgD;AAChD,yDAAoD;AAEpD,iGAAiG;AACjG,8FAA8F;AAC9F,iGAAiG;AACjG,oFAAoF;AACpF,oGAAoG;AACpG,iEAAiE;AAGjE;;;;GAIG;AACH,MAAa,gBAAgB;IACzB,KAAK,CAAS,CAAY,sCAAsC;IAChE,YAAY,CAAS,CAAK,gDAAgD;IAC1E,eAAe,CAAS,CAAE,gCAAgC;IAC1D,qGAAqG;IACrG,uGAAuG;IACvG,KAAK,CAAS;IAEd,YAAY,KAAa,EAAE,YAAoB,EAAE,eAAuB,EAAE,KAAa;QACnF,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QACvC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACvB,CAAC;CACJ;AAdD,4CAcC;AAED,qGAAqG;AAE9F,IAAM,aAAa,GAAnB,MAAM,aAAa;IAED;IACA;IACA;IAHrB,YACqB,QAAsB,EACtB,SAAoB,EACpB,YAA4B;QAF5B,aAAQ,GAAR,QAAQ,CAAc;QACtB,cAAS,GAAT,SAAS,CAAW;QACpB,iBAAY,GAAZ,YAAY,CAAgB;IAC9C,CAAC;IAEJ;;;OAGG;IACH,mBAAmB,CAAC,QAAgB;QAChC,MAAM,UAAU,GAAG,IAAA,8BAAe,EAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC;QACjE,OAAO,UAAU,KAAK,SAAS,IAAI,UAAU,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,oCAAqB,CAAC;IACrG,CAAC;IAED;;;;;;;;;;;;;;OAcG;IAC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CAAC,cAAc,CAAC,YAAY,EAAE,OAAO,CAAC;YACnD,wCAAwC,IAAI,CAAC,YAAY,KAAK,CAAC;IACvE,CAAC;CACJ,CAAA;AArEY,sCAAa;wBAAb,aAAa;IADzB,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGN,6BAAY;QACX,wBAAS;QACN,iCAAc;GAJxC,aAAa,CAqEzB","sourcesContent":["import {\n loadAndValidate, CliExitError, DEFAULT_BUILD_COMMAND, BuildsLog,\n} from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { BuildGateLog } from './build-gate-log';\nimport { StageOutputLog } from './stage-output-log';\n\n// Single source of truth for RUNNING the build gate. `wp-start-upsert-pr` runs NO build; stage ②\n// (`wp-review-upsert-pr`) runs it authoritatively before any reviewer is spawned, and stage ③\n// (`wp-finish-upsert-pr`) re-runs it only when HEAD has moved since. nx `affected` only rebuilds\n// changed projects. The fallback command itself lives in @webpieces/rules-config as\n// DEFAULT_BUILD_COMMAND — whole-repo-build-guard prints the same string, and one definition is what\n// keeps the refusal message naming the build that actually runs.\n\n\n/**\n * The caller-supplied framing for the build gate (label, re-run command, failure headline, stage id). Kept\n * as a parameter object so runBuildGate stays agnostic of who invokes it. A class (not an object literal)\n * per the codebase's data-structure convention.\n */\nexport class BuildGateOptions {\n label: string; // section header shown above the gate\n rerunCommand: string; // command the AI re-runs after fixing the build\n failureHeadline: string; // first line printed on failure\n // WHICH stage's gate this is — REVIEW_STAGE, FINISH_STAGE or BUILD_STAGE. Required, with no default:\n // it decides the captured log's filename, and a default would silently make two stages share one file.\n stage: string;\n\n constructor(label: string, rerunCommand: string, failureHeadline: string, stage: string) {\n this.label = label;\n this.rerunCommand = rerunCommand;\n this.failureHeadline = failureHeadline;\n this.stage = stage;\n }\n}\n\n/** Runs the authoritative nx-affected build gate for wp-review-upsert-pr and wp-finish-upsert-pr. */\n@injectable(bindingScopeValues.Singleton)\nexport class BuildAffected {\n constructor(\n private readonly buildLog: BuildGateLog,\n private readonly buildsLog: BuildsLog,\n private readonly stageConsole: StageOutputLog,\n ) {}\n\n /**\n * Resolve the exact build command this gate will run: the project's configured\n * PrGateConfig.buildCommand, or the default affected-ci command when none is set.\n */\n resolveBuildCommand(repoRoot: string): string {\n const configured = loadAndValidate(repoRoot).prGate.buildCommand;\n return configured !== undefined && configured.trim() !== '' ? configured : DEFAULT_BUILD_COMMAND;\n }\n\n /**\n * Run the configured build gate with consistent framing, throwing CliExitError(buildCode) on\n * failure so the bin's main()/runMain owns the exit. THE single source of truth for running a build:\n * wp-build, wp-review-upsert-pr and wp-finish-upsert-pr all call THIS (only the BuildGateOptions\n * differ), and there is no other way to reach the spawn.\n *\n * ─── EVERY BUILD ON THIS MACHINE IS LEDGERED FROM HERE ───────────────────────────────────────────\n * A START row goes into `~/.webpieces/builds.log` before the spawn and a DONE row after it, in a\n * `finally` so a throw on the failure path still closes the pair. `opts.stage` — `build` | `review` |\n * `finish` — IS the caller id the row records; there is deliberately no second `caller` field, since\n * two spellings of one fact is the shim CLAUDE.md rejects.\n *\n * The ledger is best-effort by construction (see BuildsLog): it can never throw, so no build can die\n * because a log file was busy.\n */\n async runBuildGate(repoRoot: string, opts: BuildGateOptions): Promise<void> {\n const buildCommand = this.resolveBuildCommand(repoRoot);\n // TWO lines on the happy path — the command, then the result. The old framing spent a banner and a\n // paragraph explaining how to reproduce a build that was about to pass anyway; that explanation is\n // only useful when the build FAILS, so it now lives solely on the failure path below.\n //\n // `say`, so it survives a stage that is capturing its own console (see StageOutputLog): the\n // command being run and the result of running it are exactly what a caller watching a long build\n // needs to see live.\n this.stageConsole.say(`\\n${opts.label}: ${buildCommand}\\n`);\n const logPath = this.buildLog.pathFor(repoRoot, opts.stage);\n const ticket = this.buildsLog.start(opts.stage, repoRoot);\n let buildCode = 1;\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: the DONE row must be written whether the\n // build passed, failed, or the spawn itself blew up; the throw is re-raised untouched below\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n buildCode = await this.buildLog.run(repoRoot, buildCommand, logPath);\n } finally {\n this.buildsLog.finish(ticket, buildCode);\n }\n if (buildCode !== 0) throw new CliExitError(buildCode, this.failureText(opts, buildCommand, logPath));\n this.stageConsole.say(this.buildLog.successMessage(logPath));\n }\n\n /**\n * The failure text: this gate's own headline, then the pointer at the log the build already wrote.\n *\n * There is no second, streamed variant any more. Capturing used to be behind an EXPERIMENTAL\n * machine-local opt-in, which meant the refusal an agent read depended on a file almost nobody had —\n * and the un-captured branch's advice was \"run the build again yourself\", which is the single most\n * expensive thing an agent can be told. Reading a FILE is now the only answer this gate gives.\n */\n private failureText(opts: BuildGateOptions, buildCommand: string, logPath: string): string {\n return `\\n❌ ${opts.failureHeadline}\\n` +\n this.buildLog.failureMessage(buildCommand, logPath) +\n `Fix what that log shows, then re-run ${opts.rerunCommand}.\\n`;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"build-affected.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/build-affected.ts"],"names":[],"mappings":";;;;AAAA,0DAEiC;AACjC,4DAAoF;AACpF,yCAA2D;AAC3D,qDAAgD;AAChD,yDAAoD;AAEpD,iGAAiG;AACjG,8FAA8F;AAC9F,iGAAiG;AACjG,oFAAoF;AACpF,oGAAoG;AACpG,iEAAiE;AAGjE;;;;GAIG;AACH,MAAa,gBAAgB;IACzB,KAAK,CAAS,CAAY,sCAAsC;IAChE,YAAY,CAAS,CAAK,gDAAgD;IAC1E,eAAe,CAAS,CAAE,gCAAgC;IAC1D,qGAAqG;IACrG,uGAAuG;IACvG,KAAK,CAAS;IAEd,YAAY,KAAa,EAAE,YAAoB,EAAE,eAAuB,EAAE,KAAa;QACnF,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QACvC,IAAI,CAAC,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,8BAAkB,CAAC,SAAS,CAAC;6CAGN,6BAAY;QACX,wBAAS;QACN,iCAAc;QACb,kCAAkB;GAL7C,aAAa,CAiGzB","sourcesContent":["import {\n loadAndValidate, CliExitError, DEFAULT_BUILD_COMMAND, BuildsLog, RuleFailError,\n} from '@webpieces/rules-config';\nimport { CodexGuardPresence, GuardPresenceVerdict } from '@webpieces/ai-hook-rules';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { BuildGateLog } from './build-gate-log';\nimport { StageOutputLog } from './stage-output-log';\n\n// Single source of truth for RUNNING the build gate. `wp-start-upsert-pr` runs NO build; stage ②\n// (`wp-review-upsert-pr`) runs it authoritatively before any reviewer is spawned, and stage ③\n// (`wp-finish-upsert-pr`) re-runs it only when HEAD has moved since. nx `affected` only rebuilds\n// changed projects. The fallback command itself lives in @webpieces/rules-config as\n// DEFAULT_BUILD_COMMAND — whole-repo-build-guard prints the same string, and one definition is what\n// keeps the refusal message naming the build that actually runs.\n\n\n/**\n * The caller-supplied framing for the build gate (label, re-run command, failure headline, stage id). Kept\n * as a parameter object so runBuildGate stays agnostic of who invokes it. A class (not an object literal)\n * per the codebase's data-structure convention.\n */\nexport class BuildGateOptions {\n label: string; // section header shown above the gate\n rerunCommand: string; // command the AI re-runs after fixing the build\n failureHeadline: string; // first line printed on failure\n // WHICH stage's gate this is — REVIEW_STAGE, FINISH_STAGE or BUILD_STAGE. Required, with no default:\n // it decides the captured log's filename, and a default would silently make two stages share one file.\n stage: string;\n\n constructor(label: string, rerunCommand: string, failureHeadline: string, stage: string) {\n this.label = label;\n this.rerunCommand = rerunCommand;\n this.failureHeadline = failureHeadline;\n this.stage = stage;\n }\n}\n\n/**\n * The rule name the guard-presence refusal is reported under, so it is greppable from a transcript the\n * same way `too-many-concurrent-builds` is.\n */\nexport const CODEX_GUARDS_NEVER_RAN = 'codex-guards-never-ran';\n\n/** Runs the authoritative nx-affected build gate for wp-review-upsert-pr and wp-finish-upsert-pr. */\n@injectable(bindingScopeValues.Singleton)\nexport class BuildAffected {\n constructor(\n private readonly buildLog: BuildGateLog,\n private readonly buildsLog: BuildsLog,\n private readonly stageConsole: StageOutputLog,\n private readonly guardPresence: CodexGuardPresence,\n ) {}\n\n /**\n * Resolve the exact build command this gate will run: the project's configured\n * PrGateConfig.buildCommand, or the default affected-ci command when none is set.\n */\n resolveBuildCommand(repoRoot: string): string {\n const configured = loadAndValidate(repoRoot).prGate.buildCommand;\n return configured !== undefined && configured.trim() !== '' ? configured : DEFAULT_BUILD_COMMAND;\n }\n\n /**\n * Run the configured build gate with consistent framing, throwing CliExitError(buildCode) on\n * failure so the bin's main()/runMain owns the exit. THE single source of truth for running a build:\n * wp-build, wp-review-upsert-pr and wp-finish-upsert-pr all call THIS (only the BuildGateOptions\n * differ), and there is no other way to reach the spawn.\n *\n * ─── EVERY BUILD ON THIS MACHINE IS LEDGERED FROM HERE ───────────────────────────────────────────\n * A START row goes into `~/.webpieces/builds.log` before the spawn and a DONE row after it, in a\n * `finally` so a throw on the failure path still closes the pair. `opts.stage` — `build` | `review` |\n * `finish` — IS the caller id the row records; there is deliberately no second `caller` field, since\n * two spellings of one fact is the shim CLAUDE.md rejects.\n *\n * The ledger is best-effort by construction (see BuildsLog): it can never throw, so no build can die\n * because a log file was busy.\n */\n async runBuildGate(repoRoot: string, opts: BuildGateOptions): Promise<void> {\n this.assertGuardsRan(repoRoot);\n const buildCommand = this.resolveBuildCommand(repoRoot);\n // TWO lines on the happy path — the command, then the result. The old framing spent a banner and a\n // paragraph explaining how to reproduce a build that was about to pass anyway; that explanation is\n // only useful when the build FAILS, so it now lives solely on the failure path below.\n //\n // `say`, so it survives a stage that is capturing its own console (see StageOutputLog): the\n // command being run and the result of running it are exactly what a caller watching a long build\n // needs to see live.\n this.stageConsole.say(`\\n${opts.label}: ${buildCommand}\\n`);\n const logPath = this.buildLog.pathFor(repoRoot, opts.stage);\n const ticket = this.buildsLog.start(opts.stage, repoRoot);\n let buildCode = 1;\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: the DONE row must be written whether the\n // build passed, failed, or the spawn itself blew up; the throw is re-raised untouched below\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n buildCode = await this.buildLog.run(repoRoot, buildCommand, logPath);\n } finally {\n this.buildsLog.finish(ticket, buildCode);\n }\n if (buildCode !== 0) throw new CliExitError(buildCode, this.failureText(opts, buildCommand, logPath));\n this.stageConsole.say(this.buildLog.successMessage(logPath));\n }\n\n /**\n * Refuse when this is a Codex session in which NOT ONE guard has run.\n *\n * ─── Why it lives at the build, and why in THIS method ───────────────────────────────────────────\n * `runBuildGate` is the single chokepoint every build reaches — `wp-build`, stage ② and stage ③ —\n * so one call here is the whole wiring. It runs BEFORE the command is resolved and before the\n * ledger row opens, because a session that was never guarded should cost nothing, not a full build\n * followed by a refusal to believe it.\n *\n * The build is the right MOMENT because it is where a session's work is first claimed as verified.\n * An unguarded Codex session that never builds has produced nothing anyone is about to trust; one\n * that builds is asking for exactly that trust, on the strength of guards that never ran.\n *\n * ─── Safe to call unconditionally ────────────────────────────────────────────────────────────────\n * Outside a Codex session `check()` is a no-op that returns ok — Claude Code sessions, CI, and a\n * human at a terminal all pass straight through, which is why this needs no flag and no config key\n * to sit on the shared path. The cures come from the verdict as `Option`s; this method contributes\n * the throw and nothing else, so the two halves cannot drift into two different stories.\n */\n private assertGuardsRan(repoRoot: string): void {\n const verdict: GuardPresenceVerdict = this.guardPresence.check(repoRoot);\n if (verdict.ok) return;\n throw new RuleFailError(\n CODEX_GUARDS_NEVER_RAN, verdict.reason, undefined, undefined, [...verdict.cures]);\n }\n\n /**\n * The failure text: this gate's own headline, then the pointer at the log the build already wrote.\n *\n * There is no second, streamed variant any more. Capturing used to be behind an EXPERIMENTAL\n * machine-local opt-in, which meant the refusal an agent read depended on a file almost nobody had —\n * and the un-captured branch's advice was \"run the build again yourself\", which is the single most\n * expensive thing an agent can be told. Reading a FILE is now the only answer this gate gives.\n */\n private failureText(opts: BuildGateOptions, buildCommand: string, logPath: string): string {\n return `\\n❌ ${opts.failureHeadline}\\n` +\n this.buildLog.failureMessage(buildCommand, logPath) +\n `Fix what that log shows, then re-run ${opts.rerunCommand}.\\n`;\n }\n}\n"]}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ChecklistDefinition, ChecklistResult, ChecklistReviewContext, DiffScope, RequiredChecklist, ReviewJsonService } from '@webpieces/rules-config';
|
|
2
2
|
import { AiBranchName } from './git-readAiBranchName';
|
|
3
3
|
import { ChecklistDetector, ChecklistRoster } from './checklist-detector';
|
|
4
4
|
import { DiffBasis, DiffBasisResolver } from './diff-basis';
|
|
5
5
|
import { PrContextWriter } from './pr-context-writer';
|
|
6
|
-
import { ReviewChangedFiles } from './authorization-context-resolver';
|
|
7
6
|
/** How a caller wants the scan filtered. Data-only (per CLAUDE.md). */
|
|
8
7
|
export declare class ChecklistScanOptions {
|
|
9
8
|
/**
|
|
@@ -73,17 +72,7 @@ export declare class ChecklistScan {
|
|
|
73
72
|
* passed. An optional checklist that ran and went RED is absent from here and stays in `outstanding`.
|
|
74
73
|
*/
|
|
75
74
|
optionalNotRun: RequiredChecklist[];
|
|
76
|
-
|
|
77
|
-
* The human authorizations that VERIFY for this branch right now — the only thing that turns a
|
|
78
|
-
* reviewer's `override` into a shipping verdict.
|
|
79
|
-
*
|
|
80
|
-
* Carried on the scan for the same reason `results` is: it is an input to every verdict, and a caller
|
|
81
|
-
* that re-resolved it would be verifying against a second reading of the fork point and changed-file
|
|
82
|
-
* set. One resolution, one answer, or the command that gates and the command that reports disagree
|
|
83
|
-
* about whether the human said yes.
|
|
84
|
-
*/
|
|
85
|
-
authorized: AuthorizedOverrides;
|
|
86
|
-
constructor(defined: ChecklistDefinition[], applicable: RequiredChecklist[], reviewed: RequiredChecklist[], outstanding: RequiredChecklist[], context: ChecklistReviewContext, reviewPath: string, forkPoint: string, roster: ChecklistRoster, formatErrors: string[], basis: DiffBasis | undefined, changedFiles: string[] | undefined, results: ChecklistResult[] | undefined, optionalNotRun: RequiredChecklist[] | undefined, authorized: AuthorizedOverrides);
|
|
75
|
+
constructor(defined: ChecklistDefinition[], applicable: RequiredChecklist[], reviewed: RequiredChecklist[], outstanding: RequiredChecklist[], context: ChecklistReviewContext, reviewPath: string, forkPoint: string, roster: ChecklistRoster, formatErrors: string[], basis?: DiffBasis, changedFiles?: string[], results?: ChecklistResult[], optionalNotRun?: RequiredChecklist[]);
|
|
87
76
|
}
|
|
88
77
|
/**
|
|
89
78
|
* The ONE computation of which reviewer subagents a branch owes, shared by `wp-review-upsert-pr` (which lists) and
|
|
@@ -95,9 +84,10 @@ export declare class ChecklistScan {
|
|
|
95
84
|
* 1. **The base is the FORK POINT of main, computed directly** — never `DiffScope.resolveBase`, which
|
|
96
85
|
* overlays `NX_BASE`/`NX_HEAD` from the environment. That made review coverage depend on an env var.
|
|
97
86
|
* It now arrives via {@link DiffBasisResolver}, which injects ForkPoint; same sha, one resolution.
|
|
98
|
-
* 2. **UNCOMMITTED work counts
|
|
99
|
-
*
|
|
100
|
-
*
|
|
87
|
+
* 2. **UNCOMMITTED work counts.** `getChangedFiles` is called with NO head, which is the branch of it that
|
|
88
|
+
* diffs base → WORKING TREE and unions in untracked files. Passing a head would diff commit-to-commit and
|
|
89
|
+
* silently miss staged, unstaged and untracked changes — so a checklist matching only uncommitted files
|
|
90
|
+
* would never fire and its reviewer would never be listed.
|
|
101
91
|
* 3. **The range and the command it prints are the SAME basis.** Property 2 used to be true of the file set
|
|
102
92
|
* only: reviewers were handed `git diff <base> HEAD`, which on a dirty tree covers a different range and
|
|
103
93
|
* prints nothing. Both now derive from one {@link DiffBasis}, carried on the scan so a materializing
|
|
@@ -108,23 +98,19 @@ export declare class ChecklistScan {
|
|
|
108
98
|
export declare class ChecklistScanner {
|
|
109
99
|
private readonly aiBranchName;
|
|
110
100
|
private readonly checklistDetector;
|
|
111
|
-
private readonly
|
|
101
|
+
private readonly diffScope;
|
|
112
102
|
private readonly diffBasisResolver;
|
|
113
103
|
private readonly prContextWriter;
|
|
114
104
|
private readonly reviewJsonService;
|
|
115
|
-
|
|
116
|
-
constructor(aiBranchName: AiBranchName, checklistDetector: ChecklistDetector, reviewChangedFiles: ReviewChangedFiles, diffBasisResolver: DiffBasisResolver, prContextWriter: PrContextWriter, reviewJsonService: ReviewJsonService, humanAuthorization: HumanAuthorizationService);
|
|
105
|
+
constructor(aiBranchName: AiBranchName, checklistDetector: ChecklistDetector, diffScope: DiffScope, diffBasisResolver: DiffBasisResolver, prContextWriter: PrContextWriter, reviewJsonService: ReviewJsonService);
|
|
117
106
|
/**
|
|
118
107
|
* `defined` is the caller's ALREADY-VALIDATED `prGate.checklists`. The scanner deliberately does not load
|
|
119
108
|
* config itself: `loadAndValidate` is the one gate on the checklist set (it rejects a non-array
|
|
120
109
|
* `checklists`, including the removed `{ doc }` manifest shape, and verifies every guidance doc and
|
|
121
110
|
* reviewer-agent file exists), both callers already run it for other fields, and keeping the read out of
|
|
122
|
-
* here leaves this a function of its inputs rather than of the filesystem.
|
|
123
|
-
* way and for the same reason — and as a POSITIONAL parameter rather than a field on
|
|
124
|
-
* {@link ChecklistScanOptions}, so it cannot be omitted. Omitted, every human authorization on the
|
|
125
|
-
* branch would be silently ignored, which looks exactly like a human who never approved anything.
|
|
111
|
+
* here leaves this a function of its inputs rather than of the filesystem.
|
|
126
112
|
*/
|
|
127
|
-
scan(repoRoot: string, defined: ChecklistDefinition[],
|
|
113
|
+
scan(repoRoot: string, defined: ChecklistDefinition[], opts: ChecklistScanOptions): ChecklistScan;
|
|
128
114
|
/**
|
|
129
115
|
* What `wp-finish-upsert-pr` actually REFUSES on: everything still owing a verdict, minus the optional
|
|
130
116
|
* checklists nobody ran.
|
|
@@ -135,4 +121,15 @@ export declare class ChecklistScanner {
|
|
|
135
121
|
* exactly the divergence this class's docstring exists to prevent.
|
|
136
122
|
*/
|
|
137
123
|
private blocking;
|
|
124
|
+
/**
|
|
125
|
+
* Every file changed since the fork point, INCLUDING uncommitted and untracked ones. Two non-default
|
|
126
|
+
* options, both load-bearing:
|
|
127
|
+
*
|
|
128
|
+
* `tsOnly:false` — the default drops every *.sql / Dockerfile / .env* file a checklist most wants
|
|
129
|
+
* to key on, which would silently shrink the set a reviewer is pointed at.
|
|
130
|
+
* `includeDeletions:true` — the default is `--diff-filter=d`, so a DELETED file is invisible. A PR that
|
|
131
|
+
* deletes a migration, an auth check or a terraform rule changed exactly what a
|
|
132
|
+
* checklist exists to catch, and under the default no checklist fires at all.
|
|
133
|
+
*/
|
|
134
|
+
private changedFiles;
|
|
138
135
|
}
|
|
@@ -8,7 +8,6 @@ const git_readAiBranchName_1 = require("./git-readAiBranchName");
|
|
|
8
8
|
const checklist_detector_1 = require("./checklist-detector");
|
|
9
9
|
const diff_basis_1 = require("./diff-basis");
|
|
10
10
|
const pr_context_writer_1 = require("./pr-context-writer");
|
|
11
|
-
const authorization_context_resolver_1 = require("./authorization-context-resolver");
|
|
12
11
|
/** How a caller wants the scan filtered. Data-only (per CLAUDE.md). */
|
|
13
12
|
class ChecklistScanOptions {
|
|
14
13
|
/**
|
|
@@ -88,25 +87,11 @@ class ChecklistScan {
|
|
|
88
87
|
* passed. An optional checklist that ran and went RED is absent from here and stays in `outstanding`.
|
|
89
88
|
*/
|
|
90
89
|
optionalNotRun;
|
|
91
|
-
/**
|
|
92
|
-
* The human authorizations that VERIFY for this branch right now — the only thing that turns a
|
|
93
|
-
* reviewer's `override` into a shipping verdict.
|
|
94
|
-
*
|
|
95
|
-
* Carried on the scan for the same reason `results` is: it is an input to every verdict, and a caller
|
|
96
|
-
* that re-resolved it would be verifying against a second reading of the fork point and changed-file
|
|
97
|
-
* set. One resolution, one answer, or the command that gates and the command that reports disagree
|
|
98
|
-
* about whether the human said yes.
|
|
99
|
-
*/
|
|
100
|
-
authorized;
|
|
101
90
|
// eslint-disable-next-line @typescript-eslint/max-params
|
|
102
91
|
constructor(defined, applicable, reviewed, outstanding, context, reviewPath, forkPoint, roster, formatErrors, basis = new diff_basis_1.DiffBasis(), changedFiles = [],
|
|
103
92
|
// Defaulted so a caller that only cares about the X/N/Z counts (and every existing test construction)
|
|
104
93
|
// stays a one-liner; the scanner itself always passes the real set.
|
|
105
|
-
results = [], optionalNotRun = []
|
|
106
|
-
// REQUIRED, with no default. An empty grant fails closed, but a construction that silently got one
|
|
107
|
-
// by omission would report "no human authorized this" for a branch where somebody did — the exact
|
|
108
|
-
// stall this whole feature exists to end, arrived at by forgetting an argument.
|
|
109
|
-
authorized) {
|
|
94
|
+
results = [], optionalNotRun = []) {
|
|
110
95
|
this.defined = defined;
|
|
111
96
|
this.applicable = applicable;
|
|
112
97
|
this.reviewed = reviewed;
|
|
@@ -120,7 +105,6 @@ class ChecklistScan {
|
|
|
120
105
|
this.changedFiles = changedFiles;
|
|
121
106
|
this.results = results;
|
|
122
107
|
this.optionalNotRun = optionalNotRun;
|
|
123
|
-
this.authorized = authorized;
|
|
124
108
|
}
|
|
125
109
|
}
|
|
126
110
|
exports.ChecklistScan = ChecklistScan;
|
|
@@ -134,9 +118,10 @@ exports.ChecklistScan = ChecklistScan;
|
|
|
134
118
|
* 1. **The base is the FORK POINT of main, computed directly** — never `DiffScope.resolveBase`, which
|
|
135
119
|
* overlays `NX_BASE`/`NX_HEAD` from the environment. That made review coverage depend on an env var.
|
|
136
120
|
* It now arrives via {@link DiffBasisResolver}, which injects ForkPoint; same sha, one resolution.
|
|
137
|
-
* 2. **UNCOMMITTED work counts
|
|
138
|
-
*
|
|
139
|
-
*
|
|
121
|
+
* 2. **UNCOMMITTED work counts.** `getChangedFiles` is called with NO head, which is the branch of it that
|
|
122
|
+
* diffs base → WORKING TREE and unions in untracked files. Passing a head would diff commit-to-commit and
|
|
123
|
+
* silently miss staged, unstaged and untracked changes — so a checklist matching only uncommitted files
|
|
124
|
+
* would never fire and its reviewer would never be listed.
|
|
140
125
|
* 3. **The range and the command it prints are the SAME basis.** Property 2 used to be true of the file set
|
|
141
126
|
* only: reviewers were handed `git diff <base> HEAD`, which on a dirty tree covers a different range and
|
|
142
127
|
* prints nothing. Both now derive from one {@link DiffBasis}, carried on the scan so a materializing
|
|
@@ -147,31 +132,26 @@ exports.ChecklistScan = ChecklistScan;
|
|
|
147
132
|
let ChecklistScanner = class ChecklistScanner {
|
|
148
133
|
aiBranchName;
|
|
149
134
|
checklistDetector;
|
|
150
|
-
|
|
135
|
+
diffScope;
|
|
151
136
|
diffBasisResolver;
|
|
152
137
|
prContextWriter;
|
|
153
138
|
reviewJsonService;
|
|
154
|
-
|
|
155
|
-
constructor(aiBranchName, checklistDetector, reviewChangedFiles, diffBasisResolver, prContextWriter, reviewJsonService, humanAuthorization) {
|
|
139
|
+
constructor(aiBranchName, checklistDetector, diffScope, diffBasisResolver, prContextWriter, reviewJsonService) {
|
|
156
140
|
this.aiBranchName = aiBranchName;
|
|
157
141
|
this.checklistDetector = checklistDetector;
|
|
158
|
-
this.
|
|
142
|
+
this.diffScope = diffScope;
|
|
159
143
|
this.diffBasisResolver = diffBasisResolver;
|
|
160
144
|
this.prContextWriter = prContextWriter;
|
|
161
145
|
this.reviewJsonService = reviewJsonService;
|
|
162
|
-
this.humanAuthorization = humanAuthorization;
|
|
163
146
|
}
|
|
164
147
|
/**
|
|
165
148
|
* `defined` is the caller's ALREADY-VALIDATED `prGate.checklists`. The scanner deliberately does not load
|
|
166
149
|
* config itself: `loadAndValidate` is the one gate on the checklist set (it rejects a non-array
|
|
167
150
|
* `checklists`, including the removed `{ doc }` manifest shape, and verifies every guidance doc and
|
|
168
151
|
* reviewer-agent file exists), both callers already run it for other fields, and keeping the read out of
|
|
169
|
-
* here leaves this a function of its inputs rather than of the filesystem.
|
|
170
|
-
* way and for the same reason — and as a POSITIONAL parameter rather than a field on
|
|
171
|
-
* {@link ChecklistScanOptions}, so it cannot be omitted. Omitted, every human authorization on the
|
|
172
|
-
* branch would be silently ignored, which looks exactly like a human who never approved anything.
|
|
152
|
+
* here leaves this a function of its inputs rather than of the filesystem.
|
|
173
153
|
*/
|
|
174
|
-
scan(repoRoot, defined,
|
|
154
|
+
scan(repoRoot, defined, opts) {
|
|
175
155
|
const featureName = this.aiBranchName.getFeatureName();
|
|
176
156
|
const reviewPath = (0, rules_config_1.reviewJsonPath)(repoRoot, featureName);
|
|
177
157
|
// ONE basis for the file set, the reproduce command and any downstream materialization. The fork
|
|
@@ -180,23 +160,20 @@ let ChecklistScanner = class ChecklistScanner {
|
|
|
180
160
|
const base = basis.base;
|
|
181
161
|
// ONE changed-file computation feeds both the roster (all X) and the applicable set (N). `detect` is
|
|
182
162
|
// pure and defined as the roster minus its empty entries, so the two cannot disagree about a match.
|
|
183
|
-
const changedFiles = this.
|
|
163
|
+
const changedFiles = this.changedFiles(repoRoot, base);
|
|
184
164
|
const roster = new checklist_detector_1.ChecklistRoster(this.checklistDetector.roster(defined, changedFiles), changedFiles.length, base !== '');
|
|
185
165
|
const applicable = this.checklistDetector.toRequired(this.checklistDetector.detect(defined, changedFiles));
|
|
186
166
|
const results = this.reviewJsonService.loadChecklistResults(reviewPath, applicable);
|
|
187
|
-
|
|
188
|
-
// approval's scope is checked against THIS diff, not against a second reading of it.
|
|
189
|
-
const authorized = this.humanAuthorization.verifiedFor(repoRoot, new rules_config_1.AuthorizationContext(featureName, base, changedFiles), gateSalt);
|
|
190
|
-
const stillOwed = this.reviewJsonService.pendingChecklists(applicable, results, authorized);
|
|
167
|
+
const stillOwed = this.reviewJsonService.pendingChecklists(applicable, results);
|
|
191
168
|
const owedIds = new Set(stillOwed.map((r) => r.id));
|
|
192
169
|
// NOT `!owedIds.has(...)`-with-the-optional-exemption-folded-in: an optional checklist nobody ran is
|
|
193
170
|
// neither reviewed nor blocking, and calling it "reviewed" would put a ✓ on the dashboard for a review
|
|
194
171
|
// that never happened.
|
|
195
172
|
const reviewed = applicable.filter((r) => !owedIds.has(r.id));
|
|
196
|
-
const optionalNotRun = this.reviewJsonService.optionalWithoutVerdict(applicable, results
|
|
173
|
+
const optionalNotRun = this.reviewJsonService.optionalWithoutVerdict(applicable, results);
|
|
197
174
|
return new ChecklistScan(defined, applicable, reviewed, opts.filterAlreadyReviewed ? this.blocking(stillOwed, optionalNotRun) : applicable, opts.contextStage === ''
|
|
198
175
|
? this.prContextWriter.contextFor(repoRoot, featureName, basis)
|
|
199
|
-
: this.prContextWriter.ensure(repoRoot, featureName, basis, opts.contextStage, changedFiles), reviewPath, base, roster, this.reviewJsonService.checklistFormatErrors(applicable, results
|
|
176
|
+
: this.prContextWriter.ensure(repoRoot, featureName, basis, opts.contextStage, changedFiles), reviewPath, base, roster, this.reviewJsonService.checklistFormatErrors(applicable, results), basis, changedFiles, results, optionalNotRun);
|
|
200
177
|
}
|
|
201
178
|
/**
|
|
202
179
|
* What `wp-finish-upsert-pr` actually REFUSES on: everything still owing a verdict, minus the optional
|
|
@@ -211,16 +188,34 @@ let ChecklistScanner = class ChecklistScanner {
|
|
|
211
188
|
const skipped = new Set(optionalNotRun.map((r) => r.id));
|
|
212
189
|
return stillOwed.filter((r) => !skipped.has(r.id));
|
|
213
190
|
}
|
|
191
|
+
/**
|
|
192
|
+
* Every file changed since the fork point, INCLUDING uncommitted and untracked ones. Two non-default
|
|
193
|
+
* options, both load-bearing:
|
|
194
|
+
*
|
|
195
|
+
* `tsOnly:false` — the default drops every *.sql / Dockerfile / .env* file a checklist most wants
|
|
196
|
+
* to key on, which would silently shrink the set a reviewer is pointed at.
|
|
197
|
+
* `includeDeletions:true` — the default is `--diff-filter=d`, so a DELETED file is invisible. A PR that
|
|
198
|
+
* deletes a migration, an auth check or a terraform rule changed exactly what a
|
|
199
|
+
* checklist exists to catch, and under the default no checklist fires at all.
|
|
200
|
+
*/
|
|
201
|
+
changedFiles(repoRoot, base) {
|
|
202
|
+
if (base === '')
|
|
203
|
+
return [];
|
|
204
|
+
const opts = new rules_config_1.ChangedFilesOptions();
|
|
205
|
+
opts.tsOnly = false;
|
|
206
|
+
opts.includeDeletions = true;
|
|
207
|
+
// No head argument — see the class comment. This is what includes the working tree.
|
|
208
|
+
return this.diffScope.getChangedFiles(repoRoot, base, undefined, opts);
|
|
209
|
+
}
|
|
214
210
|
};
|
|
215
211
|
exports.ChecklistScanner = ChecklistScanner;
|
|
216
212
|
exports.ChecklistScanner = ChecklistScanner = tslib_1.__decorate([
|
|
217
213
|
(0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton),
|
|
218
214
|
tslib_1.__metadata("design:paramtypes", [git_readAiBranchName_1.AiBranchName,
|
|
219
215
|
checklist_detector_1.ChecklistDetector,
|
|
220
|
-
|
|
216
|
+
rules_config_1.DiffScope,
|
|
221
217
|
diff_basis_1.DiffBasisResolver,
|
|
222
218
|
pr_context_writer_1.PrContextWriter,
|
|
223
|
-
rules_config_1.ReviewJsonService
|
|
224
|
-
rules_config_1.HumanAuthorizationService])
|
|
219
|
+
rules_config_1.ReviewJsonService])
|
|
225
220
|
], ChecklistScanner);
|
|
226
221
|
//# sourceMappingURL=checklist-scanner.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"checklist-scanner.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/checklist-scanner.ts"],"names":[],"mappings":";;;;AAAA,0DAIiC;AACjC,yCAA2D;AAC3D,iEAAsD;AACtD,6DAA0E;AAC1E,6CAA4D;AAC5D,2DAAsD;AACtD,qFAAsE;AAEtE,uEAAuE;AACvE,MAAa,oBAAoB;IAC7B;;;;OAIG;IACH,qBAAqB,CAAU;IAC/B;;;;;;;;;;;;OAYG;IACH,YAAY,CAAS;IAErB,YAAY,qBAAqB,GAAG,KAAK,EAAE,YAAY,GAAG,YAAY;QAClE,IAAI,CAAC,qBAAqB,GAAG,qBAAqB,CAAC;QACnD,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACrC,CAAC;CACJ;AA1BD,oDA0BC;AAED;;;;;;GAMG;AACH,MAAa,aAAa;IACtB,OAAO,CAAwB,CAAM,IAAI;IACzC,UAAU,CAAsB,CAAK,IAAI;IACzC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E,cAAc,CAAC,CAAC,CAAC,CAAC,UAAU,EAClF,IAAI,CAAC,YAAY,KAAK,EAAE;YACpB,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,UAAU,CAAC,QAAQ,EAAE,WAAW,EAAE,KAAK,CAAC;YAC/D,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,QAAQ,EAAE,WAAW,EAAE,KAAK,EAAE,IAAI,CAAC,YAAY,EAAE,YAAY,CAAC,EAChG,UAAU,EACV,IAAI,EACJ,MAAM,EACN,IAAI,CAAC,iBAAiB,CAAC,qBAAqB,CAAC,UAAU,EAAE,OAAO,EAAE,UAAU,CAAC,EAC7E,KAAK,EACL,YAAY,EACZ,OAAO,EACP,cAAc,EACd,UAAU,CACb,CAAC;IACN,CAAC;IAED;;;;;;;;OAQG;IACK,QAAQ,CAAC,SAAuC,EAAE,cAA4C;QAClG,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,CAAoB,EAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACpF,OAAO,SAAS,CAAC,MAAM,CAAC,CAAC,CAAoB,EAAW,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACnF,CAAC;CACJ,CAAA;AAjFY,4CAAgB;2BAAhB,gBAAgB;IAD5B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGF,mCAAY;QACP,sCAAiB;QAChB,mDAAkB;QACnB,8BAAiB;QACnB,mCAAe;QACb,gCAAiB;QAChB,wCAAyB;GARzD,gBAAgB,CAiF5B","sourcesContent":["import {\n AuthorizationContext, AuthorizedOverrides, ChecklistDefinition, ChecklistResult,\n ChecklistReviewContext, HumanAuthorizationService, RequiredChecklist, ReviewJsonService,\n reviewJsonPath,\n} from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { AiBranchName } from './git-readAiBranchName';\nimport { ChecklistDetector, ChecklistRoster } from './checklist-detector';\nimport { DiffBasis, DiffBasisResolver } from './diff-basis';\nimport { PrContextWriter } from './pr-context-writer';\nimport { ReviewChangedFiles } from './authorization-context-resolver';\n\n/** How a caller wants the scan filtered. Data-only (per CLAUDE.md). */\nexport class ChecklistScanOptions {\n /**\n * false — `outstanding` is every applicable checklist (what `wp-review-upsert-pr` LISTS).\n * true — `outstanding` drops the ones already carrying a passing/overridden verdict, leaving only what\n * still owes review (what `wp-finish-upsert-pr` BLOCKS on).\n */\n filterAlreadyReviewed: boolean;\n /**\n * Which per-stage snapshot this scan should persist ('stage3-finish', …), or '' for \"do not write\n * pr-context.json here\".\n *\n * '' exists for stage ②, which cannot write yet: the context records `diffDir`, and the diff has not\n * been materialized at scan time. Letting the scan write anyway meant stage ② wrote the file twice,\n * ~60 lines apart, the first time with an empty diffDir. Now it writes once, after materializing.\n *\n * The DEFAULT is deliberately non-empty, so writing is what you get by NOT thinking about it. A\n * reviewer block that lost its diff command because nobody had written pr-context.json is a bug this\n * codebase has already shipped once (see PrContextWriter's docstring); opting out must be an explicit,\n * visible act by a caller that takes responsibility for writing it later — not an omission.\n */\n contextStage: string;\n\n constructor(filterAlreadyReviewed = false, contextStage = 'stage-scan') {\n this.filterAlreadyReviewed = filterAlreadyReviewed;\n this.contextStage = contextStage;\n }\n}\n\n/**\n * The answer to \"what review does this branch owe?\", in the X → N → Z terms the commands report:\n * X = `defined` — every checklist in pr-gate.checklists\n * N = `applicable` — those whose patterns matched (or that have no patterns, so always run)\n * Z = `outstanding` — of N, those still owing a verdict (only when filterAlreadyReviewed)\n * Data-only.\n */\nexport class ChecklistScan {\n defined: ChecklistDefinition[]; // X\n applicable: RequiredChecklist[]; // N\n reviewed: RequiredChecklist[]; // N − Z: already have a passing/warned/overridden review-<id>.json\n outstanding: RequiredChecklist[]; // Z (== applicable when not filtering)\n context: ChecklistReviewContext; // fork-point sha + pr-context.json path\n reviewPath: string; // the branch's review.json; verdict files sit beside it\n forkPoint: string; // '' when no fork point resolved\n // ALL X, matched or not, with why — what the PR comment publishes as its roster. Skipped checklists are\n // absent from `applicable` by construction, and recovering them downstream would mean a second\n // changed-file computation with different semantics (see the class comment).\n roster: ChecklistRoster;\n // Verdict files that exist but cannot be read as a verdict (e.g. still using the removed `success`).\n // Carried on the SCAN because wp-finish-upsert-pr refuses on missing reviewers before it ever parses\n // review.json — a complaint raised only in there would never reach the AI.\n formatErrors: string[];\n /**\n * The basis the matching ACTUALLY ran against. Carried out so a caller that materializes the diff\n * (stage ②) reuses the identical range instead of resolving its own — two independent resolutions is\n * exactly how the changed-file set and the printed `git diff` command came to disagree.\n */\n basis: DiffBasis;\n changedFiles: string[]; // the full changed-file set the matching ran against\n /**\n * The verdict files the scan ALREADY read, carried out rather than dropped.\n *\n * `outstanding` answers \"who still owes a verdict?\" but not \"why\" — and the two reasons demand opposite\n * actions from the reader: a reviewer that never ran must be SPAWNED, a reviewer that ran and REFUSED\n * must not be (it will refuse again; the finding has to be fixed first). Telling them apart means\n * resolving each checklist's verdict, and without the results here every caller either re-reads the same\n * files off disk — a second read that can disagree with this one — or merges the two cases into one\n * message, which is exactly the loop this field exists to break.\n */\n results: ChecklistResult[];\n /**\n * The OPTIONAL (`required: false`) applicable checklists carrying no verdict file — i.e. nobody ran them.\n *\n * Deliberately NOT in `outstanding` when filtering: that is the exemption that makes `required: false`\n * mean something. Carried out as its own set rather than merely subtracted, because both readers need it\n * BY NAME and neither can recover it from what is left: stage ② offers exactly these to the human, and\n * the PR dashboard must publish them as \"not run\" rather than let a shorter roster imply everything\n * passed. An optional checklist that ran and went RED is absent from here and stays in `outstanding`.\n */\n optionalNotRun: RequiredChecklist[];\n /**\n * The human authorizations that VERIFY for this branch right now — the only thing that turns a\n * reviewer's `override` into a shipping verdict.\n *\n * Carried on the scan for the same reason `results` is: it is an input to every verdict, and a caller\n * that re-resolved it would be verifying against a second reading of the fork point and changed-file\n * set. One resolution, one answer, or the command that gates and the command that reports disagree\n * about whether the human said yes.\n */\n authorized: AuthorizedOverrides;\n\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(\n defined: ChecklistDefinition[],\n applicable: RequiredChecklist[],\n reviewed: RequiredChecklist[],\n outstanding: RequiredChecklist[],\n context: ChecklistReviewContext,\n reviewPath: string,\n forkPoint: string,\n roster: ChecklistRoster,\n formatErrors: string[],\n basis: DiffBasis = new DiffBasis(),\n changedFiles: string[] = [],\n // Defaulted so a caller that only cares about the X/N/Z counts (and every existing test construction)\n // stays a one-liner; the scanner itself always passes the real set.\n results: ChecklistResult[] = [],\n optionalNotRun: RequiredChecklist[] = [],\n // REQUIRED, with no default. An empty grant fails closed, but a construction that silently got one\n // by omission would report \"no human authorized this\" for a branch where somebody did — the exact\n // stall this whole feature exists to end, arrived at by forgetting an argument.\n authorized: AuthorizedOverrides,\n ) {\n this.defined = defined;\n this.applicable = applicable;\n this.reviewed = reviewed;\n this.outstanding = outstanding;\n this.context = context;\n this.reviewPath = reviewPath;\n this.forkPoint = forkPoint;\n this.roster = roster;\n this.formatErrors = formatErrors;\n this.basis = basis;\n this.changedFiles = changedFiles;\n this.results = results;\n this.optionalNotRun = optionalNotRun;\n this.authorized = authorized;\n }\n}\n\n/**\n * The ONE computation of which reviewer subagents a branch owes, shared by `wp-review-upsert-pr` (which lists) and\n * `wp-finish-upsert-pr` (which blocks). They previously each assembled this from the same parts in slightly\n * different ways, and any divergence means the command that reports and the command that gates disagree.\n *\n * Two properties are deliberate and load-bearing:\n *\n * 1. **The base is the FORK POINT of main, computed directly** — never `DiffScope.resolveBase`, which\n * overlays `NX_BASE`/`NX_HEAD` from the environment. That made review coverage depend on an env var.\n * It now arrives via {@link DiffBasisResolver}, which injects ForkPoint; same sha, one resolution.\n * 2. **UNCOMMITTED work counts**, and the set comes from {@link ReviewChangedFiles} — the one place that\n * computation lives, shared with the authorization commands so a checklist's scope and an approval's\n * scope are literally the same file set rather than two implementations of it.\n * 3. **The range and the command it prints are the SAME basis.** Property 2 used to be true of the file set\n * only: reviewers were handed `git diff <base> HEAD`, which on a dirty tree covers a different range and\n * prints nothing. Both now derive from one {@link DiffBasis}, carried on the scan so a materializing\n * caller cannot re-resolve and drift.\n *\n * `@injectable(bindingScopeValues.Singleton)` so it is injected by type and drawn in the DI design.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class ChecklistScanner {\n constructor(\n private readonly aiBranchName: AiBranchName,\n private readonly checklistDetector: ChecklistDetector,\n private readonly reviewChangedFiles: ReviewChangedFiles,\n private readonly diffBasisResolver: DiffBasisResolver,\n private readonly prContextWriter: PrContextWriter,\n private readonly reviewJsonService: ReviewJsonService,\n private readonly humanAuthorization: HumanAuthorizationService,\n ) {}\n\n /**\n * `defined` is the caller's ALREADY-VALIDATED `prGate.checklists`. The scanner deliberately does not load\n * config itself: `loadAndValidate` is the one gate on the checklist set (it rejects a non-array\n * `checklists`, including the removed `{ doc }` manifest shape, and verifies every guidance doc and\n * reviewer-agent file exists), both callers already run it for other fields, and keeping the read out of\n * here leaves this a function of its inputs rather than of the filesystem. `gateSalt` travels the same\n * way and for the same reason — and as a POSITIONAL parameter rather than a field on\n * {@link ChecklistScanOptions}, so it cannot be omitted. Omitted, every human authorization on the\n * branch would be silently ignored, which looks exactly like a human who never approved anything.\n */\n scan(\n repoRoot: string, defined: ChecklistDefinition[], gateSalt: string, opts: ChecklistScanOptions,\n ): ChecklistScan {\n const featureName = this.aiBranchName.getFeatureName();\n const reviewPath = reviewJsonPath(repoRoot, featureName);\n // ONE basis for the file set, the reproduce command and any downstream materialization. The fork\n // point still comes from ForkPoint (never DiffScope.resolveBase) — DiffBasisResolver injects it.\n const basis = this.diffBasisResolver.resolve(repoRoot);\n const base = basis.base;\n // ONE changed-file computation feeds both the roster (all X) and the applicable set (N). `detect` is\n // pure and defined as the roster minus its empty entries, so the two cannot disagree about a match.\n const changedFiles = this.reviewChangedFiles.since(repoRoot, base);\n const roster = new ChecklistRoster(\n this.checklistDetector.roster(defined, changedFiles), changedFiles.length, base !== '');\n const applicable = this.checklistDetector.toRequired(this.checklistDetector.detect(defined, changedFiles));\n const results = this.reviewJsonService.loadChecklistResults(reviewPath, applicable);\n // Resolved ONCE, from the same fork point and changed-file set the matching ran against — the\n // approval's scope is checked against THIS diff, not against a second reading of it.\n const authorized = this.humanAuthorization.verifiedFor(\n repoRoot, new AuthorizationContext(featureName, base, changedFiles), gateSalt);\n const stillOwed = this.reviewJsonService.pendingChecklists(applicable, results, authorized);\n const owedIds = new Set(stillOwed.map((r: RequiredChecklist): string => r.id));\n // NOT `!owedIds.has(...)`-with-the-optional-exemption-folded-in: an optional checklist nobody ran is\n // neither reviewed nor blocking, and calling it \"reviewed\" would put a ✓ on the dashboard for a review\n // that never happened.\n const reviewed = applicable.filter((r: RequiredChecklist): boolean => !owedIds.has(r.id));\n const optionalNotRun = this.reviewJsonService.optionalWithoutVerdict(applicable, results, authorized);\n return new ChecklistScan(\n defined,\n applicable,\n reviewed,\n opts.filterAlreadyReviewed ? this.blocking(stillOwed, optionalNotRun) : applicable,\n opts.contextStage === ''\n ? this.prContextWriter.contextFor(repoRoot, featureName, basis)\n : this.prContextWriter.ensure(repoRoot, featureName, basis, opts.contextStage, changedFiles),\n reviewPath,\n base,\n roster,\n this.reviewJsonService.checklistFormatErrors(applicable, results, authorized),\n basis,\n changedFiles,\n results,\n optionalNotRun,\n authorized,\n );\n }\n\n /**\n * What `wp-finish-upsert-pr` actually REFUSES on: everything still owing a verdict, minus the optional\n * checklists nobody ran.\n *\n * The subtraction happens HERE — in the one place `outstanding` is computed — and not in the gate, so\n * there is a single answer to \"does this branch owe review?\". When the gate did its own filtering, the\n * command that lists and the command that blocks were two implementations of the same question, which is\n * exactly the divergence this class's docstring exists to prevent.\n */\n private blocking(stillOwed: readonly RequiredChecklist[], optionalNotRun: readonly RequiredChecklist[]): RequiredChecklist[] {\n const skipped = new Set(optionalNotRun.map((r: RequiredChecklist): string => r.id));\n return stillOwed.filter((r: RequiredChecklist): boolean => !skipped.has(r.id));\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"checklist-scanner.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/checklist-scanner.ts"],"names":[],"mappings":";;;;AAAA,0DAGiC;AACjC,yCAA2D;AAC3D,iEAAsD;AACtD,6DAA0E;AAC1E,6CAA4D;AAC5D,2DAAsD;AAEtD,uEAAuE;AACvE,MAAa,oBAAoB;IAC7B;;;;OAIG;IACH,qBAAqB,CAAU;IAC/B;;;;;;;;;;;;OAYG;IACH,YAAY,CAAS;IAErB,YAAY,qBAAqB,GAAG,KAAK,EAAE,YAAY,GAAG,YAAY;QAClE,IAAI,CAAC,qBAAqB,GAAG,qBAAqB,CAAC;QACnD,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACrC,CAAC;CACJ;AA1BD,oDA0BC;AAED;;;;;;GAMG;AACH,MAAa,aAAa;IACtB,OAAO,CAAwB,CAAM,IAAI;IACzC,UAAU,CAAsB,CAAK,IAAI;IACzC,QAAQ,CAAsB,CAAO,mEAAmE;IACxG,WAAW,CAAsB,CAAI,uCAAuC;IAC5E,OAAO,CAAyB,CAAK,wCAAwC;IAC7E,UAAU,CAAS,CAAkB,wDAAwD;IAC7F,SAAS,CAAS,CAAmB,iCAAiC;IACtE,wGAAwG;IACxG,+FAA+F;IAC/F,6EAA6E;IAC7E,MAAM,CAAkB;IACxB,qGAAqG;IACrG,qGAAqG;IACrG,2EAA2E;IAC3E,YAAY,CAAW;IACvB;;;;OAIG;IACH,KAAK,CAAY;IACjB,YAAY,CAAW,CAAc,qDAAqD;IAC1F;;;;;;;;;OASG;IACH,OAAO,CAAoB;IAC3B;;;;;;;;OAQG;IACH,cAAc,CAAsB;IAEpC,yDAAyD;IACzD,YACI,OAA8B,EAC9B,UAA+B,EAC/B,QAA6B,EAC7B,WAAgC,EAChC,OAA+B,EAC/B,UAAkB,EAClB,SAAiB,EACjB,MAAuB,EACvB,YAAsB,EACtB,QAAmB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AAI,CAAC;QAC7B,oFAAoF;QACpF,OAAO,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;IAC3E,CAAC;CACJ,CAAA;AAzFY,4CAAgB;2BAAhB,gBAAgB;IAD5B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGF,mCAAY;QACP,sCAAiB;QACzB,wBAAS;QACD,8BAAiB;QACnB,mCAAe;QACb,gCAAiB;GAPhD,gBAAgB,CAyF5B","sourcesContent":["import {\n ChangedFilesOptions, ChecklistDefinition, ChecklistResult, ChecklistReviewContext, DiffScope,\n RequiredChecklist, ReviewJsonService, reviewJsonPath,\n} from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { AiBranchName } from './git-readAiBranchName';\nimport { ChecklistDetector, ChecklistRoster } from './checklist-detector';\nimport { DiffBasis, DiffBasisResolver } from './diff-basis';\nimport { PrContextWriter } from './pr-context-writer';\n\n/** How a caller wants the scan filtered. Data-only (per CLAUDE.md). */\nexport class ChecklistScanOptions {\n /**\n * false — `outstanding` is every applicable checklist (what `wp-review-upsert-pr` LISTS).\n * true — `outstanding` drops the ones already carrying a passing/overridden verdict, leaving only what\n * still owes review (what `wp-finish-upsert-pr` BLOCKS on).\n */\n filterAlreadyReviewed: boolean;\n /**\n * Which per-stage snapshot this scan should persist ('stage3-finish', …), or '' for \"do not write\n * pr-context.json here\".\n *\n * '' exists for stage ②, which cannot write yet: the context records `diffDir`, and the diff has not\n * been materialized at scan time. Letting the scan write anyway meant stage ② wrote the file twice,\n * ~60 lines apart, the first time with an empty diffDir. Now it writes once, after materializing.\n *\n * The DEFAULT is deliberately non-empty, so writing is what you get by NOT thinking about it. A\n * reviewer block that lost its diff command because nobody had written pr-context.json is a bug this\n * codebase has already shipped once (see PrContextWriter's docstring); opting out must be an explicit,\n * visible act by a caller that takes responsibility for writing it later — not an omission.\n */\n contextStage: string;\n\n constructor(filterAlreadyReviewed = false, contextStage = 'stage-scan') {\n this.filterAlreadyReviewed = filterAlreadyReviewed;\n this.contextStage = contextStage;\n }\n}\n\n/**\n * The answer to \"what review does this branch owe?\", in the X → N → Z terms the commands report:\n * X = `defined` — every checklist in pr-gate.checklists\n * N = `applicable` — those whose patterns matched (or that have no patterns, so always run)\n * Z = `outstanding` — of N, those still owing a verdict (only when filterAlreadyReviewed)\n * Data-only.\n */\nexport class ChecklistScan {\n defined: ChecklistDefinition[]; // X\n applicable: RequiredChecklist[]; // N\n reviewed: RequiredChecklist[]; // N − Z: already have a passing/warned/overridden review-<id>.json\n outstanding: RequiredChecklist[]; // Z (== applicable when not filtering)\n context: ChecklistReviewContext; // fork-point sha + pr-context.json path\n reviewPath: string; // the branch's review.json; verdict files sit beside it\n forkPoint: string; // '' when no fork point resolved\n // ALL X, matched or not, with why — what the PR comment publishes as its roster. Skipped checklists are\n // absent from `applicable` by construction, and recovering them downstream would mean a second\n // changed-file computation with different semantics (see the class comment).\n roster: ChecklistRoster;\n // Verdict files that exist but cannot be read as a verdict (e.g. still using the removed `success`).\n // Carried on the SCAN because wp-finish-upsert-pr refuses on missing reviewers before it ever parses\n // review.json — a complaint raised only in there would never reach the AI.\n formatErrors: string[];\n /**\n * The basis the matching ACTUALLY ran against. Carried out so a caller that materializes the diff\n * (stage ②) reuses the identical range instead of resolving its own — two independent resolutions is\n * exactly how the changed-file set and the printed `git diff` command came to disagree.\n */\n basis: DiffBasis;\n changedFiles: string[]; // the full changed-file set the matching ran against\n /**\n * The verdict files the scan ALREADY read, carried out rather than dropped.\n *\n * `outstanding` answers \"who still owes a verdict?\" but not \"why\" — and the two reasons demand opposite\n * actions from the reader: a reviewer that never ran must be SPAWNED, a reviewer that ran and REFUSED\n * must not be (it will refuse again; the finding has to be fixed first). Telling them apart means\n * resolving each checklist's verdict, and without the results here every caller either re-reads the same\n * files off disk — a second read that can disagree with this one — or merges the two cases into one\n * message, which is exactly the loop this field exists to break.\n */\n results: ChecklistResult[];\n /**\n * The OPTIONAL (`required: false`) applicable checklists carrying no verdict file — i.e. nobody ran them.\n *\n * Deliberately NOT in `outstanding` when filtering: that is the exemption that makes `required: false`\n * mean something. Carried out as its own set rather than merely subtracted, because both readers need it\n * BY NAME and neither can recover it from what is left: stage ② offers exactly these to the human, and\n * the PR dashboard must publish them as \"not run\" rather than let a shorter roster imply everything\n * passed. An optional checklist that ran and went RED is absent from here and stays in `outstanding`.\n */\n optionalNotRun: RequiredChecklist[];\n\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(\n defined: ChecklistDefinition[],\n applicable: RequiredChecklist[],\n reviewed: RequiredChecklist[],\n outstanding: RequiredChecklist[],\n context: ChecklistReviewContext,\n reviewPath: string,\n forkPoint: string,\n roster: ChecklistRoster,\n formatErrors: string[],\n basis: DiffBasis = new DiffBasis(),\n changedFiles: string[] = [],\n // Defaulted so a caller that only cares about the X/N/Z counts (and every existing test construction)\n // stays a one-liner; the scanner itself always passes the real set.\n results: ChecklistResult[] = [],\n optionalNotRun: RequiredChecklist[] = [],\n ) {\n this.defined = defined;\n this.applicable = applicable;\n this.reviewed = reviewed;\n this.outstanding = outstanding;\n this.context = context;\n this.reviewPath = reviewPath;\n this.forkPoint = forkPoint;\n this.roster = roster;\n this.formatErrors = formatErrors;\n this.basis = basis;\n this.changedFiles = changedFiles;\n this.results = results;\n this.optionalNotRun = optionalNotRun;\n }\n}\n\n/**\n * The ONE computation of which reviewer subagents a branch owes, shared by `wp-review-upsert-pr` (which lists) and\n * `wp-finish-upsert-pr` (which blocks). They previously each assembled this from the same parts in slightly\n * different ways, and any divergence means the command that reports and the command that gates disagree.\n *\n * Two properties are deliberate and load-bearing:\n *\n * 1. **The base is the FORK POINT of main, computed directly** — never `DiffScope.resolveBase`, which\n * overlays `NX_BASE`/`NX_HEAD` from the environment. That made review coverage depend on an env var.\n * It now arrives via {@link DiffBasisResolver}, which injects ForkPoint; same sha, one resolution.\n * 2. **UNCOMMITTED work counts.** `getChangedFiles` is called with NO head, which is the branch of it that\n * diffs base → WORKING TREE and unions in untracked files. Passing a head would diff commit-to-commit and\n * silently miss staged, unstaged and untracked changes — so a checklist matching only uncommitted files\n * would never fire and its reviewer would never be listed.\n * 3. **The range and the command it prints are the SAME basis.** Property 2 used to be true of the file set\n * only: reviewers were handed `git diff <base> HEAD`, which on a dirty tree covers a different range and\n * prints nothing. Both now derive from one {@link DiffBasis}, carried on the scan so a materializing\n * caller cannot re-resolve and drift.\n *\n * `@injectable(bindingScopeValues.Singleton)` so it is injected by type and drawn in the DI design.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class ChecklistScanner {\n constructor(\n private readonly aiBranchName: AiBranchName,\n private readonly checklistDetector: ChecklistDetector,\n private readonly diffScope: DiffScope,\n private readonly diffBasisResolver: DiffBasisResolver,\n private readonly prContextWriter: PrContextWriter,\n private readonly reviewJsonService: ReviewJsonService,\n ) {}\n\n /**\n * `defined` is the caller's ALREADY-VALIDATED `prGate.checklists`. The scanner deliberately does not load\n * config itself: `loadAndValidate` is the one gate on the checklist set (it rejects a non-array\n * `checklists`, including the removed `{ doc }` manifest shape, and verifies every guidance doc and\n * reviewer-agent file exists), both callers already run it for other fields, and keeping the read out of\n * here leaves this a function of its inputs rather than of the filesystem.\n */\n scan(repoRoot: string, defined: ChecklistDefinition[], opts: ChecklistScanOptions): ChecklistScan {\n const featureName = this.aiBranchName.getFeatureName();\n const reviewPath = reviewJsonPath(repoRoot, featureName);\n // ONE basis for the file set, the reproduce command and any downstream materialization. The fork\n // point still comes from ForkPoint (never DiffScope.resolveBase) — DiffBasisResolver injects it.\n const basis = this.diffBasisResolver.resolve(repoRoot);\n const base = basis.base;\n // ONE changed-file computation feeds both the roster (all X) and the applicable set (N). `detect` is\n // pure and defined as the roster minus its empty entries, so the two cannot disagree about a match.\n const changedFiles = this.changedFiles(repoRoot, base);\n const roster = new ChecklistRoster(\n this.checklistDetector.roster(defined, changedFiles), changedFiles.length, base !== '');\n const applicable = this.checklistDetector.toRequired(this.checklistDetector.detect(defined, changedFiles));\n const results = this.reviewJsonService.loadChecklistResults(reviewPath, applicable);\n const stillOwed = this.reviewJsonService.pendingChecklists(applicable, results);\n const owedIds = new Set(stillOwed.map((r: RequiredChecklist): string => r.id));\n // NOT `!owedIds.has(...)`-with-the-optional-exemption-folded-in: an optional checklist nobody ran is\n // neither reviewed nor blocking, and calling it \"reviewed\" would put a ✓ on the dashboard for a review\n // that never happened.\n const reviewed = applicable.filter((r: RequiredChecklist): boolean => !owedIds.has(r.id));\n const optionalNotRun = this.reviewJsonService.optionalWithoutVerdict(applicable, results);\n return new ChecklistScan(\n defined,\n applicable,\n reviewed,\n opts.filterAlreadyReviewed ? this.blocking(stillOwed, optionalNotRun) : applicable,\n opts.contextStage === ''\n ? this.prContextWriter.contextFor(repoRoot, featureName, basis)\n : this.prContextWriter.ensure(repoRoot, featureName, basis, opts.contextStage, changedFiles),\n reviewPath,\n base,\n roster,\n this.reviewJsonService.checklistFormatErrors(applicable, results),\n basis,\n changedFiles,\n results,\n optionalNotRun,\n );\n }\n\n /**\n * What `wp-finish-upsert-pr` actually REFUSES on: everything still owing a verdict, minus the optional\n * checklists nobody ran.\n *\n * The subtraction happens HERE — in the one place `outstanding` is computed — and not in the gate, so\n * there is a single answer to \"does this branch owe review?\". When the gate did its own filtering, the\n * command that lists and the command that blocks were two implementations of the same question, which is\n * exactly the divergence this class's docstring exists to prevent.\n */\n private blocking(stillOwed: readonly RequiredChecklist[], optionalNotRun: readonly RequiredChecklist[]): RequiredChecklist[] {\n const skipped = new Set(optionalNotRun.map((r: RequiredChecklist): string => r.id));\n return stillOwed.filter((r: RequiredChecklist): boolean => !skipped.has(r.id));\n }\n\n /**\n * Every file changed since the fork point, INCLUDING uncommitted and untracked ones. Two non-default\n * options, both load-bearing:\n *\n * `tsOnly:false` — the default drops every *.sql / Dockerfile / .env* file a checklist most wants\n * to key on, which would silently shrink the set a reviewer is pointed at.\n * `includeDeletions:true` — the default is `--diff-filter=d`, so a DELETED file is invisible. A PR that\n * deletes a migration, an auth check or a terraform rule changed exactly what a\n * checklist exists to catch, and under the default no checklist fires at all.\n */\n private changedFiles(repoRoot: string, base: string): string[] {\n if (base === '') return [];\n const opts = new ChangedFilesOptions();\n opts.tsOnly = false;\n opts.includeDeletions = true;\n // No head argument — see the class comment. This is what includes the working tree.\n return this.diffScope.getChangedFiles(repoRoot, base, undefined, opts);\n }\n}\n"]}
|
|
@@ -9,9 +9,9 @@ import { ChecklistNotice } from './checklist-notice';
|
|
|
9
9
|
* agent obeys that block, the reviewer re-reads unchanged code, refuses again — the loop, one stage earlier.
|
|
10
10
|
*
|
|
11
11
|
* The message is rendered by the COMMAND rather than in here for one reason: stage ② must not archive
|
|
12
|
-
* anything. `refusalError` called with no archive path
|
|
13
|
-
* which is only
|
|
14
|
-
* finish's act, on the refusal it is actually acting on.
|
|
12
|
+
* anything. `refusalError` called with no archive path says "fix it, then re-run; or set an override in
|
|
13
|
+
* review-<id>.json", which is only true while that file is still live — and at stage ② it is. Retiring a
|
|
14
|
+
* verdict is finish's act, on the refusal it is actually acting on.
|
|
15
15
|
*/
|
|
16
16
|
export declare class RefusedReviewer {
|
|
17
17
|
checklistId: string;
|