ricecoder_hooks/executor/mod.rs
1//! Hook execution engine
2
3pub mod condition;
4pub mod runner;
5pub mod substitution;
6
7pub use condition::ConditionEvaluator;
8pub use runner::DefaultHookExecutor;
9pub use substitution::VariableSubstitutor;
10
11use crate::error::Result;
12use crate::types::{EventContext, Hook, HookResult};
13
14/// Trait for executing hooks
15///
16/// The HookExecutor is responsible for:
17/// 1. Receiving hooks and event context
18/// 2. Evaluating hook conditions
19/// 3. Executing hook actions (commands, tool calls, AI prompts, chains)
20/// 4. Handling timeouts and errors
21/// 5. Capturing output and results
22/// 6. Providing hook isolation (failures don't affect other hooks)
23///
24/// # Examples
25///
26/// ```ignore
27/// let executor = DefaultHookExecutor::new();
28/// let hook = Hook { ... };
29/// let context = EventContext { ... };
30/// let result = executor.execute_hook(&hook, &context)?;
31/// ```
32pub trait HookExecutor: Send + Sync {
33 /// Execute a hook with the given context
34 ///
35 /// This method:
36 /// 1. Evaluates the hook condition (if present)
37 /// 2. Executes the hook action
38 /// 3. Captures output and errors
39 /// 4. Returns a HookResult with status and output
40 fn execute_hook(&self, hook: &Hook, context: &EventContext) -> Result<HookResult>;
41
42 /// Execute a hook action
43 ///
44 /// Routes to the appropriate executor based on action type:
45 /// - CommandAction: Execute shell command
46 /// - ToolCallAction: Call tool with parameters
47 /// - AiPromptAction: Send prompt to AI assistant
48 /// - ChainAction: Execute hooks in sequence
49 fn execute_action(&self, hook: &Hook, context: &EventContext) -> Result<String>;
50}