| 899 | } |
| 900 | |
| 901 | fn parse_event(&self, hook_type: HookType, input: &[u8]) -> AgentResult<TurnEvent> { |
| 902 | if input.is_empty() { |
| 903 | return Err(AgentError::HookInputEmpty { |
| 904 | agent: self.name().to_string(), |
| 905 | hook_type: hook_type.as_str().to_string(), |
| 906 | }); |
| 907 | } |
| 908 | |
| 909 | let raw_json: Value = |
| 910 | serde_json::from_slice(input).map_err(|e| AgentError::HookParseFailed { |
| 911 | agent: self.name().to_string(), |
| 912 | hook_type: hook_type.as_str().to_string(), |
| 913 | reason: e.to_string(), |
| 914 | })?; |
| 915 | |
| 916 | match hook_type { |
| 917 | HookType::TurnStart => { |
| 918 | // Antigravity: PreInvocation → TurnStart |
| 919 | let parsed: PreInvocationInput = |
| 920 | serde_json::from_value(raw_json.clone()).map_err(|e| { |
| 921 | AgentError::HookParseFailed { |
| 922 | agent: self.name().to_string(), |
| 923 | hook_type: hook_type.as_str().to_string(), |
| 924 | reason: e.to_string(), |
| 925 | } |
| 926 | })?; |
| 927 | |
| 928 | Ok(self |
| 929 | .base_event(hook_type, parsed.conversation_id, parsed.transcript_path) |
| 930 | .with_raw_json(raw_json)) |
| 931 | } |
| 932 | |
| 933 | HookType::TurnEnd => { |
| 934 | // Antigravity: Stop → TurnEnd |
| 935 | let parsed: StopInput = serde_json::from_value(raw_json.clone()).map_err(|e| { |
| 936 | AgentError::HookParseFailed { |
| 937 | agent: self.name().to_string(), |
| 938 | hook_type: hook_type.as_str().to_string(), |
| 939 | reason: e.to_string(), |
| 940 | } |
| 941 | })?; |
| 942 | |
| 943 | // Normalize the termination reason into the `finish_reason` |
| 944 | // field the record pipeline understands (mirrors the Codex |
| 945 | // adapter's stop normalization). |
| 946 | let raw_json = normalize_stop_raw(raw_json); |
| 947 | |
| 948 | Ok(self |
| 949 | .base_event(hook_type, parsed.conversation_id, parsed.transcript_path) |
| 950 | .with_raw_json(raw_json)) |
| 951 | } |
| 952 | |
| 953 | HookType::PostToolUse => { |
| 954 | let parsed: PostToolUseInput = |
| 955 | serde_json::from_value(raw_json.clone()).map_err(|e| { |
| 956 | AgentError::HookParseFailed { |
| 957 | agent: self.name().to_string(), |
| 958 | hook_type: hook_type.as_str().to_string(), |