@dadado/agent-kit-cli 6.23.0 → 6.26.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 (86) hide show
  1. package/README.md +1 -0
  2. package/dashboard/dashboard-data.mjs +126 -5
  3. package/dashboard/dashboard.html +48 -7
  4. package/dashboard/lib/guards.mjs +1 -0
  5. package/dashboard/lib/live-refresh.mjs +1 -0
  6. package/dist/{add-RKZQX6ZK.js → add-G7KEZLWP.js} +17 -8
  7. package/dist/{chunk-7HDQEK6T.js → chunk-2G4K4ZI5.js} +7 -3
  8. package/dist/{chunk-5PSV76CQ.js → chunk-2GXN7HVG.js} +26 -7
  9. package/dist/chunk-2QYWMSI5.js +193 -0
  10. package/dist/{chunk-B3VR5YBQ.js → chunk-2TW7ENWC.js} +12 -11
  11. package/dist/{chunk-IESSMKOV.js → chunk-5A72LTR3.js} +7 -7
  12. package/dist/{chunk-R4DUO5DA.js → chunk-AXQMVQ6O.js} +61 -237
  13. package/dist/{chunk-6WUKLS4D.js → chunk-BIFTTL2O.js} +1 -1
  14. package/dist/{chunk-AWQ6KRFV.js → chunk-BVZDPVUL.js} +1 -1
  15. package/dist/{chunk-QNISTPPZ.js → chunk-ENRXS5O6.js} +19 -12
  16. package/dist/chunk-FB6G6OD6.js +519 -0
  17. package/dist/{chunk-MFKHIWEL.js → chunk-FOVHFMSH.js} +1 -1
  18. package/dist/{chunk-6BEFGKCU.js → chunk-FUSNEYGU.js} +29 -3
  19. package/dist/chunk-H7KAXI5R.js +357 -0
  20. package/dist/chunk-HGB4DHXV.js +138 -0
  21. package/dist/{chunk-W3ZJVBNY.js → chunk-HXV6VQD4.js} +2374 -983
  22. package/dist/{chunk-BGL5DRK2.js → chunk-I3FGWNU5.js} +4 -4
  23. package/dist/chunk-IHVJTGYR.js +144 -0
  24. package/dist/{chunk-5LNHRL5E.js → chunk-IUY24WPE.js} +93 -263
  25. package/dist/chunk-JG5MKMOM.js +248 -0
  26. package/dist/{chunk-SGTTC2JP.js → chunk-JWIJHO67.js} +17 -2
  27. package/dist/chunk-KMK4T4ZM.js +34 -0
  28. package/dist/{chunk-ZMYV6PRE.js → chunk-LEVNLHH3.js} +2 -1
  29. package/dist/{chunk-2IP4OO6R.js → chunk-MGVV6YC4.js} +1 -1
  30. package/dist/{chunk-7TYA3GMI.js → chunk-MWRYQLEG.js} +7 -4
  31. package/dist/chunk-NHJ4IAVN.js +435 -0
  32. package/dist/{chunk-C4Q77GGJ.js → chunk-O7VMHCNN.js} +6 -0
  33. package/dist/{chunk-5EBT3V7G.js → chunk-OVRGTHZD.js} +1 -1
  34. package/dist/{chunk-F7YAAKYP.js → chunk-PCIYXGB3.js} +7 -5
  35. package/dist/{chunk-UJCATSYO.js → chunk-PLLXFSN2.js} +46 -17
  36. package/dist/{chunk-OYFCBYMP.js → chunk-RJP47EGS.js} +18 -1
  37. package/dist/{chunk-KDJ4ML7I.js → chunk-RRJVC35Y.js} +4 -4
  38. package/dist/{chunk-DRZFWIBN.js → chunk-SWJJW624.js} +1 -1
  39. package/dist/{chunk-MJJBIOSY.js → chunk-SYRJ5TTK.js} +34 -12
  40. package/dist/{chunk-L5V3W3DY.js → chunk-TTUFIE26.js} +60 -14
  41. package/dist/{chunk-JFS4GKP7.js → chunk-XXPI4H4D.js} +2 -2
  42. package/dist/{chunk-CVZNSRXV.js → chunk-Y5526WCN.js} +84 -19
  43. package/dist/{chunk-CQHD6UKB.js → chunk-Y575INEC.js} +2 -1
  44. package/dist/{chunk-V2H57TFD.js → chunk-ZNZHDPS3.js} +80 -170
  45. package/dist/{commands-SAQEEE6V.js → commands-K4HSDML5.js} +8 -6
  46. package/dist/{conflicts-5JOP4GX2.js → conflicts-4SUWIPWP.js} +9 -10
  47. package/dist/{contribute-BQKRT5GN.js → contribute-HE4WCBRY.js} +7 -5
  48. package/dist/{countdown-25E5C7AR.js → countdown-TYQHVAIX.js} +305 -32
  49. package/dist/{dashboard-P65XHYCU.js → dashboard-6V6PCNYF.js} +1 -1
  50. package/dist/{dashboard-broadcast-GYK34QYL.js → dashboard-broadcast-PMVQ7PXU.js} +1 -1
  51. package/dist/{diff-6JSXBVSX.js → diff-3XUZM7ZT.js} +15 -6
  52. package/dist/{doctor-I3MTHS7F.js → doctor-KGUWU5SN.js} +106 -19
  53. package/dist/{engine-info-BBI5QO5Y.js → engine-info-VM4VPGQM.js} +2 -2
  54. package/dist/{ground-control-IDCXN5FK.js → ground-control-ZIDHEOPW.js} +7 -4
  55. package/dist/{guard-RJZEEKSL.js → guard-ZO4Z3LLB.js} +47 -9
  56. package/dist/{handoff-5AGE2D3T.js → handoff-LLT4CI6H.js} +4 -3
  57. package/dist/{hook-WNA42CXE.js → hook-UPZ3CPYS.js} +22 -20
  58. package/dist/index.js +51 -33
  59. package/dist/{init-FZ2UFPO7.js → init-ZHLVXEVT.js} +25 -18
  60. package/dist/install-XWOG64W3.js +42 -0
  61. package/dist/installs-2ROXPO6M.js +223 -0
  62. package/dist/{mission-control-CRMCRZUU.js → mission-control-IGOI3WHS.js} +2 -2
  63. package/dist/models-5BDXREWM.js +45 -0
  64. package/dist/paths-JTPV6SXH.js +107 -0
  65. package/dist/pi-DCMDOY65.js +248 -0
  66. package/dist/{plan-index-BNLUU6T5.js → plan-index-5QZJK4AG.js} +2 -3
  67. package/dist/{queue-JW4VR33H.js → queue-Z5VNNHM6.js} +10 -12
  68. package/dist/{run-X2WOONTB.js → run-QURAXAR2.js} +27 -33
  69. package/dist/{run-plan-4MOLLIES.js → run-plan-4MMHVCTS.js} +35 -23
  70. package/dist/{scan-K3T5RQLC.js → scan-7D3RMO34.js} +2 -1
  71. package/dist/{session-start-MV7A4263.js → session-start-NC2HE5X5.js} +20 -14
  72. package/dist/{sessions-UPFDWDMB.js → sessions-WWWLYPW6.js} +4 -4
  73. package/dist/{setup-global-VNADNTQ2.js → setup-global-WDMARD4Z.js} +12 -10
  74. package/dist/{status-SXA3OK5E.js → status-2WNJL7PP.js} +17 -13
  75. package/dist/update-YSVOYYK5.js +32 -0
  76. package/dist/update-all-5XLTCHPX.js +697 -0
  77. package/package.json +14 -4
  78. package/pi/agent-kit.ts +224 -0
  79. package/dist/chunk-4MR4QXMF.js +0 -52
  80. package/dist/chunk-7ABY6DYH.js +0 -89
  81. package/dist/chunk-C4LCOOL4.js +0 -71
  82. package/dist/chunk-DZCLMIAS.js +0 -391
  83. package/dist/chunk-HAFRAXGV.js +0 -17
  84. package/dist/chunk-MUTTNRX4.js +0 -53
  85. package/dist/install-CTLT3TSI.js +0 -38
  86. package/dist/update-RMAWXMCV.js +0 -304
