@agentguard-run/burn 0.3.17 → 0.3.19

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,26 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.19 (2026-09-27)
4
+
5
+ - Every command Burn prints now uses the short, unscoped name `npx agentguard-burn` (the `agentguard-burn` launcher on npm runs the latest Burn): the override line in the STOP box, the `why` tips in English, Spanish and Portuguese, and the `quiet` messages. The name has no "@", so X no longer turns a quoted command into a link to someone else's account. `why` output is otherwise byte-identical to 0.3.16 in English.
6
+ - `enforce` now says what enforcement does: "In an interactive Claude Code session the next STOP asks you first; where nobody can answer, it refuses the launch."
7
+ - `why` with no session no longer picks a file Claude Code keeps inside a session's own directory, such as `<session>/skill-injections.jsonl`, when that file is the newest on disk.
8
+ - New `compare [sessionA] [sessionB] [json] [--lang en|es|pt]`: two sessions side by side from local transcripts, so the same task run once on each model reads as one table. Rows: assistant responses; input tokens, split into cache reads, cache writes and fresh input; the cache share (cache reads divided by all input); output tokens; sub-agents launched; full-prefix rewrites; the API list-price equivalent. Each is exactly the figure `why` prints for that session, child transcripts included, and the table says "Totals include sub-agents." The Change column is B against A: a signed percentage for counts and dollars, and a difference in percentage points for the cache share (for example "+2.6 pp", never a percentage of a percentage; `change.cacheShare` in json is that difference), only where both values are numbers and A is not zero as printed; a dollar range compares midpoints, and an unpriced model prints `unpriced` with no change. Every report ends with "Dollar figures are API list-price equivalents, not a bill." and "AgentGuard cannot tell whether these sessions did the same task. Compare runs of the same task."
9
+ - Picking: two sessions compare those two in the order given; one pairs it with the newest other top-level session in its project; none takes the two newest top-level sessions in the project of the newest one. Ids, id suffixes and transcript paths resolve as they do for `why`. Sub-agent transcripts and other files Claude Code keeps beside a session (such as `skill-injections.jsonl`) are never picked. A Codex rollout's project is the working directory it recorded, and a spawned sub-agent rollout is skipped. Unless both are named, A is the session that started first. The session variables `why` falls back on are not read. Fewer than two sessions exits 1 with one line on stderr saying so and how to pass two ids.
10
+ - Both sessions are named above the table: the short id (the last part of the session id, accepted back as an id suffix), the time of the first recorded response in UTC, the dominant model by output tokens (every model with at least 5% of output tokens, with its share, when there are several) and the project path (the working directory the transcript recorded, read from its first records only).
11
+ - The table fits 80 columns in English. Spanish and Portuguese follow `why`: every line through `src/insights/i18n.ts`, figures in en-US digits, AgentGuard untranslated, the same language precedence and the same exit-64 usage line for a bad `--lang`. `compare json` is never translated and carries both sessions (ids, paths, project, models, every metric) and each change as an unrounded fraction of A. The report prints its plain table on a terminal, through the same presentation path as the other reports.
12
+ - What changes in output: only the new command, and the help, which lists it in its synopsis and on one new line. `why`, `why json` and every other command are byte-identical to 0.3.17. Internally, `why`'s header figures now come from an exported `sessionFigures`, which `compare` reads as well; `render.ts` exports its `table`, `count` and `share` helpers, and `sessions.ts` gains `transcriptRoots` (the same default roots) and `transcriptOrigin` (the recorded working directory and the parser's sub-agent verdict, from at most the first megabyte of a transcript).
13
+
14
+ ## 0.3.18 (2026-09-27)
15
+
16
+ - An enforced STOP in an interactive Claude Code session (Manual, accept edits, auto or plan mode) now holds the launch behind Claude Code's own permission prompt instead of refusing it: three lines naming the one limit that fired, then "Allow this one launch? If you say no, nothing starts." Claude Code shows that text to the person and not to Claude, and since Claude Code 2.1.211 auto mode cannot approve it silently. Print mode, `bypassPermissions`, `dontAsk`, Codex and Cursor still refuse outright. `"stopStyle": "deny"` in `burn-policy.json` keeps the outright refusal everywhere. The decisions ledger records `asked: true` and the permission mode; the signed receipt adds the reason `decision:ask`.
17
+ - The STOP box is rebuilt around one cause: the limit that fired with its real number and window, one "Session so far" line, WHAT TO DO with two actions for that limit, and the way to continue. The title reads "sub-agent launch refused". The override line is `npx @agentguard-run/burn resume --once --reason "..."`, which works for plugin-only installs that never put `agentguard-burn` on PATH, with a `!` in front inside Claude Code so it runs in the person's own shell.
18
+ - Each limit words its finding the same way: "15 sub-agents in the last 15 active minutes. Limit: 15.", "40 sub-agents in the last 120 active minutes. Limit: 40.", "This session has used 5.02B tokens. Limit: 5.00B.", "This sub-agent would be 3 levels deep. Limit: 2." The fan-out warning names both counts ("Sub-agent 24 this session. Limit: 40 in any 120 active minutes; 7 so far.") instead of comparing the lifetime count with the windowed limit.
19
+ - The line after an override names the limit it passed. It used to quote the first finding in the list: on Sep 26 2026 an override past the 5.00B token limit printed "93 agent spawns this session; ceiling is 40."
20
+ - Warnings say what happens at the limit in the session's own terms: "Past the limit, the next launch waits for your yes." or "... is refused."
21
+ - The agent cannot lift a STOP itself. In enforce mode the hook refuses an agent's Bash call that runs `resume`, `shadow` or `calibrate` through any form of the Burn command, and an agent write to `override.json` or `burn-policy.json`, and tells Claude to ask the person to type it with `!`. A person's `!` command never reaches a hook, so the person's override is unaffected. Each attempt is recorded as `override_attempt`.
22
+ - Shadow messages read "would have refused".
23
+
3
24
  ## 0.3.17 (2026-09-27)
