@@ -25,18 +25,15 @@ use crate::tools::runtimes::RuntimePathPrepends;
2525use crate :: tools:: runtimes:: apply_package_path_prepend;
2626use crate :: tools:: runtimes:: maybe_wrap_shell_lc_with_snapshot;
2727use crate :: tools:: runtimes:: strip_managed_proxy_env;
28- use crate :: turn_timing:: now_unix_timestamp_ms;
2928use crate :: user_shell_command:: user_shell_command_record_item;
3029use codex_protocol:: exec_output:: ExecToolCallOutput ;
3130use codex_protocol:: exec_output:: StreamOutput ;
3231use codex_protocol:: items:: CommandExecutionItem ;
32+ use codex_protocol:: items:: CommandExecutionStatus ;
3333use codex_protocol:: items:: TurnItem ;
3434use codex_protocol:: protocol:: ErrorEvent ;
3535use codex_protocol:: protocol:: EventMsg ;
36- use codex_protocol:: protocol:: ExecCommandBeginEvent ;
37- use codex_protocol:: protocol:: ExecCommandEndEvent ;
3836use codex_protocol:: protocol:: ExecCommandSource ;
39- use codex_protocol:: protocol:: ExecCommandStatus ;
4037use codex_protocol:: protocol:: TurnStartedEvent ;
4138use codex_sandboxing:: SandboxType ;
4239use codex_shell_command:: parse_command:: parse_command;
@@ -185,19 +182,22 @@ pub(crate) async fn execute_user_shell_command(
185182 session
186183 . emit_turn_item_started (
187184 turn_context. as_ref ( ) ,
188- & TurnItem :: CommandExecution ( CommandExecutionItem :: from_exec_command_begin_event (
189- ExecCommandBeginEvent {
190- call_id : call_id. clone ( ) ,
191- process_id : None ,
192- turn_id : turn_context. sub_id . clone ( ) ,
193- started_at_ms : now_unix_timestamp_ms ( ) ,
194- command : display_command. clone ( ) ,
195- cwd : cwd. clone ( ) . into ( ) ,
196- parsed_cmd : parsed_cmd. clone ( ) ,
197- source : ExecCommandSource :: UserShell ,
198- interaction_input : None ,
199- } ,
200- ) ) ,
185+ & TurnItem :: CommandExecution ( CommandExecutionItem {
186+ id : call_id. clone ( ) ,
187+ process_id : None ,
188+ command : display_command. clone ( ) ,
189+ cwd : cwd. clone ( ) . into ( ) ,
190+ parsed_cmd : parsed_cmd. clone ( ) ,
191+ source : ExecCommandSource :: UserShell ,
192+ interaction_input : None ,
193+ status : CommandExecutionStatus :: InProgress ,
194+ stdout : None ,
195+ stderr : None ,
196+ aggregated_output : None ,
197+ exit_code : None ,
198+ duration : None ,
199+ formatted_output : None ,
200+ } ) ,
201201 )
202202 . await ;
203203
@@ -265,60 +265,52 @@ pub(crate) async fn execute_user_shell_command(
265265 session
266266 . emit_turn_item_completed (
267267 turn_context. as_ref ( ) ,
268- TurnItem :: CommandExecution ( CommandExecutionItem :: from_exec_command_end_event (
269- ExecCommandEndEvent {
270- call_id,
271- process_id : None ,
272- turn_id : turn_context. sub_id . clone ( ) ,
273- completed_at_ms : now_unix_timestamp_ms ( ) ,
274- command : display_command. clone ( ) ,
275- cwd : cwd. clone ( ) . into ( ) ,
276- parsed_cmd : parsed_cmd. clone ( ) ,
277- source : ExecCommandSource :: UserShell ,
278- interaction_input : None ,
279- stdout : String :: new ( ) ,
280- stderr : aborted_message. clone ( ) ,
281- aggregated_output : aborted_message. clone ( ) ,
282- exit_code : -1 ,
283- duration : Duration :: ZERO ,
284- formatted_output : aborted_message,
285- status : ExecCommandStatus :: Failed ,
286- } ,
287- ) ) ,
268+ TurnItem :: CommandExecution ( CommandExecutionItem {
269+ id : call_id,
270+ process_id : None ,
271+ command : display_command. clone ( ) ,
272+ cwd : cwd. clone ( ) . into ( ) ,
273+ parsed_cmd : parsed_cmd. clone ( ) ,
274+ source : ExecCommandSource :: UserShell ,
275+ interaction_input : None ,
276+ status : CommandExecutionStatus :: Failed ,
277+ stdout : Some ( String :: new ( ) ) ,
278+ stderr : Some ( aborted_message. clone ( ) ) ,
279+ aggregated_output : Some ( aborted_message. clone ( ) ) ,
280+ exit_code : Some ( -1 ) ,
281+ duration : Some ( Duration :: ZERO ) ,
282+ formatted_output : Some ( aborted_message) ,
283+ } ) ,
288284 )
289285 . await ;
290286 }
291287 Ok ( Ok ( output) ) => {
292288 session
293289 . emit_turn_item_completed (
294290 turn_context. as_ref ( ) ,
295- TurnItem :: CommandExecution ( CommandExecutionItem :: from_exec_command_end_event (
296- ExecCommandEndEvent {
297- call_id : call_id. clone ( ) ,
298- process_id : None ,
299- turn_id : turn_context. sub_id . clone ( ) ,
300- completed_at_ms : now_unix_timestamp_ms ( ) ,
301- command : display_command. clone ( ) ,
302- cwd : cwd. clone ( ) . into ( ) ,
303- parsed_cmd : parsed_cmd. clone ( ) ,
304- source : ExecCommandSource :: UserShell ,
305- interaction_input : None ,
306- stdout : output. stdout . text . clone ( ) ,
307- stderr : output. stderr . text . clone ( ) ,
308- aggregated_output : output. aggregated_output . text . clone ( ) ,
309- exit_code : output. exit_code ,
310- duration : output. duration ,
311- formatted_output : format_exec_output_str (
312- & output,
313- turn_context. model_info . truncation_policy . into ( ) ,
314- ) ,
315- status : if output. exit_code == 0 {
316- ExecCommandStatus :: Completed
317- } else {
318- ExecCommandStatus :: Failed
319- } ,
291+ TurnItem :: CommandExecution ( CommandExecutionItem {
292+ id : call_id. clone ( ) ,
293+ process_id : None ,
294+ command : display_command. clone ( ) ,
295+ cwd : cwd. clone ( ) . into ( ) ,
296+ parsed_cmd : parsed_cmd. clone ( ) ,
297+ source : ExecCommandSource :: UserShell ,
298+ interaction_input : None ,
299+ status : if output. exit_code == 0 {
300+ CommandExecutionStatus :: Completed
301+ } else {
302+ CommandExecutionStatus :: Failed
320303 } ,
321- ) ) ,
304+ stdout : Some ( output. stdout . text . clone ( ) ) ,
305+ stderr : Some ( output. stderr . text . clone ( ) ) ,
306+ aggregated_output : Some ( output. aggregated_output . text . clone ( ) ) ,
307+ exit_code : Some ( output. exit_code ) ,
308+ duration : Some ( output. duration ) ,
309+ formatted_output : Some ( format_exec_output_str (
310+ & output,
311+ turn_context. model_info . truncation_policy . into ( ) ,
312+ ) ) ,
313+ } ) ,
322314 )
323315 . await ;
324316
@@ -339,29 +331,25 @@ pub(crate) async fn execute_user_shell_command(
339331 session
340332 . emit_turn_item_completed (
341333 turn_context. as_ref ( ) ,
342- TurnItem :: CommandExecution ( CommandExecutionItem :: from_exec_command_end_event (
343- ExecCommandEndEvent {
344- call_id,
345- process_id : None ,
346- turn_id : turn_context. sub_id . clone ( ) ,
347- completed_at_ms : now_unix_timestamp_ms ( ) ,
348- command : display_command,
349- cwd : cwd. into ( ) ,
350- parsed_cmd,
351- source : ExecCommandSource :: UserShell ,
352- interaction_input : None ,
353- stdout : exec_output. stdout . text . clone ( ) ,
354- stderr : exec_output. stderr . text . clone ( ) ,
355- aggregated_output : exec_output. aggregated_output . text . clone ( ) ,
356- exit_code : exec_output. exit_code ,
357- duration : exec_output. duration ,
358- formatted_output : format_exec_output_str (
359- & exec_output,
360- turn_context. model_info . truncation_policy . into ( ) ,
361- ) ,
362- status : ExecCommandStatus :: Failed ,
363- } ,
364- ) ) ,
334+ TurnItem :: CommandExecution ( CommandExecutionItem {
335+ id : call_id,
336+ process_id : None ,
337+ command : display_command,
338+ cwd : cwd. into ( ) ,
339+ parsed_cmd,
340+ source : ExecCommandSource :: UserShell ,
341+ interaction_input : None ,
342+ status : CommandExecutionStatus :: Failed ,
343+ stdout : Some ( exec_output. stdout . text . clone ( ) ) ,
344+ stderr : Some ( exec_output. stderr . text . clone ( ) ) ,
345+ aggregated_output : Some ( exec_output. aggregated_output . text . clone ( ) ) ,
346+ exit_code : Some ( exec_output. exit_code ) ,
347+ duration : Some ( exec_output. duration ) ,
348+ formatted_output : Some ( format_exec_output_str (
349+ & exec_output,
350+ turn_context. model_info . truncation_policy . into ( ) ,
351+ ) ) ,
352+ } ) ,
365353 )
366354 . await ;
367355 persist_user_shell_output (
0 commit comments