burnoff 1.0.0 → 1.2.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.
Files changed (41) hide show
  1. package/.github/workflows/burnoff-pr-gate.yml +75 -0
  2. package/README.md +94 -20
  3. package/bin/burnoff.mjs +129 -30
  4. package/hooks/hook-io.mjs +27 -18
  5. package/hooks/post-tool-use.mjs +33 -26
  6. package/hooks/pre-tool-use.mjs +43 -41
  7. package/hooks/session-lifecycle.mjs +40 -0
  8. package/package.json +8 -5
  9. package/src/ci/ci-gate.mjs +84 -9
  10. package/src/ci/pr-cost.mjs +207 -22
  11. package/src/ci/team-digest.mjs +6 -4
  12. package/src/cli/audit.mjs +177 -23
  13. package/src/cli/doctor.mjs +230 -25
  14. package/src/cli/init.mjs +415 -75
  15. package/src/cli/startup-audit.mjs +2824 -0
  16. package/src/clients/antigravity.mjs +285 -0
  17. package/src/clients/claude-code.mjs +180 -0
  18. package/src/clients/detect.mjs +64 -0
  19. package/src/config/catalog.json +188 -45
  20. package/src/config/loader.mjs +96 -13
  21. package/src/config/paths.mjs +92 -2
  22. package/src/config/policy.mjs +103 -17
  23. package/src/config/pricing.mjs +1033 -0
  24. package/src/config/uncached-attribution.mjs +719 -0
  25. package/src/guards/loop-breaker.mjs +267 -24
  26. package/src/guards/post-tool-engine.mjs +316 -35
  27. package/src/guards/pre-tool-engine.mjs +389 -130
  28. package/src/guards/read-clamp.mjs +149 -75
  29. package/src/guards/session-hook.mjs +207 -0
  30. package/src/guards/shell-guard.mjs +610 -74
  31. package/src/ipc/daemon.mjs +50 -8
  32. package/src/ipc/fast-client.mjs +62 -5
  33. package/src/ipc/protocol.mjs +1 -1
  34. package/src/storage/antigravity-parser.mjs +258 -0
  35. package/src/storage/atomic-io.mjs +2 -2
  36. package/src/storage/file-lock.mjs +66 -13
  37. package/src/storage/fts5-archive.mjs +31 -16
  38. package/src/storage/jsonl-parser.mjs +209 -20
  39. package/src/storage/ledger.mjs +15 -10
  40. package/src/storage/sqlite-client.mjs +35 -11
  41. package/hooks/hooks.json +0 -12
package/src/cli/init.mjs CHANGED
@@ -8,6 +8,7 @@
8
8
  import fs from 'node:fs';
9
9
  import path from 'node:path';
10
10
  import { fileURLToPath } from 'node:url';
11
+ import { getHomeDir } from '../config/paths.mjs';
11
12
  import { atomicWriteFileSync, atomicWriteJsonSync } from '../storage/atomic-io.mjs';
12
13
 
13
14
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
@@ -16,16 +17,30 @@ export const PACKAGE_ROOT = path.resolve(__dirname, '../..');
16
17
  export const PRE_TOOL_MATCHER =
17
18
  'Bash|PowerShell|Edit|MultiEdit|Write|NotebookEdit|Read|Grep|Glob|Task|Agent|WebFetch|mcp__.*';
18
19
  export const POST_TOOL_MATCHER =
19
- 'Bash|PowerShell|Grep|Glob|Task|Agent|WebFetch|mcp__.*';
20
+ 'Bash|PowerShell|Edit|MultiEdit|Write|NotebookEdit|Task|Agent|WebFetch|mcp__.*';
21
+ export const SESSION_START_MATCHER = 'startup|resume|clear|compact';
22
+ export const ANTIGRAVITY_PRE_TOOL_MATCHER =
23
+ 'run_command|read_file|view_file|write_file|write_to_file|edit_file|replace_file_content|multi_replace_file_content|grep_search|find_by_name|list_dir|invoke_subagent|read_url_content|call_mcp_tool|mcp_.*';
24
+ export const ANTIGRAVITY_POST_TOOL_MATCHER =
25
+ 'run_command|read_file|view_file|write_file|write_to_file|edit_file|replace_file_content|multi_replace_file_content|grep_search|find_by_name|invoke_subagent|read_url_content|call_mcp_tool|mcp_.*';
20
26
 
