| 216 | } |
| 217 | |
| 218 | fn parse_event(&self, hook_type: HookType, input: &[u8]) -> AgentResult<TurnEvent> { |
| 219 | if input.is_empty() { |
| 220 | return Err(AgentError::HookInputEmpty { |
| 221 | agent: self.name().to_string(), |
| 222 | hook_type: hook_type.as_str().to_string(), |
| 223 | }); |
| 224 | } |
| 225 | |
| 226 | let (parsed, raw, timestamp) = Self::parse_input(self.name(), hook_type, input)?; |
| 227 | |
| 228 | if parsed.session_id.is_empty() { |
| 229 | return Err(AgentError::HookParseFailed { |
| 230 | agent: self.name().to_string(), |
| 231 | hook_type: hook_type.as_str().to_string(), |
| 232 | reason: "session_id is empty".to_string(), |
| 233 | }); |
| 234 | } |
| 235 | |
| 236 | let mut event = TurnEvent::new(parsed.session_id.clone(), hook_type).with_raw_json(raw); |
| 237 | |
| 238 | // Same as Claude Code: whichever hook carries the transcript sets |
| 239 | // it, and the session keeps the first one it sees. |
| 240 | if let Some(path) = &parsed.transcript_path { |
| 241 | if !path.is_empty() { |
| 242 | event = event.with_transcript_path(path.clone()); |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | // Stamp model and provider so the orchestrator can persist them on |
| 247 | // the AgentSession — same pattern as OpenCode. |
| 248 | if let Some(model) = &parsed.model { |
| 249 | if !model.is_empty() { |
| 250 | if let Some(ref mut raw_json) = event.raw_json { |
| 251 | if let Some(obj) = raw_json.as_object_mut() { |
| 252 | obj.insert( |
| 253 | "model".to_string(), |
| 254 | serde_json::Value::String(model.clone()), |
| 255 | ); |
| 256 | } |
| 257 | } |
| 258 | } |
| 259 | } |
| 260 | if let Some(provider) = &parsed.provider { |
| 261 | if !provider.is_empty() { |
| 262 | if let Some(ref mut raw_json) = event.raw_json { |
| 263 | if let Some(obj) = raw_json.as_object_mut() { |
| 264 | obj.insert( |
| 265 | "provider".to_string(), |
| 266 | serde_json::Value::String(provider.clone()), |
| 267 | ); |
| 268 | } |
| 269 | } |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | match hook_type { |
| 274 | HookType::TurnStart => { |
| 275 | // intent_title doubles as the turn prompt — used by the |