Skip to content

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++

agent: output budget for a local model is the window (was 8192), the Reasoning menu reaches the request, fit_max_tokens for app-loaded models, plain outcome for silent commands

Niko1221be1a871349df
diff --git a/apps/host/server/agent/agent-bridge.mjs b/apps/host/server/agent/agent-bridge.mjs
index 6e423d756..6be1fcd26 100644
--- a/apps/host/server/agent/agent-bridge.mjs
+++ b/apps/host/server/agent/agent-bridge.mjs
@@ -19,7 +19,7 @@ import { join } from 'node:path';
import { randomUUID } from 'node:crypto';
import { GatewayClient } from './gateway-client.mjs';
import { HarnessProcess, resolveHarness, redact, stopStaleAgent } from './harness-runtime.mjs';
-import { buildProfile, routeFor, MODE_PRESETS, modeOf } from './profile.mjs';
+import { buildProfile, routeFor, MODE_PRESETS, modeOf, effortOf } from './profile.mjs';
import { TurnProjector, parseArguments as parseArgs } from './events.mjs';
import { ChildProjector } from './children.mjs';
@@ -238,7 +238,7 @@ export function createAgentBridge({ dataDir, componentsDir = null, bundledDir =
try { return await runTurnInner(c, options); } finally { c.starting = false; }
}
- async function runTurnInner(c, { chatId, message, workspacePath, choice = null, mode = null, history = [], onFrame, requestId = `req-${randomUUID()}`, signal, goal = null }) {
+ async function runTurnInner(c, { chatId, message, workspacePath, choice = null, mode = null, history = [], onFrame, requestId = `req-${randomUUID()}`, signal, goal = null, thinking = null }) {
let send = onFrame;
signal?.addEventListener('abort', () => { send = () => {}; }, { once: true });
const emit = frame => { try { send(frame); } catch { send = () => {}; } };
@@ -249,14 +249,19 @@ export function createAgentBridge({ dataDir, componentsDir = null, bundledDir =
const cancelled = () => { emit({ type: 'done', finishReason: 'aborted', cancelled: true, tokensIn: null, tokensOut: null, usageSource: 'unavailable', durationMs: 0, model: route.name, contextMax: route.contextWindow }); return { cancelled: true }; };
if (c.cancelStart) return cancelled();
- if (c.route !== `${route.route}/${route.modelId}` || c.routeGeneration !== runtime.generation) {
+ // The model and the chat's thinking level (the Reasoning menu) are sent to the Harness when either changed. A level the route does
+ // not have (an API model with its own vocabulary) is dropped and the model's own default stands: never an error for the person.
+ const level = effortOf(thinking);
+ const wanted = `${route.route}/${route.modelId}/${level ?? ''}`;
+ if (c.route !== wanted || c.routeGeneration !== runtime.generation) {
+ const select = effort => runtime.gw.rpc('session/selectModel', { request: { sessionId, provider: route.route, model: route.modelId, ...(effort ? { reasoningEffort: effort } : {}) } });
try {
- await runtime.gw.rpc('session/selectModel', { request: { sessionId, provider: route.route, model: route.modelId } });
+ try { await select(level); } catch (e) { if (!level || e.code === 'session/not-found') throw e; await select(null); }
} catch (e) {
if (e.code === 'session/not-found') { delete sessionMap[c.id]; persist(); }
throw new AgentUnavailable(`The coding assistant could not use ${route.name}. Pick the model again and retry.`, 'model-unavailable', e.message);
}
- c.route = `${route.route}/${route.modelId}`; c.routeGeneration = runtime.generation;
+ c.route = wanted; c.routeGeneration = runtime.generation;
}
// The chat's permission mode is read once, here, for this whole turn. A change the user makes while the
diff --git a/apps/host/server/agent/events.mjs b/apps/host/server/agent/events.mjs
index 7dfa80221..7862d4b3a 100644
--- a/apps/host/server/agent/events.mjs
+++ b/apps/host/server/agent/events.mjs
@@ -91,6 +91,16 @@ export function withPlain(raw) {
return plain ? `${plain}\n\nDetails: ${raw.replace(/^Error:\s*/, '')}` : raw;
}
+/**
+ * A command that succeeded and printed nothing says so in words (the card used to show "(no output)" under a "Ran" that could not
+ * tell the person whether anything happened). Opening a folder or a window is not something a command can prove it did, so the
+ * sentence says only what is known.
+ */
+export function outcomeText(tool, text) {
+ if ((tool === 'pwsh' || tool === 'bash') && /^\(no output\)$/.test(text.trim())) return 'The command finished without any error. It printed nothing, so there is nothing more to show.';
+ return text;
+}
+
/** Text of a tool-result message, bounded. */
export function resultText(message) {
const parts = Array.isArray(message?.content) ? message.content : [];
@@ -204,7 +214,7 @@ export class TurnProjector {
const frame = this.#card(callId, {
state: denied ? 'denied' : isError ? 'error' : 'done',
// A card the person (or the mode) refused keeps its plain sentence; the model's own error text ("the user rejected ...") is not for them.
- result: this.byPolicy.has(callId) ? NOT_IN_MODE : denied ? (entry.card.result ?? 'Denied. Nothing ran.') : isError ? withPlain(resultText(d.message)) : resultText(d.message),
+ result: this.byPolicy.has(callId) ? NOT_IN_MODE : denied ? (entry.card.result ?? 'Denied. Nothing ran.') : isError ? withPlain(resultText(d.message)) : outcomeText(entry.card.name, resultText(d.message)),
durationMs: Math.max(0, (e.time ?? 0) - entry.calledAt),
});
if (frame) out.push(frame);
diff --git a/apps/host/server/agent/profile.mjs b/apps/host/server/agent/profile.mjs
index 7bd71c6ba..1938106ce 100644
--- a/apps/host/server/agent/profile.mjs
+++ b/apps/host/server/agent/profile.mjs
@@ -85,7 +85,29 @@ function fingerprint(provider, secret) {
return createHash('sha256').update(JSON.stringify(provider)).update('|').update(secret ?? '').digest('hex').slice(0, 16);
}
-/** Output budget that leaves the prompt room: a quarter of the window, between 1K and 8K. */
+/**
+ * Output budget for an API model, whose real limit the app does not know: a quarter of the window, between 1K and 8K.
+ * (A local model has its own, much larger budget: `localOutputBudget`.)
+ */
+/**
+ * Output budget for a LOCAL model: nearly the whole window, so a thinking model is never cut off mid-thought by the app's own
+ * limit (it was 8192, which stopped big coding answers at exactly 8192 tokens). The engine clamps the request to what is left
+ * of the context (`fit_max_tokens`, which the app turns on for the models it loads), so a long prompt never turns this into an error.
+ */
+export function localOutputBudget(context) {
+ const c = Number.isFinite(context) && context > 0 ? context : 32768;
+ return Math.max(8192, c - 4096);
+}
+
+/**
+ * The thinking levels the chat's Reasoning menu offers, as wire values for a local Strata model. `off` sends enable_thinking false;
+ * the rest send enable_thinking true plus the effort (the server reads both; "Max" is the highest effort it has).
+ */
+export const LOCAL_EFFORTS = Object.freeze({ off: null, low: 'low', medium: 'medium', high: 'high', max: 'high' });
+/** The menu's words to the Harness's level names. */
+export const EFFORT_LEVEL = Object.freeze({ off: 'off', low: 'low', medium: 'medium', high: 'high', max: 'max' });
+export const effortOf = value => EFFORT_LEVEL[String(value ?? '').toLowerCase()] ?? null;
+
export function outputBudget(context) {
const c = Number.isFinite(context) && context > 0 ? context : 32768;
return Math.max(1024, Math.min(8192, Math.floor(c / 4)));
@@ -118,10 +140,12 @@ export function buildProfile({ local = [], connections = [], gate = true }) {
api: 'openai-completions',
baseURL: inst.baseUrl,
apiKeyEnv: keyEnv,
- compat: { supportsStore: false },
+ // `qwen` thinking format: enable_thinking true/false plus reasoning_effort, which the Strata server reads.
+ compat: { supportsStore: false, thinkingFormat: 'qwen', supportsReasoningEffort: true },
models: [{
- id: inst.modelId, name: inst.label || inst.modelId, contextWindow: context, maxTokens: outputBudget(context),
+ id: inst.modelId, name: inst.label || inst.modelId, contextWindow: context, maxTokens: localOutputBudget(context),
input: inst.vision ? ['text', 'image'] : ['text'],
+ reasoning: true, reasoningEfforts: LOCAL_EFFORTS,
}],
};
slots = Math.max(slots, Number.isFinite(inst.slots) && inst.slots >= 1 ? Math.floor(inst.slots) : 1);
diff --git a/apps/host/server/index.mjs b/apps/host/server/index.mjs
index 06e008435..3b7cd276f 100644
--- a/apps/host/server/index.mjs
+++ b/apps/host/server/index.mjs
@@ -478,7 +478,7 @@ async function runAgentTurn({ res, controller, chatId, body, message, workspaceI
try {
// "/goal ..." is the Harness's goal command (set, show, pause, resume, clear); everything else is a message.
const goalLine = /^\/goal(?:\s+([\s\S]*))?$/i.exec(message.trim());
- const turnOptions = { chatId, message, workspacePath: cwd, choice, mode: typeof body.mode === 'string' ? body.mode : null, history: Array.isArray(body.history) ? body.history : [], onFrame: write, signal: controller.signal };
+ const turnOptions = { chatId, message, workspacePath: cwd, choice, mode: typeof body.mode === 'string' ? body.mode : null, thinking: typeof body.thinking === 'string' ? body.thinking : null, history: Array.isArray(body.history) ? body.history : [], onFrame: write, signal: controller.signal };
const result = goalLine ? await agent.goalCommand({ ...turnOptions, line: goalLine[1] ?? '' }) : await agent.runTurn(turnOptions);
if (result?.detached) void result.ended.then(r => settle(r?.tokensOut ?? null), () => settle(null));
else settle(result?.tokensOut ?? null, result?.error ? 'The agent turn failed.' : undefined);
diff --git a/apps/host/server/native-control.mjs b/apps/host/server/native-control.mjs
index c3a7baed0..968635a9c 100644
--- a/apps/host/server/native-control.mjs
+++ b/apps/host/server/native-control.mjs
@@ -103,6 +103,8 @@ export function createNativeControl({directory,requests=()=>[],changed=()=>{},sp
/* Installed app: several requests at once by default (4, fewer where the card has no room), unless a number was chosen. */
const parallelChoice=packaged?chooseParallel({config:cfg,values:args.values??{},hardware:snapshot.hardware?.gpus?.length?snapshot.hardware:{gpus:hardwareProbe()??[]}}):null;
let parallelNote=null;
+ /* The agent asks for long answers (a thinking model can use most of the window): let the engine clamp the output to what is left of the context instead of refusing the request. */
+ if(packaged&&cfg.fit_max_tokens===undefined)cfg.fit_max_tokens=true;
if(parallelChoice){const applied=applyParallel(cfg,parallelChoice);for(const k of Object.keys(cfg))if(!(k in applied.cfg))delete cfg[k];Object.assign(cfg,applied.cfg);parallelNote=applied.note;}
const fingerprint=createHash('sha256').update(JSON.stringify({...cfg,api_key:undefined,port:undefined})).digest('hex');
const placement=Array.isArray(cfg.gpu)?cfg.gpu:cfg.gpu===undefined?[]:[cfg.gpu];const matching=[...instances.values()].find(i=>i.model===args.model&&JSON.stringify(i.gpus)===JSON.stringify(placement));
diff --git a/apps/host/tests/agent-events.test.mjs b/apps/host/tests/agent-events.test.mjs
index 2cdefffd2..3eeb540c2 100644
--- a/apps/host/tests/agent-events.test.mjs
+++ b/apps/host/tests/agent-events.test.mjs
@@ -18,7 +18,9 @@ test('the generated profile names credentials, never carries them, and declares
const providers = entries.find(e => e.id === 'llm-pi-ai').config.providers;
assert.deepEqual(Object.keys(providers).sort(), ['api-c0nn-1234-ab', 'strata-local']);
assert.equal(providers['strata-local'].models[0].contextWindow, 32768);
- assert.equal(providers['strata-local'].models[0].maxTokens, 8192);
+ assert.equal(providers['strata-local'].models[0].maxTokens, 28672, 'a local model may use nearly the whole window (it was 8192, which cut big answers off)');
+ assert.equal(providers['strata-local'].models[0].reasoning, true);
+ assert.equal(providers['strata-local'].compat.thinkingFormat, 'qwen');
assert.equal(providers['api-c0nn-1234-ab'].models[1].contextWindow, ASSUMED_API_CONTEXT, 'an unknown API window is a stated assumption, not a catalog default');
assert.equal(entries.find(e => e.id === 'agent-default-model').config.provider, 'strata-local', 'local stays the default');
assert.equal(entries.find(e => e.id === 'session-title-llm').disabled, true);
diff --git a/apps/host/tests/agent-tools.test.mjs b/apps/host/tests/agent-tools.test.mjs
index 4236aaf41..a7901c2f8 100644
--- a/apps/host/tests/agent-tools.test.mjs
+++ b/apps/host/tests/agent-tools.test.mjs
@@ -29,7 +29,7 @@ test('the gate: only commands that provably just look are allowed without a ques
for (const ok of ['Get-ChildItem', 'Get-ChildItem -Recurse src | Select-Object -First 5', 'git status', 'git log --oneline -5', 'git diff', 'cat notes.txt', 'ls -la', 'node --version', 'Get-Content a.txt | Select-String needle', 'git branch', 'git remote -v']) {
assert.equal(isReadOnlyShell(ok), true, ok);
}
- for (const bad of ['', 'Set-Content a.txt x', 'echo hi > a.txt', 'Get-ChildItem; Remove-Item a.txt', 'rm -rf x', 'git commit -m x', 'git push', 'git branch -D x', 'git config user.name x', 'git remote add o u', 'curl http://x', 'Get-ChildItem | ForEach-Object { $_ }', 'powershell -Command x', 'node script.js', 'python x.py', 'ls && rm a', 'find . -delete', 'echo $(whoami)', 'Invoke-WebRequest u', 'Start-Process x', 'New-Item a', 'cat a | tee b']) {
+ for (const bad of ['', 'Set-Content a.txt x', 'echo hi > a.txt', 'Get-ChildItem; Remove-Item a.txt', 'rm -rf x', 'git commit -m x', 'git push', 'git branch -D x', 'git config user.name x', 'git remote add o u', 'curl http://x', 'Get-ChildItem | ForEach-Object { $_ }', 'Start-Process explorer.exe', 'explorer.exe C:/Users/x/Downloads', 'ii ~/Downloads', 'Invoke-Item $env:USERPROFILE/Downloads', 'start .', 'open .', 'xdg-open .', 'notepad a.txt', 'powershell -Command x', 'node script.js', 'python x.py', 'ls && rm a', 'find . -delete', 'echo $(whoami)', 'Invoke-WebRequest u', 'Start-Process x', 'New-Item a', 'cat a | tee b']) {
assert.equal(isReadOnlyShell(bad), false, bad);
}
assert.equal(isReadOnlyShell('x'.repeat(700)), false, 'a long command is never trusted');
@@ -220,3 +220,29 @@ function readdirDeep(dir) {
for (const e of readdirSync(dir, { withFileTypes: true })) { const p = join(dir, e.name); if (e.isDirectory()) out.push(...readdirDeep(p)); else out.push(p); }
return out;
}
+
+test('the output budget is not the old 8192, and the Reasoning menu reaches the request (off sends enable_thinking false)', { skip }, async (t) => {
+ const worker = await startScriptedWorker({});
+ const dir = mkdtempSync(join(tmpdir(), 'strata-think-'));
+ const ws = join(dir, 'ws'); mkdirSync(ws, { recursive: true });
+ const local = [{ id: 'i', baseUrl: worker.url, modelId: 'scripted-model', context: 65536 }];
+ const bridge = createAgentBridge({ dataDir: dir, localInstances: () => local, connections: () => [], env: process.env, startTimeoutMs: 90_000 });
+ t.after(async () => { await bridge.close(); await worker.close(); cleanup(dir); });
+ const ask = async (chatId, thinking) => {
+ worker.requests.length = 0;
+ await bridge.runTurn({ chatId, message: 'SCRIPT:echo hi', workspacePath: ws, mode: 'bypass', thinking, onFrame: () => {} });
+ return worker.requests.find(r => r.toolNames.length).params;
+ };
+ const off = await ask('think-off', 'Off');
+ assert.equal(off.enable_thinking, false);
+ assert.ok(off.max_completion_tokens > 40000, `budget ${off.max_completion_tokens} (the window minus the prompt, never the old 8192)`);
+ const high = await ask('think-high', 'High');
+ assert.equal(high.enable_thinking, true); assert.equal(high.reasoning_effort, 'high');
+ const low = await ask('think-low', 'Low');
+ assert.equal(low.enable_thinking, true); assert.equal(low.reasoning_effort, 'low');
+ const max = await ask('think-max', 'Max');
+ assert.equal(max.enable_thinking, true); assert.equal(max.reasoning_effort, 'high');
+ // the same chat switching its level between turns
+ assert.equal((await ask('think-off', 'High')).enable_thinking, true);
+ assert.equal((await ask('think-off', 'Off')).enable_thinking, false);
+});