Skip to content

Commit 0cf4a0a

Browse files
Alan Shumclaude
andcommitted
feat: markdown preview with mermaid diagram rendering (v0.7.0)
Press "p" to toggle between raw diff and rendered markdown preview for .md files. Works from both sidebar and diff pane focus. Markdown rendering (via pulldown-cmark): - Headings (H1-H6) with color-coded bold text - Tables with box-drawing characters (┌┬┐│┼├┤└┴┘) - Fenced code blocks with language labels - Ordered/unordered lists with nesting - Inline formatting (bold, italic, strikethrough, inline code) - Links, blockquotes, horizontal rules, task lists Mermaid diagram rendering: - Auto-detects terminal: iTerm2, Kitty, Ghostty → inline images via native protocol (OSC 1337 / Kitty graphics); tmux/screen → styled source fallback - Async mmdc subprocess with 15s timeout and blake3 content-hash caching in .git/semantic-diff-cache/mermaid/ (skip re-render if unchanged) - Images scale to diff pane width with aspect-ratio-correct height - Stale images cleared on file switch (terminal.clear + immediate redraw) - Graceful degradation: no mmdc → styled source code, no images UI changes: - Footer shows Raw/Preview mode indicator - Help overlay includes "p" shortcut - Preview scroll: j/k/g/G/Ctrl-d/u navigate within preview content Also: - Removed cmux hook script and Claude Code integration setup (cmux now uses socket-based control) - Updated README: removed cmux setup section, added markdown preview and mermaid features, updated keybindings and requirements - 11 new E2E tests for preview mode New dependencies: pulldown-cmark, blake3, image, base64 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent bb67bf6 commit 0cf4a0a

26 files changed

+3806
-1131
lines changed

.claude/hooks.example/refresh-semantic-diff.sh

Lines changed: 0 additions & 51 deletions
This file was deleted.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
target/
22
ai-plans/
3+
.claude/logs/

.planning/PROJECT.md

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## What This Is
44

5-
A Rust terminal application (built with ratatui) that displays git diffs in a rich, collapsible, semantically-grouped view. Runs as a cmux split pane triggered by Claude Code hooks, giving real-time visibility into what files Claude is changing and why — grouped by meaning, not just by file path. Published on crates.io and Homebrew.
5+
A Rust terminal application (built with ratatui) that displays git diffs in a rich, collapsible, semantically-grouped view. Triggered by Claude Code hooks, giving real-time visibility into what files Claude is changing and why — grouped by meaning, not just by file path. Published on crates.io and Homebrew.
66

77
## Core Value
88

@@ -23,7 +23,6 @@ Show Claude's code changes in real-time with AI-powered semantic grouping, so th
2323
- ✓ AI semantic grouping via Claude CLI with progressive enhancement — v0.2.3
2424
- ✓ Collapsible semantic group tree nodes with summaries — v0.2.3
2525
- ✓ SIGUSR1-triggered refresh from Claude Code hooks — v0.2.3
26-
- ✓ cmux auto-split pane lifecycle — v0.2.3
2726
- ✓ PID file management (/tmp/semantic-diff.pid) — v0.2.3
2827
- ✓ PostToolUse hook for Edit/Write tools — v0.2.3
2928
- ✓ Panic hook terminal restoration — v0.2.3
@@ -35,15 +34,13 @@ Show Claude's code changes in real-time with AI-powered semantic grouping, so th
3534

3635
### Active
3736

38-
- [ ] Security audit: command injection in shell invocations (git diff, claude CLI)
39-
- [ ] Security audit: signal handling race conditions (SIGUSR1, PID file)
40-
- [ ] Security audit: LLM output parsing safety (untrusted Claude CLI JSON)
41-
- [ ] Security audit: file path traversal and symlink safety in diff parsing
42-
- [ ] Fix all identified security vulnerabilities
43-
- [ ] E2E test: live diff rendering (syntax highlighting, line numbers, word-level diff)
44-
- [ ] E2E test: real-time refresh via Claude Code hooks in cmux pane
45-
- [ ] E2E test: semantic grouping (AI clustering, sidebar, progressive enhancement)
46-
- [ ] E2E test: graceful edge cases (empty repos, huge diffs, binary files, no clauded)
37+
- [ ] "p" key toggles between raw diff and rendered markdown preview for .md files
38+
- [ ] Preview mode renders markdown (headings, tables, links, lists) via mdcat
39+
- [ ] Preview mode renders mermaid diagrams via mmdc → PNG → Kitty graphics protocol
40+
- [ ] Mermaid image caching: content-hash mermaid code blocks, reuse PNG if unchanged
41+
- [ ] Cache directory gitignored
42+
- [ ] Footer displays current mode (Raw / Preview)
43+
- [ ] Shortcut menu updated with "p" key
4744

