@feigi/fleet-ctl 3.29.3 → 3.29.5

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.
@@ -187,7 +187,7 @@ For each labeled PR clearing the hold rule, lowest first:
187
187
  ~/.fleet/bin/fleet-run ledger.mjs row <key> "<text> · conflict-hold:#<pr> (conflict: <path1>, <path2>)"
188
188
  ```
189
189
 
190
- `<text>` is everything after the key, verbatim — `row` rewrites the whole line, so a token you drop is gone. `#<pr>` is this PR, never the one it conflicts with; the tick refuses a hold naming another PR. The `(conflict: …)` note is free text, comma-joined paths from the `diff --name-only` read above — placed *after* the token, never before, so it cannot fall inside `PR_MENTION`'s first-match binding or `CONFLICT_HOLD`'s own pattern. From then on the tick prints `DISPATCH fix-pr PR#<pr>` for it and counts it in `held=` until a fix-applier dispatched after the hold settles `applied:`/`no-op`. Skip the `row` write on an already-unresolved hold, per the paragraph above — nothing else about this path changes: still report `rebase-fallback-#<pr>`, still hand it back.
190
+ `<text>` is everything after the key, verbatim — `row` rewrites the whole line, so a token you drop is gone. `#<pr>` is this PR, never the one it conflicts with; the tick refuses a hold naming another PR. The `(conflict: …)` note is free text, comma-joined paths from the `diff --name-only` read above — placed *after* the token, never before, so it cannot become the first `PR#` mention a row with no `impl-` token is read by (`ledger-grammar.mjs`'s `rowPr`) or fall inside `CONFLICT_HOLD`'s own pattern. From then on the tick prints `DISPATCH fix-pr PR#<pr>` for it and counts it in `held=` until a fix-applier dispatched after the hold settles `applied:`/`no-op`. Skip the `row` write on an already-unresolved hold, per the paragraph above — nothing else about this path changes: still report `rebase-fallback-#<pr>`, still hand it back.
191
191
 
192
192
  **The fallback's "verified" needs a clean main-gain check on the local rebased head.** Save the PR body to `<scratch>/pr<N>/merge-bot-<n>/body.md` (`gh pr view <pr> --json body -q .body`) and, from the main checkout, run `~/.fleet/bin/fleet-run main-gain.mjs --head "$(git -C <worktree> rev-parse HEAD)" --body-file <scratch>/pr<N>/merge-bot-<n>/body.md`. Exit 0 is the only clean result; name every `acknowledged[]` entry, with its reason, in the hand-back. Exit 1 (a line `main` gained after the PR began would be removed) or exit 2 (it could not answer) is reported inside `rebase-fallback-#<pr>` — the hits and each one's `ack` line to copy, or the `reason` it could not answer — and the fallback is never reported verified.
193
193
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@feigi/fleet-ctl",
3
- "version": "3.29.3",
3
+ "version": "3.29.5",
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": {
@@ -15,18 +15,18 @@
15
15
  // `<member>=<outcome>` settled) and has no I/O at all; parseToken is read
16
16
  // from it for the same reason — one grammar, one reader, so the cockpit and
17
17
  // fleet-tick.mjs cannot disagree about which members are live.
18
- // fleet-tick.mjs owns a row's PR reading, PR_MENTION, and a row with no impl
19
- // token is read through it (see the paragraph below on a row with no `impl`
20
- // token) so both readers name the same PR for the same text, for a row that
21
- // carries a PR-bound signal —
18
+ // ledger-grammar.mjs owns a row's PR reading too, rowPr(), and a row with no
19
+ // impl token is read through it (see the paragraph below on a row with no
20
+ // `impl` token) so the cockpit and fleet-tick.mjs name the same PR for the
21
+ // same text, for a row that carries a PR-bound signal —
22
22
  // an unsignaled row (no mention, no PR-bound member, no review=/reviewed=)
23
23
  // still gets pr: null here while fleet-tick.mjs's own row-key fallback keys
24
- // it to its ticket number regardless; see the same paragraph below. The
25
- // regex is all this file takes from it: the tick's I/O and main() never run
26
- // here, main() being guarded on argv[1].
24
+ // it to its ticket number regardless; see the same paragraph below.
25
+ // fleet-tick.mjs's I/O and main() never run here, main() being guarded on
26
+ // argv[1].
27
27
  import { assessBeat, isStalled, stallReport } from "./fleet-state.mjs";
28
- import { parseToken, HALT_CAUSES } from "./ledger-grammar.mjs";
29
- import { PR_MENTION, REVIEWED, latestFinisherAttempts } from "./fleet-tick.mjs";
28
+ import { parseToken, rowPr, HALT_CAUSES } from "./ledger-grammar.mjs";
29
+ import { REVIEWED, latestFinisherAttempts } from "./fleet-tick.mjs";
30
30
 
31
31
  // A ledger row is freeform, controller-authored text. Two example shapes:
32
32
  // #<n> impl-<n>=PR#<m> → PR#<m> → MERGED 73b356de
@@ -40,19 +40,18 @@ import { PR_MENTION, REVIEWED, latestFinisherAttempts } from "./fleet-tick.mjs";
40
40
  // → that PR decides, `=released`/`=bailed` → no card of
41
41
  // the row's own (the POOL loop shows the ticket if it is still
42
42
  // `ready-for-agent`), `=killed`/`=tier-mismatch` → IMPLEMENTING with that
43
- // outcome as a flag. There the `→ PR#M` arrow is human-readable only;
44
- // parseRow reads only the settled impl token's outcome. PR_MENTION is a blind
45
- // `PR#<n>` text scan that in practice also lands on the impl token's embedded
46
- // value, because that precedes the arrow in every row this run writes — but
47
- // nothing enforces that order, so on such a row the arrow is never a value
48
- // either reader may rely on.
43
+ // outcome as a flag. There a `PR#` mention — the `→ PR#M` arrow or any
44
+ // other prose — is human-readable only; parseRow reads only the settled impl
45
+ // token's outcome, as rowPr() does for every reader. rowPr() takes the row's
46
+ // first settled `=PR#M` impl token, this card its latest attempt: the two
47
+ // differ only on a row carrying more than one impl token.
49
48
  //
50
49
  // A row with no `impl` token at all has no outcome to
51
50
  // read, so it takes the tick's reading. `ledger.mjs dispatch <pr> fix-pr-<pr>` /
52
51
  // `finisher-pr-<pr>` appends `#<pr> <member>` for a PR this run's
53
52
  // implementers did not open. Once such a row carries a PR-bound signal — a
54
53
  // `PR#M` mention, a `fix-pr-`/`finisher-pr-` member, `review=` or `reviewed=`
55
- // — its PR is PR_MENTION's, else the row key, and that PR decides the card as
54
+ // — its PR is rowPr()'s, else the row key, and that PR decides the card as
56
55
  // `=PR#M` does. An Exclusion never takes one.
57
56
  //
58
57
  // A member settled anywhere on the row is settled — a bare copy beside
@@ -211,16 +210,16 @@ export function parseRow(row) {
211
210
  let pr = prM ? Number(prM[1]) : null;
212
211
  // A row with NO impl token — a malformed one still
213
212
  // counts, since that row's key is a ticket — is keyed, once THIS row
214
- // carries a PR-bound signal, the way fleet-tick.mjs's PR_MENTION-then-
215
- // row-key logic would: its first PR_MENTION (itself a signal), else the
213
+ // carries a PR-bound signal, the way fleet-tick.mjs's rowPr-then-
214
+ // row-key logic would: rowPr()'s first `PR#` mention (itself a signal), else the
216
215
  // row key when the first word is exactly `#N`. fleet-tick.mjs's own
217
216
  // row-key fallback (deriveRun) is NOT itself gated on a signal — this
218
217
  // module's extra gate exists so an ordinary unclaimed ticket never
219
218
  // borrows its own number as a phantom PR. An Exclusion is supply and
220
219
  // never takes a PR, whatever text it carries.
221
220
  if (!anyImpl && !ex) {
222
- const mention = PR_MENTION.exec(row);
223
- if (mention) pr = Number(mention[1]);
221
+ const own = rowPr(row);
222
+ if (own !== null) pr = own;
224
223
  else if ((prMember || review || reviewed) && row.split(/\s/)[0] === issueM[0]) pr = Number(issueM[1]);
225
224
  }
226
225
  let lastFinisher = null;
@@ -59,7 +59,7 @@
59
59
  // the ledger; main() does the I/O. Split so the guard table and the reading are
60
60
  // both unit-testable without a network.
61
61
 
62
- import { parseMember, parseToken } from "./ledger-grammar.mjs";
62
+ import { parseMember, parseToken, rowPr } from "./ledger-grammar.mjs";
63
63
 
64
64
  // Every role's TARGET is its configured cap. Availability of work belongs in
65
65
  // the ACTION, not the target: a reviewer target that shrank to the backlog
@@ -340,17 +340,6 @@ export function actionable(rows) {
340
340
 
341
341
  export class LedgerError extends Error {}
342
342
 
343
- // A row's PR is its first `PR#<n>` mention — ledger.mjs rowPr()'s reading, so
344
- // both the `→ PR#<n>` arrow and a settled `impl-<N>=PR#<n>` name it. A row
345
- // with none is keyed by the PR's own number when it is about a PR at all (a PR
346
- // this run's implementers did not open) — this is ledger.mjs's
347
- // memberRowIndex() fallback specifically, which gates on the member being
348
- // PR-bound before it ever reaches this fallback. deriveRun below applies the
349
- // same row-key fallback to every row's own bookkeeping unconditionally,
350
- // signal or not; only memberRowIndex()'s caller already knows it holds a
351
- // PR-bound member. Ticket and PR numbers share GitHub's one number
352
- // space, so a ticket's key never names an open PR.
353
- export const PR_MENTION = /\bPR\s*#(\d+)\b/;
354
343
  // shortlist.mjs's own spelling of an Exclusion row and its premises.
355
344
  const EXCLUDED_ROW = /^#[0-9]+[ \t]+excluded(?=[ \t]|$)([\s\S]*)$/;
356
345
  const PREMISE = /\bbehind-(pr|issue):#?([^\s,;]+)/g;
@@ -429,13 +418,22 @@ export function labelOffMember(tok) {
429
418
  return m !== null && m.family === "finisher-pr" ? m : null;
430
419
  }
431
420
 
432
- // A row's key number and its PR, per the comment above PR_MENTION: the PR
433
- // every PR-bound token on the row speaks for.
421
+ // A row's key number and its PR: the PR every PR-bound token on the row
422
+ // speaks for. That PR is ledger-grammar.mjs's rowPr(): on a row carrying an
423
+ // `impl-` token, its settled `impl-<N>=PR#<n>` token's PR, never a prose
424
+ // `PR#` mention; on any other row, its first `PR#<n>` mention. A row with
425
+ // none is keyed by the PR's own number when it is about a PR at all (a PR
426
+ // this run's implementers did not open) — this is ledger.mjs's
427
+ // memberRowIndex() fallback specifically, which gates on the member being
428
+ // PR-bound before it ever reaches this fallback. deriveRun below applies the
429
+ // same row-key fallback to every row's own bookkeeping unconditionally,
430
+ // signal or not; only memberRowIndex()'s caller already knows it holds a
431
+ // PR-bound member. Ticket and PR numbers share GitHub's one number
432
+ // space, so a ticket's key never names an open PR.
434
433
  export function rowNums(text) {
435
434
  const key = text.split(/\s/)[0];
436
435
  const keyNum = /^#[0-9]+$/.test(key) ? Number(key.slice(1)) : null;
437
- const mention = PR_MENTION.exec(text);
438
- return { keyNum, pr: mention ? Number(mention[1]) : keyNum };
436
+ return { keyNum, pr: rowPr(text) ?? keyNum };
439
437
  }
440
438
 
441
439
  // PRs whose finisher attempts are read off the ledger while the open list shows
@@ -81,6 +81,28 @@ export function memberTokens(text) {
81
81
  return text.split(/\s+/).filter(Boolean).map(parseToken).filter(Boolean);
82
82
  }
83
83
 
84
+ // `PR#<n>` as a word of a row's text, `PR #<n>` too.
85
+ const PR_MENTION = /\bPR\s*#(\d+)\b/;
86
+
87
+ /**
88
+ * The PR a row's text is about, or null when it names none of its own — the
89
+ * one reading of it every ledger reader keys PR state by. A row carrying an
90
+ * `impl-` token, live, settled or malformed, is its first well-formed settled
91
+ * `impl-<N>=PR#<M>` token's PR in row order, and no PR while it has none: a
92
+ * `PR#` mention in its prose, an `→ PR#M` arrow included, never decides it,
93
+ * wherever it sits. A row with no `impl-` token is its first `PR#<n>`
94
+ * mention's. Falling back to the row's `#<n>` key is each caller's own.
95
+ */
96
+ export function rowPr(text) {
97
+ const impls = memberTokens(text).filter((t) => t.family === "impl");
98
+ if (impls.length > 0) {
99
+ const settled = impls.find((t) => t.error === null && t.outcome?.startsWith("PR#"));
100
+ return settled ? Number(settled.outcome.slice("PR#".length)) : null;
101
+ }
102
+ const m = PR_MENTION.exec(text);
103
+ return m ? Number(m[1]) : null;
104
+ }
105
+
84
106
  /** The name the next merge bot takes: 1 + the `merge-bot-` entries in
85
107
  * `## Dispatched`, settled ones included. One ledger per run, so n restarts
86
108
  * at 1 with every run. */
@@ -35,7 +35,7 @@ import { fileURLToPath } from "node:url";
35
35
  import { spawnSync, execFileSync } from "node:child_process";
36
36
  import { makeDie, isFlagLike, hasEqualsForm, isDigits } from "./arg.mjs";
37
37
  import { fleetFile, FleetDirUnresolvable } from "./fleet-dir.mjs";
38
- import { parseMember, parseToken, memberTokens, nextMergeBot, agentDefinition, CELL, tierValues } from "./ledger-grammar.mjs";
38
+ import { parseMember, parseToken, memberTokens, nextMergeBot, agentDefinition, CELL, tierValues, rowPr } from "./ledger-grammar.mjs";
39
39
  import { deriveRun, LedgerError, labelOffMember } from "./fleet-tick.mjs";
40
40
  import { stateFileIn, readState, assessBeat, stallsAt } from "./fleet-state.mjs";
41
41
 
@@ -1584,15 +1584,6 @@ function rowKey(r) {
1584
1584
  return r.split(/\s/)[0];
1585
1585
  }
1586
1586
 
1587
- // A row's PR is its first `PR#<n>` mention: the `→ PR#<n>` arrow or the
1588
- // implementer's settled `impl-<N>=PR#<n>` token, which name the same PR.
1589
- // compute-board.mjs parseRow() reads the settled token, so the row a
1590
- // PR-bound member lands on is the card the cockpit shows that PR on.
1591
- function rowPr(r) {
1592
- const m = /\bPR\s*#(\d+)\b/.exec(r);
1593
- return m ? Number(m[1]) : null;
1594
- }
1595
-
1596
1587
  // Whether a row carries the member's token — live only, settled only, or
1597
1588
  // either when `live` is not given.
1598
1589
  function carries(row, name, live) {
@@ -1600,8 +1591,9 @@ function carries(row, name, live) {
1600
1591
  }
1601
1592
 
1602
1593
  // The row a member's token belongs on: an implementer's is its ticket's row; a
1603
- // PR-bound member's is the row whose PR is its PR, else one keyed by that PR's
1604
- // own number (a PR this run's implementers did not open). -1 when there is
1594
+ // PR-bound member's is the row whose PR is its PR — ledger-grammar.mjs's
1595
+ // rowPr(), the reading the tick folds that PR's state by — else one keyed by
1596
+ // that PR's own number (a PR this run's implementers did not open). -1 when there is
1605
1597
  // none yet. A merge bot works no ticket and never has one.
1606
1598
  function memberRowIndex(member) {
1607
1599
  if (member.bound === null) return -1;
@@ -1876,10 +1868,11 @@ function runSettle() {
1876
1868
  // Fold that row's tokens onto this one, in order, so later PR-bound writes
1877
1869
  // find the one row through rowPr(). Only
1878
1870
  // an implementer settles to `PR#M` (ledger-grammar.mjs), and only when the
1879
- // settling row named NO PR before this write: `rowPr()` and the tick's
1880
- // `PR_MENTION` both read the FIRST `PR#` mention on a row, so a row that
1881
- // already named one — this PR via a hand-written `→ PR#M` arrow, or a
1882
- // different PR from an earlier attempt — would let the fold misattribute
1871
+ // settling row named NO PR before this write: `rowPr()` is the tick's
1872
+ // reading of a row's PR too, so a row that
1873
+ // already named one — this PR via a hand-written `→ PR#M` arrow on a row
1874
+ // with no impl token, or a different PR from an earlier attempt's settled
1875
+ // token — would let the fold misattribute
1883
1876
  // its content to the wrong PR, or bury the row's own fresher
1884
1877
  // `review=`/`reviewed=` state under the folded row's older one (the tick
1885
1878
  // reads only the LAST). The candidate row must itself carry a live or
@@ -58,9 +58,8 @@ import { fileURLToPath } from "node:url";
58
58
  import { isCLI } from "./is-cli.mjs";
59
59
  import { makeDie, defineFlags, isDigits } from "./arg.mjs";
60
60
  import { parseTsv as parseMemberTsv } from "./member-outcomes.mjs";
61
- import { parseMember, parseToken, memberTokens } from "./ledger-grammar.mjs";
61
+ import { parseMember, parseToken, memberTokens, rowPr } from "./ledger-grammar.mjs";
62
62
  import { rowText } from "./tier-check.mjs";
63
- import { PR_MENTION } from "./fleet-tick.mjs";
64
63
 
65
64
  const NAME = "tier-outcomes";
66
65
  const SCRIPT_DIR = dirname(fileURLToPath(import.meta.url));
@@ -321,16 +320,16 @@ export function checkRows(rows, memberRows) {
321
320
  }
322
321
 
323
322
  // The ledger half of `check`: every PR a run-ledger row marks `reviewed=` that
324
- // has no row here. The row's PR is read the way fleet-tick.mjs reads it — a
325
- // `PR#M` mention, else the row's own key.
323
+ // has no row here. The row's PR is read the way fleet-tick.mjs reads it —
324
+ // ledger-grammar.mjs's rowPr(), else the row's own key.
326
325
  export function unrecordedReviewedPrs(ledger, rows) {
327
326
  const have = new Set(rows.map((r) => r.pr));
328
327
  const missing = new Set();
329
328
  for (const text of ledger?.rows ?? []) {
330
329
  if (!text.split(/\s+/).some((t) => t.startsWith("reviewed="))) continue;
331
330
  const key = text.split(/\s/)[0];
332
- const mention = PR_MENTION.exec(text);
333
- const pr = mention ? mention[1] : /^#[0-9]+$/.test(key) ? key.slice(1) : null;
331
+ const own = rowPr(text);
332
+ const pr = own !== null ? String(own) : /^#[0-9]+$/.test(key) ? key.slice(1) : null;
334
333
  if (pr && !have.has(pr)) missing.add(Number(pr));
335
334
  }
336
335
  return [...missing].sort((a, b) => a - b);
@@ -632,17 +632,21 @@ wt_occupied() { [ -e "$1" ] || [ -L "$1" ]; }
632
632
  # once per run — the git dir does not move under a running script. 1 with
633
633
  # `$wt_why` when git cannot name the common directory.
634
634
  #
635
- # `2>/dev/null`, never `2>&1`: the answer is used as a PATH, and a
636
- # `~/.gitconfig` with a key outside any section makes every git command print
637
- # `error: key does not contain a section: …` on stderr AT EXIT 0, which `2>&1`
638
- # would glue in front of it.
635
+ # `2>/dev/null`, never `2>&1`, on the capture that answers: it is used as a
636
+ # PATH, and a `~/.gitconfig` with a key outside any section makes every git
637
+ # command print `error: key does not contain a section: …` on stderr AT EXIT
638
+ # 0, which `2>&1` would glue in front of it. Git's own words are fetched with
639
+ # a second call, only on the path that refuses, and there stdout is discarded
640
+ # so `2>&1` has no path to glue onto.
639
641
  wt_root=
640
642
  # shellcheck disable=SC2034
641
643
  wt_registry_root() {
642
644
  wt_why=
643
645
  [ -z "$wt_root" ] || return 0
644
646
  if ! wt_rr_common=$(git rev-parse --path-format=absolute --git-common-dir 2>/dev/null); then
645
- wt_why="cannot resolve the git common directory"
647
+ wt_rr_err=$(git rev-parse --path-format=absolute --git-common-dir 2>&1 >/dev/null) || :
648
+ wt_rr_err=$(printf '%s' "$wt_rr_err" | tr '\n' ' ') || wt_rr_err=
649
+ wt_why="cannot resolve the git common directory${wt_rr_err:+: $wt_rr_err}"
646
650
  return 1
647
651
  fi
648
652
  wt_root="$wt_rr_common/worktrees"