Skip to content

Add live limits widget, session health, multi-metric efficiency grader, and per-message live session view#123

Open
changsunglim wants to merge 3 commits into
phuryn:mainfrom
changsunglim:feature/limits-efficiency-improvements
Open

Add live limits widget, session health, multi-metric efficiency grader, and per-message live session view#123
changsunglim wants to merge 3 commits into
phuryn:mainfrom
changsunglim:feature/limits-efficiency-improvements

Conversation

@changsunglim
Copy link
Copy Markdown

Summary

Adds plan-budget visibility, session-health hints, a multi-metric efficiency grade, and a per-message live view of in-flight sessions. Also fixes a ReferenceError (cutoffstart/end) that was killing all charts, and replaces UTC-only timestamps with auto-detected local TZ.

All changes are additive — no breaking API changes, no new third-party deps, still standard-library only.

What's new

Live limits widget (limits.py + /api/limits)

  • Weekly stacked bar (Opus / Sonnet / Haiku) with a per-model breakdown line: opus X% · 5.5M sonnet Y% · 550k haiku Z%.
  • Plan auto-detect: macOS keychain → Anthropic OAuth profile endpoints → CLAUDE_USAGE_PLAN env → pro default. 24h cache at ~/.claude/usage-plan-cache.json.
  • Approximate budgets for pro / max_5x / max_20x (Anthropic doesn't publish exact caps — calibrated to within ~25% on real usage).
  • Cache-read tokens weighted 0.1× in billable totals to mirror Anthropic's cost-equivalent counting.
  • ThreadingHTTPServer so /api/limits and /api/data don't block each other.

Session Health card

Heuristic "start new session" warning when any of:

  • Context > 150k tokens
  • Cache hit rate < 40%
  • Avg > 60k tokens/turn
  • Session age > 3h

States: ok / info / warn with colored border.

Token Efficiency grader (replaces "By Model" pie)

Weighted A/B/C/D grade:

  • Cache Hit 40%
  • Reuse Ratio 25%
  • Cost Efficiency 20%
  • Output Discipline 15%

? info button reveals the formula. Recalcs with /api/data, respects date-range filter.

Per-message live session view (/api/session/<id>)

Click a session row → polls every 5s. Each user prompt shows token totals (input / output / cache_read / cache_creation), model, turn count, and tools used. Skill invocations and <system-reminder> blocks are filtered so the list shows real human turns only.

Quality-of-life

  • Session titles extracted from first JSONL user prompt (replaces opaque project IDs).
  • Local timezone auto-detect via datetime.now().astimezone().utcoffset() — no more manual UTC offset.
  • Hourly chart: average divides by calendar days in range, not active-days-only (was inflating averages); SQL pre-shifts hour to local so JS no longer double-shifts.
  • Auto-rescan on every /api/data fetch (incremental scan is cheap).
  • Bug fix: cutoffstart/end ReferenceError that was killing all charts in the previous filter refactor.

Files touched

File Change
dashboard.py Adds limits banner, session health card, efficiency grader, live session route, TZ autodetect, hourly-average fix
limits.py New — plan detection + budget computation
README.md Fork notice + documents new features

Notes for review

  • Plan budgets in PLAN_BUDGETS are approximations — happy to remove the table and surface "% of weekly" only if you prefer not to ship numbers Anthropic hasn't published.
  • Session Health thresholds are tunable constants at the top of the JS — easy to move to a config block.
  • All UI additions are gated behind their own components; existing dashboard layout unchanged.

Happy to split this into smaller PRs (limits / efficiency / live-view / bugfix) if that's easier to review. Let me know what you prefer.

…view

- limits.py: plan auto-detect via keychain OAuth + 24h cache; per-plan
  session-5h + weekly budgets for pro/max_5x/max_20x; rolling 7d split
  by opus/sonnet/haiku
- Dashboard top banner: weekly stacked bar (Opus/Sonnet/Haiku) with
  per-model breakdown line; ThreadingHTTPServer so /api/data and
  /api/limits don't block each other
- Session Health card: heuristic "start new session" warning when
  context >150k, cache-hit <40%, avg >60k tok/turn, or age >3h
- Token Efficiency: weighted grader (Cache Hit 40% + Reuse Ratio 25% +
  Cost Efficiency 20% + Output Discipline 15%) with info tooltip; replaces
  "By Model" pie; respects date-range filter
- Per-message live view: /api/session/<id> groups turns by user prompt;
  click row → polls every 5s; filters skill/system-reminder noise so list
  shows only real human turns
- Session titles from first JSONL user prompt (replaces opaque project IDs)
- Local TZ auto-detect via datetime().astimezone().utcoffset()
- Hourly chart: average divides by calendar days in range (not active-only
  days); SQL pre-shifts so JS no longer double-shifts
- Auto-rescan on every /api/data fetch
- Bug fix: cutoff → start/end ReferenceError that killed all charts
- Fork banner with link to upstream
- Fork features section: limits widget, plan budget table, session
  health heuristic, efficiency grader formula, live view, new endpoints
- Add limits.py to files table
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