4
25
 
5
26
  - `why` prints in Latin American Spanish or Brazilian Portuguese when your machine is set to that language: the nine bucket labels, the table header, both header lines, the footnotes, every Method sentence, the conditional notes (explicit attribution, unpriced models, missing cache TTL, mixed-lifetime ranges), the diagnostics line, the unknown Codex fork-history message, the three tips and the hide line. The words `unpriced` and `to` inside dollar cells are translated as well (`sin precio`, `$0.63 a $1.00`).
package/README.md CHANGED
@@ -225,6 +225,47 @@ Optional settings in your existing `burn-policy.json`:
225
225
 
226
226
  Merge these fields into the existing policy. All existing thresholds and modes remain supported. Prices are exact-model API list equivalents, not a subscription bill. Unknown models show tokens only. Every rate has a source and verification date. A local override file and full pricing table are documented in [Usage and pricing](docs/USAGE_AND_PRICING.md).
227
227
 
228
+ ## Compare two sessions
229
+
230
+ ```sh
231
+ agentguard-burn compare
232
+ agentguard-burn compare SESSION_ID
233
+ agentguard-burn compare SESSION_A SESSION_B
234
+ agentguard-burn compare SESSION_A SESSION_B json
235
+ ```
236
+
237
+ Run the same task once on each model, then put the two sessions side by side. With no session, `compare` takes the two most recent top-level sessions in the project of the newest one; with one, that session and the newest other top-level session in its project; with two, those two in the order given. Sessions resolve as they do for `why` (id, id suffix or transcript path). Sub-agent transcripts and other files Claude Code keeps beside a session are never picked. A Codex rollout's project is the working directory it recorded, and a spawned sub-agent rollout is skipped. Unless you name both, A is the session that started first. Fewer than two sessions exits 1 with one line saying how to pass two ids.
238
+
239
+ Both sessions are named first: the short id (the last part of the session id, which `compare` and `why` accept back), the time of the first recorded response in UTC, the model with the most output tokens (every model with at least 5% of output tokens, with its share, when there are several) and the project path. Each figure is the one `why` prints for that session, child transcripts included. Change is B against A, only where both values are numbers and A is not zero as printed; a dollar range compares midpoints, and an unpriced model prints `unpriced` with no change. The fixture in `tests/fixtures/compare-fixtures.ts` renders as:
240
+
241
+ ```text
242
+ AgentGuard compare: B against A
243
+ A aaaaaaaaaaaa started 2026-09-25 10:01 UTC
244
+ Output by model: claude-opus-5-5 92.3%, claude-haiku-4-5-20251001 7.7%
245
+ Project: /synthetic/project
246
+ B bbbbbbbbbbbb started 2026-09-25 11:01 UTC
247
+ Model: claude-sonnet-5
248
+ Project: /synthetic/project
249
+
250
+ Metric A B Change
251
+ Assistant responses 4 3 -25.0%
252
+ Input tokens 599,600 543,000 -9.4%
253
+ read from cache 200,000 360,000 +80.0%
254
+ cache writes 396,000 180,500 -54.4%
255
+ fresh input 3,600 2,500 -30.6%
256
+ Cache share 33.4% 66.3% +98.8%
257
+ Output tokens 6,500 4,000 -38.5%
258
+ Sub-agents launched 1 0 -100.0%
259
+ Full-prefix rewrites 2 1 -50.0%
260
+ List USD $2.13 $0.57 -73.3%
261
+ Totals include sub-agents.
262
+
263
+ Dollar figures are API list-price equivalents, not a bill.
264
+ AgentGuard cannot tell whether these sessions did the same task. Compare runs of the same task.
265
+ ```
266
+
267
+ `compare` measures and does not rank models. `--lang es|pt` and your locale choose the language exactly as for `why`. `compare json` is never translated: both sessions with ids, paths, project, models and every metric, and each change as an unrounded fraction of A.
268
+
228
269
  ## Two safety planes
229
270
 
230
271
  Structural limits use active time rather than the age of the session. The
