mirror of
https://github.com/openai/codex.git
synced 2026-12-04 00:51:02 +00:00
Add history pagination to the agent command center (#49106)
## Why The command center seeded only ten recent sessions, with no way to browse older history from the task list. ## What changed - Add a keyboard-selectable “Show more” row that discovers up to ten more tasks, with loading and retry states that remain accessible during search. - Retain per-source cursors and buffered rows across requests, merging interactive and non-interactive history by recency without discarding existing tasks on failure. - Refill vacancies after tasks are archived or deleted, and prevent stale refreshes from restoring removed tasks. - Limit routine detail refreshes to recent and loaded tasks, plus explicitly targeted threads, as retained history grows. ## Testing Add regression coverage for pagination across mixed sources, cursor retries without row loss, automatic refill, queued pagination, and “Show more” navigation, loading, search, and retry rendering. GitOrigin-RevId: 0bfcc970c9adf0c8d509b275a92ecf01c29595ad
This commit is contained in:
committed by
copyberry
parent
136391a23e
commit
8f6517772b
@@ -202,6 +202,7 @@ mod agent_status_feed;
|
||||
mod agents_overview;
|
||||
mod agents_overview_actions;
|
||||
mod agents_overview_details;
|
||||
pub(crate) mod agents_overview_discovery;
|
||||
mod agents_overview_threads;
|
||||
mod agents_overview_usage;
|
||||
mod agents_overview_view;
|
||||
|
||||
@@ -18,10 +18,19 @@ pub(super) const TASK_FILTERS: &[(&str, Option<AgentsOverviewGroup>)] = &[
|
||||
];
|
||||
|
||||
impl AgentsOverviewView {
|
||||
pub(in crate::app::agents_overview_view) fn selectable_indices(&self) -> Vec<usize> {
|
||||
let mut indices = self.visible_indices();
|
||||
if self.state().has_more {
|
||||
indices.push(usize::MAX);
|
||||
}
|
||||
indices
|
||||
}
|
||||
|
||||
pub(in crate::app::agents_overview_view) fn reconcile_command_center_selection(&mut self) {
|
||||
let visible = self.visible_indices();
|
||||
let visible = self.selectable_indices();
|
||||
if !visible.contains(&self.selected) {
|
||||
self.selected = visible.first().copied().unwrap_or(usize::MAX);
|
||||
self.state().show_more_selected = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ pub(super) enum CenterRow {
|
||||
Group(usize),
|
||||
Task(usize),
|
||||
Gap,
|
||||
ShowMore,
|
||||
}
|
||||
|
||||
impl AgentsOverviewView {
|
||||
@@ -18,6 +19,11 @@ impl AgentsOverviewView {
|
||||
let mut entries = Vec::new();
|
||||
let mut previous = None;
|
||||
for index in indices.iter().copied() {
|
||||
if index == usize::MAX {
|
||||
entries.push(CenterRow::Gap);
|
||||
entries.push(CenterRow::ShowMore);
|
||||
continue;
|
||||
}
|
||||
if previous.is_none_or(|previous| !self.same_group(grouping, previous, index)) {
|
||||
if previous.is_some() {
|
||||
entries.push(CenterRow::Gap);
|
||||
@@ -31,7 +37,7 @@ impl AgentsOverviewView {
|
||||
}
|
||||
|
||||
pub(in crate::app::agents_overview_view) fn page_selection(&mut self, action: ListAction) {
|
||||
let indices = self.visible_indices();
|
||||
let indices = self.selectable_indices();
|
||||
let mut state = self.state();
|
||||
if state.rename_target.is_some() || indices.is_empty() {
|
||||
return;
|
||||
@@ -44,6 +50,8 @@ impl AgentsOverviewView {
|
||||
.filter_map(|(position, row)| {
|
||||
if let CenterRow::Task(index) = row {
|
||||
Some((position, *index))
|
||||
} else if matches!(row, CenterRow::ShowMore) {
|
||||
Some((position, usize::MAX))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@@ -79,5 +87,6 @@ impl AgentsOverviewView {
|
||||
.min(entries.len().saturating_sub(height));
|
||||
drop(state);
|
||||
self.selected = selected;
|
||||
self.state().show_more_selected = selected == usize::MAX;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ impl AgentsOverviewView {
|
||||
if area.is_empty() {
|
||||
return;
|
||||
}
|
||||
let indices = self.visible_indices();
|
||||
let indices = self.selectable_indices();
|
||||
let mut state = self.state();
|
||||
if indices.is_empty() {
|
||||
line(
|
||||
@@ -68,7 +68,11 @@ impl AgentsOverviewView {
|
||||
let entries = self.center_rows(&indices, state.grouping);
|
||||
let selected = entries
|
||||
.iter()
|
||||
.position(|row| matches!(row, CenterRow::Task(index) if *index == self.selected))
|
||||
.position(|row| match row {
|
||||
CenterRow::Task(index) => *index == self.selected,
|
||||
CenterRow::ShowMore => self.selected == usize::MAX,
|
||||
_ => false,
|
||||
})
|
||||
.unwrap_or_default();
|
||||
let padding = u16::from(area.height >= 3);
|
||||
let viewport = row(area, padding, area.height - padding * 2);
|
||||
@@ -102,6 +106,36 @@ impl AgentsOverviewView {
|
||||
let index = match entry {
|
||||
CenterRow::Group(index) | CenterRow::Task(index) => *index,
|
||||
CenterRow::Gap => continue,
|
||||
CenterRow::ShowMore => {
|
||||
let rect = row(viewport, offset as u16, /*height*/ 1);
|
||||
let selected = self.selected == usize::MAX;
|
||||
let style = if selected {
|
||||
selection_style()
|
||||
} else {
|
||||
Style::default()
|
||||
};
|
||||
buf.set_style(
|
||||
Rect {
|
||||
width: row_width,
|
||||
..rect
|
||||
},
|
||||
style,
|
||||
);
|
||||
let label = if state.loading {
|
||||
"Loading more…"
|
||||
} else if state.refresh_failed {
|
||||
"Show more (retry)"
|
||||
} else {
|
||||
"Show more"
|
||||
};
|
||||
let marker = if selected { "›" } else { " " };
|
||||
line(
|
||||
Line::from(format!("{marker} {label}")).style(style),
|
||||
rect,
|
||||
buf,
|
||||
);
|
||||
continue;
|
||||
}
|
||||
};
|
||||
let task = &self.rows[index];
|
||||
let rect = row(viewport, offset as u16, /*height*/ 1);
|
||||
@@ -118,7 +152,9 @@ impl AgentsOverviewView {
|
||||
};
|
||||
let count = indices
|
||||
.iter()
|
||||
.filter(|&&candidate| self.same_group(state.grouping, candidate, index))
|
||||
.filter(|&&candidate| {
|
||||
candidate != usize::MAX && self.same_group(state.grouping, candidate, index)
|
||||
})
|
||||
.count();
|
||||
let total = (0..self.rows.len())
|
||||
.filter(|&candidate| self.same_group(state.grouping, candidate, index))
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
//! Dashboard rows, paging, metadata clipping and status-filter regressions.
|
||||
|
||||
use super::*;
|
||||
use assert_matches::assert_matches;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
fn screen(view: &AgentsOverviewView, width: u16, height: u16) -> String {
|
||||
@@ -553,3 +554,41 @@ async fn overview_clears_voice_badge_after_async_close() -> Result<()> {
|
||||
server.shutdown().await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn live_center_show_more_navigation_search_and_loading() {
|
||||
let mut app = make_test_app().await;
|
||||
let (tx, mut rx) = tokio::sync::mpsc::unbounded_channel();
|
||||
app.app_event_tx = AppEventSender::new(tx);
|
||||
app.agents_overview.view_state.lock().unwrap().has_more = true;
|
||||
let thread = overview_thread(
|
||||
ThreadId::new(),
|
||||
/*parent_thread_id*/ None,
|
||||
"Recent task",
|
||||
ThreadStatus::NotLoaded,
|
||||
);
|
||||
let mut view = app.agents_overview_view(vec![thread], /*selected_thread_id*/ None);
|
||||
view.handle_key_event(KeyCode::Down.into());
|
||||
insta::assert_snapshot!(
|
||||
"live_center_show_more",
|
||||
screen(&view, /*width*/ 80, /*height*/ 12)
|
||||
);
|
||||
view.handle_key_event(KeyCode::Enter.into());
|
||||
view.handle_key_event(KeyCode::Enter.into());
|
||||
assert_matches!(rx.try_recv(), Ok(AppEvent::ShowMoreAgentsOverview));
|
||||
assert!(rx.try_recv().is_err());
|
||||
assert!(screen(&view, /*width*/ 80, /*height*/ 12).contains("Loading more"));
|
||||
{
|
||||
let mut state = app.agents_overview.view_state.lock().unwrap();
|
||||
state.loading = false;
|
||||
state.refresh_failed = true;
|
||||
}
|
||||
view.handle_key_event(KeyCode::Char('f').into());
|
||||
view.handle_paste("Older task".into());
|
||||
insta::assert_snapshot!(
|
||||
"live_center_show_more_search_retry",
|
||||
screen(&view, /*width*/ 80, /*height*/ 12)
|
||||
);
|
||||
view.handle_key_event(KeyCode::Enter.into());
|
||||
assert_matches!(rx.try_recv(), Ok(AppEvent::ShowMoreAgentsOverview));
|
||||
}
|
||||
|
||||
@@ -44,6 +44,10 @@ pub(super) struct AgentsOverviewState {
|
||||
pub(super) usage_disabled: bool,
|
||||
pub(super) activity: HashMap<ThreadId, super::agents_overview_details::AgentsOverviewActivity>,
|
||||
pub(super) initialized: bool,
|
||||
pub(super) discovery: super::agents_overview_discovery::AgentsOverviewDiscovery,
|
||||
pub(super) show_more_requested: bool,
|
||||
/// Vacancies left by lifecycle removals, filled without expanding the visible window.
|
||||
pub(super) refill_count: usize,
|
||||
pub(super) request_id: Option<Uuid>,
|
||||
pub(super) refresh_pending: bool,
|
||||
pub(super) refresh_thread_ids: HashSet<ThreadId>,
|
||||
@@ -159,6 +163,9 @@ impl App {
|
||||
}
|
||||
self.agents_overview.request_id = None;
|
||||
self.agents_overview.refresh_task = None;
|
||||
let refill_succeeded = result
|
||||
.as_ref()
|
||||
.is_ok_and(|refresh| refresh.recent_seed_complete);
|
||||
{
|
||||
let mut state = self
|
||||
.agents_overview
|
||||
@@ -166,17 +173,31 @@ impl App {
|
||||
.lock()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner);
|
||||
state.loading = false;
|
||||
state.refresh_failed = !result
|
||||
.as_ref()
|
||||
.is_ok_and(|refresh| refresh.recent_seed_complete);
|
||||
state.refresh_failed = !refill_succeeded;
|
||||
}
|
||||
match result {
|
||||
Ok(refresh) => {
|
||||
self.agents_overview.initialized = refresh.recent_seed_complete;
|
||||
if let Some(discovery) = refresh.discovery {
|
||||
if !discovery.has_more() {
|
||||
self.agents_overview.refill_count = 0;
|
||||
self.agents_overview.show_more_requested = false;
|
||||
}
|
||||
self.agents_overview.initialized = true;
|
||||
self.agents_overview
|
||||
.view_state
|
||||
.lock()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner)
|
||||
.has_more = discovery.has_more();
|
||||
self.agents_overview.discovery = discovery;
|
||||
}
|
||||
self.agents_overview
|
||||
.last_messages
|
||||
.extend(refresh.last_messages);
|
||||
for (thread_id, thread) in refresh.threads {
|
||||
if self.agents_overview.removed_threads.contains(&thread_id) {
|
||||
continue;
|
||||
}
|
||||
if let Some(mut thread) = thread {
|
||||
if thread.ephemeral {
|
||||
self.agents_overview.threads.remove(&thread_id);
|
||||
@@ -185,6 +206,17 @@ impl App {
|
||||
self.agents_overview.usage.remove(&thread_id);
|
||||
continue;
|
||||
}
|
||||
if !self.agents_overview.threads.contains_key(&thread_id)
|
||||
&& !self.agents_overview.hidden_threads.contains(&thread_id)
|
||||
&& thread.parent_thread_id.is_none()
|
||||
&& !matches!(
|
||||
thread.source,
|
||||
SessionSource::SubAgent(SubAgentSource::ThreadSpawn { .. })
|
||||
)
|
||||
{
|
||||
self.agents_overview.refill_count =
|
||||
self.agents_overview.refill_count.saturating_sub(1);
|
||||
}
|
||||
thread.turns.clear();
|
||||
self.agents_overview.threads.insert(thread_id, Some(thread));
|
||||
} else {
|
||||
@@ -213,7 +245,12 @@ impl App {
|
||||
self.track_agents_overview_notification(¬ification);
|
||||
}
|
||||
}
|
||||
if std::mem::take(&mut self.agents_overview.refresh_pending) {
|
||||
if std::mem::take(&mut self.agents_overview.refresh_pending)
|
||||
|| (refill_succeeded
|
||||
&& (self.agents_overview.refill_count > 0
|
||||
|| self.agents_overview.show_more_requested)
|
||||
&& self.agents_overview.discovery.has_more())
|
||||
{
|
||||
self.refresh_changed_agents_overview_threads(app_server);
|
||||
}
|
||||
self.repaint_agents_overview();
|
||||
|
||||
@@ -227,6 +227,11 @@ impl App {
|
||||
refresh.abort();
|
||||
}
|
||||
self.agents_overview.request_id = None;
|
||||
self.agents_overview
|
||||
.view_state
|
||||
.lock()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner)
|
||||
.loading = false;
|
||||
self.agents_overview.refresh_pending = false;
|
||||
self.agents_overview.refresh_notifications.clear();
|
||||
}
|
||||
@@ -264,7 +269,7 @@ impl App {
|
||||
removed.insert(primary);
|
||||
}
|
||||
for removed_id in removed {
|
||||
self.agents_overview.threads.remove(&removed_id);
|
||||
self.remove_agents_overview_thread(removed_id);
|
||||
self.agents_overview.activity.remove(&removed_id);
|
||||
self.agents_overview.last_messages.remove(&removed_id);
|
||||
self.agents_overview.usage.remove(&removed_id);
|
||||
|
||||
@@ -335,6 +335,7 @@ async fn hidden_task_stays_hidden_through_activity_and_seed_until_explicit_resum
|
||||
threads: HashMap::from([(id, Some(thread.clone()))]),
|
||||
last_messages: HashMap::new(),
|
||||
recent_seed_complete: true,
|
||||
discovery: None,
|
||||
}),
|
||||
);
|
||||
assert_eq!(
|
||||
@@ -613,6 +614,7 @@ async fn lifecycle_removes_background_and_current_tasks_without_losing_the_dashb
|
||||
threads: stale_threads,
|
||||
last_messages: HashMap::new(),
|
||||
recent_seed_complete: true,
|
||||
discovery: None,
|
||||
}),
|
||||
);
|
||||
assert_eq!(
|
||||
@@ -699,7 +701,14 @@ async fn lifecycle_removes_background_and_current_tasks_without_losing_the_dashb
|
||||
app.agents_overview.threads.remove(&primary);
|
||||
}
|
||||
crate::chatwidget::activate_voice_for_thread(&mut app.chat_widget, primary);
|
||||
// Canceling pagination must allow automatic refill to finish after removing the last task.
|
||||
app.agents_overview.initialized = true;
|
||||
app.agents_overview.view_state.lock().unwrap().loading = true;
|
||||
Box::pin(app.handle_event(&mut tui, &mut app_server, confirmed)).await?;
|
||||
if app.agents_overview.request_id.is_some() {
|
||||
finish_overview_refresh(&mut app, &app_server, &mut rx).await;
|
||||
}
|
||||
assert!(!app.agents_overview.view_state.lock().unwrap().loading);
|
||||
assert_eq!(app.voice_owner_thread_id(), None);
|
||||
assert_eq!(
|
||||
(
|
||||
|
||||
@@ -0,0 +1,148 @@
|
||||
//! Demand-driven history discovery. Each source retains its cursor and unshown rows.
|
||||
//! One activation requests at most one page per source, then publishes up to ten tasks.
|
||||
|
||||
use codex_app_server_client::AppServerRequestHandle;
|
||||
use codex_app_server_client::TypedRequestError;
|
||||
use codex_app_server_protocol::ClientRequest;
|
||||
use codex_app_server_protocol::RequestId;
|
||||
use codex_app_server_protocol::SessionSource;
|
||||
use codex_app_server_protocol::Thread;
|
||||
use codex_app_server_protocol::ThreadListParams;
|
||||
use codex_app_server_protocol::ThreadListResponse;
|
||||
use codex_app_server_protocol::ThreadSortKey;
|
||||
use codex_app_server_protocol::ThreadSourceKind;
|
||||
use codex_protocol::protocol::SubAgentSource;
|
||||
use std::collections::VecDeque;
|
||||
use uuid::Uuid;
|
||||
|
||||
const PAGE_SIZE: u32 = 10;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct SourcePage {
|
||||
cursor: Option<String>,
|
||||
rows: VecDeque<Thread>,
|
||||
exhausted: bool,
|
||||
sort_key: ThreadSortKey,
|
||||
}
|
||||
|
||||
impl Default for SourcePage {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
cursor: None,
|
||||
rows: VecDeque::new(),
|
||||
exhausted: false,
|
||||
sort_key: ThreadSortKey::RecencyAt,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub(crate) struct AgentsOverviewDiscovery {
|
||||
sources: [SourcePage; 2],
|
||||
}
|
||||
|
||||
impl AgentsOverviewDiscovery {
|
||||
pub(super) fn has_more(&self) -> bool {
|
||||
self.sources
|
||||
.iter()
|
||||
.any(|source| !source.exhausted || !source.rows.is_empty())
|
||||
}
|
||||
|
||||
pub(super) async fn next_batch(
|
||||
&mut self,
|
||||
handle: &AppServerRequestHandle,
|
||||
limit: usize,
|
||||
) -> (Vec<Thread>, bool) {
|
||||
let [interactive, other] = &mut self.sources;
|
||||
let (left, right) = tokio::join!(
|
||||
interactive.fill(handle, Vec::new()),
|
||||
other.fill(
|
||||
handle,
|
||||
vec![ThreadSourceKind::Exec, ThreadSourceKind::AppServer]
|
||||
),
|
||||
);
|
||||
let mut rows = Vec::new();
|
||||
for _ in 0..limit {
|
||||
let next = self
|
||||
.sources
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter_map(|(index, source)| source.rows.front().map(|row| (index, row)))
|
||||
.max_by(|(_, left), (_, right)| {
|
||||
left.recency_at
|
||||
.unwrap_or(left.updated_at)
|
||||
.cmp(&right.recency_at.unwrap_or(right.updated_at))
|
||||
.then_with(|| left.id.cmp(&right.id))
|
||||
})
|
||||
.map(|(index, _)| index);
|
||||
let Some(index) = next else { break };
|
||||
if let Some(row) = self.sources[index].rows.pop_front() {
|
||||
rows.push(row);
|
||||
}
|
||||
}
|
||||
(rows, left && right)
|
||||
}
|
||||
}
|
||||
|
||||
impl SourcePage {
|
||||
async fn fill(
|
||||
&mut self,
|
||||
handle: &AppServerRequestHandle,
|
||||
source_kinds: Vec<ThreadSourceKind>,
|
||||
) -> bool {
|
||||
if self.exhausted || self.rows.len() >= PAGE_SIZE as usize {
|
||||
return true;
|
||||
}
|
||||
loop {
|
||||
let result = handle
|
||||
.request_typed::<ThreadListResponse>(ClientRequest::ThreadList {
|
||||
request_id: RequestId::String(Uuid::new_v4().to_string()),
|
||||
params: ThreadListParams {
|
||||
originators: None,
|
||||
cursor: self.cursor.clone(),
|
||||
limit: Some(PAGE_SIZE),
|
||||
sort_key: Some(self.sort_key),
|
||||
sort_direction: None,
|
||||
model_providers: Some(Vec::new()),
|
||||
source_kinds: Some(source_kinds.clone()),
|
||||
archived: Some(false),
|
||||
section_id: None,
|
||||
project_id: None,
|
||||
parent_thread_id: None,
|
||||
ancestor_thread_id: None,
|
||||
cwd: None,
|
||||
use_state_db_only: true,
|
||||
search_term: None,
|
||||
},
|
||||
})
|
||||
.await;
|
||||
match result {
|
||||
Err(TypedRequestError::Server { source, .. })
|
||||
if self.sort_key == ThreadSortKey::RecencyAt
|
||||
&& matches!(source.code, -32600 | -32602)
|
||||
&& source.message.contains("recency_at") =>
|
||||
{
|
||||
self.sort_key = ThreadSortKey::UpdatedAt;
|
||||
self.cursor = None;
|
||||
}
|
||||
Ok(page) => {
|
||||
self.exhausted = page.next_cursor.is_none();
|
||||
self.cursor = page.next_cursor;
|
||||
self.rows.extend(page.data.into_iter().filter(|thread| {
|
||||
!thread.ephemeral
|
||||
&& thread.parent_thread_id.is_none()
|
||||
&& !matches!(
|
||||
thread.source,
|
||||
SessionSource::SubAgent(SubAgentSource::ThreadSpawn { .. })
|
||||
)
|
||||
}));
|
||||
return true;
|
||||
}
|
||||
Err(error) => {
|
||||
tracing::warn!(%error, "failed to list more agent threads");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,175 @@
|
||||
//! Demand-driven discovery, cursor retry, and visible Show more behavior.
|
||||
|
||||
use super::*;
|
||||
use crate::app_server_session::ThreadParamsMode;
|
||||
use codex_app_server_protocol::JSONRPCMessage;
|
||||
use futures::SinkExt;
|
||||
use futures::StreamExt;
|
||||
use pretty_assertions::assert_eq;
|
||||
use serde_json::json;
|
||||
use tokio::net::TcpListener;
|
||||
use tokio_tungstenite::tungstenite::Message;
|
||||
|
||||
#[tokio::test]
|
||||
async fn overview_show_more_refills_archived_rows_and_retries_without_losing_rows() -> Result<()> {
|
||||
check_discovery(/*mixed_sources*/ false).await?;
|
||||
check_discovery(/*mixed_sources*/ true).await
|
||||
}
|
||||
|
||||
async fn check_discovery(mixed_sources: bool) -> Result<()> {
|
||||
let mut app = make_test_app().await;
|
||||
let rows: Vec<_> = (0..24)
|
||||
.map(|index| {
|
||||
let mut thread = overview_thread(
|
||||
ThreadId::new(),
|
||||
/*parent_thread_id*/ None,
|
||||
&format!("Task {index}"),
|
||||
ThreadStatus::NotLoaded,
|
||||
);
|
||||
if mixed_sources && (index == 0 || index >= 21) {
|
||||
thread.source = SessionSource::Exec;
|
||||
}
|
||||
thread.updated_at += 24 - index;
|
||||
thread.recency_at = Some(thread.updated_at);
|
||||
thread
|
||||
})
|
||||
.collect();
|
||||
let ids: Vec<_> = rows
|
||||
.iter()
|
||||
.map(|row| ThreadId::from_string(&row.id).unwrap())
|
||||
.collect();
|
||||
let mut expected: HashMap<_, _> = rows
|
||||
.iter()
|
||||
.map(|thread| {
|
||||
(
|
||||
ThreadId::from_string(&thread.id).unwrap(),
|
||||
Some(thread.clone()),
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
let expected_first_twenty: HashSet<_> = rows[1..21]
|
||||
.iter()
|
||||
.map(|row| ThreadId::from_string(&row.id).unwrap())
|
||||
.collect();
|
||||
let listener = TcpListener::bind("127.0.0.1:0").await?;
|
||||
let endpoint = crate::resolve_remote_addr(&format!("ws://{}", listener.local_addr()?))?;
|
||||
let server = tokio::spawn(async move {
|
||||
let (stream, _) = listener.accept().await?;
|
||||
let mut socket = tokio_tungstenite::accept_async(stream).await?;
|
||||
let mut cursors = Vec::new();
|
||||
while let Some(Ok(Message::Text(text))) = socket.next().await {
|
||||
let JSONRPCMessage::Request(request) = serde_json::from_str(&text)? else {
|
||||
continue;
|
||||
};
|
||||
let params = request.params.unwrap_or_default();
|
||||
let result = match request.method.as_str() {
|
||||
"initialize" => json!({"userAgent": "overview-test/1.0"}),
|
||||
"thread/loaded/list" => json!({"data": [], "nextCursor": null}),
|
||||
"thread/list" => {
|
||||
assert_eq!(params["sortKey"], "recency_at");
|
||||
assert_eq!(params["limit"], 10);
|
||||
{
|
||||
let interactive = params["sourceKinds"] == json!([]);
|
||||
let source_rows: Vec<_> = rows
|
||||
.iter()
|
||||
.filter(|row| matches!(row.source, SessionSource::Exec) != interactive)
|
||||
.collect();
|
||||
let cursor = params["cursor"].as_str().unwrap_or("0").parse::<usize>()?;
|
||||
if interactive {
|
||||
cursors.push(cursor);
|
||||
}
|
||||
if !mixed_sources && interactive && cursors == [0, 10] {
|
||||
socket.send(Message::Text(json!({"id": request.id, "error": {"code": -32603, "message": "transient"}}).to_string().into())).await?;
|
||||
continue;
|
||||
}
|
||||
let end = (cursor + 10).min(source_rows.len());
|
||||
json!({"data": source_rows[cursor..end], "nextCursor": (end < source_rows.len()).then(|| end.to_string())})
|
||||
}
|
||||
}
|
||||
"thread/read" => {
|
||||
json!({"thread": rows.iter().find(|thread| thread.id == params["threadId"]).unwrap()})
|
||||
}
|
||||
"thread/turns/list" => json!({"data": [], "nextCursor": null}),
|
||||
method => panic!("unexpected request: {method}"),
|
||||
};
|
||||
socket
|
||||
.send(Message::Text(
|
||||
json!({"id": request.id, "result": result})
|
||||
.to_string()
|
||||
.into(),
|
||||
))
|
||||
.await?;
|
||||
}
|
||||
Ok::<_, color_eyre::Report>(cursors)
|
||||
});
|
||||
let session = AppServerSession::new(
|
||||
crate::connect_remote_app_server(endpoint).await?,
|
||||
ThreadParamsMode::Remote,
|
||||
);
|
||||
let view = app.agents_overview_view(Vec::new(), /*selected_thread_id*/ None);
|
||||
app.chat_widget.show_bottom_pane_view(Box::new(view));
|
||||
let (tx, mut rx) = tokio::sync::mpsc::unbounded_channel();
|
||||
app.app_event_tx = AppEventSender::new(tx);
|
||||
app.refresh_agents_overview_threads(&session);
|
||||
finish_overview_refresh(&mut app, &session, &mut rx).await;
|
||||
assert_eq!(app.agents_overview.threads.len(), 10);
|
||||
assert!(app.agents_overview.discovery.has_more());
|
||||
app.track_agents_overview_notification(&ServerNotification::ThreadArchived(
|
||||
ThreadArchivedNotification {
|
||||
thread_id: ids[0].to_string(),
|
||||
},
|
||||
));
|
||||
app.remove_agents_overview_thread(ids[0]); // Duplicate local completion must not refill twice.
|
||||
expected.remove(&ids[0]);
|
||||
app.refresh_agents_overview_threads(&session);
|
||||
finish_overview_refresh(&mut app, &session, &mut rx).await;
|
||||
if !mixed_sources {
|
||||
assert_eq!(app.agents_overview.threads.len(), 9);
|
||||
assert!(
|
||||
app.agents_overview
|
||||
.view_state
|
||||
.lock()
|
||||
.unwrap()
|
||||
.refresh_failed
|
||||
);
|
||||
app.show_more_agents_overview(&session);
|
||||
finish_overview_refresh(&mut app, &session, &mut rx).await;
|
||||
}
|
||||
assert_eq!(app.agents_overview.threads.len(), 10);
|
||||
assert!(app.agents_overview.threads.contains_key(&ids[10]));
|
||||
app.show_more_agents_overview(&session);
|
||||
finish_overview_refresh(&mut app, &session, &mut rx).await;
|
||||
assert_eq!(
|
||||
app.agents_overview
|
||||
.threads
|
||||
.keys()
|
||||
.copied()
|
||||
.collect::<HashSet<_>>(),
|
||||
expected_first_twenty
|
||||
);
|
||||
app.remove_agents_overview_thread(ids[1]);
|
||||
expected.remove(&ids[1]);
|
||||
app.refresh_agents_overview_threads(&session);
|
||||
finish_overview_refresh(&mut app, &session, &mut rx).await;
|
||||
assert_eq!(app.agents_overview.threads.len(), 20);
|
||||
assert!(app.agents_overview.threads.contains_key(&ids[21]));
|
||||
for &id in &ids[2..22] {
|
||||
app.remove_agents_overview_thread(id);
|
||||
expected.remove(&id);
|
||||
}
|
||||
assert!(app.agents_overview.threads.is_empty());
|
||||
app.refresh_agents_overview_threads(&session);
|
||||
finish_overview_refresh(&mut app, &session, &mut rx).await;
|
||||
assert_eq!(app.agents_overview.threads, expected);
|
||||
assert!(!app.agents_overview.discovery.has_more());
|
||||
session.shutdown().await?;
|
||||
assert_eq!(
|
||||
server.await??,
|
||||
if mixed_sources {
|
||||
vec![0, 10]
|
||||
} else {
|
||||
vec![0, 10, 10, 20]
|
||||
}
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
@@ -1,3 +1,6 @@
|
||||
#[path = "agents_overview_discovery_tests.rs"]
|
||||
mod discovery;
|
||||
|
||||
#[path = "agent_center_tests.rs"]
|
||||
mod command_center;
|
||||
|
||||
@@ -371,6 +374,7 @@ async fn shared_overview_keeps_rows_and_replays_changes_over_stale_reads() -> Re
|
||||
(deleted, Some(deleted_thread)),
|
||||
]),
|
||||
recent_seed_complete: true,
|
||||
discovery: None,
|
||||
}),
|
||||
);
|
||||
retained_thread.name = Some("New name".to_string());
|
||||
@@ -390,6 +394,7 @@ async fn shared_overview_keeps_rows_and_replays_changes_over_stale_reads() -> Re
|
||||
last_messages: HashMap::new(),
|
||||
threads: HashMap::from([(retained, None)]),
|
||||
recent_seed_complete: true,
|
||||
discovery: None,
|
||||
}),
|
||||
);
|
||||
assert_eq!(app.agents_overview.threads, expected);
|
||||
@@ -438,6 +443,7 @@ async fn shared_overview_keeps_rows_and_replays_changes_over_stale_reads() -> Re
|
||||
threads: HashMap::new(),
|
||||
last_messages,
|
||||
recent_seed_complete: true,
|
||||
discovery: None,
|
||||
}),
|
||||
);
|
||||
assert!(app.agents_overview.last_messages.is_empty());
|
||||
@@ -628,6 +634,21 @@ async fn shared_overview_seeds_once_and_retains_locally_resumed_history() -> Res
|
||||
"agents_overview_recent_sessions",
|
||||
age.replace_all(&rendered, " [age]")
|
||||
);
|
||||
assert!(restarted.agents_overview.discovery.has_more());
|
||||
// Opening starts a metadata refresh; Show more queues behind it.
|
||||
restarted.show_more_agents_overview(&app_server);
|
||||
finish_overview_refresh(&mut restarted, &app_server, &mut event_rx).await;
|
||||
finish_overview_refresh(&mut restarted, &app_server, &mut event_rx).await;
|
||||
assert_eq!(
|
||||
restarted
|
||||
.agents_overview
|
||||
.threads
|
||||
.keys()
|
||||
.copied()
|
||||
.collect::<HashSet<_>>(),
|
||||
ids.into_iter().collect()
|
||||
);
|
||||
assert!(!restarted.agents_overview.discovery.has_more());
|
||||
app_server.shutdown().await?;
|
||||
Ok(())
|
||||
}
|
||||
@@ -2531,6 +2552,7 @@ async fn command_center_refresh_failure_is_inline_and_clears_on_success() -> Res
|
||||
threads: HashMap::new(),
|
||||
last_messages: HashMap::new(),
|
||||
recent_seed_complete: false,
|
||||
discovery: None,
|
||||
}),
|
||||
] {
|
||||
let request_id = Uuid::new_v4();
|
||||
@@ -2561,6 +2583,7 @@ async fn command_center_refresh_failure_is_inline_and_clears_on_success() -> Res
|
||||
threads: HashMap::new(),
|
||||
last_messages: HashMap::new(),
|
||||
recent_seed_complete: true,
|
||||
discovery: None,
|
||||
}),
|
||||
);
|
||||
assert_eq!(render_bottom_popup(&app.chat_widget, /*width*/ 48), before);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//! Retains overview membership for this TUI, independently of server subscriptions.
|
||||
//! The loaded/recent seed runs at startup and after reconnect; other reads only refresh metadata.
|
||||
//! A bounded recent seed runs at startup, after reconnect, and after event lag.
|
||||
//! Discovery merges into retained membership without evicting rows.
|
||||
|
||||
use super::App;
|
||||
@@ -12,20 +12,16 @@ use crate::app_event::AgentsOverviewThreadRefresh;
|
||||
use crate::app_event::AppEvent;
|
||||
use crate::app_server_session::AppServerSession;
|
||||
use crate::chatwidget::ChatWidget;
|
||||
use codex_app_server_client::TypedRequestError;
|
||||
use codex_app_server_protocol::ClientRequest;
|
||||
use codex_app_server_protocol::RequestId;
|
||||
use codex_app_server_protocol::ServerNotification;
|
||||
use codex_app_server_protocol::SessionSource;
|
||||
use codex_app_server_protocol::Thread;
|
||||
use codex_app_server_protocol::ThreadItem;
|
||||
use codex_app_server_protocol::ThreadListParams;
|
||||
use codex_app_server_protocol::ThreadListResponse;
|
||||
use codex_app_server_protocol::ThreadLoadedListParams;
|
||||
use codex_app_server_protocol::ThreadLoadedListResponse;
|
||||
use codex_app_server_protocol::ThreadReadParams;
|
||||
use codex_app_server_protocol::ThreadReadResponse;
|
||||
use codex_app_server_protocol::ThreadSortKey;
|
||||
use codex_app_server_protocol::ThreadSourceKind;
|
||||
use codex_app_server_protocol::ThreadStatus;
|
||||
use codex_app_server_protocol::ThreadTurnsListParams;
|
||||
use codex_app_server_protocol::ThreadTurnsListResponse;
|
||||
@@ -34,10 +30,53 @@ use codex_protocol::protocol::SubAgentSource;
|
||||
use std::collections::HashMap;
|
||||
use uuid::Uuid;
|
||||
|
||||
// Seed the command center with this many recent sessions, in addition to loaded sessions.
|
||||
const RECENT_SESSION_LIMIT: usize = 10;
|
||||
const RECENT_DETAIL_LIMIT: usize = 10;
|
||||
|
||||
// Listing supplies membership and row metadata without replaying every historical rollout.
|
||||
// Keep transcript previews fresh for recent and loaded tasks, plus notification-targeted reads.
|
||||
fn detail_thread_ids<'a>(threads: impl Iterator<Item = &'a Thread>) -> Vec<ThreadId> {
|
||||
let mut threads: Vec<_> = threads.collect();
|
||||
threads.sort_by(|left, right| {
|
||||
right
|
||||
.recency_at
|
||||
.unwrap_or(right.updated_at)
|
||||
.cmp(&left.recency_at.unwrap_or(left.updated_at))
|
||||
.then_with(|| right.id.cmp(&left.id))
|
||||
});
|
||||
threads
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
.filter(|(index, thread)| {
|
||||
*index < RECENT_DETAIL_LIMIT || thread.status != ThreadStatus::NotLoaded
|
||||
})
|
||||
.filter_map(|(_, thread)| ThreadId::from_string(&thread.id).ok())
|
||||
.collect()
|
||||
}
|
||||
|
||||
impl App {
|
||||
pub(super) fn remove_agents_overview_thread(&mut self, thread_id: ThreadId) {
|
||||
self.agents_overview.removed_threads.insert(thread_id);
|
||||
if let Some(Some(thread)) = self.agents_overview.threads.remove(&thread_id)
|
||||
&& !thread.ephemeral
|
||||
&& thread.parent_thread_id.is_none()
|
||||
&& !matches!(
|
||||
thread.source,
|
||||
SessionSource::SubAgent(SubAgentSource::ThreadSpawn { .. })
|
||||
)
|
||||
&& !self.agents_overview.hidden_threads.contains(&thread_id)
|
||||
{
|
||||
self.agents_overview.refill_count += 1;
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn show_more_agents_overview(&mut self, app_server: &AppServerSession) {
|
||||
if !self.agents_overview.discovery.has_more() {
|
||||
return;
|
||||
}
|
||||
self.agents_overview.show_more_requested |= self.agents_overview.refill_count == 0;
|
||||
self.start_agents_overview_refresh(app_server);
|
||||
}
|
||||
|
||||
pub(super) fn track_agents_overview_notification(&mut self, notification: &ServerNotification) {
|
||||
let ServerNotificationThreadTarget::Thread(thread_id) =
|
||||
server_notification_thread_target(notification)
|
||||
@@ -80,14 +119,13 @@ impl App {
|
||||
self.agents_overview.threads.insert(thread_id, Some(thread));
|
||||
}
|
||||
ServerNotification::ThreadArchived(_) | ServerNotification::ThreadDeleted(_) => {
|
||||
self.agents_overview.removed_threads.insert(thread_id);
|
||||
self.agents_overview
|
||||
.selected_permission_profiles
|
||||
.remove(&thread_id);
|
||||
self.agents_overview.activity.remove(&thread_id);
|
||||
self.agents_overview.last_messages.remove(&thread_id);
|
||||
self.agents_overview.usage.remove(&thread_id);
|
||||
self.agents_overview.threads.remove(&thread_id);
|
||||
self.remove_agents_overview_thread(thread_id);
|
||||
self.agents_overview.refresh_thread_ids.remove(&thread_id);
|
||||
}
|
||||
ServerNotification::ThreadUnarchived(_) => {
|
||||
@@ -169,9 +207,17 @@ impl App {
|
||||
}
|
||||
|
||||
pub(super) fn refresh_agents_overview_threads(&mut self, app_server: &AppServerSession) {
|
||||
self.agents_overview.refresh_thread_ids.extend(
|
||||
self.agents_overview
|
||||
.threads
|
||||
.iter()
|
||||
.filter_map(|(id, thread)| thread.is_none().then_some(*id)),
|
||||
);
|
||||
self.agents_overview
|
||||
.refresh_thread_ids
|
||||
.extend(self.agents_overview.threads.keys());
|
||||
.extend(detail_thread_ids(
|
||||
self.agents_overview.threads.values().flatten(),
|
||||
));
|
||||
self.start_agents_overview_refresh(app_server);
|
||||
}
|
||||
|
||||
@@ -205,13 +251,35 @@ impl App {
|
||||
self.agents_overview.refresh_pending = true;
|
||||
return;
|
||||
}
|
||||
if self.agents_overview.initialized && self.agents_overview.refresh_thread_ids.is_empty() {
|
||||
if self.agents_overview.initialized
|
||||
&& self.agents_overview.refresh_thread_ids.is_empty()
|
||||
&& !self.agents_overview.show_more_requested
|
||||
&& !(self.agents_overview.refill_count > 0 && self.agents_overview.discovery.has_more())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
let request_id = Uuid::new_v4();
|
||||
self.agents_overview.request_id = Some(request_id);
|
||||
let initialized = self.agents_overview.initialized;
|
||||
let refill = self.agents_overview.refill_count;
|
||||
let show_more =
|
||||
refill == 0 && std::mem::take(&mut self.agents_overview.show_more_requested);
|
||||
let discover =
|
||||
!initialized || show_more || (refill > 0 && self.agents_overview.discovery.has_more());
|
||||
let limit = if initialized && refill > 0 {
|
||||
refill.min(10)
|
||||
} else {
|
||||
10
|
||||
};
|
||||
let mut discovery = discover.then(|| {
|
||||
if initialized {
|
||||
self.agents_overview.discovery.clone()
|
||||
} else {
|
||||
self.agents_overview.removed_threads.clear();
|
||||
Default::default()
|
||||
}
|
||||
});
|
||||
let mut thread_ids = std::mem::take(&mut self.agents_overview.refresh_thread_ids);
|
||||
let request_handle = app_server.request_handle();
|
||||
let app_event_tx = self.app_event_tx.clone();
|
||||
@@ -219,122 +287,46 @@ impl App {
|
||||
.view_state
|
||||
.lock()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner)
|
||||
.loading = !initialized;
|
||||
.loading = discover;
|
||||
let refresh_task = tokio::spawn(async move {
|
||||
let result = async {
|
||||
let mut threads = HashMap::new();
|
||||
let mut last_messages = HashMap::new();
|
||||
let mut recent_seed_complete = true;
|
||||
if !initialized {
|
||||
let loaded = request_handle.request_typed::<ThreadLoadedListResponse>(
|
||||
ClientRequest::ThreadLoadedList {
|
||||
request_id: RequestId::String(Uuid::new_v4().to_string()),
|
||||
params: ThreadLoadedListParams {
|
||||
cursor: None,
|
||||
limit: None,
|
||||
},
|
||||
},
|
||||
);
|
||||
let list_recent = async |source_kinds: Vec<ThreadSourceKind>| {
|
||||
let mut recent = Vec::new();
|
||||
let mut cursor = None;
|
||||
let mut sort_key = ThreadSortKey::RecencyAt;
|
||||
while recent.len() < RECENT_SESSION_LIMIT {
|
||||
let page = match request_handle
|
||||
.request_typed::<ThreadListResponse>(ClientRequest::ThreadList {
|
||||
request_id: RequestId::String(Uuid::new_v4().to_string()),
|
||||
params: ThreadListParams {
|
||||
originators: None,
|
||||
cursor,
|
||||
limit: Some(RECENT_SESSION_LIMIT as u32),
|
||||
sort_key: Some(sort_key),
|
||||
sort_direction: None,
|
||||
model_providers: Some(Vec::new()),
|
||||
source_kinds: Some(source_kinds.clone()),
|
||||
archived: Some(false),
|
||||
section_id: None,
|
||||
project_id: None,
|
||||
parent_thread_id: None,
|
||||
ancestor_thread_id: None,
|
||||
cwd: None,
|
||||
use_state_db_only: true,
|
||||
search_term: None,
|
||||
},
|
||||
})
|
||||
.await
|
||||
{
|
||||
Err(TypedRequestError::Server { source, .. })
|
||||
if sort_key == ThreadSortKey::RecencyAt
|
||||
&& matches!(source.code, -32600 | -32602)
|
||||
&& source.message.contains("recency_at") =>
|
||||
{
|
||||
// Older servers can still provide their activity-sorted history.
|
||||
sort_key = ThreadSortKey::UpdatedAt;
|
||||
cursor = None;
|
||||
recent.clear();
|
||||
continue;
|
||||
}
|
||||
result => result?,
|
||||
};
|
||||
recent.extend(
|
||||
page.data
|
||||
.into_iter()
|
||||
.filter(|thread| {
|
||||
!thread.ephemeral
|
||||
&& thread.parent_thread_id.is_none()
|
||||
&& !matches!(
|
||||
thread.source,
|
||||
SessionSource::SubAgent(
|
||||
SubAgentSource::ThreadSpawn { .. }
|
||||
)
|
||||
)
|
||||
})
|
||||
.take(RECENT_SESSION_LIMIT - recent.len()),
|
||||
);
|
||||
cursor = page.next_cursor;
|
||||
if cursor.is_none() {
|
||||
break;
|
||||
}
|
||||
if let Some(discovery) = &mut discovery {
|
||||
let loaded = async {
|
||||
if initialized {
|
||||
return Ok(ThreadLoadedListResponse {
|
||||
data: Vec::new(),
|
||||
next_cursor: None,
|
||||
});
|
||||
}
|
||||
Ok::<_, TypedRequestError>(recent)
|
||||
request_handle
|
||||
.request_typed::<ThreadLoadedListResponse>(
|
||||
ClientRequest::ThreadLoadedList {
|
||||
request_id: RequestId::String(Uuid::new_v4().to_string()),
|
||||
params: ThreadLoadedListParams {
|
||||
cursor: None,
|
||||
limit: None,
|
||||
},
|
||||
},
|
||||
)
|
||||
.await
|
||||
};
|
||||
let recent = async {
|
||||
// Default interactive sources include Atlas/ChatGPT, which have no
|
||||
// explicit source kind. Exec/AppServer require a separate query.
|
||||
let (interactive, non_interactive) = tokio::join!(
|
||||
list_recent(Vec::new()),
|
||||
list_recent(vec![ThreadSourceKind::Exec, ThreadSourceKind::AppServer]),
|
||||
);
|
||||
let mut recent = interactive?;
|
||||
recent.extend(non_interactive?);
|
||||
recent.sort_by(|left, right| {
|
||||
right
|
||||
.recency_at
|
||||
.unwrap_or(right.updated_at)
|
||||
.cmp(&left.recency_at.unwrap_or(left.updated_at))
|
||||
.then_with(|| right.id.cmp(&left.id))
|
||||
});
|
||||
recent.truncate(RECENT_SESSION_LIMIT);
|
||||
Ok::<_, TypedRequestError>(recent)
|
||||
};
|
||||
let (loaded, recent) = tokio::join!(loaded, recent);
|
||||
let (loaded, (recent, complete)) =
|
||||
tokio::join!(loaded, discovery.next_batch(&request_handle, limit));
|
||||
let loaded = loaded.map_err(|error| error.to_string())?;
|
||||
let recent = recent.unwrap_or_else(|error| {
|
||||
tracing::warn!(%error, "failed to list recent agent threads");
|
||||
recent_seed_complete = false;
|
||||
Vec::new()
|
||||
});
|
||||
recent_seed_complete = complete;
|
||||
thread_ids.extend(
|
||||
loaded
|
||||
.data
|
||||
.into_iter()
|
||||
.filter_map(|id| ThreadId::from_string(&id).ok()),
|
||||
);
|
||||
// Keep list metadata even if a subsequent read fails transiently.
|
||||
thread_ids.extend(detail_thread_ids(recent.iter()));
|
||||
for thread in recent {
|
||||
if let Ok(thread_id) = ThreadId::from_string(&thread.id) {
|
||||
threads.insert(thread_id, Some(thread));
|
||||
thread_ids.insert(thread_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -419,6 +411,7 @@ impl App {
|
||||
threads,
|
||||
last_messages,
|
||||
recent_seed_complete,
|
||||
discovery,
|
||||
})
|
||||
}
|
||||
.await;
|
||||
|
||||
@@ -102,6 +102,7 @@ async fn selected_usage_is_cached_and_account_changes_discard_old_results() -> R
|
||||
threads: HashMap::from([(selected, Some(threads[0].clone()))]),
|
||||
last_messages: HashMap::new(),
|
||||
recent_seed_complete: true,
|
||||
discovery: None,
|
||||
}),
|
||||
);
|
||||
assert_eq!(
|
||||
|
||||
@@ -141,6 +141,8 @@ pub(super) struct AgentsOverviewViewState {
|
||||
pub(super) creating_worktree: bool,
|
||||
pub(super) refresh_failed: bool,
|
||||
pub(super) loading: bool,
|
||||
pub(super) has_more: bool,
|
||||
show_more_selected: bool,
|
||||
pub(super) connection_notice: Option<&'static str>,
|
||||
pub(super) server_version_notice: Option<String>,
|
||||
search: String,
|
||||
@@ -224,6 +226,9 @@ impl AgentsOverviewView {
|
||||
center_shortcut_keys,
|
||||
worktrees_enabled,
|
||||
};
|
||||
if selected_thread_id.is_none() && view.state().show_more_selected {
|
||||
view.selected = usize::MAX;
|
||||
}
|
||||
view.state().completion = None;
|
||||
view.reconcile_command_center_selection();
|
||||
view
|
||||
@@ -295,7 +300,7 @@ impl AgentsOverviewView {
|
||||
if self.state().rename_target.is_some() {
|
||||
return;
|
||||
}
|
||||
let visible = self.visible_indices();
|
||||
let visible = self.selectable_indices();
|
||||
if visible.is_empty() {
|
||||
return;
|
||||
}
|
||||
@@ -308,9 +313,17 @@ impl AgentsOverviewView {
|
||||
} else {
|
||||
visible[current.checked_sub(1).unwrap_or(visible.len() - 1)]
|
||||
};
|
||||
self.state().show_more_selected = self.selected == usize::MAX;
|
||||
}
|
||||
|
||||
fn activate(&mut self) {
|
||||
if self.selected == usize::MAX && self.state().has_more {
|
||||
if !self.state().loading {
|
||||
self.state().loading = true;
|
||||
self.app_event_tx.send(AppEvent::ShowMoreAgentsOverview);
|
||||
}
|
||||
return;
|
||||
}
|
||||
let input = self.state().input.clone();
|
||||
if self.state().rename_target.is_some() && !input.trim().is_empty() {
|
||||
if let Some(row) = self.selected_row() {
|
||||
@@ -350,7 +363,7 @@ impl AgentsOverviewView {
|
||||
drop(state);
|
||||
if searching {
|
||||
self.selected = self
|
||||
.visible_indices()
|
||||
.selectable_indices()
|
||||
.first()
|
||||
.copied()
|
||||
.unwrap_or(usize::MAX);
|
||||
|
||||
@@ -78,6 +78,7 @@ impl App {
|
||||
}
|
||||
self.agents_overview.request_id = None;
|
||||
self.agents_overview.refresh_pending = false;
|
||||
self.agents_overview.initialized = false;
|
||||
self.agents_overview.refresh_notifications.clear();
|
||||
self.agents_overview.activity.clear();
|
||||
self.agents_overview.last_messages.clear();
|
||||
|
||||
@@ -2598,6 +2598,7 @@ impl App {
|
||||
}
|
||||
}
|
||||
AppEvent::OpenAgentsOverview => self.open_agents_overview(app_server),
|
||||
AppEvent::ShowMoreAgentsOverview => self.show_more_agents_overview(app_server),
|
||||
AppEvent::NewAgentsOverviewSession { cwd } => {
|
||||
return Box::pin(self.new_agents_overview_session(tui, app_server, cwd)).await;
|
||||
}
|
||||
|
||||
+2
-1
@@ -1,5 +1,6 @@
|
||||
---
|
||||
source: tui/src/app/agents_overview_tests.rs
|
||||
assertion_line: 633
|
||||
expression: "age.replace_all(&rendered, \" [age]\")"
|
||||
---
|
||||
Agent command center Group: Project g
|
||||
@@ -18,7 +19,7 @@ expression: "age.replace_all(&rendered, \" [age]\")"
|
||||
○ Task 4 Inactive [age]
|
||||
○ Task 3 Inactive [age]
|
||||
|
||||
|
||||
Show more
|
||||
|
||||
|
||||
|
||||
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
---
|
||||
source: tui/src/app/agent_center_tests.rs
|
||||
assertion_line: 572
|
||||
expression: "screen(&view, 80, 12)"
|
||||
---
|
||||
Agent command center Group: Project g
|
||||
All 1 Needs you 0 Working 0 Ready 0 Inactive 1
|
||||
────────────────────────────────────────────────────────────────────────────
|
||||
Tasks Status Updated
|
||||
/tmp/project 1
|
||||
○ Recent task Inactive 2m ago
|
||||
|
||||
› Show more
|
||||
|
||||
|
||||
|
||||
? help esc back ↑/↓ move enter open n new
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
---
|
||||
source: tui/src/app/agent_center_tests.rs
|
||||
assertion_line: 588
|
||||
expression: "screen(&view, 80, 12)"
|
||||
---
|
||||
Agent command center Group: Project g
|
||||
All 1 Needs you 0 Working 0 Ready 0 Inactive 1
|
||||
────────────────────────────────────────────────────────────────────────────
|
||||
Search › Older task
|
||||
Tasks Status Updated
|
||||
|
||||
› Show more (retry)
|
||||
|
||||
|
||||
|
||||
|
||||
Error loading tasks
|
||||
@@ -133,6 +133,8 @@ async fn reconnect_daemon_command_center_after_socket_replacement_without_a_conv
|
||||
.last_messages
|
||||
.insert(selected, "Pre-disconnect answer".into());
|
||||
app.agents_overview.initialized = overview_initialized;
|
||||
// This task was unarchived elsewhere while disconnected.
|
||||
app.agents_overview.removed_threads.insert(added);
|
||||
let view = app.agents_overview_view(
|
||||
stale.clone(),
|
||||
Some(if previous_thread.is_some() {
|
||||
@@ -275,6 +277,7 @@ async fn reconnect_daemon_command_center_after_socket_replacement_without_a_conv
|
||||
last_messages: HashMap::new(),
|
||||
threads: HashMap::new(),
|
||||
recent_seed_complete: false,
|
||||
discovery: None,
|
||||
}),
|
||||
);
|
||||
assert_eq!(app.agents_overview.visible_thread_ids.len(), 2);
|
||||
@@ -426,6 +429,7 @@ async fn reconnect_daemon_command_center_after_socket_replacement_without_a_conv
|
||||
last_messages: HashMap::new(),
|
||||
threads: stale_threads,
|
||||
recent_seed_complete: true,
|
||||
discovery: None,
|
||||
}),
|
||||
);
|
||||
assert!(!app.agents_overview.visible_thread_ids.contains(&vanished));
|
||||
|
||||
@@ -2917,7 +2917,7 @@ async fn agents_overview_seeds_loaded_threads_when_recent_listing_is_unavailable
|
||||
),
|
||||
(
|
||||
HistoryCapabilities::ThreadListFails,
|
||||
vec!["recency_at", "recency_at", "recency_at", "recency_at"],
|
||||
vec!["recency_at", "recency_at"],
|
||||
),
|
||||
] {
|
||||
let (mut app, _codex_home) = make_history_test_app().await?;
|
||||
@@ -2959,9 +2959,10 @@ async fn agents_overview_seeds_loaded_threads_when_recent_listing_is_unavailable
|
||||
.collect::<Vec<_>>(),
|
||||
vec![started.session.thread_id]
|
||||
);
|
||||
assert!(app.agents_overview.initialized);
|
||||
assert_eq!(
|
||||
app.agents_overview.initialized,
|
||||
capabilities != HistoryCapabilities::ThreadListFails || attempt > 0
|
||||
app.agents_overview.discovery.has_more(),
|
||||
capabilities == HistoryCapabilities::ThreadListFails
|
||||
);
|
||||
if attempt == 0 {
|
||||
app.handle_app_server_event(
|
||||
|
||||
@@ -272,6 +272,7 @@ pub(crate) struct AgentsOverviewThreadRefresh {
|
||||
pub(crate) threads: std::collections::HashMap<ThreadId, Option<Thread>>,
|
||||
pub(crate) last_messages: std::collections::HashMap<ThreadId, String>,
|
||||
pub(crate) recent_seed_complete: bool,
|
||||
pub(crate) discovery: Option<crate::app::agents_overview_discovery::AgentsOverviewDiscovery>,
|
||||
}
|
||||
|
||||
#[allow(clippy::large_enum_variant)]
|
||||
@@ -285,6 +286,7 @@ pub(crate) enum AppEvent {
|
||||
CloseMisalignmentReview,
|
||||
/// Open the live command center for recent and locally retained root sessions.
|
||||
OpenAgentsOverview,
|
||||
ShowMoreAgentsOverview,
|
||||
/// Create an empty thread from the command center.
|
||||
NewAgentsOverviewSession {
|
||||
cwd: Option<AbsolutePathBuf>,
|
||||
|
||||
Reference in New Issue
Block a user