From 40e5be35ce24a92a2d71fd8d80653329dabb91b8 Mon Sep 17 00:00:00 2001 From: Wooseong Kim Date: Thu, 6 Aug 2026 17:46:37 +0900 Subject: [PATCH] fix(websearch): run .bat custom scripts via shell on Windows (#190) Node.js v20+ removed the automatic cmd.exe routing for .bat/.cmd files, causing spawn EINVAL for webSearchTool scripts pointing at .bat files. Enable shell on win32 only. (cherry picked from commit 3fe982c5f0a169e07464810e7befeef26d2f90b6) --- packages/core/src/tests/web-search-handler.test.ts | 11 +++++++++++ packages/core/src/tools/web-search-handler.ts | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/packages/core/src/tests/web-search-handler.test.ts b/packages/core/src/tests/web-search-handler.test.ts index 417c6c4c..e1b8876d 100644 --- a/packages/core/src/tests/web-search-handler.test.ts +++ b/packages/core/src/tests/web-search-handler.test.ts @@ -144,6 +144,17 @@ test("WebSearch returns a configuration error when neither a script nor an LLM c ); }); +test("WebSearch executes a configured .bat script on Windows", { skip: process.platform !== "win32" }, async () => { + const workspace = createTempWorkspace(); + const scriptPath = path.join(workspace, "web-search.bat"); + fs.writeFileSync(scriptPath, "@echo off\r\necho query=%1\r\n", "utf8"); + + const result = await handleWebSearchTool({ query: "test" }, createContext(workspace, { webSearchTool: scriptPath })); + + assert.equal(result.ok, true); + assert.match(result.output ?? "", /query=test/); +}); + function createContext( projectRoot: string, options: { diff --git a/packages/core/src/tools/web-search-handler.ts b/packages/core/src/tools/web-search-handler.ts index b3dde69c..79f43441 100644 --- a/packages/core/src/tools/web-search-handler.ts +++ b/packages/core/src/tools/web-search-handler.ts @@ -159,6 +159,10 @@ async function runWebSearchScript( return new Promise((resolve) => { const child = spawn(scriptPath, [query], { cwd: context.projectRoot, + // Node.js v20+ removed the automatic cmd.exe routing for .bat/.cmd + // files on Windows, so custom webSearchTool scripts pointing at .bat + // files need an explicit shell. (#190) + shell: process.platform === "win32", env: { ...process.env, ...configuredEnv }, stdio: ["ignore", "pipe", "pipe"], });