Skip to content

feat(tui): filter usage by model - #218

Merged
mike1858 merged 3 commits into
Piebald-AI:mainfrom
jimyag:feat/model-filter
Jul 31, 2026
Merged

feat(tui): filter usage by model#218
mike1858 merged 3 commits into
Piebald-AI:mainfrom
jimyag:feat/model-filter

Conversation

@jimyag

@jimyag jimyag commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Summary

Add an interactive TUI model filter and show each model's usage share for the selected period.

Key changes

  • Press f to edit a case-insensitive, partial model-name filter; use Enter to apply, Esc to cancel, and Ctrl+U to clear.
  • Recalculate aggregate tokens, cost, tool calls, messages, and conversation counts from matching model data.
  • Filter the Sessions view to conversations that used a matching model.
  • Display per-period and totals-row model shares, using input + output + cached tokens and falling back to message counts when token details are incomplete.

Validation

  • cargo build --quiet
  • cargo test --quiet (401 passed)
  • cargo clippy --quiet -- -D warnings
  • cargo doc --quiet
  • cargo fmt --all --quiet
  • git diff --check
  • Ratatui TestBackend rendering coverage for filtered models, recalculated cost, and model shares

Notes

  • The filter is session-local and does not change persistent configuration.
  • Session rows are selected by model membership; their numeric values remain whole-session totals because session aggregates do not retain per-model token breakdowns.

Summary by CodeRabbit

  • New Features

    • Added an interactive model filter accessible with the f key.
    • Filter model statistics using case-insensitive name matching.
    • Edit, clear, apply, or cancel filters while preserving them during updates.
    • Display active filter status, usage percentages, and estimated-model indicators.
    • Updated keyboard help and disabled quit/update shortcuts while editing.
  • Bug Fixes

    • Filtering now recalculates statistics, costs, sessions, daily summaries, and usage shares accurately, including when no models match.
    • Aggregate totals now reflect only the currently visible time periods.

Add an interactive model filter that recalculates aggregate usage and session visibility. Show per-period and total model shares using tokens with a message-count fallback.

Signed-off-by: jimyag <git@jimyag.com>
@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: bfd865c9-5929-47fd-99c6-720f8f48b281

📥 Commits

Reviewing files that changed from the base of the PR and between 582b2c8 and 6e58eeb.

📒 Files selected for processing (2)
  • src/tui.rs
  • src/tui/tests.rs
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/tui/tests.rs
  • src/tui.rs

📝 Walkthrough

Walkthrough

The TUI adds case-insensitive model filtering with editable input, cancellation, persistent application, recalculated statistics, and filtered sessions. Aggregate rows display usage shares from visible-period statistics. Tests cover filtering, fallback data, percentages, and rendering.

Changes

Model filtering and usage display

Layer / File(s) Summary
Filter analyzer data
src/tui.rs
Model filtering retains matching models and recalculates daily statistics, session aggregates, conversations, and totals. The filter reapplies when statistics change.
Interactive filter workflow
src/tui.rs
The f key opens filter input. Editing supports character entry, backspace, Ctrl+U, Enter, and Esc. Active editing guards quit and update shortcuts.
Usage share aggregation and validation
src/tui.rs, src/tui/tests.rs
Aggregate rows calculate sorted token-based usage shares with message-count fallback and estimated-model markers. Tests cover filtered calculations, empty matches, percentages, and table rendering.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant run_app
  participant UiState
  participant filter_analyzer_view_by_model
  User->>run_app: press f
  run_app->>UiState: activate filter editing
  User->>run_app: edit or apply model text
  run_app->>filter_analyzer_view_by_model: apply model filter
  filter_analyzer_view_by_model-->>UiState: return filtered statistics
  UiState-->>User: redraw filtered views and usage shares
Loading

Possibly related PRs

Suggested reviewers: mike1858

Poem

A rabbit presses f beneath the moon,
Matching models gather in tune.
Totals show their shares with care,
Sessions follow matching data there.
Enter applies; Esc restores the view.

🚥 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 and concisely describes the main change: adding model-based usage filtering to the TUI.
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 unit tests (beta)
  • Create PR with unit tests

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

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 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 `@src/tui.rs`:
- Around line 1514-1525: Update the non-empty model-filter branch in the
help_text construction to append the existing estimated-pricing note whenever
has_estimated_models is true, matching the behavior of the unfiltered help
branch while preserving the current filter controls and base_help_text.
- Around line 267-305: Update the DailyStats filtering logic around filtered_day
to preserve user_messages if it is consumed downstream, and handle days where
model_stats is incomplete relative to models without silently zeroing totals.
Inspect user_messages usages and the data-building paths, then apply the
established fallback behavior for matched models (at minimum preserving
message-count totals) while retaining accurate model_stats-derived metrics when
available. Ensure the reconstructed filtered_day and downstream totals remain
consistent for cached and current data.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 30232248-c9dc-42f2-b0d9-12edd4978ca4

📥 Commits

Reviewing files that changed from the base of the PR and between 9de0187 and 8e93d5c.

📒 Files selected for processing (2)
  • src/tui.rs
  • src/tui/tests.rs

Comment thread src/tui.rs
Comment thread src/tui.rs Outdated
Keep message totals and attributable stats when per-model details are incomplete. Preserve estimated-pricing guidance while a model filter is active.

Signed-off-by: jimyag <git@jimyag.com>
@jimyag

jimyag commented Jul 31, 2026

Copy link
Copy Markdown
Contributor Author
image

@mike1858 mike1858 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Cool, this is amazing! Thank you for all of your PRs by the way - they're very useful, and the screenshots you attach help me understand the feature better and review faster 👍

Signed-off-by: jimyag <git@jimyag.com>

# Conflicts:
#	src/tui.rs
#	src/tui/tests.rs
@mike1858

Copy link
Copy Markdown
Member

@jimyag Due to merging one of the other PRs, you have some new merge conflicts. Will you please fix them?

@jimyag

jimyag commented Jul 31, 2026

Copy link
Copy Markdown
Contributor Author

Thank you! I’m glad the PRs have been useful, and I’ll keep including screenshots where they help make the behavior easier to review. I really appreciate your time and feedback! 🙏

@mike1858
mike1858 enabled auto-merge (squash) July 31, 2026 16:34
@mike1858
mike1858 merged commit 1a6ec61 into Piebald-AI:main Jul 31, 2026
6 checks passed
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.

2 participants