@webpieces/pr-gate 0.4.837 → 0.4.839

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 (85) hide show
  1. package/package.json +6 -4
  2. package/src/scripts/commands/cleanup-command.d.ts +2 -1
  3. package/src/scripts/commands/cleanup-command.js +13 -12
  4. package/src/scripts/commands/cleanup-command.js.map +1 -1
  5. package/src/scripts/commands/finish-upsert-pr-command.js +5 -3
  6. package/src/scripts/commands/finish-upsert-pr-command.js.map +1 -1
  7. package/src/scripts/commands/human-post-pr-command.d.ts +2 -1
  8. package/src/scripts/commands/human-post-pr-command.js +3 -2
  9. package/src/scripts/commands/human-post-pr-command.js.map +1 -1
  10. package/src/scripts/commands/land-pr-command.d.ts +2 -1
  11. package/src/scripts/commands/land-pr-command.js +12 -9
  12. package/src/scripts/commands/land-pr-command.js.map +1 -1
  13. package/src/scripts/commands/reap-worktree-command.d.ts +2 -1
  14. package/src/scripts/commands/reap-worktree-command.js +4 -2
  15. package/src/scripts/commands/reap-worktree-command.js.map +1 -1
  16. package/src/scripts/commands/sync-main-command.js +2 -1
  17. package/src/scripts/commands/sync-main-command.js.map +1 -1
  18. package/src/scripts/commands/upsert-hotfix-pr-command.d.ts +2 -1
  19. package/src/scripts/commands/upsert-hotfix-pr-command.js +2 -1
  20. package/src/scripts/commands/upsert-hotfix-pr-command.js.map +1 -1
  21. package/src/scripts/commands/worktree-cleanup.d.ts +1 -1
  22. package/src/scripts/commands/worktree-cleanup.js +11 -11
  23. package/src/scripts/commands/worktree-cleanup.js.map +1 -1
  24. package/src/scripts/commands/write-review-command.js +13 -10
  25. package/src/scripts/commands/write-review-command.js.map +1 -1
  26. package/src/scripts/commands/write-review-fixes-command.js +3 -2
  27. package/src/scripts/commands/write-review-fixes-command.js.map +1 -1
  28. package/src/scripts/pr-gate-cli-app.js +2 -1
  29. package/src/scripts/pr-gate-cli-app.js.map +1 -1
  30. package/src/scripts/workflow/build-affected.d.ts +2 -1
  31. package/src/scripts/workflow/build-affected.js +2 -1
  32. package/src/scripts/workflow/build-affected.js.map +1 -1
  33. package/src/scripts/workflow/cleanTmp.d.ts +2 -1
  34. package/src/scripts/workflow/cleanTmp.js +3 -2
  35. package/src/scripts/workflow/cleanTmp.js.map +1 -1
  36. package/src/scripts/workflow/diff-materializer.js +2 -1
  37. package/src/scripts/workflow/diff-materializer.js.map +1 -1
  38. package/src/scripts/workflow/gate-log-file.js +5 -4
  39. package/src/scripts/workflow/gate-log-file.js.map +1 -1
  40. package/src/scripts/workflow/generated-artifact-registry.js +2 -1
  41. package/src/scripts/workflow/generated-artifact-registry.js.map +1 -1
  42. package/src/scripts/workflow/hotfix-redirect.d.ts +1 -1
  43. package/src/scripts/workflow/hotfix-redirect.js +2 -1
  44. package/src/scripts/workflow/hotfix-redirect.js.map +1 -1
  45. package/src/scripts/workflow/landed-tree-resolver.d.ts +1 -1
  46. package/src/scripts/workflow/landed-tree-resolver.js +2 -2
  47. package/src/scripts/workflow/landed-tree-resolver.js.map +1 -1
  48. package/src/scripts/workflow/landed-worktree-reaper.d.ts +1 -1
  49. package/src/scripts/workflow/landed-worktree-reaper.js +2 -1
  50. package/src/scripts/workflow/landed-worktree-reaper.js.map +1 -1
  51. package/src/scripts/workflow/merge-end.d.ts +1 -1
  52. package/src/scripts/workflow/merge-end.js +6 -5
  53. package/src/scripts/workflow/merge-end.js.map +1 -1
  54. package/src/scripts/workflow/merge-info-index.d.ts +1 -1
  55. package/src/scripts/workflow/merge-info-index.js +5 -4
  56. package/src/scripts/workflow/merge-info-index.js.map +1 -1
  57. package/src/scripts/workflow/merge-start.d.ts +1 -1
  58. package/src/scripts/workflow/merge-start.js +11 -9
  59. package/src/scripts/workflow/merge-start.js.map +1 -1
  60. package/src/scripts/workflow/merge-state.d.ts +1 -1
  61. package/src/scripts/workflow/merge-state.js +3 -2
  62. package/src/scripts/workflow/merge-state.js.map +1 -1
  63. package/src/scripts/workflow/provenance-enforcer.js +5 -4
  64. package/src/scripts/workflow/provenance-enforcer.js.map +1 -1
  65. package/src/scripts/workflow/push-dev-state.d.ts +1 -1
  66. package/src/scripts/workflow/push-dev-state.js +4 -2
  67. package/src/scripts/workflow/push-dev-state.js.map +1 -1
  68. package/src/scripts/workflow/review-round-state.d.ts +2 -1
  69. package/src/scripts/workflow/review-round-state.js +22 -20
  70. package/src/scripts/workflow/review-round-state.js.map +1 -1
  71. package/src/scripts/workflow/review-stage-receipt.js +2 -1
  72. package/src/scripts/workflow/review-stage-receipt.js.map +1 -1
  73. package/src/scripts/workflow/reviewer-briefing-builder.js +2 -1
  74. package/src/scripts/workflow/reviewer-briefing-builder.js.map +1 -1
  75. package/src/scripts/workflow/reviewer-identity.d.ts +1 -1
  76. package/src/scripts/workflow/reviewer-identity.js +8 -7
  77. package/src/scripts/workflow/reviewer-identity.js.map +1 -1
  78. package/src/scripts/workflow/reviewer-verdict-gate.js +2 -1
  79. package/src/scripts/workflow/reviewer-verdict-gate.js.map +1 -1
  80. package/src/scripts/workflow/run-update.d.ts +1 -1
  81. package/src/scripts/workflow/run-update.js +4 -4
  82. package/src/scripts/workflow/run-update.js.map +1 -1
  83. package/src/scripts/workflow/verdict-provenance.d.ts +2 -1
  84. package/src/scripts/workflow/verdict-provenance.js +10 -7
  85. package/src/scripts/workflow/verdict-provenance.js.map +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"land-pr-command.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/commands/land-pr-command.ts"],"names":[],"mappings":";;;;AAAA,iDAAoD;AACpD,0DAGiC;AACjC,yCAA2D;AAC3D,2EAAgE;AAChE,6DAAyD;AACzD,2EAAsG;AACtG,+EAA+F;AAC/F,2EAAqE;AACrE,mEAA6E;AAC7E,qDAA8D;AAE9D,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAEvE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AAEI,IAAM,aAAa,GA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C,CAAC,EAAE,CAAC;IAClD,CAAC;CACJ,CAAA;AAhXY,sCAAa;wBAAb,aAAa;IADzB,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAIA,6BAAc;QAChB,mCAAY;QACZ,4BAAY;QAChB,oBAAQ;QACR,6BAAc;QACR,iCAAc;QACd,6CAAoB;QAC1B,wCAAiB;QACf,yCAAkB;GAX1C,aAAa,CAgXzB;AAED,wGAAwG;AACxG,oGAAoG;AACpG,MAAM,UAAU;IACZ,MAAM,CAAS;IACf,KAAK,CAAS;IACd,GAAG,CAAS;IACZ,IAAI,CAAS;IACb,UAAU,CAAS;IACnB;;;;OAIG;IACH,WAAW,CAAS;IAEpB,yDAAyD;IACzD,YACI,MAAc,EAAE,KAAa,EAAE,GAAW,EAAE,IAAY,EAAE,UAAkB,EAAE,WAAmB;QAEjG,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACnC,CAAC;CACJ;AAED;;;;;;GAMG;AACH,MAAa,aAAa;IACtB;;;;OAIG;IACH,aAAa,CAAU;IACvB,mGAAmG;IACnG,QAAQ,CAAS;IAEjB,YAAY,aAAsB,EAAE,QAAgB;QAChD,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC7B,CAAC;CACJ;AAdD,sCAcC","sourcesContent":["import { execSync, spawnSync } from 'child_process';\nimport {\n InformAiError, RepoRootFinder, MERGE_MODE_AUTO, loadAndValidate,\n BranchArchiver, BRANCH_RETENTION_ARCHIVE_TAG, BRANCH_RETENTION_KEEP, toError,\n} from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { AiBranchName } from '../workflow/git-readAiBranchName';\nimport { BranchNaming } from '../workflow/branch-naming';\nimport { LandedTree, LandedTreeResolver, LANDED_TREE_ABSENT } from '../workflow/landed-tree-resolver';\nimport { LandedWorktreeReaper, WorktreeReapHandoff } from '../workflow/landed-worktree-reaper';\nimport { MergeBodyTempFile } from '../workflow/merge-body-temp-file';\nimport { ArchiveRecord, MergeInfoIndex } from '../workflow/merge-info-index';\nimport { MergeIntent, PrMerger } from '../workflow/pr-merger';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n/**\n * `wp-land-pr`: squash-merge THIS branch's already-posted PR into main with the compact commit body.\n *\n * It exists because a merge clicked in the GitHub UI cannot set the squash SUBJECT to `<title> (#N)`\n * and cannot archive the pre-squash tip. So when a merge has to happen outside `wp-finish-upsert-pr`\n * (a mergeMode=NONE repo, or a PR whose checks were still running when finish ran), this is the command\n * that keeps main's history consistent and finishes the branch's bookkeeping.\n *\n * ─── Where the bytes come from: THE PR ITSELF ──────────────────────────────────────────────────────\n * `wp-finish-upsert-pr` renders ONE string and publishes it as the PR DESCRIPTION, and the full\n * dashboard lives in the PR's comments (see `pr-body-is-merge-body.spec.ts`, which pins that the\n * description and the merge body are one renderer's output). So the description IS the gated squash\n * body, held by GitHub, and landing reads it back with `gh pr view --json body`.\n *\n * THE BYTES THAT LAND ARE THE BYTES FINISH PRODUCED — that invariant is unchanged; what changed is that\n * GitHub, not this machine, is the thing holding them. That removes the whole machine-global receipt\n * store: a cache of a fact the remote already owns, which could only ever be missing, stale, or on the\n * wrong computer. Landing from a second clone, a fresh clone, or another machine entirely now just\n * works. See `decisions/0005-the-pr-description-is-the-merge-body.md`.\n *\n * It still deliberately does NOT re-render the body: re-deriving it at land time would be a second\n * authoritative gate whose result nobody reads, and it could silently disagree with what was reviewed.\n *\n * ─── Two scopes, and only one of them is the tree's ────────────────────────────────────────────────\n * 1. THE MERGE, which belongs to the PR — and is therefore reachable from anywhere.\n * 2. THE BOOKKEEPING — archiving the pre-squash tip as `archive/<date>/<branch>`, promoting merge-info,\n * and reaping the landed worktree. That half belongs to the tree whose `<branch>` really is the\n * commit being squashed, and it must NOT be attempted from anywhere else: another clone's\n * `<branch>` is a different commit, so archiving it there would tag the wrong objects under the\n * right name.\n *\n * ─── WHICH tree that is, is a FACT — it is not \"the one I am standing in\" ──────────────────────────\n * That distinction used to be resolved from `process.cwd()`, and it was wrong twice over.\n *\n * It was wrong MECHANICALLY: `pnpm` hoists a bin's cwd to the workspace root, and a Claude Code agent\n * worktree lives at `<primary>/.claude/worktrees/agent-<id>` — INSIDE the primary clone — so pnpm walked\n * straight past it and `git branch --show-current` answered `main`. Landing a worktree PR, i.e. every\n * `/full-cycle` run, reported \"No open PR found for this branch\" for a PR that was open, and the #512\n * worktree reap was unreachable dead code. The invocation directory is now read from `INIT_CWD` (pnpm\n * exports the directory the human actually typed in) and given to BOTH the repo-root resolution and the\n * `git` call, so neither can be answered by the hoisted directory.\n *\n * And it was wrong in PRINCIPLE, which is the larger half: most of the time the `/full-cycle` subagent\n * lands its own PR, but many times it does not — CI was still running when it finished, it errored, or a\n * coordinator picks the work up an hour later, by which point that agent is gone and its worktree is a\n * directory nobody is standing in. So `--pr <n>` names the PR, and {@link LandedTreeResolver} finds its\n * tree by the pair `(headRefName, headRefOid)` — never by branch name alone. The reap target is the\n * worktree whose HEAD is the exact commit GitHub squashed, whichever directory the operator is in, and\n * when nothing local holds that commit the merge still happens and the bookkeeping is SKIPPED OUT LOUD.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class LandPrCommand {\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(\n private readonly repoRootFinder: RepoRootFinder,\n private readonly aiBranchName: AiBranchName,\n private readonly branchNaming: BranchNaming,\n private readonly prMerger: PrMerger,\n private readonly archiver: BranchArchiver,\n private readonly mergeInfoIndex: MergeInfoIndex,\n private readonly landedWorktree: LandedWorktreeReaper,\n private readonly bodyFile: MergeBodyTempFile,\n private readonly landedTree: LandedTreeResolver,\n ) {}\n\n /**\n * THE INVOCATION DIRECTORY, which is not `process.cwd()`.\n *\n * `pnpm` runs a workspace bin with its cwd hoisted to the workspace root and exports the directory\n * the operator was actually in as `INIT_CWD`. Every agent worktree is NESTED inside the primary\n * clone, so the hoist silently relocated this command into a different tree holding a different\n * branch — see the class doc. `process.cwd()` remains the answer when nothing set `INIT_CWD` (a\n * direct `node` invocation, or a spec), which is the case where the two are the same anyway.\n */\n private invocationCwd(): string {\n const init = process.env['INIT_CWD'] ?? '';\n return init !== '' ? init : process.cwd();\n }\n\n async run(request: LandPrRequest): Promise<void> {\n if (request.prFlagPresent && !/^\\d+$/.test(request.prNumber)) throw this.badPrNumber(request);\n const cwd = this.invocationCwd();\n const repoRoot = this.repoRootFinder.resolveRepoRoot(cwd);\n // `--pr <n>` selects the PR outright; with no flag it is this branch's, read from the tree the\n // operator is really standing in.\n const selector = request.prNumber !== ''\n ? request.prNumber\n : this.branchNaming.baseBranchName(\n execSync('git branch --show-current', { cwd, encoding: 'utf8' }).trim());\n\n const ref = this.readPr(selector);\n if (ref === null) throw this.noSuchPr(request, selector);\n // The PR's OWN head branch, never the selector: with `--pr <n>` the operator named a number and\n // has said nothing about branches, and even in the zero-arg case GitHub is the authority on which\n // branch that PR is merging.\n const base = ref.headRefName !== '' ? ref.headRefName : selector;\n if (ref.body === '') throw this.emptyDescription(ref);\n const unfit = this.notFitForGitLog(ref.body);\n if (unfit !== '') throw this.descriptionUnfitForGitLog(ref, unfit);\n\n process.stdout.write('\\n' + SEP + `🚀 Landing PR #${ref.number}\\n` + SEP + '\\n');\n const mergeBodyFile = this.bodyFile.write(ref.body);\n\n const config = loadAndValidate(repoRoot).prGate;\n const policy = config.mergeMode;\n // Reuse the SAME merge logic wp-finish-upsert-pr uses, so a PR lands identically whichever\n // command lands it — including the auto-merge fallback when the checks are still running.\n //\n // `commanded: true` — running THIS command IS the intent to merge, so it is not gated on\n // pr-gate.mergeMode (a NONE repo runs this precisely to land one PR by hand). The real `policy`\n // travels alongside it rather than being replaced by a literal AUTO, so PrMerger's diagnostics\n // never assert a config value nobody set — that is exactly what used to print a CONFIG MISMATCH\n // about `mergeMode: AUTO` two lines above this command printing `mergeMode is NONE`.\n const outcome = this.prMerger.merge(\n base, `${ref.title} (#${ref.number})`, mergeBodyFile, new MergeIntent(policy ?? '', true),\n );\n\n const bookkeeping = outcome.merged\n ? this.bookkeeping(repoRoot, base, ref, config.landPr.branchRetention, cwd)\n : '';\n process.stdout.write(\n '\\n' + SEP + (outcome.merged ? '✅ Landed\\n' : 'ℹ️ Not landed yet\\n') + SEP + '\\n' +\n ` ${outcome.message}\\n` +\n bookkeeping +\n (policy === MERGE_MODE_AUTO\n ? ''\n : ` (pr-gate.mergeMode is ${policy} — wp-finish-upsert-pr will keep leaving PRs for a human.)\\n`) +\n '\\n',\n );\n }\n\n /**\n * `--pr` without a usable number. It REFUSES rather than falling back to the branch, because the\n * fallback would land a different PR from the one the operator was reaching for, and a squash into\n * main is not a place to guess. `--pr` bare and `--pr HEAD` land here alike.\n */\n private badPrNumber(request: LandPrRequest): InformAiError {\n const got = request.prNumber === '' ? 'nothing' : `\"${request.prNumber}\"`;\n return new InformAiError(\n '\\n' + SEP + '❌ --pr needs a PR NUMBER\\n' + SEP + '\\n' +\n `\\`--pr\\` was given ${got}. It takes the digits of one pull request:\\n` +\n ' pnpm wp-land-pr --pr 1087\\n\\n' +\n 'To land the PR of the branch you are standing on, pass no flag at all:\\n' +\n ' pnpm wp-land-pr\\n' + SEP);\n }\n\n /**\n * The refusal when `gh` has no open PR for what we asked about — and it must say WHICH question was\n * asked, because the two have different cures.\n *\n * The branch form used to be the only one, and it was the face of the cwd bug: run from an agent\n * worktree, pnpm's hoist made the branch read `main`, and an operator with an open PR in front of\n * them was told there was none. So the branch form now says what it looked up and where it read that\n * branch FROM, which is the one fact that makes a wrong answer recognisable as a wrong answer, and it\n * names the `--pr <n>` form that does not depend on the tree at all.\n */\n private noSuchPr(request: LandPrRequest, selector: string): InformAiError {\n if (request.prNumber !== '') {\n return new InformAiError(\n '\\n' + SEP + `❌ No open PR #${request.prNumber}\\n` + SEP + '\\n' +\n `\\`gh pr view ${request.prNumber}\\` found no OPEN pull request with that number.\\n` +\n 'If it is already merged, run `pnpm wp-cleanup` from the primary clone to finish the\\n' +\n 'branch and worktree bookkeeping. Otherwise check the number with `gh pr list`.\\n' + SEP);\n }\n return new InformAiError(\n '\\n' + SEP + '❌ No open PR found for this branch\\n' + SEP + '\\n' +\n `No open PR has head branch \"${selector}\", read from ${this.invocationCwd()}. Nothing to land.\\n` +\n 'If that is not the branch you expected, land it by number instead — it does not depend on\\n' +\n 'which directory you are standing in:\\n' +\n ' pnpm wp-land-pr --pr <n>\\n' +\n 'If the PR is already merged, run `pnpm wp-cleanup`.\\n' +\n 'If it was never posted, run the gated flow — it posts the PR AND writes the description\\n' +\n 'that becomes this commit body:\\n' +\n ' pnpm wp-start-upsert-pr && pnpm wp-review-upsert-pr && pnpm wp-finish-upsert-pr\\n' + SEP);\n }\n\n /**\n * The refusal when the PR exists but its description is empty.\n *\n * This is the ONE remaining \"no gated body\" case, and it is now a property of the PR rather than of\n * this machine — which is why the cure is a single command with no human judgement call attached.\n * There is deliberately no `--fallback-title-only` escape any more: that flag existed because the\n * bytes could be on a DIFFERENT COMPUTER from the one landing, which cannot happen when GitHub holds\n * them. Re-running finish is always available, always correct, and lands the reviewed bytes.\n */\n private emptyDescription(ref: PrIdentity): InformAiError {\n return new InformAiError(\n '\\n' + SEP + `❌ PR #${ref.number} has an EMPTY description\\n` + SEP + '\\n' +\n 'The PR description IS the squash-commit body — `pnpm wp-finish-upsert-pr` renders one string\\n' +\n 'and publishes it as the description, and landing reads it straight back with\\n' +\n '`gh pr view --json body`. An empty description means the gated flow never published one\\n' +\n '(or a human cleared it), so there is nothing reviewed to land.\\n\\n' +\n 'Re-run the gated flow — it re-renders the description and re-posts it to this same PR:\\n' +\n ' pnpm wp-start-upsert-pr # update from main (3-point merge). No push, no build gate.\\n' +\n ' pnpm wp-review-upsert-pr # validate the merge, build gate, extract the diff, brief reviewers\\n' +\n ' # write summary.json at the path wp-review-upsert-pr prints\\n' +\n ' pnpm wp-finish-upsert-pr # build gate, dashboard, create/update the PR\\n' +\n 'Then re-run `pnpm wp-land-pr`.\\n' + SEP,\n );\n }\n\n /**\n * '' when the description is a compact gated body; otherwise the marker that proves it is not.\n *\n * This reads the SAME invariant `pr-body-is-merge-body.spec.ts` asserts from the other end: the\n * compact body \"contains nothing a plain-text git log cannot carry\" — no markdown heading, no table\n * pipe. It is therefore not a heuristic about what a dashboard looks like; it is the renderer's own\n * pinned property, checked against bytes that arrived from outside this process.\n *\n * WHY IT IS NEEDED, and why it is not a compatibility fallback: a PR posted by a release OLDER than\n * the surface swap still has the FULL DASHBOARD as its description. Measured on this repo,\n * 2026-08-07 — PR #613 (posted after the swap) has a description byte-identical to its squash body,\n * while PR #614 (still open, posted minutes before) begins `## 🚦 PR Gate Dashboard`. Landing that\n * one would dump a risk table into main, which is precisely the defect\n * `decisions/0004` § 4.1 warned about. So this REFUSES and names the one command that fixes it. It\n * never falls back, never rewrites, and never reaches for a second source of bytes.\n *\n * It keeps earning its place after the transition: nothing stops a human editing a PR description\n * in GitHub's textarea, and this is the only point between that edit and main's history.\n *\n * What it must NOT be read as is proof that the bytes did not come from `renderPrBody`. They can:\n * the compact body interpolates author text, and a `|` reaches that text from a TypeScript union, a\n * regex alternation or a quoted shell pipeline. `Dashboard.gitLogSafe` substitutes both markers at\n * the render exit so a freshly-rendered body no longer trips this — which is where that invariant\n * belongs, since the renderer is the only thing that can fix it without an extra CI cycle.\n */\n private notFitForGitLog(body: string): string {\n if (body.includes('##')) return '## (a markdown heading)';\n if (body.includes('|')) return '| (a markdown table)';\n return '';\n }\n\n /**\n * The refusal when the description is not the compact gated body.\n *\n * It names BOTH ways bytes get here, because naming only one sent readers down a path that did not\n * exist. It used to assert an old release as \"the usual cause\" and prescribe re-running finish — and\n * when the marker had come from AUTHOR TEXT instead (a `|` in a summary, from a TypeScript union or a\n * regex alternation), finish re-rendered the identical character from the unchanged `summary.json` and\n * landing refused again: a loop costing a CI cycle per turn, escapable only by guessing that one\n * character in your prose was the problem. `Dashboard.gitLogSafe` now substitutes both markers at the\n * render exit, so a freshly-rendered body cannot reach here at all — which leaves a HAND-EDITED\n * description and a genuinely old PR as the two remaining causes, and this says so.\n */\n private descriptionUnfitForGitLog(ref: PrIdentity, marker: string): InformAiError {\n return new InformAiError(\n '\\n' + SEP + `❌ PR #${ref.number}'s description is not a git-log commit body\\n` + SEP + '\\n' +\n `It contains ${marker}, which the compact body rendered by \\`pnpm wp-finish-upsert-pr\\` never\\n` +\n 'does — it substitutes both markers as it renders — so these bytes are not the gated summary,\\n' +\n 'and landing them would put a PR Gate Dashboard (or hand-written markdown) into main\\'s\\n' +\n 'history permanently.\\n\\n' +\n 'There are two causes, and they need different fixes:\\n\\n' +\n ' 1. The description was EDITED BY HAND on GitHub after finish posted it. Re-running finish\\n' +\n ' overwrites that edit with the compact body, so landing works.\\n' +\n ' 2. The PR was posted by a webpieces release OLDER than the one that made the description\\n' +\n ' the commit body, so it is still the full dashboard. The dashboard now lives in the PR\\'s\\n' +\n ' 1st comment instead, and re-running finish moves it there.\\n\\n' +\n `Either way the cure is the same, and it does NOT require removing ${marker.trim()} from your PR\\n` +\n 'summary text — a pipe or a heading in a summary is rendered safe, not rejected:\\n' +\n ' pnpm wp-start-upsert-pr && pnpm wp-review-upsert-pr && pnpm wp-finish-upsert-pr\\n' + SEP,\n );\n }\n\n /**\n * The landed branch's post-merge bookkeeping — but ONLY when this tree's `<branch>` IS the commit\n * that was squashed.\n *\n * The fact being tested is \"does this working tree hold the objects the PR merged\", and the PR\n * answers it authoritatively: `headRefOid` is the tip GitHub squashed. A second clone's `<branch>`\n * is a different commit, so `archive/<date>/<branch>` there would tag the wrong tip under the right\n * name; `merge-info/staged/<feature>` lives in the posting tree's state, not ours; and the worktree\n * to reap is not this one. So the merge stands and the bookkeeping is declined ALOUD.\n *\n * This used to be read out of an `origin.json` sidecar recording which tree posted the PR. Comparing\n * SHAs is strictly better: it is a fact rather than a recorded claim, it needs no stored state, and\n * it is more precise in both directions — a second clone sitting on the SAME commit can safely\n * archive it, and a tree that has committed further work since finish ran correctly declines.\n */\n private bookkeeping(\n repoRoot: string, base: string, ref: PrIdentity, retention: string, cwd: string,\n ): string {\n const tree = this.landedTree.resolve(repoRoot, base, ref.headRefOid);\n if (!tree.bookkeepingAllowed) return this.notTheLandedTipNotice(base, tree, ref);\n return this.archiveAndPromote(repoRoot, base, ref, retention)\n + this.nextStep(repoRoot, tree, cwd);\n }\n\n /**\n * What was skipped, why, and what the two SHAs are — so the reader can tell WHICH cause it was.\n *\n * Two causes, one message, because the cure is the same for both: the objects the PR squashed are not\n * in this repo under that name, so nothing here may archive them or reap a tree for them.\n */\n private notTheLandedTipNotice(base: string, tree: LandedTree, ref: PrIdentity): string {\n const found = tree.kind === LANDED_TREE_ABSENT\n ? ` ${base} is not in this repo at all\\n`\n : ` ${base} here → ${tree.localSha}\\n`;\n return '\\n ⚠️ Archive + worktree cleanup SKIPPED — nothing here holds the commit that landed:\\n' +\n found +\n ` PR #${ref.number} squashed → ${ref.headRefOid}\\n` +\n ' Archiving from here would tag the wrong objects under the right name, and the\\n' +\n ` merge-info record and (if any) the worktree holding ${base} live with the other tip.\\n` +\n ' Either this is a second clone of the repo — finish the bookkeeping in the clone that\\n' +\n ' posted the PR with `pnpm wp-cleanup` — or that tree has commits made after\\n' +\n ' `pnpm wp-finish-upsert-pr` ran, which the PR does not contain.\\n';\n }\n\n /**\n * What happens next — which is NOT the same act when you landed from a worktree.\n *\n * Landing from a linked worktree always used to leave a corpse: the merged branch is checked out\n * here, so `git branch -D` refuses, `wp-cleanup`'s branch pass spares it as in-use, and nothing\n * removed the worktree — so the pair sat there until branch-creation-guard hit its cap. #512 made\n * worktrees reapable and printed `cd <primary> && pnpm wp-cleanup`; that instruction was correct\n * and it was the most-skipped step in the flow, because the PR is already landed and the work\n * feels done.\n *\n * So the reap is no longer an instruction. This command still refuses to remove the directory it\n * is standing in — that rail is untouched — and instead HANDS THE REAP to a child process rooted\n * in the primary clone, which is a tree nobody is deleting. See LandedWorktreeReaper. When that\n * hand-off is not safely achievable the #512 notice is printed unchanged, because an honest\n * limitation beats a command that deletes its own working directory mid-run.\n */\n private nextStep(repoRoot: string, tree: LandedTree, cwd: string): string {\n const handoff: WorktreeReapHandoff | null\n = this.landedWorktree.plan(repoRoot, tree.worktree, cwd);\n if (handoff === null) return ' Next: `pnpm wp-cleanup` to delete the merged branch.\\n';\n if (!handoff.canReap) return this.landedWorktree.manualNotice(handoff);\n return this.landedWorktree.handOff(handoff);\n }\n\n /**\n * The landed branch's post-merge bookkeeping, in one place:\n * 1. ARCHIVE the pre-squash tip as `archive/<date>/<branch>` — the tag makes the original history\n * permanently restorable (`git checkout -b <branch> <tag>` gives back the exact objects) while\n * costing one ref, so the branch itself no longer has to survive as a `*PreMerge` husk that\n * counts toward the branch cap. See BranchArchiver for why a tag beats a patch or the reflog.\n * 2. PROMOTE `merge-info/staged/<feature>/` to `merge-info/merged/<feature>/` and rebuild\n * `index.json`, so `staged/` holds only branches that are still in flight.\n *\n * Never throws: the PR is already merged by the time we get here, and failing the command after a\n * successful merge would report a landed PR as a failure. Problems are reported in the recap.\n */\n private archiveAndPromote(repoRoot: string, base: string, ref: PrIdentity, retention: string): string {\n if (retention === BRANCH_RETENTION_KEEP) return ' Branch retention is \"keep\" — nothing archived.\\n';\n\n let line = '';\n let tag = '';\n if (retention === BRANCH_RETENTION_ARCHIVE_TAG) {\n const archive = this.archiver.archive(repoRoot, base);\n tag = archive.tag;\n line = archive.ok\n ? ` Archived ${base} → ${archive.tag} (restore: ${this.archiver.restoreCommand(base, archive.tag)})\\n`\n : ` ⚠️ Could not archive ${base}: ${archive.error} — the branch was left alone.\\n`;\n }\n\n const feature = this.aiBranchName.getFeatureName();\n const record = new ArchiveRecord(\n tag, this.revParse(repoRoot, base), this.revParse(repoRoot, 'origin/main'),\n Number(ref.number), new Date().toISOString(),\n );\n if (this.mergeInfoIndex.promoteToMerged(repoRoot, feature, record)) {\n line += ` merge-info: staged/${feature} → merged/${feature} (index.json rebuilt)\\n`;\n }\n return line;\n }\n\n // Best-effort sha of a ref — '' when it cannot resolve. Recorded in archive.json for provenance.\n private revParse(repoRoot: string, ref: string): string {\n const result = spawnSync('git', ['rev-parse', ref], { cwd: repoRoot, encoding: 'utf8' });\n return result.status === 0 ? (result.stdout ?? '').trim() : '';\n }\n\n /**\n * Everything landing needs about the PR, in ONE `gh` read: number, title, URL, DESCRIPTION and the\n * head sha GitHub is squashing. `null` when there is no open PR for this head branch.\n *\n * The TITLE comes from the PR itself, not summary.json, so the squash subject matches what a reviewer\n * approved even if summary.json was edited afterwards. The BODY is the gated commit body (see the\n * class doc). `headRefOid` is read BEFORE the merge, because it is what the bookkeeping check\n * compares against and the merge is what makes the branch's fate uninteresting to GitHub.\n */\n private readPr(selector: string): PrIdentity | null {\n const result = spawnSync(\n 'gh', ['pr', 'view', selector, '--json', 'number,title,url,body,headRefOid,headRefName'],\n { encoding: 'utf8' },\n );\n if (result.status !== 0) return null;\n return this.parsePr(result.stdout ?? '');\n }\n\n // `gh --json` output → PrIdentity. Malformed/absent JSON reads as \"no PR\", which the caller turns\n // into the same refusal a missing PR gets: both mean nothing here can be landed.\n private parsePr(stdout: string): PrIdentity | null {\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: unparseable gh output means \"no PR\", never a crash\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n // webpieces-disable no-any-unknown -- gh's JSON is opaque until narrowed field-by-field below\n const raw = JSON.parse(stdout) as Record<string, unknown>;\n const number = typeof raw['number'] === 'number' ? String(raw['number']) : this.str(raw['number']);\n if (number === '') return null;\n // GitHub stores descriptions with CRLF. A commit body must not carry them, and the bytes are\n // otherwise identical to what finish rendered, so the line endings are normalized back here.\n const body = this.str(raw['body']).replace(/\\r\\n/g, '\\n').trim();\n return new PrIdentity(\n number, this.str(raw['title']), this.str(raw['url']), body === '' ? '' : body + '\\n',\n this.str(raw['headRefOid']), this.str(raw['headRefName']),\n );\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n return null;\n }\n }\n\n // webpieces-disable no-any-unknown -- one opaque JSON field, narrowed to string\n private str(value: unknown): string {\n return typeof value === 'string' ? value : '';\n }\n}\n\n// The open PR as GitHub holds it: its number, title, web URL, DESCRIPTION (= the gated commit body) and\n// the PAIR that identifies its tree locally — the head branch's name and the commit being squashed.\nclass PrIdentity {\n number: string;\n title: string;\n url: string;\n body: string;\n headRefOid: string;\n /**\n * The PR's head BRANCH. Required alongside `headRefOid` because neither half identifies a tree on its\n * own: the name is what a worktree list can be searched by, the sha is what makes a hit the right\n * one. It also frees `--pr <n>` from needing the operator to be standing anywhere in particular.\n */\n headRefName: string;\n\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(\n number: string, title: string, url: string, body: string, headRefOid: string, headRefName: string,\n ) {\n this.number = number;\n this.title = title;\n this.url = url;\n this.body = body;\n this.headRefOid = headRefOid;\n this.headRefName = headRefName;\n }\n}\n\n/**\n * Data-only (per CLAUDE.md, classes for data): what the operator asked `wp-land-pr` to land.\n *\n * `prNumber` is '' for the zero-arg form — \"this branch's PR\" — which stays the shorthand the worker\n * uses. It is NOT an optional constructor parameter with a default at the call site: `wp-land-pr.ts`\n * builds exactly one of these from the parsed argv, so there is one spelling of the decision.\n */\nexport class LandPrRequest {\n /**\n * Was `--pr` on the command line at all? Kept SEPARATE from the value because `--pr` with no number\n * is a mistake, not a request to guess: collapsing the two would silently land whatever PR the\n * current directory's branch happens to have, which is the opposite of what the operator typed.\n */\n prFlagPresent: boolean;\n /** The `--pr <n>` value verbatim, or '' to infer the PR from the invocation directory's branch. */\n prNumber: string;\n\n constructor(prFlagPresent: boolean, prNumber: string) {\n this.prFlagPresent = prFlagPresent;\n this.prNumber = prNumber;\n }\n}\n"]}
