Add session resume to the agent command center (#42419)

## What changed

- Add a configurable `agents.resume` action, bound to `Ctrl+O` by default, that opens the session resume picker from the agent command center.
- Preserve command-center state when the picker is cancelled, and preserve per-thread composer and queued-input state when switching sessions.
- Keep resume failures within the command-center flow and wrap footer shortcuts on narrow terminals.

## Testing

- Add coverage for picker cancellation, active-session selection, resume failures, per-thread input restoration, custom keybindings, and narrow footer layout.

GitOrigin-RevId: 59159f838a0c642200cd164e3af45b0971d29bf8
This commit is contained in:
Eric Traut authored and copyberry committed 2026-09-03 02:18:43 +00:00
1 parent b27a6321fa
commit 1d741742c5
25 files changed
+712 -170

No files matched your search

+106 -87
View File
@@ -1,7 +1,106 @@
//! Layout rendering and cursor placement for the agent dashboard.
//! The prompt and its cursor reserve the same height for wrapped footer hints.
use super::*;
impl AgentsOverviewView {
fn footer_lines(&self, width: u16) -> Vec<Line<'static>> {
if self.state().connection_notice.is_some() {
return vec![
"ctrl+c quit · actions paused until the list is refreshed"
.dim()
.into(),
];
}
let list_hint = |action| {
self.keymap.primary_hint(action).filter(|hint| {
!matches!(hint, ShortcutHint::Single(binding)
if is_plain_text_key_event(KeyEvent::new(
binding.parts().0,
binding.parts().1,
)) || [
&self.agents_keymap.resume,
&self.agents_keymap.search,
&self.agents_keymap.new_task,
&self.agents_keymap.rename,
&self.agents_keymap.stop,
&self.agents_keymap.toggle_grouping,
]
.into_iter()
.any(|bindings| bindings.contains(binding)))
})
};
let navigation_hints = [ListAction::MoveUp, ListAction::MoveDown]
.into_iter()
.filter_map(list_hint)
.map(|hint| hint.display_label().replace(" + ", "+"))
.collect::<Vec<_>>();
let navigation_hint = navigation_hints.join(
if navigation_hints
.iter()
.all(|hint| hint.chars().count() == 1)
{
""
} else {
" "
},
);
let mut footer_spans = Vec::new();
if !navigation_hint.is_empty() {
footer_spans.extend([navigation_hint.bold(), " navigate ".dim()]);
}
let mut add_hint = |hint: Option<ShortcutHint>, label: &'static str, enabled: bool| {
if let Some(hint) = hint {
let key = hint.display_label().replace(" + ", "+");
footer_spans.push(if enabled { key.bold() } else { key.dim() });
footer_spans.push(format!(" {label} ").dim());
}
};
add_hint(
self.agents_keymap
.primary_hint("resume", &self.agents_keymap.resume),
"resume",
true,
);
add_hint(list_hint(ListAction::Accept), "open", true);
add_hint(
self.agents_keymap
.primary_hint("search", &self.agents_keymap.search),
"search",
true,
);
add_hint(
self.agents_keymap
.primary_hint("toggle_grouping", &self.agents_keymap.toggle_grouping),
"group",
true,
);
add_hint(
self.agents_keymap
.primary_hint("rename", &self.agents_keymap.rename),
"rename",
true,
);
add_hint(
self.agents_keymap
.primary_hint("stop", &self.agents_keymap.stop),
"stop",
self.selected_row()
.is_some_and(|row| matches!(row.thread.status, ThreadStatus::Active { .. })),
);
add_hint(list_hint(ListAction::Cancel), "back", true);
let mut footer_line: Line = footer_spans.into();
if footer_line.width() > usize::from(width) {
for span in &mut footer_line.spans {
if span.content.ends_with(" ") {
span.content.to_mut().pop();
}
}
}
crate::wrapping::word_wrap_lines([footer_line], usize::from(width))
}
}
impl Renderable for AgentsOverviewView {
fn desired_height(&self, _width: u16) -> u16 {
24
@@ -20,7 +119,9 @@ impl Renderable for AgentsOverviewView {
.x
.saturating_add((label.width() + input.width()) as u16)
.min(area.right().saturating_sub(3));
Some((x, area.bottom().saturating_sub(2)))
let footer_height = (self.footer_lines(area.width.saturating_sub(4)).len() as u16)
.min(area.height.saturating_sub(7));
Some((x, area.bottom().saturating_sub(footer_height + 1)))
}
fn render(&self, area: Rect, buf: &mut Buffer) {
@@ -28,13 +129,15 @@ impl Renderable for AgentsOverviewView {
return;
}
Clear.render(area, buf);
let footer_lines = self.footer_lines(area.width.saturating_sub(4));
let footer_height = (footer_lines.len() as u16).min(area.height.saturating_sub(7));
let [header, summary, divider, body, prompt, footer] = Layout::vertical([
Constraint::Length(1),
Constraint::Length(1),
Constraint::Length(1),
Constraint::Min(3),
Constraint::Length(1),
Constraint::Length(1),
Constraint::Length(footer_height),
])
.areas(area);
let inset =
@@ -105,90 +208,6 @@ impl Renderable for AgentsOverviewView {
let input = &input[visible_start..];
Line::from(vec![label.cyan().bold(), input.into(), placeholder.dim()])
.render(inset(prompt), buf);
if state.connection_notice.is_some() {
Line::from("ctrl+c quit · actions paused until the list is refreshed".dim())
.render(inset(footer), buf);
return;
}
let list_hint = |action| {
self.keymap.primary_hint(action).filter(|hint| {
!matches!(hint, ShortcutHint::Single(binding)
if is_plain_text_key_event(KeyEvent::new(
binding.parts().0,
binding.parts().1,
)) || [
&self.agents_keymap.search,
&self.agents_keymap.new_task,
&self.agents_keymap.rename,
&self.agents_keymap.stop,
&self.agents_keymap.toggle_grouping,
]
.into_iter()
.any(|bindings| bindings.contains(binding)))
})
};
let navigation_hints = [ListAction::MoveUp, ListAction::MoveDown]
.into_iter()
.filter_map(list_hint)
.map(|hint| hint.display_label().replace(" + ", "+"))
.collect::<Vec<_>>();
let navigation_hint = navigation_hints.join(
if navigation_hints
.iter()
.all(|hint| hint.chars().count() == 1)
{
""
} else {
" "
},
);
let mut footer_spans = Vec::new();
if !navigation_hint.is_empty() {
footer_spans.extend([navigation_hint.bold(), " navigate ".dim()]);
}
let mut add_hint = |hint: Option<ShortcutHint>, label: &'static str, enabled: bool| {
if let Some(hint) = hint {
let key = hint.display_label().replace(" + ", "+");
footer_spans.push(if enabled { key.bold() } else { key.dim() });
footer_spans.push(format!(" {label} ").dim());
}
};
add_hint(list_hint(ListAction::Accept), "open", true);
add_hint(
self.agents_keymap
.primary_hint("search", &self.agents_keymap.search),
"search",
true,
);
add_hint(
self.agents_keymap
.primary_hint("toggle_grouping", &self.agents_keymap.toggle_grouping),
"group",
true,
);
add_hint(
self.agents_keymap
.primary_hint("rename", &self.agents_keymap.rename),
"rename",
true,
);
add_hint(
self.agents_keymap
.primary_hint("stop", &self.agents_keymap.stop),
"stop",
self.selected_row()
.is_some_and(|row| matches!(row.thread.status, ThreadStatus::Active { .. })),
);
add_hint(list_hint(ListAction::Cancel), "back", true);
let footer_area = inset(footer);
let mut footer_line: Line = footer_spans.into();
if footer_line.width() > usize::from(footer_area.width) {
for span in &mut footer_line.spans {
if span.content.ends_with(" ") {
span.content.to_mut().pop();
}
}
}
footer_line.render(footer_area, buf);
Paragraph::new(footer_lines).render(inset(footer), buf);
}
}