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;
7pub mod openclaw;
8
9/// Normalized event emitted by any hook parser.
10#[derive(Debug, Clone, PartialEq, Eq)]
11pub struct HookEvent {
12    pub kind: EventKind,
13    pub session_id: String,
14    pub ts_ms: u64,
15    pub payload: serde_json::Value,
16}
17
18/// Hook event kinds recognized across agents.
19#[derive(Debug, Clone, PartialEq, Eq)]
20pub enum EventKind {
21    PreToolUse,
22    PostToolUse,
23    Stop,
24    SessionStart,
25    Unknown(String),
26}
27
28impl EventKind {
29    pub fn parse(s: &str) -> Self {
30        match s {
31            "PreToolUse" | "pre_tool_use" => Self::PreToolUse,
32            "PostToolUse" | "post_tool_use" => Self::PostToolUse,
33            "Stop" | "stop" => Self::Stop,
34            "SessionStart" | "session_start" => Self::SessionStart,
35            other => Self::Unknown(other.to_string()),
36        }
37    }
38}