(
event: &HookEvent,
agent_id: &str,
depth: u32,
workspace: Option<String>,
context: Option<EventContext>,
)
| 5 | use chrono::Utc; |
| 6 | |
| 7 | pub(super) fn map_hook_event( |
| 8 | event: &HookEvent, |
| 9 | agent_id: &str, |
| 10 | depth: u32, |
| 11 | workspace: Option<String>, |
| 12 | context: Option<EventContext>, |
| 13 | ) -> Option<AhpEvent> { |
| 14 | let (event_type, payload) = match event { |
| 15 | HookEvent::PreToolUse(e) => ( |
| 16 | EventType::PreAction, |
| 17 | serde_json::json!({ |
| 18 | "tool": e.tool, |
| 19 | "arguments": e.args, |
| 20 | "working_directory": e.working_directory, |
| 21 | "recent_tools": e.recent_tools, |
| 22 | }), |
| 23 | ), |
| 24 | HookEvent::PostToolUse(e) => ( |
| 25 | EventType::PostAction, |
| 26 | serde_json::json!({ |
| 27 | "tool": e.tool, |
| 28 | "arguments": e.args, |
| 29 | "result": { |
| 30 | "success": e.result.success, |
| 31 | "output": e.result.output, |
| 32 | "exit_code": e.result.exit_code, |
| 33 | "duration_ms": e.result.duration_ms, |
| 34 | } |
| 35 | }), |
| 36 | ), |
| 37 | HookEvent::PrePrompt(e) => ( |
| 38 | EventType::PrePrompt, |
| 39 | serde_json::json!({ |
| 40 | "prompt": e.prompt, |
| 41 | "system_prompt": e.system_prompt, |
| 42 | "message_count": e.message_count, |
| 43 | }), |
| 44 | ), |
| 45 | HookEvent::GenerateStart(e) => ( |
| 46 | EventType::PrePrompt, |
| 47 | serde_json::json!({ |
| 48 | "prompt": e.prompt, |
| 49 | "session_id": e.session_id, |
| 50 | }), |
| 51 | ), |
| 52 | HookEvent::PostResponse(e) => ( |
| 53 | EventType::PostAction, |
| 54 | serde_json::json!({ |
| 55 | "response_text": e.response_text, |
| 56 | "tool_calls_count": e.tool_calls_count, |
| 57 | "usage": e.usage, |
| 58 | "duration_ms": e.duration_ms, |
| 59 | }), |
| 60 | ), |
| 61 | HookEvent::SessionStart(e) => ( |
| 62 | EventType::SessionStart, |
| 63 | serde_json::json!({ |
| 64 | "session_id": e.session_id, |
no test coverage detected