@@ -25,16 +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 ;
31+ use codex_protocol:: items:: CommandExecutionItem ;
32+ use codex_protocol:: items:: CommandExecutionStatus ;
33+ use codex_protocol:: items:: TurnItem ;
3234use codex_protocol:: protocol:: ErrorEvent ;
3335use codex_protocol:: protocol:: EventMsg ;
34- use codex_protocol:: protocol:: ExecCommandBeginEvent ;
35- use codex_protocol:: protocol:: ExecCommandEndEvent ;
3636use codex_protocol:: protocol:: ExecCommandSource ;
37- use codex_protocol:: protocol:: ExecCommandStatus ;
3837use codex_protocol:: protocol:: TurnStartedEvent ;
3938use codex_sandboxing:: SandboxType ;
4039use codex_shell_command:: parse_command:: parse_command;
@@ -181,18 +180,23 @@ pub(crate) async fn execute_user_shell_command(
181180
182181 let parsed_cmd = parse_command ( & display_command) ;
183182 session
184- . send_event (
183+ . emit_turn_item_started (
185184 turn_context. as_ref ( ) ,
186- EventMsg :: ExecCommandBegin ( ExecCommandBeginEvent {
187- call_id : call_id. clone ( ) ,
185+ & TurnItem :: CommandExecution ( CommandExecutionItem {
186+ id : call_id. clone ( ) ,
188187 process_id : None ,
189- turn_id : turn_context. sub_id . clone ( ) ,
190- started_at_ms : now_unix_timestamp_ms ( ) ,
191188 command : display_command. clone ( ) ,
192189 cwd : cwd. clone ( ) . into ( ) ,
193190 parsed_cmd : parsed_cmd. clone ( ) ,
194191 source : ExecCommandSource :: UserShell ,
195192 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 ,
196200 } ) ,
197201 )
198202 . await ;
@@ -259,57 +263,53 @@ pub(crate) async fn execute_user_shell_command(
259263 )
260264 . await ;
261265 session
262- . send_event (
266+ . emit_turn_item_completed (
263267 turn_context. as_ref ( ) ,
264- EventMsg :: ExecCommandEnd ( ExecCommandEndEvent {
265- call_id,
268+ TurnItem :: CommandExecution ( CommandExecutionItem {
269+ id : call_id,
266270 process_id : None ,
267- turn_id : turn_context. sub_id . clone ( ) ,
268- completed_at_ms : now_unix_timestamp_ms ( ) ,
269271 command : display_command. clone ( ) ,
270272 cwd : cwd. clone ( ) . into ( ) ,
271273 parsed_cmd : parsed_cmd. clone ( ) ,
272274 source : ExecCommandSource :: UserShell ,
273275 interaction_input : None ,
274- stdout : String :: new ( ) ,
275- stderr : aborted_message . clone ( ) ,
276- aggregated_output : aborted_message. clone ( ) ,
277- exit_code : - 1 ,
278- duration : Duration :: ZERO ,
279- formatted_output : aborted_message ,
280- status : ExecCommandStatus :: Failed ,
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 ) ,
281283 } ) ,
282284 )
283285 . await ;
284286 }
285287 Ok ( Ok ( output) ) => {
286288 session
287- . send_event (
289+ . emit_turn_item_completed (
288290 turn_context. as_ref ( ) ,
289- EventMsg :: ExecCommandEnd ( ExecCommandEndEvent {
290- call_id : call_id. clone ( ) ,
291+ TurnItem :: CommandExecution ( CommandExecutionItem {
292+ id : call_id. clone ( ) ,
291293 process_id : None ,
292- turn_id : turn_context. sub_id . clone ( ) ,
293- completed_at_ms : now_unix_timestamp_ms ( ) ,
294294 command : display_command. clone ( ) ,
295295 cwd : cwd. clone ( ) . into ( ) ,
296296 parsed_cmd : parsed_cmd. clone ( ) ,
297297 source : ExecCommandSource :: UserShell ,
298298 interaction_input : None ,
299- stdout : output. stdout . text . clone ( ) ,
300- stderr : output. stderr . text . clone ( ) ,
301- aggregated_output : output. aggregated_output . text . clone ( ) ,
302- exit_code : output. exit_code ,
303- duration : output. duration ,
304- formatted_output : format_exec_output_str (
305- & output,
306- turn_context. model_info . truncation_policy . into ( ) ,
307- ) ,
308299 status : if output. exit_code == 0 {
309- ExecCommandStatus :: Completed
300+ CommandExecutionStatus :: Completed
310301 } else {
311- ExecCommandStatus :: Failed
302+ CommandExecutionStatus :: Failed
312303 } ,
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+ ) ) ,
313313 } ) ,
314314 )
315315 . await ;
@@ -329,28 +329,26 @@ pub(crate) async fn execute_user_shell_command(
329329 timed_out : false ,
330330 } ;
331331 session
332- . send_event (
332+ . emit_turn_item_completed (
333333 turn_context. as_ref ( ) ,
334- EventMsg :: ExecCommandEnd ( ExecCommandEndEvent {
335- call_id,
334+ TurnItem :: CommandExecution ( CommandExecutionItem {
335+ id : call_id,
336336 process_id : None ,
337- turn_id : turn_context. sub_id . clone ( ) ,
338- completed_at_ms : now_unix_timestamp_ms ( ) ,
339337 command : display_command,
340338 cwd : cwd. into ( ) ,
341339 parsed_cmd,
342340 source : ExecCommandSource :: UserShell ,
343341 interaction_input : None ,
344- stdout : exec_output. stdout . text . clone ( ) ,
345- stderr : exec_output. stderr . text . clone ( ) ,
346- aggregated_output : exec_output. aggregated_output . text . clone ( ) ,
347- exit_code : exec_output. exit_code ,
348- duration : exec_output. duration ,
349- formatted_output : format_exec_output_str (
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 (
350349 & exec_output,
351350 turn_context. model_info . truncation_policy . into ( ) ,
352- ) ,
353- status : ExecCommandStatus :: Failed ,
351+ ) ) ,
354352 } ) ,
355353 )
356354 . await ;
0 commit comments