@@ -2379,6 +2379,12 @@ const isWorkLogTimelineRow = (row: MessagesTimelineRow) =>
23792379 row . kind === "work-toggle" ||
23802380 row . kind === "thinking" ;
23812381
2382+ const workLogRowIsExpanded = ( row : MessagesTimelineRow ) =>
2383+ row . kind === "work"
2384+ ? row . isExpandedToolGroup
2385+ : ( row . kind === "work-live" || row . kind === "work-toggle" || row . kind === "thinking" ) &&
2386+ row . expanded === true ;
2387+
23822388/**
23832389 * Display-only pass over derived rows for the `hideReasoning` and
23842390 * `compactWorkLog` client settings. Runs after derivation so the incremental
@@ -2392,9 +2398,13 @@ export function applyTimelineDensity(
23922398 let result = rows ;
23932399
23942400 if ( options . hideReasoning ) {
2395- // Commentary = an assistant message without meta that is followed, within
2401+ // Commentary = a non-terminal assistant message that is followed, within
23962402 // the same turn, by more work or another assistant message. The trailing
23972403 // message (final answer, or the commentary still streaming) stays visible.
2404+ // Terminal answers whose meta moved below trailing tools are still terminal.
2405+ const relocatedMetaMessageIds = new Set (
2406+ result . flatMap ( ( row ) => ( row . kind === "assistant-meta" ? [ row . message . id ] : [ ] ) ) ,
2407+ ) ;
23982408 const hiddenCommentaryIds = new Set < string > ( ) ;
23992409 let laterActivityInTurn = false ;
24002410 for ( let index = result . length - 1 ; index >= 0 ; index -= 1 ) {
@@ -2404,7 +2414,8 @@ export function applyTimelineDensity(
24042414 continue ;
24052415 }
24062416 if ( row . kind === "message" && row . message . role === "assistant" ) {
2407- if ( ! row . showAssistantMeta && laterActivityInTurn ) hiddenCommentaryIds . add ( row . id ) ;
2417+ const isTerminal = row . showAssistantMeta || relocatedMetaMessageIds . has ( row . message . id ) ;
2418+ if ( ! isTerminal && laterActivityInTurn ) hiddenCommentaryIds . add ( row . id ) ;
24082419 laterActivityInTurn = true ;
24092420 } else if ( isWorkLogTimelineRow ( row ) ) {
24102421 laterActivityInTurn = true ;
@@ -2434,8 +2445,20 @@ export function applyTimelineDensity(
24342445 if ( options . compactWorkLog ) {
24352446 // Each run of consecutive work-log rows collapses to its last row, and a
24362447 // work group to its last entry, so the line updates instead of growing.
2448+ // A run the user expanded stays intact so its disclosure still works.
2449+ const expandedRunRowIds = new Set < string > ( ) ;
2450+ let run : MessagesTimelineRow [ ] = [ ] ;
2451+ for ( const row of [ ...result , null ] ) {
2452+ if ( row !== null && isWorkLogTimelineRow ( row ) ) {
2453+ run . push ( row ) ;
2454+ continue ;
2455+ }
2456+ if ( run . some ( workLogRowIsExpanded ) )
2457+ for ( const runRow of run ) expandedRunRowIds . add ( runRow . id ) ;
2458+ run = [ ] ;
2459+ }
24372460 result = result . flatMap ( ( row , index ) : MessagesTimelineRow [ ] => {
2438- if ( ! isWorkLogTimelineRow ( row ) ) return [ row ] ;
2461+ if ( ! isWorkLogTimelineRow ( row ) || expandedRunRowIds . has ( row . id ) ) return [ row ] ;
24392462 const next = result [ index + 1 ] ;
24402463 if ( next !== undefined && isWorkLogTimelineRow ( next ) ) return [ ] ;
24412464 const compactRow : MessagesTimelineRow = { ...row , continuesWorkLog : false } ;
@@ -2448,7 +2471,6 @@ export function applyTimelineDensity(
24482471 } ,
24492472 ] ;
24502473 }
2451- if ( compactRow . kind === "work-live" ) return [ { ...compactRow , expanded : false } ] ;
24522474 return [ compactRow ] ;
24532475 } ) ;
24542476 }
0 commit comments