| 29 | const sessionId = sessions[0].f.replace('.jsonl', ''); |
| 30 | |
| 31 | function tally(file) { |
| 32 | const counts = {}; |
| 33 | for (const line of readFileSync(file, 'utf8').split('\n')) { |
| 34 | if (!line) continue; |
| 35 | let ev; try { ev = JSON.parse(line); } catch { continue; } |
| 36 | const content = ev.message?.content; |
| 37 | if (!Array.isArray(content)) continue; |
| 38 | for (const b of content) { |
| 39 | if (b.type === 'tool_use') counts[b.name] = (counts[b.name] || 0) + 1; |
| 40 | } |
| 41 | } |
| 42 | return counts; |
| 43 | } |
| 44 | |
| 45 | // Sum token usage from a transcript. The TUI's "Done (…Xk tokens…)" line only |
| 46 | // covers a subagent's throughput; this works for main-thread runs too and is |