@webpieces/pr-gate 0.4.954 → 0.4.956

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webpieces/pr-gate",
3
- "version": "0.4.954",
3
+ "version": "0.4.956",
4
4
  "description": "Gated PR system: 3-point squash-merge, merge validation gate, and red/yellow/green PR dashboard. Standalone scripts, no Nx dependency required.",
5
5
  "type": "commonjs",
6
6
  "main": "./src/index.js",
@@ -16,18 +16,18 @@
16
16
  },
17
17
  "dependencies": {
18
18
  "@inversifyjs/binding-decorators": "1.1.5",
19
- "@webpieces/hook-runtime": "0.4.954",
20
- "@webpieces/rules-config": "0.4.954",
19
+ "@webpieces/hook-runtime": "0.4.956",
20
+ "@webpieces/rules-config": "0.4.956",
21
21
  "inversify": "7.10.4",
22
22
  "reflect-metadata": "0.2.2",
23
- "@webpieces/tooling-common": "0.4.954",
24
- "@webpieces/repo-workflow-core": "0.4.954"
23
+ "@webpieces/tooling-common": "0.4.956",
24
+ "@webpieces/repo-workflow-core": "0.4.956"
25
25
  },
26
26
  "publishConfig": {
27
27
  "access": "public"
28
28
  },
29
29
  "devDependencies": {
30
- "@webpieces/tooling-testkit": "0.4.954"
30
+ "@webpieces/tooling-testkit": "0.4.956"
31
31
  },
32
32
  "types": "./src/index.d.ts",
33
33
  "bin": {
@@ -144,7 +144,7 @@ let LandPrCommand = class LandPrCommand {
144
144
  bookkeeping +
145
145
  (policy === rules_config_1.MERGE_MODE_AUTO
146
146
  ? ''
147
- : ` (pr-gate.mergeMode is ${policy} — wp-finish-upsert-pr will keep leaving PRs for a human.)\n`) +
147
+ : ` (pr-gate.mergeMode is ${policy} — wp-finish-upsert-pr publishes PRs without attempting a merge.)\n`) +
148
148
  '\n');
149
149
  }
