@@ -4,6 +4,7 @@ use tokio::sync::OnceCell;
44
55use crate :: ExecServerClient ;
66use crate :: ExecServerError ;
7+ use crate :: ExecServerRuntimeConfig ;
78use crate :: RemoteExecServerConnectArgs ;
89use crate :: file_system:: ExecutorFileSystem ;
910use crate :: local_file_system:: LocalFileSystem ;
@@ -22,6 +23,7 @@ pub const CODEX_EXEC_SERVER_URL_ENV_VAR: &str = "CODEX_EXEC_SERVER_URL";
2223pub struct EnvironmentManager {
2324 exec_server_url : Option < String > ,
2425 disabled : bool ,
26+ runtime : ExecServerRuntimeConfig ,
2527 current_environment : OnceCell < Option < Arc < Environment > > > ,
2628}
2729
@@ -34,17 +36,33 @@ impl Default for EnvironmentManager {
3436impl EnvironmentManager {
3537 /// Builds a manager from the raw `CODEX_EXEC_SERVER_URL` value.
3638 pub fn new ( exec_server_url : Option < String > ) -> Self {
39+ Self :: new_with_runtime ( exec_server_url, ExecServerRuntimeConfig :: detect ( ) )
40+ }
41+
42+ /// Builds a manager from the raw `CODEX_EXEC_SERVER_URL` value and the
43+ /// runtime resources available in this client process.
44+ pub fn new_with_runtime (
45+ exec_server_url : Option < String > ,
46+ runtime : ExecServerRuntimeConfig ,
47+ ) -> Self {
3748 let ( exec_server_url, disabled) = normalize_exec_server_url ( exec_server_url) ;
3849 Self {
3950 exec_server_url,
4051 disabled,
52+ runtime,
4153 current_environment : OnceCell :: new ( ) ,
4254 }
4355 }
4456
4557 /// Builds a manager from process environment variables.
4658 pub fn from_env ( ) -> Self {
47- Self :: new ( std:: env:: var ( CODEX_EXEC_SERVER_URL_ENV_VAR ) . ok ( ) )
59+ Self :: from_env_with_runtime ( ExecServerRuntimeConfig :: detect ( ) )
60+ }
61+
62+ /// Builds a manager from process environment variables and explicit local
63+ /// runtime resources.
64+ pub fn from_env_with_runtime ( runtime : ExecServerRuntimeConfig ) -> Self {
65+ Self :: new_with_runtime ( std:: env:: var ( CODEX_EXEC_SERVER_URL_ENV_VAR ) . ok ( ) , runtime)
4866 }
4967
5068 /// Builds a manager from the currently selected environment, or from the
@@ -54,11 +72,13 @@ impl EnvironmentManager {
5472 Some ( environment) => Self {
5573 exec_server_url : environment. exec_server_url ( ) . map ( str:: to_owned) ,
5674 disabled : false ,
75+ runtime : ExecServerRuntimeConfig :: detect ( ) ,
5776 current_environment : OnceCell :: new ( ) ,
5877 } ,
5978 None => Self {
6079 exec_server_url : None ,
6180 disabled : true ,
81+ runtime : ExecServerRuntimeConfig :: detect ( ) ,
6282 current_environment : OnceCell :: new ( ) ,
6383 } ,
6484 }
@@ -82,7 +102,11 @@ impl EnvironmentManager {
82102 Ok ( None )
83103 } else {
84104 Ok ( Some ( Arc :: new (
85- Environment :: create ( self . exec_server_url . clone ( ) ) . await ?,
105+ Environment :: create_with_runtime (
106+ self . exec_server_url . clone ( ) ,
107+ self . runtime . clone ( ) ,
108+ )
109+ . await ?,
86110 ) ) )
87111 }
88112 } )
@@ -132,6 +156,15 @@ impl std::fmt::Debug for Environment {
132156impl Environment {
133157 /// Builds an environment from the raw `CODEX_EXEC_SERVER_URL` value.
134158 pub async fn create ( exec_server_url : Option < String > ) -> Result < Self , ExecServerError > {
159+ Self :: create_with_runtime ( exec_server_url, ExecServerRuntimeConfig :: detect ( ) ) . await
160+ }
161+
162+ /// Builds an environment from the raw `CODEX_EXEC_SERVER_URL` value and
163+ /// runtime resources available when spawning local processes.
164+ pub async fn create_with_runtime (
165+ exec_server_url : Option < String > ,
166+ runtime : ExecServerRuntimeConfig ,
167+ ) -> Result < Self , ExecServerError > {
135168 let ( exec_server_url, disabled) = normalize_exec_server_url ( exec_server_url) ;
136169 if disabled {
137170 return Err ( ExecServerError :: Protocol (
@@ -161,7 +194,7 @@ impl Environment {
161194 ) ) ;
162195 }
163196 None => {
164- let local_process = LocalProcess :: default ( ) ;
197+ let local_process = LocalProcess :: default_with_runtime ( runtime ) ;
165198 local_process
166199 . initialize ( )
167200 . map_err ( |err| ExecServerError :: Protocol ( err. message ) ) ?;
0 commit comments