@dadado/agent-kit-cli 6.9.0 → 6.10.1
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/dashboard/README.md +16 -0
- package/dashboard/art/atmospheric-purifier.webp +0 -0
- package/dashboard/art/rover-frozen-flats.webp +0 -0
- package/dashboard/art/seed-tree-crane.webp +0 -0
- package/dashboard/art/uplink-tower-road.webp +0 -0
- package/dashboard/dashboard-data.mjs +150 -8
- package/dashboard/dashboard.html +398 -3
- package/dashboard/lib/live-refresh.mjs +1 -0
- package/dashboard/lib/outcome-ledger.d.mts +115 -0
- package/dashboard/lib/outcome-ledger.mjs +595 -0
- package/dashboard/lib/semantic-model.d.mts +14 -0
- package/dashboard/lib/semantic-model.mjs +3 -0
- package/dashboard/serve.mjs +1 -0
- package/dist/{chunk-BCX5NDQC.js → chunk-GQ6Q3P7C.js} +1 -1
- package/dist/{chunk-67G3236R.js → chunk-K5OCGZWA.js} +2 -2
- package/dist/{chunk-3LLXDHIU.js → chunk-LFWPB2JR.js} +1 -0
- package/dist/{chunk-GO3K752H.js → chunk-SC2DBY2R.js} +2 -0
- package/dist/{chunk-3Z4PGEEJ.js → chunk-TUZVOPKY.js} +1 -1
- package/dist/{doctor-PZT7EGLQ.js → doctor-E6LOBJYK.js} +2 -2
- package/dist/{guard-ZZRQW3DJ.js → guard-X6FNFZ27.js} +24 -2
- package/dist/index.js +19 -11
- package/dist/{init-MGRZ7U7A.js → init-KKVT2RW4.js} +3 -3
- package/dist/{install-432KJISB.js → install-BPZTP5KT.js} +3 -3
- package/dist/{mission-control-MHQU73XC.js → mission-control-C2QV5D25.js} +1 -1
- package/dist/outcome-ledger-XLWHWPVQ.js +297 -0
- package/dist/{run-VOVR5O7S.js → run-326EEQYY.js} +2 -2
- package/dist/{run-plan-KWGS2SOZ.js → run-plan-2IFO4G4Y.js} +2 -2
- package/dist/{scan-UX4HARMJ.js → scan-BWA64R7I.js} +1 -1
- package/dist/{status-UDM55MHU.js → status-LNXVLDMP.js} +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,595 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Outcome ledger (ADR 2026-10-23 colony-game-canon-outcome-ledger-art-policy,
|
|
3
|
+
* points 2-6): a product-neutral record of verified outcomes the kit already
|
|
4
|
+
* writes down. Mission Control folds it on every snapshot and exposes a
|
|
5
|
+
* read-only summary as `outcomeLedger`; a host (the Colony cockpit) reads the
|
|
6
|
+
* same field. The game layer spends nothing here: player choices live in the
|
|
7
|
+
* renderer (browser localStorage), earned totals live only in this ledger.
|
|
8
|
+
*
|
|
9
|
+
* Rules the fold enforces:
|
|
10
|
+
* - Idempotent by event identity. Every entry carries a stable key (plan +
|
|
11
|
+
* to-do id, tag name, CI run id, review report + head SHA, test run HEAD).
|
|
12
|
+
* Folding the same inputs twice adds nothing; an entry already earned is
|
|
13
|
+
* never rewritten or removed, so a pruned source (old loop logs, a capped
|
|
14
|
+
* run list) never takes a reward back, and re-opening then re-closing a
|
|
15
|
+
* to-do earns nothing new.
|
|
16
|
+
* - Anti-Goodhart. Only outcomes are inputs. Lines of code, commits, diff size,
|
|
17
|
+
* keystrokes, token volume, wall-clock time and tick counts are never read,
|
|
18
|
+
* so they cannot be rewarded.
|
|
19
|
+
* - Lazy. Nothing here ticks: the file holds source-derived timestamps only,
|
|
20
|
+
* and the flow signal is computed from mission timing on each read.
|
|
21
|
+
*/
|
|
22
|
+
import { spawnSync } from "node:child_process";
|
|
23
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
24
|
+
import { dirname, join } from "node:path";
|
|
25
|
+
|
|
26
|
+
export const OUTCOME_LEDGER_REL = ".cursor/context/outcome-ledger.json";
|
|
27
|
+
export const TEST_RESULTS_REL = ".cursor/context/test-results.json";
|
|
28
|
+
export const REPOSITORY_PROFILE_REL = ".cursor/agent-kit.config.json";
|
|
29
|
+
export const OUTCOME_LEDGER_VERSION = 1;
|
|
30
|
+
/** Bound on stored entries; past it new entries are dropped, old ones kept. */
|
|
31
|
+
export const MAX_LEDGER_ENTRIES = 50_000;
|
|
32
|
+
/** Newest test runs kept in test-results.json. */
|
|
33
|
+
export const MAX_TEST_RESULTS = 200;
|
|
34
|
+
/** Newest earned entries exposed on the snapshot. */
|
|
35
|
+
export const MAX_RECENT_ENTRIES = 20;
|
|
36
|
+
const MAX_LABEL = 120;
|
|
37
|
+
const MAX_COMMAND_CHARS = 200;
|
|
38
|
+
const MAX_COMMANDS = 5;
|
|
39
|
+
|
|
40
|
+
/** Resource tiers (ADR point 5). */
|
|
41
|
+
export const OUTCOME_KINDS = Object.freeze({
|
|
42
|
+
todo: "logic",
|
|
43
|
+
test: "logic",
|
|
44
|
+
ci: "compute",
|
|
45
|
+
releaseCut: "compute",
|
|
46
|
+
plan: "rare",
|
|
47
|
+
review: "rare",
|
|
48
|
+
releasePublished: "rare",
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
const SAFE_PART_RE = /^[A-Za-z0-9][A-Za-z0-9._+-]{0,159}$/;
|
|
52
|
+
const TAG_RE = /^v[0-9A-Za-z][0-9A-Za-z._+-]{0,62}$/;
|
|
53
|
+
const SHA_RE = /^[0-9a-f]{7,40}$/;
|
|
54
|
+
const RUN_ID_RE = /^[0-9]{1,20}$/;
|
|
55
|
+
const ISO_RE = /^\d{4}-\d{2}-\d{2}(?:[T ][0-9:.]+(?:Z|[+-]\d{2}:?\d{2})?)?$/;
|
|
56
|
+
const FULL_REVIEW_HEAD_RE = /^## Full review\b[^\n]*?\bHEAD\b[^\n]{0,24}?\b([0-9a-f]{7,40})\b/gm;
|
|
57
|
+
const TODO_RE = /^\s*-\s+id:\s*(\S+)\s*\n\s*content:\s*"(?:.+)"\s*\n\s*status:\s*(\S+)/gm;
|
|
58
|
+
|
|
59
|
+
const isRecord = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
60
|
+
const safePart = (v) => (typeof v === "string" && SAFE_PART_RE.test(v) ? v : null);
|
|
61
|
+
const isoOrNull = (v) => (typeof v === "string" && ISO_RE.test(v.trim()) ? v.trim() : null);
|
|
62
|
+
|
|
63
|
+
function cap(text, max = MAX_LABEL) {
|
|
64
|
+
const s = String(text ?? "").trim();
|
|
65
|
+
return s.length > max ? `${s.slice(0, max - 1)}…` : s;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Empty ledger (fresh install). */
|
|
69
|
+
export function emptyOutcomeLedger() {
|
|
70
|
+
return { version: OUTCOME_LEDGER_VERSION, entries: {}, sources: {} };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Parse the persisted ledger. Malformed entries and a wrong version are
|
|
75
|
+
* dropped, never thrown. An entry of a kind this engine does not know (a
|
|
76
|
+
* newer engine wrote it) is kept as is and not counted, so an older engine
|
|
77
|
+
* never erases it on the next write.
|
|
78
|
+
* @param {unknown} raw
|
|
79
|
+
*/
|
|
80
|
+
export function parseOutcomeLedger(raw) {
|
|
81
|
+
const out = emptyOutcomeLedger();
|
|
82
|
+
if (!isRecord(raw) || raw.version !== OUTCOME_LEDGER_VERSION || !isRecord(raw.entries)) {
|
|
83
|
+
return out;
|
|
84
|
+
}
|
|
85
|
+
// Fingerprints (size + mtime) of large, rarely changing sources already
|
|
86
|
+
// folded, so they are not re-read on every snapshot. Source-derived only.
|
|
87
|
+
if (isRecord(raw.sources)) {
|
|
88
|
+
for (const [name, stamp] of Object.entries(raw.sources)) {
|
|
89
|
+
if (safePart(name) && typeof stamp === "string" && stamp.length <= 64) {
|
|
90
|
+
out.sources[name] = stamp;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
for (const [key, entry] of Object.entries(raw.entries)) {
|
|
95
|
+
if (typeof key !== "string" || key.length > 400 || !isRecord(entry)) continue;
|
|
96
|
+
if (typeof entry.kind !== "string" || !SAFE_PART_RE.test(entry.kind)) continue;
|
|
97
|
+
out.entries[key] = {
|
|
98
|
+
kind: entry.kind,
|
|
99
|
+
resource: OUTCOME_KINDS[entry.kind] ?? null,
|
|
100
|
+
at: isoOrNull(entry.at),
|
|
101
|
+
label: cap(entry.label),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
return out;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Whether a raw ledger file can be folded into: absent, or this version.
|
|
109
|
+
* A corrupt file or another version is left untouched (never overwritten).
|
|
110
|
+
*/
|
|
111
|
+
export function isFoldableOutcomeLedger(raw) {
|
|
112
|
+
return (
|
|
113
|
+
raw === undefined ||
|
|
114
|
+
(isRecord(raw) && raw.version === OUTCOME_LEDGER_VERSION && isRecord(raw.entries))
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** Stable JSON (sorted keys) so write-on-change never loops the SSE watcher. */
|
|
119
|
+
export function serializeOutcomeLedger(ledger) {
|
|
120
|
+
const parsed = parseOutcomeLedger(ledger);
|
|
121
|
+
const entries = {};
|
|
122
|
+
for (const key of Object.keys(parsed.entries).sort()) entries[key] = parsed.entries[key];
|
|
123
|
+
const sources = {};
|
|
124
|
+
for (const key of Object.keys(parsed.sources).sort()) sources[key] = parsed.sources[key];
|
|
125
|
+
return `${JSON.stringify({ version: OUTCOME_LEDGER_VERSION, entries, sources }, null, 2)}\n`;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** Parse plan frontmatter to-dos (same shape dashboard-data.mjs reads). */
|
|
129
|
+
export function parsePlanTodos(content) {
|
|
130
|
+
const fm = /^---\n([\s\S]*?)\n---/.exec(String(content ?? ""));
|
|
131
|
+
if (!fm) return [];
|
|
132
|
+
const todos = [];
|
|
133
|
+
for (const m of fm[1].matchAll(TODO_RE)) todos.push({ id: m[1], status: m[2] });
|
|
134
|
+
return todos;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* HEAD SHA of the last "## Full review ... HEAD `<sha>`" heading of a
|
|
139
|
+
* plan-monitor report (the plan-termination review the template asks for).
|
|
140
|
+
* Monitor logs without one are not a review outcome.
|
|
141
|
+
*/
|
|
142
|
+
export function fullReviewHeadSha(content) {
|
|
143
|
+
let head = null;
|
|
144
|
+
for (const m of String(content ?? "").matchAll(FULL_REVIEW_HEAD_RE)) head = m[1];
|
|
145
|
+
return head;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Outcome events from already-collected inputs. Pure: no fs, no clock.
|
|
150
|
+
* Every input is optional; an absent source yields no events.
|
|
151
|
+
*
|
|
152
|
+
* @param {object} inputs
|
|
153
|
+
* @param {Array<{file:string, todos:Array<{id:string,status:string}>}>} [inputs.plans] active + archived plans
|
|
154
|
+
* @param {{missions?: Record<string, {stages?: Record<string,{startedAt:string,endedAt:string|null}>}>}} [inputs.timing] mission-timing.json
|
|
155
|
+
* @param {Array<{file:string, reviewedPlanFile:string|null, hasOpenReviewGaps:boolean, fullReviewHead:string|null}>} [inputs.reviews]
|
|
156
|
+
* @param {Array<{name:string, date?:string|null}>} [inputs.tags] local v* tags
|
|
157
|
+
* @param {Array<{id?:number|string|null, conclusion?:string|null, event?:string, workflow?:string, createdAt?:string|null}>} [inputs.ciRuns] (scheduled runs are skipped)
|
|
158
|
+
* @param {boolean} [inputs.reviewsCollected] false when review reports were not read (no plan rewards then)
|
|
159
|
+
* @param {string|null} [inputs.historyRepo] owner/name: only this repository's history-ledger runs count
|
|
160
|
+
* @param {{tag?:string|null, publishedAt?:string|null}|null} [inputs.originRelease]
|
|
161
|
+
* @param {{runs?: Array<{at:string, ok:boolean, head:string|null}>}} [inputs.testResults]
|
|
162
|
+
* @param {unknown} [inputs.historyLedger] docs/evidence/history-ledger.json (factory only)
|
|
163
|
+
* @returns {Array<{key:string, kind:string, resource:string, at:string|null, label:string}>}
|
|
164
|
+
*/
|
|
165
|
+
export function extractOutcomeEvents(inputs = {}) {
|
|
166
|
+
const events = [];
|
|
167
|
+
const push = (key, kind, at, label) => {
|
|
168
|
+
events.push({ key, kind, resource: OUTCOME_KINDS[kind], at: isoOrNull(at), label: cap(label) });
|
|
169
|
+
};
|
|
170
|
+
const stageEnd = (planFile, todoId) =>
|
|
171
|
+
inputs.timing?.missions?.[planFile]?.stages?.[todoId]?.endedAt ?? null;
|
|
172
|
+
|
|
173
|
+
// Reviews first: a plan with an open-gap review is not closed with zero residuals.
|
|
174
|
+
const plansWithOpenGaps = new Set();
|
|
175
|
+
for (const r of Array.isArray(inputs.reviews) ? inputs.reviews : []) {
|
|
176
|
+
if (!isRecord(r)) continue;
|
|
177
|
+
if (r.hasOpenReviewGaps && typeof r.reviewedPlanFile === "string") {
|
|
178
|
+
plansWithOpenGaps.add(r.reviewedPlanFile);
|
|
179
|
+
}
|
|
180
|
+
const file = safePart(r.file);
|
|
181
|
+
const head =
|
|
182
|
+
typeof r.fullReviewHead === "string" && SHA_RE.test(r.fullReviewHead)
|
|
183
|
+
? r.fullReviewHead
|
|
184
|
+
: null;
|
|
185
|
+
if (!file || !head || r.hasOpenReviewGaps || typeof r.reviewedPlanFile !== "string") continue;
|
|
186
|
+
push(
|
|
187
|
+
`review:${file}:${head}`,
|
|
188
|
+
"review",
|
|
189
|
+
r.modifiedAt ?? null,
|
|
190
|
+
`${r.reviewedPlanFile} @ ${head.slice(0, 8)}`,
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
for (const plan of Array.isArray(inputs.plans) ? inputs.plans : []) {
|
|
195
|
+
const file = isRecord(plan) ? safePart(plan.file) : null;
|
|
196
|
+
if (!file?.endsWith(".plan.md")) continue;
|
|
197
|
+
const todos = Array.isArray(plan.todos) ? plan.todos.filter(isRecord) : [];
|
|
198
|
+
let lastEnd = null;
|
|
199
|
+
for (const t of todos) {
|
|
200
|
+
const id = safePart(t.id);
|
|
201
|
+
if (!id || t.status !== "completed") continue;
|
|
202
|
+
const end = isoOrNull(stageEnd(file, id));
|
|
203
|
+
if (end && (!lastEnd || end > lastEnd)) lastEnd = end;
|
|
204
|
+
push(`todo:${file}:${id}`, "todo", end, `${file} · ${id}`);
|
|
205
|
+
}
|
|
206
|
+
const allDone = todos.length > 0 && todos.every((t) => t.status === "completed");
|
|
207
|
+
// "Zero residuals" needs the review reports: when they were not read this
|
|
208
|
+
// time (snapshot budget), the plan waits for the next fold.
|
|
209
|
+
if (allDone && inputs.reviewsCollected !== false && !plansWithOpenGaps.has(file)) {
|
|
210
|
+
push(`plan:${file}`, "plan", lastEnd, file);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
for (const run of Array.isArray(inputs.testResults?.runs) ? inputs.testResults.runs : []) {
|
|
215
|
+
if (!isRecord(run) || run.ok !== true) continue;
|
|
216
|
+
const head = typeof run.head === "string" && SHA_RE.test(run.head) ? run.head : null;
|
|
217
|
+
if (!head) continue;
|
|
218
|
+
push(`test:${head}`, "test", run.at, `tests passed @ ${head.slice(0, 8)}`);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
for (const run of Array.isArray(inputs.ciRuns) ? inputs.ciRuns : []) {
|
|
222
|
+
if (!isRecord(run) || run.conclusion !== "success") continue;
|
|
223
|
+
// A cron run passes with no work behind it: not an outcome.
|
|
224
|
+
if (run.event === "schedule") continue;
|
|
225
|
+
const id = run.id == null ? "" : String(run.id);
|
|
226
|
+
if (!RUN_ID_RE.test(id)) continue;
|
|
227
|
+
push(`ci:${id}`, "ci", run.createdAt, run.workflow || `run ${id}`);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
for (const tag of Array.isArray(inputs.tags) ? inputs.tags : []) {
|
|
231
|
+
const name = isRecord(tag) && typeof tag.name === "string" ? tag.name : null;
|
|
232
|
+
if (!name || !TAG_RE.test(name)) continue;
|
|
233
|
+
push(`release-cut:${name}`, "releaseCut", tag.date ?? null, name);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const rel = inputs.originRelease;
|
|
237
|
+
if (
|
|
238
|
+
isRecord(rel) &&
|
|
239
|
+
typeof rel.tag === "string" &&
|
|
240
|
+
TAG_RE.test(rel.tag) &&
|
|
241
|
+
isoOrNull(rel.publishedAt)
|
|
242
|
+
) {
|
|
243
|
+
push(`release-published:${rel.tag}`, "releasePublished", rel.publishedAt, rel.tag);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
events.push(...historyLedgerEvents(inputs.historyLedger, inputs.historyRepo ?? null));
|
|
247
|
+
return events;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/** Rows of a history-ledger section as objects (columns + rows table). */
|
|
251
|
+
function historyRows(section) {
|
|
252
|
+
if (!isRecord(section) || !Array.isArray(section.columns) || !Array.isArray(section.rows)) {
|
|
253
|
+
return [];
|
|
254
|
+
}
|
|
255
|
+
const cols = section.columns;
|
|
256
|
+
return section.rows
|
|
257
|
+
.filter(Array.isArray)
|
|
258
|
+
.map((row) => Object.fromEntries(cols.map((c, i) => [c, row[i]])));
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/** Optional factory evidence: published releases and successful workflow runs. */
|
|
262
|
+
function historyLedgerEvents(history, repo) {
|
|
263
|
+
if (!isRecord(history) || !isRecord(history.sections)) return [];
|
|
264
|
+
const events = [];
|
|
265
|
+
for (const r of historyRows(history.sections.releases)) {
|
|
266
|
+
const tag = typeof r.tagName === "string" ? r.tagName : null;
|
|
267
|
+
if (!tag || !TAG_RE.test(tag) || !isoOrNull(r.publishedAt)) continue;
|
|
268
|
+
events.push({
|
|
269
|
+
key: `release-published:${tag}`,
|
|
270
|
+
kind: "releasePublished",
|
|
271
|
+
resource: OUTCOME_KINDS.releasePublished,
|
|
272
|
+
at: isoOrNull(r.publishedAt),
|
|
273
|
+
label: tag,
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
for (const r of historyRows(history.sections.workflowRuns)) {
|
|
277
|
+
const id = r.databaseId == null ? "" : String(r.databaseId);
|
|
278
|
+
if (r.conclusion !== "success" || r.event === "schedule" || !RUN_ID_RE.test(id)) continue;
|
|
279
|
+
// Runs of another repository (the factory's public mirror) are not this workspace's work.
|
|
280
|
+
if (repo && typeof r.repository === "string" && r.repository !== repo) continue;
|
|
281
|
+
events.push({
|
|
282
|
+
key: `ci:${id}`,
|
|
283
|
+
kind: "ci",
|
|
284
|
+
resource: OUTCOME_KINDS.ci,
|
|
285
|
+
at: isoOrNull(r.createdAt),
|
|
286
|
+
label: `run ${id}`,
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
return events;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Fold events into a ledger. First write wins: an existing key is never
|
|
294
|
+
* changed (except a null `at` filled once), so `fold(fold(L, E), E)` equals `fold(L, E)` and `fold(L, [])`
|
|
295
|
+
* equals `L`. `sources` records fingerprints of folded bulk sources (see
|
|
296
|
+
* parseOutcomeLedger). Returns a new ledger; `added` counts new keys.
|
|
297
|
+
*/
|
|
298
|
+
export function foldOutcomeLedger(prev, events, sources = {}) {
|
|
299
|
+
const base = parseOutcomeLedger(prev);
|
|
300
|
+
const entries = { ...base.entries };
|
|
301
|
+
let count = Object.keys(entries).length;
|
|
302
|
+
let added = 0;
|
|
303
|
+
for (const ev of Array.isArray(events) ? events : []) {
|
|
304
|
+
if (!isRecord(ev) || typeof ev.key !== "string" || !OUTCOME_KINDS[ev.kind]) continue;
|
|
305
|
+
if (Object.hasOwn(entries, ev.key)) {
|
|
306
|
+
// The only change ever made to an earned entry: a missing time is filled
|
|
307
|
+
// once a source provides it (still idempotent: a set time never moves).
|
|
308
|
+
const at = isoOrNull(ev.at);
|
|
309
|
+
if (entries[ev.key].at === null && at) entries[ev.key] = { ...entries[ev.key], at };
|
|
310
|
+
continue;
|
|
311
|
+
}
|
|
312
|
+
if (count >= MAX_LEDGER_ENTRIES) break;
|
|
313
|
+
entries[ev.key] = {
|
|
314
|
+
kind: ev.kind,
|
|
315
|
+
resource: OUTCOME_KINDS[ev.kind],
|
|
316
|
+
at: isoOrNull(ev.at),
|
|
317
|
+
label: cap(ev.label),
|
|
318
|
+
};
|
|
319
|
+
count += 1;
|
|
320
|
+
added += 1;
|
|
321
|
+
}
|
|
322
|
+
const nextSources = { ...base.sources };
|
|
323
|
+
for (const [name, stamp] of Object.entries(isRecord(sources) ? sources : {})) {
|
|
324
|
+
if (safePart(name) && typeof stamp === "string" && stamp.length <= 64)
|
|
325
|
+
nextSources[name] = stamp;
|
|
326
|
+
}
|
|
327
|
+
return { ledger: { version: OUTCOME_LEDGER_VERSION, entries, sources: nextSources }, added };
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* A tick that broke the streak: failed result, a HITL gate, or a stop line
|
|
332
|
+
* (other than the stop that ends an exhausted plan).
|
|
333
|
+
* Run logs are a reason to withhold the flow bonus, never a source of reward.
|
|
334
|
+
*/
|
|
335
|
+
function isBreakingTick(log) {
|
|
336
|
+
if (!isRecord(log) || log.kind !== "tick") return false;
|
|
337
|
+
if (isRecord(log.result) && log.result.isError === true) return true;
|
|
338
|
+
if (Array.isArray(log.gates) && log.gates.length > 0) return true;
|
|
339
|
+
if (typeof log.sentinel !== "string") return false;
|
|
340
|
+
const line = log.sentinel.trim();
|
|
341
|
+
// A stop because the plan ran out of to-dos ends the mission; it is not a failure.
|
|
342
|
+
return (
|
|
343
|
+
/^LOOP_TICK_RESULT:\s*stop/i.test(line) &&
|
|
344
|
+
!/^LOOP_TICK_RESULT:\s*stop\s*[—-]\s*plan exhausted\b/i.test(line)
|
|
345
|
+
);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* Flow signal (ADR point 6): consecutive to-dos closed in the most recent
|
|
350
|
+
* mission with no failed or stopped tick between them (or after the last
|
|
351
|
+
* close). A raw signal: the overclock threshold and its window are renderer
|
|
352
|
+
* tuning, not ledger state, and nothing here reads the clock.
|
|
353
|
+
*
|
|
354
|
+
* @param {{missions?: object}} timing parsed mission-timing.json
|
|
355
|
+
* @param {Array<object>} runLogs snapshot runLogs rows (any plan: run logs do not name one)
|
|
356
|
+
* @param {Array<{file:string, todos:Array<{id:string,status:string}>}>|null} [plans] when given, only completed to-dos count
|
|
357
|
+
* @returns {{plan:string, streak:number, lastClosedAt:string|null, brokenAt:string|null}|null}
|
|
358
|
+
*/
|
|
359
|
+
export function deriveFlowSignal(timing, runLogs = [], plans = null) {
|
|
360
|
+
const missions = isRecord(timing?.missions) ? timing.missions : {};
|
|
361
|
+
// A stage ends when the panel saw the to-do stop being current; only the
|
|
362
|
+
// ones whose to-do is completed in the plan count as closes.
|
|
363
|
+
const completed = new Map();
|
|
364
|
+
for (const p of Array.isArray(plans) ? plans : []) {
|
|
365
|
+
if (!isRecord(p) || typeof p.file !== "string" || !Array.isArray(p.todos)) continue;
|
|
366
|
+
completed.set(
|
|
367
|
+
p.file,
|
|
368
|
+
new Set(p.todos.filter((t) => isRecord(t) && t.status === "completed").map((t) => t.id)),
|
|
369
|
+
);
|
|
370
|
+
}
|
|
371
|
+
let best = null;
|
|
372
|
+
for (const [plan, mission] of Object.entries(missions)) {
|
|
373
|
+
if (!isRecord(mission) || mission.frozenAt || !isRecord(mission.stages)) continue;
|
|
374
|
+
const done = plans ? (completed.get(plan) ?? new Set()) : null;
|
|
375
|
+
const ends = Object.entries(mission.stages)
|
|
376
|
+
.filter(([todoId]) => !done || done.has(todoId))
|
|
377
|
+
.map(([, s]) => (isRecord(s) ? isoOrNull(s.endedAt) : null))
|
|
378
|
+
.filter(Boolean)
|
|
379
|
+
.sort();
|
|
380
|
+
if (ends.length === 0) continue;
|
|
381
|
+
const last = ends[ends.length - 1];
|
|
382
|
+
if (!best || last > best.ends[best.ends.length - 1]) best = { plan, ends };
|
|
383
|
+
}
|
|
384
|
+
if (!best) return null;
|
|
385
|
+
const breaks = (Array.isArray(runLogs) ? runLogs : [])
|
|
386
|
+
.filter(isBreakingTick)
|
|
387
|
+
.map((l) => isoOrNull(l.updatedAt))
|
|
388
|
+
.filter(Boolean)
|
|
389
|
+
.sort();
|
|
390
|
+
const ends = best.ends;
|
|
391
|
+
const lastClosedAt = ends[ends.length - 1];
|
|
392
|
+
const after = breaks.filter((b) => b > lastClosedAt);
|
|
393
|
+
if (after.length > 0) {
|
|
394
|
+
return { plan: best.plan, streak: 0, lastClosedAt, brokenAt: after[after.length - 1] };
|
|
395
|
+
}
|
|
396
|
+
let streak = 1;
|
|
397
|
+
let brokenAt = null;
|
|
398
|
+
for (let i = ends.length - 1; i > 0; i -= 1) {
|
|
399
|
+
const between = breaks.filter((b) => b > ends[i - 1] && b <= ends[i]);
|
|
400
|
+
if (between.length > 0) {
|
|
401
|
+
brokenAt = between[between.length - 1];
|
|
402
|
+
break;
|
|
403
|
+
}
|
|
404
|
+
streak += 1;
|
|
405
|
+
}
|
|
406
|
+
return { plan: best.plan, streak, lastClosedAt, brokenAt };
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* Read-only snapshot field from a ledger: totals per resource, counts per
|
|
411
|
+
* kind, the newest entries (capped) and the flow signal.
|
|
412
|
+
*/
|
|
413
|
+
export function summarizeOutcomeLedger(ledger, extras = {}) {
|
|
414
|
+
const parsed = parseOutcomeLedger(ledger);
|
|
415
|
+
const totals = { logic: 0, compute: 0, rare: 0 };
|
|
416
|
+
const byKind = Object.fromEntries(Object.keys(OUTCOME_KINDS).map((k) => [k, 0]));
|
|
417
|
+
const rows = [];
|
|
418
|
+
for (const [key, e] of Object.entries(parsed.entries)) {
|
|
419
|
+
if (!e.resource) continue; // a kind from a newer engine: kept, not counted
|
|
420
|
+
totals[e.resource] += 1;
|
|
421
|
+
byKind[e.kind] += 1;
|
|
422
|
+
rows.push({ key, ...e });
|
|
423
|
+
}
|
|
424
|
+
rows.sort((a, b) => {
|
|
425
|
+
const at = a.at ?? "";
|
|
426
|
+
const bt = b.at ?? "";
|
|
427
|
+
if (at !== bt) return at < bt ? 1 : -1;
|
|
428
|
+
return a.key < b.key ? -1 : a.key > b.key ? 1 : 0;
|
|
429
|
+
});
|
|
430
|
+
return {
|
|
431
|
+
available: extras.available !== false,
|
|
432
|
+
reason: extras.available === false ? (extras.reason ?? "unreadable") : null,
|
|
433
|
+
version: OUTCOME_LEDGER_VERSION,
|
|
434
|
+
path: OUTCOME_LEDGER_REL,
|
|
435
|
+
entries: rows.length,
|
|
436
|
+
totals,
|
|
437
|
+
byKind,
|
|
438
|
+
recent: rows.slice(0, MAX_RECENT_ENTRIES),
|
|
439
|
+
flow: extras.flow ?? null,
|
|
440
|
+
tests: extras.tests ?? { configured: false, lastRun: null },
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
/** Empty snapshot field (default, and the budget-miss shape). */
|
|
445
|
+
export function emptyOutcomeLedgerSummary(reason = null) {
|
|
446
|
+
return summarizeOutcomeLedger(emptyOutcomeLedger(), {
|
|
447
|
+
available: reason == null,
|
|
448
|
+
reason,
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
// --- fs helpers (callers: dashboard-data.mjs, `agent-kit outcome-ledger`) ---
|
|
453
|
+
|
|
454
|
+
function readJson(path) {
|
|
455
|
+
try {
|
|
456
|
+
return JSON.parse(readFileSync(path, "utf-8"));
|
|
457
|
+
} catch {
|
|
458
|
+
return null;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/** Write atomically, and only when the bytes change. Returns true when written. */
|
|
463
|
+
function writeIfChanged(path, text) {
|
|
464
|
+
let prev = null;
|
|
465
|
+
if (existsSync(path)) {
|
|
466
|
+
try {
|
|
467
|
+
prev = readFileSync(path, "utf-8");
|
|
468
|
+
} catch {
|
|
469
|
+
prev = null;
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
if (prev === text) return false;
|
|
473
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
474
|
+
const tmp = `${path}.${process.pid}.tmp`;
|
|
475
|
+
try {
|
|
476
|
+
writeFileSync(tmp, text, "utf-8");
|
|
477
|
+
renameSync(tmp, path);
|
|
478
|
+
} finally {
|
|
479
|
+
rmSync(tmp, { force: true });
|
|
480
|
+
}
|
|
481
|
+
return true;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
export function readOutcomeLedger(root) {
|
|
485
|
+
return readOutcomeLedgerFile(root).ledger;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
/**
|
|
489
|
+
* The persisted ledger plus whether a fold may write over it. An unreadable
|
|
490
|
+
* file or another version is never overwritten (an engine downgrade or a
|
|
491
|
+
* corrupt file must not erase what was earned).
|
|
492
|
+
*/
|
|
493
|
+
export function readOutcomeLedgerFile(root) {
|
|
494
|
+
const path = join(root, OUTCOME_LEDGER_REL);
|
|
495
|
+
if (!existsSync(path)) return { ledger: emptyOutcomeLedger(), foldable: true };
|
|
496
|
+
const raw = readJson(path);
|
|
497
|
+
const foldable = raw !== null && isFoldableOutcomeLedger(raw);
|
|
498
|
+
return { ledger: foldable ? parseOutcomeLedger(raw) : emptyOutcomeLedger(), foldable };
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
export function persistOutcomeLedger(root, ledger) {
|
|
502
|
+
const path = join(root, OUTCOME_LEDGER_REL);
|
|
503
|
+
const parsed = parseOutcomeLedger(ledger);
|
|
504
|
+
// A fresh install with nothing earned yet leaves no file behind.
|
|
505
|
+
if (Object.keys(parsed.entries).length === 0 && !existsSync(path)) return false;
|
|
506
|
+
return writeIfChanged(path, serializeOutcomeLedger(parsed));
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
/** Parse test-results.json: `{version: 1, runs: [{at, ok, exitCode, head, commands}]}`. */
|
|
510
|
+
export function parseTestResults(raw) {
|
|
511
|
+
const runs = [];
|
|
512
|
+
if (isRecord(raw) && raw.version === 1 && Array.isArray(raw.runs)) {
|
|
513
|
+
for (const r of raw.runs) {
|
|
514
|
+
if (!isRecord(r) || typeof r.ok !== "boolean" || !isoOrNull(r.at)) continue;
|
|
515
|
+
runs.push({
|
|
516
|
+
at: isoOrNull(r.at),
|
|
517
|
+
ok: r.ok,
|
|
518
|
+
exitCode: Number.isInteger(r.exitCode) ? r.exitCode : null,
|
|
519
|
+
head: typeof r.head === "string" && SHA_RE.test(r.head) ? r.head : null,
|
|
520
|
+
commands: Array.isArray(r.commands)
|
|
521
|
+
? r.commands
|
|
522
|
+
.filter((c) => typeof c === "string")
|
|
523
|
+
.slice(0, MAX_COMMANDS)
|
|
524
|
+
.map((c) => cap(c, MAX_COMMAND_CHARS))
|
|
525
|
+
: [],
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
return { version: 1, runs: runs.slice(-MAX_TEST_RESULTS) };
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
export function readTestResults(root) {
|
|
533
|
+
return parseTestResults(readJson(join(root, TEST_RESULTS_REL)));
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
/** Append one run, keeping the newest MAX_TEST_RESULTS. */
|
|
537
|
+
export function appendTestResult(root, run) {
|
|
538
|
+
const current = readTestResults(root);
|
|
539
|
+
const next = parseTestResults({ version: 1, runs: [...current.runs, run] });
|
|
540
|
+
writeIfChanged(join(root, TEST_RESULTS_REL), `${JSON.stringify(next, null, 2)}\n`);
|
|
541
|
+
return next;
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
/**
|
|
545
|
+
* The repo's own test commands from the repository profile
|
|
546
|
+
* (`.cursor/agent-kit.config.json#stack.testCommands`, written by the scanner
|
|
547
|
+
* or confirmed by the operator). Never guessed: no profile, no commands.
|
|
548
|
+
*/
|
|
549
|
+
export function readProfileTestCommands(root) {
|
|
550
|
+
const profile = readJson(join(root, REPOSITORY_PROFILE_REL));
|
|
551
|
+
const list = isRecord(profile) && isRecord(profile.stack) ? profile.stack.testCommands : null;
|
|
552
|
+
return Array.isArray(list)
|
|
553
|
+
? list.filter((c) => typeof c === "string" && c.trim()).slice(0, MAX_COMMANDS)
|
|
554
|
+
: [];
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
/** Test collector status for the snapshot field. */
|
|
558
|
+
export function testCollectorStatus(root, testResults) {
|
|
559
|
+
const runs = testResults?.runs ?? [];
|
|
560
|
+
const last = runs.length > 0 ? runs[runs.length - 1] : null;
|
|
561
|
+
return {
|
|
562
|
+
configured: readProfileTestCommands(root).length > 0,
|
|
563
|
+
lastRun: last ? { at: last.at, ok: last.ok, head: last.head } : null,
|
|
564
|
+
};
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
/**
|
|
568
|
+
* Run the profile's test commands in order (stop at the first failure) and
|
|
569
|
+
* record the pass/fail outcome keyed by HEAD. Records only the outcome, never
|
|
570
|
+
* a count of tests or assertions.
|
|
571
|
+
* @returns {{status: "no-commands"} | {status: "recorded", run: object}}
|
|
572
|
+
*/
|
|
573
|
+
export function runAndRecordTests(root, opts = {}) {
|
|
574
|
+
const commands = opts.commands ?? readProfileTestCommands(root);
|
|
575
|
+
if (commands.length === 0) return { status: "no-commands" };
|
|
576
|
+
const spawn = opts.spawn ?? spawnSync;
|
|
577
|
+
let exitCode = 0;
|
|
578
|
+
for (const command of commands) {
|
|
579
|
+
if (typeof opts.onCommand === "function") opts.onCommand(command);
|
|
580
|
+
const res = spawn(command, { cwd: root, shell: true, stdio: opts.stdio ?? "inherit" });
|
|
581
|
+
exitCode = typeof res.status === "number" ? res.status : 1;
|
|
582
|
+
if (exitCode !== 0) break;
|
|
583
|
+
}
|
|
584
|
+
const headRes = spawn("git", ["rev-parse", "HEAD"], { cwd: root, encoding: "utf-8" });
|
|
585
|
+
const head = String(headRes?.stdout ?? "").trim();
|
|
586
|
+
const run = {
|
|
587
|
+
at: (opts.now ?? new Date()).toISOString(),
|
|
588
|
+
ok: exitCode === 0,
|
|
589
|
+
exitCode,
|
|
590
|
+
head: SHA_RE.test(head) ? head : null,
|
|
591
|
+
commands,
|
|
592
|
+
};
|
|
593
|
+
appendTestResult(root, run);
|
|
594
|
+
return { status: "recorded", run };
|
|
595
|
+
}
|
|
@@ -53,3 +53,17 @@ export function buildFlightLogTickets(
|
|
|
53
53
|
tickets: Record<string, unknown>[] | null | undefined,
|
|
54
54
|
opts?: { cap?: number },
|
|
55
55
|
): FlightLogTicket[];
|
|
56
|
+
|
|
57
|
+
/** Mission Control snapshot slice (`missionControl`); typed loosely for the TUI tests. */
|
|
58
|
+
export type MissionControlView = {
|
|
59
|
+
now: Record<string, unknown> & { status: string; gaps: string | null };
|
|
60
|
+
flightLog: Record<string, unknown> & { current: string | null };
|
|
61
|
+
[key: string]: unknown;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export function buildMissionControlView(input: {
|
|
65
|
+
plans?: unknown[];
|
|
66
|
+
handoff?: HandoffMarkdown | null;
|
|
67
|
+
nowMs?: number;
|
|
68
|
+
[key: string]: unknown;
|
|
69
|
+
}): MissionControlView;
|
|
@@ -2044,6 +2044,9 @@ export function buildCurrentExecution(plans, handoff) {
|
|
|
2044
2044
|
planFile: null,
|
|
2045
2045
|
planPath: null,
|
|
2046
2046
|
mode: null,
|
|
2047
|
+
// Gaps outlive the plan: with `Plan: none` they still feed the Flight Log NOW
|
|
2048
|
+
// residual, so the cockpit never reads All clear over open Gaps.
|
|
2049
|
+
gaps: handoff?.gaps || null,
|
|
2047
2050
|
progress: { completed: 0, total: 0 },
|
|
2048
2051
|
previousTodo: null,
|
|
2049
2052
|
currentTodo: null,
|
package/dashboard/serve.mjs
CHANGED
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
import {
|
|
20
20
|
assessClaudeCommandAdapters,
|
|
21
21
|
executeSafeReadinessFixes
|
|
22
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-GQ6Q3P7C.js";
|
|
23
23
|
import {
|
|
24
24
|
writeReadinessSnapshot
|
|
25
25
|
} from "./chunk-HAFRAXGV.js";
|
|
@@ -41,7 +41,7 @@ import {
|
|
|
41
41
|
REPOSITORY_PROFILE_REL,
|
|
42
42
|
detectIde,
|
|
43
43
|
runScanner
|
|
44
|
-
} from "./chunk-
|
|
44
|
+
} from "./chunk-SC2DBY2R.js";
|
|
45
45
|
import {
|
|
46
46
|
GIT_PLATFORM_META
|
|
47
47
|
} from "./chunk-F6C3GFKV.js";
|
|
@@ -40,6 +40,7 @@ var SNAPSHOT_REPO_SOURCE_RELS = Object.freeze([
|
|
|
40
40
|
".cursor/context/field-report-dismissals.json",
|
|
41
41
|
".cursor/context/mission-timing.json",
|
|
42
42
|
".cursor/context/flight-log.json",
|
|
43
|
+
".cursor/context/test-results.json",
|
|
43
44
|
".cursor/context/field-report-cadence.json",
|
|
44
45
|
".cursor/skills",
|
|
45
46
|
"package.json"
|
|
@@ -437,6 +437,8 @@ var KIT_OWNED_IGNORE_PATTERNS = [
|
|
|
437
437
|
".cursor/context/readiness.json",
|
|
438
438
|
".cursor/context/flight-log.json",
|
|
439
439
|
".cursor/context/mission-timing.json",
|
|
440
|
+
".cursor/context/outcome-ledger.json",
|
|
441
|
+
".cursor/context/test-results.json",
|
|
440
442
|
".cursor/context/gate-exit.json",
|
|
441
443
|
".cursor/context/review-ledger.json",
|
|
442
444
|
".cursor/context/plan-index.json",
|