Trait for agent hook adapters. Each AI coding agent (Claude Code, Gemini CLI, Codex, OpenCode) implements this trait to: 1. **Parse** agent-specific JSON from stdin into a common [`TurnEvent`] 2. **Install** hooks into the agent's configuration file 3. **Uninstall** hooks from the agent's configuration file 4. **Detect** whether hooks are currently installed Implementations must be `Send + Sync
| 127 | /// can return `Ok(0)` / `Ok(())` for agents that don't support hook |
| 128 | /// installation (e.g., agents detected via file watching instead). |
| 129 | pub trait AgentHook: Send + Sync + fmt::Debug { |
| 130 | /// Returns the registry key for this agent. |
| 131 | /// |
| 132 | /// This is the string used in CLI commands: |
| 133 | /// `atomic agent enable --agent <name>` |
| 134 | /// `atomic agent hooks <name> <verb>` |
| 135 | /// |
| 136 | /// Convention: lowercase with hyphens (e.g., "claude-code", "gemini-cli"). |
| 137 | fn name(&self) -> &str; |
| 138 | |
| 139 | /// Returns a human-readable display name. |
| 140 | /// |
| 141 | /// Used in UI output and log messages (e.g., "Claude Code", "Gemini CLI"). |
| 142 | fn display_name(&self) -> &str; |
| 143 | |
| 144 | /// Parse hook input from an agent callback into a normalized [`TurnEvent`]. |
| 145 | /// |
| 146 | /// The `input` parameter is the raw bytes read from stdin when the agent |
| 147 | /// invokes the hook. Each agent sends a different JSON format. |
| 148 | /// |
| 149 | /// # Arguments |
| 150 | /// |
| 151 | /// * `hook_type` - The type of lifecycle event (from the CLI verb) |
| 152 | /// * `input` - Raw bytes from stdin (typically JSON) |
| 153 | /// |
| 154 | /// # Errors |
| 155 | /// |
| 156 | /// Returns [`AgentError::HookParseFailed`] if the input cannot be parsed, |
| 157 | /// or [`AgentError::HookInputEmpty`] if `input` is empty. |
| 158 | fn parse_event(&self, hook_type: HookType, input: &[u8]) -> AgentResult<TurnEvent>; |
| 159 | |
| 160 | /// Install hooks into the agent's configuration file. |
| 161 | /// |
| 162 | /// This writes entries into the agent's settings file (e.g., |
| 163 | /// `.claude/settings.json`) that call back to `atomic agent hooks`. |
| 164 | /// |
| 165 | /// # Arguments |
| 166 | /// |
| 167 | /// * `repo_root` - The repository root directory (where `.atomic/` lives) |
| 168 | /// |
| 169 | /// # Returns |
| 170 | /// |
| 171 | /// The number of hooks that were installed. Returns 0 if all hooks |
| 172 | /// were already present. |
| 173 | /// |
| 174 | /// # Errors |
| 175 | /// |
| 176 | /// Returns [`AgentError::ConfigError`] if the config file cannot be |
| 177 | /// read or written. |
| 178 | fn install(&self, repo_root: &Path) -> AgentResult<usize>; |
| 179 | |
| 180 | /// Remove hooks from the agent's configuration file. |
| 181 | /// |
| 182 | /// Removes only hooks with the `atomic agent hooks` prefix — other |
| 183 | /// hooks in the agent's config are preserved. |
| 184 | /// |
| 185 | /// # Arguments |
| 186 | /// |
nothing calls this directly
no outgoing calls
no test coverage detected