From 4487f684803e4832c77cd1f5d05005530b78970c Mon Sep 17 00:00:00 2001 From: Ian MacLeod Date: Tue, 1 Dec 2026 22:58:56 +0000 Subject: [PATCH] Show task-opening progress inline in the Codex TUI (#65126) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Why The task list already labels a visible task `Opening…`, but the spinner appears in the footer, away from the task it describes. ## What changed Place the spinner next to `Opening…` in the task's status column or compact detail row, preserving the selection highlight. Keep the `Opening task…` footer as a fallback when the inline status has no room or the task is outside the visible list. ## Testing Cover inline rendering, reverse-video selection styling, and the footer fallback for short layouts and history results that disappear when opening clears the search. GitOrigin-RevId: 6a66b368fefb4c43aa0b27ffe9b24bb07d1839d3 --- codex-rs/tui/src/app/agent_center/render.rs | 33 ++++++--- codex-rs/tui/src/app/agent_center/rows.rs | 57 +++++++++++--- codex-rs/tui/src/app/agent_center_tests.rs | 74 +++++++++++++++++++ .../tui/src/app/tests/new_session_tests.rs | 12 +-- 4 files changed, 147 insertions(+), 29 deletions(-) diff --git a/codex-rs/tui/src/app/agent_center/render.rs b/codex-rs/tui/src/app/agent_center/render.rs index 4938468040..a6bb695412 100644 --- a/codex-rs/tui/src/app/agent_center/render.rs +++ b/codex-rs/tui/src/app/agent_center/render.rs @@ -55,6 +55,12 @@ struct CenterLayout { } impl AgentsOverviewView { + pub(super) fn dock_loading_glyph(&self, started_at: Instant) -> &'static str { + self.dock_motion.as_ref().map_or("", |(motion, frames)| { + loading_glyph_with_delay(started_at, LOADING_FRAME_INTERVAL, *motion, frames) + }) + } + fn center_layout(&self, area: Rect) -> CenterLayout { let state = self.state(); let footer_height = u16::from(area.height >= 2); @@ -298,11 +304,13 @@ impl Renderable for AgentsOverviewView { }) .or_else(|| state.server_version_notice.clone()); let footer = inset(layout.footer); - let progress = if help || state.connection_notice.is_some() || footer.is_empty() { - None - } else if let Some(opening) = state.opening_task { - Some(("Opening task…", opening.started_at)) - } else if self.dock_motion.is_some() && history.is_none() && notice.is_none() { + let can_show_progress = !help && state.connection_notice.is_none() && !footer.is_empty(); + let opening = state.opening_task; + let discovery = if can_show_progress + && self.dock_motion.is_some() + && history.is_none() + && notice.is_none() + { let full_label = "Loading additional tasks…"; // Reserve a column each for the spinner and its trailing space. let label = if full_label.width() + 2 <= usize::from(footer.width) { @@ -317,17 +325,18 @@ impl Renderable for AgentsOverviewView { None }; drop(state); - if !help { - self.render_center_rows( + let opening_visible = !help + && self.render_center_rows( layout.list, buf, - /*progress_in_footer*/ progress.is_some(), + /*progress_in_footer*/ discovery.is_some(), ); - } + let progress = opening + .filter(|_| can_show_progress && !opening_visible) + .map(|task| ("Opening task…", task.started_at)) + .or(discovery); if let Some((label, started_at)) = progress { - let glyph = self.dock_motion.as_ref().map_or("", |(motion, frames)| { - loading_glyph_with_delay(started_at, LOADING_FRAME_INTERVAL, *motion, frames) - }); + let glyph = self.dock_loading_glyph(started_at); let glyph = if glyph.is_empty() { " " } else { glyph }; line( vec![ diff --git a/codex-rs/tui/src/app/agent_center/rows.rs b/codex-rs/tui/src/app/agent_center/rows.rs index 9bdf712d44..437cf806e2 100644 --- a/codex-rs/tui/src/app/agent_center/rows.rs +++ b/codex-rs/tui/src/app/agent_center/rows.rs @@ -86,12 +86,34 @@ impl AgentsOverviewView { } } + fn render_opening_spinner( + &self, + opening: OpeningTask, + x: u16, + y: u16, + style: Style, + buf: &mut Buffer, + ) { + let glyph = self.dock_loading_glyph(opening.started_at); + // In reverse video the foreground supplies the selection fill. + let style = if style + .add_modifier + .contains(ratatui::style::Modifier::REVERSED) + { + style + } else { + style.fg(crate::style::accent_color_on(style.bg)) + }; + buf.set_string(x, y, glyph, style); + } + + /// Returns whether the opening status has a visible slot, even before the spinner appears. pub(super) fn render_center_rows( &self, area: Rect, buf: &mut Buffer, progress_in_footer: bool, - ) { + ) -> bool { let row_width = area.width; let TaskListLayout { area, @@ -105,7 +127,7 @@ impl AgentsOverviewView { let mut state = self.state(); let viewport = state.scroll_area; if area.is_empty() { - return; + return false; } state.selection_offscreen = !entries.is_empty() && !page.contains(&selected); if entries.is_empty() { @@ -131,22 +153,24 @@ impl AgentsOverviewView { area, buf, ); - return; + return false; } let selected_style = if self.dock_focused == Some(false) { crate::style::quiet_workspace_style() } else { selection_style() }; - let opening = state.opening_task.map(|task| task.thread_id); + let opening = state.opening_task; + let mut opening_visible = false; let status_for = |task: &AgentsOverviewRow| { let (status, dot) = Self::status(task); - let label = if opening == Some(task.thread_id) { + let opening = opening.filter(|opening| opening.thread_id == task.thread_id); + let label = if opening.is_some() { "Opening…" } else { status }; - (label, dot) + (label, dot, opening) }; let reference = chrono::Utc::now(); let sort = if state.searching { @@ -199,7 +223,7 @@ impl AgentsOverviewView { Style::default().dim() }; buf.set_style(background, style); - let (status, _) = status_for(task); + let (status, _, opening) = status_for(task); let branch = task .thread .git_info @@ -210,6 +234,12 @@ impl AgentsOverviewView { None => format!(" {status}"), }; line(Line::from(detail).style(style), rect, buf); + if let Some(opening) = opening + && rect.width > 4 + { + opening_visible = true; + self.render_opening_spinner(opening, rect.x + 2, rect.y, style, buf); + } continue; } TaskListRow::Gap => continue, @@ -303,7 +333,7 @@ impl AgentsOverviewView { Style::default() }; buf.set_style(background, style); - let (status, mut dot) = status_for(task); + let (status, mut dot, opening) = status_for(task); let idle = matches!( task.group, AgentsOverviewGroup::Ready | AgentsOverviewGroup::Finished @@ -329,6 +359,14 @@ impl AgentsOverviewView { buf, ); let (mut title, status_area, updated) = columns(rect, widths); + if let Some(opening) = opening + && !status_area.is_empty() + { + // Leave the status text aligned and preserve the gap after a long title. + opening_visible = true; + self.render_opening_spinner(opening, title.right(), rect.y, style, buf); + title.width -= 2; + } if task.has_voice && title.width >= 8 { let badge = Rect::new( title.right() - 8, @@ -350,7 +388,7 @@ impl AgentsOverviewView { } // On narrow rows the result dot shares the only slot for the working or alert icon. if task.unread && !idle && status_area.is_empty() { - prefix.push_str(status); + prefix.push_str(Self::status(task).0); prefix.push_str(": "); } let prefix = Span::from(prefix); @@ -389,5 +427,6 @@ impl AgentsOverviewView { buf, ); } + opening_visible } } diff --git a/codex-rs/tui/src/app/agent_center_tests.rs b/codex-rs/tui/src/app/agent_center_tests.rs index bea9b091d3..4f5364f230 100644 --- a/codex-rs/tui/src/app/agent_center_tests.rs +++ b/codex-rs/tui/src/app/agent_center_tests.rs @@ -40,6 +40,69 @@ pub(super) fn screen(view: &AgentsOverviewView, width: u16, height: u16) -> Stri ) } +#[tokio::test] +async fn opening_feedback_follows_the_visible_status() { + use crate::app::agents_overview_view::OpeningTask; + + let app = make_test_app().await; + let id = ThreadId::new(); + let task = overview_thread( + id, + /*parent_thread_id*/ None, + "Investigate retry", + ThreadStatus::Idle, + ); + let mut view = app.agents_overview_view(vec![task], Some(id)); + view.dock_focused = Some(true); + view.dock_motion = Some(( + crate::motion::MotionMode::Reduced, + crate::tui::FrameRequester::test_dummy(), + )); + let state = &app.agents_overview.view_state; + let opening = OpeningTask { + thread_id: id, + started_at: std::time::Instant::now(), + }; + let compact = || screen(&view, /*width*/ 36, /*height*/ 7); + let before = compact(); + state.lock().unwrap().opening_task = Some(opening); + let pending = compact(); + assert!(pending.contains("Investigate retry")); + insta::assert_snapshot!(pending.lines().last().unwrap().trim(), @"◌ Opening task…"); + + // With room for the status, reverse video must keep a continuous selection fill. + let area = Rect::new( + /*x*/ 0, /*y*/ 0, /*width*/ 36, /*height*/ 14, + ); + let mut buf = ratatui::buffer::Buffer::empty(area); + crate::terminal_palette::with_test_palette( + /*colors*/ None, + || view.render(area, &mut buf), + ); + let spinner = buf + .content + .iter() + .position(|cell| cell.symbol() == "◌") + .unwrap(); + let label = &buf.content[spinner + 2]; + assert_eq!(label.symbol(), "O"); + assert!(label.modifier.contains(ratatui::style::Modifier::REVERSED)); + assert_eq!(buf.content[spinner].style(), label.style()); + assert!(buffer_text(&buf).lines().last().unwrap().contains("? help")); + state.lock().unwrap().opening_task = None; + assert_eq!(compact(), before); + + // A history-only result leaves the visible list as soon as Enter clears the search. + state.lock().unwrap().has_more = true; + view.handle_key_event(KeyCode::Char('/').into()); + view.handle_paste("Investigate retry".into()); + view.rows[0].search_id = Some(state.lock().unwrap().history.as_ref().unwrap().id); + view.handle_key_event(KeyCode::Enter.into()); + state.lock().unwrap().opening_task = Some(opening); + let pending = screen(&view, /*width*/ 80, /*height*/ 14); + insta::assert_snapshot!(pending.lines().last().unwrap().trim(), @"◌ Opening task…"); +} + #[tokio::test] async fn live_center_home_and_end_preserve_selection_across_refreshes() { let mut app = make_test_app().await; @@ -1514,6 +1577,17 @@ async fn workspace_navigation_preserves_the_draft_and_reading_position() -> Resu screens.push(format!("{label}\n{screen}")); } } + app.paint_docked_task_opening(&mut tui, id)?; + let frame = buffer_text(tui.terminal.previous_buffer()); + let status = frame + .lines() + .find(|line| line.contains("retry-fix")) + .and_then(|line| line.split_once('│')) + .expect("docked task status") + .0; + insta::assert_snapshot!(status.trim(), @"◌ Opening… · retry-fix"); + app.finish_docked_task_opening(&tui, id); + let [center, conversation] = wide_styles.as_slice() else { panic!("expected both wide focus states"); }; diff --git a/codex-rs/tui/src/app/tests/new_session_tests.rs b/codex-rs/tui/src/app/tests/new_session_tests.rs index 663f1012f6..2f381aa0a1 100644 --- a/codex-rs/tui/src/app/tests/new_session_tests.rs +++ b/codex-rs/tui/src/app/tests/new_session_tests.rs @@ -1586,15 +1586,11 @@ async fn resumed_backend_handoff_detaches_through_the_source_connection() -> Res } }; let frame = buffer_text(tui.terminal.previous_buffer()); - let footer = frame + let (opening_task, _) = frame .lines() - .last() - .unwrap() - .split('│') - .next() - .unwrap() - .trim(); - insta::assert_snapshot!(footer, @"◌ Opening task…"); + .find_map(|row| row.split_once("◌ Opening…")) + .expect("opening task row"); + insta::assert_snapshot!(opening_task.trim(), @"› ○ Untitled task"); let approval = exec_approval_request(resumed_id, "turn", "call", /*approval_id*/ None); let buffered = crate::app::app_server_requests::BufferedServerRequest::new( approval,