Return to the command center after session cancellation or deletion (#44711)

## Why

Deleting a session, canceling an archived session resume or fork, and pressing `Esc` in a conversation open in another app previously exited the TUI. Local daemon and remote connections can instead return to the command center to select another conversation.

## What changed

- Return to the command center after successful deletion on local daemon and remote connections. Shut down side conversations before deletion and clear the deleted thread's local state.
- Return to the command center when an unarchive prompt is canceled, discarding startup input intended for the canceled resume or fork. Keep explicit quit actions and embedded server exit behavior.
- Make `Esc` open the command center from a conversation open in another app. Reselecting that conversation preserves its read-only snapshot and draft; `R` explicitly retries attachment.
- Update deletion confirmation text and keyboard hints to reflect these destinations.

## Testing

Add lifecycle tests for deletion success and failure, side conversation cleanup, unarchive cancellation and quitting, and read-only snapshot preservation. Add snapshots for command center navigation hints and deletion confirmation.

GitOrigin-RevId: 55a96358edb7af73949877a515614943bdc73643
This commit is contained in:
Eric Traut authored and copyberry committed 2026-09-11 03:10:55 +00:00
1 parent fc948f8c47
commit 08e49689b8
18 files changed
+500 -142

No files matched your search

+13 -12
View File
@@ -13,6 +13,7 @@ use ratatui::widgets::Block;
use std::cell::Cell;
struct ExternalWriterNotice {
command_center_available: bool,
transcript_hint: Option<crate::key_hint::ShortcutHint>,
}
@@ -87,19 +88,18 @@ impl ExternalWriterNotice {
}
fn footer_lines(&self, width: u16) -> Vec<Line<'static>> {
let mut items = vec![
("r".to_string(), "retry".to_string()),
(
format!(
"{}/{}/{}",
crate::key_hint::plain(KeyCode::Esc).display_label(),
crate::key_hint::ctrl(KeyCode::Char('c')).display_label(),
crate::key_hint::plain(KeyCode::Char('q')).display_label(),
)
.replace(" + ", "+"),
"exit".to_string(),
),
let mut items = vec![("r".to_string(), "retry".to_string())];
let escape = crate::key_hint::plain(KeyCode::Esc).display_label();
let mut quit_keys = vec![
crate::key_hint::ctrl(KeyCode::Char('c')).display_label(),
crate::key_hint::plain(KeyCode::Char('q')).display_label(),
];
if self.command_center_available {
items.push((escape, "command center".to_string()));
} else {
quit_keys.insert(/*index*/ 0, escape);
}
items.push((quit_keys.join("/").replace(" + ", "+"), "exit".to_string()));
if let Some(hint) = self.transcript_hint {
items.push((
hint.display_label().replace(" + ", "+"),
@@ -193,6 +193,7 @@ impl ChatWidget {
}
let bottom = if self.external_writer_view && !self.bottom_pane.has_active_view() {
RenderableItem::Owned(Box::new(ExternalWriterNotice {
command_center_available: self.remote_connection.is_some(),
transcript_hint: self.bottom_pane.transcript_shortcut_hint(),
}))
} else {
@@ -367,3 +367,25 @@ async fn removing_active_cell_invalidates_layout_before_reusing_its_identity() {
render_frame(&widget, /*width*/ 80);
assert_eq!(desired_height_calls.load(Ordering::Relaxed), 2);
}
#[tokio::test]
async fn external_writer_notice_offers_command_center_on_shared_servers() {
let endpoint = crate::resolve_remote_addr("ws://127.0.0.1:4500").unwrap();
for target in [
crate::AppServerTarget::LocalDaemon {
endpoint: endpoint.clone(),
},
crate::AppServerTarget::Remote { endpoint },
] {
let (mut widget, _sender, _events, _operations) =
make_chatwidget_manual_with_sender().await;
widget.remote_connection = crate::status::remote_connection::remote_connection_status_value(
&target, /*server_version*/ None,
);
widget.show_external_writer_thread();
for width in [60, 100] {
let rendered = crate::chatwidget::tests::render_bottom_popup(&widget, width);
insta::assert_snapshot!(format!("external_writer_command_center_{width}"), rendered);
}
}
}
@@ -227,7 +227,12 @@ impl ChatWidget {
..Default::default()
},
SelectionItem {
name: "Yes, delete and exit".to_string(),
name: if self.remote_connection.is_some() {
"Yes, delete and return to command center"
} else {
"Yes, delete and exit"
}
.to_string(),
description: Some("Permanently delete this session now".to_string()),
actions: vec![Box::new(|tx| {
tx.send(AppEvent::DeleteCurrentThread);
@@ -0,0 +1,10 @@
---
source: tui/src/chatwidget/rendering_tests.rs
expression: rendered
---
🔒 This conversation is open in another app R to Retry
Close it there and press R to continue here.
r retry esc command center ctrl+c/q exit ctrl+t transcript
@@ -0,0 +1,11 @@
---
source: tui/src/chatwidget/rendering_tests.rs
expression: rendered
---
🔒 This conversation is open in another app R to Retry
Close it there and press R to continue here.
r retry esc command center ctrl+c/q exit ctrl+t
transcript
@@ -0,0 +1,12 @@
---
source: tui/src/chatwidget/tests/slash_commands.rs
expression: popup
---
Delete this session?
Cannot be undone. Subagent threads will also be deleted.
› 1. No, keep this session Return to the current session
2. Yes, delete and return to command center Permanently delete this session
now
Press enter to confirm or esc to go back
@@ -3108,20 +3108,31 @@ async fn slash_archive_confirmation_requests_current_thread_archive() {
#[tokio::test]
async fn slash_delete_confirmation_requests_current_thread_delete() {
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
chat.dispatch_command(SlashCommand::Delete);
assert!(chat.bottom_pane.has_active_view());
assert_matches!(rx.try_recv(), Err(TryRecvError::Empty));
let popup = render_bottom_popup(&chat, /*width*/ 80);
assert_chatwidget_snapshot!("slash_delete_confirmation_popup", popup);
chat.handle_key_event(KeyEvent::from(KeyCode::Down));
chat.handle_key_event(KeyEvent::from(KeyCode::Enter));
assert_matches!(rx.try_recv(), Ok(AppEvent::DeleteCurrentThread));
let endpoint = crate::resolve_remote_addr("ws://127.0.0.1:4500").unwrap();
for target in [
crate::AppServerTarget::Embedded,
crate::AppServerTarget::LocalDaemon {
endpoint: endpoint.clone(),
},
crate::AppServerTarget::Remote { endpoint },
] {
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
chat.remote_connection = crate::status::remote_connection::remote_connection_status_value(
&target, /*server_version*/ None,
);
chat.dispatch_command(SlashCommand::Delete);
assert!(chat.bottom_pane.has_active_view());
assert_matches!(rx.try_recv(), Err(TryRecvError::Empty));
let popup = render_bottom_popup(&chat, /*width*/ 80);
if matches!(target, crate::AppServerTarget::Embedded) {
assert_chatwidget_snapshot!("slash_delete_confirmation_popup", popup);
} else {
assert_chatwidget_snapshot!("slash_delete_confirmation_command_center", popup);
}
chat.handle_key_event(KeyEvent::from(KeyCode::Down));
chat.handle_key_event(KeyEvent::from(KeyCode::Enter));
assert_matches!(rx.try_recv(), Ok(AppEvent::DeleteCurrentThread));
}
}
#[tokio::test]