(&self)
| 68 | |
| 69 | impl Command for Receive { |
| 70 | fn run(&self) -> CliResult<()> { |
| 71 | let repo_root = crate::commands::find_repository_root_from(&self.repository)?; |
| 72 | |
| 73 | let registry = AgentRegistry::with_defaults(); |
| 74 | let agent = registry |
| 75 | .require(&self.agent) |
| 76 | .map_err(|e| CliError::InvalidArgument { |
| 77 | message: format!("Unknown agent '{}': {}", self.agent, e), |
| 78 | })?; |
| 79 | let agent_name = agent.name().to_string(); |
| 80 | let agent_display = agent.display_name().to_string(); |
| 81 | |
| 82 | // Keep the entry-point outcome separate from the service's event-type |
| 83 | // outcome: malformed stdin and transport failures never reach the |
| 84 | // service, but a later successful receive must clear those failures. |
| 85 | let mut hook_context = super::hook_log::HookContext::from_input(&[]); |
| 86 | let dispatch = (|| { |
| 87 | let mut input = Vec::new(); |
| 88 | std::io::stdin().read_to_end(&mut input).map_err(|e| { |
| 89 | CliError::Io(std::io::Error::new( |
| 90 | e.kind(), |
| 91 | format!("Failed to read typed event from stdin: {}", e), |
| 92 | )) |
| 93 | })?; |
| 94 | hook_context = super::hook_log::HookContext::from_input(&input); |
| 95 | let event: TurnEvent = |
| 96 | serde_json::from_slice(&input).map_err(|e| CliError::InvalidArgument { |
| 97 | message: format!("Invalid typed TurnEvent JSON: {}", e), |
| 98 | })?; |
| 99 | let mut event_context = super::hook_log::HookContext::from_event(&event); |
| 100 | event_context.parent_session_id = hook_context |
| 101 | .parent_session_id |
| 102 | .clone() |
| 103 | .or(event_context.parent_session_id); |
| 104 | hook_context = event_context; |
| 105 | |
| 106 | let agent_identity = |
| 107 | super::identity::resolve_effective_agent_identity().map(|(name, _)| name); |
| 108 | |
| 109 | // Both local and daemon transports call the same libatomic handler. |
| 110 | crate::commands::rpc::dispatch_turn_event( |
| 111 | &repo_root, |
| 112 | &event, |
| 113 | &agent_name, |
| 114 | &agent_display, |
| 115 | agent_identity, |
| 116 | &hook_context, |
| 117 | ) |
| 118 | })(); |
| 119 | let result = super::hook_log::record_result( |
| 120 | &repo_root, |
| 121 | &hook_context, |
| 122 | &agent_name, |
| 123 | &agent_display, |
| 124 | "receive", |
| 125 | dispatch, |
| 126 | )?; |
| 127 |
nothing calls this directly
no test coverage detected