Skip to content
Open
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Use [OpenAI Codex](https://github.com/openai/codex) from [Agent Client Protocol]
## Features

- ChatGPT, API key, and client-provided custom gateway authentication.
- Model, reasoning effort, fast mode, approval, and sandbox mode configuration.
- Model, reasoning effort, fast mode, approval reviewer, and approval/sandbox mode configuration.
- Text prompts, embedded context, images, resource links, and additional workspace directories.
- Shell command, file change, permission request, MCP tool call, terminal output, reasoning, plan, web search, image generation, image view, token usage, and review events.
- Subagent launches as standard ACP tool calls, with Codex thread identity and activity details in namespaced `_meta.codex.subagent` metadata.
Expand Down
49 changes: 49 additions & 0 deletions src/ApprovalsReviewerConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import type {SessionConfigOption} from "@agentclientprotocol/sdk";
import type {ApprovalsReviewer} from "./app-server/v2";

export const APPROVALS_REVIEWER_CONFIG_ID = "approvals_reviewer";
export const USER_APPROVALS_REVIEWER = "user";
export const AUTO_APPROVALS_REVIEWER = "auto_review";

export type SelectableApprovalsReviewer =
| typeof USER_APPROVALS_REVIEWER
| typeof AUTO_APPROVALS_REVIEWER;

export function createApprovalsReviewerConfigOption(
currentValue: SelectableApprovalsReviewer,
): SessionConfigOption {
return {
id: APPROVALS_REVIEWER_CONFIG_ID,
name: "Approval reviewer",
description: "Who reviews eligible approval requests",
category: "_approvals_reviewer",
type: "select",
currentValue,
options: [
{
value: USER_APPROVALS_REVIEWER,
name: "User",
description: "Ask the user to approve or deny requests",
},
{
value: AUTO_APPROVALS_REVIEWER,
name: "Auto-review",
description: "Use a reviewer agent to assess eligible requests",
},
],
};
}

export function parseApprovalsReviewer(value: unknown): SelectableApprovalsReviewer | null {
if (value === USER_APPROVALS_REVIEWER) return USER_APPROVALS_REVIEWER;
if (value === AUTO_APPROVALS_REVIEWER) return AUTO_APPROVALS_REVIEWER;
return null;
}

export function normalizeApprovalsReviewer(
value: ApprovalsReviewer | null | undefined,
): SelectableApprovalsReviewer {
return value === AUTO_APPROVALS_REVIEWER || value === "guardian_subagent"
? AUTO_APPROVALS_REVIEWER
: USER_APPROVALS_REVIEWER;
}
10 changes: 10 additions & 0 deletions src/CodexAcpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ import packageJson from "../package.json";
import type {AuthenticationStatusResponse} from "./AcpExtensions";
import {createCodexCollaborationMode} from "./CollaborationModeConfig";
import type {ModeKind} from "./app-server/ModeKind";
import {
normalizeApprovalsReviewer,
type SelectableApprovalsReviewer,
} from "./ApprovalsReviewerConfig";

/**
* Well-known provider id for the client-configurable custom LLM gateway.
Expand Down Expand Up @@ -344,6 +348,7 @@ export class CodexAcpClient {
currentModelId: currentModelId,
models: codexModels,
collaborationMode: this.getCollaborationMode(response.thread.id),
approvalsReviewer: normalizeApprovalsReviewer(response.approvalsReviewer),
modelProvider: response.modelProvider,
currentServiceTier: response.serviceTier as ServiceTier ?? null,
additionalDirectories,
Expand Down Expand Up @@ -372,6 +377,7 @@ export class CodexAcpClient {
currentModelId: currentModelId,
models: codexModels,
collaborationMode: this.getCollaborationMode(response.thread.id),
approvalsReviewer: normalizeApprovalsReviewer(response.approvalsReviewer),
modelProvider: response.modelProvider,
currentServiceTier: response.serviceTier as ServiceTier ?? null,
thread: historyResponse.thread,
Expand Down Expand Up @@ -399,6 +405,7 @@ export class CodexAcpClient {
currentModelId: currentModelId,
models: codexModels,
collaborationMode: this.getCollaborationMode(response.thread.id),
approvalsReviewer: normalizeApprovalsReviewer(response.approvalsReviewer),
modelProvider: response.modelProvider,
currentServiceTier: response.serviceTier as ServiceTier ?? null,
additionalDirectories,
Expand Down Expand Up @@ -686,6 +693,7 @@ export class CodexAcpClient {
async sendPrompt(
request: acp.PromptRequest,
agentMode: AgentMode,
approvalsReviewer: SelectableApprovalsReviewer,
modelId: ModelId,
serviceTier: ServiceTier | null,
disableSummary: boolean,
Expand All @@ -704,6 +712,7 @@ export class CodexAcpClient {
threadId: request.sessionId,
input: input,
approvalPolicy: agentMode.approvalPolicy,
approvalsReviewer,
sandboxPolicy: addAdditionalDirectoriesToSandboxPolicy(agentMode.sandboxPolicy, additionalDirectories),
summary: disableSummary ? "none" : "auto",
effort: effort,
Expand Down Expand Up @@ -898,6 +907,7 @@ export type SessionMetadata = {
currentModelId: string,
models: Model[],
collaborationMode: ModeKind,
approvalsReviewer: SelectableApprovalsReviewer,
modelProvider?: string | null,
currentServiceTier?: ServiceTier | null,
additionalDirectories: string[],
Expand Down
22 changes: 22 additions & 0 deletions src/CodexAcpServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ import {
type ThreadGoalSnapshot,
toThreadGoalSnapshot,
} from "./ThreadGoalSnapshot";
import {
APPROVALS_REVIEWER_CONFIG_ID,
createApprovalsReviewerConfigOption,
parseApprovalsReviewer,
type SelectableApprovalsReviewer,
} from "./ApprovalsReviewerConfig";

export interface SessionState {
sessionId: string,
Expand All @@ -98,6 +104,7 @@ export interface SessionState {
supportedReasoningEfforts: Array<ReasoningEffortOption>,
supportedInputModalities: Array<InputModality>,
agentMode: AgentMode,
approvalsReviewer: SelectableApprovalsReviewer,
collaborationMode: ModeKind,
currentTurnId: string | null;
lastTokenUsage: TokenCount | null;
Expand Down Expand Up @@ -449,6 +456,7 @@ export class CodexAcpServer {
supportedReasoningEfforts: currentModel?.supportedReasoningEfforts ?? [],
supportedInputModalities: currentModel?.inputModalities ?? ["text", "image"],
agentMode: AgentMode.getInitialAgentMode(),
approvalsReviewer: sessionMetadata.approvalsReviewer,
collaborationMode: sessionMetadata.collaborationMode,
currentTurnId: null,
lastTokenUsage: null,
Expand Down Expand Up @@ -755,6 +763,9 @@ export class CodexAcpServer {
case MODE_CONFIG_ID:
this.applyModeChange(sessionState, this.stringConfigValue(params));
break;
case APPROVALS_REVIEWER_CONFIG_ID:
this.applyApprovalsReviewerChange(sessionState, this.stringConfigValue(params));
break;
case COLLABORATION_MODE_CONFIG_ID:
await this.applyCollaborationModeChange(sessionState, this.stringConfigValue(params));
break;
Expand Down Expand Up @@ -796,6 +807,14 @@ export class CodexAcpServer {
sessionState.agentMode = newMode;
}

private applyApprovalsReviewerChange(sessionState: SessionState, value: string): void {
const approvalsReviewer = parseApprovalsReviewer(value);
if (approvalsReviewer === null) {
throw RequestError.invalidParams();
}
sessionState.approvalsReviewer = approvalsReviewer;
}

private async applyCollaborationModeChange(sessionState: SessionState, value: string): Promise<void> {
const mode = parseCollaborationMode(value);
if (mode === null) {
Expand Down Expand Up @@ -1110,6 +1129,7 @@ export class CodexAcpServer {
const currentModelId = ModelId.fromString(sessionState.currentModelId);
const configOptions = [
sessionState.agentMode.toConfigOption(),
createApprovalsReviewerConfigOption(sessionState.approvalsReviewer),
createCollaborationModeConfigOption(sessionState.collaborationMode),
createModelConfigOption(sessionState.availableModels, currentModelId.model),
];
Expand Down Expand Up @@ -1291,6 +1311,7 @@ export class CodexAcpServer {
supportedReasoningEfforts: currentModel?.supportedReasoningEfforts ?? [],
supportedInputModalities: currentModel?.inputModalities ?? ["text", "image"],
agentMode: AgentMode.getInitialAgentMode(),
approvalsReviewer: sessionMetadata.approvalsReviewer,
collaborationMode: sessionMetadata.collaborationMode,
currentTurnId: null,
lastTokenUsage: null,
Expand Down Expand Up @@ -1985,6 +2006,7 @@ export class CodexAcpServer {
() => this.codexAcpClient.sendPrompt(
params,
agentMode,
sessionState.approvalsReviewer,
modelId,
serviceTier,
disableSummary,
Expand Down
4 changes: 4 additions & 0 deletions src/__tests__/CodexACPAgent/CodexAcpClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2821,13 +2821,15 @@ describe('ACP server test', { timeout: 40_000 }, () => {
currentModelId,
models: [model],
collaborationMode: "default",
approvalsReviewer: "user",
additionalDirectories: [],
})
.mockResolvedValueOnce({
sessionId: "session-2",
currentModelId,
models: [model],
collaborationMode: "default",
approvalsReviewer: "user",
additionalDirectories: [],
});
const logoutSpy = vi.spyOn(codexAcpClient, "logout").mockResolvedValue();
Expand Down Expand Up @@ -2887,6 +2889,7 @@ describe('ACP server test', { timeout: 40_000 }, () => {
currentModelId,
models: [model],
collaborationMode: "default",
approvalsReviewer: "user",
modelProvider: "openai",
additionalDirectories: [],
});
Expand Down Expand Up @@ -2940,6 +2943,7 @@ describe('ACP server test', { timeout: 40_000 }, () => {
currentModelId,
models: [model],
collaborationMode: "default",
approvalsReviewer: "user",
additionalDirectories: [],
});
const logoutSpy = vi.spyOn(codexAcpClient, "logout").mockResolvedValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
}
],
"approvalPolicy": "on-request",
"approvalsReviewer": "approvalsReviewer",
"sandboxPolicy": {
"type": "workspaceWrite",
"writableRoots": [],
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/CodexACPAgent/fast-mode-config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ describe("Fast mode session config", () => {
currentModelId: "fast-model[medium]",
models: [fastModel, slowModel],
collaborationMode: "default",
approvalsReviewer: "user",
currentServiceTier,
additionalDirectories: [],
});
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/CodexACPAgent/list-sessions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ describe("CodexACPAgent - list sessions", () => {
isDefault: true,
}],
collaborationMode: "default",
approvalsReviewer: "user",
currentServiceTier: null,
additionalDirectories: ["/repo/extra"],
});
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/CodexACPAgent/model-filtering.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ describe("Model filtering", () => {
currentModelId: "gpt-5.2[medium]",
models,
collaborationMode: "default",
approvalsReviewer: "user",
additionalDirectories: [],
});
vi.spyOn(codexAcpClient, "getAccount").mockResolvedValue({account: null, requiresOpenaiAuth: false});
Expand Down
2 changes: 2 additions & 0 deletions src/__tests__/CodexACPAgent/new-session-logout.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ describe("New session logout handling", () => {
currentModelId,
models: [model],
collaborationMode: "default",
approvalsReviewer: "user",
modelProvider: "openai",
additionalDirectories: [],
})
Expand All @@ -91,6 +92,7 @@ describe("New session logout handling", () => {
currentModelId,
models: [model],
collaborationMode: "default",
approvalsReviewer: "user",
modelProvider: "custom-provider",
additionalDirectories: [],
})
Expand Down
2 changes: 2 additions & 0 deletions src/__tests__/CodexACPAgent/session-close.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ async function createSession(options: {
currentModelId: "model-id[medium]",
models: [model],
collaborationMode: "default",
approvalsReviewer: "user",
currentServiceTier: null,
additionalDirectories: [],
});
Expand Down Expand Up @@ -505,6 +506,7 @@ function createSessionMetadata(): SessionMetadata {
currentModelId: "model-id[medium]",
models: [createTestModel()],
collaborationMode: "default",
approvalsReviewer: "user",
currentServiceTier: null,
additionalDirectories: [],
};
Expand Down
Loading