1
+ {"version":3,"file":"land-pr-command.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/commands/land-pr-command.ts"],"names":[],"mappings":";;;;AAAA,iDAAoD;AACpD,8DAA0D;AAC1D,iEAA6D;AAC7D,0DAA2F;AAC3F,sEAAoH;AACpH,yCAA2D;AAC3D,2EAAgE;AAChE,6DAAyD;AACzD,2EAAsG;AACtG,+EAA+F;AAC/F,2EAAqE;AACrE,mEAA6E;AAC7E,qDAA8D;AAE9D,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAEvE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AAEI,IAAM,aAAa,GAAnB,MAAM,aAAa;IAGD;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IAVrB,yDAAyD;IACzD,YACqB,cAA8B,EAC9B,YAA0B,EAC1B,YAA0B,EAC1B,QAAkB,EAClB,QAAwB,EACxB,cAA8B,EAC9B,cAAoC,EACpC,QAA2B,EAC3B,UAA8B;QAR9B,mBAAc,GAAd,cAAc,CAAgB;QAC9B,iBAAY,GAAZ,YAAY,CAAc;QAC1B,iBAAY,GAAZ,YAAY,CAAc;QAC1B,aAAQ,GAAR,QAAQ,CAAU;QAClB,aAAQ,GAAR,QAAQ,CAAgB;QACxB,mBAAc,GAAd,cAAc,CAAgB;QAC9B,mBAAc,GAAd,cAAc,CAAsB;QACpC,aAAQ,GAAR,QAAQ,CAAmB;QAC3B,eAAU,GAAV,UAAU,CAAoB;IAChD,CAAC;IAEJ;;;;;;;;OAQG;IACK,aAAa;QACjB,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC;QAC3C,OAAO,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC;IAC9C,CAAC;IAED,KA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,WAAW,GAAG,WAAW,CAAC;IACnC,CAAC;CACJ;AAED;;;;;;GAMG;AACH,MAAa,aAAa;IACtB;;;;OAIG;IACH,aAAa,CAAU;IACvB,mGAAmG;IACnG,QAAQ,CAAS;IAEjB,YAAY,aAAsB,EAAE,QAAgB;QAChD,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC7B,CAAC;CACJ;AAdD,sCAcC","sourcesContent":["import { execSync, spawnSync } from 'child_process';\nimport { InformAiError } from '@webpieces/tooling-common';\nimport { toError } from '@webpieces/tooling-common/to-error';\nimport { RepoRootFinder, MERGE_MODE_AUTO, loadAndValidate } from '@webpieces/rules-config';\nimport { BranchArchiver, BRANCH_RETENTION_ARCHIVE_TAG, BRANCH_RETENTION_KEEP } from '@webpieces/repo-workflow-core';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { AiBranchName } from '../workflow/git-readAiBranchName';\nimport { BranchNaming } from '../workflow/branch-naming';\nimport { LandedTree, LandedTreeResolver, LANDED_TREE_ABSENT } from '../workflow/landed-tree-resolver';\nimport { LandedWorktreeReaper, WorktreeReapHandoff } from '../workflow/landed-worktree-reaper';\nimport { MergeBodyTempFile } from '../workflow/merge-body-temp-file';\nimport { ArchiveRecord, MergeInfoIndex } from '../workflow/merge-info-index';\nimport { MergeIntent, PrMerger } from '../workflow/pr-merger';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n/**\n * `wp-land-pr`: squash-merge THIS branch's already-posted PR into main with the compact commit body.\n *\n * It exists because a merge clicked in the GitHub UI cannot set the squash SUBJECT to `<title> (#N)`\n * and cannot archive the pre-squash tip. So when a merge has to happen outside `wp-finish-upsert-pr`\n * (a mergeMode=NONE repo, or a PR whose checks were still running when finish ran), this is the command\n * that keeps main's history consistent and finishes the branch's bookkeeping.\n *\n * ─── Where the bytes come from: THE PR ITSELF ──────────────────────────────────────────────────────\n * `wp-finish-upsert-pr` renders ONE string and publishes it as the PR DESCRIPTION, and the full\n * dashboard lives in the PR's comments (see `pr-body-is-merge-body.spec.ts`, which pins that the\n * description and the merge body are one renderer's output). So the description IS the gated squash\n * body, held by GitHub, and landing reads it back with `gh pr view --json body`.\n *\n * THE BYTES THAT LAND ARE THE BYTES FINISH PRODUCED — that invariant is unchanged; what changed is that\n * GitHub, not this machine, is the thing holding them. That removes the whole machine-global receipt\n * store: a cache of a fact the remote already owns, which could only ever be missing, stale, or on the\n * wrong computer. Landing from a second clone, a fresh clone, or another machine entirely now just\n * works. See `decisions/0005-the-pr-description-is-the-merge-body.md`.\n *\n * It still deliberately does NOT re-render the body: re-deriving it at land time would be a second\n * authoritative gate whose result nobody reads, and it could silently disagree with what was reviewed.\n *\n * ─── Two scopes, and only one of them is the tree's ────────────────────────────────────────────────\n * 1. THE MERGE, which belongs to the PR — and is therefore reachable from anywhere.\n * 2. THE BOOKKEEPING — archiving the pre-squash tip as `archive/<date>/<branch>`, promoting merge-info,\n * and reaping the landed worktree. That half belongs to the tree whose `<branch>` really is the\n * commit being squashed, and it must NOT be attempted from anywhere else: another clone's\n * `<branch>` is a different commit, so archiving it there would tag the wrong objects under the\n * right name.\n *\n * ─── WHICH tree that is, is a FACT — it is not \"the one I am standing in\" ──────────────────────────\n * That distinction used to be resolved from `process.cwd()`, and it was wrong twice over.\n *\n * It was wrong MECHANICALLY: `pnpm` hoists a bin's cwd to the workspace root, and a Claude Code agent\n * worktree lives at `<primary>/.claude/worktrees/agent-<id>` — INSIDE the primary clone — so pnpm walked\n * straight past it and `git branch --show-current` answered `main`. Landing a worktree PR, i.e. every\n * `/full-cycle` run, reported \"No open PR found for this branch\" for a PR that was open, and the #512\n * worktree reap was unreachable dead code. The invocation directory is now read from `INIT_CWD` (pnpm\n * exports the directory the human actually typed in) and given to BOTH the repo-root resolution and the\n * `git` call, so neither can be answered by the hoisted directory.\n *\n * And it was wrong in PRINCIPLE, which is the larger half: most of the time the `/full-cycle` subagent\n * lands its own PR, but many times it does not — CI was still running when it finished, it errored, or a\n * coordinator picks the work up an hour later, by which point that agent is gone and its worktree is a\n * directory nobody is standing in. So `--pr <n>` names the PR, and {@link LandedTreeResolver} finds its\n * tree by the pair `(headRefName, headRefOid)` — never by branch name alone. The reap target is the\n * worktree whose HEAD is the exact commit GitHub squashed, whichever directory the operator is in, and\n * when nothing local holds that commit the merge still happens and the bookkeeping is SKIPPED OUT LOUD.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class LandPrCommand {\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(\n private readonly repoRootFinder: RepoRootFinder,\n private readonly aiBranchName: AiBranchName,\n private readonly branchNaming: BranchNaming,\n private readonly prMerger: PrMerger,\n private readonly archiver: BranchArchiver,\n private readonly mergeInfoIndex: MergeInfoIndex,\n private readonly landedWorktree: LandedWorktreeReaper,\n private readonly bodyFile: MergeBodyTempFile,\n private readonly landedTree: LandedTreeResolver,\n ) {}\n\n /**\n * THE INVOCATION DIRECTORY, which is not `process.cwd()`.\n *\n * `pnpm` runs a workspace bin with its cwd hoisted to the workspace root and exports the directory\n * the operator was actually in as `INIT_CWD`. Every agent worktree is NESTED inside the primary\n * clone, so the hoist silently relocated this command into a different tree holding a different\n * branch — see the class doc. `process.cwd()` remains the answer when nothing set `INIT_CWD` (a\n * direct `node` invocation, or a spec), which is the case where the two are the same anyway.\n */\n private invocationCwd(): string {\n const init = process.env['INIT_CWD'] ?? '';\n return init !== '' ? init : process.cwd();\n }\n\n async run(request: LandPrRequest): Promise<void> {\n if (request.prFlagPresent && !/^\\d+$/.test(request.prNumber)) throw this.badPrNumber(request);\n const cwd = this.invocationCwd();\n const repoRoot = this.repoRootFinder.resolveRepoRoot(cwd);\n // `--pr <n>` selects the PR outright; with no flag it is this branch's, read from the tree the\n // operator is really standing in.\n const selector = request.prNumber !== ''\n ? request.prNumber\n : this.branchNaming.baseBranchName(\n execSync('git branch --show-current', { cwd, encoding: 'utf8' }).trim());\n\n const ref = this.readPr(selector);\n if (ref === null) throw this.noSuchPr(request, selector);\n // The PR's OWN head branch, never the selector: with `--pr <n>` the operator named a number and\n // has said nothing about branches, and even in the zero-arg case GitHub is the authority on which\n // branch that PR is merging.\n const base = ref.headRefName !== '' ? ref.headRefName : selector;\n if (ref.body === '') throw this.emptyDescription(ref);\n const unfit = this.notFitForGitLog(ref.body);\n if (unfit !== '') throw this.descriptionUnfitForGitLog(ref, unfit);\n\n process.stdout.write('\\n' + SEP + `🚀 Landing PR #${ref.number}\\n` + SEP + '\\n');\n const mergeBodyFile = this.bodyFile.write(ref.body);\n\n const config = loadAndValidate(repoRoot).prGate;\n const policy = config.mergeMode;\n // Reuse the SAME merge logic wp-finish-upsert-pr uses, so a PR lands identically whichever\n // command lands it — including the auto-merge fallback when the checks are still running.\n //\n // `commanded: true` — running THIS command IS the intent to merge, so it is not gated on\n // pr-gate.mergeMode (a NONE repo runs this precisely to land one PR by hand). The real `policy`\n // travels alongside it rather than being replaced by a literal AUTO, so PrMerger's diagnostics\n // never assert a config value nobody set — that is exactly what used to print a CONFIG MISMATCH\n // about `mergeMode: AUTO` two lines above this command printing `mergeMode is NONE`.\n const outcome = this.prMerger.merge(\n base, `${ref.title} (#${ref.number})`, mergeBodyFile, new MergeIntent(policy ?? '', true),\n );\n\n const bookkeeping = outcome.merged\n ? this.bookkeeping(repoRoot, base, ref, config.landPr.branchRetention, cwd)\n : '';\n process.stdout.write(\n '\\n' + SEP + (outcome.merged ? '✅ Landed\\n' : 'ℹ️ Not landed yet\\n') + SEP + '\\n' +\n ` ${outcome.message}\\n` +\n bookkeeping +\n (policy === MERGE_MODE_AUTO\n ? ''\n : ` (pr-gate.mergeMode is ${policy} — wp-finish-upsert-pr will keep leaving PRs for a human.)\\n`) +\n '\\n',\n );\n }\n\n /**\n * `--pr` without a usable number. It REFUSES rather than falling back to the branch, because the\n * fallback would land a different PR from the one the operator was reaching for, and a squash into\n * main is not a place to guess. `--pr` bare and `--pr HEAD` land here alike.\n */\n private badPrNumber(request: LandPrRequest): InformAiError {\n const got = request.prNumber === '' ? 'nothing' : `\"${request.prNumber}\"`;\n return new InformAiError(\n '\\n' + SEP + '❌ --pr needs a PR NUMBER\\n' + SEP + '\\n' +\n `\\`--pr\\` was given ${got}. It takes the digits of one pull request:\\n` +\n ' pnpm wp-land-pr --pr 1087\\n\\n' +\n 'To land the PR of the branch you are standing on, pass no flag at all:\\n' +\n ' pnpm wp-land-pr\\n' + SEP);\n }\n\n /**\n * The refusal when `gh` has no open PR for what we asked about — and it must say WHICH question was\n * asked, because the two have different cures.\n *\n * The branch form used to be the only one, and it was the face of the cwd bug: run from an agent\n * worktree, pnpm's hoist made the branch read `main`, and an operator with an open PR in front of\n * them was told there was none. So the branch form now says what it looked up and where it read that\n * branch FROM, which is the one fact that makes a wrong answer recognisable as a wrong answer, and it\n * names the `--pr <n>` form that does not depend on the tree at all.\n */\n private noSuchPr(request: LandPrRequest, selector: string): InformAiError {\n if (request.prNumber !== '') {\n return new InformAiError(\n '\\n' + SEP + `❌ No open PR #${request.prNumber}\\n` + SEP + '\\n' +\n `\\`gh pr view ${request.prNumber}\\` found no OPEN pull request with that number.\\n` +\n 'If it is already merged, run `pnpm wp-cleanup` from the primary clone to finish the\\n' +\n 'branch and worktree bookkeeping. Otherwise check the number with `gh pr list`.\\n' + SEP);\n }\n return new InformAiError(\n '\\n' + SEP + '❌ No open PR found for this branch\\n' + SEP + '\\n' +\n `No open PR has head branch \"${selector}\", read from ${this.invocationCwd()}. Nothing to land.\\n` +\n 'If that is not the branch you expected, land it by number instead — it does not depend on\\n' +\n 'which directory you are standing in:\\n' +\n ' pnpm wp-land-pr --pr <n>\\n' +\n 'If the PR is already merged, run `pnpm wp-cleanup`.\\n' +\n 'If it was never posted, run the gated flow — it posts the PR AND writes the description\\n' +\n 'that becomes this commit body:\\n' +\n ' pnpm wp-start-upsert-pr && pnpm wp-review-upsert-pr && pnpm wp-finish-upsert-pr\\n' + SEP);\n }\n\n /**\n * The refusal when the PR exists but its description is empty.\n *\n * This is the ONE remaining \"no gated body\" case, and it is now a property of the PR rather than of\n * this machine — which is why the cure is a single command with no human judgement call attached.\n * There is deliberately no `--fallback-title-only` escape any more: that flag existed because the\n * bytes could be on a DIFFERENT COMPUTER from the one landing, which cannot happen when GitHub holds\n * them. Re-running finish is always available, always correct, and lands the reviewed bytes.\n */\n private emptyDescription(ref: PrIdentity): InformAiError {\n return new InformAiError(\n '\\n' + SEP + `❌ PR #${ref.number} has an EMPTY description\\n` + SEP + '\\n' +\n 'The PR description IS the squash-commit body — `pnpm wp-finish-upsert-pr` renders one string\\n' +\n 'and publishes it as the description, and landing reads it straight back with\\n' +\n '`gh pr view --json body`. An empty description means the gated flow never published one\\n' +\n '(or a human cleared it), so there is nothing reviewed to land.\\n\\n' +\n 'Re-run the gated flow — it re-renders the description and re-posts it to this same PR:\\n' +\n ' pnpm wp-start-upsert-pr # update from main (3-point merge). No push, no build gate.\\n' +\n ' pnpm wp-review-upsert-pr # validate the merge, build gate, extract the diff, brief reviewers\\n' +\n ' # write summary.json at the path wp-review-upsert-pr prints\\n' +\n ' pnpm wp-finish-upsert-pr # build gate, dashboard, create/update the PR\\n' +\n 'Then re-run `pnpm wp-land-pr`.\\n' + SEP,\n );\n }\n\n /**\n * '' when the description is a compact gated body; otherwise the marker that proves it is not.\n *\n * This reads the SAME invariant `pr-body-is-merge-body.spec.ts` asserts from the other end: the\n * compact body \"contains nothing a plain-text git log cannot carry\" — no markdown heading, no table\n * pipe. It is therefore not a heuristic about what a dashboard looks like; it is the renderer's own\n * pinned property, checked against bytes that arrived from outside this process.\n *\n * WHY IT IS NEEDED, and why it is not a compatibility fallback: a PR posted by a release OLDER than\n * the surface swap still has the FULL DASHBOARD as its description. Measured on this repo,\n * 2026-08-07 — PR #613 (posted after the swap) has a description byte-identical to its squash body,\n * while PR #614 (still open, posted minutes before) begins `## 🚦 PR Gate Dashboard`. Landing that\n * one would dump a risk table into main, which is precisely the defect\n * `decisions/0004` § 4.1 warned about. So this REFUSES and names the one command that fixes it. It\n * never falls back, never rewrites, and never reaches for a second source of bytes.\n *\n * It keeps earning its place after the transition: nothing stops a human editing a PR description\n * in GitHub's textarea, and this is the only point between that edit and main's history.\n *\n * What it must NOT be read as is proof that the bytes did not come from `renderPrBody`. They can:\n * the compact body interpolates author text, and a `|` reaches that text from a TypeScript union, a\n * regex alternation or a quoted shell pipeline. `Dashboard.gitLogSafe` substitutes both markers at\n * the render exit so a freshly-rendered body no longer trips this — which is where that invariant\n * belongs, since the renderer is the only thing that can fix it without an extra CI cycle.\n */\n private notFitForGitLog(body: string): string {\n if (body.includes('##')) return '## (a markdown heading)';\n if (body.includes('|')) return '| (a markdown table)';\n return '';\n }\n\n /**\n * The refusal when the description is not the compact gated body.\n *\n * It names BOTH ways bytes get here, because naming only one sent readers down a path that did not\n * exist. It used to assert an old release as \"the usual cause\" and prescribe re-running finish — and\n * when the marker had come from AUTHOR TEXT instead (a `|` in a summary, from a TypeScript union or a\n * regex alternation), finish re-rendered the identical character from the unchanged `summary.json` and\n * landing refused again: a loop costing a CI cycle per turn, escapable only by guessing that one\n * character in your prose was the problem. `Dashboard.gitLogSafe` now substitutes both markers at the\n * render exit, so a freshly-rendered body cannot reach here at all — which leaves a HAND-EDITED\n * description and a genuinely old PR as the two remaining causes, and this says so.\n */\n private descriptionUnfitForGitLog(ref: PrIdentity, marker: string): InformAiError {\n return new InformAiError(\n '\\n' + SEP + `❌ PR #${ref.number}'s description is not a git-log commit body\\n` + SEP + '\\n' +\n `It contains ${marker}, which the compact body rendered by \\`pnpm wp-finish-upsert-pr\\` never\\n` +\n 'does — it substitutes both markers as it renders — so these bytes are not the gated summary,\\n' +\n 'and landing them would put a PR Gate Dashboard (or hand-written markdown) into main\\'s\\n' +\n 'history permanently.\\n\\n' +\n 'There are two causes, and they need different fixes:\\n\\n' +\n ' 1. The description was EDITED BY HAND on GitHub after finish posted it. Re-running finish\\n' +\n ' overwrites that edit with the compact body, so landing works.\\n' +\n ' 2. The PR was posted by a webpieces release OLDER than the one that made the description\\n' +\n ' the commit body, so it is still the full dashboard. The dashboard now lives in the PR\\'s\\n' +\n ' 1st comment instead, and re-running finish moves it there.\\n\\n' +\n `Either way the cure is the same, and it does NOT require removing ${marker.trim()} from your PR\\n` +\n 'summary text — a pipe or a heading in a summary is rendered safe, not rejected:\\n' +\n ' pnpm wp-start-upsert-pr && pnpm wp-review-upsert-pr && pnpm wp-finish-upsert-pr\\n' + SEP,\n );\n }\n\n /**\n * The landed branch's post-merge bookkeeping — but ONLY when this tree's `<branch>` IS the commit\n * that was squashed.\n *\n * The fact being tested is \"does this working tree hold the objects the PR merged\", and the PR\n * answers it authoritatively: `headRefOid` is the tip GitHub squashed. A second clone's `<branch>`\n * is a different commit, so `archive/<date>/<branch>` there would tag the wrong tip under the right\n * name; `merge-info/staged/<feature>` lives in the posting tree's state, not ours; and the worktree\n * to reap is not this one. So the merge stands and the bookkeeping is declined ALOUD.\n *\n * This used to be read out of an `origin.json` sidecar recording which tree posted the PR. Comparing\n * SHAs is strictly better: it is a fact rather than a recorded claim, it needs no stored state, and\n * it is more precise in both directions — a second clone sitting on the SAME commit can safely\n * archive it, and a tree that has committed further work since finish ran correctly declines.\n */\n private bookkeeping(\n repoRoot: string, base: string, ref: PrIdentity, retention: string, cwd: string,\n ): string {\n const tree = this.landedTree.resolve(repoRoot, base, ref.headRefOid);\n if (!tree.bookkeepingAllowed) return this.notTheLandedTipNotice(base, tree, ref);\n return this.archiveAndPromote(repoRoot, base, ref, retention)\n + this.nextStep(repoRoot, tree, cwd);\n }\n\n /**\n * What was skipped, why, and what the two SHAs are — so the reader can tell WHICH cause it was.\n *\n * Two causes, one message, because the cure is the same for both: the objects the PR squashed are not\n * in this repo under that name, so nothing here may archive them or reap a tree for them.\n */\n private notTheLandedTipNotice(base: string, tree: LandedTree, ref: PrIdentity): string {\n const found = tree.kind === LANDED_TREE_ABSENT\n ? ` ${base} is not in this repo at all\\n`\n : ` ${base} here → ${tree.localSha}\\n`;\n return '\\n ⚠️ Archive + worktree cleanup SKIPPED — nothing here holds the commit that landed:\\n' +\n found +\n ` PR #${ref.number} squashed → ${ref.headRefOid}\\n` +\n ' Archiving from here would tag the wrong objects under the right name, and the\\n' +\n ` merge-info record and (if any) the worktree holding ${base} live with the other tip.\\n` +\n ' Either this is a second clone of the repo — finish the bookkeeping in the clone that\\n' +\n ' posted the PR with `pnpm wp-cleanup` — or that tree has commits made after\\n' +\n ' `pnpm wp-finish-upsert-pr` ran, which the PR does not contain.\\n';\n }\n\n /**\n * What happens next — which is NOT the same act when you landed from a worktree.\n *\n * Landing from a linked worktree always used to leave a corpse: the merged branch is checked out\n * here, so `git branch -D` refuses, `wp-cleanup`'s branch pass spares it as in-use, and nothing\n * removed the worktree — so the pair sat there until branch-creation-guard hit its cap. #512 made\n * worktrees reapable and printed `cd <primary> && pnpm wp-cleanup`; that instruction was correct\n * and it was the most-skipped step in the flow, because the PR is already landed and the work\n * feels done.\n *\n * So the reap is no longer an instruction. This command still refuses to remove the directory it\n * is standing in — that rail is untouched — and instead HANDS THE REAP to a child process rooted\n * in the primary clone, which is a tree nobody is deleting. See LandedWorktreeReaper. When that\n * hand-off is not safely achievable the #512 notice is printed unchanged, because an honest\n * limitation beats a command that deletes its own working directory mid-run.\n */\n private nextStep(repoRoot: string, tree: LandedTree, cwd: string): string {\n const handoff: WorktreeReapHandoff | null\n = this.landedWorktree.plan(repoRoot, tree.worktree, cwd);\n if (handoff === null) return ' Next: `pnpm wp-cleanup` to delete the merged branch.\\n';\n if (!handoff.canReap) return this.landedWorktree.manualNotice(handoff);\n return this.landedWorktree.handOff(handoff);\n }\n\n /**\n * The landed branch's post-merge bookkeeping, in one place:\n * 1. ARCHIVE the pre-squash tip as `archive/<date>/<branch>` — the tag makes the original history\n * permanently restorable (`git checkout -b <branch> <tag>` gives back the exact objects) while\n * costing one ref, so the branch itself no longer has to survive as a `*PreMerge` husk that\n * counts toward the branch cap. See BranchArchiver for why a tag beats a patch or the reflog.\n * 2. PROMOTE `merge-info/staged/<feature>/` to `merge-info/merged/<feature>/` and rebuild\n * `index.json`, so `staged/` holds only branches that are still in flight.\n *\n * Never throws: the PR is already merged by the time we get here, and failing the command after a\n * successful merge would report a landed PR as a failure. Problems are reported in the recap.\n */\n private archiveAndPromote(repoRoot: string, base: string, ref: PrIdentity, retention: string): string {\n if (retention === BRANCH_RETENTION_KEEP) return ' Branch retention is \"keep\" — nothing archived.\\n';\n\n let line = '';\n let tag = '';\n if (retention === BRANCH_RETENTION_ARCHIVE_TAG) {\n const archive = this.archiver.archive(repoRoot, base);\n tag = archive.tag;\n line = archive.ok\n ? ` Archived ${base} → ${archive.tag} (restore: ${this.archiver.restoreCommand(base, archive.tag)})\\n`\n : ` ⚠️ Could not archive ${base}: ${archive.error} — the branch was left alone.\\n`;\n }\n\n const feature = this.aiBranchName.getFeatureName();\n const record = new ArchiveRecord(\n tag, this.revParse(repoRoot, base), this.revParse(repoRoot, 'origin/main'),\n Number(ref.number), new Date().toISOString(),\n );\n if (this.mergeInfoIndex.promoteToMerged(repoRoot, feature, record)) {\n line += ` merge-info: staged/${feature} → merged/${feature} (index.json rebuilt)\\n`;\n }\n return line;\n }\n\n // Best-effort sha of a ref — '' when it cannot resolve. Recorded in archive.json for provenance.\n private revParse(repoRoot: string, ref: string): string {\n const result = spawnSync('git', ['rev-parse', ref], { cwd: repoRoot, encoding: 'utf8' });\n return result.status === 0 ? (result.stdout ?? '').trim() : '';\n }\n\n /**\n * Everything landing needs about the PR, in ONE `gh` read: number, title, URL, DESCRIPTION and the\n * head sha GitHub is squashing. `null` when there is no open PR for this head branch.\n *\n * The TITLE comes from the PR itself, not summary.json, so the squash subject matches what a reviewer\n * approved even if summary.json was edited afterwards. The BODY is the gated commit body (see the\n * class doc). `headRefOid` is read BEFORE the merge, because it is what the bookkeeping check\n * compares against and the merge is what makes the branch's fate uninteresting to GitHub.\n */\n private readPr(selector: string): PrIdentity | null {\n const result = spawnSync(\n 'gh', ['pr', 'view', selector, '--json', 'number,title,url,body,headRefOid,headRefName'],\n { encoding: 'utf8' },\n );\n if (result.status !== 0) return null;\n return this.parsePr(result.stdout ?? '');\n }\n\n // `gh --json` output → PrIdentity. Malformed/absent JSON reads as \"no PR\", which the caller turns\n // into the same refusal a missing PR gets: both mean nothing here can be landed.\n private parsePr(stdout: string): PrIdentity | null {\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: unparseable gh output means \"no PR\", never a crash\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n // webpieces-disable no-any-unknown -- gh's JSON is opaque until narrowed field-by-field below\n const raw = JSON.parse(stdout) as Record<string, unknown>;\n const number = typeof raw['number'] === 'number' ? String(raw['number']) : this.str(raw['number']);\n if (number === '') return null;\n // GitHub stores descriptions with CRLF. A commit body must not carry them, and the bytes are\n // otherwise identical to what finish rendered, so the line endings are normalized back here.\n const body = this.str(raw['body']).replace(/\\r\\n/g, '\\n').trim();\n return new PrIdentity(\n number, this.str(raw['title']), this.str(raw['url']), body === '' ? '' : body + '\\n',\n this.str(raw['headRefOid']), this.str(raw['headRefName']),\n );\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n return null;\n }\n }\n\n // webpieces-disable no-any-unknown -- one opaque JSON field, narrowed to string\n private str(value: unknown): string {\n return typeof value === 'string' ? value : '';\n }\n}\n\n// The open PR as GitHub holds it: its number, title, web URL, DESCRIPTION (= the gated commit body) and\n// the PAIR that identifies its tree locally — the head branch's name and the commit being squashed.\nclass PrIdentity {\n number: string;\n title: string;\n url: string;\n body: string;\n headRefOid: string;\n /**\n * The PR's head BRANCH. Required alongside `headRefOid` because neither half identifies a tree on its\n * own: the name is what a worktree list can be searched by, the sha is what makes a hit the right\n * one. It also frees `--pr <n>` from needing the operator to be standing anywhere in particular.\n */\n headRefName: string;\n\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(\n number: string, title: string, url: string, body: string, headRefOid: string, headRefName: string,\n ) {\n this.number = number;\n this.title = title;\n this.url = url;\n this.body = body;\n this.headRefOid = headRefOid;\n this.headRefName = headRefName;\n }\n}\n\n/**\n * Data-only (per CLAUDE.md, classes for data): what the operator asked `wp-land-pr` to land.\n *\n * `prNumber` is '' for the zero-arg form — \"this branch's PR\" — which stays the shorthand the worker\n * uses. It is NOT an optional constructor parameter with a default at the call site: `wp-land-pr.ts`\n * builds exactly one of these from the parsed argv, so there is one spelling of the decision.\n */\nexport class LandPrRequest {\n /**\n * Was `--pr` on the command line at all? Kept SEPARATE from the value because `--pr` with no number\n * is a mistake, not a request to guess: collapsing the two would silently land whatever PR the\n * current directory's branch happens to have, which is the opposite of what the operator typed.\n */\n prFlagPresent: boolean;\n /** The `--pr <n>` value verbatim, or '' to infer the PR from the invocation directory's branch. */\n prNumber: string;\n\n constructor(prFlagPresent: boolean, prNumber: string) {\n this.prFlagPresent = prFlagPresent;\n this.prNumber = prNumber;\n }\n}\n"]}
@@ -1,4 +1,5 @@
1
- import { RepoRootFinder, WorktreeService } from '@webpieces/rules-config';
1
+ import { WorktreeService } from '@webpieces/repo-workflow-core';
2
+ import { RepoRootFinder } from '@webpieces/rules-config';
2
3
  import { ReapOutcomeSignal } from '../workflow/reap-outcome';
