Skip to content

Commit 2c053d5

Browse files
author
Ken Lin
committed
fix(plugins): add windowsHide to all child-process spawns
Windows console-flash mitigation: OpenCode v2 serve --service subprocess has no console, so every cmd/c it launches opens a visible window (upstream anomalyco/opencode#31629, closed not-planned). Adds windowsHide: true to all spawn/spawnSync/execSync/execFileSync/Bun.spawn sites under plugins/; ports the one Bun.$ call (browser-screenshot) to Bun.spawn since Bun Shell has no windowsHide option. No-op on POSIX.
1 parent d5a34e4 commit 2c053d5

9 files changed

Lines changed: 28 additions & 18 deletions

File tree

‎plugins/adr/adr-governance.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ function spawnSyncGitDiff(projectDir: string, dirs: string[], staged: boolean):
299299
cwd: projectDir,
300300
encoding: "utf-8",
301301
timeout: 5000,
302+
windowsHide: true,
302303
},
303304
)
304305
if (r.error || r.status !== 0) return null

‎plugins/adr/adr-runtime.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ export function hasAdrChanges(projectDir: string, adrDir: string | string[] = "d
288288
cwd: projectDir,
289289
encoding: "utf-8",
290290
timeout: 5000,
291+
windowsHide: true,
291292
})
292293
if (r.error || r.status !== 0) return true
293294
const stdout = (r.stdout || "").trim()

‎plugins/auto-format.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ async function formatFile(filePath: string, projectRoot: string, echoHashes: Map
124124
if (echoHashes.get(filePath) === before) return
125125

126126
const cmd = formatter.command(filePath)
127-
const process = Bun.spawn(cmd, { stdout: "ignore", stderr: "pipe" })
127+
const process = Bun.spawn(cmd, { stdout: "ignore", stderr: "pipe", windowsHide: true })
128128
if (await process.exited !== 0) {
129129
throw new Error((await new Response(process.stderr).text()).trim() || "formatter exited with an error")
130130
}

‎plugins/browser-screenshot.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,10 @@ async function loadPlaywright(): Promise<any> {
106106
} catch {
107107
// Browser binary missing — download it via `playwright install`
108108
try {
109-
const { exitCode } = await Bun.$`bunx playwright install chromium`.quiet()
109+
// Bun Shell (Bun.$) has no windowsHide option — use Bun.spawn to avoid a
110+
// visible console window on Windows (console-less serve --service, upstream anomalyco/opencode#31629)
111+
const proc = Bun.spawn(["bunx", "playwright", "install", "chromium"], { stdout: "ignore", stderr: "ignore", windowsHide: true })
112+
const exitCode = await proc.exited
110113
if (exitCode !== 0) {
111114
throw new Error("Failed to install Playwright chromium browser")
112115
}

‎plugins/md-to-docx/engine.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ ${logNotice}`
105105

106106
export function checkPandoc(): boolean {
107107
try {
108-
const res = spawnSync("pandoc", ["--version"], { stdio: "ignore" })
108+
const res = spawnSync("pandoc", ["--version"], { stdio: "ignore", windowsHide: true })
109109
return res.status === 0
110110
} catch {
111111
return false
@@ -114,7 +114,7 @@ export function checkPandoc(): boolean {
114114

115115
export function checkNode(): boolean {
116116
try {
117-
const res = spawnSync("node", ["--version"], { stdio: "ignore" })
117+
const res = spawnSync("node", ["--version"], { stdio: "ignore", windowsHide: true })
118118
return res.status === 0
119119
} catch {
120120
return false
@@ -124,7 +124,7 @@ export function checkNode(): boolean {
124124
export function checkChromium(): boolean {
125125
try {
126126
const testCode = "const { chromium } = require('playwright'); chromium.launch({ headless: true }).then(b => b.close());"
127-
const res = spawnSync("node", ["-e", testCode], { stdio: "ignore" })
127+
const res = spawnSync("node", ["-e", testCode], { stdio: "ignore", windowsHide: true })
128128
return res.status === 0
129129
} catch {
130130
return false
@@ -143,7 +143,7 @@ export function autoInstallPandoc(projectDir: string = process.cwd()): { success
143143
const proc = spawnSync(
144144
"winget",
145145
["install", "--id", "JohnMacFarlane.Pandoc", "-e", "--accept-source-agreements", "--accept-package-agreements"],
146-
{ stdio: "pipe", encoding: "utf8", shell: true },
146+
{ stdio: "pipe", encoding: "utf8", shell: true, windowsHide: true },
147147
)
148148
if (proc.status !== 0) {
149149
const logFile = writeErrorLog("autoInstallPandoc", proc.stderr || "winget install failed", proc.stdout + "\n" + proc.stderr, projectDir)
@@ -244,7 +244,7 @@ export async function convertSingleFile(
244244
}
245245

246246
try {
247-
execFileSync("pandoc", pandocArgs, { stdio: "pipe" })
247+
execFileSync("pandoc", pandocArgs, { stdio: "pipe", windowsHide: true })
248248
} catch (err: any) {
249249
const errorMsg = err?.stderr?.toString() || err?.stdout?.toString() || (err as Error).message || "Pandoc conversion failed"
250250
const logFile = writeErrorLog(`Pandoc execution (${resolvedInput})`, errorMsg, "", projectDir)

‎plugins/md-to-pdf/engine.ts‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ ${logNotice}`
116116

117117
export function checkPandoc(): boolean {
118118
try {
119-
const res = spawnSync("pandoc", ["--version"], { stdio: "ignore" })
119+
const res = spawnSync("pandoc", ["--version"], { stdio: "ignore", windowsHide: true })
120120
return res.status === 0
121121
} catch {
122122
return false
@@ -125,7 +125,7 @@ export function checkPandoc(): boolean {
125125

126126
export function checkNode(): boolean {
127127
try {
128-
const res = spawnSync("node", ["--version"], { stdio: "ignore" })
128+
const res = spawnSync("node", ["--version"], { stdio: "ignore", windowsHide: true })
129129
return res.status === 0
130130
} catch {
131131
return false
@@ -135,7 +135,7 @@ export function checkNode(): boolean {
135135
export function checkChromium(): boolean {
136136
try {
137137
const testCode = "const { chromium } = require('playwright'); chromium.launch({ headless: true }).then(b => b.close());"
138-
const res = spawnSync("node", ["-e", testCode], { stdio: "ignore" })
138+
const res = spawnSync("node", ["-e", testCode], { stdio: "ignore", windowsHide: true })
139139
return res.status === 0
140140
} catch {
141141
return false
@@ -172,6 +172,7 @@ export function autoInstallChromium(projectDir: string = process.cwd()): { succe
172172
encoding: "utf8",
173173
shell: true,
174174
env,
175+
windowsHide: true,
175176
})
176177

177178
const output = proc.stdout + "\n" + proc.stderr
@@ -202,7 +203,7 @@ export function autoInstallPandoc(projectDir: string = process.cwd()): { success
202203
const proc = spawnSync(
203204
"winget",
204205
["install", "--id", "JohnMacFarlane.Pandoc", "-e", "--accept-source-agreements", "--accept-package-agreements"],
205-
{ stdio: "pipe", encoding: "utf8", shell: true },
206+
{ stdio: "pipe", encoding: "utf8", shell: true, windowsHide: true },
206207
)
207208
if (proc.status !== 0) {
208209
const logFile = writeErrorLog("autoInstallPandoc", proc.stderr || "winget install failed", proc.stdout + "\n" + proc.stderr, projectDir)
@@ -276,7 +277,7 @@ export function renderMarkdownToHtml(
276277
"-M", "document-css=false",
277278
"-o", htmlAbsPath,
278279
],
279-
{ stdio: "pipe" },
280+
{ stdio: "pipe", windowsHide: true },
280281
)
281282
} catch (err) {
282283
const logFile = writeErrorLog(`renderMarkdownToHtml (${mdAbsPath})`, err as Error, "", projectDir)
@@ -339,6 +340,7 @@ const { chromium } = require('playwright');
339340
stdio: "pipe",
340341
encoding: "utf8",
341342
env,
343+
windowsHide: true,
342344
})
343345
} catch (err: any) {
344346
const stderr = err?.stderr || err?.stdout || (err as Error).message || ""

‎plugins/project-manager/project-manager-dprint.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ function runCommand(command: Command, root: string): Promise<void> {
7575
cwd: root,
7676
shell: process.platform === "win32",
7777
stdio: "ignore",
78+
windowsHide: true,
7879
})
7980
child.once("error", reject)
8081
child.once("exit", (code) => code === 0 ? resolve() : reject(new Error(`${command.command} exited with ${code}`)))

‎plugins/project-manager/project-manager-index.ts‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,15 @@ function mcpEnabled(name: string): boolean {
7373
function codegraphCliInstalled(): boolean {
7474
try {
7575
// `--version` — the CLI has no `version` subcommand (commander rejects it).
76-
execSync("codegraph --version", { encoding: "utf8", timeout: 8000, stdio: ["ignore", "pipe", "ignore"] })
76+
execSync("codegraph --version", { encoding: "utf8", timeout: 8000, stdio: ["ignore", "pipe", "ignore"], windowsHide: true })
7777
return true
7878
} catch { /* not installed or not on PATH */ }
7979
return false
8080
}
8181

8282
function gitnexusCliInstalled(): boolean {
8383
try {
84-
execSync("gitnexus --version", { encoding: "utf8", timeout: 8000, stdio: ["ignore", "pipe", "ignore"] })
84+
execSync("gitnexus --version", { encoding: "utf8", timeout: 8000, stdio: ["ignore", "pipe", "ignore"], windowsHide: true })
8585
return true
8686
} catch { /* not installed or not on PATH */ }
8787
return false
@@ -93,7 +93,7 @@ function gitnexusCliInstalled(): boolean {
9393
function dbhubCliInstalled(): boolean {
9494
const probe = process.platform === "win32" ? "where.exe dbhub" : "command -v dbhub"
9595
try {
96-
execSync(probe, { encoding: "utf8", timeout: 8000, stdio: ["ignore", "pipe", "ignore"] })
96+
execSync(probe, { encoding: "utf8", timeout: 8000, stdio: ["ignore", "pipe", "ignore"], windowsHide: true })
9797
return true
9898
} catch { /* not installed or not on PATH */ }
9999
return false
@@ -106,8 +106,8 @@ function cliInstalled(name: string): boolean {
106106
if (name === "tgrep") {
107107
const probe = process.platform === "win32" ? "where.exe tgrep" : "command -v tgrep"
108108
try {
109-
execSync(probe, { encoding: "utf8", timeout: 8000, stdio: ["ignore", "pipe", "ignore"] })
110-
execSync("tgrep --version", { encoding: "utf8", timeout: 8000, stdio: ["ignore", "pipe", "ignore"] })
109+
execSync(probe, { encoding: "utf8", timeout: 8000, stdio: ["ignore", "pipe", "ignore"], windowsHide: true })
110+
execSync("tgrep --version", { encoding: "utf8", timeout: 8000, stdio: ["ignore", "pipe", "ignore"], windowsHide: true })
111111
return true
112112
} catch { return false }
113113
}
@@ -130,6 +130,7 @@ function gitnexusIndexState(root: string): "ready" | "stale" | "missing" {
130130
const head = execSync("git log -1 --format=%ct", {
131131
cwd: root, encoding: "utf8", timeout: 5000,
132132
stdio: ["ignore", "pipe", "ignore"],
133+
windowsHide: true,
133134
}).trim()
134135
const headSec = parseInt(head, 10)
135136
if (!Number.isNaN(headSec) && headSec * 1000 > indexMtime) return "stale"
@@ -436,7 +437,7 @@ function runBackend(plan: BackendPlan, root: string): Promise<BackendResult> {
436437
}
437438
const [cmd, ...args] = shellwords(plan.command)
438439
return new Promise((resolve) => {
439-
const child = spawn(cmd, args, { cwd: root, shell: true, stdio: ["ignore", "ignore", "pipe"] })
440+
const child = spawn(cmd, args, { cwd: root, shell: true, stdio: ["ignore", "ignore", "pipe"], windowsHide: true })
440441
let stderr = ""
441442
child.stderr.on("data", (d) => (stderr += String(d)))
442443
child.on("error", (e) => resolve({ backend: plan.backend, status: "failed", detail: String(e) }))

‎plugins/shared/mermaid-renderer.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,7 @@ const fs = require('fs');
580580
execFileSync(nodeExecutable, [scriptPath], {
581581
stdio: "pipe",
582582
timeout: 60000,
583+
windowsHide: true,
583584
})
584585

585586
for (const item of renderPayload) {

0 commit comments

Comments
 (0)