@agentguard-run/burn 0.3.28 → 0.5.0
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 +23 -0
- package/README.md +67 -1
- package/dist/src/adapters/codex.d.ts +4 -2
- package/dist/src/adapters/codex.js +55 -9
- package/dist/src/cli.js +101 -13
- package/dist/src/history/claude-transcript.d.ts +0 -13
- package/dist/src/history/claude-transcript.js +11 -10
- package/dist/src/hook/pre-tool-use.d.ts +0 -16
- package/dist/src/hook/pre-tool-use.js +15 -10
- package/dist/src/index.d.ts +6 -1
- package/dist/src/index.js +27 -1
- package/dist/src/insights/i18n.d.ts +1 -0
- package/dist/src/insights/i18n.js +9 -7
- package/dist/src/insights/launch-evidence.d.ts +25 -0
- package/dist/src/insights/launch-evidence.js +54 -0
- package/dist/src/insights/price-shadow.js +2 -1
- package/dist/src/insights/pricing.js +8 -2
- package/dist/src/insights/status-data.d.ts +6 -0
- package/dist/src/insights/status-data.js +65 -0
- package/dist/src/insights/status-fields.d.ts +74 -0
- package/dist/src/insights/status-fields.js +136 -0
- package/dist/src/insights/status-text.d.ts +107 -0
- package/dist/src/insights/status-text.js +36 -0
- package/dist/src/insights/tally.d.ts +47 -0
- package/dist/src/insights/tally.js +266 -0
- package/dist/src/insights/transcript.js +9 -1
- package/dist/src/insights/tree.d.ts +36 -0
- package/dist/src/insights/tree.js +285 -0
- package/dist/src/insights/types.d.ts +2 -0
- package/dist/src/receipt.d.ts +10 -0
- package/dist/src/receipt.js +53 -2
- package/dist/src/telemetry-cli.d.ts +5 -0
- package/dist/src/telemetry-cli.js +57 -0
- package/dist/src/tool-names.d.ts +6 -0
- package/dist/src/tool-names.js +10 -0
- package/dist/src/upgrade-moments.js +2 -1
- package/docs/OCT5_VERIFICATION.md +118 -0
- package/docs/TREE_AND_TALLY.md +70 -0
- package/docs/USAGE_AND_PRICING.md +4 -2
- package/docs/launch-tree-local-oct5.txt +7 -0
- package/docs/oct5-followup/REPORT.md +105 -0
- package/docs/oct5-followup/checks.json +20 -0
- package/docs/oct5-followup/free-plugin-fixture-output.txt +12 -0
- package/docs/oct5-followup/tally-after.json +5 -0
- package/docs/oct5-followup/tally-after.txt +1 -0
- package/docs/oct5-followup/tree-after.json +40 -0
- package/docs/oct5-followup/tree-after.txt +7 -0
- package/docs/oct5-followup/tree-before.txt +7 -0
- package/docs/oct5-followup/verify-free-receipts.cjs +81 -0
- package/docs/session-tally-local-oct5.txt +1 -0
- package/package.json +7 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.5.0 (2026-10-07)
|
|
4
|
+
|
|
5
|
+
- Price Claude Haiku 5.5 (`claude-haiku-5-5`), released on October 7, 2026: 0.1, 0.01, 0.125, 0.2 and 0.5 USD per million tokens for fresh input, cache read, five-minute write, one-hour write and output on prompts up to 100,000 tokens, and five times each above that. Before this row its turns were unpriced.
|
|
6
|
+
- Claude Sonnet 5.5 cache reads drop to 0.1 USD per million tokens (0.05x base input), per Anthropic's October 7, 2026 change. Burn prices sessions at the current list price, so earlier Sonnet 5.5 sessions are repriced too.
|
|
7
|
+
- Offer one optional anonymous count after a successful interactive why report, sharing Spend consent and install ID; add telemetry controls and a query-free Next link.
|
|
8
|
+
|
|
9
|
+
- Add optional pace, API list cost, prefix rewrite and daily Spend status fields with a shared formatter, width fitting, panel details and localized Burn labels.
|
|
10
|
+
|
|
11
|
+
## 0.4.0 (2026-10-05)
|
|
12
|
+
|
|
13
|
+
- Add recorded launch trees and signed approval tallies. Tree shows active time
|
|
14
|
+
in hours and minutes and elapsed span in days and hours, with five-minute gap
|
|
15
|
+
capping. Unknown lineage or usage stays unknown.
|
|
16
|
+
- Read explicit caller, type, depth and linked outcomes from verified plugin
|
|
17
|
+
receipts. Resumed summaries contribute daily increments without adding the
|
|
18
|
+
earlier cumulative total twice.
|
|
19
|
+
- Own Codex cumulative usage and all shared launch aliases. Cached input is
|
|
20
|
+
already in the total, and repeated observations replace earlier totals.
|
|
21
|
+
- Standalone Claude admission receipts sign the host tool-call ID and expose
|
|
22
|
+
verification against the pinned local public key, chain and persisted head.
|
|
23
|
+
- Pin Spend 0.21.0 for the receipt verifier.
|
|
24
|
+
|
|
25
|
+
|
|
3
26
|
## 0.3.28 (2026-10-03)
|
|
4
27
|
|
|
5
28
|
- `why --commits` gives no per-commit figure when other local sessions overlap the window in the same repository: the commits can't be split between sessions, so the line says so instead of printing a number that would credit this session with other sessions' commits.
|
package/README.md
CHANGED
|
@@ -16,6 +16,19 @@ The two init commands print hook configuration for review. Merge the relevant sn
|
|
|
16
16
|
|
|
17
17
|
`agentguard-burn --version` (or `-v`) prints the installed version.
|
|
18
18
|
|
|
19
|
+
## Launch tree and signed approval tally
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
agentguard-burn tree SESSION
|
|
23
|
+
agentguard-burn tree SESSION --json
|
|
24
|
+
agentguard-burn tally SESSION
|
|
25
|
+
agentguard-burn tally SESSION --json
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Omit `SESSION` to use the current or latest local session, or pass its transcript path. `tree` shows recorded parents, each agent's model, own and subtree tokens, token share, recorded duration and unfinished status. Missing parent links stay under `parent not recorded`. The terminal view fits 80 columns and collapses large fan-outs; JSON keeps every node. `why` includes a short tree when children were recorded.
|
|
29
|
+
|
|
30
|
+
`tally` verifies signed plugin receipts and their complete hash chain before counting launch decisions. Missing or invalid receipts print a reason instead of a number. Approvals are a subset of asks; policy refusals and unrecorded approval outcomes remain separate. Codex blocks launches until allowed and never receives an ask count. See [the field definitions, arithmetic and verification limits](docs/TREE_AND_TALLY.md).
|
|
31
|
+
|
|
19
32
|
For Claude Code, configure its `statusLine` command as `agentguard-burn statusline`. It receives the host JSON on stdin. Codex 0.154.0 has no external status command slot. Use `agentguard-burn statusline SESSION_ID` in a companion terminal and the native Codex limit indicators. See [host fields and setup](docs/USAGE_AND_PRICING.md#what-the-hosts-expose).
|
|
20
33
|
|
|
21
34
|
## Import a DisciplineBench run
|
|
@@ -736,7 +749,7 @@ A provenance JSON beside the requested MP4 records the source recording's SHA256
|
|
|
736
749
|
|
|
737
750
|
Runtime observation and enforcement do not persist or render prompts, responses, file contents or tool inputs. The explicit developer `guard-candidates` command copies shell text already present in a ledger into a private review; only its `--rank` option can send that text to the selected provider.
|
|
738
751
|
`why` runs git only with `--commits`, and then reads commit hashes, times and co-author trailers on this computer and prints counts alone.
|
|
739
|
-
|
|
752
|
+
Status and pace make no telemetry calls. No provider-quota guesses. Account forecasts use only observed host percentages, never an invented allowance or cache weighting.
|
|
740
753
|
|
|
741
754
|
### Local live panel
|
|
742
755
|
|
|
@@ -774,3 +787,56 @@ output or transcript content. See [the live panel and September 20 evidence](doc
|
|
|
774
787
|
`agentguard-burn status` shows this UTC month’s recorded spawn stops and blocked shell commands. It reads Burn’s local ledger and plugin ledgers registered by either host, joins mirrored spawn receipts once, and excludes shadow decisions, approval holds and outcomes. Missing command history is unknown. Nothing is uploaded. Free installations see one Team line per UTC month. Counts update on later status calls without repeating that line.
|
|
775
788
|
|
|
776
789
|
Run `agentguard-burn quiet on`, or `node runtime/policy-cli.cjs quiet on` from the AgentGuard plugin directory, to dismiss the monthly summary, the `why` tip, the weekly STOP invitation and plugin version announcements on this machine. Both write the same flag file, `upgrade-moments/quiet`, and use `AGENTGUARD_HOME` or the default local AgentGuard home for it. `agentguard-burn quiet off` removes that file.
|
|
790
|
+
|
|
791
|
+
## Status line fields
|
|
792
|
+
|
|
793
|
+
The status line always starts with AgentGuard. Its default items remain sub-agent launches, session tokens, the token share sent to sub-agents when known, and plan usage when the host reports it. Optional fields use the same formatter in Burn and the Claude Code plugin. They read local transcripts, host usage and signed Spend files only. Codex has no external status slot.
|
|
794
|
+
|
|
795
|
+
Set `status_fields` to `pace,cost,cache,spend` in the plugin settings. Burn accepts the same comma list in `AGENTGUARD_STATUS_FIELDS`, or through the fields flag, which takes precedence even when empty. Unknown names are ignored, with one warning in the plugin panel. The default is empty.
|
|
796
|
+
|
|
797
|
+
- `pace` projects the time until the reported plan limit, using at least two rising samples from the last ten minutes, only when that limit would be reached before reset.
|
|
798
|
+
- `cost` estimates this session at Burn's API list prices, including recorded child sessions, and remains opt-in even without host plan limits.
|
|
799
|
+
- `cache` shows cache-write tokens attributed by Burn to large prefix rewrites in this session and their API list price estimate when available.
|
|
800
|
+
- `spend` shows today's signed local spend against an unscoped daily policy cap, only when both the local JSON policy and its verified ledger can be read.
|
|
801
|
+
|
|
802
|
+
Examples on a wide terminal:
|
|
803
|
+
|
|
804
|
+
```text
|
|
805
|
+
AgentGuard sub-agents 2 of 40 · tokens 686M of 5B · 33% to sub-agents · 5-hour 44% · limit in ~1h40m · /agentguard
|
|
806
|
+
AgentGuard sub-agents 2 of 40 · tokens 686M of 5B · 33% to sub-agents · 5-hour 44% · ≈$12.40 list · /agentguard
|
|
807
|
+
AgentGuard sub-agents 2 of 40 · tokens 686M of 5B · 33% to sub-agents · 5-hour 44% · cache waste 42M (≈$9.00 list) · /agentguard
|
|
808
|
+
AgentGuard sub-agents 2 of 40 · tokens 686M of 5B · 33% to sub-agents · 5-hour 44% · spend $3.20 of $10.00 list today · /agentguard
|
|
809
|
+
```
|
|
810
|
+
|
|
811
|
+
Dollar figures are API list price estimates, not a bill. Spend displays the cents recorded by the local policy, which may use configured unit prices. Pace rounds to ten minutes, always starts with `~`, and turns yellow below thirty minutes. Usage turns yellow at 70% and red at 90%, including daily spend. Optional fields are removed in this order when space runs out: pace, cost, cache, spend. Default labels then shorten so the line fits without wrapping. Open `/agentguard` for full values, reset times, enabled fields and any unknown-name warning. Extremely narrow slots clip the row; all values remain in the panel.
|
|
812
|
+
|
|
813
|
+
The Claude usage API reports context, rate-limit windows and a host cost value. Its API-key window behavior is not guaranteed by the reference or the installed host implementation, so cost does not become an automatic default. The cost field uses Burn's local price table, not that host cost value. Daily spend reads a local scope-wide JSON policy, verifies its signed ledger and uses UTC day boundaries. Selector-only caps, unreadable ledgers or failed signature checks and policies held only by a remote or in-memory application stay unavailable.
|
|
814
|
+
|
|
815
|
+
## Anonymous count (opt-in)
|
|
816
|
+
|
|
817
|
+
After the first successful interactive `why` report, Burn can ask once:
|
|
818
|
+
|
|
819
|
+
```text
|
|
820
|
+
Help us count real users? Sends one anonymous ping (random ID, Burn version, OS). Never your prompts, files or usage. [y/N]
|
|
821
|
+
```
|
|
822
|
+
|
|
823
|
+
Only `y` or `yes` enables counting. Enter, anything else or fifteen seconds without an answer records no. The report prints before the question. CI, noninteractive terminals, library imports and hooks never ask or send a Burn count. Consent and the anonymous install ID share Spend's local `install.json` under `AGENTGUARD_HOME` or the usual AgentGuard home. An existing shared consent decision or explicit environment switch is respected without another question.
|
|
824
|
+
|
|
825
|
+
A yes permits one best-effort attempt per install to `https://agentguard.run/api/beacon`, with a one-second timeout and ignored errors. It sends exactly these fields:
|
|
826
|
+
|
|
827
|
+
```json
|
|
828
|
+
{
|
|
829
|
+
"event": "burn_first_report",
|
|
830
|
+
"sdk_name": "@agentguard-run/burn",
|
|
831
|
+
"sdk_version": "<Burn version>",
|
|
832
|
+
"runtime": "<Node version>",
|
|
833
|
+
"os_family": "<OS family>",
|
|
834
|
+
"anonymous_install_id": "<random UUID shared with Spend>",
|
|
835
|
+
"ci_env_detected": false,
|
|
836
|
+
"tty": true
|
|
837
|
+
}
|
|
838
|
+
```
|
|
839
|
+
|
|
840
|
+
No prompts, files, paths, session IDs, model names or token counts are sent. Run `agentguard-burn telemetry status`, `agentguard-burn telemetry on` or `agentguard-burn telemetry off` to inspect or change the shared choice. `AGENTGUARD_TELEMETRY=1` enables it; `AGENTGUARD_NO_BEACON=1` always disables it, overriding every other setting. An attempted event stays marked so a network failure never causes repeated pings. Failed or missing local state makes counting best effort, never a requirement to use Burn.
|
|
841
|
+
|
|
842
|
+
The Next link is `https://agentguard.run/burn/next`, without query strings or an install ID. Opening it is an ordinary website visit and needs no CLI ping. See the [privacy page](https://agentguard.run/legal/privacy#anonymous-count) for server counting and retention.
|
|
@@ -42,7 +42,9 @@ export declare function handleCodexHook(raw: unknown, gateway: Gateway, now?: nu
|
|
|
42
42
|
* re-reading the file on every hook call is idempotent at the gateway.
|
|
43
43
|
*/
|
|
44
44
|
export declare function readCodexTranscriptUsage(path: string, sessionId: string, now: number): ModelUsageObserved[];
|
|
45
|
-
export declare function parseCodexTranscript(text: string, sessionId: string, now: number): ModelUsageObserved[];
|
|
45
|
+
export declare function parseCodexTranscript(text: string, sessionId: string, now: number, streamId?: string): ModelUsageObserved[];
|
|
46
46
|
/** The ~/.codex/hooks.json fragment. spawn_agent matches as Agent. */
|
|
47
47
|
export declare function codexHooksSnippet(command: string): Record<string, unknown>;
|
|
48
|
-
export declare const CODEX_SPAWN_TOOLS:
|
|
48
|
+
export declare const CODEX_SPAWN_TOOLS: Readonly<{
|
|
49
|
+
has: typeof import("../tool-names").isLaunchTool;
|
|
50
|
+
}>;
|
|
@@ -31,6 +31,8 @@ exports.parseCodexTranscript = parseCodexTranscript;
|
|
|
31
31
|
exports.codexHooksSnippet = codexHooksSnippet;
|
|
32
32
|
const node_crypto_1 = require("node:crypto");
|
|
33
33
|
const node_fs_1 = require("node:fs");
|
|
34
|
+
const node_path_1 = require("node:path");
|
|
35
|
+
const tool_names_1 = require("../tool-names");
|
|
34
36
|
const events_1 = require("../events");
|
|
35
37
|
const render_1 = require("../replay/render");
|
|
36
38
|
const stop_text_1 = require("../stop-text");
|
|
@@ -40,7 +42,7 @@ const pre_tool_use_1 = require("../hook/pre-tool-use");
|
|
|
40
42
|
/** Fields this renderer must never emit. Codex rejects the whole object if they appear. */
|
|
41
43
|
exports.CODEX_FORBIDDEN_FIELDS = ['continue', 'stopReason', 'suppressOutput', 'decision', 'reason'];
|
|
42
44
|
const HOST = 'codex';
|
|
43
|
-
const SPAWN_TOOLS =
|
|
45
|
+
const SPAWN_TOOLS = tool_names_1.LAUNCH_TOOLS;
|
|
44
46
|
function handleCodexHook(raw, gateway, now = Date.now()) {
|
|
45
47
|
const parsed = parse(raw);
|
|
46
48
|
if (!parsed)
|
|
@@ -74,8 +76,7 @@ function handleCodexSpawnHook(raw, gateway, now) {
|
|
|
74
76
|
sessionId: input.sessionId,
|
|
75
77
|
at: now,
|
|
76
78
|
spawnId,
|
|
77
|
-
//
|
|
78
|
-
proposedDepth: 1,
|
|
79
|
+
// The host does not provide a verified depth. Count enforcement still applies.
|
|
79
80
|
attribution: 'high',
|
|
80
81
|
});
|
|
81
82
|
if (decision.blocked) {
|
|
@@ -131,18 +132,41 @@ function parse(value) {
|
|
|
131
132
|
* re-reading the file on every hook call is idempotent at the gateway.
|
|
132
133
|
*/
|
|
133
134
|
function readCodexTranscriptUsage(path, sessionId, now) {
|
|
134
|
-
|
|
135
|
+
if (typeof path !== 'string' || !(0, node_path_1.isAbsolute)(path) || !path.endsWith('.jsonl'))
|
|
136
|
+
return [];
|
|
137
|
+
let fd;
|
|
135
138
|
try {
|
|
136
|
-
|
|
139
|
+
fd = (0, node_fs_1.openSync)(path, node_fs_1.constants.O_RDONLY | node_fs_1.constants.O_NOFOLLOW | node_fs_1.constants.O_NONBLOCK);
|
|
140
|
+
const stat = (0, node_fs_1.fstatSync)(fd);
|
|
141
|
+
if (!stat.isFile())
|
|
142
|
+
return [];
|
|
143
|
+
const size = Math.min(stat.size, 262144), offset = stat.size - size, buffer = Buffer.alloc(size);
|
|
144
|
+
const length = (0, node_fs_1.readSync)(fd, buffer, 0, size, offset);
|
|
145
|
+
let text = buffer.subarray(0, length).toString('utf8');
|
|
146
|
+
if (offset)
|
|
147
|
+
text = text.slice(text.indexOf('\n') + 1);
|
|
148
|
+
const events = parseCodexTranscript(text, sessionId, now, path);
|
|
149
|
+
// A tail can prove a cumulative snapshot, never a complete legacy total.
|
|
150
|
+
if (offset || events.some(e => e.callId) || !events.length)
|
|
151
|
+
return offset ? events.filter(e => e.callId) : events;
|
|
152
|
+
// Legacy per-call rows are also one replaceable stream total. If a host
|
|
153
|
+
// starts supplying cumulative snapshots later, they replace this total.
|
|
154
|
+
const tokens = events.reduce((sum, e) => sum + e.tokens, 0), cacheRead = events.reduce((sum, e) => sum + e.cacheRead, 0);
|
|
155
|
+
const callId = 'codex:launch-usage:' + (0, node_crypto_1.createHash)('sha256').update(path).digest('hex');
|
|
156
|
+
return [{ ...events.at(-1), tokens, cacheRead, callId, eventId: `${callId}:${tokens}:${cacheRead}` }];
|
|
137
157
|
}
|
|
138
158
|
catch {
|
|
139
159
|
return [];
|
|
140
160
|
}
|
|
141
|
-
|
|
161
|
+
finally {
|
|
162
|
+
if (fd !== undefined)
|
|
163
|
+
(0, node_fs_1.closeSync)(fd);
|
|
164
|
+
}
|
|
142
165
|
}
|
|
143
|
-
function parseCodexTranscript(text, sessionId, now) {
|
|
166
|
+
function parseCodexTranscript(text, sessionId, now, streamId = sessionId) {
|
|
144
167
|
const out = [];
|
|
145
168
|
const lines = text.split('\n');
|
|
169
|
+
let cumulative;
|
|
146
170
|
for (let i = 0; i < lines.length; i++) {
|
|
147
171
|
const line = lines[i].trim();
|
|
148
172
|
if (!line)
|
|
@@ -154,6 +178,24 @@ function parseCodexTranscript(text, sessionId, now) {
|
|
|
154
178
|
catch {
|
|
155
179
|
continue;
|
|
156
180
|
}
|
|
181
|
+
const row = rec;
|
|
182
|
+
if (row?.type === 'event_msg' && row.payload?.type === 'token_count') {
|
|
183
|
+
const usage = row.payload.info?.total_token_usage;
|
|
184
|
+
if (!usage || !Number.isSafeInteger(usage.total_tokens) || usage.total_tokens < 0
|
|
185
|
+
|| !Number.isSafeInteger(usage.cached_input_tokens) || usage.cached_input_tokens < 0
|
|
186
|
+
|| usage.cached_input_tokens > usage.total_tokens)
|
|
187
|
+
continue;
|
|
188
|
+
const at = Date.parse(row.timestamp);
|
|
189
|
+
if (!Number.isFinite(at))
|
|
190
|
+
continue;
|
|
191
|
+
// Keep the earlier plugin adapter's identity for a seamless handoff.
|
|
192
|
+
// Cached input is already included in total_tokens, never added again.
|
|
193
|
+
const callId = 'codex:launch-usage:' + (0, node_crypto_1.createHash)('sha256').update(streamId).digest('hex');
|
|
194
|
+
cumulative = { schemaVersion: 1, kind: 'model_usage', host: HOST, sessionId, at, callId,
|
|
195
|
+
eventId: `${callId}:${usage.total_tokens}:${usage.cached_input_tokens}`,
|
|
196
|
+
tokens: usage.total_tokens, cacheRead: usage.cached_input_tokens, usageCoverage: 'estimated' };
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
157
199
|
const usage = extractUsage(rec);
|
|
158
200
|
if (!usage)
|
|
159
201
|
continue;
|
|
@@ -171,7 +213,8 @@ function parseCodexTranscript(text, sessionId, now) {
|
|
|
171
213
|
usageCoverage: 'estimated',
|
|
172
214
|
});
|
|
173
215
|
}
|
|
174
|
-
|
|
216
|
+
// A cumulative stream includes the earlier individual call records.
|
|
217
|
+
return cumulative ? [cumulative] : out;
|
|
175
218
|
}
|
|
176
219
|
function extractUsage(rec) {
|
|
177
220
|
const num = (...paths) => {
|
|
@@ -188,7 +231,10 @@ function extractUsage(rec) {
|
|
|
188
231
|
const cached = num(['usage', 'cache_read_input_tokens'], ['usage', 'input_tokens_details', 'cached_tokens'], ['response', 'usage', 'input_tokens_details', 'cached_tokens'], ['token_usage', 'cached_input_tokens']);
|
|
189
232
|
if (input === undefined && output === undefined && total === undefined)
|
|
190
233
|
return null;
|
|
191
|
-
|
|
234
|
+
// OpenAI input tokens already include cache reads. Only the explicitly
|
|
235
|
+
// separate Anthropic-compatible cache_read_input_tokens shape adds them.
|
|
236
|
+
const separateCache = num(['usage', 'cache_read_input_tokens']) ?? 0;
|
|
237
|
+
const tokens = Math.max(total ?? 0, (input ?? 0) + (output ?? 0) + separateCache);
|
|
192
238
|
const tsRaw = walk(rec, ['timestamp']) ?? walk(rec, ['created_at']);
|
|
193
239
|
const at = typeof tsRaw === 'string' ? Date.parse(tsRaw) : typeof tsRaw === 'number' ? tsRaw : NaN;
|
|
194
240
|
return { tokens, cacheRead: cached ?? 0, at: Number.isFinite(at) ? at : undefined };
|
package/dist/src/cli.js
CHANGED
|
@@ -74,6 +74,8 @@ const simulate_1 = require("./replay/simulate");
|
|
|
74
74
|
const status_1 = require("./status");
|
|
75
75
|
const upgrade_moments_1 = require("./upgrade-moments");
|
|
76
76
|
const eligibility_1 = require("./eligibility");
|
|
77
|
+
const tree_1 = require("./insights/tree");
|
|
78
|
+
const tally_1 = require("./insights/tally");
|
|
77
79
|
const sessions_1 = require("./insights/sessions");
|
|
78
80
|
const transcript_1 = require("./insights/transcript");
|
|
79
81
|
const live_1 = require("./insights/live");
|
|
@@ -85,7 +87,11 @@ const i18n_1 = require("./insights/i18n");
|
|
|
85
87
|
const ttl_1 = require("./insights/ttl");
|
|
86
88
|
const blocks_1 = require("./insights/blocks");
|
|
87
89
|
const cli_1 = require("./idle/cli");
|
|
90
|
+
const telemetry_cli_1 = require("./telemetry-cli");
|
|
91
|
+
const status_fields_1 = require("./insights/status-fields");
|
|
92
|
+
const status_data_1 = require("./insights/status-data");
|
|
88
93
|
const HOME = process.env.AGENTGUARD_HOME ?? (0, node_path_1.join)((0, node_os_1.homedir)(), '.agentguard');
|
|
94
|
+
let finishReportNaturally = false;
|
|
89
95
|
const PROXY_HOSTS = ['ollama', 'vllm', 'lm-studio', 'openai-compatible'];
|
|
90
96
|
/** The same flag file the AgentGuard plugin reads (runtime/upgrade-moments.cjs), so one switch silences both. */
|
|
91
97
|
const quietOn = () => (0, node_fs_1.existsSync)((0, upgrade_moments_1.quietFile)(HOME));
|
|
@@ -210,6 +216,30 @@ async function main(argv) {
|
|
|
210
216
|
show({ kind: 'command', command, values: { ...report } }, (rest.includes('json') || has('--json') ? JSON.stringify(report, null, 2) : (0, blocks_1.renderBlocks)(report)) + '\n', rest.includes('json') || has('--json'));
|
|
211
217
|
return 0;
|
|
212
218
|
}
|
|
219
|
+
case 'tree':
|
|
220
|
+
case 'tally': {
|
|
221
|
+
const args = rest.filter(v => v !== 'json' && v !== '--json');
|
|
222
|
+
if (args.length > 1 || args.some(v => v.startsWith('-')))
|
|
223
|
+
throw new Error('Pass one session or transcript path.');
|
|
224
|
+
const json = rest.includes('json') || rest.includes('--json');
|
|
225
|
+
if (command === 'tree') {
|
|
226
|
+
const report = await (0, tree_1.readLaunchTreeWithReceipts)((0, sessions_1.selectInsightTranscript)(args[0]), { home: HOME });
|
|
227
|
+
process.stdout.write((json ? JSON.stringify(report, null, 2) : (0, tree_1.renderLaunchTree)(report)) + '\n');
|
|
228
|
+
}
|
|
229
|
+
else {
|
|
230
|
+
// An explicit id can be tallied even after its transcript was removed.
|
|
231
|
+
let session = args[0];
|
|
232
|
+
if (!session || (0, node_fs_1.existsSync)(session)) {
|
|
233
|
+
const location = (0, sessions_1.selectInsightTranscript)(session);
|
|
234
|
+
const parsed = (0, transcript_1.readInsightTranscript)(location.path, { host: location.host, sessionId: location.sessionId });
|
|
235
|
+
session = parsed.state.lineage?.sessionId ?? parsed.sessionId;
|
|
236
|
+
}
|
|
237
|
+
const report = await (0, tally_1.sessionTally)(session, { home: HOME });
|
|
238
|
+
process.stdout.write((json ? JSON.stringify(report, null, 2) : (0, tally_1.renderSessionTally)(report)) + '\n');
|
|
239
|
+
return report.status === 'verification_failed' ? 1 : 0;
|
|
240
|
+
}
|
|
241
|
+
return 0;
|
|
242
|
+
}
|
|
213
243
|
case 'why': {
|
|
214
244
|
// `--lang en|es|pt` (or --lang=es) picks the report's language and is never a session selector.
|
|
215
245
|
// `--commits` adds the commits that landed while the session ran. It is the only way `why` runs git.
|
|
@@ -233,14 +263,20 @@ async function main(argv) {
|
|
|
233
263
|
process.stderr.write('Usage: agentguard-burn why [session] [json] [--lang en|es|pt]\n');
|
|
234
264
|
return 64;
|
|
235
265
|
}
|
|
236
|
-
const location = (0, sessions_1.selectInsightTranscript)(args.find(value => value !== 'json'));
|
|
266
|
+
const location = (0, sessions_1.selectInsightTranscript)(args.find(value => value !== 'json' && value !== '--json'));
|
|
237
267
|
const transcript = (0, transcript_1.readInsightSession)(location.path, { host: location.host, sessionId: location.sessionId });
|
|
238
|
-
const json = args.includes('json');
|
|
268
|
+
const json = args.includes('json') || args.includes('--json');
|
|
239
269
|
// The commits reader is loaded only with the flag, so a plain `why` never reaches it.
|
|
240
270
|
const commits = withCommits ? await (await Promise.resolve().then(() => __importStar(require('./insights/commits')))).sessionCommits({ path: location.path }) : undefined;
|
|
271
|
+
const launchTree = (0, tree_1.readLaunchTree)(location);
|
|
272
|
+
const treeSection = launchTree.root.children.length || launchTree.unlinked.length ? '\n\n' + (0, tree_1.renderLaunchTree)(launchTree, true) : '';
|
|
241
273
|
const commitsValue = commits ? (0, render_2.commitsJson)(commits, transcript.state.forkHistoryBoundaryUnknown ? null : (0, render_2.sessionFigures)(transcript).attribution.totalTokens) : undefined;
|
|
242
|
-
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)))), ...(commitsValue ? { commits: commitsValue } : {}) } }, json ? JSON.stringify(
|
|
243
|
-
: (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() }), ...(commits ? { commits } : {}) }) + '\n', json);
|
|
274
|
+
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)))), ...(commitsValue ? { commits: commitsValue } : {}) } }, json ? JSON.stringify({ ...transcript, ...(treeSection ? { launchTree } : {}), ...(commitsValue ? { commits: commitsValue } : {}) }, null, 2) + '\n'
|
|
275
|
+
: (treeSection ? treeSection.trim() + '\n\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() }), ...(commits ? { commits } : {}) }) + '\n', json);
|
|
276
|
+
if (require.main === module && !json && transcript.turns.length) {
|
|
277
|
+
finishReportNaturally = true;
|
|
278
|
+
await (0, telemetry_cli_1.countFirstReport)(require('../../package.json').version);
|
|
279
|
+
}
|
|
244
280
|
return 0;
|
|
245
281
|
}
|
|
246
282
|
case 'compare': {
|
|
@@ -383,13 +419,55 @@ async function main(argv) {
|
|
|
383
419
|
show({ kind: 'command', command, values: { rates: { ...pricing_1.MODEL_PRICING, ...rates } } }, (0, render_2.renderPricing)(rates) + '\n');
|
|
384
420
|
return 0;
|
|
385
421
|
}
|
|
386
|
-
case '
|
|
422
|
+
case 'telemetry': return (0, telemetry_cli_1.telemetryCommand)(rest);
|
|
423
|
+
case 'statusline': {
|
|
424
|
+
let fields = process.env.AGENTGUARD_STATUS_FIELDS ?? '', lang;
|
|
425
|
+
const selectors = [];
|
|
426
|
+
for (let i = 0; i < rest.length; i++) {
|
|
427
|
+
if (rest[i] === '--fields')
|
|
428
|
+
fields = rest[++i] ?? '';
|
|
429
|
+
else if (rest[i].startsWith('--fields='))
|
|
430
|
+
fields = rest[i].slice(9);
|
|
431
|
+
else if (rest[i] === '--lang')
|
|
432
|
+
lang = rest[++i];
|
|
433
|
+
else if (rest[i].startsWith('--lang='))
|
|
434
|
+
lang = rest[i].slice(7);
|
|
435
|
+
else
|
|
436
|
+
selectors.push(rest[i]);
|
|
437
|
+
}
|
|
438
|
+
const raw = !process.stdin.isTTY ? readStdinJson() : null;
|
|
439
|
+
const payload = (raw && typeof raw === 'object' ? raw : {});
|
|
440
|
+
const width = payload.columns ?? payload.terminal_width ?? process.stdout.columns ?? Number(process.env.COLUMNS || 80);
|
|
441
|
+
let location;
|
|
442
|
+
try {
|
|
443
|
+
location = (0, sessions_1.selectInsightTranscript)(payload.transcript_path || selectors[0] || payload.session_id);
|
|
444
|
+
}
|
|
445
|
+
catch {
|
|
446
|
+
process.stdout.write((0, status_fields_1.formatStatusFields)({ fields, width, failed: true }).text + '\n');
|
|
447
|
+
return 0;
|
|
448
|
+
}
|
|
449
|
+
const session = payload.session_id || location.sessionId;
|
|
450
|
+
const observation = (0, live_1.observeTool)(HOME, { ...payload, session_id: session, transcript_path: location.path }, location.host, (0, pre_tool_use_1.loadPolicy)(HOME));
|
|
451
|
+
const metrics = await (0, status_data_1.readStatusMetrics)(HOME, location.path, fields, process.env.PLUGIN_DATA || process.env.CLAUDE_PLUGIN_DATA, true);
|
|
452
|
+
const burn = (0, status_data_1.readStatusBurn)(HOME, session);
|
|
453
|
+
if (!(0, node_fs_1.existsSync)((0, node_path_1.join)(HOME, 'sessions')) && metrics.totalTokens !== undefined)
|
|
454
|
+
burn.tokens.used = metrics.totalTokens;
|
|
455
|
+
const formatted = (0, status_fields_1.formatStatusFields)({ ...metrics, burn, fields, windows: observation.snapshot?.windows,
|
|
456
|
+
width,
|
|
457
|
+
lang: (0, i18n_1.detectWhyLang)({ flag: lang, env: process.env, intlLocale: intlLocale() }) });
|
|
458
|
+
const line = process.env.NO_COLOR !== undefined || noColor || formatted.clipped ? formatted.text : formatted.parts.map(part => {
|
|
459
|
+
const code = part.color === 'red' ? 31 : part.color === 'yellow' ? 33 : part.dim ? 2 : 0;
|
|
460
|
+
return code ? `\x1b[${code}m${part.text}\x1b[0m` : part.text;
|
|
461
|
+
}).join('');
|
|
462
|
+
show({ kind: 'command', command, values: { fields: formatted.enabled } }, line + '\n', true);
|
|
463
|
+
return 0;
|
|
464
|
+
}
|
|
387
465
|
case 'pace': {
|
|
388
|
-
const raw =
|
|
466
|
+
const raw = null;
|
|
389
467
|
const payload = raw && typeof raw === 'object' ? raw : {};
|
|
390
468
|
const location = (0, sessions_1.selectInsightTranscript)(payload.transcript_path || rest[0] || payload.session_id);
|
|
391
469
|
const observation = (0, live_1.observeTool)(HOME, { ...payload, session_id: payload.session_id || location.sessionId, transcript_path: location.path }, location.host, (0, pre_tool_use_1.loadPolicy)(HOME));
|
|
392
|
-
show({ kind: 'command', command, values: { snapshot: observation.snapshot ? { host: observation.snapshot.host, session: observation.snapshot.sessionId, pace: observation.snapshot.pace, forecast: observation.snapshot.forecast, lastTurnTokens: observation.snapshot.lastTurnTokens, windows: observation.snapshot.windows } : null } }, (observation.snapshot ? (0, live_1.renderStatusLine)(observation.snapshot) : 'AgentGuard pace unavailable: local usage metadata is not readable.') + '\n'
|
|
470
|
+
show({ kind: 'command', command, values: { snapshot: observation.snapshot ? { host: observation.snapshot.host, session: observation.snapshot.sessionId, pace: observation.snapshot.pace, forecast: observation.snapshot.forecast, lastTurnTokens: observation.snapshot.lastTurnTokens, windows: observation.snapshot.windows } : null } }, (observation.snapshot ? (0, live_1.renderStatusLine)(observation.snapshot) : 'AgentGuard pace unavailable: local usage metadata is not readable.') + '\n');
|
|
393
471
|
return observation.snapshot ? 0 : 1;
|
|
394
472
|
}
|
|
395
473
|
case 'hook': {
|
|
@@ -616,7 +694,7 @@ async function main(argv) {
|
|
|
616
694
|
return 0;
|
|
617
695
|
}
|
|
618
696
|
default:
|
|
619
|
-
show({ kind: 'command', command: 'help', values: { commands: ['ps', 'reap', 'live', 'record', 'render', 'blocks', 'limits', 'price-shadow', 'calendar', 'why', 'compare', 'rewrites', 'ttl', 'pace', 'statusline', 'pricing', 'replay', 'calibrate', 'status', 'init', 'enforce', 'shadow', 'resume', 'quiet', 'proxy', 'conformance'] } }, 'agentguard-burn <ps|reap|live|record|render|blocks|limits|price-shadow|calendar|why|compare|rewrites|ttl|pace|statusline|pricing|replay|calibrate|status|init|enforce|shadow|resume|quiet|proxy|conformance>\n' +
|
|
697
|
+
show({ kind: 'command', command: 'help', values: { commands: ['tree', 'tally', 'ps', 'reap', 'live', 'record', 'render', 'blocks', 'limits', 'price-shadow', 'calendar', 'why', 'compare', 'rewrites', 'ttl', 'pace', 'statusline', 'pricing', 'telemetry', 'replay', 'calibrate', 'status', 'init', 'enforce', 'shadow', 'resume', 'quiet', 'proxy', 'conformance'] } }, 'agentguard-burn <ps|reap|live|record|render|blocks|limits|price-shadow|calendar|why|compare|rewrites|ttl|pace|statusline|pricing|telemetry|replay|calibrate|status|init|enforce|shadow|resume|quiet|proxy|conformance>\n' +
|
|
620
698
|
' ps [--json] local agent processes, held memory and workspace disk\n' +
|
|
621
699
|
' render <run.jsonl> --mp4 <out.mp4> [--gif <out.gif>] [--phone] local recorded-run export\n' +
|
|
622
700
|
' render <run.jsonl> --mp4 <out.mp4> --dashboard [--wide] [--economics <blocks.json>] dashboard export\n' +
|
|
@@ -627,6 +705,8 @@ async function main(argv) {
|
|
|
627
705
|
' blocks [session|all] stored WARN/STOP receipts and that session\'s child usage\n' +
|
|
628
706
|
' limits [session|all] local plan walls and prior Burn decisions\n' +
|
|
629
707
|
' price-shadow [session|all] local child list-price exposure and sensitivity\n' +
|
|
708
|
+
' tree [session] recorded launch ancestry, tokens and duration\n' +
|
|
709
|
+
' tally [session] verified signed launch decisions\n' +
|
|
630
710
|
' why [session] token attribution and API list-price equivalents\n' +
|
|
631
711
|
' --lang es|pt the why report in Latin American Spanish or Brazilian Portuguese; your locale picks it by default\n' +
|
|
632
712
|
' --commits count the commits that landed in its git repository while it ran (runs git on this computer; off by default)\n' +
|
|
@@ -636,7 +716,8 @@ async function main(argv) {
|
|
|
636
716
|
' rewrites [session|all] every full-prefix cache write with its cause, idle gap and list price\n' +
|
|
637
717
|
' ttl [session|all] one-hour cache lifetime counterfactual from your own idle gaps\n' +
|
|
638
718
|
' pace [session] ten-minute pace and next-hour projection\n' +
|
|
639
|
-
' statusline [session] one
|
|
719
|
+
' statusline [session] one local status line; fields via AGENTGUARD_STATUS_FIELDS or the fields flag\n' +
|
|
720
|
+
' telemetry status|on|off shared anonymous count preference\n' +
|
|
640
721
|
' pricing verified model rates and local overrides\n' +
|
|
641
722
|
' replay [files...] [--json] [--top N] [--min-tokens N]\n' +
|
|
642
723
|
' import-bench <run-dir> [--out <directory>] [--publisher-key-id ID] verify and convert a signed bundle\n' +
|
|
@@ -712,7 +793,14 @@ function exit(code) {
|
|
|
712
793
|
process.stdout.write('', done);
|
|
713
794
|
process.stderr.write('', done);
|
|
714
795
|
}
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
796
|
+
if (require.main === module)
|
|
797
|
+
run().then(
|
|
798
|
+
// Let the best-effort count request finish within its one-second deadline.
|
|
799
|
+
// The report has already been printed, and Node drains stdout on natural exit.
|
|
800
|
+
(code) => { if (finishReportNaturally)
|
|
801
|
+
process.exitCode = code;
|
|
802
|
+
else
|
|
803
|
+
exit(code); }, (error) => {
|
|
804
|
+
process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
|
|
805
|
+
exit(4);
|
|
806
|
+
});
|
|
@@ -1,16 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Claude Code transcript reader.
|
|
3
|
-
*
|
|
4
|
-
* Reads ~/.claude/projects/<slug>/<session>.jsonl incrementally. The hot path
|
|
5
|
-
* (the PreToolUse hook) must never re-read a 25,000-line file, so the reader
|
|
6
|
-
* remembers the byte offset after the last complete newline and only parses
|
|
7
|
-
* what has been appended since.
|
|
8
|
-
*
|
|
9
|
-
* Transcript lines are not a stable contract. Every line is parsed defensively:
|
|
10
|
-
* a malformed line is counted and skipped, a partial trailing line is left
|
|
11
|
-
* uncommitted so it can be re-read once the host finishes writing it, and a
|
|
12
|
-
* truncated or replaced file resets the cursor rather than reading garbage.
|
|
13
|
-
*/
|
|
14
1
|
import type { BurnEvent } from '../types';
|
|
15
2
|
/** Component maxima for one provider response, never transcript contents. */
|
|
16
3
|
export type UsageSnapshot = [input: number, output: number, cacheCreation: number, cacheRead: number];
|
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.newCursor = newCursor;
|
|
4
|
+
exports.normaliseLine = normaliseLine;
|
|
5
|
+
exports.readIncremental = readIncremental;
|
|
6
|
+
exports.readSessionIncremental = readSessionIncremental;
|
|
7
|
+
exports.saveReaderCursor = saveReaderCursor;
|
|
8
|
+
exports.restoreReaderCursor = restoreReaderCursor;
|
|
9
|
+
exports.cloneReaderCursor = cloneReaderCursor;
|
|
10
|
+
exports.readAll = readAll;
|
|
11
|
+
const tool_names_1 = require("../tool-names");
|
|
2
12
|
/**
|
|
3
13
|
* Claude Code transcript reader.
|
|
4
14
|
*
|
|
@@ -12,22 +22,13 @@
|
|
|
12
22
|
* uncommitted so it can be re-read once the host finishes writing it, and a
|
|
13
23
|
* truncated or replaced file resets the cursor rather than reading garbage.
|
|
14
24
|
*/
|
|
15
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.newCursor = newCursor;
|
|
17
|
-
exports.normaliseLine = normaliseLine;
|
|
18
|
-
exports.readIncremental = readIncremental;
|
|
19
|
-
exports.readSessionIncremental = readSessionIncremental;
|
|
20
|
-
exports.saveReaderCursor = saveReaderCursor;
|
|
21
|
-
exports.restoreReaderCursor = restoreReaderCursor;
|
|
22
|
-
exports.cloneReaderCursor = cloneReaderCursor;
|
|
23
|
-
exports.readAll = readAll;
|
|
24
25
|
const node_fs_1 = require("node:fs");
|
|
25
26
|
const node_path_1 = require("node:path");
|
|
26
27
|
const transcript_1 = require("../insights/transcript");
|
|
27
28
|
const subagent_signals_1 = require("./subagent-signals");
|
|
28
29
|
const CHUNK = 64 * 1024;
|
|
29
30
|
const MAX_LINE = 4 * 1024 * 1024;
|
|
30
|
-
const SPAWN_TOOLS =
|
|
31
|
+
const SPAWN_TOOLS = tool_names_1.LAUNCH_TOOLS;
|
|
31
32
|
const SURFACE_TOOLS = new Set(['Read', 'Grep', 'Glob']);
|
|
32
33
|
function newCursor() {
|
|
33
34
|
return { offset: 0, size: 0, malformedLines: 0, depthByUuid: new Map(), usageVersion: 1, usageByMessage: new Map() };
|
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Claude Code PreToolUse hook.
|
|
3
|
-
*
|
|
4
|
-
* Reads the hook payload from stdin, evaluates the proposed spawn under the
|
|
5
|
-
* reservation lock, and emits the nested permissionDecision Claude Code
|
|
6
|
-
* expects. Only Agent/Task spawns are ever denied; ordinary tools pass.
|
|
7
|
-
*
|
|
8
|
-
* Shadow mode evaluates and records the decision but always allows. That is
|
|
9
|
-
* the first-run default, because a blocker with untuned thresholds that fires
|
|
10
|
-
* on day one gets uninstalled on day one.
|
|
11
|
-
*
|
|
12
|
-
* Fail-closed on the reservation lock: if we cannot coordinate with sibling
|
|
13
|
-
* hook processes, we deny the spawn rather than let a burst through. We
|
|
14
|
-
* cannot fail closed if Claude Code times the hook out, so the hot path does
|
|
15
|
-
* as little as possible.
|
|
16
|
-
*/
|
|
17
1
|
import { type PersistedReaderCursor, type ReaderCursor } from '../history/claude-transcript';
|
|
18
2
|
import type { BurnReport, Policy, SessionState } from '../types';
|
|
19
3
|
export interface HookInput {
|
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AGENT_OVERRIDE_REASON = exports.loadPolicy = void 0;
|
|
4
|
+
exports.inflateHookSession = inflateHookSession;
|
|
5
|
+
exports.findingSignature = findingSignature;
|
|
6
|
+
exports.refreshSession = refreshSession;
|
|
7
|
+
exports.handlePreToolUse = handlePreToolUse;
|
|
8
|
+
exports.asksPerson = asksPerson;
|
|
9
|
+
exports.agentOverrideAttempt = agentOverrideAttempt;
|
|
10
|
+
exports.settingsSnippet = settingsSnippet;
|
|
11
|
+
const tool_names_1 = require("../tool-names");
|
|
2
12
|
/**
|
|
3
13
|
* Claude Code PreToolUse hook.
|
|
4
14
|
*
|
|
@@ -15,15 +25,6 @@
|
|
|
15
25
|
* cannot fail closed if Claude Code times the hook out, so the hot path does
|
|
16
26
|
* as little as possible.
|
|
17
27
|
*/
|
|
18
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.AGENT_OVERRIDE_REASON = exports.loadPolicy = void 0;
|
|
20
|
-
exports.inflateHookSession = inflateHookSession;
|
|
21
|
-
exports.findingSignature = findingSignature;
|
|
22
|
-
exports.refreshSession = refreshSession;
|
|
23
|
-
exports.handlePreToolUse = handlePreToolUse;
|
|
24
|
-
exports.asksPerson = asksPerson;
|
|
25
|
-
exports.agentOverrideAttempt = agentOverrideAttempt;
|
|
26
|
-
exports.settingsSnippet = settingsSnippet;
|
|
27
28
|
const node_crypto_1 = require("node:crypto");
|
|
28
29
|
const events_1 = require("../events");
|
|
29
30
|
const receipt_1 = require("../receipt");
|
|
@@ -43,7 +44,7 @@ const node_os_1 = require("node:os");
|
|
|
43
44
|
const live_1 = require("../insights/live");
|
|
44
45
|
const hook_1 = require("../idle/hook");
|
|
45
46
|
const subagent_cost_1 = require("../subagent-cost");
|
|
46
|
-
const SPAWN_TOOLS =
|
|
47
|
+
const SPAWN_TOOLS = tool_names_1.LAUNCH_TOOLS;
|
|
47
48
|
function sessionFile(home, sessionId) {
|
|
48
49
|
return (0, node_path_1.join)(home, 'sessions', `${sessionId.replace(/[^a-zA-Z0-9_-]/g, '_')}.json`);
|
|
49
50
|
}
|
|
@@ -204,6 +205,10 @@ function handleSpawnPreToolUse(input, home, now) {
|
|
|
204
205
|
const receipt = signer.sign({
|
|
205
206
|
schema: 'agentguard.burn.decision.v1', decisionId: (0, node_crypto_1.randomUUID)(), at: now,
|
|
206
207
|
host: 'claude-code', action: 'spawn', sessionDigest: (0, receipt_1.sha256)(input.session_id),
|
|
208
|
+
...(typeof input.tool_use_id === 'string' && /^[A-Za-z0-9_.:@/-]{1,256}$/.test(input.tool_use_id) ? { toolUseId: input.tool_use_id } : {}),
|
|
209
|
+
agent_id: typeof input.agent_id === 'string' && /^[A-Za-z0-9_.:@/-]{1,256}$/.test(input.agent_id) ? input.agent_id : null,
|
|
210
|
+
agent_type: typeof input.agent_type === 'string' && /^[A-Za-z0-9_.:@/-]{1,128}$/.test(input.agent_type) ? input.agent_type : null,
|
|
211
|
+
depth: input.agent_id ? null : 0,
|
|
207
212
|
policy: { mode: policy.mode, digest: (0, receipt_1.sha256)((0, receipt_1.canonical)(policy)) },
|
|
208
213
|
measured: { sessionTokens: state.totalTokens, sessionSpawns: reservation.effectiveSpawns,
|
|
209
214
|
proposedDepth, inFlight: 0, occupiedMs: 0 },
|
package/dist/src/index.d.ts
CHANGED
|
@@ -15,10 +15,11 @@ export { calibrate, type CalibrationResult } from './calibrate';
|
|
|
15
15
|
export { handlePreToolUse, refreshSession, loadPolicy, settingsSnippet, asksPerson, agentOverrideAttempt, AGENT_OVERRIDE_REASON, type HookInput, type HookOutput } from './hook/pre-tool-use';
|
|
16
16
|
export * from './events';
|
|
17
17
|
export { Gateway, mergeCapabilities, type Decision, type GatewaySessionView, type UsageCoverage, type GatewayOptions } from './gateway';
|
|
18
|
-
export { ReceiptSigner, verifyReceipt, receiptDigest, canonical, sha256, type ReceiptPayload, type SignedReceipt } from './receipt';
|
|
18
|
+
export { ReceiptSigner, verifyReceipt, receiptDigest, readSpawnAdmission, canonical, sha256, type ReceiptPayload, type SignedReceipt } from './receipt';
|
|
19
19
|
export { createRawApiGuard, BurnStopError, type RawApiGuard, type RawGuardOptions } from './adapters/raw-api';
|
|
20
20
|
export { handleCursorHook, cursorHooksSnippet, type CursorHookOutput } from './adapters/cursor';
|
|
21
21
|
export { handleCodexHook, codexHooksSnippet, parseCodexTranscript, readCodexTranscriptUsage, CODEX_FORBIDDEN_FIELDS, type CodexHookOutput } from './adapters/codex';
|
|
22
|
+
export { isLaunchTool, LAUNCH_TOOLS } from './tool-names';
|
|
22
23
|
export { startProxy, profileFor, type ProxyOptions, type ProxyHost, type RunningProxy } from './proxy/server';
|
|
23
24
|
export { UsageObserver, type ProxyProfile, type ObservedUsage } from './proxy/usage-observer';
|
|
24
25
|
export { renderMachineStatus } from './status';
|
|
@@ -27,3 +28,7 @@ export { writeOverride, readOverride, consumeOverride, clearOverride, OVERRIDE_W
|
|
|
27
28
|
export { install, health, configPath, type InstallHost, type InstallResult, type HostHealth } from './install';
|
|
28
29
|
export { readHookSessions, renderHostHealth } from './status';
|
|
29
30
|
export { findingSignature, inflateHookSession, type PersistedSession } from './hook/pre-tool-use';
|
|
31
|
+
export { readLaunchTree, readLaunchTreeWithReceipts, buildLaunchTree, renderLaunchTree } from './insights/tree';
|
|
32
|
+
export { sessionTally, tallyEntries, readLedgerTallies, readLedgerDailyTallies, renderSessionTally, pluginLedgerDirectories, sessionLaunchReceipts, type SessionTally, type TallyCounts } from './insights/tally';
|
|
33
|
+
export { formatStatusFields, parseStatusFields, statusPace, statusColor, type StatusInput, type StatusMetrics } from './insights/status-fields';
|
|
34
|
+
export { readStatusBurn, readStatusMetrics } from './insights/status-data';
|