Skip to content

armgit / codex

Public Imported from GitHub
0

Lightweight coding agent that runs in your terminal

Rust

Allow Left to open the command center from read-only conversations (#48132)

Eric Trautd9275a63ed1c
diff --git a/codex-rs/tui/src/app.rs b/codex-rs/tui/src/app.rs
index 5fe9131740..7868caa193 100644
--- a/codex-rs/tui/src/app.rs
+++ b/codex-rs/tui/src/app.rs
@@ -1025,7 +1025,9 @@ impl App {
if self.overlay.is_none()
&& self.chat_widget.no_modal_or_popup_active()
&& self.chat_widget.is_external_writer_view()
- && crate::key_hint::plain(KeyCode::Esc).is_press(*key)
+ && (crate::key_hint::plain(KeyCode::Esc).is_press(*key)
+ || (crate::key_hint::plain(KeyCode::Left).is_press(*key)
+ && self.chat_widget.agents_navigation_key_available()))
{
self.open_agents_overview(app_server);
} else if self.reconnect.presentation == reconnect::ReconnectPresentation::Overview {
diff --git a/codex-rs/tui/src/app/agents_overview_tests.rs b/codex-rs/tui/src/app/agents_overview_tests.rs
index 182d7ac643..473ab79dcf 100644
--- a/codex-rs/tui/src/app/agents_overview_tests.rs
+++ b/codex-rs/tui/src/app/agents_overview_tests.rs
@@ -2439,22 +2439,22 @@ async fn command_center_attach_conflict_opens_read_only_and_retries() -> Result<
insta::assert_snapshot!("agents_overview_attach_conflict", render_bottom_popup(&app.chat_widget, /*width*/ 96));
});
- app.handle_key_event(&mut tui, &mut server, KeyCode::Esc.into())
- .await;
-
- assert_eq!(
- app.chat_widget
- .selected_index_for_present_view(AGENTS_OVERVIEW_VIEW_ID),
- selection
- );
+ for key in [KeyCode::Left, KeyCode::Esc] {
+ Box::pin(app.handle_tui_event(&mut tui, &mut server, TuiEvent::Key(key.into()))).await?;
+ assert_eq!(
+ app.chat_widget
+ .selected_index_for_present_view(AGENTS_OVERVIEW_VIEW_ID),
+ selection
+ );
- // Opening the displayed task returns to the same frozen snapshot without retrying.
- Box::pin(app.handle_event(
- &mut tui,
- &mut server,
- AppEvent::SelectAgentsOverviewThread { thread_id },
- ))
- .await?;
+ // Opening the displayed task returns to the same frozen snapshot without retrying.
+ Box::pin(app.handle_event(
+ &mut tui,
+ &mut server,
+ AppEvent::SelectAgentsOverviewThread { thread_id },
+ ))
+ .await?;
+ }
assert!(app.chat_widget.no_modal_or_popup_active());
assert!(app.chat_widget.is_external_writer_view());
app.chat_widget.handle_paste(" should be ignored".into());
diff --git a/codex-rs/tui/src/app/input.rs b/codex-rs/tui/src/app/input.rs
index a440ef07b0..f02b1b435f 100644
--- a/codex-rs/tui/src/app/input.rs
+++ b/codex-rs/tui/src/app/input.rs
@@ -562,6 +562,14 @@ impl App {
&& self.overlay.is_none()
&& self.chat_widget.no_modal_or_popup_active()
{
+ if key_event.kind == KeyEventKind::Press
+ && key_event.code == KeyCode::Left
+ && key_event.modifiers == KeyModifiers::NONE
+ && self.chat_widget.agents_navigation_key_available()
+ && !matches!(self.app_server_target, AppServerTarget::Embedded)
+ {
+ self.open_agents_overview(app_server);
+ }
return;
}
diff --git a/codex-rs/tui/src/app/tests/background_exit_tests.rs b/codex-rs/tui/src/app/tests/background_exit_tests.rs
index c18dc1194d..fcc507d8d0 100644
--- a/codex-rs/tui/src/app/tests/background_exit_tests.rs
+++ b/codex-rs/tui/src/app/tests/background_exit_tests.rs
@@ -110,6 +110,84 @@ async fn external_writer_view_preserves_draft_from_keys_and_paste() -> Result<()
Ok(())
}
+#[tokio::test]
+async fn external_writer_view_opens_agents_with_left() -> Result<()> {
+ for offline in [false, true] {
+ let (mut app, _, _) = make_test_app_with_channels().await;
+ app.app_server_target = AppServerTarget::Remote {
+ endpoint: crate::resolve_remote_addr("ws://127.0.0.1:4500")?,
+ };
+ app.chat_widget.insert_str("Retained draft");
+ app.chat_widget.show_external_writer_thread();
+ app.reconnect.offline = offline;
+ let mut app_server = crate::start_embedded_app_server_for_picker(&app.config).await?;
+ let mut tui = crate::tui::test_support::make_test_tui()?;
+ tui.set_owned_screen(/*owned*/ true)?;
+
+ app.handle_tui_event(
+ &mut tui,
+ &mut app_server,
+ TuiEvent::Key(KeyCode::Left.into()),
+ )
+ .await?;
+
+ assert!(
+ app.chat_widget
+ .selected_index_for_present_view(AGENTS_OVERVIEW_VIEW_ID)
+ .is_some()
+ );
+ assert_eq!(
+ app.chat_widget.composer_text_with_pending(),
+ "Retained draft"
+ );
+ tui.set_owned_screen(/*owned*/ false)?;
+ app_server.shutdown().await?;
+ }
+ Ok(())
+}
+
+#[tokio::test]
+async fn external_writer_view_respects_remapped_left() -> Result<()> {
+ let config: codex_config::types::TuiKeymap = toml::from_str(
+ "[global]\nopen_transcript = 'left'\n[editor]\nmove_left = 'ctrl-b'\n[list]\nmove_left = 'ctrl-h'\n",
+ )?;
+ let keymap = RuntimeKeymap::from_config(&config).map_err(|err| color_eyre::eyre::eyre!(err))?;
+ for (offline, vim) in [(false, false), (true, false), (false, true), (true, true)] {
+ let (mut app, _, _) = make_test_app_with_channels().await;
+ app.app_server_target = AppServerTarget::Remote {
+ endpoint: crate::resolve_remote_addr("ws://127.0.0.1:4500")?,
+ };
+ app.chat_widget.remote_connection =
+ crate::status::remote_connection::remote_connection_status_value(
+ &app.app_server_target,
+ /*server_version*/ None,
+ );
+ app.chat_widget.apply_keymap_update(config.clone(), &keymap);
+ app.keymap = keymap.clone();
+ if vim {
+ app.chat_widget.toggle_vim_mode_and_notify();
+ }
+ app.chat_widget.show_external_writer_thread();
+ app.reconnect.offline = offline;
+ let mut app_server = crate::start_embedded_app_server_for_picker(&app.config).await?;
+ let mut tui = crate::tui::test_support::make_test_tui()?;
+
+ if !offline && vim {
+ insta::assert_snapshot!(render_bottom_popup(&app.chat_widget, /*width*/ 96));
+ }
+ app.handle_tui_event(
+ &mut tui,
+ &mut app_server,
+ TuiEvent::Key(KeyCode::Left.into()),
+ )
+ .await?;
+ assert!(app.chat_widget.no_modal_or_popup_active());
+ assert_eq!(app.overlay.is_some(), !offline);
+ app_server.shutdown().await?;
+ }
+ Ok(())
+}
+
#[tokio::test]
async fn daemon_disconnect_exit_summary_includes_reconnect_and_stop_instructions() -> Result<()> {
let (mut app, _, _) = make_test_app_with_channels().await;
diff --git a/codex-rs/tui/src/app/tests/snapshots/codex_tui__app__tests__background_exit_tests__external_writer_view_respects_remapped_left.snap b/codex-rs/tui/src/app/tests/snapshots/codex_tui__app__tests__background_exit_tests__external_writer_view_respects_remapped_left.snap
new file mode 100644
index 0000000000..6b2ac7065a
--- /dev/null
+++ b/codex-rs/tui/src/app/tests/snapshots/codex_tui__app__tests__background_exit_tests__external_writer_view_respects_remapped_left.snap
@@ -0,0 +1,8 @@
+---
+source: tui/src/app/tests/background_exit_tests.rs
+expression: "render_bottom_popup(&app.chat_widget, 96)"
+---
+ πŸ”’ This conversation is open in another app r to retry
+ Close it there and press R to continue here.
+
+ r retry f fork esc command center ctrl+c/q exit ← transcript
diff --git a/codex-rs/tui/src/bottom_pane/chat_composer/agents_navigation.rs b/codex-rs/tui/src/bottom_pane/chat_composer/agents_navigation.rs
index f2fdbf0dd2..6375a01f32 100644
--- a/codex-rs/tui/src/bottom_pane/chat_composer/agents_navigation.rs
+++ b/codex-rs/tui/src/bottom_pane/chat_composer/agents_navigation.rs
@@ -10,14 +10,18 @@ impl ChatComposer {
self.agents_navigation_enabled = enabled;
}
- pub(super) fn agents_navigation_available(&self) -> bool {
+ pub(crate) fn agents_navigation_key_available(&self) -> bool {
let move_left = if self.draft.textarea.is_vim_normal_mode() {
&self.vim_normal_keymap.move_left
} else {
&self.editor_keymap.move_left
};
+ move_left.is_pressed(KeyCode::Left.into())
+ }
+
+ pub(super) fn agents_navigation_available(&self) -> bool {
self.agents_navigation_enabled
- && move_left.is_pressed(KeyCode::Left.into())
+ && self.agents_navigation_key_available()
&& self.has_focus
&& self.draft.input_enabled
&& self.slash_commands_enabled()
diff --git a/codex-rs/tui/src/bottom_pane/mod.rs b/codex-rs/tui/src/bottom_pane/mod.rs
index ce3742916f..f3382db2da 100644
--- a/codex-rs/tui/src/bottom_pane/mod.rs
+++ b/codex-rs/tui/src/bottom_pane/mod.rs
@@ -445,6 +445,32 @@ impl BottomPane {
self.request_redraw();
}
+ pub(crate) fn agents_navigation_key_available(&self) -> bool {
+ let left = KeyEvent::from(KeyCode::Left);
+ self.composer.agents_navigation_key_available()
+ && !crate::keymap::keymap_action_ids()
+ .filter(|action| {
+ matches!(
+ action.context,
+ KeymapContext::Global | KeymapContext::Chat | KeymapContext::Voice
+ )
+ })
+ .any(|action| {
+ crate::keymap::bindings_for_action(
+ &self.keymap,
+ action.context.config_name(),
+ action.action,
+ )
+ .is_some_and(|bindings| bindings.is_pressed(left))
+ })
+ && !self.keymap.chords.bindings.iter().any(|binding| {
+ matches!(
+ binding.action.context,
+ KeymapContext::Global | KeymapContext::Chat | KeymapContext::Voice
+ ) && binding.chord.prefix.is_press(left)
+ })
+ }
+
pub(crate) fn set_task_mentions_enabled(&mut self, enabled: bool) {
self.composer.set_task_mentions_enabled(enabled);
self.request_redraw();
diff --git a/codex-rs/tui/src/chatwidget/interaction.rs b/codex-rs/tui/src/chatwidget/interaction.rs
index 41ff9782cf..571ae8d32b 100644
--- a/codex-rs/tui/src/chatwidget/interaction.rs
+++ b/codex-rs/tui/src/chatwidget/interaction.rs
@@ -49,6 +49,10 @@ impl ChatWidget {
self.bottom_pane.set_agents_navigation_enabled(enabled);
}
+ pub(crate) fn agents_navigation_key_available(&self) -> bool {
+ self.bottom_pane.agents_navigation_key_available()
+ }
+
pub(crate) fn keymap_contexts(&self) -> crate::keymap::KeymapContextSet {
self.bottom_pane.keymap_contexts()
}
diff --git a/codex-rs/tui/src/chatwidget/rendering.rs b/codex-rs/tui/src/chatwidget/rendering.rs
index e4047f3409..345146fadb 100644
--- a/codex-rs/tui/src/chatwidget/rendering.rs
+++ b/codex-rs/tui/src/chatwidget/rendering.rs
@@ -14,6 +14,7 @@ use std::cell::Cell;
struct ExternalWriterNotice {
command_center_available: bool,
+ agents_navigation_key_available: bool,
transcript_hint: Option<crate::key_hint::ShortcutHint>,
}
@@ -98,7 +99,13 @@ impl ExternalWriterNotice {
crate::key_hint::plain(KeyCode::Char('q')).display_label(),
];
if self.command_center_available {
- items.push((escape, "command center".to_string()));
+ let key = if self.agents_navigation_key_available {
+ let left = crate::key_hint::plain(KeyCode::Left).display_label();
+ format!("{left}/{escape}")
+ } else {
+ escape
+ };
+ items.push((key, "command center".to_string()));
} else {
quit_keys.insert(/*index*/ 0, escape);
}
@@ -221,6 +228,7 @@ impl ChatWidget {
} else if self.external_writer_view && !self.bottom_pane.has_active_view() {
RenderableItem::Owned(Box::new(ExternalWriterNotice {
command_center_available: self.remote_connection.is_some(),
+ agents_navigation_key_available: self.agents_navigation_key_available(),
transcript_hint: self.bottom_pane.transcript_shortcut_hint(),
}))
} else {
diff --git a/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__rendering__tests__external_writer_command_center_100.snap b/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__rendering__tests__external_writer_command_center_100.snap
index ad87ff8d8e..96c7bc32bc 100644
--- a/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__rendering__tests__external_writer_command_center_100.snap
+++ b/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__rendering__tests__external_writer_command_center_100.snap
@@ -5,4 +5,4 @@ expression: rendered
πŸ”’ This conversation is open in another app r to retry
Close it there and press R to continue here.
- r retry f fork esc command center ctrl+c/q exit ctrl+t transcript
+ r retry f fork ←/esc command center ctrl+c/q exit ctrl+t transcript
diff --git a/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__rendering__tests__external_writer_command_center_60.snap b/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__rendering__tests__external_writer_command_center_60.snap
index 41d2057cd8..42905ae08e 100644
--- a/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__rendering__tests__external_writer_command_center_60.snap
+++ b/codex-rs/tui/src/chatwidget/snapshots/codex_tui__chatwidget__rendering__tests__external_writer_command_center_60.snap
@@ -5,5 +5,5 @@ expression: rendered
πŸ”’ This conversation is open in another app r to retry
Close it there and press R to continue here.
- r retry f fork esc command center ctrl+c/q exit
+ r retry f fork ←/esc command center ctrl+c/q exit
ctrl+t transcript
diff --git a/codex-rs/tui/src/snapshots/codex_tui__app__agents_overview__tests__agents_overview_attach_conflict.snap b/codex-rs/tui/src/snapshots/codex_tui__app__agents_overview__tests__agents_overview_attach_conflict.snap
index f094b1ce63..a48df0cb2a 100644
--- a/codex-rs/tui/src/snapshots/codex_tui__app__agents_overview__tests__agents_overview_attach_conflict.snap
+++ b/codex-rs/tui/src/snapshots/codex_tui__app__agents_overview__tests__agents_overview_attach_conflict.snap
@@ -5,4 +5,4 @@ expression: "render_bottom_popup(&app.chat_widget, 96)"
πŸ”’ This conversation is open in another app r to retry
Close it there and press R to continue here.
- r retry f fork esc command center ctrl+c/q exit ctrl+t transcript
+ r retry f fork ←/esc command center ctrl+c/q exit ctrl+t transcript