@feigi/fleet-ctl 3.143.5 → 3.144.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@feigi/fleet-ctl",
3
- "version": "3.143.5",
3
+ "version": "3.144.0",
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": {
@@ -111,7 +111,7 @@
111
111
  .ce-row { display:grid; gap:12px; border-top:1px solid var(--line); padding:6px 0; font-size:12px; }
112
112
  .ce-row a { color:var(--blue); text-decoration:none; }
113
113
  .ce-cand { color:var(--dim); margin-left:10px; }
114
- .ce-stratum { font-weight:600; }
114
+ .ce-stratum { font-weight:600; overflow-wrap:anywhere; }
115
115
  .ce-obj { margin-top:10px; }
116
116
  .ce.flash { animation:flash 1.2s ease-out 1; }
117
117
  .spend-wrap { background:var(--panel); border:1px solid var(--line); border-radius:8px; padding:10px 12px; }
@@ -172,7 +172,7 @@ function boardTitle(repo) { return repo ? `${TITLE} — ${repo}` : TITLE; }
172
172
  // Every hash the page draws is a tab (`#board`, `#cells`, `#tokens`), a card on
173
173
  // the Board (`#board/<issue>`, the issue number as a string) or a place on Cell
174
174
  // evidence: a section (`#cells/rows`, `#cells/guard`, `#cells/declared`), a policy
175
- // row (`#cells/row/<objective>/<stratum>`, the stratum `*` or one of the three), a
175
+ // row (`#cells/row/<objective>/<stratum>`, the stratum `*` or a group's rule path), a
176
176
  // Cell (`#cells/<cell>`) or one of its generations (`#cells/<cell>@<generation>`).
177
177
  // Anything else — no hash, a tab the page does not have, a target the tab does
178
178
  // not have — lands on Board's top, or the named tab's top, never on a blank
