Skip to main content

subcog/cli/
hook.rs

1//! Hook CLI command.
2//!
3//! Provides the `subcog hook` subcommand for Claude Code integration.
4//! Hooks are invoked by Claude Code at specific lifecycle events to
5//! inject context, detect signals, and capture memories.
6//!
7//! # Supported Hooks
8//!
9//! | Hook | Trigger | Purpose |
10//! |------|---------|---------|
11//! | `session-start` | Session begins | Inject relevant memories into context |
12//! | `user-prompt-submit` | User sends message | Detect search intent, surface memories |
13//! | `post-tool-use` | Tool execution completes | Surface related memories |
14//! | `pre-compact` | Before context compaction | Auto-capture important content |
15//! | `stop` | Session ends | Analyze session, sync to remote |
16//!
17//! # Usage
18//!
19//! ```bash
20//! # Called by Claude Code hooks configuration
21//! subcog hook session-start
22//! subcog hook user-prompt-submit --prompt "How do I implement auth?"
23//! subcog hook post-tool-use --tool-name "Read" --result "..."
24//! subcog hook pre-compact --context "..."
25//! subcog hook stop
26//! ```
27//!
28//! # Configuration
29//!
30//! Hooks are configured in `.claude/settings.json`:
31//!
32//! ```json
33//! {
34//!   "hooks": {
35//!     "SessionStart": [{ "type": "command", "command": "subcog hook session-start" }],
36//!     "UserPromptSubmit": [{ "type": "command", "command": "subcog hook user-prompt-submit" }]
37//!   }
38//! }
39//! ```
40
41/// Hook command handler (DOC-H1).
42///
43/// Entry point for Claude Code hook integrations. Dispatches to specific
44/// hook handlers based on the subcommand.
45///
46/// # Example
47///
48/// ```rust,ignore
49/// use subcog::cli::HookCommand;
50///
51/// let cmd = HookCommand::new();
52/// // Dispatch is handled by clap subcommand parsing in main.rs
53/// ```
54pub struct HookCommand;
55
56impl HookCommand {
57    /// Creates a new hook command handler.
58    ///
59    /// # Returns
60    ///
61    /// A new `HookCommand` instance ready to dispatch hook events.
62    #[must_use]
63    pub const fn new() -> Self {
64        Self
65    }
66}
67
68impl Default for HookCommand {
69    fn default() -> Self {
70        Self::new()
71    }
72}
73
74#[cfg(test)]
75mod tests {
76    use super::*;
77
78    #[test]
79    fn test_hook_command_new() {
80        let _cmd = HookCommand::new();
81    }
82
83    #[test]
84    #[allow(clippy::default_constructed_unit_structs)]
85    fn test_hook_command_default() {
86        let _cmd = HookCommand::default();
87    }
88}