@@ -29,6 +29,8 @@ use crate::turn_timing::now_unix_timestamp_ms;
2929use crate :: user_shell_command:: user_shell_command_record_item;
3030use codex_protocol:: exec_output:: ExecToolCallOutput ;
3131use codex_protocol:: exec_output:: StreamOutput ;
32+ use codex_protocol:: items:: CommandExecutionItem ;
33+ use codex_protocol:: items:: TurnItem ;
3234use codex_protocol:: protocol:: ErrorEvent ;
3335use codex_protocol:: protocol:: EventMsg ;
3436use codex_protocol:: protocol:: ExecCommandBeginEvent ;
@@ -181,19 +183,21 @@ pub(crate) async fn execute_user_shell_command(
181183
182184 let parsed_cmd = parse_command ( & display_command) ;
183185 session
184- . send_event (
186+ . emit_turn_item_started (
185187 turn_context. as_ref ( ) ,
186- EventMsg :: ExecCommandBegin ( ExecCommandBeginEvent {
187- call_id : call_id. clone ( ) ,
188- process_id : None ,
189- turn_id : turn_context. sub_id . clone ( ) ,
190- started_at_ms : now_unix_timestamp_ms ( ) ,
191- command : display_command. clone ( ) ,
192- cwd : cwd. clone ( ) . into ( ) ,
193- parsed_cmd : parsed_cmd. clone ( ) ,
194- source : ExecCommandSource :: UserShell ,
195- interaction_input : None ,
196- } ) ,
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+ ) ) ,
197201 )
198202 . await ;
199203
@@ -259,58 +263,62 @@ 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,
266- process_id : None ,
267- turn_id : turn_context. sub_id . clone ( ) ,
268- completed_at_ms : now_unix_timestamp_ms ( ) ,
269- command : display_command. clone ( ) ,
270- cwd : cwd. clone ( ) . into ( ) ,
271- parsed_cmd : parsed_cmd. clone ( ) ,
272- source : ExecCommandSource :: UserShell ,
273- 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 ,
281- } ) ,
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+ ) ) ,
282288 )
283289 . await ;
284290 }
285291 Ok ( Ok ( output) ) => {
286292 session
287- . send_event (
293+ . emit_turn_item_completed (
288294 turn_context. as_ref ( ) ,
289- EventMsg :: ExecCommandEnd ( ExecCommandEndEvent {
290- call_id : call_id. clone ( ) ,
291- process_id : None ,
292- turn_id : turn_context. sub_id . clone ( ) ,
293- completed_at_ms : now_unix_timestamp_ms ( ) ,
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- 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- ) ,
308- status : if output. exit_code == 0 {
309- ExecCommandStatus :: Completed
310- } else {
311- ExecCommandStatus :: Failed
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+ } ,
312320 } ,
313- } ) ,
321+ ) ) ,
314322 )
315323 . await ;
316324
@@ -329,29 +337,31 @@ pub(crate) async fn execute_user_shell_command(
329337 timed_out : false ,
330338 } ;
331339 session
332- . send_event (
340+ . emit_turn_item_completed (
333341 turn_context. as_ref ( ) ,
334- EventMsg :: ExecCommandEnd ( ExecCommandEndEvent {
335- call_id,
336- process_id : None ,
337- turn_id : turn_context. sub_id . clone ( ) ,
338- completed_at_ms : now_unix_timestamp_ms ( ) ,
339- command : display_command,
340- cwd : cwd. into ( ) ,
341- parsed_cmd,
342- source : ExecCommandSource :: UserShell ,
343- 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 (
350- & exec_output,
351- turn_context. model_info . truncation_policy . into ( ) ,
352- ) ,
353- status : ExecCommandStatus :: Failed ,
354- } ) ,
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+ ) ) ,
355365 )
356366 . await ;
357367 persist_user_shell_output (
0 commit comments