Lightweight coding agent that runs in your terminal
Rust
Improve usage report layouts and preserve reading positions (#46864)
Eric Trautd6d43270bd79
diff --git a/codex-rs/tui/src/analytics.rs b/codex-rs/tui/src/analytics.rsindex 8ef53a3946..975fa54ece 100644--- a/codex-rs/tui/src/analytics.rs+++ b/codex-rs/tui/src/analytics.rs@@ -75,7 +75,10 @@ pub(crate) struct AnalyticsView {section: Section,show_help: bool,zoomed: bool,- scroll_offset: usize,+ dashboard_scroll: usize,+ body_area: ratatui::layout::Rect,+ report_area: ratatui::layout::Rect,+ selection_visible: bool,help_scroll: usize,follow_selection: bool,viewport_height: usize,@@ -104,7 +107,10 @@ impl AnalyticsView {section: Section::Summary,show_help: false,zoomed: true,- scroll_offset: 0,+ dashboard_scroll: 0,+ body_area: ratatui::layout::Rect::default(),+ report_area: ratatui::layout::Rect::default(),+ selection_visible: false,help_scroll: 0,follow_selection: true,viewport_height: 1,@@ -425,7 +431,12 @@ impl AnalyticsView {let chart = self.section != Section::Chats;let count = self.row_count().max(/*other*/ 1);let mut scroll_offset = self.scroll_offset();- let SectionState { cursor, detail, .. } = &mut self.sections[self.section];+ let SectionState {+ cursor,+ detail,+ follow_selection_on_focus,+ ..+ } = &mut self.sections[self.section];let previous_cursor = *cursor;match action {Some(ListAction::MoveUp) => *cursor = cursor.saturating_sub(/*rhs*/ 1),@@ -460,6 +471,7 @@ impl AnalyticsView {} else if !chart && *cursor != previous_cursor {*detail = None;}+ *follow_selection_on_focus |= !self.zoomed && *cursor != previous_cursor;*self.scroll_offset_mut() = scroll_offset;}@@ -487,9 +499,8 @@ impl AnalyticsView {tui.frame_requester().schedule_frame();}TuiEvent::Draw | TuiEvent::Resume | TuiEvent::Resize(_) | TuiEvent::FocusGained => {- if matches!(event, TuiEvent::Resize(_)) && !self.show_help {- self.follow_selection = true;- }+ // Rendering follows a selection on resize only when it was visible before+ // reflow. Preserve an intentional reading position away from that selection.tui.draw(u16::MAX, |frame| self.render(frame.area(), frame.buffer))?;}_ => {}diff --git a/codex-rs/tui/src/analytics/account_layout_tests.rs b/codex-rs/tui/src/analytics/account_layout_tests.rsindex 787052cc43..8ef18bd2d7 100644--- a/codex-rs/tui/src/analytics/account_layout_tests.rs+++ b/codex-rs/tui/src/analytics/account_layout_tests.rs@@ -74,9 +74,7 @@ async fn changing_ranges_and_grouping_preserves_other_reports_and_focus() {view.sections.0.each_ref().map(|state| state.detail),view.sections.0.each_ref().map(|state| state.group),);- press(&mut view, KeyCode::Char('z'));screen(&mut view, /*width*/ 58, /*height*/ 25);- press(&mut view, KeyCode::Char('z'));assert_eq!((view.ranges,@@ -457,7 +455,11 @@ fn taller_report_reveals_more_legend_rows_and_keeps_timestamp_in_controls() {tall.lines().filter(|line| line.contains('●')).count()> short.lines().filter(|line| line.contains('●')).count());- assert!(tall.lines().take(6).any(|line| line.contains("Updated")));+ assert!(+ tall.lines()+ .take(usize::from(view.body_area.y))+ .any(|line| line.contains("Updated"))+ );for width in [24, 40, 64] {let narrow = screen(&mut view, width, /*height*/ 60);assert!(narrow.lines().nth(/*n*/ 3).unwrap().contains("7d/30d"));diff --git a/codex-rs/tui/src/analytics/chart.rs b/codex-rs/tui/src/analytics/chart.rsindex 32d31dd816..33d8bc9243 100644--- a/codex-rs/tui/src/analytics/chart.rs+++ b/codex-rs/tui/src/analytics/chart.rs@@ -1,5 +1,6 @@//! Daily history with a stable chart and a compact, separated breakdown table.//! Chart series rank by the full range; table rows rank by the selected day and retain series colors.+//! Wide focused reports place their breakdown beside the plot; narrow reports stack it.//! Missing and zero days retain the same row count; only viewport changes and explicit expansion change height.use super::AnalyticsView;@@ -148,12 +149,14 @@ impl AnalyticsView {.data.iter().any(|day| day.total != 0.0 || day.values.iter().any(|value| value.value != 0.0));+ let side_by_side = self.zoomed && width >= 140 && height > 0;+ let plot_width = if side_by_side { width - 48 } else { width };let mut bands = 0;- if has_activity {- let chart = plot::chart(&days, &categories, cursor, width, height, history.unit);+ if has_activity && height > 0 {+ let chart = plot::chart(&days, &categories, cursor, plot_width, height, history.unit);bands = chart.bands;lines.extend(chart.lines);- } else {+ } else if !has_activity {lines.push(if matches!(section,@@ -170,7 +173,12 @@ impl AnalyticsView {);}- let table_width = width.min(/*other*/ 56);+ let chart_end = lines.len();+ let table_width = if side_by_side {+ 44+ } else {+ width.min(/*other*/ 56)+ };lines.push(Line::default());if self.zoomed {lines.push("─".repeat(table_width).dim().into());@@ -193,7 +201,7 @@ impl AnalyticsView {};lines.push(truncate_line_with_ellipsis_if_overflow(vec![selected_date.clone().bold(), summary].into(),- width,+ table_width,));if self.zoomed {lines.push(columns(@@ -318,7 +326,7 @@ impl AnalyticsView {}.set_style(secondary_style()).into(),- width,+ table_width,));lines.resize(table_end, Line::default());}@@ -333,6 +341,10 @@ impl AnalyticsView {.into(),);}+ if side_by_side {+ let table = lines.split_off(chart_end);+ lines = super::render::join_columns(&lines, &table[1..], plot_width);+ }plot::Chart { lines, bands }}}diff --git a/codex-rs/tui/src/analytics/chat_panel.rs b/codex-rs/tui/src/analytics/chat_panel.rsindex 19d6ff114d..133ff6b5b3 100644--- a/codex-rs/tui/src/analytics/chat_panel.rs+++ b/codex-rs/tui/src/analytics/chat_panel.rs@@ -18,7 +18,8 @@ use std::ops::Range;impl AnalyticsView {pub(super) fn chat_lines(&self, width: usize) -> (Vec<Line<'static>>, Range<usize>) {- let width = width.clamp(/*min*/ 1, /*max*/ 96);+ let row_width = width.clamp(/*min*/ 1, /*max*/ 97);+ let width = row_width.saturating_sub(/*rhs*/ 1).max(/*other*/ 1);let wrap = |lines: Vec<Line<'static>>| word_wrap_lines(lines, RtOptions::new(width));let mut lines = wrap(vec!["Active in past 30 days · sorted by lifetime credits"@@ -126,6 +127,7 @@ impl AnalyticsView {width,)]};+ let header_len = row.len();if self.sections[Section::Chats].detail == Some(index)&& let Some(usage) = &chat.usage{@@ -254,7 +256,16 @@ impl AnalyticsView {}row.push(Line::default());}- wrap(row)+ let details = row.split_off(header_len);+ let mut row = wrap(row);+ // Wrap first: wrapping trims the highlighted trailing blank otherwise.+ if selected {+ for line in &mut row {+ super::styles::select_row(line, row_width);+ }+ }+ row.extend(wrap(details));+ row}).collect::<Vec<_>>();let coverage = wrap(vec![@@ -279,13 +290,10 @@ impl AnalyticsView {]).len();// Measure wrapped details before choosing neighbors so the range describes the rendered rows.- let budget = if self.zoomed {- self.viewport_height- .saturating_sub(lines.len() + coverage.len() + range_height + 4)- } else {- usize::MAX- };- let row_limit = if self.zoomed { count } else { 5 };+ let budget = self+ .viewport_height+ .saturating_sub(lines.len() + coverage.len() + range_height + 2);+ let row_limit = count;let cursor = self.sections[Section::Chats].cursor.min(count - 1);let mut first = cursor;let mut end = cursor + 1;diff --git a/codex-rs/tui/src/analytics/chat_panel_tests.rs b/codex-rs/tui/src/analytics/chat_panel_tests.rsindex e5b1de0be0..ff50868b0d 100644--- a/codex-rs/tui/src/analytics/chat_panel_tests.rs+++ b/codex-rs/tui/src/analytics/chat_panel_tests.rs@@ -43,12 +43,10 @@ fn chats_range_controls_and_visible_rows() {visible.last().unwrap())));}- press(&mut view, KeyCode::Char('z'));press(&mut view, KeyCode::Char('r'));assert_eq!(view.ranges, [0; 3]);press(&mut view, KeyCode::Char('2'));press(&mut view, KeyCode::Char('r'));- press(&mut view, KeyCode::Char('z'));assert_eq!(view.ranges[view.range_group(Section::Credits) as usize], 1);assert!(screen(&mut view, /*width*/ 110, /*height*/ 24).contains("r 7d/30d"));}@@ -102,7 +100,8 @@ fn chats_breakdown_ranks_nonzero_groups_and_reflows() {press(&mut view, KeyCode::Char('a'));assert!(!view.show_zero_credit_groups);let wide = view.chat_lines(/*width*/ 220).0;- assert!(wide.iter().all(|line| line.width() <= 96));+ // The content stays within 96 columns, plus one highlighted trailing blank.+ assert!(wide.iter().all(|line| line.width() <= 97));insta::assert_snapshot!(screens.join("\n"));}@@ -157,33 +156,11 @@ fn unavailable_chat_titles_are_hidden_in_panel_and_overview() {usage: None,}],});- for zoomed in [true, false] {- view.zoomed = zoomed;- view.follow_selection = true;- let output = screen(&mut view, /*width*/ 110, /*height*/ 28);- assert!(!output.contains("Another workspace's private title"));- assert!(output.contains("Chat usage unavailable"));- }-}-#[test]-fn refreshing_chats_clears_details_before_replacing_the_ranked_rows() {- for unavailable in [true, false] {- let mut view = fixture::view(models::AccountKind::Enterprise);- view.section = Section::Chats;- press(&mut view, KeyCode::Enter);- assert_eq!(view.sections[Section::Chats].detail, Some(0));- press(&mut view, KeyCode::Char('R'));- assert_eq!(view.sections[Section::Chats].detail, None);- view.account = Load::Ready(codex_protocol::account::PlanType::EnterpriseCbpUsageBased);- view.chats = if unavailable {- Load::Error("Temporarily unavailable".into())- } else {- Load::Ready(chats::Chats::default())- };- press(&mut view, KeyCode::Esc);- assert!(view.is_done);- }+ view.follow_selection = true;+ let output = screen(&mut view, /*width*/ 110, /*height*/ 28);+ assert!(!output.contains("Another workspace's private title"));+ assert!(output.contains("Chat usage unavailable"));}#[test]diff --git a/codex-rs/tui/src/analytics/chrome.rs b/codex-rs/tui/src/analytics/chrome.rsindex ae87330700..9ccc618308 100644--- a/codex-rs/tui/src/analytics/chrome.rs+++ b/codex-rs/tui/src/analytics/chrome.rs@@ -1,5 +1,5 @@-//! Report navigation and keyboard help for the full-screen usage view.-//! Help has an independent scroll position and preserves report selection.+//! Report navigation and bounded keyboard help for the full-screen usage view.+//! Each report retains its own reading position; help never replaces its selection or draft.use super::AnalyticsView;use super::controls::Control;@@ -22,35 +22,38 @@ impl AnalyticsView {}}+ /// Each surface owns its reading position; switching surfaces never copies it.pub(super) fn scroll_offset(&self) -> usize {if self.show_help {self.help_scroll+ } else if self.zoomed {+ self.sections[self.section].scroll_offset} else {- self.scroll_offset+ self.dashboard_scroll}}pub(super) fn scroll_offset_mut(&mut self) -> &mut usize {if self.show_help {&mut self.help_scroll+ } else if self.zoomed {+ &mut self.sections[self.section].scroll_offset} else {- &mut self.scroll_offset+ &mut self.dashboard_scroll}}pub(super) fn toggle_dashboard(&mut self) {self.zoomed = !self.zoomed;- self.scroll_offset = 0;- self.follow_selection = true;+ self.follow_selection = !self.zoomed;}pub(super) fn select_section(&mut self, section: Section) {- if self.zoomed && section != self.section {- self.scroll_offset = 0;+ if section != self.section {+ self.section = section;+ self.follow_selection = !self.zoomed;+ self.show_help = false;}- self.follow_selection = !self.zoomed || section != self.section;- self.section = section;- self.show_help = false;}pub(super) fn chat_has_details(&self) -> bool {diff --git a/codex-rs/tui/src/analytics/consumer_refresh_tests.rs b/codex-rs/tui/src/analytics/consumer_refresh_tests.rsindex 47dae4327e..9861becd44 100644--- a/codex-rs/tui/src/analytics/consumer_refresh_tests.rs+++ b/codex-rs/tui/src/analytics/consumer_refresh_tests.rs@@ -71,7 +71,7 @@ fn consumer_chats_keep_missing_rows_and_only_offer_known_metrics() {}#[test]-fn consumer_overview_shows_top_five_and_closes_with_retained_details() {+fn consumer_chats_show_all_rows_and_collapse_details_before_closing() {let mut view = fixture::view(models::AccountKind::Consumer);view.section = Section::Chats;view.tasks = Load::Ready(Chats {@@ -84,18 +84,20 @@ fn consumer_overview_shows_top_five_and_closes_with_retained_details() {}).collect(),..Chats::default()});+ screen(&mut view, /*width*/ 120, /*height*/ 42);press(&mut view, KeyCode::End);press(&mut view, KeyCode::Enter);assert_eq!(view.sections[Section::Chats].detail, Some(5));- press(&mut view, KeyCode::Char('z'));let content = view.task_lines(/*width*/ 70).0.iter()- .map(ToString::to_string)+ .map(|line| line.to_string().trim_end().to_owned()).collect::<Vec<_>>().join("\n");- assert!(content.contains("Task 5") && !content.contains("Task 0"));+ assert!(content.contains("Task 5") && content.contains("Task 0"));+ press(&mut view, KeyCode::Esc);+ assert!(!view.is_done);press(&mut view, KeyCode::Esc);assert!(view.is_done);}diff --git a/codex-rs/tui/src/analytics/navigation_tests.rs b/codex-rs/tui/src/analytics/navigation_tests.rsindex 98e4f88107..75ae895434 100644--- a/codex-rs/tui/src/analytics/navigation_tests.rs+++ b/codex-rs/tui/src/analytics/navigation_tests.rs@@ -148,7 +148,7 @@ fn vim_summary_navigation_scrolls_like_arrows() {],/*size*/ (64, 18),);- assert_eq!(views[0].scroll_offset, 1);+ assert_eq!(views[0].scroll_offset(), 1);}#[test]diff --git a/codex-rs/tui/src/analytics/panels.rs b/codex-rs/tui/src/analytics/panels.rsindex 0be723e859..53629f3b90 100644--- a/codex-rs/tui/src/analytics/panels.rs+++ b/codex-rs/tui/src/analytics/panels.rs@@ -48,10 +48,15 @@ impl AnalyticsView {if index == selection.start {wrapped_selection.start = wrapped.len();}- wrapped.extend(word_wrap_lines(- [line],- RtOptions::new(width.max(/*other*/ 1)),- ));+ if line.style.bg.is_some() && line.width() <= width {+ // Keep highlighted padding on selected rows that already fit the panel.+ wrapped.push(line);+ } else {+ wrapped.extend(word_wrap_lines(+ [line],+ RtOptions::new(width.max(/*other*/ 1)),+ ));+ }if index + 1 == selection.end {wrapped_selection.end = wrapped.len();}diff --git a/codex-rs/tui/src/analytics/plan_panel.rs b/codex-rs/tui/src/analytics/plan_panel.rsindex ee3bfc7801..6d81226016 100644--- a/codex-rs/tui/src/analytics/plan_panel.rs+++ b/codex-rs/tui/src/analytics/plan_panel.rs@@ -7,7 +7,6 @@ use super::render::join_columns;use super::sections::Section;use super::styles::secondary_style;use crate::keymap::ListAction;-use crate::style::accent_style;use codex_backend_client::PlanLimitDimension;use ratatui::style::Styled;use ratatui::style::Stylize;@@ -23,6 +22,7 @@ impl AnalyticsView {.ready().map(|report| &report.periods[window]);let count = periods.map_or(/*default*/ 0, Vec::len);+ let mut scroll_offset = self.scroll_offset();let cursor = &mut self.plan.cursor[window];let previous_cursor = *cursor;match action {@@ -44,14 +44,14 @@ impl AnalyticsView {}}Some(ListAction::Cancel) => {- self.is_done |= !self.zoomed || self.plan.expanded[window].take().is_none();+ self.is_done |= self.plan.expanded[window].take().is_none();}Some(ListAction::PageDown) => {- self.scroll_offset += self.viewport_height;+ scroll_offset += self.viewport_height;self.follow_selection = false;}Some(ListAction::PageUp) => {- self.scroll_offset = self.scroll_offset.saturating_sub(self.viewport_height);+ scroll_offset = scroll_offset.saturating_sub(self.viewport_height);self.follow_selection = false;}None => {}@@ -59,6 +59,9 @@ impl AnalyticsView {if *cursor != previous_cursor {self.plan.expanded[window] = None;}+ self.sections[Section::Plan].follow_selection_on_focus |=+ !self.zoomed && (self.plan.window != window || *cursor != previous_cursor);+ *self.scroll_offset_mut() = scroll_offset;}pub(super) fn plan_lines(&self, width: usize) -> (Vec<Line<'static>>, Range<usize>) {@@ -103,31 +106,26 @@ impl AnalyticsView {{let start = lines.len();let selected = self.plan.cursor[window] == index;- let label = if !self.zoomed {- format!("Latest period · {} total", report.periods[window].len())- } else {- format!(- "{} {} – {}{}",- if selected { "›" } else { " " },- period.start.format("%b %-d %H:%M"),- period.end.format("%b %-d %H:%M"),- if period.start <= report.as_of && period.end > report.as_of {- " *"- } else {- ""- }- )- };+ let label = format!(+ "{} {} – {}{}",+ if selected { "›" } else { " " },+ period.start.format("%b %-d %H:%M"),+ period.end.format("%b %-d %H:%M"),+ if period.start <= report.as_of && period.end > report.as_of {+ " *"+ } else {+ ""+ }+ );let amount = period.used.map(|value| format!("{}%", data::amount(value / 100.0))).unwrap_or_else(|| "Not available".into());- let row = columns(label.into(), amount.into(), table_width);- lines.push(if selected && self.plan.window == window {- row.set_style(accent_style())- } else {- row- });+ let mut row = columns(label.into(), amount.into(), table_width);+ if selected && self.plan.window == window {+ super::styles::select_row(&mut row, table_width);+ }+ lines.push(row);if self.zoomed && self.plan.expanded[window].as_ref() == Some(&period.id) {if !period.complete {lines.push(@@ -228,13 +226,8 @@ impl AnalyticsView {}lines.push(format!(- "Usage as of {} UTC{}",- as_of.format("%b %-d %H:%M"),- if self.zoomed {- " · * current at last update"- } else {- ""- }+ "Usage as of {} UTC · * current at last update",+ as_of.format("%b %-d %H:%M")).dim().into(),diff --git a/codex-rs/tui/src/analytics/plan_tests.rs b/codex-rs/tui/src/analytics/plan_tests.rsindex 43561e18b7..43c2b3d169 100644--- a/codex-rs/tui/src/analytics/plan_tests.rs+++ b/codex-rs/tui/src/analytics/plan_tests.rs@@ -1,5 +1,6 @@//! Snapshot semantics and independent plan-period navigation without a live billing service.use super::*;+use crate::analytics::AnalyticsView;use crate::analytics::fixture;use crate::analytics::models::AccountKind;use crate::analytics::sections::Section;@@ -28,6 +29,93 @@ fn response() -> PlanLimitHistory {.unwrap()}+#[tokio::test]+async fn resize_keeps_visible_weekly_selection_and_respects_manual_scroll() {+ let mut history = response();+ for index in 0..12 {+ let mut period = history.periods[0].clone();+ period.id = format!("five-{index}");+ history.periods.push(period);+ }+ let mut view = fixture::view(AccountKind::Consumer);+ view.plan.enabled = true;+ view.plan.report = Load::Ready(Report::parse(history).unwrap().unwrap());+ view.plan.poll();+ view.section = Section::Plan;+ view.zoomed = false;+ view.plan.expanded[0] = Some("five".into());+ let dashboard = view.dashboard_lines(/*width*/ 120, /*height*/ 60).0;+ assert!(+ dashboard+ .iter()+ .any(|line| line.to_string().contains("Weekly limits"))+ );+ view.zoomed = true;+ view.plan.expanded[0] = None;+ let render = |view: &mut AnalyticsView, width, height| {+ let mut terminal =+ ratatui::Terminal::new(ratatui::backend::TestBackend::new(width, height)).unwrap();+ terminal+ .draw(|frame| view.render(frame.area(), frame.buffer_mut()))+ .unwrap();+ terminal.backend().to_string()+ };+ render(&mut view, /*width*/ 80, /*height*/ 24);+ for code in [KeyCode::Char('z'), KeyCode::Right] {+ view.handle_key(KeyEvent::new(code, KeyModifiers::NONE));+ render(&mut view, /*width*/ 80, /*height*/ 24);+ }+ view.handle_key(KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE));+ assert!(render(&mut view, /*width*/ 80, /*height*/ 24).contains("Sep 1 00:00 – Sep 8 00:00"));+ render(&mut view, /*width*/ 120, /*height*/ 36);+ view.handle_key(KeyEvent::new(KeyCode::Char('?'), KeyModifiers::NONE));+ render(&mut view, /*width*/ 40, /*height*/ 16);+ view.handle_key(KeyEvent::new(KeyCode::Esc, KeyModifiers::NONE));+ let narrow = render(&mut view, /*width*/ 40, /*height*/ 16);+ assert!(view.scroll_offset() > 0);+ assert!(narrow.contains("Sep 1 00:00 – Sep 8 00:00"));+ assert!(narrow.contains("↑/↓ period · enter details"));+ view.handle_key(KeyEvent::new(KeyCode::PageUp, KeyModifiers::NONE));+ render(&mut view, /*width*/ 40, /*height*/ 16);+ let reading_position = view.scroll_offset();+ assert!(!view.selection_visible);+ for code in [KeyCode::Char('z'), KeyCode::Enter] {+ view.handle_key(KeyEvent::new(code, KeyModifiers::NONE));+ render(&mut view, /*width*/ 40, /*height*/ 16);+ }+ assert_eq!(view.scroll_offset(), reading_position);+ view.handle_key(KeyEvent::new(KeyCode::Char('?'), KeyModifiers::NONE));+ render(&mut view, /*width*/ 50, /*height*/ 16);+ view.handle_key(KeyEvent::new(KeyCode::Esc, KeyModifiers::NONE));+ render(&mut view, /*width*/ 50, /*height*/ 16);+ assert_eq!(view.scroll_offset(), reading_position);+ let mut tui = crate::tui::test_support::make_test_tui().unwrap();+ let event = crate::tui::TuiEvent::Resize(ratatui::layout::Size {+ width: 55,+ height: 16,+ });+ tui.screen_size_for_event(&event).unwrap();+ view.handle_event(&mut tui, event).unwrap();+ assert_eq!(view.scroll_offset(), reading_position);++ let mut history = response();+ let breakdown = &mut history.periods[0].breakdowns.as_mut().unwrap()[1];+ breakdown.rows = vec![breakdown.rows[0].clone(); 20];+ view.plan.report = Load::Ready(Report::parse(history).unwrap().unwrap());+ view.plan.poll();+ view.plan.window = 0;+ view.sections[Section::Plan].group = 1;+ view.plan.expanded[0] = Some("five".into());+ view.follow_selection = true;+ render(&mut view, /*width*/ 58, /*height*/ 16);+ view.handle_key(KeyEvent::new(KeyCode::PageDown, KeyModifiers::NONE));+ render(&mut view, /*width*/ 58, /*height*/ 16);+ let reading_position = view.scroll_offset();+ assert!(reading_position > 0);+ render(&mut view, /*width*/ 60, /*height*/ 16);+ assert_eq!(view.scroll_offset(), reading_position);+}+#[test]fn period_navigation_preserves_unknowns_and_resets_on_new_snapshot() {let mut view = fixture::view(AccountKind::Consumer);@@ -186,29 +274,15 @@ async fn plan_gate_prevents_requests_and_unavailable_plan_does_not_block_other_r}#[test]-fn plan_overview_escape_closes_with_retained_expansion() {- let mut history = response();- for index in 1..12 {- let mut period = history.periods[0].clone();- period.id = format!("five-{index}");- history.periods.push(period);- }+fn plan_escape_collapses_details_before_closing() {let mut view = fixture::view(AccountKind::Consumer);view.plan.enabled = true;- view.plan.report = Load::Ready(Report::parse(history).unwrap().unwrap());+ view.plan.report = Load::Ready(Report::parse(response()).unwrap().unwrap());view.plan.poll();view.section = Section::Plan;view.handle_key(KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE));- view.handle_key(KeyEvent::new(KeyCode::Char('z'), KeyModifiers::NONE));- let mut terminal = ratatui::Terminal::new(ratatui::backend::TestBackend::new(- /*width*/ 120, /*height*/ 60,- ))- .unwrap();- terminal- .draw(|frame| view.render(frame.area(), frame.buffer_mut()))- .unwrap();- let output = terminal.backend().to_string();- assert!(output.contains("Latest period · 12 total") && output.contains("Weekly limits"));+ view.handle_key(KeyEvent::new(KeyCode::Esc, KeyModifiers::NONE));+ assert!(!view.is_done);view.handle_key(KeyEvent::new(KeyCode::Esc, KeyModifiers::NONE));assert!(view.is_done);}diff --git a/codex-rs/tui/src/analytics/recovery_tests.rs b/codex-rs/tui/src/analytics/recovery_tests.rsindex 11cfdfccdc..d4b4890453 100644--- a/codex-rs/tui/src/analytics/recovery_tests.rs+++ b/codex-rs/tui/src/analytics/recovery_tests.rs@@ -1,4 +1,4 @@-//! Visible report controls and account-scoped dates.+//! Restored dashboard, visible controls, and responsive report regression coverage.use super::*;@@ -14,3 +14,27 @@ fn report_controls_show_dates_and_update_time() {assert!(output.contains("g Token type · m All models"));assert!(output.contains("Updated · Sep 2 16:00 UTC"));}++#[test]+fn tall_reports_use_available_height_and_wide_reports_put_details_beside_plot() {+ for (width, height) in [(80, 60), (180, 60)] {+ let mut view = fixture::view(models::AccountKind::Business);+ view.section = Section::Usage;+ let output = screen(&mut view, width, height);+ let plot_rows = output.lines().filter(|line| line.contains('█')).count();+ assert!(+ plot_rows > 14,+ "only {plot_rows} plot rows at {width} columns"+ );+ assert!(output.contains("731,000 tokens"));+ assert!(!output.contains("scroll"));+ if width == 180 {+ assert!(+ output+ .lines()+ .any(|line| line.contains("4.4M tokens") && line.contains('─'))+ );+ insta::assert_snapshot!(output);+ }+ }+}diff --git a/codex-rs/tui/src/analytics/redesign_tests.rs b/codex-rs/tui/src/analytics/redesign_tests.rsindex a41002a867..9029ef871b 100644--- a/codex-rs/tui/src/analytics/redesign_tests.rs+++ b/codex-rs/tui/src/analytics/redesign_tests.rs@@ -1,25 +1,28 @@-//! Fixed navigation and keyboard help around existing report bodies.+//! Responsive navigation and report loading regression coverage.use super::*;use pretty_assertions::assert_eq;#[test]-fn reports_keep_tabs_fixed_when_a_request_fails() {+fn reports_keep_tabs_fixed_and_expose_data_on_small_screens() {for (width, height) in [(120, 36), (80, 24), (40, 16)] {let mut view = fixture::view(models::AccountKind::Business);view.section = Section::Usage;- let loaded = screen(&mut view, width, height);+ let tokens = screen(&mut view, width, height);+ assert!(tokens.contains("tokens"));+ assert!(tokens.contains("Sep 2"));+ let tabs = tokens.lines().take(3).collect::<Vec<_>>();view.sections[Section::Usage].history = Load::Error("Couldn't load tokens.".into());let failed = screen(&mut view, width, height);- assert_eq!(- loaded.lines().take(3).collect::<Vec<_>>(),- failed.lines().take(3).collect::<Vec<_>>()- );+ assert_eq!(tabs, failed.lines().take(3).collect::<Vec<_>>());assert!(failed.contains("Couldn't load tokens."));+ if width == 40 {+ insta::assert_snapshot!(format!("{tokens}\n{failed}"));+ }}}#[test]-fn keyboard_help_preserves_report_selection_and_reading_position() {+fn keyboard_tabs_and_help_preserve_report_reading_position() {let mut view = fixture::view(models::AccountKind::Business);view.section = Section::Usage;view.sections[Section::Usage].detail = Some(6);@@ -27,6 +30,20 @@ fn keyboard_help_preserves_report_selection_and_reading_position() {press(&mut view, KeyCode::PageDown);screen(&mut view, /*width*/ 80, /*height*/ 16);let offset = view.scroll_offset();+ press(&mut view, KeyCode::BackTab);+ assert_eq!(view.section, Section::Credits);+ screen(&mut view, /*width*/ 80, /*height*/ 16);+ press(&mut view, KeyCode::PageDown);+ screen(&mut view, /*width*/ 80, /*height*/ 16);+ press(&mut view, KeyCode::Tab);+ assert_eq!(+ (+ view.section,+ view.scroll_offset(),+ view.sections[Section::Usage].detail+ ),+ (Section::Usage, offset, Some(6))+ );view.handle_key(KeyEvent::new(KeyCode::Char('?'), KeyModifiers::SHIFT));let help = screen(&mut view, /*width*/ 40, /*height*/ 16);assert!(help.contains("Usage shortcuts"));@@ -38,19 +55,32 @@ fn keyboard_help_preserves_report_selection_and_reading_position() {assert!(view.scroll_offset() > 0);press(&mut view, KeyCode::Esc);assert_eq!(- (- view.show_help,- view.is_done,- view.section,- view.sections[Section::Usage].detail,- view.scroll_offset()- ),- (false, false, Section::Usage, Some(6), offset)+ (view.show_help, view.is_done, view.scroll_offset()),+ (false, false, offset));press(&mut view, KeyCode::Char('?'));assert_eq!(view.scroll_offset(), 0);press(&mut view, KeyCode::Char('?'));assert_eq!(view.scroll_offset(), offset);+ press(&mut view, KeyCode::Char('z'));+ screen(&mut view, /*width*/ 80, /*height*/ 16);+ let dashboard_offset = view.scroll_offset();+ press(&mut view, KeyCode::Char('?'));+ press(&mut view, KeyCode::Esc);+ assert_eq!(+ (view.zoomed, view.scroll_offset()),+ (false, dashboard_offset)+ );+ press(&mut view, KeyCode::Enter);+ screen(&mut view, /*width*/ 80, /*height*/ 16);+ assert_eq!(+ (+ view.zoomed,+ view.scroll_offset(),+ view.sections[Section::Usage].detail+ ),+ (true, offset, Some(6))+ );}#[test]diff --git a/codex-rs/tui/src/analytics/render.rs b/codex-rs/tui/src/analytics/render.rsindex 717eb40008..5671d7933d 100644--- a/codex-rs/tui/src/analytics/render.rs+++ b/codex-rs/tui/src/analytics/render.rs@@ -1,4 +1,4 @@-//! Fixed analytics navigation and keyboard help around existing report panels.+//! Fixed analytics navigation and responsive report space.//! Tabs and hints never wrap or move when a report loads, changes range, or becomes empty.use super::AnalyticsView;@@ -155,6 +155,12 @@ impl AnalyticsView {tabs,buf,);+ // Keep a visible selection on screen across reflow, while retaining intentional+ // reading positions when the user has scrolled away from that selection.+ if !self.show_help && self.report_area != body && self.selection_visible {+ self.follow_selection = true;+ }+ self.body_area = body;Line::from("─".repeat(width)).dim().render(rule, buf);self.render_controls(controls, buf);self.viewport_height = usize::from(body.height).max(/*other*/ 1);@@ -175,36 +181,29 @@ impl AnalyticsView {} else if !self.zoomed {self.dashboard_lines(width, self.viewport_height)} else {- let chart_height =- (usize::from(body.height) / 5).clamp(/*min*/ 4, /*max*/ 10);- let mut panel = self.panel(self.section, width, chart_height);+ let mut height = (self.viewport_height / 3).clamp(/*min*/ 2, /*max*/ 10);+ if body.height < 15 || width < 50 {+ height = 0;+ }+ let mut panel = self.panel(self.section, width, height);if panel.chart_bands > 0 {- let overhead = panel.lines.len() - chart_height * panel.chart_bands;- let height =- usize::from(body.height).saturating_sub(overhead + 1) / panel.chart_bands;- let height = height.max(/*other*/ 2);- if height != chart_height {- panel = self.panel(self.section, width, height);- }+ let overhead = panel.lines.len().saturating_sub(height * panel.chart_bands);+ let available = self.viewport_height.saturating_sub(overhead) / panel.chart_bands;+ height = available.max(/*other*/ 2);+ panel = self.panel(self.section, width, height);}- let center_summary =- self.section == super::sections::Section::Summary && self.profile.ready().is_some();- if center_summary {- let padding = usize::from(body.height).saturating_sub(panel.lines.len()) / 2;+ if self.section == super::sections::Section::Summary && self.profile.ready().is_some() {+ let padding = self.viewport_height.saturating_sub(panel.lines.len()) / 2;panel.lines.splice(0..0, std::iter::repeat_n(Line::default(), padding));}- let selection = if panel.lines.len() <= usize::from(body.height) {- 0..panel.lines.len()- } else {- panel.selection- };- if !center_summary && panel.lines.len() > usize::from(body.height) {- panel.lines.push(Line::default());- }- (panel.lines, selection)+ (panel.lines, panel.selection)};+ if self.zoomed && !self.show_help {+ self.follow_selection |=+ std::mem::take(&mut self.sections[self.section].follow_selection_on_focus);+ }let mut scroll_offset = self.scroll_offset();if self.follow_selection {if selection.start < scroll_offset {@@ -220,6 +219,16 @@ impl AnalyticsView {scroll_offset = scroll_offset.min(lines.len().saturating_sub(self.viewport_height));*self.scroll_offset_mut() = scroll_offset;self.follow_selection = false;+ if !self.show_help {+ self.report_area = body;+ self.selection_visible = (!self.zoomed+ || matches!(+ self.section,+ super::sections::Section::Chats | super::sections::Section::Plan+ ))+ && selection.start < scroll_offset + self.viewport_height+ && selection.start >= scroll_offset;+ }Paragraph::new(lines).scroll(/*offset*/ (scroll_offset.min(usize::from(u16::MAX)) as u16, 0),diff --git a/codex-rs/tui/src/analytics/sections.rs b/codex-rs/tui/src/analytics/sections.rsindex d72476a502..e2d9e202fd 100644--- a/codex-rs/tui/src/analytics/sections.rs+++ b/codex-rs/tui/src/analytics/sections.rs@@ -1,5 +1,5 @@//! Account-specific section order, request eligibility, and independent report ranges.-//! Resolving the account precedes report loading; refreshing drops all account-owned data.+//! Resolving the account precedes report loading; reopening drops all account-owned data.use super::AnalyticsView;use super::chats;@@ -55,6 +55,8 @@ pub(super) struct SectionState {pub(super) cursor: usize,pub(super) detail: Option<usize>,pub(super) group: usize,+ pub(super) scroll_offset: usize,+ pub(super) follow_selection_on_focus: bool,}impl Default for SectionState {@@ -64,6 +66,8 @@ impl Default for SectionState {cursor: 6,detail: None,group: 0,+ scroll_offset: 0,+ follow_selection_on_focus: false,}}}diff --git a/codex-rs/tui/src/analytics/snapshots/codex_tui__analytics__tests__chats_table__chats_breakdown_ranks_nonzero_groups_and_reflows.snap b/codex-rs/tui/src/analytics/snapshots/codex_tui__analytics__tests__chats_table__chats_breakdown_ranks_nonzero_groups_and_reflows.snapindex 7bd27457c3..4f36dbb643 100644--- a/codex-rs/tui/src/analytics/snapshots/codex_tui__analytics__tests__chats_table__chats_breakdown_ranks_nonzero_groups_and_reflows.snap+++ b/codex-rs/tui/src/analytics/snapshots/codex_tui__analytics__tests__chats_table__chats_breakdown_ranks_nonzero_groups_and_reflows.snap@@ -43,26 +43,26 @@ expression: "screens.join(\"\\n\")"" "" Active in past 30 days · sorted by lifetime credits "" "-" Chat Lifetime credits "-" › Q3 planning analysis 19,350.04 "-" ────────────────────────────────────────────────────── "-" Model / effort / speed Credits "-" Top model 19,134.43 "+" Chat Lifetime credits "+" › Q3 planning analysis 19,350.04 "+" ───────────────────────────────────────────────────── "+" Model / effort / speed Credits "+" Top model 19,134.43 "" high · Not reported "-" Small model 215.61 "+" Small model 215.61 "" high · standard "-" Refund model -0.000004 "+" Refund model -0.000004 "" high · standard "" 1 zero-credit group hidden · a show all "" "-" Refactor billing usage 113.00 "-" Other usage 109.00 "-" Launch readiness review 85.00 "-" Plan the week 0.00 "+" Refactor billing usage 113.00 "+" Other usage 109.00 "+" Launch readiness review 85.00 "+" Plan the week 0.00 "" "" Showing 1–5 of 5 chats "-" Local chats · excludes archived chats and subagent usage "-" "+" Local chats · excludes archived chats and subagent "+" usage "" "" "" ↑/↓ row · enter details · esc back "diff --git a/codex-rs/tui/src/analytics/snapshots/codex_tui__analytics__tests__consumer_refresh__consumer_chat_all_metrics.snap b/codex-rs/tui/src/analytics/snapshots/codex_tui__analytics__tests__consumer_refresh__consumer_chat_all_metrics.snapindex 95a5b9c459..8b9652df9d 100644--- a/codex-rs/tui/src/analytics/snapshots/codex_tui__analytics__tests__consumer_refresh__consumer_chat_all_metrics.snap+++ b/codex-rs/tui/src/analytics/snapshots/codex_tui__analytics__tests__consumer_refresh__consumer_chat_all_metrics.snap@@ -11,24 +11,24 @@ expression: "screen(&mut view, 110, 30)"" Recorded usage / current full limit · may exceed 100% "" Partial ranking · 1 partial · 2 unavailable "" "-" Chat Weekly % 5-hour % Balance credits "-" › Refunded task · partial 125.0% 0.0% -0.000004 "-" ──────────────────────────────────────────────────────────────────────────────────────────────────────────── "+" Chat Weekly % 5-hour % Balance credits "+" › Refunded task · partial 125.0% 0.0% -0.000004 "+" ─────────────────────────────────────────────────────────────────────────────────────────────────────────── "" Refunded task "-" Weekly % 125.0% "-" 5-hour % 0.0% "-" Balance credits -0.000004 "+" Weekly % 125.0% "+" 5-hour % 0.0% "+" Balance credits -0.000004 "" "-" Model / effort / speed Weekly % "-" gpt-5.5 — "+" Model / effort / speed Weekly % "+" gpt-5.5 — "" high · fast · codex "" "-" Chat usage unavailable — — — "+" Chat usage unavailable — — — "+" Chat usage unavailable — — — "" "-" Showing 1–2 of 3 chats "+" Showing 1–3 of 3 chats "" Local chats · includes discovered descendants · excludes archived roots "" "" "-" "" ↑/↓ row · enter details · esc back "" tab/1–6 report · z dashboard · ? help · R refresh "diff --git a/codex-rs/tui/src/analytics/snapshots/codex_tui__analytics__tests__recovery__tall_reports_use_available_height_and_wide_reports_put_details_beside_plot.snap b/codex-rs/tui/src/analytics/snapshots/codex_tui__analytics__tests__recovery__tall_reports_use_available_height_and_wide_reports_put_details_beside_plot.snapnew file mode 100644index 0000000000..84e14e9761--- /dev/null+++ b/codex-rs/tui/src/analytics/snapshots/codex_tui__analytics__tests__recovery__tall_reports_use_available_height_and_wide_reports_put_details_beside_plot.snap@@ -0,0 +1,64 @@+---+source: tui/src/analytics/recovery_tests.rs+expression: output+---+" Usage · Business "+" 1 Overview 2 Credits 3 Tokens 4 Plugins 5 Skills "+" ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── "+" r 7d/30d · Aug 27–Sep 2, 2026 · g Model · m All models "+" Updated · Sep 2 16:00 UTC "+" 4.4M tokens ──────────────────────────────────────────── "+" Sep 2 · 731,000 tokens "+" 1M Model Tokens "+" ● GPT-5.5 731,000 "+" "+" "+" "+" "+" 850K "+" ▆▆▆▆▆▆▆▆▆▆▆▆ "+" ████████████ "+" 773.5K ████████████ "+" ▁▁▁▁▁▁▁▁▁▁▁ ████████████ "+" ███████████ ████████████ 731K "+" ███████████ ████████████ "+" ███████████ 688.5K ████████████ ████████████ "+" ███████████ ████████████ ████████████ "+" ███████████ ████████████ ████████████ ████████████ "+" ███████████ ████████████ ████████████ ████████████ "+" 620.5K ███████████ ████████████ ████████████ ████████████ "+" ▆▆▆▆▆▆▆▆▆▆▆▆ ███████████ ████████████ ████████████ ████████████ "+" ████████████ ███████████ ████████████ ████████████ ████████████ "+" ████████████ 544K ███████████ ████████████ ████████████ ████████████ "+" ████████████ ███████████ ████████████ ████████████ ████████████ "+" ████████████ ████████████ ███████████ ████████████ ████████████ ████████████ "+" ████████████ ████████████ ███████████ ████████████ ████████████ ████████████ "+" 500K ████████████ ████████████ ███████████ ████████████ ████████████ ████████████ "+" ████████████ ████████████ ███████████ ████████████ ████████████ ████████████ "+" ████████████ ████████████ ███████████ ████████████ ████████████ ████████████ "+" ████████████ ████████████ ███████████ ████████████ ████████████ ████████████ "+" ████████████ ████████████ ███████████ ████████████ ████████████ ████████████ "+" ████████████ ████████████ ███████████ ████████████ ████████████ ████████████ "+" ████████████ ████████████ ███████████ ████████████ ████████████ ████████████ "+" ████████████ ████████████ ███████████ ████████████ ████████████ ████████████ "+" ████████████ ████████████ ███████████ ████████████ ████████████ ████████████ "+" ████████████ ████████████ ███████████ ████████████ ████████████ ████████████ "+" ████████████ ████████████ ███████████ ████████████ ████████████ ████████████ "+" ████████████ ████████████ ███████████ ████████████ ████████████ ████████████ "+" ████████████ ████████████ ███████████ ████████████ ████████████ ████████████ "+" ████████████ ████████████ ███████████ ████████████ ████████████ ████████████ "+" 170K ████████████ ████████████ ███████████ ████████████ ████████████ ████████████ "+" ▁▁▁▁▁▁▁▁▁▁▁ ████████████ ████████████ ███████████ ████████████ ████████████ ████████████ "+" ███████████ ████████████ ████████████ ███████████ ████████████ ████████████ ████████████ "+" ███████████ ████████████ ████████████ ███████████ ████████████ ████████████ ████████████ "+" ███████████ ████████████ ████████████ ███████████ ████████████ ████████████ ████████████ "+" ███████████ ████████████ ████████████ ███████████ ████████████ ████████████ ████████████ "+" ███████████ ████████████ ████████████ ███████████ ████████████ ████████████ ████████████ "+" ███████████ ████████████ ████████████ ███████████ ████████████ ████████████ ████████████ "+" ███████████ ████████████ ████████████ ███████████ ████████████ ████████████ ████████████ "+" ███████████ ████████████ ████████████ ███████████ ████████████ ████████████ ████████████ "+" 0 ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── "+" ▲ "+" Aug 27 Aug 28 Aug 29 Aug 30 Aug 31 Sep 1 Sep 2 "+" ←/→ day · enter details · esc back "+" tab/1–5 report · z dashboard · ? help · R refresh "diff --git a/codex-rs/tui/src/analytics/snapshots/codex_tui__analytics__tests__redesign__reports_keep_tabs_fixed_and_expose_data_on_small_screens.snap b/codex-rs/tui/src/analytics/snapshots/codex_tui__analytics__tests__redesign__reports_keep_tabs_fixed_and_expose_data_on_small_screens.snapnew file mode 100644index 0000000000..8bf30d5e31--- /dev/null+++ b/codex-rs/tui/src/analytics/snapshots/codex_tui__analytics__tests__redesign__reports_keep_tabs_fixed_and_expose_data_on_small_screens.snap@@ -0,0 +1,37 @@+---+source: tui/src/analytics/redesign_tests.rs+expression: "format!(\"{tokens}\\n{failed}\")"+---+" Usage · Business "+" Overview Credits Tokens › "+" ────────────────────────────────────── "+" r 7d/30d · Aug 27–Sep 2, 2026 "+" g Model · m All models "+" Updated · Sep 2 16:00 UTC "+" 4.4M tokens "+" "+" ────────────────────────────────────── "+" Sep 2 · 731,000 tokens "+" Model Tokens "+" ● GPT-5.5 731,000 "+" "+" "+" ←/→ day · enter details · esc back "+" tab report · z all · ? · R refresh "++" Usage · Business "+" Overview Credits Tokens › "+" ────────────────────────────────────── "+" r 7d/30d · Aug 27–Sep 2, 2026 "+" g Model · m All models "+" "+" Couldn't load tokens. "+" "+" "+" "+" "+" "+" "+" "+" ←/→ day · esc back "+" tab report · z all · ? · R refresh "diff --git a/codex-rs/tui/src/analytics/styles.rs b/codex-rs/tui/src/analytics/styles.rsindex b37737fc5c..29fb2edd2b 100644--- a/codex-rs/tui/src/analytics/styles.rs+++ b/codex-rs/tui/src/analytics/styles.rs@@ -35,3 +35,14 @@ pub(super) fn secondary_style() -> Style {_ => Style::default().dim(),}}++/// Paint one selectable row, including its padding, using the shared picker accent.+pub(super) fn select_row(line: &mut ratatui::text::Line<'static>, width: usize) {+ let style = crate::bottom_pane::selection_style();+ line.spans+ .push(" ".repeat(width.saturating_sub(line.width())).into());+ line.style = style;+ for span in &mut line.spans {+ span.style = style;+ }+}diff --git a/codex-rs/tui/src/analytics/styles_tests.rs b/codex-rs/tui/src/analytics/styles_tests.rsindex 6cd7c07479..0c8ef24c7a 100644--- a/codex-rs/tui/src/analytics/styles_tests.rs+++ b/codex-rs/tui/src/analytics/styles_tests.rs@@ -126,3 +126,60 @@ fn analytics_sections_adapt_to_terminal_colors() {});}}++#[test]+fn chat_selection_keeps_a_highlighted_trailing_blank_after_wrapping() {+ with_test_default_colors(+ DefaultColors {+ fg: (30, 30, 30),+ bg: (255, 255, 255),+ },+ || {+ for kind in [models::AccountKind::Business, models::AccountKind::Consumer] {+ let mut view = fixture::view(kind);+ view.section = Section::Chats;+ view.tasks = Load::Ready(tasks::Chats {+ rows: vec![tasks::Chat {+ title: "Building Analytics".into(),+ task: Some(+ serde_json::from_value(serde_json::json!({+ "thread_id": "padding-fixture",+ "data_status": "available",+ "usage_source": "credits",+ "weekly_limit_percent": 42.0,+ "five_hour_limit_percent": 15.0,+ "balance_usage_credits": "35.83",+ "groups": []+ }))+ .unwrap(),+ ),+ }],+ ..tasks::Chats::default()+ });+ for width in [40, 120] {+ let area = Rect::new(/*x*/ 0, /*y*/ 0, width, /*height*/ 30);+ let mut buffer = Buffer::empty(area);+ view.render(area, &mut buffer);+ let selection = crate::bottom_pane::selection_style().bg.unwrap();+ let selected_rows = buffer+ .content+ .chunks(usize::from(width))+ .skip(usize::from(view.body_area.y))+ .take(usize::from(view.body_area.height))+ .filter(|row| row.iter().any(|cell| cell.bg == selection))+ .collect::<Vec<_>>();+ assert!(!selected_rows.is_empty());+ for row in selected_rows {+ let end = row.iter().rposition(|cell| cell.bg == selection).unwrap();+ assert_eq!(row[end].symbol(), " ");+ assert!(+ row[..end]+ .iter()+ .any(|cell| !cell.symbol().trim().is_empty())+ );+ }+ }+ }+ },+ );+}diff --git a/codex-rs/tui/src/analytics/summary_tests.rs b/codex-rs/tui/src/analytics/summary_tests.rsindex 363f2a7212..57d124257c 100644--- a/codex-rs/tui/src/analytics/summary_tests.rs+++ b/codex-rs/tui/src/analytics/summary_tests.rs@@ -44,10 +44,9 @@ fn summary_modes_reflow_and_keep_selection_across_tabs() {screen(&mut view, /*width*/ 64, /*height*/ 18);press(&mut view, KeyCode::End);screen(&mut view, /*width*/ 64, /*height*/ 18);- assert!(view.scroll_offset > 0);+ assert!(view.scroll_offset() > 0);press(&mut view, KeyCode::Home);- assert_eq!(view.scroll_offset, 0);- press(&mut view, KeyCode::Char('z'));+ assert_eq!(view.scroll_offset(), 0);press(&mut view, KeyCode::Esc);assert!(view.is_done);}@@ -68,7 +67,7 @@ fn partial_summary_keeps_missing_values_and_zero() {}#[tokio::test]-async fn summary_loads_once_per_refresh_and_does_not_block_other_reports() {+async fn summary_loads_once_per_open_and_does_not_block_other_reports() {use wiremock::Mock;use wiremock::ResponseTemplate;use wiremock::matchers::header;@@ -98,10 +97,14 @@ async fn summary_loads_once_per_refresh_and_does_not_block_other_reports() {assert!(view.sections[Section::Usage].history.ready().is_some());press(&mut view, KeyCode::Char('g'));press(&mut view, KeyCode::Tab);+ test_support::settle(&mut view).await;+ assert!(view.sections[Section::Usage].history.ready().is_some());press(&mut view, KeyCode::BackTab);test_support::settle(&mut view).await;assert_eq!(requests.load(std::sync::atomic::Ordering::SeqCst), 1);- press(&mut view, KeyCode::Char('R'));+ let (config, handle, frame) = view.connection.as_ref().unwrap().clone();+ view.cancel_loads();+ view.open(handle, frame, Vec::new(), config);test_support::settle(&mut view).await;assert_eq!(view.profile.ready().unwrap().stats.tokens.lifetime_tokens,diff --git a/codex-rs/tui/src/analytics/task_panel.rs b/codex-rs/tui/src/analytics/task_panel.rsindex 6f9c182610..98450ce2fb 100644--- a/codex-rs/tui/src/analytics/task_panel.rs+++ b/codex-rs/tui/src/analytics/task_panel.rs@@ -106,7 +106,8 @@ impl AnalyticsView {}pub(super) fn task_lines(&self, width: usize) -> (Vec<Line<'static>>, Range<usize>) {- let width = width.clamp(/*min*/ 1, /*max*/ 110);+ let row_width = width.clamp(/*min*/ 1, /*max*/ 111);+ let width = row_width.saturating_sub(/*rhs*/ 1).max(/*other*/ 1);let wrap = |lines| word_wrap_lines(lines, RtOptions::new(width));let Some(chats) = self.tasks.ready() else {return (@@ -239,6 +240,7 @@ impl AnalyticsView {},width,)];+ let header_len = row.len();if self.zoomed && self.sections[Section::Chats].detail == Some(index) {row.push("─".repeat(width).dim().into());row.extend(word_wrap_lines(@@ -305,7 +307,16 @@ impl AnalyticsView {}row.push(Line::default());}- wrap(row)+ let details = row.split_off(header_len);+ let mut row = wrap(row);+ // Wrap first: wrapping trims the highlighted trailing blank otherwise.+ if selected {+ for line in &mut row {+ super::styles::select_row(line, row_width);+ }+ }+ row.extend(wrap(details));+ row}).collect::<Vec<_>>();let mut coverage = vec![diff --git a/codex-rs/tui/src/analytics/tool_panel_tests.rs b/codex-rs/tui/src/analytics/tool_panel_tests.rsindex 7a32b8718a..797b82a797 100644--- a/codex-rs/tui/src/analytics/tool_panel_tests.rs+++ b/codex-rs/tui/src/analytics/tool_panel_tests.rs@@ -33,8 +33,6 @@ fn analytics_tools_reflow_and_keep_independent_days() {(29, 28, [0, 0, 1]));press(&mut view, KeyCode::Char('r'));- press(&mut view, KeyCode::Char('z'));- press(&mut view, KeyCode::Char('z'));assert_eq!((view.sections[Section::Plugins].cursor,diff --git a/codex-rs/tui/src/analytics_tests.rs b/codex-rs/tui/src/analytics_tests.rsindex d0bf65e44f..b3d2ae879c 100644--- a/codex-rs/tui/src/analytics_tests.rs+++ b/codex-rs/tui/src/analytics_tests.rs@@ -64,7 +64,6 @@ fn analytics_exact_fit_content_has_no_scroll_hint() {#[test]fn analytics_narrow_charts_and_small_terminals_keep_valid_cursors() {let mut view = fixture::view(models::AccountKind::Consumer);- press(&mut view, KeyCode::Char('z'));for section in ['2', '3', '4'] {press(&mut view, KeyCode::Char(section));press(&mut view, KeyCode::Char('r'));@@ -77,7 +76,6 @@ fn analytics_narrow_charts_and_small_terminals_keep_valid_cursors() {assert_eq!(view.sections[view.section].cursor, 29);}for _ in 0..2 {- press(&mut view, KeyCode::Char('z'));for width in [1, 4, 32, 107, 108] {screen(&mut view, width, /*height*/ 1);}@@ -92,6 +90,7 @@ async fn analytics_credits_grouping_preserves_selected_day_and_total() {let (_home, _app_server, mut view) = client::tests::connected_view(&server, "business").await;test_support::settle(&mut view).await;press(&mut view, KeyCode::Char('2'));+ test_support::settle(&mut view).await;press(&mut view, KeyCode::Left);let before = view.sections[Section::Credits].history@@ -171,7 +170,6 @@ fn analytics_preserves_full_denominators_and_signed_small_credits() {use crate::analytics::models::AccountAnalyticsDay;use crate::analytics::models::AccountAnalyticsValue;let mut view = fixture::view(models::AccountKind::Consumer);- press(&mut view, KeyCode::Char('z'));let mut history = fixture::history(/*report*/ 0, /*range*/ 0, /*group*/ 3);history.data = vec![AccountAnalyticsDay {date: "2026-09-02".parse().unwrap(),@@ -326,7 +324,6 @@ fn analytics_dates_distinguish_zero_missing_and_exact_details() {#[test]fn analytics_model_labels_and_tool_remainders_are_unambiguous() {let mut view = fixture::view(models::AccountKind::Consumer);- press(&mut view, KeyCode::Char('z'));view.model_names.insert("GPT-5.6-Sol".into(), "Friendly model".into());let mut tools = fixture::history(/*report*/ 4, /*range*/ 0, /*group*/ 0);@@ -620,11 +617,8 @@ mod chats_table;fn analytics_details_reflow_and_keep_focus() {let mut view = fixture::view(models::AccountKind::Enterprise);view.chats = Load::Ready(fixture::chats());- press(&mut view, KeyCode::Char('z'));press(&mut view, KeyCode::Char('6'));press(&mut view, KeyCode::Enter);- assert!(view.zoomed);- press(&mut view, KeyCode::Enter);screen(&mut view, /*width*/ 120, /*height*/ 42);view.follow_selection = true;let narrow = screen(&mut view, /*width*/ 58, /*height*/ 20);diff --git a/codex-rs/tui/src/snapshots/codex_tui__analytics__tests__analytics_maximized_refunds_leave_room_for_both_bands.snap b/codex-rs/tui/src/snapshots/codex_tui__analytics__tests__analytics_maximized_refunds_leave_room_for_both_bands.snapindex 38a7178978..0dc2b42256 100644--- a/codex-rs/tui/src/snapshots/codex_tui__analytics__tests__analytics_maximized_refunds_leave_room_for_both_bands.snap+++ b/codex-rs/tui/src/snapshots/codex_tui__analytics__tests__analytics_maximized_refunds_leave_room_for_both_bands.snap@@ -10,14 +10,16 @@ expression: output" "" 367.00 credits "" "-" 150 85.00 109.00 "-" 41.00 57.00 ▂▂▂▂▂▂▂▂ 75.00 ▇▇▇▇▇▇▇▇ "-" 75 ▄▄▄▄▄▄▄▄ ████████ ████████ ████████ "+" 150 109.00 "+" 85.00 75.00 ▅▅▅▅▅▅▅▅ "+" 75 41.00 57.00 ▆▆▆▆▆▆▆▆ ▄▄▄▄▄▄▄▄ ████████ "+" ▂▂▂▂▂▂▂▂ ▇▇▇▇▇▇▇▇ ████████ ████████ ████████ "" 0 ████████ ████████ ████████ ████████ ████████ "" 0 ──────────────────────────────────────────────────────────────────────────────────────────── "" ▇▇▇▇▇▇▇▇▇ "" -0.000004 "" "+" "" -150 "" "" ▲ "@@ -30,7 +32,5 @@ expression: output" ● Desktop app 0.00 "" ● IDE extension 0.00 "" ● Web 0.00 "-" "-" "" ←/→ day · enter details · esc back "" tab/1–6 report · z dashboard · ? help · R refresh "diff --git a/codex-rs/tui/src/snapshots/codex_tui__analytics__tests__analytics_preserves_full_denominators_and_signed_small_credits.snap b/codex-rs/tui/src/snapshots/codex_tui__analytics__tests__analytics_preserves_full_denominators_and_signed_small_credits.snapindex 380d495ef9..ba9e509882 100644--- a/codex-rs/tui/src/snapshots/codex_tui__analytics__tests__analytics_preserves_full_denominators_and_signed_small_credits.snap+++ b/codex-rs/tui/src/snapshots/codex_tui__analytics__tests__analytics_preserves_full_denominators_and_signed_small_credits.snap@@ -3,6 +3,7 @@ source: tui/src/analytics_tests.rsexpression: "task.into_iter().chain(credits).map(|line|\nline.to_string()).collect::<Vec<_>>().join(\"\\n\")"---Total usage · relative units+Approximate · may be delayed up to 6 hoursAll usage by how each turn started100 100@@ -11,7 +12,9 @@ All usage by how each turn started▲Aug 27 Aug 28 Aug 29 Aug 30 Aug 31 Sep 1 Sep 2+──────────────────────────────────────────────────────Sep 2 · 100 usage units+Turn start Share● Goals 30.0%-0.000004 credits@@ -24,5 +27,7 @@ Sep 2 · 100 usage units▲27 28 29 30 31 1 2+──────────────────────────────────────────────────────Sep 2 · -0.000004 credits+Product Credits● CLI -0.000004