diff --git a/packages/core/src/tools/ripGrep.ts b/packages/core/src/tools/ripGrep.ts index b851c2cd..7c8f6314 100644 --- a/packages/core/src/tools/ripGrep.ts +++ b/packages/core/src/tools/ripGrep.ts @@ -8,7 +8,6 @@ import fs from 'node:fs'; import path from 'node:path'; import { EOL } from 'node:os'; import { spawn } from 'node:child_process'; -import { rgPath } from '@lvce-editor/ripgrep'; import type { ToolInvocation, ToolResult } from './tools.js'; import { BaseDeclarativeTool, BaseToolInvocation, Kind } from './tools.js'; import { SchemaValidator } from '../utils/schemaValidator.js'; @@ -18,6 +17,14 @@ import type { Config } from '../config/config.js'; const DEFAULT_TOTAL_MAX_MATCHES = 20000; +/** + * Lazy loads the ripgrep binary path to avoid loading the library until needed + */ +async function getRipgrepPath(): Promise { + const { rgPath } = await import('@lvce-editor/ripgrep'); + return rgPath; +} + /** * Parameters for the GrepTool */ @@ -292,8 +299,9 @@ class GrepToolInvocation extends BaseToolInvocation< rgArgs.push(absolutePath); try { + const ripgrepPath = await getRipgrepPath(); const output = await new Promise((resolve, reject) => { - const child = spawn(rgPath, rgArgs, { + const child = spawn(ripgrepPath, rgArgs, { windowsHide: true, });