diff --git a/src/core/cache.ts b/src/core/cache.ts index 3283b1d7..f7cd6eb2 100644 --- a/src/core/cache.ts +++ b/src/core/cache.ts @@ -130,7 +130,7 @@ export interface CacheData { const cacheFilePath = (): string => path.join(getCacheDir(), 'parsed.json'); const cacheMetaPath = (): string => path.join(getCacheDir(), 'meta.json'); -const CACHE_VERSION = 30; +const CACHE_VERSION = 31; /** Refuse to JSON.parse cache files beyond these sizes: a corrupted (or * tampered) cache must degrade to a full re-parse, not OOM the host. */ diff --git a/src/core/parser-vscode-cli.test.ts b/src/core/parser-vscode-cli.test.ts index e7133954..f26eb780 100644 --- a/src/core/parser-vscode-cli.test.ts +++ b/src/core/parser-vscode-cli.test.ts @@ -15,7 +15,7 @@ import { parseCLIEventsFile, parseCLIEventsFileAsync } from './parser-vscode-cli import { getParseWarningCounts, resetParseWarnings, setCuriosityDetector } from './parser-shared'; import { detectCuriosity } from './curiosity'; import { CuriosityAnalyzer } from './analyzer-curiosity'; -import { runDetectors } from './detector-registry'; +import { runDetectors, runEmitters } from './detector-registry'; const tempDirs: string[] = []; @@ -52,6 +52,35 @@ afterEach(() => { }); describe('parseCLIEventsFileAsync', () => { + it.each([false, true])('recognizes MCP server metadata (Copilot App: %s)', async (remoteSteerable) => { + const file = writeEvents([ + { type: 'session.start', data: { sessionId: 'mcp-session', ...(remoteSteerable ? { remoteSteerable: true } : {}) } }, + ...Array.from({ length: 30 }, (_, index) => [ + { type: 'user.message', timestamp: new Date(Date.UTC(2026, 9, 1, 12, index)).toISOString(), data: { content: 'Find the issue' } }, + { type: 'assistant.message', data: { toolRequests: [{ toolName: 'github-search_code', arguments: {} }] } }, + { type: 'tool.execution_start', data: { toolName: 'github-search_code', mcpServerName: 'github' } }, + { type: 'tool.execution_start', data: { toolName: 'view' } }, + { type: 'tool.execution_start', data: { toolName: 'grep', mcpServerName: '' } }, + ]).flat(), + ]); + for (const parsed of [parseCLIEventsFile(file, 'ws', 'Workspace'), await parseCLIEventsFileAsync(file, 'ws', 'Workspace')]) { + expect(parsed?.requests).toHaveLength(30); + expect(parsed?.harness).toBe(remoteSteerable ? 'GitHub Copilot App' : 'GitHub Copilot CLI'); + expect(parsed?.requests[0].toolsUsed).toEqual(['mcp_github_github-search_code', 'view', 'grep']); + const mcpName = parsed?.requests[0].toolsUsed[0] ?? ''; + expect(mcpName.slice(4).split('_')[0]).toBe('github'); + const sessions = parsed ? [parsed] : []; + const emission = runEmitters(parsed?.requests ?? [], sessions, false).get('context-engineering-gaps'); + const withoutMcp = sessions.map(session => ({ + ...session, requests: session.requests.map(request => ({ ...request, toolsUsed: ['search', 'view', 'grep'] })), + })); + const missing = runEmitters(withoutMcp.flatMap(session => session.requests), withoutMcp, false).get('context-engineering-gaps'); + expect(emission).toBeDefined(); + expect(missing).toBeDefined(); + expect(emission?.count).toBe((missing?.count ?? 0) - 1); + } + }); + it('classifies PowerShell-only commands and parallel calls through both parser paths', async () => { setCuriosityDetector(detectCuriosity); const file = writeEvents([ diff --git a/src/core/parser-vscode-cli.ts b/src/core/parser-vscode-cli.ts index ebd52db6..93051006 100644 --- a/src/core/parser-vscode-cli.ts +++ b/src/core/parser-vscode-cli.ts @@ -438,7 +438,15 @@ function handleToolExecutionStart(ev: CLIEvent, state: CLIParseState): void { const ts = ev.timestamp ? new Date(ev.timestamp).getTime() : null; if (ts && turn.firstToolTs === null) turn.firstToolTs = ts; - addRecordedTools(turn, toolName, data.arguments); + // CLI/App logs identify MCP calls by server metadata rather than a name prefix. + // Use the MCP naming convention consumed by rules and feature analysis. + const mcpServerName = str(data.mcpServerName); + const recordedName = mcpServerName && toolName && !toolName.startsWith('mcp_') + ? `mcp_${mcpServerName}_${toolName}` + : toolName; + // The assistant request may have recorded the raw name before server metadata arrived. + if (recordedName !== toolName) turn.toolNames.delete(toolName); + addRecordedTools(turn, recordedName, data.arguments); const pending: PendingToolEdit = { editLocs: new Map(), editedFiles: new Set(recordedToolFiles(toolName, rawArgs).edited),