Summary
The session file preview route (/sessions/:id/file) shows .md files as Shiki-highlighted source only (same as any text file). Operators reading docs in HAPI want a Typora-style toggle between raw markdown and a rendered preview (headings, tables, blockquotes, links) without leaving the PWA.
Chat already renders markdown richly via MarkdownRenderer / markdown-text.tsx (GFM, mermaid, KaTeX, table repair, link guards). The file pane never wires that stack up.
Current behavior
web/src/routes/sessions/file.tsx — text files (including .md) → <pre><code> + Shiki highlight
- Images get
ImagePreview; markdown does not
- Existing tabs: Diff | File when git diff exists; no source/preview toggle
Proposed behavior
For markdown files (at minimum .md; consider .mdx if trivial):
- Add Source | Preview toggle in the file pane toolbar (alongside existing Diff/File tabs when present)
- Preview reuses the chat markdown pipeline (
MarkdownRenderer or equivalent exports from markdown-text.tsx) so rendering matches chat
- Default: Preview for
.md, Source for other extensions — or remember last choice per session in localStorage (operator preference; pick one and document in PR)
- Diff tab: preview toggle off or disabled while viewing diff (source-only is fine for v1)
- Copy/download buttons unchanged
Edge cases / v1 scope
- Relative links/images (
./foo.md, screenshot.png) — ideal: resolve against session cwd via existing file-route URLs; acceptable v1: render body, leave relative hrefs as-is or open externally with a known limitation called out in PR
- Large files — cap preview mode or fall back to source if over N bytes (match existing copy limit patterns in
file.tsx)
- Binary / empty — unchanged
- No hub/cli/schema changes expected (web-only); if any shared type tweak is needed, keep it minimal
Acceptance criteria
References
- File route:
web/src/routes/sessions/file.tsx
- Markdown renderer:
web/src/components/MarkdownRenderer.tsx, web/src/components/assistant-ui/markdown-text.tsx
- CSS:
.markdown-content rules in web/src/index.css
Non-goals (v1)
- WYSIWYG editing
- Split-pane simultaneous source + preview (toggle is enough)
- Hub-side markdown conversion
Summary
The session file preview route (
/sessions/:id/file) shows.mdfiles as Shiki-highlighted source only (same as any text file). Operators reading docs in HAPI want a Typora-style toggle between raw markdown and a rendered preview (headings, tables, blockquotes, links) without leaving the PWA.Chat already renders markdown richly via
MarkdownRenderer/markdown-text.tsx(GFM, mermaid, KaTeX, table repair, link guards). The file pane never wires that stack up.Current behavior
web/src/routes/sessions/file.tsx— text files (including.md) →<pre><code>+ Shiki highlightImagePreview; markdown does notProposed behavior
For markdown files (at minimum
.md; consider.mdxif trivial):MarkdownRendereror equivalent exports frommarkdown-text.tsx) so rendering matches chat.md, Source for other extensions — or remember last choice per session inlocalStorage(operator preference; pick one and document in PR)Edge cases / v1 scope
./foo.md,screenshot.png) — ideal: resolve against session cwd via existing file-route URLs; acceptable v1: render body, leave relative hrefs as-is or open externally with a known limitation called out in PRfile.tsx)Acceptance criteria
.mdfile in the file pane shows a Source | Preview toggleReferences
web/src/routes/sessions/file.tsxweb/src/components/MarkdownRenderer.tsx,web/src/components/assistant-ui/markdown-text.tsx.markdown-contentrules inweb/src/index.cssNon-goals (v1)