@agentguard-run/burn 0.3.16 → 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 +18 -0
- package/README.md +28 -3
- package/dist/src/adapters/codex.js +4 -3
- package/dist/src/adapters/cursor.js +4 -3
- package/dist/src/cli.js +33 -2
- package/dist/src/conformance.js +2 -2
- package/dist/src/detectors/evaluate.js +36 -36
- package/dist/src/frames.d.ts +3 -1
- package/dist/src/frames.js +5 -4
- package/dist/src/hook/pre-tool-use.d.ts +20 -2
- package/dist/src/hook/pre-tool-use.js +84 -13
- package/dist/src/index.d.ts +2 -1
- package/dist/src/index.js +13 -2
- package/dist/src/insights/i18n.d.ts +65 -0
- package/dist/src/insights/i18n.js +152 -0
- package/dist/src/insights/live.d.ts +5 -1
- package/dist/src/insights/live.js +3 -2
- package/dist/src/insights/render.d.ts +5 -2
- package/dist/src/insights/render.js +29 -36
- package/dist/src/live-panel.d.ts +1 -1
- package/dist/src/live-panel.js +8 -7
- package/dist/src/replay/render.d.ts +2 -0
- package/dist/src/replay/render.js +15 -12
- package/dist/src/stop-text.d.ts +37 -0
- package/dist/src/stop-text.js +59 -0
- package/dist/src/types.d.ts +9 -0
- package/fixtures/live-sep20-stop-104x35.txt +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
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
|
+
|
|
13
|
+
## 0.3.17 (2026-09-27)
|
|
14
|
+
|
|
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`).
|
|
16
|
+
- The language is chosen in this order, first match wins: `why --lang en|es|pt` (also `--lang=es`), the `AGENTGUARD_LANG` variable, then the POSIX message locale in its own precedence (`LC_ALL`, then `LC_MESSAGES`, then `LANG`, taking the part before `_` or `.`, so `es_MX.UTF-8` and `es_419` are Spanish and `pt_BR` and `pt_PT` are Portuguese), then the locale Node resolves through Intl (on Windows the only one). The first of these that is set decides, as it does for any POSIX program: `LC_ALL=C` over `LANG=es_PA.UTF-8` is English. `C`, `POSIX` and every other language are English. An unsupported or missing `--lang` value exits 64 with a usage line.
|
|
17
|
+
- Figures keep their en-US formatting in every language, deliberately: `1,234,567` tokens, `$1335.37`, `12.3%`, so a Spanish or Portuguese report matches screenshots and the site digit for digit. Session ids, model ids, commands (`npx @agentguard-run/burn rewrites`, `quiet on`), URLs, product names and the term fan-out stay as they are.
|
|
18
|
+
- What changes in output: only the plain `why` report, and only when the language resolves to Spanish or Portuguese. English output is byte-identical to 0.3.16 with tips on and off. `why json` is byte-identical to 0.3.16 in every language, and the frame `--record` writes for `why` is unchanged. Only `why` is translated in this release; every other command, the help and `quiet` print English as before. The help gains one line for `--lang`.
|
|
19
|
+
- Tests that spawn `why` and assert English now pin `AGENTGUARD_LANG=en`, so the suite passes on a machine whose locale is Spanish or Portuguese.
|
|
20
|
+
|
|
3
21
|
## 0.3.16 (2026-09-27)
|
|
4
22
|
|
|
5
23
|
- `why` ends with at most one tip built from the session's own numbers, first match wins: sub-agent fan-out at 20% or more of session tokens names that share and points at spawn limits (free on one machine, agentguard.run/try); full-prefix rewrites at 15% or more of the session's API list equivalent name both dollar figures and point at `rewrites`, which gives the cause of each one (skipped when either figure is unpriced; a dollar range compares midpoints, as the `rewrites` share does); history re-sent at 30% or more of session tokens names that share and says a fresh session, or `/compact`, starts that history over. The share and dollars are the ones the table prints. When nothing reaches its threshold there is no line, and a Codex session whose inherited history has no verifiable boundary prints none.
|
package/README.md
CHANGED
|
@@ -202,6 +202,8 @@ The table covers instruction stack + system, history re-sent, repeated file read
|
|
|
202
202
|
|
|
203
203
|
The report ends with at most one tip from the session's own numbers, first match wins: subagent fan-out at 20% or more of session tokens, full-prefix rewrites at 15% or more of the session's API list equivalent (skipped when a model is unpriced), history re-sent at 30% or more of session tokens. The tip quotes the share or dollars the table prints and names one next step. When nothing reaches its threshold there is no tip. `agentguard-burn quiet on` hides it, `quiet off` shows it again and `quiet` says which. `why json` never contains it.
|
|
204
204
|
|
|
205
|
+
`why` prints in Latin American Spanish or Brazilian Portuguese when your machine is set to that language, and `--lang es`, `--lang pt` or `--lang en` picks one explicitly. The order is `--lang`, then `AGENTGUARD_LANG`, then `LC_ALL`, `LC_MESSAGES` and `LANG` (the first one set decides, as POSIX says, so `LC_ALL=C` means English), then the locale Node resolves. Every other language is English. Figures keep their en-US formatting in every language (`1,234,567`, `$1335.37`, `12.3%`), so a translated report matches screenshots digit for digit. Only `why` is translated: `why json` is the same in every language, and every other command stays English.
|
|
206
|
+
|
|
205
207
|
Later cache reads up to the baseline go to instruction stack + system. Reads above it go to history re-sent. Fresh input plus cache creation is the measured arriving increment. Burn subtracts the previous response's output before assigning that increment to intervening tool results and user messages. Result byte sizes only split that measured total; bytes are never converted into tokens. A result for a previously read Read path goes to re-read files. Mixed user and tool intervals are marked shared and counted in the footer.
|
|
206
208
|
|
|
207
209
|
Rewrite tokens and child transcript usage keep their own buckets. Prior output deducted from an input increment remains in the unattributed residual so every recorded input and output token is counted exactly once. Missing event evidence also remains there. Integer allocation preserves every token, and the Method footer explains each row.
|
|
@@ -348,12 +350,35 @@ command still exists on disk (a hook whose script is gone fails open, and
|
|
|
348
350
|
|
|
349
351
|
### When it stops you and you disagree
|
|
350
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
|
+
|
|
351
357
|
```
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
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.
|
|
355
361
|
```
|
|
356
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
|
+
|
|
370
|
+
```
|
|
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
|
|
374
|
+
```
|
|
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
|
+
|
|
357
382
|
Every override is written to the decisions ledger with its reason. A
|
|
358
383
|
`--once` override is consumed atomically: two hooks racing for it cannot
|
|
359
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:
|
|
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
|
|
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
|
|
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:
|
|
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
|
@@ -80,6 +80,7 @@ const attribution_1 = require("./insights/attribution");
|
|
|
80
80
|
const pricing_1 = require("./insights/pricing");
|
|
81
81
|
const transcript_2 = require("./insights/transcript");
|
|
82
82
|
const render_2 = require("./insights/render");
|
|
83
|
+
const i18n_1 = require("./insights/i18n");
|
|
83
84
|
const ttl_1 = require("./insights/ttl");
|
|
84
85
|
const blocks_1 = require("./insights/blocks");
|
|
85
86
|
const cli_1 = require("./idle/cli");
|
|
@@ -87,6 +88,15 @@ const HOME = process.env.AGENTGUARD_HOME ?? (0, node_path_1.join)((0, node_os_1.
|
|
|
87
88
|
const PROXY_HOSTS = ['ollama', 'vllm', 'lm-studio', 'openai-compatible'];
|
|
88
89
|
/** The same flag file the AgentGuard plugin reads (runtime/upgrade-moments.cjs), so one switch silences both. */
|
|
89
90
|
const quietOn = () => (0, node_fs_1.existsSync)((0, upgrade_moments_1.quietFile)(HOME));
|
|
91
|
+
/** The locale Node resolved, the last fallback for the why report's language (on Windows it is the only one). */
|
|
92
|
+
const intlLocale = () => {
|
|
93
|
+
try {
|
|
94
|
+
return Intl.DateTimeFormat().resolvedOptions().locale;
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
return undefined;
|
|
98
|
+
}
|
|
99
|
+
};
|
|
90
100
|
function readStdinJson() {
|
|
91
101
|
try {
|
|
92
102
|
return JSON.parse((0, node_fs_1.readFileSync)(0, 'utf8'));
|
|
@@ -195,9 +205,29 @@ async function main(argv) {
|
|
|
195
205
|
return 0;
|
|
196
206
|
}
|
|
197
207
|
case 'why': {
|
|
198
|
-
|
|
208
|
+
// `--lang en|es|pt` (or --lang=es) picks the report's language and is never a session selector.
|
|
209
|
+
const args = [];
|
|
210
|
+
let lang, langGiven = false;
|
|
211
|
+
for (let i = 0; i < rest.length; i++) {
|
|
212
|
+
if (rest[i] === '--lang') {
|
|
213
|
+
langGiven = true;
|
|
214
|
+
lang = rest[++i];
|
|
215
|
+
}
|
|
216
|
+
else if (rest[i].startsWith('--lang=')) {
|
|
217
|
+
langGiven = true;
|
|
218
|
+
lang = rest[i].slice('--lang='.length);
|
|
219
|
+
}
|
|
220
|
+
else
|
|
221
|
+
args.push(rest[i]);
|
|
222
|
+
}
|
|
223
|
+
if (langGiven && (0, i18n_1.whyLangOf)(lang) === null) {
|
|
224
|
+
process.stderr.write('Usage: agentguard-burn why [session] [json] [--lang en|es|pt]\n');
|
|
225
|
+
return 64;
|
|
226
|
+
}
|
|
227
|
+
const location = (0, sessions_1.selectInsightTranscript)(args.find(value => value !== 'json'));
|
|
199
228
|
const transcript = (0, transcript_1.readInsightSession)(location.path, { host: location.host, sessionId: location.sessionId });
|
|
200
|
-
|
|
229
|
+
const json = args.includes('json');
|
|
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);
|
|
201
231
|
return 0;
|
|
202
232
|
}
|
|
203
233
|
case 'quiet': {
|
|
@@ -475,6 +505,7 @@ async function main(argv) {
|
|
|
475
505
|
' limits [session|all] local plan walls and prior Burn decisions\n' +
|
|
476
506
|
' price-shadow [session|all] local child list-price exposure and sensitivity\n' +
|
|
477
507
|
' why [session] token attribution and API list-price equivalents\n' +
|
|
508
|
+
' --lang es|pt the why report in Latin American Spanish or Brazilian Portuguese; your locale picks it by default\n' +
|
|
478
509
|
' rewrites [session|all] every full-prefix cache write with its cause, idle gap and list price\n' +
|
|
479
510
|
' ttl [session|all] one-hour cache lifetime counterfactual from your own idle gaps\n' +
|
|
480
511
|
' pace [session] ten-minute pace and next-hour projection\n' +
|
package/dist/src/conformance.js
CHANGED
|
@@ -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
|
|
58
|
-
const RATE_WARN = /
|
|
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:
|
|
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:
|
|
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: `
|
|
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: `
|
|
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: `
|
|
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}
|
|
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:
|
|
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 (
|
|
209
|
-
out.push(
|
|
210
|
-
|
|
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
|
-
|
|
220
|
-
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
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
|
-
|
|
230
|
-
if (has('duplicate_work'))
|
|
231
|
-
|
|
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
|
-
|
|
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;
|
package/dist/src/frames.d.ts
CHANGED
|
@@ -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;
|
package/dist/src/frames.js
CHANGED
|
@@ -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,
|
|
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
|
|
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
|
|
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,
|
|
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
|
-
(
|
|
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 {
|