@@ -135,6 +135,8 @@ const TranscriptRecord = Schema.Struct({
135135 type : Schema . optional ( Schema . String ) ,
136136 role : Schema . optional ( Schema . String ) ,
137137 message : Schema . optional ( Schema . String ) ,
138+ images : Schema . optional ( Schema . Unknown ) ,
139+ local_images : Schema . optional ( Schema . Unknown ) ,
138140 model : Schema . optional ( Schema . String ) ,
139141 cwd : Schema . optional ( Schema . String ) ,
140142 history_base : Schema . optional ( Schema . Unknown ) ,
@@ -359,7 +361,7 @@ function foldClaudeFields(fields: ClaudeFields, record: DecodedTranscriptRecord)
359361// Codex records setup context as user text ahead of the real request. Skip
360362// these leading blocks when deriving a title; imported messages keep them.
361363const CODEX_TITLE_PREAMBLE =
362- / ^ (?: \s * (?: < ( r e c o m m e n d e d _ p l u g i n s | e n v i r o n m e n t _ c o n t e x t | u s e r _ i n s t r u c t i o n s | I N S T R U C T I O N S | i n - a p p - b r o w s e r - c o n t e x t ) (?: \s [ ^ > ] * ) ? > [ \s \S ] * ?< \/ \1> | # A G E N T S \. m d i n s t r u c t i o n s \b [ ^ \n ] * ) ) + / ;
364+ / ^ (?: \s * (?: < ( r e c o m m e n d e d _ p l u g i n s | e n v i r o n m e n t _ c o n t e x t | u s e r _ i n s t r u c t i o n s | I N S T R U C T I O N S | i n - a p p - b r o w s e r - c o n t e x t ) (?: \s [ ^ > ] * ) ? > [ \s \S ] * ?< \/ \1> | # A G E N T S \. m d i n s t r u c t i o n s \b [ ^ \n ] * | # # M y r e q u e s t f o r C o d e x : ) ) + / ;
363365
364366// Codex prompts that open with generated context end it at the request line.
365367// When that line appears more than once, either side may quote it, so keep the text.
@@ -403,12 +405,28 @@ function codexUserText(text: string): string {
403405 . join ( "\n\n" ) ;
404406}
405407
408+ // Codex shows a prompt's images as these placeholders; an image-only prompt is only them.
409+ function codexImagePlaceholders ( text : string , imageCount : number ) : string {
410+ if ( text . trim ( ) . length > 0 ) return text ;
411+ return Array . from ( { length : imageCount } , ( _ , index ) => `[Image #${ index + 1 } ]` ) . join ( " " ) ;
412+ }
413+
406414// Legacy rollouts record user_message events; paginated ones record completed UserMessage items.
407415function codexUserEventText ( record : DecodedTranscriptRecord ) : string | null {
408416 if ( record . type !== "event_msg" ) return null ;
409- if ( record . payload ?. type === "user_message" ) return record . payload . message ?? "" ;
410- if ( record . payload ?. type === "item_completed" && record . payload . item ?. type === "UserMessage" ) {
411- return extractText ( record . payload . item . content ) ;
417+ const payload = record . payload ;
418+ if ( payload ?. type === "user_message" ) {
419+ const imageCount =
420+ ( Array . isArray ( payload . images ) ? payload . images . length : 0 ) +
421+ ( Array . isArray ( payload . local_images ) ? payload . local_images . length : 0 ) ;
422+ return codexImagePlaceholders ( payload . message ?? "" , imageCount ) ;
423+ }
424+ if ( payload ?. type === "item_completed" && payload . item ?. type === "UserMessage" ) {
425+ const content = payload . item . content ?? [ ] ;
426+ const imageCount = content . filter (
427+ ( block ) => block . type === "image" || block . type === "local_image" ,
428+ ) . length ;
429+ return codexImagePlaceholders ( extractText ( content ) , imageCount ) ;
412430 }
413431 return null ;
414432}
@@ -562,6 +580,7 @@ function parseAgentSessionRecords(
562580 // response copies add injected context. Rollouts without them only have responses.
563581 const hasCodexUserEvents =
564582 input . source === "codex" && records . some ( ( record ) => codexUserEventText ( record ) !== null ) ;
583+ let codexTurnUserEvents : Array < { readonly type : string | undefined ; readonly text : string } > = [ ] ;
565584
566585 let conversationMessageCount = 0 ;
567586 const retainMessage = (
@@ -610,11 +629,22 @@ function parseAgentSessionRecords(
610629 }
611630 const userEventText = codexUserEventText ( record ) ;
612631 if ( userEventText !== null ) {
632+ const eventType = record . payload ?. type ;
633+ // A rollout that records a prompt in both event forms shows it once.
634+ const copy = codexTurnUserEvents . findIndex (
635+ ( event ) => event . type !== eventType && event . text === userEventText ,
636+ ) ;
637+ if ( copy !== - 1 ) {
638+ codexTurnUserEvents . splice ( copy , 1 ) ;
639+ continue ;
640+ }
641+ codexTurnUserEvents . push ( { type : eventType , text : userEventText } ) ;
613642 retainMessage ( "user" , codexUserText ( userEventText ) , record . timestamp ) ;
614643 continue ;
615644 }
616645 if ( record . type !== "response_item" || record . payload ?. type !== "message" ) continue ;
617646 if ( record . payload . role === "assistant" ) {
647+ codexTurnUserEvents = [ ] ;
618648 retainMessage ( "assistant" , extractText ( record . payload . content ) , record . timestamp ) ;
619649 } else if ( record . payload . role === "user" && ! hasCodexUserEvents ) {
620650 retainMessage ( "user" , codexUserText ( extractText ( record . payload . content ) ) , record . timestamp ) ;
0 commit comments