@@ -6,7 +6,6 @@ import type {
66 CommandExecutionRequestApprovalResponse ,
77 FileChangeRequestApprovalParams ,
88 FileChangeRequestApprovalResponse ,
9- FileUpdateChange ,
109 McpServerElicitationRequestParams ,
1110 McpServerElicitationRequestResponse
1211} from "./app-server/v2" ;
@@ -15,7 +14,12 @@ import type {ToolCallContent} from "@agentclientprotocol/sdk/dist/schema/types.g
1514import { logger } from "./Logger" ;
1615import { stripShellPrefix } from "./CodexEventHandler" ;
1716import type { ApprovalContextStore } from "./CodexApprovalContext" ;
18- import { createFileChangeContents } from "./CodexToolCallMapper" ;
17+ import {
18+ createFileChangeContents ,
19+ createFileChangeLocations ,
20+ createRawFileChangeInput ,
21+ parseUnifiedDiffChanges ,
22+ } from "./CodexToolCallMapper" ;
1923
2024const APPROVAL_OPTIONS : acp . PermissionOption [ ] = [
2125 { optionId : "allow_once" , name : "Allow Once" , kind : "allow_once" } ,
@@ -119,47 +123,39 @@ export class CodexApprovalHandler implements ApprovalHandler {
119123 }
120124 }
121125
122- private createTextContents ( ...texts : Array < string | null | undefined > ) : Array < ToolCallContent > | null {
123- const contents = texts
124- . map ( text => this . createTextContent ( text ?? null ) )
125- . filter ( ( content ) : content is ToolCallContent => content !== null )
126- return contents . length > 0 ? contents : null
127- }
128-
129126 private async buildFileChangePermissionRequest (
130127 sessionId : string ,
131128 params : FileChangeRequestApprovalParams
132129 ) : Promise < acp . RequestPermissionRequest > {
133130 const reasonContent = this . createTextContent ( params . reason ?? null ) ;
134131 const fileChange = this . approvalContext . fileChangesByItemId . get ( params . itemId ) ;
135- const diffContent = fileChange ? await createFileChangeContents ( fileChange . changes ) : [ ] ;
132+ const content : ToolCallContent [ ] = reasonContent ? [ reasonContent ] : [ ] ;
136133 const toolCall : acp . ToolCallUpdate = {
137134 toolCallId : params . itemId ,
138135 kind : "edit" ,
139136 status : "pending" ,
140137 } ;
141- const content = [
142- ...( reasonContent ? [ reasonContent ] : [ ] ) ,
143- ...diffContent ,
144- ] ;
145- if ( content . length > 0 ) {
146- toolCall . content = content ;
147- }
148138 if ( fileChange ) {
149- toolCall . locations = dedupePaths ( fileChange . changes ) . map ( path => ( { path } ) ) ;
150- toolCall . rawInput = {
151- changes : fileChange . changes . map ( change => ( {
152- path : change . path ,
153- kind : change . kind . type ,
154- diff : change . diff ,
155- } ) ) ,
156- } ;
139+ content . push ( ...await createFileChangeContents ( fileChange . changes ) ) ;
140+ toolCall . locations = createFileChangeLocations ( fileChange . changes ) ;
141+ toolCall . rawInput = createRawFileChangeInput ( fileChange . changes ) ;
157142 } else {
158143 const turnDiff = this . approvalContext . turnDiffsByTurnId . get ( params . turnId ) ;
159144 if ( turnDiff ) {
160- toolCall . rawInput = { unifiedDiff : turnDiff } ;
145+ const parsedChanges = parseUnifiedDiffChanges ( turnDiff ) ;
146+ content . push ( ...await createFileChangeContents ( parsedChanges ) ) ;
147+ const locations = createFileChangeLocations ( parsedChanges ) ;
148+ if ( locations . length > 0 ) {
149+ toolCall . locations = locations ;
150+ }
151+ toolCall . rawInput = parsedChanges . length > 0
152+ ? { unifiedDiff : turnDiff , ...createRawFileChangeInput ( parsedChanges ) }
153+ : { unifiedDiff : turnDiff } ;
161154 }
162155 }
156+ if ( content . length > 0 ) {
157+ toolCall . content = content ;
158+ }
163159 return {
164160 sessionId,
165161 toolCall,
@@ -179,6 +175,7 @@ export class CodexApprovalHandler implements ApprovalHandler {
179175 const toolDescription = typeof meta ?. [ "tool_description" ] === "string"
180176 ? meta [ "tool_description" ]
181177 : null ;
178+ const toolDescriptionContent = this . createTextContent ( toolDescription ) ;
182179 const rawInput = this . tryToJsonValue ( meta ?. [ "tool_params" ] ) ?? null ;
183180
184181 return {
@@ -188,7 +185,7 @@ export class CodexApprovalHandler implements ApprovalHandler {
188185 title : params . message !== "" ? params . message : "MCP permission request" ,
189186 kind : "other" ,
190187 status : "pending" ,
191- content : this . createTextContents ( toolDescription ) ,
188+ content : toolDescriptionContent ? [ toolDescriptionContent ] : null ,
192189 rawInput,
193190 } ,
194191 options : this . buildMcpServerElicitationOptions ( persistOptions ) ,
@@ -350,7 +347,3 @@ export class CodexApprovalHandler implements ApprovalHandler {
350347 return { action : "cancel" , content : null , _meta : null }
351348 }
352349}
353-
354- function dedupePaths ( changes : Array < FileUpdateChange > ) : Array < string > {
355- return Array . from ( new Set ( changes . map ( change => change . path ) ) ) ;
356- }
0 commit comments