rtk-ai/rtk

enhancement: grep filter truncation may cause AI agents to miss search results

Open

#1161 aperta il 10 apr 2026

Vedi su GitHub
 (1 commento) (0 reazioni) (0 assegnatari)Rust (2914 fork)batch import
area:clieffort-mediumenhancementfilter-qualityhelp wantedpriority:medium

Metriche repository

Star
 (48.085 star)
Metriche merge PR
 (Merge medio 11g 1h) (45 PR mergiate in 30 g)

Descrizione

Problem

`rtk grep` applies multiple aggressive filters that can cause AI agents to miss relevant search results:

  1. Max results: Hard-coded limit of 200 results (src/main.rs line 286: default_value = "200")
  2. Max line length: Lines truncated to 80 characters (line 283: default_value = "80")
  3. Context stripping: context_only mode strips surrounding context
  4. Grouping: Results grouped by file, which may hide the specific match context

Impact on AI agents

When an agent searches for a specific pattern (e.g., an error message, a function call, a config value), the 80-character line truncation may cut off the relevant part of the match. The 200-result limit may exclude the file the agent is looking for if there are many matches.

Proposed fix

  1. Increase defaults for AI agent contexts: When the hook is active (detected via environment or config), use higher limits:

    • max_len: 200 (instead of 80)
    • max: 500 (instead of 200)
  2. Add a --full flag: Show unfiltered grep output for when agents need complete results

  3. Smart truncation: Instead of fixed 80 chars, truncate at the match boundary (keep the full match plus 20 chars of context on each side)

Relevant code

  • src/main.rs lines 276-300: Grep command definition with default values
  • src/cmds/system/grep_cmd.rs: grep filtering implementation

Guida contributor