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,601 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file src/cli/startup-audit/jsonc.mjs
|
|
3
|
+
* JSONC syntax inspection, strict parser, CLI arg builders, and secret/path helpers.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import fs from 'node:fs';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import { resolveModelRateCard, SUBSCRIPTION_QUOTA_CONSTANTS } from '../../config/pricing.mjs';
|
|
9
|
+
|
|
10
|
+
export const CHARS_PER_TOKEN = 4;
|
|
11
|
+
|
|
12
|
+
export const VERIFIED_CLAUDE_FLAGS = Object.freeze([
|
|
13
|
+
'--chrome',
|
|
14
|
+
'--no-chrome',
|
|
15
|
+
'--disallowedTools',
|
|
16
|
+
'--settings',
|
|
17
|
+
'--mcp-config',
|
|
18
|
+
'--strict-mcp-config',
|
|
19
|
+
'--model'
|
|
20
|
+
]);
|
|
21
|
+
|
|
22
|
+
export const FORBIDDEN_WORKAROUND_FLAGS = Object.freeze(['--tools']);
|
|
23
|
+
|
|
24
|
+
const VERIFIED_SET = new Set(VERIFIED_CLAUDE_FLAGS);
|
|
25
|
+
const FORBIDDEN_SET = new Set(FORBIDDEN_WORKAROUND_FLAGS);
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Formats a JSON object as a shell-safe CLI argument for win32 PowerShell or POSIX shells.
|
|
29
|
+
*/
|
|
30
|
+
export function formatJsonCliArg(obj, platform = process.platform) {
|
|
31
|
+
const json = JSON.stringify(obj);
|
|
32
|
+
if (platform === 'win32') {
|
|
33
|
+
return `'${json.replace(/"/g, '\\"')}'`;
|
|
34
|
+
}
|
|
35
|
+
return `'${json.replace(/'/g, "'\\''")}'`;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Validates a `claude ...` command against verified flags, forbidden `--tools`, and zero em dashes.
|
|
40
|
+
*/
|
|
41
|
+
export function validateClaudeCliCommand(cmd) {
|
|
42
|
+
const str = String(cmd || '');
|
|
43
|
+
const hasEmDash = str.includes('\u2014');
|
|
44
|
+
const stripped = str
|
|
45
|
+
.replace(/'(?:\\.|[^'\\])*'/g, ' ')
|
|
46
|
+
.replace(/"(?:\\.|[^"\\])*"/g, ' ');
|
|
47
|
+
|
|
48
|
+
const flags = [];
|
|
49
|
+
const unverifiedFlags = [];
|
|
50
|
+
const forbiddenFlags = [];
|
|
51
|
+
|
|
52
|
+
for (const m of stripped.matchAll(/(?:^|\s)(--[A-Za-z0-9-]+)(?:=|\s|$)/g)) {
|
|
53
|
+
const flag = m[1];
|
|
54
|
+
flags.push(flag);
|
|
55
|
+
if (FORBIDDEN_SET.has(flag)) {
|
|
56
|
+
forbiddenFlags.push(flag);
|
|
57
|
+
} else if (!VERIFIED_SET.has(flag)) {
|
|
58
|
+
unverifiedFlags.push(flag);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return {
|
|
63
|
+
ok: unverifiedFlags.length === 0 && forbiddenFlags.length === 0 && !hasEmDash,
|
|
64
|
+
flags,
|
|
65
|
+
unverifiedFlags,
|
|
66
|
+
forbiddenFlags,
|
|
67
|
+
hasEmDash
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function buildClaudeCliCommand(parts = [], { platform = process.platform } = {}) {
|
|
72
|
+
const tokens = ['claude'];
|
|
73
|
+
for (const part of parts) {
|
|
74
|
+
if (part === null || part === undefined) continue;
|
|
75
|
+
if (typeof part === 'object' && !Array.isArray(part)) {
|
|
76
|
+
tokens.push(formatJsonCliArg(part, platform));
|
|
77
|
+
} else {
|
|
78
|
+
const s = String(part).trim();
|
|
79
|
+
if (!s) continue;
|
|
80
|
+
if (FORBIDDEN_SET.has(s)) {
|
|
81
|
+
throw new Error(`Forbidden Claude CLI flag "${s}" cannot be emitted in fix templates.`);
|
|
82
|
+
}
|
|
83
|
+
if (s.startsWith('--') && !VERIFIED_SET.has(s)) {
|
|
84
|
+
throw new Error(`Unverified Claude CLI flag "${s}" is not in VERIFIED_CLAUDE_FLAGS.`);
|
|
85
|
+
}
|
|
86
|
+
tokens.push(s);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
const cmd = tokens.join(' ');
|
|
90
|
+
const check = validateClaudeCliCommand(cmd);
|
|
91
|
+
if (!check.ok) {
|
|
92
|
+
throw new Error(`Invalid Claude CLI command: ${cmd}`);
|
|
93
|
+
}
|
|
94
|
+
return cmd;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Inspects raw JSON/JSONC text outside string literals to detect non-strict JSON syntax
|
|
99
|
+
* (`//` line comments, `/* ... *\/` block comments, or trailing commas).
|
|
100
|
+
*/
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Inspects raw JSON/JSONC text outside string literals to detect non-strict JSON syntax
|
|
104
|
+
* (`//` line comments, `/* ... *\/` block comments, or trailing commas).
|
|
105
|
+
*/
|
|
106
|
+
export function inspectJsoncSyntax(raw) {
|
|
107
|
+
const input = String(raw ?? '');
|
|
108
|
+
let out = '';
|
|
109
|
+
let inString = false;
|
|
110
|
+
let escaped = false;
|
|
111
|
+
let inLineComment = false;
|
|
112
|
+
let inBlockComment = false;
|
|
113
|
+
let hasLineComment = false;
|
|
114
|
+
let hasBlockComment = false;
|
|
115
|
+
let hasTrailingComma = false;
|
|
116
|
+
|
|
117
|
+
for (let i = 0; i < input.length; i++) {
|
|
118
|
+
const ch = input[i];
|
|
119
|
+
const next = input[i + 1];
|
|
120
|
+
|
|
121
|
+
if (inLineComment) {
|
|
122
|
+
if (ch === '\n' || ch === '\r') {
|
|
123
|
+
inLineComment = false;
|
|
124
|
+
out += ch;
|
|
125
|
+
}
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (inBlockComment) {
|
|
130
|
+
if (ch === '*' && next === '/') {
|
|
131
|
+
inBlockComment = false;
|
|
132
|
+
i += 1;
|
|
133
|
+
} else if (ch === '\n' || ch === '\r') {
|
|
134
|
+
out += ch;
|
|
135
|
+
}
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (inString) {
|
|
140
|
+
out += ch;
|
|
141
|
+
if (escaped) {
|
|
142
|
+
escaped = false;
|
|
143
|
+
} else if (ch === '\\') {
|
|
144
|
+
escaped = true;
|
|
145
|
+
} else if (ch === '"') {
|
|
146
|
+
inString = false;
|
|
147
|
+
}
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (ch === '"') {
|
|
152
|
+
inString = true;
|
|
153
|
+
out += ch;
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (ch === '/' && next === '/') {
|
|
158
|
+
hasLineComment = true;
|
|
159
|
+
inLineComment = true;
|
|
160
|
+
i += 1;
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (ch === '/' && next === '*') {
|
|
165
|
+
hasBlockComment = true;
|
|
166
|
+
inBlockComment = true;
|
|
167
|
+
i += 1;
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
out += ch;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
inString = false;
|
|
175
|
+
escaped = false;
|
|
176
|
+
for (let i = 0; i < out.length; i++) {
|
|
177
|
+
const ch = out[i];
|
|
178
|
+
if (inString) {
|
|
179
|
+
if (escaped) escaped = false;
|
|
180
|
+
else if (ch === '\\') escaped = true;
|
|
181
|
+
else if (ch === '"') inString = false;
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
if (ch === '"') {
|
|
185
|
+
inString = true;
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
if (ch === ',') {
|
|
189
|
+
let j = i + 1;
|
|
190
|
+
while (j < out.length && /\s/.test(out[j])) j++;
|
|
191
|
+
if (out[j] === '}' || out[j] === ']') {
|
|
192
|
+
hasTrailingComma = true;
|
|
193
|
+
break;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return {
|
|
199
|
+
hasLineComment,
|
|
200
|
+
hasBlockComment,
|
|
201
|
+
hasTrailingComma,
|
|
202
|
+
hasNonStrictSyntax: hasLineComment || hasBlockComment || hasTrailingComma
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Strips JSONC comments (`//` and `/* ... *\/`) and trailing commas outside strings.
|
|
208
|
+
*/
|
|
209
|
+
export function parseJsoncString(raw) {
|
|
210
|
+
const input = String(raw ?? '');
|
|
211
|
+
let out = '';
|
|
212
|
+
let inString = false;
|
|
213
|
+
let escaped = false;
|
|
214
|
+
let inLineComment = false;
|
|
215
|
+
let inBlockComment = false;
|
|
216
|
+
|
|
217
|
+
for (let i = 0; i < input.length; i++) {
|
|
218
|
+
const ch = input[i];
|
|
219
|
+
const next = input[i + 1];
|
|
220
|
+
|
|
221
|
+
if (inLineComment) {
|
|
222
|
+
if (ch === '\n' || ch === '\r') {
|
|
223
|
+
inLineComment = false;
|
|
224
|
+
out += ch;
|
|
225
|
+
}
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (inBlockComment) {
|
|
230
|
+
if (ch === '*' && next === '/') {
|
|
231
|
+
inBlockComment = false;
|
|
232
|
+
i += 1;
|
|
233
|
+
} else if (ch === '\n' || ch === '\r') {
|
|
234
|
+
out += ch;
|
|
235
|
+
}
|
|
236
|
+
continue;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
if (inString) {
|
|
240
|
+
out += ch;
|
|
241
|
+
if (escaped) {
|
|
242
|
+
escaped = false;
|
|
243
|
+
} else if (ch === '\\') {
|
|
244
|
+
escaped = true;
|
|
245
|
+
} else if (ch === '"') {
|
|
246
|
+
inString = false;
|
|
247
|
+
}
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
if (ch === '"') {
|
|
252
|
+
inString = true;
|
|
253
|
+
out += ch;
|
|
254
|
+
continue;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
if (ch === '/' && next === '/') {
|
|
258
|
+
inLineComment = true;
|
|
259
|
+
i += 1;
|
|
260
|
+
continue;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
if (ch === '/' && next === '*') {
|
|
264
|
+
inBlockComment = true;
|
|
265
|
+
i += 1;
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
out += ch;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
let cleaned = '';
|
|
273
|
+
inString = false;
|
|
274
|
+
escaped = false;
|
|
275
|
+
for (let i = 0; i < out.length; i++) {
|
|
276
|
+
const ch = out[i];
|
|
277
|
+
if (inString) {
|
|
278
|
+
cleaned += ch;
|
|
279
|
+
if (escaped) escaped = false;
|
|
280
|
+
else if (ch === '\\') escaped = true;
|
|
281
|
+
else if (ch === '"') inString = false;
|
|
282
|
+
continue;
|
|
283
|
+
}
|
|
284
|
+
if (ch === '"') {
|
|
285
|
+
inString = true;
|
|
286
|
+
cleaned += ch;
|
|
287
|
+
continue;
|
|
288
|
+
}
|
|
289
|
+
if (ch === ',') {
|
|
290
|
+
let j = i + 1;
|
|
291
|
+
while (j < out.length && /\s/.test(out[j])) j++;
|
|
292
|
+
if (out[j] === '}' || out[j] === ']') {
|
|
293
|
+
continue;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
cleaned += ch;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
return JSON.parse(cleaned);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Reads and parses a JSON/JSONC file strictly read-only without throwing.
|
|
304
|
+
*/
|
|
305
|
+
export function parseJsoncReadOnly(filePath) {
|
|
306
|
+
if (!filePath || !fs.existsSync(filePath)) {
|
|
307
|
+
return {
|
|
308
|
+
path: filePath || '',
|
|
309
|
+
exists: false,
|
|
310
|
+
parseOk: false,
|
|
311
|
+
parsed: null,
|
|
312
|
+
strictJsonValid: false,
|
|
313
|
+
strict_json_syntax_warning: null,
|
|
314
|
+
error: null
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
try {
|
|
318
|
+
const raw = fs.readFileSync(filePath, 'utf8');
|
|
319
|
+
if (!raw || !raw.trim()) {
|
|
320
|
+
return {
|
|
321
|
+
path: filePath,
|
|
322
|
+
exists: true,
|
|
323
|
+
parseOk: false,
|
|
324
|
+
parsed: null,
|
|
325
|
+
strictJsonValid: false,
|
|
326
|
+
strict_json_syntax_warning: null,
|
|
327
|
+
error: 'empty file'
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
const parsed = parseJsoncString(raw);
|
|
331
|
+
const syntax = inspectJsoncSyntax(raw);
|
|
332
|
+
const displayPath = String(filePath).replace(/\\/g, '/');
|
|
333
|
+
const strictJsonValid = !syntax.hasNonStrictSyntax;
|
|
334
|
+
const strict_json_syntax_warning = syntax.hasNonStrictSyntax
|
|
335
|
+
? `Strict JSON warning: comments or trailing commas in ${displayPath} fail harnesses using strict JSON.parse(). Strip comments for cross-tool portability.`
|
|
336
|
+
: null;
|
|
337
|
+
return {
|
|
338
|
+
path: filePath,
|
|
339
|
+
exists: true,
|
|
340
|
+
parseOk: true,
|
|
341
|
+
parsed,
|
|
342
|
+
strictJsonValid,
|
|
343
|
+
strict_json_syntax_warning,
|
|
344
|
+
error: null
|
|
345
|
+
};
|
|
346
|
+
} catch (err) {
|
|
347
|
+
return {
|
|
348
|
+
path: filePath,
|
|
349
|
+
exists: true,
|
|
350
|
+
parseOk: false,
|
|
351
|
+
parsed: null,
|
|
352
|
+
strictJsonValid: false,
|
|
353
|
+
strict_json_syntax_warning: null,
|
|
354
|
+
error: err?.message || 'parse error'
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* Counts discrete imperative bullets and numbered rules in markdown, ignoring fenced code blocks
|
|
361
|
+
* and markdown table separator rows.
|
|
362
|
+
*/
|
|
363
|
+
|
|
364
|
+
function estimateWeeklySavingsUsd(turn0ReclaimableTokens, nowMs) {
|
|
365
|
+
if (!turn0ReclaimableTokens || turn0ReclaimableTokens <= 0) return 0;
|
|
366
|
+
const rateCard = resolveModelRateCard({
|
|
367
|
+
model: 'claude-sonnet-5-5',
|
|
368
|
+
timestampMs: nowMs
|
|
369
|
+
});
|
|
370
|
+
const inputPer1M = Number(rateCard?.inputPer1M || 2.0);
|
|
371
|
+
const cachedWeight = Number(rateCard?.cachedReadWeight || 0.05);
|
|
372
|
+
const uncachedEquivUnits = turn0ReclaimableTokens * (10 + 500 * cachedWeight);
|
|
373
|
+
return Number(((uncachedEquivUnits / 1_000_000) * inputPer1M).toFixed(2));
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
function formatConfigStatus(res) {
|
|
377
|
+
return {
|
|
378
|
+
path: String(res.path || '').replace(/\\/g, '/'),
|
|
379
|
+
exists: Boolean(res.exists),
|
|
380
|
+
parseOk: Boolean(res.parseOk),
|
|
381
|
+
strictJsonValid: Boolean(res.strictJsonValid),
|
|
382
|
+
strict_json_syntax_warning: res.strict_json_syntax_warning || null
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
const SECRET_ALLOW_PATTERNS = Object.freeze([
|
|
387
|
+
{ name: 'password_flag', regex: /--password(?:=|\s+)([^\s]+)/i, captureGroup: 1 },
|
|
388
|
+
{ name: 'bearer_token', regex: /\bBearer\s+([A-Za-z0-9._-]{8,})/i, captureGroup: 1 },
|
|
389
|
+
{ name: 'api_key_sk', regex: /\b(sk-[A-Za-z0-9_-]{12,})\b/, captureGroup: 1 },
|
|
390
|
+
{ name: 'google_api_key', regex: /\b(AIza[0-9A-Za-z_-]{20,})\b/, captureGroup: 1 },
|
|
391
|
+
{ name: 'github_pat', regex: /\b((?:ghp_|gho_|github_pat_)[A-Za-z0-9_]{16,})\b/, captureGroup: 1 },
|
|
392
|
+
{ name: 'url_credentials', regex: /[a-z][a-z0-9+.-]*:\/\/[^:\s/]+:([^@\s/]+)@/i, captureGroup: 1 }
|
|
393
|
+
]);
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
function isPlaceholderSecretValue(val) {
|
|
397
|
+
const s = String(val || '').trim();
|
|
398
|
+
if (!s) return true;
|
|
399
|
+
if (/^\$\{?[A-Za-z_][A-Za-z0-9_]*\}?$/.test(s)) return true;
|
|
400
|
+
if (/^<[A-Za-z0-9_-]+>$/.test(s)) return true;
|
|
401
|
+
if (/^\*{3,}$/.test(s)) return true;
|
|
402
|
+
return false;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
function collectStrictJsonLints(entries = [], { harness = 'claude-code' } = {}) {
|
|
406
|
+
const warnings = [];
|
|
407
|
+
const lints = [];
|
|
408
|
+
for (const entry of entries) {
|
|
409
|
+
const res = entry?.res;
|
|
410
|
+
if (!res?.exists || !res?.parseOk || !res?.strict_json_syntax_warning) continue;
|
|
411
|
+
const file = String(res.path || '').replace(/\\/g, '/');
|
|
412
|
+
warnings.push({ file, warning: res.strict_json_syntax_warning });
|
|
413
|
+
lints.push({
|
|
414
|
+
ruleId: 'BO-CFG-01',
|
|
415
|
+
severity: 'warn',
|
|
416
|
+
harness,
|
|
417
|
+
file,
|
|
418
|
+
message: res.strict_json_syntax_warning,
|
|
419
|
+
remediation: res.strict_json_syntax_warning
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
return {
|
|
423
|
+
status: warnings.length > 0 ? 'warn' : 'pass',
|
|
424
|
+
warnings,
|
|
425
|
+
lints
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
function auditMisplacedChromeKey(settingsEntries = []) {
|
|
430
|
+
const misplaced = [];
|
|
431
|
+
const lints = [];
|
|
432
|
+
for (const entry of settingsEntries) {
|
|
433
|
+
const doc = entry?.doc;
|
|
434
|
+
if (!doc?.parseOk || !doc.parsed || typeof doc.parsed !== 'object') continue;
|
|
435
|
+
if (!Object.prototype.hasOwnProperty.call(doc.parsed, 'claudeInChromeDefaultEnabled')) continue;
|
|
436
|
+
const file = String(doc.path || '').replace(/\\/g, '/');
|
|
437
|
+
const label = entry.label || file;
|
|
438
|
+
misplaced.push({ file, label });
|
|
439
|
+
lints.push({
|
|
440
|
+
ruleId: 'BO-CFG-02',
|
|
441
|
+
severity: 'warn',
|
|
442
|
+
harness: 'claude-code',
|
|
443
|
+
file,
|
|
444
|
+
message: `Misplaced key: claudeInChromeDefaultEnabled in ${label} is ignored by Claude Code. Move to ~/.claude.json or launch with --no-chrome.`,
|
|
445
|
+
remediation: 'Move claudeInChromeDefaultEnabled to ~/.claude.json or launch with --no-chrome.'
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
return {
|
|
449
|
+
status: misplaced.length > 0 ? 'warn' : 'pass',
|
|
450
|
+
misplacedFiles: misplaced.map((x) => x.file),
|
|
451
|
+
lints
|
|
452
|
+
};
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
function resolveGitDir(cwd) {
|
|
456
|
+
const repoDir = path.resolve(cwd || process.cwd());
|
|
457
|
+
const dotGit = path.join(repoDir, '.git');
|
|
458
|
+
if (!fs.existsSync(dotGit)) return null;
|
|
459
|
+
try {
|
|
460
|
+
const st = fs.statSync(dotGit);
|
|
461
|
+
if (st.isDirectory()) return dotGit;
|
|
462
|
+
if (st.isFile()) {
|
|
463
|
+
const m = fs.readFileSync(dotGit, 'utf8').match(/^gitdir:\s*(.+)$/im);
|
|
464
|
+
if (m && m[1]) {
|
|
465
|
+
const target = m[1].trim();
|
|
466
|
+
return path.isAbsolute(target) ? target : path.resolve(repoDir, target);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
} catch {
|
|
470
|
+
// ignore: unreadable .git pointer falls back to .gitignore check only
|
|
471
|
+
}
|
|
472
|
+
return null;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
function hasSettingsLocalIgnoreEntry(ignoreFilePath) {
|
|
476
|
+
if (!ignoreFilePath || !fs.existsSync(ignoreFilePath)) return false;
|
|
477
|
+
let raw = '';
|
|
478
|
+
try {
|
|
479
|
+
raw = fs.readFileSync(ignoreFilePath, 'utf8');
|
|
480
|
+
} catch {
|
|
481
|
+
return false; // ignore: unreadable ignore file
|
|
482
|
+
}
|
|
483
|
+
for (const rawLine of raw.split(/\r?\n/)) {
|
|
484
|
+
const line = rawLine.trim();
|
|
485
|
+
if (!line || line.startsWith('#') || line.startsWith('!')) continue;
|
|
486
|
+
const norm = line.replace(/^\/+/, '').replace(/\/+$/, '');
|
|
487
|
+
if (
|
|
488
|
+
norm === 'settings.local.json' ||
|
|
489
|
+
norm === '.claude/settings.local.json' ||
|
|
490
|
+
norm === '.claude/*.local.json' ||
|
|
491
|
+
norm === '*.local.json' ||
|
|
492
|
+
norm === '.claude' ||
|
|
493
|
+
norm === '.claude/*' ||
|
|
494
|
+
norm === '**/.claude/settings.local.json' ||
|
|
495
|
+
norm === '**/settings.local.json'
|
|
496
|
+
) {
|
|
497
|
+
return true;
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
return false;
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
function isSettingsLocalGitignored(cwd) {
|
|
504
|
+
if (hasSettingsLocalIgnoreEntry(path.join(cwd, '.gitignore'))) return true;
|
|
505
|
+
const gitDir = resolveGitDir(cwd);
|
|
506
|
+
if (gitDir && hasSettingsLocalIgnoreEntry(path.join(gitDir, 'info', 'exclude'))) {
|
|
507
|
+
return true;
|
|
508
|
+
}
|
|
509
|
+
return false;
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
function auditLocalSettingsSecrets(projectLocalSettings, cwd) {
|
|
513
|
+
const allowRules = Array.isArray(projectLocalSettings?.parsed?.permissions?.allow)
|
|
514
|
+
? projectLocalSettings.parsed.permissions.allow
|
|
515
|
+
: [];
|
|
516
|
+
const matches = [];
|
|
517
|
+
|
|
518
|
+
for (let i = 0; i < allowRules.length; i++) {
|
|
519
|
+
const rule = allowRules[i];
|
|
520
|
+
if (typeof rule !== 'string' || !rule) continue;
|
|
521
|
+
for (const pat of SECRET_ALLOW_PATTERNS) {
|
|
522
|
+
const m = rule.match(pat.regex);
|
|
523
|
+
if (!m) continue;
|
|
524
|
+
const captured = m[pat.captureGroup] || '';
|
|
525
|
+
if (isPlaceholderSecretValue(captured)) continue;
|
|
526
|
+
matches.push({
|
|
527
|
+
ruleIndex: i,
|
|
528
|
+
patternName: pat.name,
|
|
529
|
+
preview: '[redacted]'
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
const gitignored = isSettingsLocalGitignored(cwd);
|
|
535
|
+
const missingGitignore = Boolean(projectLocalSettings?.exists && allowRules.length > 0 && !gitignored);
|
|
536
|
+
const status = matches.length > 0 || missingGitignore ? 'warn' : 'pass';
|
|
537
|
+
const file = String(projectLocalSettings?.path || path.join(cwd, '.claude', 'settings.local.json')).replace(/\\/g, '/');
|
|
538
|
+
|
|
539
|
+
const lints = [];
|
|
540
|
+
if (status === 'warn') {
|
|
541
|
+
const message =
|
|
542
|
+
matches.length > 0
|
|
543
|
+
? `Credential Leak Risk in settings.local.json: Literal command allow-rules contain ${matches.length} credential pattern(s) [redacted]${!gitignored ? ' and file is missing from .gitignore or .git/info/exclude' : ''}. Replace inline secrets with env vars.`
|
|
544
|
+
: `Unignored settings.local.json: .claude/settings.local.json defines ${allowRules.length} permissions.allow rule(s) and is missing from .gitignore and .git/info/exclude. Add it so local approvals are never committed.`;
|
|
545
|
+
lints.push({
|
|
546
|
+
ruleId: 'BO-SEC-08',
|
|
547
|
+
severity: 'warn',
|
|
548
|
+
harness: 'claude-code',
|
|
549
|
+
file,
|
|
550
|
+
message,
|
|
551
|
+
remediation:
|
|
552
|
+
matches.length > 0
|
|
553
|
+
? 'Remove inline secrets from .claude/settings.local.json permissions.allow, use env vars, and exclude .claude/settings.local.json in .gitignore or .git/info/exclude.'
|
|
554
|
+
: 'Run `burnoff init` or add .claude/settings.local.json to .gitignore or .git/info/exclude.'
|
|
555
|
+
});
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
return {
|
|
559
|
+
status,
|
|
560
|
+
fileExists: Boolean(projectLocalSettings?.exists),
|
|
561
|
+
allowRuleCount: allowRules.length,
|
|
562
|
+
secretMatchCount: matches.length,
|
|
563
|
+
matches,
|
|
564
|
+
gitignored,
|
|
565
|
+
lints
|
|
566
|
+
};
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
|
|
570
|
+
function makeMissingJsoncStub(filePath = '') {
|
|
571
|
+
return {
|
|
572
|
+
path: filePath,
|
|
573
|
+
exists: false,
|
|
574
|
+
parseOk: false,
|
|
575
|
+
parsed: null,
|
|
576
|
+
strictJsonValid: false,
|
|
577
|
+
strict_json_syntax_warning: null,
|
|
578
|
+
error: null
|
|
579
|
+
};
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
function filterFilesWithinCwd(filePaths = [], cwd = process.cwd()) {
|
|
583
|
+
const resolvedCwd = path.resolve(cwd);
|
|
584
|
+
return (Array.isArray(filePaths) ? filePaths : []).filter((fp) => {
|
|
585
|
+
if (!fp) return false;
|
|
586
|
+
const rel = path.relative(resolvedCwd, path.resolve(fp));
|
|
587
|
+
return rel !== '..' && !rel.startsWith(`..${path.sep}`) && !path.isAbsolute(rel);
|
|
588
|
+
});
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
|
|
592
|
+
export {
|
|
593
|
+
buildClaudeCliCommand,
|
|
594
|
+
estimateWeeklySavingsUsd,
|
|
595
|
+
formatConfigStatus,
|
|
596
|
+
collectStrictJsonLints,
|
|
597
|
+
auditMisplacedChromeKey,
|
|
598
|
+
auditLocalSettingsSecrets,
|
|
599
|
+
makeMissingJsoncStub,
|
|
600
|
+
filterFilesWithinCwd
|
|
601
|
+
};
|