@@ -18,6 +18,9 @@ import type {
1818 ItemCompletedNotification ,
1919 ItemStartedNotification , ThreadItem ,
2020 ModelReroutedNotification ,
21+ ReasoningSummaryPartAddedNotification ,
22+ ReasoningSummaryTextDeltaNotification ,
23+ ReasoningTextDeltaNotification ,
2124 ThreadTokenUsageUpdatedNotification ,
2225 TurnPlanUpdatedNotification ,
2326 WarningNotification
@@ -45,6 +48,7 @@ export class CodexEventHandler {
4548 private readonly sessionState : SessionState ;
4649 private failure : RequestError | null = null ;
4750 private readonly activeFuzzyFileSearchSessions = new Set < string > ( ) ;
51+ private readonly seenReasoningDeltaItemIds = new Set < string > ( ) ;
4852
4953 constructor ( connection : acp . AgentSideConnection , sessionState : SessionState ) {
5054 this . connection = connection ;
@@ -125,13 +129,13 @@ export class CodexEventHandler {
125129 case "guardianWarning" :
126130 return this . createGuardianWarningEvent ( notification . params ) ;
127131 case "thread/compacted" :
128- return {
129- sessionUpdate : "agent_message_chunk" ,
130- content : {
131- type : "text" ,
132- text : "*Context compacted to fit the model's context window.*\n\n"
133- }
134- } ;
132+ return this . createContextCompactedEvent ( ) ;
133+ case "item/reasoning/summaryTextDelta" :
134+ return this . createReasoningDeltaEvent ( notification . params ) ;
135+ case "item/reasoning/textDelta" :
136+ return this . createReasoningDeltaEvent ( notification . params ) ;
137+ case "item/reasoning/summaryPartAdded" :
138+ return this . createReasoningSectionBreakEvent ( notification . params ) ;
135139 case "model/rerouted" :
136140 return this . createModelReroutedEvent ( notification . params ) ;
137141 case "fuzzyFileSearch/sessionUpdated" :
@@ -144,9 +148,6 @@ export class CodexEventHandler {
144148 case "item/autoApprovalReview/completed" :
145149 case "hook/started" :
146150 case "hook/completed" :
147- case "item/reasoning/summaryTextDelta" :
148- case "item/reasoning/summaryPartAdded" :
149- case "item/reasoning/textDelta" :
150151 case "turn/diff/updated" :
151152 case "item/commandExecution/terminalInteraction" :
152153 case "item/fileChange/outputDelta" :
@@ -242,6 +243,28 @@ export class CodexEventHandler {
242243 } ;
243244 }
244245
246+ private createReasoningDeltaEvent (
247+ event : ReasoningSummaryTextDeltaNotification | ReasoningTextDeltaNotification
248+ ) : UpdateSessionEvent {
249+ this . seenReasoningDeltaItemIds . add ( event . itemId ) ;
250+ return this . createAgentThoughtEvent ( event . delta ) ;
251+ }
252+
253+ private createReasoningSectionBreakEvent ( event : ReasoningSummaryPartAddedNotification ) : UpdateSessionEvent {
254+ this . seenReasoningDeltaItemIds . add ( event . itemId ) ;
255+ return this . createAgentThoughtEvent ( "\n\n" ) ;
256+ }
257+
258+ private createAgentThoughtEvent ( text : string ) : UpdateSessionEvent {
259+ return {
260+ sessionUpdate : "agent_thought_chunk" ,
261+ content : {
262+ type : "text" ,
263+ text,
264+ }
265+ } ;
266+ }
267+
245268 private async createItemEvent ( event : ItemStartedNotification ) : Promise < UpdateSessionEvent | null > {
246269 switch ( event . item . type ) {
247270 case "fileChange" :
@@ -288,15 +311,10 @@ export class CodexEventHandler {
288311 case "commandExecution" :
289312 return this . completeCommandExecutionEvent ( event . item ) ;
290313 case "reasoning" :
291- const summary = event . item . summary [ 0 ] ;
292- if ( ! summary ) return null ;
293- return {
294- sessionUpdate : "agent_thought_chunk" ,
295- content : {
296- type : "text" ,
297- text : summary
298- }
314+ if ( this . seenReasoningDeltaItemIds . delete ( event . item . id ) ) {
315+ return null ;
299316 }
317+ return this . createCompletedReasoningEvent ( event . item ) ;
300318 case "collabAgentToolCall" :
301319 case "userMessage" :
302320 case "hookPrompt" :
@@ -305,11 +323,46 @@ export class CodexEventHandler {
305323 case "imageView" :
306324 case "imageGeneration" :
307325 case "enteredReviewMode" :
308- case "exitedReviewMode" :
309- case "contextCompaction" :
310326 case "plan" :
311327 return null ;
328+ case "exitedReviewMode" :
329+ return this . createExitedReviewModeEvent ( event . item ) ;
330+ case "contextCompaction" :
331+ return this . createContextCompactedEvent ( ) ;
332+ }
333+ }
334+
335+ private createCompletedReasoningEvent ( item : ThreadItem & { type : "reasoning" } ) : UpdateSessionEvent | null {
336+ const parts = item . summary . length > 0 ? item . summary : item . content ;
337+ const text = parts . filter ( part => part . length > 0 ) . join ( "\n\n" ) ;
338+ if ( text . length === 0 ) {
339+ return null ;
312340 }
341+ return this . createAgentThoughtEvent ( text ) ;
342+ }
343+
344+ private createExitedReviewModeEvent ( item : ThreadItem & { type : "exitedReviewMode" } ) : UpdateSessionEvent | null {
345+ const text = item . review . trim ( ) ;
346+ if ( text . length === 0 ) {
347+ return null ;
348+ }
349+ return {
350+ sessionUpdate : "agent_message_chunk" ,
351+ content : {
352+ type : "text" ,
353+ text,
354+ }
355+ } ;
356+ }
357+
358+ private createContextCompactedEvent ( ) : UpdateSessionEvent {
359+ return {
360+ sessionUpdate : "agent_message_chunk" ,
361+ content : {
362+ type : "text" ,
363+ text : "*Context compacted to fit the model's context window.*\n\n"
364+ }
365+ } ;
313366 }
314367
315368 private createCommandOutputDeltaEvent ( event : CommandExecutionOutputDeltaNotification ) : UpdateSessionEvent {
0 commit comments