3
4
  import { WorktreeCleanupSection } from './worktree-cleanup';
4
5
  /**
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ReapWorktreeCommand = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const path = tslib_1.__importStar(require("path"));
6
+ const repo_workflow_core_1 = require("@webpieces/repo-workflow-core");
7
+ const tooling_common_1 = require("@webpieces/tooling-common");
6
8
  const rules_config_1 = require("@webpieces/rules-config");
7
9
  const inversify_1 = require("inversify");
8
10
  const reap_outcome_1 = require("../workflow/reap-outcome");
@@ -144,7 +146,7 @@ let ReapWorktreeCommand = class ReapWorktreeCommand {
144
146
  const branch = args[1] ?? '';
145
147
  const head = args[2] ?? '';
146
148
  if (worktreePath === '' || branch === '' || head === '') {
147
- throw new rules_config_1.InformAiError('\n' + SEP + '❌ wp-reap-worktree: missing arguments\n' + SEP + '\n'
149
+ throw new tooling_common_1.InformAiError('\n' + SEP + '❌ wp-reap-worktree: missing arguments\n' + SEP + '\n'
148
150
  + 'Usage: node wp-reap-worktree.js <worktree-path> <branch> <head-sha>\n\n'
149
151
  + 'This is an INTERNAL entry point, spawned by `pnpm wp-land-pr` with cwd set to the\n'
150
152
  + 'primary clone. To clean up by hand, run `pnpm wp-cleanup` from the primary clone.\n' + SEP);
@@ -158,7 +160,7 @@ exports.ReapWorktreeCommand = ReapWorktreeCommand = tslib_1.__decorate([
158
160
  tslib_1.__metadata("design:paramtypes", [rules_config_1.RepoRootFinder,
159
161
  worktree_cleanup_1.WorktreeCleanupSection,
160
162
  reap_outcome_1.ReapOutcomeSignal,
161
- rules_config_1.WorktreeService])
163
+ repo_workflow_core_1.WorktreeService])
162
164
  ], ReapWorktreeCommand);
163
165
  // Data-only (per CLAUDE.md, classes for data): the argv values this entry point takes.
164
166
  class ReapRequest {
@@ -1 +1 @@
1
- {"version":3,"file":"reap-worktree-command.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/commands/reap-worktree-command.ts"],"names":[],"mappings":";;;;AAAA,mDAA6B;AAC7B,0DAQiC;AACjC,yCAA2D;AAE3D,2DAKkC;AAElC,yDAA4D;AAE5D,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAEvE;;;;;;;;;;;;;;;;;;;;GAoBG;AAEI,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IAEP;IACA;IACA;IACA;IAJrB,YACqB,cAA8B,EAC9B,eAAuC,EACvC,MAAyB,EACzB,SAA0B;QAH1B,mBAAc,GAAd,cAAc,CAAgB;QAC9B,oBAAe,GAAf,eAAe,CAAwB;QACvC,WAAM,GAAN,MAAM,CAAmB;QACzB,cAAS,GAAT,SAAS,CAAiB;IAC5C,CAAC;IAEJ;;;;OAIG;IACH,KAAK,CAAC,GA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AAC,IAAI,EAAE,CAAC;QAC7B,MAAM,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QAC3B,IAAI,YAAY,KAAK,EAAE,IAAI,MAAM,KAAK,EAAE,IAAI,IAAI,KAAK,EAAE,EAAE,CAAC;YACtD,MAAM,IAAI,4BAAa,CACnB,IAAI,GAAG,GAAG,GAAG,yCAAyC,GAAG,GAAG,GAAG,IAAI;kBACjE,yEAAyE;kBACzE,qFAAqF;kBACrF,qFAAqF,GAAG,GAAG,CAAC,CAAC;QACvG,CAAC;QACD,OAAO,IAAI,WAAW,CAAC,YAAY,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;IACvD,CAAC;CACJ,CAAA;AAlIY,kDAAmB;8BAAnB,mBAAmB;IAD/B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGA,6BAAc;QACb,yCAAsB;QAC/B,gCAAiB;QACd,8BAAe;GALtC,mBAAmB,CAkI/B;AAED,uFAAuF;AACvF,MAAM,WAAW;IACb,YAAY,CAAS;IACrB,MAAM,CAAS;IACf,2FAA2F;IAC3F,IAAI,CAAS;IAEb,YAAY,YAAoB,EAAE,MAAc,EAAE,IAAY;QAC1D,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACrB,CAAC;CACJ","sourcesContent":["import * as path from 'path';\nimport {\n DeletableWorktree,\n InformAiError,\n RepoRootFinder,\n Worktree,\n WorktreeReapResult,\n WorktreeService,\n loadAndValidate,\n} from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\n\nimport {\n ReapOutcomeSignal,\n REAP_OUTCOME_FAILED,\n REAP_OUTCOME_REFUSED,\n REAP_OUTCOME_REMOVED,\n} from '../workflow/reap-outcome';\n\nimport { WorktreeCleanupSection } from './worktree-cleanup';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n/**\n * The CHILD side of `wp-land-pr`'s re-exec: reap ONE named worktree, from a process whose cwd is the\n * primary clone.\n *\n * It is not a published `bin`. Nothing about it is a verb a human should reach for — `pnpm wp-cleanup`\n * is that verb, and it does strictly more. This exists so the parent can hand off a SINGLE, already\n * identified corpse without also reaping every other agent's worktree as a side effect of landing one\n * PR. LandedWorktreeReaper spawns it by absolute path; see that class for why a child rather than a\n * `process.chdir`.\n *\n * WHAT IT WILL NOT TAKE ON TRUST. The parent tells it a path, a branch and the HEAD sha it selected the\n * tree by; it believes none of the three.\n * The verdict is recomputed here, from scratch, by the same MergedBranchesService that backs\n * `wp-cleanup` — so a worktree is removed only when it is PROVABLY dead (its PR is merged), and never\n * because a caller said so. That is what keeps \"never remove a tree still holding unmerged work\" true\n * even if the parent is wrong, out of date, or someone runs this by hand.\n *\n * The primary clone can never be a target: `classifyWorktrees` drops the main worktree from the\n * verdicts outright, so a path pointing at it simply does not resolve to a target — and WorktreeReaper\n * refuses it a second time by name. Neither rail is load-bearing alone.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class ReapWorktreeCommand {\n constructor(\n private readonly repoRootFinder: RepoRootFinder,\n private readonly worktreeSection: WorktreeCleanupSection,\n private readonly signal: ReapOutcomeSignal,\n private readonly worktrees: WorktreeService,\n ) {}\n\n /**\n * Every exit from here states an OUTCOME, because the exit code cannot: refusals exit 0 (see\n * `resolveTarget`), so a parent with only a status has no way to tell \"removed\" from \"declined to\n * remove\". The token is the last thing written, and LandedWorktreeReaper strips it before printing.\n */\n async run(args: string[]): Promise<void> {\n await Promise.resolve();\n const request = this.parse(args);\n const repoRoot = this.repoRootFinder.resolveRepoRoot(process.cwd());\n\n const target = this.resolveTarget(repoRoot, request);\n if (target === null) {\n process.stdout.write(this.signal.line(REAP_OUTCOME_REFUSED));\n return;\n }\n\n const retention = loadAndValidate(repoRoot).prGate.landPr.branchRetention;\n const result = this.worktreeSection.reap(repoRoot, 'wp-land-pr', [target], retention);\n process.stdout.write(this.render(repoRoot, result));\n process.stdout.write(this.signal.line(this.outcomeOf(result)));\n }\n\n /**\n * `reaped` is the only entry that means the DIRECTORY is gone. A tree that reached the reaper and\n * came back in neither list was spared by one of WorktreeReaper's own rails (it is the cwd, it is\n * the primary clone) — nothing was attempted, which is a refusal, not a failure.\n */\n private outcomeOf(result: WorktreeReapResult): string {\n if (result.reaped.length > 0) return REAP_OUTCOME_REMOVED;\n return result.failed.length > 0 ? REAP_OUTCOME_FAILED : REAP_OUTCOME_REFUSED;\n }\n\n /**\n * The verdict for the requested path, or null after printing WHY it is not reapable. Refusals are\n * printed rather than thrown: the PR they follow is already merged, and exiting non-zero after a\n * successful landing would report a landed PR as a failed command. That is exactly why `run` also\n * emits a ReapOutcomeSignal — the caller must be able to tell this exit 0 from a successful one.\n */\n private resolveTarget(repoRoot: string, request: ReapRequest): DeletableWorktree | null {\n const wanted = path.resolve(request.worktreePath);\n // `false`: this reaps ONE named worktree after its PR landed, and it is not the place to\n // override anybody's lock — a lock still standing here is exactly the refusal this prints.\n const target = this.worktreeSection.verdicts(repoRoot, false)\n .find((tree: DeletableWorktree): boolean => path.resolve(tree.path) === wanted);\n\n if (target === undefined) {\n process.stdout.write(\n `\\n ℹ️ ${request.worktreePath} is not a removable worktree of this repo (it may be the\\n`\n + ' primary clone, or already gone). Nothing removed.\\n');\n return null;\n }\n // The branch moved under us between landing and reaping — somebody checked something else out\n // there. Whatever that is, it is not the corpse we were asked to bury.\n if (target.branch !== request.branch) {\n process.stdout.write(\n `\\n ⚠️ ${request.worktreePath} now holds '${target.branch}', not '${request.branch}'.\\n`\n + ' Refusing to remove a worktree whose branch changed since the PR landed.\\n');\n return null;\n }\n // …and the NAME is not the identity. The parent selected this directory because its HEAD was the\n // exact commit GitHub squashed; that selection is recomputed here from git rather than taken on\n // trust, so a commit made in that tree between landing and reaping — work the archive tag of the\n // squashed tip does not contain — stops the removal instead of being buried with it.\n const here = this.headOf(repoRoot, wanted);\n if (here !== request.head) {\n process.stdout.write(\n `\\n ⚠️ ${request.worktreePath} is at ${here === '' ? '(unknown)' : here}, not the landed\\n`\n + ` commit ${request.head}.\\n`\n + ' Refusing to remove a worktree whose HEAD moved since the PR landed.\\n');\n return null;\n }\n if (!target.deletable) {\n process.stdout.write(\n `\\n ⚠️ ${request.worktreePath} is not provably dead: ${target.reason}\\n`\n + ' Refusing to remove a worktree that may still hold unmerged work.\\n');\n return null;\n }\n return target;\n }\n\n /**\n * That worktree's HEAD as git reports it right now, '' when git cannot place the path at all.\n * '' can never equal a real sha, so \"git would not answer\" fails SAFE — it declines the removal.\n */\n private headOf(repoRoot: string, resolvedPath: string): string {\n const tree = this.worktrees.listWorktrees(repoRoot)\n .find((candidate: Worktree): boolean => path.resolve(candidate.path) === resolvedPath);\n return tree?.head ?? '';\n }\n\n // The reap report, plus the spared case — which report() renders as '' because from wp-cleanup's\n // point of view \"nothing happened\" is a whole answer. Here it never is: we asked for exactly one.\n private render(repoRoot: string, result: WorktreeReapResult): string {\n if (result.reaped.length === 0 && result.failed.length === 0) {\n let out = '\\n' + SEP + '🛑 Nothing removed\\n' + SEP + '\\n';\n for (const tree of result.spared) out += ` · ${tree.path} — ${tree.reason}\\n`;\n return out;\n }\n return this.worktreeSection.report(repoRoot, result);\n }\n\n /**\n * `<worktree-path> <branch> <head-sha>`, all three required. The sha is not optional and has no\n * default: a defaulted '' would mean \"do not check\", i.e. exactly the name-only removal both\n * processes exist to refuse, so a caller that omits it must fail to run rather than run wider.\n *\n * Thrown rather than printed: bad argv means the caller is broken, and there is no landed PR in this\n * process whose success a non-zero exit could misreport.\n */\n private parse(args: string[]): ReapRequest {\n const worktreePath = args[0] ?? '';\n const branch = args[1] ?? '';\n const head = args[2] ?? '';\n if (worktreePath === '' || branch === '' || head === '') {\n throw new InformAiError(\n '\\n' + SEP + '❌ wp-reap-worktree: missing arguments\\n' + SEP + '\\n'\n + 'Usage: node wp-reap-worktree.js <worktree-path> <branch> <head-sha>\\n\\n'\n + 'This is an INTERNAL entry point, spawned by `pnpm wp-land-pr` with cwd set to the\\n'\n + 'primary clone. To clean up by hand, run `pnpm wp-cleanup` from the primary clone.\\n' + SEP);\n }\n return new ReapRequest(worktreePath, branch, head);\n }\n}\n\n// Data-only (per CLAUDE.md, classes for data): the argv values this entry point takes.\nclass ReapRequest {\n worktreePath: string;\n branch: string;\n /** The commit the parent proved this worktree was at — re-verified here, never trusted. */\n head: string;\n\n constructor(worktreePath: string, branch: string, head: string) {\n this.worktreePath = worktreePath;\n this.branch = branch;\n this.head = head;\n }\n}\n"]}
1
+ {"version":3,"file":"reap-worktree-command.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/commands/reap-worktree-command.ts"],"names":[],"mappings":";;;;AAAA,mDAA6B;AAC7B,sEAAiH;AACjH,8DAA0D;AAC1D,0DAA0E;AAC1E,yCAA2D;AAE3D,2DAKkC;AAElC,yDAA4D;AAE5D,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAEvE;;;;;;;;;;;;;;;;;;;;GAoBG;AAEI,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IAEP;IACA;IACA;IACA;IAJrB,YACqB,cAA8B,EAC9B,eAAuC,EACvC,MAAyB,EACzB,SAA0B;QAH1B,mBAAc,GAAd,cAAc,CAAgB;QAC9B,oBAAe,GAAf,eAAe,CAAwB;QACvC,WAAM,GAAN,MAAM,CAAmB;QACzB,cAAS,GAAT,SAAS,CAAiB;IAC5C,CAAC;IAEJ;;;;OAIG;IACH,KAAK,CAAC,GAAG,CAAC,IAAc;QACpB,MAAM,OAAO,CAAC,OAAO,EAAE,CAAC;QACxB,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACjC,MAAM,QAAQ,GAAG,IAAI,CAAC,cAAc,CAAC,eAAe,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;QAEpE,MAAM,MAAM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AAyC,GAAG,GAAG,GAAG,IAAI;kBACjE,yEAAyE;kBACzE,qFAAqF;kBACrF,qFAAqF,GAAG,GAAG,CAAC,CAAC;QACvG,CAAC;QACD,OAAO,IAAI,WAAW,CAAC,YAAY,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;IACvD,CAAC;CACJ,CAAA;AAlIY,kDAAmB;8BAAnB,mBAAmB;IAD/B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGA,6BAAc;QACb,yCAAsB;QAC/B,gCAAiB;QACd,oCAAe;GALtC,mBAAmB,CAkI/B;AAED,uFAAuF;AACvF,MAAM,WAAW;IACb,YAAY,CAAS;IACrB,MAAM,CAAS;IACf,2FAA2F;IAC3F,IAAI,CAAS;IAEb,YAAY,YAAoB,EAAE,MAAc,EAAE,IAAY;QAC1D,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACrB,CAAC;CACJ","sourcesContent":["import * as path from 'path';\nimport { DeletableWorktree, Worktree, WorktreeReapResult, WorktreeService } from '@webpieces/repo-workflow-core';\nimport { InformAiError } from '@webpieces/tooling-common';\nimport { RepoRootFinder, loadAndValidate } from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\n\nimport {\n ReapOutcomeSignal,\n REAP_OUTCOME_FAILED,\n REAP_OUTCOME_REFUSED,\n REAP_OUTCOME_REMOVED,\n} from '../workflow/reap-outcome';\n\nimport { WorktreeCleanupSection } from './worktree-cleanup';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n/**\n * The CHILD side of `wp-land-pr`'s re-exec: reap ONE named worktree, from a process whose cwd is the\n * primary clone.\n *\n * It is not a published `bin`. Nothing about it is a verb a human should reach for — `pnpm wp-cleanup`\n * is that verb, and it does strictly more. This exists so the parent can hand off a SINGLE, already\n * identified corpse without also reaping every other agent's worktree as a side effect of landing one\n * PR. LandedWorktreeReaper spawns it by absolute path; see that class for why a child rather than a\n * `process.chdir`.\n *\n * WHAT IT WILL NOT TAKE ON TRUST. The parent tells it a path, a branch and the HEAD sha it selected the\n * tree by; it believes none of the three.\n * The verdict is recomputed here, from scratch, by the same MergedBranchesService that backs\n * `wp-cleanup` — so a worktree is removed only when it is PROVABLY dead (its PR is merged), and never\n * because a caller said so. That is what keeps \"never remove a tree still holding unmerged work\" true\n * even if the parent is wrong, out of date, or someone runs this by hand.\n *\n * The primary clone can never be a target: `classifyWorktrees` drops the main worktree from the\n * verdicts outright, so a path pointing at it simply does not resolve to a target — and WorktreeReaper\n * refuses it a second time by name. Neither rail is load-bearing alone.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class ReapWorktreeCommand {\n constructor(\n private readonly repoRootFinder: RepoRootFinder,\n private readonly worktreeSection: WorktreeCleanupSection,\n private readonly signal: ReapOutcomeSignal,\n private readonly worktrees: WorktreeService,\n ) {}\n\n /**\n * Every exit from here states an OUTCOME, because the exit code cannot: refusals exit 0 (see\n * `resolveTarget`), so a parent with only a status has no way to tell \"removed\" from \"declined to\n * remove\". The token is the last thing written, and LandedWorktreeReaper strips it before printing.\n */\n async run(args: string[]): Promise<void> {\n await Promise.resolve();\n const request = this.parse(args);\n const repoRoot = this.repoRootFinder.resolveRepoRoot(process.cwd());\n\n const target = this.resolveTarget(repoRoot, request);\n if (target === null) {\n process.stdout.write(this.signal.line(REAP_OUTCOME_REFUSED));\n return;\n }\n\n const retention = loadAndValidate(repoRoot).prGate.landPr.branchRetention;\n const result = this.worktreeSection.reap(repoRoot, 'wp-land-pr', [target], retention);\n process.stdout.write(this.render(repoRoot, result));\n process.stdout.write(this.signal.line(this.outcomeOf(result)));\n }\n\n /**\n * `reaped` is the only entry that means the DIRECTORY is gone. A tree that reached the reaper and\n * came back in neither list was spared by one of WorktreeReaper's own rails (it is the cwd, it is\n * the primary clone) — nothing was attempted, which is a refusal, not a failure.\n */\n private outcomeOf(result: WorktreeReapResult): string {\n if (result.reaped.length > 0) return REAP_OUTCOME_REMOVED;\n return result.failed.length > 0 ? REAP_OUTCOME_FAILED : REAP_OUTCOME_REFUSED;\n }\n\n /**\n * The verdict for the requested path, or null after printing WHY it is not reapable. Refusals are\n * printed rather than thrown: the PR they follow is already merged, and exiting non-zero after a\n * successful landing would report a landed PR as a failed command. That is exactly why `run` also\n * emits a ReapOutcomeSignal — the caller must be able to tell this exit 0 from a successful one.\n */\n private resolveTarget(repoRoot: string, request: ReapRequest): DeletableWorktree | null {\n const wanted = path.resolve(request.worktreePath);\n // `false`: this reaps ONE named worktree after its PR landed, and it is not the place to\n // override anybody's lock — a lock still standing here is exactly the refusal this prints.\n const target = this.worktreeSection.verdicts(repoRoot, false)\n .find((tree: DeletableWorktree): boolean => path.resolve(tree.path) === wanted);\n\n if (target === undefined) {\n process.stdout.write(\n `\\n ℹ️ ${request.worktreePath} is not a removable worktree of this repo (it may be the\\n`\n + ' primary clone, or already gone). Nothing removed.\\n');\n return null;\n }\n // The branch moved under us between landing and reaping — somebody checked something else out\n // there. Whatever that is, it is not the corpse we were asked to bury.\n if (target.branch !== request.branch) {\n process.stdout.write(\n `\\n ⚠️ ${request.worktreePath} now holds '${target.branch}', not '${request.branch}'.\\n`\n + ' Refusing to remove a worktree whose branch changed since the PR landed.\\n');\n return null;\n }\n // …and the NAME is not the identity. The parent selected this directory because its HEAD was the\n // exact commit GitHub squashed; that selection is recomputed here from git rather than taken on\n // trust, so a commit made in that tree between landing and reaping — work the archive tag of the\n // squashed tip does not contain — stops the removal instead of being buried with it.\n const here = this.headOf(repoRoot, wanted);\n if (here !== request.head) {\n process.stdout.write(\n `\\n ⚠️ ${request.worktreePath} is at ${here === '' ? '(unknown)' : here}, not the landed\\n`\n + ` commit ${request.head}.\\n`\n + ' Refusing to remove a worktree whose HEAD moved since the PR landed.\\n');\n return null;\n }\n if (!target.deletable) {\n process.stdout.write(\n `\\n ⚠️ ${request.worktreePath} is not provably dead: ${target.reason}\\n`\n + ' Refusing to remove a worktree that may still hold unmerged work.\\n');\n return null;\n }\n return target;\n }\n\n /**\n * That worktree's HEAD as git reports it right now, '' when git cannot place the path at all.\n * '' can never equal a real sha, so \"git would not answer\" fails SAFE — it declines the removal.\n */\n private headOf(repoRoot: string, resolvedPath: string): string {\n const tree = this.worktrees.listWorktrees(repoRoot)\n .find((candidate: Worktree): boolean => path.resolve(candidate.path) === resolvedPath);\n return tree?.head ?? '';\n }\n\n // The reap report, plus the spared case — which report() renders as '' because from wp-cleanup's\n // point of view \"nothing happened\" is a whole answer. Here it never is: we asked for exactly one.\n private render(repoRoot: string, result: WorktreeReapResult): string {\n if (result.reaped.length === 0 && result.failed.length === 0) {\n let out = '\\n' + SEP + '🛑 Nothing removed\\n' + SEP + '\\n';\n for (const tree of result.spared) out += ` · ${tree.path} — ${tree.reason}\\n`;\n return out;\n }\n return this.worktreeSection.report(repoRoot, result);\n }\n\n /**\n * `<worktree-path> <branch> <head-sha>`, all three required. The sha is not optional and has no\n * default: a defaulted '' would mean \"do not check\", i.e. exactly the name-only removal both\n * processes exist to refuse, so a caller that omits it must fail to run rather than run wider.\n *\n * Thrown rather than printed: bad argv means the caller is broken, and there is no landed PR in this\n * process whose success a non-zero exit could misreport.\n */\n private parse(args: string[]): ReapRequest {\n const worktreePath = args[0] ?? '';\n const branch = args[1] ?? '';\n const head = args[2] ?? '';\n if (worktreePath === '' || branch === '' || head === '') {\n throw new InformAiError(\n '\\n' + SEP + '❌ wp-reap-worktree: missing arguments\\n' + SEP + '\\n'\n + 'Usage: node wp-reap-worktree.js <worktree-path> <branch> <head-sha>\\n\\n'\n + 'This is an INTERNAL entry point, spawned by `pnpm wp-land-pr` with cwd set to the\\n'\n + 'primary clone. To clean up by hand, run `pnpm wp-cleanup` from the primary clone.\\n' + SEP);\n }\n return new ReapRequest(worktreePath, branch, head);\n }\n}\n\n// Data-only (per CLAUDE.md, classes for data): the argv values this entry point takes.\nclass ReapRequest {\n worktreePath: string;\n branch: string;\n /** The commit the parent proved this worktree was at — re-verified here, never trusted. */\n head: string;\n\n constructor(worktreePath: string, branch: string, head: string) {\n this.worktreePath = worktreePath;\n this.branch = branch;\n this.head = head;\n }\n}\n"]}
@@ -4,6 +4,7 @@ exports.SyncMainCommand = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const inversify_1 = require("inversify");
6
6
  const rules_config_1 = require("@webpieces/rules-config");
