(&self)
| 114 | |
| 115 | impl 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() { |
nothing calls this directly
no test coverage detected