4845
### Out of Scope
4946

@@ -59,15 +56,15 @@ Show Claude's code changes in real-time with AI-powered semantic grouping, so th
5956
Shipped MVP with 3,050 LOC Rust across 3 phases in 3 days.
6057
Tech stack: Rust, ratatui, syntect, tokio, tui-tree-widget.
6158
Latest release: v0.3.0 on crates.io and Homebrew.
62-
User runs Claude Code in cmux terminal multiplexer on macOS.
59+
User runs Claude Code in a terminal on macOS.
6360
No existing terminal tool combines collapse/expand with AI-driven semantic grouping.
6461

6562
## Constraints
6663

6764
- **Tech stack**: Rust with ratatui — single binary, fast startup
6865
- **LLM integration**: Claude CLI (clauded) — no external API keys
6966
- **Refresh model**: Hook-triggered only (PostToolUse on Edit/Write)
70-
- **Platform**: macOS with cmux
67+
- **Platform**: macOS
7168
- **Performance**: Diff parsing <100ms; LLM grouping async (progressive enhancement)
7269

7370
## Key Decisions
@@ -78,14 +75,25 @@ No existing terminal tool combines collapse/expand with AI-driven semantic group
7875
| clauded for semantic grouping | No permission prompts, local daemon, no API key management | ✓ Good |
7976
| Hook-triggered refresh over file watch | Less CPU, integrates naturally with Claude Code workflow | ✓ Good |
8077
| Async semantic grouping | Show diff immediately, regroup when LLM responds — no blocking | ✓ Good |
81-
| cmux right-split pane | Natural side-by-side with Claude Code conversation on the left | ✓ Good |
8278
| 3-phase quick depth | Diff viewer first, then hooks, then semantic grouping — each builds on prior | ✓ Good |
8379
| tui-tree-widget for sidebar | Purpose-built tree rendering, less custom code than manual approach | ✓ Good |
8480

81+
## Current Milestone: v0.7.0 Markdown Preview
82+
83+
**Goal:** Add a toggle preview mode for .md files that renders markdown and mermaid diagrams inline in the diff pane.
84+
85+
**Target features:**
86+
- "p" key toggle between raw diff and rendered preview
87+
- Markdown rendering via mdcat (headings, tables, links, lists, code blocks)
88+
- Mermaid diagram rendering via mmdc → PNG → Kitty graphics protocol
89+
- Content-hashed mermaid caching (skip re-render if code unchanged)
90+
- Footer mode indicator (Raw / Preview)
91+
- Updated shortcut menu
92+
8593
## Completed Milestones
8694

8795
1. **MVP** (v0.1.0–v0.2.3) — Diff viewer, hook integration, semantic grouping
8896
2. **Security & Demo Readiness** (v0.3.0) — Red/purple/blue team audit, hardening, E2E tests
8997

9098
---
91-
*Last updated: 2026-03-15 after v0.3.0 release*
99+
*Last updated: 2026-03-16 after v0.7.0 milestone start*

