@dadado/agent-kit-cli 6.23.0 → 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.
Files changed (65) hide show
  1. package/README.md +1 -0
  2. package/dashboard/dashboard-data.mjs +126 -5
  3. package/dashboard/dashboard.html +45 -4
  4. package/dashboard/lib/live-refresh.mjs +1 -0
  5. package/dist/{add-RKZQX6ZK.js → add-OYLOMCM6.js} +14 -6
  6. package/dist/chunk-2F6NMQOA.js +519 -0
  7. package/dist/chunk-2QYWMSI5.js +193 -0
  8. package/dist/{chunk-B3VR5YBQ.js → chunk-2TW7ENWC.js} +12 -11
  9. package/dist/{chunk-2IP4OO6R.js → chunk-2XLI7XEY.js} +1 -1
  10. package/dist/chunk-6M6UKECW.js +176 -0
  11. package/dist/{chunk-UJCATSYO.js → chunk-7Y74KO7U.js} +45 -16
  12. package/dist/{chunk-DZCLMIAS.js → chunk-AQLBEEPD.js} +236 -2
  13. package/dist/{chunk-R4DUO5DA.js → chunk-AXQMVQ6O.js} +61 -237
  14. package/dist/{chunk-7TYA3GMI.js → chunk-C7SV7UP5.js} +7 -4
  15. package/dist/{chunk-F7YAAKYP.js → chunk-CIV42JGT.js} +7 -5
  16. package/dist/{chunk-CQHD6UKB.js → chunk-CXE6ASSX.js} +1 -0
  17. package/dist/{chunk-6BEFGKCU.js → chunk-EO5NGAYV.js} +1 -1
  18. package/dist/{chunk-MJJBIOSY.js → chunk-G5MQRP6M.js} +31 -13
  19. package/dist/chunk-GMG7ZH4E.js +357 -0
  20. package/dist/{chunk-5EBT3V7G.js → chunk-GQSSXDDK.js} +1 -1
  21. package/dist/{chunk-5LNHRL5E.js → chunk-H7RAFRRZ.js} +41 -245
  22. package/dist/{chunk-IESSMKOV.js → chunk-HSIHZWFF.js} +4 -4
  23. package/dist/{chunk-W3ZJVBNY.js → chunk-IFBIO7VT.js} +449 -418
  24. package/dist/{chunk-V2H57TFD.js → chunk-JG3CNGQM.js} +78 -170
  25. package/dist/{chunk-KDJ4ML7I.js → chunk-JGG574RK.js} +3 -3
  26. package/dist/{chunk-SGTTC2JP.js → chunk-KWYF7QNH.js} +1 -1
  27. package/dist/{chunk-CVZNSRXV.js → chunk-M4UL422I.js} +80 -15
  28. package/dist/{chunk-AWQ6KRFV.js → chunk-NJ2SUSWX.js} +1 -1
  29. package/dist/{chunk-DRZFWIBN.js → chunk-PIMGV3E5.js} +1 -1
  30. package/dist/{chunk-QNISTPPZ.js → chunk-QACMV46U.js} +3 -3
  31. package/dist/{chunk-5PSV76CQ.js → chunk-QLTGHJB3.js} +25 -6
  32. package/dist/{chunk-OYFCBYMP.js → chunk-QX55T4UX.js} +13 -1
  33. package/dist/chunk-SAQ3EE5R.js +138 -0
  34. package/dist/{chunk-C4LCOOL4.js → chunk-TOSAAQ5A.js} +1 -1
  35. package/dist/chunk-WKFE3RUC.js +433 -0
  36. package/dist/{chunk-BGL5DRK2.js → chunk-XGZOU4DS.js} +1 -1
  37. package/dist/{commands-SAQEEE6V.js → commands-UW2C2ZN4.js} +4 -4
  38. package/dist/{conflicts-5JOP4GX2.js → conflicts-RING6AHV.js} +6 -6
  39. package/dist/{contribute-BQKRT5GN.js → contribute-LSY75JZH.js} +5 -4
  40. package/dist/{countdown-25E5C7AR.js → countdown-SZ2P4XHB.js} +267 -23
  41. package/dist/{diff-6JSXBVSX.js → diff-NZVBVQSK.js} +13 -5
  42. package/dist/{doctor-I3MTHS7F.js → doctor-TJSXBVGV.js} +103 -17
  43. package/dist/{ground-control-IDCXN5FK.js → ground-control-ZJXPUIQN.js} +3 -3
  44. package/dist/{guard-RJZEEKSL.js → guard-ZO4Z3LLB.js} +47 -9
  45. package/dist/{handoff-5AGE2D3T.js → handoff-2OZSWGTE.js} +2 -0
  46. package/dist/{hook-WNA42CXE.js → hook-3VPKNSOO.js} +12 -10
  47. package/dist/index.js +27 -26
  48. package/dist/{init-FZ2UFPO7.js → init-UW2BJBO2.js} +21 -15
  49. package/dist/{install-CTLT3TSI.js → install-RQSI4CHG.js} +18 -15
  50. package/dist/installs-7TR4H4QH.js +222 -0
  51. package/dist/{mission-control-CRMCRZUU.js → mission-control-VSU6NT43.js} +1 -1
  52. package/dist/{queue-JW4VR33H.js → queue-JHYILLMX.js} +9 -9
  53. package/dist/{run-X2WOONTB.js → run-CQF5RM5X.js} +21 -21
  54. package/dist/{run-plan-4MOLLIES.js → run-plan-BEOCOJCF.js} +13 -13
  55. package/dist/{scan-K3T5RQLC.js → scan-7D3RMO34.js} +2 -1
  56. package/dist/{session-start-MV7A4263.js → session-start-QV7CEFRX.js} +16 -10
  57. package/dist/{sessions-UPFDWDMB.js → sessions-AWAAO3DU.js} +1 -1
  58. package/dist/{setup-global-VNADNTQ2.js → setup-global-ST4TT427.js} +8 -7
  59. package/dist/{status-SXA3OK5E.js → status-HUBPBGUU.js} +13 -10
  60. package/dist/update-DD5UZPGG.js +31 -0
  61. package/dist/update-all-YYUTXHGR.js +695 -0
  62. package/package.json +1 -1
  63. package/dist/chunk-4MR4QXMF.js +0 -52
  64. package/dist/chunk-HAFRAXGV.js +0 -17
  65. package/dist/update-RMAWXMCV.js +0 -304
