qwen-code/packages/web-shell/client/components/dialogs/TokenHeatmap.module.css
Shaojin Wen 350191e101
feat(web-shell): add token-usage analytics dashboard to Daemon Status (#6388)
* feat(web-shell): add token-usage analytics dashboard to Daemon Status

Add a "统计 / Usage" tab to the Daemon Status page: a Today/7D/30D period toggle over the selected range's token totals and input/output/cache-read breakdown, a 12-month token heatmap (per-day tokens + cache-read tooltip, localized month labels), per-model token share, skill-call counts, and daily token/session charts.

Backend: a new read-only GET /usage/dashboard daemon API backed by a core usage-dashboard service that aggregates the durable local usage history (cross-project ~/.qwen), reusing loadUsageHistory + aggregateUsage. Skill counts are threaded through the shared usage pipeline. No new instrumentation — every metric is read from data qwen-code already persists.

* fix(web-shell): address usage-dashboard review feedback

- cap `aggregateUsage` topSkills at 25 like topTools, so the aggregate and dashboard payload stay bounded
- fix a DST drift in the heatmap grid: advance the day/month cursor by calendar day (setDate) instead of a fixed `i * MS_PER_DAY` offset
- cache the loaded history once (range-independent) so toggling Today/7D/30D re-aggregates from a single disk read; split a pure `buildUsageDashboard(records, opts)` out of `loadUsageDashboard`
- drop the unused per-day streak computation and the dead `daemon.usage.streak` i18n key
- add debug logging to the dashboard builder and a direct `aggregateUsage`-skills unit test

* fix(usage-dashboard): make the dashboard load read-only + fix cache coalescing

- Make the daemon dashboard side-effect free: `loadUsageHistory` gains a `persistRebuild` option, and the route passes `persistRebuild: false`, so serving a GET never writes to `~/.qwen`. The transcript-rebuild fallback previously persisted rebuilt records (including an in-progress session), violating the read-only contract.
- Fix cache coalescing on the slow path: a pending history load is now reused regardless of age (the TTL starts at settlement), so a request arriving after the TTL while the load is still pending no longer kicks off a second full load.
- Tests: read-only rebuild writes nothing, `metricsToUsageRecord` copies `SessionMetrics.skills`, and a pending load is shared past the TTL.
2026-07-06 13:43:41 +00:00

101 lines
2 KiB
CSS

.wrap {
position: relative;
display: flex;
flex-direction: column;
gap: 10px;
--hm-cell: 13px;
--hm-gap: 3px;
--hm-radius: 3px;
}
.tooltip {
position: absolute;
transform: translate(-50%, calc(-100% - 8px));
z-index: 5;
pointer-events: none;
white-space: nowrap;
padding: 6px 12px;
border-radius: 8px;
border: 1px solid color-mix(in srgb, var(--border) 74%, transparent);
background: var(--background);
color: var(--foreground);
font-family: var(--font-mono, monospace);
font-size: 12px;
box-shadow: 0 4px 14px color-mix(in srgb, var(--foreground) 16%, transparent);
}
.legend {
display: flex;
align-items: center;
gap: 4px;
font-size: 11px;
color: var(--muted-foreground);
}
.legendLabel {
margin: 0 4px;
}
.scroll {
overflow-x: auto;
padding-bottom: 4px;
}
.grid {
display: grid;
grid-template-rows: auto repeat(7, var(--hm-cell));
gap: var(--hm-gap);
width: max-content;
}
.month {
font-size: 11px;
color: var(--muted-foreground);
white-space: nowrap;
align-self: end;
line-height: 1;
}
.weekday {
font-size: 10px;
color: var(--muted-foreground);
padding-right: 6px;
display: flex;
align-items: center;
justify-content: flex-end;
line-height: 1;
}
.cell {
width: var(--hm-cell);
height: var(--hm-cell);
border-radius: var(--hm-radius);
}
.legendCell {
width: 12px;
height: 12px;
}
/* Sequential ramp off the accent blue — theme-aware through the token, so it
tracks light/dark automatically. Level 0 is a faint neutral track. */
.lvl0 {
background: color-mix(in srgb, var(--muted-foreground) 16%, transparent);
}
.lvl1 {
background: color-mix(in srgb, var(--agent-blue-400) 30%, transparent);
}
.lvl2 {
background: color-mix(in srgb, var(--agent-blue-400) 52%, transparent);
}
.lvl3 {
background: color-mix(in srgb, var(--agent-blue-400) 76%, transparent);
}
.lvl4 {
background: var(--agent-blue-400);
}
.today {
outline: 1.5px solid var(--agent-blue-400);
outline-offset: 1px;
}