@feigi/fleet-ctl 3.29.8 → 3.30.1

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.
@@ -61,11 +61,29 @@ gh api "repos/{owner}/{repo}/issues/<pr>/timeline?per_page=100" --paginate \
61
61
  | .event + " " + (.sha // .label.name // "")'
62
62
  ```
63
63
 
64
- A `committed` or `head_ref_force_pushed` line after the last `labeled ready-to-merge` means the head moved after the audit. **Refuse: report `head-moved-after-label-#<pr>` and stop on that PR.** Leave the label where it is — you audited nothing and removing another member's verdict is not yours to do. What clears it is a **fresh** finisher against the new head; the first audit does not transfer, because it verified a different tree.
64
+ A `committed` or `head_ref_force_pushed` line after the last `labeled ready-to-merge` means the head moved after the audit. **With no `head_ref_force_pushed` among those lines, refuse:** report `head-moved-after-label-#<pr>` and stop on that PR — without a force-push the timeline names no head the label was applied to, so no carry can be proven. Leave the label where it is — you audited nothing and removing another member's verdict is not yours to do. What clears it is a **fresh** finisher against the new head; the first audit does not transfer, because it verified a different tree.
65
65
 
66
- **Nothing after that label line is the normal case, and it proceeds untouched** — label applied, head unchanged, merge goes ahead exactly as it did before this gate existed. Record the head before you rebase — `gh pr view <pr> --json headRefOid -q .headRefOid` — because step 3 hands it to the merge gate as `--pre` and nothing later can reconstruct it. Where step 1 runs, that is its `pre`; on an already-current PR it is simply the head you merge.
66
+ **A `head_ref_force_pushed` after the label is not refused on sight — it may be a rebase-carry, and the merge gate decides.** The label binds to the change the finisher audited, not to one SHA: a rewrite that leaves the PR's net change byte-identical — a conflict-free rebase onto a newer `main` — keeps it. The REST line names only the head the force-push produced; the head it replaced is GraphQL's `beforeCommit`:
67
67
 
68
- What this gate deliberately does not answer. It does not ask *who* audited — a hand-added `ready-to-merge` with no finisher behind it reads clean here, and the reviewer-only rule in `run-team/SKILL.md` is what owns that. And a head rebased after the label by an **earlier, abandoned pass of this command** refuses too: that tree is one no finisher audited either, so the halt is correct rather than a false positive.
68
+ ```bash
69
+ gh api graphql -F owner='{owner}' -F repo='{repo}' -F pr=<pr> -f query='
70
+ query($owner: String!, $repo: String!, $pr: Int!) {
71
+ repository(owner: $owner, name: $repo) { pullRequest(number: $pr) {
72
+ timelineItems(last: 100, itemTypes: [LABELED_EVENT, HEAD_REF_FORCE_PUSHED_EVENT]) { nodes {
73
+ __typename
74
+ ... on LabeledEvent { createdAt label { name } }
75
+ ... on HeadRefForcePushedEvent { createdAt beforeCommit { oid } } } } } } }' \
76
+ -q '.data.repository.pullRequest.timelineItems.nodes[]
77
+ | select(.__typename == "HeadRefForcePushedEvent" or .label.name == "ready-to-merge")
78
+ | "\(.createdAt | fromdateiso8601) " + (if .__typename == "LabeledEvent" then "labeled"
79
+ else "force-pushed \(.beforeCommit.oid // "unknown")" end)'
80
+ ```
81
+
82
+ **The labelled head is the `beforeCommit` of the first `force-pushed` line after the last `labeled` line** — unless a plain push landed between the label and that force-push, which leaves no line at all once the force-push orphans it. So, in the main checkout after a plain `git fetch origin`, read `git log --format='%ct %H' origin/main..<labelled head>`: a commit whose first field is later than the label's (the number on its `labeled` line), a non-zero exit (the object is not here), or `unknown` in place of the SHA → refuse as above. Otherwise run step 3's gate now, before step 1, with `--pre <labelled head>` and no `--post`. **`rebaseCarry` null → refuse as above.** Non-null → the current head carries the labelled head's change: `--pre` stays the labelled head on every later gate run, step 1's `pre` must read `rebaseCarry.accepted` (any other head is a push since the proof — refuse as above), and your report names the carry as `rebase-carry-#<pr>` with both SHAs.
83
+
84
+ **Nothing after that label line is the normal case, and it proceeds untouched** — label applied, head unchanged, merge goes ahead exactly as it did before this gate existed. Record the head before you rebase — `gh pr view <pr> --json headRefOid -q .headRefOid` — because step 3 hands it to the merge gate as `--pre` and nothing later can reconstruct it. Where step 1 runs, that is its `pre`; on an already-current PR it is simply the head you merge. After a force-push, `--pre` is the labelled head derived above instead.
85
+
86
+ What this gate deliberately does not answer. It does not ask *who* audited — a hand-added `ready-to-merge` with no finisher behind it reads clean here, and the reviewer-only rule in `run-team/SKILL.md` is what owns that — nor who force-pushed. A head rebased after the label by an **earlier, abandoned pass of this command** is judged like any other force-push: carried when its net change is the labelled head's, refused when it is not.
69
87
 
70
88
  ## Per-PR sequence
71
89
 
@@ -212,16 +230,16 @@ For each labeled PR clearing the hold rule, lowest first:
212
230
  --out <scratch>/pr<N>/merge-bot-<n>/ci.json; rc=$?
213
231
  ```
214
232
 
215
- `--pre` is the head you recorded at **The labelled head**; `--post` is the head step 1's rebase produced — omit it when no rebase ran, which is the same as passing `pre` twice. `pr<N>` is this PR and `merge-bot-<n>` is your own name, so the reading lands under a directory only you write, never in the scratch root by itself: that root is injected into every dispatched member and shared with every sibling. The gate is read-only — it runs the instrument re-check, `gh pr view <pr> --json labels,reviewDecision,headRefOid,body`, the main-gain check against that head in the main checkout, and `ci-state.mjs --pr <pr>`, answers their conjunction, and never merges, labels, rebases or waits. Stdout is exactly one JSON line, `{pr, verdict, reason, head, pre, post, behind, instruments, mainGain, ci}`; stderr is its children's diagnostics, so never fold `2>&1` into the line you read. Read `rc` straight off the call, as above — never through a pipe.
233
+ `--pre` is the head you recorded at **The labelled head**; `--post` is the head step 1's rebase produced — omit it when no rebase ran, which is the same as passing `pre` twice. `pr<N>` is this PR and `merge-bot-<n>` is your own name, so the reading lands under a directory only you write, never in the scratch root by itself: that root is injected into every dispatched member and shared with every sibling. The gate is read-only — it runs the instrument re-check, `gh pr view <pr> --json labels,reviewDecision,headRefOid,body`, the main-gain check against that head in the main checkout, the rebase-carry proof when that head is neither `pre` nor `post`, and `ci-state.mjs --pr <pr>`, answers their conjunction, and never merges, labels, rebases or waits. Stdout is exactly one JSON line, `{pr, verdict, reason, head, pre, post, rebaseCarry, behind, instruments, mainGain, ci}`; stderr is its children's diagnostics, so never fold `2>&1` into the line you read. Read `rc` straight off the call, as above — never through a pipe.
216
234
 
217
- **Run a plain `git fetch origin` in the main checkout before every gate run** — never `git fetch origin <src>:<dst>`, for the reason step 1's fallback gives. The main-gain check reads `origin/main` and the PR head object there as they stand and fetches nothing itself: an unfetched head is `main-gain-unanswerable`, and a stale `origin/main` is a check against the wrong `main`.
235
+ **Run a plain `git fetch origin` in the main checkout before every gate run** — never `git fetch origin <src>:<dst>`, for the reason step 1's fallback gives. The main-gain check and the rebase-carry proof read `origin/main` and the head objects there as they stand and fetch nothing themselves: an unfetched head is `main-gain-unanswerable`, an unheld labelled or carried head is no carry, and a stale `origin/main` is a check against the wrong `main`.
218
236
 
219
237
  1. **Run it.** Exit 0 → go to 2. Exit 1 with a `ci:…` `reason`, `ci.runId` set and `ci.status` not `completed` → the run has started but not finished: wait on `ci.runId` (step 2), then run it again. Exit 1 with `ci.runId` **null** (`reason` starts `no CI run whose headSha equals`) → GitHub has not yet registered a run for this head at all — right after `gh pr update-branch --rebase`, the id step 2's wait blocks on does not exist yet, so never route this into step 2's `gh run view <run-id>` poll with a null id. Wait 15s and run the gate again instead, capped at 20 attempts (~5 minutes); no run within that cap → skip the PR and report `<reason>-#<pr>`, the same as any other exit 1. Any other exit 1 → skip the PR, report `<reason>-#<pr>` (`head-moved-after-label-#<pr>`, `label-pulled-#<pr>`, `changes-requested-#<pr>` …), leave the label where it is, and move on. Exit 2 → stop on that PR and report `<reason>-#<pr>`: the gate could not evaluate — a finding about the tree, the tooling or the API, never about the PR. Re-run once only for `rate-limited`, a quota refusal that clears by itself.
220
238
  2. **Run it again immediately before `gh pr merge`, and merge only on that second exit 0.** Anything else takes the same arms as 1, and nothing merges.
221
239
 
222
240
  Each `reason` is a fact the gate now enforces, not a step you run:
223
241
 
224
- - **`head-moved-after-label`** — the PR head is neither `pre` nor `post`. **Any third SHA is a push that landed while you waited on CI, and no CI check can see it**: `ci-state.mjs` selects the run whose `headSha` equals the *current* PR head (`scripts/ci-state.mjs`, the `r.headSha === prHead` filter), so a member's push plus its own green run satisfies every CI check while the audit behind the label belongs to a tree that is gone. The remedy is a fresh finisher against the new head, label untouched.
242
+ - **`head-moved-after-label`** — the PR head is neither `pre` nor `post`, nor a head whose net change the gate proved identical to `pre`'s (`rebaseCarry`, which names both). **Any third SHA is a push that landed while you waited on CI, and no CI check can see it**: `ci-state.mjs` selects the run whose `headSha` equals the *current* PR head (`scripts/ci-state.mjs`, the `r.headSha === prHead` filter), so a member's push plus its own green run satisfies every CI check while the audit behind the label belongs to a tree that is gone. A carry is proven only for the head `gh pr view` read; a different head at `ci-state`'s own read is still this row. The remedy is a fresh finisher against the new head, label untouched.
225
243
  - **`main-gain-removed:<path>`** — merging this head would remove lines `main` gained after the PR's work began: lines a later merge landed, deleted by a branch commit that every rebase since has replayed without a conflict, so no conflict preview and no `origin/main...HEAD` read is sure to show them. `mainGain.hits[]` names each file, the landing key (`#<n>` for a merged PR, else the landing commit's 12-character SHA), the removed lines, and the `ack` line to copy. Skip the PR, leave the label alone, and report `main-gain-removed:<path>-#<pr>` with the hit list and the keys. Never restore the lines yourself — the removal may be deliberate. It clears when the PR stops removing them or its body carries `main-gain-removal: <path> <key> - <why>` for every hit; the gate reads the body each run, so editing it is enough. An acknowledged removal is listed in `mainGain.acknowledged[]` and the gate passes it — name each one, with its reason, in your report.
