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

Function ripGrepRaw

src/utils/ripgrep.ts:100–224  ·  view source on GitHub ↗
(
  args: string[],
  target: string,
  abortSignal: AbortSignal,
  callback: (
    error: ExecFileException | null,
    stdout: string,
    stderr: string,
  ) => void,
  singleThread = false,
)

Source from the content-addressed store, hash-verified

98}
99
100function ripGrepRaw(
101 args: string[],
102 target: string,
103 abortSignal: AbortSignal,
104 callback: (
105 error: ExecFileException | null,
106 stdout: string,
107 stderr: string,
108 ) => void,
109 singleThread = false,
110): ChildProcess {
111 // NB: When running interactively, ripgrep does not require a path as its last
112 // argument, but when run non-interactively, it will hang unless a path or file
113 // pattern is provided
114
115 const { rgPath, rgArgs, argv0 } = ripgrepCommand()
116
117 // Use single-threaded mode only if explicitly requested for this call's retry
118 const threadArgs = singleThread ? ['-j', '1'] : []
119 const fullArgs = [...rgArgs, ...threadArgs, ...args, target]
120 // Allow timeout to be configured via env var (in seconds), otherwise use platform defaults
121 // WSL has severe performance penalty for file reads (3-5x slower on WSL2)
122 const defaultTimeout = getPlatform() === 'wsl' ? 60_000 : 20_000
123 const parsedSeconds =
124 parseInt(process.env.CLAUDE_CODE_GLOB_TIMEOUT_SECONDS || '', 10) || 0
125 const timeout = parsedSeconds > 0 ? parsedSeconds * 1000 : defaultTimeout
126
127 // For embedded ripgrep, use spawn with argv0 (execFile doesn't support argv0 properly)
128 if (argv0) {
129 const child = spawn(rgPath, fullArgs, {
130 argv0,
131 signal: abortSignal,
132 // Prevent visible console window on Windows (no-op on other platforms)
133 windowsHide: true,
134 })
135
136 let stdout = ''
137 let stderr = ''
138 let stdoutTruncated = false
139 let stderrTruncated = false
140
141 child.stdout?.on('data', (data: Buffer) => {
142 if (!stdoutTruncated) {
143 stdout += data.toString()
144 if (stdout.length > MAX_BUFFER_SIZE) {
145 stdout = stdout.slice(0, MAX_BUFFER_SIZE)
146 stdoutTruncated = true
147 }
148 }
149 })
150
151 child.stderr?.on('data', (data: Buffer) => {
152 if (!stderrTruncated) {
153 stderr += data.toString()
154 if (stderr.length > MAX_BUFFER_SIZE) {
155 stderr = stderr.slice(0, MAX_BUFFER_SIZE)
156 stderrTruncated = true
157 }

Callers 2

handleResultFunction · 0.85
ripGrepFunction · 0.85

Calls 5

ripgrepCommandFunction · 0.85
getPlatformFunction · 0.85
spawnFunction · 0.85
toStringMethod · 0.65
killMethod · 0.45

Tested by

no test coverage detected