@@ -2,6 +2,7 @@ import * as rpc from "vscode-jsonrpc/node";
22import type { MessageConnection } from "vscode-jsonrpc/node" ;
33import type { ChildProcessWithoutNullStreams } from "node:child_process" ;
44import { spawn } from "node:child_process" ;
5+ import { createRequire } from "node:module" ;
56
67import { createJSONRPCReader , createJSONRPCWriter } from "./StdUtils" ;
78import { logger } from "./Logger" ;
@@ -11,11 +12,18 @@ export interface CodexConnection {
1112 readonly process : ChildProcessWithoutNullStreams ;
1213}
1314
14- export function startCodexConnection ( codexPath : string , env ?: NodeJS . ProcessEnv ) : CodexConnection {
15+ export function startCodexConnection ( codexPath ? : string , env ?: NodeJS . ProcessEnv ) : CodexConnection {
1516 const spawnEnv = env ?? process . env ;
16- const codex : ChildProcessWithoutNullStreams = process . platform === 'win32'
17- ? spawn ( `"${ codexPath } " app-server` , { shell : true , env : spawnEnv } )
18- : spawn ( codexPath , [ 'app-server' ] , { env : spawnEnv } ) ;
17+
18+ let codex : ChildProcessWithoutNullStreams
19+ if ( codexPath ) {
20+ codex = process . platform === 'win32'
21+ ? spawn ( `"${ codexPath } " app-server` , { shell : true , env : spawnEnv } )
22+ : spawn ( codexPath , [ 'app-server' ] , { env : spawnEnv } ) ;
23+ } else {
24+ const bundledCodexPath = createRequire ( import . meta. url ) . resolve ( "@openai/codex/bin/codex.js" ) ;
25+ codex = spawn ( process . execPath , [ bundledCodexPath , 'app-server' ] , { env : spawnEnv } ) ;
26+ }
1927
2028 attachLogs ( codex ) ;
2129
0 commit comments