226
244
  - **`main-gain-unanswerable`** — the main-gain check could not answer: a head object the main checkout does not hold after `git fetch origin`, a merge that does not resolve cleanly, a blame that failed. `mainGain.reason` says which. Stop and report `main-gain-unanswerable-#<pr>` with it, label untouched.
227
245
  - **`behind:<n>`** — you are the only place currency is proven, and a sibling merge since your rebase expires it (the staleness below).
@@ -268,7 +286,7 @@ Measured over one three-merge pass: the next queue member went 0 → 2 → 7 →
268
286
 
269
287
  **A PR whose heavy jobs have only ever `skipped` is getting its first real verification from your rebase.** Reviewers may legitimately have labelled on the checks that did run plus local evidence, saying so explicitly. When your post-rebase run finally executes those suites, treat a red there as a **genuine first result**, not a regression you caused — read the failing job before concluding, and do not hand it back as "the rebase broke it".
270
288
 
271
- Report merged / skipped-unlabeled / held-behind-#X / worktree-diverged-#X / head-moved-after-label-#X / main-gain-removed:<path>-#X / label-drop-failed-#X / label-read-failed-#X / branch-delete-failed-#X / branch-kept-#X (X the open PR that keeps the merged branch — a keep, not a failure) / rebase-fallback-#X / instrument-set-changed-#X / `<reason>-#X` for any other gate refusal / blocked after the pass — a dispatched bot once, at exit, after its grace (**Grace, then one report**, below). Every acknowledged main-gain removal the gate passed is named in the report, with its reason.
289
+ Report merged / skipped-unlabeled / held-behind-#X / worktree-diverged-#X / head-moved-after-label-#X / rebase-carry-#X (merged or not, with the labelled and accepted SHAs) / main-gain-removed:<path>-#X / label-drop-failed-#X / label-read-failed-#X / branch-delete-failed-#X / branch-kept-#X (X the open PR that keeps the merged branch — a keep, not a failure) / rebase-fallback-#X / instrument-set-changed-#X / `<reason>-#X` for any other gate refusal / blocked after the pass — a dispatched bot once, at exit, after its grace (**Grace, then one report**, below). Every acknowledged main-gain removal the gate passed is named in the report, with its reason.
272
290
 
