@@ -48,6 +48,24 @@ use super::session::OutputBuffer;
4848use super :: session:: OutputHandles ;
4949use super :: session:: UnifiedExecSession ;
5050
51+ const UNIFIED_EXEC_ENV : [ ( & str , & str ) ; 8 ] = [
52+ ( "NO_COLOR" , "1" ) ,
53+ ( "TERM" , "dumb" ) ,
54+ ( "LANG" , "C.UTF-8" ) ,
55+ ( "LC_CTYPE" , "C.UTF-8" ) ,
56+ ( "LC_ALL" , "C.UTF-8" ) ,
57+ ( "COLORTERM" , "" ) ,
58+ ( "PAGER" , "cat" ) ,
59+ ( "GIT_PAGER" , "cat" ) ,
60+ ] ;
61+
62+ fn apply_unified_exec_env ( mut env : HashMap < String , String > ) -> HashMap < String , String > {
63+ for ( key, value) in UNIFIED_EXEC_ENV {
64+ env. insert ( key. to_string ( ) , value. to_string ( ) ) ;
65+ }
66+ env
67+ }
68+
5169struct PreparedSessionHandles {
5270 writer_tx : mpsc:: Sender < Vec < u8 > > ,
5371 output_buffer : OutputBuffer ,
@@ -460,12 +478,13 @@ impl UnifiedExecSessionManager {
460478 justification : Option < String > ,
461479 context : & UnifiedExecContext ,
462480 ) -> Result < UnifiedExecSession , UnifiedExecError > {
481+ let env = apply_unified_exec_env ( create_env ( & context. turn . shell_environment_policy ) ) ;
463482 let mut orchestrator = ToolOrchestrator :: new ( ) ;
464483 let mut runtime = UnifiedExecRuntime :: new ( self ) ;
465484 let req = UnifiedExecToolRequest :: new (
466485 command. to_vec ( ) ,
467486 cwd,
468- create_env ( & context . turn . shell_environment_policy ) ,
487+ env ,
469488 with_escalated_permissions,
470489 justification,
471490 create_approval_requirement_for_command (
@@ -619,6 +638,35 @@ mod tests {
619638 use tokio:: time:: Duration ;
620639 use tokio:: time:: Instant ;
621640
641+ #[ test]
642+ fn unified_exec_env_injects_defaults ( ) {
643+ let env = apply_unified_exec_env ( HashMap :: new ( ) ) ;
644+ let expected = HashMap :: from ( [
645+ ( "NO_COLOR" . to_string ( ) , "1" . to_string ( ) ) ,
646+ ( "TERM" . to_string ( ) , "dumb" . to_string ( ) ) ,
647+ ( "LANG" . to_string ( ) , "C.UTF-8" . to_string ( ) ) ,
648+ ( "LC_CTYPE" . to_string ( ) , "C.UTF-8" . to_string ( ) ) ,
649+ ( "LC_ALL" . to_string ( ) , "C.UTF-8" . to_string ( ) ) ,
650+ ( "COLORTERM" . to_string ( ) , String :: new ( ) ) ,
651+ ( "PAGER" . to_string ( ) , "cat" . to_string ( ) ) ,
652+ ( "GIT_PAGER" . to_string ( ) , "cat" . to_string ( ) ) ,
653+ ] ) ;
654+
655+ assert_eq ! ( env, expected) ;
656+ }
657+
658+ #[ test]
659+ fn unified_exec_env_overrides_existing_values ( ) {
660+ let mut base = HashMap :: new ( ) ;
661+ base. insert ( "NO_COLOR" . to_string ( ) , "0" . to_string ( ) ) ;
662+ base. insert ( "PATH" . to_string ( ) , "/usr/bin" . to_string ( ) ) ;
663+
664+ let env = apply_unified_exec_env ( base) ;
665+
666+ assert_eq ! ( env. get( "NO_COLOR" ) , Some ( & "1" . to_string( ) ) ) ;
667+ assert_eq ! ( env. get( "PATH" ) , Some ( & "/usr/bin" . to_string( ) ) ) ;
668+ }
669+
622670 #[ test]
623671 fn pruning_prefers_exited_sessions_outside_recently_used ( ) {
624672 let now = Instant :: now ( ) ;
0 commit comments