Skip to content

feat(insights): add daily token trends and model usage costs#1668

Closed
Michaelyklam wants to merge 1 commit into
nesquena:masterfrom
Michaelyklam:fix/issue-1456-insights-tokens
Closed

feat(insights): add daily token trends and model usage costs#1668
Michaelyklam wants to merge 1 commit into
nesquena:masterfrom
Michaelyklam:fix/issue-1456-insights-tokens

Conversation

@Michaelyklam
Copy link
Copy Markdown
Contributor

@Michaelyklam Michaelyklam commented May 5, 2026

Thinking Path

  • Hermes WebUI keeps analytics in the existing Python /api/insights endpoint and vanilla-JS Insights panel, so the useful path is an endpoint/UI extension rather than a new chart dependency.
  • Issue feat(insights): daily token chart + per-model tokens/cost breakdown #1456 calls out two gaps: no daily token/cost trend for the selected 7/30/90-day window, and no per-model token/cost view.
  • The backend now aggregates the existing session index into a calendar-aligned, zero-filled daily token series plus per-model token/cost/share rows.
  • The frontend renders the new daily trend and richer model usage table inside the current Insights layout while keeping the existing token breakdown and day/hour activity cards.
  • The result is a compact way to see usage spikes and which models are driving token/cost totals.

What Changed

  • Extended api/routes.py::_handle_insights() with safe usage/cost parsing, calendar-window filtering, daily_tokens, and richer per-model models rows.
  • Updated static/panels.js and static/style.css to render a stacked daily token chart plus per-model Sessions / Tokens / Cost / Share columns with empty states.
  • Added i18n keys for the new chart/table labels.
  • Added tests/test_insights.py coverage for zero-filled daily series, cost parsing, model token/cost/share sorting, UI hooks, and range switching.
  • Added before/after UI media under docs/pr-media/1456/.

Closes #1456

Why It Matters

The old Insights tab could show aggregate tokens and session counts, but it could not answer “when did token usage spike?” or “which model is driving this month’s usage/cost?” This PR exposes those two analytics views without changing the no-build-step frontend architecture.

Verification

env -u HERMES_CONFIG_PATH /home/michael/.hermes/hermes-agent/venv/bin/python -m pytest tests/test_insights.py -q
node --check static/panels.js
node --check static/i18n.js
env -u HERMES_CONFIG_PATH /home/michael/.hermes/hermes-agent/venv/bin/python -m pytest tests/test_insights.py tests/test_korean_locale.py tests/test_issue1413_li_path_coverage.py -q
env -u HERMES_CONFIG_PATH /home/michael/.hermes/hermes-agent/venv/bin/python -m pytest tests/ -q
git diff --check

Result:

tests/test_insights.py + locale/static regression set: 13 passed
full suite: 4292 passed, 2 skipped, 3 xpassed, 1 warning, 8 subtests passed in 393.82s (0:06:33)
node --check: passed for static/panels.js and static/i18n.js
git diff --check: passed

Manual verification:

  • Started isolated WebUI instances on local temporary ports using synthetic session-index data.
  • Verified the feature branch Insights tab at 7 days renders the daily token chart, token breakdown, per-model tokens/cost/share table, and existing activity cards.
  • Verified the 7-day range selector reloads /api/insights?days=7 and renders 7 daily bars plus 3 model rows.
  • Verified raw GitHub media URLs return HTTP 200.

UI media:

Risks / Follow-ups

  • The daily chart uses lightweight CSS stacked bars rather than adding a charting dependency; if maintainers specifically prefer SVG markup, the same API payload can drive that rendering shape.
  • Existing session index rows without usage/cost metadata still render safely as zero usage / no-cost rows.

Model Used

AI assisted.

  • Provider: openai-codex
  • Model: gpt-5.5
  • Notable tool use: Hermes Kanban, git/gh, pytest, Node syntax checks, isolated WebUI browser QA, GitHub raw media verification.

@nesquena-hermes
Copy link
Copy Markdown
Collaborator

Closed by the v0.51.1 release in PR #1681 (merged at e23ba59). Massive thanks @Michaelyklam — this is now 19 merged PRs across the v0.50.292–v0.51.1 release window, an extraordinary contribution rate. Each PR was per-claim-vs-diff verified against your description and every security-relevant code path checked under independent review (Opus advisor, 6/6 questions clean). Your closes #N references are all accurate, your Thinking Path / What Changed / Why It Matters body template is consistently helpful, and your test coverage is solid behavioral scope (not source-string scaffolding) on every PR.

Live on production: https://github.com/nesquena/hermes-webui/releases/tag/v0.51.1

🚀

nesquena-hermes pushed a commit to Michaelyklam/hermes-webui that referenced this pull request May 5, 2026
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.

feat(insights): daily token chart + per-model tokens/cost breakdown

2 participants