rtk-ai/rtk

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

Open

#1,161 创建于 2026年4月10日

在 GitHub 查看
 (1 评论) (0 反应) (0 负责人)Rust (2,914 fork)batch import
area:clieffort-mediumenhancementfilter-qualityhelp wantedpriority:medium

仓库指标

Star
 (48,085 star)
PR 合并指标
 (平均合并 11天 1小时) (30 天内合并 45 个 PR)

描述

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

贡献者指南