Skip to content

armgit / codex

Public Imported from GitHub
0

Lightweight coding agent that runs in your terminal

Rust

feat: add custom env for unified exec process (#7286)

jif-oai37d83e075e3c
diff --git a/codex-rs/core/src/unified_exec/session_manager.rs b/codex-rs/core/src/unified_exec/session_manager.rs
index ed489e18cd..d4ba75849b 100644
--- a/codex-rs/core/src/unified_exec/session_manager.rs
+++ b/codex-rs/core/src/unified_exec/session_manager.rs
@@ -48,6 +48,24 @@ use super::session::OutputBuffer;
use super::session::OutputHandles;
use super::session::UnifiedExecSession;
+const UNIFIED_EXEC_ENV: [(&str, &str); 8] = [
+ ("NO_COLOR", "1"),
+ ("TERM", "dumb"),
+ ("LANG", "C.UTF-8"),
+ ("LC_CTYPE", "C.UTF-8"),
+ ("LC_ALL", "C.UTF-8"),
+ ("COLORTERM", ""),
+ ("PAGER", "cat"),
+ ("GIT_PAGER", "cat"),
+];
+
+fn apply_unified_exec_env(mut env: HashMap<String, String>) -> HashMap<String, String> {
+ for (key, value) in UNIFIED_EXEC_ENV {
+ env.insert(key.to_string(), value.to_string());
+ }
+ env
+}
+
struct PreparedSessionHandles {
writer_tx: mpsc::Sender<Vec<u8>>,
output_buffer: OutputBuffer,
@@ -460,12 +478,13 @@ impl UnifiedExecSessionManager {
justification: Option<String>,
context: &UnifiedExecContext,
) -> Result<UnifiedExecSession, UnifiedExecError> {
+ let env = apply_unified_exec_env(create_env(&context.turn.shell_environment_policy));
let mut orchestrator = ToolOrchestrator::new();
let mut runtime = UnifiedExecRuntime::new(self);
let req = UnifiedExecToolRequest::new(
command.to_vec(),
cwd,
- create_env(&context.turn.shell_environment_policy),
+ env,
with_escalated_permissions,
justification,
create_approval_requirement_for_command(
@@ -619,6 +638,35 @@ mod tests {
use tokio::time::Duration;
use tokio::time::Instant;
+ #[test]
+ fn unified_exec_env_injects_defaults() {
+ let env = apply_unified_exec_env(HashMap::new());
+ let expected = HashMap::from([
+ ("NO_COLOR".to_string(), "1".to_string()),
+ ("TERM".to_string(), "dumb".to_string()),
+ ("LANG".to_string(), "C.UTF-8".to_string()),
+ ("LC_CTYPE".to_string(), "C.UTF-8".to_string()),
+ ("LC_ALL".to_string(), "C.UTF-8".to_string()),
+ ("COLORTERM".to_string(), String::new()),
+ ("PAGER".to_string(), "cat".to_string()),
+ ("GIT_PAGER".to_string(), "cat".to_string()),
+ ]);
+
+ assert_eq!(env, expected);
+ }
+
+ #[test]
+ fn unified_exec_env_overrides_existing_values() {
+ let mut base = HashMap::new();
+ base.insert("NO_COLOR".to_string(), "0".to_string());
+ base.insert("PATH".to_string(), "/usr/bin".to_string());
+
+ let env = apply_unified_exec_env(base);
+
+ assert_eq!(env.get("NO_COLOR"), Some(&"1".to_string()));
+ assert_eq!(env.get("PATH"), Some(&"/usr/bin".to_string()));
+ }
+
#[test]
fn pruning_prefers_exited_sessions_outside_recently_used() {
let now = Instant::now();