Skip to content

find_in_file: no regex / anchor / multiline support, only literal match #1930

Description

@Widthdom

Summary

find_in_file (DbReader.FilesStatus.cs:~10, exposed via the MCP tool of the same name and the CLI command) is documented as searching for a "pattern" but actually accepts only literal substrings — internally IndexOf with StringComparison. Users who pass regex anchors (^foo, bar$), word boundaries (\bfoo\b), or multiline patterns get silent zero-result responses without any diagnostic that the input was treated as a literal string. AI agents in particular will repeatedly try regex variants and never see an error explaining why nothing matched.

Where

Suggested approach

(1) Document explicitly in the tool description and --help: "literal substring match; regex is not supported." (2) Add an opt-in regex=true parameter to both the CLI and MCP tool; implement with Regex compiled lazily and a configurable timeout (default 500 ms) to prevent ReDoS. (3) When regex=true and the pattern fails to compile, return a structured error with the compilation message and the offending sub-expression. (4) When regex=false but the query contains regex-suspicious characters (^, $, [, \b), emit a one-line hint to stderr suggesting regex=true. (5) Add regression tests covering literal-match (current), valid regex, invalid regex, regex with ReDoS-prone backtracking. (6) Cross-link with #1593, #1414, #1597.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions