A desktop coding agent with free access to frontier models.
TypeScript
feat: sandbox VM setup progress in the panel
ogsamrat35e9b16d9515
diff --git a/apps/app/src/app/lib/omnirush-server.ts b/apps/app/src/app/lib/omnirush-server.tsindex 46c7e23f..1e1dd49f 100644--- a/apps/app/src/app/lib/omnirush-server.ts+++ b/apps/app/src/app/lib/omnirush-server.ts@@ -560,6 +560,8 @@ export type OmniRushWorkspaceBoxProgress = {layersDone: number;layersTotal: number;startedAt: number | null;+ /** macOS, the OmniRush VM's first setup: its step ("lima", "vm_image", "vm_boot", "image") and that step's bytes. Older servers: absent. */+ setup?: { step: string; bytesDone: number | null; bytesTotal: number | null } | null;};export type OmniRushWorkspaceBoxChange = OmniRushWorkspaceBox & {engine: { status: "unchanged" | "applied" | "deferred" | "failed" | "unmanaged" };diff --git a/apps/app/src/react-app/domains/settings/sandbox-setup.ts b/apps/app/src/react-app/domains/settings/sandbox-setup.tsindex 8cee1b96..da2b9337 100644--- a/apps/app/src/react-app/domains/settings/sandbox-setup.ts+++ b/apps/app/src/react-app/domains/settings/sandbox-setup.ts@@ -7,7 +7,7 @@ export const WSL_TROUBLESHOOTING_URL = "https://learn.microsoft.com/windows/wsl//** One step of the setup's progress list. */export type SandboxSetupStep = {- id: "download" | "import" | "vm" | "start";+ id: "download" | "import" | "lima" | "vm_image" | "vm_boot" | "start";label: string;state: "done" | "active" | "todo";/** The download bar (bytes, parts), on the active download step. */@@ -55,20 +55,63 @@ function base(): Omit<SandboxSetupView, "kind" | "tone" | "title"> {return { detail: null, steps: [], howTo: [], link: null, consent: null, buttons: [], next: null, result: null, fallbackLine: null };}-/** The progress list: download, the WSL distro (Windows) or the VM (macOS), start. */-function progressSteps(box: OmniRushWorkspaceBox, vm: boolean): SandboxSetupStep[] {+/** The progress list: download (after the WSL distro on Windows), start. The OmniRush VM's: macVmSteps. */+function progressSteps(box: OmniRushWorkspaceBox): SandboxSetupStep[] {const downloading = box.state === "downloading";const wsl = box.backend?.id === "wsl" || box.runtime?.name === "wsl";// WSL: the distro is added first (no byte count yet), then the image comes down inside it.const importing = wsl && downloading && !box.progress?.bytesDone;const steps: SandboxSetupStep[] = [];- if (vm) steps.push({ id: "vm", label: "Start the OmniRush VM", state: box.state === "unavailable" ? "active" : "done" });if (wsl) steps.push({ id: "import", label: "Add the OmniRush Linux distro to WSL", state: importing ? "active" : "done" });- steps.push({ id: "download", label: "Download the sandbox (once)", state: importing || (vm && box.state === "unavailable") ? "todo" : downloading ? "active" : "done", progress: downloading && !importing ? linuxSandboxProgress(box.progress) : null });+ steps.push({ id: "download", label: "Download the sandbox (once)", state: importing ? "todo" : downloading ? "active" : "done", progress: downloading && !importing ? linuxSandboxProgress(box.progress) : null });steps.push({ id: "start", label: "Start the sandbox", state: box.state === "starting" ? "active" : box.state === "ready" ? "done" : "todo" });return steps;}+/** The OmniRush VM's first setup, in order (the server's setup lines: backends/lima.ts SETUP_STEPS). */+const VM_STEPS: Array<{ id: "lima" | "vm_image" | "vm_boot" | "download"; step: string; label: string }> = [+ { id: "lima", step: "lima", label: "Download the VM tools (Lima)" },+ { id: "vm_image", step: "vm_image", label: "Download the Linux VM (once)" },+ { id: "vm_boot", step: "vm_boot", label: "Start the OmniRush VM" },+ { id: "download", step: "image", label: "Download the sandbox (once)" },+];++function megabytes(bytes: number): string {+ return String(Math.max(0, Math.round(bytes / 1_000_000)));+}++/** A setup step's own bytes as a bar (the VM tools, the VM image). */+function stepBar(done: number | null, total: number | null): { value: number | null; label: string } {+ if (total && done !== null) {+ const value = Math.min(100, Math.round((done / total) * 100));+ return { value, label: `${megabytes(done)} of ${megabytes(total)} MB · ${value}%` };+ }+ return done ? { value: null, label: `${megabytes(done)} MB so far` } : { value: null, label: "Starting the download…" };+}++/**+ * macOS, the OmniRush VM being set up: its real steps from the server's+ * progress (the VM tools, the VM image, the first start, the box image),+ * then the sandbox start. Lima shipped with the app skips its step.+ */+export function macVmSteps(box: OmniRushWorkspaceBox): SandboxSetupStep[] {+ const setup = box.progress?.setup ?? null;+ const starting = box.state === "starting" || box.state === "ready";+ const at = starting ? VM_STEPS.length : Math.max(0, VM_STEPS.findIndex((s) => s.step === setup?.step));+ const steps: SandboxSetupStep[] = VM_STEPS.map((s, index) => {+ const state = index < at ? "done" : index === at ? "active" : "todo";+ const progress = state !== "active" ? null+ : s.id === "download" ? linuxSandboxProgress(box.progress)+ : s.id === "lima" || s.id === "vm_image" ? stepBar(setup?.bytesDone ?? null, setup?.bytesTotal ?? null)+ : null;+ return { id: s.id, label: s.label, state, ...(progress ? { progress } : {}) };+ });+ // The VM tools came with the app (no "lima" step was ever named): not shown.+ const shown = setup && setup.step !== "lima" ? steps.filter((s) => s.id !== "lima") : steps;+ shown.push({ id: "start", label: "Start the sandbox", state: box.state === "starting" ? "active" : box.state === "ready" ? "done" : "todo" });+ return shown;+}+/*** The chat's "Setting up the sandbox" panel for the selected project, or* null when there is nothing to show (not required, off, or ready).@@ -81,14 +124,15 @@ export function sandboxSetupView(box: OmniRushWorkspaceBox | null, { pending = nconst setup = box.setup ?? null;const result = setup?.result ? { ok: setup.result.ok, message: setup.result.message } : null;const busy = pending !== null;+ if (setup?.need === "mac_vm" && (box.state === "downloading" || box.state === "starting")) return macVmView(box);if (box.state === "downloading" || box.state === "starting") {- return { ...base(), kind: "progress", tone: "busy", title: "Setting up the sandbox", detail: "New chats in this project start as soon as it is ready. This happens once.", steps: progressSteps(box, false) };+ return { ...base(), kind: "progress", tone: "busy", title: "Setting up the sandbox", detail: "New chats in this project start as soon as it is ready. This happens once.", steps: progressSteps(box) };}if (box.state === "failed") {return { ...base(), kind: "action", tone: "error", title: "The sandbox could not start", detail: box.error ?? box.notice, buttons: [{ action: "retry", label: "Try again", primary: true, disabled: busy }], fallbackLine: RUNS_HERE };}if (!setup || setup.need === "none") {- return { ...base(), kind: "progress", tone: "busy", title: "Setting up the sandbox", detail: "Checking this computer…", steps: progressSteps(box, false) };+ return { ...base(), kind: "progress", tone: "busy", title: "Setting up the sandbox", detail: "Checking this computer…", steps: progressSteps(box) };}if (setup.declined && setup.need !== "cannot_run") {return { ...base(), kind: "line", tone: "off", title: "Sandbox setup postponed", detail: "Chats run on this computer until it is set up.", buttons: [{ action: "check", label: "Set up now", disabled: busy }] };@@ -129,7 +173,7 @@ export function sandboxSetupView(box: OmniRushWorkspaceBox | null, { pending = ncase "win_update":return { ...base(), kind: "action", tone: "attention", title: "Update WSL", detail: "WSL needs an update before the sandbox can start. Windows may ask for permission.", buttons: [{ action: "win_update", label: "Update WSL", primary: true, disabled: busy }, { action: "check", label: "Check again", disabled: busy }], fallbackLine: RUNS_HERE };case "mac_vm":- return { ...base(), kind: "progress", tone: "busy", title: "Setting up the sandbox", detail: "OmniRush starts its own small Linux VM on this Mac (once, no admin password).", steps: progressSteps(box, true) };+ return macVmView(box);case "cannot_run":return cannotRun(box, busy);case "runtime": {@@ -139,6 +183,11 @@ export function sandboxSetupView(box: OmniRushWorkspaceBox | null, { pending = n}}+/** macOS: the OmniRush VM sets itself up (no admin password); its real steps. */+function macVmView(box: OmniRushWorkspaceBox): SandboxSetupView {+ return { ...base(), kind: "progress", tone: "busy", title: "Setting up the sandbox", detail: "OmniRush sets up its own small Linux VM on this Mac (once, no admin password). New chats in this project start as soon as it is ready.", steps: macVmSteps(box) };+}+/** The box cannot run on this computer: why, what to try when there is something, and that chats run here. */function cannotRun(box: OmniRushWorkspaceBox, busy: boolean): SandboxSetupView {const setup = box.setup;diff --git a/apps/app/tests/sandbox-setup.test.tsx b/apps/app/tests/sandbox-setup.test.tsxindex bb62cf9d..be3ab653 100644--- a/apps/app/tests/sandbox-setup.test.tsx+++ b/apps/app/tests/sandbox-setup.test.tsx@@ -100,9 +100,25 @@ describe("sandbox setup panel: what it shows", () => {expect(declined?.buttons.map((b) => b.label)).toEqual(["Set up now"]);});- test("macOS VM progress (the VM backend's hook) and the usual next step when no backend works", () => {- const mac = sandboxSetupView(box({ platform: "darwin", setup: setup({ need: "mac_vm" }) }));- expect(mac?.steps.map((step) => `${step.id}:${step.state}`)).toEqual(["vm:active", "download:todo", "start:todo"]);+ test("macOS: the OmniRush VM's real setup steps from the server's progress, and the usual next step when no backend works", () => {+ const vm = { ok: true, name: "lima", flavor: "omnirush-vm", version: "2.2.1", reason: null };+ const mac = (progress: Partial<NonNullable<OmniRushWorkspaceBox["progress"]>> | null, state: OmniRushWorkspaceBox["state"] = "downloading") =>+ sandboxSetupView(box({ platform: "darwin", state, runtime: vm, setup: setup({ need: "mac_vm" }), progress: progress ? { bytesDone: null, bytesTotal: null, layersDone: 0, layersTotal: 0, startedAt: 1, ...progress } : null }));+ const steps = (view: ReturnType<typeof sandboxSetupView>) => view?.steps.map((step) => `${step.id}:${step.state}`);+ // Nothing said yet: the first step; Lima downloading: its own bytes.+ expect(steps(mac(null))).toEqual(["lima:active", "vm_image:todo", "vm_boot:todo", "download:todo", "start:todo"]);+ const lima = mac({ setup: { step: "lima", bytesDone: 19_000_000, bytesTotal: 38_000_000 } });+ expect(lima).toMatchObject({ kind: "progress", title: "Setting up the sandbox" });+ expect(lima?.steps[0]?.progress).toEqual({ value: 50, label: "19 of 38 MB · 50%" });+ // Lima shipped with the app (the first step named is the VM image): no Lima step.+ const image = mac({ setup: { step: "vm_image", bytesDone: 84_000_000, bytesTotal: 336_000_000 } });+ expect(steps(image)).toEqual(["vm_image:active", "vm_boot:todo", "download:todo", "start:todo"]);+ expect(image?.steps[0]?.progress).toEqual({ value: 25, label: "84 of 336 MB · 25%" });+ expect(steps(mac({ setup: { step: "vm_boot", bytesDone: null, bytesTotal: null } }))).toEqual(["vm_image:done", "vm_boot:active", "download:todo", "start:todo"]);+ const box_ = mac({ bytesDone: 130_000_000, bytesTotal: 260_000_000, setup: { step: "image", bytesDone: null, bytesTotal: null } });+ expect(steps(box_)).toEqual(["vm_image:done", "vm_boot:done", "download:active", "start:todo"]);+ expect(box_?.steps[2]?.progress).toEqual({ value: 50, label: "130 of 260 MB · 50%" });+ expect(steps(mac({ setup: { step: "image", bytesDone: null, bytesTotal: null } }, "starting"))).toEqual(["vm_image:done", "vm_boot:done", "download:done", "start:active"]);const runtime = sandboxSetupView(box({ platform: "linux", setup: setup({ need: "runtime" }) }));expect(runtime).toMatchObject({ kind: "action", title: "Install Podman or Docker" });expect(runtime?.next?.command).toBe("sudo apt install podman");diff --git a/apps/server/src/box/box-setup.test.ts b/apps/server/src/box/box-setup.test.tsindex 82acb53d..6834ec11 100644--- a/apps/server/src/box/box-setup.test.ts+++ b/apps/server/src/box/box-setup.test.ts@@ -42,7 +42,15 @@ describe("sandbox setup: what is needed", () => {expect(classifySetup({ runtime: fail(OFF), platform: "win32", checks, fallback: "native", state: { win: { state: "declined", at: Date.now() } } })).toMatchObject({ need: "win_install", declined: true });expect(classifySetup({ runtime: fail(OFF), platform: "win32", checks, fallback: "native", state: { win: { state: "declined", at: 1 } } }).declined).toBe(false);expect(classifySetup({ runtime: fail("no backend"), platform: "darwin", fallback: "native", release: "21.6.0" }).why).toBe("old_macos");- expect(classifySetup({ runtime: fail("no backend"), platform: "darwin", fallback: "native", release: "24.1.0", macVm: true }).need).toBe("mac_vm");+ });++ test("macOS: the OmniRush VM being set up is mac_vm; too old a macOS cannot run; nothing working is the usual next step", () => {+ const vm = { ok: true as const, name: "lima", backend: "lima", bin: "", version: "2.2.1", os: "linux", arch: "arm64", rootless: false, flavor: "omnirush-vm", vm: true, installed: false };+ expect(classifySetup({ runtime: vm, platform: "darwin", fallback: "native", release: "25.0.0", macVm: true })).toMatchObject({ need: "mac_vm", declined: false });+ expect(classifySetup({ runtime: { ...vm, installed: true }, platform: "darwin", fallback: "native", release: "25.0.0" }).need).toBe("none");+ expect(classifySetup({ runtime: fail("no backend"), platform: "darwin", fallback: "native", release: "21.6.0" }).why).toBe("old_macos");+ expect(classifySetup({ runtime: fail("no backend", ["the OmniRush VM needs macOS 13 or later (this is macOS 12)"]), platform: "darwin", fallback: "native", release: "25.0.0" }).why).toBe("old_macos");+ expect(classifySetup({ runtime: fail("no backend", ["the OmniRush VM did not start (vz: not supported)"]), platform: "darwin", fallback: "native", release: "25.0.0", macVm: true }).need).toBe("runtime");});test("the CLI's checks: build, S mode, a running hypervisor passes, firmware off, a VM guest; the install log", () => {diff --git a/apps/server/src/box/service.ts b/apps/server/src/box/service.tsindex 9ca8e06a..d0685cb1 100644--- a/apps/server/src/box/service.ts+++ b/apps/server/src/box/service.ts@@ -21,17 +21,19 @@** Not to be confused with the OpenWork worker sandbox (`sandboxBackend`).*/+import { existsSync } from "node:fs";import { mkdir, readFile, rename, writeFile } from "node:fs/promises";import { join } from "node:path";import { boxHome, boxKey, boxSnapshotsDir, containerName, installShell, listBoxes, mountReplaced, readRecord, resetBox, savedTurns, type BoxLabel, type BoxLog } from "./box.js";import { LABELS, OPT_IN, backendsFor, driverFor } from "./backends/index.js";+import { limaHome } from "./backends/lima.js";import type { BoxExec } from "./backends/types.js";import type { BoxEndpoint } from "./client.js";import { hostBuilds, hostBuildsNotice, hostBuildThings, hostRules } from "./host-builds.js";import { detectStack, imageFor, type BoxImage } from "./images.js";import { portLine } from "./ports.js";-import { askedBackend, boxRun, planBox, pullLog, pullMarker, pulling, pullInBackground, resolveMode, saveBackend, serverBackends, serverDefault, serverRequired, shimsDir, type BoxRun, type ProjectBoxMode, type ServerBoxDefault } from "./launch.js";+import { askedBackend, boxRun, planBox, pullActivityAt, pullLog, pullMarker, pulling, pullInBackground, setupWait, resolveMode, saveBackend, serverBackends, serverDefault, serverRequired, shimsDir, type BoxRun, type ProjectBoxMode, type ServerBoxDefault } from "./launch.js";import { desktopText, hostOnlyProject, shadowsApply, shadowsNotice, type RequiredFallback } from "./required.js";import { cachedWindowsChecks, classifySetup, linuxAllow, resumeWinSetup, saveSetupState, setupState, windowsInstall, windowsRestart, windowsUpdate, type BoxSetup } from "./setup.js";import type { BoxInstallLogPaths } from "./install-log.js";@@ -191,8 +193,14 @@ const REPLAN_MS = 15_000;const FREEZE_WAIT_MS = 90_000;/** The full backend check (every backend, for the status card's "others") is reused this long. */const ALTERNATIVES_MS = 60_000;-/** Required: a prompt waits this long at most for its project's box (the image download, the start). */+/**+ * Required: a prompt waits for its project's box while the first setup makes progress (the+ * download's log moves: the VM's setup lines, the image's bytes) and stops waiting after this+ * long with none (the CLI: a run's no-progress stop counts the setup too).+ */const REQUIRED_WAIT_MS = 15 * 60_000;+/** ...and at most this long in all, however slow the network (a first macOS VM setup is ~0.7 GB). */+const REQUIRED_SETUP_MAX_MS = 60 * 60_000;/** How often a waiting prompt looks again. */const REQUIRED_POLL_MS = 1_000;@@ -651,12 +659,20 @@ export class BoxService {/** What the sandbox needs here before it can run (the setup screen); this PC's checks are read (and cached) for it on Windows. */async setupFor(runtime: RuntimeResult | null, { fresh = false }: { fresh?: boolean } = {}): Promise<BoxSetup & { line: string | null }> {const checks = this.platform === "win32" && runtime && !runtime.ok ? await cachedWindowsChecks({ fresh }).catch(() => null) : null;- const setup = classifySetup({ runtime, platform: this.platform, checks, state: setupState(this.home), fallback: this.required().fallback });+ // macOS: the OmniRush VM picked and not made yet (it sets itself up; the panel shows its progress).+ const macVm = this.platform === "darwin" && Boolean(runtime?.ok && runtime.backend === "lima" && !runtime.installed && !this.limaMade(runtime));+ const setup = classifySetup({ runtime, platform: this.platform, checks, state: setupState(this.home), fallback: this.required().fallback, macVm });// The one line (required.json texts.desktop.cannot_run) when the box cannot run here.const why = setup.whyText ?? (runtime && !runtime.ok ? runtime.reason.split("\n")[0]!.replace(/\.$/, "") : null);return { ...setup, line: setup.need === "cannot_run" && why ? desktopText("cannot_run", { why }) : null };}+ /** Whether the OmniRush VM was made since the (cached) probe said it was not: its LIMA_HOME has the instance. */+ private limaMade(runtime: RuntimeResult): boolean {+ if (!runtime.ok || runtime.backend !== "lima") return false;+ try { return existsSync(join(limaHome(this.home, this.env, undefined, runtime.instance), runtime.instance ?? "omnirush-box", "lima.yaml")); } catch { return false; }+ }+/*** App start on Windows after "Set up (one restart)" (the resume marker):* `wsl --update` when WSL asks for it, then every project is planned (the@@ -812,14 +828,27 @@ export class BoxService {*/private async waitForBox(workspace: BoxWorkspace): Promise<BoxRun | null> {const key = boxKey(boxRoot(workspace));- const until = Date.now() + REQUIRED_WAIT_MS;+ const startedAt = Date.now();+ let lastProgressAt = startedAt;+ let said = false;for (;;) {const run = await this.ensure(workspace).catch(() => null);if (run) return run;const project = this.projects.get(key);- if (project?.why?.reason !== "downloading" || Date.now() >= until) return null;- await new Promise((resolve) => setTimeout(resolve, REQUIRED_POLL_MS));+ if (project?.why?.reason !== "downloading") return null;const pull = project.pull;+ const moved = pull ? pullActivityAt(this.home, pull.runtime, pull.image.pull) : null;+ if (moved !== null && moved > lastProgressAt) lastProgressAt = moved;+ const wait = setupWait({ startedAt, lastProgressAt, now: Date.now(), idleMs: REQUIRED_WAIT_MS, maxMs: REQUIRED_SETUP_MAX_MS });+ if (wait.over) {+ this.log("warn", "required sandbox wait over", { reason: wait.over, waitedMs: Date.now() - startedAt });+ return null;+ }+ if (!said && Date.now() - startedAt >= 60_000) {+ said = true;+ this.log("info", "required sandbox: the prompt waits for the first setup", { maxMin: Math.round(REQUIRED_SETUP_MAX_MS / 60_000) });+ }+ await new Promise((resolve) => setTimeout(resolve, REQUIRED_POLL_MS));if (pull && !pulling(this.home, pull.runtime, pull.image.pull)) project.nextPlanAt = 0;}}diff --git a/apps/server/src/box/setup.ts b/apps/server/src/box/setup.tsindex f9ac5f42..f1b0c1b9 100644--- a/apps/server/src/box/setup.ts+++ b/apps/server/src/box/setup.ts@@ -19,9 +19,11 @@// - Windows that cannot run WSL 2 (virtualization off in the firmware, a VM// without nested virtualization, S mode, an old build, a policy): why,// before the install and from WSL's errors after it.-// - macOS: the OmniRush VM (Lima) is its own backend; until it is in this-// build a Mac with no running container app reads "runtime" (the card's-// usual next step). `macVm` is the hook for it.+// - macOS: the OmniRush VM (Lima, backends/lima.ts) sets itself up (no admin):+// while it is not made yet the need is "mac_vm" and the panel shows the VM's+// real progress (Lima, the VM image, the VM's first boot, the box image).+// A Mac where it cannot run (macOS < 13) reads cannot_run; one where it+// failed and no container app runs reads "runtime" (the card's next step).// Never edits .wslconfig.import { createHash } from "node:crypto";@@ -117,6 +119,8 @@ function reasons(runtime: RuntimeResult | null): string[] {export function classifySetup({ runtime, platform, checks = null, state = {}, fallback, macVm = false, release = os.release(), now = Date.now() }: { runtime: RuntimeResult | null; platform: string; checks?: WindowsChecks | null; state?: SetupState; fallback: RequiredFallback; macVm?: boolean; release?: string; now?: number }): BoxSetup {const entry = platform === "win32" ? state.win : platform === "linux" ? state.linux : undefined;const base = { why: null, whyText: null, declined: recentlyDeclined(entry, { now }), result: entry?.message ? { ok: entry.state === "restart", message: entry.message, at: entry.at } : null, fallback };+ // The OmniRush VM picked and not made yet: it sets itself up now (the panel shows how far).+ if (platform === "darwin" && macVm && runtime?.ok) return { ...base, need: "mac_vm", declined: false };if (runtime?.ok) return { ...base, need: "none", declined: false };const said = reasons(runtime);const cannot = (why: CannotRunWhy | null, text?: string | null): BoxSetup => ({ ...base, need: "cannot_run", why, whyText: why ? whyText(why) : text ?? null, declined: false });@@ -139,7 +143,8 @@ export function classifySetup({ runtime, platform, checks = null, state = {}, fa// Darwin 22 is macOS 13.const darwin = Number(/^(\d+)/.exec(release)?.[1] ?? 0);if (darwin && darwin < 22) return cannot("old_macos");- return { ...base, need: macVm ? "mac_vm" : "runtime" };+ if (said.some((reason) => /needs macOS 1\d or later/.test(reason))) return cannot("old_macos");+ return { ...base, need: "runtime" };}return { ...base, need: "runtime" };}