Repository navigation
feat(plugin): show the band's subscription saving from the tokens fields - #1018
Conversation
On a subscription the band now reads `tokens.saved` and `tokens.caused` from the lean `/api/stats` read (#999), for this session in the 5-hour window. It shows one figure per tier, never a sum: `this session saved 85.0k wr · cost 40.0k rd`. - Every feature counts, not only compaction. - A tier at 0 is left out. `cost` shows only when a tier was paid. - A proxy without `tokens` keeps the old `rd / wr` figure. - The Codex copy of cg.py stays identical. Refs #998 Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]>
amiddavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 1 (glm, user of @amiddavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.322 | offload-review skill, @amiddavid's session | fresh | 1 of 2 | 1 of 2 | e4a663922879 |
approve |
Verdict: approve
Findings
None.
Non-blocking
context-guru-plugin/cg_cachestate_test.go:100— the helper putswindow_askedin the doc, but no test asserts it equalscachestateWindowStart. It only prints inside a failure message. Thesinceandsessionparams are still guarded indirectly: a wrong param changes the stub's answer, sowindow_savedfails. A direct assert would fail faster and name the cause.context-guru-plugin/scripts/cg.py:254— the comment says the tier order is "the order every screen shows them".docs/dashboard.md(Savings in tokens) lists the tiers asinput,cache_read,cache_write_5m,cache_write_1h. The band's order (wr,wr1h,rd,in) differs from that list. Say "the order the band shows them" instead.docs/plugin/statusline.md(new section) —costdoes not include the keep-alive pings' own billed tokens. On a subscription those reads also draw from the 5-hour limit.docs/dashboard.mdsays this one link away ("a ping is not agent traffic"). One sentence here would save the reader the hop.- A proxy at #999 or later, whose rows for this session are all unmeasured (rows from before the accountant, or rows it could not price), now shows no figure where it showed the compaction estimate. The PR and the docs disclose this. Deliberate, not a defect.
What I checked
- The full diff: both
cg.pycopies,cg_cachestate_test.go,register.test.tsx,docs/plugin/statusline.md. Bothcg.pycopies are byte-identical (diff), andTestCGScriptsAreVendoredIntoCodexcoverscg.py. - The read the band makes is real:
/api/stats?lean=1&since=<window>&session=<sid>goes to the lean branch (dash/api.go:1362), andoverviewLeanWindowputs thetokenstotals and the unmeasured count on the answer (dash/overview_lean.go:92,dash/acctokens.go:238). The JSON tier names (input,cache_read,cache_write_5m,cache_write_1hundersaved/caused) matchTOKEN_TIERSexactly. tokens_textlogic: I ran it locally (Python) against all six cases the Go tests assert, with_humancopied fromstatusline.py:337. All six outputs match, including tier order, thev >= 1filter, the bool guard, and theNonereturns.- The fallback: an answer with no
tokens(proxy before #999) keepssl._saved_tokens_text;mineofNone(proxy down, nothing cached) also yields no field. Both paths end inif saved:, so the field is absent, never wrong. - The statusline helpers the code touches exist and keep their names:
_human,_saved_tokens_text,_bg_json,WINDOW_TTL_SECONDS. The Go test is the guard the repo uses for these renames, and it covers the new path. - The UI side:
model.tspasseswindow_savedthrough unchanged;register.tsx:204prefixesthis session;statusRow's width ladder dropslimit.savedwhen the longer string does not fit, so the row degrades to5h 34%, never overflows.register.test.tsxasserts the new row. - The test refactor: each case gets a fresh
XDG_CACHE_HOME(t.TempDir()per call) and a fresh port, so no cache or stub leaks between cases. The stub's three branches guard the query params indirectly. - Docs: the
../dashboard.md#savings-in-tokensanchor exists; the section's rules match the code (tier at 0 left out,costonly when paid, nothing in any tier means5h 34%only, pre-#999 fallback). - Process rules: the PR names the user-visible change at the top, with the old and new behavior and the revert path. Data dependence is metadata only (token counts by tier), stated in the PR; no
docs/data-dependence.mdrow is needed. No Go component, proxy path, or fail-open path changes;statusline.pyis untouched, as the PR says.
amiddavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 2 (glm, user of @amiddavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.322 | offload-review skill, @amiddavid's session | fresh | 2 of 2 | 1 of 2 | e4a663922879 |
approve |
Verdict: approve
Findings
None.
Non-blocking
context-guru-plugin/hooks/register.tsx:6— the file's header comment still shows the old figure. Band row 2 is described as`5h 34% · saved 1.2M rd / 85.0k wr`. After this PR the band drawssaved 85.0k wr · cost 40.0k rd. The PR updateddocs/plugin/statusline.mdbut not this comment. Fix: one line, next touch.- Upgrade edge, documented, so intended: the figure can drop right after a proxy upgrade. A post-#999 proxy always answers
tokens(Go struct, never omitted), sohas_tokensis true even when every row in the 5-hour window predates the measure (acc_priced = 0, token columns 0). The band then shows nothing, or less than the compaction-only figure it showed before the upgrade, until new rows accumulate.docs/plugin/statusline.mdstates this rule ("count as nothing here"). No code change asked; noting it so the merge decision owns it knowingly. context-guru-plugin/cg_cachestate_test.go:100—window_askedis recorded but never asserted. The helper puts thesincethe window read asked for intodoc["window_asked"], and the first test names it only inside its failure message. Thesincevalue is still guarded indirectly (a wrong or missingsinceroutes the stub to another branch and fails the string assertion). A directdoc["window_asked"] != cachestateWindowStartcheck would make the intent explicit.
What I checked
- Read
CLAUDE.md,docs/design.md, and the full diff of the one commit (e4a66392) against base7fd26dcd. - The two
cg.pycopies are byte-identical (git show+diff):context-guru-plugin/scripts/cg.pyandcodex-marketplace/plugins/context-guru/scripts/cg.py.cg_test.go:601keeps them identical. - The wire contract is real. The plugin reads
/api/stats?lean=1&since=<ms>&session=<sid>.dash/overview_lean.goanswers that shape from one indexed scan and appliesleanAgg.read()→Overview.Tokens(json:"tokens",dash/overview.go:440), withsaved/causedtotals by the four tiers andtokens_unmeasured_requests, bounded by both the session andsincefilters. Tier key names (input,cache_read,cache_write_5m,cache_write_1h) matchTierTokensindash/acctokens.go:22. - The formatting matches the tests. Ran
tokens_textstandalone against every case inTestCGCachestateWindowTokensByCaseplus malformed inputs (None, missingtokens,saved: {},caused: null): outputs equal the wanted strings, and malformed input yieldsNone, never a raise.sl._humangives85.0k,2.0k,1.2M,5,600as the tests expect. - The fallback is correct.
sl._saved_tokens_texton{"saved_unique":85000,"replay_tokens":1200000}givessaved 1.2M rd / 85.0k wr, the pre-#999 figure the test wants.has_tokensis false exactly when the proxy served notokensobject; a post-#999 proxy always serves one. - The band renders the string verbatim (
hooks/model.ts:303→hooks/register.tsx:204), no parsing, so the format change cannot break the width logic;windowSavedis in the redrawsignature. With nothing in any tier the row degrades to5h 34%only, as the docs claim. - The test harness is sound.
runCGCodesetsCLAUDE_CODE_SESSION_ID=session-A, so the window read carries the session; the stub's three branches make both the session scoping and thesinceparam fail the test ifcg.pydrops either._bg_jsondoes one inline GET on a cache miss, so the first invocation sees the stub's answer (freshXDG_CACHE_HOMEper case, no cross-case cache carryover). - Docs. The new
docs/plugin/statusline.mdsection matches the code: tier order and labels, zero-tier omission,costonly when paid, pre-#999 fallback, unmeasured rows counting as nothing. The../dashboard.md#savings-in-tokensanchor exists (docs/dashboard.md:411). The status line's own compaction-only figure (statusline.md line 25) is unchanged on purpose and the new section says so. - Repo rules. Display-only change, no request path, no storage: no data-dependence change (the #998 row in
docs/data-dependence.mdalready covers the token figures), no fail-open surface touched,/statsfield names untouched. - Live tests were not run (not approved). Python was parsed and the new function exercised locally with plain
python3; no Go build or test was run.
- The test now checks that the window read asks for the window's start. - The tier-order comment in cg.py says "the band", not "every screen". - The register.tsx header shows the new band figure. - docs/plugin/statusline.md says that `cost` leaves out the keep-alive pings. Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]>
|
Round-1 notes, fixed in this push:
Box: all 8 |
amiddavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 1 (glm, user of @amiddavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.322 | offload-review skill, @amiddavid's session | resumed | 1 of 2 | 2 of 2 | 85ea890810c4 |
approve |
Verdict: approve
Findings
None.
Round-1 notes, re-checked
window_askednever asserted — fixed.cg_cachestate_test.go:35now assertsdoc["window_asked"] == fmt.Sprint(cachestateWindowStart). I traced the values: the helper passes--window-start-ms 1799996000000,cg.pyparses it withtype=int(cg.py:1661) and puts it in the query'ssince, and the stub records that string back. The assert also fails when the window read never happens (windowAskedstays""), so it guards the read itself, not only its value.fmtis already imported.- Tier-order comment — fixed. Both
cg.pycopies now say "the order the band shows them". The two copies are still byte-identical (diff), soTestCGScriptsAreVendoredIntoCodexholds. - Pings missing from the docs — fixed.
docs/plugin/statusline.mdadds one line:costleaves out the keep-alive pings' own billed tokens. The wording matches the code (dash/acctokens.go: a ping is not agent traffic; its tokens live inkeepalive_ping_tokens, nottokens.caused). - Unmeasured rows show no figure — kept as designed. The author kept it and the owner decides at merge. I called it deliberate in round 1 and the PR plus docs disclose it. I accept.
Reviewer 2's round-1 notes (register.tsx header, upgrade edge, window_asked) — I checked each myself in round 1 or in this commit's diff. The header comment now shows the real row (this session saved 85.0k wr · cost 40.0k rd), which matches what register.test.tsx asserts. No disagreement.
Non-blocking
None new.
What I checked
- Last review: round 1,
e4a663922879b6a03deb50c0db00dc1e0a37146b, 2026-11-10T08:42:07Z. - New commits read: 1 —
85ea8908"fix(mod): address the #1018 round-1 notes". - Read in full: 2 reviews, 1 comment, 0 inline comments (from the three
.review-in-*.txtfiles; the inline file is empty). - New items since my last review: my round-1 review and reviewer 2's round-1 review (both at the old sha, both approve, read in full); the author's fix comment at 08:44:12 (lists the fixes, checked each against the diff); the fix commit itself (reviewed below).
- The full diff
e4a6639..85ea8908: 5 files, 7 insertions, 3 deletions. Every hunk read. The changes are the three fixes above plus theregister.tsxheader comment. No logic changes:tokens_text,status_extras, the lean read path, andstatusline.pyare untouched. - The two
cg.pycopies are byte-identical after the change (diff). - The commit carries the DCO sign-off and
Assisted-By:attribution, per the repo rules.
amiddavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 2 (glm, user of @amiddavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.322 | offload-review skill, @amiddavid's session | resumed | 2 of 2 | 2 of 2 | 85ea890810c4 |
approve |
Verdict: approve
Findings
None.
Earlier findings, round 1
Mine (all non-blocking):
register.tsx:6header showed the old figure — fixed. The header now reads`5h 34% · this session saved 85.0k wr · cost 40.0k rd`, which matches whatstatusRowdraws for a subscription (register.tsx:204prefixesthis session).- Upgrade edge: unmeasured rows count as nothing, so the figure can drop right after a proxy upgrade — kept as designed, per the author's comment. The rule stays documented in
docs/plugin/statusline.md("count as nothing here"). I agree: the alternative would mix the accountant's measured tokens with the old compaction estimate in one string. window_askedrecorded but never asserted — fixed.cg_cachestate_test.go:35now assertsdoc["window_asked"] == fmt.Sprint(cachestateWindowStart). Checked the types: the stub recordsq.Get("since")(a string),fmt.Sprintof the constant gives the same decimal string, andfmtis already imported. The assertion fails with a clear message when the window read drops or changessince.
Reviewer 1's notes (I checked each myself, not just the author's reply):
window_askedassertion — same fix as mine, item 3 above. Verified.cg.py:254"every screen" vs "the band" — fixed in both copies;docs/dashboard.mdindeed lists the tiers in a different order (inputfirst), so "the band" is the correct scope. Verified.costleaves out the keep-alive pings — fixed.docs/plugin/statusline.md:213now says so. Checked the claim against the code: the lean read returns no ping tokens at all (leanAgg.read(),dash/acctokens.go:286), and the full read keeps them besidetokens(keepalive_ping_tokens), never insidetokens.caused. The added clause "on a subscription they also count toward the 5-hour limit" is right: a ping is a real provider request under the account.- Unmeasured-rows drop — same as my item 2. Kept as designed.
Non-blocking
None.
What I checked
- Last review: round 1,
e4a663922879b6a03deb50c0db00dc1e0a37146b, 2026-11-10T08:42:36Z. - New commits read: 1 —
85ea890"fix(mod): address the #1018 round-1 notes". - Read in full: 2 reviews, 1 comment, 0 inline comments (from
.review-in-reviews.txt,.review-in-comments.txt,.review-in-inline.txt— the inline file is empty). - New items since my last review:
- Commit
85ea890: read the full diff (git diff e4a66392..HEAD) and the changed files around each hunk. Five files, 7 insertions, 3 deletions. Every hunk is a round-1 fix; no new behavior, no new surface. - Author comment (2026-11-10T08:44:12Z): lists the fixes and the one kept-as-designed item, and reports the Go tests pass with
-race. I verified each code claim myself above. The-raceresult I cannot re-run (live tests not approved); the changed lines are a string comparison and comments, nothing that new concurrency could break.
- Commit
- The two
cg.pycopies are still byte-identical after the fix commit (git show+diff); the comment change landed in both. - The new assertion cannot pass vacuously: if the window branch of the stub is never hit,
windowAskedstays""and the assertion fails; ifsinceis mangled, the string compare fails. - The docs line added to
statusline.mdmatches the served data (checked againstdash/acctokens.goanddocs/dashboard.md"Savings in tokens").
main was red since d058b33 (#1018): TestCGCachestateCarriesTheStatusLinesExtras and TestCGCachestateWindowTokensByCase failed with window_saved empty. Cause: cg.py defined tokens_text twice. #1018 added tokens_text(stats, human) at line 259; #989 (merged just before it) added tokens_text(st) at line 572, which shadowed it. status_extras then called the wrong one with 2 arguments; it swallows the TypeError, so window_saved stayed empty. Each PR was green alone: #1018's branch never had #989, so the collision appeared only after both merged (a semantic merge conflict). Fix: rename #1018's helper to band_tokens_text, with its one call and one doc mention, in both copies of cg.py (the Codex copy too). No test changes. Behavior change: none intended; it restores the band's window saving that #1018 added (owner-approved). Data dependence: none. Reviews: 2 offload reviews (GLM), round 1, both approve at 753bcc4. Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
…0.2.12, Pi 0.1.1) Claude Code plugin 0.6.7 -> 0.7.2: - #981, #989, #1018, #1035: subscription band and savings show saved tokens. - #1038: insights drop the finding that credits a user's own removal. - #1039, #1040: dash and keep-alive fixes that touch the plugin files. Codex plugin 0.2.11 -> 0.2.12: - #1051: read the cache strategies and presets from the proxy. - The vendored cg.py gets the same plugin changes. Pi package 0.1.0 -> 0.1.1: - #1010: chain the proxy in front of an existing base URL. - #1011: check the proxy at session start and restart it once. - #1049, #1058: write the cache strategy by name; review fixes. OpenCode plugin (#483): new in v0.7.2, no version file, not changed. Bob plugin 0.1.0: no change since v0.7.1, not changed. Signed-off-by: DAVID AMID <[email protected]> Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
Bump the plugin versions for v0.7.2. - Claude Code plugin 0.6.7 -> 0.7.2: #981, #989, #1018, #1035 (savings in tokens on a subscription), #1038, #1039, #1040, #1055 (cache strategies read from the proxy). - Codex plugin 0.2.11 -> 0.2.12: #1051 (cache strategies and presets read from the proxy), plus the vendored cg.py changes. - Pi package 0.1.0 -> 0.1.1: #1010, #1011, #1049, #1058, and the #1040 README line. - OpenCode plugin: new in v0.7.2 (#483), no version file. Its first start now downloads proxy v0.7.2 (was v0.7.1). Nothing compares against PINNED_VERSION; the floor stays "v0.7.1 or later". The README lines, the install guide and 3 tests follow. - Bob plugin: 0.1.0, no change since v0.7.1. Behavior change: the OpenCode plugin's first download is proxy v0.7.2, not v0.7.1. Owner's yes, 2026-11-11, in the integrator session: "option1 it is"; the version bumps: "I approve the version bumps for the plugins". Data dependence: none. Reviews: 3 offload review rounds (GLM; round 3 pre-approved by the owner). Both reviewers approve at 3cf6176, which is the PR head. Signed-off-by: DAVID AMID <[email protected]> Assisted-By: Claude Opus 5.5 <[email protected]>
Summary
On a Claude subscription, the band now shows the session's saving from the
tokensfields of/api/stats(#999). It shows one figure per tier and never adds tiers into one number.5h 34% · this session saved 1.2M rd / 85.0k wr(compaction only).5h 34% · this session saved 85.0k wr · cost 40.0k rd(every feature).Part 2 of #998, for the band. Refs #998.
What users see changes. Who: Claude Code users on a subscription, in the band's second row. Old: compaction's
rd / wrestimate. New: the accountant's tokens for every feature, saved and cost, by tier. To go back: revert this PR. A proxy withouttokenskeeps the old figure.What changed
cg.py: newtokens_text.status_extrasuses it forwindow_saved.wr(5-minute write),wr1h(1-hour write),rd(read),in(fresh input).cost …follows only when a tier was paid.5h 34%only.lean=1, this session, since the window's start, the same cache file and TTL.tokens_unmeasured_requests.tokens(a proxy before feat(dash): store the accountant's tier tokens and serve them from /api/stats #999) keeps the oldsaved 1.2M rd / 85.0k wr.cg.pyis identical (TestCGScriptsAreVendoredIntoCodex).statusline.pydoes not change. The status line keeps itsrd / wr.next message 90.0k rd · 90.0k wr if cold) does not change.docs/plugin/statusline.md: the band example, and a new section "The band's tokens on a subscription".Data dependence
Metadata only: token counts by tier. The same at each storage level (off, metadata only, everything). No change to
docs/data-dependence.md.How it was tested
go test -race ./context-guru-plugin/...passes (378 s).go vetis clean.TestCGCachestateCarriesTheStatusLinesExtras: the stub answers both the old fields andtokens. The band showssaved 85.0k wr · 12.0k in · cost 40.0k rd, this session's only.TestCGCachestateWindowTokensByCase: 5 cases. Every tier in order, saved only, cost only, nothing, and a proxy before feat(dash): store the accountant's tier tokens and serve them from /api/stats #999.claude plugin test context-guru-plugin: 98 pass, 1 fail. The failure isno data: the band is left to the engine("no implementation for clock.now"). It fails the same way onorigin/mainwithout this change.Open questions
costhas tiers, the row readsthis session cost 40.0k rd. Is that wording right?🤖 Generated with Claude Code