Skip to content

feat: Show a project's spend by model in agentop - #2040

Merged
huang195 merged 6 commits into
rossoctl:mainfrom
huang195:feat/project-drawer-2034-pP1
Nov 20, 2026
Merged

huang195 merged 6 commits into
rossoctl:mainfrom
huang195:feat/project-drawer-2034-pP1

Conversation

@huang195

Copy link
Copy Markdown
Member

What changed

Part 2 of 3 of #2032. Part 1 (#2033, PR #2038) is on main, so this PR has no parent PR.

  • agentop asks the proxy for one project's usage. fetchUsageScopedProject sends project=<label> on /v1/usage, with agent= when an agent is scoped. The label is the group=project series label. agentop uses the reply only when the reply echoes project (and the scoped agent). Otherwise it uses the old read: group=project, narrowed by agentop. An older proxy ignores project= and gets the old read.
  • agentop never sends project=Other or project=(other). It also does not send project= for the agent Other. Those scopes use the old read.
  • Drawer under a project scope. The axes are model and endpoint, and a cycles them. The project Other has no axes. The drawer says no breakdown for this scope in <window> only when the reply has no breakdown.
  • Spend band under a project scope. The currency split also sends project=, so the band shows each unit (for example $12.00 + 0.95 Bobcoins).
  • cmd/agentop/README.md tells these facts.
  • Three tests and two fixtures pinned the old rule (no project= key). This PR changes them. The plan (decisions 3 and 4) gives the reason.

How it was tested

The gate passed on this branch's tip:

GOWORK=off go -C cmd/agentop vet ./... && test -z "$(gofmt -l cmd/agentop)" && GOWORK=off go -C cmd/agentop test -race ./tui/ ./apiclient/ -count=1 && scripts/dev/go-test-shards.sh -short cmd/agentop && pre-commit run --from-ref cd2720a5226cfad9ccc9aa403a030c01ccc47a1d --to-ref HEAD

New tests are in tui/agent_scope_project_test.go, tui/spend_drawer_project_test.go and apiclient/client_test.go. TestFetchUsageScopedProject_NoEchoFallsBack covers an older proxy.

Size

  • Counted: 399 lines (335 added, 64 removed).
  • Exempt: 214 lines (the plan document, docs/superpowers/plans/2026-11-20-project-drawer-2034.md).

Review findings that are not fixed

All are minor.

  1. No test for the agent Other with a named project (agent_scope.go, the guard in fetchUsageScopedProject). TestFetchUsageScopedProject_NeverSendsOther tests only the projects Other and (other), with agent "". Add one case with agent=otherAgents and a named project. Assert that no query has project=. (Two reviews reported this.)
  2. No test for a reply that echoes project but not the scoped agent. Examples: a ring window with an agent that is not recognised, or a versioned agent label that the server folds through pipeline.AgentName. The snap.Agent == agent half of the echo check is new logic. One case with the projectServer fixture that echoes project and leaves Agent empty covers it. (Two reviews reported this.)
  3. T5 changed two files that its file list does not name: tui/usage_pane_scope_test.go (projectUsageFetch) and tui/project_scope_spend_test.go. These tests pinned the old rule. T6 changes project_scope_spend_test.go again. Check that T6 does not make a second edit to the same counting filter that conflicts with the first.
  4. No fallback when the project= request fails. fetchUsageScopedProject returns the error. A label longer than maxProjectLabelLen gets a 400 from a new server, but an old server ignores the key. Labels come from group=project replies, so this is unlikely. The plan does not ask for a fallback on error.
  5. No test for decision 5 in spendAxis (agent_scope.go:137): || m.spendScopeProject() != "" with spendScopeAgent() == "" and groupIdx on the agent axis. Each new test also scopes an agent. This branch may be unreachable today, because keys.go:599-604 always sets agentScope with a project sub-row. Add a test that sets projectScope with agentScope "" and checks that spendAxis() is GroupModel. If that state cannot occur, write that in the comment.
  6. TestProjectScope_DrawerAxisKeyCyclesModelAndEndpoint does not check the axis before the first press. Add an assert that m.spendAxis() is GroupModel before the loop.
  7. TestProjectScope_BandMakesNoCurrencyReadForAMixedWindow now expects 2 fallback reads, not 1. Decision 10 makes this necessary. The main check (no whole-agent group=currency read) stays.
  8. The README and decision 7 say "display name". This is not correct (cmd/agentop/README.md:991-992). agentop sends m.projectScope, the group=project series label (for example ~/works/cortex). The title shows projectScopeName, a different name. The server matches only the label (core/sessionapi/usage.go). Change the text to "sends project=<label>, the label that group=project reports". (Two reviews reported this.)
  9. Two requests for each read on a proxy that does not echo project (agent_scope.go:78-87). Each read is the project= read, then the group=project fallback. This occurs on each band poll, currency split, drawer read and usage pane read, for all of the session. It also occurs always for the project Other in the mixed-unit band. Before, it was one request. To make the cost less, record on the client that the proxy did not echo project= after the first miss, and skip the project= read after that. Or accept the cost and say so in the comment or the README.

For a human after review

Nothing. This part has no step outside the repository. Opening the PR is the workflow's own step.

Fixes #2034

