@agentguard-run/burn 0.3.17 → 0.3.18

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,15 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.18 (2026-09-27)
4
+
5
+ - 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`.
6
+ - 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.
7
+ - 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.
8
+ - 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."
9
+ - 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."
10
+ - 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`.
11
+ - Shadow messages read "would have refused".
12
+
3
13
  ## 0.3.17 (2026-09-27)
4
14
 
5
15
  - `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
@@ -350,12 +350,35 @@ command still exists on disk (a hook whose script is gone fails open, and
350
350
 
351
351
  ### When it stops you and you disagree
352
352
 
353
+ In an interactive Claude Code session (Manual, accept edits, auto or plan
354
+ mode) an enforced STOP holds the launch behind Claude Code's own permission
355
+ prompt. The prompt names the one limit that fired, for example:
356
+
357
+ ```
358
+ AgentGuard: 15 sub-agents in the last 15 active minutes. Limit: 15.
359
+ Session so far: 15 sub-agents, 154.0M tokens.
360
+ Allow this one launch? If you say no, nothing starts.
361
+ ```
362
+
363
+ You answer with one keypress. Claude never sees that text, and auto mode
364
+ cannot approve it silently (Claude Code 2.1.211 and later), so the answer is
365
+ yours. Where no prompt can appear (print mode, `bypassPermissions`, `dontAsk`,
366
+ Codex, Cursor) the launch is refused with the STOP box instead, and the box
367
+ ends with the override to run. In Claude Code, type it with `!` in front so it
368
+ runs in your own shell:
369
+
353
370
  ```
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
371
+ ! npx @agentguard-run/burn resume --once --reason "these 60 agents are the plan" # the next STOP passes, once, on any host
372
+ ! npx @agentguard-run/burn resume --reason "load test" # every STOP passes for 15 minutes
373
+ ! npx @agentguard-run/burn resume --clear
357
374
  ```
358
375
 
376
+ Only the person can override. A `!` command never passes through a hook, so
377
+ AgentGuard refuses the same `resume`, `shadow` or `calibrate` command when the
378
+ agent runs it, and refuses agent writes to `override.json` or
379
+ `burn-policy.json`. Set `"stopStyle": "deny"` in `burn-policy.json` to refuse
380
+ outright even where a prompt could show.
381
+
359
382
  Every override is written to the decisions ledger with its reason. A
360
383
  `--once` override is consumed atomically: two hooks racing for it cannot
361
384
  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 {
@@ -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-run/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>;
@@ -16,11 +16,13 @@
16
16
  * as little as possible.
17
17
  */
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
- exports.loadPolicy = void 0;
19
+ exports.AGENT_OVERRIDE_REASON = exports.loadPolicy = void 0;
20
20
  exports.inflateHookSession = inflateHookSession;
21
21
  exports.findingSignature = findingSignature;
22
22
  exports.refreshSession = refreshSession;
23
23
  exports.handlePreToolUse = handlePreToolUse;
24
+ exports.asksPerson = asksPerson;
25
+ exports.agentOverrideAttempt = agentOverrideAttempt;
24
26
  exports.settingsSnippet = settingsSnippet;
25
27
  const node_crypto_1 = require("node:crypto");
26
28
  const events_1 = require("../events");
@@ -36,6 +38,8 @@ const policy_1 = require("../policy");
36
38
  const override_1 = require("../override");
37
39
  const recording_1 = require("../recording");
38
40
  const render_1 = require("../replay/render");
41
+ const stop_text_1 = require("../stop-text");
42
+ const node_os_1 = require("node:os");
39
43
  const live_1 = require("../insights/live");
40
44
  const hook_1 = require("../idle/hook");
41
45
  const SPAWN_TOOLS = new Set(['Agent', 'Task']);
@@ -165,6 +169,15 @@ function handlePreToolUse(input, home, now = Date.now()) {
165
169
  const warning = (0, hook_1.sessionStartWarning)(home, (0, policy_1.loadPolicy)(home), now);
166
170
  return warning ? { continue: true, suppressOutput: false, systemMessage: warning } : { continue: true, suppressOutput: true };
167
171
  }
172
+ const attempt = agentOverrideAttempt(input, home);
173
+ if (attempt) {
174
+ const policy = (0, policy_1.loadPolicy)(home);
175
+ if (policy.mode === 'enforce') {
176
+ recordDecision(home, { host: 'claude-code', action: 'override_attempt', at: now, sessionId: input.session_id ?? null,
177
+ toolUseId: input.tool_use_id ?? null, tool: input.tool_name ?? null, target: attempt, verdict: 'STOP', enforced: true });
178
+ return deny(exports.AGENT_OVERRIDE_REASON);
179
+ }
180
+ }
168
181
  const observation = (0, live_1.observeTool)(home, input, 'claude', (0, policy_1.loadPolicy)(home), now);
169
182
  const output = handleSpawnPreToolUse(input, home, now);
170
183
  if (!observation.messages.length)
@@ -195,6 +208,8 @@ function handleSpawnPreToolUse(input, home, now) {
195
208
  // The audited override: only consulted when a block is about to happen.
196
209
  const override = shouldDeny && policy.mode === 'enforce' ? (0, override_1.consumeOverride)(home, now) : null;
197
210
  const blocked = policy.mode === 'enforce' && shouldDeny && !override;
211
+ // Held behind Claude Code's own prompt, which only the person can answer.
212
+ const asked = blocked && asksPerson(input, policy);
198
213
  const verdict = shouldDeny ? 'STOP' : report.verdict;
199
214
  const raw = JSON.parse((0, node_fs_1.readFileSync)(sessionFile(home, input.session_id), 'utf8'));
200
215
  const receipt = signer.sign({
@@ -204,7 +219,7 @@ function handleSpawnPreToolUse(input, home, now) {
204
219
  measured: { sessionTokens: state.totalTokens, sessionSpawns: reservation.effectiveSpawns,
205
220
  proposedDepth, inFlight: 0, occupiedMs: 0 },
206
221
  coverage: events_1.CAPABILITIES['claude-code'], verdict, blocked,
207
- reasons: [...report.findings.map((f) => `${f.detector}:${f.verdict}`), ...(!reservation.allowed ? ['fanout:STOP'] : [])],
222
+ reasons: [...report.findings.map((f) => `${f.detector}:${f.verdict}`), ...(!reservation.allowed ? ['fanout:STOP'] : []), ...(asked ? ['decision:ask'] : [])],
208
223
  previous: raw.lastReceipt ?? null,
209
224
  });
210
225
  store.assertHeld();
@@ -218,6 +233,8 @@ function handleSpawnPreToolUse(input, home, now) {
218
233
  verdict,
219
234
  wouldDeny: shouldDeny,
220
235
  enforced: policy.mode === 'enforce' && shouldDeny && !override,
236
+ asked: asked || undefined,
237
+ permissionMode: input.permission_mode ?? null,
221
238
  overridden: override ? { once: override.once, reason: override.reason } : undefined,
222
239
  mode: policy.mode,
223
240
  findings: report.findings.map((f) => ({ detector: f.detector, verdict: f.verdict, observed: f.observed, threshold: f.threshold })),
@@ -227,14 +244,15 @@ function handleSpawnPreToolUse(input, home, now) {
227
244
  });
228
245
  if (shouldDeny && policy.mode === 'enforce') {
229
246
  if (!override) {
230
- (0, recording_1.recordFrame)({ kind: 'report', report, outcome: 'blocked' });
247
+ if (asked) {
248
+ (0, recording_1.recordFrame)({ kind: 'report', report, outcome: 'asked', host: 'claude-code' });
249
+ return ask((0, stop_text_1.askReason)(report));
250
+ }
251
+ (0, recording_1.recordFrame)({ kind: 'report', report, outcome: 'blocked', host: 'claude-code' });
231
252
  return deny(reason);
232
253
  }
233
- (0, recording_1.recordFrame)({ kind: 'report', report, outcome: 'overridden' });
234
- return {
235
- continue: true,
236
- systemMessage: `AgentGuard STOP overridden${override.once ? ' once' : ''} ("${override.reason}"): ${report.findings[0]?.summary ?? ''}`,
237
- };
254
+ (0, recording_1.recordFrame)({ kind: 'report', report, outcome: 'overridden', host: 'claude-code' });
255
+ return { continue: true, systemMessage: (0, stop_text_1.overriddenLine)(report, override) };
238
256
  }
239
257
  if (report.verdict !== 'OK') {
240
258
  const signature = findingSignature(report);
@@ -242,10 +260,7 @@ function handleSpawnPreToolUse(input, home, now) {
242
260
  return { continue: true, suppressOutput: true };
243
261
  rememberNotified(home, input.session_id, signature);
244
262
  (0, recording_1.recordFrame)({ kind: 'report', report, outcome: policy.mode === 'shadow' && shouldDeny ? 'shadow' : 'allowed' });
245
- return {
246
- continue: true,
247
- systemMessage: `AgentGuard ${report.verdict}${policy.mode === 'shadow' && shouldDeny ? ' (shadow: would have blocked)' : ''}: ${report.findings[0]?.summary ?? ''}`,
248
- };
263
+ return { continue: true, systemMessage: warnLine(report, policy, input, shouldDeny) };
249
264
  }
250
265
  if (notified)
251
266
  rememberNotified(home, input.session_id, '');
@@ -264,7 +279,63 @@ function buildDenyReason(report, _reservation) {
264
279
  // sentence reads as a log line. Colour is off: the host decides rendering.
265
280
  // Claude trims leading whitespace before adding Error:. A zero-width word
266
281
  // joiner preserves the blank first line, keeping that prefix off the frame.
267
- return '\u2060\n' + (0, render_1.renderStop)(report, { colour: false });
282
+ return '\u2060\n' + (0, render_1.renderStop)(report, { colour: false, host: 'claude-code' });
283
+ }
284
+ const ASK_MODES = new Set(['default', 'acceptEdits', 'auto', 'plan']);
285
+ /**
286
+ * Claude Code turns a hook's "ask" into a real permission prompt in these
287
+ * modes, and since v2.1.211 auto mode's classifier cannot approve it
288
+ * silently. bypassPermissions skips prompts, dontAsk denies them and print
289
+ * mode has nobody to ask, so those keep the hard refusal.
290
+ */
291
+ function asksPerson(input, policy) {
292
+ return (policy.stopStyle ?? 'ask') === 'ask' && typeof input.permission_mode === 'string' && ASK_MODES.has(input.permission_mode);
293
+ }
294
+ const WARN_CONSEQUENCE = new Set(['spawn_rate', 'fanout', 'sustained_burn']);
295
+ function warnLine(report, policy, input, shouldDeny) {
296
+ const shadow = policy.mode === 'shadow' && shouldDeny ? ' (shadow: would have refused)' : '';
297
+ const warn = report.verdict === 'WARN' ? report.findings.find((f) => f.verdict === 'WARN') : undefined;
298
+ const consequence = policy.mode === 'enforce' && warn && WARN_CONSEQUENCE.has(warn.detector)
299
+ ? (asksPerson(input, policy) ? ' Past the limit, the next launch waits for your yes.' : ' Past the limit, the next launch is refused.')
300
+ : '';
301
+ return `AgentGuard ${report.verdict}${shadow}: ${(0, stop_text_1.primarySummary)(report)}${consequence}`;
302
+ }
303
+ /** What Claude is told when it tries to override AgentGuard itself. */
304
+ exports.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! ${stop_text_1.OVERRIDE_COMMAND}`;
305
+ const OVERRIDE_VERB = /(?:@agentguard-run\/burn|agentguard-burn)\S*\s+(?:resume|shadow|calibrate)\b/;
306
+ const STATE_FILE = /\.agentguard[\\/](?:override|burn-policy)\.json\b/;
307
+ /**
308
+ * An agent's own attempt to lift a STOP: running `resume`, `shadow` or
309
+ * `calibrate` (which writes a shadow policy), or writing the override or
310
+ * policy file. A person's `!` command in Claude Code never reaches a hook, so
311
+ * refusing these here never blocks the person. Returns what was targeted.
312
+ */
313
+ function agentOverrideAttempt(input, home) {
314
+ const tool = input.tool_name ?? '';
315
+ const args = input.tool_input ?? {};
316
+ const own = (path) => {
317
+ const full = (0, node_path_1.resolve)(path.replace(/^~(?=$|[\\/])/, (0, node_os_1.homedir)()));
318
+ return full === (0, node_path_1.resolve)(home, 'override.json') || full === (0, node_path_1.resolve)(home, 'burn-policy.json');
319
+ };
320
+ if (tool === 'Bash' || tool === 'PowerShell') {
321
+ const command = typeof args.command === 'string' ? args.command : '';
322
+ if (OVERRIDE_VERB.test(command) || STATE_FILE.test(command)
323
+ || command.includes((0, node_path_1.resolve)(home, 'override.json')) || command.includes((0, node_path_1.resolve)(home, 'burn-policy.json')))
324
+ return 'command';
325
+ return null;
326
+ }
327
+ if (tool === 'Write' || tool === 'Edit' || tool === 'MultiEdit' || tool === 'NotebookEdit') {
328
+ const path = typeof args.file_path === 'string' ? args.file_path : typeof args.notebook_path === 'string' ? args.notebook_path : '';
329
+ if (path && (own(path) || STATE_FILE.test(path)))
330
+ return 'file';
331
+ }
332
+ return null;
333
+ }
334
+ function ask(reason) {
335
+ return {
336
+ continue: true,
337
+ hookSpecificOutput: { hookEventName: 'PreToolUse', permissionDecision: 'ask', permissionDecisionReason: reason },
338
+ };
268
339
  }
269
340
  function deny(reason) {
270
341
  return {
@@ -7,8 +7,9 @@ export { applyEvent, applyCorrection, newSessionState, windowSum, medianComplete
7
7
  export { ReservationStore, Transaction, RESERVATION_TTL_MS, type Reservation, type CallReservation, type ComputeSnapshot } from './state/reservations';
8
8
  export { replayAll, replaySession, replayEvents, discoverTranscripts, type ReplaySummary, type SessionReplay } from './replay/simulate';
9
9
  export { renderReplay, renderStop } from './replay/render';
10
+ export { askReason, continueLines, overriddenLine, primarySummary, sessionSoFar, stopSummary, OVERRIDE_COMMAND, type StopHost } from './stop-text';
10
11
  export { calibrate, type CalibrationResult } from './calibrate';
11
- export { handlePreToolUse, refreshSession, loadPolicy, settingsSnippet, type HookInput, type HookOutput } from './hook/pre-tool-use';
12
+ export { handlePreToolUse, refreshSession, loadPolicy, settingsSnippet, asksPerson, agentOverrideAttempt, AGENT_OVERRIDE_REASON, type HookInput, type HookOutput } from './hook/pre-tool-use';
12
13
  export * from './events';
13
14
  export { Gateway, mergeCapabilities, type Decision, type GatewaySessionView, type UsageCoverage, type GatewayOptions } from './gateway';
14
15
  export { ReceiptSigner, verifyReceipt, receiptDigest, canonical, sha256, type ReceiptPayload, type SignedReceipt } from './receipt';
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.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.settingsSnippet = exports.loadPolicy = exports.refreshSession = exports.handlePreToolUse = exports.calibrate = 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 = void 0;
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;
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; } });
@@ -51,6 +51,14 @@ Object.defineProperty(exports, "discoverTranscripts", { enumerable: true, get: f
51
51
  var render_1 = require("./replay/render");
52
52
  Object.defineProperty(exports, "renderReplay", { enumerable: true, get: function () { return render_1.renderReplay; } });
53
53
  Object.defineProperty(exports, "renderStop", { enumerable: true, get: function () { return render_1.renderStop; } });
54
+ var stop_text_1 = require("./stop-text");
55
+ Object.defineProperty(exports, "askReason", { enumerable: true, get: function () { return stop_text_1.askReason; } });
56
+ Object.defineProperty(exports, "continueLines", { enumerable: true, get: function () { return stop_text_1.continueLines; } });
57
+ Object.defineProperty(exports, "overriddenLine", { enumerable: true, get: function () { return stop_text_1.overriddenLine; } });
58
+ Object.defineProperty(exports, "primarySummary", { enumerable: true, get: function () { return stop_text_1.primarySummary; } });
59
+ Object.defineProperty(exports, "sessionSoFar", { enumerable: true, get: function () { return stop_text_1.sessionSoFar; } });
60
+ Object.defineProperty(exports, "stopSummary", { enumerable: true, get: function () { return stop_text_1.stopSummary; } });
61
+ Object.defineProperty(exports, "OVERRIDE_COMMAND", { enumerable: true, get: function () { return stop_text_1.OVERRIDE_COMMAND; } });
54
62
  var calibrate_1 = require("./calibrate");
55
63
  Object.defineProperty(exports, "calibrate", { enumerable: true, get: function () { return calibrate_1.calibrate; } });
56
64
  var pre_tool_use_1 = require("./hook/pre-tool-use");
@@ -58,6 +66,9 @@ Object.defineProperty(exports, "handlePreToolUse", { enumerable: true, get: func
58
66
  Object.defineProperty(exports, "refreshSession", { enumerable: true, get: function () { return pre_tool_use_1.refreshSession; } });
59
67
  Object.defineProperty(exports, "loadPolicy", { enumerable: true, get: function () { return pre_tool_use_1.loadPolicy; } });
60
68
  Object.defineProperty(exports, "settingsSnippet", { enumerable: true, get: function () { return pre_tool_use_1.settingsSnippet; } });
69
+ Object.defineProperty(exports, "asksPerson", { enumerable: true, get: function () { return pre_tool_use_1.asksPerson; } });
70
+ Object.defineProperty(exports, "agentOverrideAttempt", { enumerable: true, get: function () { return pre_tool_use_1.agentOverrideAttempt; } });
71
+ Object.defineProperty(exports, "AGENT_OVERRIDE_REASON", { enumerable: true, get: function () { return pre_tool_use_1.AGENT_OVERRIDE_REASON; } });
61
72
  // Cross-tool layer (0.2.0)
62
73
  __exportStar(require("./events"), exports);
63
74
  var gateway_1 = require("./gateway");
@@ -46,7 +46,7 @@ export declare function renderShowcasePanel(snapshot: LivePanelSnapshot, options
46
46
  export declare function renderPhonePanel(snapshot: LivePanelSnapshot, options?: FrameOptions): Canvas;
47
47
  export declare function renderLivePanel(snapshot: LivePanelSnapshot, options?: FrameOptions): Canvas;
48
48
  /** STOP report adaptation uses only already-computed metadata, never local I/O. */
49
- export declare function panelFromReport(report: BurnReport, at: number, outcome?: 'blocked' | 'shadow' | 'overridden' | 'allowed', subject?: 'spawn' | 'call'): LivePanelSnapshot;
49
+ export declare function panelFromReport(report: BurnReport, at: number, outcome?: 'blocked' | 'asked' | 'shadow' | 'overridden' | 'allowed', subject?: 'spawn' | 'call'): LivePanelSnapshot;
50
50
  /** Display-only hold. Intake continues and the latest observation follows the card. */
51
51
  export declare class StopHold {
52
52
  private held?;
@@ -90,7 +90,7 @@ function renderShowcasePanel(snapshot, options = {}) {
90
90
  for (let i = 0; i < 5; i++)
91
91
  c.put(top + i, right, ' '.repeat(room), 'none');
92
92
  c.put(top - 1, right, '─'.repeat(room), 'red');
93
- c.put(top, right, 'STOP · ' + (snapshot.stop.blocked === true ? 'blocked' : snapshot.stop.blocked === false ? 'shadow / allowed' : 'outcome unknown'), 'red');
93
+ c.put(top, right, 'STOP · ' + (snapshot.stop.blocked === true ? 'refused' : snapshot.stop.blocked === false ? 'shadow / allowed' : 'outcome unknown'), 'red');
94
94
  c.put(top + 1, right, snapshot.stop.reason.slice(0, room), 'red');
95
95
  c.put(top + 2, right, snapshot.stopHold === false ? 'Latest STOP reason.' : 'Reason held for 2 seconds.', 'slate');
96
96
  c.put(top + 3, right, '─'.repeat(room), 'red');
@@ -141,7 +141,7 @@ function renderPhonePanel(snapshot, options = {}) {
141
141
  c.put(29, 0, (options.label ? options.label.toUpperCase() : 'Each copy runs its own context window.').slice(0, w), options.label ? 'slate' : 'white');
142
142
  if (snapshot.stop) {
143
143
  c.put(30, 0, '─'.repeat(w), 'red');
144
- c.put(31, 0, ('STOP · ' + (snapshot.stop.blocked === true ? 'blocked' : snapshot.stop.blocked === false ? 'shadow / allowed' : 'outcome unknown') + ' · ' + snapshot.stop.reason).slice(0, w), 'red');
144
+ c.put(31, 0, ('STOP · ' + (snapshot.stop.blocked === true ? 'refused' : snapshot.stop.blocked === false ? 'shadow / allowed' : 'outcome unknown') + ' · ' + snapshot.stop.reason).slice(0, w), 'red');
145
145
  c.put(32, 0, '─'.repeat(w), 'red');
146
146
  }
147
147
  c.put(33, 0, 'At the ceiling, the attempt is refused.'.slice(0, w), 'white');
@@ -186,7 +186,7 @@ function renderLivePanel(snapshot, options = {}) {
186
186
  const y = h >= 30 ? h - 11 : 16;
187
187
  for (let i = 0; i < 5; i++)
188
188
  c.put(y + i, right, ' '.repeat(room), 'none');
189
- c.put(y, right, 'STOP · ' + (snapshot.stop.blocked === true ? 'blocked' : snapshot.stop.blocked === false ? 'shadow / allowed' : 'outcome unknown'), 'red');
189
+ c.put(y, right, 'STOP · ' + (snapshot.stop.blocked === true ? 'refused' : snapshot.stop.blocked === false ? 'shadow / allowed' : 'outcome unknown'), 'red');
190
190
  c.put(y + 1, right, snapshot.stop.reason.slice(0, room), 'red');
191
191
  c.put(y + 2, right, snapshot.stopHold === false ? 'Latest STOP reason.' : 'Reason held for 2 seconds.', 'slate');
192
192
  }
@@ -197,10 +197,11 @@ function renderLivePanel(snapshot, options = {}) {
197
197
  function panelFromReport(report, at, outcome, subject) {
198
198
  const rate = report.findings.find(f => f.detector === 'spawn_rate');
199
199
  const decision = { id: digest(`${report.sessionId}:${at}`), at, tool: subject === 'call' ? 'model_call' : 'spawn', verdict: report.verdict,
200
- reason: report.findings.map(f => `${f.detector}:${f.verdict} ${f.observed}/${f.threshold}`).join(' + ') || 'Reason not recorded.', blocked: outcome === undefined ? null : outcome === 'blocked' };
201
- const note = outcome === 'blocked' ? (subject === 'call' ? 'model call blocked' : 'agent spawn blocked')
202
- : outcome === 'shadow' ? 'shadow: would have blocked, call allowed' : outcome === 'overridden' ? 'override: call allowed'
203
- : outcome === 'allowed' ? 'call allowed' : 'STOP boundary · enforcement outcome not recorded';
200
+ reason: report.findings.map(f => `${f.detector}:${f.verdict} ${f.observed}/${f.threshold}`).join(' + ') || 'Reason not recorded.', blocked: outcome === undefined ? null : outcome === 'blocked' || outcome === 'asked' };
201
+ const note = outcome === 'blocked' ? (subject === 'call' ? 'model call refused' : 'sub-agent launch refused')
202
+ : outcome === 'asked' ? 'sub-agent launch held for your yes'
203
+ : outcome === 'shadow' ? 'shadow: would have refused, call allowed' : outcome === 'overridden' ? 'override: call allowed'
204
+ : outcome === 'allowed' ? 'call allowed' : 'STOP boundary · enforcement outcome not recorded';
204
205
  return { session: (/^[A-Za-z0-9_-]+$/.test(report.sessionId) ? report.sessionId : digest(report.sessionId)).slice(0, 8), startedAt: at, observedAt: at, elapsedMs: null, controls: false, stopHold: false,
205
206
  spawns: rate?.observed ?? null, tokens: null, replayShare: Number.isFinite(report.cacheReadRatio) ? report.cacheReadRatio : null,
206
207
  windowActiveMinutes: null, spawnCeiling: rate?.verdict === 'STOP' ? rate.threshold : null,
@@ -4,6 +4,7 @@
4
4
  * runaway in, one line worth quoting. Pure ASCII/ANSI, degrades cleanly.
5
5
  */
6
6
  import type { BurnReport } from '../types';
7
+ import { type StopHost } from '../stop-text';
7
8
  import type { ReplaySummary, SessionReplay } from './simulate';
8
9
  export declare function sparkline(curve: number[], stopAt: number | null, on: boolean): string;
9
10
  export declare function comparison(tokens: number): string;
@@ -14,5 +15,6 @@ export declare function renderReplay(summary: ReplaySummary, opts?: {
14
15
  export declare function renderStop(report: BurnReport, opts?: {
15
16
  colour?: boolean;
16
17
  subject?: 'spawn' | 'call';
18
+ host?: StopHost;
17
19
  }): string;
18
20
  export declare function renderSessionRow(s: SessionReplay): string;
@@ -12,6 +12,7 @@ exports.renderStop = renderStop;
12
12
  exports.renderSessionRow = renderSessionRow;
13
13
  const frames_1 = require("../frames");
14
14
  const evaluate_1 = require("../detectors/evaluate");
15
+ const stop_text_1 = require("../stop-text");
15
16
  const C = {
16
17
  reset: '\x1b[0m',
17
18
  bold: '\x1b[1m',
@@ -179,27 +180,29 @@ function renderReplay(summary, opts = {}) {
179
180
  function renderStop(report, opts = {}) {
180
181
  const on = opts.colour ?? false;
181
182
  if (on)
182
- return (0, frames_1.renderFrame)({ kind: 'report', report, subject: opts.subject, outcome: 'blocked' }, { colour: true }).render();
183
- const lead = report.findings.find((f) => f.verdict === 'STOP')?.summary ?? 'Fan-out ceiling reached.';
183
+ return (0, frames_1.renderFrame)({ kind: 'report', report, subject: opts.subject, outcome: 'blocked', host: opts.host }, { colour: true }).render();
184
184
  const w = 64;
185
185
  const bar = '─'.repeat(w);
186
- const title = opts.subject === 'call' ? ' model call blocked' : ' agent spawn blocked';
186
+ const title = opts.subject === 'call' ? ' model call refused' : ' sub-agent launch refused';
187
+ // One cause, one context line, two actions, one way to continue.
188
+ const row = (text, style = '') => paint(on, C.red, '│ ') + paint(on, style, text.padEnd(w - 1).slice(0, w - 1)) + paint(on, C.red, '│');
187
189
  const lines = [];
188
190
  lines.push(paint(on, C.red, `┌${bar}┐`));
189
191
  lines.push(paint(on, C.red, '│ ') + paint(on, C.bold + C.bgRed + C.white, ' AGENTGUARD STOP ') + paint(on, C.bold, title) + paint(on, C.red, ' '.repeat(w - 18 - title.length) + '│'));
190
192
  lines.push(paint(on, C.red, `├${bar}┤`));
191
- lines.push(paint(on, C.red, '│ ') + lead.padEnd(w - 1).slice(0, w - 1) + paint(on, C.red, '│'));
192
- lines.push(paint(on, C.red, '│ ') + paint(on, C.dim, `${(0, evaluate_1.fmt)(report.totals.tokens)} tokens · ${report.totals.spawns} spawns · depth ${report.totals.maxDepth}`.padEnd(w - 1)) + paint(on, C.red, '│'));
193
+ for (const line of wrap((0, stop_text_1.stopSummary)(report), w - 1, ''))
194
+ lines.push(row(line));
195
+ lines.push(row((0, stop_text_1.sessionSoFar)(report, opts.subject), C.dim));
193
196
  lines.push(paint(on, C.red, `├${bar}┤`));
194
- lines.push(paint(on, C.red, '│ ') + paint(on, C.bold, 'DO NOW'.padEnd(w - 1)) + paint(on, C.red, '│'));
195
- report.prescriptions.slice(0, 3).forEach((p, i) => {
196
- const wrapped = wrap(`${i + 1}. ${p}`, w - 2, ' ');
197
- for (const line of wrapped) {
198
- lines.push(paint(on, C.red, '│ ') + line.padEnd(w - 1) + paint(on, C.red, '│'));
199
- }
197
+ lines.push(row('WHAT TO DO', C.bold));
198
+ report.prescriptions.slice(0, 2).forEach((p, i) => {
199
+ for (const line of wrap(`${i + 1}. ${p}`, w - 2, ' '))
200
+ lines.push(row(line));
200
201
  });
201
202
  lines.push(paint(on, C.red, `├${bar}┤`));
202
- lines.push(paint(on, C.red, '│ ') + paint(on, C.dim, 'override once: agentguard-burn resume --once --reason "..."'.padEnd(w - 1)) + paint(on, C.red, '│'));
203
+ const [label, command] = (0, stop_text_1.continueLines)(opts.host, opts.subject);
204
+ lines.push(row(label, C.dim));
205
+ lines.push(row(command));
203
206
  lines.push(paint(on, C.red, `└${bar}┘`));
204
207
  return lines.join('\n');
205
208
  }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * The words of a STOP, shared by every surface that shows one: the plain box
3
+ * a hook returns, the canvas frame, the permission prompt, the override
4
+ * confirmation and each host adapter. One source keeps them from drifting
5
+ * apart. On Sep 26 2026 the box named the token limit while the override
6
+ * confirmation quoted the first finding in the list, a fan-out warning with
7
+ * a different number, so one refusal showed three different limits.
8
+ */
9
+ import type { BurnReport } from './types';
10
+ /** Where the person continues from. */
11
+ export type StopHost = 'claude-code' | 'codex' | 'cursor';
12
+ /**
13
+ * The override the person runs. The scoped package name works for everyone,
14
+ * including plugin-only installs that never put `agentguard-burn` on PATH.
15
+ */
16
+ export declare const OVERRIDE_COMMAND = "npx @agentguard-run/burn resume --once --reason \"...\"";
17
+ /** The one limit that stopped this launch, in its own words and numbers. */
18
+ export declare function stopSummary(report: BurnReport): string;
19
+ /** The finding a one-line message should lead with: the STOP, else the first WARN, else the first finding. */
20
+ export declare function primarySummary(report: BurnReport): string;
21
+ export declare function sessionSoFar(report: BurnReport, subject?: 'spawn' | 'call'): string;
22
+ /**
23
+ * How the person continues once. In Claude Code a command typed with `!` runs
24
+ * in the person's own shell and never passes through a hook, so it is the
25
+ * person's key; the same command attempted by the agent is refused.
26
+ */
27
+ export declare function continueLines(host: StopHost | undefined, subject?: 'spawn' | 'call'): [string, string];
28
+ /**
29
+ * The text of Claude Code's permission prompt when a STOP holds a launch.
30
+ * Claude Code shows this to the person and not to Claude.
31
+ */
32
+ export declare function askReason(report: BurnReport): string;
33
+ /** The line after a person-approved override, naming the limit it passed. */
34
+ export declare function overriddenLine(report: BurnReport, override: {
35
+ once: boolean;
36
+ reason: string;
37
+ }): string;
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OVERRIDE_COMMAND = void 0;
4
+ exports.stopSummary = stopSummary;
5
+ exports.primarySummary = primarySummary;
6
+ exports.sessionSoFar = sessionSoFar;
7
+ exports.continueLines = continueLines;
8
+ exports.askReason = askReason;
9
+ exports.overriddenLine = overriddenLine;
10
+ /**
11
+ * The override the person runs. The scoped package name works for everyone,
12
+ * including plugin-only installs that never put `agentguard-burn` on PATH.
13
+ */
14
+ exports.OVERRIDE_COMMAND = 'npx @agentguard-run/burn resume --once --reason "..."';
15
+ function fmt(n) {
16
+ if (n >= 1e9)
17
+ return `${(n / 1e9).toFixed(2)}B`;
18
+ if (n >= 1e6)
19
+ return `${(n / 1e6).toFixed(1)}M`;
20
+ if (n >= 1e3)
21
+ return `${(n / 1e3).toFixed(0)}K`;
22
+ return String(Math.round(n));
23
+ }
24
+ /** The one limit that stopped this launch, in its own words and numbers. */
25
+ function stopSummary(report) {
26
+ return report.findings.find((f) => f.verdict === 'STOP')?.summary
27
+ ?? 'Sub-agents starting right now would pass the fan-out limit.';
28
+ }
29
+ /** The finding a one-line message should lead with: the STOP, else the first WARN, else the first finding. */
30
+ function primarySummary(report) {
31
+ return (report.findings.find((f) => f.verdict === 'STOP') ?? report.findings.find((f) => f.verdict === 'WARN') ?? report.findings[0])?.summary ?? '';
32
+ }
33
+ function sessionSoFar(report, subject = 'spawn') {
34
+ return subject === 'call'
35
+ ? `Session so far: ${fmt(report.totals.tokens)} tokens.`
36
+ : `Session so far: ${report.totals.spawns} sub-agents, ${fmt(report.totals.tokens)} tokens.`;
37
+ }
38
+ /**
39
+ * How the person continues once. In Claude Code a command typed with `!` runs
40
+ * in the person's own shell and never passes through a hook, so it is the
41
+ * person's key; the same command attempted by the agent is refused.
42
+ */
43
+ function continueLines(host, subject = 'spawn') {
44
+ const what = subject === 'call' ? 'send it' : 'launch it';
45
+ return host === 'claude-code'
46
+ ? [`To ${what} anyway, once, type this yourself:`, `! ${exports.OVERRIDE_COMMAND}`]
47
+ : [`To ${what} anyway, once, run this in a terminal:`, exports.OVERRIDE_COMMAND];
48
+ }
49
+ /**
50
+ * The text of Claude Code's permission prompt when a STOP holds a launch.
51
+ * Claude Code shows this to the person and not to Claude.
52
+ */
53
+ function askReason(report) {
54
+ return `AgentGuard: ${stopSummary(report)}\n${sessionSoFar(report)}\nAllow this one launch? If you say no, nothing starts.`;
55
+ }
56
+ /** The line after a person-approved override, naming the limit it passed. */
57
+ function overriddenLine(report, override) {
58
+ return `AgentGuard STOP overridden${override.once ? ' once' : ''} ("${override.reason}"): ${stopSummary(report)}`;
59
+ }
@@ -147,6 +147,15 @@ export interface Policy {
147
147
  teamPolicyFile?: string;
148
148
  mode: Mode;
149
149
  thresholds: Thresholds;
150
+ /**
151
+ * How an enforced STOP reaches the person in an interactive Claude Code
152
+ * session. "ask" (the default) holds the launch behind Claude Code's own
153
+ * permission prompt: the person answers with one keypress, Claude never sees
154
+ * the reason, and auto mode cannot approve it silently. "deny" refuses
155
+ * outright everywhere. Hosts and modes that cannot show a prompt (print
156
+ * mode, bypassPermissions, dontAsk, Codex, Cursor) always refuse.
157
+ */
158
+ stopStyle?: 'ask' | 'deny';
150
159
  /** Additive local usage advisories. Older policy files use these defaults. */
151
160
  insights?: {
152
161
  rewriteWarnDollarsPerHour?: number;
@@ -22,7 +22,7 @@ REPLAY SHARE % │ spawn_rate:WARN
22
22
  │
23
23
  session cache-read / tokens │
24
24
  │
25
- │ STOP · blocked
25
+ │ STOP · refused
26
26
  │ spawn_rate:STOP
27
27
  │ Reason held for 2 seconds.
28
28
  │
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentguard-run/burn",
3
- "version": "0.3.17",
3
+ "version": "0.3.18",
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
  "type": "commonjs",