Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

seed OpenRouter's free stealth/ox-alpha model and stop OpenCode billing a model nobody chose

[._.]/ Adam Eivyd1e608c775c3
diff --git a/data.reference/providers.json b/data.reference/providers.json
index e06a3ef661..b6c8c51310 100644
--- a/data.reference/providers.json
+++ b/data.reference/providers.json
@@ -422,11 +422,11 @@
"type": "api",
"endpoint": "https://openrouter.ai/api/v1",
"apiKey": "",
- "models": ["openrouter/auto"],
- "defaultModel": "openrouter/auto",
+ "models": ["openrouter/auto", "stealth/ox-alpha"],
+ "defaultModel": "stealth/ox-alpha",
"lightModel": "openrouter/auto",
- "mediumModel": "openrouter/auto",
- "heavyModel": "openrouter/auto",
+ "mediumModel": "stealth/ox-alpha",
+ "heavyModel": "stealth/ox-alpha",
"timeout": 300000,
"enabled": false,
"envVars": {},
@@ -439,8 +439,8 @@
"command": "opencode",
"args": ["run"],
"endpoint": "https://openrouter.ai/api/v1",
- "models": ["openrouter/auto"],
- "defaultModel": "openrouter/auto",
+ "models": ["openrouter/auto", "stealth/ox-alpha"],
+ "defaultModel": "stealth/ox-alpha",
"gatewayBacked": "openrouter",
"timeout": 600000,
"enabled": false,
@@ -457,8 +457,8 @@
"command": "opencode",
"args": [],
"endpoint": "https://openrouter.ai/api/v1",
- "models": ["openrouter/auto"],
- "defaultModel": "openrouter/auto",
+ "models": ["openrouter/auto", "stealth/ox-alpha"],
+ "defaultModel": "stealth/ox-alpha",
"gatewayBacked": "openrouter",
"timeout": 600000,
"enabled": false,
diff --git a/scripts/migrations/294-openrouter-ox-alpha.js b/scripts/migrations/294-openrouter-ox-alpha.js
new file mode 100644
index 0000000000..3465d366cf
--- /dev/null
+++ b/scripts/migrations/294-openrouter-ox-alpha.js
@@ -0,0 +1,87 @@
+/**
+ * Add OpenRouter's `stealth/ox-alpha` to the shipped OpenRouter provider presets
+ * and point their default tier at it.
+ *
+ * Migration 293 seeded the three OpenRouter records (`openrouter` API +
+ * `opencode-openrouter` CLI/TUI wrappers) with only `openrouter/auto`, the
+ * gateway's own router. Ox Alpha is a reasoning model aimed at long-horizon
+ * agentic coding — 1M context, tool calling, and currently billed at zero on
+ * OpenRouter — so it is the model a wrapper should reach for by default, while
+ * `openrouter/auto` stays listed as the light tier.
+ *
+ * A wrapper's model list is otherwise refreshed from the gateway's `/models`
+ * endpoint, which needs the sibling API record's key; seeding the id here means
+ * an install can select Ox Alpha the moment it pastes a key, with no refresh
+ * round-trip first.
+ *
+ * Conservative in the same way 292 is — see `isUntouchedSeed` below for what
+ * that buys and what it deliberately leaves alone.
+ *
+ * Kept in lockstep with data.reference/providers.json and
+ * server/lib/aiToolkit/defaults/providers.sample.json. Later default changes
+ * require a new migration.
+ */
+
+import { readProvidersDoc, writeJsonAtomic } from './_lib.js';
+
+const AUTO_MODEL = 'openrouter/auto';
+// Namespaced for OpenCode this becomes `openrouter/stealth/ox-alpha` — the
+// gateway's ids are already `vendor/model` and are never stored prefixed
+// (`prefixOpencodeModel` in server/lib/providerModels.js).
+const OX_ALPHA = 'stealth/ox-alpha';
+const NEW_MODELS = [AUTO_MODEL, OX_ALPHA];
+
+// Each row is the record's POST-migration tier block, so the table reads as the
+// state it produces and stays row-for-row comparable with the two seed JSONs.
+// Its keys double as the guard list — every tier a row names must still be
+// parked on the router for that record to count as untouched.
+//
+// The API record carries four tier pointers; the CLI/TUI wrappers carry only
+// `defaultModel`. `lightModel` stays on the router: Ox Alpha's reasoning is
+// mandatory and defaults to max effort, which is the wrong trade for a cheap
+// light-tier call even at zero cost.
+const TARGETS = {
+ openrouter: {
+ defaultModel: OX_ALPHA, lightModel: AUTO_MODEL, mediumModel: OX_ALPHA, heavyModel: OX_ALPHA,
+ },
+ 'opencode-openrouter': { defaultModel: OX_ALPHA },
+ 'opencode-openrouter-tui': { defaultModel: OX_ALPHA },
+};
+
+// Untouched means: exactly 293's one-model list, with every tier pointer still
+// parked on it. Anything else — a list refreshed from the gateway, a trimmed
+// list, a pinned model — is a user having spoken, and is left alone.
+const isUntouchedSeed = (provider, tiers) =>
+ Array.isArray(provider?.models)
+ && provider.models.length === 1
+ && provider.models[0] === AUTO_MODEL
+ && tiers.every((tier) => provider[tier] === AUTO_MODEL);
+
+export default {
+ async up({ rootDir }) {
+ const doc = await readProvidersDoc({ rootDir });
+ // `readProvidersDoc` is deliberately silent — each caller owns its own log
+ // copy, so an install that skips still says why on the boot line.
+ if (!doc.ok) {
+ const why = doc.reason === 'no-file'
+ ? 'not present (a fresh install seeds OpenRouter from data.reference)'
+ : `unreadable: ${doc.reason === 'unreadable' ? 'invalid JSON' : 'no providers map'}`;
+ console.log(`📄 data/providers.json ${why} — skipping the OpenRouter ${OX_ALPHA} preset`);
+ return { ok: false, reason: doc.reason, updated: 0 };
+ }
+
+ let updated = 0;
+ for (const [id, tierBlock] of Object.entries(TARGETS)) {
+ const provider = doc.providers[id];
+ if (!isUntouchedSeed(provider, Object.keys(tierBlock))) continue;
+ provider.models = [...NEW_MODELS];
+ Object.assign(provider, tierBlock);
+ updated += 1;
+ }
+
+ if (!updated) return { ok: true, reason: 'already-current-or-custom', updated: 0 };
+ await writeJsonAtomic(doc.path, doc.config);
+ console.log(`📝 ${doc.path}: added ${OX_ALPHA} to ${updated} OpenRouter provider preset${updated === 1 ? '' : 's'}`);
+ return { ok: true, reason: 'updated', updated };
+ },
+};
diff --git a/scripts/migrations/294-openrouter-ox-alpha.test.js b/scripts/migrations/294-openrouter-ox-alpha.test.js
new file mode 100644
index 0000000000..0350b12ca2
--- /dev/null
+++ b/scripts/migrations/294-openrouter-ox-alpha.test.js
@@ -0,0 +1,85 @@
+import { describe, it, expect, beforeEach, afterEach } from 'vitest';
+import { mkdtempSync, rmSync, writeFileSync, readFileSync, mkdirSync } from 'fs';
+import { tmpdir } from 'os';
+import { join } from 'path';
+
+import migration from './294-openrouter-ox-alpha.js';
+
+const AUTO = 'openrouter/auto';
+const OX_ALPHA = 'stealth/ox-alpha';
+const writeJson = (path, value) => writeFileSync(path, `${JSON.stringify(value, null, 2)}\n`);
+const readJson = (path) => JSON.parse(readFileSync(path, 'utf8'));
+
+// Exactly what migration 293 leaves behind.
+const seededApi = () => ({
+ models: [AUTO], defaultModel: AUTO, lightModel: AUTO, mediumModel: AUTO, heavyModel: AUTO,
+});
+const seededWrapper = () => ({ models: [AUTO], defaultModel: AUTO });
+
+describe('migration 294 — OpenRouter Ox Alpha default', () => {
+ let rootDir;
+ let providersPath;
+
+ beforeEach(() => {
+ rootDir = mkdtempSync(join(tmpdir(), 'migration-294-'));
+ mkdirSync(join(rootDir, 'data'), { recursive: true });
+ providersPath = join(rootDir, 'data/providers.json');
+ });
+
+ afterEach(() => rmSync(rootDir, { recursive: true, force: true }));
+
+ it('adds Ox Alpha to the API record and every wrapper, keeping the router as the light tier', async () => {
+ writeJson(providersPath, {
+ providers: {
+ openrouter: seededApi(),
+ 'opencode-openrouter': seededWrapper(),
+ 'opencode-openrouter-tui': seededWrapper(),
+ },
+ });
+
+ const result = await migration.up({ rootDir });
+ const providers = readJson(providersPath).providers;
+
+ expect(result).toMatchObject({ ok: true, reason: 'updated', updated: 3 });
+ expect(providers.openrouter).toEqual({
+ models: [AUTO, OX_ALPHA],
+ defaultModel: OX_ALPHA,
+ lightModel: AUTO,
+ mediumModel: OX_ALPHA,
+ heavyModel: OX_ALPHA,
+ });
+ for (const id of ['opencode-openrouter', 'opencode-openrouter-tui']) {
+ expect(providers[id]).toEqual({ models: [AUTO, OX_ALPHA], defaultModel: OX_ALPHA });
+ }
+ });
+
+ it('leaves a refreshed or user-pinned record alone', async () => {
+ const refreshed = { models: [AUTO, 'anthropic/claude-sonnet-4', OX_ALPHA], defaultModel: AUTO };
+ const pinned = { models: [AUTO], defaultModel: 'anthropic/claude-sonnet-4' };
+ writeJson(providersPath, { providers: { 'opencode-openrouter-tui': refreshed, 'opencode-openrouter': pinned } });
+
+ const result = await migration.up({ rootDir });
+
+ expect(result).toMatchObject({ ok: true, reason: 'already-current-or-custom', updated: 0 });
+ expect(readJson(providersPath).providers).toEqual({
+ 'opencode-openrouter-tui': refreshed,
+ 'opencode-openrouter': pinned,
+ });
+ });
+
+ it('is a no-op on a second run', async () => {
+ writeJson(providersPath, { providers: { 'opencode-openrouter-tui': seededWrapper() } });
+
+ await migration.up({ rootDir });
+ const afterFirst = readJson(providersPath);
+ const second = await migration.up({ rootDir });
+
+ expect(second).toMatchObject({ updated: 0 });
+ expect(readJson(providersPath)).toEqual(afterFirst);
+ });
+
+ it('skips an install with no providers file', async () => {
+ const result = await migration.up({ rootDir });
+ expect(result).toMatchObject({ ok: false, reason: 'no-file', updated: 0 });
+ });
+});
diff --git a/scripts/migrations/_lib.js b/scripts/migrations/_lib.js
index bd5df1b97b..5a5bd2bee1 100644
--- a/scripts/migrations/_lib.js
+++ b/scripts/migrations/_lib.js
@@ -20,7 +20,11 @@
* 7. Seeded-provider-tier bumps — `makeSeededProviderTierMigration` collapses
* the exact-match → rewrite-models → swap-retired-pointers shell that
* 032 / 058 / 153 / 206 each hand-copied. Those four stay frozen; the
- * factory is for the next bump.
+ * factory is for the next RETIREMENT bump. It expresses id→id retirement
+ * only: `idMap` maps 1:1 over `oldModels`, and `swapTierPointers` moves
+ * EVERY pointer off a retired id. An ADDITIVE change — appending a model
+ * while keeping the old one listed, or re-pointing some tiers but not all
+ * (292, 294) — does not fit, and hand-rolls on `readProvidersDoc` instead.
*
* Families 5 and 7 both target `data/providers.json` and share its
* read → parse → shape-guard preamble via `readProvidersDoc`; each still owns
diff --git a/server/lib/README.md b/server/lib/README.md
index aa4564e086..829a70019f 100644
--- a/server/lib/README.md
+++ b/server/lib/README.md
@@ -140,7 +140,7 @@ The barrel `server/lib/index.js` is a machine-checkable enumeration of every pub
| `providerFamilies.js` | Subscription-quota FAMILY identity — `PROVIDER_FAMILIES` (`{ id, label, matches }` for claude/codex/agy/grok), `PROVIDER_FAMILY_IDS`, `familyLabel`, `familyForProvider(config)` → family id or null (local-runtime wrappers and API-only providers belong to none). The pure half of the registry `services/providerUsage.js` attaches quota `fetch`ers to, so cost attribution and route validation can ask "which plan is this provider on?" without importing the PTY-scrape graph. Distinct from `providerVendors.js`, which is argv-shaped and includes vendors with no subscription quota. |
| `providerGateways.js` | `PROVIDER_GATEWAYS` — one row per hosted OpenAI-compatible gateway an OpenCode CLI/TUI wrapper can front-end (`orcarouter`, `openrouter`), plus `PROVIDER_GATEWAY_IDS`, `gatewayById`, `isGatewayNamespace(ns)` and `gatewayForProvider(config)` → row or null. Each row's `id` is simultaneously the OpenCode provider namespace, the `gatewayBacked` marker value, and the id of the sibling `api` record that owns the key — so the sibling lookup is `providers[gateway.id]` and an OrcaRouter key can never satisfy an OpenRouter wrapper. Replaces the `orcarouterBacked` boolean + literal `'orcarouter'` that had been hand-copied across ~15 server and client files (namespace resolution, the OpenCode config builder, both zod schemas, the model-fetcher table, the sibling-key attach, the prerequisite check, and the two "not a local runtime" carve-outs in `cliChildEnv.js`/`localProviderRuntime.js`). Reads the legacy per-gateway boolean FOREVER, so stored records are never rewritten. Distinct from a local runtime (`ollamaBacked`, `vllmBacked`, …): remote, always authenticating, and no thinking toggle. Deliberately mirrored in `aiToolkit/internal/gateways.js` (the vendored toolkit may not import out) and `client/src/utils/providers.js` (the browser cannot import server code) — `providerGateways.parity.test.js` fails when the first two drift. Dependency-light: imports nothing. |
| `providerTranscriptUsage.js` | Parsers for the real per-message token counts the coding CLIs write to disk (0 tokens to read) — `parseClaudeTranscript` (`~/.claude/projects/<cwd-slug>/*.jsonl`), `parseCodexRollout` (`~/.codex/sessions/YYYY/MM/DD/rollout-*.jsonl`), `claudeProjectSlug`, `totalTranscriptTokens`. Both de-duplicate a format hazard that otherwise inflates counts badly: Claude repeats one response across several lines sharing a `message.id`, and Codex's `total_token_usage` is cumulative and repeated. Each parser returns per-model buckets (`byModel`) plus the message keys it counted (`countedKeys`), and accepts an `exclude` set — that is what stops two overlapping PortOS runs from both billing the same messages. Tolerant of truncated (mid-write) files; consumed by `services/usageReconciler.js`. |
-| `opencodeConfig.js` | OpenCode config builder — `buildOpencodeEnvVars(provider, model)` builds dynamic `OPENCODE_CONFIG_CONTENT` declaring bare model ids under the selected local provider (`ollama` or `mtplx`) for marked OpenCode providers. Fixes --model rejection. |
+| `opencodeConfig.js` | OpenCode config builder — `buildOpencodeEnvVars(provider, model)` builds dynamic `OPENCODE_CONFIG_CONTENT` declaring model ids under the namespace the provider's marker selects: a local runtime (`ollama` / `mtplx` / `llama` / `vllm` / `sglang`, bare ids) or a hosted gateway from `providerGateways.js` (`vendor/model` ids kept whole). Fixes --model rejection. Also attaches the key for a key-bearing namespace, and pins `small_model` to the run model for a gateway so OpenCode's own side calls (titles, summarization) can't land on its built-in default — a billed model the operator never chose. |
| `localProviderRuntime.js` | Which LOCAL daemon a provider talks to, and where — `LOCAL_RUNTIMES` (llama.cpp / Ollama / LM Studio / MTPLX / vLLM: label, binary, canonical base URL read from `opencodeConfig.js` rather than re-typed, manage/docs links, model-download hint), `localBackendForProvider` + `localEndpointPort` + `isLocalInstanceHost` (moved here from `services/localModelHealing.js`, which re-exports them, so the healing path and the readiness checklist classify a provider identically — loopback/bind-all only, so a LAN/Tailscale peer on port 11434 is NOT claimed as a local daemon), `localRuntimeKind(provider)` (the `*Backed` markers first, then that classifier; `orcarouter` excluded as a remote API), `localRuntimeForProvider(provider)` → the row with the endpoint the provider ITSELF configures (`OPENCODE_CONFIG_CONTENT`'s `baseURL`, `ANTHROPIC_BASE_URL`, or `endpoint`), then the `OLLAMA_URL`/`OLLAMA_HOST`/`LM_STUDIO_URL` override the backend managers read, then the canonical default — and `null` when that resolved endpoint fails `isLocalInstanceEndpoint` (an API provider on another machine has no local daemon to check, whatever its name says) — plus `normalizeOpenAiBaseUrl`. Pure; the probing half is `services/providerReadiness.js`. Optional `setupStateDetail` overrides `providerReadiness`'s per-state prose for a runtime whose local setup is not a model cache (vLLM's is a compose project). |
| `managedDaemon.js` | Shared mechanism for the local daemons PortOS runs as optional PM2 processes (`services/llamaServerManager.js` → `portos-llama-server`, `services/mtplxServerManager.js` → `portos-mtplx`). `createDaemonLogBuffer({maxLines?})` is the bounded timestamped ring buffer of what PortOS logged around a launch, plus `withPm2Logs(output)` → that buffer followed by anything `pm2 logs` has which it doesn't already hold, deduped and re-capped (PM2's lines are a VIEW, never folded into the buffer — PM2 owns them and re-reads them every status call). `pm2ArgValue(args, flag)` reads one value back out of a PM2 process's recorded argv so a manager can recover a still-online daemon's launch config after a PortOS restart; `null` means the flag was absent, which a relaunch must leave off rather than defaulting. Deliberately mechanism only — what a launch line means and when a daemon may start is exactly what differs between the two. |
| `mtplxModels.js` | `listMtplxCachedModels({command?})` → `{models, error}` from `mtplx models --json` (a local directory listing — no network, no model load) and `pickMtplxCachedModel(models)` → the repo id to hand `mtplx serve --model`. `models: null` means the cache could not be READ (no binary, command failed, unparseable) and is deliberately distinct from `[]` (read, and empty), because `services/localRuntimeSetup.js` starts MTPLX on its own default in the first case and refuses with the `mtplx pull` command in the second. Exists because `mtplx serve` defaults `--model` to one hard-coded checkpoint and exits 1 before binding when that repo is not cached — even on a host holding a different MTP model that serves fine. Picks only entries MTPLX itself calls complete (`validation.ok !== false`, so a half-finished pull is not served), preferring one with a recorded `mtplx_runtime.json` exactness contract. `describeMtplxCache(cache)` → `{state: 'unknown'\|'empty'\|'partial'\|'ready', model, count, error}` folds both into the one value `services/providerReadiness.js` puts on the checklist and `describeRuntimeSetup` picks a button from — so an empty cache is named up front instead of only inside the failure of a Start that could never work. |
diff --git a/server/lib/aiToolkit/defaults/providers.sample.json b/server/lib/aiToolkit/defaults/providers.sample.json
index 47939d76e4..b56cb62c8c 100644
--- a/server/lib/aiToolkit/defaults/providers.sample.json
+++ b/server/lib/aiToolkit/defaults/providers.sample.json
@@ -342,11 +342,11 @@
"type": "api",
"endpoint": "https://openrouter.ai/api/v1",
"apiKey": "",
- "models": ["openrouter/auto"],
- "defaultModel": "openrouter/auto",
+ "models": ["openrouter/auto", "stealth/ox-alpha"],
+ "defaultModel": "stealth/ox-alpha",
"lightModel": "openrouter/auto",
- "mediumModel": "openrouter/auto",
- "heavyModel": "openrouter/auto",
+ "mediumModel": "stealth/ox-alpha",
+ "heavyModel": "stealth/ox-alpha",
"timeout": 300000,
"enabled": false,
"envVars": {},
@@ -359,8 +359,8 @@
"command": "opencode",
"args": ["run"],
"endpoint": "https://openrouter.ai/api/v1",
- "models": ["openrouter/auto"],
- "defaultModel": "openrouter/auto",
+ "models": ["openrouter/auto", "stealth/ox-alpha"],
+ "defaultModel": "stealth/ox-alpha",
"gatewayBacked": "openrouter",
"timeout": 600000,
"enabled": false,
@@ -377,8 +377,8 @@
"command": "opencode",
"args": [],
"endpoint": "https://openrouter.ai/api/v1",
- "models": ["openrouter/auto"],
- "defaultModel": "openrouter/auto",
+ "models": ["openrouter/auto", "stealth/ox-alpha"],
+ "defaultModel": "stealth/ox-alpha",
"gatewayBacked": "openrouter",
"timeout": 600000,
"enabled": false,
diff --git a/server/lib/opencodeConfig.js b/server/lib/opencodeConfig.js
index 949095fc2b..5f2d2db531 100644
--- a/server/lib/opencodeConfig.js
+++ b/server/lib/opencodeConfig.js
@@ -18,7 +18,7 @@
* `provider.<local-backend>.models` with bare ids.
*/
-import { getOpencodeLocalProviderNamespace, isOpencodeCommand } from './providerModels.js';
+import { getOpencodeLocalProviderNamespace, isOpencodeCommand, prefixOpencodeModel } from './providerModels.js';
import { PROVIDER_GATEWAYS, PROVIDER_GATEWAY_IDS, gatewayById, isGatewayNamespace } from './providerGateways.js';
import { PORTS } from './ports.js';
@@ -226,6 +226,10 @@ export function buildAgentGeneration(generation, providerKey) {
* is invented), identical to the shipped base. When `base` is absent/unusable,
* the canonical endpoint for the selected local runtime is used.
*
+ * NOT the whole config: `small_model` is applied downstream by
+ * `buildOpencodeEnvVars`, which is the only caller that knows THIS run's single
+ * model (this one takes a list). A config built here alone is unpinned.
+ *
* @param {string|string[]|null|undefined} models
* @param {object|null} [base] - existing config to merge into (a fresh clone is made)
* @param {'ollama'|'mtplx'|'llama'|'vllm'|'sglang'|string} [providerKey='ollama']
@@ -314,6 +318,24 @@ export function buildOpencodeEnvVars(provider, model) {
model,
];
const config = buildOpencodeConfig(ids, base, providerKey, provider);
+ // Pin the auxiliary model OpenCode uses for its OWN side work (session titles,
+ // summarization). Left unset it falls back to its built-in default, which is a
+ // real hosted model nobody here chose — an OpenRouter run on the free
+ // `stealth/ox-alpha` otherwise emits paid `google/gemini-3.7-flash` calls
+ // alongside it, and a local run on a box carrying an `ANTHROPIC_API_KEY` /
+ // `OPENAI_API_KEY` (spawns inherit `process.env`, see `cliChildEnv.js`) can
+ // reach a cloud provider the operator never opted into — exactly the
+ // unrequested provider call the root CLAUDE.md's AI Provider Usage Policy
+ // forbids.
+ //
+ // So this is unconditional, not gateway-only: the invariant is that a run stays
+ // on the model it was dispatched with, and it holds for every namespace. The
+ // run model is always in the declared models map above, so it always resolves.
+ // A stored config that already pins `small_model` wins — same
+ // customization-preserving contract as the base merge above.
+ if (!config.small_model && model) {
+ config.small_model = prefixOpencodeModel(provider, model);
+ }
// Every key-bearing namespace reads the SAME `provider.apiKey` field; a
// gateway's `legacyApiKeyField` (`orcarouterApiKey`) is an older alias kept
// readable forever. vLLM's compose stack is started with `VLLM_API_KEY`, so a
diff --git a/server/lib/opencodeConfig.test.js b/server/lib/opencodeConfig.test.js
index 20262b9f0e..4be5c46463 100644
--- a/server/lib/opencodeConfig.test.js
+++ b/server/lib/opencodeConfig.test.js
@@ -393,3 +393,41 @@ describe('SGLang OpenCode config', () => {
expect(keyed.provider.sglang.options.apiKey).toBe('operator-key');
});
});
+
+describe('small-model pin', () => {
+ const gatewayProvider = (extra = {}) => ({
+ command: 'opencode',
+ gatewayBacked: 'openrouter',
+ apiKey: 'sk-or-v1-example',
+ models: ['openrouter/auto', 'stealth/ox-alpha'],
+ ...extra,
+ });
+
+ it('pins OpenCode\'s auxiliary model to the run model so a gateway run bills nothing else', () => {
+ const config = JSON.parse(
+ buildOpencodeEnvVars(gatewayProvider(), 'stealth/ox-alpha').OPENCODE_CONFIG_CONTENT,
+ );
+ expect(config.small_model).toBe('openrouter/stealth/ox-alpha');
+ });
+
+ it('leaves a stored small_model alone', () => {
+ const stored = JSON.stringify({
+ permission: 'allow',
+ small_model: 'openrouter/anthropic/claude-haiku-4.5',
+ provider: { openrouter: { npm: '@ai-sdk/openai-compatible', options: { baseURL: 'https://openrouter.ai/api/v1' } } },
+ });
+ const config = JSON.parse(
+ buildOpencodeEnvVars(gatewayProvider({ envVars: { OPENCODE_CONFIG_CONTENT: stored } }), 'stealth/ox-alpha')
+ .OPENCODE_CONFIG_CONTENT,
+ );
+ expect(config.small_model).toBe('openrouter/anthropic/claude-haiku-4.5');
+ });
+
+ it('pins a local runtime too — spawns inherit process.env, so an unset auxiliary model can reach a cloud provider the operator never opted into', () => {
+ const config = JSON.parse(
+ buildOpencodeEnvVars({ command: 'opencode', ollamaBacked: true, models: ['qwen3'] }, 'qwen3')
+ .OPENCODE_CONFIG_CONTENT,
+ );
+ expect(config.small_model).toBe('ollama/qwen3');
+ });
+});