From 221ea360b955e0b36d200f44e5bfb3ea53939279 Mon Sep 17 00:00:00 2001 From: Smitty Date: Wed, 18 Feb 2026 17:11:24 -0500 Subject: [PATCH] fix(core): ripgrep fails when pattern looks like ripgrep flag (#18858) Co-authored-by: Tommaso Sciortino --- packages/core/src/tools/ripGrep.test.ts | 14 +++++++++----- packages/core/src/tools/ripGrep.ts | 5 ++--- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/packages/core/src/tools/ripGrep.test.ts b/packages/core/src/tools/ripGrep.test.ts index 114b6b8e11..09f8b5f00c 100644 --- a/packages/core/src/tools/ripGrep.test.ts +++ b/packages/core/src/tools/ripGrep.test.ts @@ -1430,11 +1430,15 @@ describe('RipGrepTool', () => { }); const result = await invocation.execute(abortSignal); - expect(mockSpawn).toHaveBeenLastCalledWith( - expect.anything(), - expect.arrayContaining(['--fixed-strings']), - expect.anything(), - ); + const spawnArgs = mockSpawn.mock.calls[0][1]; + expect(spawnArgs).toContain('--fixed-strings'); + expect(spawnArgs).toContain('--regexp'); + expect(spawnArgs).toContain('hello.world'); + + // Verify --fixed-strings doesn't have the pattern as its next argument + const fixedStringsIdx = spawnArgs.indexOf('--fixed-strings'); + expect(spawnArgs[fixedStringsIdx + 1]).not.toBe('hello.world'); + expect(result.llmContent).toContain( 'Found 1 match for pattern "hello.world"', ); diff --git a/packages/core/src/tools/ripGrep.ts b/packages/core/src/tools/ripGrep.ts index d4478fffee..5fe516c335 100644 --- a/packages/core/src/tools/ripGrep.ts +++ b/packages/core/src/tools/ripGrep.ts @@ -387,11 +387,10 @@ class GrepToolInvocation extends BaseToolInvocation< if (fixed_strings) { rgArgs.push('--fixed-strings'); - rgArgs.push(pattern); - } else { - rgArgs.push('--regexp', pattern); } + rgArgs.push('--regexp', pattern); + if (context) { rgArgs.push('--context', context.toString()); }