pub struct HookExecutor { /* private fields */ }Expand description
Executes hook commands in response to agent lifecycle events.
Implementations§
Source§impl HookExecutor
impl HookExecutor
Sourcepub fn new(hooks: Vec<HookConfig>) -> Self
pub fn new(hooks: Vec<HookConfig>) -> Self
Create an executor with the given hook configurations.
Sourcepub async fn run_pre_tool_use(
&self,
tool_name: &str,
ctx: &HookContext,
) -> PreHookResult
pub async fn run_pre_tool_use( &self, tool_name: &str, ctx: &HookContext, ) -> PreHookResult
Run all matching PreToolUse hooks and return the aggregate result.
If any hook returns Block, the overall result is Block.
If any hook returns Modify, the last Modify wins.
If a hook times out, crashes, or produces non-JSON output, it degrades
to Allow (the tool call is not disrupted).
Sourcepub async fn run_post_tool_use(&self, tool_name: &str, ctx: &HookContext)
pub async fn run_post_tool_use(&self, tool_name: &str, ctx: &HookContext)
Run all matching PostToolUse hooks (fire-and-forget).
Errors are silently swallowed — post-hooks are advisory.
Sourcepub async fn run_user_prompt_submit(
&self,
prompt: &str,
session_id: &str,
cwd: &str,
) -> UserPromptHookResult
pub async fn run_user_prompt_submit( &self, prompt: &str, session_id: &str, cwd: &str, ) -> UserPromptHookResult
Run every UserPromptSubmit hook in registration order. Aggregates
results following CC’s contract:
- Any hook returning
decision: "block"(or exit non-zero) → the whole prompt is blocked; first reason wins. - Hooks emitting
hookSpecificOutput.additionalContext(JSON) or plain text on stdout → concatenated and surfaced to the agent as extra context to append to the user message. - Empty stdout / unparseable JSON → treated as a silent continue,
so a hook author can still
print(...)debug noise without accidentally injecting it into every prompt.
Each hook receives the payload as JSON on stdin (CC parity), so
scripts using json.load(sys.stdin) work unchanged.
Sourcepub async fn run_session_event(&self, event: HookEvent, ctx: &HookContext)
pub async fn run_session_event(&self, event: HookEvent, ctx: &HookContext)
Run all hooks matching a session-level event (fire-and-forget).
Sourcepub async fn execute_hook(
&self,
hook: &HookConfig,
ctx: &HookContext,
) -> Result<String>
pub async fn execute_hook( &self, hook: &HookConfig, ctx: &HookContext, ) -> Result<String>
Execute a single hook command and return its stdout.
The hook receives context via environment variables:
ATOMCODE_HOOK_EVENT— the event name (e.g.pre_tool_use)ATOMCODE_TOOL_NAME— tool name, if applicableATOMCODE_HOOK_CONTEXT— full JSON-serializedHookContext
The command is killed after hook.timeout_ms milliseconds.
Auto Trait Implementations§
impl Freeze for HookExecutor
impl RefUnwindSafe for HookExecutor
impl Send for HookExecutor
impl Sync for HookExecutor
impl Unpin for HookExecutor
impl UnsafeUnpin for HookExecutor
impl UnwindSafe for HookExecutor
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more