Conversation
Add comprehensive model usage analytics and model lock management: - Backend: provider tracking in CostTracker, model lock CRUD in phase_config, analytics utils extraction, model usage analytics script - Frontend: ModelUsageDashboard with cards, cost chart, agent model display, lock controls and confirmation dialog - Frontend: SVGLineChart reusable component, TrendsChart refactored to use it with i18n - Frontend: Model usage settings section in project settings, IPC handlers, preload API - Refactored model-costs.ts with DRY tier helper, edge case fix in getCheapestModel - Added session.py model field tracking per conversation round - i18n support (en/fr) for model-usage namespace Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Caution Review failedFailed to post review comments 📝 WalkthroughWalkthroughThis pull request introduces comprehensive model usage analytics and model lock management across the platform. It adds analytics data aggregation, cost tracking by provider, model configuration locking mechanisms, and a full-stack dashboard for visualizing model usage metrics, trends, and enabling lock controls. Changes
Sequence Diagram(s)sequenceDiagram
actor User
participant Frontend as Frontend<br/>(Dashboard)
participant IPC as IPC Handler
participant Backend as Python<br/>Analytics
participant FileSystem as File System<br/>(.auto-claude)
User->>Frontend: Open Model Usage Dashboard
Frontend->>IPC: getModelUsageSummary(projectId, filter?)
IPC->>FileSystem: Check cache validity
alt Cache valid & fresh
IPC->>IPC: Return cached summary
else Cache missing/stale
IPC->>Backend: execute model_usage_analytics.py
Backend->>FileSystem: Scan specs/ for cost_report.json
Backend->>Backend: Aggregate metrics by model & agent
Backend->>Backend: Compute period bounds & totals
Backend->>IPC: Return ModelUsageSummary JSON
IPC->>FileSystem: Write updated cache
end
IPC->>Frontend: IPCResult<ModelUsageSummary>
Frontend->>Frontend: Render summary metrics & cards
User->>Frontend: Select time range (7d/30d/90d/all)
Frontend->>IPC: getModelUsageTrends(projectId, filter)
IPC->>Backend: execute model_usage_analytics.py with --window-days & --granularity
Backend->>Backend: Build time-series by period
Backend->>IPC: Return trend points list
IPC->>Frontend: IPCResult<ModelUsageTrendPoint[]>
Frontend->>Frontend: Render CostChart with trends
User->>Frontend: Click lock icon on agent
Frontend->>IPC: lockAgentModel(projectId, agentType, modelId)
IPC->>Backend: execute model_locks_manager.py lock-agent
Backend->>FileSystem: Read model_locks.json
Backend->>FileSystem: Write locked model_id
Backend->>Backend: Verify lock persisted
Backend->>IPC: Return success
IPC->>Frontend: IPCResult<{success: true}>
Frontend->>Frontend: Update lock UI, show success toast
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
There was a problem hiding this comment.
CodeQL found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.



Summary
TrendsChartinto reusableSVGLineChartcomponent with i18n supportmodel-costs.tspricing database using shared tier helpersChanges
Backend
core/cost_tracking.py—providerfield inUsageRecord,get_cost_by_provider()methodphase_config.py—ModelLockConfigtype, lock/unlock CRUD for phases and agents with JSON persistenceagents/session.py—modelfield tracking per conversation roundanalysis/analytics_utils.py— extracted shared timestamp/CLI utilities fromproductivity_analytics.pyanalysis/model_usage_analytics.py— model usage analytics scriptscripts/model_locks_manager.py— CLI for managing model locksFrontend
components/model-usage/— 6 new components (Dashboard, Card, CostChart, AgentModelDisplay, ModelLockControl, ConfirmDialog)components/analytics/SVGLineChart.tsx— reusable SVG line chart componentcomponents/analytics/TrendsChart.tsx— refactored to use SVGLineChart + i18ncomponents/project-settings/ModelUsageSettings.tsx— settings integrationmodel-costs.ts— DRY refactor withtier()helper, edge case fixTest plan
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes