Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 29 additions & 56 deletions cmd/agentop/README.md

Large diffs are not rendered by default.

13 changes: 4 additions & 9 deletions cmd/agentop/tui/agents_nav_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,19 +172,14 @@ func TestAgentsPane_AOverAListReachedThroughThePickerIsAnOverlay(t *testing.T) {
}
}

// `A` on the picker above Sessions refreshes it without turning it into an overlay, and so does
// the catalog's round trip: esc still backs out of the connection rather than landing on Sessions.
func TestAgentsPane_ThePickerAboveSessionsSurvivesARefreshAndTheCatalog(t *testing.T) {
// `A` on the picker above Sessions refreshes it without turning it into an overlay: esc still
// backs out of the connection rather than landing on Sessions.
func TestAgentsPane_ThePickerAboveSessionsSurvivesARefresh(t *testing.T) {
m := navModel(t, paneSessions, true)
m.enterAgentsAtStartup()
m = pressA(t, m, navRows())
m.handleKey(tea.KeyMsg{Type: tea.KeyRunes, Runes: []rune{'C'}})
if m.pane != paneCatalog {
t.Fatalf("`C` landed on %v", m.pane)
}
pressEsc(m)
if m.pane != paneAgents {
t.Fatalf("esc from the catalog landed on %v, want the picker", m.pane)
t.Fatalf("`A` landed on %v, want the picker", m.pane)
}
pressEsc(m)
if m.pane != panePods {
Expand Down
6 changes: 3 additions & 3 deletions cmd/agentop/tui/agents_pane.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,8 @@ func (m *model) fetchAgentRowsCmd(open agentsOpen, from paneID) tea.Cmd {

// agentsColumns is the table's declared layout, at the width it wants on a wide terminal.
//
// A FUNCTION RATHER THAN A LITERAL INSIDE newAgentsTable, matching pipelineColumns and
// catalogColumns, because layout() has to re-fit these on every resize and must do it from
// A FUNCTION RATHER THAN A LITERAL INSIDE newAgentsTable, matching pipelineColumns,
// because layout() has to re-fit these on every resize and must do it from
// THESE definitions rather than from the live table's columns — refitting the live ones
// compounds each narrowing, so widening the terminal back up never restores what it took away.
//
Expand All @@ -290,7 +290,7 @@ func agentsColumns(window string) []table.Column {
// be worth a picker.
//
// ONE FETCH FROM initSessionView, which is the single place every entry point converges on:
// `--endpoint` mode's Init, the pod picker's portForwardReadyMsg, and `[l]`'s local endpoint all
// `--endpoint` mode's Init, the pod picker's portForwardReadyMsg, and `[L]`'s local endpoint all
// call it, and each replaces m.client first. Hooking it there rather than in Init is what makes
// the gate run again when the operator backs out to the pod picker and enters a DIFFERENT pod —
// a different proxy has different agents on it, and the answer from the previous one is not an
Expand Down
6 changes: 3 additions & 3 deletions cmd/agentop/tui/agents_pane_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,13 @@ func TestAgentRowsFromBuckets_MoneySaturatesRatherThanWrapping(t *testing.T) {

// esc leaves the AGENTS pane and lands where `A` was pressed.
//
// A KEY-OPENED SURFACE MUST RETURN TO ITS CALLER, which is the rule paneCatalog's own esc
// case states and the reason the sessions pane is the only one whose esc costs the
// A KEY-OPENED SURFACE MUST RETURN TO ITS CALLER, which is the rule every key-opened
// pane's esc case states and the reason the sessions pane is the only one whose esc costs the
// connection. Without a case of its own a new pane is a DEAD END: esc falls through, the
// reader is stuck, and the only way out is `q`.
//
// The paneNone fallback is Sessions rather than the pane enum's zero value. It is reachable
// rather than defensive — the same way paneCatalog's is — and Sessions is the one pane that is
// rather than defensive, and Sessions is the one pane that is
// always a defensible place to land; falling back to the zero value would drop the reader on
// the Kubernetes namespace picker, tearing down nothing but looking like the connection went
// away.
Expand Down
32 changes: 22 additions & 10 deletions cmd/agentop/tui/agents_projects_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ func onDesc(t *testing.T, m *model, d agentRowDesc) {
func openClaudeCode(t *testing.T, m *model) {
t.Helper()
onRow(t, m, projAgent)
deliver(m, pressCmd(m, spaceKey))
deliver(m, pressCmd(m, enterKey))
}

var (
Expand Down Expand Up @@ -296,7 +296,7 @@ func TestAgentsProjects_NoProjectsNoMarkerAndSpacePagesDown(t *testing.T) {
}
}

func TestAgentsProjects_SpaceOnAnAgentFetchesItsProjects(t *testing.T) {
func TestAgentsProjects_EnterOnAnAgentFetchesItsProjects(t *testing.T) {
m, asked := projectsModel(t, defaultProjectSeries)
openClaudeCode(t, m)
if q := asked(); !hasQuery(q, "agent=claude-code", "group=project") {
Expand All @@ -316,10 +316,10 @@ func TestAgentsProjects_SpaceOnAnAgentFetchesItsProjects(t *testing.T) {
}
}

func TestAgentsProjects_SpaceOnAllAgentsFetchesWithoutAgent(t *testing.T) {
func TestAgentsProjects_EnterOnAllAgentsFetchesWithoutAgent(t *testing.T) {
m, asked := projectsModel(t, defaultProjectSeries)
onRow(t, m, "")
deliver(m, pressCmd(m, spaceKey))
deliver(m, pressCmd(m, enterKey))
q := asked()
if !hasQuery(q, "group=project") {
t.Fatalf("queries %v; want a group=project one", q)
Expand Down Expand Up @@ -380,11 +380,23 @@ func TestAgentsProjects_OpenStateAndCursorSurviveRefetchAndW(t *testing.T) {
}
}

func TestAgentsProjects_SpaceOnASubRowClosesTheParent(t *testing.T) {
// Space no longer closes a row from a sub-row: it is the table's page-down, as everywhere.
// Enter on the open agent row is how to close it.
func TestAgentsProjects_SpaceOnASubRowDoesNotCloseTheParent(t *testing.T) {
m, _ := projectsModel(t, defaultProjectSeries)
openClaudeCode(t, m)
onDesc(t, m, cortexRow)
runCmds(pressCmd(m, spaceKey))
if !m.agentsExpanded[projAgent] {
t.Error("space closed the row; only Enter on the agent row does")
}
}

func TestAgentsProjects_EnterOnTheOpenAgentClosesIt(t *testing.T) {
m, _ := projectsModel(t, defaultProjectSeries)
openClaudeCode(t, m)
onDesc(t, m, agentRowDesc{agent: projAgent, kind: agentRowHeading})
runCmds(pressCmd(m, enterKey))
if len(m.agentsExpanded) != 0 {
t.Errorf("rows still open: %v", m.agentsExpanded)
}
Expand Down Expand Up @@ -492,11 +504,11 @@ func TestAgentsProjects_FooterNamesTheFullLabel(t *testing.T) {
if got := m.helpView(); !strings.Contains(got, "[↵] projects") {
t.Errorf("closed row footer %q; want [↵] projects", got)
}
deliver(m, pressCmd(m, spaceKey))
deliver(m, pressCmd(m, enterKey))
onDesc(t, m, agentRowDesc{agent: projAgent, kind: agentRowProject, project: label})
got := m.helpView()
if !strings.Contains(got, sanitizeLabel(label)) || !strings.Contains(got, "[space] close") {
t.Errorf("footer %q; want %q and [space] close", got, sanitizeLabel(label))
if !strings.Contains(got, sanitizeLabel(label)) || strings.Contains(got, "[space]") {
t.Errorf("footer %q; want %q and no [space]", got, sanitizeLabel(label))
}
if strings.Contains(got, "\x1b") {
t.Errorf("footer carries a raw escape: %q", got)
Expand All @@ -523,8 +535,8 @@ func TestAgentsProjects_FetchErrorClearsOnCloseAndW(t *testing.T) {
m.Update(agentProjectsLoadedMsg{agent: projAgent, err: errors.New("boom"), window: m.agentsSpanDef().window})
}
fail()
onDesc(t, m, cortexRow)
runCmds(pressCmd(m, spaceKey))
onDesc(t, m, agentRowDesc{agent: projAgent, kind: agentRowHeading})
runCmds(pressCmd(m, enterKey))
if strings.Contains(m.View(), "refresh failed") {
t.Error("error still shows after the last row closed")
}
Expand Down
14 changes: 7 additions & 7 deletions cmd/agentop/tui/agents_scope_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func TestAgentsPane_EnterListsThePickedAgentsSessionsFromAnyCaller(t *testing.T)
{label: "claude-code/2.1.270", Counts: usage.Counts{Requests: 10, PricedRequests: 10}},
{label: "bob-shell/2.0.5", Counts: usage.Counts{Requests: 8}},
}
for _, from := range []paneID{paneSessions, paneEvents, paneDetail, paneUsage, panePipeline, paneCatalog} {
for _, from := range []paneID{paneSessions, paneEvents, paneDetail, paneUsage, panePipeline} {
m := &model{
pane: from,
previousPane: paneNone,
Expand Down Expand Up @@ -272,19 +272,19 @@ func TestUsageTitle_NamesTheAgentScope(t *testing.T) {
}
}

// [b] is omitted from the footer while a scope is active, because it cannot act.
// [o] is omitted from the footer while a scope is active, because it cannot act.
//
// The wire axis is the agent's while scoped, so there is no second axis to break down by. Same
// treatment the footer already gives [b] under latency, and for the same stated reason: a footer
// treatment the footer already gives [o] under latency, and for the same stated reason: a footer
// that advertises an inert key is worse than a shorter footer.
func TestUsageFooter_OmitsTheBreakdownKeyWhileScoped(t *testing.T) {
m := fitModel(t, paneUsage, 120, 40, nil)
if !strings.Contains(m.helpView(), "[b] breakdown") {
t.Fatal("the unscoped footer does not offer [b]; this test is measuring the wrong thing")
if !strings.Contains(m.helpView(), "[o] breakdown") {
t.Fatal("the unscoped footer does not offer [o]; this test is measuring the wrong thing")
}
m.agentScope = "claude-code/2.1.270"
if strings.Contains(m.helpView(), "[b] breakdown") {
t.Error("the footer still advertises [b] under an agent scope, where it cannot act")
if strings.Contains(m.helpView(), "[o] breakdown") {
t.Error("the footer still advertises [o] under an agent scope, where it cannot act")
}
}

Expand Down
46 changes: 16 additions & 30 deletions cmd/agentop/tui/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ const (
paneDetail
panePipeline
panePluginDetail
paneCatalog
paneUsage
// paneAgents shows what each CODING AGENT has spent, and picks which one the views are
// scoped to; see agentScope. Not to be confused with paneNamespaces,
Expand Down Expand Up @@ -83,19 +82,19 @@ type connStateInfo struct {
// confirmation) stays in the footer.
const flashDuration = 3 * time.Second

// defaultLocalEndpoint is where `[l]` connects when nothing better is known:
// defaultLocalEndpoint is where `[L]` connects when nothing better is known:
// the session API's in-cluster default port, reached through an existing
// `kubectl port-forward`. Useful when agentop runs inside the mesh, or when the
// cluster's pod list isn't visible to their kubeconfig but a tunnel is.
//
// A local install listens somewhere else entirely (47601 by default), so
// RunOptions.LocalEndpoint overrides this with the address read from the
// machine's own Cortex config. Hardcoding 9094 sent `[l]` to the wrong port on
// machine's own Cortex config. Hardcoding 9094 sent `[L]` to the wrong port on
// every laptop.
const defaultLocalEndpoint = "http://localhost:9094"

// localEndpointOr returns the resolved local endpoint, falling back to the
// in-cluster default. One accessor so `[l]`, the footer and the help overlay
// in-cluster default. One accessor so `[L]`, the footer and the help overlay
// cannot disagree about where the key goes.
func (m *model) localEndpointOr() string {
if m.localEndpoint != "" {
Expand All @@ -116,7 +115,7 @@ func (m *model) localEndpointOr() string {
// Local wins when the endpoint on screen IS the local Cortex. Deliberately a
// question about the connection rather than about how agentop was started, so
// `--endpoint http://127.0.0.1:47601` aimed at your own proxy edits it just
// like a bare `agentop` does, and `[l]` gains the same ability mid-session.
// like a bare `agentop` does, and `[L]` gains the same ability mid-session.
// Compared against localEndpoint rather than localEndpointOr(): the fallback
// is the in-cluster 9094, and matching that would claim a hand-run
// port-forward to a POD is this machine's config file.
Expand Down Expand Up @@ -176,7 +175,7 @@ func isLoopbackHost(h string) bool {
return ip != nil && ip.IsLoopback()
}

// localProbeTimeout bounds the pre-connect reachability check for `[l]`.
// localProbeTimeout bounds the pre-connect reachability check for `[L]`.
// Without it, a dead localEndpoint would leave the operator in an empty
// session view wondering why nothing streams; with it they get a footer
// error and stay in the picker.
Expand Down Expand Up @@ -386,7 +385,7 @@ type model struct {

endpoint string
client *apiclient.Client
// localEndpoint is what `[l]` connects to and what the footer and help
// localEndpoint is what `[L]` connects to and what the footer and help
// overlay name. Resolved from the local Cortex config when there is one.
localEndpoint string

Expand Down Expand Up @@ -716,7 +715,6 @@ type model struct {
sessionRowIDs []string
eventsTbl table.Model
pipelineTbl table.Model
catalogTbl table.Model
detailVp viewport.Model
// detailDoc is detailVp's text, searched — see searchdoc.go. Shared by message detail
// and plugin detail, as the viewport is.
Expand Down Expand Up @@ -911,7 +909,7 @@ type model struct {
// or quit.
activePF cluster.PortForward

// localDirect is true when the session view was entered via `[l]`
// localDirect is true when the session view was entered via `[L]`
// (direct connection to localEndpoint) rather than by picking a pod.
// There is no pod to go back to, so Esc returns to the Namespaces
// pane instead of Pods.
Expand Down Expand Up @@ -1024,7 +1022,6 @@ func New(ctx context.Context, c *apiclient.Client, opts ...Option) tea.Model {
sessionsTbl: newSessionsTable(),
eventsTbl: newEventsTable(),
pipelineTbl: newPipelineTable(),
catalogTbl: newCatalogTable(),
agentsTbl: newAgentsTable(),
previousPane: paneNone,
// paneNone, not the zero value: paneNamespaces is 0, and a return pane
Expand Down Expand Up @@ -1070,7 +1067,7 @@ func (m *model) initSessionView() tea.Cmd {
// ctx / cancel is derived from m.parentCtx so the next session-view
// entry has a usable context.
//
// When the session was entered via `[l]` there is no pod to return to,
// When the session was entered via `[L]` there is no pod to return to,
// so the destination is the Namespaces pane instead.
func (m *model) backToPodsPane() {
// Cancel current ctx — stops the SSE goroutine and any in-flight
Expand Down Expand Up @@ -1136,7 +1133,6 @@ func (m *model) backToPodsPane() {
// different framework instance with potentially different plugin
// versions registered. The next `P` press refetches.
m.catalog = nil
m.catalogTbl.SetRows(nil)
// pickerHarvested and pickerShowing are deliberately NOT reset here. They are edge-derived: the
// next refresh tick recomputes "is the picker showing", finds it disagrees with the recorded
// pickerShowing, and clears the budget on that inequality. Resetting them here would make this
Expand Down Expand Up @@ -1204,7 +1200,7 @@ func (m *model) backToPodsPane() {
m.ctx, m.cancel = context.WithCancel(m.parentCtx)

if m.localDirect {
// Entered via `[l]`: no pod was ever selected, so the Pods pane
// Entered via `[L]`: no pod was ever selected, so the Pods pane
// would render an empty table for a namespace the user never
// picked. Go back to where they actually were.
m.localDirect = false
Expand Down Expand Up @@ -1307,9 +1303,8 @@ type catalogLoadedMsg struct {
err error
}

// loadCatalogCmd fetches /v1/plugins. Called lazily when the user
// presses `P` to enter the catalog pane; the result is cached on the
// model and refreshed on demand.
// loadCatalogCmd fetches /v1/plugins: on each `P`, for the pipeline pane's
// available rows, and kept on the model for the pipeline editor.
func (m *model) loadCatalogCmd() tea.Cmd {
return func() tea.Msg {
cat, err := m.client.GetPluginCatalog(m.ctx)
Expand Down Expand Up @@ -1843,7 +1838,7 @@ func (m *model) update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, nil
}
m.catalog = msg.catalog
m.rebuildCatalogTable()
m.rebuildPipelineTable()
return m, nil

case snapshotLoadedMsg:
Expand Down Expand Up @@ -2103,12 +2098,12 @@ func (m *model) update(msg tea.Msg) (tea.Model, tea.Cmd) {
//
// The pod fields are CLEARED rather than assumed empty. They are only
// empty when no pod was ever visited: backToPodsPane clears ~20 fields
// but not these, so "pick a pod → esc → [l]" arrives here with
// but not these, so "pick a pod → esc → [L]" arrives here with
// selectedNamespace / selectedPod naming the pod and statusURL naming
// its closed port-forward. Since pipelineStore falls back to the
// ConfigMap branch on exactly those three, leaving them set let `e`
// kubectl-apply against a pod the screen was not showing — and poll a
// forward this path never established. Harmless while `[l]` sessions
// forward this path never established. Harmless while `[L]` sessions
// were assumed storeless; a wrong-target write once they were not.
m.selectedNamespace = ""
m.selectedPod = ""
Expand Down Expand Up @@ -2564,7 +2559,7 @@ func (m *model) paneView() string {
if m.namespaces != nil && len(m.namespaces) == 0 && m.pickerErr == "" {
body = styleHint.Render(
"No Cortex agents found in this cluster.\n" +
"Press [l] to connect to " + m.localEndpointOr() + " (an existing\n" +
"Press [L] to connect to " + m.localEndpointOr() + " (an existing\n" +
"port-forward), or use `agentop --endpoint http://...`.")
} else {
body = m.namespacesTbl.View()
Expand Down Expand Up @@ -2725,15 +2720,6 @@ func (m *model) paneView() string {
case paneTimeline:
title = m.sessionHeader(m.timeline.session, "timeline")
body = m.timelineBody()
case paneCatalog:
title = fmt.Sprintf("%s · %s · catalog", m.appName(), m.endpoint)
if m.catalog == nil {
body = styleHint.Render("(loading catalog…)")
} else if len(m.catalog.Plugins) == 0 {
body = styleHint.Render("(no registered plugins reported by /v1/plugins)")
} else {
body = m.catalogTbl.View()
}
}

// The band above every pane is scoped too, so every pane says so; usage and agents word it
Expand Down Expand Up @@ -2932,7 +2918,7 @@ type RunOptions struct {
Endpoint string
Lister cluster.Lister
PortForwarder cluster.PortForwarder
// LocalEndpoint overrides where `[l]` connects. Empty means
// LocalEndpoint overrides where `[L]` connects. Empty means
// defaultLocalEndpoint.
LocalEndpoint string
// LocalConfigPath and LocalStatsURL describe the Cortex running on this
Expand Down
Loading
Loading