MCPcopy Index your code
hub / github.com/TanStack/ai / exec

Method exec

packages/ai-sandbox-local-process/src/handle.ts:304–327  ·  view source on GitHub ↗
(command: string, opts?: ProcessOptions)

Source from the content-addressed store, hash-verified

302 }
303
304 private exec(command: string, opts?: ProcessOptions): Promise<ExecResult> {
305 return new Promise<ExecResult>((resolve, reject) => {
306 // Run via a POSIX `sh` on every platform (see posixShell) so the adapter's
307 // single-quote-quoted commands work identically — including native Windows,
308 // where `shell: true` would be cmd.exe and mangle the quoting.
309 const child = spawn(posixShell(), ['-c', command], {
310 cwd: this.resolveCwd(opts?.cwd),
311 env: this.mergedEnv(opts?.env),
312 })
313 let stdout = ''
314 let stderr = ''
315 child.stdout.on('data', (d: Buffer) => (stdout += d.toString('utf8')))
316 child.stderr.on('data', (d: Buffer) => (stderr += d.toString('utf8')))
317 const onAbort = (): void => {
318 killTree(child)
319 }
320 opts?.signal?.addEventListener('abort', onAbort, { once: true })
321 child.on('error', reject)
322 child.on('close', (code) => {
323 opts?.signal?.removeEventListener('abort', onAbort)
324 resolve({ stdout, stderr, exitCode: code ?? 0 })
325 })
326 })
327 }
328
329 private spawnProcess(
330 command: string,

Callers 1

constructorMethod · 0.95

Calls 5

resolveCwdMethod · 0.95
mergedEnvMethod · 0.95
posixShellFunction · 0.85
toStringMethod · 0.80
addEventListenerMethod · 0.45

Tested by

no test coverage detected