(&self)
| 107 | |
| 108 | impl Command for Enable { |
| 109 | fn run(&self) -> CliResult<()> { |
| 110 | // Data-driven install — definitions come from the integration's manifest. |
| 111 | if let Some(ref manifest) = self.hooks { |
| 112 | return self.run_manifest(manifest); |
| 113 | } |
| 114 | |
| 115 | // Global install — writes to ~/.claude/settings.json |
| 116 | if self.global { |
| 117 | return self.run_global(); |
| 118 | } |
| 119 | |
| 120 | // Find the repository root |
| 121 | let repo_root = find_repository_root()?; |
| 122 | |
| 123 | // Ensure .atomic/sessions directory exists |
| 124 | let sessions_dir = repo_root.join(".atomic").join("sessions"); |
| 125 | if !sessions_dir.exists() { |
| 126 | std::fs::create_dir_all(&sessions_dir).map_err(|e| { |
| 127 | crate::error::CliError::Io(std::io::Error::new( |
| 128 | e.kind(), |
| 129 | format!("Failed to create sessions directory: {}", e), |
| 130 | )) |
| 131 | })?; |
| 132 | } |
| 133 | |
| 134 | let registry = AgentRegistry::with_defaults(); |
| 135 | |
| 136 | // Determine which agents to install for |
| 137 | let agents_to_install: Vec<&str> = if self.all { |
| 138 | // Install for all detected agents |
| 139 | let detected = registry.detect(&repo_root); |
| 140 | if detected.is_empty() { |
| 141 | // Do not install hooks when no agent is detected. |
| 142 | print_error( |
| 143 | "No agents detected in this repository — nothing to enable with --all.", |
| 144 | ); |
| 145 | print_warning( |
| 146 | "Create a .claude/, .gemini/, or .agents/ directory first, or use --agent <name>.", |
| 147 | ); |
| 148 | return Err(crate::error::CliError::InvalidArgument { |
| 149 | message: "no agents detected for --all".to_string(), |
| 150 | }); |
| 151 | } |
| 152 | detected |
| 153 | } else if let Some(ref name) = self.agent { |
| 154 | // Specific agent requested — validate it exists |
| 155 | registry |
| 156 | .require(name) |
| 157 | .map_err(|e| crate::error::CliError::InvalidArgument { |
| 158 | message: format!("Unknown agent '{}': {}", name, e), |
| 159 | })?; |
| 160 | vec![name.as_str()] |
| 161 | } else { |
| 162 | // Auto-detect |
| 163 | let detected = registry.detect(&repo_root); |
| 164 | if detected.is_empty() { |
| 165 | // No agent detected — try to install for all, with a hint |
| 166 | let available = registry.list(); |
no test coverage detected