Skip to content

fix(tools): match path includes against relative paths - #6680

Draft
BlueX888 wants to merge 1 commit into
OpenHands:mainfrom
BlueX888:fix/grep-path-includes
Draft

BlueX888 wants to merge 1 commit into
OpenHands:mainfrom
BlueX888:fix/grep-path-includes

Conversation

@BlueX888

@BlueX888 BlueX888 commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

HUMAN:


AGENT:

Why

GrepAction.include ignored any pattern with a directory component. _path_matches_filters() compared the include glob only against Path.name, so sub/*.ts, **/*.ts, and sub/**/*.ts never matched even though ripgrep's own -g did. VascoSch92 closed the earlier #6325 after the brace-expansion part landed on main and explicitly asked for a smaller PR covering these path patterns.

Summary

  • Match include patterns against the path relative to the search root when the pattern contains /; basename-only patterns keep the existing recursive basename behavior. The ripgrep backend only uses -g for basename patterns, since rg matches -g against the absolute printed path.
  • Implement ** as spanning any number of directories, so **/*.ts includes root-level files and sub/**/*.ts covers the subtree; trailing /** matches contents below the prefix.
  • Add one parameterized regression test covering sub/*.ts, **/*.ts, sub/**/*.ts, *.ts, and */a.ts across the ripgrep, grep, and Python backends.

Issue Number

Part of #6348

How to Test

uv run pytest tests/tools/grep -q

With ripgrep on PATH: 78 passed. Without ripgrep: 54 passed, 24 skipped (the ripgrep-parametrized cases skip). Run rg --version first if you want the full backend matrix. Reverting only impl.py while keeping the new test makes the grep/Python path cases fail with empty match sets; the ripgrep cases were also verified with a real rg binary. uv run pre-commit run --files openhands-tools/openhands/tools/grep/impl.py tests/tools/grep/test_grep_executor.py passes.

Video/Screenshots

N/A (behavior covered by the parameterized test output above).

Design Doc

N/A.

Type

  • Bug fix
  • Feature
  • Refactor
  • Breaking change
  • Docs / chore

Notes

  • The include contract is unchanged for existing callers: patterns without / still match the basename anywhere, and brace expansion is still applied first.
  • Path-bearing includes no longer use ripgrep -g as a prefilter; ripgrep scans and the Python filter narrows the result. That is a small performance trade-off on very large trees, kept for correctness and simplicity.
  • Hidden root dotfiles have a small backend difference for path patterns such as ./*.ts; basename patterns are consistent. This was already broken for path patterns before the patch.
  • Windows backslash path patterns (sub\\*.ts) remain unsupported; patterns use /. This is not a regression.
  • The ripgrep branch was verified locally with a real ripgrep 14.1.1 binary via a PATH shim; the hosted CI image may or may not preinstall rg.

The grep include filter compared only the basename, so sub/*.ts and
**/*.ts never matched. Match relative path segments with ** support,
keeping basename-only patterns recursive.

Co-authored-by: openhands <openhands@all-hands.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant