pub struct HookRegistry { /* private fields */ }Expand description
Registry of async hook handlers. Cheap to clone.
Implementations§
Source§impl HookRegistry
impl HookRegistry
Sourcepub fn on<F, Fut>(
&mut self,
event: HookEventKind,
matcher: Option<&str>,
handler: F,
) -> &mut Selfwhere
F: Fn(HookEventPayload) -> Fut + Send + Sync + 'static,
Fut: Future<Output = HookOutput> + Send + 'static,
pub fn on<F, Fut>(
&mut self,
event: HookEventKind,
matcher: Option<&str>,
handler: F,
) -> &mut Selfwhere
F: Fn(HookEventPayload) -> Fut + Send + Sync + 'static,
Fut: Future<Output = HookOutput> + Send + 'static,
Register an async closure for a hook event.
matcher filters by tool name for tool events (regex, e.g. "Bash|Edit");
None matches everything.
let mut hooks = HookRegistry::new();
hooks.on(HookEventKind::PreToolUse, Some("Bash"), |payload| async move {
HookOutput::block("Bash is disabled")
});Sourcepub fn on_with_timeout<F, Fut>(
&mut self,
event: HookEventKind,
matcher: Option<&str>,
timeout_s: Option<u32>,
handler: F,
) -> &mut Selfwhere
F: Fn(HookEventPayload) -> Fut + Send + Sync + 'static,
Fut: Future<Output = HookOutput> + Send + 'static,
pub fn on_with_timeout<F, Fut>(
&mut self,
event: HookEventKind,
matcher: Option<&str>,
timeout_s: Option<u32>,
handler: F,
) -> &mut Selfwhere
F: Fn(HookEventPayload) -> Fut + Send + Sync + 'static,
Fut: Future<Output = HookOutput> + Send + 'static,
Same as on, with a per-hook timeout in seconds enforced by the CLI.
Sourcepub fn on_pre_tool_use<F, Fut>(&mut self, f: F) -> &mut Selfwhere
F: Fn(HookEventPayload) -> Fut + Send + Sync + 'static,
Fut: Future<Output = HookOutput> + Send + 'static,
pub fn on_pre_tool_use<F, Fut>(&mut self, f: F) -> &mut Selfwhere
F: Fn(HookEventPayload) -> Fut + Send + Sync + 'static,
Fut: Future<Output = HookOutput> + Send + 'static,
on(PreToolUse, None, f): runs before every tool call.
Sourcepub fn on_stop<F, Fut>(&mut self, f: F) -> &mut Selfwhere
F: Fn(HookEventPayload) -> Fut + Send + Sync + 'static,
Fut: Future<Output = HookOutput> + Send + 'static,
pub fn on_stop<F, Fut>(&mut self, f: F) -> &mut Selfwhere
F: Fn(HookEventPayload) -> Fut + Send + Sync + 'static,
Fut: Future<Output = HookOutput> + Send + 'static,
on(Stop, None, f).
Sourcepub fn on_user_prompt_submit<F, Fut>(&mut self, f: F) -> &mut Selfwhere
F: Fn(HookEventPayload) -> Fut + Send + Sync + 'static,
Fut: Future<Output = HookOutput> + Send + 'static,
pub fn on_user_prompt_submit<F, Fut>(&mut self, f: F) -> &mut Selfwhere
F: Fn(HookEventPayload) -> Fut + Send + Sync + 'static,
Fut: Future<Output = HookOutput> + Send + 'static,
on(UserPromptSubmit, None, f).
Sourcepub fn initialize_config(
&self,
) -> Option<HashMap<HookEventKind, Vec<HookMatcherConfig>>>
pub fn initialize_config( &self, ) -> Option<HashMap<HookEventKind, Vec<HookMatcherConfig>>>
The hooks field of the initialize request.
Sourcepub async fn dispatch(
&self,
callback_id: &str,
payload: HookEventPayload,
) -> Option<HookOutput>
pub async fn dispatch( &self, callback_id: &str, payload: HookEventPayload, ) -> Option<HookOutput>
Run the handler registered under callback_id.
Returns None when the id is unknown.
Trait Implementations§
Source§impl Clone for HookRegistry
impl Clone for HookRegistry
Source§impl Debug for HookRegistry
impl Debug for HookRegistry
Auto Trait Implementations§
impl !RefUnwindSafe for HookRegistry
impl !UnwindSafe for HookRegistry
impl Forget for HookRegistry
impl Freeze for HookRegistry
impl Move for HookRegistry
impl Send for HookRegistry
impl Sync for HookRegistry
impl Unpin for HookRegistry
impl UnsafeUnpin for HookRegistry
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