feat(cost): surface cost-by-phase in the model usage dashboard (P5.T3)#407
Conversation
The backend model_usage_summary.json already carries cost_by_phase (P5.T2), but transformSummary() dropped it and no UI showed a per-phase cost breakdown. - model-usage-handlers.ts: pass cost_by_phase through transformSummary (it's already in the --get-summary output; cached summaries lacking it render nothing and self-heal on the 5-min TTL) - ModelUsageSummary type: optional cost_by_phase field - new pure orderPhaseCosts() helper: pipeline order (planning → coding → test_generation → validation → profiling), unknown keys appended alphabetically, non-positive/non-finite dropped - ModelUsageDashboard: a 'Cost by Phase' card (planning/coding/QA/… with $ amounts), i18n en/fr incl. phase labels (validation → QA) Roadmap named ContextViewer.tsx, but it's dead code (mounted nowhere); the card lands in the live, sidebar-reachable Model Usage dashboard. Tests: 5 new (orderPhaseCosts ordering / zero+negative+NaN filtering / unknown-key handling). Electron tsc 0, biome clean. Reviewed by a 2-lens adversarial workflow — 0 confirmed findings. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Signed-off-by: Oleg Miagkov <mrobenner@gmail.com>
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
📝 WalkthroughWalkthroughAdds a ChangesCost by Phase Feature
Estimated code review effort: 2 (Simple) | ~15 minutes Sequence Diagram(s)sequenceDiagram
participant Backend
participant Handler as transformSummary
participant Dashboard as ModelUsageDashboard
participant OrderUtil as orderPhaseCosts
Backend->>Handler: raw.cost_by_phase
Handler->>Dashboard: summary.cost_by_phase
Dashboard->>OrderUtil: orderPhaseCosts(summary.cost_by_phase)
OrderUtil-->>Dashboard: ordered PhaseCost[]
Dashboard-->>Dashboard: render Cost by Phase card
Related Issues: Not specified in the provided context. Related PRs: References PR Suggested labels: frontend, i18n, documentation Suggested reviewers: Not specified in the provided context. 🐰 A phase, a cost, a tidy row, 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning Tools execution failed with the following error: Failed to run tools: 13 INTERNAL: Received RST_STREAM with code 2 (Internal server error) 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.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@apps/frontend/src/renderer/components/model-usage/ModelUsageDashboard.tsx`:
- Around line 337-366: The Cost by Phase section is rendered via an inline IIFE
inside JSX instead of a dedicated component, which breaks the existing
composition pattern used in ModelUsageDashboard. Extract the phase-cost
calculation and conditional rendering into a small CostByPhaseCard component (or
similarly named component), and have ModelUsageDashboard pass
summary.cost_by_phase and t into it, mirroring the structure used by
ModelUsageCard and ModelListSection.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: c2d3801c-3a99-4698-b6a7-2ad06ba30929
📒 Files selected for processing (8)
apps/frontend/src/main/ipc-handlers/model-usage-handlers.tsapps/frontend/src/renderer/__tests__/phase-costs.test.tsapps/frontend/src/renderer/components/model-usage/ModelUsageDashboard.tsxapps/frontend/src/renderer/lib/phase-costs.tsapps/frontend/src/shared/i18n/locales/en/model-usage.jsonapps/frontend/src/shared/i18n/locales/fr/model-usage.jsonapps/frontend/src/shared/types/model-usage.tsdocs/strategy/roadmap.md
|
CodeRabbit: the Cost-by-Phase block computed + conditionally rendered via an inline IIFE, unlike the file's other card sections (ModelRow, ModelListSection). Extract a CostByPhaseCard sub-component to match the composition pattern. Behavior-identical. Signed-off-by: Oleg Miagkov <mrobenner@gmail.com> Co-authored-by: Claude Fable 5 <noreply@anthropic.com>



What
Roadmap P5·T3: «Дашборд: посчитать $ … + строку Cost … «Сборка стоила $X — планирование/код/QA»».
The backend
model_usage_summary.jsonalready carriescost_by_phase(from P5·T2), but the IPCtransformSummary()dropped it and no UI surfaced a per-phase cost breakdown.cost_by_phasethroughtransformSummary(already present in the--get-summaryoutput). Frontend-cached summaries written before this field simply render no section and self-heal on the existing 5-min cache TTL.cost_by_phasefield.orderPhaseCosts()helper — pipeline order (planning → coding → test_generation → validation → profiling), unknown keys appended alphabetically, non-positive/non-finite dropped.validation→ "QA").Deviation from the roadmap's named file
The roadmap said the cost line goes in
ContextViewer.tsx, but ContextViewer is dead code — it's mounted nowhere in the renderer (only its main-process handlers + preload API exist). The genuinely visible, sidebar-reachable cost surface is the Model Usage dashboard (activeView === 'model-usage', shortcut O), which already shows total/per-agent/per-model cost — so the per-phase breakdown lands there.Acceptance
Model Usage → Cost by Phase:
Planning $X · Coding $Y · QA $Z · …, sourced from the real backendcost_by_phase.Tests
phase-costs.test.ts(pipeline ordering / zero+negative+NaN filtering / unknown-key ordering / empty-null-undefined).tsc0, biome clean. Reviewed by a 2-lens adversarial workflow — 0 confirmed findings (both raised nits verified false: the$X.XXformat matches the file's existingtotal_costrendering;test_generationis intentional forward-compat).🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes