Lightweight coding agent that runs in your terminal
Rust
fix: codex-arg0 no longer depends on codex-core (#12434)
Michael Bolin2fe4be1aa98b
diff --git a/codex-rs/Cargo.lock b/codex-rs/Cargo.lockindex e9fd6ed167..42521a48df 100644--- a/codex-rs/Cargo.lock+++ b/codex-rs/Cargo.lock@@ -1398,8 +1398,8 @@ version = "0.0.0"dependencies = ["anyhow","codex-apply-patch",- "codex-core","codex-linux-sandbox",+ "codex-utils-home-dir","dotenvy","tempfile","tokio",@@ -1735,6 +1735,7 @@ dependencies = ["anyhow","assert_cmd","clap",+ "codex-apply-patch","codex-arg0","codex-cloud-requirements","codex-core",diff --git a/codex-rs/apply-patch/src/lib.rs b/codex-rs/apply-patch/src/lib.rsindex f58055f450..1fc60474b9 100644--- a/codex-rs/apply-patch/src/lib.rs+++ b/codex-rs/apply-patch/src/lib.rs@@ -25,6 +25,15 @@ use crate::invocation::ExtractHeredocError;/// Detailed instructions for gpt-4.1 on how to use the `apply_patch` tool.pub const APPLY_PATCH_TOOL_INSTRUCTIONS: &str = include_str!("../apply_patch_tool_instructions.md");+/// Special argv[1] flag used when the Codex executable self-invokes to run the+/// internal `apply_patch` path.+///+/// Although this constant lives in `codex-apply-patch` (to avoid forcing+/// `codex-arg0` to depend on `codex-core`), it is part of the "codex core"+/// process-invocation contract between the apply-patch runtime and the arg0+/// dispatcher.+pub const CODEX_CORE_APPLY_PATCH_ARG1: &str = "--codex-run-as-apply-patch";+#[derive(Debug, Error, PartialEq)]pub enum ApplyPatchError {#[error(transparent)]diff --git a/codex-rs/arg0/Cargo.toml b/codex-rs/arg0/Cargo.tomlindex c82bdd58da..c5d9681327 100644--- a/codex-rs/arg0/Cargo.toml+++ b/codex-rs/arg0/Cargo.toml@@ -14,8 +14,8 @@ workspace = true[dependencies]anyhow = { workspace = true }codex-apply-patch = { workspace = true }-codex-core = { workspace = true }codex-linux-sandbox = { workspace = true }+codex-utils-home-dir = { workspace = true }dotenvy = { workspace = true }tempfile = { workspace = true }tokio = { workspace = true, features = ["rt-multi-thread"] }diff --git a/codex-rs/arg0/src/lib.rs b/codex-rs/arg0/src/lib.rsindex dd89baeff3..3ac7e017f2 100644--- a/codex-rs/arg0/src/lib.rs+++ b/codex-rs/arg0/src/lib.rs@@ -3,7 +3,8 @@ use std::future::Future;use std::path::Path;use std::path::PathBuf;-use codex_core::CODEX_APPLY_PATCH_ARG1;+use codex_apply_patch::CODEX_CORE_APPLY_PATCH_ARG1;+use codex_utils_home_dir::find_codex_home;#[cfg(unix)]use std::os::unix::fs::symlink;use tempfile::TempDir;@@ -46,7 +47,7 @@ pub fn arg0_dispatch() -> Option<Arg0PathEntryGuard> {}let argv1 = args.next().unwrap_or_default();- if argv1 == CODEX_APPLY_PATCH_ARG1 {+ if argv1 == CODEX_CORE_APPLY_PATCH_ARG1 {let patch_arg = args.next().and_then(|s| s.to_str().map(str::to_owned));let exit_code = match patch_arg {Some(patch_arg) => {@@ -58,7 +59,7 @@ pub fn arg0_dispatch() -> Option<Arg0PathEntryGuard> {}}None => {- eprintln!("Error: {CODEX_APPLY_PATCH_ARG1} requires a UTF-8 PATCH argument.");+ eprintln!("Error: {CODEX_CORE_APPLY_PATCH_ARG1} requires a UTF-8 PATCH argument.");1}};@@ -139,7 +140,7 @@ const ILLEGAL_ENV_VAR_PREFIX: &str = "CODEX_";/// Security: Do not allow `.env` files to create or modify any variables/// with names starting with `CODEX_`.fn load_dotenv() {- if let Ok(codex_home) = codex_core::config::find_codex_home()+ if let Ok(codex_home) = find_codex_home()&& let Ok(iter) = dotenvy::from_path_iter(codex_home.join(".env")){set_filtered(iter);@@ -175,7 +176,7 @@ where/// IMPORTANT: This function modifies the PATH environment variable, so it MUST/// be called before multiple threads are spawned.pub fn prepend_path_entry_for_codex_aliases() -> std::io::Result<Arg0PathEntryGuard> {- let codex_home = codex_core::config::find_codex_home()?;+ let codex_home = find_codex_home()?;#[cfg(not(debug_assertions))]{// Guard against placing helpers in system temp directories outside debug builds.@@ -242,7 +243,7 @@ pub fn prepend_path_entry_for_codex_aliases() -> std::io::Result<Arg0PathEntryGu&batch_script,format!(r#"@echo off-"{}" {CODEX_APPLY_PATCH_ARG1} %*+"{}" {CODEX_CORE_APPLY_PATCH_ARG1} %*"#,exe.display()),diff --git a/codex-rs/core/src/apply_patch.rs b/codex-rs/core/src/apply_patch.rsindex f87e07300d..714d9c40fe 100644--- a/codex-rs/core/src/apply_patch.rs+++ b/codex-rs/core/src/apply_patch.rs@@ -9,8 +9,6 @@ use codex_apply_patch::ApplyPatchFileChange;use std::collections::HashMap;use std::path::PathBuf;-pub const CODEX_APPLY_PATCH_ARG1: &str = "--codex-run-as-apply-patch";-pub(crate) enum InternalApplyPatchInvocation {/// The `apply_patch` call was handled programmatically, without any sort/// of sandbox, because the user explicitly approved it. This is the@@ -20,7 +18,8 @@ pub(crate) enum InternalApplyPatchInvocation {/// The `apply_patch` call was approved, either automatically because it/// appears that it should be allowed based on the user's sandbox policy/// *or* because the user explicitly approved it. In either case, we use- /// exec with [`CODEX_APPLY_PATCH_ARG1`] to realize the `apply_patch` call,+ /// exec with [`codex_apply_patch::CODEX_CORE_APPLY_PATCH_ARG1`] to realize+ /// the `apply_patch` call,/// but [`ApplyPatchExec::auto_approved`] is used to determine the sandbox/// used with the `exec()`.DelegateToExec(ApplyPatchExec),diff --git a/codex-rs/core/src/lib.rs b/codex-rs/core/src/lib.rsindex b54830a539..a0ad85a421 100644--- a/codex-rs/core/src/lib.rs+++ b/codex-rs/core/src/lib.rs@@ -144,7 +144,6 @@ pub(crate) use codex_shell_command::is_safe_command;pub(crate) use codex_shell_command::parse_command;pub(crate) use codex_shell_command::powershell;-pub use apply_patch::CODEX_APPLY_PATCH_ARG1;pub use client::X_CODEX_TURN_METADATA_HEADER;pub use exec_policy::ExecPolicyError;pub use exec_policy::check_execpolicy_for_warnings;diff --git a/codex-rs/core/src/tools/runtimes/apply_patch.rs b/codex-rs/core/src/tools/runtimes/apply_patch.rsindex 1cdb30b79a..d0ae2f61d7 100644--- a/codex-rs/core/src/tools/runtimes/apply_patch.rs+++ b/codex-rs/core/src/tools/runtimes/apply_patch.rs@@ -4,7 +4,6 @@//! decision to avoid re-prompting, builds the self-invocation command for//! `codex --codex-run-as-apply-patch`, and runs under the current//! `SandboxAttempt` with a minimal environment.-use crate::CODEX_APPLY_PATCH_ARG1;use crate::exec::ExecToolCallOutput;use crate::sandboxing::CommandSpec;use crate::sandboxing::SandboxPermissions;@@ -20,6 +19,7 @@ use crate::tools::sandboxing::ToolError;use crate::tools::sandboxing::ToolRuntime;use crate::tools::sandboxing::with_cached_approval;use codex_apply_patch::ApplyPatchAction;+use codex_apply_patch::CODEX_CORE_APPLY_PATCH_ARG1;use codex_protocol::protocol::AskForApproval;use codex_protocol::protocol::FileChange;use codex_protocol::protocol::ReviewDecision;@@ -57,7 +57,10 @@ impl ApplyPatchRuntime {let program = exe.to_string_lossy().to_string();Ok(CommandSpec {program,- args: vec![CODEX_APPLY_PATCH_ARG1.to_string(), req.action.patch.clone()],+ args: vec![+ CODEX_CORE_APPLY_PATCH_ARG1.to_string(),+ req.action.patch.clone(),+ ],cwd: req.action.cwd.clone(),expiration: req.timeout_ms.into(),// Run apply_patch with a minimal environment for determinism and to avoid leaks.diff --git a/codex-rs/exec/Cargo.toml b/codex-rs/exec/Cargo.tomlindex bb2f8498e3..f3fa573ab5 100644--- a/codex-rs/exec/Cargo.toml+++ b/codex-rs/exec/Cargo.toml@@ -51,6 +51,7 @@ uuid = { workspace = true }[dev-dependencies]assert_cmd = { workspace = true }+codex-apply-patch = { workspace = true }codex-utils-cargo-bin = { workspace = true }core_test_support = { workspace = true }libc = { workspace = true }diff --git a/codex-rs/exec/tests/suite/apply_patch.rs b/codex-rs/exec/tests/suite/apply_patch.rsindex fdc5415dc6..837c55c4c0 100644--- a/codex-rs/exec/tests/suite/apply_patch.rs+++ b/codex-rs/exec/tests/suite/apply_patch.rs@@ -2,7 +2,7 @@use anyhow::Context;use assert_cmd::prelude::*;-use codex_core::CODEX_APPLY_PATCH_ARG1;+use codex_apply_patch::CODEX_CORE_APPLY_PATCH_ARG1;use core_test_support::responses::ev_apply_patch_custom_tool_call;use core_test_support::responses::ev_apply_patch_function_call;use core_test_support::responses::ev_completed;@@ -24,7 +24,7 @@ fn test_standalone_exec_cli_can_use_apply_patch() -> anyhow::Result<()> {fs::write(&absolute_path, "original content\n")?;Command::new(codex_utils_cargo_bin::cargo_bin("codex-exec")?)- .arg(CODEX_APPLY_PATCH_ARG1)+ .arg(CODEX_CORE_APPLY_PATCH_ARG1).arg(r#"*** Begin Patch*** Update File: source.txt