Skip to content

refactor(agent-core): use ripgrep for Glob tool#1068

Open
7Sageer wants to merge 3 commits into
mainfrom
refactor/glob-rg
Open

refactor(agent-core): use ripgrep for Glob tool#1068
7Sageer wants to merge 3 commits into
mainfrom
refactor/glob-rg

Conversation

@7Sageer

@7Sageer 7Sageer commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator

Related Issue

No related issue — this closes a robustness and consistency gap in the Glob tool.

Problem

The Glob tool previously relied on a hand-rolled directory walker that silently swallowed filesystem errors (missing or unreadable directories), so "no matches" and "the walk failed" were indistinguishable. It also did not respect .gitignore, listed directories mixed with files, and duplicated concerns that the Grep tool already handled well through ripgrep.

What changed

  • Glob now runs through ripgrep, sharing the same subprocess plumbing, timeout / abort handling, and sensitive-file filtering as Grep (factored into a shared helper).
  • It respects .gitignore by default and adds an include_ignored option to surface ignored files.
  • Brace patterns (*.{ts,tsx}) are now handled natively by ripgrep.
  • Results are files only (directories are no longer listed).
  • The search root is validated so a missing path reports "does not exist" and a file reports "is not a directory".
  • Grep's ripgrep invocation was moved into the shared helper with no behavior change.
  • The lower-level file-listing primitive is left unchanged.

Reviewer notes

  • This PR keeps the existing Grep ripgrep execution model: rg is resolved locally and executed through the current Kaos. Remote/SSH Kaos behavior is intentionally aligned with Grep and is not changed by this PR.
  • The line count is roughly neutral because the change is not a simple kaos.glob()rg --files substitution. The old brace expansion code is removed, but Glob now explicitly handles ripgrep root validation, timeout/abort/truncation, sensitive-file post-filtering, path relativization, and traversal warnings. The shared ripgrep subprocess plumbing was also moved from Grep into run-rg.ts.
  • Symlink directories are intentionally not followed by ripgrep. This is treated as the new Glob behavior rather than a regression.
  • VCS exclude globs currently follow ripgrep's glob ordering semantics, so broad positive patterns may still surface VCS metadata. This is treated as by design for this PR and consistent with the current ripgrep-based approach.
  • The 100-match cap is an output cap, not a traversal cap. Because Glob uses ripgrep's mtime sorting, ripgrep still enumerates and sorts the full result set before the cap is applied. This matches the current tradeoff and is not addressed here.
  • include_dirs is kept only as a deprecated, ignored parameter so older calls are not rejected by schema validation.
  • The new behavior change in this PR is that unreadable subdirectories no longer fail the whole Glob call when ripgrep already produced complete paths; the tool returns those paths with a warning instead.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

@changeset-bot

changeset-bot Bot commented Jun 24, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a1db703

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@moonshot-ai/agent-core Patch
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Jun 24, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@a1db703
npx https://pkg.pr.new/@moonshot-ai/kimi-code@a1db703

commit: a1db703

Glob now shares Grep's ripgrep subprocess plumbing: it respects .gitignore by default, supports brace patterns natively, adds an include_ignored option, and returns only files.
@7Sageer 7Sageer force-pushed the refactor/glob-rg branch from b8c6f0d to 2e42894 Compare June 24, 2026 09:48
7Sageer added 2 commits June 24, 2026 20:28
- Run rg with cwd pinned to the search root so glob patterns containing
  a slash (e.g. src/**/*.ts) match under an absolute search root.
- Keep include_dirs as a deprecated, ignored parameter so older calls
  are not rejected by parameter validation.
- Surface stdout truncation and drop half-written trailing paths when
  the rg output buffer is capped.
- Document that a bare pattern (e.g. *.ts) matches recursively, and sync
  user docs, the explore profile prompt, and the TUI summary to the new
  files-only / gitignore behavior.
- Add real-ripgrep integration tests covering sort order, recursion,
  brace patterns, and the absolute-search-root case.
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.

2 participants