| 331 | // Plan is echoed in tool_result content as "## Approved Plan:\n<text>" or |
| 332 | // "## Approved Plan (edited by user):\n<text>" (ExitPlanModeV2Tool). |
| 333 | function extractApprovedPlan(content: ToolResultBlockParam['content']): string { |
| 334 | const text = contentToText(content) |
| 335 | // Try both markers — edited plans use a different label. |
| 336 | const markers = [ |
| 337 | '## Approved Plan (edited by user):\n', |
| 338 | '## Approved Plan:\n', |
| 339 | ] |
| 340 | for (const marker of markers) { |
| 341 | const idx = text.indexOf(marker) |
| 342 | if (idx !== -1) { |
| 343 | return text.slice(idx + marker.length).trimEnd() |
| 344 | } |
| 345 | } |
| 346 | throw new Error( |
| 347 | `ExitPlanMode approved but tool_result has no "## Approved Plan:" marker — remote may have hit the empty-plan or isAgent branch. Content preview: ${text.slice(0, 200)}`, |
| 348 | ) |
| 349 | } |
| 350 | |