A desktop coding agent with free access to frontier models.
TypeScript
fix: the sandbox finds its helpers beside the new engine
ogsamratd191619d113c
diff --git a/apps/server/src/box/box-tools-root.test.ts b/apps/server/src/box/box-tools-root.test.tsnew file mode 100644index 00000000..1c5b4941--- /dev/null+++ b/apps/server/src/box/box-tools-root.test.ts@@ -0,0 +1,45 @@+import { afterEach, expect, test } from "bun:test";+import { mkdirSync, mkdtempSync, readlinkSync, rmSync, writeFileSync } from "node:fs";+import { tmpdir } from "node:os";+import path from "node:path";++import { engineToolsRoot, helperPath, installShell, setToolsRoot } from "./box.js";++const dirs: string[] = [];+afterEach(() => {+ setToolsRoot(null);+ for (const dir of dirs.splice(0)) rmSync(dir, { recursive: true, force: true });+});++/** An app's sidecars folder with only the 2.x engine and the box helpers of each OS (the 3.7.6 layout). */+function sidecars(): string {+ const dir = mkdtempSync(path.join(tmpdir(), "box-sidecars-"));+ dirs.push(dir);+ writeFileSync(path.join(dir, "opencode2-x86_64-unknown-linux-gnu"), "");+ for (const [osArch, name] of [["linux-amd64", "boxsh"], ["darwin-arm64", "boxsh"], ["windows-amd64", "boxsh.exe"]]) {+ mkdirSync(path.join(dir, "box", osArch!), { recursive: true });+ writeFileSync(path.join(dir, "box", osArch!, name!), "");+ }+ return dir;+}++test("an app without the 1.x engine finds the box helpers beside the 2.x engine", () => {+ const dir = sidecars();+ const env = { OMNIRUSH_OPENCODE2_BIN: path.join(dir, "opencode2-x86_64-unknown-linux-gnu") };+ expect(engineToolsRoot(undefined, env)).toBe(dir);+ setToolsRoot(engineToolsRoot(undefined, env));+ expect(helperPath("boxsh", { goos: "linux", goarch: "amd64", env: {} })).toBe(path.join(dir, "box", "linux-amd64", "boxsh"));+ // The same folder on macOS and Windows (the desktop sets OMNIRUSH_OPENCODE2_BIN to sidecars/opencode2-<triple> on every OS).+ expect(helperPath("boxsh", { goos: "darwin", goarch: "arm64", env: {} })).toBe(path.join(dir, "box", "darwin-arm64", "boxsh"));+ expect(helperPath("boxsh", { goos: "windows", goarch: "amd64", env: {} })).toBe(path.join(dir, "box", "windows-amd64", "boxsh.exe"));+ const home = mkdtempSync(path.join(tmpdir(), "box-home-"));+ dirs.push(home);+ const shell = installShell(home, { platform: "linux", arch: "x64", env: {} });+ expect(readlinkSync(shell)).toBe(path.join(dir, "box", "linux-amd64", "boxsh"));+});++test("the 1.x engine's folder still wins when it ships, and nothing is guessed without an engine", () => {+ expect(engineToolsRoot("/app/sidecars/opencode", { OMNIRUSH_OPENCODE2_BIN: "/other/opencode2" })).toBe("/app/sidecars");+ expect(engineToolsRoot(null, { OMNIRUSH_OPENCODE_BIN: " /a/opencode ", OMNIRUSH_OPENCODE2_BIN: "/b/opencode2" })).toBe("/a");+ expect(engineToolsRoot(null, {})).toBeNull();+});diff --git a/apps/server/src/box/box.ts b/apps/server/src/box/box.tsindex 7b99171c..a3d9184e 100644--- a/apps/server/src/box/box.ts+++ b/apps/server/src/box/box.ts@@ -43,7 +43,7 @@ import { REQUIRED_RULES, shadowRecord, shadowsNotice, type ShadowBind, type Shadtype Env = NodeJS.ProcessEnv;-export { BOX_PORT, DEPS_MAX_BYTES, FILE_MAX_BYTES, GOARCH, GOOS, HOME_IN_BOX, LABEL, RECORD_SCHEMA, RUN_DIR, SHIMS_DIR, TAR_MAX_BYTES, boxHome, boxKey, canonicalRoot, containerName, containerRoot, helperDirs, helperPath, installShell, readRecord, recordFile, runDir, setToolsRoot, wslPath, type BoxInstallLog, type BoxLog, type BoxRecord, type BoxRuntime } from "./common.js";+export { BOX_PORT, DEPS_MAX_BYTES, FILE_MAX_BYTES, GOARCH, GOOS, HOME_IN_BOX, LABEL, RECORD_SCHEMA, RUN_DIR, SHIMS_DIR, TAR_MAX_BYTES, boxHome, boxKey, canonicalRoot, containerName, containerRoot, engineToolsRoot, helperDirs, helperPath, installShell, readRecord, recordFile, runDir, setToolsRoot, wslPath, type BoxInstallLog, type BoxLog, type BoxRecord, type BoxRuntime } from "./common.js";export { commandUser, createArgs, inspectImage, parseSize, pullImage, resourceArgs, rt, singleFileTar } from "./backends/container.js";export type { ListedBox } from "./backends/types.js";diff --git a/apps/server/src/box/common.ts b/apps/server/src/box/common.tsindex c125d17b..c05a9b00 100644--- a/apps/server/src/box/common.ts+++ b/apps/server/src/box/common.ts@@ -125,6 +125,16 @@ export function setToolsRoot(dir: string | null | undefined): void {platformTools = dir || null;}+/**+ * The sidecars folder the helpers ship in: the folder of the 1.x engine when+ * one still ships, else of the 2.x engine (OMNIRUSH_OPENCODE2_BIN, set by the+ * desktop on every OS). Null when neither is known.+ */+export function engineToolsRoot(opencodeBin: string | null | undefined, env: Env = process.env): string | null {+ const bin = [opencodeBin, env.OMNIRUSH_OPENCODE_BIN, env.OMNIRUSH_OPENCODE2_BIN].map((value) => String(value ?? "").trim()).find(Boolean);+ return bin ? path.dirname(bin) : null;+}+/** The sidecars folder set at start (null: none; tests, a dev server). */export function toolsRoot(): string | null {return platformTools;diff --git a/apps/server/src/cli.ts b/apps/server/src/cli.tsindex d6443be7..bd851d96 100644--- a/apps/server/src/cli.ts+++ b/apps/server/src/cli.ts@@ -3,8 +3,7 @@import { randomUUID } from "node:crypto";import { managedDesktopPolicy } from "./managed-desktop-policy.js";import { mkdir } from "node:fs/promises";-import { dirname } from "node:path";-import { setToolsRoot } from "./box/box.js";+import { engineToolsRoot, setToolsRoot } from "./box/box.js";import { parseCliArgs, printHelp, resolveServerConfig } from "./config.js";import {@@ -71,7 +70,7 @@ if (!config.readOnly) {// (OMNIRUSH_SERVER_URL) must point at the port that actually bound, not the// requested one.// The Linux sandbox's helpers ship beside the engine (sidecars/box/): known before the server plans any box.-if (process.env.OMNIRUSH_OPENCODE_BIN?.trim()) setToolsRoot(dirname(process.env.OMNIRUSH_OPENCODE_BIN.trim()));+setToolsRoot(engineToolsRoot(null));const server = await startServer(config);config.port = server.port;const serverUrl = `http://${config.host === "0.0.0.0" ? "127.0.0.1" : config.host}:${server.port}`;diff --git a/apps/server/src/embedded.ts b/apps/server/src/embedded.tsindex 96a6843f..7ea82b8d 100644--- a/apps/server/src/embedded.ts+++ b/apps/server/src/embedded.ts@@ -11,8 +11,7 @@ import { randomUUID } from "node:crypto";import { stopTaskRecovery } from "./task-recovery.js";import { managedDesktopPolicy } from "./managed-desktop-policy.js";import { mkdir } from "node:fs/promises";-import { dirname } from "node:path";-import { setToolsRoot } from "./box/box.js";+import { engineToolsRoot, setToolsRoot } from "./box/box.js";import { setWriteCheckEngine } from "./folder-write-check.js";import { resolveServerConfig, type CliArgs } from "./config.js";import {@@ -236,7 +235,8 @@ export async function startEmbeddedServer(options: EmbeddedServerOptions): Promi// desktop only learns the server URL after this function returns.// The Linux sandbox's helpers ship beside the engine (sidecars/box/): known before the server plans any box.const engineBin = options.opencodeBin || process.env.OMNIRUSH_OPENCODE_BIN;- if (engineBin?.trim()) setToolsRoot(dirname(engineBin.trim()));+ // The 2.x engine ships in the same sidecars folder: an app without the 1.x engine finds the helpers there.+ setToolsRoot(engineToolsRoot(options.opencodeBin));setWriteCheckEngine(engineBin);server = await duringStartup(() => startServer(config));config.port = server.port;