150
150
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"land-pr-command.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-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AAU;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
+ {"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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ACZ,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 { InformAiError } from '@webpieces/tooling-common';\nimport { toError } from '@webpieces/tooling-common/to-error';\nimport { RepoRootFinder, MERGE_MODE_AUTO, loadAndValidate } from '@webpieces/rules-config';\nimport { BranchArchiver, BRANCH_RETENTION_ARCHIVE_TAG, BRANCH_RETENTION_KEEP } from '@webpieces/repo-workflow-core';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { AiBranchName } from '../workflow/git-readAiBranchName';\nimport { BranchNaming } from '../workflow/branch-naming';\nimport { LandedTree, LandedTreeResolver, LANDED_TREE_ABSENT } from '../workflow/landed-tree-resolver';\nimport { LandedWorktreeReaper, WorktreeReapHandoff } from '../workflow/landed-worktree-reaper';\nimport { MergeBodyTempFile } from '../workflow/merge-body-temp-file';\nimport { ArchiveRecord, MergeInfoIndex } from '../workflow/merge-info-index';\nimport { MergeIntent, PrMerger } from '../workflow/pr-merger';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n/**\n * `wp-land-pr`: squash-merge THIS branch's already-posted PR into main with the compact commit body.\n *\n * It exists because a merge clicked in the GitHub UI cannot set the squash SUBJECT to `<title> (#N)`\n * and cannot archive the pre-squash tip. So when a merge has to happen outside `wp-finish-upsert-pr`\n * (a mergeMode=NONE repo, or a PR whose checks were still running when finish ran), this is the command\n * that keeps main's history consistent and finishes the branch's bookkeeping.\n *\n * ─── Where the bytes come from: THE PR ITSELF ──────────────────────────────────────────────────────\n * `wp-finish-upsert-pr` renders ONE string and publishes it as the PR DESCRIPTION, and the full\n * dashboard lives in the PR's comments (see `pr-body-is-merge-body.spec.ts`, which pins that the\n * description and the merge body are one renderer's output). So the description IS the gated squash\n * body, held by GitHub, and landing reads it back with `gh pr view --json body`.\n *\n * THE BYTES THAT LAND ARE THE BYTES FINISH PRODUCED — that invariant is unchanged; what changed is that\n * GitHub, not this machine, is the thing holding them. That removes the whole machine-global receipt\n * store: a cache of a fact the remote already owns, which could only ever be missing, stale, or on the\n * wrong computer. Landing from a second clone, a fresh clone, or another machine entirely now just\n * works. See `decisions/0005-the-pr-description-is-the-merge-body.md`.\n *\n * It still deliberately does NOT re-render the body: re-deriving it at land time would be a second\n * authoritative gate whose result nobody reads, and it could silently disagree with what was reviewed.\n *\n * ─── Two scopes, and only one of them is the tree's ────────────────────────────────────────────────\n * 1. THE MERGE, which belongs to the PR — and is therefore reachable from anywhere.\n * 2. THE BOOKKEEPING — archiving the pre-squash tip as `archive/<date>/<branch>`, promoting merge-info,\n * and reaping the landed worktree. That half belongs to the tree whose `<branch>` really is the\n * commit being squashed, and it must NOT be attempted from anywhere else: another clone's\n * `<branch>` is a different commit, so archiving it there would tag the wrong objects under the\n * right name.\n *\n * ─── WHICH tree that is, is a FACT — it is not \"the one I am standing in\" ──────────────────────────\n * That distinction used to be resolved from `process.cwd()`, and it was wrong twice over.\n *\n * It was wrong MECHANICALLY: `pnpm` hoists a bin's cwd to the workspace root, and a Claude Code agent\n * worktree lives at `<primary>/.claude/worktrees/agent-<id>` — INSIDE the primary clone — so pnpm walked\n * straight past it and `git branch --show-current` answered `main`. Landing a worktree PR, i.e. every\n * `/full-cycle` run, reported \"No open PR found for this branch\" for a PR that was open, and the #512\n * worktree reap was unreachable dead code. The invocation directory is now read from `INIT_CWD` (pnpm\n * exports the directory the human actually typed in) and given to BOTH the repo-root resolution and the\n * `git` call, so neither can be answered by the hoisted directory.\n *\n * And it was wrong in PRINCIPLE, which is the larger half: most of the time the `/full-cycle` subagent\n * lands its own PR, but many times it does not — CI was still running when it finished, it errored, or a\n * coordinator picks the work up an hour later, by which point that agent is gone and its worktree is a\n * directory nobody is standing in. So `--pr <n>` names the PR, and {@link LandedTreeResolver} finds its\n * tree by the pair `(headRefName, headRefOid)` — never by branch name alone. The reap target is the\n * worktree whose HEAD is the exact commit GitHub squashed, whichever directory the operator is in, and\n * when nothing local holds that commit the merge still happens and the bookkeeping is SKIPPED OUT LOUD.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class LandPrCommand {\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(\n private readonly repoRootFinder: RepoRootFinder,\n private readonly aiBranchName: AiBranchName,\n private readonly branchNaming: BranchNaming,\n private readonly prMerger: PrMerger,\n private readonly archiver: BranchArchiver,\n private readonly mergeInfoIndex: MergeInfoIndex,\n private readonly landedWorktree: LandedWorktreeReaper,\n private readonly bodyFile: MergeBodyTempFile,\n private readonly landedTree: LandedTreeResolver,\n ) {}\n\n /**\n * THE INVOCATION DIRECTORY, which is not `process.cwd()`.\n *\n * `pnpm` runs a workspace bin with its cwd hoisted to the workspace root and exports the directory\n * the operator was actually in as `INIT_CWD`. Every agent worktree is NESTED inside the primary\n * clone, so the hoist silently relocated this command into a different tree holding a different\n * branch — see the class doc. `process.cwd()` remains the answer when nothing set `INIT_CWD` (a\n * direct `node` invocation, or a spec), which is the case where the two are the same anyway.\n */\n private invocationCwd(): string {\n const init = process.env['INIT_CWD'] ?? '';\n return init !== '' ? init : process.cwd();\n }\n\n async run(request: LandPrRequest): Promise<void> {\n if (request.prFlagPresent && !/^\\d+$/.test(request.prNumber)) throw this.badPrNumber(request);\n const cwd = this.invocationCwd();\n const repoRoot = this.repoRootFinder.resolveRepoRoot(cwd);\n // `--pr <n>` selects the PR outright; with no flag it is this branch's, read from the tree the\n // operator is really standing in.\n const selector = request.prNumber !== ''\n ? request.prNumber\n : this.branchNaming.baseBranchName(\n execSync('git branch --show-current', { cwd, encoding: 'utf8' }).trim());\n\n const ref = this.readPr(selector);\n if (ref === null) throw this.noSuchPr(request, selector);\n // The PR's OWN head branch, never the selector: with `--pr <n>` the operator named a number and\n // has said nothing about branches, and even in the zero-arg case GitHub is the authority on which\n // branch that PR is merging.\n const base = ref.headRefName !== '' ? ref.headRefName : selector;\n if (ref.body === '') throw this.emptyDescription(ref);\n const unfit = this.notFitForGitLog(ref.body);\n if (unfit !== '') throw this.descriptionUnfitForGitLog(ref, unfit);\n\n process.stdout.write('\\n' + SEP + `🚀 Landing PR #${ref.number}\\n` + SEP + '\\n');\n const mergeBodyFile = this.bodyFile.write(ref.body);\n\n const config = loadAndValidate(repoRoot).prGate;\n const policy = config.mergeMode;\n // Reuse the SAME merge logic wp-finish-upsert-pr uses, so a PR lands identically whichever\n // command lands it — including the auto-merge fallback when the checks are still running.\n //\n // `commanded: true` — running THIS command IS the intent to merge, so it is not gated on\n // pr-gate.mergeMode (a NONE repo runs this precisely to land one PR by hand). The real `policy`\n // travels alongside it rather than being replaced by a literal AUTO, so PrMerger's diagnostics\n // never assert a config value nobody set — that is exactly what used to print a CONFIG MISMATCH\n // about `mergeMode: AUTO` two lines above this command printing `mergeMode is NONE`.\n const outcome = this.prMerger.merge(\n base, `${ref.title} (#${ref.number})`, mergeBodyFile, new MergeIntent(policy ?? '', true),\n );\n\n const bookkeeping = outcome.merged\n ? this.bookkeeping(repoRoot, base, ref, config.landPr.branchRetention, cwd)\n : '';\n process.stdout.write(\n '\\n' + SEP + (outcome.merged ? '✅ Landed\\n' : 'ℹ️ Not landed yet\\n') + SEP + '\\n' +\n ` ${outcome.message}\\n` +\n bookkeeping +\n (policy === MERGE_MODE_AUTO\n ? ''\n : ` (pr-gate.mergeMode is ${policy} — wp-finish-upsert-pr publishes PRs without attempting a merge.)\\n`) +\n '\\n',\n );\n }\n\n /**\n * `--pr` without a usable number. It REFUSES rather than falling back to the branch, because the\n * fallback would land a different PR from the one the operator was reaching for, and a squash into\n * main is not a place to guess. `--pr` bare and `--pr HEAD` land here alike.\n */\n private badPrNumber(request: LandPrRequest): InformAiError {\n const got = request.prNumber === '' ? 'nothing' : `\"${request.prNumber}\"`;\n return new InformAiError(\n '\\n' + SEP + '❌ --pr needs a PR NUMBER\\n' + SEP + '\\n' +\n `\\`--pr\\` was given ${got}. It takes the digits of one pull request:\\n` +\n ' pnpm wp-land-pr --pr 1087\\n\\n' +\n 'To land the PR of the branch you are standing on, pass no flag at all:\\n' +\n ' pnpm wp-land-pr\\n' + SEP);\n }\n\n /**\n * The refusal when `gh` has no open PR for what we asked about — and it must say WHICH question was\n * asked, because the two have different cures.\n *\n * The branch form used to be the only one, and it was the face of the cwd bug: run from an agent\n * worktree, pnpm's hoist made the branch read `main`, and an operator with an open PR in front of\n * them was told there was none. So the branch form now says what it looked up and where it read that\n * branch FROM, which is the one fact that makes a wrong answer recognisable as a wrong answer, and it\n * names the `--pr <n>` form that does not depend on the tree at all.\n */\n private noSuchPr(request: LandPrRequest, selector: string): InformAiError {\n if (request.prNumber !== '') {\n return new InformAiError(\n '\\n' + SEP + `❌ No open PR #${request.prNumber}\\n` + SEP + '\\n' +\n `\\`gh pr view ${request.prNumber}\\` found no OPEN pull request with that number.\\n` +\n 'If it is already merged, run `pnpm wp-cleanup` from the primary clone to finish the\\n' +\n 'branch and worktree bookkeeping. Otherwise check the number with `gh pr list`.\\n' + SEP);\n }\n return new InformAiError(\n '\\n' + SEP + '❌ No open PR found for this branch\\n' + SEP + '\\n' +\n `No open PR has head branch \"${selector}\", read from ${this.invocationCwd()}. Nothing to land.\\n` +\n 'If that is not the branch you expected, land it by number instead — it does not depend on\\n' +\n 'which directory you are standing in:\\n' +\n ' pnpm wp-land-pr --pr <n>\\n' +\n 'If the PR is already merged, run `pnpm wp-cleanup`.\\n' +\n 'If it was never posted, run the gated flow — it posts the PR AND writes the description\\n' +\n 'that becomes this commit body:\\n' +\n ' pnpm wp-start-upsert-pr && pnpm wp-review-upsert-pr && pnpm wp-finish-upsert-pr\\n' + SEP);\n }\n\n /**\n * The refusal when the PR exists but its description is empty.\n *\n * This is the ONE remaining \"no gated body\" case, and it is now a property of the PR rather than of\n * this machine — which is why the cure is a single command with no human judgement call attached.\n * There is deliberately no `--fallback-title-only` escape any more: that flag existed because the\n * bytes could be on a DIFFERENT COMPUTER from the one landing, which cannot happen when GitHub holds\n * them. Re-running finish is always available, always correct, and lands the reviewed bytes.\n */\n private emptyDescription(ref: PrIdentity): InformAiError {\n return new InformAiError(\n '\\n' + SEP + `❌ PR #${ref.number} has an EMPTY description\\n` + SEP + '\\n' +\n 'The PR description IS the squash-commit body — `pnpm wp-finish-upsert-pr` renders one string\\n' +\n 'and publishes it as the description, and landing reads it straight back with\\n' +\n '`gh pr view --json body`. An empty description means the gated flow never published one\\n' +\n '(or a human cleared it), so there is nothing reviewed to land.\\n\\n' +\n 'Re-run the gated flow — it re-renders the description and re-posts it to this same PR:\\n' +\n ' pnpm wp-start-upsert-pr # update from main (3-point merge). No push, no build gate.\\n' +\n ' pnpm wp-review-upsert-pr # validate the merge, build gate, extract the diff, brief reviewers\\n' +\n ' # write summary.json at the path wp-review-upsert-pr prints\\n' +\n ' pnpm wp-finish-upsert-pr # build gate, dashboard, create/update the PR\\n' +\n 'Then re-run `pnpm wp-land-pr`.\\n' + SEP,\n );\n }\n\n /**\n * '' when the description is a compact gated body; otherwise the marker that proves it is not.\n *\n * This reads the SAME invariant `pr-body-is-merge-body.spec.ts` asserts from the other end: the\n * compact body \"contains nothing a plain-text git log cannot carry\" — no markdown heading, no table\n * pipe. It is therefore not a heuristic about what a dashboard looks like; it is the renderer's own\n * pinned property, checked against bytes that arrived from outside this process.\n *\n * WHY IT IS NEEDED, and why it is not a compatibility fallback: a PR posted by a release OLDER than\n * the surface swap still has the FULL DASHBOARD as its description. Measured on this repo,\n * 2026-08-07 — PR #613 (posted after the swap) has a description byte-identical to its squash body,\n * while PR #614 (still open, posted minutes before) begins `## 🚦 PR Gate Dashboard`. Landing that\n * one would dump a risk table into main, which is precisely the defect\n * `decisions/0004` § 4.1 warned about. So this REFUSES and names the one command that fixes it. It\n * never falls back, never rewrites, and never reaches for a second source of bytes.\n *\n * It keeps earning its place after the transition: nothing stops a human editing a PR description\n * in GitHub's textarea, and this is the only point between that edit and main's history.\n *\n * What it must NOT be read as is proof that the bytes did not come from `renderPrBody`. They can:\n * the compact body interpolates author text, and a `|` reaches that text from a TypeScript union, a\n * regex alternation or a quoted shell pipeline. `Dashboard.gitLogSafe` substitutes both markers at\n * the render exit so a freshly-rendered body no longer trips this — which is where that invariant\n * belongs, since the renderer is the only thing that can fix it without an extra CI cycle.\n */\n private notFitForGitLog(body: string): string {\n if (body.includes('##')) return '## (a markdown heading)';\n if (body.includes('|')) return '| (a markdown table)';\n return '';\n }\n\n /**\n * The refusal when the description is not the compact gated body.\n *\n * It names BOTH ways bytes get here, because naming only one sent readers down a path that did not\n * exist. It used to assert an old release as \"the usual cause\" and prescribe re-running finish — and\n * when the marker had come from AUTHOR TEXT instead (a `|` in a summary, from a TypeScript union or a\n * regex alternation), finish re-rendered the identical character from the unchanged `summary.json` and\n * landing refused again: a loop costing a CI cycle per turn, escapable only by guessing that one\n * character in your prose was the problem. `Dashboard.gitLogSafe` now substitutes both markers at the\n * render exit, so a freshly-rendered body cannot reach here at all — which leaves a HAND-EDITED\n * description and a genuinely old PR as the two remaining causes, and this says so.\n */\n private descriptionUnfitForGitLog(ref: PrIdentity, marker: string): InformAiError {\n return new InformAiError(\n '\\n' + SEP + `❌ PR #${ref.number}'s description is not a git-log commit body\\n` + SEP + '\\n' +\n `It contains ${marker}, which the compact body rendered by \\`pnpm wp-finish-upsert-pr\\` never\\n` +\n 'does — it substitutes both markers as it renders — so these bytes are not the gated summary,\\n' +\n 'and landing them would put a PR Gate Dashboard (or hand-written markdown) into main\\'s\\n' +\n 'history permanently.\\n\\n' +\n 'There are two causes, and they need different fixes:\\n\\n' +\n ' 1. The description was EDITED BY HAND on GitHub after finish posted it. Re-running finish\\n' +\n ' overwrites that edit with the compact body, so landing works.\\n' +\n ' 2. The PR was posted by a webpieces release OLDER than the one that made the description\\n' +\n ' the commit body, so it is still the full dashboard. The dashboard now lives in the PR\\'s\\n' +\n ' 1st comment instead, and re-running finish moves it there.\\n\\n' +\n `Either way the cure is the same, and it does NOT require removing ${marker.trim()} from your PR\\n` +\n 'summary text — a pipe or a heading in a summary is rendered safe, not rejected:\\n' +\n ' pnpm wp-start-upsert-pr && pnpm wp-review-upsert-pr && pnpm wp-finish-upsert-pr\\n' + SEP,\n );\n }\n\n /**\n * The landed branch's post-merge bookkeeping — but ONLY when this tree's `<branch>` IS the commit\n * that was squashed.\n *\n * The fact being tested is \"does this working tree hold the objects the PR merged\", and the PR\n * answers it authoritatively: `headRefOid` is the tip GitHub squashed. A second clone's `<branch>`\n * is a different commit, so `archive/<date>/<branch>` there would tag the wrong tip under the right\n * name; `merge-info/staged/<feature>` lives in the posting tree's state, not ours; and the worktree\n * to reap is not this one. So the merge stands and the bookkeeping is declined ALOUD.\n *\n * This used to be read out of an `origin.json` sidecar recording which tree posted the PR. Comparing\n * SHAs is strictly better: it is a fact rather than a recorded claim, it needs no stored state, and\n * it is more precise in both directions — a second clone sitting on the SAME commit can safely\n * archive it, and a tree that has committed further work since finish ran correctly declines.\n */\n private bookkeeping(\n repoRoot: string, base: string, ref: PrIdentity, retention: string, cwd: string,\n ): string {\n const tree = this.landedTree.resolve(repoRoot, base, ref.headRefOid);\n if (!tree.bookkeepingAllowed) return this.notTheLandedTipNotice(base, tree, ref);\n return this.archiveAndPromote(repoRoot, base, ref, retention)\n + this.nextStep(repoRoot, tree, cwd);\n }\n\n /**\n * What was skipped, why, and what the two SHAs are — so the reader can tell WHICH cause it was.\n *\n * Two causes, one message, because the cure is the same for both: the objects the PR squashed are not\n * in this repo under that name, so nothing here may archive them or reap a tree for them.\n */\n private notTheLandedTipNotice(base: string, tree: LandedTree, ref: PrIdentity): string {\n const found = tree.kind === LANDED_TREE_ABSENT\n ? ` ${base} is not in this repo at all\\n`\n : ` ${base} here → ${tree.localSha}\\n`;\n return '\\n ⚠️ Archive + worktree cleanup SKIPPED — nothing here holds the commit that landed:\\n' +\n found +\n ` PR #${ref.number} squashed → ${ref.headRefOid}\\n` +\n ' Archiving from here would tag the wrong objects under the right name, and the\\n' +\n ` merge-info record and (if any) the worktree holding ${base} live with the other tip.\\n` +\n ' Either this is a second clone of the repo — finish the bookkeeping in the clone that\\n' +\n ' posted the PR with `pnpm wp-cleanup` — or that tree has commits made after\\n' +\n ' `pnpm wp-finish-upsert-pr` ran, which the PR does not contain.\\n';\n }\n\n /**\n * What happens next — which is NOT the same act when you landed from a worktree.\n *\n * Landing from a linked worktree always used to leave a corpse: the merged branch is checked out\n * here, so `git branch -D` refuses, `wp-cleanup`'s branch pass spares it as in-use, and nothing\n * removed the worktree — so the pair sat there until branch-creation-guard hit its cap. #512 made\n * worktrees reapable and printed `cd <primary> && pnpm wp-cleanup`; that instruction was correct\n * and it was the most-skipped step in the flow, because the PR is already landed and the work\n * feels done.\n *\n * So the reap is no longer an instruction. This command still refuses to remove the directory it\n * is standing in — that rail is untouched — and instead HANDS THE REAP to a child process rooted\n * in the primary clone, which is a tree nobody is deleting. See LandedWorktreeReaper. When that\n * hand-off is not safely achievable the #512 notice is printed unchanged, because an honest\n * limitation beats a command that deletes its own working directory mid-run.\n */\n private nextStep(repoRoot: string, tree: LandedTree, cwd: string): string {\n const handoff: WorktreeReapHandoff | null\n = this.landedWorktree.plan(repoRoot, tree.worktree, cwd);\n if (handoff === null) return ' Next: `pnpm wp-cleanup` to delete the merged branch.\\n';\n if (!handoff.canReap) return this.landedWorktree.manualNotice(handoff);\n return this.landedWorktree.handOff(handoff);\n }\n\n /**\n * The landed branch's post-merge bookkeeping, in one place:\n * 1. ARCHIVE the pre-squash tip as `archive/<date>/<branch>` — the tag makes the original history\n * permanently restorable (`git checkout -b <branch> <tag>` gives back the exact objects) while\n * costing one ref, so the branch itself no longer has to survive as a `*PreMerge` husk that\n * counts toward the branch cap. See BranchArchiver for why a tag beats a patch or the reflog.\n * 2. PROMOTE `merge-info/staged/<feature>/` to `merge-info/merged/<feature>/` and rebuild\n * `index.json`, so `staged/` holds only branches that are still in flight.\n *\n * Never throws: the PR is already merged by the time we get here, and failing the command after a\n * successful merge would report a landed PR as a failure. Problems are reported in the recap.\n */\n private archiveAndPromote(repoRoot: string, base: string, ref: PrIdentity, retention: string): string {\n if (retention === BRANCH_RETENTION_KEEP) return ' Branch retention is \"keep\" — nothing archived.\\n';\n\n let line = '';\n let tag = '';\n if (retention === BRANCH_RETENTION_ARCHIVE_TAG) {\n const archive = this.archiver.archive(repoRoot, base);\n tag = archive.tag;\n line = archive.ok\n ? ` Archived ${base} → ${archive.tag} (restore: ${this.archiver.restoreCommand(base, archive.tag)})\\n`\n : ` ⚠️ Could not archive ${base}: ${archive.error} — the branch was left alone.\\n`;\n }\n\n const feature = this.aiBranchName.getFeatureName();\n const record = new ArchiveRecord(\n tag, this.revParse(repoRoot, base), this.revParse(repoRoot, 'origin/main'),\n Number(ref.number), new Date().toISOString(),\n );\n if (this.mergeInfoIndex.promoteToMerged(repoRoot, feature, record)) {\n line += ` merge-info: staged/${feature} → merged/${feature} (index.json rebuilt)\\n`;\n }\n return line;\n }\n\n // Best-effort sha of a ref — '' when it cannot resolve. Recorded in archive.json for provenance.\n private revParse(repoRoot: string, ref: string): string {\n const result = spawnSync('git', ['rev-parse', ref], { cwd: repoRoot, encoding: 'utf8' });\n return result.status === 0 ? (result.stdout ?? '').trim() : '';\n }\n\n /**\n * Everything landing needs about the PR, in ONE `gh` read: number, title, URL, DESCRIPTION and the\n * head sha GitHub is squashing. `null` when there is no open PR for this head branch.\n *\n * The TITLE comes from the PR itself, not summary.json, so the squash subject matches what a reviewer\n * approved even if summary.json was edited afterwards. The BODY is the gated commit body (see the\n * class doc). `headRefOid` is read BEFORE the merge, because it is what the bookkeeping check\n * compares against and the merge is what makes the branch's fate uninteresting to GitHub.\n */\n private readPr(selector: string): PrIdentity | null {\n const result = spawnSync(\n 'gh', ['pr', 'view', selector, '--json', 'number,title,url,body,headRefOid,headRefName'],\n { encoding: 'utf8' },\n );\n if (result.status !== 0) return null;\n return this.parsePr(result.stdout ?? '');\n }\n\n // `gh --json` output → PrIdentity. Malformed/absent JSON reads as \"no PR\", which the caller turns\n // into the same refusal a missing PR gets: both mean nothing here can be landed.\n private parsePr(stdout: string): PrIdentity | null {\n // webpieces-disable no-unmanaged-exceptions -- chokepoint: unparseable gh output means \"no PR\", never a crash\n // eslint-disable-next-line @webpieces/no-unmanaged-exceptions\n try {\n // webpieces-disable no-any-unknown -- gh's JSON is opaque until narrowed field-by-field below\n const raw = JSON.parse(stdout) as Record<string, unknown>;\n const number = typeof raw['number'] === 'number' ? String(raw['number']) : this.str(raw['number']);\n if (number === '') return null;\n // GitHub stores descriptions with CRLF. A commit body must not carry them, and the bytes are\n // otherwise identical to what finish rendered, so the line endings are normalized back here.\n const body = this.str(raw['body']).replace(/\\r\\n/g, '\\n').trim();\n return new PrIdentity(\n number, this.str(raw['title']), this.str(raw['url']), body === '' ? '' : body + '\\n',\n this.str(raw['headRefOid']), this.str(raw['headRefName']),\n );\n } catch (err: unknown) {\n const error = toError(err);\n void error;\n return null;\n }\n }\n\n // webpieces-disable no-any-unknown -- one opaque JSON field, narrowed to string\n private str(value: unknown): string {\n return typeof value === 'string' ? value : '';\n }\n}\n\n// The open PR as GitHub holds it: its number, title, web URL, DESCRIPTION (= the gated commit body) and\n// the PAIR that identifies its tree locally — the head branch's name and the commit being squashed.\nclass PrIdentity {\n number: string;\n title: string;\n url: string;\n body: string;\n headRefOid: string;\n /**\n * The PR's head BRANCH. Required alongside `headRefOid` because neither half identifies a tree on its\n * own: the name is what a worktree list can be searched by, the sha is what makes a hit the right\n * one. It also frees `--pr <n>` from needing the operator to be standing anywhere in particular.\n */\n headRefName: string;\n\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(\n number: string, title: string, url: string, body: string, headRefOid: string, headRefName: string,\n ) {\n this.number = number;\n this.title = title;\n this.url = url;\n this.body = body;\n this.headRefOid = headRefOid;\n this.headRefName = headRefName;\n }\n}\n\n/**\n * Data-only (per CLAUDE.md, classes for data): what the operator asked `wp-land-pr` to land.\n *\n * `prNumber` is '' for the zero-arg form — \"this branch's PR\" — which stays the shorthand the worker\n * uses. It is NOT an optional constructor parameter with a default at the call site: `wp-land-pr.ts`\n * builds exactly one of these from the parsed argv, so there is one spelling of the decision.\n */\nexport class LandPrRequest {\n /**\n * Was `--pr` on the command line at all? Kept SEPARATE from the value because `--pr` with no number\n * is a mistake, not a request to guess: collapsing the two would silently land whatever PR the\n * current directory's branch happens to have, which is the opposite of what the operator typed.\n */\n prFlagPresent: boolean;\n /** The `--pr <n>` value verbatim, or '' to infer the PR from the invocation directory's branch. */\n prNumber: string;\n\n constructor(prFlagPresent: boolean, prNumber: string) {\n this.prFlagPresent = prFlagPresent;\n this.prNumber = prNumber;\n }\n}\n"]}
@@ -51,7 +51,7 @@ let FinishBanner = class FinishBanner {
51
51
  this.whatIsOwed(input) + '\n';
52
52
  }
