burnoff 1.2.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +11 -0
- package/.github/workflows/burnoff-pr-gate.yml +3 -3
- package/.github/workflows/burnoff-startup-lint.yml +37 -0
- package/README.md +47 -6
- package/bin/burnoff.mjs +123 -5
- package/commands/burnoff.md +16 -0
- package/docs/CLAUDE_CODE_PLUGIN.md +67 -0
- package/docs/DESIGN_PARTNER_INTAKE.md +44 -0
- package/package.json +10 -4
- package/scripts/burnoff-statusline.mjs +104 -0
- package/src/cli/audit.mjs +82 -4
- package/src/cli/startup-audit.mjs +390 -71
- package/src/config/policy.mjs +13 -1
- package/src/guards/loop-breaker.mjs +49 -0
- package/src/guards/phase5-detectors.mjs +727 -0
- package/src/guards/pre-tool-engine.mjs +222 -66
- package/src/guards/snooze.mjs +363 -0
- package/src/storage/antigravity-parser.mjs +18 -1
- package/src/storage/jsonl-parser.mjs +29 -1
- package/src/storage/telemetry-metrics.mjs +703 -0
|
@@ -56,6 +56,8 @@ export const DEFAULT_MCP_INSTRUCTIONS_TOKENS_PER_SERVER = 600;
|
|
|
56
56
|
export const IDLE_COMPACTION_MIN_VERSION = '2.1.290';
|
|
57
57
|
export const DEFAULT_IDLE_COMPACT_MIN_TOKENS = 200000;
|
|
58
58
|
export const SDK_CLI_QUOTA_MULTIPLIER_HEURISTIC = 1.8;
|
|
59
|
+
export const COARSE_META_TOOL_MIN_SERVERS = 3;
|
|
60
|
+
export const COARSE_META_TOOL_MIN_TOKENS = 10000;
|
|
59
61
|
|
|
60
62
|
export const VERIFIED_CLAUDE_FLAGS = Object.freeze([
|
|
61
63
|
'--chrome',
|
|
@@ -760,11 +762,10 @@ function scanClaudeTelemetrySummary({
|
|
|
760
762
|
* Strictly read-only scan of `~/.claude/agents/*.md` and `<cwd>/.claude/agents/*.md`
|
|
761
763
|
* to count custom subagent definitions and narrow frontmatter `tools:` allowlists.
|
|
762
764
|
*/
|
|
763
|
-
export function scanClaudeCustomAgentSpecs({ homeDir = getHomeDir(), cwd = process.cwd() } = {}) {
|
|
764
|
-
const dirs =
|
|
765
|
-
path.join(
|
|
766
|
-
path.join(cwd, '.claude', 'agents')
|
|
767
|
-
];
|
|
765
|
+
export function scanClaudeCustomAgentSpecs({ homeDir = getHomeDir(), cwd = process.cwd(), repoOnly = false } = {}) {
|
|
766
|
+
const dirs = repoOnly
|
|
767
|
+
? [path.join(cwd, '.claude', 'agents')]
|
|
768
|
+
: [path.join(homeDir, '.claude', 'agents'), path.join(cwd, '.claude', 'agents')];
|
|
768
769
|
const seen = new Set();
|
|
769
770
|
const agents = [];
|
|
770
771
|
let narrowToolsAgents = 0;
|
|
@@ -952,8 +953,11 @@ function evaluateClaudeEagerMcpGate({
|
|
|
952
953
|
eagerGateActive: false,
|
|
953
954
|
gateReasons: [],
|
|
954
955
|
enableToolSearch,
|
|
956
|
+
toolSearchDisabled,
|
|
955
957
|
disableExperimentalBetas,
|
|
956
958
|
isCustomGateway,
|
|
959
|
+
baseUrl: baseUrl || null,
|
|
960
|
+
isLocalhostProxy: Boolean(baseUrl && isLocalhostBaseUrl(baseUrl)),
|
|
957
961
|
isSshSession,
|
|
958
962
|
gatewayVerified,
|
|
959
963
|
configuredServerCount: discovered.length,
|
|
@@ -988,8 +992,11 @@ function evaluateClaudeEagerMcpGate({
|
|
|
988
992
|
eagerGateActive: true,
|
|
989
993
|
gateReasons,
|
|
990
994
|
enableToolSearch,
|
|
995
|
+
toolSearchDisabled,
|
|
991
996
|
disableExperimentalBetas,
|
|
992
997
|
isCustomGateway,
|
|
998
|
+
baseUrl: baseUrl || null,
|
|
999
|
+
isLocalhostProxy: Boolean(baseUrl && isLocalhostBaseUrl(baseUrl)),
|
|
993
1000
|
isSshSession,
|
|
994
1001
|
gatewayVerified,
|
|
995
1002
|
configuredServerCount: discovered.length,
|
|
@@ -1001,6 +1008,107 @@ function evaluateClaudeEagerMcpGate({
|
|
|
1001
1008
|
};
|
|
1002
1009
|
}
|
|
1003
1010
|
|
|
1011
|
+
/**
|
|
1012
|
+
* Returns true if `rawUrl` points to a loopback / localhost proxy endpoint.
|
|
1013
|
+
*/
|
|
1014
|
+
export function isLocalhostBaseUrl(rawUrl) {
|
|
1015
|
+
const s = String(rawUrl || '').trim();
|
|
1016
|
+
if (!s) return false;
|
|
1017
|
+
try {
|
|
1018
|
+
const u = new URL(s);
|
|
1019
|
+
const host = u.hostname.toLowerCase().replace(/^\[|\]$/g, '');
|
|
1020
|
+
return (
|
|
1021
|
+
host === 'localhost' ||
|
|
1022
|
+
host === '127.0.0.1' ||
|
|
1023
|
+
host === '::1' ||
|
|
1024
|
+
host === '0.0.0.0' ||
|
|
1025
|
+
host === 'host.docker.internal' ||
|
|
1026
|
+
host.endsWith('.localhost')
|
|
1027
|
+
);
|
|
1028
|
+
} catch {
|
|
1029
|
+
return false; // ignore: malformed ANTHROPIC_BASE_URL is not treated as localhost proxy
|
|
1030
|
+
}
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
/**
|
|
1034
|
+
* BO-MCP-10: Eager-only coarse meta-tool coaching + local `ANTHROPIC_BASE_URL`
|
|
1035
|
+
* MCP proxy `CACHE-BACKFIRE TRAP` lint. Never emits coarse meta-tool advice when
|
|
1036
|
+
* native deferred `ToolSearch` loading is healthy (`eagerGateActive === false`).
|
|
1037
|
+
*/
|
|
1038
|
+
export function evaluateMcpProxyAndMetaToolCoaching({
|
|
1039
|
+
harness = 'claude-code',
|
|
1040
|
+
eagerGateActive = false,
|
|
1041
|
+
baseUrl = null,
|
|
1042
|
+
isLocalhostProxy = isLocalhostBaseUrl(baseUrl),
|
|
1043
|
+
gatewayVerified = false,
|
|
1044
|
+
toolSearchDisabled = false,
|
|
1045
|
+
disableExperimentalBetas = false,
|
|
1046
|
+
isSshSession = false,
|
|
1047
|
+
configuredServerCount = 0,
|
|
1048
|
+
configuredServerNames = [],
|
|
1049
|
+
startupTaxTokensPerTurn = 0,
|
|
1050
|
+
file = 'env'
|
|
1051
|
+
} = {}) {
|
|
1052
|
+
const proxyLooksLikeMcpGateway = /mcp|proxy|gateway|router/i.test(String(baseUrl || ''));
|
|
1053
|
+
const proxyCacheBackfireTrap = Boolean(
|
|
1054
|
+
harness === 'claude-code' &&
|
|
1055
|
+
isLocalhostProxy &&
|
|
1056
|
+
!gatewayVerified &&
|
|
1057
|
+
!toolSearchDisabled &&
|
|
1058
|
+
!disableExperimentalBetas &&
|
|
1059
|
+
!isSshSession &&
|
|
1060
|
+
(configuredServerCount > 0 || proxyLooksLikeMcpGateway)
|
|
1061
|
+
);
|
|
1062
|
+
|
|
1063
|
+
const meetsCoarseThreshold =
|
|
1064
|
+
configuredServerCount >= COARSE_META_TOOL_MIN_SERVERS ||
|
|
1065
|
+
Number(startupTaxTokensPerTurn || 0) >= COARSE_META_TOOL_MIN_TOKENS;
|
|
1066
|
+
const coarseMetaToolCoaching = Boolean(eagerGateActive && !proxyCacheBackfireTrap && meetsCoarseThreshold);
|
|
1067
|
+
|
|
1068
|
+
const lints = [];
|
|
1069
|
+
let coachingNote = null;
|
|
1070
|
+
|
|
1071
|
+
if (proxyCacheBackfireTrap) {
|
|
1072
|
+
coachingNote =
|
|
1073
|
+
`CACHE-BACKFIRE TRAP (BO-MCP-10): Localhost ANTHROPIC_BASE_URL proxy (${baseUrl}) wraps an otherwise native-deferred Claude Code setup, risking #95087 beta-header stripping (forcing eager MCP fallback) and extra proxy latency. Unset ANTHROPIC_BASE_URL to restore native ToolSearch deferral, or set BURNOFF_GATEWAY_VERIFIED_TOOL_SEARCH=1 if verified.`;
|
|
1074
|
+
lints.push({
|
|
1075
|
+
ruleId: 'BO-MCP-10',
|
|
1076
|
+
kind: 'proxy_cache_backfire',
|
|
1077
|
+
severity: 'warn',
|
|
1078
|
+
harness,
|
|
1079
|
+
file,
|
|
1080
|
+
message: coachingNote,
|
|
1081
|
+
remediation:
|
|
1082
|
+
'Remove unnecessary local ANTHROPIC_BASE_URL MCP proxies when native Claude Code ToolSearch deferral is available.'
|
|
1083
|
+
});
|
|
1084
|
+
} else if (coarseMetaToolCoaching) {
|
|
1085
|
+
coachingNote =
|
|
1086
|
+
`Eager MCP Coarse Meta-Tool Coaching (BO-MCP-10): Eager schema loading active (${configuredServerCount} servers, ~${Number(startupTaxTokensPerTurn || 0).toLocaleString('en-US')} est. tok/turn). Consolidate fine-grained MCP tools into coarse progressive-disclosure meta-tools or disable unused servers between sessions.`;
|
|
1087
|
+
lints.push({
|
|
1088
|
+
ruleId: 'BO-MCP-10',
|
|
1089
|
+
kind: 'eager_coarse_meta_tool',
|
|
1090
|
+
severity: 'info',
|
|
1091
|
+
harness,
|
|
1092
|
+
file,
|
|
1093
|
+
configuredServers: configuredServerNames,
|
|
1094
|
+
message: coachingNote,
|
|
1095
|
+
remediation:
|
|
1096
|
+
'Consolidate chatty fine-grained MCP tools behind coarse domain actions only while eager loading is unavoidable, or re-enable native ToolSearch deferral.'
|
|
1097
|
+
});
|
|
1098
|
+
}
|
|
1099
|
+
|
|
1100
|
+
return {
|
|
1101
|
+
status: proxyCacheBackfireTrap ? 'warn' : coarseMetaToolCoaching ? 'info' : 'pass',
|
|
1102
|
+
eagerGateActive: Boolean(eagerGateActive),
|
|
1103
|
+
isLocalhostProxy: Boolean(isLocalhostProxy),
|
|
1104
|
+
baseUrl: baseUrl || null,
|
|
1105
|
+
proxyCacheBackfireTrap,
|
|
1106
|
+
coarseMetaToolCoaching,
|
|
1107
|
+
coachingNote,
|
|
1108
|
+
lints
|
|
1109
|
+
};
|
|
1110
|
+
}
|
|
1111
|
+
|
|
1004
1112
|
/**
|
|
1005
1113
|
* BO-MCP-05 (#97616): Scans configured MCP tool definitions and observed Claude Code
|
|
1006
1114
|
* MCP tool names for `mcp__<server>__<tool>` identifiers exceeding 64 characters.
|
|
@@ -1010,7 +1118,8 @@ export function scanMcpToolNameLengthViolations({
|
|
|
1010
1118
|
workspacePath = process.cwd(),
|
|
1011
1119
|
observedToolNames = [],
|
|
1012
1120
|
manifestDirs = [],
|
|
1013
|
-
maxLength = 64
|
|
1121
|
+
maxLength = 64,
|
|
1122
|
+
repoOnly = false
|
|
1014
1123
|
} = {}) {
|
|
1015
1124
|
const disabledServers = new Set();
|
|
1016
1125
|
const violationsByFullName = new Map();
|
|
@@ -1059,7 +1168,9 @@ export function scanMcpToolNameLengthViolations({
|
|
|
1059
1168
|
inspectServerMap(projMcp.parsed.mcpServers || projMcp.parsed.servers || projMcp.parsed, projMcp.path.replace(/\\/g, '/'));
|
|
1060
1169
|
}
|
|
1061
1170
|
|
|
1062
|
-
const claudeJson =
|
|
1171
|
+
const claudeJson = repoOnly
|
|
1172
|
+
? { parseOk: false, parsed: null }
|
|
1173
|
+
: parseJsoncReadOnly(path.join(homeDir, '.claude.json'));
|
|
1063
1174
|
if (claudeJson.parseOk && claudeJson.parsed && typeof claudeJson.parsed === 'object') {
|
|
1064
1175
|
inspectServerMap(claudeJson.parsed.mcpServers, '~/.claude.json');
|
|
1065
1176
|
const projects = claudeJson.parsed.projects;
|
|
@@ -1158,7 +1269,7 @@ function collectDisabledClaudeMcpServers({ homeDir = getHomeDir(), workspacePath
|
|
|
1158
1269
|
trackServerMap(projMcp.parsed.mcpServers || projMcp.parsed.servers || projMcp.parsed);
|
|
1159
1270
|
}
|
|
1160
1271
|
|
|
1161
|
-
const claudeJson = parseJsoncReadOnly(path.join(homeDir, '.claude.json'));
|
|
1272
|
+
const claudeJson = homeDir ? parseJsoncReadOnly(path.join(homeDir, '.claude.json')) : { parseOk: false, parsed: null };
|
|
1162
1273
|
if (claudeJson.parseOk && claudeJson.parsed && typeof claudeJson.parsed === 'object') {
|
|
1163
1274
|
trackServerMap(claudeJson.parsed.mcpServers);
|
|
1164
1275
|
const projects = claudeJson.parsed.projects;
|
|
@@ -1197,9 +1308,10 @@ export function scanMcpListChangedCapabilities({
|
|
|
1197
1308
|
manifestDirs = [],
|
|
1198
1309
|
runtimeListChangedServers = [],
|
|
1199
1310
|
maxObservedCachedPrefixTokens = null,
|
|
1200
|
-
cachedPrefixThreshold = LIST_CHANGED_PREFIX_THRESHOLD
|
|
1311
|
+
cachedPrefixThreshold = LIST_CHANGED_PREFIX_THRESHOLD,
|
|
1312
|
+
repoOnly = false
|
|
1201
1313
|
} = {}) {
|
|
1202
|
-
const disabledServers = collectDisabledClaudeMcpServers({ homeDir, workspacePath });
|
|
1314
|
+
const disabledServers = collectDisabledClaudeMcpServers({ homeDir: repoOnly ? null : homeDir, workspacePath });
|
|
1203
1315
|
const flaggedByServer = new Map();
|
|
1204
1316
|
|
|
1205
1317
|
const recordFlagged = (serverName, reason, source) => {
|
|
@@ -1228,7 +1340,9 @@ export function scanMcpListChangedCapabilities({
|
|
|
1228
1340
|
inspectConfigMap(projMcp.parsed.mcpServers || projMcp.parsed.servers || projMcp.parsed, projMcp.path);
|
|
1229
1341
|
}
|
|
1230
1342
|
|
|
1231
|
-
const claudeJson =
|
|
1343
|
+
const claudeJson = repoOnly
|
|
1344
|
+
? { parseOk: false, parsed: null }
|
|
1345
|
+
: parseJsoncReadOnly(path.join(homeDir, '.claude.json'));
|
|
1232
1346
|
if (claudeJson.parseOk && claudeJson.parsed && typeof claudeJson.parsed === 'object') {
|
|
1233
1347
|
inspectConfigMap(claudeJson.parsed.mcpServers, '~/.claude.json');
|
|
1234
1348
|
const projects = claudeJson.parsed.projects;
|
|
@@ -2029,6 +2143,49 @@ export function auditVolatilePromptPrefix({
|
|
|
2029
2143
|
};
|
|
2030
2144
|
}
|
|
2031
2145
|
|
|
2146
|
+
function makeMissingJsoncStub(filePath = '') {
|
|
2147
|
+
return {
|
|
2148
|
+
path: filePath,
|
|
2149
|
+
exists: false,
|
|
2150
|
+
parseOk: false,
|
|
2151
|
+
parsed: null,
|
|
2152
|
+
strictJsonValid: false,
|
|
2153
|
+
strict_json_syntax_warning: null,
|
|
2154
|
+
error: null
|
|
2155
|
+
};
|
|
2156
|
+
}
|
|
2157
|
+
|
|
2158
|
+
function filterFilesWithinCwd(filePaths = [], cwd = process.cwd()) {
|
|
2159
|
+
const resolvedCwd = path.resolve(cwd);
|
|
2160
|
+
return (Array.isArray(filePaths) ? filePaths : []).filter((fp) => {
|
|
2161
|
+
if (!fp) return false;
|
|
2162
|
+
const rel = path.relative(resolvedCwd, path.resolve(fp));
|
|
2163
|
+
return rel !== '..' && !rel.startsWith(`..${path.sep}`) && !path.isAbsolute(rel);
|
|
2164
|
+
});
|
|
2165
|
+
}
|
|
2166
|
+
|
|
2167
|
+
function createEmptyClaudeTelemetryStub() {
|
|
2168
|
+
return {
|
|
2169
|
+
sessionsScanned: 0,
|
|
2170
|
+
bytesScanned: 0,
|
|
2171
|
+
scanTruncated: false,
|
|
2172
|
+
browserToolCalls7d: 0,
|
|
2173
|
+
artifactCalls7d: 0,
|
|
2174
|
+
mcpToolCalls7d: {},
|
|
2175
|
+
schemaTokensByServer: {},
|
|
2176
|
+
observedMcpToolNames: [],
|
|
2177
|
+
runtimeListChangedServers: [],
|
|
2178
|
+
maxCachedPrefixTokens: 0,
|
|
2179
|
+
subagentSpawns7d: 0,
|
|
2180
|
+
sidechainTurns7d: 0,
|
|
2181
|
+
observedMcpInstructionsDeltaChars: 0,
|
|
2182
|
+
observedModels: [],
|
|
2183
|
+
entrypoints: ['cli'],
|
|
2184
|
+
sdkCliSessions7d: 0,
|
|
2185
|
+
claudeCodeVersion: null
|
|
2186
|
+
};
|
|
2187
|
+
}
|
|
2188
|
+
|
|
2032
2189
|
/**
|
|
2033
2190
|
* Runs Turn-0 startup config, rules-count, and eager-only MCP audit for Claude Code.
|
|
2034
2191
|
*/
|
|
@@ -2042,16 +2199,21 @@ export function runClaudeStartupAudit({
|
|
|
2042
2199
|
nowMs = Date.now(),
|
|
2043
2200
|
manifestDirs = [],
|
|
2044
2201
|
maxTelemetryFiles = DEFAULT_TELEMETRY_MAX_FILES,
|
|
2045
|
-
maxTelemetryBytes = DEFAULT_TELEMETRY_MAX_BYTES
|
|
2202
|
+
maxTelemetryBytes = DEFAULT_TELEMETRY_MAX_BYTES,
|
|
2203
|
+
repoOnly = false,
|
|
2204
|
+
ci = false
|
|
2046
2205
|
} = {}) {
|
|
2206
|
+
const isRepoOnly = Boolean(repoOnly || ci);
|
|
2047
2207
|
const paths = resolveClaudeConfigPaths({ homeDir, cwd, platform: hostPlatform });
|
|
2048
|
-
const telemetry =
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2208
|
+
const telemetry = isRepoOnly
|
|
2209
|
+
? createEmptyClaudeTelemetryStub()
|
|
2210
|
+
: scanClaudeTelemetrySummary({
|
|
2211
|
+
projectsDir: paths.projectsDir,
|
|
2212
|
+
days,
|
|
2213
|
+
nowMs,
|
|
2214
|
+
maxFiles: maxTelemetryFiles,
|
|
2215
|
+
maxTotalBytes: maxTelemetryBytes
|
|
2216
|
+
});
|
|
2055
2217
|
|
|
2056
2218
|
const detectedClaudeVersion = claudeCodeVersion || telemetry.claudeCodeVersion || null;
|
|
2057
2219
|
const observedEntrypoint =
|
|
@@ -2059,17 +2221,29 @@ export function runClaudeStartupAudit({
|
|
|
2059
2221
|
? 'sdk-ts'
|
|
2060
2222
|
: telemetry.entrypoints[0] || 'cli';
|
|
2061
2223
|
|
|
2062
|
-
const claudeJson =
|
|
2063
|
-
|
|
2224
|
+
const claudeJson = isRepoOnly
|
|
2225
|
+
? makeMissingJsoncStub(paths.claudeJson)
|
|
2226
|
+
: parseJsoncReadOnly(paths.claudeJson);
|
|
2227
|
+
const userSettings = isRepoOnly
|
|
2228
|
+
? makeMissingJsoncStub(paths.userSettings)
|
|
2229
|
+
: parseJsoncReadOnly(paths.userSettings);
|
|
2064
2230
|
const projectSettings = parseJsoncReadOnly(paths.projectSettings);
|
|
2065
2231
|
const projectLocalSettings = parseJsoncReadOnly(paths.projectLocalSettings);
|
|
2066
2232
|
const projectMcp = parseJsoncReadOnly(paths.projectMcpJson);
|
|
2067
|
-
const settingsLayers =
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2233
|
+
const settingsLayers = isRepoOnly
|
|
2234
|
+
? [
|
|
2235
|
+
{ doc: projectSettings, label: '.claude/settings.json' },
|
|
2236
|
+
{ doc: projectLocalSettings, label: '.claude/settings.local.json' }
|
|
2237
|
+
]
|
|
2238
|
+
: [
|
|
2239
|
+
{ doc: userSettings, label: '~/.claude/settings.json' },
|
|
2240
|
+
{ doc: projectSettings, label: '.claude/settings.json' },
|
|
2241
|
+
{ doc: projectLocalSettings, label: '.claude/settings.local.json' }
|
|
2242
|
+
];
|
|
2243
|
+
const layers = isRepoOnly
|
|
2244
|
+
? [projectSettings.parsed, projectLocalSettings.parsed].filter(Boolean)
|
|
2245
|
+
: [userSettings.parsed, projectSettings.parsed, projectLocalSettings.parsed].filter(Boolean);
|
|
2246
|
+
const scopedRulesFiles = isRepoOnly ? filterFilesWithinCwd(paths.rulesFiles, paths.cwd) : paths.rulesFiles;
|
|
2073
2247
|
|
|
2074
2248
|
const chromeOnDemandCmd = buildClaudeCliCommand(['--chrome'], { platform: hostPlatform });
|
|
2075
2249
|
const artifactDisallowedCmd = buildClaudeCliCommand(['--disallowedTools', 'Artifact'], { platform: hostPlatform });
|
|
@@ -2167,19 +2341,24 @@ export function runClaudeStartupAudit({
|
|
|
2167
2341
|
schemaTokensByServer: telemetry.schemaTokensByServer
|
|
2168
2342
|
});
|
|
2169
2343
|
|
|
2170
|
-
const rulesBucket = auditRulesFiles(
|
|
2171
|
-
const strictJsonSyntax = collectStrictJsonLints(
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2344
|
+
const rulesBucket = auditRulesFiles(scopedRulesFiles);
|
|
2345
|
+
const strictJsonSyntax = collectStrictJsonLints(
|
|
2346
|
+
isRepoOnly
|
|
2347
|
+
? [{ res: projectSettings }, { res: projectLocalSettings }, { res: projectMcp }]
|
|
2348
|
+
: [
|
|
2349
|
+
{ res: claudeJson },
|
|
2350
|
+
{ res: userSettings },
|
|
2351
|
+
{ res: projectSettings },
|
|
2352
|
+
{ res: projectLocalSettings },
|
|
2353
|
+
{ res: projectMcp }
|
|
2354
|
+
]
|
|
2355
|
+
);
|
|
2178
2356
|
const localSettingsSecrets = auditLocalSettingsSecrets(projectLocalSettings, paths.cwd);
|
|
2179
2357
|
const mcpToolViolations = scanMcpToolNameLengthViolations({
|
|
2180
2358
|
homeDir: paths.homeDir,
|
|
2181
2359
|
workspacePath: paths.cwd,
|
|
2182
|
-
observedToolNames: telemetry.observedMcpToolNames || []
|
|
2360
|
+
observedToolNames: telemetry.observedMcpToolNames || [],
|
|
2361
|
+
repoOnly: isRepoOnly
|
|
2183
2362
|
});
|
|
2184
2363
|
const mcpToolNameLength = {
|
|
2185
2364
|
status: mcpToolViolations.violations.length > 0 ? 'warn' : 'pass',
|
|
@@ -2191,11 +2370,13 @@ export function runClaudeStartupAudit({
|
|
|
2191
2370
|
workspacePath: paths.cwd,
|
|
2192
2371
|
manifestDirs,
|
|
2193
2372
|
runtimeListChangedServers: telemetry.runtimeListChangedServers,
|
|
2194
|
-
maxObservedCachedPrefixTokens: telemetry.maxCachedPrefixTokens
|
|
2373
|
+
maxObservedCachedPrefixTokens: telemetry.maxCachedPrefixTokens,
|
|
2374
|
+
repoOnly: isRepoOnly
|
|
2195
2375
|
});
|
|
2196
2376
|
const customAgents = scanClaudeCustomAgentSpecs({
|
|
2197
2377
|
homeDir: paths.homeDir,
|
|
2198
|
-
cwd: paths.cwd
|
|
2378
|
+
cwd: paths.cwd,
|
|
2379
|
+
repoOnly: isRepoOnly
|
|
2199
2380
|
});
|
|
2200
2381
|
const subagentCount =
|
|
2201
2382
|
telemetry.subagentSpawns7d ||
|
|
@@ -2220,10 +2401,24 @@ export function runClaudeStartupAudit({
|
|
|
2220
2401
|
maxObservedPrefixTokens: telemetry.maxCachedPrefixTokens
|
|
2221
2402
|
});
|
|
2222
2403
|
const volatilePrefix = auditVolatilePromptPrefix({
|
|
2223
|
-
ruleFilePaths:
|
|
2404
|
+
ruleFilePaths: scopedRulesFiles,
|
|
2224
2405
|
settingsLayers,
|
|
2225
2406
|
harness: 'claude-code'
|
|
2226
2407
|
});
|
|
2408
|
+
const mcpProxyAndMetaTool = evaluateMcpProxyAndMetaToolCoaching({
|
|
2409
|
+
harness: 'claude-code',
|
|
2410
|
+
eagerGateActive: mcpStartupTax.eagerGateActive,
|
|
2411
|
+
baseUrl: mcpStartupTax.baseUrl,
|
|
2412
|
+
isLocalhostProxy: mcpStartupTax.isLocalhostProxy,
|
|
2413
|
+
gatewayVerified: mcpStartupTax.gatewayVerified,
|
|
2414
|
+
toolSearchDisabled: mcpStartupTax.toolSearchDisabled,
|
|
2415
|
+
disableExperimentalBetas: mcpStartupTax.disableExperimentalBetas,
|
|
2416
|
+
isSshSession: mcpStartupTax.isSshSession,
|
|
2417
|
+
configuredServerCount: mcpStartupTax.configuredServerCount,
|
|
2418
|
+
configuredServerNames: mcpStartupTax.configuredServerNames,
|
|
2419
|
+
startupTaxTokensPerTurn: mcpStartupTax.startupTaxTokensPerTurn,
|
|
2420
|
+
file: 'env'
|
|
2421
|
+
});
|
|
2227
2422
|
const sdkCliDetected = telemetry.entrypoints.includes('sdk-cli');
|
|
2228
2423
|
const sdkCliSessionsCount = telemetry.sdkCliSessions7d || (sdkCliDetected ? 1 : 0);
|
|
2229
2424
|
const sdkCliQuotaHeuristic = {
|
|
@@ -2306,6 +2501,7 @@ export function runClaudeStartupAudit({
|
|
|
2306
2501
|
});
|
|
2307
2502
|
}
|
|
2308
2503
|
lints.push(...deprecatedModelsAndFlags.lints);
|
|
2504
|
+
lints.push(...mcpProxyAndMetaTool.lints);
|
|
2309
2505
|
|
|
2310
2506
|
let issueCount = 0;
|
|
2311
2507
|
let estimatedTurn0ReclaimableTokens = 0;
|
|
@@ -2327,6 +2523,7 @@ export function runClaudeStartupAudit({
|
|
|
2327
2523
|
issueCount += 1;
|
|
2328
2524
|
}
|
|
2329
2525
|
for (const l of lints) {
|
|
2526
|
+
if (l.severity === 'info') continue;
|
|
2330
2527
|
if ((l.ruleId === 'BO-CFG-03' || l.ruleId === 'BO-CFG-04') && mcpTaxCounted) continue;
|
|
2331
2528
|
if (l.ruleId === 'BO-CFG-09' && disableArtifactAlreadyCounted && l.message.includes('"disableArtifact"')) continue;
|
|
2332
2529
|
issueCount += 1;
|
|
@@ -2368,6 +2565,7 @@ export function runClaudeStartupAudit({
|
|
|
2368
2565
|
deprecatedModelsAndFlags,
|
|
2369
2566
|
idleCompactionRoi,
|
|
2370
2567
|
volatilePrefix,
|
|
2568
|
+
mcpProxyAndMetaTool,
|
|
2371
2569
|
sdkCliQuotaHeuristic
|
|
2372
2570
|
}
|
|
2373
2571
|
},
|
|
@@ -2452,6 +2650,9 @@ export function formatClaudeStartupAuditReport(report) {
|
|
|
2452
2650
|
if (c.sdkCliQuotaHeuristic?.detected && c.sdkCliQuotaHeuristic.message) {
|
|
2453
2651
|
lines.push(` - [info] ${c.sdkCliQuotaHeuristic.message}`);
|
|
2454
2652
|
}
|
|
2653
|
+
if (c.mcpProxyAndMetaTool?.coachingNote) {
|
|
2654
|
+
lines.push(` - [${c.mcpProxyAndMetaTool.status}] ${c.mcpProxyAndMetaTool.coachingNote}`);
|
|
2655
|
+
}
|
|
2455
2656
|
}
|
|
2456
2657
|
|
|
2457
2658
|
if (r) {
|
|
@@ -2567,32 +2768,47 @@ export function runAntigravityStartupAudit({
|
|
|
2567
2768
|
homeDir = getHomeDir(),
|
|
2568
2769
|
cwd = process.cwd(),
|
|
2569
2770
|
hostPlatform = process.platform,
|
|
2570
|
-
nowMs = Date.now()
|
|
2771
|
+
nowMs = Date.now(),
|
|
2772
|
+
repoOnly = false,
|
|
2773
|
+
ci = false
|
|
2571
2774
|
} = {}) {
|
|
2775
|
+
const isRepoOnly = Boolean(repoOnly || ci);
|
|
2572
2776
|
const paths = resolveAntigravityConfigPaths({ homeDir, cwd, platform: hostPlatform });
|
|
2573
2777
|
const projectHooks = parseJsoncReadOnly(paths.projectHooksJson);
|
|
2574
|
-
const userHooks =
|
|
2778
|
+
const userHooks = isRepoOnly
|
|
2779
|
+
? makeMissingJsoncStub(paths.userHooksJson)
|
|
2780
|
+
: parseJsoncReadOnly(paths.userHooksJson);
|
|
2575
2781
|
const projectMcp = parseJsoncReadOnly(paths.projectMcpJson);
|
|
2576
|
-
const userMcp =
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
...listMarkdownFilesInDir(paths.
|
|
2582
|
-
|
|
2782
|
+
const userMcp = isRepoOnly
|
|
2783
|
+
? makeMissingJsoncStub(paths.userMcpJson)
|
|
2784
|
+
: parseJsoncReadOnly(paths.userMcpJson);
|
|
2785
|
+
|
|
2786
|
+
const ruleFiles = isRepoOnly
|
|
2787
|
+
? filterFilesWithinCwd([...paths.rulesFiles, ...listMarkdownFilesInDir(paths.projectRulesDir)], cwd)
|
|
2788
|
+
: [
|
|
2789
|
+
...paths.rulesFiles,
|
|
2790
|
+
...listMarkdownFilesInDir(paths.projectRulesDir),
|
|
2791
|
+
...listMarkdownFilesInDir(paths.globalRulesDir)
|
|
2792
|
+
];
|
|
2583
2793
|
const rulesBucket = auditAntigravityRulesFiles(ruleFiles);
|
|
2584
|
-
const strictJsonSyntax = collectStrictJsonLints(
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2794
|
+
const strictJsonSyntax = collectStrictJsonLints(
|
|
2795
|
+
isRepoOnly
|
|
2796
|
+
? [{ res: projectHooks }, { res: projectMcp }]
|
|
2797
|
+
: [
|
|
2798
|
+
{ res: projectHooks },
|
|
2799
|
+
{ res: userHooks },
|
|
2800
|
+
{ res: projectMcp },
|
|
2801
|
+
{ res: userMcp }
|
|
2802
|
+
]
|
|
2803
|
+
);
|
|
2590
2804
|
const volatilePrefix = auditVolatilePromptPrefix({
|
|
2591
2805
|
ruleFilePaths: ruleFiles,
|
|
2592
|
-
settingsLayers:
|
|
2593
|
-
{ label: paths.projectHooksJson, doc: projectHooks }
|
|
2594
|
-
|
|
2595
|
-
|
|
2806
|
+
settingsLayers: isRepoOnly
|
|
2807
|
+
? [{ label: paths.projectHooksJson, doc: projectHooks }]
|
|
2808
|
+
: [
|
|
2809
|
+
{ label: paths.projectHooksJson, doc: projectHooks },
|
|
2810
|
+
{ label: paths.userHooksJson, doc: userHooks }
|
|
2811
|
+
],
|
|
2596
2812
|
harness: 'antigravity'
|
|
2597
2813
|
});
|
|
2598
2814
|
|
|
@@ -2616,9 +2832,17 @@ export function runAntigravityStartupAudit({
|
|
|
2616
2832
|
isEstimated: true,
|
|
2617
2833
|
summaryLine: `Antigravity MCP servers active: ${uniqueServers.length} (~${mcpTaxTokens} est. tok/turn)`
|
|
2618
2834
|
};
|
|
2835
|
+
const mcpProxyAndMetaTool = evaluateMcpProxyAndMetaToolCoaching({
|
|
2836
|
+
harness: 'antigravity',
|
|
2837
|
+
eagerGateActive: uniqueServers.length > 0,
|
|
2838
|
+
configuredServerCount: uniqueServers.length,
|
|
2839
|
+
configuredServerNames: uniqueServers,
|
|
2840
|
+
startupTaxTokensPerTurn: mcpTaxTokens,
|
|
2841
|
+
file: paths.projectMcpJson.replace(/\\/g, '/')
|
|
2842
|
+
});
|
|
2619
2843
|
|
|
2620
|
-
const lints = [...strictJsonSyntax.lints, ...volatilePrefix.lints];
|
|
2621
|
-
let issueCount = lints.length;
|
|
2844
|
+
const lints = [...strictJsonSyntax.lints, ...volatilePrefix.lints, ...mcpProxyAndMetaTool.lints];
|
|
2845
|
+
let issueCount = lints.filter((l) => l.severity !== 'info').length;
|
|
2622
2846
|
let estimatedTurn0ReclaimableTokens = 0;
|
|
2623
2847
|
if (mcpStatus === 'warn') {
|
|
2624
2848
|
issueCount += 1;
|
|
@@ -2642,6 +2866,7 @@ export function runAntigravityStartupAudit({
|
|
|
2642
2866
|
},
|
|
2643
2867
|
checks: {
|
|
2644
2868
|
mcpCheck,
|
|
2869
|
+
mcpProxyAndMetaTool,
|
|
2645
2870
|
strictJsonSyntax,
|
|
2646
2871
|
volatilePrefix
|
|
2647
2872
|
}
|
|
@@ -2675,6 +2900,9 @@ export function formatAntigravityStartupAuditReport(report) {
|
|
|
2675
2900
|
if (c?.mcpCheck) {
|
|
2676
2901
|
lines.push(` - [${c.mcpCheck.status}] ${c.mcpCheck.summaryLine}`);
|
|
2677
2902
|
}
|
|
2903
|
+
if (c?.mcpProxyAndMetaTool?.coachingNote) {
|
|
2904
|
+
lines.push(` - [${c.mcpProxyAndMetaTool.status}] ${c.mcpProxyAndMetaTool.coachingNote}`);
|
|
2905
|
+
}
|
|
2678
2906
|
if (r) {
|
|
2679
2907
|
lines.push(
|
|
2680
2908
|
` - Rules [${r.status}]: ${r.files.length} file(s), ${r.totalRuleCount} always-on rules (${r.onDemandCount} on-demand), ~${r.totalTokensEst.toLocaleString('en-US')} est. tokens`
|
|
@@ -2698,28 +2926,33 @@ export function formatAntigravityStartupAuditReport(report) {
|
|
|
2698
2926
|
export function runStartupAudit(options = {}) {
|
|
2699
2927
|
const cwd = path.resolve(options.cwd || process.cwd());
|
|
2700
2928
|
const homeDir = options.homeDir || getHomeDir();
|
|
2929
|
+
const isRepoOnly = Boolean(options.repoOnly || options.ci);
|
|
2701
2930
|
const rawClient = String(options.client || 'auto').trim().toLowerCase();
|
|
2702
2931
|
|
|
2703
2932
|
let target = rawClient;
|
|
2704
2933
|
if (rawClient === 'auto') {
|
|
2705
|
-
const hasAg =
|
|
2706
|
-
fs.existsSync(path.join(cwd, '.agents')) ||
|
|
2707
|
-
fs.existsSync(path.join(cwd, '
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
fs.existsSync(path.join(
|
|
2934
|
+
const hasAg = isRepoOnly
|
|
2935
|
+
? fs.existsSync(path.join(cwd, '.agents')) || fs.existsSync(path.join(cwd, 'GEMINI.md'))
|
|
2936
|
+
: fs.existsSync(path.join(cwd, '.agents')) ||
|
|
2937
|
+
fs.existsSync(path.join(cwd, 'GEMINI.md')) ||
|
|
2938
|
+
fs.existsSync(path.join(homeDir, '.gemini', 'config', 'hooks.json'));
|
|
2939
|
+
const hasClaude = isRepoOnly
|
|
2940
|
+
? fs.existsSync(path.join(cwd, '.claude')) ||
|
|
2941
|
+
fs.existsSync(path.join(cwd, 'CLAUDE.md')) ||
|
|
2942
|
+
fs.existsSync(path.join(cwd, '.mcp.json'))
|
|
2943
|
+
: fs.existsSync(path.join(cwd, '.claude')) || fs.existsSync(path.join(homeDir, '.claude'));
|
|
2712
2944
|
if (hasAg && hasClaude) target = 'both';
|
|
2713
2945
|
else if (hasAg) target = 'antigravity';
|
|
2714
2946
|
else target = 'claude';
|
|
2715
2947
|
}
|
|
2716
2948
|
|
|
2949
|
+
const forwardedOpts = { ...options, repoOnly: isRepoOnly };
|
|
2717
2950
|
if (target === 'antigravity' || target === 'ag') {
|
|
2718
|
-
return runAntigravityStartupAudit(
|
|
2951
|
+
return runAntigravityStartupAudit(forwardedOpts);
|
|
2719
2952
|
}
|
|
2720
2953
|
if (target === 'both') {
|
|
2721
|
-
const claudeReport = runClaudeStartupAudit(
|
|
2722
|
-
const agReport = runAntigravityStartupAudit(
|
|
2954
|
+
const claudeReport = runClaudeStartupAudit(forwardedOpts);
|
|
2955
|
+
const agReport = runAntigravityStartupAudit(forwardedOpts);
|
|
2723
2956
|
const claudeLints = claudeReport.lints || [];
|
|
2724
2957
|
const agLints = agReport.lints || [];
|
|
2725
2958
|
return {
|
|
@@ -2789,6 +3022,87 @@ export function formatStartupAuditReport(report) {
|
|
|
2789
3022
|
return formatClaudeStartupAuditReport(report);
|
|
2790
3023
|
}
|
|
2791
3024
|
|
|
3025
|
+
function escapeGhAnnotationValue(text = '') {
|
|
3026
|
+
return String(text || '')
|
|
3027
|
+
.replace(/%/g, '%25')
|
|
3028
|
+
.replace(/\r/g, '%0D')
|
|
3029
|
+
.replace(/\n/g, '%0A');
|
|
3030
|
+
}
|
|
3031
|
+
|
|
3032
|
+
function toRepoRelativePath(filePath, cwd = process.cwd()) {
|
|
3033
|
+
const raw = String(filePath || '').trim();
|
|
3034
|
+
if (!raw) return '.';
|
|
3035
|
+
if (!path.isAbsolute(raw)) return raw.replace(/\\/g, '/');
|
|
3036
|
+
const resolvedCwd = path.resolve(cwd);
|
|
3037
|
+
const rel = path.relative(resolvedCwd, path.resolve(raw));
|
|
3038
|
+
if (rel && rel !== '..' && !rel.startsWith(`..${path.sep}`) && !path.isAbsolute(rel)) {
|
|
3039
|
+
return rel.replace(/\\/g, '/');
|
|
3040
|
+
}
|
|
3041
|
+
return raw.replace(/\\/g, '/');
|
|
3042
|
+
}
|
|
3043
|
+
|
|
3044
|
+
/**
|
|
3045
|
+
* Evaluates a `runStartupAudit({ ci: true })` report for CI pass/warn/fail exit codes
|
|
3046
|
+
* and formats GitHub Actions `::error` / `::warning` workflow annotations.
|
|
3047
|
+
*/
|
|
3048
|
+
export function evaluateStartupAuditCi(report = {}, { strict = false, cwd = process.cwd() } = {}) {
|
|
3049
|
+
const lints = Array.isArray(report?.lints) ? report.lints : [];
|
|
3050
|
+
let errorCount = 0;
|
|
3051
|
+
let warnCount = 0;
|
|
3052
|
+
let infoCount = 0;
|
|
3053
|
+
const annotations = [];
|
|
3054
|
+
|
|
3055
|
+
for (const l of lints) {
|
|
3056
|
+
const sev = String(l?.severity || 'warn').toLowerCase();
|
|
3057
|
+
const rel = toRepoRelativePath(l?.file || '.', cwd);
|
|
3058
|
+
const ruleId = String(l?.ruleId || 'BO-CFG');
|
|
3059
|
+
const msg = escapeGhAnnotationValue(l?.message || ruleId);
|
|
3060
|
+
if (sev === 'error') {
|
|
3061
|
+
errorCount += 1;
|
|
3062
|
+
annotations.push(`::error file=${rel},title=${ruleId}::${msg}`);
|
|
3063
|
+
} else if (sev === 'info') {
|
|
3064
|
+
infoCount += 1;
|
|
3065
|
+
} else {
|
|
3066
|
+
warnCount += 1;
|
|
3067
|
+
annotations.push(`::warning file=${rel},title=${ruleId}::${msg}`);
|
|
3068
|
+
}
|
|
3069
|
+
}
|
|
3070
|
+
|
|
3071
|
+
for (const harnessKey of ['claudeCode', 'antigravity']) {
|
|
3072
|
+
const bucket = report?.rulesAudit?.byHarness?.[harnessKey];
|
|
3073
|
+
if (bucket && bucket.status === 'warn') {
|
|
3074
|
+
warnCount += 1;
|
|
3075
|
+
const firstFile = bucket.files?.[0]?.path || '.';
|
|
3076
|
+
const rel = toRepoRelativePath(firstFile, cwd);
|
|
3077
|
+
const adv = (bucket.advisories || []).join('; ') || 'Static Turn-0 rule threshold exceeded.';
|
|
3078
|
+
annotations.push(`::warning file=${rel},title=BO-RULE-01::${escapeGhAnnotationValue(adv)}`);
|
|
3079
|
+
}
|
|
3080
|
+
}
|
|
3081
|
+
|
|
3082
|
+
const issueCount = Number(report?.summary?.issueCount || 0);
|
|
3083
|
+
let verdict = 'PASS';
|
|
3084
|
+
let exitCode = 0;
|
|
3085
|
+
if (errorCount > 0 || (Boolean(strict) && (warnCount > 0 || issueCount > 0))) {
|
|
3086
|
+
verdict = 'FAIL';
|
|
3087
|
+
exitCode = 1;
|
|
3088
|
+
} else if (warnCount > 0 || issueCount > 0) {
|
|
3089
|
+
verdict = 'WARN';
|
|
3090
|
+
exitCode = 0;
|
|
3091
|
+
}
|
|
3092
|
+
|
|
3093
|
+
return {
|
|
3094
|
+
verdict,
|
|
3095
|
+
exitCode,
|
|
3096
|
+
strict: Boolean(strict),
|
|
3097
|
+
repoOnly: true,
|
|
3098
|
+
errorCount,
|
|
3099
|
+
warnCount,
|
|
3100
|
+
infoCount,
|
|
3101
|
+
issueCount,
|
|
3102
|
+
annotations
|
|
3103
|
+
};
|
|
3104
|
+
}
|
|
3105
|
+
|
|
2792
3106
|
export default {
|
|
2793
3107
|
CALIBRATION_MANIFEST,
|
|
2794
3108
|
RULES_THRESHOLDS,
|
|
@@ -2800,8 +3114,12 @@ export default {
|
|
|
2800
3114
|
IDLE_COMPACTION_MIN_VERSION,
|
|
2801
3115
|
DEFAULT_IDLE_COMPACT_MIN_TOKENS,
|
|
2802
3116
|
SDK_CLI_QUOTA_MULTIPLIER_HEURISTIC,
|
|
3117
|
+
COARSE_META_TOOL_MIN_SERVERS,
|
|
3118
|
+
COARSE_META_TOOL_MIN_TOKENS,
|
|
2803
3119
|
VERIFIED_CLAUDE_FLAGS,
|
|
2804
3120
|
FORBIDDEN_WORKAROUND_FLAGS,
|
|
3121
|
+
isLocalhostBaseUrl,
|
|
3122
|
+
evaluateMcpProxyAndMetaToolCoaching,
|
|
2805
3123
|
formatJsonCliArg,
|
|
2806
3124
|
validateClaudeCliCommand,
|
|
2807
3125
|
inspectJsoncSyntax,
|
|
@@ -2820,5 +3138,6 @@ export default {
|
|
|
2820
3138
|
runAntigravityStartupAudit,
|
|
2821
3139
|
formatAntigravityStartupAuditReport,
|
|
2822
3140
|
runStartupAudit,
|
|
2823
|
-
formatStartupAuditReport
|
|
3141
|
+
formatStartupAuditReport,
|
|
3142
|
+
evaluateStartupAuditCi
|
|
2824
3143
|
};
|