@@ -115,6 +115,8 @@ type GoalCommand =
115115 | { kind : "resume" }
116116 | { kind : "set" ; objective : string } ;
117117
118+ const MAX_PLAN_PROPOSAL_CHARS = 100_000 ;
119+
118120type CodexSkill = {
119121 name ?: string ;
120122 description ?: string ;
@@ -1168,7 +1170,7 @@ export class CodexAppServerAgent extends BaseAcpAgent {
11681170 sessionId : this . sessionId ,
11691171 update,
11701172 } as unknown as Parameters < AgentSideConnection [ "sessionUpdate" ] > [ 0 ] ;
1171- this . appendNotification ( this . sessionId , notification ) ;
1173+ this . appendPlanApprovalNotification ( notification ) ;
11721174 void this . client . sessionUpdate ( notification ) . catch ( ( error ) => {
11731175 this . logger . warn ( "Failed to emit plan approval tool call update" , {
11741176 error : String ( error ) ,
@@ -1178,6 +1180,36 @@ export class CodexAppServerAgent extends BaseAcpAgent {
11781180 } ) ;
11791181 }
11801182
1183+ private appendPlanApprovalNotification (
1184+ notification : Parameters < AgentSideConnection [ "sessionUpdate" ] > [ 0 ] ,
1185+ ) : void {
1186+ const update = notification . update as Record < string , unknown > ;
1187+ if (
1188+ update . sessionUpdate === "tool_call_update" &&
1189+ update . status === "in_progress" &&
1190+ typeof update . toolCallId === "string"
1191+ ) {
1192+ for (
1193+ let index = this . session . notificationHistory . length - 1 ;
1194+ index >= 0 ;
1195+ index --
1196+ ) {
1197+ const previous = this . session . notificationHistory [ index ] as unknown as {
1198+ update ?: Record < string , unknown > ;
1199+ } ;
1200+ if (
1201+ previous . update ?. sessionUpdate === "tool_call_update" &&
1202+ previous . update . status === "in_progress" &&
1203+ previous . update . toolCallId === update . toolCallId
1204+ ) {
1205+ this . session . notificationHistory [ index ] = notification ;
1206+ return ;
1207+ }
1208+ }
1209+ }
1210+ this . appendNotification ( this . sessionId , notification ) ;
1211+ }
1212+
11811213 /** Emit a plain agent message (user-facing status the model didn't produce). */
11821214 private broadcastAgentText ( text : string ) : void {
11831215 if ( ! this . sessionId ) return ;
@@ -1459,7 +1491,10 @@ export class CodexAppServerAgent extends BaseAcpAgent {
14591491 params as { item ?: { type ?: string ; id ?: string ; text ?: string } }
14601492 ) ?. item ;
14611493 if ( item ?. type === "plan" && typeof item . text === "string" && item . text ) {
1462- this . planProposal = { itemId : item . id ?? "codex-plan" , text : item . text } ;
1494+ this . planProposal = {
1495+ itemId : item . id ?? "codex-plan" ,
1496+ text : item . text . slice ( 0 , MAX_PLAN_PROPOSAL_CHARS ) ,
1497+ } ;
14631498 if ( this . config . mode === "plan" && this . streamedPlanToolCallId ) {
14641499 this . emitPlanProposal (
14651500 this . buildPlanApprovalToolCall ( this . planProposal ) ,
@@ -1482,7 +1517,12 @@ export class CodexAppServerAgent extends BaseAcpAgent {
14821517 : ( this . planProposal ?. itemId ?? "codex-plan" ) ;
14831518 const previousText =
14841519 this . planProposal ?. itemId === proposalId ? this . planProposal . text : "" ;
1485- this . planProposal = { itemId : proposalId , text : previousText + delta } ;
1520+ const remainingChars = MAX_PLAN_PROPOSAL_CHARS - previousText . length ;
1521+ if ( remainingChars <= 0 ) return ;
1522+ this . planProposal = {
1523+ itemId : proposalId ,
1524+ text : previousText + delta . slice ( 0 , remainingChars ) ,
1525+ } ;
14861526 if ( this . config . mode === "plan" ) {
14871527 this . emitPlanProposal (
14881528 this . buildPlanApprovalToolCall ( this . planProposal ) ,
0 commit comments