burnoff 1.1.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.
- package/.github/workflows/burnoff-pr-gate.yml +3 -3
- package/README.md +66 -78
- package/bin/burnoff.mjs +67 -23
- package/hooks/hook-io.mjs +19 -7
- package/hooks/post-tool-use.mjs +33 -26
- package/hooks/pre-tool-use.mjs +43 -41
- package/hooks/session-lifecycle.mjs +40 -0
- package/package.json +7 -5
- package/src/ci/ci-gate.mjs +22 -0
- package/src/ci/pr-cost.mjs +42 -10
- package/src/ci/team-digest.mjs +5 -3
- package/src/cli/audit.mjs +103 -18
- package/src/cli/doctor.mjs +209 -14
- package/src/cli/init.mjs +349 -96
- package/src/cli/startup-audit.mjs +500 -24
- package/src/clients/antigravity.mjs +285 -0
- package/src/clients/claude-code.mjs +180 -0
- package/src/clients/detect.mjs +64 -0
- package/src/config/loader.mjs +11 -4
- package/src/config/paths.mjs +62 -2
- package/src/config/policy.mjs +34 -5
- package/src/config/pricing.mjs +16 -5
- package/src/guards/loop-breaker.mjs +198 -13
- package/src/guards/post-tool-engine.mjs +289 -29
- package/src/guards/pre-tool-engine.mjs +336 -129
- package/src/guards/read-clamp.mjs +78 -18
- package/src/guards/session-hook.mjs +207 -0
- package/src/guards/shell-guard.mjs +583 -73
- package/src/ipc/daemon.mjs +50 -8
- package/src/ipc/fast-client.mjs +62 -5
- package/src/ipc/protocol.mjs +1 -1
- package/src/storage/antigravity-parser.mjs +258 -0
- package/src/storage/file-lock.mjs +13 -4
- package/src/storage/fts5-archive.mjs +4 -4
- package/src/storage/jsonl-parser.mjs +7 -1
- package/src/storage/ledger.mjs +10 -3
- package/src/storage/sqlite-client.mjs +4 -2
- package/hooks/hooks.json +0 -12
package/src/cli/doctor.mjs
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
import fs from 'node:fs';
|
|
9
9
|
import path from 'node:path';
|
|
10
|
+
import { spawnSync } from 'node:child_process';
|
|
10
11
|
import {
|
|
11
12
|
MIN_NODE_VERSION,
|
|
12
13
|
NATIVE_SQLITE_NODE_VERSION,
|
|
@@ -27,10 +28,159 @@ import { getSavedQuotaReceiptSummary, rotateMonthlyLedger } from '../storage/led
|
|
|
27
28
|
import { openBurnoffDb, resolveFallbackDbPath } from '../storage/sqlite-client.mjs';
|
|
28
29
|
import { sendDaemonRpc, resolveFastIpcPipePath } from '../ipc/fast-client.mjs';
|
|
29
30
|
|
|
31
|
+
function extractFirstCommand(groups) {
|
|
32
|
+
if (!Array.isArray(groups)) return null;
|
|
33
|
+
for (const g of groups) {
|
|
34
|
+
if (Array.isArray(g?.hooks)) {
|
|
35
|
+
for (const h of g.hooks) {
|
|
36
|
+
if (typeof h?.command === 'string' && h.command.trim()) {
|
|
37
|
+
return h.command.trim();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
} else if (typeof g?.command === 'string' && g.command.trim()) {
|
|
41
|
+
return g.command.trim();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function probeAntigravityHookCommand(command, probeCwd, projectCwd) {
|
|
48
|
+
if (!command) {
|
|
49
|
+
return { checked: false, ok: false, command: null, decision: null, exitCode: null, error: 'missing command' };
|
|
50
|
+
}
|
|
51
|
+
const probePayload = JSON.stringify({
|
|
52
|
+
conversationId: 'burnoff-doctor-probe',
|
|
53
|
+
cwd: projectCwd,
|
|
54
|
+
hookEventName: 'PreToolUse',
|
|
55
|
+
toolCall: {
|
|
56
|
+
id: 'doctor-probe',
|
|
57
|
+
name: 'read_file',
|
|
58
|
+
args: {
|
|
59
|
+
AbsolutePath: path.join(projectCwd, 'package.json'),
|
|
60
|
+
StartLine: 1,
|
|
61
|
+
EndLine: 5
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
const run = spawnSync(command, {
|
|
66
|
+
shell: true,
|
|
67
|
+
cwd: probeCwd,
|
|
68
|
+
input: probePayload,
|
|
69
|
+
encoding: 'utf8',
|
|
70
|
+
timeout: 4000,
|
|
71
|
+
windowsHide: true
|
|
72
|
+
});
|
|
73
|
+
if (run.error) {
|
|
74
|
+
return {
|
|
75
|
+
checked: true,
|
|
76
|
+
ok: false,
|
|
77
|
+
command,
|
|
78
|
+
decision: null,
|
|
79
|
+
exitCode: run.status ?? null,
|
|
80
|
+
error: run.error.message || String(run.error)
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
const stdout = String(run.stdout || '').trim();
|
|
84
|
+
if (run.status !== 0) {
|
|
85
|
+
return {
|
|
86
|
+
checked: true,
|
|
87
|
+
ok: false,
|
|
88
|
+
command,
|
|
89
|
+
decision: null,
|
|
90
|
+
exitCode: run.status,
|
|
91
|
+
error: String(run.stderr || stdout || `Exited with status ${run.status}`).trim()
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
try {
|
|
95
|
+
const parsed = JSON.parse(stdout);
|
|
96
|
+
const ok = Boolean(parsed && typeof parsed === 'object' && typeof parsed.decision === 'string');
|
|
97
|
+
return {
|
|
98
|
+
checked: true,
|
|
99
|
+
ok,
|
|
100
|
+
command,
|
|
101
|
+
decision: parsed?.decision || null,
|
|
102
|
+
exitCode: run.status,
|
|
103
|
+
error: ok ? null : 'Missing JSON decision field in stdout'
|
|
104
|
+
};
|
|
105
|
+
} catch (parseErr) {
|
|
106
|
+
return {
|
|
107
|
+
checked: true,
|
|
108
|
+
ok: false,
|
|
109
|
+
command,
|
|
110
|
+
decision: null,
|
|
111
|
+
exitCode: run.status,
|
|
112
|
+
error: `Invalid JSON stdout: ${parseErr?.message || String(parseErr)}`
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function inspectAntigravityHookWiring(cwd, homeDir = getHomeDir(), options = {}) {
|
|
118
|
+
const projectHooksPath = path.join(cwd, '.agents', 'hooks.json');
|
|
119
|
+
const globalHooksPath = path.join(homeDir, '.gemini', 'config', 'hooks.json');
|
|
120
|
+
const inspectFile = (filePath) => {
|
|
121
|
+
if (!filePath || !fs.existsSync(filePath)) {
|
|
122
|
+
return { path: filePath, installed: false, preToolHook: false, postToolHook: false, enabled: false, preCommand: null };
|
|
123
|
+
}
|
|
124
|
+
try {
|
|
125
|
+
const parsed = JSON.parse(fs.readFileSync(filePath, 'utf8'));
|
|
126
|
+
const entry = parsed?.burnoff;
|
|
127
|
+
if (!entry || typeof entry !== 'object') {
|
|
128
|
+
return { path: filePath, installed: false, preToolHook: false, postToolHook: false, enabled: false, preCommand: null };
|
|
129
|
+
}
|
|
130
|
+
const enabled = entry.enabled !== false;
|
|
131
|
+
const containsHook = (groups, targetName, shimToken) =>
|
|
132
|
+
Array.isArray(groups) &&
|
|
133
|
+
groups.some((g) => {
|
|
134
|
+
const checkCmd = (c) => {
|
|
135
|
+
const s = String(c || '');
|
|
136
|
+
return s.includes(targetName) || (s.includes('hook-shim.mjs') && s.includes(shimToken));
|
|
137
|
+
};
|
|
138
|
+
return Array.isArray(g?.hooks) ? g.hooks.some((h) => checkCmd(h?.command)) : checkCmd(g?.command);
|
|
139
|
+
});
|
|
140
|
+
const preToolHook = containsHook(entry.PreToolUse, 'pre-tool-use.mjs', ' pre');
|
|
141
|
+
const postToolHook = containsHook(entry.PostToolUse, 'post-tool-use.mjs', ' post');
|
|
142
|
+
const preCommand = extractFirstCommand(entry.PreToolUse);
|
|
143
|
+
return {
|
|
144
|
+
path: filePath,
|
|
145
|
+
installed: enabled && preToolHook && postToolHook,
|
|
146
|
+
enabled,
|
|
147
|
+
preToolHook,
|
|
148
|
+
postToolHook,
|
|
149
|
+
preCommand
|
|
150
|
+
};
|
|
151
|
+
} catch (err) {
|
|
152
|
+
void err; // ignore: malformed hooks.json reported as unwired
|
|
153
|
+
return { path: filePath, installed: false, preToolHook: false, postToolHook: false, enabled: false, preCommand: null };
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
const project = inspectFile(projectHooksPath);
|
|
158
|
+
const global = inspectFile(globalHooksPath);
|
|
159
|
+
const installed = project.installed || global.installed;
|
|
160
|
+
|
|
161
|
+
let healthCheck = { checked: false, ok: false, command: null, decision: null, exitCode: null, error: null };
|
|
162
|
+
if (installed && !options.skipAntigravityProbe) {
|
|
163
|
+
const active = project.installed ? project : global;
|
|
164
|
+
const agentsDir = path.join(cwd, '.agents');
|
|
165
|
+
const probeCwd = fs.existsSync(agentsDir) ? agentsDir : cwd;
|
|
166
|
+
healthCheck = probeAntigravityHookCommand(active.preCommand, probeCwd, cwd);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
return {
|
|
170
|
+
installed,
|
|
171
|
+
project,
|
|
172
|
+
global,
|
|
173
|
+
healthCheck
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
|
|
30
177
|
function inspectHookWiring(cwd) {
|
|
31
178
|
const settingsLocalPath = path.join(cwd, '.claude', 'settings.local.json');
|
|
32
179
|
let preToolHook = false;
|
|
33
180
|
let postToolHook = false;
|
|
181
|
+
let postToolFailureHook = false;
|
|
182
|
+
let sessionStartHook = false;
|
|
183
|
+
let preCompactHook = false;
|
|
34
184
|
|
|
35
185
|
if (fs.existsSync(settingsLocalPath)) {
|
|
36
186
|
try {
|
|
@@ -47,6 +197,9 @@ function inspectHookWiring(cwd) {
|
|
|
47
197
|
});
|
|
48
198
|
preToolHook = containsHook(hooks.PreToolUse, 'pre-tool-use.mjs', ' pre');
|
|
49
199
|
postToolHook = containsHook(hooks.PostToolUse, 'post-tool-use.mjs', ' post');
|
|
200
|
+
postToolFailureHook = containsHook(hooks.PostToolUseFailure, 'post-tool-use.mjs', ' post');
|
|
201
|
+
sessionStartHook = containsHook(hooks.SessionStart, 'session-lifecycle.mjs', ' session');
|
|
202
|
+
preCompactHook = containsHook(hooks.PreCompact, 'session-lifecycle.mjs', ' session');
|
|
50
203
|
} catch (err) {
|
|
51
204
|
void err; // ignore: malformed settings.local.json reported as unwired
|
|
52
205
|
}
|
|
@@ -82,6 +235,9 @@ function inspectHookWiring(cwd) {
|
|
|
82
235
|
installed: preToolHook && postToolHook,
|
|
83
236
|
preToolHook,
|
|
84
237
|
postToolHook,
|
|
238
|
+
postToolFailureHook,
|
|
239
|
+
sessionStartHook,
|
|
240
|
+
preCompactHook,
|
|
85
241
|
excludePath,
|
|
86
242
|
gitExcludeProtected
|
|
87
243
|
};
|
|
@@ -129,7 +285,10 @@ function reapStaleCacheFiles(dirPath, cutoffMs, skipNames = new Set()) {
|
|
|
129
285
|
*/
|
|
130
286
|
export async function runDoctor(options = {}) {
|
|
131
287
|
const cwd = path.resolve(options.cwd || process.cwd());
|
|
132
|
-
const
|
|
288
|
+
const explicitHomeDir = typeof options.homeDir === 'string' && options.homeDir.trim()
|
|
289
|
+
? options.homeDir.trim()
|
|
290
|
+
: null;
|
|
291
|
+
const homeDir = explicitHomeDir || getHomeDir();
|
|
133
292
|
const nodeVersion = options.nodeVersion || process.versions.node;
|
|
134
293
|
const nowMs = Number(options.nowMs || Date.now());
|
|
135
294
|
const maxCacheAgeDays = Math.max(1, Number(options.maxCacheAgeDays ?? 14));
|
|
@@ -138,18 +297,19 @@ export async function runDoctor(options = {}) {
|
|
|
138
297
|
const nativeSqlite = hasNativeNodeSqlite(nodeVersion);
|
|
139
298
|
const policy = loadBurnoffPolicy(cwd);
|
|
140
299
|
const hooks = inspectHookWiring(cwd);
|
|
141
|
-
const
|
|
142
|
-
const
|
|
143
|
-
const
|
|
300
|
+
const antigravityHooks = inspectAntigravityHookWiring(cwd, homeDir, options);
|
|
301
|
+
const fts5DbPath = getDefaultToolLogsDbPath(explicitHomeDir);
|
|
302
|
+
const fts5Stats = getFts5CompressionStats(fts5DbPath, { homeDir: explicitHomeDir });
|
|
303
|
+
const ledgerSummary = getSavedQuotaReceiptSummary({ homeDir: explicitHomeDir, nowMs });
|
|
144
304
|
const atomicIo = getAtomicIoMetrics();
|
|
145
305
|
|
|
146
306
|
let daemonPing = null;
|
|
147
|
-
const ipcPath = resolveFastIpcPipePath({ cwd, homeDir, ipcPath: options.ipcPath });
|
|
307
|
+
const ipcPath = resolveFastIpcPipePath({ cwd, homeDir: explicitHomeDir, ipcPath: options.ipcPath });
|
|
148
308
|
if (!options.skipDaemonCheck) {
|
|
149
309
|
daemonPing = await sendDaemonRpc(
|
|
150
310
|
'daemon.ping',
|
|
151
311
|
{},
|
|
152
|
-
{ cwd, homeDir, ipcPath: options.ipcPath, requestTimeoutMs: 80 }
|
|
312
|
+
{ cwd, homeDir: explicitHomeDir, ipcPath: options.ipcPath, requestTimeoutMs: 80 }
|
|
153
313
|
);
|
|
154
314
|
}
|
|
155
315
|
|
|
@@ -169,31 +329,51 @@ export async function runDoctor(options = {}) {
|
|
|
169
329
|
}
|
|
170
330
|
}
|
|
171
331
|
const cutoffMs = nowMs - maxCacheAgeDays * 24 * 60 * 60 * 1000;
|
|
172
|
-
const homeCacheReaped = reapStaleCacheFiles(getBurnoffCacheDir(
|
|
332
|
+
const homeCacheReaped = reapStaleCacheFiles(getBurnoffCacheDir(explicitHomeDir), cutoffMs);
|
|
173
333
|
const wsCacheReaped = reapStaleCacheFiles(path.join(cwd, '.claude', 'cache'), cutoffMs);
|
|
174
334
|
const wsArtifactsReaped = reapStaleCacheFiles(path.join(cwd, '.claude', 'cache', 'artifacts'), cutoffMs);
|
|
175
|
-
const
|
|
335
|
+
const stateRootDir = path.join(getBurnoffHomeDir(explicitHomeDir), 'state');
|
|
336
|
+
let agStateRemoved = 0;
|
|
337
|
+
let agStateBytes = 0;
|
|
338
|
+
if (fs.existsSync(stateRootDir)) {
|
|
339
|
+
try {
|
|
340
|
+
for (const ent of fs.readdirSync(stateRootDir, { withFileTypes: true })) {
|
|
341
|
+
if (ent.isDirectory()) {
|
|
342
|
+
const sub = reapStaleCacheFiles(path.join(stateRootDir, ent.name), cutoffMs);
|
|
343
|
+
agStateRemoved += sub.removedFiles;
|
|
344
|
+
agStateBytes += sub.reclaimedBytes;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
} catch (err) {
|
|
348
|
+
void err; // ignore: unreadable state root during gc
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
const ledgerRotation = rotateMonthlyLedger({ homeDir: explicitHomeDir, nowMs });
|
|
176
352
|
gcResult = {
|
|
177
353
|
performed: true,
|
|
178
354
|
maxCacheAgeDays,
|
|
179
355
|
fts5Pruned,
|
|
180
356
|
reapedCacheFiles:
|
|
181
|
-
homeCacheReaped.removedFiles + wsCacheReaped.removedFiles + wsArtifactsReaped.removedFiles,
|
|
357
|
+
homeCacheReaped.removedFiles + wsCacheReaped.removedFiles + wsArtifactsReaped.removedFiles + agStateRemoved,
|
|
182
358
|
reclaimedBytes:
|
|
183
|
-
homeCacheReaped.reclaimedBytes + wsCacheReaped.reclaimedBytes + wsArtifactsReaped.reclaimedBytes,
|
|
359
|
+
homeCacheReaped.reclaimedBytes + wsCacheReaped.reclaimedBytes + wsArtifactsReaped.reclaimedBytes + agStateBytes,
|
|
184
360
|
ledgerRotation
|
|
185
361
|
};
|
|
186
362
|
}
|
|
187
363
|
|
|
364
|
+
const anyHooksInstalled = hooks.installed || antigravityHooks.installed;
|
|
365
|
+
const hooksDegraded =
|
|
366
|
+
(hooks.installed && !hooks.postToolFailureHook) ||
|
|
367
|
+
(antigravityHooks.installed && antigravityHooks.healthCheck?.checked && !antigravityHooks.healthCheck.ok);
|
|
188
368
|
const status = !nodeSupported
|
|
189
369
|
? 'ERROR'
|
|
190
|
-
: (!nativeSqlite || policy.parseError || !
|
|
370
|
+
: (!nativeSqlite || policy.parseError || !anyHooksInstalled || hooksDegraded ? 'WARN' : 'OK');
|
|
191
371
|
|
|
192
372
|
return {
|
|
193
373
|
ok: nodeSupported,
|
|
194
374
|
status,
|
|
195
375
|
cwd,
|
|
196
|
-
burnoffHome: getBurnoffHomeDir(
|
|
376
|
+
burnoffHome: getBurnoffHomeDir(explicitHomeDir),
|
|
197
377
|
node: {
|
|
198
378
|
version: nodeVersion,
|
|
199
379
|
supported: nodeSupported,
|
|
@@ -213,6 +393,7 @@ export async function runDoctor(options = {}) {
|
|
|
213
393
|
neverClampCodeOffCliff: Boolean(policy.readClamp?.neverClampCodeOffCliff)
|
|
214
394
|
},
|
|
215
395
|
hooks,
|
|
396
|
+
antigravityHooks,
|
|
216
397
|
daemon: {
|
|
217
398
|
ipcPath,
|
|
218
399
|
running: Boolean(daemonPing?.pong),
|
|
@@ -221,7 +402,7 @@ export async function runDoctor(options = {}) {
|
|
|
221
402
|
},
|
|
222
403
|
fts5: {
|
|
223
404
|
dbPath: fts5DbPath,
|
|
224
|
-
exists: fs.existsSync(fts5DbPath),
|
|
405
|
+
exists: fs.existsSync(fts5DbPath) || fs.existsSync(resolveFallbackDbPath(fts5DbPath)),
|
|
225
406
|
...fts5Stats
|
|
226
407
|
},
|
|
227
408
|
ledger: {
|
|
@@ -241,13 +422,27 @@ export async function runDoctor(options = {}) {
|
|
|
241
422
|
* Formats a `runDoctor()` report for terminal output.
|
|
242
423
|
*/
|
|
243
424
|
export function formatDoctorReport(report = {}) {
|
|
425
|
+
const claudeLine = report.hooks?.installed
|
|
426
|
+
? `installed (.claude/settings.local.json) [PostToolUseFailure=${report.hooks.postToolFailureHook ? 'ok' : 'missing'}]`
|
|
427
|
+
: 'not installed';
|
|
428
|
+
const agBase = report.antigravityHooks?.project?.installed
|
|
429
|
+
? 'installed (.agents/hooks.json)'
|
|
430
|
+
: report.antigravityHooks?.global?.installed
|
|
431
|
+
? 'installed (~/.gemini/config/hooks.json)'
|
|
432
|
+
: 'not installed';
|
|
433
|
+
const agProbe = report.antigravityHooks?.healthCheck?.checked
|
|
434
|
+
? (report.antigravityHooks.healthCheck.ok
|
|
435
|
+
? ' [probe=ok]'
|
|
436
|
+
: ` [probe=failed: ${report.antigravityHooks.healthCheck.error || 'error'}]`)
|
|
437
|
+
: '';
|
|
244
438
|
const lines = [
|
|
245
439
|
`Burnoff Doctor: ${report.status || 'UNKNOWN'}`,
|
|
246
440
|
` Node.js : v${report.node?.version || 'unknown'} (${report.node?.supported ? 'supported' : `requires >=${report.node?.minVersion}`})`,
|
|
247
441
|
` SQLite FTS5 : ${report.sqlite?.mode || 'unknown'}`,
|
|
248
442
|
` Burnoff Home : ${report.burnoffHome || ''}`,
|
|
249
443
|
` Policy : ${report.policy?.exists ? report.policy.sourcePath : 'defaults (no .burnoff.yaml)'} [mode=${report.policy?.guardMode || 'guard'}]`,
|
|
250
|
-
` Claude Hooks : ${
|
|
444
|
+
` Claude Hooks : ${claudeLine} | git exclude=${report.hooks?.gitExcludeProtected ? 'yes' : 'no'}`,
|
|
445
|
+
` Antigravity : ${agBase}${agProbe}`,
|
|
251
446
|
` Warm Daemon : ${report.daemon?.running ? `running (pid=${report.daemon.pid})` : 'stopped (cold fallback active)'}`,
|
|
252
447
|
` FTS5 Archive : ${report.fts5?.logCount ?? 0} logs (~${report.fts5?.formattedSavedK || '0.0k'} tok compressed)`,
|
|
253
448
|
` Ledger : $${Number(report.ledger?.avoidedWriteUSD || 0).toFixed(4)} avoided | $${Number(report.ledger?.platformCacheUSD || 0).toFixed(4)} cache discount (${report.ledger?.entryCount ?? 0} receipts)`,
|