53
53
  // TRUE only for the outcomes where nothing further is owed: merged, queued behind green-able checks,
54
- // or deliberately left for a human. Everything else — BEHIND, config mismatch, gh failure, no PR —
54
+ // or published without an automatic merge. Everything else — BEHIND, config mismatch, gh failure, no PR —
55
55
  // is unfinished work, and the banner must not decorate it with a checkmark.
56
56
  isDone(merge) {
57
57
  return merge.result === pr_merger_1.MERGE_RESULT_MERGED
@@ -65,7 +65,7 @@ let FinishBanner = class FinishBanner {
65
65
  return '✅ PR finished — auto-merge is ON; it lands itself when the checks pass\n';
66
66
  }
67
67
  if (merge.result === pr_merger_1.MERGE_RESULT_LEFT_TO_HUMAN) {
68
- return '✅ PR finished — posted for a human to merge (that is this repo\'s policy)\n';
68
+ return '✅ PR published — automatic merging by wp-finish-upsert-pr is disabled\n';
69
69
  }
70
70
  // NOT "PR NOT FINISHED". Everything this command owns SUCCEEDED — the branch is pushed, the body
71
71
  // is written, the build gate is green. What happened is that another author landed on main
@@ -178,8 +178,10 @@ let FinishBanner = class FinishBanner {
178
178
  this.watchOffer();
179
179
  }
180
180
  if (merge.result === pr_merger_1.MERGE_RESULT_LEFT_TO_HUMAN) {
181
- return ' Nothing else is owed by the tooling — a person merges it. You can stop here.\n' +
182
- this.watchOffer() +
181
+ return ' This command published the PR without attempting a merge.\n' +
182
+ ' This setting does not require additional authorization or override existing user instructions.\n' +
183
+ ' If landing was requested (including $full-cycle or /full-cycle), continue through the\n' +
184
+ ' required checks and run `pnpm wp-land-pr`.\n' +
183
185
  '\n' +
184
186
  ' ℹ️ Clicking Merge in the GitHub UI is CORRECT here and produces the right history. The\n' +
185
187
  ' PR description IS the commit body this flow rendered — compact, non-green flags\n' +
@@ -1 +1 @@
1
- {"version":3,"file":"finish-banner.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/finish-banner.ts"],"names":[],"mappings":";;;;AAAA,yCAA2D;AAC3D,2CAGqB;AAErB,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAEvE,qGAAqG;AACrG,gGAAgG;AAChG,MAAa,iBAAiB;IAC1B,QAAQ,CAAS;IACjB,KAAK,CAAS;IACd,KAAK,CAAS;IACd,IAAI,CAAS;IACb,KAAK,CAAe;IA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AC,KAAK,CAAC;YACrC,CAAC,CAAC,EAAE;YACJ,CAAC,CAAC,6BAA6B,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,wCAAwC;gBACjG,CAAC,KAAK,CAAC,KAAK,CAAC,QAAQ,EAAE;oBACnB,CAAC,CAAC,2FAA2F;wBAC3F,yFAAyF;wBACzF,4FAA4F;oBAC9F,CAAC,CAAC,2FAA2F,CAAC,CAAC;QACzG,OAAO,GAAG,GAAG,UAAU,KAAK,CAAC,QAAQ,KAAK,KAAK,CAAC,KAAK,QAAQ,KAAK,CAAC,KAAK,MAAM,GAAG,GAAG,GAAG,QAAQ;YAC3F,4FAA4F;YAC5F,iFAAiF;YACjF,QAAQ,KAAK,CAAC,QAAQ,IAAI,KAAK,KAAK,KAAK,CAAC,KAAK,OAAO,CAAC;IAC/D,CAAC;IAED,oGAAoG;IACpG,qGAAqG;IACrG,oFAAoF;IAC5E,UAAU,CAAC,KAAmB;QAClC,IAAI,KAAK,CAAC,MAAM,KAAK,2CAA+B;YAAE,OAAO,oEAAoE,CAAC;QAClI,IAAI,KAAK,CAAC,MAAM,KAAK,uCAA2B;YAAE,OAAO,8DAA8D,CAAC;QACxH,IAAI,KAAK,CAAC,QAAQ,EAAE;YAAE,OAAO,kEAAkE,CAAC;QAChG,OAAO,YAAY,CAAC;IACxB,CAAC;CACJ,CAAA;AA5NY,oCAAY;uBAAZ,YAAY;IADxB,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;GAC5B,YAAY,CA4NxB","sourcesContent":["import { injectable, bindingScopeValues } from 'inversify';\nimport {\n MergeOutcome, MERGE_RESULT_MERGED, MERGE_RESULT_AUTO_QUEUED, MERGE_RESULT_LEFT_TO_HUMAN,\n MERGE_RESULT_BEHIND_CONFLICTING, MERGE_RESULT_BEHIND_UNKNOWN,\n} from './pr-merger';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n// Everything the closing block of wp-finish-upsert-pr needs to describe what actually happened. Both\n// `prNumber` and `prUrl` are '' when the PR could not be resolved (e.g. `gh pr create` failed).\nexport class FinishBannerInput {\n prNumber: string;\n prUrl: string;\n title: string;\n base: string;\n merge: MergeOutcome;\n\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(prNumber: string, prUrl: string, title: string, base: string, merge: MergeOutcome) {\n this.prNumber = prNumber;\n this.prUrl = prUrl;\n this.title = title;\n this.base = base;\n this.merge = merge;\n }\n}\n\n/**\n * Renders the closing block of `wp-finish-upsert-pr` — and it is the FRAME, not the merge message, that\n * this class exists to get right.\n *\n * PrMerger has long been honest in its `message`. The banner around it was not: it printed a hard-coded\n * `✅ PR finished` on every path, so a run whose merge failed still looked like a completed one at a\n * glance. The worst case is `mergeStateStatus: BEHIND` — unlike BLOCKED (waiting on checks), which\n * auto-merge resolves on its own, a BEHIND branch NEVER lands. Under a green checkmark, agents walked\n * away from stranded PRs. Three of them independently reported the output as untrustworthy.\n *\n * So the header is derived from `MergeOutcome.result`, and a not-done outcome is loud, distinct, and\n * carries the exact commands that fix it — including in the clickable-link directive, whose whole job\n * is to be the last thing the AI says.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class FinishBanner {\n // The full closing recap: header keyed to the real outcome, the four things this command did, and —\n // when the PR is not done — what must happen next.\n render(input: FinishBannerInput): string {\n const prNum = input.prNumber;\n return '\\n' + SEP + this.header(input.merge) + SEP + '\\n' +\n ` 1. validated the build gate (authoritative)\\n` +\n ` 2. ${prNum ? `wrote the gated body to PR #${prNum}` : 'composed the gated PR body'} titled: \"${input.title}\"\\n` +\n ` 3. force-pushed your work to origin/${input.base} (after the body, so CI reads the right token)\\n` +\n ` 4. ${input.merge.message}\\n` +\n ` You are on ${input.base} — same name as the remote branch and the PR head.\\n` +\n this.whatIsOwed(input) + '\\n';\n }\n\n // TRUE only for the outcomes where nothing further is owed: merged, queued behind green-able checks,\n // or deliberately left for a human. Everything else — BEHIND, config mismatch, gh failure, no PR —\n // is unfinished work, and the banner must not decorate it with a checkmark.\n isDone(merge: MergeOutcome): boolean {\n return merge.result === MERGE_RESULT_MERGED\n || merge.result === MERGE_RESULT_AUTO_QUEUED\n || merge.result === MERGE_RESULT_LEFT_TO_HUMAN;\n }\n\n private header(merge: MergeOutcome): string {\n if (merge.result === MERGE_RESULT_MERGED) return '✅ PR finished AND MERGED — here is exactly what I did\\n';\n if (merge.result === MERGE_RESULT_AUTO_QUEUED) {\n return '✅ PR finished — auto-merge is ON; it lands itself when the checks pass\\n';\n }\n if (merge.result === MERGE_RESULT_LEFT_TO_HUMAN) {\n return '✅ PR finished — posted for a human to merge (that is this repo\\'s policy)\\n';\n }\n // NOT \"PR NOT FINISHED\". Everything this command owns SUCCEEDED — the branch is pushed, the body\n // is written, the build gate is green. What happened is that another author landed on main\n // between our fetch and our push. Reporting that as the author's failure sent agents off\n // re-auditing their own diff and hunting build flakes for a race they did not cause.\n if (merge.isBehind()) return this.behindHeader(merge);\n return '⚠️ PR NOT FINISHED — the PR is up, but the merge did NOT happen\\n';\n }\n\n private behindHeader(merge: MergeOutcome): string {\n if (merge.result === MERGE_RESULT_BEHIND_CONFLICTING) {\n return '⏸️ PR IS UP AND GREEN — someone landed on main first, and it CONFLICTS with your work\\n';\n }\n if (merge.result === MERGE_RESULT_BEHIND_UNKNOWN) {\n return '⏸️ PR IS UP AND GREEN — GitHub has not finished computing mergeability yet\\n';\n }\n return '⏸️ PR IS UP AND GREEN — someone landed on main first (no conflicts with your work)\\n';\n }\n\n // The follow-up block. '' for a done outcome — a finished run should not invent chores.\n private whatIsOwed(input: FinishBannerInput): string {\n if (this.isDone(input.merge)) return this.doneNote(input.merge);\n if (input.merge.isBehind()) return this.behindRemedy(input);\n return '\\n' + SEP +\n ' ⚠️ DO NOT report this PR as done. The merge failed for the reason in step 4 above.\\n' +\n ' Fix that, then re-run: pnpm wp-finish-upsert-pr\\n' +\n ` Confirm for yourself: gh pr view ${input.prNumber === '' ? '<n>' : input.prNumber} --json mergeable,mergeStateStatus,state\\n`;\n }\n\n /**\n * The BEHIND follow-up. Two rules govern every word here.\n *\n * FIRST: the remedy is the FULL ①②③, never a shortcut. `gh pr update-branch` looks like the obvious\n * one-command fix and is a trap — it rewrites the REMOTE branch while every fork-point consumer\n * (`ForkPoint.resolveForkPoint`, `nx affected --base=$(git merge-base ...)`, the review diff) computes\n * against the LOCAL HEAD. That splits reality in two: stage ③ force-pushes local over the remote and\n * silently reverts it, the recorded hash points describe a tree that is no longer the PR head, and the\n * rebased tree never passes a build gate. Only ① moves the fork point AND records it; only ② rebuilds\n * and re-receipts against the new one.\n *\n * SECOND: it ASKS, it does not order. An imperative command list is what turns an agent into a loop —\n * it complies, main moves again, it complies again. Asking forces a stop at a human, which is the only\n * thing that reliably terminates a race we cannot win by retrying.\n */\n private behindRemedy(input: FinishBannerInput): string {\n const num = input.prNumber === '' ? '<n>' : input.prNumber;\n return '\\n' + SEP + this.behindSituation(input.merge) + '\\n' +\n ' ⚠️ STOP HERE AND ASK THE HUMAN. Do NOT run these yourself — if main keeps moving,\\n' +\n ' running them on your own is an infinite loop with a full build inside it.\\n\\n' +\n ' Ask, in your own words:\\n' +\n ` \"${this.behindAsk(input.merge)}\\n` +\n ` ${this.behindAskClose(input.merge)}\"\\n\\n` +\n ' Only once they say yes:\\n\\n' +\n ' pnpm wp-start-upsert-pr # 3-point merge from main — re-forks onto the new main\\n' +\n ' pnpm wp-review-upsert-pr # re-validates the merge + REBUILDS on the new fork point\\n' +\n ' pnpm wp-finish-upsert-pr # gated body + merge, now up to date\\n\\n' +\n ' Do NOT skip ②. It is the only stage that validates the new merge and rebuilds against\\n' +\n ' the new fork point; skipping it publishes a PR whose tree was never gated.\\n' +\n ' Do NOT reach for `gh pr update-branch`. It rewrites the REMOTE branch only, which stage\\n' +\n ' ③ then force-pushes over — and it lands a tree no build gate ever saw.\\n' +\n ` Verify independently, do not trust this banner:\\n` +\n ` gh pr view ${num} --json mergeable,mergeStateStatus,state\\n`;\n }\n\n // What is actually true right now, per kind. The CLEAN case gets the caveat that it may not even\n // matter: \"out of date\" only blocks a merge on repos that require branches be up to date.\n private behindSituation(merge: MergeOutcome): string {\n if (merge.result === MERGE_RESULT_BEHIND_CONFLICTING) {\n return ' Your PR is pushed, its body is written, and the build gate passed. Then someone\\n' +\n ' else landed on main, and their change CONFLICTS with yours — same lines. Real\\n' +\n ' resolution is owed, and if people keep landing ahead of you it genuinely repeats.\\n' +\n ' That is inherent to concurrent editing, not a bug and not something you did wrong.\\n';\n }\n if (merge.result === MERGE_RESULT_BEHIND_UNKNOWN) {\n return ' Your PR is pushed, its body is written, and the build gate passed. GitHub has not\\n' +\n ' finished computing mergeability yet (it is asynchronous, and we asked seconds after\\n' +\n ' the push), so we do NOT know whether this conflicts. Re-check before doing anything:\\n' +\n ' a few seconds later the answer is usually CLEAN and no work is owed at all.\\n';\n }\n return ' Your PR is pushed, its body is written, and the build gate passed. Someone else simply\\n' +\n ' landed on main first. There are NO conflicts — nobody touched your lines.\\n' +\n ' This may not even matter: \"out of date\" blocks a merge only on repos that REQUIRE\\n' +\n ' branches be up to date. If yours does not, this PR can merge as-is.\\n';\n }\n\n // The one sentence to put to the human, in their terms.\n private behindAsk(merge: MergeOutcome): string {\n if (merge.result === MERGE_RESULT_BEHIND_CONFLICTING) {\n return 'Someone beat me to landing on main and there are conflicts. We MUST run a\\n' +\n ' 3-point merge so I can resolve them properly.';\n }\n if (merge.result === MERGE_RESULT_BEHIND_UNKNOWN) {\n return 'Someone beat me to landing on main. GitHub has not said yet whether it\\n' +\n ' conflicts, so I have not touched anything.';\n }\n return 'Someone beat me to landing on main. There are no conflicts, so this is just\\n' +\n ' a re-sync — but it costs a full rebuild.';\n }\n\n // The actual question. UNKNOWN gets a DIFFERENT one: with mergeability still uncomputed, proposing a\n // full re-run is proposing work we cannot yet show is needed — a re-check is free and often ends it.\n private behindAskClose(merge: MergeOutcome): string {\n if (merge.result === MERGE_RESULT_BEHIND_UNKNOWN) {\n return 'Shall I re-check in a moment, or start the wp-*-upsert-pr process over?';\n }\n return 'May I start the wp-*-upsert-pr process over again?';\n }\n\n // A short, positive \"you are free to stop\" line for the two non-merged-but-fine outcomes, so an AI\n // reading a queued PR does not go hunting for work that is not owed.\n private doneNote(merge: MergeOutcome): string {\n if (merge.result === MERGE_RESULT_AUTO_QUEUED) {\n return ' Nothing else is owed: GitHub lands it when the checks go green. You can stop here.\\n' +\n this.watchOffer();\n }\n if (merge.result === MERGE_RESULT_LEFT_TO_HUMAN) {\n return ' Nothing else is owed by the tooling — a person merges it. You can stop here.\\n' +\n this.watchOffer() +\n '\\n' +\n ' ℹ️ Clicking Merge in the GitHub UI is CORRECT here and produces the right history. The\\n' +\n ' PR description IS the commit body this flow rendered — compact, non-green flags\\n' +\n ' only, with the PR link on top — and this flow keeps the two repo settings that copy\\n' +\n ' it into main pinned itself (squash_merge_commit_title=PR_TITLE,\\n' +\n ' squash_merge_commit_message=PR_BODY). There is nothing for you to configure.\\n' +\n ' (`pnpm wp-land-pr` lands the identical bytes from the CLI, and also archives the\\n' +\n ' pre-squash tip and reaps the worktree. Either route is fine.)\\n';\n }\n return '';\n }\n\n /**\n * The one OPTIONAL line about watching CI — offered, never instructed.\n *\n * \"You can stop here\" above stays the DEFAULT and is deliberately printed first: landing is the\n * developer's call, and several of this repo's workflows stop at a green PR on purpose. This exists\n * for the caller who has ALREADY decided to see it land, because the alternative they otherwise\n * reach for is an `echo .` keep-alive — measured at 18.3% of every token the fleet spent in the 24h\n * to 2026-09-07 (issue #874). Naming a blocking command is cheaper than the wait somebody was going\n * to do anyway; it is not a reason to wait.\n *\n * It names the EFFICIENT WAIT and the wasteful one, and says nothing about when to end a turn\n * (issue #902). An earlier cut led with \"END YOUR TURN\"; that is a turn-level judgement the caller is\n * better placed to make than this string is, and it contradicted `SUBAGENT_CURE` shipped in the same\n * release. `--watch` is named because it exists, it blocks, and it is never refused; what it lacks is\n * a bounded exit, so the harness kills it at 600s having printed nothing.\n */\n private watchOffer(): string {\n return ' (Optional — only if you have decided to watch it land, which nothing here asks you to do.\\n' +\n ' Be efficient with tokens: `pnpm wp-await-checks --pr <n>` BLOCKS in one call and returns\\n' +\n ' at 540s asking to be run again; `gh pr checks <n> --watch` also blocks but is killed at\\n' +\n ' the 600s silence ceiling. Do not send status checks every few seconds, and\\n' +\n ' never `echo` to keep a turn alive — a turn costs your whole context.)\\n';\n }\n\n /**\n * The closing AI directive: the resolved PR's number/title/URL and an instruction to end the\n * user-facing summary with EXACTLY `[#N title](url)` as the final line, nothing after it.\n *\n * The link text CARRIES the outcome. Ending on a bare cheerful link is exactly how a stranded PR got\n * reported as finished, and the directive says the link must be last — so the truth has to live\n * inside the link itself, not merely above it.\n *\n * '' when the PR could not be resolved: better to say nothing than to point at a link that is not real.\n */\n linkDirective(input: FinishBannerInput): string {\n if (input.prNumber === '' || input.prUrl === '') return '';\n const label = this.isDone(input.merge) ? input.title : `${input.title} — ${this.notDoneTag(input.merge)}`;\n const preamble = this.isDone(input.merge)\n ? ''\n : `AI — this PR is NOT done (${this.notDoneTag(input.merge)}). Your summary MUST say so plainly.\\n` +\n (input.merge.isBehind()\n ? `MUST END BY ASKING the human for permission to re-run the flow, and MUST NOT run any of\\n` +\n `the commands above until they answer. Say plainly that nothing they did caused this —\\n` +\n `another author landed on main first — and that the PR itself is pushed and gate-green.\\n\\n`\n : `MUST include the remedy commands printed above. Do not describe this run as complete.\\n\\n`);\n return SEP + `🔗 PR #${input.prNumber}: ${input.title}\\n ${input.prUrl}\\n\\n` + SEP + preamble +\n `AI — the LAST line of your summary to the user MUST be EXACTLY this clickable link, with\\n` +\n `NOTHING printed after it (no sign-off, no next steps, no blank commentary):\\n\\n` +\n ` [#${input.prNumber} ${label}](${input.prUrl})\\n\\n`;\n }\n\n // The tag rides INSIDE the clickable link, which the directive above forces to be the last line the\n // AI prints — so it is the one piece of wording guaranteed to reach the user. It says who is waiting\n // on whom: for every BEHIND flavour the answer is \"a human\", not \"more automation\".\n private notDoneTag(merge: MergeOutcome): string {\n if (merge.result === MERGE_RESULT_BEHIND_CONFLICTING) return 'NOT MERGED — main moved and it conflicts, needs your OK to re-sync';\n if (merge.result === MERGE_RESULT_BEHIND_UNKNOWN) return 'NOT MERGED — main moved, GitHub still computing mergeability';\n if (merge.isBehind()) return 'NOT MERGED — main moved (no conflicts), needs your OK to re-sync';\n return 'NOT MERGED';\n }\n}\n"]}
1
+ {"version":3,"file":"finish-banner.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/finish-banner.ts"],"names":[],"mappings":";;;;AAAA,yCAA2D;AAC3D,2CAGqB;AAErB,MAAM,GAAG,GAAG,0DAA0D,CAAC;AAEvE,qGAAqG;AACrG,gGAAgG;AAChG,MAAa,iBAAiB;IAC1B,QAAQ,CAAS;IACjB,KAAK,CAAS;IACd,KAAK,CAAS;IACd,IAAI,CAAS;IACb,KAAK,CAAe;IAEpB,yDAAyD;IACzD,YAAY,QAAgB,EAAE,KAAa,EAAE,KAAa,EAAE,IAAY,EAAE,KAAmB;QACzF,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACvB,CAAC;CACJ;AAfD,8CAeC;AAED;;;;;;;;;;;;;GAaG;AAEI,IAAM,YAAY,GAAlB,MAAM,YAAY;IACrB,oGAAoG;IACpG,mDAAmD;IACnD,MAAM,CAAC,KAAwB;QAC3B,MAAM,KAAK,GAAG,KAAK,CAAC,QAAQ,CAAC;QAC7B,OAAO,IAAI,GAAG,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,GAAG,GAAG,IAAI;YACrD,kDAAkD;YAClD,SAAS,KAAK,CAAC,CAAC,C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AK,2CAA+B;YAAE,OAAO,oEAAoE,CAAC;QAClI,IAAI,KAAK,CAAC,MAAM,KAAK,uCAA2B;YAAE,OAAO,8DAA8D,CAAC;QACxH,IAAI,KAAK,CAAC,QAAQ,EAAE;YAAE,OAAO,kEAAkE,CAAC;QAChG,OAAO,YAAY,CAAC;IACxB,CAAC;CACJ,CAAA;AA9NY,oCAAY;uBAAZ,YAAY;IADxB,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;GAC5B,YAAY,CA8NxB","sourcesContent":["import { injectable, bindingScopeValues } from 'inversify';\nimport {\n MergeOutcome, MERGE_RESULT_MERGED, MERGE_RESULT_AUTO_QUEUED, MERGE_RESULT_LEFT_TO_HUMAN,\n MERGE_RESULT_BEHIND_CONFLICTING, MERGE_RESULT_BEHIND_UNKNOWN,\n} from './pr-merger';\n\nconst SEP = '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\\n';\n\n// Everything the closing block of wp-finish-upsert-pr needs to describe what actually happened. Both\n// `prNumber` and `prUrl` are '' when the PR could not be resolved (e.g. `gh pr create` failed).\nexport class FinishBannerInput {\n prNumber: string;\n prUrl: string;\n title: string;\n base: string;\n merge: MergeOutcome;\n\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(prNumber: string, prUrl: string, title: string, base: string, merge: MergeOutcome) {\n this.prNumber = prNumber;\n this.prUrl = prUrl;\n this.title = title;\n this.base = base;\n this.merge = merge;\n }\n}\n\n/**\n * Renders the closing block of `wp-finish-upsert-pr` — and it is the FRAME, not the merge message, that\n * this class exists to get right.\n *\n * PrMerger has long been honest in its `message`. The banner around it was not: it printed a hard-coded\n * `✅ PR finished` on every path, so a run whose merge failed still looked like a completed one at a\n * glance. The worst case is `mergeStateStatus: BEHIND` — unlike BLOCKED (waiting on checks), which\n * auto-merge resolves on its own, a BEHIND branch NEVER lands. Under a green checkmark, agents walked\n * away from stranded PRs. Three of them independently reported the output as untrustworthy.\n *\n * So the header is derived from `MergeOutcome.result`, and a not-done outcome is loud, distinct, and\n * carries the exact commands that fix it — including in the clickable-link directive, whose whole job\n * is to be the last thing the AI says.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class FinishBanner {\n // The full closing recap: header keyed to the real outcome, the four things this command did, and —\n // when the PR is not done — what must happen next.\n render(input: FinishBannerInput): string {\n const prNum = input.prNumber;\n return '\\n' + SEP + this.header(input.merge) + SEP + '\\n' +\n ` 1. validated the build gate (authoritative)\\n` +\n ` 2. ${prNum ? `wrote the gated body to PR #${prNum}` : 'composed the gated PR body'} titled: \"${input.title}\"\\n` +\n ` 3. force-pushed your work to origin/${input.base} (after the body, so CI reads the right token)\\n` +\n ` 4. ${input.merge.message}\\n` +\n ` You are on ${input.base} — same name as the remote branch and the PR head.\\n` +\n this.whatIsOwed(input) + '\\n';\n }\n\n // TRUE only for the outcomes where nothing further is owed: merged, queued behind green-able checks,\n // or published without an automatic merge. Everything else — BEHIND, config mismatch, gh failure, no PR —\n // is unfinished work, and the banner must not decorate it with a checkmark.\n isDone(merge: MergeOutcome): boolean {\n return merge.result === MERGE_RESULT_MERGED\n || merge.result === MERGE_RESULT_AUTO_QUEUED\n || merge.result === MERGE_RESULT_LEFT_TO_HUMAN;\n }\n\n private header(merge: MergeOutcome): string {\n if (merge.result === MERGE_RESULT_MERGED) return '✅ PR finished AND MERGED — here is exactly what I did\\n';\n if (merge.result === MERGE_RESULT_AUTO_QUEUED) {\n return '✅ PR finished — auto-merge is ON; it lands itself when the checks pass\\n';\n }\n if (merge.result === MERGE_RESULT_LEFT_TO_HUMAN) {\n return '✅ PR published — automatic merging by wp-finish-upsert-pr is disabled\\n';\n }\n // NOT \"PR NOT FINISHED\". Everything this command owns SUCCEEDED — the branch is pushed, the body\n // is written, the build gate is green. What happened is that another author landed on main\n // between our fetch and our push. Reporting that as the author's failure sent agents off\n // re-auditing their own diff and hunting build flakes for a race they did not cause.\n if (merge.isBehind()) return this.behindHeader(merge);\n return '⚠️ PR NOT FINISHED — the PR is up, but the merge did NOT happen\\n';\n }\n\n private behindHeader(merge: MergeOutcome): string {\n if (merge.result === MERGE_RESULT_BEHIND_CONFLICTING) {\n return '⏸️ PR IS UP AND GREEN — someone landed on main first, and it CONFLICTS with your work\\n';\n }\n if (merge.result === MERGE_RESULT_BEHIND_UNKNOWN) {\n return '⏸️ PR IS UP AND GREEN — GitHub has not finished computing mergeability yet\\n';\n }\n return '⏸️ PR IS UP AND GREEN — someone landed on main first (no conflicts with your work)\\n';\n }\n\n // The follow-up block. '' for a done outcome — a finished run should not invent chores.\n private whatIsOwed(input: FinishBannerInput): string {\n if (this.isDone(input.merge)) return this.doneNote(input.merge);\n if (input.merge.isBehind()) return this.behindRemedy(input);\n return '\\n' + SEP +\n ' ⚠️ DO NOT report this PR as done. The merge failed for the reason in step 4 above.\\n' +\n ' Fix that, then re-run: pnpm wp-finish-upsert-pr\\n' +\n ` Confirm for yourself: gh pr view ${input.prNumber === '' ? '<n>' : input.prNumber} --json mergeable,mergeStateStatus,state\\n`;\n }\n\n /**\n * The BEHIND follow-up. Two rules govern every word here.\n *\n * FIRST: the remedy is the FULL ①②③, never a shortcut. `gh pr update-branch` looks like the obvious\n * one-command fix and is a trap — it rewrites the REMOTE branch while every fork-point consumer\n * (`ForkPoint.resolveForkPoint`, `nx affected --base=$(git merge-base ...)`, the review diff) computes\n * against the LOCAL HEAD. That splits reality in two: stage ③ force-pushes local over the remote and\n * silently reverts it, the recorded hash points describe a tree that is no longer the PR head, and the\n * rebased tree never passes a build gate. Only ① moves the fork point AND records it; only ② rebuilds\n * and re-receipts against the new one.\n *\n * SECOND: it ASKS, it does not order. An imperative command list is what turns an agent into a loop —\n * it complies, main moves again, it complies again. Asking forces a stop at a human, which is the only\n * thing that reliably terminates a race we cannot win by retrying.\n */\n private behindRemedy(input: FinishBannerInput): string {\n const num = input.prNumber === '' ? '<n>' : input.prNumber;\n return '\\n' + SEP + this.behindSituation(input.merge) + '\\n' +\n ' ⚠️ STOP HERE AND ASK THE HUMAN. Do NOT run these yourself — if main keeps moving,\\n' +\n ' running them on your own is an infinite loop with a full build inside it.\\n\\n' +\n ' Ask, in your own words:\\n' +\n ` \"${this.behindAsk(input.merge)}\\n` +\n ` ${this.behindAskClose(input.merge)}\"\\n\\n` +\n ' Only once they say yes:\\n\\n' +\n ' pnpm wp-start-upsert-pr # 3-point merge from main — re-forks onto the new main\\n' +\n ' pnpm wp-review-upsert-pr # re-validates the merge + REBUILDS on the new fork point\\n' +\n ' pnpm wp-finish-upsert-pr # gated body + merge, now up to date\\n\\n' +\n ' Do NOT skip ②. It is the only stage that validates the new merge and rebuilds against\\n' +\n ' the new fork point; skipping it publishes a PR whose tree was never gated.\\n' +\n ' Do NOT reach for `gh pr update-branch`. It rewrites the REMOTE branch only, which stage\\n' +\n ' ③ then force-pushes over — and it lands a tree no build gate ever saw.\\n' +\n ` Verify independently, do not trust this banner:\\n` +\n ` gh pr view ${num} --json mergeable,mergeStateStatus,state\\n`;\n }\n\n // What is actually true right now, per kind. The CLEAN case gets the caveat that it may not even\n // matter: \"out of date\" only blocks a merge on repos that require branches be up to date.\n private behindSituation(merge: MergeOutcome): string {\n if (merge.result === MERGE_RESULT_BEHIND_CONFLICTING) {\n return ' Your PR is pushed, its body is written, and the build gate passed. Then someone\\n' +\n ' else landed on main, and their change CONFLICTS with yours — same lines. Real\\n' +\n ' resolution is owed, and if people keep landing ahead of you it genuinely repeats.\\n' +\n ' That is inherent to concurrent editing, not a bug and not something you did wrong.\\n';\n }\n if (merge.result === MERGE_RESULT_BEHIND_UNKNOWN) {\n return ' Your PR is pushed, its body is written, and the build gate passed. GitHub has not\\n' +\n ' finished computing mergeability yet (it is asynchronous, and we asked seconds after\\n' +\n ' the push), so we do NOT know whether this conflicts. Re-check before doing anything:\\n' +\n ' a few seconds later the answer is usually CLEAN and no work is owed at all.\\n';\n }\n return ' Your PR is pushed, its body is written, and the build gate passed. Someone else simply\\n' +\n ' landed on main first. There are NO conflicts — nobody touched your lines.\\n' +\n ' This may not even matter: \"out of date\" blocks a merge only on repos that REQUIRE\\n' +\n ' branches be up to date. If yours does not, this PR can merge as-is.\\n';\n }\n\n // The one sentence to put to the human, in their terms.\n private behindAsk(merge: MergeOutcome): string {\n if (merge.result === MERGE_RESULT_BEHIND_CONFLICTING) {\n return 'Someone beat me to landing on main and there are conflicts. We MUST run a\\n' +\n ' 3-point merge so I can resolve them properly.';\n }\n if (merge.result === MERGE_RESULT_BEHIND_UNKNOWN) {\n return 'Someone beat me to landing on main. GitHub has not said yet whether it\\n' +\n ' conflicts, so I have not touched anything.';\n }\n return 'Someone beat me to landing on main. There are no conflicts, so this is just\\n' +\n ' a re-sync — but it costs a full rebuild.';\n }\n\n // The actual question. UNKNOWN gets a DIFFERENT one: with mergeability still uncomputed, proposing a\n // full re-run is proposing work we cannot yet show is needed — a re-check is free and often ends it.\n private behindAskClose(merge: MergeOutcome): string {\n if (merge.result === MERGE_RESULT_BEHIND_UNKNOWN) {\n return 'Shall I re-check in a moment, or start the wp-*-upsert-pr process over?';\n }\n return 'May I start the wp-*-upsert-pr process over again?';\n }\n\n // A short, positive \"you are free to stop\" line for the two non-merged-but-fine outcomes, so an AI\n // reading a queued PR does not go hunting for work that is not owed.\n private doneNote(merge: MergeOutcome): string {\n if (merge.result === MERGE_RESULT_AUTO_QUEUED) {\n return ' Nothing else is owed: GitHub lands it when the checks go green. You can stop here.\\n' +\n this.watchOffer();\n }\n if (merge.result === MERGE_RESULT_LEFT_TO_HUMAN) {\n return ' This command published the PR without attempting a merge.\\n' +\n ' This setting does not require additional authorization or override existing user instructions.\\n' +\n ' If landing was requested (including $full-cycle or /full-cycle), continue through the\\n' +\n ' required checks and run `pnpm wp-land-pr`.\\n' +\n '\\n' +\n ' ℹ️ Clicking Merge in the GitHub UI is CORRECT here and produces the right history. The\\n' +\n ' PR description IS the commit body this flow rendered — compact, non-green flags\\n' +\n ' only, with the PR link on top — and this flow keeps the two repo settings that copy\\n' +\n ' it into main pinned itself (squash_merge_commit_title=PR_TITLE,\\n' +\n ' squash_merge_commit_message=PR_BODY). There is nothing for you to configure.\\n' +\n ' (`pnpm wp-land-pr` lands the identical bytes from the CLI, and also archives the\\n' +\n ' pre-squash tip and reaps the worktree. Either route is fine.)\\n';\n }\n return '';\n }\n\n /**\n * The one OPTIONAL line about watching CI — offered, never instructed.\n *\n * \"You can stop here\" above stays the DEFAULT and is deliberately printed first: landing is the\n * developer's call, and several of this repo's workflows stop at a green PR on purpose. This exists\n * for the caller who has ALREADY decided to see it land, because the alternative they otherwise\n * reach for is an `echo .` keep-alive — measured at 18.3% of every token the fleet spent in the 24h\n * to 2026-09-07 (issue #874). Naming a blocking command is cheaper than the wait somebody was going\n * to do anyway; it is not a reason to wait.\n *\n * It names the EFFICIENT WAIT and the wasteful one, and says nothing about when to end a turn\n * (issue #902). An earlier cut led with \"END YOUR TURN\"; that is a turn-level judgement the caller is\n * better placed to make than this string is, and it contradicted `SUBAGENT_CURE` shipped in the same\n * release. `--watch` is named because it exists, it blocks, and it is never refused; what it lacks is\n * a bounded exit, so the harness kills it at 600s having printed nothing.\n */\n private watchOffer(): string {\n return ' (Optional — only if you have decided to watch it land, which nothing here asks you to do.\\n' +\n ' Be efficient with tokens: `pnpm wp-await-checks --pr <n>` BLOCKS in one call and returns\\n' +\n ' at 540s asking to be run again; `gh pr checks <n> --watch` also blocks but is killed at\\n' +\n ' the 600s silence ceiling. Do not send status checks every few seconds, and\\n' +\n ' never `echo` to keep a turn alive — a turn costs your whole context.)\\n';\n }\n\n /**\n * The closing AI directive: the resolved PR's number/title/URL and an instruction to end the\n * user-facing summary with EXACTLY `[#N title](url)` as the final line, nothing after it.\n *\n * The link text CARRIES the outcome. Ending on a bare cheerful link is exactly how a stranded PR got\n * reported as finished, and the directive says the link must be last — so the truth has to live\n * inside the link itself, not merely above it.\n *\n * '' when the PR could not be resolved: better to say nothing than to point at a link that is not real.\n */\n linkDirective(input: FinishBannerInput): string {\n if (input.prNumber === '' || input.prUrl === '') return '';\n const label = this.isDone(input.merge) ? input.title : `${input.title} — ${this.notDoneTag(input.merge)}`;\n const preamble = this.isDone(input.merge)\n ? ''\n : `AI — this PR is NOT done (${this.notDoneTag(input.merge)}). Your summary MUST say so plainly.\\n` +\n (input.merge.isBehind()\n ? `MUST END BY ASKING the human for permission to re-run the flow, and MUST NOT run any of\\n` +\n `the commands above until they answer. Say plainly that nothing they did caused this —\\n` +\n `another author landed on main first — and that the PR itself is pushed and gate-green.\\n\\n`\n : `MUST include the remedy commands printed above. Do not describe this run as complete.\\n\\n`);\n return SEP + `🔗 PR #${input.prNumber}: ${input.title}\\n ${input.prUrl}\\n\\n` + SEP + preamble +\n `AI — the LAST line of your summary to the user MUST be EXACTLY this clickable link, with\\n` +\n `NOTHING printed after it (no sign-off, no next steps, no blank commentary):\\n\\n` +\n ` [#${input.prNumber} ${label}](${input.prUrl})\\n\\n`;\n }\n\n // The tag rides INSIDE the clickable link, which the directive above forces to be the last line the\n // AI prints — so it is the one piece of wording guaranteed to reach the user. It says who is waiting\n // on whom: for every BEHIND flavour the answer is \"a human\", not \"more automation\".\n private notDoneTag(merge: MergeOutcome): string {\n if (merge.result === MERGE_RESULT_BEHIND_CONFLICTING) return 'NOT MERGED — main moved and it conflicts, needs your OK to re-sync';\n if (merge.result === MERGE_RESULT_BEHIND_UNKNOWN) return 'NOT MERGED — main moved, GitHub still computing mergeability';\n if (merge.isBehind()) return 'NOT MERGED — main moved (no conflicts), needs your OK to re-sync';\n return 'NOT MERGED';\n }\n}\n"]}
@@ -6,7 +6,7 @@
6
6
  export declare const MERGE_RESULT_MERGED = "MERGED";
