| 730 | } |
| 731 | |
| 732 | fn handoff_codex_lifecycle(&self, input: &[u8]) -> CliResult<()> { |
| 733 | let exe = std::env::current_exe().map_err(|e| { |
| 734 | CliError::Internal(anyhow!("Failed to resolve atomic executable: {}", e)) |
| 735 | })?; |
| 736 | |
| 737 | let mut child = ProcessCommand::new(exe) |
| 738 | .arg("agent") |
| 739 | .arg("hooks") |
| 740 | .arg(&self.agent_name) |
| 741 | .arg(&self.verb) |
| 742 | .arg("--foreground") |
| 743 | .stdin(Stdio::piped()) |
| 744 | .stdout(Stdio::null()) |
| 745 | .stderr(Stdio::null()) |
| 746 | .spawn() |
| 747 | .map_err(|e| { |
| 748 | CliError::Internal(anyhow!( |
| 749 | "Failed to start background Codex {} worker: {}", |
| 750 | self.verb, |
| 751 | e, |
| 752 | )) |
| 753 | })?; |
| 754 | |
| 755 | if let Some(mut stdin) = child.stdin.take() { |
| 756 | stdin.write_all(input).map_err(|e| { |
| 757 | CliError::Io(std::io::Error::new( |
| 758 | e.kind(), |
| 759 | format!( |
| 760 | "Failed to pass Codex {} input to background worker: {}", |
| 761 | self.verb, e, |
| 762 | ), |
| 763 | )) |
| 764 | })?; |
| 765 | } |
| 766 | |
| 767 | Ok(()) |
| 768 | } |
| 769 | } |
| 770 | |
| 771 | // Tests |