MCPcopy
hub / github.com/codeaashu/claude-code / ripGrep

Function ripGrep

src/utils/ripgrep.ts:345–463  ·  view source on GitHub ↗
(
  args: string[],
  target: string,
  abortSignal: AbortSignal,
)

Source from the content-addressed store, hash-verified

343}
344
345export async function ripGrep(
346 args: string[],
347 target: string,
348 abortSignal: AbortSignal,
349): Promise<string[]> {
350 await codesignRipgrepIfNecessary()
351
352 // Test ripgrep on first use and cache the result (fire and forget)
353 void testRipgrepOnFirstUse().catch(error => {
354 logError(error)
355 })
356
357 return new Promise((resolve, reject) => {
358 const handleResult = (
359 error: ExecFileException | null,
360 stdout: string,
361 stderr: string,
362 isRetry: boolean,
363 ): void => {
364 // Success case
365 if (!error) {
366 resolve(
367 stdout
368 .trim()
369 .split('\n')
370 .map(line => line.replace(/\r$/, ''))
371 .filter(Boolean),
372 )
373 return
374 }
375
376 // Exit code 1 is normal "no matches"
377 if (error.code === 1) {
378 resolve([])
379 return
380 }
381
382 // Critical errors that indicate ripgrep is broken, not "no matches"
383 // These should be surfaced to the user rather than silently returning empty results
384 const CRITICAL_ERROR_CODES = ['ENOENT', 'EACCES', 'EPERM']
385 if (CRITICAL_ERROR_CODES.includes(error.code as string)) {
386 reject(error)
387 return
388 }
389
390 // If we hit EAGAIN and haven't retried yet, retry with single-threaded mode
391 // Note: We only use -j 1 for this specific retry, not for future calls.
392 // Persisting single-threaded mode globally caused timeouts on large repos
393 // where EAGAIN was just a transient startup error.
394 if (!isRetry && isEagainError(stderr)) {
395 logForDebugging(
396 `rg EAGAIN error detected, retrying with single-threaded mode (-j 1)`,
397 )
398 logEvent('tengu_ripgrep_eagain_retry', {})
399 ripGrepRaw(
400 args,
401 target,
402 abortSignal,

Callers 5

callFunction · 0.85
loadMarkdownFilesFunction · 0.85
globFunction · 0.85
getProjectFilesFunction · 0.85

Calls 4

ripGrepRawFunction · 0.85
handleResultFunction · 0.85
logErrorFunction · 0.70

Tested by

no test coverage detected