273
291
  ## No-undo audit (before every rebase)
274
292
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@feigi/fleet-ctl",
3
- "version": "3.29.8",
3
+ "version": "3.30.1",
4
4
  "description": "Agent fleet: run-team controller, merge bot, PR reviewer, and the ticket pipeline they share",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -9,9 +9,11 @@
9
9
  // then answers the conjunction. All four run on every call, whatever the
10
10
  // earlier ones said — except main-gain.mjs, which needs the head and body gh
11
11
  // read and the main checkout, and is skipped when either could not be had — so
12
- // the JSON line carries every field that was read. It never merges, labels,
13
- // rebases or waits: the merge bot runs it once before any wait and once
14
- // immediately before `gh pr merge`, and merges only on that second exit 0.
12
+ // the JSON line carries every field that was read. A head gh reads outside
13
+ // {pre, post} adds one more read, the rebase-carry proof below, in the main
14
+ // checkout. It never merges, labels, rebases or waits: the merge bot runs it
15
+ // once before any wait and once immediately before `gh pr merge`, and merges
16
+ // only on that second exit 0.
15
17
  //
16
18
  // `--pre` is the labelled head, `--post` the head the bot's own
17
19
  // `gh pr update-branch --rebase` produced; omitted, it is `--pre` (the
@@ -22,7 +24,9 @@
22
24
  // guesses it.
