From 58cb1ccf8def3b8e93407352f3aa5b46d3e4a3d5 Mon Sep 17 00:00:00 2001 From: Felipe Coury Date: Thu, 26 Nov 2026 19:04:05 +0000 Subject: [PATCH] Smooth transitions between TUI reasoning headings (#64202) ## Why Streaming reasoning summaries can replace the status heading before the current line finishes, making fast updates hard to read. ## What changed With shimmer active, sample the latest usable reasoning heading every 3.5 seconds while letting the visible line finish as its text arrives. Fade out the previous heading and reveal the next one across the visible terminal columns. Retry messages still appear immediately, and reduced motion and unsupported terminals keep the static display. Use the same prepared frame for layout and rendering so the status row can reflow when the heading changes. ## Testing Cover chunks that finish one heading and start another before a draw, delayed frames, and split Markdown bold markers. Snapshot the transition in light and dark themes and verify that hook status text reflows at the fade boundary. GitOrigin-RevId: 63c579602f030f461ac81c4841106b29755710b1 --- codex-rs/tui/src/bottom_pane/mod.rs | 10 +- codex-rs/tui/src/chatwidget.rs | 5 +- .../tui/src/chatwidget/safety_recourse.rs | 2 +- .../tui/src/chatwidget/status_controls.rs | 10 +- codex-rs/tui/src/chatwidget/streaming.rs | 54 +++++------ .../tests/reasoning_status_tests.rs | 60 ++++++++++++ .../src/chatwidget/tests/status_and_layout.rs | 14 ++- codex-rs/tui/src/screen_reader_tests.rs | 10 +- ...eaders_remain_stable_during_the_sweep.snap | 3 + ..._labels_sweep_smoothly_in_both_themes.snap | 30 ++++-- codex-rs/tui/src/status_indicator_widget.rs | 95 +++++++++++++++---- .../status_indicator_widget/effects_tests.rs | 70 ++++++++++++++ .../tui/src/status_indicator_widget/header.rs | 73 ++++++++++++++ ..._status_reflows_at_the_prepared_frame.snap | 14 +++ codex-rs/tui/src/summary_shimmer.rs | 90 ++++++++++++------ codex-rs/tui/src/summary_shimmer_tests.rs | 61 ++++++++---- 16 files changed, 490 insertions(+), 111 deletions(-) create mode 100644 codex-rs/tui/src/status_indicator_widget/header.rs create mode 100644 codex-rs/tui/src/status_indicator_widget/snapshots/codex_tui__status_indicator_widget__effects_tests__hook_status_reflows_at_the_prepared_frame.snap diff --git a/codex-rs/tui/src/bottom_pane/mod.rs b/codex-rs/tui/src/bottom_pane/mod.rs index 14620b66ae..ffb5eb2716 100644 --- a/codex-rs/tui/src/bottom_pane/mod.rs +++ b/codex-rs/tui/src/bottom_pane/mod.rs @@ -281,6 +281,7 @@ pub(crate) use chat_composer::ShellPrefixHandling; pub(crate) use chat_composer_history::HistoryEntry; use crate::status_indicator_widget::StatusDetailsCapitalization; +use crate::status_indicator_widget::StatusHeader; use crate::status_indicator_widget::StatusIndicatorWidget; #[cfg(test)] pub(crate) use experimental_features_view::ExperimentalFeatureItem; @@ -731,6 +732,10 @@ impl BottomPane { self.status.as_ref() } + pub(crate) fn status_widget_mut(&mut self) -> Option<&mut StatusIndicatorWidget> { + self.status.as_mut() + } + pub(crate) fn status_elapsed(&self) -> Option { self.is_task_running .then(|| self.status_timer.elapsed_at(Instant::now())) @@ -1167,6 +1172,9 @@ impl BottomPane { fn pre_draw_tick_at(&mut self, now: Instant) { self.composer.sync_popups(); self.maybe_show_delayed_prompts_at(now); + if let Some(status) = &mut self.status { + status.prepare_frame(now); + } self.tick_active_view(now); self.schedule_active_view_frame(); } @@ -1371,7 +1379,7 @@ impl BottomPane { /// was updated and requested a redraw. pub(crate) fn update_status( &mut self, - header: String, + header: impl Into, details: Option, details_capitalization: StatusDetailsCapitalization, details_max_lines: usize, diff --git a/codex-rs/tui/src/chatwidget.rs b/codex-rs/tui/src/chatwidget.rs index e419698b81..9d5da01036 100644 --- a/codex-rs/tui/src/chatwidget.rs +++ b/codex-rs/tui/src/chatwidget.rs @@ -252,6 +252,7 @@ use crate::status::RateLimitSnapshotDisplay; use crate::status::remote_connection::RemoteConnectionStatus; use crate::status_indicator_widget::STATUS_DETAILS_DEFAULT_MAX_LINES; use crate::status_indicator_widget::StatusDetailsCapitalization; +use crate::status_indicator_widget::StatusHeader; use crate::text_formatting::truncate_text; use crate::tui::FrameRequester; mod activity_groups; @@ -679,8 +680,8 @@ pub(crate) struct ChatWidget { interrupts: InterruptManager, // Accumulates the current reasoning block text to extract a header reasoning_buffer: String, - // Caches the first completed bold header so later deltas do not rescan the whole block. - reasoning_header: Option, + // Keep the last usable heading through tools and empty reasoning items. + reasoning_header: Option, // Preserves reasoning-summary part boundaries for transcript-only recording. reasoning_summary_parts: Vec, status_state: StatusState, diff --git a/codex-rs/tui/src/chatwidget/safety_recourse.rs b/codex-rs/tui/src/chatwidget/safety_recourse.rs index 8126459a26..f5a5617b9a 100644 --- a/codex-rs/tui/src/chatwidget/safety_recourse.rs +++ b/codex-rs/tui/src/chatwidget/safety_recourse.rs @@ -39,7 +39,7 @@ pub(super) fn on_metadata(chat: &mut ChatWidget, notification: TurnModerationMet chat.clear_safety_buffering(); chat.bottom_pane.ensure_status_indicator(); chat.set_status_header( - "I can’t help with this request. Preparing alternative suggestions…".into(), + "I can’t help with this request. Preparing alternative suggestions…".to_owned(), ); } } diff --git a/codex-rs/tui/src/chatwidget/status_controls.rs b/codex-rs/tui/src/chatwidget/status_controls.rs index 399ae2c491..eb088e67a2 100644 --- a/codex-rs/tui/src/chatwidget/status_controls.rs +++ b/codex-rs/tui/src/chatwidget/status_controls.rs @@ -16,7 +16,7 @@ impl ChatWidget { /// requested a redraw. pub(super) fn set_status( &mut self, - header: String, + header: impl Into, details: Option, details_capitalization: StatusDetailsCapitalization, details_max_lines: usize, @@ -27,12 +27,12 @@ impl ChatWidget { && self.status_state.retry_status_header.is_none() { ( - compaction::COMPACTION_HEADER.to_string(), + compaction::COMPACTION_HEADER.to_string().into(), Some(compaction::COMPACTION_DETAILS.to_string()), STATUS_DETAILS_DEFAULT_MAX_LINES, ) } else { - (header, details, details_max_lines) + (header.into(), details, details_max_lines) }; let details = details .filter(|details| !details.is_empty()) @@ -46,7 +46,7 @@ impl ChatWidget { } }); self.status_state.set_status(StatusIndicatorState { - header: header.clone(), + header: header.text.clone(), details: details.clone(), details_max_lines, }); @@ -75,7 +75,7 @@ impl ChatWidget { /// Convenience wrapper around [`Self::set_status`]; /// updates the status indicator header and clears any existing details, returning whether the /// visible status indicator requested a redraw. - pub(super) fn set_status_header(&mut self, header: String) -> bool { + pub(super) fn set_status_header(&mut self, header: impl Into) -> bool { self.set_status( header, /*details*/ None, diff --git a/codex-rs/tui/src/chatwidget/streaming.rs b/codex-rs/tui/src/chatwidget/streaming.rs index 4c950ec824..cf2eaeb494 100644 --- a/codex-rs/tui/src/chatwidget/streaming.rs +++ b/codex-rs/tui/src/chatwidget/streaming.rs @@ -13,24 +13,23 @@ fn streamed_message_matches_completed(streamed: &str, completed: &str) -> bool { streamed == completed || streamed.strip_suffix('\n') == Some(completed) } -fn latest_summary_line(text: &str) -> Option { - text.lines().rev().find_map(|line| { - let line = line.trim(); - if line.is_empty() || line.starts_with("