mirror of
https://github.com/openai/codex.git
synced 2026-11-22 23:00:42 +00:00
Show task loading progress in the docked agent command center (#63146)
## Why The current task can already be visible while initial discovery is still running. Opening a different task can also involve several backend requests, leaving the user waiting without an indication that their selection took effect. ## What changed - Show “Loading additional tasks…” in the footer during initial discovery, with “Loading tasks…” in narrower layouts. - Mark the selected row “Opening…” and show “Opening task…” in the footer during resume, including across backends. Keep the outgoing frame visible until the destination is ready to draw. - Draw the replayed transcript before scanning for loaded subagents, then replay their pending requests. Suppress repeats of the selection key so a held key cannot act on an approval dialog opened during replay. ## Testing Add regression coverage for the discovery footer, cross-backend opening progress and held-key suppression, and replay of a pending subagent request after discovery. GitOrigin-RevId: 7c5088edd620a76c5157919c63566b95ad456664
This commit is contained in:
@@ -35,6 +35,11 @@ impl ActivationKeyGuard {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn extend_for_protected_view(&mut self, now: Instant) {
|
||||
self.legacy_repeat_fallback = true;
|
||||
self.block_until = self.block_until.max(now + INITIAL_GUARD);
|
||||
}
|
||||
|
||||
pub(crate) fn consume(&mut self, key: KeyBinding, kind: KeyEventKind) -> bool {
|
||||
self.consume_at(key, kind, Instant::now())
|
||||
}
|
||||
|
||||
@@ -27,6 +27,13 @@ fn suppresses_activation_until_release_and_bounds_legacy_presses() {
|
||||
));
|
||||
assert!(!guard.is_active());
|
||||
|
||||
let mut guard = ActivationKeyGuard::new_at(key, start, /*reported_repeats_only*/ true);
|
||||
let modal_visible = start + Duration::from_secs(/*secs*/ 5);
|
||||
guard.extend_for_protected_view(modal_visible);
|
||||
assert!(guard.consume_at(key, KeyEventKind::Press, modal_visible));
|
||||
assert!(guard.consume_at(key, KeyEventKind::Release, modal_visible));
|
||||
assert!(!guard.consume_at(key, KeyEventKind::Press, modal_visible));
|
||||
|
||||
let mut guard = ActivationKeyGuard::new_at(
|
||||
key_hint::plain(KeyCode::BackTab),
|
||||
start,
|
||||
|
||||
@@ -4,6 +4,10 @@ use super::hints::hint_line;
|
||||
use super::*;
|
||||
use crate::bottom_pane::render_filled_tab_bar;
|
||||
use crate::line_truncation::truncate_line_with_ellipsis_if_overflow;
|
||||
use crate::motion::LOADING_FRAME_INTERVAL;
|
||||
use crate::motion::loading_glyph_with_delay;
|
||||
use crate::style::accent_style;
|
||||
use crate::style::secondary_text_style;
|
||||
use crossterm::cursor::SetCursorStyle;
|
||||
use ratatui::widgets::WidgetRef;
|
||||
use unicode_segmentation::UnicodeSegmentation;
|
||||
@@ -241,10 +245,43 @@ impl Renderable for AgentsOverviewView {
|
||||
(failed && !state.loading).then(|| "Error loading tasks".to_owned())
|
||||
})
|
||||
.or_else(|| state.server_version_notice.clone());
|
||||
if let Some(notice) = notice.filter(|_| !state.help) {
|
||||
line(notice.dim(), inset(layout.footer), buf);
|
||||
let footer = inset(layout.footer);
|
||||
let progress = if state.help || state.connection_notice.is_some() || footer.is_empty() {
|
||||
None
|
||||
} else if let Some(opening) = state.opening_task {
|
||||
Some(("Opening task…", opening.started_at))
|
||||
} else if self.dock_motion.is_some() && history.is_none() && notice.is_none() {
|
||||
let full_label = "Loading additional tasks…";
|
||||
// Reserve a column each for the spinner and its trailing space.
|
||||
let label = if full_label.width() + 2 <= usize::from(footer.width) {
|
||||
full_label
|
||||
} else {
|
||||
"Loading tasks…"
|
||||
};
|
||||
state
|
||||
.initial_discovery_started_at
|
||||
.map(|started_at| (label, started_at))
|
||||
} else {
|
||||
line(hint_line(&footer_hints), inset(layout.footer), buf);
|
||||
None
|
||||
};
|
||||
if let Some((label, started_at)) = progress {
|
||||
let glyph = self.dock_motion.as_ref().map_or("", |(motion, frames)| {
|
||||
loading_glyph_with_delay(started_at, LOADING_FRAME_INTERVAL, *motion, frames)
|
||||
});
|
||||
let glyph = if glyph.is_empty() { " " } else { glyph };
|
||||
line(
|
||||
vec![
|
||||
Span::styled(glyph, accent_style()),
|
||||
" ".into(),
|
||||
Span::styled(label, secondary_text_style()),
|
||||
],
|
||||
footer,
|
||||
buf,
|
||||
);
|
||||
} else if let Some(notice) = notice.filter(|_| !state.help) {
|
||||
line(notice.dim(), footer, buf);
|
||||
} else {
|
||||
line(hint_line(&footer_hints), footer, buf);
|
||||
}
|
||||
let help = state.help;
|
||||
drop(state);
|
||||
@@ -271,7 +308,11 @@ impl Renderable for AgentsOverviewView {
|
||||
.set_style(Style::default().dim());
|
||||
}
|
||||
}
|
||||
self.render_center_rows(layout.list, buf);
|
||||
self.render_center_rows(
|
||||
layout.list,
|
||||
buf,
|
||||
/*progress_in_footer*/ progress.is_some(),
|
||||
);
|
||||
if !layout.details.is_empty() {
|
||||
self.render_details(layout.details, buf);
|
||||
}
|
||||
|
||||
@@ -36,7 +36,12 @@ fn columns(area: Rect, widths: Option<(u16, u16)>) -> (Rect, Rect, Rect) {
|
||||
}
|
||||
|
||||
impl AgentsOverviewView {
|
||||
pub(super) fn render_center_rows(&self, area: Rect, buf: &mut Buffer) {
|
||||
pub(super) fn render_center_rows(
|
||||
&self,
|
||||
area: Rect,
|
||||
buf: &mut Buffer,
|
||||
progress_in_footer: bool,
|
||||
) {
|
||||
let row_width = area.width;
|
||||
let area = Rect {
|
||||
width: row_width.saturating_sub(/*rhs*/ 1),
|
||||
@@ -58,7 +63,11 @@ impl AgentsOverviewView {
|
||||
} else if state.history.is_some() {
|
||||
"No matching tasks"
|
||||
} else if state.loading && self.rows.is_empty() {
|
||||
"Loading tasks…"
|
||||
if progress_in_footer {
|
||||
""
|
||||
} else {
|
||||
"Loading tasks…"
|
||||
}
|
||||
} else if state.refresh_failed {
|
||||
"Could not load tasks"
|
||||
} else if self.rows.is_empty() {
|
||||
@@ -77,6 +86,16 @@ impl AgentsOverviewView {
|
||||
} else {
|
||||
selection_style()
|
||||
};
|
||||
let opening = state.opening_task.map(|task| task.thread_id);
|
||||
let status_for = |task: &AgentsOverviewRow| {
|
||||
let (status, dot) = Self::status(task);
|
||||
let label = if opening == Some(task.thread_id) {
|
||||
"Opening…"
|
||||
} else {
|
||||
status
|
||||
};
|
||||
(label, dot)
|
||||
};
|
||||
let entries = self.center_rows(&indices, &state);
|
||||
let reference = chrono::Utc::now();
|
||||
let age = |task: &AgentsOverviewRow| {
|
||||
@@ -89,7 +108,7 @@ impl AgentsOverviewView {
|
||||
let mut status_width = "Status".width();
|
||||
let mut updated_width = "Updated".width();
|
||||
for task in indices.iter().filter_map(|&index| self.rows.get(index)) {
|
||||
status_width = status_width.max(Self::status(task).0.width());
|
||||
status_width = status_width.max(status_for(task).0.width());
|
||||
updated_width = updated_width.max(age(task).width());
|
||||
}
|
||||
(status_width.min(11) as u16, updated_width.min(9) as u16)
|
||||
@@ -124,7 +143,7 @@ impl AgentsOverviewView {
|
||||
Style::default().dim()
|
||||
};
|
||||
buf.set_style(background, style);
|
||||
let (status, _) = Self::status(task);
|
||||
let (status, _) = status_for(task);
|
||||
let branch = task
|
||||
.thread
|
||||
.git_info
|
||||
@@ -227,7 +246,7 @@ impl AgentsOverviewView {
|
||||
Style::default()
|
||||
};
|
||||
buf.set_style(background, style);
|
||||
let (status, mut dot) = Self::status(task);
|
||||
let (status, mut dot) = status_for(task);
|
||||
let idle = matches!(
|
||||
task.group,
|
||||
AgentsOverviewGroup::Ready | AgentsOverviewGroup::Finished
|
||||
|
||||
@@ -1149,6 +1149,7 @@ async fn workspace_navigation_preserves_the_draft_and_reading_position() -> Resu
|
||||
origin_url: None,
|
||||
});
|
||||
task.updated_at = 4_000_000_000;
|
||||
app.agents_overview.initialized.insert(server.backend_id());
|
||||
app.agents_overview.threads.insert(id, Some(task));
|
||||
app.agents_overview
|
||||
.pins_by_backend
|
||||
|
||||
@@ -182,7 +182,7 @@ impl App {
|
||||
.view_state
|
||||
.lock()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner);
|
||||
state.loading = false;
|
||||
state.finish_loading();
|
||||
state.connection_notice = Some(if self.reconnect.failed {
|
||||
"Reconnect failed — agent list is stale; relaunch to retry"
|
||||
} else {
|
||||
@@ -241,7 +241,7 @@ impl App {
|
||||
.view_state
|
||||
.lock()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner);
|
||||
state.loading = false;
|
||||
state.finish_loading();
|
||||
state.refresh_failed = self
|
||||
.agents_overview
|
||||
.refresh_failed_backends
|
||||
@@ -476,7 +476,7 @@ impl App {
|
||||
.view_state
|
||||
.lock()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner)
|
||||
.loading = false;
|
||||
.finish_loading();
|
||||
}
|
||||
overview
|
||||
.pending_refresh_backends
|
||||
@@ -750,20 +750,24 @@ impl App {
|
||||
));
|
||||
return Ok(AppRunControl::Continue);
|
||||
};
|
||||
let target = SessionTarget {
|
||||
backend_id: owner,
|
||||
path: thread.path.clone(),
|
||||
thread_id,
|
||||
cwd: Some(thread.cwd.to_path_buf()),
|
||||
history_mode: Some(thread.history_mode),
|
||||
};
|
||||
self.paint_docked_task_opening(tui, thread_id)?;
|
||||
self.app_event_tx
|
||||
.send(AppEvent::ResumeBackendSession(SessionTarget {
|
||||
backend_id: owner,
|
||||
path: thread.path.clone(),
|
||||
thread_id,
|
||||
cwd: Some(thread.cwd.to_path_buf()),
|
||||
history_mode: Some(thread.history_mode),
|
||||
}));
|
||||
.send(AppEvent::ResumeBackendSession(target));
|
||||
return Ok(AppRunControl::Continue);
|
||||
}
|
||||
Box::pin(self.attach_agents_overview_thread(
|
||||
let result = crate::boxed_future!(self.attach_agents_overview_thread(
|
||||
tui, app_server, thread_id, /*started*/ None, /*startup_draft*/ None,
|
||||
))
|
||||
.await
|
||||
.await;
|
||||
self.finish_docked_task_opening(tui, thread_id);
|
||||
result
|
||||
}
|
||||
|
||||
fn redraw_during_task_attach(&mut self, tui: &mut tui::Tui) -> Result<()> {
|
||||
@@ -802,9 +806,14 @@ impl App {
|
||||
if self.reject_pending_permission_root_switch() {
|
||||
return Ok(AppRunControl::Continue);
|
||||
}
|
||||
if startup_draft.is_none() && !self.agents_overview.workspace.is_open() {
|
||||
let docked_resume =
|
||||
!is_new_session && self.agents_overview.workspace.is_open() && tui.is_owned_screen();
|
||||
if docked_resume {
|
||||
self.paint_docked_task_opening(tui, root_thread_id)?;
|
||||
} else if startup_draft.is_none() && !self.agents_overview.workspace.is_open() {
|
||||
loading::draw(tui)?;
|
||||
}
|
||||
let mut backfill_after_replay = false;
|
||||
let mut restored_blank_session = false;
|
||||
let mut resumed_mode = None;
|
||||
let mut provider_resume_checked = false;
|
||||
@@ -867,13 +876,14 @@ impl App {
|
||||
.insert(active_thread_id, input_state);
|
||||
}
|
||||
|
||||
let target_thread = match StartupDraftPump::run_with_optional_draft(
|
||||
startup_draft.as_deref_mut(),
|
||||
tui,
|
||||
app_server.thread_read(root_thread_id, /*include_turns*/ false),
|
||||
)
|
||||
.await
|
||||
{
|
||||
let thread_read = app_server.thread_read(root_thread_id, /*include_turns*/ false);
|
||||
let read_result = match startup_draft.as_deref_mut() {
|
||||
Some(draft) => {
|
||||
StartupDraftPump::run_with_optional_draft(Some(draft), tui, thread_read).await
|
||||
}
|
||||
None => self.wait_for_opening_task(tui, thread_read).await,
|
||||
};
|
||||
let target_thread = match read_result {
|
||||
Ok(thread) => thread,
|
||||
Err(error) => {
|
||||
self.add_agents_overview_error(format!(
|
||||
@@ -1009,22 +1019,23 @@ impl App {
|
||||
let (resumed, read_only) = if let Some((_, started)) = started {
|
||||
(started, None)
|
||||
} else if let Some(blank) = self
|
||||
.live_blank_session(app_server, root_thread_id, &target_thread)
|
||||
.live_blank_session(tui, app_server, root_thread_id, &target_thread)
|
||||
.await
|
||||
{
|
||||
restored_blank_session = true;
|
||||
(blank, None)
|
||||
} else {
|
||||
match app_server
|
||||
.resume_thread_with_permission_overrides(
|
||||
// The progress loop holds the request while attaching the destination.
|
||||
// Box the large resume future to keep the attach stack bounded.
|
||||
let resume =
|
||||
crate::boxed_future!(app_server.resume_thread_with_permission_overrides(
|
||||
&local_settings,
|
||||
resume_config.clone(),
|
||||
root_thread_id,
|
||||
resume_model_settings,
|
||||
self.resume_permission_overrides(&resume_config),
|
||||
)
|
||||
.await
|
||||
{
|
||||
));
|
||||
match self.wait_for_opening_task(tui, resume).await {
|
||||
Ok(resumed) => {
|
||||
provider_resume_checked = true;
|
||||
resumed_mode = Some(resumed.session.collaboration_mode.is_some());
|
||||
@@ -1043,14 +1054,12 @@ impl App {
|
||||
} else {
|
||||
ReadOnlyThread::ExternalWriter
|
||||
};
|
||||
match app_server
|
||||
.read_thread_for_viewing(
|
||||
&resume_config,
|
||||
&local_settings,
|
||||
root_thread_id,
|
||||
)
|
||||
.await
|
||||
{
|
||||
let history = crate::boxed_future!(app_server.read_thread_for_viewing(
|
||||
&resume_config,
|
||||
&local_settings,
|
||||
root_thread_id,
|
||||
));
|
||||
match self.wait_for_opening_task(tui, history).await {
|
||||
Ok((thread, notice)) => {
|
||||
history_notice = notice;
|
||||
(thread, Some(reason))
|
||||
@@ -1140,13 +1149,13 @@ impl App {
|
||||
);
|
||||
self.file_search
|
||||
.update_search_dir(self.config.cwd.to_path_buf());
|
||||
if let Err(error) = self
|
||||
.replace_chat_widget_with_app_server_thread(
|
||||
if let Err(error) =
|
||||
crate::boxed_future!(self.replace_chat_widget_with_app_server_thread(
|
||||
tui,
|
||||
resumed,
|
||||
presentation,
|
||||
/*initial_user_message*/ None,
|
||||
)
|
||||
))
|
||||
.await
|
||||
{
|
||||
self.add_agents_overview_error(format!("Failed to attach to task: {error}"));
|
||||
@@ -1173,8 +1182,8 @@ impl App {
|
||||
self.chat_widget
|
||||
.add_info_message(notice.to_string(), /*hint*/ None);
|
||||
}
|
||||
// Widget replacement clears the terminal. Paint the destination before further waits.
|
||||
if startup_draft.is_none() {
|
||||
// The dock keeps the outgoing frame until replay has populated the destination.
|
||||
if startup_draft.is_none() && !docked_resume {
|
||||
self.redraw_during_task_attach(tui)?;
|
||||
}
|
||||
let mut destination_config = self.chat_widget.config_ref().clone();
|
||||
@@ -1215,13 +1224,16 @@ impl App {
|
||||
}
|
||||
// A new session has no descendants. Scanning every loaded thread here
|
||||
// adds a serial round trip per agent before the composer can render.
|
||||
if !is_new_session
|
||||
&& !self
|
||||
if !is_new_session {
|
||||
if docked_resume {
|
||||
backfill_after_replay = true;
|
||||
} else if !self
|
||||
.backfill_loaded_subagent_threads(app_server)
|
||||
.await
|
||||
.completed
|
||||
{
|
||||
self.backfill_loaded_subagent_threads(app_server).await;
|
||||
{
|
||||
self.backfill_loaded_subagent_threads(app_server).await;
|
||||
}
|
||||
}
|
||||
for thread_id in previous_thread_ids {
|
||||
if previous_running_thread_ids.is_empty()
|
||||
@@ -1245,8 +1257,7 @@ impl App {
|
||||
if self.current_displayed_thread_id() != Some(root_thread_id)
|
||||
|| (self.thread_unavailable(root_thread_id) && !self.chat_widget.is_read_only_view())
|
||||
{
|
||||
self.select_agent_thread(tui, app_server, root_thread_id)
|
||||
.await?;
|
||||
crate::boxed_future!(self.select_agent_thread(tui, app_server, root_thread_id)).await?;
|
||||
}
|
||||
if self.current_displayed_thread_id() == Some(root_thread_id) {
|
||||
self.remember_attached_host_project(app_server);
|
||||
@@ -1279,6 +1290,12 @@ impl App {
|
||||
.await;
|
||||
}
|
||||
|
||||
if backfill_after_replay {
|
||||
self.app_event_tx.send(AppEvent::BackfillResumedSubagents {
|
||||
thread_id: root_thread_id,
|
||||
backend_id: app_server.backend_id(),
|
||||
});
|
||||
}
|
||||
Ok(AppRunControl::Continue)
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,76 @@ use tokio::net::TcpListener;
|
||||
use tokio::sync::mpsc;
|
||||
use tokio_tungstenite::tungstenite::Message;
|
||||
|
||||
#[tokio::test]
|
||||
async fn deferred_subagent_backfill_replays_parked_request() -> Result<()> {
|
||||
let mut app = make_test_app().await;
|
||||
let root_id = ThreadId::new();
|
||||
attach_thread(&mut app, root_id);
|
||||
app.primary_thread_id = Some(root_id);
|
||||
app.active_thread_id = Some(root_id);
|
||||
let child_id = ThreadId::new();
|
||||
let backend_id = BackendId::new();
|
||||
let (mut cloud, mut commands, _events) =
|
||||
overview_session_stub(backend_id, ThreadParamsMode::Cloud);
|
||||
let child = overview_thread(child_id, Some(root_id), "Child task", ThreadStatus::Idle);
|
||||
let request = ServerRequest::ToolRequestUserInput {
|
||||
request_id: RequestId::Integer(42),
|
||||
params: ToolRequestUserInputParams {
|
||||
thread_id: child_id.to_string(),
|
||||
turn_id: "turn".into(),
|
||||
item_id: "question".into(),
|
||||
questions: Vec::new(),
|
||||
is_blocking: true,
|
||||
auto_resolution_ms: None,
|
||||
},
|
||||
};
|
||||
app.agents_overview.dispatched_requests.insert(
|
||||
child_id,
|
||||
vec![BufferedServerRequest::new(
|
||||
request.clone(),
|
||||
&cloud.request_handle(),
|
||||
)],
|
||||
);
|
||||
app.replay_agents_overview_requests(&cloud, root_id).await;
|
||||
assert!(
|
||||
app.agents_overview
|
||||
.dispatched_requests
|
||||
.contains_key(&child_id)
|
||||
);
|
||||
|
||||
let serve_backfill = async {
|
||||
let list = commands.recv().await.expect("loaded thread list request");
|
||||
assert!(matches!(list.operation, CloudOperation::Request(request)
|
||||
if matches!(request.as_ref(), ClientRequest::ThreadLoadedList { .. })));
|
||||
list.response
|
||||
.send(Ok(Ok(json!({"data": [child_id], "nextCursor": null}))))
|
||||
.unwrap();
|
||||
let read = commands.recv().await.expect("child thread read request");
|
||||
assert!(matches!(read.operation, CloudOperation::Request(request)
|
||||
if matches!(request.as_ref(), ClientRequest::ThreadRead { params, .. }
|
||||
if params.thread_id == child.id && !params.include_turns)));
|
||||
read.response
|
||||
.send(Ok(Ok(json!({"thread": child, "readState": null}))))
|
||||
.unwrap();
|
||||
};
|
||||
let mut tui = crate::tui::test_support::make_test_tui()?;
|
||||
let backfill = crate::boxed_future!(app.handle_event(
|
||||
&mut tui,
|
||||
&mut cloud,
|
||||
AppEvent::BackfillResumedSubagents {
|
||||
thread_id: root_id,
|
||||
backend_id
|
||||
},
|
||||
));
|
||||
let (result, ()) = tokio::join!(backfill, serve_backfill);
|
||||
result?;
|
||||
assert!(
|
||||
app.pending_app_server_requests
|
||||
.contains_server_request(&request)
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn overview_refresh_grows_visible_history_and_preserves_the_show_more_cursor() {
|
||||
let (client, mut commands, _events) = CloudClient::channel(/*capacity*/ 1);
|
||||
@@ -135,8 +205,10 @@ async fn overview_return_to_current_chat_cancels_the_cloud_list_and_allows_reope
|
||||
.unwrap();
|
||||
next_cloud_page(commands, /*cursor*/ None).await
|
||||
};
|
||||
let mut tui = crate::tui::test_support::make_test_tui()?;
|
||||
let size = Size::new(/*width*/ 115, /*height*/ 12);
|
||||
let mut tui = crate::tui::test_support::make_test_tui_with_size(size)?;
|
||||
crate::app::test_support::enable_side_retention(&mut app)?;
|
||||
app.local_settings.tui.animations = false;
|
||||
tui.set_owned_screen(/*owned*/ true)?;
|
||||
for key in [KeyCode::Esc, KeyCode::Enter] {
|
||||
if key == KeyCode::Enter {
|
||||
@@ -145,6 +217,27 @@ async fn overview_return_to_current_chat_cancels_the_cloud_list_and_allows_reope
|
||||
}
|
||||
app.open_agents_overview(&cloud);
|
||||
let held_list = tokio::time::timeout(timeout, next_list(&mut commands)).await?;
|
||||
if key == KeyCode::Esc {
|
||||
let frame = crate::app::test_support::side_frame(&mut app, &mut tui, size)?;
|
||||
let screen = frame
|
||||
.lines()
|
||||
.filter_map(|row| row.split_once('│').map(|(left, _)| left.trim_end()))
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n")
|
||||
.replace(&test_path_display("/tmp/project"), "/tmp/project");
|
||||
insta::assert_snapshot!("initial_discovery_with_current_task", screen);
|
||||
let view = app.agents_overview.workspace.view.as_ref().unwrap();
|
||||
let footers = [30, 31].map(|width| {
|
||||
super::command_center::screen(view, width, size.height)
|
||||
.lines()
|
||||
.last()
|
||||
.unwrap()
|
||||
.trim()
|
||||
.to_string()
|
||||
});
|
||||
assert_eq!(footers, ["◌ Loading tasks…", "◌ Loading additional tasks…"]);
|
||||
assert_eq!(app.overview_selected_thread_id(), Some(thread_id));
|
||||
}
|
||||
Box::pin(app.handle_tui_event(&mut tui, &mut cloud, TuiEvent::Key(key.into()))).await?;
|
||||
if key == KeyCode::Enter {
|
||||
tokio::time::timeout(timeout, async {
|
||||
@@ -169,6 +262,7 @@ async fn overview_return_to_current_chat_cancels_the_cloud_list_and_allows_reope
|
||||
// The previous archive was observed, but its unarchive notification was missed.
|
||||
app.agents_overview.threads.remove(&thread_id);
|
||||
app.agents_overview.removed_threads.insert(thread_id);
|
||||
crate::app::test_support::enable_side_retention(&mut app)?;
|
||||
app.open_agents_overview(&cloud);
|
||||
let reopened = tokio::time::timeout(timeout, next_list(&mut commands)).await?;
|
||||
let mut listed = current.clone();
|
||||
@@ -210,7 +304,11 @@ async fn overview_return_to_current_chat_cancels_the_cloud_list_and_allows_reope
|
||||
)))
|
||||
.unwrap();
|
||||
finish_overview_refresh(&mut app, &cloud, &mut events).await;
|
||||
assert!(app.chat_widget.active_view_is(AGENTS_OVERVIEW_VIEW_ID));
|
||||
let screen = crate::app::test_support::side_frame(&mut app, &mut tui, size)?;
|
||||
assert!(!screen.contains("Loading tasks"));
|
||||
assert!(!screen.contains("Loading additional tasks"));
|
||||
assert!(screen.contains("? help esc back"));
|
||||
assert_eq!(app.overview_selected_thread_id(), Some(thread_id));
|
||||
assert!(!app.agents_overview.refresh_failed_backends.contains(&owner));
|
||||
assert_eq!(
|
||||
app.agents_overview.threads[&thread_id],
|
||||
|
||||
@@ -1,10 +1,90 @@
|
||||
//! Transient feedback while command-center selection waits for a session to load.
|
||||
//! Draw directly because the app event handler cannot process scheduled frames while awaiting.
|
||||
//! Repaint directly during backend waits because the app event handler owns the event loop.
|
||||
|
||||
use super::App;
|
||||
use crate::app::agents_overview_view::OpeningTask;
|
||||
use crate::motion::LOADING_FRAME_INTERVAL;
|
||||
use crate::tui::Tui;
|
||||
use codex_protocol::ThreadId;
|
||||
use color_eyre::Result;
|
||||
use ratatui::style::Stylize;
|
||||
use ratatui::text::Line;
|
||||
use ratatui::widgets::Paragraph;
|
||||
use std::future::Future;
|
||||
use std::time::Instant;
|
||||
|
||||
impl App {
|
||||
pub(super) fn paint_docked_task_opening(
|
||||
&mut self,
|
||||
tui: &mut Tui,
|
||||
thread_id: ThreadId,
|
||||
) -> Result<()> {
|
||||
if self.agents_overview.workspace.is_open() && tui.is_owned_screen() {
|
||||
if let Ok(mut state) = self.agents_overview.view_state.lock() {
|
||||
state.opening_task = Some(OpeningTask {
|
||||
thread_id,
|
||||
started_at: Instant::now(),
|
||||
});
|
||||
}
|
||||
// This handler awaits the backend, so a scheduled draw alone cannot show feedback.
|
||||
if let Err(error) = self.refresh_owned_transcript(tui) {
|
||||
self.finish_docked_task_opening(tui, thread_id);
|
||||
return Err(error);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(in crate::app) fn docked_task_opening(&self, tui: &Tui) -> bool {
|
||||
tui.is_owned_screen()
|
||||
&& self
|
||||
.agents_overview
|
||||
.view_state
|
||||
.lock()
|
||||
.is_ok_and(|state| state.opening_task.is_some())
|
||||
}
|
||||
|
||||
pub(in crate::app) fn finish_docked_task_opening(
|
||||
&mut self,
|
||||
tui: &Tui,
|
||||
thread_id: ThreadId,
|
||||
) -> bool {
|
||||
if let Ok(mut state) = self.agents_overview.view_state.lock()
|
||||
&& state
|
||||
.opening_task
|
||||
.is_some_and(|opening| opening.thread_id == thread_id)
|
||||
{
|
||||
state.opening_task = None;
|
||||
tui.frame_requester().schedule_frame();
|
||||
return true;
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
pub(in crate::app) async fn wait_for_opening_task<T>(
|
||||
&mut self,
|
||||
tui: &mut Tui,
|
||||
request: impl Future<Output = T>,
|
||||
) -> T {
|
||||
if !self.local_settings.tui.animations || !self.docked_task_opening(tui) {
|
||||
return request.await;
|
||||
}
|
||||
tokio::pin!(request);
|
||||
loop {
|
||||
tokio::select! {
|
||||
biased;
|
||||
result = &mut request => return result,
|
||||
_ = tokio::time::sleep(LOADING_FRAME_INTERVAL) => {
|
||||
if let Err(error) = self.refresh_owned_transcript(tui) {
|
||||
tracing::warn!(%error, "failed to update task opening progress");
|
||||
// The request may already have changed the backend attachment.
|
||||
return request.await;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn draw(tui: &mut Tui) -> std::io::Result<()> {
|
||||
tui.draw(u16::MAX, |frame| {
|
||||
|
||||
@@ -429,11 +429,15 @@ impl App {
|
||||
}
|
||||
}
|
||||
let app_event_tx = self.app_event_tx.clone();
|
||||
self.agents_overview
|
||||
.view_state
|
||||
.lock()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner)
|
||||
.loading = discover && !refresh_recent;
|
||||
{
|
||||
let mut state = self
|
||||
.agents_overview
|
||||
.view_state
|
||||
.lock()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner);
|
||||
state.loading = discover && !refresh_recent;
|
||||
state.initial_discovery_started_at = (!initialized).then(std::time::Instant::now);
|
||||
}
|
||||
let refresh_task = tokio::spawn(async move {
|
||||
let result = async {
|
||||
let mut threads = HashMap::new();
|
||||
|
||||
@@ -66,6 +66,7 @@ use std::sync::Arc;
|
||||
use std::sync::Mutex;
|
||||
use std::sync::MutexGuard;
|
||||
use std::sync::PoisonError;
|
||||
use std::time::Instant;
|
||||
use unicode_width::UnicodeWidthStr;
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
|
||||
@@ -167,6 +168,12 @@ enum RowTarget {
|
||||
ShowMore,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub(super) struct OpeningTask {
|
||||
pub(super) thread_id: ThreadId,
|
||||
pub(super) started_at: Instant,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub(super) struct AgentsOverviewViewState {
|
||||
row_hits: Vec<(RowTarget, Rect)>,
|
||||
@@ -180,7 +187,9 @@ pub(super) struct AgentsOverviewViewState {
|
||||
pub(super) creating_worktree: bool,
|
||||
pub(super) refresh_failed: bool,
|
||||
pub(super) loading: bool,
|
||||
pub(super) initial_discovery_started_at: Option<Instant>,
|
||||
pub(super) has_more: bool,
|
||||
pub(super) opening_task: Option<OpeningTask>,
|
||||
show_more_selected: bool,
|
||||
pub(super) connection_notice: Option<&'static str>,
|
||||
/// Browse only while the server holds its lifecycle lock.
|
||||
@@ -197,6 +206,11 @@ pub(super) struct AgentsOverviewViewState {
|
||||
}
|
||||
|
||||
impl AgentsOverviewViewState {
|
||||
pub(super) fn finish_loading(&mut self) {
|
||||
self.loading = false;
|
||||
self.initial_discovery_started_at = None;
|
||||
}
|
||||
|
||||
pub(super) fn set_rename_input(&mut self, text: &str, keymap: &RuntimeKeymap) {
|
||||
let mut input = TextArea::new_single_line();
|
||||
input.set_keymap_bindings(keymap);
|
||||
@@ -236,6 +250,7 @@ impl AgentsOverviewViewState {
|
||||
}
|
||||
|
||||
pub(super) struct AgentsOverviewView {
|
||||
pub(super) dock_motion: Option<(crate::motion::MotionMode, crate::tui::FrameRequester)>,
|
||||
/// Some when shown beside the conversation. The value records keyboard focus.
|
||||
pub(super) dock_focused: Option<bool>,
|
||||
use_theme_colors: bool,
|
||||
@@ -316,6 +331,7 @@ impl AgentsOverviewView {
|
||||
}
|
||||
}
|
||||
let mut view = Self {
|
||||
dock_motion: None,
|
||||
dock_focused: None,
|
||||
editor_keymap: keymap.clone(),
|
||||
use_theme_colors,
|
||||
|
||||
@@ -630,7 +630,10 @@ impl App {
|
||||
};
|
||||
let destination = backends.session_at_mut(destination_slot);
|
||||
self.cancel_cloud_inventory_refresh(destination).await;
|
||||
let bootstrap = match destination.bootstrap(&settings.config).await {
|
||||
let bootstrap = match self
|
||||
.wait_for_opening_task(tui, destination.bootstrap(&settings.config))
|
||||
.await
|
||||
{
|
||||
Ok(bootstrap) => bootstrap,
|
||||
Err(error) => {
|
||||
let message = format!("Failed to prepare the conversation: {error}");
|
||||
|
||||
@@ -211,6 +211,18 @@ impl App {
|
||||
.send(AppEvent::Exit(ExitMode::ShutdownFirst));
|
||||
}
|
||||
} else {
|
||||
// The destination widget inherits this guard, including during a slow resume.
|
||||
if self.keymap.list.action_for(key) == Some(crate::keymap::ListAction::Accept) {
|
||||
let activation = self
|
||||
.routed_key_activation
|
||||
.take()
|
||||
.unwrap_or_else(|| crate::key_hint::KeyBinding::from_event(key));
|
||||
self.chat_widget.suppress_current_view_key_until_release(
|
||||
activation,
|
||||
std::time::Instant::now(),
|
||||
crate::activation_key_guard::ActivationKeySuppression::ReportedRepeats,
|
||||
);
|
||||
}
|
||||
view.handle_key_event(key);
|
||||
}
|
||||
if view.is_complete() {
|
||||
@@ -305,6 +317,7 @@ impl App {
|
||||
frame: &mut crate::custom_terminal::Frame<'_>,
|
||||
center: Rect,
|
||||
conversation: Option<Rect>,
|
||||
frames: &crate::tui::FrameRequester,
|
||||
) {
|
||||
let center_focused = self.workspace_center_owns_input();
|
||||
frame
|
||||
@@ -316,6 +329,12 @@ impl App {
|
||||
let area = center;
|
||||
if let Some(view) = &mut self.agents_overview.workspace.view {
|
||||
view.dock_focused = conversation.map(|_| center_focused);
|
||||
view.dock_motion = Some((
|
||||
crate::motion::MotionMode::from_animations_enabled(
|
||||
self.local_settings.tui.animations,
|
||||
),
|
||||
frames.clone(),
|
||||
));
|
||||
view.render(area, frame.buffer);
|
||||
if center_focused {
|
||||
frame.cursor_position = view.cursor_pos(area).map(Into::into);
|
||||
|
||||
@@ -3469,10 +3469,7 @@ impl App {
|
||||
AppEvent::SelectAgentsOverviewThread { thread_id }
|
||||
if self.agents_overview.pending_archives.contains_key(&thread_id) => {}
|
||||
AppEvent::SelectAgentsOverviewThread { thread_id } => {
|
||||
match self
|
||||
.select_agents_overview_thread(tui, app_server, thread_id)
|
||||
.await?
|
||||
{
|
||||
match crate::boxed_future!(self.select_agents_overview_thread(tui, app_server, thread_id)).await? {
|
||||
AppRunControl::Continue
|
||||
if self.primary_thread_id.is_none()
|
||||
&& self.overview_selected_index().is_none() => {
|
||||
@@ -3488,6 +3485,25 @@ impl App {
|
||||
AppRunControl::Exit(reason) => return Ok(AppRunControl::Exit(reason)),
|
||||
}
|
||||
}
|
||||
AppEvent::BackfillResumedSubagents { thread_id, backend_id } => {
|
||||
if self.primary_thread_id == Some(thread_id) && app_server.backend_id() == backend_id {
|
||||
// Earlier replay events have populated the destination's transcript.
|
||||
self.refresh_owned_transcript(tui)?;
|
||||
if !crate::boxed_future!(self.backfill_loaded_subagent_threads(app_server)).await.completed {
|
||||
crate::boxed_future!(self.backfill_loaded_subagent_threads(app_server)).await;
|
||||
}
|
||||
// The scan may outlast the press-only guard window.
|
||||
if self.startup_protected_input_boundary && self.chat_widget.has_active_modal() {
|
||||
self.discard_startup_modal_input(tui)?;
|
||||
}
|
||||
if !self.chat_widget.is_read_only_view() {
|
||||
// Backfill makes parked child requests eligible for replay.
|
||||
// The event loop paints and protects any newly opened modal.
|
||||
crate::boxed_future!(self.replay_agents_overview_requests(app_server, thread_id)).await;
|
||||
}
|
||||
tui.frame_requester().schedule_frame();
|
||||
}
|
||||
}
|
||||
AppEvent::ForkAgentsOverviewThread { thread_id } => {
|
||||
if self.reconnect.offline {
|
||||
return Ok(AppRunControl::Continue);
|
||||
@@ -3502,7 +3518,7 @@ impl App {
|
||||
}
|
||||
// Attachment replay must not submit queued input on the source task.
|
||||
self.chat_widget.fork_in_progress = true;
|
||||
let control = self.select_agents_overview_thread(tui, app_server, thread_id).await;
|
||||
let control = crate::boxed_future!(self.select_agents_overview_thread(tui, app_server, thread_id)).await;
|
||||
if matches!(&control, Ok(AppRunControl::Continue))
|
||||
&& self.current_displayed_thread_id() == Some(thread_id)
|
||||
{
|
||||
|
||||
@@ -655,7 +655,7 @@ impl App {
|
||||
super::link_hover::paint_hover_foreground(area, frame.buffer);
|
||||
}
|
||||
if let Some(center) = center {
|
||||
self.paint_command_center(frame, center, available);
|
||||
self.paint_command_center(frame, center, available, &frames);
|
||||
}
|
||||
self.paint_centered_dialog(frame);
|
||||
})?;
|
||||
|
||||
@@ -180,15 +180,17 @@ impl App {
|
||||
}
|
||||
let resumed_thread = if matches!(target, AppServerTarget::LocalDaemon { .. }) {
|
||||
Some(
|
||||
app_server
|
||||
.thread_read(target_session.thread_id, /*include_turns*/ false)
|
||||
.await
|
||||
.map_err(|error| {
|
||||
self.add_session_picker_error(format!(
|
||||
"Unable to check resumed folder: {error}"
|
||||
));
|
||||
AppRunControl::Continue
|
||||
})?,
|
||||
self.wait_for_opening_task(
|
||||
tui,
|
||||
app_server.thread_read(target_session.thread_id, /*include_turns*/ false),
|
||||
)
|
||||
.await
|
||||
.map_err(|error| {
|
||||
self.add_session_picker_error(format!(
|
||||
"Unable to check resumed folder: {error}"
|
||||
));
|
||||
AppRunControl::Continue
|
||||
})?,
|
||||
)
|
||||
} else {
|
||||
None
|
||||
|
||||
@@ -47,6 +47,7 @@ impl App {
|
||||
|
||||
pub(super) async fn live_blank_session(
|
||||
&mut self,
|
||||
tui: &mut tui::Tui,
|
||||
app_server: &mut AppServerSession,
|
||||
thread_id: ThreadId,
|
||||
thread: &codex_app_server_protocol::Thread,
|
||||
@@ -62,7 +63,9 @@ impl App {
|
||||
codex_app_server_protocol::ThreadHistoryMode::Paginated
|
||||
) && app_server.supports_paginated_history();
|
||||
let untouched = if paginated {
|
||||
match app_server.thread_turns_page(thread_id, /*cursor*/ None, /*limit*/ 1).await {
|
||||
let page =
|
||||
app_server.thread_turns_page(thread_id, /*cursor*/ None, /*limit*/ 1);
|
||||
match self.wait_for_opening_task(tui, page).await {
|
||||
Ok(page) => Some(page.data.is_empty() && page.next_cursor.is_none()),
|
||||
Err(error) if Self::can_fallback_from_include_turns_error(&error) => Some(true),
|
||||
Err(error) if error.chain().any(|cause| matches!(
|
||||
@@ -77,8 +80,11 @@ impl App {
|
||||
};
|
||||
let untouched = match untouched {
|
||||
Some(untouched) => untouched,
|
||||
None => match app_server
|
||||
.thread_read(thread_id, /*include_turns*/ true)
|
||||
None => match self
|
||||
.wait_for_opening_task(
|
||||
tui,
|
||||
app_server.thread_read(thread_id, /*include_turns*/ true),
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(thread) => {
|
||||
@@ -145,11 +151,14 @@ impl App {
|
||||
let live_blank = if matches!(source, ResumeSource::Backend(_))
|
||||
&& self.backend_registry.owner(thread_id) == Some(app_server.backend_id())
|
||||
&& self.agents_overview.blank_sessions.contains_key(&thread_id)
|
||||
&& let Ok(thread) = app_server
|
||||
.thread_read(thread_id, /*include_turns*/ false)
|
||||
&& let Ok(thread) = self
|
||||
.wait_for_opening_task(
|
||||
tui,
|
||||
app_server.thread_read(thread_id, /*include_turns*/ false),
|
||||
)
|
||||
.await
|
||||
{
|
||||
self.live_blank_session(app_server, thread_id, &thread)
|
||||
self.live_blank_session(tui, app_server, thread_id, &thread)
|
||||
.await
|
||||
} else {
|
||||
None
|
||||
@@ -158,15 +167,14 @@ impl App {
|
||||
let resumed = match live_blank {
|
||||
Some(thread) => Ok(thread),
|
||||
None => {
|
||||
app_server
|
||||
.resume_thread_for_navigation(
|
||||
&local_settings,
|
||||
resume_config.clone(),
|
||||
thread_id,
|
||||
model_settings,
|
||||
permission_overrides,
|
||||
)
|
||||
.await
|
||||
let resume = crate::boxed_future!(app_server.resume_thread_for_navigation(
|
||||
&local_settings,
|
||||
resume_config.clone(),
|
||||
thread_id,
|
||||
model_settings,
|
||||
permission_overrides,
|
||||
));
|
||||
self.wait_for_opening_task(tui, resume).await
|
||||
}
|
||||
};
|
||||
let mut history_notice = None;
|
||||
@@ -178,14 +186,12 @@ impl App {
|
||||
|| crate::app_server_session::model_provider_error(&err).is_some() =>
|
||||
{
|
||||
provider_error = crate::app_server_session::model_provider_error(&err);
|
||||
match app_server
|
||||
.read_thread_for_viewing(
|
||||
&resume_config,
|
||||
&local_settings,
|
||||
target_session.thread_id,
|
||||
)
|
||||
.await
|
||||
{
|
||||
let history = crate::boxed_future!(app_server.read_thread_for_viewing(
|
||||
&resume_config,
|
||||
&local_settings,
|
||||
target_session.thread_id,
|
||||
));
|
||||
match self.wait_for_opening_task(tui, history).await {
|
||||
Ok((thread, notice)) => {
|
||||
history_notice = notice;
|
||||
(thread, true)
|
||||
|
||||
@@ -37,7 +37,7 @@ pub(super) enum ThreadAttachPresentation {
|
||||
/// A fresh thread whose startup composer is already visible.
|
||||
FreshWithDraft,
|
||||
SessionLineage,
|
||||
/// A resume whose outgoing events were drained and terminal cleared before capture.
|
||||
/// Outgoing events were drained and the terminal handoff prepared before capture.
|
||||
SessionLineageAfterClear,
|
||||
}
|
||||
|
||||
@@ -1009,10 +1009,13 @@ impl App {
|
||||
.get(&self.side_pair_key(id)?)
|
||||
.map(|side| side.parent_thread_id)
|
||||
};
|
||||
let docked_resume = self.docked_task_opening(tui);
|
||||
let preserve_screen = retain_side_view
|
||||
&& side_parent(thread_id).is_some_and(|parent| {
|
||||
self.chat_widget.thread_id().and_then(side_parent) == Some(parent)
|
||||
});
|
||||
&& (docked_resume
|
||||
|| side_parent(thread_id).is_some_and(|parent| {
|
||||
self.chat_widget.thread_id().and_then(side_parent) == Some(parent)
|
||||
}));
|
||||
self.startup_protected_input_boundary |= docked_resume;
|
||||
let mut init = self.chatwidget_init_for_forked_or_resumed_thread(
|
||||
tui,
|
||||
self.config.clone(),
|
||||
@@ -1752,6 +1755,15 @@ impl App {
|
||||
self.refresh_transcript_document_links();
|
||||
self.reset_transcript_state_after_clear();
|
||||
tui.clear_pending_history_lines();
|
||||
let docked_resume = matches!(
|
||||
presentation,
|
||||
ThreadAttachPresentation::SessionLineage
|
||||
| ThreadAttachPresentation::SessionLineageAfterClear
|
||||
) && self.docked_task_opening(tui);
|
||||
// Replayed approvals need the same first-frame input quarantine as startup.
|
||||
self.startup_protected_input_boundary |= docked_resume;
|
||||
let preserve_screen =
|
||||
docked_resume || matches!(presentation, ThreadAttachPresentation::FreshWithDraft);
|
||||
let presentation = match presentation {
|
||||
ThreadAttachPresentation::FreshAfterClear => ThreadAttachPresentation::Fresh,
|
||||
ThreadAttachPresentation::SessionLineageAfterClear => {
|
||||
@@ -1762,18 +1774,18 @@ impl App {
|
||||
presentation
|
||||
}
|
||||
ThreadAttachPresentation::Fresh | ThreadAttachPresentation::SessionLineage => {
|
||||
tui.clear_for_thread_switch()?;
|
||||
if !docked_resume {
|
||||
tui.clear_for_thread_switch()?;
|
||||
}
|
||||
presentation
|
||||
}
|
||||
};
|
||||
self.pending_thread_switch_resets += 1;
|
||||
self.app_event_tx.send(
|
||||
if matches!(presentation, ThreadAttachPresentation::FreshWithDraft) {
|
||||
AppEvent::ResetTranscriptForThreadSwitchPreservingScreen
|
||||
} else {
|
||||
AppEvent::ResetTranscriptForThreadSwitch
|
||||
},
|
||||
);
|
||||
self.app_event_tx.send(if preserve_screen {
|
||||
AppEvent::ResetTranscriptForThreadSwitchPreservingScreen
|
||||
} else {
|
||||
AppEvent::ResetTranscriptForThreadSwitch
|
||||
});
|
||||
self.reset_thread_event_state().await;
|
||||
let mut init = self.chatwidget_init_for_forked_or_resumed_thread(
|
||||
tui,
|
||||
@@ -2028,8 +2040,10 @@ impl App {
|
||||
handoff: std::sync::Arc<()>,
|
||||
) -> Result<std::sync::Arc<()>> {
|
||||
self.drain_outgoing_thread_events().await;
|
||||
// Keep the outgoing receiver and session in place if the terminal clear fails.
|
||||
if let Err(error) = tui.clear_for_thread_switch() {
|
||||
// A docked open keeps the outgoing frame until the synchronized destination draw.
|
||||
if !self.docked_task_opening(tui)
|
||||
&& let Err(error) = tui.clear_for_thread_switch()
|
||||
{
|
||||
drop(handoff);
|
||||
self.chat_widget.maybe_send_next_queued_input();
|
||||
return Err(error.into());
|
||||
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
---
|
||||
source: tui/src/app/agents_overview_discovery_tests.rs
|
||||
assertion_line: 127
|
||||
expression: screen
|
||||
---
|
||||
Agent command center Group: Pr…
|
||||
All 1 Needs you 0 ›
|
||||
────────────────────────────────
|
||||
|
||||
/tmp/project 1
|
||||
› ○ Current Cloud chat
|
||||
Ready
|
||||
|
||||
|
||||
|
||||
|
||||
◌ Loading additional tasks…
|
||||
@@ -216,7 +216,11 @@ impl App {
|
||||
/// Keep a visible modal closed to input if the terminal has not settled yet. The next input
|
||||
/// event retries the drain instead of acting on the modal; server events can continue meanwhile.
|
||||
pub(super) fn discard_startup_modal_input(&mut self, tui: &mut tui::Tui) -> Result<()> {
|
||||
match tui.discard_pending_input_before_interactive_screen() {
|
||||
let drained = tui.discard_pending_input_before_interactive_screen();
|
||||
// A press-only terminal can report the held key again after the input drain.
|
||||
self.chat_widget
|
||||
.protect_modal_from_held_activation_key(Instant::now());
|
||||
match drained {
|
||||
Ok(()) => self.startup_pending_protected_request = false,
|
||||
Err(err) if err.kind() == std::io::ErrorKind::TimedOut => {
|
||||
self.startup_pending_protected_request = true;
|
||||
@@ -1666,7 +1670,15 @@ See the Codex keymap documentation for supported actions and examples."
|
||||
continue;
|
||||
}
|
||||
if let AppEvent::ResumeBackendSession(target) = event {
|
||||
match app.resume_backend_session(tui, &mut backends, target).await {
|
||||
let thread_id = target.thread_id;
|
||||
let result = app.resume_backend_session(tui, &mut backends, target).await;
|
||||
if app.finish_docked_task_opening(tui, thread_id)
|
||||
&& app.chat_widget.has_active_modal()
|
||||
&& let Err(err) = app.render_startup_frame(tui, &app_event_rx)
|
||||
{
|
||||
break Err(err);
|
||||
}
|
||||
match result {
|
||||
Ok(AppRunControl::Continue) => continue,
|
||||
Ok(AppRunControl::Exit(reason)) => break Ok(reason),
|
||||
Err(error) => break Err(error),
|
||||
|
||||
@@ -1246,8 +1246,8 @@ async fn backend_handoff_errors_are_snapshotted() -> Result<()> {
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn resumed_backend_handoff_detaches_through_the_source_connection() -> Result<()> {
|
||||
let mut app = make_test_app().await;
|
||||
let (source, source_requests, source_proxy) = start_recording_app_server(
|
||||
let (mut app, mut events, _ops) = make_test_app_with_channels().await;
|
||||
let (mut source, source_requests, source_proxy) = start_recording_app_server(
|
||||
&app.config,
|
||||
/*blocked_thread_list*/ None,
|
||||
/*failed_thread_name*/ None,
|
||||
@@ -1276,19 +1276,53 @@ async fn resumed_backend_handoff_detaches_through_the_source_connection() -> Res
|
||||
Vec::new(),
|
||||
)
|
||||
.await?;
|
||||
let target = crate::resume_picker::SessionTarget {
|
||||
backend_id: destination_id,
|
||||
path: None,
|
||||
thread_id: resumed_id,
|
||||
cwd: Some(resumed.session.cwd.to_path_buf()),
|
||||
history_mode: None,
|
||||
};
|
||||
let task = destination
|
||||
.thread_read(resumed_id, /*include_turns*/ false)
|
||||
.await?;
|
||||
app.backend_registry
|
||||
.register_started(destination_id, &resumed)?;
|
||||
app.agents_overview
|
||||
.threads
|
||||
.insert(resumed_id, Some(task.clone()));
|
||||
let mut tui = crate::tui::test_support::make_test_tui()?;
|
||||
tui.set_owned_screen(/*owned*/ true)?;
|
||||
app.local_settings.transcript_mode = tui.transcript_mode();
|
||||
app.config.features.enable(Feature::TuiWorkspace)?;
|
||||
app.open_agents_overview(&source);
|
||||
assert!(app.workspace_center_owns_input());
|
||||
let view = app.agents_overview_view(vec![task], Some(resumed_id));
|
||||
app.agents_overview.workspace.replace_view(view);
|
||||
app.startup_protected_input_boundary = false;
|
||||
app.local_settings.tui.animations = false;
|
||||
boxed_future!(app.handle_workspace_key(&mut tui, &mut source, KeyCode::Enter.into())).await;
|
||||
let target = loop {
|
||||
match events.try_recv()? {
|
||||
AppEvent::SelectAgentsOverviewThread { thread_id } => {
|
||||
app.select_agents_overview_thread(&mut tui, &mut source, thread_id)
|
||||
.await?;
|
||||
}
|
||||
AppEvent::ResumeBackendSession(target) => break target,
|
||||
_ => {}
|
||||
}
|
||||
};
|
||||
let frame = buffer_text(tui.terminal.previous_buffer());
|
||||
let footer = frame
|
||||
.lines()
|
||||
.last()
|
||||
.unwrap()
|
||||
.split('│')
|
||||
.next()
|
||||
.unwrap()
|
||||
.trim();
|
||||
insta::assert_snapshot!(footer, @"◌ Opening task…");
|
||||
let approval = exec_approval_request(resumed_id, "turn", "call", /*approval_id*/ None);
|
||||
let buffered = crate::app::app_server_requests::BufferedServerRequest::new(
|
||||
approval,
|
||||
&destination.request_handle(),
|
||||
);
|
||||
app.agents_overview
|
||||
.dispatched_requests
|
||||
.insert(resumed_id, vec![buffered]);
|
||||
let mut backends = BackendSessions::from_initial(source, vec![destination]);
|
||||
backends
|
||||
.settings
|
||||
@@ -1309,6 +1343,22 @@ async fn resumed_backend_handoff_detaches_through_the_source_connection() -> Res
|
||||
app.resume_backend_session(&mut tui, &mut backends, target)
|
||||
.await?;
|
||||
|
||||
assert!(app.finish_docked_task_opening(&tui, resumed_id));
|
||||
assert!(app.startup_protected_input_boundary);
|
||||
while let Ok(event) = app.active_thread_rx.as_mut().unwrap().try_recv() {
|
||||
app.handle_thread_event_now(event);
|
||||
}
|
||||
assert!(app.chat_widget.has_active_modal());
|
||||
// The modal input drain refreshes the guard before input routing resumes.
|
||||
app.chat_widget
|
||||
.protect_modal_from_held_activation_key(Instant::now());
|
||||
assert!(
|
||||
app.route_key_chord_event(&mut tui, KeyCode::Enter.into())
|
||||
.is_none()
|
||||
);
|
||||
let held = KeyEvent::new_with_kind(KeyCode::Enter, KeyModifiers::NONE, KeyEventKind::Repeat);
|
||||
assert!(app.route_key_chord_event(&mut tui, held).is_none());
|
||||
assert!(app.chat_widget.has_active_modal());
|
||||
assert!(app.agents_overview.workspace.is_open());
|
||||
assert!(!app.workspace_center_owns_input());
|
||||
assert_eq!(backends.displayed_owner(), destination_id);
|
||||
|
||||
@@ -417,6 +417,11 @@ pub(crate) enum AppEvent {
|
||||
SelectAgentsOverviewThread {
|
||||
thread_id: ThreadId,
|
||||
},
|
||||
/// Refresh the resumed task's agent list after its transcript replay reaches the screen.
|
||||
BackfillResumedSubagents {
|
||||
thread_id: ThreadId,
|
||||
backend_id: crate::backend_id::BackendId,
|
||||
},
|
||||
/// Create an empty session in a worktree from the selected project's default branch.
|
||||
NewAgentsOverviewWorktree {
|
||||
backend_id: Option<crate::backend_id::BackendId>,
|
||||
|
||||
@@ -2079,9 +2079,7 @@ impl BottomPane {
|
||||
let reported_repeats_only = match suppression {
|
||||
ActivationKeySuppression::ViewTransition => self.enhanced_keys_supported,
|
||||
ActivationKeySuppression::ReportedRepeats => true,
|
||||
ActivationKeySuppression::PressOnlyFallback => {
|
||||
self.enhanced_keys_supported && crate::tui::reports_key_releases()
|
||||
}
|
||||
ActivationKeySuppression::PressOnlyFallback => self.reports_key_releases(),
|
||||
};
|
||||
self.view_transition_key_guard = Some(ActivationKeyGuard::new_at(
|
||||
key,
|
||||
@@ -2090,6 +2088,10 @@ impl BottomPane {
|
||||
));
|
||||
}
|
||||
|
||||
pub(crate) fn reports_key_releases(&self) -> bool {
|
||||
self.enhanced_keys_supported && crate::tui::reports_key_releases()
|
||||
}
|
||||
|
||||
pub(crate) fn consume_view_transition_key_event(&mut self, key_event: KeyEvent) -> bool {
|
||||
self.consume_view_transition_key(KeyBinding::from_event(key_event), key_event.kind)
|
||||
}
|
||||
|
||||
@@ -116,6 +116,14 @@ impl ChatWidget {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn protect_modal_from_held_activation_key(&mut self, now: Instant) {
|
||||
if !self.bottom_pane.reports_key_releases()
|
||||
&& let Some(guard) = &mut self.bottom_pane.view_transition_key_guard
|
||||
{
|
||||
guard.extend_for_protected_view(now);
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn consume_view_transition_key_event(&mut self, key_event: KeyEvent) -> bool {
|
||||
self.bottom_pane
|
||||
.consume_view_transition_key_event(key_event)
|
||||
|
||||
@@ -38,6 +38,8 @@ pub(crate) enum ReducedMotionIndicator {
|
||||
StaticBullet,
|
||||
}
|
||||
|
||||
pub(crate) const LOADING_FRAME_INTERVAL: Duration = Duration::from_millis(100);
|
||||
|
||||
/// Show the current loading glyph immediately and schedule the next frame.
|
||||
pub(crate) fn loading_glyph(
|
||||
started_at: Instant,
|
||||
@@ -55,7 +57,6 @@ pub(crate) fn loading_glyph_with_delay(
|
||||
mode: MotionMode,
|
||||
requester: &FrameRequester,
|
||||
) -> &'static str {
|
||||
const FRAME_DURATION: Duration = Duration::from_millis(100);
|
||||
const FRAMES: [&str; 10] = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
|
||||
if mode == MotionMode::Reduced {
|
||||
return "◌";
|
||||
@@ -65,8 +66,8 @@ pub(crate) fn loading_glyph_with_delay(
|
||||
requester.schedule_frame_in(delay - elapsed);
|
||||
return "";
|
||||
}
|
||||
requester.schedule_frame_in(FRAME_DURATION);
|
||||
let frame = elapsed.as_millis() / FRAME_DURATION.as_millis();
|
||||
requester.schedule_frame_in(LOADING_FRAME_INTERVAL);
|
||||
let frame = elapsed.as_millis() / LOADING_FRAME_INTERVAL.as_millis();
|
||||
FRAMES[usize::try_from(frame).unwrap_or_default() % FRAMES.len()]
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user