- Extract validateAgent, toToolResult, runAgentWithRetries so index.ts
is wiring only; orchestration, validation, and result shaping each own
their concern.
- Separate runner internals: createRunState, handleEvent (pure event
reducer), spawnPi (process lifecycle), runOnce (single attempt).
- Track attempt/maxAttempts on SubagentStatus; surface "try x/y" in the
UI without overwriting the user-facing task with the retry preamble.
- Replace pi's default system prompt (--system-prompt) instead of
appending, so the subagent .md body is authoritative.
- Document prompt-replacement and retry/cache semantics in AGENTS.md.