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-web): Home's default line, first-run list, Continue on menu, demo desktops (CUA-3486) (#6535)

cua-agents[bot]f9279c51adcd
diff --git a/apps/cua-spaces-web/src/__tests__/first-run-new.test.tsx b/apps/cua-spaces-web/src/__tests__/first-run-new.test.tsx
index 4b572040da..2dc32025fd 100644
--- a/apps/cua-spaces-web/src/__tests__/first-run-new.test.tsx
+++ b/apps/cua-spaces-web/src/__tests__/first-run-new.test.tsx
@@ -112,6 +112,42 @@ describe("screen 2, an offline computer", () => {
});
});
+describe("screen 2, a long list", () => {
+ const many = (n: number) => Array.from({ length: n }, (_, i) => ({ id: `off-${i}`, name: `Old box ${i + 1}`, os: "linux", online: false, lastSeen: NOW / 1000 - 86400, current: false }));
+ const long = { ...base, machines: [...base.machines!, ...many(13)] };
+
+ it("folds offline computers into one row with their count, so the online ones and Continue stay in view", () => {
+ drawWhere(long);
+ const fold = document.querySelector<HTMLElement>("[data-new-run-offline-fold]")!;
+ // Gaming PC and the 13 old boxes.
+ expect(fold.textContent).toContain("14 offline");
+ expect(fold.getAttribute("aria-expanded")).toBe("false");
+ const ids = () => [...document.querySelectorAll<HTMLElement>("[data-new-run-computer]")].map((e) => e.dataset.newRunComputer);
+ expect(ids()).toEqual(["this", "mini", "build"]);
+ fireEvent.click(fold);
+ expect(fold.getAttribute("aria-expanded")).toBe("true");
+ expect(ids()).toHaveLength(3 + 14);
+ expect(document.querySelector("[data-new-run-computer=pc]")!.getAttribute("aria-disabled")).toBe("true");
+ fireEvent.click(fold);
+ expect(ids()).toEqual(["this", "mini", "build"]);
+ });
+
+ it("counts whatever is offline", () => {
+ expect(whereView({ ...base, machines: [...base.machines!, ...many(2)] }).offlineFold?.label).toBe("3 offline");
+ // One offline computer shows as itself.
+ expect(whereView(base).offlineFold).toBeNull();
+ expect(whereView({ ...base, machines: base.machines!.map((m) => ({ ...m, online: true })) }).offlineFold).toBeNull();
+ });
+
+ it("keeps Continue in a footer that sticks to the bottom of the window", () => {
+ drawWhere(long);
+ const footer = document.querySelector<HTMLElement>("[data-new-run-footer]")!;
+ expect(footer.className).toContain("sticky");
+ expect(footer.className).toContain("bottom-0");
+ expect(footer.contains(screen.getByRole("button", { name: "Continue" }))).toBe(true);
+ });
+});
+
describe("screen 2, signed out (after Skip for now)", () => {
it("shows this Mac not added yet with Add, 'Sign in to see your other computers', and no Add another computer", () => {
const onAddThis = vi.fn();
diff --git a/apps/cua-spaces-web/src/__tests__/pick-up.test.tsx b/apps/cua-spaces-web/src/__tests__/pick-up.test.tsx
index 78ad079bf3..d3f3c66c9b 100644
--- a/apps/cua-spaces-web/src/__tests__/pick-up.test.tsx
+++ b/apps/cua-spaces-web/src/__tests__/pick-up.test.tsx
@@ -9,9 +9,10 @@
import { cleanup, fireEvent, render, screen, waitFor } from "@testing-library/react";
import { afterEach, beforeEach, describe, expect, it } from "vitest";
-import { BridgeProvider, setFlagOverride, type HostStatus } from "@/bridge";
+import { BridgeProvider, setFlagOverride, type DataAdapter, type HostStatus } from "@/bridge";
import { createDemoAdapter } from "@/bridge/adapters/demo";
import { testCore, wasmBuilt } from "@/bridge/__tests__/testCore";
+import { ContinueOn } from "@/components/ask-first/imported-task";
import { PickUpWhereYouLeftOff, ReadyScreen } from "@/components/first-run-new/first-run-new";
import { readyView } from "@/lib/first-run-new";
import { addImportedTask, askTask, resetAskTasks, type AskTask } from "@/lib/ask-first";
@@ -77,6 +78,44 @@ describe("the new setup's Ready screen", () => {
});
});
+describe("Continue on", () => {
+ it("lists only your other computers that could run the chat, each once, and fits the window", async () => {
+ const demo = createDemoAdapter({ latencyMs: 1 });
+ const extra = [
+ { id: "browser-1", name: "Web browser", via: "relay", online: true, os: "web", current: false, device: true, limits: [] },
+ { id: "browser-2", name: "Web browser", via: "relay", online: true, os: "web", current: false, device: true, limits: [] },
+ ];
+ const adapter: DataAdapter = {
+ ...demo,
+ subscribe: (l) => demo.subscribe(l),
+ call: (async (op: string, args: never) => {
+ const out = await demo.call(op as never, args);
+ if (op !== "machines.list") return out;
+ const rows = out as { id: string }[];
+ // The Mac mini listed twice, plus two signed-in browsers.
+ return [...rows, rows.find((r) => r.id === "mac-mini")!, ...extra];
+ }) as DataAdapter["call"],
+ };
+ render(
+ <BridgeProvider adapter={adapter} core={await testCore()}>
+ <ContinueOn />
+ </BridgeProvider>,
+ );
+ fireEvent.click(await waitFor(() => q("[data-continue-on]")!));
+ await waitFor(() => expect(q("[data-continue-on-menu]")).not.toBeNull());
+ await waitFor(() => expect(document.querySelectorAll("[data-continue-on-other]").length).toBeGreaterThan(0));
+ const ids = [...document.querySelectorAll<HTMLElement>("[data-continue-on-other]")].map((e) => e.dataset.continueOnOther);
+ // Mac mini once, the Linux box; no browsers, and Studio PC is offline.
+ expect(ids).toEqual(["mac-mini", "linux-box"]);
+ expect(document.body.textContent).not.toContain("Web browser");
+ expect(q("[data-continue-on-offline]")?.textContent).toBe("1 more computer is offline.");
+ // It scrolls inside the room the window has rather than running off it.
+ const menu = q("[data-continue-on-menu]")!;
+ expect(menu.className).toContain("max-h-[min(480px,var(--available-height))]");
+ expect(menu.className).toContain("overflow-y-auto");
+ });
+});
+
describe.skipIf(!wasmBuilt)("a continued chat in Home", () => {
it("shows what was said, runs nothing, and resumes the agent's own session on send", { timeout: 30000 }, async () => {
const task = addImportedTask(KETTLE);
diff --git a/apps/cua-spaces-web/src/__tests__/spaces-tree.test.tsx b/apps/cua-spaces-web/src/__tests__/spaces-tree.test.tsx
index aebd8d6d16..9d5f1eb12d 100644
--- a/apps/cua-spaces-web/src/__tests__/spaces-tree.test.tsx
+++ b/apps/cua-spaces-web/src/__tests__/spaces-tree.test.tsx
@@ -216,6 +216,30 @@ describe.skipIf(!wasmBuilt)("Home with Spaces as a tree (Labs)", () => {
expect(q("[data-tree-fallback]")).toBeNull();
});
+ it("the demo's computers share their desktops, so Home starts on the Mac mini when it is the default", { timeout: 30000 }, async () => {
+ on();
+ await mountApp("/home", host([]));
+ await waitFor(() => expect(q("[data-ask-where]")?.textContent).toBe("Mac miniDefault"));
+ expect(q("[data-tree-fallback]")).toBeNull();
+ });
+
+ it("with the default offline, the next online computer is the one used, never contradicted by the line", { timeout: 30000 }, async () => {
+ on();
+ const resolved = {
+ space: "relay:mac-mini",
+ reason: "fallback",
+ defaultSpace: "relay:linux-box",
+ defaultOnline: false,
+ order: [step("relay:linux-box", "Linux box", false, "default"), step("relay:mac-mini", "Mac mini", true, "fallback"), step("relay:this-mac", "This Mac", true, "here")],
+ };
+ await mountApp("/home", host([], { offline: ["linux-box"], resolved }));
+ await waitFor(() => expect(q("[data-ask-where]")?.textContent).toBe("Mac mini"));
+ const line = await found("[data-tree-fallback]");
+ expect(line.textContent).toContain("Linux box, your default, is offline. This runs on Mac mini, the next computer that can take it. If none can, it runs on This Mac.");
+ expect(line.textContent).not.toContain("no other computer is online");
+ expect(qa("[data-tree-fallback-step]").map((s) => s.textContent)).toEqual(["1Linux boxYour default. Offline now", "2Mac miniNext online computer. Used now", "3This MacLast resort"]);
+ });
+
it("falls back to the next online computer when the default is offline, and says why", { timeout: 30000 }, async () => {
on();
const resolved = {
@@ -228,7 +252,7 @@ describe.skipIf(!wasmBuilt)("Home with Spaces as a tree (Labs)", () => {
await mountApp("/home", host([], { offline: ["mac-mini"], resolved }));
await waitFor(() => expect(q("[data-ask-where]")?.textContent).toBe("Linux box"));
const line = await found("[data-tree-fallback]");
- expect(line.textContent).toContain("Mac mini, your default, is offline. This runs on Linux box, your next online computer. If none is online, it runs on This Mac.");
+ expect(line.textContent).toContain("Mac mini, your default, is offline. This runs on Linux box, the next computer that can take it. If none can, it runs on This Mac.");
expect(qa("[data-tree-fallback-step]").map((s) => s.textContent)).toEqual(["1Mac miniYour default. Offline now", "2Linux boxNext online computer. Used now", "3This MacLast resort"]);
expect(line.textContent).toContain("A new computer is never made unless you pick one.");
});
diff --git a/apps/cua-spaces-web/src/bridge/adapters/demo-data.ts b/apps/cua-spaces-web/src/bridge/adapters/demo-data.ts
index 3fdc30164e..b5bbc161cb 100644
--- a/apps/cua-spaces-web/src/bridge/adapters/demo-data.ts
+++ b/apps/cua-spaces-web/src/bridge/adapters/demo-data.ts
@@ -63,9 +63,24 @@ const STREAMS = ["desktop_stream", "window_stream", "audio.desktop", "relay_atta
/** `minutesAgo` → RFC 3339, relative to `now`. */
const at = (now: number, minutesAgo: number) => new Date(now - minutesAgo * 60_000).toISOString();
-/** The Linux box sharing its own desktop over the relay (`?demo=desktops`): a row of its own, no host above it. */
+/** The Mac mini and the Linux box sharing their own desktops over the relay (`?demo=desktops`): rows of their own, no
+ * host above them. Without these the demo's computers have nowhere to run a task, so Home can't start on one made the
+ * default. */
export function demoDesktopRows(now: number): SpaceRow[] {
return [
+ {
+ id: "relay:mac-mini",
+ name: "Mac mini",
+ provider: "relay",
+ spacesdVersion: "0.6.0",
+ features: [...STREAMS, "host_spaces"],
+ addedAt: at(now, 900),
+ os: "macos",
+ osName: "macOS",
+ osPrettyName: "macOS Tahoe 26.0",
+ arch: "arm64",
+ reachable: true,
+ },
{
id: "relay:linux-box",
name: "Linux box",
diff --git a/apps/cua-spaces-web/src/bridge/adapters/demo.ts b/apps/cua-spaces-web/src/bridge/adapters/demo.ts
index 5af6a1f099..feb2e9f31a 100644
--- a/apps/cua-spaces-web/src/bridge/adapters/demo.ts
+++ b/apps/cua-spaces-web/src/bridge/adapters/demo.ts
@@ -105,7 +105,7 @@ export interface DemoOptions {
keys?: "none" | "several";
/** Start with no Spaces (the first-Space empty state). */
noSpaces?: boolean;
- /** `?demo=desktops`: the Linux box also shares its desktop (a Space row of its own, `relay:linux-box`). */
+ /** `?demo=desktops`: the Mac mini and the Linux box also share their desktops (Space rows of their own, `relay:mac-mini`, `relay:linux-box`). */
desktops?: boolean;
/** This many more Spaces on the list, for scale (`?demo=scale-1000`;
* scripts/scale-bench.mjs). */
@@ -230,7 +230,7 @@ const DEMO_NOTES = "https://github.com/trycua/cua/releases/tag/cua-spaces-v0.9.3
* `?demo=low-disk` / `?demo=disk-full` (This Mac almost out of space: New
* Space and the first Space offers see it too), and `?demo=intel-mac` /
* `?demo=linux-pc` (an Intel Mac, an x64 Linux PC with QEMU), and
- * `?demo=desktops` (the Linux box shares its desktop, a shared desktop row beside the Spaces), and
+ * `?demo=desktops` (the Mac mini and the Linux box share their desktops, a shared desktop row beside the Spaces), and
* `?demo=creating-elsewhere` (the Mac mini is creating a Space). */
/** The account's signed-in machines that share nothing, as a host lists them (`?demo=signed-in-machines`): one enrolled, and the demo devices that wait. */
function demoSignedInRows(nowMs: number): MachineRow[] {
diff --git a/apps/cua-spaces-web/src/bridge/adapters/demo/spaces-settings.ts b/apps/cua-spaces-web/src/bridge/adapters/demo/spaces-settings.ts
index d361c12ec0..698c368f92 100644
--- a/apps/cua-spaces-web/src/bridge/adapters/demo/spaces-settings.ts
+++ b/apps/cua-spaces-web/src/bridge/adapters/demo/spaces-settings.ts
@@ -37,10 +37,13 @@ export function demoSpacesSettingsHandlers(
"spaces.resolveDefault": () => {
if (!state.identity) return null;
const rows = machines().filter((m) => !m.device && m.via !== "direct");
- return resolveDefaultSpace(
- state.spacesSettings,
- rows.map((m) => ({ space: spaceOf(m), name: m.name, online: m.online, here: m.current === true })),
- );
+ const candidates = rows.map((m) => ({ space: spaceOf(m), name: m.name, online: m.online, here: m.current === true }));
+ // A Space made on one of them can be the default too (`relay:<machine>/<name>`): online while its computer is.
+ const def = state.spacesSettings.defaultSpace;
+ const onMachine = def?.match(/^relay:([^/]+)\/(.+)$/);
+ const host = onMachine ? rows.find((m) => m.id === onMachine[1]) : undefined;
+ if (def && onMachine && host) candidates.unshift({ space: def, name: onMachine[2]!, online: host.online, here: false });
+ return resolveDefaultSpace(state.spacesSettings, candidates);
},
};
}
diff --git a/apps/cua-spaces-web/src/bridge/ops/spaces-settings.ts b/apps/cua-spaces-web/src/bridge/ops/spaces-settings.ts
index 518d2f39a9..898b466c21 100644
--- a/apps/cua-spaces-web/src/bridge/ops/spaces-settings.ts
+++ b/apps/cua-spaces-web/src/bridge/ops/spaces-settings.ts
@@ -103,7 +103,9 @@ export interface DefaultCandidate {
* demo that has no relay to ask: the default, then the fallback list
* (explicit, or every other computer when empty; never `here` or the
* default again), then this computer. The first online one wins. It never
- * makes anything: with nothing online, the answer is this computer.
+ * makes anything: with nothing online, the answer is this computer. A
+ * default that isn't among the candidates any more (the computer was
+ * removed) is treated as unset.
*/
export function resolveDefaultSpace(settings: SpacesSettingsInput | null, candidates: readonly DefaultCandidate[]): DefaultSpace {
const here = candidates.find((c) => c.here) ?? null;
@@ -120,7 +122,8 @@ export function resolveDefaultSpace(settings: SpacesSettingsInput | null, candid
}
if (here) order.push({ space: here.space, name: here.name, online: true, role: "here" });
const first = order.find((o) => o.online && o.role !== "here");
- const defaultSpace = settings?.defaultSpace ?? null;
+ // A saved default that is no longer among the computers (removed since) counts as unset.
+ const defaultSpace = def ? (settings?.defaultSpace ?? null) : null;
const defaultOnline = defaultSpace === null ? null : def?.here ? true : (def?.online ?? false);
if (def?.here) return { space: here!.space, reason: "default", defaultSpace, defaultOnline, order };
if (!first) return { space: here?.space ?? null, reason: defaultSpace === null && order.length <= (here ? 1 : 0) ? "unset" : "here", defaultSpace, defaultOnline, order };
diff --git a/apps/cua-spaces-web/src/components/ask-first/imported-task.tsx b/apps/cua-spaces-web/src/components/ask-first/imported-task.tsx
index fceb633f16..defd13995f 100644
--- a/apps/cua-spaces-web/src/components/ask-first/imported-task.tsx
+++ b/apps/cua-spaces-web/src/components/ask-first/imported-task.tsx
@@ -11,6 +11,7 @@ import { Timeline } from "@/components/agents/timeline";
import { Button } from "@/components/ui/button";
import { toastError } from "@/components/ui/toast";
import { HOST_NOT_SHARED, hostSpaceId, updateAskTask, type AskTask } from "@/lib/ask-first";
+import { chatComputers } from "@/lib/machines";
import { cn } from "@/lib/utils";
import { agentName, AppMark } from "./ask-box";
@@ -181,13 +182,15 @@ export function ImportedTaskView({ task }: { task: AskTask & { imported: NonNull
}
/**
- * **Continue on**: where the chat carries on. This Mac today; the account's
- * other computers are listed but can't be picked yet, because the agent's
- * session lives on this Mac (continuing elsewhere is CUA-3331).
+ * **Continue on**: where the chat carries on. This Mac today; your other
+ * computers that could run it (online, each once, no browsers or phones) are
+ * listed but can't be picked yet, because the agent's session lives on this
+ * Mac (continuing elsewhere is CUA-3331). The menu opens above or below the
+ * box, whichever has room, and scrolls rather than leave the window.
*/
-function ContinueOn() {
+export function ContinueOn() {
const { data: machines } = useMachines();
- const others = (machines ?? []).filter((m) => !m.current);
+ const { computers: others, offline } = chatComputers(machines ?? []);
return (
<MenuPrimitive.Root>
<MenuPrimitive.Trigger
@@ -198,8 +201,12 @@ function ContinueOn() {
}
/>
<MenuPrimitive.Portal>
- <MenuPrimitive.Positioner sideOffset={6} align="end" className="z-50 outline-none">
- <MenuPrimitive.Popup /* design-ok: a menu's popup, as Home's pickers */ className="glass w-[340px] origin-(--transform-origin) rounded-xl border p-2 text-popover-foreground shadow-float outline-none">
+ <MenuPrimitive.Positioner side="top" sideOffset={6} align="end" collisionPadding={12} className="z-50 outline-none">
+ <MenuPrimitive.Popup
+ /* design-ok: a menu's popup, as Home's pickers */
+ className="glass max-h-[min(480px,var(--available-height))] w-[340px] origin-(--transform-origin) overflow-y-auto overscroll-contain rounded-xl border p-2 text-popover-foreground shadow-float outline-none"
+ data-continue-on-menu=""
+ >
<p className="px-3 pt-2 pb-1 text-[12px] font-medium text-muted-foreground">Continue on</p>
<MenuPrimitive.Item className="flex min-h-12 cursor-default items-center gap-3 rounded-lg bg-foreground/[0.06] px-3 py-2 outline-none">
<LaptopIcon className="size-4" />
@@ -218,6 +225,11 @@ function ContinueOn() {
</div>
</MenuPrimitive.Item>
))}
+ {offline > 0 ? (
+ <p className="px-3 pt-2 pb-1 text-[12px] text-muted-foreground" data-continue-on-offline={offline}>
+ {offline === 1 ? "1 more computer is offline." : `${offline} more computers are offline.`}
+ </p>
+ ) : null}
</MenuPrimitive.Popup>
</MenuPrimitive.Positioner>
</MenuPrimitive.Portal>
diff --git a/apps/cua-spaces-web/src/components/ask-first/tree-where.tsx b/apps/cua-spaces-web/src/components/ask-first/tree-where.tsx
index fb70d293ff..1d68bca0cb 100644
--- a/apps/cua-spaces-web/src/components/ask-first/tree-where.tsx
+++ b/apps/cua-spaces-web/src/components/ask-first/tree-where.tsx
@@ -55,6 +55,8 @@ function agentsLine(n: Pick<TreeNode, "running">): string | null {
/** A row's second line in the picker. */
export function pickerNote(n: TreeNode): string {
if (!n.online) return n.status.replace(/, Default$/, "");
+ // Online, but no desktop to run a task in: it can't be picked, and "On now" would say it could.
+ if (!nodeWhere(n)) return "Online. Doesn't share its desktop";
const agents = agentsLine(n);
if (n.current) return agents ?? "Works on your own files and apps";
if (n.kind === "computer" && n.people.length > 1) return agents ? `Shared with your team. ${agents}` : "Shared with your team";
@@ -231,7 +233,7 @@ export function TreeWherePicker({
);
}
-/** f2: the default is offline. One line says why, then the order tried. */
+/** f2: the default is offline or shares no desktop. One line says why, then the order tried. */
export function FallbackLine({ fallback }: { fallback: NonNullable<TreeDefault["fallback"]> }) {
return (
<div data-tree-fallback="" className="flex flex-col gap-3 text-[14px]">
@@ -243,7 +245,7 @@ export function FallbackLine({ fallback }: { fallback: NonNullable<TreeDefault["
<p className="mb-2 text-[13px] text-muted-foreground">Where a task goes</p>
<ol className="flex flex-col gap-2">
{fallback.steps.map((s, i) => (
- <li key={`${s.name}:${i}`} className="flex items-center gap-3" data-tree-fallback-step={s.used ? "used" : s.online ? "online" : "offline"}>
+ <li key={`${s.name}:${i}`} className="flex items-center gap-3" data-tree-fallback-step={s.state}>
<span className="flex size-6 shrink-0 items-center justify-center rounded-full bg-foreground/[0.06] text-[12px] text-muted-foreground">{i + 1}</span>
{s.node ? <TreeIcon node={s.node} /> : null}
<span className={cn(!s.online && "text-muted-foreground")}>{s.name}</span>
diff --git a/apps/cua-spaces-web/src/components/first-run-new/first-run-new.tsx b/apps/cua-spaces-web/src/components/first-run-new/first-run-new.tsx
index 9ec4b407ef..7a8a867208 100644
--- a/apps/cua-spaces-web/src/components/first-run-new/first-run-new.tsx
+++ b/apps/cua-spaces-web/src/components/first-run-new/first-run-new.tsx
@@ -202,6 +202,9 @@ export function WhereScreen({
}) {
const t = view.thisRow;
const sep = view.separate;
+ const fold = view.offlineFold;
+ const [showOffline, setShowOffline] = useState(false);
+ const other = (o: ComputerRow) => <Row key={o.id} icon={<Mark os={o.os} />} name={o.name} sub={o.sub} picked={o.picked} disabled={o.disabled} onClick={() => onToggle(o.id)} data-new-run-computer={o.id} data-offline={o.disabled ? "" : undefined} />;
return (
<div data-new-run="where">
<Title>{view.title}</Title>
@@ -243,7 +246,30 @@ export function WhereScreen({
<>
<Label>{view.othersLabel}</Label>
{view.others.length ? (
- view.others.map((o) => <Row key={o.id} icon={<Mark os={o.os} />} name={o.name} sub={o.sub} picked={o.picked} disabled={o.disabled} onClick={() => onToggle(o.id)} data-new-run-computer={o.id} data-offline={o.disabled ? "" : undefined} />)
+ <>
+ {(fold ? view.others.filter((o) => !o.offline) : view.others).map(other)}
+ {fold ? (
+ <>
+ <button
+ type="button"
+ aria-expanded={showOffline}
+ // design-ok: the first run is drawn from the spaces.cua.ai hero (storyboard CUA-3193), not the app's pages
+ className="flex w-full items-center gap-3 rounded-[14px] px-3 py-[7px] text-left outline-none hover:bg-white/[0.06] focus-visible:ring-2 focus-visible:ring-[#5ec0e8]"
+ onClick={() => setShowOffline((v) => !v)}
+ data-new-run-offline-fold={fold.rows.length}
+ >
+ <span className="flex size-7 shrink-0 items-center justify-center text-white">
+ <ChevronRightIcon className={cn("size-4 transition-transform motion-reduce:transition-none", showOffline && "rotate-90")} strokeWidth={2.2} />
+ </span>
+ <span className="min-w-0 flex-1">
+ <span className="block text-[15px] leading-5 font-medium text-white">{fold.label}</span>
+ <span className={cn("block text-[13.5px] leading-[19px] font-medium", GREY)}>{fold.sub}</span>
+ </span>
+ </button>
+ {showOffline ? fold.rows.map(other) : null}
+ </>
+ ) : null}
+ </>
) : (
<p className={cn("px-3 pt-1 pb-2 text-[13.5px] leading-[19px] font-medium", GREY)} data-new-run-none="">
{view.emptyLine}
@@ -298,7 +324,8 @@ export function WhereScreen({
</div>
) : null}
</div>
- <div className="mt-[min(28px,3vh)]">
+ {/* Stays in view at the bottom of the window however long the list is; the fade keeps the list readable under it. */}
+ <div className="sticky bottom-0 z-10 -mx-4 mt-2 bg-linear-to-t from-[#050607] from-60% to-transparent px-4 pt-[min(20px,2.2vh)] pb-3" data-new-run-footer="">
<button type="button" className={WHITE_BUTTON} disabled={!view.continueEnabled} onClick={onContinue} data-onboarding-primary="">
Continue
</button>
diff --git a/apps/cua-spaces-web/src/lib/default-where.ts b/apps/cua-spaces-web/src/lib/default-where.ts
index 8877e6d264..816f1bad90 100644
--- a/apps/cua-spaces-web/src/lib/default-where.ts
+++ b/apps/cua-spaces-web/src/lib/default-where.ts
@@ -12,11 +12,14 @@
* ask it resolves the same way over the tree (`resolveDefaultSpace`).
*/
-import { resolveDefaultSpace, type DefaultSpace, type SpacesSettings } from "@/bridge";
+import { resolveDefaultSpace, type DefaultSpace, type DefaultSpaceStep, type SpacesSettings } from "@/bridge";
import type { NewKind, TaskWhere } from "./ask-first";
import { defaultCandidates, findNode, type SpacesTree, type TreeNode } from "./spaces-tree";
+/** How a computer in "Where a task goes" stands: it runs the task, it could, it's online but has no desktop to run in, or it's offline. */
+export type WhereStepState = "used" | "ready" | "no-desktop" | "offline";
+
/** One line of "Where a task goes" (f2). */
export interface WhereStep {
name: string;
@@ -24,6 +27,7 @@ export interface WhereStep {
note: string;
online: boolean;
used: boolean;
+ state: WhereStepState;
node: TreeNode | null;
}
@@ -31,7 +35,7 @@ export interface TreeDefault {
where: TaskWhere;
/** The row it runs on; null: This Mac before it's in the tree. */
node: TreeNode | null;
- /** The default is offline: the line under Home's box and the order tried. Null otherwise. */
+ /** The default can't take the task (offline, or it shares no desktop): the line under Home's box and the order tried. Null otherwise. */
fallback: { line: string; steps: WhereStep[] } | null;
}
@@ -49,34 +53,85 @@ export function resolvedDefault(tree: SpacesTree, settings: SpacesSettings | nul
return resolveDefaultSpace({ defaultSpace: def, fallback: settings?.fallback ?? [], fallbackOn: settings?.fallbackOn ?? true }, defaultCandidates(tree));
}
+/** Why the default can't take a task. */
+export type DefaultProblem = "offline" | "no-desktop";
+
+/** The parts of the line under Home's box; `fallbackSentence` puts them together. */
+export interface FallbackParts {
+ /** The default's own name, never "your default". */
+ defaultName: string;
+ problem: DefaultProblem;
+ /** The computer it runs on instead; null: This Mac. */
+ usedName: string | null;
+ /** Another computer is online but shares no desktop to run in, so "no other computer is online" would be wrong. */
+ othersOnline: boolean;
+}
+
+const PROBLEM: Record<DefaultProblem, string> = { offline: "is offline", "no-desktop": "is online but doesn't share its desktop" };
+
+/** The line under Home's box, built from its parts so a name or a phrase is never said twice. */
+export function fallbackSentence({ defaultName, problem, usedName, othersOnline }: FallbackParts): string {
+ const why = `${defaultName}, your default, ${PROBLEM[problem]}`;
+ if (usedName) return `${why}. This runs on ${usedName}, the next computer that can take it. If none can, it runs on This Mac.`;
+ const others = othersOnline ? "no other computer can take it now" : "no other computer is online";
+ return `${why}, and ${others}. This runs on This Mac.`;
+}
+
+const stepNote = (role: string, state: WhereStepState): string => {
+ if (role === "here") return state === "used" ? "Last resort. Used now" : "Last resort";
+ if (role === "default") return state === "offline" ? "Your default. Offline now" : state === "no-desktop" ? "Your default. Doesn't share its desktop" : "Your default";
+ return state === "used" ? "Next online computer. Used now" : state === "ready" ? "Next to try" : state === "no-desktop" ? "Online, doesn't share its desktop" : "Offline now";
+};
+
/**
- * Where a task goes unless you pick: the resolution's Space, as a place
- * to run. Anything that can't be run in (gone from the list, no desktop
- * to start in) goes to This Mac. Never a new computer.
+ * Where a task goes unless you pick: the resolution's Space, as a place to
+ * run. A computer that's online but shares no desktop can't take the task, so
+ * it's passed over for the next one in the order that can, then This Mac.
+ * Never a new computer. A saved default that's no longer in the tree (the
+ * computer was removed) counts as no default at all.
*/
export function treeDefault(tree: SpacesTree, settings: SpacesSettings | null, resolved: DefaultSpace | null): TreeDefault {
const r = resolvedDefault(tree, settings, resolved);
- const picked = findNode(tree, r.space);
- const where = picked ? (nodeWhere(picked) ?? ({ kind: "this-mac" } as const)) : ({ kind: "this-mac" } as const);
- const node = where.kind === "this-mac" ? (tree.roots.find((n) => n.current) ?? null) : (picked ?? null);
- const usedKey = node?.key ?? null;
- const defOffline = r.defaultSpace !== null && r.defaultOnline === false;
- if (!defOffline) return { where, node, fallback: null };
-
- const steps: WhereStep[] = r.order.map((o) => {
- const n = findNode(tree, o.space) ?? null;
- const used = o.role === "here" ? where.kind === "this-mac" : where.kind !== "this-mac" && n !== null && n.key === usedKey;
+ const here = tree.roots.find((n) => n.current) ?? null;
+ const defNode = r.defaultSpace ? (findNode(tree, r.defaultSpace) ?? null) : null;
+
+ // The order with each computer's own row; computers no longer in the tree (removed since) are left out.
+ const order = r.order
+ .map((o) => ({ o, n: o.role === "here" ? here : (findNode(tree, o.space) ?? null) }))
+ .filter(({ o, n }) => o.role === "here" || n !== null);
+ const stateOf = (o: DefaultSpaceStep, n: TreeNode | null): Exclude<WhereStepState, "used"> => {
+ if (o.role === "here") return "ready";
+ if (!n || !o.online || !n.online) return "offline";
+ return nodeWhere(n) ? "ready" : "no-desktop";
+ };
+ const states = order.map(({ o, n }) => stateOf(o, n));
+
+ // Start from the resolution's pick (null: This Mac) and take the first that can run the task.
+ const pickedAt = r.space === null ? -1 : order.findIndex(({ o, n }) => o.role !== "here" && (o.space === r.space || n?.key === r.space || n?.settingsId === r.space));
+ const usedAt = pickedAt < 0 ? -1 : order.findIndex(({ o }, i) => i >= pickedAt && o.role !== "here" && states[i] === "ready");
+ const usedNode = usedAt >= 0 ? order[usedAt]!.n : null;
+ const usedWhere = usedNode ? nodeWhere(usedNode) : null;
+ const where: TaskWhere = usedWhere ?? { kind: "this-mac" };
+ const node = where.kind === "this-mac" ? here : usedNode;
+
+ const defIndex = order.findIndex(({ o }) => o.role === "default");
+ const defState = defIndex >= 0 ? states[defIndex]! : null;
+ // No line while the default takes the task, or there's no default that still exists (or it's This Mac).
+ if (!defNode || defNode.current || defState === null || defState === "ready") return { where, node, fallback: null };
+
+ const usedHere = where.kind === "this-mac";
+ const steps: WhereStep[] = order.map(({ o, n }, i) => {
+ const used = o.role === "here" ? usedHere : i === usedAt && !usedHere;
+ const state: WhereStepState = used ? "used" : states[i]!;
const name = o.role === "here" ? "This Mac" : (n?.name ?? o.name);
- const note =
- o.role === "default" ? (o.online ? "Your default" : "Your default. Offline now") : o.role === "here" ? (used ? "Last resort. Used now" : "Last resort") : used ? "Next online computer. Used now" : o.online ? "Next to try" : "Offline now";
- return { name, note, online: o.online, used, node: n };
+ return { name, note: stepNote(o.role, state), online: state !== "offline", used, state, node: n };
+ });
+ const line = fallbackSentence({
+ defaultName: defNode.name,
+ problem: defState,
+ usedName: usedHere ? null : (usedNode?.name ?? null),
+ othersOnline: steps.some((s, i) => i !== defIndex && s.state === "no-desktop"),
});
- const defName = steps.find((s) => s.note.startsWith("Your default"))?.name ?? findNode(tree, r.defaultSpace)?.name ?? "Your default";
- const usedStep = steps.find((s) => s.used);
- const line =
- where.kind === "this-mac" || !usedStep
- ? `${defName}, your default, is offline, and no other computer is online. This runs on This Mac.`
- : `${defName}, your default, is offline. This runs on ${usedStep.name}, your next online computer. If none is online, it runs on This Mac.`;
return { where, node, fallback: { line, steps } };
}
diff --git a/apps/cua-spaces-web/src/lib/first-run-new.ts b/apps/cua-spaces-web/src/lib/first-run-new.ts
index 9684e7562a..db3cb26b12 100644
--- a/apps/cua-spaces-web/src/lib/first-run-new.ts
+++ b/apps/cua-spaces-web/src/lib/first-run-new.ts
@@ -115,8 +115,28 @@ export interface ComputerRow {
os: "macos" | "windows" | "linux" | null;
sub: string;
picked: boolean;
- /** Offline: shown greyed, with no check circle, and it can't be picked. */
+ /** Offline or not sharing: shown greyed, with no check circle, and it can't be picked. */
disabled: boolean;
+ /** Offline: with others offline too, it folds into one "N offline" row (`OfflineFold`). */
+ offline: boolean;
+}
+
+/** Offline computers folded into one row, so a long list never pushes Continue off the screen. */
+export interface OfflineFold {
+ /** "14 offline". */
+ label: string;
+ sub: string;
+ rows: ComputerRow[];
+}
+
+/** From this many offline computers on, they fold into one row; a single one is shown as itself. */
+export const OFFLINE_FOLD_AT = 2;
+
+/** The offline rows as one fold, or null when there are too few to fold. */
+export function offlineFold(rows: readonly ComputerRow[]): OfflineFold | null {
+ const off = rows.filter((r) => r.offline);
+ if (off.length < OFFLINE_FOLD_AT) return null;
+ return { label: `${off.length} offline`, sub: "They can be picked once they're back online.", rows: off };
}
export interface WhereView {
@@ -137,6 +157,8 @@ export interface WhereView {
};
/** Signed in: the account's other computers (empty: `emptyLine`). Signed out: null, and `signInLine` shows instead. */
others: ComputerRow[] | null;
+ /** The offline ones among `others`, folded into one row (null: none, or only one, which shows as itself). */
+ offlineFold: OfflineFold | null;
othersLabel: string;
emptyLine: string;
signInLine: { link: string; rest: string } | null;
@@ -189,7 +211,7 @@ export function otherComputers(input: Pick<WhereInput, "machines" | "picks" | "n
? "Not sharing"
: `${os ? OS_WORD[os] : "Computer"} · ready`;
const disabled = offline || Boolean(m.notSharing);
- return { id: m.id, name: m.name, os, sub, picked: !disabled && input.picks.includes(m.id), disabled };
+ return { id: m.id, name: m.name, os, sub, picked: !disabled && input.picks.includes(m.id), disabled, offline };
});
}
@@ -228,6 +250,7 @@ export function whereView(input: WhereInput): WhereView {
line: `Your agents can work on ${place} without an account. Add ${place} to an account when you want them on your other computers too.`,
thisRow: { name: Place, status: "not added yet", tick: false, model: input.model, modelFirst: true, picked: thisPicked, action: { id: "add", label: "Add" } },
others: null,
+ offlineFold: null,
othersLabel: "Other computers in your account",
emptyLine: "",
signInLine: { link: "Sign in", rest: " to see your other computers." },
@@ -236,6 +259,7 @@ export function whereView(input: WhereInput): WhereView {
continueEnabled: input.picks.length > 0,
};
}
+ const others = otherComputers(input);
const status =
input.thisState === "adding"
? "Adding to your account…"
@@ -256,7 +280,8 @@ export function whereView(input: WhereInput): WhereView {
picked: thisPicked,
action: input.thisState === "failed" ? { id: "retry-add", label: "Try again" } : null,
},
- others: otherComputers(input),
+ others,
+ offlineFold: offlineFold(others),
othersLabel: "Other computers in your account",
emptyLine: "None yet. Computers you or your team sign in on show up here.",
signInLine: null,
diff --git a/apps/cua-spaces-web/src/lib/machines.test.ts b/apps/cua-spaces-web/src/lib/machines.test.ts
index a3d07a667e..8242ce24a4 100644
--- a/apps/cua-spaces-web/src/lib/machines.test.ts
+++ b/apps/cua-spaces-web/src/lib/machines.test.ts
@@ -4,7 +4,7 @@
import { describe, expect, it } from "vitest";
import type { Machine } from "@/bridge";
-import { connectionLabel, machineOs, machinesSummary, machineSubtitle, presenceLabel, presenceWord, reachable, selectedMachine, spaceCount, spacesLabel } from "./machines";
+import { chatComputers, connectionLabel, machineOs, machinesSummary, machineSubtitle, presenceLabel, presenceWord, reachable, selectedMachine, spaceCount, spacesLabel } from "./machines";
const NOW = Date.parse("2026-10-03T12:00:00Z");
@@ -94,3 +94,23 @@ describe("machines", () => {
expect(selectedMachine([], null)).toBeUndefined();
});
});
+
+describe("chatComputers", () => {
+ const m = (over: Partial<Machine>): Machine => ({ id: "m", name: "M", os: "macos", via: "relay", connection: "relay", online: true, current: false, spaceIds: [], limits: [], ...over });
+
+ it("keeps your other online computers once each, and leaves out this one, devices and offline ones", () => {
+ const rows = [
+ m({ id: "here", name: "This Mac", current: true }),
+ m({ id: "mini", name: "Mac mini" }),
+ m({ id: "mini", name: "Mac mini" }),
+ m({ id: "web-1", name: "Web browser", os: "web", device: true }),
+ m({ id: "web-2", name: "Web browser", os: "web", device: true }),
+ m({ id: "old", name: "Old box", online: false }),
+ m({ id: "off", name: "Not shared", notSharing: "Stopped sharing" }),
+ m({ id: "pc", name: "Studio PC", os: "windows" }),
+ ];
+ const { computers, offline } = chatComputers(rows);
+ expect(computers.map((c) => c.id)).toEqual(["mini", "pc"]);
+ expect(offline).toBe(2);
+ });
+});
diff --git a/apps/cua-spaces-web/src/lib/machines.ts b/apps/cua-spaces-web/src/lib/machines.ts
index 0060c82671..543a9d38b8 100644
--- a/apps/cua-spaces-web/src/lib/machines.ts
+++ b/apps/cua-spaces-web/src/lib/machines.ts
@@ -88,3 +88,21 @@ export function selectedMachine<T extends Pick<Machine, "id">>(machines: readonl
export function machinesSummary(total: number, online: number): string {
return `${plural(total, "machine")}, ${online} online`;
}
+
+/**
+ * The computers a chat could carry on on ("Continue on"): your other
+ * computers that are online and shared, each once. Signed-in devices that
+ * aren't computers (a web browser, a phone) can't run a chat, nor can an
+ * offline one; `offline` counts the computers left out for being offline.
+ */
+export function chatComputers(machines: readonly Machine[]): { computers: Machine[]; offline: number } {
+ const seen = new Set<string>();
+ const others: Machine[] = [];
+ for (const m of machines) {
+ if (m.current || m.device || seen.has(m.id)) continue;
+ seen.add(m.id);
+ others.push(m);
+ }
+ const computers = others.filter(reachable);
+ return { computers, offline: others.length - computers.length };
+}
diff --git a/apps/cua-spaces-web/src/lib/spaces-tree.test.ts b/apps/cua-spaces-web/src/lib/spaces-tree.test.ts
index 2258ae1018..7bd81cfa46 100644
--- a/apps/cua-spaces-web/src/lib/spaces-tree.test.ts
+++ b/apps/cua-spaces-web/src/lib/spaces-tree.test.ts
@@ -3,9 +3,9 @@
import { describe, expect, it } from "vitest";
-import type { Machine, Space } from "@/bridge";
+import { resolveDefaultSpace, type Machine, type Space } from "@/bridge";
-import { currentTreeWhere, newSpaceTargets, treeDefault } from "./default-where";
+import { currentTreeWhere, fallbackSentence, newSpaceTargets, treeDefault } from "./default-where";
import { buildSpacesTree, defaultCandidates, findNode, treeRows, treeSummary } from "./spaces-tree";
const NOW = Date.parse("2026-11-04T12:00:00Z");
@@ -143,7 +143,7 @@ describe("treeDefault", () => {
const t = tree({ defaultSpace: "relay:studio", machines: [THIS_MAC, { ...STUDIO, online: false }, DILLON] });
const d = treeDefault(t, settings("relay:studio"), null);
expect(d.where).toEqual({ kind: "space", space: SPACES[6] });
- expect(d.fallback?.line).toBe("Studio Mac mini, your default, is offline. This runs on Dillon's PC, your next online computer. If none is online, it runs on This Mac.");
+ expect(d.fallback?.line).toBe("Studio Mac mini, your default, is offline. This runs on Dillon's PC, the next computer that can take it. If none can, it runs on This Mac.");
expect(d.fallback?.steps.map((s) => [s.name, s.note])).toEqual([
["Studio Mac mini", "Your default. Offline now"],
["Dillon's PC", "Next online computer. Used now"],
@@ -179,6 +179,87 @@ describe("treeDefault", () => {
expect(treeDefault(single, null, null).where).toEqual({ kind: "this-mac" });
});
+ it("ignores a saved default whose computer was removed, and never says \"your default\" twice", () => {
+ // The live case: This Mac is the default in the tree, every other computer is offline, and the account still has
+ // a default saved for a computer that's gone.
+ const machines = [THIS_MAC, { ...STUDIO, online: false }, { ...DILLON, online: false }];
+ const t = tree({ machines, defaultSpace: "relay:removed" });
+ const local = treeDefault(t, settings("relay:removed"), null);
+ expect(local.where).toEqual({ kind: "this-mac" });
+ expect(local.fallback).toBeNull();
+ // The relay still answering with the old default changes nothing.
+ const relay = { space: null, reason: "here", defaultSpace: "relay:removed", defaultOnline: false, order: [{ space: "relay:studio", name: "Studio Mac mini", online: false, role: "fallback" }, { space: "relay:mac-here", name: "This Mac", online: true, role: "here" }] };
+ const remote = treeDefault(t, settings("relay:removed"), relay);
+ expect(remote.where).toEqual({ kind: "this-mac" });
+ expect(remote.fallback).toBeNull();
+ });
+
+ it("never repeats \"your default\" in any line it builds", () => {
+ for (const problem of ["offline", "no-desktop"] as const)
+ for (const usedName of [null, "Dillon's PC"])
+ for (const othersOnline of [false, true]) {
+ const line = fallbackSentence({ defaultName: "Studio Mac mini", problem, usedName, othersOnline });
+ expect(line.match(/your default/gi)).toHaveLength(1);
+ expect(line.startsWith("Studio Mac mini, your default, ")).toBe(true);
+ }
+ });
+
+ it("passes over an online computer that shares no desktop, and doesn't call it offline", () => {
+ // Dillon's PC is online but shares no desktop (no Space row of its own).
+ const spaces = SPACES.filter((s) => s.id !== "relay:dillon");
+ const t = tree({ defaultSpace: "relay:studio", machines: [THIS_MAC, { ...STUDIO, online: false }, DILLON], spaces });
+ const d = treeDefault(t, settings("relay:studio"), null);
+ expect(d.where).toEqual({ kind: "this-mac" });
+ expect(d.fallback?.line).toBe("Studio Mac mini, your default, is offline, and no other computer can take it now. This runs on This Mac.");
+ expect(d.fallback?.steps.map((s) => [s.name, s.note, s.state])).toEqual([
+ ["Studio Mac mini", "Your default. Offline now", "offline"],
+ ["Dillon's PC", "Online, doesn't share its desktop", "no-desktop"],
+ ["This Mac", "Last resort. Used now", "used"],
+ ]);
+ expect(d.fallback?.steps.some((s) => s.note === "Next to try")).toBe(false);
+ });
+
+ it("moves on to the next computer that can take it when the relay picked one with no desktop", () => {
+ const linux = machine({ id: "linux", name: "Linux box", os: "linux" });
+ const spaces = [...SPACES.filter((s) => s.id !== "relay:dillon"), space({ id: "relay:linux", name: "Linux box" })];
+ const t = tree({ defaultSpace: "relay:studio", machines: [THIS_MAC, { ...STUDIO, online: false }, DILLON, linux], spaces });
+ const relay = {
+ space: "relay:dillon",
+ reason: "fallback",
+ defaultSpace: "relay:studio",
+ defaultOnline: false,
+ order: [
+ { space: "relay:studio", name: "Studio Mac mini", online: false, role: "default" },
+ { space: "relay:dillon", name: "Dillon's PC", online: true, role: "fallback" },
+ { space: "relay:linux", name: "Linux box", online: true, role: "fallback" },
+ { space: "relay:mac-here", name: "This Mac", online: true, role: "here" },
+ ],
+ };
+ const d = treeDefault(t, settings("relay:studio"), relay);
+ expect(d.where).toMatchObject({ kind: "space", space: { id: "relay:linux" } });
+ expect(d.fallback?.line).toBe("Studio Mac mini, your default, is offline. This runs on Linux box, the next computer that can take it. If none can, it runs on This Mac.");
+ expect(d.fallback?.steps.map((s) => s.state)).toEqual(["offline", "no-desktop", "used", "ready"]);
+ });
+
+ it("says why when the default is online but shares no desktop, instead of running elsewhere silently", () => {
+ const spaces = SPACES.filter((s) => s.id !== "relay:studio");
+ const t = tree({ defaultSpace: "relay:studio", spaces });
+ const d = treeDefault(t, settings("relay:studio"), null);
+ expect(d.where).toMatchObject({ kind: "space", space: { id: "relay:dillon" } });
+ expect(d.fallback?.line).toBe("Studio Mac mini, your default, is online but doesn't share its desktop. This runs on Dillon's PC, the next computer that can take it. If none can, it runs on This Mac.");
+ expect(d.fallback?.steps[0]).toMatchObject({ name: "Studio Mac mini", note: "Your default. Doesn't share its desktop", state: "no-desktop", online: true });
+ });
+
+ it("the resolver treats a saved default that's no longer a computer of yours as unset", () => {
+ const candidates = [
+ { space: "relay:studio", name: "Studio Mac mini", online: false },
+ { space: "relay:mac-here", name: "This Mac", online: true, here: true },
+ ];
+ expect(resolveDefaultSpace({ defaultSpace: "relay:removed", fallback: [], fallbackOn: true }, candidates)).toMatchObject({ space: "relay:mac-here", defaultSpace: null, defaultOnline: null });
+ // One that is still there is kept.
+ expect(resolveDefaultSpace({ defaultSpace: "relay:studio", fallback: [], fallbackOn: true }, candidates)).toMatchObject({ defaultSpace: "relay:studio", defaultOnline: false });
+ });
+
it("lists This Mac last among the candidates", () => {
const c = defaultCandidates(tree());
expect(c.map((x) => x.space)).toEqual(["relay:mac-here", "relay:studio", "relay:dillon"]);