@@ -1,21 +1,17 @@
1
1
  import {
2
- loadRolesContext,
3
- resolveReviewJobRole,
4
- resolveWorkerRole
5
- } from "./chunk-DZCLMIAS.js";
2
+ NO_PROGRESS_REASON,
3
+ isNoProgressLine,
4
+ isPlanExhaustedReason,
5
+ parseAgentStopLine
6
+ } from "./chunk-JG5MKMOM.js";
6
7
  import {
7
8
  REVIEW_BACKENDS,
8
9
  REVIEW_PACK_DEFAULT_MAX_BYTES,
9
10
  REVIEW_PACK_SLASH,
10
11
  parseReviewPackMaxBytes,
11
12
  reviewBackendMessage
12
- } from "./chunk-IESSMKOV.js";
13
- import "./chunk-7ABY6DYH.js";
14
- import {
15
- detectAgentBackend,
16
- listDetectBackendIds
17
- } from "./chunk-C4LCOOL4.js";
18
- import "./chunk-5EBT3V7G.js";
13
+ } from "./chunk-5A72LTR3.js";
14
+ import "./chunk-OVRGTHZD.js";
19
15
  import {
20
16
  GATE_EXIT_MARKER_RELPATH,
21
17
  defaultExec,
@@ -26,24 +22,36 @@ import {
26
22
  readGateExitMarker,
27
23
  resolveGateExitRefs,
28
24
  writeGateExitMarker
29
- } from "./chunk-BGL5DRK2.js";
30
- import "./chunk-L5V3W3DY.js";
31
- import "./chunk-MUTTNRX4.js";
25
+ } from "./chunk-I3FGWNU5.js";
32
26
  import {
33
27
  classifySlash,
34
28
  normalizeSlashName,
35
29
  promoteBlockedMessage,
36
30
  unknownSlashMessage
37
- } from "./chunk-SGTTC2JP.js";
31
+ } from "./chunk-JWIJHO67.js";
38
32
  import {
39
33
  CLAUDE_MAX_BUDGET_USD_ENV,
40
34
  CLAUDE_MAX_TURNS_ENV,
41
35
  RedactingStreamBuffer,
42
- redactSecrets
43
- } from "./chunk-W3ZJVBNY.js";
36
+ claudeRunCaps,
37
+ countPendingTodos,
38
+ detectAgentBackend,
39
+ listDetectBackendIds,
40
+ loadRolesContext,
41
+ parseResultLine,
42
+ readPlan,
43
+ redactSecrets,
44
+ resolveActivePlanPath,
45
+ resolveReviewJobRole,
46
+ resolveWorkerRole
47
+ } from "./chunk-HXV6VQD4.js";
44
48
  import {
45
49
  HITL_UNANSWERED_EXIT_CODE
46
50
  } from "./chunk-P7732A25.js";
