@feigi/fleet-ctl 3.24.33 → 3.24.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.24.33",
3
+ "version": "3.24.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": {
@@ -38,14 +38,20 @@
38
38
  // listed as unbooked.
39
39
  //
40
40
  // A ticket's RULING is its last tier-outcomes.tsv row in file order dated on or
41
- // after its first Pull in the window; that row names the PR and carries the quality
42
- // verdict. The PR's CELL is the `chosen_cell` of the last Pull dated on or
43
- // before the ruling, cross-checked against that Pull's member row: a
44
- // `subagent_type` other than `fleet-implementer-<cell>`, or an `effort` other
45
- // than the cell's level, lists the PR under `mismatch` and books it to no cell
46
- // at all. A PR still OPEN is pending and booked nowhere yet. A Pull with no
47
- // ruling books to its own `chosen_cell` as unmerged spend — unless its member
48
- // opened a PR that is still open, which is pending too.
41
+ // after its first Pull in the window, skipping rows with both verdict columns
42
+ // blank, which were never ruled; that row names the PR and carries the quality
43
+ // verdict. A PR ruling several tickets takes its verdict from the later of
44
+ // their rulings in file order, whatever their dates. A ruling whose run_date is
45
+ // not YYYY-MM-DD is an input error (exit 2), as is one whose verdict is not
46
+ // yes or no. The PR's CELL is the `chosen_cell` of the last Pull booked to it
47
+ // — tickets in the order of their first Pull, each ticket's Pulls in file
48
+ // order, those dated on or before the ticket's ruling — cross-checked against
49
+ // that Pull's member row: a `subagent_type` other than
50
+ // `fleet-implementer-<cell>`, or an `effort` other than the cell's level,
51
+ // lists the PR under `mismatch` and books it to no cell at all. A PR still
52
+ // OPEN is pending and booked nowhere yet. A Pull with no ruling books to its
53
+ // own `chosen_cell` as unmerged spend — unless its member opened a PR that is
54
+ // still open, which is pending too.
49
55
  //
50
56
  // PER CELL: `n_pulls`; `n_merged`; `n_pass` (merged PRs passing the quality
51
57
  // floor — failure is `minted_false_claim=yes` or `closed_own_ticket=no`);
@@ -66,7 +72,7 @@ import { isCLI } from "./is-cli.mjs";
66
72
  import { CELL } from "./ledger-grammar.mjs";
67
73
  import { parseMemberName } from "./member-record.mjs";
68
74
  import { parseTsv as parseMemberTsv } from "./member-outcomes.mjs";
69
- import { parseTierOutcomes } from "./tier-outcomes.mjs";
75
+ import { RulingError, parseTierOutcomes, rulingFor, rulingsByTicket } from "./tier-outcomes.mjs";
70
76
 
71
77
  const NAME = "pr-cost";
72
78
  const SCRIPT_DIR = dirname(fileURLToPath(import.meta.url));
@@ -203,7 +209,10 @@ export function computeReport({ members, tiers, features, prs, routerTable = nul
203
209
  }
204
210
  }
205
211
 
206
- // Rulings: per ticket, the last tier-outcomes row in file order on or after its first Pull.
212
+ // Rulings: per ticket, `rulingFor` of the ticket's first Pull — the last
213
+ // ruling row in file order dated on or after it, both-blank rows skipped.
214
+ const rulings = rulingsByTicket(tiers);
215
+ const fileOrder = new Map(tiers.map((t, i) => [t, i]));
207
216
  const pullsByTicket = new Map();
208
217
  for (const p of pulls) {
209
218
  if (!pullsByTicket.has(p.ticket)) pullsByTicket.set(p.ticket, []);
@@ -212,11 +221,10 @@ export function computeReport({ members, tiers, features, prs, routerTable = nul
212
221
  const groups = new Map(); // pr -> { pr, tier, pulls[] }
213
222
  const unruled = [];
214
223
  for (const [ticket, ps] of pullsByTicket) {
215
- const first = ps[0].run_date;
216
- const ruling = tiers.filter((t) => t.ticket.split("+").includes(ticket) && t.run_date >= first).at(-1);
224
+ const ruling = rulingFor(rulings, ticket, ps[0].run_date);
217
225
  if (!ruling) { unruled.push(...ps); continue; }
218
226
  const g = groups.get(ruling.pr) ?? { pr: ruling.pr, tier: ruling, pulls: [] };
219
- if (ruling.run_date > g.tier.run_date) g.tier = ruling;
227
+ if (fileOrder.get(ruling) > fileOrder.get(g.tier)) g.tier = ruling;
220
228
  for (const p of ps) (p.run_date <= ruling.run_date ? g.pulls : unruled).push(p);
221
229
  groups.set(ruling.pr, g);
222
230
  }
@@ -476,7 +484,9 @@ function main() {
476
484
  // silently, so a full page is refused rather than trusted.
477
485
  if (prs.length >= GH_PR_LIMIT) die(`gh pr list returned ${prs.length} PRs, its cap — merged state may be truncated`);
478
486
 
479
- const report = computeReport({ members, tiers, features, prs, routerTable, pricing });
487
+ let report;
488
+ try { report = computeReport({ members, tiers, features, prs, routerTable, pricing }); }
489
+ catch (e) { if (e instanceof RulingError) die(`${tiersPath}: ${e.message}`); throw e; }
480
490
  process.stdout.write(has("json") ? JSON.stringify(report, null, 2) + "\n" : formatReport(report));
481
491
  if (!has("guard")) return;
482
492
  const file = arg("out") ?? defaultGuardPath();
@@ -155,22 +155,26 @@ export function lastPullByTicket(pulls) {
155
155
  return new Map(pulls.map((p) => [p.ticket, p]));
156
156
  }
157
157
 
158
+ // A ruling row `rulingFor` refuses, as opposed to a bug in `rulingFor` itself:
159
+ // a caller that reports bad input catches this class alone.
160
+ export class RulingError extends Error {}
161
+
158
162
  // The row ruling `ticket`'s Pull dated `pullDate`, from `rulingsByTicket`: its
159
163
  // last ruling in file order dated on or after the Pull, since a ruling never
160
- // predates the Pull it rules — or null. Throws on a ruling of the ticket whose
161
- // `run_date` is not YYYY-MM-DD, which cannot be placed against the Pull and
162
- // whose drop would uncount the ticket, and on the ruling it picks holding
163
- // anything but `yes` or `no` in a verdict column, which would otherwise read
164
- // as a pass.
164
+ // predates the Pull it rules — or null. Throws a `RulingError` on a ruling of
165
+ // the ticket whose `run_date` is not YYYY-MM-DD, which cannot be placed against
166
+ // the Pull and whose drop would uncount the ticket, and on the ruling it picks
167
+ // holding anything but `yes` or `no` in a verdict column, which would otherwise
168
+ // read as a pass.
165
169
  export function rulingFor(rulings, ticket, pullDate) {
166
170
  const own = rulings.get(String(ticket)) ?? [];
167
171
  for (const r of own) {
168
- if (!DATE.test(r.run_date)) throw new Error(`ticket #${ticket} (PR #${r.pr}): run_date is '${r.run_date}', expected YYYY-MM-DD`);
172
+ if (!DATE.test(r.run_date)) throw new RulingError(`ticket #${ticket} (PR #${r.pr}): run_date is '${r.run_date}', expected YYYY-MM-DD`);
169
173
  }
170
174
  const v = own.findLast((r) => r.run_date >= pullDate);
171
175
  if (!v) return null;
172
176
  for (const c of VERDICT_COLUMNS) {
173
- if (!VERDICT.includes(v[c])) throw new Error(`ticket #${ticket} (PR #${v.pr}): ${c} is '${v[c]}', expected yes or no`);
177
+ if (!VERDICT.includes(v[c])) throw new RulingError(`ticket #${ticket} (PR #${v.pr}): ${c} is '${v[c]}', expected yes or no`);
174
178
  }
175
179
  return v;
176
180
  }