Skip to content

feat(gain): add gain --weak-filters — rank tools by leaked tokens - #135

Merged
thehoff merged 1 commit into
developfrom
feat/gain-weak-filters
May 23, 2026
Merged

thehoff merged 1 commit into
developfrom
feat/gain-weak-filters

Conversation

@thehoff

@thehoff thehoff commented May 23, 2026

Copy link
Copy Markdown
Owner

The e2e audit (docs/audits/2026-05-22-e2e-review.md) flagged that the tracking DB already holds the data to show where tokens leak, but nothing surfaces it. gain reports blended savings; it doesn't tell you which filter to fix next.

gain --weak-filters (-W) ranks tools by leaked tokens — input that reached the model unfiltered (input − saved). High leak + low savings% = a filter worth improving, or a command with no filter worth building. Passthrough rows (0 input) contribute nothing and drop out — so honest no-ops do not pollute the ranking.

  • tracking::get_weak_filters aggregates per-command rows into tool buckets via weak_filter_tool_key (git log, read, cargo test), computes leak, sorts highest-first. Project-scope aware.
  • gain::show_weak_filters renders the ranked table.
  • New WeakFilter struct (Serialize-ready for future JSON export).

Empirically, on a seeded DB this immediately surfaces read as the top leaker at 0% savings — exactly the READ-I1 audit finding — without any manual DB spelunking.

Tests: +2 (tool-key extraction; leak ranking + passthrough exclusion), 2,535 pass, clippy clean.

🤖 Generated with Claude Code

The E2E audit (docs/audits/2026-05-22-e2e-review.md) flagged that the
tracking DB already holds the data to show *where tokens leak*, but
nothing surfaces it. `gain` reports blended savings; it does not tell
you which filter to fix next.

`gain --weak-filters` (`-W`) ranks tools by leaked tokens — input that
reached the model unfiltered (`input - saved`). A high leak paired with
a low savings% is a filter worth improving, or a command with no filter
worth building. Passthrough rows (0 input) contribute nothing and drop
out, so honest no-ops do not pollute the ranking.

  - tracking::get_weak_filters aggregates per-command rows into tool
    buckets via weak_filter_tool_key (`git log`, `read`, `cargo test`),
    computes leak, sorts highest-first. Project-scope aware.
  - gain::show_weak_filters renders the ranked table.
  - New `WeakFilter` struct (Serialize-ready for future JSON export).

Empirically, on a seeded DB this immediately surfaces `read` as the
top leaker at 0% savings — exactly the READ-I1 audit finding — without
any manual DB spelunking.

2 unit tests (tool-key extraction; leak ranking + passthrough exclusion).
2,535 tests pass, clippy clean.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@thehoff
thehoff merged commit f9e5270 into develop May 23, 2026
4 checks passed
@thehoff
thehoff deleted the feat/gain-weak-filters branch May 23, 2026 00:23
noogalabs pushed a commit to noogalabs/contextcrawler that referenced this pull request Jun 4, 2026
fix(grep): accept -n flag for grep/rg compatibility
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