MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / run

Method run

atomic-cli/src/commands/agent/enable.rs:179–468  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

177
178impl Command for Enable {
179 fn run(&self) -> CliResult<()> {
180 // Data-driven install — definitions come from the integration's manifest.
181 if let Some(ref manifest) = self.hooks {
182 return self.run_manifest(manifest);
183 }
184
185 // Find the repository root if there is one. Packaged integrations
186 // (the normal path — every registry agent resolves to one) install
187 // entirely into the home directory per their manifest; the repo
188 // root is used only for agent auto-detection, `.atomic/sessions`,
189 // and `--agents-md` `[[repo-file]]` entries. The built-in hook
190 // install below is a fallback for when the package cannot be
191 // fetched — inside a repository it installs repo-relative, and
192 // outside one it targets the home directory, matching where the
193 // packages install.
194 let (install_base, in_repo) = match find_repository_root() {
195 Ok(root) => (root, true),
196 Err(_) => {
197 print_warning(
198 "No Atomic repository found — installing hooks globally to the home directory.",
199 );
200 print_warning(
201 "Turns are only recorded in projects that have a .atomic/ directory.",
202 );
203 let home = dirs::home_dir().ok_or_else(|| {
204 crate::error::CliError::Io(std::io::Error::new(
205 std::io::ErrorKind::NotFound,
206 "Could not determine the home directory",
207 ))
208 })?;
209 (home, false)
210 }
211 };
212
213 // Ensure .atomic/sessions directory exists — inside repositories
214 // only, so running outside a repo never touches the home .atomic/.
215 if in_repo {
216 let sessions_dir = install_base.join(".atomic").join("sessions");
217 if !sessions_dir.exists() {
218 std::fs::create_dir_all(&sessions_dir).map_err(|e| {
219 crate::error::CliError::Io(std::io::Error::new(
220 e.kind(),
221 format!("Failed to create sessions directory: {}", e),
222 ))
223 })?;
224 }
225 }
226
227 let registry = AgentRegistry::with_defaults();
228
229 // Determine which agents to install for
230 let agents_to_install: Vec<&str> = if self.all {
231 // Install for all detected agents
232 let detected = registry.detect(&install_base);
233 if detected.is_empty() {
234 // Do not install hooks when no agent is detected.
235 print_error(
236 "No agents detected in this repository — nothing to enable with --all.",

Callers 2

sync_skills_cacheFunction · 0.45
sync_integration_packageFunction · 0.45

Calls 15

find_repository_rootFunction · 0.85
print_warningFunction · 0.85
print_errorFunction · 0.85
print_successFunction · 0.85
partial_install_errorFunction · 0.85
getMethod · 0.65
resolveFunction · 0.50
run_manifestMethod · 0.45
existsMethod · 0.45
kindMethod · 0.45
detectMethod · 0.45

Tested by

no test coverage detected