A desktop coding agent with free access to frontier models.
TypeScript
fix: macOS accepts the team-signed bundled engine; release gate starts the signed app
ogsamratd85798448817
diff --git a/.github/workflows/build-electron-desktop.yml b/.github/workflows/build-electron-desktop.ymlindex c39542d2..fa53530a 100644--- a/.github/workflows/build-electron-desktop.yml+++ b/.github/workflows/build-electron-desktop.yml@@ -84,6 +84,21 @@ jobs:OMNIRUSH_DESKTOP_SENTRY_TRACES_SAMPLE_RATE: ${{ vars.OMNIRUSH_DESKTOP_SENTRY_TRACES_SAMPLE_RATE || '0.01' }}run: pnpm --filter @omnirush/desktop package:electron:dir+ # The packaged app must accept its own bundled engine (the app's own checks, its own runtime).+ - name: Verify the packaged app accepts its bundled engine+ shell: bash+ run: |+ set -euo pipefail+ d=apps/desktop/dist-electron+ app=$(find "$d" -maxdepth 2 -name '*.app' -type d | head -n 1)+ if [ -n "$app" ]; then+ exe="$app/Contents/MacOS/$(/usr/libexec/PlistBuddy -c 'Print CFBundleExecutable' "$app/Contents/Info.plist")"; res="$app/Contents/Resources"+ else+ u=$(find "$d" -maxdepth 1 -type d -name '*-unpacked' | head -n 1)+ exe=$(find "$u" -maxdepth 1 -type f \( -name 'omnirush' -o -name '*.exe' \) ! -iname 'uninstall*' | head -n 1); res="$u/resources"+ fi+ ELECTRON_RUN_AS_NODE=1 "$exe" apps/desktop/scripts/check-packaged-engine.mjs "$res"+- name: Upload Electron artifactsuses: actions/upload-artifact@v4with:@@ -346,6 +361,16 @@ jobs:echo "bundled engine: $version"test "$version" = "$(node -p "require('./apps/desktop/scripts/engine-release.json').version")"+ # The notarized app must accept and start its own bundled engine (signing rewrites the engine+ # after packaging records its sha256): the app's own checks with its own runtime, then a real start.+ - name: Verify the notarized app accepts and starts its bundled engine+ run: |+ set -euo pipefail+ app=$(find apps/desktop/dist-electron -maxdepth 2 -name '*.app' -type d | head -n 1)+ exe="$app/Contents/MacOS/$(/usr/libexec/PlistBuddy -c 'Print CFBundleExecutable' "$app/Contents/Info.plist")"+ ELECTRON_RUN_AS_NODE=1 "$exe" apps/desktop/scripts/check-packaged-engine.mjs "$app/Contents/Resources"+ bash apps/desktop/scripts/launch-check.sh "$exe" 180+- name: Check installer window, app name and in-place updaterun: scripts/release/check-macos-installer.sh apps/desktop/dist-electron "$RUNNER_TEMP/installer-check"diff --git a/.github/workflows/release-desktop.yml b/.github/workflows/release-desktop.ymlindex 77230b8d..579d5e1e 100644--- a/.github/workflows/release-desktop.yml+++ b/.github/workflows/release-desktop.yml@@ -262,6 +262,36 @@ jobs:shell: bashrun: scripts/release/verify-macos-signing.sh apps/desktop/dist-electron+ # The final, signed app must accept and start its own bundled engine: macOS signing and+ # notarization rewrite the engine after packaging records its sha256 (3.6.7/3.6.9 shipped+ # Mac builds that refused to start). Runs the app's own checks with its own runtime, then+ # starts the app (macOS, Linux) and waits for its engine.+ - name: Verify the packaged app accepts and starts its bundled engine+ shell: bash+ run: |+ set -euo pipefail+ d=apps/desktop/dist-electron+ case "${{ matrix.platform }}" in+ macos)+ app=$(find "$d" -maxdepth 2 -name '*.app' -type d | head -n 1)+ exe="$app/Contents/MacOS/$(/usr/libexec/PlistBuddy -c 'Print CFBundleExecutable' "$app/Contents/Info.plist")"+ res="$app/Contents/Resources" ;;+ windows)+ u=$(find "$d" -maxdepth 1 -type d -name 'win*-unpacked' | head -n 1)+ exe=$(find "$u" -maxdepth 1 -name '*.exe' ! -iname 'uninstall*' | head -n 1)+ res="$u/resources" ;;+ linux)+ u=$(find "$d" -maxdepth 1 -type d -name 'linux*-unpacked' | head -n 1)+ exe="$u/omnirush"+ res="$u/resources" ;;+ esac+ ELECTRON_RUN_AS_NODE=1 "$exe" apps/desktop/scripts/check-packaged-engine.mjs "$res"+ if [ "${{ matrix.platform }}" = macos ]; then bash apps/desktop/scripts/launch-check.sh "$exe" 180; fi+ if [ "${{ matrix.platform }}" = linux ]; then+ command -v xvfb-run > /dev/null || { sudo apt-get update -qq && sudo apt-get install -y -qq xvfb; }+ xvfb-run -a -s "-screen 0 1280x800x24" bash apps/desktop/scripts/launch-check.sh "$exe" 180+ fi+- name: Verify packaged server importsshell: bashrun: node apps/desktop/scripts/verify-packaged-imports.mjsdiff --git a/apps/desktop/electron/build-variant.mjs b/apps/desktop/electron/build-variant.mjsindex 81ca191d..2b6b30fe 100644--- a/apps/desktop/electron/build-variant.mjs+++ b/apps/desktop/electron/build-variant.mjs@@ -11,6 +11,7 @@// - talks to https://omnirush.ai or https://<name>.omnirush.ai only, from// every source of an address; another address is an error, not a fallback;// - runs only the engine binary it bundles, checked by its sha256.+import { spawnSync } from "node:child_process";import { createHash } from "node:crypto";import { existsSync, readFileSync } from "node:fs";import path from "node:path";@@ -63,16 +64,37 @@ function sha256File(file) {return createHash("sha256").update(readFileSync(file)).digest("hex");}+/** The Apple Developer ID team that signs the app and its bundled engine. */+export const ENGINE_SIGNING_TEAM = "2KFG4BXC8K";+/** codesign requirement: a Developer ID certificate (Apple anchor) of that team. */+export const ENGINE_SIGNING_REQUIREMENT = `anchor apple generic and certificate leaf[subject.OU] = "${ENGINE_SIGNING_TEAM}"`;++/**+ * macOS: whether `file` carries a valid signature by this app's team. Signing and+ * notarization rewrite the engine binary after packaging records its sha256, so on+ * macOS the signature, not the raw hash, says it is the bundled engine.+ */+export function engineSignedByTeam(file, { platform = process.platform, run = spawnSync } = {}) {+ if (platform !== "darwin") return false;+ try {+ const result = run("/usr/bin/codesign", ["--verify", "--strict", `-R=${ENGINE_SIGNING_REQUIREMENT}`, file], { stdio: "ignore", timeout: 20_000 });+ return result?.status === 0;+ } catch {+ return false;+ }+}+/*** The engine binary a release build runs: the bundled one in <resources>/sidecars,* when its sha256 is the one recorded at packaging. Throws otherwise.* @param {{ fileNames: string[], build?: DesktopBuild, resourcesPath?: string, exists?: (file: string) => boolean, hash?: (file: string) => string }} input* @returns {{ path: string, source: "bundled" }}*/-export function releaseEngineBinary({ build = desktopBuild, resourcesPath = process.resourcesPath, fileNames, exists = existsSync, hash = sha256File }) {+export function releaseEngineBinary({ build = desktopBuild, resourcesPath = process.resourcesPath, fileNames, exists = existsSync, hash = sha256File, signedByTeam = engineSignedByTeam }) {const directory = resourcesPath ? path.join(resourcesPath, "sidecars") : null;const candidate = directory ? fileNames.map((name) => path.join(directory, name)).find((file) => exists(file)) : null;if (!candidate || !build.engineSha256) throw new Error(`${RELEASE_ENGINE_ERROR} No bundled engine was found. Reinstall OmniRush.ai.`);- if (!build.engineSha256.split(",").includes(hash(candidate))) throw new Error(`${RELEASE_ENGINE_ERROR} The bundled engine was changed. Reinstall OmniRush.ai.`);+ // The recorded sha256 (Linux, Windows), or on macOS this team's valid signature (signing changes the bytes).+ if (!build.engineSha256.split(",").includes(hash(candidate)) && !signedByTeam(candidate)) throw new Error(`${RELEASE_ENGINE_ERROR} The bundled engine was changed. Reinstall OmniRush.ai.`);return { path: candidate, source: "bundled" };}diff --git a/apps/desktop/electron/build-variant.test.mjs b/apps/desktop/electron/build-variant.test.mjsindex 65854f9d..7fa1cea3 100644--- a/apps/desktop/electron/build-variant.test.mjs+++ b/apps/desktop/electron/build-variant.test.mjs@@ -5,7 +5,7 @@ import path from "node:path";import test from "node:test";import { createHash } from "node:crypto";-import { gatewayUrlAllowedForBuild, readDesktopBuild, releaseEngineBinary } from "./build-variant.mjs";+import { ENGINE_SIGNING_REQUIREMENT, engineSignedByTeam, gatewayUrlAllowedForBuild, readDesktopBuild, releaseEngineBinary } from "./build-variant.mjs";import { createDesktopOmniRushAccountStore } from "./omnirush-account.mjs";import { desktopVariant, stampBuildVariant } from "../scripts/stamp-build-variant.mjs";@@ -106,3 +106,26 @@ test("packaging stamps release with the engine hash, or dev when asked at buildawait mkdir(sidecarDir);assert.throws(() => stampBuildVariant({ env: {}, sidecarDir, serverDistDir, buildFilePath }), /one engine per architecture/);});++test("macOS: signing changes the engine after its sha256 is recorded; this team's valid signature counts instead", async () => {+ const directory = await mkdtemp(path.join(os.tmpdir(), "omnirush-build-engine-mac-"));+ await mkdir(path.join(directory, "sidecars"));+ await writeFile(path.join(directory, "sidecars", "opencode-aarch64-apple-darwin"), "signed engine");+ /** @type {DesktopBuild} */+ const build = { variant: "release", engineSha256: "f".repeat(64), packaged: true };+ const args = { build, resourcesPath: directory, fileNames: ["opencode-aarch64-apple-darwin"] };+ assert.equal(releaseEngineBinary({ ...args, signedByTeam: () => true }).source, "bundled");+ assert.throws(() => releaseEngineBinary({ ...args, signedByTeam: () => false }), /was changed/);+ // The signature check asks codesign for this team's Developer ID, and only on macOS.+ const calls = [];+ const run = (cmd, argv) => { calls.push([cmd, ...argv]); return { status: 0 }; };+ assert.equal(engineSignedByTeam("/x/opencode", { platform: "darwin", run }), true);+ assert.deepEqual(calls[0], ["/usr/bin/codesign", "--verify", "--strict", `-R=${ENGINE_SIGNING_REQUIREMENT}`, "/x/opencode"]);+ assert.match(ENGINE_SIGNING_REQUIREMENT, /anchor apple generic and certificate leaf\[subject\.OU\] = "2KFG4BXC8K"/);+ assert.equal(engineSignedByTeam("/x/opencode", { platform: "darwin", run: () => ({ status: 1 }) }), false);+ assert.equal(engineSignedByTeam("/x/opencode", { platform: "linux", run }), false);+ assert.equal(engineSignedByTeam("/x/opencode", { platform: "win32", run }), false);+ assert.equal(calls.length, 1, "codesign is never run off macOS");+ // Off macOS a changed engine is still refused (the default check is false there).+ if (process.platform !== "darwin") assert.throws(() => releaseEngineBinary(args), /was changed/);+});diff --git a/apps/desktop/scripts/check-packaged-engine.mjs b/apps/desktop/scripts/check-packaged-engine.mjsnew file mode 100644index 00000000..b800289c--- /dev/null+++ b/apps/desktop/scripts/check-packaged-engine.mjs@@ -0,0 +1,37 @@+// check-packaged-engine.mjs <resources-dir>: run with the PACKAGED app's own runtime+// (ELECTRON_RUN_AS_NODE=1 <app executable> check-packaged-engine.mjs <resources>), after packaging and+// signing, on the final artifact. It runs the app's own engine checks against the app's own files:+// Electron main's (electron/build-variant.mjs, the one that shows "The bundled engine was changed")+// and the local server's (server/dist/release-guard.js). Both must accept every bundled engine, so a+// build whose stamp no longer matches its (signed) engine cannot ship. Exit 1 on any failure.+import { readdirSync } from "node:fs";+import path from "node:path";+import { pathToFileURL } from "node:url";++const resources = path.resolve(process.argv[2] || process.resourcesPath || "");+const asar = path.join(resources, "app.asar");+const fail = (message) => { console.error(`check-packaged-engine: ${message}`); process.exit(1); };++const variant = await import(pathToFileURL(path.join(asar, "electron", "build-variant.mjs")).href);+const build = variant.readDesktopBuild({ resourcesPath: resources });+if (build.variant !== "release") fail(`expected a release build, found "${build.variant}"`);+if (!build.engineSha256) fail("the build records no engine sha256");++const sidecars = path.join(resources, "sidecars");+const engines = readdirSync(sidecars).filter((name) => /^opencode(?:-[a-z0-9_-]+)?(?:\.exe)?$/.test(name) && !/^opencode-v\d|^opencode2/.test(name));+if (!engines.length) fail(`no bundled engine in ${sidecars}`);++const guard = await import(pathToFileURL(path.join(asar, "server", "dist", "release-guard.js")).href);+for (const name of engines) {+ try {+ variant.releaseEngineBinary({ build, resourcesPath: resources, fileNames: [name] });+ } catch (error) {+ fail(`Electron main refuses ${name}: ${error instanceof Error ? error.message : String(error)}`);+ }+ try {+ await guard.releaseEngineBinary(path.join(sidecars, name), { release: true, engineSha256: build.engineSha256 });+ } catch (error) {+ fail(`the local server refuses ${name}: ${error instanceof Error ? error.message : String(error)}`);+ }+ console.log(`check-packaged-engine: ${name} accepted by Electron main and the local server`);+}diff --git a/apps/desktop/scripts/launch-check.sh b/apps/desktop/scripts/launch-check.shnew file mode 100755index 00000000..9842a2b7--- /dev/null+++ b/apps/desktop/scripts/launch-check.sh@@ -0,0 +1,43 @@+#!/usr/bin/env bash+# launch-check.sh <app executable> [seconds]: start the PACKAGED app (signed out, a throwaway profile)+# and wait until its bundled engine is running. Fails when the app reports that it cannot start the+# engine (for example "The bundled engine was changed"), or when no engine runs within the time.+# macOS: the executable inside the .app (Contents/MacOS/<name>); Linux: run under a display (xvfb-run).+set -uo pipefail+exe=${1:?app executable}; limit=${2:-120}+work=$(mktemp -d); log="$work/app.log"+dir=$(cd "$(dirname "$exe")" && pwd)+# This app's own sidecars: <app>/Contents/Resources (macOS) or <dir>/resources (Linux, Windows).+if [ -d "$dir/../Resources/sidecars" ]; then sidecars=$(cd "$dir/../Resources/sidecars" && pwd); else sidecars="$dir/resources/sidecars"; fi+cleanup() {+ [ -n "${app_pid:-}" ] && kill "$app_pid" 2>/dev/null+ sleep 2+ pkill -f "$sidecars/opencode" 2>/dev/null+ rm -rf "$work"+}+trap cleanup EXIT+# Linux CI and test boxes have no setuid sandbox helper.+extra=(); [ "$(uname -s)" = Linux ] && extra=(--no-sandbox)+OMNIRUSH_ELECTRON_USERDATA="$work/profile" OMNIRUSH_DATA_DIR="$work/data" OMNIRUSH_AUTO_UPDATE=0 \+ OMNIRUSH_POSTHOG_HOST=http://127.0.0.1:9 "$exe" "${extra[@]}" > "$log" 2>&1 &+app_pid=$!+for _ in $(seq "$limit"); do+ if grep -qE "engineStart failed|only runs the engine it ships with|bundled engine was changed" "$log"; then+ echo "launch-check: the app cannot start its engine:" >&2+ grep -m3 -E "engineStart failed|only runs the engine it ships with|bundled engine was changed" "$log" >&2+ exit 1+ fi+ if pgrep -f "$sidecars/opencode" > /dev/null; then+ echo "launch-check: the app started and its bundled engine is running"+ exit 0+ fi+ if ! kill -0 "$app_pid" 2>/dev/null; then+ echo "launch-check: the app exited before its engine started" >&2+ tail -20 "$log" >&2+ exit 1+ fi+ sleep 1+done+echo "launch-check: no engine running after ${limit}s" >&2+tail -20 "$log" >&2+exit 1diff --git a/apps/server/src/release-guard.test.ts b/apps/server/src/release-guard.test.tsindex ec7bdd3d..3acafde7 100644--- a/apps/server/src/release-guard.test.ts+++ b/apps/server/src/release-guard.test.ts@@ -5,7 +5,7 @@ import { tmpdir } from "node:os";import { join } from "node:path";import { BUILD_VARIANT, RELEASE_ENGINE_SHA256 } from "./build-variant.js";-import { allowedGatewayUrlFromEnv, assertGatewayUrlAllowed, gatewayUrlAllowed, releaseEngineBinary } from "./release-guard.js";+import { allowedGatewayUrlFromEnv, assertGatewayUrlAllowed, engineSignedByTeam, gatewayUrlAllowed, releaseEngineBinary } from "./release-guard.js";const DEV = { release: false, engineSha256: null };const roots: string[] = [];@@ -50,6 +50,11 @@ describe("release build guard", () => {const other = join(root, "other");await writeFile(other, "#!/bin/sh\necho other\n");await expect(releaseEngineBinary(other, release)).rejects.toThrow("is not the bundled one");+ // macOS: signing rewrites the engine after its sha256 is recorded; this team's signature counts instead.+ expect(await releaseEngineBinary(other, release, async () => true)).toBe(other);+ await expect(releaseEngineBinary(other, release, async () => false)).rejects.toThrow("is not the bundled one");+ expect(await engineSignedByTeam(other, "linux")).toBe(false);+ expect(await engineSignedByTeam(other, "win32")).toBe(false);// One hash per bundled architecture (macOS arm64 + x64), comma-separated.expect(await releaseEngineBinary(bin, { release: true, engineSha256: ["f".repeat(64), sha].join(",") })).toBe(bin);await expect(releaseEngineBinary(other, { release: true, engineSha256: ["f".repeat(64), sha].join(",") })).rejects.toThrow("is not the bundled one");diff --git a/apps/server/src/release-guard.ts b/apps/server/src/release-guard.tsindex e930590a..68735824 100644--- a/apps/server/src/release-guard.ts+++ b/apps/server/src/release-guard.ts@@ -8,6 +8,7 @@* stamped into the build).* The dev variant takes any address and engine, as before.*/+import { execFile } from "node:child_process";import { createHash } from "node:crypto";import { createReadStream } from "node:fs";import { isAbsolute } from "node:path";@@ -78,13 +79,33 @@ async function fileSha256(path: string): Promise<string> {return hash.digest("hex");}+/** The Apple Developer ID team that signs the app and its bundled engine (electron/build-variant.mjs). */+export const ENGINE_SIGNING_TEAM = "2KFG4BXC8K";+export const ENGINE_SIGNING_REQUIREMENT = `anchor apple generic and certificate leaf[subject.OU] = "${ENGINE_SIGNING_TEAM}"`;++/**+ * macOS: whether `file` carries a valid signature by this app's team. Signing and+ * notarization rewrite the engine after packaging records its sha256, so on macOS+ * the signature, not the raw hash, says it is the bundled engine.+ */+export function engineSignedByTeam(file: string, platform: NodeJS.Platform = process.platform): Promise<boolean> {+ if (platform !== "darwin") return Promise.resolve(false);+ return new Promise((resolve) => {+ try {+ execFile("/usr/bin/codesign", ["--verify", "--strict", `-R=${ENGINE_SIGNING_REQUIREMENT}`, file], { timeout: 20_000 }, (error) => resolve(!error));+ } catch {+ resolve(false);+ }+ });+}+/*** The engine binary to run. In a release build: `bin` must be an absolute* path to a file whose sha256 is the one stamped into the build (the bundled* engine); anything else, no path, or no stamped hash throws. In the dev* variant, `bin` as given.*/-export async function releaseEngineBinary(bin: string | undefined | null, facts: BuildFacts = buildFacts()): Promise<string | undefined> {+export async function releaseEngineBinary(bin: string | undefined | null, facts: BuildFacts = buildFacts(), signedByTeam: (file: string) => Promise<boolean> = engineSignedByTeam): Promise<string | undefined> {if (!facts.release) return bin ?? undefined;const path = bin?.trim() ?? "";if (!facts.engineSha256 || !path || !isAbsolute(path)) throw new Error(`${RELEASE_ENGINE_ERROR} No bundled engine was found.`);@@ -95,6 +116,7 @@ export async function releaseEngineBinary(bin: string | undefined | null, facts:throw new Error(`${RELEASE_ENGINE_ERROR} The bundled engine could not be read.`);}// One hash per bundled architecture, comma-separated (apps/desktop/scripts/stamp-build-variant.mjs).- if (!facts.engineSha256.split(",").includes(actual)) throw new Error(`${RELEASE_ENGINE_ERROR} The engine at ${path} is not the bundled one. Reinstall OmniRush.ai.`);+ // The recorded sha256 (Linux, Windows), or on macOS this team's valid signature (signing changes the bytes).+ if (!facts.engineSha256.split(",").includes(actual) && !(await signedByTeam(path))) throw new Error(`${RELEASE_ENGINE_ERROR} The engine at ${path} is not the bundled one. Reinstall OmniRush.ai.`);return path;}