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

Method run

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

Source from the content-addressed store, hash-verified

97
98impl Command for Enable {
99 fn run(&self) -> CliResult<()> {
100 // Data-driven install — definitions come from the integration's manifest.
101 if let Some(ref manifest) = self.hooks {
102 return self.run_manifest(manifest);
103 }
104
105 // Global install — writes to ~/.claude/settings.json
106 if self.global {
107 return self.run_global();
108 }
109
110 // Find the repository root
111 let repo_root = find_repository_root()?;
112
113 // Ensure .atomic/sessions directory exists
114 let sessions_dir = repo_root.join(".atomic").join("sessions");
115 if !sessions_dir.exists() {
116 std::fs::create_dir_all(&sessions_dir).map_err(|e| {
117 crate::error::CliError::Io(std::io::Error::new(
118 e.kind(),
119 format!("Failed to create sessions directory: {}", e),
120 ))
121 })?;
122 }
123
124 let registry = AgentRegistry::with_defaults();
125
126 // Determine which agents to install for
127 let agents_to_install: Vec<&str> = if self.all {
128 // Install for all detected agents
129 let detected = registry.detect(&repo_root);
130 if detected.is_empty() {
131 // If none detected, try all registered agents
132 print_warning("No agents detected — installing hooks for all registered agents.");
133 registry.list()
134 } else {
135 detected
136 }
137 } else if let Some(ref name) = self.agent {
138 // Specific agent requested — validate it exists
139 registry
140 .require(name)
141 .map_err(|e| crate::error::CliError::InvalidArgument {
142 message: format!("Unknown agent '{}': {}", name, e),
143 })?;
144 vec![name.as_str()]
145 } else {
146 // Auto-detect
147 let detected = registry.detect(&repo_root);
148 if detected.is_empty() {
149 // No agent detected — try to install for all, with a hint
150 let available = registry.list();
151 if available.is_empty() {
152 print_error("No agents available. This is a bug — the registry should have built-in agents.");
153 return Ok(());
154 }
155
156 // Default to the first available agent (claude-code)

Callers

nothing calls this directly

Calls 15

find_repository_rootFunction · 0.85
print_warningFunction · 0.85
print_errorFunction · 0.85
print_successFunction · 0.85
getMethod · 0.65
run_manifestMethod · 0.45
run_globalMethod · 0.45
existsMethod · 0.45
kindMethod · 0.45
detectMethod · 0.45
is_emptyMethod · 0.45
listMethod · 0.45

Tested by

no test coverage detected