MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / parse_hook_event

Function parse_hook_event

atomic-agent/src/hooks/claude_code/parse.rs:97–127  ·  view source on GitHub ↗

Parse raw JSON input from a Claude Code hook into a [`TurnEvent`]. This is the core parsing logic extracted from the `AgentHook::parse_event` implementation. Each hook type has a different JSON schema.

(
    hook: &super::ClaudeCodeHook,
    hook_type: HookType,
    input: &[u8],
)

Source from the content-addressed store, hash-verified

95/// This is the core parsing logic extracted from the `AgentHook::parse_event`
96/// implementation. Each hook type has a different JSON schema.
97pub(super) fn parse_hook_event(
98 hook: &super::ClaudeCodeHook,
99 hook_type: HookType,
100 input: &[u8],
101) -> AgentResult<TurnEvent> {
102 let agent_name = hook.name();
103 if input.is_empty() {
104 return Err(AgentError::HookInputEmpty {
105 agent: agent_name.to_string(),
106 hook_type: hook_type.as_str().to_string(),
107 });
108 }
109
110 // Preserve raw JSON for debugging
111 let raw_json: serde_json::Value =
112 serde_json::from_slice(input).map_err(|e| AgentError::HookParseFailed {
113 agent: agent_name.to_string(),
114 hook_type: hook_type.as_str().to_string(),
115 reason: e.to_string(),
116 })?;
117
118 match hook_type {
119 HookType::SessionStart => parse_session_start(agent_name, hook_type, raw_json),
120 HookType::SessionEnd | HookType::TurnEnd => {
121 parse_session_info(agent_name, hook_type, raw_json)
122 }
123 HookType::TurnStart => parse_user_prompt(agent_name, hook_type, raw_json),
124 HookType::PreToolUse => parse_pre_tool(agent_name, hook_type, raw_json),
125 HookType::PostToolUse => parse_post_tool(agent_name, hook_type, raw_json),
126 }
127}
128
129/// Extract the session_id from parsed input, returning a default if missing.
130fn extract_session_id(session_id: Option<String>) -> String {

Callers 1

parse_eventMethod · 0.85

Calls 8

parse_session_startFunction · 0.85
parse_session_infoFunction · 0.85
parse_user_promptFunction · 0.85
parse_pre_toolFunction · 0.85
parse_post_toolFunction · 0.85
nameMethod · 0.45
is_emptyMethod · 0.45
as_strMethod · 0.45

Tested by

no test coverage detected