@webpieces/pr-gate 0.4.975 → 0.4.977

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (182) hide show
  1. package/package.json +6 -6
  2. package/src/scripts/commands/await-checks-command.d.ts +6 -3
  3. package/src/scripts/commands/await-checks-command.js +17 -12
  4. package/src/scripts/commands/await-checks-command.js.map +1 -1
  5. package/src/scripts/commands/await-reviews-command.d.ts +1 -1
  6. package/src/scripts/commands/await-reviews-command.js +3 -3
  7. package/src/scripts/commands/await-reviews-command.js.map +1 -1
  8. package/src/scripts/commands/check-pr-command.d.ts +3 -1
  9. package/src/scripts/commands/check-pr-command.js +12 -9
  10. package/src/scripts/commands/check-pr-command.js.map +1 -1
  11. package/src/scripts/commands/cleanup-command.js +12 -12
  12. package/src/scripts/commands/cleanup-command.js.map +1 -1
  13. package/src/scripts/commands/finish-push-dev-command.js +3 -4
  14. package/src/scripts/commands/finish-push-dev-command.js.map +1 -1
  15. package/src/scripts/commands/finish-update-command.js +1 -1
  16. package/src/scripts/commands/finish-update-command.js.map +1 -1
  17. package/src/scripts/commands/finish-upsert-pr-command.d.ts +4 -1
  18. package/src/scripts/commands/finish-upsert-pr-command.js +65 -62
  19. package/src/scripts/commands/finish-upsert-pr-command.js.map +1 -1
  20. package/src/scripts/commands/human-post-pr-command.d.ts +8 -6
  21. package/src/scripts/commands/human-post-pr-command.js +33 -32
  22. package/src/scripts/commands/human-post-pr-command.js.map +1 -1
  23. package/src/scripts/commands/land-pr-command.d.ts +5 -1
  24. package/src/scripts/commands/land-pr-command.js +37 -23
  25. package/src/scripts/commands/land-pr-command.js.map +1 -1
  26. package/src/scripts/commands/main-checkout.d.ts +4 -1
  27. package/src/scripts/commands/main-checkout.js +22 -22
  28. package/src/scripts/commands/main-checkout.js.map +1 -1
  29. package/src/scripts/commands/push-dev-command.js +28 -29
  30. package/src/scripts/commands/push-dev-command.js.map +1 -1
  31. package/src/scripts/commands/reap-worktree-command.js +4 -5
  32. package/src/scripts/commands/reap-worktree-command.js.map +1 -1
  33. package/src/scripts/commands/review-upsert-pr-command.js +10 -10
  34. package/src/scripts/commands/review-upsert-pr-command.js.map +1 -1
  35. package/src/scripts/commands/start-update-command.d.ts +1 -1
  36. package/src/scripts/commands/start-update-command.js +3 -3
  37. package/src/scripts/commands/start-update-command.js.map +1 -1
  38. package/src/scripts/commands/start-upsert-pr-command.js +4 -4
  39. package/src/scripts/commands/start-upsert-pr-command.js.map +1 -1
  40. package/src/scripts/commands/sync-main-command.js +6 -6
  41. package/src/scripts/commands/sync-main-command.js.map +1 -1
  42. package/src/scripts/commands/upsert-hotfix-pr-command.d.ts +6 -4
  43. package/src/scripts/commands/upsert-hotfix-pr-command.js +46 -43
  44. package/src/scripts/commands/upsert-hotfix-pr-command.js.map +1 -1
  45. package/src/scripts/commands/working-tree-gate.d.ts +4 -1
  46. package/src/scripts/commands/working-tree-gate.js +14 -11
  47. package/src/scripts/commands/working-tree-gate.js.map +1 -1
  48. package/src/scripts/commands/worktree-cleanup.d.ts +4 -4
  49. package/src/scripts/commands/worktree-cleanup.js +4 -4
  50. package/src/scripts/commands/worktree-cleanup.js.map +1 -1
  51. package/src/scripts/commands/write-review-command.js +4 -6
  52. package/src/scripts/commands/write-review-command.js.map +1 -1
  53. package/src/scripts/commands/write-review-fixes-command.js +3 -4
  54. package/src/scripts/commands/write-review-fixes-command.js.map +1 -1
  55. package/src/scripts/git-finishUpsertPr.js +2 -2
  56. package/src/scripts/git-finishUpsertPr.js.map +1 -1
  57. package/src/scripts/git-gatherInfo.js +6 -7
  58. package/src/scripts/git-gatherInfo.js.map +1 -1
  59. package/src/scripts/pr-gate-container.d.ts +9 -0
  60. package/src/scripts/pr-gate-container.js +19 -0
  61. package/src/scripts/pr-gate-container.js.map +1 -0
  62. package/src/scripts/workflow/await-loop.d.ts +1 -1
  63. package/src/scripts/workflow/await-loop.js +1 -1
  64. package/src/scripts/workflow/await-loop.js.map +1 -1
  65. package/src/scripts/workflow/build-affected.js +1 -1
  66. package/src/scripts/workflow/build-affected.js.map +1 -1
  67. package/src/scripts/workflow/build-artifact-gate.d.ts +1 -1
  68. package/src/scripts/workflow/build-artifact-gate.js +3 -3
  69. package/src/scripts/workflow/build-artifact-gate.js.map +1 -1
  70. package/src/scripts/workflow/build-gate-log.d.ts +9 -6
  71. package/src/scripts/workflow/build-gate-log.js +34 -40
  72. package/src/scripts/workflow/build-gate-log.js.map +1 -1
  73. package/src/scripts/workflow/checklist-detector.d.ts +2 -2
  74. package/src/scripts/workflow/checklist-detector.js +4 -4
  75. package/src/scripts/workflow/checklist-detector.js.map +1 -1
  76. package/src/scripts/workflow/checklist-scanner.d.ts +1 -1
  77. package/src/scripts/workflow/checklist-scanner.js +11 -11
  78. package/src/scripts/workflow/checklist-scanner.js.map +1 -1
  79. package/src/scripts/workflow/checklist-scope-hasher.d.ts +1 -1
  80. package/src/scripts/workflow/checklist-scope-hasher.js +2 -2
  81. package/src/scripts/workflow/checklist-scope-hasher.js.map +1 -1
  82. package/src/scripts/workflow/dev-deploy-refs.d.ts +5 -5
  83. package/src/scripts/workflow/dev-deploy-refs.js +8 -8
  84. package/src/scripts/workflow/dev-deploy-refs.js.map +1 -1
  85. package/src/scripts/workflow/dev-resolve-runner.d.ts +3 -3
  86. package/src/scripts/workflow/dev-resolve-runner.js +30 -30
  87. package/src/scripts/workflow/dev-resolve-runner.js.map +1 -1
  88. package/src/scripts/workflow/diff-basis.d.ts +4 -2
  89. package/src/scripts/workflow/diff-basis.js +18 -15
  90. package/src/scripts/workflow/diff-basis.js.map +1 -1
  91. package/src/scripts/workflow/diff-materializer.d.ts +5 -3
  92. package/src/scripts/workflow/diff-materializer.js +18 -15
  93. package/src/scripts/workflow/diff-materializer.js.map +1 -1
  94. package/src/scripts/workflow/gated-pr-publisher.d.ts +8 -6
  95. package/src/scripts/workflow/gated-pr-publisher.js +23 -22
  96. package/src/scripts/workflow/gated-pr-publisher.js.map +1 -1
  97. package/src/scripts/workflow/generated-artifact-registry.d.ts +4 -2
  98. package/src/scripts/workflow/generated-artifact-registry.js +11 -8
  99. package/src/scripts/workflow/generated-artifact-registry.js.map +1 -1
  100. package/src/scripts/workflow/git-exec.d.ts +22 -12
  101. package/src/scripts/workflow/git-exec.js +45 -29
  102. package/src/scripts/workflow/git-exec.js.map +1 -1
  103. package/src/scripts/workflow/git-findForkPoint.d.ts +6 -2
  104. package/src/scripts/workflow/git-findForkPoint.js +31 -23
  105. package/src/scripts/workflow/git-findForkPoint.js.map +1 -1
  106. package/src/scripts/workflow/git-readAiBranchName.d.ts +4 -2
  107. package/src/scripts/workflow/git-readAiBranchName.js +8 -5
  108. package/src/scripts/workflow/git-readAiBranchName.js.map +1 -1
  109. package/src/scripts/workflow/hotfix-pr-publisher.d.ts +4 -3
  110. package/src/scripts/workflow/hotfix-pr-publisher.js +7 -6
  111. package/src/scripts/workflow/hotfix-pr-publisher.js.map +1 -1
  112. package/src/scripts/workflow/landed-tree-resolver.d.ts +4 -2
  113. package/src/scripts/workflow/landed-tree-resolver.js +11 -8
  114. package/src/scripts/workflow/landed-tree-resolver.js.map +1 -1
  115. package/src/scripts/workflow/landed-worktree-reaper.d.ts +4 -2
  116. package/src/scripts/workflow/landed-worktree-reaper.js +12 -9
  117. package/src/scripts/workflow/landed-worktree-reaper.js.map +1 -1
  118. package/src/scripts/workflow/merge-end.d.ts +5 -4
  119. package/src/scripts/workflow/merge-end.js +28 -27
  120. package/src/scripts/workflow/merge-end.js.map +1 -1
  121. package/src/scripts/workflow/merge-start.d.ts +5 -1
  122. package/src/scripts/workflow/merge-start.js +56 -49
  123. package/src/scripts/workflow/merge-start.js.map +1 -1
  124. package/src/scripts/workflow/open-pr-check.d.ts +4 -2
  125. package/src/scripts/workflow/open-pr-check.js +11 -8
  126. package/src/scripts/workflow/open-pr-check.js.map +1 -1
  127. package/src/scripts/workflow/pr-comment-upserter.d.ts +5 -3
  128. package/src/scripts/workflow/pr-comment-upserter.js +15 -14
  129. package/src/scripts/workflow/pr-comment-upserter.js.map +1 -1
  130. package/src/scripts/workflow/pr-context-writer.d.ts +1 -1
  131. package/src/scripts/workflow/pr-context-writer.js +3 -3
  132. package/src/scripts/workflow/pr-context-writer.js.map +1 -1
  133. package/src/scripts/workflow/pr-merger.d.ts +8 -5
  134. package/src/scripts/workflow/pr-merger.js +32 -27
  135. package/src/scripts/workflow/pr-merger.js.map +1 -1
  136. package/src/scripts/workflow/provenance-enforcer.d.ts +4 -2
  137. package/src/scripts/workflow/provenance-enforcer.js +19 -17
  138. package/src/scripts/workflow/provenance-enforcer.js.map +1 -1
  139. package/src/scripts/workflow/review-round-state.d.ts +7 -6
  140. package/src/scripts/workflow/review-round-state.js +33 -38
  141. package/src/scripts/workflow/review-round-state.js.map +1 -1
  142. package/src/scripts/workflow/run-update.js +1 -1
  143. package/src/scripts/workflow/run-update.js.map +1 -1
  144. package/src/scripts/workflow/squash-settings-enforcer.d.ts +6 -3
  145. package/src/scripts/workflow/squash-settings-enforcer.js +19 -14
  146. package/src/scripts/workflow/squash-settings-enforcer.js.map +1 -1
  147. package/src/scripts/wp-await-checks.js +2 -2
  148. package/src/scripts/wp-await-checks.js.map +1 -1
  149. package/src/scripts/wp-await-reviews.js +2 -2
  150. package/src/scripts/wp-await-reviews.js.map +1 -1
  151. package/src/scripts/wp-build.js +2 -2
  152. package/src/scripts/wp-build.js.map +1 -1
  153. package/src/scripts/wp-check-pr.js +2 -2
  154. package/src/scripts/wp-check-pr.js.map +1 -1
  155. package/src/scripts/wp-cleanup.js +2 -2
  156. package/src/scripts/wp-cleanup.js.map +1 -1
  157. package/src/scripts/wp-finish-push-dev.js +2 -2
  158. package/src/scripts/wp-finish-push-dev.js.map +1 -1
  159. package/src/scripts/wp-finish-update.js +2 -2
  160. package/src/scripts/wp-finish-update.js.map +1 -1
  161. package/src/scripts/wp-human-post-pr.js +2 -2
  162. package/src/scripts/wp-human-post-pr.js.map +1 -1
  163. package/src/scripts/wp-land-pr.js +2 -2
  164. package/src/scripts/wp-land-pr.js.map +1 -1
  165. package/src/scripts/wp-push-dev.js +2 -2
  166. package/src/scripts/wp-push-dev.js.map +1 -1
  167. package/src/scripts/wp-reap-worktree.js +2 -2
  168. package/src/scripts/wp-reap-worktree.js.map +1 -1
  169. package/src/scripts/wp-review-upsert-pr.js +2 -2
  170. package/src/scripts/wp-review-upsert-pr.js.map +1 -1
  171. package/src/scripts/wp-start-update.js +2 -2
  172. package/src/scripts/wp-start-update.js.map +1 -1
  173. package/src/scripts/wp-start-upsert-pr.js +2 -2
  174. package/src/scripts/wp-start-upsert-pr.js.map +1 -1
  175. package/src/scripts/wp-sync-main.js +2 -2
  176. package/src/scripts/wp-sync-main.js.map +1 -1
  177. package/src/scripts/wp-upsert-hotfix-pr.js +2 -2
  178. package/src/scripts/wp-upsert-hotfix-pr.js.map +1 -1
  179. package/src/scripts/wp-write-review-fixes.js +2 -2
  180. package/src/scripts/wp-write-review-fixes.js.map +1 -1
  181. package/src/scripts/wp-write-review.js +2 -2
  182. package/src/scripts/wp-write-review.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"review-upsert-pr-command.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/commands/review-upsert-pr-command.ts"],"names":[],"mappings":";;;;AAAA,+CAAyB;AACzB,0DAAmN;AACnN,yCAA2D;AAC3D,+DAA4E;AAC5E,2EAAgE;AAChE,+DAA6E;AAC7E,+DAA0D;AAC1D,yEAAoE;AACpE,qEAAsG;AACtG,qEAAiE;AACjE,mDAA+C;AAC/C,yDAAuD;AACvD,qDAAkE;AAClE,yDAAqD;AACrD,qEAAgE;AAChE,qFAAgF;AAChF,6DAA6F;AAC7F,2EAAiG;AACjG,mEAAkF;AAClF,iEAA6D;AAC7D,uEAEwC;AAExC,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAEvE;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEI,IAAM,qBAAqB,GAA3B,MAAM,qBAAqB;IAGT;IAC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,gCAAiB;QACtB,iCAAc;QACZ,gCAAc;QACtB,4CAAuB;GAtB3C,qBAAqB,CAmRjC","sourcesContent":["import * as fs from 'fs';\nimport { loadAndValidate, writeTemplate, PrGateConfig, RepoRootFinder, RequiredChecklist, ReviewerBriefing, ReviewerInstructionsService, ReviewJsonService, summaryJsonSchemaHint } from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { ActiveHatch, ActiveHatchReport } from '../workflow/active-hatches';\nimport { AiBranchName } from '../workflow/git-readAiBranchName';\nimport { BuildAffected, BuildGateOptions } from '../workflow/build-affected';\nimport { REVIEW_STAGE } from '../workflow/build-gate-log';\nimport { BuildArtifactGate } from '../workflow/build-artifact-gate';\nimport { ChecklistScan, ChecklistScanOptions, ChecklistScanner } from '../workflow/checklist-scanner';\nimport { DiffMaterializer } from '../workflow/diff-materializer';\nimport { GitExec } from '../workflow/git-exec';\nimport { MergeContext } from '../workflow/merge-start';\nimport { MergeEnd, MergeEndOptions } from '../workflow/merge-end';\nimport { MergeState } from '../workflow/merge-state';\nimport { PrContextWriter } from '../workflow/pr-context-writer';\nimport { ReviewerBriefingBuilder } from '../workflow/reviewer-briefing-builder';\nimport { RefusedReviewer, ReviewReport, ReviewReportInput } from '../workflow/review-report';\nimport { ReviewStageReceipt, ReviewStageReceiptService } from '../workflow/review-stage-receipt';\nimport { StageOutputLog, REVIEW_CONSOLE_LOG } from '../workflow/stage-output-log';\nimport { HotfixRedirect } from '../workflow/hotfix-redirect';\nimport {\n ReviewRoundPlan, ReviewRoundStateService, ROUND_ACTION_REVIEW, ROUND_ACTION_RESUME,\n} from '../workflow/review-round-state';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n/**\n * `wp-review-upsert-pr` — STAGE ② of the three-stage PR flow, between `wp-start-upsert-pr` (sync from main)\n * and `wp-finish-upsert-pr` (post the PR).\n *\n * It exists because reviewing came before verifying. Under the old two-command flow the 3-point merge was\n * finalized and the build gate ran inside `wp-finish-upsert-pr` — i.e. AFTER the reviewers had already run.\n * A reviewer could therefore spend a full review on an unresolved merge, or on code that does not compile,\n * and only afterwards would the branch be checked. This command puts the verification first:\n *\n * 1. finalize + VALIDATE any in-progress 3-point merge (moved here from finish)\n * 2. assert a clean tree (meaningful now — step 1 committed the resolution)\n * 3. run the build gate (on the merged, committed tree)\n * 4. scan the checklists, EXTRACT the diff, BRIEF the reviewers\n * 5. write the stage receipt, then print what to spawn + the summary.json schema\n *\n * Unlike the report-only command it replaces — which always exited 0, because reporting is not gating — this\n * command CAN FAIL, at steps 1, 2 and 3. That is the point: it fails BEFORE any reviewer is spawned, so a\n * branch with an unresolved merge or a broken build costs zero reviewer tokens.\n *\n * The ordering of 1 → 2 → 3 is load-bearing. MergeEnd stages and commits the conflict resolution, so the\n * tree is clean by the time the build runs; building first would either build a dirty tree (proving nothing\n * about what ships) or refuse a tree that is legitimately mid-resolution.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class ReviewUpsertPrCommand {\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(\n private readonly repoRootFinder: RepoRootFinder,\n private readonly aiBranchName: AiBranchName,\n private readonly gitExec: GitExec,\n private readonly buildAffected: BuildAffected,\n private readonly buildArtifactGate: BuildArtifactGate,\n private readonly mergeState: MergeState,\n private readonly mergeEnd: MergeEnd,\n private readonly checklistScanner: ChecklistScanner,\n private readonly reviewReport: ReviewReport,\n private readonly materializer: DiffMaterializer,\n private readonly prContextWriter: PrContextWriter,\n private readonly briefingBuilder: ReviewerBriefingBuilder,\n private readonly reviewerInstructions: ReviewerInstructionsService,\n private readonly receipts: ReviewStageReceiptService,\n private readonly activeHatchReport: ActiveHatchReport,\n // Injected to RESOLVE + RENDER refusals (see refusals()) and to name each round's verdict file.\n private readonly reviewJsonService: ReviewJsonService,\n private readonly stageConsole: StageOutputLog,\n private readonly hotfixRedirect: HotfixRedirect,\n private readonly rounds: ReviewRoundStateService,\n ) {}\n\n /**\n * Everything below runs with this stage's console CAPTURED to a file (see StageOutputLog). Only the\n * lines an agent must act on before it can do anything else reach the terminal — the build heartbeat\n * and result, and the closing instruction block. The merge validation, the hatch report, the checklist\n * scan and the diff extraction are all in the file, one `grep` away.\n *\n * This is the FIRST half of the fix for the piped-command watchdog kill: an agent pipes a command it\n * expects to flood, a pipe withholds every byte until exit, and the harness kills a command that has\n * printed nothing for 600 seconds — after a full build. Guarding the pipe without first shrinking the\n * output would only have traded that kill for a flooded context.\n */\n async run(): Promise<void> {\n // A /hotfix/ branch has no review stage — it publishes with wp-upsert-hotfix-pr (issue #1057).\n this.hotfixRedirect.assertNotHotfix('wp-review-upsert-pr');\n const repoRoot = this.repoRootFinder.resolveRepoRoot(process.cwd());\n await this.stageConsole.withCapture(repoRoot, REVIEW_CONSOLE_LOG, (): Promise<void> => this.runStage(repoRoot));\n }\n\n private async runStage(repoRoot: string): Promise<void> {\n writeTemplate(repoRoot, 'webpieces.git-workflow.md');\n writeTemplate(repoRoot, 'webpieces.review-checklists.md');\n const featureName = this.aiBranchName.getFeatureName();\n const config = loadAndValidate(repoRoot).prGate;\n\n const mergeValidated = await this.finalizeAnyInProgressMerge(repoRoot);\n this.gitExec.assertCleanTree(repoRoot);\n const buildPassedAt = await this.runBuildGate(repoRoot);\n\n const scan = this.checklistScanner.scan(repoRoot, config.checklists, new ChecklistScanOptions(config.maxReviewerRounds, false, '')); // '' — THIS command writes the context itself, after materializing\n const previousReceipt = this.receipts.read(repoRoot, featureName);\n const plan = this.rounds.plan(repoRoot, scan.summaryPath, previousReceipt, config.maxReviewerRounds, scan.basis);\n if (plan.action === ROUND_ACTION_RESUME && previousReceipt !== null) {\n this.resumeRound(repoRoot, featureName, scan, previousReceipt, mergeValidated, buildPassedAt);\n this.reportActiveHatches(repoRoot);\n if (scan.reviewersDisabled) this.report(repoRoot, featureName, scan, [], plan, config);\n return;\n }\n const shouldBrief = plan.action === ROUND_ACTION_REVIEW;\n const briefings = shouldBrief\n ? this.briefReviewers(repoRoot, featureName, scan, config, plan)\n : [];\n const recordedReviewers = briefings.map((b: ReviewerBriefing): string => b.checklistId);\n if (shouldBrief) {\n const receipt = new ReviewStageReceipt(scan.basis.headSha, mergeValidated, this.buildAffected.resolveBuildCommand(repoRoot), buildPassedAt, recordedReviewers);\n receipt.scopeHashes = scan.scopeHashes;\n // Which briefed checklists are OPTIONAL: a round is complete once every REQUIRED one has a\n // verdict, and an optional one joins the round only if it actually submitted (issue #1062).\n receipt.optionalBriefed = briefings.filter((b: ReviewerBriefing): boolean => !b.required).map((b: ReviewerBriefing): string => b.checklistId);\n // A global round begins only when a non-empty fixed roster is actually briefed.\n receipt.round = recordedReviewers.length === 0 ? 0 : plan.round;\n receipt.maxReviewerRounds = plan.maxRounds;\n this.receipts.write(repoRoot, featureName, receipt);\n } else if (previousReceipt !== null) {\n previousReceipt.buildHeadSha = scan.basis.headSha;\n previousReceipt.mergeValidated = mergeValidated;\n previousReceipt.buildCommand = this.buildAffected.resolveBuildCommand(repoRoot);\n previousReceipt.buildPassedAt = buildPassedAt;\n this.receipts.write(repoRoot, featureName, previousReceipt);\n }\n this.reportActiveHatches(repoRoot);\n this.report(repoRoot, featureName, scan, briefings, plan, config);\n }\n\n /** Keep the original briefing, diff, roster and provenance intact while refreshing build evidence. */\n // eslint-disable-next-line @typescript-eslint/max-params\n private resumeRound(\n repoRoot: string,\n featureName: string,\n scan: ChecklistScan,\n receipt: ReviewStageReceipt,\n mergeValidated: boolean,\n buildPassedAt: string,\n ): void {\n receipt.buildHeadSha = scan.basis.headSha;\n receipt.mergeValidated = mergeValidated;\n receipt.buildCommand = this.buildAffected.resolveBuildCommand(repoRoot);\n receipt.buildPassedAt = buildPassedAt;\n this.receipts.write(repoRoot, featureName, receipt);\n // The scanner owns reviewer suppression. Keep the historical roster for later recovery, but\n // never instruct it to run while the existing opt-out is active.\n if (scan.reviewersDisabled) return;\n const pending = receipt.reviewersBriefed.filter(\n (id: string): boolean =>\n !receipt.optionalBriefed.includes(id) &&\n !this.rounds.hasVerdict(scan.summaryPath, id, receipt.round),\n );\n this.stageConsole.say(\n `\\nResume the existing reviewer roster: round ${receipt.round} of ${receipt.maxReviewerRounds}.\\n` +\n `Build passed at ${receipt.buildHeadSha}; reviewers retain their briefing at ${receipt.headSha}.\\n` +\n 'Continue the existing reviewer agents; do not respawn them for a SHA or fork-point change.\\n' +\n pending\n .map(\n (id: string): string =>\n ` REQUIRED ${id}: ${this.reviewerInstructions.pathFor(repoRoot, featureName, id)}\\n` +\n ` Submit with: pnpm wp-write-review --checklist ${id} --file '<verdict JSON file>'\\n`,\n )\n .join('') +\n `\\nBefore reviewers read it, write ${scan.summaryPath}, or keep its unchanged same-PR metadata.\\n` +\n 'Explicitly refresh it when intent, issue, title or risk changes.\\n' +\n `${summaryJsonSchemaHint(scan.summaryPath)}\\n` +\n 'Then run: pnpm wp-review-upsert-pr (to plan any RED follow-up), followed by pnpm wp-finish-upsert-pr.\\n',\n );\n }\n\n /**\n * List every rule that is currently switched off in webpieces.config.json. NON-BLOCKING and printed\n * before the instruction block, because it is context for the review rather than a step in it.\n *\n * A hatch is the one config change that makes the build QUIETER, so no gate, reviewer or red check\n * will ever mention it — which is how a repo ends up with rules off for weeks that nobody chose to\n * leave off. This is the only place in the flow that says so out loud.\n */\n private reportActiveHatches(repoRoot: string): void {\n const hatches: ActiveHatch[] = this.activeHatchReport.scan(repoRoot);\n process.stdout.write(this.activeHatchReport.render(hatches));\n }\n\n /**\n * Validate + commit + finalize a conflict resolution, if one is in flight. MOVED here from\n * `wp-finish-upsert-pr` so that exactly one command owns merge finalization — two owners is the drift\n * failure `PrContextWriter`'s own docstring records having already happened once in this codebase.\n *\n * MergeEnd's three checks are what \"did the AI do the 3-point merge right?\" means concretely: no\n * conflict markers left in the scoped files, `git diff --diff-filter=U` empty, and a non-empty\n * merge-explanation.md beside every conflicted file.\n *\n * Returns true when a merge was finalized OR there was none to finalize; it throws rather than returning\n * false when validation fails, so the receipt can never record an unvalidated merge as validated.\n */\n private async finalizeAnyInProgressMerge(repoRoot: string): Promise<boolean> {\n const home = this.mergeState.mergeDirFor(repoRoot, this.aiBranchName.getFeatureName());\n const activeDir = this.mergeState.findActiveMergeRunDir(home);\n const marker = activeDir ? this.mergeState.readMergeMarker(activeDir) : null;\n if (!activeDir || !marker || marker.validated) return true;\n process.stdout.write('\\n' + SEP + '① Validating your 3-point merge\\n' + SEP + '\\n');\n // pushRemote:false — finish still owns the single push.\n await this.mergeEnd.mergeEnd(repoRoot, 'wp-review-upsert-pr', activeDir, new MergeContext(marker.currentBranch, marker.squashBranch, marker.backupBranch, marker.prNumber), new MergeEndOptions(marker.conflictedFiles, false));\n return true;\n }\n\n /**\n * The build gate, run BEFORE any reviewer is briefed. Returns the ISO time it passed, for the receipt —\n * which is what lets `wp-finish-upsert-pr` skip its own gate when HEAD has not moved, so moving the gate\n * earlier did not turn one build into two.\n */\n private async runBuildGate(repoRoot: string): Promise<string> {\n await this.buildAffected.runBuildGate(repoRoot, new BuildGateOptions('🛠️ Build gate', 'pnpm wp-review-upsert-pr', 'Build failed — NO reviewer was briefed and no diff was extracted. Fix it, then re-run.', REVIEW_STAGE));\n // Repo-wide: the build must not have left anything uncommitted AND unstaged. Runs HERE, not in\n // finish, because this is the stage that ran buildCommand and is therefore holding the dirty\n // tree at the exact moment the question is answerable. Replaces the per-project\n // validate-di-graph-unchanged nx target — see BuildArtifactGate for why that one had to go.\n this.buildArtifactGate.assertBuildLeftNothingUncommitted(repoRoot);\n return new Date().toISOString();\n }\n\n /**\n * Extract the diff once, then write one instructions file per reviewer.\n *\n * The changed-file set and the basis both come off the SCAN rather than being recomputed, so the diff a\n * reviewer reads covers exactly the files its checklist matched against.\n */\n private briefReviewers(repoRoot: string, featureName: string, scan: ChecklistScan, config: PrGateConfig, plan: ReviewRoundPlan): ReviewerBriefing[] {\n if (plan.basis.unresolved) return [];\n const changedFiles = plan.round > 1 ? plan.changedFiles : scan.changedFiles;\n const manifest = this.materializer.materialize(repoRoot, featureName, plan.basis, changedFiles, config.reviewDiffExclude);\n const diffDir = this.materializer.diffDirFor(repoRoot, featureName);\n // Write pr-context.json ONCE, here — after materializing, so `diffDir` is populated on the first\n // write. The scan deliberately did not write it (ChecklistScanOptions.contextStage === ''); it used\n // to, which meant this command wrote the same file twice, the first time with an empty diffDir.\n // `scan.changedFiles` is passed through so the context is not recomputed from a second git call.\n scan.context = this.prContextWriter.ensure(repoRoot, featureName, plan.basis, 'stage2-review', changedFiles, diffDir);\n // ONLY the checklists still owed a verdict (issue #863). A green or yellow CARRIES whatever changed\n // since (issue #1053) — the scan left it in `reviewed` — so briefing it again would pay a reviewer to\n // re-read code it already judged. A later round re-briefs exactly the previous round's REDS.\n const reviewedIds = new Set(scan.reviewed.map((r: RequiredChecklist): string => r.id));\n const owed = scan.applicable.filter((r: RequiredChecklist): boolean => plan.round > 1\n ? plan.redChecklistIds.includes(r.id)\n : !reviewedIds.has(r.id));\n const briefings = this.briefingBuilder.build(repoRoot, scan, owed, manifest, diffDir, config);\n const dir = this.reviewerInstructions.instructionsDirFor(repoRoot, featureName);\n fs.rmSync(dir, { recursive: true, force: true }); // stale instructions read as current are worse than none\n fs.mkdirSync(dir, { recursive: true });\n for (const b of briefings) {\n b.round = plan.round;\n b.maxRounds = plan.maxRounds;\n b.verdictPath = this.reviewJsonService.checklistResultPath(scan.summaryPath, b.checklistId, plan.round);\n b.remediationOnly = plan.round > 1;\n if (b.remediationOnly) {\n b.previousVerdictPath = this.reviewJsonService.checklistResultPath(scan.summaryPath, b.checklistId, plan.round - 1);\n b.remediationPath = this.rounds.fixesPath(scan.summaryPath, plan.round - 1);\n }\n fs.writeFileSync(this.reviewerInstructions.pathFor(repoRoot, featureName, b.checklistId), this.reviewerInstructions.render(b));\n }\n return briefings;\n }\n\n /**\n * What the AI must do next — rendered by `ReviewReport`, which owns the ordering.\n *\n * The rendering moved OUT of this command so the ordering could be asserted on as a string. It had a\n * real bug: the zero-checklist notice signed off with \"Carry on and run: pnpm wp-finish-upsert-pr\"\n * while the block right beneath it said to write summary.json first. An agent that reads top to bottom\n * obeyed the first line and posted a PR with no review at all.\n */\n // eslint-disable-next-line @typescript-eslint/max-params\n private report(repoRoot: string, featureName: string, scan: ChecklistScan, briefings: readonly ReviewerBriefing[], plan: ReviewRoundPlan, config: PrGateConfig): void {\n const input = new ReviewReportInput(repoRoot, featureName, scan.summaryPath);\n input.definedCount = scan.defined.length;\n input.applicableCount = scan.applicable.length;\n input.reviewed = scan.reviewed.slice();\n input.formatErrors = scan.formatErrors.slice();\n input.briefings = briefings.slice();\n input.refused = this.refusals(scan);\n input.reviewer = config.reviewer;\n // Straight off the SCAN — the one place `experimental.turnOffAllReviewers` is read. This command\n // deliberately does NOT consult the home config itself: a second read is a second answer, and the\n // command that lists and the command that blocks would be free to disagree about whether a branch\n // was reviewed. See ChecklistScanner.\n input.reviewersSuppressed = scan.reviewersDisabled;\n input.suppressed = scan.suppressed.slice();\n input.round = plan.round;\n input.maxReviewerRounds = plan.maxRounds;\n input.roundAction = plan.action;\n input.redChecklistIds = plan.redChecklistIds.slice();\n input.orangeChecklistIds = plan.orangeChecklistIds.slice();\n input.notBriefed = scan.notBriefed.slice();\n input.standings = scan.standings.slice();\n // `say`: this block IS the next action — which reviewers to spawn, where summary.json goes, and\n // the command after that. Capturing it into the log would leave the terminal with a pointer and\n // no instruction, which is the one thing this stage may never do.\n this.stageConsole.say(this.reviewReport.render(input));\n }\n\n /**\n * The applicable checklists that ALREADY ANSWERED and refused, each with its refusal rendered by the ONE\n * renderer `wp-finish-upsert-pr` also uses.\n *\n * Stage ② had the identical defect finish did: a refused checklist has no passing verdict, so it is not\n * in `scan.reviewed`, so it was printed as an ordinary owed reviewer and re-instructed word for word —\n * and an agent that obeys spawns it against unchanged code, gets the same refusal, and loops one stage\n * earlier than the loop that was reported.\n *\n * Nothing is moved: a red verdict stays on disk as its round's record, and the next round's verdict is a\n * new file (issue #1053). The review path IS passed, because the ship-anyway route the refusal prints is a\n * command that writes `override-<id>.json` beside it.\n */\n private refusals(scan: ChecklistScan): RefusedReviewer[] {\n const refused = this.reviewJsonService.refusedChecklists(scan.applicable, scan.results);\n return refused.map((req: RequiredChecklist): RefusedReviewer => new RefusedReviewer(req.id, this.reviewJsonService.refusalError(req, this.reviewJsonService.resolveVerdict(req, scan.results), scan.summaryPath)));\n }\n}\n"]}
