Wait for subagent transcripts before enabling sidebar selection (#63887)

## Why

The sidebar can learn about a subagent from live activity before it can
open the transcript. During that gap, the chooser can offer a row whose
transcript is still unavailable.

## What changed

- Start transcript discovery when the TUI observes subagent activity
  and retry when the chooser opens with disabled rows.
- Keep starting and unconfirmed subagents visible but skip their rows
  during keyboard and mouse selection. Show whether an unconfirmed
  transcript is loading or unavailable once the subagent leaves
  `Starting`.
- Resolve provisional status from discovered threads, including idle
  and unloaded ones, while preserving newer live outcomes. Open
  transcript links only after discovery confirms the subagent.

## Testing

Extend TUI coverage for discovery retries, status updates arriving
during discovery, disabled row navigation and clicks, and transcript
links that wait for a follow-up refresh.

GitOrigin-RevId: e4d3b992830884532531239507083e4bd2df6687
This commit is contained in:
Felipe Coury
2026-11-25 11:49:41 +00:00
committed by copyberry
parent 16466d9e3a
commit 600595d67c
11 changed files with 401 additions and 61 deletions
+12 -8
View File
@@ -194,11 +194,7 @@ impl App {
Ok(refresh) => refresh,
Err(err) => {
tracing::warn!(%err, "failed to refresh agent picker descendants");
self.agent_navigation.prune_untracked_picker_exclusions();
if completion.follow_up_requested {
self.refresh_agent_picker_threads(app_server, root);
}
return None;
AgentPickerThreadRefresh::default()
}
};
for thread in refresh.threads {
@@ -249,8 +245,7 @@ impl App {
if !live && update_liveness {
self.agent_navigation.set_running(thread_id, is_running);
}
if sidebar_agent && !live && (is_running || thread.status == ThreadStatus::SystemError)
{
if sidebar_agent && !live {
self.seed_discovered_sidebar_agent(root, thread_id, &thread.status);
}
}
@@ -280,10 +275,19 @@ impl App {
self.refresh_collab_history();
self.refresh_agent_picker();
self.chat_widget.request_redraw();
let mut pending_link = pending_link.filter(|link| link.backend == app_server.backend_id());
if completion.follow_up_requested {
if pending_link
.as_ref()
.is_some_and(|link| !self.is_confirmed_sidebar_agent(root, link.agent))
&& let Some(pane) = self.sidebars.get_mut(&Some(root))
{
pane.agents.pending_link = pending_link.take();
}
self.refresh_agent_picker_threads(app_server, root);
}
pending_link.filter(|link| link.backend == app_server.backend_id())
pending_link.filter(|link| self.is_confirmed_sidebar_agent(root, link.agent))
}
pub(super) fn set_agent_picker_thread_visibility(
+1
View File
@@ -3740,6 +3740,7 @@ impl App {
AppEvent::DiscoverSidebarAgents(root) => {
if self.primary_thread_id == Some(root) && !self.reconnect.offline {
self.refresh_agent_picker_threads(app_server, root);
tui.frame_requester().schedule_frame();
}
}
AppEvent::AgentPickerThreadsLoaded {
+12 -1
View File
@@ -70,12 +70,19 @@ impl App {
}
self.zoomed_thread = None;
let parent = self.current_displayed_thread_id();
let pane = self.sidebar_mut();
let sidebar_parent = self.sidebar_parent();
let pane = self.sidebars.entry(sidebar_parent).or_default();
pane.closing_chats.retain(|_, task| !task.is_finished());
pane.show(SidebarContent::Chooser, PaneFocus::Sidebar);
if pane.creation.is_none()
&& let Some(parent) = parent
{
if self.primary_thread_id == Some(parent) {
pane.sync_agent_rows(&self.agent_navigation);
if pane.agents.rows.iter().any(|agent| !agent.selectable) {
self.refresh_agent_picker_threads(server, parent);
}
}
self.refresh_saved_chats(server, parent);
self.refresh_sidebar_files(server, parent).await;
}
@@ -535,6 +542,10 @@ impl App {
&& pane.creation.is_none()
&& let Some(agent) = pane.chat_tabs().agent(index).map(|agent| agent.id)
{
if pane.chat_tabs().agent_is_disabled(index) {
self.guard_chooser_key(activation);
return true;
}
pane.choice = index;
if self
.agent_navigation
+4 -2
View File
@@ -253,7 +253,7 @@ impl SidebarPane {
.ne(rows.iter().map(|agent| agent.id));
let selection = self.input_state().choice;
self.agents.rows = rows;
if reordered {
if reordered || self.chat_tabs().agent_is_disabled(self.choice) {
self.restore_choice(selection);
self.tabs_revision += 1;
}
@@ -264,7 +264,9 @@ impl SidebarPane {
let index = match selection {
ChooserSelection::New => Some(0),
ChooserSelection::Chat(id) => tabs.choice_index(id),
ChooserSelection::Agent(id) => tabs.agent_index(id),
ChooserSelection::Agent(id) => tabs
.agent_index(id)
.filter(|&index| !tabs.agent_is_disabled(index)),
ChooserSelection::File(offset) => {
Some(tabs.file_start() + offset).filter(|&index| tabs.file(index).is_some())
}
+5 -2
View File
@@ -31,8 +31,11 @@ impl State {
pub(super) fn supersedes(self, previous: Option<Self>, start_hint: bool) -> bool {
// Spawn activity can arrive after the child's own completion notification.
!(previous.is_some_and(Self::done)
&& (matches!(self, Self::Idle | Self::Unavailable) || start_hint && !self.done()))
!previous.is_some_and(|previous| {
(previous.done()
&& (matches!(self, Self::Idle | Self::Unavailable) || start_hint && !self.done()))
|| (matches!(previous, Self::Running | Self::Waiting) && self == Self::Starting)
})
}
pub(super) fn done(self) -> bool {
@@ -54,8 +54,8 @@ fn idle_preserves_explicit_outcome_until_new_work() {
observe(&thread_status(ThreadStatus::Idle), &mut overview);
observe(&activity(SubAgentActivityKind::Interacted), &mut overview);
observe(&activity(SubAgentActivityKind::Started), &mut overview);
observe(
&completed_item(ThreadItemPayload::CollabAgentToolCall {
let spawn = |status| {
completed_item(ThreadItemPayload::CollabAgentToolCall {
id: "spawn".into(),
tool: CollabAgentTool::SpawnAgent,
status: codex_app_server_protocol::CollabAgentToolCallStatus::Completed,
@@ -67,13 +67,13 @@ fn idle_preserves_explicit_outcome_until_new_work() {
agents_states: HashMap::from([(
id.to_string(),
codex_app_server_protocol::CollabAgentState {
status: CollabAgentStatus::Running,
status,
message: None,
},
)]),
}),
&mut overview,
);
})
};
observe(&spawn(CollabAgentStatus::Running), &mut overview);
assert_eq!(overview.states, HashMap::from([(id, State::Completed)]));
observe(
&thread_status(ThreadStatus::Active {
@@ -81,6 +81,8 @@ fn idle_preserves_explicit_outcome_until_new_work() {
}),
&mut overview,
);
// A delayed spawn notification must not disable a transcript that is already running.
observe(&spawn(CollabAgentStatus::PendingInit), &mut overview);
assert_eq!(overview.states, HashMap::from([(id, State::Running)]));
observe(&completed(TurnStatus::Failed), &mut overview);
observe(&thread_status(ThreadStatus::Idle), &mut overview);
@@ -126,6 +128,11 @@ async fn chooser_lists_subagents_by_observed_outcome() -> color_eyre::Result<()>
);
}
app.agent_navigation.mark_parent_owned(first);
app.sidebar_mut()
.agents
.states
.insert(first, State::Starting);
assert!(app.confirm_sidebar_agent(root, second));
app.observe_sidebar_agent_event(&ServerNotification::TurnCompleted(
TurnCompletedNotification {
thread_id: second.to_string(),
@@ -175,15 +182,21 @@ async fn chooser_lists_subagents_by_observed_outcome() -> color_eyre::Result<()>
}
#[tokio::test]
async fn active_discovery_supersedes_restored_completion() -> color_eyre::Result<()> {
async fn discovery_updates_provisional_status_without_overwriting_newer_outcomes()
-> color_eyre::Result<()> {
use crate::app::owned_transcript::tests::attach_thread;
use crate::app::test_support::enable_side_retention;
use crate::app::test_support::side_frame;
use crate::app::tests::make_test_app_with_channels;
use crate::tui::TuiEvent;
use crossterm::event::KeyCode;
use ratatui::layout::Size;
let (mut app, _events, _ops) = Box::pin(make_test_app_with_channels()).await;
let (mut app, mut events, _ops) = Box::pin(make_test_app_with_channels()).await;
enable_side_retention(&mut app)?;
let config = app.chat_widget.config_ref();
let mut server = Box::pin(crate::start_embedded_app_server_for_picker(config)).await?;
app.local_settings.tui.animations = false;
let config = app.chat_widget.config_ref().clone();
let mut server = Box::pin(crate::start_embedded_app_server_for_picker(&config)).await?;
let root = ThreadId::new();
let child = ThreadId::from_string(
&app_test_support::create_fake_paginated_rollout(
@@ -210,7 +223,18 @@ async fn active_discovery_supersedes_restored_completion() -> color_eyre::Result
let mut failed_thread = thread.clone();
failed_thread.id = failed.to_string();
failed_thread.status = ThreadStatus::SystemError;
let outcomes = [child, completed]
let idle = ThreadId::new();
let mut idle_thread = thread.clone();
idle_thread.id = idle.to_string();
idle_thread.status = ThreadStatus::Idle;
let saved = ThreadId::new();
let mut saved_thread = idle_thread.clone();
saved_thread.id = saved.to_string();
saved_thread.status = ThreadStatus::NotLoaded;
let unloaded = ThreadId::new();
let mut unloaded_thread = saved_thread.clone();
unloaded_thread.id = unloaded.to_string();
let outcomes = [child, completed, saved]
.into_iter()
.flat_map(|id| {
[
@@ -235,6 +259,37 @@ async fn active_discovery_supersedes_restored_completion() -> color_eyre::Result
status: thread.status.clone(),
},
));
assert!(
std::iter::from_fn(|| events.try_recv().ok()).any(|event| {
matches!(event, crate::app_event::AppEvent::DiscoverSidebarAgents(id) if id == root)
}),
"a live status update must start discovery even without chooser input"
);
let request = app
.agent_navigation
.begin_picker_refresh(root)
.expect("start discovery");
assert!(
app.apply_agent_picker_thread_refresh(
&server,
root,
request,
Err("discovery failed".into()),
)
.is_none()
);
app.observe_sidebar_agent_event(&ServerNotification::ThreadStatusChanged(
ThreadStatusChangedNotification {
thread_id: child.to_string(),
status: thread.status.clone(),
},
));
assert!(
std::iter::from_fn(|| events.try_recv().ok()).any(|event| {
matches!(event, crate::app_event::AppEvent::DiscoverSidebarAgents(id) if id == root)
}),
"a later active update must retry discovery for a running unconfirmed agent"
);
app.restore_sidebar_agent_outcomes(
root,
&[crate::app::tests::test_turn(
@@ -244,10 +299,20 @@ async fn active_discovery_supersedes_restored_completion() -> color_eyre::Result
)],
super::super::OutcomeReplay::Reconnect,
);
for id in [child, completed] {
for id in [idle, unloaded] {
assert!(app.register_sidebar_agent(root, id));
app.sidebar_mut().agents.states.insert(id, State::Starting);
}
for (id, name) in [
(child, "worker"),
(completed, "worker"),
(idle, "idle-worker"),
(saved, "worker"),
(unloaded, "saved-worker"),
] {
app.upsert_agent_picker_thread(
id,
Some("worker".into()),
Some(name.into()),
/*agent_role*/ None,
/*is_closed*/ false,
);
@@ -258,14 +323,42 @@ async fn active_discovery_supersedes_restored_completion() -> color_eyre::Result
.agents
.chooser_rows(&app.agent_navigation)
.into_iter()
.map(|row| (row.id, row.status))
.collect::<Vec<_>>()
.map(|row| (row.id, (row.status, row.selectable)))
.collect::<HashMap<_, _>>()
};
assert_eq!(
rows(&app),
HashMap::from([
(child, ("Transcript unavailable", false)),
(completed, ("Transcript unavailable", false)),
(idle, ("Starting", false)),
(saved, ("Transcript unavailable", false)),
(unloaded, ("Starting", false)),
])
);
// No frame has drawn the hidden chooser since discovery failed.
assert!(app.sidebar().unwrap().agents.rows.is_empty());
app.keymap.app.focus_sidebar_tabs = vec![crate::key_hint::plain(KeyCode::F(6))];
let size = Size::new(/*width*/ 210, /*height*/ 24);
let mut tui = crate::tui::test_support::make_test_tui_with_size(size)?;
tui.set_owned_screen(/*owned*/ true)?;
Box::pin(app.handle_tui_event(&mut tui, &mut server, TuiEvent::Key(KeyCode::F(6).into())))
.await?;
assert_eq!(
app.chooser_focus(),
Some(crate::app::sidebar::PaneFocus::Sidebar)
);
assert!(
app.agent_navigation.picker_refresh.is_some(),
"opening the hidden chooser retries discovery before the first draw"
);
let request = loop {
if let crate::app_event::AppEvent::AgentPickerThreadsLoaded { request_id, .. } =
events.recv().await.expect("app event channel")
{
break request_id;
}
};
assert!(rows(&app).iter().all(|(_, state)| *state == "Completed"));
let request = app
.agent_navigation
.begin_picker_refresh(root)
.expect("start discovery");
// A completion arriving while the refresh is in flight wins over the active snapshot.
app.observe_sidebar_agent_event(&ServerNotification::TurnCompleted(
TurnCompletedNotification {
@@ -279,7 +372,14 @@ async fn active_discovery_supersedes_restored_completion() -> color_eyre::Result
root,
request,
Ok(crate::app_event::AgentPickerThreadRefresh {
threads: vec![thread, completed_thread, failed_thread],
threads: vec![
thread,
completed_thread,
failed_thread,
idle_thread,
saved_thread,
unloaded_thread,
],
..Default::default()
}),
)
@@ -287,12 +387,45 @@ async fn active_discovery_supersedes_restored_completion() -> color_eyre::Result
);
assert_eq!(
rows(&app),
vec![
(child, "Running"),
(completed, "Completed"),
(failed, "Failed")
]
HashMap::from([
(child, ("Running", true)),
(completed, ("Completed", true)),
(failed, ("Failed", true)),
(idle, ("Idle", true)),
(saved, ("Completed", true)),
(unloaded, ("Unavailable", true)),
])
);
app.restore_sidebar_agent_outcomes(
root,
&[crate::app::tests::test_turn(
"reconnected-turn",
TurnStatus::Completed,
vec![ThreadItemPayload::SubAgentActivity {
id: "completed-while-disconnected".into(),
kind: SubAgentActivityKind::Completed,
agent_thread_id: idle.to_string(),
agent_path: "/root/idle-worker".into(),
model: None,
reasoning_effort: None,
}],
)],
super::super::OutcomeReplay::Reconnect,
);
assert_eq!(rows(&app).get(&idle), Some(&("Completed", true)));
let screen = side_frame(&mut app, &mut tui, size)?;
let ready_rows = screen
.lines()
.filter_map(|line| line.split_once('│').map(|(_, row)| row))
.filter(|row| row.contains("saved-worker") || row.contains("idle-worker"))
.map(|row| row.split_whitespace().collect::<Vec<_>>().join(" "))
.collect::<Vec<_>>()
.join("\n");
insta::assert_snapshot!(ready_rows, @r"
○ saved-worker Unavailable
○ idle-worker Completed
");
tui.set_owned_screen(/*owned*/ false)?;
server.shutdown().await?;
Ok(())
}
@@ -383,7 +516,7 @@ async fn opens_agent_transcript_beside_parent_and_returns_to_chooser() -> color_
))?;
tui.set_owned_screen(/*owned*/ true)?;
// Hold the actual discovery response so the first click races it deterministically.
let discovery = tokio::time::timeout(std::time::Duration::from_secs(5), async {
let mut discovery = tokio::time::timeout(std::time::Duration::from_secs(5), async {
loop {
let event = rx.recv().await.expect("app event channel");
if matches!(
@@ -396,6 +529,11 @@ async fn opens_agent_transcript_beside_parent_and_returns_to_chooser() -> color_
}
})
.await??;
let crate::app_event::AppEvent::AgentPickerThreadsLoaded { result, .. } = &mut discovery else {
unreachable!();
};
// Model the first request taking its snapshot before either agent was spawned.
result.as_mut().expect("initial discovery").threads.clear();
let activity = ThreadItemPayload::SubAgentActivity {
id: "started".into(),
agent_thread_id: child.to_string(),
@@ -404,6 +542,84 @@ async fn opens_agent_transcript_beside_parent_and_returns_to_chooser() -> color_
model: None,
reasoning_effort: None,
};
// Parent notifications can expose a running row before an earlier lookup has finished.
app.observe_sidebar_agent_event(&ServerNotification::ItemCompleted(
ItemCompletedNotification::new(
root.to_string(),
"parent-turn".into(),
activity.clone(),
/*started_at_ms*/ None,
/*completed_at_ms*/ 0,
),
));
assert!(
app.agent_navigation
.picker_refresh
.as_ref()
.unwrap()
.follow_up_requested,
"a lookup that started before the spawn needs a follow-up"
);
use crate::app::sidebar::PaneFocus;
use crate::app::sidebar::SidebarContent;
app.sidebar_mut()
.show(SidebarContent::Chooser, PaneFocus::Sidebar);
let size = Size::new(/*width*/ 210, /*height*/ 24);
let screen = side_frame(&mut app, &mut tui, size)?;
let loading_row = screen
.lines()
.filter_map(|line| line.split_once('│').map(|(_, row)| row.trim()))
.find(|row| row.contains("reviewer"))
.expect("visible agent loading row")
.split_whitespace()
.collect::<Vec<_>>()
.join(" ");
insta::assert_snapshot!(loading_row, @"● reviewer Loading transcript…");
let (row, column) = screen
.lines()
.enumerate()
.find_map(|(row, line)| {
let offset = line.find("reviewer")?;
Some((row as u16, line[..offset].chars().count() as u16))
})
.expect("visible disabled row");
let status_column = screen.lines().nth(usize::from(row)).unwrap();
let status_column = status_column[..status_column.find("Loading transcript…").unwrap()]
.chars()
.count() as u16;
let buffer = tui.terminal.previous_buffer();
for col in [column, status_column] {
assert!(
buffer[(col, row)]
.modifier
.contains(ratatui::style::Modifier::DIM),
"the disabled name and status both use dim text"
);
}
for kind in [
MouseEventKind::Down(MouseButton::Left),
MouseEventKind::Up(MouseButton::Left),
] {
let click = crate::app::owned_transcript::tests::mouse(kind, column, row);
Box::pin(app.handle_tui_event(&mut tui, &mut server, click)).await?;
}
assert_eq!(
app.sidebar().unwrap().choice,
0,
"click skips the disabled row"
);
assert_eq!(app.chooser_focus(), Some(PaneFocus::Sidebar));
for key in [KeyCode::Down, KeyCode::End, KeyCode::PageDown] {
Box::pin(app.handle_tui_event(&mut tui, &mut server, TuiEvent::Key(key.into()))).await?;
assert_eq!(
app.sidebar().unwrap().choice,
0,
"{key:?} skips the disabled row"
);
}
assert_eq!(app.docked_agent(), None);
app.sidebar_mut()
.show(SidebarContent::Chooser, PaneFocus::Main);
let cell = crate::multi_agents::sub_agent_activity_history_cell(&activity).unwrap();
use crate::history_cell::HistoryCell;
let lines = cell.display_hyperlink_lines(/*width*/ 80);
@@ -473,6 +689,24 @@ async fn opens_agent_transcript_beside_parent_and_returns_to_chooser() -> color_
}
assert_eq!(app.current_displayed_thread_id(), Some(root));
Box::pin(app.handle_event(&mut tui, &mut server, discovery)).await?;
assert_eq!(
app.sidebar()
.unwrap()
.agents
.pending_link
.as_ref()
.map(|link| link.agent),
Some(child),
"a click stays pending while the follow-up checks ancestry"
);
tokio::time::timeout(std::time::Duration::from_secs(5), async {
while app.current_displayed_thread_id() == Some(root) {
let event = rx.recv().await.expect("app event channel");
Box::pin(app.handle_event(&mut tui, &mut server, event)).await?;
}
Ok::<_, color_eyre::Report>(())
})
.await??;
while let Ok(event) = rx.try_recv() {
Box::pin(app.handle_event(&mut tui, &mut server, event)).await?;
}
@@ -528,6 +762,24 @@ async fn opens_agent_transcript_beside_parent_and_returns_to_chooser() -> color_
assert_eq!(app.docked_agent(), None);
let screen = side_frame(&mut app, &mut tui, Size::new(140, 20))?;
assert!(screen.contains("Subagents 2"), "{screen}");
let (row, column) = screen
.lines()
.enumerate()
.find_map(|(row, line)| {
let (main, sidebar) = line.split_once('│')?;
let offset = sidebar.find("reviewer")?;
Some((
row as u16,
(main.chars().count() + 1 + sidebar[..offset].chars().count()) as u16,
))
})
.expect("visible selectable row");
assert!(
!tui.terminal.previous_buffer()[(column, row)]
.modifier
.contains(ratatui::style::Modifier::DIM),
"the name uses normal emphasis once the transcript is available"
);
let pane = app.sidebar().unwrap();
assert!(
!pane
@@ -63,6 +63,7 @@ fn sidebar_files_chooser_matches_the_grouped_file_inventory() -> color_eyre::eyr
name: "Reviewer".into(),
symbol: "○",
status: "Completed",
selectable: true,
});
pane.choice = pane.chat_tabs().file_start();
pane.update_saved_chats(vec![ThreadId::new().into()]);
+59 -17
View File
@@ -73,12 +73,22 @@ impl Overview {
)
}
});
let (symbol, status) = state.label();
let (symbol, label) = state.label();
let confirmed = self.confirmed_members.contains(&id);
let selectable = confirmed && state != State::Starting;
let status = if selectable || state == State::Starting {
label
} else if nav.picker_refresh.is_some() {
"Loading transcript…"
} else {
"Transcript unavailable"
};
AgentRow {
id,
name,
symbol,
status,
selectable,
}
})
.collect()
@@ -258,21 +268,37 @@ impl App {
}
}
// Active or failed discovery supersedes saved history. Live notifications can arrive during
// discovery and take precedence over its response.
// Idle and unloaded threads have readable history. Clear a provisional start and let
// navigation supply the status so reconnect can still restore explicit outcomes.
pub(super) fn seed_discovered_sidebar_agent(
&mut self,
root: ThreadId,
child: ThreadId,
status: &ThreadStatus,
) {
if let Some(pane) = self.sidebars.get_mut(&Some(root))
&& (pane.agents.restored_outcomes.remove(&child)
|| !pane.agents.states.contains_key(&child))
{
pane.agents
.states
.insert(child, status::thread_status(status));
let Some(pane) = self.sidebars.get_mut(&Some(root)) else {
return;
};
match status {
ThreadStatus::Idle | ThreadStatus::NotLoaded => {
if pane.agents.states.get(&child) == Some(&State::Starting) {
pane.agents.states.remove(&child);
}
}
ThreadStatus::Active { .. } | ThreadStatus::SystemError => {
// A discovery snapshot can supersede saved history. Live updates take precedence.
if pane.agents.restored_outcomes.remove(&child)
|| pane
.agents
.states
.get(&child)
.is_none_or(|state| *state == State::Starting)
{
pane.agents
.states
.insert(child, status::thread_status(status));
}
}
}
}
@@ -302,6 +328,16 @@ impl App {
true
}
fn discover_observed_sidebar_agent(&mut self, child: ThreadId) {
if let Some(root) = self.primary_thread_id
&& !self.is_confirmed_sidebar_agent(root, child)
&& !self.agent_navigation.queue_picker_refresh(root)
{
self.app_event_tx
.send(AppEvent::DiscoverSidebarAgents(root));
}
}
pub(in crate::app) fn observe_sidebar_agent_event(&mut self, event: &ServerNotification) {
if !self.local_settings.workspace_enabled(&self.config) {
return;
@@ -336,8 +372,11 @@ impl App {
if let Ok(id) = ThreadId::from_string(&e.thread_id)
&& self.is_sidebar_agent(id)
{
self.agent_navigation
.set_running(id, matches!(e.status, ThreadStatus::Active { .. }));
let running = matches!(e.status, ThreadStatus::Active { .. });
if running {
self.discover_observed_sidebar_agent(id);
}
self.agent_navigation.set_running(id, running);
self.chat_widget.request_redraw();
}
}
@@ -352,6 +391,7 @@ impl App {
};
if let Some(activity) = sub_agent_activity_display(item) {
if self.register_sidebar_agent(parent, activity.thread_id) {
self.discover_observed_sidebar_agent(activity.thread_id);
self.agent_navigation.record_sub_agent_activity(activity);
self.chat_widget.request_redraw();
}
@@ -372,12 +412,14 @@ impl App {
}
if *tool == CollabAgentTool::SpawnAgent
&& self.register_sidebar_agent(parent, child)
&& self.agent_navigation.get(&child).is_none()
{
self.upsert_agent_picker_thread(
child, /*agent_nickname*/ None, /*agent_role*/ None,
/*is_closed*/ false,
);
self.discover_observed_sidebar_agent(child);
if self.agent_navigation.get(&child).is_none() {
self.upsert_agent_picker_thread(
child, /*agent_nickname*/ None, /*agent_role*/ None,
/*is_closed*/ false,
);
}
}
if let Some(state) = state
&& self.is_sidebar_agent(child)
@@ -6,6 +6,6 @@ expression: rows
Open in sidebar
› + New side chat Available after first message
Subagents 2
○ Source navigation reviewer with a long name Idle
● Source navigation reviewer with a long name Starting
○ Builder Completed
esc back · ↑/↓ move · ⌃x - hide pane
@@ -7,8 +7,8 @@ expression: rows
› + New side chat
Available after first message
Subagents 2
○ Source navigation reviewer with…
Idle
● Source navigation reviewer with…
Starting
○ Builder
Completed
esc back · ↑/↓ move · ⌃x - hide pane
+25 -1
View File
@@ -21,6 +21,7 @@ use codex_utils_path_uri::PathUri;
use ratatui::buffer::Buffer;
use ratatui::layout::Position;
use ratatui::layout::Rect;
use ratatui::style::Style;
use ratatui::style::Styled;
use ratatui::style::Stylize;
use ratatui::text::Line;
@@ -107,7 +108,9 @@ pub(crate) fn footer(
let movement = [ListAction::MoveUp, ListAction::MoveDown]
.into_iter()
.filter(|_| {
new_chat == NewChatState::Available || !tabs.files.is_empty() || !tabs.agents.is_empty()
new_chat == NewChatState::Available
|| !tabs.files.is_empty()
|| tabs.agents.iter().any(|agent| agent.selectable)
})
.filter_map(hint)
.collect::<Vec<_>>()
@@ -120,6 +123,7 @@ pub(crate) fn footer(
hint(ListAction::Accept)
.filter(|_| {
visible
&& !tabs.agent_is_disabled(choice)
&& (new_chat == NewChatState::Available
|| selected_file.is_some()
|| tabs.agent(choice).is_some())
@@ -206,6 +210,7 @@ pub(crate) struct AgentRow {
pub(crate) name: String,
pub(crate) symbol: &'static str,
pub(crate) status: &'static str,
pub(crate) selectable: bool,
}
#[derive(Clone, Copy)]
@@ -250,6 +255,10 @@ impl<'a> ChatTabs<'a> {
.map(|offset| self.first_agent() + offset)
}
pub(crate) fn agent_is_disabled(self, index: usize) -> bool {
self.agent(index).is_some_and(|agent| !agent.selectable)
}
fn first_agent(self) -> usize {
let end = self.choices.len() + 1;
end + usize::from(self.retry_row(end))
@@ -502,6 +511,14 @@ pub(crate) fn navigate(
.max((choice + 1).min(last)),
_ => return (choice, tabs.scroll),
};
let selectable = |index: &usize| !tabs.agent_is_disabled(*index);
let choice = match action {
ListAction::MoveDown | ListAction::PageDown => (choice..=last)
.find(selectable)
.or_else(|| (0..choice).rev().find(selectable)),
_ => (0..=choice).rev().find(selectable),
}
.unwrap_or_default();
if choice == 0 {
return (choice, ChooserScroll::default());
}
@@ -542,6 +559,7 @@ pub(crate) fn row_targets(
let first = lines.start.max(start);
let last = lines.end.min(end);
(first < last
&& !tabs.agent_is_disabled(index)
&& match tabs.file(index) {
Some(_) => tabs.file_preview_unavailable.is_none(),
None => new_chat == NewChatState::Available || tabs.agent(index).is_some(),
@@ -802,6 +820,12 @@ pub(crate) fn paint(
{
let (marker, fill, subtitle) = row_style(index);
if let Some(agent) = tabs.agent(index) {
let (marker, fill, subtitle) = if agent.selectable {
(marker, fill, subtitle)
} else {
let disabled = Style::default().dim();
(' ', disabled, disabled)
};
let name = format!("{marker} {} {}", agent.symbol, agent.name);
let status = agent.status;
if rows.wide {