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
56 changes: 28 additions & 28 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 @@ -62,7 +62,7 @@
},
"dependencies": {
"@agentclientprotocol/sdk": "^0.22.1",
"@openai/codex": "^0.128.0",
"@openai/codex": "^0.134.0",
"diff": "^8.0.3",
"open": "^11.0.0",
"vscode-jsonrpc": "^8.2.1"
Expand Down
43 changes: 19 additions & 24 deletions src/CodexAcpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ export class CodexAcpClient {
}

async resumeSession(request: acp.ResumeSessionRequest): Promise<SessionMetadata> {
await this.refreshSkills(request.cwd, request._meta);
await this.refreshSkills(request.cwd);

const response = await this.codexClient.threadResume({
config: await this.createSessionConfig(request.cwd, request.mcpServers ?? []),
Expand All @@ -214,7 +214,7 @@ export class CodexAcpClient {
sessionId: request.sessionId,
currentModelId: currentModelId,
models: codexModels,
currentServiceTier: response.serviceTier ?? null,
currentServiceTier: normalizeServiceTier(response.serviceTier),
}
}

Expand All @@ -231,13 +231,13 @@ export class CodexAcpClient {
sessionId: request.sessionId,
currentModelId: currentModelId,
models: codexModels,
currentServiceTier: response.serviceTier ?? null,
currentServiceTier: normalizeServiceTier(response.serviceTier),
thread: response.thread,
};
}

async newSession(request: acp.NewSessionRequest): Promise<SessionMetadata> {
await this.refreshSkills(request.cwd, request._meta);
await this.refreshSkills(request.cwd);

const response = await this.codexClient.threadStart({
config: await this.createSessionConfig(request.cwd, request.mcpServers),
Expand All @@ -254,7 +254,7 @@ export class CodexAcpClient {
sessionId: response.thread.id,
currentModelId: currentModelId,
models: codexModels,
currentServiceTier: response.serviceTier ?? null,
currentServiceTier: normalizeServiceTier(response.serviceTier),
};
}

Expand Down Expand Up @@ -312,18 +312,13 @@ export class CodexAcpClient {
return this.getModelProvider() ?? "openai";
}

private async refreshSkills(cwd: string, meta?: Record<string, unknown> | null): Promise<void> {
private async refreshSkills(cwd: string): Promise<void> {
if (!cwd) {
return;
}
const additionalRoots = readAdditionalRoots(meta);
await this.codexClient.listSkills({
cwds: [cwd],
forceReload: true,
perCwdExtraUserRoots: [{
cwd: cwd,
extraUserRoots: additionalRoots
}]
});
}

Expand Down Expand Up @@ -389,7 +384,7 @@ export class CodexAcpClient {
const input = buildPromptItems(request.prompt);
const effort = modelId.effort as ReasoningEffort | null; //TODO remove unsafe conversion

await this.refreshSkills(cwd, request._meta);
await this.refreshSkills(cwd);
return await this.codexClient.runTurn({
threadId: request.sessionId,
input: input,
Expand Down Expand Up @@ -623,18 +618,6 @@ interface GatewayConfig {
}
}

function readAdditionalRoots(meta: Record<string, unknown> | null | undefined): string[] {
const rawRoots = meta?.["additionalRoots"];
if (!Array.isArray(rawRoots)) {
return [];
}

return Array.from(new Set(rawRoots
.filter((value): value is string => typeof value === "string")
.map(value => value.trim())
.filter(value => value.length > 0)));
}

function mergeGatewayConfig(config: JsonObject, gatewayConfig: GatewayConfig | null): JsonObject {
if (gatewayConfig !== null) {
const newConfig = {...config};
Expand All @@ -650,3 +633,15 @@ function mergeGatewayConfig(config: JsonObject, gatewayConfig: GatewayConfig | n
return config;
}
}

function normalizeServiceTier(serviceTier: string | null): ServiceTier | null {
switch (serviceTier) {
case "fast":
case "flex":
return serviceTier;
case null:
return null;
default:
return null;
}
}
3 changes: 3 additions & 0 deletions src/CodexEventHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ export class CodexEventHandler {
case "thread/goal/cleared":
case "remoteControl/status/changed":
case "app/list/updated":
case "thread/settings/updated":
case "process/outputDelta":
case "process/exited":
return null;
}
}
Expand Down
36 changes: 16 additions & 20 deletions src/__tests__/CodexACPAgent/CodexAcpClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import type {ServerNotification} from "../../app-server";
import type {SessionState} from "../../CodexAcpServer";
import {AgentMode} from "../../AgentMode";
import type {Model, TurnStartParams} from "../../app-server/v2";
import type {Model, Turn, TurnStartParams} from "../../app-server/v2";
import type {RateLimitsMap} from "../../RateLimitsMap";
import {ModelId} from "../../ModelId";

Expand Down Expand Up @@ -215,7 +215,7 @@ describe('ACP server test', { timeout: 40_000 }, () => {
expect(logoutSpy).toHaveBeenCalledWith({});
});

it('prefetches session additional skill roots before thread start', async () => {
it('prefetches session skills before thread start', async () => {
const mockFixture = createCodexMockTestFixture();
const codexAcpClient = mockFixture.getCodexAcpClient();
const codexAppServerClient = mockFixture.getCodexAppServerClient();
Expand Down Expand Up @@ -245,6 +245,8 @@ describe('ACP server test', { timeout: 40_000 }, () => {
inputModalities: ["text"],
supportsPersonality: false,
additionalSpeedTiers: [],
serviceTiers: [],
defaultServiceTier: null,
isDefault: true
}],
nextCursor: null
Expand All @@ -253,18 +255,11 @@ describe('ACP server test', { timeout: 40_000 }, () => {
await codexAcpClient.newSession({
cwd: "/workspace",
mcpServers: [],
_meta: {
additionalRoots: ["/skills/one", " /skills/two ", 7]
}
});

expect(listSkillsSpy).toHaveBeenCalledWith({
cwds: ["/workspace"],
forceReload: true,
perCwdExtraUserRoots: [{
cwd: "/workspace",
extraUserRoots: ["/skills/one", "/skills/two"]
}]
});
expect(listSkillsSpy.mock.invocationCallOrder[0]!).toBeLessThan(threadStartSpy.mock.invocationCallOrder[0]!);
});
Expand Down Expand Up @@ -358,7 +353,7 @@ describe('ACP server test', { timeout: 40_000 }, () => {
expect(session.sessionId).toBe("thread-id");
});

it('prefetches session additional skill roots before turn start', async () => {
it('prefetches session skills before turn start', async () => {
const mockFixture = createCodexMockTestFixture();
const codexAcpAgent = mockFixture.getCodexAcpAgent();
const codexAppServerClient = mockFixture.getCodexAppServerClient();
Expand All @@ -380,19 +375,12 @@ describe('ACP server test', { timeout: 40_000 }, () => {
const promptRequest: acp.PromptRequest = {
sessionId: "session-id",
prompt: [{ type: "text", text: "Hello" }],
_meta: {
additionalRoots: ["/skills/one", " /skills/two ", 7]
}
};
await codexAcpAgent.prompt(promptRequest);

expect(listSkillsSpy).toHaveBeenCalledWith({
cwds: ["/workspace"],
forceReload: true,
perCwdExtraUserRoots: [{
cwd: "/workspace",
extraUserRoots: ["/skills/one", "/skills/two"]
}]
});
expect(listSkillsSpy.mock.invocationCallOrder[0]!).toBeLessThan(turnStartSpy.mock.invocationCallOrder[0]!);
});
Expand All @@ -412,10 +400,11 @@ describe('ACP server test', { timeout: 40_000 }, () => {
return onServerNotification;
}

function createTurn(id: string, status: "inProgress" | "completed") {
function createTurn(id: string, status: "inProgress" | "completed"): Turn {
return {
id,
items: [],
itemsView: "full",
status,
error: null,
startedAt: null,
Expand Down Expand Up @@ -445,11 +434,11 @@ describe('ACP server test', { timeout: 40_000 }, () => {

fixture.getCodexAppServerClient().listSkills = vi.fn().mockResolvedValue({ data: [] });
fixture.getCodexAppServerClient().turnStart = vi.fn().mockResolvedValue({
turn: { id: "turn-id", items: [], status: "inProgress", error: null }
turn: { id: "turn-id", items: [], itemsView: "full", status: "inProgress", error: null, startedAt: null, completedAt: null, durationMs: null }
});
fixture.getCodexAppServerClient().awaitTurnCompleted = vi.fn().mockResolvedValue({
threadId: "id",
turn: { id: "turn-id", items: [], status: "completed", error: null }
turn: { id: "turn-id", items: [], itemsView: "full", status: "completed", error: null, startedAt: null, completedAt: null, durationMs: null }
});
const sessionState: SessionState = createTestSessionState({
sessionId: "id",
Expand Down Expand Up @@ -657,6 +646,7 @@ describe('ACP server test', { timeout: 40_000 }, () => {
turn: {
id: "turn-id",
items: [],
itemsView: "full",
status: "completed",
error: null,
startedAt: null,
Expand Down Expand Up @@ -852,6 +842,8 @@ describe('ACP server test', { timeout: 40_000 }, () => {
defaultReasoningEffort: 'medium',
supportsPersonality: false,
additionalSpeedTiers: [],
serviceTiers: [],
defaultServiceTier: null,
isDefault: false,
inputModalities: []
},
Expand All @@ -870,6 +862,8 @@ describe('ACP server test', { timeout: 40_000 }, () => {
defaultReasoningEffort: 'low',
supportsPersonality: false,
additionalSpeedTiers: [],
serviceTiers: [],
defaultServiceTier: null,
isDefault: true,
inputModalities: []
}
Expand All @@ -896,6 +890,7 @@ describe('ACP server test', { timeout: 40_000 }, () => {
turn: {
id: "turn-id",
items: [],
itemsView: "full",
status: "inProgress",
error: null,
startedAt: null,
Expand All @@ -908,6 +903,7 @@ describe('ACP server test', { timeout: 40_000 }, () => {
turn: {
id: "turn-id",
items: [],
itemsView: "full",
status: "completed",
error: null,
startedAt: null,
Expand Down
Loading
Loading