Skip to main content

kaizen/collect/hooks/
mod.rs

1// SPDX-License-Identifier: AGPL-3.0-or-later
2//! Hook event types shared by Cursor and Claude Code parsers.
3
4pub mod claude;
5pub mod cursor;
6pub mod normalize;
7
8/// Normalized event emitted by any hook parser.
9#[derive(Debug, Clone, PartialEq, Eq)]
10pub struct HookEvent {
11    pub kind: EventKind,
12    pub session_id: String,
13    pub ts_ms: u64,
14    pub payload: serde_json::Value,
15}
16
17/// Hook event kinds recognized across agents.
18#[derive(Debug, Clone, PartialEq, Eq)]
19pub enum EventKind {
20    PreToolUse,
21    PostToolUse,
22    Stop,
23    SessionStart,
24    Unknown(String),
25}
26
27impl EventKind {
28    pub fn parse(s: &str) -> Self {
29        match s {
30            "PreToolUse" | "pre_tool_use" => Self::PreToolUse,
31            "PostToolUse" | "post_tool_use" => Self::PostToolUse,
32            "Stop" | "stop" => Self::Stop,
33            "SessionStart" | "session_start" => Self::SessionStart,
34            other => Self::Unknown(other.to_string()),
35        }
36    }
37}