21
27
  const EXCLUDE_START_MARKER = '# burnoff-managed:start';
22
28
  const EXCLUDE_END_MARKER = '# burnoff-managed:end';
23
- const EXCLUDE_PATTERNS = Object.freeze([
29
+ const CLAUDE_EXCLUDE_PATTERNS = Object.freeze([
24
30
  '.claude/settings.local.json',
31
+ '.claude/burnoff-hook-shim.mjs',
25
32
  '.claude/cache/',
26
33
  '.claude/locks/',
27
- '.burnoff-ci/'
34
+ '.burnoff/'
28
35
  ]);
36
+ const ANTIGRAVITY_EXCLUDE_PATTERNS = Object.freeze([
37
+ '.burnoff/'
38
+ ]);
39
+
40
+ export function isEphemeralNpxPath(pkgRoot = PACKAGE_ROOT) {
41
+ const norm = String(pkgRoot || '').replace(/\\/g, '/');
42
+ return /(?:^|\/)_npx(?:\/|$)|(?:^|\/)npm-cache\/_npx(?:\/|$)/i.test(norm);
43
+ }
29
44
 
30
45
  function normalizeCommandPath(filePath) {
31
46
  return path.resolve(filePath).replace(/\\/g, '/');
@@ -34,8 +49,9 @@ function normalizeCommandPath(filePath) {
34
49
  function isBurnoffCommand(command = '') {
35
50
  const cmd = String(command || '').replace(/\\/g, '/');
36
51
  if (!cmd) return false;
52
+ if (/\.claude\/burnoff-hook-shim\.mjs/i.test(cmd)) return true;
37
53
  return (
38
- /(?:^|[/"'\s])hooks\/(?:pre|post)-tool-use\.mjs(?:["'\s]|$)/i.test(cmd) &&
54
+ /(?:^|[/"'\s])hooks\/(?:(?:pre|post)-tool-use|session-lifecycle)\.mjs(?:["'\s]|$)/i.test(cmd) &&
39
55
  (/burnoff/i.test(cmd) ||
40
56
  cmd.includes(normalizeCommandPath(path.join(PACKAGE_ROOT, 'hooks'))))
41
57
  );
@@ -62,12 +78,12 @@ function resolveGitDir(cwd) {
62
78
  return null;
63
79
  }
64
80
 
65
- function buildExcludeBlock() {
66
- return [EXCLUDE_START_MARKER, ...EXCLUDE_PATTERNS, EXCLUDE_END_MARKER].join('\n');
81
+ function buildExcludeBlock(patterns = CLAUDE_EXCLUDE_PATTERNS) {
82
+ return [EXCLUDE_START_MARKER, ...patterns, EXCLUDE_END_MARKER].join('\n');
67
83
  }
68
84
 
69
- function upsertExcludeBlock(existingContent = '') {
70
- const block = buildExcludeBlock();
85
+ function upsertExcludeBlock(existingContent = '', patterns = CLAUDE_EXCLUDE_PATTERNS) {
86
+ const block = buildExcludeBlock(patterns);
71
87
  const blockRe = new RegExp(
72
88
  `${EXCLUDE_START_MARKER}[\\s\\S]*?${EXCLUDE_END_MARKER}\\r?\\n?`,
73
89
  'g'
@@ -116,13 +132,74 @@ function readJsonObjectSafe(filePath) {
116
132
  return {};
117
133
  }
118
134
 
135
+ function buildHookShimSource(fallbackPackageRoot) {
136
+ const fallback = normalizeCommandPath(fallbackPackageRoot);
137
+ return `import fs from 'node:fs';
138
+ import path from 'node:path';
139
+ import { createRequire } from 'node:module';
140
+ import { fileURLToPath, pathToFileURL } from 'node:url';
141
+
142
+ const hookArgMap = {
143
+ post: 'post-tool-use.mjs',
144
+ session: 'session-lifecycle.mjs',
145
+ pre: 'pre-tool-use.mjs'
146
+ };
147
+ const hookArg = hookArgMap[process.argv[2]] || 'pre-tool-use.mjs';
148
+ const cwd = process.cwd();
149
+ const parentDir = path.dirname(cwd);
150
+ const shimDir = path.dirname(fileURLToPath(import.meta.url));
151
+ const candidates = [
152
+ path.join(cwd, 'node_modules', 'burnoff', 'hooks', hookArg),
153
+ path.join(parentDir, 'node_modules', 'burnoff', 'hooks', hookArg),
154
+ path.join(shimDir, '..', 'node_modules', 'burnoff', 'hooks', hookArg)
155
+ ];
156
+
157
+ for (const baseDir of [cwd, parentDir, path.join(shimDir, '..')]) {
158
+ try {
159
+ const req = createRequire(path.join(baseDir, 'package.json'));
160
+ const pkgPath = req.resolve('burnoff/package.json');
161
+ candidates.push(path.join(path.dirname(pkgPath), 'hooks', hookArg));
162
+ } catch {
163
+ // ignore: local/global resolution miss falls back to bundled path
164
+ }
165
+ }
166
+
167
+ candidates.push(path.join(${JSON.stringify(fallback)}, 'hooks', hookArg));
168
+
169
+ const resolved = candidates.find((p) => {
170
+ try {
171
+ return fs.existsSync(p);
172
+ } catch {
173
+ return false;
174
+ }
175
+ });
176
+
177
+ if (!resolved) {
178
+ process.stderr.write(
179
+ '[burnoff] Hook target missing (ephemeral npx cache cleared). Install persistently: npm i -D burnoff or npm i -g burnoff.\\n'
180
+ );
181
+ process.exit(0);
182
+ }
183
+
184
+ await import(pathToFileURL(resolved).href);
185
+ `;
186
+ }
187
+
119
188
  /**
120
- * Builds Claude Code `PreToolUse` and `PostToolUse` hook definitions pointing to Burnoff's fast-shell hooks.
189
+ * Builds Claude Code `PreToolUse`, `PostToolUse`, `PostToolUseFailure`, `SessionStart`,
190
+ * and `PreCompact` hook definitions pointing to Burnoff's fast-shell hooks.
121
191
  */
122
192
  export function buildClaudeHooksConfig(options = {}) {
123
193
  const root = path.resolve(options.packageRoot || PACKAGE_ROOT);
124
- const prePath = normalizeCommandPath(path.join(root, 'hooks', 'pre-tool-use.mjs'));
125
- const postPath = normalizeCommandPath(path.join(root, 'hooks', 'post-tool-use.mjs'));
194
+ const preCmd = options.shimPath
195
+ ? `node "${normalizeCommandPath(options.shimPath)}" pre`
196
+ : `node "${normalizeCommandPath(path.join(root, 'hooks', 'pre-tool-use.mjs'))}"`;
197
+ const postCmd = options.shimPath
198
+ ? `node "${normalizeCommandPath(options.shimPath)}" post`
199
+ : `node "${normalizeCommandPath(path.join(root, 'hooks', 'post-tool-use.mjs'))}"`;
200
+ const sessionCmd = options.shimPath
201
+ ? `node "${normalizeCommandPath(options.shimPath)}" session`
202
+ : `node "${normalizeCommandPath(path.join(root, 'hooks', 'session-lifecycle.mjs'))}"`;
126
203
  const timeout = Number.isFinite(Number(options.timeout)) ? Number(options.timeout) : 5;
127
204
 
128
205
  return {
@@ -132,7 +209,7 @@ export function buildClaudeHooksConfig(options = {}) {
132
209
  hooks: [
133
210
  {
134
211
  type: 'command',
135
- command: `node "${prePath}"`,
212
+ command: preCmd,
136
213
  timeout
137
214
  }
138
215
  ]
@@ -144,7 +221,90 @@ export function buildClaudeHooksConfig(options = {}) {
144
221
  hooks: [
145
222
  {
146
223
  type: 'command',
147
- command: `node "${postPath}"`,
224
+ command: postCmd,
225
+ timeout
226
+ }
227
+ ]
228
+ }
229
+ ],
230
+ PostToolUseFailure: [
231
+ {
232
+ matcher: options.postMatcher || POST_TOOL_MATCHER,
233
+ hooks: [
234
+ {
235
+ type: 'command',
236
+ command: postCmd,
237
+ timeout
238
+ }
239
+ ]
240
+ }
241
+ ],
242
+ SessionStart: [
243
+ {
244
+ matcher: options.sessionStartMatcher || SESSION_START_MATCHER,
245
+ hooks: [
246
+ {
247
+ type: 'command',
248
+ command: sessionCmd,
249
+ timeout
250
+ }
251
+ ]
252
+ }
253
+ ],
254
+ PreCompact: [
255
+ {
256
+ hooks: [
257
+ {
258
+ type: 'command',
259
+ command: sessionCmd,
260
+ timeout
261
+ }
262
+ ]
263
+ }
264
+ ]
265
+ };
266
+ }
267
+
268
+ function resolveAntigravityHookCommand(hookFileName, shimArg, options = {}) {
269
+ const root = path.resolve(options.packageRoot || PACKAGE_ROOT);
270
+
271
+ if (options.shimPath) {
272
+ const shimAbs = path.resolve(options.shimPath);
273
+ return `node "${normalizeCommandPath(shimAbs)}" ${shimArg}`;
274
+ }
275
+
276
+ return `node "${normalizeCommandPath(path.join(root, 'hooks', hookFileName))}"`;
277
+ }
278
+
279
+ /**
280
+ * Builds Google Antigravity `hooks.json` `"burnoff"` entry supporting both Antigravity 2.0 and IDE v1.
281
+ */
282
+ export function buildAntigravityHooksConfig(options = {}) {
283
+ const preCmd = resolveAntigravityHookCommand('pre-tool-use.mjs', 'pre', options);
284
+ const postCmd = resolveAntigravityHookCommand('post-tool-use.mjs', 'post', options);
285
+ const timeout = Number.isFinite(Number(options.timeout)) ? Number(options.timeout) : 5;
286
+
287
+ return {
288
+ enabled: true,
289
+ PreToolUse: [
290
+ {
291
+ matcher: options.preMatcher || ANTIGRAVITY_PRE_TOOL_MATCHER,
292
+ hooks: [
293
+ {
294
+ type: 'command',
295
+ command: preCmd,
296
+ timeout
297
+ }
298
+ ]
299
+ }
300
+ ],
301
+ PostToolUse: [
302
+ {
303
+ matcher: options.postMatcher || ANTIGRAVITY_POST_TOOL_MATCHER,
304
+ hooks: [
305
+ {
306
+ type: 'command',
307
+ command: postCmd,
148
308
  timeout
149
309
  }
150
310
  ]
@@ -153,45 +313,130 @@ export function buildClaudeHooksConfig(options = {}) {
153
313
  };
154
314
  }
155
315
 
316
+ export function resolveInitClients(clientOpt = 'claude', { cwd = process.cwd(), homeDir = getHomeDir() } = {}) {
317
+ const raw = String(clientOpt || 'claude').trim().toLowerCase();
318
+ if (raw === 'antigravity' || raw === 'ag') return ['antigravity'];
319
+ if (raw === 'both' || raw === 'all') return ['claude', 'antigravity'];
320
+ if (raw === 'auto') {
321
+ const detected = [];
322
+ if (fs.existsSync(path.join(cwd, '.claude'))) detected.push('claude');
323
+ if (
324
+ fs.existsSync(path.join(cwd, '.agents')) ||
325
+ fs.existsSync(path.join(homeDir, '.gemini', 'config'))
326
+ ) {
327
+ detected.push('antigravity');
328
+ }
329
+ return detected.length > 0 ? detected : ['claude'];
330
+ }
331
+ return ['claude'];
332
+ }
333
+
156
334
  /**
157
- * Installs Burnoff hooks into `<cwd>/.claude/settings.local.json` and adds local state paths
158
- * to `<gitDir>/info/exclude` without touching `.claude/settings.json` or `.gitignore`.
335
+ * Installs Burnoff hooks for Claude Code (`.claude/settings.local.json`) and/or
336
+ * Google Antigravity (`.agents/hooks.json` or `--global` `~/.gemini/config/hooks.json`).
159
337
  */
160
338
  export function initBurnoff(options = {}) {
161
339
  const cwd = path.resolve(options.cwd || process.cwd());
340
+ const homeDir = options.homeDir || getHomeDir();
162
341
  const dryRun = Boolean(options.dryRun);
163
- const settingsPath = path.join(cwd, '.claude', 'settings.local.json');
164
- const hooks = buildClaudeHooksConfig(options);
165
-
166
- const current = readJsonObjectSafe(settingsPath);
167
- const existingHooks =
168
- current.hooks && typeof current.hooks === 'object' && !Array.isArray(current.hooks)
169
- ? { ...current.hooks }
170
- : {};
171
-
172
- const prevPre = filterOutBurnoffMatcherGroups(existingHooks.PreToolUse);
173
- const prevPost = filterOutBurnoffMatcherGroups(existingHooks.PostToolUse);
174
-
175
- const nextSettings = {
176
- ...current,
177
- hooks: {
178
- ...existingHooks,
179
- PreToolUse: [...prevPre, ...hooks.PreToolUse],
180
- PostToolUse: [...prevPost, ...hooks.PostToolUse]
342
+ const isGlobal = Boolean(options.global);
343
+ const pkgRoot = path.resolve(options.packageRoot || PACKAGE_ROOT);
344
+ const ephemeralNpx = isEphemeralNpxPath(pkgRoot);
345
+ const useShim = Boolean(options.useShim || ephemeralNpx);
346
+ const clients = resolveInitClients(options.client || 'claude', { cwd, homeDir });
347
+ const installClaude = clients.includes('claude');
348
+ const installAntigravity = clients.includes('antigravity');
349
+
350
+ const warnings = [];
351
+ const shimPath = installClaude && useShim ? path.join(cwd, '.claude', 'burnoff-hook-shim.mjs') : null;
352
+ const agShimPath =
353
+ installAntigravity && useShim
354
+ ? (shimPath || path.join(cwd, '.burnoff', 'hook-shim.mjs'))
355
+ : null;
356
+
357
+ if (ephemeralNpx) {
358
+ warnings.push(
359
+ `Ephemeral npx cache path detected; wrote ${agShimPath && !shimPath ? '.burnoff/hook-shim.mjs' : '.claude/burnoff-hook-shim.mjs'}. Install persistently with "npm i -D burnoff" or "npm i -g burnoff".`
360
+ );
361
+ }
362
+
363
+ let settingsPath = path.join(cwd, '.claude', 'settings.local.json');
364
+ let hooks = null;
365
+ if (installClaude) {
366
+ hooks = buildClaudeHooksConfig({
367
+ ...options,
368
+ packageRoot: pkgRoot,
369
+ ...(shimPath ? { shimPath } : {})
370
+ });
371
+
372
+ const current = readJsonObjectSafe(settingsPath);
373
+ const existingHooks =
374
+ current.hooks && typeof current.hooks === 'object' && !Array.isArray(current.hooks)
375
+ ? { ...current.hooks }
376
+ : {};
377
+
378
+ const prevPre = filterOutBurnoffMatcherGroups(existingHooks.PreToolUse);
379
+ const prevPost = filterOutBurnoffMatcherGroups(existingHooks.PostToolUse);
380
+ const prevPostFail = filterOutBurnoffMatcherGroups(existingHooks.PostToolUseFailure);
381
+ const prevSessionStart = filterOutBurnoffMatcherGroups(existingHooks.SessionStart);
382
+ const prevPreCompact = filterOutBurnoffMatcherGroups(existingHooks.PreCompact);
383
+
384
+ const nextSettings = {
385
+ ...current,
386
+ hooks: {
387
+ ...existingHooks,
388
+ PreToolUse: [...prevPre, ...hooks.PreToolUse],
389
+ PostToolUse: [...prevPost, ...hooks.PostToolUse],
390
+ PostToolUseFailure: [...prevPostFail, ...hooks.PostToolUseFailure],
391
+ SessionStart: [...prevSessionStart, ...hooks.SessionStart],
392
+ PreCompact: [...prevPreCompact, ...hooks.PreCompact]
393
+ }
394
+ };
395
+
396
+ if (!dryRun) {
397
+ if (shimPath) {
398
+ atomicWriteFileSync(shimPath, buildHookShimSource(pkgRoot), { encoding: 'utf8' });
399
+ }
400
+ atomicWriteJsonSync(settingsPath, nextSettings);
181
401
  }
182
- };
402
+ }
403
+
404
+ let antigravityHooksPath = null;
405
+ let antigravityHooks = null;
406
+ if (installAntigravity) {
407
+ antigravityHooksPath = isGlobal
408
+ ? path.join(homeDir, '.gemini', 'config', 'hooks.json')
409
+ : path.join(cwd, '.agents', 'hooks.json');
410
+ antigravityHooks = buildAntigravityHooksConfig({
411
+ ...options,
412
+ cwd,
413
+ global: isGlobal,
414
+ packageRoot: pkgRoot,
415
+ ...(agShimPath ? { shimPath: agShimPath } : {})
416
+ });
183
417
 
184
- if (!dryRun) {
185
- atomicWriteJsonSync(settingsPath, nextSettings);
418
+ const currentAg = readJsonObjectSafe(antigravityHooksPath);
419
+ const nextAg = {
420
+ ...currentAg,
421
+ burnoff: antigravityHooks
422
+ };
423
+
424
+ if (!dryRun) {
425
+ if (agShimPath && agShimPath !== shimPath) {
426
+ atomicWriteFileSync(agShimPath, buildHookShimSource(pkgRoot), { encoding: 'utf8' });
427
+ }
428
+ atomicWriteJsonSync(antigravityHooksPath, nextAg);
429
+ }
186
430
  }
187
431
 
188
432
  let excludePath = null;
189
433
  let excludeUpdated = false;
190
- const gitDir = resolveGitDir(cwd);
434
+ const gitDir = !isGlobal || installClaude ? resolveGitDir(cwd) : null;
191
435
  if (gitDir) {
192
436
  excludePath = path.join(gitDir, 'info', 'exclude');
193
437
  const prevExclude = fs.existsSync(excludePath) ? fs.readFileSync(excludePath, 'utf8') : '';
194
- const nextExclude = upsertExcludeBlock(prevExclude);
438
+ const patterns = installClaude ? CLAUDE_EXCLUDE_PATTERNS : ANTIGRAVITY_EXCLUDE_PATTERNS;
439
+ const nextExclude = upsertExcludeBlock(prevExclude, patterns);
195
440
  if (nextExclude !== prevExclude) {
196
441
  excludeUpdated = true;
197
442
  if (!dryRun) {
@@ -204,66 +449,151 @@ export function initBurnoff(options = {}) {
204
449
  ok: true,
205
450
  dryRun,
206
451
  cwd,
452
+ clients,
453
+ global: isGlobal,
207
454
  settingsPath,
455
+ antigravityHooksPath,
456
+ shimPath: shimPath || agShimPath,
457
+ ephemeralNpx,
458
+ warnings,
208
459
  excludePath,
209
460
  excludeUpdated,
210
- hooks
461
+ hooks,
462
+ antigravityHooks
211
463
  };
212
464
  }
213
465
 
214
466
  /**
215
- * Removes Burnoff hooks from `<cwd>/.claude/settings.local.json` and cleans `<gitDir>/info/exclude`.
467
+ * Removes Burnoff hooks for Claude Code and/or Google Antigravity and cleans `<gitDir>/info/exclude`.
216
468
  */
217
469
  export function uninstallBurnoff(options = {}) {
218
470
  const cwd = path.resolve(options.cwd || process.cwd());
471
+ const homeDir = options.homeDir || getHomeDir();
219
472
  const dryRun = Boolean(options.dryRun);
473
+ const isGlobal = Boolean(options.global);
474
+ const clients = options.client
475
+ ? resolveInitClients(options.client, { cwd, homeDir })
476
+ : ['claude', 'antigravity'];
477
+ const uninstallClaude = clients.includes('claude');
478
+ const uninstallAntigravity = clients.includes('antigravity');
479
+
220
480
  const settingsPath = path.join(cwd, '.claude', 'settings.local.json');
221
481
  let removedSettings = false;
222
482
  let updatedSettings = false;
223
483
 
224
- if (fs.existsSync(settingsPath)) {
225
- const current = readJsonObjectSafe(settingsPath);
226
- const nextHooks =
227
- current.hooks && typeof current.hooks === 'object' && !Array.isArray(current.hooks)
228
- ? { ...current.hooks }
229
- : {};
230
-
231
- if (nextHooks.PreToolUse) {
232
- const keptPre = filterOutBurnoffMatcherGroups(nextHooks.PreToolUse);
233
- if (keptPre.length > 0) nextHooks.PreToolUse = keptPre;
234
- else delete nextHooks.PreToolUse;
484
+ if (uninstallClaude) {
485
+ const shimPath = path.join(cwd, '.claude', 'burnoff-hook-shim.mjs');
486
+ if (fs.existsSync(shimPath) && !dryRun) {
487
+ try {
488
+ fs.unlinkSync(shimPath);
489
+ } catch (err) {
490
+ void err; // ignore: shim unlink best-effort
491
+ }
235
492
  }
236
- if (nextHooks.PostToolUse) {
237
- const keptPost = filterOutBurnoffMatcherGroups(nextHooks.PostToolUse);
238
- if (keptPost.length > 0) nextHooks.PostToolUse = keptPost;
239
- else delete nextHooks.PostToolUse;
493
+
494
+ if (fs.existsSync(settingsPath)) {
495
+ const current = readJsonObjectSafe(settingsPath);
496
+ const nextHooks =
497
+ current.hooks && typeof current.hooks === 'object' && !Array.isArray(current.hooks)
498
+ ? { ...current.hooks }
499
+ : {};
500
+
501
+ if (nextHooks.PreToolUse) {
502
+ const keptPre = filterOutBurnoffMatcherGroups(nextHooks.PreToolUse);
503
+ if (keptPre.length > 0) nextHooks.PreToolUse = keptPre;
504
+ else delete nextHooks.PreToolUse;
505
+ }
506
+ if (nextHooks.PostToolUse) {
507
+ const keptPost = filterOutBurnoffMatcherGroups(nextHooks.PostToolUse);
508
+ if (keptPost.length > 0) nextHooks.PostToolUse = keptPost;
509
+ else delete nextHooks.PostToolUse;
510
+ }
511
+ if (nextHooks.PostToolUseFailure) {
512
+ const keptPostFail = filterOutBurnoffMatcherGroups(nextHooks.PostToolUseFailure);
513
+ if (keptPostFail.length > 0) nextHooks.PostToolUseFailure = keptPostFail;
514
+ else delete nextHooks.PostToolUseFailure;
515
+ }
516
+ if (nextHooks.SessionStart) {
517
+ const keptSessionStart = filterOutBurnoffMatcherGroups(nextHooks.SessionStart);
518
+ if (keptSessionStart.length > 0) nextHooks.SessionStart = keptSessionStart;
519
+ else delete nextHooks.SessionStart;
520
+ }
521
+ if (nextHooks.PreCompact) {
522
+ const keptPreCompact = filterOutBurnoffMatcherGroups(nextHooks.PreCompact);
523
+ if (keptPreCompact.length > 0) nextHooks.PreCompact = keptPreCompact;
524
+ else delete nextHooks.PreCompact;
525
+ }
526
+
527
+ const nextSettings = { ...current };
528
+ if (Object.keys(nextHooks).length > 0) {
529
+ nextSettings.hooks = nextHooks;
530
+ } else {
531
+ delete nextSettings.hooks;
532
+ }
533
+
534
+ if (Object.keys(nextSettings).length === 0) {
535
+ removedSettings = true;
536
+ if (!dryRun) {
537
+ fs.unlinkSync(settingsPath);
538
+ const claudeDir = path.dirname(settingsPath);
539
+ try {
540
+ if (fs.existsSync(claudeDir) && fs.readdirSync(claudeDir).length === 0) {
541
+ fs.rmdirSync(claudeDir);
542
+ }
543
+ } catch (err) {
544
+ void err; // ignore: non-empty or locked .claude directory left intact
545
+ }
546
+ }
547
+ } else {
548
+ updatedSettings = true;
549
+ if (!dryRun) {
550
+ atomicWriteJsonSync(settingsPath, nextSettings);
551
+ }
552
+ }
240
553
  }
554
+ }
241
555
 
242
- const nextSettings = { ...current };
243
- if (Object.keys(nextHooks).length > 0) {
244
- nextSettings.hooks = nextHooks;
245
- } else {
246
- delete nextSettings.hooks;
556
+ const antigravityHooksPath = isGlobal
557
+ ? path.join(homeDir, '.gemini', 'config', 'hooks.json')
558
+ : path.join(cwd, '.agents', 'hooks.json');
559
+ let removedAntigravityHooks = false;
560
+ let updatedAntigravityHooks = false;
561
+
562
+ if (uninstallAntigravity) {
563
+ const agShimPath = path.join(cwd, '.burnoff', 'hook-shim.mjs');
564
+ if (fs.existsSync(agShimPath) && !dryRun) {
565
+ try {
566
+ fs.unlinkSync(agShimPath);
567
+ } catch (err) {
568
+ void err; // ignore: Antigravity shim unlink best-effort
569
+ }
247
570
  }
248
571
 
249
- if (Object.keys(nextSettings).length === 0) {
250
- removedSettings = true;
251
- if (!dryRun) {
252
- fs.unlinkSync(settingsPath);
253
- const claudeDir = path.dirname(settingsPath);
254
- try {
255
- if (fs.existsSync(claudeDir) && fs.readdirSync(claudeDir).length === 0) {
256
- fs.rmdirSync(claudeDir);
572
+ if (fs.existsSync(antigravityHooksPath)) {
573
+ const currentAg = readJsonObjectSafe(antigravityHooksPath);
574
+ if (Object.prototype.hasOwnProperty.call(currentAg, 'burnoff')) {
575
+ const nextAg = { ...currentAg };
576
+ delete nextAg.burnoff;
577
+ if (Object.keys(nextAg).length === 0) {
578
+ removedAntigravityHooks = true;
579
+ if (!dryRun) {
580
+ fs.unlinkSync(antigravityHooksPath);
581
+ const agDir = path.dirname(antigravityHooksPath);
582
+ try {
583
+ if (!isGlobal && fs.existsSync(agDir) && fs.readdirSync(agDir).length === 0) {
584
+ fs.rmdirSync(agDir);
585
+ }
586
+ } catch (err) {
587
+ void err; // ignore: non-empty or locked .agents directory left intact
588
+ }
589
+ }
590
+ } else {
591
+ updatedAntigravityHooks = true;
592
+ if (!dryRun) {
593
+ atomicWriteJsonSync(antigravityHooksPath, nextAg);
257
594
  }
258
- } catch (err) {
259
- void err; // ignore: non-empty or locked .claude directory left intact
260
595
  }
261
596
  }
262
- } else {
263
- updatedSettings = true;
264
- if (!dryRun) {
265
- atomicWriteJsonSync(settingsPath, nextSettings);
266
- }
267
597
  }
268
598
  }
269
599
 
@@ -288,9 +618,14 @@ export function uninstallBurnoff(options = {}) {
288
618
  ok: true,
289
619
  dryRun,
290
620
  cwd,
621
+ clients,
622
+ global: isGlobal,
291
623
  settingsPath,
292
624
  removedSettings,
293
625
  updatedSettings,
626
+ antigravityHooksPath,
627
+ removedAntigravityHooks,
628
+ updatedAntigravityHooks,
294
629
  excludePath,
295
630
  excludeUpdated
296
631
  };
@@ -300,7 +635,12 @@ export default {
300
635
  PACKAGE_ROOT,
301
636
  PRE_TOOL_MATCHER,
302
637
  POST_TOOL_MATCHER,
638
+ SESSION_START_MATCHER,
639
+ ANTIGRAVITY_PRE_TOOL_MATCHER,
640
+ ANTIGRAVITY_POST_TOOL_MATCHER,
303
641
  buildClaudeHooksConfig,
642
+ buildAntigravityHooksConfig,
643
+ resolveInitClients,
304
644
  initBurnoff,
305
645
  uninstallBurnoff
306
646
  };