fix(adapter-utils): use cmd.exe for .cmd/.bat wrappers on Windows

Avoid relying on ComSpec for .cmd/.bat invocation in runChildProcess. Some Win11 environments set ComSpec to PowerShell, which breaks cmd-specific flags (/d /s /c) and causes adapter CLI discovery failures (e.g. opencode models).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Timo Götzken 2026-04-01 09:25:39 +02:00
parent 5b479652f2
commit b642d3e06b

View file

@ -306,6 +306,12 @@ function quoteForCmd(arg: string) {
return /[\s"&<>|^()]/.test(escaped) ? `"${escaped}"` : escaped;
}
function resolveWindowsCmdShell(env: NodeJS.ProcessEnv): string {
const fallbackRoot = env.SystemRoot || process.env.SystemRoot || "C:\\Windows";
const candidate = path.join(fallbackRoot, "System32", "cmd.exe");
return candidate;
}
async function resolveSpawnTarget(
command: string,
args: string[],
@ -320,7 +326,9 @@ async function resolveSpawnTarget(
}
if (/\.(cmd|bat)$/i.test(executable)) {
const shell = env.ComSpec || process.env.ComSpec || "cmd.exe";
// Always use cmd.exe for .cmd/.bat wrappers. Some environments override
// ComSpec to PowerShell, which breaks cmd-specific flags like /d /s /c.
const shell = resolveWindowsCmdShell(env);
const commandLine = [quoteForCmd(executable), ...args.map(quoteForCmd)].join(" ");
return {
command: shell,