@@ -20,6 +20,9 @@ import type {
2020 ItemStartedNotification ,
2121 ThreadItem ,
2222 ModelReroutedNotification ,
23+ ReasoningSummaryPartAddedNotification ,
24+ ReasoningSummaryTextDeltaNotification ,
25+ ReasoningTextDeltaNotification ,
2326 ThreadGoalClearedNotification ,
2427 ThreadGoalUpdatedNotification ,
2528 ThreadTokenUsageUpdatedNotification ,
@@ -60,6 +63,7 @@ export class CodexEventHandler {
6063 private readonly activeGuardianApprovalReviews = new Set < string > ( ) ;
6164 private readonly activeImageGenerationItems = new Set < string > ( ) ;
6265 private readonly emittedImageViewItems = new Set < string > ( ) ;
66+ private readonly seenReasoningDeltaItemIds = new Set < string > ( ) ;
6367
6468 constructor ( connection : acp . AgentSideConnection , sessionState : SessionState ) {
6569 this . connection = connection ;
@@ -145,6 +149,12 @@ export class CodexEventHandler {
145149 return this . handleGuardianApprovalReviewCompleted ( notification . params ) ;
146150 case "thread/compacted" :
147151 return this . createContextCompactedEvent ( ) ;
152+ case "item/reasoning/summaryTextDelta" :
153+ return this . createReasoningDeltaEvent ( notification . params ) ;
154+ case "item/reasoning/textDelta" :
155+ return this . createReasoningDeltaEvent ( notification . params ) ;
156+ case "item/reasoning/summaryPartAdded" :
157+ return this . createReasoningSectionBreakEvent ( notification . params ) ;
148158 case "model/rerouted" :
149159 return this . createModelReroutedEvent ( notification . params ) ;
150160 case "fuzzyFileSearch/sessionUpdated" :
@@ -159,9 +169,6 @@ export class CodexEventHandler {
159169 case "command/exec/outputDelta" :
160170 case "hook/started" :
161171 case "hook/completed" :
162- case "item/reasoning/summaryTextDelta" :
163- case "item/reasoning/summaryPartAdded" :
164- case "item/reasoning/textDelta" :
165172 case "turn/diff/updated" :
166173 case "item/commandExecution/terminalInteraction" :
167174 case "item/fileChange/outputDelta" :
@@ -290,6 +297,28 @@ export class CodexEventHandler {
290297 } ;
291298 }
292299
300+ private createReasoningDeltaEvent (
301+ event : ReasoningSummaryTextDeltaNotification | ReasoningTextDeltaNotification
302+ ) : UpdateSessionEvent {
303+ this . seenReasoningDeltaItemIds . add ( event . itemId ) ;
304+ return this . createAgentThoughtEvent ( event . delta ) ;
305+ }
306+
307+ private createReasoningSectionBreakEvent ( event : ReasoningSummaryPartAddedNotification ) : UpdateSessionEvent {
308+ this . seenReasoningDeltaItemIds . add ( event . itemId ) ;
309+ return this . createAgentThoughtEvent ( "\n\n" ) ;
310+ }
311+
312+ private createAgentThoughtEvent ( text : string ) : UpdateSessionEvent {
313+ return {
314+ sessionUpdate : "agent_thought_chunk" ,
315+ content : {
316+ type : "text" ,
317+ text,
318+ }
319+ } ;
320+ }
321+
293322 private async createItemEvent ( event : ItemStartedNotification ) : Promise < UpdateSessionEvent | null > {
294323 switch ( event . item . type ) {
295324 case "fileChange" :
@@ -351,15 +380,10 @@ export class CodexEventHandler {
351380 }
352381 return createImageGenerationUpdate ( event . item ) ;
353382 case "reasoning" :
354- const summary = event . item . summary [ 0 ] ;
355- if ( ! summary ) return null ;
356- return {
357- sessionUpdate : "agent_thought_chunk" ,
358- content : {
359- type : "text" ,
360- text : summary
361- }
383+ if ( this . seenReasoningDeltaItemIds . delete ( event . item . id ) ) {
384+ return null ;
362385 }
386+ return this . createCompletedReasoningEvent ( event . item ) ;
363387 case "webSearch" :
364388 return createWebSearchCompleteUpdate ( event . item ) ;
365389 case "collabAgentToolCall" :
@@ -376,6 +400,15 @@ export class CodexEventHandler {
376400 }
377401 }
378402
403+ private createCompletedReasoningEvent ( item : ThreadItem & { type : "reasoning" } ) : UpdateSessionEvent | null {
404+ const parts = item . summary . length > 0 ? item . summary : item . content ;
405+ const text = parts . filter ( part => part . length > 0 ) . join ( "\n\n" ) ;
406+ if ( text . length === 0 ) {
407+ return null ;
408+ }
409+ return this . createAgentThoughtEvent ( text ) ;
410+ }
411+
379412 private createExitedReviewModeEvent ( item : ThreadItem & { type : "exitedReviewMode" } ) : UpdateSessionEvent | null {
380413 const text = item . review . trim ( ) ;
381414 if ( text . length === 0 ) {
0 commit comments