MCPcopy Create free account
hub / github.com/Noumena-Network/code / ripGrep

Function ripGrep

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

Source from the content-addressed store, hash-verified

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

Callers 6

callFunction · 0.85
loadMarkdownFilesFunction · 0.85
ripgrep.test.tsFile · 0.85
globFunction · 0.85

Calls 4

ripGrepRawFunction · 0.85
handleResultFunction · 0.85
logErrorFunction · 0.70

Tested by

no test coverage detected