forked from steipete/CodexBar
-
Notifications
You must be signed in to change notification settings - Fork 119
CI validation mirror for #449 #461
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| //! Canonical Codex CLI executable discovery. | ||
| //! | ||
| //! Keep install-layout knowledge here so login, provider version detection, and | ||
| //! TTY launching do not drift into separate path lists. | ||
|
|
||
| use std::path::{Path, PathBuf}; | ||
| use std::process::Command; | ||
|
|
||
| /// Locate the Codex CLI using the explicit override, PATH, and known installs. | ||
| pub(crate) fn locate_codex_binary() -> Option<PathBuf> { | ||
| if let Some(path) = std::env::var_os("CODEX_BINARY") | ||
| .map(PathBuf::from) | ||
| .filter(|path| path.is_file()) | ||
| { | ||
| return Some(path); | ||
| } | ||
| if let Ok(path) = which::which("codex") { | ||
| return Some(path); | ||
| } | ||
|
|
||
| known_candidates() | ||
| .into_iter() | ||
| .find(|candidate| candidate.is_file()) | ||
| .or_else(desktop_package_binary) | ||
| } | ||
|
|
||
| fn known_candidates() -> Vec<PathBuf> { | ||
| let local_app_data = std::env::var_os("LOCALAPPDATA") | ||
| .map(PathBuf::from) | ||
| .or_else(dirs::data_local_dir) | ||
| .unwrap_or_else(|| { | ||
| dirs::home_dir() | ||
| .unwrap_or_else(|| PathBuf::from(".")) | ||
| .join("AppData") | ||
| .join("Local") | ||
| }); | ||
| let home = dirs::home_dir().unwrap_or_else(|| PathBuf::from(".")); | ||
| let desktop_bin = local_app_data.join("OpenAI").join("Codex").join("bin"); | ||
|
|
||
| let mut candidates = vec![ | ||
| desktop_bin.join("codex.exe"), | ||
| home.join(".bun").join("bin").join("codex.exe"), | ||
| local_app_data | ||
| .join("Microsoft") | ||
| .join("WindowsApps") | ||
| .join("codex.exe"), | ||
| local_app_data | ||
| .join("Programs") | ||
| .join("codex") | ||
| .join("codex.exe"), | ||
| ]; | ||
| candidates.extend(versioned_binaries(&desktop_bin)); | ||
|
|
||
| if let Some(roaming) = dirs::config_dir().or_else(dirs::data_dir) { | ||
| candidates.push(roaming.join("npm").join("codex.cmd")); | ||
| candidates.push( | ||
| roaming | ||
| .join("fnm") | ||
| .join("aliases") | ||
| .join("default") | ||
| .join("codex.cmd"), | ||
| ); | ||
| } | ||
| candidates | ||
| } | ||
|
|
||
| fn versioned_binaries(root: &Path) -> Vec<PathBuf> { | ||
| let mut binaries: Vec<_> = std::fs::read_dir(root) | ||
| .into_iter() | ||
| .flatten() | ||
| .filter_map(Result::ok) | ||
| .map(|entry| entry.path().join("codex.exe")) | ||
| .filter(|path| path.is_file()) | ||
| .collect(); | ||
| binaries.sort_by_key(|path| { | ||
| std::cmp::Reverse(path.metadata().and_then(|meta| meta.modified()).ok()) | ||
| }); | ||
| binaries | ||
| } | ||
|
|
||
| #[cfg(windows)] | ||
| fn desktop_package_binary() -> Option<PathBuf> { | ||
| use std::os::windows::process::CommandExt; | ||
|
|
||
| let powershell = PathBuf::from(std::env::var_os("WINDIR")?) | ||
| .join("System32/WindowsPowerShell/v1.0/powershell.exe"); | ||
| let output = Command::new(powershell) | ||
| .args([ | ||
| "-NoProfile", | ||
| "-NonInteractive", | ||
| "-Command", | ||
| "Get-AppxPackage -Name OpenAI.Codex | Sort-Object Version -Descending | ForEach-Object { Join-Path $_.InstallLocation 'app\\resources\\codex.exe' } | Where-Object { Test-Path -LiteralPath $_ -PathType Leaf } | Select-Object -First 1", | ||
| ]) | ||
| .creation_flags(0x0800_0000) | ||
| .output() | ||
| .ok()?; | ||
| if !output.status.success() { | ||
| return None; | ||
| } | ||
| let path = PathBuf::from(String::from_utf8(output.stdout).ok()?.trim()); | ||
| path.is_file().then_some(path) | ||
| } | ||
|
|
||
| #[cfg(not(windows))] | ||
| fn desktop_package_binary() -> Option<PathBuf> { | ||
| None | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn discovers_versioned_desktop_cli_and_ignores_incomplete_updates() { | ||
| let root = tempfile::tempdir().unwrap(); | ||
| let installed = root.path().join("hash with spaces"); | ||
| std::fs::create_dir(&installed).unwrap(); | ||
| std::fs::write(installed.join("codex.exe"), b"fixture").unwrap(); | ||
| std::fs::create_dir(root.path().join("incomplete")).unwrap(); | ||
| std::fs::write(root.path().join("unrelated"), b"fixture").unwrap(); | ||
| assert_eq!( | ||
| versioned_binaries(root.path()), | ||
| vec![installed.join("codex.exe")] | ||
| ); | ||
| assert!(versioned_binaries(&root.path().join("missing")).is_empty()); | ||
| } | ||
| } | ||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Use the Unix Bun executable name.
On non-Windows systems, this fallback checks
~/.bun/bin/codex.exe. The executable is~/.bun/bin/codex. If PATH does not include the Bun directory,which::which("codex")fails and the terminal, login, and provider flows report a missing binary although Codex is installed.Proposed fix
🤖 Prompt for AI Agents