@feigi/fleet-ctl 3.23.45 → 3.24.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.
@@ -242,15 +242,7 @@ For each labeled PR clearing the hold rule, lowest first:
242
242
 
243
243
  **A `rebase-fallback-#<pr>` merge is expected to disprove here.** Step 1's fallback never lands a rebased head on the remote, so `pre == post` and `headWasCurrent` reads false — `prove-merge.sh` exits **1**, correctly (`prove-merge.test.mjs`'s `ATTACK: un-rebased head that merged cleanly still proves false` pins exactly this shape). That is the honest answer, not a script fault. Report the merge as **argued** — backed by the fallback's four checks — and never as `proved`; a merge whose ancestry was not proved is never reported as proved.
244
244
 
245
- **Drop `in-progress` from every issue this PR closes** — the merge is the only point where the ticket number and the fact of completion are known together, and nothing else clears it:
246
-
247
- ```bash
248
- ~/.fleet/bin/fleet-run drop-merged-label.sh <pr> --apply
249
- ```
250
-
251
- Exit 0 done or nothing to close, **1 a removal failed — report it as `label-drop-failed-#<issue>`, never swallow it**: a merged ticket that keeps the label is invisible the moment it is reopened. Exit 2 means the PR was not actually MERGED yet — call this only after the merge is confirmed at the top of this step.
252
-
253
- **Delete the head branch from `origin`** — this bot owns that step, and no repo setting does it for you (#2196). Without it a merged branch is never `[gone]`, so `reap.sh` never reaps it or its worktree:
245
+ **Delete the head branch from `origin`** — this bot owns that step, and no repo setting does it for you. Without it a merged branch is never `[gone]`, so `reap.sh` never reaps it or its worktree. The same step also drops `in-progress` from every issue this PR closes: the merge is the only point where the ticket number and the fact of completion are known together, and nothing else clears it.
254
246
 
255
247
  ```bash
256
248
  ~/.fleet/bin/fleet-run delete-merged-branch.sh <pr>
@@ -258,7 +250,9 @@ For each labeled PR clearing the hold rule, lowest first:
258
250
 
259
251
  Exit 0 the branch is gone from `origin` — `deleted`, `alreadyGone` (a repo that still auto-deletes), or `skipped` for a fork PR, whose branch is not ours. **1 the branch is still on `origin` — report it as `branch-delete-failed-#<pr>`, never swallow it**: either a push landed on it after the merge (the delete is leased to the merged head, so it refuses rather than destroy commits `main` never received) or the push failed. The script reads the deletion back from `origin` rather than trusting the push's exit status. Exit 2 could not tell what to delete — the PR is not MERGED, a `gh` or `ls-remote` read failed, or the lookup for other open PRs on the branch failed (nothing is deleted then); call this only after the merge is confirmed at the top of this step. **Exit 3 the branch is kept on purpose — another open PR uses it as its head or its base** (#2295): deleting it would close the PRs headed by it, and may close rather than retarget the PRs based on it. Nothing was pushed. Its stdout is one `branch-kept-#<pr>` line per such PR, naming that open PR, not the merged one — report each line as printed. A deliberate keep, not a failure: never retry it, and never report it as `branch-delete-failed`. The branch stays on `origin`, so it is not `[gone]` and `reap.sh` leaves it and its worktree in place.
260
252
 
261
- It deletes the **remote** ref only, and that is why it exists instead of `gh pr merge --delete-branch`: that flag's local cleanup dies with `fatal: 'main' is already used by worktree at <path>` whenever the branch is checked out in a worktree — which every fleet-claimed branch is, at `.worktrees/<issue>-<slug>` — or strands the feature worktree on `main`, after the remote merge already succeeded. The local branch and its worktree are left `[gone]` for `reap.sh`, which removes the worktree before deleting the branch and keeps either when it holds anything unmerged.
253
+ **Exit 4 the branch half succeeded but the label half did not — report every token line the step printed on stdout, never swallow one.** `label-drop-failed-#<issue>` is one issue whose removal failed: a merged ticket that keeps the label is invisible the moment it is reopened. `label-read-failed-#<pr>` means what the PR closes could not be determined — never read it as "nothing to drop". When the branch half exits 1, 2 or 3 that code wins, and the same token lines are still printed ahead of the branch output. On any non-zero exit, report every token line; never retry.
254
+
255
+ The branch half deletes the **remote** ref only, and that is why it exists instead of `gh pr merge --delete-branch`: that flag's local cleanup dies with `fatal: 'main' is already used by worktree at <path>` whenever the branch is checked out in a worktree — which every fleet-claimed branch is, at `.worktrees/<issue>-<slug>` — or strands the feature worktree on `main`, after the remote merge already succeeded. The local branch and its worktree are left `[gone]` for `reap.sh`, which removes the worktree before deleting the branch and keeps either when it holds anything unmerged.
262
256
 
263
257
  Then re-fetch and **re-evaluate the queue from scratch** — labels and numbers move while CI runs, and a merge newly unblocks or blocks others.
264
258
 
@@ -268,7 +262,7 @@ Measured over one three-merge pass: the next queue member went 0 → 2 → 7 →
268
262
 
269
263
  **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
264
 
271
- Report merged / skipped-unlabeled / held-behind-#X / worktree-diverged-#X / head-moved-after-label-#X / label-drop-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).
265
+ Report merged / skipped-unlabeled / held-behind-#X / worktree-diverged-#X / head-moved-after-label-#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).
272
266
 
273
267
  ## No-undo audit (before every rebase)
274
268
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@feigi/fleet-ctl",
3
- "version": "3.23.45",
3
+ "version": "3.24.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": {
@@ -68,9 +68,7 @@ import { isCLI } from "./is-cli.mjs";
68
68
  import { CELL, POLICY_CELL } from "./ledger-grammar.mjs";
69
69
  import { formatTsv as formatMemberTsv, parseTsv as parseMemberTsv } from "./member-outcomes.mjs";
70
70
  import { parseFeatures } from "./pr-cost.mjs";
71
- import { VERDICT, VERDICT_COLUMNS } from "./tier-outcomes.mjs";
72
-
73
- const ISO_DATE = /^\d{4}-\d{2}-\d{2}$/;
71
+ import { rulingFor, rulingsByTicket } from "./tier-outcomes.mjs";
74
72
 
75
73
  const NAME = "cell-readout";
76
74
  export const GATE = Object.freeze({ comparisons: 10, runDates: 5 });
@@ -175,11 +173,7 @@ export function readout({ features, members }) {
175
173
  */
176
174
  export function stoppingRule({ features, members, verdicts, added }) {
177
175
  const byKey = indexMembers(members);
178
- const rulings = new Map();
179
- for (const v of verdicts) {
180
- if (VERDICT_COLUMNS.every((c) => v[c] === "")) continue;
181
- for (const t of String(v.ticket).split("+")) (rulings.get(t) ?? rulings.set(t, []).get(t)).push(v);
182
- }
176
+ const rulings = rulingsByTicket(verdicts);
183
177
  // Per cell, each ticket's last admissible Pull: the one its ruling must follow.
184
178
  const charged = new Map(Object.keys(added).filter((c) => c !== POLICY_CELL).map((c) => [c, new Map()]));
185
179
  for (const p of features) {
@@ -190,15 +184,8 @@ export function stoppingRule({ features, members, verdicts, added }) {
190
184
  return [...charged].sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)).map(([cell, pulls]) => {
191
185
  const list = [];
192
186
  for (const p of pulls.values()) {
193
- const own = rulings.get(p.ticket) ?? [];
194
- for (const r of own) {
195
- if (!ISO_DATE.test(r.run_date)) throw new Error(`ticket #${p.ticket} (PR #${r.pr}): run_date is '${r.run_date}', expected YYYY-MM-DD`);
196
- }
197
- const v = own.findLast((r) => r.run_date >= p.run_date);
187
+ const v = rulingFor(rulings, p.ticket, p.run_date);
198
188
  if (!v) continue;
199
- for (const c of VERDICT_COLUMNS) {
200
- if (!VERDICT.includes(v[c])) throw new Error(`ticket #${p.ticket} (PR #${v.pr}): ${c} is '${v[c]}', expected yes or no`);
201
- }
202
189
  list.push({
203
190
  ticket: p.ticket, pr: v.pr, run_date: v.run_date,
204
191
  closed_own_ticket: v.closed_own_ticket, minted_false_claim: v.minted_false_claim,
@@ -39,6 +39,21 @@
39
39
  # The lookups run only when there is a delete to guard — a branch already gone
40
40
  # has none, and is exit 0 whatever they would say.
41
41
  #
42
+ # THE LABEL HALF. The same step also drops `in-progress` from every issue the
43
+ # merged PR closes, by running its sibling `drop-merged-label.sh <pr> --apply`
44
+ # through `sh`, resolved beside this file. It runs right after the MERGED gate,
45
+ # before any branch-half validation, so every later exit already carries its
46
+ # outcome; a PR that is not MERGED is refused (exit 2) with no `issue edit`. A
47
+ # missing or unreadable sibling is exit 2 at startup, nothing touched. Its JSON
48
+ # line and stderr go to this script's stderr; stdout carries only these failure
49
+ # tokens, one per line, printed before the branch half's output:
50
+ # label-drop-failed-#<issue> one per issue whose removal failed
51
+ # label-read-failed-#<pr> the outcome could not be determined: the sibling
52
+ # exited 2, exited 1 naming no issue, or ended any
53
+ # other way (stderr names the raw exit code) —
54
+ # never read as "nothing to drop"
55
+ # A label failure never stops the branch delete from running.
56
+ #
42
57
  # Exit 0: the branch is gone from origin (deleted here, already gone, or a fork
43
58
  # PR's branch, which lives in another repository and is not ours to
44
59
  # delete — `"skipped":"cross-repository"`).
@@ -55,6 +70,10 @@
55
70
  # such PR (that PR's number, not the merged one's) instead of the JSON
56
71
  # payload; stderr says which role each plays. A deliberate keep, not a
57
72
  # failure: report the lines, never retry.
73
+ # Exit 4: the branch half succeeded (what would be exit 0) but the label half
74
+ # printed at least one token. When the branch half exits 1, 2 or 3 that
75
+ # code wins and the tokens are still printed. Report every token line
76
+ # on any non-zero exit; never retry.
58
77
  set -eu
59
78
 
60
79
  # Ambient GIT_DIR/GIT_WORK_TREE would point `ls-remote origin` and the push at
@@ -77,6 +96,13 @@ net_lib="$(dirname "$0")/net.sh"
77
96
  # shellcheck source=net.sh
78
97
  . "$net_lib" || die "$net_lib failed to load"
79
98
 
99
+ # The label half is a sibling script, resolved from this file's own location —
100
+ # not PATH, not the caller's cwd. Checked with the helper libraries, before
101
+ # anything is touched: a partial install must never delete branches while
102
+ # silently skipping the label.
103
+ label_script="$(dirname "$0")/drop-merged-label.sh"
104
+ [ -r "$label_script" ] || die "cannot read $label_script — refusing to delete a branch without the label drop that belongs to it"
105
+
80
106
  [ $# -eq 1 ] || die "usage: delete-merged-branch.sh <pr>"
81
107
  pr=$1
82
108
  case "$pr" in ''|*[!0-9]*|0?*) die "pr must be a number, got '$pr'";; esac
@@ -99,6 +125,55 @@ EOF
99
125
 
100
126
  # MERGED, not just closed: a PR closed unmerged still holds work nowhere else.
101
127
  [ "$state" = "MERGED" ] || die "PR #$pr is not merged (state=$state) — refusing to delete its branch"
128
+
129
+ # The label half runs HERE — right after the MERGED gate and before any
130
+ # branch-half validation — so every later exit (deleted, already gone, skipped,
131
+ # kept, delete failed, a read that dies) already carries its outcome. A PR that
132
+ # is not MERGED never reaches it. Its JSON line and stderr stay on stderr:
133
+ # stdout carries only the tokens below and the branch half's own output, and a
134
+ # label failure never stops the branch delete from running.
135
+ label_failed=false
136
+ label_token() { printf '%s\n' "$1"; label_failed=true; }
137
+
138
+ echo "\$ sh $label_script $pr --apply" >&2
139
+ label_rc=0
140
+ label_out=$(sh "$label_script" "$pr" --apply) || label_rc=$?
141
+ [ -z "$label_out" ] || printf '%s\n' "$label_out" >&2
142
+ case "$label_rc" in
143
+ 0) echo "$NAME: in-progress dropped from every issue PR #$pr closes (or none carried it)" >&2 ;;
144
+ 1)
145
+ # The label script's own exit 1 is "one or more removals failed"; its
146
+ # `failed` array names them. Exit 1 with no number to extract is not an
147
+ # answer about any issue, so it reads as undetermined, never as clear.
148
+ if ! failed_issues=$(printf '%s\n' "$label_out" | sed -n 's/.*"failed":\[\([0-9][0-9,]*\)\].*/\1/p'); then
149
+ failed_issues=""
150
+ fi
151
+ if [ -z "$failed_issues" ]; then
152
+ echo "$NAME: $label_script exited 1 but named no failed issue — the label outcome is unknown" >&2
153
+ label_token "label-read-failed-#$pr"
154
+ else
155
+ for n in $(printf '%s\n' "$failed_issues" | tr ',' ' '); do
156
+ label_token "label-drop-failed-#$n"
157
+ done
158
+ fi
159
+ ;;
160
+ *)
161
+ echo "$NAME: $label_script exited $label_rc — the label outcome could not be determined" >&2
162
+ label_token "label-read-failed-#$pr"
163
+ ;;
164
+ esac
165
+
166
+ # Exit 4: the branch half succeeded but a label token was printed. The branch
167
+ # half's own 1, 2 and 3 win; this only lifts a would-be 0.
168
+ lift_exit_to_label_failure() {
169
+ exit_rc=$?
170
+ trap - EXIT
171
+ if [ "$exit_rc" -eq 0 ]; then exit 4; fi
172
+ exit "$exit_rc"
173
+ }
174
+ if [ "$label_failed" = true ]; then
175
+ trap lift_exit_to_label_failure EXIT
176
+ fi
102
177
  [ -n "$branch" ] && [ -n "$oid" ] || die "gh pr view $pr returned no head branch or head commit"
103
178
  case "$oid" in *[!0-9a-f]*) die "gh pr view $pr returned a head commit that is not a hex SHA: '$oid'";; esac
104
179
  [ "$branch" != "$base" ] || die "PR #$pr's head branch is its base branch '$base' — refusing to delete it"
@@ -9,8 +9,9 @@
9
9
  # Single writer, per the #170 ruling: the merge is the only moment the ticket
10
10
  # number and the fact of completion are known together, so only a PROVEN merge
11
11
  # triggers this — never reap (branches, not tickets), never a repo automation
12
- # (no attribution). Call this from run-merge-bot.md's step 4, after
13
- # prove-merge.sh, never before: the claim has not ended until the merge lands.
12
+ # (no attribution). The merge bot's branch-delete step, delete-merged-branch.sh,
13
+ # calls this script as a sibling with --apply, after its own MERGED gate: the
14
+ # claim has not ended until the merge lands. Direct use is manual repair.
14
15
  #
15
16
  # #1617: `closingIssuesReferences` reflects `Closes #N` syntax in the PR's own
16
17
  # title/body, but NOT a commit-message-only reference — GitHub's real
@@ -36,7 +36,7 @@ import { isCLI } from "./is-cli.mjs";
36
36
  import { makeDie, defineFlags } from "./arg.mjs";
37
37
  import { CELL, POLICY_CELL, drawCell, parseMember } from "./ledger-grammar.mjs";
38
38
  import { parseTsv as parseMemberTsv } from "./member-outcomes.mjs";
39
- import { parseTierOutcomes } from "./tier-outcomes.mjs";
39
+ import { DATE, parseTierOutcomes, rulingFor, rulingsByTicket } from "./tier-outcomes.mjs";
40
40
 
41
41
  const NAME = "ticket-router";
42
42
  const SCRIPT_DIR = dirname(fileURLToPath(import.meta.url));
@@ -280,26 +280,26 @@ export function parseFeatures(text) {
280
280
  const UNBOOKED = (name) => name.startsWith("merge-bot-") || name === "memory" || name === "__advisor";
281
281
  const round4 = (x) => Math.round(x * 1e4) / 1e4;
282
282
 
283
- /** The last verdict row per ticket: `{ pr, fail }`. A verdict is a ruled PR; the floor fails on a minted false claim or an unclosed ticket. */
284
- function verdictsByTicket(verdictRows) {
285
- const by = new Map();
286
- for (const r of verdictRows) {
287
- for (const t of String(r.ticket ?? "").split("+").filter(Boolean)) {
288
- by.set(t, { pr: String(r.pr ?? ""), fail: r.minted_false_claim === "yes" || r.closed_own_ticket === "no" });
289
- }
290
- }
291
- return by;
283
+ /**
284
+ * The verdict on a ticket's Pull dated `pullDate`, `{ pr, fail }`, or null: the
285
+ * ruling `rulingFor` picks. A verdict is a ruled PR; the floor fails on a
286
+ * minted false claim or an unclosed ticket.
287
+ */
288
+ function verdictOf(rulings, ticket, pullDate) {
289
+ const r = rulingFor(rulings, ticket, pullDate);
290
+ return r && { pr: String(r.pr ?? ""), fail: r.minted_false_claim === "yes" || r.closed_own_ticket === "no" };
292
291
  }
293
292
 
294
293
  /**
295
294
  * Per-ticket input rows: the ticket's features rows inside [window, cutoff],
296
295
  * attributed to its LAST row's cell and stratum, restricted to rows the
297
296
  * free classifier routed plus exploration rows — a row a live B classifier
298
- * routed is the A/B's test set, not the fit's. A fit over everything cuts at
299
- * its latest features row's date; the verdict and member rows are cut at that
300
- * same date, so `--check`'s re-fit at the recorded `fitted_through` reads the
301
- * rows the fit read and a verdict or member row that lands later waits for the
302
- * next fit instead of failing CI.
297
+ * routed is the A/B's test set, not the fit's. Its verdict rules its last
298
+ * input row. A fit over everything cuts at its latest features row's date;
299
+ * the verdict and member rows are cut at that same date, so `--check`'s
300
+ * re-fit at the recorded `fitted_through` reads the rows the fit read and a
301
+ * verdict or member row that lands later waits for the next fit instead of
302
+ * failing CI.
303
303
  */
304
304
  function fitTickets({ features, members, verdicts, window, cutoff }) {
305
305
  const inRange = features.filter((r) => (!window || r.run_date >= window)
@@ -312,12 +312,15 @@ function fitTickets({ features, members, verdicts, window, cutoff }) {
312
312
  if (!byTicket.has(r.ticket)) byTicket.set(r.ticket, []);
313
313
  byTicket.get(r.ticket).push(r);
314
314
  }
315
- const v = verdictsByTicket(verdicts.filter(upToThrough));
315
+ // A ruling whose date is not YYYY-MM-DD cannot be placed against the cut, and
316
+ // a string `<=` would drop 'abc' or '2027' unseen: it is left in, so `rulingFor`
317
+ // refuses it when its ticket is an input, as `fit --due` does.
318
+ const rulings = rulingsByTicket(verdicts.filter((r) => !DATE.test(r.run_date) || upToThrough(r)));
316
319
  const out = [];
317
320
  for (const [ticket, rows] of byTicket) {
318
321
  const last = rows[rows.length - 1];
319
322
  if (last.exploration_draw === "" && last.sizing_src !== "rule") continue;
320
- const verdict = v.get(ticket) ?? null;
323
+ const verdict = verdictOf(rulings, ticket, last.run_date);
321
324
  const keys = new Set(rows.map((r) => `${r.session}\0${r.agent}`));
322
325
  let cost = 0;
323
326
  let costKnown = true;
@@ -434,11 +437,12 @@ export function fitTable({ prior, features, members, verdicts, guard, cutoff })
434
437
  };
435
438
  }
436
439
 
437
- /** Merged PRs (tickets with a verdict) among the features rows dated after `fitted_through`. */
440
+ /** Merged PRs (tickets with a verdict on their last such row) among the features rows dated after `fitted_through`. */
438
441
  export function mergedSince({ table, features, verdicts }) {
439
- const v = verdictsByTicket(verdicts);
442
+ const rulings = rulingsByTicket(verdicts);
440
443
  const after = features.filter((r) => (!table.window_start || r.run_date >= table.window_start) && (!table.fitted_through || r.run_date > table.fitted_through));
441
- return new Set(after.map((r) => r.ticket).filter((t) => v.has(t))).size;
444
+ const pullDates = new Map(after.map((r) => [r.ticket, r.run_date]));
445
+ return [...pullDates].filter(([ticket, date]) => verdictOf(rulings, ticket, date)).length;
442
446
  }
443
447
 
444
448
  // ---------------------------------------------------------------------------
@@ -512,9 +516,13 @@ function main() {
512
516
  const features = read("features", parseFeatures);
513
517
  const members = read("members", parseMemberTsv);
514
518
  const verdicts = read("verdicts", parseTierOutcomes);
519
+ // The verdict join throws on a ruling of an input ticket it cannot place.
520
+ const joined = (fit) => {
521
+ try { return fit(); } catch (e) { die(`cannot read --verdicts ${need("verdicts")}: ${e.message}`); }
522
+ };
515
523
 
516
524
  if (mode === "check") {
517
- const refit = fitTable({ prior: table, features, members, verdicts, guard: { ...table.guard, window_start: table.window_start }, cutoff: table.fitted_through });
525
+ const refit = joined(() => fitTable({ prior: table, features, members, verdicts, guard: { ...table.guard, window_start: table.window_start }, cutoff: table.fitted_through }));
518
526
  const differ = Object.keys({ ...refit, ...table }).filter((k) => !isDeepStrictEqual(refit[k], table[k]));
519
527
  if (differ.length) {
520
528
  process.stderr.write(`${NAME}: ${tablePath} is not a re-fit of its own rows — differs in ${differ.map((k) => `\`${k}\``).join(", ")}; re-fitted:\n${JSON.stringify(refit, null, 2)}\n`);
@@ -530,11 +538,11 @@ function main() {
530
538
  const guard = readGuard(readJson(guardPath));
531
539
  if (guard === null) die(`cannot read --guard ${guardPath} as a cost guard — the fit needs its tripped cells and per-cell n`);
532
540
  if (F.has("due")) {
533
- const n = mergedSince({ table, features, verdicts });
541
+ const n = joined(() => mergedSince({ table, features, verdicts }));
534
542
  process.stdout.write(`DUE=${n >= FIT_EVERY_MERGED ? "yes" : "no"} MERGED=${n}/${FIT_EVERY_MERGED}\n`);
535
543
  return;
536
544
  }
537
- const next = fitTable({ prior: table, features, members, verdicts, guard });
545
+ const next = joined(() => fitTable({ prior: table, features, members, verdicts, guard }));
538
546
  writeFileSync(`${tablePath}.tmp`, `${JSON.stringify(next, null, 2)}\n`);
539
547
  renameSync(`${tablePath}.tmp`, tablePath);
540
548
  process.stdout.write(`${NAME}: fitted ${next.n_rows} tickets through ${next.fitted_through ?? "no rows"}; rows ${JSON.stringify(next.rows)}; burn_in ${next.burn_in}; stage ${next.stage}\n`);
@@ -80,7 +80,7 @@ export const LEGACY_WIDTH = COLUMNS.length - 4;
80
80
  // date of the header's switch note.
81
81
  export const TIER_SWITCH_DATE = "2026-09-29";
82
82
 
83
- const DATE = /^\d{4}-\d{2}-\d{2}$/;
83
+ export const DATE = /^\d{4}-\d{2}-\d{2}$/;
84
84
  const BASE_DEFINITION = "fleet-implementer";
85
85
  // The two quality-floor columns `append` writes. Every reader fails the floor
86
86
  // on exactly `minted_false_claim=yes` or `closed_own_ticket=no`, so any other
@@ -132,6 +132,37 @@ export function formatRow(fields) {
132
132
  return COLUMNS.map((c) => String(fields[c] ?? "")).join("\t");
133
133
  }
134
134
 
135
+ // Each ticket's ruling rows of parsed tier-outcomes `rows`, in file order. A
136
+ // `+`-joined `ticket` field rules each ticket it names; a row with both
137
+ // verdict columns blank was never ruled, so it is skipped.
138
+ export function rulingsByTicket(rows) {
139
+ const by = new Map();
140
+ for (const r of rows) {
141
+ if (VERDICT_COLUMNS.every((c) => r[c] === "")) continue;
142
+ for (const t of String(r.ticket ?? "").split("+").filter(Boolean)) (by.get(t) ?? by.set(t, []).get(t)).push(r);
143
+ }
144
+ return by;
145
+ }
146
+
147
+ // The row ruling `ticket`'s Pull dated `pullDate`, from `rulingsByTicket`: its
148
+ // last ruling dated on or after the Pull, since a ruling never predates the
149
+ // Pull it rules — or null. Throws on a ruling of the ticket whose `run_date`
150
+ // is not YYYY-MM-DD, which cannot be placed against the Pull and whose drop
151
+ // would uncount the ticket, and on the ruling it picks holding anything but
152
+ // `yes` or `no` in a verdict column, which would otherwise read as a pass.
153
+ export function rulingFor(rulings, ticket, pullDate) {
154
+ const own = rulings.get(String(ticket)) ?? [];
155
+ for (const r of own) {
156
+ if (!DATE.test(r.run_date)) throw new Error(`ticket #${ticket} (PR #${r.pr}): run_date is '${r.run_date}', expected YYYY-MM-DD`);
157
+ }
158
+ const v = own.findLast((r) => r.run_date >= pullDate);
159
+ if (!v) return null;
160
+ for (const c of VERDICT_COLUMNS) {
161
+ if (!VERDICT.includes(v[c])) throw new Error(`ticket #${ticket} (PR #${v.pr}): ${c} is '${v[c]}', expected yes or no`);
162
+ }
163
+ return v;
164
+ }
165
+
135
166
  // Every member-outcomes.tsv row for the ticket's implementer, of ANY agent
136
167
  // type: a lone `task` row is still the ticket's one implementer, and the
137
168
  // point of the check is to catch exactly that.
@@ -3408,6 +3408,8 @@ the deletion back; `reap.sh` takes the `[gone]` local branch and its worktree.
3408
3408
  No repo setting is relied on to do it (#2196). A branch another open PR still
3409
3409
  uses as its head or base is kept instead — `branch-kept-#<that PR>` in the bot's
3410
3410
  report, a deliberate keep and not a failure (#2295).
3411
+ The branch-delete step also releases the claim label: it drops `in-progress` from
3412
+ every issue the PR closes.
3411
3413
 
3412
3414
  **Never force a rebase to start.** No `git clean`, `git checkout .`,
3413
3415
  `git reset --hard`, `git stash`. Uncommitted changes may exist nowhere else.