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
6 changes: 5 additions & 1 deletion src/CodexAcpServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1878,7 +1878,11 @@ export class CodexAcpServer {
const disposePromptRequestCancellation = this.observePromptRequestCancellation(signal, sessionState, activePrompt);

try {
const eventHandler = new CodexEventHandler(this.connection, sessionState);
const eventHandler = new CodexEventHandler(
this.connection,
sessionState,
() => this.availableCommands.publish(sessionState),
);
const approvalHandler = new CodexApprovalHandler(this.connection, sessionState, activePrompt.signal);
const elicitationHandler = new CodexElicitationHandler(
this.connection,
Expand Down
12 changes: 10 additions & 2 deletions src/CodexEventHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export class CodexEventHandler {

private readonly connection: AcpClientConnection;
private readonly sessionState: SessionState;
private readonly onSkillsChanged: () => void | Promise<void>;
private failure: RequestError | null = null;
private readonly activeFuzzyFileSearchSessions = new Set<string>();
private readonly activeGuardianApprovalReviews = new Set<string>();
Expand All @@ -82,9 +83,14 @@ export class CodexEventHandler {
private readonly agentMessagePhases = new Map<string, string | null>();
private readonly activeSubAgentActivities = new Set<string>();

constructor(connection: AcpClientConnection, sessionState: SessionState) {
constructor(
connection: AcpClientConnection,
sessionState: SessionState,
onSkillsChanged: () => void | Promise<void>,
) {
this.connection = connection;
this.sessionState = sessionState;
this.onSkillsChanged = onSkillsChanged;
}

getFailure(): RequestError | null {
Expand Down Expand Up @@ -188,6 +194,9 @@ export class CodexEventHandler {
return this.createThreadGoalClearedEvent(notification.params);
case "item/commandExecution/terminalInteraction":
return this.createTerminalInteractionEvent(notification.params);
case "skills/changed":
await this.onSkillsChanged();
return null;
// ignored events
case "thread/deleted":
case "thread/environment/connected":
Expand Down Expand Up @@ -216,7 +225,6 @@ export class CodexEventHandler {
case "thread/realtime/closed":
case "windowsSandbox/setupCompleted":
case "account/login/completed":
case "skills/changed":
case "deprecationNotice":
case "mcpServer/oauthLogin/completed":
case "externalAgentConfig/import/completed":
Expand Down
36 changes: 36 additions & 0 deletions src/__tests__/CodexACPAgent/CodexAcpClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1351,6 +1351,42 @@ describe('ACP server test', { timeout: 40_000 }, () => {
await expect(mockFixture.getAcpConnectionDump([])).toMatchFileSnapshot("data/available-commands-skills.json");
});

it('should refresh available commands when skills change', async () => {
const { mockFixture } = setupPromptFixture({
sessionId: "session-id",
cwd: "/workspace",
additionalDirectories: ["/workspace/extra"],
});
const listSkillsSpy = vi.spyOn(mockFixture.getCodexAcpClient(), "listSkills").mockResolvedValue({
data: [{
cwd: "/workspace",
skills: [{
name: "build",
description: "Build the project",
shortDescription: "Build",
path: "/workspace",
scope: "user",
enabled: true
}],
errors: []
}]
});

await mockFixture.getCodexAcpAgent().prompt({
sessionId: "session-id",
prompt: [{ type: "text", text: "Hello" }],
});
mockFixture.clearAcpConnectionDump();

mockFixture.sendServerNotification({ method: "skills/changed", params: {} });
await mockFixture.getCodexAcpClient().waitForSessionNotifications("session-id");

expect(listSkillsSpy).toHaveBeenCalledWith({
cwds: ["/workspace", "/workspace/extra"],
});
Comment on lines +1375 to +1386
await expect(mockFixture.getAcpConnectionDump([])).toMatchFileSnapshot("data/available-commands-skills.json");
});

it('handles builtin slash command locally', async () => {
const mockFixture = createCodexMockTestFixture();
const codexAcpAgent = mockFixture.getCodexAcpAgent();
Expand Down