@agentguard-run/burn 0.3.19 → 0.3.21

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 (39) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/README.md +63 -2
  3. package/dist/src/canvas.d.ts +7 -1
  4. package/dist/src/canvas.js +10 -1
  5. package/dist/src/cli.js +70 -6
  6. package/dist/src/frames.d.ts +10 -0
  7. package/dist/src/frames.js +5 -0
  8. package/dist/src/gateway.js +11 -7
  9. package/dist/src/history/claude-transcript.d.ts +63 -1
  10. package/dist/src/history/claude-transcript.js +105 -2
  11. package/dist/src/hook/pre-tool-use.d.ts +2 -10
  12. package/dist/src/hook/pre-tool-use.js +9 -18
  13. package/dist/src/index.d.ts +4 -1
  14. package/dist/src/index.js +18 -2
  15. package/dist/src/insights/calendar-render.d.ts +71 -0
  16. package/dist/src/insights/calendar-render.js +251 -0
  17. package/dist/src/insights/calendar.d.ts +138 -0
  18. package/dist/src/insights/calendar.js +431 -0
  19. package/dist/src/insights/i18n.d.ts +103 -6
  20. package/dist/src/insights/i18n.js +123 -7
  21. package/dist/src/insights/render.d.ts +85 -12
  22. package/dist/src/insights/render.js +207 -17
  23. package/dist/src/insights/session-tip.d.ts +33 -0
  24. package/dist/src/insights/session-tip.js +32 -0
  25. package/dist/src/insights/sessions.d.ts +6 -0
  26. package/dist/src/insights/sessions.js +15 -4
  27. package/dist/src/insights/transcript.d.ts +13 -2
  28. package/dist/src/insights/transcript.js +61 -6
  29. package/dist/src/insights/types.d.ts +14 -0
  30. package/dist/src/policy.d.ts +25 -0
  31. package/dist/src/policy.js +82 -9
  32. package/dist/src/recording.js +5 -1
  33. package/dist/src/replay/render.d.ts +2 -0
  34. package/dist/src/replay/render.js +4 -0
  35. package/dist/src/stop-text.d.ts +11 -2
  36. package/dist/src/stop-text.js +23 -3
  37. package/dist/src/subagent-cost.d.ts +49 -0
  38. package/dist/src/subagent-cost.js +90 -0
  39. package/package.json +5 -1
@@ -17,6 +17,9 @@ exports.newCursor = newCursor;
17
17
  exports.normaliseLine = normaliseLine;
18
18
  exports.readIncremental = readIncremental;
19
19
  exports.readSessionIncremental = readSessionIncremental;
20
+ exports.saveReaderCursor = saveReaderCursor;
21
+ exports.restoreReaderCursor = restoreReaderCursor;
22
+ exports.cloneReaderCursor = cloneReaderCursor;
20
23
  exports.readAll = readAll;
21
24
  const node_fs_1 = require("node:fs");
22
25
  const node_path_1 = require("node:path");
