@feigi/fleet-ctl 3.158.33 → 3.158.35

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.158.33",
3
+ "version": "3.158.35",
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": {
@@ -64,14 +64,14 @@
64
64
  // FIT. After the cost guard wrote a guard, and only then, the Router's fit
65
65
  // (`ticket-router.mjs`'s fitTree) runs in-process over the working-tree TSVs
66
66
  // the guard just read and the guard just written, with the starting table
67
- // (`router-table.json` beside the scripts) as its prior and no commit. It
67
+ // (`router-table.json` beside the scripts) as its prior. It
68
68
  // writes the Fit, `.fleet/router-fit.json`, through a temp file and a rename:
69
69
  // `computed_at`, `guard_computed_at` (the guard's own `computed_at`),
70
70
  // `guard` (the guard it used, as the router reads it: its `computed_at`,
71
71
  // `tripped`, per-Cell `n` and `window_start`), `tsv_blobs` (the git blob id of
72
72
  // each TSV it read, keyed by path as the guard keys its own), `prior` (the
73
- // starting table's `fitted_commit`, `cells`, `classifier`, `splits` and
74
- // `window_start`, and the install's `package.json` `version`), the
73
+ // starting table's `cells`, `classifier`, `splits` and `window_start`, and
74
+ // the install's `package.json` `version`), the
75
75
  // fitted `table` and `gate`, the split gate's record: a digest of the Cells
76
76
  // and Pulls it searched (`records`), the Pulls it scored and those it left
77
77
  // out for want of a recorded assignment probability, the best split it found