7
+ const tooling_common_1 = require("@webpieces/tooling-common");
7
8
  const cleanup_command_1 = require("./cleanup-command");
8
9
  const cleanup_options_1 = require("./cleanup-options");
9
10
  const main_checkout_1 = require("./main-checkout");
@@ -97,7 +98,7 @@ let SyncMainCommand = class SyncMainCommand {
97
98
  return Promise.resolve();
98
99
  }
99
100
  isLinkedWorktree(repoRoot) {
100
- const dirs = rules_config_1.dotWebpieces.gitDirs(repoRoot);
101
+ const dirs = tooling_common_1.dotWebpieces.gitDirs(repoRoot);
101
102
  return dirs !== null && dirs.isLinkedWorktree;
102
103
  }
103
104
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"sync-main-command.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/commands/sync-main-command.ts"],"names":[],"mappings":";;;;AAAA,yCAA2D;AAC3D,0DAIiC;AAEjC,uDAAmD;AACnD,uDAK2B;AAC3B,mDAA6D;AAC7D,2DAAsE;AAEtE,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAEvE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAEI,IAAM,eAAe,GAArB,MAAM,eAAe;IAEH;IACA;IACA;IACA;IACA;IALrB,YACqB,cAA8B,EAC9B,cAA8B,EAC9B,gBAAkC,EAClC,eAAgC,EAChC,YAA0B;QAJ1B,mBAAc,GAAd,cAAc,CAAgB;QAC9B,mBAAc,GAAd,cAAc,CAAgB;QAC9B,qBAAgB,GAAhB,gBAAgB,CAAkB;Q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SAAS,CAAC;6CAGA,6BAAc;QACd,gCAAc;QACZ,+BAAgB;QACjB,mCAAe;QAClB,4BAAY;GANtC,eAAe,CA0F3B","sourcesContent":["import { injectable, bindingScopeValues } from 'inversify';\nimport {\n OrphanDirSweeper,\n RepoRootFinder,\n dotWebpieces,\n} from '@webpieces/rules-config';\n\nimport { CleanupCommand } from './cleanup-command';\nimport {\n CleanupOptions,\n DeleteSelection,\n FLAG_DELETE_BRANCHES,\n FLAG_DELETE_WORKTREES,\n} from './cleanup-options';\nimport { MainCheckout, StashedFiles } from './main-checkout';\nimport { WorkingTreeGate, UntrackedFiles } from './working-tree-gate';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n/**\n * `wp-sync-main` — go to main, get main, and take out the trash. ONE command, because the three\n * are one intention and splitting them is what let the third never happen.\n *\n * ─── ITS RELATIONSHIP TO `git checkout main && git pull origin main` (READ BEFORE \"DELETING\" THAT) ────\n * That pair was already the enforced spelling: bare `git checkout main` is blocked precisely so the pull\n * rides along. This command is the same pairing with cleanup and the sweep welded on, and the WORKFLOW\n * messages now prescribe this instead — two spellings where one sweeps and one does not is shim shape\n * #1, an agent types whichever is accepted and the corpses accumulate forever.\n *\n * The raw pair is NOT deleted, and the reason is a constraint that outranks the shim rule: it is a\n * TERMINAL ENTRY ON THE L0 ALLOWLIST (`CHECKOUT_MAIN_PULL_CMD` in ai-hook-rules\n * `src/bin/l0-allowlist.ts`, consumed as an L0 cure in `src/core/l0-matrix.ts`) — one of\n * the few commands still permitted while an L0 block denies every other tool call. In exactly that\n * state, `node_modules` is the thing that is untrustworthy, so a `pnpm wp-*` bin is the one kind of cure\n * that cannot be relied on to run. The same reasoning covers the L0 shim's own fix option in\n * `templates/ai-hook.sh` (rendered from `src/bin/shim-drift-fix.ts`).\n *\n * So the end state is TWO LAYERS, not a deletion, and it is now in place:\n * • L0 recovery (l0-allowlist, shim-drift-fix, l0-matrix) → keeps the raw pair. It is not a shim\n * there; it is the only thing that works when the package manager's output is what is in doubt.\n * • the WORKFLOW layer (stale-main-bash-guard's preferred cure, merged-branch-message/-bash-guard,\n * TreeRecovery's cleanupSteps and updateMainSteps, the L2 rows/doc, CLAUDE.md's \"Finishing a\n * Feature\") → prescribes `pnpm wp-sync-main`, and no longer prints the pair.\n *\n * The pair remains ALLOWED as a Bash command in both layers — this changed what the guards TEACH, not\n * what they permit. Blocking it would have deleted the L0 escape along with the shim.\n *\n * ─── WHY GOING TO MAIN IS THE RIGHT MOMENT TO SWEEP ───────────────────────────────────────────────────\n * The corpses appear when git moves the working tree onto a base where the tracked files under some\n * directory are gone. Landing a PR and returning to main is when every developer does that, on every\n * clone, roughly once per merged PR — so a sweep bolted here converges the whole team's machines with no\n * new trigger, no git hook to distribute, and no background daemon. It is also the quietest moment in the\n * day to move directories: nothing is building, no dev server is watching files.\n *\n * ─── WHY THE ORDER IS FIXED AND NOT PARALLEL ──────────────────────────────────────────────────────────\n * Cleanup runs BEFORE the sweep and not beside it. `wp-cleanup` removes dead worktrees, which changes\n * what is on disk, and a scan racing that would be reading a tree mid-demolition. The scan is one\n * ignore-walk and costs about a second; there is no wall-clock worth buying with that race.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class SyncMainCommand {\n constructor(\n private readonly repoRootFinder: RepoRootFinder,\n private readonly cleanupCommand: CleanupCommand,\n private readonly orphanDirSweeper: OrphanDirSweeper,\n private readonly workingTreeGate: WorkingTreeGate,\n private readonly mainCheckout: MainCheckout,\n ) {}\n\n async run(): Promise<void> {\n const repoRoot = this.repoRootFinder.resolveRepoRoot(process.cwd());\n process.stdout.write(`${SEP}🧹 Checkout main, pull, clean\\n${SEP}\\n`);\n if (this.isLinkedWorktree(repoRoot)) {\n await this.sweepOnly(repoRoot);\n return;\n }\n const untracked = this.workingTreeGate.assertNoTrackedChanges(repoRoot);\n const stashed = this.mainCheckout.goToMain(repoRoot, untracked);\n this.reportUntracked(untracked, stashed);\n // No flags: this is the \"go to main and take out the trash\" path, so cleanup behaves exactly as a\n // bare `pnpm wp-cleanup` does here — reap what is provably dead and every zero-commit husk, ask\n // (or report) about the rest. Spelled out rather than defaulted so that if CleanupOptions ever\n // grows a field, this call site is a compile error instead of a silent old behaviour.\n await this.cleanupCommand.run(new CleanupOptions(\n new DeleteSelection(FLAG_DELETE_BRANCHES, false, ''),\n new DeleteSelection(FLAG_DELETE_WORKTREES, false, ''),\n false, false, false));\n this.sweep(repoRoot);\n this.reportStashed(stashed);\n }\n\n /**\n * A linked worktree has no main to check out — `git checkout main` FATALS there with \"main is already\n * checked out at <primary clone>\", which is a footgun `.claude/rules/finishing-a-feature.md`\n * currently has to warn about in prose.\n * So the command does the half that IS meaningful here (worktrees accumulate corpses too, if a\n * long-lived one keeps merging main in) and says plainly where the other half lives.\n */\n private async sweepOnly(repoRoot: string): Promise<void> {\n process.stdout.write(\n 'This is a linked WORKTREE. main is checked out in the primary clone, so there is nothing\\n'\n + 'here to check out or pull — sweeping this tree only.\\n\\n'\n + 'Most worktrees never need this: `wp-cleanup` removes the whole directory once its branch\\n'\n + 'lands, which takes any orphan directories inside it along. Run this command again from the\\n'\n + 'primary clone to go to main there.\\n\\n');\n this.sweep(repoRoot);\n return Promise.resolve();\n }\n\n private isLinkedWorktree(repoRoot: string): boolean {\n const dirs = dotWebpieces.gitDirs(repoRoot);\n return dirs !== null && dirs.isLinkedWorktree;\n }\n\n /**\n * Say which untracked files were let through, AFTER the move — so nobody has to wonder whether the\n * files still sitting in their tree came along for the ride. Printed rather than refused on: see\n * `WorkingTreeGate` for why an untracked file is not the hazard a tracked one is.\n *\n * Silent when the checkout had to stash: those files are NOT sitting in the tree any more, and\n * \"nothing about them changed\" would be a lie. `reportStashed` speaks for that case instead.\n */\n private reportUntracked(untracked: UntrackedFiles, stashed: StashedFiles): void {\n if (!stashed.isEmpty()) return;\n const rendered = untracked.render();\n if (rendered === '') return;\n process.stdout.write(`\\n${rendered}`);\n }\n\n /**\n * The stash banner goes LAST, on purpose. It is the one thing in this command's output a reader\n * must not miss — their files left the working tree — and the cleanup and sweep that follow the\n * checkout print enough to scroll it away if it were emitted where it happened.\n */\n private reportStashed(stashed: StashedFiles): void {\n const rendered = stashed.render();\n if (rendered === '') return;\n process.stdout.write(`\\n${rendered}`);\n }\n\n /**\n * Sweep, then print. Never throws: the checkout and pull above already succeeded, and a tidier is not\n * permitted to turn somebody's completed sync into a failed command.\n */\n private sweep(repoRoot: string): void {\n const report = this.orphanDirSweeper.sweep(repoRoot, new Date());\n const rendered = report.render();\n if (rendered === '') return;\n process.stdout.write(`\\n${rendered}`);\n }\n}\n"]}
1
+ {"version":3,"file":"sync-main-command.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/commands/sync-main-command.ts"],"names":[],"mappings":";;;;AAAA,yCAA2D;AAC3D,0DAA2E;AAC3E,8DAAyD;AAEzD,uDAAmD;AACnD,uDAK2B;AAC3B,mDAA6D;AAC7D,2DAAsE;AAEtE,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAEvE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAEI,IAAM,eAAe,GAArB,MAAM,eAAe;IAEH;IACA;IACA;IACA;IACA;IALrB,YACqB,cAA8B,EAC9B,cAA8B,EAC9B,gBAAkC,EAClC,eAAgC,EAChC,YAA0B;QAJ1B,mBAAc,GAAd,cAAc,CAAgB;QAC9B,mBAAc,GAAd,cAAc,CAAgB;QAC9B,qBAAgB,GAAhB,gBAAgB,CAAkB;QAClC,oBAAe,GAAf,eAAe,CAAiB;QAChC,iBAAY,GAAZ,YAAY,CAAc;IAC5C,CAAC;IAEJ,KAAK,CAAC,GAAG;QACL,MAAM,QAAQ,GAAG,IAAI,CAAC,cAAc,CAAC,eAAe,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;QACpE,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,GAAG,kCAAkC,GAAG,IAAI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gBAAgB,CAAC;IAClD,CAAC;IAED;;;;;;;OAOG;IACK,eAAe,CAAC,SAAyB,EAAE,OAAqB;QACpE,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE;YAAE,OAAO;QAC/B,MAAM,QAAQ,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC;QACpC,IAAI,QAAQ,KAAK,EAAE;YAAE,OAAO;QAC5B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,QAAQ,EAAE,CAAC,CAAC;IAC1C,CAAC;IAED;;;;OAIG;IACK,aAAa,CAAC,OAAqB;QACvC,MAAM,QAAQ,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;QAClC,IAAI,QAAQ,KAAK,EAAE;YAAE,OAAO;QAC5B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,QAAQ,EAAE,CAAC,CAAC;IAC1C,CAAC;IAED;;;OAGG;IACK,KAAK,CAAC,QAAgB;QAC1B,MAAM,MAAM,GAAG,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,IAAI,EAAE,CAAC,CAAC;QACjE,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC;QACjC,IAAI,QAAQ,KAAK,EAAE;YAAE,OAAO;QAC5B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,QAAQ,EAAE,CAAC,CAAC;IAC1C,CAAC;CACJ,CAAA;AA1FY,0CAAe;0BAAf,eAAe;IAD3B,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAGA,6BAAc;QACd,gCAAc;QACZ,+BAAgB;QACjB,mCAAe;QAClB,4BAAY;GANtC,eAAe,CA0F3B","sourcesContent":["import { injectable, bindingScopeValues } from 'inversify';\nimport { OrphanDirSweeper, RepoRootFinder } from '@webpieces/rules-config';\nimport { dotWebpieces } from '@webpieces/tooling-common';\n\nimport { CleanupCommand } from './cleanup-command';\nimport {\n CleanupOptions,\n DeleteSelection,\n FLAG_DELETE_BRANCHES,\n FLAG_DELETE_WORKTREES,\n} from './cleanup-options';\nimport { MainCheckout, StashedFiles } from './main-checkout';\nimport { WorkingTreeGate, UntrackedFiles } from './working-tree-gate';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n/**\n * `wp-sync-main` — go to main, get main, and take out the trash. ONE command, because the three\n * are one intention and splitting them is what let the third never happen.\n *\n * ─── ITS RELATIONSHIP TO `git checkout main && git pull origin main` (READ BEFORE \"DELETING\" THAT) ────\n * That pair was already the enforced spelling: bare `git checkout main` is blocked precisely so the pull\n * rides along. This command is the same pairing with cleanup and the sweep welded on, and the WORKFLOW\n * messages now prescribe this instead — two spellings where one sweeps and one does not is shim shape\n * #1, an agent types whichever is accepted and the corpses accumulate forever.\n *\n * The raw pair is NOT deleted, and the reason is a constraint that outranks the shim rule: it is a\n * TERMINAL ENTRY ON THE L0 ALLOWLIST (`CHECKOUT_MAIN_PULL_CMD` in ai-hook-rules\n * `src/bin/l0-allowlist.ts`, consumed as an L0 cure in `src/core/l0-matrix.ts`) — one of\n * the few commands still permitted while an L0 block denies every other tool call. In exactly that\n * state, `node_modules` is the thing that is untrustworthy, so a `pnpm wp-*` bin is the one kind of cure\n * that cannot be relied on to run. The same reasoning covers the L0 shim's own fix option in\n * `templates/ai-hook.sh` (rendered from `src/bin/shim-drift-fix.ts`).\n *\n * So the end state is TWO LAYERS, not a deletion, and it is now in place:\n * • L0 recovery (l0-allowlist, shim-drift-fix, l0-matrix) → keeps the raw pair. It is not a shim\n * there; it is the only thing that works when the package manager's output is what is in doubt.\n * • the WORKFLOW layer (stale-main-bash-guard's preferred cure, merged-branch-message/-bash-guard,\n * TreeRecovery's cleanupSteps and updateMainSteps, the L2 rows/doc, CLAUDE.md's \"Finishing a\n * Feature\") → prescribes `pnpm wp-sync-main`, and no longer prints the pair.\n *\n * The pair remains ALLOWED as a Bash command in both layers — this changed what the guards TEACH, not\n * what they permit. Blocking it would have deleted the L0 escape along with the shim.\n *\n * ─── WHY GOING TO MAIN IS THE RIGHT MOMENT TO SWEEP ───────────────────────────────────────────────────\n * The corpses appear when git moves the working tree onto a base where the tracked files under some\n * directory are gone. Landing a PR and returning to main is when every developer does that, on every\n * clone, roughly once per merged PR — so a sweep bolted here converges the whole team's machines with no\n * new trigger, no git hook to distribute, and no background daemon. It is also the quietest moment in the\n * day to move directories: nothing is building, no dev server is watching files.\n *\n * ─── WHY THE ORDER IS FIXED AND NOT PARALLEL ──────────────────────────────────────────────────────────\n * Cleanup runs BEFORE the sweep and not beside it. `wp-cleanup` removes dead worktrees, which changes\n * what is on disk, and a scan racing that would be reading a tree mid-demolition. The scan is one\n * ignore-walk and costs about a second; there is no wall-clock worth buying with that race.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class SyncMainCommand {\n constructor(\n private readonly repoRootFinder: RepoRootFinder,\n private readonly cleanupCommand: CleanupCommand,\n private readonly orphanDirSweeper: OrphanDirSweeper,\n private readonly workingTreeGate: WorkingTreeGate,\n private readonly mainCheckout: MainCheckout,\n ) {}\n\n async run(): Promise<void> {\n const repoRoot = this.repoRootFinder.resolveRepoRoot(process.cwd());\n process.stdout.write(`${SEP}🧹 Checkout main, pull, clean\\n${SEP}\\n`);\n if (this.isLinkedWorktree(repoRoot)) {\n await this.sweepOnly(repoRoot);\n return;\n }\n const untracked = this.workingTreeGate.assertNoTrackedChanges(repoRoot);\n const stashed = this.mainCheckout.goToMain(repoRoot, untracked);\n this.reportUntracked(untracked, stashed);\n // No flags: this is the \"go to main and take out the trash\" path, so cleanup behaves exactly as a\n // bare `pnpm wp-cleanup` does here — reap what is provably dead and every zero-commit husk, ask\n // (or report) about the rest. Spelled out rather than defaulted so that if CleanupOptions ever\n // grows a field, this call site is a compile error instead of a silent old behaviour.\n await this.cleanupCommand.run(new CleanupOptions(\n new DeleteSelection(FLAG_DELETE_BRANCHES, false, ''),\n new DeleteSelection(FLAG_DELETE_WORKTREES, false, ''),\n false, false, false));\n this.sweep(repoRoot);\n this.reportStashed(stashed);\n }\n\n /**\n * A linked worktree has no main to check out — `git checkout main` FATALS there with \"main is already\n * checked out at <primary clone>\", which is a footgun `.claude/rules/finishing-a-feature.md`\n * currently has to warn about in prose.\n * So the command does the half that IS meaningful here (worktrees accumulate corpses too, if a\n * long-lived one keeps merging main in) and says plainly where the other half lives.\n */\n private async sweepOnly(repoRoot: string): Promise<void> {\n process.stdout.write(\n 'This is a linked WORKTREE. main is checked out in the primary clone, so there is nothing\\n'\n + 'here to check out or pull — sweeping this tree only.\\n\\n'\n + 'Most worktrees never need this: `wp-cleanup` removes the whole directory once its branch\\n'\n + 'lands, which takes any orphan directories inside it along. Run this command again from the\\n'\n + 'primary clone to go to main there.\\n\\n');\n this.sweep(repoRoot);\n return Promise.resolve();\n }\n\n private isLinkedWorktree(repoRoot: string): boolean {\n const dirs = dotWebpieces.gitDirs(repoRoot);\n return dirs !== null && dirs.isLinkedWorktree;\n }\n\n /**\n * Say which untracked files were let through, AFTER the move — so nobody has to wonder whether the\n * files still sitting in their tree came along for the ride. Printed rather than refused on: see\n * `WorkingTreeGate` for why an untracked file is not the hazard a tracked one is.\n *\n * Silent when the checkout had to stash: those files are NOT sitting in the tree any more, and\n * \"nothing about them changed\" would be a lie. `reportStashed` speaks for that case instead.\n */\n private reportUntracked(untracked: UntrackedFiles, stashed: StashedFiles): void {\n if (!stashed.isEmpty()) return;\n const rendered = untracked.render();\n if (rendered === '') return;\n process.stdout.write(`\\n${rendered}`);\n }\n\n /**\n * The stash banner goes LAST, on purpose. It is the one thing in this command's output a reader\n * must not miss — their files left the working tree — and the cleanup and sweep that follow the\n * checkout print enough to scroll it away if it were emitted where it happened.\n */\n private reportStashed(stashed: StashedFiles): void {\n const rendered = stashed.render();\n if (rendered === '') return;\n process.stdout.write(`\\n${rendered}`);\n }\n\n /**\n * Sweep, then print. Never throws: the checkout and pull above already succeeded, and a tidier is not\n * permitted to turn somebody's completed sync into a failed command.\n */\n private sweep(repoRoot: string): void {\n const report = this.orphanDirSweeper.sweep(repoRoot, new Date());\n const rendered = report.render();\n if (rendered === '') return;\n process.stdout.write(`\\n${rendered}`);\n }\n}\n"]}
@@ -1,4 +1,5 @@
1
- import { BranchIdentity, GateTokenService, PrGateConfig, RepoRootFinder, ReviewJsonService } from '@webpieces/rules-config';
1
+ import { BranchIdentity } from '@webpieces/repo-workflow-core';
2
+ import { GateTokenService, PrGateConfig, RepoRootFinder, ReviewJsonService } from '@webpieces/rules-config';
2
3
  import { AiBranchName } from '../workflow/git-readAiBranchName';