1
+ {"version":3,"file":"review-upsert-pr-command.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/commands/review-upsert-pr-command.ts"],"names":[],"mappings":";;;;AAAA,+CAAyB;AACzB,0DAAmN;AACnN,yCAA2D;AAC3D,+DAA4E;AAC5E,2EAAgE;AAChE,+DAA6E;AAC7E,+DAA0D;AAC1D,yEAAoE;AACpE,qEAAsG;AACtG,qEAAiE;AACjE,mDAA+C;AAC/C,yDAAuD;AACvD,qDAAkE;AAClE,yDAAqD;AACrD,qEAAgE;AAChE,qFAAgF;AAChF,6DAA6F;AAC7F,2EAAiG;AACjG,mEAAkF;AAClF,iEAA6D;AAC7D,uEAEwC;AAExC,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAEvE;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEI,IAAM,qBAAqB,GAA3B,MAAM,qBAAqB;IAGT;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IAEA;IACA;IACA;IACA;IArBrB,yDAAyD;IACzD,YACqB,cAA8B,EAC9B,YAA0B,EAC1B,OAAgB,EAChB,aAA4B,EAC5B,iBAAoC,EACpC,UAAsB,EACtB,QAAkB,EAClB,gBAAkC,EAClC,YAA0B,EAC1B,YAA8B,EAC9B,eAAgC,EAChC,eAAwC,EACxC,oBAAiD,EACjD,QAAmC,EACnC,iBAAoC;IACrD,gGAAgG;IAC/E,iBAAoC,EACpC,YAA4B,EAC5B,cAA8B,EAC9B,MAA+B;QAnB/B,mBAAc,GAAd,cAAc,CAAgB;QAC9B,iB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,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IAC3D,CAAC;IAED;;;;;;;;;;;;OAYG;IACK,QAAQ,CAAC,IAAmB;QAChC,MAAM,OAAO,GAAG,IAAI,CAAC,iBAAiB,CAAC,iBAAiB,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QACxF,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,GAAsB,EAAmB,EAAE,CAAC,IAAI,+BAAe,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,iBAAiB,CAAC,YAAY,CAAC,GAAG,EAAE,IAAI,CAAC,iBAAiB,CAAC,cAAc,CAAC,GAAG,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IACvN,CAAC;CACJ,CAAA;AAnRY,sDAAqB;gCAArB,qBAAqB;IADjC,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAIA,6BAAc;QAChB,mCAAY;QACjB,kBAAO;QACD,8BAAa;QACT,uCAAiB;QACxB,wBAAU;QACZ,oBAAQ;QACA,oCAAgB;QACpB,4BAAY;QACZ,oCAAgB;QACb,mCAAe;QACf,mDAAuB;QAClB,0CAA2B;QACvC,gDAAyB;QAChB,kCAAiB;QAEjB,gCAAiB;QACtB,iCAAc;QACZ,gCAAc;QACtB,4CAAuB;GAtB3C,qBAAqB,CAmRjC","sourcesContent":["import * as fs from 'fs';\nimport { loadAndValidate, writeTemplate, PrGateConfig, RepoRootFinder, RequiredChecklist, ReviewerBriefing, ReviewerInstructionsService, ReviewJsonService, summaryJsonSchemaHint } from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { ActiveHatch, ActiveHatchReport } from '../workflow/active-hatches';\nimport { AiBranchName } from '../workflow/git-readAiBranchName';\nimport { BuildAffected, BuildGateOptions } from '../workflow/build-affected';\nimport { REVIEW_STAGE } from '../workflow/build-gate-log';\nimport { BuildArtifactGate } from '../workflow/build-artifact-gate';\nimport { ChecklistScan, ChecklistScanOptions, ChecklistScanner } from '../workflow/checklist-scanner';\nimport { DiffMaterializer } from '../workflow/diff-materializer';\nimport { GitExec } from '../workflow/git-exec';\nimport { MergeContext } from '../workflow/merge-start';\nimport { MergeEnd, MergeEndOptions } from '../workflow/merge-end';\nimport { MergeState } from '../workflow/merge-state';\nimport { PrContextWriter } from '../workflow/pr-context-writer';\nimport { ReviewerBriefingBuilder } from '../workflow/reviewer-briefing-builder';\nimport { RefusedReviewer, ReviewReport, ReviewReportInput } from '../workflow/review-report';\nimport { ReviewStageReceipt, ReviewStageReceiptService } from '../workflow/review-stage-receipt';\nimport { StageOutputLog, REVIEW_CONSOLE_LOG } from '../workflow/stage-output-log';\nimport { HotfixRedirect } from '../workflow/hotfix-redirect';\nimport {\n ReviewRoundPlan, ReviewRoundStateService, ROUND_ACTION_REVIEW, ROUND_ACTION_RESUME,\n} from '../workflow/review-round-state';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n/**\n * `wp-review-upsert-pr` — STAGE ② of the three-stage PR flow, between `wp-start-upsert-pr` (sync from main)\n * and `wp-finish-upsert-pr` (post the PR).\n *\n * It exists because reviewing came before verifying. Under the old two-command flow the 3-point merge was\n * finalized and the build gate ran inside `wp-finish-upsert-pr` — i.e. AFTER the reviewers had already run.\n * A reviewer could therefore spend a full review on an unresolved merge, or on code that does not compile,\n * and only afterwards would the branch be checked. This command puts the verification first:\n *\n * 1. finalize + VALIDATE any in-progress 3-point merge (moved here from finish)\n * 2. assert a clean tree (meaningful now — step 1 committed the resolution)\n * 3. run the build gate (on the merged, committed tree)\n * 4. scan the checklists, EXTRACT the diff, BRIEF the reviewers\n * 5. write the stage receipt, then print what to spawn + the summary.json schema\n *\n * Unlike the report-only command it replaces — which always exited 0, because reporting is not gating — this\n * command CAN FAIL, at steps 1, 2 and 3. That is the point: it fails BEFORE any reviewer is spawned, so a\n * branch with an unresolved merge or a broken build costs zero reviewer tokens.\n *\n * The ordering of 1 → 2 → 3 is load-bearing. MergeEnd stages and commits the conflict resolution, so the\n * tree is clean by the time the build runs; building first would either build a dirty tree (proving nothing\n * about what ships) or refuse a tree that is legitimately mid-resolution.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class ReviewUpsertPrCommand {\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(\n private readonly repoRootFinder: RepoRootFinder,\n private readonly aiBranchName: AiBranchName,\n private readonly gitExec: GitExec,\n private readonly buildAffected: BuildAffected,\n private readonly buildArtifactGate: BuildArtifactGate,\n private readonly mergeState: MergeState,\n private readonly mergeEnd: MergeEnd,\n private readonly checklistScanner: ChecklistScanner,\n private readonly reviewReport: ReviewReport,\n private readonly materializer: DiffMaterializer,\n private readonly prContextWriter: PrContextWriter,\n private readonly briefingBuilder: ReviewerBriefingBuilder,\n private readonly reviewerInstructions: ReviewerInstructionsService,\n private readonly receipts: ReviewStageReceiptService,\n private readonly activeHatchReport: ActiveHatchReport,\n // Injected to RESOLVE + RENDER refusals (see refusals()) and to name each round's verdict file.\n private readonly reviewJsonService: ReviewJsonService,\n private readonly stageConsole: StageOutputLog,\n private readonly hotfixRedirect: HotfixRedirect,\n private readonly rounds: ReviewRoundStateService,\n ) {}\n\n /**\n * Everything below runs with this stage's console CAPTURED to a file (see StageOutputLog). Only the\n * lines an agent must act on before it can do anything else reach the terminal — the build heartbeat\n * and result, and the closing instruction block. The merge validation, the hatch report, the checklist\n * scan and the diff extraction are all in the file, one `grep` away.\n *\n * This is the FIRST half of the fix for the piped-command watchdog kill: an agent pipes a command it\n * expects to flood, a pipe withholds every byte until exit, and the harness kills a command that has\n * printed nothing for 600 seconds — after a full build. Guarding the pipe without first shrinking the\n * output would only have traded that kill for a flooded context.\n */\n async run(): Promise<void> {\n // A /hotfix/ branch has no review stage — it publishes with wp-upsert-hotfix-pr (issue #1057).\n this.hotfixRedirect.assertNotHotfix('wp-review-upsert-pr');\n const repoRoot = this.repoRootFinder.resolveRepoRoot(process.cwd());\n await this.stageConsole.withCapture(repoRoot, REVIEW_CONSOLE_LOG, (): Promise<void> => this.runStage(repoRoot));\n }\n\n private async runStage(repoRoot: string): Promise<void> {\n writeTemplate(repoRoot, 'webpieces.git-workflow.md');\n writeTemplate(repoRoot, 'webpieces.review-checklists.md');\n const featureName = await this.aiBranchName.getFeatureName();\n const config = loadAndValidate(repoRoot).prGate;\n\n const mergeValidated = await this.finalizeAnyInProgressMerge(repoRoot);\n await this.gitExec.assertCleanTree(repoRoot);\n const buildPassedAt = await this.runBuildGate(repoRoot);\n\n const scan = await this.checklistScanner.scan(repoRoot, config.checklists, new ChecklistScanOptions(config.maxReviewerRounds, false, '')); // '' — THIS command writes the context itself, after materializing\n const previousReceipt = this.receipts.read(repoRoot, featureName);\n const plan = await this.rounds.plan(repoRoot, scan.summaryPath, previousReceipt, config.maxReviewerRounds, scan.basis);\n if (plan.action === ROUND_ACTION_RESUME && previousReceipt !== null) {\n this.resumeRound(repoRoot, featureName, scan, previousReceipt, mergeValidated, buildPassedAt);\n this.reportActiveHatches(repoRoot);\n if (scan.reviewersDisabled) this.report(repoRoot, featureName, scan, [], plan, config);\n return;\n }\n const shouldBrief = plan.action === ROUND_ACTION_REVIEW;\n const briefings = shouldBrief\n ? await this.briefReviewers(repoRoot, featureName, scan, config, plan)\n : [];\n const recordedReviewers = briefings.map((b: ReviewerBriefing): string => b.checklistId);\n if (shouldBrief) {\n const receipt = new ReviewStageReceipt(scan.basis.headSha, mergeValidated, this.buildAffected.resolveBuildCommand(repoRoot), buildPassedAt, recordedReviewers);\n receipt.scopeHashes = scan.scopeHashes;\n // Which briefed checklists are OPTIONAL: a round is complete once every REQUIRED one has a\n // verdict, and an optional one joins the round only if it actually submitted (issue #1062).\n receipt.optionalBriefed = briefings.filter((b: ReviewerBriefing): boolean => !b.required).map((b: ReviewerBriefing): string => b.checklistId);\n // A global round begins only when a non-empty fixed roster is actually briefed.\n receipt.round = recordedReviewers.length === 0 ? 0 : plan.round;\n receipt.maxReviewerRounds = plan.maxRounds;\n this.receipts.write(repoRoot, featureName, receipt);\n } else if (previousReceipt !== null) {\n previousReceipt.buildHeadSha = scan.basis.headSha;\n previousReceipt.mergeValidated = mergeValidated;\n previousReceipt.buildCommand = this.buildAffected.resolveBuildCommand(repoRoot);\n previousReceipt.buildPassedAt = buildPassedAt;\n this.receipts.write(repoRoot, featureName, previousReceipt);\n }\n this.reportActiveHatches(repoRoot);\n this.report(repoRoot, featureName, scan, briefings, plan, config);\n }\n\n /** Keep the original briefing, diff, roster and provenance intact while refreshing build evidence. */\n // eslint-disable-next-line @typescript-eslint/max-params\n private resumeRound(\n repoRoot: string,\n featureName: string,\n scan: ChecklistScan,\n receipt: ReviewStageReceipt,\n mergeValidated: boolean,\n buildPassedAt: string,\n ): void {\n receipt.buildHeadSha = scan.basis.headSha;\n receipt.mergeValidated = mergeValidated;\n receipt.buildCommand = this.buildAffected.resolveBuildCommand(repoRoot);\n receipt.buildPassedAt = buildPassedAt;\n this.receipts.write(repoRoot, featureName, receipt);\n // The scanner owns reviewer suppression. Keep the historical roster for later recovery, but\n // never instruct it to run while the existing opt-out is active.\n if (scan.reviewersDisabled) return;\n const pending = receipt.reviewersBriefed.filter(\n (id: string): boolean =>\n !receipt.optionalBriefed.includes(id) &&\n !this.rounds.hasVerdict(scan.summaryPath, id, receipt.round),\n );\n this.stageConsole.say(\n `\\nResume the existing reviewer roster: round ${receipt.round} of ${receipt.maxReviewerRounds}.\\n` +\n `Build passed at ${receipt.buildHeadSha}; reviewers retain their briefing at ${receipt.headSha}.\\n` +\n 'Continue the existing reviewer agents; do not respawn them for a SHA or fork-point change.\\n' +\n pending\n .map(\n (id: string): string =>\n ` REQUIRED ${id}: ${this.reviewerInstructions.pathFor(repoRoot, featureName, id)}\\n` +\n ` Submit with: pnpm wp-write-review --checklist ${id} --file '<verdict JSON file>'\\n`,\n )\n .join('') +\n `\\nBefore reviewers read it, write ${scan.summaryPath}, or keep its unchanged same-PR metadata.\\n` +\n 'Explicitly refresh it when intent, issue, title or risk changes.\\n' +\n `${summaryJsonSchemaHint(scan.summaryPath)}\\n` +\n 'Then run: pnpm wp-review-upsert-pr (to plan any RED follow-up), followed by pnpm wp-finish-upsert-pr.\\n',\n );\n }\n\n /**\n * List every rule that is currently switched off in webpieces.config.json. NON-BLOCKING and printed\n * before the instruction block, because it is context for the review rather than a step in it.\n *\n * A hatch is the one config change that makes the build QUIETER, so no gate, reviewer or red check\n * will ever mention it — which is how a repo ends up with rules off for weeks that nobody chose to\n * leave off. This is the only place in the flow that says so out loud.\n */\n private reportActiveHatches(repoRoot: string): void {\n const hatches: ActiveHatch[] = this.activeHatchReport.scan(repoRoot);\n process.stdout.write(this.activeHatchReport.render(hatches));\n }\n\n /**\n * Validate + commit + finalize a conflict resolution, if one is in flight. MOVED here from\n * `wp-finish-upsert-pr` so that exactly one command owns merge finalization — two owners is the drift\n * failure `PrContextWriter`'s own docstring records having already happened once in this codebase.\n *\n * MergeEnd's three checks are what \"did the AI do the 3-point merge right?\" means concretely: no\n * conflict markers left in the scoped files, `git diff --diff-filter=U` empty, and a non-empty\n * merge-explanation.md beside every conflicted file.\n *\n * Returns true when a merge was finalized OR there was none to finalize; it throws rather than returning\n * false when validation fails, so the receipt can never record an unvalidated merge as validated.\n */\n private async finalizeAnyInProgressMerge(repoRoot: string): Promise<boolean> {\n const home = this.mergeState.mergeDirFor(repoRoot, await this.aiBranchName.getFeatureName());\n const activeDir = this.mergeState.findActiveMergeRunDir(home);\n const marker = activeDir ? this.mergeState.readMergeMarker(activeDir) : null;\n if (!activeDir || !marker || marker.validated) return true;\n process.stdout.write('\\n' + SEP + '① Validating your 3-point merge\\n' + SEP + '\\n');\n // pushRemote:false — finish still owns the single push.\n await this.mergeEnd.mergeEnd(repoRoot, 'wp-review-upsert-pr', activeDir, new MergeContext(marker.currentBranch, marker.squashBranch, marker.backupBranch, marker.prNumber), new MergeEndOptions(marker.conflictedFiles, false));\n return true;\n }\n\n /**\n * The build gate, run BEFORE any reviewer is briefed. Returns the ISO time it passed, for the receipt —\n * which is what lets `wp-finish-upsert-pr` skip its own gate when HEAD has not moved, so moving the gate\n * earlier did not turn one build into two.\n */\n private async runBuildGate(repoRoot: string): Promise<string> {\n await this.buildAffected.runBuildGate(repoRoot, new BuildGateOptions('🛠️ Build gate', 'pnpm wp-review-upsert-pr', 'Build failed — NO reviewer was briefed and no diff was extracted. Fix it, then re-run.', REVIEW_STAGE));\n // Repo-wide: the build must not have left anything uncommitted AND unstaged. Runs HERE, not in\n // finish, because this is the stage that ran buildCommand and is therefore holding the dirty\n // tree at the exact moment the question is answerable. Replaces the per-project\n // validate-di-graph-unchanged nx target — see BuildArtifactGate for why that one had to go.\n await this.buildArtifactGate.assertBuildLeftNothingUncommitted(repoRoot);\n return new Date().toISOString();\n }\n\n /**\n * Extract the diff once, then write one instructions file per reviewer.\n *\n * The changed-file set and the basis both come off the SCAN rather than being recomputed, so the diff a\n * reviewer reads covers exactly the files its checklist matched against.\n */\n private async briefReviewers(repoRoot: string, featureName: string, scan: ChecklistScan, config: PrGateConfig, plan: ReviewRoundPlan): Promise<ReviewerBriefing[]> {\n if (plan.basis.unresolved) return [];\n const changedFiles = plan.round > 1 ? plan.changedFiles : scan.changedFiles;\n const manifest = await this.materializer.materialize(repoRoot, featureName, plan.basis, changedFiles, config.reviewDiffExclude);\n const diffDir = this.materializer.diffDirFor(repoRoot, featureName);\n // Write pr-context.json ONCE, here — after materializing, so `diffDir` is populated on the first\n // write. The scan deliberately did not write it (ChecklistScanOptions.contextStage === ''); it used\n // to, which meant this command wrote the same file twice, the first time with an empty diffDir.\n // `scan.changedFiles` is passed through so the context is not recomputed from a second git call.\n scan.context = await this.prContextWriter.ensure(repoRoot, featureName, plan.basis, 'stage2-review', changedFiles, diffDir);\n // ONLY the checklists still owed a verdict (issue #863). A green or yellow CARRIES whatever changed\n // since (issue #1053) — the scan left it in `reviewed` — so briefing it again would pay a reviewer to\n // re-read code it already judged. A later round re-briefs exactly the previous round's REDS.\n const reviewedIds = new Set(scan.reviewed.map((r: RequiredChecklist): string => r.id));\n const owed = scan.applicable.filter((r: RequiredChecklist): boolean => plan.round > 1\n ? plan.redChecklistIds.includes(r.id)\n : !reviewedIds.has(r.id));\n const briefings = this.briefingBuilder.build(repoRoot, scan, owed, manifest, diffDir, config);\n const dir = this.reviewerInstructions.instructionsDirFor(repoRoot, featureName);\n fs.rmSync(dir, { recursive: true, force: true }); // stale instructions read as current are worse than none\n fs.mkdirSync(dir, { recursive: true });\n for (const b of briefings) {\n b.round = plan.round;\n b.maxRounds = plan.maxRounds;\n b.verdictPath = this.reviewJsonService.checklistResultPath(scan.summaryPath, b.checklistId, plan.round);\n b.remediationOnly = plan.round > 1;\n if (b.remediationOnly) {\n b.previousVerdictPath = this.reviewJsonService.checklistResultPath(scan.summaryPath, b.checklistId, plan.round - 1);\n b.remediationPath = this.rounds.fixesPath(scan.summaryPath, plan.round - 1);\n }\n fs.writeFileSync(this.reviewerInstructions.pathFor(repoRoot, featureName, b.checklistId), this.reviewerInstructions.render(b));\n }\n return briefings;\n }\n\n /**\n * What the AI must do next — rendered by `ReviewReport`, which owns the ordering.\n *\n * The rendering moved OUT of this command so the ordering could be asserted on as a string. It had a\n * real bug: the zero-checklist notice signed off with \"Carry on and run: pnpm wp-finish-upsert-pr\"\n * while the block right beneath it said to write summary.json first. An agent that reads top to bottom\n * obeyed the first line and posted a PR with no review at all.\n */\n // eslint-disable-next-line @typescript-eslint/max-params\n private report(repoRoot: string, featureName: string, scan: ChecklistScan, briefings: readonly ReviewerBriefing[], plan: ReviewRoundPlan, config: PrGateConfig): void {\n const input = new ReviewReportInput(repoRoot, featureName, scan.summaryPath);\n input.definedCount = scan.defined.length;\n input.applicableCount = scan.applicable.length;\n input.reviewed = scan.reviewed.slice();\n input.formatErrors = scan.formatErrors.slice();\n input.briefings = briefings.slice();\n input.refused = this.refusals(scan);\n input.reviewer = config.reviewer;\n // Straight off the SCAN — the one place `experimental.turnOffAllReviewers` is read. This command\n // deliberately does NOT consult the home config itself: a second read is a second answer, and the\n // command that lists and the command that blocks would be free to disagree about whether a branch\n // was reviewed. See ChecklistScanner.\n input.reviewersSuppressed = scan.reviewersDisabled;\n input.suppressed = scan.suppressed.slice();\n input.round = plan.round;\n input.maxReviewerRounds = plan.maxRounds;\n input.roundAction = plan.action;\n input.redChecklistIds = plan.redChecklistIds.slice();\n input.orangeChecklistIds = plan.orangeChecklistIds.slice();\n input.notBriefed = scan.notBriefed.slice();\n input.standings = scan.standings.slice();\n // `say`: this block IS the next action — which reviewers to spawn, where summary.json goes, and\n // the command after that. Capturing it into the log would leave the terminal with a pointer and\n // no instruction, which is the one thing this stage may never do.\n this.stageConsole.say(this.reviewReport.render(input));\n }\n\n /**\n * The applicable checklists that ALREADY ANSWERED and refused, each with its refusal rendered by the ONE\n * renderer `wp-finish-upsert-pr` also uses.\n *\n * Stage ② had the identical defect finish did: a refused checklist has no passing verdict, so it is not\n * in `scan.reviewed`, so it was printed as an ordinary owed reviewer and re-instructed word for word —\n * and an agent that obeys spawns it against unchanged code, gets the same refusal, and loops one stage\n * earlier than the loop that was reported.\n *\n * Nothing is moved: a red verdict stays on disk as its round's record, and the next round's verdict is a\n * new file (issue #1053). The review path IS passed, because the ship-anyway route the refusal prints is a\n * command that writes `override-<id>.json` beside it.\n */\n private refusals(scan: ChecklistScan): RefusedReviewer[] {\n const refused = this.reviewJsonService.refusedChecklists(scan.applicable, scan.results);\n return refused.map((req: RequiredChecklist): RefusedReviewer => new RefusedReviewer(req.id, this.reviewJsonService.refusalError(req, this.reviewJsonService.resolveVerdict(req, scan.results), scan.summaryPath)));\n }\n}\n"]}
@@ -7,5 +7,5 @@ export declare class StartUpdateCommand {
7
7
  private readonly runUpdate;
8
8
  constructor(repoRootFinder: RepoRootFinder, openPrCheck: OpenPrCheck, runUpdate: RunUpdate);
9
9
  run(): Promise<void>;
10
- assertNoOpenPr(repoRoot: string): void;
10
+ assertNoOpenPr(repoRoot: string): Promise<void>;
11
11
  }
