diff --git a/lib/adapter-sdk/src/server-utils.ts b/lib/adapter-sdk/src/server-utils.ts index 13dc887f..4f9f1eca 100644 --- a/lib/adapter-sdk/src/server-utils.ts +++ b/lib/adapter-sdk/src/server-utils.ts @@ -180,7 +180,8 @@ export async function ensureCommandResolvable(command: string, cwd: string, env: return; } - const pathValue = env.PATH ?? env.Path ?? ""; + const pathValue = + env.PATH ?? env.Path ?? process.env.PATH ?? process.env.Path ?? ""; const delimiter = process.platform === "win32" ? ";" : ":"; const dirs = pathValue.split(delimiter).filter(Boolean); const windowsExt = process.platform === "win32" @@ -223,7 +224,7 @@ export async function runChildProcess( const child = spawn(command, args, { cwd: opts.cwd, env: mergedEnv, - shell: false, + shell: process.platform === "win32", stdio: [opts.stdin != null ? "pipe" : "ignore", "pipe", "pipe"], }) as ChildProcessWithEvents; diff --git a/server/src/__tests__/cursor-local-adapter-environment.test.ts b/server/src/__tests__/cursor-local-adapter-environment.test.ts index daf18e0c..7a2850db 100644 --- a/server/src/__tests__/cursor-local-adapter-environment.test.ts +++ b/server/src/__tests__/cursor-local-adapter-environment.test.ts @@ -10,8 +10,10 @@ import { } from "./_helpers/adapter-test-harness.js"; async function writeFakeAgentCommand(binDir: string): Promise { - const commandPath = path.join(binDir, "agent"); - const script = `#!/usr/bin/env node + const isWindows = process.platform === "win32"; + + const jsPath = path.join(binDir, "agent.js"); + const jsScript = ` const fs = require("node:fs"); const outPath = process.env.GITMESH_TEST_ARGS_PATH; if (outPath) { @@ -27,9 +29,19 @@ console.log(JSON.stringify({ result: "hello", })); `; - await fs.writeFile(commandPath, script, "utf8"); - await fs.chmod(commandPath, 0o755); - return commandPath; + await fs.writeFile(jsPath, jsScript, "utf8"); + + if (isWindows) { + // On Windows, create agent.cmd that delegates to agent.js + const cmdPath = path.join(binDir, "agent.cmd"); + await fs.writeFile(cmdPath, `@echo off\nnode "%~dp0agent.js" %*\n`, "utf8"); + return cmdPath; + } else { + const commandPath = path.join(binDir, "agent"); + await fs.writeFile(commandPath, `#!/usr/bin/env node\n` + jsScript, "utf8"); + await fs.chmod(commandPath, 0o755); + return commandPath; + } } interface CursorEnvCtx {