From 9ee63716253f767f639e91548dfd46bd14e4458a Mon Sep 17 00:00:00 2001 From: Felipe Coury Date: Fri, 5 Jun 2026 14:08:41 -0300 Subject: [PATCH] refactor(tui): remove redundant workspace reads --- .../src/protocol/common.rs | 6 - .../src/protocol/v2/tests.rs | 15 -- .../src/protocol/v2/thread.rs | 15 -- codex-rs/app-server/README.md | 1 - codex-rs/app-server/src/message_processor.rs | 3 - codex-rs/app-server/src/request_processors.rs | 2 - .../src/request_processors/turn_processor.rs | 21 --- codex-rs/tui/src/app/event_dispatch.rs | 136 ------------------ codex-rs/tui/src/app/tests.rs | 40 ------ codex-rs/tui/src/app/thread_settings.rs | 30 ---- codex-rs/tui/src/app_event.rs | 9 -- codex-rs/tui/src/app_server_session.rs | 18 --- codex-rs/tui/src/chatwidget.rs | 1 - codex-rs/tui/src/chatwidget/settings.rs | 21 --- codex-rs/tui/src/chatwidget/slash_dispatch.rs | 42 +++++- .../tui/src/chatwidget/status_controls.rs | 29 +--- .../src/chatwidget/tests/slash_commands.rs | 16 ++- .../chatwidget/tests/status_command_tests.rs | 80 +++-------- codex-rs/tui/src/status/card.rs | 15 -- codex-rs/tui/src/status/tests.rs | 3 - 20 files changed, 74 insertions(+), 429 deletions(-) diff --git a/codex-rs/app-server-protocol/src/protocol/common.rs b/codex-rs/app-server-protocol/src/protocol/common.rs index b238995845..56ed666429 100644 --- a/codex-rs/app-server-protocol/src/protocol/common.rs +++ b/codex-rs/app-server-protocol/src/protocol/common.rs @@ -552,12 +552,6 @@ client_request_definitions! { serialization: thread_id(params.thread_id), response: v2::ThreadWorkspaceUpdateResponse, }, - #[experimental("thread/workspace/read")] - ThreadWorkspaceRead => "thread/workspace/read" { - params: v2::ThreadWorkspaceReadParams, - serialization: thread_id(params.thread_id), - response: v2::ThreadWorkspaceReadResponse, - }, #[experimental("thread/memoryMode/set")] ThreadMemoryModeSet => "thread/memoryMode/set" { params: v2::ThreadMemoryModeSetParams, diff --git a/codex-rs/app-server-protocol/src/protocol/v2/tests.rs b/codex-rs/app-server-protocol/src/protocol/v2/tests.rs index b442a8b6b1..58cc436427 100644 --- a/codex-rs/app-server-protocol/src/protocol/v2/tests.rs +++ b/codex-rs/app-server-protocol/src/protocol/v2/tests.rs @@ -3736,21 +3736,6 @@ fn thread_workspace_update_params_round_trip() { ); } -#[test] -fn thread_workspace_read_params_round_trip() { - let params = ThreadWorkspaceReadParams { - thread_id: "thread_123".to_string(), - }; - - let serialized = serde_json::to_value(¶ms).expect("params should serialize"); - assert_eq!(serialized, json!({ "threadId": "thread_123" })); - assert_eq!( - serde_json::from_value::(serialized) - .expect("params should deserialize"), - params - ); -} - #[test] fn thread_settings_update_params_preserve_field_level_experimental_gates() { let permissions = ThreadSettingsUpdateParams { diff --git a/codex-rs/app-server-protocol/src/protocol/v2/thread.rs b/codex-rs/app-server-protocol/src/protocol/v2/thread.rs index 1c6751696d..6ace2d514d 100644 --- a/codex-rs/app-server-protocol/src/protocol/v2/thread.rs +++ b/codex-rs/app-server-protocol/src/protocol/v2/thread.rs @@ -300,21 +300,6 @@ pub struct ThreadWorkspaceUpdateResponse { pub runtime_workspace_roots: Vec, } -#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export_to = "v2/")] -pub struct ThreadWorkspaceReadParams { - pub thread_id: String, -} - -#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS)] -#[serde(rename_all = "camelCase")] -#[ts(export_to = "v2/")] -pub struct ThreadWorkspaceReadResponse { - pub cwd: AbsolutePathBuf, - pub runtime_workspace_roots: Vec, -} - #[derive(Serialize, Deserialize, Debug, Clone, PartialEq, JsonSchema, TS, ExperimentalApi)] #[serde(rename_all = "camelCase")] #[ts(export_to = "v2/")] diff --git a/codex-rs/app-server/README.md b/codex-rs/app-server/README.md index 20568d9b39..90fe246d5a 100644 --- a/codex-rs/app-server/README.md +++ b/codex-rs/app-server/README.md @@ -150,7 +150,6 @@ Example with notification opt-out: - `thread/goal/cleared` — notification emitted whenever a thread goal is removed. - `thread/settings/updated` — experimental notification emitted to subscribed clients when a loaded thread’s effective next-turn settings change; includes `threadId` and the full `threadSettings`. Experimental clients also receive `threadSettings.runtimeWorkspaceRoots`, including roots added by model workspace mutations. - `thread/workspace/update` — experimental direct user workspace mutation; accepts `threadId`, `operation` (`setWorkingDirectory` or `addWorkspaceRoot`), and an absolute or cwd-relative `path`, then returns the authoritative runtime cwd and workspace roots. This method supports exactly one selected execution environment and does not request an additional approval because invoking it is an explicit user action. -- `thread/workspace/read` — experimental read-only lookup for the authoritative runtime cwd and workspace roots of a loaded thread. - `thread/status/changed` — notification emitted when a loaded thread’s status changes (`threadId` + new `status`). - `thread/archive` — move a thread’s rollout file into the archived directory and attempt to move any spawned descendant thread rollout files; returns `{}` on success and emits `thread/archived` for each archived thread. - `thread/delete` — hard-delete an active or archived thread and any spawned descendant threads; returns `{}` on success and emits `thread/deleted` for each deleted thread. diff --git a/codex-rs/app-server/src/message_processor.rs b/codex-rs/app-server/src/message_processor.rs index 6404584e55..bc8884635c 100644 --- a/codex-rs/app-server/src/message_processor.rs +++ b/codex-rs/app-server/src/message_processor.rs @@ -1134,9 +1134,6 @@ impl MessageProcessor { ClientRequest::ThreadWorkspaceUpdate { params, .. } => { self.turn_processor.thread_workspace_update(params).await } - ClientRequest::ThreadWorkspaceRead { params, .. } => { - self.turn_processor.thread_workspace_read(params).await - } ClientRequest::ThreadMemoryModeSet { params, .. } => { self.thread_processor.thread_memory_mode_set(params).await } diff --git a/codex-rs/app-server/src/request_processors.rs b/codex-rs/app-server/src/request_processors.rs index 6df46fbf09..349af75f5b 100644 --- a/codex-rs/app-server/src/request_processors.rs +++ b/codex-rs/app-server/src/request_processors.rs @@ -256,8 +256,6 @@ use codex_app_server_protocol::ThreadUnarchivedNotification; use codex_app_server_protocol::ThreadUnsubscribeParams; use codex_app_server_protocol::ThreadUnsubscribeResponse; use codex_app_server_protocol::ThreadUnsubscribeStatus; -use codex_app_server_protocol::ThreadWorkspaceReadParams; -use codex_app_server_protocol::ThreadWorkspaceReadResponse; use codex_app_server_protocol::ThreadWorkspaceUpdateParams; use codex_app_server_protocol::ThreadWorkspaceUpdateResponse; use codex_app_server_protocol::Turn; diff --git a/codex-rs/app-server/src/request_processors/turn_processor.rs b/codex-rs/app-server/src/request_processors/turn_processor.rs index 7106c335df..7c6f69ba2d 100644 --- a/codex-rs/app-server/src/request_processors/turn_processor.rs +++ b/codex-rs/app-server/src/request_processors/turn_processor.rs @@ -140,15 +140,6 @@ impl TurnRequestProcessor { .map(|response| Some(response.into())) } - pub(crate) async fn thread_workspace_read( - &self, - params: ThreadWorkspaceReadParams, - ) -> Result, JSONRPCErrorError> { - self.thread_workspace_read_inner(params) - .await - .map(|response| Some(response.into())) - } - pub(crate) async fn turn_steer( &self, request_id: &ConnectionRequestId, @@ -768,18 +759,6 @@ impl TurnRequestProcessor { }) } - async fn thread_workspace_read_inner( - &self, - params: ThreadWorkspaceReadParams, - ) -> Result { - let (_, thread) = self.load_thread(¶ms.thread_id).await?; - let snapshot = thread.config_snapshot().await; - Ok(ThreadWorkspaceReadResponse { - cwd: snapshot.cwd, - runtime_workspace_roots: snapshot.workspace_roots, - }) - } - async fn thread_inject_items_response_inner( &self, params: ThreadInjectItemsParams, diff --git a/codex-rs/tui/src/app/event_dispatch.rs b/codex-rs/tui/src/app/event_dispatch.rs index 2575c25e5c..e872e9e4c8 100644 --- a/codex-rs/tui/src/app/event_dispatch.rs +++ b/codex-rs/tui/src/app/event_dispatch.rs @@ -7,53 +7,12 @@ use super::resize_reflow::trailing_run_start; use super::*; use crate::config_update::format_config_error; use crate::external_agent_config_migration_flow::ExternalAgentConfigMigrationFlowOutcome; -use crate::render::highlight::foreground_style_for_scopes; -use crate::style::accent_style; -use crate::style::table_separator_style; -use codex_app_server_protocol::ThreadWorkspaceReadResponse; use codex_app_server_protocol::WorkspaceMutationOperation; #[cfg(target_os = "windows")] use codex_config::types::WindowsSandboxModeToml; -use ratatui::style::Styled; -use ratatui::text::Line; const SHUTDOWN_FIRST_EXIT_TIMEOUT: Duration = Duration::from_secs(/*secs*/ 2); -fn thread_workspace_lines(response: &ThreadWorkspaceReadResponse) -> Vec> { - let accent_style = accent_style(); - let label_style = - foreground_style_for_scopes(&["entity.name.type", "support.type", "variable"]) - .unwrap_or(accent_style); - let separator_style = table_separator_style(); - let mut lines = vec![ - vec![ - "• ".set_style(separator_style), - "Workspace".set_style(accent_style), - ] - .into(), - vec![ - " cwd ".set_style(label_style), - response.cwd.as_path().display().to_string().into(), - ] - .into(), - ]; - - let mut roots = response.runtime_workspace_roots.iter(); - let first_root = roots - .next() - .map(|root| root.as_path().display().to_string()) - .unwrap_or_else(|| "(none)".to_string()); - lines.push(vec![" roots ".set_style(label_style), first_root.into()].into()); - lines.extend(roots.map(|root| { - vec![ - " ".set_style(separator_style), - root.as_path().display().to_string().into(), - ] - .into() - })); - lines -} - impl App { pub(super) async fn handle_event( &mut self, @@ -414,21 +373,6 @@ impl App { .await { Ok(response) => { - self.config.cwd = response.cwd.clone(); - self.config.workspace_roots = response.runtime_workspace_roots.clone(); - self.config - .permissions - .set_workspace_roots(self.config.workspace_roots.clone()); - self.chat_widget.apply_runtime_workspace( - response.cwd.clone(), - response.runtime_workspace_roots.clone(), - ); - self.apply_workspace_to_cached_session( - thread_id, - &response.cwd, - &response.runtime_workspace_roots, - ) - .await; let message = match (operation, response.changed) { ( WorkspaceMutationOperation::SetWorkingDirectory, @@ -457,43 +401,6 @@ impl App { .add_error_message(format!("Failed to update workspace: {err}")), } } - AppEvent::ReadThreadWorkspace => { - let Some(thread_id) = self.active_thread_id else { - self.chat_widget.add_error_message( - "Workspace commands are unavailable before the session starts.".to_string(), - ); - return Ok(AppRunControl::Continue); - }; - match app_server.thread_workspace_read(thread_id).await { - Ok(response) => self - .chat_widget - .add_plain_history_lines(thread_workspace_lines(&response)), - Err(err) => self - .chat_widget - .add_error_message(format!("Failed to read workspace: {err}")), - } - } - AppEvent::ReadThreadWorkspaceForStatus { - refreshing_rate_limits, - request_id, - } => { - let workspace = match self.active_thread_id { - Some(thread_id) => match app_server.thread_workspace_read(thread_id).await { - Ok(response) => Some(response), - Err(err) => { - tracing::warn!("failed to read workspace for /status: {err}"); - None - } - }, - None => None, - }; - self.chat_widget.add_status_output_with_workspace( - refreshing_rate_limits, - request_id, - workspace.as_ref(), - /*workspace_state_stale*/ workspace.is_none(), - ); - } AppEvent::AppendMessageHistoryEntry { thread_id, text } => { self.append_message_history_entry(thread_id, text); } @@ -2434,46 +2341,3 @@ impl App { } } } - -#[cfg(test)] -mod tests { - use super::*; - use crate::test_support::test_path_display; - use codex_utils_absolute_path::test_support::PathBufExt; - use codex_utils_absolute_path::test_support::test_path_buf; - use pretty_assertions::assert_eq; - - #[test] - fn thread_workspace_lines_list_cwd_and_roots_snapshot() { - let response = ThreadWorkspaceReadResponse { - cwd: test_path_buf("/tmp/current").abs(), - runtime_workspace_roots: vec![ - test_path_buf("/tmp/current").abs(), - test_path_buf("/tmp/shared").abs(), - ], - }; - - let lines = thread_workspace_lines(&response); - assert_eq!(lines[0].spans[1].style, accent_style()); - assert_eq!( - lines[1].spans[0].style, - foreground_style_for_scopes(&["entity.name.type", "support.type", "variable"]) - .unwrap_or_else(accent_style) - ); - assert_eq!(lines[0].spans[0].style, table_separator_style()); - - let text = lines - .into_iter() - .map(|line| line.to_string()) - .collect::>() - .join("\n") - .replace(&test_path_display("/tmp/current"), "/tmp/current") - .replace(&test_path_display("/tmp/shared"), "/tmp/shared"); - insta::assert_snapshot!(text, @r" - • Workspace - cwd /tmp/current - roots /tmp/current - /tmp/shared - "); - } -} diff --git a/codex-rs/tui/src/app/tests.rs b/codex-rs/tui/src/app/tests.rs index b078694bd6..74e08bbe17 100644 --- a/codex-rs/tui/src/app/tests.rs +++ b/codex-rs/tui/src/app/tests.rs @@ -5937,46 +5937,6 @@ async fn inactive_thread_settings_notification_updates_cached_collaboration_mode ); } -#[tokio::test] -async fn workspace_update_updates_cached_session_roots() { - let mut app = make_test_app().await; - let thread_id = ThreadId::new(); - let session = test_thread_session(thread_id, test_path_buf("/tmp/main")); - let cwd = test_absolute_path("/tmp/stack-layer"); - let roots = vec![cwd.clone(), test_absolute_path("/tmp/shared")]; - - app.primary_thread_id = Some(thread_id); - app.primary_session_configured = Some(session.clone()); - app.thread_event_channels.insert( - thread_id, - ThreadEventChannel::new_with_session(THREAD_EVENT_CHANNEL_CAPACITY, session, Vec::new()), - ); - - app.apply_workspace_to_cached_session(thread_id, &cwd, &roots) - .await; - - let cached_session = app - .thread_event_channels - .get(&thread_id) - .expect("thread channel") - .store - .lock() - .await - .session - .clone() - .expect("cached session"); - assert_eq!(cached_session.cwd, cwd); - assert_eq!(cached_session.runtime_workspace_roots, roots); - assert_eq!( - app.primary_session_configured - .as_ref() - .expect("primary session") - .runtime_workspace_roots - .as_slice(), - cached_session.runtime_workspace_roots.as_slice() - ); -} - #[tokio::test] async fn clear_only_ui_reset_preserves_chat_session_state() { let mut app = make_test_app().await; diff --git a/codex-rs/tui/src/app/thread_settings.rs b/codex-rs/tui/src/app/thread_settings.rs index 089752828f..4e0f31d5bb 100644 --- a/codex-rs/tui/src/app/thread_settings.rs +++ b/codex-rs/tui/src/app/thread_settings.rs @@ -10,7 +10,6 @@ use codex_app_server_protocol::ThreadSettingsUpdateParams; use codex_protocol::ThreadId; use codex_protocol::config_types::ModeKind; use codex_protocol::models::PermissionProfile; -use codex_utils_absolute_path::AbsolutePathBuf; impl App { pub(super) async fn sync_active_thread_model_setting( @@ -154,26 +153,6 @@ impl App { } } - pub(super) async fn apply_workspace_to_cached_session( - &mut self, - thread_id: ThreadId, - cwd: &AbsolutePathBuf, - runtime_workspace_roots: &[AbsolutePathBuf], - ) { - if self.primary_thread_id == Some(thread_id) - && let Some(session) = self.primary_session_configured.as_mut() - { - apply_workspace_to_session(session, cwd, runtime_workspace_roots); - } - - if let Some(channel) = self.thread_event_channels.get(&thread_id) { - let mut store = channel.store.lock().await; - if let Some(session) = store.session.as_mut() { - apply_workspace_to_session(session, cwd, runtime_workspace_roots); - } - } - } - async fn send_thread_settings_update( &mut self, app_server: &mut AppServerSession, @@ -218,15 +197,6 @@ fn apply_thread_settings_to_session(session: &mut ThreadSessionState, settings: session.collaboration_mode = Some(Box::new(collaboration_mode)); } -fn apply_workspace_to_session( - session: &mut ThreadSessionState, - cwd: &AbsolutePathBuf, - runtime_workspace_roots: &[AbsolutePathBuf], -) { - session.cwd.clone_from(cwd); - session.runtime_workspace_roots = runtime_workspace_roots.to_vec(); -} - fn thread_settings_update_has_changes(params: &ThreadSettingsUpdateParams) -> bool { params.cwd.is_some() || params.approval_policy.is_some() diff --git a/codex-rs/tui/src/app_event.rs b/codex-rs/tui/src/app_event.rs index aa333f7288..af4dc99f50 100644 --- a/codex-rs/tui/src/app_event.rs +++ b/codex-rs/tui/src/app_event.rs @@ -265,15 +265,6 @@ pub(crate) enum AppEvent { path: String, }, - /// Show the authoritative runtime cwd and workspace roots. - ReadThreadWorkspace, - - /// Read the authoritative runtime workspace before rendering `/status`. - ReadThreadWorkspaceForStatus { - refreshing_rate_limits: bool, - request_id: Option, - }, - /// Approve one retry of a recent auto-review denial selected in the TUI. ApproveRecentAutoReviewDenial { thread_id: ThreadId, diff --git a/codex-rs/tui/src/app_server_session.rs b/codex-rs/tui/src/app_server_session.rs index cde42e7545..e93b2a02e6 100644 --- a/codex-rs/tui/src/app_server_session.rs +++ b/codex-rs/tui/src/app_server_session.rs @@ -107,8 +107,6 @@ use codex_app_server_protocol::ThreadUnarchiveParams; use codex_app_server_protocol::ThreadUnarchiveResponse; use codex_app_server_protocol::ThreadUnsubscribeParams; use codex_app_server_protocol::ThreadUnsubscribeResponse; -use codex_app_server_protocol::ThreadWorkspaceReadParams; -use codex_app_server_protocol::ThreadWorkspaceReadResponse; use codex_app_server_protocol::ThreadWorkspaceUpdateParams; use codex_app_server_protocol::ThreadWorkspaceUpdateResponse; use codex_app_server_protocol::Turn; @@ -748,22 +746,6 @@ impl AppServerSession { .wrap_err("thread/workspace/update failed in TUI") } - pub(crate) async fn thread_workspace_read( - &mut self, - thread_id: ThreadId, - ) -> Result { - let request_id = self.next_request_id(); - self.client - .request_typed(ClientRequest::ThreadWorkspaceRead { - request_id, - params: ThreadWorkspaceReadParams { - thread_id: thread_id.to_string(), - }, - }) - .await - .wrap_err("thread/workspace/read failed in TUI") - } - pub(crate) async fn thread_inject_items( &mut self, thread_id: ThreadId, diff --git a/codex-rs/tui/src/chatwidget.rs b/codex-rs/tui/src/chatwidget.rs index cc4e0804e8..32c9b0e986 100644 --- a/codex-rs/tui/src/chatwidget.rs +++ b/codex-rs/tui/src/chatwidget.rs @@ -115,7 +115,6 @@ use codex_app_server_protocol::ThreadItem; use codex_app_server_protocol::ThreadSettings; use codex_app_server_protocol::ThreadSettingsUpdatedNotification; use codex_app_server_protocol::ThreadTokenUsage; -use codex_app_server_protocol::ThreadWorkspaceReadResponse; use codex_app_server_protocol::ToolRequestUserInputParams; use codex_app_server_protocol::Turn; use codex_app_server_protocol::TurnCompletedNotification; diff --git a/codex-rs/tui/src/chatwidget/settings.rs b/codex-rs/tui/src/chatwidget/settings.rs index 66d6ce3c6e..bed42e2bb4 100644 --- a/codex-rs/tui/src/chatwidget/settings.rs +++ b/codex-rs/tui/src/chatwidget/settings.rs @@ -573,27 +573,6 @@ impl ChatWidget { .set_workspace_roots(self.config.workspace_roots.clone()); } - pub(crate) fn apply_runtime_workspace( - &mut self, - cwd: AbsolutePathBuf, - workspace_roots: Vec, - ) { - let cwd_changed = self.config.cwd != cwd; - self.config.cwd = cwd.clone(); - self.current_cwd = Some(cwd.to_path_buf()); - self.config.workspace_roots = workspace_roots; - self.config - .permissions - .set_workspace_roots(self.config.workspace_roots.clone()); - self.status_line_project_root_name_cache = None; - self.refresh_status_surfaces(); - if cwd_changed { - self.refresh_skills_for_current_cwd(/*force_reload*/ true); - } - self.refresh_plugin_mentions(); - self.request_redraw(); - } - pub(super) fn set_effective_collaboration_mode(&mut self, mode: CollaborationMode) { let mode_kind = mode.mode; let settings = mode.settings; diff --git a/codex-rs/tui/src/chatwidget/slash_dispatch.rs b/codex-rs/tui/src/chatwidget/slash_dispatch.rs index 990ff689b8..56ad59fba8 100644 --- a/codex-rs/tui/src/chatwidget/slash_dispatch.rs +++ b/codex-rs/tui/src/chatwidget/slash_dispatch.rs @@ -13,6 +13,10 @@ use crate::bottom_pane::slash_commands::ServiceTierCommand; use crate::bottom_pane::slash_commands::SlashCommandItem; use crate::bottom_pane::slash_commands::find_slash_command; use crate::goal_display::GOAL_USAGE; +use crate::render::highlight::foreground_style_for_scopes; +use crate::style::accent_style; +use crate::style::table_separator_style; +use ratatui::style::Styled; #[derive(Clone, Copy, Debug, PartialEq, Eq)] enum SlashCommandDispatchSource { @@ -300,7 +304,37 @@ impl ChatWidget { } } SlashCommand::Cwd => { - self.app_event_tx.send(AppEvent::ReadThreadWorkspace); + let accent_style = accent_style(); + let label_style = + foreground_style_for_scopes(&["entity.name.type", "support.type", "variable"]) + .unwrap_or(accent_style); + let separator_style = table_separator_style(); + let mut lines: Vec> = vec![ + vec![ + "• ".set_style(separator_style), + "Workspace".set_style(accent_style), + ] + .into(), + vec![ + " cwd ".set_style(label_style), + self.config.cwd.as_path().display().to_string().into(), + ] + .into(), + ]; + let mut roots = self.config.workspace_roots.iter(); + let first_root = roots + .next() + .map(|root| root.as_path().display().to_string()) + .unwrap_or_else(|| "(none)".to_string()); + lines.push(vec![" roots ".set_style(label_style), first_root.into()].into()); + lines.extend(roots.map(|root| { + vec![ + " ".set_style(separator_style), + root.as_path().display().to_string().into(), + ] + .into() + })); + self.add_plain_history_lines(lines); } SlashCommand::AddDir => { self.add_error_message(ADD_DIR_USAGE.to_string()); @@ -447,11 +481,7 @@ impl ChatWidget { } else { (false, None) }; - self.app_event_tx - .send(AppEvent::ReadThreadWorkspaceForStatus { - refreshing_rate_limits, - request_id, - }); + self.add_status_output(refreshing_rate_limits, request_id); if let Some(request_id) = request_id { self.app_event_tx.send(AppEvent::RefreshRateLimits { origin: RateLimitRefreshOrigin::StatusCommand { request_id }, diff --git a/codex-rs/tui/src/chatwidget/status_controls.rs b/codex-rs/tui/src/chatwidget/status_controls.rs index 8a3fd2a879..d4de738314 100644 --- a/codex-rs/tui/src/chatwidget/status_controls.rs +++ b/codex-rs/tui/src/chatwidget/status_controls.rs @@ -188,35 +188,11 @@ impl ChatWidget { self.refresh_status_surfaces(); } - #[cfg(test)] pub(crate) fn add_status_output( &mut self, refreshing_rate_limits: bool, request_id: Option, ) { - self.add_status_output_with_workspace( - refreshing_rate_limits, - request_id, - /*workspace*/ None, - /*workspace_state_stale*/ false, - ); - } - - pub(crate) fn add_status_output_with_workspace( - &mut self, - refreshing_rate_limits: bool, - request_id: Option, - workspace: Option<&ThreadWorkspaceReadResponse>, - workspace_state_stale: bool, - ) { - let mut config = self.config.clone(); - if let Some(workspace) = workspace { - config.cwd = workspace.cwd.clone(); - config.workspace_roots = workspace.runtime_workspace_roots.clone(); - config - .permissions - .set_workspace_roots(config.workspace_roots.clone()); - } let default_usage = TokenUsage::default(); let token_info = self.token_info.as_ref(); let total_usage = token_info @@ -245,9 +221,9 @@ impl ChatWidget { .cloned() .collect(); let agents_summary = - crate::status::compose_agents_summary(&config, &self.instruction_source_paths); + crate::status::compose_agents_summary(&self.config, &self.instruction_source_paths); let (cell, handle) = crate::status::new_status_output_with_rate_limits_handle( - &config, + &self.config, self.runtime_model_provider_base_url.as_deref(), self.remote_connection.as_ref(), self.status_account_display.as_ref(), @@ -263,7 +239,6 @@ impl ChatWidget { collaboration_mode, reasoning_effort_override, agents_summary, - workspace_state_stale, refreshing_rate_limits, ); if let Some(request_id) = request_id { diff --git a/codex-rs/tui/src/chatwidget/tests/slash_commands.rs b/codex-rs/tui/src/chatwidget/tests/slash_commands.rs index 0d66413835..adeb929e5e 100644 --- a/codex-rs/tui/src/chatwidget/tests/slash_commands.rs +++ b/codex-rs/tui/src/chatwidget/tests/slash_commands.rs @@ -88,12 +88,24 @@ fn next_add_to_history_event(rx: &mut tokio::sync::mpsc::UnboundedReceiver { + lines_to_single_string(&cell.display_lines(/*width*/ 120)) + } + other => panic!("expected workspace output, got {other:?}"), + }; + assert!(rendered.contains("Workspace")); + assert!(rendered.contains(&chat.config.cwd.display().to_string())); + assert!(rendered.contains("/workspace/shared")); } #[tokio::test] diff --git a/codex-rs/tui/src/chatwidget/tests/status_command_tests.rs b/codex-rs/tui/src/chatwidget/tests/status_command_tests.rs index d41e8a7ee9..be356bd683 100644 --- a/codex-rs/tui/src/chatwidget/tests/status_command_tests.rs +++ b/codex-rs/tui/src/chatwidget/tests/status_command_tests.rs @@ -1,45 +1,32 @@ use super::*; -use assert_matches::assert_matches; fn render_requested_status( - chat: &mut ChatWidget, rx: &mut tokio::sync::mpsc::UnboundedReceiver, ) -> (String, Option) { - let (refreshing_rate_limits, request_id) = match rx.try_recv() { - Ok(AppEvent::ReadThreadWorkspaceForStatus { - refreshing_rate_limits, - request_id, - }) => (refreshing_rate_limits, request_id), - other => panic!("expected workspace read request for /status, got {other:?}"), - }; - if let Some(request_id) = request_id { - assert_matches!( - rx.try_recv(), - Ok(AppEvent::RefreshRateLimits { - origin: RateLimitRefreshOrigin::StatusCommand { - request_id: event_request_id, - }, - }) if event_request_id == request_id - ); - } - chat.add_status_output(refreshing_rate_limits, request_id); let rendered = match rx.try_recv() { Ok(AppEvent::InsertHistoryCell(cell)) => { lines_to_single_string(&cell.display_lines(/*width*/ 80)) } - other => panic!("expected status output after workspace read, got {other:?}"), + other => panic!("expected status output, got {other:?}"), + }; + let request_id = match rx.try_recv() { + Ok(AppEvent::RefreshRateLimits { + origin: RateLimitRefreshOrigin::StatusCommand { request_id }, + }) => Some(request_id), + Err(tokio::sync::mpsc::error::TryRecvError::Empty) => None, + other => panic!("expected rate-limit refresh or empty queue, got {other:?}"), }; (rendered, request_id) } #[tokio::test] -async fn status_command_reads_workspace_and_refreshes_rate_limits_for_chatgpt_auth() { +async fn status_command_refreshes_rate_limits_for_chatgpt_auth() { let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await; set_chatgpt_auth(&mut chat); chat.dispatch_command(SlashCommand::Status); - let (rendered, request_id) = render_requested_status(&mut chat, &mut rx); + let (rendered, request_id) = render_requested_status(&mut rx); assert!( !rendered.contains("refreshing limits"), "expected /status to avoid transient refresh text in terminal history, got: {rendered}" @@ -54,7 +41,7 @@ async fn status_command_refresh_updates_cached_limits_for_future_status_outputs( chat.dispatch_command(SlashCommand::Status); - let (_, first_request_id) = render_requested_status(&mut chat, &mut rx); + let (_, first_request_id) = render_requested_status(&mut rx); let first_request_id = first_request_id.expect("ChatGPT status should refresh limits"); chat.on_rate_limit_snapshot(Some(snapshot(/*percent*/ 92.0))); @@ -62,7 +49,7 @@ async fn status_command_refresh_updates_cached_limits_for_future_status_outputs( drain_insert_history(&mut rx); chat.dispatch_command(SlashCommand::Status); - let (refreshed, _) = render_requested_status(&mut chat, &mut rx); + let (refreshed, _) = render_requested_status(&mut rx); assert!( refreshed.contains("8% left"), "expected a future /status output to use refreshed cached limits, got: {refreshed}" @@ -70,12 +57,12 @@ async fn status_command_refresh_updates_cached_limits_for_future_status_outputs( } #[tokio::test] -async fn status_command_reads_workspace_without_rate_limit_refresh() { +async fn status_command_skips_rate_limit_refresh_without_chatgpt_auth() { let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await; chat.dispatch_command(SlashCommand::Status); - let (_, request_id) = render_requested_status(&mut chat, &mut rx); + let (_, request_id) = render_requested_status(&mut rx); pretty_assertions::assert_eq!(request_id, None); assert!( !std::iter::from_fn(|| rx.try_recv().ok()) @@ -91,7 +78,7 @@ async fn status_command_uses_catalog_default_reasoning_when_config_empty() { chat.dispatch_command(SlashCommand::Status); - let (rendered, _) = render_requested_status(&mut chat, &mut rx); + let (rendered, _) = render_requested_status(&mut rx); assert!( rendered.contains("gpt-5.4 (reasoning medium, summaries auto)"), "expected /status to render the catalog default reasoning effort, got: {rendered}" @@ -105,7 +92,7 @@ async fn status_command_renders_instruction_sources_from_thread_session() { chat.dispatch_command(SlashCommand::Status); - let (rendered, _) = render_requested_status(&mut chat, &mut rx); + let (rendered, _) = render_requested_status(&mut rx); assert!( rendered.contains("Agents.md"), "expected /status to render app-server instruction sources, got: {rendered}" @@ -122,11 +109,11 @@ async fn status_command_overlapping_refreshes_update_matching_cells_only() { set_chatgpt_auth(&mut chat); chat.dispatch_command(SlashCommand::Status); - let (_, first_request_id) = render_requested_status(&mut chat, &mut rx); + let (_, first_request_id) = render_requested_status(&mut rx); let first_request_id = first_request_id.expect("ChatGPT status should refresh limits"); chat.dispatch_command(SlashCommand::Status); - let (second_rendered, second_request_id) = render_requested_status(&mut chat, &mut rx); + let (second_rendered, second_request_id) = render_requested_status(&mut rx); let second_request_id = second_request_id.expect("ChatGPT status should refresh limits"); assert_ne!(first_request_id, second_request_id); @@ -150,16 +137,12 @@ async fn status_output_uses_authoritative_runtime_workspace() { let extra_root = test_path_buf("/workspace/shared").abs(); let cwd_display = cwd.display().to_string(); let extra_root_display = extra_root.display().to_string(); + chat.config.cwd = cwd.clone(); + chat.config.workspace_roots = vec![cwd.clone(), extra_root]; chat.instruction_source_paths = vec![cwd.join("AGENTS.md")]; - chat.add_status_output_with_workspace( - /*refreshing_rate_limits*/ false, - /*request_id*/ None, - Some(&codex_app_server_protocol::ThreadWorkspaceReadResponse { - cwd: cwd.clone(), - runtime_workspace_roots: vec![cwd, extra_root], - }), - /*workspace_state_stale*/ false, + chat.add_status_output( + /*refreshing_rate_limits*/ false, /*request_id*/ None, ); let rendered = match rx.try_recv() { @@ -175,22 +158,3 @@ async fn status_output_uses_authoritative_runtime_workspace() { assert!(rendered.contains("Agents.md:")); assert!(rendered.contains("AGENTS.md")); } - -#[tokio::test] -async fn status_output_warns_when_workspace_state_may_be_stale() { - let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await; - - chat.add_status_output_with_workspace( - /*refreshing_rate_limits*/ false, /*request_id*/ None, /*workspace*/ None, - /*workspace_state_stale*/ true, - ); - - let rendered = match rx.try_recv() { - Ok(AppEvent::InsertHistoryCell(cell)) => { - lines_to_single_string(&cell.display_lines(/*width*/ 120)) - } - other => panic!("expected status output, got {other:?}"), - }; - assert!(rendered.contains("Warning:")); - assert!(rendered.contains("workspace state may be stale")); -} diff --git a/codex-rs/tui/src/status/card.rs b/codex-rs/tui/src/status/card.rs index f8be72aa58..9fdb0c4708 100644 --- a/codex-rs/tui/src/status/card.rs +++ b/codex-rs/tui/src/status/card.rs @@ -108,7 +108,6 @@ struct StatusHistoryCell { model_details: Vec, directory: PathBuf, workspace_roots: Vec, - workspace_state_stale: bool, permissions: String, agents_summary: Arc>, collaboration_mode: Option, @@ -194,7 +193,6 @@ pub(crate) fn new_status_output_with_rate_limits( collaboration_mode, reasoning_effort_override, "".to_string(), - /*workspace_state_stale*/ false, refreshing_rate_limits, ) .0 @@ -218,7 +216,6 @@ pub(crate) fn new_status_output_with_rate_limits_handle( collaboration_mode: Option<&str>, reasoning_effort_override: Option>, agents_summary: String, - workspace_state_stale: bool, refreshing_rate_limits: bool, ) -> (CompositeHistoryCell, StatusHistoryHandle) { let command = PlainHistoryCell::new(vec!["/status".magenta().into()]); @@ -239,7 +236,6 @@ pub(crate) fn new_status_output_with_rate_limits_handle( collaboration_mode, reasoning_effort_override, agents_summary, - workspace_state_stale, refreshing_rate_limits, ); @@ -268,7 +264,6 @@ impl StatusHistoryCell { collaboration_mode: Option<&str>, reasoning_effort_override: Option>, agents_summary: String, - workspace_state_stale: bool, refreshing_rate_limits: bool, ) -> (Self, StatusHistoryHandle) { let approval_policy = AskForApproval::from(config.permissions.approval_policy.value()); @@ -361,7 +356,6 @@ impl StatusHistoryCell { model_details, directory: config.cwd.to_path_buf(), workspace_roots: config.workspace_roots.clone(), - workspace_state_stale, permissions, collaboration_mode: collaboration_mode.map(ToString::to_string), model_provider, @@ -745,9 +739,6 @@ impl HistoryCell for StatusHistoryCell { if !additional_workspace_roots.is_empty() { push_label(&mut labels, &mut seen, "Workspace roots"); } - if self.workspace_state_stale { - push_label(&mut labels, &mut seen, "Warning"); - } push_label(&mut labels, &mut seen, "Token usage"); if self.token_usage.context_window.is_some() { push_label(&mut labels, &mut seen, "Context window"); @@ -827,12 +818,6 @@ impl HistoryCell for StatusHistoryCell { } lines.push(formatter.line("Permissions", vec![Span::from(self.permissions.clone())])); lines.push(formatter.line("Agents.md", vec![Span::from(agents_summary)])); - if self.workspace_state_stale { - lines.push(formatter.line( - "Warning", - vec![Span::from("workspace state may be stale").dim()], - )); - } if let Some(account_value) = account_value { lines.push(formatter.line("Account", vec![Span::from(account_value)])); diff --git a/codex-rs/tui/src/status/tests.rs b/codex-rs/tui/src/status/tests.rs index e41ddc5ac6..225e75ea67 100644 --- a/codex-rs/tui/src/status/tests.rs +++ b/codex-rs/tui/src/status/tests.rs @@ -746,7 +746,6 @@ async fn status_model_provider_uses_bedrock_runtime_base_url_and_gates_usage_lin /*collaboration_mode*/ None, /*reasoning_effort_override*/ None, "".to_string(), - /*workspace_state_stale*/ false, /*refreshing_rate_limits*/ false, ); let rendered = render_lines(&composite.display_lines(/*width*/ 120)).join("\n"); @@ -788,7 +787,6 @@ async fn status_model_provider_uses_bedrock_runtime_base_url_and_gates_usage_lin /*collaboration_mode*/ None, /*reasoning_effort_override*/ None, "".to_string(), - /*workspace_state_stale*/ false, /*refreshing_rate_limits*/ false, ); let rendered = render_lines(&composite.display_lines(/*width*/ 120)).join("\n"); @@ -1579,7 +1577,6 @@ async fn status_snapshot_uses_default_reasoning_when_config_empty() { /*collaboration_mode*/ None, /*reasoning_effort_override*/ Some(Some(ReasoningEffort::Medium)), "".to_string(), - /*workspace_state_stale*/ false, /*refreshing_rate_limits*/ false, ); let mut rendered_lines = render_lines(&composite.display_lines(/*width*/ 80));