23
25
  //
24
26
  // Stdout: exactly one JSON line, `{pr, verdict, reason, head, pre, post,
25
- // behind, instruments, mainGain, ci}`, `mainGain` echoing main-gain.mjs's own
27
+ // rebaseCarry, behind, instruments, mainGain, ci}`, `rebaseCarry` naming the
28
+ // labelled head and the head accepted as carrying it (`{labelled, accepted}`),
29
+ // or null when no carry was proven, `mainGain` echoing main-gain.mjs's own
26
30
  // payload — hits, acknowledged removals and unchecked files — or null when
27
31
  // it did not run or printed no JSON object; an unusable payload is still
28
32
  // echoed. Stderr: the children's own diagnostics, passed straight through
@@ -43,7 +47,8 @@
43
47
  //
44
48
  // label `ready-to-merge` absent 1 label-pulled
45
49
  // reviewDecision CHANGES_REQUESTED 1 changes-requested
46
- // PR head not in {pre, post} 1 head-moved-after-label
50
+ // PR head not in {pre, post} and not a 1 head-moved-after-label
51
+ // proven rebase-carry of pre
47
52
  // main-gain.mjs exit 1 1 main-gain-removed:<first path>
48
53
  // ci-state exit 1 (not-green) 1 ci:<first entry of ci.reasons>
49
54
  // ci.behind > 0 1 behind:<n>
@@ -63,6 +68,13 @@
63
68
  //
64
69
  // An instrument change is 2, not 1: a changed instrument says nothing about
65
70
  // the PR, and the response is stop-and-report like every other 2.
71
+ //
72
+ // A rebase-carry is a head outside {pre, post} whose net change is the
73
+ // labelled head's and whose tree is exactly that change merged onto the moved
74
+ // head's own base: the label binds to the change it audited, not to one SHA,
75
+ // so a conflict-free rebase keeps it. Anything the proof cannot establish —
76
+ // a missing object, an unresolvable base, a git failure, a merge conflict — is
77
+ // no carry, and the head row blocks exactly as it does for any other moved head.
66
78
 
67
79
  import { spawnSync } from "node:child_process";
68
80
  import { mkdirSync, writeFileSync } from "node:fs";
@@ -112,6 +124,89 @@ const pre = sha("pre", preArg);
112
124
  const post = postArg === null ? null : sha("post", postArg);
