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

Method run

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

Source from the content-addressed store, hash-verified

113
114impl Command for Hooks {
115 fn run(&self) -> CliResult<()> {
116 // Read stdin (agent sends JSON here)
117 let mut input = Vec::new();
118 std::io::stdin().read_to_end(&mut input).map_err(|e| {
119 CliError::Io(std::io::Error::new(
120 e.kind(),
121 format!("Failed to read hook input from stdin: {}", e),
122 ))
123 })?;
124
125 if self.should_handoff_codex_stop() {
126 return self.handoff_codex_stop(&input);
127 }
128
129 // Look up the agent adapter
130 let registry = AgentRegistry::with_defaults();
131 let agent = registry
132 .require(&self.agent_name)
133 .map_err(|e| CliError::InvalidArgument {
134 message: format!("Unknown agent '{}': {}", self.agent_name, e),
135 })?;
136
137 // Map the CLI verb to a HookType
138 let hook_type =
139 HookType::from_verb(&self.verb).ok_or_else(|| CliError::InvalidArgument {
140 message: format!(
141 "Unknown hook verb '{}' for agent '{}'. Known verbs: {}",
142 self.verb,
143 self.agent_name,
144 agent.hook_verbs().join(", "),
145 ),
146 })?;
147
148 // Parse the agent-specific JSON into a common TurnEvent
149 let event = agent.parse_event(hook_type, &input).map_err(|e| {
150 // Log to stderr but don't fail hard on parse errors for
151 // non-critical hooks (tool use events)
152 if hook_type.is_tool_use() {
153 eprintln!(
154 "[atomic] Warning: failed to parse {} {} input: {}",
155 self.agent_name, self.verb, e
156 );
157 // Return a generic event so we can continue
158 return CliError::Internal(anyhow!("Hook parse failed: {}", e));
159 }
160 CliError::Internal(anyhow!(
161 "Failed to parse hook input for {} {}: {}",
162 self.agent_name,
163 self.verb,
164 e
165 ))
166 })?;
167
168 // Find the repository root
169 let repo_root = find_repository_root().map_err(|e| {
170 // Log to stderr — the agent should continue even if Atomic can't find a repo
171 eprintln!("[atomic] Warning: {}", e);
172 e

Callers

nothing calls this directly

Calls 15

find_repository_rootFunction · 0.85
handoff_codex_stopMethod · 0.80
is_tool_useMethod · 0.80
set_agentMethod · 0.80
set_managed_runMethod · 0.80
dispatchMethod · 0.80
as_refMethod · 0.80
recorded_file_listMethod · 0.80
kindMethod · 0.45

Tested by

no test coverage detected