51
+ import {
52
+ ensurePathIgnored,
53
+ parsePlanFrontmatter
54
+ } from "./chunk-TTUFIE26.js";
47
55
  import "./chunk-WGLPZXNU.js";
48
56
  import "./chunk-Q35TWISF.js";
49
57
  import "./chunk-QTON2GQX.js";
@@ -54,22 +62,151 @@ import "./chunk-PFEUZXVT.js";
54
62
  import {
55
63
  ensureLoopLogsDir,
56
64
  runnerStatePaths
57
- } from "./chunk-C4Q77GGJ.js";
65
+ } from "./chunk-O7VMHCNN.js";
58
66
  import "./chunk-5B4DVO6C.js";
59
67
 
60
68
  // src/commands/countdown.ts
61
69
  import { spawn } from "child_process";
62
- import { appendFile } from "fs/promises";
70
+ import { appendFile, mkdir } from "fs/promises";
63
71
  import path from "path";
64
72
  import { defineCommand } from "citty";
65
73
  var COUNTDOWN_EXIT = {
66
74
  completed: 0,
67
75
  usage: 1,
68
- /** A gate exit is pending, or the run reached a gate. */
76
+ /**
77
+ * A gate exit is pending, the run reached a gate, or `--budget-remaining`
78
+ * does not cover the job: waits for the operator.
79
+ */
69
80
  pending: 2,
70
- /** Circuit's Dead: failed, stalled, over the window, dirty tree, fetch failed. */
71
- circuitsDead: 3
81
+ /**
82
+ * Circuit's Dead: failed, stalled, over the window, dirty tree, fetch
83
+ * failed, or a tick that reported `continue` without progress.
84
+ */
85
+ circuitsDead: 3,
86
+ /**
87
+ * Needs operator: the tick ended because the agent requested a stop (a
88
+ * question, nothing implementable) while to-dos remain. A stop on an
89
+ * exhausted plan stays 0.
90
+ */
91
+ needsOperator: 5
72
92
  };
