mirror of
https://github.com/block/buzz.git
synced 2026-08-18 06:50:31 +02:00
Adds a rolling token/cost usage view for agents, sourced from the local NIP-AM metrics archive. Covers the Agents overview and a focused per-agent subview in the profile panel, with the per-agent breakdown grouped by (harness, model) so the same model under two harnesses renders as two distinct rows. Backend: - get_agent_usage_series Tauri command (archive/agent_usage.rs): reads the local SQLite archive over a sliding 7/30-day window, aggregates by (agent_pubkey, session_id, harness, model), and returns a serialized AgentUsageSeries response. - archive/metric_store.rs: MetricIndexRow + insert_metric_index_row with turn/cumulative token + cost + cache-read fields; query layer produces AgentMetricRow slices. - store_migrations.rs: M1 (harness column + index rebuild) and M2 (cache-read columns: turn_cache_read_tokens, cumulative_cache_read_tokens). M2 runs before M1 so the rebuild always operates against the full schema. All migrations are idempotent via marker guard. - archive/mod.rs: pipeline integration — AgentMetricRow ingestion, persistedAgentMetrics notifier, archiveSyncManager wiring. - tauriArchive.ts: wire types + Tauri command bridge. - archiveSyncManager.ts: persistedAgentMetrics notifier. Agent-side first-turn accounting (buzz-acp): - UsageTracker::seed_zero_baseline() seeds a zero baseline for sessions this process just spawned, so the first turn of a fresh session reports reliable deltas. Re-attached sessions are not seeded; their true prior cumulative is unknown. Seeding is idempotent via entry().or_insert(). acp.rs call sites are immediately after create_session_and_apply_model() on both channel and heartbeat paths. UI: - desktop/src/features/agent-usage/: AgentUsageDailyBars (recharts), AgentUsageRangeTabs (7/30-day preset + custom), AgentUsageFocusedView (per-agent breakdown by harness/model), AgentUsageSection (wires overview + focused view). hooks.ts: data fetch and memoised series. lib/agentUsage.ts: bucket math, formatter, caveat detection, DisplayTotal, sortModelsByKnownTotal. - Profile panel: canViewUsage/onOpenUsage threaded; BarChart3 ingress row in the Info tab. AgentsView/AgentsScreen reordered. - ProfilePanelContext: usage navigation state. - e2eBridge.ts + tests/helpers/bridge.ts: get_agent_usage_series mock handler + fixture types. - agent-usage.spec.ts: 19-test Playwright spec (loading, empty, bars, range switch, error/retry, focused view, caveats, cache-invalidation). - agent-usage-screenshots.spec.ts: 3-test screenshot spec. - playwright.config.ts: agent-usage specs added to suite. - package.json: recharts dependency. Co-authored-by: Will Pfleger <pfleger.will@gmail.com> Signed-off-by: Will Pfleger <pfleger.will@gmail.com>