@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.
- package/CHANGELOG.md +41 -0
- package/README.md +63 -2
- package/dist/src/canvas.d.ts +7 -1
- package/dist/src/canvas.js +10 -1
- package/dist/src/cli.js +70 -6
- package/dist/src/frames.d.ts +10 -0
- package/dist/src/frames.js +5 -0
- package/dist/src/gateway.js +11 -7
- package/dist/src/history/claude-transcript.d.ts +63 -1
- package/dist/src/history/claude-transcript.js +105 -2
- package/dist/src/hook/pre-tool-use.d.ts +2 -10
- package/dist/src/hook/pre-tool-use.js +9 -18
- package/dist/src/index.d.ts +4 -1
- package/dist/src/index.js +18 -2
- package/dist/src/insights/calendar-render.d.ts +71 -0
- package/dist/src/insights/calendar-render.js +251 -0
- package/dist/src/insights/calendar.d.ts +138 -0
- package/dist/src/insights/calendar.js +431 -0
- package/dist/src/insights/i18n.d.ts +103 -6
- package/dist/src/insights/i18n.js +123 -7
- package/dist/src/insights/render.d.ts +85 -12
- package/dist/src/insights/render.js +207 -17
- package/dist/src/insights/session-tip.d.ts +33 -0
- package/dist/src/insights/session-tip.js +32 -0
- package/dist/src/insights/sessions.d.ts +6 -0
- package/dist/src/insights/sessions.js +15 -4
- package/dist/src/insights/transcript.d.ts +13 -2
- package/dist/src/insights/transcript.js +61 -6
- package/dist/src/insights/types.d.ts +14 -0
- package/dist/src/policy.d.ts +25 -0
- package/dist/src/policy.js +82 -9
- package/dist/src/recording.js +5 -1
- package/dist/src/replay/render.d.ts +2 -0
- package/dist/src/replay/render.js +4 -0
- package/dist/src/stop-text.d.ts +11 -2
- package/dist/src/stop-text.js +23 -3
- package/dist/src/subagent-cost.d.ts +49 -0
- package/dist/src/subagent-cost.js +90 -0
- package/package.json +5 -1
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.calendarCells = exports.calendarGridWidth = exports.CALENDAR_MARKERS = exports.CALENDAR_SHADES = void 0;
|
|
4
|
+
exports.calendarDollars = calendarDollars;
|
|
5
|
+
exports.wrap = wrap;
|
|
6
|
+
exports.calendarLines = calendarLines;
|
|
7
|
+
exports.renderCalendar = renderCalendar;
|
|
8
|
+
exports.drawCalendar = drawCalendar;
|
|
9
|
+
/**
|
|
10
|
+
* The calendar's two faces from one layout. On a colour terminal each day is a
|
|
11
|
+
* coloured block on the canvas palette (teal by tokens, amber when sub-agents
|
|
12
|
+
* used more than half of the day's tokens, a red diamond on a day AgentGuard
|
|
13
|
+
* held a launch), drawn through the presentation path. Piped, with --no-color or
|
|
14
|
+
* NO_COLOR, each day is shade characters and the two kinds of marked day are
|
|
15
|
+
* letters, so nothing depends on colour.
|
|
16
|
+
*
|
|
17
|
+
* Two cell sizes. Big, whenever the span fits the width that way: two
|
|
18
|
+
* characters a day (▇▇ in colour, the shade pair such as ▓▓ in plain text) and
|
|
19
|
+
* one space between weeks, which reads as roughly square. Compact otherwise: one
|
|
20
|
+
* character a day and one space, as 0.3.20 drew every calendar. The span is
|
|
21
|
+
* chosen first (calendarReport) and never shrinks to make the cells bigger.
|
|
22
|
+
*
|
|
23
|
+
* A colour day is the lower seven-eighths block, not the full block: terminals
|
|
24
|
+
* draw █ to the full height of the line, so a week of full blocks joins into one
|
|
25
|
+
* bar, while ▇ leaves a thin gap above each day and the grid reads as squares.
|
|
26
|
+
*/
|
|
27
|
+
const canvas_1 = require("../canvas");
|
|
28
|
+
const calendar_1 = require("./calendar");
|
|
29
|
+
const i18n_1 = require("./i18n");
|
|
30
|
+
const live_1 = require("./live");
|
|
31
|
+
const render_1 = require("./render");
|
|
32
|
+
/** Levels 0 to 4, "Less" to "More". */
|
|
33
|
+
exports.CALENDAR_SHADES = ['·', '░', '▒', '▓', '█'];
|
|
34
|
+
/** The plain-text day letters, the same in every language: sub-agents used most of the day, and AgentGuard held a launch. */
|
|
35
|
+
exports.CALENDAR_MARKERS = { subagents: 's', held: 'H' };
|
|
36
|
+
/** A compact colour day; half of a big colour day (see above); a held day's mark. */
|
|
37
|
+
const SQUARE = '■', BLOCK = '▇', DIAMOND = '◆';
|
|
38
|
+
const TEAL = ['shade0', 'teal1', 'teal2', 'teal3', 'teal4'];
|
|
39
|
+
const AMBER = ['shade0', 'amber1', 'amber2', 'amber3', 'amber4'];
|
|
40
|
+
/** Columns per week: the day's characters and one space. */
|
|
41
|
+
const WEEK_COLUMNS = { big: 3, compact: 2 };
|
|
42
|
+
/**
|
|
43
|
+
* The grid's width at a cell size: the weekday labels and the week columns,
|
|
44
|
+
* without the last space. The labels count at their widest language, so a width
|
|
45
|
+
* picks the same cell size in every language.
|
|
46
|
+
*/
|
|
47
|
+
const calendarGridWidth = (weeks, cells) => calendar_1.CALENDAR_GRID_PREFIX + WEEK_COLUMNS[cells] * weeks - 1;
|
|
48
|
+
exports.calendarGridWidth = calendarGridWidth;
|
|
49
|
+
/** "Less ·· ░░ ▒▒ ▓▓ ██ More" in the widest language: five two-character swatches and six spaces. */
|
|
50
|
+
const BIG_SCALE_WIDTH = Math.max(...Object.values(i18n_1.CALENDAR_TEXT).map(text => text.less.length + text.more.length + 16));
|
|
51
|
+
/**
|
|
52
|
+
* Big cells whenever the span's weeks, and the Less to More scale under them,
|
|
53
|
+
* fit `columns` at two characters a day; compact otherwise, a `--weeks` span
|
|
54
|
+
* wider than the terminal included.
|
|
55
|
+
*/
|
|
56
|
+
const calendarCells = (weeks, columns) => Math.max((0, exports.calendarGridWidth)(weeks, 'big'), BIG_SCALE_WIDTH) <= columns ? 'big' : 'compact';
|
|
57
|
+
exports.calendarCells = calendarCells;
|
|
58
|
+
const segment = (text, color = 'none') => ({ text, color });
|
|
59
|
+
const dateOf = (day, text) => ({ month: text.months[Number(day.slice(5, 7)) - 1], day: Number(day.slice(8, 10)), year: Number(day.slice(0, 4)) });
|
|
60
|
+
/**
|
|
61
|
+
* One day's cell and the marks it shows. Compact: the level's shade or square,
|
|
62
|
+
* or on a marked day the mark alone, the held mark winning over amber. Big: the
|
|
63
|
+
* left half always shows the level (amber on a sub-agent day, in colour), and
|
|
64
|
+
* the right half repeats it or carries the day's mark (`s` or `H` in plain text,
|
|
65
|
+
* the red diamond in colour), so a marked day keeps its shade. A day before the
|
|
66
|
+
* first record, or after today, is blank unless AgentGuard held a launch on it.
|
|
67
|
+
*/
|
|
68
|
+
function cell(day, skin, cells) {
|
|
69
|
+
const level = day?.level ?? null, held = (day?.heldLaunches ?? 0) > 0, amber = level !== null && day.subagentsOverHalf;
|
|
70
|
+
if (level === null && !held)
|
|
71
|
+
return { parts: [segment(cells === 'big' ? ' ' : ' ')], marks: [] };
|
|
72
|
+
const heldMark = skin === 'plain' ? segment(exports.CALENDAR_MARKERS.held) : segment(DIAMOND, 'red');
|
|
73
|
+
const colours = amber ? AMBER : TEAL, marks = held ? ['held'] : amber ? ['subagents'] : [];
|
|
74
|
+
if (cells === 'compact') {
|
|
75
|
+
if (held)
|
|
76
|
+
return { parts: [heldMark], marks };
|
|
77
|
+
return { parts: [skin === 'plain' ? segment(amber ? exports.CALENDAR_MARKERS.subagents : exports.CALENDAR_SHADES[level]) : segment(SQUARE, colours[level])], marks };
|
|
78
|
+
}
|
|
79
|
+
if (skin === 'plain') {
|
|
80
|
+
const shade = level === null ? ' ' : exports.CALENDAR_SHADES[level];
|
|
81
|
+
return { parts: [segment(shade + (held ? exports.CALENDAR_MARKERS.held : amber ? exports.CALENDAR_MARKERS.subagents : shade))], marks };
|
|
82
|
+
}
|
|
83
|
+
if (!held)
|
|
84
|
+
return { parts: [segment(BLOCK + BLOCK, colours[level])], marks };
|
|
85
|
+
// A held day in colour: its level's block, then the red diamond. An amber left half shows amber too.
|
|
86
|
+
return { parts: [level === null ? segment(' ') : segment(BLOCK, colours[level]), heldMark], marks: amber ? ['subagents', 'held'] : marks };
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* The calendar's dollar total. Under $1,000 it prints as `why` prints dollars
|
|
90
|
+
* ($7.29, or $0.63 to $1.00). From $1,000, decided by the larger end, both ends
|
|
91
|
+
* are whole dollars with thousands separators ($28,252 to $28,254), and one
|
|
92
|
+
* number when both round to the same dollar. The calendar only: `why` keeps its
|
|
93
|
+
* cents.
|
|
94
|
+
*/
|
|
95
|
+
function calendarDollars(value, words) {
|
|
96
|
+
if (Math.round(Math.max(value.min, value.max) * 100) < 100_000)
|
|
97
|
+
return (0, live_1.dollars)(value, words);
|
|
98
|
+
const low = Math.round(value.min), high = Math.round(value.max);
|
|
99
|
+
return low === high ? `$${(0, render_1.count)(low)}` : `$${(0, render_1.count)(low)} ${words.to} $${(0, render_1.count)(high)}`;
|
|
100
|
+
}
|
|
101
|
+
/** Greedy word wrap at `width`; a word is never split, and a word wider than the line stands alone. */
|
|
102
|
+
function wrap(text, width, indent = '') {
|
|
103
|
+
const lines = [];
|
|
104
|
+
let line = '';
|
|
105
|
+
for (const word of text.split(' ')) {
|
|
106
|
+
if (!line)
|
|
107
|
+
line = word;
|
|
108
|
+
else if (line.length + 1 + word.length <= width)
|
|
109
|
+
line += ` ${word}`;
|
|
110
|
+
else {
|
|
111
|
+
lines.push(line);
|
|
112
|
+
line = indent + word;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
if (line)
|
|
116
|
+
lines.push(line);
|
|
117
|
+
return lines;
|
|
118
|
+
}
|
|
119
|
+
/** Summary items joined with " · ", a new line before an item that would pass the width. */
|
|
120
|
+
function joinItems(items, width) {
|
|
121
|
+
const lines = [];
|
|
122
|
+
let line = '';
|
|
123
|
+
for (const item of items) {
|
|
124
|
+
if (!line)
|
|
125
|
+
line = item;
|
|
126
|
+
else if (line.length + 3 + item.length <= width)
|
|
127
|
+
line += ` · ${item}`;
|
|
128
|
+
else {
|
|
129
|
+
lines.push(line);
|
|
130
|
+
line = item;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (line)
|
|
134
|
+
lines.push(line);
|
|
135
|
+
return lines.flatMap(value => wrap(value, width));
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* The report line by line. `columns` wraps the text lines and picks the cell
|
|
139
|
+
* size (calendarCells); the span was already chosen to fit it.
|
|
140
|
+
*/
|
|
141
|
+
function calendarLines(report, lang, columns, skin) {
|
|
142
|
+
const text = i18n_1.CALENDAR_TEXT[lang], words = i18n_1.WHY_TEXT[lang], width = Math.max(20, Math.floor(columns));
|
|
143
|
+
const lines = [];
|
|
144
|
+
const paragraph = (value, color, indent = '') => { for (const line of wrap(value, width, indent))
|
|
145
|
+
lines.push([segment(line, color)]); };
|
|
146
|
+
paragraph(text.title(text.span(dateOf(report.from, text), dateOf(report.to, text))), 'mint');
|
|
147
|
+
if (report.firstRecordedDay === null) {
|
|
148
|
+
paragraph(text.noData, 'white');
|
|
149
|
+
return lines;
|
|
150
|
+
}
|
|
151
|
+
// The summary in short lines: tokens and dollars; the busiest day and the
|
|
152
|
+
// sub-agent share; the launches AgentGuard held, when there were any. Two items
|
|
153
|
+
// share a line only when both fit the width; no line takes an item from another.
|
|
154
|
+
const totals = report.totals, spansYears = report.from.slice(0, 4) !== report.to.slice(0, 4);
|
|
155
|
+
const summary = [
|
|
156
|
+
[text.tokens((0, render_1.count)(totals.tokens)), text.dollars(totals.usd === null ? null : calendarDollars(totals.usd, words))],
|
|
157
|
+
[...(report.busiest ? [text.busiest(text.date(dateOf(report.busiest.date, text), spansYears), (0, render_1.count)(report.busiest.tokens))] : []),
|
|
158
|
+
text.subagents((0, render_1.share)(totals.subagentTokens, totals.tokens))],
|
|
159
|
+
totals.heldLaunches > 0 ? [text.held(totals.heldLaunches)] : [],
|
|
160
|
+
];
|
|
161
|
+
for (const items of summary)
|
|
162
|
+
for (const line of joinItems(items, width))
|
|
163
|
+
lines.push([segment(line, 'white')]);
|
|
164
|
+
lines.push([]);
|
|
165
|
+
const cells = (0, exports.calendarCells)(report.weeks, columns), step = WEEK_COLUMNS[cells];
|
|
166
|
+
const labelWidth = Math.max(...text.weekdays.map(label => label.length)) + 1;
|
|
167
|
+
// Month names above the first week whose Sunday falls in that month. The first
|
|
168
|
+
// column is named too unless the next name starts before it ends. A name that
|
|
169
|
+
// would run past the width (or past the grid, when a --weeks grid is wider) is
|
|
170
|
+
// left out: it would wrap the whole row.
|
|
171
|
+
const limit = Math.max(width, labelWidth + step * report.weeks - 1);
|
|
172
|
+
const months = [];
|
|
173
|
+
for (let week = 0; week < report.weeks; week++) {
|
|
174
|
+
const sunday = (0, calendar_1.addDays)(report.from, 7 * week);
|
|
175
|
+
if (week === 0 || sunday.slice(0, 7) !== (0, calendar_1.addDays)(sunday, -7).slice(0, 7))
|
|
176
|
+
months.push({ x: labelWidth + step * week, name: text.months[Number(sunday.slice(5, 7)) - 1] });
|
|
177
|
+
}
|
|
178
|
+
if (months.length > 1 && months[1].x < months[0].x + months[0].name.length + 1)
|
|
179
|
+
months.shift();
|
|
180
|
+
const monthRow = [];
|
|
181
|
+
let x = 0;
|
|
182
|
+
for (const month of months.filter(label => label.x + label.name.length <= limit)) {
|
|
183
|
+
monthRow.push(segment(' '.repeat(month.x - x)), segment(month.name, 'slate'));
|
|
184
|
+
x = month.x + month.name.length;
|
|
185
|
+
}
|
|
186
|
+
lines.push(monthRow);
|
|
187
|
+
const marked = new Set();
|
|
188
|
+
for (let weekday = 0; weekday < 7; weekday++) {
|
|
189
|
+
const row = [segment(text.weekdays[weekday].padEnd(labelWidth), 'slate')];
|
|
190
|
+
for (let week = 0; week < report.weeks; week++) {
|
|
191
|
+
const drawn = cell(report.days[7 * week + weekday], skin, cells);
|
|
192
|
+
for (const mark of drawn.marks)
|
|
193
|
+
marked.add(mark);
|
|
194
|
+
row.push(...drawn.parts, segment(' '));
|
|
195
|
+
}
|
|
196
|
+
lines.push(row);
|
|
197
|
+
}
|
|
198
|
+
lines.push([]);
|
|
199
|
+
// The Less to More scale in the cells the grid uses.
|
|
200
|
+
const swatch = cells === 'big' ? BLOCK + BLOCK : SQUARE;
|
|
201
|
+
lines.push(skin === 'plain'
|
|
202
|
+
? [segment(`${text.less} ${exports.CALENDAR_SHADES.map(shade => cells === 'big' ? shade + shade : shade).join(' ')} ${text.more}`)]
|
|
203
|
+
: [segment(text.less, 'slate'), ...TEAL.flatMap(color => [segment(' '), segment(swatch, color)]), segment(' '), segment(text.more, 'slate')]);
|
|
204
|
+
// A colour screen shows the mark beside its sentence, where it sits in a day
|
|
205
|
+
// (the diamond is a big day's right half); plain text names the letter.
|
|
206
|
+
const legend = (mark, glyph, sentences) => {
|
|
207
|
+
if (!marked.has(mark))
|
|
208
|
+
return;
|
|
209
|
+
if (skin === 'plain') {
|
|
210
|
+
paragraph(sentences.plain(exports.CALENDAR_MARKERS[mark]), 'none');
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
const indent = ' '.repeat(glyph.reduce((sum, part) => sum + part.text.length, 0) + 1);
|
|
214
|
+
const [head = '', ...rest] = wrap(sentences.colour, width - indent.length);
|
|
215
|
+
lines.push([...glyph, segment(` ${head}`, 'slate')]);
|
|
216
|
+
for (const line of rest)
|
|
217
|
+
lines.push([segment(`${indent}${line}`, 'slate')]);
|
|
218
|
+
};
|
|
219
|
+
legend('subagents', [segment(swatch, 'amber4')], text.subagentDays);
|
|
220
|
+
legend('held', cells === 'big' ? [segment(' '), segment(DIAMOND, 'red')] : [segment(DIAMOND, 'red')], text.heldDays);
|
|
221
|
+
if (totals.claudeTokens > 0 || totals.codexTokens > 0)
|
|
222
|
+
paragraph(text.sources(totals.claudeTokens > 0, totals.codexTokens > 0), 'slate');
|
|
223
|
+
if (totals.unpricedTokens > 0)
|
|
224
|
+
paragraph(text.unpriced((0, render_1.count)(totals.unpricedTokens), totals.unpricedModels.map(model => model ?? words.missingModel).join(', ')), 'slate');
|
|
225
|
+
if (report.sources.forkBoundaryUnknown > 0)
|
|
226
|
+
paragraph(text.forkUnknown(report.sources.forkBoundaryUnknown), 'slate');
|
|
227
|
+
if (report.sources.unreadable > 0)
|
|
228
|
+
paragraph(text.unreadable(report.sources.unreadable), 'slate');
|
|
229
|
+
if (report.historyShort)
|
|
230
|
+
for (const sentence of text.shortHistory)
|
|
231
|
+
paragraph(sentence, 'slate');
|
|
232
|
+
return lines;
|
|
233
|
+
}
|
|
234
|
+
/** Plain text: shade characters and day letters, no control sequences, trailing spaces trimmed. */
|
|
235
|
+
function renderCalendar(report, lang = 'en', columns = 80) {
|
|
236
|
+
return calendarLines(report, lang, columns, 'plain').map(line => line.map(part => part.text).join('').trimEnd()).join('\n');
|
|
237
|
+
}
|
|
238
|
+
/** The colour face on a canvas sized to the report, never paged: a calendar is one block. */
|
|
239
|
+
function drawCalendar(report, lang = 'en', columns = 80, colour) {
|
|
240
|
+
const lines = calendarLines(report, lang, columns, 'colour');
|
|
241
|
+
const width = Math.max(1, ...lines.map(line => line.reduce((sum, part) => sum + part.text.length, 0)));
|
|
242
|
+
const canvas = new canvas_1.Canvas({ width, height: Math.max(1, lines.length), ...(colour === undefined ? {} : { colour }) });
|
|
243
|
+
lines.forEach((line, row) => {
|
|
244
|
+
let column = 0;
|
|
245
|
+
for (const part of line) {
|
|
246
|
+
canvas.put(row, column, part.text, part.color);
|
|
247
|
+
column += part.text.length;
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
return canvas;
|
|
251
|
+
}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { type DollarRange, type PricingTable } from './pricing';
|
|
2
|
+
/** A span of at most 53 weeks: a year of Sundays plus the week in progress. */
|
|
3
|
+
export declare const CALENDAR_MAX_WEEKS = 53;
|
|
4
|
+
/**
|
|
5
|
+
* Weekday labels plus one space, in the widest language, so the span a width
|
|
6
|
+
* allows, and so `calendar json`, is the same in every language.
|
|
7
|
+
*/
|
|
8
|
+
export declare const CALENDAR_GRID_PREFIX: number;
|
|
9
|
+
/** The local calendar day of an instant, YYYY-MM-DD, in this process's time zone. */
|
|
10
|
+
export declare function localDay(at: number): string;
|
|
11
|
+
/** Days since the epoch for a YYYY-MM-DD date: date arithmetic without clock time or daylight saving. */
|
|
12
|
+
export declare const dayNumber: (day: string) => number;
|
|
13
|
+
export declare const addDays: (day: string, days: number) => string;
|
|
14
|
+
/** 0 is Sunday. */
|
|
15
|
+
export declare const weekdayOf: (day: string) => number;
|
|
16
|
+
/** One file's measured figures for one day. */
|
|
17
|
+
export interface CalendarFigures {
|
|
18
|
+
tokens: number;
|
|
19
|
+
/** Every token of the responses sub-agents recorded (input, cache and output), sub-agent transcripts being what `why` reads as child transcripts. */
|
|
20
|
+
subagentTokens: number;
|
|
21
|
+
/** API list price of the tokens whose model has a verified rate. */
|
|
22
|
+
usd: DollarRange;
|
|
23
|
+
/** Tokens on models without a verified rate; not in `usd`. */
|
|
24
|
+
unpricedTokens: number;
|
|
25
|
+
/** Those models; null is a response without a model id. */
|
|
26
|
+
unpricedModels: Array<string | null>;
|
|
27
|
+
}
|
|
28
|
+
export interface CalendarDayData extends CalendarFigures {
|
|
29
|
+
claudeTokens: number;
|
|
30
|
+
codexTokens: number;
|
|
31
|
+
}
|
|
32
|
+
export interface CalendarSources {
|
|
33
|
+
/** Transcript files read this run, from the cache or from disk. */
|
|
34
|
+
transcripts: number;
|
|
35
|
+
/** Files whose transcript is gone and whose days come from the daily count. */
|
|
36
|
+
rollupFiles: number;
|
|
37
|
+
/** Codex forks whose inherited history has no verifiable boundary; `why` reports their usage unavailable, so none of it is counted. */
|
|
38
|
+
forkBoundaryUnknown: number;
|
|
39
|
+
/** Transcripts that could not be read this run; any earlier daily count of theirs is kept. */
|
|
40
|
+
unreadable: number;
|
|
41
|
+
/** Tokens on responses without a recorded time, which no day can hold. */
|
|
42
|
+
undatedTokens: number;
|
|
43
|
+
}
|
|
44
|
+
export interface CalendarData {
|
|
45
|
+
days: Map<string, CalendarDayData>;
|
|
46
|
+
/** Sub-agent launches AgentGuard held per day: refused by an enforced STOP, or held for the person's yes (`asked: true`). */
|
|
47
|
+
heldLaunches: Map<string, number>;
|
|
48
|
+
/** The oldest day with tokens, from transcripts or the daily count. */
|
|
49
|
+
firstDay: string | null;
|
|
50
|
+
claudeSeen: boolean;
|
|
51
|
+
sources: CalendarSources;
|
|
52
|
+
/** False when the daily count could not be written. */
|
|
53
|
+
saved: boolean;
|
|
54
|
+
}
|
|
55
|
+
export declare const calendarDirectory: (home: string) => string;
|
|
56
|
+
export declare const rollupPath: (home: string) => string;
|
|
57
|
+
export declare const cachePath: (home: string) => string;
|
|
58
|
+
export interface CalendarCollectOptions {
|
|
59
|
+
/** The Burn home (AGENTGUARD_HOME). */
|
|
60
|
+
home: string;
|
|
61
|
+
roots?: {
|
|
62
|
+
claude: string;
|
|
63
|
+
codex: string;
|
|
64
|
+
};
|
|
65
|
+
rates?: PricingTable;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Reads every local transcript (from the cache when unchanged), merges the daily
|
|
69
|
+
* count of files that are gone, writes both back, and reads the ledger.
|
|
70
|
+
*/
|
|
71
|
+
export declare function collectCalendar(options: CalendarCollectOptions): CalendarData;
|
|
72
|
+
export type CalendarLevel = 0 | 1 | 2 | 3 | 4;
|
|
73
|
+
export interface CalendarDay {
|
|
74
|
+
/** YYYY-MM-DD, local time. */
|
|
75
|
+
date: string;
|
|
76
|
+
/** False before the first recorded day, where no transcript or daily count covers the day. */
|
|
77
|
+
recorded: boolean;
|
|
78
|
+
tokens: number;
|
|
79
|
+
/** Tokens of responses sub-agents recorded. */
|
|
80
|
+
subagentTokens: number;
|
|
81
|
+
/** API list price of the day's priced tokens. */
|
|
82
|
+
usd: DollarRange;
|
|
83
|
+
unpricedTokens: number;
|
|
84
|
+
claudeTokens: number;
|
|
85
|
+
codexTokens: number;
|
|
86
|
+
/** 0 without tokens; 1 to 4 by the quarter of the shown days with tokens this day reaches; null when not recorded. */
|
|
87
|
+
level: CalendarLevel | null;
|
|
88
|
+
/** Sub-agents recorded more than half of the day's tokens: drawn in amber. */
|
|
89
|
+
subagentsOverHalf: boolean;
|
|
90
|
+
/** Sub-agent launches AgentGuard held that day: drawn with the red mark. */
|
|
91
|
+
heldLaunches: number;
|
|
92
|
+
}
|
|
93
|
+
export interface CalendarTotals {
|
|
94
|
+
tokens: number;
|
|
95
|
+
subagentTokens: number;
|
|
96
|
+
/** Sub-agent tokens over all tokens, 0 to 1; null without tokens. */
|
|
97
|
+
subagentShare: number | null;
|
|
98
|
+
/** API list price of the priced tokens; null when there are tokens and none is priced. */
|
|
99
|
+
usd: DollarRange | null;
|
|
100
|
+
unpricedTokens: number;
|
|
101
|
+
unpricedModels: Array<string | null>;
|
|
102
|
+
heldLaunches: number;
|
|
103
|
+
claudeTokens: number;
|
|
104
|
+
codexTokens: number;
|
|
105
|
+
}
|
|
106
|
+
export interface CalendarReport {
|
|
107
|
+
/** The Sunday that starts the first week shown. */
|
|
108
|
+
from: string;
|
|
109
|
+
/** Today. */
|
|
110
|
+
to: string;
|
|
111
|
+
weeks: number;
|
|
112
|
+
firstRecordedDay: string | null;
|
|
113
|
+
/** Every day from `from` to `to`. */
|
|
114
|
+
days: CalendarDay[];
|
|
115
|
+
totals: CalendarTotals;
|
|
116
|
+
/** The shown day with the most tokens, the first of equal days. */
|
|
117
|
+
busiest: {
|
|
118
|
+
date: string;
|
|
119
|
+
tokens: number;
|
|
120
|
+
} | null;
|
|
121
|
+
/** The recorded history is shorter than the calendar could show, and Claude Code transcripts are in it. */
|
|
122
|
+
historyShort: boolean;
|
|
123
|
+
sources: CalendarSources;
|
|
124
|
+
subagentsIncluded: true;
|
|
125
|
+
basis: 'estimated_api_list_price';
|
|
126
|
+
}
|
|
127
|
+
export interface CalendarReportOptions {
|
|
128
|
+
now?: number;
|
|
129
|
+
/** An exact span, 1 to 53 weeks ending with the current week. */
|
|
130
|
+
weeks?: number;
|
|
131
|
+
/** Output width: without `weeks`, the span runs from the oldest recorded day, capped to the weeks that fit. */
|
|
132
|
+
columns?: number;
|
|
133
|
+
}
|
|
134
|
+
/** Weeks of two columns each that fit beside the weekday labels in `columns`, 1 to 53. */
|
|
135
|
+
export declare const weeksThatFit: (columns: number) => number;
|
|
136
|
+
/** A day's shade: the quarter of the shown days with tokens that it reaches, so the busiest shown day is always level 4. */
|
|
137
|
+
export declare function calendarLevels(values: number[]): (tokens: number) => CalendarLevel;
|
|
138
|
+
export declare function calendarReport(data: CalendarData, options?: CalendarReportOptions): CalendarReport;
|