| 21 | const cgShort = (n) => n.replace('mcp__codegraph__codegraph_', '').replace('mcp__codegraph__', ''); |
| 22 | |
| 23 | function parse(file) { |
| 24 | if (!existsSync(file)) return null; |
| 25 | const lines = readFileSync(file, 'utf8').split('\n').filter(Boolean); |
| 26 | const calls = []; let result = null, initCg = 0; |
| 27 | for (const l of lines) { |
| 28 | let ev; try { ev = JSON.parse(l); } catch { continue; } |
| 29 | if (ev.type === 'system' && ev.subtype === 'init') initCg = (ev.tools || []).filter(t => /codegraph/.test(t)).length; |
| 30 | if (ev.type === 'assistant') for (const b of (ev.message?.content || [])) if (b.type === 'tool_use') |
| 31 | calls.push({ id: b.id, name: b.name, out: 0 }); |
| 32 | if (ev.type === 'user') for (const b of (ev.message?.content || [])) if (b.type === 'tool_result') { |
| 33 | const c = b.content; |
| 34 | const txt = typeof c === 'string' ? c : Array.isArray(c) ? c.map(x => x?.text || '').join('') : ''; |
| 35 | const call = calls.find(k => k.id === b.tool_use_id); if (call) call.out = txt.length; |
| 36 | } |
| 37 | if (ev.type === 'result') result = ev; |
| 38 | } |
| 39 | const cg = calls.filter(c => c.name.includes('codegraph')); |
| 40 | return { |
| 41 | initCg, |
| 42 | reads: calls.filter(c => c.name === 'Read').length, |
| 43 | greps: calls.filter(c => c.name === 'Grep').length + calls.filter(c => c.name === 'Glob').length, |
| 44 | cgCalls: cg.length, |
| 45 | cgSeq: cg.map(c => cgShort(c.name)), |
| 46 | cgOut: cg.reduce((s, c) => s + c.out, 0), |
| 47 | traceUsed: cg.some(c => c.name.includes('trace')), |
| 48 | turns: result?.num_turns ?? null, |
| 49 | dur: result?.duration_ms ? Math.round(result.duration_ms / 1000) : null, |
| 50 | cost: result?.total_cost_usd || 0, |
| 51 | ok: result?.subtype === 'success', |
| 52 | }; |
| 53 | } |
| 54 | |
| 55 | // repo -> arm -> [runs] |
| 56 | const data = {}; |