@@ -266,3 +266,47 @@ describe('shouldSmoothTextSegment', () => {
266266 )
267267 } )
268268} )
269+
270+ describe ( 'parseBlocks legacy — thinking between top-level tools' , ( ) => {
271+ it ( 'keeps consecutive mothership tools in one group across intervening thinking' , ( ) => {
272+ const blocks : ContentBlock [ ] = [
273+ { type : 'thinking' , content : 'planning the search' , timestamp : 1 } ,
274+ mainToolCall ( 't1' , 'grep' ) ,
275+ { type : 'thinking' , content : 'now read the workflow' , timestamp : 1 } ,
276+ mainToolCall ( 't2' , 'read' ) ,
277+ mainToolCall ( 't3' , 'read' ) ,
278+ ]
279+ const segments = parseBlocks ( blocks )
280+ const groups = segments . filter ( ( s ) => s . type === 'agent_group' )
281+ expect ( groups ) . toHaveLength ( 1 )
282+ if ( groups [ 0 ] . type !== 'agent_group' ) throw new Error ( 'expected group' )
283+ expect ( groups [ 0 ] . agentName ) . toBe ( 'mothership' )
284+ expect ( groups [ 0 ] . items ) . toHaveLength ( 3 )
285+ } )
286+
287+ it ( 'still splits the mothership run on real main text' , ( ) => {
288+ const blocks : ContentBlock [ ] = [
289+ mainToolCall ( 't1' , 'grep' ) ,
290+ mainText ( 'Here is what I found so far.' ) ,
291+ mainToolCall ( 't2' , 'read' ) ,
292+ ]
293+ const segments = parseBlocks ( blocks )
294+ const groups = segments . filter ( ( s ) => s . type === 'agent_group' )
295+ expect ( groups ) . toHaveLength ( 2 )
296+ } )
297+
298+ it ( 'still breaks subagent lanes on main thinking' , ( ) => {
299+ const blocks : ContentBlock [ ] = [
300+ { type : 'subagent' , content : 'workflow' , parentToolCallId : 'd1' , timestamp : 1 } ,
301+ { type : 'subagent_text' , content : 'working' , parentToolCallId : 'd1' , timestamp : 1 } ,
302+ { type : 'thinking' , content : 'main reasoning' , timestamp : 1 } ,
303+ { type : 'subagent_text' , content : 'later chunk with no lane tag' , timestamp : 1 } ,
304+ ]
305+ const segments = parseBlocks ( blocks )
306+ const groups = segments . filter ( ( s ) => s . type === 'agent_group' )
307+ expect ( groups ) . toHaveLength ( 1 )
308+ if ( groups [ 0 ] . type !== 'agent_group' ) throw new Error ( 'expected group' )
309+ // The untagged chunk after thinking must NOT merge into the flushed lane.
310+ expect ( groups [ 0 ] . items ) . toHaveLength ( 1 )
311+ } )
312+ } )
0 commit comments