Add task group navigation to the agent command center (#62200)

## Why

Row and page navigation make users step through tasks to reach another group.

## What changed

Use `Shift+Down` or `Shift+J` to jump to the first task in the next
visible group, and `Shift+Up` or `Shift+K` to jump to the first task
in the previous group. Navigation stops at the ends of the list.

Expose `agents.next_group` and `agents.previous_group` in the keymap
picker and show the active shortcuts in Task shortcuts.

## Testing

Add coverage for jumps in both directions, list boundaries, and key
handling during search and rename. Update snapshots for shortcut help
and the keymap picker.

GitOrigin-RevId: 2542a75e7fdd7a3326c0914e19a9f5c191de082b
This commit is contained in:
Benjamin Carlsson
2026-11-18 05:49:12 +00:00
committed by copyberry
parent 89feadf3cc
commit e58677f0cb
22 changed files with 219 additions and 47 deletions
+4
View File
@@ -522,6 +522,10 @@ pub struct TuiListKeymap {
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, Default, JsonSchema)]
#[schemars(deny_unknown_fields)]
pub struct TuiAgentsKeymap {
/// Select the first task in the next group.
pub next_group: Option<KeybindingsSpec>,
/// Select the first task in the previous group.
pub previous_group: Option<KeybindingsSpec>,
/// Open the session resume picker.
pub resume: Option<KeybindingsSpec>,
/// Search the available agent tasks.
+20
View File
@@ -5496,6 +5496,8 @@
"hide": null,
"new_task": null,
"new_worktree": null,
"next_group": null,
"previous_group": null,
"rename": null,
"resume": null,
"search": null,
@@ -5935,6 +5937,22 @@
],
"description": "Open a new session in a worktree from the project default branch."
},
"next_group": {
"allOf": [
{
"$ref": "#/definitions/KeybindingsSpec"
}
],
"description": "Select the first task in the next group."
},
"previous_group": {
"allOf": [
{
"$ref": "#/definitions/KeybindingsSpec"
}
],
"description": "Select the first task in the previous group."
},
"rename": {
"allOf": [
{
@@ -6691,6 +6709,8 @@
"hide": null,
"new_task": null,
"new_worktree": null,
"next_group": null,
"previous_group": null,
"rename": null,
"resume": null,
"search": null,
@@ -25,6 +25,8 @@ impl AgentsOverviewView {
fn center_list_hint(&self, action: ListAction) -> Option<ShortcutHint> {
self.keymap.primary_hint(action).filter(|hint| {
!matches!(hint, ShortcutHint::Single(binding) if [
&self.agents_keymap.next_group,
&self.agents_keymap.previous_group,
&self.agents_keymap.resume,
&self.agents_keymap.search,
&self.agents_keymap.new_task,
@@ -69,6 +71,41 @@ impl AgentsOverviewView {
] {
navigate.push(self.center_list_hint(action), label);
}
for (action, bindings, list_action, label) in [
(
"next_group",
&self.agents_keymap.next_group,
ListAction::MoveDown,
"Next group",
),
(
"previous_group",
&self.agents_keymap.previous_group,
ListAction::MoveUp,
"Previous group",
),
] {
let primary = self.agents_keymap.primary_hint(action, bindings);
let hint = match (self.center_list_hint(list_action), primary) {
(Some(ShortcutHint::Single(row)), Some(ShortcutHint::Single(group)))
if matches!(
group.parts(),
(
KeyCode::Up | KeyCode::Down | KeyCode::Char('j' | 'k'),
KeyModifiers::SHIFT
)
) && row.parts().1.is_empty() =>
{
let shifted = key_hint::shift(row.parts().0);
bindings
.contains(&shifted)
.then_some(shifted.into())
.or(primary)
}
_ => primary,
};
navigate.push(hint, label);
}
navigate
.entries
.push(Shortcut::new(key_hint::ctrl(KeyCode::Char('c')), "Quit"));
+1
View File
@@ -7,6 +7,7 @@ mod render;
mod rows;
use super::*;
pub(super) use navigation::SectionDirection;
// Counts and filtering use the same status groups.
pub(super) const TASK_FILTERS: &[(&str, Option<AgentsOverviewGroup>)] = &[
@@ -1,5 +1,5 @@
//! Page navigation shares the rendered row layout, including group headings.
//! Command-center paging moves the viewport and selection together without wrapping at either end.
//! Section and page navigation share the rendered row layout, including group headings.
//! Navigation clamps at either end of the visible list.
use super::*;
@@ -10,6 +10,11 @@ pub(super) enum CenterRow {
ShowMore,
}
pub(in crate::app::agents_overview_view) enum SectionDirection {
Next,
Previous,
}
impl AgentsOverviewView {
pub(super) fn center_rows(
&self,
@@ -36,6 +41,39 @@ impl AgentsOverviewView {
entries
}
pub(in crate::app::agents_overview_view) fn select_section(
&mut self,
direction: SectionDirection,
) {
if self.state().rename_target.is_some() {
return;
}
let indices = self.selectable_indices();
let entries = self.center_rows(&indices, self.state().grouping);
let mut sections = Vec::new();
let mut current = None;
for row in entries {
match row {
CenterRow::Group(index) => sections.push(index),
CenterRow::Task(index) if index == self.selected => {
current = sections.len().checked_sub(1)
}
CenterRow::ShowMore if self.selected == usize::MAX => {
current = Some(sections.len())
}
CenterRow::Task(_) | CenterRow::Gap | CenterRow::ShowMore => {}
}
}
let target = current.and_then(|current| match direction {
SectionDirection::Next => current.checked_add(1),
SectionDirection::Previous => current.checked_sub(1),
});
if let Some(index) = target.and_then(|target| sections.get(target)).copied() {
self.selected = index;
self.state().show_more_selected = false;
}
}
pub(in crate::app::agents_overview_view) fn page_selection(&mut self, action: ListAction) {
let indices = self.selectable_indices();
let mut state = self.state();
@@ -462,6 +462,47 @@ async fn live_center_pages_visible_rows_without_wrapping() {
}
}
#[tokio::test]
async fn live_center_navigates_sections() {
let mut app = make_test_app().await;
let config: TuiKeymap =
toml::from_str("[agents]\nnext_group = ['shift-down', 'shift-j', 'f8']").unwrap();
app.keymap = RuntimeKeymap::from_config(&config).unwrap();
let threads = (0..6)
.map(|index| {
let mut thread = overview_thread(
ThreadId::from_u128(100 + index),
/*parent_thread_id*/ None,
&format!("Section task {index}"),
ThreadStatus::Idle,
);
thread.updated_at -= index as i64;
thread.cwd = test_path_buf(&format!("/tmp/project-{}", index / 2)).abs();
thread
})
.collect();
let mut view = app.agents_overview_view(threads, Some(ThreadId::from_u128(/*value*/ 101)));
let selected = |view: &AgentsOverviewView| view.rows[view.selected_index().unwrap()].thread_id;
for (key, expected) in [
(KeyEvent::new(KeyCode::Down, KeyModifiers::SHIFT), 102),
(KeyCode::Char('J').into(), 104),
(KeyEvent::new(KeyCode::Char('j'), KeyModifiers::SHIFT), 104),
(KeyEvent::new(KeyCode::Up, KeyModifiers::SHIFT), 102),
(KeyCode::Char('K').into(), 100),
(KeyEvent::new(KeyCode::Char('k'), KeyModifiers::SHIFT), 100),
] {
view.handle_key_event(key);
assert_eq!(selected(&view), ThreadId::from_u128(expected));
}
view.handle_key_event(KeyCode::Char('/').into());
view.handle_key_event(KeyCode::Char('J').into());
assert!(screen(&view, /*width*/ 80, /*height*/ 18).contains("Search › J"));
view.handle_key_event(KeyCode::Esc.into());
view.handle_key_event(KeyCode::Char('r').into());
view.handle_key_event(KeyCode::F(8).into());
assert_eq!(selected(&view), ThreadId::from_u128(/*value*/ 100));
}
#[tokio::test]
async fn live_center_metadata_clips_at_grapheme_boundaries() {
let app = make_test_app().await;
@@ -723,6 +723,15 @@ impl BottomPaneView for AgentsOverviewView {
return;
}
if self.agents_keymap.next_group.is_pressed(key) {
self.select_section(command_center::SectionDirection::Next);
return;
}
if self.agents_keymap.previous_group.is_pressed(key) {
self.select_section(command_center::SectionDirection::Previous);
return;
}
if self.agents_keymap.search.is_pressed(key) {
let mut state = self.state();
if state.rename_target.is_none() {
@@ -7,16 +7,16 @@ expression: "screen(&view, 100, 24)"
────────────────────────────────────────────────────────────────────────────────────────────────
Task shortcuts
Navigate Tasks View
k Up n New tab/⇧tab Filter
j Down w New worktree f3 Search
enter Open o Resume g Group
pgdn Page down f Fork
⌃c Quit z r Rename
x Stop
h Hide
backspace Delete
z p Pin/unpin
Navigate Tasks View
k Up n New tab/⇧tab Filter
j Down w New worktree f3 Search
enter Open o Resume g Group
pgdn Page down f Fork
⇧j Next group z r Rename
⇧k Previous group x Stop
⌃c Quit h Hide
backspace Delete
z p Pin/unpin
@@ -13,6 +13,8 @@ expression: "screen(&view, width, height)"
enter Open
pgup Page up
pgdn Page down
⇧↓ Next group
⇧↑ Previous group
⌃c Quit
Tasks
@@ -31,6 +33,4 @@ expression: "screen(&view, width, height)"
f3 Search
g Group
esc back
@@ -8,16 +8,16 @@ expression: "screen(&view, width, height)"
────────────────────────────────────────────────────────────────────────────────────────────────
Task shortcuts
Navigate Tasks View
↑ Up n New tab/⇧tab Filter
↓ Down w New worktree f3 Search
enter Open o Resume g Group
pgup Page up f Fork
pgdn Page down r Rename
⌃c Quit x Stop
a Archive
h Hide
backspace Delete
Navigate Tasks View
↑ Up n New tab/⇧tab Filter
↓ Down w New worktree f3 Search
enter Open o Resume g Group
pgup Page up f Fork
pgdn Page down r Rename
⇧↓ Next group x Stop
⇧↑ Previous group a Archive
⌃c Quit h Hide
backspace Delete
@@ -7,21 +7,21 @@ expression: "screen(&view, width, height)"
────────────────────────────────────────────────────────
Task shortcuts
Navigate Tasks
↑ Up n New
↓ Down w New worktree
enter Open o Resume
pgup Page up f Fork
pgdn Page down r Rename
⌃c Quit x Stop
a Archive
h Hide
backspace Delete
Navigate Tasks
↑ Up n New
↓ Down w New worktree
enter Open o Resume
pgup Page up f Fork
pgdn Page down r Rename
⇧↓ Next group x Stop
⇧↑ Previous group a Archive
⌃c Quit h Hide
backspace Delete
View
tab/⇧tab Filter
f3 Search
g Group
View
tab/⇧tab Filter
f3 Search
g Group
@@ -13,6 +13,8 @@ expression: "screen(&view, width, height)"
enter Open
pgup Page up
pgdn Page down
⇧↓ Next group
⇧↑ Previous group
⌃c Quit
Tasks
@@ -22,7 +24,5 @@ expression: "screen(&view, width, height)"
f Fork
r Rename
x Stop
a Archive
h Hide
… resize to see all
esc back
+16
View File
@@ -478,6 +478,8 @@ impl ListKeymap {
/// Task-management shortcuts specific to the agents dashboard.
#[derive(Clone, Debug)]
pub(crate) struct AgentsKeymap {
pub(crate) next_group: Vec<KeyBinding>,
pub(crate) previous_group: Vec<KeyBinding>,
pub(crate) resume: Vec<KeyBinding>,
pub(crate) search: Vec<KeyBinding>,
pub(crate) new_task: Vec<KeyBinding>,
@@ -1539,6 +1541,8 @@ impl RuntimeKeymap {
};
let mut agents = AgentsKeymap {
next_group: resolve_local!(keymap, defaults, agents, next_group),
previous_group: resolve_local!(keymap, defaults, agents, previous_group),
resume: resolve_local!(keymap, defaults, agents, resume),
search: resolve_local!(keymap, defaults, agents, search),
new_task: resolve_local!(keymap, defaults, agents, new_task),
@@ -1556,6 +1560,11 @@ impl RuntimeKeymap {
// New defaults yield to explicit bindings, including existing list shortcuts.
for (configured, bindings) in [
(keymap.agents.next_group.as_ref(), &mut agents.next_group),
(
keymap.agents.previous_group.as_ref(),
&mut agents.previous_group,
),
(keymap.agents.resume.as_ref(), &mut agents.resume),
(keymap.agents.search.as_ref(), &mut agents.search),
(keymap.agents.new_task.as_ref(), &mut agents.new_task),
@@ -1727,6 +1736,11 @@ impl RuntimeKeymap {
};
for (configured, bindings) in [
(keymap.agents.next_group.as_ref(), &mut agents.next_group),
(
keymap.agents.previous_group.as_ref(),
&mut agents.previous_group,
),
(keymap.agents.resume.as_ref(), &mut agents.resume),
(keymap.agents.search.as_ref(), &mut agents.search),
(keymap.agents.new_task.as_ref(), &mut agents.new_task),
@@ -2189,6 +2203,8 @@ impl RuntimeKeymap {
chord_hints: Arc::default(),
},
agents: AgentsKeymap {
next_group: default_bindings![shift(KeyCode::Down), shift(KeyCode::Char('j'))],
previous_group: default_bindings![shift(KeyCode::Up), shift(KeyCode::Char('k'))],
resume: default_bindings![plain(KeyCode::Char('o'))],
search: default_bindings![plain(KeyCode::F(3)), plain(KeyCode::Char('/'))],
new_task: default_bindings![plain(KeyCode::Char('n'))],
+2
View File
@@ -492,6 +492,8 @@ define_runtime_action_bindings! {
cancel,
],
"agents" => Agents, agents, agents [
next_group,
previous_group,
resume,
search,
new_task,
+2
View File
@@ -294,6 +294,8 @@ define_keymap_actions! {
cancel => "Cancel and close selection views.",
}
agents "Agents" {
next_group => "Select the first task in the next group.",
previous_group => "Select the first task in the previous group.",
resume => "Open the session resume picker.",
search => "Search the available agent tasks.",
new_task => "Open a new session in the selected checkout.",
@@ -2,6 +2,8 @@
source: tui/src/keymap_setup.rs
expression: agents
---
Next Group | shift-down, shift-j | Agents next_group Next Group Select the first task in the next group. shift-down, shift-j Default
Previous Group | shift-up, shift-k | Agents previous_group Previous Group Select the first task in the previous group. shift-up, shift-k Default
Resume | o | Agents resume Resume Open the session resume picker. o Default
Search | f3, / | Agents search Search Search the available agent tasks. f3, / Default
New Task | n | Agents new_task New Task Open a new session in the selected checkout. n Default
@@ -5,7 +5,7 @@ expression: "render_picker(params, 120)"
Keymap
All configurable shortcuts.
156 actions, 1 customized, 5 unbound.
158 actions, 1 customized, 5 unbound.
All Common Customized (1) Unbound (5) App Composer Editor Vim Navigation Agents Approval ›
@@ -5,7 +5,7 @@ expression: "render_picker(params, 120)"
Keymap
All configurable shortcuts.
157 actions, 0 customized, 6 unbound.
159 actions, 0 customized, 6 unbound.
All Common Customized (0) Unbound (6) App Composer Editor Vim Navigation Agents Approval ›
@@ -2,7 +2,7 @@
source: tui/src/keymap_setup.rs
expression: snapshot
---
tab: All (156 selectable)
tab: All (158 selectable)
tab: Common (20 selectable)
tab: Customized (0) (0 selectable)
tab: Unbound (5) (5 selectable)
@@ -11,7 +11,7 @@ tab: Composer (7 selectable)
tab: Editor (17 selectable)
tab: Vim (69 selectable)
tab: Navigation (22 selectable)
tab: Agents (11 selectable)
tab: Agents (13 selectable)
tab: Approval (8 selectable)
tab: Debug (1 selectable)
Open Agents | unbound | Global open_agents Open Agents Open the agent command center. unbound Default
@@ -5,7 +5,7 @@ expression: "render_picker(params, 120)"
Keymap
All configurable shortcuts.
156 actions, 1 customized, 8 unbound.
158 actions, 1 customized, 8 unbound.
All Common Customized (1) Unbound (8) App Composer Editor Vim Navigation Agents Approval ›
@@ -5,7 +5,7 @@ expression: "render_picker(params, 78)"
Keymap
All configurable shortcuts.
156 actions, 0 customized, 5 unbound.
158 actions, 0 customized, 5 unbound.
All Common Customized (0) Unbound (5) App Composer Editor ›
@@ -5,7 +5,7 @@ expression: "render_picker(params, 120)"
Keymap
All configurable shortcuts.
156 actions, 0 customized, 5 unbound.
158 actions, 0 customized, 5 unbound.
All Common Customized (0) Unbound (5) App Composer Editor Vim Navigation Agents Approval ›