@@ -341,7 +341,7 @@ export function writeFit(repo, written, { tablePath = DEFAULT_TABLE, packagePath
341
341
  const members = read(MEMBERS, parseMemberTsv);
342
342
  const verdicts = read(TIERS, parseTierOutcomes);
343
343
  const features = read(FEATURES, parseFeatures);
344
- const { table, gate } = fitTree({ prior, features, members, verdicts, guard, commit: null, previous });
344
+ const { table, gate } = fitTree({ prior, features, members, verdicts, guard, previous });
345
345
  // The tree the gate grew is the one `route` will read it through.
346
346
  const valid = validateTable(table);
347
347
  if (valid instanceof Error) throw valid;
@@ -351,7 +351,6 @@ export function writeFit(repo, written, { tablePath = DEFAULT_TABLE, packagePath
351
351
  guard: { computed_at: written.computed_at, tripped: guard.tripped, n: guard.n, window_start: guard.window_start },
352
352
  tsv_blobs: Object.fromEntries(Object.entries(tsvBlobs).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))),
353
353
  prior: {
354
- fitted_commit: prior.fitted_commit,
355
354
  version: installVersion(packagePath),
356
355
  cells: prior.cells,
357
356
  classifier: prior.classifier,
@@ -1,6 +1,5 @@
1
1
  {
2
2
  "window_start": null,
3
- "fitted_commit": null,
4
3
  "n_rows": 0,
5
4
  "cells": [
6
5
  "slow-high",
@@ -40,34 +40,21 @@
40
40
  // within OMP_READ_TIMEOUT_MS, warns and leaves the Pull no Cell to draw;
41
41
  // a read that leaves a role no level to run at, or finds no implementer
42
42
  // definition, warns too.
43
- // --check --table <json> --features <tsv> --members <tsv> --verdicts <tsv>
44
- // Re-fits from the commit the table records as `fitted_commit` (an empty
45
- // corpus while it is null), against the guard snapshot the table itself
46
- // records, and exits 1 when the result is not the table: the table is a
47
- // code carrier, never hand-edited. A `fitted_commit` this repository does
48
- // not hold exits 2 naming the `git fetch` that brings it.
49
- //
50
43
  // The script never touches the network: the issue, the sizing verdict and
51
- // the guard are files the caller wrote, a fitted commit is fetched by the
52
- // caller, and the install reads ask the local `omp`.
44
+ // the guard are files the caller wrote, and the install reads ask the local `omp`.
53
45
 
54
46
  import { createHash } from "node:crypto";
55
47
  import { readFileSync, readdirSync, appendFileSync, mkdirSync, statSync, realpathSync } from "node:fs";
56
- import { spawnSync } from "node:child_process";
57
48
  import { basename, dirname, isAbsolute, join, posix, relative, resolve, sep } from "node:path";
58
49
  import { fileURLToPath } from "node:url";
59
- import { isDeepStrictEqual } from "node:util";
60
50
  import { isCLI } from "./is-cli.mjs";
61
- import { gitEnv } from "./git-env.mjs";
62
51
  import { makeDie, defineFlags, isDigits } from "./arg.mjs";
63
52
  import { CELL, OBJECTIVES, POLICY_CELL, STARTING_CELLS, drawCell, formatRouting, isRulePath, parseMember } from "./ledger-grammar.mjs";
64
53
  import { objectiveFromReceipt, sessionFromReceipt } from "./phase0-receipt.mjs";
65
- import { parseTsv as parseMemberTsv } from "./member-outcomes.mjs";
66
54
  import {
67
- AttributionError, FEATURE_COLUMNS, OPTIONAL_COLUMNS, TRIP_POINTS, attribute, compareCells, generations, parseFeatures, tally,
55
+ AttributionError, FEATURE_COLUMNS, OPTIONAL_COLUMNS, TRIP_POINTS, attribute, compareCells, generations, tally,
68
56
  } from "./pull-attribution.mjs";
69
57
  import { searchSplits, standing } from "./split-gate.mjs";
70
- import { RulingError, parseTierOutcomes } from "./tier-outcomes.mjs";
71
58
  import { LINE_REF, briefPaths, briefText } from "./ticket-text.mjs";
72
59
  import { catalogEntry, implementerCell, readOmpConfigValue, readOmpModelCatalog, resolveRole } from "./tier-roles.mjs";
73
60
 
@@ -671,9 +658,8 @@ const round4 = (x) => Math.round(x * 1e4) / 1e4;
671
658
  * routed, each to its own row's cell — restricted to rows the free classifier
672
659
  * routed plus exploration rows: a row a live B classifier routed is the A/B's
673
660
  * test set, not the fit's. The fit sees no PR state, so a Pull with
674
- * a Ruling is merged. A fit reads everything in the commit it is given: no row
675
- * is cut by date, because `--check` re-reads that same commit rather than
676
- * re-cutting the working tree's files. `order` ranks each cell's generations
661
+ * a Ruling is merged. A fit reads everything it is given: no row
662
+ * is cut by date, whatever the working tree's files hold. `order` ranks each cell's generations
677
663
  * over every Pull in the window, the restriction aside, so the fit names the
678
664
  * same newest generation the guard does. No unit is in a group yet: `book`
679
665
  * puts each where a tree walks its features row.
@@ -814,7 +800,7 @@ function judge(objective, pulls = {}, cells, tripped, baseCell) {
814
800
  const mergedOf = (c) => pullsOf(c).filter((u) => u.merged).length;
815
801
  // A default cell or base short of MIN_N merged PRs has none to give any candidate, whichever stretches they share.
816
802
  if (mergedOf(POLICY_CELL) < MIN_N || mergedOf(baseCell) < MIN_N) return record;
817
- // JSON writes −0 as 0, so a recorded end is 0 either way; `--check` compares the two.
803
+ // JSON writes −0 as 0, so a recorded end is 0 either way: normalise it here.
818
804
  const range = (m) => m.range(metric)?.map((x) => x + 0) ?? null;
819
805
  const reliablyBelow = (r) => r !== null && r[1] < 0;
820
806
  // A matched figure as the table prints one, four places; none is unknown, past every figure that is known.
@@ -888,8 +874,7 @@ function judgeSpeedRow(pulls, cells, tripped, costCell) {
888
874
  /**
889
875
  * The re-fit table, over the tree `prior.splits` holds: this makes no split
890
876
  * and takes none away (fitTree grows the tree). `guard` is `{ tripped, n, window_start }` (readGuard's
891
- * shape); `commit` is the sha of the commit the inputs were read from, or null
892
- * for the empty corpus before any fit. `rows` and `reasons` hold one set per
877
+ * shape). `rows` and `reasons` hold one set per
893
878
  * objective, and each a row or record for every node. `reasons.cost` holds
894
879
  * `judgeRow()`'s record, its `cell` the cell the node's `cost` row holds: a
895
880
  * node whose record has no cell holds its parent's `cost` row, as a ticket
@@ -902,13 +887,13 @@ function judgeSpeedRow(pulls, cells, tripped, costCell) {
902
887
  * (`guard.n`, which starts again at 0 when a role's model changes): no other
903
888
  * Cell the table holds ends it or holds it, whatever its merged PRs.
904
889
  */
905
- export function fitTable({ prior, features, members, verdicts, guard, commit = null }) {
890
+ export function fitTable({ prior, features, members, verdicts, guard }) {
906
891
  const window = guard.window_start ?? prior.window_start ?? null;
907
- return tableOver({ prior, ...fitPulls({ features, members, verdicts, window }), guard, commit, window });
892
+ return tableOver({ prior, ...fitPulls({ features, members, verdicts, window }), guard, window });
908
893
  }
909
894
 
910
895
  // The table over the tree `prior.splits` holds, from the fit's Pulls (fitPulls') booked to its groups.
911
- function tableOver({ prior, units: unbooked, order, guard, commit, window }) {
896
+ function tableOver({ prior, units: unbooked, order, guard, window }) {
912
897
  const nodes = treeNodes(prior.splits);
913
898
  const units = book(unbooked, prior);
914
899
  const { estimates, pulls } = estimate(units, order, nodes);
@@ -931,7 +916,6 @@ function tableOver({ prior, units: unbooked, order, guard, commit, window }) {
931
916
  }
932
917
  return {
933
918
  window_start: window,
934
- fitted_commit: commit,
935
919
  n_rows: units.length,
936
920
  cells: prior.cells,
937
921
  burn_in: shortStartingCells(guard.n).length > 0,
@@ -1045,45 +1029,11 @@ function growTree({ prior, units, order, tripped, previous }) {
1045
1029
  * first Fit it fails; that Fit's `gate` is the whole of what the next one reads of this.
1046
1030
  * @returns {{ table: object, gate: { records: string, scored: number, left_out: number, best: object|null, passed: string[], stands: string[] } }}
1047
1031
  */
1048
- export function fitTree({ prior, features, members, verdicts, guard, commit = null, previous = null }) {
1032
+ export function fitTree({ prior, features, members, verdicts, guard, previous = null }) {
1049
1033
  const window = guard.window_start ?? prior.window_start ?? null;
1050
1034
  const fitted = fitPulls({ features, members, verdicts, window });
1051
1035
  const { gate, splits } = growTree({ prior, ...fitted, tripped: new Set(guard.tripped), previous });
1052
- return { table: tableOver({ prior: { ...prior, splits }, ...fitted, guard, commit, window }), gate };
1053
- }
1054
-
1055
- // ---------------------------------------------------------------------------
1056
- // the commit a fit reads
1057
- // ---------------------------------------------------------------------------
1058
-
1059
- const SHA = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/;
1060
-
1061
- // `git` run in the directory holding `path`, so `path` names a file of the
1062
- // repository around it whichever directory the caller is in.
1063
- function gitBeside(path, args) {
1064
- const r = spawnSync("git", ["-C", dirname(resolve(path)), ...args], { encoding: "utf8", env: gitEnv(), maxBuffer: 1 << 30 });
1065
- if (r.error) throw r.error;
1066
- return r;
1067
- }
1068
-
1069
- /**
1070
- * The full sha `rev` names as a commit in the repository holding `path`, or null when it names none there.
1071
- * Throws when git itself fails (not a repository, unreadable config, no git): that is not an answer about `rev`.
1072
- */
1073
- export function resolveCommit(path, rev) {
1074
- if (rev.startsWith("-")) return null;
1075
- const r = gitBeside(path, ["rev-parse", "--verify", "--quiet", `${rev}^{commit}`]);
1076
- if (r.status === 0) return r.stdout.trim();
1077
- // `--verify --quiet` exits 1, silently, for a rev that names no commit; any other status is git failing.
1078
- if (r.status === 1) return null;
1079
- throw new Error(r.stderr.trim() || `git rev-parse exited ${r.status}`);
1080
- }
1081
-
1082
- /** `path` as committed at `sha`; throws when the commit does not hold it. */
1083
- export function showAt(sha, path) {
1084
- const r = gitBeside(path, ["show", `${sha}:./${basename(path)}`]);
1085
- if (r.status !== 0) throw new Error(r.stderr.trim() || `git show exited ${r.status}`);
1086
- return r.stdout;
1036
+ return { table: tableOver({ prior: { ...prior, splits }, ...fitted, guard, window }), gate };
1087
1037
  }
1088
1038
 
1089
1039
  // ---------------------------------------------------------------------------
@@ -1096,29 +1046,17 @@ function main() {
1096
1046
  flags: {
1097
1047
  session: "value", objective: "value", ticket: "value", arm: "value", "impl-row": "value", issue: "value",
1098
1048
  sizing: "value", guard: "value", table: "value", pending: "value", "chain-head": "bool", "model-roles": "value", catalog: "value", agents: "value",
1099
- features: "value", members: "value", verdicts: "value", check: "bool",
1100
1049
  },
1101
1050
  positionals: ["route"],
1102
1051
  });
1103
1052
  F.sweep();
1104
1053
  F.stray();
1105
- const argv = process.argv.slice(2);
1106
- const mode = F.has("check") ? "check" : argv.find((a) => a === "route");
1107
- if (!mode || (F.has("check") && argv.includes("route"))) {
1108
- die("usage: ticket-router.mjs route … | --check … — exactly one mode");
1109
- }
1110
- const allowed = {
1111
- route: ["session", "objective", "ticket", "arm", "impl-row", "issue", "sizing", "guard", "table", "pending", "chain-head", "model-roles", "catalog", "agents"],
1112
- check: ["check", "table", "features", "members", "verdicts"],
1113
- }[mode];
1114
- const given = argv.filter((a) => a.startsWith("--")).map((a) => a.slice(2).split("=")[0]);
1115
- const foreign = given.find((g) => !allowed.includes(g));
1116
- if (foreign) die(`--${foreign} does not apply to ${mode === "check" ? "--check" : mode}`);
1117
- const need = (name) => F.arg(name) ?? die(`${mode === "check" ? "--check" : mode} needs --${name}`);
1118
-
1119
- // `route` with no `--table` routes by the Fit beside `--guard`, else by the starting table.
1120
- const fit = mode === "route" && F.arg("table") === null && F.arg("guard") !== null ? readFitBeside(F.arg("guard")) : null;
1121
- const tablePath = mode === "route" ? (F.arg("table") ?? DEFAULT_TABLE) : need("table");
1054
+ if (!process.argv.slice(2).includes("route")) die("usage: ticket-router.mjs route …");
1055
+ const need = (name) => F.arg(name) ?? die(`route needs --${name}`);
1056
+
1057
+ // With no `--table`, routes by the Fit beside `--guard`, else by the starting table.
1058
+ const fit = F.arg("table") === null && F.arg("guard") !== null ? readFitBeside(F.arg("guard")) : null;
1059
+ const tablePath = F.arg("table") ?? DEFAULT_TABLE;
1122
1060
  let table = fit?.table ?? null;
1123
1061
  if (table === null) {
1124
1062
  try { table = JSON.parse(readFileSync(tablePath, "utf8")); } catch (e) { die(`cannot read the router table ${tablePath}: ${e.message}`); }
@@ -1126,153 +1064,101 @@ function main() {
1126
1064
  if (valid instanceof Error) die(`${tablePath}: ${valid.message}`);
1127
1065
  }
1128
1066
 
1129
- if (mode === "route") {
1130
- const ticket = need("ticket");
1131
- if (!/^[1-9][0-9]*$/.test(ticket)) die(`--ticket ${ticket} is not an issue number`);
1132
- const arm = need("arm");
1133
- if (arm !== "A" && arm !== "B") die(`--arm ${arm} is not A or B`);
1134
- const implRowArg = need("impl-row");
1135
- if (!/^[1-9][0-9]*$/.test(implRowArg)) die(`--impl-row ${implRowArg} is not a positive row count`);
1136
- const issuePath = need("issue");
1137
- const guardPath = need("guard");
1138
- // `--session` omitted is the session directory the phase-0 receipt
1139
- // records; a receipt that records none is a usage error naming it.
1140
- let sessionArg = F.arg("session");
1141
- if (sessionArg === null) {
1142
- try { sessionArg = sessionFromReceipt(); } catch (e) { die(e.message); }
1143
- }
1144
- const session = basename(sessionArg.replace(/\/+$/, ""));
1145
- // `--objective` omitted is the one the receipt records, likewise.
1146
- let objective = F.arg("objective");
1147
- if (objective === null) {
1148
- try { objective = objectiveFromReceipt(); } catch (e) { die(e.message); }
1149
- } else if (!OBJECTIVES.includes(objective)) {
1150
- die(`--objective ${objective} is not ${OBJECTIVES.join(" or ")}`);
1151
- }
1152
- // A working directory removed under the run, or an install `package.json`
1153
- // with no readable version, degrades the row and warns, never the exit.
1154
- let root = null;
1155
- try { root = process.cwd(); } catch (e) {
1156
- process.stderr.write(`${NAME}: WARNING cannot resolve the working directory: ${e.message} — every named path reads \`-\`\n`);
1157
- }
1158
- const version = installVersion();
1159
- if (version === null) process.stderr.write(`${NAME}: WARNING ${INSTALL_PACKAGE} names no readable version — plugin_version is blank\n`);
1160
- const guard = readGuard(readJson(guardPath));
1161
- const chainHead = F.has("chain-head");
1162
- // Only a Pull past burn-in that may explore reads what the install runs: its draw, or the share it ran at, needs
1163
- // the group's exploration Cells. A read that fails or does not answer in OMP_READ_TIMEOUT_MS, a `modelRoles` that
1164
- // is no record and a catalog with no `models` list leave the Pull no Cell to draw, and warn, never the exit; so
1165
- // does a read that holds nothing to draw: a role that runs at no level, or no implementer definition.
1166
- let install = null;
1167
- if (guard !== null && !table.burn_in && !chainHead) {
1168
- const warn = (what) => process.stderr.write(`${NAME}: WARNING ${what}\n`);
1169
- const agents = F.arg("agents") ?? join(SCRIPT_DIR, "..", "agents");
1170
- const kind = (v) => (v === undefined ? "absent" : v === null ? "null" : Array.isArray(v) ? "an array" : `a ${typeof v}`);
1171
- try {
1172
- const modelRoles = F.arg("model-roles") === null
1173
- ? readOmpConfigValue("modelRoles", { timeout: OMP_READ_TIMEOUT_MS })
1174
- : JSON.parse(readFileSync(F.arg("model-roles"), "utf8"));
1175
- const catalog = F.arg("catalog") === null
1176
- ? readOmpModelCatalog({ timeout: OMP_READ_TIMEOUT_MS })
1177
- : JSON.parse(readFileSync(F.arg("catalog"), "utf8"));
1178
- if (typeof modelRoles !== "object" || modelRoles === null || Array.isArray(modelRoles)) {
1179
- throw new Error(`modelRoles is ${kind(modelRoles)}, not a record of role to model`);
1180
- }
1181
- if (!Array.isArray(catalog?.models)) throw new Error(`omp's model catalog has no models list (models: ${kind(catalog?.models)})`);
1182
- install = installOf({ modelRoles, catalog, definitions: readdirSync(agents) });
1183
- } catch (e) {
1184
- warn(`cannot read what this install runs: ${e.message} — no exploration Cell is drawn`);
1185
- }
1186
- if (install !== null) {
1187
- const unrun = ROLES_BY_PRICE.filter((role) => install.ladders[role].length === 0);
1188
- if (unrun.length > 0) {
1189
- warn(`this install runs ${unrun.join(", ")} at no level (modelRoles names no model for it, or one omp's catalog lists at none) — no exploration Cell of ${unrun.length === 1 ? "that role" : "those roles"} is drawn`);
1190
- }
1191
- if (install.defined.size === 0) warn(`${agents} holds no implementer definition — no exploration Cell is drawn`);
1192
- }
1193
- }
1194
- const { line, row } = route({
1195
- session, ticket: Number(ticket), arm, implRow: Number(implRowArg), chainHead,
1196
- issue: readJson(issuePath), sizing: readJson(F.arg("sizing")), guard, table, objective, root, version,
1197
- fallback: fit?.fallback ?? null, install,
1198
- });
1199
- const pending = F.arg("pending") ?? join(dirname(guardPath), "ticket-features.pending.tsv");
1200
- // The header decision and the append are not atomic and take no lock. That is
1201
- // safe only while the run's controller is the only process that routes or
1202
- // drains on a checkout, doing both serially: one controller per checkout is
1203
- // the rule, and neither this append nor the drain checks it. A pending file
1204
- // already begun keeps its header's columns, so a plugin updated mid-run
1205
- // never appends a row wider or narrower than the file. A first line that is
1206
- // no features header — a required column missing, or a name no features
1207
- // file carries — is refused, not appended against.
1067
+ const ticket = need("ticket");
1068
+ if (!/^[1-9][0-9]*$/.test(ticket)) die(`--ticket ${ticket} is not an issue number`);
1069
+ const arm = need("arm");
1070
+ if (arm !== "A" && arm !== "B") die(`--arm ${arm} is not A or B`);
1071
+ const implRowArg = need("impl-row");
1072
+ if (!/^[1-9][0-9]*$/.test(implRowArg)) die(`--impl-row ${implRowArg} is not a positive row count`);
1073
+ const issuePath = need("issue");
1074
+ const guardPath = need("guard");
1075
+ // `--session` omitted is the session directory the phase-0 receipt
1076
+ // records; a receipt that records none is a usage error naming it.
1077
+ let sessionArg = F.arg("session");
1078
+ if (sessionArg === null) {
1079
+ try { sessionArg = sessionFromReceipt(); } catch (e) { die(e.message); }
1080
+ }
1081
+ const session = basename(sessionArg.replace(/\/+$/, ""));
1082
+ // `--objective` omitted is the one the receipt records, likewise.
1083
+ let objective = F.arg("objective");
1084
+ if (objective === null) {
1085
+ try { objective = objectiveFromReceipt(); } catch (e) { die(e.message); }
1086
+ } else if (!OBJECTIVES.includes(objective)) {
1087
+ die(`--objective ${objective} is not ${OBJECTIVES.join(" or ")}`);
1088
+ }
1089
+ // A working directory removed under the run, or an install `package.json`
1090
+ // with no readable version, degrades the row and warns, never the exit.
1091
+ let root = null;
1092
+ try { root = process.cwd(); } catch (e) {
1093
+ process.stderr.write(`${NAME}: WARNING cannot resolve the working directory: ${e.message} — every named path reads \`-\`\n`);
1094
+ }
1095
+ const version = installVersion();
1096
+ if (version === null) process.stderr.write(`${NAME}: WARNING ${INSTALL_PACKAGE} names no readable version — plugin_version is blank\n`);
1097
+ const guard = readGuard(readJson(guardPath));
1098
+ const chainHead = F.has("chain-head");
1099
+ // Only a Pull past burn-in that may explore reads what the install runs: its draw, or the share it ran at, needs
1100
+ // the group's exploration Cells. A read that fails or does not answer in OMP_READ_TIMEOUT_MS, a `modelRoles` that
1101
+ // is no record and a catalog with no `models` list leave the Pull no Cell to draw, and warn, never the exit; so
1102
+ // does a read that holds nothing to draw: a role that runs at no level, or no implementer definition.
1103
+ let install = null;
1104
+ if (guard !== null && !table.burn_in && !chainHead) {
1105
+ const warn = (what) => process.stderr.write(`${NAME}: WARNING ${what}\n`);
1106
+ const agents = F.arg("agents") ?? join(SCRIPT_DIR, "..", "agents");
1107
+ const kind = (v) => (v === undefined ? "absent" : v === null ? "null" : Array.isArray(v) ? "an array" : `a ${typeof v}`);
1208
1108
  try {
1209
- mkdirSync(dirname(pending), { recursive: true });
1210
- const had = statSync(pending, { throwIfNoEntry: false })?.size > 0 ? readFileSync(pending, "utf8").split("\n", 1)[0].split("\t") : null;
1211
- if (had !== null) {
1212
- const missing = FEATURE_COLUMNS.filter((c) => !had.includes(c) && !OPTIONAL_COLUMNS.has(c));
1213
- const unknown = had.filter((c) => !FEATURE_COLUMNS.includes(c));
1214
- if (missing.length || unknown.length) {
1215
- const why = [missing.length ? `lacks ${missing.join(", ")}` : "", unknown.length ? `names ${unknown.map((c) => JSON.stringify(c)).join(", ")}` : ""];
1216
- throw new Error(`its first line is no ticket-features header: it ${why.filter(Boolean).join(" and ")}`);
1217
- }
1109
+ const modelRoles = F.arg("model-roles") === null
1110
+ ? readOmpConfigValue("modelRoles", { timeout: OMP_READ_TIMEOUT_MS })
1111
+ : JSON.parse(readFileSync(F.arg("model-roles"), "utf8"));
1112
+ const catalog = F.arg("catalog") === null
1113
+ ? readOmpModelCatalog({ timeout: OMP_READ_TIMEOUT_MS })
1114
+ : JSON.parse(readFileSync(F.arg("catalog"), "utf8"));
1115
+ if (typeof modelRoles !== "object" || modelRoles === null || Array.isArray(modelRoles)) {
1116
+ throw new Error(`modelRoles is ${kind(modelRoles)}, not a record of role to model`);
1218
1117
  }
1219
- const header = had === null ? `${FEATURE_COLUMNS.join("\t")}\n` : "";
1220
- appendFileSync(pending, `${header}${formatFeatureRow(row, had ?? FEATURE_COLUMNS)}\n`);
1118
+ if (!Array.isArray(catalog?.models)) throw new Error(`omp's model catalog has no models list (models: ${kind(catalog?.models)})`);
1119
+ install = installOf({ modelRoles, catalog, definitions: readdirSync(agents) });
1221
1120
  } catch (e) {
1222
- process.stderr.write(`${NAME}: WARNING could not append to ${pending}: ${e.message} — this Pull's ticket-features row is not recorded\n`);
1121
+ warn(`cannot read what this install runs: ${e.message} — no exploration Cell is drawn`);
1122
+ }
1123
+ if (install !== null) {
1124
+ const unrun = ROLES_BY_PRICE.filter((role) => install.ladders[role].length === 0);
1125
+ if (unrun.length > 0) {
1126
+ warn(`this install runs ${unrun.join(", ")} at no level (modelRoles names no model for it, or one omp's catalog lists at none) — no exploration Cell of ${unrun.length === 1 ? "that role" : "those roles"} is drawn`);
1127
+ }
1128
+ if (install.defined.size === 0) warn(`${agents} holds no implementer definition — no exploration Cell is drawn`);
1223
1129
  }
1224
- process.stdout.write(`${line}\n`);
1225
- return;
1226
1130
  }
1227
-
1228
- const short = (sha) => (sha === null ? "no commit" : sha.slice(0, 8));
1229
- const fileAt = (sha, flag, parse) => {
1230
- const p = need(flag);
1231
- try { return parse(showAt(sha, p)); } catch (e) { die(`cannot read --${flag} ${p} at commit ${short(sha)}: ${e.message}`); }
1232
- };
1233
- // The three TSVs as committed at `sha`, never the working tree's copies.
1234
- const corpusAt = (sha) => ({
1235
- features: fileAt(sha, "features", parseFeatures),
1236
- members: fileAt(sha, "members", parseMemberTsv),
1237
- verdicts: fileAt(sha, "verdicts", parseTierOutcomes),
1131
+ const { line, row } = route({
1132
+ session, ticket: Number(ticket), arm, implRow: Number(implRowArg), chainHead,
1133
+ issue: readJson(issuePath), sizing: readJson(F.arg("sizing")), guard, table, objective, root, version,
1134
+ fallback: fit?.fallback ?? null, install,
1238
1135
  });
1239
- // The commit `rev` names in the repository holding --features, or null; git itself failing is a die, not "no such commit".
1240
- const commitOf = (rev) => {
1241
- try { return resolveCommit(need("features"), rev); } catch (e) { die(`cannot resolve ${rev} in the repository holding --features ${need("features")}: ${e.message}`); }
1242
- };
1243
- // The commit the table records: null before any fit, else a sha this repository holds.
1244
- const fittedCommit = () => {
1245
- const sha = table.fitted_commit;
1246
- if (sha === null) return null;
1247
- if (typeof sha !== "string" || !SHA.test(sha)) die(`${tablePath}: \`fitted_commit\` is not null or a full commit sha`);
1248
- if (commitOf(sha) === null) {
1249
- die(`${tablePath} was fitted from commit ${sha}, which this repository does not hold — run \`git fetch --depth=1 origin ${sha}\``);
1250
- }
1251
- return sha;
1252
- };
1253
- // The join throws on a features row it cannot date or whose column a split reads holds no plain count, a booked
1254
- // member row whose `cost` or `work_s` is not a number, and a ruling of a windowed Pull's ticket it cannot place —
1255
- // for `--check` too on a Pull the fit then skips as a live B classifier's, since every windowed Pull is
1256
- // booked before that skip. Anything else it throws is a bug, never bad input, so it surfaces with its stack.
1257
- const joined = (fit) => {
1258
- try { return fit(); } catch (e) {
1259
- if (!(e instanceof RulingError || e instanceof AttributionError)) throw e;
1260
- die(`cannot join --features ${need("features")}, --members ${need("members")} and --verdicts ${need("verdicts")}: ${e.message}`);
1136
+ const pending = F.arg("pending") ?? join(dirname(guardPath), "ticket-features.pending.tsv");
1137
+ // The header decision and the append are not atomic and take no lock. That is
1138
+ // safe only while the run's controller is the only process that routes or
1139
+ // drains on a checkout, doing both serially: one controller per checkout is
1140
+ // the rule, and neither this append nor the drain checks it. A pending file
1141
+ // already begun keeps its header's columns, so a plugin updated mid-run
1142
+ // never appends a row wider or narrower than the file. A first line that is
1143
+ // no features header — a required column missing, or a name no features
1144
+ // file carries — is refused, not appended against.
1145
+ try {
1146
+ mkdirSync(dirname(pending), { recursive: true });
1147
+ const had = statSync(pending, { throwIfNoEntry: false })?.size > 0 ? readFileSync(pending, "utf8").split("\n", 1)[0].split("\t") : null;
1148
+ if (had !== null) {
1149
+ const missing = FEATURE_COLUMNS.filter((c) => !had.includes(c) && !OPTIONAL_COLUMNS.has(c));
1150
+ const unknown = had.filter((c) => !FEATURE_COLUMNS.includes(c));
1151
+ if (missing.length || unknown.length) {
1152
+ const why = [missing.length ? `lacks ${missing.join(", ")}` : "", unknown.length ? `names ${unknown.map((c) => JSON.stringify(c)).join(", ")}` : ""];
1153
+ throw new Error(`its first line is no ticket-features header: it ${why.filter(Boolean).join(" and ")}`);
1154
+ }
1261
1155
  }
1262
- };
1263
-
1264
- for (const flag of ["features", "members", "verdicts"]) need(flag);
1265
- const fitted = fittedCommit();
1266
- const { features, members, verdicts } = fitted === null ? { features: [], members: [], verdicts: [] } : corpusAt(fitted);
1267
- const refit = joined(() => fitTable({ prior: table, features, members, verdicts, guard: { ...table.guard, window_start: table.window_start }, commit: fitted }));
1268
- const differ = Object.keys({ ...refit, ...table }).filter((k) => !isDeepStrictEqual(refit[k], table[k]));
1269
- if (differ.length) {
1270
- process.stderr.write(`${NAME}: ${tablePath} is not a re-fit of its own rows — differs in ${differ.map((k) => `\`${k}\``).join(", ")}; re-fitted:\n${JSON.stringify(refit, null, 2)}\n`);
1271
- // exitCode, not exit(): a piped stderr is written asynchronously and exit() can cut the payload off.
1272
- process.exitCode = 1;
1273
- return;
1156
+ const header = had === null ? `${FEATURE_COLUMNS.join("\t")}\n` : "";
1157
+ appendFileSync(pending, `${header}${formatFeatureRow(row, had ?? FEATURE_COLUMNS)}\n`);
1158
+ } catch (e) {
1159
+ process.stderr.write(`${NAME}: WARNING could not append to ${pending}: ${e.message} — this Pull's ticket-features row is not recorded\n`);
1274
1160
  }
1275
- process.stdout.write(`${NAME}: ${tablePath} matches a re-fit of ${refit.n_rows} Pulls at ${short(fitted)}\n`);
1161
+ process.stdout.write(`${line}\n`);
1276
1162
  }
1277
1163
 
1278
1164
  if (isCLI(import.meta.url)) main();