Skip to content

feat(read): --intent flag for surgical extraction on large files #157

Closed

Description

@thehoff

Background

Per the v0.1.10 post-install weak-filters audit, the read filter ranks #4 by absolute leaked tokens despite 87% per-invocation savings:

Tool Runs Input Leaked Savings
read 1838 19.3M 2.5M 87.3%

Current filter applies a symmetric head/tail cap (80/80 lines). Heuristic — works for medium files, weaker on large files where relevant content sits in the middle.

Problem

For files > 5KB the model usually has a specific reason for reading. Today it gets head + tail; the middle is silently dropped, and either way the model doesn't know what was kept.

Proposed Design (clean-room)

Add --intent flag to contextcrawler read:

contextcrawler read large-config.json --intent "auth-related keys"
contextcrawler read schema.rs --intent "User struct + impls"

When intent provided AND input > 5KB:

  1. Tokenise intent into search terms (no stopwords)
  2. Scan file for heading-anchored sections (markdown #, Rust fn/impl, JSON top-level keys, etc.)
  3. Score sections by term-frequency match against intent
  4. Return top-N sections + one-line index of what was dropped
  5. Always preserve first 20 + last 20 lines so file shape stays readable

When intent absent OR input ≤ 5KB: behave exactly as today (no regression).

Why now

  • 1838 runs × 12.7% leaked = ~2.5M tokens
  • Large reads in this codebase: Cargo.lock (1.5M tokens), audit reports — pattern-perfect for intent extraction
  • Cleanly opt-in

Effort

S (1-2 days). New flag, lexical band-pass extractor, snapshot tests. Token-savings assertion: ≥ 90% with intent provided.

Out of scope

  • LLM-based extraction (keeps zero-async startup posture)
  • File-type heuristics beyond markdown / Rust / JSON / YAML for v1

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions