@agentguard-run/burn 0.6.2 → 0.7.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 CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.7.0 (2026-10-28)
4
+
5
+ - Add `install`: one command for every agent host on this computer. It finds Claude Code, Codex, Cursor and Hermes by their command on PATH and their config folder, reading files only, and prints the plan: each host, the exact commands and the files they change. `--yes` carries it out: the AgentGuard plugin through Claude Code's and Codex's own plugin commands (with `npm ci` in Codex's plugin folder, and in Claude Code's only when it left the dependencies out), Burn's hook merged into `~/.cursor/hooks.json`, and `agentguard-spend-hermes` installed with uv into the Python environment Hermes runs from, then enabled. It then reads each host again and prints one line per host (installed, already installed, skipped, or failed with the reason) with the mode AgentGuard runs in and the status command that confirms the effective mode. `--only` and `--skip` choose hosts; `--json` gives an agent the plan and the results. A second run changes nothing. A failed host does not stop the others, and the exit code is 1. It never runs a downloaded script, never uses sudo, never installs a host itself, never asks for a key and never writes `burn-policy.json`, so the plugin's enforce default still applies to a fresh install.
6
+ - `install` updates an installed AgentGuard plugin that is older than what is available (the newer of the host's local marketplace copy and plugin 0.5.0, as that copy can be stale) through the host's own plugin commands: `claude plugin marketplace update agentguard` and `claude plugin update agentguard@agentguard`, or `codex plugin marketplace upgrade agentguard` and `codex plugin add agentguard@agentguard --json`, adding the agentguard-run marketplace first when none is configured. A marketplace still added from MerchantGuard/agentguard-codex-plugin stays in place, since both hosts refuse the new source under the same name and GitHub forwards the old one.
7
+ - Where the plugin is installed and enabled, `install` removes a standalone Burn hook from `~/.codex/hooks.json` or `~/.claude/settings.json` after the plugin steps succeed, with a timestamped backup, taking out only the Burn gate entries and keeping every other byte of the file.
8
+ - The `agentguard-burn` wrapper passes `install` through unchanged. Its `^0.6.1` range does not reach 0.7.0, so `npx agentguard-burn install` needs a wrapper release on `^0.7.0`.
9
+
3
10
  ## 0.6.2 (2026-10-22)
4
11
 
5
12
  - `ps` opens with free disk on the volume holding your home folder and swap use. [WARN] under 10 GB or 10% free, [CRIT] under 5 GB, swap [WARN] above 80% used. Unknown readings say unknown. `ps --json` adds `disk` (`freeBytes`, `totalBytes`, `level`, `swapUsedBytes`, `swapTotalBytes`, `swapLevel`).
package/README.md CHANGED
@@ -18,6 +18,32 @@ Press y if npm asks to install Burn. Plain `npx agentguard-burn` shows these thr
18
18
 
19
19
  Burn prints its installed version on the first line of every `why` and `calendar` text report, including the empty message. JSON reports include a `version` field. `npx agentguard-burn --version` (or `-v`) prints only the installed version.
20
20
 
21
+ ## Install AgentGuard on every agent host
22
+
23
+ ```sh
24
+ npx agentguard-burn install # the plan; nothing changes
25
+ npx agentguard-burn install --yes # carry it out
26
+ ```
27
+
28
+ `install` finds Claude Code, Codex, Cursor and Hermes on this computer by their command on PATH and their config folder. It decides by reading files and starts nothing to look. Without `--yes` it prints the plan: each host it found, the exact commands it would run and the files they change. With `--yes` it runs them, reads each host again, and prints one line per host: installed, already installed, skipped, or failed with the reason, with the mode AgentGuard runs in there.
29
+
30
+ | Host | What `--yes` does |
31
+ |---|---|
32
+ | Claude Code | `claude plugin marketplace add agentguard-run/agentguard-codex-plugin` (unless an agentguard marketplace is already added), `claude plugin install agentguard@agentguard`, and `npm ci` in the plugin folder only if the dependencies are missing. An older plugin: `claude plugin marketplace update agentguard`, then `claude plugin update agentguard@agentguard` |
33
+ | Codex | `codex plugin marketplace add agentguard-run/agentguard-codex-plugin` (unless already added), `codex plugin add agentguard@agentguard --json`, then `npm ci` in the plugin folder Codex reports if the dependencies are missing. An older plugin: `codex plugin marketplace upgrade agentguard`, then the same `plugin add` and `npm ci` |
34
+ | Cursor | merges the AgentGuard hook into `~/.cursor/hooks.json` after a timestamped backup: the same entry as `init cursor --write` |
35
+ | Hermes | `uv pip install --python <the Python environment Hermes runs from> agentguard-spend-hermes`, then `hermes plugins enable agentguard-spend` |
36
+
37
+ - `--only claude,codex` or `--skip hermes` chooses hosts (claude, codex, cursor, hermes).
38
+ - `--json` prints the plan, and after `--yes` each host's result, for an agent to read. An agent shows the plan to its person and runs `--yes` only after they agree.
39
+ - Run it again at any time. A host that already has AgentGuard is reported as already installed and nothing runs for it; a host that failed is tried again.
40
+ - An installed plugin older than what is available shows as "update available" and is updated through the host's own plugin commands; plugin files are never edited by hand. Available means the newer of what the host's local copy of the marketplace lists and plugin 0.5.0, since that local copy refreshes only when asked. A marketplace still added from the plugin's old repository (MerchantGuard/agentguard-codex-plugin, which GitHub forwards to agentguard-run/agentguard-codex-plugin) is left in place: Claude Code and Codex refuse to add the new source under the same name while it exists, and updates come through it.
41
+ - Where the plugin is installed (or being installed) and enabled, a standalone Burn hook in `~/.codex/hooks.json` or `~/.claude/settings.json` is removed after the plugin steps succeed: a timestamped backup first, then only the Burn gate entries go and every other hook and setting keeps its exact bytes. The plugin includes the same gate; in Codex it does not hand launch checks to a standalone hook, so both would check every launch. With the plugin turned off, or its install failed, the standalone hook stays.
42
+ - A failed host command does not stop the other hosts, and the exit code is 1. A host that is present but missing something it needs (its command on PATH, npm, uv, a readable `hooks.json`) shows in the plan with the reason and is reported as failed. A usage error exits 64.
43
+ - It never pipes a downloaded script to a shell, never uses sudo, never installs a host itself, never asks for or stores a key, and never writes `burn-policy.json`: the plugin writes enforce into a fresh one, and a file written first would keep a new install in shadow.
44
+ - Afterwards: start a new session in each host. In Codex, open `/hooks`, review the AgentGuard hooks and trust them yourself; an agent must never approve its own hooks. Restart Hermes. Then check the effective mode: `agentguard-status` in a Claude Code or Codex session, `agentguard-burn status` for Cursor, `/agentguard status` in Hermes. The mode `install` prints is read from local files; a paid license whose check fails falls back to shadow, which only `agentguard-status` can see.
45
+ - Run through `npx`, the Cursor hook points into the npx cache, which npm can clear. For a lasting hook, install Burn globally first (see "Optional global install and hooks" below), then run `agentguard-burn install`.
46
+
21
47
  ## Simple and detailed views
22
48
 
23
49
  `statusline`, `why` and `live` default to simple; `compact-replay` defaults to detailed so its table shows. Save a preference with `agentguard-burn mode simple` or `agentguard-burn mode detailed`. It lives in `AGENTGUARD_HOME/burn-config.json`, normally under `~/.agentguard`. `AGENTGUARD_BURN_MODE` overrides it. Per-command `simple` and `detailed` flags, prefixed by two hyphens, override both. Detailed output and JSON stay unchanged.
package/dist/src/cli.d.ts CHANGED
@@ -8,6 +8,7 @@
8
8
  * replay what enforcement would have stopped, on your history
9
9
  * calibrate fit thresholds to your own usage, write shadow policy
10
10
  * status mode, shadow decisions, eligibility, every host's sessions
11
+ * install find every agent host here, print the plan, install with --yes
11
12
  * init [host] hook snippet for claude (default), cursor or codex
12
13
  * enforce promote shadow -> enforce, once eligible
13
14
  * shadow demote back to shadow
package/dist/src/cli.js CHANGED
@@ -9,6 +9,7 @@
9
9
  * replay what enforcement would have stopped, on your history
10
10
  * calibrate fit thresholds to your own usage, write shadow policy
11
11
  * status mode, shadow decisions, eligibility, every host's sessions
12
+ * install find every agent host here, print the plan, install with --yes
12
13
  * init [host] hook snippet for claude (default), cursor or codex
13
14
  * enforce promote shadow -> enforce, once eligible
14
15
  * shadow demote back to shadow
@@ -742,6 +743,28 @@ async function main(argv) {
742
743
  .replace(/\n\n\n/g, '\n\n') + '\n');
743
744
  return 0;
744
745
  }