@@ -350,12 +391,35 @@ command still exists on disk (a hook whose script is gone fails open, and
350
391
 
351
392
  ### When it stops you and you disagree
352
393
 
394
+ In an interactive Claude Code session (Manual, accept edits, auto or plan
395
+ mode) an enforced STOP holds the launch behind Claude Code's own permission
396
+ prompt. The prompt names the one limit that fired, for example:
397
+
398
+ ```
399
+ AgentGuard: 15 sub-agents in the last 15 active minutes. Limit: 15.
400
+ Session so far: 15 sub-agents, 154.0M tokens.
401
+ Allow this one launch? If you say no, nothing starts.
402
+ ```
403
+
404
+ You answer with one keypress. Claude never sees that text, and auto mode
405
+ cannot approve it silently (Claude Code 2.1.211 and later), so the answer is
406
+ yours. Where no prompt can appear (print mode, `bypassPermissions`, `dontAsk`,
407
+ Codex, Cursor) the launch is refused with the STOP box instead, and the box
408
+ ends with the override to run. In Claude Code, type it with `!` in front so it
409
+ runs in your own shell:
410
+
353
411
  ```
354
- agentguard-burn resume --once --reason "these 60 agents are the plan" # the next STOP passes, once, on any host
355
- agentguard-burn resume --reason "load test" # every STOP passes for 15 minutes
356
- agentguard-burn resume --clear
412
+ ! npx agentguard-burn resume --once --reason "these 60 agents are the plan" # the next STOP passes, once, on any host
413
+ ! npx agentguard-burn resume --reason "load test" # every STOP passes for 15 minutes
414
+ ! npx agentguard-burn resume --clear
357
415
  ```
358
416
 
417
+ Only the person can override. A `!` command never passes through a hook, so
418
+ AgentGuard refuses the same `resume`, `shadow` or `calibrate` command when the
419
+ agent runs it, and refuses agent writes to `override.json` or
420
+ `burn-policy.json`. Set `"stopStyle": "deny"` in `burn-policy.json` to refuse
421
+ outright even where a prompt could show.
422
+
359
423
  Every override is written to the decisions ledger with its reason. A
360
424
  `--once` override is consumed atomically: two hooks racing for it cannot
361
425
  both pass. Warnings are spoken once per change in the finding set, not once
@@ -33,6 +33,7 @@ const node_crypto_1 = require("node:crypto");
33
33
  const node_fs_1 = require("node:fs");
34
34
  const events_1 = require("../events");
35
35
  const render_1 = require("../replay/render");
36
+ const stop_text_1 = require("../stop-text");
36
37
  const live_1 = require("../insights/live");
37
38
  const hook_1 = require("../idle/hook");
38
39
  const pre_tool_use_1 = require("../hook/pre-tool-use");
@@ -82,7 +83,7 @@ function handleCodexSpawnHook(raw, gateway, now) {
82
83
  hookSpecificOutput: {
83
84
  hookEventName: 'PreToolUse',
84
85
  permissionDecision: 'deny',
85
- permissionDecisionReason: (0, render_1.renderStop)(decision.report, { colour: false }),
86
+ permissionDecisionReason: (0, render_1.renderStop)(decision.report, { colour: false, host: 'codex' }),
86
87
  },
87
88
  };
88
89
  }
