Skip to content

mission control for agent skills

Implement TUI keybindings for jumping source groups

Alvin Unrealab3a5a0481f3
diff --git a/internal/tui/tui.go b/internal/tui/tui.go
index a4b9fb8..6c6f2b8 100644
--- a/internal/tui/tui.go
+++ b/internal/tui/tui.go
@@ -287,16 +287,20 @@ func (m appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
m.action = 0
m.actionResult = nil
m.viewport.GotoTop()
- case "tab", "right", "l":
+ case "tab":
m.filter = (m.filter + 1) % 3
m.selected = 0
m.actionResult = nil
m.viewport.GotoTop()
- case "shift+tab", "left", "h":
+ case "shift+tab":
m.filter = (m.filter + 2) % 3
m.selected = 0
m.actionResult = nil
m.viewport.GotoTop()
+ case "right", "l":
+ m.jumpSourceGroup(1)
+ case "left", "h":
+ m.jumpSourceGroup(-1)
case "down", "j":
if m.commands {
m.action++
@@ -582,6 +586,45 @@ func (m *appModel) selectCurrentSourceGroup() {
}
}
+func (m *appModel) jumpSourceGroup(direction int) {
+ items := m.filteredSkills()
+ if len(items) == 0 || direction == 0 {
+ return
+ }
+ m.clampSelection()
+ starts := sourceGroupStartIndexes(items)
+ if len(starts) <= 1 {
+ return
+ }
+ currentGroup := 0
+ for i, start := range starts {
+ if start <= m.selected {
+ currentGroup = i
+ }
+ }
+ if direction > 0 {
+ currentGroup = (currentGroup + 1) % len(starts)
+ } else {
+ currentGroup = (currentGroup + len(starts) - 1) % len(starts)
+ }
+ m.selected = starts[currentGroup]
+ m.actionResult = nil
+ m.viewport.GotoTop()
+}
+
+func sourceGroupStartIndexes(items []*model.Skill) []int {
+ starts := []int{}
+ previousGroup := ""
+ for i, skill := range items {
+ group := listGroupLabel(skill)
+ if i == 0 || group != previousGroup {
+ starts = append(starts, i)
+ previousGroup = group
+ }
+ }
+ return starts
+}
+
func (m appModel) isSelected(skill *model.Skill) bool {
return len(m.selectedKeys) > 0 && m.selectedKeys[skillKey(skill)]
}
diff --git a/internal/tui/tui_test.go b/internal/tui/tui_test.go
index 79fd9ee..669e81f 100644
--- a/internal/tui/tui_test.go
+++ b/internal/tui/tui_test.go
@@ -561,6 +561,40 @@ func TestSkillListSeparatesNoSourceMetadata(t *testing.T) {
}
}
+func TestLeftRightJumpSourceGroupsWithoutChangingScope(t *testing.T) {
+ m := appModel{width: 120, height: 32, result: model.ScanResult{Skills: []*model.Skill{
+ {Name: "One", Scope: model.ScopeProject, LocalLock: &model.LocalLockEntry{Source: "owner/one"}},
+ {Name: "Two", Scope: model.ScopeProject, LocalLock: &model.LocalLockEntry{Source: "owner/one"}},
+ {Name: "Three", Scope: model.ScopeProject, LocalLock: &model.LocalLockEntry{Source: "owner/two"}},
+ {Name: "Manual", Scope: model.ScopeProject},
+ }}}
+
+ updated, _ := m.Update(tea.KeyMsg{Type: tea.KeyRight})
+ next := updated.(appModel)
+ if next.filter != scopeAll || next.selected != 2 {
+ t.Fatalf("expected right arrow to jump to next source group without changing scope, filter=%d selected=%d", next.filter, next.selected)
+ }
+
+ updated, _ = next.Update(tea.KeyMsg{Type: tea.KeyLeft})
+ next = updated.(appModel)
+ if next.filter != scopeAll || next.selected != 0 {
+ t.Fatalf("expected left arrow to jump to previous source group without changing scope, filter=%d selected=%d", next.filter, next.selected)
+ }
+}
+
+func TestTabChangesScopeFilter(t *testing.T) {
+ m := appModel{width: 120, height: 32, result: model.ScanResult{Skills: []*model.Skill{
+ {Name: "Project", Scope: model.ScopeProject},
+ {Name: "Global", Scope: model.ScopeGlobal},
+ }}}
+
+ updated, _ := m.Update(tea.KeyMsg{Type: tea.KeyTab})
+ next := updated.(appModel)
+ if next.filter != scopeProject {
+ t.Fatalf("expected tab to switch to project scope, got %d", next.filter)
+ }
+}
+
func TestGroupedListKeepsSelectedRowVisible(t *testing.T) {
skills := []*model.Skill{}
for i := 0; i < 12; i++ {