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++
Helper agents on a named model: forgiving model choice (id, provider/id, name, local), did-you-mean, plain list, guidance for every model
Niko1221bca49fc5f229
diff --git a/apps/host/server/agent/model-routes.mjs b/apps/host/server/agent/model-routes.mjsnew file mode 100644index 000000000..c8a98c9e3--- /dev/null+++ b/apps/host/server/agent/model-routes.mjs@@ -0,0 +1,151 @@+/**+ * Which model did the person (or the assistant) mean when a helper agent is started with a model?+ *+ * The Harness's `subagent` tool wants an exact `provider` route key and an exact model id. People say "ask DeepSeek", "use the local+ * model", "ask deepseek/deepseek-v3.2" or a display name in other letters; a route key such as `api-1b2c3d4e-5f` is something no+ * model can guess. This module turns what was asked into one route, or into a plain answer that says what to do next.+ *+ * Pure and dependency free: the profile writes the route table, the `strata-models` Harness plugin and the tests call it.+ *+ * A route is `{ provider, model, name, connection, local }`:+ * provider the route key in the Harness profile (what the Harness needs)+ * model the model id the server knows+ * name the name the person sees in the model picker+ * connection the connection's name ("OpenRouter") or "this computer" for a local model+ * local true for a model running in the Strata engine+ */++/** The words people use for the model that runs in Strata on this computer. */+const LOCAL_WORDS = new Set(['local', 'localmodel', 'localstrata', 'thelocalmodel', 'mylocalmodel', 'strata', 'stratalocal', 'stratamodel', 'localstratamodel', 'strataslocalmodel', 'default', 'thismodel', 'samemodel', 'themodel', 'thislocalmodel']);++/** Letters and digits only, lower case: "DeepSeek: V3.2" and "deepseek v3.2" meet. */+export const squash = value => String(value ?? '').toLowerCase().replace(/[^\p{L}\p{N}]+/gu, '');+const words = value => String(value ?? '').toLowerCase().split(/[^\p{L}\p{N}.]+/u).filter(Boolean);++/** Edit distance, capped: enough to tell "deepseek-v3.2" from "deepseek-v3.1" and "depseek" from "deepseek". */+function distance(a, b, cap = 4) {+ if (Math.abs(a.length - b.length) > cap) return cap + 1;+ let prev = Array.from({ length: b.length + 1 }, (_, i) => i);+ for (let i = 1; i <= a.length; i++) {+ const row = [i];+ let best = row[0];+ for (let j = 1; j <= b.length; j++) {+ row[j] = Math.min(prev[j] + 1, row[j - 1] + 1, prev[j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1));+ best = Math.min(best, row[j]);+ }+ if (best > cap) return cap + 1;+ prev = row;+ }+ return prev[b.length];+}++/** Every spelling by which this route can be asked for, as squashed strings (an exact spelling, not a guess). */+function exactKeys(route) {+ const keys = new Set();+ const add = value => { const s = squash(value); if (s) keys.add(s); };+ add(route.model); add(route.name);+ add(`${route.provider}/${route.model}`);+ add(`${route.connection}/${route.model}`); add(`${route.connection} ${route.name}`); add(`${route.connection}: ${route.name}`); add(`${route.name} ${route.connection}`);+ add(`${route.name} (${route.connection})`);+ return keys;+}++/** The loose pieces a guess can match: the id, its last part after a slash, the name and the connection. */+function looseForms(route) {+ const forms = [route.model, String(route.model).split('/').pop(), route.name, `${route.connection} ${route.name}`];+ return forms.map(squash).filter(Boolean);+}++/** One line for a model in a list the assistant or the person reads. */+export function routeLine(route) {+ const where = route.local ? 'running on this computer' : route.connection;+ return `${route.name} (${where}): provider "${route.provider}", model "${route.model}"`;+}++/** The whole list as text, kept short enough for a small model's context. */+export function routeList(routes, { max = 30 } = {}) {+ const lines = routes.slice(0, max).map(r => `- ${routeLine(r)}`);+ if (routes.length > max) lines.push(`- ...and ${routes.length - max} more (ask for the name of one of them, or the part of its id you know)`);+ return lines.join('\n');+}++/**+ * Resolve one request.+ * @param {Array<{provider:string,model:string,name:string,connection:string,local:boolean}>} routes+ * @param {{provider?:string, model?:string}} request what the caller wrote (either or both)+ * @returns {{status:'inherit'}|{status:'exact',route:object,how:string}|{status:'confirm',route:object,others:object[]}|{status:'ambiguous',options:object[]}|{status:'none'}}+ * inherit: nothing was asked (the helper uses the chat's model); exact: one model; confirm: one close guess to check with the person;+ * ambiguous: several models fit; none: nothing fits.+ */+export function resolveModel(routes, request = {}) {+ const provider = typeof request.provider === 'string' ? request.provider.trim() : '';+ const model = typeof request.model === 'string' ? request.model.trim() : '';+ if (!provider && !model) return { status: 'inherit' };+ // 1. The exact route the Harness knows.+ if (provider && model) {+ const hit = routes.find(r => r.provider === provider && r.model === model);+ if (hit) return { status: 'exact', route: hit, how: 'route' };+ }+ const texts = [model, provider, provider && model ? `${provider}/${model}` : '', provider && model ? `${provider} ${model}` : ''].filter(Boolean);+ const squashed = [...new Set(texts.map(squash).filter(Boolean))];+ // 2. A spelling of one route: its id, "provider/id", its name or "connection name", in any letters.+ const exact = routes.filter(r => { const keys = exactKeys(r); return squashed.some(s => keys.has(s)); });+ // A name that fits several routes of one model id on different connections is not decided by the id alone: prefer the one the other half names.+ if (exact.length > 1 && provider && model) {+ const both = exact.filter(r => { const c = squash(r.connection); return squash(provider) === c || squash(provider) === squash(r.provider); });+ if (both.length === 1) return { status: 'exact', route: both[0], how: 'spelling' };+ }+ if (exact.length === 1) return { status: 'exact', route: exact[0], how: 'spelling' };+ if (exact.length > 1) return { status: 'ambiguous', options: exact };+ // 3. The local model by its everyday words.+ const locals = routes.filter(r => r.local);+ if (squashed.some(s => LOCAL_WORDS.has(s)) && locals.length) {+ return locals.length === 1 ? { status: 'exact', route: locals[0], how: 'local' } : { status: 'ambiguous', options: locals };+ }+ // 4. A close guess: part of an id or a name, a small typo.+ const scored = [];+ for (const route of routes) {+ const forms = looseForms(route);+ let best = Infinity;+ for (const s of squashed) {+ for (const form of forms) {+ if (s.length >= 3 && form === s) best = Math.min(best, 0);+ else if (s.length >= 4 && (form.includes(s) || s.includes(form) && form.length >= 4)) best = Math.min(best, 1);+ else if (s.length >= 5) best = Math.min(best, distance(s, form, 2) <= 2 ? 2 : Infinity);+ }+ // every word the caller wrote appears in the id or the name ("flash deepseek")+ const wanted = words(texts.join(' '));+ const haystack = squash(`${route.name} ${route.model} ${route.connection}`);+ if (wanted.length && wanted.every(w => w.length >= 2 && haystack.includes(squash(w)))) best = Math.min(best, 1.5);+ }+ if (best < Infinity) scored.push({ route, score: best });+ }+ scored.sort((a, b) => a.score - b.score || a.route.name.length - b.route.name.length);+ if (!scored.length) return { status: 'none' };+ const top = scored[0];+ const close = scored.filter(s => s.score === top.score);+ if (close.length === 1) return { status: 'confirm', route: top.route, others: scored.slice(1, 4).map(s => s.route) };+ return { status: 'ambiguous', options: scored.slice(0, 6).map(s => s.route) };+}++/** What the person or assistant typed, for a message ("deepseek", "openrouter/deepseek"). */+export const asked = request => [request.provider, request.model].filter(v => typeof v === 'string' && v.trim()).join(' / ');++/**+ * The text the `subagent` tool answers with when the model could not be settled. `null` when the call can go ahead (the caller then+ * uses the `exact` route or inherits). Plain words, with the next step; never a route key as the only thing said.+ */+export function modelProblem(routes, request) {+ const result = resolveModel(routes, request);+ const what = asked(request);+ if (result.status === 'inherit' || result.status === 'exact') return null;+ if (!routes.length) return 'No other model is set up. Nothing was started. Add a model in Models, or start the helper without naming a model.';+ if (result.status === 'confirm') {+ const r = result.route;+ return `No model is called "${what}". Nothing was started. Did you mean ${r.name} (${r.local ? 'running on this computer' : r.connection})? Ask the person "Did you mean ${r.name}?" and, when they agree, call subagent again with provider "${r.provider}" and model "${r.model}".`;+ }+ if (result.status === 'ambiguous') {+ return `More than one model fits "${what}". Nothing was started. Ask the person which one they mean, then call subagent again with that model's provider and model:\n${routeList(result.options, { max: 8 })}`;+ }+ return `No model is called "${what}". Nothing was started. These are the models that can be used:\n${routeList(routes)}\nChoose one of them, or tell the person it is not set up (they can add it in Models).`;+}diff --git a/apps/host/server/agent/plugins/strata-models.mjs b/apps/host/server/agent/plugins/strata-models.mjsnew file mode 100644index 000000000..1e8615d9a--- /dev/null+++ b/apps/host/server/agent/plugins/strata-models.mjs@@ -0,0 +1,85 @@+/**+ * Helper agents on a model the person names: the Harness `subagent` tool with a forgiving model choice.+ *+ * The pinned Harness's `subagent` tool takes an exact `provider` route key and model id, and its discovery tool lists them as+ * `api-1b2c3d4e-5f/deepseek/deepseek-v3.2`. Nobody (and no small local model) can guess that from "ask DeepSeek". This plugin keeps the+ * Harness's tool and its checks and changes three things at the seam where the tool is called:+ *+ * - the choice: the model id, `provider/id`, the name in the model picker, or "the local model" (any letters) is turned into the route+ * the Harness needs; a close guess is not started but answered with "Did you mean ...?" for the person to confirm; nothing that fits+ * is answered with the plain list of models that can be used (server/agent/model-routes.mjs);+ * - the words the assistant reads: the tool says when to use it ("ask a subagent", "ask model X") and that the model must never be looked for+ * with shell commands or in the environment;+ * - the discovery tool lists the models by the names the person knows.+ *+ * It rewrites no Harness file: the two tool definitions the Harness registers for each chat are wrapped in place (their `execute` and their+ * text), once each. A Harness update that renames them leaves the tools as they were and the test that runs the real Harness fails.+ *+ * Plain ESM, loaded by absolute path like strata-gate.mjs. `config.routes` is the table the profile wrote (model-routes.mjs documents a route).+ */+import { modelProblem, resolveModel, routeList } from '../model-routes.mjs';++export const name = 'strata-models';+export const inject = ['tools'];++/** What the assistant is told in the tool's own text, so every model (a small local one and a hosted one alike) knows when and how. */+export const SUBAGENT_GUIDANCE = ' Use this tool whenever the person asks you to ask a subagent, a helper or another model ("ask a subagent", "ask DeepSeek", "use the local model", "ask model X"): start it with this tool and do not look for the model yourself with shell commands, in the environment or on this computer. To use a particular model, give `model` as its name or id (for example "DeepSeek V3.2" or "deepseek/deepseek-v3.2", or "local" for the model running on this computer); `provider` is optional. `list_subagent_models` shows what can be used. After starting a helper, do not wait with sleep or commands: end your turn and its answer arrives as a new message.';+const MODEL_WORDS = 'The model to use for the helper: its name as the person knows it ("DeepSeek V3.2"), its id ("deepseek/deepseek-v3.2") or "local" for the model running on this computer. Omit it to use this chat\'s model.';+const PROVIDER_WORDS = 'Optional: the connection the model belongs to ("OpenRouter"). Usually the model alone is enough.';++const wrapped = new WeakSet();++/** The two wrappers' behaviour, apart from the Harness objects (the tests call these directly). */+export function subagentArgs(routes, args) {+ const result = resolveModel(routes, args ?? {});+ if (result.status !== 'exact') return { ok: result.status === 'inherit', args };+ const { provider, model } = result.route;+ return { ok: true, args: { ...args, provider, model } };+}++export function apply(ctx, config = {}) {+ const routes = Array.isArray(config.routes) ? config.routes : [];++ const wrapSubagent = def => {+ if (wrapped.has(def)) return;+ wrapped.add(def);+ const original = def.execute;+ def.description = `${def.description}${SUBAGENT_GUIDANCE}`;+ const props = def.parameters?.properties;+ if (props?.model) props.model = { ...props.model, description: MODEL_WORDS };+ if (props?.provider) props.provider = { ...props.provider, description: PROVIDER_WORDS };+ def.execute = function execute(args, exec) {+ const request = args && typeof args === 'object' ? args : {};+ const problem = modelProblem(routes, request);+ if (problem) throw new Error(problem);+ const settled = subagentArgs(routes, request);+ return original.call(this, settled.args, exec);+ };+ };++ const wrapList = def => {+ if (wrapped.has(def)) return;+ wrapped.add(def);+ def.description = 'List the models a helper agent can be started on, by the names the person knows. Call it with no arguments, then give `model` (a name or id from the list, or "local") to the subagent tool.';+ def.execute = function execute() {+ return routes.length+ ? `Models a helper can use:\n${routeList(routes)}\nStart one with the subagent tool: model = its name or id.`+ : 'No other model is set up. A helper agent uses this chat\'s own model.';+ };+ };++ const wrapAll = () => {+ let agents;+ try { agents = ctx.get('agents')?.list?.() ?? []; } catch { return; }+ for (const agent of agents) {+ try {+ const sub = ctx.tools.get('subagent', agent);+ if (sub) wrapSubagent(sub);+ const list = ctx.tools.get('list_subagent_models', agent);+ if (list) wrapList(list);+ } catch { /* a tool that is not there yet is wrapped at the next change */ }+ }+ };+ ctx.on('tools/change', wrapAll);+ wrapAll();+}diff --git a/apps/host/server/agent/preset.mjs b/apps/host/server/agent/preset.mjsindex d14c7e89e..cf85bfd26 100644--- a/apps/host/server/agent/preset.mjs+++ b/apps/host/server/agent/preset.mjs@@ -44,6 +44,7 @@ export const AGENT_PROMPT = ['Look before you change: read a file before you edit or overwrite it, and prefer a small edit to a rewrite. Search with the glob and grep tools and read files with the read tool; use the shell for running programs.','When you start a program or open a folder or file for the person, the command returning without an error means it worked: say plainly that it is open. Do not say you could not confirm it. If a command fails, say what went wrong in one sentence and what you will try next.','To open a page or a file for the person (a browser, an app, a folder), start it so the command returns at once and never wait for the program to close: on Windows use Start-Process, on macOS open, on Linux xdg-open. Then say plainly that it is open.',+ 'When the person asks you to ask a subagent, a helper or another model ("ask a subagent", "ask DeepSeek", "use the local model"), start it with the subagent tool, naming the model with its model field. Never look for a model with shell commands or in the environment, and never wait for a helper with sleep: end your turn and its answer arrives as a new message.','Tokens prefixed with @ are files or folders the person pointed at. A failed or refused action changed nothing; say so, and do not claim work you did not do.',].join('\n\n');diff --git a/apps/host/server/agent/profile.mjs b/apps/host/server/agent/profile.mjsindex b70fb63ae..fc25fb3bd 100644--- a/apps/host/server/agent/profile.mjs+++ b/apps/host/server/agent/profile.mjs@@ -55,6 +55,7 @@ export const modeOf = value => (Object.hasOwn(MODE_PRESETS, value) ? value : DEF/** The approval gate plugin (plain ESM, loaded by absolute path). */export const GATE_PLUGIN = fileURLToPath(new URL('./plugins/strata-gate.mjs', import.meta.url));/** The app's web search (DuckDuckGo, or the person's own Exa / Perplexity key), registered with the Harness's web seam. */+export const MODELS_PLUGIN = fileURLToPath(new URL('./plugins/strata-models.mjs', import.meta.url));export const SEARCH_PLUGIN = fileURLToPath(new URL('./plugins/strata-search.mjs', import.meta.url));/** The app's own tool server for the tools a person writes (instructions, commands). */export const CUSTOM_TOOLS_SCRIPT = fileURLToPath(new URL('./custom-tools-mcp.mjs', import.meta.url));@@ -203,7 +204,7 @@ export function buildProfile({ local = [], connections = [], gate = true, toolscompaction.push({ provider: route, model: inst.modelId, headroomTokens: compactionHeadroom(context, localOutputBudget(context)) });slots = Math.max(slots, Number.isFinite(inst.slots) && inst.slots >= 1 ? Math.floor(inst.slots) : 1);const shaped = addShaped(route, providers[route], inst.baseUrl);- routes.push({ route, fp: fingerprint(providers[route], env[keyEnv]), kind: 'local', instanceId: inst.id, modelId: inst.modelId, name: inst.label || inst.modelId, contextWindow: context, ...(shaped ? { shaped } : {}) });+ routes.push({ route, fp: fingerprint(providers[route], env[keyEnv]), kind: 'local', connectionName: 'this computer', instanceId: inst.id, modelId: inst.modelId, name: inst.label || inst.modelId, contextWindow: context, ...(shaped ? { shaped } : {}) });});connections.forEach(conn => {@@ -242,7 +243,7 @@ export function buildProfile({ local = [], connections = [], gate = true, toolsconst fp = fingerprint(providers[route], conn.apiKey ?? '');const shaped = ownServer ? addShaped(route, providers[route], baseURL) : null;for (const m of conn.models) { const ctx = m.contextMax ?? ASSUMED_API_CONTEXT; compaction.push({ provider: route, model: m.id, headroomTokens: compactionHeadroom(ctx, reply(m)) }); }- for (const m of conn.models) routes.push({ route, fp, kind: 'api', connectionId: conn.id, modelId: m.id, name: m.name || m.id, contextWindow: m.contextMax ?? ASSUMED_API_CONTEXT, ...(shaped ? { shaped } : {}) });+ for (const m of conn.models) routes.push({ route, fp, kind: 'api', connectionId: conn.id, connectionName: conn.name, modelId: m.id, name: m.name || m.id, contextWindow: m.contextMax ?? ASSUMED_API_CONTEXT, ...(shaped ? { shaped } : {}) });});const defaultRoute = routes.find(r => r.kind === 'local') ?? null;@@ -263,6 +264,8 @@ export function buildProfile({ local = [], connections = [], gate = true, tools? [{ id: 'web', config: { searchProvider: 'deepseek-official', fetchProvider: 'http' } }, { id: 'web-search-deepseek', config: { apiKeyEnv: 'STRATA_SEARCH_KEY' } }]: [{ id: 'web', config: { searchProvider: keyed ?? DDG_PROVIDER_ID, fetchProvider: 'http' } }, { id: 'web-search-deepseek', disabled: true },{ insert: [{ id: 'strata-web-search', name: SEARCH_PLUGIN, config: { provider: keyed ?? 'duckduckgo', keyEnv: 'STRATA_SEARCH_KEY' } }] }];+ /** The models a helper agent may be started on: the table the model-choice plugin and the Harness's allow-list are written from. */+ const subagentRoutes = routes.map(r => ({ provider: r.route, model: r.modelId, name: r.name, connection: r.connectionName, local: r.kind === 'local' }));const entries = [...(defaultRoute ? [{ id: 'agent-default-model', name: '@deepseek-ai/dsh-agent-default-model', config: { provider: defaultRoute.route, model: defaultRoute.modelId } }] : []),{ id: 'llm-pi-ai', name: '@deepseek-ai/dsh-llm-pi-ai', config: { providers } },@@ -271,6 +274,9 @@ export function buildProfile({ local = [], connections = [], gate = true, tools{ id: 'subagent', config: { maxActiveSubagents: slots > 0 ? Math.max(slots, MIN_LOCAL_HELPERS) : DEFAULT_API_HELPERS } },// Manual asks before a change runs, so the person sees one Approve/Deny card and nothing has happened yet....(gate ? [{ insert: [{ id: 'strata-gate', name: GATE_PLUGIN }] }] : []),+ // Helper agents on a model the person names: every model the app can reach is allowed, and the plugin makes the choice forgiving (plugins/strata-models.mjs).+ ...(subagentRoutes.length ? [{ id: 'subagent-model-selection-settings', config: { enabled: true, allowedModels: subagentRoutes.map(r => ({ provider: r.provider, model: r.model })) } }] : []),+ ...(subagentRoutes.length ? [{ insert: [{ id: 'strata-models', name: MODELS_PLUGIN, config: { routes: subagentRoutes } }] }] : []),...(mcp.length || ownRows.length ? [{ insert: [...mcp, ...ownRows] }] : []),...webRows,// The reminder tools would be a second scheduler beside the app's Tasks. The tool groups the person switched off in Settings -> Tools are left out.diff --git a/apps/host/tests/agent-subagent-models.test.mjs b/apps/host/tests/agent-subagent-models.test.mjsnew file mode 100644index 000000000..cfe9d31a3--- /dev/null+++ b/apps/host/tests/agent-subagent-models.test.mjs@@ -0,0 +1,112 @@+/**+ * Helper agents on a model the person names (server/agent/model-routes.mjs and plugins/strata-models.mjs).+ * Pure tests always run; the real-Harness tests need STRATA_HARNESS_DIR and skip loudly without it.+ */+import test from 'node:test';+import assert from 'node:assert/strict';+import { 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';+import { resolveModel, modelProblem, routeList } from '../server/agent/model-routes.mjs';+import { AGENT_PROMPT } from '../server/agent/preset.mjs';++const HARNESS = process.env.STRATA_HARNESS_DIR;+const skip = !HARNESS || !resolveHarness({ env: process.env }).ok ? 'STRATA_HARNESS_DIR is not set to a built Harness' : false;++const routes = [+ { provider: 'strata-local', model: 'gyro-gyro-s', name: 'qwen3.8-flash-next-gyro-gyro-s', connection: 'this computer', local: true },+ { provider: 'api-aaaa', model: 'deepseek/deepseek-v3.2', name: 'DeepSeek: DeepSeek V3.2', connection: 'OpenRouter', local: false },+ { provider: 'api-aaaa', model: 'anthropic/claude-sonnet-4.5', name: 'Anthropic: Claude Sonnet 4.5', connection: 'OpenRouter', local: false },+ { provider: 'api-bbbb', model: 'deepseek-chat', name: 'DeepSeek Chat', connection: 'DeepSeek', local: false },+];++test('nothing named: the helper uses the chat model', () => {+ assert.equal(resolveModel(routes, {}).status, 'inherit');+ assert.equal(modelProblem(routes, {}), null);+});++test('exact route, exact id, provider/id, connection and name, in any letters', () => {+ const want = (request, id) => { const r = resolveModel(routes, request); assert.equal(r.status, 'exact', JSON.stringify(request)); assert.equal(r.route.model, id); };+ want({ provider: 'api-aaaa', model: 'deepseek/deepseek-v3.2' }, 'deepseek/deepseek-v3.2');+ want({ model: 'deepseek/deepseek-v3.2' }, 'deepseek/deepseek-v3.2');+ want({ model: 'DeepSeek/DeepSeek-V3.2' }, 'deepseek/deepseek-v3.2');+ want({ provider: 'openrouter', model: 'deepseek/deepseek-v3.2' }, 'deepseek/deepseek-v3.2');+ want({ model: 'openrouter/deepseek/deepseek-v3.2' }, 'deepseek/deepseek-v3.2');+ want({ model: 'DeepSeek: DeepSeek V3.2' }, 'deepseek/deepseek-v3.2');+ want({ model: 'deepseek chat' }, 'deepseek-chat');+ want({ model: 'Local' }, 'gyro-gyro-s');+ want({ provider: 'strata-local', model: 'gyro-gyro-s' }, 'gyro-gyro-s');+});++test('a close guess is checked with the person, several fits are listed, nothing fitting lists the models', () => {+ const guess = resolveModel(routes, { model: 'claude sonnet' });+ assert.equal(guess.status, 'confirm'); assert.equal(guess.route.model, 'anthropic/claude-sonnet-4.5');+ assert.match(modelProblem(routes, { model: 'claude sonnet' }), /Did you mean Anthropic: Claude Sonnet 4\.5/);+ const several = resolveModel(routes, { model: 'deepseek' });+ assert.equal(several.status, 'ambiguous'); assert.ok(several.options.length >= 2);+ const none = modelProblem(routes, { model: 'llama banana' });+ assert.match(none, /No model is called "llama banana"/); assert.match(none, /DeepSeek Chat/); assert.match(none, /Nothing was started/);+ assert.match(modelProblem([], { model: 'x' }), /No other model is set up/);+ assert.match(routeList(routes), /running on this computer/);+});++test('the assistant is told to use the subagent tool when asked for a subagent or a model', () => {+ assert.match(AGENT_PROMPT, /ask a subagent/); assert.match(AGENT_PROMPT, /Never look for a model with shell commands/);+});++async function rig(t) {+ const local = await startScriptedWorker();+ const remote = await startScriptedWorker({ model: 'deepseek/deepseek-v3.2' });+ const dir = mkdtempSync(join(tmpdir(), 'strata-sub-'));+ const ws = join(dir, 'ws'); mkdirSync(ws, { recursive: true });+ const bridge = createAgentBridge({+ dataDir: dir, env: process.env, startTimeoutMs: 90_000,+ localInstances: () => [{ id: 'inst-1', label: 'Local Scripted', baseUrl: local.url, modelId: 'scripted-model', context: 32768, slots: 2 }],+ connections: () => [{ id: 'conn-1', name: 'OpenRouter', baseUrl: remote.url, protocol: 'openai-chat', apiKey: 'k', models: [{ id: 'deepseek/deepseek-v3.2', name: 'DeepSeek V3.2', contextMax: 32768 }] }],+ });+ t.after(async () => { await bridge.close(); await local.close(); await remote.close(); try { rmSync(dir, { recursive: true, force: true, maxRetries: 3 }); } catch { /* best effort */ } });+ const call = async (chatId, args) => {+ const frames = [];+ await bridge.runTurn({ chatId, message: `SCRIPT:call subagent ${JSON.stringify(args)}`, workspacePath: ws, mode: 'bypass', onFrame: f => frames.push(f) });+ return { frames, text: frames.filter(f => f.type === 'delta').map(f => f.text).join('') };+ };+ return { local, remote, bridge, call, ws };+}++test('the real Harness: the model sees guidance and the discovery list, and a name starts the helper on that model', { skip }, async (t) => {+ const r = await rig(t);+ const first = await r.call('m1', { description: 'Weather', prompt: 'SCRIPT:echo grey', model: 'DeepSeek V3.2' });+ const tools = JSON.parse([...r.local.requests].reverse().find(q => q.toolNames.length).raw).tools;+ const sub = tools.find(x => x.function.name === 'subagent').function;+ assert.match(sub.description, /ask a subagent/); assert.match(sub.description, /do not look for the model yourself/);+ assert.match(sub.parameters.properties.model.description, /"local"/);+ assert.ok(tools.some(x => x.function.name === 'list_subagent_models'));+ // the helper ran on the remote route, not on the chat's model+ for (let i = 0; i < 60 && !r.remote.requests.length; i++) await new Promise(res => setTimeout(res, 250));+ assert.ok(r.remote.requests.length >= 1, `the helper reached the OpenRouter mock (${first.text})`);+});++test('the real Harness: a close guess and an unknown model are answered in plain words and start nothing', { skip }, async (t) => {+ const r = await rig(t);+ const guess = await r.call('m2', { description: 'Weather', prompt: 'x', model: 'deepseek v3' });+ assert.match(guess.text, /Did you mean DeepSeek V3\.2/);+ const none = await r.call('m3', { description: 'Weather', prompt: 'x', model: 'llama banana' });+ assert.match(none.text, /No model is called "llama banana"/);+ const seen = [...r.local.requests].reverse().find(q => q.lastRole === 'tool').raw;+ assert.match(seen, /DeepSeek V3.2/, 'the list the assistant read names the models');+ await new Promise(res => setTimeout(res, 1500));+ assert.equal(r.remote.requests.length, 0, 'nothing was started');+});++test('the real Harness: naming the local model, and naming no model, both work', { skip }, async (t) => {+ const r = await rig(t);+ const before = r.local.requests.length;+ await r.call('m4', { description: 'Local', prompt: 'SCRIPT:echo hi', model: 'the local model' });+ await r.call('m5', { description: 'Plain', prompt: 'SCRIPT:echo hi' });+ for (let i = 0; i < 40 && r.local.requests.filter(q => q.directive === 'echo').length < 2; i++) await new Promise(res => setTimeout(res, 250));+ assert.ok(r.local.requests.length > before);+ assert.equal(r.remote.requests.length, 0);+});diff --git a/apps/host/tests/agent-tools.test.mjs b/apps/host/tests/agent-tools.test.mjsindex b4d3b6acb..b2065e10f 100644--- a/apps/host/tests/agent-tools.test.mjs+++ b/apps/host/tests/agent-tools.test.mjs@@ -105,7 +105,7 @@ test('the agent is offered exactly these tools: everything useful including webconst r = await rig(t);await r.run('inv', 'SCRIPT:echo hi');const offered = [...r.worker.requests].reverse().find(q => q.toolNames.length)?.toolNames.sort();- assert.deepEqual(offered, ['create_goal', 'edit', 'get_goal', 'glob', 'grep', 'interrupt_agent', 'job_kill', 'job_list', 'job_output', 'list_agents', 'present', 'pwsh', 'read', 'read_image', 'send_message', 'skill', 'subagent', 'subagent_fork', 'todo_write', 'update_goal', 'web_fetch', 'web_search', 'workflow', 'working_directory', 'write'].sort());+ assert.deepEqual(offered, ['create_goal', 'edit', 'get_goal', 'glob', 'grep', 'interrupt_agent', 'job_kill', 'job_list', 'job_output', 'list_agents', 'list_subagent_models', 'present', 'pwsh', 'read', 'read_image', 'send_message', 'skill', 'subagent', 'subagent_fork', 'todo_write', 'update_goal', 'web_fetch', 'web_search', 'workflow', 'working_directory', 'write'].sort());assert.ok(!offered.some(n => n.startsWith('schedule_')) && offered.includes('web_search') && !offered.includes('ask_user_question') && !offered.includes('exit_plan_mode'));});