@feigi/fleet-ctl 0.0.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/.claude-plugin/plugin.json +9 -0
- package/LICENSE +202 -0
- package/NOTICE +18 -0
- package/agents/fleet-finisher.agent.md +7 -0
- package/agents/fleet-implementer-alt.agent.md +210 -0
- package/agents/fleet-implementer.agent.md +210 -0
- package/agents/fleet-merge-bot.agent.md +7 -0
- package/agents/fleet-review-comments.agent.md +40 -0
- package/agents/fleet-review-correctness.agent.md +43 -0
- package/agents/fleet-review-runner.agent.md +73 -0
- package/agents/fleet-review-silent-failure.agent.md +49 -0
- package/agents/fleet-review-simplify.agent.md +46 -0
- package/agents/fleet-review-snapshot.agent.md +24 -0
- package/agents/fleet-review-tests.agent.md +46 -0
- package/agents/fleet-review-types.agent.md +41 -0
- package/agents/fleet-review-verifier.agent.md +29 -0
- package/commands/review-and-fix.md +98 -0
- package/commands/run-merge-bot.md +357 -0
- package/commands/run-team-help.md +17 -0
- package/package.json +23 -0
- package/scripts/agent-test-dir-prose.test.mjs +59 -0
- package/scripts/agent-test.test.mjs +1636 -0
- package/scripts/ambient-git-vars-mjs-prose.test.mjs +354 -0
- package/scripts/ambient-git-vars-prose.test.mjs +192 -0
- package/scripts/ancestry-check-position-prose.test.mjs +175 -0
- package/scripts/apply-ruleset.test.mjs +420 -0
- package/scripts/arg-header-probes-prose.test.mjs +393 -0
- package/scripts/arg.mjs +600 -0
- package/scripts/arg.test.mjs +1354 -0
- package/scripts/board-cli.test.mjs +694 -0
- package/scripts/board-identity.test.mjs +429 -0
- package/scripts/board-liveness-banner.test.mjs +119 -0
- package/scripts/board-prev-shape.test.mjs +229 -0
- package/scripts/board-tryparse-null.test.mjs +119 -0
- package/scripts/board.html +471 -0
- package/scripts/board.mjs +2037 -0
- package/scripts/board.test.mjs +3086 -0
- package/scripts/brief-after-cut-prose.test.mjs +53 -0
- package/scripts/candidates-exit3-prose.test.mjs +302 -0
- package/scripts/candidates.mjs +674 -0
- package/scripts/candidates.test.mjs +2101 -0
- package/scripts/caveat-unification-prose.test.mjs +98 -0
- package/scripts/ci-comment-rot-prose.test.mjs +2025 -0
- package/scripts/ci-completes-premise-prose.test.mjs +257 -0
- package/scripts/ci-state-prose.test.mjs +113 -0
- package/scripts/ci-state.mjs +761 -0
- package/scripts/ci-state.test.mjs +1640 -0
- package/scripts/ci-vacuous-green.test.mjs +368 -0
- package/scripts/citation-sweep-prose.test.mjs +1572 -0
- package/scripts/claim-lifecycle.test.mjs +185 -0
- package/scripts/claim-ticket.sh +417 -0
- package/scripts/claim-ticket.test.mjs +1121 -0
- package/scripts/closing-keyword-prose.test.mjs +193 -0
- package/scripts/cockpit-launch-idempotent-prose.test.mjs +165 -0
- package/scripts/cockpit-tick-nonblocking.test.mjs +210 -0
- package/scripts/compute-board.mjs +579 -0
- package/scripts/compute-board.test.mjs +1060 -0
- package/scripts/compute-spend.mjs +329 -0
- package/scripts/compute-spend.test.mjs +451 -0
- package/scripts/cross-repo-citation-prose.test.mjs +156 -0
- package/scripts/cwd-isolation-pins.mjs +83 -0
- package/scripts/dedupe-guard-prose.test.mjs +243 -0
- package/scripts/derive-testcmd.sh +239 -0
- package/scripts/derive-testcmd.test.mjs +380 -0
- package/scripts/diff-stats.mjs +231 -0
- package/scripts/diff-stats.test.mjs +408 -0
- package/scripts/dispatch-block-golden-prose.test.mjs +1024 -0
- package/scripts/dispatch-block-pins-prose.test.mjs +615 -0
- package/scripts/drop-merged-label.sh +173 -0
- package/scripts/drop-merged-label.test.mjs +480 -0
- package/scripts/expected-jobs-prose.test.mjs +80 -0
- package/scripts/filing-bar-seat-prose.test.mjs +242 -0
- package/scripts/filing-claim-bar-prose.test.mjs +166 -0
- package/scripts/finisher-dispatch-premise-prose.test.mjs +312 -0
- package/scripts/finisher-halt-prose.test.mjs +106 -0
- package/scripts/finisher-name-prose.test.mjs +134 -0
- package/scripts/finisher-own-tree-prose.test.mjs +285 -0
- package/scripts/finisher-pin-race-prose.test.mjs +339 -0
- package/scripts/fix-applier-correction-rules-prose.test.mjs +201 -0
- package/scripts/fix-applier-result-file-prose.test.mjs +100 -0
- package/scripts/fleet-bootstrap +155 -0
- package/scripts/fleet-heartbeat.mjs +272 -0
- package/scripts/fleet-heartbeat.test.mjs +450 -0
- package/scripts/fleet-provenance +207 -0
- package/scripts/fleet-provenance.test.mjs +64 -0
- package/scripts/fleet-run +148 -0
- package/scripts/fleet-run.test.mjs +90 -0
- package/scripts/fleet-state.mjs +400 -0
- package/scripts/fleet-state.test.mjs +373 -0
- package/scripts/fleet-tick-prose.test.mjs +299 -0
- package/scripts/fleet-tick.mjs +832 -0
- package/scripts/fleet-tick.test.mjs +1332 -0
- package/scripts/force-with-lease-reason-prose.test.mjs +184 -0
- package/scripts/frontmatter-allowlist.json +64 -0
- package/scripts/frontmatter-check.mjs +256 -0
- package/scripts/frontmatter-check.test.mjs +436 -0
- package/scripts/git-env.mjs +124 -0
- package/scripts/git-env.test.mjs +149 -0
- package/scripts/git-status-untracked-mode-sweep.test.mjs +216 -0
- package/scripts/gone-walk.test.mjs +213 -0
- package/scripts/gp-sep-invariant-prose.test.mjs +188 -0
- package/scripts/head-moved-after-label-prose.test.mjs +233 -0
- package/scripts/immutable-body-claim-prose.test.mjs +413 -0
- package/scripts/implementer-model-tier.test.mjs +643 -0
- package/scripts/inflight-citation-prose.test.mjs +144 -0
- package/scripts/inflight-exit2-prose.test.mjs +81 -0
- package/scripts/inflight-probe-guard-prose.test.mjs +109 -0
- package/scripts/inflight-scan-scope-prose.test.mjs +57 -0
- package/scripts/inflight.sh +1106 -0
- package/scripts/inflight.test.mjs +2984 -0
- package/scripts/injection-control-prose.test.mjs +404 -0
- package/scripts/install-root-audit.test.mjs +464 -0
- package/scripts/instrument-check-prose.test.mjs +235 -0
- package/scripts/instruments.sh +394 -0
- package/scripts/instruments.test.mjs +787 -0
- package/scripts/issue-tracker-prose.test.mjs +71 -0
- package/scripts/json.sh +248 -0
- package/scripts/json.test.mjs +364 -0
- package/scripts/ledger-dispatch.test.mjs +516 -0
- package/scripts/ledger-grammar.mjs +85 -0
- package/scripts/ledger-grammar.test.mjs +142 -0
- package/scripts/ledger-read-require-file.test.mjs +197 -0
- package/scripts/ledger.mjs +1753 -0
- package/scripts/ledger.test.mjs +3554 -0
- package/scripts/line-distance-prose.test.mjs +245 -0
- package/scripts/liveness-rationale-prose.test.mjs +83 -0
- package/scripts/locale-pin-prose.test.mjs +189 -0
- package/scripts/member-outcome-prose.test.mjs +167 -0
- package/scripts/member-outcomes-header.test.mjs +148 -0
- package/scripts/member-outcomes-prose.test.mjs +63 -0
- package/scripts/member-outcomes.mjs +231 -0
- package/scripts/member-outcomes.test.mjs +507 -0
- package/scripts/member-prompt-prose.test.mjs +161 -0
- package/scripts/member-record.mjs +605 -0
- package/scripts/member-record.test.mjs +516 -0
- package/scripts/member-write-guard.mjs +279 -0
- package/scripts/member-write-guard.test.mjs +211 -0
- package/scripts/merge-commit-probe-prose.test.mjs +122 -0
- package/scripts/merge-gate.mjs +262 -0
- package/scripts/merge-gate.test.mjs +613 -0
- package/scripts/muted-git-guard-sweep.test.mjs +493 -0
- package/scripts/net-ssh-precedence-prose.test.mjs +91 -0
- package/scripts/net-watchdog-prose.test.mjs +79 -0
- package/scripts/net.sh +409 -0
- package/scripts/net.test.mjs +211 -0
- package/scripts/no-ci-gate-prose.test.mjs +108 -0
- package/scripts/no-undo-audit.sh +1134 -0
- package/scripts/no-undo-audit.test.mjs +3965 -0
- package/scripts/no-wave.test.mjs +138 -0
- package/scripts/node-floor-sweep.test.mjs +611 -0
- package/scripts/pointer-target-prose.test.mjs +186 -0
- package/scripts/pr-overlap.mjs +417 -0
- package/scripts/pr-overlap.test.mjs +695 -0
- package/scripts/printf-die-sweep.test.mjs +384 -0
- package/scripts/prompt-renderer.mjs +39 -0
- package/scripts/prompt-renderer.test.mjs +68 -0
- package/scripts/prose-pin.mjs +808 -0
- package/scripts/prose-pin.test.mjs +1034 -0
- package/scripts/prove-merge.sh +228 -0
- package/scripts/prove-merge.test.mjs +995 -0
- package/scripts/pull-table-relabel-prose.test.mjs +60 -0
- package/scripts/quiet-payload-prose.test.mjs +222 -0
- package/scripts/reap.sh +1768 -0
- package/scripts/reap.test.mjs +4395 -0
- package/scripts/reaping-prose.test.mjs +159 -0
- package/scripts/refuter-scratch-prose.test.mjs +135 -0
- package/scripts/release-label-required-prose.test.mjs +71 -0
- package/scripts/release-label-split-prose.test.mjs +169 -0
- package/scripts/release-ticket.sh +1716 -0
- package/scripts/release-ticket.test.mjs +5106 -0
- package/scripts/renovate-release-contract.test.mjs +379 -0
- package/scripts/repo-root.mjs +544 -0
- package/scripts/repo-root.test.mjs +873 -0
- package/scripts/reporter-output-rule-prose.test.mjs +208 -0
- package/scripts/review-agent-report-only.test.mjs +49 -0
- package/scripts/review-core-cwd-isolation.test.mjs +374 -0
- package/scripts/review-core-reads.test.mjs +478 -0
- package/scripts/review-core-refuter-scratch.test.mjs +148 -0
- package/scripts/review-core-snapshot-path.test.mjs +777 -0
- package/scripts/review-core-specialist-scratch.test.mjs +189 -0
- package/scripts/review-core-testcmd.test.mjs +288 -0
- package/scripts/review-core-unrun.test.mjs +530 -0
- package/scripts/review-core-unverified-discriminant.test.mjs +208 -0
- package/scripts/review-core.mjs +1028 -0
- package/scripts/review-eval-resolver-path.test.mjs +55 -0
- package/scripts/review-eval.mjs +197 -0
- package/scripts/review-host-fixture.mjs +73 -0
- package/scripts/review-in-run-retry.test.mjs +187 -0
- package/scripts/review-no-vendor-dispatch.test.mjs +45 -0
- package/scripts/review-path-default.test.mjs +796 -0
- package/scripts/review-runner-spawns.test.mjs +93 -0
- package/scripts/review-runner.test.mjs +155 -0
- package/scripts/review-tier-audit.test.mjs +140 -0
- package/scripts/run-artifact-pr-prose.test.mjs +341 -0
- package/scripts/run-merge-bot-prose.test.mjs +1391 -0
- package/scripts/scratch-partition-invariant-prose.test.mjs +74 -0
- package/scripts/scripts-path-citation-sweep.test.mjs +73 -0
- package/scripts/section-between-guard-prose.test.mjs +378 -0
- package/scripts/select-dimensions.test.mjs +674 -0
- package/scripts/shared-refusal.test.mjs +388 -0
- package/scripts/shell-traps-prose.test.mjs +507 -0
- package/scripts/shortlist.mjs +355 -0
- package/scripts/shortlist.test.mjs +366 -0
- package/scripts/slow-transport.mjs +72 -0
- package/scripts/snapshot-repo.test.mjs +772 -0
- package/scripts/snapshot-runner-audience-prose.test.mjs +129 -0
- package/scripts/spend-view.test.mjs +312 -0
- package/scripts/staleness-qualifier-prose.test.mjs +251 -0
- package/scripts/staleness-verdict-prose.test.mjs +142 -0
- package/scripts/staleness.mjs +414 -0
- package/scripts/staleness.test.mjs +893 -0
- package/scripts/stalled-member-liveness-prose.test.mjs +219 -0
- package/scripts/stash-prohibition-prose.test.mjs +313 -0
- package/scripts/strip-comments.mjs +44 -0
- package/scripts/tier-check.mjs +468 -0
- package/scripts/tier-check.test.mjs +726 -0
- package/scripts/tier-guard-gate-prose.test.mjs +216 -0
- package/scripts/tier-outcomes-header.test.mjs +586 -0
- package/scripts/tier-outcomes.mjs +441 -0
- package/scripts/tier-outcomes.test.mjs +342 -0
- package/scripts/tier-roles.mjs +250 -0
- package/scripts/tier-roles.test.mjs +316 -0
- package/scripts/tracker-block-copy-prose.test.mjs +288 -0
- package/scripts/triage-labels-gloss-prose.test.mjs +97 -0
- package/scripts/unattended-git-sweep.test.mjs +142 -0
- package/scripts/verify-sha-exit2-prose.test.mjs +269 -0
- package/scripts/verify-sha.sh +117 -0
- package/scripts/verify-sha.test.mjs +693 -0
- package/scripts/watcher-degraded-block.test.mjs +372 -0
- package/scripts/watcher-key-prose.test.mjs +106 -0
- package/scripts/within-run-pair-prose.test.mjs +208 -0
- package/scripts/worktree-audit.sh +482 -0
- package/scripts/worktree-audit.test.mjs +1407 -0
- package/scripts/worktree-head-prose.test.mjs +276 -0
- package/scripts/worktree-listing-sweep.test.mjs +217 -0
- package/scripts/worktree-model-prose.test.mjs +216 -0
- package/scripts/worktree.sh +470 -0
- package/skills/next-ticket/SKILL.md +138 -0
- package/skills/run-team/SKILL.md +3603 -0
- package/skills/run-team/references/ci-and-staleness.md +75 -0
- package/skills/run-team/references/correction-tickets.md +37 -0
- package/skills/run-team/references/isolation.md +23 -0
- package/skills/run-team/references/member-lifecycle.md +73 -0
- package/skills/run-team/references/reaping.md +73 -0
- package/skills/sizing-a-ticket/SKILL.md +39 -0
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
// #2207: tier-outcomes.mjs writes the `tier` column instead of the controller
|
|
2
|
+
// typing it, and `check` compares it with what actually ran. Driven through
|
|
3
|
+
// the CLI against fixture files: the resolution order, the blank reasons and
|
|
4
|
+
// the idempotency are all observable only there, and `gh` is a PATH stub that
|
|
5
|
+
// logs every call so the no-op run can prove it never asked.
|
|
6
|
+
import { test } from "node:test";
|
|
7
|
+
import assert from "node:assert/strict";
|
|
8
|
+
import { spawnSync } from "node:child_process";
|
|
9
|
+
import { mkdtempSync, mkdirSync, rmSync, writeFileSync, readFileSync, chmodSync, existsSync } from "node:fs";
|
|
10
|
+
import { tmpdir } from "node:os";
|
|
11
|
+
import { join } from "node:path";
|
|
12
|
+
import { fileURLToPath } from "node:url";
|
|
13
|
+
import { COLUMNS, TIER_SWITCH_DATE } from "./tier-outcomes.mjs";
|
|
14
|
+
import { COLUMNS as MEMBER_COLUMNS } from "./member-outcomes.mjs";
|
|
15
|
+
|
|
16
|
+
const SCRIPT = fileURLToPath(new URL("./tier-outcomes.mjs", import.meta.url));
|
|
17
|
+
const PRE_SWITCH = "2026-09-17";
|
|
18
|
+
assert.ok(PRE_SWITCH < TIER_SWITCH_DATE);
|
|
19
|
+
|
|
20
|
+
const HEADER = `# ${COLUMNS.join("\t")}\n`;
|
|
21
|
+
|
|
22
|
+
// One member-outcomes.tsv row, every column present so parseTsv accepts it.
|
|
23
|
+
function memberRow({ member, ticket, type, role = "implementer" }) {
|
|
24
|
+
const r = Object.fromEntries(MEMBER_COLUMNS.map((c) => [c, ""]));
|
|
25
|
+
Object.assign(r, { session: "s1", run_date: TIER_SWITCH_DATE, role, member, ticket: String(ticket), agent: member, subagent_type: type });
|
|
26
|
+
return MEMBER_COLUMNS.map((c) => r[c]).join("\t");
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function tierRow({ date = TIER_SWITCH_DATE, pr, ticket, tier }) {
|
|
30
|
+
return [date, pr, ticket, "routine", tier, "yes", "no", "a note with spaces", "light", "production", "40", "2"].join("\t");
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function ledgerText(rows = [], dispatched = []) {
|
|
34
|
+
return `# Fleet run ledger\n\n## Rows\n${rows.map((r) => `- ${r}\n`).join("")}\n## Dispatched\n${dispatched.map((d) => `- ${d}\n`).join("")}\n## Filed\n\n## Ruled\n`;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function fixture(t, { members = [], tierRows = [], ledger = null, closes = [10] } = {}) {
|
|
38
|
+
const dir = mkdtempSync(join(tmpdir(), "tier-outcomes-"));
|
|
39
|
+
t.after(() => rmSync(dir, { recursive: true, force: true }));
|
|
40
|
+
const bin = join(dir, "bin");
|
|
41
|
+
mkdirSync(bin);
|
|
42
|
+
writeFileSync(join(bin, "gh"), '#!/bin/sh\nprintf \'%s\\n\' "$*" >> "$GH_LOG"\nprintf \'%s\\n\' "$GH_JSON"\n');
|
|
43
|
+
chmodSync(join(bin, "gh"), 0o755);
|
|
44
|
+
const f = {
|
|
45
|
+
tier: join(dir, "tier-outcomes.tsv"),
|
|
46
|
+
members: join(dir, "member-outcomes.tsv"),
|
|
47
|
+
ledger: join(dir, "ledger.md"),
|
|
48
|
+
ghLog: join(dir, "gh.log"),
|
|
49
|
+
};
|
|
50
|
+
writeFileSync(f.tier, HEADER + tierRows.map((r) => `${r}\n`).join(""));
|
|
51
|
+
writeFileSync(f.members, `# member facts\n${members.map((m) => `${memberRow(m)}\n`).join("")}`);
|
|
52
|
+
if (ledger) writeFileSync(f.ledger, ledgerText(ledger.rows, ledger.dispatched));
|
|
53
|
+
f.run = (...args) => {
|
|
54
|
+
const r = spawnSync(process.execPath, [SCRIPT, ...args, "--file", f.tier, "--member-outcomes", f.members, "--ledger", f.ledger], {
|
|
55
|
+
cwd: dir,
|
|
56
|
+
encoding: "utf8",
|
|
57
|
+
env: {
|
|
58
|
+
...process.env,
|
|
59
|
+
PATH: `${bin}:${process.env.PATH}`,
|
|
60
|
+
GH_LOG: f.ghLog,
|
|
61
|
+
GH_JSON: JSON.stringify({ closingIssuesReferences: closes.map((number) => ({ number })) }),
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
return { code: r.status, stdout: r.stdout, stderr: r.stderr };
|
|
65
|
+
};
|
|
66
|
+
f.append = (pr = "20", { note = "a note with spaces" } = {}) =>
|
|
67
|
+
f.run("append", pr, "--class", "routine", "--closed-own-ticket", "yes", "--minted-false-claim", "no", "--note", note);
|
|
68
|
+
f.dataRows = () => readFileSync(f.tier, "utf8").split("\n").filter((l) => l.trim() && !l.startsWith("#")).map((l) => l.split("\t"));
|
|
69
|
+
f.ghCalls = () => (existsSync(f.ghLog) ? readFileSync(f.ghLog, "utf8").trim().split("\n").filter(Boolean) : []);
|
|
70
|
+
return f;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const col = (name) => COLUMNS.indexOf(name);
|
|
74
|
+
|
|
75
|
+
// ---------------------------------------------------------------------------
|
|
76
|
+
// append
|
|
77
|
+
// ---------------------------------------------------------------------------
|
|
78
|
+
|
|
79
|
+
const localDate = (d = new Date()) =>
|
|
80
|
+
`${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}`;
|
|
81
|
+
|
|
82
|
+
test("append: the ledger's tier-ok token wins over member-outcomes.tsv", (t) => {
|
|
83
|
+
const f = fixture(t, {
|
|
84
|
+
ledger: { rows: ["#10 impl-10=PR#20 · class=routine · tier=alt · tier-ok=impl-10:fleet-implementer-alt"], dispatched: ["impl-10=PR#20"] },
|
|
85
|
+
// An older dispatch of the same ticket under the default definition: step 2
|
|
86
|
+
// alone would read `default`.
|
|
87
|
+
members: [{ member: "impl-10", ticket: 10, type: "fleet-implementer" }],
|
|
88
|
+
});
|
|
89
|
+
const before = localDate();
|
|
90
|
+
const r = f.append();
|
|
91
|
+
const after = localDate();
|
|
92
|
+
assert.equal(r.code, 0, r.stderr);
|
|
93
|
+
const rows = f.dataRows();
|
|
94
|
+
assert.equal(rows.length, 1);
|
|
95
|
+
assert.equal(rows[0].length, COLUMNS.length, "a new row is written to the full width");
|
|
96
|
+
assert.equal(rows[0][col("pr")], "20");
|
|
97
|
+
assert.equal(rows[0][col("ticket")], "10", "the ticket comes from gh's closingIssuesReferences");
|
|
98
|
+
assert.equal(rows[0][col("tier")], "alt");
|
|
99
|
+
// Stamped at ruling: the day `append` ran, in local time — either side of a
|
|
100
|
+
// midnight the run straddled.
|
|
101
|
+
assert.ok([before, after].includes(rows[0][col("run_date")]), `run_date ${rows[0][col("run_date")]} is not the day append ran`);
|
|
102
|
+
assert.equal(rows[0][col("note")], "a note with spaces");
|
|
103
|
+
assert.match(r.stderr, /tier-ok=impl-10:fleet-implementer-alt/);
|
|
104
|
+
assert.deepEqual(f.ghCalls(), ["pr view 20 --json closingIssuesReferences"]);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test("append: the verdict of the member that opened the PR, not a replaced attempt's", (t) => {
|
|
108
|
+
const f = fixture(t, {
|
|
109
|
+
ledger: {
|
|
110
|
+
rows: ["#10 impl-10=released · tier-ok=impl-10:fleet-implementer · impl-10-b=PR#20 · tier-ok=impl-10-b:fleet-implementer-alt"],
|
|
111
|
+
dispatched: ["impl-10=released", "impl-10-b=PR#20"],
|
|
112
|
+
},
|
|
113
|
+
});
|
|
114
|
+
assert.equal(f.append().code, 0);
|
|
115
|
+
assert.equal(f.dataRows()[0][col("tier")], "alt");
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test("append: a stale tier-ok from a member who released the ticket is not used when nobody owns this PR", (t) => {
|
|
119
|
+
const f = fixture(t, {
|
|
120
|
+
ledger: { rows: ["#10 impl-10=released · tier-ok=impl-10:fleet-implementer-alt"], dispatched: ["impl-10=released"] },
|
|
121
|
+
});
|
|
122
|
+
const r = f.append();
|
|
123
|
+
assert.equal(r.code, 0, r.stderr);
|
|
124
|
+
assert.equal(f.dataRows()[0][col("tier")], "");
|
|
125
|
+
assert.match(r.stderr, /WARNING tier left blank for PR #20 \(ticket #10\): no implementer row for #10/);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
test("append: with no ledger verdict, the ticket's single fleet-implementer* row in member-outcomes.tsv supplies it", (t) => {
|
|
129
|
+
// The PR ruled in a later run than the one that dispatched it: this run's
|
|
130
|
+
// ledger has no row for the ticket at all.
|
|
131
|
+
const f = fixture(t, { members: [{ member: "impl-10", ticket: 10, type: "fleet-implementer" }] });
|
|
132
|
+
const r = f.append();
|
|
133
|
+
assert.equal(r.code, 0, r.stderr);
|
|
134
|
+
assert.equal(f.dataRows()[0][col("tier")], "default");
|
|
135
|
+
assert.doesNotMatch(r.stderr, /WARNING/);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
test("append: a per-cell definition's short name is its suffix, not refused", (t) => {
|
|
139
|
+
const f = fixture(t, { members: [{ member: "impl-10", ticket: 10, type: "fleet-implementer-slow-high" }] });
|
|
140
|
+
assert.equal(f.append().code, 0);
|
|
141
|
+
assert.equal(f.dataRows()[0][col("tier")], "slow-high");
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
for (const [why, members, reason] of [
|
|
145
|
+
["no member row", [{ member: "impl-11", ticket: 11, type: "fleet-implementer" }], /no implementer row for #10/],
|
|
146
|
+
[
|
|
147
|
+
"several member rows",
|
|
148
|
+
[{ member: "impl-10", ticket: 10, type: "fleet-implementer" }, { member: "impl-10-b", ticket: 10, type: "fleet-implementer-alt" }],
|
|
149
|
+
/2 implementer rows for #10/,
|
|
150
|
+
],
|
|
151
|
+
["a `task` row", [{ member: "impl-10", ticket: 10, type: "task" }], /impl-10 ran as 'task', not a fleet-implementer\* definition/],
|
|
152
|
+
]) {
|
|
153
|
+
test(`append: ${why} leaves tier blank, warns why, and still writes the row`, (t) => {
|
|
154
|
+
const f = fixture(t, { members });
|
|
155
|
+
const r = f.append();
|
|
156
|
+
assert.equal(r.code, 0, r.stderr);
|
|
157
|
+
const rows = f.dataRows();
|
|
158
|
+
assert.equal(rows.length, 1);
|
|
159
|
+
assert.equal(rows[0].length, COLUMNS.length);
|
|
160
|
+
assert.equal(rows[0][col("tier")], "");
|
|
161
|
+
assert.match(r.stderr, /WARNING tier left blank for PR #20 \(ticket #10\)/);
|
|
162
|
+
assert.match(r.stderr, reason);
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
test("append: a tier-mismatch verdict blanks the tier instead of falling back to an older dispatch", (t) => {
|
|
167
|
+
const f = fixture(t, {
|
|
168
|
+
ledger: { rows: ["#10 impl-10=PR#20 · tier-mismatch=impl-10:fleet-implementer"], dispatched: ["impl-10=PR#20"] },
|
|
169
|
+
members: [{ member: "impl-10", ticket: 10, type: "fleet-implementer" }],
|
|
170
|
+
});
|
|
171
|
+
const r = f.append();
|
|
172
|
+
assert.equal(r.code, 0);
|
|
173
|
+
assert.equal(f.dataRows()[0][col("tier")], "");
|
|
174
|
+
assert.match(r.stderr, /tier-mismatch=impl-10:fleet-implementer/);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
test("append: a member settled tier-mismatch on the ledger blanks the tier even with no free-text tier-mismatch= token", (t) => {
|
|
178
|
+
// tier-check.mjs's main path (a mismatch caught while the member is still
|
|
179
|
+
// live) settles the member as `tier-mismatch` directly and writes no
|
|
180
|
+
// free-text token — see tier-check.mjs's recordImplementer.
|
|
181
|
+
const f = fixture(t, {
|
|
182
|
+
ledger: { rows: ["#10 impl-10=tier-mismatch"], dispatched: ["impl-10=tier-mismatch"] },
|
|
183
|
+
members: [{ member: "impl-10", ticket: 10, type: "fleet-implementer" }],
|
|
184
|
+
});
|
|
185
|
+
const r = f.append();
|
|
186
|
+
assert.equal(r.code, 0, r.stderr);
|
|
187
|
+
assert.equal(f.dataRows()[0][col("tier")], "");
|
|
188
|
+
assert.match(r.stderr, /the ledger settled impl-10=tier-mismatch/);
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
test("append: running it twice is a no-op that names the existing row and never asks gh", (t) => {
|
|
192
|
+
const f = fixture(t, { members: [{ member: "impl-10", ticket: 10, type: "fleet-implementer" }] });
|
|
193
|
+
assert.equal(f.append().code, 0);
|
|
194
|
+
const before = readFileSync(f.tier, "utf8");
|
|
195
|
+
const again = f.append("20", { note: "a different note" });
|
|
196
|
+
assert.equal(again.code, 0, again.stderr);
|
|
197
|
+
assert.equal(readFileSync(f.tier, "utf8"), before);
|
|
198
|
+
assert.match(again.stdout, /PR #20 already has a row/);
|
|
199
|
+
assert.ok(again.stdout.includes(before.trim().split("\n").at(-1)), "the existing row is printed");
|
|
200
|
+
assert.equal(f.ghCalls().length, 1, "the second run asked gh again");
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
test("append: a leading zero in the PR argument is normalized, not treated as a different PR", (t) => {
|
|
204
|
+
const f = fixture(t, { members: [{ member: "impl-10", ticket: 10, type: "fleet-implementer" }] });
|
|
205
|
+
assert.equal(f.append("020").code, 0);
|
|
206
|
+
assert.equal(f.dataRows().length, 1);
|
|
207
|
+
assert.equal(f.dataRows()[0][col("pr")], "20", "the stored PR is normalized, not the raw '020' argument");
|
|
208
|
+
const again = f.append("20", { note: "a different note" });
|
|
209
|
+
assert.equal(again.code, 0, again.stderr);
|
|
210
|
+
assert.equal(f.dataRows().length, 1, "the normalized PR is recognized as already having a row, not duplicated");
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
test("append: a tab in --note is refused before anything is written", (t) => {
|
|
214
|
+
const f = fixture(t, { members: [{ member: "impl-10", ticket: 10, type: "fleet-implementer" }] });
|
|
215
|
+
const before = readFileSync(f.tier, "utf8");
|
|
216
|
+
const r = f.append("20", { note: "shifted\tfields" });
|
|
217
|
+
assert.equal(r.code, 2);
|
|
218
|
+
assert.equal(readFileSync(f.tier, "utf8"), before);
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
test("append: a newline or carriage return in a flag value is refused, the same as a tab", (t) => {
|
|
222
|
+
const f = fixture(t, { members: [{ member: "impl-10", ticket: 10, type: "fleet-implementer" }] });
|
|
223
|
+
const before = readFileSync(f.tier, "utf8");
|
|
224
|
+
for (const bad of ["shifted\nfields", "shifted\rfields"]) {
|
|
225
|
+
const r = f.append("20", { note: bad });
|
|
226
|
+
assert.equal(r.code, 2, `note ${JSON.stringify(bad)} was not refused`);
|
|
227
|
+
}
|
|
228
|
+
assert.equal(readFileSync(f.tier, "utf8"), before);
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
test("append: a PR closing no issue is refused, not written with a blank ticket", (t) => {
|
|
232
|
+
const f = fixture(t, { closes: [] });
|
|
233
|
+
const before = readFileSync(f.tier, "utf8");
|
|
234
|
+
const r = f.append();
|
|
235
|
+
assert.equal(r.code, 2);
|
|
236
|
+
assert.match(r.stderr, /closes no issue/);
|
|
237
|
+
assert.equal(readFileSync(f.tier, "utf8"), before);
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
// ---------------------------------------------------------------------------
|
|
241
|
+
// check
|
|
242
|
+
// ---------------------------------------------------------------------------
|
|
243
|
+
|
|
244
|
+
test("check: a tier equal to the single implementer row's short name passes", (t) => {
|
|
245
|
+
const f = fixture(t, {
|
|
246
|
+
members: [{ member: "impl-10", ticket: 10, type: "fleet-implementer-alt" }, { member: "impl-12", ticket: 12, type: "fleet-implementer" }],
|
|
247
|
+
tierRows: [tierRow({ pr: 20, ticket: 10, tier: "alt" }), tierRow({ pr: 22, ticket: 12, tier: "default" })],
|
|
248
|
+
});
|
|
249
|
+
const r = f.run("check");
|
|
250
|
+
assert.equal(r.code, 0, r.stderr);
|
|
251
|
+
assert.match(r.stdout, /2 checked, 0 failed/);
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
test("check: a tier naming a different definition than ran fails", (t) => {
|
|
255
|
+
const f = fixture(t, {
|
|
256
|
+
members: [{ member: "impl-10", ticket: 10, type: "fleet-implementer-alt" }],
|
|
257
|
+
tierRows: [tierRow({ pr: 20, ticket: 10, tier: "default" })],
|
|
258
|
+
});
|
|
259
|
+
const r = f.run("check");
|
|
260
|
+
assert.equal(r.code, 1);
|
|
261
|
+
assert.match(r.stderr, /FAIL PR #20 \(ticket #10\): tier=default, but impl-10 ran as fleet-implementer-alt \(alt\)/);
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
test("check: a lone `task` implementer row fails a filled tier", (t) => {
|
|
265
|
+
const f = fixture(t, {
|
|
266
|
+
members: [{ member: "impl-10", ticket: 10, type: "task" }],
|
|
267
|
+
tierRows: [tierRow({ pr: 20, ticket: 10, tier: "default" })],
|
|
268
|
+
});
|
|
269
|
+
const r = f.run("check");
|
|
270
|
+
assert.equal(r.code, 1);
|
|
271
|
+
assert.match(r.stderr, /FAIL PR #20 .*ran as 'task'/);
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
test("check: blank, several-row and no-row rows are skipped, not failed", (t) => {
|
|
275
|
+
const f = fixture(t, {
|
|
276
|
+
members: [
|
|
277
|
+
{ member: "impl-10", ticket: 10, type: "task" },
|
|
278
|
+
{ member: "impl-11", ticket: 11, type: "fleet-implementer" },
|
|
279
|
+
{ member: "impl-11-b", ticket: 11, type: "task" },
|
|
280
|
+
// A single-member row (ticket 13) is CHECKED, not skipped — closes the
|
|
281
|
+
// boundary between this and the several-member-rows case above.
|
|
282
|
+
{ member: "impl-13", ticket: 13, type: "fleet-implementer" },
|
|
283
|
+
],
|
|
284
|
+
tierRows: [
|
|
285
|
+
tierRow({ pr: 20, ticket: 10, tier: "" }),
|
|
286
|
+
tierRow({ pr: 21, ticket: 11, tier: "default" }),
|
|
287
|
+
tierRow({ pr: 22, ticket: 12, tier: "default" }),
|
|
288
|
+
tierRow({ pr: 23, ticket: 13, tier: "default" }),
|
|
289
|
+
],
|
|
290
|
+
});
|
|
291
|
+
const r = f.run("check");
|
|
292
|
+
assert.equal(r.code, 0, r.stderr);
|
|
293
|
+
assert.match(r.stdout, /1 checked, 0 failed; skipped 0 before \S+, 1 blank, 1 with no member row, 1 with several member rows/);
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
test("check: rows dated before the switch are skipped, whatever they say", (t) => {
|
|
297
|
+
const f = fixture(t, {
|
|
298
|
+
members: [{ member: "impl-10", ticket: 10, type: "task" }],
|
|
299
|
+
tierRows: [tierRow({ date: PRE_SWITCH, pr: 20, ticket: 10, tier: "opus" })],
|
|
300
|
+
});
|
|
301
|
+
const r = f.run("check");
|
|
302
|
+
assert.equal(r.code, 0, r.stderr);
|
|
303
|
+
assert.match(r.stdout, /skipped 1 before/);
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
test("check: a missing tier-outcomes.tsv file fails loudly instead of passing 0 checked", (t) => {
|
|
307
|
+
const f = fixture(t, {
|
|
308
|
+
members: [{ member: "impl-10", ticket: 10, type: "fleet-implementer" }],
|
|
309
|
+
tierRows: [tierRow({ pr: 20, ticket: 10, tier: "default" })],
|
|
310
|
+
});
|
|
311
|
+
rmSync(f.tier);
|
|
312
|
+
const r = f.run("check");
|
|
313
|
+
assert.equal(r.code, 2);
|
|
314
|
+
assert.match(r.stderr, /no .*tier-outcomes\.tsv — no rows to check/);
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
test("check --live: warns on each reviewed PR with no row, and the warning alone never fails", (t) => {
|
|
318
|
+
const f = fixture(t, {
|
|
319
|
+
members: [{ member: "impl-10", ticket: 10, type: "fleet-implementer" }],
|
|
320
|
+
tierRows: [tierRow({ pr: 20, ticket: 10, tier: "default" })],
|
|
321
|
+
ledger: {
|
|
322
|
+
rows: [
|
|
323
|
+
"#10 impl-10=PR#20 · reviewed=abcdef1:0/0/0",
|
|
324
|
+
"#13 impl-13=PR#23 · reviewed=abcdef2:1/0/0",
|
|
325
|
+
"#30 review=member:review-pr-30 · reviewed=abcdef3:0/1/0",
|
|
326
|
+
"#14 impl-14=PR#24 · review=member:review-pr-24",
|
|
327
|
+
],
|
|
328
|
+
dispatched: ["impl-10=PR#20", "impl-13=PR#23", "impl-14=PR#24"],
|
|
329
|
+
},
|
|
330
|
+
});
|
|
331
|
+
const r = f.run("check", "--live");
|
|
332
|
+
assert.equal(r.code, 0, r.stderr);
|
|
333
|
+
const warned = [...r.stderr.matchAll(/WARNING PR #(\d+) carries reviewed=/g)].map((m) => Number(m[1]));
|
|
334
|
+
assert.deepEqual(warned, [23, 30], "a reviewed PR with a row, or an unreviewed one, was warned about");
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
test("check --live: a run ledger that does not exist is refused, not read as empty", (t) => {
|
|
338
|
+
const f = fixture(t, { tierRows: [tierRow({ pr: 20, ticket: 10, tier: "" })] });
|
|
339
|
+
const r = f.run("check", "--live");
|
|
340
|
+
assert.equal(r.code, 2);
|
|
341
|
+
assert.match(r.stderr, /ledger/);
|
|
342
|
+
});
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// omp tier routing (ADR 0011, ADR 0014). `model: "@<role>:<level>"` in an
|
|
3
|
+
// agent definition is a fleet tier route — never a vendor id — resolved
|
|
4
|
+
// through the operator's `modelRoles.slow|task|smol`, with the explicit
|
|
5
|
+
// `:<level>` suffix on the REFERRING alias winning over the role's own
|
|
6
|
+
// baked one (`modelRoles.<role>` values carry their own baked suffix,
|
|
7
|
+
// measured `smol: anthropic/claude-haiku-4-5:auto` on a real install).
|
|
8
|
+
//
|
|
9
|
+
// This file is CHECK-ONLY (ADR 0014): there is no generator and no
|
|
10
|
+
// operator-side override record to derive any more — `model:` in the
|
|
11
|
+
// definition IS the route, and omp resolves the `@<role>` alias through
|
|
12
|
+
// `modelRoles` natively (`omp://task-agent-discovery.md`). What is left to
|
|
13
|
+
// verify, read-only, never `omp config set`:
|
|
14
|
+
// (a) every definition's `model:` is a well-formed route
|
|
15
|
+
// (`@slow|@task|@smol:<level>`);
|
|
16
|
+
// (b) every role a definition uses has a `modelRoles.<role>` that
|
|
17
|
+
// resolves to a model;
|
|
18
|
+
// (c) no `task.agentModelOverrides` entry shadows a fleet definition —
|
|
19
|
+
// that config is model-precedence #1 for task/eval dispatch (ADR
|
|
20
|
+
// 0011), so a leftover `fleet-*` key there would silently win over
|
|
21
|
+
// the definition's own `model:`, which ADR 0014 retires as a lever;
|
|
22
|
+
// (d) `modelRoles.slow`/`modelRoles.task` resolving to the same model is
|
|
23
|
+
// flagged as a notice — legal, but the alt-tier comparison
|
|
24
|
+
// (fleet-implementer-alt) then controls nothing.
|
|
25
|
+
|
|
26
|
+
import { readFileSync, readdirSync } from "node:fs";
|
|
27
|
+
import { execFileSync } from "node:child_process";
|
|
28
|
+
import { join, dirname } from "node:path";
|
|
29
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
30
|
+
import { makeDie, defineFlags } from "./arg.mjs";
|
|
31
|
+
|
|
32
|
+
const NAME = "tier-roles";
|
|
33
|
+
const SCRIPT_DIR = dirname(fileURLToPath(import.meta.url));
|
|
34
|
+
|
|
35
|
+
// ---------------------------------------------------------------------------
|
|
36
|
+
// pure core — unit-tested directly (tier-roles.test.mjs), no filesystem or
|
|
37
|
+
// process access below this line until main()
|
|
38
|
+
// ---------------------------------------------------------------------------
|
|
39
|
+
|
|
40
|
+
// Role names in print order — a fixed list, not derived from anything: ADR
|
|
41
|
+
// 0014 retired the tier->role map this used to come from (OMP_ROLE_FOR_MODEL
|
|
42
|
+
// with its opus/sonnet/haiku keys), and the fleet only ever names these
|
|
43
|
+
// three roles.
|
|
44
|
+
const ROLE_ORDER = ["slow", "task", "smol"];
|
|
45
|
+
|
|
46
|
+
const MODEL_ROUTE_RE = /^@(slow|task|smol):(minimal|low|medium|high|xhigh|max)$/;
|
|
47
|
+
|
|
48
|
+
// Strips one matching pair of surrounding double or single quotes — YAML's
|
|
49
|
+
// own scalar quoting, needed because `model:` must be quoted in frontmatter
|
|
50
|
+
// (a bare leading `@` is not valid unquoted YAML).
|
|
51
|
+
function unquote(value) {
|
|
52
|
+
const s = String(value ?? "");
|
|
53
|
+
const m = /^"(.*)"$/.exec(s) || /^'(.*)'$/.exec(s);
|
|
54
|
+
return m ? m[1] : s;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// A frontmatter `model:` value -> `{ role, level }`, both `null` when it is
|
|
58
|
+
// not a well-formed `@slow|@task|@smol:<level>` route.
|
|
59
|
+
export function parseModelRoute(value) {
|
|
60
|
+
const m = MODEL_ROUTE_RE.exec(unquote(value));
|
|
61
|
+
return m ? { role: m[1], level: m[2] } : { role: null, level: null };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Reads a definition's frontmatter -> `{ model, role, level }`. `model` is
|
|
65
|
+
// the raw declared value (as written, quotes and all); `role`/`level` are
|
|
66
|
+
// parsed off its unquoted form and both `null` when `model` is missing or
|
|
67
|
+
// does not match `@<role>:<level>` — the shape tier-check.mjs's own
|
|
68
|
+
// dispatch-time compare imports this for.
|
|
69
|
+
export function parseFrontmatter(agentFileText) {
|
|
70
|
+
const fm = String(agentFileText ?? "").split("---")[1] ?? "";
|
|
71
|
+
const model = /^model:\s*(.+)$/m.exec(fm)?.[1]?.trim() ?? null;
|
|
72
|
+
const { role, level } = model ? parseModelRoute(model) : { role: null, level: null };
|
|
73
|
+
return { model, role, level };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Removes a trailing `:<level>` (`claude-opus-5:high` -> `claude-opus-5`);
|
|
77
|
+
// never touches the provider `/` (`anthropic/claude-opus-5` is untouched
|
|
78
|
+
// past its own colon-free tail).
|
|
79
|
+
export function stripLevel(selector) {
|
|
80
|
+
return String(selector ?? "").replace(/:[^:/]*$/, "");
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// One role's `modelRoles` entry -> the model identity it ultimately names,
|
|
84
|
+
// following an `@other-role` alias chain (a role may point at another role,
|
|
85
|
+
// omp://models.md) until a bare model is reached. `null` when the role is
|
|
86
|
+
// unset, empty, non-string, or the chain is longer than 8 hops (a cycle a
|
|
87
|
+
// human config could otherwise hang this on).
|
|
88
|
+
export function resolveRole(role, modelRoles, depth = 0) {
|
|
89
|
+
if (depth > 8) return null;
|
|
90
|
+
const raw = modelRoles?.[role];
|
|
91
|
+
if (typeof raw !== "string" || raw === "") return null;
|
|
92
|
+
if (raw.startsWith("@")) return resolveRole(stripLevel(raw.slice(1)), modelRoles, depth + 1);
|
|
93
|
+
return stripLevel(raw);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// A declared route (`@slow:xhigh`/…) -> the role/level it carries and the
|
|
97
|
+
// model that role currently resolves to. `role`/`level` are `null` when the
|
|
98
|
+
// value is not a route at all; `model` is `null` when the role is unset (or
|
|
99
|
+
// the value is not a route).
|
|
100
|
+
export function expectedOmpModel(declaredModel, modelRoles) {
|
|
101
|
+
const { role, level } = parseModelRoute(declaredModel);
|
|
102
|
+
return { role, level, model: role ? resolveRole(role, modelRoles) : null };
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Tolerates a role value written without its provider prefix — omp's
|
|
106
|
+
// `resolvedModelIdentity` is always provider-prefixed, a plain `modelRoles`
|
|
107
|
+
// entry may not be.
|
|
108
|
+
export function modelsEqual(a, b) {
|
|
109
|
+
const sa = stripLevel(a);
|
|
110
|
+
const sb = stripLevel(b);
|
|
111
|
+
return sa === sb || sa.endsWith("/" + sb) || sb.endsWith("/" + sa);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// `omp config get <key> --json` reads the MERGED effective value (built-in
|
|
115
|
+
// defaults, global config, project settings, `--config` overlays, runtime
|
|
116
|
+
// overrides — measured for the retired pool-preflight.mjs, #1588) —
|
|
117
|
+
// `modelRoles.slow` dotted into a record is `Unknown setting` on this box,
|
|
118
|
+
// so a record-valued key is always read whole. Never writes.
|
|
119
|
+
export function readOmpConfigValue(key) {
|
|
120
|
+
let out;
|
|
121
|
+
try {
|
|
122
|
+
out = execFileSync("omp", ["config", "get", key, "--json"], { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] });
|
|
123
|
+
} catch (e) {
|
|
124
|
+
throw new Error(`omp config get ${key} --json failed: ${e.stderr || e.message}`);
|
|
125
|
+
}
|
|
126
|
+
try {
|
|
127
|
+
return JSON.parse(out).value;
|
|
128
|
+
} catch (e) {
|
|
129
|
+
throw new Error(`omp config get ${key} --json exited 0 but printed non-JSON: ${e.message}`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Every fleet definition's `name:` carries this prefix — enforced in CI by
|
|
134
|
+
// frontmatter-allowlist.json's agents `name` pattern (`^fleet-[^:]*$`,
|
|
135
|
+
// #1303). It is the only way to tell a fleet-owned `task.agentModelOverrides`
|
|
136
|
+
// entry (a pre-cutover install can still carry one — ADR 0014 retires the
|
|
137
|
+
// config as a lever, it does not clear it) from the operator's own entry,
|
|
138
|
+
// which this check never touches.
|
|
139
|
+
const FLEET_NAME_PREFIX = "fleet-";
|
|
140
|
+
|
|
141
|
+
// POSIX single-quoting for a printed command line: the remedy carries the
|
|
142
|
+
// operator's own override values, which this file never chose.
|
|
143
|
+
function shellQuote(s) {
|
|
144
|
+
return `'${s.replace(/'/g, `'\\''`)}'`;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// The operator's install (`modelRoles`, and any leftover
|
|
148
|
+
// `task.agentModelOverrides`) against what the fleet's own definitions need.
|
|
149
|
+
// `violations` stop a run (ADR 0014); `notices` never do — they flag a
|
|
150
|
+
// hazard (the alt-tier pairing controlling nothing) that is legal
|
|
151
|
+
// configuration, just probably not what the operator meant.
|
|
152
|
+
export function checkRoutes({ agentsDir, modelRoles, overrides }) {
|
|
153
|
+
const violations = [];
|
|
154
|
+
const notices = [];
|
|
155
|
+
const usedBy = {}; // role -> [file, ...]
|
|
156
|
+
|
|
157
|
+
const files = readdirSync(agentsDir).filter((f) => f.endsWith(".agent.md")).sort();
|
|
158
|
+
for (const file of files) {
|
|
159
|
+
const text = readFileSync(join(agentsDir, file), "utf8");
|
|
160
|
+
const fm = parseFrontmatter(text);
|
|
161
|
+
if (!fm.role || !fm.level) {
|
|
162
|
+
violations.push(`${file}: model ${JSON.stringify(fm.model)} is not @<role>:<level>`);
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
(usedBy[fm.role] ??= []).push(file);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
for (const role of ROLE_ORDER) {
|
|
169
|
+
if (!usedBy[role]) continue;
|
|
170
|
+
if (resolveRole(role, modelRoles) === null) {
|
|
171
|
+
violations.push(`modelRoles.${role} is unset — needed by ${usedBy[role].join(", ")}`);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const overrideKeys = Object.keys(overrides ?? {});
|
|
176
|
+
const fleetKeys = overrideKeys.filter((k) => k.startsWith(FLEET_NAME_PREFIX)).sort();
|
|
177
|
+
if (fleetKeys.length > 0) {
|
|
178
|
+
const nonFleet = Object.fromEntries(
|
|
179
|
+
overrideKeys.filter((k) => !k.startsWith(FLEET_NAME_PREFIX)).map((k) => [k, overrides[k]]),
|
|
180
|
+
);
|
|
181
|
+
const remedy = Object.keys(nonFleet).length === 0
|
|
182
|
+
? "omp config reset task.agentModelOverrides"
|
|
183
|
+
: `omp config set task.agentModelOverrides ${shellQuote(JSON.stringify(nonFleet))}`;
|
|
184
|
+
for (const name of fleetKeys) {
|
|
185
|
+
violations.push(`task.agentModelOverrides.${name} shadows the definition's own model (precedence #1) — remove it (${remedy})`);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const slowModel = resolveRole("slow", modelRoles);
|
|
190
|
+
const taskModel = resolveRole("task", modelRoles);
|
|
191
|
+
if (slowModel !== null && taskModel !== null && modelsEqual(slowModel, taskModel)) {
|
|
192
|
+
notices.push(`modelRoles.slow and modelRoles.task both resolve to ${slowModel} — the alternate-tier comparison controls nothing`);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return { violations, notices };
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// ---------------------------------------------------------------------------
|
|
199
|
+
// CLI
|
|
200
|
+
// ---------------------------------------------------------------------------
|
|
201
|
+
|
|
202
|
+
const die = makeDie(NAME);
|
|
203
|
+
const { arg, has, sweep, stray } = defineFlags(die, {
|
|
204
|
+
flags: {
|
|
205
|
+
check: "bool",
|
|
206
|
+
agents: "value",
|
|
207
|
+
overrides: "value",
|
|
208
|
+
"model-roles": "value",
|
|
209
|
+
},
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
function loadJsonObject(path, configKey, flagName) {
|
|
213
|
+
let value;
|
|
214
|
+
try {
|
|
215
|
+
value = path ? JSON.parse(readFileSync(path, "utf8")) : readOmpConfigValue(configKey);
|
|
216
|
+
} catch (e) {
|
|
217
|
+
die(e.message);
|
|
218
|
+
}
|
|
219
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
220
|
+
const source = path ? `--${flagName} ${path}` : `omp config get ${configKey} --json`;
|
|
221
|
+
die(`${source} must be a JSON object, got ${Array.isArray(value) ? "an array" : typeof value}`);
|
|
222
|
+
}
|
|
223
|
+
return value;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function main() {
|
|
227
|
+
sweep();
|
|
228
|
+
stray();
|
|
229
|
+
|
|
230
|
+
const check = has("check");
|
|
231
|
+
if (!check) die("--check is required (usage: tier-roles.mjs --check [--agents <dir>] [--model-roles <path>] [--overrides <path>])");
|
|
232
|
+
|
|
233
|
+
const agentsDir = arg("agents") ?? join(SCRIPT_DIR, "..", "agents");
|
|
234
|
+
const overrides = loadJsonObject(arg("overrides"), "task.agentModelOverrides", "overrides");
|
|
235
|
+
const modelRoles = loadJsonObject(arg("model-roles"), "modelRoles", "model-roles");
|
|
236
|
+
|
|
237
|
+
const { violations, notices } = checkRoutes({ agentsDir, modelRoles, overrides });
|
|
238
|
+
|
|
239
|
+
if (violations.length === 0) {
|
|
240
|
+
console.log("tier-roles: every definition routes to a resolvable model, no shadowing override");
|
|
241
|
+
for (const n of notices) console.log(`tier-roles: notice: ${n}`);
|
|
242
|
+
process.exit(0);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
for (const v of violations) console.error(`tier-roles: ${v}`);
|
|
246
|
+
for (const n of notices) console.error(`tier-roles: notice: ${n}`);
|
|
247
|
+
process.exit(1);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
if (import.meta.url === pathToFileURL(process.argv[1] || "").href) main();
|