Skip to content

feat(gain): add command sorting, filtering, and row limits - #4435

Open
yeahjack wants to merge 19 commits into
rtk-ai:developfrom
yeahjack:feat/gain-command-controls
Open

yeahjack wants to merge 19 commits into
rtk-ai:developfrom
yeahjack:feat/gain-command-controls

Conversation

@yeahjack

@yeahjack yeahjack commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Add --sort saved|count|ratio, --reverse, --limit N (0 for all), and literal --filter / --exclude controls to the rtk gain By Command table.
  • Apply project scope and filtering before grouping, sorting, and limiting, so frequently used commands outside the old top ten can surface. Preserve weighted ratios and signed savings ordering, with deterministic command-name ties.
  • Export the same selected rows through summary JSON/CSV, document the controls and Impact column, and cover selection, formatting, and compatibility with regression tests.

Addresses #1700.

Usage and compatibility

rtk gain --sort count --limit 25
rtk gain --sort ratio --reverse
rtk gain --filter gradle --exclude test
rtk gain --project --limit 0 --format json

The default stays at ten rows sorted by saved tokens. Filters are case-sensitive literal substrings of the full recorded RTK command. They affect the By Command rows; summary totals, graph, history, and quota retain their current scope. Command-table controls conflict with temporal/failure/recall/reset views rather than being silently ignored; --all retains its existing temporal meaning.

Summary JSON adds by_command records with command, count, saved_tokens, savings_pct, and avg_time_ms. Summary CSV now exports those columns, with full command names and CSV escaping. Temporal export schemas stay unchanged.

Accounting semantics are preserved: sorting uses signed recorded savings before the existing display clamp; ratios remain SUM(saved_tokens) / SUM(input_tokens), with zero-input groups returning zero. A derived potential score and a pager are outside this change.

Test plan

Verified locally on Linux with Rust 1.99.0:

  • cargo fmt --all --check
  • cargo clippy --locked --all-targets
  • cargo test --locked --all: 4,123 passed, zero failed, eight existing ignored
  • Ten new integration tests, also passing with hostile GIT_DIR, RTK_DB_PATH, RTK_NO_TOML, and RTK_TEE values
  • Initial eight feature tests fail against unmodified develop and pass with this implementation
  • cargo build --locked --release and isolated release-binary smoke checks for count sorting beyond the old top ten, unlimited results, and CSV selection
  • Independent review: default text unchanged for uniquely ranked groups; all twelve temporal view/export combinations unchanged; 110-row alignment, signed/mixed/zero-input groups, literal Unicode/SQL-like filters, large limits, and conflicting flags checked
  • git diff --check and repository test-presence check

The eight existing ignored tests were not run locally.

Windows CI follow-up

The initial CI run exposed a Windows test-thread stack overflow in Clap's large generated command parser. The follow-up commit isolates only the five new options in a boxed, flattened argument group. Existing option names, defaults, conflicts, and query behavior are preserved; global stack settings are unchanged.

After the fix, CI run 37138579529 passes on head 7445367: Linux, Windows, and macOS tests, benchmark, fmt/clippy, security scan, and Semgrep. Windows explicitly passes the previously overflowing parser test and all ten new gain integration tests. CLA also passes. The optional AI documentation-review step was skipped because the repository API key is not configured.

@rtk-wshm-sync-bot rtk-wshm-sync-bot Bot added analytics cli enhancement New feature or request labels Oct 3, 2026
@rtk-wshm-sync-bot

Copy link
Copy Markdown

wshm · Automated triage by AI

📊 Automated PR Analysis

✨ Type feature
🟡 Risk medium

Summary

Adds --sort, --reverse, --limit, --filter, and --exclude controls to the rtk gain By Command table, applying project scope and filtering before grouping/sorting/limiting so commands beyond the old top-ten can surface. Extends summary JSON/CSV exports with the same selected by_command rows and updates docs, with new integration tests covering selection, formatting, and compatibility.

Review Checklist

  • Tests present
  • Breaking change
  • Docs updated

Linked issues: #1700


Analyzed automatically by wshm · This is an automated analysis, not a human review.

@yeahjack
yeahjack marked this pull request as ready for review October 4, 2026 20:22
@CLAassistant

CLAassistant commented Oct 19, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@yeahjack
yeahjack force-pushed the feat/gain-command-controls branch from a43e77f to 51c8b27 Compare October 19, 2026 10:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

analytics cli enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants