Your own team of AI bots in one self-hosted binary: spaces, every account you have, handoffs, approvals and routines. Open-source, self-hosted alternative to Grok Bot, Claude Duet and OpenAI dots. Rust + React.
Rust ai-agentsai-assistantai-botautomationbotbots-teamchatbotclaude-duetgrokgrok-botgrok-bot-alternativeharnessllmmulti-agentopenai-dotsopenbotpersonal-agentrustself-hostedselfhosted-ai
Chat: a reply lands without a jump (16a) (#656)
Oleksandr Ivanchenko3b876b8d09e5
diff --git a/frontend/perf/stream/README.md b/frontend/perf/stream/README.mdindex 186f2c53..694b0041 100644--- a/frontend/perf/stream/README.md+++ b/frontend/perf/stream/README.md@@ -30,6 +30,8 @@ node perf/stream/run.mjs --n 30 --tokens 2000 --rate 50node perf/stream/run.mjs --n 300 --tokens 0 # 40 s idle: what the machine itself costsnode perf/stream/run.mjs --n 300 --width 390 --shot mid.png # screenshot at 60% of the streamnode perf/stream/run.mjs --n 300 --end-shot end.png --final-shot final.png # last token in, then the reply landed+node perf/stream/run.mjs --n 300 --width 390 --measure geo.json # the reply's box and blocks live vs landed (16a)+node perf/stream/run.mjs --n 300 --width 390 --message-html m.html # the landed reply's outerHTML, to diff the final render byte for byte (16a)```It needs `playwright-core` and a Chromium; point `PLAYWRIGHT_CORE` (path to its `index.mjs`) and `CHROMIUM`diff --git a/frontend/perf/stream/run.mjs b/frontend/perf/stream/run.mjsindex af0822b9..08f9eab4 100644--- a/frontend/perf/stream/run.mjs+++ b/frontend/perf/stream/run.mjs@@ -24,6 +24,10 @@ const LABEL = arg('label', '');// 15a: --end-shot after the last token (still streaming), --final-shot once the saved reply has landed.const END_SHOT = arg('end-shot', '');const FINAL_SHOT = arg('final-shot', '');+// 16a: --measure file.json writes the reply's geometry at the last token and once landed (bubble, blocks).+const MEASURE = arg('measure', '');+// 16a: --message-html file.html saves the landed message's HTML (the viewport shot depends on the scroll).+const MESSAGE_HTML = arg('message-html', '');const { chromium } = await import(process.env.PLAYWRIGHT_CORE ?? '/home/maus/work/iris-ft-shots/node_modules/playwright-core/index.mjs');const exe = process.env.CHROMIUM ?? '/home/maus/.cache/ms-playwright/chromium_headless_shell-1248/chrome-headless-shell-linux-arm64/chrome-headless-shell';@@ -130,12 +134,34 @@ const result = {};console.log(JSON.stringify(result));if (END_SHOT) await page.screenshot({ path: END_SHOT });-if (FINAL_SHOT) {+// The bubble's box and each text block's box relative to it: same x and heights live and landed = no shift, no re-wrap.+const geometry = (sel) =>+ page.evaluate((sel) => {+ const md = document.querySelector(sel);+ const bubble = md?.closest('[data-live-bubble-body]') ?? md?.parentElement;+ if (!bubble) return null;+ const b = bubble.getBoundingClientRect();+ const r = (n) => Math.round(n * 100) / 100;+ const blocks = [...bubble.querySelectorAll('p, li, h1, h2, h3, h4, pre, table, blockquote')].map((el) => {+ const e = el.getBoundingClientRect();+ return { tag: el.tagName.toLowerCase(), x: r(e.left), w: r(e.width), h: r(e.height), dy: r(e.top - b.top), lines: el.getClientRects().length };+ });+ return { bubble: { x: r(b.left), w: r(b.width), h: r(b.height) }, text: blocks[0] ? { x: blocks[0].x } : null, blocks };+ }, sel);+const live = MEASURE ? await geometry('[data-live-bubble-body] .markdown-content') : null;+if (FINAL_SHOT || MEASURE || MESSAGE_HTML) {await page.evaluate(() => window.__harness.finish());await page.waitForSelector('[data-message-id="m-final"]', { timeout: 30000 });- await page.waitForFunction(() => !document.querySelector('[data-live-bubble-body]'), null, { timeout: 30000 }).catch(() => {});+ await page.waitForFunction(() => !document.querySelector('[data-live-bubble-body] .markdown-content'), null, { timeout: 30000 }).catch(() => {});await page.waitForTimeout(800);- await page.screenshot({ path: FINAL_SHOT });+ if (FINAL_SHOT) await page.screenshot({ path: FINAL_SHOT });+ if (MESSAGE_HTML) fs.writeFileSync(MESSAGE_HTML, await page.locator('[data-message-id="m-final"]').evaluate((el) => el.outerHTML));+}+if (MEASURE) {+ const landed = await geometry('[data-message-id="m-final"] .markdown-content');+ const same = !!live && !!landed && live.blocks.length === landed.blocks.length;+ const moved = same ? live.blocks.filter((l, i) => ['x', 'w', 'h', 'dy'].some((k) => l[k] !== landed.blocks[i][k])).length : null;+ fs.writeFileSync(MEASURE, JSON.stringify({ width: WIDTH, label: LABEL, live, landed, blocksMoved: moved }, null, 1));}await browser.close();server.close();diff --git a/frontend/src/App.tsx b/frontend/src/App.tsxindex 617a0f67..4d66cb8b 100644--- a/frontend/src/App.tsx+++ b/frontend/src/App.tsx@@ -290,9 +290,9 @@ export const SpaceApp: React.FC<SpaceAppProps> = ({// What the open chat is streaming; other chats' streams are kept in streamsRef until opened.// The open chat's streaming reply (14b): a store only the live reply subscribes to, not App state, so a// token never re-renders the app or the finished messages. Updates land once per frame, with one blip.- const streamStore = useMemo(- () => createStreamText({}, { onFrame: (prev, next) => next.text !== prev.text && playSfx('blip') }),- [],+ // useState, not useMemo: React may drop a memo, and the store must live as long as the app (#642 QA).+ const [streamStore] = useState(() =>+ createStreamText({}, { onFrame: (prev, next) => next.text !== prev.text && playSfx('blip') }),);const streamsRef = useRef<Record<string, { text: string; thinking: string }>>({});// Running turns' live steps by turn id (with the chat they belong to), until the saved reply shows.diff --git a/frontend/src/components/ChatView.tsx b/frontend/src/components/ChatView.tsxindex c365ae81..22175c1b 100644--- a/frontend/src/components/ChatView.tsx+++ b/frontend/src/components/ChatView.tsx@@ -205,6 +205,13 @@ export interface RoutingState {basis?: string;}+// One reply row geometry, shared by the live row and the finished one (16a), so a reply lands without a shift:+// a 36 px avatar column from sm up, a 20 px avatar in the name line on phones, and the same bubble padding.+const REPLY_AVATAR = 36;+const REPLY_AVATAR_PHONE = 20;+const REPLY_BUBBLE = 'px-3.5 py-3 sm:p-5 rounded-2xl text-sm leading-relaxed shadow-sm w-full';+const REPLY_BUBBLE_BOT = 'bg-zinc-900/60 text-zinc-200 rounded-tl-sm border border-zinc-800/80';+export interface ChatViewProps {/** H3: a line under the person's held message ("Waiting for Juno: …", Try again), by message id. */heldNotes?: Record<string, React.ReactNode>;@@ -759,6 +766,8 @@ export const ChatView: React.FC<ChatViewProps> = ({if (liveTurnId) setTrailFrom(null);}, [liveTurnId]);const liveSpeaker = streamingSpeakerName || title;+ // Who the live row shows: the current speaker in a discussion, else the replying bot.+ const liveName = discussionState?.inProgress && discussionState.currentSpeaker ? discussionState.currentSpeaker : liveSpeaker;const livePages = useMemo(() => pagesOfReply(liveActivity?.steps), [liveActivity?.steps]);const savedTrail = useMemo((): { id: string; bot: string; pages: ReplyPage[] } | null => {const from = (m: ChatMessage) => {@@ -896,10 +905,10 @@ export const ChatView: React.FC<ChatViewProps> = ({useLayoutEffect(() => {if (!streamProp) propStream.show({ text: streamingTextProp, thinking: streamingThinkingProp });}, [streamProp, propStream, streamingTextProp, streamingThinkingProp]);- // From here on these only say whether the reply has words (a thinking line) yet; they flip once per reply.+ // Whether the reply is writing (has words) or thinking (has a thinking line) yet; each flips once per reply.// The words themselves reach StreamPart alone.- const streamingText = useStreamWriting(stream) || (!streamProp && !!streamingTextProp);- const streamingThinking = useStreamThinking(stream) || (!streamProp && !!streamingThinkingProp);+ const writing = useStreamWriting(stream) || (!streamProp && !!streamingTextProp);+ const thinking = useStreamThinking(stream) || (!streamProp && !!streamingThinkingProp);const lastScrollTopRef = useRef(0);// The empty chat's home opens at its top: on a phone a team home is taller than the screen, and its faces come first (13d).const homeShowingRef = useRef(false);@@ -934,7 +943,7 @@ export const ChatView: React.FC<ChatViewProps> = ({// (`phone` is the A1 PHONE_QUERY flag above).const stripWaitsOn = isStreaming ? waitingOn({ live: liveActivity, queued: !!queued, awaitingAnswer: !!awaitingAnswer, awaitingBrowser: !!awaitingBrowser }) : null;// What the live bubble holds before its first words: a pending approval reads as "waiting for your OK", not loading.- const bubble = liveBubble({ live: liveActivity, queued: !!queued, awaitingAnswer: !!awaitingAnswer, awaitingBrowser: !!awaitingBrowser, writing: streamingText });+ const bubble = liveBubble({ live: liveActivity, queued: !!queued, awaitingAnswer: !!awaitingAnswer, awaitingBrowser: !!awaitingBrowser, writing });// The strip's "Answer ↑": the open question card, else the approval card, fully in view.const showWaitingCard = (on: 'question' | 'approval') => {if (on === 'approval') return showApproval();@@ -954,7 +963,7 @@ export const ChatView: React.FC<ChatViewProps> = ({awaitingBrowser: !!awaitingBrowser,approvalOpen: pendingApprovals.length > 0,queued: !!queued,- writing: streamingText,+ writing,});// Team words ("Stop team", the rail) only for a team turn; a single bot asking in a channel gets "Stop".const teamChat = isTeamTurn(home?.kind, !!discussionState?.inProgress);@@ -981,7 +990,7 @@ export const ChatView: React.FC<ChatViewProps> = ({queued={!!queued}awaitingAnswer={!!awaitingAnswer}awaitingBrowser={!!awaitingBrowser}- writing={streamingText}+ writing={writing}onAnswer={showWaitingCard}onWatch={onWatchBrowser && !vmOpen ? onWatchBrowser : undefined}phone={phone}@@ -1032,7 +1041,7 @@ export const ChatView: React.FC<ChatViewProps> = ({useEffect(() => {if (scrollRef.current && stickRef.current) pinToBottom(scrollRef.current);checkApprovalVisible();- }, [messages, streamingText, streamingThinking, approvalKey, routingState, queued, contextKey]);+ }, [messages, writing, thinking, approvalKey, routingState, queued, contextKey]);// Each streamed update (at most one a frame) keeps the bottom pinned while the person follows the chat.const onStreamGrowRef = useRef(() => {});onStreamGrowRef.current = () => {@@ -1766,7 +1775,7 @@ export const ChatView: React.FC<ChatViewProps> = ({<ModernAvatarrole={isUser ? 'user' : title}name={displayName}- size={36}+ size={REPLY_AVATAR}kwantId={replyKwantId}modelBadge={false}/>@@ -1788,7 +1797,7 @@ export const ChatView: React.FC<ChatViewProps> = ({name={displayName}at={msg.created_at}sentToTelegram={sentToTelegram(parseMetaObject(msg.meta))}- avatar={<span className={routed && freshTrack.current.fresh.has(msg.id) ? 'kws-handoff inline-flex' : 'inline-flex'}><ModernAvatar role={title} name={displayName} size={20} kwantId={replyKwantId} modelBadge={false} /></span>}+ avatar={<span className={routed && freshTrack.current.fresh.has(msg.id) ? 'kws-handoff inline-flex' : 'inline-flex'}><ModernAvatar role={title} name={displayName} size={REPLY_AVATAR_PHONE} kwantId={replyKwantId} modelBadge={false} /></span>}ranOn={ranOn}account={account}tokens={tokens}@@ -1866,12 +1875,12 @@ export const ChatView: React.FC<ChatViewProps> = ({return more ? <div className="absolute right-full bottom-0 mr-1" data-message-more-gutter="">{more}</div> : null;})()}<div- className={`px-3.5 py-3 sm:p-5 rounded-2xl text-sm leading-relaxed shadow-sm w-full ${+ className={`${REPLY_BUBBLE} ${isUser? 'bg-zinc-800 text-zinc-100 rounded-tr-sm border border-zinc-700/60 max-w-2xl': workAhead? 'bg-indigo-950/15 text-zinc-200 rounded-tl-sm border border-dashed border-indigo-400/25'- : 'bg-zinc-900/60 text-zinc-200 rounded-tl-sm border border-zinc-800/80'+ : REPLY_BUBBLE_BOT}`}data-work-ahead={workAhead ? '' : undefined}>@@ -2466,27 +2475,17 @@ export const ChatView: React.FC<ChatViewProps> = ({{/* Live Streaming Assistant Message (or its place in the queue, in the same frame) */}{isStreaming && !deciding && routingState?.phase !== 'deciding' && !askOnly && (- <div className="flex items-start gap-3.5 w-full max-w-5xl">- <ModernAvatar- role={- discussionState?.inProgress && discussionState.currentSpeaker- ? discussionState.currentSpeaker- : streamingSpeakerName || title- }- name={- discussionState?.inProgress && discussionState.currentSpeaker- ? discussionState.currentSpeaker- : streamingSpeakerName || title- }- size={34}- />+ <div className="flex items-start gap-3.5 w-full max-w-5xl" data-live-row="">+ {/* The finished reply's geometry (16a): avatar column from sm up, in the name line on phones */}+ <span className="hidden sm:contents">+ <ModernAvatar role={liveName} name={liveName} size={REPLY_AVATAR} />+ </span><div className="flex flex-col items-start min-w-0 flex-1 max-w-4xl"><div className="flex items-center gap-2 mb-1.5 text-[11px] text-zinc-400 font-medium">- <span className="text-zinc-200">- {discussionState?.inProgress && discussionState.currentSpeaker- ? discussionState.currentSpeaker- : streamingSpeakerName || title}+ <span className="sm:hidden shrink-0 inline-flex">+ <ModernAvatar role={liveName} name={liveName} size={REPLY_AVATAR_PHONE} /></span>+ <span className="text-zinc-200">{liveName}</span>{queued ? (<span className="inline-flex items-center gap-1 text-zinc-400 text-[10px]"><span className="w-1.5 h-1.5 rounded-full bg-zinc-500" aria-hidden="true" />@@ -2520,7 +2519,7 @@ export const ChatView: React.FC<ChatViewProps> = ({/>)}- {streamingThinking && (+ {thinking && (<div className="mb-2 p-2.5 rounded-xl bg-violet-950/20 border border-violet-500/20 text-xs text-violet-300/90 flex items-center gap-2 animate-pulse motion-reduce:animate-none max-w-full"><Sparkles size={13} className="text-violet-400 flex-shrink-0" /><span className="truncate"><StreamPart stream={stream} part="thinking" onGrow={onStreamGrow} /></span>@@ -2528,14 +2527,14 @@ export const ChatView: React.FC<ChatViewProps> = ({)}{/* On a phone the strip says "working" and "waiting": no skeleton, no "Paused on…" bubble. */}- {(!phone || queued || streamingText) && (- <div className="p-4 sm:p-5 min-h-[3.5rem] rounded-2xl rounded-tl-sm bg-zinc-900/60 text-zinc-200 border border-zinc-800/80 text-sm leading-relaxed shadow-sm w-full" data-live-bubble-body="">+ {(!phone || queued || writing) && (+ <div className={`${REPLY_BUBBLE} min-h-[3.5rem] ${REPLY_BUBBLE_BOT}`} data-live-bubble-body="">{queued ? (<p className="text-zinc-300" role="status">{queued.position ? <strong className="font-medium text-zinc-100">#{queued.position} in line.</strong> : <strong className="font-medium text-zinc-100">In line.</strong>}{' '}{queuedText(queued.reason, queued.slots)}</p>- ) : streamingText ? (+ ) : writing ? (/* The scene's 62 px holds under the first words (kw-wa-hold, in StreamPart), so the bubble does not jump; they fade in once. */<StreamPart stream={stream} part="text" onGrow={onStreamGrow} />) : awaitingAnswer ? (diff --git a/frontend/src/components/MarkdownRenderer.tsx b/frontend/src/components/MarkdownRenderer.tsxindex 1948a36a..37b88cde 100644--- a/frontend/src/components/MarkdownRenderer.tsx+++ b/frontend/src/components/MarkdownRenderer.tsx@@ -112,6 +112,38 @@ const isTaskItem = (n: HastNode | undefined) => hasClass(n, 'task-list-item');const checkClass = 'mt-[5px] h-3.5 w-3.5 shrink-0 rounded-sm accent-sky-500';+// The typing cursor (16a): at the end of the last line of text, so the reply doesn't lose a line when it lands.+const cursorClass = ['inline-block', 'w-1.5', 'h-4', 'ml-0.5', 'align-middle', 'bg-sky-400', 'animate-pulse', 'motion-reduce:animate-none', 'rounded-sm'];+const INLINE_END = new Set(['p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6']);+const lastElement = (n: HastNode) => {+ const kids = n.children ?? [];+ for (let i = kids.length - 1; i >= 0; i--) {+ const k = kids[i];+ if (k.type === 'element') return k;+ if (k.type !== 'text' || (k.value ?? '').trim()) return null; // text after the last element: it ends there+ }+ return null;+};+/** The node to end with the cursor: the last paragraph or heading, or the last list item's last line. */+function cursorHost(block: HastNode | null): HastNode | null {+ if (!block) return null;+ if (INLINE_END.has(block.tagName ?? '')) return block;+ if (block.tagName === 'ul' || block.tagName === 'ol') return cursorHost(lastElement(block));+ if (block.tagName !== 'li') return null;+ const last = lastElement(block);+ if (!last) return block; // a tight item: its text is the last line+ if (last.tagName === 'p' || last.tagName === 'ul' || last.tagName === 'ol') return cursorHost(last);+ // A task item's box, or inline markup (a link, bold) closing the line+ if (!['pre', 'table', 'blockquote', 'hr', 'div'].includes(last.tagName ?? '')) return block;+ return null;+}+/** Appends the cursor inside the last text block; after a code block, table or quote it keeps its own line. */+const rehypeCursor = () => (tree: HastNode) => {+ const cursor: HastNode = { type: 'element', tagName: 'span', properties: { className: cursorClass, ariaHidden: 'true' }, children: [] };+ const host = cursorHost(lastElement(tree)) ?? tree;+ (host.children ??= []).push(cursor);+};+/** A task item's content without its checkbox or the space after it. */function taskContent(children: React.ReactNode): React.ReactNode[] {const out = React.Children.toArray(children).filter((c) => !(React.isValidElement(c) && tagOf(c as MdElement) === 'input'));@@ -191,7 +223,13 @@ export const MarkdownRenderer = React.memo(function MarkdownRenderer({<ReactMarkdownremarkPlugins={[remarkGfm]}urlTransform={urlTransform}- rehypePlugins={smart ? [rehypeSmartIndex as never, ...(section ? [rehypeSmartSection(content, results) as never] : [])] : undefined}+ rehypePlugins={+ smart+ ? [rehypeSmartIndex as never, ...(section ? [rehypeSmartSection(content, results) as never] : [])]+ : cursor+ ? [rehypeCursor as never]+ : undefined+ }components={{// Pre element pass-through to let CodeBlock handle layoutpre: ({ children }) => <>{children}</>,@@ -323,10 +361,10 @@ export const MarkdownRenderer = React.memo(function MarkdownRenderer({);return listView(node as HastNode | undefined, children, plain);},- ol: ({ node, children }) => {+ ol: ({ node, children, start }) => {const task = hasClass(node as HastNode | undefined, 'contains-task-list');const plain = (- <ol className={`${task ? 'list-none pl-1' : 'list-decimal list-outside pl-5'} my-2.5 space-y-1 text-zinc-300`}>+ <ol start={start} className={`${task ? 'list-none pl-1' : 'list-decimal list-outside pl-5'} my-2.5 space-y-1 text-zinc-300`}>{children}</ol>);@@ -386,9 +424,6 @@ export const MarkdownRenderer = React.memo(function MarkdownRenderer({/>)}- {cursor && (- <span className="inline-block w-1.5 h-4 ml-0.5 align-middle bg-sky-400 animate-pulse rounded-sm" />- )}</div></ReplyText.Provider>);diff --git a/frontend/tests/modelBadge.test.mjs b/frontend/tests/modelBadge.test.mjsindex b07eb28c..acc2a365 100644--- a/frontend/tests/modelBadge.test.mjs+++ b/frontend/tests/modelBadge.test.mjs@@ -237,7 +237,8 @@ test('hidden under 24 px, and on reply avatars in the chat', () => {draw({ size: 32, kwantId: undefined });assert.equal(badge(), null, 'no bot, no badge');const chat = readFileSync(new URL('../src/components/ChatView.tsx', import.meta.url), 'utf8');- assert.match(chat, /size=\{20\} kwantId=\{replyKwantId\} modelBadge=\{false\}/);+ assert.match(chat, /const REPLY_AVATAR_PHONE = 20;/);+ assert.match(chat, /size=\{REPLY_AVATAR_PHONE\} kwantId=\{replyKwantId\} modelBadge=\{false\}/);// Every reply avatar with a bot id (the 36 px one beside each message too) opts out: the ran-on line names the model.const replyAvatars = chat.match(/kwantId=\{replyKwantId\}[^/>]*/g) ?? [];assert.ok(replyAvatars.length >= 2);diff --git a/frontend/tests/replyLandsStill.test.mjs b/frontend/tests/replyLandsStill.test.mjsnew file mode 100644index 00000000..472b1bde--- /dev/null+++ b/frontend/tests/replyLandsStill.test.mjs@@ -0,0 +1,88 @@+// 16a reply-lands-still: the live reply row has the finished row's geometry, the typing cursor ends the last+// line of text (its own line after a code block, table or quote), and an ordered list keeps its start number.+import assert from 'node:assert/strict';+import test from 'node:test';+import { readFileSync } from 'node:fs';+import { JSDOM } from 'jsdom';+import { loadBundled } from './bundle.mjs';++const dom = new JSDOM('<!doctype html><html><body></body></html>', { url: 'http://localhost/' });+for (const k of ['window', 'document', 'navigator', 'HTMLElement', 'Element', 'Node', 'localStorage', 'sessionStorage']) {+ Object.defineProperty(globalThis, k, { value: dom.window[k], configurable: true, writable: true });+}++const m = await loadBundled(`+ export { default as React } from 'react';+ export { renderToStaticMarkup } from 'react-dom/server.browser';+ export { MarkdownRenderer } from './src/components/MarkdownRenderer';+`);+const { React, renderToStaticMarkup, MarkdownRenderer } = m;+const h = React.createElement;+// The HTML with the newlines between tags dropped.+const html = (content, props = {}) => renderToStaticMarkup(h(MarkdownRenderer, { content, ...props })).replace(/>\s+</g, '><');+const live = (content) => html(content, { isStreaming: true });+const CURSOR = '<span class="inline-block w-1.5 h-4 ml-0.5 align-middle bg-sky-400 animate-pulse motion-reduce:animate-none rounded-sm" aria-hidden="true"></span>';+const count = (s, sub) => s.split(sub).length - 1;++test('the cursor ends the last paragraph, not a line of its own', () => {+ const out = live('First.\n\nThe last line is still');+ assert.equal(count(out, CURSOR), 1);+ assert.ok(out.includes(`The last line is still${CURSOR}</p></div>`), out);+});++test('the cursor ends the last list item (tight, loose, nested, task, ordered)', () => {+ assert.ok(live('- one\n- two is still').includes(`two is still${CURSOR}</li>`));+ assert.ok(live('- one\n\n- two is still').includes(`two is still${CURSOR}</p>`));+ assert.ok(live('1. one\n - inner is still').includes(`inner is still${CURSOR}</li></ul>`));+ assert.ok(live('- [ ] one\n- [x] two is still').includes(`two is still${CURSOR}</span></li>`));+ assert.ok(live('- one **bold**').includes(`<strong class="font-semibold text-zinc-100">bold</strong>${CURSOR}</li>`));+});++test('the cursor ends a heading', () => {+ assert.ok(live('## Plan so').includes(`Plan so${CURSOR}</h2>`));+});++test('after a fenced code block, a table or a quote the cursor keeps its own line', () => {+ for (const md of ['Run:\n\n```sh\nls -la\n```', '| a | b |\n|---|---|\n| 1 | 2 |', '> quoted line', '- item\n\n ```\n code\n ```']) {+ const out = live(md);+ assert.equal(count(out, CURSOR), 1, md);+ assert.ok(out.endsWith(`${CURSOR}</div>`), `own line after:\n${md}\n${out}`);+ }+ // An empty reply still shows the cursor.+ assert.equal(live(''), `<div class="markdown-content text-sm leading-relaxed text-zinc-200 ">${CURSOR}</div>`);+});++test('no cursor in a finished message or a finished block', () => {+ assert.equal(count(html('Done.\n\n- a\n- b'), 'animate-pulse'), 0);+ assert.equal(count(html('Done.', { isStreaming: true, cursor: false }), 'animate-pulse'), 0);+});++test('an ordered list keeps its start number; a list from 1 renders as before', () => {+ assert.match(html('3. three\n4. four'), /<ol start="3" class="list-decimal/);+ assert.match(html('1. one\n2. two'), /<ol class="list-decimal/);+ assert.match(live('5. five'), /<ol start="5" class="list-decimal/);+});++test('the live row and the finished row share one geometry', () => {+ const chat = readFileSync(new URL('../src/components/ChatView.tsx', import.meta.url), 'utf8');+ // One avatar size, one bubble padding: both rows read the same constants.+ assert.match(chat, /const REPLY_AVATAR = 36;/);+ assert.match(chat, /const REPLY_AVATAR_PHONE = 20;/);+ assert.match(chat, /const REPLY_BUBBLE = 'px-3\.5 py-3 sm:p-5 rounded-2xl text-sm leading-relaxed shadow-sm w-full';/);+ const liveRow = chat.slice(chat.indexOf('data-live-row=""'), chat.indexOf('data-live-bubble-body=""') + 30);+ assert.match(liveRow, /<span className="hidden sm:contents">\s+<ModernAvatar role=\{liveName\} name=\{liveName\} size=\{REPLY_AVATAR\} \/>/);+ assert.match(liveRow, /<span className="sm:hidden shrink-0 inline-flex">\s+<ModernAvatar role=\{liveName\} name=\{liveName\} size=\{REPLY_AVATAR_PHONE\} \/>/);+ assert.match(liveRow, /className=\{`\$\{REPLY_BUBBLE\} min-h-\[3\.5rem\] \$\{REPLY_BUBBLE_BOT\}`\} data-live-bubble-body=""/);+ assert.doesNotMatch(liveRow, /size=\{34\}|p-4 sm:p-5/);+ // The finished row uses the same strings.+ assert.match(chat, /size=\{REPLY_AVATAR\}\s+kwantId=\{replyKwantId\}/);+ assert.match(chat, /size=\{REPLY_AVATAR_PHONE\} kwantId=\{replyKwantId\}/);+ assert.match(chat, /className=\{`\$\{REPLY_BUBBLE\} \$\{\s+isUser/);+ assert.match(chat, /: REPLY_BUBBLE_BOT\s+\}`\}/);+});++test('the stream store lives as long as the app (useState, not useMemo)', () => {+ const app = readFileSync(new URL('../src/App.tsx', import.meta.url), 'utf8');+ assert.match(app, /const \[streamStore\] = useState\(\(\) =>\s+createStreamText\(/);+ assert.doesNotMatch(app, /streamStore = useMemo/);+});diff --git a/frontend/tests/workingAvatar.test.mjs b/frontend/tests/workingAvatar.test.mjsindex 7cd7d2df..bb9b48b4 100644--- a/frontend/tests/workingAvatar.test.mjs+++ b/frontend/tests/workingAvatar.test.mjs@@ -61,7 +61,7 @@ test('queued and paused bubbles keep their text and do not hold the scene height'Paused on the approval below. Allow or deny it there; this reply carries on from it.',]) assert.ok(chat.includes(s), s);assert.equal((chat.match(/kw-wa-hold/g) ?? []).length, 2, 'only the first-words wrapper (and its comment) name the hold');- assert.match(chat, /\{\(!phone \|\| queued \|\| streamingText\) && \(/, 'phones keep the strip, no bubble');+ assert.match(chat, /\{\(!phone \|\| queued \|\| writing\) && \(/, 'phones keep the strip, no bubble');});test('motion is CSS keyframes on transform and opacity only, no JS timers, a 2.4 s loop', () => {