-
Notifications
You must be signed in to change notification settings - Fork 6.1k
feat: Auto update approval #5185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
0d3b9fc
Auto update approval
dedrisian-oai de4cf42
fix
dedrisian-oai e26d2db
fix
dedrisian-oai 29bf645
Add tests
dedrisian-oai 0c8bb9d
Fixes
dedrisian-oai d876083
handle resume too
dedrisian-oai 4449c1a
Merge remote-tracking branch 'origin/main' into daniel/auto-update
dedrisian-oai b877d8e
Refactor
dedrisian-oai 63c401e
Fixes
dedrisian-oai 6aa4d41
nit
dedrisian-oai 1f7eebf
Add docc
dedrisian-oai 9ef1418
Fix
dedrisian-oai 224e398
clip
dedrisian-oai a34c86f
Move to onboarding stage
dedrisian-oai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__tests__update_popup.snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| --- | ||
| source: tui/src/chatwidget/tests.rs | ||
| expression: terminal.backend().vt100().screen().contents() | ||
| --- | ||
| ✨ New version available! Would you like to update? | ||
|
|
||
| Full release notes: https://github.com/openai/codex/releases/latest | ||
|
|
||
|
|
||
| › 1. Yes, update now | ||
| 2. No, not now | ||
| 3. Don't remind me | ||
|
|
||
| Press enter to confirm or esc to go back |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -59,6 +59,7 @@ mod pager_overlay; | |
| pub mod public_widgets; | ||
| mod render; | ||
| mod resume_picker; | ||
| mod selection_list; | ||
| mod session_log; | ||
| mod shimmer; | ||
| mod slash_command; | ||
|
|
@@ -70,7 +71,38 @@ mod terminal_palette; | |
| mod text_formatting; | ||
| mod tui; | ||
| mod ui_consts; | ||
| mod update_prompt; | ||
| mod version; | ||
|
|
||
| /// Update action the CLI should perform after the TUI exits. | ||
| #[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
| pub enum UpdateAction { | ||
| /// Update via `npm install -g @openai/codex@latest`. | ||
| NpmGlobalLatest, | ||
| /// Update via `bun install -g @openai/codex@latest`. | ||
| BunGlobalLatest, | ||
| /// Update via `brew upgrade codex`. | ||
| BrewUpgrade, | ||
| } | ||
|
|
||
| impl UpdateAction { | ||
| /// Returns the list of command-line arguments for invoking the update. | ||
| pub fn command_args(&self) -> (&'static str, &'static [&'static str]) { | ||
| match self { | ||
| UpdateAction::NpmGlobalLatest => ("npm", &["install", "-g", "@openai/codex@latest"]), | ||
| UpdateAction::BunGlobalLatest => ("bun", &["install", "-g", "@openai/codex@latest"]), | ||
| UpdateAction::BrewUpgrade => ("brew", &["upgrade", "codex"]), | ||
| } | ||
| } | ||
|
|
||
| /// Returns string representation of the command-line arguments for invoking the update. | ||
| pub fn command_str(&self) -> String { | ||
| let (command, args) = self.command_args(); | ||
| let args_str = args.join(" "); | ||
| format!("{command} {args_str}") | ||
| } | ||
| } | ||
|
|
||
| mod wrapping; | ||
|
|
||
| #[cfg(test)] | ||
|
|
@@ -299,6 +331,26 @@ async fn run_ratatui_app( | |
|
|
||
| let mut tui = Tui::new(terminal); | ||
|
|
||
| #[cfg(not(debug_assertions))] | ||
| { | ||
| use crate::update_prompt::UpdatePromptOutcome; | ||
|
|
||
| let skip_update_prompt = cli.prompt.as_ref().is_some_and(|prompt| !prompt.is_empty()); | ||
| if !skip_update_prompt { | ||
| match update_prompt::run_update_prompt_if_needed(&mut tui, &config).await? { | ||
| UpdatePromptOutcome::Continue => {} | ||
| UpdatePromptOutcome::RunUpdate(action) => { | ||
| crate::tui::restore()?; | ||
| return Ok(AppExitInfo { | ||
| token_usage: codex_core::protocol::TokenUsage::default(), | ||
| conversation_id: None, | ||
| update_action: Some(action), | ||
| }); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Show update banner in terminal history (instead of stderr) so it is visible | ||
| // within the TUI scrollback. Building spans keeps styling consistent. | ||
| #[cfg(not(debug_assertions))] | ||
|
|
@@ -309,9 +361,6 @@ async fn run_ratatui_app( | |
| use ratatui::text::Line; | ||
|
|
||
| let current_version = env!("CARGO_PKG_VERSION"); | ||
| let exe = std::env::current_exe()?; | ||
| let managed_by_bun = std::env::var_os("CODEX_MANAGED_BY_BUN").is_some(); | ||
| let managed_by_npm = std::env::var_os("CODEX_MANAGED_BY_NPM").is_some(); | ||
|
|
||
| let mut content_lines: Vec<Line<'static>> = vec![ | ||
| Line::from(vec![ | ||
|
|
@@ -331,27 +380,10 @@ async fn run_ratatui_app( | |
| Line::from(""), | ||
| ]; | ||
|
|
||
| if managed_by_bun { | ||
| let bun_cmd = "bun install -g @openai/codex@latest"; | ||
| content_lines.push(Line::from(vec![ | ||
| "Run ".into(), | ||
| bun_cmd.cyan(), | ||
| " to update.".into(), | ||
| ])); | ||
| } else if managed_by_npm { | ||
| let npm_cmd = "npm install -g @openai/codex@latest"; | ||
| if let Some(update_action) = get_update_action() { | ||
| content_lines.push(Line::from(vec![ | ||
| "Run ".into(), | ||
| npm_cmd.cyan(), | ||
| " to update.".into(), | ||
| ])); | ||
| } else if cfg!(target_os = "macos") | ||
| && (exe.starts_with("/opt/homebrew") || exe.starts_with("/usr/local")) | ||
| { | ||
| let brew_cmd = "brew upgrade codex"; | ||
| content_lines.push(Line::from(vec![ | ||
| "Run ".into(), | ||
| brew_cmd.cyan(), | ||
| update_action.command_str().cyan(), | ||
| " to update.".into(), | ||
| ])); | ||
| } else { | ||
|
|
@@ -405,6 +437,7 @@ async fn run_ratatui_app( | |
| return Ok(AppExitInfo { | ||
| token_usage: codex_core::protocol::TokenUsage::default(), | ||
| conversation_id: None, | ||
| update_action: None, | ||
| }); | ||
| } | ||
| if should_show_windows_wsl_screen { | ||
|
|
@@ -449,6 +482,7 @@ async fn run_ratatui_app( | |
| return Ok(AppExitInfo { | ||
| token_usage: codex_core::protocol::TokenUsage::default(), | ||
| conversation_id: None, | ||
| update_action: None, | ||
| }); | ||
| } | ||
| other => other, | ||
|
|
@@ -477,6 +511,47 @@ async fn run_ratatui_app( | |
| app_result | ||
| } | ||
|
|
||
| /// Get the update action from the environment. | ||
| /// Returns `None` if not managed by npm, bun, or brew. | ||
| #[cfg(not(debug_assertions))] | ||
| pub(crate) fn get_update_action() -> Option<UpdateAction> { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @.bolinfest took a long time cleaning up env var modifications in tests, they were causing race conditions iirc. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should I remove the test then? |
||
| let exe = std::env::current_exe().unwrap_or_default(); | ||
| let managed_by_npm = std::env::var_os("CODEX_MANAGED_BY_NPM").is_some(); | ||
| let managed_by_bun = std::env::var_os("CODEX_MANAGED_BY_BUN").is_some(); | ||
| if managed_by_npm { | ||
| Some(UpdateAction::NpmGlobalLatest) | ||
| } else if managed_by_bun { | ||
| Some(UpdateAction::BunGlobalLatest) | ||
| } else if cfg!(target_os = "macos") | ||
| && (exe.starts_with("/opt/homebrew") || exe.starts_with("/usr/local")) | ||
| { | ||
| Some(UpdateAction::BrewUpgrade) | ||
| } else { | ||
| None | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| #[cfg(not(debug_assertions))] | ||
| fn test_get_update_action() { | ||
| let prev = std::env::var_os("CODEX_MANAGED_BY_NPM"); | ||
|
|
||
| // First: no npm var -> expect None (we do not run from brew in CI) | ||
| unsafe { std::env::remove_var("CODEX_MANAGED_BY_NPM") }; | ||
| assert_eq!(get_update_action(), None); | ||
|
|
||
| // Then: with npm var -> expect NpmGlobalLatest | ||
| unsafe { std::env::set_var("CODEX_MANAGED_BY_NPM", "1") }; | ||
| assert_eq!(get_update_action(), Some(UpdateAction::NpmGlobalLatest)); | ||
|
|
||
| // Restore prior value to avoid leaking state | ||
| if let Some(v) = prev { | ||
| unsafe { std::env::set_var("CODEX_MANAGED_BY_NPM", v) }; | ||
| } else { | ||
| unsafe { std::env::remove_var("CODEX_MANAGED_BY_NPM") }; | ||
| } | ||
| } | ||
|
|
||
| #[expect( | ||
| clippy::print_stderr, | ||
| reason = "TUI should no longer be displayed, so we can write to stderr." | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.