@feigi/fleet-ctl 3.41.0 → 3.41.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.41.0",
3
+ "version": "3.41.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": {
@@ -1214,34 +1214,56 @@ function readShortlist(path) {
1214
1214
  return parseShortlist(text);
1215
1215
  }
1216
1216
 
1217
- // An Exclusion whose premise has lifted, for a ticket the current file does
1218
- // not already carry (if it does, the refresh that lifted it has run). A
1219
- // `behind-pr:#M` reads off the open list already in hand; a `behind-issue:#M`
1220
- // costs one `gh issue view`. A branch-named `behind-pr` is left to the
1221
- // refresh itself: before its PR exists, "no open PR" is not "merged". Any
1222
- // probe that cannot answer leaves the exclusion standing.
1217
+ // A gh state read of one Exclusion premise, scrubbed as shortlist.mjs's
1218
+ // probeState() is: gh's remote resolution follows GIT_DIR/GIT_WORK_TREE, and
1219
+ // GH_REPO outranks both. The state it printed, or null when it could not
1220
+ // answer — a nonzero exit, or exit 0 with a body carrying no state (an HTML
1221
+ // error page, JSON with no state). Either way the unanswered probe is
1222
+ // disclosed, not dropped: every other gh call in this file either dies or
1223
+ // logs its failure, so a bare empty catch here would be the one silent
1224
+ // exception in a file whose whole design goal is "no silent stall".
1225
+ function premiseState(noun, target, label) {
1226
+ const r = spawnSync("gh", [noun, "view", target, "--json", "state"], { encoding: "utf8", timeout: GH_TIMEOUT_MS, env: gitEnv({ GH_REPO: "" }) });
1227
+ if (r.error || r.status !== 0) {
1228
+ console.error(`${NAME}: ${failure(r, `gh ${noun} view ${target}`)} — ${label} premise unconfirmed, exclusion stands`);
1229
+ return null;
1230
+ }
1231
+ let st = null;
1232
+ try { st = JSON.parse(r.stdout).state; } catch { /* no state: disclosed below */ }
1233
+ if (typeof st !== "string") {
1234
+ console.error(`${NAME}: gh ${noun} view ${target} printed no state — ${label} premise unconfirmed, exclusion stands`);
1235
+ return null;
1236
+ }
1237
+ return st;
1238
+ }
1239
+
1240
+ // An Exclusion whose premise sends the tick to a refresh. Lifted, for a
1241
+ // ticket the current file does not already carry (if it does, the refresh
1242
+ // that lifted it has run): a `behind-pr:#M` reads off the open list already
1243
+ // in hand; a `behind-issue:#M` costs one `gh issue view`; a branch-named
1244
+ // `behind-pr` costs one `gh pr view`, whose MERGED or CLOSED lifts it —
1245
+ // before its PR exists, "no open PR" is not "merged". Standing, for a
1246
+ // branch-named `behind-pr` whose ticket the current file still carries: the
1247
+ // file may predate the exclusion, and only the refresh's own probe can drop
1248
+ // the ticket from it, so any answer short of MERGED or CLOSED, an
1249
+ // unanswered probe included, asks for that refresh. An unanswered probe
1250
+ // never lifts an exclusion.
1223
1251
  function liftedPremise(excluded, entries, prs) {
1224
1252
  const inFile = new Set(entries.map((e) => e.n));
1225
1253
  const open = new Set(prs.map((p) => p.number));
1226
1254
  for (const { n, premises } of excluded) {
1227
- if (inFile.has(n)) continue;
1228
1255
  for (const { kind, target } of premises) {
1229
- if (!isDigits(target)) continue;
1256
+ if (kind === "pr" && !isDigits(target)) {
1257
+ const st = premiseState("pr", target, `behind-pr:#${target}`);
1258
+ const lifted = st === "CLOSED" || st === "MERGED";
1259
+ if (lifted && !inFile.has(n)) return `behind-pr:#${target} ${st}`;
1260
+ if (!lifted && inFile.has(n)) return `behind-pr:#${target} not merged, #${n} still on the shortlist`;
1261
+ continue;
1262
+ }
1263
+ if (inFile.has(n) || !isDigits(target)) continue;
1230
1264
  if (kind === "pr" && !open.has(Number(target))) return `behind-pr:#${target} no longer open`;
1231
1265
  if (kind === "issue") {
1232
- // Scrubbed as shortlist.mjs's probeState() is: gh's remote resolution
1233
- // follows GIT_DIR/GIT_WORK_TREE, and GH_REPO outranks both.
1234
- const r = spawnSync("gh", ["issue", "view", target, "--json", "state"], { encoding: "utf8", timeout: GH_TIMEOUT_MS, env: gitEnv({ GH_REPO: "" }) });
1235
- if (r.error || r.status !== 0) {
1236
- // Disclosed, not dropped: every other gh call in this file either
1237
- // dies or logs its failure — a bare empty catch here would be the
1238
- // one silent exception in a file whose whole design goal is "no
1239
- // silent stall".
1240
- console.error(`${NAME}: ${failure(r, `gh issue view ${target}`)} — behind-issue:#${target} premise unconfirmed, exclusion stands`);
1241
- continue;
1242
- }
1243
- let st = null;
1244
- try { st = JSON.parse(r.stdout).state; } catch { /* unanswered: the exclusion stands */ }
1266
+ const st = premiseState("issue", target, `behind-issue:#${target}`);
1245
1267
  if (st === "CLOSED" || st === "MERGED") return `behind-issue:#${target} ${st}`;
1246
1268
  }
1247
1269
  }
@@ -1386,9 +1408,11 @@ function main() {
1386
1408
  throw e;
1387
1409
  }
1388
1410
 
1389
- // Pull from the current file first; refresh when it is short, absent, or an
1390
- // exclusion has lifted — and top the PULL up from what the refresh found,
1391
- // so a slot the current file could not fill does not wait a tick for it.
1411
+ // Pull from the current file first; refresh when it is short, absent, an
1412
+ // exclusion has lifted, or a branch-named one still names a ticket on it.
1413
+ // A refresh that succeeds replaces the heads outright: the PULL is read off
1414
+ // what shortlist.mjs just probed, never merged with the file's own heads,
1415
+ // or a ticket the refresh dropped would be pulled anyway.
1392
1416
  let heads = unclaimed(current.entries, run);
1393
1417
  let supply = current.scanned;
1394
1418
  let dropped = current.dropped;
@@ -1400,7 +1424,7 @@ function main() {
1400
1424
  const r = refresh();
1401
1425
  if (r.ok) {
1402
1426
  const excludedSet = new Set(run.excluded.map((x) => x.n));
1403
- heads = [...new Set([...heads, ...unclaimed(r.entries, run)])];
1427
+ heads = unclaimed(r.entries, run);
1404
1428
  supply = r.scanned;
1405
1429
  dropped = r.dropped;
1406
1430
  fresh = {
@@ -66,8 +66,10 @@
66
66
  // unknown — some read failed: git, a hash, HEAD, `origin/main`, or a baseline
67
67
  // that EXISTS but cannot be read (unreadable file, unsearchable
68
68
  // `.fleet/`, dangling symlink, not written by --record) — or is a
69
- // v1 baseline, which says nothing of HEAD: re-record it. "A failure
70
- // is an unknown answer, never a 'no'" — never `clean`.
69
+ // v1 baseline, which says nothing of HEAD: re-record it — or names
70
+ // a commit absent from the repository: examine HEAD, then
71
+ // re-record it. "A failure is an unknown answer, never a 'no'" —
72
+ // never `clean`.
71
73
  // absent — no baseline at all: the run never recorded one. A refusal
72
74
  // ("record at run start"), never `clean`.
73
75
  //
@@ -78,7 +80,20 @@
78
80
  // so it refuses on every unknown cause it can see: a baseline that exists but
79
81
  // cannot be read, and any failed git or hash read (no snapshot, nothing to
80
82
  // write). A detached HEAD has no symbolic ref to record, so it refuses that
81
- // too. A v1 baseline is the one thing it overwrites without a word.
83
+ // too. A v1 baseline, and one whose commit is gone (it never reads the
84
+ // recorded commit), it overwrites without a word.
85
+ //
86
+ // A BASELINE COMMIT GONE FROM THE REPOSITORY is its own unknown. An amend or
87
+ // reset leaves the baseline's commit unreachable, and once reflog expiry and
88
+ // gc prune it the ancestry read fails where it would have answered `dirty`.
89
+ // What failed is the baseline, not the environment, so "fix the failure and
90
+ // never re-baseline" would forbid the one remedy: the advice is to examine
91
+ // HEAD against `origin/main` FIRST — the move off that commit is unexamined —
92
+ // and only then re-record. The check returns before it compares paths, so the
93
+ // advice also says to resolve any stray paths. On the baseline's own branch it
94
+ // is still `unknown`, never `dirty` or `clean`: the read that would have
95
+ // judged the move could not be made. A different branch reads `dirty` before
96
+ // any ancestry read.
82
97
  //
83
98
  // ROOT. The main checkout is the parent of `git rev-parse --git-common-dir`
84
99
  // (git-env.mjs's `workspaceDirFromGitCommonDir`, as fleet-tick.mjs resolves
@@ -272,13 +287,18 @@ function originMain(root, env) {
272
287
 
273
288
  /**
274
289
  * Did HEAD move off the baseline's? `{ok, change}`: `change` is null, or the
275
- * `HEAD <was> → <now>` entry; `{ok: false, why}` when a read failed.
290
+ * `HEAD <was> → <now>` entry; `{ok: false, why}` when a read failed, with
291
+ * `missing: true` when the failure is the baseline's commit being absent.
276
292
  * Clean is all of: the same symbolic ref; the baseline's commit an ancestor of
277
293
  * HEAD or equal to it; no commit in `B..HEAD` that `origin/main` lacks. So a
278
294
  * fast-forward to `origin/main` and a commit already unpushed at the baseline
279
295
  * read clean, while a stray commit, a reset or an amend do not. `origin/main`
280
296
  * is read even when HEAD equals the baseline: a checkout that cannot name it
281
297
  * is one this cannot vouch for.
298
+ * A failed ancestry read is followed by `git cat-file -e B`, which exits 1
299
+ * for an absent object and 0 for a present one, even a corrupt one;
300
+ * `-e B^{commit}` exits 128 for both, so it cannot tell them apart. Only
301
+ * exit 1 is the missing answer; anything else keeps the ancestry failure.
282
302
  */
283
303
  function headMove(root, env, was, now) {
284
304
  const origin = originMain(root, env);
@@ -287,7 +307,12 @@ function headMove(root, env, was, now) {
287
307
  if (now.ref !== was.ref) return moved;
288
308
  if (now.oid === was.oid) return { ok: true, change: null };
289
309
  const ancestor = git("git merge-base --is-ancestor", ["merge-base", "--is-ancestor", was.oid, now.oid], root, env);
290
- if (!ancestor.ok) return ancestor.status === 1 ? moved : ancestor;
310
+ if (!ancestor.ok) {
311
+ if (ancestor.status === 1) return moved;
312
+ const present = git("git cat-file -e", ["cat-file", "-e", was.oid], root, env);
313
+ if (present.ok || present.status !== 1) return ancestor;
314
+ return { ok: false, missing: true, why: `baseline commit ${was.oid.slice(0, 7)} is missing from this repository; HEAD is ${headLabel(now)}` };
315
+ }
291
316
  const stray = git("git rev-list", ["rev-list", "--max-count=1", `${was.oid}..${now.oid}`, "^refs/remotes/origin/main"], root, env);
292
317
  if (!stray.ok) return stray;
293
318
  return stray.stdout.trim() === "" ? { ok: true, change: null } : moved;
@@ -345,9 +370,10 @@ export function changedPaths(baseline, current) {
345
370
 
346
371
  /**
347
372
  * The tick's question: `{state, root?, baseline?, changed?, headMove?, why?, cause?}`.
348
- * `cause` tells the three unknowns apart — `"baseline"` (it exists but cannot
373
+ * `cause` tells the four unknowns apart — `"baseline"` (it exists but cannot
349
374
  * be read), `"outdated"` (a v1 baseline: it says nothing of HEAD, so it can
350
- * answer nothing) and `"read"` (git or a hash failed) — since each has its own
375
+ * answer nothing), `"missing"` (the baseline's commit is absent from the
376
+ * repository) and `"read"` (git or a hash failed) — since each has its own
351
377
  * message. The baseline is read before the tree, because without one there
352
378
  * is nothing to compare against and no reason to look.
353
379
  * A HEAD move is the first entry of `changed`, also named in `headMove`.
@@ -359,13 +385,13 @@ export function checkMainCheckout({ cwd = process.cwd(), env = process.env } = {
359
385
  const path = baselinePath(root);
360
386
  const base = readBaseline(path);
361
387
  if (base.status === "absent") return { state: "absent", root, baseline: path };
362
- if (base.status === "unreadable") return { state: "unknown", cause: "baseline", root, baseline: path, why: base.why };
363
- if (base.status === "outdated") return { state: "unknown", cause: "outdated", root, baseline: path, why: base.why };
364
- const unknown = (why) => ({ state: "unknown", cause: "read", root, baseline: path, why });
388
+ const unknown = (why, cause = "read") => ({ state: "unknown", cause, root, baseline: path, why });
389
+ if (base.status === "unreadable") return unknown(base.why, "baseline");
390
+ if (base.status === "outdated") return unknown(base.why, "outdated");
365
391
  const now = readState(root, env);
366
392
  if (!now.ok) return unknown(now.why);
367
393
  const move = headMove(root, env, base.head, now.head);
368
- if (!move.ok) return unknown(move.why);
394
+ if (!move.ok) return unknown(move.why, move.missing ? "missing" : "read");
369
395
  const changed = changedPaths(base.entries, now.entries);
370
396
  if (move.change !== null) changed.unshift(move.change);
371
397
  if (!changed.length) return { state: "clean", root, baseline: path };
@@ -400,6 +426,11 @@ export function describe(check, live = null) {
400
426
  return `MAIN-CHECKOUT-UNKNOWN ${check.why}${members}`
401
427
  + ` — dispatch held: resolve any stray paths FIRST, then re-record with ${RECORD_COMMAND} (it overwrites, it does not compare)`;
402
428
  }
429
+ if (check.cause === "missing") {
430
+ return `MAIN-CHECKOUT-UNKNOWN ${check.why}${members}`
431
+ + " — dispatch held: examine HEAD against origin/main FIRST, since a missing baseline commit means HEAD moved off it by an amend or reset nobody has looked at, and resolve any stray paths;"
432
+ + ` then re-record with ${RECORD_COMMAND} (it overwrites, it does not compare)`;
433
+ }
403
434
  return check.cause === "baseline"
404
435
  ? `MAIN-CHECKOUT-UNKNOWN baseline unreadable: ${check.why}${members}`
405
436
  + " — dispatch held: fix the baseline so it can be read; NEVER re-baseline over it, --record overwrites rather than compares"
@@ -309,7 +309,9 @@ phase, or in any later one, asks the maintainer which tickets to take.
309
309
  certifies them. **Never re-record over `MAIN-CHECKOUT-UNKNOWN`**: that
310
310
  walks the run from "could not look" to "certified clean" in one step, so
311
311
  `--record` itself refuses over a baseline it cannot read and on any git
312
- read that fails. `main-checkout.mjs --check` prints the same answer
312
+ read that fails. The exceptions are a v1 baseline and a baseline whose
313
+ commit is missing from the repository; Phase 3's tick lines say how each
314
+ is cleared. `main-checkout.mjs --check` prints the same answer
313
315
  without a tick.
314
316
 
315
317
  **Run the pre-flight, once the pin and the baseline are recorded.**
@@ -656,9 +658,11 @@ phase, or in any later one, asks the maintainer which tickets to take.
656
658
  drop, survivors and specs together, is named the same way.
657
659
  2. **Refresh is the tick's from here on.** `fleet-tick.mjs` runs
658
660
  `shortlist.mjs` itself when unclaimed entries fall below the implementer
659
- cap, when the file is missing or empty, and when an `excluded` premise has
660
- lifted, and prints `REFRESHED shortlist: <n> entries; <k> lifted`. Phase 0
661
- runs it by hand once because a dead run's shortlist is stale by definition.
661
+ cap, when the file is missing or empty, when an `excluded` premise has
662
+ lifted, and when a branch-named `behind-pr` exclusion whose PR is not yet
663
+ MERGED or CLOSED names a ticket the file still carries, and prints
664
+ `REFRESHED shortlist: <n> entries; <k> lifted`. Phase 0 runs it by hand
665
+ once because a dead run's shortlist is stale by definition.
662
666
 
663
667
  **No multi-select, no maintainer tick.** Selection and ordering are batched —
664
668
  one scan, oldest first; admission never is. The invariant this replaces — one
@@ -1942,9 +1946,13 @@ depth** guard table applied in code. Act on each line as it reads:
1942
1946
  could not look: a git or hash read failed (`could not look:`), or the
1943
1947
  baseline exists but cannot be read (`baseline unreadable:`). Never clean,
1944
1948
  and **never re-baseline over it** — `--record` overwrites, so that certifies
1945
- a tree nobody read. Fix what the line names and tick again. The one
1946
- exception is `baseline v1 — re-record`: an old-format baseline says nothing
1947
- of HEAD, and `--record` is its remedy.
1949
+ a tree nobody read. Fix what the line names and tick again. The exceptions
1950
+ are the two whose remedy is `--record`: `baseline v1 — re-record`, an
1951
+ old-format baseline that says nothing of HEAD; and `baseline commit <oid> is
1952
+ missing from this repository`, which an amend or reset followed by gc
1953
+ leaves — examine HEAD against `origin/main` FIRST, since HEAD moved off
1954
+ that commit and nobody has looked at the move, and resolve any stray paths,
1955
+ which the line does not name; only then re-record.
1948
1956
  - `MAIN-CHECKOUT-NO-BASELINE …` with `HOLD (main checkout no baseline)` — no
1949
1957
  baseline was recorded. Yours to fix: run Phase 0's `--record`. A baseline
1950
1958
  that vanished mid-run is not a fresh run — report it to the maintainer