@@ -214,6 +214,36 @@ describe("collapsed tool results", () => {
214214 expect ( row . summary ) . toBe ( "Read Linear project Alpha" )
215215 } )
216216
217+ test ( "a sub-agent report collapses to its summary line, envelope and headings stripped from the detail" , ( ) => {
218+ const row = toolResultRow ( {
219+ name : "task" ,
220+ content :
221+ 'Sub-agent "explore callers" reported:\n\n## Summary\nFound 3 call sites in src/tui-opentui.\n\n## Findings\n- shell.ts line 40\n- diff.ts line 12' ,
222+ } )
223+ expect ( row . summary ) . toBe ( "Found 3 call sites in src/tui-opentui." )
224+ expect ( isCollapsibleRow ( row ) ) . toBe ( true )
225+ const detailText = ( row . detail ?? [ ] )
226+ . map ( ( line ) => line . map ( ( seg ) => seg . text ) . join ( "" ) )
227+ . join ( "\n" )
228+ expect ( detailText ) . not . toContain ( "Sub-agent" )
229+ expect ( detailText ) . not . toContain ( "## " )
230+ expect ( detailText ) . toContain ( "Found 3 call sites in src/tui-opentui." )
231+ expect ( detailText ) . toContain ( "Findings" )
232+ } )
233+
234+ test ( "a short sub-agent report is still curated, not left as raw envelope" , ( ) => {
235+ const row = toolResultRow ( {
236+ name : "task" ,
237+ content : 'Sub-agent "quick check" reported:\n\n## Summary\nAll clear.' ,
238+ } )
239+ expect ( row . summary ) . toBe ( "All clear." )
240+ const detailText = ( row . detail ?? [ ] )
241+ . map ( ( line ) => line . map ( ( seg ) => seg . text ) . join ( "" ) )
242+ . join ( "\n" )
243+ expect ( detailText ) . not . toContain ( "Sub-agent" )
244+ expect ( detailText ) . not . toContain ( "## " )
245+ } )
246+
217247 test ( "an error result is neither summarised nor collapsed" , ( ) => {
218248 const row = toolResultRow ( {
219249 name : "mcp__linear__list_projects" ,
0 commit comments