nexus/.planning/phases/21-chat-foundation/21-02-SUMMARY.md
Mikkel Georgsen 94a7c723de docs(21-02): complete chat-foundation plan 02 — ChatMarkdownMessage + ChatInput components
- SUMMARY.md created with task commits, deviations, decisions
- STATE.md advanced to plan 2, 50% progress recorded
- ROADMAP.md updated with phase 21 plan progress (2/4 summaries)
- REQUIREMENTS.md: CHAT-02, CHAT-03, INPUT-01, INPUT-07, THEME-01, THEME-02 marked complete
2026-04-01 13:05:49 +02:00

139 lines
6.5 KiB
Markdown

---
phase: 21-chat-foundation
plan: 02
subsystem: ui
tags: [react, rehype-highlight, highlight.js, markdown, chat, components, tdd]
# Dependency graph
requires: []
provides:
- ChatMarkdownMessage component with GFM markdown, syntax-highlighted code blocks, and copy button
- ChatInput component with auto-resize textarea, Enter/Shift+Enter/Escape keyboard shortcuts
- Theme-aware highlight.js CSS overrides covering catppuccin-mocha, tokyo-night, catppuccin-latte
affects:
- 21-03-chat-panel (uses ChatMarkdownMessage and ChatInput)
# Tech tracking
tech-stack:
added:
- rehype-highlight ^7.0.2 (syntax highlighting via lowlight/highlight.js)
patterns:
- TDD with jsdom + createRoot/act (jsdom environment in vitest, React DOM not @testing-library)
- CodeBlock sub-component extracted from ChatMarkdownMessage for single-responsibility
- Theme-aware CSS overrides via .dark, .theme-tokyo-night, :root:not(.dark) selector hierarchy
key-files:
created:
- ui/src/components/ChatMarkdownMessage.tsx
- ui/src/components/ChatMarkdownMessage.test.tsx
- ui/src/components/ChatInput.tsx
- ui/src/components/ChatInput.test.tsx
modified:
- ui/src/index.css
- ui/package.json
- pnpm-lock.yaml
key-decisions:
- "Skipped @import for highlight.js/styles/base16/catppuccin-mocha.css (not in highlight.js 11.11.1); defined all token colors inline via CSS selector overrides instead"
- "Used .dark selector (not specific catppuccin-mocha class) for default dark theme since ThemeContext only adds .dark for both dark themes — .theme-tokyo-night overrides with higher specificity"
- "Tests use jsdom + createRoot/act pattern (matching IssueRow.test.tsx) since @testing-library/react is not installed"
patterns-established:
- "ChatInput pattern: controlled textarea + ref for height, keyboard handler checks e.key and e.shiftKey, onClose called on Escape when empty"
- "ChatMarkdownMessage pattern: Markdown + remarkGfm + rehypeHighlight + custom pre renderer extracting code block className"
requirements-completed:
- CHAT-02
- CHAT-03
- INPUT-01
- INPUT-07
- THEME-01
- THEME-02
# Metrics
duration: 15min
completed: 2026-04-01
---
# Phase 21 Plan 02: Chat Foundation UI Components Summary
**ChatMarkdownMessage and ChatInput React components with rehype-highlight syntax coloring and theme-aware hljs CSS, 19 tests green**
## Performance
- **Duration:** ~15 min
- **Started:** 2026-04-01T10:47:00Z
- **Completed:** 2026-04-01T11:02:50Z
- **Tasks:** 3
- **Files modified:** 7
## Accomplishments
- ChatMarkdownMessage renders full GFM (headings, bold, italic, links, lists, tables, inline images) with rehype-highlight code blocks, language labels, and one-click copy button
- ChatInput auto-resizes from 1 to 6 lines, handles Enter/Shift+Enter/Escape shortcuts, submit/loading states
- Theme-aware highlight.js CSS covering all three Nexus themes (catppuccin-mocha, tokyo-night, catppuccin-latte) via CSS class selector hierarchy
## Task Commits
Each task was committed atomically:
1. **Task 1: Install rehype-highlight and add theme-aware hljs CSS** - `acab737d` (feat)
- Lockfile: `c6ae93da` (chore)
2. **Task 2: ChatMarkdownMessage component (TDD)** - `c7e0d936` (feat)
3. **Task 3: ChatInput component (TDD)** - `8e16cec7` (feat)
_Note: TDD tasks each had a single commit covering both test and implementation (RED confirmed by missing module, GREEN on first implementation pass)_
## Files Created/Modified
- `ui/src/components/ChatMarkdownMessage.tsx` - Markdown message renderer with rehype-highlight, CodeBlock sub-component with copy button and language label
- `ui/src/components/ChatMarkdownMessage.test.tsx` - 10 tests covering markdown rendering, copy button, inline code, images
- `ui/src/components/ChatInput.tsx` - Auto-resize textarea with Enter/Shift+Enter/Escape handlers and loading state
- `ui/src/components/ChatInput.test.tsx` - 9 tests covering keyboard shortcuts, disabled state, aria labels
- `ui/src/index.css` - Added 70 lines of theme-aware hljs CSS (three themes)
- `ui/package.json` - Added rehype-highlight ^7.0.2 dependency
- `pnpm-lock.yaml` - Updated with rehype-highlight 7.0.2, lowlight 3.3.0 dependencies
## Decisions Made
1. **highlight.js CSS import path** - The plan specified `@import "highlight.js/styles/base16/catppuccin-mocha.css"` but this file doesn't exist in highlight.js 11.11.1 (the version pulled by rehype-highlight 7 via lowlight). Wrote all three theme color sets inline using `.dark`, `.theme-tokyo-night`, and `:root:not(.dark)` selectors. Achieves the same visual result with better control.
2. **`.dark` for default catppuccin-mocha theme** - ThemeContext applies `.dark` class to `<html>` for both catppuccin-mocha and tokyo-night. Tokyo-night also gets `.theme-tokyo-night`. So `.dark` CSS covers catppuccin-mocha and `.theme-tokyo-night` (higher specificity) overrides for tokyo-night. Clean and matches the existing theme architecture.
3. **Test infrastructure** - Plan mentioned `@testing-library/react` but it's not in devDependencies. Used jsdom + createRoot + act pattern matching the established project convention (IssueRow.test.tsx).
## Deviations from Plan
### Auto-fixed Issues
**1. [Rule 1 - Bug] highlight.js base16/catppuccin-mocha.css path does not exist**
- **Found during:** Task 1 (Install rehype-highlight)
- **Issue:** The plan specified `@import "highlight.js/styles/base16/catppuccin-mocha.css"` but highlight.js 11.11.1 (installed transitively via lowlight 3.3.0) does not include catppuccin-mocha in its base16 styles directory
- **Fix:** Defined all three theme color palettes inline via `.dark`, `.theme-tokyo-night`, and `:root:not(.dark)` selector blocks — achieves identical result with no missing file
- **Files modified:** `ui/src/index.css`
- **Verification:** All `.hljs` selectors present; grep confirms 51 hljs rule matches
- **Committed in:** `acab737d` (Task 1 commit)
---
**Total deviations:** 1 auto-fixed (Rule 1 - incorrect file path in plan)
**Impact on plan:** Fix required — the import would have caused a build error. Inline CSS is equivalent and more portable.
## Issues Encountered
None beyond the hljs import path deviation above.
## User Setup Required
None - no external service configuration required.
## Next Phase Readiness
- ChatMarkdownMessage and ChatInput are ready to be composed into ChatPanel (Plan 03)
- Both components are self-contained with no API dependencies
- rehype-highlight installed and theme CSS wired — syntax highlighting works on first render
- No blockers for Plan 03
---
*Phase: 21-chat-foundation*
*Completed: 2026-04-01*