Skip to main content

HookOutput

Struct HookOutput 

Source
pub struct HookOutput {
    pub permission: Option<HookPermission>,
    pub updated_input: Option<Value>,
    pub updated_output: Option<ToolOutput>,
    pub additional_context: Vec<String>,
    pub prevent_continuation: bool,
    pub stop_reason: Option<String>,
    pub blocking_error: Option<String>,
    pub system_message: Option<String>,
}
Expand description

Hook 的执行结果 — 告诉 Agent loop 如何继续。

§设计要点

  • Default = 无操作(passthrough),不影响正常流程
  • 多个字段独立,可同时设置(如 allow + 注入 context)
  • 权限聚合优先级由 AggregatedHookOutput 处理

§Examples

use katu_core::hook::HookOutput;

// passthrough — 什么都不做
let out = HookOutput::passthrough();
assert!(!out.has_decision());

// deny + context
let out = HookOutput::deny("dangerous")
    .with_context("This command modifies system files");
assert!(out.has_decision());

Fields§

§permission: Option<HookPermission>

权限决策 — 仅对 PreToolUse 有意义。

§updated_input: Option<Value>

修改后的工具输入 — PreToolUse 时替换原始 input。

§updated_output: Option<ToolOutput>

修改后的工具输出 — PostToolUse 时替换原始 output。

§additional_context: Vec<String>

注入给 LLM 的额外上下文。

§prevent_continuation: bool

是否阻止 Agent 继续执行。

§stop_reason: Option<String>

阻止原因(prevent_continuation = true 时展示给用户)。

§blocking_error: Option<String>

阻塞性错误 — 反馈给 model 的错误消息。

§system_message: Option<String>

系统消息 — 展示给用户的提示/警告。

Implementations§

Source§

impl HookOutput

Source

pub fn passthrough() -> Self

无操作 — 不影响正常流程。

Source

pub fn allow() -> Self

允许执行。

Source

pub fn deny(reason: impl Into<String>) -> Self

拒绝执行。

Source

pub fn ask(message: impl Into<String>) -> Self

需要用户确认。

Source

pub fn with_updated_input(self, input: Value) -> Self

设置修改后的工具输入(builder 模式)。

Source

pub fn with_updated_output(self, output: ToolOutput) -> Self

设置修改后的工具输出(builder 模式)。

Source

pub fn with_context(self, ctx: impl Into<String>) -> Self

追加额外上下文(builder 模式)。

Source

pub fn with_stop(self, reason: impl Into<String>) -> Self

阻止 Agent 继续执行(builder 模式)。

Source

pub fn with_blocking_error(self, error: impl Into<String>) -> Self

设置阻塞性错误(builder 模式)。

Source

pub fn with_system_message(self, message: impl Into<String>) -> Self

设置系统消息(builder 模式)。

Source

pub fn has_decision(&self) -> bool

是否做出了实质性决策(非 passthrough)。

Trait Implementations§

Source§

impl Clone for HookOutput

Source§

fn clone(&self) -> HookOutput

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for HookOutput

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for HookOutput

Source§

fn default() -> HookOutput

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for HookOutput

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for HookOutput

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,