Skip to content

A desktop coding agent with free access to frontier models.

TypeScript

feat(models): build the omnirush.ai models from the account's catalog

ogsamrat985d92b00dab
diff --git a/apps/server/src/__fixtures__/omnirush-model-catalog.json b/apps/server/src/__fixtures__/omnirush-model-catalog.json
new file mode 100644
index 00000000..93cf5f03
--- /dev/null
+++ b/apps/server/src/__fixtures__/omnirush-model-catalog.json
@@ -0,0 +1,154 @@
+{
+ "object": "list",
+ "data": [
+ {
+ "id": "gpt-6-astra",
+ "object": "model",
+ "created": 0,
+ "owned_by": "omnirush",
+ "display_name": "GPT 6 Astra",
+ "default": true,
+ "reasoning_levels": [
+ "low",
+ "high",
+ "xhigh",
+ "max"
+ ],
+ "family": "OpenAI",
+ "status": "active",
+ "order": 0,
+ "api": "responses",
+ "limits": {
+ "context": 400000,
+ "output": 128000
+ },
+ "capabilities": {
+ "reasoning": true,
+ "tool_call": true,
+ "web_search": true,
+ "image_input": true,
+ "file_input": true
+ }
+ },
+ {
+ "id": "gpt-5.6-sol",
+ "object": "model",
+ "created": 0,
+ "owned_by": "omnirush",
+ "display_name": "GPT-5.6 Sol",
+ "default": false,
+ "reasoning_levels": [
+ "low",
+ "high",
+ "xhigh",
+ "max"
+ ],
+ "family": "OpenAI",
+ "status": "active",
+ "order": 1,
+ "api": "responses",
+ "limits": {
+ "context": 400000,
+ "output": 128000
+ },
+ "capabilities": {
+ "reasoning": true,
+ "tool_call": true,
+ "web_search": true,
+ "image_input": true,
+ "file_input": true
+ }
+ },
+ {
+ "id": "meta-muse-spark",
+ "object": "model",
+ "created": 0,
+ "owned_by": "omnirush",
+ "display_name": "Meta Muse Spark",
+ "default": false,
+ "reasoning_levels": [
+ "minimal",
+ "low",
+ "medium",
+ "high",
+ "xhigh"
+ ],
+ "family": "Meta Muse",
+ "status": "active",
+ "order": 20,
+ "api": "responses",
+ "limits": {
+ "context": 158000,
+ "output": 32000
+ },
+ "capabilities": {
+ "reasoning": true,
+ "tool_call": true,
+ "web_search": true,
+ "image_input": true,
+ "file_input": true
+ }
+ },
+ {
+ "id": "muse-spark-1.1",
+ "object": "model",
+ "created": 0,
+ "owned_by": "omnirush",
+ "display_name": "Meta Muse Spark 1.1",
+ "default": false,
+ "reasoning_levels": [
+ "minimal",
+ "low",
+ "medium",
+ "high",
+ "xhigh"
+ ],
+ "family": "Meta Muse",
+ "status": "active",
+ "order": 21,
+ "api": "responses",
+ "limits": {
+ "context": 158000,
+ "output": 32000
+ },
+ "capabilities": {
+ "reasoning": true,
+ "tool_call": true,
+ "web_search": true,
+ "image_input": true,
+ "file_input": true
+ }
+ },
+ {
+ "id": "muse-spark-1.3",
+ "object": "model",
+ "created": 0,
+ "owned_by": "omnirush",
+ "display_name": "Meta Muse Spark 1.3",
+ "default": false,
+ "reasoning_levels": [
+ "minimal",
+ "low",
+ "medium",
+ "high",
+ "xhigh"
+ ],
+ "family": "Meta Muse",
+ "status": "beta",
+ "order": 23,
+ "api": "responses",
+ "limits": {
+ "context": 99000,
+ "output": 16000
+ },
+ "capabilities": {
+ "reasoning": true,
+ "tool_call": true,
+ "web_search": true,
+ "image_input": false,
+ "file_input": false
+ }
+ }
+ ],
+ "catalog_version": "79ceef05dec63c39"
+}
diff --git a/apps/server/src/__fixtures__/omnirush-model-catalog.ts b/apps/server/src/__fixtures__/omnirush-model-catalog.ts
new file mode 100644
index 00000000..4137c942
--- /dev/null
+++ b/apps/server/src/__fixtures__/omnirush-model-catalog.ts
@@ -0,0 +1,31 @@
+import { readFileSync } from "node:fs";
+import { dirname, join } from "node:path";
+import { fileURLToPath } from "node:url";
+
+export type BackendCatalogModel = {
+ id: string;
+ object: string;
+ created: number;
+ owned_by: string;
+ display_name: string;
+ default: boolean;
+ reasoning_levels: string[];
+ family: string;
+ status: string;
+ order: number;
+ api: string;
+ limits: { context: number | null; output: number | null };
+ capabilities: Record<string, boolean>;
+};
+
+export type BackendCatalogBody = { object: string; catalog_version: string; data: BackendCatalogModel[] };
+
+/**
+ * GET /omnirush/v1/models as the backend's catalog serves it to an account
+ * with Meta Muse on (rendered from the backend's own catalog code): Astra
+ * (default) and Sol, then meta-muse-spark, muse-spark-1.1 and muse-spark-1.3
+ * (beta, text only). muse-spark-1.2 is unlisted. A fresh copy on every call.
+ */
+export function backendCatalogBody(): BackendCatalogBody {
+ return JSON.parse(readFileSync(join(dirname(fileURLToPath(import.meta.url)), "omnirush-model-catalog.json"), "utf8")) as BackendCatalogBody;
+}
diff --git a/apps/server/src/omnirush-model-catalog-sync.test.ts b/apps/server/src/omnirush-model-catalog-sync.test.ts
new file mode 100644
index 00000000..9dfaa0ce
--- /dev/null
+++ b/apps/server/src/omnirush-model-catalog-sync.test.ts
@@ -0,0 +1,285 @@
+import { afterEach, describe, expect, test } from "bun:test";
+import { mkdtemp, readFile, rm, stat } from "node:fs/promises";
+import { tmpdir } from "node:os";
+import { join } from "node:path";
+
+import { backendCatalogBody } from "./__fixtures__/omnirush-model-catalog.js";
+import {
+ builtinOmniRushModelCatalog,
+ omnirushModelCatalogPath,
+ readOmniRushModelCatalog,
+ sanitizeOmniRushModelCatalog,
+ writeOmniRushModelCatalog,
+} from "./omnirush-model-catalog.js";
+import { OmniRushModelCatalogSync, startOmniRushModelCatalogSync } from "./omnirush-model-catalog-sync.js";
+import {
+ keepOmniRushRuntimeConfigFileFresh,
+ omnirushRuntimeConfigFilePath,
+ writeOmniRushRuntimeConfigFile,
+} from "./omnirush-runtime-config.js";
+import { writeGlobalRuntimeOpencodeConfig } from "./runtime-opencode-config-store.js";
+import type { ServerConfig } from "./types.js";
+
+const roots: string[] = [];
+const cleanups: Array<() => void> = [];
+let previousDb: string | undefined;
+
+afterEach(async () => {
+ while (cleanups.length) cleanups.pop()?.();
+ while (roots.length) await rm(roots.pop()!, { recursive: true, force: true });
+ if (previousDb === undefined) delete process.env.OMNIRUSH_RUNTIME_DB;
+ else process.env.OMNIRUSH_RUNTIME_DB = previousDb;
+});
+
+/** A signed-in desktop server: the engine config carries the omnirush provider. */
+async function setup(): Promise<ServerConfig> {
+ const root = await mkdtemp(join(tmpdir(), "omnirush-model-catalog-sync-"));
+ roots.push(root);
+ previousDb = process.env.OMNIRUSH_RUNTIME_DB;
+ process.env.OMNIRUSH_RUNTIME_DB = join(root, "runtime.sqlite");
+ return {
+ host: "127.0.0.1",
+ port: 48123,
+ token: "owt_test_token",
+ hostToken: "owt_host_token",
+ approval: { mode: "auto", timeoutMs: 1000 },
+ corsOrigins: ["*"],
+ workspaces: [{ id: "ws_1", name: "Workspace", path: root, preset: "starter", workspaceType: "local" }],
+ authorizedRoots: [root],
+ readOnly: false,
+ startedAt: Date.now(),
+ tokenSource: "cli",
+ hostTokenSource: "cli",
+ logFormat: "pretty",
+ logRequests: false,
+ omnirushEngineToken: "engine-token",
+ omnirushGatewayCredentials: {
+ gatewayUrl: "https://api.example.test/omnirush/v1",
+ accessToken: "device-access-token",
+ refreshToken: "device-refresh-token",
+ },
+ };
+}
+
+async function engineModelIds(config: ServerConfig): Promise<string[]> {
+ const parsed = JSON.parse(await readFile(omnirushRuntimeConfigFilePath(config), "utf8")) as {
+ provider: { omnirush: { models: Record<string, unknown> } };
+ };
+ return Object.keys(parsed.provider.omnirush.models).sort();
+}
+
+async function waitFor(condition: () => boolean, timeoutMs = 2_000, poll?: () => Promise<void>): Promise<void> {
+ const deadline = Date.now() + timeoutMs;
+ await poll?.();
+ while (!condition()) {
+ if (Date.now() > deadline) throw new Error("timed out");
+ await new Promise((resolve) => setTimeout(resolve, 5));
+ await poll?.();
+ }
+}
+
+type SyncRecord = {
+ /** The engine's model ids (sorted) at each reload. */
+ reloads: string[][];
+ fetches: number;
+ logs: string[];
+};
+
+/**
+ * A sync whose reload records the engine's model list at reload time, as the
+ * engine pool would read it from the runtime config file.
+ */
+function harness(config: ServerConfig, options: {
+ respond: () => Promise<Response>;
+ engineBusy?: () => Promise<boolean>;
+ reloadFails?: () => boolean;
+}): SyncRecord & { sync: OmniRushModelCatalogSync } {
+ const record: SyncRecord = { reloads: [], fetches: 0, logs: [] };
+ const sync = new OmniRushModelCatalogSync({
+ config,
+ fetchCatalog: () => {
+ record.fetches += 1;
+ return options.respond();
+ },
+ reloadEngine: async () => {
+ if (options.reloadFails?.()) throw new Error("engine reload failed");
+ record.reloads.push(await engineModelIds(config));
+ },
+ engineBusy: options.engineBusy,
+ log: (level, message) => record.logs.push(`${level}: ${message}`),
+ reloadRetryMs: 10,
+ });
+ cleanups.push(() => sync.stop());
+ return Object.assign(record, { sync });
+}
+
+const MUSE_IDS = ["gpt-6-astra", "gpt-5.6-sol", "meta-muse-spark", "muse-spark-1.1", "muse-spark-1.3"];
+/** The engine config file is written with sorted keys. */
+const MUSE_ENGINE_IDS = [...MUSE_IDS].sort();
+const BUILTIN_ENGINE_IDS = ["gpt-5.6-sol", "gpt-6-astra"];
+
+describe("omnirush model catalog sync", () => {
+ test("a changed catalog is stored and ALWAYS reloads the engine, even when the config file already moved on", async () => {
+ const config = await setup();
+ await writeOmniRushRuntimeConfigFile(config);
+ expect(await engineModelIds(config)).toEqual(BUILTIN_ENGINE_IDS);
+ cleanups.push(keepOmniRushRuntimeConfigFileFresh(config));
+ const race: { changed?: boolean } = {};
+ const state = harness(config, {
+ respond: async () => Response.json(backendCatalogBody()),
+ // The race from the design critique: an unrelated ENGINE_GLOBAL write
+ // lands between the cache write and the sync's own config write, so the
+ // file already holds the new catalog and the sync's write reports
+ // changed=false. The engine must still reload.
+ engineBusy: async () => {
+ await writeGlobalRuntimeOpencodeConfig(config, (current) => ({
+ ...current,
+ mcp: { docs: { type: "remote", url: "https://mcp.example.test/mcp", enabled: false } },
+ }));
+ race.changed = (await writeOmniRushRuntimeConfigFile(config)).changed;
+ return false;
+ },
+ });
+
+ expect(await state.sync.run()).toBe("applied");
+ expect(race.changed).toBe(false);
+ expect((await readOmniRushModelCatalog(config)).map((model) => model.id)).toEqual(MUSE_IDS);
+ expect(state.reloads).toEqual([MUSE_ENGINE_IDS]);
+ });
+
+ test("an unchanged catalog neither rewrites the cache nor reloads", async () => {
+ const config = await setup();
+ const catalog = sanitizeOmniRushModelCatalog(backendCatalogBody())!;
+ await writeOmniRushModelCatalog(config, catalog);
+ const written = (await stat(omnirushModelCatalogPath(config))).mtimeMs;
+ const state = harness(config, { respond: async () => Response.json(backendCatalogBody()) });
+
+ expect(await state.sync.run()).toBe("unchanged");
+ expect(await state.sync.run()).toBe("unchanged");
+ expect(state.reloads).toEqual([]);
+ expect((await stat(omnirushModelCatalogPath(config))).mtimeMs).toBe(written);
+ });
+
+ test("an account without Muse keeps the built-ins and never reloads on first sync", async () => {
+ const config = await setup();
+ const body = backendCatalogBody();
+ const state = harness(config, { respond: async () => Response.json({ ...body, data: body.data.slice(0, 2) }) });
+
+ expect(await state.sync.run()).toBe("unchanged");
+ expect(state.reloads).toEqual([]);
+ expect(await readOmniRushModelCatalog(config)).toEqual(builtinOmniRushModelCatalog());
+ });
+
+ test("Muse turned off for the account drops it from the engine with one reload", async () => {
+ const config = await setup();
+ await writeOmniRushModelCatalog(config, sanitizeOmniRushModelCatalog(backendCatalogBody())!);
+ const body = backendCatalogBody();
+ const state = harness(config, { respond: async () => Response.json({ ...body, data: body.data.slice(0, 2) }) });
+
+ expect(await state.sync.run()).toBe("applied");
+ expect(state.reloads).toEqual([BUILTIN_ENGINE_IDS]);
+ });
+
+ test("a busy engine defers the reload until it idles, then reloads exactly once", async () => {
+ const config = await setup();
+ let busy = true;
+ let busyChecks = 0;
+ const state = harness(config, {
+ respond: async () => Response.json(backendCatalogBody()),
+ engineBusy: async () => {
+ busyChecks += 1;
+ return busy;
+ },
+ });
+
+ expect(await state.sync.run()).toBe("applied");
+ expect(state.reloads).toEqual([]);
+ await waitFor(() => busyChecks >= 3);
+ expect(state.reloads).toEqual([]);
+ busy = false;
+ await waitFor(() => state.reloads.length > 0);
+ await new Promise((resolve) => setTimeout(resolve, 50));
+ expect(state.reloads).toEqual([MUSE_ENGINE_IDS]);
+ // The catalog was stored when it arrived: the next pass has nothing to do.
+ expect(await state.sync.run()).toBe("unchanged");
+ expect(state.reloads).toHaveLength(1);
+ });
+
+ test("a failed reload is retried until it lands", async () => {
+ const config = await setup();
+ let failures = 2;
+ const state = harness(config, {
+ respond: async () => Response.json(backendCatalogBody()),
+ reloadFails: () => failures-- > 0,
+ });
+
+ expect(await state.sync.run()).toBe("applied");
+ await waitFor(() => state.reloads.length > 0);
+ expect(state.reloads).toEqual([MUSE_ENGINE_IDS]);
+ expect(state.logs.filter((line) => line.includes("reload failed"))).toHaveLength(2);
+ });
+
+ test("a failed fetch or an unusable body keeps the last good catalog", async () => {
+ const config = await setup();
+ const good = sanitizeOmniRushModelCatalog(backendCatalogBody())!;
+ await writeOmniRushModelCatalog(config, good);
+ const answers: Array<() => Promise<Response>> = [
+ async () => Response.json({ detail: "grant_check_unavailable" }, { status: 503 }),
+ async () => Response.json({ error: "omnirush_account_required" }, { status: 401 }),
+ async () => { throw new TypeError("fetch failed"); },
+ async () => new Response("<html>bad gateway</html>", { status: 200, headers: { "content-type": "text/html" } }),
+ async () => Response.json({ object: "list", data: [] }),
+ async () => Response.json({ object: "list", data: [{ id: "../escape", npm: "evil-sdk" }] }),
+ ];
+ for (const respond of answers) {
+ const state = harness(config, { respond });
+ expect(await state.sync.run()).toBe("failed");
+ expect(state.reloads).toEqual([]);
+ expect(await readOmniRushModelCatalog(config)).toEqual(good);
+ }
+ });
+
+ test("the timer runs a first pass after the initial delay and then on the interval until stopped", async () => {
+ const config = await setup();
+ let fetches = 0;
+ const reloads: number[] = [];
+ const sync = new OmniRushModelCatalogSync({
+ config,
+ fetchCatalog: async () => {
+ fetches += 1;
+ return Response.json(backendCatalogBody());
+ },
+ reloadEngine: async () => { reloads.push(fetches); },
+ initialDelayMs: 5,
+ intervalMs: 20,
+ });
+ cleanups.push(() => sync.stop());
+ sync.start();
+ await waitFor(() => fetches >= 3);
+ sync.stop();
+ const stoppedAt = fetches;
+ await new Promise((resolve) => setTimeout(resolve, 80));
+ expect(fetches).toBe(stoppedAt);
+ expect(reloads).toEqual([1]);
+ });
+});
+
+describe("startOmniRushModelCatalogSync", () => {
+ test("signed out: never fetches and drops the stored catalog, so the next account starts from the built-ins", async () => {
+ const config = await setup();
+ await writeOmniRushModelCatalog(config, sanitizeOmniRushModelCatalog(backendCatalogBody())!);
+ let fetches = 0;
+ const handle = startOmniRushModelCatalogSync({
+ config,
+ broker: { enabled: false, modelCatalog: async () => { fetches += 1; return Response.json(backendCatalogBody()); } },
+ reloadEngine: async () => undefined,
+ });
+ cleanups.push(() => handle.stop());
+ let stored = true;
+ await waitFor(() => !stored, 2_000, async () => {
+ stored = await stat(omnirushModelCatalogPath(config)).then(() => true, () => false);
+ });
+ expect(fetches).toBe(0);
+ expect(await readOmniRushModelCatalog(config)).toEqual(builtinOmniRushModelCatalog());
+ });
+});
diff --git a/apps/server/src/omnirush-model-catalog-sync.ts b/apps/server/src/omnirush-model-catalog-sync.ts
new file mode 100644
index 00000000..980b4dd6
--- /dev/null
+++ b/apps/server/src/omnirush-model-catalog-sync.ts
@@ -0,0 +1,192 @@
+/**
+ * Keeps the desktop's omnirush.ai model catalog in step with the account's:
+ * GET /omnirush/v1/models through the gateway broker (device bearer), shortly
+ * after the server starts (which is also every sign-in) and then every
+ * ~15 minutes.
+ *
+ * A sanitized catalog that differs from the one the engine config is built
+ * from is persisted, and the engine is ALWAYS reloaded after it. The runtime
+ * config file cannot be trusted to tell: any ENGINE_GLOBAL runtime-DB write
+ * rewrites it from the new cache (keepOmniRushRuntimeConfigFileFresh), so its
+ * `changed` flag may already be spent by the time the sync writes. The engine
+ * pool rewrites the file before a rollover and skips an unchanged
+ * fingerprint, so an extra reload costs nothing.
+ *
+ * A failed fetch or an unusable body keeps the last good catalog.
+ */
+import {
+ canonicalOmniRushModelCatalog,
+ clearOmniRushModelCatalog,
+ readOmniRushModelCatalog,
+ sanitizeOmniRushModelCatalog,
+ writeOmniRushModelCatalog,
+ type OmniRushModelCatalog,
+} from "./omnirush-model-catalog.js";
+import type { OmniRushGatewayBroker } from "./omnirush-gateway-broker.js";
+import { writeOmniRushRuntimeConfigFile } from "./omnirush-runtime-config.js";
+import type { ServerConfig } from "./types.js";
+
+type SyncLog = (level: "info" | "warn", message: string, attributes?: Record<string, unknown>) => void;
+
+export type OmniRushModelCatalogSyncOptions = {
+ config: ServerConfig;
+ fetchCatalog: () => Promise<Response>;
+ reloadEngine: () => Promise<void>;
+ /** A busy engine defers the reload; unknown activity never blocks it. */
+ engineBusy?: () => Promise<boolean>;
+ log?: SyncLog;
+ /** Off the startup path: the engine and the session restore go first. */
+ initialDelayMs?: number;
+ intervalMs?: number;
+ reloadRetryMs?: number;
+};
+
+export type OmniRushModelCatalogSyncResult = "applied" | "unchanged" | "failed";
+
+const INITIAL_DELAY_MS = 20_000;
+const INTERVAL_MS = 15 * 60_000;
+const RELOAD_RETRY_MS = 15_000;
+
+export class OmniRushModelCatalogSync {
+ private readonly options: OmniRushModelCatalogSyncOptions;
+ private queue: Promise<unknown> = Promise.resolve();
+ private timer: ReturnType<typeof setTimeout> | null = null;
+ private reloadTimer: ReturnType<typeof setTimeout> | null = null;
+ private reloadPending = false;
+ private stopped = false;
+
+ constructor(options: OmniRushModelCatalogSyncOptions) {
+ this.options = options;
+ }
+
+ start(): void {
+ this.schedule(this.options.initialDelayMs ?? INITIAL_DELAY_MS);
+ }
+
+ stop(): void {
+ this.stopped = true;
+ if (this.timer) clearTimeout(this.timer);
+ if (this.reloadTimer) clearTimeout(this.reloadTimer);
+ this.timer = null;
+ this.reloadTimer = null;
+ }
+
+ /** One sync pass. Passes are serialized, so a slow fetch never overlaps the next. */
+ run(): Promise<OmniRushModelCatalogSyncResult> {
+ const pass = this.queue.then(() => this.pass());
+ this.queue = pass.catch(() => undefined);
+ return pass;
+ }
+
+ private schedule(delayMs: number): void {
+ if (this.stopped) return;
+ this.timer = setTimeout(() => {
+ this.timer = null;
+ void this.run().catch(() => undefined).finally(() => {
+ const interval = this.options.intervalMs ?? INTERVAL_MS;
+ // ±10% so desktops that started together do not poll together.
+ this.schedule(interval * (0.9 + Math.random() * 0.2));
+ });
+ }, delayMs);
+ this.timer.unref?.();
+ }
+
+ private async pass(): Promise<OmniRushModelCatalogSyncResult> {
+ if (this.stopped) return "unchanged";
+ const catalog = await this.download();
+ if (!catalog || this.stopped) return "failed";
+ const current = await readOmniRushModelCatalog(this.options.config);
+ if (canonicalOmniRushModelCatalog(catalog) === canonicalOmniRushModelCatalog(current)) return "unchanged";
+ await writeOmniRushModelCatalog(this.options.config, catalog);
+ this.options.log?.("info", "omnirush.ai model catalog changed; reloading the engine", {
+ models: catalog.map((model) => model.id).join(","),
+ });
+ this.reloadPending = true;
+ await this.reload();
+ return "applied";
+ }
+
+ private async download(): Promise<OmniRushModelCatalog | null> {
+ try {
+ const response = await this.options.fetchCatalog();
+ if (!response.ok) {
+ await response.body?.cancel().catch(() => undefined);
+ this.options.log?.("warn", "omnirush.ai model catalog fetch failed; keeping the last catalog", { status: response.status });
+ return null;
+ }
+ const catalog = sanitizeOmniRushModelCatalog(await response.json());
+ if (!catalog) this.options.log?.("warn", "omnirush.ai model catalog had no usable model; keeping the last catalog");
+ return catalog;
+ } catch (error) {
+ this.options.log?.("warn", "omnirush.ai model catalog fetch failed; keeping the last catalog", {
+ error: error instanceof Error ? error.name : "unknown",
+ });
+ return null;
+ }
+ }
+
+ private async reload(): Promise<void> {
+ if (!this.reloadPending || this.stopped) return;
+ if (await this.engineBusy()) {
+ this.scheduleReload();
+ return;
+ }
+ try {
+ // An engine without a rollover pool reloads in place and reads the file
+ // as it stands; the pool rewrites it itself before comparing.
+ await writeOmniRushRuntimeConfigFile(this.options.config);
+ await this.options.reloadEngine();
+ this.reloadPending = false;
+ } catch (error) {
+ this.options.log?.("warn", "omnirush.ai model catalog engine reload failed; retrying", {
+ error: error instanceof Error ? error.message : "unknown",
+ });
+ this.scheduleReload();
+ }
+ }
+
+ private scheduleReload(): void {
+ if (this.reloadTimer || this.stopped) return;
+ this.reloadTimer = setTimeout(() => {
+ this.reloadTimer = null;
+ const retry = this.queue.then(() => this.reload());
+ this.queue = retry.catch(() => undefined);
+ }, this.options.reloadRetryMs ?? RELOAD_RETRY_MS);
+ this.reloadTimer.unref?.();
+ }
+
+ private async engineBusy(): Promise<boolean> {
+ try {
+ return (await this.options.engineBusy?.()) === true;
+ } catch {
+ return false;
+ }
+ }
+}
+
+/**
+ * Starts the sync while the broker holds omnirush.ai account credentials. A
+ * signed-out server drops the stored catalog instead, so the next account to
+ * sign in never starts from another account's models.
+ */
+export function startOmniRushModelCatalogSync(input: {
+ config: ServerConfig;
+ broker: Pick<OmniRushGatewayBroker, "enabled" | "modelCatalog">;
+ reloadEngine: () => Promise<void>;
+ engineBusy?: () => Promise<boolean>;
+ log?: SyncLog;
+}): { stop: () => void } {
+ if (!input.broker.enabled) {
+ void clearOmniRushModelCatalog(input.config).catch(() => undefined);
+ return { stop: () => undefined };
+ }
+ const sync = new OmniRushModelCatalogSync({
+ config: input.config,
+ fetchCatalog: () => input.broker.modelCatalog(),
+ reloadEngine: input.reloadEngine,
+ engineBusy: input.engineBusy,
+ log: input.log,
+ });
+ sync.start();
+ return sync;
+}
diff --git a/apps/server/src/omnirush-model-catalog.test.ts b/apps/server/src/omnirush-model-catalog.test.ts
new file mode 100644
index 00000000..516562a5
--- /dev/null
+++ b/apps/server/src/omnirush-model-catalog.test.ts
@@ -0,0 +1,251 @@
+import { afterEach, describe, expect, test } from "bun:test";
+import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
+import { tmpdir } from "node:os";
+import { join } from "node:path";
+
+import {
+ builtinOmniRushModelCatalog,
+ canonicalOmniRushModelCatalog,
+ clearOmniRushModelCatalog,
+ engineModelsFromCatalog,
+ omnirushDefaultModelId,
+ omnirushModelCatalogPath,
+ readOmniRushModelCatalog,
+ sanitizeOmniRushModelCatalog,
+ writeOmniRushModelCatalog,
+ type OmniRushModelCatalog,
+} from "./omnirush-model-catalog.js";
+import type { ServerConfig } from "./types.js";
+import { backendCatalogBody } from "./__fixtures__/omnirush-model-catalog.js";
+
+const roots: string[] = [];
+let previousDb: string | undefined;
+
+afterEach(async () => {
+ while (roots.length) await rm(roots.pop()!, { recursive: true, force: true });
+ if (previousDb === undefined) delete process.env.OMNIRUSH_RUNTIME_DB;
+ else process.env.OMNIRUSH_RUNTIME_DB = previousDb;
+});
+
+async function setupConfig(): Promise<ServerConfig> {
+ const root = await mkdtemp(join(tmpdir(), "omnirush-model-catalog-"));
+ roots.push(root);
+ previousDb = process.env.OMNIRUSH_RUNTIME_DB;
+ process.env.OMNIRUSH_RUNTIME_DB = join(root, "runtime.sqlite");
+ return {
+ host: "127.0.0.1",
+ port: 0,
+ token: "owt_test_token",
+ hostToken: "owt_host_token",
+ approval: { mode: "auto", timeoutMs: 1000 },
+ corsOrigins: ["*"],
+ workspaces: [],
+ authorizedRoots: [root],
+ readOnly: false,
+ startedAt: Date.now(),
+ tokenSource: "cli",
+ hostTokenSource: "cli",
+ logFormat: "pretty",
+ logRequests: false,
+ };
+}
+
+/** Every key path of a JSON value, e.g. "0.capabilities.web_search". */
+function keyPaths(value: unknown, prefix = ""): string[] {
+ if (Array.isArray(value)) return value.flatMap((entry, index) => keyPaths(entry, `${prefix}${index}.`));
+ if (typeof value !== "object" || value === null) return [];
+ return Object.entries(value).flatMap(([key, child]) => [`${prefix}${key}`, ...keyPaths(child, `${prefix}${key}.`)]);
+}
+
+describe("omnirush model catalog sanitizer", () => {
+ test("reads the backend catalog: Astra first and default, Muse under its family with its own efforts", () => {
+ const catalog = sanitizeOmniRushModelCatalog(backendCatalogBody());
+ expect(catalog?.map((model) => model.id)).toEqual(["gpt-6-astra", "gpt-5.6-sol", "meta-muse-spark", "muse-spark-1.1", "muse-spark-1.3"]);
+ expect(catalog && omnirushDefaultModelId(catalog)).toBe("gpt-6-astra");
+ expect(catalog?.filter((model) => model.default).map((model) => model.id)).toEqual(["gpt-6-astra"]);
+ expect(catalog?.[4]).toEqual({
+ id: "muse-spark-1.3",
+ display_name: "Meta Muse Spark 1.3",
+ family: "Meta Muse",
+ status: "beta",
+ default: false,
+ reasoning_levels: ["minimal", "low", "medium", "high", "xhigh"],
+ limits: { context: 99_000, output: 16_000 },
+ capabilities: { reasoning: true, tool_call: true, web_search: true, image_input: false, file_input: false },
+ });
+ });
+
+ test("Astra and Sol from the backend equal the built-in catalog, so a Muse-less account never reloads", () => {
+ const body = backendCatalogBody();
+ const openaiOnly = { ...body, data: body.data.slice(0, 2) };
+ const catalog = sanitizeOmniRushModelCatalog(openaiOnly);
+ expect(catalog).not.toBeNull();
+ expect(canonicalOmniRushModelCatalog(catalog!)).toBe(canonicalOmniRushModelCatalog(builtinOmniRushModelCatalog()));
+ });
+
+ test("never takes provider plumbing from the backend, at any depth", () => {
+ const body = backendCatalogBody();
+ const hostile = {
+ ...body,
+ npm: "evil-sdk",
+ baseURL: "https://attacker.example",
+ provider: { npm: "evil-sdk" },
+ data: body.data.map((model) => ({
+ ...model,
+ npm: "evil-sdk",
+ baseURL: "https://attacker.example/v1",
+ headers: { authorization: "Bearer stolen" },
+ env: ["AWS_SECRET_ACCESS_KEY"],
+ options: { baseURL: "https://attacker.example/v1" },
+ provider: { npm: "evil-sdk", api: "https://attacker.example" },
+ upstream_model: "internal-codename",
+ limits: { ...model.limits, input: 5, url: "https://attacker.example" },
+ capabilities: { ...model.capabilities, attachment: true, shell: true },
+ })),
+ };
+ const catalog = sanitizeOmniRushModelCatalog(hostile);
+ const allowed = new Set([
+ "id", "display_name", "family", "status", "default", "reasoning_levels", "limits", "limits.context", "limits.output",
+ "capabilities", "capabilities.reasoning", "capabilities.tool_call", "capabilities.web_search",
+ "capabilities.image_input", "capabilities.file_input",
+ ]);
+ const paths = keyPaths(catalog).map((path) => path.replace(/^\d+\./, "")).filter((path) => !/^\d+$/.test(path));
+ expect(paths.filter((path) => !allowed.has(path) && !/^reasoning_levels\.\d+$/.test(path))).toEqual([]);
+ const text = JSON.stringify(catalog);
+ for (const leaked of ["evil-sdk", "attacker.example", "stolen", "AWS_SECRET", "internal-codename"]) {
+ expect(text).not.toContain(leaked);
+ }
+ });
+
+ test("drops bad ids, duplicates, non-Responses models and wrong types; clamps limits", () => {
+ const catalog = sanitizeOmniRushModelCatalog({
+ data: [
+ { id: "../../etc/passwd", display_name: "Path" },
+ { id: "z-ai/glm-5.2", display_name: "Slash" },
+ { id: "-leading-dash", display_name: "Dash" },
+ { id: "a".repeat(129), display_name: "Long" },
+ { id: 42, display_name: "Number" },
+ "not-an-object",
+ { id: "chat-only", display_name: "Chat", api: "chat" },
+ {
+ id: "new-model:v2",
+ display_name: " New\u0007 Model‮ ",
+ family: "x".repeat(40),
+ status: "retired",
+ default: "yes",
+ reasoning_levels: ["ultra", "high", "HIGH", "low", 3, "low"],
+ limits: { context: 10, output: 9_999_999 },
+ capabilities: { reasoning: "true", tool_call: false },
+ },
+ { id: "new-model:v2", display_name: "Duplicate" },
+ ],
+ });
+ expect(catalog).toEqual([{
+ id: "new-model:v2",
+ display_name: "New Model",
+ family: null,
+ status: "active",
+ default: true,
+ reasoning_levels: ["low", "high"],
+ limits: { context: 1_000, output: 1_000 },
+ capabilities: { reasoning: true, tool_call: false, web_search: true, image_input: true, file_input: true },
+ }]);
+ });
+
+ test("an older backend's four fields give Astra and Sol their v1.0.9 metadata", () => {
+ const catalog = sanitizeOmniRushModelCatalog({
+ object: "list",
+ data: [
+ { id: "gpt-6-astra", display_name: "GPT 6 Astra", default: true, reasoning_levels: ["low", "high", "xhigh", "max"] },
+ { id: "gpt-5.6-sol", display_name: "GPT-5.6 Sol", default: false, reasoning_levels: ["low", "high", "xhigh", "max"] },
+ ],
+ });
+ expect(catalog).toEqual(builtinOmniRushModelCatalog());
+ });
+
+ test("keeps exactly one default, and at most 32 models", () => {
+ const many = Array.from({ length: 40 }, (_, index) => ({ id: `model-${index}`, display_name: `Model ${index}`, default: index >= 3 }));
+ const catalog = sanitizeOmniRushModelCatalog({ data: many });
+ expect(catalog).toHaveLength(32);
+ expect(catalog?.filter((model) => model.default).map((model) => model.id)).toEqual(["model-3"]);
+
+ const none = sanitizeOmniRushModelCatalog({ data: [{ id: "first" }, { id: "second" }] });
+ expect(none?.map((model) => model.default)).toEqual([true, false]);
+ });
+
+ test("an unusable body is no catalog, so the last good one stays", () => {
+ for (const body of [null, "list", [], {}, { data: {} }, { data: [] }, { data: [{ id: "" }, { nope: true }] }]) {
+ expect(sanitizeOmniRushModelCatalog(body)).toBeNull();
+ }
+ });
+});
+
+describe("omnirush model catalog cache", () => {
+ test("round-trips through the file, re-sanitized on read, and falls back to the built-ins", async () => {
+ const config = await setupConfig();
+ expect(await readOmniRushModelCatalog(config)).toEqual(builtinOmniRushModelCatalog());
+
+ const catalog = sanitizeOmniRushModelCatalog(backendCatalogBody())!;
+ await writeOmniRushModelCatalog(config, catalog);
+ expect(await readOmniRushModelCatalog(config)).toEqual(catalog);
+
+ // The file is re-read through the sanitizer: a tampered entry is dropped, not trusted.
+ const stored = JSON.parse(await readFile(omnirushModelCatalogPath(config), "utf8")) as { data: Array<Record<string, unknown>> };
+ stored.data.push({ id: "bad id", npm: "evil-sdk" });
+ await writeFile(omnirushModelCatalogPath(config), JSON.stringify(stored));
+ expect(await readOmniRushModelCatalog(config)).toEqual(catalog);
+
+ await writeFile(omnirushModelCatalogPath(config), "{not json");
+ expect(await readOmniRushModelCatalog(config)).toEqual(builtinOmniRushModelCatalog());
+
+ await writeOmniRushModelCatalog(config, catalog);
+ await clearOmniRushModelCatalog(config);
+ expect(await readOmniRushModelCatalog(config)).toEqual(builtinOmniRushModelCatalog());
+ });
+});
+
+describe("omnirush engine models from the catalog", () => {
+ const enabled = (model: Record<string, unknown>) => Object.entries(model.variants as Record<string, { disabled?: boolean }>)
+ .filter(([, options]) => options.disabled !== true)
+ .map(([key]) => key);
+ const disabled = (model: Record<string, unknown>) => Object.entries(model.variants as Record<string, { disabled?: boolean }>)
+ .filter(([, options]) => options.disabled === true)
+ .map(([key]) => key);
+
+ test("gives every model its own effort variants and disables the rest", () => {
+ const models = engineModelsFromCatalog(sanitizeOmniRushModelCatalog(backendCatalogBody())!);
+ expect(enabled(models["gpt-6-astra"]!)).toEqual(["low", "high", "xhigh", "max"]);
+ expect(disabled(models["gpt-6-astra"]!)).toEqual(["none", "minimal", "medium"]);
+ for (const id of ["meta-muse-spark", "muse-spark-1.1", "muse-spark-1.3"]) {
+ expect(enabled(models[id]!)).toEqual(["minimal", "low", "medium", "high", "xhigh"]);
+ expect(disabled(models[id]!)).toEqual(["none", "max"]);
+ expect(models[id]!.variants).toMatchObject({ xhigh: { reasoning_effort: "xhigh" } });
+ }
+ });
+
+ test("labels Muse by family, keeps 1.3 beta and text-only, and never sets attachment", () => {
+ const models = engineModelsFromCatalog(sanitizeOmniRushModelCatalog(backendCatalogBody())!);
+ expect(models["meta-muse-spark"]).toMatchObject({
+ name: "Meta Muse Spark",
+ family: "Meta Muse",
+ limit: { context: 158_000, output: 32_000 },
+ modalities: { input: ["text", "image", "pdf"], output: ["text"] },
+ });
+ expect(models["meta-muse-spark"]!.status).toBeUndefined();
+ expect(models["muse-spark-1.3"]).toMatchObject({ status: "beta", modalities: { input: ["text"], output: ["text"] } });
+ for (const model of Object.values(models)) expect(model.attachment).toBeUndefined();
+ expect(models["gpt-6-astra"]!.family).toBeUndefined();
+ });
+
+ test("a deprecated model stays active in the engine, which would otherwise delete it", () => {
+ const catalog: OmniRushModelCatalog = builtinOmniRushModelCatalog().map((model) => ({ ...model, status: "deprecated" as const }));
+ for (const model of Object.values(engineModelsFromCatalog(catalog))) expect(model.status).toBeUndefined();
+ });
+
+ test("a model without effort control offers no variant", () => {
+ const [model] = sanitizeOmniRushModelCatalog({ data: [{ id: "plain", display_name: "Plain", reasoning_levels: [], capabilities: { reasoning: false } }] })!;
+ const engine = engineModelsFromCatalog([model!]).plain!;
+ expect(enabled(engine)).toEqual([]);
+ expect(engine.reasoning).toBe(false);
+ });
+});
diff --git a/apps/server/src/omnirush-model-catalog.ts b/apps/server/src/omnirush-model-catalog.ts
new file mode 100644
index 00000000..3cd6a628
--- /dev/null
+++ b/apps/server/src/omnirush-model-catalog.ts
@@ -0,0 +1,241 @@
+/**
+ * The omnirush.ai model catalog on the desktop: the models the account may
+ * use, as the backend lists them at GET /omnirush/v1/models, reduced to what
+ * the engine config needs.
+ *
+ * The backend is trusted for model ids, names, numbers, enums and booleans
+ * only. The engine provider itself (npm package, base URL, env, headers,
+ * options) stays hardcoded in omnirush-runtime-config.ts, so a catalog can
+ * never point the engine anywhere but the local gateway broker.
+ *
+ * The last good catalog is kept at <runtimeStorageDir>/omnirush-model-catalog.json.
+ * Without one (first run, offline, or a backend that fails) the engine gets
+ * the built-in Astra and Sol, exactly as v1.0.9 declared them.
+ */
+import { randomUUID } from "node:crypto";
+import { mkdir, readFile, rename, rm, writeFile } from "node:fs/promises";
+import { join } from "node:path";
+
+import { runtimeStorageDir } from "./runtime-db.js";
+import type { ServerConfig } from "./types.js";
+
+/** Every effort a catalog model may list, lowest first. */
+export const OMNIRUSH_MODEL_EFFORTS = ["none", "minimal", "low", "medium", "high", "xhigh", "max"] as const;
+export type OmniRushModelEffort = (typeof OMNIRUSH_MODEL_EFFORTS)[number];
+
+const MODEL_STATUSES = ["active", "beta", "deprecated"] as const;
+export type OmniRushModelStatus = (typeof MODEL_STATUSES)[number];
+
+export type OmniRushCatalogModel = {
+ id: string;
+ display_name: string;
+ /** The model family the backend names ("OpenAI", "Meta Muse"), if any. */
+ family: string | null;
+ status: OmniRushModelStatus;
+ /** Exactly one model of a catalog is the default. */
+ default: boolean;
+ /** The efforts the model accepts, lowest first; empty means no effort control. */
+ reasoning_levels: OmniRushModelEffort[];
+ limits: { context: number; output: number };
+ capabilities: {
+ reasoning: boolean;
+ tool_call: boolean;
+ web_search: boolean;
+ image_input: boolean;
+ file_input: boolean;
+ };
+};
+
+/** Models in the backend's order, default first. Never empty. */
+export type OmniRushModelCatalog = OmniRushCatalogModel[];
+
+const MODEL_ID = /^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/;
+const MAX_MODELS = 32;
+const CONTEXT_LIMIT_RANGE = { min: 1_000, max: 2_000_000 };
+const OUTPUT_LIMIT_RANGE = { min: 1_000, max: 256_000 };
+/**
+ * The family of the models v1.0.9 shipped. The engine gets no `family` for
+ * it, so Astra and Sol keep their v1.0.9 entries byte for byte and pickers
+ * list them under the provider's own name; any other family is its own group.
+ */
+const PROVIDER_FAMILY = "OpenAI";
+
+function catalogModel(
+ id: string,
+ displayName: string,
+ family: string | null,
+ isDefault: boolean,
+): OmniRushCatalogModel {
+ return {
+ id,
+ display_name: displayName,
+ family,
+ status: "active",
+ default: isDefault,
+ reasoning_levels: ["low", "high", "xhigh", "max"],
+ limits: { context: 400_000, output: 128_000 },
+ capabilities: { reasoning: true, tool_call: true, web_search: true, image_input: true, file_input: true },
+ };
+}
+
+/** Astra and Sol with their v1.0.9 metadata, Astra the default. */
+export function builtinOmniRushModelCatalog(): OmniRushModelCatalog {
+ return [
+ catalogModel("gpt-6-astra", "GPT 6 Astra", PROVIDER_FAMILY, true),
+ catalogModel("gpt-5.6-sol", "GPT-5.6 Sol", PROVIDER_FAMILY, false),
+ ];
+}
+
+export function omnirushDefaultModelId(catalog: OmniRushModelCatalog): string {
+ return (catalog.find((model) => model.default) ?? catalog[0] ?? builtinOmniRushModelCatalog()[0]!).id;
+}
+
+function isRecord(value: unknown): value is Record<string, unknown> {
+ return typeof value === "object" && value !== null && !Array.isArray(value);
+}
+
+/** Visible text only (no control or bidi characters), trimmed, at most `limit` characters. */
+function label(value: unknown, limit: number): string | null {
+ if (typeof value !== "string") return null;
+ const text = value.replace(/[\u0000-\u001f\u007f-\u009f\p{Default_Ignorable_Code_Point}]/gu, "").trim();
+ return text && text.length <= limit ? text : null;
+}
+
+function tokenLimit(value: unknown, range: { min: number; max: number }): number | null {
+ if (typeof value !== "number" || !Number.isFinite(value)) return null;
+ return Math.min(range.max, Math.max(range.min, Math.floor(value)));
+}
+
+function efforts(value: unknown[]): OmniRushModelEffort[] {
+ return OMNIRUSH_MODEL_EFFORTS.filter((effort) => value.includes(effort));
+}
+
+function sanitizeModel(raw: unknown): OmniRushCatalogModel | null {
+ if (!isRecord(raw)) return null;
+ const id = raw.id;
+ if (typeof id !== "string" || !MODEL_ID.test(id)) return null;
+ // The broker serves the Responses API only; a model on another wire API
+ // could never answer through it.
+ if (raw.api !== undefined && raw.api !== null && raw.api !== "responses") return null;
+ // An older backend lists only id, display_name, default and
+ // reasoning_levels: known ids keep their built-in metadata, new ids get the
+ // shared defaults.
+ const fallback = builtinOmniRushModelCatalog().find((model) => model.id === id)
+ ?? catalogModel(id, id, null, false);
+ const limits = isRecord(raw.limits) ? raw.limits : {};
+ const capabilities = isRecord(raw.capabilities) ? raw.capabilities : {};
+ const flag = (name: keyof OmniRushCatalogModel["capabilities"]) => {
+ const value = capabilities[name];
+ return typeof value === "boolean" ? value : fallback.capabilities[name];
+ };
+ const context = tokenLimit(limits.context, CONTEXT_LIMIT_RANGE) ?? fallback.limits.context;
+ const output = tokenLimit(limits.output, OUTPUT_LIMIT_RANGE) ?? fallback.limits.output;
+ const status = MODEL_STATUSES.find((entry) => entry === raw.status);
+ return {
+ id,
+ display_name: label(raw.display_name, 64) ?? fallback.display_name,
+ family: label(raw.family, 32) ?? fallback.family,
+ status: status ?? "active",
+ default: raw.default === true,
+ reasoning_levels: Array.isArray(raw.reasoning_levels) ? efforts(raw.reasoning_levels) : fallback.reasoning_levels,
+ limits: { context, output: Math.min(output, context) },
+ capabilities: {
+ reasoning: flag("reasoning"),
+ tool_call: flag("tool_call"),
+ web_search: flag("web_search"),
+ image_input: flag("image_input"),
+ file_input: flag("file_input"),
+ },
+ };
+}
+
+/**
+ * The catalog in a GET /omnirush/v1/models body (or the cache file, which
+ * has the same shape), or null when it holds no usable model. Unknown keys
+ * are dropped; only whitelisted fields of the expected types are read.
+ */
+export function sanitizeOmniRushModelCatalog(raw: unknown): OmniRushModelCatalog | null {
+ if (!isRecord(raw) || !Array.isArray(raw.data)) return null;
+ const models: OmniRushCatalogModel[] = [];
+ const seen = new Set<string>();
+ for (const entry of raw.data) {
+ if (models.length === MAX_MODELS) break;
+ const model = sanitizeModel(entry);
+ if (!model || seen.has(model.id)) continue;
+ seen.add(model.id);
+ models.push(model);
+ }
+ if (models.length === 0) return null;
+ const flagged = models.findIndex((model) => model.default);
+ const defaultIndex = flagged < 0 ? 0 : flagged;
+ return models.map((model, index) => ({ ...model, default: index === defaultIndex }));
+}
+
+/** Stable text for change detection: sanitized models are built in a fixed key order. */
+export function canonicalOmniRushModelCatalog(catalog: OmniRushModelCatalog): string {
+ return JSON.stringify(catalog);
+}
+
+export function omnirushModelCatalogPath(config: ServerConfig): string {
+ return join(runtimeStorageDir(config), "omnirush-model-catalog.json");
+}
+
+/** The last synced catalog, or the built-in one when none is stored or it is unreadable. */
+export async function readOmniRushModelCatalog(config: ServerConfig): Promise<OmniRushModelCatalog> {
+ const raw = await readFile(omnirushModelCatalogPath(config), "utf8").catch(() => null);
+ if (raw === null) return builtinOmniRushModelCatalog();
+ try {
+ return sanitizeOmniRushModelCatalog(JSON.parse(raw)) ?? builtinOmniRushModelCatalog();
+ } catch {
+ return builtinOmniRushModelCatalog();
+ }
+}
+
+/** Atomic (temp file + rename), so a config build never reads a partial file. */
+export async function writeOmniRushModelCatalog(config: ServerConfig, catalog: OmniRushModelCatalog): Promise<void> {
+ const path = omnirushModelCatalogPath(config);
+ await mkdir(runtimeStorageDir(config), { recursive: true });
+ const tmp = `${path}.${randomUUID()}.tmp`;
+ await writeFile(tmp, `${JSON.stringify({ data: catalog }, null, 2)}\n`, "utf8");
+ await rename(tmp, path);
+}
+
+export async function clearOmniRushModelCatalog(config: ServerConfig): Promise<void> {
+ await rm(omnirushModelCatalogPath(config), { force: true });
+}
+
+/**
+ * The `omnirush` provider's engine models. Each model's efforts become
+ * variants carrying the client-facing `reasoning_effort` (the
+ * omnirush-reasoning-effort plugin and the broker put it on the wire); every
+ * other effort is declared disabled, because the engine merges its own
+ * OpenAI reasoning defaults into a model's variants and drops only entries
+ * marked disabled. `deprecated` is never passed on: the engine deletes
+ * deprecated models, which would strand the sessions pinned to one.
+ */
+export function engineModelsFromCatalog(catalog: OmniRushModelCatalog): Record<string, Record<string, unknown>> {
+ return Object.fromEntries(catalog.map((model) => [model.id, {
+ name: model.display_name,
+ reasoning: model.capabilities.reasoning,
+ tool_call: model.capabilities.tool_call,
+ structured_output: true,
+ temperature: true,
+ variants: {
+ ...Object.fromEntries(model.reasoning_levels.map((effort) => [effort, { reasoning_effort: effort }])),
+ ...Object.fromEntries(OMNIRUSH_MODEL_EFFORTS
+ .filter((effort) => !model.reasoning_levels.includes(effort))
+ .map((effort) => [effort, { disabled: true }])),
+ },
+ limit: { context: model.limits.context, output: model.limits.output },
+ modalities: {
+ input: [
+ "text",
+ ...(model.capabilities.image_input ? ["image"] : []),
+ ...(model.capabilities.file_input ? ["pdf"] : []),
+ ],
+ output: ["text"],
+ },
+ ...(model.family && model.family !== PROVIDER_FAMILY ? { family: model.family } : {}),
+ ...(model.status === "beta" ? { status: "beta" } : {}),
+ }]));
+}
diff --git a/apps/server/src/omnirush-runtime-config.test.ts b/apps/server/src/omnirush-runtime-config.test.ts
index a10dd7fd..aa699e21 100644
--- a/apps/server/src/omnirush-runtime-config.test.ts
+++ b/apps/server/src/omnirush-runtime-config.test.ts
@@ -1,7 +1,7 @@
import { afterEach, describe, expect, test } from "bun:test";
-import { mkdtemp, readFile, rm } from "node:fs/promises";
+import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
-import { join } from "node:path";
+import { dirname, join } from "node:path";
import {
buildOmniRushRuntimeConfig,
@@ -12,6 +12,12 @@ import {
} from "./omnirush-runtime-config.js";
import { writeGlobalRuntimeOpencodeConfig, writeRuntimeOpencodeConfig } from "./runtime-opencode-config-store.js";
import { rulesFromPermissionConfig, winningRule } from "./effective-permissions.js";
+import { backendCatalogBody } from "./__fixtures__/omnirush-model-catalog.js";
+import {
+ sanitizeOmniRushModelCatalog,
+ writeOmniRushModelCatalog,
+ type OmniRushModelCatalog,
+} from "./omnirush-model-catalog.js";
import { gitWorkflowPermissionRules } from "./git-command-policy.js";
import type { ServerConfig } from "./types.js";
@@ -401,3 +407,193 @@ describe("omnirush runtime config file", () => {
expect(second).toBe(first);
});
});
+
+/**
+ * The omnirush provider exactly as v1.0.9 declared it (the INTERNAL_MODELS
+ * and internalGatewayModel it hardcoded). Astra and Sol must keep these
+ * bytes: they feed the engine-pool fingerprint, and any drift (an
+ * `attachment` flag, a family, a status) would change how the engine treats
+ * them.
+ */
+function v109OmniRushProvider(baseURL: string) {
+ const model = (name: string) => ({
+ name,
+ reasoning: true,
+ tool_call: true,
+ structured_output: true,
+ temperature: true,
+ variants: {
+ low: { reasoning_effort: "low" },
+ high: { reasoning_effort: "high" },
+ xhigh: { reasoning_effort: "xhigh" },
+ max: { reasoning_effort: "max" },
+ none: { disabled: true },
+ minimal: { disabled: true },
+ medium: { disabled: true },
+ },
+ limit: { context: 400_000, output: 128_000 },
+ modalities: { input: ["text", "image", "pdf"], output: ["text"] },
+ });
+ return {
+ npm: "@ai-sdk/openai",
+ name: "omnirush.ai",
+ env: ["OMNIRUSH_ACCESS_TOKEN"],
+ options: { baseURL },
+ models: { "gpt-6-astra": model("GPT 6 Astra"), "gpt-5.6-sol": model("GPT-5.6 Sol") },
+ };
+}
+
+/** What the engine reads: the config as JSON. */
+function asEngineReadsIt(value: unknown): unknown {
+ return JSON.parse(JSON.stringify(value));
+}
+
+describe("omnirush runtime config from the model catalog", () => {
+ const gateway = { baseUrl: "http://127.0.0.1:48123/omnirush-gateway/v1" };
+ const providerOf = (parsed: Record<string, unknown>) => (parsed.provider as Record<string, Record<string, unknown>>).omnirush!;
+
+ function signIn(config: ServerConfig): void {
+ config.port = 48123;
+ config.omnirushEngineToken = "engine-token";
+ config.omnirushGatewayCredentials = {
+ gatewayUrl: "https://api.example.test/omnirush/v1",
+ accessToken: "device-access-token",
+ refreshToken: "device-refresh-token",
+ };
+ }
+
+ test("Astra and Sol render exactly as in v1.0.9: built-in, from the new backend, and from an older one", () => {
+ const body = backendCatalogBody();
+ const catalogs: Array<[string, OmniRushModelCatalog | undefined]> = [
+ ["built-in", undefined],
+ ["new backend", sanitizeOmniRushModelCatalog({ ...body, data: body.data.slice(0, 2) })!],
+ ["older backend", sanitizeOmniRushModelCatalog({
+ object: "list",
+ data: body.data.slice(0, 2).map(({ id, display_name, reasoning_levels }) => ({ id, display_name, default: id === "gpt-6-astra", reasoning_levels })),
+ })!],
+ ];
+ for (const [source, catalog] of catalogs) {
+ const parsed = buildOmniRushRuntimeConfigObjectFromSnapshot({}, gateway, process.env, catalog);
+ expect([source, asEngineReadsIt(providerOf(parsed))]).toEqual([source, v109OmniRushProvider(gateway.baseUrl)]);
+ expect([source, parsed.model]).toEqual([source, "omnirush/gpt-6-astra"]);
+ }
+ });
+
+ test("an account without Muse writes the same engine config bytes as before the sync", async () => {
+ const { config } = await setup();
+ signIn(config);
+ const before = await buildOmniRushRuntimeConfig(config);
+ const body = backendCatalogBody();
+ await writeOmniRushModelCatalog(config, sanitizeOmniRushModelCatalog({ ...body, data: body.data.slice(0, 2) })!);
+ expect(await buildOmniRushRuntimeConfig(config)).toBe(before);
+ });
+
+ test("the synced catalog gives each model its own efforts, limits and inputs; Astra stays the default", async () => {
+ const { config } = await setup();
+ signIn(config);
+ await writeOmniRushModelCatalog(config, sanitizeOmniRushModelCatalog(backendCatalogBody())!);
+ const parsed = JSON.parse(await buildOmniRushRuntimeConfig(config)) as Record<string, unknown>;
+ const provider = providerOf(parsed);
+ const models = provider.models as Record<string, Record<string, unknown>>;
+ const museVariants = {
+ minimal: { reasoning_effort: "minimal" },
+ low: { reasoning_effort: "low" },
+ medium: { reasoning_effort: "medium" },
+ high: { reasoning_effort: "high" },
+ xhigh: { reasoning_effort: "xhigh" },
+ // Muse answers none and max with 400; the engine's own defaults are disabled.
+ none: { disabled: true },
+ max: { disabled: true },
+ };
+
+ expect(parsed.model).toBe("omnirush/gpt-6-astra");
+ expect(Object.keys(models).sort()).toEqual(["gpt-5.6-sol", "gpt-6-astra", "meta-muse-spark", "muse-spark-1.1", "muse-spark-1.3"]);
+ const { models: _v109Models, ...v109Plumbing } = v109OmniRushProvider("http://127.0.0.1:48123/omnirush-gateway/v1");
+ const { models: _models, ...plumbing } = provider;
+ expect(plumbing).toEqual(v109Plumbing);
+ expect(models["gpt-6-astra"]).toEqual(asEngineReadsIt(v109OmniRushProvider("").models["gpt-6-astra"]) as Record<string, unknown>);
+ expect(models["meta-muse-spark"]).toEqual({
+ name: "Meta Muse Spark",
+ family: "Meta Muse",
+ reasoning: true,
+ tool_call: true,
+ structured_output: true,
+ temperature: true,
+ variants: museVariants,
+ limit: { context: 158_000, output: 32_000 },
+ modalities: { input: ["text", "image", "pdf"], output: ["text"] },
+ });
+ expect(models["muse-spark-1.3"]).toEqual({
+ name: "Meta Muse Spark 1.3",
+ family: "Meta Muse",
+ status: "beta",
+ reasoning: true,
+ tool_call: true,
+ structured_output: true,
+ temperature: true,
+ variants: museVariants,
+ limit: { context: 99_000, output: 16_000 },
+ modalities: { input: ["text"], output: ["text"] },
+ });
+ for (const model of Object.values(models)) expect(model.attachment).toBeUndefined();
+ });
+
+ test("provider plumbing never comes from the catalog, even from a tampered cache file", async () => {
+ const { config } = await setup();
+ signIn(config);
+ const body = backendCatalogBody();
+ const tampered = {
+ ...body,
+ npm: "evil-sdk",
+ data: body.data.map((model) => ({
+ ...model,
+ npm: "evil-sdk",
+ api: "chat",
+ baseURL: "https://attacker.example/v1",
+ options: { baseURL: "https://attacker.example/v1" },
+ headers: { authorization: "Bearer stolen" },
+ provider: { npm: "evil-sdk" },
+ })),
+ };
+ tampered.data.push({ ...tampered.data[0]!, id: "gpt-6-astra-2", api: "responses" });
+ await mkdir(dirname(omnirushRuntimeConfigFilePath(config)), { recursive: true });
+ await writeFile(join(dirname(omnirushRuntimeConfigFilePath(config)), "omnirush-model-catalog.json"), JSON.stringify(tampered));
+ const text = await buildOmniRushRuntimeConfig(config);
+ for (const leaked of ["evil-sdk", "attacker.example", "stolen"]) expect(text).not.toContain(leaked);
+ const parsed = JSON.parse(text) as Record<string, unknown>;
+ const provider = providerOf(parsed);
+ expect(provider.npm).toBe("@ai-sdk/openai");
+ expect(provider.options).toEqual({ baseURL: "http://127.0.0.1:48123/omnirush-gateway/v1" });
+ // Only the one entry still on the Responses API survives.
+ expect(Object.keys(provider.models as object)).toEqual(["gpt-6-astra-2"]);
+ });
+
+ test("a deprecated catalog model stays selectable in the engine (which deletes deprecated models)", () => {
+ const body = backendCatalogBody();
+ const catalog = sanitizeOmniRushModelCatalog({ ...body, data: body.data.map((model) => ({ ...model, status: "deprecated" })) })!;
+ expect(catalog.every((model) => model.status === "deprecated")).toBe(true);
+ const parsed = buildOmniRushRuntimeConfigObjectFromSnapshot({}, gateway, process.env, catalog);
+ for (const model of Object.values(providerOf(parsed).models as Record<string, Record<string, unknown>>)) {
+ expect(model.status).toBeUndefined();
+ }
+ });
+
+ test("identical catalogs render identical bytes, so the engine pool sees no change", async () => {
+ const { config } = await setup();
+ signIn(config);
+ await writeOmniRushModelCatalog(config, sanitizeOmniRushModelCatalog(backendCatalogBody())!);
+ const first = await buildOmniRushRuntimeConfig(config);
+ const reordered = backendCatalogBody();
+ reordered.data = reordered.data.map((model) => Object.fromEntries(Object.entries(model).reverse()) as typeof model);
+ await writeOmniRushModelCatalog(config, sanitizeOmniRushModelCatalog(reordered)!);
+ expect(await buildOmniRushRuntimeConfig(config)).toBe(first);
+ });
+
+ test("a signed-out server never reads the catalog", async () => {
+ const { config } = await setup();
+ await writeOmniRushModelCatalog(config, sanitizeOmniRushModelCatalog(backendCatalogBody())!);
+ const parsed = JSON.parse(await buildOmniRushRuntimeConfig(config)) as Record<string, unknown>;
+ expect((parsed.provider as Record<string, unknown> | undefined)?.omnirush).toBeUndefined();
+ expect(parsed.model).toBeUndefined();
+ });
+});
diff --git a/apps/server/src/omnirush-runtime-config.ts b/apps/server/src/omnirush-runtime-config.ts
index 6679859b..8628860e 100644
--- a/apps/server/src/omnirush-runtime-config.ts
+++ b/apps/server/src/omnirush-runtime-config.ts
@@ -45,26 +45,15 @@ import {
import { CONNECT_MCP_SERVER_NAME_PREFIX } from "./connect-mcp-server-catalog.js";
import { isOmniRushUiMcpRegistryEntry } from "./omnirush-ui-mcp-command.js";
import { OMNIRUSH_AGENT_PROMPT } from "./omnirush-agent-prompt.js";
+import {
+ builtinOmniRushModelCatalog,
+ engineModelsFromCatalog,
+ omnirushDefaultModelId,
+ readOmniRushModelCatalog,
+ type OmniRushModelCatalog,
+} from "./omnirush-model-catalog.js";
const INTERNAL_PROVIDER_ID = "omnirush";
-const INTERNAL_DEFAULT_MODEL_ID = "gpt-6-astra";
-/**
- * Effort levels offered for every omnirush.ai model, in picker order. Clients
- * send these literal values; "max" is the upstream's top level.
- */
-const INTERNAL_REASONING_EFFORTS = ["low", "high", "xhigh", "max"] as const;
-/**
- * Effort levels the engine adds on its own to every reasoning model served by
- * the OpenAI adapter (it merges its defaults into the configured variants and
- * drops only entries marked disabled). Declaring them disabled keeps the
- * picker at exactly INTERNAL_REASONING_EFFORTS and the default at "high".
- */
-const INTERNAL_HIDDEN_EFFORTS = ["none", "minimal", "medium"] as const;
-/** Models served by the omnirush.ai account route. The default comes first. */
-const INTERNAL_MODELS: ReadonlyArray<{ id: string; name: string }> = [
- { id: INTERNAL_DEFAULT_MODEL_ID, name: "GPT 6 Astra" },
- { id: "gpt-5.6-sol", name: "GPT-5.6 Sol" },
-];
type InternalGatewayRuntime = {
baseUrl: string;
@@ -104,31 +93,7 @@ function resolveConfiguredInternalGatewayRuntime(
return resolveInternalGatewayRuntime(env);
}
-function internalGatewayModel(name: string): Record<string, unknown> {
- return {
- name,
- reasoning: true,
- tool_call: true,
- structured_output: true,
- temperature: true,
- // Keep the effort controls visible in the desktop model picker. The
- // selected variant is merged into the request options by the engine; the
- // omnirush-reasoning-effort plugin and the local gateway broker make sure
- // it reaches the outgoing request as reasoning.effort for every model.
- variants: {
- ...Object.fromEntries(
- INTERNAL_REASONING_EFFORTS.map((effort) => [effort, { reasoning_effort: effort }]),
- ),
- ...Object.fromEntries(
- INTERNAL_HIDDEN_EFFORTS.map((effort) => [effort, { disabled: true }]),
- ),
- },
- limit: { context: 400_000, output: 128_000 },
- modalities: { input: ["text", "image", "pdf"], output: ["text"] },
- };
-}
-
-function internalGatewayProvider(runtime: InternalGatewayRuntime): Record<string, unknown> {
+function internalGatewayProvider(runtime: InternalGatewayRuntime, catalog: OmniRushModelCatalog): Record<string, unknown> {
return {
// The native OpenAI provider uses the Responses API, which preserves
// reasoning summaries, tool calls, and delegated task events. The generic
@@ -138,9 +103,9 @@ function internalGatewayProvider(runtime: InternalGatewayRuntime): Record<string
name: "omnirush.ai",
env: ["OMNIRUSH_ACCESS_TOKEN"],
options: { baseURL: runtime.baseUrl },
- models: Object.fromEntries(
- INTERNAL_MODELS.map((model) => [model.id, internalGatewayModel(model.name)]),
- ),
+ // Only models come from the account's catalog; the provider fields above
+ // never do, so a catalog cannot route the engine past the local broker.
+ models: engineModelsFromCatalog(catalog),
};
}
@@ -148,14 +113,17 @@ export async function buildOmniRushRuntimeConfigObject(
config?: ServerConfig,
): Promise<Record<string, unknown>> {
// Workspace-independent by design: the injected engine config file is
- // rendered from the ENGINE_GLOBAL runtime row plus static built-ins only,
- // so workspace activation rewrites identical bytes and never varies the
- // engine-pool fingerprint. Per-workspace MCPs reach the engine through the
- // dynamic push path instead.
+ // rendered from the ENGINE_GLOBAL runtime row, the synced model catalog and
+ // static built-ins only, so workspace activation rewrites identical bytes
+ // and never varies the engine-pool fingerprint. Per-workspace MCPs reach the
+ // engine through the dynamic push path instead.
const runtimeConfig = config ? await readGlobalRuntimeOpencodeConfig(config) : {};
+ const internalGateway = resolveConfiguredInternalGatewayRuntime(config);
return buildOmniRushRuntimeConfigObjectFromSnapshot(
runtimeConfig,
- resolveConfiguredInternalGatewayRuntime(config),
+ internalGateway,
+ process.env,
+ internalGateway && config ? await readOmniRushModelCatalog(config) : undefined,
);
}
@@ -163,6 +131,7 @@ export function buildOmniRushRuntimeConfigObjectFromSnapshot(
runtimeConfig: RuntimeOpencodeConfig,
internalGateway?: InternalGatewayRuntime,
env: NodeJS.ProcessEnv = process.env,
+ catalog: OmniRushModelCatalog = builtinOmniRushModelCatalog(),
): Record<string, unknown> {
const disabledProviders = runtimeDisabledProviderList(runtimeConfig);
// OMNIRUSH_APPROVALS in the server environment wins over the persisted setting.
@@ -171,13 +140,13 @@ export function buildOmniRushRuntimeConfigObjectFromSnapshot(
const provider = {
...runtimeProviderMap(runtimeConfig),
...(internalGateway
- ? { [INTERNAL_PROVIDER_ID]: internalGatewayProvider(internalGateway) }
+ ? { [INTERNAL_PROVIDER_ID]: internalGatewayProvider(internalGateway, catalog) }
: {}),
};
return {
...engineConfig,
...(internalGateway
- ? { model: `${INTERNAL_PROVIDER_ID}/${INTERNAL_DEFAULT_MODEL_ID}` }
+ ? { model: `${INTERNAL_PROVIDER_ID}/${omnirushDefaultModelId(catalog)}` }
: {}),
...(runtimeConfig.managedPolicy?.allowCustomProviders === false ? { enabled_providers: [
...Object.keys(provider).filter((id) => /^(?:lpr_|omnirush$)/i.test(id)),
diff --git a/apps/server/src/server.ts b/apps/server/src/server.ts
index fe67088d..f4cf6125 100644
--- a/apps/server/src/server.ts
+++ b/apps/server/src/server.ts
@@ -160,6 +160,7 @@ import { createEngineV2Preview, type EngineV2Preview } from "./engine-v2-preview
import { MAX_COLLECTOR_CHILD_SESSION_DEPTH, WorkspaceCollector, type CollectorSessionModel } from "./workspace-collector.js";
import { collectPromptAttachments, promptBodyForTrace } from "./collector-attachments.js";
import { OmniRushGatewayBroker } from "./omnirush-gateway-broker.js";
+import { startOmniRushModelCatalogSync } from "./omnirush-model-catalog-sync.js";
import { createProjectArchive } from "./project-archive.js";
import { isFinishedAssistantMessage, type ArchiveEngineReads, type ProjectArchiveLifecycle } from "./session-archive/lifecycle.js";
import { runtimeStorageDir } from "./runtime-db.js";
@@ -1596,6 +1597,26 @@ export async function startServer(config: ServerConfig): Promise<ServeResult> {
.catch(() => undefined);
engineInstanceReaper.start();
+ // The account's model catalog (omnirush-model-catalog-sync.ts): a change
+ // reloads the engine like a cloud provider sync, without stopping a run.
+ const modelCatalogSync = startOmniRushModelCatalogSync({
+ config,
+ broker: gatewayBroker,
+ reloadEngine: async () => {
+ if (config.workspaces.length === 0) return;
+ await reloadOpencodeEngine(config, resolveEngineRuntimeWorkspace(config), engineMcpServerState, {
+ forceStandby: true,
+ reason: "omnirush_model_catalog",
+ });
+ },
+ engineBusy: () => {
+ const pool = enginePoolForConfig(config);
+ return pool
+ ? Promise.resolve(pool.hasDrainingGeneration())
+ : engineHasActiveSessions(config, resolveEngineRuntimeWorkspace(config));
+ },
+ log: (level, message, attributes) => logger.log(level, message, attributes),
+ });
return {
...server,
@@ -1615,6 +1636,7 @@ export async function startServer(config: ServerConfig): Promise<ServeResult> {
await localWorkflowServices.get(config)?.stop();
managedDesktopPolicy(config).onChange = undefined;
cloudProviderSync.stop();
+ modelCatalogSync.stop();
await engineV2Preview.stop().catch(() => undefined);
engineInstanceReaper.close();
clearEngineInstanceReaperForConfig(config);
diff --git a/docs/skills-and-mcp.md b/docs/skills-and-mcp.md
index cbc2d266..169c1cb9 100644
--- a/docs/skills-and-mcp.md
+++ b/docs/skills-and-mcp.md
@@ -2,7 +2,7 @@
This document describes how a user adds a skill and an MCP server in the desktop app, where the files live, how they reach the bundled engine (the OpenCode sidecar that serves the omnirush.ai models and any external provider), and how to troubleshoot when something does not show up.
-The same flows apply to every model: the omnirush.ai models (GPT 6 Astra, GPT-5.6 Sol via the local gateway broker) and external providers (OpenAI, Anthropic, and others) all run in the same engine and see the same skills and MCP tools.
+The same flows apply to every model: the omnirush.ai models (GPT 6 Astra, GPT-5.6 Sol and any other model the account's catalog lists, such as Meta Muse, via the local gateway broker) and external providers (OpenAI, Anthropic, and others) all run in the same engine and see the same skills and MCP tools.
## Moving parts
@@ -117,7 +117,7 @@ The engine-visible config file is rendered from the engine-global runtime row pl
- `provider.omnirush` (the omnirush.ai models, `baseURL` pointing at the local gateway broker) is added after any runtime `provider` entries, so a runtime provider with the same id cannot shadow it.
- `mcp` holds only the engine-global entries (for example `omnirush-cloud`); workspace MCP entries are pushed dynamically and never collide with it.
- `disabled_providers` is copied through untouched.
-- `model` defaults to `omnirush/gpt-6-astra` when the account is signed in.
+- `model` defaults to the account catalog's default model (`omnirush/gpt-6-astra`) when the account is signed in. The `omnirush` provider's models come from the catalog the server syncs from `GET /omnirush/v1/models` (ids, names, efforts, limits and input types only); its package, base URL and credentials never do.
Adding skills or MCP servers never modifies the provider block.