From d0b907d3992dd73d40a4ba1f6d78e9c51c0ec324 Mon Sep 17 00:00:00 2001 From: easong-openai Date: Thu, 14 Aug 2025 19:14:46 -0700 Subject: [PATCH] re-implement session id in status (#2332) Basically the same thing as https://github.com/openai/codex/pull/2297 --- codex-rs/tui/src/chatwidget.rs | 5 +++++ codex-rs/tui/src/chatwidget/tests.rs | 1 + codex-rs/tui/src/history_cell.rs | 14 +++++++++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/codex-rs/tui/src/chatwidget.rs b/codex-rs/tui/src/chatwidget.rs index 7cd7e6fa..c10b94b7 100644 --- a/codex-rs/tui/src/chatwidget.rs +++ b/codex-rs/tui/src/chatwidget.rs @@ -59,6 +59,7 @@ use crate::streaming::controller::AppEventHistorySink; use crate::streaming::controller::StreamController; use codex_core::ConversationManager; use codex_file_search::FileMatch; +use uuid::Uuid; // Track information about an in-flight exec command. struct RunningCommand { @@ -86,6 +87,7 @@ pub(crate) struct ChatWidget<'a> { interrupts: InterruptManager, // Whether a redraw is needed after handling the current event needs_redraw: bool, + session_id: Option, } struct UserMessage { @@ -125,6 +127,7 @@ impl ChatWidget<'_> { fn on_session_configured(&mut self, event: codex_core::protocol::SessionConfiguredEvent) { self.bottom_pane .set_history_metadata(event.history_log_id, event.history_entry_count); + self.session_id = Some(event.session_id); self.add_to_history(&history_cell::new_session_info(&self.config, event, true)); if let Some(user_message) = self.initial_user_message.take() { self.submit_user_message(user_message); @@ -528,6 +531,7 @@ impl ChatWidget<'_> { task_complete_pending: false, interrupts: InterruptManager::new(), needs_redraw: false, + session_id: None, } } @@ -675,6 +679,7 @@ impl ChatWidget<'_> { self.add_to_history(&history_cell::new_status_output( &self.config, &self.total_token_usage, + &self.session_id, )); } diff --git a/codex-rs/tui/src/chatwidget/tests.rs b/codex-rs/tui/src/chatwidget/tests.rs index 95542c06..bf03a8ed 100644 --- a/codex-rs/tui/src/chatwidget/tests.rs +++ b/codex-rs/tui/src/chatwidget/tests.rs @@ -141,6 +141,7 @@ fn make_chatwidget_manual() -> ( task_complete_pending: false, interrupts: InterruptManager::new(), needs_redraw: false, + session_id: None, }; (widget, rx, op_rx) } diff --git a/codex-rs/tui/src/history_cell.rs b/codex-rs/tui/src/history_cell.rs index ba645a7e..a4cebe98 100644 --- a/codex-rs/tui/src/history_cell.rs +++ b/codex-rs/tui/src/history_cell.rs @@ -37,6 +37,7 @@ use std::path::PathBuf; use std::time::Duration; use std::time::Instant; use tracing::error; +use uuid::Uuid; #[derive(Clone)] pub(crate) struct CommandOutput { @@ -483,7 +484,11 @@ pub(crate) fn new_diff_output(message: String) -> PlainHistoryCell { PlainHistoryCell { lines } } -pub(crate) fn new_status_output(config: &Config, usage: &TokenUsage) -> PlainHistoryCell { +pub(crate) fn new_status_output( + config: &Config, + usage: &TokenUsage, + session_id: &Option, +) -> PlainHistoryCell { let mut lines: Vec> = Vec::new(); lines.push(Line::from("/status".magenta())); @@ -521,6 +526,13 @@ pub(crate) fn new_status_output(config: &Config, usage: &TokenUsage) -> PlainHis sandbox_name.into(), ])); + if let Some(session_id) = session_id { + lines.push(Line::from(vec![ + " • Session ID: ".into(), + session_id.to_string().into(), + ])); + } + lines.push(Line::from("")); // 👤 Account (only if ChatGPT tokens exist), shown under the first block