Assisted-By: Claude (Anthropic AI) noreply@anthropic.com

Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com>
Signed-off-by: Hai Huang <huang195@gmail.com>
Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com>
Signed-off-by: Hai Huang <huang195@gmail.com>
agentop now sends project= and uses the reply only when the reply
echoes project. An older proxy, and the Other and (other) scopes, use
the old group=project read. The drawer axes under a project scope are
model and endpoint, and the spend band shows each unit.

Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com>
Signed-off-by: Hai Huang <huang195@gmail.com>
fetchUsageScopedProject now sends project= (with agent= when an agent
is scoped) through the new apiclient GetUsageWindowScoped. It uses the
reply only when the reply echoes the project (and the agent). A proxy
older than project= does not echo it, so agentop falls back to the old
group=project read and narrows it. agentop never sends project=Other or
project=(other), and an agent Other scope also uses the old read.

The tests that pinned the old "no project= key" rule now act as an
older proxy: they fail only on project=Other or project=(other), and
count only the fallback reads.

Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com>
Signed-off-by: Hai Huang <huang195@gmail.com>
Under a project scope the drawer now has the axes of an agent scope
(model and endpoint), and `a` cycles them. The project Other has no
axes. The drawer says "no breakdown for this scope" only when the
reply has no breakdown. The band asks for the currency split under a
project scope too, so a mixed window shows each unit.

Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com>
Signed-off-by: Hai Huang <huang195@gmail.com>
@huang195
huang195 requested a review from a team as a code owner November 20, 2026 20:09
@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 3 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: fbf1be98-4665-46bd-ad75-d1ce85857be2
Commits

Reviewing files that changed from the base of the PR and between f409488 and 5a8305f.

Files selected for processing: 14

  • cmd/agentop/README.md
  • cmd/agentop/apiclient/client.go
  • cmd/agentop/apiclient/client_test.go
  • cmd/agentop/tui/agent_scope.go
  • cmd/agentop/tui/agent_scope_project_test.go
  • cmd/agentop/tui/agent_scope_test.go
  • cmd/agentop/tui/agents_cursor_scope_test.go
  • cmd/agentop/tui/agents_projects_test.go
  • cmd/agentop/tui/project_scope_spend_test.go
  • cmd/agentop/tui/spend.go
  • cmd/agentop/tui/spend_drawer.go
  • cmd/agentop/tui/spend_drawer_project_test.go
  • cmd/agentop/tui/usage_pane_scope_test.go
  • docs/superpowers/plans/2026-11-20-project-drawer-2034.md
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@github-actions github-actions Bot added the ready-for-ai-review Request automated AI code review from clawgenti label Nov 20, 2026
The README said that agentop sends the display name in project=.
agentop sends the label that group=project reports. The README now
says that.

TestFetchUsageScopedProject_NeverSendsOther tested only the projects
Other and (other). It now also tests the agent Other with a named
project. Without the guard, a server that echoes agent=Other and
project=X gives a zero, and agentop shows that zero as the project's
spend.

Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com>
Signed-off-by: Hai Huang <huang195@gmail.com>

@clawgenti clawgenti left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

This PR makes agentop send project=<label> (plus agent= when one is scoped) and use the reply only when the proxy echoes it. When there is no echo, it falls back to the old group=project narrowing. That gives the drawer model/endpoint axes under a project scope and lets the band show each unit. I found no must-fix issues.

I checked the client against the server at this head:

  • core/sessionapi/usage.go matches project= on the group=project label.
  • In core/cost/usage/scope.go, ProjectSnapshot echoes project on the complete-ring path and on the narrowed path, and the narrowed path is served as group none. That fits the new drawerScopeNote rule. An unrecognised agent with no complete ring gets AgentSnapshot with no echo, and the agentop fallback handles that case.
  • The ledger (core/cost/ledger/snapshot.go) filters by FilterProject and echoes both keys.
  • agent= is folded by pipeline.AgentName before the echo. agentop's scope labels come from group=agent, which is versionless, so the snap.Agent == agent check holds.
  • Snapshot.Project is the existing LenientString field, so the decoder gets no new typed field.
  • The fold labels (Other, (other), agent Other) never go on the wire, and TestFetchUsageScopedProject_NeverSendsOther now covers the agent Other case too.

On an older proxy the currency split falls back to the narrowed group-none read. unitCosts returns nil for that, so the cell still says mixed rather than showing figures for the whole agent.

I ran the PR's gate locally on 5a8305f: go vet, gofmt -l and go test -race ./tui/ ./apiclient/. All pass.

The open items the PR body lists stay minor and do not block: the extra request per read on a proxy that does not echo, and no test for a reply that echoes project but not the agent.

Author: huang195 (MEMBER — maintainer)
Areas reviewed: Go (agentop apiclient/tui), Docs (README, plan), cross-checked against core/sessionapi, core/cost/usage, core/cost/ledger
Agent/IDE config (.claude/.vscode): none
Commits: 6 commits, all signed-off: yes
CI status: passing (annotations checked: no hidden or non-blocking test failures)

@huang195
huang195 merged commit 08146f1 into rossoctl:main Nov 20, 2026
38 checks passed
@huang195
huang195 deleted the feat/project-drawer-2034-pP1 branch November 20, 2026 20:41
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-ai-review Request automated AI code review from clawgenti

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

feat: Show a project's spend by model in the agentop drawer

2 participants