@@ -91,11 +92,11 @@ function handleCodexSpawnHook(raw, gateway, now) {
91
92
  // the conservative direction.
92
93
  quietly(() => gateway.observe([{ schemaVersion: 1, kind: 'spawn_started', eventId: `codex:start:${spawnId}`, host: HOST, sessionId: input.sessionId, at: now, spawnId, depth: 1 }]));
93
94
  if (decision.overridden) {
94
- return { systemMessage: `AgentGuard STOP overridden${decision.overridden.once ? ' once' : ''} ("${decision.overridden.reason}"): ${decision.report.findings[0]?.summary ?? ''}` };
95
+ return { systemMessage: (0, stop_text_1.overriddenLine)(decision.report, decision.overridden) };
95
96
  }
96
97
  if (decision.notify && decision.verdict !== 'OK') {
97
98
  return {
98
- systemMessage: `AgentGuard ${decision.verdict}${decision.mode === 'shadow' && decision.wouldBlock ? ' (shadow: would have blocked)' : ''}: ${decision.report.findings[0]?.summary ?? ''}`,
99
+ systemMessage: `AgentGuard ${decision.verdict}${decision.mode === 'shadow' && decision.wouldBlock ? ' (shadow: would have refused)' : ''}: ${(0, stop_text_1.primarySummary)(decision.report)}`,
99
100
  };
100
101
  }
101
102
  return {};
@@ -24,6 +24,7 @@ exports.handleCursorHook = handleCursorHook;
24
24
  exports.cursorHooksSnippet = cursorHooksSnippet;
25
25
  const events_1 = require("../events");
26
26
  const render_1 = require("../replay/render");
27
+ const stop_text_1 = require("../stop-text");
27
28
  const HOST = 'cursor';
28
29
  /**
29
30
  * Handle one hook invocation. Unknown events allow. Returns the object to
@@ -54,8 +55,8 @@ function handleCursorHook(raw, gateway, now = Date.now()) {
54
55
  if (decision.blocked) {
55
56
  return {
56
57
  permission: 'deny',
57
- user_message: (0, render_1.renderStop)(decision.report, { colour: false }),
58
- agent_message: `AgentGuard STOP: ${decision.report.findings[0]?.summary ?? 'policy ceiling reached'} Do not start another subagent.`,
58
+ user_message: (0, render_1.renderStop)(decision.report, { colour: false, host: 'cursor' }),
59
+ agent_message: `AgentGuard STOP: ${(0, stop_text_1.stopSummary)(decision.report)} Do not start another sub-agent.`,
59
60
  };
60
61
  }
61
62
  // Admitted: the subagent will run. Record it so depth and count are live.
@@ -65,7 +66,7 @@ function handleCursorHook(raw, gateway, now = Date.now()) {
65
66
  const depth = decision.proposedDepth ?? 1;
66
67
  quietly(() => gateway.observe([{ schemaVersion: 1, kind: 'spawn_started', eventId: `cursor:start:${spawnId}`, host: HOST, sessionId: input.sessionId, at, spawnId, depth }]));
67
68
  if (decision.overridden) {
68
- return { permission: 'allow', agent_message: `AgentGuard STOP overridden${decision.overridden.once ? ' once' : ''} ("${decision.overridden.reason}"): ${decision.report.findings[0]?.summary ?? ''}` };
69
+ return { permission: 'allow', agent_message: (0, stop_text_1.overriddenLine)(decision.report, decision.overridden) };
69
70
  }
70
71
  if (decision.notify && decision.verdict !== 'OK') {
71
72
  return {
package/dist/src/cli.js CHANGED
@@ -230,6 +230,39 @@ async function main(argv) {
230
230
  show({ kind: 'command', command, values: { session: transcript.sessionId, observations: transcript.observations, diagnostics: transcript.diagnostics, attribution: (0, attribution_1.attributeTurns)((0, transcript_2.deduplicateTurns)(transcript.turns)).buckets, prices: (0, transcript_2.deduplicateTurns)(transcript.turns).map(turn => (0, pricing_1.priceTurn)(turn, (0, live_1.readPricing)(HOME, (0, pre_tool_use_1.loadPolicy)(HOME)))) } }, json ? JSON.stringify(transcript, null, 2) + '\n' : (0, render_2.renderWhy)(transcript, (0, live_1.readPricing)(HOME, (0, pre_tool_use_1.loadPolicy)(HOME)), { tips: !quietOn(), lang: (0, i18n_1.detectWhyLang)({ flag: lang, env: process.env, intlLocale: intlLocale() }) }) + '\n', json);
231
231
  return 0;
232
232
  }
233
+ case 'compare': {
234
+ // Up to two session selectors, `json`, and `--lang` exactly as `why` takes it.
235
+ const args = [];
236
+ let lang, langGiven = false;
237
+ for (let i = 0; i < rest.length; i++) {
238
+ if (rest[i] === '--lang') {
239
+ langGiven = true;
240
+ lang = rest[++i];
241
+ }
242
+ else if (rest[i].startsWith('--lang=')) {
243
+ langGiven = true;
244
+ lang = rest[i].slice('--lang='.length);
245
+ }
246
+ else
247
+ args.push(rest[i]);
248
+ }
249
+ const json = args.includes('json') || args.includes('--json');
250
+ const selectors = args.filter(value => value !== 'json' && value !== '--json');
251
+ if ((langGiven && (0, i18n_1.whyLangOf)(lang) === null) || selectors.length > 2 || selectors.some(value => !value.trim() || value.startsWith('--'))) {
252
+ process.stderr.write('Usage: agentguard-burn compare [sessionA] [sessionB] [json] [--lang en|es|pt]\n');
253
+ return 64;
254
+ }
255
+ const language = (0, i18n_1.detectWhyLang)({ flag: lang, env: process.env, intlLocale: intlLocale() });
256
+ const { comparePicked, pickCompareSessions, renderCompare } = await Promise.resolve().then(() => __importStar(require('./insights/compare')));
257
+ const pick = pickCompareSessions(selectors);
258
+ if (!pick.ok) {
259
+ process.stderr.write(i18n_1.COMPARE_TEXT[language].fewerThanTwo(pick.found, pick.project) + '\n');
260
+ return 1;
261
+ }
262
+ const report = comparePicked(pick, (0, live_1.readPricing)(HOME, (0, pre_tool_use_1.loadPolicy)(HOME)));
263
+ show({ kind: 'command', command, values: { ...report } }, json ? JSON.stringify(report, null, 2) + '\n' : renderCompare(report, language) + '\n', json);
264
+ return 0;
265
+ }
233
266
  case 'quiet': {
234
267
  const [state, ...extra] = rest;
235
268
  if (extra.length || (state !== undefined && state !== 'on' && state !== 'off')) {
@@ -240,8 +273,8 @@ async function main(argv) {
240
273
  (0, upgrade_moments_1.setQuiet)(HOME, state === 'on');
241
274
  const quiet = quietOn();
242
275
  show({ kind: 'command', command, values: { tips: quiet ? 'off' : 'on', quiet: quiet ? 'on' : 'off', file: (0, upgrade_moments_1.quietFile)(HOME) } }, quiet
243
- ? 'Tips are off. Quiet is on: the why tip, the monthly summary in status and the AgentGuard plugin\'s upgrade, version and Score lines stay hidden on this machine.\nTurn them back on: npx @agentguard-run/burn quiet off\n'
244
- : 'Tips are on. The why report ends with one tip when a share of the session stands out.\nHide tips: npx @agentguard-run/burn quiet on\n');
276
+ ? 'Tips are off. Quiet is on: the why tip, the monthly summary in status and the AgentGuard plugin\'s upgrade, version and Score lines stay hidden on this machine.\nTurn them back on: npx agentguard-burn quiet off\n'
277
+ : 'Tips are on. The why report ends with one tip when a share of the session stands out.\nHide tips: npx agentguard-burn quiet on\n');
245
278
  return 0;
246
279
  }
247
280
  case 'rewrites':
@@ -465,7 +498,7 @@ async function main(argv) {
465
498
  return 2;
466
499
  }
467
500
  savePolicy({ ...policy, mode: 'enforce' });
468
- show({ kind: 'command', command, values: { mode: 'enforce' } }, 'Enforcement ON. The next STOP will block the spawn.\n');
501
+ show({ kind: 'command', command, values: { mode: 'enforce' } }, 'Enforcement ON. In an interactive Claude Code session the next STOP asks you first; where nobody can answer, it refuses the launch.\n');
469
502
  return 0;
470
503
  }
471
504
  case 'shadow': {
@@ -493,7 +526,7 @@ async function main(argv) {
493
526
  return 0;
494
527
  }
495
528
  default:
496
- show({ kind: 'command', command: 'help', values: { commands: ['ps', 'reap', 'live', 'record', 'render', 'blocks', 'limits', 'price-shadow', 'why', 'rewrites', 'ttl', 'pace', 'statusline', 'pricing', 'replay', 'calibrate', 'status', 'init', 'enforce', 'shadow', 'resume', 'quiet', 'proxy', 'conformance'] } }, 'agentguard-burn <ps|reap|live|record|render|blocks|limits|price-shadow|why|rewrites|ttl|pace|statusline|pricing|replay|calibrate|status|init|enforce|shadow|resume|quiet|proxy|conformance>\n' +
529
+ show({ kind: 'command', command: 'help', values: { commands: ['ps', 'reap', 'live', 'record', 'render', 'blocks', 'limits', 'price-shadow', 'why', 'compare', 'rewrites', 'ttl', 'pace', 'statusline', 'pricing', 'replay', 'calibrate', 'status', 'init', 'enforce', 'shadow', 'resume', 'quiet', 'proxy', 'conformance'] } }, 'agentguard-burn <ps|reap|live|record|render|blocks|limits|price-shadow|why|compare|rewrites|ttl|pace|statusline|pricing|replay|calibrate|status|init|enforce|shadow|resume|quiet|proxy|conformance>\n' +
497
530
  ' ps [--json] local agent processes, held memory and workspace disk\n' +
498
531
  ' render <run.jsonl> --mp4 <out.mp4> [--gif <out.gif>] [--phone] local recorded-run export\n' +
499
532
  ' render <run.jsonl> --mp4 <out.mp4> --dashboard [--wide] [--economics <blocks.json>] dashboard export\n' +
@@ -506,6 +539,7 @@ async function main(argv) {
506
539
  ' price-shadow [session|all] local child list-price exposure and sensitivity\n' +
507
540
  ' why [session] token attribution and API list-price equivalents\n' +
508
541
  ' --lang es|pt the why report in Latin American Spanish or Brazilian Portuguese; your locale picks it by default\n' +
542
+ ' compare [sessionA] [sessionB] two sessions side by side: tokens, cache, sub-agents, rewrites, list USD; json and --lang as for why\n' +
509
543
  ' rewrites [session|all] every full-prefix cache write with its cause, idle gap and list price\n' +
510
544
  ' ttl [session|all] one-hour cache lifetime counterfactual from your own idle gaps\n' +
511
545
  ' pace [session] ten-minute pace and next-hour projection\n' +
@@ -54,8 +54,8 @@ function boundaries(steps) {
54
54
  }
55
55
  // Hook adapters only expose the first finding's summary. Fan-out is evaluated
56
56
  // first in the core, so when it fires it is the one in the message.
57
- const FANOUT_WARN = /agent spawns this session/;
58
- const RATE_WARN = /spawns in the last 15 active minutes/;
57
+ const FANOUT_WARN = /Sub-agent \d+ this session/;
58
+ const RATE_WARN = /in the last 15 active minutes/;
59
59
  function stepFromMessage(denied, message, warnPattern) {
60
60
  if (denied)
61
61
  return 'STOP';
@@ -42,7 +42,7 @@ function evaluate(state, thresholds, proposedSpawnDepth = null, account) {
42
42
  findings.push({
43
43
  detector: 'fanout',
44
44
  verdict: 'STOP',
45
- summary: `Spawn ${recentFanout} would exceed the fan-out ceiling of ${thresholds.fanout.stop}.`,
45
+ summary: `${recentFanout - 1} sub-agents in the last ${fanoutWindow} active minutes. Limit: ${thresholds.fanout.stop}.`,
46
46
  observed: recentFanout,
47
47
  threshold: thresholds.fanout.stop,
48
48
  });
@@ -52,7 +52,7 @@ function evaluate(state, thresholds, proposedSpawnDepth = null, account) {
52
52
  findings.push({
53
53
  detector: 'fanout',
54
54
  verdict: 'WARN',
55
- summary: `${effectiveSpawns} agent spawns this session; ceiling is ${thresholds.fanout.stop}.`,
55
+ summary: `Sub-agent ${effectiveSpawns} this session. Limit: ${thresholds.fanout.stop} in any ${fanoutWindow} active minutes; ${recentFanout} so far.`,
56
56
  observed: effectiveSpawns,
57
57
  threshold: thresholds.fanout.warn,
58
58
  });
@@ -62,7 +62,7 @@ function evaluate(state, thresholds, proposedSpawnDepth = null, account) {
62
62
  findings.push({
63
63
  detector: 'fanout',
64
64
  verdict: 'STOP',
65
- summary: `Proposed agent would sit at depth ${proposedSpawnDepth}; agents spawning agents beyond depth ${thresholds.fanout.maxDepth} is the fan-out amplifier.`,
65
+ summary: `This sub-agent would be ${proposedSpawnDepth} levels deep. Limit: ${thresholds.fanout.maxDepth}.`,
66
66
  observed: proposedSpawnDepth,
67
67
  threshold: thresholds.fanout.maxDepth,
68
68
  });
@@ -73,7 +73,7 @@ function evaluate(state, thresholds, proposedSpawnDepth = null, account) {
73
73
  findings.push({
74
74
  detector: 'sustained_burn',
75
75
  verdict: 'STOP',
76
- summary: `Session has consumed ${fmt(state.totalTokens)} tokens, above the ${fmt(thresholds.sustained.stopTokens)} ceiling.`,
76
+ summary: `This session has used ${fmt(state.totalTokens)} tokens. Limit: ${fmt(thresholds.sustained.stopTokens)}.`,
77
77
  observed: state.totalTokens,
78
78
  threshold: thresholds.sustained.stopTokens,
79
79
  });
@@ -83,7 +83,7 @@ function evaluate(state, thresholds, proposedSpawnDepth = null, account) {
83
83
  findings.push({
84
84
  detector: 'sustained_burn',
85
85
  verdict: 'WARN',
86
- summary: `Session at ${fmt(state.totalTokens)} tokens; ceiling is ${fmt(thresholds.sustained.stopTokens)}.`,
86
+ summary: `This session has used ${fmt(state.totalTokens)} tokens. Limit: ${fmt(thresholds.sustained.stopTokens)}.`,
87
87
  observed: state.totalTokens,
88
88
  threshold: thresholds.sustained.warnTokens,
89
89
  });
@@ -119,7 +119,7 @@ function evaluate(state, thresholds, proposedSpawnDepth = null, account) {
119
119
  findings.push({
120
120
  detector: 'spawn_rate',
121
121
  verdict: severity,
122
- summary: `${recentSpawns} spawns in the last ${thresholds.spawnRate.windowActiveMinutes} active minutes.`,
122
+ summary: `${recentSpawns - 1} sub-agents in the last ${thresholds.spawnRate.windowActiveMinutes} active minutes. Limit: ${thresholds.spawnRate.stop - 1}.`,
123
123
  observed: recentSpawns,
124
124
  threshold: thresholds.spawnRate.stop,
125
125
  });
@@ -129,7 +129,7 @@ function evaluate(state, thresholds, proposedSpawnDepth = null, account) {
129
129
  findings.push({
130
130
  detector: 'spawn_rate',
131
131
  verdict: 'WARN',
132
- summary: `${recentSpawns} spawns in the last ${thresholds.spawnRate.windowActiveMinutes} active minutes.`,
132
+ summary: `Sub-agent ${recentSpawns} in the last ${thresholds.spawnRate.windowActiveMinutes} active minutes. Limit: ${thresholds.spawnRate.stop - 1}.`,
133
133
  observed: recentSpawns,
134
134
  threshold: thresholds.spawnRate.warn,
135
135
  });
@@ -205,38 +205,38 @@ function evaluate(state, thresholds, proposedSpawnDepth = null, account) {
205
205
  function prescribe(state, findings, t) {
206
206
  const out = [];
207
207
  const has = (d, v) => findings.some((f) => f.detector === d && (!v || f.verdict === v));
208
- if (has('fanout', 'STOP')) {
209
- out.push('Do not start another subagent. The fan-out ceiling is the validated stop.');
210
- out.push(`Let the ${Math.min(state.spawnCount, 4)} most useful running agents finish; do not replace them.`);
211
- }
212
- else if (has('fanout')) {
213
- out.push(`You are at ${state.spawnCount} spawns; ${Math.max(0, t.fanout.stop - (0, session_1.windowSum)(state.spawnsByActiveMinute, state.activeMinutes, t.fanout.windowActiveMinutes ?? defaults_1.DEFAULT_THRESHOLDS.fanout.windowActiveMinutes))} remain before the ceiling. Plan for it.`);
214
- }
215
- if (state.maxDepth >= 2) {
216
- out.push('Agents are spawning agents. Make the root orchestrator the only process allowed to spawn.');
217
- }
208
+ const add = (line) => { if (!out.includes(line))
209
+ out.push(line); };
210
+ // A STOP box shows the first two lines, so each limit leads with its own
211
+ // two actions: what to do now, and the alternative. One line, one action.
218
212
  if (has('sustained_burn', 'STOP')) {
219
- out.push(`This session is at ${fmt(state.totalTokens)} tokens. Start a fresh session for the next task; do not keep extending this one.`);
220
- out.push('Compact before any further heavy work so the next call does not re-send the full history.');
221
- }
222
- else if (has('sustained_burn')) {
223
- out.push('Compact now. Every call from here re-sends the accumulated context.');
224
- }
225
- if (has('burn_debt')) {
226
- out.push('Burn is sustained above your own baseline. Narrow the task or split it into a new session.');
227
- }
213
+ add('Start a fresh session for the next task.');
214
+ add('Or /compact first, so each call stops re-sending history.');
215
+ }
216
+ if (has('fanout', 'STOP') || has('spawn_rate', 'STOP')) {
217
+ add('Let the running sub-agents finish before starting more.');
218
+ add('Give related work to one sub-agent instead of several.');
219
+ }
220
+ if (state.maxDepth >= 2)
221
+ add('Let only the main session start sub-agents.');
222
+ if (has('fanout', 'WARN')) {
223
+ const window = t.fanout.windowActiveMinutes ?? defaults_1.DEFAULT_THRESHOLDS.fanout.windowActiveMinutes;
224
+ const remaining = Math.max(0, t.fanout.stop - (0, session_1.windowSum)(state.spawnsByActiveMinute, state.activeMinutes, window));
225
+ add(`${remaining} more sub-agents fit in the next ${window} active minutes.`);
226
+ }
227
+ if (has('sustained_burn', 'WARN'))
228
+ add('Compact now, or start a fresh session soon: every call re-sends this history.');
229
+ if (has('spawn_rate', 'WARN'))
230
+ add('Start the next sub-agents after these finish.');
231
+ if (has('burn_debt'))
232
+ add('Burn is sustained above your own baseline. Narrow the task or split it into a new session.');
228
233
  if (has('account'))
229
- out.push('Pause new work across active sessions on this machine until the account window clears.');
230
- if (has('duplicate_work')) {
231
- out.push('Assign one reader per file and pass a short digest down, instead of letting every agent re-read it.');
232
- }
233
- if (has('spawn_rate')) {
234
- out.push('Queue agents instead of launching them in parallel; the limit is shared across all of them.');
235
- }
234
+ add('Pause new work across active sessions on this machine until the account window clears.');
235
+ if (has('duplicate_work'))
236
+ add('Have one agent read each file and pass a short summary down.');
236
237
  const median = (0, session_1.medianCompletedMinute)(state);
237
- if (median > 0 && (0, session_1.cacheReadRatio)(state) > 0.9) {
238
- out.push('Most of this burn is cached context re-sent per agent. Fewer, longer-lived agents beat many short ones.');
239
- }
238
+ if (median > 0 && (0, session_1.cacheReadRatio)(state) > 0.9)
239
+ add('Fewer, longer-lived sub-agents re-send less context.');
240
240
  if (out.length === 0)
241
241
  out.push('Nothing pathological. Carry on.');
242
242
  return out;
@@ -4,6 +4,7 @@ import { type BenchPanelSnapshot } from './bench-panel';
4
4
  import { type LivePanelSnapshot } from './live-panel';
5
5
  import type { AuditReport, AuditRow } from './idle/types';
6
6
  import type { BurnReport } from './types';
7
+ import { type StopHost } from './stop-text';
7
8
  import type { ReplaySummary } from './replay/simulate';
8
9
  export type AuditFrameReport = Omit<AuditReport, 'processes' | 'rows'> & {
9
10
  rows: Array<Omit<AuditRow, 'processes'>>;
@@ -23,7 +24,8 @@ export type BurnFrame = {
23
24
  kind: 'report';
24
25
  report: BurnReport;
25
26
  subject?: 'spawn' | 'call';
26
- outcome?: 'blocked' | 'shadow' | 'overridden' | 'allowed';
27
+ outcome?: 'blocked' | 'asked' | 'shadow' | 'overridden' | 'allowed';
28
+ host?: StopHost;
27
29
  } | {
28
30
  kind: 'replay';
29
31
  summary: ReplaySummary;
@@ -7,6 +7,7 @@ exports.renderFrame = renderFrame;
7
7
  const canvas_1 = require("./canvas");
8
8
  const bench_panel_1 = require("./bench-panel");
9
9
  const live_panel_1 = require("./live-panel");
10
+ const stop_text_1 = require("./stop-text");
10
11
  function auditFrame(command, report) {
11
12
  const { processes: ignored, rows, ...metadata } = report;
12
13
  return { kind: 'audit', command, report: { ...metadata, rows: rows.map(({ processes: omitted, ...row }) => row) } };
@@ -42,7 +43,7 @@ function renderFrame(data, options = {}) {
42
43
  const at = options.at ?? new Date().toISOString();
43
44
  const snapshot = (0, live_panel_1.panelFromReport)(data.report, Date.parse(at), data.outcome, data.subject), panel = (0, live_panel_1.renderLivePanel)(snapshot, options);
44
45
  panel.put(2, 0, `AGENTGUARD STOP · session ${snapshot.session} · ${at.slice(11, 19)} UTC`.padEnd(panel.width), 'red');
45
- panel.put(panel.height - 4, 0, 'override once: agentguard-burn resume --once --reason "..."', 'slate');
46
+ panel.put(panel.height - 4, 0, `continue once: ${(0, stop_text_1.continueLines)(data.host, data.subject)[1]}`, 'slate');
46
47
  return panel;
47
48
  }
48
49
  const canvas = new canvas_1.Canvas(options), w = canvas.width, h = canvas.height;
@@ -84,13 +85,13 @@ function renderFrame(data, options = {}) {
84
85
  else if (data.kind === 'report') {
85
86
  const r = data.report, color = r.verdict === 'STOP' ? 'red' : r.verdict === 'WARN' ? 'amber' : 'mint';
86
87
  canvas.put(3, 0, `AGENTGUARD ${r.verdict}`, color);
87
- canvas.put(4, 0, data.outcome === 'blocked' ? (data.subject === 'call' ? 'model call blocked' : 'agent spawn blocked') : data.outcome === 'shadow' ? 'shadow: would have blocked, call allowed' : data.outcome === 'overridden' ? 'override: call allowed' : r.verdict === 'STOP' ? 'STOP boundary · enforcement outcome not recorded' : 'session advisory', color);
88
+ canvas.put(4, 0, data.outcome === 'blocked' ? (data.subject === 'call' ? 'model call refused' : 'sub-agent launch refused') : data.outcome === 'asked' ? 'sub-agent launch held for your yes' : data.outcome === 'shadow' ? 'shadow: would have refused, call allowed' : data.outcome === 'overridden' ? 'override: call allowed' : r.verdict === 'STOP' ? 'STOP boundary · enforcement outcome not recorded' : 'session advisory', color);
88
89
  canvas.digits(6, 0, r.totals.spawns, color);
89
90
  canvas.put(10, 0, `spawns · ${r.totals.tokens.toLocaleString('en-US')} tokens · depth ${r.totals.maxDepth}`, 'slate');
90
91
  r.findings.slice(0, 5).forEach((f, i) => canvas.put(12 + i, 0, `${f.detector}: ${f.summary}`, color));
91
- canvas.put(18, 0, 'DO NOW', 'white');
92
+ canvas.put(18, 0, 'WHAT TO DO', 'white');
92
93
  r.prescriptions.slice(0, Math.max(0, h - 23)).forEach((p, i) => canvas.put(20 + i, 0, `${i + 1}. ${p}`, 'white'));
93
- canvas.put(h - 4, 0, 'override once: agentguard-burn resume --once --reason "..."', 'slate');
94
+ canvas.put(h - 4, 0, `continue once: ${(0, stop_text_1.continueLines)(data.host, data.subject)[1]}`, 'slate');
94
95
  }
95
96
  else if (data.kind === 'replay') {
96
97
  const s = data.summary, slots = Math.max(1, h - 16);
@@ -15,7 +15,7 @@
15
15
  * as little as possible.
16
16
  */
17
17
  import { type ReaderCursor, type UsageSnapshot } from '../history/claude-transcript';
18
- import type { BurnReport, SessionState } from '../types';
18
+ import type { BurnReport, Policy, SessionState } from '../types';
19
19
  export interface HookInput {
20
20
  hook_event_name?: string;
21
21
  session_id?: string;
@@ -25,6 +25,8 @@ export interface HookInput {
25
25
  tool_input?: Record<string, unknown>;
26
26
  agent_id?: string;
27
27
  agent_type?: string;
28
+ /** Claude Code's permission mode for this call: default, acceptEdits, auto, plan, dontAsk or bypassPermissions. */
29
+ permission_mode?: string;
28
30
  }
29
31
  export interface HookOutput {
30
32
  continue: true;
@@ -32,7 +34,7 @@ export interface HookOutput {
32
34
  systemMessage?: string;
33
35
  hookSpecificOutput?: {
34
36
  hookEventName: 'PreToolUse';
35
- permissionDecision: 'allow' | 'deny';
37
+ permissionDecision: 'allow' | 'deny' | 'ask';
36
38
  permissionDecisionReason: string;
37
39
  };
38
40
  }
@@ -74,5 +76,21 @@ export declare function refreshSession(home: string, sessionId: string, transcri
74
76
  notified: string;
75
77
  };
76
78
  export declare function handlePreToolUse(input: HookInput, home: string, now?: number): HookOutput;
79
+ /**
80
+ * Claude Code turns a hook's "ask" into a real permission prompt in these
81
+ * modes, and since v2.1.211 auto mode's classifier cannot approve it
82
+ * silently. bypassPermissions skips prompts, dontAsk denies them and print
83
+ * mode has nobody to ask, so those keep the hard refusal.
84
+ */
85
+ export declare function asksPerson(input: HookInput, policy: Pick<Policy, 'stopStyle'>): boolean;
86
+ /** What Claude is told when it tries to override AgentGuard itself. */
87
+ export declare const AGENT_OVERRIDE_REASON = "AgentGuard: overrides come from the person, not the agent. Ask them to type it themselves in Claude Code, with ! in front:\n! npx agentguard-burn resume --once --reason \"...\"";
88
+ /**
89
+ * An agent's own attempt to lift a STOP: running `resume`, `shadow` or
90
+ * `calibrate` (which writes a shadow policy), or writing the override or
91
+ * policy file. A person's `!` command in Claude Code never reaches a hook, so
92
+ * refusing these here never blocks the person. Returns what was targeted.
93
+ */
94
+ export declare function agentOverrideAttempt(input: HookInput, home: string): 'command' | 'file' | null;
77
95
  /** The settings.json fragment users paste in. Only PreToolUse can block. */
78
96
  export declare function settingsSnippet(command: string): Record<string, unknown>;