rtk-ai/rtk

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

Open

#1,161 opened on 2026年4月10日

GitHub で見る
 (1 comment) (0 reactions) (0 assignees)Rust (2,914 forks)batch import
area:clieffort-mediumenhancementfilter-qualityhelp wantedpriority:medium

Repository metrics

Stars
 (48,085 stars)
PR merge metrics
 (平均マージ 11d 1h) (30d で 45 merged PRs)

説明

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

コントリビューターガイド