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

Method run

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

Source from the content-addressed store, hash-verified

114
115impl Command for Hooks {
116 fn run(&self) -> CliResult<()> {
117 // Read stdin (agent sends JSON here)
118 let mut input = Vec::new();
119 std::io::stdin().read_to_end(&mut input).map_err(|e| {
120 CliError::Io(std::io::Error::new(
121 e.kind(),
122 format!("Failed to read hook input from stdin: {}", e),
123 ))
124 })?;
125
126 if self.agent_name == "opencode" && self.verb == "file-snapshot" {
127 let value: serde_json::Value =
128 serde_json::from_slice(&input).map_err(|e| CliError::Internal(anyhow!(e)))?;
129 let cwd = value
130 .get("cwd")
131 .and_then(|v| v.as_str())
132 .ok_or_else(|| CliError::Internal(anyhow!("file-snapshot requires cwd")))?;
133 let extra: Vec<String> = serde_json::from_value(
134 value
135 .get("paths")
136 .cloned()
137 .unwrap_or_else(|| serde_json::json!([])),
138 )
139 .map_err(|e| CliError::Internal(anyhow!(e)))?;
140 let snapshot = atomic_agent::record::scope::snapshot(std::path::Path::new(cwd), &extra)
141 .map_err(|e| CliError::Internal(anyhow!(e)))?;
142 println!("{}", snapshot);
143 return Ok(());
144 }
145
146 if self.should_handoff_codex_lifecycle() {
147 return self.handoff_codex_lifecycle(&input);
148 }
149
150 // Look up the agent adapter
151 let registry = AgentRegistry::with_defaults();
152 let agent = registry
153 .require(&self.agent_name)
154 .map_err(|e| CliError::InvalidArgument {
155 message: format!("Unknown agent '{}': {}", self.agent_name, e),
156 })?;
157
158 // Map the CLI verb to a HookType
159 let hook_type =
160 HookType::from_verb(&self.verb).ok_or_else(|| CliError::InvalidArgument {
161 message: format!(
162 "Unknown hook verb '{}' for agent '{}'. Known verbs: {}",
163 self.verb,
164 self.agent_name,
165 agent.hook_verbs().join(", "),
166 ),
167 })?;
168
169 // Parse the agent-specific JSON into a common TurnEvent
170 let event = agent.parse_event(hook_type, &input).map_err(|e| {
171 // Log to stderr but don't fail hard on parse errors for
172 // non-critical hooks (tool use events)
173 if hook_type.is_tool_use() {

Callers

nothing calls this directly

Calls 15

snapshotFunction · 0.85
find_repository_rootFunction · 0.85
is_tool_useMethod · 0.80
set_agentMethod · 0.80
set_journal_sinkMethod · 0.80
set_managed_runMethod · 0.80
dispatchMethod · 0.80

Tested by

no test coverage detected