A desktop coding agent with free access to frontier models.
TypeScript
fix(desktop): import the legacy keychain account only on the default production profile
ogsamrat44dc2eacb791
diff --git a/apps/desktop/electron/main.mjs b/apps/desktop/electron/main.mjsindex 9f001ea5..39406d71 100644--- a/apps/desktop/electron/main.mjs+++ b/apps/desktop/electron/main.mjs@@ -79,7 +79,7 @@ import {} from "./brand-icon-windows.mjs";import { resetMacDockIcon } from "./brand-icon-darwin.mjs";import { createDesktopVaultKeyProvider } from "./secure-vault-key.mjs";-import { createDesktopOmniRushAccountStore } from "./omnirush-account.mjs";+import { createDesktopOmniRushAccountStore, legacyKeychainAllowed } from "./omnirush-account.mjs";import {clearOmniRushSentrySession,initOmniRushSentry,@@ -1314,6 +1314,11 @@ function validateSkillName(raw) {const omnirushAccountStore = createDesktopOmniRushAccountStore({filePath: path.join(app.getPath("userData"), "omnirush-account.bin"),loadSafeStorage: () => require("electron").safeStorage,+ legacyKeychain: legacyKeychainAllowed({+ appIdentifier: APP_IDENTIFIER,+ productionAppIdentifier: TAURI_APP_IDENTIFIER,+ blankSlate: BLANK_SLATE_LAUNCH.enabled,+ }),});function omnirushUiMcpLaunch() {diff --git a/apps/desktop/electron/omnirush-account.mjs b/apps/desktop/electron/omnirush-account.mjsindex 0ca5b1e8..f6f1c2e8 100644--- a/apps/desktop/electron/omnirush-account.mjs+++ b/apps/desktop/electron/omnirush-account.mjs@@ -187,6 +187,23 @@ async function deleteMacKeychain(service, platform, runSecurity) {return removed;}+/**+ * Whether this launch may read, and on sign-out remove, the legacy macOS+ * keychain entries (KEYCHAIN_SERVICES). They hold the owner's real+ * account, and belong to the default production profile alone: a dev,+ * eval, test or blank-slate profile, a custom OMNIRUSH_ELECTRON_USERDATA or+ * OMNIRUSH_ELECTRON_APP_IDENTIFIER, or the mock keychain must never import+ * them.+ * @param {{ appIdentifier: string, productionAppIdentifier: string, blankSlate: boolean, env?: NodeJS.ProcessEnv }} launch+ */+export function legacyKeychainAllowed({ appIdentifier, productionAppIdentifier, blankSlate, env = process.env }) {+ return appIdentifier === productionAppIdentifier+ && !blankSlate+ && !env.OMNIRUSH_ELECTRON_USERDATA?.trim()+ && !env.OMNIRUSH_ELECTRON_APP_IDENTIFIER?.trim()+ && env.OMNIRUSH_ELECTRON_USE_MOCK_KEYCHAIN !== "1";+}+export function createDesktopOmniRushAccountStore({filePath,loadSafeStorage,@@ -195,6 +212,8 @@ export function createDesktopOmniRushAccountStore({fetchImpl = globalThis.fetch,execFileImpl = /** @type {SecurityCommandRunner} */ (execFileAsync),sleep = (milliseconds) => new Promise((resolvePromise) => setTimeout(resolvePromise, milliseconds)),+ // Only the default production profile may use the legacy keychain entries (legacyKeychainAllowed).+ legacyKeychain = false,}) {let cached = null;// The embedded broker shares this store (persist/latest/invalidate) and@@ -207,7 +226,9 @@ export function createDesktopOmniRushAccountStore({/** Whether the sign-out in flight revokes the session (see save()). */let clearRevokesRemote = false;const signedOutPath = `${filePath}.signed-out`;- const runSecurity = (args) => execFileImpl(SECURITY_TOOL, args, { timeout: 5_000, maxBuffer: 64 * 1024 });+ const runSecurity = (args) => (legacyKeychain+ ? execFileImpl(SECURITY_TOOL, args, { timeout: 5_000, maxBuffer: 64 * 1024 })+ : Promise.reject(new Error("The legacy keychain entries belong to the default production profile")));/*** Resolves once every in-flight refresh, save and sign-out has finished.diff --git a/apps/desktop/electron/omnirush-account.test.mjs b/apps/desktop/electron/omnirush-account.test.mjsindex 7b8a45aa..064f3960 100644--- a/apps/desktop/electron/omnirush-account.test.mjs+++ b/apps/desktop/electron/omnirush-account.test.mjs@@ -9,6 +9,7 @@ import {accountServerLabel,classifyRemoteLogout,createDesktopOmniRushAccountStore,+ legacyKeychainAllowed,} from "./omnirush-account.mjs";function testStorage() {@@ -387,6 +388,7 @@ test("sign out on macOS forgets the keychain gateway URL so the next sign-in useconst logoutRequests = [];const options = await storeOptions({platform: "darwin",+ legacyKeychain: true,execFileImpl: keychain.execFileImpl,env: { OMNIRUSH_DEV_MODE: "1", OMNIRUSH_ACCESS_TOKEN: "legacy-access", OMNIRUSH_REFRESH_TOKEN: "legacy-refresh" },fetchImpl: async (url) => {@@ -421,6 +423,7 @@ test("sign out removes every duplicate keychain gateway URL item", async () => {const calls = [];const options = await storeOptions({platform: "darwin",+ legacyKeychain: true,execFileImpl: async (_file, args) => {calls.push(args);if (args[0] === "find-generic-password") throw new Error("not found");@@ -444,6 +447,7 @@ test("server-driven invalidation keeps the keychain gateway URL", async () => {const keychain = fakeMacKeychain({ [KEYCHAIN_SERVICES.gatewayUrl]: "https://staging.example/omnirush/v1" });const options = await storeOptions({platform: "darwin",+ legacyKeychain: true,execFileImpl: keychain.execFileImpl,env: { OMNIRUSH_DEV_MODE: "1", OMNIRUSH_ACCESS_TOKEN: "expired-access", OMNIRUSH_REFRESH_TOKEN: "expired-refresh" },fetchImpl: async () => Response.json({ detail: "device_token_invalid" }, { status: 401 }),@@ -456,6 +460,52 @@ test("server-driven invalidation keeps the keychain gateway URL", async () => {assert.equal(keychain.items.get(KEYCHAIN_SERVICES.gatewayUrl), "https://staging.example/omnirush/v1");});+test("only the default production profile imports the legacy keychain account", async () => {+ const signedIn = {+ [KEYCHAIN_SERVICES.gatewayUrl]: "https://omnirush.ai/omnirush/v1",+ [KEYCHAIN_SERVICES.accessToken]: "real-access",+ [KEYCHAIN_SERVICES.refreshToken]: "real-refresh",+ };+ const requests = [];+ const fetchImpl = async (url) => {+ requests.push(String(url));+ return new URL(url).pathname.endsWith("/device/logout")+ ? new Response(null, { status: 204 })+ : Response.json({ email: "[email protected]", status: "active" });+ };++ // A custom profile (an eval, a test, a dev or blank-slate one) on the owner's Mac.+ const keychain = fakeMacKeychain(signedIn);+ const isolated = createDesktopOmniRushAccountStore(await storeOptions({ platform: "darwin", env: {}, execFileImpl: keychain.execFileImpl, fetchImpl }));+ const status = await isolated.status();+ assert.equal(status.connected, false);+ assert.equal(status.gatewayUrl, "https://omnirush.ai/omnirush/v1");+ await isolated.clear();+ assert.deepEqual(keychain.calls, []);+ assert.deepEqual(requests, []);+ assert.equal(keychain.items.size, 3);++ // The default production profile still imports it once.+ const production = createDesktopOmniRushAccountStore(await storeOptions({ platform: "darwin", env: {}, legacyKeychain: true, execFileImpl: keychain.execFileImpl, fetchImpl }));+ assert.equal((await production.status()).connected, true);+ assert.deepEqual(requests, ["https://omnirush.ai/omnirush/device/me"]);+});++test("legacyKeychainAllowed admits the default production profile alone", () => {+ const production = { appIdentifier: "ai.omnirush.desktop", productionAppIdentifier: "ai.omnirush.desktop", blankSlate: false };+ assert.equal(legacyKeychainAllowed({ ...production, env: {} }), true);+ assert.equal(legacyKeychainAllowed({ ...production, env: { OMNIRUSH_ELECTRON_USERDATA: " " } }), true);+ const refused = {+ "dev identifier": { ...production, appIdentifier: "ai.omnirush.desktop.dev", env: {} },+ "eval identifier": { ...production, appIdentifier: "ai.omnirush.desktop.eval.search", env: {} },+ "blank slate": { ...production, blankSlate: true, env: {} },+ "userData override": { ...production, env: { OMNIRUSH_ELECTRON_USERDATA: "/tmp/eval/electron-userdata" } },+ "identifier override": { ...production, env: { OMNIRUSH_ELECTRON_APP_IDENTIFIER: "ai.omnirush.desktop" } },+ "mock keychain": { ...production, env: { OMNIRUSH_ELECTRON_USE_MOCK_KEYCHAIN: "1" } },+ };+ for (const [label, launch] of Object.entries(refused)) assert.equal(legacyKeychainAllowed(launch), false, label);+});+test("status names the account server the app is connected to", async () => {const publicStore = createDesktopOmniRushAccountStore(await storeOptions({ env: {} }));assert.deepEqual(await publicStore.status(), {diff --git a/apps/desktop/package.json b/apps/desktop/package.jsonindex 4397df9e..a4bd10b0 100644--- a/apps/desktop/package.json+++ b/apps/desktop/package.json@@ -27,7 +27,7 @@"prepare:sidecar": "node ./scripts/prepare-sidecar.mjs","pretest": "pnpm --filter @omnirush/headless-threads build","test:omnirush-account": "node --test electron/omnirush-account.test.mjs",- "test": "node --test scripts/prepare-server-constants.test.mjs scripts/verify-update-manifest.test.mjs electron/after-pack-paths.test.mjs electron/agent-context-diagnostics-fetch.test.mjs electron/automation-runner.test.mjs electron/binary-transfer.test.mjs electron/blank-slate-profile.test.mjs electron/blank-slate-profile-isolation.test.mjs electron/brand-app-name.test.mjs electron/brand-icon-darwin.test.mjs electron/brand-icon-windows.test.mjs electron/browser-login-sync.test.mjs electron/browser-panel.test.mjs electron/connect-link.test.mjs electron/desktop-distribution.test.mjs electron/dev-profile.test.mjs electron/electron-builder-config.test.mjs electron/linux-desktop-integration.test.mjs electron/no-bare-external-fetch.test.mjs electron/nuke.test.mjs electron/omnirush-ui-mcp.test.mjs electron/open-external.test.mjs electron/process-resilience.test.mjs electron/runtime.test.mjs electron/runtime-ca.test.mjs electron/runtime-chain-repair.test.mjs electron/sentry.test.mjs electron/server-dependency-mirror.test.mjs electron/secure-vault-key.test.mjs electron/stdio-errors.test.mjs electron/ui-control-server.test.mjs electron/updater.test.mjs electron/remote-workspace.test.mjs electron/workspace-archive.test.mjs electron/workspace-store.test.mjs",+ "test": "node --test scripts/prepare-server-constants.test.mjs scripts/verify-update-manifest.test.mjs electron/after-pack-paths.test.mjs electron/agent-context-diagnostics-fetch.test.mjs electron/automation-runner.test.mjs electron/binary-transfer.test.mjs electron/blank-slate-profile.test.mjs electron/blank-slate-profile-isolation.test.mjs electron/brand-app-name.test.mjs electron/brand-icon-darwin.test.mjs electron/brand-icon-windows.test.mjs electron/browser-login-sync.test.mjs electron/browser-panel.test.mjs electron/connect-link.test.mjs electron/desktop-distribution.test.mjs electron/dev-profile.test.mjs electron/electron-builder-config.test.mjs electron/linux-desktop-integration.test.mjs electron/no-bare-external-fetch.test.mjs electron/nuke.test.mjs electron/omnirush-account.test.mjs electron/omnirush-ui-mcp.test.mjs electron/open-external.test.mjs electron/process-resilience.test.mjs electron/runtime.test.mjs electron/runtime-ca.test.mjs electron/runtime-chain-repair.test.mjs electron/sentry.test.mjs electron/server-dependency-mirror.test.mjs electron/secure-vault-key.test.mjs electron/stdio-errors.test.mjs electron/ui-control-server.test.mjs electron/updater.test.mjs electron/remote-workspace.test.mjs electron/workspace-archive.test.mjs electron/workspace-store.test.mjs","test:core": "node --test scripts/prepare-server-constants.test.mjs electron/workspace-store.test.mjs electron/workspace-archive.test.mjs electron/connect-link.test.mjs electron/open-external.test.mjs electron/secure-vault-key.test.mjs electron/process-resilience.test.mjs electron/stdio-errors.test.mjs electron/runtime-ca.test.mjs electron/runtime-chain-repair.test.mjs electron/automation-runner.test.mjs","pretest:core": "pnpm --filter @omnirush/headless-threads build"},diff --git a/evals/packages/hosts/src/local.ts b/evals/packages/hosts/src/local.tsindex 11b936c1..9be9dcfa 100644--- a/evals/packages/hosts/src/local.ts+++ b/evals/packages/hosts/src/local.ts@@ -474,6 +474,9 @@ function hostPnpmHome(): string | null {return null;}+/** Nothing listens on the discard port: every account and gateway call from an eval surface fails at once. */+export const EVAL_DEAD_GATEWAY_URL = "http://127.0.0.1:9/omnirush/v1";+export function electronSurfaceEnv(paths: ElectronProfilePaths,options: ElectronSurfaceEnvOptions,@@ -483,6 +486,12 @@ export function electronSurfaceEnv(// Give local eval Electron surfaces isolated app data, config, and identity so// they cannot affect the user's real desktop app.return {+ // No account: empty tokens and a dead gateway, so a source app on the+ // owner's Mac cannot sign in from the legacy keychain entries or reach+ // omnirush.ai. A spec that needs an account passes its own.+ OMNIRUSH_ACCESS_TOKEN: "",+ OMNIRUSH_REFRESH_TOKEN: "",+ OMNIRUSH_GATEWAY_URL: EVAL_DEAD_GATEWAY_URL,...(pnpmHome ? { PNPM_HOME: pnpmHome } : {}),APPDATA: paths.appDataDir,HOME: paths.homeDir,diff --git a/evals/packages/hosts/test/local-host.test.ts b/evals/packages/hosts/test/local-host.test.tsindex 86af8243..1f8b23c6 100644--- a/evals/packages/hosts/test/local-host.test.ts+++ b/evals/packages/hosts/test/local-host.test.ts@@ -7,13 +7,14 @@ import { join, resolve } from "node:path";import test from "node:test";import { allocateFreePort } from "@omnirush/cdp";-import { electronProfilePaths, electronSurfaceEnv, freePort, pruneStaleSurfaceProfiles, registerLiveProfileRoot, resolveChromeBinary, stopOwnedElectronSurface, unregisterLiveProfileRoot } from "../src/local.ts";+import { EVAL_DEAD_GATEWAY_URL, electronProfilePaths, electronSurfaceEnv, freePort, pruneStaleSurfaceProfiles, registerLiveProfileRoot, resolveChromeBinary, stopOwnedElectronSurface, unregisterLiveProfileRoot } from "../src/local.ts";const ENV_KEYS = ["APPDATA","HOME","LOCALAPPDATA","OPENCODE_CONFIG_DIR",+ "OMNIRUSH_ACCESS_TOKEN","OMNIRUSH_DATA_DIR","OMNIRUSH_DESKTOP_BOOTSTRAP_PATH","OMNIRUSH_DESKTOP_DISABLE_WORKSPACE_RECOVERY",@@ -26,6 +27,8 @@ const ENV_KEYS = ["OMNIRUSH_ELECTRON_USE_MOCK_KEYCHAIN","OMNIRUSH_ELECTRON_USERDATA","OMNIRUSH_ENV_STORE",+ "OMNIRUSH_GATEWAY_URL",+ "OMNIRUSH_REFRESH_TOKEN","PORT","VITE_DISABLE_OMNIRUSH_MODELS","XDG_CACHE_HOME",@@ -95,6 +98,19 @@ test("electronSurfaceEnv matches the isolated Electron demo contract", () => {assert.equal(env.XDG_CONFIG_HOME, paths.configHome);assert.equal(env.XDG_DATA_HOME, paths.dataHome);assert.equal(env.XDG_STATE_HOME, paths.stateHome);+ // Signed out by default: no tokens, and a gateway nothing answers on.+ assert.equal(env.OMNIRUSH_ACCESS_TOKEN, "");+ assert.equal(env.OMNIRUSH_REFRESH_TOKEN, "");+ assert.equal(env.OMNIRUSH_GATEWAY_URL, EVAL_DEAD_GATEWAY_URL);+ assert.equal(new URL(env.OMNIRUSH_GATEWAY_URL).host, "127.0.0.1:9");+ // A spec that needs an account passes its own.+ const withAccount = electronSurfaceEnv(paths, { appName: "OmniRush.ai Eval probe", appIdentifier: "ai.omnirush.desktop.eval.probe", port: 5123, cdpPort: 9123 }, {+ OMNIRUSH_GATEWAY_URL: "http://127.0.0.1:8090/omnirush/v1",+ OMNIRUSH_ACCESS_TOKEN: "spec-access",+ OMNIRUSH_REFRESH_TOKEN: "spec-refresh",+ });+ assert.equal(withAccount.OMNIRUSH_GATEWAY_URL, "http://127.0.0.1:8090/omnirush/v1");+ assert.equal(withAccount.OMNIRUSH_ACCESS_TOKEN, "spec-access");});test("electronSurfaceEnv maps the v2 eval lane before caller overrides", () => {