@@ -182,8 +182,13 @@ function routeHash(hash) {
182
182
  if (tab === "board") return { tab, target: more.length === 0 && /^[1-9]\d*$/.test(target) ? target : null };
183
183
  if (tab === "cells") {
184
184
  if (target === "row") {
185
- const [objective, stratum] = more;
186
- const ok = more.length === 2 && /^(cost|speed)$/.test(objective) && /^(\*|light|heavy|unknown)$/.test(stratum);
185
+ // The stratum is a rule path, as the ledger grammar reads one: `*`, or tests joined by `&`, each an input
186
+ // and a comparison. A browser hands a fragment back percent-encoded, `<` and `>` among what it encodes.
187
+ const [objective, encoded] = more;
188
+ let stratum = "";
189
+ try { stratum = decodeURIComponent(encoded ?? ""); } catch { /* an escape that decodes to nothing names no row */ }
190
+ const test = "[a-z][a-z_]*(?:(?:>|<=)(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?|!?=[a-z]+)";
191
+ const ok = more.length === 2 && /^(cost|speed)$/.test(objective) && new RegExp(`^(?:\\*|${test}(?:&${test})*)$`).test(stratum);
187
192
  return { tab, target: ok ? `row/${objective}/${stratum}` : null };
188
193
  }
189
194
  const place = /^(rows|guard|declared|(slow|task|smol)-(minimal|low|medium|high|xhigh|max)(@[^\s/@]+)?)$/;
@@ -494,16 +499,11 @@ function cePolicyCell(s, href) {
494
499
  return box;
495
500
  }
496
501
 
497
- // One line of the policy rows: a Stratum's row across every side, or the one
498
- // line a Stratum with no row of its own collapses to. Either way it is a place
502
+ // One line of the policy rows: a group's row across every side. It is a place
499
503
  // `#cells/row/<objective>/<stratum>` lands on.
500
504
  function cePolicyLine(line) {
501
505
  const box = ceBox("div", "ce-row", line.anchor);
502
- if (line.collapsed) {
503
- box.append(el("span", "ce-dim", line.collapsed));
504
- return box;
505
- }
506
- box.style.gridTemplateColumns = `6em repeat(${line.sides.length}, minmax(0, 1fr))`;
506
+ box.style.gridTemplateColumns = `10em repeat(${line.sides.length}, minmax(0, 1fr))`;
507
507
  box.append(el("span", "ce-stratum", line.stratum));
508
508
  for (const s of line.sides) box.append(cePolicyCell(s, line.href));
509
509
  return box;
@@ -890,7 +890,10 @@ function boot() {
890
890
  document.addEventListener("click", (e) => {
891
891
  if (e.defaultPrevented || e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return;
892
892
  const a = e.target.closest?.('a[href^="#"]');
893
- if (a && a.getAttribute("href") === location.hash) { e.preventDefault(); applyHash(); }
893
+ // The browser hands the open hash back percent-encoded, `<` and `>` among what it encodes; a link has its own as spelled.
894
+ let open = location.hash;
895
+ try { open = decodeURI(open); } catch { /* an escape that decodes to nothing is no link's hash */ }
896
+ if (a && a.getAttribute("href") === open) { e.preventDefault(); applyHash(); }
894
897
  });
895
898
  applyHash();
896
899
  poll();
@@ -33,12 +33,11 @@
33
33
  // fleet-tick.mjs's I/O and main() never run here, main() being guarded on
34
34
  // argv[1].
35
35
  import { assessBeat, isStalled, isReported, stallReport, NO_OWNER } from "./fleet-state.mjs";
36
- import { parseToken, rowPr, premisesOf, HALT_CAUSES, REVIEW, CELL, POLICY_CELL, parseRoutedEntry, tierValues, cellValues } from "./ledger-grammar.mjs";
36
+ import { parseToken, rowPr, premisesOf, HALT_CAUSES, REVIEW, CELL, POLICY_CELL, parseRoutedEntry, tierValues, cellValues, isRulePath } from "./ledger-grammar.mjs";
37
37
  import { latestFinisherAttempts, foldLedger, pastPinDue } from "./fleet-tick.mjs";
38
38
  import { computeCellEvidence } from "./compute-cell-evidence.mjs";
39
39
  import { admissibleRow, lastSegment } from "./pull-attribution.mjs";
40
40
  import { dispatchModel } from "./member-outcomes.mjs";
41
- import { HEAVY_BRIEF_CHARS, HEAVY_CRITERIA } from "./ticket-router.mjs";
42
41
  import { implementerCell, modelsEqual } from "./tier-roles.mjs";
43
42
 
44
43
  // A ledger row is freeform, controller-authored text. Two example shapes:
@@ -315,7 +314,6 @@ const isBadge = (flag) => flag === "excluded" || flag.startsWith("excluded:");
315
314
  const NOT_ON_RECORD = "not on record";
316
315
  const part = (text, o = {}) => ({ text, dim: false, href: null, sep: " · ", ...o });
317
316
  const hole = (o = {}) => part(NOT_ON_RECORD, { dim: true, ...o });
318
- const grouped = (n) => String(n).replace(/\B(?=(\d{3})+(?!\d))/g, ",");
319
317
 
320
318
  // A transcript's member record, as gather() keeps it, put the way the figures
321
319
  // read an implementer row (member-outcomes.mjs): its definition, its level
@@ -342,6 +340,14 @@ function implementersOf(row, issue) {
342
340
  .map((t) => t.name);
343
341
  }
344
342
 
343
+ // The policy row a Routing links to: its group's, else the `*` row — for a group the table holds no row for, and for
344
+ // a word filed before the table was a tree (`light`, `heavy`, `unknown`), which names no place on Cell evidence. With
345
+ // no table read, a rule path is linked as filed.
346
+ function rowHref(r, table) {
347
+ const own = isRulePath(r.stratum) && (table === null || Object.hasOwn(table.rows[r.objective], r.stratum));
348
+ return `#cells/row/${r.objective}/${own ? r.stratum : "*"}`;
349
+ }
350
+
345
351
  // The words of a recorded reason, after the draw's, and whether they name the
346
352
  // policy row. `REASON` keeps only the first thing that went wrong, and nothing
347
353
  // here guesses the rest.
@@ -352,12 +358,11 @@ function reasonWords(r, table) {
352
358
  case "ok": {
353
359
  if (drawn) return [];
354
360
  const follows = table !== null && !Object.hasOwn(table.rows[r.objective], r.stratum);
355
- const href = `#cells/row/${r.objective}/${follows ? "*" : r.stratum}`;
356
- return [part(`${row}, ${r.stratum}`, { href }), ...(follows ? [part("follows *")] : [])];
361
+ return [part(`${row}, ${r.stratum}`, { href: rowHref(r, table) }), ...(follows ? [part("follows *")] : [])];
357
362
  }
358
363
  case "table-cell-tripped": {
359
364
  const named = r.tripped.length === 1 ? `${row}'s ${r.tripped[0]}` : `${row}'s Cell (one of ${r.tripped.join(", ")})`;
360
- return [part(`${named} tripped${drawn ? "" : ": default Cell"}`, { href: `#cells/row/${r.objective}/${r.stratum}` })];
365
+ return [part(`${named} tripped${drawn ? "" : ": default Cell"}`, { href: rowHref(r, table) })];
361
366
  }
362
367
  case "guard-tripped":
363
368
  return [part(drawn ? `left out as tripped: ${r.tripped.join(", ")}` : "every other Cell tripped: no draw")];
@@ -368,14 +373,14 @@ function reasonWords(r, table) {
368
373
  }
369
374
  }
370
375
 
371
- // The Stratum and the numbers that set it: a Slice's parent sets it, ahead of the brief's numbers.
376
+ // The Stratum — the group's rule path — with what is known of how the Pull came by it: the sizing label arm B gave
377
+ // it, no brief read, no sizing, or the Slice it is a part of. Else the rule path alone.
372
378
  function stratumWords(r) {
373
379
  if (r.sized !== null) return `${r.stratum}: sized ${r.sized}`;
374
380
  if (r.brief === null) return `${r.stratum}: no brief read`;
375
381
  if (r.reason === "no-sizing") return `${r.stratum}: no sizing`;
376
382
  if (r.parent !== null) return `${r.stratum}: Slice of #${r.parent}`;
377
- const past = (n, at) => `${n > at ? "past" : "not past"} ${grouped(at)}`;
378
- return `${r.stratum}: ${grouped(r.brief)} chars (${past(r.brief, HEAVY_BRIEF_CHARS)}), ${r.criteria} criteria (${past(r.criteria, HEAVY_CRITERIA)})`;
383
+ return r.stratum;
379
384
  }
380
385
 
381
386
  // "<model> · <level>" off a dispatch record, holes where it carries none.
@@ -452,7 +457,7 @@ export function cellLine({ row, issue, routed = [], agents = {}, members = new M
452
457
  targets.push({ cell: rescue.at, generation: gen });
453
458
  }
454
459
 
455
- // Line 2: the Stratum with its numbers, then the model and level of the
460
+ // Line 2: the Stratum, the group's rule path, then the model and level of the
456
461
  // Pull's first implementer at its Cell.
457
462
  const shown = recs[firstAdmissible === -1 ? 0 : firstAdmissible];
458
463
  const stratum = [routing !== null ? part(stratumWords(routing), { sep: "" }) : hole({ sep: "" }), ...modelParts(shown, " · ")];
@@ -10,7 +10,7 @@
10
10
  // What this holds is the guard section — what the cost guard holds each
11
11
  // implementer Cell to, from the guard file and nothing recomputed, with this
12
12
  // run's Pulls booked to each Cell off the board's cards — "Declared, not
13
- // measured", and the policy rows: for each Objective × Stratum row, on the
13
+ // measured", and the policy rows: for each Objective × group of the tree, on the
14
14
  // routes-now side the Cell the installed router table plus the workspace's guard
15
15
  // route to, why, and how a Pull on that row is dispatched (ticket-router.mjs's
16
16
  // rowDispatch, the function `route` itself calls), and on the evidence-favours
@@ -30,7 +30,7 @@
30
30
  // checked where its figure would show.
31
31
 
32
32
  import { isDeepStrictEqual } from "node:util";
33
- import { CELL, OBJECTIVES, POLICY_CELL, STRATA } from "./ledger-grammar.mjs";
33
+ import { CELL, OBJECTIVES, POLICY_CELL } from "./ledger-grammar.mjs";
34
34
  import { costGuardFault } from "./fleet-tick.mjs";
35
35
  import { MIN_N, parseGuard, readGuard, rowDispatch } from "./ticket-router.mjs";
36
36
  import { implementerCell, modelsEqual, parseModelRoute, resolveRole } from "./tier-roles.mjs";
@@ -592,9 +592,9 @@ function behindMain(source, table, checkout) {
592
592
  }
593
593
 
594
594
  // The routes-now side of the policy rows: its heading words and every row the
595
- // installed table holds, `rows[objective][stratum]` — `*` and each Stratum with a
596
- // row of its own. `rows` is null when no table could be read, and each of its
597
- // rows then reads `unread`.
595
+ // installed table holds, `rows[objective][stratum]` — one for each group of its
596
+ // tree, the root `*` and any below it. `rows` is null when no table could be
597
+ // read, and each of its rows then reads `unread`.
598
598
  function routesNow({ table, guard, modelRoles, install, repoUrl, checkout }) {
599
599
  const source = routesSource(table, install, repoUrl);
600
600
  const behind = behindMain(source, table, checkout);
@@ -606,7 +606,7 @@ function routesNow({ table, guard, modelRoles, install, repoUrl, checkout }) {
606
606
  labels: behind.label === null ? [] : [behind.label],
607
607
  footnotes: foot,
608
608
  rows: table === null ? null : Object.fromEntries(OBJECTIVES.map((o) => [o,
609
- Object.fromEntries(["*", ...STRATA].filter((s) => Object.hasOwn(table.rows[o], s)).map((s) => [s, rowEntry(table, guard, modelRoles, o, s)])),
609
+ Object.fromEntries(Object.keys(table.rows[o]).map((s) => [s, rowEntry(table, guard, modelRoles, o, s)])),
610
610
  ])),
611
611
  unread: "router table not read",
612
612
  };
@@ -643,7 +643,7 @@ function refitLabel(step, p) {
643
643
  // the fit read the guard's files: fitted beside another guard, on other records,
644
644
  // or against another prior. The prior is
645
645
  // compared only on what the fit takes from it — `stage`, `cells`, `classifier`,
646
- // and `window_start` when the guard gives none — so a release that changes only
646
+ // `splits`, and `window_start` when the guard gives none — so a release that changes only
647
647
  // what the fit recomputes, or `fitted_commit` and `version`, raises nothing: the
648
648
  // next phase 0's refit would come out the same.
649
649
  function previewLabels(p, raw, routed, table, records) {
@@ -655,7 +655,7 @@ function previewLabels(p, raw, routed, table, records) {
655
655
  labels.push("fitted against the installed table: not checked: no router table read");
656
656
  return labels;
657
657
  }
658
- const read = ["stage", "cells", "classifier", ...(routed.window_start === null ? ["window_start"] : [])];
658
+ const read = ["stage", "cells", "classifier", "splits", ...(routed.window_start === null ? ["window_start"] : [])];
659
659
  const prior = isRecord(p.prior) ? p.prior : {};
660
660
  if (read.some((k) => !isDeepStrictEqual(prior[k], table[k]))) {
661
661
  const version = prior.version === "0.0.0" ? "linked checkout" : (typeof prior.version === "string" ? prior.version : "no version");
@@ -713,7 +713,7 @@ function evidenceFavours({ preview, guard, routed, table, modelRoles, step, mark
713
713
  labels: [...refitLabel(step, p), ...previewLabels(p, raw, routed, table, records)],
714
714
  footnotes: differ.length === 0 ? [] : [{ mark, text: `${list(differ)}: the guard counts merges by GitHub's state, the fit by Rulings, and the fit admits only drawn or rule-sized Pulls` }],
715
715
  rows: Object.fromEntries(OBJECTIVES.map((o) => [o,
716
- Object.fromEntries(["*", ...STRATA].filter((s) => Object.hasOwn(fit.rows[o], s)).map((s) => [s, entry(o, s)])),
716
+ Object.fromEntries(Object.keys(fit.rows[o]).map((s) => [s, entry(o, s)])),
717
717
  ])),
718
718
  unread: null,
719
719
  };
@@ -722,12 +722,13 @@ function evidenceFavours({ preview, guard, routed, table, modelRoles, step, mark
722
722
  // The policy rows as the page lays them out, from each side built above. Pure
723
723
  // and side-agnostic: a side's shared dispatch (the one most rows have, the rest
724
724
  // showing theirs on the row), its one model-name line when every candidate it
725
- // names differs, a Stratum no side has a row for collapsed to one line, and the
726
- // Objective of the live run marked. Every row, collapsed or not, has an anchor
727
- // the `#cells/row/<objective>/<stratum>` link lands on. A side with no rows reads
728
- // its `unread` on every row, and keeps a Stratum from collapsing, since its rows
729
- // are not known; one whose `unread` is null has nothing to show, its cells are
730
- // empty, and the Strata collapse on the sides that have rows.
725
+ // names differs, and the Objective of the live run marked. An Objective's lines
726
+ // are the root and then each group any side holds a row for, the first side's
727
+ // groups first: a side the group is no node of reads "no row of its own" there,
728
+ // and follows `*`. Every row has an anchor the
729
+ // `#cells/row/<objective>/<stratum>` link lands on. A side with no rows reads
730
+ // its `unread` on every row; one whose `unread` is null has nothing to show, and
731
+ // its cells are empty.
731
732
  export function policyRowsView({ sides, objective = null }) {
732
733
  const entries = (s) => (s.rows === null ? [] : OBJECTIVES.flatMap((o) => Object.values(s.rows[o])));
733
734
  const shared = sides.map((s) => {
@@ -744,28 +745,21 @@ export function policyRowsView({ sides, objective = null }) {
744
745
  dispatch: e.dispatch === shared[i] ? null : e.dispatch,
745
746
  candidates: e.candidates.map((c) => (c.model !== null && modelLine[i] !== null ? { ...c, model: { ...c.model, text: null } } : c)),
746
747
  });
747
- // How many sides have rows, and whether a Stratum none of them has a row for
748
- // may collapse: never while a side's rows are unknown.
749
- const read = sides.filter((s) => s.rows !== null).length;
750
- const collapsible = read > 0 && sides.every((s) => s.rows !== null || !s.unread);
751
748
  const cellOf = (s, e, i) => {
752
749
  if (s.rows === null) return s.unread ? { unread: s.unread } : { empty: true };
753
750
  if (e === null) return { follows: "no row of its own: follows *" };
754
751
  return show(e, i);
755
752
  };
753
+ const strata = (o) => ["*", ...new Set(sides.flatMap((s) => Object.keys(s.rows?.[o] ?? {})).filter((stratum) => stratum !== "*"))];
756
754
  return {
757
755
  sides: sides.map((s, i) => ({ title: s.title, source: s.source, heading: s.heading, labels: s.labels ?? [], dispatch: shared[i], modelLine: modelLine[i], footnotes: s.footnotes })),
758
756
  objectives: OBJECTIVES.map((o) => ({
759
757
  objective: o,
760
758
  live: o === objective,
761
- lines: ["*", ...STRATA].map((stratum) => {
762
- const line = { stratum, anchor: `cells-row-${o}-${stratum}`, href: `#cells/row/${o}/${stratum}` };
763
- const own = sides.map((s) => s.rows?.[o]?.[stratum] ?? null);
764
- if (stratum !== "*" && collapsible && own.every((e) => e === null)) {
765
- return { ...line, collapsed: `${stratum}: ${read > 1 ? "no row on either side" : "no row"}, follows *` };
766
- }
767
- return { ...line, sides: sides.map((s, i) => cellOf(s, own[i], i)) };
768
- }),
759
+ lines: strata(o).map((stratum) => ({
760
+ stratum, anchor: `cells-row-${o}-${stratum}`, href: `#cells/row/${o}/${stratum}`,
761
+ sides: sides.map((s, i) => cellOf(s, s.rows?.[o]?.[stratum] ?? null, i)),
762
+ })),
769
763
  })),
770
764
  };
771
765
  }
@@ -882,14 +882,30 @@ export function drawCell({ session, ticket, policyCell, cells }) {
882
882
  // this order, `-` for none:
883
883
  // POLICY the policy row's Cell CELL the Pull's Cell
884
884
  // DRAW k/K of the draw BY burn-in | every-5th
885
- // STRATUM light | heavy | unknown BRIEF the brief's chars
885
+ // STRATUM the group's rule path BRIEF the brief's chars
886
886
  // CRITERIA the criteria count PARENT a Slice's parent issue
887
887
  // SIZED arm B's sizing label OBJECTIVE cost | speed
888
888
  // TRIPPED the guard's tripped Cells REASON the first thing that went wrong
889
889
  // DRAW and BY are `-` together (no draw); so are BRIEF and CRITERIA (no issue
890
890
  // read), and PARENT is `-` with them. A line written before PARENT was a part
891
891
  // carries none, and reads as `PARENT=-`.
892
- export const STRATA = Object.freeze(["light", "heavy", "unknown"]);
892
+ //
893
+ // STRATUM names the group the Pull was routed to — the router table's node the
894
+ // walk ended at — by its rule path. `*` is the root, the group of every ticket
895
+ // before any split; any other path is the tests taken from the root, in order,
896
+ // joined by `&`. A test is the input a split reads, then `>` or `<=` and a
897
+ // number (`brief_chars>4047`, `brief_chars<=4047`), or `=` or `!=` and a
898
+ // ticket kind (`kind=bug`, `kind!=bug`): `brief_chars>4047&kind=bug`. A path
899
+ // holds no whitespace, so it is one word of the line, and it is the key the
900
+ // table's rows, estimates and reasons name the group by. A line filed before the
901
+ // table was a tree carries `light`, `heavy` or `unknown`: a ledger is append-only
902
+ // and outlives an upgrade, so those words still read, and the router writes none.
903
+ const RULE_TEST = "[a-z][a-z_]*(?:(?:>|<=)(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?|!?=[a-z]+)";
904
+ const RULE_PATH = new RegExp(`^(?:\\*|${RULE_TEST}(?:&${RULE_TEST})*)$`);
905
+ const FILED_STRATA = Object.freeze(["light", "heavy", "unknown"]);
906
+
907
+ /** Whether `x` is a rule path: `*`, or one or more tests joined by `&`. */
908
+ export const isRulePath = (x) => typeof x === "string" && RULE_PATH.test(x);
893
909
  // What a run asks the router to minimise. phase0.mjs records the run's in its
894
910
  // receipt, and every Routing names the one it routed by.
895
911
  export const OBJECTIVES = Object.freeze(["cost", "speed"]);
@@ -929,7 +945,7 @@ export function parseRouting(line) {
929
945
  cell: CELL.test(v.CELL) ? v.CELL : undefined,
930
946
  draw: v.DRAW === "-" ? null : d === null ? undefined : { k: Number(d[1]), K: Number(d[2]) },
931
947
  by: opt(v.BY, (x) => DRAWN_BY.includes(x)),
932
- stratum: STRATA.includes(v.STRATUM) ? v.STRATUM : undefined,
948
+ stratum: isRulePath(v.STRATUM) || FILED_STRATA.includes(v.STRATUM) ? v.STRATUM : undefined,
933
949
  brief: count(v.BRIEF),
934
950
  criteria: count(v.CRITERIA),
935
951
  parent: v.PARENT === "-" ? null : ISSUE.test(v.PARENT) && Number.isSafeInteger(Number(v.PARENT)) ? Number(v.PARENT) : undefined,
@@ -67,7 +67,7 @@
67
67
  // rename: `computed_at`, `guard_computed_at` (the guard's own `computed_at`),
68
68
  // `tsv_blobs` (the git blob id of each TSV it read, keyed by path as the guard
69
69
  // keys its own), `prior` (the installed table's `fitted_commit`, `stage`,
70
- // `cells`, `classifier` and `window_start`, and the install's `package.json`
70
+ // `cells`, `classifier`, `splits` and `window_start`, and the install's `package.json`
71
71
  // `version`) and the fitted `table`. The cockpit lays it out as what the
72
72
  // evidence favours; nothing routes by it and nothing commits it. It is called
73
73
  // in-process because a fit has no verdict for an exit status to carry, and the
@@ -312,6 +312,7 @@ export function writePreview(repo, written, { tablePath = DEFAULT_TABLE, package
312
312
  stage: prior.stage,
313
313
  cells: prior.cells,
314
314
  classifier: prior.classifier,
315
+ splits: prior.splits,
315
316
  window_start: prior.window_start,
316
317
  },
317
318
  table,
@@ -11,16 +11,13 @@
11
11
  "task-max"
12
12
  ],
13
13
  "burn_in": true,
14
+ "splits": {},
14
15
  "rows": {
15
16
  "cost": {
16
- "*": "task-high",
17
- "light": "task-high",
18
- "heavy": "task-high"
17
+ "*": "task-high"
19
18
  },
20
19
  "speed": {
21
- "*": "task-high",
22
- "light": "task-high",
23
- "heavy": "task-high"
20
+ "*": "task-high"
24
21
  }
25
22
  },
26
23
  "classifier": {
@@ -99,150 +96,6 @@
99
96
  "excluded": 1,
100
97
  "older": {}
101
98
  }
102
- },
103
- "heavy": {
104
- "slow-high": {
105
- "generation": "claude-opus-5-5",
106
- "n": 73,
107
- "merged": 73,
108
- "by_hand": 0,
109
- "claims": 73,
110
- "failed": 17,
111
- "usd_per_merged": 16.7549,
112
- "minutes_per_merged": 127.9543,
113
- "fail_rate": 0.2329,
114
- "fix_rounds": 1.2466,
115
- "review_findings": null,
116
- "left_out": 0,
117
- "unpriced": 0,
118
- "untimed": 0,
119
- "excluded": 0,
120
- "older": {}
121
- },
122
- "smol-high": {
123
- "generation": "claude-haiku-5-5",
124
- "n": 20,
125
- "merged": 20,
126
- "by_hand": 1,
127
- "claims": 20,
128
- "failed": 12,
129
- "usd_per_merged": 12.1787,
130
- "minutes_per_merged": 114.6475,
131
- "fail_rate": 0.6,
132
- "fix_rounds": 1.6,
133
- "review_findings": null,
134
- "left_out": 0,
135
- "unpriced": 0,
136
- "untimed": 0,
137
- "excluded": 4,
138
- "older": {
139
- "claude-haiku-4-5": {
140
- "n": 13,
141
- "merged": 13,
142
- "by_hand": 0,
143
- "claims": 13,
144
- "failed": 9,
145
- "usd_per_merged": 14.7469,
146
- "minutes_per_merged": 132.7231,
147
- "fail_rate": 0.6923,
148
- "fix_rounds": 1.7692,
149
- "review_findings": null,
150
- "left_out": 0,
151
- "unpriced": 0,
152
- "untimed": 0
153
- }
154
- }
155
- },
156
- "task-high": {
157
- "generation": "claude-sonnet-5-5",
158
- "n": 74,
159
- "merged": 74,
160
- "by_hand": 1,
161
- "claims": 74,
162
- "failed": 24,
163
- "usd_per_merged": 12.2054,
164
- "minutes_per_merged": 111.6597,
165
- "fail_rate": 0.3243,
166
- "fix_rounds": 1.2703,
167
- "review_findings": null,
168
- "left_out": 0,
169
- "unpriced": 0,
170
- "untimed": 0,
171
- "excluded": 0,
172
- "older": {}
173
- }
174
- },
175
- "light": {
176
- "slow-high": {
177
- "generation": "claude-opus-5-5",
178
- "n": 31,
179
- "merged": 31,
180
- "by_hand": 0,
181
- "claims": 31,
182
- "failed": 3,
183
- "usd_per_merged": 9.2093,
184
- "minutes_per_merged": 105.7452,
185
- "fail_rate": 0.0968,
186
- "fix_rounds": 1.0968,
187
- "review_findings": null,
188
- "left_out": 0,
189
- "unpriced": 0,
190
- "untimed": 0,
191
- "excluded": 0,
192
- "older": {}
193
- },
194
- "smol-high": {
195
- "generation": "claude-haiku-5-5",
196
- "n": 12,
197
- "merged": 12,
198
- "by_hand": 0,
199
- "claims": 12,
200
- "failed": 6,
201
- "usd_per_merged": 9.1866,
202
- "minutes_per_merged": 103.0153,
203
- "fail_rate": 0.5,
204
- "fix_rounds": 1.0833,
205
- "review_findings": null,
206
- "left_out": 0,
207
- "unpriced": 1,
208
- "untimed": 0,
209
- "excluded": 1,
210
- "older": {
211
- "claude-haiku-4-5": {
212
- "n": 8,
213
- "merged": 8,
214
- "by_hand": 0,
215
- "claims": 8,
216
- "failed": 8,
217
- "usd_per_merged": 6.9292,
218
- "minutes_per_merged": 89.4396,
219
- "fail_rate": 1,
220
- "fix_rounds": 1.125,
221
- "review_findings": null,
222
- "left_out": 0,
223
- "unpriced": 0,
224
- "untimed": 0
225
- }
226
- }
227
- },
228
- "task-high": {
229
- "generation": "claude-sonnet-5-5",
230
- "n": 30,
231
- "merged": 30,
232
- "by_hand": 0,
233
- "claims": 30,
234
- "failed": 4,
235
- "usd_per_merged": 5.523,
236
- "minutes_per_merged": 81.2328,
237
- "fail_rate": 0.1333,
238
- "fix_rounds": 1.0333,
239
- "review_findings": null,
240
- "left_out": 0,
241
- "unpriced": 0,
242
- "untimed": 0,
243
- "excluded": 1,
244
- "older": {}
245
- }
246
99
  }
247
100
  },
248
101
  "reasons": {
@@ -280,74 +133,6 @@
280
133
  }
281
134
  },
282
135
  "pairs": []
283
- },
284
- "light": {
285
- "cell": "task-high",
286
- "reason": "sole-qualifier",
287
- "cells": {
288
- "task-high": {
289
- "verdict": "qualifies",
290
- "under_floor": false,
291
- "bar": 0.2468,
292
- "range": [
293
- -7.11,
294
- -0.8
295
- ]
296
- },
297
- "smol-high": {
298
- "verdict": "tripped",
299
- "under_floor": null,
300
- "bar": null,
301
- "range": null
302
- },
303
- "slow-medium": {
304
- "verdict": "too-few",
305
- "under_floor": null,
306
- "bar": null,
307
- "range": null
308
- },
309
- "task-max": {
310
- "verdict": "too-few",
311
- "under_floor": null,
312
- "bar": null,
313
- "range": null
314
- }
315
- },
316
- "pairs": []
317
- },
318
- "heavy": {
319
- "cell": "task-high",
320
- "reason": "sole-qualifier",
321
- "cells": {
322
- "task-high": {
323
- "verdict": "qualifies",
324
- "under_floor": false,
325
- "bar": 0.3829,
326
- "range": [
327
- -7.33,
328
- -1.89
329
- ]
330
- },
331
- "smol-high": {
332
- "verdict": "tripped",
333
- "under_floor": null,
334
- "bar": null,
335
- "range": null
336
- },
337
- "slow-medium": {
338
- "verdict": "too-few",
339
- "under_floor": null,
340
- "bar": null,
341
- "range": null
342
- },
343
- "task-max": {
344
- "verdict": "too-few",
345
- "under_floor": null,
346
- "bar": null,
347
- "range": null
348
- }
349
- },
350
- "pairs": []
351
136
  }
352
137
  },
353
138
  "speed": {
@@ -384,74 +169,6 @@
384
169
  }
385
170
  },
386
171
  "pairs": []
387
- },
388
- "light": {
389
- "cell": "task-high",
390
- "reason": "no-qualifier",
391
- "cells": {
392
- "slow-high": {
393
- "verdict": "too-slow",
394
- "under_floor": false,
395
- "bar": 0.2468,
396
- "range": [
397
- 0.71,
398
- 48.04
399
- ]
400
- },
401
- "smol-high": {
402
- "verdict": "tripped",
403
- "under_floor": null,
404
- "bar": null,
405
- "range": null
406
- },
407
- "slow-medium": {
408
- "verdict": "too-few",
409
- "under_floor": null,
410
- "bar": null,
411
- "range": null
412
- },
413
- "task-max": {
414
- "verdict": "too-few",
415
- "under_floor": null,
416
- "bar": null,
417
- "range": null
418
- }
419
- },
420
- "pairs": []
421
- },
422
- "heavy": {
423
- "cell": "task-high",
424
- "reason": "no-qualifier",
425
- "cells": {
426
- "slow-high": {
427
- "verdict": "too-slow",
428
- "under_floor": false,
429
- "bar": 0.3829,
430
- "range": [
431
- -2.55,
432
- 36.08
433
- ]
434
- },
435
- "smol-high": {
436
- "verdict": "tripped",
437
- "under_floor": null,
438
- "bar": null,
439
- "range": null
440
- },
441
- "slow-medium": {
442
- "verdict": "too-few",
443
- "under_floor": null,
444
- "bar": null,
445
- "range": null
446
- },
447
- "task-max": {
448
- "verdict": "too-few",
449
- "under_floor": null,
450
- "bar": null,
451
- "range": null
452
- }
453
- },
454
- "pairs": []
455
172
  }
456
173
  }
457
174
  },
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  // The per-ticket router: which implementer cell a Pull dispatches. One script
3
- // for dispatch and for the offline fit, because the stratum rule is the one
4
- // function that must never read differently between the two.
3
+ // for dispatch and for the offline fit, because the walk from a ticket's inputs
4
+ // to its group is the one function that must never read differently between
5
+ // the two.
5
6
  //
6
7
  // route [--session <dir|id>] [--objective cost|speed] --ticket <N> --arm A|B
7
8
  // --impl-row <k> --issue <issue.json> --guard <cost-guard.json>
@@ -9,7 +10,7 @@
9
10
  // [--chain-head] [--pending <tsv>]
10
11
  // Prints one line, the Pull's Routing (ledger-grammar.mjs owns its
11
12
  // grammar): `POLICY=<cell> CELL=<cell> DRAW=<k/K|-> BY=<burn-in|every-5th|->
12
- // STRATUM=<light|heavy|unknown> BRIEF=<chars|-> CRITERIA=<n|-> PARENT=<N|->
13
+ // STRATUM=<rule path> BRIEF=<chars|-> CRITERIA=<n|-> PARENT=<N|->
13
14
  // SIZED=<light|heavy|-> OBJECTIVE=<cost|speed> TRIPPED=<cell,…|->
14
15
  // REASON=<reason>`,
15
16
  // routing by the objective's row set, and appends the Pull's
@@ -53,7 +54,7 @@ import { isDeepStrictEqual } from "node:util";
53
54
  import { isCLI } from "./is-cli.mjs";
54
55
  import { gitEnv } from "./git-env.mjs";
55
56
  import { makeDie, defineFlags } from "./arg.mjs";
56
- import { CELL, OBJECTIVES, POLICY_CELL, STRATA, drawCell, formatRouting, parseMember } from "./ledger-grammar.mjs";
57
+ import { CELL, OBJECTIVES, POLICY_CELL, drawCell, formatRouting, isRulePath, parseMember } from "./ledger-grammar.mjs";
57
58
  import { objectiveFromReceipt, sessionFromReceipt } from "./phase0-receipt.mjs";
58
59
  import { parseTsv as parseMemberTsv } from "./member-outcomes.mjs";
59
60
  import {
@@ -68,10 +69,6 @@ export const DEFAULT_TABLE = join(SCRIPT_DIR, "router-table.json");
68
69
  // The install's own package.json, whose `version` names the plugin a Pull was routed by.
69
70
  export const INSTALL_PACKAGE = join(SCRIPT_DIR, "..", "package.json");
70
71
 
71
- // The free classifier's thresholds: heavy past the median brief length of
72
- // the tickets whose sizing verdict is known, or past five criteria.
73
- export const HEAVY_BRIEF_CHARS = 3483;
74
- export const HEAVY_CRITERIA = 5;
75
72
  // Exploration cadence after burn-in: the Pull that creates `impl-` row 5k.
76
73
  const EXPLORE_EVERY = 5;
77
74
  // The fit's adoption floor (merged PRs per side), margin, and cadence.
@@ -208,22 +205,93 @@ export function namedLines(named, root) {
208
205
  return paths.map((p) => lineEntry(p, abs, realRoot)).join(" ");
209
206
  }
210
207
 
208
+ // ---------------------------------------------------------------------------
209
+ // the tree — which group a ticket falls in
210
+ // ---------------------------------------------------------------------------
211
+
212
+ // The table's groups are the nodes of a tree of splits on what is known of a
213
+ // ticket at dispatch. A group is named by its rule path (ledger-grammar.mjs
214
+ // says how a path reads): `*` is the root, the group of every ticket before any
215
+ // split, and a node's two children are named by the node's path and the test
216
+ // each takes, joined by `&`. `splits` holds the tree, keyed by the path of the
217
+ // node a split sits at:
218
+ //
219
+ // "splits": { "*": { "input": "brief_chars", "cut": 4047 } }
220
+ //
221
+ // A split reads one input, a ticket-features column, and sends a ticket to one
222
+ // of its two children. For an input that reads as a number, a ticket past the
223
+ // cut goes to `<input>><cut>` and any other to `<input><=<cut>`; for `kind`, a
224
+ // ticket of the cut's kind goes to `kind=<cut>` and any other to
225
+ // `kind!=<cut>`. A ticket that lacks the input a split reads — its issue was not
226
+ // read, or its column is blank — goes no further than that node, and the
227
+ // node's own row routes it. Every node, inner nodes and root included, holds a
228
+ // `cost` row and a `speed` row of its own, and its estimates and reasons. A
229
+ // table with no split is the one-node tree: `*` routes every ticket.
230
+
231
+ const SEP = "&";
232
+ // Each input a split may read, and what it reads as: the columns of a ticket-features row that are known at
233
+ // dispatch and are a count or a kind. `parent` reads as the Slice's parent number, and 0 for an issue read that
234
+ // names none, so a cut at 0 splits Slices from the rest. The brief's paths, its title and the install's version
235
+ // are no input: no cut of theirs is defined.
236
+ const INPUTS = Object.freeze({
237
+ brief_chars: "number", criteria: "number", comments: "number", age_days: "number", paths: "number", test_paths: "number", xrefs: "number", dirs: "number",
238
+ parent: "number", kind: "kind",
239
+ });
240
+
241
+ /** What a ticket holds for `input` — a number, or a kind — or null where it lacks it: its issue was not read, or its column is blank. */
242
+ function inputOf(input, m) {
243
+ // A row whose issue was not read has blank metrics, `brief_chars` among them: it holds none of the inputs.
244
+ if (m.brief_chars === undefined || m.brief_chars === "") return null;
245
+ const s = m[input] ?? "";
246
+ if (input === "kind") return s === "" ? null : s;
247
+ if (input === "parent" && s === "") return 0;
248
+ const n = s === "" ? NaN : Number(s);
249
+ return Number.isFinite(n) ? n : null;
250
+ }
251
+
252
+ const child = (node, test) => (node === "*" ? test : `${node}${SEP}${test}`);
253
+ /** The two children of the split at `node`, the group a test holds for first. */
254
+ function childrenOf(node, { input, cut }) {
255
+ return (INPUTS[input] === "kind" ? [`kind=${cut}`, `kind!=${cut}`] : [`${input}>${cut}`, `${input}<=${cut}`]).map((test) => child(node, test));
256
+ }
257
+ /** The path of `node`'s parent, null for the root. */
258
+ const parentOf = (node) => (node === "*" ? null : node.includes(SEP) ? node.slice(0, node.lastIndexOf(SEP)) : "*");
259
+
260
+ /** The nodes of the tree `splits` holds, root first, then each split's two children, depth first. */
261
+ function treeNodes(splits) {
262
+ const nodes = [];
263
+ const down = (node) => {
264
+ nodes.push(node);
265
+ if (Object.hasOwn(splits, node)) for (const c of childrenOf(node, splits[node])) down(c);
266
+ };
267
+ down("*");
268
+ return nodes;
269
+ }
270
+
211
271
  /**
212
- * The `rule` classifier, over a row's metric columns: blank metrics are
213
- * `unknown`, a Slice (a row with a `parent`) is `heavy`, and any other row is
214
- * `heavy` past the brief length or the criteria count. A Slice whose metrics
215
- * are blank stays `unknown`, as it was routed: its issue was not read then.
272
+ * The group a ticket falls in: from the root, each split sends it to the child
273
+ * its input says, until a node has no split or the ticket lacks the input the
274
+ * node's split reads. `m` is the ticket's metrics row, the columns `issueMetrics`
275
+ * makes or a ticket-features file holds, as strings.
216
276
  */
217
- export function ruleStratum({ brief_chars, criteria, parent }) {
218
- if (brief_chars === "" || brief_chars === undefined || criteria === "" || criteria === undefined) return "unknown";
219
- if (parent) return "heavy";
220
- return Number(brief_chars) > HEAVY_BRIEF_CHARS || Number(criteria) > HEAVY_CRITERIA ? "heavy" : "light";
277
+ export function stratumOf(table, m) {
278
+ let node = "*";
279
+ while (Object.hasOwn(table.splits, node)) {
280
+ const split = table.splits[node];
281
+ const v = inputOf(split.input, m);
282
+ if (v === null) break;
283
+ const [holds, other] = childrenOf(node, split);
284
+ node = (INPUTS[split.input] === "kind" ? v === split.cut : v > split.cut) ? holds : other;
285
+ }
286
+ return node;
221
287
  }
222
288
 
223
289
  // ---------------------------------------------------------------------------
224
290
  // the table
225
291
  // ---------------------------------------------------------------------------
226
292
 
293
+ const shown = (x) => (typeof x === "number" ? String(x) : JSON.stringify(x));
294
+
227
295
  /** A parsed table, or an Error saying why it is not one. */
228
296
  export function validateTable(t) {
229
297
  const bad = (why) => new Error(`router table: ${why}`);
@@ -232,7 +300,26 @@ export function validateTable(t) {
232
300
  if (!Array.isArray(t.cells) || t.cells.length === 0) return bad("`cells` is not a non-empty array");
233
301
  for (const c of t.cells) if (typeof c !== "string" || !CELL.test(c)) return bad(`\`cells\` holds ${JSON.stringify(c)}, not a cell token`);
234
302
  if (new Set(t.cells).size !== t.cells.length) return bad("`cells` repeats a cell");
235
- // `rows` and `reasons` are each keyed by objective, then by `*` or a stratum.
303
+ // The tree: each split reads an input a split may read, at a cut that input can take, and sits at a node of the
304
+ // tree the other splits make.
305
+ if (!isObject(t.splits)) return bad("`splits` is not an object");
306
+ for (const [path, s] of Object.entries(t.splits)) {
307
+ const at = `splits[${JSON.stringify(path)}]`;
308
+ if (!isObject(s)) return bad(`\`${at}\` is not \`{ input, cut }\``);
309
+ if (typeof s.input !== "string" || !Object.hasOwn(INPUTS, s.input)) return bad(`\`${at}\` reads ${shown(s.input)}, which no split can read`);
310
+ const number = INPUTS[s.input] === "number";
311
+ // A number is a cut when the rule path it makes is one the Routing line can carry: no NaN, sign or exponent.
312
+ if (number ? typeof s.cut !== "number" || !isRulePath(childrenOf("*", s)[0]) : !KINDS.has(s.cut)) {
313
+ return bad(`\`${at}\` cuts ${s.input} at ${shown(s.cut)}, which is not ${number ? "a non-negative number" : "a ticket kind"}`);
314
+ }
315
+ if (Object.keys(s).length !== 2) return bad(`\`${at}\` is not \`{ input, cut }\``);
316
+ }
317
+ const nodes = treeNodes(t.splits);
318
+ // The first key of `o` that names no node of the tree.
319
+ const offTree = (o) => Object.keys(o).find((key) => !nodes.includes(key));
320
+ const unreached = offTree(t.splits);
321
+ if (unreached !== undefined) return bad(`\`splits[${JSON.stringify(unreached)}]\` sits at no node of the tree`);
322
+ // `rows` and `reasons` are each keyed by objective, then by the nodes of the tree.
236
323
  for (const field of ["rows", "reasons"]) {
237
324
  if (!isObject(t[field])) return bad(`\`${field}\` is not an object`);
238
325
  const stray = Object.keys(t[field]).find((o) => !OBJECTIVES.includes(o));
@@ -240,13 +327,18 @@ export function validateTable(t) {
240
327
  for (const o of OBJECTIVES) {
241
328
  const set = t[field][o];
242
329
  if (!isObject(set)) return bad(`\`${field}.${o}\` is not an object`);
243
- for (const k of Object.keys(set)) {
244
- if (k !== "*" && !STRATA.includes(k)) return bad(`\`${field}.${o}\` key ${JSON.stringify(k)} is not \`*\` or a stratum`);
245
- }
330
+ const k = offTree(set);
331
+ if (k !== undefined) return bad(`\`${field}.${o}\` key ${JSON.stringify(k)} is not a node of the tree`);
246
332
  }
247
333
  }
334
+ if (isObject(t.estimates)) {
335
+ const k = offTree(t.estimates);
336
+ if (k !== undefined) return bad(`\`estimates\` key ${JSON.stringify(k)} is not a node of the tree`);
337
+ }
248
338
  for (const o of OBJECTIVES) {
249
- if (!Object.hasOwn(t.rows[o], "*")) return bad(`\`rows.${o}\` has no \`*\` row`);
339
+ for (const node of nodes) {
340
+ if (!Object.hasOwn(t.rows[o], node)) return bad(node === "*" ? `\`rows.${o}\` has no \`*\` row` : `\`rows.${o}\` has no row for ${JSON.stringify(node)}`);
341
+ }
250
342
  for (const [k, v] of Object.entries(t.rows[o])) {
251
343
  if (typeof v !== "string" || !CELL.test(v)) return bad(`\`rows.${o}.${k}\` is ${JSON.stringify(v)}, not a cell token`);
252
344
  }
@@ -273,7 +365,7 @@ export function bArmLive(table, objective) {
273
365
  return table.classifier.b !== null && Object.values(table.rows[objective]).some((c) => c !== POLICY_CELL);
274
366
  }
275
367
 
276
- /** The row a stratum routes by: its own, else the `*` row's. */
368
+ /** The row a group routes by: its own, else the `*` row's — as a name no node of the table holds does, such as a group a Routing filed under another table names. */
277
369
  export const rowFor = (rows, stratum) => rows[stratum] ?? rows["*"];
278
370
 
279
371
  /**
@@ -338,14 +430,12 @@ export function readGuard(raw) {
338
430
  return r.ok ? r.guard : null;
339
431
  }
340
432
 
341
- /** The sizing verdict on a live B Pull: `{ stratum, src, label, usd }`, or null when it is unusable. */
433
+ /** The sizing verdict on a live B Pull: `{ src, label, usd }`, or null when it is unusable. */
342
434
  function readSizing(raw, classifier) {
343
435
  if (raw === null || typeof raw !== "object" || raw.source !== classifier.b) return null;
344
436
  const label = raw.label === "light" || raw.label === "heavy" ? raw.label : null;
345
437
  if (label === null) return null;
346
- const abstains = raw.source === "jev" && classifier.tau !== null && !(Number(raw.confidence) >= classifier.tau);
347
438
  return {
348
- stratum: abstains ? "unknown" : label,
349
439
  src: raw.source === "jev" ? `jev:${raw.model ?? ""}` : "haiku",
350
440
  label,
351
441
  usd: Number.isFinite(raw.usd) ? String(raw.usd) : "",
@@ -361,10 +451,12 @@ export function sessionDate(session) {
361
451
  * One Pull's routing, by `objective`'s row set. Every input is already read
362
452
  * but the paths the brief names, which `named_lines` reads under `root`, the
363
453
  * checkout. `version` is the install's, `plugin_version` on the row. The
364
- * exploration draw ignores the objective: it leaves out the cell
365
- * the `cost` set routes the Pull to — by the sizing when arm B is live for
366
- * the `cost` set, whichever set routes the Pull — so a Pull draws the same
367
- * cell under both.
454
+ * ticket's group is the node the tree's walk ends at (stratumOf), and the row
455
+ * set's row for it routes the Pull. The exploration draw ignores the objective:
456
+ * it leaves out the cell the `cost` set routes the group to, whichever set
457
+ * routes the Pull, so a Pull draws the same cell under both. A live B Pull
458
+ * records its sizing verdict and routes as an A Pull does: a label names no
459
+ * group of the tree.
368
460
  * @returns {{ line: string, row: Record<string,string> }}
369
461
  */
370
462
  export function route({
@@ -380,35 +472,29 @@ export function route({
380
472
  .slice(FEATURE_COLUMNS.indexOf("brief_chars"), FEATURE_COLUMNS.indexOf("plugin_version"))
381
473
  .filter((c) => c !== "objective").map((c) => [c, ""]));
382
474
  const m = metrics === null ? blank : { ...metrics, named_lines: namedLines(metrics.named_paths, root) };
383
- const ruleS = ruleStratum(m);
475
+ const stratum = stratumOf(table, m);
384
476
 
385
- let stratum = ruleS;
386
477
  let sizingSrc = "rule";
387
478
  let sizingPre = "";
388
479
  let routerUsd = "";
389
- const sized = arm === "B" ? readSizing(sizing, table.classifier) : null;
390
- const b = arm === "B" && bArmLive(table, objective);
391
- if (b) {
392
- const s = sized;
393
- if (s === null) {
480
+ if (arm === "B" && bArmLive(table, objective)) {
481
+ const sized = readSizing(sizing, table.classifier);
482
+ if (sized === null) {
394
483
  degrade("no-sizing");
395
- stratum = "unknown";
396
484
  sizingSrc = "";
397
485
  } else {
398
- ({ stratum, src: sizingSrc, label: sizingPre, usd: routerUsd } = s);
486
+ ({ src: sizingSrc, label: sizingPre, usd: routerUsd } = sized);
399
487
  }
400
488
  }
401
489
 
402
- const dispatch = (o, s) => rowDispatch({ table, guard, objective: o, stratum: s });
403
- const policyRow = dispatch(objective, ruleS);
404
- const baseRow = b ? dispatch(objective, stratum) : policyRow;
405
- const costB = arm === "B" && bArmLive(table, "cost");
406
- const drawRow = dispatch("cost", costB ? sized?.stratum ?? "unknown" : ruleS);
407
- for (const r of [policyRow.reason, baseRow.reason]) if (r !== "ok") degrade(r);
490
+ const dispatch = (o) => rowDispatch({ table, guard, objective: o, stratum });
491
+ const policyRow = dispatch(objective);
492
+ const drawRow = dispatch("cost");
493
+ if (policyRow.reason !== "ok") degrade(policyRow.reason);
408
494
  // With no guard the default cell is the only one: the guard cannot be
409
495
  // evaded by deleting it.
410
496
  const policy = policyRow.policy;
411
- let cell = baseRow.policy;
497
+ let cell = policy;
412
498
  let draw = null;
413
499
  let by = null;
414
500
  if (guard !== null) {
@@ -455,35 +541,39 @@ const round4 = (x) => Math.round(x * 1e4) / 1e4;
455
541
 
456
542
  /**
457
543
  * The fit's Pulls: pull-attribution.mjs's units over the window — booked as
458
- * routed, each to its own row's cell and stratum — restricted to rows the free
459
- * classifier routed plus exploration rows: a row a live B classifier routed is
460
- * the A/B's test set, not the fit's. The fit sees no PR state, so a Pull with
544
+ * routed, each to its own row's cell and group, `stratum` the walk from a
545
+ * features row to its group — restricted to rows the free classifier routed
546
+ * plus exploration rows: a row a live B classifier routed is the A/B's test
547
+ * set, not the fit's. The fit sees no PR state, so a Pull with
461
548
  * a Ruling is merged. A fit reads everything in the commit it is given: no row
462
549
  * is cut by date, because `--check` re-reads that same commit rather than
463
550
  * re-cutting the working tree's files. `order` ranks each cell's generations
464
551
  * over every Pull in the window, the restriction aside, so the fit names the
465
552
  * same newest generation the guard does.
466
553
  */
467
- function fitPulls({ features, members, verdicts, window }) {
468
- const all = attribute({ features, members, tiers: verdicts, windowStart: window || null, stratum: ruleStratum });
554
+ function fitPulls({ features, members, verdicts, window, stratum }) {
555
+ const all = attribute({ features, members, tiers: verdicts, windowStart: window || null, stratum });
469
556
  return { units: all.filter((u) => u.pull.exploration_draw !== "" || u.pull.sizing_src === "rule"), order: generations(all) };
470
557
  }
471
558
 
472
- // Per stratum and `*`, per cell, its newest generation's figures: `n` counted
559
+ // Per node of the tree, per cell, its newest generation's figures: `n` counted
473
560
  // Pulls, `merged`, $ per merged PR, minutes of work time per merged PR, false
474
561
  // claims over claims, fix rounds per merged PR, `by_hand` (the counted merged Pulls whose
475
562
  // Ruling was given by hand), and its left-out, unpriced and
476
563
  // untimed Pull counts. Both per merged PR figures take every counted Pull,
477
564
  // merged or not, over the merged ones. Beside them the cell's
478
565
  // excluded Pull count, `generation` naming the newest generation's model, and
479
- // `older`, each older generation's model to its figures, newest first. Beside
480
- // `estimates`, `pulls`: per stratum and `*`, per cell, the newest generation's
481
- // counted Pulls those figures are over.
482
- function estimate(units, order) {
566
+ // `older`, each older generation's model to its figures, newest first. A node's
567
+ // Pulls are those that went through it: the Pulls of its own group and of each
568
+ // group below it, so the root's are every Pull's. A node no Pull went through
569
+ // has none. Beside `estimates`, `pulls`: per node, per cell, the newest
570
+ // generation's counted Pulls those figures are over.
571
+ function estimate(units, order, nodes) {
483
572
  const estimates = {};
484
573
  const pulls = {};
485
- for (const s of units.length ? [...new Set([...units.map((u) => u.stratum), "*"])].sort() : []) {
486
- const mine = s === "*" ? units : units.filter((u) => u.stratum === s);
574
+ for (const s of nodes) {
575
+ const mine = s === "*" ? units : units.filter((u) => u.stratum === s || u.stratum.startsWith(`${s}${SEP}`));
576
+ if (mine.length === 0) continue;
487
577
  estimates[s] = {};
488
578
  pulls[s] = {};
489
579
  for (const t of tally(mine, order)) {
@@ -539,7 +629,7 @@ const JUDGE = Object.freeze({
539
629
  const unjudged = () => ({ cell: null, reason: "unjudged", cells: {}, pairs: [] });
540
630
 
541
631
  /**
542
- * One row's cell under one objective — the `*` row's or a stratum's — and
632
+ * One row's cell under one objective — a node's of the tree — and
543
633
  * why. The quality floor is held twice: pooled by the guard, whose trip takes
544
634
  * a cell out of every row and out of the exploration draw, and per row by the
545
635
  * fit, which refuses a cell under the floor that row alone. The floor is
@@ -641,45 +731,43 @@ function judgeSpeedRow(est, pulls, cells, tripped, costCell) {
641
731
  }
642
732
 
643
733
  /**
644
- * The re-fit table. `guard` is `{ tripped, n, window_start }` (readGuard's
734
+ * The re-fit table, over the tree `prior.splits` holds: the fit makes no split
735
+ * and takes none away. `guard` is `{ tripped, n, window_start }` (readGuard's
645
736
  * shape); `commit` is the sha of the commit the inputs were read from, or null
646
737
  * for the empty corpus before any fit. `rows` and `reasons` hold one set per
647
- * objective. `reasons.cost` holds `judgeRow()`'s record for `*` and for each
648
- * stratum with Pulls; a stratum whose record has no cell gets no `cost` row
649
- * and follows `*`, and an unjudged `*` is the default cell. `reasons.speed`
650
- * holds `judgeSpeedRow()`'s record for each row with a `cost` row, from that
651
- * row's cell, and an `unjudged` record with no cell for each stratum with no
652
- * `cost` row: a row with a `cost` row holds a `speed` row, the base when the
653
- * record has no cell, and a stratum with no `cost` row has no `speed` row
654
- * and follows `*`.
738
+ * objective, and each a row or record for every node. `reasons.cost` holds
739
+ * `judgeRow()`'s record, its `cell` the cell the node's `cost` row holds: a
740
+ * node whose record has no cell holds its parent's `cost` row, as a ticket
741
+ * there follows the parent, and an unjudged root holds the default cell.
742
+ * `reasons.speed` holds `judgeSpeedRow()`'s record for each node with a `cost`
743
+ * row of its own (the root always has one), from that row's cell, the base when
744
+ * the record has no cell; a node with none holds its parent's `speed` row and
745
+ * an `unjudged` record.
655
746
  */
656
747
  export function fitTable({ prior, features, members, verdicts, guard, commit = null }) {
657
748
  const window = guard.window_start ?? prior.window_start ?? null;
658
- const { units, order } = fitPulls({ features, members, verdicts, window });
659
- const { estimates, pulls } = estimate(units, order);
749
+ const nodes = treeNodes(prior.splits);
750
+ const { units, order } = fitPulls({ features, members, verdicts, window, stratum: (row) => stratumOf(prior, row) });
751
+ const { estimates, pulls } = estimate(units, order, nodes);
660
752
  const tripped = new Set(guard.tripped);
661
753
 
662
754
  let { stage, cells } = prior;
663
755
  cells = [...cells];
664
756
  // The rows and their reasons over `cells`: a fitted table's `reasons` cover exactly its `cells`.
665
757
  const judgeRows = () => {
666
- const star = judgeRow(estimates["*"], pulls["*"], cells, tripped);
667
- const rows = { cost: { "*": star.cell ?? POLICY_CELL }, speed: {} };
668
- const reasons = { cost: { "*": { ...star, cell: rows.cost["*"] } }, speed: {} };
669
- for (const s of STRATA) {
670
- if (!estimates[s]) continue;
671
- reasons.cost[s] = judgeRow(estimates[s], pulls[s], cells, tripped);
672
- if (reasons.cost[s].cell !== null) rows.cost[s] = reasons.cost[s].cell;
673
- }
674
- for (const s of Object.keys(reasons.cost)) {
675
- const costCell = rows.cost[s];
676
- if (costCell === undefined) {
677
- reasons.speed[s] = unjudged();
678
- continue;
679
- }
680
- const record = judgeSpeedRow(estimates[s], pulls[s], cells, tripped, costCell);
681
- rows.speed[s] = record.cell ?? costCell;
682
- reasons.speed[s] = { ...record, cell: rows.speed[s] };
758
+ const rows = { cost: {}, speed: {} };
759
+ const reasons = { cost: {}, speed: {} };
760
+ for (const s of nodes) {
761
+ const up = parentOf(s);
762
+ const cost = judgeRow(estimates[s], pulls[s], cells, tripped);
763
+ const own = cost.cell !== null || up === null;
764
+ const costCell = cost.cell ?? (up === null ? POLICY_CELL : rows.cost[up]);
765
+ const speed = own ? judgeSpeedRow(estimates[s], pulls[s], cells, tripped, costCell) : unjudged();
766
+ const speedCell = speed.cell ?? (own ? costCell : rows.speed[up]);
767
+ rows.cost[s] = costCell;
768
+ rows.speed[s] = speedCell;
769
+ reasons.cost[s] = { ...cost, cell: costCell };
770
+ reasons.speed[s] = { ...speed, cell: speedCell };
683
771
  }
684
772
  return { rows, reasons };
685
773
  };
@@ -701,6 +789,7 @@ export function fitTable({ prior, features, members, verdicts, guard, commit = n
701
789
  stage,
702
790
  cells,
703
791
  burn_in: !cells.every(atN),
792
+ splits: prior.splits,
704
793
  rows,
705
794
  classifier: prior.classifier,
706
795
  estimates,
@@ -721,7 +810,7 @@ export function mergedSince({ table, features, members, verdicts, fitted }) {
721
810
  .filter((u) => u.status === "counted" && u.merged && !read.has(`${u.pull.session}\0${u.pull.agent}`)).length;
722
811
  }
723
812
 
724
- // Each cell's Pull counts over every stratum, as the fit prints them: its
813
+ // Each cell's Pull counts over every Pull, the root's, as the fit prints them: its
725
814
  // newest generation, then each older one.
726
815
  function cellCounts(estimates) {
727
816
  const two = (x) => (x === null ? "-" : x.toFixed(2));
@@ -734,14 +823,13 @@ function cellCounts(estimates) {
734
823
  .join(", ") || "none";
735
824
  }
736
825
 
737
- // One line per row the fit judged or skipped, per objective: its cell (`-`
738
- // for a stratum that follows `*`) and its reason, then each candidate's
739
- // verdict and range.
826
+ // One line per row the fit judged, per objective: its cell and its reason,
827
+ // then each candidate's verdict and range.
740
828
  function rowLines(reasons) {
741
829
  const range = (r) => (r === null ? "" : ` [${r.map((x) => x.toFixed(2)).join(", ")}]`);
742
830
  return Object.entries(reasons).flatMap(([o, set]) => Object.entries(set).map(([s, r]) => {
743
831
  const cells = Object.entries(r.cells).map(([c, x]) => `${c} ${x.verdict}${range(x.range)}`).join(", ");
744
- return `${NAME}: row ${o} ${s} ${r.cell ?? "-"} ${r.reason}${cells ? ` (${cells})` : ""}\n`;
832
+ return `${NAME}: row ${o} ${s} ${r.cell} ${r.reason}${cells ? ` (${cells})` : ""}\n`;
745
833
  })).join("");
746
834
  }
747
835