burnoff 1.4.1 → 2.1.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 +1 -1
- package/.github/workflows/burnoff-pr-gate.yml +5 -3
- package/.github/workflows/burnoff-startup-lint.yml +2 -2
- package/CHANGELOG.md +74 -0
- package/README.md +187 -213
- package/SECURITY.md +38 -0
- package/bin/burnoff.mjs +307 -32
- package/commands/burnoff.md +6 -4
- package/docs/CLAUDE_CODE_PLUGIN.md +29 -28
- package/docs/DESIGN_PARTNER_INTAKE.md +3 -3
- package/hooks/hook-io.mjs +216 -11
- package/hooks/hooks.json +44 -0
- package/hooks/post-tool-use.mjs +3 -1
- package/hooks/pre-tool-use.mjs +47 -8
- package/hooks/session-lifecycle.mjs +24 -3
- package/hooks/user-prompt-submit.mjs +98 -0
- package/package.json +6 -4
- package/scripts/bench-hooks.mjs +34 -3
- package/scripts/bench-savings.mjs +318 -0
- package/scripts/burnoff-statusline.mjs +138 -6
- package/src/ci/ci-gate.mjs +199 -13
- package/src/ci/pr-cost.mjs +417 -45
- package/src/ci/pr-summary.mjs +467 -0
- package/src/cli/audit.mjs +179 -28
- package/src/cli/doctor.mjs +32 -6
- package/src/cli/hook-health.mjs +9 -1
- package/src/cli/init.mjs +226 -39
- package/src/cli/preview.mjs +299 -0
- package/src/cli/startup-audit/formatter.mjs +248 -0
- package/src/cli/startup-audit/jsonc.mjs +601 -0
- package/src/cli/startup-audit/mcp-audit.mjs +735 -0
- package/src/cli/startup-audit/rules-hygiene.mjs +645 -0
- package/src/cli/startup-audit/telemetry-scan.mjs +975 -0
- package/src/cli/startup-audit.mjs +451 -2471
- package/src/clients/claude-code.mjs +41 -4
- package/src/config/catalog.json +295 -0
- package/src/config/effort.mjs +145 -0
- package/src/config/harness-quirks.mjs +340 -0
- package/src/config/loader.mjs +27 -2
- package/src/config/policy.mjs +81 -9
- package/src/config/pricing.mjs +247 -19
- package/src/config/semver.mjs +25 -0
- package/src/config/uncached-attribution.mjs +280 -41
- package/src/guards/compaction-baton.mjs +248 -0
- package/src/guards/loop-breaker.mjs +328 -47
- package/src/guards/model-switch-hook.mjs +126 -0
- package/src/guards/phase5-detectors.mjs +275 -21
- package/src/guards/post-tool-engine.mjs +333 -11
- package/src/guards/pre-tool-engine.mjs +607 -45
- package/src/guards/prefix-guard.mjs +609 -0
- package/src/guards/prompt-guard.mjs +309 -0
- package/src/guards/read-clamp.mjs +192 -8
- package/src/guards/session-hook.mjs +149 -7
- package/src/guards/shell-guard.mjs +56 -5
- package/src/guards/snooze.mjs +169 -5
- package/src/ipc/daemon.mjs +76 -0
- package/src/ipc/fast-client.mjs +165 -4
- package/src/ipc/protocol.mjs +16 -3
- package/src/storage/antigravity-parser.mjs +16 -2
- package/src/storage/file-lock.mjs +16 -3
- package/src/storage/jsonl-parser.mjs +133 -22
- package/src/storage/telemetry-metrics.mjs +254 -4
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file src/cli/preview.mjs
|
|
3
|
+
* Fast (<2.5s), strictly read-only 0-commitment quick preview (`npx burnoff` / `burnoff preview`).
|
|
4
|
+
* Zero filesystem mutations in `cwd` or `homeDir`.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import fs from 'node:fs';
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
import { fileURLToPath } from 'node:url';
|
|
10
|
+
import { getHomeDir } from '../config/paths.mjs';
|
|
11
|
+
import { auditClaudeSessions } from './audit.mjs';
|
|
12
|
+
import { runStartupAudit } from './startup-audit.mjs';
|
|
13
|
+
|
|
14
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
15
|
+
const PACKAGE_ROOT = path.resolve(__dirname, '..', '..');
|
|
16
|
+
|
|
17
|
+
function readPackageVersionSafe() {
|
|
18
|
+
try {
|
|
19
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(PACKAGE_ROOT, 'package.json'), 'utf8'));
|
|
20
|
+
if (pkg?.version) return String(pkg.version);
|
|
21
|
+
} catch (err) {
|
|
22
|
+
void err; // ignore: version lookup fallback
|
|
23
|
+
}
|
|
24
|
+
return '2.0.0';
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function readJsonSafeReadOnly(filePath) {
|
|
28
|
+
try {
|
|
29
|
+
if (!fs.existsSync(filePath)) return null;
|
|
30
|
+
return JSON.parse(fs.readFileSync(filePath, 'utf8'));
|
|
31
|
+
} catch (err) {
|
|
32
|
+
void err; // ignore: unreadable or invalid JSON reported cleanly
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function hooksContainBurnoff(hooksObj) {
|
|
38
|
+
if (!hooksObj || typeof hooksObj !== 'object') return false;
|
|
39
|
+
return JSON.stringify(hooksObj).toLowerCase().includes('burnoff');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Detects local Claude Code & Google Antigravity configs and hook wiring read-only.
|
|
44
|
+
*/
|
|
45
|
+
export function detectClientsReadOnly({ cwd = process.cwd(), homeDir = getHomeDir() } = {}) {
|
|
46
|
+
const baseCwd = path.resolve(cwd);
|
|
47
|
+
const resolvedHome = homeDir ? path.resolve(homeDir) : getHomeDir();
|
|
48
|
+
|
|
49
|
+
const claudeLocalSettings = path.join(baseCwd, '.claude', 'settings.local.json');
|
|
50
|
+
const claudeGlobalSettings = path.join(resolvedHome, '.claude', 'settings.json');
|
|
51
|
+
const claudeProjectDir = path.join(baseCwd, '.claude');
|
|
52
|
+
const claudeGlobalDir = path.join(resolvedHome, '.claude');
|
|
53
|
+
|
|
54
|
+
const claudeLocalDoc = readJsonSafeReadOnly(claudeLocalSettings);
|
|
55
|
+
const claudeGlobalDoc = readJsonSafeReadOnly(claudeGlobalSettings);
|
|
56
|
+
const claudeLocalWired = hooksContainBurnoff(claudeLocalDoc?.hooks);
|
|
57
|
+
const claudeGlobalWired = hooksContainBurnoff(claudeGlobalDoc?.hooks);
|
|
58
|
+
const claudePresent =
|
|
59
|
+
claudeLocalWired ||
|
|
60
|
+
claudeGlobalWired ||
|
|
61
|
+
fs.existsSync(claudeProjectDir) ||
|
|
62
|
+
fs.existsSync(claudeGlobalDir) ||
|
|
63
|
+
fs.existsSync(path.join(baseCwd, 'CLAUDE.md')) ||
|
|
64
|
+
fs.existsSync(path.join(baseCwd, '.mcp.json'));
|
|
65
|
+
|
|
66
|
+
const agLocalHooks = path.join(baseCwd, '.agents', 'hooks.json');
|
|
67
|
+
const agGlobalHooks = path.join(resolvedHome, '.gemini', 'config', 'hooks.json');
|
|
68
|
+
const agLocalDoc = readJsonSafeReadOnly(agLocalHooks);
|
|
69
|
+
const agGlobalDoc = readJsonSafeReadOnly(agGlobalHooks);
|
|
70
|
+
const agLocalWired = hooksContainBurnoff(agLocalDoc?.hooks);
|
|
71
|
+
const agGlobalWired = hooksContainBurnoff(agGlobalDoc?.hooks);
|
|
72
|
+
const agPresent =
|
|
73
|
+
agLocalWired ||
|
|
74
|
+
agGlobalWired ||
|
|
75
|
+
fs.existsSync(path.join(baseCwd, '.agents')) ||
|
|
76
|
+
fs.existsSync(path.join(resolvedHome, '.gemini')) ||
|
|
77
|
+
fs.existsSync(path.join(baseCwd, 'GEMINI.md'));
|
|
78
|
+
|
|
79
|
+
const clientsDetected = [];
|
|
80
|
+
if (claudePresent) clientsDetected.push('claude-code');
|
|
81
|
+
if (agPresent) clientsDetected.push('antigravity');
|
|
82
|
+
|
|
83
|
+
const hookScopes = [];
|
|
84
|
+
if (claudeLocalWired) hookScopes.push('.claude/settings.local.json');
|
|
85
|
+
if (claudeGlobalWired) hookScopes.push('~/.claude/settings.json');
|
|
86
|
+
if (agLocalWired) hookScopes.push('.agents/hooks.json');
|
|
87
|
+
if (agGlobalWired) hookScopes.push('~/.gemini/config/hooks.json');
|
|
88
|
+
|
|
89
|
+
return {
|
|
90
|
+
clientsDetected,
|
|
91
|
+
hooksInstalled: hookScopes.length > 0,
|
|
92
|
+
hookScopes,
|
|
93
|
+
claude: {
|
|
94
|
+
detected: claudePresent,
|
|
95
|
+
installed: claudeLocalWired || claudeGlobalWired,
|
|
96
|
+
scope: claudeLocalWired ? 'project' : claudeGlobalWired ? 'global' : 'none'
|
|
97
|
+
},
|
|
98
|
+
antigravity: {
|
|
99
|
+
detected: agPresent,
|
|
100
|
+
installed: agLocalWired || agGlobalWired,
|
|
101
|
+
scope: agLocalWired ? 'project' : agGlobalWired ? 'global' : 'none'
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Runs a bounded, strictly read-only quick preview of local sessions and repo Turn-0 hygiene.
|
|
108
|
+
*/
|
|
109
|
+
export function runQuickPreview({
|
|
110
|
+
cwd = process.cwd(),
|
|
111
|
+
homeDir = getHomeDir(),
|
|
112
|
+
days = 7,
|
|
113
|
+
maxFiles = 10,
|
|
114
|
+
timeBudgetMs = 2500,
|
|
115
|
+
client = 'auto',
|
|
116
|
+
nowMs = Date.now()
|
|
117
|
+
} = {}) {
|
|
118
|
+
const startedAt = Date.now();
|
|
119
|
+
const safeBudgetMs = Math.max(250, Number(timeBudgetMs || 2500));
|
|
120
|
+
const deadlineMs = startedAt + safeBudgetMs;
|
|
121
|
+
const baseCwd = path.resolve(cwd);
|
|
122
|
+
const resolvedHome = homeDir ? path.resolve(homeDir) : getHomeDir();
|
|
123
|
+
const safeDays = Math.max(1, Number(days || 7));
|
|
124
|
+
const safeLimit = Math.max(1, Number(maxFiles || 10));
|
|
125
|
+
|
|
126
|
+
const detection = detectClientsReadOnly({ cwd: baseCwd, homeDir: resolvedHome });
|
|
127
|
+
|
|
128
|
+
let transcriptReport = null;
|
|
129
|
+
let transcriptSkippedReason = null;
|
|
130
|
+
if (Date.now() < deadlineMs - 100) {
|
|
131
|
+
try {
|
|
132
|
+
transcriptReport = auditClaudeSessions({
|
|
133
|
+
cwd: baseCwd,
|
|
134
|
+
homeDir: resolvedHome,
|
|
135
|
+
client,
|
|
136
|
+
limit: safeLimit,
|
|
137
|
+
days: safeDays,
|
|
138
|
+
nowMs,
|
|
139
|
+
tailBytes: 512 * 1024,
|
|
140
|
+
readOnly: true
|
|
141
|
+
});
|
|
142
|
+
} catch (err) {
|
|
143
|
+
transcriptSkippedReason = err?.message || 'transcript scan unavailable';
|
|
144
|
+
}
|
|
145
|
+
} else {
|
|
146
|
+
transcriptSkippedReason = 'time budget reached';
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
let startupReport = null;
|
|
150
|
+
let startupSkippedReason = null;
|
|
151
|
+
if (Date.now() < deadlineMs - 30) {
|
|
152
|
+
try {
|
|
153
|
+
startupReport = runStartupAudit({
|
|
154
|
+
cwd: baseCwd,
|
|
155
|
+
homeDir: resolvedHome,
|
|
156
|
+
client,
|
|
157
|
+
ci: true,
|
|
158
|
+
repoOnly: true
|
|
159
|
+
});
|
|
160
|
+
} catch (err) {
|
|
161
|
+
startupSkippedReason = err?.message || 'startup hygiene check unavailable';
|
|
162
|
+
}
|
|
163
|
+
} else {
|
|
164
|
+
startupSkippedReason = 'time budget reached';
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const totals = transcriptReport?.totals || {};
|
|
168
|
+
const uncachedAttr = transcriptReport?.uncachedAttribution || {};
|
|
169
|
+
const ledger = transcriptReport?.ledger || {};
|
|
170
|
+
const coldCalls = Array.isArray(uncachedAttr?.causes)
|
|
171
|
+
? uncachedAttr.causes.reduce((sum, c) => sum + Number(c?.calls || 0), 0)
|
|
172
|
+
: Number(totals.cliffTurns || 0);
|
|
173
|
+
const missedCacheTokens = Number(uncachedAttr?.totalUncachedTokens || 0);
|
|
174
|
+
const estMissedUsd = Number(uncachedAttr?.totalExtraCostUsd || 0);
|
|
175
|
+
const lints = Array.isArray(startupReport?.lints) ? startupReport.lints : [];
|
|
176
|
+
|
|
177
|
+
const elapsedMs = Math.max(0, Date.now() - startedAt);
|
|
178
|
+
return {
|
|
179
|
+
ok: true,
|
|
180
|
+
readOnly: true,
|
|
181
|
+
version: readPackageVersionSafe(),
|
|
182
|
+
cwd: baseCwd,
|
|
183
|
+
days: safeDays,
|
|
184
|
+
maxFiles: safeLimit,
|
|
185
|
+
timeBudgetMs: safeBudgetMs,
|
|
186
|
+
elapsedMs,
|
|
187
|
+
withinBudget: elapsedMs <= safeBudgetMs,
|
|
188
|
+
detection,
|
|
189
|
+
transcripts: {
|
|
190
|
+
scanned: transcriptReport !== null,
|
|
191
|
+
skippedReason: transcriptSkippedReason,
|
|
192
|
+
sessions: Number(totals.sessions || 0),
|
|
193
|
+
turns: Number(totals.turns || 0),
|
|
194
|
+
estimatedCostUsd: Number(totals.estimatedCostUsd || 0),
|
|
195
|
+
cacheHitPct: Number(totals.cacheHitPct || 0),
|
|
196
|
+
coldCacheRebuilds: coldCalls,
|
|
197
|
+
missedCacheTokens,
|
|
198
|
+
estimatedMissedUsd: estMissedUsd,
|
|
199
|
+
ledgerAvoidedUsd: Number(ledger.avoidedWriteUSD || 0),
|
|
200
|
+
ledgerAvoidedTokens: Number(ledger.avoidedWriteTokens || 0)
|
|
201
|
+
},
|
|
202
|
+
startup: {
|
|
203
|
+
scanned: startupReport !== null,
|
|
204
|
+
skippedReason: startupSkippedReason,
|
|
205
|
+
issueCount: Number(startupReport?.summary?.issueCount || lints.length || 0),
|
|
206
|
+
estimatedTurn0ReclaimableTokens: Number(
|
|
207
|
+
startupReport?.summary?.estimatedTurn0ReclaimableTokens || 0
|
|
208
|
+
),
|
|
209
|
+
estimatedWeeklySavingsUsd: Number(
|
|
210
|
+
startupReport?.summary?.estimatedWeeklySavingsUsd || 0
|
|
211
|
+
),
|
|
212
|
+
topLints: lints.slice(0, 3).map((l) => ({
|
|
213
|
+
ruleId: l.ruleId || l.id || 'BO-CFG',
|
|
214
|
+
severity: l.severity || 'warn',
|
|
215
|
+
message: String(l.message || l.summary || l.detail || '').replace(/\s+/g, ' ').trim()
|
|
216
|
+
}))
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function truncateLine(text, maxLen = 68) {
|
|
222
|
+
const s = String(text || '');
|
|
223
|
+
return s.length <= maxLen ? s : `${s.slice(0, maxLen - 3)}...`;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Formats a compact, <=72-column screenshot-worthy read-only preview receipt.
|
|
228
|
+
*/
|
|
229
|
+
export function formatPreviewReceipt(report = {}) {
|
|
230
|
+
const version = report.version || '2.0.0';
|
|
231
|
+
const det = report.detection || {};
|
|
232
|
+
const tr = report.transcripts || {};
|
|
233
|
+
const st = report.startup || {};
|
|
234
|
+
const bar = '─'.repeat(70);
|
|
235
|
+
|
|
236
|
+
const clientLabel =
|
|
237
|
+
Array.isArray(det.clientsDetected) && det.clientsDetected.length > 0
|
|
238
|
+
? det.clientsDetected.join(' + ')
|
|
239
|
+
: 'none detected yet';
|
|
240
|
+
const hooksLabel = det.hooksInstalled
|
|
241
|
+
? `wired (${(det.hookScopes || []).join(', ')})`
|
|
242
|
+
: 'not wired (read-only preview)';
|
|
243
|
+
|
|
244
|
+
const lines = [
|
|
245
|
+
bar,
|
|
246
|
+
`burnoff v${version} — 0-Commitment Preview (0 files written, ${report.elapsedMs ?? 0}ms)`,
|
|
247
|
+
bar,
|
|
248
|
+
` Workspace : ${truncateLine(path.basename(report.cwd || process.cwd()) || '.', 56)}`,
|
|
249
|
+
` Clients : ${truncateLine(clientLabel, 56)}`,
|
|
250
|
+
` Hooks : ${truncateLine(hooksLabel, 56)}`
|
|
251
|
+
];
|
|
252
|
+
|
|
253
|
+
if (!tr.scanned) {
|
|
254
|
+
lines.push(` Sessions : skipped (${truncateLine(tr.skippedReason || 'budget', 48)})`);
|
|
255
|
+
} else if (tr.sessions === 0) {
|
|
256
|
+
lines.push(` Sessions : 0 recent transcripts in last ${report.days || 7}d`);
|
|
257
|
+
} else {
|
|
258
|
+
const spend = `$${Number(tr.estimatedCostUsd || 0).toFixed(2)}`;
|
|
259
|
+
const coldNote = tr.coldCacheRebuilds > 0 ? ` | ${tr.coldCacheRebuilds} cold rebuild(s)` : '';
|
|
260
|
+
const daysTag = `${report.days || 7}d`;
|
|
261
|
+
lines.push(
|
|
262
|
+
` Last ${daysTag.padEnd(3)} : ${tr.sessions} sess / ${tr.turns} turns | ${spend} | ${tr.cacheHitPct}% hit${coldNote}`
|
|
263
|
+
);
|
|
264
|
+
if (tr.ledgerAvoidedUsd >= 0.1) {
|
|
265
|
+
lines.push(
|
|
266
|
+
` Saved : $${Number(tr.ledgerAvoidedUsd).toFixed(2)} (${Number(tr.ledgerAvoidedTokens || 0).toLocaleString('en-US')} tok avoided)`
|
|
267
|
+
);
|
|
268
|
+
} else if (tr.estimatedMissedUsd >= 0.05) {
|
|
269
|
+
lines.push(
|
|
270
|
+
` Reclaim : ~$${Number(tr.estimatedMissedUsd).toFixed(2)} est. uncached prefill waste`
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
if (!st.scanned) {
|
|
276
|
+
lines.push(` Repo Lint : skipped (${truncateLine(st.skippedReason || 'budget', 48)})`);
|
|
277
|
+
} else if (st.issueCount === 0) {
|
|
278
|
+
lines.push(' Repo Lint : 0 Turn-0 rule/MCP/secret issues detected');
|
|
279
|
+
} else {
|
|
280
|
+
const tok = Number(st.estimatedTurn0ReclaimableTokens || 0);
|
|
281
|
+
const tokLabel = tok > 0 ? ` (~${tok.toLocaleString('en-US')} Turn-0 tok reclaimable)` : '';
|
|
282
|
+
lines.push(` Repo Lint : ${st.issueCount} issue(s)${tokLabel}`);
|
|
283
|
+
for (const lint of st.topLints || []) {
|
|
284
|
+
lines.push(` - ${lint.ruleId}: ${truncateLine(lint.message, 56)}`);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
lines.push(bar);
|
|
289
|
+
lines.push(det.hooksInstalled ? ' Run diagnostics: npx burnoff doctor' : ' Install hooks : npx burnoff init');
|
|
290
|
+
lines.push(' All commands : burnoff --help');
|
|
291
|
+
lines.push(bar);
|
|
292
|
+
return `${lines.join('\n')}\n`;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
export default {
|
|
296
|
+
detectClientsReadOnly,
|
|
297
|
+
runQuickPreview,
|
|
298
|
+
formatPreviewReceipt
|
|
299
|
+
};
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file src/cli/startup-audit/formatter.mjs
|
|
3
|
+
* Terminal report formatting and GitHub Actions CI verdict/annotation evaluation.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Formats `runClaudeStartupAudit()` for terminal output with zero em dashes.
|
|
10
|
+
*/
|
|
11
|
+
export function formatClaudeStartupAuditReport(report) {
|
|
12
|
+
if (!report?.ok) return 'Burnoff Startup Audit failed\n';
|
|
13
|
+
const s = report.summary || {};
|
|
14
|
+
const c = report.claudeCode?.checks;
|
|
15
|
+
const r = report.rulesAudit?.byHarness?.claudeCode;
|
|
16
|
+
const lines = [
|
|
17
|
+
`Burnoff Claude Code Turn-0 Startup Audit | Findings: ${s.issueCount ?? 0} | Reclaimable: ~${Number(s.estimatedTurn0ReclaimableTokens || 0).toLocaleString('en-US')} tok/turn (est.) (~$${Number(s.estimatedWeeklySavingsUsd || 0).toFixed(2)}/wk)`
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
if (c) {
|
|
21
|
+
lines.push(` - ${c.mcpStartupTax.summaryLine}`);
|
|
22
|
+
if (c.mcpStartupTax.unusedEagerServers?.length) {
|
|
23
|
+
lines.push(
|
|
24
|
+
` Unused eager servers (7d): ${c.mcpStartupTax.unusedEagerServers.map((x) => `${x.name} (~${x.tokensEst} tok)`).join(', ')}`
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
if (c.chromeDefaultEnabled.status === 'warn') {
|
|
28
|
+
lines.push(
|
|
29
|
+
` - [warn] Chrome default enabled in ~/.claude.json with 0 browser calls in 7d (~${c.chromeDefaultEnabled.reclaimableTokensPerTurn} tok/turn est.)`
|
|
30
|
+
);
|
|
31
|
+
lines.push(` Fix: ${c.chromeDefaultEnabled.fix}`);
|
|
32
|
+
} else {
|
|
33
|
+
lines.push(' - [pass] Chrome default disabled (or actively used)');
|
|
34
|
+
}
|
|
35
|
+
if (c.artifactTool.status === 'warn') {
|
|
36
|
+
lines.push(
|
|
37
|
+
` - [warn] Artifact built-in tool active (${c.artifactTool.entrypoint}, 0 calls in 7d, ~${c.artifactTool.reclaimableTokensPerTurn} tok/turn est.)`
|
|
38
|
+
);
|
|
39
|
+
lines.push(` Note: ${c.artifactTool.oneWayLockWarning}`);
|
|
40
|
+
if (c.artifactTool.fixes?.migrateDeprecated) {
|
|
41
|
+
lines.push(` Fix (migrate): ${c.artifactTool.fixes.migrateDeprecated}`);
|
|
42
|
+
}
|
|
43
|
+
if (c.artifactTool.fixes?.neverUseArtifacts) {
|
|
44
|
+
lines.push(` Fix (never use): ${c.artifactTool.fixes.neverUseArtifacts}`);
|
|
45
|
+
}
|
|
46
|
+
if (c.artifactTool.fixes?.occasionalArtifacts) {
|
|
47
|
+
lines.push(` Fix (occasional): ${c.artifactTool.fixes.occasionalArtifacts}`);
|
|
48
|
+
}
|
|
49
|
+
} else {
|
|
50
|
+
lines.push(` - [pass] Artifact tool (${c.artifactTool.entrypoint})`);
|
|
51
|
+
}
|
|
52
|
+
if (c.bundledSkillsAndWorkflows.status === 'warn' && c.bundledSkillsAndWorkflows.fix) {
|
|
53
|
+
const prio = c.bundledSkillsAndWorkflows.priority === 'high' ? ' [HIGH: Anthropic SDK markers detected]' : '';
|
|
54
|
+
lines.push(
|
|
55
|
+
` - [warn] Bundled skills/workflows enabled${prio} (~${c.bundledSkillsAndWorkflows.reclaimableTokensPerTurn} tok/turn est.)`
|
|
56
|
+
);
|
|
57
|
+
lines.push(` Fix: ${c.bundledSkillsAndWorkflows.fix}`);
|
|
58
|
+
} else {
|
|
59
|
+
lines.push(' - [pass] Repo-local Turn-0 focus (no unverified global settings keys recommended)');
|
|
60
|
+
}
|
|
61
|
+
if (c.subagentMcpInstructionsTax?.triggered) {
|
|
62
|
+
lines.push(
|
|
63
|
+
` - [warn] Subagent mcp_instructions_delta tax (#104791): ~${c.subagentMcpInstructionsTax.perSubagentTokensEst.toLocaleString('en-US')} tok/subagent across ${c.subagentMcpInstructionsTax.subagentCount} subagents (${c.subagentMcpInstructionsTax.connectedServerCount} servers)`
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
if (c.idleCompactionRoi?.status === 'warn' && c.idleCompactionRoi.coachingNote) {
|
|
67
|
+
lines.push(` - [warn] ${c.idleCompactionRoi.coachingNote}`);
|
|
68
|
+
} else if (c.idleCompactionRoi?.coachingMode === 'surgical_idle_disabled_overflow_protected') {
|
|
69
|
+
lines.push(` - [pass] ${c.idleCompactionRoi.coachingNote}`);
|
|
70
|
+
}
|
|
71
|
+
if (c.sdkCliQuotaHeuristic?.detected && c.sdkCliQuotaHeuristic.message) {
|
|
72
|
+
lines.push(` - [info] ${c.sdkCliQuotaHeuristic.message}`);
|
|
73
|
+
}
|
|
74
|
+
if (c.mcpProxyAndMetaTool?.coachingNote) {
|
|
75
|
+
lines.push(` - [${c.mcpProxyAndMetaTool.status}] ${c.mcpProxyAndMetaTool.coachingNote}`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (r) {
|
|
80
|
+
lines.push(
|
|
81
|
+
` - Rules [${r.status}]: ${r.files.length} file(s), ${r.totalRuleCount} discrete rules, ~${r.totalTokensEst.toLocaleString('en-US')} est. tokens`
|
|
82
|
+
);
|
|
83
|
+
for (const adv of r.advisories || []) {
|
|
84
|
+
lines.push(` Advisories: ${adv}`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (Array.isArray(report.lints) && report.lints.length > 0) {
|
|
89
|
+
lines.push(' Silent-Failure & Security Lints:');
|
|
90
|
+
for (const l of report.lints) {
|
|
91
|
+
lines.push(` - [${l.severity}] ${l.ruleId}: ${l.message}`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return lines.join('\n') + '\n';
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Formats `runAntigravityStartupAudit()` for terminal output.
|
|
101
|
+
*/
|
|
102
|
+
export function formatAntigravityStartupAuditReport(report) {
|
|
103
|
+
if (!report?.ok) return 'Burnoff Antigravity Startup Audit failed\n';
|
|
104
|
+
const s = report.summary || {};
|
|
105
|
+
const c = report.antigravity?.checks;
|
|
106
|
+
const r = report.rulesAudit?.byHarness?.antigravity;
|
|
107
|
+
const lines = [
|
|
108
|
+
`Burnoff Antigravity Turn-0 Startup Audit | Findings: ${s.issueCount ?? 0} | Reclaimable: ~${Number(s.estimatedTurn0ReclaimableTokens || 0).toLocaleString('en-US')} tok/turn (est.) (~$${Number(s.estimatedWeeklySavingsUsd || 0).toFixed(2)}/wk)`
|
|
109
|
+
];
|
|
110
|
+
if (c?.mcpCheck) {
|
|
111
|
+
lines.push(` - [${c.mcpCheck.status}] ${c.mcpCheck.summaryLine}`);
|
|
112
|
+
}
|
|
113
|
+
if (c?.mcpProxyAndMetaTool?.coachingNote) {
|
|
114
|
+
lines.push(` - [${c.mcpProxyAndMetaTool.status}] ${c.mcpProxyAndMetaTool.coachingNote}`);
|
|
115
|
+
}
|
|
116
|
+
if (r) {
|
|
117
|
+
lines.push(
|
|
118
|
+
` - Rules [${r.status}]: ${r.files.length} file(s), ${r.totalRuleCount} always-on rules (${r.onDemandCount} on-demand), ~${r.totalTokensEst.toLocaleString('en-US')} est. tokens`
|
|
119
|
+
);
|
|
120
|
+
for (const adv of r.advisories || []) {
|
|
121
|
+
lines.push(` Advisories: ${adv}`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (Array.isArray(report.lints) && report.lints.length > 0) {
|
|
125
|
+
lines.push(' JSON & Config Lints:');
|
|
126
|
+
for (const l of report.lints) {
|
|
127
|
+
lines.push(` - [${l.severity}] ${l.ruleId}: ${l.message}`);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return lines.join('\n') + '\n';
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Unified startup audit supporting `--client claude|antigravity|both|auto`.
|
|
135
|
+
*/
|
|
136
|
+
|
|
137
|
+
export function formatStartupAuditReport(report) {
|
|
138
|
+
if (report?.harnessesAudited?.length === 1 && report.harnessesAudited[0] === 'antigravity') {
|
|
139
|
+
return formatAntigravityStartupAuditReport(report);
|
|
140
|
+
}
|
|
141
|
+
if (report?.harnessesAudited?.includes('antigravity') && report?.claudeCode) {
|
|
142
|
+
const claudeSummary = report.summaryByHarness?.['claude-code'] || report.summary;
|
|
143
|
+
const agSummary = report.summaryByHarness?.antigravity || report.summary;
|
|
144
|
+
const claudeLints =
|
|
145
|
+
report.lintsByHarness?.['claude-code'] ||
|
|
146
|
+
(report.lints || []).filter((l) => !(l.file?.includes('.agents') || l.file?.includes('.gemini')));
|
|
147
|
+
const agLints =
|
|
148
|
+
report.lintsByHarness?.antigravity ||
|
|
149
|
+
(report.lints || []).filter((l) => l.file?.includes('.agents') || l.file?.includes('.gemini'));
|
|
150
|
+
return (
|
|
151
|
+
formatClaudeStartupAuditReport({
|
|
152
|
+
...report,
|
|
153
|
+
lints: claudeLints,
|
|
154
|
+
summary: claudeSummary
|
|
155
|
+
}) +
|
|
156
|
+
'\n' +
|
|
157
|
+
formatAntigravityStartupAuditReport({
|
|
158
|
+
ok: report.ok,
|
|
159
|
+
antigravity: report.antigravity,
|
|
160
|
+
rulesAudit: report.rulesAudit,
|
|
161
|
+
lints: agLints,
|
|
162
|
+
summary: agSummary
|
|
163
|
+
})
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
return formatClaudeStartupAuditReport(report);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function escapeGhAnnotationValue(text = '') {
|
|
170
|
+
return String(text || '')
|
|
171
|
+
.replace(/%/g, '%25')
|
|
172
|
+
.replace(/\r/g, '%0D')
|
|
173
|
+
.replace(/\n/g, '%0A');
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function toRepoRelativePath(filePath, cwd = process.cwd()) {
|
|
177
|
+
const raw = String(filePath || '').trim();
|
|
178
|
+
if (!raw) return '.';
|
|
179
|
+
if (!path.isAbsolute(raw)) return raw.replace(/\\/g, '/');
|
|
180
|
+
const resolvedCwd = path.resolve(cwd);
|
|
181
|
+
const rel = path.relative(resolvedCwd, path.resolve(raw));
|
|
182
|
+
if (rel && rel !== '..' && !rel.startsWith(`..${path.sep}`) && !path.isAbsolute(rel)) {
|
|
183
|
+
return rel.replace(/\\/g, '/');
|
|
184
|
+
}
|
|
185
|
+
return raw.replace(/\\/g, '/');
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Evaluates a `runStartupAudit({ ci: true })` report for CI pass/warn/fail exit codes
|
|
190
|
+
* and formats GitHub Actions `::error` / `::warning` workflow annotations.
|
|
191
|
+
*/
|
|
192
|
+
export function evaluateStartupAuditCi(report = {}, { strict = false, cwd = process.cwd() } = {}) {
|
|
193
|
+
const lints = Array.isArray(report?.lints) ? report.lints : [];
|
|
194
|
+
let errorCount = 0;
|
|
195
|
+
let warnCount = 0;
|
|
196
|
+
let infoCount = 0;
|
|
197
|
+
const annotations = [];
|
|
198
|
+
|
|
199
|
+
for (const l of lints) {
|
|
200
|
+
const sev = String(l?.severity || 'warn').toLowerCase();
|
|
201
|
+
const rel = toRepoRelativePath(l?.file || '.', cwd);
|
|
202
|
+
const ruleId = String(l?.ruleId || 'BO-CFG');
|
|
203
|
+
const msg = escapeGhAnnotationValue(l?.message || ruleId);
|
|
204
|
+
if (sev === 'error') {
|
|
205
|
+
errorCount += 1;
|
|
206
|
+
annotations.push(`::error file=${rel},title=${ruleId}::${msg}`);
|
|
207
|
+
} else if (sev === 'info') {
|
|
208
|
+
infoCount += 1;
|
|
209
|
+
} else {
|
|
210
|
+
warnCount += 1;
|
|
211
|
+
annotations.push(`::warning file=${rel},title=${ruleId}::${msg}`);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
for (const harnessKey of ['claudeCode', 'antigravity']) {
|
|
216
|
+
const bucket = report?.rulesAudit?.byHarness?.[harnessKey];
|
|
217
|
+
if (bucket && bucket.status === 'warn') {
|
|
218
|
+
warnCount += 1;
|
|
219
|
+
const firstFile = bucket.files?.[0]?.path || '.';
|
|
220
|
+
const rel = toRepoRelativePath(firstFile, cwd);
|
|
221
|
+
const adv = (bucket.advisories || []).join('; ') || 'Static Turn-0 rule threshold exceeded.';
|
|
222
|
+
annotations.push(`::warning file=${rel},title=BO-RULE-01::${escapeGhAnnotationValue(adv)}`);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const issueCount = Number(report?.summary?.issueCount || 0);
|
|
227
|
+
let verdict = 'PASS';
|
|
228
|
+
let exitCode = 0;
|
|
229
|
+
if (errorCount > 0 || (Boolean(strict) && (warnCount > 0 || issueCount > 0))) {
|
|
230
|
+
verdict = 'FAIL';
|
|
231
|
+
exitCode = 1;
|
|
232
|
+
} else if (warnCount > 0 || issueCount > 0) {
|
|
233
|
+
verdict = 'WARN';
|
|
234
|
+
exitCode = 0;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
return {
|
|
238
|
+
verdict,
|
|
239
|
+
exitCode,
|
|
240
|
+
strict: Boolean(strict),
|
|
241
|
+
repoOnly: true,
|
|
242
|
+
errorCount,
|
|
243
|
+
warnCount,
|
|
244
|
+
infoCount,
|
|
245
|
+
issueCount,
|
|
246
|
+
annotations
|
|
247
|
+
};
|
|
248
|
+
}
|