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.
| Principle | Status | Notes |
|---|---|---|
| I. Specifications as source of truth | Pass | Spec defines FR-001βFR-004 and acceptance scenarios |
| II. Agent-first | Pass | No workflow change |
| III. MCP | N/A | UI-only change |
| IV. LangGraph | N/A | UI-only change |
| V. A2A | N/A | UI-only change |
| VI. Skills | N/A | No new skills |
| VII. Test-first | Pass | Existing ChatPanel tests; add/update test for final-message collapsed default |
| VIII. Documentation | Pass | Spec + plan in docs/docs/specs/095-fix-thinking-panel-expand/ |
| IX. Security | Pass | No auth/sensitive data; no new inputs |
| X. Simplicity | Pass | Minimal 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.