Repository navigation
#113: Cost screen — replace table-only view with a real chart - #123
Merged
Merged
Conversation
Replace the table-only Cost view with a uPlot chart that leads, table below. - Spend-over-time line/area chart (default 7d). Window toggle 24h/7d/30d/90d and group-by total/model/agent, both URL-synced (#112). Multi-series split keeps the top-5 keys + an "other" bucket. - Trend chip (▲/▼ % vs previous period) from /api/v1/cost/compare. - Single linear run-rate: dashed mean-per-day line + a plain-language "~$X over 30 days" projection (explicitly not a forecast — no moving averages). - Plan-tier framing (#110): subscription/local switch the axis + totals to token framing; the framing qualifier renders above the chart; api/unknown show dollars. Formatting mirrors core/framing.render_dollar. - Loading shimmer, empty ("No spend in this window"), and inline error+retry. - The precise daily table is preserved below the chart. - Extend /api/v1/cost with a daily `series` (per date+agent+model) so the chart can split by model/agent — the grouped `rows` collapse that dimension. No new endpoint. Dates use AT TIME ZONE 'UTC' (Rule 1). Tests: new assertion that /cost returns the daily series; offline test green; JS syntax validated; ASGI smoke confirms the series + model split. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
anilmurty
commented
Jun 18, 2026
anilmurty
left a comment
Contributor
Author
There was a problem hiding this comment.
Review: ✅ Approve with nits
Reviewed the #113-specific commit 9964b9d only — the rest of the PR diff is #110 + #112 work I already approved on #117 / #119 / #121.
Acceptance criteria — all 10 met:
- ✓ Chart leads (uPlot, 7d default), precise daily table preserved below.
- ✓ Window toggle (
?since=) and group-by toggle (?group_by=) URL-synced via #112's machinery. - ✓ Trend chip ▲/▼ % from
/api/v1/cost/compare. - ✓ Linear run-rate only: dashed mean-per-day line + "~$X over 30 days" with "linear run-rate, not a forecast" caveat. No moving averages.
- ✓ Plan-tier framing — JS reads the server's
pricing_moderather than re-deriving the rules. - ✓ Loading shimmer, "No spend in this window" empty state, inline error+retry all present.
- ✓ Theme via CSS custom properties;
useEffectcleanup correct (plot.destroy()+removeEventListener). - ✓ No new endpoint — extends
/api/v1/costwith a dailyseriesfield. - ✓ Daily table not regressed.
- ✓ Rule 1 honored (
AT TIME ZONE 'UTC'). No new f-string SQL, nodatetime.now(), no CDN URLs.
Nits / discussion points (non-blocking):
cost.py:26-30—_daily_seriesalways computes the(date, agent, model)breakdown regardless of the table'sgroup_by. Documented choice, but adds one extra GROUP BY scan per/costcall. For 90d on a busy DB this is the most expensive part of the response. Consider?series=truegating later if it shows up in profiling.- Payload scaling: top-5 + "other" bucketing happens client-side in
buildCostSeries. Full series cardinality crosses the wire — ~225KB at 90d × 5 agents × 5 models. Defensible for v1; server-side top-5 would shrink it. - Plan-tier framing: JS derives
useTokensfromframing.pricing_moderather than the explicitframing.display_rulefield. Both work today since they're consistent, but the spec wanteddisplay_ruleas the switch so the server stays the single source of truth if the rules ever diverge from rawpricing_mode. Worth a tiny follow-up. test_cost_includes_daily_series_for_chartusesif data["series"]:— passes silently if empty. Asserting non-empty after_ingest_sample_spanwould be stronger.- Polling: cadence lowered from 10s → 30s. Sensible for the heavier payload; worth calling out in the PR description.
Note on merge order: this PR's base is feature/112-uplot-url-state, so it can't merge until #117 + #121 land first. Plan to retarget to main once they do, per PR body. Tracking that.
Good work — chart looks faithful to the spec. Visual pass via tj serve recommended before merge as the PR body suggests.
# Conflicts: # tokenjam/ui/index.html
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.
Closes #113.
Stacked PR. Base is
feature/112(uPlot + URL state); also merges infeature/110(framing) since the Cost chart needs both. The diff thereforeincludes the framing module (#110) until #117/#121 merge — review the
#113-titled commit for the new work, or re-review after the parents land. I'llretarget the base to
mainas the foundations merge.What changed
the precise daily table preserved below.
24h/7d/30d/90d(?since=), group-bytotal / model / agent(?group_by=). Splits keep the top-5 keys + "other"./api/v1/cost/compare.projection, explicitly labelled not a forecast (no moving averages /
seasonality — within [feature] Cost screen — replace the table-only view with a real chart #113 scope).
token framing and surface the framing qualifier above the chart; api / unknown
show dollars. The JS formatter mirrors
core/framing.render_dollar— it readsthe server's decision, doesn't re-derive it.
state, inline error + retry.
/api/v1/costnow returns a dailyseries(per date+agent+model) so the chart can split by model/agent — thegrouped
rowscollapse that dimension. Dates useAT TIME ZONE 'UTC'(Rule 1).Tests
New assertion that
/api/v1/costreturns the daily series; offline test green;module JS validated with
node --check; ASGI smoke confirms the series + theby-model split. Full suite: 578 passed;
ruff/mypyclean.Note
Per repo convention (architecture doc: no Playwright/Cypress for v1) this is
verified via the offline + API tests; a visual pass via
tj serveisrecommended before merge.