The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.
TypeScript agentai-chatai-studioall-in-onecoding-agentdesktop-appfluximage-generationlinuxllmlocal-ailocal-llmopen-sourceprivacyself-hostedstable-diffusionuncensoreduncensored-aivideo-generationwindows
fix(chat): a streaming answer shows no raw backtick or asterisks
purple3c3a0055c35b
diff --git a/src/components/chat/CodexView.tsx b/src/components/chat/CodexView.tsxindex 4e815433..e8121de0 100644--- a/src/components/chat/CodexView.tsx+++ b/src/components/chat/CodexView.tsx@@ -10,6 +10,7 @@ import { ToolCallBand } from './ToolCallBand'import { groupAgentBlocks } from '../../lib/tool-call-groups'import { ThinkingBlock } from './ThinkingBlock'import { MarkdownRenderer } from './MarkdownRenderer'+import { closeOpenMarkdown } from '../../lib/streaming-markdown'import { TokenCounter } from './TokenCounter'import { ContextDropdown } from './ContextDropdown'import { SmallModelModeToggle } from './SmallModelModeToggle'@@ -445,6 +446,9 @@ export function CodexView() {)}{(() => {const running = codexGenerating && msg.id === messages[messages.length - 1]?.id+ // While this message streams, an open ` or ** is closed+ // for the frame (lib/streaming-markdown.ts).+ const shown = (text: string) => (running ? closeOpenMarkdown(text) : text)const hasBlocks = !!(msg.role === 'assistant' && msg.agentBlocks && msg.agentBlocks.length > 0)const stepCount = msg.agentBlocks?.filter((b) => b.phase === 'tool_call' && b.toolCall).length ?? 0const hasAnswerBlock = !!(msg.agentBlocks && msg.agentBlocks.some((b) => b.phase === 'answer' && b.content.trim()))@@ -541,7 +545,7 @@ export function CodexView() {return (<div key={block.id} className="px-1 py-0.5"><div className="text-[12px] leading-relaxed">- <MarkdownRenderer content={answer} />+ <MarkdownRenderer content={shown(answer)} /></div></div>)@@ -576,7 +580,7 @@ export function CodexView() {{msg.role === 'user' ? (<p className="text-gray-800 dark:text-gray-200 whitespace-pre-wrap">{cleanContent}</p>) : (- <MarkdownRenderer content={cleanContent} />+ <MarkdownRenderer content={shown(cleanContent)} />)}</div></div>@@ -641,7 +645,7 @@ export function CodexView() {{finalAnswerText && (<div className="px-1 py-0.5"><div className="text-[12px] leading-relaxed">- <MarkdownRenderer content={finalAnswerText} />+ <MarkdownRenderer content={shown(finalAnswerText)} /></div></div>)}diff --git a/src/components/chat/MessageBubble.tsx b/src/components/chat/MessageBubble.tsxindex 7294ef26..bf099ed4 100644--- a/src/components/chat/MessageBubble.tsx+++ b/src/components/chat/MessageBubble.tsx@@ -3,6 +3,7 @@ import { motion } from 'framer-motion'import { User, Copy, Check, Pencil, RefreshCw, X, Wrench, Trash2, Scissors, Unlink } from 'lucide-react'import { useState, useRef, useEffect, useMemo, memo } from 'react'import { MarkdownRenderer } from './MarkdownRenderer'+import { closeOpenMarkdown } from '../../lib/streaming-markdown'import { ThinkingBlock } from './ThinkingBlock'import { ToolCallBand } from './ToolCallBand'import { ReflectionBlock } from './ReflectionBlock'@@ -391,7 +392,7 @@ function MessageBubbleImpl({ message, onRegenerate, onEdit, pendingApprovalId, oreturn (<div key={block.id} className="px-1 py-0.5"><div className={'text-[0.8rem] leading-relaxed' + (isStreaming && istSchluss ? ' lu-caret' : '')}>- <MarkdownRenderer content={clean} />+ <MarkdownRenderer content={isStreaming && istSchluss ? closeOpenMarkdown(clean) : clean} /></div></div>)@@ -471,7 +472,9 @@ function MessageBubbleImpl({ message, onRegenerate, onEdit, pendingApprovalId, o// kein Zustand, kein Timer, keine Subscription, also auch// kein Rerender, den der Stream nicht ohnehin ausloest.<div className={'text-[0.78rem] leading-relaxed' + (isStreaming ? ' lu-caret' : '')}>- <MarkdownRenderer content={cleanContent} />+ {/* While it streams, an open ` or ** is closed for the frame+ (lib/streaming-markdown.ts); the stored text is untouched. */}+ <MarkdownRenderer content={isStreaming ? closeOpenMarkdown(cleanContent) : cleanContent} />{/* Cut-off marker: a turn the model did not finish on its ownterms (length budget / dropped connection). The benchmarkscreen has always flagged cut-offs; the chat did not, so adiff --git a/src/components/chat/__tests__/a-streaming-answer-shows-no-raw-marker.test.tsx b/src/components/chat/__tests__/a-streaming-answer-shows-no-raw-marker.test.tsxnew file mode 100644index 00000000..df473730--- /dev/null+++ b/src/components/chat/__tests__/a-streaming-answer-shows-no-raw-marker.test.tsx@@ -0,0 +1,37 @@+/**+ * @vitest-environment jsdom+ *+ * Gegenprobe 01.10.2026: "I created a file named `" stood with a raw backtick+ * while the answer streamed. While it streams, an open marker is closed for+ * the frame; a finished answer shows exactly what the model wrote.+ */+import { describe, it, expect, afterEach } from 'vitest'+import { createElement } from 'react'+import { render, cleanup } from '@testing-library/react'+import { MessageBubble } from '../MessageBubble'+import type { Message } from '../../../types/chat'++afterEach(() => cleanup())++const msg = (content: string): Message =>+ ({ id: 'm1', role: 'assistant', content, timestamp: 1 }) as Message++const bubble = (content: string, isStreaming: boolean) =>+ render(createElement(MessageBubble, { message: msg(content), isStreaming, isLast: true }))++describe('a streaming answer', () => {+ it('does not show the lone backtick at its end', () => {+ const { container } = bubble('I created a file named `', true)+ expect(container.querySelector('.markdown-content')?.textContent).not.toContain('`')+ })++ it('renders an open code span as code already', () => {+ const { container } = bubble('I created a file named `notes', true)+ expect(container.querySelector('.markdown-content code')?.textContent).toBe('notes')+ })++ it('a finished answer is left exactly as written', () => {+ const { container } = bubble('A lone ` stays', false)+ expect(container.querySelector('.markdown-content')?.textContent).toContain('`')+ })+})diff --git a/src/lib/__tests__/streaming-markdown.test.ts b/src/lib/__tests__/streaming-markdown.test.tsnew file mode 100644index 00000000..d1031c53--- /dev/null+++ b/src/lib/__tests__/streaming-markdown.test.ts@@ -0,0 +1,48 @@+/**+ * Gegenprobe 01.10.2026: "I created a file named `" stood with a raw backtick+ * for a second while the answer streamed. Only the frame on screen is fixed;+ * the finished answer is what the model wrote.+ *+ * Run: npx vitest run src/lib/__tests__/streaming-markdown.test.ts+ */+import { describe, it, expect } from 'vitest'+import { closeOpenMarkdown } from '../streaming-markdown'++describe('markdown still arriving', () => {+ it('the box case: a lone opening backtick at the end is left out', () => {+ expect(closeOpenMarkdown('I created a file named `')).toBe('I created a file named ')+ })++ it('an open code span is closed, so it renders as code already', () => {+ expect(closeOpenMarkdown('I created a file named `notes')).toBe('I created a file named `notes`')+ })++ it('an open bold run is closed, a bare opener at the end is left out', () => {+ expect(closeOpenMarkdown('This is **important')).toBe('This is **important**')+ expect(closeOpenMarkdown('This is **')).toBe('This is ')+ })++ it('balanced text is untouched', () => {+ const t = 'Use `npm test` and **then** commit.'+ expect(closeOpenMarkdown(t)).toBe(t)+ })++ it('only the paragraph being written counts', () => {+ const t = 'A finished `odd paragraph\n\nNow `notes'+ expect(closeOpenMarkdown(t)).toBe('A finished `odd paragraph\n\nNow `notes`')+ })++ it('inside an open fence nothing is touched', () => {+ const t = 'Here:\n```ts\nconst a = `x'+ expect(closeOpenMarkdown(t)).toBe(t)+ })++ it('after a closed fence the new paragraph is handled', () => {+ expect(closeOpenMarkdown('```\ncode `\n```\nThen `x')).toBe('```\ncode `\n```\nThen `x`')+ })++ it('asterisks inside code do not count as bold', () => {+ const t = 'Run `a ** b` now'+ expect(closeOpenMarkdown(t)).toBe(t)+ })+})diff --git a/src/lib/streaming-markdown.ts b/src/lib/streaming-markdown.tsnew file mode 100644index 00000000..2c1e4110--- /dev/null+++ b/src/lib/streaming-markdown.ts@@ -0,0 +1,60 @@+/**+ * Markdown that is still arriving, made presentable for the frame it is shown.+ *+ * Gegenprobe 01.10.2026: for a second the answer read "I created a file named `"+ * with a raw backtick, until the closing one arrived. An open inline code span+ * or an open bold run shows its marker as text until the model closes it.+ * While the answer streams, this closes them for display: the opened span+ * renders as what it will become, and an opener with nothing after it yet is+ * left out for that frame. The stored message is never touched; the finished+ * answer renders exactly what the model wrote.+ *+ * Fenced code needs nothing: an unclosed fence already renders as a code block+ * to the end, and nothing inside it is touched here.+ */++const FENCE = /^ {0,3}(`{3,}|~{3,})/++/** The paragraph still being written, or null when it sits inside an open fence. */+function openParagraph(text: string): { head: string; tail: string } | null {+ const lines = text.split('\n')+ let fence: string | null = null+ let start = 0+ for (let i = 0; i < lines.length; i++) {+ const m = FENCE.exec(lines[i])+ if (fence) {+ if (m && m[1][0] === fence[0] && m[1].length >= fence.length) { fence = null; start = i + 1 }+ continue+ }+ if (m) { fence = m[1]; continue }+ if (!lines[i].trim()) start = i + 1+ }+ if (fence) return null+ const head = lines.slice(0, start).join('\n')+ return { head: start > 0 ? head + '\n' : '', tail: lines.slice(start).join('\n') }+}++function closeInlineCode(tail: string): string {+ const runs = tail.match(/`+/g) ?? []+ // Spans pair by equal run length; only the plain single backtick is ever+ // left open in practice, longer runs are rare enough to leave alone.+ const singles = runs.filter((r) => r === '`').length+ if (singles % 2 === 0) return tail+ if (tail.endsWith('`') && !tail.endsWith('``')) return tail.slice(0, -1)+ return tail + '`'+}++function closeBold(tail: string): string {+ // Code spans carry their own asterisks; they do not count.+ const outsideCode = tail.replace(/`[^`]*`/g, '')+ const runs = outsideCode.match(/\*\*/g) ?? []+ if (runs.length % 2 === 0) return tail+ if (tail.endsWith('**')) return tail.slice(0, -2)+ return tail + '**'+}++export function closeOpenMarkdown(text: string): string {+ const part = openParagraph(text)+ if (!part || !part.tail) return text+ return part.head + closeBold(closeInlineCode(part.tail))+}