burnoff 1.1.0 → 1.3.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 (45) hide show
  1. package/.claude-plugin/plugin.json +11 -0
  2. package/.github/workflows/burnoff-pr-gate.yml +3 -3
  3. package/.github/workflows/burnoff-startup-lint.yml +37 -0
  4. package/README.md +90 -75
  5. package/bin/burnoff.mjs +185 -24
  6. package/commands/burnoff.md +16 -0
  7. package/docs/CLAUDE_CODE_PLUGIN.md +67 -0
  8. package/docs/DESIGN_PARTNER_INTAKE.md +44 -0
  9. package/hooks/hook-io.mjs +19 -7
  10. package/hooks/post-tool-use.mjs +33 -26
  11. package/hooks/pre-tool-use.mjs +43 -41
  12. package/hooks/session-lifecycle.mjs +40 -0
  13. package/package.json +15 -7
  14. package/scripts/burnoff-statusline.mjs +84 -0
  15. package/src/ci/ci-gate.mjs +22 -0
  16. package/src/ci/pr-cost.mjs +42 -10
  17. package/src/ci/team-digest.mjs +5 -3
  18. package/src/cli/audit.mjs +103 -18
  19. package/src/cli/doctor.mjs +209 -14
  20. package/src/cli/init.mjs +349 -96
  21. package/src/cli/startup-audit.mjs +712 -62
  22. package/src/clients/antigravity.mjs +285 -0
  23. package/src/clients/claude-code.mjs +180 -0
  24. package/src/clients/detect.mjs +64 -0
  25. package/src/config/loader.mjs +11 -4
  26. package/src/config/paths.mjs +62 -2
  27. package/src/config/policy.mjs +34 -5
  28. package/src/config/pricing.mjs +16 -5
  29. package/src/guards/loop-breaker.mjs +198 -13
  30. package/src/guards/post-tool-engine.mjs +289 -29
  31. package/src/guards/pre-tool-engine.mjs +382 -151
  32. package/src/guards/read-clamp.mjs +78 -18
  33. package/src/guards/session-hook.mjs +207 -0
  34. package/src/guards/shell-guard.mjs +583 -73
  35. package/src/guards/snooze.mjs +360 -0
  36. package/src/ipc/daemon.mjs +50 -8
  37. package/src/ipc/fast-client.mjs +62 -5
  38. package/src/ipc/protocol.mjs +1 -1
  39. package/src/storage/antigravity-parser.mjs +258 -0
  40. package/src/storage/file-lock.mjs +13 -4
  41. package/src/storage/fts5-archive.mjs +4 -4
  42. package/src/storage/jsonl-parser.mjs +7 -1
  43. package/src/storage/ledger.mjs +10 -3
  44. package/src/storage/sqlite-client.mjs +4 -2
  45. 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,17 +17,24 @@ 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',
25
31
  '.claude/burnoff-hook-shim.mjs',
26
32
  '.claude/cache/',
27
33
  '.claude/locks/',
28
- '.burnoff/',
29
- '.burnoff-ci/'
34
+ '.burnoff/'
35
+ ]);
36
+ const ANTIGRAVITY_EXCLUDE_PATTERNS = Object.freeze([
37
+ '.burnoff/'
30
38
  ]);
31
39
 
