<img width="850" height="723" alt="image" src="https://github.com/user-attachments/assets/2ae067bf-ba6b-47bf-9ffe-d1c3f3aa1870" /> <img width="872" height="547" alt="image" src="https://github.com/user-attachments/assets/9058be24-6513-4423-9dae-2d5fd4cbf162" />
46 lines
1.3 KiB
Rust
46 lines
1.3 KiB
Rust
use std::path::Path;
|
|
|
|
use codex_core::config::Config;
|
|
use codex_core::protocol::Event;
|
|
use codex_core::protocol::SessionConfiguredEvent;
|
|
|
|
pub(crate) enum CodexStatus {
|
|
Running,
|
|
InitiateShutdown,
|
|
Shutdown,
|
|
}
|
|
|
|
pub(crate) trait EventProcessor {
|
|
/// Print summary of effective configuration and user prompt.
|
|
fn print_config_summary(
|
|
&mut self,
|
|
config: &Config,
|
|
prompt: &str,
|
|
session_configured: &SessionConfiguredEvent,
|
|
);
|
|
|
|
/// Handle a single event emitted by the agent.
|
|
fn process_event(&mut self, event: Event) -> CodexStatus;
|
|
|
|
fn print_final_output(&mut self) {}
|
|
}
|
|
|
|
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()
|
|
);
|
|
}
|
|
}
|
|
|
|
fn write_last_message_file(contents: &str, last_message_path: Option<&Path>) {
|
|
if let Some(path) = last_message_path
|
|
&& let Err(e) = std::fs::write(path, contents)
|
|
{
|
|
eprintln!("Failed to write last message file {path:?}: {e}");
|
|
}
|
|
}
|