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
@@ -1,6 +1,8 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import { suppressSqliteExperimentalWarning } from '../config/paths.mjs';
4
+ import { atomicWriteFileSync } from './atomic-io.mjs';
5
+ import { withFileLockSync } from './file-lock.mjs';
4
6
 
5
7
  const BURNOFF_OWNED_DB_DIR_RE = /(?:^|[\\/])(?:\.burnoff|\.claude)(?:[\\/]|$)/i;
6
8
 
@@ -300,6 +302,21 @@ export function enforceOwnerOnlyDbPermissions(filePath = '') {
300
302
  }
301
303
  }
302
304
 
305
+ export function resolveFallbackDbPath(dbPath = '') {
306
+ if (!dbPath || dbPath === ':memory:' || String(dbPath).startsWith('file:')) {
307
+ return dbPath;
308
+ }
309
+ const resolved = path.resolve(dbPath);
310
+ const base = path.basename(resolved);
311
+ if (base.toLowerCase() === 'tool_logs_fts5.db') {
312
+ return path.join(path.dirname(resolved), 'tool_logs_fallback.json');
313
+ }
314
+ if (/\.(?:db|sqlite3?)$/i.test(base)) {
315
+ return path.join(path.dirname(resolved), base.replace(/\.(?:db|sqlite3?)$/i, '_fallback.json'));
316
+ }
317
+ return resolved;
318
+ }
319
+
303
320
  /**
304
321
  * Pure-JS JSON fallback database adapter for Node 20 LTS runtimes (where built-in `node:sqlite`
305
322
  * is absent) or when `BURNOFF_FORCE_NO_SQLITE=1` is set.
@@ -309,14 +326,19 @@ export class JsonlFallbackDatabaseSync {
309
326
  this.dbPath = dbPath;
310
327
  this.readOnly = Boolean(options.readOnly || options.readonly);
311
328
  this.isMemory = !dbPath || dbPath === ':memory:' || String(dbPath).startsWith('file:');
329
+ this.storagePath = this.isMemory ? dbPath : resolveFallbackDbPath(dbPath);
312
330
  this.tables = {};
313
331
  this._load();
314
332
  }
315
333
 
316
334
  _load() {
317
- if (this.isMemory || !fs.existsSync(this.dbPath)) return;
335
+ if (this.isMemory) return;
336
+ const candidatePath = fs.existsSync(this.storagePath)
337
+ ? this.storagePath
338
+ : (this.dbPath !== this.storagePath && fs.existsSync(this.dbPath) ? this.dbPath : null);
339
+ if (!candidatePath) return;
318
340
  try {
319
- const raw = fs.readFileSync(this.dbPath, 'utf8').trim();
341
+ const raw = fs.readFileSync(candidatePath, 'utf8').trim();
320
342
  if (raw.startsWith('{')) {
321
343
  const parsed = JSON.parse(raw);
322
344
  if (parsed && typeof parsed.tables === 'object') {
@@ -331,13 +353,12 @@ export class JsonlFallbackDatabaseSync {
331
353
  _flush() {
332
354
  if (this.isMemory || this.readOnly) return;
333
355
  try {
334
- fs.mkdirSync(path.dirname(this.dbPath), { recursive: true, mode: 0o700 });
335
- fs.writeFileSync(
336
- this.dbPath,
337
- JSON.stringify({ fallbackFormat: 'json-v1', tables: this.tables }),
338
- { encoding: 'utf8', mode: 0o600 }
339
- );
340
- enforceOwnerOnlyDbPermissions(this.dbPath);
356
+ fs.mkdirSync(path.dirname(this.storagePath), { recursive: true, mode: 0o700 });
357
+ const payload = JSON.stringify({ fallbackFormat: 'json-v1', tables: this.tables });
358
+ withFileLockSync(this.storagePath, () => {
359
+ atomicWriteFileSync(this.storagePath, payload, { encoding: 'utf8', mode: 0o600 });
360
+ enforceOwnerOnlyDbPermissions(this.storagePath);
361
+ });
341
362
  } catch {
342
363
  // ignore: best-effort persistence in fallback mode
343
364
  }
@@ -465,12 +486,14 @@ export class JsonlFallbackDatabaseSync {
465
486
  }
466
487
  }
467
488
 
468
- if (/SELECT\s+count\(\*\)\s+as\s+count/i.test(normSql)) {
489
+ const countMatch = normSql.match(/^SELECT\s+count\(\*\)(?:\s+as\s+([A-Za-z0-9_]+))?/i);
490
+ if (countMatch) {
491
+ const alias = countMatch[1] || 'count';
469
492
  const totalBytes = filtered.reduce(
470
493
  (sum, r) => sum + Buffer.byteLength(String(r.raw_output || r.rawOutput || ''), 'utf8'),
471
494
  0
472
495
  );
473
- return [{ count: filtered.length, totalBytes }];
496
+ return [{ count: filtered.length, [alias]: filtered.length, totalBytes }];
474
497
  }
475
498
 
476
499
  if (/\bLIMIT\s+\?/i.test(normSql) && argIdx < args.length) {
@@ -559,6 +582,7 @@ export function openBurnoffDb(dbPath, { readOnly = false, readonly = false, busy
559
582
  export default {
560
583
  probeSqliteBuiltin,
561
584
  getDatabaseSyncClass,
585
+ resolveFallbackDbPath,
562
586
  JsonlFallbackDatabaseSync,
563
587
  resolveDatabaseSync,
564
588
  enforceOwnerOnlyDbPermissions,
package/hooks/hooks.json DELETED
@@ -1,12 +0,0 @@
1
- {
2
- "hooks": {
3
- "PreToolUse": [
4
- { "matcher": "Bash|PowerShell|Edit|MultiEdit|Write|NotebookEdit|Read|Grep|Glob|Task|Agent|WebFetch|mcp__.*",
5
- "hooks": [{ "type": "command", "command": "node \"hooks/pre-tool-use.mjs\"", "timeout": 5 }] }
6
- ],
7
- "PostToolUse": [
8
- { "matcher": "Bash|PowerShell|Grep|Glob|Task|Agent|WebFetch|mcp__.*",
9
- "hooks": [{ "type": "command", "command": "node \"hooks/post-tool-use.mjs\"", "timeout": 5 }] }
10
- ]
11
- }
12
- }