| 230 | } |
| 231 | |
| 232 | fn parse_event(&self, hook_type: HookType, input: &[u8]) -> AgentResult<TurnEvent> { |
| 233 | if input.is_empty() { |
| 234 | return Err(AgentError::HookInputEmpty { |
| 235 | agent: self.name().to_string(), |
| 236 | hook_type: hook_type.as_str().to_string(), |
| 237 | }); |
| 238 | } |
| 239 | |
| 240 | let raw_json: Value = |
| 241 | serde_json::from_slice(input).map_err(|e| AgentError::HookParseFailed { |
| 242 | agent: self.name().to_string(), |
| 243 | hook_type: hook_type.as_str().to_string(), |
| 244 | reason: e.to_string(), |
| 245 | })?; |
| 246 | |
| 247 | match hook_type { |
| 248 | HookType::TurnStart => { |
| 249 | // Antigravity: PreInvocation → TurnStart |
| 250 | let parsed: PreInvocationInput = |
| 251 | serde_json::from_value(raw_json.clone()).map_err(|e| { |
| 252 | AgentError::HookParseFailed { |
| 253 | agent: self.name().to_string(), |
| 254 | hook_type: hook_type.as_str().to_string(), |
| 255 | reason: e.to_string(), |
| 256 | } |
| 257 | })?; |
| 258 | |
| 259 | Ok(self |
| 260 | .base_event(hook_type, parsed.conversation_id, parsed.transcript_path) |
| 261 | .with_raw_json(raw_json)) |
| 262 | } |
| 263 | |
| 264 | HookType::TurnEnd => { |
| 265 | // Antigravity: Stop → TurnEnd |
| 266 | let parsed: StopInput = serde_json::from_value(raw_json.clone()).map_err(|e| { |
| 267 | AgentError::HookParseFailed { |
| 268 | agent: self.name().to_string(), |
| 269 | hook_type: hook_type.as_str().to_string(), |
| 270 | reason: e.to_string(), |
| 271 | } |
| 272 | })?; |
| 273 | |
| 274 | // Normalize the termination reason into the `finish_reason` |
| 275 | // field the record pipeline understands (mirrors the Codex |
| 276 | // adapter's stop normalization). |
| 277 | let raw_json = normalize_stop_raw(raw_json); |
| 278 | |
| 279 | Ok(self |
| 280 | .base_event(hook_type, parsed.conversation_id, parsed.transcript_path) |
| 281 | .with_raw_json(raw_json)) |
| 282 | } |
| 283 | |
| 284 | HookType::PostToolUse => { |
| 285 | let parsed: PostToolUseInput = |
| 286 | serde_json::from_value(raw_json.clone()).map_err(|e| { |
| 287 | AgentError::HookParseFailed { |
| 288 | agent: self.name().to_string(), |
| 289 | hook_type: hook_type.as_str().to_string(), |