A desktop coding agent with free access to frontier models.
TypeScript
Merge #173: keep the server's sandbox backends allowlist
ogsamrat9ef710092d33
diff --cc apps/server/src/box/box.test.tsindex d15bbfd0,3aba9ea2..47e63ef4--- a/apps/server/src/box/box.test.ts+++ b/apps/server/src/box/box.test.ts@@@ -310,102 -262,27 +310,123 @@@ describe("box service", () =>expect(await none.engineBits()).toBeNull();});+ test("Try again with no runtime: a fresh look, still unavailable, with the OS for the card's next step", async () => {+ const stateDir = await temp("state");+ const root = await temp("project");+ const workspace: BoxWorkspace = { id: "ws_t", path: root, workspaceType: "local" };+ const settings: Settings = new Map([["ws_t", { mode: "on", offered: true }]]);+ const boxes = service({ stateDir, workspaces: [workspace], settings, env: { OMNIRUSH_BOX_HOME: await temp("boxhome"), OMNIRUSH_BOX_BIN_DIR: await helpers(), PATH: "", OMNIRUSH_BOX_RUNTIME: "/nonexistent/docker" } });+ const status = await boxes.retry(workspace);+ expect(status).toMatchObject({ on: true, state: "unavailable", platform: process.platform, progress: null });+ expect(settings.get("ws_t")).toEqual({ mode: "on", offered: true });+ });++ test("a chat that ran natively names its turn in each checkpoint (session_turn)", async () => {+ const stateDir = await temp("state");+ const root = await temp("project");+ const workspace: BoxWorkspace = { id: "ws_t", path: root, workspaceType: "local" };+ const env = { OMNIRUSH_BOX_HOME: await temp("boxhome") };+ const frozen: Array<string> = [];+ const run: BoxRun = {+ key: "k", container: "c", runtimeBin: "docker", runtimeArgs: [], backend: "docker", exec: null, root, native: false, box: null,+ ready: async () => null,+ label: () => null,+ setTurn: () => {},+ freeze: async (label, { sessionId, turn = null, sessionTurn = null }) => {+ frozen.push(`${sessionId} ${label} ${sessionTurn}`);+ return { label, turn, copied: 0, carried: 0, save: async () => ({ label, changed: 0, bytes: 0 }), discard: async () => null };+ },+ };+ let on = false;+ const start = () => {+ const boxes = service({ stateDir, workspaces: [workspace], settings: new Map(), env });+ boxes.ensure = async () => (on ? run : null);+ return boxes;+ };+ // Two turns with the box off, a steer (not captured), then the box turned on mid-chat: turn-1 comes before turn 3.+ let boxes = start();+ await boxes.beforePrompt("ses_turns_a1", workspace);+ await boxes.beforePrompt("ses_turns_a1", workspace);+ await boxes.beforePrompt("ses_turns_a1", workspace, { capture: false });+ on = true;+ await boxes.beforePrompt("ses_turns_a1", workspace);+ await boxes.beforePrompt("ses_turns_a1", workspace);+ expect(frozen.splice(0)).toEqual(["ses_turns_a1 turn-1 3", "ses_turns_a1 turn-2 4"]);+ // Reopened after a restart with 4 native turns: before turns 5 and 6.+ boxes = start();+ await boxes.beforePrompt("ses_turns_b1", workspace, { turnsBefore: 4 });+ await boxes.beforePrompt("ses_turns_b1", workspace);+ expect(frozen.splice(0)).toEqual(["ses_turns_b1 turn-1 5", "ses_turns_b1 turn-2 6"]);+ // Saved checkpoints go on numbering the files; the chat's turn comes from the engine's count.+ await mkdir(join(stateDir, "sandbox", "snapshots", "ses_turns_c1"), { recursive: true });+ await writeFile(join(boxes.snapshotsDir, "ses_turns_c1", "turn-7.json"), "{}");+ await boxes.beforePrompt("ses_turns_c1", workspace, { turnsBefore: 2 });+ expect(frozen.splice(0)).toEqual(["ses_turns_c1 turn-8 3"]);+ });++ test("a reopened chat that ran on this machine stays there when only the server's default turned the box on", async () => {+ const stateDir = await temp("state");+ const home = await temp("boxhome");+ const root = await temp("project");+ const workspace: BoxWorkspace = { id: "ws_n", path: root, workspaceType: "local" };+ const settings: Settings = new Map();+ const frozen: string[] = [];+ const run: BoxRun = {+ key: boxKey(root), container: "c", runtimeBin: "docker", runtimeArgs: [], backend: "docker", exec: null, root, native: false, box: null,+ ready: async () => null,+ label: () => null,+ setTurn: () => {},+ freeze: async (label, { sessionId, turn = null }) => {+ frozen.push(`${sessionId} ${label}`);+ return { label, turn, copied: 0, carried: 0, save: async () => ({ label, changed: 0, bytes: 0 }), discard: async () => null };+ },+ };+ rememberServerDefault(stateDir, { local_box: { default: "on" } });+ const boxes = service({ stateDir, workspaces: [workspace], settings, env: { OMNIRUSH_BOX_HOME: home } });+ boxes.ensure = async () => run;+ const listed = async () => JSON.parse(await readFile(join(home, DESKTOP_PROJECTS_FILE), "utf8")).native_chats ?? [];+ // Reopened with 2 turns and no checkpoint: no checkpoint now either, and the plugin is told to leave it here.+ expect(await boxes.beforePrompt("ses_native_r1", workspace, { turnsBefore: 2 })).toBeNull();+ await boxes.beforePrompt("ses_native_r1", workspace);+ // A new chat and a chat that already has checkpoints go in the box.+ await boxes.beforePrompt("ses_native_n1", workspace);+ await mkdir(join(boxes.snapshotsDir, "ses_native_b1"), { recursive: true });+ await writeFile(join(boxes.snapshotsDir, "ses_native_b1", "turn-1.json"), "{}");+ await boxes.beforePrompt("ses_native_b1", workspace, { turnsBefore: 3 });+ expect(frozen.splice(0)).toEqual(["ses_native_n1 turn-1", "ses_native_b1 turn-2"]);+ expect(await listed()).toEqual(["ses_native_r1"]);+ // The user turns the project on: the chat moves to the box.+ boxes.ensure = async () => run;+ await boxes.setMode(workspace, "on");+ expect(await listed()).toEqual([]);+ await boxes.beforePrompt("ses_native_r1", workspace);+ expect(frozen.splice(0)).toEqual(["ses_native_r1 turn-1"]);+ // Turned on by the user before it was reopened: it moves at once.+ await boxes.beforePrompt("ses_native_r2", workspace, { turnsBefore: 4 });+ expect(frozen.splice(0)).toEqual(["ses_native_r2 turn-1"]);+ });++ test("a box on a backend the server no longer allows is planned again", async () => {+ const stateDir = await temp("state");+ const root = await temp("project");+ const workspace: BoxWorkspace = { id: "ws_a", path: root, workspaceType: "local" };+ const boxes = service({ stateDir, workspaces: [workspace], settings: new Map(), env: { OMNIRUSH_BOX_HOME: await temp("boxhome") } });+ const run: BoxRun = {+ key: boxKey(root), container: "c", runtimeBin: "docker", runtimeArgs: [], backend: "docker", exec: null, root, native: false, box: null,+ ready: async () => null, label: () => null, setTurn: () => {}, freeze: async () => null,+ };+ const projects = boxes["projects"];- projects.set(boxKey(root), { run, notice: null, planning: null, nextPlanAt: Date.now() + 60_000 });++ projects.set(boxKey(root), { run, notice: null, planning: null, nextPlanAt: Date.now() + 60_000, waitingImage: false });+ rememberServerDefault(stateDir, { local_box: { default: "on", backends: ["docker", "podman"] } });+ await boxes.serverBackendsChanged();+ expect(projects.get(boxKey(root))?.run).toBe(run);+ expect(await boxes.listedProjects()).toEqual([boxKey(root)]);+ rememberServerDefault(stateDir, { local_box: { default: "on", backends: ["podman"] } });+ await boxes.serverBackendsChanged();+ expect(projects.get(boxKey(root))).toMatchObject({ run: null, nextPlanAt: 0 });+ expect(await boxes.listedProjects()).toEqual([]);+ });+test("a remote workspace never gets a box", async () => {const stateDir = await temp("state");const workspace: BoxWorkspace = { id: "ws_r", path: "/remote", workspaceType: "remote" };diff --cc apps/server/src/server.tsindex 1654ea96,568b5abf..210ab88a--- a/apps/server/src/server.ts+++ b/apps/server/src/server.ts@@@ -1150,20 -1150,15 +1150,21 @@@ export async function startServer(confi// The Linux sandbox (box/): every workspace whose box is on is planned in the background (a missing// image starts downloading), and the server's default (local_box) is read for the engine config.const boxes = boxServiceFor(config, (level, message, attributes) => logger.log(level, message, attributes));- void boxes.ensureAll();if (gatewayBroker.enabled) {- void gatewayBroker.sessionUploadCapabilities().then(async (capabilities) => {- if (!rememberServerDefault(runtimeStorageDir(config), capabilities)) return;- await boxes.serverBackendsChanged();- await applyBoxEngineConfig(config, "local_box_default");- await boxes.ensureAll();- }).catch(() => undefined);+ // Read before the first plan and the engine's first config (at most 1.5 s, else the last answer is+ // used until it comes): a switch flipped or rolled back on the server applies at this start.+ const read = gatewayBroker.sessionUploadCapabilities().then((capabilities) => rememberServerDefault(runtimeStorageDir(config), capabilities)).catch(() => false);+ const inTime = await Promise.race([read.then(() => true), new Promise<false>((resolvePromise) => setTimeout(() => resolvePromise(false), 1_500).unref?.())]);+ if (!inTime) {+ void read.then(async (changed) => {+ if (!changed) return;++ await boxes.serverBackendsChanged();+ await applyBoxEngineConfig(config, "local_box_default");+ await boxes.ensureAll();+ }).catch(() => undefined);+ }}+ void boxes.ensureAll();if (config.clearUploadQueue) {// The user signed out: what the last account queued is deleted before anything else runs.await Promise.race([capture.signOut(), new Promise((resolvePromise) => setTimeout(resolvePromise, 10_000).unref?.())]);