@feigi/fleet-ctl 3.114.0 → 3.114.2

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.114.0",
3
+ "version": "3.114.2",
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": {
@@ -21,7 +21,7 @@ import { FleetDirUnresolvable } from "./fleet-dir.mjs";
21
21
  import { spawnSync } from "node:child_process";
22
22
  import { fileURLToPath } from "node:url";
23
23
  import { FIXED_SHA } from "./fleet-event.mjs";
24
- import { parseReport, reportViolation } from "./report-schema.mjs";
24
+ import { parseReport, reportViolation, SCHEMAS } from "./report-schema.mjs";
25
25
 
26
26
  export { normalizeModel, parseMemberName };
27
27
 
@@ -233,6 +233,16 @@ export function withReports(rows, scratch) {
233
233
  const IMPLEMENTER_LEAF = /^impl-\d+(?:-[a-z0-9]+)?$/;
234
234
  export const isImplementer = (member) => IMPLEMENTER_LEAF.test(member.split("/").pop());
235
235
 
236
+ // Every value endingOf() returns on an implementer's row: its own literals,
237
+ // `bail:<cause>` for each cause the impl schema admits, since lastReport()
238
+ // keeps only a report that schema accepts, and bailEnding()'s
239
+ // `bail:fixed-refuted`. A non-implementer's row reads blank, which is not here.
240
+ export const ENDINGS = new Set([
241
+ "pr", "blocked",
242
+ ...SCHEMAS.impl.properties.bailCause.enum.filter((c) => c !== null).map((c) => `bail:${c}`), "bail:fixed-refuted",
243
+ "provider", "budget", "abort", "crash", "hollow", "unknown",
244
+ ]);
245
+
236
246
  export function endingOf({ member, pr, signals = null, earlierPrs = new Set(), verifyMain = verifyMainWithGit }) {
237
247
  if (!isImplementer(member)) return "";
238
248
  if (pr) return "pr";
@@ -36,7 +36,16 @@
36
36
  // current width is not touched, so a second run changes nothing. Rows of any
37
37
  // other width, rows of mixed widths and git conflict markers fail the duty,
38
38
  // naming the file, and the file is left as it was; the cost guard after it does
39
- // not run.
39
+ // not run. So does a row whose cell breaks its column's grammar at the file's
40
+ // width (`run_date` blank or a date; the token, time, `turns` and `cost`
41
+ // columns blank or a non-negative decimal; `harness` omp or claude; `report`
42
+ // blank or a reportStatus() value; `ending` one of endingOf()'s values on an
43
+ // implementer's row, blank on any other), the failure naming the line and the
44
+ // leftmost column that breaks, with its value: a tab inside a cell on every
45
+ // row, or on the only one, makes the file look one column wider and moves each
46
+ // cell after it one column right. Its limit: a tab whose split halves still fit
47
+ // their columns' grammar is widened — a trailing tab in the last cell of a
48
+ // reviewer row is byte for byte a real row one column wider.
40
49
  //
41
50
  // COST GUARD. `pr-cost.mjs --guard` rewrites `.fleet/cost-guard.json`, which
42
51
  // the router reads and fails closed without. It needs all three metrics TSVs;
@@ -58,8 +67,9 @@ import { makeDie, defineFlags } from "./arg.mjs";
58
67
  import { gitEnv } from "./git-env.mjs";
59
68
  import { FleetDirUnresolvable, fleetFile } from "./fleet-dir.mjs";
60
69
  import { isCLI } from "./is-cli.mjs";
61
- import { COLUMNS as MEMBER_COLUMNS, isImplementer } from "./member-outcomes.mjs";
70
+ import { COLUMNS as MEMBER_COLUMNS, ENDINGS, isImplementer } from "./member-outcomes.mjs";
62
71
  import { FEATURE_COLUMNS, parseFeatures } from "./pull-attribution.mjs";
72
+ import { REPORT_STATUSES } from "./report-files.mjs";
63
73
 
64
74
  const NAME = "metrics-refresh";
65
75
  const PR_COST = fileURLToPath(new URL("./pr-cost.mjs", import.meta.url));
@@ -94,6 +104,28 @@ function widen(text, columns) {
94
104
  const MEMBER_FIRST_WIDTH = MEMBER_COLUMNS.indexOf("ending");
95
105
  const MEMBER_NAME_AT = MEMBER_COLUMNS.indexOf("member");
96
106
 
107
+ // The grammar of every member-outcomes column the widen checks, as [test(cell, cells), what it
108
+ // expected]. The free-text columns (`model`, `effort`, `member`, `agent`, `subagent_type`,
109
+ // `dispatch_model`) and `role` have none here, and neither does `work_s`: it is the current
110
+ // width's last column, so no width the widen reads reaches it. A blank `run_date` is unknown —
111
+ // rowsForSession() writes one when no transcript's mtime can be read, or every one is the epoch.
112
+ const DECIMAL = [(v) => /^(?:\d+(?:\.\d+)?)?$/.test(v), "blank or a non-negative decimal"];
113
+ const MEMBER_GRAMMAR = {
114
+ run_date: [(v) => /^(?:\d{4}-\d{2}-\d{2})?$/.test(v), "blank or a YYYY-MM-DD date"],
115
+ tokens_cache_create: DECIMAL, tokens_out: DECIMAL, wall_s: DECIMAL, turns: DECIMAL, tokens_in: DECIMAL,
116
+ tokens_cache_read: DECIMAL, tokens_cache_write_1h: DECIMAL, cost: DECIMAL,
117
+ harness: [(v) => v === "omp" || v === "claude", "omp or claude"],
118
+ report: [(v) => v === "" || REPORT_STATUSES.includes(v), `blank or one of ${REPORT_STATUSES.join(", ")}`],
119
+ ending: [
120
+ (v, cells) => (isImplementer(cells[MEMBER_NAME_AT]) ? ENDINGS.has(v) : v === ""),
121
+ "one of endingOf()'s values on an implementer's row, blank on any other",
122
+ ],
123
+ };
124
+ // In column order, so a row that breaks several columns is refused naming the leftmost.
125
+ const MEMBER_CHECKED = Object.entries(MEMBER_GRAMMAR)
126
+ .map(([c, [ok, what]]) => ({ c, at: MEMBER_COLUMNS.indexOf(c), ok, what }))
127
+ .sort((a, b) => a.at - b.at);
128
+
97
129
  // `text`, a member-outcomes TSV at an earlier width, at the current one, with the columns it
98
130
  // lacks appended to every row. The file has no header row, so a row's width is the only thing
99
131
  // that says which columns it holds; leading comments and every cell already there are kept.
@@ -101,9 +133,16 @@ const MEMBER_NAME_AT = MEMBER_COLUMNS.indexOf("member");
101
133
  // an implementer's row, where blank means "not an implementer": that reads `unknown`. Rows of
102
134
  // one width other than the current or an earlier one, and a file whose rows are not all of
103
135
  // one width, throw: parseTsv's refusal to guess a row's columns stands, and this does not
104
- // widen what it would not read. A row ending in a CR (a CRLF file) gains its cells before that
105
- // CR, which stays the row's last byte. A file with no rows comes back as `{ rows: 0 }`, and one
106
- // already at the current width as null: neither has anything to write.
136
+ // widen what it would not read. So does a row with a cell that breaks MEMBER_GRAMMAR for the
137
+ // column it sits in at that width, the error naming the leftmost such column: a tab inside a
138
+ // cell, on every row or the only one, makes a file look one column wider than it is and moves
139
+ // each cell after it one column right, where `agent` lands in `harness` and `cost` in
140
+ // `ending`. Its limit: a tab whose split halves still fit the grammar of the columns they land
141
+ // in is widened — a trailing tab in the last cell of a reviewer row is byte for byte a real row
142
+ // one column wider. A row ending in a CR (a CRLF file) is checked without that CR, and gains
143
+ // its cells before it, so the CR stays the row's last byte. A file with no rows comes back as
144
+ // `{ rows: 0 }`, and one already at the current width as null, unchecked: neither has anything
145
+ // to write.
107
146
  function widenMembers(text) {
108
147
  const lines = text.split("\n");
109
148
  const rows = [];
@@ -119,10 +158,16 @@ function widenMembers(text) {
119
158
  const row = lines[rows[0]];
120
159
  throw new Error(`malformed row: ${width} fields, expected ${MEMBER_COLUMNS.length} (or an earlier ${MEMBER_FIRST_WIDTH} to ${MEMBER_COLUMNS.length - 1}) — ${row.slice(0, 60)}`);
121
160
  }
161
+ const checked = MEMBER_CHECKED.filter(({ at }) => at < width);
122
162
  const added = MEMBER_COLUMNS.slice(width);
123
163
  for (const i of rows) {
124
164
  const eol = lines[i].endsWith("\r") ? "\r" : "";
125
165
  const cells = lines[i].slice(0, lines[i].length - eol.length).split("\t");
166
+ const bad = checked.find(({ at, ok }) => !ok(cells[at], cells));
167
+ if (bad) {
168
+ throw new Error(`line ${i + 1}: \`${bad.c}\` is ${JSON.stringify(cells[bad.at])}, expected ${bad.what}, read at ${width} columns`
169
+ + ` — a tab inside a cell, or a hand edit, moves every cell after it one column — ${lines[i].slice(0, 60)}`);
170
+ }
126
171
  lines[i] = [...cells, ...added.map((c) => (c === "ending" && isImplementer(cells[MEMBER_NAME_AT]) ? "unknown" : ""))].join("\t") + eol;
127
172
  }
128
173
  return { text: lines.join("\n"), width, rows: rows.length };
@@ -118,6 +118,9 @@ export function readReportIn(dir, member) {
118
118
  return violation === null ? { state: "ok", path, report: parsed.value } : { state: "invalid", path, violation };
119
119
  }
120
120
 
121
+ /** Every value reportStatus() returns: readReport()'s three states, and `-`. */
122
+ export const REPORT_STATUSES = ["ok", "invalid", "absent", "-"];
123
+
121
124
  /** `ok`, `invalid`, `absent`, or `-` when no schema covers the member. */
122
125
  export function reportStatus(scratch, member) {
123
126
  return reportFamily(member) === null ? "-" : readReport(scratch, member).state;