[codex] stop printing error message when --output-last-message is not specified (#1828)

Previously, `codex exec` was printing `Warning: no file to write last
message to` as a warning to stderr even though `--output-last-message`
was not specified, which is wrong. This fixes the code and changes
`handle_last_message()` so that it is only called when
`last_message_path` is `Some`.
This commit is contained in:
Michael Bolin
2025-08-04 15:56:32 -07:00
committed by GitHub
parent 7279080edd
commit 3f13ebce10
3 changed files with 14 additions and 22 deletions

View File

@@ -44,20 +44,14 @@ pub(crate) fn create_config_summary_entries(config: &Config) -> Vec<(&'static st
entries entries
} }
pub(crate) fn handle_last_message( pub(crate) fn handle_last_message(last_agent_message: Option<&str>, output_file: &Path) {
last_agent_message: Option<&str>, let message = last_agent_message.unwrap_or_default();
last_message_path: Option<&Path>, write_last_message_file(message, Some(output_file));
) { if last_agent_message.is_none() {
match (last_message_path, last_agent_message) { eprintln!(
(Some(path), Some(msg)) => write_last_message_file(msg, Some(path)), "Warning: no last agent message; wrote empty content to {}",
(Some(path), None) => { output_file.display()
write_last_message_file("", Some(path)); );
eprintln!(
"Warning: no last agent message; wrote empty content to {}",
path.display()
);
}
(None, _) => eprintln!("Warning: no file to write last message to."),
} }
} }

View File

@@ -170,10 +170,9 @@ impl EventProcessor for EventProcessorWithHumanOutput {
// Ignore. // Ignore.
} }
EventMsg::TaskComplete(TaskCompleteEvent { last_agent_message }) => { EventMsg::TaskComplete(TaskCompleteEvent { last_agent_message }) => {
handle_last_message( if let Some(output_file) = self.last_message_path.as_deref() {
last_agent_message.as_deref(), handle_last_message(last_agent_message.as_deref(), output_file);
self.last_message_path.as_deref(), }
);
return CodexStatus::InitiateShutdown; return CodexStatus::InitiateShutdown;
} }
EventMsg::TokenCount(TokenUsage { total_tokens, .. }) => { EventMsg::TokenCount(TokenUsage { total_tokens, .. }) => {

View File

@@ -46,10 +46,9 @@ impl EventProcessor for EventProcessorWithJsonOutput {
CodexStatus::Running CodexStatus::Running
} }
EventMsg::TaskComplete(TaskCompleteEvent { last_agent_message }) => { EventMsg::TaskComplete(TaskCompleteEvent { last_agent_message }) => {
handle_last_message( if let Some(output_file) = self.last_message_path.as_deref() {
last_agent_message.as_deref(), handle_last_message(last_agent_message.as_deref(), output_file);
self.last_message_path.as_deref(), }
);
CodexStatus::InitiateShutdown CodexStatus::InitiateShutdown
} }
EventMsg::ShutdownComplete => CodexStatus::Shutdown, EventMsg::ShutdownComplete => CodexStatus::Shutdown,