3
4
  import { GitExec } from '../workflow/git-exec';
4
5
  import { BuildAffected } from '../workflow/build-affected';
@@ -5,6 +5,7 @@ const tslib_1 = require("tslib");
5
5
  const child_process_1 = require("child_process");
6
6
  const fs = tslib_1.__importStar(require("fs"));
7
7
  const path = tslib_1.__importStar(require("path"));
8
+ const repo_workflow_core_1 = require("@webpieces/repo-workflow-core");
8
9
  const rules_config_1 = require("@webpieces/rules-config");
9
10
  const inversify_1 = require("inversify");
10
11
  const git_readAiBranchName_1 = require("../workflow/git-readAiBranchName");
@@ -258,7 +259,7 @@ exports.UpsertHotfixPrCommand = UpsertHotfixPrCommand;
258
259
  exports.UpsertHotfixPrCommand = UpsertHotfixPrCommand = tslib_1.__decorate([
259
260
  (0, inversify_1.injectable)(inversify_1.bindingScopeValues.Singleton),
260
261
  tslib_1.__metadata("design:paramtypes", [rules_config_1.RepoRootFinder,
261
- rules_config_1.BranchIdentity,
262
+ repo_workflow_core_1.BranchIdentity,
262
263
  git_readAiBranchName_1.AiBranchName,
263
264
  git_exec_1.GitExec,
264
265
  rules_config_1.ReviewJsonService,
@@ -1 +1 @@
1
- {"version":3,"file":"upsert-hotfix-pr-command.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/commands/upsert-hotfix-pr-command.ts"],"names":[],"mappings":";;;;AAAA,iDAA0C;AAC1C,+CAAyB;AACzB,mDAA6B;AA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BAAc;QAChB,mCAAY;QACjB,kBAAO;QACG,gCAAiB;QACrB,8BAAa;QACT,uCAAiB;QACxB,wBAAU;QACJ,oCAAgB;QACvB,uCAAiB;QACjB,qBAAS;QACJ,wCAAsB;QACpB,qDAAwB;QACzB,uCAAiB;QAClB,iDAAsB;QACpB,+BAAgB;GAlB9C,qBAAqB,CAuNjC","sourcesContent":["import { spawnSync } from 'child_process';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport {\n BranchIdentity,\n CliExitError,\n GateTokenService,\n PrGateConfig,\n PrSummary,\n RepoRootFinder,\n ReviewJsonService,\n loadAndValidate,\n writeTemplate,\n} from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { AiBranchName } from '../workflow/git-readAiBranchName';\nimport { GitExec } from '../workflow/git-exec';\nimport { BuildAffected, BuildGateOptions } from '../workflow/build-affected';\nimport { BuildArtifactGate } from '../workflow/build-artifact-gate';\nimport { FINISH_STAGE } from '../workflow/build-gate-log';\nimport { MergeState } from '../workflow/merge-state';\nimport { ChecklistScanOptions, ChecklistScanner } from '../workflow/checklist-scanner';\nimport { TriggeredChecklist } from '../workflow/checklist-detector';\nimport { HotfixPrPublisher } from '../workflow/hotfix-pr-publisher';\nimport { UPSERT_HOTFIX_PR_COMMAND } from '../workflow/hotfix-redirect';\nimport { PrCommentRequest, PrCommentUpserter } from '../workflow/pr-comment-upserter';\nimport { SquashSettingsEnforcer } from '../workflow/squash-settings-enforcer';\nimport { Dashboard, DashboardInput, DETAIL_COMMENT_MARKER } from '../../dashboard/dashboard';\nimport { ChecklistCommentRenderer, CHECKLIST_COMMENT_MARKER } from '../../dashboard/checklist-comment-renderer';\nimport { ChecklistCommentRow } from '../../dashboard/checklist-comment-row';\nimport { AuthorIdentityResolver } from '../../dashboard/author-identity';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n/** The PR this run landed on. Both '' when it could not be resolved. Data-only, per CLAUDE.md. */\nexport class HotfixPrRef {\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 * `wp-upsert-hotfix-pr` — the ONE command that publishes a `/hotfix/` branch (issue #1057).\n *\n * A hotfix branch is cut from the exact sha running in production, so that what ships is production plus\n * the fix and nothing else. The three-stage PR flow cannot publish it: stage ① merges main into the branch,\n * which turns \"prod + fix\" into \"main + fix\" and ships every commit that has landed but has not been\n * promoted. And a hotfix runs no reviewers, so the stages have nothing to do between them. This is the\n * whole flow, in one command, in this order:\n *\n * 1. refuse unless the branch carries the exact, case-sensitive `/hotfix/` segment;\n * 2. require a clean tree and summary.json — a missing one prints its path and schema and exits;\n * 3. run ONLY the `hotfix-ci` gate (build + test). Red means nothing is pushed;\n * 4. NEVER merge main into the branch, never squash it, never rewrite it — HEAD is checked unchanged;\n * 5. push ONCE, fast-forward only, as a child process (pr-creation-or-push-guard stays intact);\n * 6. create or update the audit-bannered PR to main, and NEVER enable auto-merge — the consumer merges\n * after it has deployed and verified the hotfix. Re-running after another commit pushes again and\n * updates the same PR.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class UpsertHotfixPrCommand {\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(\n private readonly repoRootFinder: RepoRootFinder,\n private readonly branchIdentity: BranchIdentity,\n private readonly aiBranchName: AiBranchName,\n private readonly gitExec: GitExec,\n private readonly reviewJsonService: ReviewJsonService,\n private readonly buildAffected: BuildAffected,\n private readonly buildArtifactGate: BuildArtifactGate,\n private readonly mergeState: MergeState,\n private readonly checklistScanner: ChecklistScanner,\n private readonly publisher: HotfixPrPublisher,\n private readonly dashboard: Dashboard,\n private readonly authorIdentity: AuthorIdentityResolver,\n private readonly checklistComment: ChecklistCommentRenderer,\n private readonly commentUpserter: PrCommentUpserter,\n private readonly squashSettings: SquashSettingsEnforcer,\n private readonly gateTokenService: GateTokenService,\n ) {}\n\n async run(): Promise<void> {\n const repoRoot = this.repoRootFinder.resolveRepoRoot(process.cwd());\n const branch = this.branchIdentity.current();\n // FIRST, before any write: a non-hotfix branch gets nothing from this command, not even a template.\n this.assertHotfixBranch(branch);\n writeTemplate(repoRoot, 'webpieces.git-workflow.md');\n this.gitExec.assertCleanTree(repoRoot);\n this.assertNoUnvalidatedMerge(repoRoot);\n\n const featureName = this.aiBranchName.getFeatureName();\n const summaryPath = this.reviewJsonService.summaryJsonPath(repoRoot, featureName);\n // Throws InformAiError carrying the path and the schema when summary.json is missing or invalid.\n const summary = this.reviewJsonService.loadSummaryJson(summaryPath, [], '', {}, UPSERT_HOTFIX_PR_COMMAND);\n\n // origin/main is READ (the build's merge-base and the dashboard's fork point) — never merged.\n this.fetchMain(repoRoot);\n const headBefore = this.headSha(repoRoot);\n await this.buildAffected.runBuildGate(\n repoRoot,\n new BuildGateOptions('🛠️ Hotfix build gate (hotfix-ci: build + test only)', UPSERT_HOTFIX_PR_COMMAND, 'Hotfix build failed — nothing was pushed and no PR was created or updated.', FINISH_STAGE),\n );\n this.buildArtifactGate.assertBuildLeftNothingUncommitted(repoRoot);\n this.gitExec.assertCleanTree(repoRoot);\n if (this.headSha(repoRoot) !== headBefore) {\n throw new CliExitError(1, `❌ HEAD moved while the hotfix build ran, so the build does not cover the commit that would be pushed. Nothing was pushed. Re-run ${UPSERT_HOTFIX_PR_COMMAND}.`);\n }\n\n const ref = this.publish(repoRoot, branch, summary, headBefore);\n this.postComments(repoRoot, featureName, ref, summary);\n this.squashSettings.ensure();\n const archived = this.reviewJsonService.archiveSummaryJson(summaryPath);\n if (archived !== '') process.stdout.write(` archived this run's summary.json → ${archived} (audit only) ✓\\n`);\n process.stdout.write(this.closingBlock(ref, summary.title, branch));\n }\n\n private assertHotfixBranch(branch: string): void {\n if (this.branchIdentity.isHotfix(branch)) return;\n throw new CliExitError(\n 1,\n `wp-upsert-hotfix-pr only runs on a branch containing the exact, case-sensitive /hotfix/ segment; '${branch}' does not.\\n` +\n 'Nothing was changed. A normal branch is published with the three-stage flow:\\n' +\n ' pnpm wp-start-upsert-pr\\n pnpm wp-review-upsert-pr\\n pnpm wp-finish-upsert-pr',\n );\n }\n\n // A hotfix flow never STARTS a merge, but a branch somebody ran wp-start-update on can carry one.\n private assertNoUnvalidatedMerge(repoRoot: string): void {\n const home = this.mergeState.mergeDirFor(repoRoot, this.aiBranchName.getFeatureName());\n const active = this.mergeState.findActiveMergeRunDir(home);\n const marker = active === null ? null : this.mergeState.readMergeMarker(active);\n if (marker === null || marker.validated) return;\n throw new CliExitError(\n 1,\n 'wp-upsert-hotfix-pr refuses a branch with an active, unvalidated 3-point merge. A hotfix branch must\\n' +\n 'not take main at all: abort that merge and return the branch to the production sha plus your fix\\n' +\n `commits, then re-run ${UPSERT_HOTFIX_PR_COMMAND}. Nothing was pushed.`,\n );\n }\n\n /** Body before push (GatedPrPublisher's ordering), fast-forward push, then create or edit — never merge. */\n private publish(repoRoot: string, branch: string, summary: PrSummary, headSha: string): HotfixPrRef {\n const config = this.prGateConfig(repoRoot);\n const input = this.dashboardInput(repoRoot, summary, config);\n const tokenSuffix = this.tokenSuffix(config.gateSalt, headSha);\n const initial = this.prRef(branch);\n const body = this.dashboard.renderPrBody(input, initial.url) + tokenSuffix;\n const bodyFile = path.join(this.reviewJsonService.prDirFor(repoRoot, this.aiBranchName.getFeatureName()), 'pr-body.md');\n fs.mkdirSync(path.dirname(bodyFile), { recursive: true });\n fs.writeFileSync(bodyFile, body + '\\n');\n\n process.stdout.write('\\n' + SEP + '📋 Hotfix PR (bannered audit, never auto-merged)\\n' + SEP + '\\n');\n const published = this.publisher.publish(branch, this.titleFrom(summary, branch), bodyFile, UPSERT_HOTFIX_PR_COMMAND);\n if (published.createFailed) {\n throw new CliExitError(1, `❌ gh pr create failed after the push. The rendered body is in ${bodyFile}; summary.json was kept. Re-run ${UPSERT_HOTFIX_PR_COMMAND}.`);\n }\n const ref = this.prRef(branch);\n const resolved = new HotfixPrRef(ref.number !== '' ? ref.number : published.number, ref.url);\n // A brand-new PR had no URL to self-link until `gh pr create` returned one.\n const finalBody = this.dashboard.renderPrBody(input, resolved.url) + tokenSuffix;\n if (finalBody !== body && resolved.number !== '') {\n fs.writeFileSync(bodyFile, finalBody + '\\n');\n if (!this.editPrBody(resolved.number, bodyFile)) {\n process.stderr.write(`⚠️ Could not add the PR's own link to its description (non-fatal — the PR and the gate token are up).\\n`);\n }\n }\n return resolved;\n }\n\n private dashboardInput(repoRoot: string, summary: PrSummary, config: PrGateConfig): DashboardInput {\n const forkPoint = this.git(repoRoot, ['merge-base', 'origin/main', 'HEAD']);\n const featureHead = this.git(repoRoot, ['rev-parse', 'HEAD']);\n const mainHead = this.git(repoRoot, ['rev-parse', 'origin/main']);\n const range = `${forkPoint}..${featureHead}`;\n const changedFiles = this.git(repoRoot, ['diff', range, '--name-only'])\n .split('\\n')\n .filter((f: string): boolean => f.trim() !== '');\n const gateResults = this.dashboard.computeGateResults(config.gates, changedFiles);\n const disables = this.dashboard.countAddedDisables(this.git(repoRoot, ['diff', range]));\n const buildCommand = this.buildAffected.resolveBuildCommand(repoRoot);\n const title = this.titleFrom(summary, this.branchIdentity.current());\n return new DashboardInput(title, gateResults, disables, true, forkPoint, featureHead, mainHead, summary, [], buildCommand, 0, this.authorIdentity.resolve(summary.model), true);\n }\n\n /** The 1st comment (full dashboard) and, when the repo defines checklists, the bypassed-roster 2nd. */\n private postComments(repoRoot: string, featureName: string, ref: HotfixPrRef, summary: PrSummary): void {\n if (ref.number === '') {\n process.stderr.write(`⚠️ Could not resolve the PR number after the push, so the audit comments were not posted. The PR body\\n still carries the hotfix banner. Re-run ${UPSERT_HOTFIX_PR_COMMAND} to post them.\\n`);\n return;\n }\n const config = this.prGateConfig(repoRoot);\n const prDir = this.reviewJsonService.prDirFor(repoRoot, featureName);\n const detail = new PrCommentRequest();\n detail.prNumber = ref.number;\n detail.marker = DETAIL_COMMENT_MARKER;\n // The audit banner must be the FIRST thing on the comment, so the marker goes last.\n detail.body = this.dashboard.renderDetailComment(this.dashboardInput(repoRoot, summary, config)) + '\\n\\n' + DETAIL_COMMENT_MARKER;\n detail.payloadDir = prDir;\n detail.payloadName = 'detail-comment.json';\n detail.label = 'full dashboard comment';\n this.commentUpserter.upsert(detail);\n\n if (config.checklists.length === 0 || !config.checklistComments) return;\n const scan = this.checklistScanner.scan(repoRoot, config.checklists, new ChecklistScanOptions(config.maxReviewerRounds, false, ''));\n const rows = scan.roster.entries.map(\n (entry: TriggeredChecklist): ChecklistCommentRow =>\n new ChecklistCommentRow('none', 'none', entry.def.id, '', '', entry.matchedFiles.length > 0, entry.def.patterns, entry.matchedPatterns, entry.matchedFiles, scan.roster.changedFileCount),\n );\n const roster = new PrCommentRequest();\n roster.prNumber = ref.number;\n roster.marker = CHECKLIST_COMMENT_MARKER;\n roster.body = this.checklistComment.render(rows, false, scan.roster.baseResolved, 0, true);\n roster.payloadDir = prDir;\n roster.payloadName = 'checklist-comment.json';\n roster.label = 'checklist review comment';\n this.commentUpserter.upsert(roster);\n }\n\n private closingBlock(ref: HotfixPrRef, title: string, branch: string): string {\n const link = ref.url === '' ? '(PR URL unresolved — see the gh output above)' : ref.url;\n return (\n '\\n' +\n SEP +\n `✅ Hotfix PR ${ref.number === '' ? '' : `#${ref.number} `}is up — NOT merged, and auto-merge was NOT enabled\\n` +\n SEP +\n '\\n' +\n ' 1. ran hotfix-ci (build + test only); lint, validators and reviewers are bypassed and bannered\\n' +\n ` 2. pushed ${branch} fast-forward only — main was never merged in and the branch was not rewritten\\n` +\n ` 3. wrote the audit-bannered body to the PR titled: \"${title}\"\\n\\n` +\n ' A hotfix PR is never auto-merged. Deploy and verify the hotfix first; the merge to main is then a\\n' +\n ' deliberate step (pnpm wp-land-pr). Another commit on this branch? Commit it and re-run\\n' +\n ` ${UPSERT_HOTFIX_PR_COMMAND} — it pushes again and updates this same PR.\\n\\n` +\n `🔗 ${link}\\n`\n );\n }\n\n private tokenSuffix(gateSalt: string, headSha: string): string {\n const marker = this.gateTokenService.gateTokenMarker(gateSalt, headSha);\n return marker === '' ? '' : `\\n\\n${marker}\\n`;\n }\n\n private titleFrom(summary: PrSummary, branch: string): string {\n return summary.title !== '' ? summary.title : branch.replace(/[-/]+/g, ' ').trim();\n }\n\n private headSha(repoRoot: string): string {\n return this.git(repoRoot, ['rev-parse', 'HEAD']);\n }\n\n private git(repoRoot: string, args: string[]): string {\n return this.gitExec.gitQuery(args, repoRoot, `git ${args.join(' ')} failed in ${repoRoot}`);\n }\n\n // ── seams, protected so the spec drives them with no network, no gh and no webpieces.config.json ──\n\n protected prGateConfig(repoRoot: string): PrGateConfig {\n return loadAndValidate(repoRoot).prGate;\n }\n\n protected fetchMain(repoRoot: string): void {\n const out = this.gitExec.tryGit(['fetch', 'origin', 'main'], repoRoot);\n if (out.ok) return;\n throw new CliExitError(1, `❌ Could not fetch origin/main (needed to READ the fork point — it is never merged). Nothing was pushed.\\n git said: ${out.stderr}`);\n }\n\n protected prRef(branch: string): HotfixPrRef {\n const out = spawnSync('gh', ['pr', 'view', branch, '--json', 'number,url', '--jq', '\"\\\\(.number)\\\\t\\\\(.url)\"'], { encoding: 'utf8' });\n if (out.status !== 0) return new HotfixPrRef('', '');\n const parts = (out.stdout ?? '').trim().split('\\t');\n return new HotfixPrRef(parts[0] ?? '', parts[1] ?? '');\n }\n\n protected editPrBody(prNumber: string, bodyFile: string): boolean {\n return spawnSync('gh', ['pr', 'edit', prNumber, '--body-file', bodyFile], { stdio: 'inherit' }).status === 0;\n }\n}\n"]}
1
+ {"version":3,"file":"upsert-hotfix-pr-command.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/commands/upsert-hotfix-pr-command.ts"],"names":[],"mappings":";;;;AAAA,iDAA0C;AAC1C,+CAAyB;AACzB,mDAA6B;AAC7B,sEAA+D;AAC/D,0DAAqK;AACrK,yCAA2D;AAC3D,2EAAgE;AAChE,mDAA+C;AAC/C,+DAA6E;AAC7E,yEAAoE;AACpE,+DAA0D;AAC1D,yDAA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ACjB,qBAAS;QACJ,wCAAsB;QACpB,qDAAwB;QACzB,uCAAiB;QAClB,iDAAsB;QACpB,+BAAgB;GAlB9C,qBAAqB,CAuNjC","sourcesContent":["import { spawnSync } from 'child_process';\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport { BranchIdentity } from '@webpieces/repo-workflow-core';\nimport { CliExitError, GateTokenService, PrGateConfig, PrSummary, RepoRootFinder, ReviewJsonService, loadAndValidate, writeTemplate } from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { AiBranchName } from '../workflow/git-readAiBranchName';\nimport { GitExec } from '../workflow/git-exec';\nimport { BuildAffected, BuildGateOptions } from '../workflow/build-affected';\nimport { BuildArtifactGate } from '../workflow/build-artifact-gate';\nimport { FINISH_STAGE } from '../workflow/build-gate-log';\nimport { MergeState } from '../workflow/merge-state';\nimport { ChecklistScanOptions, ChecklistScanner } from '../workflow/checklist-scanner';\nimport { TriggeredChecklist } from '../workflow/checklist-detector';\nimport { HotfixPrPublisher } from '../workflow/hotfix-pr-publisher';\nimport { UPSERT_HOTFIX_PR_COMMAND } from '../workflow/hotfix-redirect';\nimport { PrCommentRequest, PrCommentUpserter } from '../workflow/pr-comment-upserter';\nimport { SquashSettingsEnforcer } from '../workflow/squash-settings-enforcer';\nimport { Dashboard, DashboardInput, DETAIL_COMMENT_MARKER } from '../../dashboard/dashboard';\nimport { ChecklistCommentRenderer, CHECKLIST_COMMENT_MARKER } from '../../dashboard/checklist-comment-renderer';\nimport { ChecklistCommentRow } from '../../dashboard/checklist-comment-row';\nimport { AuthorIdentityResolver } from '../../dashboard/author-identity';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n/** The PR this run landed on. Both '' when it could not be resolved. Data-only, per CLAUDE.md. */\nexport class HotfixPrRef {\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 * `wp-upsert-hotfix-pr` — the ONE command that publishes a `/hotfix/` branch (issue #1057).\n *\n * A hotfix branch is cut from the exact sha running in production, so that what ships is production plus\n * the fix and nothing else. The three-stage PR flow cannot publish it: stage ① merges main into the branch,\n * which turns \"prod + fix\" into \"main + fix\" and ships every commit that has landed but has not been\n * promoted. And a hotfix runs no reviewers, so the stages have nothing to do between them. This is the\n * whole flow, in one command, in this order:\n *\n * 1. refuse unless the branch carries the exact, case-sensitive `/hotfix/` segment;\n * 2. require a clean tree and summary.json — a missing one prints its path and schema and exits;\n * 3. run ONLY the `hotfix-ci` gate (build + test). Red means nothing is pushed;\n * 4. NEVER merge main into the branch, never squash it, never rewrite it — HEAD is checked unchanged;\n * 5. push ONCE, fast-forward only, as a child process (pr-creation-or-push-guard stays intact);\n * 6. create or update the audit-bannered PR to main, and NEVER enable auto-merge — the consumer merges\n * after it has deployed and verified the hotfix. Re-running after another commit pushes again and\n * updates the same PR.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class UpsertHotfixPrCommand {\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(\n private readonly repoRootFinder: RepoRootFinder,\n private readonly branchIdentity: BranchIdentity,\n private readonly aiBranchName: AiBranchName,\n private readonly gitExec: GitExec,\n private readonly reviewJsonService: ReviewJsonService,\n private readonly buildAffected: BuildAffected,\n private readonly buildArtifactGate: BuildArtifactGate,\n private readonly mergeState: MergeState,\n private readonly checklistScanner: ChecklistScanner,\n private readonly publisher: HotfixPrPublisher,\n private readonly dashboard: Dashboard,\n private readonly authorIdentity: AuthorIdentityResolver,\n private readonly checklistComment: ChecklistCommentRenderer,\n private readonly commentUpserter: PrCommentUpserter,\n private readonly squashSettings: SquashSettingsEnforcer,\n private readonly gateTokenService: GateTokenService,\n ) {}\n\n async run(): Promise<void> {\n const repoRoot = this.repoRootFinder.resolveRepoRoot(process.cwd());\n const branch = this.branchIdentity.current();\n // FIRST, before any write: a non-hotfix branch gets nothing from this command, not even a template.\n this.assertHotfixBranch(branch);\n writeTemplate(repoRoot, 'webpieces.git-workflow.md');\n this.gitExec.assertCleanTree(repoRoot);\n this.assertNoUnvalidatedMerge(repoRoot);\n\n const featureName = this.aiBranchName.getFeatureName();\n const summaryPath = this.reviewJsonService.summaryJsonPath(repoRoot, featureName);\n // Throws InformAiError carrying the path and the schema when summary.json is missing or invalid.\n const summary = this.reviewJsonService.loadSummaryJson(summaryPath, [], '', {}, UPSERT_HOTFIX_PR_COMMAND);\n\n // origin/main is READ (the build's merge-base and the dashboard's fork point) — never merged.\n this.fetchMain(repoRoot);\n const headBefore = this.headSha(repoRoot);\n await this.buildAffected.runBuildGate(\n repoRoot,\n new BuildGateOptions('🛠️ Hotfix build gate (hotfix-ci: build + test only)', UPSERT_HOTFIX_PR_COMMAND, 'Hotfix build failed — nothing was pushed and no PR was created or updated.', FINISH_STAGE),\n );\n this.buildArtifactGate.assertBuildLeftNothingUncommitted(repoRoot);\n this.gitExec.assertCleanTree(repoRoot);\n if (this.headSha(repoRoot) !== headBefore) {\n throw new CliExitError(1, `❌ HEAD moved while the hotfix build ran, so the build does not cover the commit that would be pushed. Nothing was pushed. Re-run ${UPSERT_HOTFIX_PR_COMMAND}.`);\n }\n\n const ref = this.publish(repoRoot, branch, summary, headBefore);\n this.postComments(repoRoot, featureName, ref, summary);\n this.squashSettings.ensure();\n const archived = this.reviewJsonService.archiveSummaryJson(summaryPath);\n if (archived !== '') process.stdout.write(` archived this run's summary.json → ${archived} (audit only) ✓\\n`);\n process.stdout.write(this.closingBlock(ref, summary.title, branch));\n }\n\n private assertHotfixBranch(branch: string): void {\n if (this.branchIdentity.isHotfix(branch)) return;\n throw new CliExitError(\n 1,\n `wp-upsert-hotfix-pr only runs on a branch containing the exact, case-sensitive /hotfix/ segment; '${branch}' does not.\\n` +\n 'Nothing was changed. A normal branch is published with the three-stage flow:\\n' +\n ' pnpm wp-start-upsert-pr\\n pnpm wp-review-upsert-pr\\n pnpm wp-finish-upsert-pr',\n );\n }\n\n // A hotfix flow never STARTS a merge, but a branch somebody ran wp-start-update on can carry one.\n private assertNoUnvalidatedMerge(repoRoot: string): void {\n const home = this.mergeState.mergeDirFor(repoRoot, this.aiBranchName.getFeatureName());\n const active = this.mergeState.findActiveMergeRunDir(home);\n const marker = active === null ? null : this.mergeState.readMergeMarker(active);\n if (marker === null || marker.validated) return;\n throw new CliExitError(\n 1,\n 'wp-upsert-hotfix-pr refuses a branch with an active, unvalidated 3-point merge. A hotfix branch must\\n' +\n 'not take main at all: abort that merge and return the branch to the production sha plus your fix\\n' +\n `commits, then re-run ${UPSERT_HOTFIX_PR_COMMAND}. Nothing was pushed.`,\n );\n }\n\n /** Body before push (GatedPrPublisher's ordering), fast-forward push, then create or edit — never merge. */\n private publish(repoRoot: string, branch: string, summary: PrSummary, headSha: string): HotfixPrRef {\n const config = this.prGateConfig(repoRoot);\n const input = this.dashboardInput(repoRoot, summary, config);\n const tokenSuffix = this.tokenSuffix(config.gateSalt, headSha);\n const initial = this.prRef(branch);\n const body = this.dashboard.renderPrBody(input, initial.url) + tokenSuffix;\n const bodyFile = path.join(this.reviewJsonService.prDirFor(repoRoot, this.aiBranchName.getFeatureName()), 'pr-body.md');\n fs.mkdirSync(path.dirname(bodyFile), { recursive: true });\n fs.writeFileSync(bodyFile, body + '\\n');\n\n process.stdout.write('\\n' + SEP + '📋 Hotfix PR (bannered audit, never auto-merged)\\n' + SEP + '\\n');\n const published = this.publisher.publish(branch, this.titleFrom(summary, branch), bodyFile, UPSERT_HOTFIX_PR_COMMAND);\n if (published.createFailed) {\n throw new CliExitError(1, `❌ gh pr create failed after the push. The rendered body is in ${bodyFile}; summary.json was kept. Re-run ${UPSERT_HOTFIX_PR_COMMAND}.`);\n }\n const ref = this.prRef(branch);\n const resolved = new HotfixPrRef(ref.number !== '' ? ref.number : published.number, ref.url);\n // A brand-new PR had no URL to self-link until `gh pr create` returned one.\n const finalBody = this.dashboard.renderPrBody(input, resolved.url) + tokenSuffix;\n if (finalBody !== body && resolved.number !== '') {\n fs.writeFileSync(bodyFile, finalBody + '\\n');\n if (!this.editPrBody(resolved.number, bodyFile)) {\n process.stderr.write(`⚠️ Could not add the PR's own link to its description (non-fatal — the PR and the gate token are up).\\n`);\n }\n }\n return resolved;\n }\n\n private dashboardInput(repoRoot: string, summary: PrSummary, config: PrGateConfig): DashboardInput {\n const forkPoint = this.git(repoRoot, ['merge-base', 'origin/main', 'HEAD']);\n const featureHead = this.git(repoRoot, ['rev-parse', 'HEAD']);\n const mainHead = this.git(repoRoot, ['rev-parse', 'origin/main']);\n const range = `${forkPoint}..${featureHead}`;\n const changedFiles = this.git(repoRoot, ['diff', range, '--name-only'])\n .split('\\n')\n .filter((f: string): boolean => f.trim() !== '');\n const gateResults = this.dashboard.computeGateResults(config.gates, changedFiles);\n const disables = this.dashboard.countAddedDisables(this.git(repoRoot, ['diff', range]));\n const buildCommand = this.buildAffected.resolveBuildCommand(repoRoot);\n const title = this.titleFrom(summary, this.branchIdentity.current());\n return new DashboardInput(title, gateResults, disables, true, forkPoint, featureHead, mainHead, summary, [], buildCommand, 0, this.authorIdentity.resolve(summary.model), true);\n }\n\n /** The 1st comment (full dashboard) and, when the repo defines checklists, the bypassed-roster 2nd. */\n private postComments(repoRoot: string, featureName: string, ref: HotfixPrRef, summary: PrSummary): void {\n if (ref.number === '') {\n process.stderr.write(`⚠️ Could not resolve the PR number after the push, so the audit comments were not posted. The PR body\\n still carries the hotfix banner. Re-run ${UPSERT_HOTFIX_PR_COMMAND} to post them.\\n`);\n return;\n }\n const config = this.prGateConfig(repoRoot);\n const prDir = this.reviewJsonService.prDirFor(repoRoot, featureName);\n const detail = new PrCommentRequest();\n detail.prNumber = ref.number;\n detail.marker = DETAIL_COMMENT_MARKER;\n // The audit banner must be the FIRST thing on the comment, so the marker goes last.\n detail.body = this.dashboard.renderDetailComment(this.dashboardInput(repoRoot, summary, config)) + '\\n\\n' + DETAIL_COMMENT_MARKER;\n detail.payloadDir = prDir;\n detail.payloadName = 'detail-comment.json';\n detail.label = 'full dashboard comment';\n this.commentUpserter.upsert(detail);\n\n if (config.checklists.length === 0 || !config.checklistComments) return;\n const scan = this.checklistScanner.scan(repoRoot, config.checklists, new ChecklistScanOptions(config.maxReviewerRounds, false, ''));\n const rows = scan.roster.entries.map(\n (entry: TriggeredChecklist): ChecklistCommentRow =>\n new ChecklistCommentRow('none', 'none', entry.def.id, '', '', entry.matchedFiles.length > 0, entry.def.patterns, entry.matchedPatterns, entry.matchedFiles, scan.roster.changedFileCount),\n );\n const roster = new PrCommentRequest();\n roster.prNumber = ref.number;\n roster.marker = CHECKLIST_COMMENT_MARKER;\n roster.body = this.checklistComment.render(rows, false, scan.roster.baseResolved, 0, true);\n roster.payloadDir = prDir;\n roster.payloadName = 'checklist-comment.json';\n roster.label = 'checklist review comment';\n this.commentUpserter.upsert(roster);\n }\n\n private closingBlock(ref: HotfixPrRef, title: string, branch: string): string {\n const link = ref.url === '' ? '(PR URL unresolved — see the gh output above)' : ref.url;\n return (\n '\\n' +\n SEP +\n `✅ Hotfix PR ${ref.number === '' ? '' : `#${ref.number} `}is up — NOT merged, and auto-merge was NOT enabled\\n` +\n SEP +\n '\\n' +\n ' 1. ran hotfix-ci (build + test only); lint, validators and reviewers are bypassed and bannered\\n' +\n ` 2. pushed ${branch} fast-forward only — main was never merged in and the branch was not rewritten\\n` +\n ` 3. wrote the audit-bannered body to the PR titled: \"${title}\"\\n\\n` +\n ' A hotfix PR is never auto-merged. Deploy and verify the hotfix first; the merge to main is then a\\n' +\n ' deliberate step (pnpm wp-land-pr). Another commit on this branch? Commit it and re-run\\n' +\n ` ${UPSERT_HOTFIX_PR_COMMAND} — it pushes again and updates this same PR.\\n\\n` +\n `🔗 ${link}\\n`\n );\n }\n\n private tokenSuffix(gateSalt: string, headSha: string): string {\n const marker = this.gateTokenService.gateTokenMarker(gateSalt, headSha);\n return marker === '' ? '' : `\\n\\n${marker}\\n`;\n }\n\n private titleFrom(summary: PrSummary, branch: string): string {\n return summary.title !== '' ? summary.title : branch.replace(/[-/]+/g, ' ').trim();\n }\n\n private headSha(repoRoot: string): string {\n return this.git(repoRoot, ['rev-parse', 'HEAD']);\n }\n\n private git(repoRoot: string, args: string[]): string {\n return this.gitExec.gitQuery(args, repoRoot, `git ${args.join(' ')} failed in ${repoRoot}`);\n }\n\n // ── seams, protected so the spec drives them with no network, no gh and no webpieces.config.json ──\n\n protected prGateConfig(repoRoot: string): PrGateConfig {\n return loadAndValidate(repoRoot).prGate;\n }\n\n protected fetchMain(repoRoot: string): void {\n const out = this.gitExec.tryGit(['fetch', 'origin', 'main'], repoRoot);\n if (out.ok) return;\n throw new CliExitError(1, `❌ Could not fetch origin/main (needed to READ the fork point — it is never merged). Nothing was pushed.\\n git said: ${out.stderr}`);\n }\n\n protected prRef(branch: string): HotfixPrRef {\n const out = spawnSync('gh', ['pr', 'view', branch, '--json', 'number,url', '--jq', '\"\\\\(.number)\\\\t\\\\(.url)\"'], { encoding: 'utf8' });\n if (out.status !== 0) return new HotfixPrRef('', '');\n const parts = (out.stdout ?? '').trim().split('\\t');\n return new HotfixPrRef(parts[0] ?? '', parts[1] ?? '');\n }\n\n protected editPrBody(prNumber: string, bodyFile: string): boolean {\n return spawnSync('gh', ['pr', 'edit', prNumber, '--body-file', bodyFile], { stdio: 'inherit' }).status === 0;\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { BranchMutationLog, MutationVerb, DeletableWorktree, MergedBranchesService, WorktreeReapResult, WorktreeReaper, WorktreeService, WorktreeWorkInFlight } from '@webpieces/rules-config';
1
+ import { BranchMutationLog, MutationVerb, DeletableWorktree, MergedBranchesService, WorktreeReapResult, WorktreeReaper, WorktreeService, WorktreeWorkInFlight } from '@webpieces/repo-workflow-core';
2
2
  /**
3
3
  * The WORKTREE half of `wp-cleanup` — the verdicts, the reap and the human-facing text.
4
4
  *