Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.
C++
Answers: reasoning wrapper tags and a stray leading tag fragment never show in the answer or the Markdown export (UI side only)
Niko1221f4078faf4f74
diff --git a/apps/host/src/lib/answer-text.ts b/apps/host/src/lib/answer-text.tsnew file mode 100644index 000000000..6689f289c--- /dev/null+++ b/apps/host/src/lib/answer-text.ts@@ -0,0 +1,33 @@+/**+ * Keeps markup that belongs to the model's reasoning, not to the answer, out of the answer text (QA report F01: a literal "<analysis>" with+ * reasoning Off, and a "p> " in front of a short answer, also in the Markdown export).+ *+ * This only removes the wrapper itself, never the words around it, and only for names the reasoning formats use. The words stay, so a model that+ * answers inside such a tag still shows its answer. If the raw text of a model really holds these, that is the engine's output and is reported+ * there: this is not a fix for it, only a guard so the page never shows a wrapper to a person.+ *+ * Streaming: the page calls this with everything received so far, plus the next piece, every time, so it is cheap and leaves a tag that has not+ * arrived completely yet alone (it is removed when the rest arrives).+ */+const WRAPPER = '(?:think|thinking|thought|analysis|reasoning)';+/** <think>, </think>, <analysis ...> : one reasoning wrapper tag, open or close. */+const TAG = new RegExp(`</?${WRAPPER}(?:\\s[^<>]*)?/?>`, 'gi');+/**+ * A tag that lost its "<" at the very start of the answer ("p> CEDAR-742", "/p> done"): only well-known markup names, only at the start.+ * The text after it (and the single space that follows) is kept.+ */+const LOST_LEAD = /^\s*\/?(?:p|br|div|span|li|ul|ol|h[1-6]|b|i|em|strong|code|pre|answer|reply|final|analysis|think|thinking|reasoning)>[ \t]+/i;++/** The answer with reasoning wrapper tags and a stray leading tag fragment removed. Anything else is returned unchanged. */+export function tidyAnswer(text: string): string {+ if (!text) return text;+ let out = text;+ if (out.indexOf('>') !== -1) {+ out = out.replace(TAG, '');+ out = out.replace(LOST_LEAD, '');+ }+ return out;+}++/** True when `tidyAnswer` would change nothing, so a caller can skip a copy. */+export const isTidy = (text: string) => tidyAnswer(text) === text;diff --git a/apps/host/src/lib/deliverables.ts b/apps/host/src/lib/deliverables.tsindex 40295a870..a6c14aca7 100644--- a/apps/host/src/lib/deliverables.ts+++ b/apps/host/src/lib/deliverables.ts@@ -1,5 +1,6 @@import { api } from './client';import type { PreviewArtifact } from './artifacts';+import { tidyAnswer } from './answer-text';/*** Deliverables and grouped activity (notes-split-agent8.md, item 12). The host sends `deliverable` frames for every file the assistant wrote or@@ -50,8 +51,8 @@ export function readSkills(raw: unknown): { name: string; description: string }[/** Add streamed text to the reply's ordered pieces: it continues the last text piece, or starts a new one after an activity line. */export function appendText(blocks: MessageBlock[] | undefined, text: string): MessageBlock[] {const list = blocks ?? [], last = list.at(-1);- if (last?.kind === 'text') return [...list.slice(0, -1), { kind: 'text', text: last.text + text }];- return [...list, { kind: 'text', text }];+ if (last?.kind === 'text') return [...list.slice(0, -1), { kind: 'text', text: tidyAnswer(last.text + text) }];+ return [...list, { kind: 'text', text: tidyAnswer(text) }];}/** A group frame is re-sent while it grows: the same id replaces its line; a new id goes after what came before. */diff --git a/apps/host/src/lib/store.ts b/apps/host/src/lib/store.tsindex 9899b80c9..e18085d19 100644--- a/apps/host/src/lib/store.ts+++ b/apps/host/src/lib/store.ts@@ -4,6 +4,7 @@ import { updateAgent } from './agents';import { LOOP_MAX_RUNS, LOOP_USAGE, loopEvery, parseLoop, type LoopCommand } from './loop';import { applyStatusFrame, clearStatus } from './live-status';import { applyGoalFrame } from './goal';+import { tidyAnswer } from './answer-text';import { appendText, mergeDeliverable, readDeliverable, readGroup, readSkills, upsertGroup } from './deliverables';import { applyPlanFrame, applyQueueFrame, planApprove, queueMessage } from './plan';import { forkFields, isForkJob, TIME_SKIP_DURATION, timeSkipPrompt, timeSkipTabId, withTimeSkipResult, type TimeSkipFile, type TimeSkipJob, type TimeSkipRun, type TimeSkipVersion } from './time-skip';@@ -1435,7 +1436,7 @@ export function rewindTo(messageId: string): string | null {export function exportConversation() {const session = state.sessions.find(s => s.id === state.activeSession);if (!session) return;- const text = '# ' + session.title + '\n\n' + session.messages.map(m => '## ' + m.role + '\n\n' + m.content).join('\n\n');+ const text = '# ' + session.title + '\n\n' + session.messages.map(m => '## ' + m.role + '\n\n' + (m.role === 'assistant' ? tidyAnswer(m.content) : m.content)).join('\n\n');const url = URL.createObjectURL(new Blob([text], { type: 'text/markdown' }));const a = document.createElement('a'); a.href = url; a.download = session.title.replace(/[^a-z0-9 -]/gi, '').slice(0, 60) + '.md';document.body.append(a); a.click(); a.remove();@@ -1665,7 +1666,7 @@ export async function sendMessage(text: string, options: { fromLoop?: boolean; g} else if (type === 'agent') {patchSession(sessionId, s => ({ ...s, agents: updateAgent(s.agents ?? [], frame.agent) }));} else if (type === 'delta') {- patchAssistant((m) => { const content=m.content+String(frame.text??''); if (m.reasoningStartedAt && m.reasoningMs === undefined) m = { ...m, reasoningMs: Date.now() - m.reasoningStartedAt }; const count=Math.max(1,Math.ceil((content.length+(m.reasoning?.length??0))/4)); return {...m,content,...(m.blocks?{blocks:appendText(m.blocks,String(frame.text??''))}:{}),tokens:m.usageSource==='estimated'&&m.tps?m.tokens:count,inputTokens:m.inputTokens??Math.ceil((body.length+prior.reduce((n,p)=>n+p.content.length,0))/4),usageSource:'estimated'}; });+ patchAssistant((m) => { const content=tidyAnswer(m.content+String(frame.text??'')); if (m.reasoningStartedAt && m.reasoningMs === undefined) m = { ...m, reasoningMs: Date.now() - m.reasoningStartedAt }; const count=Math.max(1,Math.ceil((content.length+(m.reasoning?.length??0))/4)); return {...m,content,...(m.blocks?{blocks:appendText(m.blocks,String(frame.text??''))}:{}),tokens:m.usageSource==='estimated'&&m.tps?m.tokens:count,inputTokens:m.inputTokens??Math.ceil((body.length+prior.reduce((n,p)=>n+p.content.length,0))/4),usageSource:'estimated'}; });} else if (type === 'deliverable') {const file = readDeliverable(frame);if (file) patchAssistant(m => ({ ...m, deliverables: mergeDeliverable(m.deliverables, file) }));diff --git a/apps/host/tests/answer-text.test.mjs b/apps/host/tests/answer-text.test.mjsnew file mode 100644index 000000000..c60a9bb93--- /dev/null+++ b/apps/host/tests/answer-text.test.mjs@@ -0,0 +1,43 @@+// QA report F01: reasoning wrappers and stray tag fragments never show in an answer or its Markdown export.+import test from 'node:test';+import assert from 'node:assert/strict';+import { readFile } from 'node:fs/promises';+import { transform } from 'esbuild';+async function loadTs(path) {+ const { code } = await transform(await readFile(new URL(path, import.meta.url), 'utf8'), { loader: 'ts', format: 'esm' });+ return import(`data:text/javascript;base64,${Buffer.from(code).toString('base64')}`);+}+const { tidyAnswer } = await loadTs('../src/lib/answer-text.ts');+const { appendText } = await loadTs('../src/lib/deliverables.ts').catch(() => ({}));++test('a literal <analysis> or <think> wrapper is removed, the words stay', () => {+ assert.equal(tidyAnswer('<analysis>The answer is 4.'), 'The answer is 4.');+ assert.equal(tidyAnswer('Sure.\n<think>\nplan\n</think>\nIt is 4.'), 'Sure.\n\nplan\n\nIt is 4.');+ assert.equal(tidyAnswer('x </ANALYSIS> y <Thinking style="a"> z'), 'x y z');+});++test('a tag that lost its "<" at the very start is not shown as a prefix', () => {+ assert.equal(tidyAnswer('p> CEDAR-742'), 'CEDAR-742');+ assert.equal(tidyAnswer(' /p> done'), 'done');+ assert.equal(tidyAnswer('analysis> 4'), '4');+});++test('ordinary text, code and comparisons are untouched', () => {+ for (const text of ['CEDAR-742', 'if a > b then c', 'x -> y', '```html\n<p>hi</p>\n```', 'The p> in the middle', '<div>kept</div>', 'a <b and c> d', 'Result: 5 > 3', '']) assert.equal(tidyAnswer(text), text);+});++test('streaming: a tag that arrives in pieces is removed once it is complete', () => {+ let content = '';+ for (const piece of ['<', 'ana', 'lysis', '>', 'The code is ', 'p', '> no']) content = tidyAnswer(content + piece);+ assert.equal(content, 'The code is p> no');+ let lead = '';+ for (const piece of ['p', '>', ' CEDAR', '-742']) lead = tidyAnswer(lead + piece);+ assert.equal(lead, 'CEDAR-742');+});++test('the store applies it to the answer, the ordered pieces and the Markdown export', async () => {+ const store = await readFile(new URL('../src/lib/store.ts', import.meta.url), 'utf8');+ assert.match(store, /tidyAnswer\(m\.content\+String\(frame\.text/);+ assert.match(store, /m\.role === 'assistant' \? tidyAnswer\(m\.content\) : m\.content\)/);+ assert.match(await readFile(new URL('../src/lib/deliverables.ts', import.meta.url), 'utf8'), /tidyAnswer\(last\.text \+ text\)/);+});