diff --git a/codex-rs/tui/src/app.rs b/codex-rs/tui/src/app.rs index cced763ac2..f5de4c512f 100644 --- a/codex-rs/tui/src/app.rs +++ b/codex-rs/tui/src/app.rs @@ -297,6 +297,7 @@ mod sidebar_model_documents; #[path = "app/sidebar_open_in_codex_tests.rs"] mod sidebar_open_in_codex_tests; mod sidebar_subagents; +mod sidebar_visibility; mod startup; pub(crate) mod startup_bootstrap; mod startup_prompts; diff --git a/codex-rs/tui/src/app/agent_center_tests.rs b/codex-rs/tui/src/app/agent_center_tests.rs index 445eee24c9..76779b33b1 100644 --- a/codex-rs/tui/src/app/agent_center_tests.rs +++ b/codex-rs/tui/src/app/agent_center_tests.rs @@ -1488,7 +1488,17 @@ async fn workspace_navigation_preserves_the_draft_and_reading_position() -> Resu .await?; tui.screen_size_for_event(&TuiEvent::Resize(wide))?; app.render_chat_widget_frame(&mut tui, wide)?; - assert_eq!(buffer_text(tui.terminal.previous_buffer()), before); + let returned = buffer_text(tui.terminal.previous_buffer()); + let (header, body) = returned.split_once('\n').expect("restore header"); + assert_eq!(header.trim(), "‹"); + // The restore header replaces the last visible transcript row, without moving its start. + let mut original = before.lines().collect::>(); + let transcript_rows = original + .iter() + .take_while(|row| row.starts_with("Response row ")) + .count(); + original.remove(transcript_rows - 1); + assert_eq!(body, original.join("\n")); app.local_settings.tui.keymap = serde_json::from_value(serde_json::json!({ "global":{"leader":"f12","open_agents":"leader a","focus_main_composer":["leader c", "f10"]}, diff --git a/codex-rs/tui/src/app/owned_transcript.rs b/codex-rs/tui/src/app/owned_transcript.rs index 977705fa36..8f52e17aab 100644 --- a/codex-rs/tui/src/app/owned_transcript.rs +++ b/codex-rs/tui/src/app/owned_transcript.rs @@ -44,6 +44,7 @@ pub(super) struct ConversationFrame { pub(super) command_center: Option, pub(super) sidebar: Option, pub(super) chat_strip: Option, + pub(super) restore_header: Option, pub(super) sidebar_input: Option, pub(super) sidebar_targets: Vec<(SidebarTarget, Rect)>, pub(super) close_buttons: [Rect; 2], @@ -58,6 +59,7 @@ impl ConversationFrame { && self.command_center.is_none() && self.sidebar.is_none() && self.chat_strip.is_none() + && self.restore_header.is_none() } pub(super) fn side_pane(&self) -> Option<&side_pane::SidePaneLayout> { @@ -261,6 +263,7 @@ impl App { if self.conversation_frame.command_center.is_some() || self.conversation_frame.sidebar.is_some() || self.conversation_frame.chat_strip.is_some() + || self.conversation_frame.restore_header.is_some() { // Recompute our own inset on every frame, including the first narrow frame. self.conversation_frame = ConversationFrame::default(); @@ -313,13 +316,32 @@ impl App { } None => (None, None), }; + let restore_header = (layout.is_none() + && strip.is_none() + && caller_inset.is_none() + && content.width >= 4 + && content.height >= 2 + && self.conversation_focus_available(tui) + && !self.reconnect.offline + && self.chat_widget.sidebar_chooser_available() + && self.sidebar().is_some_and(|pane| { + pane.hidden_content().is_some() + || (self.zoomed_thread.is_none() + && content.width < side_pane::MIN_SPLIT_WIDTH + && pane.visible_content().is_some()) + })) + .then(|| side_pane::tab_and_body(content)); let mut prepared = self.prepare_conversation( viewport, - caller_inset.or(live).or(center.map(|_| content)), + caller_inset + .or(live) + .or(restore_header.map(|areas| areas[1])) + .or(center.map(|_| content)), &frames, ); self.conversation_frame.sidebar = layout; self.conversation_frame.chat_strip = strip; + self.conversation_frame.restore_header = restore_header.map(|areas| areas[0]); self.conversation_frame.sidebar_input = self.sidebar().map(sidebar::SidebarPane::input_state); let divider = self.conversation_frame.divider_area(); @@ -667,6 +689,17 @@ impl App { .map(|(target, area)| (SidebarTarget::Tab(target), area)), ); } + if let Some([header, _]) = restore_header { + ratatui::widgets::Clear.render(header, frame.buffer); + let area = Rect::new(header.right() - 4, header.y, 3, 1); + crate::sidebar_tab_strip::paint_toggle( + "‹", + area, + pointer.is_some_and(|point| area.contains(point)), + frame.buffer, + ); + sidebar_targets.push((SidebarTarget::Restore, area)); + } if let Some(point) = pointer { for &(target, area) in &sidebar_targets { if matches!(target, SidebarTarget::Footer(_)) && area.contains(point) { @@ -740,6 +773,7 @@ impl App { self.conversation_frame.inset = conversation_inset; self.conversation_frame.sidebar = None; self.conversation_frame.chat_strip = None; + self.conversation_frame.restore_header = None; let area = self.conversation_area(viewport); if let Some((previous, reflowed)) = self.chat_widget.resize_owned_conversation(area.width) { self.transcript_view diff --git a/codex-rs/tui/src/app/side_focus.rs b/codex-rs/tui/src/app/side_focus.rs index da601d5116..a7a8015262 100644 --- a/codex-rs/tui/src/app/side_focus.rs +++ b/codex-rs/tui/src/app/side_focus.rs @@ -378,33 +378,31 @@ impl App { self.zoomed_thread = (self.zoomed_thread != Some(target)).then_some(target); tui.frame_requester().schedule_frame(); self.refresh_owned_transcript(tui) + } else if panel_focus.is_some() + && (hide || (sidebar && panel_focus == Some(PaneFocus::Sidebar))) + { + self.hide_sidebar(tui, app_server).await } else if panel_focus.is_some() { - if hide || (sidebar && panel_focus == Some(PaneFocus::Sidebar)) { - self.zoomed_thread = None; + if main { self.focus_current_parent_view(tui); - self.sidebar_mut().hide(); + } + let focus = if main || left { + PaneFocus::Main } else { - if main { - self.focus_current_parent_view(tui); - } - let focus = if main || left { - PaneFocus::Main - } else { - PaneFocus::Sidebar - }; - if focus == PaneFocus::Main - && matches!( - self.sidebar() - .and_then(sidebar::SidebarPane::visible_content), - Some(SidebarContent::Document(_)) - ) - { - self.zoomed_thread = None; - } - let pane = self.sidebar_mut(); - if let Some(content) = pane.visible_content() { - pane.show(content, focus); - } + PaneFocus::Sidebar + }; + if focus == PaneFocus::Main + && matches!( + self.sidebar() + .and_then(sidebar::SidebarPane::visible_content), + Some(SidebarContent::Document(_)) + ) + { + self.zoomed_thread = None; + } + let pane = self.sidebar_mut(); + if let Some(content) = pane.visible_content() { + pane.show(content, focus); } tui.frame_requester().schedule_frame(); Ok(()) @@ -428,8 +426,8 @@ impl App { } else if sidebar && child.is_none() { self.focus_current_parent_view(tui); self.open_sidebar_tabs(tui, app_server).await - } else if hide || sidebar { - self.hide_focused_side_pane(tui, app_server).await + } else if (hide || sidebar) && on_child { + self.hide_sidebar(tui, app_server).await } else { // A direction with no reachable neighbor leaves the current interaction intact. Ok(()) @@ -474,7 +472,7 @@ impl App { Ok(()) } - fn focus_current_parent_view(&mut self, tui: &mut tui::Tui) { + pub(super) fn focus_current_parent_view(&mut self, tui: &mut tui::Tui) { if let Some(pane) = self.sidebars.get_mut(&self.sidebar_parent()) { pane.agents.pending_link = None; } diff --git a/codex-rs/tui/src/app/sidebar.rs b/codex-rs/tui/src/app/sidebar.rs index 81e25cddba..92c55aa3a3 100644 --- a/codex-rs/tui/src/app/sidebar.rs +++ b/codex-rs/tui/src/app/sidebar.rs @@ -82,6 +82,7 @@ pub(super) struct SidebarInputState { pub(super) choice: ChooserSelection, scroll: ChooserScroll, content: SidebarContent, + focus: Option, showing_file_path: bool, file_path_scroll: usize, } @@ -117,6 +118,7 @@ pub(super) struct SidebarPane { pub(super) file_preview_unavailable: Option<&'static str>, pub(super) tabs_revision: usize, focus: Option, + hidden: bool, motion: PaneMotion, } @@ -160,6 +162,8 @@ impl SidebarPane { } pub(super) fn show(&mut self, content: SidebarContent, focus: PaneFocus) { + let resume_chooser = self.hidden && self.content == SidebarContent::Chooser; + self.hidden = false; if self.content != content { self.cancel_hidden_document_primary(/*visible*/ false); } @@ -174,7 +178,9 @@ impl SidebarPane { self.visit(SidebarTab::Chat(id)); } SidebarContent::Chooser - if self.focus.is_none() || matches!(self.content, SidebarContent::Chat(_)) => + if !resume_chooser + && (self.focus.is_none() + || matches!(self.content, SidebarContent::Chat(_))) => { self.reset_choice(); } @@ -465,6 +471,7 @@ impl SidebarPane { choice, scroll: self.chooser_scroll, content: self.content, + focus: self.focus, showing_file_path: self.showing_file_path, file_path_scroll: self.file_path_scroll, } @@ -497,6 +504,7 @@ impl SidebarPane { } pub(super) fn hide(&mut self) { + self.hidden |= self.focus.is_some(); self.cancel_hidden_document_primary(/*visible*/ false); self.focus_document_request = None; self.agents.pending_link = None; @@ -558,6 +566,10 @@ impl SidebarPane { } } + pub(super) fn hidden_content(&self) -> Option { + (self.hidden && self.focus.is_none()).then_some(self.content) + } + pub(super) fn visible_content(&self) -> Option { self.focus.map(|_| self.content) } diff --git a/codex-rs/tui/src/app/sidebar_document_tests.rs b/codex-rs/tui/src/app/sidebar_document_tests.rs index a66c9df418..8f7536dc05 100644 --- a/codex-rs/tui/src/app/sidebar_document_tests.rs +++ b/codex-rs/tui/src/app/sidebar_document_tests.rs @@ -220,7 +220,7 @@ async fn document_preview_scenario() -> Result<()> { .collect::>() .join("\n"); insta::assert_snapshot!(visible, @" - guide.md × + + guide.md × + › # Guide First section. "); @@ -539,7 +539,7 @@ async fn document_preview_scenario() -> Result<()> { .collect::>() .join("\n"); insta::assert_snapshot!(preview, @" - guide.md × main.rs × + + guide.md × main.rs × + › 3 let value = 3; ↑ esc clear highlight · c copy path · p show path · ↑/↓ read f3 find · Tab link · f8 select @@ -726,7 +726,7 @@ size 123 .sidebar_tab_strip() .expect("tab strip"); let narrow_labels = visible_sidebar_row(&tui, strip, strip.y); - insta::assert_snapshot!(narrow_labels, @"‹ f…eA/g…d × f…eB/g…d × +"); + insta::assert_snapshot!(narrow_labels, @"‹ fe…eB/g…md × + ›"); let long_file = "Before the fold.\n\n".repeat(24); for directory in ["feature-alpha-build", "feature-beta-build"] { std::fs::create_dir_all(dir.path().join(directory))?; @@ -753,7 +753,7 @@ size 123 .sidebar_tab_strip() .expect("tab strip"); let narrow_labels = visible_sidebar_row(&tui, strip, strip.y); - insta::assert_snapshot!(narrow_labels, @"‹ 1:f…d/…d × 2:f…d/…d × +"); + insta::assert_snapshot!(narrow_labels, @"‹ 2:f…ld/g…d × + ›"); // If resolution itself fails, there is no new tab in which to show the path. let tab_count = app.sidebar().unwrap().documents.len(); app.open_document( @@ -822,6 +822,45 @@ size 123 .collect::>() .join("\n"); insta::assert_snapshot!("refreshed_sidebar_at_reading_position", visible); + let document = app.sidebar().unwrap().visible_content(); + for target in [ + sidebar_input::SidebarTarget::Tab(crate::sidebar_tab_strip::TabTarget::Hide), + sidebar_input::SidebarTarget::Restore, + ] { + let area = app + .conversation_frame + .sidebar_targets + .iter() + .find_map(|(candidate, area)| (*candidate == target).then_some(*area)) + .expect("painted sidebar control"); + for kind in [ + MouseEventKind::Down(MouseButton::Left), + MouseEventKind::Up(MouseButton::Left), + ] { + let event = MouseEvent { + kind, + column: area.x + 1, + row: area.y, + modifiers: KeyModifiers::NONE, + }; + Box::pin(app.handle_tui_event(&mut tui, &mut server, TuiEvent::Mouse(event))).await?; + } + side_frame(&mut app, &mut tui, size)?; + if target == sidebar_input::SidebarTarget::Tab(crate::sidebar_tab_strip::TabTarget::Hide) { + app.chat_widget.apply_external_edit("/m".into()); + side_frame(&mut app, &mut tui, size)?; + assert!(!app.chat_widget.no_modal_or_popup_active()); + assert!( + !app.conversation_frame + .sidebar_targets + .iter() + .any(|(target, _)| *target == sidebar_input::SidebarTarget::Restore) + ); + app.chat_widget.apply_external_edit(String::new()); + side_frame(&mut app, &mut tui, size)?; + } + } + assert!(app.sidebar().unwrap().visible_content() == document); server.shutdown().await?; Ok(()) } diff --git a/codex-rs/tui/src/app/sidebar_input.rs b/codex-rs/tui/src/app/sidebar_input.rs index 56915e2b8c..2720fc93c0 100644 --- a/codex-rs/tui/src/app/sidebar_input.rs +++ b/codex-rs/tui/src/app/sidebar_input.rs @@ -17,6 +17,7 @@ pub(super) enum SidebarTarget { Tab(TabTarget), Row(usize), Footer(ChooserAction), + Restore, } #[derive(Clone, Copy, PartialEq, Eq)] @@ -41,6 +42,8 @@ enum SidebarAction { ActivateTab(SidebarTab), CloseTab(SidebarTab), OpenChooser, + Hide, + Restore, } impl App { @@ -71,6 +74,8 @@ impl App { self.close_sidebar_tab(tui, server, id).await } SidebarAction::OpenChooser => self.open_sidebar_tabs(tui, server).await, + SidebarAction::Hide => self.hide_sidebar(tui, server).await, + SidebarAction::Restore => self.restore_sidebar(tui, server).await, }; if let Err(err) = result { self.chat_widget.add_error_message(err.to_string()); @@ -114,6 +119,9 @@ impl App { let over_strip = frame .sidebar_tab_strip() .is_some_and(|area| area.contains(point)); + let over_restore = frame + .restore_header + .is_some_and(|area| area.contains(point)); let over_chooser = self.chooser_focus().is_some() && frame.panel_area().is_some_and(|area| area.contains(point)); if tui.shortcut_hud_contains(mouse) { @@ -146,7 +154,7 @@ impl App { { let down = matches!(mouse.kind, MouseEventKind::Down(_)); let pressed = self.sidebar_press.take(); - if over_strip || over_chooser || pressed.is_some() { + if over_strip || over_chooser || over_restore || pressed.is_some() { let current = self.sidebar().map(sidebar::SidebarPane::input_state); let hit = frame .sidebar_targets @@ -197,10 +205,14 @@ impl App { MouseButton::Left, TabTarget::Tab(id) | TabTarget::Overflow { tab: id, .. }, ) => SidebarAction::ActivateTab(id), + (MouseButton::Left, TabTarget::Hide) => SidebarAction::Hide, _ => return PointerResult::Consumed, }; return PointerResult::Action(action); } + SidebarTarget::Restore if button == MouseButton::Left => { + return PointerResult::Action(SidebarAction::Restore); + } SidebarTarget::Row(index) if button == MouseButton::Left => { return PointerResult::Chooser(ChooserAction::Open(index)); } diff --git a/codex-rs/tui/src/app/sidebar_visibility.rs b/codex-rs/tui/src/app/sidebar_visibility.rs new file mode 100644 index 0000000000..79fd592dac --- /dev/null +++ b/codex-rs/tui/src/app/sidebar_visibility.rs @@ -0,0 +1,93 @@ +//! Hide and restore the sidebar using the same focus and tab transitions as keyboard navigation. + +use super::sidebar::PaneFocus; +use super::sidebar::SidebarContent; +use super::sidebar::{self}; +use super::*; +use crate::sidebar_tab_strip::SidebarTab; + +impl App { + /// Hide the sidebar while returning input to its parent conversation. + pub(super) async fn hide_sidebar( + &mut self, + tui: &mut tui::Tui, + app_server: &mut AppServerSession, + ) -> Result<()> { + if self.panel_focus().is_none() && self.sidebar_has_focus() { + let previous = self.current_displayed_thread_id(); + let result = self.hide_focused_side_pane(tui, app_server).await; + if self.current_displayed_thread_id() != previous { + self.zoomed_thread = None; + } + return result; + } + if self + .sidebar() + .and_then(sidebar::SidebarPane::visible_content) + .is_some() + { + self.zoomed_thread = None; + if self.panel_focus() == Some(PaneFocus::Sidebar) { + self.focus_current_parent_view(tui); + } + self.sidebar_mut().hide(); + tui.frame_requester().schedule_frame(); + } + Ok(()) + } + + pub(super) async fn restore_sidebar( + &mut self, + tui: &mut tui::Tui, + server: &mut AppServerSession, + ) -> Result<()> { + let content = self + .sidebar() + .and_then(|pane| pane.hidden_content().or_else(|| pane.visible_content())); + let tab = match content { + Some(SidebarContent::Chat(id)) => Some(SidebarTab::Chat(id)), + Some(SidebarContent::Document(id)) => Some(SidebarTab::Document(id)), + Some(SidebarContent::Subagents) => Some(SidebarTab::Subagents), + Some(SidebarContent::Chooser) | None => None, + }; + if let Some(tab) = tab.filter(|tab| { + self.sidebar() + .is_some_and(|pane| pane.chat_tabs().ids.contains(tab)) + }) { + if tab == SidebarTab::Subagents + && self + .sidebar() + .is_some_and(|pane| pane.agents.detail.is_none()) + { + self.sidebar_mut() + .show(SidebarContent::Subagents, PaneFocus::Sidebar); + tui.frame_requester().schedule_frame(); + return Ok(()); + } + let hidden = self + .sidebar() + .is_some_and(|pane| pane.hidden_content().is_some()); + let agent = (tab == SidebarTab::Subagents) + .then(|| self.sidebar().and_then(|pane| pane.agents.detail)) + .flatten(); + let result = self.activate_sidebar_tab(tui, server, tab).await; + if let Some(agent) = agent + && self.current_displayed_thread_id() != Some(agent) + { + let pane = self.sidebar_mut(); + pane.show(SidebarContent::Subagents, PaneFocus::Main); + if hidden { + pane.hide(); + } + return result; + } + result?; + if self.sidebar_has_focus() { + self.zoomed_thread = None; + tui.frame_requester().schedule_frame(); + } + return Ok(()); + } + self.open_sidebar_tabs(tui, server).await + } +} diff --git a/codex-rs/tui/src/app/snapshots/codex_tui__app__sidebar_document__tests__refreshed_sidebar_at_reading_position.snap b/codex-rs/tui/src/app/snapshots/codex_tui__app__sidebar_document__tests__refreshed_sidebar_at_reading_position.snap index c7f6fd9ee8..62b35ec897 100644 --- a/codex-rs/tui/src/app/snapshots/codex_tui__app__sidebar_document__tests__refreshed_sidebar_at_reading_position.snap +++ b/codex-rs/tui/src/app/snapshots/codex_tui__app__sidebar_document__tests__refreshed_sidebar_at_reading_position.snap @@ -2,7 +2,7 @@ source: tui/src/app/sidebar_document_tests.rs expression: visible --- -‹ 1:f…ld/g…d × 2:f…ld/g…d × + +‹ 1:f…ld/g…d × 2:f…ld/g…d × + › ↑ Before the fold. diff --git a/codex-rs/tui/src/app/snapshots/codex_tui__app__sidebar_open_in_codex_tests__open_in_codex_confirmation.snap b/codex-rs/tui/src/app/snapshots/codex_tui__app__sidebar_open_in_codex_tests__open_in_codex_confirmation.snap index 29b016eef6..7e66912d85 100644 --- a/codex-rs/tui/src/app/snapshots/codex_tui__app__sidebar_open_in_codex_tests__open_in_codex_confirmation.snap +++ b/codex-rs/tui/src/app/snapshots/codex_tui__app__sidebar_open_in_codex_tests__open_in_codex_confirmation.snap @@ -1,8 +1,7 @@ --- source: tui/src/app/sidebar_open_in_codex_tests.rs -assertion_line: 341 expression: sidebar.trim_end() --- - Side chat × PLAN.md × Agent transcript × note.md × + + Side chat × PLAN.md × Agent transcript × note.md × + › Open /note.md? ⌃x s focus sidebar diff --git a/codex-rs/tui/src/app/snapshots/codex_tui__app__sidebar_open_in_codex_tests__open_in_codex_sidebar.snap b/codex-rs/tui/src/app/snapshots/codex_tui__app__sidebar_open_in_codex_tests__open_in_codex_sidebar.snap index 0e53c8036f..794db41e22 100644 --- a/codex-rs/tui/src/app/snapshots/codex_tui__app__sidebar_open_in_codex_tests__open_in_codex_sidebar.snap +++ b/codex-rs/tui/src/app/snapshots/codex_tui__app__sidebar_open_in_codex_tests__open_in_codex_sidebar.snap @@ -2,7 +2,7 @@ source: tui/src/app/sidebar_open_in_codex_tests.rs expression: sidebar.trim_end() --- - PLAN.md × + + PLAN.md × + › Snapshot Use the sidebar. ↑ diff --git a/codex-rs/tui/src/app/snapshots/codex_tui__app__sidebar_subagents__status__tests__subagent_chooser.snap b/codex-rs/tui/src/app/snapshots/codex_tui__app__sidebar_subagents__status__tests__subagent_chooser.snap index a2b0d2f8d2..ce76f6f2da 100644 --- a/codex-rs/tui/src/app/snapshots/codex_tui__app__sidebar_subagents__status__tests__subagent_chooser.snap +++ b/codex-rs/tui/src/app/snapshots/codex_tui__app__sidebar_subagents__status__tests__subagent_chooser.snap @@ -2,7 +2,7 @@ source: tui/src/app/sidebar_agent_status_tests.rs expression: rows --- - + + + › Open in sidebar › + New side chat Available after first message Subagents 2 diff --git a/codex-rs/tui/src/app/snapshots/codex_tui__app__sidebar_subagents__status__tests__subagent_chooser_narrow.snap b/codex-rs/tui/src/app/snapshots/codex_tui__app__sidebar_subagents__status__tests__subagent_chooser_narrow.snap index a619f6f399..bc903f8e78 100644 --- a/codex-rs/tui/src/app/snapshots/codex_tui__app__sidebar_subagents__status__tests__subagent_chooser_narrow.snap +++ b/codex-rs/tui/src/app/snapshots/codex_tui__app__sidebar_subagents__status__tests__subagent_chooser_narrow.snap @@ -2,7 +2,7 @@ source: tui/src/app/sidebar_agent_status_tests.rs expression: rows --- - + + + › Open in sidebar › + New side chat Available after first message diff --git a/codex-rs/tui/src/app/snapshots/codex_tui__app__sidebar_subagents__status__tests__watch_only_subagent.snap b/codex-rs/tui/src/app/snapshots/codex_tui__app__sidebar_subagents__status__tests__watch_only_subagent.snap index 8878d8c6a6..dd175843d2 100644 --- a/codex-rs/tui/src/app/snapshots/codex_tui__app__sidebar_subagents__status__tests__watch_only_subagent.snap +++ b/codex-rs/tui/src/app/snapshots/codex_tui__app__sidebar_subagents__status__tests__watch_only_subagent.snap @@ -2,7 +2,7 @@ source: tui/src/app/sidebar_agent_status_tests.rs expression: "crate::chatwidget::tests::helpers::normalize_agent_center_snapshot(screen.replace(&child.to_string(),\n\"[agent id]\"))" --- - │ reviewer × + + │ reviewer × + › >_ OpenAI Codex (v0.0.0) │esc back to agents · Watch only /tmp/project │ │ >_ OpenAI Codex (v0.0.0) diff --git a/codex-rs/tui/src/app/snapshots/codex_tui__app__tests__side_chat_tab_overflow.snap b/codex-rs/tui/src/app/snapshots/codex_tui__app__tests__side_chat_tab_overflow.snap index e0fd6f4ea8..2564403fe2 100644 --- a/codex-rs/tui/src/app/snapshots/codex_tui__app__tests__side_chat_tab_overflow.snap +++ b/codex-rs/tui/src/app/snapshots/codex_tui__app__tests__side_chat_tab_overflow.snap @@ -2,4 +2,4 @@ source: tui/src/app/tests.rs expression: header.trim_end() --- -‹ Fix cache × + +‹ Fix cache × + › diff --git a/codex-rs/tui/src/app/tests.rs b/codex-rs/tui/src/app/tests.rs index ae4de7a4c8..999a5196d5 100644 --- a/codex-rs/tui/src/app/tests.rs +++ b/codex-rs/tui/src/app/tests.rs @@ -3188,115 +3188,6 @@ fn attach_live_thread_for_selection_rejects_unmaterialized_fallback_threads() -> }) } -#[tokio::test] -async fn docked_replay_finishes_while_skills_refresh_is_pending() -> Result<()> { - let (mut app, mut events, _ops) = make_test_app_with_channels().await; - let parent = ThreadId::new(); - let side = ThreadId::new(); - app.side_threads - .insert(side, side::SideThreadState::new(parent)); - enable_side_retention(&mut app)?; - let _ = app.config.features.disable(Feature::Plugins); - app.chat_widget.sync_plugin_mentions_config(&app.config); - let mut tui = crate::tui::test_support::make_test_tui()?; - tui.set_owned_screen(/*owned*/ true)?; - let mut session = test_thread_session(parent, app.config.cwd.to_path_buf()); - session.cwd = codex_utils_path_uri::PathUri::parse("file:///D:/Workspace")?; - app.chat_widget.handle_thread_session(session); - let cwd = codex_utils_path_uri::PathUri::parse("file:///D:/workspace")?; - - let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await?; - let endpoint = crate::resolve_remote_addr(&format!("ws://{}", listener.local_addr()?))?; - let (pending_tx, mut pending_rx) = tokio::sync::mpsc::unbounded_channel(); - let proxy = tokio::spawn(async move { - let (stream, _) = listener.accept().await?; - let socket = tokio_tungstenite::accept_async(stream).await?; - disconnect::serve_reconnect_requests(socket, |request| { - assert_eq!(request.method, "skills/list"); - let (release, wait) = tokio::sync::oneshot::channel(); - pending_tx - .send((request.params, release)) - .expect("test is running"); - async move { - wait.await.expect("release the pending skills refresh"); - Some(serde_json::json!({"result": {"data": []}})) - } - }) - .await - }); - let mut app_server = AppServerSession::new( - crate::backend_id::BackendId::new(), - crate::connect_remote_app_server(endpoint).await?, - crate::app_server_session::ThreadParamsMode::Embedded, - ); - let deadline = std::time::Duration::from_secs(/*secs*/ 5); - while events.try_recv().is_ok() {} - - for thread_id in [side, parent] { - app.active_thread_id = Some(thread_id); - app.pending_thread_switch_resets = 1; - app.app_event_tx - .send(AppEvent::CodexOp(AppCommand::list_skills( - cwd.clone(), - /*force_reload*/ true, - ))); - app.app_event_tx - .send(AppEvent::SideReplayFinished(thread_id)); - - time::timeout( - deadline, - drain_app_events(&mut app, &mut tui, &mut app_server, &mut events), - ) - .await??; - let (params, release) = time::timeout(deadline, pending_rx.recv()) - .await? - .expect("skills/list should be requested"); - assert_eq!( - params, - Some(serde_json::json!({"cwds": [r"D:\workspace"], "forceReload": true})) - ); - assert!(!app.awaiting_side_replay(&tui)); - - release - .send(()) - .expect("skills/list should still be pending"); - let event = time::timeout(deadline, events.recv()) - .await? - .expect("receive the skills refresh"); - assert!(matches!( - &event, - AppEvent::SideReplaySkillsLoaded { thread_id: loaded_thread_id, result: Ok(_), .. } - if *loaded_thread_id == thread_id - )); - boxed_future!(app.handle_event(&mut tui, &mut app_server, event)).await?; - assert_eq!(app_server.pending_side_skills_refresh, None); - } - - app_server.shutdown().await?; - proxy.await??; - Ok(()) -} - -#[tokio::test] -async fn sidebar_reopens_saved_side_chat_after_restart() -> Result<()> { - boxed_future!(reopen_saved_side_chat(DuringOpen::Navigate)).await -} - -#[tokio::test] -async fn closed_saved_chat_keeps_its_live_read_receipt_during_install() -> Result<()> { - boxed_future!(reopen_saved_side_chat(DuringOpen::Close)).await -} - -#[tokio::test] -async fn saved_chat_replays_approval_after_a_stale_runtime_close() -> Result<()> { - boxed_future!(reopen_saved_side_chat(DuringOpen::Approval)).await -} - -#[tokio::test] -async fn fork_releases_a_provisional_saved_chat_on_its_original_connection() -> Result<()> { - boxed_future!(reopen_saved_side_chat(DuringOpen::Fork)).await -} - enum DuringOpen { Navigate, Close, @@ -3531,6 +3422,10 @@ async fn reopen_saved_side_chat(during: DuringOpen) -> Result<()> { assert_eq!(app.current_displayed_thread_id(), Some(parent)); boxed_future!(app.handle_tui_event(&mut tui, &mut server, TuiEvent::Key(release_enter))) .await?; + app.sidebar_mut().choice = 0; + app.hide_sidebar(&mut tui, &mut server).await?; + app.restore_sidebar(&mut tui, &mut server).await?; + assert_eq!(app.sidebar().unwrap().choice, 0); app.sidebar_mut().choice = 1; app.refresh_saved_chats(&server, parent); let request = app.sidebar().unwrap().discovery.request().unwrap(); @@ -3576,7 +3471,7 @@ async fn reopen_saved_side_chat(during: DuringOpen) -> Result<()> { MouseEventKind::Down(MouseButton::Left), MouseEventKind::Up(MouseButton::Left), ] { - let click = mouse(kind, strip.right() - 3, strip.y); + let click = mouse(kind, strip.right() - 6, strip.y); boxed_future!(app.handle_tui_event(&mut tui, &mut server, click)).await?; } let request = app.sidebar().unwrap().discovery.request().unwrap(); @@ -4477,6 +4372,14 @@ async fn handle_start_side_seeds_navigation_before_thread_started() -> Result<() frame.contains(parent_row) && frame.contains("parent draft"), "{frame}" ); + if width == 99 { + assert!( + app.conversation_frame + .sidebar_targets + .iter() + .any(|(target, _)| *target == side_focus::SidebarTarget::Restore) + ); + } for marker in [child_row, "child draft!", "│"] { assert_eq!(frame.contains(marker), width == 100, "{frame}"); } @@ -4688,6 +4591,36 @@ async fn handle_start_side_seeds_navigation_before_thread_started() -> Result<() width == 100, "{reopened}" ); + if width == 100 { + use crate::sidebar_tab_strip::TabTarget; + use side_focus::SidebarTarget; + for (target, thread) in [ + (SidebarTarget::Tab(TabTarget::Hide), parent_thread_id), + (SidebarTarget::Restore, side_thread_id), + ] { + let area = app + .conversation_frame + .sidebar_targets + .iter() + .find(|(candidate, _)| *candidate == target) + .expect("sidebar control") + .1; + for kind in [ + MouseEventKind::Down(MouseButton::Left), + MouseEventKind::Up(MouseButton::Left), + ] { + boxed_future!(app.handle_tui_event( + &mut tui, + &mut app_server, + mouse(kind, area.x + 1, area.y) + )) + .await?; + } + drain_app_events(&mut app, &mut tui, &mut app_server, &mut app_event_rx).await?; + assert_eq!(app.current_displayed_thread_id(), Some(thread)); + side_frame(&mut app, &mut tui, size)?; + } + } frames.push(format!("{width} columns, reopened\n{reopened}")); } assert_app_snapshot!("hide_and_reopen_side_conversation", frames.join("\n\n")); @@ -5414,7 +5347,7 @@ async fn handle_start_side_seeds_navigation_before_thread_started() -> Result<() let arrow_x = header.chars().position(|c| c == '‹').expect("previous tab") as u16; let buffer = tui.terminal.previous_buffer(); let arrow_cell = &buffer[(arrow_x, strip.y)]; - let add_cell = &buffer[(strip.right() - 3, strip.y)]; + let add_cell = &buffer[(strip.right() - 6, strip.y)]; let idle_style = arrow_cell.style(); assert_eq!(idle_style, add_cell.style()); @@ -5556,7 +5489,7 @@ async fn handle_start_side_seeds_navigation_before_thread_started() -> Result<() assert_eq!(app.chooser_focus(), expected_focus, "{focus}"); side_frame(&mut app, &mut tui, even)?; let strip = app.conversation_frame.sidebar_tab_strip().unwrap(); - let add = strip.right() - 3; + let add = strip.right() - 6; let [inactive, selected] = app .conversation_frame .sidebar_targets diff --git a/codex-rs/tui/src/app/tests/saved_chat_loading_tests.rs b/codex-rs/tui/src/app/tests/saved_chat_loading_tests.rs index b866a4df30..6a90bea1a2 100644 --- a/codex-rs/tui/src/app/tests/saved_chat_loading_tests.rs +++ b/codex-rs/tui/src/app/tests/saved_chat_loading_tests.rs @@ -3,6 +3,115 @@ use super::*; use pretty_assertions::assert_eq; +#[tokio::test] +async fn docked_replay_finishes_while_skills_refresh_is_pending() -> Result<()> { + let (mut app, mut events, _ops) = make_test_app_with_channels().await; + let parent = ThreadId::new(); + let side = ThreadId::new(); + app.side_threads + .insert(side, side::SideThreadState::new(parent)); + enable_side_retention(&mut app)?; + let _ = app.config.features.disable(Feature::Plugins); + app.chat_widget.sync_plugin_mentions_config(&app.config); + let mut tui = crate::tui::test_support::make_test_tui()?; + tui.set_owned_screen(/*owned*/ true)?; + let mut session = test_thread_session(parent, app.config.cwd.to_path_buf()); + session.cwd = codex_utils_path_uri::PathUri::parse("file:///D:/Workspace")?; + app.chat_widget.handle_thread_session(session); + let cwd = codex_utils_path_uri::PathUri::parse("file:///D:/workspace")?; + + let listener = tokio::net::TcpListener::bind("127.0.0.1:0").await?; + let endpoint = crate::resolve_remote_addr(&format!("ws://{}", listener.local_addr()?))?; + let (pending_tx, mut pending_rx) = tokio::sync::mpsc::unbounded_channel(); + let proxy = tokio::spawn(async move { + let (stream, _) = listener.accept().await?; + let socket = tokio_tungstenite::accept_async(stream).await?; + disconnect::serve_reconnect_requests(socket, |request| { + assert_eq!(request.method, "skills/list"); + let (release, wait) = tokio::sync::oneshot::channel(); + pending_tx + .send((request.params, release)) + .expect("test is running"); + async move { + wait.await.expect("release the pending skills refresh"); + Some(serde_json::json!({"result": {"data": []}})) + } + }) + .await + }); + let mut app_server = AppServerSession::new( + crate::backend_id::BackendId::new(), + crate::connect_remote_app_server(endpoint).await?, + crate::app_server_session::ThreadParamsMode::Embedded, + ); + let deadline = std::time::Duration::from_secs(/*secs*/ 5); + while events.try_recv().is_ok() {} + + for thread_id in [side, parent] { + app.active_thread_id = Some(thread_id); + app.pending_thread_switch_resets = 1; + app.app_event_tx + .send(AppEvent::CodexOp(AppCommand::list_skills( + cwd.clone(), + /*force_reload*/ true, + ))); + app.app_event_tx + .send(AppEvent::SideReplayFinished(thread_id)); + + time::timeout( + deadline, + drain_app_events(&mut app, &mut tui, &mut app_server, &mut events), + ) + .await??; + let (params, release) = time::timeout(deadline, pending_rx.recv()) + .await? + .expect("skills/list should be requested"); + assert_eq!( + params, + Some(serde_json::json!({"cwds": [r"D:\workspace"], "forceReload": true})) + ); + assert!(!app.awaiting_side_replay(&tui)); + + release + .send(()) + .expect("skills/list should still be pending"); + let event = time::timeout(deadline, events.recv()) + .await? + .expect("receive the skills refresh"); + assert!(matches!( + &event, + AppEvent::SideReplaySkillsLoaded { thread_id: loaded_thread_id, result: Ok(_), .. } + if *loaded_thread_id == thread_id + )); + boxed_future!(app.handle_event(&mut tui, &mut app_server, event)).await?; + assert_eq!(app_server.pending_side_skills_refresh, None); + } + + app_server.shutdown().await?; + proxy.await??; + Ok(()) +} + +#[tokio::test] +async fn sidebar_reopens_saved_side_chat_after_restart() -> Result<()> { + boxed_future!(reopen_saved_side_chat(DuringOpen::Navigate)).await +} + +#[tokio::test] +async fn closed_saved_chat_keeps_its_live_read_receipt_during_install() -> Result<()> { + boxed_future!(reopen_saved_side_chat(DuringOpen::Close)).await +} + +#[tokio::test] +async fn saved_chat_replays_approval_after_a_stale_runtime_close() -> Result<()> { + boxed_future!(reopen_saved_side_chat(DuringOpen::Approval)).await +} + +#[tokio::test] +async fn fork_releases_a_provisional_saved_chat_on_its_original_connection() -> Result<()> { + boxed_future!(reopen_saved_side_chat(DuringOpen::Fork)).await +} + #[tokio::test] async fn saved_chat_retry_and_supersession_with_pending_requests() -> Result<()> { let (mut app, mut events, _ops) = make_test_app_with_channels().await; diff --git a/codex-rs/tui/src/app/tests/snapshots/codex_tui__app__tests__key_chords__sidebar_new_chat.snap b/codex-rs/tui/src/app/tests/snapshots/codex_tui__app__tests__key_chords__sidebar_new_chat.snap index a9f851b1be..ad4dcad320 100644 --- a/codex-rs/tui/src/app/tests/snapshots/codex_tui__app__tests__key_chords__sidebar_new_chat.snap +++ b/codex-rs/tui/src/app/tests/snapshots/codex_tui__app__tests__key_chords__sidebar_new_chat.snap @@ -1,9 +1,8 @@ --- source: tui/src/app/tests/key_chords.rs -assertion_line: 1372 expression: frame --- - │ + + │ + › │ │ Open in sidebar │ diff --git a/codex-rs/tui/src/app/tests/snapshots/codex_tui__app__tests__saved_chat_loading__waiting_and_retry_rows.snap b/codex-rs/tui/src/app/tests/snapshots/codex_tui__app__tests__saved_chat_loading__waiting_and_retry_rows.snap index 352b6ad76b..f524bf944a 100644 --- a/codex-rs/tui/src/app/tests/snapshots/codex_tui__app__tests__saved_chat_loading__waiting_and_retry_rows.snap +++ b/codex-rs/tui/src/app/tests/snapshots/codex_tui__app__tests__saved_chat_loading__waiting_and_retry_rows.snap @@ -1,10 +1,9 @@ --- source: tui/src/app/tests/saved_chat_loading_tests.rs -assertion_line: 138 expression: "format!(\"Waiting\\n{waiting}\\n\\nRetry\\n{retry}\")" --- Waiting - + + + › Open in sidebar + New side chat Start from this conversation Side chats 4 @@ -15,7 +14,7 @@ Waiting enter open · esc cancel opening · ↑/↓ move · ⌃x - hide pane Retry - + + + › Open in sidebar + New side chat Start from this conversation Side chats 4 diff --git a/codex-rs/tui/src/sidebar_tab_strip.rs b/codex-rs/tui/src/sidebar_tab_strip.rs index 93d88952b8..33591b46bc 100644 --- a/codex-rs/tui/src/sidebar_tab_strip.rs +++ b/codex-rs/tui/src/sidebar_tab_strip.rs @@ -1,5 +1,5 @@ //! Draw sidebar tabs and hit-test the same visible cells. When space runs out, -//! keep the selected tab visible and reserve the add button at the right edge. +//! keep the selected tab visible and reserve the add and hide buttons at the right edge. //! A one-column gap separates tabs and is excluded from their click targets. use ratatui::buffer::Buffer; @@ -42,6 +42,7 @@ pub(crate) enum TabTarget { Close(Id), Overflow { tab: Id, glyph: &'static str }, Add, + Hide, } impl<'a, Id: Copy + Eq> TabStrip<'a, Id> { @@ -51,8 +52,9 @@ impl<'a, Id: Copy + Eq> TabStrip<'a, Id> { pub(crate) fn strip_targets(self, area: Rect) -> Vec<(TabTarget, Rect)> { let width = area.width.saturating_sub(1); - let plus = width.min(3); - let available = width - plus; + let hide = width.min(3); + let plus = (width - hide).min(3); + let available = width - plus - hide; let height = area.height.min(1); let rect = |offset, width| Rect::new(area.x + offset, area.y, width, height); let mut targets = Vec::new(); @@ -102,7 +104,12 @@ impl<'a, Id: Copy + Eq> TabStrip<'a, Id> { )); } } - targets.push((TabTarget::Add, rect(available, plus))); + if plus > 0 { + targets.push((TabTarget::Add, rect(available, plus))); + } + if hide > 0 { + targets.push((TabTarget::Hide, rect(available + plus, hide))); + } targets } @@ -163,14 +170,36 @@ impl<'a, Id: Copy + Eq> TabStrip<'a, Id> { let add = match (hovered, add_state) { (true, TabState::Active) => crate::style::hover_style(style(add_state)), (true, TabState::Inactive | TabState::Absent) => hover, - (false, TabState::Active | TabState::Inactive | TabState::Absent) => { - style(add_state) - } + (false, _) => style(add_state), }; - Line::from(" + ").style(add).render(rect, buf); + paint_control("+", rect, add, buf); } + TabTarget::Hide => paint_toggle("›", rect, hovered, buf), } } targets } } + +/// Paint a sidebar visibility control using the same style in open and collapsed layouts. +pub(crate) fn paint_toggle(glyph: &str, area: Rect, hovered: bool, buf: &mut Buffer) { + let normal = crate::style::secondary_text_style() + .bg(Color::Reset) + .not_underlined() + .not_reversed(); + let style = if hovered { + crate::style::hover_style(normal.fg(Color::Reset)) + } else { + normal + }; + paint_control(glyph, area, style, buf); +} + +fn paint_control(glyph: &str, area: Rect, style: Style, buf: &mut Buffer) { + let text = if area.width >= 3 { + format!(" {glyph} ") + } else { + glyph.to_owned() + }; + Line::from(text).style(style).render(area, buf); +} diff --git a/codex-rs/tui/src/snapshots/codex_tui__app__tests__hide_and_reopen_side_conversation.snap b/codex-rs/tui/src/snapshots/codex_tui__app__tests__hide_and_reopen_side_conversation.snap index 04229f763f..8506b76b88 100644 --- a/codex-rs/tui/src/snapshots/codex_tui__app__tests__hide_and_reopen_side_conversation.snap +++ b/codex-rs/tui/src/snapshots/codex_tui__app__tests__hide_and_reopen_side_conversation.snap @@ -3,6 +3,7 @@ source: tui/src/app/tests.rs expression: "frames.join(\"\\n\\n\")" --- 100 columns, hidden + ‹ parent-24 parent-25 @@ -14,7 +15,6 @@ parent-27 parent-28 parent-29 - New activity · ↓ Back to bottom · esc › parent draft @@ -23,7 +23,7 @@ parent-29 New activity · esc latest 100 columns, reopened -parent-24 │ Side chat × + +parent-24 │ Side chat × + › │ parent-25 │child-25 │ @@ -43,7 +43,7 @@ parent-29 │child-29 │ 99 columns, reopened - Side chat × + + Side chat × + › child-25 diff --git a/codex-rs/tui/src/snapshots/codex_tui__app__tests__keyboard_pane_widths.snap b/codex-rs/tui/src/snapshots/codex_tui__app__tests__keyboard_pane_widths.snap index 2cac5e9912..358fc3869a 100644 --- a/codex-rs/tui/src/snapshots/codex_tui__app__tests__keyboard_pane_widths.snap +++ b/codex-rs/tui/src/snapshots/codex_tui__app__tests__keyboard_pane_widths.snap @@ -3,7 +3,7 @@ source: tui/src/app/tests.rs expression: "format!(\"Zoomed\\n{zoomed}\\nRestored\\n{restored}\\nEqualized\\n{equalized}\")" --- Zoomed - Side chat × + + Side chat × + › • unfinished answer @@ -22,7 +22,7 @@ Zoomed GPT-6.2-Sol default · Agent tab to queue message · esc to interrupt · Side from main thread · ⌃/ to switch · ⌃c to close Restored -parent-24 │ Side chat × + +parent-24 │ Side chat × + › │• unfinished answer parent-25 │ │ @@ -41,7 +41,7 @@ parent-29 GPT-6.2-Sol default │ GPT-6.2-Sol default · Agent │ tab to queue message · esc to interrupt · Side from main thread · ⌃/ to switch · ⌃c to close Equalized -parent-24 │ Side chat × + +parent-24 │ Side chat × + › │• unfinished answer parent-25 │ │ diff --git a/codex-rs/tui/src/snapshots/codex_tui__app__tests__side_chat_tabs.snap b/codex-rs/tui/src/snapshots/codex_tui__app__tests__side_chat_tabs.snap index 3d22853a00..3a323a1a9f 100644 --- a/codex-rs/tui/src/snapshots/codex_tui__app__tests__side_chat_tabs.snap +++ b/codex-rs/tui/src/snapshots/codex_tui__app__tests__side_chat_tabs.snap @@ -2,4 +2,4 @@ source: tui/src/app/tests.rs expression: header.trim_end() --- - Investigate re… × Fix cache × + + Investigate re… × Fix cache × + › diff --git a/codex-rs/tui/src/snapshots/codex_tui__app__tests__sidebar_existing_chat.snap b/codex-rs/tui/src/snapshots/codex_tui__app__tests__sidebar_existing_chat.snap index ff7ea06092..6d8087df82 100644 --- a/codex-rs/tui/src/snapshots/codex_tui__app__tests__sidebar_existing_chat.snap +++ b/codex-rs/tui/src/snapshots/codex_tui__app__tests__sidebar_existing_chat.snap @@ -2,7 +2,7 @@ source: tui/src/app/tests.rs expression: "chooser.lines().filter_map(|line|\nline.split_once('│').map(|(_, sidebar)|\nsidebar.trim_end())).collect::>().join(\"\\n\")" --- - Side chat × + + Side chat × + › Open in sidebar diff --git a/codex-rs/tui/src/snapshots/codex_tui__app__tests__single_side_chat.snap b/codex-rs/tui/src/snapshots/codex_tui__app__tests__single_side_chat.snap index 784a95aa2c..c6955c5106 100644 --- a/codex-rs/tui/src/snapshots/codex_tui__app__tests__single_side_chat.snap +++ b/codex-rs/tui/src/snapshots/codex_tui__app__tests__single_side_chat.snap @@ -2,7 +2,7 @@ source: tui/src/app/tests.rs expression: panel --- -parent-24 │ Side chat × + +parent-24 │ Side chat × + › │child-24 parent-25 │ │child-25