(&self)
| 153 | |
| 154 | impl Command for Enable { |
| 155 | fn run(&self) -> CliResult<()> { |
| 156 | // Data-driven install — definitions come from the integration's manifest. |
| 157 | if let Some(ref manifest) = self.hooks { |
| 158 | return self.run_manifest(manifest); |
| 159 | } |
| 160 | |
| 161 | // Global install — writes to ~/.claude/settings.json |
| 162 | if self.global { |
| 163 | return self.run_global(); |
| 164 | } |
| 165 | |
| 166 | // Find the repository root |
| 167 | let repo_root = find_repository_root()?; |
| 168 | |
| 169 | // Ensure .atomic/sessions directory exists |
| 170 | let sessions_dir = repo_root.join(".atomic").join("sessions"); |
| 171 | if !sessions_dir.exists() { |
| 172 | std::fs::create_dir_all(&sessions_dir).map_err(|e| { |
| 173 | crate::error::CliError::Io(std::io::Error::new( |
| 174 | e.kind(), |
| 175 | format!("Failed to create sessions directory: {}", e), |
| 176 | )) |
| 177 | })?; |
| 178 | } |
| 179 | |
| 180 | let registry = AgentRegistry::with_defaults(); |
| 181 | |
| 182 | // Determine which agents to install for |
| 183 | let agents_to_install: Vec<&str> = if self.all { |
| 184 | // Install for all detected agents |
| 185 | let detected = registry.detect(&repo_root); |
| 186 | if detected.is_empty() { |
| 187 | // Do not install hooks when no agent is detected. |
| 188 | print_error( |
| 189 | "No agents detected in this repository — nothing to enable with --all.", |
| 190 | ); |
| 191 | print_warning( |
| 192 | "Create a .claude/, .gemini/, or .agents/ directory first, or use --agent <name>.", |
| 193 | ); |
| 194 | return Err(crate::error::CliError::InvalidArgument { |
| 195 | message: "no agents detected for --all".to_string(), |
| 196 | }); |
| 197 | } |
| 198 | detected |
| 199 | } else if let Some(ref name) = self.agent { |
| 200 | // Specific agent requested — validate it exists |
| 201 | registry |
| 202 | .require(name) |
| 203 | .map_err(|e| crate::error::CliError::InvalidArgument { |
| 204 | message: format!("Unknown agent '{}': {}", name, e), |
| 205 | })?; |
| 206 | vec![name.as_str()] |
| 207 | } else { |
| 208 | // Auto-detect |
| 209 | let detected = registry.detect(&repo_root); |
| 210 | if detected.is_empty() { |
| 211 | // No agent detected — try to install for all, with a hint |
| 212 | let available = registry.list(); |
no test coverage detected