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,975 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file src/cli/startup-audit/telemetry-scan.mjs
|
|
3
|
+
* Bounded JSONL telemetry scanning, custom agent inspection, idle compaction, and retired-model checks.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import fs from 'node:fs';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import { StringDecoder } from 'node:string_decoder';
|
|
9
|
+
import { compareSemver } from '../../config/semver.mjs';
|
|
10
|
+
import { getHomeDir, canonicalizePath } from '../../config/paths.mjs';
|
|
11
|
+
import { parseJsoncReadOnly } from './jsonc.mjs';
|
|
12
|
+
import { parseSkillFrontmatter, listMarkdownFilesInDir } from './rules-hygiene.mjs';
|
|
13
|
+
|
|
14
|
+
export const IDLE_COMPACTION_MIN_VERSION = '2.1.290';
|
|
15
|
+
export const DEFAULT_IDLE_COMPACT_MIN_TOKENS = 200000;
|
|
16
|
+
|
|
17
|
+
function collectJsonlFiles(rootDir, cutoffMs) {
|
|
18
|
+
const out = [];
|
|
19
|
+
if (!rootDir || !fs.existsSync(rootDir)) return out;
|
|
20
|
+
const walk = (dir) => {
|
|
21
|
+
let entries = [];
|
|
22
|
+
try {
|
|
23
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
24
|
+
} catch {
|
|
25
|
+
return; // ignore: unreadable projects subdirectory
|
|
26
|
+
}
|
|
27
|
+
for (const ent of entries) {
|
|
28
|
+
const full = path.join(dir, ent.name);
|
|
29
|
+
if (ent.isDirectory()) {
|
|
30
|
+
walk(full);
|
|
31
|
+
} else if (ent.isFile() && ent.name.endsWith('.jsonl')) {
|
|
32
|
+
try {
|
|
33
|
+
const st = fs.statSync(full);
|
|
34
|
+
if (!cutoffMs || st.mtimeMs >= cutoffMs) {
|
|
35
|
+
out.push({ path: full, mtimeMs: st.mtimeMs });
|
|
36
|
+
}
|
|
37
|
+
} catch {
|
|
38
|
+
// ignore: unreadable JSONL stat
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
walk(rootDir);
|
|
44
|
+
out.sort((a, b) => b.mtimeMs - a.mtimeMs);
|
|
45
|
+
return out;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export const DEFAULT_TELEMETRY_MAX_FILES = 50;
|
|
49
|
+
export const DEFAULT_TELEMETRY_MAX_BYTES = 16 * 1024 * 1024;
|
|
50
|
+
const TELEMETRY_READ_CHUNK_BYTES = 64 * 1024;
|
|
51
|
+
|
|
52
|
+
function scanJsonlFileChunked(filePath, { maxBytesRemaining = Infinity, onLine } = {}) {
|
|
53
|
+
let fd = null;
|
|
54
|
+
let bytesRead = 0;
|
|
55
|
+
let truncated = false;
|
|
56
|
+
const decoder = new StringDecoder('utf8');
|
|
57
|
+
let carry = '';
|
|
58
|
+
try {
|
|
59
|
+
fd = fs.openSync(filePath, 'r');
|
|
60
|
+
const buf = Buffer.allocUnsafe(TELEMETRY_READ_CHUNK_BYTES);
|
|
61
|
+
while (bytesRead < maxBytesRemaining) {
|
|
62
|
+
const toRead = Math.min(TELEMETRY_READ_CHUNK_BYTES, Math.max(0, maxBytesRemaining - bytesRead));
|
|
63
|
+
if (toRead <= 0) {
|
|
64
|
+
truncated = true;
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
const n = fs.readSync(fd, buf, 0, toRead, null);
|
|
68
|
+
if (n <= 0) break;
|
|
69
|
+
bytesRead += n;
|
|
70
|
+
const chunkText = carry + decoder.write(buf.subarray(0, n));
|
|
71
|
+
const parts = chunkText.split(/\r?\n/);
|
|
72
|
+
carry = parts.pop() || '';
|
|
73
|
+
for (const line of parts) {
|
|
74
|
+
if (line.trim()) onLine(line);
|
|
75
|
+
}
|
|
76
|
+
if (bytesRead >= maxBytesRemaining) {
|
|
77
|
+
truncated = true;
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (!truncated) {
|
|
82
|
+
const tail = carry + decoder.end();
|
|
83
|
+
if (tail.trim()) onLine(tail);
|
|
84
|
+
}
|
|
85
|
+
} catch {
|
|
86
|
+
// ignore: unreadable JSONL transcript
|
|
87
|
+
} finally {
|
|
88
|
+
if (fd !== null) {
|
|
89
|
+
try {
|
|
90
|
+
fs.closeSync(fd);
|
|
91
|
+
} catch {
|
|
92
|
+
// ignore: fd close cleanup
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return { bytesRead, truncated };
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function scanClaudeTelemetrySummary({
|
|
100
|
+
projectsDir,
|
|
101
|
+
days = 7,
|
|
102
|
+
nowMs = Date.now(),
|
|
103
|
+
maxFiles = DEFAULT_TELEMETRY_MAX_FILES,
|
|
104
|
+
maxTotalBytes = DEFAULT_TELEMETRY_MAX_BYTES
|
|
105
|
+
} = {}) {
|
|
106
|
+
const cutoffMs = days > 0 ? nowMs - days * 86_400_000 : 0;
|
|
107
|
+
const files = collectJsonlFiles(projectsDir, cutoffMs);
|
|
108
|
+
const fileCap = Math.max(1, Number(maxFiles) || DEFAULT_TELEMETRY_MAX_FILES);
|
|
109
|
+
const byteCap = Math.max(1024, Number(maxTotalBytes) || DEFAULT_TELEMETRY_MAX_BYTES);
|
|
110
|
+
const filesToScan = files.slice(0, fileCap);
|
|
111
|
+
let scanTruncated = files.length > filesToScan.length;
|
|
112
|
+
let bytesScanned = 0;
|
|
113
|
+
let sessionsScanned = 0;
|
|
114
|
+
|
|
115
|
+
let latestVersion = null;
|
|
116
|
+
let latestVersionMtime = -1;
|
|
117
|
+
const entrypoints = new Set();
|
|
118
|
+
let browserToolCalls7d = 0;
|
|
119
|
+
let artifactCalls7d = 0;
|
|
120
|
+
const mcpToolCalls7d = {};
|
|
121
|
+
const schemaTokensByServer = {};
|
|
122
|
+
const observedMcpToolNames = new Set();
|
|
123
|
+
let maxCachedPrefixTokens = null;
|
|
124
|
+
const runtimeListChangedServers = new Set();
|
|
125
|
+
let subagentSpawns7d = 0;
|
|
126
|
+
let sidechainTurns7d = 0;
|
|
127
|
+
let observedMcpInstructionsDeltaChars = 0;
|
|
128
|
+
const observedModels = new Set();
|
|
129
|
+
let sdkCliSessions7d = 0;
|
|
130
|
+
|
|
131
|
+
for (const fileInfo of filesToScan) {
|
|
132
|
+
if (bytesScanned >= byteCap) {
|
|
133
|
+
scanTruncated = true;
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
let fileHasSdkCli = false;
|
|
137
|
+
const res = scanJsonlFileChunked(fileInfo.path, {
|
|
138
|
+
maxBytesRemaining: byteCap - bytesScanned,
|
|
139
|
+
onLine: (line) => {
|
|
140
|
+
let row;
|
|
141
|
+
try {
|
|
142
|
+
row = JSON.parse(line);
|
|
143
|
+
} catch {
|
|
144
|
+
return; // ignore: partial trailing JSONL line
|
|
145
|
+
}
|
|
146
|
+
if (row.version && fileInfo.mtimeMs >= latestVersionMtime) {
|
|
147
|
+
latestVersion = String(row.version).trim();
|
|
148
|
+
latestVersionMtime = fileInfo.mtimeMs;
|
|
149
|
+
}
|
|
150
|
+
if (row.entrypoint) {
|
|
151
|
+
const ep = String(row.entrypoint).trim();
|
|
152
|
+
entrypoints.add(ep);
|
|
153
|
+
if (ep === 'sdk-cli') fileHasSdkCli = true;
|
|
154
|
+
}
|
|
155
|
+
if (row.isSidechain === true) {
|
|
156
|
+
sidechainTurns7d += 1;
|
|
157
|
+
}
|
|
158
|
+
if (row.type === 'assistant') {
|
|
159
|
+
if (row.message?.model) {
|
|
160
|
+
observedModels.add(String(row.message.model).trim());
|
|
161
|
+
}
|
|
162
|
+
const u = row.message?.usage;
|
|
163
|
+
if (
|
|
164
|
+
u &&
|
|
165
|
+
typeof u === 'object' &&
|
|
166
|
+
(u.cache_read_input_tokens !== undefined || u.cache_creation_input_tokens !== undefined)
|
|
167
|
+
) {
|
|
168
|
+
const prefixTok = Number(u.cache_read_input_tokens || 0) + Number(u.cache_creation_input_tokens || 0);
|
|
169
|
+
if (Number.isFinite(prefixTok) && prefixTok >= 0) {
|
|
170
|
+
maxCachedPrefixTokens = maxCachedPrefixTokens === null ? prefixTok : Math.max(maxCachedPrefixTokens, prefixTok);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
if (Array.isArray(row.message?.content)) {
|
|
174
|
+
for (const blk of row.message.content) {
|
|
175
|
+
if (blk?.type !== 'tool_use' || !blk.name) continue;
|
|
176
|
+
const toolName = String(blk.name);
|
|
177
|
+
if (toolName === 'Artifact') artifactCalls7d += 1;
|
|
178
|
+
if (toolName === 'Agent' || toolName === 'Task' || toolName === 'invoke_subagent') {
|
|
179
|
+
subagentSpawns7d += 1;
|
|
180
|
+
}
|
|
181
|
+
if (/^mcp__claude-in-chrome__/i.test(toolName) || /(?:^|__)chrome(?:__|$)/i.test(toolName)) {
|
|
182
|
+
browserToolCalls7d += 1;
|
|
183
|
+
}
|
|
184
|
+
if (toolName.startsWith('mcp__')) {
|
|
185
|
+
observedMcpToolNames.add(toolName);
|
|
186
|
+
}
|
|
187
|
+
const mcpMatch = toolName.match(/^mcp__([^_]+)__/);
|
|
188
|
+
if (mcpMatch) {
|
|
189
|
+
const srv = mcpMatch[1];
|
|
190
|
+
mcpToolCalls7d[srv] = (mcpToolCalls7d[srv] || 0) + 1;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
const sysText =
|
|
196
|
+
typeof row.text === 'string'
|
|
197
|
+
? row.text
|
|
198
|
+
: typeof row.content === 'string'
|
|
199
|
+
? row.content
|
|
200
|
+
: typeof row.attachment?.text === 'string'
|
|
201
|
+
? row.attachment.text
|
|
202
|
+
: typeof row.attachment?.content === 'string'
|
|
203
|
+
? row.attachment.content
|
|
204
|
+
: '';
|
|
205
|
+
if (
|
|
206
|
+
row.method === 'notifications/tools/list_changed' ||
|
|
207
|
+
row.subtype === 'mcp_tools_list_changed' ||
|
|
208
|
+
((row.type === 'system' || row.type === 'attachment') && sysText.includes('notifications/tools/list_changed'))
|
|
209
|
+
) {
|
|
210
|
+
const srvName = String(row.server || row.serverName || row.params?.server || 'unknown').trim() || 'unknown';
|
|
211
|
+
runtimeListChangedServers.add(srvName);
|
|
212
|
+
}
|
|
213
|
+
if (
|
|
214
|
+
(row.type === 'attachment' && row.attachment?.type === 'mcp_instructions_delta') ||
|
|
215
|
+
row.subtype === 'mcp_instructions_delta'
|
|
216
|
+
) {
|
|
217
|
+
const payload = row.attachment?.content ?? row.attachment?.text ?? row.content ?? row.text ?? row.attachment ?? row;
|
|
218
|
+
const charLen = typeof payload === 'string' ? payload.length : JSON.stringify(payload || '').length;
|
|
219
|
+
if (charLen > observedMcpInstructionsDeltaChars) {
|
|
220
|
+
observedMcpInstructionsDeltaChars = charLen;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
if (row.type === 'tools-used') {
|
|
224
|
+
if (Array.isArray(row.tools)) {
|
|
225
|
+
for (const t of row.tools) {
|
|
226
|
+
const name = typeof t === 'string' ? t : t && typeof t === 'object' ? t.name : null;
|
|
227
|
+
if (typeof name === 'string' && name.startsWith('mcp__')) {
|
|
228
|
+
observedMcpToolNames.add(name);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
if (row.serverSchemas && typeof row.serverSchemas === 'object') {
|
|
233
|
+
for (const [srv, tok] of Object.entries(row.serverSchemas)) {
|
|
234
|
+
const n = Number(tok);
|
|
235
|
+
if (Number.isFinite(n) && n > 0) schemaTokensByServer[srv] = n;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
sessionsScanned += 1;
|
|
242
|
+
bytesScanned += res.bytesRead;
|
|
243
|
+
if (res.truncated) scanTruncated = true;
|
|
244
|
+
if (fileHasSdkCli) sdkCliSessions7d += 1;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
return {
|
|
248
|
+
sessionsScanned,
|
|
249
|
+
bytesScanned,
|
|
250
|
+
scanTruncated,
|
|
251
|
+
claudeCodeVersion: latestVersion,
|
|
252
|
+
entrypoints: Array.from(entrypoints),
|
|
253
|
+
browserToolCalls7d,
|
|
254
|
+
artifactCalls7d,
|
|
255
|
+
mcpToolCalls7d,
|
|
256
|
+
schemaTokensByServer,
|
|
257
|
+
observedMcpToolNames: Array.from(observedMcpToolNames),
|
|
258
|
+
maxCachedPrefixTokens,
|
|
259
|
+
runtimeListChangedServers: Array.from(runtimeListChangedServers),
|
|
260
|
+
subagentSpawns7d,
|
|
261
|
+
sidechainTurns7d,
|
|
262
|
+
observedMcpInstructionsDeltaChars,
|
|
263
|
+
observedModels: Array.from(observedModels),
|
|
264
|
+
sdkCliSessions7d
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Strictly read-only scan of `~/.claude/agents/*.md` and `<cwd>/.claude/agents/*.md`
|
|
270
|
+
* to count custom subagent definitions and narrow frontmatter `tools:` allowlists.
|
|
271
|
+
*/
|
|
272
|
+
export function scanClaudeCustomAgentSpecs({ homeDir = getHomeDir(), cwd = process.cwd(), repoOnly = false } = {}) {
|
|
273
|
+
const dirs = repoOnly
|
|
274
|
+
? [path.join(cwd, '.claude', 'agents')]
|
|
275
|
+
: [path.join(homeDir, '.claude', 'agents'), path.join(cwd, '.claude', 'agents')];
|
|
276
|
+
const seen = new Set();
|
|
277
|
+
const agents = [];
|
|
278
|
+
let narrowToolsAgents = 0;
|
|
279
|
+
|
|
280
|
+
for (const dir of dirs) {
|
|
281
|
+
if (!fs.existsSync(dir)) continue;
|
|
282
|
+
let entries = [];
|
|
283
|
+
try {
|
|
284
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
285
|
+
} catch {
|
|
286
|
+
continue; // ignore: unreadable Claude agents directory
|
|
287
|
+
}
|
|
288
|
+
for (const ent of entries) {
|
|
289
|
+
if (!ent.isFile() || !/\.md$/i.test(ent.name)) continue;
|
|
290
|
+
const fullPath = path.join(dir, ent.name);
|
|
291
|
+
let key = canonicalizePath(fullPath);
|
|
292
|
+
try {
|
|
293
|
+
key = canonicalizePath(fs.realpathSync(fullPath));
|
|
294
|
+
} catch {
|
|
295
|
+
// ignore: fallback to canonicalized path when realpath fails
|
|
296
|
+
}
|
|
297
|
+
if (seen.has(key)) continue;
|
|
298
|
+
seen.add(key);
|
|
299
|
+
|
|
300
|
+
let hasNarrowTools = false;
|
|
301
|
+
let omitClaudeMd = false;
|
|
302
|
+
let agentName = ent.name.replace(/\.md$/i, '');
|
|
303
|
+
let description = '';
|
|
304
|
+
try {
|
|
305
|
+
const raw = fs.readFileSync(fullPath, 'utf8');
|
|
306
|
+
const fm = parseSkillFrontmatter(raw);
|
|
307
|
+
if (fm.name) agentName = fm.name;
|
|
308
|
+
if (fm.description) description = fm.description;
|
|
309
|
+
const fmMatch = raw.match(/^---\r?\n([\s\S]*?)\r?\n---/);
|
|
310
|
+
if (fmMatch) {
|
|
311
|
+
if (/(?:^|\r?\n)tools\s*:/i.test(fmMatch[1])) {
|
|
312
|
+
hasNarrowTools = true;
|
|
313
|
+
narrowToolsAgents += 1;
|
|
314
|
+
}
|
|
315
|
+
if (/(?:^|\r?\n)omitClaudeMd\s*:\s*true\b/i.test(fmMatch[1])) {
|
|
316
|
+
omitClaudeMd = true;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
} catch {
|
|
320
|
+
// ignore: unreadable custom agent markdown file
|
|
321
|
+
}
|
|
322
|
+
const roleText = `${agentName} ${description}`;
|
|
323
|
+
const isBuiltIn = /^(?:explore|plan)$/i.test(agentName.trim());
|
|
324
|
+
const isReviewOrEditRole =
|
|
325
|
+
/\b(?:review|reviewer|code-review|audit|architect|implement|refactor|edit|writer|coder|developer)\b/i.test(
|
|
326
|
+
roleText
|
|
327
|
+
);
|
|
328
|
+
const isLookupSearchLogRole =
|
|
329
|
+
/\b(?:search|lookup|look-up|finder|grep|log|logs|log-read|log-reader|log-triage|scout|fetch|query|index)\b/i.test(
|
|
330
|
+
roleText
|
|
331
|
+
);
|
|
332
|
+
const isLookupSearchLogCandidate = !isBuiltIn && !isReviewOrEditRole && isLookupSearchLogRole;
|
|
333
|
+
agents.push({
|
|
334
|
+
name: agentName,
|
|
335
|
+
path: fullPath.replace(/\\/g, '/'),
|
|
336
|
+
hasNarrowTools,
|
|
337
|
+
omitClaudeMd,
|
|
338
|
+
isLookupSearchLogCandidate
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
return {
|
|
344
|
+
totalAgents: agents.length,
|
|
345
|
+
narrowToolsAgents,
|
|
346
|
+
omitClaudeMdCandidates: agents.filter((a) => a.isLookupSearchLogCandidate && !a.omitClaudeMd),
|
|
347
|
+
agents
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
function detectAnthropicSdkMarkers(cwd) {
|
|
352
|
+
const pkg = parseJsoncReadOnly(path.join(cwd, 'package.json'));
|
|
353
|
+
if (pkg.parseOk && pkg.parsed && typeof pkg.parsed === 'object') {
|
|
354
|
+
const allDeps = {
|
|
355
|
+
...(pkg.parsed.dependencies || {}),
|
|
356
|
+
...(pkg.parsed.devDependencies || {}),
|
|
357
|
+
...(pkg.parsed.peerDependencies || {})
|
|
358
|
+
};
|
|
359
|
+
for (const depName of Object.keys(allDeps)) {
|
|
360
|
+
if (depName === '@anthropic-ai/sdk' || /^@anthropic-ai\//i.test(depName) || /^claude-/i.test(depName)) {
|
|
361
|
+
return true;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
for (const docName of ['README.md', 'readme.md']) {
|
|
366
|
+
const fp = path.join(cwd, docName);
|
|
367
|
+
if (!fs.existsSync(fp)) continue;
|
|
368
|
+
try {
|
|
369
|
+
const head = fs.readFileSync(fp, 'utf8').slice(0, 16384);
|
|
370
|
+
if (/@anthropic-ai\/sdk|cache_control|prompt caching/i.test(head)) return true;
|
|
371
|
+
} catch {
|
|
372
|
+
// ignore: unreadable README.md
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
return false;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
export const RETIRED_MODELS_SPEC = Object.freeze({
|
|
380
|
+
'gemini-3.8-flash': Object.freeze({
|
|
381
|
+
replacement: 'gemini-4-hydrogen',
|
|
382
|
+
antigravity: Object.freeze({
|
|
383
|
+
status: 'leaving_soon',
|
|
384
|
+
sunsetUtc: '2026-11-30T00:00:00Z',
|
|
385
|
+
sourceUrl: 'https://antigravity.google/docs/models',
|
|
386
|
+
checkedOn: '2026-11-27'
|
|
387
|
+
}),
|
|
388
|
+
anthropicApi: null
|
|
389
|
+
}),
|
|
390
|
+
'gemini-4-argon': Object.freeze({
|
|
391
|
+
replacement: 'gemini-4-hydrogen',
|
|
392
|
+
antigravity: Object.freeze({
|
|
393
|
+
status: 'leaving_soon',
|
|
394
|
+
sunsetUtc: '2026-11-30T00:00:00Z',
|
|
395
|
+
sourceUrl: 'https://antigravity.google/docs/models',
|
|
396
|
+
checkedOn: '2026-11-27'
|
|
397
|
+
}),
|
|
398
|
+
anthropicApi: null
|
|
399
|
+
}),
|
|
400
|
+
'claude-opus-4-6': Object.freeze({
|
|
401
|
+
replacement: 'claude-opus-5-5',
|
|
402
|
+
antigravity: Object.freeze({
|
|
403
|
+
status: 'leaving_soon',
|
|
404
|
+
sunsetUtc: '2026-11-30T00:00:00Z',
|
|
405
|
+
sourceUrl: 'https://antigravity.google/docs/models',
|
|
406
|
+
checkedOn: '2026-11-27'
|
|
407
|
+
}),
|
|
408
|
+
anthropicApi: Object.freeze({
|
|
409
|
+
status: 'active',
|
|
410
|
+
deprecationUtc: null,
|
|
411
|
+
notSoonerThanUtc: '2027-02-05T00:00:00Z',
|
|
412
|
+
sourceUrl: 'https://platform.claude.com/docs/en/about-claude/model-deprecations',
|
|
413
|
+
checkedOn: '2026-11-27'
|
|
414
|
+
})
|
|
415
|
+
}),
|
|
416
|
+
'claude-sonnet-4-6': Object.freeze({
|
|
417
|
+
replacement: 'claude-sonnet-5-5',
|
|
418
|
+
antigravity: Object.freeze({
|
|
419
|
+
status: 'leaving_soon',
|
|
420
|
+
sunsetUtc: '2026-11-30T00:00:00Z',
|
|
421
|
+
sourceUrl: 'https://antigravity.google/docs/models',
|
|
422
|
+
checkedOn: '2026-11-27'
|
|
423
|
+
}),
|
|
424
|
+
anthropicApi: Object.freeze({
|
|
425
|
+
status: 'active',
|
|
426
|
+
deprecationUtc: null,
|
|
427
|
+
notSoonerThanUtc: '2027-02-05T00:00:00Z',
|
|
428
|
+
sourceUrl: 'https://platform.claude.com/docs/en/about-claude/model-deprecations',
|
|
429
|
+
checkedOn: '2026-11-27'
|
|
430
|
+
})
|
|
431
|
+
}),
|
|
432
|
+
'gpt-oss-120b': Object.freeze({
|
|
433
|
+
replacement: 'gemini-4-hydrogen',
|
|
434
|
+
antigravity: Object.freeze({
|
|
435
|
+
status: 'leaving_soon',
|
|
436
|
+
sunsetUtc: '2026-11-30T00:00:00Z',
|
|
437
|
+
sourceUrl: 'https://antigravity.google/docs/models',
|
|
438
|
+
checkedOn: '2026-11-27'
|
|
439
|
+
}),
|
|
440
|
+
anthropicApi: null
|
|
441
|
+
}),
|
|
442
|
+
'claude-opus-4-5': Object.freeze({
|
|
443
|
+
replacement: 'claude-opus-5-5',
|
|
444
|
+
antigravity: null,
|
|
445
|
+
anthropicApi: Object.freeze({
|
|
446
|
+
status: 'deprecated',
|
|
447
|
+
deprecationUtc: '2026-11-23T00:00:00Z',
|
|
448
|
+
retirementUtc: '2027-01-22T00:00:00Z',
|
|
449
|
+
notSoonerThanUtc: '2027-01-22T00:00:00Z',
|
|
450
|
+
sourceUrl: 'https://docs.claude.com/en/release-notes/api',
|
|
451
|
+
checkedOn: '2026-11-28'
|
|
452
|
+
})
|
|
453
|
+
})
|
|
454
|
+
});
|
|
455
|
+
|
|
456
|
+
|
|
457
|
+
function normalizeRetiredModelCandidate(raw) {
|
|
458
|
+
let s = String(raw || '').trim().toLowerCase();
|
|
459
|
+
if (!s) return '';
|
|
460
|
+
s = s.replace(/\[[12]m\]/gi, '').replace(/@\d{8}$/, '');
|
|
461
|
+
s = s.replace(/^claude-(opus|sonnet|haiku)-4\.6/, 'claude-$1-4-6');
|
|
462
|
+
s = s.replace(/^claude-(opus|sonnet|haiku)-4\.5/, 'claude-$1-4-5');
|
|
463
|
+
s = s.replace(/^gemini-3-8-flash/, 'gemini-3.8-flash');
|
|
464
|
+
let prev = '';
|
|
465
|
+
while (s !== prev) {
|
|
466
|
+
prev = s;
|
|
467
|
+
s = s.replace(/-(?:\d{8}|low|medium|med|high|xhigh|extra-high|tiered-high|tiered-medium|tiered-low)$/, '');
|
|
468
|
+
}
|
|
469
|
+
return s;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
function extractFrontmatterModelPin(markdown = '') {
|
|
473
|
+
const fmMatch = String(markdown || '').match(/^---\r?\n([\s\S]*?)\r?\n---/);
|
|
474
|
+
if (!fmMatch) return null;
|
|
475
|
+
const m = fmMatch[1].match(/^\s*model\s*:\s*["']?([^"'\r\n#]+)["']?/im);
|
|
476
|
+
return m && m[1] ? m[1].trim() : null;
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
function auditRetiredModelsAndDeprecatedFlags({
|
|
480
|
+
cwd,
|
|
481
|
+
homeDir = null,
|
|
482
|
+
env = process.env,
|
|
483
|
+
settingsLayers = [],
|
|
484
|
+
nowMs = Date.now(),
|
|
485
|
+
harness = 'claude-code',
|
|
486
|
+
isCustomGateway = false,
|
|
487
|
+
antigravityConfigFiles = [],
|
|
488
|
+
antigravityRuleFiles = [],
|
|
489
|
+
repoOnly = false
|
|
490
|
+
} = {}) {
|
|
491
|
+
const findings = [];
|
|
492
|
+
const lints = [];
|
|
493
|
+
const seenKeys = new Set();
|
|
494
|
+
|
|
495
|
+
const addModelFinding = (rawModel, source, targetHarness = harness) => {
|
|
496
|
+
const normalized = normalizeRetiredModelCandidate(rawModel);
|
|
497
|
+
const spec = RETIRED_MODELS_SPEC[normalized];
|
|
498
|
+
if (!spec) return;
|
|
499
|
+
const dedupeKey = `model:${targetHarness}:${normalized}:${source}`;
|
|
500
|
+
if (seenKeys.has(dedupeKey)) return;
|
|
501
|
+
seenKeys.add(dedupeKey);
|
|
502
|
+
|
|
503
|
+
if (targetHarness === 'antigravity') {
|
|
504
|
+
const pSpec = spec.antigravity;
|
|
505
|
+
if (!pSpec) return;
|
|
506
|
+
const sunsetMs = Date.parse(pSpec.sunsetUtc);
|
|
507
|
+
const retired = Number.isFinite(sunsetMs) && nowMs >= sunsetMs;
|
|
508
|
+
const severity = retired ? 'error' : 'warn';
|
|
509
|
+
const sunsetDate = pSpec.sunsetUtc.slice(0, 10);
|
|
510
|
+
const message = `Deprecated / Retired Model (Antigravity): Replace ${rawModel} (Antigravity sunset ${sunsetDate}) with ${spec.replacement} (found in ${source}).`;
|
|
511
|
+
findings.push({
|
|
512
|
+
kind: 'retired_model',
|
|
513
|
+
harness: 'antigravity',
|
|
514
|
+
modelId: normalized,
|
|
515
|
+
rawModel: String(rawModel),
|
|
516
|
+
sunsetUtc: pSpec.sunsetUtc,
|
|
517
|
+
replacement: spec.replacement,
|
|
518
|
+
sourceUrl: pSpec.sourceUrl,
|
|
519
|
+
checkedOn: pSpec.checkedOn,
|
|
520
|
+
severity,
|
|
521
|
+
source
|
|
522
|
+
});
|
|
523
|
+
lints.push({
|
|
524
|
+
ruleId: 'BO-CFG-09',
|
|
525
|
+
severity,
|
|
526
|
+
harness: 'antigravity',
|
|
527
|
+
file: source,
|
|
528
|
+
sourceUrl: pSpec.sourceUrl,
|
|
529
|
+
checkedOn: pSpec.checkedOn,
|
|
530
|
+
message,
|
|
531
|
+
remediation: `Migrate ${rawModel} to ${spec.replacement} before ${sunsetDate} (${pSpec.sourceUrl}).`
|
|
532
|
+
});
|
|
533
|
+
return;
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
const pSpec = spec.anthropicApi;
|
|
537
|
+
if (!pSpec) {
|
|
538
|
+
if (!isCustomGateway) return;
|
|
539
|
+
const agSunsetDate = spec.antigravity?.sunsetUtc ? spec.antigravity.sunsetUtc.slice(0, 10) : '2026-11-30';
|
|
540
|
+
const sourceUrl = spec.antigravity?.sourceUrl || 'https://antigravity.google/docs/models';
|
|
541
|
+
const checkedOn = spec.antigravity?.checkedOn || '2026-11-27';
|
|
542
|
+
const message = `Gateway Model Note: ${rawModel} is an Antigravity / third-party gateway model (Antigravity sunset ${agSunsetDate}; recommended replacement ${spec.replacement}) (found in ${source}).`;
|
|
543
|
+
findings.push({
|
|
544
|
+
kind: 'gateway_model_info',
|
|
545
|
+
harness: 'claude-code',
|
|
546
|
+
modelId: normalized,
|
|
547
|
+
rawModel: String(rawModel),
|
|
548
|
+
replacement: spec.replacement,
|
|
549
|
+
sourceUrl,
|
|
550
|
+
checkedOn,
|
|
551
|
+
severity: 'info',
|
|
552
|
+
source
|
|
553
|
+
});
|
|
554
|
+
lints.push({
|
|
555
|
+
ruleId: 'BO-CFG-09',
|
|
556
|
+
severity: 'info',
|
|
557
|
+
harness: 'claude-code',
|
|
558
|
+
file: source,
|
|
559
|
+
sourceUrl,
|
|
560
|
+
checkedOn,
|
|
561
|
+
message,
|
|
562
|
+
remediation: `Verify gateway model lifecycle for ${rawModel} (${sourceUrl}).`
|
|
563
|
+
});
|
|
564
|
+
return;
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
const retirementMs = pSpec.retirementUtc ? Date.parse(pSpec.retirementUtc) : NaN;
|
|
568
|
+
const depMs = pSpec.deprecationUtc ? Date.parse(pSpec.deprecationUtc) : NaN;
|
|
569
|
+
let severity = 'info';
|
|
570
|
+
if (Number.isFinite(retirementMs) && nowMs >= retirementMs) {
|
|
571
|
+
severity = 'error';
|
|
572
|
+
} else if (pSpec.deprecationUtc && (!Number.isFinite(depMs) || nowMs >= depMs)) {
|
|
573
|
+
severity = 'warn';
|
|
574
|
+
}
|
|
575
|
+
const notSoonerDate = pSpec.notSoonerThanUtc ? pSpec.notSoonerThanUtc.slice(0, 10) : 'TBD';
|
|
576
|
+
const message =
|
|
577
|
+
severity === 'info'
|
|
578
|
+
? `Newer model available: ${spec.replacement} (${rawModel} is Active on Anthropic API; retirement not sooner than ${notSoonerDate}) (found in ${source}).`
|
|
579
|
+
: `Deprecated / Retired Model (Anthropic API): Replace ${rawModel} with ${spec.replacement} (found in ${source}).`;
|
|
580
|
+
findings.push({
|
|
581
|
+
kind: severity === 'info' ? 'newer_model_available' : 'retired_model',
|
|
582
|
+
harness: 'claude-code',
|
|
583
|
+
modelId: normalized,
|
|
584
|
+
rawModel: String(rawModel),
|
|
585
|
+
notSoonerThanUtc: pSpec.notSoonerThanUtc || null,
|
|
586
|
+
deprecationUtc: pSpec.deprecationUtc || null,
|
|
587
|
+
retirementUtc: pSpec.retirementUtc || null,
|
|
588
|
+
replacement: spec.replacement,
|
|
589
|
+
sourceUrl: pSpec.sourceUrl,
|
|
590
|
+
checkedOn: pSpec.checkedOn,
|
|
591
|
+
severity,
|
|
592
|
+
source
|
|
593
|
+
});
|
|
594
|
+
lints.push({
|
|
595
|
+
ruleId: 'BO-CFG-09',
|
|
596
|
+
severity,
|
|
597
|
+
harness: 'claude-code',
|
|
598
|
+
file: source,
|
|
599
|
+
sourceUrl: pSpec.sourceUrl,
|
|
600
|
+
checkedOn: pSpec.checkedOn,
|
|
601
|
+
message,
|
|
602
|
+
remediation:
|
|
603
|
+
severity === 'info'
|
|
604
|
+
? `Consider upgrading ${rawModel} to ${spec.replacement} (${pSpec.sourceUrl}).`
|
|
605
|
+
: `Migrate ${rawModel} to ${spec.replacement} (${pSpec.sourceUrl}).`
|
|
606
|
+
});
|
|
607
|
+
};
|
|
608
|
+
|
|
609
|
+
const scanAgentMarkdownDirs = (dirs, targetHarness) => {
|
|
610
|
+
for (const dir of dirs) {
|
|
611
|
+
for (const fp of listMarkdownFilesInDir(dir)) {
|
|
612
|
+
try {
|
|
613
|
+
const text = fs.readFileSync(fp, 'utf8');
|
|
614
|
+
const pin = extractFrontmatterModelPin(text);
|
|
615
|
+
if (pin) addModelFinding(pin, fp.replace(/\\/g, '/'), targetHarness);
|
|
616
|
+
} catch {
|
|
617
|
+
// ignore: unreadable agent markdown file
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
};
|
|
622
|
+
|
|
623
|
+
if (harness === 'claude-code') {
|
|
624
|
+
for (const layerEntry of settingsLayers) {
|
|
625
|
+
const doc = layerEntry?.doc?.parsed;
|
|
626
|
+
const source = layerEntry?.label || layerEntry?.doc?.path || 'settings.json';
|
|
627
|
+
if (!doc || typeof doc !== 'object') continue;
|
|
628
|
+
for (const k of ['model', 'defaultModel']) {
|
|
629
|
+
if (typeof doc[k] === 'string' && doc[k].trim()) {
|
|
630
|
+
addModelFinding(doc[k].trim(), source, 'claude-code');
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
if (doc.env && typeof doc.env === 'object') {
|
|
634
|
+
for (const ek of [
|
|
635
|
+
'ANTHROPIC_MODEL',
|
|
636
|
+
'CLAUDE_MODEL',
|
|
637
|
+
'ANTHROPIC_DEFAULT_OPUS_MODEL',
|
|
638
|
+
'ANTHROPIC_DEFAULT_SONNET_MODEL',
|
|
639
|
+
'ANTHROPIC_DEFAULT_HAIKU_MODEL'
|
|
640
|
+
]) {
|
|
641
|
+
if (typeof doc.env[ek] === 'string' && doc.env[ek].trim()) {
|
|
642
|
+
addModelFinding(doc.env[ek].trim(), `${source}#env.${ek}`, 'claude-code');
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
if (doc.disableArtifact === true) {
|
|
647
|
+
const dedupeKey = `flag:disableArtifact:${source}`;
|
|
648
|
+
if (!seenKeys.has(dedupeKey)) {
|
|
649
|
+
seenKeys.add(dedupeKey);
|
|
650
|
+
findings.push({
|
|
651
|
+
kind: 'deprecated_flag',
|
|
652
|
+
flag: 'disableArtifact',
|
|
653
|
+
severity: 'warn',
|
|
654
|
+
source
|
|
655
|
+
});
|
|
656
|
+
lints.push({
|
|
657
|
+
ruleId: 'BO-CFG-09',
|
|
658
|
+
severity: 'warn',
|
|
659
|
+
harness: 'claude-code',
|
|
660
|
+
file: source,
|
|
661
|
+
message: `Deprecated / Retired Model or Flag: Migrate deprecated "disableArtifact": true in ${source} to "enableArtifact": false or --disallowedTools Artifact.`,
|
|
662
|
+
remediation: 'Replace "disableArtifact": true with "enableArtifact": false or pass --disallowedTools Artifact.'
|
|
663
|
+
});
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
for (const ek of ['ANTHROPIC_MODEL', 'CLAUDE_MODEL']) {
|
|
669
|
+
if (env && typeof env[ek] === 'string' && env[ek].trim()) {
|
|
670
|
+
addModelFinding(env[ek].trim(), `env:${ek}`, 'claude-code');
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
const claudeAgentDirs = repoOnly || !homeDir
|
|
675
|
+
? [path.join(cwd, '.claude', 'agents')]
|
|
676
|
+
: [path.join(homeDir, '.claude', 'agents'), path.join(cwd, '.claude', 'agents')];
|
|
677
|
+
scanAgentMarkdownDirs(claudeAgentDirs, 'claude-code');
|
|
678
|
+
|
|
679
|
+
const pkg = parseJsoncReadOnly(path.join(cwd, 'package.json'));
|
|
680
|
+
if (pkg.parseOk && pkg.parsed && typeof pkg.parsed === 'object' && pkg.parsed.scripts && typeof pkg.parsed.scripts === 'object') {
|
|
681
|
+
const retiredPattern = /\b(gemini-3[.-]8-flash|gemini-4-argon|claude-opus-4[.-]6|claude-sonnet-4[.-]6|gpt-oss-120b)(?:-[a-z0-9-]+)?\b/gi;
|
|
682
|
+
for (const [scriptName, scriptCmd] of Object.entries(pkg.parsed.scripts)) {
|
|
683
|
+
if (typeof scriptCmd !== 'string') continue;
|
|
684
|
+
if (/\bclaude\b/.test(scriptCmd) && !/\b(?:antigravity|gemini)\b/i.test(scriptCmd)) {
|
|
685
|
+
for (const m of scriptCmd.matchAll(retiredPattern)) {
|
|
686
|
+
addModelFinding(m[0], `package.json#scripts.${scriptName}`, 'claude-code');
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
if (/\bclaude\b[^\n]*\s--tools(?:\s|=|$)/.test(scriptCmd)) {
|
|
690
|
+
const source = `package.json#scripts.${scriptName}`;
|
|
691
|
+
const dedupeKey = `flag:--tools:${source}`;
|
|
692
|
+
if (!seenKeys.has(dedupeKey)) {
|
|
693
|
+
seenKeys.add(dedupeKey);
|
|
694
|
+
findings.push({
|
|
695
|
+
kind: 'forbidden_flag',
|
|
696
|
+
flag: '--tools',
|
|
697
|
+
severity: 'warn',
|
|
698
|
+
source
|
|
699
|
+
});
|
|
700
|
+
lints.push({
|
|
701
|
+
ruleId: 'BO-CFG-09',
|
|
702
|
+
severity: 'warn',
|
|
703
|
+
harness: 'claude-code',
|
|
704
|
+
file: source,
|
|
705
|
+
message: `Deprecated / Retired Model or Flag: Never use strict allowlist --tools in ${source}; use --disallowedTools Artifact instead.`,
|
|
706
|
+
remediation: 'Replace --tools with --disallowedTools Artifact.'
|
|
707
|
+
});
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
} else if (harness === 'antigravity') {
|
|
713
|
+
for (const ek of ['GEMINI_MODEL', 'ANTIGRAVITY_MODEL']) {
|
|
714
|
+
if (env && typeof env[ek] === 'string' && env[ek].trim()) {
|
|
715
|
+
addModelFinding(env[ek].trim(), `env:${ek}`, 'antigravity');
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
for (const cfgEntry of Array.isArray(antigravityConfigFiles) ? antigravityConfigFiles : []) {
|
|
720
|
+
const doc = cfgEntry?.doc?.parsed || cfgEntry?.parsed;
|
|
721
|
+
const source = cfgEntry?.label || cfgEntry?.doc?.path || cfgEntry?.path || '.agents/mcp_config.json';
|
|
722
|
+
if (!doc || typeof doc !== 'object') continue;
|
|
723
|
+
for (const k of ['model', 'defaultModel']) {
|
|
724
|
+
if (typeof doc[k] === 'string' && doc[k].trim()) {
|
|
725
|
+
addModelFinding(doc[k].trim(), String(source).replace(/\\/g, '/'), 'antigravity');
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
if (doc.env && typeof doc.env === 'object') {
|
|
729
|
+
for (const ek of ['GEMINI_MODEL', 'ANTIGRAVITY_MODEL', 'ANTHROPIC_MODEL']) {
|
|
730
|
+
if (typeof doc.env[ek] === 'string' && doc.env[ek].trim()) {
|
|
731
|
+
addModelFinding(doc.env[ek].trim(), `${String(source).replace(/\\/g, '/')}#env.${ek}`, 'antigravity');
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
const agAgentDirs = repoOnly || !homeDir
|
|
738
|
+
? [path.join(cwd, '.agents', 'agents')]
|
|
739
|
+
: [path.join(homeDir, '.gemini', 'config', 'agents'), path.join(cwd, '.agents', 'agents')];
|
|
740
|
+
scanAgentMarkdownDirs(agAgentDirs, 'antigravity');
|
|
741
|
+
for (const rf of Array.isArray(antigravityRuleFiles) ? antigravityRuleFiles : []) {
|
|
742
|
+
if (!rf || !fs.existsSync(rf)) continue;
|
|
743
|
+
try {
|
|
744
|
+
const pin = extractFrontmatterModelPin(fs.readFileSync(rf, 'utf8'));
|
|
745
|
+
if (pin) addModelFinding(pin, String(rf).replace(/\\/g, '/'), 'antigravity');
|
|
746
|
+
} catch {
|
|
747
|
+
// ignore: unreadable Antigravity rule markdown
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
const pkg = parseJsoncReadOnly(path.join(cwd, 'package.json'));
|
|
752
|
+
if (pkg.parseOk && pkg.parsed && typeof pkg.parsed === 'object' && pkg.parsed.scripts && typeof pkg.parsed.scripts === 'object') {
|
|
753
|
+
const retiredPattern = /\b(gemini-3[.-]8-flash|gemini-4-argon|claude-opus-4[.-]6|claude-sonnet-4[.-]6|gpt-oss-120b)(?:-[a-z0-9-]+)?\b/gi;
|
|
754
|
+
for (const [scriptName, scriptCmd] of Object.entries(pkg.parsed.scripts)) {
|
|
755
|
+
if (typeof scriptCmd !== 'string') continue;
|
|
756
|
+
if (/\bclaude\b/.test(scriptCmd) && !/\b(?:antigravity|gemini)\b/i.test(scriptCmd)) continue;
|
|
757
|
+
for (const m of scriptCmd.matchAll(retiredPattern)) {
|
|
758
|
+
addModelFinding(m[0], `package.json#scripts.${scriptName}`, 'antigravity');
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
const hasError = lints.some((l) => l.severity === 'error');
|
|
765
|
+
const hasWarn = lints.some((l) => l.severity === 'warn');
|
|
766
|
+
return {
|
|
767
|
+
status: hasError ? 'error' : hasWarn ? 'warn' : lints.length > 0 ? 'info' : 'pass',
|
|
768
|
+
findings,
|
|
769
|
+
lints
|
|
770
|
+
};
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
/**
|
|
774
|
+
* Audits Claude Code `idleCompaction` (~54m idle) vs `autoCompactEnabled` ROI tradeoffs,
|
|
775
|
+
* gating `idleCompaction` checks strictly on `claudeCodeVersion >= 2.1.290`.
|
|
776
|
+
*/
|
|
777
|
+
export function auditIdleCompactionConfig({
|
|
778
|
+
settingsLayers = [],
|
|
779
|
+
env = {},
|
|
780
|
+
claudeCodeVersion = null,
|
|
781
|
+
observedModels = [],
|
|
782
|
+
maxObservedPrefixTokens = null
|
|
783
|
+
} = {}) {
|
|
784
|
+
let idleCompaction = null;
|
|
785
|
+
let idleCompactionSource = null;
|
|
786
|
+
let autoCompactEnabled = null;
|
|
787
|
+
let autoCompactSource = null;
|
|
788
|
+
let envMinTokensRaw = env?.CLAUDE_CODE_IDLE_COMPACT_MIN_TOKENS;
|
|
789
|
+
const configuredModels = [];
|
|
790
|
+
|
|
791
|
+
for (const layerEntry of settingsLayers) {
|
|
792
|
+
const doc = layerEntry?.doc?.parsed;
|
|
793
|
+
const source = layerEntry?.label || layerEntry?.doc?.path || 'settings.json';
|
|
794
|
+
if (!doc || typeof doc !== 'object') continue;
|
|
795
|
+
if (typeof doc.idleCompaction === 'boolean') {
|
|
796
|
+
idleCompaction = doc.idleCompaction;
|
|
797
|
+
idleCompactionSource = source;
|
|
798
|
+
}
|
|
799
|
+
if (typeof doc.autoCompactEnabled === 'boolean') {
|
|
800
|
+
autoCompactEnabled = doc.autoCompactEnabled;
|
|
801
|
+
autoCompactSource = source;
|
|
802
|
+
}
|
|
803
|
+
if (typeof doc.model === 'string' && doc.model.trim()) configuredModels.push(doc.model.trim());
|
|
804
|
+
if (typeof doc.defaultModel === 'string' && doc.defaultModel.trim()) configuredModels.push(doc.defaultModel.trim());
|
|
805
|
+
if (doc.env && typeof doc.env === 'object') {
|
|
806
|
+
if (doc.env.CLAUDE_CODE_IDLE_COMPACT_MIN_TOKENS !== undefined) {
|
|
807
|
+
envMinTokensRaw = doc.env.CLAUDE_CODE_IDLE_COMPACT_MIN_TOKENS;
|
|
808
|
+
}
|
|
809
|
+
for (const mk of ['ANTHROPIC_MODEL', 'CLAUDE_MODEL']) {
|
|
810
|
+
if (typeof doc.env[mk] === 'string' && doc.env[mk].trim()) configuredModels.push(doc.env[mk].trim());
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
if (env?.ANTHROPIC_MODEL) configuredModels.push(String(env.ANTHROPIC_MODEL).trim());
|
|
815
|
+
if (env?.CLAUDE_MODEL) configuredModels.push(String(env.CLAUDE_MODEL).trim());
|
|
816
|
+
|
|
817
|
+
const parsedMinTok = Number(envMinTokensRaw);
|
|
818
|
+
const idleCompactMinTokens =
|
|
819
|
+
Number.isFinite(parsedMinTok) && parsedMinTok > 0
|
|
820
|
+
? Math.round(parsedMinTok)
|
|
821
|
+
: DEFAULT_IDLE_COMPACT_MIN_TOKENS;
|
|
822
|
+
|
|
823
|
+
const versionSupported = Boolean(
|
|
824
|
+
claudeCodeVersion && compareSemver(String(claudeCodeVersion), IDLE_COMPACTION_MIN_VERSION) >= 0
|
|
825
|
+
);
|
|
826
|
+
const allModels = [...configuredModels, ...(Array.isArray(observedModels) ? observedModels : [])];
|
|
827
|
+
const claude55Active = allModels.some((m) => /claude-(?:opus|sonnet)-5[.-]5/i.test(String(m || '')));
|
|
828
|
+
|
|
829
|
+
if (autoCompactEnabled === false) {
|
|
830
|
+
const file = autoCompactSource || '~/.claude/settings.json';
|
|
831
|
+
const message =
|
|
832
|
+
'Global autoCompactEnabled: false disables hard overflow protection. Re-enable "autoCompactEnabled": true and set "idleCompaction": false surgically if you want to skip ~54m idle compaction without risking context overflow.';
|
|
833
|
+
return {
|
|
834
|
+
status: 'warn',
|
|
835
|
+
versionSupported,
|
|
836
|
+
claudeCodeVersion: claudeCodeVersion || null,
|
|
837
|
+
idleCompaction,
|
|
838
|
+
autoCompactEnabled,
|
|
839
|
+
idleCompactMinTokens,
|
|
840
|
+
claude55Active,
|
|
841
|
+
idleCompactionAlert: false,
|
|
842
|
+
coachingMode: 'restore_auto_compact_use_surgical_idle_disable',
|
|
843
|
+
coachingNote: message,
|
|
844
|
+
fix: { autoCompactEnabled: true, idleCompaction: false },
|
|
845
|
+
lints: [
|
|
846
|
+
{
|
|
847
|
+
ruleId: 'BO-CFG-10',
|
|
848
|
+
severity: 'warn',
|
|
849
|
+
harness: 'claude-code',
|
|
850
|
+
file,
|
|
851
|
+
message,
|
|
852
|
+
remediation: 'Set "autoCompactEnabled": true and use "idleCompaction": false surgically instead.'
|
|
853
|
+
}
|
|
854
|
+
]
|
|
855
|
+
};
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
if (!versionSupported) {
|
|
859
|
+
return {
|
|
860
|
+
status: 'pass',
|
|
861
|
+
versionSupported: false,
|
|
862
|
+
claudeCodeVersion: claudeCodeVersion || null,
|
|
863
|
+
idleCompaction,
|
|
864
|
+
autoCompactEnabled,
|
|
865
|
+
idleCompactMinTokens,
|
|
866
|
+
claude55Active,
|
|
867
|
+
idleCompactionAlert: false,
|
|
868
|
+
coachingMode: 'unsupported_version',
|
|
869
|
+
coachingNote: null,
|
|
870
|
+
fix: null,
|
|
871
|
+
lints: []
|
|
872
|
+
};
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
if (idleCompaction === false) {
|
|
876
|
+
return {
|
|
877
|
+
status: 'pass',
|
|
878
|
+
versionSupported: true,
|
|
879
|
+
claudeCodeVersion,
|
|
880
|
+
idleCompaction: false,
|
|
881
|
+
autoCompactEnabled,
|
|
882
|
+
idleCompactMinTokens,
|
|
883
|
+
claude55Active,
|
|
884
|
+
idleCompactionAlert: false,
|
|
885
|
+
coachingMode: 'surgical_idle_disabled_overflow_protected',
|
|
886
|
+
coachingNote: 'Surgical "idleCompaction": false preserves reasoning nuance past 54m idle while keeping autoCompactEnabled active.',
|
|
887
|
+
fix: null,
|
|
888
|
+
lints: []
|
|
889
|
+
};
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
const hasLargePrefix = Number.isFinite(maxObservedPrefixTokens) && maxObservedPrefixTokens >= idleCompactMinTokens;
|
|
893
|
+
const loweredThreshold = idleCompactMinTokens < DEFAULT_IDLE_COMPACT_MIN_TOKENS;
|
|
894
|
+
const triggerRoiAlert = Boolean(claude55Active || loweredThreshold || hasLargePrefix);
|
|
895
|
+
|
|
896
|
+
if (triggerRoiAlert) {
|
|
897
|
+
const coachingMode = claude55Active ? 'claude55_compact_miss_backfire_risk' : 'idle_compaction_roi_tradeoff';
|
|
898
|
+
const file = idleCompactionSource || '~/.claude/settings.json';
|
|
899
|
+
const message = claude55Active
|
|
900
|
+
? `Idle Compaction ROI Risk (v2.1.290+ & #99624): idleCompaction auto-compacts >=${idleCompactMinTokens.toLocaleString('en-US')} tok sessions at ~54m idle, which on Claude 5.5 can miss the warm cache and bill a full cache write while losing reasoning nuance. Set "idleCompaction": false surgically while keeping "autoCompactEnabled": true for hard overflow protection.`
|
|
901
|
+
: `Idle Compaction ROI Advisory (v2.1.290+): idleCompaction triggers around ~54m idle (threshold ${idleCompactMinTokens.toLocaleString('en-US')} tok) before 1h cache TTL. If preserving multi-step reasoning nuance outweighs cold-resume cost, set "idleCompaction": false surgically and keep "autoCompactEnabled": true for hard overflow protection.`;
|
|
902
|
+
return {
|
|
903
|
+
status: 'warn',
|
|
904
|
+
versionSupported: true,
|
|
905
|
+
claudeCodeVersion,
|
|
906
|
+
idleCompaction,
|
|
907
|
+
autoCompactEnabled,
|
|
908
|
+
idleCompactMinTokens,
|
|
909
|
+
claude55Active,
|
|
910
|
+
idleCompactionAlert: true,
|
|
911
|
+
coachingMode,
|
|
912
|
+
coachingNote: message,
|
|
913
|
+
fix: { idleCompaction: false, autoCompactEnabled: true },
|
|
914
|
+
lints: [
|
|
915
|
+
{
|
|
916
|
+
ruleId: 'BO-CFG-10',
|
|
917
|
+
severity: 'warn',
|
|
918
|
+
harness: 'claude-code',
|
|
919
|
+
file,
|
|
920
|
+
message,
|
|
921
|
+
remediation: 'Set "idleCompaction": false surgically in settings.json while keeping "autoCompactEnabled": true.'
|
|
922
|
+
}
|
|
923
|
+
]
|
|
924
|
+
};
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
return {
|
|
928
|
+
status: 'info',
|
|
929
|
+
versionSupported: true,
|
|
930
|
+
claudeCodeVersion,
|
|
931
|
+
idleCompaction,
|
|
932
|
+
autoCompactEnabled,
|
|
933
|
+
idleCompactMinTokens,
|
|
934
|
+
claude55Active,
|
|
935
|
+
idleCompactionAlert: false,
|
|
936
|
+
coachingMode: 'default_idle_compaction_active',
|
|
937
|
+
coachingNote: `v2.1.290+ idleCompaction (~54m idle, min ${idleCompactMinTokens.toLocaleString('en-US')} tok) active. Only set "idleCompaction": false surgically when reasoning nuance outweighs cold-resume cost; keep "autoCompactEnabled": true.`,
|
|
938
|
+
fix: null,
|
|
939
|
+
lints: []
|
|
940
|
+
};
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
|
|
944
|
+
function createEmptyClaudeTelemetryStub() {
|
|
945
|
+
return {
|
|
946
|
+
sessionsScanned: 0,
|
|
947
|
+
bytesScanned: 0,
|
|
948
|
+
scanTruncated: false,
|
|
949
|
+
browserToolCalls7d: 0,
|
|
950
|
+
artifactCalls7d: 0,
|
|
951
|
+
mcpToolCalls7d: {},
|
|
952
|
+
schemaTokensByServer: {},
|
|
953
|
+
observedMcpToolNames: [],
|
|
954
|
+
runtimeListChangedServers: [],
|
|
955
|
+
maxCachedPrefixTokens: 0,
|
|
956
|
+
subagentSpawns7d: 0,
|
|
957
|
+
sidechainTurns7d: 0,
|
|
958
|
+
observedMcpInstructionsDeltaChars: 0,
|
|
959
|
+
observedModels: [],
|
|
960
|
+
entrypoints: ['cli'],
|
|
961
|
+
sdkCliSessions7d: 0,
|
|
962
|
+
claudeCodeVersion: null
|
|
963
|
+
};
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
/**
|
|
967
|
+
* Runs Turn-0 startup config, rules-count, and eager-only MCP audit for Claude Code.
|
|
968
|
+
*/
|
|
969
|
+
|
|
970
|
+
export {
|
|
971
|
+
scanClaudeTelemetrySummary,
|
|
972
|
+
detectAnthropicSdkMarkers,
|
|
973
|
+
auditRetiredModelsAndDeprecatedFlags,
|
|
974
|
+
createEmptyClaudeTelemetryStub
|
|
975
|
+
};
|