Skip to content

refactor(web): render code surfaces through stream-diffs - #1833

Open
Simon-He95 wants to merge 1 commit into
felinics:mainfrom
Simon-He95:feat/stream-diffs-code-surfaces
Open

Simon-He95 wants to merge 1 commit into
felinics:mainfrom
Simon-He95:feat/stream-diffs-code-surfaces

Conversation

@Simon-He95

@Simon-He95 Simon-He95 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Author

  • Human
  • Agent

Type

  • bug
  • feat
  • test

Summary

The web app carried two hand-maintained highlighter stacks: a Shiki kernel (useShikiHighlighter, a custom unified-diff row grid) for chat/tool output, and monaco-editor + stream-monaco for the file editor, Compare view, asset viewer, JSON dialogs and appearance previews. Both are now rendered by stream-diffs.

What changed:

  • Code fences and tool diffs: CodeBlockNode from markstream-vue renders fences (streaming handoff and ```diff fences included) through stream-diffs. The design-system `CodePanel` frame stays — it is the app's own DIY styling (menu-shell radius, card fill, edge rule, copy button), so it was kept and the inner highlight kernel was replaced.
  • Editors: new apps/web/src/components/code-surface/* wrappers (CodeEditor, CodeDiff, CodeSurface, PatchSurface) replace monaco-editor/diff.vue, monaco-editor/index.vue, minimap-theme.ts and lazy.ts. The file editor, Compare view, asset viewer, bot-settings JSON dialogs and the two appearance previews all use them.
  • Behaviour kept on purpose: external reloads win over drafts (the wrapper passes no editStateKey, so @pierre/diffs keeps no retained draft), focus() flushes a queued rebuild before focusing, light/dark switches call setThemeType() and keep the edit session, card/editor plane and code typography still come from design-system tokens.
  • Cleanup: removed the Monaco bridge, minimap theme patching, the custom Markdown-outline symbol provider, getLanguageByFilename, the dead *** Begin Patch highlight path, and the .typography-code-preview / .shiki-preview styles. Pure unified-diff helpers moved to utils/unified-diff.ts with their tests.
  • Dependencies: markstream-vue 2.0.26 → 2.0.32, stream-diffs 0.0.5 added, monaco-editor, stream-monaco and the unused @shikijs/transformers removed in apps/web and apps/desktop; both Vite configs pre-bundle stream-diffs + shiki instead of Monaco.

Related Issues

None.

Decision this PR asks for: keep Monaco, or move to stream-diffs?

This is a capability swap, not a drop-in reimplementation, and part of what it removes was built deliberately in this repo. If any item below is a must-have, the correct outcome is to close this PR — main already has the Monaco implementation and nothing there needs to change.

Removed on purpose (previously built here)

Capability Where it came from After this PR
Editor minimap, including its fill matched to the --surface-editor plane by re-registering themes apps/web/src/components/monaco-editor/minimap-theme.ts (98 lines), added by @qqqqqf-q in #1788, with the minimap behaviour tuned further in #1809 Gone. @pierre/diffs renders no minimap (the only minimap strings in its dist are Monaco theme colour keys, no minimap code), so this is a capability loss, not a new implementation of the same thing
stickyScroll and the Markdown heading DocumentSymbol provider written to feed it registerMarkdownHeadingSymbols in monaco-editor/index.vue, added by @qqqqqf-q in #624 Gone — both were Monaco-only
Monaco language services: JSON/TS/CSS/HTML diagnostics, formatOnPaste / formatOnType Monaco Gone. The app's own JSON.parse validation and the explicit Format button remain
Virtualized rendering for large files Monaco Gone: File / FileDiff render every line

What it buys

Measured on this branch:

  • 46 files, +1479 / −1739. The monaco-editor/* files are replaced by 8 files / 779 lines under apps/web/src/components/code-surface/.
  • monaco-editor, stream-monaco and @shikijs/transformers are removed from apps/web and apps/desktop; pnpm --filter @memohai/web build leaves no monaco reference in dist/assets.
  • Structural for streaming: a fence is highlighted once after it settles and becomes visible, instead of re-tokenizing on every chunk. Not benchmarked.

Not claimed: this is not a blanket performance win. The editor and Compare surfaces are not virtualized, so very large files are expected to be slower than Monaco. That was not measured.

Behaviour differences from Monaco

Area main (Monaco) This PR (stream-diffs)
Minimap shown; fill aligned to the editor plane none
Sticky scroll / Markdown outline current heading pinned while scrolling none
Diagnostics / auto-format Monaco language services app-level JSON.parse validation + explicit Format only
Large files virtualized every line rendered
Undo history continuous for the mounted editor survives light/dark and typography changes; resets on a theme name, filename/language, or readonly change (the surface is rebuilt)
External writes vs drafts host replaces the model no retained draft: an external write always wins. The panel keeps the editor mounted while a tab is hidden or Compare is open, so undo survives those
Editor commands Monaco keybindings, context menu, folding, find widget basic editing, undo/redo and selection; Monaco-specific commands were not itemized or tested here — assume they are absent unless verified
Diff surfaces hand-built grid, no hunk collapsing collapsible unchanged runs, hunk separators with ± counts, upstream reveal/edit APIs
Chat fences no line numbers, no token colours mid-stream same: line numbers only on diff fences, colours after the block settles
Language inference getLanguageByFilename map stream-diffs infers the language from the filename; an extension-less path may fall back to plaintext

If you want the minimap, sticky scroll, Monaco diagnostics or virtualized large-file editing, close this PR; nothing on main needs to change. A smaller middle path exists but is out of scope here: adopt stream-diffs only for chat fences and tool diffs, and keep monaco-editor for the editor and the Compare view.

Attribution matters here: the minimap and the Markdown outline were @qqqqqf-q's work. Closing this PR is the intended way to say those should stay.

Validation

Run locally on this branch:

  • pnpm --filter @memohai/web typecheck — pass
  • pnpm --filter @memohai/desktop typecheck (includes the runtime build) — pass
  • pnpm exec vitest run --project web — 288 files / 2622 tests pass
  • pnpm lint — 0 errors (warnings only, all pre-existing)
  • pnpm --filter @memohai/web build — pass; no monaco reference remains in dist/assets

One caveat on the test run: src/pages/oauth/mcp-oauth-security.test.ts fails intermittently when the whole web project runs in parallel. The same file fails on a clean worktree of the base commit (5db320a) with the same unhandled-rejection signature, and it passes when run alone on this branch; it is unrelated to this change.

Browser verification (headless Chromium through Playwright, against a temporary harness page that mounts the real components; the harness is not committed):

  • chat: ts, text and diff fences render highlighted rows (the text fence is the language-key collision the custom router exists for), CodePanel copy button present, no console errors
  • tool diff surface: unified patch with 2 additions / 1 deletion and correct +/- rows
  • Compare: side-by-side panes with aligned line numbers
  • editor: keyboard typing updates v-model, applyEdits() reaches the host, getText() returns the live draft, edit survives a theme switch and a v-show cycle
  • regression guard for the review finding: replacing modelValue externally (disk reload / JSON “Format”) shows the new text instead of a retained draft, and focus() after a queued rebuild lands in the live editor
  • planes: card / editor / theme-pinned previews resolve to the expected backgrounds; a theme-pinned appearance preview stays light while the UI is dark

Not verified: Electron packaging (build:dir), Docker/dev stack, and large-file (>10k lines) performance. No automated test covers the edit-session lifecycle; it was only exercised in the browser run above.

Screenshots / Recordings

No screenshot is attached: the agent had no upload channel, and local file paths are not reviewable evidence. The verification above was done with a real browser (headless Chromium) on this branch. To reproduce locally: pnpm --filter @memohai/web dev, open a conversation that streams a fenced block, open a file from the workspace, trigger a conflict chip → Compare, and open the MCP import dialog.

Human QA

  • Human QA passed

Additional Context

Please check before merging

Rendering and interaction on this branch (in priority order):

  1. Chat code fences — streaming code still updates in place; diff fences are full width while plain fences stay fit-to-content; horizontal scrolling works on long lines; copy still copies the whole block.
  2. Tool call details — edit / write show the server diff; apply_patch shows one diff per file when the server sent a unified diff and falls back to the raw *** Begin Patch text otherwise; long diffs stop at 24rem.
  3. File editor — typing, Cmd/Ctrl+S, dirty dot, undo/redo; drag the panel narrow/wide; hide it (tab switch) and come back.
  4. External changes — with unsaved edits, let the agent write the file, then use the chip: Compare (left = disk, right = yours), Reload (the editor must show the disk text, not the old draft), Save anyway.
  5. JSON dialogs — MCP import and network config: edit, Format, validation error, save.
  6. Appearance — light and dark previews each keep their own theme regardless of the UI mode; changing code font family/size updates without losing the caret.
  7. Keyboard — chat shortcuts must not fire while focus is inside a code surface, and focus must return to the editor after a chip action closes.

Benefits and trade-offs

See Decision this PR asks for above for the full ledger (measured vs structural), the removed capabilities with their authors, and the behaviour differences from Monaco. Short version: one runtime instead of two, fewer dependencies, and diff surfaces that gain hunk collapsing — at the cost of the minimap, sticky scroll, Monaco language services and virtualized large-file rendering.

Requires markstream-vue >= 2.0.31 and stream-diffs >= 0.0.5; both are pinned here.

Replace the two hand-maintained highlighters with one runtime.

- Code fences and tool diffs: drop the Shiki `useShikiHighlighter` kernel and
  the hand-built diff grid; markstream's `CodeBlockNode` (stream-diffs) renders
  them, inside the existing design-system `CodePanel` frame.
- Editors: replace `monaco-editor`/`stream-monaco` with `stream-diffs` surfaces
  (`code-surface/CodeEditor`, `CodeDiff`, `CodeSurface`, `PatchSurface`), so the
  file editor, Compare view, asset viewer, JSON dialogs and appearance previews
  share one runtime.
- Keep behaviour: external reloads win over drafts (no retained edit state),
  focus survives surface rebuilds, light/dark switches update in place, and the
  card/editor plane and code typography still come from design-system tokens.
- Remove the dead Monaco bridge, minimap theming, `getLanguageByFilename`, and
  the `.typography-code-preview`/`.shiki-preview` styles; move the pure
  unified-diff helpers to `utils/unified-diff.ts` with their tests.

Requires markstream-vue 2.0.32 (code-block editing/stream-diffs handoff) and
stream-diffs 0.0.5.
@github-actions github-actions Bot added change:desktop Changes the Electron desktop app or shared desktop configuration change:web Changes web frontend or shared frontend packages feat Adds or improves functionality size:L PR size uses the larger of added or deleted lines, excluding generated files labels Nov 24, 2026
@Simon-He95
Simon-He95 marked this pull request as draft November 24, 2026 08:11
@Simon-He95
Simon-He95 marked this pull request as ready for review November 24, 2026 09:10

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:desktop Changes the Electron desktop app or shared desktop configuration change:web Changes web frontend or shared frontend packages feat Adds or improves functionality size:L PR size uses the larger of added or deleted lines, excluding generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant