mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Keep side conversations open when switching threads (#35011)
## What changed - Add a configurable `toggle_side_conversation` TUI action, bound to `ctrl-/` by default, to switch between a side conversation and its parent without closing either. - Show the active binding in the footer and distinguish switching from closing with `ctrl-c`. - Allow starting a replacement side conversation from the parent, while cleaning up the previous side thread and preserving it if cleanup fails. - Clean up retained side conversations when shutting down the current thread. ## Testing - Cover shortcut remapping, conflicts, and compatibility with existing `ctrl-/` and `ctrl-7` bindings. - Cover side-thread replacement and footer states for both the parent and side conversation. GitOrigin-RevId: a621c21e1c45ba73197d59750b2e05efa5ee1081
This commit is contained in:
1 parent
62ba648136
commit
7d4b417cd1
20 files changed
+244
-27
No files matched your search
@@ -2398,6 +2398,7 @@ impl App {
|
||||
self.keymap = runtime_keymap.clone();
|
||||
self.chat_widget
|
||||
.apply_keymap_update(keymap_config, &runtime_keymap);
|
||||
self.sync_side_thread_ui();
|
||||
self.chat_widget
|
||||
.return_to_keymap_picker(&context, &action, &runtime_keymap);
|
||||
self.chat_widget.add_info_message(message, /*hint*/ None);
|
||||
@@ -2448,6 +2449,7 @@ impl App {
|
||||
self.keymap = runtime_keymap.clone();
|
||||
self.chat_widget
|
||||
.apply_keymap_update(keymap_config, &runtime_keymap);
|
||||
self.sync_side_thread_ui();
|
||||
self.chat_widget
|
||||
.return_to_keymap_picker(&context, &action, &runtime_keymap);
|
||||
self.chat_widget.add_info_message(
|
||||
|
||||
@@ -142,6 +142,19 @@ impl App {
|
||||
|
||||
let app_keymap_shortcuts_available = self.app_keymap_shortcuts_available();
|
||||
|
||||
let side_toggle_bindings = &self.keymap.app.toggle_side_conversation;
|
||||
if app_keymap_shortcuts_available
|
||||
&& (side_toggle_bindings.is_pressed(key_event)
|
||||
|| side_toggle_bindings.contains(&crate::key_hint::ctrl(KeyCode::Char('/')))
|
||||
&& crate::key_hint::ctrl(KeyCode::Char('7')).is_press(key_event))
|
||||
{
|
||||
if let Err(err) = self.toggle_side_conversation(tui, app_server).await {
|
||||
self.chat_widget
|
||||
.add_error_message(format!("Failed to switch side conversation: {err}"));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if app_keymap_shortcuts_available && self.keymap.app.toggle_vim_mode.is_pressed(key_event) {
|
||||
self.chat_widget.toggle_vim_mode_and_notify();
|
||||
return;
|
||||
|
||||
@@ -20,7 +20,7 @@ const SIDE_NO_STARTED_CONVERSATION_MESSAGE: &str = concat!(
|
||||
"Send a message first, then try /side again."
|
||||
);
|
||||
const SIDE_ALREADY_OPEN_MESSAGE: &str =
|
||||
"A side conversation is already open. Press Ctrl+C to return before starting another.";
|
||||
"A side conversation is already open. Press ctrl + c to return before starting another.";
|
||||
const SIDE_BOUNDARY_PROMPT: &str = r#"Side conversation boundary.
|
||||
|
||||
Everything before this boundary is inherited history from the parent thread. It is reference context only. It is not your current task.
|
||||
@@ -236,6 +236,19 @@ impl App {
|
||||
.map(|state| (state.parent_thread_id, state.parent_status))
|
||||
else {
|
||||
clear_side_ui(&mut self.chat_widget);
|
||||
if self
|
||||
.side_threads
|
||||
.values()
|
||||
.any(|state| state.parent_thread_id == active_thread_id)
|
||||
&& let Some(binding) =
|
||||
crate::keymap::primary_binding(&self.keymap.app.toggle_side_conversation)
|
||||
{
|
||||
self.chat_widget
|
||||
.set_side_conversation_context_label(Some(format!(
|
||||
"{} for side",
|
||||
binding.display_label()
|
||||
)));
|
||||
}
|
||||
return;
|
||||
};
|
||||
|
||||
@@ -256,7 +269,12 @@ impl App {
|
||||
if let Some(parent_status) = parent_status {
|
||||
label_parts.push(parent_status.label(parent_is_main).to_string());
|
||||
}
|
||||
label_parts.push("Ctrl+C to return".to_string());
|
||||
if let Some(binding) =
|
||||
crate::keymap::primary_binding(&self.keymap.app.toggle_side_conversation)
|
||||
{
|
||||
label_parts.push(format!("{} to switch", binding.display_label()));
|
||||
}
|
||||
label_parts.push("ctrl + c to close".to_string());
|
||||
self.chat_widget
|
||||
.set_side_conversation_context_label(Some(format!("Side {}", label_parts.join(" · "))));
|
||||
}
|
||||
@@ -353,12 +371,37 @@ impl App {
|
||||
&self,
|
||||
target_thread_id: ThreadId,
|
||||
) -> Option<ThreadId> {
|
||||
let side_thread_id = self.current_displayed_thread_id()?;
|
||||
if target_thread_id == side_thread_id || !self.side_threads.contains_key(&side_thread_id) {
|
||||
let active_thread_id = self.current_displayed_thread_id()?;
|
||||
let (&side_thread_id, state) = self.side_threads.iter().next()?;
|
||||
if target_thread_id == side_thread_id || target_thread_id == active_thread_id {
|
||||
return None;
|
||||
}
|
||||
|
||||
Some(side_thread_id)
|
||||
(active_thread_id == side_thread_id || active_thread_id == state.parent_thread_id)
|
||||
.then_some(side_thread_id)
|
||||
}
|
||||
|
||||
pub(super) async fn toggle_side_conversation(
|
||||
&mut self,
|
||||
tui: &mut tui::Tui,
|
||||
app_server: &mut AppServerSession,
|
||||
) -> Result<()> {
|
||||
let Some(active_thread_id) = self.current_displayed_thread_id() else {
|
||||
return Ok(());
|
||||
};
|
||||
let Some((&side_thread_id, state)) = self.side_threads.iter().next() else {
|
||||
return Ok(());
|
||||
};
|
||||
let target_thread_id = if active_thread_id == side_thread_id {
|
||||
state.parent_thread_id
|
||||
} else if active_thread_id == state.parent_thread_id {
|
||||
side_thread_id
|
||||
} else {
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
self.select_agent_thread(tui, app_server, target_thread_id)
|
||||
.await
|
||||
}
|
||||
|
||||
pub(super) async fn discard_side_thread(
|
||||
@@ -484,7 +527,7 @@ impl App {
|
||||
pub(super) fn side_start_block_message(&self) -> Option<&'static str> {
|
||||
if self.primary_thread_id.is_none() {
|
||||
Some(SIDE_MAIN_THREAD_UNAVAILABLE_MESSAGE)
|
||||
} else if !self.side_threads.is_empty() {
|
||||
} else if self.active_side_parent_thread_id().is_some() {
|
||||
Some(SIDE_ALREADY_OPEN_MESSAGE)
|
||||
} else {
|
||||
None
|
||||
@@ -530,7 +573,6 @@ impl App {
|
||||
app_server: &mut AppServerSession,
|
||||
thread_id: ThreadId,
|
||||
) -> Result<()> {
|
||||
let active_thread_id_before_switch = self.active_thread_id;
|
||||
let side_thread_to_discard = self.side_thread_to_discard_after_switch(thread_id);
|
||||
self.select_agent_thread(tui, app_server, thread_id).await?;
|
||||
if self.active_thread_id == Some(thread_id)
|
||||
@@ -539,7 +581,7 @@ impl App {
|
||||
if self.discard_side_thread(app_server, side_thread_id).await {
|
||||
self.surface_pending_inactive_thread_interactive_requests()
|
||||
.await?;
|
||||
} else if active_thread_id_before_switch == Some(side_thread_id) {
|
||||
} else {
|
||||
self.keep_side_thread_visible_after_cleanup_failure(
|
||||
tui,
|
||||
app_server,
|
||||
@@ -565,6 +607,15 @@ impl App {
|
||||
return Ok(AppRunControl::Continue);
|
||||
}
|
||||
|
||||
if let Some((&side_thread_id, state)) = self.side_threads.iter().next()
|
||||
&& (parent_thread_id != state.parent_thread_id
|
||||
|| !self.discard_side_thread(app_server, side_thread_id).await)
|
||||
{
|
||||
self.restore_side_user_message(user_message.take());
|
||||
self.sync_side_thread_ui();
|
||||
return Ok(AppRunControl::Continue);
|
||||
}
|
||||
|
||||
self.session_telemetry.counter(
|
||||
"codex.thread.side",
|
||||
/*inc*/ 1,
|
||||
|
||||
@@ -3788,7 +3788,7 @@ async fn side_fork_config_inherits_parent_thread_runtime_settings() {
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn side_start_block_message_tracks_open_side_conversation() {
|
||||
async fn side_start_block_message_allows_replacing_open_side_conversation() {
|
||||
let mut app = make_test_app().await;
|
||||
assert_eq!(
|
||||
app.side_start_block_message(),
|
||||
@@ -3803,10 +3803,14 @@ async fn side_start_block_message_tracks_open_side_conversation() {
|
||||
app.side_threads
|
||||
.insert(side_thread_id, SideThreadState::new(parent_thread_id));
|
||||
|
||||
app.active_thread_id = Some(parent_thread_id);
|
||||
assert_eq!(app.side_start_block_message(), None);
|
||||
|
||||
app.active_thread_id = Some(side_thread_id);
|
||||
assert_eq!(
|
||||
app.side_start_block_message(),
|
||||
Some(
|
||||
"A side conversation is already open. Press Ctrl+C to return before starting another."
|
||||
"A side conversation is already open. Press ctrl + c to return before starting another."
|
||||
)
|
||||
);
|
||||
|
||||
@@ -4269,6 +4273,16 @@ async fn side_discard_selection_keeps_current_side_thread() {
|
||||
app.side_thread_to_discard_after_switch(parent_thread_id),
|
||||
Some(side_thread_id)
|
||||
);
|
||||
|
||||
app.active_thread_id = Some(parent_thread_id);
|
||||
assert_eq!(
|
||||
app.side_thread_to_discard_after_switch(ThreadId::new()),
|
||||
Some(side_thread_id)
|
||||
);
|
||||
assert_eq!(
|
||||
app.side_thread_to_discard_after_switch(side_thread_id),
|
||||
None
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
|
||||
@@ -14,6 +14,10 @@ use codex_app_server_protocol::WarningNotification;
|
||||
|
||||
impl App {
|
||||
pub(super) async fn shutdown_current_thread(&mut self, app_server: &mut AppServerSession) {
|
||||
let side_thread_ids: Vec<ThreadId> = self.side_threads.keys().copied().collect();
|
||||
for side_thread_id in side_thread_ids {
|
||||
self.discard_side_thread(app_server, side_thread_id).await;
|
||||
}
|
||||
if let Some(thread_id) = self.chat_widget.thread_id() {
|
||||
if let Err(err) = app_server.thread_unsubscribe(thread_id).await {
|
||||
tracing::warn!("failed to unsubscribe thread {thread_id}: {err}");
|
||||
|
||||
Reference in new issue
Block a user