@webpieces/pr-gate 0.4.976 → 0.4.977

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/package.json +6 -6
  2. package/src/scripts/commands/cleanup-command.js +12 -12
  3. package/src/scripts/commands/cleanup-command.js.map +1 -1
  4. package/src/scripts/commands/human-post-pr-command.js +1 -1
  5. package/src/scripts/commands/human-post-pr-command.js.map +1 -1
  6. package/src/scripts/commands/land-pr-command.js +1 -1
  7. package/src/scripts/commands/land-pr-command.js.map +1 -1
  8. package/src/scripts/commands/reap-worktree-command.js +4 -5
  9. package/src/scripts/commands/reap-worktree-command.js.map +1 -1
  10. package/src/scripts/commands/review-upsert-pr-command.js +1 -1
  11. package/src/scripts/commands/review-upsert-pr-command.js.map +1 -1
  12. package/src/scripts/commands/start-upsert-pr-command.js +1 -1
  13. package/src/scripts/commands/start-upsert-pr-command.js.map +1 -1
  14. package/src/scripts/commands/sync-main-command.js +4 -4
  15. package/src/scripts/commands/sync-main-command.js.map +1 -1
  16. package/src/scripts/commands/worktree-cleanup.d.ts +4 -4
  17. package/src/scripts/commands/worktree-cleanup.js +4 -4
  18. package/src/scripts/commands/worktree-cleanup.js.map +1 -1
  19. package/src/scripts/workflow/checklist-detector.d.ts +2 -2
  20. package/src/scripts/workflow/checklist-detector.js +4 -4
  21. package/src/scripts/workflow/checklist-detector.js.map +1 -1
  22. package/src/scripts/workflow/checklist-scanner.js +3 -3
  23. package/src/scripts/workflow/checklist-scanner.js.map +1 -1
  24. package/src/scripts/workflow/merge-end.d.ts +3 -2
  25. package/src/scripts/workflow/merge-end.js +6 -3
  26. package/src/scripts/workflow/merge-end.js.map +1 -1
  27. package/src/scripts/workflow/pr-context-writer.d.ts +1 -1
  28. package/src/scripts/workflow/pr-context-writer.js +3 -3
  29. package/src/scripts/workflow/pr-context-writer.js.map +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webpieces/pr-gate",
3
- "version": "0.4.976",
3
+ "version": "0.4.977",
4
4
  "description": "Gated PR system: 3-point squash-merge, merge validation gate, and red/yellow/green PR dashboard. Standalone scripts, no Nx dependency required.",
5
5
  "type": "commonjs",
6
6
  "main": "./src/index.js",
@@ -16,18 +16,18 @@
16
16
  },
17
17
  "dependencies": {
18
18
  "@inversifyjs/binding-decorators": "1.1.5",
19
- "@webpieces/hook-runtime": "0.4.976",
20
- "@webpieces/rules-config": "0.4.976",
19
+ "@webpieces/hook-runtime": "0.4.977",
20
+ "@webpieces/rules-config": "0.4.977",
21
21
  "inversify": "7.10.4",
22
22
  "reflect-metadata": "0.2.2",
23
- "@webpieces/tooling-common": "0.4.976",
24
- "@webpieces/repo-workflow-core": "0.4.976"
23
+ "@webpieces/tooling-common": "0.4.977",
24
+ "@webpieces/repo-workflow-core": "0.4.977"
25
25
  },
26
26
  "publishConfig": {
27
27
  "access": "public"
28
28
  },
29
29
  "devDependencies": {
30
- "@webpieces/tooling-testkit": "0.4.976"
30
+ "@webpieces/tooling-testkit": "0.4.977"
31
31
  },
32
32
  "types": "./src/index.d.ts",
