@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
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MIN_FINISHED_SUBAGENTS = void 0;
4
+ exports.finishedSubagents = finishedSubagents;
5
+ exports.subagentCostLine = subagentCostLine;
6
+ exports.decisionCostLine = decisionCostLine;
7
+ const i18n_1 = require("./insights/i18n");
8
+ const live_1 = require("./insights/live");
9
+ const pricing_1 = require("./insights/pricing");
10
+ const stop_text_1 = require("./stop-text");
11
+ /** Fewer finished sub-agents than this say too little about the next one, so the line is left out. */
12
+ exports.MIN_FINISHED_SUBAGENTS = 3;
13
+ const rateOf = (model, rates) => Object.hasOwn(rates, model) ? rates[model] : Object.hasOwn(pricing_1.MODEL_PRICING, model) ? pricing_1.MODEL_PRICING[model] : undefined;
14
+ /** One child's list price, model by model; null when any model is unpriced. */
15
+ function childUsd(usage, rates) {
16
+ let total = { min: 0, max: 0 };
17
+ for (const [model, [input, output, write, read, fiveMinute, oneHour]] of usage) {
18
+ const rate = model ? rateOf(model, rates) : undefined;
19
+ // A long-context tier applies per request, which a sum of requests cannot show: such a model stays unpriced here.
20
+ const price = rate && !rate.longContext ? (0, pricing_1.priceTurn)({ id: model, sessionId: '', host: 'claude', model,
21
+ inputTokens: input, outputTokens: output, cacheWriteTokens: write, cacheReadTokens: read, cacheWrite5mTokens: fiveMinute, cacheWrite1hTokens: oneHour,
22
+ signals: { afterCompaction: false, firstSpawnedTurn: false }, explicitAttribution: [], uncertainties: [] }, rates).usd : null;
23
+ total = total && price ? { min: total.min + price.min, max: total.max + price.max } : null;
24
+ }
25
+ return total;
26
+ }
27
+ /**
28
+ * The sub-agents a session's transcripts record as completed (Claude Code's
29
+ * `agent-<id>.jsonl` children), each measured from its first byte; null when
30
+ * fewer than three qualify. A child an older Burn had already read part of has
31
+ * no measurement and is left out rather than undercounted. `priced` false
32
+ * leaves the dollars out.
33
+ */
34
+ function finishedSubagents(cursor, rates = {}, priced = true) {
35
+ if (!cursor.completed?.size || !cursor.children?.size)
36
+ return null;
37
+ const rows = [];
38
+ for (const [name, child] of cursor.children) {
39
+ const id = /^agent-([A-Za-z0-9_-]{1,64})\.jsonl$/.exec(name)?.[1];
40
+ if (!id || !cursor.completed.has(id) || !child.usage)
41
+ continue;
42
+ let tokens = 0;
43
+ for (const [input, output, write, read] of child.usage.values())
44
+ tokens += input + output + write + read;
45
+ if (tokens > 0)
46
+ rows.push({ tokens, usd: priced ? childUsd(child.usage, rates) : null });
47
+ }
48
+ if (rows.length < exports.MIN_FINISHED_SUBAGENTS)
49
+ return null;
50
+ const count = rows.length;
51
+ const meanUsd = rows.every(row => row.usd !== null)
52
+ ? { min: rows.reduce((sum, row) => sum + row.usd.min, 0) / count, max: rows.reduce((sum, row) => sum + row.usd.max, 0) / count }
53
+ : null;
54
+ return { count, meanTokens: rows.reduce((sum, row) => sum + row.tokens, 0) / count, meanUsd };
55
+ }
56
+ /**
57
+ * "The 15 sub-agents that finished in this session averaged 10.0M tokens each
58
+ * ($4.99 at API prices, not a bill). This one could differ." A measured average
59
+ * of what already ran, never a forecast; null without a summary. The STOP text
60
+ * is English on every host, so the hook passes 'en'.
61
+ */
62
+ function subagentCostLine(summary, lang = 'en') {
63
+ if (!summary)
64
+ return null;
65
+ return i18n_1.DECISION_TEXT[lang].finished(summary.count, (0, stop_text_1.shortTokens)(summary.meanTokens), summary.meanUsd ? (0, live_1.dollars)(summary.meanUsd, i18n_1.WHY_TEXT[lang]) : null);
66
+ }
67
+ /**
68
+ * The line a STOP prints, exactly as Burn's own Claude Code hook prints it: the
69
+ * summary of a cursor that readSessionIncremental advanced, priced with the
70
+ * rates `why` uses (burn-pricing.json under `home`, or the policy's pricing
71
+ * file), in English like the rest of the STOP text. Null below three finished
72
+ * sub-agents. Best effort: a pricing file that cannot be read costs the line its
73
+ * dollars, and nothing here throws, so it can never turn a prompt into a
74
+ * failed-closed refusal.
75
+ */
76
+ function decisionCostLine(cursor, home, policy) {
77
+ let rates;
78
+ try {
79
+ rates = (0, live_1.readPricing)(home, policy);
80
+ }
81
+ catch {
82
+ rates = null;
83
+ }
84
+ try {
85
+ return subagentCostLine(finishedSubagents(cursor, rates ?? {}, rates !== null));
86
+ }
87
+ catch {
88
+ return null;
89
+ }
90
+ }
package/package.json CHANGED
@@ -1,8 +1,12 @@
1
1
  {
2
2
  "name": "@agentguard-run/burn",
3
- "version": "0.3.19",
3
+ "version": "0.3.21",
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
+ "homepage": "https://agentguard.run/burn",
7
+ "bugs": {
8
+ "url": "https://github.com/MerchantGuard/agentguard-codex-plugin/issues"
9
+ },
6
10
  "type": "commonjs",
7
11
  "main": "dist/src/index.js",
8
12
  "types": "dist/src/index.d.ts",