@feigi/fleet-ctl 3.110.1 → 3.110.3
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
|
@@ -396,7 +396,7 @@ export function parseTsv(text) {
|
|
|
396
396
|
});
|
|
397
397
|
}
|
|
398
398
|
|
|
399
|
-
import { writeFileSync, existsSync, renameSync } from "node:fs";
|
|
399
|
+
import { writeFileSync, existsSync, mkdirSync, renameSync } from "node:fs";
|
|
400
400
|
import { isCLI } from "./is-cli.mjs";
|
|
401
401
|
import { makeDie, isFlagLike } from "./arg.mjs";
|
|
402
402
|
|
|
@@ -499,6 +499,7 @@ if (isCLI(import.meta.url)) {
|
|
|
499
499
|
// Write-then-rename: writeFileSync truncates before it writes, so an interrupt
|
|
500
500
|
// over the committed corpus left a torn file that the NEXT scrape read, merged
|
|
501
501
|
// and rewrote — losing every other session's rows for good.
|
|
502
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
502
503
|
writeFileSync(file + ".tmp", (header ? header + "\n" : "") + formatTsv(merged));
|
|
503
504
|
renameSync(file + ".tmp", file);
|
|
504
505
|
// Report the SCRAPE, not just the file. `merged.length` is the whole corpus,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// The run's
|
|
3
|
-
// pending ticket-features rows into the tracked corpus,
|
|
4
|
-
// guard over it.
|
|
2
|
+
// The run's three metrics duties that keep the router's inputs current: move the
|
|
3
|
+
// pending ticket-features rows into the tracked corpus, widen a member-outcomes
|
|
4
|
+
// corpus written before its latest columns, then refresh the cost guard over it.
|
|
5
5
|
//
|
|
6
6
|
// metrics-refresh.mjs [--repo <dir>]
|
|
7
7
|
//
|
|
@@ -24,6 +24,20 @@
|
|
|
24
24
|
// rule, but phase 0 refuses a second one at its ledger rotation, which runs
|
|
25
25
|
// after its drain step, so a second controller's drain is not guarded.
|
|
26
26
|
//
|
|
27
|
+
// MEMBER-OUTCOMES WIDEN. `member-outcomes.mjs` refuses a row that is not exactly
|
|
28
|
+
// as wide as its current columns, so a consumer's `docs/metrics/member-outcomes.tsv`
|
|
29
|
+
// written before `ending`, `dispatch_model` or `work_s` shipped (20, 21 or 22
|
|
30
|
+
// columns; the file has no header row, so width is all that tells) could not be
|
|
31
|
+
// read by phase 0, the close-out scrape or `tier-outcomes.mjs append`. This
|
|
32
|
+
// appends the missing columns to every row, so every consumer widens at its next
|
|
33
|
+
// run start. Cells already there and the leading comments stay as written; an
|
|
34
|
+
// added cell is blank (unknown), except `ending` on an implementer's row, which
|
|
35
|
+
// is `unknown`, because blank there means "not an implementer". A file at the
|
|
36
|
+
// current width is not touched, so a second run changes nothing. Rows of any
|
|
37
|
+
// other width, rows of mixed widths and git conflict markers fail the duty,
|
|
38
|
+
// naming the file, and the file is left as it was; the cost guard after it does
|
|
39
|
+
// not run.
|
|
40
|
+
//
|
|
27
41
|
// COST GUARD. `pr-cost.mjs --guard` rewrites `.fleet/cost-guard.json`, which
|
|
28
42
|
// the router reads and fails closed without. It needs all three metrics TSVs;
|
|
29
43
|
// a workspace that lacks one has no corpus to guard yet (its first run), so the
|
|
@@ -32,8 +46,8 @@
|
|
|
32
46
|
// (no verdict yet — the baseline cell has too few merged PRs) are verdicts the
|
|
33
47
|
// router and `fleet-tick.mjs` consume, not failures; any other non-zero exit is.
|
|
34
48
|
//
|
|
35
|
-
// One `metrics-refresh: <duty>: …` line per duty on stdout. Exit 0 when
|
|
36
|
-
//
|
|
49
|
+
// One `metrics-refresh: <duty>: …` line per duty on stdout. Exit 0 when no
|
|
50
|
+
// duty failed; 1 when one failed — named on stderr, and the duties after
|
|
37
51
|
// it did not run (each is safe to run again); 2 on a usage error.
|
|
38
52
|
|
|
39
53
|
import { spawnSync } from "node:child_process";
|
|
@@ -44,13 +58,15 @@ import { makeDie, defineFlags } from "./arg.mjs";
|
|
|
44
58
|
import { gitEnv } from "./git-env.mjs";
|
|
45
59
|
import { FleetDirUnresolvable, fleetFile } from "./fleet-dir.mjs";
|
|
46
60
|
import { isCLI } from "./is-cli.mjs";
|
|
61
|
+
import { COLUMNS as MEMBER_COLUMNS, isImplementer } from "./member-outcomes.mjs";
|
|
47
62
|
import { FEATURE_COLUMNS, parseFeatures } from "./pull-attribution.mjs";
|
|
48
63
|
|
|
49
64
|
const NAME = "metrics-refresh";
|
|
50
65
|
const PR_COST = fileURLToPath(new URL("./pr-cost.mjs", import.meta.url));
|
|
51
66
|
const PENDING = join(".fleet", "ticket-features.pending.tsv");
|
|
52
67
|
const FEATURES = join("docs", "metrics", "ticket-features.tsv");
|
|
53
|
-
const
|
|
68
|
+
const MEMBERS = join("docs", "metrics", "member-outcomes.tsv");
|
|
69
|
+
const CORPUS = [MEMBERS, join("docs", "metrics", "tier-outcomes.tsv"), FEATURES];
|
|
54
70
|
const GUARD = join(".fleet", "cost-guard.json");
|
|
55
71
|
// pr-cost.mjs --guard: 0 no cell tripped, 3 a cell tripped, 4 no verdict yet —
|
|
56
72
|
// all three are verdicts its readers consume; anything else is a failure.
|
|
@@ -72,6 +88,62 @@ function widen(text, columns) {
|
|
|
72
88
|
}).join("\n");
|
|
73
89
|
}
|
|
74
90
|
|
|
91
|
+
// The first width a member-outcomes.tsv was ever written at that a later column widened: the
|
|
92
|
+
// width before `ending` shipped (merged 2026-10-22). Every width from it up to the current
|
|
93
|
+
// one is a file of this corpus written before the columns past that width existed.
|
|
94
|
+
const MEMBER_FIRST_WIDTH = MEMBER_COLUMNS.indexOf("ending");
|
|
95
|
+
const MEMBER_NAME_AT = MEMBER_COLUMNS.indexOf("member");
|
|
96
|
+
|
|
97
|
+
// `text`, a member-outcomes TSV at an earlier width, at the current one, with the columns it
|
|
98
|
+
// lacks appended to every row. The file has no header row, so a row's width is the only thing
|
|
99
|
+
// that says which columns it holds; leading comments and every cell already there are kept.
|
|
100
|
+
// An appended cell is blank, which that file's own rule reads as unknown — except `ending` on
|
|
101
|
+
// an implementer's row, where blank means "not an implementer": that reads `unknown`. Rows of
|
|
102
|
+
// one width other than the current or an earlier one, and a file whose rows are not all of
|
|
103
|
+
// 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.
|
|
107
|
+
function widenMembers(text) {
|
|
108
|
+
const lines = text.split("\n");
|
|
109
|
+
const rows = [];
|
|
110
|
+
lines.forEach((l, i) => { if (l.trim() && !l.startsWith("#")) rows.push(i); });
|
|
111
|
+
if (!rows.length) return { rows: 0 };
|
|
112
|
+
const markerAt = rows.find((i) => /^(<{7}|={7}|>{7})( |\r?$)/.test(lines[i]));
|
|
113
|
+
if (markerAt !== undefined) throw new Error(`git conflict marker — ${lines[markerAt].slice(0, 60)}`);
|
|
114
|
+
const widths = [...new Set(rows.map((i) => lines[i].split("\t").length))].sort((a, b) => a - b);
|
|
115
|
+
if (widths.length > 1) throw new Error(`rows of different widths (${widths.join(", ")}) — a file is written at one width`);
|
|
116
|
+
const [width] = widths;
|
|
117
|
+
if (width === MEMBER_COLUMNS.length) return null;
|
|
118
|
+
if (width < MEMBER_FIRST_WIDTH || width > MEMBER_COLUMNS.length) {
|
|
119
|
+
const row = lines[rows[0]];
|
|
120
|
+
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
|
+
}
|
|
122
|
+
const added = MEMBER_COLUMNS.slice(width);
|
|
123
|
+
for (const i of rows) {
|
|
124
|
+
const eol = lines[i].endsWith("\r") ? "\r" : "";
|
|
125
|
+
const cells = lines[i].slice(0, lines[i].length - eol.length).split("\t");
|
|
126
|
+
lines[i] = [...cells, ...added.map((c) => (c === "ending" && isImplementer(cells[MEMBER_NAME_AT]) ? "unknown" : ""))].join("\t") + eol;
|
|
127
|
+
}
|
|
128
|
+
return { text: lines.join("\n"), width, rows: rows.length };
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function widenMemberOutcomes(repo) {
|
|
132
|
+
const file = join(repo, MEMBERS);
|
|
133
|
+
if (!existsSync(file)) return say(`member-outcomes: skipped, ${MEMBERS} not found — no corpus to widen yet`);
|
|
134
|
+
let widened;
|
|
135
|
+
try {
|
|
136
|
+
widened = widenMembers(readFileSync(file, "utf8"));
|
|
137
|
+
} catch (e) {
|
|
138
|
+
throw new Error(`${MEMBERS}: ${e.message}`);
|
|
139
|
+
}
|
|
140
|
+
if (widened === null) return say(`member-outcomes: already ${MEMBER_COLUMNS.length} columns`);
|
|
141
|
+
if (widened.rows === 0) return say("member-outcomes: no rows to widen");
|
|
142
|
+
writeFileSync(`${file}.tmp`, widened.text);
|
|
143
|
+
renameSync(`${file}.tmp`, file);
|
|
144
|
+
say(`member-outcomes: widened ${widened.rows} row${widened.rows === 1 ? "" : "s"} from ${widened.width} to ${MEMBER_COLUMNS.length} columns`);
|
|
145
|
+
}
|
|
146
|
+
|
|
75
147
|
function drain(repo) {
|
|
76
148
|
const pending = join(repo, PENDING);
|
|
77
149
|
if (!existsSync(pending)) return say(`drain: nothing pending in ${PENDING}`);
|
|
@@ -140,7 +212,7 @@ function main() {
|
|
|
140
212
|
die(`${e.message} — pass --repo <dir>`);
|
|
141
213
|
}
|
|
142
214
|
}
|
|
143
|
-
for (const [name, duty] of [["drain", drain], ["cost guard", costGuard]]) {
|
|
215
|
+
for (const [name, duty] of [["drain", drain], ["member-outcomes", widenMemberOutcomes], ["cost guard", costGuard]]) {
|
|
144
216
|
try {
|
|
145
217
|
duty(repo);
|
|
146
218
|
} catch (e) {
|
|
@@ -113,7 +113,7 @@
|
|
|
113
113
|
// verdict flags is derived when its evidence is still in scratch, and
|
|
114
114
|
// otherwise refused with the flags to give.
|
|
115
115
|
|
|
116
|
-
import { appendFileSync, existsSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
116
|
+
import { appendFileSync, existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
117
117
|
import { execFileSync } from "node:child_process";
|
|
118
118
|
import { dirname, join } from "node:path";
|
|
119
119
|
import { fileURLToPath } from "node:url";
|
|
@@ -889,8 +889,10 @@ function append(pr, paths) {
|
|
|
889
889
|
}
|
|
890
890
|
|
|
891
891
|
const line = formatRow({ ...fields, run_date: today(), pr, ticket, tier: resolved.tier });
|
|
892
|
-
if (text === null)
|
|
893
|
-
|
|
892
|
+
if (text === null) {
|
|
893
|
+
mkdirSync(dirname(paths.file), { recursive: true });
|
|
894
|
+
writeFileSync(paths.file, `# ${COLUMNS.join("\t")}\n${line}\n`);
|
|
895
|
+
} else appendFileSync(paths.file, `${text === "" || text.endsWith("\n") ? "" : "\n"}${line}\n`);
|
|
894
896
|
console.log(line);
|
|
895
897
|
}
|
|
896
898
|
|
|
@@ -106,11 +106,13 @@ moves `.fleet/ticket-features.pending.tsv` — the row the router script
|
|
|
106
106
|
appended for each Pull at dispatch — into `docs/metrics/ticket-features.tsv`,
|
|
107
107
|
deduped on `session`+`agent`, so this run's own rows are in the file that gets
|
|
108
108
|
committed; that file is a run artifact too and is committed with the other
|
|
109
|
-
two. It then
|
|
110
|
-
|
|
109
|
+
two. It then widens a `docs/metrics/member-outcomes.tsv` written before the
|
|
110
|
+
newest columns, as at phase 0 — a file already at the current width is left
|
|
111
|
+
as it is — and then runs `pr-cost.mjs --guard`, which rewrites
|
|
112
|
+
`.fleet/cost-guard.json` from all three files. Exit 0: every duty ran. The guard's
|
|
111
113
|
own exit 3 (a cell tripped) and 4 (no verdict yet, baseline too thin) are
|
|
112
114
|
verdicts the router and `fleet-tick.mjs` read, never failures; the script
|
|
113
|
-
absorbs them. Exit 1 names the duty that failed on stderr and the
|
|
115
|
+
absorbs them. Exit 1 names the duty that failed on stderr and the duties after it
|
|
114
116
|
did not run; exit 2 is a usage error. At close-out a failure fails the
|
|
115
117
|
`metrics` step of `closeout.mjs finish`, so `commit-and-pr` stays pending: fix
|
|
116
118
|
the cause and run `finish` again — the pending file stays in `.fleet/` and the
|
|
@@ -162,7 +162,11 @@ script absorbs them. A workspace that lacks one of the three metrics TSVs
|
|
|
162
162
|
has no corpus to guard yet — its first run: the script prints a line naming
|
|
163
163
|
the missing file, skips the guard and exits 0. Exit 1 or 2 stops the run
|
|
164
164
|
before its first Pull: report the line the script printed on stderr, fix
|
|
165
|
-
the cause and run it again — each duty is safe to repeat.
|
|
165
|
+
the cause and run it again — each duty is safe to repeat. Between the drain
|
|
166
|
+
and the guard the script also widens a `docs/metrics/member-outcomes.tsv`
|
|
167
|
+
written before the newest columns: each row gains them, `ending` reads
|
|
168
|
+
`unknown` on an implementer's row, and nothing else changes. Without that,
|
|
169
|
+
phase 0, the close-out scrape and `tier-outcomes.mjs append` refuse the file.
|
|
166
170
|
|
|
167
171
|
## Launch the cockpit
|
|
168
172
|
|