@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.
- package/package.json +6 -6
- package/src/scripts/commands/await-checks-command.d.ts +6 -3
- package/src/scripts/commands/await-checks-command.js +17 -12
- package/src/scripts/commands/await-checks-command.js.map +1 -1
- package/src/scripts/commands/await-reviews-command.d.ts +1 -1
- package/src/scripts/commands/await-reviews-command.js +3 -3
- package/src/scripts/commands/await-reviews-command.js.map +1 -1
- package/src/scripts/commands/check-pr-command.d.ts +3 -1
- package/src/scripts/commands/check-pr-command.js +12 -9
- package/src/scripts/commands/check-pr-command.js.map +1 -1
- package/src/scripts/commands/cleanup-command.js +12 -12
- package/src/scripts/commands/cleanup-command.js.map +1 -1
- package/src/scripts/commands/finish-push-dev-command.js +3 -4
- package/src/scripts/commands/finish-push-dev-command.js.map +1 -1
- package/src/scripts/commands/finish-update-command.js +1 -1
- package/src/scripts/commands/finish-update-command.js.map +1 -1
- package/src/scripts/commands/finish-upsert-pr-command.d.ts +4 -1
- package/src/scripts/commands/finish-upsert-pr-command.js +65 -62
- package/src/scripts/commands/finish-upsert-pr-command.js.map +1 -1
- package/src/scripts/commands/human-post-pr-command.d.ts +8 -6
- package/src/scripts/commands/human-post-pr-command.js +33 -32
- package/src/scripts/commands/human-post-pr-command.js.map +1 -1
- package/src/scripts/commands/land-pr-command.d.ts +5 -1
- package/src/scripts/commands/land-pr-command.js +37 -23
- package/src/scripts/commands/land-pr-command.js.map +1 -1
- package/src/scripts/commands/main-checkout.d.ts +4 -1
- package/src/scripts/commands/main-checkout.js +22 -22
- package/src/scripts/commands/main-checkout.js.map +1 -1
- package/src/scripts/commands/push-dev-command.js +28 -29
- package/src/scripts/commands/push-dev-command.js.map +1 -1
- package/src/scripts/commands/reap-worktree-command.js +4 -5
- package/src/scripts/commands/reap-worktree-command.js.map +1 -1
- package/src/scripts/commands/review-upsert-pr-command.js +10 -10
- package/src/scripts/commands/review-upsert-pr-command.js.map +1 -1
- package/src/scripts/commands/start-update-command.d.ts +1 -1
- package/src/scripts/commands/start-update-command.js +3 -3
- package/src/scripts/commands/start-update-command.js.map +1 -1
- package/src/scripts/commands/start-upsert-pr-command.js +4 -4
- package/src/scripts/commands/start-upsert-pr-command.js.map +1 -1
- package/src/scripts/commands/sync-main-command.js +6 -6
- package/src/scripts/commands/sync-main-command.js.map +1 -1
- package/src/scripts/commands/upsert-hotfix-pr-command.d.ts +6 -4
- package/src/scripts/commands/upsert-hotfix-pr-command.js +46 -43
- package/src/scripts/commands/upsert-hotfix-pr-command.js.map +1 -1
- package/src/scripts/commands/working-tree-gate.d.ts +4 -1
- package/src/scripts/commands/working-tree-gate.js +14 -11
- package/src/scripts/commands/working-tree-gate.js.map +1 -1
- package/src/scripts/commands/worktree-cleanup.d.ts +4 -4
- package/src/scripts/commands/worktree-cleanup.js +4 -4
- package/src/scripts/commands/worktree-cleanup.js.map +1 -1
- package/src/scripts/commands/write-review-command.js +4 -6
- package/src/scripts/commands/write-review-command.js.map +1 -1
- package/src/scripts/commands/write-review-fixes-command.js +3 -4
- package/src/scripts/commands/write-review-fixes-command.js.map +1 -1
- package/src/scripts/git-finishUpsertPr.js +2 -2
- package/src/scripts/git-finishUpsertPr.js.map +1 -1
- package/src/scripts/git-gatherInfo.js +6 -7
- package/src/scripts/git-gatherInfo.js.map +1 -1
- package/src/scripts/pr-gate-container.d.ts +9 -0
- package/src/scripts/pr-gate-container.js +19 -0
- package/src/scripts/pr-gate-container.js.map +1 -0
- package/src/scripts/workflow/await-loop.d.ts +1 -1
- package/src/scripts/workflow/await-loop.js +1 -1
- package/src/scripts/workflow/await-loop.js.map +1 -1
- package/src/scripts/workflow/build-affected.js +1 -1
- package/src/scripts/workflow/build-affected.js.map +1 -1
- package/src/scripts/workflow/build-artifact-gate.d.ts +1 -1
- package/src/scripts/workflow/build-artifact-gate.js +3 -3
- package/src/scripts/workflow/build-artifact-gate.js.map +1 -1
- package/src/scripts/workflow/build-gate-log.d.ts +9 -6
- package/src/scripts/workflow/build-gate-log.js +34 -40
- package/src/scripts/workflow/build-gate-log.js.map +1 -1
- package/src/scripts/workflow/checklist-detector.d.ts +2 -2
- package/src/scripts/workflow/checklist-detector.js +4 -4
- package/src/scripts/workflow/checklist-detector.js.map +1 -1
- package/src/scripts/workflow/checklist-scanner.d.ts +1 -1
- package/src/scripts/workflow/checklist-scanner.js +11 -11
- package/src/scripts/workflow/checklist-scanner.js.map +1 -1
- package/src/scripts/workflow/checklist-scope-hasher.d.ts +1 -1
- package/src/scripts/workflow/checklist-scope-hasher.js +2 -2
- package/src/scripts/workflow/checklist-scope-hasher.js.map +1 -1
- package/src/scripts/workflow/dev-deploy-refs.d.ts +5 -5
- package/src/scripts/workflow/dev-deploy-refs.js +8 -8
- package/src/scripts/workflow/dev-deploy-refs.js.map +1 -1
- package/src/scripts/workflow/dev-resolve-runner.d.ts +3 -3
- package/src/scripts/workflow/dev-resolve-runner.js +30 -30
- package/src/scripts/workflow/dev-resolve-runner.js.map +1 -1
- package/src/scripts/workflow/diff-basis.d.ts +4 -2
- package/src/scripts/workflow/diff-basis.js +18 -15
- package/src/scripts/workflow/diff-basis.js.map +1 -1
- package/src/scripts/workflow/diff-materializer.d.ts +5 -3
- package/src/scripts/workflow/diff-materializer.js +18 -15
- package/src/scripts/workflow/diff-materializer.js.map +1 -1
- package/src/scripts/workflow/gated-pr-publisher.d.ts +8 -6
- package/src/scripts/workflow/gated-pr-publisher.js +23 -22
- package/src/scripts/workflow/gated-pr-publisher.js.map +1 -1
- package/src/scripts/workflow/generated-artifact-registry.d.ts +4 -2
- package/src/scripts/workflow/generated-artifact-registry.js +11 -8
- package/src/scripts/workflow/generated-artifact-registry.js.map +1 -1
- package/src/scripts/workflow/git-exec.d.ts +22 -12
- package/src/scripts/workflow/git-exec.js +45 -29
- package/src/scripts/workflow/git-exec.js.map +1 -1
- package/src/scripts/workflow/git-findForkPoint.d.ts +6 -2
- package/src/scripts/workflow/git-findForkPoint.js +31 -23
- package/src/scripts/workflow/git-findForkPoint.js.map +1 -1
- package/src/scripts/workflow/git-readAiBranchName.d.ts +4 -2
- package/src/scripts/workflow/git-readAiBranchName.js +8 -5
- package/src/scripts/workflow/git-readAiBranchName.js.map +1 -1
- package/src/scripts/workflow/hotfix-pr-publisher.d.ts +4 -3
- package/src/scripts/workflow/hotfix-pr-publisher.js +7 -6
- package/src/scripts/workflow/hotfix-pr-publisher.js.map +1 -1
- package/src/scripts/workflow/landed-tree-resolver.d.ts +4 -2
- package/src/scripts/workflow/landed-tree-resolver.js +11 -8
- package/src/scripts/workflow/landed-tree-resolver.js.map +1 -1
- package/src/scripts/workflow/landed-worktree-reaper.d.ts +4 -2
- package/src/scripts/workflow/landed-worktree-reaper.js +12 -9
- package/src/scripts/workflow/landed-worktree-reaper.js.map +1 -1
- package/src/scripts/workflow/merge-end.d.ts +5 -4
- package/src/scripts/workflow/merge-end.js +28 -27
- package/src/scripts/workflow/merge-end.js.map +1 -1
- package/src/scripts/workflow/merge-start.d.ts +5 -1
- package/src/scripts/workflow/merge-start.js +56 -49
- package/src/scripts/workflow/merge-start.js.map +1 -1
- package/src/scripts/workflow/open-pr-check.d.ts +4 -2
- package/src/scripts/workflow/open-pr-check.js +11 -8
- package/src/scripts/workflow/open-pr-check.js.map +1 -1
- package/src/scripts/workflow/pr-comment-upserter.d.ts +5 -3
- package/src/scripts/workflow/pr-comment-upserter.js +15 -14
- package/src/scripts/workflow/pr-comment-upserter.js.map +1 -1
- package/src/scripts/workflow/pr-context-writer.d.ts +1 -1
- package/src/scripts/workflow/pr-context-writer.js +3 -3
- package/src/scripts/workflow/pr-context-writer.js.map +1 -1
- package/src/scripts/workflow/pr-merger.d.ts +8 -5
- package/src/scripts/workflow/pr-merger.js +32 -27
- package/src/scripts/workflow/pr-merger.js.map +1 -1
- package/src/scripts/workflow/provenance-enforcer.d.ts +4 -2
- package/src/scripts/workflow/provenance-enforcer.js +19 -17
- package/src/scripts/workflow/provenance-enforcer.js.map +1 -1
- package/src/scripts/workflow/review-round-state.d.ts +7 -6
- package/src/scripts/workflow/review-round-state.js +33 -38
- package/src/scripts/workflow/review-round-state.js.map +1 -1
- package/src/scripts/workflow/run-update.js +1 -1
- package/src/scripts/workflow/run-update.js.map +1 -1
- package/src/scripts/workflow/squash-settings-enforcer.d.ts +6 -3
- package/src/scripts/workflow/squash-settings-enforcer.js +19 -14
- package/src/scripts/workflow/squash-settings-enforcer.js.map +1 -1
- package/src/scripts/wp-await-checks.js +2 -2
- package/src/scripts/wp-await-checks.js.map +1 -1
- package/src/scripts/wp-await-reviews.js +2 -2
- package/src/scripts/wp-await-reviews.js.map +1 -1
- package/src/scripts/wp-build.js +2 -2
- package/src/scripts/wp-build.js.map +1 -1
- package/src/scripts/wp-check-pr.js +2 -2
- package/src/scripts/wp-check-pr.js.map +1 -1
- package/src/scripts/wp-cleanup.js +2 -2
- package/src/scripts/wp-cleanup.js.map +1 -1
- package/src/scripts/wp-finish-push-dev.js +2 -2
- package/src/scripts/wp-finish-push-dev.js.map +1 -1
- package/src/scripts/wp-finish-update.js +2 -2
- package/src/scripts/wp-finish-update.js.map +1 -1
- package/src/scripts/wp-human-post-pr.js +2 -2
- package/src/scripts/wp-human-post-pr.js.map +1 -1
- package/src/scripts/wp-land-pr.js +2 -2
- package/src/scripts/wp-land-pr.js.map +1 -1
- package/src/scripts/wp-push-dev.js +2 -2
- package/src/scripts/wp-push-dev.js.map +1 -1
- package/src/scripts/wp-reap-worktree.js +2 -2
- package/src/scripts/wp-reap-worktree.js.map +1 -1
- package/src/scripts/wp-review-upsert-pr.js +2 -2
- package/src/scripts/wp-review-upsert-pr.js.map +1 -1
- package/src/scripts/wp-start-update.js +2 -2
- package/src/scripts/wp-start-update.js.map +1 -1
- package/src/scripts/wp-start-upsert-pr.js +2 -2
- package/src/scripts/wp-start-upsert-pr.js.map +1 -1
- package/src/scripts/wp-sync-main.js +2 -2
- package/src/scripts/wp-sync-main.js.map +1 -1
- package/src/scripts/wp-upsert-hotfix-pr.js +2 -2
- package/src/scripts/wp-upsert-hotfix-pr.js.map +1 -1
- package/src/scripts/wp-write-review-fixes.js +2 -2
- package/src/scripts/wp-write-review-fixes.js.map +1 -1
- package/src/scripts/wp-write-review.js +2 -2
- package/src/scripts/wp-write-review.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"human-post-pr-command.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/commands/human-post-pr-command.ts"],"names":[],"mappings":";;;;AAAA,iDAA0C;AAC1C,+CAAyB;AACzB,mDAA6B;AAC7B,2DAAqC;AACrC,sEAAsG;AACtG,0DAAwI;AACxI,yCAA2D;AAC3D,2EAAgE;AAChE,6DAAyD;AACzD,uEAAkE;AAClE,mDAA+C;AAC/C,yDAAqD;AACrD,mFAA8E;AAC9E,mDAA6D;AAC7D,uEAAmE;AAEnE,MAAM,aAAa,GAAG,uBAAuB,CAAC;AAE9C,kFAAkF;AAClF,MAAa,aAAa;IACtB,MAAM,CAAS;IACf,GAAG,CAAS;IAEZ,YAAY,MAAc,EAAE,GAAW;QACnC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACnB,CAAC;CACJ;AARD,sCAQC;AAED;;;;;;GAMG;AAEI,IAAM,kBAAkB,GAAxB,MAAM,kBAAkB;IAEN;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IAZrB,YACqB,cAA8B,EAC9B,cAA8B,EAC9B,YAA0B,EAC1B,YAA0B,EAC1B,OAAgB,EAChB,UAAsB,EACtB,iBAAoC,EACpC,cAAqC,EACrC,gBAAkC,EAClC,SAA2B,EAC3B,cAAsC,EACtC,YAA0B;QAX1B,mBAAc,GAAd,cAAc,CAAgB;QAC9B,mBAAc,GAAd,cAAc,CAAgB;QAC9B,iBAAY,GAAZ,YAAY,CAAc;QAC1B,iBAA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\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport * as readline from 'readline';\nimport { BranchIdentity, MainSyncStatus, MainSyncStatusService } from '@webpieces/repo-workflow-core';\nimport { CliExitError, GateTokenService, PrSummary, RepoRootFinder, ReviewJsonService, loadAndValidate } from '@webpieces/rules-config';\nimport { bindingScopeValues, injectable } from 'inversify';\nimport { AiBranchName } from '../workflow/git-readAiBranchName';\nimport { BranchNaming } from '../workflow/branch-naming';\nimport { GatedPrPublisher } from '../workflow/gated-pr-publisher';\nimport { GitExec } from '../workflow/git-exec';\nimport { MergeState } from '../workflow/merge-state';\nimport { SquashSettingsEnforcer } from '../workflow/squash-settings-enforcer';\nimport { BuildCommand, BuildOptions } from './build-command';\nimport { IssueReferences } from '../../dashboard/issue-references';\n\nconst RETRY_COMMAND = 'pnpm wp-human-post-pr';\n\n/** The PR identity returned by GitHub after posting. Data-only, per CLAUDE.md. */\nexport class HumanPostedPr {\n number: string;\n url: string;\n\n constructor(number: string, url: string) {\n this.number = number;\n this.url = url;\n }\n}\n\n/**\n * Interactive, human-attested PR escape hatch.\n *\n * The first answer is an attestation, not identity detection: a process cannot prove who typed it. The\n * fail-closed ordering is the security property here — every answer except the literal normalized\n * `human` returns before repository discovery, git, GitHub, or any write.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class HumanPostPrCommand {\n constructor(\n private readonly repoRootFinder: RepoRootFinder,\n private readonly branchIdentity: BranchIdentity,\n private readonly branchNaming: BranchNaming,\n private readonly aiBranchName: AiBranchName,\n private readonly gitExec: GitExec,\n private readonly mergeState: MergeState,\n private readonly reviewJsonService: ReviewJsonService,\n private readonly mainSyncStatus: MainSyncStatusService,\n private readonly gateTokenService: GateTokenService,\n private readonly publisher: GatedPrPublisher,\n private readonly squashSettings: SquashSettingsEnforcer,\n private readonly buildCommand: BuildCommand,\n ) {}\n\n async run(): Promise<void> {\n const answer = (await this.question('Are you human or AI (human/AI)?\\n'))\n .trim()\n .toLowerCase();\n if (answer !== 'human') {\n throw new CliExitError(\n 1,\n 'wp-human-post-pr requires an explicit human attestation. Nothing was changed.',\n );\n }\n\n const repoRoot = this.repoRootFinder.resolveRepoRoot(process.cwd());\n const currentBranch = this.branchIdentity.current();\n if (currentBranch === '' || currentBranch === 'HEAD') {\n throw new CliExitError(\n 1,\n 'wp-human-post-pr requires a checked-out feature branch; detached HEAD is not publishable.',\n );\n }\n if (currentBranch === 'main') {\n throw new CliExitError(\n 1,\n 'wp-human-post-pr refuses main. Check out a clean feature branch and rerun it.',\n );\n }\n const baseBranch = this.branchNaming.baseBranchName(currentBranch);\n this.gitExec.assertCleanTree(repoRoot);\n this.assertNoUnvalidatedMerge(repoRoot);\n this.fetchMain(repoRoot);\n\n const forkPoint = this.git(\n ['merge-base', 'origin/main', 'HEAD'],\n repoRoot,\n 'Could not resolve the pure-main fork point against freshly fetched origin/main.',\n );\n const summaryPath = this.reviewJsonService.summaryJsonPath(\n repoRoot,\n this.aiBranchName.getFeatureName(),\n );\n await this.ensureSummary(summaryPath, forkPoint);\n const summary = this.reviewJsonService.loadSummaryJson(summaryPath, [], '', {}, RETRY_COMMAND);\n // FAIL FAST on a hand-written closing reference (issue #1310), before the human is asked to build.\n new IssueReferences().assertNoStrayClosingReferences(summary.summary, summary.addressesIssues, RETRY_COMMAND);\n\n const status = this.mainSyncStatus.computeMainSyncStatus(repoRoot);\n this.assertCurrentMain(status);\n const buildRan = await this.askToBuild();\n if (buildRan) this.gitExec.assertCleanTree(repoRoot);\n\n this.post(repoRoot, baseBranch, summaryPath, summary, buildRan);\n }\n\n /** The safe body-before-push publication shared with the automated flow via GatedPrPublisher. */\n private post(\n repoRoot: string,\n baseBranch: string,\n summaryPath: string,\n summary: PrSummary,\n buildRan: boolean,\n ): void {\n const headSha = this.git(\n ['rev-parse', 'HEAD'],\n repoRoot,\n 'Could not resolve feature HEAD.',\n );\n const gateSalt = this.gateSalt(repoRoot);\n const initialRef = this.resolvePr(baseBranch);\n const initialBody = this.renderBody(summary, initialRef.url, gateSalt, headSha, buildRan);\n for (const warning of new IssueReferences().closeWarnings(summary.addressesIssues)) process.stdout.write(`${warning}\\n`);\n const bodyFile = path.join(\n this.reviewJsonService.prDirFor(repoRoot, this.aiBranchName.getFeatureName()),\n 'pr-body.md',\n );\n fs.mkdirSync(path.dirname(bodyFile), { recursive: true });\n fs.writeFileSync(bodyFile, initialBody + '\\n');\n\n const published = this.publisher.publish(\n baseBranch,\n this.titleFrom(summary, baseBranch),\n bodyFile,\n RETRY_COMMAND,\n );\n if (published.createFailed) {\n throw new CliExitError(\n 1,\n `gh pr create failed. The validated body remains at ${bodyFile}; summary.json was not consumed.`,\n );\n }\n\n const finalRef = this.resolvePr(baseBranch);\n if (finalRef.number === '') {\n throw new CliExitError(\n 1,\n 'The branch was pushed but GitHub did not return its open PR; summary.json was not consumed.',\n );\n }\n const finalBody = this.renderBody(summary, finalRef.url, gateSalt, headSha, buildRan);\n if (finalBody !== initialBody) this.backfillBody(finalRef.number, bodyFile, finalBody);\n this.squashSettings.ensure();\n const archive = this.reviewJsonService.archiveSummaryJson(summaryPath);\n if (archive !== '')\n process.stdout.write(`Archived this run's summary.json → ${archive} (audit only) ✓\\n`);\n process.stdout.write(\n `✅ Human-attested PR posted (${buildRan ? 'local wp-build passed; automated review skipped' : 'local build/review skipped'}): ${finalRef.url}\\n`,\n );\n }\n\n private async askToBuild(): Promise<boolean> {\n const answer = (\n await this.question('Run ' + 'wp-build here (If no, CI will run it in the cloud) Y/N?\\n')\n )\n .trim()\n .toLowerCase();\n if (answer === 'n' || answer === 'no') return false;\n if (answer !== 'y' && answer !== 'yes') {\n throw new CliExitError(1, 'Please answer Y or N. No PR was pushed or edited.');\n }\n await this.buildCommand.runStreaming(new BuildOptions(false));\n return true;\n }\n\n private assertNoUnvalidatedMerge(repoRoot: string): void {\n const home = this.mergeState.mergeDirFor(repoRoot, this.aiBranchName.getFeatureName());\n const active = this.mergeState.findActiveMergeRunDir(home);\n const marker = active === null ? null : this.mergeState.readMergeMarker(active);\n if (marker === null || marker.validated) return;\n throw new CliExitError(\n 1,\n 'wp-human-post-pr refuses an active, unvalidated 3-point merge. Resolve it and run the supported ' +\n 'Webpieces finish/update flow before posting.',\n );\n }\n\n protected fetchMain(repoRoot: string): void {\n this.gitExec.runGitChecked(\n ['fetch', 'origin', 'main'],\n 'Could not refresh origin/main; wp-human-post-pr will not evaluate or publish against a stale ref',\n );\n }\n\n protected gateSalt(repoRoot: string): string {\n return loadAndValidate(repoRoot).prGate.gateSalt;\n }\n\n private async ensureSummary(summaryPath: string, forkPoint: string): Promise<void> {\n if (fs.existsSync(summaryPath)) return;\n process.stdout.write(\n '\\nCopy/paste the following instruction into AI:\\n\\n' +\n `Write ONLY ${summaryPath}.\\n` +\n 'Do not run pnpm wp-review-upsert-pr, pnpm wp-finish-upsert-pr, push, or create/update a PR.\\n' +\n `Summarize exactly: git diff ${forkPoint} HEAD\\n` +\n `Changed files: git diff --name-only ${forkPoint} HEAD\\n\\n` +\n this.reviewJsonService.summaryJsonSchemaHint(summaryPath) +\n '\\n\\n',\n );\n const answer = (\n await this.question(\n \"I don't see summary.json and we at least need that to short circuit pushing.\\n\" +\n 'Please paste the instructions above into AI. When it is done generating summary.json, continue? (Y/N)\\n',\n )\n )\n .trim()\n .toLowerCase();\n if (answer !== 'y' && answer !== 'yes') {\n throw new CliExitError(\n 1,\n 'No PR was pushed or edited. Rerun pnpm wp-human-post-pr when summary.json is ready.',\n );\n }\n }\n\n private assertCurrentMain(status: MainSyncStatus): void {\n if (!status.hasForkPoint || status.forkPoint === null) {\n throw new CliExitError(\n 1,\n 'Could not establish a pure-main fork point. Use the Webpieces update process; do not merge or rebase manually.',\n );\n }\n if (status.forkPoint === status.originMain) return;\n const conflicts =\n status.conflictFiles.length === 0\n ? 'Conflicts: (none predicted)'\n : 'Conflicts (files changed on both sides; conservative prediction):\\n' +\n status.conflictFiles.map((file: string): string => ` - ${file}`).join('\\n');\n const update =\n status.openPr === ''\n ? ' pnpm wp-start-update\\n # if conflicts are reported, resolve them, then:\\n pnpm wp-finish-update'\n : ' pnpm wp-start-upsert-pr\\n pnpm wp-review-upsert-pr\\n pnpm wp-finish-upsert-pr';\n throw new CliExitError(\n 1,\n 'Your branch is behind origin/main.\\n\\n' +\n 'Ask AI to run the Webpieces update process, then rerun pnpm wp-human-post-pr.\\n' +\n 'This is usually very quick unless you have conflicts.\\n\\n' +\n update +\n '\\n\\n' +\n conflicts,\n );\n }\n\n private renderBody(\n summary: PrSummary,\n prUrl: string,\n gateSalt: string,\n headSha: string,\n buildRan: boolean,\n ): string {\n const lines: string[] = [];\n if (prUrl !== '') lines.push(prUrl, '');\n lines.push(`Risk: ${summary.riskScore}/100 ${summary.riskEmoji} (${summary.riskLevel})`);\n lines.push(`Summary authored by ${summary.agent} (${summary.model})`);\n lines.push('');\n lines.push(\n buildRan\n ? 'Flags: ⚠️ HUMAN ESCAPE HATCH — local wp-build passed; automated reviewer stages were explicitly skipped.'\n : 'Flags: ⚠️ HUMAN ESCAPE HATCH — local build and automated reviewer stages were explicitly skipped; cloud CI will run.',\n );\n const issues = new IssueReferences();\n const text = issues.withoutBlockLines(summary.summary.trim(), summary.addressesIssues);\n if (text !== '') lines.push('', text);\n // The same `Fixes <url>` / `Part of <url>` block wp-finish-upsert-pr renders (issue #1310).\n const ticketLines = issues.blockLines(summary.addressesIssues);\n if (ticketLines.length > 0) lines.push('', ...ticketLines);\n lines.push(\n '',\n `Generated by webpieces-ts wp-human-post-pr (human-attested; ${buildRan ? 'local wp-build passed, automated review skipped' : 'local build/review skipped'})`,\n );\n const marker = this.gateTokenService.gateTokenMarker(gateSalt, headSha);\n if (marker !== '') lines.push('', marker);\n const body = lines.join('\\n').replace(/\\|/g, '\\u00a6').replace(/#{2,}/g, '#');\n issues.assertNoStrayClosingReferences(body, summary.addressesIssues, RETRY_COMMAND);\n return body;\n }\n\n private titleFrom(summary: PrSummary, branch: string): string {\n return summary.title === '' ? branch.replace(/[-/]+/g, ' ').trim() : summary.title;\n }\n\n protected resolvePr(branch: string): HumanPostedPr {\n const result = spawnSync(\n 'gh',\n ['pr', 'view', branch, '--json', 'number,url', '--jq', '\"\\\\(.number)\\\\t\\\\(.url)\"'],\n { encoding: 'utf8' },\n );\n if (result.status !== 0) return new HumanPostedPr('', '');\n const parts = (result.stdout ?? '').trim().split('\\t');\n return new HumanPostedPr(parts[0] ?? '', parts[1] ?? '');\n }\n\n protected backfillBody(prNumber: string, bodyFile: string, body: string): void {\n fs.writeFileSync(bodyFile, body + '\\n');\n if (this.editPrBody(prNumber, bodyFile) !== 0) {\n throw new CliExitError(\n 1,\n `Could not update PR #${prNumber} with its final human-bypass body. The validated body remains at ${bodyFile}. ` +\n `Fix GitHub access, then re-run ${RETRY_COMMAND}; summary.json was not consumed.`,\n );\n }\n }\n\n protected editPrBody(prNumber: string, bodyFile: string): number | null {\n return spawnSync('gh', ['pr', 'edit', prNumber, '--body-file', bodyFile], {\n stdio: 'inherit',\n }).status;\n }\n\n protected git(args: string[], cwd: string, failure: string): string {\n return this.gitExec.gitQuery(args, cwd, failure);\n }\n\n // Seam: overridden in specs. EOF resolves to '' and therefore fails closed.\n protected question(prompt: string): Promise<string> {\n const rl = readline.createInterface({ input: process.stdin, output: process.stdout });\n return new Promise<string>((resolve: (value: string) => void): void => {\n let answered = false;\n rl.question(prompt, (answer: string): void => {\n answered = true;\n rl.close();\n resolve(answer);\n });\n rl.on('close', (): void => {\n if (!answered) resolve('');\n });\n });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"human-post-pr-command.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/commands/human-post-pr-command.ts"],"names":[],"mappings":";;;;AAAA,+CAAyB;AACzB,mDAA6B;AAC7B,2DAAqC;AACrC,sEAAsG;AACtG,0DAAwI;AACxI,8DAA6D;AAC7D,yCAA2D;AAC3D,2EAAgE;AAChE,6DAAyD;AACzD,uEAAkE;AAClE,mDAA+C;AAC/C,yDAAqD;AACrD,mFAA8E;AAC9E,mDAA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AK,EAAE,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;QACtF,OAAO,IAAI,OAAO,CAAS,CAAC,OAAgC,EAAQ,EAAE;YAClE,IAAI,QAAQ,GAAG,KAAK,CAAC;YACrB,EAAE,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,MAAc,EAAQ,EAAE;gBACzC,QAAQ,GAAG,IAAI,CAAC;gBAChB,EAAE,CAAC,KAAK,EAAE,CAAC;gBACX,OAAO,CAAC,MAAM,CAAC,CAAC;YACpB,CAAC,CAAC,CAAC;YACH,EAAE,CAAC,EAAE,CAAC,OAAO,EAAE,GAAS,EAAE;gBACtB,IAAI,CAAC,QAAQ;oBAAE,OAAO,CAAC,EAAE,CAAC,CAAC;YAC/B,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC;CACJ,CAAA;AA1SY,gDAAkB;6BAAlB,kBAAkB;IAD9B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGA,6BAAc;QACd,mCAAc;QAChB,4BAAY;QACZ,mCAAY;QACjB,kBAAO;QACJ,wBAAU;QACH,gCAAiB;QACpB,0CAAqB;QACnB,+BAAgB;QACvB,qCAAgB;QACX,iDAAsB;QACxB,4BAAY;QACf,iCAAgB;GAdvC,kBAAkB,CA0S9B","sourcesContent":["import * as fs from 'fs';\nimport * as path from 'path';\nimport * as readline from 'readline';\nimport { BranchIdentity, MainSyncStatus, MainSyncStatusService } from '@webpieces/repo-workflow-core';\nimport { CliExitError, GateTokenService, PrSummary, RepoRootFinder, ReviewJsonService, loadAndValidate } from '@webpieces/rules-config';\nimport { NativeProcessApi } from '@webpieces/tooling-common';\nimport { bindingScopeValues, injectable } from 'inversify';\nimport { AiBranchName } from '../workflow/git-readAiBranchName';\nimport { BranchNaming } from '../workflow/branch-naming';\nimport { GatedPrPublisher } from '../workflow/gated-pr-publisher';\nimport { GitExec } from '../workflow/git-exec';\nimport { MergeState } from '../workflow/merge-state';\nimport { SquashSettingsEnforcer } from '../workflow/squash-settings-enforcer';\nimport { BuildCommand, BuildOptions } from './build-command';\nimport { IssueReferences } from '../../dashboard/issue-references';\n\nconst RETRY_COMMAND = 'pnpm wp-human-post-pr';\n\n/** The PR identity returned by GitHub after posting. Data-only, per CLAUDE.md. */\nexport class HumanPostedPr {\n number: string;\n url: string;\n\n constructor(number: string, url: string) {\n this.number = number;\n this.url = url;\n }\n}\n\n/**\n * Interactive, human-attested PR escape hatch.\n *\n * The first answer is an attestation, not identity detection: a process cannot prove who typed it. The\n * fail-closed ordering is the security property here — every answer except the literal normalized\n * `human` returns before repository discovery, git, GitHub, or any write.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class HumanPostPrCommand {\n constructor(\n private readonly repoRootFinder: RepoRootFinder,\n private readonly branchIdentity: BranchIdentity,\n private readonly branchNaming: BranchNaming,\n private readonly aiBranchName: AiBranchName,\n private readonly gitExec: GitExec,\n private readonly mergeState: MergeState,\n private readonly reviewJsonService: ReviewJsonService,\n private readonly mainSyncStatus: MainSyncStatusService,\n private readonly gateTokenService: GateTokenService,\n private readonly publisher: GatedPrPublisher,\n private readonly squashSettings: SquashSettingsEnforcer,\n private readonly buildCommand: BuildCommand,\n private readonly processes: NativeProcessApi,\n ) {}\n\n async run(): Promise<void> {\n const answer = (await this.question('Are you human or AI (human/AI)?\\n'))\n .trim()\n .toLowerCase();\n if (answer !== 'human') {\n throw new CliExitError(\n 1,\n 'wp-human-post-pr requires an explicit human attestation. Nothing was changed.',\n );\n }\n\n const repoRoot = this.repoRootFinder.resolveRepoRoot(process.cwd());\n const currentBranch = this.branchIdentity.current();\n if (currentBranch === '' || currentBranch === 'HEAD') {\n throw new CliExitError(\n 1,\n 'wp-human-post-pr requires a checked-out feature branch; detached HEAD is not publishable.',\n );\n }\n if (currentBranch === 'main') {\n throw new CliExitError(\n 1,\n 'wp-human-post-pr refuses main. Check out a clean feature branch and rerun it.',\n );\n }\n const baseBranch = this.branchNaming.baseBranchName(currentBranch);\n await this.gitExec.assertCleanTree(repoRoot);\n await this.assertNoUnvalidatedMerge(repoRoot);\n await this.fetchMain(repoRoot);\n\n const forkPoint = await this.git(\n ['merge-base', 'origin/main', 'HEAD'],\n repoRoot,\n 'Could not resolve the pure-main fork point against freshly fetched origin/main.',\n );\n const summaryPath = this.reviewJsonService.summaryJsonPath(\n repoRoot,\n await this.aiBranchName.getFeatureName(),\n );\n await this.ensureSummary(summaryPath, forkPoint);\n const summary = this.reviewJsonService.loadSummaryJson(summaryPath, [], '', {}, RETRY_COMMAND);\n // FAIL FAST on a hand-written closing reference (issue #1310), before the human is asked to build.\n new IssueReferences().assertNoStrayClosingReferences(summary.summary, summary.addressesIssues, RETRY_COMMAND);\n\n const status = await this.mainSyncStatus.computeMainSyncStatus(repoRoot);\n this.assertCurrentMain(status);\n const buildRan = await this.askToBuild();\n if (buildRan) await this.gitExec.assertCleanTree(repoRoot);\n\n await this.post(repoRoot, baseBranch, summaryPath, summary, buildRan);\n }\n\n /** The safe body-before-push publication shared with the automated flow via GatedPrPublisher. */\n private async post(\n repoRoot: string,\n baseBranch: string,\n summaryPath: string,\n summary: PrSummary,\n buildRan: boolean,\n ): Promise<void> {\n const headSha = await this.git(\n ['rev-parse', 'HEAD'],\n repoRoot,\n 'Could not resolve feature HEAD.',\n );\n const gateSalt = this.gateSalt(repoRoot);\n const initialRef = await this.resolvePr(baseBranch);\n const initialBody = this.renderBody(summary, initialRef.url, gateSalt, headSha, buildRan);\n for (const warning of new IssueReferences().closeWarnings(summary.addressesIssues)) process.stdout.write(`${warning}\\n`);\n const bodyFile = path.join(\n this.reviewJsonService.prDirFor(repoRoot, await this.aiBranchName.getFeatureName()),\n 'pr-body.md',\n );\n fs.mkdirSync(path.dirname(bodyFile), { recursive: true });\n fs.writeFileSync(bodyFile, initialBody + '\\n');\n\n const published = await this.publisher.publish(\n baseBranch,\n this.titleFrom(summary, baseBranch),\n bodyFile,\n RETRY_COMMAND,\n );\n if (published.createFailed) {\n throw new CliExitError(\n 1,\n `gh pr create failed. The validated body remains at ${bodyFile}; summary.json was not consumed.`,\n );\n }\n\n const finalRef = await this.resolvePr(baseBranch);\n if (finalRef.number === '') {\n throw new CliExitError(\n 1,\n 'The branch was pushed but GitHub did not return its open PR; summary.json was not consumed.',\n );\n }\n const finalBody = this.renderBody(summary, finalRef.url, gateSalt, headSha, buildRan);\n if (finalBody !== initialBody) await this.backfillBody(finalRef.number, bodyFile, finalBody);\n await this.squashSettings.ensure();\n const archive = this.reviewJsonService.archiveSummaryJson(summaryPath);\n if (archive !== '')\n process.stdout.write(`Archived this run's summary.json → ${archive} (audit only) ✓\\n`);\n process.stdout.write(\n `✅ Human-attested PR posted (${buildRan ? 'local wp-build passed; automated review skipped' : 'local build/review skipped'}): ${finalRef.url}\\n`,\n );\n }\n\n private async askToBuild(): Promise<boolean> {\n const answer = (\n await this.question('Run ' + 'wp-build here (If no, CI will run it in the cloud) Y/N?\\n')\n )\n .trim()\n .toLowerCase();\n if (answer === 'n' || answer === 'no') return false;\n if (answer !== 'y' && answer !== 'yes') {\n throw new CliExitError(1, 'Please answer Y or N. No PR was pushed or edited.');\n }\n await this.buildCommand.runStreaming(new BuildOptions(false));\n return true;\n }\n\n private async assertNoUnvalidatedMerge(repoRoot: string): Promise<void> {\n const home = this.mergeState.mergeDirFor(repoRoot, await this.aiBranchName.getFeatureName());\n const active = this.mergeState.findActiveMergeRunDir(home);\n const marker = active === null ? null : this.mergeState.readMergeMarker(active);\n if (marker === null || marker.validated) return;\n throw new CliExitError(\n 1,\n 'wp-human-post-pr refuses an active, unvalidated 3-point merge. Resolve it and run the supported ' +\n 'Webpieces finish/update flow before posting.',\n );\n }\n\n protected fetchMain(repoRoot: string): Promise<void> {\n return this.gitExec.runGitChecked(\n ['fetch', 'origin', 'main'],\n 'Could not refresh origin/main; wp-human-post-pr will not evaluate or publish against a stale ref',\n );\n }\n\n protected gateSalt(repoRoot: string): string {\n return loadAndValidate(repoRoot).prGate.gateSalt;\n }\n\n private async ensureSummary(summaryPath: string, forkPoint: string): Promise<void> {\n if (fs.existsSync(summaryPath)) return;\n process.stdout.write(\n '\\nCopy/paste the following instruction into AI:\\n\\n' +\n `Write ONLY ${summaryPath}.\\n` +\n 'Do not run pnpm wp-review-upsert-pr, pnpm wp-finish-upsert-pr, push, or create/update a PR.\\n' +\n `Summarize exactly: git diff ${forkPoint} HEAD\\n` +\n `Changed files: git diff --name-only ${forkPoint} HEAD\\n\\n` +\n this.reviewJsonService.summaryJsonSchemaHint(summaryPath) +\n '\\n\\n',\n );\n const answer = (\n await this.question(\n \"I don't see summary.json and we at least need that to short circuit pushing.\\n\" +\n 'Please paste the instructions above into AI. When it is done generating summary.json, continue? (Y/N)\\n',\n )\n )\n .trim()\n .toLowerCase();\n if (answer !== 'y' && answer !== 'yes') {\n throw new CliExitError(\n 1,\n 'No PR was pushed or edited. Rerun pnpm wp-human-post-pr when summary.json is ready.',\n );\n }\n }\n\n private assertCurrentMain(status: MainSyncStatus): void {\n if (!status.hasForkPoint || status.forkPoint === null) {\n throw new CliExitError(\n 1,\n 'Could not establish a pure-main fork point. Use the Webpieces update process; do not merge or rebase manually.',\n );\n }\n if (status.forkPoint === status.originMain) return;\n const conflicts =\n status.conflictFiles.length === 0\n ? 'Conflicts: (none predicted)'\n : 'Conflicts (files changed on both sides; conservative prediction):\\n' +\n status.conflictFiles.map((file: string): string => ` - ${file}`).join('\\n');\n const update =\n status.openPr === ''\n ? ' pnpm wp-start-update\\n # if conflicts are reported, resolve them, then:\\n pnpm wp-finish-update'\n : ' pnpm wp-start-upsert-pr\\n pnpm wp-review-upsert-pr\\n pnpm wp-finish-upsert-pr';\n throw new CliExitError(\n 1,\n 'Your branch is behind origin/main.\\n\\n' +\n 'Ask AI to run the Webpieces update process, then rerun pnpm wp-human-post-pr.\\n' +\n 'This is usually very quick unless you have conflicts.\\n\\n' +\n update +\n '\\n\\n' +\n conflicts,\n );\n }\n\n private renderBody(\n summary: PrSummary,\n prUrl: string,\n gateSalt: string,\n headSha: string,\n buildRan: boolean,\n ): string {\n const lines: string[] = [];\n if (prUrl !== '') lines.push(prUrl, '');\n lines.push(`Risk: ${summary.riskScore}/100 ${summary.riskEmoji} (${summary.riskLevel})`);\n lines.push(`Summary authored by ${summary.agent} (${summary.model})`);\n lines.push('');\n lines.push(\n buildRan\n ? 'Flags: ⚠️ HUMAN ESCAPE HATCH — local wp-build passed; automated reviewer stages were explicitly skipped.'\n : 'Flags: ⚠️ HUMAN ESCAPE HATCH — local build and automated reviewer stages were explicitly skipped; cloud CI will run.',\n );\n const issues = new IssueReferences();\n const text = issues.withoutBlockLines(summary.summary.trim(), summary.addressesIssues);\n if (text !== '') lines.push('', text);\n // The same `Fixes <url>` / `Part of <url>` block wp-finish-upsert-pr renders (issue #1310).\n const ticketLines = issues.blockLines(summary.addressesIssues);\n if (ticketLines.length > 0) lines.push('', ...ticketLines);\n lines.push(\n '',\n `Generated by webpieces-ts wp-human-post-pr (human-attested; ${buildRan ? 'local wp-build passed, automated review skipped' : 'local build/review skipped'})`,\n );\n const marker = this.gateTokenService.gateTokenMarker(gateSalt, headSha);\n if (marker !== '') lines.push('', marker);\n const body = lines.join('\\n').replace(/\\|/g, '\\u00a6').replace(/#{2,}/g, '#');\n issues.assertNoStrayClosingReferences(body, summary.addressesIssues, RETRY_COMMAND);\n return body;\n }\n\n private titleFrom(summary: PrSummary, branch: string): string {\n return summary.title === '' ? branch.replace(/[-/]+/g, ' ').trim() : summary.title;\n }\n\n protected async resolvePr(branch: string): Promise<HumanPostedPr> {\n const result = await this.processes.run(\n 'gh',\n ['pr', 'view', branch, '--json', 'number,url', '--jq', '\"\\\\(.number)\\\\t\\\\(.url)\"'],\n );\n if (!result.ok) return new HumanPostedPr('', '');\n const parts = result.stdout.trim().split('\\t');\n return new HumanPostedPr(parts[0] ?? '', parts[1] ?? '');\n }\n\n protected async backfillBody(prNumber: string, bodyFile: string, body: string): Promise<void> {\n fs.writeFileSync(bodyFile, body + '\\n');\n if (await this.editPrBody(prNumber, bodyFile) !== 0) {\n throw new CliExitError(\n 1,\n `Could not update PR #${prNumber} with its final human-bypass body. The validated body remains at ${bodyFile}. ` +\n `Fix GitHub access, then re-run ${RETRY_COMMAND}; summary.json was not consumed.`,\n );\n }\n }\n\n protected async editPrBody(prNumber: string, bodyFile: string): Promise<number> {\n return (await this.processes.passThrough('gh', ['pr', 'edit', prNumber, '--body-file', bodyFile])).code;\n }\n\n protected git(args: string[], cwd: string, failure: string): Promise<string> {\n return this.gitExec.gitQuery(args, cwd, failure);\n }\n\n // Seam: overridden in specs. EOF resolves to '' and therefore fails closed.\n protected question(prompt: string): Promise<string> {\n const rl = readline.createInterface({ input: process.stdin, output: process.stdout });\n return new Promise<string>((resolve: (value: string) => void): void => {\n let answered = false;\n rl.question(prompt, (answer: string): void => {\n answered = true;\n rl.close();\n resolve(answer);\n });\n rl.on('close', (): void => {\n if (!answered) resolve('');\n });\n });\n }\n}\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { GitProcessApi, NativeProcessApi } from '@webpieces/tooling-common';
|
|
1
2
|
import { RepoRootFinder } from '@webpieces/rules-config';
|
|
2
3
|
import { BranchArchiver } from '@webpieces/repo-workflow-core';
|
|
3
4
|
import { AiBranchName } from '../workflow/git-readAiBranchName';
|
|
@@ -67,7 +68,9 @@ export declare class LandPrCommand {
|
|
|
67
68
|
private readonly landedWorktree;
|
|
68
69
|
private readonly bodyFile;
|
|
69
70
|
private readonly landedTree;
|
|
70
|
-
|
|
71
|
+
private readonly git;
|
|
72
|
+
private readonly processes;
|
|
73
|
+
constructor(repoRootFinder: RepoRootFinder, aiBranchName: AiBranchName, branchNaming: BranchNaming, prMerger: PrMerger, archiver: BranchArchiver, mergeInfoIndex: MergeInfoIndex, landedWorktree: LandedWorktreeReaper, bodyFile: MergeBodyTempFile, landedTree: LandedTreeResolver, git: GitProcessApi, processes: NativeProcessApi);
|
|
71
74
|
/**
|
|
72
75
|
* THE INVOCATION DIRECTORY, which is not `process.cwd()`.
|
|
73
76
|
*
|
|
@@ -199,6 +202,7 @@ export declare class LandPrCommand {
|
|
|
199
202
|
*/
|
|
200
203
|
private archiveAndPromote;
|
|
201
204
|
private revParse;
|
|
205
|
+
private currentBranch;
|
|
202
206
|
/**
|
|
203
207
|
* Everything landing needs about the PR, in ONE `gh` read: number, title, URL, DESCRIPTION and the
|
|
204
208
|
* head sha GitHub is squashing. `null` when there is no open PR for this head branch.
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.LandPrRequest = exports.LandPrCommand = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const child_process_1 = require("child_process");
|
|
6
5
|
const tooling_common_1 = require("@webpieces/tooling-common");
|
|
7
6
|
const to_error_1 = require("@webpieces/tooling-common/to-error");
|
|
8
7
|
const rules_config_1 = require("@webpieces/rules-config");
|
|
@@ -76,8 +75,10 @@ let LandPrCommand = class LandPrCommand {
|
|
|
76
75
|
landedWorktree;
|
|
77
76
|
bodyFile;
|
|
78
77
|
landedTree;
|
|
78
|
+
git;
|
|
79
|
+
processes;
|
|
79
80
|
// eslint-disable-next-line @typescript-eslint/max-params
|
|
80
|
-
constructor(repoRootFinder, aiBranchName, branchNaming, prMerger, archiver, mergeInfoIndex, landedWorktree, bodyFile, landedTree) {
|
|
81
|
+
constructor(repoRootFinder, aiBranchName, branchNaming, prMerger, archiver, mergeInfoIndex, landedWorktree, bodyFile, landedTree, git, processes) {
|
|
81
82
|
this.repoRootFinder = repoRootFinder;
|
|
82
83
|
this.aiBranchName = aiBranchName;
|
|
83
84
|
this.branchNaming = branchNaming;
|
|
@@ -87,6 +88,8 @@ let LandPrCommand = class LandPrCommand {
|
|
|
87
88
|
this.landedWorktree = landedWorktree;
|
|
88
89
|
this.bodyFile = bodyFile;
|
|
89
90
|
this.landedTree = landedTree;
|
|
91
|
+
this.git = git;
|
|
92
|
+
this.processes = processes;
|
|
90
93
|
}
|
|
91
94
|
/**
|
|
92
95
|
* THE INVOCATION DIRECTORY, which is not `process.cwd()`.
|
|
@@ -110,8 +113,8 @@ let LandPrCommand = class LandPrCommand {
|
|
|
110
113
|
// operator is really standing in.
|
|
111
114
|
const selector = request.prNumber !== ''
|
|
112
115
|
? request.prNumber
|
|
113
|
-
: this.branchNaming.baseBranchName(
|
|
114
|
-
const ref = this.readPr(selector);
|
|
116
|
+
: this.branchNaming.baseBranchName(await this.currentBranch(cwd));
|
|
117
|
+
const ref = await this.readPr(selector);
|
|
115
118
|
if (ref === null)
|
|
116
119
|
throw this.noSuchPr(request, selector);
|
|
117
120
|
// The PR's OWN head branch, never the selector: with `--pr <n>` the operator named a number and
|
|
@@ -135,9 +138,9 @@ let LandPrCommand = class LandPrCommand {
|
|
|
135
138
|
// travels alongside it rather than being replaced by a literal AUTO, so PrMerger's diagnostics
|
|
136
139
|
// never assert a config value nobody set — that is exactly what used to print a CONFIG MISMATCH
|
|
137
140
|
// about `mergeMode: AUTO` two lines above this command printing `mergeMode is NONE`.
|
|
138
|
-
const outcome = this.prMerger.merge(base, `${ref.title} (#${ref.number})`, mergeBodyFile, new pr_merger_1.MergeIntent(policy ?? '', true));
|
|
141
|
+
const outcome = await this.prMerger.merge(base, `${ref.title} (#${ref.number})`, mergeBodyFile, new pr_merger_1.MergeIntent(policy ?? '', true));
|
|
139
142
|
const bookkeeping = outcome.merged
|
|
140
|
-
? this.bookkeeping(repoRoot, base, ref, config.landPr.branchRetention, cwd)
|
|
143
|
+
? await this.bookkeeping(repoRoot, base, ref, config.landPr.branchRetention, cwd)
|
|
141
144
|
: '';
|
|
142
145
|
process.stdout.write('\n' + SEP + (outcome.merged ? '✅ Landed\n' : 'ℹ️ Not landed yet\n') + SEP + '\n' +
|
|
143
146
|
` ${outcome.message}\n` +
|
|
@@ -284,12 +287,12 @@ let LandPrCommand = class LandPrCommand {
|
|
|
284
287
|
* it is more precise in both directions — a second clone sitting on the SAME commit can safely
|
|
285
288
|
* archive it, and a tree that has committed further work since finish ran correctly declines.
|
|
286
289
|
*/
|
|
287
|
-
bookkeeping(repoRoot, base, ref, retention, cwd) {
|
|
288
|
-
const tree = this.landedTree.resolve(repoRoot, base, ref.headRefOid);
|
|
290
|
+
async bookkeeping(repoRoot, base, ref, retention, cwd) {
|
|
291
|
+
const tree = await this.landedTree.resolve(repoRoot, base, ref.headRefOid);
|
|
289
292
|
if (!tree.bookkeepingAllowed)
|
|
290
293
|
return this.notTheLandedTipNotice(base, tree, ref);
|
|
291
|
-
return this.archiveAndPromote(repoRoot, base, ref, retention)
|
|
292
|
-
+ this.nextStep(repoRoot, tree, cwd);
|
|
294
|
+
return await this.archiveAndPromote(repoRoot, base, ref, retention)
|
|
295
|
+
+ await this.nextStep(repoRoot, tree, cwd);
|
|
293
296
|
}
|
|
294
297
|
/**
|
|
295
298
|
* What was skipped, why, and what the two SHAs are — so the reader can tell WHICH cause it was.
|
|
@@ -326,7 +329,7 @@ let LandPrCommand = class LandPrCommand {
|
|
|
326
329
|
* hand-off is not safely achievable the #512 notice is printed unchanged, because an honest
|
|
327
330
|
* limitation beats a command that deletes its own working directory mid-run.
|
|
328
331
|
*/
|
|
329
|
-
nextStep(repoRoot, tree, cwd) {
|
|
332
|
+
async nextStep(repoRoot, tree, cwd) {
|
|
330
333
|
const handoff = this.landedWorktree.plan(repoRoot, tree.worktree, cwd);
|
|
331
334
|
if (handoff === null)
|
|
332
335
|
return ' Next: `pnpm wp-cleanup` to delete the merged branch.\n';
|
|
@@ -346,29 +349,38 @@ let LandPrCommand = class LandPrCommand {
|
|
|
346
349
|
* Never throws: the PR is already merged by the time we get here, and failing the command after a
|
|
347
350
|
* successful merge would report a landed PR as a failure. Problems are reported in the recap.
|
|
348
351
|
*/
|
|
349
|
-
archiveAndPromote(repoRoot, base, ref, retention) {
|
|
352
|
+
async archiveAndPromote(repoRoot, base, ref, retention) {
|
|
350
353
|
if (retention === repo_workflow_core_1.BRANCH_RETENTION_KEEP)
|
|
351
354
|
return ' Branch retention is "keep" — nothing archived.\n';
|
|
352
355
|
let line = '';
|
|
353
356
|
let tag = '';
|
|
354
357
|
if (retention === repo_workflow_core_1.BRANCH_RETENTION_ARCHIVE_TAG) {
|
|
355
|
-
const archive = this.archiver.archive(repoRoot, base);
|
|
358
|
+
const archive = await this.archiver.archive(repoRoot, base);
|
|
356
359
|
tag = archive.tag;
|
|
357
360
|
line = archive.ok
|
|
358
361
|
? ` Archived ${base} → ${archive.tag} (restore: ${this.archiver.restoreCommand(base, archive.tag)})\n`
|
|
359
362
|
: ` ⚠️ Could not archive ${base}: ${archive.error} — the branch was left alone.\n`;
|
|
360
363
|
}
|
|
361
|
-
const feature = this.aiBranchName.getFeatureName();
|
|
362
|
-
const record = new merge_info_index_1.ArchiveRecord(tag, this.revParse(repoRoot, base), this.revParse(repoRoot, 'origin/main'), Number(ref.number), new Date().toISOString());
|
|
364
|
+
const feature = await this.aiBranchName.getFeatureName();
|
|
365
|
+
const record = new merge_info_index_1.ArchiveRecord(tag, await this.revParse(repoRoot, base), await this.revParse(repoRoot, 'origin/main'), Number(ref.number), new Date().toISOString());
|
|
363
366
|
if (this.mergeInfoIndex.promoteToMerged(repoRoot, feature, record)) {
|
|
364
367
|
line += ` merge-info: staged/${feature} → merged/${feature} (index.json rebuilt)\n`;
|
|
365
368
|
}
|
|
366
369
|
return line;
|
|
367
370
|
}
|
|
368
371
|
// Best-effort sha of a ref — '' when it cannot resolve. Recorded in archive.json for provenance.
|
|
369
|
-
revParse(repoRoot, ref) {
|
|
370
|
-
const result =
|
|
371
|
-
return result.
|
|
372
|
+
async revParse(repoRoot, ref) {
|
|
373
|
+
const result = await this.git.run(['rev-parse', ref], repoRoot);
|
|
374
|
+
return result.ok ? result.stdout.trim() : '';
|
|
375
|
+
}
|
|
376
|
+
// `git branch --show-current` in the invocation directory. Must succeed: a branch we cannot read is
|
|
377
|
+
// not a selector to guess at.
|
|
378
|
+
async currentBranch(cwd) {
|
|
379
|
+
const result = await this.git.run(['branch', '--show-current'], cwd);
|
|
380
|
+
if (!result.ok) {
|
|
381
|
+
throw new tooling_common_1.InformAiError(`Could not read the current branch in ${cwd} (git branch --show-current): ${result.stderr.trim()}`);
|
|
382
|
+
}
|
|
383
|
+
return result.stdout.trim();
|
|
372
384
|
}
|
|
373
385
|
/**
|
|
374
386
|
* Everything landing needs about the PR, in ONE `gh` read: number, title, URL, DESCRIPTION and the
|
|
@@ -379,11 +391,11 @@ let LandPrCommand = class LandPrCommand {
|
|
|
379
391
|
* class doc). `headRefOid` is read BEFORE the merge, because it is what the bookkeeping check
|
|
380
392
|
* compares against and the merge is what makes the branch's fate uninteresting to GitHub.
|
|
381
393
|
*/
|
|
382
|
-
readPr(selector) {
|
|
383
|
-
const result =
|
|
384
|
-
if (result.
|
|
394
|
+
async readPr(selector) {
|
|
395
|
+
const result = await this.processes.run('gh', ['pr', 'view', selector, '--json', 'number,title,url,body,headRefOid,headRefName']);
|
|
396
|
+
if (!result.ok)
|
|
385
397
|
return null;
|
|
386
|
-
return this.parsePr(result.stdout
|
|
398
|
+
return this.parsePr(result.stdout);
|
|
387
399
|
}
|
|
388
400
|
// `gh --json` output → PrIdentity. Malformed/absent JSON reads as "no PR", which the caller turns
|
|
389
401
|
// into the same refusal a missing PR gets: both mean nothing here can be landed.
|
|
@@ -423,7 +435,9 @@ exports.LandPrCommand = LandPrCommand = tslib_1.__decorate([
|
|
|
423
435
|
merge_info_index_1.MergeInfoIndex,
|
|
424
436
|
landed_worktree_reaper_1.LandedWorktreeReaper,
|
|
425
437
|
merge_body_temp_file_1.MergeBodyTempFile,
|
|
426
|
-
landed_tree_resolver_1.LandedTreeResolver
|
|
438
|
+
landed_tree_resolver_1.LandedTreeResolver,
|
|
439
|
+
tooling_common_1.GitProcessApi,
|
|
440
|
+
tooling_common_1.NativeProcessApi])
|
|
427
441
|
], LandPrCommand);
|
|
428
442
|
// The open PR as GitHub holds it: its number, title, web URL, DESCRIPTION (= the gated commit body) and
|
|
429
443
|
// the PAIR that identifies its tree locally — the head branch's name and the commit being squashed.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"land-pr-command.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/commands/land-pr-command.ts"],"names":[],"mappings":";;;;AAAA,iDAAoD;AACpD,8DAA0D;AAC1D,iEAA6D;AAC7D,0DAA2F;AAC3F,sEAAoH;AACpH,yCAA2D;AAC3D,2EAAgE;AAChE,6DAAyD;AACzD,2EAAsG;AACtG,+EAA+F;AAC/F,2EAAqE;AACrE,mEAA6E;AAC7E,qDAA8D;AAE9D,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAEvE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AAEI,IAAM,aAAa,GAAnB,MAAM,aAAa;IAGD;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IAVrB,yDAAyD;IACzD,YACqB,cAA8B,EAC9B,YAA0B,EAC1B,YAA0B,EAC1B,QAAkB,EAClB,QAAwB,EACxB,cAA8B,EAC9B,cAAoC,EACpC,QAA2B,EAC3B,UAA8B;QAR9B,mBAAc,GAAd,cAAc,CAAgB;QAC9B,iBAAY,GAAZ,YAAY,CAAc;QAC1B,iBAAY,GAAZ,YAAY,CAAc;QAC1B,aAAQ,GAAR,QAAQ,CAAU;QAClB,aAAQ,GAAR,QAAQ,CAAgB;QACxB,mBAAc,GAAd,cAAc,CAAgB;QAC9B,mBAAc,GAAd,cAAc,CAAsB;QACpC,aAAQ,GAAR,QAAQ,CAAmB;QAC3B,eAAU,GAAV,UAAU,CAAoB;IAChD,CAAC;IAEJ;;;;;;;;OAQG;IACK,aAAa;QACjB,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC;QAC3C,OAAO,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,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jB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACnC,CAAC;CACJ;AAED;;;;;;GAMG;AACH,MAAa,aAAa;IACtB;;;;OAIG;IACH,aAAa,CAAU;IACvB,mGAAmG;IACnG,QAAQ,CAAS;IAEjB,YAAY,aAAsB,EAAE,QAAgB;QAChD,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC7B,CAAC;CACJ;AAdD,sCAcC","sourcesContent":["import { execSync, spawnSync } from 'child_process';\nimport { InformAiError } from '@webpieces/tooling-common';\nimport { toError } from '@webpieces/tooling-common/to-error';\nimport { RepoRootFinder, MERGE_MODE_AUTO, loadAndValidate } from '@webpieces/rules-config';\nimport { BranchArchiver, BRANCH_RETENTION_ARCHIVE_TAG, BRANCH_RETENTION_KEEP } from '@webpieces/repo-workflow-core';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { AiBranchName } from '../workflow/git-readAiBranchName';\nimport { BranchNaming } from '../workflow/branch-naming';\nimport { LandedTree, LandedTreeResolver, LANDED_TREE_ABSENT } from '../workflow/landed-tree-resolver';\nimport { LandedWorktreeReaper, WorktreeReapHandoff } from '../workflow/landed-worktree-reaper';\nimport { MergeBodyTempFile } from '../workflow/merge-body-temp-file';\nimport { ArchiveRecord, MergeInfoIndex } from '../workflow/merge-info-index';\nimport { MergeIntent, PrMerger } from '../workflow/pr-merger';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n/**\n * `wp-land-pr`: squash-merge THIS branch's already-posted PR into main with the compact commit body.\n *\n * It exists because a merge clicked in the GitHub UI cannot set the squash SUBJECT to `<title> (#N)`\n * and cannot archive the pre-squash tip. So when a merge has to happen outside `wp-finish-upsert-pr`\n * (a mergeMode=NONE repo, or a PR whose checks were still running when finish ran), this is the command\n * that keeps main's history consistent and finishes the branch's bookkeeping.\n *\n * ─── Where the bytes come from: THE PR ITSELF ──────────────────────────────────────────────────────\n * `wp-finish-upsert-pr` renders ONE string and publishes it as the PR DESCRIPTION, and the full\n * dashboard lives in the PR's comments (see `pr-body-is-merge-body.spec.ts`, which pins that the\n * description and the merge body are one renderer's output). So the description IS the gated squash\n * body, held by GitHub, and landing reads it back with `gh pr view --json body`.\n *\n * THE BYTES THAT LAND ARE THE BYTES FINISH PRODUCED — that invariant is unchanged; what changed is that\n * GitHub, not this machine, is the thing holding them. That removes the whole machine-global receipt\n * store: a cache of a fact the remote already owns, which could only ever be missing, stale, or on the\n * wrong computer. Landing from a second clone, a fresh clone, or another machine entirely now just\n * works. See `decisions/0005-the-pr-description-is-the-merge-body.md`.\n *\n * It still deliberately does NOT re-render the body: re-deriving it at land time would be a second\n * authoritative gate whose result nobody reads, and it could silently disagree with what was reviewed.\n *\n * ─── Two scopes, and only one of them is the tree's ────────────────────────────────────────────────\n * 1. THE MERGE, which belongs to the PR — and is therefore reachable from anywhere.\n * 2. THE BOOKKEEPING — archiving the pre-squash tip as `archive/<date>/<branch>`, promoting merge-info,\n * and reaping the landed worktree. That half belongs to the tree whose `<branch>` really is the\n * commit being squashed, and it must NOT be attempted from anywhere else: another clone's\n * `<branch>` is a different commit, so archiving it there would tag the wrong objects under the\n * right name.\n *\n * ─── WHICH tree that is, is a FACT — it is not \"the one I am standing in\" ──────────────────────────\n * That distinction used to be resolved from `process.cwd()`, and it was wrong twice over.\n *\n * It was wrong MECHANICALLY: `pnpm` hoists a bin's cwd to the workspace root, and a Claude Code agent\n * worktree lives at `<primary>/.claude/worktrees/agent-<id>` — INSIDE the primary clone — so pnpm walked\n * straight past it and `git branch --show-current` answered `main`. Landing a worktree PR, i.e. every\n * `/full-cycle` run, reported \"No open PR found for this branch\" for a PR that was open, and the #512\n * worktree reap was unreachable dead code. The invocation directory is now read from `INIT_CWD` (pnpm\n * exports the directory the human actually typed in) and given to BOTH the repo-root resolution and the\n * `git` call, so neither can be answered by the hoisted directory.\n *\n * And it was wrong in PRINCIPLE, which is the larger half: most of the time the `/full-cycle` subagent\n * lands its own PR, but many times it does not — CI was still running when it finished, it errored, or a\n * coordinator picks the work up an hour later, by which point that agent is gone and its worktree is a\n * directory nobody is standing in. So `--pr <n>` names the PR, and {@link LandedTreeResolver} finds its\n * tree by the pair `(headRefName, headRefOid)` — never by branch name alone. The reap target is the\n * worktree whose HEAD is the exact commit GitHub squashed, whichever directory the operator is in, and\n * when nothing local holds that commit the merge still happens and the bookkeeping is SKIPPED OUT LOUD.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class LandPrCommand {\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(\n private readonly repoRootFinder: RepoRootFinder,\n private readonly aiBranchName: AiBranchName,\n private readonly branchNaming: BranchNaming,\n private readonly prMerger: PrMerger,\n private readonly archiver: BranchArchiver,\n private readonly mergeInfoIndex: MergeInfoIndex,\n private readonly landedWorktree: LandedWorktreeReaper,\n private readonly bodyFile: MergeBodyTempFile,\n private readonly landedTree: LandedTreeResolver,\n ) {}\n\n /**\n * THE INVOCATION DIRECTORY, which is not `process.cwd()`.\n *\n * `pnpm` runs a workspace bin with its cwd hoisted to the workspace root and exports the directory\n * the operator was actually in as `INIT_CWD`. Every agent worktree is NESTED inside the primary\n * clone, so the hoist silently relocated this command into a different tree holding a different\n * branch — see the class doc. `process.cwd()` remains the answer when nothing set `INIT_CWD` (a\n * direct `node` invocation, or a spec), which is the case where the two are the same anyway.\n */\n private invocationCwd(): string {\n const init = process.env['INIT_CWD'] ?? '';\n return init !== '' ? init : process.cwd();\n }\n\n async run(request: LandPrRequest): Promise<void> {\n if (request.prFlagPresent && !/^\\d+$/.test(request.prNumber)) throw this.badPrNumber(request);\n const cwd = this.invocationCwd();\n const repoRoot = this.repoRootFinder.resolveRepoRoot(cwd);\n // `--pr <n>` selects the PR outright; with no flag it is this branch's, read from the tree the\n // operator is really standing in.\n const selector = request.prNumber !== ''\n ? request.prNumber\n : this.branchNaming.baseBranchName(\n execSync('git branch --show-current', { cwd, encoding: 'utf8' }).trim());\n\n const ref = this.readPr(selector);\n if (ref === null) throw this.noSuchPr(request, selector);\n // The PR's OWN head branch, never the selector: with `--pr <n>` the operator named a number and\n // has said nothing about branches, and even in the zero-arg case GitHub is the authority on which\n // branch that PR is merging.\n const base = ref.headRefName !== '' ? ref.headRefName : selector;\n if (ref.body === '') throw this.emptyDescription(ref);\n const unfit = this.notFitForGitLog(ref.body);\n if (unfit !== '') throw this.descriptionUnfitForGitLog(ref, unfit);\n\n process.stdout.write('\\n' + SEP + `🚀 Landing PR #${ref.number}\\n` + SEP + '\\n');\n const mergeBodyFile = this.bodyFile.write(ref.body);\n\n const config = loadAndValidate(repoRoot).prGate;\n const policy = config.mergeMode;\n // Reuse the SAME merge logic wp-finish-upsert-pr uses, so a PR lands identically whichever\n // command lands it — including the auto-merge fallback when the checks are still running.\n //\n // `commanded: true` — running THIS command IS the intent to merge, so it is not gated on\n // pr-gate.mergeMode (a NONE repo runs this precisely to land one PR by hand). The real `policy`\n // travels alongside it rather than being replaced by a literal AUTO, so PrMerger's diagnostics\n // never assert a config value nobody set — that is exactly what used to print a CONFIG MISMATCH\n // about `mergeMode: AUTO` two lines above this command printing `mergeMode is NONE`.\n const outcome = this.prMerger.merge(\n base, `${ref.title} (#${ref.number})`, mergeBodyFile, new MergeIntent(policy ?? '', true),\n );\n\n const bookkeeping = outcome.merged\n ? this.bookkeeping(repoRoot, base, ref, config.landPr.branchRetention, cwd)\n : '';\n process.stdout.write(\n '\\n' + SEP + (outcome.merged ? '✅ Landed\\n' : 'ℹ️ Not landed yet\\n') + SEP + '\\n' +\n ` ${outcome.message}\\n` +\n bookkeeping +\n (policy === MERGE_MODE_AUTO\n ? ''\n : ` (pr-gate.mergeMode is ${policy} — wp-finish-upsert-pr publishes PRs without attempting a merge.)\\n`) +\n '\\n',\n );\n }\n\n /**\n * `--pr` without a usable number. It REFUSES rather than falling back to the branch, because the\n * fallback would land a different PR from the one the operator was reaching for, and a squash into\n * main is not a place to guess. `--pr` bare and `--pr HEAD` land here alike.\n */\n private badPrNumber(request: LandPrRequest): InformAiError {\n const got = request.prNumber === '' ? 'nothing' : `\"${request.prNumber}\"`;\n return new InformAiError(\n '\\n' + SEP + '❌ --pr needs a PR NUMBER\\n' + SEP + '\\n' +\n `\\`--pr\\` was given ${got}. It takes the digits of one pull request:\\n` +\n ' pnpm wp-land-pr --pr 1087\\n\\n' +\n 'To land the PR of the branch you are standing on, pass no flag at all:\\n' +\n ' pnpm wp-land-pr\\n' + SEP);\n }\n\n /**\n * The refusal when `gh` has no open PR for what we asked about — and it must say WHICH question was\n * asked, because the two have different cures.\n *\n * The branch form used to be the only one, and it was the face of the cwd bug: run from an agent\n * worktree, pnpm's hoist made the branch read `main`, and an operator with an open PR in front of\n * them was told there was none. So the branch form now says what it looked up and where it read that\n * branch FROM, which is the one fact that makes a wrong answer recognisable as a wrong answer, and it\n * names the `--pr <n>` form that does not depend on the tree at all.\n */\n private noSuchPr(request: LandPrRequest, selector: string): InformAiError {\n if (request.prNumber !== '') {\n return new InformAiError(\n '\\n' + SEP + `❌ No open PR #${request.prNumber}\\n` + SEP + '\\n' +\n `\\`gh pr view ${request.prNumber}\\` found no OPEN pull request with that number.\\n` +\n 'If it is already merged, run `pnpm wp-cleanup` from the primary clone to finish the\\n' +\n 'branch and worktree bookkeeping. Otherwise check the number with `gh pr list`.\\n' + SEP);\n }\n return new InformAiError(\n '\\n' + SEP + '❌ No open PR found for this branch\\n' + SEP + '\\n' +\n `No open PR has head branch \"${selector}\", read from ${this.invocationCwd()}. Nothing to land.\\n` +\n 'If that is not the branch you expected, land it by number instead — it does not depend on\\n' +\n 'which directory you are standing in:\\n' +\n ' pnpm wp-land-pr --pr <n>\\n' +\n 'If the PR is already merged, run `pnpm wp-cleanup`.\\n' +\n 'If it was never posted, run the gated flow — it posts the PR AND writes the description\\n' +\n 'that becomes this commit body:\\n' +\n ' pnpm wp-start-upsert-pr && pnpm wp-review-upsert-pr && pnpm wp-finish-upsert-pr\\n' + SEP);\n }\n\n /**\n * The refusal when the PR exists but its description is empty.\n *\n * This is the ONE remaining \"no gated body\" case, and it is now a property of the PR rather than of\n * this machine — which is why the cure is a single command with no human judgement call attached.\n * There is deliberately no `--fallback-title-only` escape any more: that flag existed because the\n * bytes could be on a DIFFERENT COMPUTER from the one landing, which cannot happen when GitHub holds\n * them. Re-running finish is always available, always correct, and lands the reviewed bytes.\n */\n private emptyDescription(ref: PrIdentity): InformAiError {\n return new InformAiError(\n '\\n' + SEP + `❌ PR #${ref.number} has an EMPTY description\\n` + SEP + '\\n' +\n 'The PR description IS the squash-commit body — `pnpm wp-finish-upsert-pr` renders one string\\n' +\n 'and publishes it as the description, and landing reads it straight back with\\n' +\n '`gh pr view --json body`. An empty description means the gated flow never published one\\n' +\n '(or a human cleared it), so there is nothing reviewed to land.\\n\\n' +\n 'Re-run the gated flow — it re-renders the description and re-posts it to this same PR:\\n' +\n ' pnpm wp-start-upsert-pr # update from main (3-point merge). No push, no build gate.\\n' +\n ' pnpm wp-review-upsert-pr # validate the merge, build gate, extract the diff, brief reviewers\\n' +\n ' # write summary.json at the path wp-review-upsert-pr prints\\n' +\n ' pnpm wp-finish-upsert-pr # build gate, dashboard, create/update the PR\\n' +\n 'Then re-run `pnpm wp-land-pr`.\\n' + SEP,\n );\n }\n\n /**\n * '' when the description is a compact gated body; otherwise the marker that proves it is not.\n *\n * This reads the SAME invariant `pr-body-is-merge-body.spec.ts` asserts from the other end: the\n * compact body \"contains nothing a plain-text git log cannot carry\" — no markdown heading, no table\n * pipe. It is therefore not a heuristic about what a dashboard looks like; it is the renderer's own\n * pinned property, checked against bytes that arrived from outside this process.\n *\n * WHY IT IS NEEDED, and why it is not a compatibility fallback: a PR posted by a release OLDER than\n * the surface swap still has the FULL DASHBOARD as its description. Measured on this repo,\n * 2026-08-07 — PR #613 (posted after the swap) has a description byte-identical to its squash body,\n * while PR #614 (still open, posted minutes before) begins `## 🚦 PR Gate Dashboard`. Landing that\n * one would dump a risk table into main, which is precisely the defect\n * `decisions/0004` § 4.1 warned about. So this REFUSES and names the one command that fixes it. It\n * never falls back, never rewrites, and never reaches for a second source of bytes.\n *\n * It keeps earning its place after the transition: nothing stops a human editing a PR description\n * in GitHub's textarea, and this is the only point between that edit and main's history.\n *\n * What it must NOT be read as is proof that the bytes did not come from `renderPrBody`. They can:\n * the compact body interpolates author text, and a `|` reaches that text from a TypeScript union, a\n * regex alternation or a quoted shell pipeline. `Dashboard.gitLogSafe` substitutes both markers at\n * the render exit so a freshly-rendered body no longer trips this — which is where that invariant\n * belongs, since the renderer is the only thing that can fix it without an extra CI cycle.\n */\n private notFitForGitLog(body: string): string {\n if (body.includes('##')) return '## (a markdown heading)';\n if (body.includes('|')) return '| (a markdown table)';\n return '';\n }\n\n /**\n * The refusal when the description is not the compact gated body.\n *\n * It names BOTH ways bytes get here, because naming only one sent readers down a path that did not\n * exist. It used to assert an old release as \"the usual cause\" and prescribe re-running finish — and\n * when the marker had come from AUTHOR TEXT instead (a `|` in a summary, from a TypeScript union or a\n * regex alternation), finish re-rendered the identical character from the unchanged `summary.json` and\n * landing refused again: a loop costing a CI cycle per turn, escapable only by guessing that one\n * character in your prose was the problem. `Dashboard.gitLogSafe` now substitutes both markers at the\n * render exit, so a freshly-rendered body cannot reach here at all — which leaves a HAND-EDITED\n * description and a genuinely old PR as the two remaining causes, and this says so.\n */\n private descriptionUnfitForGitLog(ref: PrIdentity, marker: string): InformAiError {\n return new InformAiError(\n '\\n' + SEP + `❌ PR #${ref.number}'s description is not a git-log commit body\\n` + SEP + '\\n' +\n `It contains ${marker}, which the compact body rendered by \\`pnpm wp-finish-upsert-pr\\` never\\n` +\n 'does — it substitutes both markers as it renders — so these bytes are not the gated summary,\\n' +\n 'and landing them would put a PR Gate Dashboard (or hand-written markdown) into main\\'s\\n' +\n 'history permanently.\\n\\n' +\n 'There are two causes, and they need different fixes:\\n\\n' +\n ' 1. The description was EDITED BY HAND on GitHub after finish posted it. Re-running finish\\n' +\n ' overwrites that edit with the compact body, so landing works.\\n' +\n ' 2. The PR was posted by a webpieces release OLDER than the one that made the description\\n' +\n ' the commit body, so it is still the full dashboard. The dashboard now lives in the PR\\'s\\n' +\n ' 1st comment instead, and re-running finish moves it there.\\n\\n' +\n `Either way the cure is the same, and it does NOT require removing ${marker.trim()} from your PR\\n` +\n 'summary text — a pipe or a heading in a summary is rendered safe, not rejected:\\n' +\n ' pnpm wp-start-upsert-pr && pnpm wp-review-upsert-pr && pnpm wp-finish-upsert-pr\\n' + SEP,\n );\n }\n\n /**\n * The landed branch's post-merge bookkeeping — but ONLY when this tree's `<branch>` IS the commit\n * that was squashed.\n *\n * The fact being tested is \"does this working tree hold the objects the PR merged\", and the PR\n * answers it authoritatively: `headRefOid` is the tip GitHub squashed. A second clone's `<branch>`\n * is a different commit, so `archive/<date>/<branch>` there would tag the wrong tip under the right\n * name; `merge-info/staged/<feature>` lives in the posting tree's state, not ours; and the worktree\n * to reap is not this one. So the merge stands and the bookkeeping is declined ALOUD.\n *\n * This used to be read out of an `origin.json` sidecar recording which tree posted the PR. Comparing\n * SHAs is strictly better: it is a fact rather than a recorded claim, it needs no stored state, and\n * it is more precise in both directions — a second clone sitting on the SAME commit can safely\n * archive it, and a tree that has committed further work since finish ran correctly declines.\n */\n private bookkeeping(\n repoRoot: string, base: string, ref: PrIdentity, retention: string, cwd: string,\n ): string {\n const tree = this.landedTree.resolve(repoRoot, base, ref.headRefOid);\n if (!tree.bookkeepingAllowed) return this.notTheLandedTipNotice(base, tree, ref);\n return this.archiveAndPromote(repoRoot, base, ref, retention)\n + this.nextStep(repoRoot, tree, cwd);\n }\n\n /**\n * What was skipped, why, and what the two SHAs are — so the reader can tell WHICH cause it was.\n *\n * Two causes, one message, because the cure is the same for both: the objects the PR squashed are not\n * in this repo under that name, so nothing here may archive them or reap a tree for them.\n */\n private notTheLandedTipNotice(base: string, tree: LandedTree, ref: PrIdentity): string {\n const found = tree.kind === LANDED_TREE_ABSENT\n ? ` ${base} is not in this repo at all\\n`\n : ` ${base} here → ${tree.localSha}\\n`;\n return '\\n ⚠️ Archive + worktree cleanup SKIPPED — nothing here holds the commit that landed:\\n' +\n found +\n ` PR #${ref.number} squashed → ${ref.headRefOid}\\n` +\n ' Archiving from here would tag the wrong objects under the right name, and the\\n' +\n ` merge-info record and (if any) the worktree holding ${base} live with the other tip.\\n` +\n ' Either this is a second clone of the repo — finish the bookkeeping in the clone that\\n' +\n ' posted the PR with `pnpm wp-cleanup` — or that tree has commits made after\\n' +\n ' `pnpm wp-finish-upsert-pr` ran, which the PR does not contain.\\n';\n }\n\n /**\n * What happens next — which is NOT the same act when you landed from a worktree.\n *\n * Landing from a linked worktree always used to leave a corpse: the merged branch is checked out\n * here, so `git branch -D` refuses, `wp-cleanup`'s branch pass spares it as in-use, and nothing\n * removed the worktree — so the pair sat there until branch-creation-guard hit its cap. #512 made\n * worktrees reapable and printed `cd <primary> && pnpm wp-cleanup`; that instruction was correct\n * and it was the most-skipped step in the flow, because the PR is already landed and the work\n * feels done.\n *\n * So the reap is no longer an instruction. This command still refuses to remove the directory it\n * is standing in — that rail is untouched — and instead HANDS THE REAP to a child process rooted\n * in the primary clone, which is a tree nobody is deleting. See LandedWorktreeReaper. When that\n * hand-off is not safely achievable the #512 notice is printed unchanged, because an honest\n * limitation beats a command that deletes its own working directory mid-run.\n */\n private nextStep(repoRoot: string, tree: LandedTree, cwd: string): string {\n const handoff: WorktreeReapHandoff | null\n = this.landedWorktree.plan(repoRoot, tree.worktree, cwd);\n if (handoff === null) return ' Next: `pnpm wp-cleanup` to delete the merged branch.\\n';\n if (!handoff.canReap) return this.landedWorktree.manualNotice(handoff);\n return this.landedWorktree.handOff(handoff);\n }\n\n /**\n * The landed branch's post-merge bookkeeping, in one place:\n * 1. ARCHIVE the pre-squash tip as `archive/<date>/<branch>` — the tag makes the original history\n * permanently restorable (`git checkout -b <branch> <tag>` gives back the exact objects) while\n * costing one ref, so the branch itself no longer has to survive as a `*PreMerge` husk that\n * counts toward the branch cap. See BranchArchiver for why a tag beats a patch or the reflog.\n * 2. PROMOTE `merge-info/staged/<feature>/` to `merge-info/merged/<feature>/` and rebuild\n * `index.json`, so `staged/` holds only branches that are still in flight.\n *\n * Never throws: the PR is already merged by the time we get here, and failing the command after a\n * successful merge would report a landed PR as a failure. Problems are reported in the recap.\n */\n private archiveAndPromote(repoRoot: string, base: string, ref: PrIdentity, retention: string): string {\n if (retention === BRANCH_RETENTION_KEEP) return ' Branch retention is \"keep\" — nothing archived.\\n';\n\n let line = '';\n let tag = '';\n if (retention === BRANCH_RETENTION_ARCHIVE_TAG) {\n const archive = this.archiver.archive(repoRoot, base);\n tag = archive.tag;\n line = archive.ok\n ? ` Archived ${base} → ${archive.tag} (restore: ${this.archiver.restoreCommand(base, archive.tag)})\\n`\n : ` ⚠️ Could not archive ${base}: ${archive.error} — the branch was left alone.\\n`;\n }\n\n const feature = this.aiBranchName.getFeatureName();\n const record = new ArchiveRecord(\n tag, this.revParse(repoRoot, base), this.revParse(repoRoot, 'origin/main'),\n Number(ref.number), new Date().toISOString(),\n );\n if (this.mergeInfoIndex.promoteToMerged(repoRoot, feature, record)) {\n line += ` merge-info: staged/${feature} → merged/${feature} (index.json rebuilt)\\n`;\n }\n return line;\n }\n\n // Best-effort sha of a ref — '' when it cannot resolve. Recorded in archive.json for provenance.\n private revParse(repoRoot: string, ref: string): string {\n const result = spawnSync('git', ['rev-parse', ref], { cwd: repoRoot, encoding: 'utf8' });\n return result.status === 0 ? (result.stdout ?? '').trim() : '';\n }\n\n /**\n * Everything landing needs about the PR, in ONE `gh` read: number, title, URL, DESCRIPTION and the\n * head sha GitHub is squashing. `null` when there is no open PR for this head branch.\n *\n * The TITLE comes from the PR itself, not summary.json, so the squash subject matches what a reviewer\n * approved even if summary.json was edited afterwards. The BODY is the gated commit body (see the\n * class doc). `headRefOid` is read BEFORE the merge, because it is what the bookkeeping check\n * compares against and the merge is what makes the branch's fate uninteresting to GitHub.\n */\n private readPr(selector: string): PrIdentity | null {\n const result = spawnSync(\n 'gh', ['pr', 'view', selector, '--json', 'number,title,url,body,headRefOid,headRefName'],\n { encoding: 'utf8' },\n );\n if (result.status !== 0) return null;\n return this.parsePr(result.stdout ?? '');\n }\n\n // `gh --json` output → PrIdentity. Malformed/absent JSON reads as \"no PR\", which the caller turns\n // into the same refusal a missing PR gets: both mean nothing here can be landed.\n private parsePr(stdout: string): PrIdentity | null {\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: unparseable gh output means \"no PR\", never a crash\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n // webpieces-disable no-any-unknown -- gh's JSON is opaque until narrowed field-by-field below\n const raw = JSON.parse(stdout) as Record<string, unknown>;\n const number = typeof raw['number'] === 'number' ? String(raw['number']) : this.str(raw['number']);\n if (number === '') return null;\n // GitHub stores descriptions with CRLF. A commit body must not carry them, and the bytes are\n // otherwise identical to what finish rendered, so the line endings are normalized back here.\n const body = this.str(raw['body']).replace(/\\r\\n/g, '\\n').trim();\n return new PrIdentity(\n number, this.str(raw['title']), this.str(raw['url']), body === '' ? '' : body + '\\n',\n this.str(raw['headRefOid']), this.str(raw['headRefName']),\n );\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n return null;\n }\n }\n\n // webpieces-disable no-any-unknown -- one opaque JSON field, narrowed to string\n private str(value: unknown): string {\n return typeof value === 'string' ? value : '';\n }\n}\n\n// The open PR as GitHub holds it: its number, title, web URL, DESCRIPTION (= the gated commit body) and\n// the PAIR that identifies its tree locally — the head branch's name and the commit being squashed.\nclass PrIdentity {\n number: string;\n title: string;\n url: string;\n body: string;\n headRefOid: string;\n /**\n * The PR's head BRANCH. Required alongside `headRefOid` because neither half identifies a tree on its\n * own: the name is what a worktree list can be searched by, the sha is what makes a hit the right\n * one. It also frees `--pr <n>` from needing the operator to be standing anywhere in particular.\n */\n headRefName: string;\n\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(\n number: string, title: string, url: string, body: string, headRefOid: string, headRefName: string,\n ) {\n this.number = number;\n this.title = title;\n this.url = url;\n this.body = body;\n this.headRefOid = headRefOid;\n this.headRefName = headRefName;\n }\n}\n\n/**\n * Data-only (per CLAUDE.md, classes for data): what the operator asked `wp-land-pr` to land.\n *\n * `prNumber` is '' for the zero-arg form — \"this branch's PR\" — which stays the shorthand the worker\n * uses. It is NOT an optional constructor parameter with a default at the call site: `wp-land-pr.ts`\n * builds exactly one of these from the parsed argv, so there is one spelling of the decision.\n */\nexport class LandPrRequest {\n /**\n * Was `--pr` on the command line at all? Kept SEPARATE from the value because `--pr` with no number\n * is a mistake, not a request to guess: collapsing the two would silently land whatever PR the\n * current directory's branch happens to have, which is the opposite of what the operator typed.\n */\n prFlagPresent: boolean;\n /** The `--pr <n>` value verbatim, or '' to infer the PR from the invocation directory's branch. */\n prNumber: string;\n\n constructor(prFlagPresent: boolean, prNumber: string) {\n this.prFlagPresent = prFlagPresent;\n this.prNumber = prNumber;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"land-pr-command.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/commands/land-pr-command.ts"],"names":[],"mappings":";;;;AAAA,8DAA2F;AAC3F,iEAA6D;AAC7D,0DAA2F;AAC3F,sEAAoH;AACpH,yCAA2D;AAC3D,2EAAgE;AAChE,6DAAyD;AACzD,2EAAsG;AACtG,+EAA+F;AAC/F,2EAAqE;AACrE,mEAA6E;AAC7E,qDAA8D;AAE9D,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAEvE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AAEI,IAAM,aAAa,GAAnB,MAAM,aAAa;IAGD;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IAZrB,yDAAyD;IACzD,YACqB,cAA8B,EAC9B,YAA0B,EAC1B,YAA0B,EAC1B,QAAkB,EAClB,QAA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,CAAS;IAEjB,YAAY,aAAsB,EAAE,QAAgB;QAChD,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC7B,CAAC;CACJ;AAdD,sCAcC","sourcesContent":["import { GitProcessApi, InformAiError, NativeProcessApi } from '@webpieces/tooling-common';\nimport { toError } from '@webpieces/tooling-common/to-error';\nimport { RepoRootFinder, MERGE_MODE_AUTO, loadAndValidate } from '@webpieces/rules-config';\nimport { BranchArchiver, BRANCH_RETENTION_ARCHIVE_TAG, BRANCH_RETENTION_KEEP } from '@webpieces/repo-workflow-core';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { AiBranchName } from '../workflow/git-readAiBranchName';\nimport { BranchNaming } from '../workflow/branch-naming';\nimport { LandedTree, LandedTreeResolver, LANDED_TREE_ABSENT } from '../workflow/landed-tree-resolver';\nimport { LandedWorktreeReaper, WorktreeReapHandoff } from '../workflow/landed-worktree-reaper';\nimport { MergeBodyTempFile } from '../workflow/merge-body-temp-file';\nimport { ArchiveRecord, MergeInfoIndex } from '../workflow/merge-info-index';\nimport { MergeIntent, PrMerger } from '../workflow/pr-merger';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n/**\n * `wp-land-pr`: squash-merge THIS branch's already-posted PR into main with the compact commit body.\n *\n * It exists because a merge clicked in the GitHub UI cannot set the squash SUBJECT to `<title> (#N)`\n * and cannot archive the pre-squash tip. So when a merge has to happen outside `wp-finish-upsert-pr`\n * (a mergeMode=NONE repo, or a PR whose checks were still running when finish ran), this is the command\n * that keeps main's history consistent and finishes the branch's bookkeeping.\n *\n * ─── Where the bytes come from: THE PR ITSELF ──────────────────────────────────────────────────────\n * `wp-finish-upsert-pr` renders ONE string and publishes it as the PR DESCRIPTION, and the full\n * dashboard lives in the PR's comments (see `pr-body-is-merge-body.spec.ts`, which pins that the\n * description and the merge body are one renderer's output). So the description IS the gated squash\n * body, held by GitHub, and landing reads it back with `gh pr view --json body`.\n *\n * THE BYTES THAT LAND ARE THE BYTES FINISH PRODUCED — that invariant is unchanged; what changed is that\n * GitHub, not this machine, is the thing holding them. That removes the whole machine-global receipt\n * store: a cache of a fact the remote already owns, which could only ever be missing, stale, or on the\n * wrong computer. Landing from a second clone, a fresh clone, or another machine entirely now just\n * works. See `decisions/0005-the-pr-description-is-the-merge-body.md`.\n *\n * It still deliberately does NOT re-render the body: re-deriving it at land time would be a second\n * authoritative gate whose result nobody reads, and it could silently disagree with what was reviewed.\n *\n * ─── Two scopes, and only one of them is the tree's ────────────────────────────────────────────────\n * 1. THE MERGE, which belongs to the PR — and is therefore reachable from anywhere.\n * 2. THE BOOKKEEPING — archiving the pre-squash tip as `archive/<date>/<branch>`, promoting merge-info,\n * and reaping the landed worktree. That half belongs to the tree whose `<branch>` really is the\n * commit being squashed, and it must NOT be attempted from anywhere else: another clone's\n * `<branch>` is a different commit, so archiving it there would tag the wrong objects under the\n * right name.\n *\n * ─── WHICH tree that is, is a FACT — it is not \"the one I am standing in\" ──────────────────────────\n * That distinction used to be resolved from `process.cwd()`, and it was wrong twice over.\n *\n * It was wrong MECHANICALLY: `pnpm` hoists a bin's cwd to the workspace root, and a Claude Code agent\n * worktree lives at `<primary>/.claude/worktrees/agent-<id>` — INSIDE the primary clone — so pnpm walked\n * straight past it and `git branch --show-current` answered `main`. Landing a worktree PR, i.e. every\n * `/full-cycle` run, reported \"No open PR found for this branch\" for a PR that was open, and the #512\n * worktree reap was unreachable dead code. The invocation directory is now read from `INIT_CWD` (pnpm\n * exports the directory the human actually typed in) and given to BOTH the repo-root resolution and the\n * `git` call, so neither can be answered by the hoisted directory.\n *\n * And it was wrong in PRINCIPLE, which is the larger half: most of the time the `/full-cycle` subagent\n * lands its own PR, but many times it does not — CI was still running when it finished, it errored, or a\n * coordinator picks the work up an hour later, by which point that agent is gone and its worktree is a\n * directory nobody is standing in. So `--pr <n>` names the PR, and {@link LandedTreeResolver} finds its\n * tree by the pair `(headRefName, headRefOid)` — never by branch name alone. The reap target is the\n * worktree whose HEAD is the exact commit GitHub squashed, whichever directory the operator is in, and\n * when nothing local holds that commit the merge still happens and the bookkeeping is SKIPPED OUT LOUD.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class LandPrCommand {\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(\n private readonly repoRootFinder: RepoRootFinder,\n private readonly aiBranchName: AiBranchName,\n private readonly branchNaming: BranchNaming,\n private readonly prMerger: PrMerger,\n private readonly archiver: BranchArchiver,\n private readonly mergeInfoIndex: MergeInfoIndex,\n private readonly landedWorktree: LandedWorktreeReaper,\n private readonly bodyFile: MergeBodyTempFile,\n private readonly landedTree: LandedTreeResolver,\n private readonly git: GitProcessApi,\n private readonly processes: NativeProcessApi,\n ) {}\n\n /**\n * THE INVOCATION DIRECTORY, which is not `process.cwd()`.\n *\n * `pnpm` runs a workspace bin with its cwd hoisted to the workspace root and exports the directory\n * the operator was actually in as `INIT_CWD`. Every agent worktree is NESTED inside the primary\n * clone, so the hoist silently relocated this command into a different tree holding a different\n * branch — see the class doc. `process.cwd()` remains the answer when nothing set `INIT_CWD` (a\n * direct `node` invocation, or a spec), which is the case where the two are the same anyway.\n */\n private invocationCwd(): string {\n const init = process.env['INIT_CWD'] ?? '';\n return init !== '' ? init : process.cwd();\n }\n\n async run(request: LandPrRequest): Promise<void> {\n if (request.prFlagPresent && !/^\\d+$/.test(request.prNumber)) throw this.badPrNumber(request);\n const cwd = this.invocationCwd();\n const repoRoot = this.repoRootFinder.resolveRepoRoot(cwd);\n // `--pr <n>` selects the PR outright; with no flag it is this branch's, read from the tree the\n // operator is really standing in.\n const selector = request.prNumber !== ''\n ? request.prNumber\n : this.branchNaming.baseBranchName(await this.currentBranch(cwd));\n\n const ref = await this.readPr(selector);\n if (ref === null) throw this.noSuchPr(request, selector);\n // The PR's OWN head branch, never the selector: with `--pr <n>` the operator named a number and\n // has said nothing about branches, and even in the zero-arg case GitHub is the authority on which\n // branch that PR is merging.\n const base = ref.headRefName !== '' ? ref.headRefName : selector;\n if (ref.body === '') throw this.emptyDescription(ref);\n const unfit = this.notFitForGitLog(ref.body);\n if (unfit !== '') throw this.descriptionUnfitForGitLog(ref, unfit);\n\n process.stdout.write('\\n' + SEP + `🚀 Landing PR #${ref.number}\\n` + SEP + '\\n');\n const mergeBodyFile = this.bodyFile.write(ref.body);\n\n const config = loadAndValidate(repoRoot).prGate;\n const policy = config.mergeMode;\n // Reuse the SAME merge logic wp-finish-upsert-pr uses, so a PR lands identically whichever\n // command lands it — including the auto-merge fallback when the checks are still running.\n //\n // `commanded: true` — running THIS command IS the intent to merge, so it is not gated on\n // pr-gate.mergeMode (a NONE repo runs this precisely to land one PR by hand). The real `policy`\n // travels alongside it rather than being replaced by a literal AUTO, so PrMerger's diagnostics\n // never assert a config value nobody set — that is exactly what used to print a CONFIG MISMATCH\n // about `mergeMode: AUTO` two lines above this command printing `mergeMode is NONE`.\n const outcome = await this.prMerger.merge(\n base, `${ref.title} (#${ref.number})`, mergeBodyFile, new MergeIntent(policy ?? '', true),\n );\n\n const bookkeeping = outcome.merged\n ? await this.bookkeeping(repoRoot, base, ref, config.landPr.branchRetention, cwd)\n : '';\n process.stdout.write(\n '\\n' + SEP + (outcome.merged ? '✅ Landed\\n' : 'ℹ️ Not landed yet\\n') + SEP + '\\n' +\n ` ${outcome.message}\\n` +\n bookkeeping +\n (policy === MERGE_MODE_AUTO\n ? ''\n : ` (pr-gate.mergeMode is ${policy} — wp-finish-upsert-pr publishes PRs without attempting a merge.)\\n`) +\n '\\n',\n );\n }\n\n /**\n * `--pr` without a usable number. It REFUSES rather than falling back to the branch, because the\n * fallback would land a different PR from the one the operator was reaching for, and a squash into\n * main is not a place to guess. `--pr` bare and `--pr HEAD` land here alike.\n */\n private badPrNumber(request: LandPrRequest): InformAiError {\n const got = request.prNumber === '' ? 'nothing' : `\"${request.prNumber}\"`;\n return new InformAiError(\n '\\n' + SEP + '❌ --pr needs a PR NUMBER\\n' + SEP + '\\n' +\n `\\`--pr\\` was given ${got}. It takes the digits of one pull request:\\n` +\n ' pnpm wp-land-pr --pr 1087\\n\\n' +\n 'To land the PR of the branch you are standing on, pass no flag at all:\\n' +\n ' pnpm wp-land-pr\\n' + SEP);\n }\n\n /**\n * The refusal when `gh` has no open PR for what we asked about — and it must say WHICH question was\n * asked, because the two have different cures.\n *\n * The branch form used to be the only one, and it was the face of the cwd bug: run from an agent\n * worktree, pnpm's hoist made the branch read `main`, and an operator with an open PR in front of\n * them was told there was none. So the branch form now says what it looked up and where it read that\n * branch FROM, which is the one fact that makes a wrong answer recognisable as a wrong answer, and it\n * names the `--pr <n>` form that does not depend on the tree at all.\n */\n private noSuchPr(request: LandPrRequest, selector: string): InformAiError {\n if (request.prNumber !== '') {\n return new InformAiError(\n '\\n' + SEP + `❌ No open PR #${request.prNumber}\\n` + SEP + '\\n' +\n `\\`gh pr view ${request.prNumber}\\` found no OPEN pull request with that number.\\n` +\n 'If it is already merged, run `pnpm wp-cleanup` from the primary clone to finish the\\n' +\n 'branch and worktree bookkeeping. Otherwise check the number with `gh pr list`.\\n' + SEP);\n }\n return new InformAiError(\n '\\n' + SEP + '❌ No open PR found for this branch\\n' + SEP + '\\n' +\n `No open PR has head branch \"${selector}\", read from ${this.invocationCwd()}. Nothing to land.\\n` +\n 'If that is not the branch you expected, land it by number instead — it does not depend on\\n' +\n 'which directory you are standing in:\\n' +\n ' pnpm wp-land-pr --pr <n>\\n' +\n 'If the PR is already merged, run `pnpm wp-cleanup`.\\n' +\n 'If it was never posted, run the gated flow — it posts the PR AND writes the description\\n' +\n 'that becomes this commit body:\\n' +\n ' pnpm wp-start-upsert-pr && pnpm wp-review-upsert-pr && pnpm wp-finish-upsert-pr\\n' + SEP);\n }\n\n /**\n * The refusal when the PR exists but its description is empty.\n *\n * This is the ONE remaining \"no gated body\" case, and it is now a property of the PR rather than of\n * this machine — which is why the cure is a single command with no human judgement call attached.\n * There is deliberately no `--fallback-title-only` escape any more: that flag existed because the\n * bytes could be on a DIFFERENT COMPUTER from the one landing, which cannot happen when GitHub holds\n * them. Re-running finish is always available, always correct, and lands the reviewed bytes.\n */\n private emptyDescription(ref: PrIdentity): InformAiError {\n return new InformAiError(\n '\\n' + SEP + `❌ PR #${ref.number} has an EMPTY description\\n` + SEP + '\\n' +\n 'The PR description IS the squash-commit body — `pnpm wp-finish-upsert-pr` renders one string\\n' +\n 'and publishes it as the description, and landing reads it straight back with\\n' +\n '`gh pr view --json body`. An empty description means the gated flow never published one\\n' +\n '(or a human cleared it), so there is nothing reviewed to land.\\n\\n' +\n 'Re-run the gated flow — it re-renders the description and re-posts it to this same PR:\\n' +\n ' pnpm wp-start-upsert-pr # update from main (3-point merge). No push, no build gate.\\n' +\n ' pnpm wp-review-upsert-pr # validate the merge, build gate, extract the diff, brief reviewers\\n' +\n ' # write summary.json at the path wp-review-upsert-pr prints\\n' +\n ' pnpm wp-finish-upsert-pr # build gate, dashboard, create/update the PR\\n' +\n 'Then re-run `pnpm wp-land-pr`.\\n' + SEP,\n );\n }\n\n /**\n * '' when the description is a compact gated body; otherwise the marker that proves it is not.\n *\n * This reads the SAME invariant `pr-body-is-merge-body.spec.ts` asserts from the other end: the\n * compact body \"contains nothing a plain-text git log cannot carry\" — no markdown heading, no table\n * pipe. It is therefore not a heuristic about what a dashboard looks like; it is the renderer's own\n * pinned property, checked against bytes that arrived from outside this process.\n *\n * WHY IT IS NEEDED, and why it is not a compatibility fallback: a PR posted by a release OLDER than\n * the surface swap still has the FULL DASHBOARD as its description. Measured on this repo,\n * 2026-08-07 — PR #613 (posted after the swap) has a description byte-identical to its squash body,\n * while PR #614 (still open, posted minutes before) begins `## 🚦 PR Gate Dashboard`. Landing that\n * one would dump a risk table into main, which is precisely the defect\n * `decisions/0004` § 4.1 warned about. So this REFUSES and names the one command that fixes it. It\n * never falls back, never rewrites, and never reaches for a second source of bytes.\n *\n * It keeps earning its place after the transition: nothing stops a human editing a PR description\n * in GitHub's textarea, and this is the only point between that edit and main's history.\n *\n * What it must NOT be read as is proof that the bytes did not come from `renderPrBody`. They can:\n * the compact body interpolates author text, and a `|` reaches that text from a TypeScript union, a\n * regex alternation or a quoted shell pipeline. `Dashboard.gitLogSafe` substitutes both markers at\n * the render exit so a freshly-rendered body no longer trips this — which is where that invariant\n * belongs, since the renderer is the only thing that can fix it without an extra CI cycle.\n */\n private notFitForGitLog(body: string): string {\n if (body.includes('##')) return '## (a markdown heading)';\n if (body.includes('|')) return '| (a markdown table)';\n return '';\n }\n\n /**\n * The refusal when the description is not the compact gated body.\n *\n * It names BOTH ways bytes get here, because naming only one sent readers down a path that did not\n * exist. It used to assert an old release as \"the usual cause\" and prescribe re-running finish — and\n * when the marker had come from AUTHOR TEXT instead (a `|` in a summary, from a TypeScript union or a\n * regex alternation), finish re-rendered the identical character from the unchanged `summary.json` and\n * landing refused again: a loop costing a CI cycle per turn, escapable only by guessing that one\n * character in your prose was the problem. `Dashboard.gitLogSafe` now substitutes both markers at the\n * render exit, so a freshly-rendered body cannot reach here at all — which leaves a HAND-EDITED\n * description and a genuinely old PR as the two remaining causes, and this says so.\n */\n private descriptionUnfitForGitLog(ref: PrIdentity, marker: string): InformAiError {\n return new InformAiError(\n '\\n' + SEP + `❌ PR #${ref.number}'s description is not a git-log commit body\\n` + SEP + '\\n' +\n `It contains ${marker}, which the compact body rendered by \\`pnpm wp-finish-upsert-pr\\` never\\n` +\n 'does — it substitutes both markers as it renders — so these bytes are not the gated summary,\\n' +\n 'and landing them would put a PR Gate Dashboard (or hand-written markdown) into main\\'s\\n' +\n 'history permanently.\\n\\n' +\n 'There are two causes, and they need different fixes:\\n\\n' +\n ' 1. The description was EDITED BY HAND on GitHub after finish posted it. Re-running finish\\n' +\n ' overwrites that edit with the compact body, so landing works.\\n' +\n ' 2. The PR was posted by a webpieces release OLDER than the one that made the description\\n' +\n ' the commit body, so it is still the full dashboard. The dashboard now lives in the PR\\'s\\n' +\n ' 1st comment instead, and re-running finish moves it there.\\n\\n' +\n `Either way the cure is the same, and it does NOT require removing ${marker.trim()} from your PR\\n` +\n 'summary text — a pipe or a heading in a summary is rendered safe, not rejected:\\n' +\n ' pnpm wp-start-upsert-pr && pnpm wp-review-upsert-pr && pnpm wp-finish-upsert-pr\\n' + SEP,\n );\n }\n\n /**\n * The landed branch's post-merge bookkeeping — but ONLY when this tree's `<branch>` IS the commit\n * that was squashed.\n *\n * The fact being tested is \"does this working tree hold the objects the PR merged\", and the PR\n * answers it authoritatively: `headRefOid` is the tip GitHub squashed. A second clone's `<branch>`\n * is a different commit, so `archive/<date>/<branch>` there would tag the wrong tip under the right\n * name; `merge-info/staged/<feature>` lives in the posting tree's state, not ours; and the worktree\n * to reap is not this one. So the merge stands and the bookkeeping is declined ALOUD.\n *\n * This used to be read out of an `origin.json` sidecar recording which tree posted the PR. Comparing\n * SHAs is strictly better: it is a fact rather than a recorded claim, it needs no stored state, and\n * it is more precise in both directions — a second clone sitting on the SAME commit can safely\n * archive it, and a tree that has committed further work since finish ran correctly declines.\n */\n private async bookkeeping(\n repoRoot: string, base: string, ref: PrIdentity, retention: string, cwd: string,\n ): Promise<string> {\n const tree = await this.landedTree.resolve(repoRoot, base, ref.headRefOid);\n if (!tree.bookkeepingAllowed) return this.notTheLandedTipNotice(base, tree, ref);\n return await this.archiveAndPromote(repoRoot, base, ref, retention)\n + await this.nextStep(repoRoot, tree, cwd);\n }\n\n /**\n * What was skipped, why, and what the two SHAs are — so the reader can tell WHICH cause it was.\n *\n * Two causes, one message, because the cure is the same for both: the objects the PR squashed are not\n * in this repo under that name, so nothing here may archive them or reap a tree for them.\n */\n private notTheLandedTipNotice(base: string, tree: LandedTree, ref: PrIdentity): string {\n const found = tree.kind === LANDED_TREE_ABSENT\n ? ` ${base} is not in this repo at all\\n`\n : ` ${base} here → ${tree.localSha}\\n`;\n return '\\n ⚠️ Archive + worktree cleanup SKIPPED — nothing here holds the commit that landed:\\n' +\n found +\n ` PR #${ref.number} squashed → ${ref.headRefOid}\\n` +\n ' Archiving from here would tag the wrong objects under the right name, and the\\n' +\n ` merge-info record and (if any) the worktree holding ${base} live with the other tip.\\n` +\n ' Either this is a second clone of the repo — finish the bookkeeping in the clone that\\n' +\n ' posted the PR with `pnpm wp-cleanup` — or that tree has commits made after\\n' +\n ' `pnpm wp-finish-upsert-pr` ran, which the PR does not contain.\\n';\n }\n\n /**\n * What happens next — which is NOT the same act when you landed from a worktree.\n *\n * Landing from a linked worktree always used to leave a corpse: the merged branch is checked out\n * here, so `git branch -D` refuses, `wp-cleanup`'s branch pass spares it as in-use, and nothing\n * removed the worktree — so the pair sat there until branch-creation-guard hit its cap. #512 made\n * worktrees reapable and printed `cd <primary> && pnpm wp-cleanup`; that instruction was correct\n * and it was the most-skipped step in the flow, because the PR is already landed and the work\n * feels done.\n *\n * So the reap is no longer an instruction. This command still refuses to remove the directory it\n * is standing in — that rail is untouched — and instead HANDS THE REAP to a child process rooted\n * in the primary clone, which is a tree nobody is deleting. See LandedWorktreeReaper. When that\n * hand-off is not safely achievable the #512 notice is printed unchanged, because an honest\n * limitation beats a command that deletes its own working directory mid-run.\n */\n private async nextStep(repoRoot: string, tree: LandedTree, cwd: string): Promise<string> {\n const handoff: WorktreeReapHandoff | null\n = this.landedWorktree.plan(repoRoot, tree.worktree, cwd);\n if (handoff === null) return ' Next: `pnpm wp-cleanup` to delete the merged branch.\\n';\n if (!handoff.canReap) return this.landedWorktree.manualNotice(handoff);\n return this.landedWorktree.handOff(handoff);\n }\n\n /**\n * The landed branch's post-merge bookkeeping, in one place:\n * 1. ARCHIVE the pre-squash tip as `archive/<date>/<branch>` — the tag makes the original history\n * permanently restorable (`git checkout -b <branch> <tag>` gives back the exact objects) while\n * costing one ref, so the branch itself no longer has to survive as a `*PreMerge` husk that\n * counts toward the branch cap. See BranchArchiver for why a tag beats a patch or the reflog.\n * 2. PROMOTE `merge-info/staged/<feature>/` to `merge-info/merged/<feature>/` and rebuild\n * `index.json`, so `staged/` holds only branches that are still in flight.\n *\n * Never throws: the PR is already merged by the time we get here, and failing the command after a\n * successful merge would report a landed PR as a failure. Problems are reported in the recap.\n */\n private async archiveAndPromote(repoRoot: string, base: string, ref: PrIdentity, retention: string): Promise<string> {\n if (retention === BRANCH_RETENTION_KEEP) return ' Branch retention is \"keep\" — nothing archived.\\n';\n\n let line = '';\n let tag = '';\n if (retention === BRANCH_RETENTION_ARCHIVE_TAG) {\n const archive = await this.archiver.archive(repoRoot, base);\n tag = archive.tag;\n line = archive.ok\n ? ` Archived ${base} → ${archive.tag} (restore: ${this.archiver.restoreCommand(base, archive.tag)})\\n`\n : ` ⚠️ Could not archive ${base}: ${archive.error} — the branch was left alone.\\n`;\n }\n\n const feature = await this.aiBranchName.getFeatureName();\n const record = new ArchiveRecord(\n tag, await this.revParse(repoRoot, base), await this.revParse(repoRoot, 'origin/main'),\n Number(ref.number), new Date().toISOString(),\n );\n if (this.mergeInfoIndex.promoteToMerged(repoRoot, feature, record)) {\n line += ` merge-info: staged/${feature} → merged/${feature} (index.json rebuilt)\\n`;\n }\n return line;\n }\n\n // Best-effort sha of a ref — '' when it cannot resolve. Recorded in archive.json for provenance.\n private async revParse(repoRoot: string, ref: string): Promise<string> {\n const result = await this.git.run(['rev-parse', ref], repoRoot);\n return result.ok ? result.stdout.trim() : '';\n }\n\n // `git branch --show-current` in the invocation directory. Must succeed: a branch we cannot read is\n // not a selector to guess at.\n private async currentBranch(cwd: string): Promise<string> {\n const result = await this.git.run(['branch', '--show-current'], cwd);\n if (!result.ok) {\n throw new InformAiError(`Could not read the current branch in ${cwd} (git branch --show-current): ${result.stderr.trim()}`);\n }\n return result.stdout.trim();\n }\n\n /**\n * Everything landing needs about the PR, in ONE `gh` read: number, title, URL, DESCRIPTION and the\n * head sha GitHub is squashing. `null` when there is no open PR for this head branch.\n *\n * The TITLE comes from the PR itself, not summary.json, so the squash subject matches what a reviewer\n * approved even if summary.json was edited afterwards. The BODY is the gated commit body (see the\n * class doc). `headRefOid` is read BEFORE the merge, because it is what the bookkeeping check\n * compares against and the merge is what makes the branch's fate uninteresting to GitHub.\n */\n private async readPr(selector: string): Promise<PrIdentity | null> {\n const result = await this.processes.run(\n 'gh', ['pr', 'view', selector, '--json', 'number,title,url,body,headRefOid,headRefName'],\n );\n if (!result.ok) return null;\n return this.parsePr(result.stdout);\n }\n\n // `gh --json` output → PrIdentity. Malformed/absent JSON reads as \"no PR\", which the caller turns\n // into the same refusal a missing PR gets: both mean nothing here can be landed.\n private parsePr(stdout: string): PrIdentity | null {\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: unparseable gh output means \"no PR\", never a crash\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n // webpieces-disable no-any-unknown -- gh's JSON is opaque until narrowed field-by-field below\n const raw = JSON.parse(stdout) as Record<string, unknown>;\n const number = typeof raw['number'] === 'number' ? String(raw['number']) : this.str(raw['number']);\n if (number === '') return null;\n // GitHub stores descriptions with CRLF. A commit body must not carry them, and the bytes are\n // otherwise identical to what finish rendered, so the line endings are normalized back here.\n const body = this.str(raw['body']).replace(/\\r\\n/g, '\\n').trim();\n return new PrIdentity(\n number, this.str(raw['title']), this.str(raw['url']), body === '' ? '' : body + '\\n',\n this.str(raw['headRefOid']), this.str(raw['headRefName']),\n );\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n return null;\n }\n }\n\n // webpieces-disable no-any-unknown -- one opaque JSON field, narrowed to string\n private str(value: unknown): string {\n return typeof value === 'string' ? value : '';\n }\n}\n\n// The open PR as GitHub holds it: its number, title, web URL, DESCRIPTION (= the gated commit body) and\n// the PAIR that identifies its tree locally — the head branch's name and the commit being squashed.\nclass PrIdentity {\n number: string;\n title: string;\n url: string;\n body: string;\n headRefOid: string;\n /**\n * The PR's head BRANCH. Required alongside `headRefOid` because neither half identifies a tree on its\n * own: the name is what a worktree list can be searched by, the sha is what makes a hit the right\n * one. It also frees `--pr <n>` from needing the operator to be standing anywhere in particular.\n */\n headRefName: string;\n\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(\n number: string, title: string, url: string, body: string, headRefOid: string, headRefName: string,\n ) {\n this.number = number;\n this.title = title;\n this.url = url;\n this.body = body;\n this.headRefOid = headRefOid;\n this.headRefName = headRefName;\n }\n}\n\n/**\n * Data-only (per CLAUDE.md, classes for data): what the operator asked `wp-land-pr` to land.\n *\n * `prNumber` is '' for the zero-arg form — \"this branch's PR\" — which stays the shorthand the worker\n * uses. It is NOT an optional constructor parameter with a default at the call site: `wp-land-pr.ts`\n * builds exactly one of these from the parsed argv, so there is one spelling of the decision.\n */\nexport class LandPrRequest {\n /**\n * Was `--pr` on the command line at all? Kept SEPARATE from the value because `--pr` with no number\n * is a mistake, not a request to guess: collapsing the two would silently land whatever PR the\n * current directory's branch happens to have, which is the opposite of what the operator typed.\n */\n prFlagPresent: boolean;\n /** The `--pr <n>` value verbatim, or '' to infer the PR from the invocation directory's branch. */\n prNumber: string;\n\n constructor(prFlagPresent: boolean, prNumber: string) {\n this.prFlagPresent = prFlagPresent;\n this.prNumber = prNumber;\n }\n}\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { GitProcessApi } from '@webpieces/tooling-common';
|
|
1
2
|
import { UntrackedFiles } from './working-tree-gate';
|
|
2
3
|
/** One git invocation's exit status and the output it produced, for a caller that must decide on it. */
|
|
3
4
|
export declare class GitRun {
|
|
@@ -47,6 +48,8 @@ export declare class StashedFiles {
|
|
|
47
48
|
* is decided from their text, and they are the two that render live progress, which a pipe flattens.
|
|
48
49
|
*/
|
|
49
50
|
export declare class MainCheckout {
|
|
51
|
+
private readonly git;
|
|
52
|
+
constructor(git: GitProcessApi);
|
|
50
53
|
/**
|
|
51
54
|
* Fetch, check out main, fast-forward it. Returns the files that had to be stashed to get there —
|
|
52
55
|
* empty in the ordinary case.
|
|
@@ -56,7 +59,7 @@ export declare class MainCheckout {
|
|
|
56
59
|
* the whole point of this command is that it is safe to run without thinking. A refusal to
|
|
57
60
|
* fast-forward is a real condition a human should see and decide about.
|
|
58
61
|
*/
|
|
59
|
-
goToMain(repoRoot: string, untracked: UntrackedFiles): StashedFiles
|
|
62
|
+
goToMain(repoRoot: string, untracked: UntrackedFiles): Promise<StashedFiles>;
|
|
60
63
|
private checkoutMain;
|
|
61
64
|
/**
|
|
62
65
|
* Only the collision git NAMES, and only when there is something a stash could actually take.
|