AI timeline groups tool calls for cleaner chat

The instance AI timeline now collapses tool calls and intermediate text into expandable response groups, keeping conclusions visible. Event listeners were reduced by ~37% by fixing a handler leak in InstanceAiMarkdown.
The AI chat timeline could get noisy — multiple tool calls, intermediate thinking text, and subagent outputs all rendered inline made it hard to follow the conversation. Now response groups collapse these elements behind expandable summaries showing tool call counts and icons. Tool calls and subagent spawns are grouped together by their API response, with the actual answer text extracted and always visible outside the group.
The responseId tracking runs through the event pipeline. When the LLM stream emits a step-start chunk, the responseId is captured before any trace hooks run. Agent-spawned tool calls inherit the responseId from their parent's last entry since those events originate from tool code, not the stream executor. Text entries from the same response as an active group stay inside it as intermediate thinking text.
A memory leak in InstanceAiMarkdown was also fixed — click handlers on resource links were added on each render without cleanup, causing listeners to accumulate. A WeakMap now tracks handlers so they can be removed on unmount and update. The initial listener count dropped from roughly 7,900 to 4,900.
The collapsible animations use a new AnimatedCollapsibleContent component with slide-down and slide-up CSS animations, replacing the standard reka-ui CollapsibleContent across all collapsible sections. The PlanReviewPanel header became a collapsible trigger so the whole panel collapses after approval.
Visual refinements from the visual-tweaks branch standardized button sizes to medium, adjusted card backgrounds to use a consistent light-3 shade, improved dark mode contrast on answered questions, and refined typography in task details and JSON viewers.
This builds on #28155 and groups the instance AI timeline with response grouping and UI improvements.
View Original GitHub Description
Summary
- Add response grouping to instance AI timeline, collapsing tool calls and intermediate text into expandable sections per response
- Track
responseIdthrough stream chunks and agent-spawned tool calls for accurate grouping - Extract trailing text from response groups so conclusions remain visible
- Add
AnimatedCollapsibleContentcomponent with slide animations for all collapsible sections - Make
PlanReviewPanelheader a collapsible trigger so the body collapses after approval - Fix
InstanceAiMarkdownevent listener leak (clean up handlers on update/unmount) - Reduce initial event listener count by ~37% through listener cleanup
- Visual refinements from instance-ai-visual-tweaks-3
Related Linear tickets, Github issues, and Community forum posts
Builds on #28155
Review / Merge checklist
- I have seen this code, I have run this code, and I take responsibility for this code.
- PR title and summary are descriptive. (conventions)
- Docs updated or follow-up ticket created.
- Tests included.
Test plan
- Verify response groups collapse/expand correctly in instance AI chat
- Verify streaming responses group in real-time
- Verify answered questions count displays correctly
- Verify trailing text after tool calls remains visible outside groups
- Verify collapsible animations (slide down/up) work on all sections
- Verify PlanReviewPanel collapses after approval
- Browser performance profiled — listeners reduced from ~7,900 to ~4,900