Fix qwen_delegate: quote args for shell:true on Windows

Node's shell:true does NOT escape array args on Windows (DEP0190) — it
just space-joins them, so any multi-word prompt silently split into
extra positional args and collided with qwen's -p flag ("Cannot use
both a positional prompt and the --prompt (-p) flag together"). Never
caught before because the tool was only smoke-tested via tools/list,
not an actual invocation.

Build the command as a single explicitly-quoted string instead. Verified
against real qwen-code CLI arg parsing; existing mocked tests still pass.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CRnb5Gqdu7gVTQrwAqFdfJ
This commit is contained in:
2026-09-06 18:21:33 +02:00
co-authored by Claude-Bot
parent 061a1f381d
commit 5cd0453162
+9 -2
View File
@@ -32,8 +32,15 @@ export function delegateToQwen (
const { timeoutMs = DEFAULT_TIMEOUT_MS, spawnFn = spawn } = options; const { timeoutMs = DEFAULT_TIMEOUT_MS, spawnFn = spawn } = options;
return new Promise((resolve) => { return new Promise((resolve) => {
const child: ChildProcess = spawnFn("qwen", ["-p", prompt], { // shell:true is required for qwen.cmd to resolve on Windows, but Node does NOT escape
shell: true, // qwen.cmd on Windows needs a shell to resolve // array args in that mode (see DEP0190) — it just space-joins them, so an unquoted
// multi-word prompt silently splits into extra positional args and confuses qwen's CLI
// parser ("Cannot use both a positional prompt and the --prompt (-p) flag together").
// Build the command as a single, explicitly-quoted string instead.
const quoteArg = (s: string) => `"${s.replace(/"/g, '\\"')}"`;
const command = ["qwen", "-p", quoteArg(prompt)].join(" ");
const child: ChildProcess = spawnFn(command, {
shell: true,
stdio: ["ignore", "pipe", "pipe"], stdio: ["ignore", "pipe", "pipe"],
}); });