113
125
  const heads = new Set([pre, post ?? pre]);
114
126
 
127
+ // --- rebase-carry proof ----------------------------------------------------
128
+ // Same net change: `git diff-tree` of each head against its own merge base
129
+ // with `origin/main`, in the main checkout, compared byte for byte after
130
+ // dropping only what a conflict-free rebase moves without changing the
131
+ // change — the line numbers and function context of each hunk header, and a
132
+ // text file's pre/post blob ids (the file around the hunks moved with
133
+ // `main`). Kept: every added, removed and context line, every mode, new-file,
134
+ // deleted-file and `\ No newline` line, symlink targets and submodule
135
+ // pointers (both are content lines), and a binary file's whole block, whose
136
+ // `index` line carries both full blob ids: its patch can be a delta against
137
+ // the other side, and two different pairs of blobs can share one delta in
138
+ // both directions. `--no-renames` turns a rename into the deletion and
139
+ // addition it is, so no similarity score decides anything.
140
+ //
141
+ // Not `git patch-id`: it drops whitespace. Measured with git 2.50.1, two
142
+ // branches adding `new` and ` new` to the same file gave one
143
+ // `patch-id --stable`, so an indentation change would read as a carry.
144
+ //
145
+ // latin1 decodes every byte to its own code unit, so two different invalid
146
+ // UTF-8 sequences can never decode to the same replacement character and
147
+ // compare equal.
148
+ //
149
+ // The text comparison alone cannot place a hunk: its header's line numbers and
150
+ // function context are dropped, so the same edit made somewhere else in the
151
+ // file reads as the same change. It is therefore the first of two proofs, and
152
+ // the second is the exact one: a three-way merge of the labelled head into the
153
+ // moved head's own merge base, with the labelled head's merge base as the
154
+ // common ancestor, must produce the moved head's tree. A clean rebase is
155
+ // precisely that merge; an edit relocated, added or dropped anywhere else
156
+ // yields a different tree, and a merge that conflicts yields none.
157
+ //
158
+ // Read-only: cat-file, merge-base, diff-tree and rev-parse write nothing,
159
+ // and merge-tree writes no ref, index or worktree — only the unreachable tree
160
+ // and blob objects of the merge it computes, as main-gain.mjs's does.
161
+ const GIT = gitEnv({ LC_ALL: "C" });
162
+
163
+ function gitRead(root, args) {
164
+ const r = spawnSync("git", args, { cwd: root, encoding: "latin1", env: GIT, stdio: ["ignore", "pipe", "inherit"], maxBuffer: 1 << 30 });
165
+ return r.error || r.signal || r.status !== 0 ? null : r.stdout;
166
+ }
167
+
168
+ function netChange(root, head) {
169
+ if (gitRead(root, ["cat-file", "-e", `${head}^{commit}`]) === null) return null;
170
+ const bases = gitRead(root, ["merge-base", "--all", "origin/main", head]);
171
+ const base = bases === null ? [] : bases.split("\n").filter(Boolean);
172
+ if (base.length !== 1) return null;
173
+ const diff = gitRead(root, [
174
+ "diff-tree", "-r", "-p", "--binary", "--full-index", "--no-renames", "--no-ext-diff", "--no-textconv",
175
+ "--no-color", "-U3", "--src-prefix=a/", "--dst-prefix=b/", base[0], head,
176
+ ]);
177
+ if (diff === null || diff === "") return null;
178
+ // One block per file, each starting at its `diff --git` line. No content
179
+ // line can start that way — every one carries a ` `, `+`, `-` or `\` prefix,
180
+ // and a binary patch line has no space in it.
181
+ const blocks = diff.split(/^(?=diff --git )/m);
182
+ const text = blocks
183
+ .map((block) => {
184
+ const lines = block.split("\n");
185
+ if (lines.includes("GIT binary patch")) return block;
186
+ return lines
187
+ .map((l) => {
188
+ const index = /^index [0-9a-f]+\.\.[0-9a-f]+((?: [0-7]+)?)$/.exec(l);
189
+ if (index) return `index${index[1]}`;
190
+ return /^@@ -\d+(?:,\d+)? \+\d+(?:,\d+)? @@/.test(l) ? "@@" : l;
191
+ })
192
+ .join("\n");
193
+ })
194
+ .join("");
195
+ return { base: base[0], text };
196
+ }
197
+
198
+ function proveCarry(root, prView) {
199
+ if (root === null || prView === null || heads.has(prView.headRefOid)) return null;
200
+ const labelled = netChange(root, pre);
201
+ if (labelled === null) return null;
202
+ const moved = netChange(root, prView.headRefOid);
203
+ if (moved === null || moved.text !== labelled.text) return null;
204
+ const merged = gitRead(root, ["merge-tree", "--write-tree", `--merge-base=${labelled.base}`, moved.base, pre]);
205
+ const tree = gitRead(root, ["rev-parse", "--verify", `${prView.headRefOid}^{tree}`]);
206
+ if (merged === null || tree === null || merged.split("\n")[0] !== tree.trim()) return null;
207
+ return { labelled: pre, accepted: prView.headRefOid };
208
+ }
209
+
115
210
  const isObject = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
