Skip to content

feat(cost): surface cost-by-phase in the model usage dashboard (P5.T3)#407

Merged
OBenner merged 1 commit into
developfrom
claude/p5-cost-dashboard
Jul 7, 2026
Merged

feat(cost): surface cost-by-phase in the model usage dashboard (P5.T3)#407
OBenner merged 1 commit into
developfrom
claude/p5-cost-dashboard

Conversation

@OBenner

@OBenner OBenner commented Jul 7, 2026

Copy link
Copy Markdown
Owner

What

Roadmap P5·T3: «Дашборд: посчитать $ … + строку Cost … «Сборка стоила $X — планирование/код/QA»».

The backend model_usage_summary.json already carries cost_by_phase (from P5·T2), but the IPC transformSummary() dropped it and no UI surfaced a per-phase cost breakdown.

  • model-usage-handlers.ts — pass cost_by_phase through transformSummary (already present in the --get-summary output). Frontend-cached summaries written before this field simply render no section and self-heal on the existing 5-min cache 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 including phase labels (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 backend cost_by_phase.

Tests

  • 5 new in phase-costs.test.ts (pipeline ordering / zero+negative+NaN filtering / unknown-key ordering / empty-null-undefined).
  • Electron tsc 0, biome clean. Reviewed by a 2-lens adversarial workflow — 0 confirmed findings (both raised nits verified false: the $X.XX format matches the file's existing total_cost rendering; test_generation is intentional forward-compat).

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added a new Cost by Phase section in the Model Usage dashboard to show spending broken down by execution phase.
    • Phase labels are now localized and displayed in a consistent order, with unknown phases still shown.
  • Bug Fixes

    • Improved handling of phase-cost data so empty, missing, or invalid values no longer appear in the dashboard.
    • Older saved usage summaries continue to work even if phase-cost data is unavailable.

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>
@cursor

cursor Bot commented Jul 7, 2026

Copy link
Copy Markdown

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.

@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds a cost_by_phase field to the model usage backend handler and shared type, introduces a new orderPhaseCosts utility with tests for ordering/filtering phase costs, renders a "Cost by Phase" section in the Model Usage dashboard with new i18n strings, and updates roadmap documentation.

Changes

Cost by Phase Feature

Layer / File(s) Summary
Type contract and data shape
apps/frontend/src/shared/types/model-usage.ts, apps/frontend/src/renderer/lib/phase-costs.ts
Adds cost_by_phase optional field to ModelUsageSummary, and defines PhaseCost interface with PHASE_ORDER constant.
Backend passthrough and ordering utility
apps/frontend/src/main/ipc-handlers/model-usage-handlers.ts, apps/frontend/src/renderer/lib/phase-costs.ts, apps/frontend/src/renderer/__tests__/phase-costs.test.ts
transformSummary populates cost_by_phase; orderPhaseCosts filters non-positive/non-finite costs, orders known phases by pipeline order, and appends unknown phases alphabetically; tests cover empty input, ordering, filtering, and edge cases.
Dashboard UI and localization
apps/frontend/src/renderer/components/model-usage/ModelUsageDashboard.tsx, apps/frontend/src/shared/i18n/locales/en/model-usage.json, apps/frontend/src/shared/i18n/locales/fr/model-usage.json
Dashboard renders a "Cost by Phase" card using orderPhaseCosts, with i18n phase labels and formatted dollar costs; en/fr locale files add dashboard.costByPhase and dashboard.phases entries.
Roadmap documentation update
docs/strategy/roadmap.md
Roadmap replaces prior ContextViewer-based cost plan with the Cost by Phase dashboard approach and marks a corresponding checklist item complete.

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
Loading

Related Issues: Not specified in the provided context.

Related PRs: References PR #361 in roadmap documentation.

Suggested labels: frontend, i18n, documentation

Suggested reviewers: Not specified in the provided context.

🐰 A phase, a cost, a tidy row,
Ordered neatly, watch them grow,
Planning, coding, tests align,
A dashboard card now looks so fine,
Hop along, the numbers show! 🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding cost-by-phase visibility to the Model Usage dashboard.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/p5-cost-dashboard

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between e0836ed and 707de76.

📒 Files selected for processing (8)
  • apps/frontend/src/main/ipc-handlers/model-usage-handlers.ts
  • apps/frontend/src/renderer/__tests__/phase-costs.test.ts
  • apps/frontend/src/renderer/components/model-usage/ModelUsageDashboard.tsx
  • apps/frontend/src/renderer/lib/phase-costs.ts
  • apps/frontend/src/shared/i18n/locales/en/model-usage.json
  • apps/frontend/src/shared/i18n/locales/fr/model-usage.json
  • apps/frontend/src/shared/types/model-usage.ts
  • docs/strategy/roadmap.md

@sonarqubecloud

sonarqubecloud Bot commented Jul 7, 2026

Copy link
Copy Markdown

@OBenner OBenner merged commit a51a6de into develop Jul 7, 2026
20 checks passed
@OBenner OBenner deleted the claude/p5-cost-dashboard branch July 7, 2026 18:21
OBenner added a commit that referenced this pull request Jul 7, 2026
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant