diff --git a/src/commandResolution.ts b/src/commandResolution.ts index 91b092347..778db5be5 100644 --- a/src/commandResolution.ts +++ b/src/commandResolution.ts @@ -1,7 +1,7 @@ -import { spawnSync } from 'node:child_process' import { existsSync } from 'node:fs' import { homedir } from 'node:os' import { delimiter, join } from 'node:path' +import { spawnSyncCommand } from './utils/commandInvocation.js' export type CommandInvocation = { command: string @@ -61,7 +61,7 @@ function getPotentialCodexExecutables(prefix: string): string[] { 'codex-win32-x64', 'vendor', 'x86_64-pc-windows-msvc', - 'codex', + 'bin', 'codex.exe', ) : join(packageDir, 'bin', 'codex') @@ -86,7 +86,7 @@ function getPotentialRipgrepExecutables(prefix: string): string[] { } export function canRunCommand(command: string, args: string[] = []): boolean { - const result = spawnSync(command, args, { + const result = spawnSyncCommand(command, args, { stdio: 'ignore', windowsHide: true, }) diff --git a/src/server/accountRoutes.ts b/src/server/accountRoutes.ts index 08264bb42..8d6aa31cc 100644 --- a/src/server/accountRoutes.ts +++ b/src/server/accountRoutes.ts @@ -4,6 +4,8 @@ import { mkdtemp, mkdir, readFile, readdir, rename, rm, stat, writeFile } from ' import type { IncomingMessage, ServerResponse } from 'node:http' import { homedir, tmpdir } from 'node:os' import { join } from 'node:path' +import { resolveCodexCommand } from '../commandResolution.js' +import { getSpawnInvocation } from '../utils/commandInvocation.js' import { buildAppServerArgs } from './appServerRuntimeConfig.js' import { callRpcWithRateLimitDecodeRecovery } from './rateLimitDecodeRecovery.js' @@ -650,7 +652,13 @@ async function withTemporaryCodexAppServer( const authPath = join(tempCodexHome, 'auth.json') await writeFile(authPath, authRaw, { encoding: 'utf8', mode: 0o600 }) - const proc = spawn('codex', buildAppServerArgs(), { + const codexCommand = resolveCodexCommand() + if (!codexCommand) { + throw new Error('Codex CLI is not available. Install @openai/codex or set CODEXUI_CODEX_COMMAND.') + } + + const invocation = getSpawnInvocation(codexCommand, buildAppServerArgs()) + const proc = spawn(invocation.command, invocation.args, { env: { ...process.env, CODEX_HOME: tempCodexHome }, stdio: ['pipe', 'pipe', 'pipe'], }) @@ -1027,7 +1035,13 @@ async function startCodexLogin(): Promise { return await waitForLoginUrl() } - const proc = spawn('codex', ['login'], { + const codexCommand = resolveCodexCommand() + if (!codexCommand) { + throw new Error('Codex CLI is not available. Install @openai/codex or set CODEXUI_CODEX_COMMAND.') + } + + const invocation = getSpawnInvocation(codexCommand, ['login']) + const proc = spawn(invocation.command, invocation.args, { env: process.env, stdio: ['pipe', 'pipe', 'pipe'], })