Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/CodexJsonRpcConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as rpc from "vscode-jsonrpc/node";
import type {MessageConnection} from "vscode-jsonrpc/node";
import type {ChildProcessWithoutNullStreams} from "node:child_process";
import {spawn} from "node:child_process";
import {createRequire} from "node:module";

import {createJSONRPCReader, createJSONRPCWriter} from "./StdUtils";
import {logger} from "./Logger";
Expand All @@ -11,11 +12,18 @@ export interface CodexConnection {
readonly process: ChildProcessWithoutNullStreams;
}

export function startCodexConnection(codexPath: string, env?: NodeJS.ProcessEnv): CodexConnection {
export function startCodexConnection(codexPath?: string, env?: NodeJS.ProcessEnv): CodexConnection {
const spawnEnv = env ?? process.env;
const codex: ChildProcessWithoutNullStreams = process.platform === 'win32'
? spawn(`"${codexPath}" app-server`, { shell: true, env: spawnEnv })
: spawn(codexPath, ['app-server'], { env: spawnEnv });

let codex: ChildProcessWithoutNullStreams
if (codexPath) {
codex = process.platform === 'win32'
? spawn(`"${codexPath}" app-server`, { shell: true, env: spawnEnv })
: spawn(codexPath, ['app-server'], { env: spawnEnv });
} else {
const bundledCodexPath = createRequire(import.meta.url).resolve("@openai/codex/bin/codex.js");
codex = spawn(process.execPath, [bundledCodexPath, 'app-server'], {env: spawnEnv});
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

process.execPath - ensures that codex.js will be started with node.
Otherwise may lead to errors like https://youtrack.jetbrains.com/issue/LLM-27503

}

attachLogs(codex);

Expand Down
3 changes: 1 addition & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env node

import {createRequire} from "node:module";
import * as acp from "@agentclientprotocol/sdk";
import {startCodexConnection} from "./CodexJsonRpcConnection";
import {CodexAcpServer} from "./CodexAcpServer";
Expand Down Expand Up @@ -30,7 +29,7 @@ if (process.argv[2] === "login") {
}

function startAcpServer() {
const codexPath = process.env["CODEX_PATH"] ?? createRequire(import.meta.url).resolve("@openai/codex/bin/codex.js");
const codexPath = process.env["CODEX_PATH"];
const configString = process.env["CODEX_CONFIG"];
const authRequestString = process.env["DEFAULT_AUTH_REQUEST"];
const modelProvider = process.env["MODEL_PROVIDER"];
Expand Down
Loading