mirror of
https://github.com/openai/codex.git
synced 2026-11-20 07:06:24 +00:00
Add session resume to the agent command center (#42419)
## What changed - Add a configurable `agents.resume` action, bound to `Ctrl+O` by default, that opens the session resume picker from the agent command center. - Preserve command-center state when the picker is cancelled, and preserve per-thread composer and queued-input state when switching sessions. - Keep resume failures within the command-center flow and wrap footer shortcuts on narrow terminals. ## Testing - Add coverage for picker cancellation, active-session selection, resume failures, per-thread input restoration, custom keybindings, and narrow footer layout. GitOrigin-RevId: 59159f838a0c642200cd164e3af45b0971d29bf8
This commit is contained in:
1 parent
b27a6321fa
commit
1d741742c5
25 files changed
+712
-170
No files matched your search
@@ -0,0 +1,142 @@
|
||||
//! In-app session picker transitions, preserving per-thread input and the view on cancellation.
|
||||
|
||||
use super::*;
|
||||
use crate::chatwidget::ThreadInputStateRestoreMode;
|
||||
|
||||
impl App {
|
||||
pub(super) async fn open_resume_picker(
|
||||
&mut self,
|
||||
tui: &mut tui::Tui,
|
||||
app_server: &mut AppServerSession,
|
||||
) -> Result<AppRunControl> {
|
||||
let picker_app_server = match crate::start_app_server_for_picker(
|
||||
&self.config,
|
||||
&self.app_server_target,
|
||||
self.state_db.clone(),
|
||||
self.environment_manager.clone(),
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(app_server) => app_server,
|
||||
Err(err) => {
|
||||
self.add_session_picker_error(format!("Failed to start TUI session picker: {err}"));
|
||||
self.chat_widget.maybe_send_next_queued_input();
|
||||
return Ok(AppRunControl::Continue);
|
||||
}
|
||||
};
|
||||
let selection =
|
||||
crate::resume_picker::run_resume_picker_from_existing_session_with_app_server(
|
||||
tui,
|
||||
&self.config,
|
||||
&self.local_settings,
|
||||
/*show_all*/ false,
|
||||
/*include_non_interactive*/ false,
|
||||
picker_app_server,
|
||||
app_server.request_handle(),
|
||||
self.primary_thread_id
|
||||
.or(self.current_displayed_thread_id()),
|
||||
)
|
||||
.await;
|
||||
match selection {
|
||||
Ok(selection) => {
|
||||
self.apply_resume_picker_selection(tui, app_server, selection)
|
||||
.await
|
||||
}
|
||||
Err(err) => {
|
||||
self.add_session_picker_error(format!("Failed to open session picker: {err}"));
|
||||
self.chat_widget.maybe_send_next_queued_input();
|
||||
Ok(AppRunControl::Continue)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) async fn apply_resume_picker_selection(
|
||||
&mut self,
|
||||
tui: &mut tui::Tui,
|
||||
app_server: &mut AppServerSession,
|
||||
selection: SessionSelection,
|
||||
) -> Result<AppRunControl> {
|
||||
match selection {
|
||||
SessionSelection::Resume(target_session) => {
|
||||
let thread_id = target_session.thread_id;
|
||||
let switching_threads = self.current_displayed_thread_id() != Some(thread_id);
|
||||
if switching_threads {
|
||||
for (id, channel) in &self.thread_event_channels {
|
||||
if let Some(input_state) = channel.store.lock().await.input_state.clone() {
|
||||
self.agents_overview.input_states.insert(*id, input_state);
|
||||
}
|
||||
}
|
||||
if let Some(current_thread_id) = self.current_displayed_thread_id()
|
||||
&& let Some(input_state) = self.chat_widget.capture_thread_input_state()
|
||||
{
|
||||
self.agents_overview
|
||||
.input_states
|
||||
.insert(current_thread_id, input_state);
|
||||
}
|
||||
}
|
||||
if let AppRunControl::Exit(reason) = self
|
||||
.resume_target_session(tui, app_server, target_session)
|
||||
.await?
|
||||
{
|
||||
return Ok(AppRunControl::Exit(reason));
|
||||
}
|
||||
if switching_threads
|
||||
&& self.current_displayed_thread_id() == Some(thread_id)
|
||||
&& let Some(input_state) = self.agents_overview.input_states.remove(&thread_id)
|
||||
{
|
||||
let preserve_in_flight_turn =
|
||||
self.active_turn_id_for_thread(thread_id).await.is_some();
|
||||
self.chat_widget.restore_thread_input_state(
|
||||
Some(input_state),
|
||||
ThreadInputStateRestoreMode {
|
||||
preserve_in_flight_turn,
|
||||
},
|
||||
);
|
||||
}
|
||||
if self.active_thread_id == Some(thread_id)
|
||||
&& self
|
||||
.chat_widget
|
||||
.selected_index_for_present_view(AGENTS_OVERVIEW_VIEW_ID)
|
||||
.is_some()
|
||||
{
|
||||
if let Ok(mut state) = self.agents_overview.view_state.lock() {
|
||||
state.completion = Some(crate::bottom_pane::ViewCompletion::Accepted);
|
||||
}
|
||||
self.chat_widget.pre_draw_tick();
|
||||
}
|
||||
}
|
||||
SessionSelection::Exit
|
||||
| SessionSelection::StartFresh
|
||||
| SessionSelection::AgentsOverview => {
|
||||
self.refresh_in_memory_config_from_disk_best_effort("closing the session picker")
|
||||
.await;
|
||||
}
|
||||
SessionSelection::Fork(_) => {}
|
||||
}
|
||||
|
||||
self.chat_widget.maybe_send_next_queued_input();
|
||||
// Leaving alt-screen may blank the inline viewport; force a redraw either way.
|
||||
tui.frame_requester().schedule_frame();
|
||||
Ok(AppRunControl::Continue)
|
||||
}
|
||||
|
||||
pub(super) fn add_session_picker_error(&mut self, message: String) {
|
||||
if self
|
||||
.chat_widget
|
||||
.selected_index_for_present_view(AGENTS_OVERVIEW_VIEW_ID)
|
||||
.is_some()
|
||||
{
|
||||
self.chat_widget.show_selection_view(SelectionViewParams {
|
||||
title: Some("Unable to resume session".to_string()),
|
||||
subtitle: Some(message.clone()),
|
||||
items: vec![SelectionItem {
|
||||
name: "Return to command center".to_string(),
|
||||
dismiss_on_select: true,
|
||||
..Default::default()
|
||||
}],
|
||||
..Default::default()
|
||||
});
|
||||
}
|
||||
self.chat_widget.add_error_message(message);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user