Skip to content

Add optional literal search mode to the grep tool #38

Closed

Description

@vicgupta

Problem

The grep tool always treats pattern as a Go regular expression. Searching for ordinary code such as func( fails with a regex error, while strings such as config.json can match unintended text because . is a wildcard. The agent must escape regex metacharacters correctly or fall back to a shell command for a simple literal search.

Proposed improvement

Add an optional boolean fixed_strings argument to grep. When true, treat the entire pattern as literal text, equivalent to grep -F. Keep regex matching as the default.

For example, this should find a literal func( in Go files without requiring regex escaping:

{"pattern":"func(","path":".","include":"*.go","fixed_strings":true}

Acceptance criteria

  • The tool schema exposes fixed_strings as an optional boolean and explains that the default is regex matching. Update the tool and pattern descriptions to make literal mode discoverable.
  • With fixed_strings: true, metacharacters such as ., (, [, *, and backslashes are matched literally. For example, config.json matches that exact substring but not configXjson; func( is a valid literal search.
  • Omitted, false, or null values preserve existing regex behavior, including inline regex flags and invalid-regex errors. Invalid non-boolean values return an actionable tool error using the existing boolArg convention.
  • Literal mode works for both single-file and recursive searches and combines with the existing include glob. Preserve path confinement, skipped directories, binary/large-file exclusions, match limits, file:line: content output, and the no matches response.
  • Add focused tests for literal metacharacters, the default regex behavior, single-file and recursive/include searches, executor argument validation, and the optional boolean schema property. go test ./... passes.
  • Add a brief README note showing a literal search example.

Implementation pointers and scope

The change should fit within internal/tools/grep.go, the argument/schema/dispatch handling in internal/tools/tools.go, existing tests in internal/tools/tools_test.go, and README.md. Quoting the supplied pattern with regexp.QuoteMeta in literal mode would allow reuse of the existing search loop. No new dependency or CLI flag is needed.

This is separate from #36 (ignore_case): that issue changes case sensitivity; this one changes how regex syntax is interpreted. It does not depend on #36 being implemented.

Activity

  1. added
    enhancementNew feature or request
    amf:readyReady for amf to turn into a pull request
    amf:doneamf opened a pull request for this issue
    and removed
    amf:readyReady for amf to turn into a pull request
    on Oct 24, 2026
  2. vicgupta commented on Oct 24, 2026

    @vicgupta
    OwnerAuthor

    amf opened #46 for this issue.

  3. added and removed
    amf:doneamf opened a pull request for this issue
    on Oct 24, 2026
  4. added a commit that references this issue on Oct 24, 2026
    0684628
  5. added
    amf:doneamf opened a pull request for this issue
    and removed on Oct 24, 2026
  6. vicgupta commented on Oct 24, 2026

    @vicgupta
    OwnerAuthor

    amf opened #48 for this issue.

  7. added a commit that references this issue on Oct 24, 2026
    d5062a1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    amf:doneamf opened a pull request for this issueenhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions