Parse NDJSON agent events to recover iteration/tool/cost telemetry + any error.
(stdout)
| 70 | |
| 71 | /** Parse NDJSON agent events to recover iteration/tool/cost telemetry + any error. */ |
| 72 | function parseAgentEvents(stdout) { |
| 73 | let iterations = 0, toolCalls = 0, costUsd = 0, error; |
| 74 | for (const line of stdout.split('\n')) { |
| 75 | const trimmed = line.trim(); |
| 76 | if (!trimmed.startsWith('{')) continue; |
| 77 | let ev; |
| 78 | try { ev = JSON.parse(trimmed); } catch { continue; } |
| 79 | if (ev.type === 'iteration_start' && typeof ev.iteration === 'number') iterations = Math.max(iterations, ev.iteration); |
| 80 | if (ev.type === 'tool_call_start') toolCalls += 1; |
| 81 | if (ev.type === 'budget_update' && typeof ev.lastCostUsd === 'number') costUsd += ev.lastCostUsd; |
| 82 | if (ev.type === 'error' && ev.message) error = ev.message; |
| 83 | } |
| 84 | return { iterations, toolCalls, costUsd, error }; |
| 85 | } |
| 86 | |
| 87 | async function observeOutcome(task, cwd, runError) { |
| 88 | const existingFiles = []; |