From baa1cbedecd55d3740581516a51d5c8ea55ac676 Mon Sep 17 00:00:00 2001 From: Owen Lin Date: Thu, 13 Nov 2025 15:38:54 -0800 Subject: [PATCH] wip event updates --- codex-rs/app-server-protocol/src/protocol/v2.rs | 7 +++---- codex-rs/app-server/src/codex_message_processor.rs | 11 +++++++---- codex-rs/core/src/tasks/user_shell.rs | 1 + codex-rs/core/src/tools/events.rs | 1 + codex-rs/protocol/src/protocol.rs | 4 ++++ 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/codex-rs/app-server-protocol/src/protocol/v2.rs b/codex-rs/app-server-protocol/src/protocol/v2.rs index aef171d41a..7b2e241dd5 100644 --- a/codex-rs/app-server-protocol/src/protocol/v2.rs +++ b/codex-rs/app-server-protocol/src/protocol/v2.rs @@ -666,9 +666,10 @@ pub enum ThreadItem { CommandExecution { id: String, command: String, - aggregated_output: String, - exit_code: Option, status: CommandExecutionStatus, + is_user_shell_command: bool, + aggregated_output: Option, + exit_code: Option, duration_ms: Option, }, FileChange { @@ -916,7 +917,6 @@ pub struct FileChangeRequestApprovalResponse { #[serde(rename_all = "camelCase")] #[ts(export_to = "v2/")] pub struct CommandExecutionRequest { - pub call_id: String, pub command: Vec, pub cwd: PathBuf, /// Optional explanatory reason (e.g. request for network access). @@ -929,7 +929,6 @@ pub struct CommandExecutionRequest { #[serde(rename_all = "camelCase")] #[ts(export_to = "v2/")] pub struct FileChangeRequest { - pub call_id: String, pub file_changes: HashMap, /// Optional explanatory reason (e.g. request for extra write access). pub reason: Option, diff --git a/codex-rs/app-server/src/codex_message_processor.rs b/codex-rs/app-server/src/codex_message_processor.rs index bf2d0f1995..f67470dcb7 100644 --- a/codex-rs/app-server/src/codex_message_processor.rs +++ b/codex-rs/app-server/src/codex_message_processor.rs @@ -2696,8 +2696,10 @@ async fn apply_bespoke_event_handling( }); } ApiVersion::V2 => { + // TODO: Until we migrate the core to be aware of a first class FileChangeItem + // and emit the corresponding EventMsg, we repurpose the call_id as the item_id. + let item_id = call_id.clone(); let request = FileChangeRequest { - call_id, file_changes: changes .into_iter() .map(|(path, change)| (path, V2FileChange::from(change))) @@ -2709,7 +2711,7 @@ async fn apply_bespoke_event_handling( thread_id: conversation_id.to_string(), // TODO: use the actual IDs once we have them turn_id: "placeholder_turn_id".to_string(), - item_id: "placeholder_item_id".to_string(), + item_id, request, }; let rx = outgoing @@ -2747,7 +2749,6 @@ async fn apply_bespoke_event_handling( } ApiVersion::V2 => { let request = CommandExecutionRequest { - call_id, command, cwd, reason, @@ -2758,7 +2759,9 @@ async fn apply_bespoke_event_handling( thread_id: conversation_id.to_string(), // TODO: use the actual IDs once we have them turn_id: "placeholder_turn_id".to_string(), - item_id: "placeholder_item_id".to_string(), + // TODO: Until we migrate the core to be aware of a first class CommandExecutionItem + // and emit the corresponding EventMsg, we repurpose the call_id as the item_id. + item_id: call_id.clone(), request, }; let rx = outgoing diff --git a/codex-rs/core/src/tasks/user_shell.rs b/codex-rs/core/src/tasks/user_shell.rs index e894a08444..5c1231fbcf 100644 --- a/codex-rs/core/src/tasks/user_shell.rs +++ b/codex-rs/core/src/tasks/user_shell.rs @@ -77,6 +77,7 @@ impl SessionTask for UserShellCommandTask { turn_context.as_ref(), EventMsg::ExecCommandBegin(ExecCommandBeginEvent { call_id: call_id.clone(), + turn_id: turn_context.sub_id.clone(), command: shell_invocation.clone(), cwd: turn_context.cwd.clone(), parsed_cmd, diff --git a/codex-rs/core/src/tools/events.rs b/codex-rs/core/src/tools/events.rs index 9019dac5ed..06a3f3f115 100644 --- a/codex-rs/core/src/tools/events.rs +++ b/codex-rs/core/src/tools/events.rs @@ -67,6 +67,7 @@ pub(crate) async fn emit_exec_command_begin( ctx.turn, EventMsg::ExecCommandBegin(ExecCommandBeginEvent { call_id: ctx.call_id.to_string(), + turn_id: ctx.turn.sub_id.clone(), command: command.to_vec(), cwd: cwd.to_path_buf(), parsed_cmd: parse_command(command), diff --git a/codex-rs/protocol/src/protocol.rs b/codex-rs/protocol/src/protocol.rs index 2d0b0f013a..4705ce6fc0 100644 --- a/codex-rs/protocol/src/protocol.rs +++ b/codex-rs/protocol/src/protocol.rs @@ -1207,6 +1207,10 @@ pub struct ReviewLineRange { pub struct ExecCommandBeginEvent { /// Identifier so this can be paired with the ExecCommandEnd event. pub call_id: String, + /// Turn ID that this command belongs to. + /// Use `#[serde(default)]` for backwards compatibility. + #[serde(default)] + pub turn_id: String, /// The command to be executed. pub command: Vec, /// The command's working directory if not the default cwd for the agent.