Skip to content
Closed
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
3 changes: 2 additions & 1 deletion .github/workflows/codex-update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ jobs:
openai-api-key: ${{ secrets.OPENAI_API_KEY }}
codex-version: ${{ env.VERSION }}
output-file: pr-body.md
codex-args: >-
-c sandbox_workspace_write.writable_roots=["${{ github.workspace }}/.git"]
prompt: >
Finalize the update using codex-update-compat skill.
Commit the changes, the message should mention that types or/and tests after the update were fixed.
Expand Down Expand Up @@ -100,4 +102,3 @@ jobs:
--base main \
--title "Update codex to ${{ env.VERSION }}" \
--body-file pr-body.md \
--label "codex-update"
65 changes: 30 additions & 35 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"license": "ISC",
"type": "module",
"devDependencies": {
"@openai/codex": "^0.111.0",
"@openai/codex": "^0.115.0",
"@types/node": "^24.10.1",
"mcp-hello-world": "^1.1.2",
"tsx": "^4.20.6",
Expand Down
21 changes: 13 additions & 8 deletions src/CodexAcpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,25 @@ export class CodexAcpClient {
throw RequestError.invalidRequest();
}

let loginId: string | null = null;
switch (authRequest.methodId) {
case "api-key":
if (!authRequest._meta || !authRequest._meta["api-key"]) throw RequestError.invalidRequest();
await this.codexClient.accountLogin({
type: "apiKey",
apiKey: authRequest._meta["api-key"].apiKey
});
break;
this.gatewayConfig = null;
return true;
case "chat-gpt":
const loginResponse = await this.codexClient.accountLogin({type: "chatgpt"});
if (loginResponse.type == "chatgpt") {
loginId = loginResponse.loginId;
await open(loginResponse.authUrl);
break;
}
break;
this.gatewayConfig = null;
return loginResponse.type === "chatgptAuthTokens";
case "gateway":
if (!authRequest._meta) throw RequestError.invalidRequest();

Expand Down Expand Up @@ -112,7 +117,7 @@ export class CodexAcpClient {
// Reset the gateway config to null if another authentication method was used
this.gatewayConfig = null;

const result = await this.codexClient.awaitLoginCompleted()
const result = await this.codexClient.awaitLoginCompleted(loginId)
return result.success;
}

Expand Down Expand Up @@ -259,11 +264,6 @@ export class CodexAcpClient {
};
}

async awaitMcpServers(): Promise<Array<string>>{
const response = await this.codexClient.awaitMcpStartup();
return response.ready;
}

private createSessionConfig(projectPath: string, mcpServers: Array<McpServer>): JsonObject {
const mergedConfig = {
...mergeGatewayConfig(this.config, this.gatewayConfig),
Expand Down Expand Up @@ -384,6 +384,11 @@ export class CodexAcpClient {
return this.codexClient.listMcpServerStatus(params);
}

async awaitMcpServers(): Promise<Array<string>> {
const response = await this.listMcpServers();
return response.data.map((server) => server.name);
}

async listSessions(request: acp.ListSessionsRequest): Promise<acp.ListSessionsResponse> {
const sourceKinds: ThreadSourceKind[] = [
"cli",
Expand Down
8 changes: 2 additions & 6 deletions src/CodexAcpServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ export class CodexAcpServer implements acp.Agent {

async getOrCreateSession(request: acp.NewSessionRequest | acp.ResumeSessionRequest): Promise<[SessionId, SessionModelState, SessionModeState]> {
await this.checkAuthorization();
const pendingMcpServers: Promise<Array<string>> = this.codexAcpClient.awaitMcpServers();

let sessionMetadata: SessionMetadata;
if ("sessionId" in request) {
Expand All @@ -140,8 +139,7 @@ export class CodexAcpServer implements acp.Agent {

const accountResponse = await this.runWithProcessCheck(() => this.codexAcpClient.getAccount());
const {sessionId, currentModelId, models} = sessionMetadata;
logger.log(`Waiting MCP servers to start...`)
const sessionMcpServers = await pendingMcpServers;
const sessionMcpServers = request.mcpServers?.map((server) => server.name) ?? [];
const currentModel = this.findCurrentModel(models, currentModelId);
const sessionState: SessionState = {
sessionId: sessionId,
Expand Down Expand Up @@ -332,7 +330,6 @@ export class CodexAcpServer implements acp.Agent {
thread: Thread;
}> {
await this.checkAuthorization();
const pendingMcpServers: Promise<Array<string>> = this.codexAcpClient.awaitMcpServers();

logger.log(`Load existing session: ${request.sessionId}...`);
const sessionMetadata: SessionMetadataWithThread = await this.runWithProcessCheck(() =>
Expand All @@ -341,8 +338,7 @@ export class CodexAcpServer implements acp.Agent {

const accountResponse = await this.runWithProcessCheck(() => this.codexAcpClient.getAccount());
const {sessionId, currentModelId, models, thread} = sessionMetadata;
logger.log("Waiting MCP servers to start...");
const sessionMcpServers = await pendingMcpServers;
const sessionMcpServers = request.mcpServers?.map((server) => server.name) ?? [];
const currentModel = this.findCurrentModel(models, currentModelId);
const sessionState: SessionState = {
sessionId: sessionId,
Expand Down
5 changes: 4 additions & 1 deletion src/CodexAppServerClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,12 @@ export class CodexAppServerClient {
return await this.sendRequest({ method: "config/read", params: params });
}

async awaitLoginCompleted(): Promise<AccountLoginCompletedNotification> {
async awaitLoginCompleted(loginId: string | null = null): Promise<AccountLoginCompletedNotification> {
return await new Promise((resolve) => {
this.connection.onNotification("account/login/completed", (event: AccountLoginCompletedNotification) => {
if (loginId !== null && event.loginId !== loginId) {
return;
}
resolve(event);
});
});
Expand Down
7 changes: 7 additions & 0 deletions src/CodexEventHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,16 @@ export class CodexEventHandler {
case "turn/completed":
this.sessionState.currentTurnId = null;
return null;
case "hook/started":
case "hook/completed":
case "item/autoApprovalReview/started":
case "item/autoApprovalReview/completed":
return null;
case "thread/tokenUsage/updated":
this.handleTokenUsageUpdated(notification.params);
return null;
case "command/exec/outputDelta":
return null;
case "item/commandExecution/outputDelta":
return this.createCommandOutputDeltaEvent(notification.params);
case "item/reasoning/summaryTextDelta": //TODO streaming reasoning?
Expand Down
37 changes: 19 additions & 18 deletions src/__tests__/CodexACPAgent/CodexAcpClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,31 +108,32 @@ describe('ACP server test', { timeout: 40_000 }, () => {
});

it('should authenticate with a gateway', async () => {
const codexAcpAgent = fixture.getCodexAcpAgent();
await overrideCodexHome('cli_auth_credentials_store = "file"', async () => {
const codexAcpAgent = fixture.getCodexAcpAgent();

await codexAcpAgent.initialize({protocolVersion: 1});
await fixture.getCodexAcpClient().logout();
await codexAcpAgent.initialize({protocolVersion: 1});

const authRequest: CodexAuthRequest = {
methodId: "gateway",
_meta: {
"gateway": {
baseUrl: "https://www.example.com",
headers: {
"Custom-Auth-Header": "TOKEN"
const authRequest: CodexAuthRequest = {
methodId: "gateway",
_meta: {
"gateway": {
baseUrl: "https://www.example.com",
headers: {
"Custom-Auth-Header": "TOKEN"
}
}
}
}
};
};

await codexAcpAgent.authenticate(authRequest);
expect(await fixture.getCodexAcpClient().authRequired()).toBe(false);
await codexAcpAgent.authenticate(authRequest);
expect(await fixture.getCodexAcpClient().authRequired()).toBe(false);

const authenticatedResponse = await fixture.getCodexAcpAgent().extMethod("authentication/status", {});
expect(authenticatedResponse).toEqual({type: "gateway", name: "custom-gateway"});
const authenticatedResponse = await fixture.getCodexAcpAgent().extMethod("authentication/status", {});
expect(authenticatedResponse).toEqual({type: "gateway", name: "custom-gateway"});

const newSessionResponse = await codexAcpAgent.newSession({cwd: "", mcpServers: []});
expect(newSessionResponse.sessionId).toBeDefined()
const newSessionResponse = await codexAcpAgent.newSession({cwd: "", mcpServers: []});
expect(newSessionResponse.sessionId).toBeDefined()
});
})

it('prefetches session additional skill roots before thread start', async () => {
Expand Down
Loading
Loading