From 6b446003bf7b2e0019a0db4b677791b69bae9608 Mon Sep 17 00:00:00 2001 From: Joshua LeBlanc Date: Fri, 8 Aug 2025 11:55:57 -0300 Subject: [PATCH 1/5] fix: allow windows build through --- codex-rs/tui/src/tui.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/codex-rs/tui/src/tui.rs b/codex-rs/tui/src/tui.rs index e0bf9bcc57..0447e32ae9 100644 --- a/codex-rs/tui/src/tui.rs +++ b/codex-rs/tui/src/tui.rs @@ -29,14 +29,17 @@ pub fn init(_config: &Config) -> Result { // Enable keyboard enhancement flags so modifiers for keys like Enter are disambiguated. // chat_composer.rs is using a keyboard event listener to enter for any modified keys // to create a new line that require this. - execute!( + // Some terminals (notably legacy Windows consoles) do not support + // keyboard enhancement flags. Attempt to enable them, but continue + // gracefully if unsupported. + let _ = execute!( stdout(), PushKeyboardEnhancementFlags( KeyboardEnhancementFlags::DISAMBIGUATE_ESCAPE_CODES | KeyboardEnhancementFlags::REPORT_EVENT_TYPES | KeyboardEnhancementFlags::REPORT_ALTERNATE_KEYS ) - )?; + ); set_panic_hook(); // Clear screen and move cursor to top-left before drawing UI @@ -57,7 +60,8 @@ fn set_panic_hook() { /// Restore the terminal to its original state pub fn restore() -> Result<()> { - execute!(stdout(), PopKeyboardEnhancementFlags)?; + // Pop may fail on platforms that didn't support the push; ignore errors. + let _ = execute!(stdout(), PopKeyboardEnhancementFlags); execute!(stdout(), DisableBracketedPaste)?; disable_raw_mode()?; Ok(()) From 388914420951e8d30e178eb097081ce4794e7790 Mon Sep 17 00:00:00 2001 From: Joshua LeBlanc Date: Fri, 8 Aug 2025 12:11:41 -0300 Subject: [PATCH 2/5] fix: workaround windows limits --- codex-rs/login/src/lib.rs | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/codex-rs/login/src/lib.rs b/codex-rs/login/src/lib.rs index 2a8f6749b4..2b09218813 100644 --- a/codex-rs/login/src/lib.rs +++ b/codex-rs/login/src/lib.rs @@ -5,6 +5,7 @@ use serde::Deserialize; use serde::Serialize; use std::env; use std::fs::File; +use std::fs::OpenOptions as StdOpenOptions; use std::fs::OpenOptions; use std::fs::remove_file; use std::io::Read; @@ -261,11 +262,25 @@ pub struct SpawnedLogin { pub stderr: Arc>>, } +fn ensure_login_script(codex_home: &Path) -> std::io::Result { + // Write the embedded Python script to a file to avoid very long + // command-line arguments (Windows error 206). + let script_path = codex_home.join("login_with_chatgpt.py"); + let mut file = StdOpenOptions::new() + .create(true) + .truncate(true) + .write(true) + .open(&script_path)?; + file.write_all(SOURCE_FOR_PYTHON_SERVER.as_bytes())?; + file.flush()?; + Ok(script_path) +} + /// Spawn the ChatGPT login Python server as a child process and return a handle to its process. pub fn spawn_login_with_chatgpt(codex_home: &Path) -> std::io::Result { + let script_path = ensure_login_script(codex_home)?; let mut cmd = std::process::Command::new("python3"); - cmd.arg("-c") - .arg(SOURCE_FOR_PYTHON_SERVER) + cmd.arg(&script_path) .env("CODEX_HOME", codex_home) .env("CODEX_CLIENT_ID", CLIENT_ID) .stdin(Stdio::null()) @@ -315,9 +330,9 @@ pub fn spawn_login_with_chatgpt(codex_home: &Path) -> std::io::Result std::io::Result<()> { + let script_path = ensure_login_script(codex_home)?; let child = Command::new("python3") - .arg("-c") - .arg(SOURCE_FOR_PYTHON_SERVER) + .arg(&script_path) .env("CODEX_HOME", codex_home) .env("CODEX_CLIENT_ID", CLIENT_ID) .stdin(Stdio::null()) From c0ce03c4f882915ccaf029ebc0e94acaa21135c7 Mon Sep 17 00:00:00 2001 From: Joshua LeBlanc Date: Fri, 8 Aug 2025 14:11:00 -0300 Subject: [PATCH 3/5] fix: write login script to temp dir --- codex-rs/login/src/lib.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/codex-rs/login/src/lib.rs b/codex-rs/login/src/lib.rs index 2b09218813..25369be350 100644 --- a/codex-rs/login/src/lib.rs +++ b/codex-rs/login/src/lib.rs @@ -19,6 +19,7 @@ use std::process::Stdio; use std::sync::Arc; use std::sync::Mutex; use std::time::Duration; +use tempfile::NamedTempFile; use tokio::process::Command; pub use crate::token_data::TokenData; @@ -265,15 +266,12 @@ pub struct SpawnedLogin { fn ensure_login_script(codex_home: &Path) -> std::io::Result { // Write the embedded Python script to a file to avoid very long // command-line arguments (Windows error 206). - let script_path = codex_home.join("login_with_chatgpt.py"); - let mut file = StdOpenOptions::new() - .create(true) - .truncate(true) - .write(true) - .open(&script_path)?; - file.write_all(SOURCE_FOR_PYTHON_SERVER.as_bytes())?; - file.flush()?; - Ok(script_path) + let mut tmp = NamedTempFile::new()?; + tmp.write_all(SOURCE_FOR_PYTHON_SERVER.as_bytes())?; + tmp.flush()?; + + let (_file, path) = tmp.keep()?; + Ok(path) } /// Spawn the ChatGPT login Python server as a child process and return a handle to its process. From 8eb441ba0a8cc1eba4b8443c6b0e70e28d7b41dc Mon Sep 17 00:00:00 2001 From: Michael Bolin Date: Fri, 8 Aug 2025 10:42:35 -0700 Subject: [PATCH 4/5] fix imports --- codex-rs/login/src/lib.rs | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/codex-rs/login/src/lib.rs b/codex-rs/login/src/lib.rs index 25369be350..f25f885bdc 100644 --- a/codex-rs/login/src/lib.rs +++ b/codex-rs/login/src/lib.rs @@ -5,7 +5,6 @@ use serde::Deserialize; use serde::Serialize; use std::env; use std::fs::File; -use std::fs::OpenOptions as StdOpenOptions; use std::fs::OpenOptions; use std::fs::remove_file; use std::io::Read; @@ -263,20 +262,9 @@ pub struct SpawnedLogin { pub stderr: Arc>>, } -fn ensure_login_script(codex_home: &Path) -> std::io::Result { - // Write the embedded Python script to a file to avoid very long - // command-line arguments (Windows error 206). - let mut tmp = NamedTempFile::new()?; - tmp.write_all(SOURCE_FOR_PYTHON_SERVER.as_bytes())?; - tmp.flush()?; - - let (_file, path) = tmp.keep()?; - Ok(path) -} - /// Spawn the ChatGPT login Python server as a child process and return a handle to its process. pub fn spawn_login_with_chatgpt(codex_home: &Path) -> std::io::Result { - let script_path = ensure_login_script(codex_home)?; + let script_path = write_login_script_to_disk()?; let mut cmd = std::process::Command::new("python3"); cmd.arg(&script_path) .env("CODEX_HOME", codex_home) @@ -328,7 +316,7 @@ pub fn spawn_login_with_chatgpt(codex_home: &Path) -> std::io::Result std::io::Result<()> { - let script_path = ensure_login_script(codex_home)?; + let script_path = write_login_script_to_disk()?; let child = Command::new("python3") .arg(&script_path) .env("CODEX_HOME", codex_home) @@ -357,6 +345,17 @@ pub async fn login_with_chatgpt(codex_home: &Path, capture_output: bool) -> std: } } +fn write_login_script_to_disk() -> std::io::Result { + // Write the embedded Python script to a file to avoid very long + // command-line arguments (Windows error 206). + let mut tmp = NamedTempFile::new()?; + tmp.write_all(SOURCE_FOR_PYTHON_SERVER.as_bytes())?; + tmp.flush()?; + + let (_file, path) = tmp.keep()?; + Ok(path) +} + pub fn login_with_api_key(codex_home: &Path, api_key: &str) -> std::io::Result<()> { let auth_dot_json = AuthDotJson { openai_api_key: Some(api_key.to_string()), From 7307a88aa374624e274b95fedfe49e0062ff4f38 Mon Sep 17 00:00:00 2001 From: Michael Bolin Date: Fri, 8 Aug 2025 10:47:54 -0700 Subject: [PATCH 5/5] add tempfile to Cargo.toml --- codex-rs/login/Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/codex-rs/login/Cargo.toml b/codex-rs/login/Cargo.toml index a290c01eb6..85c11505ec 100644 --- a/codex-rs/login/Cargo.toml +++ b/codex-rs/login/Cargo.toml @@ -12,6 +12,7 @@ chrono = { version = "0.4", features = ["serde"] } reqwest = { version = "0.12", features = ["json"] } serde = { version = "1", features = ["derive"] } serde_json = "1" +tempfile = "3" thiserror = "2.0.12" tokio = { version = "1", features = [ "io-std",