32
40
  export function isEphemeralNpxPath(pkgRoot = PACKAGE_ROOT) {
@@ -43,7 +51,7 @@ function isBurnoffCommand(command = '') {
43
51
  if (!cmd) return false;
44
52
  if (/\.claude\/burnoff-hook-shim\.mjs/i.test(cmd)) return true;
45
53
  return (
46
- /(?:^|[/"'\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) &&
47
55
  (/burnoff/i.test(cmd) ||
48
56
  cmd.includes(normalizeCommandPath(path.join(PACKAGE_ROOT, 'hooks'))))
49
57
  );
@@ -70,12 +78,12 @@ function resolveGitDir(cwd) {
70
78
  return null;
71
79
  }
72
80
 
73
- function buildExcludeBlock() {
74
- 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');
75
83
  }
76
84
 
77
- function upsertExcludeBlock(existingContent = '') {
78
- const block = buildExcludeBlock();
85
+ function upsertExcludeBlock(existingContent = '', patterns = CLAUDE_EXCLUDE_PATTERNS) {
86
+ const block = buildExcludeBlock(patterns);
79
87
  const blockRe = new RegExp(
80
88
  `${EXCLUDE_START_MARKER}[\\s\\S]*?${EXCLUDE_END_MARKER}\\r?\\n?`,
81
89
  'g'
@@ -129,20 +137,31 @@ function buildHookShimSource(fallbackPackageRoot) {
129
137
  return `import fs from 'node:fs';
130
138
  import path from 'node:path';
131
139
  import { createRequire } from 'node:module';
132
- import { pathToFileURL } from 'node:url';
140
+ import { fileURLToPath, pathToFileURL } from 'node:url';
133
141
 
134
- const hookArg = process.argv[2] === 'post' ? 'post-tool-use.mjs' : 'pre-tool-use.mjs';
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';
135
148
  const cwd = process.cwd();
149
+ const parentDir = path.dirname(cwd);
150
+ const shimDir = path.dirname(fileURLToPath(import.meta.url));
136
151
  const candidates = [
137
- path.join(cwd, 'node_modules', 'burnoff', 'hooks', hookArg)
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)
138
155
  ];
139
156
 
140
- try {
141
- const req = createRequire(path.join(cwd, 'package.json'));
142
- const pkgPath = req.resolve('burnoff/package.json');
143
- candidates.push(path.join(path.dirname(pkgPath), 'hooks', hookArg));
144
- } catch {
145
- // ignore: local/global resolution miss falls back to bundled path
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
+ }
146
165
  }
147
166
 
148
167
  candidates.push(path.join(${JSON.stringify(fallback)}, 'hooks', hookArg));
@@ -167,7 +186,8 @@ await import(pathToFileURL(resolved).href);
167
186
  }
168
187
 
169
188
  /**
170
- * 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.
171
191
  */
172
192
  export function buildClaudeHooksConfig(options = {}) {
173
193
  const root = path.resolve(options.packageRoot || PACKAGE_ROOT);
@@ -177,6 +197,9 @@ export function buildClaudeHooksConfig(options = {}) {
177
197
  const postCmd = options.shimPath
178
198
  ? `node "${normalizeCommandPath(options.shimPath)}" post`
179
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'))}"`;
180
203
  const timeout = Number.isFinite(Number(options.timeout)) ? Number(options.timeout) : 5;
181
204
 
182
205
  return {
@@ -203,66 +226,217 @@ export function buildClaudeHooksConfig(options = {}) {
203
226
  }
204
227
  ]
205
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,
308
+ timeout
309
+ }
310
+ ]
311
+ }
206
312
  ]
207
313
  };
208
314
  }
209
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
+
210
334
  /**
211
- * Installs Burnoff hooks into `<cwd>/.claude/settings.local.json` and adds local state paths
212
- * 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`).
213
337
  */
214
338
  export function initBurnoff(options = {}) {
215
339
  const cwd = path.resolve(options.cwd || process.cwd());
340
+ const homeDir = options.homeDir || getHomeDir();
216
341
  const dryRun = Boolean(options.dryRun);
342
+ const isGlobal = Boolean(options.global);
217
343
  const pkgRoot = path.resolve(options.packageRoot || PACKAGE_ROOT);
218
344
  const ephemeralNpx = isEphemeralNpxPath(pkgRoot);
219
345
  const useShim = Boolean(options.useShim || ephemeralNpx);
220
- const shimPath = useShim ? path.join(cwd, '.claude', 'burnoff-hook-shim.mjs') : null;
346
+ const clients = resolveInitClients(options.client || 'claude', { cwd, homeDir });
347
+ const installClaude = clients.includes('claude');
348
+ const installAntigravity = clients.includes('antigravity');
349
+
221
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
+
222
357
  if (ephemeralNpx) {
223
358
  warnings.push(
224
- 'Ephemeral npx cache path detected; wrote .claude/burnoff-hook-shim.mjs. Install persistently with "npm i -D burnoff" or "npm i -g burnoff".'
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".`
225
360
  );
226
361
  }
227
- const settingsPath = path.join(cwd, '.claude', 'settings.local.json');
228
- const hooks = buildClaudeHooksConfig({
229
- ...options,
230
- packageRoot: pkgRoot,
231
- ...(shimPath ? { shimPath } : {})
232
- });
233
-
234
- const current = readJsonObjectSafe(settingsPath);
235
- const existingHooks =
236
- current.hooks && typeof current.hooks === 'object' && !Array.isArray(current.hooks)
237
- ? { ...current.hooks }
238
- : {};
239
-
240
- const prevPre = filterOutBurnoffMatcherGroups(existingHooks.PreToolUse);
241
- const prevPost = filterOutBurnoffMatcherGroups(existingHooks.PostToolUse);
242
-
243
- const nextSettings = {
244
- ...current,
245
- hooks: {
246
- ...existingHooks,
247
- PreToolUse: [...prevPre, ...hooks.PreToolUse],
248
- PostToolUse: [...prevPost, ...hooks.PostToolUse]
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);
249
401
  }
250
- };
402
+ }
251
403
 
252
- if (!dryRun) {
253
- if (shimPath) {
254
- atomicWriteFileSync(shimPath, buildHookShimSource(pkgRoot), { encoding: 'utf8' });
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
+ });
417
+
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);
255
429
  }
