1+ use std:: path:: PathBuf ;
12use std:: sync:: Arc ;
23
34use tokio:: sync:: Notify ;
@@ -38,14 +39,20 @@ impl UnifiedExecSessionManager {
3839 request : ExecCommandRequest < ' _ > ,
3940 context : & UnifiedExecContext ,
4041 ) -> Result < UnifiedExecResponse , UnifiedExecError > {
42+ let cwd = request
43+ . workdir
44+ . clone ( )
45+ . unwrap_or_else ( || context. turn . cwd . clone ( ) ) ;
4146 let shell_flag = if request. login { "-lc" } else { "-c" } ;
4247 let command = vec ! [
4348 request. shell. to_string( ) ,
4449 shell_flag. to_string( ) ,
4550 request. command. to_string( ) ,
4651 ] ;
4752
48- let session = self . open_session_with_sandbox ( command, context) . await ?;
53+ let session = self
54+ . open_session_with_sandbox ( command, cwd. clone ( ) , context)
55+ . await ?;
4956
5057 let max_tokens = resolve_max_tokens ( request. max_output_tokens ) ;
5158 let yield_time_ms =
@@ -66,7 +73,7 @@ impl UnifiedExecSessionManager {
6673 None
6774 } else {
6875 Some (
69- self . store_session ( session, context, request. command , start)
76+ self . store_session ( session, context, request. command , cwd . clone ( ) , start)
7077 . await ,
7178 )
7279 } ;
@@ -87,6 +94,7 @@ impl UnifiedExecSessionManager {
8794 Self :: emit_exec_end_from_context (
8895 context,
8996 request. command . to_string ( ) ,
97+ cwd,
9098 response. output . clone ( ) ,
9199 exit,
92100 response. wall_time ,
@@ -211,6 +219,7 @@ impl UnifiedExecSessionManager {
211219 session : UnifiedExecSession ,
212220 context : & UnifiedExecContext ,
213221 command : & str ,
222+ cwd : PathBuf ,
214223 started_at : Instant ,
215224 ) -> i32 {
216225 let session_id = self
@@ -222,7 +231,7 @@ impl UnifiedExecSessionManager {
222231 turn_ref : Arc :: clone ( & context. turn ) ,
223232 call_id : context. call_id . clone ( ) ,
224233 command : command. to_string ( ) ,
225- cwd : context . turn . cwd . clone ( ) ,
234+ cwd,
226235 started_at,
227236 } ;
228237 self . sessions . lock ( ) . await . insert ( session_id, entry) ;
@@ -258,6 +267,7 @@ impl UnifiedExecSessionManager {
258267 async fn emit_exec_end_from_context (
259268 context : & UnifiedExecContext ,
260269 command : String ,
270+ cwd : PathBuf ,
261271 aggregated_output : String ,
262272 exit_code : i32 ,
263273 duration : Duration ,
@@ -276,7 +286,7 @@ impl UnifiedExecSessionManager {
276286 & context. call_id ,
277287 None ,
278288 ) ;
279- let emitter = ToolEmitter :: unified_exec ( command, context . turn . cwd . clone ( ) , true ) ;
289+ let emitter = ToolEmitter :: unified_exec ( command, cwd, true ) ;
280290 emitter
281291 . emit ( event_ctx, ToolEventStage :: Success ( output) )
282292 . await ;
@@ -300,13 +310,14 @@ impl UnifiedExecSessionManager {
300310 pub ( super ) async fn open_session_with_sandbox (
301311 & self ,
302312 command : Vec < String > ,
313+ cwd : PathBuf ,
303314 context : & UnifiedExecContext ,
304315 ) -> Result < UnifiedExecSession , UnifiedExecError > {
305316 let mut orchestrator = ToolOrchestrator :: new ( ) ;
306317 let mut runtime = UnifiedExecRuntime :: new ( self ) ;
307318 let req = UnifiedExecToolRequest :: new (
308319 command,
309- context . turn . cwd . clone ( ) ,
320+ cwd,
310321 create_env ( & context. turn . shell_environment_policy ) ,
311322 ) ;
312323 let tool_ctx = ToolCtx {
0 commit comments