@feigi/fleet-ctl 3.76.0 → 3.76.2

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": "@feigi/fleet-ctl",
3
- "version": "3.76.0",
3
+ "version": "3.76.2",
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": {
package/scripts/pull.mjs CHANGED
@@ -18,7 +18,9 @@
18
18
  // `next --head <N>` on a dispatched Pull prints it again.
19
19
  // 1 the ticket left the Pull — taken, relabelled elsewhere, closed,
20
20
  // relabelled by cause, excluded — with the reason printed; take the next
21
- // entry. An empty shortlist is this exit too.
21
+ // entry. An empty shortlist is this exit too. `next --head <N>` starting
22
+ // a Pull for a ticket whose ledger row is an exclusion naming no premise,
23
+ // or one whose premise still stands, is this exit as well.
22
24
  // 2 could not look, named on stderr: a probe that did not answer, a write
23
25
  // that failed, a router that refused. `next --head <N>` runs a step that
24
26
  // failed again; when the failure came from applying an answer, the
@@ -27,8 +29,10 @@
27
29
  // the ticket over; one whose claim could not be released leaves the Pull
28
30
  // at the route step with the claim standing, and `next` routes again. An
29
31
  // exclusion premise `gh` could not read is exit 2 when no other entry is
30
- // left. An unknown flag is exit 2 as well, as for every script that holds
31
- // a command line of its own.
32
+ // left, and always exit 2 when `next --head <N>` starts a Pull for the
33
+ // ticket that holds it, the exclusion standing and no record written. An
34
+ // unknown flag is exit 2 as well, as for every script that holds a command
35
+ // line of its own.
32
36
  // 3 usage: any other mistake in the command line, or an answer the pending
33
37
  // question does not take. Nothing is recorded.
34
38
  // 10 a question is pending: its `QUESTION <qid>:` block, with the tokens it
@@ -36,6 +40,17 @@
36
40
  //
37
41
  // THE STEPS, in this order:
38
42
  //
43
+ // 0 hold-out Only `next --head <N>` starting a Pull (no record, or one that
44
+ // is `left`, `released` or another session's) runs it; resuming
45
+ // a running Pull or reprinting a dispatched one does not. The
46
+ // ledger row for `#<N>`, when it reads `excluded`, has its
47
+ // premises checked as `next` without `--head` checks them. One
48
+ // still standing ends the Pull, reason `excluded ·
49
+ // behind-<kind>:#<target> <STATE>` (no STATE when `gh` was not
50
+ // asked), and a row naming no premise ends it too, reason the
51
+ // row's own text; either way the record is saved and nothing
52
+ // else run. A premise `gh` could not read is exit 2 with nothing
53
+ // recorded, and every premise lifted lets step 1 run.
39
54
  // 1 inflight `inflight.sh <N>`: anything but exit 0 is taken.
40
55
  // 2 issue `gh issue view <N> --json title,body,comments,labels,createdAt`
41
56
  // written to `<scratch>/impl-<N>/issue.json`. Without the