.planning/REQUIREMENTS.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# Requirements: Semantic Diff TUI
2+
3+
**Defined:** 2026-03-16
4+
**Core Value:** Show Claude's code changes in real-time with AI-powered semantic grouping, so the user always knows what's being changed and can mentally track the work without leaving the terminal.
5+
6+
## v0.7.0 Requirements
7+
8+
Requirements for markdown preview milestone. Each maps to roadmap phases.
9+
10+
### Preview Toggle
11+
12+
- [x] **PREV-01**: User can press "p" to toggle between raw diff and rendered preview mode
13+
- [x] **PREV-02**: Toggle is global -- all .md files switch mode together
14+
- [x] **PREV-03**: Toggle is no-op when viewing non-.md files
15+
- [x] **PREV-04**: Footer displays current mode indicator (Raw / Preview)
16+
- [x] **PREV-05**: Shortcut menu updated to show "p" key binding
17+
- [x] **PREV-06**: Scroll position preserved across mode toggles
18+
19+
### Markdown Rendering
20+
21+
- [x] **MKDN-01**: Preview renders headings with visual weight (size/bold/color differentiation)
22+
- [x] **MKDN-02**: Preview renders tables with aligned columns
23+
- [x] **MKDN-03**: Preview renders fenced code blocks with syntax highlighting
24+
- [x] **MKDN-04**: Preview renders ordered and unordered lists
25+
- [x] **MKDN-05**: Preview renders inline formatting (bold, italic, inline code)
26+
- [x] **MKDN-06**: Preview renders links with visible URLs
27+
- [x] **MKDN-07**: Preview renders blockquotes with visual distinction
28+
- [x] **MKDN-08**: Preview shows post-change file content (reads from working tree)
29+
30+
### Mermaid Diagrams
31+
32+
- [x] **MERM-01**: Mermaid fenced code blocks extracted and identified from markdown
33+
- [x] **MERM-02**: Mermaid code rendered to PNG via mmdc subprocess (async, non-blocking)
34+
- [x] **MERM-03**: Rendered PNG displayed inline via Kitty graphics protocol (ratatui-image)
35+
- [x] **MERM-04**: Placeholder text shown while mermaid diagram is rendering
36+
- [x] **MERM-05**: Content-hash caching via blake3 -- skip re-render if mermaid code unchanged
37+
- [x] **MERM-06**: Cache stored in .git/semantic-diff-cache/mermaid/
38+
- [x] **MERM-07**: Graceful degradation when mmdc not installed -- show styled mermaid source
39+
- [x] **MERM-08**: Three-tier terminal support: Kitty images, halfblock fallback, code block fallback
40+
41+
## Future Requirements
42+
43+
### Preview Enhancements
44+
45+
- **PREV-F01**: Per-file mode memory (remember raw/preview per file)
46+
- **PREV-F02**: Side-by-side raw + preview split view
47+
- **PREV-F03**: Preview for other file types (JSON, YAML, TOML)
48+
49+
## Out of Scope
50+
51+
| Feature | Reason |
52+
|---------|--------|
53+
| Side-by-side raw+preview | Diff pane too narrow for split view |
54+
| Diff-within-preview | Too complex -- preview shows post-change content only |
55+
| Generic image rendering | Only mermaid diagrams, not arbitrary images in markdown |
56+
| Edit/write in preview mode | Read-only viewer |
57+
| mdcat integration | mdcat archived Jan 2025; using pulldown-cmark instead |
58+
59+
## Traceability
60+
61+
| Requirement | Phase | Status |
62+
|-------------|-------|--------|
63+
| PREV-01 | Phase 7 | Complete |
64+
| PREV-02 | Phase 7 | Complete |
65+
| PREV-03 | Phase 7 | Complete |
66+
| PREV-04 | Phase 7 | Complete |
67+
| PREV-05 | Phase 7 | Complete |
68+
| PREV-06 | Phase 7 | Complete |
69+
| MKDN-01 | Phase 7 | Complete |
70+
| MKDN-02 | Phase 7 | Complete |
71+
| MKDN-03 | Phase 7 | Complete |
72+
| MKDN-04 | Phase 7 | Complete |
73+
| MKDN-05 | Phase 7 | Complete |
74+
| MKDN-06 | Phase 7 | Complete |
75+
| MKDN-07 | Phase 7 | Complete |
76+
| MKDN-08 | Phase 7 | Complete |
77+
| MERM-01 | Phase 8 | Complete |
78+
| MERM-02 | Phase 8 | Complete |
79+
| MERM-03 | Phase 8 | Complete |
80+
| MERM-04 | Phase 8 | Complete |
81+
| MERM-05 | Phase 8 | Complete |
82+
| MERM-06 | Phase 8 | Complete |
83+
| MERM-07 | Phase 9 | Complete |
84+
| MERM-08 | Phase 9 | Complete |
85+
86+
**Coverage:**
87+
- v0.7.0 requirements: 22 total
88+
- Mapped to phases: 22
89+
- Complete: 22
90+
- Unmapped: 0
91+
92+
---
93+
*Requirements defined: 2026-03-16*
94+
*Last updated: 2026-03-16 after all phases complete*

.planning/ROADMAP.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
-**Milestone 1: MVP** -- Phases 1-3 (shipped 2026-03-15, v0.1.0-v0.2.3)
66
-**Milestone 2: Security & Demo Readiness** -- Phases 4-6 (shipped 2026-03-15, v0.3.0)
7+
-**v0.7.0: Markdown Preview** -- Phases 7-9 (shipped 2026-03-16)
78

89
## Phases
910

