@dadado/agent-kit-cli 6.22.1 → 6.25.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/README.md +1 -0
- package/dashboard/dashboard-data.mjs +126 -5
- package/dashboard/dashboard.html +45 -4
- package/dashboard/lib/live-refresh.mjs +1 -0
- package/dist/{add-YVDIFP4N.js → add-OYLOMCM6.js} +14 -6
- package/dist/chunk-2F6NMQOA.js +519 -0
- package/dist/chunk-2QYWMSI5.js +193 -0
- package/dist/{chunk-B3VR5YBQ.js → chunk-2TW7ENWC.js} +12 -11
- package/dist/{chunk-GT5R7W66.js → chunk-2XLI7XEY.js} +1 -1
- package/dist/chunk-6M6UKECW.js +176 -0
- package/dist/{chunk-YRBRYTM5.js → chunk-7Y74KO7U.js} +45 -16
- package/dist/{chunk-DZCLMIAS.js → chunk-AQLBEEPD.js} +236 -2
- package/dist/{chunk-R4DUO5DA.js → chunk-AXQMVQ6O.js} +61 -237
- package/dist/{chunk-4SEQ76BQ.js → chunk-C7SV7UP5.js} +7 -4
- package/dist/{chunk-WS6OX2IG.js → chunk-CGXLR77R.js} +4 -0
- package/dist/{chunk-XZQM55BK.js → chunk-CIV42JGT.js} +7 -5
- package/dist/{chunk-CQHD6UKB.js → chunk-CXE6ASSX.js} +1 -0
- package/dist/{chunk-2FKAKFMH.js → chunk-EO5NGAYV.js} +1 -1
- package/dist/{chunk-GV4VKIPO.js → chunk-G5MQRP6M.js} +32 -14
- package/dist/chunk-GMG7ZH4E.js +357 -0
- package/dist/{chunk-5EBT3V7G.js → chunk-GQSSXDDK.js} +1 -1
- package/dist/{chunk-EYNSSL6B.js → chunk-H7RAFRRZ.js} +47 -251
- package/dist/{chunk-IESSMKOV.js → chunk-HSIHZWFF.js} +4 -4
- package/dist/{chunk-W3ZJVBNY.js → chunk-IFBIO7VT.js} +449 -418
- package/dist/{chunk-QWTBYXHN.js → chunk-JFS4GKP7.js} +1 -1
- package/dist/{chunk-LDZAK5DU.js → chunk-JG3CNGQM.js} +78 -170
- package/dist/{chunk-SDJIMC5S.js → chunk-JGG574RK.js} +3 -3
- package/dist/{chunk-SGTTC2JP.js → chunk-KWYF7QNH.js} +1 -1
- package/dist/{chunk-5HH3HSUR.js → chunk-M4UL422I.js} +80 -15
- package/dist/{chunk-DTSL2RH7.js → chunk-MFKHIWEL.js} +5 -3
- package/dist/{chunk-MGIPA6SD.js → chunk-NJ2SUSWX.js} +1 -1
- package/dist/{chunk-BCU54M2P.js → chunk-PIMGV3E5.js} +1 -1
- package/dist/{chunk-HJWSOZXS.js → chunk-QACMV46U.js} +10 -10
- package/dist/{chunk-WHBGJ7IJ.js → chunk-QLTGHJB3.js} +26 -7
- package/dist/{chunk-ZJDJCMQO.js → chunk-QX55T4UX.js} +23 -1
- package/dist/chunk-SAQ3EE5R.js +138 -0
- package/dist/{chunk-C4LCOOL4.js → chunk-TOSAAQ5A.js} +1 -1
- package/dist/chunk-WKFE3RUC.js +433 -0
- package/dist/{chunk-BGL5DRK2.js → chunk-XGZOU4DS.js} +1 -1
- package/dist/{commands-LEBG6DMD.js → commands-UW2C2ZN4.js} +5 -5
- package/dist/{conflicts-FJD3IVPQ.js → conflicts-RING6AHV.js} +22 -12
- package/dist/{contribute-XPAR2JER.js → contribute-LSY75JZH.js} +6 -5
- package/dist/{countdown-25E5C7AR.js → countdown-SZ2P4XHB.js} +267 -23
- package/dist/{diff-KFID4SX3.js → diff-NZVBVQSK.js} +14 -6
- package/dist/{doctor-J2GJFTSE.js → doctor-TJSXBVGV.js} +104 -18
- package/dist/{ground-control-IDCXN5FK.js → ground-control-ZJXPUIQN.js} +3 -3
- package/dist/{guard-RJZEEKSL.js → guard-ZO4Z3LLB.js} +47 -9
- package/dist/{handoff-5AGE2D3T.js → handoff-2OZSWGTE.js} +2 -0
- package/dist/{hook-HV6U3ANI.js → hook-3VPKNSOO.js} +14 -12
- package/dist/index.js +27 -26
- package/dist/{init-47WA2SCG.js → init-UW2BJBO2.js} +22 -16
- package/dist/install-RQSI4CHG.js +41 -0
- package/dist/installs-7TR4H4QH.js +222 -0
- package/dist/{mission-control-CRMCRZUU.js → mission-control-VSU6NT43.js} +1 -1
- package/dist/{queue-OJHKFKK3.js → queue-JHYILLMX.js} +10 -10
- package/dist/{run-Z2GHNVBO.js → run-CQF5RM5X.js} +29 -29
- package/dist/{run-plan-XA7MYOQ3.js → run-plan-BEOCOJCF.js} +13 -13
- package/dist/{scan-K3T5RQLC.js → scan-7D3RMO34.js} +2 -1
- package/dist/{session-start-PEVTDMOZ.js → session-start-QV7CEFRX.js} +18 -12
- package/dist/{sessions-6IGVH467.js → sessions-AWAAO3DU.js} +3 -3
- package/dist/{setup-global-KBJL7QRD.js → setup-global-ST4TT427.js} +9 -8
- package/dist/{status-3UGVDIO6.js → status-HUBPBGUU.js} +14 -11
- package/dist/update-DD5UZPGG.js +31 -0
- package/dist/update-all-YYUTXHGR.js +695 -0
- package/package.json +1 -1
- package/dist/chunk-HAFRAXGV.js +0 -17
- package/dist/chunk-ZNY32NK2.js +0 -52
- package/dist/install-Y63HEM4G.js +0 -38
- package/dist/update-4UQHGENC.js +0 -283
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import {
|
|
2
2
|
RUN_CATALOG,
|
|
3
3
|
RUN_PROMOTE_BLOCKED
|
|
4
|
-
} from "./chunk-
|
|
5
|
-
import "./chunk-
|
|
4
|
+
} from "./chunk-KWYF7QNH.js";
|
|
5
|
+
import "./chunk-IFBIO7VT.js";
|
|
6
6
|
import "./chunk-P7732A25.js";
|
|
7
7
|
import {
|
|
8
8
|
CURSOR_COMMANDS_DIR_REL,
|
|
9
9
|
discoverInstalledCommands
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-EO5NGAYV.js";
|
|
11
11
|
import "./chunk-WGLPZXNU.js";
|
|
12
12
|
import "./chunk-Q35TWISF.js";
|
|
13
13
|
import "./chunk-QTON2GQX.js";
|
|
14
14
|
import {
|
|
15
15
|
L0_ARTIFACTS
|
|
16
|
-
} from "./chunk-
|
|
17
|
-
import "./chunk-
|
|
16
|
+
} from "./chunk-CGXLR77R.js";
|
|
17
|
+
import "./chunk-QX55T4UX.js";
|
|
18
18
|
import {
|
|
19
19
|
KIT_VERSION
|
|
20
20
|
} from "./chunk-7HDQEK6T.js";
|
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
import {
|
|
2
2
|
REVIEW_PACK_DEFAULT_MAX_BYTES
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-HSIHZWFF.js";
|
|
4
|
+
import "./chunk-GQSSXDDK.js";
|
|
4
5
|
import {
|
|
5
6
|
detectAgentBackend
|
|
6
|
-
} from "./chunk-
|
|
7
|
-
import "./chunk-5EBT3V7G.js";
|
|
7
|
+
} from "./chunk-TOSAAQ5A.js";
|
|
8
8
|
import {
|
|
9
9
|
defaultExec,
|
|
10
10
|
gateExitRedactions,
|
|
11
11
|
isOutside
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-XGZOU4DS.js";
|
|
13
13
|
import "./chunk-MUTTNRX4.js";
|
|
14
14
|
import {
|
|
15
15
|
ensureDispatchLogPath,
|
|
16
16
|
readCommandFile,
|
|
17
17
|
runHeadlessDispatch
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-KWYF7QNH.js";
|
|
19
19
|
import {
|
|
20
20
|
createStreamRenderer,
|
|
21
21
|
redactSecrets
|
|
22
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-IFBIO7VT.js";
|
|
23
23
|
import "./chunk-P7732A25.js";
|
|
24
24
|
import "./chunk-WGLPZXNU.js";
|
|
25
25
|
import "./chunk-Q35TWISF.js";
|
|
@@ -970,7 +970,12 @@ async function runConflictsPropose(input) {
|
|
|
970
970
|
}
|
|
971
971
|
resolvedText = spliced;
|
|
972
972
|
if (input.noVerify) {
|
|
973
|
-
verification = {
|
|
973
|
+
verification = {
|
|
974
|
+
status: "skipped",
|
|
975
|
+
reason: "not requested (pass --verify to run it)",
|
|
976
|
+
commands: [],
|
|
977
|
+
notes: []
|
|
978
|
+
};
|
|
974
979
|
} else {
|
|
975
980
|
const commands = input.verifyCommands?.length ? input.verifyCommands : await readVerifyCommands(git);
|
|
976
981
|
say(`verifying in a temporary worktree: ${commands.join(" ; ") || "(no command)"}`);
|
|
@@ -1036,12 +1041,12 @@ var proposeCommand = defineCommand({
|
|
|
1036
1041
|
json: { type: "boolean", description: "Print the full result as JSON", default: false },
|
|
1037
1042
|
verify: {
|
|
1038
1043
|
type: "boolean",
|
|
1039
|
-
description: "Verify the resolved file in a temporary worktree: runs stack.validationCommands and stack.testCommands from HEAD's .cursor/agent-kit.config.json (or --verify-cmd) on the model's text and the files the merge brought in, before anyone has reviewed them, unsandboxed, as you, with your environment and network
|
|
1040
|
-
default:
|
|
1044
|
+
description: "Off by default. Verify the resolved file in a temporary worktree: runs stack.validationCommands and stack.testCommands from HEAD's .cursor/agent-kit.config.json (or --verify-cmd) on the model's text and the files the merge brought in, before anyone has reviewed them, unsandboxed, as you, with your environment and network. Pass it only for a branch whose code you trust",
|
|
1045
|
+
default: false
|
|
1041
1046
|
},
|
|
1042
1047
|
"verify-cmd": {
|
|
1043
1048
|
type: "string",
|
|
1044
|
-
description: "
|
|
1049
|
+
description: "With --verify: a shell command to verify with instead of the configured ones. The temporary worktree has no dependencies installed: on a Node repository put the install first, e.g. --verify --verify-cmd 'pnpm install --frozen-lockfile --prefer-offline && pnpm test' (npm: 'npm ci --prefer-offline && npm test'); a failed verification without node_modules prints the one for your lockfile and commands"
|
|
1045
1050
|
},
|
|
1046
1051
|
"verify-timeout": {
|
|
1047
1052
|
type: "string",
|
|
@@ -1055,6 +1060,12 @@ var proposeCommand = defineCommand({
|
|
|
1055
1060
|
},
|
|
1056
1061
|
async run({ args }) {
|
|
1057
1062
|
const cwd = path3.resolve(String(args.cwd));
|
|
1063
|
+
const verifyCmd = args["verify-cmd"] ? String(args["verify-cmd"]).trim() : "";
|
|
1064
|
+
if (verifyCmd && args.verify !== true) {
|
|
1065
|
+
logger.error("--verify-cmd only applies with --verify (verification is off by default)");
|
|
1066
|
+
process.exitCode = 1;
|
|
1067
|
+
return;
|
|
1068
|
+
}
|
|
1058
1069
|
const requested = String(args.backend ?? "auto");
|
|
1059
1070
|
let backendId;
|
|
1060
1071
|
let bin;
|
|
@@ -1092,14 +1103,13 @@ var proposeCommand = defineCommand({
|
|
|
1092
1103
|
}
|
|
1093
1104
|
verifyTimeoutMs = s * 1e3;
|
|
1094
1105
|
}
|
|
1095
|
-
const verifyCmd = args["verify-cmd"] ? String(args["verify-cmd"]).trim() : "";
|
|
1096
1106
|
const out = await runConflictsPropose({
|
|
1097
1107
|
root: cwd,
|
|
1098
1108
|
path: String(args.path),
|
|
1099
1109
|
backendId,
|
|
1100
1110
|
bin,
|
|
1101
1111
|
model: args.model ? String(args.model) : void 0,
|
|
1102
|
-
noVerify: args.verify
|
|
1112
|
+
noVerify: args.verify !== true,
|
|
1103
1113
|
verifyCommands: verifyCmd ? [verifyCmd] : void 0,
|
|
1104
1114
|
verifyTimeoutMs,
|
|
1105
1115
|
dryRun: args["dry-run"] === true
|
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
import {
|
|
2
2
|
REGISTRY_CLI_ARGS,
|
|
3
3
|
resolveRegistryFromCli
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-PIMGV3E5.js";
|
|
5
5
|
import {
|
|
6
6
|
logger
|
|
7
7
|
} from "./chunk-ZB43YMHW.js";
|
|
8
8
|
import {
|
|
9
9
|
managedPairs
|
|
10
|
-
} from "./chunk-
|
|
11
|
-
import "./chunk-
|
|
10
|
+
} from "./chunk-SAQ3EE5R.js";
|
|
11
|
+
import "./chunk-CGXLR77R.js";
|
|
12
12
|
import {
|
|
13
13
|
loadAgentKitManifest,
|
|
14
14
|
normalizeRelPath
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-JG3CNGQM.js";
|
|
16
16
|
import {
|
|
17
17
|
resolveContained
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-QX55T4UX.js";
|
|
19
|
+
import "./chunk-6M6UKECW.js";
|
|
19
20
|
import "./chunk-C4Q77GGJ.js";
|
|
20
21
|
import "./chunk-5B4DVO6C.js";
|
|
21
22
|
|
|
@@ -1,21 +1,27 @@
|
|
|
1
1
|
import {
|
|
2
|
+
isPlanExhaustedReason,
|
|
2
3
|
loadRolesContext,
|
|
4
|
+
parseAgentStopLine,
|
|
3
5
|
resolveReviewJobRole,
|
|
4
6
|
resolveWorkerRole
|
|
5
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-AQLBEEPD.js";
|
|
6
8
|
import {
|
|
7
9
|
REVIEW_BACKENDS,
|
|
8
10
|
REVIEW_PACK_DEFAULT_MAX_BYTES,
|
|
9
11
|
REVIEW_PACK_SLASH,
|
|
10
12
|
parseReviewPackMaxBytes,
|
|
11
13
|
reviewBackendMessage
|
|
12
|
-
} from "./chunk-
|
|
13
|
-
import "./chunk-
|
|
14
|
+
} from "./chunk-HSIHZWFF.js";
|
|
15
|
+
import "./chunk-GQSSXDDK.js";
|
|
16
|
+
import {
|
|
17
|
+
countPendingTodos,
|
|
18
|
+
readPlan,
|
|
19
|
+
resolveActivePlanPath
|
|
20
|
+
} from "./chunk-7ABY6DYH.js";
|
|
14
21
|
import {
|
|
15
22
|
detectAgentBackend,
|
|
16
23
|
listDetectBackendIds
|
|
17
|
-
} from "./chunk-
|
|
18
|
-
import "./chunk-5EBT3V7G.js";
|
|
24
|
+
} from "./chunk-TOSAAQ5A.js";
|
|
19
25
|
import {
|
|
20
26
|
GATE_EXIT_MARKER_RELPATH,
|
|
21
27
|
defaultExec,
|
|
@@ -26,21 +32,27 @@ import {
|
|
|
26
32
|
readGateExitMarker,
|
|
27
33
|
resolveGateExitRefs,
|
|
28
34
|
writeGateExitMarker
|
|
29
|
-
} from "./chunk-
|
|
30
|
-
import
|
|
31
|
-
|
|
35
|
+
} from "./chunk-XGZOU4DS.js";
|
|
36
|
+
import {
|
|
37
|
+
parsePlanFrontmatter
|
|
38
|
+
} from "./chunk-L5V3W3DY.js";
|
|
39
|
+
import {
|
|
40
|
+
ensurePathIgnored
|
|
41
|
+
} from "./chunk-MUTTNRX4.js";
|
|
32
42
|
import {
|
|
33
43
|
classifySlash,
|
|
34
44
|
normalizeSlashName,
|
|
35
45
|
promoteBlockedMessage,
|
|
36
46
|
unknownSlashMessage
|
|
37
|
-
} from "./chunk-
|
|
47
|
+
} from "./chunk-KWYF7QNH.js";
|
|
38
48
|
import {
|
|
39
49
|
CLAUDE_MAX_BUDGET_USD_ENV,
|
|
40
50
|
CLAUDE_MAX_TURNS_ENV,
|
|
41
51
|
RedactingStreamBuffer,
|
|
52
|
+
claudeRunCaps,
|
|
53
|
+
parseResultLine,
|
|
42
54
|
redactSecrets
|
|
43
|
-
} from "./chunk-
|
|
55
|
+
} from "./chunk-IFBIO7VT.js";
|
|
44
56
|
import {
|
|
45
57
|
HITL_UNANSWERED_EXIT_CODE
|
|
46
58
|
} from "./chunk-P7732A25.js";
|
|
@@ -59,17 +71,120 @@ import "./chunk-5B4DVO6C.js";
|
|
|
59
71
|
|
|
60
72
|
// src/commands/countdown.ts
|
|
61
73
|
import { spawn } from "child_process";
|
|
62
|
-
import { appendFile } from "fs/promises";
|
|
74
|
+
import { appendFile, mkdir } from "fs/promises";
|
|
63
75
|
import path from "path";
|
|
64
76
|
import { defineCommand } from "citty";
|
|
65
77
|
var COUNTDOWN_EXIT = {
|
|
66
78
|
completed: 0,
|
|
67
79
|
usage: 1,
|
|
68
|
-
/**
|
|
80
|
+
/**
|
|
81
|
+
* A gate exit is pending, the run reached a gate, or `--budget-remaining`
|
|
82
|
+
* does not cover the job: waits for the operator.
|
|
83
|
+
*/
|
|
69
84
|
pending: 2,
|
|
70
85
|
/** Circuit's Dead: failed, stalled, over the window, dirty tree, fetch failed. */
|
|
71
|
-
circuitsDead: 3
|
|
86
|
+
circuitsDead: 3,
|
|
87
|
+
/**
|
|
88
|
+
* Needs operator: the tick ended because the agent requested a stop (a
|
|
89
|
+
* question, nothing implementable) while to-dos remain. A stop on an
|
|
90
|
+
* exhausted plan stays 0.
|
|
91
|
+
*/
|
|
92
|
+
needsOperator: 5
|
|
72
93
|
};
|
|
94
|
+
var COUNTDOWN_RESULT_PREFIX = "AGENT_KIT_RESULT";
|
|
95
|
+
function countdownOutcome(exitCode) {
|
|
96
|
+
if (exitCode === COUNTDOWN_EXIT.completed) return "ok";
|
|
97
|
+
if (exitCode === COUNTDOWN_EXIT.pending || exitCode === COUNTDOWN_EXIT.needsOperator) {
|
|
98
|
+
return "needs-operator";
|
|
99
|
+
}
|
|
100
|
+
return "broken";
|
|
101
|
+
}
|
|
102
|
+
function formatCountdownResultLine(record) {
|
|
103
|
+
return `${COUNTDOWN_RESULT_PREFIX} ${JSON.stringify(record)}`;
|
|
104
|
+
}
|
|
105
|
+
function createAgentStopWatcher() {
|
|
106
|
+
let last = null;
|
|
107
|
+
let partial = "";
|
|
108
|
+
return {
|
|
109
|
+
push(text) {
|
|
110
|
+
const lines = (partial + text).split("\n");
|
|
111
|
+
partial = lines.pop() ?? "";
|
|
112
|
+
for (const line of lines) {
|
|
113
|
+
const hit = parseAgentStopLine(line);
|
|
114
|
+
if (hit !== null) last = hit;
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
reason() {
|
|
118
|
+
const hit = partial ? parseAgentStopLine(partial) : null;
|
|
119
|
+
return hit ?? last;
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
function createCostWatcher() {
|
|
124
|
+
let total = 0;
|
|
125
|
+
let seen = false;
|
|
126
|
+
let last = null;
|
|
127
|
+
let partial = "";
|
|
128
|
+
const take = (line) => {
|
|
129
|
+
const hit = parseResultLine(line);
|
|
130
|
+
if (hit === null || hit.costUsd === null) return;
|
|
131
|
+
const replaces = hit.sessionTotal && last !== null && hit.costUsd >= last;
|
|
132
|
+
total += replaces && last !== null ? hit.costUsd - last : hit.costUsd;
|
|
133
|
+
last = hit.costUsd;
|
|
134
|
+
seen = true;
|
|
135
|
+
};
|
|
136
|
+
return {
|
|
137
|
+
push(text) {
|
|
138
|
+
const lines = (partial + text).split("\n");
|
|
139
|
+
partial = lines.pop() ?? "";
|
|
140
|
+
for (const line of lines) take(line);
|
|
141
|
+
},
|
|
142
|
+
costUsd() {
|
|
143
|
+
if (partial) {
|
|
144
|
+
take(partial);
|
|
145
|
+
partial = "";
|
|
146
|
+
}
|
|
147
|
+
return seen ? Math.round(total * 1e6) / 1e6 : null;
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
var COST_LEDGER_RELPATH = ".cursor/context/cost-ledger.ndjson";
|
|
152
|
+
function formatCostLedgerLine(entry) {
|
|
153
|
+
return `${JSON.stringify(entry)}
|
|
154
|
+
`;
|
|
155
|
+
}
|
|
156
|
+
async function appendCostLedger(opts) {
|
|
157
|
+
try {
|
|
158
|
+
const git = (args) => opts.exec("git", args, { cwd: opts.root, env: opts.env });
|
|
159
|
+
if (!await ensurePathIgnored(git, opts.root, COST_LEDGER_RELPATH)) {
|
|
160
|
+
return `${COST_LEDGER_RELPATH} is not ignored by git and could not be added to .git/info/exclude`;
|
|
161
|
+
}
|
|
162
|
+
const file = path.join(opts.root, COST_LEDGER_RELPATH);
|
|
163
|
+
await mkdir(path.dirname(file), { recursive: true });
|
|
164
|
+
await appendFile(file, formatCostLedgerLine(opts.entry), "utf8");
|
|
165
|
+
return null;
|
|
166
|
+
} catch (err) {
|
|
167
|
+
return String(err instanceof Error ? err.message : err);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
function parseBudgetRemaining(raw) {
|
|
171
|
+
if (raw === void 0) return null;
|
|
172
|
+
const text = String(raw).trim();
|
|
173
|
+
const value = Number(text);
|
|
174
|
+
if (!text || !Number.isFinite(value)) return "--budget-remaining must be a number (USD)";
|
|
175
|
+
return value;
|
|
176
|
+
}
|
|
177
|
+
function usd(value) {
|
|
178
|
+
return `${value < 0 ? "-" : ""}$${Math.abs(value).toFixed(2)}`;
|
|
179
|
+
}
|
|
180
|
+
function budgetRefusal(input) {
|
|
181
|
+
if (input.remaining <= 0) return `budget: ${usd(input.remaining)} remaining; nothing left`;
|
|
182
|
+
if (input.capUsd === void 0) return null;
|
|
183
|
+
const need = input.capUsd * input.ticks;
|
|
184
|
+
if (input.remaining >= need) return null;
|
|
185
|
+
const per = input.ticks === 1 ? `${CLAUDE_MAX_BUDGET_USD_ENV}=${input.capUsd}` : `${CLAUDE_MAX_BUDGET_USD_ENV}=${input.capUsd} x ${input.ticks} ticks`;
|
|
186
|
+
return `budget: ${usd(input.remaining)} remaining is below the cap of this fire (${usd(need)}, ${per})`;
|
|
187
|
+
}
|
|
73
188
|
var COUNTDOWN_JOBS = ["tick", "dispatch", "review"];
|
|
74
189
|
var COUNTDOWN_DEFAULT_MAX_TICKS = 1;
|
|
75
190
|
var COUNTDOWN_DEFAULT_WINDOW_MIN = 120;
|
|
@@ -142,7 +257,10 @@ async function superviseJob(handle, opts) {
|
|
|
142
257
|
}
|
|
143
258
|
function countdownExitCode(input) {
|
|
144
259
|
if (input.circuitsDead) return COUNTDOWN_EXIT.circuitsDead;
|
|
145
|
-
if (input.code === 0)
|
|
260
|
+
if (input.code === 0) {
|
|
261
|
+
if (input.pendingGrew) return COUNTDOWN_EXIT.pending;
|
|
262
|
+
return input.needsOperator ? COUNTDOWN_EXIT.needsOperator : COUNTDOWN_EXIT.completed;
|
|
263
|
+
}
|
|
146
264
|
if (input.code === HITL_UNANSWERED_EXIT_CODE) return COUNTDOWN_EXIT.pending;
|
|
147
265
|
return COUNTDOWN_EXIT.circuitsDead;
|
|
148
266
|
}
|
|
@@ -240,14 +358,73 @@ function positive(raw, flag, integer) {
|
|
|
240
358
|
return value;
|
|
241
359
|
}
|
|
242
360
|
async function executeCountdown(input) {
|
|
361
|
+
const write = input.write ?? ((text) => process.stdout.write(text));
|
|
362
|
+
const root = path.resolve(input.cwd);
|
|
363
|
+
const env = input.env ?? process.env;
|
|
364
|
+
const now = input.now ?? /* @__PURE__ */ new Date();
|
|
365
|
+
const end = await runCountdown({ ...input, write, now });
|
|
366
|
+
const red = (text) => redactSecrets(text, gateExitRedactions(env));
|
|
367
|
+
const result = {
|
|
368
|
+
outcome: countdownOutcome(end.exitCode),
|
|
369
|
+
reason: red(end.reason).replace(/\s+/g, " ").trim(),
|
|
370
|
+
repo: path.basename(root),
|
|
371
|
+
plan: end.plan ?? null,
|
|
372
|
+
todo: end.todo ?? null,
|
|
373
|
+
exit: end.exitCode,
|
|
374
|
+
cost_usd: end.costUsd ?? null
|
|
375
|
+
};
|
|
376
|
+
if (end.exitCode !== COUNTDOWN_EXIT.usage && end.job) {
|
|
377
|
+
const failed = await appendCostLedger({
|
|
378
|
+
root,
|
|
379
|
+
env,
|
|
380
|
+
exec: input.exec ?? defaultExec,
|
|
381
|
+
entry: {
|
|
382
|
+
at: now.toISOString(),
|
|
383
|
+
repo: result.repo,
|
|
384
|
+
plan: result.plan,
|
|
385
|
+
todo: result.todo,
|
|
386
|
+
job: end.job,
|
|
387
|
+
backend: end.backend ?? null,
|
|
388
|
+
model: end.model ?? null,
|
|
389
|
+
cost_usd: result.cost_usd,
|
|
390
|
+
input_tokens: null,
|
|
391
|
+
output_tokens: null,
|
|
392
|
+
exit: result.exit,
|
|
393
|
+
outcome: result.outcome
|
|
394
|
+
}
|
|
395
|
+
});
|
|
396
|
+
if (failed !== null) {
|
|
397
|
+
const warning = `${red(`countdown: warning: cost ledger not written: ${failed}`).replace(/\s+/g, " ").trim()}
|
|
398
|
+
`;
|
|
399
|
+
write(warning);
|
|
400
|
+
if (end.logPath) await appendFile(end.logPath, warning, "utf8").catch(() => void 0);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
const line = `${formatCountdownResultLine(result)}
|
|
404
|
+
`;
|
|
405
|
+
write(line);
|
|
406
|
+
if (end.logPath) await appendFile(end.logPath, line, "utf8").catch(() => void 0);
|
|
407
|
+
return {
|
|
408
|
+
exitCode: end.exitCode,
|
|
409
|
+
...end.error ? { error: end.error } : {},
|
|
410
|
+
...end.logPath ? { logPath: end.logPath } : {},
|
|
411
|
+
result
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
function inProgressTodo(raw) {
|
|
415
|
+
const active = parsePlanFrontmatter(raw).todos.filter((t) => t.status === "in_progress");
|
|
416
|
+
return active.length === 1 ? active[0]?.id ?? null : null;
|
|
417
|
+
}
|
|
418
|
+
async function runCountdown(input) {
|
|
243
419
|
const root = path.resolve(input.cwd);
|
|
244
420
|
const env = input.env ?? process.env;
|
|
245
421
|
const exec = input.exec ?? defaultExec;
|
|
246
422
|
const now = input.now ?? /* @__PURE__ */ new Date();
|
|
247
|
-
const write = input.write
|
|
423
|
+
const write = input.write;
|
|
248
424
|
const usage = (error) => ({
|
|
249
425
|
exitCode: COUNTDOWN_EXIT.usage,
|
|
250
|
-
error
|
|
426
|
+
error,
|
|
427
|
+
reason: `usage: ${error}`
|
|
251
428
|
});
|
|
252
429
|
const slash = normalizeSlashName(input.slash ?? "");
|
|
253
430
|
const job = String(input.job).trim();
|
|
@@ -268,6 +445,8 @@ async function executeCountdown(input) {
|
|
|
268
445
|
const windowMin = positive(input.windowMin, "--window-min", false);
|
|
269
446
|
const stallMin = positive(input.stallMin, "--stall-min", false);
|
|
270
447
|
for (const v of [maxTicks, windowMin, stallMin]) if (typeof v === "string") return usage(v);
|
|
448
|
+
const budget = parseBudgetRemaining(input.budgetRemaining);
|
|
449
|
+
if (typeof budget === "string") return usage(budget);
|
|
271
450
|
const packRaw = input.maxPackBytes === void 0 ? "" : String(input.maxPackBytes).trim();
|
|
272
451
|
if (job !== "review" && packRaw) return usage("--max-pack-bytes only applies to --job review");
|
|
273
452
|
if (job !== "review" && input.includeReviewed) {
|
|
@@ -352,11 +531,41 @@ async function executeCountdown(input) {
|
|
|
352
531
|
const jobLabel = job === "tick" ? "run-plan" : job === "review" ? `run ${REVIEW_PACK_SLASH}` : `run ${slash}`;
|
|
353
532
|
say(`fire ${gateExitStamp(now)}: job ${job} (${jobLabel}) on ${detected.id}`);
|
|
354
533
|
for (const note of rolesNotes) say(note);
|
|
534
|
+
const runsTick = job === "tick" || job === "dispatch" && classifySlash(slash) === "run-plan";
|
|
535
|
+
const planPath = runsTick ? await resolveActivePlanPath(root).catch(() => null) : null;
|
|
536
|
+
const plan = planPath ? path.basename(planPath) : null;
|
|
537
|
+
const ledger = { job, backend: detected.id, model: model ?? null };
|
|
538
|
+
if (budget !== null) {
|
|
539
|
+
const refusal = budgetRefusal({
|
|
540
|
+
remaining: budget,
|
|
541
|
+
capUsd: claudeRunCaps(env).caps.maxBudgetUsd,
|
|
542
|
+
ticks: job === "review" ? 1 : maxTicks
|
|
543
|
+
});
|
|
544
|
+
if (refusal !== null) {
|
|
545
|
+
say(`refused: ${refusal} (exit ${COUNTDOWN_EXIT.pending})`);
|
|
546
|
+
await openLog().catch(() => void 0);
|
|
547
|
+
return {
|
|
548
|
+
exitCode: COUNTDOWN_EXIT.pending,
|
|
549
|
+
reason: refusal,
|
|
550
|
+
plan,
|
|
551
|
+
...ledger,
|
|
552
|
+
costUsd: null,
|
|
553
|
+
...logPath ? { logPath } : {}
|
|
554
|
+
};
|
|
555
|
+
}
|
|
556
|
+
say(`budget: ${usd(budget)} remaining`);
|
|
557
|
+
}
|
|
355
558
|
const preflight = await countdownPreflight({ root, env, exec, now, log: say });
|
|
356
559
|
if (!preflight.ok) {
|
|
357
560
|
say(`refused: ${preflight.reason} (exit ${preflight.exitCode})`);
|
|
358
561
|
await openLog().catch(() => void 0);
|
|
359
|
-
return {
|
|
562
|
+
return {
|
|
563
|
+
exitCode: preflight.exitCode,
|
|
564
|
+
reason: `refused: ${preflight.reason}`,
|
|
565
|
+
plan,
|
|
566
|
+
...ledger,
|
|
567
|
+
...logPath ? { logPath } : {}
|
|
568
|
+
};
|
|
360
569
|
}
|
|
361
570
|
await openLog();
|
|
362
571
|
const capLines = [CLAUDE_MAX_TURNS_ENV, CLAUDE_MAX_BUDGET_USD_ENV].filter((k) => env[k]).map((k) => `${k}=${env[k]}`);
|
|
@@ -383,8 +592,12 @@ async function executeCountdown(input) {
|
|
|
383
592
|
process.on("SIGTERM", onSigterm);
|
|
384
593
|
}
|
|
385
594
|
const jobOut = new RedactingStreamBuffer(redactions);
|
|
595
|
+
const stopWatch = runsTick ? createAgentStopWatcher() : null;
|
|
596
|
+
const costWatch = createCostWatcher();
|
|
386
597
|
const emitJob = (out) => {
|
|
387
598
|
if (!out) return;
|
|
599
|
+
stopWatch?.push(out);
|
|
600
|
+
costWatch.push(out);
|
|
388
601
|
write(out);
|
|
389
602
|
toLog(out);
|
|
390
603
|
};
|
|
@@ -409,17 +622,24 @@ async function executeCountdown(input) {
|
|
|
409
622
|
const after = await readGateExitMarker(root);
|
|
410
623
|
const pendingAfter = after.kind === "ok" ? after.marker.pending.length : preflight.pendingBefore;
|
|
411
624
|
const pendingGrew = pendingAfter > preflight.pendingBefore;
|
|
625
|
+
const stopReason = stopWatch?.reason() ?? null;
|
|
626
|
+
const planRaw = planPath ? await readPlan(planPath).catch(() => null) : null;
|
|
627
|
+
const todosLeft = planRaw === null ? null : countPendingTodos(planRaw);
|
|
628
|
+
const todo = planRaw === null ? null : inProgressTodo(planRaw);
|
|
629
|
+
const planExhausted = stopReason !== null && (todosLeft === null ? isPlanExhaustedReason(stopReason) : todosLeft === 0);
|
|
412
630
|
const exitCode = countdownExitCode({
|
|
413
631
|
code: end.code,
|
|
414
632
|
circuitsDead: end.circuitsDead,
|
|
415
|
-
pendingGrew
|
|
633
|
+
pendingGrew,
|
|
634
|
+
needsOperator: stopReason !== null && !planExhausted
|
|
416
635
|
});
|
|
636
|
+
const deadReason = end.circuitsDead ? `Circuit's Dead: ${end.circuitsDead === "window" ? `window of ${windowMin} min exceeded` : `no stream event for ${stallMin} min`}` : `Circuit's Dead: job exited with ${end.code === null ? `signal ${end.signal ?? "unknown"}` : `code ${end.code}`}`;
|
|
417
637
|
if (exitCode === COUNTDOWN_EXIT.circuitsDead && !pendingGrew) {
|
|
418
|
-
const
|
|
638
|
+
const reason2 = deadReason;
|
|
419
639
|
const outcome = {
|
|
420
640
|
trigger: "failure",
|
|
421
641
|
exitCode,
|
|
422
|
-
reason,
|
|
642
|
+
reason: reason2,
|
|
423
643
|
command: `countdown --job ${job}${job === "dispatch" ? ` --slash ${slash}` : ""}`,
|
|
424
644
|
backend: detected.id,
|
|
425
645
|
...logPath ? { logPath } : {}
|
|
@@ -430,15 +650,24 @@ async function executeCountdown(input) {
|
|
|
430
650
|
say(`gate-exit: landing failed: ${String(err)}`);
|
|
431
651
|
}
|
|
432
652
|
}
|
|
433
|
-
const meaning = exitCode === 0 ? "completed" : exitCode === COUNTDOWN_EXIT.pending ? job === "review" && end.code === 0 ? "review findings landed; gate exit pending" : "gate reached; gate exit pending" : "Circuit's Dead";
|
|
653
|
+
const meaning = exitCode === 0 ? stopReason !== null ? "completed; plan exhausted" : "completed" : exitCode === COUNTDOWN_EXIT.pending ? job === "review" && end.code === 0 ? "review findings landed; gate exit pending" : "gate reached; gate exit pending" : exitCode === COUNTDOWN_EXIT.needsOperator ? "needs operator; the agent requested a stop" : "Circuit's Dead";
|
|
434
654
|
say(`exit ${exitCode} (${meaning})`);
|
|
435
655
|
await logChain;
|
|
436
|
-
|
|
656
|
+
const reason = exitCode === COUNTDOWN_EXIT.needsOperator ? `agent requested stop: ${stopReason ?? ""}` : exitCode === COUNTDOWN_EXIT.circuitsDead ? deadReason : exitCode === 0 && stopReason !== null ? `plan exhausted: ${stopReason}` : meaning;
|
|
657
|
+
return {
|
|
658
|
+
exitCode,
|
|
659
|
+
reason,
|
|
660
|
+
plan,
|
|
661
|
+
todo,
|
|
662
|
+
...ledger,
|
|
663
|
+
costUsd: costWatch.costUsd(),
|
|
664
|
+
...logPath ? { logPath } : {}
|
|
665
|
+
};
|
|
437
666
|
}
|
|
438
667
|
var countdownCommand = defineCommand({
|
|
439
668
|
meta: {
|
|
440
669
|
name: "countdown",
|
|
441
|
-
description: "Countdown: one-shot launcher for a cron/systemd timer. Runs one headless job (tick, dispatch or review) with --no-hitl --land-on-gate; refused while a gate exit is pending. Exit 0 done, 2 gate or
|
|
670
|
+
description: "Countdown: one-shot launcher for a cron/systemd timer. Runs one headless job (tick, dispatch or review) with --no-hitl --land-on-gate; refused while a gate exit is pending or when --budget-remaining does not cover it. Exit 0 done, 2 gate, findings or budget pending, 3 Circuit's Dead, 5 the agent requested a stop (needs operator). Each fire appends one line to .cursor/context/cost-ledger.ndjson; the last stdout line is AGENT_KIT_RESULT {json}. Never git-prod."
|
|
442
671
|
},
|
|
443
672
|
args: {
|
|
444
673
|
cwd: {
|
|
@@ -490,6 +719,10 @@ var countdownCommand = defineCommand({
|
|
|
490
719
|
type: "string",
|
|
491
720
|
description: `Minutes with no stream event before the job is stopped as Circuit's Dead (default: ${COUNTDOWN_DEFAULT_STALL_MIN})`,
|
|
492
721
|
default: String(COUNTDOWN_DEFAULT_STALL_MIN)
|
|
722
|
+
},
|
|
723
|
+
"budget-remaining": {
|
|
724
|
+
type: "string",
|
|
725
|
+
description: `USD left in your budget (for example computed from .cursor/context/cost-ledger.ndjson). Refuses the fire with exit 2 when it is <= 0, or below ${CLAUDE_MAX_BUDGET_USD_ENV} times the ticks of this fire when that env is set; not a number (or empty) is a usage error`
|
|
493
726
|
}
|
|
494
727
|
},
|
|
495
728
|
async run({ args }) {
|
|
@@ -504,6 +737,7 @@ var countdownCommand = defineCommand({
|
|
|
504
737
|
...args["include-reviewed"] ? { includeReviewed: true } : {},
|
|
505
738
|
windowMin: String(args["window-min"]),
|
|
506
739
|
stallMin: String(args["stall-min"]),
|
|
740
|
+
...args["budget-remaining"] !== void 0 ? { budgetRemaining: String(args["budget-remaining"]) } : {},
|
|
507
741
|
forwardSignals: true
|
|
508
742
|
});
|
|
509
743
|
if (result.error) logger.error(result.error);
|
|
@@ -511,17 +745,27 @@ var countdownCommand = defineCommand({
|
|
|
511
745
|
}
|
|
512
746
|
});
|
|
513
747
|
export {
|
|
748
|
+
COST_LEDGER_RELPATH,
|
|
514
749
|
COUNTDOWN_DEFAULT_MAX_TICKS,
|
|
515
750
|
COUNTDOWN_DEFAULT_STALL_MIN,
|
|
516
751
|
COUNTDOWN_DEFAULT_WINDOW_MIN,
|
|
517
752
|
COUNTDOWN_EXIT,
|
|
518
753
|
COUNTDOWN_JOBS,
|
|
519
754
|
COUNTDOWN_KILL_GRACE_MS,
|
|
755
|
+
COUNTDOWN_RESULT_PREFIX,
|
|
756
|
+
appendCostLedger,
|
|
757
|
+
budgetRefusal,
|
|
520
758
|
countdownChildArgs,
|
|
521
759
|
countdownCommand,
|
|
522
760
|
countdownExitCode,
|
|
761
|
+
countdownOutcome,
|
|
523
762
|
countdownPreflight,
|
|
763
|
+
createAgentStopWatcher,
|
|
764
|
+
createCostWatcher,
|
|
524
765
|
defaultSpawnJob,
|
|
525
766
|
executeCountdown,
|
|
767
|
+
formatCostLedgerLine,
|
|
768
|
+
formatCountdownResultLine,
|
|
769
|
+
parseBudgetRemaining,
|
|
526
770
|
superviseJob
|
|
527
771
|
};
|
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
import {
|
|
2
2
|
REGISTRY_CLI_ARGS,
|
|
3
3
|
resolveRegistryFromCli
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-PIMGV3E5.js";
|
|
5
5
|
import {
|
|
6
6
|
logger
|
|
7
7
|
} from "./chunk-ZB43YMHW.js";
|
|
8
8
|
import {
|
|
9
9
|
diffAgainstRegistry,
|
|
10
10
|
summarizeDiff
|
|
11
|
-
} from "./chunk-
|
|
12
|
-
import "./chunk-
|
|
13
|
-
import "./chunk-
|
|
11
|
+
} from "./chunk-C7SV7UP5.js";
|
|
12
|
+
import "./chunk-SAQ3EE5R.js";
|
|
13
|
+
import "./chunk-CGXLR77R.js";
|
|
14
14
|
import {
|
|
15
|
+
canonicalizePackIds,
|
|
16
|
+
formatUnknownPack,
|
|
15
17
|
loadAgentKitManifest
|
|
16
|
-
} from "./chunk-
|
|
17
|
-
import "./chunk-
|
|
18
|
+
} from "./chunk-JG3CNGQM.js";
|
|
19
|
+
import "./chunk-QX55T4UX.js";
|
|
20
|
+
import "./chunk-6M6UKECW.js";
|
|
18
21
|
import "./chunk-C4Q77GGJ.js";
|
|
19
22
|
import "./chunk-5B4DVO6C.js";
|
|
20
23
|
|
|
@@ -53,6 +56,11 @@ var diffCommand = defineCommand({
|
|
|
53
56
|
});
|
|
54
57
|
try {
|
|
55
58
|
logger.info(`Registry: ${registry.root} (${registry.source})`);
|
|
59
|
+
const packIds = await canonicalizePackIds(registry.root, manifest.packs);
|
|
60
|
+
for (const { from, to } of packIds.rewrites) {
|
|
61
|
+
logger.info(`Pack id '${from}' is a legacy id for '${to}'; agent-kit update rewrites it.`);
|
|
62
|
+
}
|
|
63
|
+
for (const id of packIds.unknown) logger.warn(formatUnknownPack(id, packIds.knownIds));
|
|
56
64
|
const entries = await diffAgainstRegistry(registry.root, args.cwd, manifest);
|
|
57
65
|
const summary = summarizeDiff(entries);
|
|
58
66
|
console.log(
|