Repository navigation
[Lens viz] Cost-by-component + recoverable-waste overlay (#211) - #224
Merged
Merged
Conversation
The differentiated Lens viz (#211, milestone #3): split the window's spend into the four token components and overlay each optimize analyzer's attributed recoverable waste — the cost-WASTE view a generic activity dashboard can't show because it depends on our analyzers' attributed estimates. New GET /api/v1/cost/components computes, server-side: - the component cost split (input / output / cache-read / cache-write), priced per (provider, model) via the pricing table so it's exact, not apportioned from the aggregate cost_usd; and - a registry-driven per-analyzer recoverable list — it iterates the typed downgrade slot plus every wave-2 finding carrying the #111 recoverable contract field, so a new analyzer appears automatically with no code change. Each entry keeps the analyzer's own caveat + estimate_basis verbatim and the component its savings act on ("call" = whole-call model swap / call elimination, for analyzers that can't be honestly pinned to one component). The UI adds a ComponentWasteChart (vendored uPlot stacked bars, offline intact): two columns — measured "Cost" stacked by component and "Recoverable (est.)" stacked by analyzer. They are SEPARATE bars; recoverable is never subtracted from cost and never called "saved" (Critical Rule 14) — the caption reads "a heuristic estimate to review before acting, not a realized cost reduction". A per-analyzer list under the chart surfaces each estimate behind the "estimated recoverable" tag with its caveat. Every figure routes through the framing block (fmtFramedSavings / fmtFramedDollar) so subscription/local users see token-share, not raw dollars, and the bars themselves switch to token volume. The endpoint fetch is best-effort — a failure never blanks Optimize. Tests: endpoint tests (httpx + InMemoryBackend) pin the per-component pricing, the registry-driven recoverable (reuse appears from the findings dict), the downsize caveat verbatim, "saved" absent from the payload, and subscription framing; static-grep UI regressions assert the chart/helpers, the registry- driven build (no hard-coded analyzer list), the honesty caption + "saved" absent from the surface, and the framing routing; test_ui_offline stays green and the app module passes node --check. Closes #211 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
anilmurty
commented
Jun 23, 2026
anilmurty
left a comment
Contributor
Author
There was a problem hiding this comment.
Verdict: ✅ APPROVE — ready to merge
The differentiator, and the honesty discipline that got it carved out of Wave 1 is handled exactly right and pinned by tests. CI all 4 green (823), MERGEABLE, scope clean (cost.py + index.html + 2 test files), no committed binaries (screenshot delivered out-of-band — good).
Honesty discipline (Rule 14) — exemplary
- "saved" never appears — asserted absent in BOTH the payload (
"saved" not in json.dumps(d)) and the UI card. - Recoverable is never subtracted from cost — rendered as a separate column ("Cost by component" vs "Estimated recoverable"), so it can't read as a realized reduction.
- Caption is exactly the right frame: "estimated recoverable waste … a heuristic estimate to review before acting, not a realized cost reduction" (test-pinned).
- Routes through framing —
fmtFramedSavings/fmtFramedDollar, subscription/local → token-share, bars switch to tokens. - Each analyzer's caveat/estimate_basis preserved verbatim (on the per-analyzer detail).
Design
- Registry-driven via the #111 contract — iterates
estimated_recoverable_usd/tokenson every finding, so a new analyzer appears automatically (matches the recoverable-savings contract). - Component cost priced exact per (provider, model), not apportioned from aggregate
cost_usd— and an honest "call" (whole-call) attribution default where a component can't be pinned (cache/trim → input). That's the right call: don't fake per-component precision.
Tests
test_cost_charts.py pins per-component pricing, registry-drivenness, the downsize caveat verbatim, "saved" absent, subscription framing; UI static-grep pins the chart/helpers + honesty caption + framing routing. test_ui_offline green, node --check clean.
Ready to merge. Completes the Lens-viz Wave-1 (#211/#212/#213) and clears the last beachhead gate.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The differentiated Lens viz (milestone #3): split the window's spend into the four token components and overlay each optimize analyzer's attributed recoverable waste — the cost-WASTE view a generic activity dashboard can't produce, because it depends on our analyzers' attributed estimates. Data is shaped server-side; the UI renders from the response and consumes the
framingblock (never re-derives), uses vendored uPlot (offline intact), and respects plan-tier framing.Verification (screenshot)
Delivered to the reviewer to attach here (no binaries committed to the repo, per the hard rule). It shows: the left Cost bar stacked by the 4 token components; the right Recoverable (est.) bar stacked by analyzer; the honest caption ("…a heuristic estimate to review before acting, not a realized cost reduction"); and the per-analyzer list —
Downsize → whole-call,Cache → input,Reuse → whole-call, each tagged estimated recoverable with its caveat verbatim. (Reuse appears straight from the findings dict — registry-driven.)Summary
GET /api/v1/cost/components— component cost split (input / output / cache-read / cache-write), priced per (provider, model) via the pricing table (exact, not apportioned from aggregatecost_usd) + a registry-driven per-analyzer recoverable list.ComponentWasteChart(uPlot stacked bars) on the Optimize screen: measured Cost vs Recoverable (est.) as two separate columns, plus a per-analyzer recoverable list.Honesty discipline (Rule 14 — the reason #211 was split out)
MODEL_DOWNGRADE_CAVEAT, reuse's basis, etc.).fmtFramedSavingsfor recoverable — same as the existing recoverable band —fmtFramedDollarfor measured cost), so subscription/local see token-share, and the bars themselves switch to token volume.Registry-driven
_collect_recoverableiterates the typeddowngradeslot plus every finding carrying the #111estimated_recoverable_usdcontract field — a new analyzer surfaces with no code change. Component attribution defaults to"call"(whole-call) for analyzers that can't be honestly pinned to one token component (downsize / script / reuse); cache + trim →input. The test proves it by assertingreuse(a findings-dict analyzer, not a typed slot) appears automatically.Tests / Verification
tests/integration/test_cost_charts.py(+4): per-component pricing + exact token volumes; registry-driven recoverable (reuse present) with the downsize caveat verbatim and "saved" absent from the payload; subscription framing suppresses dollars; empty-window safe.tests/unit/test_lens_ui_regression.py(+5): chart/helpers present (uPlot.paths.bars, no new lib); built fromresp.recoverable(no hard-coded analyzer list); honesty caption + "saved" absent from the [Lens viz] Cost-by-component + recoverable-waste overlay (differentiator) #211 card; recoverable routes throughfmtFramedSavings, cost total throughfmtFramedDollar.test_ui_offline.pygreen; extracted app module passesnode --check.pytest tests/unit tests/integration→ 823 passed;ruff check tokenjam/+mypy tokenjam/clean (116 files).Notes
/cost/componentsfailure renders nothing extra rather than blanking Optimize.Closes #211
🤖 Generated with Claude Code