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(thinking): Workflow, A/B-Vergleich und Benchmark ziehen mit
purplef72000bcc462
diff --git a/src/hooks/useABCompare.ts b/src/hooks/useABCompare.tsindex cb39f304..824e0713 100644--- a/src/hooks/useABCompare.ts+++ b/src/hooks/useABCompare.ts@@ -11,6 +11,9 @@ import { applySendBudget, chatBudgetApplies, sharedChatSendBudget } from '../libimport { v4 as uuid } from 'uuid'import type { ChatMessage } from '../api/providers/types'import type { Message } from '../types/chat'+import { createThinkStreamSplitter } from '../lib/hermes-stream'+import { settleThinking } from '../lib/thinking-stripper'+import { isThinkingCompatible } from '../lib/model-compatibility'export function useABCompare() {const store = useCompareStore()@@ -78,6 +81,13 @@ export function useABCompare() {// Bug AA v2.5.0 — forward num_ctx override to both A/B sides.contextWindow: settings.contextWindowOverride || undefined,}+ // 2.6.7 Denk-Audit, Loch 6: this hook sent no thinking signal at all and+ // stripped nothing, so a comparison ran on whatever the backend defaulted+ // to and the raw <think> block was part of what the user compared. Both+ // sides get the same tri-state the plain chat sends, per model, because a+ // line-up can mix a reasoner with an instruct model.+ const thinkOptFor = (model: string): boolean | undefined =>+ isThinkingCompatible(model) ? settings.thinkingEnabled === true : undefined// Stream Model AabortA.current = new AbortController()@@ -85,17 +95,30 @@ export function useABCompare() {const startTime = Date.now()let fullContent = ''let tokenCount = 0+ // The pane has no thinking block, so reasoning is never part of what+ // is being compared: it is split out of the live stream and the+ // end-of-turn settlement catches the pre-opened shape the splitter+ // cannot see coming.+ const splitter = createThinkStreamSplitter()+ const show = (part: { prose: string }) => {+ if (!part.prose) return+ fullContent += part.prose+ useCompareStore.getState().addContentA(part.prose)+ }try {const { provider, modelId } = getProviderForModel(modelA)- const stream = provider.chatStream(modelId, sendMessages, { ...opts, signal: abortA.current!.signal })+ const stream = provider.chatStream(modelId, sendMessages, {+ ...opts, thinking: thinkOptFor(modelA), signal: abortA.current!.signal,+ })for await (const chunk of stream) {if (chunk.content) {- fullContent += chunk.contenttokenCount++- useCompareStore.getState().addContentA(chunk.content)+ show(splitter.feed(chunk.content))}}+ show(splitter.flush())} catch { /* aborted or error */ }+ fullContent = settleThinking(fullContent, '', false).contentconst elapsed = Date.now() - startTimeuseCompareStore.getState().finishA(fullContent, {tokens: tokenCount,@@ -110,17 +133,30 @@ export function useABCompare() {const startTime = Date.now()let fullContent = ''let tokenCount = 0+ // The pane has no thinking block, so reasoning is never part of what+ // is being compared: it is split out of the live stream and the+ // end-of-turn settlement catches the pre-opened shape the splitter+ // cannot see coming.+ const splitter = createThinkStreamSplitter()+ const show = (part: { prose: string }) => {+ if (!part.prose) return+ fullContent += part.prose+ useCompareStore.getState().addContentB(part.prose)+ }try {const { provider, modelId } = getProviderForModel(modelB)- const stream = provider.chatStream(modelId, sendMessages, { ...opts, signal: abortB.current!.signal })+ const stream = provider.chatStream(modelId, sendMessages, {+ ...opts, thinking: thinkOptFor(modelB), signal: abortB.current!.signal,+ })for await (const chunk of stream) {if (chunk.content) {- fullContent += chunk.contenttokenCount++- useCompareStore.getState().addContentB(chunk.content)+ show(splitter.feed(chunk.content))}}+ show(splitter.flush())} catch { /* aborted or error */ }+ fullContent = settleThinking(fullContent, '', false).contentconst elapsed = Date.now() - startTimeuseCompareStore.getState().finishB(fullContent, {tokens: tokenCount,diff --git a/src/lib/__tests__/thinking-side-surfaces.test.ts b/src/lib/__tests__/thinking-side-surfaces.test.tsnew file mode 100644index 00000000..b3a7bfa0--- /dev/null+++ b/src/lib/__tests__/thinking-side-surfaces.test.ts@@ -0,0 +1,134 @@+/**+ * Loch 5, 6 und 7 des Denk-Audits (2.6.7, 2026-08-29): the three surfaces+ * beside chat, agent and coding.+ *+ * 5. Workflow engine — carried its own hand-written copy of the balanced+ * `<think>` regex. It missed the pre-opened Qwen3 shape (closer without+ * opener), a turn cut off mid-thought, and every non-canonical marker.+ * A workflow step's output is not only shown, it becomes a workflow+ * VARIABLE and rides into every later step's prompt, so leaked reasoning+ * compounds down the chain.+ * 6. A/B compare — sent no thinking signal at all and stripped nothing, so+ * the comparison ran on whatever the backend happened to default to and+ * the raw reasoning was part of what the user was comparing.+ * 7. Benchmark — counted a reasoning chunk only on the NATIVE channel. A+ * backend without one sends the thought inline as `<think>` inside the+ * content (Ollama with the flag unset, llama.cpp with reasoning-format+ * none, LM Studio), so it landed in the answer text the correctness+ * check scores, and thinkShare read 0 on exactly the local backends the+ * board exists to compare.+ *+ * Run: npx vitest run src/lib/__tests__/thinking-side-surfaces.test.ts+ */+import { describe, it, expect } from 'vitest'+import { readFileSync } from 'node:fs'+import { fileURLToPath } from 'node:url'+import { dirname, resolve } from 'node:path'+import { measureRun } from '../benchmark-run'+import { settleThinking } from '../thinking-stripper'+import type { ChatStreamChunk } from '../../api/providers/types'++const read = (p: string) =>+ readFileSync(resolve(dirname(fileURLToPath(import.meta.url)), p), 'utf8')++async function* streamOf(chunks: Partial<ChatStreamChunk>[]): AsyncGenerator<ChatStreamChunk> {+ for (const c of chunks) yield { content: '', done: false, ...c } as ChatStreamChunk+}+const steppedClock = (...values: number[]) => {+ let i = 0+ return () => values[Math.min(i++, values.length - 1)]+}++// ── Loch 5: the workflow engine ────────────────────────────────+describe('a workflow step hands the next step an answer, not a thought', () => {+ const src = read('../workflow-engine.ts')++ it('the step output goes through the shared settlement', () => {+ expect(src).toContain("settleThinking(output, '', false).content")+ })++ it('and the hand-written regex copy is gone', () => {+ expect(src).not.toMatch(/output\.replace\(\/<think>/)+ })++ it('which is what makes the pre-opened shape survive the step', () => {+ const raw = 'Weighing the options here.</think>rename the file to build.log'+ expect(settleThinking(raw, '', false).content).toBe('rename the file to build.log')+ })++ it('NEGATIVE CONTROL: the old copy left the whole thought in the variable', () => {+ const raw = 'Weighing the options here.</think>rename the file to build.log'+ const old = raw.replace(/<think>[\s\S]*?<\/think>/g, '').trim()+ expect(old).toContain('Weighing the options here.')+ expect(old).toContain('</think>')+ })+})++// ── Loch 6: A/B compare ────────────────────────────────────────+describe('A/B compare asks for thinking and never shows it', () => {+ const src = read('../../hooks/useABCompare.ts')++ it('both sides carry the tri-state, per model', () => {+ expect(src).toContain('thinking: thinkOptFor(modelA)')+ expect(src).toContain('thinking: thinkOptFor(modelB)')+ })++ it('the switch only applies where the model has one', () => {+ expect(src).toContain('isThinkingCompatible(model) ? settings.thinkingEnabled === true : undefined')+ })++ it('the live stream is split, so no raw tag ever flashes into the pane', () => {+ expect(src.split('createThinkStreamSplitter()').length - 1).toBe(2)+ })++ it('and the finished pane is settled once more', () => {+ expect(src.split("settleThinking(fullContent, '', false).content").length - 1).toBe(2)+ })+})++// ── Loch 7: the benchmark board ────────────────────────────────+describe('the benchmark counts an inline thought as a thought', () => {+ it('inline reasoning is kept out of the answer the check scores', async () => {+ // A model that reasons its way past a wrong number and prints the right+ // one. Scoring the raw stream would score the reasoning too.+ const m = await measureRun(+ streamOf([+ { content: '<think>Maybe 17. No, all but 9 remain, ' },+ { content: 'so the answer is 9.</think>' },+ { content: '9 sheep are left.' },+ { done: true, finishReason: 'stop' },+ ]),+ (text: string) => text.trim() === '9 sheep are left.',+ { clock: steppedClock(0, 100, 200, 300, 1000) },+ )+ expect(m.correct).toBe(true)+ expect(m.thinkTokens).toBeGreaterThan(0)+ })++ it('NEGATIVE CONTROL: a run with no reasoning at all reports none', async () => {+ const m = await measureRun(+ streamOf([+ { content: '9 sheep are left.' },+ { done: true, finishReason: 'stop' },+ ]),+ (text: string) => text.trim() === '9 sheep are left.',+ { clock: steppedClock(0, 100, 1000) },+ )+ expect(m.correct).toBe(true)+ expect(m.thinkTokens).toBe(0)+ })++ it('the native reasoning channel still counts, it was never the broken half', async () => {+ const m = await measureRun(+ streamOf([+ { thinking: 'working it out ' },+ { content: '9 sheep are left.' },+ { done: true, finishReason: 'stop' },+ ]),+ (text: string) => text.trim() === '9 sheep are left.',+ { clock: steppedClock(0, 100, 200, 1000) },+ )+ expect(m.correct).toBe(true)+ expect(m.thinkTokens).toBeGreaterThan(0)+ })+})diff --git a/src/lib/benchmark-run.ts b/src/lib/benchmark-run.tsindex 3f2b82f7..33272aa8 100644--- a/src/lib/benchmark-run.ts+++ b/src/lib/benchmark-run.ts@@ -9,6 +9,8 @@* performance.now.*/+import { createThinkStreamSplitter } from './hermes-stream'+import { settleThinking } from './thinking-stripper'import type { ChatStreamChunk } from '../api/providers/types'import { computeGenerationTps } from '../stores/benchmarkStore'@@ -70,6 +72,11 @@ export async function measureRun(let contentCount = 0let thinkCount = 0let answerText = ''+ // Splits an inline <think> span out of the content stream. Never+ // startInThink here: a benchmark prompt is a fresh turn and a pre-opened+ // thought closes itself on the first closer, which the settlement below+ // catches for the answer text.+ const inlineThink = createThinkStreamSplitter()let finishReason: string | undefinedlet apiEvalCount: number | undefinedlet apiEvalDurationMs: number | undefined@@ -102,8 +109,20 @@ export async function measureRun(}if (chunk.thinking) thinkCount++if (chunk.content) {- answerText += chunk.content- contentCount+++ // 2.6.7 Denk-Audit, Loch 7: a backend that does NOT own a reasoning+ // channel sends the thought inline, as <think> inside the content+ // (Ollama with the think flag unset, llama.cpp with reasoning-format+ // none, LM Studio). Counting that as answer put the reasoning into+ // `answerText`, so the correctness check could pass on a number the+ // model only considered and rejected, and thinkShare read 0 on exactly+ // the local backends the board is used to compare. Same splitter every+ // other surface uses.+ const part = inlineThink.feed(chunk.content)+ if (part.thinking) thinkCount+++ if (part.prose) {+ answerText += part.prose+ contentCount+++ }}if (chunk.finishReason) finishReason = chunk.finishReason// Bug M v2.4.7 — Ollama reports authoritative gen metrics in the done:true@@ -144,6 +163,15 @@ export async function measureRun(const totalTime = clock() - startTime+ // Whatever the splitter still held back, plus the pre-opened shape it could+ // not see coming: the answer the check scores is prose only.+ {+ const rest = inlineThink.flush()+ if (rest.prose) { answerText += rest.prose; contentCount++ }+ if (rest.thinking) thinkCount+++ answerText = settleThinking(answerText, '', false).content+ }+// totalTokens is the whole output, thinking included, so a model that reasons// out loud and one that does not are counted the same way (David 2026-08-05:// two 9B models tied on tok/s, one spent 8975 tokens where the other spentdiff --git a/src/lib/workflow-engine.ts b/src/lib/workflow-engine.tsindex de093917..54aff2c7 100644--- a/src/lib/workflow-engine.ts+++ b/src/lib/workflow-engine.ts@@ -10,6 +10,7 @@ import { useSettingsStore } from '../stores/settingsStore'import { useMemoryStore } from '../stores/memoryStore'import { getOllamaTools, executeAgentTool } from '../api/tool-registry'import { streamProviderTurn } from './provider-stream'+import { settleThinking } from './thinking-stripper'import { buildHermesToolPrompt, parseHermesToolCalls, stripToolCallTags, hasToolCallTags } from '../api/hermes-tool-calling'import { resolveToolCallingStrategy } from './agent-strategy'import type { AgentWorkflow, WorkflowStep, StepResult, WorkflowEngineCallbacks } from '../types/agent-workflows'@@ -293,8 +294,13 @@ export class WorkflowEngine {}}- // Strip think tags- output = output.replace(/<think>[\s\S]*?<\/think>/g, '').trim()+ // Strip reasoning through the SHARED settlement (2.6.7 Denk-Audit,+ // Loch 5). This used to be a hand-written copy of the balanced-block+ // regex, so a pre-opened Qwen3 thought (closer without opener), a turn cut+ // off mid-thought and every non-canonical marker went straight into the+ // step output — which is not only shown, it becomes a workflow VARIABLE+ // and rides into every later step's prompt.+ output = settleThinking(output, '', false).contentreturn {stepId: step.id,