| 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 mod authority; |
| 23 | pub mod config; |
| 24 | mod executor; |
| 25 | |
| 26 | #[allow(unused_imports)] |
| 27 | pub use config::{PROJECT_HOOKS_TEMPLATE, workspace_allows_project_hooks}; |
| 28 | #[allow(unused_imports)] |
| 29 | pub use executor::HookCaller; |
| 30 | pub use executor::{ |
| 31 | HOOK_CONTEXT_AGGREGATE_MAX_CHARS, HOOK_EXECUTION_RECEIPT_MAX_BYTES, HOOK_LABEL_MAX_CHARS, |
| 32 | HOOK_TEXT_FIELD_MAX_CHARS, HOOK_UPDATED_INPUT_MAX_BYTES, generic_unavailable_detail, |
| 33 | parse_tool_call_before_stdout, sanitize_hook_denial_reason, sanitize_hook_label, |
| 34 | sanitize_hook_line, sanitize_hook_text, |
| 35 | }; |
| 36 | #[cfg(any(test, feature = "test-support"))] |
| 37 | pub use executor::{HOOK_MESSAGE_SUBMIT_PAYLOAD_MAX_BYTES, message_submit_payload}; |
| 38 | pub use executor::{ |
| 39 | HookContext, HookExecutor, HookResult, MessageSubmitOutcome, ToolCallDecision, |
| 40 | TurnEndPayloadInput, TurnEndTotals, turn_end_payload, |
| 41 | }; |
| 42 | |
| 43 | pub use executor::shell_env_keys; |
| 44 |