@@ -6,6 +6,7 @@ import { formatCodeSearchOutput } from '../../../common/src/util/format-code-sea
66import { getBundledRgPath } from '../native/ripgrep'
77
88import type { CodebuffToolOutput } from '../../../common/src/tools/list'
9+ import { Logger } from '@codebuff/common/types/contracts/logger'
910
1011// Hidden directories to include in code search by default.
1112// These are searched in addition to '.' to ensure important config/workflow files are discoverable.
@@ -27,6 +28,7 @@ export function codeSearch({
2728 globalMaxResults = 250 ,
2829 maxOutputStringLength = 20_000 ,
2930 timeoutSeconds = 10 ,
31+ logger,
3032} : {
3133 projectPath : string
3234 pattern : string
@@ -36,6 +38,7 @@ export function codeSearch({
3638 globalMaxResults ?: number
3739 maxOutputStringLength ?: number
3840 timeoutSeconds ?: number
41+ logger ?: Logger
3942} ) : Promise < CodebuffToolOutput < 'code_search' > > {
4043 return new Promise ( ( resolve ) => {
4144 let isResolved = false
@@ -61,7 +64,12 @@ export function codeSearch({
6164
6265 // Parse flags - do NOT deduplicate to preserve flag-argument pairs like '-g *.ts'
6366 // Deduplicating would break up these pairs and cause errors
64- const flagsArray = ( flags || '' ) . split ( ' ' ) . filter ( Boolean )
67+ // Strip surrounding quotes from each token since spawn() passes args directly
68+ // without shell interpretation (e.g. "'foo.md'" → "foo.md")
69+ const flagsArray = ( flags || '' )
70+ . split ( ' ' )
71+ . filter ( Boolean )
72+ . map ( ( token ) => token . replace ( / ^ [ ' " ] | [ ' " ] $ / g, '' ) )
6573
6674 // Use JSON output for robust parsing and early stopping
6775 // --no-config prevents user/system .ripgreprc from interfering
@@ -89,6 +97,9 @@ export function codeSearch({
8997 ]
9098
9199 const rgPath = getBundledRgPath ( import . meta. url )
100+ if ( logger ) {
101+ logger . info ( { rgPath, args, searchCwd } , 'code-search: Spawning ripgrep process' )
102+ }
92103 const childProcess = spawn ( rgPath , args , {
93104 cwd : searchCwd ,
94105 stdio : [ 'ignore' , 'pipe' , 'pipe' ] ,
@@ -129,15 +140,15 @@ export function codeSearch({
129140 const hardKill = ( ) => {
130141 try {
131142 childProcess . kill ( 'SIGTERM' )
132- } catch { }
143+ } catch { }
133144 // Store timeout reference so it can be cleared if process closes normally
134145 killTimeoutId = setTimeout ( ( ) => {
135146 try {
136147 childProcess . kill ( 'SIGKILL' )
137148 } catch {
138149 try {
139150 childProcess . kill ( )
140- } catch { }
151+ } catch { }
141152 }
142153 killTimeoutId = null
143154 } , 1000 )
@@ -247,7 +258,7 @@ export function codeSearch({
247258 const finalOutput =
248259 formattedOutput . length > maxOutputStringLength
249260 ? formattedOutput . substring ( 0 , maxOutputStringLength ) +
250- '\n\n[Output truncated]'
261+ '\n\n[Output truncated]'
251262 : formattedOutput
252263
253264 const limitReason =
@@ -324,10 +335,10 @@ export function codeSearch({
324335 }
325336 }
326337 }
327- } catch { }
338+ } catch { }
328339 }
329340 }
330- } catch { }
341+ } catch { }
331342
332343 // Build final output from collected matches
333344 const limitedLines : string [ ] = [ ]
@@ -369,14 +380,14 @@ export function codeSearch({
369380 const truncatedStdout =
370381 formattedOutput . length > maxOutputStringLength
371382 ? formattedOutput . substring ( 0 , maxOutputStringLength ) +
372- '\n\n[Output truncated]'
383+ '\n\n[Output truncated]'
373384 : formattedOutput
374385
375386 const truncatedStderr = stderrBuf
376387 ? stderrBuf +
377- ( stderrBuf . length >= Math . floor ( maxOutputStringLength / 5 )
378- ? '\n\n[Error output truncated]'
379- : '' )
388+ ( stderrBuf . length >= Math . floor ( maxOutputStringLength / 5 )
389+ ? '\n\n[Error output truncated]'
390+ : '' )
380391 : ''
381392
382393 settle ( {
0 commit comments