Skip to content

feature: agentop: Expand an Agents row into its projects #1817

Closed

Description

@huang195

Parent: #1739. Third of four issues. Depends on: #1815 (SessionSummary.Projects) and #1816 (group=project). Next: #1818.

Problem

The AGENTS pane (A) shows one row per coding agent with SESSIONS, LAST SEEN and COST <window>. It cannot show where an agent's spend went. This issue lets a reader expand an agent row into its projects. The pane is the same as it is today until the reader opens a row.

Target

AGENTS · MONTH                    SESSIONS  LAST SEEN   COST MONTH
▸ All agents                           212  12s ago       $184.20
▾ claude-code
    All projects                       160  12s ago       $151.03
    cortex                              98  12s ago        $97.40
    moca                                41  2h ago         $38.11
    Other                               21  3d ago         $15.52
▸ codex                                 44  1d ago         $30.90
  Other                                  8  5d ago          $2.27

Decisions (fixed, do not reopen)

  1. space opens and closes the row under the cursor. It is the only new key.
    • space reaches this pane today only as the table's page-down (table.DefaultKeyMap, table/table.go:119,133-135). On this pane, page-down stays on d, pgdn and f.
    • Handle space in keys.go before the fall-through to m.agentsTbl.Update (~line 1085). Skip it while a search is active.
    • On a sub-row, space closes the parent and moves the cursor to the parent row.
  2. Rows start closed. The open state is a map[string]bool keyed by the agent label, with "" for All agents. It is not persisted (no field in UserSettings, settings.go:27-31). A refetch, the 20s poll (agents_pane.go:149), w and A keep it.
  3. Offer the expansion only when the data exists. A row shows ▸ only when some listed session has a non-empty Projects (a sessionsNameProjects() beside sessionsNameAgents(), agents_pane.go:591-598). The agent Other row never shows ▸: a client-narrowed snapshot has no series (agent_scope.go:12-18). Against an older server, the pane is exactly as it is today.
  4. An open agent row is a heading. It is the label with ▾ and blank figure cells. The All agents row already uses blank cells (agents_pane.go:356-364). Its figures move to its first sub-row, All projects, so no number shows twice. A closed row shows ▸ and its figures as today. Rows that cannot expand get two spaces in that place, so the labels stay aligned.
  5. Sub-rows, in this order: All projects, then one row per project ordered by usage.SortSeriesLabels, then Other. Other folds the unknown series (no PID, or the cwd / of an IDE agent that macOS started as an app, see feature: Record a project label on each request and session #1815) and the (other) overflow band (16 series, MaxSeriesInResponse). Other is left out when its cost is 0 and no session counts in it. The ▸/▾ and the 4-space indent are literal text in the AGENT cell, as the events pane does for subagent blocks (events_blocks.go:49-60).
  6. Project display name: the last path segment of the label. The label ~ displays as ~, and it is a normal project row, never part of Other. When two sub-rows of one parent have the same last segment, show for each of them the shortest tail of segments that is unique among those rows. Two segments are not always enough: ~/works/go/src/github.com/kagenti/kagenti-extensions and ~/git/kagenti/kagenti-extensions both end in kagenti/kagenti-extensions, so they show github.com/kagenti/kagenti-extensions and git/kagenti/kagenti-extensions. The full label is in the footer when the cursor is on the row.
  7. Spend from before the upgrade is in Other. Ledger rows written before feature: Cost by project in usage, ledger and agentop cost #1816 have no project and read as unknown. For a MONTH window, Other can hold most of the spend for up to a month after the upgrade. Say this in the ? overlay note and in the README.
  8. COST partitions, SESSIONS does not. The projects plus Other add up to All projects. A session that used two projects counts under both. Say this in the ? overlay note for this pane.
  9. In this issue, Enter, → and l on any sub-row act on the parent agent, as Enter on that agent row does today. feature: agentop: Scope views to a project from the Agents pane #1818 changes project sub-rows. x (erase) and S (server) act on the parent agent on the heading and on All projects. On project and project-Other sub-rows they do nothing, and the footer does not offer them.
  10. The $ band and drawer follow the cursor's PARENT agent on a sub-row (spendScopeAgent, spend.go:1030-1037). feature: agentop: Scope views to a project from the Agents pane #1818 narrows them to the project.

Design

  • Data:
    • When a row is open, fetch with the pane's window and resolution:
      • a known agent X: fetchUsageScoped(ctx, client, window, res, X, usage.GroupProject) (agent_scope.go:20)
      • All agents: GetUsageWindow(..., usage.GroupProject)
    • Fold each series across the window with usage.FoldSeriesAcrossWindow, as agentRowsFromBuckets does.
    • Cost units come from SeriesCurrencies, as agentRowsFromSnapshot does.
    • Store the result per agent label. Refetch it on the same events that refetch m.agents: the poll, w and A.
    • A failed fetch keeps the old sub-rows and shows the error the way the pane shows a failed row fetch.
  • SESSIONS and LAST SEEN for a project sub-row come from m.sessions, like agentSessionsCell and agentLastSeen (agents_pane.go:543-575):
    • a project sub-row: sessions where agentRowLists(s, parent) is true and s.Projects contains the label
    • the project Other sub-row: those sessions where s.Projects is empty
    • under All agents: drop the agent test
  • Rows and cursor:
    • rebuildAgentsTable (agents_pane.go:318-391) builds the sub-rows.
    • m.agentRowLabels (app.go:854-855) and selectedAgentScope (agents_pane.go:489-499) must stay in step. Replace the index arithmetic with one slice of row descriptors, {agent, kind, project}, that both of them read. kind is agent, heading, all-projects, project or project-other.
    • Cursor restore matches on the descriptor.
    • Every caller of selectedAgentScope must get the parent agent for a sub-row: Enter (keys.go:642), the footer (keys.go:1432), openAgentErase (clear.go:81), server_picker.go:130,137 and spendScopeAgent (spend.go:1032).
  • Footer and help:
    • The footer (keys.go:1424-1452) adds [space] projects when the row under the cursor can expand, and [space] close on an open row or sub-row.
    • help_overlay.go:400-434: add the binding and the notes from decisions 7 and 8. Stay inside the line budget (TestHelpOverlayScrollHint_AbsentWhenEverythingFits).
  • README (cmd/agentop/README.md): add the space row to the keybindings table (~1526-1530) and a paragraph in the Agents prose (~1596-1607). Change the line "space and d are the table's page-down" (~1522) to say that space opens projects on the Agents pane.

Acceptance (tests in cmd/agentop/tui/)

Use the existing helpers: scopedModel in agents_scope_test.go and cursorScopeModel in agents_cursor_scope_test.go. The cursorScopeModel server records each query. Tests:

  • No session has Projects: no ▸, and space pages down as before.
  • space on claude-code fetches agent=claude-code&group=project, and the rows match the Target.
  • space on All agents fetches group=project with no agent=.
  • Two labels that share a last segment show their shortest unique tails, including the kagenti-extensions pair from decision 6.
  • unknown and (other) fold into one Other. Other is absent when it is 0 and empty.
  • The open state and the cursor survive a refetch and w.
  • space on a sub-row closes the parent and puts the cursor on it.
  • Enter on a project sub-row scopes to the parent agent. x and S do nothing there.
  • The band follows the parent agent on a sub-row.
  • The agent Other row never expands.
  • The help overlay fits its budget.

Run scripts/dev/go-test-shards.sh -short cmd/agentop while you work. Before you push, run scripts/dev/go-test-shards.sh -race cmd/agentop.

Out of scope

Scoping views to a project (#1818). A PROJECT column in the Sessions pane. Persisting the open state.

Assisted-By: Claude (Anthropic AI) [email protected]

Metadata

Metadata

Assignees

Labels

enhancementgoux

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions