@agentguard-run/burn 0.3.24 → 0.3.25

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 CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.25 (2026-10-01)
4
+
5
+ - `card` draws the calendar's totals as one 1200 by 675 PNG to post: tokens with the Claude Code and Codex split, dollars at API list price (not a bill), the sub-agent share, the busiest day, the launches AgentGuard held, and one bar per day in whole weeks. `--weeks N` (1 to 53, default 4) and `--out file.png` (default `agentguard-burn-card.png`). It is drawn locally from the figures `calendar` prints; no project, prompt or file name appears on it, and nothing is uploaded.
6
+
3
7
  ## 0.3.24 (2026-09-29)
4
8
 
5
9
  - `calendar` ends with one next step, so it never stops at a number with nothing to do about it. The rule is the one `why` uses for its tip: sub-agents at a fifth or more of the tokens point at the free plugin, or at giving related work to one sub-agent once AgentGuard has held launches on this machine; anything else points at `why`, which names the change for one session. In English, Spanish and Portuguese, and short enough that the command never wraps at 80 columns.
package/README.md CHANGED
@@ -324,6 +324,15 @@ Claude Code deletes transcripts after 30 days by default (`cleanupPeriodDays`),
324
324
 
325
325
  `calendar json` is never translated: every day of the span with its figures and level, the totals, the busiest day and where the figures came from. `--lang es|pt` and your locale choose the language exactly as for `why`. Nothing in the calendar compares you with anyone else.
326
326
 
327
+ ## Share card
328
+
329
+ ```sh
330
+ agentguard-burn card
331
+ agentguard-burn card --weeks 1 --out this-week.png
332
+ ```
333
+
334
+ One 1200 by 675 PNG with the calendar's totals, made to post: the token total with the Claude Code and Codex split, the dollars at API prices (not a bill), the share sub-agents used, the busiest day, the sub-agent launches AgentGuard held (or the transcripts read, when it held none) and one bar per day in whole weeks. `--weeks N` takes 1 to 53 and defaults to 4. The image is saved as `agentguard-burn-card.png` in the current folder unless `--out` names another file. It is drawn on your machine from the same figures `calendar` prints; no project, prompt or file name appears on it, and nothing is uploaded. A span with no recorded usage is refused.
335
+
327
336
  ## Two safety planes
328
337
 
329
338
  Structural limits use active time rather than the age of the session. The
package/dist/src/cli.js CHANGED
@@ -311,6 +311,38 @@ async function main(argv) {
311
311
  show({ kind: 'calendar', report, lang: language, columns }, json ? JSON.stringify(report, null, 2) + '\n' : renderCalendar(report, language, columns) + '\n', json);
312
312
  return 0;
313
313
  }
