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.
- package/.claude-plugin/plugin.json +11 -0
- package/.github/workflows/burnoff-pr-gate.yml +3 -3
- package/.github/workflows/burnoff-startup-lint.yml +37 -0
- package/README.md +90 -75
- package/bin/burnoff.mjs +185 -24
- package/commands/burnoff.md +16 -0
- package/docs/CLAUDE_CODE_PLUGIN.md +67 -0
- package/docs/DESIGN_PARTNER_INTAKE.md +44 -0
- 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 +15 -7
- package/scripts/burnoff-statusline.mjs +84 -0
- 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 +712 -62
- 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 +382 -151
- 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/guards/snooze.mjs +360 -0
- 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/audit.mjs
CHANGED
|
@@ -12,6 +12,11 @@ import {
|
|
|
12
12
|
discoverClaudeCodeSessions,
|
|
13
13
|
parseTranscriptIncremental
|
|
14
14
|
} from '../storage/jsonl-parser.mjs';
|
|
15
|
+
import {
|
|
16
|
+
discoverAntigravityTranscripts,
|
|
17
|
+
isAntigravityTranscriptFile,
|
|
18
|
+
parseAntigravityTranscript
|
|
19
|
+
} from '../storage/antigravity-parser.mjs';
|
|
15
20
|
import { getSavedQuotaReceiptSummary } from '../storage/ledger.mjs';
|
|
16
21
|
import { attributeUncachedTokens } from '../config/uncached-attribution.mjs';
|
|
17
22
|
import { valuateBatch } from '../config/pricing.mjs';
|
|
@@ -23,6 +28,7 @@ function summarizeParsedSession(meta, parsed, options = {}) {
|
|
|
23
28
|
let cacheReadTokens = 0;
|
|
24
29
|
let outputTokens = 0;
|
|
25
30
|
let thinkingTokens = 0;
|
|
31
|
+
let billedOutputTokens = 0;
|
|
26
32
|
let estimatedCostUsd = 0;
|
|
27
33
|
let cliffTurns = 0;
|
|
28
34
|
let unknownModelTurns = 0;
|
|
@@ -88,6 +94,7 @@ function summarizeParsedSession(meta, parsed, options = {}) {
|
|
|
88
94
|
cacheReadTokens += crTok;
|
|
89
95
|
outputTokens += outTok;
|
|
90
96
|
thinkingTokens += thinkTok;
|
|
97
|
+
billedOutputTokens += Number(costRes?.tokens?.totalOutput ?? outTok);
|
|
91
98
|
|
|
92
99
|
if (costRes.unknownModel) {
|
|
93
100
|
unknownModelTurns += 1;
|
|
@@ -97,7 +104,7 @@ function summarizeParsedSession(meta, parsed, options = {}) {
|
|
|
97
104
|
}
|
|
98
105
|
}
|
|
99
106
|
|
|
100
|
-
const totalTokens = inputTokens + cacheWriteTokens + cacheReadTokens +
|
|
107
|
+
const totalTokens = inputTokens + cacheWriteTokens + cacheReadTokens + billedOutputTokens;
|
|
101
108
|
const cacheDenom = inputTokens + cacheWriteTokens + cacheReadTokens;
|
|
102
109
|
const cacheHitPct = cacheDenom > 0 ? Math.round((cacheReadTokens / cacheDenom) * 100) : 0;
|
|
103
110
|
|
|
@@ -133,28 +140,48 @@ function summarizeParsedSession(meta, parsed, options = {}) {
|
|
|
133
140
|
}
|
|
134
141
|
|
|
135
142
|
/**
|
|
136
|
-
* Audits local Claude Code JSONL transcripts (or a single `--session <path>` file).
|
|
143
|
+
* Audits local Claude Code and/or Google Antigravity JSONL transcripts (or a single `--session <path>` file).
|
|
137
144
|
*/
|
|
138
145
|
export function auditClaudeSessions(options = {}) {
|
|
139
|
-
const
|
|
146
|
+
const explicitHomeDir = typeof options.homeDir === 'string' && options.homeDir.trim()
|
|
147
|
+
? options.homeDir.trim()
|
|
148
|
+
: null;
|
|
149
|
+
const homeDir = explicitHomeDir || getHomeDir();
|
|
140
150
|
const limit = Math.max(1, Number(options.limit ?? 20));
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
+
let candidates;
|
|
152
|
+
if (options.sessionPath) {
|
|
153
|
+
const abs = path.resolve(options.sessionPath);
|
|
154
|
+
const isAg = isAntigravityTranscriptFile(abs);
|
|
155
|
+
candidates = [
|
|
156
|
+
{
|
|
157
|
+
filePath: abs,
|
|
158
|
+
sessionId: path.basename(options.sessionPath, '.jsonl'),
|
|
159
|
+
projectSlug: isAg ? 'antigravity' : '',
|
|
160
|
+
client: isAg ? 'antigravity' : 'claude-code',
|
|
161
|
+
mtimeMs: 0
|
|
162
|
+
}
|
|
163
|
+
];
|
|
164
|
+
} else {
|
|
165
|
+
const clientOpt = String(options.client || 'auto').trim().toLowerCase();
|
|
166
|
+
const includeClaude = clientOpt !== 'antigravity' && clientOpt !== 'ag';
|
|
167
|
+
const includeAg =
|
|
168
|
+
clientOpt === 'antigravity' || clientOpt === 'ag' || clientOpt === 'both' || clientOpt === 'auto';
|
|
169
|
+
const claudeList = includeClaude ? discoverClaudeCodeSessions(homeDir, options) : [];
|
|
170
|
+
const agList = includeAg ? discoverAntigravityTranscripts({ homeDir, cwd: options.cwd }) : [];
|
|
171
|
+
candidates = [...claudeList, ...agList]
|
|
172
|
+
.sort((a, b) => (b.mtimeMs || 0) - (a.mtimeMs || 0))
|
|
173
|
+
.slice(0, limit);
|
|
174
|
+
}
|
|
151
175
|
|
|
152
176
|
const sessions = [];
|
|
153
177
|
for (const meta of candidates) {
|
|
154
|
-
const
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
178
|
+
const useAg = meta.client === 'antigravity' || isAntigravityTranscriptFile(meta.filePath);
|
|
179
|
+
const parsed = useAg
|
|
180
|
+
? parseAntigravityTranscript(meta.filePath, { sessionId: meta.sessionId })
|
|
181
|
+
: parseTranscriptIncremental(meta.filePath, {
|
|
182
|
+
homeDir: explicitHomeDir,
|
|
183
|
+
tailBytes: options.tailBytes
|
|
184
|
+
});
|
|
158
185
|
sessions.push(summarizeParsedSession(meta, parsed, options));
|
|
159
186
|
}
|
|
160
187
|
|
|
@@ -191,7 +218,7 @@ export function auditClaudeSessions(options = {}) {
|
|
|
191
218
|
const denom = totals.inputTokens + totals.cacheWriteTokens + totals.cacheReadTokens;
|
|
192
219
|
totals.cacheHitPct = denom > 0 ? Math.round((totals.cacheReadTokens / denom) * 100) : 0;
|
|
193
220
|
|
|
194
|
-
const ledger = getSavedQuotaReceiptSummary({ homeDir });
|
|
221
|
+
const ledger = getSavedQuotaReceiptSummary({ homeDir: explicitHomeDir });
|
|
195
222
|
const allAttributionCalls = sessions.flatMap((s) => s.attributionCalls || []);
|
|
196
223
|
const valuation = valuateBatch(allAttributionCalls, {
|
|
197
224
|
nowMs: options.nowMs ?? Date.now(),
|
|
@@ -247,6 +274,64 @@ export function formatAuditReport(report = {}) {
|
|
|
247
274
|
` Provider Quirk : Claude 5.5 /compact warm-cache miss (#99624): ${claude55Miss.calls} calls, ${claude55Miss.tokens.toLocaleString('en-US')} uncached tok`
|
|
248
275
|
);
|
|
249
276
|
}
|
|
277
|
+
const buckets = report.uncachedAttribution?.buckets || {};
|
|
278
|
+
const thrash = buckets.model_or_effort_switch?.orchestratorThrash;
|
|
279
|
+
if (thrash && thrash.calls > 0) {
|
|
280
|
+
lines.push(
|
|
281
|
+
` Provider Quirk : Orchestrator/model ping-pong thrash (${thrash.issueRef || '#1638'}): ${thrash.calls} calls, ${thrash.tokens.toLocaleString('en-US')} uncached tok — ${thrash.guidance}`
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
if (Number(report.uncachedAttribution?.totalUncachedTokens || 0) > 0) {
|
|
285
|
+
const driverLines = [];
|
|
286
|
+
const idleMiss = buckets.idle_ttl_miss;
|
|
287
|
+
if (idleMiss && idleMiss.tokens > 0) {
|
|
288
|
+
driverLines.push(
|
|
289
|
+
` - idle_ttl_miss: ${idleMiss.calls} calls, ${idleMiss.tokens.toLocaleString('en-US')} tok (${idleMiss.sharePct}%, ~$${Number(idleMiss.estimatedUsd || 0).toFixed(2)}) — consider 1h cache TTL for >5m review pauses`
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
const modelSwitch = buckets.model_or_effort_switch;
|
|
293
|
+
if (modelSwitch && modelSwitch.tokens > 0) {
|
|
294
|
+
driverLines.push(
|
|
295
|
+
` - model_or_effort_switch: ${modelSwitch.calls} calls, ${modelSwitch.tokens.toLocaleString('en-US')} tok (${modelSwitch.sharePct}%, ~$${Number(modelSwitch.estimatedUsd || 0).toFixed(2)})`
|
|
296
|
+
);
|
|
297
|
+
}
|
|
298
|
+
const unexplained = buckets.unexplained_prefix_reset;
|
|
299
|
+
if (unexplained && unexplained.tokens > 0) {
|
|
300
|
+
const act = unexplained.subBuckets?.actionable_prefix_reset;
|
|
301
|
+
const up = unexplained.subBuckets?.upstream_provider_eviction;
|
|
302
|
+
let emittedSub = false;
|
|
303
|
+
if (act && act.tokens > 0) {
|
|
304
|
+
const likelyHint = Array.isArray(unexplained.likelyCauses) && unexplained.likelyCauses.length > 0
|
|
305
|
+
? ` (e.g., ${unexplained.likelyCauses[0]})`
|
|
306
|
+
: '';
|
|
307
|
+
driverLines.push(
|
|
308
|
+
` - unexplained_prefix_reset (actionable): ${act.calls} calls, ${act.tokens.toLocaleString('en-US')} tok (${act.shareOfBucketPct ?? unexplained.sharePct}%, ~$${Number(act.estimatedUsd || 0).toFixed(2)})${likelyHint}`
|
|
309
|
+
);
|
|
310
|
+
emittedSub = true;
|
|
311
|
+
}
|
|
312
|
+
if (up && up.tokens > 0) {
|
|
313
|
+
const adviceHint = up.advice ? ` — ${up.advice}` : '';
|
|
314
|
+
driverLines.push(
|
|
315
|
+
` - unexplained_prefix_reset (upstream eviction): ${up.calls} calls, ${up.tokens.toLocaleString('en-US')} tok (${up.shareOfBucketPct ?? unexplained.sharePct}%, ~$${Number(up.estimatedUsd || 0).toFixed(2)})${adviceHint}`
|
|
316
|
+
);
|
|
317
|
+
emittedSub = true;
|
|
318
|
+
}
|
|
319
|
+
if (!emittedSub) {
|
|
320
|
+
driverLines.push(
|
|
321
|
+
` - unexplained_prefix_reset: ${unexplained.calls} calls, ${unexplained.tokens.toLocaleString('en-US')} tok (${unexplained.sharePct}%, ~$${Number(unexplained.estimatedUsd || 0).toFixed(2)})`
|
|
322
|
+
);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
const compaction = buckets.compaction_rebuild;
|
|
326
|
+
if (compaction && compaction.tokens > 0) {
|
|
327
|
+
driverLines.push(
|
|
328
|
+
` - compaction_rebuild: ${compaction.calls} calls, ${compaction.tokens.toLocaleString('en-US')} tok (${compaction.sharePct}%, ~$${Number(compaction.estimatedUsd || 0).toFixed(2)})`
|
|
329
|
+
);
|
|
330
|
+
}
|
|
331
|
+
if (driverLines.length > 0) {
|
|
332
|
+
lines.push('', ' Uncached Drivers:', ...driverLines);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
250
335
|
if (Array.isArray(report.sessions) && report.sessions.length > 0) {
|
|
251
336
|
lines.push('', ' Recent Sessions:');
|
|
252
337
|
for (const s of report.sessions.slice(0, 10)) {
|
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)`,
|