From 26aea8b69424346af8ec385bcb492b6046254a4b Mon Sep 17 00:00:00 2001 From: danieliyahu1 Date: Thu, 18 Jun 2026 15:25:29 +0300 Subject: [PATCH] fix(process): spawn opencode.exe directly on Windows to prevent visible console window --- src/opencode/process.ts | 31 ++++++++++++++++++++++++++++--- tests/opencode/process.test.ts | 8 +++----- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/src/opencode/process.ts b/src/opencode/process.ts index 4681d8ee..1f192e7a 100644 --- a/src/opencode/process.ts +++ b/src/opencode/process.ts @@ -1,4 +1,6 @@ import { exec, spawn, type ChildProcess } from "node:child_process"; +import { existsSync } from "node:fs"; +import * as path from "node:path"; import { promisify } from "node:util"; const execAsync = promisify(exec); @@ -43,16 +45,39 @@ export function resolveLocalOpencodeTarget(apiUrl: string): LocalOpencodeTarget } } +function resolveWindowsOpencodeExe(): string { + const npmPrefix = path.dirname(process.execPath); + const candidate = path.join( + npmPrefix, + "node_modules", + "opencode-ai", + "bin", + "opencode.exe", + ); + if (existsSync(candidate)) { + return candidate; + } + return "opencode.exe"; +} + export function createOpencodeServeSpawnCommand( target: LocalOpencodeTarget, ): OpencodeServeSpawnCommand { const isWindows = process.platform === "win32"; const port = target.port.toString(); + if (isWindows) { + return { + command: resolveWindowsOpencodeExe(), + args: ["serve", "--port", port], + windowsHide: true, + }; + } + return { - command: isWindows ? "cmd.exe" : "opencode", - args: isWindows ? ["/c", "opencode", "serve", "--port", port] : ["serve", "--port", port], - windowsHide: isWindows, + command: "opencode", + args: ["serve", "--port", port], + windowsHide: false, }; } diff --git a/tests/opencode/process.test.ts b/tests/opencode/process.test.ts index 893b77ea..81a393bd 100644 --- a/tests/opencode/process.test.ts +++ b/tests/opencode/process.test.ts @@ -29,11 +29,9 @@ describe("opencode/process", () => { const command = createOpencodeServeSpawnCommand({ host: "localhost", port: 4987 }); if (process.platform === "win32") { - expect(command).toEqual({ - command: "cmd.exe", - args: ["/c", "opencode", "serve", "--port", "4987"], - windowsHide: true, - }); + expect(command.windowsHide).toBe(true); + expect(command.command).not.toBe("cmd.exe"); + expect(command.args).toEqual(["serve", "--port", "4987"]); return; }