Skip to content

feat(ui): visual cost bars, savings hero, and daily trend chart#418

Merged
BYK merged 2 commits into
mainfrom
feat/cost-intelligence-ui
May 20, 2026
Merged

feat(ui): visual cost bars, savings hero, and daily trend chart#418
BYK merged 2 commits into
mainfrom
feat/cost-intelligence-ui

Conversation

@BYK
Copy link
Copy Markdown
Owner

@BYK BYK commented May 20, 2026

Summary

Overhauls the Cost Intelligence page (/ui/costs) and per-session cost cards with CodexBar-inspired visual elements, making cost/savings data visually scannable via colored progress bars, ratio visualizations, and clear visual hierarchy.

Changes

Savings Hero Stat

  • Replaces the plain "Net Savings" stat pill with a prominent centered card showing $X.XX saved (Y%) in large green text (or red for net overhead)
  • Sub-label shows total spend, overhead, and counterfactual

Cost Progress Bars

  • Spend Composition: green bar showing conversation vs Lore overhead proportion
  • Savings Ratio: blue fill (actual spend) with dashed ghost outline (counterfactual "without Lore") — makes savings visually obvious at a glance
  • Cache Hit Rate: green bar for aggregated cache hit percentage
  • New reusable renderCostBar() and renderMiniBar() helpers in ui.ts

Daily Cost Trend Chart

  • CSS-only bar chart showing cost per day over the last 14 days
  • New computeDailyCosts() function in cost-tracker.ts aggregates historical + live session data by date
  • Hover tooltips show exact cost and session count

Per-Session Table Enhancements

  • Cache Hit column now includes inline mini progress bars
  • Savings cells have green/red background tinting based on net savings/overhead
  • Historical table avoided-compaction cells get green tinting when > 0

Trend Indicators

  • Spend stat pill shows a green up-arrow or red down-arrow comparing live savings rate vs historical average (with 2% dead zone to avoid noise)

Technical Notes

  • Pure server-rendered HTML + CSS — no JS frameworks or external dependencies
  • Dark/light mode works via existing prefers-color-scheme media queries
  • Only 2 files modified: ui.ts (CSS + rendering) and cost-tracker.ts (daily aggregation)
  • All 1687 tests pass, typecheck clean across all 4 packages

Overhaul the Cost Intelligence page and per-session cost cards with
CodexBar-inspired visual elements:

- Savings hero stat: prominent centered card showing total savings amount
  and percentage in large colored text
- Cost progress bars: spend composition (conversation vs overhead),
  savings ratio with ghost counterfactual outline, cache hit rate
- Daily cost trend chart: CSS-only bar chart showing cost per day over
  the last 14 days using new computeDailyCosts() in cost-tracker.ts
- Inline mini-bars: cache hit column in per-session tables now shows
  a visual progress bar alongside the percentage
- Color-coded savings cells: green/red background tinting on savings
  and avoided-compaction cells
- Trend arrows: spend stat pill shows directional indicator comparing
  live vs historical savings rate

All changes are pure server-rendered HTML+CSS with no JS framework
dependencies. Dark/light mode works via existing prefers-color-scheme.
@BYK BYK self-assigned this May 20, 2026
…tency

- C1: Add display:block to .mini-bar-fill (span elements ignore height/width)
- M1: Escape opts.value in renderCostBar, rename detail fields to
  detailLeftHtml/detailRightHtml to signal trust boundary
- M2: Accept preloaded HistoricalEstimates in computeDailyCosts() to
  avoid redundant DB scans when caller already has the data
- M3: Use consistent rate formula for trend arrows (netSavings/counterfactual
  where counterfactual = actualSpend + netSavings for both live and historical)
- L3: Handle combinedNetSavings === 0 edge case with 'Breaking even' state
- L2: Use Math.abs() instead of negation for defensive formatting
@BYK BYK merged commit 10765de into main May 20, 2026
15 of 16 checks passed
@BYK BYK deleted the feat/cost-intelligence-ui branch May 20, 2026 09:49
BYK added a commit that referenced this pull request May 20, 2026
## Summary

Follow-up fix for #418 — the daily cost trend chart was rendering but
bars had zero height, making them invisible.

## Root Causes

1. **CSS layout bug**: `.day-col` had no explicit height, so
percentage-based `height: X%` on `.day-bar` resolved to `auto`
(effectively 0px, leaving only `min-height: 2px`). The parent
`.daily-chart` had `height: 120px` but it didn't propagate through the
flex column.

2. **Zero-cost live sessions**: The live session loop added entries with
`cost: 0` to today's bucket, inflating session count without
contributing cost.

## Fix

- Give `.day-col` explicit `height: 100%` and `justify-content:
flex-end` so bars anchor to the bottom
- Switch from percentage bar heights to pixel heights calculated
server-side (`barMaxPx = 90`, leaving room for the date label)
- Add `cost > 0` guard when bucketing live sessions
- Add `flex-shrink: 0` on bar and label to prevent compression
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant