2025-07-23 15:03:26 -07:00
|
|
|
use std::path::Path;
|
|
|
|
|
|
2025-05-21 22:53:02 -07:00
|
|
|
use codex_core::config::Config;
|
2025-04-29 09:59:35 -07:00
|
|
|
use codex_core::protocol::Event;
|
|
|
|
|
|
2025-07-23 15:03:26 -07:00
|
|
|
pub(crate) enum CodexStatus {
|
|
|
|
|
Running,
|
|
|
|
|
InitiateShutdown,
|
|
|
|
|
Shutdown,
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-17 15:10:15 -07:00
|
|
|
pub(crate) trait EventProcessor {
|
|
|
|
|
/// Print summary of effective configuration and user prompt.
|
|
|
|
|
fn print_config_summary(&mut self, config: &Config, prompt: &str);
|
|
|
|
|
|
|
|
|
|
/// Handle a single event emitted by the agent.
|
2025-07-23 15:03:26 -07:00
|
|
|
fn process_event(&mut self, event: Event) -> CodexStatus;
|
2025-07-17 15:10:15 -07:00
|
|
|
}
|
|
|
|
|
|
2025-08-04 15:56:32 -07:00
|
|
|
pub(crate) fn handle_last_message(last_agent_message: Option<&str>, output_file: &Path) {
|
|
|
|
|
let message = last_agent_message.unwrap_or_default();
|
|
|
|
|
write_last_message_file(message, Some(output_file));
|
|
|
|
|
if last_agent_message.is_none() {
|
|
|
|
|
eprintln!(
|
|
|
|
|
"Warning: no last agent message; wrote empty content to {}",
|
|
|
|
|
output_file.display()
|
|
|
|
|
);
|
2025-07-23 15:03:26 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn write_last_message_file(contents: &str, last_message_path: Option<&Path>) {
|
|
|
|
|
if let Some(path) = last_message_path {
|
|
|
|
|
if let Err(e) = std::fs::write(path, contents) {
|
|
|
|
|
eprintln!("Failed to write last message file {path:?}: {e}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|