Commit Graph
1 Commits
Author SHA1 Message Date
Theo BrowneandClaude Fable 5 ee46b611d2 feat(usage): local usage analytics — durable ledger, usage.getSummary RPC, settings page
Records token/cost usage facts from live provider events into a replayable
projection, exposes a dashboard-shaped RPC, and adds Settings > Usage.

Server:
- New thread.usage-recorded orchestration event (internal thread.usage.record
  command) carrying immutable per-model interval facts with provider-native
  session identity; emitted from runtime ingestion for Codex cumulative
  token-usage updates and Claude turn.completed modelUsage settlements
  (exact cost in integer micro-USD; stale completions recorded, flagged).
- Registered projection.usage projector -> projection_usage_facts (fact_id
  upsert, migration 033). Deliberately does NOT prune on thread.reverted
  (billing history is immutable); thread deletion redacts linkage.
- Cumulative->delta baselines keyed by native session + model, reseeded from
  fact sums after restart to prevent double counting.
- ClaudeAdapter: providerRefs now carry the SDK session id. CodexAdapter:
  snapshots now include cumulative total* fields; native thread id attached
  to usage events (separates concurrent subagent sessions on one thread).
- usage.getSummary RPC (orchestration:read scope): totals, by-model, daily,
  hour-of-week, by-project buckets grouped in the caller's IANA timezone.
- Pricing: versioned effective-dated list-price catalog in shared runtime
  code; estimates computed at query time only, never stored, always flagged.
  Unpriced models surface as token-only, never $0.

Web:
- Settings > Usage per the approved mock: harness-level twin donuts
  (tokens + cost, model shades within family, striped estimate slices),
  KPI tiles, tokens-per-day stacks, hour x weekday heatmap, models table,
  project bars.

Tests: pure accounting (delta/reset/normalization), projector (idempotent
replay, revert retention, deletion redaction, session-model sums), adapter
fixtures updated for the new snapshot fields.

Co-Authored-By: Claude Fable 5 <[email protected]>
2026-07-24 04:49:36 -07:00