Files
codex/codex-rs/tui/src/app/reasoning_replay.rs
T
Felipe Coury 9ec33e1926 Show streaming reasoning summaries in the TUI status row (#43921)
## What changed

- Update the status heading from the latest usable reasoning line and retain it through tool activity and empty reasoning items. Keep completed reasoning in the expanded transcript only.
- Restore active reasoning after resume, thread switches, and session refreshes, including when earlier events have left the replay buffer.
- Default new embedded TUI threads to `model_reasoning_summary = "detailed"`, honoring explicit summary settings. Keep `concurrent_reasoning_summaries` opt-in and disable it when summaries are `none`.
- Persist the request's captured reasoning summary setting in context updates and local and remote compaction checkpoints.
- Animate status text with a smooth, grapheme-aware shimmer that respects terminal colors and reduced motion.

## Testing

Add regression coverage for reasoning status updates, transcript visibility, resume and buffered replay, outbound summary configuration, and summary settings across all three compaction modes. Add shimmer snapshots and checks for smooth brightness changes and Unicode grapheme preservation.

GitOrigin-RevId: 725c7de20f23166d7a3da6daeca617add5cbc600
2026-09-08 21:41:02 +00:00

68 lines
2.8 KiB
Rust

//! Restores the active reasoning stream without treating its snapshot as a completed item.
//!
//! Buffered turn events must replay before the active item is restored. Its first retained
//! event, or the end of replay when all its events were evicted, establishes that boundary.
use super::ThreadBufferedEvent;
use super::ThreadEventSnapshot;
use crate::chatwidget::ChatWidget;
use codex_app_server_protocol::ItemStartedNotification;
use codex_app_server_protocol::ServerNotification;
use codex_app_server_protocol::ThreadItem;
use codex_app_server_protocol::TurnStatus;
pub(super) struct ReasoningReplay {
started: Option<ItemStartedNotification>,
parts: Option<(Vec<String>, Vec<String>)>,
}
impl ReasoningReplay {
pub(super) fn new(snapshot: &mut ThreadEventSnapshot) -> Self {
let started = snapshot.active_reasoning_item.take();
let parts = started.as_ref().and_then(|started| {
let turn = snapshot
.turns
.iter_mut()
.find(|turn| turn.id == started.turn_id && turn.status == TurnStatus::InProgress)?;
let index = turn.items.iter().position(
|item| matches!(item, ThreadItem::Reasoning { id, .. } if id == started.item.id()),
)?;
match turn.items.remove(index) {
ThreadItem::Reasoning {
summary, content, ..
} => Some((summary, content)),
_ => unreachable!("matched a reasoning item"),
}
});
Self { started, parts }
}
pub(super) fn before_event(&mut self, event: &ThreadBufferedEvent, chat: &mut ChatWidget) {
if self.started.as_ref().is_some_and(|started| {
matches!(event, ThreadBufferedEvent::Notification(notification) if match notification.as_ref() {
ServerNotification::ItemStarted(item) => {
item.turn_id == started.turn_id && item.item.id() == started.item.id()
}
ServerNotification::ReasoningSummaryTextDelta(delta) => {
delta.turn_id == started.turn_id && delta.item_id == started.item.id()
}
ServerNotification::ReasoningTextDelta(delta) => {
delta.turn_id == started.turn_id && delta.item_id == started.item.id()
}
ServerNotification::ReasoningSummaryPartAdded(part) => {
part.turn_id == started.turn_id && part.item_id == started.item.id()
}
_ => false,
})
}) {
self.restore(chat);
}
}
pub(super) fn restore(&mut self, chat: &mut ChatWidget) {
if let Some(started) = self.started.take() {
chat.restore_active_reasoning_item(started, self.parts.take());
}
}
}