Skip to content

Conversation

@uinstinct
Copy link
Contributor

@uinstinct uinstinct commented Nov 6, 2025

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

  • Team members only: AI review runs automatically when PR is opened or marked ready for review
  • Team members can also trigger a review by commenting @continue-review

Checklist

  • [] I've read the contributing guide
  • [] The relevant docs, if any, have been updated or created
  • [] The relevant tests, if any, have been updated or created

Screen recording or screenshot

before

image

after

image

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.

  • New Features
    • Automatically falls back to grep (Unix) or findstr (Windows) if ripgrep is missing.
    • Parses .gitignore and excludes matching files/dirs with ripgrep and grep.
    • Keeps file_pattern filtering for targeted searches.
    • Updates messages to surface warnings and use a unified “Error executing search” on failure.

Written for commit 9ba56ff. Summary will update automatically on new commits.

@uinstinct uinstinct requested a review from a team as a code owner November 6, 2025 14:16
@uinstinct uinstinct requested review from sestinj and removed request for a team November 6, 2025 14:16
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Nov 6, 2025
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a 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}"`;
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Nov 6, 2025

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 &quot;fs&quot;;
+      excludeArgs += ` --exclude=&quot;${ignorePattern}&quot; --exclude-dir=&quot;${ignorePattern}&quot;`; // use both exclude and exclude-dir because ignorePattern can be a file or directory
+    }
+    if (filePattern) {
+      command = `find . -type f -name &quot;${filePattern}&quot; -print0 | xargs -0 grep -nH -I${excludeArgs} &quot;${pattern}&quot;`;
+    } else {
+      command = `grep -R -n -H -I${excludeArgs} &quot;${pattern}&quot; .`;
</file context>
Suggested change
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}"`;
Fix with Cubic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

1 participant