746
+ case 'install': {
747
+ // Loaded only here, so hooks and reports never load it.
748
+ const { defaultRunner, installJson, parseInstallArgs, planInstall, renderPlan, renderReport, runInstall } = await Promise.resolve().then(() => __importStar(require('./install-all')));
749
+ const options = parseInstallArgs(rest);
750
+ if ('error' in options) {
751
+ process.stderr.write(`${options.error}\n`);
752
+ return 64;
753
+ }
754
+ const context = { home: (0, node_os_1.homedir)(), env: process.env, platform: process.platform, cliPath: (0, node_path_1.join)(__dirname, 'cli.js') };
755
+ const plan = planInstall(context, options);
756
+ if (!options.yes) {
757
+ const values = installJson(version_1.BURN_VERSION, plan, null);
758
+ show({ kind: 'command', command, values }, options.json ? `${JSON.stringify(values, null, 2)}\n` : renderPlan(plan, context), true);
759
+ return 0;
760
+ }
761
+ if (!options.json && plan.next)
762
+ process.stdout.write('Installing AgentGuard\n');
763
+ const report = runInstall(plan, context, defaultRunner(context), options.json ? undefined : (line) => process.stdout.write(` ${line}\n`));
764
+ const values = installJson(version_1.BURN_VERSION, plan, report);
765
+ show({ kind: 'command', command, values }, options.json ? `${JSON.stringify(values, null, 2)}\n` : `${plan.next ? '\n' : ''}${renderReport(report)}`, true);
766
+ return report.ok ? 0 : 1;
767
+ }
745
768
  case 'init': {
746
769
  const policy = (0, pre_tool_use_1.loadPolicy)(HOME);
747
770
  savePolicy(policy);
@@ -870,7 +893,7 @@ async function main(argv) {
870
893
  show({ kind: 'command', command: 'help', values: { commands: ['why', 'calendar', 'card'] } }, starter + '\nStart here: npx agentguard-burn why\nAll commands: npx agentguard-burn --help all\n', true);
871
894
  return !command || command === 'help' || command === '--help' || command === '-h' ? 0 : 64;
872
895
  }
873
- show({ kind: 'command', command: 'help', values: { commands: ['tree', 'tally', 'ps', 'reap', 'live', 'record', 'render', 'blocks', 'limits', 'price-shadow', 'calendar', 'week', 'why', 'compare', 'rewrites', 'compact-replay', 'ttl', 'pace', 'statusline', 'pricing', 'telemetry', 'replay', 'calibrate', 'status', 'init', 'enforce', 'shadow', 'resume', 'quiet', 'proxy', 'conformance'] } }, starter + '\nAll commands\n' +
896
+ show({ kind: 'command', command: 'help', values: { commands: ['tree', 'tally', 'ps', 'reap', 'live', 'record', 'render', 'blocks', 'limits', 'price-shadow', 'calendar', 'week', 'why', 'compare', 'rewrites', 'compact-replay', 'ttl', 'pace', 'statusline', 'pricing', 'telemetry', 'replay', 'calibrate', 'status', 'install', 'init', 'enforce', 'shadow', 'resume', 'quiet', 'proxy', 'conformance'] } }, starter + '\nAll commands\n' +
874
897
  ' ps [--json] local agent processes, held memory and workspace disk\n' +
875
898
  ' render <run.jsonl> --mp4 <out.mp4> [--gif <out.gif>] [--phone] local recorded-run export\n' +
876
899
  ' render <run.jsonl> --mp4 <out.mp4> --dashboard [--wide] [--economics <blocks.json>] dashboard export\n' +
@@ -902,6 +925,7 @@ async function main(argv) {
902
925
  ' replay <replay.json> --pricing <snapshot.json> [--json] replay a saved run with its original prices\n' +
903
926
  ' calibrate fit thresholds to your history (writes shadow policy)\n' +
904
927
  ' status mode, shadow observations, eligibility, hook health, every host\n' +
928
+ ' install [--yes] [--only <hosts>] [--skip <hosts>] [--json] find Claude Code, Codex, Cursor and Hermes here, print the plan; --yes installs AgentGuard on each\n' +
905
929
  ' init [claude|cursor|codex] [--write] print the hook snippet, or merge it into the config (with a backup)\n' +
906
930
  ' enforce [--force] shadow -> enforce\n' +
907
931
  ' shadow enforce -> shadow\n' +
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Removing AgentGuard's standalone Burn hook from a host's hooks file
3
+ * (~/.codex/hooks.json, ~/.claude/settings.json) once the AgentGuard plugin,
4
+ * which includes the same gate, is installed there.
5
+ *
6
+ * The file is the person's. Other hooks, other settings, their spacing and
7
+ * their key order stay exactly as written: instead of parsing and
8
+ * re-serializing, the file is parsed with byte positions and only the arrays
9
+ * and objects that lose an entry are rebuilt, from the original bytes of the
10
+ * entries they keep. A backup is taken first and the write is atomic.
11
+ */
12
+ export declare function isStandaloneBurnGate(command: unknown): boolean;
13
+ /**
14
+ * Removes the standalone Burn gate entries under "hooks". A matcher group
15
+ * holding only Burn entries goes with them, and an event left with no group
16
+ * goes too; a group that also holds other hooks keeps them.
17
+ */
18
+ export declare function removeStandaloneBurnHooks(text: string): {
19
+ text: string;
20
+ removed: number;
21
+ };
22
+ /** How many standalone Burn gate entries a hooks file holds (0 when it is missing or not valid JSON). */
23
+ export declare function countStandaloneBurnHooks(file: string): number;
24
+ /** Removes the Burn gate entries from a file: a timestamped backup first, then an atomic write that keeps the file's mode. */
25
+ export declare function removeStandaloneBurnHooksFromFile(file: string): {
26
+ removed: number;
27
+ backup: string | null;
28
+ };
@@ -0,0 +1,232 @@
1
+ "use strict";
2
+ /**
3
+ * Removing AgentGuard's standalone Burn hook from a host's hooks file
4
+ * (~/.codex/hooks.json, ~/.claude/settings.json) once the AgentGuard plugin,
5
+ * which includes the same gate, is installed there.
6
+ *
7
+ * The file is the person's. Other hooks, other settings, their spacing and
8
+ * their key order stay exactly as written: instead of parsing and
9
+ * re-serializing, the file is parsed with byte positions and only the arrays
10
+ * and objects that lose an entry are rebuilt, from the original bytes of the
11
+ * entries they keep. A backup is taken first and the write is atomic.
12
+ */
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.isStandaloneBurnGate = isStandaloneBurnGate;
15
+ exports.removeStandaloneBurnHooks = removeStandaloneBurnHooks;
16
+ exports.countStandaloneBurnHooks = countStandaloneBurnHooks;
17
+ exports.removeStandaloneBurnHooksFromFile = removeStandaloneBurnHooksFromFile;
18
+ const node_fs_1 = require("node:fs");
19
+ /**
20
+ * A Burn gate command as `init claude|codex --write` writes it (or the npx and
21
+ * bare-command forms): Burn's CLI followed by `hook` or `codex-hook`. Other
22
+ * commands that mention Burn, such as `npx agentguard-burn why`, are not gates.
23
+ */
24
+ const BURN_GATE = /(?:agentguard-burn|agentguard-run\/burn)\S*\s+(?:hook|codex-hook)$/;
25
+ function isStandaloneBurnGate(command) {
26
+ return typeof command === 'string' && BURN_GATE.test(command.trim());
27
+ }
28
+ /** A JSON parser that keeps where every value starts and ends. Input is already known to be valid JSON. */
29
+ function parseWithPositions(text) {
30
+ let i = 0;
31
+ const ws = () => {
32
+ while (i < text.length && (text[i] === ' ' || text[i] === '\t' || text[i] === '\n' || text[i] === '\r'))
33
+ i++;
34
+ };
35
+ const fail = (what) => {
36
+ throw new Error(`not valid JSON: ${what} at offset ${i}`);
37
+ };
38
+ const string = () => {
39
+ const start = i;
40
+ if (text[i] !== '"')
41
+ fail('string expected');
42
+ i++;
43
+ while (i < text.length && text[i] !== '"')
44
+ i += text[i] === '\\' ? 2 : 1;
45
+ if (text[i] !== '"')
46
+ fail('unterminated string');
47
+ i++;
48
+ return JSON.parse(text.slice(start, i));
49
+ };
50
+ const value = () => {
51
+ ws();
52
+ const start = i;
53
+ if (text[i] === '{') {
54
+ i++;
55
+ const members = [];
56
+ ws();
57
+ if (text[i] === '}')
58
+ return { kind: 'object', start, end: ++i, members };
59
+ for (;;) {
60
+ ws();
61
+ const keyStart = i;
62
+ const key = string();
63
+ ws();
64
+ if (text[i] !== ':')
65
+ fail("':' expected");
66
+ i++;
67
+ members.push({ key, keyStart, value: value() });
68
+ ws();
69
+ if (text[i] === ',') {
70
+ i++;
71
+ continue;
72
+ }
73
+ if (text[i] === '}') {
74
+ i++;
75
+ break;
76
+ }
77
+ fail("',' or '}' expected");
78
+ }
79
+ return { kind: 'object', start, end: i, members };
80
+ }
81
+ if (text[i] === '[') {
82
+ i++;
83
+ const items = [];
84
+ ws();
85
+ if (text[i] === ']')
86
+ return { kind: 'array', start, end: ++i, items };
87
+ for (;;) {
88
+ items.push(value());
89
+ ws();
90
+ if (text[i] === ',') {
91
+ i++;
92
+ continue;
93
+ }
94
+ if (text[i] === ']') {
95
+ i++;
96
+ break;
97
+ }
98
+ fail("',' or ']' expected");
99
+ }
100
+ return { kind: 'array', start, end: i, items };
101
+ }
102
+ if (text[i] === '"') {
103
+ const parsed = string();
104
+ return { kind: 'value', start, end: i, value: parsed };
105
+ }
106
+ const literal = /^(?:-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?|true|false|null)/.exec(text.slice(i, i + 64));
107
+ if (!literal)
108
+ fail('value expected');
109
+ i += literal[0].length;
110
+ return { kind: 'value', start, end: i, value: JSON.parse(literal[0]) };
111
+ };
112
+ const root = value();
113
+ ws();
114
+ if (i !== text.length)
115
+ fail('trailing text');
116
+ return root;
117
+ }
118
+ /** The original text with every node in `drop` removed; untouched parts keep their bytes. */
119
+ function render(text, node, drop) {
120
+ if (node.kind === 'value')
121
+ return text.slice(node.start, node.end);
122
+ const children = node.kind === 'array'
123
+ ? node.items.map((item) => ({ start: item.start, node: item }))
124
+ : node.members.map((member) => ({ start: member.keyStart, node: member.value }));
125
+ if (!children.length)
126
+ return text.slice(node.start, node.end);
127
+ const kept = children.filter((child) => !drop.has(child.node));
128
+ const [open, close] = node.kind === 'array' ? ['[', ']'] : ['{', '}'];
129
+ if (!kept.length)
130
+ return open + close;
131
+ if (kept.length === children.length) {
132
+ let out = '';
133
+ let at = node.start;
134
+ for (const child of children) {
135
+ out += text.slice(at, child.node.start) + render(text, child.node, drop);
136
+ at = child.node.end;
137
+ }
138
+ return out + text.slice(at, node.end);
139
+ }
140
+ const first = children[0];
141
+ const last = children[children.length - 1];
142
+ const separator = children.length > 1 ? text.slice(first.node.end, children[1].start) : ', ';
143
+ return open + text.slice(node.start + 1, first.start)
144
+ + kept.map((child) => text.slice(child.start, child.node.start) + render(text, child.node, drop)).join(separator)
145
+ + text.slice(last.node.end, node.end - 1) + close;
146
+ }
147
+ const commandOf = (node) => {
148
+ if (node.kind !== 'object')
149
+ return undefined;
150
+ const command = node.members.find((m) => m.key === 'command')?.value;
151
+ return command?.kind === 'value' ? command.value : undefined;
152
+ };
153
+ /**
154
+ * Removes the standalone Burn gate entries under "hooks". A matcher group
155
+ * holding only Burn entries goes with them, and an event left with no group
156
+ * goes too; a group that also holds other hooks keeps them.
157
+ */
158
+ function removeStandaloneBurnHooks(text) {
159
+ JSON.parse(text); // refuse anything that is not plain JSON before touching it
160
+ const root = parseWithPositions(text);
161
+ if (root.kind !== 'object')
162
+ return { text, removed: 0 };
163
+ const hooks = root.members.find((m) => m.key === 'hooks')?.value;
164
+ if (!hooks || hooks.kind !== 'object')
165
+ return { text, removed: 0 };
166
+ const drop = new Set();
167
+ let removed = 0;
168
+ for (const event of hooks.members) {
169
+ if (event.value.kind !== 'array')
170
+ continue;
171
+ let kept = 0;
172
+ let dropped = 0;
173
+ for (const group of event.value.items) {
174
+ if (commandOf(group) !== undefined) {
175
+ if (isStandaloneBurnGate(commandOf(group))) {
176
+ drop.add(group);
177
+ removed++;
178
+ dropped++;
179
+ }
180
+ else
181
+ kept++;
182
+ continue;
183
+ }
184
+ const inner = group.kind === 'object' ? group.members.find((m) => m.key === 'hooks')?.value : undefined;
185
+ const burn = inner?.kind === 'array' ? inner.items.filter((h) => isStandaloneBurnGate(commandOf(h))) : [];
186
+ if (!inner || inner.kind !== 'array' || !burn.length) {
187
+ kept++;
188
+ continue;
189
+ }
190
+ removed += burn.length;
191
+ if (burn.length === inner.items.length) {
192
+ drop.add(group);
193
+ dropped++;
194
+ }
195
+ else {
196
+ for (const entry of burn)
197
+ drop.add(entry);
198
+ kept++;
199
+ }
200
+ }
201
+ if (!kept && dropped)
202
+ drop.add(event.value);
203
+ }
204
+ // Whitespace around the top-level object (a final newline, say) stays as it was.
205
+ return removed ? { text: text.slice(0, root.start) + render(text, root, drop) + text.slice(root.end), removed } : { text, removed: 0 };
206
+ }
207
+ /** How many standalone Burn gate entries a hooks file holds (0 when it is missing or not valid JSON). */
208
+ function countStandaloneBurnHooks(file) {
209
+ try {
210
+ return removeStandaloneBurnHooks((0, node_fs_1.readFileSync)(file, 'utf8')).removed;
211
+ }
212
+ catch {
213
+ return 0;
214
+ }
215
+ }
216
+ /** Removes the Burn gate entries from a file: a timestamped backup first, then an atomic write that keeps the file's mode. */
217
+ function removeStandaloneBurnHooksFromFile(file) {
218
+ const original = (0, node_fs_1.readFileSync)(file, 'utf8');
219
+ const result = removeStandaloneBurnHooks(original);
220
+ if (!result.removed)
221
+ return { removed: 0, backup: null };
222
+ JSON.parse(result.text); // the rebuilt file must still be valid JSON before it replaces the original
223
+ const stamp = new Date().toISOString().replace(/[-:.]/g, '').slice(0, 15); // 20261028T163812
224
+ let backup = `${file}.bak-${stamp}`;
225
+ for (let n = 1; (0, node_fs_1.existsSync)(backup); n++)
226
+ backup = `${file}.bak-${stamp}-${n}`;
227
+ (0, node_fs_1.copyFileSync)(file, backup, node_fs_1.constants.COPYFILE_EXCL);
228
+ const temporary = `${file}.agentguard.tmp`;
229
+ (0, node_fs_1.writeFileSync)(temporary, result.text, { mode: (0, node_fs_1.statSync)(file).mode & 0o777 });
230
+ (0, node_fs_1.renameSync)(temporary, file);
231
+ return { removed: result.removed, backup };
232
+ }
@@ -0,0 +1,209 @@
1
+ /**
2
+ * `agentguard-burn install`: AgentGuard on every agent host on this machine.
3
+ *
4
+ * It finds Claude Code, Codex, Cursor and Hermes by their command on PATH and
5
+ * their config folder, and decides what to do by reading files: nothing is
6
+ * started to look. Without --yes it prints the plan (each host, the exact
7
+ * commands, the files they change) and changes nothing, so an agent can show
8
+ * the plan to its person first. With --yes it runs each host's own plugin
9
+ * commands, reads the same files again, and reports one line per host.
10
+ *
11
+ * It never pipes a downloaded script to a shell, never uses sudo, never
12
+ * installs a host itself and never asks for or stores a key. It also never
13
+ * writes Burn's policy file: the plugin seeds enforce mode into a fresh one,
14
+ * and a file written first would keep a new install in shadow.
15
+ */
16
+ export type AgentHost = 'claude' | 'codex' | 'cursor' | 'hermes';
17
+ export declare const AGENT_HOSTS: readonly AgentHost[];
18
+ export declare const HOST_NAMES: Record<AgentHost, string>;
19
+ export declare const PLUGIN_REPO = "agentguard-run/agentguard-codex-plugin";
20
+ export declare const PLUGIN_ID = "agentguard@agentguard";
21
+ export declare const HERMES_PACKAGE = "agentguard-spend-hermes";
22
+ export declare const HERMES_PLUGIN = "agentguard-spend";
23
+ /** Where the plugin lived before it moved; GitHub forwards it to PLUGIN_REPO. */
24
+ export declare const OLD_PLUGIN_REPO = "MerchantGuard/agentguard-codex-plugin";
25
+ /**
26
+ * The oldest plugin release this Burn treats as current. A host's local
27
+ * marketplace copy can be weeks stale (it refreshes only when asked), so an
28
+ * install older than this is updated even when that copy offers nothing newer.
29
+ */
30
+ export declare const PLUGIN_FLOOR_VERSION = "0.5.0";
31
+ /** Negative when a is older than b. Versions that are not x.y.z compare equal. */
32
+ export declare function compareVersions(a: string, b: string): number;
33
+ export interface InstallContext {
34
+ home: string;
35
+ env: Record<string, string | undefined>;
36
+ platform: NodeJS.Platform;
37
+ /** This Burn's cli.js. The Cursor hook runs it. */
38
+ cliPath: string;
39
+ }
40
+ export interface InstallOptions {
41
+ yes: boolean;
42
+ json: boolean;
43
+ /** Hosts named with --only, or null for every host. */
44
+ only: AgentHost[] | null;
45
+ skip: AgentHost[];
46
+ }
47
+ export declare const INSTALL_USAGE = "Usage: agentguard-burn install [--yes] [--only claude,codex,cursor,hermes] [--skip <hosts>] [--json]";
48
+ export declare function parseInstallArgs(args: string[]): InstallOptions | {
49
+ error: string;
50
+ };
51
+ export declare function which(name: string, ctx: Pick<InstallContext, 'env' | 'platform'>): string | null;
52
+ /**
53
+ * The plugin's two locked runtime packages are on disk: in its folder, or in
54
+ * the durable copy its postinstall keeps in the plugin data folder, keyed by
55
+ * the lockfile digest (Codex can replace its install cache at session start).
56
+ */
57
+ export declare function pluginDependenciesPresent(root: string, data?: string | null): boolean;
58
+ /** Where the host keeps the plugin's data: `<plugins>/data/agentguard-<marketplace>`, the same for Claude Code and Codex. */
59
+ export declare function pluginDataDir(configDir: string): string;
60
+ /** The mode AgentGuard runs in on a host, read from local files. */
61
+ export interface HostMode {
62
+ mode: 'enforce' | 'shadow';
63
+ /** Why it is not enforcing, or what can still change it; null when nothing does. */
64
+ reason: string | null;
65
+ /** Where the mode was read. */
66
+ source: string;
67
+ /** The status command that reports the effective mode on that host. */
68
+ check: string;
69
+ }
70
+ /** One host as found on this machine. */
71
+ export interface HostState {
72
+ host: AgentHost;
73
+ /** The host's command on PATH. */
74
+ binary: string | null;
75
+ /** Where the host keeps its config, whether or not it exists. */
76
+ configDir: string;
77
+ configDirExists: boolean;
78
+ present: boolean;
79
+ /** AgentGuard is in place and complete for this host. */
80
+ installed: boolean;
81
+ /** The host has AgentGuard registered (its record exists), complete or not. */
82
+ registered: boolean;
83
+ version: string | null;
84
+ /** The plugin folder, the hook file or the Python environment AgentGuard lives in. */
85
+ root: string | null;
86
+ /** The plugin's locked dependencies are on disk (Claude Code and Codex). */
87
+ dependencies: boolean | null;
88
+ /** The configured AgentGuard marketplace source, if any. */
89
+ marketplace: string | null;
90
+ /** False when the person turned AgentGuard off in the host's own config. */
91
+ enabled: boolean | null;
92
+ /** A file holding a standalone Burn hook for this host. */
93
+ standaloneHook: string | null;
94
+ /** Something found while reading that stops a safe install. */
95
+ problem: string | null;
96
+ /** Hermes: the Python environment Hermes runs from. */
97
+ python: string | null;
98
+ /** Cursor: a hook entry exists but its command is gone from disk. */
99
+ broken: boolean;
100
+ /** The mode AgentGuard runs in, once it is registered. */
101
+ mode: HostMode | null;
102
+ /** The plugin version the host's local marketplace copy offers. */
103
+ offered: string | null;
104
+ /** The version an update would bring, when the installed one is older. */
105
+ updateTo: string | null;
106
+ /** The marketplace still points at the plugin's old repository. */
107
+ oldMarketplace: boolean;
108
+ /** Nothing left to do: installed, current, and no standalone Burn hook beside an enabled plugin. */
109
+ complete: boolean;
110
+ }
111
+ /** The data folder the plugin derives from its install folder: `<plugins>/data/agentguard-<marketplace>`. */
112
+ export declare function dataDirForRoot(root: string): string;
113
+ export declare function probeHost(host: AgentHost, ctx: InstallContext): HostState;
114
+ export declare function detectHosts(ctx: InstallContext): HostState[];
115
+ export interface PlannedCommand {
116
+ /** The command as a person would type it, or what Burn does itself. */
117
+ command: string;
118
+ /** The program and arguments, run without a shell; null when Burn makes the change itself. */
119
+ argv: string[] | null;
120
+ /** Where it runs; null is the current folder. */
121
+ cwd: string | null;
122
+ /** Runs in the plugin folder the previous command installed, which is known only then. */
123
+ cwdFromPluginRoot?: boolean;
124
+ /** Runs only when the plugin's dependencies are missing after the step before. */
125
+ onlyIfDependenciesMissing?: boolean;
126
+ /** A change Burn makes itself (argv is null): Cursor's hook, or removing a standalone Burn hook from `file`. */
127
+ builtin?: 'cursor-hook' | 'remove-burn-hook';
128
+ file?: string;
129
+ }
130
+ export type HostPlanState = 'absent' | 'excluded' | 'installed' | 'install' | 'blocked';
131
+ export interface HostPlan {
132
+ host: AgentHost;
133
+ name: string;
134
+ found: {
135
+ binary: string | null;
136
+ configDir: string | null;
137
+ };
138
+ /** absent: not on this machine. excluded: left out by --only or --skip. installed: nothing to do. install: the commands below. blocked: present, but something it needs is missing. */
139
+ state: HostPlanState;
140
+ detail: string;
141
+ commands: PlannedCommand[];
142
+ /** Files and folders the commands change. */
143
+ files: string[];
144
+ notes: string[];
145
+ /** Named with --only. */
146
+ requested: boolean;
147
+ /** The mode AgentGuard runs in on this host, when it is already registered. */
148
+ mode: HostMode | null;
149
+ /** Set when an installed plugin is older than what is available. */
150
+ update?: {
151
+ from: string;
152
+ to: string;
153
+ } | null;
154
+ }
155
+ export interface InstallPlan {
156
+ hosts: HostPlan[];
157
+ options: InstallOptions;
158
+ /** The command that carries out this plan. */
159
+ next: string | null;
160
+ }
161
+ export declare function planInstall(ctx: InstallContext, options: InstallOptions): InstallPlan;
162
+ /** "enforce (local policy)" or "shadow: <why> (<where read>)". */
163
+ export declare function modeText(mode: HostMode): string;
164
+ export declare function renderPlan(plan: InstallPlan, ctx: InstallContext): string;
165
+ export interface RunResult {
166
+ status: number | null;
167
+ stdout: string;
168
+ stderr: string;
169
+ /** Set when the program could not be started (missing, timed out). */
170
+ error?: string;
171
+ }
172
+ export type Runner = (argv: string[], options: {
173
+ cwd: string | null;
174
+ }) => RunResult;
175
+ /** Runs a host command without a shell and without stdin, so nothing can wait on a prompt. */
176
+ export declare function defaultRunner(ctx: InstallContext): Runner;
177
+ export type HostOutcome = 'installed' | 'already-installed' | 'skipped' | 'failed';
178
+ export interface HostResult {
179
+ host: AgentHost;
180
+ name: string;
181
+ outcome: HostOutcome;
182
+ reason: string;
183
+ /** Every command started, in order, with its exit code. */
184
+ ran: Array<{
185
+ command: string;
186
+ cwd: string | null;
187
+ exitCode: number | null;
188
+ }>;
189
+ /** The host as read again after the run. */
190
+ after: {
191
+ installed: boolean;
192
+ version: string | null;
193
+ root: string | null;
194
+ mode: HostMode | null;
195
+ };
196
+ notes: string[];
197
+ }
198
+ export interface InstallReport {
199
+ ok: boolean;
200
+ hosts: HostResult[];
201
+ }
202
+ /**
203
+ * Carries out a plan: each host in turn, continuing past a host that fails,
204
+ * then reads every host again (the same checks the plan used) for its line.
205
+ */
206
+ export declare function runInstall(plan: InstallPlan, ctx: InstallContext, runner: Runner, log?: (line: string) => void): InstallReport;
207
+ export declare function renderReport(report: InstallReport): string;
208
+ /** What --json prints: the plan, and after --yes the result for each host. `mode` is plan or install; each host's `agentguardMode` is the enforce or shadow mode AgentGuard runs in there. */
209
+ export declare function installJson(version: string, plan: InstallPlan, report: InstallReport | null): Record<string, unknown>;