Skip to content

[Feature] Add file_pattern Parameter to exact_search and Fix limit Semantics / 为 exact_search 增加 file_pattern 参数并修复 limit 语义 #134

@SunYanbox

Description

@SunYanbox

Currently, exact_search lacks a file_pattern parameter and hardcodes rglob("*") (exact_search_tool.py:119). We should add this parameter to allow users to filter which files are searched (e.g., "*.py", "*.md"), matching the behavior of regex_search. This prevents wasted time scanning binary files like .pyc or images.
当前 exact_search 没有 file_pattern 参数,硬编码为 rglob("*")exact_search_tool.py:119)。我们计划添加该参数,允许用户过滤要搜索的文件(例如 "*.py""*.md"),与 regex_search 的行为保持一致。这可以避免浪费时间扫描 .pyc 或图片等二进制文件。

The limit parameter currently stops after scanning a fixed number of files rather than after finding a fixed number of matches (see exact_search_tool.py:126 and regex_search_tool.py:156). We should change the semantics so that limit controls the maximum number of match results returned, not the number of files examined.
当前 limit 参数在扫描固定数量的文件后就停止,而不是在找到固定数量的匹配项后停止(见 exact_search_tool.py:126regex_search_tool.py:156)。我们计划修改语义,使 limit 控制返回的 匹配结果 的最大数量,而不是检查的文件数量。

Proposed changes / 拟修改内容:

  • Add file_pattern: Optional[str] = None parameter to exact_search, defaulting to "*" (all files) for backward compatibility.
    exact_search 添加 file_pattern: Optional[str] = None 参数,默认 "*"(所有文件)以保持向后兼容。
  • Replace the hardcoded rglob("*") with rglob(file_pattern) when pattern is provided.
    当提供 pattern 时,将硬编码的 rglob("*") 替换为 rglob(file_pattern)
  • Change the limit check to accumulate individual match results (not files) and stop once limit matches have been collected.
    修改 limit 检查逻辑,改为累积单个匹配结果(而非文件),一旦收集到 limit 个匹配项即停止。

Additionally, the same limit semantic fix should be applied to regex_search for consistency.
另外,为保持一致性,regex_search 也应应用相同的 limit 语义修复。

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions