@dadado/agent-kit-cli 6.8.0 → 6.10.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/dashboard/README.md +31 -5
- 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 +385 -9
- package/dashboard/dashboard.html +794 -75
- 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/ship-lane.mjs +690 -0
- package/dashboard/serve.mjs +20 -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-M3W3QE62.js} +14 -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-DXGTFYJK.js → run-326EEQYY.js} +34 -11
- 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
package/dashboard/serve.mjs
CHANGED
|
@@ -39,6 +39,7 @@ import {
|
|
|
39
39
|
} from "./lib/live-refresh.mjs";
|
|
40
40
|
import { PIPELINE_CACHE_ENV, pipelineCacheJsonFromSnapshot } from "./lib/pipeline-cache.mjs";
|
|
41
41
|
import { buildInventoryBaseline } from "./lib/semantic-model.mjs";
|
|
42
|
+
import { SHIP_LANE_CACHE_ENV, shipLaneCacheJsonFromSnapshot } from "./lib/ship-lane.mjs";
|
|
42
43
|
|
|
43
44
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
44
45
|
/** Kit tree that owns `dashboard/` static assets and serve.mjs. */
|
|
@@ -68,6 +69,7 @@ const MIME = {
|
|
|
68
69
|
".mjs": "application/javascript; charset=utf-8",
|
|
69
70
|
".css": "text/css",
|
|
70
71
|
".png": "image/png",
|
|
72
|
+
".webp": "image/webp",
|
|
71
73
|
".svg": "image/svg+xml",
|
|
72
74
|
".ico": "image/x-icon",
|
|
73
75
|
};
|
|
@@ -78,6 +80,8 @@ const dataScript = join(__dirname, "dashboard-data.mjs");
|
|
|
78
80
|
let previousInventoryJson = null;
|
|
79
81
|
/** Last attempted devops.pipeline (with fetchedAt); the data script reuses it while fresh. */
|
|
80
82
|
let previousPipelineJson = null;
|
|
83
|
+
/** Last attempted shipLane.remote (with fetchedAt); reused for up to 120s (lib/ship-lane.mjs). */
|
|
84
|
+
let previousShipLaneJson = null;
|
|
81
85
|
|
|
82
86
|
/**
|
|
83
87
|
* @param {string} payload
|
|
@@ -113,6 +117,19 @@ function pipelineCacheJsonFromPayload(payload) {
|
|
|
113
117
|
}
|
|
114
118
|
}
|
|
115
119
|
|
|
120
|
+
/**
|
|
121
|
+
* @param {string} payload
|
|
122
|
+
* @returns {string|null}
|
|
123
|
+
*/
|
|
124
|
+
function shipLaneCacheJsonFromPayload(payload) {
|
|
125
|
+
try {
|
|
126
|
+
const data = JSON.parse(payload);
|
|
127
|
+
return data && !data.error ? shipLaneCacheJsonFromSnapshot(data) : null;
|
|
128
|
+
} catch {
|
|
129
|
+
return null;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
116
133
|
function setCorsHeaders(req, res) {
|
|
117
134
|
applyCorsHeaders(req, res, PORT);
|
|
118
135
|
}
|
|
@@ -286,6 +303,7 @@ function runDataScript() {
|
|
|
286
303
|
// Empty string = cold start (dashboard-data treats falsy as no previous).
|
|
287
304
|
AGENT_KIT_PREV_INVENTORY: previousInventoryJson || "",
|
|
288
305
|
[PIPELINE_CACHE_ENV]: previousPipelineJson || "",
|
|
306
|
+
[SHIP_LANE_CACHE_ENV]: previousShipLaneJson || "",
|
|
289
307
|
};
|
|
290
308
|
execFile(
|
|
291
309
|
process.execPath,
|
|
@@ -310,6 +328,8 @@ function runDataScript() {
|
|
|
310
328
|
if (baseline) previousInventoryJson = baseline;
|
|
311
329
|
const pipelineCache = pipelineCacheJsonFromPayload(stdout);
|
|
312
330
|
if (pipelineCache) previousPipelineJson = pipelineCache;
|
|
331
|
+
const shipLaneCache = shipLaneCacheJsonFromPayload(stdout);
|
|
332
|
+
if (shipLaneCache) previousShipLaneJson = shipLaneCache;
|
|
313
333
|
// Chat titles are private: a broadcast (LAN, token-gated) server never serves them, even
|
|
314
334
|
// if the child missed the bind env. Every route (/api/data, SSE connect, push) reads this.
|
|
315
335
|
resolve(authResolved.broadcast ? withholdChatsFromPayload(stdout) : stdout);
|
|
@@ -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",
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
assessHooksHealth,
|
|
3
3
|
executeSafeReadinessFixes,
|
|
4
4
|
refreshRepositoryProfile
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-GQ6Q3P7C.js";
|
|
6
6
|
import {
|
|
7
7
|
writeReadinessSnapshot
|
|
8
8
|
} from "./chunk-HAFRAXGV.js";
|
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
} from "./chunk-PNFF6OU3.js";
|
|
23
23
|
import {
|
|
24
24
|
runScanner
|
|
25
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-SC2DBY2R.js";
|
|
26
26
|
import "./chunk-F6C3GFKV.js";
|
|
27
27
|
import {
|
|
28
28
|
logger
|
|
@@ -315,6 +315,14 @@ function parsePrMergeHead(head) {
|
|
|
315
315
|
}
|
|
316
316
|
return { forge, selector, repo };
|
|
317
317
|
}
|
|
318
|
+
var FORGE_API_CALL_RE = /(?:^|[\s'"(;|&`$])(?:[\w./-]+\/)?(?:gh|glab)\s+api(?:\s|$)/;
|
|
319
|
+
var FORGE_API_MERGE_RE = /\bpulls\/[^/\s'"]+\/merge\b|\/merges\b|\bmerge_requests\/[^/\s'"]+\/merge\b|\b(?:mergePullRequest|enablePullRequestAutoMerge|enqueuePullRequest|mergeBranch|mergeRequestAccept|mergeRequestSetAutoMerge)\b/;
|
|
320
|
+
function forgeApiMergeCall(command) {
|
|
321
|
+
if (!FORGE_API_MERGE_RE.test(command)) return false;
|
|
322
|
+
return shellSegments(command).some(
|
|
323
|
+
(segment) => FORGE_API_CALL_RE.test(segment) && !segmentHasAllowMainPushEnv(segment)
|
|
324
|
+
);
|
|
325
|
+
}
|
|
318
326
|
function prMergeKey(target) {
|
|
319
327
|
return `${target.forge}\0${target.repo ?? ""}\0${target.selector ?? ""}`;
|
|
320
328
|
}
|
|
@@ -430,9 +438,13 @@ var SHELL_DENY_RULES = [
|
|
|
430
438
|
{
|
|
431
439
|
// Claude settings allow `gh pr merge` / `glab mr merge` so the /git-staging merge
|
|
432
440
|
// skips the auto-mode classifier; this rule keeps that allowance to non-protected bases.
|
|
441
|
+
// A forge API merge (`gh api … pulls/<n>/merge`, a GraphQL merge mutation) has no base
|
|
442
|
+
// to resolve and no /git-staging use: it is denied outright, so neither the API nor
|
|
443
|
+
// Colony's host path (typed yes for main) can be bypassed that way.
|
|
433
444
|
id: "pr-merge-protected-base",
|
|
434
|
-
description: "merging a PR/MR into main/master/prod bypasses /git-prod; an unresolved base (gh/glab could not read the PR/MR: not logged in, wrong selector, or no such PR) is denied too",
|
|
445
|
+
description: "merging a PR/MR into main/master/prod bypasses /git-prod; an unresolved base (gh/glab could not read the PR/MR: not logged in, wrong selector, or no such PR) is denied too, and so is any gh api / glab api merge call (REST merge endpoint or GraphQL merge mutation)",
|
|
435
446
|
test: (cmd, opts) => {
|
|
447
|
+
if (forgeApiMergeCall(cmd)) return true;
|
|
436
448
|
const bases = opts?.prMergeBases;
|
|
437
449
|
if (!bases) return false;
|
|
438
450
|
return shellSegments(cmd).some((segment) => {
|
|
@@ -567,7 +579,7 @@ var guardCommand = defineCommand({
|
|
|
567
579
|
shell: defineCommand({
|
|
568
580
|
meta: {
|
|
569
581
|
name: "shell",
|
|
570
|
-
description: "Evaluate a shell command against the git-workflow / protected-branch deny-list (git checkout|restore|reset --hard|clean -fd + pushes to main/master/prod + gh pr merge / glab mr merge into main/master/prod or an unresolved base + direct git push/gh pr create|merge against the public repo). Not a general destructive-command guard: rm -rf, chmod, dd are allowed."
|
|
582
|
+
description: "Evaluate a shell command against the git-workflow / protected-branch deny-list (git checkout|restore|reset --hard|clean -fd + pushes to main/master/prod + gh pr merge / glab mr merge into main/master/prod or an unresolved base + any gh api / glab api merge call + direct git push/gh pr create|merge against the public repo). Not a general destructive-command guard: rm -rf, chmod, dd are allowed."
|
|
571
583
|
},
|
|
572
584
|
args: {
|
|
573
585
|
json: {
|
package/dist/index.js
CHANGED
|
@@ -132,7 +132,14 @@ var CLI_HELP_GROUPS = [
|
|
|
132
132
|
{
|
|
133
133
|
id: "dashboard",
|
|
134
134
|
title: "DASHBOARD",
|
|
135
|
-
commands: [
|
|
135
|
+
commands: [
|
|
136
|
+
"dashboard",
|
|
137
|
+
"dashboard-broadcast",
|
|
138
|
+
"mission-control",
|
|
139
|
+
"monitors",
|
|
140
|
+
"sessions",
|
|
141
|
+
"outcome-ledger"
|
|
142
|
+
]
|
|
136
143
|
},
|
|
137
144
|
{
|
|
138
145
|
id: "integrity",
|
|
@@ -224,13 +231,13 @@ var main = defineCommand({
|
|
|
224
231
|
version: KIT_VERSION
|
|
225
232
|
},
|
|
226
233
|
subCommands: {
|
|
227
|
-
init: () => import("./init-
|
|
228
|
-
install: () => import("./install-
|
|
229
|
-
scan: () => import("./scan-
|
|
234
|
+
init: () => import("./init-KKVT2RW4.js").then((m) => m.initCommand),
|
|
235
|
+
install: () => import("./install-BPZTP5KT.js").then((m) => m.installCommand),
|
|
236
|
+
scan: () => import("./scan-BWA64R7I.js").then((m) => m.scanCommand),
|
|
230
237
|
add: () => import("./add-7GH3K44T.js").then((m) => m.addCommand),
|
|
231
|
-
doctor: () => import("./doctor-
|
|
238
|
+
doctor: () => import("./doctor-E6LOBJYK.js").then((m) => m.doctorCommand),
|
|
232
239
|
"setup-global": () => import("./setup-global-BFBSR2RZ.js").then((m) => m.setupGlobalCommand),
|
|
233
|
-
status: () => import("./status-
|
|
240
|
+
status: () => import("./status-LNXVLDMP.js").then((m) => m.statusCommand),
|
|
234
241
|
update: () => import("./update-PX5XFCSG.js").then((m) => m.updateCommand),
|
|
235
242
|
"cursor-awareness": () => import("./cursor-awareness-TN5JXD2C.js").then((m) => m.cursorAwarenessCommand),
|
|
236
243
|
"public-inbound-radar": () => import("./public-inbound-radar-5U4JMBRU.js").then((m) => m.publicInboundRadarCommand),
|
|
@@ -240,18 +247,19 @@ var main = defineCommand({
|
|
|
240
247
|
contribute: () => import("./contribute-VSVPRHQ7.js").then((m) => m.contributeCommand),
|
|
241
248
|
handoff: () => import("./handoff-5AGE2D3T.js").then((m) => m.handoffCommand),
|
|
242
249
|
"plan-index": () => import("./plan-index-BNLUU6T5.js").then((m) => m.planIndexCommand),
|
|
243
|
-
run: () => import("./run-
|
|
244
|
-
"run-plan": () => import("./run-plan-
|
|
245
|
-
"run-plan-all": () => import("./run-
|
|
250
|
+
run: () => import("./run-326EEQYY.js").then((m) => m.runCommand),
|
|
251
|
+
"run-plan": () => import("./run-plan-2IFO4G4Y.js").then((m) => m.runPlanCommand),
|
|
252
|
+
"run-plan-all": () => import("./run-326EEQYY.js").then((m) => m.runPlanAllCommand),
|
|
246
253
|
countdown: () => import("./countdown-XYRE4GZU.js").then((m) => m.countdownCommand),
|
|
247
254
|
"ground-control": () => import("./ground-control-726LRB6Q.js").then((m) => m.groundControlCommand),
|
|
248
255
|
dashboard: () => import("./dashboard-YNCFISNO.js").then((m) => m.dashboardCommand),
|
|
249
256
|
"dashboard-broadcast": () => import("./dashboard-broadcast-NK7PU72L.js").then((m) => m.dashboardBroadcastCommand),
|
|
250
|
-
"mission-control": () => import("./mission-control-
|
|
257
|
+
"mission-control": () => import("./mission-control-C2QV5D25.js").then((m) => m.missionControlCommand),
|
|
251
258
|
hook: () => import("./hook-HJW5SXQG.js").then((m) => m.hookCommand),
|
|
252
|
-
guard: () => import("./guard-
|
|
259
|
+
guard: () => import("./guard-M3W3QE62.js").then((m) => m.guardCommand),
|
|
253
260
|
monitors: () => import("./monitors-PDXBLB3U.js").then((m) => m.monitorsCommand),
|
|
254
261
|
sessions: () => import("./sessions-O7MYEMCT.js").then((m) => m.sessionsCommand),
|
|
262
|
+
"outcome-ledger": () => import("./outcome-ledger-XLWHWPVQ.js").then((m) => m.outcomeLedgerCommand),
|
|
255
263
|
validate: () => import("./validate-V2CW7J4B.js").then((m) => m.validateCommand),
|
|
256
264
|
"engine-info": () => import("./engine-info-3MQML5I2.js").then((m) => m.engineInfoCommand),
|
|
257
265
|
commands: () => import("./commands-EQHK3ZEP.js").then((m) => m.commandsCommand)
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
nextStepAfterInstall,
|
|
3
3
|
performInstall,
|
|
4
4
|
printInstallEpilogue
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-K5OCGZWA.js";
|
|
6
6
|
import {
|
|
7
7
|
NON_INTERACTIVE_ROOT_ARGS
|
|
8
8
|
} from "./chunk-HIJTNHJE.js";
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
logApplyStats
|
|
12
12
|
} from "./chunk-HS7LVVLO.js";
|
|
13
13
|
import "./chunk-75ELVLBY.js";
|
|
14
|
-
import "./chunk-
|
|
14
|
+
import "./chunk-GQ6Q3P7C.js";
|
|
15
15
|
import "./chunk-HAFRAXGV.js";
|
|
16
16
|
import "./chunk-ZF4YBL7F.js";
|
|
17
17
|
import "./chunk-LGSNC4OI.js";
|
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
withCliProgress
|
|
22
22
|
} from "./chunk-QTON2GQX.js";
|
|
23
23
|
import "./chunk-PNFF6OU3.js";
|
|
24
|
-
import "./chunk-
|
|
24
|
+
import "./chunk-SC2DBY2R.js";
|
|
25
25
|
import "./chunk-F6C3GFKV.js";
|
|
26
26
|
import {
|
|
27
27
|
logger
|
|
@@ -3,11 +3,11 @@ import {
|
|
|
3
3
|
nextStepAfterInstall,
|
|
4
4
|
performInstall,
|
|
5
5
|
printInstallEpilogue
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-K5OCGZWA.js";
|
|
7
7
|
import "./chunk-HIJTNHJE.js";
|
|
8
8
|
import "./chunk-HS7LVVLO.js";
|
|
9
9
|
import "./chunk-75ELVLBY.js";
|
|
10
|
-
import "./chunk-
|
|
10
|
+
import "./chunk-GQ6Q3P7C.js";
|
|
11
11
|
import "./chunk-HAFRAXGV.js";
|
|
12
12
|
import "./chunk-ZF4YBL7F.js";
|
|
13
13
|
import "./chunk-LGSNC4OI.js";
|
|
@@ -15,7 +15,7 @@ import "./chunk-WGLPZXNU.js";
|
|
|
15
15
|
import "./chunk-6RRG3WOE.js";
|
|
16
16
|
import "./chunk-QTON2GQX.js";
|
|
17
17
|
import "./chunk-PNFF6OU3.js";
|
|
18
|
-
import "./chunk-
|
|
18
|
+
import "./chunk-SC2DBY2R.js";
|
|
19
19
|
import "./chunk-F6C3GFKV.js";
|
|
20
20
|
import "./chunk-ZB43YMHW.js";
|
|
21
21
|
import "./chunk-TZA7MT4I.js";
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
// src/commands/outcome-ledger.ts
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { defineCommand } from "citty";
|
|
4
|
+
|
|
5
|
+
// ../../dashboard/lib/outcome-ledger.mjs
|
|
6
|
+
import { spawnSync } from "child_process";
|
|
7
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "fs";
|
|
8
|
+
import { dirname, join } from "path";
|
|
9
|
+
var OUTCOME_LEDGER_REL = ".cursor/context/outcome-ledger.json";
|
|
10
|
+
var TEST_RESULTS_REL = ".cursor/context/test-results.json";
|
|
11
|
+
var REPOSITORY_PROFILE_REL = ".cursor/agent-kit.config.json";
|
|
12
|
+
var OUTCOME_LEDGER_VERSION = 1;
|
|
13
|
+
var MAX_TEST_RESULTS = 200;
|
|
14
|
+
var MAX_RECENT_ENTRIES = 20;
|
|
15
|
+
var MAX_LABEL = 120;
|
|
16
|
+
var MAX_COMMAND_CHARS = 200;
|
|
17
|
+
var MAX_COMMANDS = 5;
|
|
18
|
+
var OUTCOME_KINDS = Object.freeze({
|
|
19
|
+
todo: "logic",
|
|
20
|
+
test: "logic",
|
|
21
|
+
ci: "compute",
|
|
22
|
+
releaseCut: "compute",
|
|
23
|
+
plan: "rare",
|
|
24
|
+
review: "rare",
|
|
25
|
+
releasePublished: "rare"
|
|
26
|
+
});
|
|
27
|
+
var SAFE_PART_RE = /^[A-Za-z0-9][A-Za-z0-9._+-]{0,159}$/;
|
|
28
|
+
var SHA_RE = /^[0-9a-f]{7,40}$/;
|
|
29
|
+
var ISO_RE = /^\d{4}-\d{2}-\d{2}(?:[T ][0-9:.]+(?:Z|[+-]\d{2}:?\d{2})?)?$/;
|
|
30
|
+
var isRecord = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
31
|
+
var safePart = (v) => typeof v === "string" && SAFE_PART_RE.test(v) ? v : null;
|
|
32
|
+
var isoOrNull = (v) => typeof v === "string" && ISO_RE.test(v.trim()) ? v.trim() : null;
|
|
33
|
+
function cap(text, max = MAX_LABEL) {
|
|
34
|
+
const s = String(text ?? "").trim();
|
|
35
|
+
return s.length > max ? `${s.slice(0, max - 1)}\u2026` : s;
|
|
36
|
+
}
|
|
37
|
+
function emptyOutcomeLedger() {
|
|
38
|
+
return { version: OUTCOME_LEDGER_VERSION, entries: {}, sources: {} };
|
|
39
|
+
}
|
|
40
|
+
function parseOutcomeLedger(raw) {
|
|
41
|
+
const out = emptyOutcomeLedger();
|
|
42
|
+
if (!isRecord(raw) || raw.version !== OUTCOME_LEDGER_VERSION || !isRecord(raw.entries)) {
|
|
43
|
+
return out;
|
|
44
|
+
}
|
|
45
|
+
if (isRecord(raw.sources)) {
|
|
46
|
+
for (const [name, stamp] of Object.entries(raw.sources)) {
|
|
47
|
+
if (safePart(name) && typeof stamp === "string" && stamp.length <= 64) {
|
|
48
|
+
out.sources[name] = stamp;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
for (const [key, entry] of Object.entries(raw.entries)) {
|
|
53
|
+
if (typeof key !== "string" || key.length > 400 || !isRecord(entry)) continue;
|
|
54
|
+
if (typeof entry.kind !== "string" || !SAFE_PART_RE.test(entry.kind)) continue;
|
|
55
|
+
out.entries[key] = {
|
|
56
|
+
kind: entry.kind,
|
|
57
|
+
resource: OUTCOME_KINDS[entry.kind] ?? null,
|
|
58
|
+
at: isoOrNull(entry.at),
|
|
59
|
+
label: cap(entry.label)
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
return out;
|
|
63
|
+
}
|
|
64
|
+
function isFoldableOutcomeLedger(raw) {
|
|
65
|
+
return raw === void 0 || isRecord(raw) && raw.version === OUTCOME_LEDGER_VERSION && isRecord(raw.entries);
|
|
66
|
+
}
|
|
67
|
+
function summarizeOutcomeLedger(ledger, extras = {}) {
|
|
68
|
+
const parsed = parseOutcomeLedger(ledger);
|
|
69
|
+
const totals = { logic: 0, compute: 0, rare: 0 };
|
|
70
|
+
const byKind = Object.fromEntries(Object.keys(OUTCOME_KINDS).map((k) => [k, 0]));
|
|
71
|
+
const rows = [];
|
|
72
|
+
for (const [key, e] of Object.entries(parsed.entries)) {
|
|
73
|
+
if (!e.resource) continue;
|
|
74
|
+
totals[e.resource] += 1;
|
|
75
|
+
byKind[e.kind] += 1;
|
|
76
|
+
rows.push({ key, ...e });
|
|
77
|
+
}
|
|
78
|
+
rows.sort((a, b) => {
|
|
79
|
+
const at = a.at ?? "";
|
|
80
|
+
const bt = b.at ?? "";
|
|
81
|
+
if (at !== bt) return at < bt ? 1 : -1;
|
|
82
|
+
return a.key < b.key ? -1 : a.key > b.key ? 1 : 0;
|
|
83
|
+
});
|
|
84
|
+
return {
|
|
85
|
+
available: extras.available !== false,
|
|
86
|
+
reason: extras.available === false ? extras.reason ?? "unreadable" : null,
|
|
87
|
+
version: OUTCOME_LEDGER_VERSION,
|
|
88
|
+
path: OUTCOME_LEDGER_REL,
|
|
89
|
+
entries: rows.length,
|
|
90
|
+
totals,
|
|
91
|
+
byKind,
|
|
92
|
+
recent: rows.slice(0, MAX_RECENT_ENTRIES),
|
|
93
|
+
flow: extras.flow ?? null,
|
|
94
|
+
tests: extras.tests ?? { configured: false, lastRun: null }
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function readJson(path2) {
|
|
98
|
+
try {
|
|
99
|
+
return JSON.parse(readFileSync(path2, "utf-8"));
|
|
100
|
+
} catch {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
function writeIfChanged(path2, text) {
|
|
105
|
+
let prev = null;
|
|
106
|
+
if (existsSync(path2)) {
|
|
107
|
+
try {
|
|
108
|
+
prev = readFileSync(path2, "utf-8");
|
|
109
|
+
} catch {
|
|
110
|
+
prev = null;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (prev === text) return false;
|
|
114
|
+
mkdirSync(dirname(path2), { recursive: true });
|
|
115
|
+
const tmp = `${path2}.${process.pid}.tmp`;
|
|
116
|
+
try {
|
|
117
|
+
writeFileSync(tmp, text, "utf-8");
|
|
118
|
+
renameSync(tmp, path2);
|
|
119
|
+
} finally {
|
|
120
|
+
rmSync(tmp, { force: true });
|
|
121
|
+
}
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
function readOutcomeLedger(root) {
|
|
125
|
+
return readOutcomeLedgerFile(root).ledger;
|
|
126
|
+
}
|
|
127
|
+
function readOutcomeLedgerFile(root) {
|
|
128
|
+
const path2 = join(root, OUTCOME_LEDGER_REL);
|
|
129
|
+
if (!existsSync(path2)) return { ledger: emptyOutcomeLedger(), foldable: true };
|
|
130
|
+
const raw = readJson(path2);
|
|
131
|
+
const foldable = raw !== null && isFoldableOutcomeLedger(raw);
|
|
132
|
+
return { ledger: foldable ? parseOutcomeLedger(raw) : emptyOutcomeLedger(), foldable };
|
|
133
|
+
}
|
|
134
|
+
function parseTestResults(raw) {
|
|
135
|
+
const runs = [];
|
|
136
|
+
if (isRecord(raw) && raw.version === 1 && Array.isArray(raw.runs)) {
|
|
137
|
+
for (const r of raw.runs) {
|
|
138
|
+
if (!isRecord(r) || typeof r.ok !== "boolean" || !isoOrNull(r.at)) continue;
|
|
139
|
+
runs.push({
|
|
140
|
+
at: isoOrNull(r.at),
|
|
141
|
+
ok: r.ok,
|
|
142
|
+
exitCode: Number.isInteger(r.exitCode) ? r.exitCode : null,
|
|
143
|
+
head: typeof r.head === "string" && SHA_RE.test(r.head) ? r.head : null,
|
|
144
|
+
commands: Array.isArray(r.commands) ? r.commands.filter((c) => typeof c === "string").slice(0, MAX_COMMANDS).map((c) => cap(c, MAX_COMMAND_CHARS)) : []
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return { version: 1, runs: runs.slice(-MAX_TEST_RESULTS) };
|
|
149
|
+
}
|
|
150
|
+
function readTestResults(root) {
|
|
151
|
+
return parseTestResults(readJson(join(root, TEST_RESULTS_REL)));
|
|
152
|
+
}
|
|
153
|
+
function appendTestResult(root, run) {
|
|
154
|
+
const current = readTestResults(root);
|
|
155
|
+
const next = parseTestResults({ version: 1, runs: [...current.runs, run] });
|
|
156
|
+
writeIfChanged(join(root, TEST_RESULTS_REL), `${JSON.stringify(next, null, 2)}
|
|
157
|
+
`);
|
|
158
|
+
return next;
|
|
159
|
+
}
|
|
160
|
+
function readProfileTestCommands(root) {
|
|
161
|
+
const profile = readJson(join(root, REPOSITORY_PROFILE_REL));
|
|
162
|
+
const list = isRecord(profile) && isRecord(profile.stack) ? profile.stack.testCommands : null;
|
|
163
|
+
return Array.isArray(list) ? list.filter((c) => typeof c === "string" && c.trim()).slice(0, MAX_COMMANDS) : [];
|
|
164
|
+
}
|
|
165
|
+
function testCollectorStatus(root, testResults) {
|
|
166
|
+
const runs = testResults?.runs ?? [];
|
|
167
|
+
const last = runs.length > 0 ? runs[runs.length - 1] : null;
|
|
168
|
+
return {
|
|
169
|
+
configured: readProfileTestCommands(root).length > 0,
|
|
170
|
+
lastRun: last ? { at: last.at, ok: last.ok, head: last.head } : null
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
function runAndRecordTests(root, opts = {}) {
|
|
174
|
+
const commands = opts.commands ?? readProfileTestCommands(root);
|
|
175
|
+
if (commands.length === 0) return { status: "no-commands" };
|
|
176
|
+
const spawn = opts.spawn ?? spawnSync;
|
|
177
|
+
let exitCode = 0;
|
|
178
|
+
for (const command of commands) {
|
|
179
|
+
if (typeof opts.onCommand === "function") opts.onCommand(command);
|
|
180
|
+
const res = spawn(command, { cwd: root, shell: true, stdio: opts.stdio ?? "inherit" });
|
|
181
|
+
exitCode = typeof res.status === "number" ? res.status : 1;
|
|
182
|
+
if (exitCode !== 0) break;
|
|
183
|
+
}
|
|
184
|
+
const headRes = spawn("git", ["rev-parse", "HEAD"], { cwd: root, encoding: "utf-8" });
|
|
185
|
+
const head = String(headRes?.stdout ?? "").trim();
|
|
186
|
+
const run = {
|
|
187
|
+
at: (opts.now ?? /* @__PURE__ */ new Date()).toISOString(),
|
|
188
|
+
ok: exitCode === 0,
|
|
189
|
+
exitCode,
|
|
190
|
+
head: SHA_RE.test(head) ? head : null,
|
|
191
|
+
commands
|
|
192
|
+
};
|
|
193
|
+
appendTestResult(root, run);
|
|
194
|
+
return { status: "recorded", run };
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// src/commands/outcome-ledger.ts
|
|
198
|
+
function renderOutcomeLedger(summary) {
|
|
199
|
+
const lines = [
|
|
200
|
+
`Outcome ledger (${OUTCOME_LEDGER_REL}): ${summary.entries} earned`,
|
|
201
|
+
` Logic ${summary.totals.logic} \xB7 Compute ${summary.totals.compute} \xB7 Rare ${summary.totals.rare}`
|
|
202
|
+
];
|
|
203
|
+
const kinds = Object.entries(summary.byKind).filter(([, n]) => n > 0).map(([kind, n]) => `${kind} ${n}`);
|
|
204
|
+
if (kinds.length > 0) lines.push(` ${kinds.join(" \xB7 ")}`);
|
|
205
|
+
if (!summary.tests.configured) {
|
|
206
|
+
lines.push(
|
|
207
|
+
" Tests: no stack.testCommands in .cursor/agent-kit.config.json (run `agent-kit doctor --refresh-profile` or set them)"
|
|
208
|
+
);
|
|
209
|
+
} else if (summary.tests.lastRun) {
|
|
210
|
+
const r = summary.tests.lastRun;
|
|
211
|
+
lines.push(` Tests: last run ${r.ok ? "passed" : "failed"} at ${r.at}`);
|
|
212
|
+
} else {
|
|
213
|
+
lines.push(" Tests: none recorded yet (`agent-kit outcome-ledger test`)");
|
|
214
|
+
}
|
|
215
|
+
if (summary.entries === 0) {
|
|
216
|
+
lines.push("Nothing earned yet. Mission Control folds the ledger on every refresh.");
|
|
217
|
+
}
|
|
218
|
+
return lines.join("\n");
|
|
219
|
+
}
|
|
220
|
+
var cwdArg = {
|
|
221
|
+
type: "string",
|
|
222
|
+
description: "Workspace folder (default: current directory)"
|
|
223
|
+
};
|
|
224
|
+
var outcomeLedgerCommand = defineCommand({
|
|
225
|
+
meta: {
|
|
226
|
+
name: "outcome-ledger",
|
|
227
|
+
description: "Show the verified-outcome ledger, or run the repo's test commands and record pass/fail (`test`)"
|
|
228
|
+
},
|
|
229
|
+
subCommands: {
|
|
230
|
+
show: defineCommand({
|
|
231
|
+
meta: { name: "show", description: "Print the persisted ledger totals (default)" },
|
|
232
|
+
args: {
|
|
233
|
+
json: { type: "boolean", description: "Print the summary as JSON", default: false },
|
|
234
|
+
cwd: cwdArg
|
|
235
|
+
},
|
|
236
|
+
run({ args }) {
|
|
237
|
+
const root = path.resolve(typeof args.cwd === "string" && args.cwd ? args.cwd : ".");
|
|
238
|
+
const summary = summarizeOutcomeLedger(readOutcomeLedger(root), {
|
|
239
|
+
tests: testCollectorStatus(root, readTestResults(root))
|
|
240
|
+
});
|
|
241
|
+
process.stdout.write(
|
|
242
|
+
args.json ? `${JSON.stringify(summary, null, 2)}
|
|
243
|
+
` : `${renderOutcomeLedger(summary)}
|
|
244
|
+
`
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
}),
|
|
248
|
+
test: defineCommand({
|
|
249
|
+
meta: {
|
|
250
|
+
name: "test",
|
|
251
|
+
description: `Run stack.testCommands from the repository profile and append the outcome to ${TEST_RESULTS_REL}`
|
|
252
|
+
},
|
|
253
|
+
args: { cwd: cwdArg },
|
|
254
|
+
run({ args }) {
|
|
255
|
+
const root = path.resolve(typeof args.cwd === "string" && args.cwd ? args.cwd : ".");
|
|
256
|
+
if (readProfileTestCommands(root).length === 0) {
|
|
257
|
+
process.stderr.write(
|
|
258
|
+
"No stack.testCommands in .cursor/agent-kit.config.json: nothing to run, nothing recorded. Run `agent-kit doctor --refresh-profile` or set them.\n"
|
|
259
|
+
);
|
|
260
|
+
process.exitCode = 2;
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
const result = runAndRecordTests(root, {
|
|
264
|
+
onCommand: (command) => process.stderr.write(`$ ${command}
|
|
265
|
+
`)
|
|
266
|
+
});
|
|
267
|
+
if (result.status !== "recorded") return;
|
|
268
|
+
const { run } = result;
|
|
269
|
+
process.stderr.write(
|
|
270
|
+
`Recorded: tests ${run.ok ? "passed" : `failed (exit ${run.exitCode})`}${run.head ? ` at ${run.head.slice(0, 8)}` : " (no git HEAD: earns nothing)"}
|
|
271
|
+
`
|
|
272
|
+
);
|
|
273
|
+
if (!run.ok) process.exitCode = run.exitCode ?? 1;
|
|
274
|
+
}
|
|
275
|
+
})
|
|
276
|
+
},
|
|
277
|
+
args: {
|
|
278
|
+
json: { type: "boolean", description: "Print the summary as JSON", default: false },
|
|
279
|
+
cwd: cwdArg
|
|
280
|
+
},
|
|
281
|
+
run({ rawArgs, args }) {
|
|
282
|
+
if (rawArgs.some((a) => a === "show" || a === "test")) return;
|
|
283
|
+
const root = path.resolve(typeof args.cwd === "string" && args.cwd ? args.cwd : ".");
|
|
284
|
+
const summary = summarizeOutcomeLedger(readOutcomeLedger(root), {
|
|
285
|
+
tests: testCollectorStatus(root, readTestResults(root))
|
|
286
|
+
});
|
|
287
|
+
process.stdout.write(
|
|
288
|
+
args.json ? `${JSON.stringify(summary, null, 2)}
|
|
289
|
+
` : `${renderOutcomeLedger(summary)}
|
|
290
|
+
`
|
|
291
|
+
);
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
export {
|
|
295
|
+
outcomeLedgerCommand,
|
|
296
|
+
renderOutcomeLedger
|
|
297
|
+
};
|