Repository navigation
Show per-model cached tokens alongside cost in desktop and menubar - #1265
ozymandiashh wants to merge 7 commits into
Conversation
Main took render revision 6 for `sessionCountBasis` and changed the provider-slice session fold from a sum to a per-day max. Both had to survive the merge, so the resolutions are unions rather than sides: - `addProviderSlice` keeps main's `Math.max` for `sessions` (per-day ticks are not distinct identities) and adds the cache-read sum beside it, with a comment saying why one is additive and the other is not. - `ProviderSliceTotal`, `ProviderCost`, `providerDetails` and the Swift `ProviderDetail` carry both `sessionCountBasis` and `cacheReadTokens`. - The snapshot revision stays 7, which is still the next free number above main's 6. Its doc comment said v6 was PR1265's per-model counts; it is main's `sessionCountBasis`, so the comment now says that. The status-menubar suite hard-codes render revisions. Main's assertion that a rejected v5 snapshot is rewritten as `:render-6:` auto-merged cleanly while this branch moved the current revision to 7, which would have failed silently on the next bump too. Those assertions now derive the tag from `STATUS_SNAPSHOT_RENDER_VERSION`, so the current and previous revisions follow the constant; the deliberately historical `:render-5:` and `:render-2:` plants stay literal.
Ports the two parts of getagentseal#1287 the maintainer asked to keep, expressed through this branch's `QuotaPacePresentation` rather than through `QuotaPace.Verdict`: - Placement: `QuotaDetailRow` in the agent-tab quota hover card becomes a VStack and draws the pace line under the bar, indented past the label column, with the three tones the dock already uses. The card is fitted, so a silent caption collapses there instead of reserving a slot the way the dock's computed frame must. - Wording: the long-window caption drops "est. N% at reset" / "est. out in X" for the plain "Lasts until reset" / "Runs out in X", and the exhausted state becomes "Limit reached". The projected percentage it came from stays in the hover text, which has room for the reasoning. Short windows keep the on-pace / deficit / reserve stage (getagentseal#726), and the freshness, connection and duration gates are untouched. `QuotaPace.inferredWindowSeconds(label:)` is deliberately NOT ported. Grok Build chooses its window label from the distance to the reset, so a monthly cycle passing through the 4-12 day band is labeled "Weekly" and a label round trip paces a month's budget against seven days. The adapter's real `windowSeconds` is the only source here, and a new test pins that shape: 72% used with six days to a monthly reset reads "Lasts until reset", while the same sample against an inferred 7-day window overflows and would have printed "Runs out in 9h 20m". The same test asserts a window with no duration metadata stays silent rather than falling back to its label. Verified with a standalone swiftc harness over QuotaPace, QuotaPacePresentation and QuotaSummary: this host has Command Line Tools only, so `swift test` cannot load the Testing module. Closes getagentseal#1267
getagentseal#1267 lands first, so rebuild this branch on top of it rather than on origin/main. The remaining diff is then only this branch's own contribution: per-model input/output/cache-read counts in the desktop Overview and the macOS menubar Models rows. Conflict resolutions: * src/status-snapshot-semantic.ts — this branch bumped the snapshot render revision from 5 to 6, but main had already taken 6 for sessionCountBasis and getagentseal#1267 has taken 7 for per-provider cacheReadTokens. Move to 8, and bump the single shared constant getagentseal#1267 extracted instead of making a third inline edit in src/main.ts. A revision must be distinct from every other branch's or a snapshot written elsewhere would be accepted here while lacking this change's fields. * src/main.ts — take getagentseal#1267's side: the revision and semantic key now come from statusSnapshotSemanticKey() rather than local constants. * src/usage-aggregator.ts — import-only conflicts, superset of both sides. addProviderSlice keeps main's Math.max session folding and getagentseal#1267's summed cacheReadTokens; neither is reverted. * tests/cli-status-menubar.test.ts — both branches appended a test at the same insertion point and git interleaved them. Reassembled so both blocks survive intact. This branch's own snapshot-invalidation test planted a literal :render-5:. Against a tree that already ships 7, that plant proves nothing — main alone rejects it, so the case passed without this change. Plant the immediately previous revision via getagentseal#1267's derived PREVIOUS_RENDER_TAG instead, and assert the rewritten record carries CURRENT_RENDER_TAG. The deliberately historical :render-5: / :render-2: plants elsewhere stay literal: those name specific pre-field contracts rather than "one revision back".
Review follow-ups on the per-model token counts, addressed on the merged
head.
buildPeriodData walked every assistant call in every session twice: once
through sessionBillableOutputTokens for the headline and again through
sessionModelBillableOutputTokens for the per-model split. Both derive from
the same traversal and the same sawUsage fallback decision, so fold them
into one sessionBillableOutput(session) returning { total, byModel }; the
two existing exports become thin wrappers, keeping their semantics for
other callers. A call whose model resolves to no breakdown bucket still
counts toward the session total and still lands in no row, exactly as
before, so no total moves.
The macOS accessibility text grouped a signed string, counting the minus
as a leading digit and emitting it twice: a -1,234,567 count read as
"--1,234,567", a different number to a screen reader. Group the magnitude
and re-apply the sign; magnitude is unsigned, so Int.min no longer traps
on negation either. Negative counts are not expected from the CLI, but the
payload field is a plain Int and a corrupt or hand-edited snapshot carries
whatever it carries.
Two findings are disclosed rather than changed:
* buildTopModels' unknown-vs-zero guard cannot fire on the durable path.
ModelDayStats types the four counts as required numbers and daily-cache
sanitizeModels runs each through num(), so a missing value becomes a
known 0 and a carried day under-reports as exact instead of unknown.
Making it reachable means widening ModelDayStats to optional counts and
teaching every daily-cache arithmetic site (fold, subtract, reduce) plus
buildPeriodDataFromDays to propagate absence — a durable-cache contract
change, too broad to ride along here. The guard stays: PeriodData
already types these counts optional, so fresh-session and plugin-sourced
rows may legitimately omit them.
* The all-provider Overview models table now reads current.topModels and
so inherits the payload's 20-row TOP_MODELS_LIMIT, which its previous
uncapped daily-history union did not have. Kept, because that union was
itself a per-day top-five truncation whose tail rows were already
partial sums, but the PR body's "the cap is unchanged" claim was wrong
for this view and the trade-off is now recorded at the call site.
|
Rebased on top of #1267, which should land first; against that branch this PR's own contribution is 18 files. Render revision is now 8, taken by bumping the shared Also fixed from the earlier review: the double per-session call walk is folded into one Two findings disclosed rather than changed, both documented at the call sites: the tsc clean, swift build complete, full suite 3996 passed / 0 failed. |
|
Landed as #1315 (ef97600) with your two commits and authorship intact, rebased onto #1314 (the snapshot bump that lived in your merge resolution was restored into the first commit), plus two assertions pinning the per-model reasoning normalization. Verified on frozen dates: 16 added token fields, zero changed values, every cost, call and session identical to the digit; rows sum exactly to period totals and match models --format json. The Overview all-provider table now capping at 20 rows is tracked separately. Thank you. |
Summary
Previously, the menubar payload discarded per-model token counts, Overview had no cache-read column, and the desktop Models table hid usage when a model had no attributed cost. A menubar row now includes a secondary line such as
12.3K in · 4.5K out · 67.8K cache read, with its cost on the primary line.Cache-read means reused input. Cache pricing was already included in attributed cost; this change exposes usage without changing pricing. Cache-write remains a separate payload field and is included in the macOS accessibility description. Reasoning is added to output only where the provider reports it separately.
The new fields are optional. Older payloads still decode, missing counts remain unknown, and known zero stays zero. Alias merges do not present partial counts when a contributor lacks data. Overview uses the period/provider-scoped model rows when available, with its previous daily-history source retained for older payloads. The existing 20-model cap remains. Daily/session cache formats and stored history are unchanged.
Testing
npm testpasses in the completed branch validation runnpm run buildsucceedsValidation against the unchanged
mainbase (4a9d8852):cli-status-menubar.test.ts: their fixture offsets placed calls in the future. The entire file passed 23/23 on rerun after that window; the other 3,725 tests passed in the full run.usePolledand sixoverviewSnapshotfailures occur under local Node 26 with unavailable jsdom localStorage; no new failures.git diff --checkis clean.The new CLI regression plants a render-v5 snapshot without token fields, verifies that the new binary recomputes the counts, then requires the next identical call to leave the snapshot byte-identical. Pipeline fixtures also cover fresh versus durable history, provider/range selection, alias merging, cache-only usage and unpriced models.
Real Hermes data returns
input=139, output=393, cacheRead=30,592, cacheWrite=0with the existing attributed cost unchanged. A 15-model real corpus also reconciled model counts with the period totals.Layout was checked using the actual branch components with fixture data: native SwiftUI views at the 360pt popover width, and desktop Overview/Models at 1200px and 900px. An additional 900px check reserved the 186px sidebar and applied the real content padding. Cache values, costs and zero-cost usage remain visible. These are isolated component/native-view renders, not validation of an installed release; no installed applications were replaced.