Skip to content

Commit 08c0e27

Browse files
committed
feat: Add more informative permissions approval
Uses the info we have to construct nicer menu items (translation of similar behavior on the Rust one)
1 parent 7e18de9 commit 08c0e27

9 files changed

Lines changed: 799 additions & 37 deletions

src/ApprovalOptionId.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ export const ApprovalOptionId = {
22
AllowOnce: "allow_once",
33
AllowAlways: "allow_always",
44
RejectOnce: "reject_once",
5+
AcceptWithExecpolicyAmendment: "accept_execpolicy_amendment",
6+
ApplyNetworkPolicyAmendment: "apply_network_policy_amendment",
7+
AllowPermissionsForTurn: "allow_permissions_turn",
8+
AllowPermissionsForSession: "allow_permissions_session",
9+
RejectPermissions: "reject_permissions",
510
} as const;
611

712
export type ApprovalOptionId = typeof ApprovalOptionId[keyof typeof ApprovalOptionId];

src/CodexAcpClient.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,10 @@ export class CodexAcpClient {
401401
await this.waitForSessionNotifications(sessionId);
402402
return await approvalHandler.handleFileChange(params);
403403
},
404+
handlePermissionsRequest: async (params) => {
405+
await this.waitForSessionNotifications(sessionId);
406+
return await approvalHandler.handlePermissionsRequest(params);
407+
},
404408
});
405409
this.codexClient.onElicitationRequest(sessionId, {
406410
handleElicitation: async (params) => {

src/CodexAppServerClient.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,14 @@ import type {
4444
CommandExecutionRequestApprovalResponse,
4545
FileChangeRequestApprovalParams,
4646
FileChangeRequestApprovalResponse,
47+
PermissionsRequestApprovalParams,
48+
PermissionsRequestApprovalResponse,
4749
} from "./app-server/v2";
4850

4951
export interface ApprovalHandler {
5052
handleCommandExecution(params: CommandExecutionRequestApprovalParams): Promise<CommandExecutionRequestApprovalResponse>;
5153
handleFileChange(params: FileChangeRequestApprovalParams): Promise<FileChangeRequestApprovalResponse>;
54+
handlePermissionsRequest(params: PermissionsRequestApprovalParams): Promise<PermissionsRequestApprovalResponse>;
5255
}
5356

5457
export interface ElicitationHandler {
@@ -78,6 +81,12 @@ const FileChangeApprovalRequest = new RequestType<
7881
void
7982
>('item/fileChange/requestApproval');
8083

84+
const PermissionsApprovalRequest = new RequestType<
85+
PermissionsRequestApprovalParams,
86+
PermissionsRequestApprovalResponse,
87+
void
88+
>('item/permissions/requestApproval');
89+
8190
const McpServerElicitationRequest = new RequestType<
8291
McpServerElicitationRequestParams,
8392
McpServerElicitationRequestResponse,
@@ -154,6 +163,17 @@ export class CodexAppServerClient {
154163
return await handler.handleFileChange(params);
155164
});
156165

166+
this.connection.onRequest(PermissionsApprovalRequest, async (params) => {
167+
if (this.isStaleTurn(params.threadId, params.turnId)) {
168+
return { permissions: {}, scope: "turn", strictAutoReview: true };
169+
}
170+
const handler = this.approvalHandlers.get(params.threadId);
171+
if (!handler) {
172+
return { permissions: {}, scope: "turn", strictAutoReview: true };
173+
}
174+
return await handler.handlePermissionsRequest(params);
175+
});
176+
157177
this.connection.onRequest(McpServerElicitationRequest, async (params) => {
158178
if (this.isStaleTurn(params.threadId, params.turnId)) {
159179
return { action: "cancel", content: null, _meta: null };

0 commit comments

Comments
 (0)