Dispatch a turn event through the orchestrator. This is the main entry point called by the CLI hook handler. It: 1. Routes the event to the appropriate handler based on `event_type` 2. Loads or creates the session state 3. Runs the state machine transition 4. Executes any actions (begin/end turn, record change) 5. Saves the updated session state 6. Returns a `DispatchResult` with any data to send
(&mut self, event: TurnEvent)
| 524 | /// Most errors are non-fatal — the orchestrator logs warnings and |
| 525 | /// continues. Fatal errors (session store IO failure, etc.) are propagated. |
| 526 | pub async fn dispatch(&mut self, event: TurnEvent) -> AgentResult<DispatchResult> { |
| 527 | match event.event_type { |
| 528 | HookType::SessionStart => self.handle_session_start(event).await, |
| 529 | HookType::TurnStart => self.handle_turn_start(event).await, |
| 530 | HookType::TurnEnd => self.handle_turn_end(event).await, |
| 531 | HookType::SessionEnd => self.handle_session_end(event).await, |
| 532 | HookType::PreToolUse | HookType::PostToolUse => self.handle_tool_use(event).await, |
| 533 | } |
| 534 | } |
| 535 | } |
| 536 | |
| 537 | // ═══════════════════════════════════════════════════════════════════════ |