Skip to content

feat(gain): --insights mode — surface patterns from the tracking DB #158

Description

@thehoff

Background

gain --weak-filters (just landed in PR #150) ranks tools by leaked tokens. history.db contains 17K+ rows of empirical truth about every filter invocation. Today we report aggregates and the leaderboard; the patterns in the data go un-surfaced.

The substrate is already there — what's missing is the narrative layer that surfaces actionable patterns directly to the user.

Problem

A user reading gain output sees totals. They don't see:

Proposed Design (clean-room)

New gain --insights mode. Each insight is a function:

fn insight_proxy_overuse(tracker: &Tracker) -> Option<Insight> { ... }
fn insight_target_below_release_boundary(...) -> Option<Insight> { ... }
fn insight_target_vs_actual(...) -> Option<Insight> { ... }

Each returns Some(Insight { headline, evidence, action }) if the pattern fires.

Output:

ContextCrawler Insights — patterns in your usage
════════════════════════════════════════════════════════════════

• `ls -la target/debug/deps/` ran 8× today, all 39% saved.
  → This is your biggest absolute leak. See #?? for proposed fix.

• `proxy cargo` ran 166× lifetime (4.0M leaked, 0% saved).
  → If unintentional, drop `proxy` prefix. If intentional (filter debugging), ignore.

• `git show <ref>:<path>` saves 47% vs 80% target across 221 invocations.
  → File-content reads in git show output don't route through read filter. See #??.

JSON output (--insights --format json) for downstream consumption — dashboards, scripts, or piping into other tools.

Why now

Effort

S-M (2-4 days). Define ~10-15 patterns, narrative formatter, JSON exporter, snapshot tests on synthetic histories.

Out of scope

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions