pub enum HookInput {
PreToolUse {
tool_name: String,
tool_input: Value,
call_id: ToolCallId,
},
PostToolUse {
tool_name: String,
tool_input: Value,
tool_output: ToolOutput,
call_id: ToolCallId,
},
PostToolFailure {
tool_name: String,
tool_input: Value,
error: String,
call_id: ToolCallId,
},
UserPromptSubmit {
prompt: String,
},
SessionStart {
session_id: SessionId,
},
SessionEnd {
session_id: SessionId,
reason: String,
},
Stop {
finish_reason: String,
},
SubAgentStart {
agent_name: String,
},
PreCompact {
trigger: String,
tokens_before: u64,
},
PostCompact {
trigger: String,
tokens_after: u64,
},
}Expand description
Hook 输入 — 每个 HookEvent 携带的上下文数据。
使用 enum 确保类型安全,Hook 实现方通过 match 获取精确类型。 所有变体均可序列化,支持跨进程 Hook(如 shell command hook)。
§Examples
use katu_core::hook::{HookEvent, HookInput};
use katu_core::ToolCallId;
use serde_json::json;
let input = HookInput::PreToolUse {
tool_name: "bash".into(),
tool_input: json!({"command": "ls -la"}),
call_id: ToolCallId::new("call_1"),
};
assert_eq!(input.event(), HookEvent::PreToolUse);
assert_eq!(input.tool_name(), Some("bash"));Variants§
PreToolUse
工具执行前。
PostToolUse
工具执行成功后。
PostToolFailure
工具执行失败后。
UserPromptSubmit
用户提交 prompt 前。
SessionStart
Session 开始。
SessionEnd
Session 结束。
Stop
Agent loop 单步结束判定。
SubAgentStart
SubAgent 启动前。
PreCompact
上下文压缩前。
PostCompact
上下文压缩后。
Implementations§
Trait Implementations§
Source§impl<'de> Deserialize<'de> for HookInput
impl<'de> Deserialize<'de> for HookInput
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for HookInput
impl RefUnwindSafe for HookInput
impl Send for HookInput
impl Sync for HookInput
impl Unpin for HookInput
impl UnsafeUnpin for HookInput
impl UnwindSafe for HookInput
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more