33
33
  "bin": {
@@ -110,7 +110,7 @@ let CleanupCommand = class CleanupCommand {
110
110
  const repoRoot = this.repoRootFinder.resolveRepoRoot(process.cwd());
111
111
  const retention = (0, rules_config_1.loadAndValidate)(repoRoot).prGate.landPr.branchRetention;
112
112
  if (options.report) {
113
- this.reportOnly(repoRoot, retention, options);
113
+ await this.reportOnly(repoRoot, retention, options);
114
114
  return;
115
115
  }
116
116
  await this.cleanUpWorktrees(repoRoot, retention, options);
@@ -123,9 +123,9 @@ let CleanupCommand = class CleanupCommand {
123
123
  * because a run that deletes nothing cannot renumber anything. That is what makes it the honest
124
124
  * first half of `--report` → read the numbers → `--delete-branches=1,3`.
125
125
  */
126
- reportOnly(repoRoot, retention, options) {
126
+ async reportOnly(repoRoot, retention, options) {
127
127
  process.stdout.write('\n' + SEP + '🔎 wp-cleanup --report — nothing will be deleted\n' + SEP);
128
- const verdicts = this.worktreeSection.verdicts(repoRoot, options.ignoreStaleLocks);
128
+ const verdicts = await this.worktreeSection.verdicts(repoRoot, options.ignoreStaleLocks);
129
129
  const deadTrees = this.worktreeSection.provablyDead(verdicts);
130
130
  process.stdout.write(this.wouldReapBlock(WORKTREE_KINDS, deadTrees.map((tree) => `${tree.path} — ${tree.reason}`)));
131
131
  const treePromptable = this.worktreeSection.promptable(verdicts);
@@ -141,7 +141,7 @@ let CleanupCommand = class CleanupCommand {
141
141
  // lands in `spared`, nothing is touched. That is exactly what a report needs, and it means
142
142
  // the classified block below is computed by the identical code path a real run uses, so the
143
143
  // numbering it prints IS the numbering the flag will act on.
144
- const branches = this.branchReaper.reap(repoRoot, 'wp-cleanup', null, repo_workflow_core_1.BRANCH_RETENTION_KEEP).spared;
144
+ const branches = (await this.branchReaper.reap(repoRoot, 'wp-cleanup', null, repo_workflow_core_1.BRANCH_RETENTION_KEEP)).spared;
145
145
  process.stdout.write(this.wouldReapBlock(BRANCH_KINDS, branches
146
146
  .filter((entry) => AUTO_REAPED_CLASSIFICATIONS.includes(entry.classification))
147
147
  .map((entry) => `${entry.branch} — ${entry.reason}`)));
@@ -167,7 +167,7 @@ let CleanupCommand = class CleanupCommand {
167
167
  async cleanUpBranches(repoRoot, retention, options) {
168
168
  // No cache argument: wp-cleanup recomputes the verdicts itself. The file on disk is allowed to
169
169
  // go stale, and stale evidence is fine for BLOCKING but never for DELETING.
170
- const result = this.branchReaper.reap(repoRoot, 'wp-cleanup', null, retention);
170
+ const result = await this.branchReaper.reap(repoRoot, 'wp-cleanup', null, retention);
171
171
  const first = this.report(repoRoot, result);
172
172
  process.stdout.write(first);
173
173
  const promptable = this.promptable(result.spared);
@@ -178,7 +178,7 @@ let CleanupCommand = class CleanupCommand {
178
178
  options.branches.pick(block);
179
179
  if (husks.length > 0) {
180
180
  process.stdout.write(this.huskBlock(BRANCH_KINDS, husks.map((entry) => entry.branch)));
181
- process.stdout.write(this.report(repoRoot, this.branchReaper.reapApproved(repoRoot, 'wp-cleanup', husks, retention)));
181
+ process.stdout.write(this.report(repoRoot, await this.branchReaper.reapApproved(repoRoot, 'wp-cleanup', husks, retention)));
182
182
  }
183
183
  if (block.length === 0) {
184
184
  if (first === '' && husks.length === 0)
@@ -191,7 +191,7 @@ let CleanupCommand = class CleanupCommand {
191
191
  process.stdout.write(`\nNothing else deleted — the ${String(block.length)} ${BRANCH_KINDS} above were kept.\n`);
192
192
  return;
193
193
  }
194
- process.stdout.write(this.report(repoRoot, this.branchReaper.reapApproved(repoRoot, 'wp-cleanup', approved, retention)));
194
+ process.stdout.write(this.report(repoRoot, await this.branchReaper.reapApproved(repoRoot, 'wp-cleanup', approved, retention)));
195
195
  }
196
196
  /**
197
197
  * Reap the provably-dead worktrees and the zero-commit husks, then decide about the rest.
@@ -202,22 +202,22 @@ let CleanupCommand = class CleanupCommand {
202
202
  * cleanup command becomes a data-loss command).
203
203
  */
204
204
  async cleanUpWorktrees(repoRoot, retention, options) {
205
- const verdicts = this.worktreeSection.verdicts(repoRoot, options.ignoreStaleLocks);
205
+ const verdicts = await this.worktreeSection.verdicts(repoRoot, options.ignoreStaleLocks);
206
206
  const dead = this.worktreeSection.provablyDead(verdicts);
207
207
  if (dead.length > 0) {
208
- process.stdout.write(this.worktreeSection.report(repoRoot, this.worktreeSection.reap(repoRoot, 'wp-cleanup', dead, retention)));
208
+ process.stdout.write(this.worktreeSection.report(repoRoot, await this.worktreeSection.reap(repoRoot, 'wp-cleanup', dead, retention)));
209
209
  }
210
210
  process.stdout.write(this.worktreeSection.sparedBlock(verdicts, dead));
211
211
  const promptable = this.worktreeSection.promptable(verdicts);
212
212
  // A zero-commit worktree is a husk ONLY if nobody is holding it. Uncommitted or untracked
213
213
  // files are the one thing that says "somebody is", and they are the one thing no archive tag
214
214
  // can bring back — so they are checked here rather than left to git's refusal at removal time.
215
- const husks = this.worktreeSection.withoutUncommitted(this.husks(promptable));
215
+ const husks = await this.worktreeSection.withoutUncommitted(this.husks(promptable));
216
216
  const block = this.rest(promptable, husks);
217
217
  options.worktrees.pick(block);
218
218
  if (husks.length > 0) {
219
219
  process.stdout.write(this.huskBlock(WORKTREE_KINDS, husks.map((tree) => `${tree.path} [${tree.branch}]`)));
220
- process.stdout.write(this.worktreeSection.report(repoRoot, this.worktreeSection.reap(repoRoot, 'wp-cleanup', husks, retention)));
220
+ process.stdout.write(this.worktreeSection.report(repoRoot, await this.worktreeSection.reap(repoRoot, 'wp-cleanup', husks, retention)));
221
221
  }
222
222
  if (block.length === 0)
223
223
  return;
@@ -227,7 +227,7 @@ let CleanupCommand = class CleanupCommand {
227
227
  process.stdout.write(`\nNothing else removed — the ${String(block.length)} ${WORKTREE_KINDS} above were kept.\n`);
228
228
  return;
229
229
  }
230
- process.stdout.write(this.worktreeSection.report(repoRoot, this.worktreeSection.reap(repoRoot, 'wp-cleanup', approved, retention)));
230
+ process.stdout.write(this.worktreeSection.report(repoRoot, await this.worktreeSection.reap(repoRoot, 'wp-cleanup', approved, retention)));
231
231
  }
232
232
  // What a bare run with an empty repo says. It points at --help because the flags are the whole
233
233
  // reason a caller who DOES have something to say never has to be prompted.
@@ -1 +1 @@
1
- {"version":3,"file":"cleanup-command.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/commands/cleanup-command.ts"],"names":[],"mappings":";;;;AAAA,2DAAqC;AACrC,sEAAia;AACja,0DAA0E;AAC1E,yCAA2D;AAE3D,yDAA4D;AAC5D,uDAK2B;AAE3B,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAEvE,sGAAsG;AACtG,8FAA8F;AAC9F,MAAM,WAAW,GAAG,QAAQ,CAAC;AAC7B,MAAM,YAAY,GAAG,UAAU,CAAC;AAChC,MAAM,aAAa,GAAG,UAAU,CAAC;AACjC,MAAM,cAAc,GAAG,WAAW,CAAC;AAEnC,mGAAmG;AACnG,oGAAoG;AACpG,MAAM,2BAA2B,GAAsB;IACnD,6CAAwB;IACxB,oDAA+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AAQ,CAAC,eAAe,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;QACtF,OAAO,IAAI,OAAO,CAAS,CAAC,OAAgC,EAAQ,EAAE;YAClE,EAAE,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,MAAc,EAAQ,EAAE;gBACzC,EAAE,CAAC,KAAK,EAAE,CAAC;gBACX,OAAO,CAAC,MAAM,CAAC,CAAC;YACpB,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC;CACJ,CAAA;AA9WY,wCAAc;yBAAd,cAAc;IAD1B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGA,6BAAc;QAChB,iCAAY;QAChB,mCAAc;QACP,yCAAsB;QAI1B,sCAAiB;GAT1C,cAAc,CA8W1B","sourcesContent":["import * as readline from 'readline';\nimport { BranchArchiver, BranchMutationLog, BranchReaper, DeletableBranch, DeletableWorktree, ReapResult, ReapedBranch, BRANCH_RETENTION_KEEP, CLASSIFICATION_SUPERSEDED, CLASSIFICATION_CONTENT_IN_MAIN, CLASSIFICATION_NEVER_PROPOSED, CLASSIFICATION_NO_COMMITS, CLASSIFICATION_MERGED_PR, CLASSIFICATION_BACKUP_OF_MERGED, CLASSIFICATION_BACKUP_OF_LIVE, ADJUDICATED_CLASSIFICATIONS } from '@webpieces/repo-workflow-core';\nimport { RepoRootFinder, loadAndValidate } from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\n\nimport { WorktreeCleanupSection } from './worktree-cleanup';\nimport {\n CleanupOptions,\n DeleteSelection,\n FLAG_DELETE_BRANCHES,\n FLAG_DELETE_WORKTREES,\n} from './cleanup-options';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n// Singular / plural as a pair, because every one of these strings is read by a human deciding whether\n// to delete something and `branch(s)` reads as a typo in the middle of exactly that sentence.\nconst BRANCH_KIND = 'branch';\nconst BRANCH_KINDS = 'branches';\nconst WORKTREE_KIND = 'worktree';\nconst WORKTREE_KINDS = 'worktrees';\n\n// The verdicts that reap themselves — a merged PR, or a snapshot of a ref that still exists. Named\n// here only so `--report` can SAY what a real run would take; the reaping itself is BranchReaper's.\nconst AUTO_REAPED_CLASSIFICATIONS: readonly string[] = [\n CLASSIFICATION_MERGED_PR,\n CLASSIFICATION_BACKUP_OF_MERGED,\n CLASSIFICATION_BACKUP_OF_LIVE,\n];\n\n// One line of human-facing explanation per promptable classification, ordered most-safe first. These\n// replace the single string `no merged PR found — a human must decide`, which covered all three of\n// these situations identically and so told a human nothing they could act on.\n//\n// CLASSIFICATION_NO_COMMITS has no entry and needs none: a zero-commit ref never reaches this block\n// any more — it is reaped on sight (see `husks`). A worktree spared for holding uncommitted work is\n// reported by the worktree section, with that as its reason, rather than offered as a question.\nconst CLASSIFICATION_HEADINGS: Readonly<Record<string, string>> = {\n [CLASSIFICATION_SUPERSEDED]:\n 'SUPERSEDED — the PR was closed WITHOUT merging and later PRs have merged since. Near-certainly\\n'\n + ' the abandoned first attempt at work that landed under a different number. Safest group to delete.',\n [CLASSIFICATION_CONTENT_IN_MAIN]:\n 'CONTENT ALREADY IN MAIN — every commit has a patch-equivalent in origin/main (git cherry).\\n'\n + ' The work is not unique to this branch; only the commit objects are.',\n [CLASSIFICATION_NEVER_PROPOSED]:\n 'NEVER PROPOSED — no PR was ever opened, and these commits may be the ONLY copy in existence.\\n'\n + ' Read the unique-commit counts before answering. This is the group to say no to if unsure.',\n};\n\n/**\n * wp-cleanup: remove the dead WORKTREES, delete the local branches whose PR is already MERGED, REAP\n * THE ZERO-COMMIT HUSKS, then report everything that is left with the exact command that takes it.\n *\n * ─── WHY A ZERO-COMMIT REF IS REAPED AND NOT ASKED ABOUT ─────────────────────────────────────────\n * A ref with 0 unique commits is byte-identical to origin/main. Deleting it loses a NAME, not a\n * commit — and the name comes back with one `git checkout -b`, or from the archive tag this writes\n * first. It was previously PROMPTED about, for one real reason: a WORKING TREE looks exactly like\n * that husk from `git worktree add -b` until its first commit, i.e. for exactly the window an agent\n * is working in it. But that case is DETECTABLE, and detecting it is cheaper than asking a human:\n *\n * · the worktree holds uncommitted or untracked files (`git status --porcelain`) — spared, said out loud\n * · the worktree is LOCKED and that lock still stands — a reason naming somebody other than the\n * Claude Code harness, or a harness lock whose agent the harness itself still reports as\n * mid-tool-call — spared by the verdicts before it ever reaches here (see WorktreeLockVerdicts;\n * the pid in a harness lock reason proves nothing, it is the shared session process)\n * · it is the tree we are standing in, or a detached HEAD — spared, likewise\n *\n * So the bar moved from \"prove it is dead\" to \"prove somebody is holding it\", deliberately, because\n * the cost of being wrong is a re-`checkout -b` and the cost of being cautious was a prompt that\n * stopped a human's terminal to adjudicate two refs that could not possibly hold work. Refs that DO\n * carry unique commits keep every bit of the old caution.\n *\n * ─── WHY FLAGS, AND WHY THEY BEAT THE TTY SNIFF ──────────────────────────────────────────────────\n * `process.stdin.isTTY !== true` used to be the whole basis for \"is a human standing here?\", and it\n * is a proxy, not a fact: a human running `pnpm wp-cleanup | tee log` has no tty, an agent on a pty\n * has one. The sniff stays as the DEFAULT selector; `--delete-branches` / `--delete-worktrees` /\n * `--interactive` / `--report` let the caller who KNOWS say so, and an explicit flag always wins.\n * `--ignore-stale-locks` is the same idea for the OTHER thing this command could not previously be\n * told: that a standing claude-agent lock is stale. It replaces the `git worktree unlock` a human had\n * to run per directory — seven times, in the incident that produced it — before wp-cleanup would do\n * its job. A dirty worktree and a genuinely live agent's are still spared under it.\n *\n * ─── WHY A NON-TTY RUN NOW DELETES NOTHING IT WAS NOT ASKED TO ───────────────────────────────────\n * It used to silently take the \"redundant\" groups and print a bare list of names it left. That is\n * strictly less than the human sees, and — worse — it broke the one invariant that makes numeric\n * selection safe: THE NUMBERS IN THE FLAG ARE THE NUMBERS JUST PRINTED. A run that deletes half of a\n * numbered list renumbers the rest, so the `--delete-branches=3,4` it printed would land on entries\n * 5 and 6 next time. So the unattended path now prints the IDENTICAL numbered, classified block a\n * human sees plus the exact command that takes it, and takes nothing from that block itself. The\n * husks it does reap are never IN the block, so reaping them cannot shift a single number.\n *\n * All the danger still lives in the verdicts, not here — see BranchReaper for why every automatically\n * deleted branch is recoverable, and note that EVERY delete on every path here archives first.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class CleanupCommand {\n constructor(\n private readonly repoRootFinder: RepoRootFinder,\n private readonly branchReaper: BranchReaper,\n private readonly archiver: BranchArchiver,\n private readonly worktreeSection: WorktreeCleanupSection,\n // The log path is COMPUTED, never restated. It is per-worktree, so the relative literal these\n // messages used to carry named a file that does not exist in a linked worktree — the reader\n // greps nothing and reads the silence as \"nothing was deleted\".\n private readonly mutationLog: BranchMutationLog,\n ) {}\n\n /**\n * WORKTREES FIRST, then branches. The order is the fix, not a detail: a worktree HOLDS its branch,\n * so that branch is spared `in-use` (\"remove that worktree before deleting the branch\") and nothing\n * used to remove the worktree — so both piled up until branch-creation-guard refused to make the\n * next one. Reaping the worktree takes its branch with it, and the branch pass then recomputes its\n * verdicts from scratch against the post-removal truth.\n */\n async run(options: CleanupOptions): Promise<void> {\n const repoRoot = this.repoRootFinder.resolveRepoRoot(process.cwd());\n const retention = loadAndValidate(repoRoot).prGate.landPr.branchRetention;\n if (options.report) {\n this.reportOnly(repoRoot, retention, options);\n return;\n }\n await this.cleanUpWorktrees(repoRoot, retention, options);\n await this.cleanUpBranches(repoRoot, retention, options);\n }\n\n /**\n * `--report`: the whole classified picture, and NOT ONE DELETE.\n *\n * This is the only run whose numbers are guaranteed still valid when the next command starts,\n * because a run that deletes nothing cannot renumber anything. That is what makes it the honest\n * first half of `--report` → read the numbers → `--delete-branches=1,3`.\n */\n private reportOnly(repoRoot: string, retention: string, options: CleanupOptions): void {\n process.stdout.write('\\n' + SEP + '🔎 wp-cleanup --report — nothing will be deleted\\n' + SEP);\n\n const verdicts = this.worktreeSection.verdicts(repoRoot, options.ignoreStaleLocks);\n const deadTrees = this.worktreeSection.provablyDead(verdicts);\n process.stdout.write(this.wouldReapBlock(\n WORKTREE_KINDS, deadTrees.map((tree: DeletableWorktree): string => `${tree.path} — ${tree.reason}`)));\n const treePromptable = this.worktreeSection.promptable(verdicts);\n const treeHusks = this.husks(treePromptable);\n process.stdout.write(this.wouldReapBlock(`zero-commit ${WORKTREE_KINDS}`,\n treeHusks.map((tree: DeletableWorktree): string => `${tree.path} [${tree.branch}]`)));\n process.stdout.write(this.worktreeSection.sparedBlock(verdicts, deadTrees));\n const treeBlock = this.rest(treePromptable, treeHusks);\n if (treeBlock.length > 0) {\n process.stdout.write(this.worktreeSection.promptBlock(treeBlock));\n process.stdout.write(this.flagHint(repoRoot, WORKTREE_KINDS, FLAG_DELETE_WORKTREES, treeBlock.length));\n }\n\n // Retention 'keep' turns BranchReaper.reap into a pure verdict computation — every branch\n // lands in `spared`, nothing is touched. That is exactly what a report needs, and it means\n // the classified block below is computed by the identical code path a real run uses, so the\n // numbering it prints IS the numbering the flag will act on.\n const branches = this.branchReaper.reap(repoRoot, 'wp-cleanup', null, BRANCH_RETENTION_KEEP).spared;\n process.stdout.write(this.wouldReapBlock(BRANCH_KINDS, branches\n .filter((entry: DeletableBranch): boolean =>\n AUTO_REAPED_CLASSIFICATIONS.includes(entry.classification))\n .map((entry: DeletableBranch): string => `${entry.branch} — ${entry.reason}`)));\n const promptable = this.promptable(branches);\n const husks = this.husks(promptable);\n process.stdout.write(this.wouldReapBlock(`zero-commit ${BRANCH_KINDS}`,\n husks.map((entry: DeletableBranch): string => entry.branch)));\n const block = this.rest(promptable, husks);\n if (block.length > 0) {\n process.stdout.write(this.classifiedBlock(block));\n process.stdout.write(this.flagHint(repoRoot, BRANCH_KINDS, FLAG_DELETE_BRANCHES, block.length));\n }\n process.stdout.write(`\\nNothing was deleted (--report). Retention policy in effect: ${retention}.\\n`\n + 'Re-run without --report to act, or with the flags above to say exactly what to take.\\n');\n }\n\n private wouldReapBlock(kinds: string, lines: string[]): string {\n if (lines.length === 0) return '';\n let out = `\\nWould reap ${String(lines.length)} ${kinds} — no question asked, each archived first:\\n`;\n for (const line of lines) out += ` ✓ ${line}\\n`;\n return out;\n }\n\n private async cleanUpBranches(repoRoot: string, retention: string, options: CleanupOptions): Promise<void> {\n // No cache argument: wp-cleanup recomputes the verdicts itself. The file on disk is allowed to\n // go stale, and stale evidence is fine for BLOCKING but never for DELETING.\n const result = this.branchReaper.reap(repoRoot, 'wp-cleanup', null, retention);\n const first = this.report(repoRoot, result);\n process.stdout.write(first);\n\n const promptable = this.promptable(result.spared);\n const husks = this.husks(promptable);\n const block = this.rest(promptable, husks);\n\n // Range-check the flag against the block BEFORE anything in this half is deleted, so a caller\n // holding stale numbers stops the run rather than half-executing it.\n options.branches.pick(block);\n\n if (husks.length > 0) {\n process.stdout.write(this.huskBlock(BRANCH_KINDS, husks.map(\n (entry: DeletableBranch): string => entry.branch)));\n process.stdout.write(this.report(repoRoot,\n this.branchReaper.reapApproved(repoRoot, 'wp-cleanup', husks, retention)));\n }\n\n if (block.length === 0) {\n if (first === '' && husks.length === 0) process.stdout.write(this.nothingToDo());\n return;\n }\n process.stdout.write(this.classifiedBlock(block));\n const approved = await this.decide(\n repoRoot, block, BRANCH_KIND, BRANCH_KINDS, FLAG_DELETE_BRANCHES, options.branches, options);\n if (approved.length === 0) {\n process.stdout.write(\n `\\nNothing else deleted — the ${String(block.length)} ${BRANCH_KINDS} above were kept.\\n`);\n return;\n }\n process.stdout.write(this.report(repoRoot,\n this.branchReaper.reapApproved(repoRoot, 'wp-cleanup', approved, retention)));\n }\n\n /**\n * Reap the provably-dead worktrees and the zero-commit husks, then decide about the rest.\n *\n * WorktreeReaper enforces the safety rails regardless of what is passed or answered: never the\n * primary clone, never the tree this command is running in, and never `--force` (git's refusal to\n * remove a worktree holding untracked or modified files is a feature, and forcing it is how a\n * cleanup command becomes a data-loss command).\n */\n private async cleanUpWorktrees(repoRoot: string, retention: string, options: CleanupOptions): Promise<void> {\n const verdicts = this.worktreeSection.verdicts(repoRoot, options.ignoreStaleLocks);\n const dead = this.worktreeSection.provablyDead(verdicts);\n if (dead.length > 0) {\n process.stdout.write(\n this.worktreeSection.report(repoRoot,\n this.worktreeSection.reap(repoRoot, 'wp-cleanup', dead, retention)));\n }\n process.stdout.write(this.worktreeSection.sparedBlock(verdicts, dead));\n\n const promptable = this.worktreeSection.promptable(verdicts);\n // A zero-commit worktree is a husk ONLY if nobody is holding it. Uncommitted or untracked\n // files are the one thing that says \"somebody is\", and they are the one thing no archive tag\n // can bring back — so they are checked here rather than left to git's refusal at removal time.\n const husks = this.worktreeSection.withoutUncommitted(this.husks(promptable));\n const block = this.rest(promptable, husks);\n\n options.worktrees.pick(block);\n\n if (husks.length > 0) {\n process.stdout.write(this.huskBlock(WORKTREE_KINDS, husks.map(\n (tree: DeletableWorktree): string => `${tree.path} [${tree.branch}]`)));\n process.stdout.write(\n this.worktreeSection.report(repoRoot,\n this.worktreeSection.reap(repoRoot, 'wp-cleanup', husks, retention)));\n }\n\n if (block.length === 0) return;\n process.stdout.write(this.worktreeSection.promptBlock(block));\n const approved = await this.decide(\n repoRoot, block, WORKTREE_KIND, WORKTREE_KINDS, FLAG_DELETE_WORKTREES, options.worktrees, options);\n if (approved.length === 0) {\n process.stdout.write(\n `\\nNothing else removed — the ${String(block.length)} ${WORKTREE_KINDS} above were kept.\\n`);\n return;\n }\n process.stdout.write(\n this.worktreeSection.report(repoRoot,\n this.worktreeSection.reap(repoRoot, 'wp-cleanup', approved, retention)));\n }\n\n // What a bare run with an empty repo says. It points at --help because the flags are the whole\n // reason a caller who DOES have something to say never has to be prompted.\n private nothingToDo(): string {\n return '\\nNothing else to decide. `pnpm wp-cleanup --help` lists every flag '\n + '(--report, --delete-branches, --delete-worktrees, --interactive).\\n';\n }\n\n private huskBlock(kinds: string, names: string[]): string {\n let out = '\\n' + SEP\n + `♻️ Reaping ${String(names.length)} zero-commit ${kinds} — 0 unique commits, identical to origin/main\\n`\n + SEP + '\\n'\n + 'Nothing is held here: no uncommitted files, no live lock, not the tree you are standing in.\\n'\n + 'Deleting one of these loses a NAME, not a commit — and the name is archived to a tag first.\\n\\n';\n for (const name of names) out += ` · ${name}\\n`;\n return out;\n }\n\n private report(repoRoot: string, result: ReapResult): string {\n const gone = result.alreadyGone.length;\n if (result.reaped.length === 0 && result.failed.length === 0 && gone === 0) return '';\n\n let out = '\\n' + SEP + `🧹 Cleaned up ${String(result.reaped.length)} dead local branch(es)\\n` + SEP + '\\n';\n for (const entry of result.reaped) out += this.reapedLine(entry);\n\n // Stated, not warned about. These branches ARE gone — the detached refresher's auto-reap\n // deleted and archived them moments before this pass reached them, which it is entitled to do\n // (it acts on its own fresh verdicts, and the hooks start it on the same commands you run\n // wp-cleanup from). Before this line they came out under \"⚠️ N branch(es) could not be\n // deleted\", which reads as work left undone and sends a human hunting for branches that no\n // longer exist.\n if (gone > 0) {\n const names = result.alreadyGone.map((entry: ReapedBranch): string => entry.branch).join(', ');\n out += `\\nℹ️ ${String(gone)} branch(es) were already gone — a concurrent auto-reap deleted and\\n`\n + ` archived them first, so there was nothing left to do: ${names}\\n`;\n }\n\n if (result.failed.length > 0) {\n out += `\\n⚠️ ${String(result.failed.length)} branch(es) could not be deleted:\\n`;\n for (const entry of result.failed) out += ` ✗ ${entry.branch} — ${entry.error}\\n`;\n }\n\n // Printed even on success: a deletion the human cannot undo is a deletion they have to trust\n // blindly, and the whole argument for auto-cleanup is that they never have to.\n out += `\\nEvery deletion is logged with its pre-delete SHA in\\n${this.mutationLog.branchMutationLogPath(repoRoot)} —\\n`\n + 'recover any of them with the `recover=` command on its line.\\n';\n return out;\n }\n\n private reapedLine(entry: ReapedBranch): string {\n const sha = entry.sha !== '' ? ` (was ${entry.sha.slice(0, 8)})` : '';\n // The archive tag is printed inline because it is the ONE thing that makes this delete casually\n // reversible — a name a human can type, rather than a sha they have to go dig out of a log.\n const archived = entry.archiveTag !== ''\n ? `\\n archived → ${entry.archiveTag} (restore: ${this.archiver.restoreCommand(entry.branch, entry.archiveTag)})`\n : '';\n return ` ✓ ${entry.branch}${sha} — ${entry.reason}${archived}\\n`;\n }\n\n /**\n * The spared branches a human can meaningfully rule on, grouped and ordered most-safe first.\n *\n * Branches spared as IN_USE — checked out in a worktree — are still excluded here, but the reason\n * is no longer \"git would simply refuse\". That premise died the moment worktrees became reapable.\n * The real reason is the ORDER in run(): the worktree pass has already run, so an IN_USE branch is\n * one of exactly two things. Either its worktree was dead and the reap took the branch with it (so\n * it is not in this list at all), or its worktree is one we are deliberately keeping — locked, held\n * open by uncommitted work, or the one we are standing in — and offering to delete the branch out\n * from under a live checkout is not a question worth asking. The pair is offered TOGETHER by the\n * worktree prompt, which shows both the path and the branch it holds, or it is not offered at all.\n */\n private promptable(spared: DeletableBranch[]): DeletableBranch[] {\n const out: DeletableBranch[] = [];\n for (const classification of ADJUDICATED_CLASSIFICATIONS) {\n for (const entry of spared) {\n if (entry.classification === classification) out.push(entry);\n }\n }\n return out;\n }\n\n /**\n * The zero-commit husks out of a promptable list — reaped by default, and never numbered.\n *\n * Keeping them OUT of the numbered block is what keeps `--delete-branches=1,3` honest: whatever\n * this reaps, the entries the caller can name are the same entries in the same order as on the\n * `--report` run that printed those numbers.\n *\n * THE CLASSIFICATION TOKEN IS THE ONLY SPELLING OF \"husk\". It would read as belt-and-braces to\n * also accept `commits === 0` here, and it is the opposite: MergedBranchesService.classify tests\n * commits===0 BEFORE anything else, so a second test can only ever disagree with the verdict — and\n * disagreeing in the widening direction, auto-reaping something no classification called a husk.\n */\n private husks<T extends DeletableBranch | DeletableWorktree>(adjudicated: T[]): T[] {\n return adjudicated.filter(\n (entry: T): boolean => entry.classification === CLASSIFICATION_NO_COMMITS);\n }\n\n private rest<T extends DeletableBranch | DeletableWorktree>(promptable: T[], husks: T[]): T[] {\n return promptable.filter((entry: T): boolean => !husks.includes(entry));\n }\n\n // The classification table: what each group means, and per branch its unique-commit count — the one\n // number that says whether a yes costs nothing or costs the only copy of somebody's work.\n private classifiedBlock(promptable: DeletableBranch[]): string {\n let out = '\\n' + SEP + `🤔 ${String(promptable.length)} branch(es) are probably dead — your call\\n` + SEP;\n let current = '';\n for (let i = 0; i < promptable.length; i += 1) {\n const entry = promptable[i];\n if (entry.classification !== current) {\n current = entry.classification;\n out += `\\n${CLASSIFICATION_HEADINGS[current] ?? current}\\n\\n`;\n }\n const commits = entry.commits >= 0 ? `${String(entry.commits)} unique commit(s)` : 'unique commits unknown';\n out += ` [${String(i + 1)}] ${entry.branch}\\n ${commits} — ${entry.reason}\\n`;\n }\n return out;\n }\n\n /**\n * Who decides about the numbered block, in priority order:\n *\n * 1. an explicit `--delete-branches` / `--delete-worktrees` — the caller said so, and a caller who\n * said so is never overruled by what stdin happens to be attached to;\n * 2. a terminal, or `--interactive` — ask;\n * 3. otherwise — take NOTHING, and print the exact command that takes it.\n *\n * (3) is the case an agent lands in, and it is deliberately empty-handed. See the class comment:\n * a run that deletes part of a numbered list invalidates the numbers it just printed, and those\n * numbers are the whole interface the next run is given.\n */\n private async decide<T extends DeletableBranch | DeletableWorktree>(\n repoRoot: string, block: T[], kind: string, kinds: string, flag: string,\n selection: DeleteSelection, options: CleanupOptions,\n ): Promise<T[]> {\n if (selection.given()) {\n const picked = selection.pick(block);\n process.stdout.write(`\\n${flag} chose ${String(picked.length)} of the ${String(block.length)} `\n + `${kinds} above.\\n`);\n if (picked.length < block.length) process.stdout.write(this.flagHint(repoRoot, kinds, flag, block.length));\n return picked;\n }\n if (!options.prompts()) {\n process.stdout.write(this.flagHint(repoRoot, kinds, flag, block.length));\n return [];\n }\n const answer = (await this.question(\n `\\nDelete which ${kind}(s)? [all / none / e.g. \"1,3\"] (default none): `)).trim().toLowerCase();\n if (answer === '' || answer === 'none' || answer === 'n') return [];\n if (answer === 'all' || answer === 'a') return block;\n return this.pickByNumber(block, answer);\n }\n\n /**\n * The exact command that takes what this run left — the half a non-tty caller never used to get.\n *\n * It states the numbering contract out loud because a shifted number is the one way this command\n * can delete the wrong ref, and the caller reading this is usually a program.\n */\n private flagHint(repoRoot: string, kinds: string, flag: string, count: number): string {\n return `\\nLeft for you to decide (${String(count)} ${kinds}, numbered above).\\n`\n + 'To delete them yourself, re-run with:\\n'\n + ` pnpm wp-cleanup ${flag}=all # every one listed above\\n`\n + ` pnpm wp-cleanup ${flag}=1,3 # just those, BY THE NUMBERS PRINTED ABOVE\\n`\n + ` pnpm wp-cleanup ${flag}=none # say no out loud\\n`\n + 'Those numbers are the numbers of THIS run. wp-cleanup renumbers from a fresh scan every\\n'\n + 'time, so once anything in the list is deleted, re-run `pnpm wp-cleanup --report` (which\\n'\n + 'deletes nothing) and read the new numbers before passing numbers again.\\n'\n + 'Every delete is archived to a tag first; `recover=` lines land in\\n'\n + `${this.mutationLog.branchMutationLogPath(repoRoot)}\\n`;\n }\n\n // Parse `1,3` / `1 3` from a HUMAN at the prompt, ignoring anything out of range. An unparseable\n // answer selects nothing, which is the fail-safe direction for a typed answer to a delete question.\n // The `--delete-*` flags deliberately do NOT behave this way: a program passing an out-of-range\n // number is holding stale numbers, and that stops the run (see DeleteSelection.pick).\n private pickByNumber<T extends DeletableBranch | DeletableWorktree>(promptable: T[], answer: string): T[] {\n const out: T[] = [];\n for (const token of answer.split(/[\\s,]+/)) {\n const index = Number(token);\n if (!Number.isInteger(index) || index < 1 || index > promptable.length) continue;\n out.push(promptable[index - 1]);\n }\n return out;\n }\n\n // Seam: overridden in the spec so the prompt parsing is testable with no terminal.\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 rl.question(prompt, (answer: string): void => {\n rl.close();\n resolve(answer);\n });\n });\n }\n}\n"]}
1
+ {"version":3,"file":"cleanup-command.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/commands/cleanup-command.ts"],"names":[],"mappings":";;;;AAAA,2DAAqC;AACrC,sEAAia;AACja,0DAA0E;A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AM,KAAK,IAAI,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC;YACzC,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;YAC5B,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,IAAI,KAAK,GAAG,UAAU,CAAC,MAAM;gBAAE,SAAS;YACjF,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC;QACpC,CAAC;QACD,OAAO,GAAG,CAAC;IACf,CAAC;IAED,mFAAmF;IACzE,QAAQ,CAAC,MAAc;QAC7B,MAAM,EAAE,GAAG,QAAQ,CAAC,eAAe,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;QACtF,OAAO,IAAI,OAAO,CAAS,CAAC,OAAgC,EAAQ,EAAE;YAClE,EAAE,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC,MAAc,EAAQ,EAAE;gBACzC,EAAE,CAAC,KAAK,EAAE,CAAC;gBACX,OAAO,CAAC,MAAM,CAAC,CAAC;YACpB,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC;CACJ,CAAA;AA9WY,wCAAc;yBAAd,cAAc;IAD1B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGA,6BAAc;QAChB,iCAAY;QAChB,mCAAc;QACP,yCAAsB;QAI1B,sCAAiB;GAT1C,cAAc,CA8W1B","sourcesContent":["import * as readline from 'readline';\nimport { BranchArchiver, BranchMutationLog, BranchReaper, DeletableBranch, DeletableWorktree, ReapResult, ReapedBranch, BRANCH_RETENTION_KEEP, CLASSIFICATION_SUPERSEDED, CLASSIFICATION_CONTENT_IN_MAIN, CLASSIFICATION_NEVER_PROPOSED, CLASSIFICATION_NO_COMMITS, CLASSIFICATION_MERGED_PR, CLASSIFICATION_BACKUP_OF_MERGED, CLASSIFICATION_BACKUP_OF_LIVE, ADJUDICATED_CLASSIFICATIONS } from '@webpieces/repo-workflow-core';\nimport { RepoRootFinder, loadAndValidate } from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\n\nimport { WorktreeCleanupSection } from './worktree-cleanup';\nimport {\n CleanupOptions,\n DeleteSelection,\n FLAG_DELETE_BRANCHES,\n FLAG_DELETE_WORKTREES,\n} from './cleanup-options';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n// Singular / plural as a pair, because every one of these strings is read by a human deciding whether\n// to delete something and `branch(s)` reads as a typo in the middle of exactly that sentence.\nconst BRANCH_KIND = 'branch';\nconst BRANCH_KINDS = 'branches';\nconst WORKTREE_KIND = 'worktree';\nconst WORKTREE_KINDS = 'worktrees';\n\n// The verdicts that reap themselves — a merged PR, or a snapshot of a ref that still exists. Named\n// here only so `--report` can SAY what a real run would take; the reaping itself is BranchReaper's.\nconst AUTO_REAPED_CLASSIFICATIONS: readonly string[] = [\n CLASSIFICATION_MERGED_PR,\n CLASSIFICATION_BACKUP_OF_MERGED,\n CLASSIFICATION_BACKUP_OF_LIVE,\n];\n\n// One line of human-facing explanation per promptable classification, ordered most-safe first. These\n// replace the single string `no merged PR found — a human must decide`, which covered all three of\n// these situations identically and so told a human nothing they could act on.\n//\n// CLASSIFICATION_NO_COMMITS has no entry and needs none: a zero-commit ref never reaches this block\n// any more — it is reaped on sight (see `husks`). A worktree spared for holding uncommitted work is\n// reported by the worktree section, with that as its reason, rather than offered as a question.\nconst CLASSIFICATION_HEADINGS: Readonly<Record<string, string>> = {\n [CLASSIFICATION_SUPERSEDED]:\n 'SUPERSEDED — the PR was closed WITHOUT merging and later PRs have merged since. Near-certainly\\n'\n + ' the abandoned first attempt at work that landed under a different number. Safest group to delete.',\n [CLASSIFICATION_CONTENT_IN_MAIN]:\n 'CONTENT ALREADY IN MAIN — every commit has a patch-equivalent in origin/main (git cherry).\\n'\n + ' The work is not unique to this branch; only the commit objects are.',\n [CLASSIFICATION_NEVER_PROPOSED]:\n 'NEVER PROPOSED — no PR was ever opened, and these commits may be the ONLY copy in existence.\\n'\n + ' Read the unique-commit counts before answering. This is the group to say no to if unsure.',\n};\n\n/**\n * wp-cleanup: remove the dead WORKTREES, delete the local branches whose PR is already MERGED, REAP\n * THE ZERO-COMMIT HUSKS, then report everything that is left with the exact command that takes it.\n *\n * ─── WHY A ZERO-COMMIT REF IS REAPED AND NOT ASKED ABOUT ─────────────────────────────────────────\n * A ref with 0 unique commits is byte-identical to origin/main. Deleting it loses a NAME, not a\n * commit — and the name comes back with one `git checkout -b`, or from the archive tag this writes\n * first. It was previously PROMPTED about, for one real reason: a WORKING TREE looks exactly like\n * that husk from `git worktree add -b` until its first commit, i.e. for exactly the window an agent\n * is working in it. But that case is DETECTABLE, and detecting it is cheaper than asking a human:\n *\n * · the worktree holds uncommitted or untracked files (`git status --porcelain`) — spared, said out loud\n * · the worktree is LOCKED and that lock still stands — a reason naming somebody other than the\n * Claude Code harness, or a harness lock whose agent the harness itself still reports as\n * mid-tool-call — spared by the verdicts before it ever reaches here (see WorktreeLockVerdicts;\n * the pid in a harness lock reason proves nothing, it is the shared session process)\n * · it is the tree we are standing in, or a detached HEAD — spared, likewise\n *\n * So the bar moved from \"prove it is dead\" to \"prove somebody is holding it\", deliberately, because\n * the cost of being wrong is a re-`checkout -b` and the cost of being cautious was a prompt that\n * stopped a human's terminal to adjudicate two refs that could not possibly hold work. Refs that DO\n * carry unique commits keep every bit of the old caution.\n *\n * ─── WHY FLAGS, AND WHY THEY BEAT THE TTY SNIFF ──────────────────────────────────────────────────\n * `process.stdin.isTTY !== true` used to be the whole basis for \"is a human standing here?\", and it\n * is a proxy, not a fact: a human running `pnpm wp-cleanup | tee log` has no tty, an agent on a pty\n * has one. The sniff stays as the DEFAULT selector; `--delete-branches` / `--delete-worktrees` /\n * `--interactive` / `--report` let the caller who KNOWS say so, and an explicit flag always wins.\n * `--ignore-stale-locks` is the same idea for the OTHER thing this command could not previously be\n * told: that a standing claude-agent lock is stale. It replaces the `git worktree unlock` a human had\n * to run per directory — seven times, in the incident that produced it — before wp-cleanup would do\n * its job. A dirty worktree and a genuinely live agent's are still spared under it.\n *\n * ─── WHY A NON-TTY RUN NOW DELETES NOTHING IT WAS NOT ASKED TO ───────────────────────────────────\n * It used to silently take the \"redundant\" groups and print a bare list of names it left. That is\n * strictly less than the human sees, and — worse — it broke the one invariant that makes numeric\n * selection safe: THE NUMBERS IN THE FLAG ARE THE NUMBERS JUST PRINTED. A run that deletes half of a\n * numbered list renumbers the rest, so the `--delete-branches=3,4` it printed would land on entries\n * 5 and 6 next time. So the unattended path now prints the IDENTICAL numbered, classified block a\n * human sees plus the exact command that takes it, and takes nothing from that block itself. The\n * husks it does reap are never IN the block, so reaping them cannot shift a single number.\n *\n * All the danger still lives in the verdicts, not here — see BranchReaper for why every automatically\n * deleted branch is recoverable, and note that EVERY delete on every path here archives first.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class CleanupCommand {\n constructor(\n private readonly repoRootFinder: RepoRootFinder,\n private readonly branchReaper: BranchReaper,\n private readonly archiver: BranchArchiver,\n private readonly worktreeSection: WorktreeCleanupSection,\n // The log path is COMPUTED, never restated. It is per-worktree, so the relative literal these\n // messages used to carry named a file that does not exist in a linked worktree — the reader\n // greps nothing and reads the silence as \"nothing was deleted\".\n private readonly mutationLog: BranchMutationLog,\n ) {}\n\n /**\n * WORKTREES FIRST, then branches. The order is the fix, not a detail: a worktree HOLDS its branch,\n * so that branch is spared `in-use` (\"remove that worktree before deleting the branch\") and nothing\n * used to remove the worktree — so both piled up until branch-creation-guard refused to make the\n * next one. Reaping the worktree takes its branch with it, and the branch pass then recomputes its\n * verdicts from scratch against the post-removal truth.\n */\n async run(options: CleanupOptions): Promise<void> {\n const repoRoot = this.repoRootFinder.resolveRepoRoot(process.cwd());\n const retention = loadAndValidate(repoRoot).prGate.landPr.branchRetention;\n if (options.report) {\n await this.reportOnly(repoRoot, retention, options);\n return;\n }\n await this.cleanUpWorktrees(repoRoot, retention, options);\n await this.cleanUpBranches(repoRoot, retention, options);\n }\n\n /**\n * `--report`: the whole classified picture, and NOT ONE DELETE.\n *\n * This is the only run whose numbers are guaranteed still valid when the next command starts,\n * because a run that deletes nothing cannot renumber anything. That is what makes it the honest\n * first half of `--report` → read the numbers → `--delete-branches=1,3`.\n */\n private async reportOnly(repoRoot: string, retention: string, options: CleanupOptions): Promise<void> {\n process.stdout.write('\\n' + SEP + '🔎 wp-cleanup --report — nothing will be deleted\\n' + SEP);\n\n const verdicts = await this.worktreeSection.verdicts(repoRoot, options.ignoreStaleLocks);\n const deadTrees = this.worktreeSection.provablyDead(verdicts);\n process.stdout.write(this.wouldReapBlock(\n WORKTREE_KINDS, deadTrees.map((tree: DeletableWorktree): string => `${tree.path} — ${tree.reason}`)));\n const treePromptable = this.worktreeSection.promptable(verdicts);\n const treeHusks = this.husks(treePromptable);\n process.stdout.write(this.wouldReapBlock(`zero-commit ${WORKTREE_KINDS}`,\n treeHusks.map((tree: DeletableWorktree): string => `${tree.path} [${tree.branch}]`)));\n process.stdout.write(this.worktreeSection.sparedBlock(verdicts, deadTrees));\n const treeBlock = this.rest(treePromptable, treeHusks);\n if (treeBlock.length > 0) {\n process.stdout.write(this.worktreeSection.promptBlock(treeBlock));\n process.stdout.write(this.flagHint(repoRoot, WORKTREE_KINDS, FLAG_DELETE_WORKTREES, treeBlock.length));\n }\n\n // Retention 'keep' turns BranchReaper.reap into a pure verdict computation — every branch\n // lands in `spared`, nothing is touched. That is exactly what a report needs, and it means\n // the classified block below is computed by the identical code path a real run uses, so the\n // numbering it prints IS the numbering the flag will act on.\n const branches = (await this.branchReaper.reap(repoRoot, 'wp-cleanup', null, BRANCH_RETENTION_KEEP)).spared;\n process.stdout.write(this.wouldReapBlock(BRANCH_KINDS, branches\n .filter((entry: DeletableBranch): boolean =>\n AUTO_REAPED_CLASSIFICATIONS.includes(entry.classification))\n .map((entry: DeletableBranch): string => `${entry.branch} — ${entry.reason}`)));\n const promptable = this.promptable(branches);\n const husks = this.husks(promptable);\n process.stdout.write(this.wouldReapBlock(`zero-commit ${BRANCH_KINDS}`,\n husks.map((entry: DeletableBranch): string => entry.branch)));\n const block = this.rest(promptable, husks);\n if (block.length > 0) {\n process.stdout.write(this.classifiedBlock(block));\n process.stdout.write(this.flagHint(repoRoot, BRANCH_KINDS, FLAG_DELETE_BRANCHES, block.length));\n }\n process.stdout.write(`\\nNothing was deleted (--report). Retention policy in effect: ${retention}.\\n`\n + 'Re-run without --report to act, or with the flags above to say exactly what to take.\\n');\n }\n\n private wouldReapBlock(kinds: string, lines: string[]): string {\n if (lines.length === 0) return '';\n let out = `\\nWould reap ${String(lines.length)} ${kinds} — no question asked, each archived first:\\n`;\n for (const line of lines) out += ` ✓ ${line}\\n`;\n return out;\n }\n\n private async cleanUpBranches(repoRoot: string, retention: string, options: CleanupOptions): Promise<void> {\n // No cache argument: wp-cleanup recomputes the verdicts itself. The file on disk is allowed to\n // go stale, and stale evidence is fine for BLOCKING but never for DELETING.\n const result = await this.branchReaper.reap(repoRoot, 'wp-cleanup', null, retention);\n const first = this.report(repoRoot, result);\n process.stdout.write(first);\n\n const promptable = this.promptable(result.spared);\n const husks = this.husks(promptable);\n const block = this.rest(promptable, husks);\n\n // Range-check the flag against the block BEFORE anything in this half is deleted, so a caller\n // holding stale numbers stops the run rather than half-executing it.\n options.branches.pick(block);\n\n if (husks.length > 0) {\n process.stdout.write(this.huskBlock(BRANCH_KINDS, husks.map(\n (entry: DeletableBranch): string => entry.branch)));\n process.stdout.write(this.report(repoRoot,\n await this.branchReaper.reapApproved(repoRoot, 'wp-cleanup', husks, retention)));\n }\n\n if (block.length === 0) {\n if (first === '' && husks.length === 0) process.stdout.write(this.nothingToDo());\n return;\n }\n process.stdout.write(this.classifiedBlock(block));\n const approved = await this.decide(\n repoRoot, block, BRANCH_KIND, BRANCH_KINDS, FLAG_DELETE_BRANCHES, options.branches, options);\n if (approved.length === 0) {\n process.stdout.write(\n `\\nNothing else deleted — the ${String(block.length)} ${BRANCH_KINDS} above were kept.\\n`);\n return;\n }\n process.stdout.write(this.report(repoRoot,\n await this.branchReaper.reapApproved(repoRoot, 'wp-cleanup', approved, retention)));\n }\n\n /**\n * Reap the provably-dead worktrees and the zero-commit husks, then decide about the rest.\n *\n * WorktreeReaper enforces the safety rails regardless of what is passed or answered: never the\n * primary clone, never the tree this command is running in, and never `--force` (git's refusal to\n * remove a worktree holding untracked or modified files is a feature, and forcing it is how a\n * cleanup command becomes a data-loss command).\n */\n private async cleanUpWorktrees(repoRoot: string, retention: string, options: CleanupOptions): Promise<void> {\n const verdicts = await this.worktreeSection.verdicts(repoRoot, options.ignoreStaleLocks);\n const dead = this.worktreeSection.provablyDead(verdicts);\n if (dead.length > 0) {\n process.stdout.write(\n this.worktreeSection.report(repoRoot,\n await this.worktreeSection.reap(repoRoot, 'wp-cleanup', dead, retention)));\n }\n process.stdout.write(this.worktreeSection.sparedBlock(verdicts, dead));\n\n const promptable = this.worktreeSection.promptable(verdicts);\n // A zero-commit worktree is a husk ONLY if nobody is holding it. Uncommitted or untracked\n // files are the one thing that says \"somebody is\", and they are the one thing no archive tag\n // can bring back — so they are checked here rather than left to git's refusal at removal time.\n const husks = await this.worktreeSection.withoutUncommitted(this.husks(promptable));\n const block = this.rest(promptable, husks);\n\n options.worktrees.pick(block);\n\n if (husks.length > 0) {\n process.stdout.write(this.huskBlock(WORKTREE_KINDS, husks.map(\n (tree: DeletableWorktree): string => `${tree.path} [${tree.branch}]`)));\n process.stdout.write(\n this.worktreeSection.report(repoRoot,\n await this.worktreeSection.reap(repoRoot, 'wp-cleanup', husks, retention)));\n }\n\n if (block.length === 0) return;\n process.stdout.write(this.worktreeSection.promptBlock(block));\n const approved = await this.decide(\n repoRoot, block, WORKTREE_KIND, WORKTREE_KINDS, FLAG_DELETE_WORKTREES, options.worktrees, options);\n if (approved.length === 0) {\n process.stdout.write(\n `\\nNothing else removed — the ${String(block.length)} ${WORKTREE_KINDS} above were kept.\\n`);\n return;\n }\n process.stdout.write(\n this.worktreeSection.report(repoRoot,\n await this.worktreeSection.reap(repoRoot, 'wp-cleanup', approved, retention)));\n }\n\n // What a bare run with an empty repo says. It points at --help because the flags are the whole\n // reason a caller who DOES have something to say never has to be prompted.\n private nothingToDo(): string {\n return '\\nNothing else to decide. `pnpm wp-cleanup --help` lists every flag '\n + '(--report, --delete-branches, --delete-worktrees, --interactive).\\n';\n }\n\n private huskBlock(kinds: string, names: string[]): string {\n let out = '\\n' + SEP\n + `♻️ Reaping ${String(names.length)} zero-commit ${kinds} — 0 unique commits, identical to origin/main\\n`\n + SEP + '\\n'\n + 'Nothing is held here: no uncommitted files, no live lock, not the tree you are standing in.\\n'\n + 'Deleting one of these loses a NAME, not a commit — and the name is archived to a tag first.\\n\\n';\n for (const name of names) out += ` · ${name}\\n`;\n return out;\n }\n\n private report(repoRoot: string, result: ReapResult): string {\n const gone = result.alreadyGone.length;\n if (result.reaped.length === 0 && result.failed.length === 0 && gone === 0) return '';\n\n let out = '\\n' + SEP + `🧹 Cleaned up ${String(result.reaped.length)} dead local branch(es)\\n` + SEP + '\\n';\n for (const entry of result.reaped) out += this.reapedLine(entry);\n\n // Stated, not warned about. These branches ARE gone — the detached refresher's auto-reap\n // deleted and archived them moments before this pass reached them, which it is entitled to do\n // (it acts on its own fresh verdicts, and the hooks start it on the same commands you run\n // wp-cleanup from). Before this line they came out under \"⚠️ N branch(es) could not be\n // deleted\", which reads as work left undone and sends a human hunting for branches that no\n // longer exist.\n if (gone > 0) {\n const names = result.alreadyGone.map((entry: ReapedBranch): string => entry.branch).join(', ');\n out += `\\nℹ️ ${String(gone)} branch(es) were already gone — a concurrent auto-reap deleted and\\n`\n + ` archived them first, so there was nothing left to do: ${names}\\n`;\n }\n\n if (result.failed.length > 0) {\n out += `\\n⚠️ ${String(result.failed.length)} branch(es) could not be deleted:\\n`;\n for (const entry of result.failed) out += ` ✗ ${entry.branch} — ${entry.error}\\n`;\n }\n\n // Printed even on success: a deletion the human cannot undo is a deletion they have to trust\n // blindly, and the whole argument for auto-cleanup is that they never have to.\n out += `\\nEvery deletion is logged with its pre-delete SHA in\\n${this.mutationLog.branchMutationLogPath(repoRoot)} —\\n`\n + 'recover any of them with the `recover=` command on its line.\\n';\n return out;\n }\n\n private reapedLine(entry: ReapedBranch): string {\n const sha = entry.sha !== '' ? ` (was ${entry.sha.slice(0, 8)})` : '';\n // The archive tag is printed inline because it is the ONE thing that makes this delete casually\n // reversible — a name a human can type, rather than a sha they have to go dig out of a log.\n const archived = entry.archiveTag !== ''\n ? `\\n archived → ${entry.archiveTag} (restore: ${this.archiver.restoreCommand(entry.branch, entry.archiveTag)})`\n : '';\n return ` ✓ ${entry.branch}${sha} — ${entry.reason}${archived}\\n`;\n }\n\n /**\n * The spared branches a human can meaningfully rule on, grouped and ordered most-safe first.\n *\n * Branches spared as IN_USE — checked out in a worktree — are still excluded here, but the reason\n * is no longer \"git would simply refuse\". That premise died the moment worktrees became reapable.\n * The real reason is the ORDER in run(): the worktree pass has already run, so an IN_USE branch is\n * one of exactly two things. Either its worktree was dead and the reap took the branch with it (so\n * it is not in this list at all), or its worktree is one we are deliberately keeping — locked, held\n * open by uncommitted work, or the one we are standing in — and offering to delete the branch out\n * from under a live checkout is not a question worth asking. The pair is offered TOGETHER by the\n * worktree prompt, which shows both the path and the branch it holds, or it is not offered at all.\n */\n private promptable(spared: DeletableBranch[]): DeletableBranch[] {\n const out: DeletableBranch[] = [];\n for (const classification of ADJUDICATED_CLASSIFICATIONS) {\n for (const entry of spared) {\n if (entry.classification === classification) out.push(entry);\n }\n }\n return out;\n }\n\n /**\n * The zero-commit husks out of a promptable list — reaped by default, and never numbered.\n *\n * Keeping them OUT of the numbered block is what keeps `--delete-branches=1,3` honest: whatever\n * this reaps, the entries the caller can name are the same entries in the same order as on the\n * `--report` run that printed those numbers.\n *\n * THE CLASSIFICATION TOKEN IS THE ONLY SPELLING OF \"husk\". It would read as belt-and-braces to\n * also accept `commits === 0` here, and it is the opposite: MergedBranchesService.classify tests\n * commits===0 BEFORE anything else, so a second test can only ever disagree with the verdict — and\n * disagreeing in the widening direction, auto-reaping something no classification called a husk.\n */\n private husks<T extends DeletableBranch | DeletableWorktree>(adjudicated: T[]): T[] {\n return adjudicated.filter(\n (entry: T): boolean => entry.classification === CLASSIFICATION_NO_COMMITS);\n }\n\n private rest<T extends DeletableBranch | DeletableWorktree>(promptable: T[], husks: T[]): T[] {\n return promptable.filter((entry: T): boolean => !husks.includes(entry));\n }\n\n // The classification table: what each group means, and per branch its unique-commit count — the one\n // number that says whether a yes costs nothing or costs the only copy of somebody's work.\n private classifiedBlock(promptable: DeletableBranch[]): string {\n let out = '\\n' + SEP + `🤔 ${String(promptable.length)} branch(es) are probably dead — your call\\n` + SEP;\n let current = '';\n for (let i = 0; i < promptable.length; i += 1) {\n const entry = promptable[i];\n if (entry.classification !== current) {\n current = entry.classification;\n out += `\\n${CLASSIFICATION_HEADINGS[current] ?? current}\\n\\n`;\n }\n const commits = entry.commits >= 0 ? `${String(entry.commits)} unique commit(s)` : 'unique commits unknown';\n out += ` [${String(i + 1)}] ${entry.branch}\\n ${commits} — ${entry.reason}\\n`;\n }\n return out;\n }\n\n /**\n * Who decides about the numbered block, in priority order:\n *\n * 1. an explicit `--delete-branches` / `--delete-worktrees` — the caller said so, and a caller who\n * said so is never overruled by what stdin happens to be attached to;\n * 2. a terminal, or `--interactive` — ask;\n * 3. otherwise — take NOTHING, and print the exact command that takes it.\n *\n * (3) is the case an agent lands in, and it is deliberately empty-handed. See the class comment:\n * a run that deletes part of a numbered list invalidates the numbers it just printed, and those\n * numbers are the whole interface the next run is given.\n */\n private async decide<T extends DeletableBranch | DeletableWorktree>(\n repoRoot: string, block: T[], kind: string, kinds: string, flag: string,\n selection: DeleteSelection, options: CleanupOptions,\n ): Promise<T[]> {\n if (selection.given()) {\n const picked = selection.pick(block);\n process.stdout.write(`\\n${flag} chose ${String(picked.length)} of the ${String(block.length)} `\n + `${kinds} above.\\n`);\n if (picked.length < block.length) process.stdout.write(this.flagHint(repoRoot, kinds, flag, block.length));\n return picked;\n }\n if (!options.prompts()) {\n process.stdout.write(this.flagHint(repoRoot, kinds, flag, block.length));\n return [];\n }\n const answer = (await this.question(\n `\\nDelete which ${kind}(s)? [all / none / e.g. \"1,3\"] (default none): `)).trim().toLowerCase();\n if (answer === '' || answer === 'none' || answer === 'n') return [];\n if (answer === 'all' || answer === 'a') return block;\n return this.pickByNumber(block, answer);\n }\n\n /**\n * The exact command that takes what this run left — the half a non-tty caller never used to get.\n *\n * It states the numbering contract out loud because a shifted number is the one way this command\n * can delete the wrong ref, and the caller reading this is usually a program.\n */\n private flagHint(repoRoot: string, kinds: string, flag: string, count: number): string {\n return `\\nLeft for you to decide (${String(count)} ${kinds}, numbered above).\\n`\n + 'To delete them yourself, re-run with:\\n'\n + ` pnpm wp-cleanup ${flag}=all # every one listed above\\n`\n + ` pnpm wp-cleanup ${flag}=1,3 # just those, BY THE NUMBERS PRINTED ABOVE\\n`\n + ` pnpm wp-cleanup ${flag}=none # say no out loud\\n`\n + 'Those numbers are the numbers of THIS run. wp-cleanup renumbers from a fresh scan every\\n'\n + 'time, so once anything in the list is deleted, re-run `pnpm wp-cleanup --report` (which\\n'\n + 'deletes nothing) and read the new numbers before passing numbers again.\\n'\n + 'Every delete is archived to a tag first; `recover=` lines land in\\n'\n + `${this.mutationLog.branchMutationLogPath(repoRoot)}\\n`;\n }\n\n // Parse `1,3` / `1 3` from a HUMAN at the prompt, ignoring anything out of range. An unparseable\n // answer selects nothing, which is the fail-safe direction for a typed answer to a delete question.\n // The `--delete-*` flags deliberately do NOT behave this way: a program passing an out-of-range\n // number is holding stale numbers, and that stops the run (see DeleteSelection.pick).\n private pickByNumber<T extends DeletableBranch | DeletableWorktree>(promptable: T[], answer: string): T[] {\n const out: T[] = [];\n for (const token of answer.split(/[\\s,]+/)) {\n const index = Number(token);\n if (!Number.isInteger(index) || index < 1 || index > promptable.length) continue;\n out.push(promptable[index - 1]);\n }\n return out;\n }\n\n // Seam: overridden in the spec so the prompt parsing is testable with no terminal.\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 rl.question(prompt, (answer: string): void => {\n rl.close();\n resolve(answer);\n });\n });\n }\n}\n"]}
@@ -89,7 +89,7 @@ let HumanPostPrCommand = class HumanPostPrCommand {
89
89
  const summary = this.reviewJsonService.loadSummaryJson(summaryPath, [], '', {}, RETRY_COMMAND);
90
90
  // FAIL FAST on a hand-written closing reference (issue #1310), before the human is asked to build.
91
91
  new issue_references_1.IssueReferences().assertNoStrayClosingReferences(summary.summary, summary.addressesIssues, RETRY_COMMAND);
92
- const status = this.mainSyncStatus.computeMainSyncStatus(repoRoot);
92
+ const status = await this.mainSyncStatus.computeMainSyncStatus(repoRoot);
93
93
  this.assertCurrentMain(status);
94
94
  const buildRan = await this.askToBuild();
95
95
  if (buildRan)
@@ -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,+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,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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,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 = 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
+ {"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,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;IACA;IAbrB,YACqB,cAA8B,EAC9B,cAA8B,EAC9B,YAA0B,EAC1B,YAA0B,EAC1B,OAAgB,EAChB,UAAsB,EACtB,iBAAoC,EACpC,cAA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AAC;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"]}
@@ -355,7 +355,7 @@ let LandPrCommand = class LandPrCommand {
355
355
  let line = '';
356
356
  let tag = '';
357
357
  if (retention === repo_workflow_core_1.BRANCH_RETENTION_ARCHIVE_TAG) {
358
- const archive = this.archiver.archive(repoRoot, base);
358
+ const archive = await this.archiver.archive(repoRoot, base);
359
359
  tag = archive.tag;
360
360
  line = archive.ok
361
361
  ? ` Archived ${base} → ${archive.tag} (restore: ${this.archiver.restoreCommand(base, archive.tag)})\n`