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

Method run

atomic-cli/src/commands/agent/hooks.rs:124–497  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

122
123impl Command for Hooks {
124 fn run(&self) -> CliResult<()> {
125 // Read stdin (agent sends JSON here)
126 let mut input = Vec::new();
127 std::io::stdin().read_to_end(&mut input).map_err(|e| {
128 CliError::Io(std::io::Error::new(
129 e.kind(),
130 format!("Failed to read hook input from stdin: {}", e),
131 ))
132 })?;
133
134 // Resolve managed ownership before considering Codex's background
135 // handoff. A governed ending stays in the foreground so a typed guard
136 // refusal can reach the lifecycle caller.
137 let mut managed = super::lifecycle::find_governing_lifecycle_for_hook(&self.agent_name);
138 if self.agent_name == "opencode" && self.verb == "file-snapshot" {
139 let value: serde_json::Value =
140 serde_json::from_slice(&input).map_err(|e| CliError::Internal(anyhow!(e)))?;
141 let cwd = value
142 .get("cwd")
143 .and_then(|v| v.as_str())
144 .ok_or_else(|| CliError::Internal(anyhow!("file-snapshot requires cwd")))?;
145 let extra: Vec<String> = serde_json::from_value(
146 value
147 .get("paths")
148 .cloned()
149 .unwrap_or_else(|| serde_json::json!([])),
150 )
151 .map_err(|e| CliError::Internal(anyhow!(e)))?;
152 let snapshot = atomic_agent::record::scope::snapshot(std::path::Path::new(cwd), &extra)
153 .map_err(|e| CliError::Internal(anyhow!(e)))?;
154 println!("{}", snapshot);
155 return Ok(());
156 }
157
158 if self.should_handoff_codex_lifecycle(managed.is_some()) {
159 return self.handoff_codex_lifecycle(&input);
160 }
161
162 // Look up the agent adapter
163 let registry = AgentRegistry::with_defaults();
164 let agent = registry
165 .require(&self.agent_name)
166 .map_err(|e| CliError::InvalidArgument {
167 message: format!("Unknown agent '{}': {}", self.agent_name, e),
168 })?;
169
170 // Map the CLI verb to a HookType
171 let hook_type =
172 HookType::from_verb(&self.verb).ok_or_else(|| CliError::InvalidArgument {
173 message: format!(
174 "Unknown hook verb '{}' for agent '{}'. Known verbs: {}",
175 self.verb,
176 self.agent_name,
177 agent.hook_verbs().join(", "),
178 ),
179 })?;
180
181 // Parse the agent-specific JSON into a common TurnEvent

Callers

nothing calls this directly

Calls 15

find_repository_rootFunction · 0.85
guard_agent_boundaryFunction · 0.85
database_lock_waitFunction · 0.85
sink_forFunction · 0.85

Tested by

no test coverage detected