diff --git a/cmd/agentop/README.md b/cmd/agentop/README.md index 176d7e4c0..823b32163 100644 --- a/cmd/agentop/README.md +++ b/cmd/agentop/README.md @@ -674,7 +674,7 @@ agentop is for, and the others are surfaces you visit and leave. updated 7s ago (every 20s) - [m] metric [w] window [b] breakdown [s] this session [esc] back [?] keys [q] quit + [m] metric [w] 10m [o] breakdown [/] search [esc] back [?] keys [q] quit ``` Under `latency` the bars give way to mean-with-whiskers and the breakdown @@ -863,7 +863,7 @@ Layered on top of all of them: | `n` / `N` | any pane with a search, and the key help | next / previous match, wrapping at both ends; in a text view an off-screen match is scrolled to a third of the way down | | `x` | sessions, agents | erase the row under the cursor, in memory and on disk: the highlighted session, or every session of the highlighted agent — on *All agents*, every session this Cortex holds; that confirmation also shows the size on disk. Asks first, with the count; `y` erases, `n`/`esc` keeps. The cost ledger is kept. An agent still using a session brings it back with its next request. Refused — with the proxy's reason — anywhere but a loopback-only laptop install. Not in the footer; the `?` overlay names it | | `s` | events | toggle hiding exchanges no plugin acted on (default: shown; an exchange is hidden only when no plugin acted on either half; the events footer shows the hidden count) | -| `c` | events | open the column picker (`↑↓`/`jk` move, `space`/`x` toggle, `s` sort, `r` reset, `Esc`/`Enter`/`c` close); the selection and sort are saved on close | +| `c` | events | open the column picker (`↑↓`/`jk` move, `space` toggle, `s` sort, `r` reset, `Esc`/`Enter`/`c` close); the selection and sort are saved on close | | `s` | column picker | sort by the column under the cursor: descending → ascending → chronological. Pressing it on a different column starts that column descending. `#` is not sortable — its order already *is* chronological | | `p` | any | pause/resume stream | | `y` | detail | yank the event of the section the cursor is in (request or response) to `~/.cortex/agentop-events` (path stays until the next keypress) | diff --git a/cmd/agentop/tui/events_columns.go b/cmd/agentop/tui/events_columns.go index be9bc0801..bda6f3c26 100644 --- a/cmd/agentop/tui/events_columns.go +++ b/cmd/agentop/tui/events_columns.go @@ -825,7 +825,7 @@ func renderColumnPicker(sel map[eventColumnID]bool, widths map[eventColumnID]int // fitHintLine, so a narrow terminal drops hints from the front and keeps // [q] quit rather than wrapping the line. Same treatment the footer gets. b.WriteString(styleHint.Render(fitHintLine( - "[↑↓] move [space]/[x] toggle [s] sort [r] reset [esc]/[enter] close [q] quit", + "[↑↓] move [space] toggle [s] sort [r] reset [esc]/[enter] close [q] quit", width-borderWidth))) // MaxWidth as a backstop. overlayCenter is explicit that bounding the panel is diff --git a/cmd/agentop/tui/events_columns_test.go b/cmd/agentop/tui/events_columns_test.go index a6ae1bd06..b0c992b81 100644 --- a/cmd/agentop/tui/events_columns_test.go +++ b/cmd/agentop/tui/events_columns_test.go @@ -2,6 +2,7 @@ package tui import ( "context" + "maps" "strings" "testing" "time" @@ -973,3 +974,19 @@ func TestRenderColumnPicker_ShowsSort(t *testing.T) { t.Errorf("picker marks a sort when none is active: %q", none) } } + +// `x` is the erase key, so the picker does not reuse it: only `space` toggles. +func TestColumnPicker_XDoesNotToggle(t *testing.T) { + m := newTestEventsModel(t) + m.handleKey(keyRune('c')) + before := maps.Clone(m.eventColumns) + m.handleKey(keyRune('x')) + if !maps.Equal(before, m.eventColumns) || !m.colPicker { + t.Errorf("`x` changed the columns (%v -> %v) or closed the picker", before, m.eventColumns) + } + id := eventColumns[m.colCursor].id + m.handleKey(keyRune(' ')) + if m.eventColumns[id] == before[id] { + t.Errorf("`space` did not toggle column %q", id) + } +} diff --git a/cmd/agentop/tui/footer_test.go b/cmd/agentop/tui/footer_test.go index 699a6adea..5e3f813a2 100644 --- a/cmd/agentop/tui/footer_test.go +++ b/cmd/agentop/tui/footer_test.go @@ -7,6 +7,8 @@ import ( "github.com/charmbracelet/lipgloss" "github.com/muesli/termenv" + + "github.com/rossoctl/cortex/core/session/timeline" ) // statusRow returns the first line of the footer — the status row, where the @@ -130,3 +132,43 @@ func TestFooterShowsSearchOnEveryPane(t *testing.T) { } } } + +// Each [w] hint names the window it is on now, so the key reads the same on every pane. +func TestFooter_WShowsTheCurrentWindow(t *testing.T) { + u := &model{pane: paneUsage} + if got := u.helpView(); !strings.Contains(got, "[w] 10m") { + t.Errorf("usage footer at the first window: %q, want [w] 10m", got) + } + u.usage.cycleWindow() + if got := u.helpView(); !strings.Contains(got, "[w] 1h") { + t.Errorf("usage footer after w: %q, want [w] 1h", got) + } + + resetSettingsForTest(t) + tl := timelineModel(t, 120, 40) // a 30-minute session + tl.timeline.windowIdx = 1 // 1h: longer than the session, so "all" is drawn + if got := tl.helpView(); !strings.Contains(got, "[w] all") { + t.Errorf("timeline footer: %q, want [w] all", got) + } + // An ended session with a tool that never ended: the pane draws from tl.End, not the clock. + tl.timeline.tl.Tools = append(tl.timeline.tl.Tools, timeline.Tool{Agent: timeline.MainAgent, ID: "open", Name: "Bash", Start: tlAt(1700)}) + _, _, _, win := tl.timelineRange() + if want := "[w] " + timelineWindows[win].label + " "; !strings.Contains(tl.helpView(), want) { + t.Errorf("timeline footer with an open tool: %q, want %q", tl.helpView(), want) + } + + a := &model{pane: paneAgents} + label := a.agentsWindowLabel() + if label == "" { + t.Fatal("agentsWindowLabel is empty before the first rows reply") + } + if got := a.helpView(); !strings.Contains(got, "[w] "+label) { + t.Errorf("agents footer: %q, want [w] %s", got, label) + } + + for _, m := range []*model{u, tl, a} { + if strings.Contains(m.helpView(), "[w] window") { + t.Errorf("pane %v still says [w] window", m.pane) + } + } +} diff --git a/cmd/agentop/tui/help_overlay_test.go b/cmd/agentop/tui/help_overlay_test.go index 6d34878e5..2c6b24063 100644 --- a/cmd/agentop/tui/help_overlay_test.go +++ b/cmd/agentop/tui/help_overlay_test.go @@ -301,7 +301,7 @@ func TestFooterHintsMentionUsageKey(t *testing.T) { // The usage pane's own footer must not fall through to the bare default. m.pane = paneUsage got := m.helpView() - for _, want := range []string{"[m] metric", "[w] window", "[o] breakdown"} { + for _, want := range []string{"[m] metric", "[w] 10m", "[o] breakdown"} { if !strings.Contains(got, want) { t.Errorf("usage footer omits %q:\n %s", want, got) } diff --git a/cmd/agentop/tui/help_pane_map_test.go b/cmd/agentop/tui/help_pane_map_test.go index 2f4fcbef5..ac16ee4ed 100644 --- a/cmd/agentop/tui/help_pane_map_test.go +++ b/cmd/agentop/tui/help_pane_map_test.go @@ -508,3 +508,19 @@ func TestHelpBody_WrapsProseToTheGivenWidth(t *testing.T) { } } } + +// `s` hides the Events table's passthrough rows, so it works only where that table is. +func TestSKey_TogglesOnlyOnEvents(t *testing.T) { + for _, p := range []paneID{paneSessions, paneAgents, panePipeline, paneTimeline, paneDetail, paneUsage} { + m := &model{pane: p} + m.handleKey(keyRune('s')) + if m.hideInactive { + t.Errorf("pane %v: `s` toggled hideInactive off the Events pane", p) + } + } + m := &model{pane: paneEvents} + m.handleKey(keyRune('s')) + if !m.hideInactive { + t.Error("`s` on Events did not toggle hideInactive") + } +} diff --git a/cmd/agentop/tui/key_grammar_test.go b/cmd/agentop/tui/key_grammar_test.go new file mode 100644 index 000000000..719a168c5 --- /dev/null +++ b/cmd/agentop/tui/key_grammar_test.go @@ -0,0 +1,258 @@ +package tui + +import ( + "go/ast" + "go/parser" + "go/token" + "os" + "slices" + "strconv" + "strings" + "testing" +) + +// The key grammar: docs/superpowers/specs/2026-11-19-agentop-key-grammar-design.md. + +// realGlobalKeys may act on every pane without checking it (rule 5). +var realGlobalKeys = []string{ + "q", "ctrl+c", "p", "?", "/", "n", "N", "$", + "u", "T", "P", "A", + "g", "G", "b", "f", "pgup", "pgdown", "pgdn", + "esc", "left", "h", "enter", "right", "l", +} + +// sharedPaneKeys are the letters that more than one pane's `?` table may list, each with +// the one meaning it keeps there. +var sharedPaneKeys = map[string]string{ + "h": "back on a list, the axis on a chart (rule 4)", + "l": "open on a list, the axis on a chart (rule 4)", + "j": "down", "k": "up", + "r": "reload the agent list, on the two pickers", + "x": "erase the row under the cursor", + "S": "choose the inference server for the row", + "w": "cycle the pane's window", +} + +func parseTUI(t *testing.T) (*token.FileSet, map[string]*ast.FuncDecl) { + t.Helper() + fset := token.NewFileSet() + pkgs, err := parser.ParseDir(fset, ".", func(fi os.FileInfo) bool { + return !strings.HasSuffix(fi.Name(), "_test.go") + }, 0) + if err != nil { + t.Fatal(err) + } + funcs := map[string]*ast.FuncDecl{} + for _, pkg := range pkgs { + for _, f := range pkg.Files { + for _, d := range f.Decls { + if fd, ok := d.(*ast.FuncDecl); ok { + funcs[fd.Name.Name] = fd + } + } + } + } + return fset, funcs +} + +// isKeySwitch reports whether s is `switch msg.String()` or `switch key` style: a switch on a +// call to String() or on an identifier named msg or key. +func isKeySwitch(s *ast.SwitchStmt) bool { + switch tag := s.Tag.(type) { + case *ast.CallExpr: + sel, ok := tag.Fun.(*ast.SelectorExpr) + return ok && sel.Sel.Name == "String" + case *ast.Ident: + return tag.Name == "msg" || tag.Name == "key" + } + return false +} + +func caseKeys(cc *ast.CaseClause) []string { + var out []string + for _, e := range cc.List { + if lit, ok := e.(*ast.BasicLit); ok && lit.Kind == token.STRING { + if s, err := strconv.Unquote(lit.Value); err == nil { + out = append(out, s) + } + } + } + return out +} + +// keysHandledIn lists the case keys of every key switch below n. +func keysHandledIn(n ast.Node) []string { + var out []string + ast.Inspect(n, func(n ast.Node) bool { + if s, ok := n.(*ast.SwitchStmt); ok && isKeySwitch(s) { + for _, st := range s.Body.List { + out = append(out, caseKeys(st.(*ast.CaseClause))...) + } + } + return true + }) + return out +} + +func refersToMField(n ast.Node, field string) bool { + found := false + ast.Inspect(n, func(n ast.Node) bool { + if sel, ok := n.(*ast.SelectorExpr); ok && sel.Sel.Name == field { + if id, ok := sel.X.(*ast.Ident); ok && id.Name == "m" { + found = true + } + } + return !found + }) + return found +} + +func stringLits(n ast.Node) string { + var b strings.Builder + ast.Inspect(n, func(n ast.Node) bool { + if lit, ok := n.(*ast.BasicLit); ok && lit.Kind == token.STRING { + b.WriteString(lit.Value) + } + return true + }) + return b.String() +} + +// Rule 1: a letter that two panes' `?` tables list keeps one meaning. A new letter on a +// second pane must join sharedPaneKeys with that meaning. +func TestKeyGrammar_OneMeaningPerKey(t *testing.T) { + panes := map[string][]string{} // letter -> "pane: desc" + for _, g := range paneKeys { + for _, kb := range g.bindings { + // "c then s": the second key belongs to the modal the first one opens. + first, _, _ := strings.Cut(kb.keys, " then ") + for _, tok := range strings.FieldsFunc(first, func(r rune) bool { return r == ' ' || r == '/' }) { + if len(tok) != 1 || !(tok[0] >= 'a' && tok[0] <= 'z' || tok[0] >= 'A' && tok[0] <= 'Z') { + continue + } + if !slices.ContainsFunc(panes[tok], func(u string) bool { return strings.HasPrefix(u, g.title+":") }) { + panes[tok] = append(panes[tok], g.title+": "+kb.desc) + } + } + } + } + for k, uses := range panes { + if len(uses) < 2 { + continue + } + if _, ok := sharedPaneKeys[k]; !ok { + t.Errorf("%q is listed on %d panes and is not in sharedPaneKeys:\n %s", + k, len(uses), strings.Join(uses, "\n ")) + } + } +} + +// Rule 5: a case of handleKey's global switch acts on one pane's state only after it checks +// the pane, unless its key is a real global key. +func TestKeyGrammar_GlobalCasesCheckThePane(t *testing.T) { + fset, funcs := parseTUI(t) + hk := funcs["handleKey"] + if hk == nil { + t.Fatal("handleKey not found") + } + var global *ast.SwitchStmt + for _, st := range hk.Body.List { + if s, ok := st.(*ast.SwitchStmt); ok && isKeySwitch(s) { + global = s + } + } + if global == nil { + t.Fatal("handleKey has no top-level key switch") + } + for _, st := range global.Body.List { + cc := st.(*ast.CaseClause) + keys := caseKeys(cc) + allGlobal := len(keys) > 0 + for _, k := range keys { + if !slices.Contains(realGlobalKeys, k) { + allGlobal = false + } + } + if allGlobal { + continue + } + body := &ast.BlockStmt{List: cc.Body} + if !refersToMField(body, "pane") { + t.Errorf("%s: case %q acts without checking m.pane and is not a real global key", + fset.Position(cc.Pos()), keys) + } + } +} + +// Rule 2: a modal names in its hint line each key it gives a meaning of its own, and it never +// takes `x`, the erase key. +func TestKeyGrammar_ModalHintsNameTheirKeys(t *testing.T) { + _, funcs := parseTUI(t) + + // The column picker's keys are a block of handleKey; find it by its condition. + var picker ast.Node + ast.Inspect(funcs["handleKey"], func(n ast.Node) bool { + if is, ok := n.(*ast.IfStmt); ok && picker == nil { + cond := is.Cond + for { + b, ok := cond.(*ast.BinaryExpr) + if !ok { + break + } + cond = b.X + } + if sel, ok := cond.(*ast.SelectorExpr); ok && sel.Sel.Name == "colPicker" { + picker = is.Body + } + } + return picker == nil + }) + if picker == nil { + t.Fatal("column picker block not found in handleKey") + } + + modals := []struct { + name string + keys ast.Node + hints []string // functions whose string literals hold the hint line + opener string // the key that opened the modal also closes it + }{ + {"column picker", picker, []string{"renderColumnPicker"}, "c"}, + {"erase confirm", funcs["clearConfirmKey"], []string{"confirmText"}, ""}, + {"edit overlay", funcs["handleEditKey"], []string{"renderEditOverlay"}, ""}, + {"server picker", funcs["serverPickerKey"], []string{"renderServerPicker", "renderScopeStep"}, ""}, + } + // Moving and leaving work the same in every modal, so a hint line need not repeat them. + common := []string{"up", "down", "k", "j", "home", "end", "g", "G", "esc", "q", "ctrl+c"} + for _, md := range modals { + if md.keys == nil { + t.Fatalf("%s: key handler not found", md.name) + } + var hint strings.Builder + for _, fn := range md.hints { + if funcs[fn] == nil { + t.Fatalf("%s: hint function %s not found", md.name, fn) + } + hint.WriteString(stringLits(funcs[fn])) + } + h := hint.String() + for _, k := range keysHandledIn(md.keys) { + if k == "x" { + t.Errorf("%s takes `x`, the erase key", md.name) + } + if slices.Contains(common, k) || k == md.opener { + continue + } + want := []string{"[" + strings.ToLower(k) + "]"} + switch k { + case " ": + want = []string{"[space]"} + case "enter": + want = []string{"[enter]", "[↵]"} + } + if !slices.ContainsFunc(want, func(w string) bool { return strings.Contains(h, w) }) { + t.Errorf("%s handles %q but its hint line does not name it (want one of %v)", md.name, k, want) + } + } + } +} diff --git a/cmd/agentop/tui/keys.go b/cmd/agentop/tui/keys.go index 1c3a8183d..87c220308 100644 --- a/cmd/agentop/tui/keys.go +++ b/cmd/agentop/tui/keys.go @@ -169,9 +169,6 @@ func (m *model) handleKey(msg tea.KeyMsg) tea.Cmd { m.usage.cycleGroup() m.persistUsage() return m.beginFetch() - case "s": - // Was the session toggle. Swallowed so it cannot reach the global hideInactive toggle. - return nil } // No scope key: the pane `u` was pressed on sets it — Sessions charts every // session, Events and Detail the one being read. @@ -300,7 +297,7 @@ func (m *model) handleKey(msg tea.KeyMsg) tea.Cmd { m.colCursor++ } return nil - case " ", "x": + case " ": // Toggle. selectedColumns falls back to the defaults when the set is // empty, so turning everything off cannot leave an unrecoverable blank // pane. @@ -490,11 +487,11 @@ func (m *model) handleKey(msg tea.KeyMsg) tea.Cmd { case "s": // Toggle hiding of passthrough / skip-only messages. Default is // off (show everything); turning it on focuses the timeline on - // plugin activity. Only meaningful while the events pane is - // active, but accepting the key on other panes keeps the keybinding - // simple and lets operators set their preference before drilling - // into a session. rebuildEventsTable is a no-op when no session - // is selected. + // plugin activity. Events only: on another pane it would change a + // table the user cannot see. + if m.pane != paneEvents { + return nil + } m.hideInactive = !m.hideInactive m.rebuildEventsTable() return nil @@ -1307,7 +1304,8 @@ func (m *model) helpView() string { if lay, ok := m.timelineLayoutNow(); ok && m.timelineScrollMax(lay) > 0 { scroll = "[↑↓] rows " } - return "[w] window [←→] moment " + scroll + "[enter] events " + m.searchHints(m.pane) + " [esc] back [?] keys [q] quit" + _, _, _, win := m.timelineRange() + return "[w] " + timelineWindows[win].label + " [←→] moment " + scroll + "[enter] events " + m.searchHints(m.pane) + " [esc] back [?] keys [q] quit" case paneUsage: // [o] is omitted under latency rather than shown as a no-op: a footer that // advertises an inert key is worse than a shorter footer. @@ -1323,7 +1321,8 @@ func (m *model) helpView() string { } // No [r]: the pane polls every 20s on its own, so a manual refresh key // bought nothing but a line of footer. - return "[m] metric [w] window" + breakdownHint + + usageWindow, _ := m.usage.window() + return "[m] metric [w] " + formatWindowLabel(usageWindow) + breakdownHint + " " + m.searchHints(m.pane) + " [esc] back [?] keys [q] quit" case paneAgents: // [↵] LABELLED BY WHAT IT WILL SHOW: the highlighted agent, or every agent on the All @@ -1369,7 +1368,7 @@ func (m *model) helpView() string { // key gets discovered. The drawer here breaks down the row under the cursor. spendHint := " [$] spend" // [w] the pane's window, which the title names; see cycleAgentsWindow. - return navHint + enterHint + escHint + serverHint + " [w] window" + spendHint + " " + m.searchHints(m.pane) + " [?] keys [q] quit" + return navHint + enterHint + escHint + serverHint + " [w] " + m.agentsWindowLabel() + spendHint + " " + m.searchHints(m.pane) + " [?] keys [q] quit" } return "[?] keys [q] quit" } diff --git a/docs/assets/cortex-demo.svg b/docs/assets/cortex-demo.svg index 791cfd19c..94d7654d7 100644 --- a/docs/assets/cortex-demo.svg +++ b/docs/assets/cortex-demo.svg @@ -389,7 +389,7 @@ clipPath rect{width:100000px} ● connected12.4 events/sec feedback: https://github.com/rossoctl/cortex/issues/new/choose -[w] window [←→] moment [enter] events [/] search [esc] back [?] keys [q] quit +[w] all [←→] moment [enter] events [/] search [esc] back [?] keys [q] quit @@ -583,7 +583,7 @@ clipPath rect{width:100000px} ● connected12.4 events/sec feedback: https://github.com/rossoctl/cortex/issues/new/choose -[w] window [←→] moment [enter] events [/] search [esc] back [?] keys [q] quit +[w] all [←→] moment [enter] events [/] search [esc] back [?] keys [q] quit diff --git a/docs/superpowers/plans/2026-11-19-agentop-key-grammar.md b/docs/superpowers/plans/2026-11-19-agentop-key-grammar.md new file mode 100644 index 000000000..108d87cd3 --- /dev/null +++ b/docs/superpowers/plans/2026-11-19-agentop-key-grammar.md @@ -0,0 +1,95 @@ +# agentop key grammar Implementation Plan + +> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. + +**Goal:** Make each agentop key keep one meaning on every pane, and add tests that keep it so. + +**Architecture:** Three small changes in `cmd/agentop/tui` (`s` scoped to Events, column picker +toggles with `space` only, `[w]` hints show the current window), then guard tests that read the +`?` overlay tables and walk `keys.go` with `go/ast`. + +**Tech Stack:** Go 1.26.10, Bubble Tea, `go/parser` + `go/ast` (already used by `removed_keys_test.go`). + +**Spec:** `docs/superpowers/specs/2026-11-19-agentop-key-grammar-design.md` + +## Global Constraints + +- Work in `cmd/agentop`. Run tests with `GOWORK=off`. +- While you change code: `GOWORK=off go test ./tui/...`. Before the PR: `scripts/dev/go-test-shards.sh -race cmd/agentop` from the repo root, and `go vet ./...` and `gofmt -l .` in `cmd/agentop`. +- Commits: `git commit -s`, trailer `Assisted-By: Claude (Anthropic AI) `. +- Real global keys (rule 5): `q`, `ctrl+c`, `p`, `?`, `/`, `n`, `N`, `$`, the jump keys (`u`, `T`, `P`, `A`), and navigation (`g`, `G`, `b`, `f`, `pgup`, `pgdown`, `pgdn`, `esc`, `left`, `h`, `enter`, `right`, `l`). +- The `w` value sets do not change. + +## Review Focus + +1. `s` typed into the search prompt on Events stays a search character (the search block runs first). Task 1 test. +2. `s` inside the column picker still sorts after the global `s` is scoped. Task 1 test. +3. `[w]` on Agents before the first rows reply: the label is the requested window, not empty. Task 3 test. +4. `[w]` on Timeline for a session shorter than the chosen window shows `all`, the window drawn. Task 3 test. +5. Footer width: a longer `[w] ` must still fit; `fitHintLine` drops from the front. Task 3 runs `footer_fit_test.go`. + +--- + +### Task 1: `s` works on Events only + +**Files:** +- Modify: `cmd/agentop/tui/keys.go` (global `case "s"` near line 490; the Usage block's `case "s"` near line 172) +- Test: `cmd/agentop/tui/help_pane_map_test.go` +- Docs: `cmd/agentop/README.md`, `docs/using-agentop.md` (each sentence about `s`) + +- [ ] **Step 1: Failing test** `TestSKey_TogglesOnlyOnEvents`: for each pane in `paneSessions, paneAgents, panePipeline, paneTimeline, paneDetail, paneUsage`, `handleKey(keyRune('s'))` leaves `hideInactive == false`. On `paneEvents` it sets `hideInactive == true`. Keep `TestUsagePane_RemovedSKeyDoesNothing`. +- [ ] **Step 2:** Run `GOWORK=off go test ./tui/ -run TestSKey_TogglesOnlyOnEvents`. Expect FAIL on `paneSessions`. +- [ ] **Step 3:** In the global `case "s"`, return nil unless `m.pane == paneEvents`. Delete the Usage block's `case "s"`, because the global case now covers it. Delete the false part of the comment ("accepting the key on other panes … before drilling into a session"). +- [ ] **Step 4:** Run `GOWORK=off go test ./tui/...`. Expect PASS. Fix every existing test that pressed `s` off Events and expected the toggle. +- [ ] **Step 5:** Docs: where they say `s` works anywhere or sets the filter before you open a session, say it works on Events. +- [ ] **Step 6:** Commit `fix: Make s toggle the passthrough rows on the Events pane only`. + +### Task 2: The column picker toggles with `space` only + +**Files:** +- Modify: `cmd/agentop/tui/keys.go` (`case " ", "x":` in the column picker block, near line 300) +- Modify: `cmd/agentop/tui/events_columns.go:828` (hint line) +- Test: `cmd/agentop/tui/settings_persist_test.go:199` and any other test that presses `x` in the picker +- Docs: README and `docs/using-agentop.md` lines that name `x` in the picker + +- [ ] **Step 1: Failing test** `TestColumnPicker_XDoesNotToggle`: open the picker (`m.colPicker = true`), copy `m.eventColumns`, press `x`, assert the map is unchanged and `m.colPicker` stays true. Press `space`, assert the column under the cursor flipped. +- [ ] **Step 2:** Run it. Expect FAIL. +- [ ] **Step 3:** Change the case to `case " ":`. The hint line becomes `[↑↓] move [space] toggle [s] sort [r] reset [esc]/[enter] close [q] quit`. `x` then goes to the picker's `default:` arm, which swallows it. +- [ ] **Step 4:** Change the tests that pressed `x` to press `space`. Run `GOWORK=off go test ./tui/...`. Expect PASS. +- [ ] **Step 5:** Docs. Commit `fix: Toggle a column with space only in the column picker`. + +### Task 3: `[w]` hints show the current window + +**Files:** +- Modify: `cmd/agentop/tui/keys.go` `helpView` (Timeline near 1310, Usage near 1326, Agents near 1372) +- Test: `cmd/agentop/tui/footer_test.go` + +**Interfaces:** +- Consumes: `formatWindowLabel(time.Duration) string` (`spend.go`), `(*usageState).window() (window, resolution time.Duration)`, `(*timelineState).window(now time.Time) int` with `timelineWindows[i].label`, `(*model).agentsWindowLabel() string`. + +- [ ] **Step 1: Failing test** `TestFooter_WShowsTheCurrentWindow`: + - Usage at the default window: footer contains `[w] 10m` (the first `usageWindows` entry; use the actual default if it differs). After `cycleWindow()`: `[w] 1h`. + - Timeline with a 10-minute session and `windowIdx` = the `1h` entry: footer contains `[w] all`. + - Agents with `agentsRowsWindow == ""`: footer contains `"[w] " + m.agentsWindowLabel()`, and that label is not empty. + - No footer of the three contains `[w] window`. +- [ ] **Step 2:** Run it. Expect FAIL. +- [ ] **Step 3:** Replace each `[w] window` with `"[w] " +