@feigi/fleet-ctl 3.64.0 → 3.64.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@feigi/fleet-ctl",
3
- "version": "3.64.0",
3
+ "version": "3.64.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": {
@@ -45,6 +45,15 @@
45
45
  // the PR once it exists, are kept in the receipt: a re-run
46
46
  // after a failed push or PR resumes on that branch and never
47
47
  // opens a second PR.
48
+ // phase0-receipt moves `.fleet/phase0.json` to `.fleet/phase0.previous.json`,
49
+ // the name `phase0.mjs` holds a previous run's receipt under,
50
+ // so a run that ended here leaves no phase-0 receipt for the
51
+ // next run in this session to resume, and that run's rotation
52
+ // files it as `phase0.<UTC stamp>.json` beside the ledger
53
+ // archive. After the tick, which reads the caps from it, and
54
+ // before the stop. No `phase0.json` is nothing to move and is
55
+ // `ok`; a held receipt already there that is not this one is
56
+ // a failed step.
48
57
  // heartbeat-stop `fleet-heartbeat.mjs --stop "<reason>"`, last, because
49
58
  // every reader takes a recorded stop as the end of the run.
50
59
  //
@@ -70,7 +79,7 @@
70
79
  // Zero deps: node builtins and sibling scripts only.
71
80
 
72
81
  import { spawnSync } from "node:child_process";
73
- import { existsSync, mkdirSync, readFileSync, readdirSync, renameSync, writeFileSync } from "node:fs";
82
+ import { existsSync, linkSync, mkdirSync, readFileSync, readdirSync, renameSync, statSync, unlinkSync, writeFileSync } from "node:fs";
74
83
  import { homedir } from "node:os";
75
84
  import { dirname, join } from "node:path";
76
85
  import { fileURLToPath } from "node:url";
@@ -78,7 +87,7 @@ import { makeDie, defineFlags } from "./arg.mjs";
78
87
  import { FleetDirUnresolvable, fleetFile } from "./fleet-dir.mjs";
79
88
  import { gitEnv } from "./git-env.mjs";
80
89
  import { isCLI } from "./is-cli.mjs";
81
- import { CLOSEOUT_RECEIPT, memberTokens, rowPr } from "./ledger-grammar.mjs";
90
+ import { CLOSEOUT_RECEIPT, RECEIPT, RECEIPT_HELD, memberTokens, rowPr } from "./ledger-grammar.mjs";
82
91
  import { encodeProjectDir, isOmpSessionDirName } from "./member-record.mjs";
83
92
  import { tickCaps } from "./phase0-receipt.mjs";
84
93
 
@@ -334,6 +343,31 @@ function stepCommitAndPR({ reason, branch, receipt, save }) {
334
343
  return result;
335
344
  }
336
345
 
346
+ // The receipt `phase0.mjs` resumes would otherwise outlive the run it describes.
347
+ // It is set aside under the name `phase0.mjs` holds a previous run's receipt
348
+ // under, which the next run's rotation restores and archives with the ledger.
349
+ // Linked, then unlinked, so a held receipt already there is refused rather than
350
+ // overwritten; one that is this very file, left by a crash between the two, is
351
+ // finished off.
352
+ function stepPhase0Receipt({ fleetDir }) {
353
+ const from = join(fleetDir, RECEIPT);
354
+ if (!existsSync(from)) return ok(`no ${RECEIPT} to move`);
355
+ const to = join(fleetDir, RECEIPT_HELD);
356
+ try {
357
+ linkSync(from, to);
358
+ } catch (e) {
359
+ if (e.code !== "EEXIST") return failed(`cannot move ${from} to ${to}: ${e.message}`);
360
+ const [a, b] = [statSync(from), statSync(to)];
361
+ if (a.dev !== b.dev || a.ino !== b.ino) return failed(`${to} already holds another receipt — move it out of the way, then run finish again`);
362
+ }
363
+ try {
364
+ unlinkSync(from);
365
+ } catch (e) {
366
+ return failed(`moved ${from} to ${to} but could not remove it: ${e.message} — remove it by hand before the next run`);
367
+ }
368
+ return ok(`${from} -> ${to}`);
369
+ }
370
+
337
371
  function stepHeartbeatStop({ cwd, reason }) {
338
372
  const r = node("fleet-heartbeat.mjs", ["--stop", reason], { cwd });
339
373
  return r.status === 0 ? ok(r.stdout) : failed(`fleet-heartbeat.mjs --stop failed: ${detail(r)}`);
@@ -348,6 +382,7 @@ const FINISH = {
348
382
  "tier-outcomes": stepTierOutcomes,
349
383
  metrics: stepMetrics,
350
384
  "commit-and-pr": stepCommitAndPR,
385
+ "phase0-receipt": stepPhase0Receipt,
351
386
  "heartbeat-stop": stepHeartbeatStop,
352
387
  };
353
388
  const STEP_NAMES = [...Object.keys(BEGIN), ...Object.keys(FINISH)];
@@ -29,6 +29,11 @@ import { createHash } from "node:crypto";
29
29
  // way, so the format lives here once.
30
30
  const RECEIPT_STEM = "phase0";
31
31
  export const RECEIPT = `${RECEIPT_STEM}.json`;
32
+ // Where a previous run's receipt waits, beside the ledger, until the next run's
33
+ // rotation files it: `phase0.mjs` holds a receipt there at startup, and
34
+ // `closeout.mjs finish` sets the run's own there, so a run that ended cleanly
35
+ // leaves no receipt for the next run to resume.
36
+ export const RECEIPT_HELD = `${RECEIPT_STEM}.previous.json`;
32
37
  export const archiveStamp = () => new Date().toISOString().replace(/\.\d{3}Z$/, "Z").replaceAll(":", "");
33
38
  export const receiptArchiveName = (stamp) => `${RECEIPT_STEM}.${stamp}.json`;
34
39
  const CLOSEOUT_STEM = "closeout";
@@ -76,7 +76,8 @@
76
76
  // writes the next, so the previous run's receipt still matches it, and a
77
77
  // re-run that trusted `run` alone would skip `rotate`. The session rule closes
78
78
  // a new session. A receipt of any other run (a `run` that is set and does not
79
- // match, or a different session) is held as `phase0.previous.json` and the
79
+ // match, or a different session) is held as `phase0.previous.json`, where
80
+ // `closeout.mjs finish` also leaves a finished run's receipt, and the
80
81
  // script starts at `branch`; this run's own receipt is written at
81
82
  // `phase0.json` after every step. A receipt whose rotation has not run is
82
83
  // simply overwritten: every step before `rotate` is idempotent and is re-run
@@ -122,7 +123,7 @@ import { FleetDirUnresolvable, fleetFile } from "./fleet-dir.mjs";
122
123
  import { readState, stateFileIn } from "./fleet-state.mjs";
123
124
  import { gitEnv } from "./git-env.mjs";
124
125
  import { isCLI } from "./is-cli.mjs";
125
- import { RECEIPT, archiveStamp, receiptArchiveName, rowNums } from "./ledger-grammar.mjs";
126
+ import { RECEIPT, RECEIPT_HELD, archiveStamp, receiptArchiveName, rowNums } from "./ledger-grammar.mjs";
126
127
 
127
128
  const NAME = "phase0";
128
129
  const SCRIPTS = dirname(fileURLToPath(import.meta.url));
@@ -131,8 +132,6 @@ const NETWORK_TIMEOUT_MS = 120_000;
131
132
  const PR_LIMIT = 1000;
132
133
  // The tail of a child's output is the part that says why it stopped.
133
134
  const OUTPUT_MAX = 16_000;
134
- // The previous run's receipt, set aside at startup until the rotation files it.
135
- const HELD = "phase0.previous.json";
136
135
  const RULESET_SPEC = join(".github", "rulesets", "main.json");
137
136
  const RULESET_CHECK = join(".github", "scripts", "apply-ruleset.sh");
138
137
 
@@ -479,7 +478,7 @@ function main() {
479
478
  const scratch = root.stdout;
480
479
 
481
480
  const receiptPath = join(fleetDir, RECEIPT);
482
- const held = join(fleetDir, HELD);
481
+ const held = join(fleetDir, RECEIPT_HELD);
483
482
  const state = readState(stateFileIn(fleetDir), NAME);
484
483
  if (state.degraded) {
485
484
  // The record decides whether a receipt is the previous run's, and a record