From f22aa72c62c79aa99c9ea3da9c0464b0a6670678 Mon Sep 17 00:00:00 2001 From: gsehgal Date: Sun, 19 Oct 2025 03:08:01 +0000 Subject: [PATCH] Making shell:true as default and adding -I to grep (#11448) Co-authored-by: Tommaso Sciortino --- packages/core/src/tools/grep.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/packages/core/src/tools/grep.ts b/packages/core/src/tools/grep.ts index 679e920d6a..3492cc15c6 100644 --- a/packages/core/src/tools/grep.ts +++ b/packages/core/src/tools/grep.ts @@ -18,6 +18,7 @@ import { isGitRepository } from '../utils/gitUtils.js'; import type { Config } from '../config/config.js'; import type { FileExclusions } from '../utils/ignorePatterns.js'; import { ToolErrorType } from './tool-error.js'; +import { debugLogger } from '../utils/debugLogger.js'; // --- Interfaces --- @@ -219,10 +220,16 @@ class GrepToolInvocation extends BaseToolInvocation< try { const child = spawn(checkCommand, checkArgs, { stdio: 'ignore', - shell: process.platform === 'win32', + shell: true, }); child.on('close', (code) => resolve(code === 0)); - child.on('error', () => resolve(false)); + child.on('error', (err) => { + debugLogger.debug( + `[GrepTool] Failed to start process for '${command}':`, + err.message, + ); + resolve(false); + }); } catch { resolve(false); } @@ -385,10 +392,14 @@ class GrepToolInvocation extends BaseToolInvocation< } // --- Strategy 2: System grep --- + console.debug( + 'GrepLogic: System grep is being considered as fallback strategy.', + ); + const grepAvailable = await this.isCommandAvailable('grep'); if (grepAvailable) { strategyUsed = 'system grep'; - const grepArgs = ['-r', '-n', '-H', '-E']; + const grepArgs = ['-r', '-n', '-H', '-E', '-I']; // Extract directory names from exclusion patterns for grep --exclude-dir const globExcludes = this.fileExclusions.getGlobExcludes(); const commonExcludes = globExcludes