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