A desktop coding agent with free access to frontier models.
TypeScript
import { afterEach, describe, expect, test } from "bun:test";
import { mkdir, mkdtemp, readFile, rm, stat, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { dirname, join } from "node:path";
import {
buildOmniRushRuntimeConfig,
buildOmniRushRuntimeConfigObjectFromSnapshot,
keepOmniRushRuntimeConfigFileFresh,
omnirushOwnPluginPaths,
omnirushRuntimeConfigFilePath,
omnirushRuntimeSkillsDir,
writeOmniRushRuntimeConfigFile,
} 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 { MAX_UPLOAD_CHILD_SESSION_DEPTH } from "./session-uploader.js";
import {
OMNIRUSH_SUBAGENT_DEPTH,
OMNIRUSH_SWARM_MAX_PER_TURN,
OMNIRUSH_SWARM_MAX_RUNNING,
OMNIRUSH_SWARM_SKILL,
OMNIRUSH_SWARM_ARCHIVE_DIR,
OMNIRUSH_SWARM_SKILL_NAME,
OMNIRUSH_SWARM_TOOL_NAME,
omnirushSwarmSkillMarkdown,
omnirushSwarmSubagentNote,
omnirushSubagentNote,
} from "./omnirush-swarm.js";
import { parseFrontmatter } from "./frontmatter.js";
import {
sanitizeOmniRushModelCatalog,
writeOmniRushModelCatalog,
type OmniRushModelCatalog,
} from "./omnirush-model-catalog.js";
import { legacyExecutionPermissions } from "./managed-policy-rules.js";
/** The default (Normal) injected permission block: shared Normal bash/read rules, then the git workflow rules. */
const GUARDED = legacyExecutionPermissions(undefined, "guarded");
import { OMNIRUSH_AGENT_PROMPT } from "./omnirush-agent-prompt.js";
import { BestPracticesEngineReloads, OMNIRUSH_BEST_PRACTICES, omnirushBestPracticesSkillsDir, waitForBestPracticesReady } from "./best-practices.js";
import type { ServerConfig } from "./types.js";
import { providerLockPolicy } from "./provider-lock/provider-lock.mjs";
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;
});
async function setup() {
const root = await mkdtemp(join(tmpdir(), "omnirush-runtime-config-file-"));
roots.push(root);
previousDb = process.env.OMNIRUSH_RUNTIME_DB;
process.env.OMNIRUSH_RUNTIME_DB = join(root, "runtime.sqlite");
const config: ServerConfig = {
host: "127.0.0.1",
port: 0,
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,
};
return { root, config };
}
async function readConfigFile(config: ServerConfig): Promise<Record<string, unknown>> {
const raw = await readFile(omnirushRuntimeConfigFilePath(config), "utf8");
return JSON.parse(raw) as Record<string, unknown>;
}
describe("omnirush runtime config file", () => {
test("leaves MCP to the policy plugin, loaded last, with no MCP permission rules", () => {
const parsed = buildOmniRushRuntimeConfigObjectFromSnapshot(
{ mcp: { posthog: { type: "remote", url: "https://mcp.example" } } },
undefined,
{},
undefined,
undefined,
undefined,
);
expect(parsed.mcp).toBeUndefined();
expect(JSON.stringify(parsed.permission)).not.toContain("mcp");
const plugins = Array.isArray(parsed.plugin) ? parsed.plugin : [];
expect(plugins.some((plugin) => typeof plugin === "string" && plugin.includes("omnirush-mcp-policy"))).toBe(true);
expect(String(plugins.at(-1))).toContain("omnirush-mcp-policy");
});
test("every plugin omnirush.ai configures is named as its own, so the engine never holds a project for their install", () => {
// Unlocked by the server, the user's plugin is the only one not ours; locked, the app's own only (provider-lock.ts).
const unlocked = providerLockPolicy({ providers: { locked: false } });
const parsed = buildOmniRushRuntimeConfigObjectFromSnapshot({ plugin: ["[email protected]"] }, undefined, {}, undefined, undefined, undefined, null, [], unlocked);
const plugins = Array.isArray(parsed.plugin) ? parsed.plugin.map(String) : [];
const own = new Set(omnirushOwnPluginPaths());
expect(plugins.filter((plugin) => !own.has(plugin))).toEqual(["[email protected]"]);
const locked = buildOmniRushRuntimeConfigObjectFromSnapshot({ plugin: ["[email protected]"] });
expect((locked.plugin as string[]).filter((plugin) => !own.has(plugin))).toEqual([]);
expect([...own].some((plugin) => /omnirush-box\.(?:ts|js)$/.test(plugin))).toBe(true);
});
test("managed browser restrictions use scalar actions in global and agent permissions", () => {
const parsed = buildOmniRushRuntimeConfigObjectFromSnapshot({
managedPolicy: {
execution: {
commands: "deny", blockedCommands: ["curl *"],
browserOrigins: ["https://approved.example"], blockBrowserUploads: true,
},
},
});
// Normal's shared rules and the built-in git workflow rules come first; the organization's
// execution rules are appended last so the engine's last-match-wins evaluation keeps them.
const { "*": _allow, ...guardedBash } = legacyExecutionPermissions(undefined).bash;
const permission = { bash: { ...guardedBash, "*": "deny", "curl *": "deny" }, read: GUARDED.read, webfetch: "deny", websearch: "deny" };
expect(parsed.permission).toEqual(permission);
expect(Object.keys((parsed.permission as { bash: Record<string, string> }).bash).slice(-2)).toEqual(["*", "curl *"]);
expect(parsed.agent).toMatchObject({ omnirush: { permission } });
expect(parsed.managedPolicy).toBeUndefined();
expect(buildOmniRushRuntimeConfigObjectFromSnapshot({}).permission).toEqual(GUARDED);
});
test("full approval mode allows every permission category; the environment overrides the setting", () => {
const permission = { bash: { "*": "allow" }, read: { "*": "allow" }, edit: "allow", webfetch: "allow", websearch: "allow", doom_loop: "allow", external_directory: "allow" };
const full = buildOmniRushRuntimeConfigObjectFromSnapshot(
{ approvals: { mode: "full" }, permission: { external_directory: { "/Users/sam/Docs": "allow" } } },
undefined,
{},
);
expect(full.permission).toEqual(permission);
expect(full.agent).toMatchObject({ omnirush: { permission: { ...permission, skill: { "get-started": "deny" } } } });
// The setting is server state, never engine config.
expect(full.approvals).toBeUndefined();
// The engine asks before reading .env files by default and appends the injected block after its
// own rules; the full-mode catch-all read allow wins, the guarded block keeps asking.
const engineEnvDefaults = [{ permission: "read", pattern: "*.env", action: "ask" as const }, { permission: "read", pattern: "*.env.*", action: "ask" as const }];
const guarded = buildOmniRushRuntimeConfigObjectFromSnapshot({}, undefined, {});
for (const file of ["/workspace/.env", "/workspace/.env.local"]) {
expect(winningRule([...engineEnvDefaults, ...rulesFromPermissionConfig(full.permission)], "read", file)?.action).toBe("allow");
expect(winningRule([...engineEnvDefaults, ...rulesFromPermissionConfig(guarded.permission)], "read", file)?.action).toBe("ask");
}
// Organization denies are appended last so the engine's last-match-wins keeps them.
const denied = buildOmniRushRuntimeConfigObjectFromSnapshot({
approvals: { mode: "full" },
managedPolicy: { execution: { commands: "allow", blockedCommands: ["curl *"], browserOrigins: ["https://approved.example"], blockBrowserUploads: false } },
}, undefined, {});
expect(denied.permission).toEqual({ ...permission, bash: { "*": "allow", "curl *": "deny" }, webfetch: "deny", websearch: "deny" });
// OMNIRUSH_APPROVALS on the server process wins in both directions; the default stays guarded.
expect(buildOmniRushRuntimeConfigObjectFromSnapshot({ approvals: { mode: "full" } }, undefined, { OMNIRUSH_APPROVALS: "guarded" }).permission)
.toEqual(GUARDED);
expect(buildOmniRushRuntimeConfigObjectFromSnapshot({}, undefined, { OMNIRUSH_APPROVALS: "full" }).permission).toEqual(permission);
expect(buildOmniRushRuntimeConfigObjectFromSnapshot({}, undefined, {}).permission).toEqual(GUARDED);
});
test("omits global-row MCPs while writing omnirush defaults into the file", async () => {
const { config } = await setup();
await writeGlobalRuntimeOpencodeConfig(config, (current) => ({
...current,
mcp: {
posthog: { type: "remote", url: "https://mcp.posthog.com/mcp", enabled: true },
"omnirush-connect-stale": { type: "remote", url: "https://cloud.example/stale", enabled: true },
},
}));
const { path } = await writeOmniRushRuntimeConfigFile(config);
expect(path).toBe(omnirushRuntimeConfigFilePath(config));
const parsed = await readConfigFile(config);
expect(parsed.mcp).toBeUndefined();
expect(parsed.default_agent).toBe("omnirush");
// No session sharing to an outside share service.
expect(parsed.share).toBe("disabled");
expect(Array.isArray(parsed.plugin)).toBe(true);
if (!Array.isArray(parsed.plugin)) throw new Error("Expected runtime plugins");
expect(parsed.plugin).not.toContain("opencode-chrome-devtools");
expect(parsed.plugin.some(
(plugin) => typeof plugin === "string" && /omnirush-chrome-devtools\.(?:ts|js)$/.test(plugin),
)).toBe(true);
expect(parsed.agent).toMatchObject({
omnirush: {
permission: {
skill: {
"customize-opencode": "deny",
"get-started": "deny",
"command-creator": "deny",
"agent-creator": "deny",
"plugin-creator": "deny",
},
},
},
});
});
test("injects the account-scoped internal gateway without persisting its access token", () => {
const parsed = buildOmniRushRuntimeConfigObjectFromSnapshot({}, {
baseUrl: "http://127.0.0.1:8090/omnirush/v1",
});
const providers = parsed.provider as Record<string, Record<string, unknown>>;
expect(parsed.model).toBe("omnirush/gpt-6-astra");
expect(providers.omnirush).toMatchObject({
npm: "@ai-sdk/openai",
name: "omnirush.ai",
env: ["OMNIRUSH_ACCESS_TOKEN"],
options: { baseURL: "http://127.0.0.1:8090/omnirush/v1" },
});
// The permission rules name commands that print access tokens; no token value is anywhere else.
expect(JSON.stringify({ ...parsed, permission: undefined, agent: undefined })).not.toContain("access-token");
});
test("exposes every omnirush.ai model with the shared effort levels, default first", () => {
const parsed = buildOmniRushRuntimeConfigObjectFromSnapshot({}, {
baseUrl: "http://127.0.0.1:8090/omnirush/v1",
});
const providers = parsed.provider as Record<string, { models: Record<string, Record<string, unknown>> }>;
const models = providers.omnirush!.models;
const variants = {
low: { reasoningEffort: "low" },
high: { reasoningEffort: "high" },
xhigh: { reasoningEffort: "xhigh" },
max: { reasoningEffort: "max" },
// The engine merges its own OpenAI reasoning defaults into a model's
// variants and only drops entries marked disabled; these keep the
// resolved picker at exactly the four levels above.
none: { disabled: true },
minimal: { disabled: true },
medium: { disabled: true },
};
const enabledVariants = (model: Record<string, unknown>) => Object.entries(model.variants as Record<string, { disabled?: boolean }>)
.filter(([, options]) => options.disabled !== true)
.map(([key]) => key);
expect(Object.keys(models)).toEqual(["gpt-6-astra", "gpt-6.1-sol", "gpt-6-sol"]);
expect(models["gpt-6-astra"]).toMatchObject({ name: "GPT 6 Astra", reasoning: true, tool_call: true, variants });
expect(models["gpt-6-sol"]).toMatchObject({ name: "GPT 6 Sol", reasoning: true, tool_call: true, variants });
expect(models["gpt-6.1-sol"]).toMatchObject({ name: "GPT 6.1 Sol", reasoning: true, tool_call: true, variants });
for (const id of ["gpt-6-astra", "gpt-6.1-sol", "gpt-6-sol"]) {
expect(Object.keys(models[id]!.variants as object).sort()).toEqual(Object.keys(variants).sort());
expect(enabledVariants(models[id]!)).toEqual(["low", "high", "xhigh", "max"]);
// The default effort (High, as the picker shows), for a message that names no variant.
expect(models[id]!.options).toEqual({ reasoningEffort: "high" });
}
expect(parsed.model).toBe("omnirush/gpt-6-astra");
expect((parsed.plugin as string[]).some((plugin) => /omnirush-reasoning-effort\.(?:ts|js)$/.test(plugin))).toBe(true);
});
test("derives the desktop loopback gateway from the server config without process-global credentials", async () => {
const { config } = await setup();
config.port = 48123;
config.omnirushEngineToken = "ephemeral-engine-token";
config.omnirushGatewayCredentials = {
gatewayUrl: "https://api.example.test/omnirush/v1",
accessToken: "device-access-token",
refreshToken: "device-refresh-token",
};
const previous = {
engineGateway: process.env.OMNIRUSH_ENGINE_GATEWAY_URL,
gateway: process.env.OMNIRUSH_GATEWAY_URL,
access: process.env.OMNIRUSH_ACCESS_TOKEN,
};
try {
delete process.env.OMNIRUSH_ENGINE_GATEWAY_URL;
delete process.env.OMNIRUSH_GATEWAY_URL;
delete process.env.OMNIRUSH_ACCESS_TOKEN;
const parsed = JSON.parse(await buildOmniRushRuntimeConfig(config)) as Record<string, unknown>;
const providers = parsed.provider as Record<string, Record<string, unknown>>;
expect(parsed.model).toBe("omnirush/gpt-6-astra");
expect(providers.omnirush).toMatchObject({
env: ["OMNIRUSH_ACCESS_TOKEN"],
options: { baseURL: "http://127.0.0.1:48123/omnirush-gateway/v1" },
});
expect(JSON.stringify(parsed)).not.toContain("device-access-token");
expect(JSON.stringify(parsed)).not.toContain("device-refresh-token");
expect(JSON.stringify(parsed)).not.toContain("ephemeral-engine-token");
} finally {
if (previous.engineGateway === undefined) delete process.env.OMNIRUSH_ENGINE_GATEWAY_URL;
else process.env.OMNIRUSH_ENGINE_GATEWAY_URL = previous.engineGateway;
if (previous.gateway === undefined) delete process.env.OMNIRUSH_GATEWAY_URL;
else process.env.OMNIRUSH_GATEWAY_URL = previous.gateway;
if (previous.access === undefined) delete process.env.OMNIRUSH_ACCESS_TOKEN;
else process.env.OMNIRUSH_ACCESS_TOKEN = previous.access;
}
});
test("reserves the internal provider id for the account-scoped gateway", () => {
const parsed = buildOmniRushRuntimeConfigObjectFromSnapshot({
provider: {
omnirush: { npm: "untrusted-override", name: "Wrong route" },
},
}, {
baseUrl: "https://api.omnirush.ai/omnirush/v1",
});
const providers = parsed.provider as Record<string, Record<string, unknown>>;
expect(parsed.model).toBe("omnirush/gpt-6-astra");
expect(providers.omnirush).toMatchObject({
npm: "@ai-sdk/openai",
options: { baseURL: "https://api.omnirush.ai/omnirush/v1" },
});
});
test("workspace runtime rows never reach the injected file", async () => {
const { config } = await setup();
await writeRuntimeOpencodeConfig(config, "ws_1", (current) => ({
...current,
mcp: { posthog: { type: "remote", url: "https://mcp.posthog.com/mcp", enabled: true } },
}));
await writeOmniRushRuntimeConfigFile(config);
const parsed = await readConfigFile(config);
const mcp = (parsed.mcp ?? {}) as Record<string, Record<string, unknown>>;
expect(mcp.posthog).toBeUndefined();
});
test("never injects a registry launch of omnirush-ui-mcp, whatever the snapshot holds", () => {
const bundled = {
type: "local",
command: [
"/Applications/OmniRush.ai.app/Contents/MacOS/OmniRush.ai",
"/Applications/OmniRush.ai.app/Contents/Resources/omnirush-ui-mcp/index.mjs",
],
environment: { ELECTRON_RUN_AS_NODE: "1" },
};
const built = buildOmniRushRuntimeConfigObjectFromSnapshot({
mcp: {
"omnirush-ui": { type: "local", command: ["npx", "-y", "omnirush-ui-mcp"], enabled: true },
"ui-bunx": { type: "local", command: ["bunx", "omnirush-ui-mcp@latest"] },
"ui-bundled": bundled,
},
});
expect(built.mcp).toBeUndefined();
});
test("omnirush prompt states identity, repo memory, artifacts, and Connect routing once, without the removed Memory Bank", async () => {
const { config } = await setup();
await writeOmniRushRuntimeConfigFile(config);
const parsed = await readConfigFile(config);
const agent = parsed.agent as Record<string, { prompt?: string }>;
const prompt = agent.omnirush?.prompt ?? "";
expect(prompt.startsWith("You are the user's coding assistant.")).toBe(true);
expect(prompt).toContain("## Memory\n");
expect(prompt).toContain("## Artifacts");
expect(prompt).toContain("## Connected work");
expect(prompt).not.toContain("Split real work");
expect(prompt).toContain("Do the work yourself by default");
expect(prompt).toContain("## Autonomy and persistence");
expect(prompt).toContain("Verify before you finish.");
expect(prompt).toContain("never report an unrun check as passed");
expect(prompt).toContain("## Final answer");
expect(prompt).toContain("When the user asks only for an explanation, a review or a plan, answer and do not change files.");
expect(prompt).toContain("make exactly that many task-tool calls, no more and no fewer, and start them all in one message");
expect(prompt).toContain("Never paste the user's whole message, or the user's instructions about sub-agents, into a sub-agent's prompt");
expect(prompt).toContain("Never replace an explicit delegation request with a simulated multi-role answer");
expect(prompt).toContain("Wait for every delegated task");
// Den removed the Memory Bank; the prompt must not teach capabilities that
// the live catalog can no longer return.
expect(prompt).not.toContain("Memory Bank");
expect(prompt).not.toContain("postMemory");
expect(prompt).not.toContain("getMemorySearch");
// Connect tool names appear exactly once each, in the base prompt's own
// routing paragraph; the diagnostics prompt markers key on them.
expect(prompt.match(/search_capabilities/g)).toHaveLength(1);
expect(prompt.match(/execute_capability/g)).toHaveLength(1);
expect(prompt).not.toContain("2-4 keyword variants");
// Skill capture defers to the runtime skill-authoring mode instead of
// contradicting it with a workspace-only default.
expect(prompt).toContain("`Skill creation:` instruction");
expect(prompt).not.toContain("factor them into a skill");
});
test("sub-agent swarms: nested delegation up to the captured depth, for the general sub-agent only, bounded by the swarm plugin", () => {
for (const mode of ["guarded", "full"] as const) {
const parsed = buildOmniRushRuntimeConfigObjectFromSnapshot({ approvals: { mode } } as never, undefined, {});
// The engine counts layers below the main session and refuses the task
// tool at subagent_depth; the session uploader walks the same number of layers.
expect(parsed.subagent_depth).toBe(OMNIRUSH_SUBAGENT_DEPTH);
expect(OMNIRUSH_SUBAGENT_DEPTH).toBe(MAX_UPLOAD_CHILD_SESSION_DEPTH);
const agents = parsed.agent as Record<string, { permission?: Record<string, unknown>; prompt?: string; mode?: string }>;
// A sub-agent keeps the task tool only when its own rules mention it:
// only general does; no global task rule reaches explore.
expect(agents.general).toEqual({ permission: { task: "allow", skill: { [OMNIRUSH_SWARM_SKILL_NAME]: "deny" } } });
expect(agents.explore).toBeUndefined();
expect((parsed.permission as Record<string, unknown>).task).toBeUndefined();
expect(agents.omnirush?.permission?.task).toBeUndefined();
// The board tool is for sub-agents only: hidden from the main agent.
expect(agents.omnirush?.permission?.[OMNIRUSH_SWARM_TOOL_NAME]).toBe("deny");
expect(agents.general?.permission?.[OMNIRUSH_SWARM_TOOL_NAME]).toBeUndefined();
expect((parsed.plugin as string[]).some((plugin) => /omnirush-swarm\.(?:ts|js)$/.test(plugin))).toBe(true);
}
const prompt = (buildOmniRushRuntimeConfigObjectFromSnapshot({}).agent as Record<string, { prompt: string }>).omnirush!.prompt;
expect(prompt).toContain("## Sub-agent swarms");
expect(OMNIRUSH_SWARM_MAX_RUNNING).toBe(Number.POSITIVE_INFINITY);
expect(OMNIRUSH_SWARM_MAX_PER_TURN).toBe(Number.POSITIVE_INFINITY);
expect(prompt.indexOf("## Sub-agent swarms")).toBeLessThan(prompt.indexOf("## Editing files"));
});
test("the always-on prompt only says when to load the swarm skill; the board procedure is the skill", () => {
const prompt = (buildOmniRushRuntimeConfigObjectFromSnapshot({}).agent as Record<string, { prompt: string }>).omnirush!.prompt;
const section = prompt.slice(prompt.indexOf("## Sub-agent swarms"), prompt.indexOf("## Editing files"));
expect(section).toContain(`load the \`${OMNIRUSH_SWARM_SKILL_NAME}\` skill first`);
expect(section).toContain("Before you start 3 or more sub-agents for implementation work");
expect(section).toContain("follow the Sub-agents rules above");
expect(section).not.toContain("use 1-2 sub-agents directly when they help");
// No board mechanics on every request: no file name, no table, no layers.
expect(prompt).not.toContain("swarm.md");
expect(prompt).not.toContain("## Tasks");
expect(section.length).toBeLessThan(500);
// The skill carries the procedure, with the board under .omnirush/.
expect(OMNIRUSH_SWARM_SKILL).toContain("`.omnirush/swarm.md`");
expect(OMNIRUSH_SWARM_SKILL).toContain("never a file in the project root");
expect(OMNIRUSH_SWARM_SKILL).toContain("For 1-2 sub-agents, stop here");
expect(OMNIRUSH_SWARM_SKILL).toContain("Sub-agents do their own task themselves");
expect(OMNIRUSH_SWARM_SKILL).toContain("never the user's whole message or instructions about sub-agents");
// Sub-agents use the board tool instead of reading the whole board, and
// the app (not the model) clears the board when the turn ends.
expect(OMNIRUSH_SWARM_SKILL).toContain(`use the \`${OMNIRUSH_SWARM_TOOL_NAME}\` tool with your task id`);
expect(OMNIRUSH_SWARM_SKILL).toContain("do not read or edit the board file");
expect(OMNIRUSH_SWARM_SKILL).toContain("the app does that when the turn ends");
const { data, body } = parseFrontmatter(omnirushSwarmSkillMarkdown());
expect(data.name).toBe(OMNIRUSH_SWARM_SKILL_NAME);
expect(String(data.description)).toContain("Required before starting 3 or more sub-agents for implementation work");
expect(body.trim()).toBe(OMNIRUSH_SWARM_SKILL);
});
test("no prompt, skill or sub-agent note points a model at archived boards", () => {
const prompt = (buildOmniRushRuntimeConfigObjectFromSnapshot({}).agent as Record<string, { prompt: string }>).omnirush!.prompt;
for (const text of [prompt, OMNIRUSH_SWARM_SKILL, omnirushSwarmSkillMarkdown(), omnirushSwarmSubagentNote(1), omnirushSwarmSubagentNote(3), omnirushSubagentNote(1), omnirushSubagentNote(3)]) {
expect(text).not.toContain(OMNIRUSH_SWARM_ARCHIVE_DIR);
expect(text).not.toContain("swarms/");
}
});
test("the engine loads the swarm skill from the runtime folder", async () => {
const { root, config } = await setup();
const { path } = await writeOmniRushRuntimeConfigFile(config);
const parsed = JSON.parse(await readFile(path, "utf8")) as { skills?: { paths?: string[] } };
const skillsDir = omnirushRuntimeSkillsDir(config);
expect(skillsDir.startsWith(root)).toBe(true);
expect(parsed.skills?.paths).toEqual([skillsDir, omnirushBestPracticesSkillsDir(config)]);
expect(await readFile(join(skillsDir, OMNIRUSH_SWARM_SKILL_NAME, "SKILL.md"), "utf8")).toBe(omnirushSwarmSkillMarkdown());
// Without a server config (specs, previews) nothing points at a folder.
expect(buildOmniRushRuntimeConfigObjectFromSnapshot({}).skills).toBeUndefined();
});
test("best practices default on, opt out without removing swarm skills, and restore after restart", async () => {
const { config } = await setup();
const swarmDir = omnirushRuntimeSkillsDir(config);
const bestDir = omnirushBestPracticesSkillsDir(config);
expect(dirname(bestDir)).toBe(dirname(swarmDir));
expect(bestDir.startsWith(`${swarmDir}/`)).toBe(false);
const prompt = `${OMNIRUSH_AGENT_PROMPT}\n\n${OMNIRUSH_BEST_PRACTICES.systemPrompt}`;
await writeOmniRushRuntimeConfigFile(config);
const on = await readConfigFile(config);
expect(on).toMatchObject({ skills: { paths: [swarmDir, bestDir] }, agent: { omnirush: { prompt } } });
expect(on.bestPractices).toBeUndefined();
expect(OMNIRUSH_BEST_PRACTICES.skills).toHaveLength(9);
expect(OMNIRUSH_BEST_PRACTICES.source.commit).toBe("4cd6fcedc62f604522db3621e5c509475ada6a0f");
expect(OMNIRUSH_BEST_PRACTICES.license).toContain("MIT License");
for (const skill of OMNIRUSH_BEST_PRACTICES.skills) {
expect(await readFile(join(bestDir, skill.name, "SKILL.md"), "utf8")).toBe(skill.content);
}
await writeGlobalRuntimeOpencodeConfig(config, (current) => ({ ...current, bestPractices: false }));
await writeOmniRushRuntimeConfigFile(config);
const off = await readConfigFile(config);
expect(off).toMatchObject({ skills: { paths: [swarmDir] }, agent: { omnirush: { prompt: OMNIRUSH_AGENT_PROMPT } } });
expect(off.bestPractices).toBeUndefined();
// A fresh config object, as on startup, still reads the local persisted choice.
expect(JSON.parse(await buildOmniRushRuntimeConfig({ ...config }))).toEqual(off);
expect(await readFile(join(swarmDir, OMNIRUSH_SWARM_SKILL_NAME, "SKILL.md"), "utf8")).toBe(omnirushSwarmSkillMarkdown());
await writeGlobalRuntimeOpencodeConfig(config, (current) => ({ ...current, bestPractices: true }));
await writeOmniRushRuntimeConfigFile(config);
expect(await readConfigFile(config)).toEqual(on);
});
test("attached-engine changes wait for busy folders, apply idle folders, and stop retrying at shutdown", async () => {
const { config } = await setup();
const first = config.workspaces[0];
const second = { ...first, id: "ws_second", path: join(first.path, "second") };
let busy = true;
const reloaded: string[] = [];
const reloads = new BestPracticesEngineReloads({
isBusy: async (workspace) => workspace.id === first.id && busy,
reload: async (workspace) => { reloaded.push(workspace.id); },
isPresent: () => true,
retryMs: 10,
});
try {
expect(await reloads.apply([first, second])).toBe("deferred");
expect(reloaded).toEqual([second.id]);
await new Promise((resolve) => setTimeout(resolve, 25));
expect(reloaded).toEqual([second.id]);
busy = false;
const deadline = Date.now() + 3_000;
while (reloaded.length === 1 && Date.now() < deadline) await new Promise((resolve) => setTimeout(resolve, 10));
expect(reloaded).toEqual([second.id, first.id]);
busy = true;
expect(await reloads.apply([first])).toBe("deferred");
reloads.stop();
busy = false;
await new Promise((resolve) => setTimeout(resolve, 25));
expect(reloaded).toEqual([second.id, first.id]);
await expect(reloads.apply([first])).rejects.toThrow("Best practices reloads stopped");
} finally {
reloads.stop();
}
});
test("a saved off choice neither materializes nor repairs the bundled guide folder", async () => {
const { config } = await setup();
await writeGlobalRuntimeOpencodeConfig(config, (current) => ({ ...current, bestPractices: false }));
const bestDir = omnirushBestPracticesSkillsDir(config);
await mkdir(dirname(bestDir), { recursive: true });
await writeFile(bestDir, "leave this path alone while off\n", "utf8");
await writeOmniRushRuntimeConfigFile(config);
expect(await readFile(bestDir, "utf8")).toBe("leave this path alone while off\n");
expect(await readConfigFile(config)).toMatchObject({ skills: { paths: [omnirushRuntimeSkillsDir(config)] } });
});
test("skills written under their earlier names are removed; user files next to them stay", async () => {
const { config } = await setup();
const swarmDir = omnirushRuntimeSkillsDir(config);
const bestDir = omnirushBestPracticesSkillsDir(config);
const oldSwarm = join(swarmDir, "omnirush-swarm");
const oldGuide = join(bestDir, "omnirush-build");
const keptGuide = join(bestDir, "omnirush-debug");
const userSkill = join(swarmDir, "omnirush-notes");
await mkdir(oldSwarm, { recursive: true });
await writeFile(join(oldSwarm, "SKILL.md"), "---\nname: omnirush-swarm\ndescription: old\n---\n\nold\n", "utf8");
await mkdir(oldGuide, { recursive: true });
await writeFile(join(oldGuide, "SKILL.md"), "---\nname: omnirush-build\ndescription: old\n---\n\nold\n", "utf8");
// A folder with the user's own file next to the old guide keeps that file.
await mkdir(keptGuide, { recursive: true });
await writeFile(join(keptGuide, "SKILL.md"), "---\nname: omnirush-debug\ndescription: old\n---\n", "utf8");
await writeFile(join(keptGuide, "notes.md"), "mine\n", "utf8");
// A skill the user wrote under an old-looking name but a different declared name stays.
await mkdir(userSkill, { recursive: true });
await writeFile(join(userSkill, "SKILL.md"), "---\nname: my-notes\n---\n", "utf8");
await writeOmniRushRuntimeConfigFile(config);
expect(await stat(oldSwarm).then(() => true, () => false)).toBe(false);
expect(await stat(oldGuide).then(() => true, () => false)).toBe(false);
expect(await stat(join(keptGuide, "SKILL.md")).then(() => true, () => false)).toBe(false);
expect(await readFile(join(keptGuide, "notes.md"), "utf8")).toBe("mine\n");
expect(await readFile(join(userSkill, "SKILL.md"), "utf8")).toBe("---\nname: my-notes\n---\n");
expect(await readFile(join(swarmDir, OMNIRUSH_SWARM_SKILL_NAME, "SKILL.md"), "utf8")).toBe(omnirushSwarmSkillMarkdown());
expect(OMNIRUSH_SWARM_SKILL_NAME).toBe("agent-swarm");
expect(OMNIRUSH_BEST_PRACTICES.skills.map((skill) => skill.name)).toEqual([
"project-build", "project-debug", "project-feature", "project-handoff", "project-performance",
"project-refactor", "project-review", "project-setup", "project-test",
]);
for (const skill of OMNIRUSH_BEST_PRACTICES.skills) {
expect(await readFile(join(bestDir, skill.name, "SKILL.md"), "utf8")).toBe(skill.content);
}
});
test("live apply waits for both native prompt and owned skill readiness, and times out honestly", async () => {
const { root, config } = await setup();
const owned = OMNIRUSH_BEST_PRACTICES.skills.map((skill) => ({ name: skill.name, location: join(omnirushBestPracticesSkillsDir(config), skill.name, "SKILL.md") }));
const user = { name: "project-feature", location: join(root, ".opencode", "skills", "project-feature", "SKILL.md") };
const stale = { agents: [{ name: "omnirush", prompt: `${OMNIRUSH_AGENT_PROMPT}\n\n${OMNIRUSH_BEST_PRACTICES.systemPrompt}` }], skills: [...owned, user] };
const promptReady = { agents: [{ name: "omnirush", prompt: OMNIRUSH_AGENT_PROMPT }], skills: [...owned, user] };
const allReady = { agents: promptReady.agents, skills: [user] };
let probes = 0;
await waitForBestPracticesReady({
config, enabled: false, timeoutMs: 1_000, intervalMs: 1,
read: async () => { probes += 1; return [probes === 1 ? stale : probes === 2 ? promptReady : allReady]; },
});
expect(probes).toBe(3);
await expect(waitForBestPracticesReady({
config, enabled: false, timeoutMs: 20, intervalMs: 1,
read: async () => [promptReady],
})).rejects.toThrow("Best practices engine readiness was not observed");
const overrides = OMNIRUSH_BEST_PRACTICES.skills.map((skill) => ({ name: skill.name, location: join(root, ".opencode", "skills", skill.name, "SKILL.md") }));
await waitForBestPracticesReady({ config, enabled: true, timeoutMs: 1_000, read: async () => [{ agents: stale.agents, skills: overrides }] });
await expect(waitForBestPracticesReady({
config, enabled: false, timeoutMs: 20, intervalMs: 1,
read: async () => [{ agents: allReady.agents, skills: [{ name: user.name, location: "" }] }],
})).rejects.toThrow("Best practices engine readiness was not observed");
});
test("keepOmniRushRuntimeConfigFileFresh rewrites the file on ENGINE_GLOBAL writes", async () => {
const { config } = await setup();
await writeOmniRushRuntimeConfigFile(config);
cleanups.push(keepOmniRushRuntimeConfigFileFresh(config));
await writeGlobalRuntimeOpencodeConfig(config, (current) => ({
...current,
mcp: { stripe: { type: "remote", url: "https://mcp.stripe.com", enabled: false } },
}));
// The refresh is fire-and-forget; poll briefly for the rewrite.
await new Promise((resolve) => setTimeout(resolve, 50));
const parsed = await readConfigFile(config);
expect(parsed.mcp).toBeUndefined();
});
test("workspace runtime writes do not rewrite the file", async () => {
const { config } = await setup();
await writeOmniRushRuntimeConfigFile(config);
cleanups.push(keepOmniRushRuntimeConfigFileFresh(config));
await writeRuntimeOpencodeConfig(config, "ws_1", (current) => ({
...current,
mcp: { other: { type: "remote", url: "https://example.com/mcp", enabled: true } },
}));
await new Promise((resolve) => setTimeout(resolve, 50));
const parsed = await readConfigFile(config);
const mcp = (parsed.mcp ?? {}) as Record<string, Record<string, unknown>>;
expect(mcp.other).toBeUndefined();
});
test("builds byte-stable config for repeated snapshots", async () => {
const { config } = await setup();
await writeGlobalRuntimeOpencodeConfig(config, (current) => ({
...current,
mcp: { posthog: { type: "remote", url: "https://mcp.posthog.com/mcp" } },
}));
const first = await buildOmniRushRuntimeConfig(config);
const second = await buildOmniRushRuntimeConfig(config);
expect(second).toBe(first);
});
test("builds byte-stable config for equivalent snapshots with different key order", async () => {
const { config } = await setup();
await writeGlobalRuntimeOpencodeConfig(config, () => ({
mcp: {
zeta: { url: "https://z.example/mcp", type: "remote" },
alpha: { type: "remote", url: "https://a.example/mcp" },
},
provider: {
zeta: { npm: "@ai-sdk/openai-compatible", name: "Zeta" },
alpha: { name: "Alpha", npm: "@ai-sdk/openai-compatible" },
},
}));
const first = await buildOmniRushRuntimeConfig(config);
await writeGlobalRuntimeOpencodeConfig(config, () => ({
provider: {
alpha: { npm: "@ai-sdk/openai-compatible", name: "Alpha" },
zeta: { name: "Zeta", npm: "@ai-sdk/openai-compatible" },
},
mcp: {
alpha: { url: "https://a.example/mcp", type: "remote" },
zeta: { type: "remote", url: "https://z.example/mcp" },
},
}));
const second = await buildOmniRushRuntimeConfig(config);
expect(second).toBe(first);
});
});
/**
* The omnirush provider as v1.0.9 declared it (the INTERNAL_MODELS and
* internalGatewayModel it hardcoded), with two deliberate changes: variants
* carry the camelCase `reasoningEffort` the engine's OpenAI adapter reads, and
* each model has a default effort (`options.reasoningEffort`, High). Astra
* and Sol must keep these bytes otherwise: they feed the engine-pool
* fingerprint, and any other 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: { reasoningEffort: "low" },
high: { reasoningEffort: "high" },
xhigh: { reasoningEffort: "xhigh" },
max: { reasoningEffort: "max" },
none: { disabled: true },
minimal: { disabled: true },
medium: { disabled: true },
},
options: { reasoningEffort: "high" },
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-6.1-sol": model("GPT 6.1 Sol"), "gpt-6-sol": model("GPT 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 both Sols 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, 3) })!],
["older backend", sanitizeOmniRushModelCatalog({
object: "list",
data: body.data.slice(0, 3).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, 3) })!);
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: { reasoningEffort: "minimal" },
low: { reasoningEffort: "low" },
medium: { reasoningEffort: "medium" },
high: { reasoningEffort: "high" },
xhigh: { reasoningEffort: "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-6-astra", "gpt-6-sol", "gpt-6.1-sol", "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,
options: { reasoningEffort: "high" },
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,
options: { reasoningEffort: "high" },
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();
});
});