7
7
  /** Not merged YET, but queued: auto-merge is enabled and lands it when the checks pass. Self-healing. */
8
8
  export declare const MERGE_RESULT_AUTO_QUEUED = "AUTO_QUEUED";
9
- /** Not merged BY DESIGN: pr-gate.mergeMode is not AUTO, so a person merges. Nothing is owed here. */
9
+ /** This command did not attempt a merge; the caller may still owe landing under the user request. */
10
10
  export declare const MERGE_RESULT_LEFT_TO_HUMAN = "LEFT_TO_HUMAN";
11
11
  /**
12
12
  * Not merged and it NEVER will be without action: `gh pr view --json mergeStateStatus` says BEHIND, i.e.
@@ -97,7 +97,7 @@ export declare class MergeIntent {
97
97
  * queue to fall back to, so we say so loudly instead of firing a `--auto` that can only fail.
98
98
  *
99
99
  * WHICH of those a repo gets is not guessed — `pr-gate.mergeMode` is REQUIRED config. AUTO means the
100
- * tooling lands PRs; NONE means it only posts them and a person merges. No mode can force a queue the
100
+ * tooling attempts landing; NONE means this automatic step only publishes the PR. No mode can force a queue the
101
101
  * repo has turned off, so AUTO on a repo with allow_auto_merge=false is a CONFIG error, reported as
102
102
  * one rather than papered over — but ONLY when the AUTO was read from config. A commanded merge
103
103
  * (`wp-land-pr`) on a NONE repo is not a mismatch at all; see MergeIntent.
@@ -13,7 +13,7 @@ const inversify_1 = require("inversify");
13
13
  exports.MERGE_RESULT_MERGED = 'MERGED';
14
14
  /** Not merged YET, but queued: auto-merge is enabled and lands it when the checks pass. Self-healing. */