@@ -37,6 +40,48 @@ function toMillis(value) {
37
40
  function nonNegative(value) {
38
41
  return typeof value === 'number' && Number.isFinite(value) && value > 0 ? value : 0;
39
42
  }
43
+ const MODEL_ID = /^[A-Za-z0-9_.:/-]{1,128}$/;
44
+ const AGENT_ID = /^[A-Za-z0-9_-]{1,64}$/;
45
+ /**
46
+ * Add one response's newly observed usage to its child's running total. The
47
+ * five-minute and one-hour parts of a cache write follow the record's own split;
48
+ * a write without one keeps no lifetime and prices as a range.
49
+ */
50
+ function addChildUsage(usage, raw, [input, output, write, read]) {
51
+ const model = typeof raw.message?.model === 'string' && MODEL_ID.test(raw.message.model) ? raw.message.model : '';
52
+ const split = raw.message?.usage?.cache_creation;
53
+ const record = split && typeof split === 'object' ? split : {};
54
+ const fiveMinute = nonNegative(record.ephemeral_5m_input_tokens), oneHour = nonNegative(record.ephemeral_1h_input_tokens);
55
+ const hour = fiveMinute + oneHour > 0 ? Math.round(write * oneHour / (fiveMinute + oneHour)) : 0;
56
+ const five = fiveMinute + oneHour > 0 ? write - hour : 0;
57
+ const row = usage.get(model) ?? [0, 0, 0, 0, 0, 0];
58
+ usage.set(model, [row[0] + input, row[1] + output, row[2] + write, row[3] + read, row[4] + five, row[5] + hour]);
59
+ }
60
+ /**
61
+ * Note the sub-agents the host records as completed. Claude Code writes a
62
+ * synchronous sub-agent's result with status "completed", and announces the end
63
+ * of a background one with a <task-notification> in a queued message (a queue
64
+ * operation, a queued-command attachment, or the user message it becomes). Only
65
+ * the id of a completed sub-agent is kept; nothing else of the message is.
66
+ */
67
+ function observeCompleted(raw, completed) {
68
+ const result = raw.toolUseResult;
69
+ if (result && typeof result === 'object' && !Array.isArray(result)) {
70
+ const { status, agentId } = result;
71
+ if (status === 'completed' && typeof agentId === 'string' && AGENT_ID.test(agentId))
72
+ completed.add(agentId);
73
+ }
74
+ const text = raw.type === 'queue-operation' ? raw.content
75
+ : raw.type === 'user' ? raw.message?.content
76
+ : raw.type === 'attachment' && raw.attachment?.type === 'queued_command' ? raw.attachment.prompt : undefined;
77
+ if (typeof text !== 'string' || !text.startsWith('<task-notification>'))
78
+ return;
79
+ for (const [, body] of text.matchAll(/<task-notification>([\s\S]*?)<\/task-notification>/g)) {
80
+ const id = /<task-id>([A-Za-z0-9_-]{1,64})<\/task-id>/.exec(body)?.[1];
81
+ if (id && /<status>completed<\/status>/.test(body))
82
+ completed.add(id);
83
+ }
84
+ }
40
85
  /** Turn one parsed line into an event, or null if it carries nothing we track. */
41
86
  function normaliseLine(raw, cursor) {
42
87
  const at = toMillis(raw.timestamp);
@@ -47,6 +92,7 @@ function normaliseLine(raw, cursor) {
47
92
  nonNegative(usage.cache_creation_input_tokens), nonNegative(usage.cache_read_input_tokens)];
48
93
  let tokens = snapshot.reduce((sum, value) => sum + value, 0);
49
94
  let cacheRead = snapshot[3];
95
+ let added = snapshot;
50
96
  // Claude writes one row per content block, all carrying the same message.id.
51
97
  // Fork copies preserve that id too. Match the attribution parser's global
52
98
  // identity and per-category maxima, emitting only newly observed usage.
@@ -55,10 +101,13 @@ function normaliseLine(raw, cursor) {
55
101
  cursor.usageByMessage ??= new Map();
56
102
  const previous = cursor.usageByMessage.get(id) ?? [0, 0, 0, 0];
57
103
  const merged = snapshot.map((value, index) => Math.max(value, previous[index]));
58
- tokens = merged.reduce((sum, value, index) => sum + value - previous[index], 0);
59
- cacheRead = merged[3] - previous[3];
104
+ added = merged.map((value, index) => value - previous[index]);
105
+ tokens = added.reduce((sum, value) => sum + value, 0);
106
+ cacheRead = added[3];
60
107
  cursor.usageByMessage.set(id, merged);
61
108
  }
109
+ if (cursor.usage && tokens > 0)
110
+ addChildUsage(cursor.usage, raw, added);
62
111
  // Depth attribution: a line's depth is its parent's depth, plus one if the
63
112
  // host flagged it as a sidechain (subagent) line. Unknown parents are root.
64
113
  const parentDepth = raw.parentUuid ? cursor.depthByUuid.get(raw.parentUuid) ?? 0 : 0;
@@ -121,6 +170,8 @@ function readIncremental(path, cursor, options = {}) {
121
170
  if (size < cursor.offset) {
122
171
  cursor.offset = 0;
123
172
  cursor.depthByUuid.clear();
173
+ // Shared de-duplication would hide a re-read file's usage: it is no longer measured.
174
+ cursor.usage = undefined;
124
175
  }
125
176
  cursor.size = size;
126
177
  if (size === cursor.offset)
@@ -145,6 +196,8 @@ function readIncremental(path, cursor, options = {}) {
145
196
  if (lineBytes.length > 0 && lineBytes.length <= MAX_LINE) {
146
197
  try {
147
198
  const parsed = JSON.parse(lineBytes.toString('utf8'));
199
+ if (cursor.completed)
200
+ observeCompleted(parsed, cursor.completed);
148
201
  const event = normaliseLine(parsed, cursor);
149
202
  if (event)
150
203
  events.push(event);
@@ -186,6 +239,7 @@ function readIncremental(path, cursor, options = {}) {
186
239
  function readSessionIncremental(path, cursor, options = {}) {
187
240
  cursor.usageByMessage ??= new Map();
188
241
  cursor.children ??= new Map();
242
+ cursor.completed ??= new Set();
189
243
  const events = readIncremental(path, cursor, options);
190
244
  const directory = (0, node_path_1.join)(path.replace(/\.jsonl$/, ''), 'subagents');
191
245
  let names;
@@ -200,14 +254,63 @@ function readSessionIncremental(path, cursor, options = {}) {
200
254
  for (const name of names) {
201
255
  const child = cursor.children.get(name) ?? newCursor();
202
256
  child.usageByMessage = cursor.usageByMessage;
257
+ // A sub-agent's own sub-agents report their completion in its transcript.
258
+ child.completed = cursor.completed;
259
+ // Measured from its first byte, as it is read anyway: no second pass over any child.
260
+ if (!child.usage && child.offset === 0)
261
+ child.usage = new Map();
203
262
  cursor.children.set(name, child);
204
263
  for (const event of readIncremental((0, node_path_1.join)(directory, name), child, options)) {
205
264
  if (event.tokens > 0 || event.cacheRead > 0)
206
265
  events.push({ ...event, spawns: [], surfaces: [], sidechain: true });
207
266
  }
267
+ // Line depth only places spawns, and a sub-agent's spawns are dropped above,
268
+ // so a sub-agent cursor keeps no depth map: the saved cursor stays small.
269
+ child.depthByUuid.clear();
208
270
  }
209
271
  return events.sort((a, b) => a.at - b.at);
210
272
  }
273
+ function persist(cursor, child) {
274
+ return { offset: cursor.offset, size: cursor.size, malformedLines: cursor.malformedLines, depthByUuid: [...cursor.depthByUuid],
275
+ usageVersion: cursor.usageVersion,
276
+ ...(!child ? { usageByMessage: [...(cursor.usageByMessage ?? [])] } : {}),
277
+ ...(!child && cursor.completed?.size ? { completed: [...cursor.completed] } : {}),
278
+ ...(child && cursor.usage ? { usage: [...cursor.usage] } : {}),
279
+ ...(cursor.children?.size ? { children: [...cursor.children].map(([name, value]) => [name, persist(value, true)]) } : {}) };
280
+ }
281
+ /** A session cursor, sub-agent cursors included, as JSON can store it. Pair with restoreReaderCursor. */
282
+ function saveReaderCursor(cursor) {
283
+ return persist(cursor, false);
284
+ }
285
+ /**
286
+ * The cursor saveReaderCursor stored. Its sub-agent cursors share the session's
287
+ * de-duplication map and completed ids, as they do while reading. A cursor saved
288
+ * from readIncremental alone (no sub-agent cursors) resumes the session
289
+ * transcript where it stopped and reads each sub-agent transcript from its first
290
+ * byte on the next readSessionIncremental.
291
+ */
292
+ function restoreReaderCursor(saved) {
293
+ const restore = (raw, usageByMessage, completed) => ({
294
+ offset: raw.offset, size: raw.size, malformedLines: raw.malformedLines, depthByUuid: new Map(raw.depthByUuid),
295
+ usageVersion: raw.usageVersion, usageByMessage, completed, ...(raw.usage ? { usage: new Map(raw.usage) } : {}),
296
+ children: new Map((raw.children ?? []).map(([name, child]) => [name, restore(child, usageByMessage, completed)]))
297
+ });
298
+ return restore(saved, new Map(saved.usageByMessage ?? []), new Set(saved.completed ?? []));
299
+ }
300
+ /**
301
+ * An independent copy of a session cursor, sub-agent cursors included, to read
302
+ * into. A caller keeps the cursor it has until what the copy read is stored, so
303
+ * a step that fails reads the same bytes again instead of losing them.
304
+ */
305
+ function cloneReaderCursor(cursor) {
306
+ const usageByMessage = new Map(cursor.usageByMessage ?? []), completed = new Set(cursor.completed ?? []);
307
+ const copy = (item) => ({
308
+ offset: item.offset, size: item.size, malformedLines: item.malformedLines, depthByUuid: new Map(item.depthByUuid),
309
+ usageVersion: item.usageVersion, usageByMessage, completed, ...(item.usage ? { usage: new Map(item.usage) } : {}),
310
+ ...(item.children ? { children: new Map([...item.children].map(([name, child]) => [name, copy(child)])) } : {})
311
+ });
312
+ return copy(cursor);
313
+ }
211
314
  /** Convenience for replay and tests: read a session and its own stored children. */
212
315
  function readAll(path) {
213
316
  const cursor = newCursor();
@@ -14,7 +14,7 @@
14
14
  * cannot fail closed if Claude Code times the hook out, so the hot path does
15
15
  * as little as possible.
16
16
  */
17
- import { type ReaderCursor, type UsageSnapshot } from '../history/claude-transcript';
17
+ import { type PersistedReaderCursor, type ReaderCursor } from '../history/claude-transcript';
18
18
  import type { BurnReport, Policy, SessionState } from '../types';
19
19
  export interface HookInput {
20
20
  hook_event_name?: string;
@@ -38,15 +38,7 @@ export interface HookOutput {
38
38
  permissionDecisionReason: string;
39
39
  };
40
40
  }
41
- export interface PersistedReaderCursor {
42
- offset: number;
43
- size: number;
44
- malformedLines: number;
45
- depthByUuid: [string, number][];
46
- usageVersion?: 1;
47
- usageByMessage?: [string, UsageSnapshot][];
48
- children?: [string, PersistedReaderCursor][];
49
- }
41
+ export type { PersistedReaderCursor };
50
42
  export interface PersistedSession {
51
43
  cursor: PersistedReaderCursor;
52
44
  state: Omit<SessionState, 'tokensByActiveMinute' | 'spawnsByActiveMinute' | 'surfaceReaders'> & {
@@ -42,6 +42,7 @@ const stop_text_1 = require("../stop-text");
42
42
  const node_os_1 = require("node:os");
43
43
  const live_1 = require("../insights/live");
44
44
  const hook_1 = require("../idle/hook");
45
+ const subagent_cost_1 = require("../subagent-cost");
45
46
  const SPAWN_TOOLS = new Set(['Agent', 'Task']);
46
47
  function sessionFile(home, sessionId) {
47
48
  return (0, node_path_1.join)(home, 'sessions', `${sessionId.replace(/[^a-zA-Z0-9_-]/g, '_')}.json`);
@@ -55,21 +56,10 @@ function inflateHookSession(raw) {
55
56
  surfaceReaders: new Map(raw.state.surfaceReaders.map(([k, v]) => [k, new Set(v)])),
56
57
  };
57
58
  }
58
- function inflateCursor(raw, shared) {
59
- const usageByMessage = shared ?? new Map(raw.usageByMessage ?? []);
60
- return { ...raw, depthByUuid: new Map(raw.depthByUuid), usageByMessage,
61
- children: new Map((raw.children ?? []).map(([name, child]) => [name, inflateCursor(child, usageByMessage)])) };
62
- }
63
- function persistCursor(cursor, child = false) {
64
- return { offset: cursor.offset, size: cursor.size, malformedLines: cursor.malformedLines, depthByUuid: [...cursor.depthByUuid],
65
- usageVersion: cursor.usageVersion,
66
- ...(!child ? { usageByMessage: [...(cursor.usageByMessage ?? [])] } : {}),
67
- ...(cursor.children?.size ? { children: [...cursor.children].map(([name, value]) => [name, persistCursor(value, true)]) } : {}) };
68
- }
69
59
  function loadSession(home, sessionId, firstEventAt) {
70
60
  try {
71
61
  const raw = JSON.parse((0, node_fs_1.readFileSync)(sessionFile(home, sessionId), 'utf8'));
72
- return { cursor: inflateCursor(raw.cursor), state: inflateHookSession(raw), notified: raw.notified ?? '', lastReceipt: raw.lastReceipt ?? null,
62
+ return { cursor: (0, claude_transcript_1.restoreReaderCursor)(raw.cursor), state: inflateHookSession(raw), notified: raw.notified ?? '', lastReceipt: raw.lastReceipt ?? null,
73
63
  fresh: false, needsRebuild: raw.cursor.usageVersion !== 1 || !Array.isArray(raw.cursor.usageByMessage) };
74
64
  }
75
65
  catch {
@@ -79,7 +69,7 @@ function loadSession(home, sessionId, firstEventAt) {
79
69
  function saveSession(home, cursor, state, notified, lastReceipt) {
80
70
  (0, node_fs_1.mkdirSync)((0, node_path_1.join)(home, 'sessions'), { recursive: true, mode: 0o700 });
81
71
  const persisted = {
82
- cursor: persistCursor(cursor),
72
+ cursor: (0, claude_transcript_1.saveReaderCursor)(cursor),
83
73
  state: {
84
74
  ...state,
85
75
  tokensByActiveMinute: [...state.tokensByActiveMinute],
@@ -204,7 +194,6 @@ function handleSpawnPreToolUse(input, home, now) {
204
194
  const proposedDepth = input.agent_id ? 2 : 1;
205
195
  const { report, reservation, window } = (0, spawn_window_1.evaluateSpawnReservation)(tx, state, policy.thresholds, proposedDepth, input.tool_use_id ?? `${input.session_id}:${now}`, now, { sessions: (0, account_1.readAccountSessions)(home, state, now), now });
206
196
  const shouldDeny = report.verdict === 'STOP' || !reservation.allowed;
207
- const reason = shouldDeny ? buildDenyReason(report, reservation) : '';
208
197
  // The audited override: only consulted when a block is about to happen.
209
198
  const override = shouldDeny && policy.mode === 'enforce' ? (0, override_1.consumeOverride)(home, now) : null;
210
199
  const blocked = policy.mode === 'enforce' && shouldDeny && !override;
@@ -244,12 +233,14 @@ function handleSpawnPreToolUse(input, home, now) {
244
233
  });
245
234
  if (shouldDeny && policy.mode === 'enforce') {
246
235
  if (!override) {
236
+ // The cost of one more sub-agent, at the decision: from the state just refreshed, never a transcript read.
237
+ const costLine = (0, subagent_cost_1.decisionCostLine)(refreshed.cursor, home, policy);
247
238
  if (asked) {
248
239
  (0, recording_1.recordFrame)({ kind: 'report', report, outcome: 'asked', host: 'claude-code' });
249
- return ask((0, stop_text_1.askReason)(report));
240
+ return ask((0, stop_text_1.askReason)(report, costLine));
250
241
  }
251
242
  (0, recording_1.recordFrame)({ kind: 'report', report, outcome: 'blocked', host: 'claude-code' });
252
- return deny(reason);
243
+ return deny(buildDenyReason(report, costLine));
253
244
  }
254
245
  (0, recording_1.recordFrame)({ kind: 'report', report, outcome: 'overridden', host: 'claude-code' });
255
246
  return { continue: true, systemMessage: (0, stop_text_1.overriddenLine)(report, override) };
@@ -274,12 +265,12 @@ function handleSpawnPreToolUse(input, home, now) {
274
265
  return policy.mode === 'enforce' ? deny(reason) : { continue: true, suppressOutput: true };
275
266
  }
276
267
  }
277
- function buildDenyReason(report, _reservation) {
268
+ function buildDenyReason(report, costLine) {
278
269
  // Claude Code shows this reason to the user. A box reads as an alarm; a
279
270
  // sentence reads as a log line. Colour is off: the host decides rendering.
280
271
  // Claude trims leading whitespace before adding Error:. A zero-width word
281
272
  // joiner preserves the blank first line, keeping that prefix off the frame.
282
- return '\u2060\n' + (0, render_1.renderStop)(report, { colour: false, host: 'claude-code' });
273
+ return '\u2060\n' + (0, render_1.renderStop)(report, { colour: false, host: 'claude-code', costLine });
283
274
  }
284
275
  const ASK_MODES = new Set(['default', 'acceptEdits', 'auto', 'plan']);
285
276
  /**
@@ -2,7 +2,10 @@ export * from './types';
2
2
  export { DEFAULT_POLICY, DEFAULT_THRESHOLDS, DEFAULT_LOCAL_COMPUTE, CALL_RESERVATION_TTL_MS } from './defaults';
3
3
  export { evaluate, fmt } from './detectors/evaluate';
4
4
  export { evaluateLocalCompute } from './detectors/local-compute';
5
- export { readIncremental, readAll, newCursor, normaliseLine, type ReaderCursor } from './history/claude-transcript';
5
+ export { readIncremental, readAll, newCursor, normaliseLine, readSessionIncremental, saveReaderCursor, restoreReaderCursor, cloneReaderCursor, type ReaderCursor, type PersistedReaderCursor, type ChildUsage, type UsageSnapshot } from './history/claude-transcript';
6
+ export { finishedSubagents, subagentCostLine, decisionCostLine, MIN_FINISHED_SUBAGENTS, type FinishedSubagents } from './subagent-cost';
7
+ export { sessionTip, type SessionTipOptions, type TipContext } from './insights/session-tip';
8
+ export { checkPolicyFile, type PolicyFileCheck, type PolicyFileProblem } from './policy';
6
9
  export { applyEvent, applyCorrection, newSessionState, windowSum, medianCompletedMinute, cacheReadRatio } from './state/session';
7
10
  export { ReservationStore, Transaction, RESERVATION_TTL_MS, type Reservation, type CallReservation, type ComputeSnapshot } from './state/reservations';
8
11
  export { replayAll, replaySession, replayEvents, discoverTranscripts, type ReplaySummary, type SessionReplay } from './replay/simulate';
package/dist/src/index.js CHANGED
@@ -14,8 +14,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.BurnStopError = exports.createRawApiGuard = exports.sha256 = exports.canonical = exports.receiptDigest = exports.verifyReceipt = exports.ReceiptSigner = exports.mergeCapabilities = exports.Gateway = exports.AGENT_OVERRIDE_REASON = exports.agentOverrideAttempt = exports.asksPerson = exports.settingsSnippet = exports.loadPolicy = exports.refreshSession = exports.handlePreToolUse = exports.calibrate = exports.OVERRIDE_COMMAND = exports.stopSummary = exports.sessionSoFar = exports.primarySummary = exports.overriddenLine = exports.continueLines = exports.askReason = exports.renderStop = exports.renderReplay = exports.discoverTranscripts = exports.replayEvents = exports.replaySession = exports.replayAll = exports.RESERVATION_TTL_MS = exports.Transaction = exports.ReservationStore = exports.cacheReadRatio = exports.medianCompletedMinute = exports.windowSum = exports.newSessionState = exports.applyCorrection = exports.applyEvent = exports.normaliseLine = exports.newCursor = exports.readAll = exports.readIncremental = exports.evaluateLocalCompute = exports.fmt = exports.evaluate = exports.CALL_RESERVATION_TTL_MS = exports.DEFAULT_LOCAL_COMPUTE = exports.DEFAULT_THRESHOLDS = exports.DEFAULT_POLICY = void 0;
18
- exports.inflateHookSession = exports.findingSignature = exports.renderHostHealth = exports.readHookSessions = exports.configPath = exports.health = exports.install = exports.OVERRIDE_WINDOW_MS = exports.clearOverride = exports.consumeOverride = exports.readOverride = exports.writeOverride = exports.runConformance = exports.renderMachineStatus = exports.UsageObserver = exports.profileFor = exports.startProxy = exports.CODEX_FORBIDDEN_FIELDS = exports.readCodexTranscriptUsage = exports.parseCodexTranscript = exports.codexHooksSnippet = exports.handleCodexHook = exports.cursorHooksSnippet = exports.handleCursorHook = void 0;
17
+ exports.agentOverrideAttempt = exports.asksPerson = exports.settingsSnippet = exports.loadPolicy = exports.refreshSession = exports.handlePreToolUse = exports.calibrate = exports.OVERRIDE_COMMAND = exports.stopSummary = exports.sessionSoFar = exports.primarySummary = exports.overriddenLine = exports.continueLines = exports.askReason = exports.renderStop = exports.renderReplay = exports.discoverTranscripts = exports.replayEvents = exports.replaySession = exports.replayAll = exports.RESERVATION_TTL_MS = exports.Transaction = exports.ReservationStore = exports.cacheReadRatio = exports.medianCompletedMinute = exports.windowSum = exports.newSessionState = exports.applyCorrection = exports.applyEvent = exports.checkPolicyFile = exports.sessionTip = exports.MIN_FINISHED_SUBAGENTS = exports.decisionCostLine = exports.subagentCostLine = exports.finishedSubagents = exports.cloneReaderCursor = exports.restoreReaderCursor = exports.saveReaderCursor = exports.readSessionIncremental = exports.normaliseLine = exports.newCursor = exports.readAll = exports.readIncremental = exports.evaluateLocalCompute = exports.fmt = exports.evaluate = exports.CALL_RESERVATION_TTL_MS = exports.DEFAULT_LOCAL_COMPUTE = exports.DEFAULT_THRESHOLDS = exports.DEFAULT_POLICY = void 0;
18
+ exports.inflateHookSession = exports.findingSignature = exports.renderHostHealth = exports.readHookSessions = exports.configPath = exports.health = exports.install = exports.OVERRIDE_WINDOW_MS = exports.clearOverride = exports.consumeOverride = exports.readOverride = exports.writeOverride = exports.runConformance = exports.renderMachineStatus = exports.UsageObserver = exports.profileFor = exports.startProxy = exports.CODEX_FORBIDDEN_FIELDS = exports.readCodexTranscriptUsage = exports.parseCodexTranscript = exports.codexHooksSnippet = exports.handleCodexHook = exports.cursorHooksSnippet = exports.handleCursorHook = exports.BurnStopError = exports.createRawApiGuard = exports.sha256 = exports.canonical = exports.receiptDigest = exports.verifyReceipt = exports.ReceiptSigner = exports.mergeCapabilities = exports.Gateway = exports.AGENT_OVERRIDE_REASON = void 0;
19
19
  __exportStar(require("./types"), exports);
20
20
  var defaults_1 = require("./defaults");
21
21
  Object.defineProperty(exports, "DEFAULT_POLICY", { enumerable: true, get: function () { return defaults_1.DEFAULT_POLICY; } });
@@ -32,6 +32,22 @@ Object.defineProperty(exports, "readIncremental", { enumerable: true, get: funct
32
32
  Object.defineProperty(exports, "readAll", { enumerable: true, get: function () { return claude_transcript_1.readAll; } });
33
33
  Object.defineProperty(exports, "newCursor", { enumerable: true, get: function () { return claude_transcript_1.newCursor; } });
34
34
  Object.defineProperty(exports, "normaliseLine", { enumerable: true, get: function () { return claude_transcript_1.normaliseLine; } });
35
+ Object.defineProperty(exports, "readSessionIncremental", { enumerable: true, get: function () { return claude_transcript_1.readSessionIncremental; } });
36
+ Object.defineProperty(exports, "saveReaderCursor", { enumerable: true, get: function () { return claude_transcript_1.saveReaderCursor; } });
37
+ Object.defineProperty(exports, "restoreReaderCursor", { enumerable: true, get: function () { return claude_transcript_1.restoreReaderCursor; } });
38
+ Object.defineProperty(exports, "cloneReaderCursor", { enumerable: true, get: function () { return claude_transcript_1.cloneReaderCursor; } });
39
+ // What another Claude Code hook needs for the same session totals and STOP line as Burn's own hook (0.3.21).
40
+ var subagent_cost_1 = require("./subagent-cost");
41
+ Object.defineProperty(exports, "finishedSubagents", { enumerable: true, get: function () { return subagent_cost_1.finishedSubagents; } });
42
+ Object.defineProperty(exports, "subagentCostLine", { enumerable: true, get: function () { return subagent_cost_1.subagentCostLine; } });
43
+ Object.defineProperty(exports, "decisionCostLine", { enumerable: true, get: function () { return subagent_cost_1.decisionCostLine; } });
44
+ Object.defineProperty(exports, "MIN_FINISHED_SUBAGENTS", { enumerable: true, get: function () { return subagent_cost_1.MIN_FINISHED_SUBAGENTS; } });
45
+ // The tip `why` ends with, for a session's transcript path, so a hook can show it when the next session starts (0.3.21).
46
+ var session_tip_1 = require("./insights/session-tip");
47
+ Object.defineProperty(exports, "sessionTip", { enumerable: true, get: function () { return session_tip_1.sessionTip; } });
48
+ // Whether burn-policy.json is missing, loaded or ignored, and the line that says why it was ignored (0.3.21).
49
+ var policy_1 = require("./policy");
50
+ Object.defineProperty(exports, "checkPolicyFile", { enumerable: true, get: function () { return policy_1.checkPolicyFile; } });
35
51
  var session_1 = require("./state/session");
36
52
  Object.defineProperty(exports, "applyEvent", { enumerable: true, get: function () { return session_1.applyEvent; } });
37
53
  Object.defineProperty(exports, "applyCorrection", { enumerable: true, get: function () { return session_1.applyCorrection; } });
@@ -0,0 +1,71 @@
1
+ /**
2
+ * The calendar's two faces from one layout. On a colour terminal each day is a
3
+ * coloured block on the canvas palette (teal by tokens, amber when sub-agents
4
+ * used more than half of the day's tokens, a red diamond on a day AgentGuard
5
+ * held a launch), drawn through the presentation path. Piped, with --no-color or
6
+ * NO_COLOR, each day is shade characters and the two kinds of marked day are
7
+ * letters, so nothing depends on colour.
8
+ *
9
+ * Two cell sizes. Big, whenever the span fits the width that way: two
10
+ * characters a day (▇▇ in colour, the shade pair such as ▓▓ in plain text) and
11
+ * one space between weeks, which reads as roughly square. Compact otherwise: one
12
+ * character a day and one space, as 0.3.20 drew every calendar. The span is
13
+ * chosen first (calendarReport) and never shrinks to make the cells bigger.
14
+ *
15
+ * A colour day is the lower seven-eighths block, not the full block: terminals
16
+ * draw █ to the full height of the line, so a week of full blocks joins into one
17
+ * bar, while ▇ leaves a thin gap above each day and the grid reads as squares.
18
+ */
19
+ import { Canvas, type CanvasColor } from '../canvas';
20
+ import { type CalendarReport } from './calendar';
21
+ import { type WhyLang } from './i18n';
22
+ import type { DollarRange } from './pricing';
23
+ export type CalendarSkin = 'plain' | 'colour';
24
+ /** `big`: two characters a day; `compact`: one. Both put one space between weeks. */
25
+ export type CalendarCells = 'big' | 'compact';
26
+ export interface CalendarSegment {
27
+ text: string;
28
+ color: CanvasColor;
29
+ }
30
+ export type CalendarLine = CalendarSegment[];
31
+ /** Levels 0 to 4, "Less" to "More". */
32
+ export declare const CALENDAR_SHADES: readonly ["·", "░", "▒", "▓", "█"];
33
+ /** The plain-text day letters, the same in every language: sub-agents used most of the day, and AgentGuard held a launch. */
34
+ export declare const CALENDAR_MARKERS: {
35
+ readonly subagents: "s";
36
+ readonly held: "H";
37
+ };
38
+ /**
39
+ * The grid's width at a cell size: the weekday labels and the week columns,
40
+ * without the last space. The labels count at their widest language, so a width
41
+ * picks the same cell size in every language.
42
+ */
43
+ export declare const calendarGridWidth: (weeks: number, cells: CalendarCells) => number;
44
+ /**
45
+ * Big cells whenever the span's weeks, and the Less to More scale under them,
46
+ * fit `columns` at two characters a day; compact otherwise, a `--weeks` span
47
+ * wider than the terminal included.
48
+ */
49
+ export declare const calendarCells: (weeks: number, columns: number) => CalendarCells;
50
+ /**
51
+ * The calendar's dollar total. Under $1,000 it prints as `why` prints dollars
52
+ * ($7.29, or $0.63 to $1.00). From $1,000, decided by the larger end, both ends
53
+ * are whole dollars with thousands separators ($28,252 to $28,254), and one
54
+ * number when both round to the same dollar. The calendar only: `why` keeps its
55
+ * cents.
56
+ */
57
+ export declare function calendarDollars(value: DollarRange, words: {
58
+ unpriced: string;
59
+ to: string;
60
+ }): string;
61
+ /** Greedy word wrap at `width`; a word is never split, and a word wider than the line stands alone. */
62
+ export declare function wrap(text: string, width: number, indent?: string): string[];
63
+ /**
64
+ * The report line by line. `columns` wraps the text lines and picks the cell
65
+ * size (calendarCells); the span was already chosen to fit it.
66
+ */
67
+ export declare function calendarLines(report: CalendarReport, lang: WhyLang, columns: number, skin: CalendarSkin): CalendarLine[];
68
+ /** Plain text: shade characters and day letters, no control sequences, trailing spaces trimmed. */
69
+ export declare function renderCalendar(report: CalendarReport, lang?: WhyLang, columns?: number): string;
70
+ /** The colour face on a canvas sized to the report, never paged: a calendar is one block. */
71
+ export declare function drawCalendar(report: CalendarReport, lang?: WhyLang, columns?: number, colour?: boolean): Canvas;