@@ -1096,29 +1111,64 @@ class Pull {
1096
1111
 
1097
1112
  // ── the shortlist head ───────────────────────────────────────────────────────
1098
1113
 
1099
- // Whether an exclusion's premises still hold: a premise `gh` cannot be asked
1100
- // about, or whose state could not be read, stands, as the shortlist's refresh
1101
- // reads it. Each such premise is added to `unreadable`, so that a shortlist
1102
- // emptied by premises nobody could read is told apart from an empty one.
1103
- function exclusionLive(premises, cwd, unreadable) {
1104
- if (premises.length === 0) return true;
1114
+ // The first of an exclusion's premises that still stands, or null when every one is lifted. A premise `gh` cannot
1115
+ // be asked about, or whose state could not be read, stands, as the shortlist's refresh reads it: `token` is the
1116
+ // premise normalised to `behind-<kind>:#<target>` (null for a row naming none), `state` what `gh` answered (null
1117
+ // when it was not asked or answered no state), `unread` what could not be read (null when nothing went unread).
1118
+ function standingPremise(premises, cwd) {
1119
+ if (premises.length === 0) return { token: null, state: null, unread: null };
1105
1120
  for (const { kind, target } of premises) {
1106
- if (target.startsWith("-") || !(kind === "pr" || isDigits(target))) return true;
1121
+ const token = `behind-${kind}:#${target}`;
1122
+ if (target.startsWith("-") || !(kind === "pr" || isDigits(target))) return { token, state: null, unread: null };
1107
1123
  const r = spawn("gh", [kind, "view", target, "--json", "state"], { cwd, env: GH_ENV, timeoutMs: NETWORK_TIMEOUT_MS });
1108
1124
  if (r.status !== 0) {
1109
- unreadable.push(`gh ${kind} view ${target} (${r.how}${r.stderr === "" ? "" : `: ${r.stderr.split("\n")[0]}`})`);
1110
- return true;
1125
+ return { token, state: null, unread: `gh ${kind} view ${target} (${r.how}${r.stderr === "" ? "" : `: ${r.stderr.split("\n")[0]}`})` };
1111
1126
  }
1112
1127
  let state;
1113
1128
  try {
1114
1129
  ({ state } = JSON.parse(r.stdout));
1115
1130
  } catch {
1116
- unreadable.push(`gh ${kind} view ${target} (printed no JSON state)`);
1117
- return true;
1131
+ // Unparseable: `state` stays undefined and is read as no state, as the shortlist's refresh reads it.
1118
1132
  }
1119
- if (!LIFTED.has(state)) return true;
1133
+ if (typeof state !== "string" || state === "") {
1134
+ return { token, state: null, unread: `gh ${kind} view ${target} (printed no JSON state)` };
1135
+ }
1136
+ if (!LIFTED.has(state)) return { token, state, unread: null };
1137
+ }
1138
+ return null;
1139
+ }
1140
+
1141
+ // The rows of the ledger, read through `ledger.mjs read`.
1142
+ function readLedgerRows(p) {
1143
+ const led = spawn(process.execPath, [join(SCRIPTS, "ledger.mjs"), "read"], { cwd: p.cwd });
1144
+ let rows;
1145
+ try {
1146
+ ({ rows } = JSON.parse(led.stdout));
1147
+ } catch {
1148
+ rows = null;
1149
+ }
1150
+ if (led.status !== 0 || !Array.isArray(rows) || !rows.every((r) => typeof r === "string")) {
1151
+ throw new Refusal(withText(`ledger.mjs read did not answer (${led.how})`, led));
1120
1152
  }
1121
- return false;
1153
+ return rows;
1154
+ }
1155
+
1156
+ /**
1157
+ * Why ticket `n` may not start a Pull: the reason a Pull would leave it with, when its ledger row is an exclusion
1158
+ * whose premise still stands; null when the ledger holds no such row or the premise is lifted. A premise `gh`
1159
+ * could not read is a refusal (exit 2) that says the exclusion stands.
1160
+ */
1161
+ function heldOut(p, n) {
1162
+ const row = readLedgerRows(p).find((r) => rowKey(r) === `#${n}`);
1163
+ const premises = row === undefined ? null : premisesOf(row);
1164
+ if (premises === null) return null;
1165
+ const standing = standingPremise(premises, p.cwd);
1166
+ if (standing === null) return null;
1167
+ if (standing.unread !== null) {
1168
+ throw new Refusal(`#${n}: the premise of its exclusion could not be read, so the exclusion stands: ${standing.unread} — run again once gh answers`);
1169
+ }
1170
+ if (standing.token === null) return row.slice(rowKey(row).length).trim();
1171
+ return `excluded · ${standing.token}${standing.state === null ? "" : ` ${standing.state}`}`;
1122
1172
  }
1123
1173
 
1124
1174
  // The phase-0 session names the run a Pull belongs to: the persistent scratch
@@ -1143,22 +1193,19 @@ function shortlistHead(p, run) {
1143
1193
  if (!Array.isArray(list?.shortlist) || !list.shortlist.every((e) => Number.isInteger(e?.n))) {
1144
1194
  throw new Refusal(`${p.shortlist} holds no shortlist[] of {n}`);
1145
1195
  }
1146
- const led = spawn(process.execPath, [join(SCRIPTS, "ledger.mjs"), "read"], { cwd: p.cwd });
1147
- let rows;
1148
- try {
1149
- ({ rows } = JSON.parse(led.stdout));
1150
- } catch {
1151
- rows = null;
1152
- }
1153
- if (led.status !== 0 || !Array.isArray(rows) || !rows.every((r) => typeof r === "string")) {
1154
- throw new Refusal(withText(`ledger.mjs read did not answer (${led.how})`, led));
1155
- }
1196
+ const rows = readLedgerRows(p);
1197
+ // Each premise nobody could read, so that a shortlist emptied by premises nobody could read is told apart from an
1198
+ // empty one.
1156
1199
  const unreadable = [];
1157
1200
  for (const { n } of list.shortlist) {
1158
1201
  const row = rows.find((r) => rowKey(r) === `#${n}`);
1159
1202
  if (row !== undefined && isImplRow(row)) continue;
1160
1203
  const premises = row === undefined ? null : premisesOf(row);
1161
- if (premises !== null && exclusionLive(premises, p.cwd, unreadable)) continue;
1204
+ const standing = premises === null ? null : standingPremise(premises, p.cwd);
1205
+ if (standing !== null) {
1206
+ if (standing.unread !== null) unreadable.push(standing.unread);
1207
+ continue;
1208
+ }
1162
1209
  const ended = readPull(p.statePath(n));
1163
1210
  if (ended !== null && (ended.status === "left" || ended.status === "released") && (run === null || ended.session === run)) continue;
1164
1211
  return n;
@@ -1216,7 +1263,11 @@ function next(args) {
1216
1263
  const n = head ?? shortlistHead(base, run);
1217
1264
  if (n === null) return result(1, ["EMPTY: the shortlist holds no entry to pull — run shortlist.mjs once and Pull again; still empty, hold the slot idle until the next refresh trigger"]);
1218
1265
  let st = readPull(base.statePath(n));
1219
- if (st !== null && (st.status === "left" || st.status === "released" || (run !== null && st.session !== run))) {
1266
+ const starts = st === null || st.status === "left" || st.status === "released" || (run !== null && st.session !== run);
1267
+ // The shortlist head was checked against the ledger on the way here; one asked for by number was not. A premise
1268
+ // that cannot be read is refused here, before the ended record is moved, so the next run asks again.
1269
+ const held = head !== null && starts ? heldOut(base, n) : null;
1270
+ if (starts && st !== null) {
1220
1271
  // Asked for by number, so asked for again: the ended Pull is kept beside the new one. A record from another
1221
1272
  // run is ended too, whatever it says: the ledger rotated, and a dispatch it made is none of this run's.
1222
1273
  renameSync(base.statePath(n), base.previousPath(n));
@@ -1225,6 +1276,11 @@ function next(args) {
1225
1276
  const first = st === null;
1226
1277
  if (first) st = fresh(n, run);
1227
1278
  const pull = pullFor(base, st);
1279
+ if (held !== null) {
1280
+ const r = pull.leave(held);
1281
+ pull.save();
1282
+ return r;
1283
+ }
1228
1284
  if (first) pull.save();
1229
1285
  const r = pull.advance();
1230
1286
  return { ...r, out: [first ? `PULL #${n}: started, state in ${base.statePath(n)}` : `PULL #${n}: resumed at ${st.pending === null ? st.stage : `question ${st.pending.qid}`}`, ...pull.log, ...r.out] };
@@ -395,7 +395,7 @@ worktree re-created for an already-open PR is in references/isolation.md.
395
395
  | 1 `LEFT #N: relabelled elsewhere` | no longer labelled `ready-for-agent` | next entry |
396
396
  | 1 `LEFT #N: closed: fixed by …` | `close` answered `yes` | next entry |
397
397
  | 1 `LEFT #N: relabelled <label>: …` | `decided` answered with a cause | next entry |
398
- | 1 `LEFT #N: excluded · behind-…` | `collision` answered `behind-pr:#M` or `behind-issue:#M` | next entry |
398
+ | 1 `LEFT #N: excluded …` | `collision` answered `behind-pr:#M` or `behind-issue:#M`, or its ledger exclusion stands | next entry |
399
399
  | 1 `EMPTY` | the shortlist holds no entry to pull | run `shortlist.mjs` once and Pull again; still empty, hold the slot idle until the next refresh trigger |
400
400
  | 2 | could not look, named on stderr | as the entry paragraph says |
401
401
  | 3 | a usage mistake, or a token the question does not take | correct it; nothing was recorded |
@@ -276,7 +276,18 @@ sequences after. No new ledger section. `shortlist.mjs` probes every premise at
276
276
  each refresh — MERGED or CLOSED lifts a `behind-pr`, CLOSED lifts a
277
277
  `behind-issue` — and a lifted ticket re-enters the shortlist in its own
278
278
  oldest-first slot; its row is rewritten to `impl-<N> …` when it is pulled,
279
- because `row` replaces the whole line.
279
+ because `row` replaces the whole line. `pull.mjs next --head <N>` reads the
280
+ ticket's row too when it would start a Pull (no record, or an ended one, or one
281
+ from another session; a Pull in progress or dispatched is resumed or reprinted
282
+ without a read): a premise still standing — one `gh` cannot be asked about
283
+ stands — ends the Pull at once, exit 1 `LEFT #<N>: excluded · behind-issue:#M
284
+ OPEN`, and so does an `excluded` row naming no premise, its reason the row's
285
+ own text; either way the record is saved and nothing claimed or commented. A
286
+ premise `gh` could not read, or whose answer holds no state, is exit 2 naming
287
+ it, the exclusion standing and nothing recorded, so the same command asks again
288
+ once `gh` answers. A branch-named `behind-pr` whose PR does not exist yet is
289
+ read that way: `gh pr view` finds no PR for the branch, so it is exit 2, not a
290
+ `LEFT`.
280
291
 
281
292
  ## Claiming
282
293