15
15
  exports.MERGE_RESULT_AUTO_QUEUED = 'AUTO_QUEUED';
16
- /** Not merged BY DESIGN: pr-gate.mergeMode is not AUTO, so a person merges. Nothing is owed here. */
16
+ /** This command did not attempt a merge; the caller may still owe landing under the user request. */
17
17
  exports.MERGE_RESULT_LEFT_TO_HUMAN = 'LEFT_TO_HUMAN';
18
18
  /**
19
19
  * Not merged and it NEVER will be without action: `gh pr view --json mergeStateStatus` says BEHIND, i.e.
@@ -161,7 +161,7 @@ exports.MergeIntent = MergeIntent;
161
161
  * queue to fall back to, so we say so loudly instead of firing a `--auto` that can only fail.
162
162
  *
163
163
  * WHICH of those a repo gets is not guessed — `pr-gate.mergeMode` is REQUIRED config. AUTO means the
164
- * tooling lands PRs; NONE means it only posts them and a person merges. No mode can force a queue the
164
+ * tooling attempts landing; NONE means this automatic step only publishes the PR. No mode can force a queue the
165
165
  * repo has turned off, so AUTO on a repo with allow_auto_merge=false is a CONFIG error, reported as
166
166
  * one rather than papered over — but ONLY when the AUTO was read from config. A commanded merge
167
167
  * (`wp-land-pr`) on a NONE repo is not a mismatch at all; see MergeIntent.
@@ -187,13 +187,15 @@ let PrMerger = class PrMerger {
187
187
  // long dashboard. It is now the compact git-log body (see Dashboard.renderPrBody), so
188
188
  // `squash_merge_commit_message: PR_BODY` copies exactly the right text and a UI merge is
189
189
  // CORRECT — provided both settings are right. Naming them is the useful thing to say; telling
190
- // a mergeMode=NONE repo to stop using the UI is not, since using it is the whole policy.
191
- return new MergeOutcome(false, false, `did NOT merge — pr-gate.mergeMode is ${mergeMode === rules_config_1.MERGE_MODE_NONE ? 'NONE' : `"${mergeMode}"`}, so the PR is left for a human to merge.\n` +
190
+ // a mergeMode=NONE repo to stop using the UI is not; either landing route is valid.
191
+ return new MergeOutcome(false, false, `did NOT merge — pr-gate.mergeMode is ${mergeMode === rules_config_1.MERGE_MODE_NONE ? 'NONE' : `"${mergeMode}"`}, so wp-finish-upsert-pr published the PR without attempting a merge.\n` +
192
192
  ` Clicking Merge is fine and writes the right history: this flow keeps\n` +
193
193
  ` squash_merge_commit_title=PR_TITLE and squash_merge_commit_message=PR_BODY pinned on\n` +
194
194
  ` the repo, so the subject becomes "${subject}" and the body is the gated description\n` +
195
195
  ` verbatim. Nothing to set up.\n` +
196
- ` \`pnpm wp-land-pr\` lands the same bytes from the CLI if you would rather not click.`, exports.MERGE_RESULT_LEFT_TO_HUMAN);
196
+ ` \`pnpm wp-land-pr\` lands the same bytes from the CLI.\n` +
197
+ ` This setting does not require additional authorization. Honor existing user instructions,\n` +
198
+ ` including $full-cycle or /full-cycle, and continue to landing when requested.`, exports.MERGE_RESULT_LEFT_TO_HUMAN);
197
199
  }
198
200
  // A direct `gh pr merge --squash --subject --body-file` writes exactly this subject/body to
199
201
  // main's history regardless of the repo's squash_merge_commit_title/message defaults — and
@@ -1 +1 @@
1
- {"version":3,"file":"pr-merger.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/sc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,GAAG,MAAM,CAAC;IACzB,CAAC;CACJ;AARD,4BAQC","sourcesContent":["import { spawnSync } from 'child_process';\nimport { MERGE_MODE_AUTO, MERGE_MODE_NONE } from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\n\n/**\n * The five terminal shapes a merge attempt can take. The CALLER branches on these — a `message` string\n * is for humans to read, never for code to pattern-match, and the banner that frames it must be able to\n * tell \"done\" from \"stranded\" without parsing prose.\n */\nexport const MERGE_RESULT_MERGED = 'MERGED';\n/** Not merged YET, but queued: auto-merge is enabled and lands it when the checks pass. Self-healing. */\nexport const MERGE_RESULT_AUTO_QUEUED = 'AUTO_QUEUED';\n/** Not merged BY DESIGN: pr-gate.mergeMode is not AUTO, so a person merges. Nothing is owed here. */\nexport const MERGE_RESULT_LEFT_TO_HUMAN = 'LEFT_TO_HUMAN';\n/**\n * Not merged and it NEVER will be without action: `gh pr view --json mergeStateStatus` says BEHIND, i.e.\n * the head branch is out of date with base. Unlike BLOCKED (waiting on checks — self-healing), BEHIND\n * cannot resolve itself; the branch must be re-synced from main. This is the case that used to print a\n * green \"✅ PR finished\" and get abandoned.\n */\nexport const MERGE_RESULT_BEHIND = 'BEHIND';\n/**\n * BEHIND *and* GitHub says the tree merges cleanly (`mergeable: MERGEABLE`). Nobody touched the same\n * lines — somebody simply landed on main first. One clean re-run of ①②③ converges. Split out from the\n * conflicting case because the two need completely different sentences: this one is not the author's\n * problem to solve, it is a queue collision, and telling them \"resolve the conflict\" is a lie.\n */\nexport const MERGE_RESULT_BEHIND_CLEAN = 'BEHIND_CLEAN';\n/**\n * BEHIND *and* `mergeable: CONFLICTING` — the landed work and this branch touch the same lines. Real\n * human/AI judgement is owed, and if others keep landing first it genuinely repeats. That is inherent to\n * concurrent editing, not a defect, and the banner says so rather than pretending a re-run is free.\n */\nexport const MERGE_RESULT_BEHIND_CONFLICTING = 'BEHIND_CONFLICTING';\n/**\n * BEHIND but `mergeable: UNKNOWN` (or unreadable). GitHub computes mergeability ASYNCHRONOUSLY and we ask\n * moments after a force-push, so UNKNOWN is the EXPECTED answer, not an error. Diagnosing from it would be\n * guessing, so this outcome asks for a re-check instead of prescribing a remedy.\n */\nexport const MERGE_RESULT_BEHIND_UNKNOWN = 'BEHIND_UNKNOWN';\n/** Not merged for some other reason (config mismatch, gh error, no PR at all). Read `message`. */\nexport const MERGE_RESULT_FAILED = 'FAILED';\n\n// The `mergeStateStatus` value GitHub reports for \"head branch is not up to date with the base branch\".\nconst GH_STATE_BEHIND = 'BEHIND';\n// `mergeable` values. GitHub returns UNKNOWN while it is still computing the merge — which is most of the\n// time in the seconds after a push — so UNKNOWN must never be read as \"no conflicts\".\nconst GH_MERGEABLE_CLEAN = 'MERGEABLE';\nconst GH_MERGEABLE_CONFLICTING = 'CONFLICTING';\n\n// What actually happened when we tried to land the squash merge. `message` is printed VERBATIM in the\n// final wp-finish-upsert-pr summary, so a merge that did not happen can never be reported as done —\n// the old code ignored `spawnSync().status` entirely and printed \"✅ PR finished\" even when `gh pr\n// merge` had errored out, which is what hid the auto-merge-disabled failure for weeks. `result` is the\n// machine-readable half of the same honesty: the banner picks its HEADER from it, so the frame around\n// the message can no longer say \"finished\" while the message says \"did NOT merge\".\nexport class MergeOutcome {\n merged: boolean;\n autoMergeEnabled: boolean;\n message: string;\n result: string;\n\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(merged: boolean, autoMergeEnabled: boolean, message: string, result: string) {\n this.merged = merged;\n this.autoMergeEnabled = autoMergeEnabled;\n this.message = message;\n this.result = result;\n }\n\n // TRUE for every flavour of \"the branch is out of date with main\", so the banner can ask that one\n // question once instead of listing four constants at each branch point. Kept here rather than as a\n // module function because `no-function-outside-class` forbids the latter — and PrMergeState below\n // already sets the precedent that a verdict class answers questions about itself.\n isBehind(): boolean {\n return this.result === MERGE_RESULT_BEHIND\n || this.result === MERGE_RESULT_BEHIND_CLEAN\n || this.result === MERGE_RESULT_BEHIND_CONFLICTING\n || this.result === MERGE_RESULT_BEHIND_UNKNOWN;\n }\n}\n\n// GitHub's own verdict on the PR, straight from `gh pr view --json mergeable,mergeStateStatus,state`.\n// All '' when gh could not be asked — an unreadable answer must never be treated as a diagnosis.\nexport class PrMergeState {\n mergeable: string;\n mergeStateStatus: string;\n state: string;\n\n constructor(mergeable: string, mergeStateStatus: string, state: string) {\n this.mergeable = mergeable;\n this.mergeStateStatus = mergeStateStatus;\n this.state = state;\n }\n\n isBehind(): boolean {\n return this.mergeStateStatus === GH_STATE_BEHIND;\n }\n\n /**\n * WHICH kind of BEHIND this is, from the `mergeable` field we have always fetched and never read.\n *\n * This is the whole point of the split. \"Out of date\" and \"conflicting\" are different situations with\n * different costs, and collapsing them told every author the expensive story: a clean queue collision\n * — nobody touched your lines, somebody just landed first — got reported in the same alarming words as\n * a genuine textual conflict.\n *\n * UNKNOWN is its own answer, never folded into CLEAN. GitHub computes mergeability asynchronously and\n * we ask seconds after a force-push, so UNKNOWN is the ordinary reply in exactly our situation.\n * Treating it as \"no conflicts\" would promise a clean re-run we cannot see.\n */\n behindKind(): string {\n if (this.mergeable === GH_MERGEABLE_CLEAN) return MERGE_RESULT_BEHIND_CLEAN;\n if (this.mergeable === GH_MERGEABLE_CONFLICTING) return MERGE_RESULT_BEHIND_CONFLICTING;\n return MERGE_RESULT_BEHIND_UNKNOWN;\n }\n\n // One-line rendering for the failure message, or '' when GitHub could not be asked.\n describe(): string {\n if (this.mergeStateStatus === '') return '';\n return `mergeable=${this.mergeable}, mergeStateStatus=${this.mergeStateStatus}, state=${this.state}`;\n }\n}\n\n/**\n * WHY this run is allowed to merge — the config value, kept separate from the caller's intent.\n *\n * Those two used to be one `mergeMode: string` parameter, and `wp-land-pr` passed a literal\n * `MERGE_MODE_AUTO` through it to mean \"merge it\" rather than \"config says AUTO\". PrMerger could not\n * tell the two apart, so on a `mergeMode: \"NONE\"` repo it reported a CONFIG MISMATCH naming a value\n * nobody had set, and prescribed remedies that were already in place. Keeping the real `mergeMode`\n * alongside a `commanded` flag means no message ever has to assert a config value the code did not read.\n */\nexport class MergeIntent {\n /** pr-gate.mergeMode EXACTLY as read from webpieces.config.json — '' when it could not be read. */\n mergeMode: string;\n /**\n * TRUE when running the command IS the intent to merge (`wp-land-pr`), so the merge happens whatever\n * the config says. FALSE for the policy-driven caller (`wp-finish-upsert-pr`), where only an\n * explicit AUTO merges.\n */\n commanded: boolean;\n\n constructor(mergeMode: string, commanded: boolean) {\n this.mergeMode = mergeMode;\n this.commanded = commanded;\n }\n\n // The gate: a commanded run always proceeds; otherwise only an explicit AUTO does. Anything else\n // (including a repo on a published rules-config that predates the field) is treated as NONE —\n // when the policy is unreadable, do NOT touch main.\n shouldMerge(): boolean {\n return this.commanded || this.mergeMode === MERGE_MODE_AUTO;\n }\n}\n\n/**\n * Lands — or queues — the squash merge with an EXPLICIT subject/body, on BOTH kinds of repo:\n *\n * - auto-merge ALLOWED (`allow_auto_merge: true`): a PR whose checks are still running falls back to\n * the auto-merge queue, carrying the same subject/body so it lands when the checks pass.\n * - auto-merge DISALLOWED (`allow_auto_merge: false`, a deliberate policy control in many orgs): the\n * direct merge still works the moment the PR is mergeable, because `gh pr merge --squash --subject\n * --body-file` does not depend on that setting at all. When the PR is NOT yet mergeable there is no\n * queue to fall back to, so we say so loudly instead of firing a `--auto` that can only fail.\n *\n * WHICH of those a repo gets is not guessed — `pr-gate.mergeMode` is REQUIRED config. AUTO means the\n * tooling lands PRs; NONE means it only posts them and a person merges. No mode can force a queue the\n * repo has turned off, so AUTO on a repo with allow_auto_merge=false is a CONFIG error, reported as\n * one rather than papered over — but ONLY when the AUTO was read from config. A commanded merge\n * (`wp-land-pr`) on a NONE repo is not a mismatch at all; see MergeIntent.\n *\n * Every `gh` status is checked. Nothing here is allowed to fail silently.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class PrMerger {\n /**\n * @param subject the squash-commit subject, normally `<PR title> (#N)`\n * @param mergeBodyFile file holding the squash-commit body (risk/flags/PR link)\n * @param intent the real pr-gate.mergeMode PLUS whether this caller commands the merge\n * regardless of it (see MergeIntent).\n */\n merge(baseBranch: string, subject: string, mergeBodyFile: string, intent: MergeIntent): MergeOutcome {\n // Anything that is not an explicit AUTO leaves the PR alone. The PR itself is already\n // posted/updated by this point, which is the whole job in this mode.\n if (!intent.shouldMerge()) {\n const mergeMode = intent.mergeMode;\n // What a UI merge produces, in terms of the repo's OWN two settings.\n //\n // This message said the opposite one release ago: \"a UI merge pastes the whole dashboard into\n // git log, land it with wp-land-pr instead\". That was true while the PR description held the\n // long dashboard. It is now the compact git-log body (see Dashboard.renderPrBody), so\n // `squash_merge_commit_message: PR_BODY` copies exactly the right text and a UI merge is\n // CORRECT — provided both settings are right. Naming them is the useful thing to say; telling\n // a mergeMode=NONE repo to stop using the UI is not, since using it is the whole policy.\n return new MergeOutcome(false, false,\n `did NOT merge — pr-gate.mergeMode is ${mergeMode === MERGE_MODE_NONE ? 'NONE' : `\"${mergeMode}\"`}, so the PR is left for a human to merge.\\n` +\n ` Clicking Merge is fine and writes the right history: this flow keeps\\n` +\n ` squash_merge_commit_title=PR_TITLE and squash_merge_commit_message=PR_BODY pinned on\\n` +\n ` the repo, so the subject becomes \"${subject}\" and the body is the gated description\\n` +\n ` verbatim. Nothing to set up.\\n` +\n ` \\`pnpm wp-land-pr\\` lands the same bytes from the CLI if you would rather not click.`,\n MERGE_RESULT_LEFT_TO_HUMAN);\n }\n\n // A direct `gh pr merge --squash --subject --body-file` writes exactly this subject/body to\n // main's history regardless of the repo's squash_merge_commit_title/message defaults — and\n // regardless of allow_auto_merge. It is the ONLY path that guarantees the good commit message.\n //\n // Its output is CAPTURED, not inherited: this attempt fails BY DESIGN on any repo whose policy\n // forbids a direct merge, and gh's raw `X Pull request #N is not mergeable: …` on the terminal\n // read as a hard failure to every human and agent who saw it. We reprint the reason ourselves,\n // framed as the expected first step of a two-step dance (see announceDirectFailure).\n const direct = this.ghCapture(['pr', 'merge', baseBranch, '--squash', '--subject', subject, '--body-file', mergeBodyFile]);\n if (direct.status === 0) {\n process.stdout.write(direct.output);\n return new MergeOutcome(true, false, `squash-merged the PR as: \"${subject}\"`, MERGE_RESULT_MERGED);\n }\n\n // Past here the PR is not mergeable yet. WHY matters enormously and gh's exit status does not\n // say: checks-still-running (BLOCKED) is self-healing once auto-merge is on, while out-of-date\n // (BEHIND) can NEVER land unattended. Ask GitHub itself — one cheap, failure-tolerant call, made\n // only on the failure path, so a run whose direct merge succeeded costs no extra API call.\n const state = this.prMergeState(baseBranch);\n this.announceDirectFailure(direct.output, state);\n return this.fallBackToAutoMerge(baseBranch, subject, mergeBodyFile, state, intent);\n }\n\n /**\n * The auto-merge queue: the only way to still land a not-yet-mergeable PR unattended. Returns the\n * BEHIND outcome regardless of how queuing went whenever GitHub says the branch is out of date —\n * queuing a BEHIND PR is not an error (a repo that auto-updates branches will still land it), but it\n * is NOT success either, and reporting it as such is precisely the bug this whole file guards.\n */\n // eslint-disable-next-line @typescript-eslint/max-params\n private fallBackToAutoMerge(baseBranch: string, subject: string, mergeBodyFile: string, state: PrMergeState, intent: MergeIntent): MergeOutcome {\n if (!this.autoMergeAllowed()) {\n if (state.isBehind()) return this.behindOutcome(state, false);\n return new MergeOutcome(false, false, this.noQueueMessage(intent), MERGE_RESULT_FAILED);\n }\n\n process.stdout.write(' … retrying with --auto (the auto-merge queue)\\n');\n // gh records the merge subject/body only at the moment auto-merge is FIRST enabled; a second\n // `--auto` on an already-enabled PR silently keeps the OLD body. Disabling first re-stamps the\n // current subject/body on every re-run (a harmless no-op when auto-merge is not enabled).\n this.gh(['pr', 'merge', baseBranch, '--disable-auto'], true);\n const auto = this.gh(['pr', 'merge', baseBranch, '--auto', '--squash', '--subject', subject, '--body-file', mergeBodyFile]);\n if (auto !== 0) {\n if (state.isBehind()) return this.behindOutcome(state, false);\n return new MergeOutcome(false, false,\n '⚠️ did NOT merge and could NOT enable auto-merge either (see the gh error above) —\\n' +\n ' NOTHING is queued. Re-run once the PR is healthy.',\n MERGE_RESULT_FAILED);\n }\n if (state.isBehind()) return this.behindOutcome(state, true);\n return new MergeOutcome(false, true,\n `enabled auto-merge — it will squash-merge as \"${subject}\" when the checks pass`,\n MERGE_RESULT_AUTO_QUEUED);\n }\n\n /**\n * \"Not mergeable yet, and this repo has no queue to park it in\" — in the words that are TRUE for the\n * caller we actually have.\n *\n * A COMMANDED run (`wp-land-pr`) is not a misconfiguration at all: nobody set mergeMode to AUTO, the\n * user asked for a merge by hand, and the checks simply are not green yet. Telling that reader to\n * \"set mergeMode to NONE\" named a value they had already set and sent them investigating a mismatch\n * that did not exist. Nothing is owed here but a re-run.\n *\n * A POLICY-driven run (`wp-finish-upsert-pr`) only reaches here with a config that really does say\n * AUTO on a repo that forbids the queue — the genuine mismatch, where both remedies are real.\n */\n private noQueueMessage(intent: MergeIntent): string {\n if (intent.commanded) {\n return '⚠️ did NOT merge, and queued NOTHING — the PR is not mergeable yet (checks still\\n' +\n ' running, or a required review outstanding), and this repo has allow_auto_merge=false,\\n' +\n ' so there was no queue to fall back to. NOTHING is misconfigured and nothing needs\\n' +\n ' changing — re-run `pnpm wp-land-pr` once the PR is green and it will land.';\n }\n return '⚠️ did NOT merge, and queued NOTHING — CONFIG MISMATCH: pr-gate.mergeMode is AUTO, but\\n' +\n ' this repo has allow_auto_merge=false, so there is no queue to fall back to and the\\n' +\n ' PR is not mergeable yet. `gh pr merge --auto` cannot override a repo that says no.\\n' +\n ' Fix it at ONE of the two ends: turn on \"Allow auto-merge\" in the repo settings, or\\n' +\n ' set commands.pr-gate.mergeMode to \"NONE\" (and set that repo\\'s\\n' +\n ' squash_merge_commit_title to PR_TITLE so a human merge still gets a real subject).';\n }\n\n /**\n * The one outcome that looks queued but is stranded. `queued` says whether auto-merge did get enabled,\n * because \"parked forever\" and \"not queued at all\" need different sentences — but neither is done.\n *\n * The `result` now carries WHICH kind of behind, so the banner can stop describing a queue collision\n * in the vocabulary of a merge conflict. The wording here is deliberately blame-free: nothing the\n * author did caused this, and the PR itself is in perfectly good shape — pushed, bodied, gate-green.\n */\n private behindOutcome(state: PrMergeState, queued: boolean): MergeOutcome {\n const parked = queued ? 'Auto-merge is enabled but parked.' : 'Nothing is queued.';\n return new MergeOutcome(false, queued,\n `did NOT merge — someone else landed on main first, so GitHub wants this branch rebuilt on\\n` +\n ` top of theirs before it will merge (${state.describe()}).\\n` +\n ` This does NOT self-heal: auto-merge never updates your branch. ${parked}`,\n state.behindKind());\n }\n\n // Reprint the expected first-attempt failure as CONTEXT, not as a verdict. gh's own `X …` line is\n // captured (never inherited) so this framing is the only thing on screen.\n private announceDirectFailure(ghOutput: string, state: PrMergeState): void {\n const reason = ghOutput.trim().split('\\n').filter((l: string): boolean => l.trim() !== '').pop() ?? '';\n process.stdout.write(\n 'ℹ️ the direct squash-merge did not go through (expected while checks run, or when repo\\n' +\n ' policy forbids direct merges):\\n' +\n (reason === '' ? '' : ` ${reason}\\n`) +\n (state.describe() === '' ? '' : ` GitHub says: ${state.describe()}\\n`),\n );\n }\n\n /**\n * GitHub's own verdict on the PR. AUTHORITATIVE for the BEHIND check — the alternative is\n * pattern-matching gh's English error prose, which changes between releases. Failure-tolerant on\n * purpose: a gh hiccup returns an all-'' state (never BEHIND) so a transient API blip can only cost\n * us the extra diagnosis, never turn a working run into a crash.\n */\n protected prMergeState(baseBranch: string): PrMergeState {\n const result = spawnSync(\n 'gh',\n ['pr', 'view', baseBranch, '--json', 'mergeable,mergeStateStatus,state',\n '--jq', '\"\\\\(.mergeable)\\\\t\\\\(.mergeStateStatus)\\\\t\\\\(.state)\"'],\n { encoding: 'utf8' },\n );\n if (result.status !== 0) return new PrMergeState('', '', '');\n const parts = (result.stdout ?? '').trim().split('\\t');\n return new PrMergeState(parts[0] ?? '', parts[1] ?? '', parts[2] ?? '');\n }\n\n // Whether `gh pr merge --auto` is even possible on this repo. Many orgs set allow_auto_merge=false\n // as a policy control, where `--auto` can only ever fail with `GraphQL: Auto merge is not allowed\n // for this repository`. One API call beats discovering that from an error string. Anything other\n // than a clean `true` counts as NOT allowed: if the setting cannot be read we must not claim the\n // queue is available.\n protected autoMergeAllowed(): boolean {\n const result = spawnSync('gh', ['api', 'repos/{owner}/{repo}', '--jq', '.allow_auto_merge'], { encoding: 'utf8' });\n return result.status === 0 && (result.stdout ?? '').trim() === 'true';\n }\n\n // Runs `gh`, returning its exit status (-1 when gh could not be spawned at all, which must NOT be\n // mistaken for the 0 that means success).\n protected gh(args: string[], quiet: boolean = false): number {\n const result = spawnSync('gh', args, { stdio: quiet ? 'ignore' : 'inherit' });\n return result.status ?? -1;\n }\n\n // Runs `gh` CAPTURING both streams instead of inheriting them, so an expected-to-fail attempt can be\n // reported in our own words rather than dumping a raw `X …` line the reader reads as fatal.\n protected ghCapture(args: string[]): GhResult {\n const result = spawnSync('gh', args, { encoding: 'utf8' });\n return new GhResult(result.status ?? -1, (result.stdout ?? '') + (result.stderr ?? ''));\n }\n}\n\n// A captured `gh` invocation: its exit status (-1 when gh could not be spawned) and both streams\n// combined, in the order a terminal would have shown them.\nexport class GhResult {\n status: number;\n output: string;\n\n constructor(status: number, output: string) {\n this.status = status;\n this.output = output;\n }\n}\n"]}
1
+ {"version":3,"file":"pr-merger.js","sourceRoot":"","sources":["../../../../../../../packages/tooling/pr-gate/src/scripts/workflow/pr-merger.ts"],"names":[],"mappings":";;;;AAAA,iDAA0C;AAC1C,0DAA2E;AAC3E,yCAA2D;AAE3D;;;;GAIG;AACU,QAAA,mBAAmB,GAAG,QAAQ,CAAC;AAC5C,yGAAyG;AAC5F,QAAA,wBAAwB,GAAG,aAAa,CAAC;AACtD,qGAAqG;AACxF,QAAA,0BAA0B,GAAG,eAAe,CAAC;AAC1D;;;;;GAKG;AACU,QAAA,mBAAmB,GAAG,QAAQ,CAAC;AAC5C;;;;;GAKG;AACU,QAAA,yBAAyB,GAAG,cAAc,CAAC;AACxD;;;;GAIG;AACU,QAAA,+BAA+B,GAAG,oBAAoB,CAAC;AACpE;;;;GAIG;AACU,QAAA,2BAA2B,GAAG,gBAAgB,CAAC;AAC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AAK,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC;QAC9E,OAAO,MAAM,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC;IAC/B,CAAC;IAED,qGAAqG;IACrG,4FAA4F;IAClF,SAAS,CAAC,IAAc;QAC9B,MAAM,MAAM,GAAG,IAAA,yBAAS,EAAC,IAAI,EAAE,IAAI,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;QAC3D,OAAO,IAAI,QAAQ,CAAC,MAAM,CAAC,MAAM,IAAI,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,CAAC;IAC5F,CAAC;CACJ,CAAA;AAxLY,4BAAQ;mBAAR,QAAQ;IADpB,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;GAC5B,QAAQ,CAwLpB;AAED,iGAAiG;AACjG,2DAA2D;AAC3D,MAAa,QAAQ;IACjB,MAAM,CAAS;IACf,MAAM,CAAS;IAEf,YAAY,MAAc,EAAE,MAAc;QACtC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;CACJ;AARD,4BAQC","sourcesContent":["import { spawnSync } from 'child_process';\nimport { MERGE_MODE_AUTO, MERGE_MODE_NONE } from '@webpieces/rules-config';\nimport { injectable, bindingScopeValues } from 'inversify';\n\n/**\n * The five terminal shapes a merge attempt can take. The CALLER branches on these — a `message` string\n * is for humans to read, never for code to pattern-match, and the banner that frames it must be able to\n * tell \"done\" from \"stranded\" without parsing prose.\n */\nexport const MERGE_RESULT_MERGED = 'MERGED';\n/** Not merged YET, but queued: auto-merge is enabled and lands it when the checks pass. Self-healing. */\nexport const MERGE_RESULT_AUTO_QUEUED = 'AUTO_QUEUED';\n/** This command did not attempt a merge; the caller may still owe landing under the user request. */\nexport const MERGE_RESULT_LEFT_TO_HUMAN = 'LEFT_TO_HUMAN';\n/**\n * Not merged and it NEVER will be without action: `gh pr view --json mergeStateStatus` says BEHIND, i.e.\n * the head branch is out of date with base. Unlike BLOCKED (waiting on checks — self-healing), BEHIND\n * cannot resolve itself; the branch must be re-synced from main. This is the case that used to print a\n * green \"✅ PR finished\" and get abandoned.\n */\nexport const MERGE_RESULT_BEHIND = 'BEHIND';\n/**\n * BEHIND *and* GitHub says the tree merges cleanly (`mergeable: MERGEABLE`). Nobody touched the same\n * lines — somebody simply landed on main first. One clean re-run of ①②③ converges. Split out from the\n * conflicting case because the two need completely different sentences: this one is not the author's\n * problem to solve, it is a queue collision, and telling them \"resolve the conflict\" is a lie.\n */\nexport const MERGE_RESULT_BEHIND_CLEAN = 'BEHIND_CLEAN';\n/**\n * BEHIND *and* `mergeable: CONFLICTING` — the landed work and this branch touch the same lines. Real\n * human/AI judgement is owed, and if others keep landing first it genuinely repeats. That is inherent to\n * concurrent editing, not a defect, and the banner says so rather than pretending a re-run is free.\n */\nexport const MERGE_RESULT_BEHIND_CONFLICTING = 'BEHIND_CONFLICTING';\n/**\n * BEHIND but `mergeable: UNKNOWN` (or unreadable). GitHub computes mergeability ASYNCHRONOUSLY and we ask\n * moments after a force-push, so UNKNOWN is the EXPECTED answer, not an error. Diagnosing from it would be\n * guessing, so this outcome asks for a re-check instead of prescribing a remedy.\n */\nexport const MERGE_RESULT_BEHIND_UNKNOWN = 'BEHIND_UNKNOWN';\n/** Not merged for some other reason (config mismatch, gh error, no PR at all). Read `message`. */\nexport const MERGE_RESULT_FAILED = 'FAILED';\n\n// The `mergeStateStatus` value GitHub reports for \"head branch is not up to date with the base branch\".\nconst GH_STATE_BEHIND = 'BEHIND';\n// `mergeable` values. GitHub returns UNKNOWN while it is still computing the merge — which is most of the\n// time in the seconds after a push — so UNKNOWN must never be read as \"no conflicts\".\nconst GH_MERGEABLE_CLEAN = 'MERGEABLE';\nconst GH_MERGEABLE_CONFLICTING = 'CONFLICTING';\n\n// What actually happened when we tried to land the squash merge. `message` is printed VERBATIM in the\n// final wp-finish-upsert-pr summary, so a merge that did not happen can never be reported as done —\n// the old code ignored `spawnSync().status` entirely and printed \"✅ PR finished\" even when `gh pr\n// merge` had errored out, which is what hid the auto-merge-disabled failure for weeks. `result` is the\n// machine-readable half of the same honesty: the banner picks its HEADER from it, so the frame around\n// the message can no longer say \"finished\" while the message says \"did NOT merge\".\nexport class MergeOutcome {\n merged: boolean;\n autoMergeEnabled: boolean;\n message: string;\n result: string;\n\n // eslint-disable-next-line @typescript-eslint/max-params\n constructor(merged: boolean, autoMergeEnabled: boolean, message: string, result: string) {\n this.merged = merged;\n this.autoMergeEnabled = autoMergeEnabled;\n this.message = message;\n this.result = result;\n }\n\n // TRUE for every flavour of \"the branch is out of date with main\", so the banner can ask that one\n // question once instead of listing four constants at each branch point. Kept here rather than as a\n // module function because `no-function-outside-class` forbids the latter — and PrMergeState below\n // already sets the precedent that a verdict class answers questions about itself.\n isBehind(): boolean {\n return this.result === MERGE_RESULT_BEHIND\n || this.result === MERGE_RESULT_BEHIND_CLEAN\n || this.result === MERGE_RESULT_BEHIND_CONFLICTING\n || this.result === MERGE_RESULT_BEHIND_UNKNOWN;\n }\n}\n\n// GitHub's own verdict on the PR, straight from `gh pr view --json mergeable,mergeStateStatus,state`.\n// All '' when gh could not be asked — an unreadable answer must never be treated as a diagnosis.\nexport class PrMergeState {\n mergeable: string;\n mergeStateStatus: string;\n state: string;\n\n constructor(mergeable: string, mergeStateStatus: string, state: string) {\n this.mergeable = mergeable;\n this.mergeStateStatus = mergeStateStatus;\n this.state = state;\n }\n\n isBehind(): boolean {\n return this.mergeStateStatus === GH_STATE_BEHIND;\n }\n\n /**\n * WHICH kind of BEHIND this is, from the `mergeable` field we have always fetched and never read.\n *\n * This is the whole point of the split. \"Out of date\" and \"conflicting\" are different situations with\n * different costs, and collapsing them told every author the expensive story: a clean queue collision\n * — nobody touched your lines, somebody just landed first — got reported in the same alarming words as\n * a genuine textual conflict.\n *\n * UNKNOWN is its own answer, never folded into CLEAN. GitHub computes mergeability asynchronously and\n * we ask seconds after a force-push, so UNKNOWN is the ordinary reply in exactly our situation.\n * Treating it as \"no conflicts\" would promise a clean re-run we cannot see.\n */\n behindKind(): string {\n if (this.mergeable === GH_MERGEABLE_CLEAN) return MERGE_RESULT_BEHIND_CLEAN;\n if (this.mergeable === GH_MERGEABLE_CONFLICTING) return MERGE_RESULT_BEHIND_CONFLICTING;\n return MERGE_RESULT_BEHIND_UNKNOWN;\n }\n\n // One-line rendering for the failure message, or '' when GitHub could not be asked.\n describe(): string {\n if (this.mergeStateStatus === '') return '';\n return `mergeable=${this.mergeable}, mergeStateStatus=${this.mergeStateStatus}, state=${this.state}`;\n }\n}\n\n/**\n * WHY this run is allowed to merge — the config value, kept separate from the caller's intent.\n *\n * Those two used to be one `mergeMode: string` parameter, and `wp-land-pr` passed a literal\n * `MERGE_MODE_AUTO` through it to mean \"merge it\" rather than \"config says AUTO\". PrMerger could not\n * tell the two apart, so on a `mergeMode: \"NONE\"` repo it reported a CONFIG MISMATCH naming a value\n * nobody had set, and prescribed remedies that were already in place. Keeping the real `mergeMode`\n * alongside a `commanded` flag means no message ever has to assert a config value the code did not read.\n */\nexport class MergeIntent {\n /** pr-gate.mergeMode EXACTLY as read from webpieces.config.json — '' when it could not be read. */\n mergeMode: string;\n /**\n * TRUE when running the command IS the intent to merge (`wp-land-pr`), so the merge happens whatever\n * the config says. FALSE for the policy-driven caller (`wp-finish-upsert-pr`), where only an\n * explicit AUTO merges.\n */\n commanded: boolean;\n\n constructor(mergeMode: string, commanded: boolean) {\n this.mergeMode = mergeMode;\n this.commanded = commanded;\n }\n\n // The gate: a commanded run always proceeds; otherwise only an explicit AUTO does. Anything else\n // (including a repo on a published rules-config that predates the field) is treated as NONE —\n // when the policy is unreadable, do NOT touch main.\n shouldMerge(): boolean {\n return this.commanded || this.mergeMode === MERGE_MODE_AUTO;\n }\n}\n\n/**\n * Lands — or queues — the squash merge with an EXPLICIT subject/body, on BOTH kinds of repo:\n *\n * - auto-merge ALLOWED (`allow_auto_merge: true`): a PR whose checks are still running falls back to\n * the auto-merge queue, carrying the same subject/body so it lands when the checks pass.\n * - auto-merge DISALLOWED (`allow_auto_merge: false`, a deliberate policy control in many orgs): the\n * direct merge still works the moment the PR is mergeable, because `gh pr merge --squash --subject\n * --body-file` does not depend on that setting at all. When the PR is NOT yet mergeable there is no\n * queue to fall back to, so we say so loudly instead of firing a `--auto` that can only fail.\n *\n * WHICH of those a repo gets is not guessed — `pr-gate.mergeMode` is REQUIRED config. AUTO means the\n * tooling attempts landing; NONE means this automatic step only publishes the PR. No mode can force a queue the\n * repo has turned off, so AUTO on a repo with allow_auto_merge=false is a CONFIG error, reported as\n * one rather than papered over — but ONLY when the AUTO was read from config. A commanded merge\n * (`wp-land-pr`) on a NONE repo is not a mismatch at all; see MergeIntent.\n *\n * Every `gh` status is checked. Nothing here is allowed to fail silently.\n */\n@injectable(bindingScopeValues.Singleton)\nexport class PrMerger {\n /**\n * @param subject the squash-commit subject, normally `<PR title> (#N)`\n * @param mergeBodyFile file holding the squash-commit body (risk/flags/PR link)\n * @param intent the real pr-gate.mergeMode PLUS whether this caller commands the merge\n * regardless of it (see MergeIntent).\n */\n merge(baseBranch: string, subject: string, mergeBodyFile: string, intent: MergeIntent): MergeOutcome {\n // Anything that is not an explicit AUTO leaves the PR alone. The PR itself is already\n // posted/updated by this point, which is the whole job in this mode.\n if (!intent.shouldMerge()) {\n const mergeMode = intent.mergeMode;\n // What a UI merge produces, in terms of the repo's OWN two settings.\n //\n // This message said the opposite one release ago: \"a UI merge pastes the whole dashboard into\n // git log, land it with wp-land-pr instead\". That was true while the PR description held the\n // long dashboard. It is now the compact git-log body (see Dashboard.renderPrBody), so\n // `squash_merge_commit_message: PR_BODY` copies exactly the right text and a UI merge is\n // CORRECT — provided both settings are right. Naming them is the useful thing to say; telling\n // a mergeMode=NONE repo to stop using the UI is not; either landing route is valid.\n return new MergeOutcome(false, false,\n `did NOT merge — pr-gate.mergeMode is ${mergeMode === MERGE_MODE_NONE ? 'NONE' : `\"${mergeMode}\"`}, so wp-finish-upsert-pr published the PR without attempting a merge.\\n` +\n ` Clicking Merge is fine and writes the right history: this flow keeps\\n` +\n ` squash_merge_commit_title=PR_TITLE and squash_merge_commit_message=PR_BODY pinned on\\n` +\n ` the repo, so the subject becomes \"${subject}\" and the body is the gated description\\n` +\n ` verbatim. Nothing to set up.\\n` +\n ` \\`pnpm wp-land-pr\\` lands the same bytes from the CLI.\\n` +\n ` This setting does not require additional authorization. Honor existing user instructions,\\n` +\n ` including $full-cycle or /full-cycle, and continue to landing when requested.`,\n MERGE_RESULT_LEFT_TO_HUMAN);\n }\n\n // A direct `gh pr merge --squash --subject --body-file` writes exactly this subject/body to\n // main's history regardless of the repo's squash_merge_commit_title/message defaults — and\n // regardless of allow_auto_merge. It is the ONLY path that guarantees the good commit message.\n //\n // Its output is CAPTURED, not inherited: this attempt fails BY DESIGN on any repo whose policy\n // forbids a direct merge, and gh's raw `X Pull request #N is not mergeable: …` on the terminal\n // read as a hard failure to every human and agent who saw it. We reprint the reason ourselves,\n // framed as the expected first step of a two-step dance (see announceDirectFailure).\n const direct = this.ghCapture(['pr', 'merge', baseBranch, '--squash', '--subject', subject, '--body-file', mergeBodyFile]);\n if (direct.status === 0) {\n process.stdout.write(direct.output);\n return new MergeOutcome(true, false, `squash-merged the PR as: \"${subject}\"`, MERGE_RESULT_MERGED);\n }\n\n // Past here the PR is not mergeable yet. WHY matters enormously and gh's exit status does not\n // say: checks-still-running (BLOCKED) is self-healing once auto-merge is on, while out-of-date\n // (BEHIND) can NEVER land unattended. Ask GitHub itself — one cheap, failure-tolerant call, made\n // only on the failure path, so a run whose direct merge succeeded costs no extra API call.\n const state = this.prMergeState(baseBranch);\n this.announceDirectFailure(direct.output, state);\n return this.fallBackToAutoMerge(baseBranch, subject, mergeBodyFile, state, intent);\n }\n\n /**\n * The auto-merge queue: the only way to still land a not-yet-mergeable PR unattended. Returns the\n * BEHIND outcome regardless of how queuing went whenever GitHub says the branch is out of date —\n * queuing a BEHIND PR is not an error (a repo that auto-updates branches will still land it), but it\n * is NOT success either, and reporting it as such is precisely the bug this whole file guards.\n */\n // eslint-disable-next-line @typescript-eslint/max-params\n private fallBackToAutoMerge(baseBranch: string, subject: string, mergeBodyFile: string, state: PrMergeState, intent: MergeIntent): MergeOutcome {\n if (!this.autoMergeAllowed()) {\n if (state.isBehind()) return this.behindOutcome(state, false);\n return new MergeOutcome(false, false, this.noQueueMessage(intent), MERGE_RESULT_FAILED);\n }\n\n process.stdout.write(' … retrying with --auto (the auto-merge queue)\\n');\n // gh records the merge subject/body only at the moment auto-merge is FIRST enabled; a second\n // `--auto` on an already-enabled PR silently keeps the OLD body. Disabling first re-stamps the\n // current subject/body on every re-run (a harmless no-op when auto-merge is not enabled).\n this.gh(['pr', 'merge', baseBranch, '--disable-auto'], true);\n const auto = this.gh(['pr', 'merge', baseBranch, '--auto', '--squash', '--subject', subject, '--body-file', mergeBodyFile]);\n if (auto !== 0) {\n if (state.isBehind()) return this.behindOutcome(state, false);\n return new MergeOutcome(false, false,\n '⚠️ did NOT merge and could NOT enable auto-merge either (see the gh error above) —\\n' +\n ' NOTHING is queued. Re-run once the PR is healthy.',\n MERGE_RESULT_FAILED);\n }\n if (state.isBehind()) return this.behindOutcome(state, true);\n return new MergeOutcome(false, true,\n `enabled auto-merge — it will squash-merge as \"${subject}\" when the checks pass`,\n MERGE_RESULT_AUTO_QUEUED);\n }\n\n /**\n * \"Not mergeable yet, and this repo has no queue to park it in\" — in the words that are TRUE for the\n * caller we actually have.\n *\n * A COMMANDED run (`wp-land-pr`) is not a misconfiguration at all: nobody set mergeMode to AUTO, the\n * user asked for a merge by hand, and the checks simply are not green yet. Telling that reader to\n * \"set mergeMode to NONE\" named a value they had already set and sent them investigating a mismatch\n * that did not exist. Nothing is owed here but a re-run.\n *\n * A POLICY-driven run (`wp-finish-upsert-pr`) only reaches here with a config that really does say\n * AUTO on a repo that forbids the queue — the genuine mismatch, where both remedies are real.\n */\n private noQueueMessage(intent: MergeIntent): string {\n if (intent.commanded) {\n return '⚠️ did NOT merge, and queued NOTHING — the PR is not mergeable yet (checks still\\n' +\n ' running, or a required review outstanding), and this repo has allow_auto_merge=false,\\n' +\n ' so there was no queue to fall back to. NOTHING is misconfigured and nothing needs\\n' +\n ' changing — re-run `pnpm wp-land-pr` once the PR is green and it will land.';\n }\n return '⚠️ did NOT merge, and queued NOTHING — CONFIG MISMATCH: pr-gate.mergeMode is AUTO, but\\n' +\n ' this repo has allow_auto_merge=false, so there is no queue to fall back to and the\\n' +\n ' PR is not mergeable yet. `gh pr merge --auto` cannot override a repo that says no.\\n' +\n ' Fix it at ONE of the two ends: turn on \"Allow auto-merge\" in the repo settings, or\\n' +\n ' set commands.pr-gate.mergeMode to \"NONE\" (and set that repo\\'s\\n' +\n ' squash_merge_commit_title to PR_TITLE so a human merge still gets a real subject).';\n }\n\n /**\n * The one outcome that looks queued but is stranded. `queued` says whether auto-merge did get enabled,\n * because \"parked forever\" and \"not queued at all\" need different sentences — but neither is done.\n *\n * The `result` now carries WHICH kind of behind, so the banner can stop describing a queue collision\n * in the vocabulary of a merge conflict. The wording here is deliberately blame-free: nothing the\n * author did caused this, and the PR itself is in perfectly good shape — pushed, bodied, gate-green.\n */\n private behindOutcome(state: PrMergeState, queued: boolean): MergeOutcome {\n const parked = queued ? 'Auto-merge is enabled but parked.' : 'Nothing is queued.';\n return new MergeOutcome(false, queued,\n `did NOT merge — someone else landed on main first, so GitHub wants this branch rebuilt on\\n` +\n ` top of theirs before it will merge (${state.describe()}).\\n` +\n ` This does NOT self-heal: auto-merge never updates your branch. ${parked}`,\n state.behindKind());\n }\n\n // Reprint the expected first-attempt failure as CONTEXT, not as a verdict. gh's own `X …` line is\n // captured (never inherited) so this framing is the only thing on screen.\n private announceDirectFailure(ghOutput: string, state: PrMergeState): void {\n const reason = ghOutput.trim().split('\\n').filter((l: string): boolean => l.trim() !== '').pop() ?? '';\n process.stdout.write(\n 'ℹ️ the direct squash-merge did not go through (expected while checks run, or when repo\\n' +\n ' policy forbids direct merges):\\n' +\n (reason === '' ? '' : ` ${reason}\\n`) +\n (state.describe() === '' ? '' : ` GitHub says: ${state.describe()}\\n`),\n );\n }\n\n /**\n * GitHub's own verdict on the PR. AUTHORITATIVE for the BEHIND check — the alternative is\n * pattern-matching gh's English error prose, which changes between releases. Failure-tolerant on\n * purpose: a gh hiccup returns an all-'' state (never BEHIND) so a transient API blip can only cost\n * us the extra diagnosis, never turn a working run into a crash.\n */\n protected prMergeState(baseBranch: string): PrMergeState {\n const result = spawnSync(\n 'gh',\n ['pr', 'view', baseBranch, '--json', 'mergeable,mergeStateStatus,state',\n '--jq', '\"\\\\(.mergeable)\\\\t\\\\(.mergeStateStatus)\\\\t\\\\(.state)\"'],\n { encoding: 'utf8' },\n );\n if (result.status !== 0) return new PrMergeState('', '', '');\n const parts = (result.stdout ?? '').trim().split('\\t');\n return new PrMergeState(parts[0] ?? '', parts[1] ?? '', parts[2] ?? '');\n }\n\n // Whether `gh pr merge --auto` is even possible on this repo. Many orgs set allow_auto_merge=false\n // as a policy control, where `--auto` can only ever fail with `GraphQL: Auto merge is not allowed\n // for this repository`. One API call beats discovering that from an error string. Anything other\n // than a clean `true` counts as NOT allowed: if the setting cannot be read we must not claim the\n // queue is available.\n protected autoMergeAllowed(): boolean {\n const result = spawnSync('gh', ['api', 'repos/{owner}/{repo}', '--jq', '.allow_auto_merge'], { encoding: 'utf8' });\n return result.status === 0 && (result.stdout ?? '').trim() === 'true';\n }\n\n // Runs `gh`, returning its exit status (-1 when gh could not be spawned at all, which must NOT be\n // mistaken for the 0 that means success).\n protected gh(args: string[], quiet: boolean = false): number {\n const result = spawnSync('gh', args, { stdio: quiet ? 'ignore' : 'inherit' });\n return result.status ?? -1;\n }\n\n // Runs `gh` CAPTURING both streams instead of inheriting them, so an expected-to-fail attempt can be\n // reported in our own words rather than dumping a raw `X …` line the reader reads as fatal.\n protected ghCapture(args: string[]): GhResult {\n const result = spawnSync('gh', args, { encoding: 'utf8' });\n return new GhResult(result.status ?? -1, (result.stdout ?? '') + (result.stderr ?? ''));\n }\n}\n\n// A captured `gh` invocation: its exit status (-1 when gh could not be spawned) and both streams\n// combined, in the order a terminal would have shown them.\nexport class GhResult {\n status: number;\n output: string;\n\n constructor(status: number, output: string) {\n this.status = status;\n this.output = output;\n }\n}\n"]}