Repository navigation
feat(native-chat): highlight code blocks and shell commands - #26343
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (3)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review. 📝 WalkthroughWalkthroughThe change adds Shiki-based syntax highlighting for eligible native chat code blocks and recognized shell commands. Highlighting loads grammars on demand and processes code incrementally in scheduled slices. The renderer preserves source text and line endings, and uses plain rendering when highlighting is disabled or unavailable. System messages and reasoning code blocks use plain rendering. The change also updates Monaco’s Oniguruma loader to use a shared helper. Priority: ➖ Normal Merge Risk: ⚪ Minimal · up to Collapsed commands intentionally remain plain text; the opened full command receives highlighting. No actionable merge-blocking issue remains after normal checks. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Uses Shiki rather than the highlight.js already in the preview: it can resume mid-block while a reply streams.
9192e2a to
6f7d996
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
48b05dfc-21c6-4d9f-9ef4-d89bfcbbfd3f
📥 Commits
Reviewing files that changed from the base of the PR and between 9192e2a7ea54a3db13b1d0698427152fa0fc71bb and 9bbdcf1.
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (3)
src/renderer/src/components/native-chat/NativeChatMessageRow.tsxsrc/renderer/src/components/native-chat/NativeChatToolLine.tsxsrc/renderer/src/components/native-chat/native-chat-tool-line-label.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
| {commandLanguage ? ( | ||
| <NativeChatHighlightedCode code={fullCommand} language={commandLanguage} /> | ||
| ) : ( | ||
| fullCommand | ||
| )} |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Highlight the command target in the collapsed row.
This change highlights fullCommand only in expanded details. The visible command target in the collapsed row still renders as plain text. Apply NativeChatHighlightedCode to the target when commandLanguage is present, and keep other targets plain. The PR objective includes highlighted command pills.
# Conflicts: # src/renderer/src/components/native-chat/NativeChatMessageRow.tsx
…face Chat code now goes through one renderer highlighting interface built on Shiki core and the Oniguruma WASM the editor already loads for Nim and Typst, with VS Code Light+/Dark+. Lines that are too long or too slow leave the rest of the block plain, failed grammar loads retry from a mounted block, every block shares one time slice, finished-block caching counts retained text, each theme keeps its own formatting, Vue template expressions are colored, and tool-row commands take the grammar of the shell they ran in.
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
1fec3cbf-eecc-4b64-a07c-5888d2c532a5
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (23)
package.jsonsrc/renderer/src/components/native-chat/NativeChatAssistantMessageRow.tsxsrc/renderer/src/components/native-chat/NativeChatCodeBlock.load-failure.test.tsxsrc/renderer/src/components/native-chat/NativeChatCodeBlock.test.tsxsrc/renderer/src/components/native-chat/NativeChatHighlightedCode.tsxsrc/renderer/src/components/native-chat/NativeChatMessageRow.test.tsxsrc/renderer/src/components/native-chat/NativeChatReasoningDisclosure.tsxsrc/renderer/src/components/native-chat/NativeChatToolLine.test.tsxsrc/renderer/src/components/native-chat/NativeChatToolLine.tsxsrc/renderer/src/components/native-chat/native-chat-command-language.test.tssrc/renderer/src/components/native-chat/native-chat-command-language.tssrc/renderer/src/components/native-chat/native-chat-tool-line-label.tssrc/renderer/src/hooks/use-highlighted-syntax.tssrc/renderer/src/lib/monaco-languages/textmate-token-provider.tssrc/renderer/src/lib/syntax-highlighting/incremental-syntax-tokenizer.test.tssrc/renderer/src/lib/syntax-highlighting/incremental-syntax-tokenizer.tssrc/renderer/src/lib/syntax-highlighting/oniguruma-test-harness.tssrc/renderer/src/lib/syntax-highlighting/oniguruma.tssrc/renderer/src/lib/syntax-highlighting/syntax-highlight-scheduler.test.tssrc/renderer/src/lib/syntax-highlighting/syntax-highlight-scheduler.tssrc/renderer/src/lib/syntax-highlighting/syntax-highlighter.test.tssrc/renderer/src/lib/syntax-highlighting/syntax-highlighter.tssrc/renderer/src/lib/syntax-highlighting/vue-template-injections.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.
| /** | ||
| * Tokens for as much of `code` as has been colored so far, or null while there | ||
| * is nothing to color it with. The rest, `code.slice(highlightedLength)`, is | ||
| * still plain and arrives over later renders. | ||
| */ | ||
| export function useHighlightedSyntax(code: string, language: string): SyntaxProgress | null { | ||
| const source = | ||
| code.length > MAX_HIGHLIGHTED_CODE_LENGTH ? code.slice(0, MAX_HIGHLIGHTED_CODE_LENGTH) : code | ||
| const highlighter = loadedSyntaxHighlighter(language) | ||
| const [, rerender] = useReducer((count: number) => count + 1, 0) | ||
|
|
||
| // Why: `source` is a dependency so a block still streaming asks again after a failed load. | ||
| useEffect(() => { | ||
| if (highlighter) { | ||
| return | ||
| } | ||
| let cancelled = false | ||
| void loadSyntaxLanguage(language).then((status) => { | ||
| if (!cancelled && status === 'ready') { | ||
| rerender() | ||
| } | ||
| }) | ||
| return () => { | ||
| cancelled = true | ||
| } | ||
| }, [language, highlighter, source]) | ||
|
|
||
| const tokenize = useMemo( | ||
| () => (highlighter ? createIncrementalSyntaxTokenizer(highlighter) : null), | ||
| [highlighter] | ||
| ) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
sed -n '1,155p' src/renderer/src/hooks/use-highlighted-syntax.ts
sed -n '290,360p' src/renderer/src/lib/syntax-highlighting/syntax-highlighter.ts
sed -n '1,80p' src/renderer/src/components/native-chat/NativeChatCodeBlock.load-failure.test.tsxRepository: stablyai/orca
Length of output: 9032
🏁 Script executed:
printf '%s\n' '--- diff ---'
git diff --unified=5 6ef42adfc0effb744d83f8240268079e8987af39 4ce02f6f4cfc9dbcc21fadc3facd9464f539e312 -- src/renderer/src/hooks/use-highlighted-syntax.ts src/renderer/src/lib/syntax-highlighting/syntax-highlighter.ts src/renderer/src/components/native-chat/NativeChatCodeBlock.load-failure.test.tsx
printf '%s\n' '--- loader declarations ---'
rg -n 'LOAD_RETRY_DELAY_MS|MAX_LOAD_ATTEMPTS|pendingLanguages|function loadLanguage|function loadSyntaxLanguage|loadedSyntaxHighlighter' src/renderer/src/lib/syntax-highlighting/syntax-highlighter.ts
sed -n '1,100p' src/renderer/src/lib/syntax-highlighting/syntax-highlighter.ts
sed -n '275,370p' src/renderer/src/lib/syntax-highlighting/syntax-highlighter.ts
printf '%s\n' '--- complete load-failure test ---'
cat src/renderer/src/components/native-chat/NativeChatCodeBlock.load-failure.test.tsxRepository: stablyai/orca
Length of output: 30001
Retry failed grammar loads without requiring a code update.
When loadSyntaxLanguage returns failed, this effect neither rerenders nor schedules another call. If the code stays unchanged, the loader’s cooldown expiring does not rerun the effect, so the mounted block can stay plain until another render or remount. Schedule bounded retries using the loader’s cooldown and stop when its retry limit is reached.
Keeps the lockfile change to Shiki alone; the earlier commit picked up the @pnpm/exe entries pnpm 12 writes when it runs in a fresh checkout.
The first colored block in a test file loads its grammar and the regex engine, which took over a second on a busy CI runner.
|
Hey Kelvin, thanks for this one. We've taken #26343 the rest of the way and pushed the changes to your branch, so the credit stays with you. Why: we want chat and the editor on one highlighting setup. Orca already ships the Oniguruma WASM for the editor (Nim and Typst), and Shiki core can run on it. So instead of a chat-only Shiki with its own WASM and colours, chat now goes through a small shared highlighting layer ( What changed:
What we'll do after this lands:
|
Upstream now highlights chat code (stablyai#26343) with VS Code's Light+ and Dark+ only, so an imported Custom appearance theme repainted Monaco but not code in chat. While a theme is active it is registered with the chat highlighter in its own mode's slot (a dark theme replaces Dark+, a light one Light+); turning it off restores both. A theme change bumps a revision that colored blocks subscribe to, and finished blocks are cached per revision, so code already on screen repaints instead of keeping the old colors. Custom-Feature: chat-code-theme Co-Authored-By: Claude Opus 5.5 <[email protected]>
Upstream now highlights chat code (stablyai#26343) with VS Code's Light+ and Dark+ only, so an imported Custom appearance theme repainted Monaco but not code in chat. While a theme is active it is registered with the chat highlighter in its own mode's slot (a dark theme replaces Dark+, a light one Light+); turning it off restores both. A theme change bumps a revision that colored blocks subscribe to, and finished blocks are cached per revision, so code already on screen repaints instead of keeping the old colors. Custom-Feature: chat-code-theme Co-Authored-By: Claude Opus 5.5 <[email protected]>
Upstream now highlights chat code (stablyai#26343) with VS Code's Light+ and Dark+ only, so an imported Custom appearance theme repainted Monaco but not code in chat. While a theme is active it is registered with the chat highlighter in its own mode's slot (a dark theme replaces Dark+, a light one Light+); turning it off restores both. A theme change bumps a revision that colored blocks subscribe to, and finished blocks are cached per revision, so code already on screen repaints instead of keeping the old colors. Custom-Feature: chat-code-theme Co-Authored-By: Claude Opus 5.5 <[email protected]>
Upstream now highlights chat code (stablyai#26343) with VS Code's Light+ and Dark+ only, so an imported Custom appearance theme repainted Monaco but not code in chat. While a theme is active it is registered with the chat highlighter in its own mode's slot (a dark theme replaces Dark+, a light one Light+); turning it off restores both. A theme change bumps a revision that colored blocks subscribe to, and finished blocks are cached per revision, so code already on screen repaints instead of keeping the old colors. Custom-Feature: chat-code-theme Co-Authored-By: Claude Opus 5.5 <[email protected]>
Upstream now highlights chat code (stablyai#26343) with VS Code's Light+ and Dark+ only, so an imported Custom appearance theme repainted Monaco but not code in chat. While a theme is active it is registered with the chat highlighter in its own mode's slot (a dark theme replaces Dark+, a light one Light+); turning it off restores both. A theme change bumps a revision that colored blocks subscribe to, and finished blocks are cached per revision, so code already on screen repaints instead of keeping the old colors. Custom-Feature: chat-code-theme Co-Authored-By: Claude Opus 5.5 <[email protected]>

ELI5
Code in the chat used to be one flat colour. Now it is coloured the way VS Code colours it, and it colours in place while the agent is still writing it. When you open a shortened shell command on a tool row, the full command is coloured in the language of the shell it actually ran in (PowerShell, cmd, bash), or left plain when Orca can't tell.
What Changed
Before: fenced code blocks in agent replies, and the full command you open on a "Ran …" tool row, were one plain colour.
After (what you see):
{{ }}and directive values (:title="…"), on one line or several.How it works:
src/renderer/src/lib/syntax-highlighting/: give it code, a language and the state it returned last time; it returns coloured lines (a light and a dark colour plus formatting per token), a state to continue from, and an outcome:ok,degraded, orfailed. Loading a language reportsready,unsupportedorfailed.degraded: that line and everything after it in the block stay plain, instead of continuing from a state that might be wrong. Shiki's high-level API doesn't report a timed-out line, so the interface tokenizes line by line through the grammar's owntokenizeLine2, which does.Bash,PowerShell) wins; otherwise the shell program the agent wrapped the command in (zsh -lc,bash -lc,powershell.exe -Command,pwsh,cmd /c,wsl.exe). This uses data the row already has; nothing new crosses the wire. It is not based on the host's operating system.source.vue, but the Vue grammar's root scope istext.html.vue, so stock Shiki never applied them. They are now added to the Vue grammar's own injections, which also works when another grammar (Markdown) referenced Vue before Vue loaded.Why
vscode-textmate: Shiki brings the bundled grammar catalogue with lazy loaders, embedded-language handling and theme resolution. It is pinned to exactly 4.5.0 because the tokenizing route uses Shiki'ssetTheme, which Shiki marks internal.Visual Proof
Hidden dev app on macOS, fresh isolated profile, a local stand-in agent (no real agent) that runs a PowerShell and a Bash command and then streams one reply with TypeScript, Python, Bash, Vue, PowerShell and an unknown-language (
zzlang) block. Rendered checks were driven by a separate non-Claude QA agent over the DevTools protocol.{{ }}, lightThe unknown-language block stays plain in both (visible at the bottom of the window shots).
Testing
Automated (new or updated):
withis a keyword again after it); per-theme formatting; Vue{{ }}and directive values on one line and several lines, with Markdown loaded first; a too-long line and a timed-out line degrade the rest of the document; a state taken before its grammar reloaded is not resumed; unknown language; aliases and letter case; retry after a pause; stop after 3 failed loads.\r\n/\n/lone\rsurvive; plus "every line after a skipped one stays plain".zsh -lc, argv arrays,wsl.exe, quotedpowershell.exe -Command,pwsh,cmd.exe /c, and unknown cases.Ran locally: web typecheck,
orca-ci-checks --no-typecheck(lint, code quality, localization), all native-chat tests (3,631), the syntax-highlighting tests and the editor's TextMate tests.Platforms: macOS only (hidden dev app). Not exercised in a packaged build, on Windows or Linux, or over SSH. The change is renderer-only, so SSH/remote sessions render the same transcript the same way.
Review
Agent skill upstream boundary
Notes
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)