feat: add usage statistics visualization (closes #13)#55
Open
Neo2025new wants to merge 3 commits intoErlichLiu:mainfrom
Open
feat: add usage statistics visualization (closes #13)#55Neo2025new wants to merge 3 commits intoErlichLiu:mainfrom
Neo2025new wants to merge 3 commits intoErlichLiu:mainfrom
Conversation
Add StreamUsageEvent to the event system and implement token usage extraction across all three provider adapters: - Anthropic: parse message_start (input_tokens) + message_delta (output_tokens) - OpenAI: enable stream_options.include_usage, parse final usage chunk - Google: parse usageMetadata from streaming response Token usage is accumulated across tool-use rounds in chat-service and persisted as an optional `usage` field on ChatMessage. This lays the groundwork for usage statistics visualization (Issue ErlichLiu#13). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add the data persistence and IPC layer for token usage tracking: - New UsageRecord/UsageSummary types and USAGE_IPC_CHANNELS constants - usage-stats-service.ts: read/write ~/.proma/usage-stats.json with daily and per-model aggregation queries - Register IPC handlers for getUsageSummary and clearUsageStats - Expose APIs through preload bridge - Call recordUsage() in chat-service after message persistence Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add UsageSettings component with token consumption dashboard: - Today/30-day summary cards with formatted token counts - 30-day trend AreaChart (input/output tokens) - Per-model usage distribution list - Empty state placeholder - Register usage tab in SettingsPanel navigation Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #13
Complete implementation of token usage statistics tracking and visualization, split into 3 logical commits:
Commit 1: Token Capture Layer
Capture token usage from all provider SSE streaming responses:
message_start.usage+message_delta.usagestream_options, parse final usage chunkusageMetadatafrom stream responseChatMessage.usageCommit 2: Storage Service + IPC
Data persistence and IPC layer for usage tracking:
UsageRecord/UsageSummarytypes +USAGE_IPC_CHANNELSconstantsusage-stats-service.ts: read/write~/.proma/usage-stats.jsonwith daily + per-model aggregationrecordUsage()after message persistence in chat-serviceCommit 3: UI Visualization
Settings panel with recharts dashboard:
Files Changed (16 files)
packages/core/ (4 files)
providers/types.ts—StreamUsageEventtypeproviders/sse-reader.ts—TokenUsageinterface, accumulation inStreamSSEResultproviders/anthropic-adapter.ts— Anthropic usage parsingproviders/openai-adapter.ts— OpenAI usage parsingproviders/google-adapter.ts— Google usage parsingpackages/shared/ (2 files)
types/usage.ts— Usage types and IPC channel constantstypes/chat.ts—MessageUsageonChatMessageapps/electron/ (10 files)
main/lib/usage-stats-service.ts— Storage service (new)main/lib/config-paths.ts—getUsageStatsPath()main/lib/chat-service.ts— Usage accumulation +recordUsage()callmain/ipc.ts— IPC handler registrationpreload/index.ts— Preload bridge APIsrenderer/atoms/usage-atoms.ts— Jotai atoms (new)renderer/atoms/settings-tab.ts— Add 'usage' tab typerenderer/components/settings/UsageSettings.tsx— Dashboard UI (new)renderer/components/settings/SettingsPanel.tsx— Tab registrationpackage.json— recharts dependencyDesign Decisions
usage?field on ChatMessage — fully backward compatible with existing JSONL dataTest plan
bun run typecheckpasses across all packages ✅message_start/message_deltastream_optionsworks, usage returnedusageMetadataparsed correctly🤖 Generated with Claude Code