93
+ var COUNTDOWN_RESULT_PREFIX = "AGENT_KIT_RESULT";
94
+ function countdownOutcome(exitCode) {
95
+ if (exitCode === COUNTDOWN_EXIT.completed) return "ok";
96
+ if (exitCode === COUNTDOWN_EXIT.pending || exitCode === COUNTDOWN_EXIT.needsOperator) {
97
+ return "needs-operator";
98
+ }
99
+ return "broken";
100
+ }
101
+ function formatCountdownResultLine(record) {
102
+ return `${COUNTDOWN_RESULT_PREFIX} ${JSON.stringify(record)}`;
103
+ }
104
+ function createAgentStopWatcher() {
105
+ let last = null;
106
+ let partial = "";
107
+ return {
108
+ push(text) {
109
+ const lines = (partial + text).split("\n");
110
+ partial = lines.pop() ?? "";
111
+ for (const line of lines) {
112
+ const hit = parseAgentStopLine(line);
113
+ if (hit !== null) last = hit;
114
+ }
115
+ },
116
+ reason() {
117
+ const hit = partial ? parseAgentStopLine(partial) : null;
118
+ return hit ?? last;
119
+ }
120
+ };
121
+ }
122
+ function createCostWatcher() {
123
+ let total = 0;
124
+ let seen = false;
125
+ let unpriced = false;
126
+ let last = null;
127
+ let partial = "";
128
+ const take = (line) => {
129
+ const hit = parseResultLine(line);
130
+ if (hit === null) return;
131
+ if (hit.costBasis === "unknown") unpriced = true;
132
+ const figure = hit.reportedUsd;
133
+ if (figure === null) return;
134
+ const replaces = hit.sessionTotal && last !== null && figure >= last;
135
+ total += replaces && last !== null ? figure - last : figure;
136
+ last = figure;
137
+ seen = true;
138
+ };
139
+ const cost = () => {
140
+ if (partial) {
141
+ take(partial);
142
+ partial = "";
143
+ }
144
+ const reportedUsd = seen ? Math.round(total * 1e6) / 1e6 : null;
145
+ return {
146
+ costUsd: unpriced ? null : reportedUsd,
147
+ reportedUsd,
148
+ costBasis: unpriced ? "unknown" : null
149
+ };
150
+ };
151
+ return {
152
+ push(text) {
153
+ const lines = (partial + text).split("\n");
154
+ partial = lines.pop() ?? "";
155
+ for (const line of lines) take(line);
156
+ },
157
+ costUsd: () => cost().costUsd,
158
+ cost
159
+ };
160
+ }
161
+ function createNoProgressWatcher() {
162
+ let hit = false;
163
+ let partial = "";
164
+ return {
165
+ push(text) {
166
+ const lines = (partial + text).split("\n");
167
+ partial = lines.pop() ?? "";
168
+ if (lines.some(isNoProgressLine)) hit = true;
169
+ },
170
+ seen: () => hit || partial !== "" && isNoProgressLine(partial)
171
+ };
172
+ }
173
+ var COST_LEDGER_RELPATH = ".cursor/context/cost-ledger.ndjson";
174
+ function formatCostLedgerLine(entry) {
175
+ return `${JSON.stringify(entry)}
176
+ `;
177
+ }
178
+ async function appendCostLedger(opts) {
179
+ try {
180
+ const git = (args) => opts.exec("git", args, { cwd: opts.root, env: opts.env });
181
+ if (!await ensurePathIgnored(git, opts.root, COST_LEDGER_RELPATH)) {
182
+ return `${COST_LEDGER_RELPATH} is not ignored by git and could not be added to .git/info/exclude`;
183
+ }
184
+ const file = path.join(opts.root, COST_LEDGER_RELPATH);
185
+ await mkdir(path.dirname(file), { recursive: true });
186
+ await appendFile(file, formatCostLedgerLine(opts.entry), "utf8");
187
+ return null;
188
+ } catch (err) {
189
+ return String(err instanceof Error ? err.message : err);
190
+ }
191
+ }
192
+ function parseBudgetRemaining(raw) {
193
+ if (raw === void 0) return null;
194
+ const text = String(raw).trim();
195
+ const value = Number(text);
196
+ if (!text || !Number.isFinite(value)) return "--budget-remaining must be a number (USD)";
197
+ return value;
198
+ }
199
+ function usd(value) {
200
+ return `${value < 0 ? "-" : ""}$${Math.abs(value).toFixed(2)}`;
201
+ }
202
+ function budgetRefusal(input) {
203
+ if (input.remaining <= 0) return `budget: ${usd(input.remaining)} remaining; nothing left`;
204
+ if (input.capUsd === void 0) return null;
205
+ const need = input.capUsd * input.ticks;
206
+ if (input.remaining >= need) return null;
207
+ const per = input.ticks === 1 ? `${CLAUDE_MAX_BUDGET_USD_ENV}=${input.capUsd}` : `${CLAUDE_MAX_BUDGET_USD_ENV}=${input.capUsd} x ${input.ticks} ticks`;
208
+ return `budget: ${usd(input.remaining)} remaining is below the cap of this fire (${usd(need)}, ${per})`;
209
+ }
73
210
  var COUNTDOWN_JOBS = ["tick", "dispatch", "review"];
