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++
status tests (plain chat, real Harness file write), HTTP driver for real-model checks
Niko1221b085d54b9476
diff --git a/apps/host/scripts/agent3-http.mjs b/apps/host/scripts/agent3-http.mjsnew file mode 100644index 000000000..04163661f--- /dev/null+++ b/apps/host/scripts/agent3-http.mjs@@ -0,0 +1,116 @@+/**+ * Drive the host over HTTP (no browser) against a real model and print what the page would receive.+ *+ * STRATA_URL=http://127.0.0.1:8899 node scripts/agent3-http.mjs <command> [args]+ *+ * connect <baseUrl> <modelId> save an API connection to a model server (once per STRATA_HOME)+ * stream "<message>" [mode] one chat turn; prints every frame compactly with its time (status, goal, tools, deltas counted)+ * goal "<objective>" /goal run, then the goal bar calls: state, pause, edit, clear, resume+ * timeskip "<request>" [stopAfterS] a Time-skip job; polls status (phase + activity); with stopAfterS, presses Stop that many seconds in+ *+ * Environment: STRATA_URL (required), CHAT (chat id, default a fresh one), WORKSPACE_ID.+ */+const BASE = process.env.STRATA_URL;+if (!BASE) { console.error('STRATA_URL is required'); process.exit(2); }+const [command, ...rest] = process.argv.slice(2);+const t0 = Date.now();+const stamp = () => `${String(Math.round((Date.now() - t0) / 1000)).padStart(4)}s`;+const j = async (path, body, method = body ? 'POST' : 'GET') => {+ const res = await fetch(BASE + path, { method, headers: { 'content-type': 'application/json' }, ...(body ? { body: JSON.stringify(body) } : {}) });+ const text = await res.text();+ let data; try { data = JSON.parse(text); } catch { data = { raw: text }; }+ if (!res.ok) throw new Error(`${path} -> ${res.status} ${data.error ?? text.slice(0, 200)}`);+ return data;+};+const sleep = ms => new Promise(r => setTimeout(r, ms));++async function model() {+ const providers = await j('/api/model-providers');+ const c = providers.connections[0];+ if (!c) throw new Error('no API connection saved: run "connect" first');+ return { connectionId: c.id, modelId: c.models[0].id };+}++/** One chat stream; returns the frames. `print` shows a compact line per frame, deltas and reasoning as counters. */+async function stream(body, { quiet = false } = {}) {+ const res = await fetch(BASE + '/api/chat/stream', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(body) });+ if (!res.ok) throw new Error(`stream -> ${res.status} ${await res.text()}`);+ const frames = []; let buffer = '', text = 0, reasoning = 0, lastLine = '';+ const flushCounters = () => { if (text || reasoning) { console.log(`${stamp()} ... ${reasoning} reasoning chars, ${text} answer chars`); text = 0; reasoning = 0; } };+ const reader = res.body.getReader(); const dec = new TextDecoder();+ for (;;) {+ const { value, done } = await reader.read();+ if (value) {+ buffer += dec.decode(value, { stream: true });+ const lines = buffer.split('\n'); buffer = lines.pop() ?? '';+ for (const line of lines.filter(Boolean)) {+ const f = JSON.parse(line); f._at = Date.now(); frames.push(f);+ if (f.type === 'delta') { text += (f.text ?? '').length; continue; }+ if (f.type === 'reasoning') { reasoning += (f.text ?? '').length; continue; }+ if (f.type === 'stats') continue;+ flushCounters();+ let out = f.type;+ if (f.type === 'status') out = `status[${f.seq}] ${f.phase}/${f.code}: ${f.text}${f.tokens !== undefined ? ` (tokens ${f.tokens})` : ''} +${f.elapsedMs}ms`;+ else if (f.type === 'goal') out = `goal ${JSON.stringify(f.goal)}`;+ else if (f.type === 'agent-tool') out = `tool ${f.tool.state} ${f.tool.verb} ${f.tool.target ?? ''}`;+ else if (f.type === 'done') out = `done ${f.finishReason} tokensOut=${f.tokensOut}`;+ else if (f.type === 'error') out = `ERROR ${f.message}`;+ if (!quiet && out !== lastLine) console.log(`${stamp()} ${out}`);+ lastLine = out;+ }+ }+ if (done) break;+ }+ flushCounters();+ return frames;+}++if (command === 'connect') {+ const [baseUrl, modelId] = rest;+ await j('/api/model-providers', { kind: 'custom', name: 'Cloud model', baseUrl, protocol: 'openai-chat', apiKey: '', models: [{ id: modelId, name: 'Test model' }] });+ console.log('saved');+} else if (command === 'stream') {+ const [message, mode = 'bypass'] = rest;+ const chat = process.env.CHAT ?? `c-${Date.now()}`;+ await stream({ sessionId: chat, message, mode, remoteModel: await model(), workspaceId: process.env.WORKSPACE_ID });+} else if (command === 'goal') {+ const [objective] = rest;+ const chat = process.env.CHAT ?? `g-${Date.now()}`;+ const common = { sessionId: chat, mode: 'bypass', remoteModel: await model() };+ console.log(`${stamp()} -- /goal run`);+ const frames = await stream({ ...common, message: `/goal ${objective}` });+ const last = frames.filter(f => f.type === 'goal').at(-1);+ console.log(`${stamp()} -- goal bar: state`, JSON.stringify((await j(`/api/goal?chatId=${chat}`)).goal));+ console.log(`${stamp()} -- pause`, JSON.stringify(await j('/api/goal/pause', { chatId: chat })));+ console.log(`${stamp()} -- edit`, JSON.stringify(await j('/api/goal/edit', { chatId: chat, text: `${objective} (edited)` })));+ console.log(`${stamp()} -- resume (stream)`);+ await stream({ ...common, goalAction: 'resume' });+ console.log(`${stamp()} -- clear`, JSON.stringify(await j('/api/goal/clear', { chatId: chat })));+ console.log(`${stamp()} -- state after clear`, JSON.stringify(await j(`/api/goal?chatId=${chat}`)));+ void last;+} else if (command === 'timeskip') {+ const [request, stopAfter] = rest;+ const chat = process.env.CHAT ?? `t-${Date.now()}`;+ const started = await j('/api/timeskip/start', { prompt: request, sessionId: chat, attempts: 1, workspaceId: process.env.WORKSPACE_ID, remoteModel: await model() });+ const id = started.run.id;+ console.log(`${stamp()} started ${id} activity=${JSON.stringify(started.run.activity)}`);+ let last = '', stopped = false;+ for (;;) {+ const { run } = await j(`/api/timeskip/status?id=${id}`);+ const line = `${run.phase}${run.activity ? ` | ${run.activity.text}${run.activity.args?.step ? ` | assistant: ${run.activity.args.step}` : ''}` : ''}`;+ if (line !== last) { console.log(`${stamp()} ${line}`); last = line; }+ if (stopAfter && !stopped && (Date.now() - t0) / 1000 >= Number(stopAfter)) {+ console.log(`${stamp()} -- pressing Stop (the chat Stop route)`);+ console.log(`${stamp()} `, JSON.stringify(await j('/api/chat/stop', { sessionId: chat })));+ stopped = true;+ }+ if (['completed', 'cancelled', 'failed', 'interrupted'].includes(run.phase)) {+ console.log(`${stamp()} END ${run.phase}${run.error ? ` error=${run.error}` : ''} needsReview=${run.needsUserReview}`);+ try { const files = await j(`/api/timeskip/files?id=${id}`); console.log(`${stamp()} files: ${files.files.map(f => `${f.status} ${f.path}`).join(', ') || '(none)'}`); } catch (e) { console.log(`${stamp()} files: ${e.message}`); }+ break;+ }+ await sleep(4000);+ }+} else {+ console.error('commands: connect | stream | goal | timeskip'); process.exit(2);+}diff --git a/apps/host/tests/agent-status.test.mjs b/apps/host/tests/agent-status.test.mjsindex 48b424095..74b479034 100644--- a/apps/host/tests/agent-status.test.mjs+++ b/apps/host/tests/agent-status.test.mjs@@ -101,3 +101,51 @@ test('token count: one per chunk, or characters / 4 when the server batches', ()const a = new TokenCount(); for (const t of ['a', 'b', 'c']) a.add(t); assert.equal(a.tokens, 3);const b = new TokenCount(); b.add('x'.repeat(400)); assert.equal(b.tokens, 100);});++test('plain chat says what it is doing too: reading the message, thinking with a token count, writing, then the line is cleared before done', async () => {+ const { withPlainStatus } = await import('../server/agent/status.mjs');+ let clock = 1000; const written = [];+ const frame = withPlainStatus(f => written.push(f), { now: () => clock, timers: { set: () => ({ unref() {} }), clear() {} } });+ const feed = f => { clock += 2100; frame(f); };+ feed({ type: 'start', demo: false });+ for (const t of ['a', 'b', 'c']) feed({ type: 'reasoning', text: t });+ feed({ type: 'delta', text: 'Hello' });+ feed({ type: 'done', tokensOut: 4 });+ const phases = written.filter(f => f.type === 'status').map(f => f.phase);+ assert.deepEqual(phases.filter((p, i, a) => a[i - 1] !== p), ['starting', 'waiting', 'thinking', 'answering', 'idle']);+ const think = written.filter(f => f.type === 'status' && f.phase === 'thinking').at(-1);+ assert.equal(think.tokens, 3); assert.equal(think.text, 'Thinking… 3 tokens');+ assert.equal(written.at(-1).type, 'done');+ assert.equal(written.at(-2).phase, 'idle');+ frame.dispose();+});++// ------------------------------------------------------------------------------------------------- real Harness++import { existsSync, mkdtempSync, mkdirSync, rmSync } from 'node:fs';+import { tmpdir } from 'node:os';+import { join } from 'node:path';+import { startScriptedWorker } from './helpers/scripted-worker.mjs';+import { createAgentBridge } from '../server/agent/agent-bridge.mjs';+import { resolveHarness } from '../server/agent/harness-runtime.mjs';++const skip = !process.env.STRATA_HARNESS_DIR || !resolveHarness({ env: process.env }).ok ? 'STRATA_HARNESS_DIR is not set to a built Harness' : false;++test('real Harness: a turn that writes a file says what it is doing, in order, and ends with the status cleared before done', { skip }, async (t) => {+ const worker = await startScriptedWorker({});+ const dir = mkdtempSync(join(tmpdir(), 'strata-status-'));+ const ws = join(dir, 'ws'); mkdirSync(ws, { recursive: true });+ const local = [{ id: 'inst-1', label: 'Scripted', baseUrl: worker.url, modelId: 'scripted-model', context: 32768, slots: 2 }];+ const bridge = createAgentBridge({ dataDir: dir, localInstances: () => local, connections: () => [], env: process.env, startTimeoutMs: 90_000 });+ t.after(async () => { await bridge.close(); await worker.close(); try { rmSync(dir, { recursive: true, force: true, maxRetries: 3 }); } catch { /* best effort */ } });+ const frames = [];+ await bridge.runTurn({ chatId: 's1', message: `SCRIPT:call write ${JSON.stringify({ file_path: join(ws, 'pagoda.html'), content: '<html></html>' })}`, workspacePath: ws, mode: 'bypass', onFrame: f => frames.push(f) });+ const statuses = frames.filter(f => f.type === 'status');+ assert.ok(statuses.length >= 2, 'statuses were sent');+ assert.equal(statuses[0].phase, 'starting');+ assert.ok(statuses.some(s => /^Writing (a file|pagoda\.html)…/.test(s.text)), `a "Writing …" status was sent (${statuses.map(s => s.text).join(' | ')})`);+ assert.deepEqual(statuses.map(s => s.seq), statuses.map((_, i) => i + 1), 'sequence numbers count up');+ assert.equal(statuses.at(-1).phase, 'idle');+ assert.ok(frames.indexOf(statuses.at(-1)) < frames.findIndex(f => f.type === 'done'), 'cleared before done');+ assert.ok(existsSync(join(ws, 'pagoda.html')));+});