From f90647ea8ef08f9bbe42217c84b79c7dd31b4b4c Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Sat, 21 Mar 2026 10:46:01 +0100 Subject: [PATCH] fix(coding-agent): disable cli-highlight auto-detection for languageless code blocks cli-highlight's auto-detection misidentifies prose as AppleScript, LiveCodeServer, etc., coloring random English words (if, but, and, the, that, is) as keywords. This happens when code blocks have no language specified: fenced blocks without a language tag, indented code blocks, or unclosed fences during streaming. Skip auto-detection entirely and apply plain mdCodeBlock styling instead. --- .../src/modes/interactive/theme/theme.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/coding-agent/src/modes/interactive/theme/theme.ts b/packages/coding-agent/src/modes/interactive/theme/theme.ts index 757d99b4..f83894f1 100644 --- a/packages/coding-agent/src/modes/interactive/theme/theme.ts +++ b/packages/coding-agent/src/modes/interactive/theme/theme.ts @@ -978,6 +978,12 @@ function getCliHighlightTheme(t: Theme): CliHighlightTheme { export function highlightCode(code: string, lang?: string): string[] { // Validate language before highlighting to avoid stderr spam from cli-highlight const validLang = lang && supportsLanguage(lang) ? lang : undefined; + // Skip highlighting when no valid language is specified. cli-highlight's + // auto-detection is unreliable and can misidentify prose as AppleScript, + // LiveCodeServer, etc., coloring random English words as keywords. + if (!validLang) { + return code.split("\n").map((line) => theme.fg("mdCodeBlock", line)); + } const opts = { language: validLang, ignoreIllegals: true, @@ -1080,6 +1086,12 @@ export function getMarkdownTheme(): MarkdownTheme { highlightCode: (code: string, lang?: string): string[] => { // Validate language before highlighting to avoid stderr spam from cli-highlight const validLang = lang && supportsLanguage(lang) ? lang : undefined; + // Skip highlighting when no valid language is specified. cli-highlight's + // auto-detection is unreliable and can misidentify prose as AppleScript, + // LiveCodeServer, etc., coloring random English words as keywords. + if (!validLang) { + return code.split("\n").map((line) => theme.fg("mdCodeBlock", line)); + } const opts = { language: validLang, ignoreIllegals: true,