Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

fix(spaces): Ready only once Cua Driver runs with its permissions (CUA-3660) (#6761)

cua-agents[bot]1945040338f6
diff --git a/apps/cua-spaces-web/src/__tests__/first-run.test.tsx b/apps/cua-spaces-web/src/__tests__/first-run.test.tsx
index 5dd1c6f9e6..d7429cf00c 100644
--- a/apps/cua-spaces-web/src/__tests__/first-run.test.tsx
+++ b/apps/cua-spaces-web/src/__tests__/first-run.test.tsx
@@ -40,7 +40,7 @@ afterEach(() => {
type Calls = { op: string; args: unknown }[];
-async function mount(opts: { signedIn?: boolean; host?: (h: HostStatus) => HostStatus; local?: (l: NonNullable<NewSpaceOptions["local"]>) => NewSpaceOptions["local"]; agents?: (rows: AgentSetupRow[]) => AgentSetupRow[]; cli?: "missing" | "local"; demo?: object; intercept?: (op: string, args: unknown) => unknown } = {}) {
+async function mount(opts: { signedIn?: boolean; host?: (h: HostStatus) => HostStatus; local?: (l: NonNullable<NewSpaceOptions["local"]>) => NewSpaceOptions["local"]; agents?: (rows: AgentSetupRow[]) => AgentSetupRow[]; cli?: "missing" | "local"; demo?: object; permissionsOff?: boolean; intercept?: (op: string, args: unknown) => unknown } = {}) {
await testCore();
const calls: Calls = [];
let lastRows: AgentSetupRow[] | null = null;
@@ -55,6 +55,12 @@ async function mount(opts: { signedIn?: boolean; host?: (h: HostStatus) => HostS
},
answer: (op, out) => {
if (op === "host.status" && opts.host) return opts.host(out as HostStatus);
+ // Cua Spaces already has both permissions, so Cua Driver runs (permissionsOff: a Mac that hasn't allowed them yet).
+ if (!opts.permissionsOff && op === "driver.permissions" && out) {
+ const p = out as { appName: string; permissions: { granted: boolean }[] };
+ return { ...p, permissions: p.permissions.map((x) => ({ ...x, granted: true })) };
+ }
+ if (!opts.permissionsOff && op === "driver.status" && out && (out as { state: string }).state === "needs-permission") return { ...(out as object), state: "ready" };
// The agents found here as the test sets them up (Connect still adds Cua to them).
if ((op === "agents.setup" || op === "agents.signIn" || op === "agents.configure") && opts.agents) {
lastRows = opts.agents(out as AgentSetupRow[]);
@@ -133,7 +139,7 @@ const noAgents = (rows: AgentSetupRow[]) => rows.map((r) => ({ ...r, installed:
describe.skipIf(!wasmBuilt)("the first run (real route, wasm core)", () => {
it("asks once, naming the apps found, and connects nothing until Set up", async () => {
- const calls = await mount();
+ const calls = await mount({ permissionsOff: true });
await waitFor(() => expect(heading()).toBe("Your computers, shared by your team and its agents."));
click("[data-onboarding-primary]");
await waitFor(() => expect(heading()).toBe("Let your 6 coding apps use Cua?"));
@@ -149,7 +155,18 @@ describe.skipIf(!wasmBuilt)("the first run (real route, wasm core)", () => {
click("[data-first-run-set-up]");
// The same Connect as Settings, the CLI and MCP: Cua's tools and the app's sign-in, one app at a time.
await waitFor(() => expect(calls.filter((c) => c.op === "agents.connect").map((c) => (c.args as { agents: string[] }).agents)).toHaveLength(5));
- await waitFor(() => expect(heading()).toBe("Your 6 coding apps can use Cua."));
+ // Connected, but not "Ready" while Cua Spaces is missing the two permissions Cua Driver runs with.
+ await waitFor(() => expect(heading()).toBe("Almost ready."));
+ expect(document.querySelector("[data-first-run-prompt]")).toBeNull();
+ for (const id of ["screen", "accessibility"]) {
+ const row = await waitFor(() => {
+ const r = document.querySelector<HTMLElement>(`[data-app-permission="${id}"]:not([data-granted])`);
+ expect(r).not.toBeNull();
+ return r!;
+ });
+ fireEvent.click([...row.querySelectorAll("button")].find((b) => b.textContent === "Allow")!);
+ }
+ await waitFor(() => expect(heading()).toBe("Your 6 coding apps can use Cua."), { timeout: 8000 });
expect(document.querySelector("[data-first-run-prompt]")!.textContent).toBe("Reproduce the crash from issue #4821 on a fresh Windows 11 Space and show me a recording.");
expect(document.body.textContent).toMatch(/restart it first/);
expect(connectedAppsState().auto).toBe(true);
diff --git a/apps/cua-spaces-web/src/components/driver/driver-page.tsx b/apps/cua-spaces-web/src/components/driver/driver-page.tsx
index b20443e57e..ca98d7c17d 100644
--- a/apps/cua-spaces-web/src/components/driver/driver-page.tsx
+++ b/apps/cua-spaces-web/src/components/driver/driver-page.tsx
@@ -5,7 +5,7 @@ import { Link } from "@tanstack/react-router";
import { CheckIcon, ChevronRightIcon, MousePointer2Icon } from "lucide-react";
import { useEffect, useRef, useState } from "react";
-import { pointerChange, pointerSettings, POINTER_STYLES, useDriver, useDriverMachines, type DriverApp, type DriverHook, type DriverStatus, type PointerSettings } from "@/bridge";
+import { pointerChange, pointerSettings, POINTER_STYLES, useBridge, useDriver, useDriverMachines, type DriverApp, type DriverHook, type DriverStatus, type PointerSettings } from "@/bridge";
import { useAppPermissions } from "@/bridge/app-permissions";
import { AppMarkImage } from "@/components/agents/harness-mark";
import { AppPermissionList } from "@/components/app-permissions";
@@ -18,7 +18,7 @@ import { Segmented } from "@/components/ui/segmented";
import { Select } from "@/components/ui/select";
import { Switch } from "@/components/ui/switch";
import { toast, toastError } from "@/components/ui/toast";
-import { driverUsesAppPermissions } from "@/lib/app-permissions";
+import { driverUsesAppPermissions, repairOutcome } from "@/lib/app-permissions";
import { cn } from "@/lib/utils";
import { driverLine, markFor, stateText, testText, versionText } from "./copy";
import { PointerPreview } from "./pointer-preview";
@@ -75,6 +75,7 @@ function DriverBody({ driver, status }: { driver: DriverHook; status: DriverStat
/* ---- The top: keycap, the line, state, version, actions, preview ---------------- */
function Hero({ driver, status, settings }: { driver: DriverHook; status: DriverStatus; settings: PointerSettings }) {
+ const bridge = useBridge();
const [busy, setBusy] = useState<"test" | "setup" | null>(null);
const run = async (what: "test" | "setup", work: () => Promise<void>) => {
setBusy(what);
@@ -100,9 +101,12 @@ function Hero({ driver, status, settings }: { driver: DriverHook; status: Driver
return undefined;
});
if (after === undefined) return;
- const t = after?.lastTest;
- if (t && !t.passed) toast("Set up, but the test didn't pass", { description: t.failure ?? undefined, type: "error" });
- else toast("Cua Driver is ready", { description: "Start a new Claude Code or Codex session to use it." });
+ if (!after) return;
+ const outcome = repairOutcome(after);
+ if (outcome.kind === "ok") toast(outcome.title, { description: outcome.description });
+ else toast(outcome.title, { description: outcome.description, type: "error" });
+ // A switch that's off: open its guide now, so Repair leaves one thing to do.
+ if (outcome.kind === "permission" && outcome.settingsUrl) await bridge.data?.call("host.openSettings", { url: outcome.settingsUrl }).catch(toastError("Couldn't open System Settings"));
});
const ok = status.state === "ready";
const tested = testText(status);
diff --git a/apps/cua-spaces-web/src/lib/__tests__/driver-readiness.test.ts b/apps/cua-spaces-web/src/lib/__tests__/driver-readiness.test.ts
new file mode 100644
index 0000000000..64f3d2e1e0
--- /dev/null
+++ b/apps/cua-spaces-web/src/lib/__tests__/driver-readiness.test.ts
@@ -0,0 +1,56 @@
+// SPDX-License-Identifier: FSL-1.1-MIT
+// Copyright (c) 2026 Cua AI, Inc.
+
+import { describe, expect, it } from "vitest";
+
+import { driverReadiness, readinessLede, repairOutcome } from "../app-permissions";
+
+const on = { available: true, allGranted: true };
+const off = { available: true, allGranted: false };
+const perms = (screen: boolean, accessibility: boolean) => [
+ { id: "screen" as const, granted: screen, settingsUrl: "x-apple.systempreferences:screen" },
+ { id: "accessibility" as const, granted: accessibility, settingsUrl: "x-apple.systempreferences:ax" },
+];
+
+describe("Ready only after Cua Driver runs with its permissions", () => {
+ it("waits for the permissions first", () => {
+ expect(driverReadiness({ permissions: off, driver: { state: "ready" } })).toBe("permissions");
+ });
+ it("waits for a running driver", () => {
+ expect(driverReadiness({ permissions: on, driver: { state: "starting" } })).toBe("starting");
+ expect(driverReadiness({ permissions: on, driver: { state: "failed" } })).toBe("driver");
+ expect(driverReadiness({ permissions: on, driver: { state: "stopped" } })).toBe("driver");
+ });
+ it("is ready with both on and the driver answering", () => {
+ expect(driverReadiness({ permissions: on, driver: { state: "ready" } })).toBe("ready");
+ });
+ it("has nothing to wait for where there is no driver or no permission", () => {
+ expect(driverReadiness({ permissions: on, driver: null })).toBe("ready");
+ expect(driverReadiness({ permissions: { available: false, allGranted: false }, driver: { state: "failed" } })).toBe("ready");
+ });
+ it("says what is missing in plain words", () => {
+ expect(readinessLede("permissions", "Cua Spaces", null)).toContain("two switches");
+ expect(readinessLede("driver", "Cua Spaces", "Cua Driver didn't start: boom")).toBe("Cua Driver didn't start: boom Repair starts it again.");
+ });
+});
+
+describe("Repair outcomes", () => {
+ const base = { state: "ready", appName: "Cua Spaces", permissions: perms(true, true), lastError: null, lastTest: { passed: true, failure: null } };
+ it("ok when running and the test passed", () => {
+ expect(repairOutcome(base).kind).toBe("ok");
+ });
+ it("opens the guide for the first missing permission", () => {
+ const out = repairOutcome({ ...base, state: "needs-permission", permissions: perms(false, true), lastTest: { passed: false, failure: "Screen Recording is off for Cua Spaces" } });
+ expect(out.kind).toBe("permission");
+ expect(out.settingsUrl).toBe("x-apple.systempreferences:screen");
+ expect(out.description).toContain("turn on Cua Spaces");
+ });
+ it("fails with the reason and one next step", () => {
+ const out = repairOutcome({ ...base, state: "failed", lastError: "Cua Driver didn't start: exit 1" });
+ expect(out.kind).toBe("failed");
+ expect(out.description).toBe("Cua Driver didn't start: exit 1. Quit and reopen Cua Spaces, then try Repair again.");
+ });
+ it("says so when agents are paused", () => {
+ expect(repairOutcome({ ...base, state: "paused" }).title).toBe("Cua Driver is off");
+ });
+});
diff --git a/apps/cua-spaces-web/src/lib/app-permissions.ts b/apps/cua-spaces-web/src/lib/app-permissions.ts
index b99679b2e3..3533fc3c3f 100644
--- a/apps/cua-spaces-web/src/lib/app-permissions.ts
+++ b/apps/cua-spaces-web/src/lib/app-permissions.ts
@@ -49,3 +49,79 @@ export function permissionsStepView(input: { appName: string; allGranted: boolea
primary: input.allGranted ? { label: "Continue", white: true } : { label: "Later", white: false },
};
}
+
+/** What the first run's "Ready" waits for: Cua Driver running, with both permissions. */
+export type DriverReadiness = "ready" | "permissions" | "starting" | "driver";
+
+/**
+ * Whether the coding apps can really use Cua Driver yet. A host with no
+ * permissions to give or no driver (Windows, Linux, an older app) has
+ * nothing to wait for. A driver the person paused is their choice.
+ */
+export function driverReadiness(input: { permissions: { available: boolean; allGranted: boolean }; driver: { state: string } | null }): DriverReadiness {
+ if (!input.driver || !input.permissions.available) return "ready";
+ if (!input.permissions.allGranted) return "permissions";
+ switch (input.driver.state) {
+ case "ready":
+ case "paused":
+ return "ready";
+ case "starting":
+ return "starting";
+ // A switch the driver hasn't noticed yet: the host restarts it once both are on.
+ case "needs-permission":
+ return "starting";
+ default:
+ return "driver";
+ }
+}
+
+/** The words under "Almost ready" while something is missing. */
+export function readinessLede(readiness: Exclude<DriverReadiness, "ready">, appName: string, problem: string | null): string {
+ switch (readiness) {
+ case "permissions":
+ return `One more step: turn on two switches for ${appName}, so Cua Driver can see and use apps. Allow opens System Settings.`;
+ case "starting":
+ return "Cua Driver is starting. This takes a few seconds.";
+ case "driver":
+ return `${problem ?? "Cua Driver isn't running."} Repair starts it again.`;
+ }
+}
+
+export interface RepairOutcome {
+ /** `ok`: working. `permission`: a switch is off, so open its guide. `failed`: show why. */
+ kind: "ok" | "permission" | "failed";
+ title: string;
+ /** The plain reason and the one next step. */
+ description?: string;
+ /** The pane to open for `permission`. */
+ settingsUrl?: string | null;
+}
+
+/** What Repair and Set up tell the person once they have run, from the status they leave. */
+export function repairOutcome(after: {
+ state: string;
+ appName?: string | null;
+ permissions: { id: "screen" | "accessibility"; granted: boolean; settingsUrl: string | null }[];
+ lastError: string | null;
+ lastTest: { passed: boolean; failure: string | null } | null;
+}): RepairOutcome {
+ const app = after.appName ?? "Cua Spaces";
+ const missing = after.permissions.find((p) => !p.granted);
+ if (missing) {
+ const words = permissionWords(missing.id, app);
+ return {
+ kind: "permission",
+ title: "One switch is still off",
+ description: `${words.title} is off. In System Settings, turn on ${app}, then come back.`,
+ settingsUrl: missing.settingsUrl,
+ };
+ }
+ if (after.state === "ready" && (!after.lastTest || after.lastTest.passed)) {
+ return { kind: "ok", title: "Cua Driver is ready", description: "Start a new Claude Code or Codex session to use it." };
+ }
+ if (after.state === "paused") {
+ return { kind: "failed", title: "Cua Driver is off", description: "Agents can't use apps on this Mac. Turn on Let agents use apps, then Repair." };
+ }
+ const reason = after.lastError ?? after.lastTest?.failure ?? "Cua Driver isn't answering.";
+ return { kind: "failed", title: "Cua Driver still isn't working", description: `${reason.replace(/\.$/, "")}. Quit and reopen ${app}, then try Repair again.` };
+}
diff --git a/apps/cua-spaces-web/src/routes/onboarding/index.tsx b/apps/cua-spaces-web/src/routes/onboarding/index.tsx
index 28d85f0c3f..fa3c45bbf2 100644
--- a/apps/cua-spaces-web/src/routes/onboarding/index.tsx
+++ b/apps/cua-spaces-web/src/routes/onboarding/index.tsx
@@ -5,9 +5,11 @@ import { createFileRoute, redirect, useNavigate } from "@tanstack/react-router";
import { ArrowLeftIcon, CheckIcon, CopyIcon, ExternalLinkIcon } from "lucide-react";
import { useEffect, useState, type ReactNode } from "react";
-import { useAgentKeys, useBridge, useFirstRun, useNewOnboarding, useSpaces, type FirstRunArt, type FirstRunCredential, type FirstRunExtraView, type FirstRunHook, type FirstRunRow, type FirstRunView } from "@/bridge";
+import { useAgentKeys, useBridge, useDriver, useFirstRun, useNewOnboarding, useSpaces, type FirstRunArt, type FirstRunCredential, type FirstRunExtraView, type FirstRunHook, type FirstRunRow, type FirstRunView } from "@/bridge";
+import { useAppPermissions } from "@/bridge/app-permissions";
import { readSavedOnboarding, writeSavedOnboarding } from "@/bridge/onboarding";
import { AddAgentSheet } from "@/components/add-agent/add-agent-sheet";
+import { AppPermissionList } from "@/components/app-permissions";
import { APP_MARKS, AppMarkImage } from "@/components/agents/harness-mark";
import { CuaLogo } from "@/components/cua-logo";
import { NewFirstRun } from "@/components/first-run-new/first-run-new";
@@ -21,6 +23,7 @@ import { Snippet } from "@/components/settings/snippet";
import { KeySheet } from "@/components/agents/key-sheet";
import { setConnectedAppsState, useConnectedAppsState } from "@/hooks/use-connected-apps";
import { BY_HAND, failureText, getItUrl } from "@/lib/connected-apps";
+import { driverReadiness, readinessLede } from "@/lib/app-permissions";
import { cn } from "@/lib/utils";
import { usePrepare } from "@/lib/prepare/store";
@@ -328,6 +331,14 @@ function Connect({ fr, view }: { fr: FirstRunHook; view: FirstRunView }) {
const none = rows.length === 0 && !looking;
const pending = rows.filter((a) => !a.connected);
const ready = rows.filter((a) => a.connected);
+ // "Ready" waits for a Cua Driver that runs, with both permissions on (it uses Cua Spaces' own).
+ const everyAppConnected = rows.length > 0 && pending.length === 0;
+ const perms = useAppPermissions(everyAppConnected);
+ const driver = useDriver();
+ const [repairing, setRepairing] = useState(false);
+ // Until both have answered, nothing is "Ready" yet: no green check that flips back to "Almost ready".
+ const checking = perms.loading || driver.loading;
+ const readiness = !everyAppConnected ? "ready" : checking ? "starting" : driverReadiness({ permissions: perms, driver: driver.available ? driver.status : null });
const working = busy || rows.some((a) => a.note === "Connecting\u2026");
const failed = tried && !working ? pending : [];
const why = (agent: string, name: string) =>
@@ -423,9 +434,22 @@ function Connect({ fr, view }: { fr: FirstRunHook; view: FirstRunView }) {
}
const all = pending.length === 0;
+ const waiting = all && readiness !== "ready";
+ const repair = async () => {
+ setRepairing(true);
+ try {
+ await driver.setup();
+ } catch (e) {
+ toast("Couldn\u2019t repair Cua Driver", { description: e instanceof Error ? e.message : undefined, type: "error" });
+ } finally {
+ setRepairing(false);
+ }
+ };
// Up to three names read well in a heading; more are "your 5 coding apps" and the rows name them.
const phrase = (list: { name: string }[]) => (list.length <= 3 ? listNames(list.map((a) => a.name)) : `your ${list.length} coding apps`);
- const title = all
+ const title = waiting
+ ? "Almost ready."
+ : all
? sentence(`${phrase(rows)} can use Cua.`)
: failed.length
? `${ready.length ? sentence(`${phrase(ready)} can use Cua.`) + " " : ""}${sentence(`${phrase(failed)} ${failed.length === 1 ? "needs" : "need"} a hand.`)}`
@@ -433,10 +457,12 @@ function Connect({ fr, view }: { fr: FirstRunHook; view: FirstRunView }) {
return (
<Step id="connect" onBack={fr.back}>
- <div data-first-run-connect-state={all ? "done" : failed.length ? "failed" : "ask"}>
+ <div data-first-run-connect-state={waiting ? `waiting-${readiness}` : all ? "done" : failed.length ? "failed" : "ask"}>
<Heading>{title}</Heading>
<Lede>
- {all
+ {waiting
+ ? `${sentence(`${phrase(rows)} ${rows.length === 1 ? "is" : "are"} connected.`)} ${readinessLede(readiness as Exclude<typeof readiness, "ready">, perms.data?.appName ?? "Cua Spaces", driver.status?.lastError ?? null)}`
+ : all
? "If one of them is open, restart it first. Then try this:"
: failed.length
? failed.length === 1
@@ -444,7 +470,13 @@ function Connect({ fr, view }: { fr: FirstRunHook; view: FirstRunView }) {
: `Cua couldn\u2019t change their settings, so ${listNames(failed.map((a) => a.name))} can\u2019t use Cua yet.`
: "Then you can ask them for things like \u201cReproduce this bug on a fresh Windows machine.\u201d They create the Space, work in it and tell you what they found."}
</Lede>
- {all ? (
+ {waiting && readiness === "permissions" ? <AppPermissionList perms={perms} variant="settings" title="Allow Cua Driver" className="mt-6" /> : null}
+ {waiting && readiness === "driver" ? (
+ <Button variant="outline" size="sm" disabled={repairing} className="mt-6" onClick={() => void repair()} data-first-run-driver-repair="">
+ {repairing ? "Repairing…" : "Repair"}
+ </Button>
+ ) : null}
+ {all && !waiting ? (
<div className="mt-6 flex items-start gap-3 rounded-2xl border border-foreground/15 px-5 py-4" data-first-run-prompt="">
<p className="min-w-0 flex-1 text-[15px] leading-relaxed select-text">{FIRST_PROMPT}</p>
<button type="button" aria-label="Copy the prompt" onClick={copy} className="mt-0.5 text-muted-foreground hover:text-foreground">
@@ -462,7 +494,11 @@ function Connect({ fr, view }: { fr: FirstRunHook; view: FirstRunView }) {
<div className="text-[14px]">{a.name}</div>
{bad ? <div className="text-[13px] text-destructive">{why(a.agent, a.name)}</div> : null}
</div>
- {a.connected ? (
+ {a.connected && waiting ? (
+ <span className="shrink-0 text-[13px] text-muted-foreground" data-first-run-connected-waiting="">
+ Connected
+ </span>
+ ) : a.connected ? (
<span className="flex shrink-0 items-center gap-1 text-[13px] text-[#1f9d55] dark:text-[#4ade80]">
<CheckIcon className="size-3.5" /> Ready
</span>
@@ -481,8 +517,8 @@ function Connect({ fr, view }: { fr: FirstRunHook; view: FirstRunView }) {
<div className={ACTION_ROW}>
{all || failed.length ? (
<>
- <Primary label="Continue" onClick={() => void fr.act(c.primary.id)} />
- {all ? <Secondary label={copied ? "Copied" : "Copy the prompt"} onClick={copy} /> : <Secondary label="Add it by hand" onClick={() => setByHand(!byHand)} />}
+ <Primary label={waiting ? "Later" : "Continue"} onClick={() => void fr.act(c.primary.id)} />
+ {all && !waiting ? <Secondary label={copied ? "Copied" : "Copy the prompt"} onClick={copy} /> : <Secondary label="Add it by hand" onClick={() => setByHand(!byHand)} />}
</>
) : (
<>
@@ -514,7 +550,9 @@ function Connect({ fr, view }: { fr: FirstRunHook; view: FirstRunView }) {
</div>
) : null}
<p className="mt-4 max-w-[460px] text-[13px] text-muted-foreground" data-first-run-consent="">
- {all
+ {waiting
+ ? "Cua Driver uses the permissions you give Cua Spaces. You can also do this later on the Cua Driver page."
+ : all
? "Cua added itself to each app\u2019s settings and left everything else alone."
: failed.length
? `${listNames(ready.map((a) => a.name))} ${ready.length === 1 ? "is" : "are"} done. ${listNames(failed.map((a) => a.name))} can wait: Settings has the same button.`