trantor 0.18.144 → 0.18.146
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/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +1 -1
- package/bin/canary.mjs +55 -15
- package/bin/capacity.mjs +3 -1
- package/bin/crew-runner.mjs +76 -16
- package/bin/disk.mjs +8 -5
- package/bin/wake-nudge.mjs +27 -3
- package/configs/dispatcher-policy.json +84 -0
- package/docs/FEATURES.md +25 -12
- package/hub/routes/capacity.mjs +1 -1
- package/hub/routes/cards.mjs +7 -2
- package/hub/routes/insights.mjs +1 -0
- package/kimi.plugin.json +1 -1
- package/lib/canary/canary.mjs +66 -7
- package/lib/canary/registry.mjs +153 -4
- package/lib/capacity.mjs +21 -4
- package/lib/classify-failure.mjs +14 -8
- package/lib/dispatcher/policy.mjs +41 -0
- package/lib/dispatcher/schemas.mjs +218 -0
- package/lib/dispatcher/snapshot.mjs +70 -0
- package/lib/dispatcher/store.mjs +111 -0
- package/lib/launchd.mjs +61 -0
- package/lib/seat-liveness.mjs +41 -0
- package/lib/session-liveness.mjs +23 -0
- package/lib/turn-usage.mjs +88 -17
- package/package.json +1 -1
package/hub/routes/insights.mjs
CHANGED
|
@@ -52,6 +52,7 @@ function validTurnRow(row, nowMs) {
|
|
|
52
52
|
if (row.containers !== undefined && (!Array.isArray(row.containers) || row.containers.length > 100 || row.containers.some(name => !stringWithin(name, 200)))) return null;
|
|
53
53
|
if (!["cut", "stalled", "authFailed", "emptyOutput", "emptyTurn"].every(key => optionalBoolean(row, key))) return null;
|
|
54
54
|
if (row.cutSignal !== undefined && (typeof row.cutSignal !== "string" || row.cutSignal.length > 80)) return null;
|
|
55
|
+
if (row.stderrTail !== undefined && (typeof row.stderrTail !== "string" || row.stderrTail.length > 8000)) return null;
|
|
55
56
|
if (row.extensions !== undefined && !safeInteger(row.extensions)) return null;
|
|
56
57
|
if (row.boxMs !== undefined && !safeInteger(row.boxMs)) return null;
|
|
57
58
|
const attempt = row.attempt === undefined ? null : validAttempt(row.attempt, row, nowMs);
|
package/kimi.plugin.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "trantor",
|
|
3
|
-
"version": "0.18.
|
|
3
|
+
"version": "0.18.146",
|
|
4
4
|
"description": "Trantor — the hub-world for AI agent crews: live message bus, presence, project Kanban/flow board + crew orchestration for independent AI coding agents (Claude, Codex, Gemini, Kimi, DeepSeek). This manifest makes Kimi Code CLI a first-class ORCHESTRATOR, mirroring .claude-plugin/plugin.json. Hooks are the CANONICAL hooks/** executed through the kimi dialect bridge (kimi/bridge.mjs) — docs/KIMI-BRIDGE-CONTRACT.md.",
|
|
5
5
|
"interface": {
|
|
6
6
|
"displayName": "Trantor",
|
package/lib/canary/canary.mjs
CHANGED
|
@@ -29,15 +29,16 @@ const withTimeout = (promise, ms, id) => new Promise((resolve, reject) => {
|
|
|
29
29
|
export async function runCanary({ rows, probes = PROBES, ctx, timeoutMs = PROBE_TIMEOUT_MS }) {
|
|
30
30
|
const results = [];
|
|
31
31
|
for (const row of rows) {
|
|
32
|
-
const
|
|
32
|
+
const probeId = row.probeId || row.id;
|
|
33
|
+
const probe = probes[probeId];
|
|
33
34
|
let result;
|
|
34
|
-
if (!probe) result = { status: "fail", detail: `docs/FEATURES.md names ${
|
|
35
|
+
if (!probe) result = { status: "fail", detail: `docs/FEATURES.md names ${probeId} but lib/canary/probes.mjs has no probe for it` };
|
|
35
36
|
else {
|
|
36
37
|
try { result = await withTimeout(Promise.resolve().then(() => probe(ctx)), timeoutMs, row.id); }
|
|
37
38
|
catch (error) { result = { status: "fail", detail: `probe crashed: ${error.message}` }; }
|
|
38
39
|
if (!["pass", "fail", "skip"].includes(result?.status)) result = { status: "fail", detail: "probe returned no status" };
|
|
39
40
|
}
|
|
40
|
-
results.push({ id: row.id, feature: row.feature, status: result.status, detail: String(result.detail || "") });
|
|
41
|
+
results.push({ id: row.id, probeId, host: row.host || "any", feature: row.feature, status: result.status, detail: String(result.detail || "") });
|
|
41
42
|
}
|
|
42
43
|
return { ts: ctx.now, results };
|
|
43
44
|
}
|
|
@@ -48,19 +49,64 @@ export const tally = (results) => ({
|
|
|
48
49
|
skip: results.filter((r) => r.status === "skip").length,
|
|
49
50
|
});
|
|
50
51
|
|
|
51
|
-
/**
|
|
52
|
-
*
|
|
52
|
+
/** Episodes: a new failure opens one and is announced, a repeat updates it quietly, a pass closes it,
|
|
53
|
+
* a skip changes nothing. #14670: an undelivered announcement (delivered false) is retried next run. */
|
|
53
54
|
export function advanceEpisodes(previous, run) {
|
|
54
55
|
const episodes = { ...(previous || {}) };
|
|
55
56
|
const announce = [], recovered = [];
|
|
56
57
|
for (const r of run.results) {
|
|
57
58
|
const open = episodes[r.id];
|
|
58
|
-
if (r.status === "fail" && !open) {
|
|
59
|
-
|
|
59
|
+
if (r.status === "fail" && !open) {
|
|
60
|
+
episodes[r.id] = { since: run.ts, lastFailTs: run.ts, failures: 1, feature: r.feature, detail: r.detail, delivered: null };
|
|
61
|
+
announce.push(r);
|
|
62
|
+
} else if (r.status === "fail") {
|
|
63
|
+
episodes[r.id] = { ...open, lastFailTs: run.ts, failures: (open.failures || 1) + 1, feature: r.feature, detail: r.detail };
|
|
64
|
+
if (open.delivered === false) announce.push(r);
|
|
65
|
+
} else if (r.status === "pass" && open) { delete episodes[r.id]; recovered.push({ ...r, since: open.since }); }
|
|
60
66
|
}
|
|
61
67
|
return { episodes, announce, recovered };
|
|
62
68
|
}
|
|
63
69
|
|
|
70
|
+
/** After the post attempt: stamps each announced episode delivered true or false. */
|
|
71
|
+
export function markDelivered(episodes, ids, delivered, error = "") {
|
|
72
|
+
const out = { ...episodes };
|
|
73
|
+
for (const id of ids) {
|
|
74
|
+
if (!out[id]) continue;
|
|
75
|
+
const { deliveryError: _drop, ...rest } = out[id];
|
|
76
|
+
out[id] = delivered ? { ...rest, delivered } : { ...rest, delivered, deliveryError: error };
|
|
77
|
+
}
|
|
78
|
+
return out;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export const PROBE_RESULTS = ["pass", "fail", "skip"];
|
|
82
|
+
|
|
83
|
+
/** The signed payload a registered canary identity posts to the hub's canary-report route
|
|
84
|
+
* (TDD §7.1). It reports one probe on one host for one artifact; it never grants acceptance. */
|
|
85
|
+
export function probeReport({ registryHash, result, host, artifactSha, now, evidenceRef = "" }) {
|
|
86
|
+
return {
|
|
87
|
+
registryHash, probeId: result.probeId || result.id, host: host || result.host || "any",
|
|
88
|
+
artifactSha, result: result.status, observedAtMs: now, evidenceRef: String(evidenceRef || result.detail || "").slice(0, 500),
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** Rejects a report the hub must not store: missing fields, an unknown result, or a probe the
|
|
93
|
+
* current registry does not name. */
|
|
94
|
+
export function validateProbeReport(report, rows) {
|
|
95
|
+
const errors = [];
|
|
96
|
+
for (const k of ["registryHash", "probeId", "host", "artifactSha"]) if (!String(report?.[k] ?? "").trim()) errors.push(`${k} is required`);
|
|
97
|
+
if (!PROBE_RESULTS.includes(report?.result)) errors.push(`result must be pass, fail or skip`);
|
|
98
|
+
if (!Number.isFinite(report?.observedAtMs) || report.observedAtMs <= 0) errors.push("observedAtMs must be a timestamp");
|
|
99
|
+
if (report?.probeId && rows && !rows.some((r) => (r.probeId || r.id) === report.probeId)) errors.push(`probe ${report.probeId} is not in docs/FEATURES.md`);
|
|
100
|
+
return { ok: errors.length === 0, errors };
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** Open regressions in brief order: first failure first, then feature id. */
|
|
104
|
+
export function openRegressions(episodes) {
|
|
105
|
+
return Object.entries(episodes || {})
|
|
106
|
+
.map(([id, e]) => ({ id, ...e }))
|
|
107
|
+
.sort((a, b) => (a.since - b.since) || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
|
|
108
|
+
}
|
|
109
|
+
|
|
64
110
|
const dur = (ms) => ms < 3600e3 ? `${Math.max(1, Math.round(ms / 60e3))}m` : ms < 86400e3 ? `${Math.round(ms / 3600e3)}h` : `${Math.round(ms / 86400e3)}d`;
|
|
65
111
|
|
|
66
112
|
/** The single message a daily run posts, or "" when nothing newly failed. Recoveries ride along
|
|
@@ -164,3 +210,16 @@ export function canaryDoctorRows({ lastRun, installed, now = Date.now() }) {
|
|
|
164
210
|
if (!t.fail) rows.push({ level: "ok", message: `feature canary: last run ${when}, ${t.pass} pass, ${t.skip} skip` });
|
|
165
211
|
return rows;
|
|
166
212
|
}
|
|
213
|
+
|
|
214
|
+
/** The lines the shared brief renders before capacity and plan: every open regression, oldest first,
|
|
215
|
+
* and a stale or missing daily run as an incident of its own. Empty when there is nothing open. */
|
|
216
|
+
export function regressionBrief({ episodes, lastRun, now = Date.now() }) {
|
|
217
|
+
const lines = [];
|
|
218
|
+
for (const e of openRegressions(episodes)) {
|
|
219
|
+
const tail = e.delivered === false ? `, alert not delivered${e.deliveryError ? ` (${e.deliveryError})` : ""}` : "";
|
|
220
|
+
lines.push(`REGRESSION ${e.feature || e.id} [${e.id}] failing ${dur(now - e.since)}, ${e.failures || 1} run${(e.failures || 1) === 1 ? "" : "s"}${tail}: ${e.detail || "no detail"}`);
|
|
221
|
+
}
|
|
222
|
+
if (!lastRun?.ts) lines.push("INCIDENT feature canary has no recorded daily run, so a feature that goes dark stays silent");
|
|
223
|
+
else if (now - lastRun.ts > STALE_MS) lines.push(`INCIDENT feature canary last ran ${dur(now - lastRun.ts)} ago, the daily job has stopped running`);
|
|
224
|
+
return lines;
|
|
225
|
+
}
|
package/lib/canary/registry.mjs
CHANGED
|
@@ -1,15 +1,32 @@
|
|
|
1
1
|
// #14655: docs/FEATURES.md is the source of truth for which features the canary watches. Each table
|
|
2
2
|
// row under "## Registry" names one probe by id; parsing it here keeps the doc and the code honest.
|
|
3
|
+
// #14670 (TDD-dispatcher §7.1): mapped rows attach their probe to any card touching their files.
|
|
3
4
|
import { readFileSync } from "node:fs";
|
|
5
|
+
import { createHash } from "node:crypto";
|
|
4
6
|
import { dirname, join } from "node:path";
|
|
5
7
|
import { fileURLToPath } from "node:url";
|
|
6
8
|
|
|
7
9
|
export const REGISTRY_PATH = join(dirname(dirname(dirname(fileURLToPath(import.meta.url)))), "docs", "FEATURES.md");
|
|
8
10
|
|
|
9
11
|
const cellsOf = (line) => line.trim().replace(/^\|/, "").replace(/\|$/, "").split("|").map((c) => c.trim());
|
|
12
|
+
const ticked = (cell) => /^`([^`]+)`$/.exec(cell)?.[1];
|
|
10
13
|
|
|
11
|
-
/**
|
|
12
|
-
*
|
|
14
|
+
/** A Files cell: comma-separated backticked repo paths; a path ending in "/" is a directory prefix.
|
|
15
|
+
* Returns null when any entry is not backticked, so prose never turns into a glob. */
|
|
16
|
+
function filesOf(cell) {
|
|
17
|
+
if (!cell || cell === "-") return [];
|
|
18
|
+
const out = [];
|
|
19
|
+
for (const part of cell.split(",").map((s) => s.trim()).filter(Boolean)) {
|
|
20
|
+
const path = ticked(part);
|
|
21
|
+
if (!path) return null;
|
|
22
|
+
out.push(path);
|
|
23
|
+
}
|
|
24
|
+
return out;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** The rows of the "## Registry" table: { id, feature, reads, origin, files, probeId, host, required,
|
|
28
|
+
* mapped }. Old four-column rows stay unmapped (files [], required false) and still name their own
|
|
29
|
+
* probe by id. Header and divider rows are dropped; a row without a backticked id is ignored. */
|
|
13
30
|
export function parseRegistry(markdown) {
|
|
14
31
|
const lines = String(markdown || "").split("\n");
|
|
15
32
|
const start = lines.findIndex((l) => /^##\s+Registry\b/.test(l));
|
|
@@ -18,9 +35,22 @@ export function parseRegistry(markdown) {
|
|
|
18
35
|
for (const line of lines.slice(start + 1)) {
|
|
19
36
|
if (/^##\s/.test(line)) break;
|
|
20
37
|
if (!line.trim().startsWith("|")) continue;
|
|
21
|
-
const
|
|
38
|
+
const cells = cellsOf(line);
|
|
39
|
+
const [idCell = "", feature = "", reads = "", origin = "", filesCell = "", probeCell = "", hostCell = "", requiredCell = ""] = cells;
|
|
22
40
|
const id = /^`([a-z0-9-]+)`$/.exec(idCell)?.[1];
|
|
23
|
-
if (id)
|
|
41
|
+
if (!id) continue;
|
|
42
|
+
const mapped = cells.length > 4;
|
|
43
|
+
const files = mapped ? filesOf(filesCell) : [];
|
|
44
|
+
const req = requiredCell.toLowerCase();
|
|
45
|
+
rows.push({
|
|
46
|
+
id, feature, reads, origin,
|
|
47
|
+
files,
|
|
48
|
+
probeId: mapped ? (ticked(probeCell) ?? (probeCell || null)) : id,
|
|
49
|
+
host: mapped ? (hostCell || "any") : "any",
|
|
50
|
+
required: mapped ? req === "yes" : false,
|
|
51
|
+
requiredRaw: mapped ? req : "",
|
|
52
|
+
mapped,
|
|
53
|
+
});
|
|
24
54
|
}
|
|
25
55
|
return rows;
|
|
26
56
|
}
|
|
@@ -28,3 +58,122 @@ export function parseRegistry(markdown) {
|
|
|
28
58
|
export function loadRegistry(path = REGISTRY_PATH) {
|
|
29
59
|
return parseRegistry(readFileSync(path, "utf8"));
|
|
30
60
|
}
|
|
61
|
+
|
|
62
|
+
const BAD_PATH = /(^\/)|(^|\/)\.\.(\/|$)|[*?[\]{}\s\\]/;
|
|
63
|
+
|
|
64
|
+
/** Malformed mappings are errors, not warnings: a mapped row needs exact repo paths (or "dir/"
|
|
65
|
+
* prefixes), a probe that exists in PROBES, a host, and Required-for-acceptance of yes or no. */
|
|
66
|
+
export function validateRegistry(rows, probes) {
|
|
67
|
+
const errors = [];
|
|
68
|
+
const seen = new Set();
|
|
69
|
+
for (const row of rows) {
|
|
70
|
+
if (seen.has(row.id)) errors.push(`${row.id}: listed twice`);
|
|
71
|
+
seen.add(row.id);
|
|
72
|
+
if (!row.mapped) continue;
|
|
73
|
+
if (row.files === null) { errors.push(`${row.id}: Files must be backticked repo paths separated by commas`); continue; }
|
|
74
|
+
if (!row.files.length) errors.push(`${row.id}: a mapped row needs at least one path in Files`);
|
|
75
|
+
for (const f of row.files) if (BAD_PATH.test(f) || f === "/" || f === "") errors.push(`${row.id}: "${f}" is not an exact repo path or dir/ prefix`);
|
|
76
|
+
if (!row.probeId) errors.push(`${row.id}: Probe is empty`);
|
|
77
|
+
else if (!probes?.[row.probeId]) errors.push(`${row.id}: probe ${row.probeId} is not in lib/canary/probes.mjs`);
|
|
78
|
+
if (!/^[a-z0-9-]+$/.test(row.host)) errors.push(`${row.id}: Host "${row.host}" is not a host kind (any, mac, …)`);
|
|
79
|
+
if (row.requiredRaw !== "yes" && row.requiredRaw !== "no") errors.push(`${row.id}: Required-for-acceptance must be yes or no, not "${row.requiredRaw}"`);
|
|
80
|
+
}
|
|
81
|
+
return { ok: errors.length === 0, errors };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** The hash a card's drill spec pins. Only the mapping columns count, so rewording a feature's prose
|
|
85
|
+
* does not force every open card to replan, while any change to paths, probe, host or required does. */
|
|
86
|
+
export function registryHash(rows) {
|
|
87
|
+
const canon = rows
|
|
88
|
+
.filter((r) => r.mapped)
|
|
89
|
+
.map((r) => [r.id, [...(r.files || [])].sort(), r.probeId, r.host, r.required])
|
|
90
|
+
.sort((a, b) => (a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0));
|
|
91
|
+
return createHash("sha256").update(JSON.stringify(canon)).digest("hex");
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const WHOLE_REPO = new Set(["", ".", "./", "/", "*", "**", "**/*"]);
|
|
95
|
+
|
|
96
|
+
/** Repo-relative, forward slashes, no leading "./"; a trailing "/" survives because it marks a tree. */
|
|
97
|
+
export function normalizePath(p) {
|
|
98
|
+
let s = String(p ?? "").trim().replace(/\\/g, "/");
|
|
99
|
+
if (WHOLE_REPO.has(s)) return "";
|
|
100
|
+
while (s.startsWith("./")) s = s.slice(2);
|
|
101
|
+
return s.replace(/\/{2,}/g, "/");
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const isTree = (p) => p === "" || p.endsWith("/");
|
|
105
|
+
|
|
106
|
+
/** Whether a claimed path or tree overlaps a registry path or prefix. */
|
|
107
|
+
export function pathsOverlap(claim, regPath) {
|
|
108
|
+
const a = normalizePath(claim), b = normalizePath(regPath);
|
|
109
|
+
if (a === "" || a === b) return true;
|
|
110
|
+
if (isTree(a) && b.startsWith(a)) return true;
|
|
111
|
+
if (isTree(b) && a.startsWith(b)) return true;
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** Card creation / preflight: which features and probes a card must carry.
|
|
116
|
+
* claims: the card's claimed files or trees; declaredFeatures: card.features; noFeatureImpact: an
|
|
117
|
+
* owner-approved { approvedBy, reason } covering claimed paths no feature maps. A whole-repository
|
|
118
|
+
* claim attaches every mapped feature. ok is false while an unmapped path has no rationale. */
|
|
119
|
+
export function attachProbes({ rows, claims = [], declaredFeatures = [], noFeatureImpact = null }) {
|
|
120
|
+
const mapped = rows.filter((r) => r.mapped && Array.isArray(r.files));
|
|
121
|
+
const byId = new Map(rows.map((r) => [r.id, r]));
|
|
122
|
+
const features = new Set();
|
|
123
|
+
const unmapped = [];
|
|
124
|
+
const unknownFeatures = [];
|
|
125
|
+
for (const raw of claims) {
|
|
126
|
+
const claim = normalizePath(raw);
|
|
127
|
+
const hits = mapped.filter((r) => r.files.some((f) => pathsOverlap(claim, f)));
|
|
128
|
+
for (const r of hits) features.add(r.id);
|
|
129
|
+
if (!hits.length) unmapped.push(claim);
|
|
130
|
+
}
|
|
131
|
+
for (const f of declaredFeatures) {
|
|
132
|
+
if (byId.has(f)) features.add(f);
|
|
133
|
+
else unknownFeatures.push(f);
|
|
134
|
+
}
|
|
135
|
+
const ids = [...features].sort();
|
|
136
|
+
const required = ids.map((id) => byId.get(id)).filter((r) => r.required);
|
|
137
|
+
const probeIds = [...new Set(required.map((r) => r.probeId))].sort();
|
|
138
|
+
const hosts = Object.fromEntries(required.map((r) => [r.probeId, r.host]));
|
|
139
|
+
const rationale = noFeatureImpact && String(noFeatureImpact.approvedBy || "").trim() && String(noFeatureImpact.reason || "").trim()
|
|
140
|
+
? { approvedBy: String(noFeatureImpact.approvedBy).trim(), reason: String(noFeatureImpact.reason).trim() } : null;
|
|
141
|
+
const problems = [];
|
|
142
|
+
if (unmapped.length && !rationale) problems.push(`no feature maps ${unmapped.join(", ")}: an owner-approved no-feature-impact rationale is required`);
|
|
143
|
+
if (unknownFeatures.length) problems.push(`card.features names unknown feature${unknownFeatures.length === 1 ? "" : "s"} ${unknownFeatures.join(", ")}`);
|
|
144
|
+
return {
|
|
145
|
+
ok: problems.length === 0,
|
|
146
|
+
problems,
|
|
147
|
+
features: ids,
|
|
148
|
+
probeIds,
|
|
149
|
+
hosts,
|
|
150
|
+
unmapped,
|
|
151
|
+
noFeatureImpact: unmapped.length ? rationale : null,
|
|
152
|
+
registryHash: registryHash(rows),
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** Before acceptance: spec is what attachProbes persisted. Blocks on a changed registry, an unclaimed
|
|
157
|
+
* diff path or a failed probe; a required probe without a pass for this SHA and hash stays pending. */
|
|
158
|
+
export function acceptanceGate({ spec, rows, claims = [], diffPaths = [], artifactSha, reports = [] }) {
|
|
159
|
+
const blocked = [], pending = [];
|
|
160
|
+
const currentHash = registryHash(rows);
|
|
161
|
+
if (!spec?.registryHash) blocked.push("the card carries no registry hash: attach probes at card creation");
|
|
162
|
+
else if (spec.registryHash !== currentHash) blocked.push(`docs/FEATURES.md changed since the card was planned (${spec.registryHash.slice(0, 12)} → ${currentHash.slice(0, 12)}): replan and reverify`);
|
|
163
|
+
const covers = (raw, p) => { const c = normalizePath(raw); return c === "" || c === p || (isTree(c) && p.startsWith(c)); };
|
|
164
|
+
const outside = diffPaths.map(normalizePath).filter((p) => !claims.some((c) => covers(c, p)));
|
|
165
|
+
if (outside.length) blocked.push(`diff touches unclaimed path${outside.length === 1 ? "" : "s"} ${outside.join(", ")}`);
|
|
166
|
+
if (!artifactSha) blocked.push("no artifact SHA to accept");
|
|
167
|
+
const passed = [];
|
|
168
|
+
for (const probeId of spec?.probeIds || []) {
|
|
169
|
+
const mine = reports.filter((r) => r.probeId === probeId && r.artifactSha === artifactSha && r.registryHash === spec.registryHash);
|
|
170
|
+
if (mine.some((r) => r.result === "fail")) blocked.push(`required probe ${probeId} failed on ${String(artifactSha).slice(0, 12)}`);
|
|
171
|
+
else if (mine.some((r) => r.result === "pass")) passed.push(probeId);
|
|
172
|
+
else {
|
|
173
|
+
const host = spec.hosts?.[probeId] || "any";
|
|
174
|
+
const why = mine.some((r) => r.result === "skip") ? "skipped" : "not run";
|
|
175
|
+
pending.push(`required probe ${probeId} ${why} on ${String(artifactSha).slice(0, 12)}${host === "any" ? "" : ` (queue a verifier job on ${host})`}`);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return { accept: blocked.length === 0 && pending.length === 0, blocked, pending, passed };
|
|
179
|
+
}
|
package/lib/capacity.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// #14653: the pure views behind GET /capacity and `trantor capacity` — budgets (windows, resets,
|
|
2
2
|
// prepaid, merged across machine snapshots), burn rate from turn telemetry, seats with their last
|
|
3
|
-
// turn,
|
|
3
|
+
// turn, machine rows joined with seat counts, and online-seat faults for direct work left
|
|
4
|
+
// unconsumed past the delivery ledger's high-water mark (#14662).
|
|
4
5
|
|
|
5
6
|
// Unknown values stay null; ages ride along so a consumer can say HOW unknown ("12m old", "no
|
|
6
7
|
// beat"). Pure: a function over the hub's state and telemetry rows, so tests feed fixtures.
|
|
@@ -95,19 +96,34 @@ export function burnView({ rows, nowMs, canSee = () => true }) {
|
|
|
95
96
|
return { windows };
|
|
96
97
|
}
|
|
97
98
|
|
|
99
|
+
export const UNCONSUMED_WORK_MS = 30 * 60e3;
|
|
100
|
+
|
|
101
|
+
// A heartbeat is not consumption. Only direct wake-worthy work counts: broadcasts, receipts and
|
|
102
|
+
// batched FYI context do not owe the seat a turn. deliveredUpTo is the hub's monotonic hand-off mark.
|
|
103
|
+
export function seatWorkFlags({ messages = [], session, deliveredUpTo = 0, nowMs, online, stuckAfterMs = UNCONSUMED_WORK_MS }) {
|
|
104
|
+
const waiting = messages.filter(m => m && m.to === session && m.from !== session && Number(m.id) > Number(deliveredUpTo || 0)
|
|
105
|
+
&& m.wake !== false && m.kind !== "status" && m.kind !== "receipt" && Number.isFinite(Number(m.ts)));
|
|
106
|
+
const oldestTs = waiting.length ? Math.min(...waiting.map(m => Number(m.ts))) : null;
|
|
107
|
+
const unconsumedWork = oldestTs == null ? null : { count: waiting.length, oldestTs, ageMs: Math.max(0, nowMs - oldestTs) };
|
|
108
|
+
const stuck = online && unconsumedWork?.ageMs > stuckAfterMs;
|
|
109
|
+
return { flags: stuck ? ["unconsumed-work"] : [], fault: stuck ? "alive-but-turnless" : "", unconsumedWork };
|
|
110
|
+
}
|
|
111
|
+
|
|
98
112
|
// Seat rows from presence, with the last turn from telemetry. lastRows are the (bounded) recent
|
|
99
113
|
// rows the route already read — not re-queried here, so the view stays pure.
|
|
100
|
-
export function seatsView({ peers, lastRows, nowMs, onlineMs }) {
|
|
114
|
+
export function seatsView({ peers, lastRows, messages = [], nowMs, onlineMs, stuckAfterMs = UNCONSUMED_WORK_MS }) {
|
|
101
115
|
const lastBySeat = new Map();
|
|
102
116
|
for (const r of lastRows) {
|
|
103
117
|
const key = `${r.persona}\u0000${r.project}`;
|
|
104
118
|
const cur = lastBySeat.get(key);
|
|
105
|
-
if (!cur || Number(r.ts) > cur.ts) lastBySeat.set(key, { ts: Number(r.ts), outcome: r.outcome || "", model: r.model || "" });
|
|
119
|
+
if (!cur || Number(r.ts) > cur.ts) lastBySeat.set(key, { ts: Number(r.ts), outcome: r.outcome || "", model: r.model || "", verdict: r.verdict || "", stderrTail: r.stderrTail || "" });
|
|
106
120
|
}
|
|
107
121
|
return Object.entries(peers || {})
|
|
108
122
|
.map(([session, p]) => {
|
|
109
123
|
const persona = session.includes(":") ? session.slice(0, session.indexOf(":")) : session;
|
|
110
124
|
const last = lastBySeat.get(`${persona}\u0000${p.project || ""}`) || null;
|
|
125
|
+
const online = p.lastSeen > nowMs - onlineMs;
|
|
126
|
+
const work = seatWorkFlags({ messages, session, deliveredUpTo: p.deliveredUpTo, nowMs, online, stuckAfterMs });
|
|
111
127
|
return {
|
|
112
128
|
session,
|
|
113
129
|
project: p.project || "",
|
|
@@ -120,7 +136,8 @@ export function seatsView({ peers, lastRows, nowMs, onlineMs }) {
|
|
|
120
136
|
machine: p.machine || "",
|
|
121
137
|
lastSeen: p.lastSeen || 0,
|
|
122
138
|
ageMs: p.lastSeen ? Math.max(0, nowMs - p.lastSeen) : null,
|
|
123
|
-
online
|
|
139
|
+
online,
|
|
140
|
+
...work,
|
|
124
141
|
lastTurn: last ? { ...last, ageMs: Math.max(0, nowMs - last.ts) } : null,
|
|
125
142
|
};
|
|
126
143
|
})
|
package/lib/classify-failure.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Failure classification for crew seats (#5868), lifted out of crew-runner.mjs so the rules are
|
|
2
2
|
// unit-testable against the real specimens that misfired; the rules are in docs/CONTRACT-lib.md.
|
|
3
3
|
import { readFileSync } from "node:fs";
|
|
4
|
+
import { redactKeys } from "./redact.mjs";
|
|
4
5
|
|
|
5
6
|
export const AUTH_MARKER_RE = /unauthor|401|403|forbidden|invalid[ _-]?api[ _-]?key|authentication? failed|token expired/i;
|
|
6
7
|
|
|
@@ -116,8 +117,8 @@ export function verdictFor(realExit, effExit, emptyOutput, ownText, emptyTurn =
|
|
|
116
117
|
const m = AUTH_MARKER_RE.exec(String(ownText || ""));
|
|
117
118
|
return `classified auth because ${m ? m[0] : "auth marker"} in the CLI's own short output`;
|
|
118
119
|
}
|
|
119
|
-
const { reason, matched } = classifyFailure(realExit, String(ownText || ""), emptyOutput, emptyTurn, cut);
|
|
120
|
-
return `classified ${reason} because ${matched}`;
|
|
120
|
+
const { reason, matched, stderrTail } = classifyFailure(realExit, String(ownText || ""), emptyOutput, emptyTurn, cut);
|
|
121
|
+
return `classified ${reason} because ${matched}${stderrTail ? `\nredacted stderr tail:\n${stderrTail}` : ""}`;
|
|
121
122
|
}
|
|
122
123
|
|
|
123
124
|
// ---- the provider-rejected 401 (#8778) ---------------------------------------------------------
|
|
@@ -211,10 +212,15 @@ export function noDeliveryVerdict(card, status) {
|
|
|
211
212
|
return `classified no-delivery because exit 0 with no new commit and card #${card} still ${status}`;
|
|
212
213
|
}
|
|
213
214
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
215
|
+
export function failureStderrTail(errText) {
|
|
216
|
+
const tail = redactKeys(String(errText || "")).trim().split("\n").slice(-40).join("\n");
|
|
217
|
+
return tail.slice(-8000);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** Classify one failed turn. `matched` is the logged evidence; an unmatched error also returns its
|
|
221
|
+
* redacted stderr tail for the telemetry row and card note (#14662). `cut` is the runner's box/stall
|
|
222
|
+
* marker: only under it does 137 read as the sweep's SIGKILL; otherwise it is an OOM/outside kill
|
|
223
|
+
* and stays a crash (#7099). */
|
|
218
224
|
export function classifyFailure(exit, errText, emptyOutput = false, emptyTurn = false, cut = false) {
|
|
219
225
|
// #5481: silence with a clean exit is a failure shape, not success — see lastEmptyOutput.
|
|
220
226
|
if (emptyOutput) return { reason: "empty-output", matched: "exit 0 with no output on either stream" };
|
|
@@ -253,7 +259,7 @@ export function classifyFailure(exit, errText, emptyOutput = false, emptyTurn =
|
|
|
253
259
|
// your Fable 5 limit"), which say nothing about quota or credits and would otherwise read as a crash.
|
|
254
260
|
// #9724: the OpenRouter billing phrasing — "requires more credits … can only afford 16" — and
|
|
255
261
|
// "insufficient balance" name the same wall without any of the older tokens.
|
|
256
|
-
m = t.match(/quota|payment required|requires more credits|can only afford|insufficient balance|402|429|too many requests|rate.?limit|usage limit|exceeded your|reached your [^.\n]*limit|insufficient (?:credits?|funds)|out of (?:credits?|quota)/);
|
|
262
|
+
m = t.match(/apiproviderquotaexhaustederror|quota|payment required|requires more credits|can only afford|insufficient balance|402|429|too many requests|rate.?limit|usage limit|exceeded your|reached your [^.\n]*limit|insufficient (?:credits?|funds)|out of (?:credits?|quota)/);
|
|
257
263
|
if (m) return { reason: "exhausted", matched: m[0] };
|
|
258
264
|
m = t.match(/unauthor|401|invalid[ _-]?api[ _-]?key|forbidden|403|token expired|expired/);
|
|
259
265
|
if (m) return { reason: "auth", matched: m[0] };
|
|
@@ -261,7 +267,7 @@ export function classifyFailure(exit, errText, emptyOutput = false, emptyTurn =
|
|
|
261
267
|
// is a HOLLOW turn — the CLI printed its banner and quit. It ranks BELOW every real failure
|
|
262
268
|
// shape above: an auth-shaped or exhausted exit is that failure, never an empty turn.
|
|
263
269
|
if (emptyTurn) return { reason: "empty-turn", matched: "exit 0 with no worktree change, no substantive output, no bus activity" };
|
|
264
|
-
return { reason: "crashed", matched: `exit ${exit} with no known failure pattern
|
|
270
|
+
return { reason: "crashed", matched: `exit ${exit} with no known failure pattern`, stderrTail: failureStderrTail(errText) };
|
|
265
271
|
}
|
|
266
272
|
|
|
267
273
|
/** Read the prompt file if it exists (the turn prompt the CLI may echo into its transcript). */
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { PolicySchema } from './schemas.mjs';
|
|
3
|
+
import { canonicalHash, deepFreeze } from './snapshot.mjs';
|
|
4
|
+
|
|
5
|
+
export function hashPolicy(input) {
|
|
6
|
+
const { hash: _hash, ...policy } = PolicySchema.parse(input);
|
|
7
|
+
return canonicalHash(policy);
|
|
8
|
+
}
|
|
9
|
+
export function createPolicy(input) {
|
|
10
|
+
const policy = PolicySchema.omit({ hash: true }).parse(input);
|
|
11
|
+
return deepFreeze({ ...policy, hash: canonicalHash(policy) });
|
|
12
|
+
}
|
|
13
|
+
export function verifyPolicy(input) {
|
|
14
|
+
const policy = PolicySchema.parse(input);
|
|
15
|
+
if (hashPolicy(policy) !== policy.hash) throw new Error('policy_invalid');
|
|
16
|
+
return deepFreeze(policy);
|
|
17
|
+
}
|
|
18
|
+
export function projectMode(policy, project) {
|
|
19
|
+
return Object.hasOwn(policy.modeByProject, project) ? policy.modeByProject[project] : 'off';
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const DEFAULT_POLICY = verifyPolicy(JSON.parse(readFileSync(
|
|
23
|
+
new URL('../../configs/dispatcher-policy.json', import.meta.url), 'utf8')));
|
|
24
|
+
export const LEGACY_POLICY_INPUTS = deepFreeze({
|
|
25
|
+
source: 'bin/advise.mjs@442ea2282f6148bb0996ceac862da19be3c09348',
|
|
26
|
+
tokenEstimates: { easy: 300_000, medium: 1_500_000, hard: 6_000_000 },
|
|
27
|
+
seatPreferences: {
|
|
28
|
+
hard: ['codex', 'glm', 'kimi', 'deepseek', 'openrouter'],
|
|
29
|
+
medium: ['kimi', 'glm', 'codex', 'deepseek', 'openrouter'],
|
|
30
|
+
easy: ['deepseek', 'kimi', 'glm', 'codex', 'openrouter'],
|
|
31
|
+
},
|
|
32
|
+
roster: [
|
|
33
|
+
{ seatId: 'codex', cli: 'codex', provider: 'codex' },
|
|
34
|
+
{ seatId: 'kimi', cli: 'kimi', provider: 'kimi' },
|
|
35
|
+
{ seatId: 'deepseek', cli: 'opencode', provider: 'deepseek' },
|
|
36
|
+
{ seatId: 'glm', cli: 'opencode', provider: 'zai' },
|
|
37
|
+
{ seatId: 'openrouter', cli: 'opencode', provider: 'openrouter' },
|
|
38
|
+
],
|
|
39
|
+
catalog: JSON.parse(readFileSync(new URL('../../configs/model-catalog.json', import.meta.url), 'utf8')),
|
|
40
|
+
missing: ['registered host bindings', 'bounded durations', 'success pseudo-counts'],
|
|
41
|
+
});
|