From 5ecb4a24305a97389abe4429d9ecd4f42b9e301f Mon Sep 17 00:00:00 2001 From: tanzhenxin Date: Tue, 23 Sep 2025 14:44:48 +0800 Subject: [PATCH] fix: make ripgrep lazy load, to fix vscode ide companion unable to start (#676) --- packages/core/src/tools/ripGrep.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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, });