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/bin/burnoff.mjs CHANGED
@@ -10,8 +10,7 @@ import { spawn } from 'node:child_process';
10
10
  import { fileURLToPath } from 'node:url';
11
11
  import {
12
12
  suppressSqliteExperimentalWarning,
13
- ensureSupportedNodeVersion,
14
- getHomeDir
13
+ ensureSupportedNodeVersion
15
14
  } from '../src/config/paths.mjs';
16
15
  import { isCliEntrypoint } from '../hooks/hook-io.mjs';
17
16
  import { atomicWriteFileSync } from '../src/storage/atomic-io.mjs';
@@ -28,7 +27,7 @@ function getPackageVersion() {
28
27
  } catch (err) {
29
28
  void err; // ignore: package.json read fallback
30
29
  }
31
- return '1.1.0';
30
+ return '1.3.0';
32
31
  }
33
32
 
34
33
  const BOOLEAN_FLAGS = new Set([
@@ -39,8 +38,12 @@ const BOOLEAN_FLAGS = new Set([
39
38
  'github-annotations',
40
39
  'markdown',
41
40
  'startup',
41
+ 'ci',
42
+ 'list',
43
+ 'clear',
42
44
  'foreground',
43
45
  'skip-daemon',
46
+ 'global',
44
47
  'help',
45
48
  'version'
46
49
  ]);
@@ -92,17 +95,20 @@ function writeOut(text, outPath, stream = process.stdout) {
92
95
 
93
96
  function formatHelp() {
94
97
  return [
95
- `burnoff v${getPackageVersion()} — Deterministic circuit breakers, bounded file-read guards, and CI spend gates for Claude Code`,
98
+ `burnoff v${getPackageVersion()} — Deterministic circuit breakers, bounded file-read guards, and CI spend gates for Claude Code & Google Antigravity`,
96
99
  '',
97
100
  'Usage:',
98
101
  ' burnoff <command> [options]',
99
102
  '',
100
103
  'Commands:',
101
- ' init [--dry-run] [--cwd <dir>] Install PreToolUse/PostToolUse hooks in .claude/settings.local.json',
102
- ' uninstall [--dry-run] [--cwd <dir>] Remove Burnoff hooks and .git/info/exclude entries',
104
+ ' init [--client claude|antigravity|both|auto] [--global] [--dry-run] [--cwd <dir>] Install Burnoff hooks',
105
+ ' uninstall [--client claude|antigravity|both|auto] [--global] [--dry-run] [--cwd <dir>] Remove Burnoff hooks',
103
106
  ' doctor [--gc] [--json] Run Node/SQLite/hooks/daemon/FTS5/ledger diagnostics',
104
- ' audit [--startup] [--session <file>] [--json] Audit Claude Code JSONL transcripts or Turn-0 startup config',
105
- ' pr-cost [--base main] [--json|--markdown] Attribute branch commits to Claude Code token/USD cost',
107
+ ' audit [--startup [--ci] [--strict] [--github-annotations]] [--client auto|claude|antigravity|both] [--session <file>] [--json] Audit transcripts or Turn-0 config',
108
+ ' allow-once [DET-01..DET-04|*] [--scope <substr>] [--minutes <N>] [--session <id>] [--list|--clear] Temporary ask-gate override',
109
+ ' snooze [DET-01..DET-04|*] [--minutes 15] [--scope <substr>] [--session <id>] [--list|--clear] Timed ask-gate snooze',
110
+ ' pr-cost [--base main] [--client auto|claude|antigravity|both] [--json|--markdown] Attribute branch commits to AI cost',
111
+ ' export [--since <sha>] [--out <file>] Export PR attribution JSON for CI budget gate',
106
112
  ' ci-gate [--strict] [--github-annotations] Enforce .burnoff.yaml ciBudgetGate thresholds',
107
113
  ' team-digest [--days 7] [--json] Generate 5-line Engineering Manager spend & savings digest',
108
114
  ' search <turnId> [keyword] Query archived FTS5 tool outputs',
@@ -119,13 +125,21 @@ async function handleInit(flags, io) {
119
125
  const { initBurnoff } = await import('../src/cli/init.mjs');
120
126
  const res = initBurnoff({
121
127
  cwd: flags.cwd || process.cwd(),
128
+ homeDir: flags.home || undefined,
129
+ client: typeof flags.client === 'string' ? flags.client : 'claude',
130
+ global: Boolean(flags.global),
122
131
  dryRun: Boolean(flags['dry-run'])
123
132
  });
124
133
  if (flags.json) {
125
134
  io.stdout.write(JSON.stringify(res, null, 2) + '\n');
126
135
  } else {
136
+ const targets = [];
137
+ if (res.clients?.includes('claude')) targets.push(res.settingsPath);
138
+ if (res.clients?.includes('antigravity') && res.antigravityHooksPath) {
139
+ targets.push(res.antigravityHooksPath);
140
+ }
127
141
  io.stdout.write(
128
- `Burnoff hooks ${res.dryRun ? '[DRY RUN] ' : ''}installed in ${res.settingsPath}\n` +
142
+ `Burnoff hooks ${res.dryRun ? '[DRY RUN] ' : ''}installed in ${targets.join(' and ')}\n` +
129
143
  (res.excludePath ? ` git exclude: ${res.excludePath}\n` : '') +
130
144
  (Array.isArray(res.warnings) && res.warnings.length > 0
131
145
  ? res.warnings.map((w) => ` warning: ${w}\n`).join('')
@@ -139,13 +153,21 @@ async function handleUninstall(flags, io) {
139
153
  const { uninstallBurnoff } = await import('../src/cli/init.mjs');
140
154
  const res = uninstallBurnoff({
141
155
  cwd: flags.cwd || process.cwd(),
156
+ homeDir: flags.home || undefined,
157
+ client: typeof flags.client === 'string' ? flags.client : undefined,
158
+ global: Boolean(flags.global),
142
159
  dryRun: Boolean(flags['dry-run'])
143
160
  });
144
161
  if (flags.json) {
145
162
  io.stdout.write(JSON.stringify(res, null, 2) + '\n');
146
163
  } else {
164
+ const targets = [];
165
+ if (res.clients?.includes('claude')) targets.push(res.settingsPath);
166
+ if (res.clients?.includes('antigravity') && res.antigravityHooksPath) {
167
+ targets.push(res.antigravityHooksPath);
168
+ }
147
169
  io.stdout.write(
148
- `Burnoff hooks ${res.dryRun ? '[DRY RUN] ' : ''}removed from ${res.settingsPath}\n`
170
+ `Burnoff hooks ${res.dryRun ? '[DRY RUN] ' : ''}removed from ${targets.join(' and ')}\n`
149
171
  );
150
172
  }
151
173
  return 0;
@@ -155,7 +177,7 @@ async function handleDoctor(flags, io) {
155
177
  const { runDoctor, formatDoctorReport } = await import('../src/cli/doctor.mjs');
156
178
  const report = await runDoctor({
157
179
  cwd: flags.cwd || process.cwd(),
158
- homeDir: flags.home || getHomeDir(),
180
+ homeDir: flags.home || undefined,
159
181
  gc: Boolean(flags.gc),
160
182
  skipDaemonCheck: Boolean(flags['skip-daemon'])
161
183
  });
@@ -165,21 +187,47 @@ async function handleDoctor(flags, io) {
165
187
  }
166
188
 
167
189
  async function handleAudit(flags, io) {
190
+ const clientOpt = typeof flags.client === 'string' ? flags.client : 'auto';
168
191
  if (flags.startup) {
169
- const { runClaudeStartupAudit, formatClaudeStartupAuditReport } = await import('../src/cli/startup-audit.mjs');
170
- const report = runClaudeStartupAudit({
171
- cwd: flags.cwd || process.cwd(),
172
- homeDir: flags.home || getHomeDir(),
173
- days: flags.days ? Number(flags.days) : 7
192
+ const { runStartupAudit, formatStartupAuditReport, evaluateStartupAuditCi } = await import(
193
+ '../src/cli/startup-audit.mjs'
194
+ );
195
+ const cwd = flags.cwd || process.cwd();
196
+ const isCi = Boolean(flags.ci);
197
+ const report = runStartupAudit({
198
+ cwd,
199
+ homeDir: flags.home || undefined,
200
+ days: flags.days ? Number(flags.days) : 7,
201
+ client: clientOpt,
202
+ ci: isCi,
203
+ repoOnly: isCi
174
204
  });
175
- const text = flags.json ? JSON.stringify(report, null, 2) + '\n' : formatClaudeStartupAuditReport(report);
205
+ if (isCi) {
206
+ const ciResult = evaluateStartupAuditCi(report, {
207
+ strict: Boolean(flags.strict),
208
+ cwd
209
+ });
210
+ report.ci = ciResult;
211
+ if (flags['github-annotations'] && Array.isArray(ciResult.annotations)) {
212
+ for (const line of ciResult.annotations) {
213
+ io.stdout.write(`${line}\n`);
214
+ }
215
+ }
216
+ const text = flags.json
217
+ ? JSON.stringify(report, null, 2) + '\n'
218
+ : `${formatStartupAuditReport(report)}CI Verdict: ${ciResult.verdict} (errors=${ciResult.errorCount}, warnings=${ciResult.warnCount}, strict=${ciResult.strict})\n`;
219
+ writeOut(text, flags.out, io.stdout);
220
+ return ciResult.exitCode;
221
+ }
222
+ const text = flags.json ? JSON.stringify(report, null, 2) + '\n' : formatStartupAuditReport(report);
176
223
  writeOut(text, flags.out, io.stdout);
177
224
  return 0;
178
225
  }
179
226
  const { auditClaudeSessions, formatAuditReport } = await import('../src/cli/audit.mjs');
180
227
  const report = auditClaudeSessions({
181
228
  cwd: flags.cwd || process.cwd(),
182
- homeDir: flags.home || getHomeDir(),
229
+ homeDir: flags.home || undefined,
230
+ client: clientOpt,
183
231
  sessionPath: typeof flags.session === 'string' ? flags.session : undefined,
184
232
  limit: flags.limit ? Number(flags.limit) : undefined
185
233
  });
@@ -192,7 +240,8 @@ async function handlePrCost(flags, io) {
192
240
  const { buildPrCostAttribution, formatPrAttributionMarkdown } = await import('../src/ci/pr-cost.mjs');
193
241
  const report = buildPrCostAttribution({
194
242
  cwd: flags.cwd || process.cwd(),
195
- homeDir: flags.home || getHomeDir(),
243
+ homeDir: flags.home || undefined,
244
+ client: typeof flags.client === 'string' ? flags.client : 'auto',
196
245
  base: typeof flags.base === 'string' ? flags.base : 'main',
197
246
  head: typeof flags.head === 'string' ? flags.head : 'HEAD',
198
247
  providerUsagePath: typeof flags['provider-usage'] === 'string' ? flags['provider-usage'] : undefined
@@ -208,11 +257,30 @@ async function handlePrCost(flags, io) {
208
257
  return 0;
209
258
  }
210
259
 
260
+ async function handleExport(flags, io) {
261
+ const { buildPrCostAttribution } = await import('../src/ci/pr-cost.mjs');
262
+ const report = buildPrCostAttribution({
263
+ cwd: flags.cwd || process.cwd(),
264
+ homeDir: flags.home || undefined,
265
+ client: typeof flags.client === 'string' ? flags.client : 'auto',
266
+ base: typeof flags.since === 'string' ? flags.since : typeof flags.base === 'string' ? flags.base : 'main',
267
+ head: typeof flags.head === 'string' ? flags.head : 'HEAD',
268
+ providerUsagePath: typeof flags['provider-usage'] === 'string' ? flags['provider-usage'] : undefined
269
+ });
270
+ if (!report.ok) {
271
+ io.stderr.write(`Burnoff export error: ${report.error || 'failed'}\n`);
272
+ return 1;
273
+ }
274
+ const text = JSON.stringify(report, null, 2) + '\n';
275
+ writeOut(text, flags.out, io.stdout);
276
+ return 0;
277
+ }
278
+
211
279
  async function handleCiGate(flags, io) {
212
280
  const { evaluateCiBudgetGate, formatCiGateMarkdown } = await import('../src/ci/ci-gate.mjs');
213
281
  const result = evaluateCiBudgetGate({
214
282
  cwd: flags.cwd || process.cwd(),
215
- homeDir: flags.home || getHomeDir(),
283
+ homeDir: flags.home || undefined,
216
284
  base: typeof flags.base === 'string' ? flags.base : 'main',
217
285
  head: typeof flags.head === 'string' ? flags.head : 'HEAD',
218
286
  inputPath: typeof flags.input === 'string' ? flags.input : undefined,
@@ -239,7 +307,7 @@ async function handleTeamDigest(flags, io) {
239
307
  const { buildTeamDigest, formatTeamDigest } = await import('../src/ci/team-digest.mjs');
240
308
  const { buildPrCostAttribution } = await import('../src/ci/pr-cost.mjs');
241
309
  const cwd = flags.cwd || process.cwd();
242
- const homeDir = flags.home || getHomeDir();
310
+ const homeDir = flags.home || undefined;
243
311
  const prReports = [];
244
312
  try {
245
313
  const prReport = buildPrCostAttribution({
@@ -282,7 +350,7 @@ async function handleSearch(positionals, flags, io) {
282
350
  turnId,
283
351
  keyword,
284
352
  limit: flags.limit ? Number(flags.limit) : 10,
285
- homeDir: flags.home || getHomeDir()
353
+ homeDir: flags.home || undefined
286
354
  };
287
355
  let res;
288
356
  if (typeof flags.db === 'string' && flags.db) {
@@ -316,7 +384,7 @@ async function handleSearch(positionals, flags, io) {
316
384
  async function handleDaemon(positionals, flags, io) {
317
385
  const sub = String(positionals[1] || 'status').toLowerCase();
318
386
  const cwd = path.resolve(flags.cwd || process.cwd());
319
- const homeDir = flags.home || getHomeDir();
387
+ const homeDir = typeof flags.home === 'string' && flags.home.trim() ? flags.home.trim() : undefined;
320
388
  const { sendDaemonRpc, resolveFastIpcPipePath } = await import('../src/ipc/fast-client.mjs');
321
389
  const ipcPath = resolveFastIpcPipePath({ cwd, homeDir, ipcPath: flags.ipc });
322
390
 
@@ -368,9 +436,11 @@ async function handleDaemon(positionals, flags, io) {
368
436
  }
369
437
 
370
438
  const cliEntry = path.join(PACKAGE_ROOT, 'bin', 'burnoff.mjs');
439
+ const spawnArgs = [cliEntry, 'daemon', 'start', '--foreground', '--cwd', cwd, '--ipc', ipcPath];
440
+ if (homeDir) spawnArgs.push('--home', homeDir);
371
441
  const child = spawn(
372
442
  process.execPath,
373
- [cliEntry, 'daemon', 'start', '--foreground', '--cwd', cwd, '--home', homeDir, '--ipc', ipcPath],
443
+ spawnArgs,
374
444
  {
375
445
  cwd,
376
446
  detached: true,
@@ -395,6 +465,92 @@ async function handleDaemon(positionals, flags, io) {
395
465
  return 1;
396
466
  }
397
467
 
468
+ async function handleAllowOnce(cmd, positionals, flags, io) {
469
+ const {
470
+ normalizeSnoozeDetectorId,
471
+ grantAskSnoozeAtomicSync,
472
+ listActiveSnoozes,
473
+ clearAskSnoozesAtomicSync,
474
+ DEFAULT_ALLOW_ONCE_TTL_MS,
475
+ DEFAULT_SNOOZE_TTL_MS
476
+ } = await import('../src/guards/snooze.mjs');
477
+
478
+ const cwd = path.resolve(flags.cwd || process.cwd());
479
+ const homeDir = flags.home || undefined;
480
+ const sessionId = typeof flags.session === 'string' && flags.session.trim() ? flags.session.trim() : null;
481
+ const rawClient = typeof flags.client === 'string' ? flags.client.trim().toLowerCase() : 'claude';
482
+ const client = rawClient === 'antigravity' || rawClient === 'ag' ? 'antigravity' : 'claude-code';
483
+ const storeOpts = { cwd, homeDir, client };
484
+
485
+ const rawDetArg = positionals[1];
486
+ const detectorId = normalizeSnoozeDetectorId(rawDetArg === undefined ? '*' : rawDetArg);
487
+ if (!detectorId) {
488
+ io.stderr.write(`Invalid detector ID "${rawDetArg}". Expected DET-01..DET-04, all, or *.\n`);
489
+ return 1;
490
+ }
491
+
492
+ if (flags.list) {
493
+ const entries = listActiveSnoozes({ sessionId }, storeOpts);
494
+ if (flags.json) {
495
+ io.stdout.write(JSON.stringify({ ok: true, count: entries.length, snoozes: entries }, null, 2) + '\n');
496
+ } else if (entries.length === 0) {
497
+ io.stdout.write('No active Burnoff ask-gate snoozes.\n');
498
+ } else {
499
+ for (const e of entries) {
500
+ const remLabel = e.remaining === null ? 'timed' : `uses=${e.remaining}`;
501
+ io.stdout.write(
502
+ `[${e.source}] id=${e.id} detector=${e.detectorId} scope=${e.scope} ${remLabel} expires=${new Date(e.expiresAtMs).toISOString()}\n`
503
+ );
504
+ }
505
+ }
506
+ return 0;
507
+ }
508
+
509
+ if (flags.clear) {
510
+ const res = clearAskSnoozesAtomicSync(
511
+ { sessionId, detectorId: rawDetArg !== undefined ? detectorId : null },
512
+ storeOpts
513
+ );
514
+ if (flags.json) {
515
+ io.stdout.write(JSON.stringify(res, null, 2) + '\n');
516
+ } else {
517
+ io.stdout.write(`Cleared ${res.clearedCount} active Burnoff ask-gate snooze(s).\n`);
518
+ }
519
+ return 0;
520
+ }
521
+
522
+ const defaultTtlMin = cmd === 'snooze' ? DEFAULT_SNOOZE_TTL_MS / 60000 : DEFAULT_ALLOW_ONCE_TTL_MS / 60000;
523
+ const parsedMinutes = flags.minutes !== undefined ? Number(flags.minutes) : defaultTtlMin;
524
+ const ttlMs =
525
+ Number.isFinite(parsedMinutes) && parsedMinutes > 0
526
+ ? Math.round(parsedMinutes * 60 * 1000)
527
+ : cmd === 'snooze'
528
+ ? DEFAULT_SNOOZE_TTL_MS
529
+ : DEFAULT_ALLOW_ONCE_TTL_MS;
530
+ const count =
531
+ flags.count !== undefined
532
+ ? Math.max(1, Math.floor(Number(flags.count) || 1))
533
+ : cmd === 'snooze'
534
+ ? null
535
+ : 1;
536
+ const scope = typeof flags.scope === 'string' && flags.scope.trim() ? flags.scope.trim() : '*';
537
+ const reason = typeof flags.reason === 'string' ? flags.reason : '';
538
+
539
+ const res = grantAskSnoozeAtomicSync(
540
+ { sessionId, detectorId, scope, count, ttlMs, reason },
541
+ storeOpts
542
+ );
543
+ if (flags.json) {
544
+ io.stdout.write(JSON.stringify(res, null, 2) + '\n');
545
+ } else {
546
+ const modeLabel = res.grant.remaining === null ? 'timed snooze' : `allow-once (uses=${res.grant.remaining})`;
547
+ io.stdout.write(
548
+ `Granted ${modeLabel} for ${res.grant.detectorId} (scope=${res.grant.scope}, target=${res.target}, expires=${new Date(res.grant.expiresAtMs).toISOString()})\n`
549
+ );
550
+ }
551
+ return 0;
552
+ }
553
+
398
554
  /**
399
555
  * Dispatches Burnoff CLI commands and returns an exit code.
400
556
  */
@@ -429,8 +585,13 @@ export async function runCli(argv = process.argv.slice(2), io = { stdout: proces
429
585
  return handleDoctor(flags, io);
430
586
  case 'audit':
431
587
  return handleAudit(flags, io);
588
+ case 'allow-once':
589
+ case 'snooze':
590
+ return handleAllowOnce(cmd, positionals, flags, io);
432
591
  case 'pr-cost':
433
592
  return handlePrCost(flags, io);
593
+ case 'export':
594
+ return handleExport(flags, io);
434
595
  case 'ci-gate':
435
596
  return handleCiGate(flags, io);
436
597
  case 'team-digest':
@@ -0,0 +1,16 @@
1
+ ---
2
+ description: Run Burnoff diagnostics, Turn-0 startup audits, ask-gate overrides, or PR spend digests
3
+ argument-hint: "[doctor|audit|startup|allow-once <DET-xx>|snooze <DET-xx>|pr-cost|team-digest|init]"
4
+ ---
5
+
6
+ Run Burnoff (`npx -y burnoff@1.3.0` or local `node bin/burnoff.mjs` when developing in the Burnoff repo) according to `$ARGUMENTS`:
7
+
8
+ - Empty arguments: run `burnoff doctor` and `burnoff team-digest --days 7` and summarize findings clearly.
9
+ - `doctor`: run `burnoff doctor` to verify Node/SQLite FTS5, hooks, and warm daemon health.
10
+ - `startup` or `audit --startup`: run `burnoff audit --startup --ci` for repo-local Turn-0 rule, secret, and MCP linting (or drop `--ci` to include local machine config).
11
+ - `audit`: run `burnoff audit --limit 10` across recent local transcripts.
12
+ - `allow-once ...` or `snooze ...`: run `burnoff $ARGUMENTS` to grant/list/clear temporary overrides for interactive `ask` gates (`DET-01`..`DET-04`; never bypasses `deny` hard blocks).
13
+ - `pr-cost` or `team-digest`: run `burnoff $ARGUMENTS` to inspect AI branch cost attribution or 7-day savings telemetry.
14
+ - `init`: run `burnoff init --client claude` to install/refresh `.claude/settings.local.json` hooks deterministically.
15
+
16
+ Keep the response concise and show exact command output numbers without guessing or extrapolating.
@@ -0,0 +1,67 @@
1
+ # Burnoff Claude Code Plugin & Status Line
2
+
3
+ Burnoff ships a lightweight Claude Code plugin manifest (`.claude-plugin/plugin.json`), the `/burnoff` slash command (`commands/burnoff.md`), and a zero-dependency status-line snippet (`scripts/burnoff-statusline.mjs`).
4
+
5
+ ## 1. Install Deterministic Hooks
6
+
7
+ Run the CLI installer in your repository (or pass `--global` for user-wide defaults):
8
+
9
+ ```bash
10
+ npx -y burnoff@1.3.0 init --client claude
11
+ ```
12
+
13
+ Why hooks are installed via `burnoff init` instead of a static hook file:
14
+
15
+ - `burnoff init` resolves node paths cleanly across Windows, macOS, and Linux and configures `PreToolUse`, `PostToolUse`, `PostToolUseFailure`, `SessionStart`, and `PreCompact`.
16
+ - Verify installation anytime with:
17
+
18
+ ```bash
19
+ npx -y burnoff@1.3.0 doctor
20
+ ```
21
+
22
+ ## 2. Enable `/burnoff` Slash Command
23
+
24
+ Load the plugin directory when testing locally:
25
+
26
+ ```bash
27
+ claude --plugin-dir /path/to/burnoff
28
+ ```
29
+
30
+ Or copy `commands/burnoff.md` into your project's `.claude/commands/` folder so team members get `/burnoff` automatically:
31
+
32
+ - `/burnoff` — run `doctor` + `team-digest --days 7`
33
+ - `/burnoff startup` — run Turn-0 repo-local linter (`audit --startup --ci`)
34
+ - `/burnoff allow-once DET-03 --scope deploy.yml` — grant a single-use `ask` override
35
+ - `/burnoff pr-cost` — inspect branch spend attribution
36
+
37
+ ## 3. Add Status-Line Telemetry Snippet
38
+
39
+ Add a `"statusLine"` entry to `.claude/settings.local.json` or `~/.claude/settings.json`:
40
+
41
+ ```json
42
+ {
43
+ "statusLine": {
44
+ "type": "command",
45
+ "command": "node /abs/path/to/burnoff/scripts/burnoff-statusline.mjs"
46
+ }
47
+ }
48
+ ```
49
+
50
+ Example terminal output (`<50 ms`, zero network calls, fail-silent):
51
+
52
+ ```text
53
+ burnoff | saved: 14.2k tok ($0.04) | guards: 2 | ctx: 38%
54
+ ```
55
+
56
+ ## 4. Temporary Overrides for `ask` Prompts
57
+
58
+ When interactive `ask` gates pause an intentional edit or command (`DET-01`, `DET-02`, `DET-03`, or `DET-04`), grant a scoped single-use or timed snooze from your terminal:
59
+
60
+ ```bash
61
+ npx -y burnoff@1.3.0 allow-once DET-03 --scope deploy.yml
62
+ npx -y burnoff@1.3.0 snooze DET-04 --minutes 15
63
+ npx -y burnoff@1.3.0 allow-once --list
64
+ npx -y burnoff@1.3.0 allow-once --clear
65
+ ```
66
+
67
+ Security invariant: `allow-once` and `snooze` apply **only** to `ask` decisions. Ring-0 `deny` / `exitCode: 2` hard blocks (`git push --force`, `.env`/credential reads, strict-mode blocks) are never bypassed.
@@ -0,0 +1,44 @@
1
+ # Burnoff Private Design-Partner Intake
2
+
3
+ Burnoff (`MIT`, zero runtime dependencies, 100% local execution) is onboarding a small cohort of engineering teams using Claude Code and/or Google Antigravity to validate Turn-0 CI config linting, bounded file-read savings, and PR cost gates on real repositories.
4
+
5
+ - **Cost & Terms:** Free open-source MIT CLI during design partnership — no public SaaS tier, no seat license keys, and zero external telemetry uploads without explicit export.
6
+ - **How to Submit:** Open a private discussion/issue on `https://github.com/Gizzant/burnoff/issues` marked `[Design Partner]` (sanitized — do **not** paste secrets or `.env` values), or email maintainers with the template below.
7
+
8
+ ---
9
+
10
+ ## Intake Questionnaire
11
+
12
+ ### 1. Team & Repository Profile
13
+ - **Organization / Team Name:**
14
+ - **GitHub Org / Repo Count:**
15
+ - **Primary Languages & Monorepo Layout:**
16
+ - **Active Coding Harnesses (check all):**
17
+ - [ ] Claude Code CLI / IDE
18
+ - [ ] Google Antigravity CLI / IDE
19
+ - [ ] GitHub Actions PR Workflows
20
+
21
+ ### 2. Current Failure Modes & Spend Hotspots (rank top 3)
22
+ - [ ] Oversized file reads blowing context (`Read` / `read_file`)
23
+ - [ ] Retry loops burning turns (`DET-04` repeated test/build failures)
24
+ - [ ] Turn-0 startup token tax (`CLAUDE.md` / `GEMINI.md` / eager MCP schemas / `BO-CFG-*`)
25
+ - [ ] Subagent fan-out or prompt bloat (`DET-05` / `BO-MCP-09`)
26
+ - [ ] PR cost visibility & CI budget enforcement (`pr-cost` / `ci-gate`)
27
+ - [ ] Destructive command / credential boundary incidents (`DET-01` / `DET-02`)
28
+
29
+ ### 3. Baseline Snapshot (optional, local-only commands)
30
+ Run inside a representative repo and paste sanitized summary lines only:
31
+
32
+ ```bash
33
+ npx -y burnoff@1.3.0 doctor
34
+ npx -y burnoff@1.3.0 audit --startup --ci
35
+ npx -y burnoff@1.3.0 team-digest --days 7
36
+ ```
37
+
38
+ ### 4. Security & Privacy Requirements
39
+ - **Strict air-gap / offline CI runner?** (Yes / No)
40
+ - **Strict JSON-only config requirement?** (`BO-CFG-01`) (Yes / No)
41
+ - **Custom `.burnoff.yaml` thresholds needed?**
42
+
43
+ ### 5. Success Criteria (30-Day Pilot)
44
+ What measurable outcome would make Burnoff a permanent default in your repos? (e.g., Turn-0 prefix tokens reduced, CI catches unignored secrets in `.claude/settings.local.json`, or zero runaway retry loops.)
package/hooks/hook-io.mjs CHANGED
@@ -7,6 +7,7 @@
7
7
  import fs from 'node:fs';
8
8
  import path from 'node:path';
9
9
  import { fileURLToPath } from 'node:url';
10
+ import { getWorkspaceStateDir } from '../src/config/paths.mjs';
10
11
 
11
12
  const BOUNDED_READ_TOOL_RE = /^(?:Read|read_file|view_file)$/i;
12
13
  const SENSITIVE_SEGMENT_RE =
@@ -379,7 +380,7 @@ export function recordHookTrace(eventName, payload = {}, details = {}) {
379
380
  * Returns `false` whenever any active guard, lock, breaker failure state, policy file,
380
381
  * or read-interval overlap could require full evaluation.
381
382
  */
382
- export function canFastAllowBoundedRead(payload = {}, { cwd = '' } = {}) {
383
+ export function canFastAllowBoundedRead(payload = {}, { cwd = '', homeDir = null } = {}) {
383
384
  if (!payload || typeof payload !== 'object') return false;
384
385
  if (payload.shieldForceActive || payload.shieldConfig || payload.consecutiveFailures) {
385
386
  return false;
@@ -442,19 +443,30 @@ export function canFastAllowBoundedRead(payload = {}, { cwd = '' } = {}) {
442
443
  ) {
443
444
  return false;
444
445
  }
445
- if (fs.existsSync(path.join(baseCwd, '.claude', 'locks', 'active_scopes.json'))) {
446
+
447
+ const wsStateDir = getWorkspaceStateDir(baseCwd, homeDir);
448
+ if (
449
+ fs.existsSync(path.join(baseCwd, '.claude', 'locks', 'active_scopes.json')) ||
450
+ fs.existsSync(path.join(wsStateDir, 'active_scopes.json'))
451
+ ) {
446
452
  return false;
447
453
  }
448
454
 
449
- const sessionId = String(payload.session_id || payload.sessionId || 'default');
455
+ const sessionId = String(payload.session_id || payload.sessionId || payload.conversationId || 'default');
450
456
  const safeSid = sessionId.replace(/[^a-zA-Z0-9._-]/g, '_').slice(0, 80) || 'default';
451
- const breakerPath = path.join(baseCwd, '.claude', 'cache', `burnoff_breaker_state_${safeSid}.json`);
452
- if (fs.existsSync(breakerPath)) {
457
+ if (
458
+ fs.existsSync(path.join(baseCwd, '.claude', 'cache', `burnoff_breaker_state_${safeSid}.json`)) ||
459
+ fs.existsSync(path.join(wsStateDir, `burnoff_breaker_state_${safeSid}.json`))
460
+ ) {
453
461
  return false;
454
462
  }
455
463
 
456
- const snapPath = path.join(baseCwd, '.claude', 'cache', `read_snapshots_${safeSid.slice(0, 64)}.json`);
457
- if (fs.existsSync(snapPath)) {
464
+ const snapCandidates = [
465
+ path.join(baseCwd, '.claude', 'cache', `read_snapshots_${safeSid.slice(0, 64)}.json`),
466
+ path.join(wsStateDir, `read_snapshots_${safeSid.slice(0, 64)}.json`)
467
+ ];
468
+ for (const snapPath of snapCandidates) {
469
+ if (!fs.existsSync(snapPath)) continue;
458
470
  try {
459
471
  const snap = JSON.parse(fs.readFileSync(snapPath, 'utf8'));
460
472
  const absTarget = path.isAbsolute(rawPath) ? path.resolve(rawPath) : path.resolve(baseCwd, rawPath);
@@ -15,6 +15,7 @@ import {
15
15
  tryTier1PostToolFastPath
16
16
  } from './hook-io.mjs';
17
17
  import { tryFastDaemonRpc } from '../src/ipc/fast-client.mjs';
18
+ import { getClientAdapter, normalizeHookEvent } from '../src/clients/detect.mjs';
18
19
 
19
20
  let _engineMod = null;
20
21
  if (!isCliEntrypoint(import.meta.url)) {
@@ -39,60 +40,56 @@ export function runPostToolUseHook(event = {}, options = {}) {
39
40
  return _engineMod.runPostToolUseHook(event, options);
40
41
  }
41
42
 
43
+ function emitPostToolResult(res, payload, traceBase, pathLabel, ioOverride) {
44
+ if (res.stdout) {
45
+ recordHookTrace('PostToolUse', payload, { ...traceBase, outcome: 'stdout_json', path: pathLabel, exitCode: 0 });
46
+ exitWithStdoutJson(res.stdout, ioOverride);
47
+ } else {
48
+ recordHookTrace('PostToolUse', payload, { ...traceBase, outcome: 'pass_through', path: pathLabel, exitCode: 0 });
49
+ exitPassThrough(ioOverride.exitFn);
50
+ }
51
+ }
52
+
42
53
  export async function executePostToolUseCli(cliOptions = {}) {
43
54
  const readPayload = cliOptions.readPayload || readStdinJsonAsync;
44
55
  const ioOverride = cliOptions.ioOverride || {};
45
56
  let payload = {};
57
+ let detectedClient = 'claude-code';
46
58
  try {
47
59
  payload = await readPayload(cliOptions.timeoutMs);
60
+ const { client, adapter, canonical } = normalizeHookEvent(payload, cliOptions.hookOptions);
61
+ detectedClient = client;
48
62
  const hasCustomOptions = Boolean(cliOptions.runHook || cliOptions.hookOptions);
49
63
  const traceBase = { tracePath: cliOptions.tracePath };
50
64
 
51
65
  if (cliOptions.runHook) {
52
66
  const res = cliOptions.runHook(payload, { persistState: true, ...(cliOptions.hookOptions || {}) });
53
- if (res.stdout) {
54
- recordHookTrace('PostToolUse', payload, { ...traceBase, outcome: 'stdout_json', path: 'custom', exitCode: 0 });
55
- exitWithStdoutJson(res.stdout, ioOverride);
56
- } else {
57
- recordHookTrace('PostToolUse', payload, { ...traceBase, outcome: 'pass_through', path: 'custom', exitCode: 0 });
58
- exitPassThrough(ioOverride.exitFn);
59
- }
67
+ emitPostToolResult(res, payload, traceBase, 'custom', ioOverride);
60
68
  return;
61
69
  }
62
70
 
63
71
  if (!hasCustomOptions) {
64
- if (tryTier1PostToolFastPath(payload)) {
65
- recordHookTrace('PostToolUse', payload, { ...traceBase, outcome: 'pass_through', path: 'tier1_fast', exitCode: 0 });
66
- exitPassThrough(ioOverride.exitFn);
72
+ const tier1 = tryTier1PostToolFastPath(canonical);
73
+ if (tier1) {
74
+ const rendered = client === 'antigravity' ? adapter.renderPost(tier1) : tier1;
75
+ emitPostToolResult(rendered, payload, traceBase, 'tier1_fast', ioOverride);
67
76
  return;
68
77
  }
69
78
 
70
79
  const ipcRes = await tryFastDaemonRpc(
71
- 'hook.claude.postToolUse',
72
- { event: payload },
80
+ 'hook.postToolUse',
81
+ { client, event: payload },
73
82
  { ipcPath: cliOptions.ipcPath }
74
83
  );
75
84
  if (ipcRes && ipcRes.fullVerdict === true) {
76
- if (ipcRes.stdout) {
77
- recordHookTrace('PostToolUse', payload, { ...traceBase, outcome: 'stdout_json', path: 'daemon_ipc', exitCode: 0 });
78
- exitWithStdoutJson(ipcRes.stdout, ioOverride);
79
- } else {
80
- recordHookTrace('PostToolUse', payload, { ...traceBase, outcome: 'pass_through', path: 'daemon_ipc', exitCode: 0 });
81
- exitPassThrough(ioOverride.exitFn);
82
- }
85
+ emitPostToolResult(ipcRes, payload, traceBase, 'daemon_ipc', ioOverride);
83
86
  return;
84
87
  }
85
88
  }
86
89
 
87
90
  const { runPostToolUseHook: runCore } = await import('../src/guards/post-tool-engine.mjs');
88
91
  const res = runCore(payload, { persistState: true, ...(cliOptions.hookOptions || {}) });
89
- if (res.stdout) {
90
- recordHookTrace('PostToolUse', payload, { ...traceBase, outcome: 'stdout_json', path: 'core', exitCode: 0 });
91
- exitWithStdoutJson(res.stdout, ioOverride);
92
- } else {
93
- recordHookTrace('PostToolUse', payload, { ...traceBase, outcome: 'pass_through', path: 'core', exitCode: 0 });
94
- exitPassThrough(ioOverride.exitFn);
95
- }
92
+ emitPostToolResult(res, payload, traceBase, 'core', ioOverride);
96
93
  } catch (err) {
97
94
  recordHookTrace('PostToolUse', payload, {
98
95
  tracePath: cliOptions.tracePath,
@@ -101,6 +98,16 @@ export async function executePostToolUseCli(cliOptions = {}) {
101
98
  exitCode: 0,
102
99
  error: err?.message || String(err)
103
100
  });
101
+ if (detectedClient === 'antigravity') {
102
+ const failRes = getClientAdapter(detectedClient).renderFailOpen(err?.message || String(err), 'PostToolUse');
103
+ const writeStderr =
104
+ ioOverride.stderrWrite ||
105
+ ioOverride.writeStderr ||
106
+ ((s) => globalThis.process?.stderr?.write?.(s));
107
+ writeStderr(failRes.stderr);
108
+ exitWithStdoutJson(failRes.stdout, ioOverride);
109
+ return;
110
+ }
104
111
  exitDiagnosticZero(err?.message || String(err), 'PostToolUse', ioOverride);
105
112
  }
106
113
  }