@feigi/fleet-ctl 3.55.0 → 3.57.0
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/agents/fleet-finisher.agent.md +223 -1
- package/agents/fleet-fix-applier.agent.md +331 -0
- package/agents/fleet-merge-bot.agent.md +80 -1
- package/package.json +1 -1
- package/scripts/dispatch-prompt.mjs +2 -3
- package/scripts/fleet-state.mjs +27 -2
- package/scripts/fleet-tick.mjs +225 -39
- package/scripts/ledger-grammar.mjs +8 -14
- package/scripts/ledger.mjs +10 -9
- package/scripts/member-write-guard.mjs +5 -4
- package/skills/run-team/SKILL.md +65 -54
- package/skills/run-team/briefs/finisher.md +8 -125
- package/skills/run-team/briefs/fix-applier.md +1 -334
- package/skills/run-team/briefs/merge-bot.md +2 -73
package/package.json
CHANGED
|
@@ -57,9 +57,8 @@
|
|
|
57
57
|
// only a caller passing a value like `<branch>` can cause — refuses, naming
|
|
58
58
|
// it.
|
|
59
59
|
//
|
|
60
|
-
// The text every member of a role shares
|
|
61
|
-
//
|
|
62
|
-
// into the dispatch prompt by hand.
|
|
60
|
+
// The text every member of a role shares lives in that role's agent body; a
|
|
61
|
+
// template carries only what varies between dispatches of the role.
|
|
63
62
|
|
|
64
63
|
import { spawnSync } from "node:child_process";
|
|
65
64
|
import { createHash } from "node:crypto";
|
package/scripts/fleet-state.mjs
CHANGED
|
@@ -47,6 +47,16 @@
|
|
|
47
47
|
// never when. Pruned to the live set on every tick, so a settled
|
|
48
48
|
// member's stamp does not outlive it. Carried, never written, by
|
|
49
49
|
// the heartbeat and by ledger.mjs.
|
|
50
|
+
// applied fleet-tick only, and only under --apply. {run, reapAfter}: the
|
|
51
|
+
// merge-bot numbers whose `merge-bot-<n>=done` the tick has already
|
|
52
|
+
// run reap.sh and reclaim-scratch.mjs after, and the controller
|
|
53
|
+
// record's `at` they belong to. Written only under a record: with
|
|
54
|
+
// none, nothing tells one run from the next. Merge-bot numbering
|
|
55
|
+
// restarts at 1 in a run that carries no bot forward, and this
|
|
56
|
+
// file outlives the rotation, so a list whose `run` is not the
|
|
57
|
+
// current record's `at` is the previous run's and names nothing in
|
|
58
|
+
// this one. Carried, never written, by the heartbeat and by
|
|
59
|
+
// ledger.mjs.
|
|
50
60
|
//
|
|
51
61
|
// One writer per key. A key two scripts wrote would need locking to be
|
|
52
62
|
// correct, and none of them is in a position to hold one. That holds per key,
|
|
@@ -119,7 +129,7 @@ export function readState(path, name) {
|
|
|
119
129
|
// to judge and nothing to report. A zeroed mark would date the beat to the
|
|
120
130
|
// epoch and read as decades overdue on a run that has simply not started
|
|
121
131
|
// one — the cry-wolf direction this key must never fail in.
|
|
122
|
-
const fresh = { quiet: 0, elapsed: 0, digest: "", beat: null, ticked: null, acted: null, controller: null, seen: {}, rest: {} };
|
|
132
|
+
const fresh = { quiet: 0, elapsed: 0, digest: "", beat: null, ticked: null, acted: null, controller: null, seen: {}, applied: null, rest: {} };
|
|
123
133
|
// The same state, flagged: the file EXISTS and could not be used. A caller
|
|
124
134
|
// that acts on the absence of a record — ledger.mjs rotate — must tell this
|
|
125
135
|
// from `fresh`, which is a run that has simply not written one yet. The
|
|
@@ -227,7 +237,18 @@ export function readState(path, name) {
|
|
|
227
237
|
for (const [member, at] of Object.entries(v)) if (Number.isInteger(at) && at > 0) out[member] = at;
|
|
228
238
|
return out;
|
|
229
239
|
};
|
|
230
|
-
|
|
240
|
+
// `applied` is validated as a unit for the controller record's reason: a
|
|
241
|
+
// list is only read against the run it names, so one whose `run` is not a
|
|
242
|
+
// positive integer belongs to no run and reads as absent. Absent is the
|
|
243
|
+
// safe direction: the duties it records are idempotent, and the next
|
|
244
|
+
// --apply tick runs them again. A junk entry in the list costs that entry
|
|
245
|
+
// alone.
|
|
246
|
+
const done = (v) => {
|
|
247
|
+
if (!isRecord(v) || !Array.isArray(v.reapAfter)) return null;
|
|
248
|
+
if (!(Number.isInteger(v.run) && v.run > 0)) return null;
|
|
249
|
+
return { run: v.run, reapAfter: v.reapAfter.filter((n) => Number.isInteger(n) && n > 0) };
|
|
250
|
+
};
|
|
251
|
+
const { quiet, elapsed, digest, beat, ticked, acted, controller, seen, applied, ...rest } = parsed;
|
|
231
252
|
// A controller key that ctl() rejects is a record someone wrote and nobody
|
|
232
253
|
// can judge, not the absence of one — announced like the other degraded
|
|
233
254
|
// causes, and flagged.
|
|
@@ -245,6 +266,7 @@ export function readState(path, name) {
|
|
|
245
266
|
acted: tick(acted),
|
|
246
267
|
controller: record,
|
|
247
268
|
seen: stamps(seen),
|
|
269
|
+
applied: done(applied),
|
|
248
270
|
rest,
|
|
249
271
|
};
|
|
250
272
|
}
|
|
@@ -301,6 +323,9 @@ export function writeState(path, name, prev, patch) {
|
|
|
301
323
|
// `seen` is fleet-tick's, and the heartbeat and ledger.mjs write this file
|
|
302
324
|
// too: carried the same way, so neither erases the ages the tick keeps.
|
|
303
325
|
...(prev.seen && Object.keys(prev.seen).length > 0 ? { seen: prev.seen } : {}),
|
|
326
|
+
// `applied` too: a heartbeat write that dropped it would have the next
|
|
327
|
+
// --apply tick reap again after every merge pass it already reaped after.
|
|
328
|
+
...(prev.applied ? { applied: prev.applied } : {}),
|
|
304
329
|
...patch,
|
|
305
330
|
};
|
|
306
331
|
const tmp = `${path}.${process.pid}.tmp`;
|
package/scripts/fleet-tick.mjs
CHANGED
|
@@ -207,9 +207,10 @@ function implementers(s, left) {
|
|
|
207
207
|
}
|
|
208
208
|
// Held until tier-check.mjs has run on the newest implementer and written
|
|
209
209
|
// its verdict to the ledger — a Pull on top of an unchecked
|
|
210
|
-
// dispatch repeats whatever it got wrong.
|
|
211
|
-
//
|
|
212
|
-
//
|
|
210
|
+
// dispatch repeats whatever it got wrong. `--apply` runs the check itself
|
|
211
|
+
// before this row is read; the row is the controller's to act on when the
|
|
212
|
+
// tick ran without `--apply`, or the check wrote no verdict, so it asks to
|
|
213
|
+
// act, with the command in the detail.
|
|
213
214
|
if (s.tierUnchecked.length) {
|
|
214
215
|
return row(`HOLD (tier unchecked ${s.tierUnchecked.join(" ")})`, { acts: true, extra: tierCheckStep(s.tierUnchecked, s.phase0?.session) });
|
|
215
216
|
}
|
|
@@ -637,10 +638,9 @@ export function foldLedger({ rows, dispatched }, open, { lenient = false } = {})
|
|
|
637
638
|
// fix-applier is still working the conflict.
|
|
638
639
|
// `reviewFixed`: a REVIEW fix-applier landed after the latest
|
|
639
640
|
// `reviewed=` — one read while no hold stood unresolved. The one read
|
|
640
|
-
// while a hold did is the conflict fix-applier
|
|
641
|
-
//
|
|
642
|
-
//
|
|
643
|
-
// does one of those jobs once, so its landing folds once per PR
|
|
641
|
+
// while a hold did is the conflict fix-applier: it rebases and never sees
|
|
642
|
+
// the review file, so it clears the hold and answers no finding. Each
|
|
643
|
+
// fix-applier does one of those jobs once, so its landing folds once per PR
|
|
644
644
|
// (`fixLanded`), however many copies of its token the rows carry.
|
|
645
645
|
// `fixMembers`: every fix-applier on this PR, wherever its token sits —
|
|
646
646
|
// one still unsettled anywhere holds the PR off fixDue, since `dispatch`
|
|
@@ -887,6 +887,9 @@ export function deriveRun({ rows, dispatched, drain }, prs, closed = new Set(),
|
|
|
887
887
|
implLive: live("impl"),
|
|
888
888
|
fixLive: live("fix-pr"),
|
|
889
889
|
mergeBotLive,
|
|
890
|
+
// The number of every merge bot settled `done`: each is a merge pass
|
|
891
|
+
// `--apply` reaps and reclaims after, once (reapDue).
|
|
892
|
+
mergeBotDone: all.filter((m) => m.family === "merge-bot" && m.outcome === "done").map((m) => m.number).sort(asc),
|
|
890
893
|
reviewsLive: liveReviews.length,
|
|
891
894
|
// The in-flight reviews of PRs the open list does not carry: the ones
|
|
892
895
|
// `finished` could retire, so the caller asks gh about these and no others.
|
|
@@ -927,8 +930,8 @@ export function deriveRun({ rows, dispatched, drain }, prs, closed = new Set(),
|
|
|
927
930
|
unlabelled: unlabelledFinishers({ rows, dispatched },
|
|
928
931
|
new Set(prs.filter((p) => !isQueued(p)).map((p) => p.number))),
|
|
929
932
|
// Every PR, open or not, on a conflict hold no fix-applier has cleared —
|
|
930
|
-
// the one reading of a hold: `ledger.mjs dispatch`
|
|
931
|
-
//
|
|
933
|
+
// the one reading of a hold: `ledger.mjs dispatch` refuses a finisher off
|
|
934
|
+
// this list, so it
|
|
932
935
|
// answers the same per-PR fold this tick holds the merge on, split rows
|
|
933
936
|
// and a settle made anywhere included, rather than re-deriving it from
|
|
934
937
|
// one row's text.
|
|
@@ -1074,20 +1077,77 @@ export function livenessLines({ live, seen, thresholds, now }) {
|
|
|
1074
1077
|
return out;
|
|
1075
1078
|
}
|
|
1076
1079
|
|
|
1080
|
+
// --apply's pure half. The merge-bot numbers `applied.reapAfter` names for
|
|
1081
|
+
// THIS run: none when its `run` is not the controller record's `at`, since
|
|
1082
|
+
// merge-bot numbering restarts with a run and the state file outlives it
|
|
1083
|
+
// (fleet-state.mjs's `applied`). `controllerAt` is null with no record, and
|
|
1084
|
+
// with no record nothing tells this run from the one before it: a list then
|
|
1085
|
+
// names nothing, and the sweeps run again on the next tick.
|
|
1086
|
+
export function reapedAfter(applied, controllerAt) {
|
|
1087
|
+
return applied !== null && controllerAt != null && applied.run === controllerAt ? applied.reapAfter : [];
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
// The merge passes owed their reap and reclaim: every merge bot settled
|
|
1091
|
+
// `done` that reapedAfter() does not name.
|
|
1092
|
+
export function reapDue(done, applied, controllerAt) {
|
|
1093
|
+
const ran = new Set(reapedAfter(applied, controllerAt));
|
|
1094
|
+
return done.filter((n) => !ran.has(n));
|
|
1095
|
+
}
|
|
1096
|
+
|
|
1097
|
+
// The implementers the tick would print `HOLD (tier unchecked …)` for: read
|
|
1098
|
+
// off the rows reconcile() computed, so whatever outranks that hold — the
|
|
1099
|
+
// drain, a mismatch, phase 0, the main checkout — outranks the check too.
|
|
1100
|
+
export function tierCheckDue(rows, unchecked) {
|
|
1101
|
+
return rows.some((r) => r.role === "implementers" && r.action.startsWith("HOLD (tier unchecked ")) ? unchecked : [];
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1104
|
+
// The one JSON line a receipt-printing script ends on, or null.
|
|
1105
|
+
function receiptOf(stdout) {
|
|
1106
|
+
try {
|
|
1107
|
+
const r = JSON.parse(String(stdout).trim().split("\n").at(-1));
|
|
1108
|
+
return r !== null && typeof r === "object" ? r : null;
|
|
1109
|
+
} catch {
|
|
1110
|
+
return null;
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1113
|
+
|
|
1114
|
+
// reap.sh's receipt as `reaped <k>, kept <m>, worktreesRemoved <w>`, or null
|
|
1115
|
+
// for a stdout that carries none. A receipt with warnings adds `warnings
|
|
1116
|
+
// <n>: <first note>`: reap.sh exits 0 with them, and this line is the only
|
|
1117
|
+
// place an unattended tick can say so.
|
|
1118
|
+
export function reapSummary(stdout) {
|
|
1119
|
+
const r = receiptOf(stdout);
|
|
1120
|
+
if (r === null || ![r.reaped, r.kept, r.worktreesRemoved].every(Array.isArray)) return null;
|
|
1121
|
+
const warned = Array.isArray(r.warnings) ? r.warnings : [];
|
|
1122
|
+
const first = warned[0]?.note;
|
|
1123
|
+
return `reaped ${r.reaped.length}, kept ${r.kept.length}, worktreesRemoved ${r.worktreesRemoved.length}`
|
|
1124
|
+
+ (warned.length ? `, warnings ${warned.length}${typeof first === "string" ? `: ${first}` : ""}` : "");
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
// reclaim-scratch.mjs's receipt as `removed <k>, kept <m>, failed <f>`, or
|
|
1128
|
+
// null. A removal that failed is in the receipt and exits 0: it is reported
|
|
1129
|
+
// here, and the pass still counts as reclaimed after.
|
|
1130
|
+
export function reclaimSummary(stdout) {
|
|
1131
|
+
const r = receiptOf(stdout);
|
|
1132
|
+
if (r === null || ![r.removed, r.kept, r.failed].every(Array.isArray)) return null;
|
|
1133
|
+
return `removed ${r.removed.length}, kept ${r.kept.length}, failed ${r.failed.length}`;
|
|
1134
|
+
}
|
|
1135
|
+
|
|
1077
1136
|
// --------------------------------------------------------------------------
|
|
1078
1137
|
// I/O. Everything below runs only as a CLI — importing this file must never
|
|
1079
1138
|
// parse argv or touch the network, or the pure half stops being unit-testable.
|
|
1080
1139
|
|
|
1081
1140
|
import { execFileSync, spawnSync } from "node:child_process";
|
|
1082
1141
|
import { createHash } from "node:crypto";
|
|
1083
|
-
import { readFileSync } from "node:fs";
|
|
1142
|
+
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
1143
|
+
import { tmpdir } from "node:os";
|
|
1084
1144
|
import { dirname, join } from "node:path";
|
|
1085
1145
|
import { fileURLToPath } from "node:url";
|
|
1086
1146
|
import { isCLI } from "./is-cli.mjs";
|
|
1087
1147
|
import { parseArgs } from "node:util";
|
|
1088
1148
|
import { makeDie, isDigits } from "./arg.mjs";
|
|
1089
1149
|
import { gitEnv } from "./git-env.mjs";
|
|
1090
|
-
import { fleetFile, FleetDirUnresolvable } from "./fleet-dir.mjs";
|
|
1150
|
+
import { fleetFile, FleetDirUnresolvable, scratchRoot } from "./fleet-dir.mjs";
|
|
1091
1151
|
import { statePath, readState, writeState, assessBeat, isStalled, isReported, stallReport, stallOwner } from "./fleet-state.mjs";
|
|
1092
1152
|
import { checkMainCheckout, describe } from "./main-checkout.mjs";
|
|
1093
1153
|
import { readRunReceipt, phase0Gate } from "./phase0-receipt.mjs";
|
|
@@ -1150,6 +1210,13 @@ const OPTIONS = {
|
|
|
1150
1210
|
// unattended night affordable. Opt-in because folding is wrong on an edge:
|
|
1151
1211
|
// a controller that just acted needs the full rows.
|
|
1152
1212
|
"fold-unchanged": { type: "boolean", default: false },
|
|
1213
|
+
// `--apply` runs the idempotent follow-ups whose trigger the ledger and the
|
|
1214
|
+
// state file show, before the rows: reap.sh and reclaim-scratch.mjs after
|
|
1215
|
+
// every merge pass settled `done`, and tier-check.mjs on every implementer
|
|
1216
|
+
// the tick would hold as unchecked. It never dispatches, never settles a
|
|
1217
|
+
// member and writes no ledger row but through those scripts. Without it the
|
|
1218
|
+
// tick is read-only.
|
|
1219
|
+
apply: { type: "boolean", default: false },
|
|
1153
1220
|
// Path override, for tests. An empty value cannot be told from an absent one
|
|
1154
1221
|
// under parseArgs, and no path is legitimately empty, so empty resolves to
|
|
1155
1222
|
// the default.
|
|
@@ -1185,7 +1252,7 @@ function options() {
|
|
|
1185
1252
|
return {
|
|
1186
1253
|
implCap: positive("implementer-cap"), reviewerCap,
|
|
1187
1254
|
maxReviews: values["max-reviews"] === undefined ? reviewerCap : positive("max-reviews"),
|
|
1188
|
-
fold: values["fold-unchanged"], state: values.state || statePath(NAME),
|
|
1255
|
+
fold: values["fold-unchanged"], apply: values.apply, state: values.state || statePath(NAME),
|
|
1189
1256
|
liveness: Object.fromEntries(Object.entries(LIVENESS_FLAGS).map(([family, flag]) => [family, positive(flag)])),
|
|
1190
1257
|
};
|
|
1191
1258
|
}
|
|
@@ -1412,6 +1479,94 @@ function refresh() {
|
|
|
1412
1479
|
return { ok: true, ...p };
|
|
1413
1480
|
}
|
|
1414
1481
|
|
|
1482
|
+
// A sibling script --apply runs, the way refresh() runs shortlist.mjs: stdout
|
|
1483
|
+
// kept for its receipt, stderr captured so only a failure's last line rides
|
|
1484
|
+
// along. A `.mjs` runs under this node, reap.sh by its own shebang.
|
|
1485
|
+
function runSibling(file, args) {
|
|
1486
|
+
const opts = { encoding: "utf8", maxBuffer: MAX_BUFFER, stdio: ["ignore", "pipe", "pipe"] };
|
|
1487
|
+
return file.endsWith(".mjs")
|
|
1488
|
+
? spawnSync(process.execPath, [join(SCRIPT_DIR, file), ...args], opts)
|
|
1489
|
+
: spawnSync(join(SCRIPT_DIR, file), args, opts);
|
|
1490
|
+
}
|
|
1491
|
+
|
|
1492
|
+
// One duty's line: `APPLIED <label>: <receipt summary>`, or `APPLY FAILED
|
|
1493
|
+
// <duty>: <why>` for a script that did not exit 0 or printed no receipt.
|
|
1494
|
+
// True when it applied.
|
|
1495
|
+
function reportDuty(r, { label, duty, what, summarise }) {
|
|
1496
|
+
const ran = !r.error && r.status === 0;
|
|
1497
|
+
const summary = ran ? summarise(r.stdout) : null;
|
|
1498
|
+
console.log(summary !== null ? `APPLIED ${label}: ${summary}`
|
|
1499
|
+
: `APPLY FAILED ${duty}: ${ran ? `${what} printed no receipt` : failure(r, what)}`);
|
|
1500
|
+
return summary !== null;
|
|
1501
|
+
}
|
|
1502
|
+
|
|
1503
|
+
// Reap, then reclaim, after the merge passes in `due` — once however many
|
|
1504
|
+
// there are, since both sweep the whole repository and scratch root rather
|
|
1505
|
+
// than one pass's share. Reclaim runs whether or not reap did: neither reads
|
|
1506
|
+
// the other's result. True only when both applied, the one case `due` is
|
|
1507
|
+
// recorded as reaped after; otherwise the next --apply tick runs both again.
|
|
1508
|
+
function applyReap(due) {
|
|
1509
|
+
const label = `reap after ${due.map((n) => `merge-bot-${n}`).join(" ")}`;
|
|
1510
|
+
const reaped = reportDuty(runSibling("reap.sh", ["--apply"]), { label, duty: "reap", what: "reap.sh", summarise: reapSummary });
|
|
1511
|
+
let root;
|
|
1512
|
+
try {
|
|
1513
|
+
root = scratchRoot();
|
|
1514
|
+
} catch (e) {
|
|
1515
|
+
if (!(e instanceof FleetDirUnresolvable)) throw e;
|
|
1516
|
+
console.log(`APPLY FAILED reclaim: ${e.message}`);
|
|
1517
|
+
return false;
|
|
1518
|
+
}
|
|
1519
|
+
const reclaimed = reportDuty(runSibling("reclaim-scratch.mjs", ["--root", root, "--apply"]),
|
|
1520
|
+
{ label: "reclaim", duty: "reclaim", what: "reclaim-scratch.mjs", summarise: reclaimSummary });
|
|
1521
|
+
return reaped && reclaimed;
|
|
1522
|
+
}
|
|
1523
|
+
|
|
1524
|
+
// tier-check.mjs's verdict by its exit status, each one a token the check
|
|
1525
|
+
// writes on the ledger itself. Exit 2 writes nothing. Exit 1 is the check's
|
|
1526
|
+
// mismatch and also what node exits with on a throw, so it stands as a
|
|
1527
|
+
// verdict only once the ledger carries it.
|
|
1528
|
+
const TIER_VERDICTS = new Map([[0, "tier-ok"], [1, "tier-mismatch"], [3, "tier-unverifiable"]]);
|
|
1529
|
+
|
|
1530
|
+
// Whether the ledger holds tier-check.mjs's mismatch for `member`: the token
|
|
1531
|
+
// on a row, or the member itself settled `tier-mismatch`.
|
|
1532
|
+
function mismatchOnLedger(member) {
|
|
1533
|
+
const { rows, dispatched } = readLedger();
|
|
1534
|
+
return [...rows, ...dispatched].some((text) => text.split(/\s+/)
|
|
1535
|
+
.some((tok) => tok === `${member}=tier-mismatch` || tok.startsWith(`tier-mismatch=${member}:`)));
|
|
1536
|
+
}
|
|
1537
|
+
|
|
1538
|
+
// tier-check.mjs on each member, a batch of one apiece in a temporary file,
|
|
1539
|
+
// `session` the phase-0 receipt's — left out when the receipt records none,
|
|
1540
|
+
// which the check refuses by name. True when any check wrote a verdict, so
|
|
1541
|
+
// the caller reads the ledger it changed again.
|
|
1542
|
+
function applyTierChecks(members, session) {
|
|
1543
|
+
let wrote = false;
|
|
1544
|
+
for (const member of members) {
|
|
1545
|
+
const dir = mkdtempSync(join(tmpdir(), "fleet-tick-tier-"));
|
|
1546
|
+
let r;
|
|
1547
|
+
try {
|
|
1548
|
+
const batch = join(dir, "batch.json");
|
|
1549
|
+
writeFileSync(batch, JSON.stringify([session === null ? { member } : { member, session }]));
|
|
1550
|
+
r = runSibling("tier-check.mjs", ["--batch", batch]);
|
|
1551
|
+
} finally {
|
|
1552
|
+
rmSync(dir, { recursive: true, force: true });
|
|
1553
|
+
}
|
|
1554
|
+
const verdict = r.error ? undefined : TIER_VERDICTS.get(r.status);
|
|
1555
|
+
if (verdict !== undefined && (r.status !== 1 || mismatchOnLedger(member))) {
|
|
1556
|
+
wrote = true;
|
|
1557
|
+
console.log(`APPLIED tier-check ${member}: ${verdict}`);
|
|
1558
|
+
} else if (!r.error && r.status === 2) {
|
|
1559
|
+
// No verdict — most often a live member with no transcript yet — so
|
|
1560
|
+
// the hold stands, and the check's own line says why.
|
|
1561
|
+
const last = String(r.stderr ?? "").trim().split("\n").at(-1);
|
|
1562
|
+
console.log(`APPLIED tier-check ${member}: no verdict${last ? ` — ${last}` : ""}`);
|
|
1563
|
+
} else {
|
|
1564
|
+
console.log(`APPLY FAILED tier-check ${member}: ${failure(r, "tier-check.mjs")}`);
|
|
1565
|
+
}
|
|
1566
|
+
}
|
|
1567
|
+
return wrote;
|
|
1568
|
+
}
|
|
1569
|
+
|
|
1415
1570
|
// How many tickets a dead run stranded. `in-progress` is the claim label
|
|
1416
1571
|
// claim-ticket.sh adds and candidates.mjs's query EXCLUDES — which is why a
|
|
1417
1572
|
// stranded ticket is invisible to the next run's scans, and why this count is
|
|
@@ -1451,8 +1606,23 @@ function controllerState(controller) {
|
|
|
1451
1606
|
}
|
|
1452
1607
|
}
|
|
1453
1608
|
|
|
1609
|
+
// The run off the ledger, with the closed tickets and finished reviews gh
|
|
1610
|
+
// says the ledger cannot. A ledger it cannot read refuses the tick.
|
|
1611
|
+
function readRun(prs) {
|
|
1612
|
+
try {
|
|
1613
|
+
const ledger = readLedger();
|
|
1614
|
+
const run = deriveRun(ledger, prs);
|
|
1615
|
+
const closed = closedTickets(run.tierMismatch);
|
|
1616
|
+
const finished = finishedReviewPrs(run.reviewsOffList);
|
|
1617
|
+
return closed.size || finished.size ? deriveRun(ledger, prs, closed, finished) : run;
|
|
1618
|
+
} catch (e) {
|
|
1619
|
+
if (e instanceof LedgerError) die(e.message);
|
|
1620
|
+
throw e;
|
|
1621
|
+
}
|
|
1622
|
+
}
|
|
1623
|
+
|
|
1454
1624
|
function main() {
|
|
1455
|
-
const { fold, state: path, liveness, ...caps } = options();
|
|
1625
|
+
const { fold, apply, state: path, liveness, ...caps } = options();
|
|
1456
1626
|
const listPath = shortlistPath();
|
|
1457
1627
|
const current = readShortlist(listPath);
|
|
1458
1628
|
// Beside the shortlist, off the same git probe rather than a second one.
|
|
@@ -1486,18 +1656,49 @@ function main() {
|
|
|
1486
1656
|
}
|
|
1487
1657
|
|
|
1488
1658
|
// Every read happens before anything prints: a partial tick is worse than no
|
|
1489
|
-
// tick, because half a reconcile still reads like a reconcile.
|
|
1659
|
+
// tick, because half a reconcile still reads like a reconcile. The APPLIED
|
|
1660
|
+
// lines are the exception, printed as each duty runs: they say what was
|
|
1661
|
+
// done, which is true whether or not the reconcile after them lands.
|
|
1490
1662
|
const prs = openPrs();
|
|
1491
|
-
let run;
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1663
|
+
let run = readRun(prs);
|
|
1664
|
+
|
|
1665
|
+
// The main checkout against the run's baseline, on every tick — the
|
|
1666
|
+
// backstop for what member-write-guard cannot see. Never a refusal of the tick:
|
|
1667
|
+
// every answer but `clean` is a hold on the dispatching rows plus one line
|
|
1668
|
+
// saying why, so the rest of the run keeps reporting.
|
|
1669
|
+
const mainCheckout = checkMainCheckout();
|
|
1670
|
+
// This run's phase 0, off its receipt: unfinished holds the same rows the
|
|
1671
|
+
// main checkout does, and never refuses the tick either. Judged against
|
|
1672
|
+
// the controller record this tick started from, and against whether that
|
|
1673
|
+
// record's process is still there: a finished receipt of the run before
|
|
1674
|
+
// carries the same `at` until this run's rotation writes the next.
|
|
1675
|
+
const receipt = readRunReceipt();
|
|
1676
|
+
const phase0 = phase0Gate(receipt.read, {
|
|
1677
|
+
path: receipt.path, controllerAt: controller?.at, controller: controllerState(controller),
|
|
1678
|
+
});
|
|
1679
|
+
|
|
1680
|
+
if (apply) {
|
|
1681
|
+
// Reap and reclaim after every merge pass settled `done` since the last
|
|
1682
|
+
// time they ran. Recorded only once both applied, on a fresh read of the
|
|
1683
|
+
// state file so nothing the heartbeat wrote meanwhile is reverted, never
|
|
1684
|
+
// onto a file that could not be read, and never with no controller
|
|
1685
|
+
// record: nothing could tell a list recorded then from the next run's.
|
|
1686
|
+
const run0 = controller?.at ?? null;
|
|
1687
|
+
const due = reapDue(run.mergeBotDone, priorState.applied, run0);
|
|
1688
|
+
if (due.length && applyReap(due) && run0 !== null) {
|
|
1689
|
+
const now = readState(path, NAME);
|
|
1690
|
+
if (!now.degraded) {
|
|
1691
|
+
writeState(path, NAME, now, { applied: { run: run0, reapAfter: [...new Set([...reapedAfter(now.applied, run0), ...due])] } });
|
|
1692
|
+
}
|
|
1693
|
+
}
|
|
1694
|
+
// The tier check, on exactly the members the implementer row would hold
|
|
1695
|
+
// as unchecked — that row reads the same before the refresh as after it.
|
|
1696
|
+
// A verdict written changes the ledger, so the run is read again.
|
|
1697
|
+
const unchecked = tierCheckDue(reconcile({
|
|
1698
|
+
...caps, ...run, heads: unclaimed(current.entries, run), supply: current.scanned, dropped: current.dropped,
|
|
1699
|
+
shortlistStatus: current.status, refresh: null, mainCheckout, phase0, router,
|
|
1700
|
+
}), run.tierUnchecked);
|
|
1701
|
+
if (unchecked.length && applyTierChecks(unchecked, phase0.session)) run = readRun(prs);
|
|
1501
1702
|
}
|
|
1502
1703
|
|
|
1503
1704
|
// Pull from the current file first; refresh when it is short, absent, an
|
|
@@ -1529,21 +1730,6 @@ function main() {
|
|
|
1529
1730
|
}
|
|
1530
1731
|
}
|
|
1531
1732
|
|
|
1532
|
-
// The main checkout against the run's baseline, on every tick — the
|
|
1533
|
-
// backstop for what member-write-guard cannot see. Never a refusal of the tick:
|
|
1534
|
-
// every answer but `clean` is a hold on the dispatching rows plus one line
|
|
1535
|
-
// saying why, so the rest of the run keeps reporting.
|
|
1536
|
-
const mainCheckout = checkMainCheckout();
|
|
1537
|
-
// This run's phase 0, off its receipt: unfinished holds the same rows the
|
|
1538
|
-
// main checkout does, and never refuses the tick either. Judged against
|
|
1539
|
-
// the controller record this tick started from, and against whether that
|
|
1540
|
-
// record's process is still there: a finished receipt of the run before
|
|
1541
|
-
// carries the same `at` until this run's rotation writes the next.
|
|
1542
|
-
const receipt = readRunReceipt();
|
|
1543
|
-
const phase0 = phase0Gate(receipt.read, {
|
|
1544
|
-
path: receipt.path, controllerAt: controller?.at, controller: controllerState(controller),
|
|
1545
|
-
});
|
|
1546
|
-
|
|
1547
1733
|
const rows = reconcile({
|
|
1548
1734
|
...caps, ...run, heads, supply, dropped, shortlistStatus: current.status, refresh: fresh, mainCheckout, phase0, router,
|
|
1549
1735
|
});
|
|
@@ -651,22 +651,16 @@ export function expectedDefinition(rowText) {
|
|
|
651
651
|
// The agent definition a member is dispatched as, for a parsed member
|
|
652
652
|
// and the text of the row it works: `ledger.mjs dispatch` prints it so the
|
|
653
653
|
// `task` call that follows names it off a script's output, not off prose a
|
|
654
|
-
// compaction drops. A fix-applier
|
|
655
|
-
//
|
|
656
|
-
//
|
|
657
|
-
//
|
|
658
|
-
//
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
// expectedDefinition throws, and throws on a family this switch has no case
|
|
662
|
-
// for: null is the review fix-applier's deliberate answer, so a
|
|
663
|
-
// `default: return null` would print a new family as a generic `task`
|
|
664
|
-
// without anyone having decided it is one.
|
|
665
|
-
/** @returns {string|null} the definition name; null only for a review fix-applier. */
|
|
666
|
-
export function agentDefinition(member, rowText, conflictHeld = false) {
|
|
654
|
+
// compaction drops. A fix-applier is `fleet-fix-applier` for every kind of
|
|
655
|
+
// work — a review's findings, a conflict hold, a dispositions retry — whatever
|
|
656
|
+
// the row says. Throws whatever expectedDefinition throws, and throws on a
|
|
657
|
+
// family this switch has no case for: a `default` answer would print a new
|
|
658
|
+
// family as a definition without anyone having decided it is one.
|
|
659
|
+
/** @returns {string} the definition name. */
|
|
660
|
+
export function agentDefinition(member, rowText) {
|
|
667
661
|
switch (member.family) {
|
|
668
662
|
case "impl": return expectedDefinition(rowText);
|
|
669
|
-
case "fix-pr": return
|
|
663
|
+
case "fix-pr": return "fleet-fix-applier";
|
|
670
664
|
case "finisher-pr": return "fleet-finisher";
|
|
671
665
|
case "merge-bot": return "fleet-merge-bot";
|
|
672
666
|
default: throw new Error(`agentDefinition has no case for member family '${member.family}' (${member.name}) — add one to ledger-grammar.mjs`);
|
package/scripts/ledger.mjs
CHANGED
|
@@ -1877,15 +1877,17 @@ function runDispatch() {
|
|
|
1877
1877
|
// refused here, before the member is live, not discovered by the check
|
|
1878
1878
|
// after the call.
|
|
1879
1879
|
//
|
|
1880
|
-
// A fix-applier
|
|
1881
|
-
// hold,
|
|
1882
|
-
//
|
|
1883
|
-
//
|
|
1880
|
+
// A fix-applier is `fleet-fix-applier` for every kind of work — review,
|
|
1881
|
+
// conflict hold, dispositions retry — so its definition reads nothing off
|
|
1882
|
+
// the ledger.
|
|
1883
|
+
//
|
|
1884
|
+
// The finisher's gates below turn on the tick's own verdict, not a second
|
|
1885
|
+
// reading of row `i`: a PR's tokens can be split across its ticket row and
|
|
1886
|
+
// its own `#<pr>` row, and a settle can live in `## Dispatched` alone, so
|
|
1884
1887
|
// one row's text can read held where the tick reads cleared, and the
|
|
1885
1888
|
// reverse. A ledger the tick refuses is refused here too, before the member
|
|
1886
|
-
// is live
|
|
1887
|
-
//
|
|
1888
|
-
// `what` naming what could not be read off a refused ledger.
|
|
1889
|
+
// is live. `tickFold` reads that fold, `what` naming what could not be read
|
|
1890
|
+
// off a refused ledger.
|
|
1889
1891
|
const tickFold = (what) => {
|
|
1890
1892
|
try {
|
|
1891
1893
|
return deriveRun({ rows: data.rows, dispatched: data.dispatched, drain: data.drain }, []);
|
|
@@ -1894,7 +1896,6 @@ function runDispatch() {
|
|
|
1894
1896
|
die(`${e.message} — fleet-tick.mjs refuses this ledger, so ${member.name}'s ${what} cannot be read off it; fix it with \`ledger.mjs row\` before dispatching`);
|
|
1895
1897
|
}
|
|
1896
1898
|
};
|
|
1897
|
-
const held = member.family === "fix-pr" && tickFold("definition").conflictHeld.includes(member.number);
|
|
1898
1899
|
|
|
1899
1900
|
// A finisher labels its PR `ready-to-merge`, so it is recorded only once
|
|
1900
1901
|
// the PR sits on no conflict hold a fix-applier has yet to clear — a PR
|
|
@@ -1922,7 +1923,7 @@ function runDispatch() {
|
|
|
1922
1923
|
// refusal's tail names neither.
|
|
1923
1924
|
let agent;
|
|
1924
1925
|
try {
|
|
1925
|
-
agent = agentDefinition(member, i === -1 ? "" : data.rows[i]
|
|
1926
|
+
agent = agentDefinition(member, i === -1 ? "" : data.rows[i]);
|
|
1926
1927
|
if (member.family === "impl" && !existsSync(join(AGENTS_DIR, `${agent}.agent.md`))) {
|
|
1927
1928
|
throw new Error(`row #${member.number}'s tier= names ${agent}, which has no agents/${agent}.agent.md — fix the row with \`ledger.mjs row\``);
|
|
1928
1929
|
}
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
// - any subagent whose definition name starts with `fleet-`;
|
|
19
19
|
// - any subagent whose own id is a fleet member's task name (`impl-1411`,
|
|
20
20
|
// `fix-pr-88`, `review-pr-2245`, `finisher-pr-7`, with an optional `-b`
|
|
21
|
-
// recovery suffix):
|
|
22
|
-
//
|
|
21
|
+
// recovery suffix): a member named by id is caught whatever definition
|
|
22
|
+
// name its dispatch gave it;
|
|
23
23
|
// - any subagent spawned BY a fleet member: its `parentId` is the member's
|
|
24
24
|
// task name, while its own definition name is a generic one no prefix
|
|
25
25
|
// check could see.
|
|
@@ -36,7 +36,8 @@
|
|
|
36
36
|
// same set, and the checkout's HEAD besides).
|
|
37
37
|
// - `bash` cwd, for every `fleet-implementer-<cell>` (ledger-grammar.mjs's
|
|
38
38
|
// `CELL_DEF`), and for a fix-applier's own id (`fix-pr-<n>`) directly,
|
|
39
|
-
// since
|
|
39
|
+
// since its definition, `fleet-fix-applier`, is no implementer cell and
|
|
40
|
+
// `CELL_DEF` does not match it: refuse when
|
|
40
41
|
// `input.cwd ?? ctx.cwd` lies inside the main checkout outside
|
|
41
42
|
// `.worktrees/`. Command text is never parsed. Review specialists and
|
|
42
43
|
// refuters are REQUIRED to start from the inherited cwd (`pwd` first,
|
|
@@ -71,7 +72,7 @@ import { fileURLToPath } from "node:url";
|
|
|
71
72
|
import { gitEnv, workspaceDirFromGitCommonDir } from "./git-env.mjs";
|
|
72
73
|
import { CELL_DEF } from "./ledger-grammar.mjs";
|
|
73
74
|
|
|
74
|
-
/** The task names the controller gives fleet members; a subagent whose parent carries one is a member's child, and a
|
|
75
|
+
/** The task names the controller gives fleet members; a subagent whose parent carries one is a member's child, and a member whose own id matches this is caught directly, whatever definition name its dispatch gave it. */
|
|
75
76
|
const MEMBER_TASK_NAME = /^(impl|fix-pr|review-pr|finisher-pr)-\d+(-[a-z])?$/;
|
|
76
77
|
const FIX_APPLIER_ID = /^fix-pr-\d+(-[a-z])?$/;
|
|
77
78
|
const PATH_WRITERS = new Set(["write", "edit", "ast_edit"]);
|