@@ -27,7 +27,7 @@ let StartUpdateCommand = class StartUpdateCommand {
27
27
  (0, rules_config_1.writeTemplate)(repoRoot, 'webpieces.git-workflow.md');
28
28
  // An open PR means the PR flow must be used — a 3-point update would strand the PR on the old
29
29
  // branch generation. Fails fast if GitHub can't be reached (never guesses "no PR").
30
- this.assertNoOpenPr(repoRoot);
30
+ await this.assertNoOpenPr(repoRoot);
31
31
  // pushRemote=true: this is the END of the update-only flow — no later command pushes, so not
32
32
  // pushing here would silently strand the squash rewrite locally. (The PR flow passes false.)
33
33
  const outcome = await this.runUpdate.runUpdateFromMain(repoRoot, 'wp-start-update', 'wp-finish-update', true);
@@ -46,9 +46,9 @@ let StartUpdateCommand = class StartUpdateCommand {
46
46
  // re-squashes your branch onto main and force-pushes it to origin/<feature> — the PR head — but it
47
47
  // does NOT refresh the PR body/review or run the authoritative build gate. Fail fast and steer to
48
48
  // the PR flow, which re-merges main AND updates the PR.
49
- assertNoOpenPr(repoRoot) {
49
+ async assertNoOpenPr(repoRoot) {
50
50
  const branch = tooling_common_1.gitCheckout.requireBranch(repoRoot);
51
- const openPr = this.openPrCheck.openPrForBranch(repoRoot, branch);
51
+ const openPr = await this.openPrCheck.openPrForBranch(repoRoot, branch);
52
52
  if (openPr === '')
53
53
  return;
54
54
  throw new rules_config_1.CliExitError(2, '\n' + SEP + `⛔ An open PR (#${openPr}) already tracks this branch\n` + SEP + '\n' +
@@ -1 +1 @@
1
- {"version":3,"file":"start-update-command.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/commands/start-update-command.ts"],"names":[],"mappings":";;;;AAAA,8DAAwD;AACxD,0DAAsF;AACtF,yCAA2D;AAC3D,6DAAwD;AACxD,uDAAmD;AAEnD,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAEvE,8FAA8F;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,QAAQ,CAAC,CAAC;QACnD,MAAM,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,eAAe,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QAClE,IAAI,MAAM,KAAK,EAAE;YAAE,OAAO;QAC1B,MAAM,IAAI,2BAAY,CAAC,CAAC,EACpB,IAAI,GAAG,GAAG,GAAG,kBAAkB,MAAM,gCAAgC,GAAG,GAAG,GAAG,IAAI;YAClF,kGAAkG;YAClG,+BAA+B,MAAM,6DAA6D;YAClG,wDAAwD;YACxD,gCAAgC;YAChC,wCAAwC;YACxC,uFAAuF;YACvF,kEAAkE;YAClE,iCAAiC,CACpC,CAAC;IACN,CAAC;CACJ,CAAA;AArDY,gDAAkB;6BAAlB,kBAAkB;IAD9B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGA,6BAAc;QACjB,2BAAW;QACb,sBAAS;GAJhC,kBAAkB,CAqD9B","sourcesContent":["import { gitCheckout } from '@webpieces/tooling-common';\nimport { writeTemplate, CliExitError, RepoRootFinder } from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { OpenPrCheck } from '../workflow/open-pr-check';\nimport { RunUpdate } from '../workflow/run-update';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n// wp-start-update: the \"sync this feature branch from main\" entry (the redirect target of the\n// redirect-how-to-merge-main guard). Runs the FULL 3-point squash-update via RunUpdate: a CLEAN merge\n// finalizes everything; CONFLICT writes the 3-point context + merge process doc and hands back. NEVER\n// creates a PR (that is the wp-*-upsert-pr flow).\n@injectable(bindingScopeValues.Singleton)\nexport class StartUpdateCommand {\n constructor(\n private readonly repoRootFinder: RepoRootFinder,\n private readonly openPrCheck: OpenPrCheck,\n private readonly runUpdate: RunUpdate,\n ) {}\n\n async run(): Promise<void> {\n const repoRoot = this.repoRootFinder.resolveRepoRoot(process.cwd());\n // Refresh the AI-facing workflow doc so it's present + current for any failure message to cite.\n writeTemplate(repoRoot, 'webpieces.git-workflow.md');\n\n // An open PR means the PR flow must be used — a 3-point update would strand the PR on the old\n // branch generation. Fails fast if GitHub can't be reached (never guesses \"no PR\").\n this.assertNoOpenPr(repoRoot);\n\n // pushRemote=true: this is the END of the update-only flow — no later command pushes, so not\n // pushing here would silently strand the squash rewrite locally. (The PR flow passes false.)\n const outcome = await this.runUpdate.runUpdateFromMain(repoRoot, 'wp-start-update', 'wp-finish-update', true);\n if (outcome === 'conflict') {\n // Context + marker + merge process doc already written by merge-start; hand back to the AI.\n throw new CliExitError(2, '');\n }\n if (outcome === 'unvalidatedResume') {\n throw new CliExitError(1,\n '\\n' + SEP + '⏸️ Merge in progress — not yet validated\\n' + SEP + '\\n' +\n 'Resolve the remaining conflicts in the working tree, then run:\\n' +\n ' pnpm wp-finish-update\\n',\n );\n }\n process.stdout.write('\\n✅ Updated from main — clean. No need to call `pnpm wp-finish-update`.\\n');\n }\n\n // If a PR is already OPEN for this branch, wp-start-update must refuse. The 3-point update\n // re-squashes your branch onto main and force-pushes it to origin/<feature> — the PR head — but it\n // does NOT refresh the PR body/review or run the authoritative build gate. Fail fast and steer to\n // the PR flow, which re-merges main AND updates the PR.\n assertNoOpenPr(repoRoot: string): void {\n const branch = gitCheckout.requireBranch(repoRoot);\n const openPr = this.openPrCheck.openPrForBranch(repoRoot, branch);\n if (openPr === '') return;\n throw new CliExitError(2,\n '\\n' + SEP + `⛔ An open PR (#${openPr}) already tracks this branch\\n` + SEP + '\\n' +\n 'wp-start-update re-squashes your branch onto main and force-pushes it, but it does NOT refresh\\n' +\n `the PR body/review — so PR #${openPr} would get new code without an updated review. Use the PR\\n` +\n 'flow instead — it re-merges main AND updates the PR:\\n' +\n ' 1. pnpm wp-start-upsert-pr\\n' +\n ' 2. /wp-merge (only if conflicts)\\n' +\n ' 3. pnpm wp-review-upsert-pr (validates the merge, builds, briefs the reviewers)\\n' +\n ' 4. write summary.json at the path wp-review-upsert-pr prints\\n' +\n ' 5. pnpm wp-finish-upsert-pr\\n',\n );\n }\n}\n"]}
1
+ {"version":3,"file":"start-update-command.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/commands/start-update-command.ts"],"names":[],"mappings":";;;;AAAA,8DAAwD;AACxD,0DAAsF;AACtF,yCAA2D;AAC3D,6DAAwD;AACxD,uDAAmD;AAEnD,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAEvE,8FAA8F;AAC9F,sGAAsG;AACtG,sGAAsG;AACtG,kDAAkD;AAE3C,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAEN;IACA;IACA;IAHrB,YACqB,cAA8B,EAC9B,WAAwB,EACxB,SAAoB;QAFpB,mBAAc,GAAd,cAAc,CAAgB;QAC9B,gBAAW,GAAX,WAAW,CAAa;QACxB,cAAS,GAAT,SAAS,CAAW;IACtC,CAAC;IAEJ,KAAK,CAAC,GAAG;QACL,MAAM,QAAQ,GAAG,IAAI,CAAC,cAAc,CAAC,eAAe,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;QACpE,gGAAgG;QAChG,IAAA,4BAAa,EAAC,QAAQ,EAAE,2BAA2B,CAAC,CAAC;QAErD,8FAA8F;QAC9F,oFAAoF;QACpF,MAAM,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;QAEpC,6FAA6F;QAC7F,6FAA6F;QAC7F,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAC,QAAQ,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,IAAI,CAAC,CAAC;QAC9G,IAAI,OAAO,KAAK,UAAU,EAAE,CAAC;YACzB,4FAA4F;YAC5F,MAAM,IAAI,2BAAY,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAClC,CAAC;QACD,IAAI,OAAO,KAAK,mBAAmB,EAAE,CAAC;YAClC,MAAM,IAAI,2BAAY,CAAC,CAAC,EACpB,IAAI,GAAG,GAAG,GAAG,6CAA6C,GAAG,GAAG,GAAG,IAAI;gBACvE,kEAAkE;gBAClE,2BAA2B,CAC9B,CAAC;QACN,CAAC;QACD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,2EAA2E,CAAC,CAAC;IACtG,CAAC;IAED,2FAA2F;IAC3F,mGAAmG;IACnG,kGAAkG;IAClG,wDAAwD;IACxD,KAAK,CAAC,cAAc,CAAC,QAAgB;QACjC,MAAM,MAAM,GAAG,4BAAW,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QACnD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,eAAe,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QACxE,IAAI,MAAM,KAAK,EAAE;YAAE,OAAO;QAC1B,MAAM,IAAI,2BAAY,CAAC,CAAC,EACpB,IAAI,GAAG,GAAG,GAAG,kBAAkB,MAAM,gCAAgC,GAAG,GAAG,GAAG,IAAI;YAClF,kGAAkG;YAClG,+BAA+B,MAAM,6DAA6D;YAClG,wDAAwD;YACxD,gCAAgC;YAChC,wCAAwC;YACxC,uFAAuF;YACvF,kEAAkE;YAClE,iCAAiC,CACpC,CAAC;IACN,CAAC;CACJ,CAAA;AArDY,gDAAkB;6BAAlB,kBAAkB;IAD9B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGA,6BAAc;QACjB,2BAAW;QACb,sBAAS;GAJhC,kBAAkB,CAqD9B","sourcesContent":["import { gitCheckout } from '@webpieces/tooling-common';\nimport { writeTemplate, CliExitError, RepoRootFinder } from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { OpenPrCheck } from '../workflow/open-pr-check';\nimport { RunUpdate } from '../workflow/run-update';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n// wp-start-update: the \"sync this feature branch from main\" entry (the redirect target of the\n// redirect-how-to-merge-main guard). Runs the FULL 3-point squash-update via RunUpdate: a CLEAN merge\n// finalizes everything; CONFLICT writes the 3-point context + merge process doc and hands back. NEVER\n// creates a PR (that is the wp-*-upsert-pr flow).\n@injectable(bindingScopeValues.Singleton)\nexport class StartUpdateCommand {\n constructor(\n private readonly repoRootFinder: RepoRootFinder,\n private readonly openPrCheck: OpenPrCheck,\n private readonly runUpdate: RunUpdate,\n ) {}\n\n async run(): Promise<void> {\n const repoRoot = this.repoRootFinder.resolveRepoRoot(process.cwd());\n // Refresh the AI-facing workflow doc so it's present + current for any failure message to cite.\n writeTemplate(repoRoot, 'webpieces.git-workflow.md');\n\n // An open PR means the PR flow must be used — a 3-point update would strand the PR on the old\n // branch generation. Fails fast if GitHub can't be reached (never guesses \"no PR\").\n await this.assertNoOpenPr(repoRoot);\n\n // pushRemote=true: this is the END of the update-only flow — no later command pushes, so not\n // pushing here would silently strand the squash rewrite locally. (The PR flow passes false.)\n const outcome = await this.runUpdate.runUpdateFromMain(repoRoot, 'wp-start-update', 'wp-finish-update', true);\n if (outcome === 'conflict') {\n // Context + marker + merge process doc already written by merge-start; hand back to the AI.\n throw new CliExitError(2, '');\n }\n if (outcome === 'unvalidatedResume') {\n throw new CliExitError(1,\n '\\n' + SEP + '⏸️ Merge in progress — not yet validated\\n' + SEP + '\\n' +\n 'Resolve the remaining conflicts in the working tree, then run:\\n' +\n ' pnpm wp-finish-update\\n',\n );\n }\n process.stdout.write('\\n✅ Updated from main — clean. No need to call `pnpm wp-finish-update`.\\n');\n }\n\n // If a PR is already OPEN for this branch, wp-start-update must refuse. The 3-point update\n // re-squashes your branch onto main and force-pushes it to origin/<feature> — the PR head — but it\n // does NOT refresh the PR body/review or run the authoritative build gate. Fail fast and steer to\n // the PR flow, which re-merges main AND updates the PR.\n async assertNoOpenPr(repoRoot: string): Promise<void> {\n const branch = gitCheckout.requireBranch(repoRoot);\n const openPr = await this.openPrCheck.openPrForBranch(repoRoot, branch);\n if (openPr === '') return;\n throw new CliExitError(2,\n '\\n' + SEP + `⛔ An open PR (#${openPr}) already tracks this branch\\n` + SEP + '\\n' +\n 'wp-start-update re-squashes your branch onto main and force-pushes it, but it does NOT refresh\\n' +\n `the PR body/review — so PR #${openPr} would get new code without an updated review. Use the PR\\n` +\n 'flow instead — it re-merges main AND updates the PR:\\n' +\n ' 1. pnpm wp-start-upsert-pr\\n' +\n ' 2. /wp-merge (only if conflicts)\\n' +\n ' 3. pnpm wp-review-upsert-pr (validates the merge, builds, briefs the reviewers)\\n' +\n ' 4. write summary.json at the path wp-review-upsert-pr prints\\n' +\n ' 5. pnpm wp-finish-upsert-pr\\n',\n );\n }\n}\n"]}
@@ -55,14 +55,14 @@ let StartUpsertPrCommand = class StartUpsertPrCommand {
55
55
  // Precondition: a fully-committed tree. This flow squash-updates the branch and builds it — the
56
56
  // tooling must not commit your work for you, and building a dirty working tree would let an
57
57
  // uncommitted change build green over a different commit than the one that ships. Fail if dirty.
58
- this.gitExec.assertCleanTree(repoRoot);
58
+ await this.gitExec.assertCleanTree(repoRoot);
59
59
  // Nothing here pushes. This command reviews; wp-finish-upsert-pr pushes ONCE, after summary.json,
60
60
  // every BLOCK checklist, and the authoritative build gate — so no unreviewed commit reaches the
61
61
  // remote, and there is no early `synchronize` firing against a PR body with a stale gate token.
62
62
  await this.updateBranchFromMain(repoRoot);
63
63
  // No build gate here — a conflicted merge may still be unresolved, so there is nothing worth
64
64
  // building. Stage ② finalizes the merge FIRST, then builds; see the class comment.
65
- this.handOffToReview(repoRoot);
65
+ await this.handOffToReview(repoRoot);
66
66
  }
67
67
  /**
68
68
  * Hand the AI its ONE next step: `wp-review-upsert-pr`.
@@ -74,12 +74,12 @@ let StartUpsertPrCommand = class StartUpsertPrCommand {
74
74
  * requested here any more: asking for a written PR summary before the branch is known to compile invites
75
75
  * one that describes code that does not build.
76
76
  */
77
- handOffToReview(repoRoot) {
77
+ async handOffToReview(repoRoot) {
78
78
  // Persist the review-format + process instructions where any failure message can cite them.
79
79
  (0, rules_config_1.writeTemplate)(repoRoot, 'webpieces.review-checklists.md');
80
80
  // Persist the PR diff context (base sha + the full changed-file set) so it exists even if the AI
81
81
  // stops here. Stage ② rewrites it with the materialized-diff dir once it has one.
82
- const context = this.prContextWriter.ensure(repoRoot, this.aiBranchName.getFeatureName(), this.diffBasisResolver.resolve(repoRoot), 'stage1-start');
82
+ const context = await this.prContextWriter.ensure(repoRoot, await this.aiBranchName.getFeatureName(), await this.diffBasisResolver.resolve(repoRoot), 'stage1-start');
83
83
  process.stdout.write('\n' + SEP + '② Brief the reviewers and write the PR summary, then finish\n' + SEP + '\n');
84
84
  process.stdout.write(`Branch is updated (nothing pushed yet — finish does the one push, behind the build gate).\n` +
85
85
  `${this.contextLines(context)}\n` +
@@ -1 +1 @@
1
- {"version":3,"file":"start-upsert-pr-command.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/commands/start-upsert-pr-command.ts"],"names":[],"mappings":";;;;AACA,0DAA8G;AAC9G,yCAA2D;AAC3D,2EAAgE;AAChE,6DAAyD;AACzD,uDAA2D;AAC3D,mDAA+C;AAC/C,qEAAgE;AAChE,uDAAmD;AACnD,iEAA6D;AAE7D,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAEvE,0GAA0G;AAC1G,4DAA4D;AAC5D,EAAE;AACF,4GAA4G;AAC5G,2GAA2G;AAC3G,0GAA0G;AAC1G,0GAA0G;AAC1G,2GAA2G;AAC3G,EAAE;AACF,sGAAsG;AACtG,iEAAiE;AAE1D,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IAER;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IARrB,YACqB,cAA8B,EAC9B,YAA0B,EAC1B,YAA0B,EAC1B,OAAgB,EAChB,SAAoB,EACpB,iBAAoC,EACpC,eAAgC,EAChC,cAA8B;QAP9B,mBAAc,GAAd,cAAc,CAAgB;QAC9B,iBAAY,GAAZ,YAAY,CAAc;QAC1B,iBAAY,GAAZ,YAAY,CAAc;QAC1B,YAAO,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AAO;QACL,sBAAS;QACD,8BAAiB;QACnB,mCAAe;QAChB,gCAAc;GAT1C,oBAAoB,CAoFhC","sourcesContent":["import { execSync } from 'child_process';\nimport { writeTemplate, CliExitError, RepoRootFinder, ChecklistReviewContext } from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { AiBranchName } from '../workflow/git-readAiBranchName';\nimport { BranchNaming } from '../workflow/branch-naming';\nimport { DiffBasisResolver } from '../workflow/diff-basis';\nimport { GitExec } from '../workflow/git-exec';\nimport { PrContextWriter } from '../workflow/pr-context-writer';\nimport { RunUpdate } from '../workflow/run-update';\nimport { HotfixRedirect } from '../workflow/hotfix-redirect';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n// STAGE ① of the AI-first PR flow: the deterministic setup — update from main / drive the 3-point merge —\n// then hand the AI ONE next command, `wp-review-upsert-pr`.\n//\n// It runs NO build gate, and that is still deliberate, but the reason has changed. It is not that the build\n// belongs only at the end: it is that at THIS point a conflicted 3-point merge may still be unresolved, so\n// there is nothing worth building yet. The gate moved FORWARD, not away — stage ② finalizes the merge and\n// then builds, so reviewers never judge a branch that does not compile, and wp-finish-upsert-pr skips the\n// rebuild when HEAD has not moved since. `pr-gate.buildCommand` is therefore no longer a finish-only knob.\n//\n// This command NEVER creates/updates a PR and NEVER pushes: all `gh` posting and the ONE push live in\n// finish, behind summary.json + the checklists + the build gate.\n@injectable(bindingScopeValues.Singleton)\nexport class StartUpsertPrCommand {\n constructor(\n private readonly repoRootFinder: RepoRootFinder,\n private readonly aiBranchName: AiBranchName,\n private readonly branchNaming: BranchNaming,\n private readonly gitExec: GitExec,\n private readonly runUpdate: RunUpdate,\n private readonly diffBasisResolver: DiffBasisResolver,\n private readonly prContextWriter: PrContextWriter,\n private readonly hotfixRedirect: HotfixRedirect,\n ) {}\n\n async run(): Promise<void> {\n // FIRST, before anything is written or merged: a /hotfix/ branch must never take main (issue #1057).\n this.hotfixRedirect.assertNotHotfix('wp-start-upsert-pr');\n const repoRoot = this.repoRootFinder.resolveRepoRoot(process.cwd());\n // Refresh the AI-facing workflow doc so it's present + current for any failure message to cite.\n writeTemplate(repoRoot, 'webpieces.git-workflow.md');\n // NOTE: the server-side CI gate is NOT scaffolded here any more — `wp-install-ai-hooks` owns it.\n // This printed copy-to-.github + branch-protection instructions on EVERY run, at an agent doing\n // feature work that could not act on them: marking a check required needs a repo admin. Setup\n // belongs in the setup command; see templates/webpieces.ci-gate-setup.md.\n\n // Precondition: a fully-committed tree. This flow squash-updates the branch and builds it — the\n // tooling must not commit your work for you, and building a dirty working tree would let an\n // uncommitted change build green over a different commit than the one that ships. Fail if dirty.\n this.gitExec.assertCleanTree(repoRoot);\n\n // Nothing here pushes. This command reviews; wp-finish-upsert-pr pushes ONCE, after summary.json,\n // every BLOCK checklist, and the authoritative build gate — so no unreviewed commit reaches the\n // remote, and there is no early `synchronize` firing against a PR body with a stale gate token.\n await this.updateBranchFromMain(repoRoot);\n\n // No build gate here — a conflicted merge may still be unresolved, so there is nothing worth\n // building. Stage ② finalizes the merge FIRST, then builds; see the class comment.\n this.handOffToReview(repoRoot);\n }\n\n /**\n * Hand the AI its ONE next step: `wp-review-upsert-pr`.\n *\n * This prints exactly one command on purpose. It used to print three (run the checklist, write\n * summary.json, then finish), and a three-item list is a list with a step to skip. Stage ② now owns all\n * of it — it validates the 3-point merge, builds, materializes the diff, briefs the reviewers, AND\n * prints the summary.json schema — so there is nothing here to enumerate. Notably summary.json is NOT\n * requested here any more: asking for a written PR summary before the branch is known to compile invites\n * one that describes code that does not build.\n */\n private handOffToReview(repoRoot: string): void {\n // Persist the review-format + process instructions where any failure message can cite them.\n writeTemplate(repoRoot, 'webpieces.review-checklists.md');\n // Persist the PR diff context (base sha + the full changed-file set) so it exists even if the AI\n // stops here. Stage ② rewrites it with the materialized-diff dir once it has one.\n const context = this.prContextWriter.ensure(repoRoot, this.aiBranchName.getFeatureName(), this.diffBasisResolver.resolve(repoRoot), 'stage1-start');\n process.stdout.write('\\n' + SEP + '② Brief the reviewers and write the PR summary, then finish\\n' + SEP + '\\n');\n process.stdout.write(\n `Branch is updated (nothing pushed yet — finish does the one push, behind the build gate).\\n` +\n `${this.contextLines(context)}\\n` +\n `▶ NEXT run: pnpm wp-review-upsert-pr\\n` +\n ` It validates the 3-point merge, runs the build gate, extracts this branch's diff for the\\n` +\n ` reviewers, and prints what to spawn plus the summary.json schema. Everything else waits on it —\\n` +\n ` wp-finish-upsert-pr refuses to open a PR until it has run.\\n\\n`,\n );\n }\n\n // The diff facts, stated where the instruction to use them is — not in a separate block above it. The\n // command comes from the resolved basis; hand-writing `<base> HEAD` here is empty on a dirty tree.\n private contextLines(context: ChecklistReviewContext): string {\n if (context.baseSha.trim() === '') return '';\n const cmd = context.fileDiffCommand.replace(' -- <file>', '');\n return `${cmd === '' ? '' : `Your diff: ${cmd}\\n`}` + `Full changed-file set + base/head sha: ${context.prContextPath}\\n`;\n }\n\n // Bring the branch up to date with main via the shared 3-point engine (in-process). On conflict the\n // merge process doc it writes names `wp-review-upsert-pr` as the finish command — that is the command\n // that now validates and commits a conflict resolution, so it is what the doc must send the AI to.\n private async updateBranchFromMain(repoRoot: string): Promise<void> {\n process.stdout.write('\\n' + SEP + '① Updating branch from main\\n' + SEP + '\\n');\n // pushRemote=false — finish owns the single push (see MergeEndOptions).\n const outcome = await this.runUpdate.runUpdateFromMain(repoRoot, 'wp-start-upsert-pr', 'wp-review-upsert-pr', false);\n if (outcome === 'conflict' || outcome === 'unvalidatedResume') {\n throw new CliExitError(2, '\\n⏸️ Conflicts — resolve them, then run pnpm wp-review-upsert-pr (it validates the merge, builds it, and only then briefs the reviewers).');\n }\n }\n}\n"]}
1
+ {"version":3,"file":"start-upsert-pr-command.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/commands/start-upsert-pr-command.ts"],"names":[],"mappings":";;;;AAAA,0DAA8G;AAC9G,yC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Aa,IAAI,CAAC;IAChI,CAAC;IAED,oGAAoG;IACpG,sGAAsG;IACtG,mGAAmG;IAC3F,KAAK,CAAC,oBAAoB,CAAC,QAAgB;QAC/C,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,GAAG,GAAG,GAAG,+BAA+B,GAAG,GAAG,GAAG,IAAI,CAAC,CAAC;QAChF,wEAAwE;QACxE,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAC,QAAQ,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,KAAK,CAAC,CAAC;QACrH,IAAI,OAAO,KAAK,UAAU,IAAI,OAAO,KAAK,mBAAmB,EAAE,CAAC;YAC5D,MAAM,IAAI,2BAAY,CAAC,CAAC,EAAE,4IAA4I,CAAC,CAAC;QAC5K,CAAC;IACL,CAAC;CACJ,CAAA;AApFY,oDAAoB;+BAApB,oBAAoB;IADhC,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGA,6BAAc;QAChB,mCAAY;QACZ,4BAAY;QACjB,kBAAO;QACL,sBAAS;QACD,8BAAiB;QACnB,mCAAe;QAChB,gCAAc;GAT1C,oBAAoB,CAoFhC","sourcesContent":["import { writeTemplate, CliExitError, RepoRootFinder, ChecklistReviewContext } from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { AiBranchName } from '../workflow/git-readAiBranchName';\nimport { BranchNaming } from '../workflow/branch-naming';\nimport { DiffBasisResolver } from '../workflow/diff-basis';\nimport { GitExec } from '../workflow/git-exec';\nimport { PrContextWriter } from '../workflow/pr-context-writer';\nimport { RunUpdate } from '../workflow/run-update';\nimport { HotfixRedirect } from '../workflow/hotfix-redirect';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n// STAGE ① of the AI-first PR flow: the deterministic setup — update from main / drive the 3-point merge —\n// then hand the AI ONE next command, `wp-review-upsert-pr`.\n//\n// It runs NO build gate, and that is still deliberate, but the reason has changed. It is not that the build\n// belongs only at the end: it is that at THIS point a conflicted 3-point merge may still be unresolved, so\n// there is nothing worth building yet. The gate moved FORWARD, not away — stage ② finalizes the merge and\n// then builds, so reviewers never judge a branch that does not compile, and wp-finish-upsert-pr skips the\n// rebuild when HEAD has not moved since. `pr-gate.buildCommand` is therefore no longer a finish-only knob.\n//\n// This command NEVER creates/updates a PR and NEVER pushes: all `gh` posting and the ONE push live in\n// finish, behind summary.json + the checklists + the build gate.\n@injectable(bindingScopeValues.Singleton)\nexport class StartUpsertPrCommand {\n constructor(\n private readonly repoRootFinder: RepoRootFinder,\n private readonly aiBranchName: AiBranchName,\n private readonly branchNaming: BranchNaming,\n private readonly gitExec: GitExec,\n private readonly runUpdate: RunUpdate,\n private readonly diffBasisResolver: DiffBasisResolver,\n private readonly prContextWriter: PrContextWriter,\n private readonly hotfixRedirect: HotfixRedirect,\n ) {}\n\n async run(): Promise<void> {\n // FIRST, before anything is written or merged: a /hotfix/ branch must never take main (issue #1057).\n this.hotfixRedirect.assertNotHotfix('wp-start-upsert-pr');\n const repoRoot = this.repoRootFinder.resolveRepoRoot(process.cwd());\n // Refresh the AI-facing workflow doc so it's present + current for any failure message to cite.\n writeTemplate(repoRoot, 'webpieces.git-workflow.md');\n // NOTE: the server-side CI gate is NOT scaffolded here any more — `wp-install-ai-hooks` owns it.\n // This printed copy-to-.github + branch-protection instructions on EVERY run, at an agent doing\n // feature work that could not act on them: marking a check required needs a repo admin. Setup\n // belongs in the setup command; see templates/webpieces.ci-gate-setup.md.\n\n // Precondition: a fully-committed tree. This flow squash-updates the branch and builds it — the\n // tooling must not commit your work for you, and building a dirty working tree would let an\n // uncommitted change build green over a different commit than the one that ships. Fail if dirty.\n await this.gitExec.assertCleanTree(repoRoot);\n\n // Nothing here pushes. This command reviews; wp-finish-upsert-pr pushes ONCE, after summary.json,\n // every BLOCK checklist, and the authoritative build gate — so no unreviewed commit reaches the\n // remote, and there is no early `synchronize` firing against a PR body with a stale gate token.\n await this.updateBranchFromMain(repoRoot);\n\n // No build gate here — a conflicted merge may still be unresolved, so there is nothing worth\n // building. Stage ② finalizes the merge FIRST, then builds; see the class comment.\n await this.handOffToReview(repoRoot);\n }\n\n /**\n * Hand the AI its ONE next step: `wp-review-upsert-pr`.\n *\n * This prints exactly one command on purpose. It used to print three (run the checklist, write\n * summary.json, then finish), and a three-item list is a list with a step to skip. Stage ② now owns all\n * of it — it validates the 3-point merge, builds, materializes the diff, briefs the reviewers, AND\n * prints the summary.json schema — so there is nothing here to enumerate. Notably summary.json is NOT\n * requested here any more: asking for a written PR summary before the branch is known to compile invites\n * one that describes code that does not build.\n */\n private async handOffToReview(repoRoot: string): Promise<void> {\n // Persist the review-format + process instructions where any failure message can cite them.\n writeTemplate(repoRoot, 'webpieces.review-checklists.md');\n // Persist the PR diff context (base sha + the full changed-file set) so it exists even if the AI\n // stops here. Stage ② rewrites it with the materialized-diff dir once it has one.\n const context = await this.prContextWriter.ensure(repoRoot, await this.aiBranchName.getFeatureName(), await this.diffBasisResolver.resolve(repoRoot), 'stage1-start');\n process.stdout.write('\\n' + SEP + '② Brief the reviewers and write the PR summary, then finish\\n' + SEP + '\\n');\n process.stdout.write(\n `Branch is updated (nothing pushed yet — finish does the one push, behind the build gate).\\n` +\n `${this.contextLines(context)}\\n` +\n `▶ NEXT run: pnpm wp-review-upsert-pr\\n` +\n ` It validates the 3-point merge, runs the build gate, extracts this branch's diff for the\\n` +\n ` reviewers, and prints what to spawn plus the summary.json schema. Everything else waits on it —\\n` +\n ` wp-finish-upsert-pr refuses to open a PR until it has run.\\n\\n`,\n );\n }\n\n // The diff facts, stated where the instruction to use them is — not in a separate block above it. The\n // command comes from the resolved basis; hand-writing `<base> HEAD` here is empty on a dirty tree.\n private contextLines(context: ChecklistReviewContext): string {\n if (context.baseSha.trim() === '') return '';\n const cmd = context.fileDiffCommand.replace(' -- <file>', '');\n return `${cmd === '' ? '' : `Your diff: ${cmd}\\n`}` + `Full changed-file set + base/head sha: ${context.prContextPath}\\n`;\n }\n\n // Bring the branch up to date with main via the shared 3-point engine (in-process). On conflict the\n // merge process doc it writes names `wp-review-upsert-pr` as the finish command — that is the command\n // that now validates and commits a conflict resolution, so it is what the doc must send the AI to.\n private async updateBranchFromMain(repoRoot: string): Promise<void> {\n process.stdout.write('\\n' + SEP + '① Updating branch from main\\n' + SEP + '\\n');\n // pushRemote=false — finish owns the single push (see MergeEndOptions).\n const outcome = await this.runUpdate.runUpdateFromMain(repoRoot, 'wp-start-upsert-pr', 'wp-review-upsert-pr', false);\n if (outcome === 'conflict' || outcome === 'unvalidatedResume') {\n throw new CliExitError(2, '\\n⏸️ Conflicts — resolve them, then run pnpm wp-review-upsert-pr (it validates the merge, builds it, and only then briefs the reviewers).');\n }\n }\n}\n"]}
@@ -70,15 +70,15 @@ let SyncMainCommand = class SyncMainCommand {
70
70
  await this.sweepOnly(repoRoot);
71
71
  return;
72
72
  }
73
- const untracked = this.workingTreeGate.assertNoTrackedChanges(repoRoot);
74
- const stashed = this.mainCheckout.goToMain(repoRoot, untracked);
73
+ const untracked = await this.workingTreeGate.assertNoTrackedChanges(repoRoot);
74
+ const stashed = await this.mainCheckout.goToMain(repoRoot, untracked);
75
75
  this.reportUntracked(untracked, stashed);
76
76
  // No flags: this is the "go to main and take out the trash" path, so cleanup behaves exactly as a
77
77
  // bare `pnpm wp-cleanup` does here — reap what is provably dead and every zero-commit husk, ask
78
78
  // (or report) about the rest. Spelled out rather than defaulted so that if CleanupOptions ever
79
79
  // grows a field, this call site is a compile error instead of a silent old behaviour.
80
80
  await this.cleanupCommand.run(new cleanup_options_1.CleanupOptions(new cleanup_options_1.DeleteSelection(cleanup_options_1.FLAG_DELETE_BRANCHES, false, ''), new cleanup_options_1.DeleteSelection(cleanup_options_1.FLAG_DELETE_WORKTREES, false, ''), false, false, false));
81
- this.sweep(repoRoot);
81
+ await this.sweep(repoRoot);
82
82
  this.reportStashed(stashed);
83
83
  }
84
84
  /**
@@ -94,7 +94,7 @@ let SyncMainCommand = class SyncMainCommand {
94
94
  + 'Most worktrees never need this: `wp-cleanup` removes the whole directory once its branch\n'
95
95
  + 'lands, which takes any orphan directories inside it along. Run this command again from the\n'
96
96
  + 'primary clone to go to main there.\n\n');
97
- this.sweep(repoRoot);
97
+ await this.sweep(repoRoot);
98
98
  return Promise.resolve();
99
99
  }
100
100
  isLinkedWorktree(repoRoot) {
@@ -132,8 +132,8 @@ let SyncMainCommand = class SyncMainCommand {
132
132
  * Sweep, then print. Never throws: the checkout and pull above already succeeded, and a tidier is not
133
133
  * permitted to turn somebody's completed sync into a failed command.
134
134
  */
135
- sweep(repoRoot) {
136
- const report = this.orphanDirSweeper.sweep(repoRoot, new Date());
135
+ async sweep(repoRoot) {
136
+ const report = await this.orphanDirSweeper.sweep(repoRoot, new Date());
137
137
  const rendered = report.render();
138
138
  if (rendered === '')
139
139
  return;
@@ -1 +1 @@
1
- {"version":3,"file":"sync-main-command.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/commands/sync-main-command.ts"],"names":[],"mappings":";;;;AAAA,yCAA2D;AAC3D,0DAA2E;AAC3E,8DAAyD;AAEzD,uDAAmD;AACnD,uDAK2B;AAC3B,mDAA6D;AAC7D,2DAAsE;AAEtE,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAEvE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAEI,IAAM,eAAe,GAArB,MAAM,eAAe;IAEH;IACA;IACA;IACA;IACA;IALrB,YACqB,cAA8B,EAC9B,cAA8B,EAC9B,gBAAkC,EAClC,eAAgC,EAChC,YAA0B;QAJ1B,mBAAc,GAAd,cAAc,CAAgB;QAC9B,mBAAc,GAAd,cAAc,CAAgB;QAC9B,qBAAgB,GAAhB,gBAAgB,CAAkB;QAClC,oBAAe,GAAf,eAAe,CAAiB;QAChC,iBAAY,GAAZ,YAAY,CAAc;IAC5C,CAAC;IAE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ANtC,eAAe,CA0F3B","sourcesContent":["import { injectable, bindingScopeValues } from 'inversify';\nimport { OrphanDirSweeper, RepoRootFinder } from '@webpieces/rules-config';\nimport { dotWebpieces } from '@webpieces/tooling-common';\n\nimport { CleanupCommand } from './cleanup-command';\nimport {\n CleanupOptions,\n DeleteSelection,\n FLAG_DELETE_BRANCHES,\n FLAG_DELETE_WORKTREES,\n} from './cleanup-options';\nimport { MainCheckout, StashedFiles } from './main-checkout';\nimport { WorkingTreeGate, UntrackedFiles } from './working-tree-gate';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n/**\n * `wp-sync-main` — go to main, get main, and take out the trash. ONE command, because the three\n * are one intention and splitting them is what let the third never happen.\n *\n * ─── ITS RELATIONSHIP TO `git checkout main && git pull origin main` (READ BEFORE \"DELETING\" THAT) ────\n * That pair was already the enforced spelling: bare `git checkout main` is blocked precisely so the pull\n * rides along. This command is the same pairing with cleanup and the sweep welded on, and the WORKFLOW\n * messages now prescribe this instead — two spellings where one sweeps and one does not is shim shape\n * #1, an agent types whichever is accepted and the corpses accumulate forever.\n *\n * The raw pair is NOT deleted, and the reason is a constraint that outranks the shim rule: it is a\n * TERMINAL ENTRY ON THE L0 ALLOWLIST (`CHECKOUT_MAIN_PULL_CMD` in ai-hook-rules\n * `src/bin/l0-allowlist.ts`, consumed as an L0 cure in `src/core/l0-matrix.ts`) — one of\n * the few commands still permitted while an L0 block denies every other tool call. In exactly that\n * state, `node_modules` is the thing that is untrustworthy, so a `pnpm wp-*` bin is the one kind of cure\n * that cannot be relied on to run. The same reasoning covers the L0 shim's own fix option in\n * `templates/ai-hook.sh` (rendered from `src/bin/shim-drift-fix.ts`).\n *\n * So the end state is TWO LAYERS, not a deletion, and it is now in place:\n * • L0 recovery (l0-allowlist, shim-drift-fix, l0-matrix) → keeps the raw pair. It is not a shim\n * there; it is the only thing that works when the package manager's output is what is in doubt.\n * • the WORKFLOW layer (stale-main-bash-guard's preferred cure, merged-branch-message/-bash-guard,\n * TreeRecovery's cleanupSteps and updateMainSteps, the L2 rows/doc, CLAUDE.md's \"Finishing a\n * Feature\") → prescribes `pnpm wp-sync-main`, and no longer prints the pair.\n *\n * The pair remains ALLOWED as a Bash command in both layers — this changed what the guards TEACH, not\n * what they permit. Blocking it would have deleted the L0 escape along with the shim.\n *\n * ─── WHY GOING TO MAIN IS THE RIGHT MOMENT TO SWEEP ───────────────────────────────────────────────────\n * The corpses appear when git moves the working tree onto a base where the tracked files under some\n * directory are gone. Landing a PR and returning to main is when every developer does that, on every\n * clone, roughly once per merged PR — so a sweep bolted here converges the whole team's machines with no\n * new trigger, no git hook to distribute, and no background daemon. It is also the quietest moment in the\n * day to move directories: nothing is building, no dev server is watching files.\n *\n * ─── WHY THE ORDER IS FIXED AND NOT PARALLEL ──────────────────────────────────────────────────────────\n * Cleanup runs BEFORE the sweep and not beside it. `wp-cleanup` removes dead worktrees, which changes\n * what is on disk, and a scan racing that would be reading a tree mid-demolition. The scan is one\n * ignore-walk and costs about a second; there is no wall-clock worth buying with that race.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class SyncMainCommand {\n constructor(\n private readonly repoRootFinder: RepoRootFinder,\n private readonly cleanupCommand: CleanupCommand,\n private readonly orphanDirSweeper: OrphanDirSweeper,\n private readonly workingTreeGate: WorkingTreeGate,\n private readonly mainCheckout: MainCheckout,\n ) {}\n\n async run(): Promise<void> {\n const repoRoot = this.repoRootFinder.resolveRepoRoot(process.cwd());\n process.stdout.write(`${SEP}🧹 Checkout main, pull, clean\\n${SEP}\\n`);\n if (this.isLinkedWorktree(repoRoot)) {\n await this.sweepOnly(repoRoot);\n return;\n }\n const untracked = this.workingTreeGate.assertNoTrackedChanges(repoRoot);\n const stashed = this.mainCheckout.goToMain(repoRoot, untracked);\n this.reportUntracked(untracked, stashed);\n // No flags: this is the \"go to main and take out the trash\" path, so cleanup behaves exactly as a\n // bare `pnpm wp-cleanup` does here — reap what is provably dead and every zero-commit husk, ask\n // (or report) about the rest. Spelled out rather than defaulted so that if CleanupOptions ever\n // grows a field, this call site is a compile error instead of a silent old behaviour.\n await this.cleanupCommand.run(new CleanupOptions(\n new DeleteSelection(FLAG_DELETE_BRANCHES, false, ''),\n new DeleteSelection(FLAG_DELETE_WORKTREES, false, ''),\n false, false, false));\n this.sweep(repoRoot);\n this.reportStashed(stashed);\n }\n\n /**\n * A linked worktree has no main to check out — `git checkout main` FATALS there with \"main is already\n * checked out at <primary clone>\", which is a footgun `.claude/rules/finishing-a-feature.md`\n * currently has to warn about in prose.\n * So the command does the half that IS meaningful here (worktrees accumulate corpses too, if a\n * long-lived one keeps merging main in) and says plainly where the other half lives.\n */\n private async sweepOnly(repoRoot: string): Promise<void> {\n process.stdout.write(\n 'This is a linked WORKTREE. main is checked out in the primary clone, so there is nothing\\n'\n + 'here to check out or pull — sweeping this tree only.\\n\\n'\n + 'Most worktrees never need this: `wp-cleanup` removes the whole directory once its branch\\n'\n + 'lands, which takes any orphan directories inside it along. Run this command again from the\\n'\n + 'primary clone to go to main there.\\n\\n');\n this.sweep(repoRoot);\n return Promise.resolve();\n }\n\n private isLinkedWorktree(repoRoot: string): boolean {\n const dirs = dotWebpieces.gitDirs(repoRoot);\n return dirs !== null && dirs.isLinkedWorktree;\n }\n\n /**\n * Say which untracked files were let through, AFTER the move — so nobody has to wonder whether the\n * files still sitting in their tree came along for the ride. Printed rather than refused on: see\n * `WorkingTreeGate` for why an untracked file is not the hazard a tracked one is.\n *\n * Silent when the checkout had to stash: those files are NOT sitting in the tree any more, and\n * \"nothing about them changed\" would be a lie. `reportStashed` speaks for that case instead.\n */\n private reportUntracked(untracked: UntrackedFiles, stashed: StashedFiles): void {\n if (!stashed.isEmpty()) return;\n const rendered = untracked.render();\n if (rendered === '') return;\n process.stdout.write(`\\n${rendered}`);\n }\n\n /**\n * The stash banner goes LAST, on purpose. It is the one thing in this command's output a reader\n * must not miss — their files left the working tree — and the cleanup and sweep that follow the\n * checkout print enough to scroll it away if it were emitted where it happened.\n */\n private reportStashed(stashed: StashedFiles): void {\n const rendered = stashed.render();\n if (rendered === '') return;\n process.stdout.write(`\\n${rendered}`);\n }\n\n /**\n * Sweep, then print. Never throws: the checkout and pull above already succeeded, and a tidier is not\n * permitted to turn somebody's completed sync into a failed command.\n */\n private sweep(repoRoot: string): void {\n const report = this.orphanDirSweeper.sweep(repoRoot, new Date());\n const rendered = report.render();\n if (rendered === '') return;\n process.stdout.write(`\\n${rendered}`);\n }\n}\n"]}
1
+ {"version":3,"file":"sync-main-command.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/commands/sync-main-command.ts"],"names":[],"mappings":";;;;AAAA,yCAA2D;AAC3D,0DAA2E;AAC3E,8DAAyD;AAEzD,uDAAmD;AACnD,uDAK2B;AAC3B,mDAA6D;AAC7D,2DAAsE;AAEtE,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAEvE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAEI,IAAM,eAAe,GAArB,MAAM,eAAe;IAEH;IACA;IACA;IACA;IACA;IALrB,YACqB,cAA8B,EAC9B,cAA8B,EAC9B,gBAAkC,EAClC,eAAgC,EAChC,YAA0B;QAJ1B,mBAAc,GAAd,cAAc,CAAgB;QAC9B,mBAAc,GAAd,cAAc,CAAgB;QAC9B,qBAAgB,GAAhB,gBAAgB,CAAkB;QAClC,oBAAe,GAAf,eAAe,CAAiB;QAChC,iBAAY,GAAZ,YAAY,CAAc;IAC5C,CAAC;IAEJ,KAAK,CAAC,GAAG;QACL,MAAM,QAAQ,GAAG,IAAI,CAAC,cAAc,CAAC,eAAe,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;QACpE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,GAAG,kCAAkC,GAAG,IAAI,CAAC,CAAC;QACtE,IAAI,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,EAA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OG;IACK,eAAe,CAAC,SAAyB,EAAE,OAAqB;QACpE,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE;YAAE,OAAO;QAC/B,MAAM,QAAQ,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC;QACpC,IAAI,QAAQ,KAAK,EAAE;YAAE,OAAO;QAC5B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,QAAQ,EAAE,CAAC,CAAC;IAC1C,CAAC;IAED;;;;OAIG;IACK,aAAa,CAAC,OAAqB;QACvC,MAAM,QAAQ,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;QAClC,IAAI,QAAQ,KAAK,EAAE;YAAE,OAAO;QAC5B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,QAAQ,EAAE,CAAC,CAAC;IAC1C,CAAC;IAED;;;OAGG;IACK,KAAK,CAAC,KAAK,CAAC,QAAgB;QAChC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,IAAI,EAAE,CAAC,CAAC;QACvE,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC;QACjC,IAAI,QAAQ,KAAK,EAAE;YAAE,OAAO;QAC5B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,QAAQ,EAAE,CAAC,CAAC;IAC1C,CAAC;CACJ,CAAA;AA1FY,0CAAe;0BAAf,eAAe;IAD3B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGA,6BAAc;QACd,gCAAc;QACZ,+BAAgB;QACjB,mCAAe;QAClB,4BAAY;GANtC,eAAe,CA0F3B","sourcesContent":["import { injectable, bindingScopeValues } from 'inversify';\nimport { OrphanDirSweeper, RepoRootFinder } from '@webpieces/rules-config';\nimport { dotWebpieces } from '@webpieces/tooling-common';\n\nimport { CleanupCommand } from './cleanup-command';\nimport {\n CleanupOptions,\n DeleteSelection,\n FLAG_DELETE_BRANCHES,\n FLAG_DELETE_WORKTREES,\n} from './cleanup-options';\nimport { MainCheckout, StashedFiles } from './main-checkout';\nimport { WorkingTreeGate, UntrackedFiles } from './working-tree-gate';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n/**\n * `wp-sync-main` — go to main, get main, and take out the trash. ONE command, because the three\n * are one intention and splitting them is what let the third never happen.\n *\n * ─── ITS RELATIONSHIP TO `git checkout main && git pull origin main` (READ BEFORE \"DELETING\" THAT) ────\n * That pair was already the enforced spelling: bare `git checkout main` is blocked precisely so the pull\n * rides along. This command is the same pairing with cleanup and the sweep welded on, and the WORKFLOW\n * messages now prescribe this instead — two spellings where one sweeps and one does not is shim shape\n * #1, an agent types whichever is accepted and the corpses accumulate forever.\n *\n * The raw pair is NOT deleted, and the reason is a constraint that outranks the shim rule: it is a\n * TERMINAL ENTRY ON THE L0 ALLOWLIST (`CHECKOUT_MAIN_PULL_CMD` in ai-hook-rules\n * `src/bin/l0-allowlist.ts`, consumed as an L0 cure in `src/core/l0-matrix.ts`) — one of\n * the few commands still permitted while an L0 block denies every other tool call. In exactly that\n * state, `node_modules` is the thing that is untrustworthy, so a `pnpm wp-*` bin is the one kind of cure\n * that cannot be relied on to run. The same reasoning covers the L0 shim's own fix option in\n * `templates/ai-hook.sh` (rendered from `src/bin/shim-drift-fix.ts`).\n *\n * So the end state is TWO LAYERS, not a deletion, and it is now in place:\n * • L0 recovery (l0-allowlist, shim-drift-fix, l0-matrix) → keeps the raw pair. It is not a shim\n * there; it is the only thing that works when the package manager's output is what is in doubt.\n * • the WORKFLOW layer (stale-main-bash-guard's preferred cure, merged-branch-message/-bash-guard,\n * TreeRecovery's cleanupSteps and updateMainSteps, the L2 rows/doc, CLAUDE.md's \"Finishing a\n * Feature\") → prescribes `pnpm wp-sync-main`, and no longer prints the pair.\n *\n * The pair remains ALLOWED as a Bash command in both layers — this changed what the guards TEACH, not\n * what they permit. Blocking it would have deleted the L0 escape along with the shim.\n *\n * ─── WHY GOING TO MAIN IS THE RIGHT MOMENT TO SWEEP ───────────────────────────────────────────────────\n * The corpses appear when git moves the working tree onto a base where the tracked files under some\n * directory are gone. Landing a PR and returning to main is when every developer does that, on every\n * clone, roughly once per merged PR — so a sweep bolted here converges the whole team's machines with no\n * new trigger, no git hook to distribute, and no background daemon. It is also the quietest moment in the\n * day to move directories: nothing is building, no dev server is watching files.\n *\n * ─── WHY THE ORDER IS FIXED AND NOT PARALLEL ──────────────────────────────────────────────────────────\n * Cleanup runs BEFORE the sweep and not beside it. `wp-cleanup` removes dead worktrees, which changes\n * what is on disk, and a scan racing that would be reading a tree mid-demolition. The scan is one\n * ignore-walk and costs about a second; there is no wall-clock worth buying with that race.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class SyncMainCommand {\n constructor(\n private readonly repoRootFinder: RepoRootFinder,\n private readonly cleanupCommand: CleanupCommand,\n private readonly orphanDirSweeper: OrphanDirSweeper,\n private readonly workingTreeGate: WorkingTreeGate,\n private readonly mainCheckout: MainCheckout,\n ) {}\n\n async run(): Promise<void> {\n const repoRoot = this.repoRootFinder.resolveRepoRoot(process.cwd());\n process.stdout.write(`${SEP}🧹 Checkout main, pull, clean\\n${SEP}\\n`);\n if (this.isLinkedWorktree(repoRoot)) {\n await this.sweepOnly(repoRoot);\n return;\n }\n const untracked = await this.workingTreeGate.assertNoTrackedChanges(repoRoot);\n const stashed = await this.mainCheckout.goToMain(repoRoot, untracked);\n this.reportUntracked(untracked, stashed);\n // No flags: this is the \"go to main and take out the trash\" path, so cleanup behaves exactly as a\n // bare `pnpm wp-cleanup` does here — reap what is provably dead and every zero-commit husk, ask\n // (or report) about the rest. Spelled out rather than defaulted so that if CleanupOptions ever\n // grows a field, this call site is a compile error instead of a silent old behaviour.\n await this.cleanupCommand.run(new CleanupOptions(\n new DeleteSelection(FLAG_DELETE_BRANCHES, false, ''),\n new DeleteSelection(FLAG_DELETE_WORKTREES, false, ''),\n false, false, false));\n await this.sweep(repoRoot);\n this.reportStashed(stashed);\n }\n\n /**\n * A linked worktree has no main to check out — `git checkout main` FATALS there with \"main is already\n * checked out at <primary clone>\", which is a footgun `.claude/rules/finishing-a-feature.md`\n * currently has to warn about in prose.\n * So the command does the half that IS meaningful here (worktrees accumulate corpses too, if a\n * long-lived one keeps merging main in) and says plainly where the other half lives.\n */\n private async sweepOnly(repoRoot: string): Promise<void> {\n process.stdout.write(\n 'This is a linked WORKTREE. main is checked out in the primary clone, so there is nothing\\n'\n + 'here to check out or pull — sweeping this tree only.\\n\\n'\n + 'Most worktrees never need this: `wp-cleanup` removes the whole directory once its branch\\n'\n + 'lands, which takes any orphan directories inside it along. Run this command again from the\\n'\n + 'primary clone to go to main there.\\n\\n');\n await this.sweep(repoRoot);\n return Promise.resolve();\n }\n\n private isLinkedWorktree(repoRoot: string): boolean {\n const dirs = dotWebpieces.gitDirs(repoRoot);\n return dirs !== null && dirs.isLinkedWorktree;\n }\n\n /**\n * Say which untracked files were let through, AFTER the move — so nobody has to wonder whether the\n * files still sitting in their tree came along for the ride. Printed rather than refused on: see\n * `WorkingTreeGate` for why an untracked file is not the hazard a tracked one is.\n *\n * Silent when the checkout had to stash: those files are NOT sitting in the tree any more, and\n * \"nothing about them changed\" would be a lie. `reportStashed` speaks for that case instead.\n */\n private reportUntracked(untracked: UntrackedFiles, stashed: StashedFiles): void {\n if (!stashed.isEmpty()) return;\n const rendered = untracked.render();\n if (rendered === '') return;\n process.stdout.write(`\\n${rendered}`);\n }\n\n /**\n * The stash banner goes LAST, on purpose. It is the one thing in this command's output a reader\n * must not miss — their files left the working tree — and the cleanup and sweep that follow the\n * checkout print enough to scroll it away if it were emitted where it happened.\n */\n private reportStashed(stashed: StashedFiles): void {\n const rendered = stashed.render();\n if (rendered === '') return;\n process.stdout.write(`\\n${rendered}`);\n }\n\n /**\n * Sweep, then print. Never throws: the checkout and pull above already succeeded, and a tidier is not\n * permitted to turn somebody's completed sync into a failed command.\n */\n private async sweep(repoRoot: string): Promise<void> {\n const report = await this.orphanDirSweeper.sweep(repoRoot, new Date());\n const rendered = report.render();\n if (rendered === '') return;\n process.stdout.write(`\\n${rendered}`);\n }\n}\n"]}
@@ -1,5 +1,6 @@
1
1
  import { BranchIdentity } from '@webpieces/repo-workflow-core';
2
2
  import { GateTokenService, PrGateConfig, RepoRootFinder, ReviewJsonService } from '@webpieces/rules-config';
3
+ import { NativeProcessApi } from '@webpieces/tooling-common';
3
4
  import { AiBranchName } from '../workflow/git-readAiBranchName';
4
5
  import { GitExec } from '../workflow/git-exec';
5
6
  import { BuildAffected } from '../workflow/build-affected';
@@ -53,7 +54,8 @@ export declare class UpsertHotfixPrCommand {
53
54
  private readonly commentUpserter;
54
55
  private readonly squashSettings;
55
56
  private readonly gateTokenService;
56
- constructor(repoRootFinder: RepoRootFinder, branchIdentity: BranchIdentity, aiBranchName: AiBranchName, gitExec: GitExec, reviewJsonService: ReviewJsonService, buildAffected: BuildAffected, buildArtifactGate: BuildArtifactGate, mergeState: MergeState, checklistScanner: ChecklistScanner, publisher: HotfixPrPublisher, dashboard: Dashboard, authorIdentity: AuthorIdentityResolver, checklistComment: ChecklistCommentRenderer, commentUpserter: PrCommentUpserter, squashSettings: SquashSettingsEnforcer, gateTokenService: GateTokenService);
57
+ private readonly processes;
58
+ constructor(repoRootFinder: RepoRootFinder, branchIdentity: BranchIdentity, aiBranchName: AiBranchName, gitExec: GitExec, reviewJsonService: ReviewJsonService, buildAffected: BuildAffected, buildArtifactGate: BuildArtifactGate, mergeState: MergeState, checklistScanner: ChecklistScanner, publisher: HotfixPrPublisher, dashboard: Dashboard, authorIdentity: AuthorIdentityResolver, checklistComment: ChecklistCommentRenderer, commentUpserter: PrCommentUpserter, squashSettings: SquashSettingsEnforcer, gateTokenService: GateTokenService, processes: NativeProcessApi);
57
59
  run(): Promise<void>;
58
60
  private assertHotfixBranch;
59
61
  private assertNoUnvalidatedMerge;
@@ -68,7 +70,7 @@ export declare class UpsertHotfixPrCommand {
68
70
  private headSha;
69
71
  private git;
70
72
  protected prGateConfig(repoRoot: string): PrGateConfig;
71
- protected fetchMain(repoRoot: string): void;
72
- protected prRef(branch: string): HotfixPrRef;
73
- protected editPrBody(prNumber: string, bodyFile: string): boolean;
73
+ private fetchMain;
74
+ private prRef;
75
+ private editPrBody;
74
76
  }