From fbb9330b1c487f666f03b0fbd8a6e2cccb6e9d56 Mon Sep 17 00:00:00 2001 From: Bohdan Triapitsyn Date: Tue, 14 Apr 2026 23:41:53 +0300 Subject: [PATCH] fix: reduce Windows console popups in web backend Prefer graceful process termination before taskkill fallback Force ConPTY for Windows terminal sessions to avoid console flashes Keep git and server process operations running without visible command windows --- packages/web/bin/cli.js | 9 +++++++++ packages/web/server/lib/opencode/lifecycle.js | 9 +++++++++ packages/web/server/lib/terminal/runtime.js | 10 ++++++++-- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/packages/web/bin/cli.js b/packages/web/bin/cli.js index bc9bb830..1c5fc7e5 100755 --- a/packages/web/bin/cli.js +++ b/packages/web/bin/cli.js @@ -1821,6 +1821,15 @@ async function terminateProcessTree(pid, options = {}) { : 3000; if (process.platform === 'win32') { + try { + process.kill(pid); + } catch { + } + + if (await waitForProcessExit(pid, 800)) { + return true; + } + try { spawnSync('taskkill', ['/pid', String(pid), '/t'], { stdio: 'ignore', diff --git a/packages/web/server/lib/opencode/lifecycle.js b/packages/web/server/lib/opencode/lifecycle.js index 20d784cf..9d85d028 100644 --- a/packages/web/server/lib/opencode/lifecycle.js +++ b/packages/web/server/lib/opencode/lifecycle.js @@ -124,6 +124,15 @@ export const createOpenCodeLifecycleRuntime = (deps) => { } if (process.platform === 'win32') { + try { + child.kill(); + } catch { + } + + if (await waitForChildProcessClose(child, 800)) { + return; + } + try { spawnSync('taskkill', ['/pid', String(pid), '/t'], { stdio: 'ignore', diff --git a/packages/web/server/lib/terminal/runtime.js b/packages/web/server/lib/terminal/runtime.js index 2d104b69..2bb38170 100644 --- a/packages/web/server/lib/terminal/runtime.js +++ b/packages/web/server/lib/terminal/runtime.js @@ -130,7 +130,7 @@ export function createTerminalRuntime({ let lastError = null; for (const shell of shellCandidates) { try { - const ptyProcess = pty.spawn(shell, [], { + const ptyOptions = { name: 'xterm-256color', cols: cols || 80, rows: rows || 24, @@ -140,7 +140,13 @@ export function createTerminalRuntime({ TERM: 'xterm-256color', COLORTERM: 'truecolor', }, - }); + }; + + if (process.platform === 'win32') { + ptyOptions.useConpty = true; + } + + const ptyProcess = pty.spawn(shell, [], ptyOptions); return { ptyProcess, shell }; } catch (error) {