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
20 changes: 2 additions & 18 deletions src/CodexApprovalHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import type {
FileChangeRequestApprovalParams,
FileChangeRequestApprovalResponse
} from "./app-server/v2";
import type {ToolCallContent} from "@agentclientprotocol/sdk/dist/schema/types.gen";
import {logger} from "./Logger";
import {stripShellPrefix} from "./CodexEventHandler";
import {ApprovalOptionId} from "./ApprovalOptionId";
Expand Down Expand Up @@ -62,47 +61,32 @@ export class CodexApprovalHandler implements ApprovalHandler {
sessionId: string,
params: CommandExecutionRequestApprovalParams
): acp.RequestPermissionRequest {
const reasonContent = this.createContentFromReason(params.reason ?? null);
return {
sessionId,
toolCall: {
toolCallId: params.itemId,
kind: "execute",
status: "pending",
content: reasonContent ? [reasonContent] : null,
rawInput: params.command ? { command: stripShellPrefix(params.command), cwd: params.cwd } : null,
},
options: APPROVAL_OPTIONS,
_meta: { codex: { params } }
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course, we could also cherry-pick specific fields only.

};
}

private createContentFromReason(reason: string | null): ToolCallContent | null {
if (reason === null || reason === "") {
return null;
}
return {
type: "content",
content: {
type: "text",
text: reason
}
}
}

private buildFileChangePermissionRequest(
sessionId: string,
params: FileChangeRequestApprovalParams
): acp.RequestPermissionRequest {
const reasonContent = this.createContentFromReason(params.reason ?? null);
return {
sessionId,
toolCall: {
toolCallId: params.itemId,
kind: "edit",
status: "pending",
content: reasonContent ? [reasonContent] : null,
},
options: APPROVAL_OPTIONS,
_meta: { codex: { params } }
};
}

Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/CodexACPAgent/approval-events.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ describe('Approval Events', () => {
params
);

await expect(fixture.getAcpConnectionDump(['_meta'])).toMatchFileSnapshot(
await expect(fixture.getAcpConnectionDump([])).toMatchFileSnapshot(
'data/approval-command-allow-once.json'
);

Expand Down Expand Up @@ -172,7 +172,7 @@ describe('Approval Events', () => {
params
);

await expect(fixture.getAcpConnectionDump(['_meta'])).toMatchFileSnapshot(
await expect(fixture.getAcpConnectionDump([])).toMatchFileSnapshot(
'data/approval-command-with-rawInput.json'
);

Expand Down Expand Up @@ -314,7 +314,7 @@ describe('Approval Events', () => {
params
);

await expect(fixture.getAcpConnectionDump(['_meta'])).toMatchFileSnapshot(
await expect(fixture.getAcpConnectionDump([])).toMatchFileSnapshot(
'data/approval-file-change.json'
);

Expand Down
22 changes: 12 additions & 10 deletions src/__tests__/CodexACPAgent/data/approval-command-allow-once.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,6 @@
"toolCallId": "item-snapshot",
"kind": "execute",
"status": "pending",
"content": [
{
"type": "content",
"content": {
"type": "text",
"text": "Running npm install"
}
}
],
"rawInput": null
},
"options": [
Expand All @@ -34,7 +25,18 @@
"name": "Reject",
"kind": "reject_once"
}
]
],
"_meta": {
"codex": {
"params": {
"threadId": "test-session-id",
"turnId": "turn-1",
"itemId": "item-snapshot",
"reason": "Running npm install",
"proposedExecpolicyAmendment": null
}
}
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,6 @@
"toolCallId": "item-with-command",
"kind": "execute",
"status": "pending",
"content": [
{
"type": "content",
"content": {
"type": "text",
"text": "Installing dependencies"
}
}
],
"rawInput": {
"command": "npm install",
"cwd": "/home/user/project"
Expand All @@ -37,7 +28,20 @@
"name": "Reject",
"kind": "reject_once"
}
]
],
"_meta": {
"codex": {
"params": {
"threadId": "test-session-id",
"turnId": "turn-1",
"itemId": "item-with-command",
"reason": "Installing dependencies",
"command": "npm install",
"cwd": "/home/user/project",
"proposedExecpolicyAmendment": null
}
}
}
}
]
}
24 changes: 13 additions & 11 deletions src/__tests__/CodexACPAgent/data/approval-file-change.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,7 @@
"toolCall": {
"toolCallId": "file-change-snapshot",
"kind": "edit",
"status": "pending",
"content": [
{
"type": "content",
"content": {
"type": "text",
"text": "Modifying config file"
}
}
]
"status": "pending"
},
"options": [
{
Expand All @@ -33,7 +24,18 @@
"name": "Reject",
"kind": "reject_once"
}
]
],
"_meta": {
"codex": {
"params": {
"threadId": "test-session-id",
"turnId": "turn-1",
"itemId": "file-change-snapshot",
"reason": "Modifying config file",
"grantRoot": null
}
}
}
}
]
}
Loading