@feigi/fleet-ctl 3.160.6 → 3.161.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/package.json +1 -1
- package/scripts/baseline-cell.mjs +111 -0
- package/scripts/board-gather.mjs +17 -13
- package/scripts/cell-readout.mjs +27 -13
- package/scripts/compute-board.mjs +3 -2
- package/scripts/compute-cell-evidence.mjs +61 -49
- package/scripts/fleet-tick.mjs +19 -6
- package/scripts/ledger-grammar.mjs +30 -13
- package/scripts/ledger.mjs +3 -3
- package/scripts/metrics-refresh.mjs +36 -23
- package/scripts/phase0-receipt.mjs +39 -2
- package/scripts/phase0.mjs +108 -5
- package/scripts/pr-cost.mjs +84 -36
- package/scripts/pull.mjs +2 -2
- package/scripts/router-table.json +5 -9
- package/scripts/ticket-router.mjs +242 -143
- package/scripts/trip-reasons.mjs +47 -0
- package/skills/run-team/SKILL.md +2 -2
- package/skills/run-team/references/ledger.md +1 -1
- package/skills/run-team/references/member-lifecycle.md +1 -1
- package/skills/run-team/references/phase-0.md +21 -0
- package/skills/run-team/references/pull.md +2 -2
package/scripts/fleet-tick.mjs
CHANGED
|
@@ -520,8 +520,9 @@ function shortlistRows(s) {
|
|
|
520
520
|
}
|
|
521
521
|
|
|
522
522
|
// The cost guard's verdict, as pr-cost.mjs --guard wrote it: OK, DEFAULT-ONLY
|
|
523
|
-
// (a cell tripped, or no readable guard file — the router then
|
|
524
|
-
//
|
|
523
|
+
// (a cell tripped, or no readable guard file — the router then holds the
|
|
524
|
+
// tripped Cells back, and with no guard runs the Baseline Cell alone), or NO VERDICT (the
|
|
525
|
+
// Baseline Cell is short of its n). The
|
|
525
526
|
// controller has nothing to do about any of them inside a run, so the row
|
|
526
527
|
// never acts; it is here so the verdict is printed by code, not recalled.
|
|
527
528
|
// Every verdict carries the guard's own `computed_at`: a refresh that failed
|
|
@@ -541,8 +542,15 @@ export function routerRows(s) {
|
|
|
541
542
|
const usd = (x) => (x === null ? "n/a" : `$${x.toFixed(2)}`);
|
|
542
543
|
const vs = (c) => `${c.cell} ${usd(c.mean_usd)} vs ${usd(b.mean_usd)}, fail ${pct(c.fail_rate)} vs ${pct(b.fail_rate)}, n=${c.n}/${b.n}`;
|
|
543
544
|
if (verdict === "tripped") {
|
|
544
|
-
const retired = g.guard.retire ? "; every
|
|
545
|
-
|
|
545
|
+
const retired = g.guard.retire ? "; every starting Cell but the baseline tripped under cost — the router retires" : "";
|
|
546
|
+
// Each tripped Cell with the reasons it tripped on, and for a `minutes` trip its minutes per merged PR beside the baseline's.
|
|
547
|
+
const minutes = (x) => (typeof x === "number" ? `${x.toFixed(1)} min` : "n/a");
|
|
548
|
+
const why = (e) => {
|
|
549
|
+
const c = cells.find((x) => x.cell === e.cell);
|
|
550
|
+
const words = vs(c).replace(c.cell, tripWords(e));
|
|
551
|
+
return e.on !== null && e.on.includes("minutes") ? `${words}, ${minutes(c.mean_minutes)} vs ${minutes(b.mean_minutes)} work time per merged PR` : words;
|
|
552
|
+
};
|
|
553
|
+
return row("DEFAULT-ONLY", `cost guard: ${tripped.map(tripEntry).map(why).join("; ")}${retired}; ${age}`);
|
|
546
554
|
}
|
|
547
555
|
const others = cells.filter((c) => c.cell !== b.cell);
|
|
548
556
|
return row("OK", `${others.length ? others.map(vs).join("; ") : `baseline ${b.cell} ${usd(b.mean_usd)}, n=${b.n}`}; ${age}`);
|
|
@@ -562,10 +570,14 @@ export function costGuardFault(guard) {
|
|
|
562
570
|
if (!Array.isArray(guard.cells)) return "`cells` is not a list";
|
|
563
571
|
if (!guard.cells.every(cellShaped)) return `a \`cells\` entry is not ${cellWords}`;
|
|
564
572
|
if (!Number.isInteger(guard.min_n)) return "`min_n` is not an integer";
|
|
565
|
-
if (!Array.isArray(guard.tripped)
|
|
573
|
+
if (!Array.isArray(guard.tripped)) return "`tripped` is not a list of Cell names";
|
|
574
|
+
// A bare name is read as the tick always has; any other entry must be one trip-reasons.mjs's tripFault
|
|
575
|
+
// accepts, the router's rule for it, so a malformed `on` is a fault rather than a throw further down.
|
|
576
|
+
const entryFault = guard.tripped.map((t) => (typeof t === "string" ? null : tripFault(t))).find((why) => why !== null);
|
|
577
|
+
if (entryFault !== undefined) return entryFault;
|
|
566
578
|
// The verdict is "tripped" exactly when a cell is named, and only a reported cell can be named.
|
|
567
579
|
if ((guard.verdict === "tripped") !== (guard.tripped.length > 0)) return "`verdict` and `tripped` disagree";
|
|
568
|
-
if (!guard.tripped.every((
|
|
580
|
+
if (!guard.tripped.every((t) => guard.cells.some((x) => x.cell === tripEntry(t).cell))) return "`tripped` names a Cell that `cells` does not report";
|
|
569
581
|
if (!(guard.retire === undefined || typeof guard.retire === "boolean")) return "`retire` is not a boolean";
|
|
570
582
|
return null;
|
|
571
583
|
}
|
|
@@ -1751,6 +1763,7 @@ import { judgeRecord, ProcUnreadable } from "./proc.mjs";
|
|
|
1751
1763
|
import { reportFamily, readReport, reportPath, reportsDir } from "./report-files.mjs";
|
|
1752
1764
|
import { ownClosingIssues } from "./closing-refs.mjs";
|
|
1753
1765
|
import { GH_LOGIN_ARGS, isOwnedPr, loginOf, ownershipReadable } from "./owned-pr.mjs";
|
|
1766
|
+
import { tripEntry, tripFault, tripWords } from "./trip-reasons.mjs";
|
|
1754
1767
|
|
|
1755
1768
|
const NAME = "fleet-tick";
|
|
1756
1769
|
const SCRIPT_DIR = dirname(fileURLToPath(import.meta.url));
|
|
@@ -993,17 +993,34 @@ export function replacementName(name, rows, dispatched, retired) {
|
|
|
993
993
|
export const CELL = /^(slow|task|smol)-(minimal|low|medium|high|xhigh|max)$/;
|
|
994
994
|
export const CELL_DEF = new RegExp(`^fleet-implementer-${CELL.source.slice(1)}`);
|
|
995
995
|
|
|
996
|
-
// The
|
|
997
|
-
//
|
|
998
|
-
// Exported so
|
|
999
|
-
//
|
|
1000
|
-
export const
|
|
1001
|
-
|
|
1002
|
-
// The
|
|
1003
|
-
//
|
|
1004
|
-
//
|
|
1005
|
-
|
|
1006
|
-
|
|
996
|
+
// The Cell a row with neither `tier=` nor `cell=` runs: `slow-high`, whatever
|
|
997
|
+
// Baseline Cell routed the Pull, since a Pull whose routed Cell differs from it
|
|
998
|
+
// is written with `cell=<cell>`. Exported so every reader of a bare row maps it
|
|
999
|
+
// to the same Cell.
|
|
1000
|
+
export const BARE_ROW_CELL = "slow-high";
|
|
1001
|
+
|
|
1002
|
+
// The Baseline Cell a repository starts from until it names its own: the Cell
|
|
1003
|
+
// the router starts at, the cost guard compares every other Cell with and the
|
|
1004
|
+
// quality floor is read against.
|
|
1005
|
+
export const DEFAULT_BASELINE_CELL = "slow-high";
|
|
1006
|
+
|
|
1007
|
+
// The roles a starting set holds a Cell of, in the order its Cells are drawn
|
|
1008
|
+
// and counted: the three models.
|
|
1009
|
+
const STARTING_ROLES = Object.freeze(["slow", "task", "smol"]);
|
|
1010
|
+
|
|
1011
|
+
/**
|
|
1012
|
+
* The starting set of a Baseline Cell: its level on each of the three models,
|
|
1013
|
+
* `slow` first. The Cells burn-in draws and counts, and the Cells the Fit judges.
|
|
1014
|
+
* A Cell exploration adds is none of them, whatever its merged PRs. Exported so
|
|
1015
|
+
* ticket-router.mjs's burn-in and pr-cost.mjs's retire condition read one rule,
|
|
1016
|
+
* though neither script imports the other.
|
|
1017
|
+
* @returns {string[]}
|
|
1018
|
+
*/
|
|
1019
|
+
export function startingSetOf(baseline) {
|
|
1020
|
+
const level = CELL.exec(baseline)?.[2];
|
|
1021
|
+
if (level === undefined) throw new TypeError(`startingSetOf: ${JSON.stringify(baseline)} is not a Cell`);
|
|
1022
|
+
return STARTING_ROLES.map((role) => `${role}-${level}`);
|
|
1023
|
+
}
|
|
1007
1024
|
|
|
1008
1025
|
// The Exploration Pull's draw: uniform over every cell but
|
|
1009
1026
|
// `policyCell`, keyed off the row's own `session` and `ticket`, so the draw
|
|
@@ -1154,7 +1171,7 @@ export function parseRoutedEntry(entry) {
|
|
|
1154
1171
|
}
|
|
1155
1172
|
|
|
1156
1173
|
// The definition an implementer is dispatched under, off its ticket
|
|
1157
|
-
// row's cell token — none means `fleet-implementer-<
|
|
1174
|
+
// row's cell token — none means `fleet-implementer-<BARE_ROW_CELL>`,
|
|
1158
1175
|
// `tier=<x>` or `cell=<x>` means `fleet-implementer-<x>`. `tier=` is the
|
|
1159
1176
|
// cell a draw picked (a row carrying one is a drawn Pull, which `implRow`
|
|
1160
1177
|
// reads); `cell=` is the cell the router printed for a Pull it routed without
|
|
@@ -1202,7 +1219,7 @@ export function decidingCell(rowText) {
|
|
|
1202
1219
|
export function expectedDefinition(rowText) {
|
|
1203
1220
|
const { name, values: all } = decidingCell(rowText);
|
|
1204
1221
|
const values = [...new Set(all)];
|
|
1205
|
-
if (values.length === 0) return `fleet-implementer-${
|
|
1222
|
+
if (values.length === 0) return `fleet-implementer-${BARE_ROW_CELL}`;
|
|
1206
1223
|
if (values.length > 1) throw new Error(`row carries conflicting ${name}= tokens (${values.map((v) => `${name}=${v}`).join(", ")}) — fix the row with \`ledger.mjs row\``);
|
|
1207
1224
|
if (!TIER_SUFFIX.test(values[0])) throw new Error(`${name}=${values[0]} is not a definition suffix — expected [a-z0-9] words joined by '-' — fix the row with \`ledger.mjs row\``);
|
|
1208
1225
|
return `fleet-implementer-${values[0]}`;
|
package/scripts/ledger.mjs
CHANGED
|
@@ -74,7 +74,7 @@ import { spawnSync, execFileSync } from "node:child_process";
|
|
|
74
74
|
import { makeDie, isFlagLike, hasEqualsForm, isDigits, writeAll } from "./arg.mjs";
|
|
75
75
|
import { fleetFile, FleetDirUnresolvable } from "./fleet-dir.mjs";
|
|
76
76
|
import { readReceipt } from "./phase0-receipt.mjs";
|
|
77
|
-
import { parseMember, parseToken, memberTokens, nextMergeBot, sessionMemberNames, priorUse, replacementName, liveOnLedger, settledOnLedger, retiredOnLedger, retiredName, readRetired, agentDefinition, expectedDefinition, CELL,
|
|
77
|
+
import { parseMember, parseToken, memberTokens, nextMergeBot, sessionMemberNames, priorUse, replacementName, liveOnLedger, settledOnLedger, retiredOnLedger, retiredName, readRetired, agentDefinition, expectedDefinition, CELL, BARE_ROW_CELL, tierValues, cellValues, decidingCell, rowPr, rowNums, rowWriteRefusal, isReviewToken, addedReviewToken, isDispositionsWord, gateVerdictWriter, gateVerdictRefusal, settledMemberRefusal, newSplitRow, splitRowClause, added, premisesOf, MEMBER_FAMILIES, HALT_CAUSES, ROWS, DISPATCHED, ROUTED, FILED, RULED, DRAIN, RETIRED, RECEIPT, archiveStamp, receiptArchiveName, CLOSEOUT_RECEIPT, closeoutArchiveName, BRIEFS, briefsArchiveName, memberRole, parseDispatchedEntry, dispatchedEntry, parseRouting, parseRoutedEntry, routedEntry, headerRe, escapeText, ledgerSection, nextReviewerName, isOmpSessionDirName } from "./ledger-grammar.mjs";
|
|
78
78
|
import { deriveRun, foldLedger, liveFixers, LedgerError, labelOffMember, CONFLICT_HOLD, PARKED } from "./fleet-tick.mjs";
|
|
79
79
|
import { stateFileIn, readState, writeState, assessBeat, stallsAt } from "./fleet-state.mjs";
|
|
80
80
|
import { processSource, ancestry, controllerOf, judgeController, ProcUnreadable } from "./proc.mjs";
|
|
@@ -3507,7 +3507,7 @@ function badLabelOff(words) {
|
|
|
3507
3507
|
}
|
|
3508
3508
|
|
|
3509
3509
|
// The cell a row's implementer runs at — its `tier=`, else its `cell=`, or
|
|
3510
|
-
//
|
|
3510
|
+
// BARE_ROW_CELL on a row with neither — read the way `dispatch` reads it: null
|
|
3511
3511
|
// for a row whose deciding values conflict or name no
|
|
3512
3512
|
// agents/<definition>.agent.md, which `dispatch` refuses, so such a row has no
|
|
3513
3513
|
// draw to bind.
|
|
@@ -3549,7 +3549,7 @@ function cellChangeRefusal(oldLine, line) {
|
|
|
3549
3549
|
const cell = runnableCell(oldLine);
|
|
3550
3550
|
if (cell === null) return null;
|
|
3551
3551
|
const tiers = [...new Set(decidingCell(line).values)];
|
|
3552
|
-
const to = tiers.length === 0 ?
|
|
3552
|
+
const to = tiers.length === 0 ? BARE_ROW_CELL : tiers.join(" and ");
|
|
3553
3553
|
if (to === cell) return null;
|
|
3554
3554
|
const member = unsettledImplementer(oldLine);
|
|
3555
3555
|
if (member === null) return null;
|
|
@@ -120,11 +120,14 @@ import { gitEnv } from "./git-env.mjs";
|
|
|
120
120
|
import { FleetDirUnresolvable, fleetFile } from "./fleet-dir.mjs";
|
|
121
121
|
import { isCLI } from "./is-cli.mjs";
|
|
122
122
|
import { COLUMNS as MEMBER_COLUMNS, ENDINGS, isImplementer, parseTsv as parseMemberTsv } from "./member-outcomes.mjs";
|
|
123
|
+
import { DEFAULT_BASELINE_CELL } from "./ledger-grammar.mjs";
|
|
124
|
+
import { baselineIn } from "./phase0-receipt.mjs";
|
|
123
125
|
import { blobId } from "./pr-cost.mjs";
|
|
124
126
|
import { FEATURE_COLUMNS, parseFeatures } from "./pull-attribution.mjs";
|
|
125
127
|
import { REPORT_STATUSES } from "./report-files.mjs";
|
|
126
|
-
import { DEFAULT_TABLE, FIT_FILE, INSTALL_PACKAGE, fitTree, installVersion, readGuard, readInstall, startingCellsOf, validateTable } from "./ticket-router.mjs";
|
|
128
|
+
import { DEFAULT_TABLE, FIT_FILE, INSTALL_PACKAGE, fitBaselineOf, fitTree, installVersion, readGuard, readInstall, startingCellsOf, startingTableOf, validateTable } from "./ticket-router.mjs";
|
|
127
129
|
import { parseTierOutcomes } from "./tier-outcomes.mjs";
|
|
130
|
+
import { tripEntry, tripWords } from "./trip-reasons.mjs";
|
|
128
131
|
|
|
129
132
|
const NAME = "metrics-refresh";
|
|
130
133
|
const PR_COST = fileURLToPath(new URL("./pr-cost.mjs", import.meta.url));
|
|
@@ -285,30 +288,32 @@ function drain(repo) {
|
|
|
285
288
|
say(`drain: ${added.length} row${added.length === 1 ? "" : "s"} from ${PENDING} into ${FEATURES} (${incoming.length - added.length} already there)`);
|
|
286
289
|
}
|
|
287
290
|
|
|
288
|
-
// The guard file it wrote, parsed, or null when it skipped and wrote none.
|
|
289
|
-
function costGuard(repo) {
|
|
291
|
+
// The guard file it wrote, parsed, or null when it skipped and wrote none. `baseline` is the run's Baseline Cell.
|
|
292
|
+
function costGuard(repo, baseline) {
|
|
290
293
|
const missing = CORPUS.filter((f) => !existsSync(join(repo, f)));
|
|
291
294
|
if (missing.length) {
|
|
292
295
|
say(`cost guard: skipped, ${missing.join(", ")} not found — no corpus to guard yet; ${GUARD} left as it is`);
|
|
293
296
|
return null;
|
|
294
297
|
}
|
|
295
298
|
const out = join(repo, GUARD);
|
|
296
|
-
const r = spawnSync(process.execPath, [PR_COST, "--guard", "--out", out], {
|
|
299
|
+
const r = spawnSync(process.execPath, [PR_COST, "--guard", "--baseline-cell", baseline, "--out", out], {
|
|
297
300
|
cwd: repo, encoding: "utf8", env: gitEnv(), maxBuffer: MAX_BUFFER,
|
|
298
301
|
});
|
|
299
302
|
if (!GUARD_VERDICT_EXITS.has(r.status)) {
|
|
300
303
|
throw new Error(`pr-cost.mjs --guard exited ${r.error?.code ?? r.status ?? r.signal}: ${String(r.stderr ?? "").trim()}`);
|
|
301
304
|
}
|
|
302
305
|
const g = JSON.parse(readFileSync(out, "utf8"));
|
|
303
|
-
const tripped = g.tripped.map((t) => (
|
|
306
|
+
const tripped = g.tripped.map((t) => tripWords(tripEntry(t)));
|
|
304
307
|
say(`cost guard: verdict ${g.verdict}${tripped.length ? ` (tripped: ${tripped.join(", ")})` : ""}, pr-cost.mjs exit ${r.status}; ${GUARD} computed ${g.computed_at}`);
|
|
305
308
|
return g;
|
|
306
309
|
}
|
|
307
310
|
|
|
308
311
|
// What the last Fit that computed recorded of the split gate (its `gate`), or null where there is no such Fit to read:
|
|
309
|
-
// no file, one that will not parse,
|
|
310
|
-
// Fit that
|
|
311
|
-
|
|
312
|
+
// no file, one that will not parse, one written before the gate, or one computed under another Baseline Cell than
|
|
313
|
+
// `baseline`, the run's (a Fit that records none was computed under `slow-high`): a gate over another Cell's
|
|
314
|
+
// records says nothing of this one's. Any other failure to read the file throws, as a Fit that cannot read what it
|
|
315
|
+
// replaces cannot write it either.
|
|
316
|
+
function previousGate(repo, baseline) {
|
|
312
317
|
let text;
|
|
313
318
|
try {
|
|
314
319
|
text = readFileSync(join(repo, FIT), "utf8");
|
|
@@ -316,32 +321,37 @@ function previousGate(repo) {
|
|
|
316
321
|
if (e.code === "ENOENT") return null;
|
|
317
322
|
throw e;
|
|
318
323
|
}
|
|
324
|
+
let fit;
|
|
319
325
|
try {
|
|
320
|
-
|
|
326
|
+
fit = JSON.parse(text);
|
|
321
327
|
} catch {
|
|
322
328
|
return null;
|
|
323
329
|
}
|
|
330
|
+
const table = validateTable(fit?.table);
|
|
331
|
+
if (!(table instanceof Error) && fitBaselineOf(table) !== baseline) return null;
|
|
332
|
+
return fit?.gate ?? null;
|
|
324
333
|
}
|
|
325
334
|
|
|
326
335
|
// The Fit over `repo`'s working-tree TSVs and `written`, the guard file the
|
|
327
336
|
// guard duty just wrote (parsed), with the router table at `tablePath` as its
|
|
328
|
-
// prior,
|
|
329
|
-
//
|
|
330
|
-
//
|
|
337
|
+
// prior, filled in for `baseline`, the run's Baseline Cell (`slow-high` when none is named), written to
|
|
338
|
+
// `.fleet/router-fit.json` through a temp file and a rename.
|
|
339
|
+
// Burn-in counts `startingCells`, the starting Cells the install runs — the whole starting set of
|
|
340
|
+
// `baseline` when none is named — which the Fit's `table` records. Throws on anything
|
|
331
341
|
// it cannot read, fit or write, before the rename, so the
|
|
332
342
|
// old file stays as it was: a Fit that throws is no look at the split gate,
|
|
333
343
|
// and the next one reads the gate the old file holds.
|
|
334
|
-
export function writeFit(repo, written, { tablePath = DEFAULT_TABLE, packagePath = INSTALL_PACKAGE, now = new Date(), startingCells } = {}) {
|
|
344
|
+
export function writeFit(repo, written, { tablePath = DEFAULT_TABLE, packagePath = INSTALL_PACKAGE, now = new Date(), baseline = DEFAULT_BASELINE_CELL, startingCells } = {}) {
|
|
335
345
|
const guard = readGuard(written);
|
|
336
346
|
if (guard === null) throw new Error(`${GUARD} is not a guard the router reads`);
|
|
337
347
|
let prior;
|
|
338
348
|
try {
|
|
339
|
-
prior = validateTable(JSON.parse(readFileSync(tablePath, "utf8")));
|
|
349
|
+
prior = validateTable(startingTableOf(JSON.parse(readFileSync(tablePath, "utf8")), baseline));
|
|
340
350
|
} catch (e) {
|
|
341
351
|
throw new Error(`cannot read the starting router table ${tablePath}: ${e.code ?? e.message}`);
|
|
342
352
|
}
|
|
343
353
|
if (prior instanceof Error) throw new Error(`${tablePath}: ${prior.message}`);
|
|
344
|
-
const previous = previousGate(repo);
|
|
354
|
+
const previous = previousGate(repo, baseline);
|
|
345
355
|
// Keyed by the path as the guard keys its own (pr-cost.mjs reads these, relative to the workspace).
|
|
346
356
|
const tsvBlobs = {};
|
|
347
357
|
const read = (rel, parse) => {
|
|
@@ -352,14 +362,14 @@ export function writeFit(repo, written, { tablePath = DEFAULT_TABLE, packagePath
|
|
|
352
362
|
const members = read(MEMBERS, parseMemberTsv);
|
|
353
363
|
const verdicts = read(TIERS, parseTierOutcomes);
|
|
354
364
|
const features = read(FEATURES, parseFeatures);
|
|
355
|
-
const { table, gate } = fitTree({ prior, features, members, verdicts, guard, previous, startingCells });
|
|
365
|
+
const { table, gate } = fitTree({ prior, features, members, verdicts, guard, previous, baseline, startingCells });
|
|
356
366
|
// The tree the gate grew is the one `route` will read it through.
|
|
357
367
|
const valid = validateTable(table);
|
|
358
368
|
if (valid instanceof Error) throw valid;
|
|
359
369
|
const record = {
|
|
360
370
|
computed_at: now.toISOString(),
|
|
361
371
|
guard_computed_at: written.computed_at,
|
|
362
|
-
guard: { computed_at: written.computed_at, tripped: guard.tripped, n: guard.n, window_start: guard.window_start },
|
|
372
|
+
guard: { computed_at: written.computed_at, tripped: guard.tripped, n: guard.n, shared: guard.shared, window_start: guard.window_start },
|
|
363
373
|
tsv_blobs: Object.fromEntries(Object.entries(tsvBlobs).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))),
|
|
364
374
|
prior: {
|
|
365
375
|
version: installVersion(packagePath),
|
|
@@ -380,16 +390,17 @@ export function writeFit(repo, written, { tablePath = DEFAULT_TABLE, packagePath
|
|
|
380
390
|
// The Fit as the run calls it: only beside a guard the guard duty wrote, and
|
|
381
391
|
// never a failure of the run — its error is a line, and the exit stays as it was.
|
|
382
392
|
// `sources` name the files the install read takes in place of omp's own (ticket-router.mjs's
|
|
383
|
-
// readInstall): burn-in counts the starting Cells that install runs,
|
|
384
|
-
|
|
393
|
+
// readInstall): burn-in counts the starting Cells that install runs, the whole starting set of
|
|
394
|
+
// `baseline` when it cannot be read.
|
|
395
|
+
function fit(repo, written, sources, baseline) {
|
|
385
396
|
if (written === null) return say(`fit: skipped, no guard written — ${FIT} left as it is`);
|
|
386
397
|
const { install, why } = readInstall(sources);
|
|
387
398
|
if (install === null) {
|
|
388
|
-
process.stderr.write(`${NAME}: WARNING cannot read what this install runs: ${why} — burn-in counts
|
|
399
|
+
process.stderr.write(`${NAME}: WARNING cannot read what this install runs: ${why} — burn-in counts every starting Cell of ${baseline}\n`);
|
|
389
400
|
}
|
|
390
401
|
let p;
|
|
391
402
|
try {
|
|
392
|
-
p = writeFit(repo, written, { startingCells: startingCellsOf(install) });
|
|
403
|
+
p = writeFit(repo, written, { baseline, startingCells: startingCellsOf(install, baseline) });
|
|
393
404
|
} catch (e) {
|
|
394
405
|
return say(`fit: failed — ${e.message}`);
|
|
395
406
|
}
|
|
@@ -410,10 +421,12 @@ function main() {
|
|
|
410
421
|
die(`${e.message} — pass --repo <dir>`);
|
|
411
422
|
}
|
|
412
423
|
}
|
|
424
|
+
// The run's Baseline Cell, once: the receipt's, else the saved value, else `slow-high`.
|
|
425
|
+
const baseline = baselineIn(join(repo, ".fleet")).cell;
|
|
413
426
|
let written = null;
|
|
414
427
|
for (const [name, duty] of [["drain", drain], ["member-outcomes", widenMemberOutcomes], ["cost guard", costGuard]]) {
|
|
415
428
|
try {
|
|
416
|
-
const out = duty(repo);
|
|
429
|
+
const out = duty(repo, baseline);
|
|
417
430
|
if (duty === costGuard) written = out;
|
|
418
431
|
} catch (e) {
|
|
419
432
|
process.stderr.write(`${NAME}: ${name} failed: ${e.message}\n`);
|
|
@@ -421,7 +434,7 @@ function main() {
|
|
|
421
434
|
return;
|
|
422
435
|
}
|
|
423
436
|
}
|
|
424
|
-
if (!F.has("no-fit")) fit(repo, written, { modelRoles: F.arg("model-roles"), catalog: F.arg("catalog") });
|
|
437
|
+
if (!F.has("no-fit")) fit(repo, written, { modelRoles: F.arg("model-roles"), catalog: F.arg("catalog") }, baseline);
|
|
425
438
|
}
|
|
426
439
|
|
|
427
440
|
if (isCLI(import.meta.url)) main();
|
|
@@ -11,9 +11,10 @@
|
|
|
11
11
|
// Zero deps: node builtins and sibling modules only.
|
|
12
12
|
|
|
13
13
|
import { readFileSync } from "node:fs";
|
|
14
|
-
import { join } from "node:path";
|
|
14
|
+
import { dirname, join } from "node:path";
|
|
15
|
+
import { readSavedBaseline } from "./baseline-cell.mjs";
|
|
15
16
|
import { fleetFile, FleetDirUnresolvable } from "./fleet-dir.mjs";
|
|
16
|
-
import { OBJECTIVES, RECEIPT } from "./ledger-grammar.mjs";
|
|
17
|
+
import { CELL, DEFAULT_BASELINE_CELL, OBJECTIVES, RECEIPT } from "./ledger-grammar.mjs";
|
|
17
18
|
|
|
18
19
|
const isRecord = (x) => x !== null && typeof x === "object" && !Array.isArray(x);
|
|
19
20
|
|
|
@@ -166,6 +167,42 @@ export function objectiveFromReceipt(opts) {
|
|
|
166
167
|
throw new Error(`no objective given and none in the phase-0 receipt ${path} (${why}) — give one (${OBJECTIVES.join(" or ")}), or run ${phase0Command(null)} first`);
|
|
167
168
|
}
|
|
168
169
|
|
|
170
|
+
/**
|
|
171
|
+
* The run's Baseline Cell as its readers take it, `{ cell, source }`, off `read` (readReceipt's or readRunReceipt()'s
|
|
172
|
+
* `read`) and `fleetDir`, the `.fleet/` the saved value is in: the receipt's `baselineCell`, which phase 0 resolved
|
|
173
|
+
* once for the run — DEFAULT_BASELINE_CELL for a receipt that records none, as phase 0 resumes one — else, with no
|
|
174
|
+
* receipt to read, the saved value, else DEFAULT_BASELINE_CELL. Never throws, and never refuses: a reader that
|
|
175
|
+
* cannot be told the Cell runs the default.
|
|
176
|
+
*/
|
|
177
|
+
export function baselineOf(read, fleetDir) {
|
|
178
|
+
if (read.state === "ok") {
|
|
179
|
+
const recorded = read.receipt.baselineCell;
|
|
180
|
+
if (typeof recorded === "string" && CELL.test(recorded)) return { cell: recorded, source: "the receipt" };
|
|
181
|
+
if (recorded === undefined) return { cell: DEFAULT_BASELINE_CELL, source: "the default (the receipt records none)" };
|
|
182
|
+
}
|
|
183
|
+
const saved = fleetDir === null ? { state: "none" } : readSavedBaseline(fleetDir);
|
|
184
|
+
return saved.state === "ok" ? { cell: saved.cell, source: "the saved value" } : { cell: DEFAULT_BASELINE_CELL, source: "the default" };
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** baselineOf over the receipt and saved value in `fleetDir`, a `.fleet/` directory. */
|
|
188
|
+
export const baselineIn = (fleetDir) => baselineOf(readReceipt(join(fleetDir, RECEIPT)), fleetDir);
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* The Baseline Cell for a reader whose own flag was omitted, resolved the way `sessionFromReceipt` resolves the
|
|
192
|
+
* receipt: `{ cell, source }`, baselineOf's, over the run's `.fleet/`. Never throws: where the workspace cannot be
|
|
193
|
+
* resolved — a working directory removed under the run included — it is the default, since a Cell is no reason
|
|
194
|
+
* for a reader to refuse.
|
|
195
|
+
*/
|
|
196
|
+
export function baselineCellFromReceipt(opts) {
|
|
197
|
+
let fleetDir;
|
|
198
|
+
try {
|
|
199
|
+
fleetDir = dirname(fleetFile(RECEIPT, opts));
|
|
200
|
+
} catch {
|
|
201
|
+
return { cell: DEFAULT_BASELINE_CELL, source: "the default (no workspace)" };
|
|
202
|
+
}
|
|
203
|
+
return baselineIn(fleetDir);
|
|
204
|
+
}
|
|
205
|
+
|
|
169
206
|
// Whether a run's merge bot merges when nobody says: phase0.mjs records the
|
|
170
207
|
// run's choice in its receipt as `merge`, and a receipt written before it
|
|
171
208
|
// recorded one is read as the default when phase 0 resumes it.
|
package/scripts/phase0.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// Phase 0 as one command: the run's start sequence, in order, with a receipt.
|
|
3
3
|
//
|
|
4
|
-
// phase0.mjs [--session <dir>] [--in-flight n] [--objective cost|speed]
|
|
4
|
+
// phase0.mjs [--session <dir>] [--in-flight n] [--objective cost|speed] [--baseline-cell <cell>]
|
|
5
5
|
// [--merge | --no-merge] [--spend-dir <dir>]
|
|
6
6
|
// [--workflow <name> | --declare-no-ci]
|
|
7
7
|
//
|
|
@@ -125,7 +125,7 @@
|
|
|
125
125
|
// THE RECEIPT is `.fleet/phase0.json` (resolved through fleet-dir.mjs, so a
|
|
126
126
|
// worktree and the main checkout name one file):
|
|
127
127
|
//
|
|
128
|
-
// { run, session, scratch, inFlight, objective, merge, pluginVersion,
|
|
128
|
+
// { run, session, scratch, inFlight, objective, baselineCell, merge, pluginVersion,
|
|
129
129
|
// steps: { <name>: { status, at, output } } }
|
|
130
130
|
//
|
|
131
131
|
// `status` is ok, pending, failed, drift or unanswered; `at` an ISO time;
|
|
@@ -142,6 +142,30 @@
|
|
|
142
142
|
// default when it records none — and a resume whose `--objective` names the
|
|
143
143
|
// other one exits 2 naming both, leaving the receipt as it was. A resumed
|
|
144
144
|
// receipt recording a value that is not an Objective exits 3 naming it.
|
|
145
|
+
// `baselineCell` is the run's Baseline Cell, the Cell the router starts from, the
|
|
146
|
+
// cost guard compares every other Cell with and the quality floor reads, worked
|
|
147
|
+
// out once, when the receipt is written: `--baseline-cell` when it is valid
|
|
148
|
+
// (a Cell with an implementer definition), else the value saved in
|
|
149
|
+
// `.fleet/baseline-cell.json`, else `slow-high`. A valid argument is saved and
|
|
150
|
+
// binds every later run until a run names another; `--baseline-cell slow-high`
|
|
151
|
+
// goes back to the default. Phase 0 never refuses a Baseline Cell argument or
|
|
152
|
+
// saved value and never asks about it: an invalid argument is a notice, is not
|
|
153
|
+
// saved, and the run goes on to the saved value; an invalid saved value is a
|
|
154
|
+
// notice, the run uses `slow-high` and the file is left as it is; implementer
|
|
155
|
+
// definitions that cannot be listed are a notice naming that as the cause. A
|
|
156
|
+
// Baseline Cell the install cannot run is replaced for the run by the nearest
|
|
157
|
+
// level of its role the install runs and has a definition for
|
|
158
|
+
// (ticket-router.mjs's defaultCellOf), a notice naming both Cells, the saved
|
|
159
|
+
// value unchanged. Every phase 0 prints the Baseline Cell it runs and where it
|
|
160
|
+
// came from, and a notice when it differs from the one the last cost guard
|
|
161
|
+
// recorded: a switch, after which the guard and the Fit compare a Cell with the
|
|
162
|
+
// Baseline Cell only over the stretches both were drawn in; a last cost guard
|
|
163
|
+
// that is there but cannot be read is a notice that whether it is a switch is
|
|
164
|
+
// not known. A resumed receipt keeps its `baselineCell` — `slow-high` when it
|
|
165
|
+
// records none — for the
|
|
166
|
+
// rest of the run, since the guard and the Fit its `metrics` step computed
|
|
167
|
+
// stand; a valid argument is still saved, and a notice says it applies from the
|
|
168
|
+
// next run. A resumed receipt recording a value that is no Cell exits 3 naming it.
|
|
145
169
|
// `merge` is whether the run's merge bot merges: `false` under `--no-merge`,
|
|
146
170
|
// `true` under `--merge` or with neither (MERGE_DEFAULT in
|
|
147
171
|
// phase0-receipt.mjs). `--merge` and `--no-merge` together exit 2. Like the
|
|
@@ -213,9 +237,11 @@ import { readState, stateFileIn } from "./fleet-state.mjs";
|
|
|
213
237
|
import { gitEnv } from "./git-env.mjs";
|
|
214
238
|
import { isCLI } from "./is-cli.mjs";
|
|
215
239
|
import { GH_LOGIN_ARGS, isOwnedPr, loginOf, ownershipReadable } from "./owned-pr.mjs";
|
|
216
|
-
import { OBJECTIVES, RECEIPT, RECEIPT_HELD, archiveStamp, receiptArchiveName, rowNums } from "./ledger-grammar.mjs";
|
|
240
|
+
import { CELL, DEFAULT_BASELINE_CELL, OBJECTIVES, RECEIPT, RECEIPT_HELD, archiveStamp, receiptArchiveName, rowNums } from "./ledger-grammar.mjs";
|
|
217
241
|
import { ancestry, controllerOf, processSource, ProcUnreadable } from "./proc.mjs";
|
|
218
242
|
import { IN_FLIGHT_DEFAULT, MERGE_DEFAULT, OBJECTIVE_DEFAULT } from "./phase0-receipt.mjs";
|
|
243
|
+
import { definedCells, isBaselineCell, readSavedBaseline, resolveBaselineCell, saveBaseline } from "./baseline-cell.mjs";
|
|
244
|
+
import { defaultCellOf, readInstall } from "./ticket-router.mjs";
|
|
219
245
|
import { readRecipe } from "./recipe-read.mjs";
|
|
220
246
|
import { gather, recordChanges, refusedLine, unclosedRecords } from "./run-records.mjs";
|
|
221
247
|
|
|
@@ -711,11 +737,77 @@ function writeReceipt(path, receipt) {
|
|
|
711
737
|
|
|
712
738
|
const capped = (s) => (s.length > OUTPUT_MAX ? `…${s.slice(-(OUTPUT_MAX - 1))}` : s);
|
|
713
739
|
|
|
740
|
+
// The Cell the last cost guard recorded as its baseline: `{ cell, why }`, `cell` null when there is no guard or it
|
|
741
|
+
// records none, and `why` saying so when the guard is there but cannot be read or parsed.
|
|
742
|
+
function guardBaseline(fleetDir) {
|
|
743
|
+
const file = join(fleetDir, "cost-guard.json");
|
|
744
|
+
let text;
|
|
745
|
+
try {
|
|
746
|
+
text = readFileSync(file, "utf8");
|
|
747
|
+
} catch (e) {
|
|
748
|
+
return { cell: null, why: e.code === "ENOENT" ? null : `${file} cannot be read (${e.code ?? e.message})` };
|
|
749
|
+
}
|
|
750
|
+
let guard;
|
|
751
|
+
try { guard = JSON.parse(text); } catch { return { cell: null, why: `${file} is not JSON` }; }
|
|
752
|
+
const cell = guard?.baseline?.cell;
|
|
753
|
+
return { cell: typeof cell === "string" ? cell : null, why: null };
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
/**
|
|
757
|
+
* The run's Baseline Cell, worked out once: `{ cell, source, notices }`. A new run resolves it
|
|
758
|
+
* (baseline-cell.mjs's resolveBaselineCell) off `named`, `--baseline-cell`'s value or null, the value saved in
|
|
759
|
+
* `fleetDir` and what the install runs, and saves a valid argument. A resumed run keeps its receipt's
|
|
760
|
+
* (`slow-high` when it records none), since the guard and the Fit its `metrics` step computed stand; a valid
|
|
761
|
+
* argument is still saved, and a notice says it applies from the next run. Never refuses and never asks: what it
|
|
762
|
+
* has to say is a notice, among them that the Cell differs from the one the last cost guard recorded, a switch.
|
|
763
|
+
*/
|
|
764
|
+
function baselineCellOf({ resumed, previous, named, fleetDir }) {
|
|
765
|
+
const { cells: defined, why: unlisted } = definedCells();
|
|
766
|
+
const saved = readSavedBaseline(fleetDir, defined);
|
|
767
|
+
const save = (cell) => {
|
|
768
|
+
try {
|
|
769
|
+
saveBaseline(fleetDir, cell);
|
|
770
|
+
return null;
|
|
771
|
+
} catch (e) {
|
|
772
|
+
return `could not save ${cell} as the Baseline Cell (${e.code ?? e.message}): it binds this run only`;
|
|
773
|
+
}
|
|
774
|
+
};
|
|
775
|
+
let result;
|
|
776
|
+
if (resumed) {
|
|
777
|
+
const cell = previous.baselineCell ?? DEFAULT_BASELINE_CELL;
|
|
778
|
+
result = { cell, source: "this run's receipt", notices: [] };
|
|
779
|
+
if (named !== null && !isBaselineCell(named, defined)) {
|
|
780
|
+
result.notices.push(`--baseline-cell ${JSON.stringify(named)} is not a Cell with an implementer definition: ignored, and not saved`);
|
|
781
|
+
} else if (named !== null && !(saved.state === "ok" && saved.cell === named)) {
|
|
782
|
+
const failed = save(named);
|
|
783
|
+
result.notices.push(failed ?? `--baseline-cell ${named} is saved and applies from the next run: this run keeps ${cell}, as its receipt records`);
|
|
784
|
+
}
|
|
785
|
+
} else {
|
|
786
|
+
// What the install runs is read live, as `route` reads it; a read that fails leaves the configured Cell.
|
|
787
|
+
const { install } = readInstall();
|
|
788
|
+
const resolved = resolveBaselineCell({ arg: named, saved, defined, substitute: (cell) => (install === null ? cell : defaultCellOf(install, cell)) });
|
|
789
|
+
result = { cell: resolved.cell, source: resolved.source, notices: resolved.notices };
|
|
790
|
+
if (resolved.save !== null) {
|
|
791
|
+
const failed = save(resolved.save);
|
|
792
|
+
if (failed !== null) result.notices.push(failed);
|
|
793
|
+
}
|
|
794
|
+
}
|
|
795
|
+
// Listed first: the notices after it blame a value for what is the install's.
|
|
796
|
+
if (unlisted !== null) result.notices.unshift(`the implementer definitions cannot be listed (${unlisted}): no Cell counts as having one, so this run takes no --baseline-cell or saved value`);
|
|
797
|
+
const last = guardBaseline(fleetDir);
|
|
798
|
+
if (last.why !== null) {
|
|
799
|
+
result.notices.push(`the last cost guard cannot be read (${last.why}): whether this run's ${result.cell} is a switch is not known`);
|
|
800
|
+
} else if (last.cell !== null && last.cell !== result.cell) {
|
|
801
|
+
result.notices.push(`the last cost guard recorded ${last.cell} as its baseline: this run's ${result.cell} is a switch — no trip carries across it, every Cell not drawn beside ${result.cell} is unjudged, and burn-in resumes until the starting set is judged against it`);
|
|
802
|
+
}
|
|
803
|
+
return result;
|
|
804
|
+
}
|
|
805
|
+
|
|
714
806
|
function main() {
|
|
715
807
|
const die = makeDie(NAME);
|
|
716
808
|
const F = defineFlags(die, {
|
|
717
809
|
flags: {
|
|
718
|
-
session: "value", "in-flight": "value", objective: "value", merge: "bool", "no-merge": "bool",
|
|
810
|
+
session: "value", "in-flight": "value", objective: "value", "baseline-cell": "value", merge: "bool", "no-merge": "bool",
|
|
719
811
|
"spend-dir": "value", workflow: "value", "declare-no-ci": "bool",
|
|
720
812
|
},
|
|
721
813
|
});
|
|
@@ -836,6 +928,15 @@ function main() {
|
|
|
836
928
|
die(`${flag(mergeNamed)}: this run's receipt ${receiptPath} records ${keptMerge ? "merge" : "no-merge"}, fixed for the run — run phase 0 again without ${flag(mergeNamed)}, or with ${flag(keptMerge)}`);
|
|
837
929
|
}
|
|
838
930
|
const merge = keptMerge ?? mergeNamed ?? MERGE_DEFAULT;
|
|
931
|
+
// The Baseline Cell is fixed for the run the same way: a resumed receipt's stands, and one that records none
|
|
932
|
+
// resumes as `slow-high`. One recording anything but a Cell is refused. It never refuses and never asks
|
|
933
|
+
// otherwise: what it has to say is a notice.
|
|
934
|
+
if (resumed && previous.baselineCell !== undefined && !(typeof previous.baselineCell === "string" && CELL.test(previous.baselineCell))) {
|
|
935
|
+
process.stderr.write(`${NAME}: this run's receipt ${receiptPath} records the Baseline Cell ${JSON.stringify(previous.baselineCell)}, which is not a Cell — set it to the Cell this run began with and re-run\n`);
|
|
936
|
+
process.exitCode = 3;
|
|
937
|
+
return;
|
|
938
|
+
}
|
|
939
|
+
const baseline = baselineCellOf({ resumed, previous, named: F.arg("baseline-cell"), fleetDir });
|
|
839
940
|
if (rotated && !resumed) {
|
|
840
941
|
if (existsSync(held)) {
|
|
841
942
|
process.stderr.write(`${NAME}: cannot hold the previous run's receipt for the rotation: ${held} already holds another\n`);
|
|
@@ -846,7 +947,7 @@ function main() {
|
|
|
846
947
|
}
|
|
847
948
|
|
|
848
949
|
const pluginVersion = resumed && typeof previous.pluginVersion === "string" ? previous.pluginVersion : null;
|
|
849
|
-
const receipt = { run: resumed ? previous.run : null, session, scratch, inFlight, objective, merge, pluginVersion, steps: {} };
|
|
950
|
+
const receipt = { run: resumed ? previous.run : null, session, scratch, inFlight, objective, baselineCell: baseline.cell, merge, pluginVersion, steps: {} };
|
|
850
951
|
for (const name of STEP_NAMES) {
|
|
851
952
|
// `alarm` checks the omp running this invocation, so its `ok` is never carried.
|
|
852
953
|
const was = resumed && name !== "alarm" ? previous.steps[name] : undefined;
|
|
@@ -856,6 +957,8 @@ function main() {
|
|
|
856
957
|
const ctx = { cwd, fleetDir, held, receipt, receiptPath, scratch, spendDir, ci };
|
|
857
958
|
const say = (line) => process.stdout.write(`${line}\n`);
|
|
858
959
|
say(`session ${session} (from ${source})`);
|
|
960
|
+
say(`baseline cell ${baseline.cell} (from ${baseline.source})`);
|
|
961
|
+
for (const notice of baseline.notices) say(`notice: ${notice}`);
|
|
859
962
|
let stop = null;
|
|
860
963
|
for (const name of STEP_NAMES) {
|
|
861
964
|
if (receipt.steps[name].status === "ok") {
|