| 1 | //! Lifecycle hooks for the Codewhale TUI and Runtime API threads. |
| 2 | //! |
| 3 | //! Hooks fire in the interactive TUI (`crates/tui/src/tui/`), the engine turn |
| 4 | //! loop, and Runtime API threads (`runtime_threads.rs`). Which surface fires |
| 5 | //! which event is the scope table in `docs/HOOKS.md`. The unrelated |
| 6 | //! `crates/hooks` event-sink crate is a different mechanism and shares no |
| 7 | //! configuration. |
| 8 | //! |
| 9 | //! Hooks execute user-defined shell commands at: |
| 10 | //! - Session start/end |
| 11 | //! - Tool call before/after |
| 12 | //! - Mode changes |
| 13 | //! - Message submission |
| 14 | //! - Error events |
| 15 | //! - Turn completion |
| 16 | //! - Sub-agent spawn/completion |
| 17 | //! - `exec_shell` environment collection |
| 18 | //! |
| 19 | //! Configuration is done via `[[hooks.hooks]]` in config.toml. See |
| 20 | //! `docs/HOOKS.md` for the per-event contract. |
| 21 | |
| 22 | pub(crate) mod authority; |
| 23 | pub(crate) mod config; |
| 24 | mod executor; |
| 25 | |
| 26 | #[cfg(test)] |
| 27 | pub use config::ALL_HOOK_EVENTS; |
| 28 | #[allow(unused_imports)] |
| 29 | pub use config::{ |
| 30 | Hook, HookCondition, HookConfigProblem, HookEvent, HookSteering, HooksConfig, |
| 31 | PROJECT_HOOKS_TEMPLATE, workspace_allows_project_hooks, |
| 32 | }; |
| 33 | #[allow(unused_imports)] |
| 34 | pub(crate) use executor::HookCaller; |
| 35 | pub(crate) use executor::{ |
| 36 | HOOK_CONTEXT_AGGREGATE_MAX_CHARS, HOOK_EXECUTION_RECEIPT_MAX_BYTES, HOOK_LABEL_MAX_CHARS, |
| 37 | generic_unavailable_detail, parse_tool_call_before_stdout, sanitize_hook_denial_reason, |
| 38 | sanitize_hook_label, sanitize_hook_line, sanitize_hook_text, |
| 39 | }; |
| 40 | #[cfg(test)] |
| 41 | pub(crate) use executor::{ |
| 42 | HOOK_MESSAGE_SUBMIT_PAYLOAD_MAX_BYTES, HOOK_TEXT_FIELD_MAX_CHARS, message_submit_payload, |
| 43 | }; |
| 44 | pub use executor::{ |
| 45 | HookContext, HookExecutor, HookResult, MessageSubmitOutcome, ToolCallDecision, |
| 46 | TurnEndPayloadInput, TurnEndTotals, turn_end_payload, |
| 47 | }; |
| 48 | |
| 49 | pub(crate) use executor::shell_env_keys; |
| 50 |