-
Notifications
You must be signed in to change notification settings - Fork 3.7k
feat(cli): add grep/find/findstr as alternative search strategy #8616
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 issue found across 1 file
Prompt for AI agents (all 1 issues)
Understand the root cause of the following 1 issues and fix them.
<file name="extensions/cli/src/tools/searchCode.ts">
<violation number="1" location="extensions/cli/src/tools/searchCode.ts:75">
The fallback search uses `find -name` with the provided file pattern, but `-name` only matches the basename, so patterns with directories like `src/**/*.ts` stop working when falling back from ripgrep. Please switch to a path-aware match (e.g. `find … -path …`) to keep file filters consistent regardless of backend.</violation>
</file>
React with 👍 or 👎 to teach cubic. Mention @cubic-dev-ai to give feedback, ask questions, or re-run the review.
| excludeArgs += ` --exclude="${ignorePattern}" --exclude-dir="${ignorePattern}"`; // use both exclude and exclude-dir because ignorePattern can be a file or directory | ||
| } | ||
| if (filePattern) { | ||
| command = `find . -type f -name "${filePattern}" -print0 | xargs -0 grep -nH -I${excludeArgs} "${pattern}"`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fallback search uses find -name with the provided file pattern, but -name only matches the basename, so patterns with directories like src/**/*.ts stop working when falling back from ripgrep. Please switch to a path-aware match (e.g. find … -path …) to keep file filters consistent regardless of backend.
Prompt for AI agents
Address the following comment on extensions/cli/src/tools/searchCode.ts at line 75:
<comment>The fallback search uses `find -name` with the provided file pattern, but `-name` only matches the basename, so patterns with directories like `src/**/*.ts` stop working when falling back from ripgrep. Please switch to a path-aware match (e.g. `find … -path …`) to keep file filters consistent regardless of backend.</comment>
<file context>
@@ -3,11 +3,83 @@ import * as fs from "fs";
+ excludeArgs += ` --exclude="${ignorePattern}" --exclude-dir="${ignorePattern}"`; // use both exclude and exclude-dir because ignorePattern can be a file or directory
+ }
+ if (filePattern) {
+ command = `find . -type f -name "${filePattern}" -print0 | xargs -0 grep -nH -I${excludeArgs} "${pattern}"`;
+ } else {
+ command = `grep -R -n -H -I${excludeArgs} "${pattern}" .`;
</file context>
| command = `find . -type f -name "${filePattern}" -print0 | xargs -0 grep -nH -I${excludeArgs} "${pattern}"`; | |
| command = `find . -type f -path "./${filePattern}" -print0 | xargs -0 grep -nH -I${excludeArgs} "${pattern}"`; |
Description
Search tool on cn relies on ripgrep for searching inside files which is often not present in the running system. This leads to the model using alternative approaches which might skip search for files altogether. This PR adds grep/find utility for linux and findstr for windows.
AI Code Review
@continue-reviewChecklist
Screen recording or screenshot
before
after
Tests
[ What tests were added or updated to ensure the changes work as expected? ]
Summary by cubic
Add a cross-platform fallback for CLI code search: use grep/find on Unix and findstr on Windows when ripgrep isn’t available. Improves reliability on systems without ripgrep and applies .gitignore excludes where supported.
Written for commit 9ba56ff. Summary will update automatically on new commits.