256
- atomicWriteJsonSync(settingsPath, nextSettings);
257
430
  }
258
431
 
259
432
  let excludePath = null;
260
433
  let excludeUpdated = false;
261
- const gitDir = resolveGitDir(cwd);
434
+ const gitDir = !isGlobal || installClaude ? resolveGitDir(cwd) : null;
262
435
  if (gitDir) {
263
436
  excludePath = path.join(gitDir, 'info', 'exclude');
264
437
  const prevExclude = fs.existsSync(excludePath) ? fs.readFileSync(excludePath, 'utf8') : '';
265
- const nextExclude = upsertExcludeBlock(prevExclude);
438
+ const patterns = installClaude ? CLAUDE_EXCLUDE_PATTERNS : ANTIGRAVITY_EXCLUDE_PATTERNS;
439
+ const nextExclude = upsertExcludeBlock(prevExclude, patterns);
266
440
  if (nextExclude !== prevExclude) {
267
441
  excludeUpdated = true;
268
442
  if (!dryRun) {
@@ -275,82 +449,151 @@ export function initBurnoff(options = {}) {
275
449
  ok: true,
276
450
  dryRun,
277
451
  cwd,
452
+ clients,
453
+ global: isGlobal,
278
454
  settingsPath,
279
- shimPath,
455
+ antigravityHooksPath,
456
+ shimPath: shimPath || agShimPath,
280
457
  ephemeralNpx,
281
458
  warnings,
282
459
  excludePath,
283
460
  excludeUpdated,
284
- hooks
461
+ hooks,
462
+ antigravityHooks
285
463
  };
286
464
  }
287
465
 
288
466
  /**
289
- * 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`.
290
468
  */
291
469
  export function uninstallBurnoff(options = {}) {
292
470
  const cwd = path.resolve(options.cwd || process.cwd());
471
+ const homeDir = options.homeDir || getHomeDir();
293
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
+
294
480
  const settingsPath = path.join(cwd, '.claude', 'settings.local.json');
295
481
  let removedSettings = false;
296
482
  let updatedSettings = false;
297
483
 
298
- const shimPath = path.join(cwd, '.claude', 'burnoff-hook-shim.mjs');
299
- let removedShim = false;
300
- if (fs.existsSync(shimPath)) {
301
- removedShim = true;
302
- if (!dryRun) {
484
+ if (uninstallClaude) {
485
+ const shimPath = path.join(cwd, '.claude', 'burnoff-hook-shim.mjs');
486
+ if (fs.existsSync(shimPath) && !dryRun) {
303
487
  try {
304
488
  fs.unlinkSync(shimPath);
305
489
  } catch (err) {
306
490
  void err; // ignore: shim unlink best-effort
307
491
  }
308
492
  }
309
- }
310
493
 
311
- if (fs.existsSync(settingsPath)) {
312
- const current = readJsonObjectSafe(settingsPath);
313
- const nextHooks =
314
- current.hooks && typeof current.hooks === 'object' && !Array.isArray(current.hooks)
315
- ? { ...current.hooks }
316
- : {};
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
+ }
317
526
 
318
- if (nextHooks.PreToolUse) {
319
- const keptPre = filterOutBurnoffMatcherGroups(nextHooks.PreToolUse);
320
- if (keptPre.length > 0) nextHooks.PreToolUse = keptPre;
321
- else delete nextHooks.PreToolUse;
322
- }
323
- if (nextHooks.PostToolUse) {
324
- const keptPost = filterOutBurnoffMatcherGroups(nextHooks.PostToolUse);
325
- if (keptPost.length > 0) nextHooks.PostToolUse = keptPost;
326
- else delete nextHooks.PostToolUse;
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
+ }
327
553
  }
554
+ }
555
+
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;
328
561
 
329
- const nextSettings = { ...current };
330
- if (Object.keys(nextHooks).length > 0) {
331
- nextSettings.hooks = nextHooks;
332
- } else {
333
- delete nextSettings.hooks;
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
+ }
334
570
  }
335
571
 
336
- if (Object.keys(nextSettings).length === 0) {
337
- removedSettings = true;
338
- if (!dryRun) {
339
- fs.unlinkSync(settingsPath);
340
- const claudeDir = path.dirname(settingsPath);
341
- try {
342
- if (fs.existsSync(claudeDir) && fs.readdirSync(claudeDir).length === 0) {
343
- 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);
344
594
  }
345
- } catch (err) {
346
- void err; // ignore: non-empty or locked .claude directory left intact
347
595
  }
348
596
  }
349
- } else {
350
- updatedSettings = true;
351
- if (!dryRun) {
352
- atomicWriteJsonSync(settingsPath, nextSettings);
353
- }
354
597
  }
355
598
  }
356
599
 
@@ -375,9 +618,14 @@ export function uninstallBurnoff(options = {}) {
375
618
  ok: true,
376
619
  dryRun,
377
620
  cwd,
621
+ clients,
622
+ global: isGlobal,
378
623
  settingsPath,
379
624
  removedSettings,
380
625
  updatedSettings,
626
+ antigravityHooksPath,
627
+ removedAntigravityHooks,
628
+ updatedAntigravityHooks,
381
629
  excludePath,
382
630
  excludeUpdated
383
631
  };
@@ -387,7 +635,12 @@ export default {
387
635
  PACKAGE_ROOT,
388
636
  PRE_TOOL_MATCHER,
389
637
  POST_TOOL_MATCHER,
638
+ SESSION_START_MATCHER,
639
+ ANTIGRAVITY_PRE_TOOL_MATCHER,
640
+ ANTIGRAVITY_POST_TOOL_MATCHER,
390
641
  buildClaudeHooksConfig,
642
+ buildAntigravityHooksConfig,
643
+ resolveInitClients,
391
644
  initBurnoff,
392
645
  uninstallBurnoff
393
646
  };