@@ -1,21 +1,27 @@
1
1
  import {
2
+ isPlanExhaustedReason,
2
3
  loadRolesContext,
4
+ parseAgentStopLine,
3
5
  resolveReviewJobRole,
4
6
  resolveWorkerRole
5
- } from "./chunk-DZCLMIAS.js";
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-IESSMKOV.js";
13
- import "./chunk-7ABY6DYH.js";
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-C4LCOOL4.js";
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-BGL5DRK2.js";
30
- import "./chunk-L5V3W3DY.js";
31
- import "./chunk-MUTTNRX4.js";
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-SGTTC2JP.js";
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-W3ZJVBNY.js";
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
- /** A gate exit is pending, or the run reached a gate. */
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) return input.pendingGrew ? COUNTDOWN_EXIT.pending : 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 ?? ((text) => process.stdout.write(text));
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 { exitCode: preflight.exitCode, ...logPath ? { logPath } : {} };
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 reason = 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}`}`;
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
- return { exitCode, ...logPath ? { logPath } : {} };
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 findings pending, 3 Circuit's Dead. Never git-prod."
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-DRZFWIBN.js";
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-7TYA3GMI.js";
12
- import "./chunk-4MR4QXMF.js";
11
+ } from "./chunk-C7SV7UP5.js";
12
+ import "./chunk-SAQ3EE5R.js";
13
13
  import "./chunk-CGXLR77R.js";
14
14
  import {
15
+ canonicalizePackIds,
16
+ formatUnknownPack,
15
17
  loadAgentKitManifest
16
- } from "./chunk-V2H57TFD.js";
17
- import "./chunk-OYFCBYMP.js";
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(