From 41d1cb6462a02f459904964cd29a773421834fb4 Mon Sep 17 00:00:00 2001 From: Nandana Dileep Date: Tue, 28 Apr 2026 14:57:39 +0530 Subject: [PATCH] fix: import getMaxToolUseConcurrency into local scope and add ripgrep fallback (#8) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit toolOrchestration.ts used `export { getMaxToolUseConcurrency } from './toolConcurrency.js'` (a re-export) but then called the function directly in runToolsConcurrently(). A re-export does not bring the name into the module's own scope, causing a ReferenceError at runtime — visible as "getMaxToolUseConcurrency is not defined" in --print mode. TypeScript also flagged this as TS2304 on main. Fix: replace the re-export with an explicit import + a separate export statement so the name is both locally callable and publicly exported. ripgrep.ts fell through to the vendor binary path on non-bundled (npm) installs where the vendor/ directory is not shipped alongside dist/cli.mjs, producing "spawn .../vendor/ripgrep/x64-linux/rg ENOENT". Fix: check whether the vendor binary exists before returning the builtin config; fall back to system rg if it is absent. --- src/services/tools/toolOrchestration.ts | 3 ++- src/utils/ripgrep.ts | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/services/tools/toolOrchestration.ts b/src/services/tools/toolOrchestration.ts index d82010ce..2416dcbb 100644 --- a/src/services/tools/toolOrchestration.ts +++ b/src/services/tools/toolOrchestration.ts @@ -4,10 +4,11 @@ import { findToolByName, type ToolUseContext } from '../../Tool.js' import type { AssistantMessage, Message } from '../../types/message.js' import { all } from '../../utils/generators.js' import { type MessageUpdateLazy, runToolUse } from './toolExecution.js' -export { +import { DEFAULT_MAX_TOOL_USE_CONCURRENCY, getMaxToolUseConcurrency, } from './toolConcurrency.js' +export { DEFAULT_MAX_TOOL_USE_CONCURRENCY, getMaxToolUseConcurrency } export type MessageUpdate = { message?: Message diff --git a/src/utils/ripgrep.ts b/src/utils/ripgrep.ts index 683da051..0697688a 100644 --- a/src/utils/ripgrep.ts +++ b/src/utils/ripgrep.ts @@ -1,5 +1,6 @@ import type { ChildProcess, ExecFileException } from 'child_process' import { execFile, spawn } from 'child_process' +import { existsSync } from 'fs' import memoize from 'lodash-es/memoize.js' import { homedir } from 'os' import * as path from 'path' @@ -61,6 +62,12 @@ const getRipgrepConfig = memoize((): RipgrepConfig => { ? path.resolve(rgRoot, `${process.arch}-win32`, 'rg.exe') : path.resolve(rgRoot, `${process.arch}-${process.platform}`, 'rg') + // Fall back to system rg when the vendor binary is absent (e.g. npm installs + // that don't ship the vendor/ directory alongside dist/cli.mjs). + if (!existsSync(command)) { + return { mode: 'system', command: 'rg', args: [] } + } + return { mode: 'builtin', command, args: [] } })