From b131bf59feabcd05160283aee9fd0497e43cc3d2 Mon Sep 17 00:00:00 2001 From: "nekomimi.pet" Date: Tue, 3 Nov 2026 23:21:35 -0500 Subject: [PATCH] tui: /extensions sorts extensions onto shelves and shows everywhere and here side by side on every row --- cli/internal/tui/extension_picker.go | 179 +++++++++++++-------- cli/internal/tui/extension_shelves.go | 168 +++++++++++++++++++ cli/internal/tui/extension_shelves_test.go | 46 ++++++ cli/internal/tui/list_view.go | 98 ++++++++--- cli/internal/tui/shot_extensions_test.go | 52 ++++-- cli/test/e2e/tui_flow_test.go | 20 +-- robot-docs/tui.md | 6 + 7 files changed, 457 insertions(+), 112 deletions(-) create mode 100644 cli/internal/tui/extension_shelves.go create mode 100644 cli/internal/tui/extension_shelves_test.go diff --git a/cli/internal/tui/extension_picker.go b/cli/internal/tui/extension_picker.go index 4c7a6cdba..66ffd69ee 100644 --- a/cli/internal/tui/extension_picker.go +++ b/cli/internal/tui/extension_picker.go @@ -24,10 +24,10 @@ type extensionsLoadedMsg struct { type extensionToggledMsg struct { Err error - Extensions []ExtensionItem Notice string - Warns bool + Extensions []ExtensionItem Gen int + Warns bool } // The scopes a change can be made in, and the confirmation each asks. @@ -44,11 +44,12 @@ type ExtensionPickerModel struct { Conn *daemon.Connection SessionID string Extensions []ExtensionItem - // noticeWarns says the notice is a warning rather than a save that went through. - noticeWarns bool - pageStatus listView confirm + pageStatus + // noticeWarns says the notice is a warning rather than a save that went through. + noticeWarns bool + providersOpen, builtinsOpen bool } func NewExtensionPickerModel(conn *daemon.Connection, sessionID string) ExtensionPickerModel { @@ -62,11 +63,11 @@ func NewExtensionPickerModel(conn *daemon.Connection, sessionID string) Extensio func (m *ExtensionPickerModel) SetSize(width, height int) { m.pageStatus.SetSize(width, height) - m.listView.setSize(width, height) + m.setSize(width, height) } // Confirming reports a question waiting for enter or esc. -func (m ExtensionPickerModel) Confirming() bool { return m.confirm.asking() } +func (m ExtensionPickerModel) Confirming() bool { return m.asking() } func (m ExtensionPickerModel) Init() tea.Cmd { return m.loadExtensionsCmd(m.Generation) @@ -128,7 +129,7 @@ func (m ExtensionPickerModel) changeExtensionCmd(name, scope string, enabled boo } } -func (m ExtensionPickerModel) capabilitiesList(ext ExtensionItem) []string { +func extensionCapabilities(ext ExtensionItem) []string { var caps []string if ext.Context { caps = append(caps, "context") @@ -157,11 +158,7 @@ func (m ExtensionPickerModel) current() (ExtensionItem, bool) { func (m *ExtensionPickerModel) setExtensions(items []ExtensionItem) { m.Extensions = items - rows := make([]listEntry, len(items)) - for i, ext := range items { - rows[i] = m.entry(ext) - } - m.setRows(rows) + m.rebuildShelves() } // askToggle asks before changing an extension in scope, or before dropping @@ -180,37 +177,71 @@ func (m *ExtensionPickerModel) askToggle(scope string) { if scope == scopeSession { on = ext.Enabled } + if memoryStrategy(ext) && scope != scopeInherit { + if on { + return + } + scopeText := "globally" + if scope == scopeSession { + scopeText = "for this session" + } + prompt := fmt.Sprintf("Switch memory to %s %s?", ext.Name, scopeText) + suffix := "" + for _, old := range m.Extensions { + chosen := old.GlobalEnabled + if scope == scopeSession { + chosen = old.Enabled + } + if memoryStrategy(old) && chosen && old.Name != ext.Name { + switch old.Name { + case "coding-lcm": + suffix = " coding-lcm's summaries stay readable through the lcm tools." + case "snapcompact": + suffix = " snapcompact's images stay in the transcript." + default: + suffix = " Existing summaries stay in the transcript." + } + break + } + } + prompt += suffix + if scope == scopeSession { + prompt += " This will reload this session." + } + m.ask(scope, ext.Name, "switch", prompt) + return + } verb := "enable" if on { verb = "disable" } switch scope { case scopeInherit: - m.confirm.ask(scope, ext.Name, "follow global", fmt.Sprintf("This session will follow the global default for %s. Remove its own choice?", ext.Name)) + m.ask(scope, ext.Name, "follow global", fmt.Sprintf("This session will follow the global default for %s. Remove its own choice?", ext.Name)) case scopeSession: - m.confirm.ask(scope, ext.Name, verb, fmt.Sprintf("This will reload this session. %s %s for this session only?", strings.ToUpper(verb[:1])+verb[1:], ext.Name)) + m.ask(scope, ext.Name, verb, fmt.Sprintf("This will reload this session. %s %s for this session only?", strings.ToUpper(verb[:1])+verb[1:], ext.Name)) default: - m.confirm.ask(scope, ext.Name, verb, fmt.Sprintf("Sessions following global defaults will use this change. %s %s globally?", strings.ToUpper(verb[:1])+verb[1:], ext.Name)) + m.ask(scope, ext.Name, verb, fmt.Sprintf("Sessions following global defaults will use this change. %s %s globally?", strings.ToUpper(verb[:1])+verb[1:], ext.Name)) } } // save sends the change the confirmation asked about. func (m *ExtensionPickerModel) save() tea.Cmd { ext, ok := m.current() - if !ok || ext.Name != m.confirm.target { - m.confirm.dismiss() + if !ok || ext.Name != m.target { + m.dismiss() return nil } m.Saving, m.Error = true, "" m.Generation = nextPageGeneration() enabled := !ext.GlobalEnabled - switch m.confirm.what { + switch m.what { case scopeSession: enabled = !ext.Enabled case scopeInherit: enabled = false } - return m.changeExtensionCmd(ext.Name, m.confirm.what, enabled, m.Generation) + return m.changeExtensionCmd(ext.Name, m.what, enabled, m.Generation) } func (m ExtensionPickerModel) Update(msg tea.Msg) (ExtensionPickerModel, tea.Cmd) { @@ -227,17 +258,17 @@ func (m ExtensionPickerModel) Update(msg tea.Msg) (ExtensionPickerModel, tea.Cmd if msg.Gen == m.Generation { if apiErr, ok := errors.AsType[*daemon.APIError](msg.Err); ok && apiErr.StatusCode == 412 { m.Saving, m.Loading, m.Error = false, true, "" - m.confirm.dismiss() + m.dismiss() m.Notice, m.noticeWarns = "The configuration changed. Review the refreshed choices before saving.", true m.Generation = nextPageGeneration() return m, m.loadExtensionsCmd(m.Generation) } } if !m.settle(msg.Gen, msg.Err, &m.Saving) { - m.confirm.failed = msg.Gen == m.Generation + m.failed = msg.Gen == m.Generation return m, nil } - m.confirm.dismiss() + m.dismiss() m.setExtensions(msg.Extensions) m.Error = "" m.Notice, m.noticeWarns = msg.Notice, msg.Warns @@ -246,12 +277,12 @@ func (m ExtensionPickerModel) Update(msg tea.Msg) (ExtensionPickerModel, tea.Cmd case tea.KeyPressMsg: key := msg.String() switch { - case m.confirm.asking() && !m.Saving: - if m.confirm.key(msg) { + case m.asking() && !m.Saving: + if m.key(msg) { cmd := m.save() return m, cmd } - if !m.confirm.asking() { + if !m.asking() { m.Error = "" } return m, nil @@ -263,7 +294,17 @@ func (m ExtensionPickerModel) Update(msg tea.Msg) (ExtensionPickerModel, tea.Cmd ext, _ := m.current() switch key { case "enter": - m.askToggle(scopeGlobal) + if row, ok := m.highlighted(); ok && row.heading { + switch row.group { + case "providers": + m.providersOpen = !m.providersOpen + case "builtins": + m.builtinsOpen = !m.builtinsOpen + } + m.rebuildShelves() + } else { + m.askToggle(scopeGlobal) + } case "shift+enter", "alt+enter": m.askToggle(scopeSession) case "ctrl+x": @@ -282,31 +323,21 @@ func (m ExtensionPickerModel) Update(msg tea.Msg) (ExtensionPickerModel, tea.Cmd m.Generation = nextPageGeneration() return m, m.loadExtensionsCmd(m.Generation) default: - cmd := m.listView.update(msg) + before := m.input.Value() + cmd := m.update(msg) + if before != m.input.Value() { + m.rebuildShelves() + } return m, cmd } return m, nil } - cmd := m.listView.update(msg) - return m, cmd -} - -// entry is how an extension reads in the list: its state in this session in -// front, daggered when that is the session's own choice. -func (m ExtensionPickerModel) entry(ext ExtensionItem) listEntry { - lead, tag := daggered(stateLead(ext.Enabled), ext.Overridden), "" - if ext.Quarantined != "" { - lead, tag = DefaultStyles.Error.Render("bad"), DefaultStyles.Error.Render("quarantined") - } - return listEntry{ - key: ext.Name, - lead: lead, - name: ext.Name, - desc: ext.Description, - tag: tag, - search: append(slices.Clone(ext.Plugins), ext.Requires...), - detail: func(width int) []string { return m.details(ext, "", width) }, + before := m.input.Value() + cmd := m.update(msg) + if before != m.input.Value() { + m.rebuildShelves() } + return m, cmd } func stateLead(on bool) string { @@ -339,23 +370,27 @@ func onOff(on bool) string { return "off" } -// details is the pane: both choices, the one a question asks about first, -// what the extension provides, and what each key would change. -func (m ExtensionPickerModel) details(ext ExtensionItem, asked string, width int) []string { +// extensionDetails returns pane facts, with the scope being confirmed first. +func extensionDetails(ext ExtensionItem, asked string, width int) []string { lines := paneTitle(ext.Name, ext.Description, width) - session := "follows global" + if ext.Quarantined != "" { + for _, line := range svWrap("quarantined: "+ext.Quarantined, width, 6) { + lines = append(lines, DefaultStyles.Error.Render(line)) + } + lines = append(lines, "") + } + session := "follows everywhere" if ext.Overridden { session = onOff(ext.Enabled) + " (its own choice)" } - lines = append(lines, scopeRows(onOff(ext.GlobalEnabled)+" default", session, asked, width)...) - lines = append(lines, factRows("plugins", joinOr(ext.Plugins, ", ", "not reported"), width)...) - lines = append(lines, factRows("provides", joinOr(m.capabilitiesList(ext), " · ", "not reported"), width)...) - lines = append(lines, factRows("requires", joinOr(ext.Requires, ", ", "none"), width)...) + facts := [][]string{factRows("everywhere", onOff(ext.GlobalEnabled), width), factRows("here", session, width)} + if asked == scopeSession || asked == scopeInherit { + slices.Reverse(facts) + } + lines = append(lines, slices.Concat(facts...)...) + lines = append(lines, factRows("needs", joinOr(ext.Requires, ", ", "none"), width)...) + lines = append(lines, factRows("provides", joinOr(extensionCapabilities(ext), " · ", "not reported"), width)...) if ext.Quarantined != "" { - lines = append(lines, "") - for _, l := range svWrap("quarantined: "+ext.Quarantined, width, 6) { - lines = append(lines, DefaultStyles.Error.Render(l)) - } return lines } switch asked { @@ -385,21 +420,24 @@ func joinOr(items []string, sep, empty string) string { } func (m ExtensionPickerModel) footer(width int) string { - if m.confirm.asking() && !m.Saving { + if m.asking() && !m.Saving { return m.confirm.footer(width, m.Error) } if len(m.Extensions) == 0 && m.Error != "" { return footerLine(width, []hint{{"ctrl+r", "retry"}, {"esc", "back"}}, DefaultStyles.Error.Render(m.Error), true) } ext, _ := m.current() - hints := []hint{{"↑↓", "move"}, {"enter", "global"}, {"shift+enter", "this session"}} + hints := []hint{{"↑↓", "move"}, {"enter", "everywhere"}, {"shift+enter", "here"}} + if row, ok := m.highlighted(); ok && row.heading { + hints = []hint{{"↑↓", "move"}, {"enter", "open/close"}} + } if ext.Overridden { hints = append(hints, hint{"ctrl+x", "follow global"}) } if (ext.Name == "webhooks" || ext.Name == "discord") && ext.Enabled { hints = append(hints, hint{"ctrl+w", ext.Name}) } - hints = append(hints, hint{"esc", "back"}) + hints = append(hints, hint{"ctrl+r", "refresh"}, hint{"esc", "back"}) var status string urgent := true @@ -433,10 +471,19 @@ func (m ExtensionPickerModel) View() string { case m.Error != "" && len(m.Extensions) == 0: lv.Empty = "Could not load extensions; the reason is in the footer." } - marked := slices.ContainsFunc(m.Extensions, func(e ExtensionItem) bool { return e.Overridden && e.Quarantined == "" }) - frame := lv.frame(brand("albedo")+" "+DefaultStyles.Muted.Render("/extensions"), daggerLegend(marked), m.footer(max(1, m.Width))) - if ext, ok := m.current(); ok && m.confirm.asking() { - frame.pane = detailPane(func(width int) []string { return m.details(ext, m.confirm.what, width) }) + own := 0 + for _, ext := range m.Extensions { + if ext.Overridden { + own++ + } + } + right := "" + if own > 0 { + right = DefaultStyles.Muted.Render(fmt.Sprintf("%d own choices here", own)) + } + frame := lv.frame(brand("albedo")+" "+DefaultStyles.Muted.Render("/extensions"), right, m.footer(max(1, m.Width))) + if ext, ok := m.current(); ok && m.asking() { + frame.pane = detailPane(func(width int) []string { return extensionDetails(ext, m.what, width) }) } return frame.view(m.Width, m.Height) } diff --git a/cli/internal/tui/extension_shelves.go b/cli/internal/tui/extension_shelves.go new file mode 100644 index 000000000..6715b5dfd --- /dev/null +++ b/cli/internal/tui/extension_shelves.go @@ -0,0 +1,168 @@ +package tui + +import ( + "fmt" + "slices" + "strings" + + "github.com/charmbracelet/x/ansi" +) + +type extensionShelf struct{ key, name, note string } + +var extensionShelves = []extensionShelf{ + {"memory", "Memory", "how it remembers · one at a time"}, + {"reach", "Reach", "what it can touch"}, + {"channels", "Channels", "how the world reaches it"}, + {"providers", "Providers", "the models it can think with"}, + {"builtins", "Builtins", "albedo's own core"}, +} + +func memoryStrategy(ext ExtensionItem) bool { + return ext.Shelf == "memory" && ext.Name != "notes" +} + +func (m *ExtensionPickerModel) rebuildShelves() { + var rows []listEntry + filtered := strings.TrimSpace(m.input.Value()) != "" + for _, shelf := range extensionShelves { + var items []ExtensionItem + for _, ext := range m.Extensions { + if ext.Shelf == shelf.key || (ext.Shelf == "" && shelf.key == "reach") { + items = append(items, ext) + } + } + if len(items) == 0 { + continue + } + // Notes is a layer after the mutually exclusive strategies. + if shelf.key == "memory" { + slices.SortStableFunc(items, func(a, b ExtensionItem) int { + if a.Name == "notes" && b.Name != "notes" { + return 1 + } + if b.Name == "notes" && a.Name != "notes" { + return -1 + } + return 0 + }) + } + foldable := shelf.key == "providers" || shelf.key == "builtins" + open := (shelf.key == "providers" && m.providersOpen) || (shelf.key == "builtins" && m.builtinsOpen) + if foldable { + on, own := 0, 0 + for _, ext := range items { + if ext.GlobalEnabled { + on++ + } + if ext.Overridden { + own++ + } + } + global := fmt.Sprintf("%d on", on) + if on == len(items) { + global = "all on" + } + here := "·" + if own > 0 { + here = fmt.Sprintf("%d own", own) + } + arrow := "▸" + if open { + arrow = "▾" + } + name := fmt.Sprintf("%s %s %d", arrow, shelf.name, len(items)) + rows = append(rows, listEntry{key: "shelf:" + shelf.key, group: shelf.key, name: shelf.name, heading: true, + draw: func(width int, _ []int) string { + if open || filtered { + return shelfColumns(name, shelf.note, "everywhere", "here", width, true) + } + return shelfColumns(name, shelf.note, global, here, width, true) + }, + detail: func(width int) []string { + lines := paneTitle(shelf.name, shelf.note, width) + if shelf.key == "builtins" { + lines = append(lines, paneNote("Turning one off also turns off what needs it.", width)...) + } + return append(lines, paneNote("Enter opens or closes this shelf. Search includes its extensions while folded.", width)...) + }, + }) + } + for _, ext := range items { + row := extensionEntry(ext) + row.group = shelf.key + row.hidden = foldable && !open + rows = append(rows, row) + } + } + m.groupTitle = func(group string, width int) string { + for _, shelf := range extensionShelves { + if shelf.key == group { + if group == "providers" || group == "builtins" { + return "" + } + return " " + shelfColumns(shelf.name, shelf.note, "everywhere", "here", max(1, width-3), true) + } + } + return "" + } + m.setRows(rows) +} + +func extensionEntry(ext ExtensionItem) listEntry { + name := ext.Name + if name == "notes" { + name = "+ notes" + } + global, here := stateLead(ext.GlobalEnabled), DefaultStyles.Faint.Render("·") + if memoryStrategy(ext) { + global = memoryDot(ext.GlobalEnabled) + } + if ext.Overridden { + here = stateLead(ext.Enabled) + if memoryStrategy(ext) { + here = memoryDot(ext.Enabled) + } + here = DefaultStyles.Bold.Render(here) + } + return listEntry{ + key: ext.Name, name: name, desc: ext.Summary, + search: slices.Concat([]string{ext.Description, ext.Shelf}, ext.Plugins, ext.Requires), + draw: func(width int, hits []int) string { + style := DefaultStyles.Bold.UnsetBold() + if ext.Quarantined != "" { + style = DefaultStyles.Error + } + label := markedCell(name, hits, min(17, max(1, width-22)), style) + return shelfColumns(label, ext.Summary, global, here, width, false) + }, + detail: func(width int) []string { return extensionDetails(ext, "", width) }, + } +} + +func memoryDot(on bool) string { + if on { + return DefaultStyles.Success.Render("●") + } + return DefaultStyles.Faint.Render("○") +} + +// shelfColumns keeps both scope columns when the summary no longer fits. +func shelfColumns(name, summary, global, here string, width int, heading bool) string { + const globalW, hereW = 10, 6 + leftW := max(1, width-globalW-hereW-3) + nameW := min(17, leftW) + if heading { + nameW = min(ansi.StringWidth(name), leftW) + } + left := svCell(name, nameW, false) + if heading { + left = DefaultStyles.Bold.Render(left) + } + room := leftW - nameW - 2 + if room >= 12 { + left += DefaultStyles.Faint.Render(" " + ansi.Truncate(summary, room, "…")) + } + left += strings.Repeat(" ", max(0, leftW-ansi.StringWidth(left))) + return left + " " + svCell(global, globalW, false) + " " + svCell(here, hereW, false) +} diff --git a/cli/internal/tui/extension_shelves_test.go b/cli/internal/tui/extension_shelves_test.go new file mode 100644 index 000000000..66dc727b4 --- /dev/null +++ b/cli/internal/tui/extension_shelves_test.go @@ -0,0 +1,46 @@ +// These tests catch folded headings moving behind later groups and filters +// losing hidden rows. The daemon tests cannot exercise terminal list state. +package tui + +import ( + "slices" + "testing" + + tea "charm.land/bubbletea/v2" +) + +func TestExtensionShelvesKeepOrderAcrossFolding(t *testing.T) { + m := extensionsModel(120, 30, nil) + for range 2 { + var groups []string + for _, shown := range m.shown { + group := m.rows[shown.row].group + if len(groups) == 0 || groups[len(groups)-1] != group { + groups = append(groups, group) + } + } + if !slices.Equal(groups, []string{"memory", "reach", "channels", "providers", "builtins"}) { + t.Fatalf("shelves split or reordered: %v", groups) + } + m.refilter("shelf:builtins") + m, _ = m.Update(tea.KeyPressMsg{Code: tea.KeyEnter}) + } +} + +func TestExtensionFilterIncludesFoldedRowsAndRestoresFolds(t *testing.T) { + m := extensionsModel(120, 30, nil) + m, _ = m.Update(tea.PasteMsg{Content: "codex"}) + ext, ok := m.current() + if !ok || ext.Name != "codex" { + t.Fatalf("filter did not reach folded provider: %v", ext.Name) + } + if len(m.shown) != 2 || !m.rows[m.shown[0].row].heading { + t.Fatal("filtered row lost its shelf heading") + } + m, _ = m.Update(tea.KeyPressMsg{Code: 'u', Mod: tea.ModCtrl}) + for _, shown := range m.shown { + if m.rows[shown.row].key == "codex" { + t.Fatal("clearing filter unfolded providers") + } + } +} diff --git a/cli/internal/tui/list_view.go b/cli/internal/tui/list_view.go index 0297b5a4e..7b4f7436f 100644 --- a/cli/internal/tui/list_view.go +++ b/cli/internal/tui/list_view.go @@ -13,21 +13,24 @@ import ( // listEntry is one entry of a list screen: how it draws, what the filter // matches, and what its detail pane says. type listEntry struct { - key string // names the row across reloads, so the cursor stays on it - group string // sections of one group sit together under its heading - section string // rows of one section sit together under its rule - lead string // styled state before the name, padded to the widest - name string // what the filter underlines - desc string // faint after the name, and searched - tag string // styled, at the right edge - faint bool // a row that is done with, drawn faint unless selected + key string // names the row across reloads, so the cursor stays on it + group string // sections of one group sit together under its heading + section string // rows of one section sit together under its rule + lead string // styled state before the name, padded to the widest + name string // what the filter underlines + desc string // faint after the name, and searched + tag string // styled, at the right edge + detail func(width int) []string // the pane's lines; nil leaves it blank + draw func(width int, hits []int) string // optional row contents, without selection search []string - detail func(width int) []string // the pane's lines; nil leaves it blank + heading bool // selectable heading for a foldable group + hidden bool // hidden only while the filter is empty + faint bool // a row that is done with, drawn faint unless selected } type listShown struct { - row int hits []int + row int } // listView is the state every list screen shares: a filter that is always @@ -35,13 +38,14 @@ type listShown struct { // or type belong to it; keys that act on a row belong to the screen, which // asks for them first. Actions are therefore never bare letters. type listView struct { - input textinput.Model - rows []listEntry - shown []listShown - Cursor int - height int + rows []listEntry + shown []listShown // Empty is said when there are no rows at all. - Empty string + Empty string + groupTitle func(group string, width int) string + input textinput.Model + Cursor int + height int } // newFilter is a focused search field. @@ -88,6 +92,17 @@ func (l *listView) refilter(keep string) { var order []bucket buckets := map[bucket][]scored{} for i, r := range l.rows { + if r.heading { + if len(words) == 0 { + b := bucket{r.group, r.section} + order = append(order, b) + buckets[b] = []scored{{shown: listShown{row: i}}} + } + continue + } + if r.hidden && len(words) == 0 { + continue + } rank, hits, ok := matchFields(words, append([]string{r.name, r.desc}, r.search...)...) if !ok { continue @@ -96,7 +111,7 @@ func (l *listView) refilter(keep string) { if _, seen := buckets[b]; !seen { order = append(order, b) } - buckets[b] = append(buckets[b], scored{listShown{i, hits}, rank}) + buckets[b] = append(buckets[b], scored{listShown{row: i, hits: hits}, rank}) } if len(words) > 0 { for _, g := range buckets { @@ -113,6 +128,17 @@ func (l *listView) refilter(keep string) { } sections[b.group] = append(sections[b.group], b) } + // Foldable headings stay with matching children; closed groups remain browsable. + for i, r := range l.rows { + if !r.heading || len(words) == 0 { + continue + } + b := bucket{r.group, r.section} + if _, exists := buckets[b]; !exists { + continue + } + buckets[b] = append([]scored{{shown: listShown{row: i}}}, buckets[b]...) + } l.shown = l.shown[:0] for _, group := range groups { for _, b := range sections[group] { @@ -122,6 +148,9 @@ func (l *listView) refilter(keep string) { } } l.Cursor = max(0, slices.IndexFunc(l.shown, func(s listShown) bool { return l.rows[s.row].key == keep })) + if keep == "" && len(words) > 0 && len(l.shown) > 1 && l.rows[l.shown[0].row].heading { + l.Cursor = 1 + } } func (l listView) highlighted() (listEntry, bool) { @@ -211,7 +240,13 @@ func (l listView) list(width, height int) []string { if len(all) > 0 { all = append(all, line{shown: -1}) } - all = append(all, line{text: groupHeading(r.group, width), shown: -1}) + heading := groupHeading(r.group, width) + if l.groupTitle != nil { + heading = l.groupTitle(r.group, width) + } + if heading != "" { + all = append(all, line{text: heading, shown: -1}) + } } if r.section != "" && (prev == nil || prev.group != r.group || prev.section != r.section) { run := 1 @@ -235,7 +270,17 @@ func (l listView) list(width, height int) []string { // A window never ends on a heading with none of its rows under it, and // one that starts inside a group shows that group's heading on top. start, cut := windowStart(len(all), selectedAt, height), len(all) > height && height >= 3 - orphan := func() bool { return cut && start < len(all)-height && all[start+height-2].shown < 0 } + headingAt := func(at int) bool { + if all[at].shown < 0 { + return true + } + r := l.rows[l.shown[all[at].shown].row] + if !r.heading || at+1 >= len(all) || all[at+1].shown < 0 { + return false + } + return l.rows[l.shown[all[at+1].shown].row].group == r.group + } + orphan := func() bool { return cut && start < len(all)-height && headingAt(start+height-2) } for orphan() && start > 0 && selectedAt < start+height-3 { start-- } @@ -250,6 +295,10 @@ func (l listView) list(width, height int) []string { }, start, width, height) if cut && start > 0 && all[start+1].shown >= 0 { for i := start; i >= 0; i-- { + if all[i].shown >= 0 && l.rows[l.shown[all[i].shown].row].heading { + out[0] = svFit(l.row(l.shown[all[i].shown], false, width, leadW, nameW), width) + break + } if all[i].shown < 0 && all[i].text != "" { out[0] = svFit(all[i].text, width) break @@ -261,6 +310,17 @@ func (l listView) list(width, height int) []string { func (l listView) row(s listShown, selected bool, width, leadW, nameW int) string { r := l.rows[s.row] + if r.draw != nil { + bar := " " + if selected { + bar = selectBar() + } + line := bar + " " + r.draw(max(1, width-3), s.hits) + if selected { + return selectedLine(line, width) + } + return line + } bar, nameStyle := " ", lipgloss.NewStyle() switch { case selected: diff --git a/cli/internal/tui/shot_extensions_test.go b/cli/internal/tui/shot_extensions_test.go index b7a97939b..c145f87d7 100644 --- a/cli/internal/tui/shot_extensions_test.go +++ b/cli/internal/tui/shot_extensions_test.go @@ -9,7 +9,6 @@ import ( func init() { enter := tea.KeyPressMsg{Code: tea.KeyEnter} shiftEnter := tea.KeyPressMsg{Code: tea.KeyEnter, Mod: tea.ModShift} - down := tea.KeyPressMsg{Code: tea.KeyDown} typed := func(text string) []tea.Msg { var keys []tea.Msg for _, r := range text { @@ -19,15 +18,20 @@ func init() { } registerShots("extensions", shotState{"list", extensionsShot(nil)}, - shotState{"filtering", extensionsShot(nil, typed("bs")...)}, + shotState{"filtering", extensionsShot(nil, typed("codex")...)}, shotState{"no-match", extensionsShot(nil, typed("zzz")...)}, - shotState{"quarantined", extensionsShot(nil, down, down, down)}, - shotState{"confirm-global", extensionsShot(nil, enter)}, - shotState{"confirm-session", extensionsShot(nil, shiftEnter)}, - shotState{"confirm-follow-global", extensionsShot(nil, tea.KeyPressMsg{Code: 'x', Mod: tea.ModCtrl})}, - shotState{"saving", extensionsShot(nil, shiftEnter, enter)}, + shotState{"quarantined", extensionsShot(func(m *ExtensionPickerModel) { m.input.SetValue("mcp"); m.refilter("") })}, + shotState{"own-choice", extensionsShot(func(m *ExtensionPickerModel) { m.input.SetValue("cua"); m.refilter("") })}, + shotState{"folded-shelf", extensionsShot(func(m *ExtensionPickerModel) { m.refilter("shelf:providers") })}, + shotState{"builtins-open", extensionsShot(func(m *ExtensionPickerModel) { m.builtinsOpen = true; m.rebuildShelves(); m.refilter("python") })}, + shotState{"confirm-memory", extensionsShot(func(m *ExtensionPickerModel) { m.refilter("persistent-agent") }, shiftEnter)}, + shotState{"confirm-global", extensionsShot(func(m *ExtensionPickerModel) { m.refilter("cua") }, enter)}, + shotState{"confirm-session", extensionsShot(func(m *ExtensionPickerModel) { m.refilter("cua") }, shiftEnter)}, + shotState{"confirm-follow-global", extensionsShot(func(m *ExtensionPickerModel) { m.refilter("cua") }, tea.KeyPressMsg{Code: 'x', Mod: tea.ModCtrl})}, + shotState{"saving", extensionsShot(func(m *ExtensionPickerModel) { m.refilter("cua") }, shiftEnter, enter)}, shotState{"save-failed", func(w, h int) string { m := extensionsModel(w, h, nil) + m.refilter("cua") m, _ = m.Update(shiftEnter) m, _ = m.Update(enter) m, _ = m.Update(extensionToggledMsg{Gen: m.Generation, Err: errors.New("daemon refused the change")}) @@ -38,9 +42,10 @@ func init() { })}, shotState{"overridden-quarantined", extensionsShot(func(m *ExtensionPickerModel) { *m, _ = m.Update(extensionsLoadedMsg{Gen: m.Generation, Extensions: append(m.Extensions, ExtensionItem{ - Name: "discord", Description: "a bot that answers in a channel", Enabled: true, Overridden: true, Quarantined: "token rejected on startup", Plugins: []string{"service"}, + Name: "discord-extra", Shelf: "channels", Description: "a bot that answers in a channel", Enabled: true, Overridden: true, Quarantined: "token rejected on startup", Plugins: []string{"service"}, })}) - }, down, down, down, down)}, + m.refilter("discord-extra") + })}, shotState{"reload-failed", func(w, h int) string { m := extensionsModel(w, h, nil) m, _ = m.Update(extensionsLoadedMsg{Gen: m.Generation, Err: errors.New("daemon connection unavailable")}) @@ -70,10 +75,31 @@ func extensionsModel(width, height int, setup func(*ExtensionPickerModel)) Exten m := NewExtensionPickerModel(nil, "s") m.SetSize(width, height) m, _ = m.Update(extensionsLoadedMsg{Gen: m.Generation, Extensions: []ExtensionItem{ - {Name: "view", Description: "show the model its changes as highlighted images", Enabled: true, Overridden: true, Plugins: []string{"tool"}, Tools: []string{"view_diff"}}, - {Name: "bash", Description: "run shell commands", Enabled: true, GlobalEnabled: true, Plugins: []string{"tool", "context"}, Context: true}, - {Name: "webhooks", Description: "signed inbound requests wake a session"}, - {Name: "mcp", Description: "tool servers", GlobalEnabled: true, Quarantined: "failed to start"}, + {Name: "rolling", Shelf: "memory", Summary: "one running summary + recent tail", Description: "Keep one running summary alongside the recent conversation.", GlobalEnabled: true}, + {Name: "coding-lcm", Shelf: "memory", Summary: "summaries tied to their sources", Description: "Linked summaries remain readable through the lcm tools.", Enabled: true, Overridden: true}, + {Name: "persistent-agent", Shelf: "memory", Summary: "its own memories, across days", Description: "Persistent memories across sessions and days."}, + {Name: "snapcompact", Shelf: "memory", Summary: "history as images, folds instantly", Description: "Compact history into rendered images."}, + {Name: "notes", Shelf: "memory", Summary: "notes it rewrites at each fold", Enabled: true, GlobalEnabled: true}, + {Name: "web-search", Shelf: "reach", Summary: "search via signed-in providers", Enabled: true, GlobalEnabled: true}, + {Name: "exa", Shelf: "reach", Summary: "exa as a search provider", Enabled: true, GlobalEnabled: true}, + {Name: "browser", Shelf: "reach", Summary: "drive chrome or chromium", Enabled: true, GlobalEnabled: true}, + {Name: "cua", Shelf: "reach", Summary: "drive native desktop apps", Description: "Control native apps through cua-driver from Python.", Enabled: true, Overridden: true, Requires: []string{"python"}, PythonModules: []string{"cua"}}, + {Name: "remote", Shelf: "reach", Summary: "run its kernel on another machine", Enabled: true, GlobalEnabled: true}, + {Name: "colab", Shelf: "reach", Summary: "google colab gpu runtimes", Enabled: true, GlobalEnabled: true}, + {Name: "view", Shelf: "reach", Summary: "see its own diffs as images", Description: "Show the model its changes as highlighted images.", Enabled: true, GlobalEnabled: true, Plugins: []string{"tool"}, Tools: []string{"view_diff"}}, + {Name: "mcp", Shelf: "reach", Summary: "tool servers over mcp", Description: "Connect external tool servers.", GlobalEnabled: true, Quarantined: "failed to start: executable not found"}, + {Name: "editor-mcp", Shelf: "reach", Summary: "mcp servers your editor shares", Enabled: true, GlobalEnabled: true}, + {Name: "discord", Shelf: "channels", Summary: "a discord bot for the session"}, + {Name: "webhooks", Shelf: "channels", Summary: "signed requests wake a session"}, + {Name: "proxy", Shelf: "channels", Summary: "your models as an openai api"}, + {Name: "hooks", Shelf: "channels", Summary: "claude code style command hooks"}, + {Name: "codex", Shelf: "providers", Summary: "your chatgpt subscription", Enabled: true, GlobalEnabled: true}, + {Name: "claude", Shelf: "providers", Summary: "anthropic models", Enabled: true, GlobalEnabled: true}, + {Name: "openai", Shelf: "providers", Summary: "openai models", Enabled: true, GlobalEnabled: true}, + {Name: "vertex", Shelf: "providers", Summary: "google cloud models"}, + {Name: "python", Shelf: "builtins", Summary: "the persistent python kernel", Enabled: true, GlobalEnabled: true}, + {Name: "run", Shelf: "builtins", Summary: "run programs", Enabled: true, GlobalEnabled: true}, + {Name: "files", Shelf: "builtins", Summary: "read and edit files", Enabled: true, GlobalEnabled: true}, }}) if setup != nil { setup(&m) diff --git a/cli/test/e2e/tui_flow_test.go b/cli/test/e2e/tui_flow_test.go index 6cca9cd10..18a4b1b26 100644 --- a/cli/test/e2e/tui_flow_test.go +++ b/cli/test/e2e/tui_flow_test.go @@ -205,24 +205,14 @@ func TestTUIExtensionPickerSwitchesCompactionStrategies(t *testing.T) { for turn, name := range []string{"coding-lcm", "rolling", "coding-lcm"} { d.Dispatch(tui.ChatExecuteCommandMsg{Name: "/extensions"}) picker := d.App.ExtensionPicker - index := -1 - for i, item := range picker.Extensions { - if item.Name == name { - index = i - if item.Enabled { - t.Fatalf("strategy %s is already enabled before its switch", name) - } - } - } + index := slices.IndexFunc(picker.Extensions, func(item tui.ExtensionItem) bool { return item.Name == name }) if index < 0 { t.Fatalf("strategy %s is missing from the actual extension picker", name) } - for d.App.ExtensionPicker.Cursor < index { - d.Dispatch(tea.KeyPressMsg{Code: tea.KeyDown}) - } - for d.App.ExtensionPicker.Cursor > index { - d.Dispatch(tea.KeyPressMsg{Code: tea.KeyUp}) + if picker.Extensions[index].Enabled { + t.Fatalf("strategy %s is already enabled before its switch", name) } + d.Type(name) d.Dispatch(tea.KeyPressMsg{Code: tea.KeyEnter, Mod: tea.ModShift}) d.Dispatch(tea.KeyPressMsg{Code: tea.KeyEnter}) if picker := d.App.ExtensionPicker; picker.Error != "" || picker.Confirming() || !strings.Contains(picker.Notice, "Reload completed.") { @@ -254,6 +244,8 @@ func TestTUIExtensionPickerSwitchesCompactionStrategies(t *testing.T) { } // Another client edited this session while the picker was open. // A stale confirmation refreshes the choices without replaying it. + d.Dispatch(tea.KeyPressMsg{Code: 'u', Mod: tea.ModCtrl}) + d.Type("rolling") d.Dispatch(tea.KeyPressMsg{Code: tea.KeyEnter, Mod: tea.ModShift}) d.Dispatch(tea.KeyPressMsg{Code: tea.KeyEnter}) picker := d.App.ExtensionPicker diff --git a/robot-docs/tui.md b/robot-docs/tui.md index de2cb6861..cf98f7d97 100644 --- a/robot-docs/tui.md +++ b/robot-docs/tui.md @@ -71,6 +71,12 @@ the one question a letter answers is the chat's direnv question above an empty c 4. call `listView.update` for movement and typing and compute its command before returning the model (`cmd := m.listView.update(msg); return m, cmd`). go does not promise the order in which `return m, m.listView.update(msg)` reads `m` and runs the call, and the returned model can miss the filter change. 5. register the screen's states for the gallery (below). +## extensions + +`/extensions` groups the catalog by its `shelf`: memory, reach, channels, providers, builtins. The picker owns folding; `listView` keeps selectable shelf headings with matching rows, including results inside folded shelves. Providers and builtins start folded. Opening builtins explains that disabling one also disables its dependants. + +Every row keeps the everywhere and here columns. A dot means this session follows everywhere; a bold value is its own choice. Each open shelf repeats the column labels in its sticky heading. Memory strategies use radio dots; notes is a separate `+ notes` layer. Enter changes everywhere, shift+enter changes here and reloads, ctrl+x follows everywhere again. Picking a different memory strategy asks to switch and explains what remains readable. The title counts own choices, and the pane shows the description, both scopes, needs, provides and quarantine failures. + ## seeing the screens `ALBEDO_SHOT_DIR` makes tests write what a view draws. nothing is written without it, so the gate never creates files. `shotTerminal(t)` gives the styles a real terminal with its own palette would get; without it a test falls back to reverse video and the selection looks wrong. -- knotmirror 0.0.1