314
+ case 'card': {
315
+ // `--weeks N` (1 to 53, default 4, also --weeks=N) and `--out file.png` (default agentguard-burn-card.png here).
316
+ let weeksText, out = 'agentguard-burn-card.png', bad = false;
317
+ for (let i = 0; i < rest.length; i++) {
318
+ if (rest[i] === '--weeks')
319
+ weeksText = rest[++i];
320
+ else if (rest[i].startsWith('--weeks='))
321
+ weeksText = rest[i].slice('--weeks='.length);
322
+ else if (rest[i] === '--out')
323
+ out = rest[++i] ?? '';
324
+ else if (rest[i].startsWith('--out='))
325
+ out = rest[i].slice('--out='.length);
326
+ else
327
+ bad = true;
328
+ }
329
+ const weeks = weeksText === undefined ? 4 : /^\d{1,2}$/.test(weeksText) ? Number(weeksText) : 0;
330
+ if (bad || !(weeks >= 1 && weeks <= 53) || !out.trim()) {
331
+ process.stderr.write('Usage: agentguard-burn card [--weeks N] [--out file.png]\n');
332
+ return 64;
333
+ }
334
+ const { calendarReport, collectCalendar } = await Promise.resolve().then(() => __importStar(require('./insights/calendar')));
335
+ const { cardModel, renderCard } = await Promise.resolve().then(() => __importStar(require('./insights/card')));
336
+ const data = collectCalendar({ home: HOME, rates: (0, live_1.readPricing)(HOME, (0, pre_tool_use_1.loadPolicy)(HOME)) });
337
+ const report = calendarReport(data, { now: Date.now(), weeks });
338
+ if (!(report.totals.tokens > 0)) {
339
+ process.stderr.write('No Claude Code or Codex usage is recorded on this machine for that span, so there is nothing to put on a card.\n');
340
+ return 1;
341
+ }
342
+ (0, node_fs_1.writeFileSync)(out, await renderCard(cardModel(report)));
343
+ process.stdout.write(`Card saved: ${out} (1200x675). Dollars on it are API list prices, not a bill; nothing was uploaded.\n`);
344
+ return 0;
345
+ }
314
346
  case 'quiet': {
315
347
  const [state, ...extra] = rest;
316
348
  if (extra.length || (state !== undefined && state !== 'on' && state !== 'off')) {
@@ -592,6 +624,7 @@ async function main(argv) {
592
624
  ' --lang es|pt the why report in Latin American Spanish or Brazilian Portuguese; your locale picks it by default\n' +
593
625
  ' compare [sessionA] [sessionB] two sessions side by side: tokens, cache, sub-agents, rewrites, list USD; json and --lang as for why\n' +
594
626
  ' calendar [--weeks N] tokens per day, Claude Code and Codex together: sub-agent days, launches AgentGuard held, dollars at API prices; json and --lang as for why\n' +
627
+ ' card [--weeks N] [--out file.png] the calendar\'s totals as one 1200x675 image to share (default 4 weeks); written locally, nothing uploaded\n' +
595
628
  ' rewrites [session|all] every full-prefix cache write with its cause, idle gap and list price\n' +
596
629
  ' ttl [session|all] one-hour cache lifetime counterfactual from your own idle gaps\n' +
597
630
  ' pace [session] ten-minute pace and next-hour projection\n' +
@@ -0,0 +1,34 @@
1
+ import type { CalendarReport } from './calendar';
2
+ import type { DollarRange } from './pricing';
3
+ export declare const CARD_WIDTH = 1200;
4
+ export declare const CARD_HEIGHT = 675;
5
+ export declare const CARD_SITE = "agentguard.run/burn";
6
+ export interface CardTile {
7
+ value: string;
8
+ label: string;
9
+ tone: 'teal' | 'ink' | 'amber';
10
+ }
11
+ export interface CardBar {
12
+ date: string;
13
+ tokens: number;
14
+ held: boolean;
15
+ busiest: boolean;
16
+ }
17
+ export interface CardModel {
18
+ heading: string;
19
+ range: string;
20
+ hero: string;
21
+ heroLabel: string;
22
+ /** Claude and Codex tokens side by side; null when one host carries every token. */
23
+ split: string | null;
24
+ tiles: CardTile[];
25
+ bars: CardBar[];
26
+ footnote: string;
27
+ site: string;
28
+ }
29
+ /** Three significant digits and a unit: 28.8B, 4.39B, 738M, 12.3K, 999. */
30
+ export declare function compact(value: number): string;
31
+ /** A dollar range for the card: one figure when both ends round alike, null when nothing is priced. */
32
+ export declare function compactDollars(range: DollarRange | null): string | null;
33
+ export declare function cardModel(report: CalendarReport): CardModel;
34
+ export declare function renderCard(model: CardModel): Promise<Buffer>;
@@ -0,0 +1,225 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CARD_SITE = exports.CARD_HEIGHT = exports.CARD_WIDTH = void 0;
4
+ exports.compact = compact;
5
+ exports.compactDollars = compactDollars;
6
+ exports.cardModel = cardModel;
7
+ exports.renderCard = renderCard;
8
+ /**
9
+ * `agentguard-burn card`: the calendar's totals as one image made to be shared, 1200x675 (the
10
+ * X/Twitter large-card ratio). Everything on it comes from `calendarReport`, the same figures the
11
+ * calendar prints; dollars carry the calendar's basis (API list price, not a bill); nothing
12
+ * about a project, prompt or file is drawn, and the image is written locally, never uploaded.
13
+ */
14
+ const promises_1 = require("node:fs/promises");
15
+ const node_path_1 = require("node:path");
16
+ const canvas_1 = require("@napi-rs/canvas");
17
+ exports.CARD_WIDTH = 1200;
18
+ exports.CARD_HEIGHT = 675;
19
+ exports.CARD_SITE = 'agentguard.run/burn';
20
+ const UNITS = [[1e12, 'T'], [1e9, 'B'], [1e6, 'M'], [1e3, 'K']];
21
+ /** Three significant digits and a unit: 28.8B, 4.39B, 738M, 12.3K, 999. */
22
+ function compact(value) {
23
+ for (const [size, unit] of UNITS) {
24
+ if (Math.abs(value) >= size)
25
+ return `${Number((value / size).toPrecision(3))}${unit}`;
26
+ }
27
+ return String(Math.round(value));
28
+ }
29
+ /** A dollar range for the card: one figure when both ends round alike, null when nothing is priced. */
30
+ function compactDollars(range) {
31
+ if (!range || !(Math.max(range.min, range.max) > 0))
32
+ return null;
33
+ const low = dollarFigure(range.min), high = dollarFigure(range.max);
34
+ return low === high ? low : `${low} to ${high}`;
35
+ }
36
+ function dollarFigure(value) {
37
+ return value >= 1000 ? `$${compact(value)}` : `$${Math.round(value)}`;
38
+ }
39
+ const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
40
+ const monthDay = (day) => `${MONTHS[Number(day.slice(5, 7)) - 1]} ${Number(day.slice(8, 10))}`;
41
+ function spanText(from, to) {
42
+ const fromYear = from.slice(0, 4), toYear = to.slice(0, 4);
43
+ return fromYear === toYear
44
+ ? `${monthDay(from)} to ${monthDay(to)}, ${toYear}`
45
+ : `${monthDay(from)}, ${fromYear} to ${monthDay(to)}, ${toYear}`;
46
+ }
47
+ /** The span starts on a Sunday; the days after today stay as empty slots so the week reads as a week. */
48
+ function wholeWeeks(bars) {
49
+ const padded = [...bars];
50
+ while (padded.length % 7 !== 0)
51
+ padded.push({ date: '', tokens: 0, held: false, busiest: false });
52
+ return padded;
53
+ }
54
+ function cardModel(report) {
55
+ const { totals } = report;
56
+ const both = totals.claudeTokens > 0 && totals.codexTokens > 0;
57
+ const host = both ? 'Claude Code and Codex' : totals.codexTokens > 0 ? 'Codex' : 'Claude Code';
58
+ const tiles = [];
59
+ const dollars = compactDollars(totals.usd);
60
+ if (dollars)
61
+ tiles.push({ value: dollars, label: 'at API prices, not a bill', tone: 'teal' });
62
+ if (totals.subagentShare !== null) {
63
+ tiles.push({ value: `${Math.round(totals.subagentShare * 100)}%`, label: 'by sub-agents', tone: 'ink' });
64
+ }
65
+ if (report.busiest) {
66
+ tiles.push({ value: compact(report.busiest.tokens), label: `busiest day, ${monthDay(report.busiest.date)}`, tone: 'ink' });
67
+ }
68
+ tiles.push(totals.heldLaunches > 0
69
+ ? { value: totals.heldLaunches.toLocaleString('en-US'), label: 'sub-agent launches AgentGuard held', tone: 'amber' }
70
+ : { value: report.sources.transcripts.toLocaleString('en-US'), label: 'transcripts read on this machine', tone: 'ink' });
71
+ return {
72
+ heading: report.weeks === 1 ? 'My week of AI coding' : `My last ${report.weeks} weeks of AI coding`,
73
+ range: spanText(report.from, report.to),
74
+ hero: compact(totals.tokens),
75
+ heroLabel: `tokens through ${host}`,
76
+ split: both ? `Claude ${compact(totals.claudeTokens)} · Codex ${compact(totals.codexTokens)}` : null,
77
+ tiles,
78
+ bars: wholeWeeks(report.days.map(day => ({
79
+ date: day.date, tokens: day.tokens, held: day.heldLaunches > 0,
80
+ busiest: report.busiest?.date === day.date,
81
+ }))),
82
+ footnote: 'Counted from this machine’s transcripts. Dollars are API list prices, not a bill. Nothing was uploaded.',
83
+ site: exports.CARD_SITE,
84
+ };
85
+ }
86
+ /* ---------------------------------------------------------------- drawing */
87
+ const FONT_DIR = (0, node_path_1.join)(__dirname, '../../../fonts');
88
+ const TEXT = 'AgentGuardCardText', MONO = 'AgentGuardCardMono';
89
+ const FONT_FILES = [
90
+ ['Inter-Regular.ttf', TEXT], ['Inter-SemiBold.ttf', TEXT],
91
+ ['JetBrainsMono-Regular.ttf', MONO], ['JetBrainsMono-Bold.ttf', MONO],
92
+ ];
93
+ const INK = {
94
+ paper: '#0B1117', ink: '#FFFFFF', secondary: '#B4BECF', faint: '#6B7686', teal: '#2ABCB4',
95
+ tealSoft: 'rgba(42,188,180,0.38)', amber: '#F59E0B', panel: 'rgba(255,255,255,0.04)', line: 'rgba(255,255,255,0.10)',
96
+ };
97
+ const TONE = { teal: INK.teal, ink: INK.ink, amber: INK.amber };
98
+ let fontsReady = false;
99
+ async function registerFonts() {
100
+ if (fontsReady)
101
+ return;
102
+ for (const [file, alias] of FONT_FILES) {
103
+ const path = (0, node_path_1.join)(FONT_DIR, file);
104
+ await (0, promises_1.access)(path, promises_1.constants.R_OK);
105
+ canvas_1.GlobalFonts.registerFromPath(path, alias);
106
+ }
107
+ if (!canvas_1.GlobalFonts.has(TEXT) || !canvas_1.GlobalFonts.has(MONO))
108
+ throw new Error('Card fonts did not register from the package fonts directory.');
109
+ fontsReady = true;
110
+ }
111
+ function wrapLines(ctx, text, width) {
112
+ const lines = [];
113
+ let line = '';
114
+ for (const word of text.split(' ')) {
115
+ const next = line ? `${line} ${word}` : word;
116
+ if (line && ctx.measureText(next).width > width) {
117
+ lines.push(line);
118
+ line = word;
119
+ }
120
+ else
121
+ line = next;
122
+ }
123
+ if (line)
124
+ lines.push(line);
125
+ return lines;
126
+ }
127
+ function roundedRect(ctx, x, y, w, h, r) {
128
+ ctx.beginPath();
129
+ ctx.moveTo(x + r, y);
130
+ ctx.arcTo(x + w, y, x + w, y + h, r);
131
+ ctx.arcTo(x + w, y + h, x, y + h, r);
132
+ ctx.arcTo(x, y + h, x, y, r);
133
+ ctx.arcTo(x, y, x + w, y, r);
134
+ ctx.closePath();
135
+ }
136
+ async function renderCard(model) {
137
+ await registerFonts();
138
+ const canvas = (0, canvas_1.createCanvas)(exports.CARD_WIDTH, exports.CARD_HEIGHT);
139
+ const ctx = canvas.getContext('2d');
140
+ const pad = 64;
141
+ ctx.fillStyle = INK.paper;
142
+ ctx.fillRect(0, 0, exports.CARD_WIDTH, exports.CARD_HEIGHT);
143
+ ctx.textBaseline = 'alphabetic';
144
+ // Header: wordmark left, date span right.
145
+ ctx.font = `600 26px ${TEXT}`;
146
+ ctx.fillStyle = INK.ink;
147
+ // No registration symbol: the card is a social image, and the registration's services do not list Burn.
148
+ ctx.fillText('AgentGuard', pad, 88);
149
+ const markWidth = ctx.measureText('AgentGuard ').width;
150
+ ctx.fillStyle = INK.teal;
151
+ ctx.fillText('Burn', pad + markWidth, 88);
152
+ ctx.font = `22px ${TEXT}`;
153
+ ctx.fillStyle = INK.secondary;
154
+ ctx.textAlign = 'right';
155
+ ctx.fillText(model.range, exports.CARD_WIDTH - pad, 88);
156
+ ctx.textAlign = 'left';
157
+ // Hero: the token total.
158
+ ctx.font = `30px ${TEXT}`;
159
+ ctx.fillStyle = INK.secondary;
160
+ ctx.fillText(model.heading, pad, 158);
161
+ ctx.font = `600 150px ${TEXT}`;
162
+ ctx.fillStyle = INK.ink;
163
+ ctx.fillText(model.hero, pad - 6, 292);
164
+ ctx.font = `26px ${TEXT}`;
165
+ ctx.fillStyle = INK.secondary;
166
+ ctx.fillText(model.heroLabel, pad, 336);
167
+ if (model.split) {
168
+ ctx.font = `22px ${TEXT}`;
169
+ ctx.fillStyle = INK.faint;
170
+ ctx.fillText(model.split, pad, 372);
171
+ }
172
+ // Tiles: a 2x2 grid on the right.
173
+ const gridX = 668, gridY = 126, tileW = 226, tileH = 118, gap = 16;
174
+ model.tiles.slice(0, 4).forEach((tile, index) => {
175
+ const x = gridX + (index % 2) * (tileW + gap), y = gridY + Math.floor(index / 2) * (tileH + gap);
176
+ roundedRect(ctx, x, y, tileW, tileH, 14);
177
+ ctx.fillStyle = INK.panel;
178
+ ctx.fill();
179
+ ctx.strokeStyle = INK.line;
180
+ ctx.lineWidth = 1;
181
+ ctx.stroke();
182
+ ctx.font = `600 40px ${TEXT}`;
183
+ ctx.fillStyle = TONE[tile.tone];
184
+ ctx.fillText(tile.value, x + 20, y + 56);
185
+ ctx.font = `17px ${TEXT}`;
186
+ ctx.fillStyle = INK.secondary;
187
+ wrapLines(ctx, tile.label, tileW - 40).slice(0, 2).forEach((line, row) => ctx.fillText(line, x + 20, y + 84 + row * 21));
188
+ });
189
+ // Daily bars: one per day of the span, the busiest in full teal, a dot where AgentGuard held a launch.
190
+ const barsTop = 420, barsBottom = 566, barsLeft = pad, barsRight = exports.CARD_WIDTH - pad;
191
+ const count = Math.max(model.bars.length, 1);
192
+ const slot = (barsRight - barsLeft) / count;
193
+ const barWidth = Math.max(2, Math.min(28, slot * 0.72));
194
+ const peak = Math.max(...model.bars.map(bar => bar.tokens), 1);
195
+ ctx.strokeStyle = INK.line;
196
+ ctx.beginPath();
197
+ ctx.moveTo(barsLeft, barsBottom + 0.5);
198
+ ctx.lineTo(barsRight, barsBottom + 0.5);
199
+ ctx.stroke();
200
+ model.bars.forEach((bar, index) => {
201
+ const x = barsLeft + index * slot + (slot - barWidth) / 2;
202
+ const height = bar.tokens > 0 ? Math.max(3, (bar.tokens / peak) * (barsBottom - barsTop - 18)) : 0;
203
+ if (height > 0) {
204
+ roundedRect(ctx, x, barsBottom - height, barWidth, height, Math.min(4, barWidth / 2));
205
+ ctx.fillStyle = bar.busiest ? INK.teal : INK.tealSoft;
206
+ ctx.fill();
207
+ }
208
+ if (bar.held) {
209
+ ctx.beginPath();
210
+ ctx.arc(x + barWidth / 2, barsBottom - height - 9, 3.5, 0, Math.PI * 2);
211
+ ctx.fillStyle = INK.amber;
212
+ ctx.fill();
213
+ }
214
+ });
215
+ // Footer: the basis, then the site.
216
+ ctx.font = `16px ${TEXT}`;
217
+ ctx.fillStyle = INK.faint;
218
+ ctx.fillText(model.footnote, pad, 616);
219
+ ctx.font = `600 20px ${TEXT}`;
220
+ ctx.fillStyle = INK.teal;
221
+ ctx.textAlign = 'right';
222
+ ctx.fillText(model.site, exports.CARD_WIDTH - pad, 616);
223
+ ctx.textAlign = 'left';
224
+ return canvas.encode('png');
225
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentguard-run/burn",
3
- "version": "0.3.24",
3
+ "version": "0.3.25",
4
4
  "description": "Local session usage and runaway-agent circuit breaker. Explain tokens, cache rewrites and API list cost, track pace, warn on heavy turns, and gate agent fan-out with signed receipts. Developer command ranking requires explicit --rank.",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "homepage": "https://agentguard.run/burn",