Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.
Rust agentai-agentapplecomputer-usecomputer-use-agentcontainerizationcuadesktop-automationhacktoberfestlumemacosmanusoperatorswiftvirtualizationvirtualization-frameworkwindowswindows-sandbox
feat(spaces): Ask-first tasks can run on This Mac, asked once; no coloured left stripes (CUA-2385) (#6032)
cua-agents[bot]56a9070ca315
diff --git a/apps/cua-spaces-web/src/__tests__/ask-first-start-failed.test.tsx b/apps/cua-spaces-web/src/__tests__/ask-first-start-failed.test.tsxindex 76cb0d0578..17cd1c9dc8 100644--- a/apps/cua-spaces-web/src/__tests__/ask-first-start-failed.test.tsx+++ b/apps/cua-spaces-web/src/__tests__/ask-first-start-failed.test.tsx@@ -2,22 +2,25 @@// Copyright (c) 2026 Cua AI, Inc.// The "Ask first" Home sent a task to "This computer" and agents.start got-// the pseudo-id `this-mac`: the core answered with its own jargon-// ("use its id, such as local:<name> ... add_space") and the page said-// "Stopped" over a screen that said "Finished". A start that fails now says-// "Didn't start" everywhere, in plain words, with Change computer and Try-// again in the card and the core's words under Details.+// the pseudo-id `this-mac`: the core answered with its own jargon and the+// page said "Stopped" over a screen that said "Finished". This Mac is now a+// real target, asked about once: it starts on the Space id its host+// service shares it as. A start that fails says "Didn't start" in plain+// words, with Try again and Change computer in the card.import { act, cleanup, fireEvent, screen, waitFor } from "@testing-library/react";import { afterEach, beforeEach, describe, expect, it } from "vitest";import { setFlagOverride } from "@/bridge";import { wasmBuilt } from "@/bridge/__tests__/testCore";-import { addAskTask, askTask, resetAskTasks } from "@/lib/ask-first";+import { addAskTask, askTask, askTasks, resetAskTasks, setThisMacConfirmed, thisMacConfirmed } from "@/lib/ask-first";import { mountApp, stubBrowserApis } from "./app-harness";const CORE_NOT_FOUND = 'Space "this-mac" (use its id, such as local:<name> or cloud:<name>, or add it with add_space) not found';+/** The demo host shares this Mac on the relay as machine `this-mac`. */+const HOST_SPACE = "relay:this-mac";+const HOST = { failsCreates: false, listsGhost: false };afterEach(cleanup);stubBrowserApis();@@ -27,12 +30,68 @@ beforeEach(() => {setFlagOverride("spaces_ask_first_home", true);});+async function pickThisMac() {+ fireEvent.click(document.querySelector('[data-picker="where"]')!);+ const item = await screen.findByRole("menuitem", { name: /^This Mac/ });+ await act(async () => {+ fireEvent.click(item);+ });+}++async function startJob(text: string) {+ fireEvent.change(screen.getByLabelText("What do you want to do?"), { target: { value: text } });+ await act(async () => {+ fireEvent.click(screen.getByRole("button", { name: "Start" }));+ });+}++describe.skipIf(!wasmBuilt)("This Mac as a task's computer (real routes, wasm core)", () => {+ it("defaults to a new Linux computer, and This Mac asks once, then starts on this Mac's Space id", async () => {+ await mountApp("/home", HOST);+ await screen.findByText("What do you want to do?");+ expect(document.querySelector('[data-picker="where"]')!.textContent).toContain("A new Linux computer");+ await pickThisMac();+ await screen.findByText("Work on this Mac?");+ expect(screen.getByText(/Claude Code will work directly on this Mac, with your files and apps\. It can't be undone by throwing the computer away\./)).toBeTruthy();+ await act(async () => {+ fireEvent.click(screen.getByRole("button", { name: "Use this Mac" }));+ });+ expect(thisMacConfirmed()).toBe(true);+ await waitFor(() => expect(document.querySelector('[data-picker="where"]')!.textContent).toContain("This Mac"));+ await startJob("Tidy my Downloads folder");+ const id = askTasks()[0]!.id;+ await waitFor(() => expect(askTask(id)?.runId).toBeTruthy(), { timeout: 5000 });+ expect(askTask(id)).toMatchObject({ spaceId: HOST_SPACE, onHost: true, error: null });+ });++ it("Pick another keeps the default and reopens the picker", async () => {+ await mountApp("/home", HOST);+ await screen.findByText("What do you want to do?");+ await pickThisMac();+ await act(async () => {+ fireEvent.click(await screen.findByRole("button", { name: "Pick another" }));+ });+ await screen.findByRole("menuitem", { name: /A new Linux computer on this Mac/ });+ expect(thisMacConfirmed()).toBe(false);+ expect(document.querySelector('[data-picker="where"]')!.textContent).toContain("A new Linux computer");+ });++ it("doesn't ask again once answered on this device", async () => {+ setThisMacConfirmed(true);+ await mountApp("/home", HOST);+ await screen.findByText("What do you want to do?");+ await pickThisMac();+ await waitFor(() => expect(document.querySelector('[data-picker="where"]')!.textContent).toContain("This Mac"));+ expect(screen.queryByText("Work on this Mac?")).toBeNull();+ });+});+describe.skipIf(!wasmBuilt)("a task that couldn't start (real routes, wasm core)", () => {- it("says Didn't start in plain words, and Change computer starts it on a new Linux computer", async () => {+ it("an old this-mac task says Didn't start in plain words, and Try again starts it on this Mac", async () => {+ setThisMacConfirmed(true);const task = addAskTask({ prompt: "Hey!", agent: "openai-codex", os: "macos", spaceId: "this-mac", error: CORE_NOT_FOUND });- const { router } = await mountApp(`/home/${task.id}`, { failsCreates: false, listsGhost: false });- await screen.findByText("Agents can't work on this Mac itself");- expect(router.state.location.pathname).toBe(`/home/${task.id}`);+ await mountApp(`/home/${task.id}`, HOST);+ await screen.findByText("Couldn't start on this Mac");// The header and the screen agree.expect(screen.getAllByText("Didn't start").length).toBeGreaterThanOrEqual(2);expect(screen.queryByText("Finished")).toBeNull();@@ -41,24 +100,31 @@ describe.skipIf(!wasmBuilt)("a task that couldn't start (real routes, wasm core)const details = screen.getByText("Details").closest("details")!;expect(details.textContent).toContain("add_space");expect(document.querySelector("[data-ask-start-failed]")!.textContent!.replace(details.textContent!, "")).not.toMatch(/add_space|local:</);- // Try again can't help a target that can't work: only Change computer.- expect(screen.queryByRole("button", { name: /Try again/ })).toBeNull();+ expect(screen.getByRole("button", { name: /Change computer/ })).toBeTruthy();+ await act(async () => {+ fireEvent.click(screen.getByRole("button", { name: /Try again/ }));+ });+ await waitFor(() => expect(askTask(task.id)?.runId).toBeTruthy(), { timeout: 5000 });+ expect(askTask(task.id)).toMatchObject({ spaceId: HOST_SPACE, onHost: true, error: null });+ });+ it("Change computer moves a failed task to a new Linux computer", async () => {+ const task = addAskTask({ prompt: "Run the tests", agent: "claude-code", os: "linux", spaceId: "local:gone", error: 'Space "local:gone" (use its id, such as local:<name> or cloud:<name>, or add it with add_space) not found' });+ await mountApp(`/home/${task.id}`, HOST);+ await screen.findByText("Couldn't find that computer");+ expect(screen.queryByRole("button", { name: /Try again/ })).toBeNull();fireEvent.click(screen.getByRole("button", { name: /Change computer/ }));const linux = await screen.findByRole("menuitem", { name: /A new Linux computer on this Mac/ });- expect(screen.getByText(/Agents don't work on this Mac itself/)).toBeTruthy();- expect(screen.queryByRole("menuitem", { name: /This computer/ })).toBeNull();await act(async () => {fireEvent.click(linux);});await waitFor(() => expect(askTask(task.id)?.runId).toBeTruthy(), { timeout: 5000 });- expect(askTask(task.id)).toMatchObject({ error: null, os: "linux" });- expect(askTask(task.id)?.spaceId).not.toBe("this-mac");+ expect(askTask(task.id)).toMatchObject({ error: null, os: "linux", onHost: false });});it("offers Try again for an error that may pass", async () => {const task = addAskTask({ prompt: "Run the tests", agent: "claude-code", os: "linux", spaceId: "local:agent-sandbox", error: "agent-sandbox is not running" });- await mountApp(`/home/${task.id}`, { failsCreates: false, listsGhost: false });+ await mountApp(`/home/${task.id}`, HOST);await screen.findByText("Couldn't reach that computer");expect(screen.getByRole("button", { name: /Try again/ })).toBeTruthy();expect(screen.getByRole("button", { name: /Change computer/ })).toBeTruthy();diff --git a/apps/cua-spaces-web/src/bridge/adapters/demo.ts b/apps/cua-spaces-web/src/bridge/adapters/demo.tsindex 6843b0f51c..997399fa6e 100644--- a/apps/cua-spaces-web/src/bridge/adapters/demo.ts+++ b/apps/cua-spaces-web/src/bridge/adapters/demo.ts@@ -558,8 +558,12 @@ export function createDemoAdapter(options: DemoOptions = {}): DataAdapter & { re};},"agents.start": async ({ spaceId, agent, prompt, repo }) => {- const row = findRow(spaceId);- if (row.powerState !== "running" || !row.reachable) throw new HostError(`${row.name} is not running`, "space_off");+ // This Mac's own Space id (its host service shares it on the relay) runs too, like the core's.+ const own = state.host.configured && state.host.sharing && state.host.machineId ? `relay:${state.host.machineId}` : null;+ if (spaceId !== own) {+ const row = findRow(spaceId);+ if (row.powerState !== "running" || !row.reachable) throw new HostError(`${row.name} is not running`, "space_off");+ }await wait(step);const runId = `run-${Math.random().toString(16).slice(2, 8)}`;state.runs.push(demoStartedRun(spaceId, runId, agent, prompt, now(), repo));diff --git a/apps/cua-spaces-web/src/components/ask-first/ask-box.tsx b/apps/cua-spaces-web/src/components/ask-first/ask-box.tsxindex 9da51ad4bc..999e3cf7d8 100644--- a/apps/cua-spaces-web/src/components/ask-first/ask-box.tsx+++ b/apps/cua-spaces-web/src/components/ask-first/ask-box.tsx@@ -28,7 +28,7 @@ export const agentName = (id: string) => TASK_AGENTS.find((a) => a.id === id)?.nconst OS_WORD: Record<SpaceOs, string> = { linux: "Linux", macos: "Mac", windows: "Windows", unknown: "" };export function whereLabel(where: TaskWhere): string {- return where.kind === "new" ? `A new ${OS_WORD[where.os]} computer · this Mac` : where.space.name;+ return where.kind === "new" ? `A new ${OS_WORD[where.os]} computer · this Mac` : where.kind === "this-mac" ? "This Mac" : where.space.name;}export function AppMark({ agent, size = 32 }: { agent: string; size?: number }) {@@ -39,12 +39,26 @@ export function AppMark({ agent, size = 32 }: { agent: string; size?: number }));}-/** Why this Mac itself isn't in the list. */-export const WHERE_FOOTER = "Agents don't work on this Mac itself. Each job gets its own computer, so yours stays untouched.";+/** The trade-off, under the list. */+export const WHERE_FOOTER = "A new computer keeps yours untouched. This Mac works on your own files and apps.";-function Picker({ trigger, title, children, footer }: { trigger: ReactElement; title: string; children: ReactNode; footer?: ReactNode }) {+function Picker({+ trigger,+ title,+ children,+ footer,+ open,+ onOpenChange,+}: {+ trigger: ReactElement;+ title: string;+ children: ReactNode;+ footer?: ReactNode;+ open?: boolean;+ onOpenChange?: (open: boolean) => void;+}) {return (- <MenuPrimitive.Root>+ <MenuPrimitive.Root {...(open === undefined ? {} : { open })} onOpenChange={(o) => onOpenChange?.(o)}><MenuPrimitive.Trigger render={trigger} /><MenuPrimitive.Portal><MenuPrimitive.Positioner sideOffset={6} align="start" className="z-50 outline-none">@@ -90,6 +104,8 @@ export function AskBox({mostUsed,where,onWhere,+ whereOpen,+ onWhereOpen,kinds,spaces,busy,@@ -106,6 +122,9 @@ export function AskBox({mostUsed: string | null;where: TaskWhere;onWhere: (w: TaskWhere) => void;+ /** The Where picker held open (it reopens when "Use this Mac?" is declined). */+ whereOpen?: boolean;+ onWhereOpen?: (open: boolean) => void;/** The kinds of new computer this Mac can make, with a line each ("about 2 min"). */kinds: NewKind[];/** Running Spaces to use instead (never this Mac's own desktop: `pickableSpaces`). */@@ -158,11 +177,19 @@ export function AskBox({<WherePickerwhere={where}onWhere={onWhere}+ open={whereOpen}+ onOpenChange={onWhereOpen}kinds={kinds}spaces={spaces}trigger={<button type="button" className={pickerButton} data-picker="where">- {where.kind === "new" ? <OsIcon os={where.os} className="size-4 text-muted-foreground" /> : <MonitorIcon className="size-4 text-muted-foreground" />}+ {where.kind === "new" ? (+ <OsIcon os={where.os} className="size-4 text-muted-foreground" />+ ) : where.kind === "this-mac" ? (+ <LaptopIcon className="size-4 text-muted-foreground" />+ ) : (+ <MonitorIcon className="size-4 text-muted-foreground" />+ )}<span className="max-w-72 truncate">{whereLabel(where)}</span><ChevronDownIcon className="size-4 text-muted-foreground" /></button>@@ -184,9 +211,9 @@ export function AskBox({}/**- * "Where it runs": the kinds of new computer this Mac can make, then the- * running Spaces you have. This Mac's own desktop is never offered (the- * footer says why): `agent_start` runs only in a Space.+ * "Where it runs": the kinds of new computer this Mac can make, then this+ * Mac itself and the running Spaces you have. Picking this Mac asks once+ * (`useWherePick`).*/export function WherePicker({where,@@ -194,15 +221,19 @@ export function WherePicker({kinds,spaces,trigger,+ open,+ onOpenChange,}: {where: TaskWhere | null;onWhere: (w: TaskWhere) => void;kinds: NewKind[];spaces: Space[];trigger: ReactElement;+ open?: boolean;+ onOpenChange?: (open: boolean) => void;}) {return (- <Picker title="Where it runs" trigger={trigger} footer={WHERE_FOOTER}>+ <Picker title="Where it runs" trigger={trigger} footer={WHERE_FOOTER} open={open} onOpenChange={onOpenChange}>{kinds.map((k) => (<PickerRowkey={k.os}@@ -217,7 +248,18 @@ export function WherePicker({onSelect={() => onWhere({ kind: "new", os: k.os })}/>))}- {spaces.length ? <p className="px-3 pt-3 pb-1 text-[12px] font-medium text-muted-foreground">Or use a computer you already have</p> : null}+ <p className="px-3 pt-3 pb-1 text-[12px] font-medium text-muted-foreground">Or use a computer you already have</p>+ <PickerRow+ icon={+ <span className="flex size-7 items-center justify-center rounded-md border text-muted-foreground">+ <LaptopIcon className="size-4" />+ </span>+ }+ title="This Mac"+ note="Works on your own files and apps"+ selected={where?.kind === "this-mac"}+ onSelect={() => onWhere({ kind: "this-mac" })}+ />{spaces.slice(0, 5).map((s) => (<PickerRowkey={s.id}diff --git a/apps/cua-spaces-web/src/components/ask-first/home.tsx b/apps/cua-spaces-web/src/components/ask-first/home.tsxindex 0de7ac7630..cc8679736d 100644--- a/apps/cua-spaces-web/src/components/ask-first/home.tsx+++ b/apps/cua-spaces-web/src/components/ask-first/home.tsx@@ -15,6 +15,7 @@ import { realSpaces, spaceState } from "@/lib/spaces";import { cn } from "@/lib/utils";import { agentName, AppMark, AskBox, TASK_AGENTS, type TaskWhere } from "./ask-box";+import { useWherePick } from "./this-mac-confirm";import { useStartTask } from "./use-start-task";import { useWhereOptions } from "./where-options";@@ -65,6 +66,8 @@ export function AskFirstHome() {const chosenAgent = agent ?? mostUsed ?? TASK_AGENTS.find((a) => installed.has(a.id))?.id ?? "claude-code";// A new Linux computer unless you pick; a pick that's no longer offered falls back to it.const [picked, setWhere] = useState<TaskWhere | null>(null);+ const [whereOpen, setWhereOpen] = useState(false);+ const pick = useWherePick(agentName(chosenAgent));const where = currentWhere(picked, kinds, pickable);const submit = (prompt = text, w = where) => {if (!prompt.trim()) return;@@ -92,7 +95,9 @@ export function AskFirstHome() {installed={installed}mostUsed={mostUsed}where={where}- onWhere={setWhere}+ onWhere={(w) => pick.choose(w, setWhere, () => setWhereOpen(true))}+ whereOpen={whereOpen}+ onWhereOpen={setWhereOpen}kinds={kinds}spaces={pickable}busy={false}@@ -128,6 +133,7 @@ export function AskFirstHome() {)}{!first && realSpaces(spaces ?? []).length > 0 ? <YourSpaces spaces={realSpaces(spaces ?? [])} /> : null}</div>+ {pick.dialog}</div>);}@@ -165,13 +171,13 @@ function TaskRow({ task, run, state, space }: { task: AskTask; run: AgentRunSumm: state === "didnt-start" && task.error? `Didn't start: ${startErrorView(task.error, agentName(task.agent)).title}`: TASK_STATE_TEXT[state];- const where = task.ending === "thrown" ? "Thrown away" : (space?.name ?? "");+ const where = task.ending === "thrown" ? "Thrown away" : task.onHost ? "This Mac" : (space?.name ?? "");return (<Linkto="/home/$taskId"params={{ taskId: task.id }}data-task-row={task.id}- className={cn("flex min-h-[72px] items-center gap-4 px-5 py-3 hover:bg-accent/60", (state === "needs-you" || state === "stuck") && "border-l-2 border-l-warning")}+ className="flex min-h-[72px] items-center gap-4 px-5 py-3 hover:bg-accent/60"><AppMark agent={task.agent} size={36} /><div className="min-w-0 flex-1">diff --git a/apps/cua-spaces-web/src/components/ask-first/task-view.tsx b/apps/cua-spaces-web/src/components/ask-first/task-view.tsxindex e3eb6781c5..2e05ea536c 100644--- a/apps/cua-spaces-web/src/components/ask-first/task-view.tsx+++ b/apps/cua-spaces-web/src/components/ask-first/task-view.tsx@@ -13,12 +13,13 @@ import { StreamSurface } from "@/components/space-detail/stream-surface";import { ConfirmDialog } from "@/components/ui/alert-dialog";import { Button } from "@/components/ui/button";import { toastError } from "@/components/ui/toast";-import { keepTranscript, startErrorView, taskState, TASK_STATE_TEXT, taskTitle, updateAskTask, useAskTasks, type AskTask, type TaskState, type TaskWhere } from "@/lib/ask-first";+import { keepTranscript, retryTarget, startErrorView, taskState, TASK_STATE_TEXT, taskTitle, updateAskTask, useAskTasks, type AskTask, type TaskState, type TaskWhere } from "@/lib/ask-first";import { createProgress, spaceState } from "@/lib/spaces";import { cn } from "@/lib/utils";import { agentName, AppMark, WherePicker } from "./ask-box";import { StateDot, taskRun } from "./home";+import { useWherePick } from "./this-mac-confirm";import { useStartTask } from "./use-start-task";import { useWhereOptions } from "./where-options";@@ -55,7 +56,8 @@ function TaskView({ task }: { task: AskTask }) {const { data: session } = useSession();const sharing = useShareSheet();const { retry } = useStartTask();- const space = spaces?.find((s) => s.id === task.spaceId);+ // On this Mac there is no other screen to show, share or take over, and nothing to throw away.+ const space = task.onHost ? undefined : spaces?.find((s) => s.id === task.spaceId);const pending = task.pendingId ? spaces?.find((s) => s.id === task.pendingId) : undefined;const ref = task.runId && task.spaceId && task.ending !== "thrown" ? { spaceId: task.spaceId, runId: task.runId } : null;const live = useAgentTimeline(ref);@@ -168,7 +170,7 @@ function TaskView({ task }: { task: AskTask }) {<div className="flex justify-end"><div className="max-w-[85%] rounded-2xl rounded-br-md bg-muted px-3.5 py-2 text-[13px] leading-[1.55] whitespace-pre-wrap">{task.prompt}</div></div>- {task.error ? null : <Starting pending={pending} space={space} name={name} />}+ {task.error ? null : <Starting pending={pending} space={space} name={name} onHost={Boolean(task.onHost)} />}{footer}</div></div>@@ -231,29 +233,34 @@ function TaskView({ task }: { task: AskTask }) {);}-function CuaLine({ children, tone }: { children: ReactNode; tone?: "bad" }) {+function CuaLine({ children }: { children: ReactNode }) {return (- <div className={cn("flex items-start gap-3 rounded-xl border bg-card px-5 py-4 shadow-xs", tone === "bad" && "border-l-2 border-l-destructive")}>+ <div className="flex items-start gap-3 rounded-xl border bg-card px-5 py-4 shadow-xs"><CuaKey size={28} /><div className="min-w-0 flex-1 text-[13px] leading-relaxed text-muted-foreground">{children}</div></div>);}-function Starting({ pending, space, name }: { pending: Space | undefined; space: Space | undefined; name: string }) {+function Starting({ pending, space, name, onHost }: { pending: Space | undefined; space: Space | undefined; name: string; onHost: boolean }) {const making = pending?.progress;- const steps = [- { text: "Making the computer", done: Boolean(space), now: !space },- { text: `Opening ${name} inside it`, done: false, now: Boolean(space) },- ];+ const steps = onHost+ ? [{ text: `Opening ${name} on this Mac`, done: false, now: true }]+ : [+ { text: "Making the computer", done: Boolean(space), now: !space },+ { text: `Opening ${name} inside it`, done: false, now: Boolean(space) },+ ];return (<div className="rounded-xl border bg-card px-5 py-4 shadow-xs" data-ask-starting=""><div className="flex items-center gap-3"><CuaKey size={28} /><div className="flex-1">- <div className="text-[15px] font-semibold">Getting a fresh computer ready</div>+ <div className="text-[15px] font-semibold">{onHost ? "Starting on this Mac" : "Getting a fresh computer ready"}</div><div className="text-[13px] text-muted-foreground">- {making?.transfer ?? (making ? `${making.label} ${Math.round(createProgress({ progress: making }) * 100)}%` : "Usually under a minute. The first one takes a few minutes.")}+ {onHost+ ? "It works with your own files and apps."+ : (making?.transfer ??+ (making ? `${making.label} ${Math.round(createProgress({ progress: making }) * 100)}%` : "Usually under a minute. The first one takes a few minutes."))}</div></div></div>@@ -274,30 +281,39 @@ function Starting({ pending, space, name }: { pending: Space | undefined; space:* Change computer right in the card, and the core's own words under* Details.*/-export function StartFailed({ error, name, onRetry }: { error: string; name: string; onRetry: (where?: TaskWhere) => void }) {+export function StartFailed({ error, name, host, onRetry }: { error: string; name: string; host: boolean; onRetry: (where?: TaskWhere) => void }) {const view = startErrorView(error, name);const { kinds, spaces } = useWhereOptions();+ const [open, setOpen] = useState(false);+ const pick = useWherePick(name);return (- <CuaLine tone="bad">+ <CuaLine><div data-ask-start-failed={view.action}><div className="mb-1 flex items-center gap-2 text-[15px] font-semibold text-foreground"><TriangleAlertIcon className="size-4 text-destructive" /> {view.title}</div><p>{view.body}</p><div className="mt-3 flex flex-wrap items-center gap-2">+ {view.action === "set-up-host" ? (+ <Button className="h-10 px-4" render={<Link to="/machines" />}>+ Open Computers+ </Button>+ ) : null}{view.action === "add-key" ? (<Button className="h-10 px-4" render={<Link to="/settings/connected-apps" />}>Add your key</Button>) : null}{view.retry ? (- <Button variant={view.action === "retry" ? "default" : "outline"} className="h-10 px-4" onClick={() => onRetry()}>+ <Button variant={view.action === "retry" ? "default" : "outline"} className="h-10 px-4" onClick={() => (host ? pick.choose({ kind: "this-mac" }, onRetry) : onRetry())}><RotateCwIcon /> Try again</Button>) : null}<WherePickerwhere={null}- onWhere={(w) => onRetry(w)}+ onWhere={(w) => pick.choose(w, onRetry, () => setOpen(true))}+ open={open}+ onOpenChange={setOpen}kinds={kinds}spaces={spaces}trigger={@@ -312,6 +328,7 @@ export function StartFailed({ error, name, onRetry }: { error: string; name: str<p className="mt-1 font-mono break-words whitespace-pre-wrap">{error}</p></details></div>+ {pick.dialog}</CuaLine>);}@@ -341,7 +358,7 @@ function ThreadFooter({}) {return (<div className="flex flex-col gap-5" data-ask-footer="">- {task.error ? <StartFailed error={task.error} name={name} onRetry={onRetry} /> : null}+ {task.error ? <StartFailed error={task.error} name={name} host={retryTarget(task).kind === "host"} onRetry={onRetry} /> : null}{state === "working" ? (<p className="flex items-center gap-2 text-xs text-muted-foreground" role="status"><StateDot state="working" />@@ -362,7 +379,7 @@ function ThreadFooter({</CuaLine>) : null}{state === "needs-you" && needsYou ? (- <div className="rounded-xl border border-l-2 border-l-warning bg-card px-5 py-4 shadow-xs" data-ask-needs-you="">+ <div className="rounded-xl border bg-card px-5 py-4 shadow-xs" data-ask-needs-you=""><div className="flex items-start gap-3"><AppMark agent={task.agent} size={28} /><div className="min-w-0 flex-1">@@ -388,9 +405,12 @@ function ThreadFooter({<CheckIcon className="mt-0.5 size-5 text-success" /><div><div className="text-[15px] font-semibold">{name} finished</div>- <div className="mt-1 text-[13px] text-muted-foreground">Ask a follow-up below, or decide what happens to the computer.</div>+ <div className="mt-1 text-[13px] text-muted-foreground">+ {task.onHost ? "Ask a follow-up below." : "Ask a follow-up below, or decide what happens to the computer."}+ </div></div></div>+ {task.onHost ? null : (<div className="flex flex-wrap items-center gap-3 border-t px-5 py-3"><span className="flex-1 text-[13px] text-muted-foreground">The computer is still on. What should happen to it?</span><Button variant="outline" className="h-11 px-4" onClick={onKeep}>@@ -400,9 +420,10 @@ function ThreadFooter({<Trash2Icon /> Throw it away</Button></div>+ )}</div>) : null}- {state === "done" ? <p className="text-[12px] text-muted-foreground">Throwing it away deletes the computer. This conversation stays.</p> : null}+ {state === "done" && !task.onHost ? <p className="text-[12px] text-muted-foreground">Throwing it away deletes the computer. This conversation stays.</p> : null}{state === "kept" ? <p className="text-[12px] text-muted-foreground">You kept the computer. It's with your Spaces.</p> : null}{state === "thrown" ? <p className="text-[12px] text-muted-foreground">You threw the computer away. This is the conversation as it was.</p> : null}</div>@@ -435,7 +456,11 @@ function Screen({: !space? task.ending === "thrown"? "Thrown away"- : "Not ready yet"+ : task.onHost+ ? state === "working" || state === "stuck"+ ? "Working on this Mac"+ : TASK_STATE_TEXT[state]+ : "Not ready yet": state === "needs-you"? "Waiting for you": state === "working" || state === "stuck"@@ -494,13 +519,23 @@ function Screen({function ComputerCard({ task, space }: { task: AskTask; space: Space | undefined }) {const os = task.os === "macos" ? "Mac" : task.os === "windows" ? "Windows" : "Linux";- const line = !space ? (task.ending === "thrown" ? "Thrown away" : task.error ? "Not made" : "Getting ready") : spaceState(space) === "running" ? "On" : "Off";+ const line = task.onHost+ ? "Your own Mac, with your files and apps"+ : !space+ ? task.ending === "thrown"+ ? "Thrown away"+ : task.error+ ? "Not made"+ : "Getting ready"+ : spaceState(space) === "running"+ ? "On"+ : "Off";return (<div className="rounded-xl border bg-card text-[13px] shadow-xs"><div className="flex min-h-12 items-center gap-3 px-4 py-2"><OsIcon os={task.os} className="size-4 text-muted-foreground" /><div className="min-w-0 flex-1">- <div className="font-medium">{space ? space.name : `${os} computer for this task`}</div>+ <div className="font-medium">{task.onHost ? "This Mac" : space ? space.name : `${os} computer for this task`}</div><div className="text-muted-foreground">{line}</div></div>{space ? (diff --git a/apps/cua-spaces-web/src/components/ask-first/this-mac-confirm.tsx b/apps/cua-spaces-web/src/components/ask-first/this-mac-confirm.tsxnew file mode 100644index 0000000000..d64f7d42cf--- /dev/null+++ b/apps/cua-spaces-web/src/components/ask-first/this-mac-confirm.tsx@@ -0,0 +1,53 @@+// SPDX-License-Identifier: FSL-1.1-MIT+// Copyright (c) 2026 Cua AI, Inc.++import { useRef, useState, type ReactNode } from "react";++import { ConfirmDialog } from "@/components/ui/alert-dialog";+import { setThisMacConfirmed, thisMacConfirmed, thisMacConfirmText, type TaskWhere } from "@/lib/ask-first";++/**+ * Picking where a task runs. This Mac asks once per device ("Use this Mac"+ * or "Pick another"); the answer is kept until it is reset in Settings →+ * Advanced. Declining calls `onDeclined` (the picker reopens).+ */+export function useWherePick(agent: string): {+ choose: (where: TaskWhere, onChosen: (w: TaskWhere) => void, onDeclined?: () => void) => void;+ dialog: ReactNode;+} {+ const [asking, setAsking] = useState<{ onChosen: (w: TaskWhere) => void; onDeclined?: () => void } | null>(null);+ // The dialog closes before its confirm runs: a close is a "Pick another" only if no confirm follows.+ const confirmed = useRef(false);+ const text = thisMacConfirmText(agent);+ return {+ choose: (where, onChosen, onDeclined) => {+ if (where.kind !== "this-mac" || thisMacConfirmed()) onChosen(where);+ else setAsking({ onChosen, onDeclined });+ },+ dialog: (+ <ConfirmDialog+ open={asking !== null}+ onOpenChange={(open) => {+ if (open || !asking) return;+ const declined = asking.onDeclined;+ setAsking(null);+ setTimeout(() => {+ if (!confirmed.current) declined?.();+ confirmed.current = false;+ }, 0);+ }}+ title={text.title}+ description={text.description}+ confirmLabel="Use this Mac"+ cancelLabel="Pick another"+ onConfirm={() => {+ const chosen = asking?.onChosen;+ confirmed.current = true;+ setThisMacConfirmed(true);+ setAsking(null);+ chosen?.({ kind: "this-mac" });+ }}+ />+ ),+ };+}diff --git a/apps/cua-spaces-web/src/components/ask-first/use-start-task.ts b/apps/cua-spaces-web/src/components/ask-first/use-start-task.tsindex 97f03efb7a..9857a104be 100644--- a/apps/cua-spaces-web/src/components/ask-first/use-start-task.ts+++ b/apps/cua-spaces-web/src/components/ask-first/use-start-task.ts@@ -3,13 +3,14 @@import { useNavigate } from "@tanstack/react-router";-import { newPendingId, useAgents, useFeatureRecorder, useFirstSpaceOffers, useSpaces } from "@/bridge";-import { addAskTask, askTask, HOST_TARGET_ERROR, retryTarget, taskTarget, updateAskTask, type AskTask, type TaskTarget, type TaskWhere } from "@/lib/ask-first";+import { newPendingId, useAgents, useBridge, useFeatureRecorder, useFirstSpaceOffers, useSpaces, type HostStatus } from "@/bridge";+import { addAskTask, askTask, HOST_NOT_SHARED, hostSpaceId, retryTarget, taskTarget, updateAskTask, whereOs, type AskTask, type TaskTarget, type TaskWhere } from "@/lib/ask-first";/*** Starts a task: records it, opens its conversation at once, makes the* computer (or uses the one picked), then starts the coding app on it with- * the job as its prompt. A failure is kept on the task and shown in its+ * the job as its prompt. This Mac runs it in its own Space id, the one its+ * host service shares it as (`hostSpaceId`). A failure is kept on the task and shown in its* thread, which offers Try again (`retry`) and Change computer* (`retry(task, where)`).*/@@ -18,7 +19,8 @@ export function useStartTask(): {retry: (task: AskTask, where?: TaskWhere) => void;} {const navigate = useNavigate();- const { data: spaces, createSpace } = useSpaces();+ const { createSpace } = useSpaces();+ const { data: host } = useBridge();const { startRun } = useAgents();const { offers } = useFirstSpaceOffers();const record = useFeatureRecorder();@@ -26,8 +28,13 @@ export function useStartTask(): {const run = (id: string, target: TaskTarget) =>void (async () => {try {- if (target.kind === "host") throw new Error(HOST_TARGET_ERROR);let spaceId = target.kind === "space" ? target.spaceId : null;+ if (target.kind === "host") {+ const status = (await host?.call("host.status", {} as never).catch(() => null)) as HostStatus | null;+ spaceId = hostSpaceId(status);+ if (!spaceId) throw new Error(HOST_NOT_SHARED);+ updateAskTask(id, { spaceId, onHost: true });+ }if (!spaceId) {const os = target.kind === "create" ? target.os : "linux";const pendingId = newPendingId();@@ -48,16 +55,16 @@ export function useStartTask(): {return {start: ({ prompt, agent, where }) => {const target = taskTarget(where);- const os = where.kind === "new" ? where.os : where.space.os;- const task = addAskTask({ prompt: prompt.trim(), agent, os, spaceId: target.kind === "space" ? target.spaceId : null });+ const task = addAskTask({ prompt: prompt.trim(), agent, os: whereOs(where), spaceId: target.kind === "space" ? target.spaceId : null, onHost: target.kind === "host" });record("ask_first_task_started");void navigate({ to: "/home/$taskId", params: { taskId: task.id } });run(task.id, target);},retry: (task, where) => {- const target = where ? taskTarget(where) : retryTarget(task, spaces);- const os = where ? (where.kind === "new" ? where.os : where.space.os) : task.os;- updateAskTask(task.id, { error: null, runId: null, pendingId: null, os, spaceId: target.kind === "space" ? target.spaceId : where ? null : task.spaceId });+ const target = where ? taskTarget(where) : retryTarget(task);+ const os = where ? whereOs(where) : task.os;+ const spaceId = target.kind === "space" ? target.spaceId : target.kind === "create" && !where ? task.spaceId : null;+ updateAskTask(task.id, { error: null, runId: null, pendingId: null, os, spaceId, onHost: target.kind === "host" });record("ask_first_task_retried");run(task.id, target);},diff --git a/apps/cua-spaces-web/src/components/settings/advanced-tab.tsx b/apps/cua-spaces-web/src/components/settings/advanced-tab.tsxindex 526fa46597..be173fd108 100644--- a/apps/cua-spaces-web/src/components/settings/advanced-tab.tsx+++ b/apps/cua-spaces-web/src/components/settings/advanced-tab.tsx@@ -8,6 +8,7 @@ import { CoreSettingsRow } from "@/components/settings/core-section";import { HostSetupForm } from "@/components/this-machine";import { Button } from "@/components/ui/button";import { toastError } from "@/components/ui/toast";+import { setThisMacConfirmed, useThisMacConfirmed } from "@/lib/ask-first";/** The host form's profile for your own connection server or Direct (`host::SELF_HOSTED_PROFILE`). */const SELF_HOSTED = "self-hosted";@@ -121,10 +122,19 @@ function askFirstRow(on: boolean): CoreRow {};}+/** Whether a task asks before it works on this Mac itself (the answer to "Work on this Mac?" is kept per device). */+function thisMacAskRow(asks: boolean): CoreRow {+ return { ...askFirstRow(asks), id: "ask-first:this-mac", label: "Ask before a task uses this Mac", options: [+ { id: "on", label: "On", active: asks },+ { id: "off", label: "Off", active: !asks },+ ] };+}+/** Cua Volume and the new Home. Off hides; nothing set up is undone. */function Labs() {const { data, chooseExperiment } = useExperiments();const askFirst = useFlag("spaces_ask_first_home");+ const thisMacOk = useThisMacConfirmed();const rows = (data?.page?.sections.flatMap((s) => s.rows) ?? []).filter((r) => LABS.has(r.id));const note: Record<string, string> = {"experiment:cua_volume": "Memory and files your agents share across every Space.",@@ -136,6 +146,13 @@ function Labs() {description="Home asks what you want done, then does it on a fresh computer you can watch. On this device only."onChoose={(_, option) => setFlagOverride("spaces_ask_first_home", option === "on")}/>+ {askFirst ? (+ <CoreSettingsRow+ row={thisMacAskRow(!thisMacOk)}+ description="Before a task works directly on this Mac, with your files and apps. Turn it on to be asked again."+ onChoose={(_, option) => setThisMacConfirmed(option === "off")}+ />+ ) : null}{rows.map((r) => (<CoreSettingsRowkey={r.id}diff --git a/apps/cua-spaces-web/src/lib/ask-first.test.ts b/apps/cua-spaces-web/src/lib/ask-first.test.tsindex 5ca6a29ec7..1b192a570e 100644--- a/apps/cua-spaces-web/src/lib/ask-first.test.ts+++ b/apps/cua-spaces-web/src/lib/ask-first.test.ts@@ -12,7 +12,11 @@ import {askTasks,currentWhere,defaultWhere,- HOST_TARGET_ERROR,+ HOST_NOT_SHARED,+ hostSpaceId,+ setThisMacConfirmed,+ thisMacConfirmed,+ thisMacConfirmText,mostUsedAgent,orderTasks,pickableSpaces,@@ -92,6 +96,7 @@ const row = (id: string, more: Partial<Space> = {}): Space => ({ id, name: id, oconst thisMac = row("this-mac", { name: "This computer", os: "macos", status: "local", provider: "local" });const LINUX: NewKind = { os: "linux", note: "Free.", blocked: null };const MAC: NewKind = { os: "macos", note: "Free.", blocked: null };+const shared = { configured: true, mode: "relay" as const, machineId: "m-ada-mbp", sharing: true, shareDesktop: true };describe("where a task runs", () => {it("maps each pick to what agents.start is pointed at", () => {@@ -100,20 +105,31 @@ describe("where a task runs", () => {// A local Space and a cloud Space are passed by their own ids.expect(taskTarget({ kind: "space", space: row("local:aurora", { provider: "local" }) })).toEqual({ kind: "space", spaceId: "local:aurora" });expect(taskTarget({ kind: "space", space: row("cloud:ci-box", { provider: "direct", cloud: "aws" }) })).toEqual({ kind: "space", spaceId: "cloud:ci-box" });- expect(taskTarget({ kind: "space", space: row("relay:mac-mini/qa-windows", { provider: "relay", host: "mac-mini" }) })).toEqual({ kind: "space", spaceId: "relay:mac-mini/qa-windows" });- // This Mac's own desktop (and another machine's) is never passed as a Space id.+ // This Mac (its own row, or the picker's This Mac) starts on its host Space id.+ expect(taskTarget({ kind: "this-mac" })).toEqual({ kind: "host" });expect(taskTarget({ kind: "space", space: thisMac })).toEqual({ kind: "host" });- expect(taskTarget({ kind: "space", space: row("relay:96fedb7e1be65c3d", { provider: "relay" }) })).toEqual({ kind: "host" });+ });++ it("finds this Mac's own Space id from its host service", () => {+ expect(hostSpaceId(shared)).toBe("relay:m-ada-mbp");+ expect(hostSpaceId({ ...shared, mode: "direct", machineId: null, directUrl: "http://10.0.0.5:3211" })).toBe("direct:10.0.0.5:3211");+ // Not set up, not sharing, or not sharing its desktop: no Space id, so the start says how to fix it.+ expect(hostSpaceId(null)).toBeNull();+ expect(hostSpaceId({ ...shared, configured: false })).toBeNull();+ expect(hostSpaceId({ ...shared, sharing: false })).toBeNull();+ expect(hostSpaceId({ ...shared, shareDesktop: false })).toBeNull();});it("retries on the task's own computer, or makes a new one", () => {- expect(retryTarget({ spaceId: null, os: "linux" }, [])).toEqual({ kind: "create", os: "linux" });- expect(retryTarget({ spaceId: "local:aurora", os: "linux" }, [row("local:aurora")])).toEqual({ kind: "space", spaceId: "local:aurora" });- expect(retryTarget({ spaceId: "this-mac", os: "macos" }, undefined)).toEqual({ kind: "host" });+ expect(retryTarget({ spaceId: null, os: "linux" })).toEqual({ kind: "create", os: "linux" });+ expect(retryTarget({ spaceId: "local:aurora", os: "linux" })).toEqual({ kind: "space", spaceId: "local:aurora" });+ expect(retryTarget({ spaceId: "relay:m-ada-mbp", os: "macos", onHost: true })).toEqual({ kind: "host" });+ // A task from before: the pseudo-id now starts on this Mac's Space id.+ expect(retryTarget({ spaceId: "this-mac", os: "macos" })).toEqual({ kind: "host" });});- it("never offers this Mac's own desktop, or a Space that isn't on", () => {- const spaces = [thisMac, row("local:aurora"), row("local:off", { power: { control: "stop", off: true } as Space["power"] }), row("relay:96fedb7e1be65c3d", { provider: "relay" })];+ it("lists running Spaces; this Mac has its own row in the picker", () => {+ const spaces = [thisMac, row("local:aurora"), row("local:off", { power: { control: "stop", off: true } as Space["power"] })];expect(pickableSpaces(spaces).map((s) => s.id)).toEqual(["local:aurora"]);});@@ -121,7 +137,6 @@ describe("where a task runs", () => {expect(defaultWhere([MAC, LINUX])).toEqual({ kind: "new", os: "linux" });expect(defaultWhere([])).toEqual({ kind: "new", os: "linux" });expect(defaultWhere([{ ...LINUX, blocked: "Needs Docker" }, MAC])).toEqual({ kind: "new", os: "macos" });- // Running Spaces, this Mac included, never change the default.expect(currentWhere(null, [LINUX, MAC], [row("local:aurora")])).toEqual({ kind: "new", os: "linux" });});@@ -129,10 +144,24 @@ describe("where a task runs", () => {const aurora = row("local:aurora");expect(currentWhere({ kind: "space", space: aurora }, [LINUX], [aurora])).toEqual({ kind: "space", space: aurora });expect(currentWhere({ kind: "space", space: aurora }, [LINUX], [])).toEqual({ kind: "new", os: "linux" });- expect(currentWhere({ kind: "space", space: thisMac }, [LINUX], pickableSpaces([thisMac]))).toEqual({ kind: "new", os: "linux" });+ expect(currentWhere({ kind: "this-mac" }, [LINUX], [])).toEqual({ kind: "this-mac" });expect(currentWhere({ kind: "new", os: "macos" }, [LINUX, MAC], [])).toEqual({ kind: "new", os: "macos" });expect(currentWhere({ kind: "new", os: "windows" }, [LINUX], [])).toEqual({ kind: "new", os: "linux" });});++ it("remembers the answer to Work on this Mac? on this device until Settings resets it", () => {+ expect(thisMacConfirmed()).toBe(false);+ setThisMacConfirmed(true);+ expect(thisMacConfirmed()).toBe(true);+ expect(localStorage.getItem("cua.askFirst.thisMacOk")).toBe("1");+ setThisMacConfirmed(false);+ expect(thisMacConfirmed()).toBe(false);+ });++ it("says plainly what working on this Mac means", () => {+ expect(thisMacConfirmText("Codex").description).toContain("Codex will work directly on this Mac, with your files and apps. It can't be undone by throwing the computer away.");+ expect(thisMacConfirmText("Codex").description).toContain("doesn't ask before each step");+ });});describe("a start that failed", () => {@@ -143,9 +172,8 @@ describe("a start that failed", () => {});it("says what went wrong in plain words, with one thing to do", () => {- const thisMacView = startErrorView(CORE_NOT_FOUND, "Codex");- expect(thisMacView).toMatchObject({ title: "Agents can't work on this Mac itself", action: "change-computer", retry: false });- expect(startErrorView(HOST_TARGET_ERROR, "Codex").title).toBe("Agents can't work on this Mac itself");+ expect(startErrorView(CORE_NOT_FOUND, "Codex")).toMatchObject({ title: "Couldn't start on this Mac", action: "retry", retry: true });+ expect(startErrorView(HOST_NOT_SHARED, "Codex")).toMatchObject({ title: "This Mac isn't set up for tasks yet", action: "set-up-host", retry: true });expect(startErrorView('Space "local:gone" (use its id, such as local:<name> or cloud:<name>, or add it with add_space) not found', "Codex")).toMatchObject({title: "Couldn't find that computer",body: "It may have been deleted or renamed. Pick another one.",@@ -159,9 +187,9 @@ describe("a start that failed", () => {});it("never shows the core's jargon in the headline or the line under it", () => {- for (const raw of [CORE_NOT_FOUND, "Space \"x\" not found", "boom", "OPENAI_API_KEY is not set"]) {+ for (const raw of [CORE_NOT_FOUND, HOST_NOT_SHARED, 'Space "x" not found', "boom", "OPENAI_API_KEY is not set"]) {const v = startErrorView(raw, "Codex");- expect(`${v.title} ${v.body}`).not.toMatch(/add_space|local:<|cloud:<|this-mac|API_KEY/);+ expect(`${v.title} ${v.body}`).not.toMatch(/add_space|local:<|cloud:<|this-mac|API_KEY|host service/);}});});diff --git a/apps/cua-spaces-web/src/lib/ask-first.ts b/apps/cua-spaces-web/src/lib/ask-first.tsindex 63677f767d..94a0246aa7 100644--- a/apps/cua-spaces-web/src/lib/ask-first.ts+++ b/apps/cua-spaces-web/src/lib/ask-first.ts@@ -14,7 +14,7 @@import { useSyncExternalStore } from "react";-import type { AgentRunStatus, Space, SpaceOs, TranscriptItem } from "@/bridge";+import type { AgentRunStatus, HostStatus, Space, SpaceOs, TranscriptItem } from "@/bridge";import { isMachineDesktop, spaceState } from "./spaces";@@ -42,6 +42,8 @@ export interface AskTask {transcript: TranscriptItem[] | null;/** The status the run last had, for a thrown-away task's line. */lastStatus: AgentRunStatus | null;+ /** It runs on this Mac itself (its own Space id is in `spaceId`): nothing to throw away. */+ onHost?: boolean;}const KEY = "cua.askFirst.tasks";@@ -150,36 +152,56 @@ export function taskTitle(prompt: string, max = 80): string {return [...line].length <= max ? line : `${[...line].slice(0, max - 1).join("").trimEnd()}…`;}-/** Where the job runs, as picked: a new computer of a kind on this Mac, or a Space you already have. */-export type TaskWhere = { kind: "new"; os: SpaceOs } | { kind: "space"; space: Space };+/** Where the job runs, as picked: a new computer of a kind on this Mac, a Space you already have, or this Mac itself. */+export type TaskWhere = { kind: "new"; os: SpaceOs } | { kind: "space"; space: Space } | { kind: "this-mac" };/**- * What `agents.start` is pointed at. The core's `agent_start` only runs in a- * Space (a `local:`, `cloud:`, `direct:` or `relay:` id), auto-approved- * because "the Space is the sandbox". A machine's own desktop (this Mac's- * `this-mac` row, or another of your machines sharing its screen) is not a- * Space: the core can't resolve it, and running an auto-approved agent on- * a real computer would break the promise that yours stays untouched. So- * that target is refused here, before anything is called.+ * What `agents.start` is pointed at. The core's `agent_start` only takes a+ * Space id (`local:`, `cloud:`, `direct:`, `relay:`), so this Mac (the+ * `this-mac` row) is first turned into its own Space id: the one its host+ * service shares it as (`hostSpaceId`), the same id `cua mcp` treats as+ * This Mac. The person confirms once that the agent works on their own+ * files and apps.*/export type TaskTarget = { kind: "create"; os: SpaceOs } | { kind: "space"; spaceId: string } | { kind: "host" };/** The id of this Mac's own row in the Spaces list. */export const THIS_MAC_ID = "this-mac";-/** The raw error kept on a task that was pointed at a machine's own desktop. */-export const HOST_TARGET_ERROR = `${THIS_MAC_ID}: agents run in a Space, not on a computer's own desktop`;+/** The raw error kept on a task for this Mac when its host service doesn't share it (no Space id to start in). */+export const HOST_NOT_SHARED = `${THIS_MAC_ID}: this Mac isn't shared by its host service, so it has no Space id to start in`;++/**+ * This Mac's own Space id, from its host service (`host.status`): the relay+ * machine (`relay:<machine>`) or the direct address (`direct:<host:port>`)+ * it shares its desktop on. Null when it isn't set up or doesn't share its+ * desktop.+ */+export function hostSpaceId(status: Pick<HostStatus, "configured" | "mode" | "machineId" | "directUrl" | "sharing" | "shareDesktop"> | null | undefined): string | null {+ if (!status?.configured || !status.sharing || status.shareDesktop === false) return null;+ if (status.mode === "relay" && status.machineId) return `relay:${status.machineId}`;+ if (status.mode === "direct" && status.directUrl) {+ try {+ return `direct:${new URL(status.directUrl).host}`;+ } catch {+ return null;+ }+ }+ return null;+}export function taskTarget(where: TaskWhere): TaskTarget {if (where.kind === "new") return { kind: "create", os: where.os };- return isMachineDesktop(where.space) ? { kind: "host" } : { kind: "space", spaceId: where.space.id };+ if (where.kind === "this-mac" || where.space.id === THIS_MAC_ID) return { kind: "host" };+ return { kind: "space", spaceId: where.space.id };}+export const whereOs = (where: TaskWhere): SpaceOs => (where.kind === "new" ? where.os : where.kind === "space" ? where.space.os : "macos");+/** A kept task's target, for Try again: its computer if it has one (the row, when listed, decides), else a new one. */-export function retryTarget(task: Pick<AskTask, "spaceId" | "os">, spaces: readonly Space[] | undefined): TaskTarget {+export function retryTarget(task: Pick<AskTask, "spaceId" | "os" | "onHost">): TaskTarget {+ if (task.onHost || task.spaceId === THIS_MAC_ID) return { kind: "host" };if (!task.spaceId) return { kind: "create", os: task.os };- const row = spaces?.find((s) => s.id === task.spaceId);- if (task.spaceId === THIS_MAC_ID || (row && isMachineDesktop(row))) return { kind: "host" };return { kind: "space", spaceId: task.spaceId };}@@ -190,7 +212,7 @@ export interface NewKind {blocked: string | null;}-/** The computers you already have that a job can use: running Spaces, never a machine's own desktop. */+/** The Spaces you already have that a job can use: running ones, not a machine's own desktop (this Mac has its own row). */export function pickableSpaces(spaces: readonly Space[] | undefined): Space[] {return (spaces ?? []).filter((s) => !isMachineDesktop(s) && spaceState(s) === "running");}@@ -202,8 +224,9 @@ export function defaultWhere(kinds: readonly NewKind[]): TaskWhere {return { kind: "new", os };}-/** The pick if it's still offered, else the default (a picked Space that went away, or this Mac's own desktop, falls back). */+/** The pick if it's still offered, else the default (a picked Space that went away falls back). */export function currentWhere(picked: TaskWhere | null, kinds: readonly NewKind[], spaces: readonly Space[]): TaskWhere {+ if (picked?.kind === "this-mac") return picked;if (picked?.kind === "new" && kinds.some((k) => k.os === picked.os && !k.blocked)) return picked;if (picked?.kind === "space") {const row = spaces.find((s) => s.id === picked.space.id);@@ -212,8 +235,50 @@ export function currentWhere(picked: TaskWhere | null, kinds: readonly NewKind[]return defaultWhere(kinds);}+const THIS_MAC_OK_KEY = "cua.askFirst.thisMacOk";+const okListeners = new Set<() => void>();++/** Whether the person said once, on this device, that tasks may work on this Mac itself. */+export function thisMacConfirmed(): boolean {+ try {+ return globalThis.localStorage?.getItem(THIS_MAC_OK_KEY) === "1";+ } catch {+ return false;+ }+}++/** Remembers (or forgets, from Settings) that tasks may work on this Mac itself. */+export function setThisMacConfirmed(ok: boolean): void {+ try {+ if (ok) globalThis.localStorage?.setItem(THIS_MAC_OK_KEY, "1");+ else globalThis.localStorage?.removeItem(THIS_MAC_OK_KEY);+ } catch {+ // Asked again next time.+ }+ for (const l of [...okListeners]) l();+}++export function useThisMacConfirmed(): boolean {+ return useSyncExternalStore(+ (l) => {+ okListeners.add(l);+ return () => okListeners.delete(l);+ },+ thisMacConfirmed,+ thisMacConfirmed,+ );+}++/** What the person is told, once, before a task works on this Mac itself. */+export function thisMacConfirmText(agent: string): { title: string; description: string } {+ return {+ title: "Work on this Mac?",+ description: `${agent} will work directly on this Mac, with your files and apps. It can't be undone by throwing the computer away. ${agent} doesn't ask before each step here, the same as on a new computer.`,+ };+}+/** What a failed start offers in its card. */-export type StartErrorAction = "change-computer" | "add-key" | "retry";+export type StartErrorAction = "change-computer" | "add-key" | "retry" | "set-up-host";export interface StartErrorView {title: string;@@ -231,13 +296,16 @@ export interface StartErrorView {*/export function startErrorView(raw: string, agent: string): StartErrorView {const e = raw.toLowerCase();- if (e.includes(THIS_MAC_ID))+ if (e.includes("isn't shared"))return {- title: "Agents can't work on this Mac itself",- body: `${agent} gets its own computer, so yours stays untouched. Pick a new computer or one you already have.`,- action: "change-computer",- retry: false,+ title: "This Mac isn't set up for tasks yet",+ body: "Turn on sharing for this Mac on the Computers page, then try again. Or pick another computer.",+ action: "set-up-host",+ retry: true,};+ // A task from before this Mac was turned into its own Space id: trying again now works.+ if (e.includes(`"${THIS_MAC_ID}"`))+ return { title: "Couldn't start on this Mac", body: "Try again to start it on this Mac, or pick another computer.", action: "retry", retry: true };if (/cloud has ended/.test(e))return { title: "That computer is no longer available", body: "Cua Cloud has ended. Pick a computer on this Mac instead.", action: "change-computer", retry: false };if (/more than one|ambiguous/.test(e))diff --git a/apps/cua-spaces-web/src/routes/agents/index.tsx b/apps/cua-spaces-web/src/routes/agents/index.tsxindex 1b75450f70..9e2a1838fc 100644--- a/apps/cua-spaces-web/src/routes/agents/index.tsx+++ b/apps/cua-spaces-web/src/routes/agents/index.tsx@@ -144,7 +144,7 @@ function Overview({ data, onSelect }: { data: AgentsData; onSelect: (s: AgentsSe<divkey={`${r.spaceId}/${r.runId}`}data-waiting-run={r.runId}- className="flex min-h-12 items-center gap-3 border-l-2 border-l-warning px-4 py-3"+ className="flex min-h-12 items-center gap-3 px-4 py-3"><HarnessMark agent={r.agent} name={r.harnessName} /><div className="min-w-0 flex-1">