@@ -29,8 +30,52 @@ Full details: `milestones/v1.1-ROADMAP.md`
2930

3031
</details>
3132

33+
### ✅ v0.7.0: Markdown Preview (Shipped 2026-03-16)
34+
35+
**Milestone Goal:** Add a toggle preview mode for .md files that renders markdown and mermaid diagrams inline in the diff pane.
36+
37+
- [x] **Phase 7: Core Markdown Preview** - Toggle between raw diff and rendered markdown for .md files
38+
- [x] **Phase 8: Mermaid Diagram Rendering** - Inline mermaid diagrams via mmdc with content-hash caching
39+
- [x] **Phase 9: Graceful Degradation** - Terminal tier fallback and missing-tool resilience
40+
41+
## Phase Details
42+
43+
### Phase 7: Core Markdown Preview
44+
**Goal**: Users can toggle .md files between raw diff and a rendered markdown preview showing headings, tables, code blocks, lists, and formatting
45+
**Depends on**: Phase 6 (existing codebase)
46+
**Requirements**: PREV-01, PREV-02, PREV-03, PREV-04, PREV-05, PREV-06, MKDN-01, MKDN-02, MKDN-03, MKDN-04, MKDN-05, MKDN-06, MKDN-07, MKDN-08
47+
**Success Criteria** (what must be TRUE):
48+
1. User presses "p" and the diff pane switches from raw diff to rendered markdown showing formatted headings, tables, lists, code blocks, links, and blockquotes
49+
2. User presses "p" again and returns to the raw diff view with scroll position preserved
50+
3. User navigates to a non-.md file and "p" does nothing (no error, no mode change)
51+
4. Footer shows "Raw" or "Preview" to indicate current mode, and shortcut menu includes the "p" key
52+
5. Preview displays the post-change working-tree version of the file (not the diff)
53+
**Plans**: TBD
54+
55+
### Phase 8: Mermaid Diagram Rendering
56+
**Goal**: Mermaid code blocks in markdown files render as inline images in the preview pane, with caching so repeat views are instant
57+
**Depends on**: Phase 7
58+
**Requirements**: MERM-01, MERM-02, MERM-03, MERM-04, MERM-05, MERM-06
59+
**Success Criteria** (what must be TRUE):
60+
1. User views a .md file with mermaid code blocks in preview mode and sees rendered diagram images inline where the code blocks were
61+
2. User sees "[Rendering diagram...]" placeholder text immediately, replaced by the rendered image when mmdc completes (UI never blocks)
62+
3. User views the same file again and diagrams appear instantly from cache (no mmdc re-invocation for unchanged mermaid code)
63+
4. Cache directory exists under .git/semantic-diff-cache/mermaid/ and does not pollute the working tree
64+
**Plans**: TBD
65+
66+
### Phase 9: Graceful Degradation
67+
**Goal**: Preview mode works gracefully across all terminal capabilities and when external tools are missing
68+
**Depends on**: Phase 8
69+
**Requirements**: MERM-07, MERM-08
70+
**Success Criteria** (what must be TRUE):
71+
1. User without mmdc installed sees styled mermaid source code in place of diagrams (no errors, no blank space)
72+
2. User in a terminal without Kitty graphics support sees mermaid diagrams as halfblock fallback or styled code block fallback, depending on terminal capability
73+
**Plans**: TBD
74+
3275
## Progress
3376

77+
**Execution Order:** 7 → 8 → 9
78+
3479
| Phase | Milestone | Plans Complete | Status | Completed |
3580
|-------|-----------|----------------|--------|-----------|
3681
| 1. Diff Viewer | MVP | 3/3 | Complete | 2026-03-13 |
@@ -39,3 +84,6 @@ Full details: `milestones/v1.1-ROADMAP.md`
3984
| 4. Red Team Audit | Security | 2/2 | Complete | 2026-03-15 |
4085
| 5. Purple Team Hardening | Security | 4/4 | Complete | 2026-03-15 |
4186
| 6. Blue Team E2E Testing | Security | 3/3 | Complete | 2026-03-15 |
87+
| 7. Core Markdown Preview | v0.7.0 | 1/1 | Complete | 2026-03-16 |
88+
| 8. Mermaid Diagram Rendering | v0.7.0 | 1/1 | Complete | 2026-03-16 |
89+
| 9. Graceful Degradation | v0.7.0 | 1/1 | Complete | 2026-03-16 |

0 commit comments

Comments
 (0)