Skip to main content

Implementation Plan: Fix Thinking Panel Re-Expand on Conversation Switch

Branch: 095-fix-thinking-panel-expand | Date: 2026-03-18 | Spec: spec.md Input: Feature specification from docs/docs/specs/095-fix-thinking-panel-expand/spec.md

Summary​

When a message has completed streaming, the thinking/plan panel must default to collapsed when the message is (re)displayedβ€”e.g. when the user switches back to the conversation. Today, component remount on conversation switch re-initializes local state from a single default (expanded), causing the panel to re-expand every time. The fix is to derive the initial expand/collapse state from message completion status: if message.isFinal then default to collapsed; otherwise keep honoring the user's default (e.g. feature flag showThinking).

Technical Context​

Language/Version: TypeScript (UI), React 19
Primary Dependencies: Next.js 16, React, Tailwind CSS, feature-flag store (e.g. Zustand)
Storage: N/A (UI state only)
Testing: Jest (UI), make caipe-ui-tests
Target Platform: Web (browser)
Project Type: Web application (Next.js frontend in ui/)
Performance Goals: No regression; initial state is a single branch on mount
Constraints: Single-file change in ui/src/components/chat/ChatPanel.tsx; no new dependencies
Scale/Scope: One component (ChatMessage), one state initializer

Constitution Check​

GATE: Must pass before Phase 0 research. Re-check after Phase 1 design.

PrincipleStatusNotes
I. Specifications as source of truthPassSpec defines FR-001–FR-004 and acceptance scenarios
II. Agent-firstPassNo workflow change
III. MCPN/AUI-only change
IV. LangGraphN/AUI-only change
V. A2AN/AUI-only change
VI. SkillsN/ANo new skills
VII. Test-firstPassExisting ChatPanel tests; add/update test for final-message collapsed default
VIII. DocumentationPassSpec + plan in docs/docs/specs/095-fix-thinking-panel-expand/
IX. SecurityPassNo auth/sensitive data; no new inputs
X. SimplicityPassMinimal change: initial state derived from message.isFinal + user default

Project Structure​

Documentation (this feature)​

docs/docs/specs/095-fix-thinking-panel-expand/
β”œβ”€β”€ plan.md # This file
β”œβ”€β”€ research.md # Phase 0
β”œβ”€β”€ data-model.md # Phase 1
β”œβ”€β”€ quickstart.md # Phase 1
β”œβ”€β”€ contracts/ # Phase 1 (minimal UI contract)
└── tasks.md # Created by /speckit.tasks

Source Code (repository root)​

ui/
β”œβ”€β”€ src/
β”‚ └── components/
β”‚ └── chat/
β”‚ β”œβ”€β”€ ChatPanel.tsx # ChatMessage: showRawStream initializer
β”‚ └── __tests__/
β”‚ └── ChatPanel.test.tsx

Structure Decision: Single-app layout; the change is confined to ChatPanel.tsx (ChatMessage) and its tests. No new modules or backend changes.

Complexity Tracking​

No constitution violations; this section is empty.