74
211
  var COUNTDOWN_DEFAULT_MAX_TICKS = 1;
75
212
  var COUNTDOWN_DEFAULT_WINDOW_MIN = 120;
@@ -142,7 +279,10 @@ async function superviseJob(handle, opts) {
142
279
  }
143
280
  function countdownExitCode(input) {
144
281
  if (input.circuitsDead) return COUNTDOWN_EXIT.circuitsDead;
145
- if (input.code === 0) return input.pendingGrew ? COUNTDOWN_EXIT.pending : 0;
282
+ if (input.code === 0) {
283
+ if (input.pendingGrew) return COUNTDOWN_EXIT.pending;
284
+ return input.needsOperator ? COUNTDOWN_EXIT.needsOperator : COUNTDOWN_EXIT.completed;
285
+ }
146
286
  if (input.code === HITL_UNANSWERED_EXIT_CODE) return COUNTDOWN_EXIT.pending;
147
287
  return COUNTDOWN_EXIT.circuitsDead;
148
288
  }
@@ -240,14 +380,77 @@ function positive(raw, flag, integer) {
240
380
  return value;
241
381
  }
242
382
  async function executeCountdown(input) {
383
+ const write = input.write ?? ((text) => process.stdout.write(text));
384
+ const root = path.resolve(input.cwd);
385
+ const env = input.env ?? process.env;
386
+ const now = input.now ?? /* @__PURE__ */ new Date();
387
+ const end = await runCountdown({ ...input, write, now });
388
+ const red = (text) => redactSecrets(text, gateExitRedactions(env));
389
+ const result = {
390
+ outcome: countdownOutcome(end.exitCode),
391
+ reason: red(end.reason).replace(/\s+/g, " ").trim(),
392
+ repo: path.basename(root),
393
+ plan: end.plan ?? null,
394
+ todo: end.todo ?? null,
395
+ exit: end.exitCode,
396
+ cost_usd: end.cost?.costUsd ?? null,
397
+ cost_usd_reported: end.cost?.reportedUsd ?? null,
398
+ cost_basis: end.cost?.costBasis ?? null
399
+ };
400
+ if (end.exitCode !== COUNTDOWN_EXIT.usage && end.job) {
401
+ const failed = await appendCostLedger({
402
+ root,
403
+ env,
404
+ exec: input.exec ?? defaultExec,
405
+ entry: {
406
+ at: now.toISOString(),
407
+ repo: result.repo,
408
+ plan: result.plan,
409
+ todo: result.todo,
410
+ job: end.job,
411
+ backend: end.backend ?? null,
412
+ model: end.model ?? null,
413
+ cost_usd: result.cost_usd,
414
+ input_tokens: null,
415
+ output_tokens: null,
416
+ exit: result.exit,
417
+ outcome: result.outcome,
418
+ cost_usd_reported: result.cost_usd_reported,
419
+ cost_basis: result.cost_basis
420
+ }
421
+ });
422
+ if (failed !== null) {
423
+ const warning = `${red(`countdown: warning: cost ledger not written: ${failed}`).replace(/\s+/g, " ").trim()}
424
+ `;
425
+ write(warning);
426
+ if (end.logPath) await appendFile(end.logPath, warning, "utf8").catch(() => void 0);
427
+ }
428
+ }
429
+ const line = `${formatCountdownResultLine(result)}
430
+ `;
431
+ write(line);
432
+ if (end.logPath) await appendFile(end.logPath, line, "utf8").catch(() => void 0);
433
+ return {
434
+ exitCode: end.exitCode,
435
+ ...end.error ? { error: end.error } : {},
436
+ ...end.logPath ? { logPath: end.logPath } : {},
437
+ result
438
+ };
439
+ }
440
+ function inProgressTodo(raw) {
441
+ const active = parsePlanFrontmatter(raw).todos.filter((t) => t.status === "in_progress");
442
+ return active.length === 1 ? active[0]?.id ?? null : null;
443
+ }
444
+ async function runCountdown(input) {
243
445
  const root = path.resolve(input.cwd);
244
446
  const env = input.env ?? process.env;
245
447
  const exec = input.exec ?? defaultExec;
246
448
  const now = input.now ?? /* @__PURE__ */ new Date();
247
- const write = input.write ?? ((text) => process.stdout.write(text));
449
+ const write = input.write;
248
450
  const usage = (error) => ({
249
451
  exitCode: COUNTDOWN_EXIT.usage,
250
- error
452
+ error,
453
+ reason: `usage: ${error}`
251
454
  });
252
455
  const slash = normalizeSlashName(input.slash ?? "");
253
456
  const job = String(input.job).trim();
@@ -268,6 +471,8 @@ async function executeCountdown(input) {
268
471
  const windowMin = positive(input.windowMin, "--window-min", false);
269
472
  const stallMin = positive(input.stallMin, "--stall-min", false);
270
473
  for (const v of [maxTicks, windowMin, stallMin]) if (typeof v === "string") return usage(v);
474
+ const budget = parseBudgetRemaining(input.budgetRemaining);
475
+ if (typeof budget === "string") return usage(budget);
271
476
  const packRaw = input.maxPackBytes === void 0 ? "" : String(input.maxPackBytes).trim();
272
477
  if (job !== "review" && packRaw) return usage("--max-pack-bytes only applies to --job review");
273
478
  if (job !== "review" && input.includeReviewed) {
@@ -352,11 +557,40 @@ async function executeCountdown(input) {
352
557
  const jobLabel = job === "tick" ? "run-plan" : job === "review" ? `run ${REVIEW_PACK_SLASH}` : `run ${slash}`;
353
558
  say(`fire ${gateExitStamp(now)}: job ${job} (${jobLabel}) on ${detected.id}`);
354
559
  for (const note of rolesNotes) say(note);
560
+ const runsTick = job === "tick" || job === "dispatch" && classifySlash(slash) === "run-plan";
561
+ const planPath = runsTick ? await resolveActivePlanPath(root).catch(() => null) : null;
562
+ const plan = planPath ? path.basename(planPath) : null;
563
+ const ledger = { job, backend: detected.id, model: model ?? null };
564
+ if (budget !== null) {
565
+ const refusal = budgetRefusal({
566
+ remaining: budget,
567
+ capUsd: claudeRunCaps(env).caps.maxBudgetUsd,
568
+ ticks: job === "review" ? 1 : maxTicks
569
+ });
570
+ if (refusal !== null) {
571
+ say(`refused: ${refusal} (exit ${COUNTDOWN_EXIT.pending})`);
572
+ await openLog().catch(() => void 0);
573
+ return {
574
+ exitCode: COUNTDOWN_EXIT.pending,
575
+ reason: refusal,
576
+ plan,
577
+ ...ledger,
578
+ ...logPath ? { logPath } : {}
579
+ };
580
+ }
581
+ say(`budget: ${usd(budget)} remaining`);
582
+ }
355
583
  const preflight = await countdownPreflight({ root, env, exec, now, log: say });
356
584
  if (!preflight.ok) {
357
585
  say(`refused: ${preflight.reason} (exit ${preflight.exitCode})`);
358
586
  await openLog().catch(() => void 0);
359
- return { exitCode: preflight.exitCode, ...logPath ? { logPath } : {} };
587
+ return {
588
+ exitCode: preflight.exitCode,
589
+ reason: `refused: ${preflight.reason}`,
590
+ plan,
591
+ ...ledger,
592
+ ...logPath ? { logPath } : {}
593
+ };
360
594
  }
361
595
  await openLog();
362
596
  const capLines = [CLAUDE_MAX_TURNS_ENV, CLAUDE_MAX_BUDGET_USD_ENV].filter((k) => env[k]).map((k) => `${k}=${env[k]}`);
@@ -383,8 +617,14 @@ async function executeCountdown(input) {
383
617
  process.on("SIGTERM", onSigterm);
384
618
  }
385
619
  const jobOut = new RedactingStreamBuffer(redactions);
620
+ const stopWatch = runsTick ? createAgentStopWatcher() : null;
621
+ const noProgressWatch = runsTick ? createNoProgressWatcher() : null;
622
+ const costWatch = createCostWatcher();
386
623
  const emitJob = (out) => {
387
624
  if (!out) return;
625
+ stopWatch?.push(out);
626
+ noProgressWatch?.push(out);
627
+ costWatch.push(out);
388
628
  write(out);
389
629
  toLog(out);
390
630
  };
@@ -409,17 +649,25 @@ async function executeCountdown(input) {
409
649
  const after = await readGateExitMarker(root);
410
650
  const pendingAfter = after.kind === "ok" ? after.marker.pending.length : preflight.pendingBefore;
411
651
  const pendingGrew = pendingAfter > preflight.pendingBefore;
652
+ const stopReason = stopWatch?.reason() ?? null;
653
+ const planRaw = planPath ? await readPlan(planPath).catch(() => null) : null;
654
+ const todosLeft = planRaw === null ? null : countPendingTodos(planRaw);
655
+ const todo = planRaw === null ? null : inProgressTodo(planRaw);
656
+ const planExhausted = stopReason !== null && (todosLeft === null ? isPlanExhaustedReason(stopReason) : todosLeft === 0);
412
657
  const exitCode = countdownExitCode({
413
658
  code: end.code,
414
659
  circuitsDead: end.circuitsDead,
415
- pendingGrew
660
+ pendingGrew,
661
+ needsOperator: stopReason !== null && !planExhausted
416
662
  });
663
+ const noProgress = end.code === 1 && noProgressWatch?.seen() === true;
664
+ const deadReason = end.circuitsDead ? `Circuit's Dead: ${end.circuitsDead === "window" ? `window of ${windowMin} min exceeded` : `no stream event for ${stallMin} min`}` : noProgress ? `Circuit's Dead: ${NO_PROGRESS_REASON} (job exited with code 1)` : `Circuit's Dead: job exited with ${end.code === null ? `signal ${end.signal ?? "unknown"}` : `code ${end.code}`}`;
417
665
  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}`}`;
666
+ const reason2 = deadReason;
419
667
  const outcome = {
420
668
  trigger: "failure",
421
669
  exitCode,
422
- reason,
670
+ reason: reason2,
423
671
  command: `countdown --job ${job}${job === "dispatch" ? ` --slash ${slash}` : ""}`,
424
672
  backend: detected.id,
425
673
  ...logPath ? { logPath } : {}
@@ -430,15 +678,24 @@ async function executeCountdown(input) {
430
678
  say(`gate-exit: landing failed: ${String(err)}`);
431
679
  }
432
680
  }
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";
681
+ 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
682
  say(`exit ${exitCode} (${meaning})`);
435
683
  await logChain;
436
- return { exitCode, ...logPath ? { logPath } : {} };
684
+ const reason = exitCode === COUNTDOWN_EXIT.needsOperator ? `agent requested stop: ${stopReason ?? ""}` : exitCode === COUNTDOWN_EXIT.circuitsDead ? deadReason : exitCode === 0 && stopReason !== null ? `plan exhausted: ${stopReason}` : meaning;
685
+ return {
686
+ exitCode,
687
+ reason,
688
+ plan,
689
+ todo,
690
+ ...ledger,
691
+ cost: costWatch.cost(),
692
+ ...logPath ? { logPath } : {}
693
+ };
437
694
  }
438
695
  var countdownCommand = defineCommand({
439
696
  meta: {
440
697
  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."
698
+ 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 (failed, stalled, or a tick that reported continue without progress), 5 the agent requested a stop (needs operator). Each fire appends one line to .cursor/context/cost-ledger.ndjson (cost_usd null when the model could not be priced; cost_usd_reported keeps the reported figure); the last stdout line is AGENT_KIT_RESULT {json}. Never git-prod."
442
699
  },
443
700
  args: {
444
701
  cwd: {
@@ -490,6 +747,10 @@ var countdownCommand = defineCommand({
490
747
  type: "string",
491
748
  description: `Minutes with no stream event before the job is stopped as Circuit's Dead (default: ${COUNTDOWN_DEFAULT_STALL_MIN})`,
492
749
  default: String(COUNTDOWN_DEFAULT_STALL_MIN)
750
+ },
751
+ "budget-remaining": {
752
+ type: "string",
753
+ 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
754
  }
494
755
  },
495
756
  async run({ args }) {
@@ -504,6 +765,7 @@ var countdownCommand = defineCommand({
504
765
  ...args["include-reviewed"] ? { includeReviewed: true } : {},
505
766
  windowMin: String(args["window-min"]),
506
767
  stallMin: String(args["stall-min"]),
768
+ ...args["budget-remaining"] !== void 0 ? { budgetRemaining: String(args["budget-remaining"]) } : {},
507
769
  forwardSignals: true
508
770
  });
509
771
  if (result.error) logger.error(result.error);
@@ -511,17 +773,28 @@ var countdownCommand = defineCommand({
511
773
  }
512
774
  });
513
775
  export {
776
+ COST_LEDGER_RELPATH,
514
777
  COUNTDOWN_DEFAULT_MAX_TICKS,
515
778
  COUNTDOWN_DEFAULT_STALL_MIN,
516
779
  COUNTDOWN_DEFAULT_WINDOW_MIN,
517
780
  COUNTDOWN_EXIT,
518
781
  COUNTDOWN_JOBS,
519
782
  COUNTDOWN_KILL_GRACE_MS,
783
+ COUNTDOWN_RESULT_PREFIX,
784
+ appendCostLedger,
785
+ budgetRefusal,
520
786
  countdownChildArgs,
521
787
  countdownCommand,
522
788
  countdownExitCode,
789
+ countdownOutcome,
523
790
  countdownPreflight,
791
+ createAgentStopWatcher,
792
+ createCostWatcher,
793
+ createNoProgressWatcher,
524
794
  defaultSpawnJob,
525
795
  executeCountdown,
796
+ formatCostLedgerLine,
797
+ formatCountdownResultLine,
798
+ parseBudgetRemaining,
526
799
  superviseJob
527
800
  };
@@ -7,7 +7,7 @@ import {
7
7
  findDashboardStart,
8
8
  readPreferredBrowserFromWorkspace,
9
9
  resolveDashboardSnapshotRoot
10
- } from "./chunk-ZMYV6PRE.js";
10
+ } from "./chunk-LEVNLHH3.js";
11
11
  import "./chunk-ZB43YMHW.js";
12
12
  export {
13
13
  applyDashboardOpenEnv,
@@ -5,7 +5,7 @@ import {
5
5
  findDashboardStart,
6
6
  negatedFlag,
7
7
  resolveDashboardSnapshotRoot
8
- } from "./chunk-ZMYV6PRE.js";
8
+ } from "./chunk-LEVNLHH3.js";
9
9
  import {
10
10
  logger
11
11
  } from "./chunk-ZB43YMHW.js";
@@ -1,21 +1,25 @@
1
1
  import {
2
2
  REGISTRY_CLI_ARGS,
3
3
  resolveRegistryFromCli
4
- } from "./chunk-DRZFWIBN.js";
4
+ } from "./chunk-SWJJW624.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-MWRYQLEG.js";
12
+ import "./chunk-HGB4DHXV.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
- import "./chunk-C4Q77GGJ.js";
18
+ } from "./chunk-ZNZHDPS3.js";
19
+ import "./chunk-RJP47EGS.js";
20
+ import "./chunk-IHVJTGYR.js";
21
+ import "./chunk-KMK4T4ZM.js";
22
+ import "./chunk-O7VMHCNN.js";
19
23
  import "./chunk-5B4DVO6C.js";
20
24
 
21
25
  // src/commands/diff.ts
@@ -53,6 +57,11 @@ var diffCommand = defineCommand({
53
57
  });
54
58
  try {
55
59
  logger.info(`Registry: ${registry.root} (${registry.source})`);
60
+ const packIds = await canonicalizePackIds(registry.root, manifest.packs);
61
+ for (const { from, to } of packIds.rewrites) {
62
+ logger.info(`Pack id '${from}' is a legacy id for '${to}'; agent-kit update rewrites it.`);
63
+ }
64
+ for (const id of packIds.unknown) logger.warn(formatUnknownPack(id, packIds.knownIds));
56
65
  const entries = await diffAgainstRegistry(registry.root, args.cwd, manifest);
57
66
  const summary = summarizeDiff(entries);
58
67
  console.log(