Skip to content

feat: track API profile per session for per-profile stats (#32)#38

Merged
ourines merged 1 commit intomainfrom
feat/issue-32-profile-tracking
Feb 18, 2026
Merged

feat: track API profile per session for per-profile stats (#32)#38
ourines merged 1 commit intomainfrom
feat/issue-32-profile-tracking

Conversation

@ourines
Copy link
Owner

@ourines ourines commented Feb 18, 2026

Summary

  • Add Profile field to SessionRecord, populated with config.Default at scan time (falls back to "unknown")
  • Add ByProfile map[string]float64 to DailyStat for per-profile cost aggregation
  • Add ProfileCost struct, ProfileBreakdown() function, and TopProfiles to Summary
  • TUI Stats tab: f key now cycles all → project → model → profile → all

Changes

File What changed
internal/stats/types.go Profile on SessionRecord, ByProfile on DailyStat, ProfileCost struct, TopProfiles on Summary
internal/stats/scanner.go Load config.Default at scan time and pass to parseSessionFile
internal/stats/aggregator.go Populate ByProfile in Aggregate, add ProfileBreakdown(), include in GenerateSummary
internal/tui/stats_view.go Add profile to f-key cycle, aggregateByProfile(), "By Profile:" render section

Test plan

  • go vet ./... — no errors
  • go test ./... — all tests pass
  • Manual: codes → Stats tab → press f repeatedly to cycle through all/project/model/profile views

Summary by CodeRabbit

New Features

  • Profile cost tracking: Sessions now record the API profile used, enabling costs to be aggregated and displayed by profile.
  • Enhanced stats view: Added "By Profile" breakdown option to display top profiles by cost, cycling through project, model, and profile views.

- Add Profile field to SessionRecord, populated with config.Default at scan time
- Add ByProfile map to DailyStat for per-profile cost aggregation
- Add ProfileCost struct and TopProfiles to Summary
- Add ProfileBreakdown() aggregator function
- Update Aggregate() to populate ByProfile data
- Add 'profile' view to TUI Stats tab f-key cycle (all→project→model→profile→all)
- Add aggregateByProfile() and rendering in stats_view.go
@coderabbitai
Copy link

coderabbitai bot commented Feb 18, 2026

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

The changes introduce profile-level cost tracking throughout the stats system. Profiles are detected from config during session scanning, accumulated in daily stats aggregations, exposed via a ProfileBreakdown function, and rendered in the TUI alongside existing project and model breakdowns.

Changes

Cohort / File(s) Summary
Data Model Enhancements
internal/stats/types.go
Adds Profile field to SessionRecord, ByProfile map to DailyStat, TopProfiles list to Summary, and new ProfileCost type for cost aggregation by profile.
Profile Detection & Propagation
internal/stats/scanner.go
Detects default user profile from config, propagates it through ScanSessions, and passes it to parseSessionFile where it's assigned to SessionRecord.Profile. Adds file close handling via defer.
Profile Cost Aggregation
internal/stats/aggregator.go
Accumulates costs by profile in DailyStat.ByProfile during aggregation, adds ProfileBreakdown function to compute total costs by profile across all stats, and exposes TopProfiles in GenerateSummary output.
TUI Profile Breakdown Display
internal/tui/stats_view.go
Adds aggregateByProfile function and renders "By Profile" section in stats view. Extends breakdown cycling to include profile option and updates help text and labels accordingly.

Sequence Diagram

sequenceDiagram
    participant Scanner as Session Scanner
    participant Config as Config System
    participant Aggregator as Stats Aggregator
    participant TUI as TUI Display

    Scanner->>Config: Load default user profile
    Config-->>Scanner: Return profile (or "unknown")
    
    Scanner->>Scanner: ScanSessions with currentProfile
    Scanner->>Scanner: parseSessionFile(..., profile)
    Scanner->>Scanner: Create SessionRecord with Profile field
    
    Scanner->>Aggregator: Pass SessionRecord with profile
    Aggregator->>Aggregator: Accumulate costs to DailyStat.ByProfile
    Aggregator->>Aggregator: ProfileBreakdown(dailyStats)
    Aggregator-->>Aggregator: Return sorted []ProfileCost
    
    Aggregator->>Aggregator: GenerateSummary with TopProfiles
    Aggregator-->>TUI: Summary containing TopProfiles
    
    TUI->>TUI: aggregateByProfile(dailyStats)
    TUI->>TUI: Render "By Profile" section
    TUI-->>TUI: Display profile costs sorted
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related issues

Poem

🐰 Hop along with profiles clear,
Each session's cost now tracked right here,
From scanner's detection to UI's glow,
Profile breakdowns steal the show!

✨ Finishing Touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/issue-32-profile-tracking

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


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 and usage tips.

@ourines ourines merged commit 644ace8 into main Feb 18, 2026
2 of 3 checks passed
@ourines ourines deleted the feat/issue-32-profile-tracking branch February 18, 2026 07:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments