(&self)
| 91 | |
| 92 | impl Command for Hooks { |
| 93 | fn run(&self) -> CliResult<()> { |
| 94 | // Read stdin (agent sends JSON here) |
| 95 | let mut input = Vec::new(); |
| 96 | std::io::stdin().read_to_end(&mut input).map_err(|e| { |
| 97 | CliError::Io(std::io::Error::new( |
| 98 | e.kind(), |
| 99 | format!("Failed to read hook input from stdin: {}", e), |
| 100 | )) |
| 101 | })?; |
| 102 | |
| 103 | if self.should_handoff_codex_stop() { |
| 104 | return self.handoff_codex_stop(&input); |
| 105 | } |
| 106 | |
| 107 | // Look up the agent adapter |
| 108 | let registry = AgentRegistry::with_defaults(); |
| 109 | let agent = registry |
| 110 | .require(&self.agent_name) |
| 111 | .map_err(|e| CliError::InvalidArgument { |
| 112 | message: format!("Unknown agent '{}': {}", self.agent_name, e), |
| 113 | })?; |
| 114 | |
| 115 | // Map the CLI verb to a HookType |
| 116 | let hook_type = |
| 117 | HookType::from_verb(&self.verb).ok_or_else(|| CliError::InvalidArgument { |
| 118 | message: format!( |
| 119 | "Unknown hook verb '{}' for agent '{}'. Known verbs: {}", |
| 120 | self.verb, |
| 121 | self.agent_name, |
| 122 | agent.hook_verbs().join(", "), |
| 123 | ), |
| 124 | })?; |
| 125 | |
| 126 | // Parse the agent-specific JSON into a common TurnEvent |
| 127 | let event = agent.parse_event(hook_type, &input).map_err(|e| { |
| 128 | // Log to stderr but don't fail hard on parse errors for |
| 129 | // non-critical hooks (tool use events) |
| 130 | if hook_type.is_tool_use() { |
| 131 | eprintln!( |
| 132 | "[atomic] Warning: failed to parse {} {} input: {}", |
| 133 | self.agent_name, self.verb, e |
| 134 | ); |
| 135 | // Return a generic event so we can continue |
| 136 | return CliError::Internal(anyhow!("Hook parse failed: {}", e)); |
| 137 | } |
| 138 | CliError::Internal(anyhow!( |
| 139 | "Failed to parse hook input for {} {}: {}", |
| 140 | self.agent_name, |
| 141 | self.verb, |
| 142 | e |
| 143 | )) |
| 144 | })?; |
| 145 | |
| 146 | // Find the repository root |
| 147 | let repo_root = find_repository_root().map_err(|e| { |
| 148 | // Log to stderr — the agent should continue even if Atomic can't find a repo |
| 149 | eprintln!("[atomic] Warning: {}", e); |
| 150 | e |
nothing calls this directly
no test coverage detected