diff --git a/codex-rs/cli/src/main.rs b/codex-rs/cli/src/main.rs index 7e9f24afdd..6221628436 100644 --- a/codex-rs/cli/src/main.rs +++ b/codex-rs/cli/src/main.rs @@ -234,11 +234,30 @@ fn format_exit_messages(exit_info: AppExitInfo, color_enabled: bool) -> Vec anyhow::Result<()> { + let update_action = exit_info.update_action; let color_enabled = supports_color::on(Stream::Stdout).is_some(); for line in format_exit_messages(exit_info, color_enabled) { println!("{line}"); } + if let Some(action) = update_action { + run_update_action(action)?; + } + Ok(()) +} + +fn run_update_action(action: UpdateAction) -> anyhow::Result<()> { + println!(); + let (cmd, args) = action.command_args(); + let cmd_str = action.command_str(); + println!("Updating Codex via `{cmd_str}`..."); + let status = std::process::Command::new(cmd).args(args).status()?; + if !status.success() { + anyhow::bail!("`{cmd_str}` failed with status {status}"); + } + println!(); + println!("🎉 Update ran successfully! Please restart Codex."); + Ok(()) } #[derive(Debug, Default, Parser, Clone)] @@ -323,13 +342,7 @@ async fn cli_main(codex_linux_sandbox_exe: Option) -> anyhow::Result<() root_config_overrides.clone(), ); let exit_info = codex_tui::run_main(interactive, codex_linux_sandbox_exe).await?; - let action = exit_info.update_action; - print_exit_messages(exit_info); - if let Some(action) = action { - run_update_action(action)?; - // After update completes, exit immediately. - return Ok(()); - } + handle_app_exit(exit_info)?; } Some(Subcommand::Exec(mut exec_cli)) => { prepend_config_flags( @@ -362,13 +375,7 @@ async fn cli_main(codex_linux_sandbox_exe: Option) -> anyhow::Result<() config_overrides, ); let exit_info = codex_tui::run_main(interactive, codex_linux_sandbox_exe).await?; - let action = exit_info.update_action; - print_exit_messages(exit_info); - if let Some(action) = action { - run_update_action(action)?; - // After update completes, exit immediately. - return Ok(()); - } + handle_app_exit(exit_info); } Some(Subcommand::Login(mut login_cli)) => { prepend_config_flags( @@ -570,20 +577,6 @@ fn print_completion(cmd: CompletionCommand) { generate(cmd.shell, &mut app, name, &mut std::io::stdout()); } -fn run_update_action(action: UpdateAction) -> anyhow::Result<()> { - println!(); - let (cmd, args) = action.command_args(); - let cmd_str = action.command_str(); - println!("Updating Codex via {cmd_str}…"); - let status = std::process::Command::new(cmd).args(args).status()?; - if !status.success() { - anyhow::bail!("`{cmd_str}` failed with status {status}"); - } - println!(); - println!("🎉 Update ran successfully! Please restart Codex."); - Ok(()) -} - #[cfg(test)] mod tests { use super::*; diff --git a/codex-rs/tui/src/chatwidget.rs b/codex-rs/tui/src/chatwidget.rs index 5faec1cf47..481b5925cb 100644 --- a/codex-rs/tui/src/chatwidget.rs +++ b/codex-rs/tui/src/chatwidget.rs @@ -53,8 +53,6 @@ use ratatui::buffer::Buffer; use ratatui::layout::Constraint; use ratatui::layout::Layout; use ratatui::layout::Rect; -use ratatui::style::Stylize as _; -use ratatui::text::Line; use ratatui::widgets::Widget; use ratatui::widgets::WidgetRef; use tokio::sync::mpsc::UnboundedSender; @@ -78,12 +76,10 @@ use crate::exec_cell::CommandOutput; use crate::exec_cell::ExecCell; use crate::exec_cell::new_active_exec_command; use crate::get_git_diff::get_git_diff; -use crate::get_update_action; use crate::history_cell; use crate::history_cell::AgentMessageCell; use crate::history_cell::HistoryCell; use crate::history_cell::McpToolCallCell; -use crate::history_cell::padded_emoji; use crate::markdown::append_markdown; use crate::slash_command::SlashCommand; use crate::status::RateLimitSnapshotDisplay; @@ -97,9 +93,6 @@ use self::agent::spawn_agent_from_existing; mod session_header; use self::session_header::SessionHeader; use crate::streaming::controller::StreamController; -use std::path::Path; - -use crate::UpdateAction; use chrono::Local; use codex_common::approval_presets::ApprovalPreset; use codex_common::approval_presets::builtin_approval_presets; @@ -117,6 +110,7 @@ use codex_git_tooling::GitToolingError; use codex_git_tooling::create_ghost_commit; use codex_git_tooling::restore_ghost_commit; use codex_protocol::plan_tool::UpdatePlanArgs; +use std::path::Path; use strum::IntoEnumIterator; const MAX_TRACKED_GHOST_COMMITS: usize = 20; @@ -1837,13 +1831,16 @@ impl ChatWidget { /// Open a simple modal asking to update Codex when an update action is available. #[cfg(not(debug_assertions))] pub(crate) fn handle_update_popup(&mut self) { - if let Some(update_action) = get_update_action() { + if let Some(update_action) = crate::get_update_action() { self.show_update_popup(update_action); } } #[cfg(not(debug_assertions))] - pub(crate) fn show_update_popup(&mut self, update_action: UpdateAction) { + pub(crate) fn show_update_popup(&mut self, update_action: crate::UpdateAction) { + use ratatui::style::Stylize as _; + use ratatui::text::Line; + self.bottom_pane.show_selection_view(SelectionViewParams { title: None, footer_hint: Some(standard_popup_hint_line()), @@ -1864,7 +1861,7 @@ impl ChatWidget { ], header: Box::new(ratatui::widgets::Paragraph::new(vec![ Line::from(vec![ - padded_emoji("✨").bold().cyan(), + crate::history_cell::padded_emoji("✨").bold().cyan(), "New version available! Would you like to update?".bold(), ]), Line::from(""),