116
211
 
117
212
  // Children's stdout is captured for parsing; their stderr goes straight to
@@ -248,20 +343,23 @@ function readCi() {
248
343
  }
249
344
 
250
345
  // --- the conjunction ------------------------------------------------------
251
- function decide(instruments, prView, mainGain, ciRead) {
346
+ function decide(instruments, prView, mainGain, ciRead, rebaseCarry) {
252
347
  const blocked = (reason) => ({ verdict: "blocked", reason });
253
348
  const unknown = (reason) => ({ verdict: "unknown", reason });
254
349
  const { validated, usable } = ciRead;
350
+ // The carried head joins the accepted set; nothing else does. A third head
351
+ // at ci-state's read is still not one of them.
352
+ const accepted = rebaseCarry === null ? heads : new Set([...heads, rebaseCarry.accepted]);
255
353
  if (prView !== null) {
256
354
  if (!prView.labels.some((l) => l.name === "ready-to-merge")) return blocked("label-pulled");
257
355
  if (prView.reviewDecision === "CHANGES_REQUESTED") return blocked("changes-requested");
258
- if (!heads.has(prView.headRefOid)) return blocked("head-moved-after-label");
356
+ if (!accepted.has(prView.headRefOid)) return blocked("head-moved-after-label");
259
357
  }
260
358
  // ci-state reads the head a second time, a few seconds after gh pr view
261
359
  // above, and binds its run to THAT read. A push in between would have its
262
360
  // own CI judged here while the label's audit belongs to the tree before it,
263
361
  // so the same row applies to ci-state's reading too.
264
- if (usable && !heads.has(validated.prHead)) return blocked("head-moved-after-label");
362
+ if (usable && !accepted.has(validated.prHead)) return blocked("head-moved-after-label");
265
363
  if (mainGain.usable && mainGain.exit === 1) return blocked(`main-gain-removed:${mainGain.payload.hits[0].path}`);
266
364
  if (usable && ciRead.notGreen) return blocked(`ci:${validated.reasons[0]}`);
267
365
  if (usable && validated.behind > 0) return blocked(`behind:${validated.behind}`);
@@ -283,8 +381,9 @@ try {
283
381
  const instruments = readInstruments();
284
382
  const prView = readPr();
285
383
  const mainGain = readMainGain(instruments.root, prView);
384
+ const rebaseCarry = proveCarry(instruments.root, prView);
286
385
  const ciRead = readCi();
287
- const { verdict, reason } = decide(instruments, prView, mainGain, ciRead);
386
+ const { verdict, reason } = decide(instruments, prView, mainGain, ciRead, rebaseCarry);
288
387
  const line = `${JSON.stringify({
289
388
  pr,
290
389
  verdict,
@@ -292,6 +391,7 @@ try {
292
391
  head: prView?.headRefOid ?? null,
293
392
  pre,
294
393
  post,
394
+ rebaseCarry,
295
395
  behind: ciRead.usable ? ciRead.ci.behind : null,
296
396
  instruments: instruments.digest,
297
397
  mainGain: mainGain.payload,
package/scripts/reap.sh CHANGED
@@ -312,22 +312,18 @@ removed=""
312
312
  # a substitution that failed would contribute an empty string and splice
313
313
  # `{"branch":,…}` — malformed JSON — with nothing to notice it.
314
314
  #
315
- # Five interpolations converge on this function: the branch name, `dirty
316
- # worktree $wt`, `ignored files present in $wt: $ignored`, `cherry probe
317
- # failed …: $cherry` (arbitrary git stderr) — the first four via `keep`, whose
318
- # own `jfield "$1"` / `jfield "$2"` every `keep` call carrying one of them
319
- # reaches — and the `reaped` accumulator, which calls `jfield`
320
- # directly and never routes through `keep` at all. The branch name is the
321
- # demonstrated trigger — `git branch 'has"quote'` is a legal refname — and raw
322
- # it emitted a payload no parser accepts at exit 0, while the branch was
323
- # correctly kept. The stderr lines stay raw: they are prose for an
324
- # operator, not JSON.
325
- #
326
- # A sixth joined the five above later: grep's own stderr, `$gq_err`,
327
- # surfaced through `gp_why "$gq_err"` in `keep`'s message at the cherry
328
- # checks and the registry re-reads —
329
- # arbitrary text on the same footing as `$cherry`, routed through the same
330
- # jfield/jstr escaping the paragraph above already covers.
315
+ # Arbitrary text reaches this function by many routes, and what follows names
316
+ # the kinds of it, not every caller: branch names; worktree paths; git's own
317
+ # stderr, surfaced through `gp_why` with no argument, which reads `$gp_err`;
318
+ # grep's own stderr, through `gp_why "$gq_err"`; the error text of `git
319
+ # worktree remove`, `git update-ref` and `git config --remove-section`; and
320
+ # scan output such as `$cherry` and the `$ignored` listing. Most of it arrives
321
+ # inside a `keep` message, through `keep`'s own `jfield "$1"` / `jfield "$2"`;
322
+ # the `reaped`, `removed` and `warnings` accumulators call `jfield` directly
323
+ # and never route through `keep` at all. The branch name is the demonstrated
324
+ # trigger — `git branch 'has"quote'` is a legal refname — and raw it emitted a
325
+ # payload no parser accepts at exit 0, while the branch was correctly kept.
326
+ # The stderr lines stay raw: they are prose for an operator, not JSON.
331
327
  jfield() {
332
328
  if jf=$(jstr "$1"); then
333
329
  printf '"%s"' "$jf"
@@ -3595,7 +3595,7 @@ Plan it as a PR the run's own merge queue lands, never as an edit-and-continue.
3595
3595
  | Reviewer or fix-applier cannot reach green | Report, leave the PR unlabeled, free the slot |
3596
3596
  | Merge bot hits the hold rule | Report `held-behind-#<lower>`, PR stays queued |
3597
3597
  | Merge bot finds the worktree ahead of the PR head **on the local-rebase fallback** | `worktree-diverged-#<pr>`, PR stays queued. Read the stray commit; push-or-discard is yours, and the maintainer's if the evidence cannot settle it |
3598
- | Merge bot finds the head moved after `ready-to-merge` was applied | `head-moved-after-label-#<pr>`, PR stays queued, label untouched. Dispatch a **fresh** finisher against the new head — the first audit verified a different tree |
3598
+ | Merge bot finds the head moved after `ready-to-merge` was applied | The label binds to the head's net change, not to one SHA: a proven rebase-carry keeps the label — the bot proceeds and reports `rebase-carry-#<pr>` with the labelled and accepted SHAs, and nothing is dispatched. Any other move is `head-moved-after-label-#<pr>`, PR stays queued, label untouched. Dispatch a **fresh** finisher against the new head — the first audit verified a different tree |
3599
3599
  | Merge bot's gate finds the merge would remove lines `main` gained after the PR's work began (`main-gain-removed:<path>`, exit 1) | Relay `main-gain-removed:<path>-#<pr>` to a human with the hit list and the acknowledgement keys the bot printed. PR stays queued, label untouched, nothing written to the ledger, and no member is dispatched to restore the lines — the removal may be deliberate. It clears when the PR stops removing them or its body carries `main-gain-removal: <path> <key> - <why>` for each hit |
3600
3600
  | Merge bot's gate cannot answer the main-gain check (`main-gain-unanswerable`, exit 2) | Report `main-gain-unanswerable-#<pr>` with what it printed, PR stays queued, label untouched |
3601
3601
  | Merge bot cannot resolve a rebase safely | Stop that PR, report, continue. On a conflict the bot has already appended `conflict-hold:#<pr>` to the PR's row; the tick prints `DISPATCH fix-pr PR#<pr>` and holds the merge until that fix-applier settles |