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): the tree only on the Spaces page, one Spaces item in the sidebar (CUA-3510) (#6546)
Francesco Bonacci3ffe9bd4b5f0
diff --git a/apps/cua-spaces-web/src/__tests__/spaces-tree.test.tsx b/apps/cua-spaces-web/src/__tests__/spaces-tree.test.tsxindex 22eb05ded5..d352b98a0a 100644--- a/apps/cua-spaces-web/src/__tests__/spaces-tree.test.tsx+++ b/apps/cua-spaces-web/src/__tests__/spaces-tree.test.tsx@@ -3,8 +3,8 @@// Spaces as a tree and a default Space (CUA-3413, Labs `spaces_tree`) on the// real routes and the wasm core: off, the app is as it was; on, Machines-// leaves the nav and the sidebar and the Spaces page list each computer with-// the Spaces made on it; rename by double-click; Remove names each Space and+// leaves the nav, the sidebar keeps one Spaces item, and the Spaces page+// lists each computer with the Spaces made on it; rename by double-click; Remove names each Space and// deletes them only with the box ticked; Home starts on the default Space,// says why when it falls back, and never makes a computer by itself.@@ -44,13 +44,15 @@ const found = (s: string) =>});type Call = [string, Record<string, unknown>];-/** The demo host with the Linux box sharing its desktop; `offline` machines are offline; every change recorded. */-function host(calls: Call[], opts: { offline?: string[]; resolved?: DefaultSpace } = {}): TestHost {+/** The demo host with the Linux box sharing its desktop; `offline` machines are offline; `extra` machines join the+ * account; every change recorded. */+function host(calls: Call[], opts: { offline?: string[]; resolved?: DefaultSpace; extra?: MachineRow[] } = {}): TestHost {return {failsCreates: false,listsGhost: false,demo: { onboarded: true, desktops: true },- answer: (op, out) => (op === "machines.list" ? (out as MachineRow[]).map((m) => (opts.offline?.includes(m.id) ? { ...m, online: false } : m)) : out),+ answer: (op, out) =>+ op === "machines.list" ? [...(out as MachineRow[]), ...(opts.extra ?? [])].map((m) => (opts.offline?.includes(m.id) ? { ...m, online: false } : m)) : out,intercept: (op, args) => {if (op === "spaces.rename" || op === "machines.rename" || op === "machines.remove" || op === "spaces.delete" || op === "spaces.setSettings" || op === "spaces.create") {calls.push([op, args as Record<string, unknown>]);@@ -86,7 +88,7 @@ describe.skipIf(!wasmBuilt)("Spaces as a tree (Labs)", () => {expect(q("[data-spaces-tree]")).toBeNull();});- it("on: Machines leaves the nav, and each computer lists the Spaces made on it, This Mac first", { timeout: 30000 }, async () => {+ it("on: Machines leaves the nav, the sidebar keeps one Spaces item, and the page lists each computer with its Spaces, This Mac first", { timeout: 30000 }, async () => {on();const { router } = await mountApp("/spaces", host([]));await router.load();@@ -96,17 +98,19 @@ describe.skipIf(!wasmBuilt)("Spaces as a tree (Labs)", () => {const names = qa("[data-tree-kind=computer] [data-tree-name]").map((e) => e.textContent);expect(names[0]).toBe("This Mac");expect(names).toContain("Linux box");- // The Linux box's Spaces sit under it, in the sidebar too.+ // The Linux box's Spaces sit under it on the page.const rows = qa("[data-tree-row]").map((r) => r.getAttribute("data-tree-row"));expect(rows.indexOf("relay:linux-box/ubuntu-build")).toBeGreaterThan(rows.indexOf("relay:linux-box"));- expect(q('[data-sidebar-tree-row="relay:linux-box/ubuntu-build"]')).not.toBeNull();+ // The sidebar has no tree: one Spaces item, counting the computers and Spaces the page lists.+ const sidebar = q("aside[aria-label=Sidebar]")!;+ expect(sidebar.querySelector("[data-sidebar-tree], [data-tree-row], [data-tree-default]")).toBeNull();+ expect(sidebar.textContent).not.toContain("Linux box");+ await waitFor(() => expect(within(sidebar).getByRole("link", { name: /^Spaces/ }).textContent).toContain(String(rows.length)));// The first computer that isn't this Mac is the default until one is set.expect(q('[data-tree-status="relay:mac-mini"]')?.textContent).toMatch(/, Default$/);- expect(q("[data-sidebar-tree] [data-tree-default]")).not.toBeNull();- // Folding a computer hides its Spaces in both lists.+ // Folding a computer hides its Spaces.fireEvent.click(q('[data-tree-fold="relay:linux-box"]')!);expect(q('[data-tree-row="relay:linux-box/ubuntu-build"]')).toBeNull();- expect(q('[data-sidebar-tree-row="relay:linux-box/ubuntu-build"]')).toBeNull();// Machines' page still opens.await act(() => router.navigate({ to: "/machines" }));await waitFor(() => expect(router.state.location.pathname).toBe("/machines"));@@ -120,6 +124,22 @@ describe.skipIf(!wasmBuilt)("Spaces as a tree (Labs)", () => {expect(document.body.textContent).toContain("Linux box is offline, so the 2 Spaces on it are too. They come back when it does.");});+ it("folds offline computers with no Spaces on them into one \"N offline\" row that opens", { timeout: 30000 }, async () => {+ on();+ const old = (n: number): MachineRow => ({ id: `old-${n}`, name: `Old box ${n}`, via: "relay", online: false, os: "linux", limits: [] });+ await mountApp("/spaces", host([], { extra: [old(1), old(2), old(3)] }));+ const fold = await found("[data-tree-offline-fold]");+ expect(fold.textContent).toMatch(/^\d+ offline/);+ expect(fold.textContent).toContain("Old box 1, Old box 2, Old box 3");+ expect(qa("[data-tree-name]").map((e) => e.textContent)).not.toContain("Old box 1");+ // The computers with Spaces stay in the list above it.+ expect(q('[data-tree-row="relay:linux-box"]')).not.toBeNull();+ fireEvent.click(q("[data-tree-offline-toggle]")!);+ await waitFor(() => expect(qa("[data-tree-name]").map((e) => e.textContent)).toContain("Old box 1"));+ // Each one keeps its row menu once shown.+ expect(qa("[data-tree-menu]").length).toBe(qa("[data-tree-row]").length);+ });+it("renames a Space by double-clicking its name: Enter saves, Esc cancels", { timeout: 30000 }, async () => {on();const calls: Call[] = [];diff --git a/apps/cua-spaces-web/src/components/shell/sidebar-tree.tsx b/apps/cua-spaces-web/src/components/shell/sidebar-tree.tsxdeleted file mode 100644index 16c0c5ed31..0000000000--- a/apps/cua-spaces-web/src/components/shell/sidebar-tree.tsx+++ /dev/null@@ -1,82 +0,0 @@-// SPDX-License-Identifier: FSL-1.1-MIT-// Copyright (c) 2026 Cua AI, Inc.--import { Link } from "@tanstack/react-router";-import { ChevronRightIcon } from "lucide-react";--import { TreeDot, TreeIcon, toggleCollapsed, useCollapsed } from "@/components/spaces/tree-parts";-import type { SpacesTree, TreeNode } from "@/lib/spaces-tree";-import { cn } from "@/lib/utils";--const row =- "group flex h-7 min-w-0 flex-1 items-center gap-2 rounded-lg px-2 text-[13px] outline-none hover:bg-foreground/5 focus-visible:ring-2 focus-visible:ring-ring/60 data-[status=active]:bg-foreground/[0.07] data-[status=active]:font-medium dark:data-[status=active]:bg-white/[0.08]";--function NodeLink({ node, depth }: { node: TreeNode; depth: 0 | 1 }) {- const body = (- <>- <TreeIcon node={node} className={cn(node.dim && "opacity-50")} />- <span className={cn("min-w-0 flex-1 truncate", node.dim && "text-muted-foreground")}>{node.name}</span>- {node.isDefault ? (- <span data-tree-default="" className="shrink-0 text-2xs text-muted-foreground">- Default- </span>- ) : null}- <TreeDot tone={node.tone} />- </>- );- const cls = cn(row, depth === 1 && "pl-7");- // A computer that shares no desktop has no page of its own: its Machines page.- return node.space ? (- <Link to="/spaces/$spaceId" params={{ spaceId: node.space.id }} className={cls} data-sidebar-tree-row={node.key}>- {body}- </Link>- ) : (- <Link to="/machines" className={cls} data-sidebar-tree-row={node.key}>- {body}- </Link>- );-}--/**- * The sidebar's Spaces as a tree (Labs, CUA-3413): each computer, with the- * Spaces made on it under it. A computer with Spaces folds and unfolds.- */-export function SidebarTree({ tree }: { tree: SpacesTree }) {- const collapsed = useCollapsed();- if (tree.roots.length === 0) return null;- return (- <ul className="flex flex-col gap-px pb-1" data-sidebar-tree="" aria-label="Your Spaces">- {tree.roots.map((node) => {- const folded = collapsed.has(node.key);- return (- <li key={node.key}>- <div className="relative flex items-center">- <NodeLink node={node} depth={0} />- {node.children.length > 0 ? (- <button- type="button"- aria-label={folded ? `Show the Spaces on ${node.name}` : `Hide the Spaces on ${node.name}`}- aria-expanded={!folded}- data-sidebar-tree-fold={node.key}- onClick={() => toggleCollapsed(node.key)}- className="absolute -left-2 flex size-4 items-center justify-center rounded-lg text-muted-foreground opacity-0 outline-none hover:text-foreground focus-visible:opacity-100 group-hover:opacity-100 [li:hover_&]:opacity-100"- >- <ChevronRightIcon className={cn("size-3 transition-transform", !folded && "rotate-90")} />- </button>- ) : null}- </div>- {node.children.length > 0 && !folded ? (- <ul className="flex flex-col gap-px">- {node.children.map((c) => (- <li key={c.key} className="flex">- <NodeLink node={c} depth={1} />- </li>- ))}- </ul>- ) : null}- </li>- );- })}- </ul>- );-}diff --git a/apps/cua-spaces-web/src/components/shell/sidebar.tsx b/apps/cua-spaces-web/src/components/shell/sidebar.tsxindex 51a61eea4b..4610cf54f4 100644--- a/apps/cua-spaces-web/src/components/shell/sidebar.tsx+++ b/apps/cua-spaces-web/src/components/shell/sidebar.tsx@@ -26,7 +26,6 @@ import { SidebarUpdateButton } from "./update-indicator";import { SidebarTip } from "@/components/tips";import { useMachinesAccount } from "@/components/machines/account-parts";import { AccountLine, ProBanner } from "./account-area";-import { SidebarTree } from "./sidebar-tree";import { useSpacesTreeData } from "@/components/spaces/use-spaces-tree";export function Sidebar() {@@ -43,7 +42,8 @@ export function Sidebar() {const spacesCount = spaces && listStatus.loaded ? counted.length : undefined;// Machines waiting to be added show beside the item, so they are seen from every page.const { pending } = useMachinesAccount();- // Spaces as a tree (Labs): your computers and the Spaces on them, counted together, under Spaces.+ // Spaces as a tree (Labs): one Spaces item counting your computers and the Spaces on them, as the Spaces page lists+ // them. The tree itself is only on the Spaces page, so the sidebar stays short.const { tree } = useSpacesTreeData();const treeCount = tree && listStatus.loaded ? tree.computers + tree.spaces : undefined;const counts: Partial<Record<string, number>> = { "/spaces": tree ? treeCount : spacesCount, "/machines": machines?.length };@@ -63,7 +63,7 @@ export function Sidebar() {// A host without the feed has no Notifications page.if (item.to === "/notifications" && notifications.unsupported) return null;const shortcut = item.command ? bindingFor(item.command) : undefined;- const link = (+ return (<Linkkey={item.to}to={item.to}@@ -93,14 +93,6 @@ export function Sidebar() {)}</Link>);- return item.to === "/spaces" && tree ? (- <div key={item.to} className="flex flex-col gap-px">- {link}- <SidebarTree tree={tree} />- </div>- ) : (- link- );})}</nav>{/* A spacer, not a wrapper pushed down: what appears at the foot (a tip, the account) growsdiff --git a/apps/cua-spaces-web/src/components/spaces/spaces-tree-page.tsx b/apps/cua-spaces-web/src/components/spaces/spaces-tree-page.tsxindex 833731f729..dc6ff4b6a7 100644--- a/apps/cua-spaces-web/src/components/spaces/spaces-tree-page.tsx+++ b/apps/cua-spaces-web/src/components/spaces/spaces-tree-page.tsx@@ -18,7 +18,7 @@ import { Menu, type MenuItem } from "@/components/ui/menu";import { toast, toastError } from "@/components/ui/toast";import { useNewSpace } from "@/hooks/use-new-space";import { plural } from "@/lib/plural";-import { treeSummary, type TreeNode } from "@/lib/spaces-tree";+import { foldOffline, treeSummary, type TreeNode } from "@/lib/spaces-tree";import { cn } from "@/lib/utils";import { PeopleFaces, TreeDot, TreeIcon, toggleCollapsed, useCollapsed } from "./tree-parts";@@ -81,6 +81,8 @@ export function SpacesTreePage() {const [editing, setEditing] = useState<{ key: string; name: string } | null>(null);const [removing, setRemoving] = useState<TreeNode | null>(null);const [deleting, setDeleting] = useState<TreeNode | null>(null);+ // Offline computers with nothing on them sit folded in one "N offline" row until it's opened.+ const [showOffline, setShowOffline] = useState(false);// A click on a name waits out the double-click time before opening (see clickName below).const clickTimer = useRef<ReturnType<typeof setTimeout> | null>(null);const cancelClick = () => {@@ -245,6 +247,26 @@ export function SpacesTreePage() {};const single = tree.computers === 1 && tree.spaces === 0;+ const { shown, folded } = foldOffline(tree.roots);+ const branch = (r: TreeNode) => [rowFor(r, 0), ...(collapsed.has(r.key) ? [] : r.children.map((c) => rowFor(c, 1)))];+ const offlineRow =+ folded.length > 0 ? (+ <div key="offline" role="row" data-tree-offline-fold="" className={cn(COLS, "min-h-12 px-4 py-1.5 text-[14px] text-muted-foreground")}>+ <div role="cell" className="col-span-5 flex min-w-0 items-center gap-2.5">+ <button+ type="button"+ aria-expanded={showOffline}+ onClick={() => setShowOffline((v) => !v)}+ className="-ml-5 flex min-w-0 items-center gap-2.5 text-left outline-none hover:text-foreground focus-visible:underline"+ data-tree-offline-toggle=""+ >+ <ChevronRightIcon className={cn("size-3.5 shrink-0 transition-transform", showOffline && "rotate-90")} />+ <span className="shrink-0 font-medium text-foreground">{folded.length} offline</span>+ {showOffline ? null : <span className="min-w-0 truncate">{folded.map((n) => n.name).join(", ")}</span>}+ </button>+ </div>+ </div>+ ) : null;return (<Page><PageHeader title="Spaces" description={editing ? "Double-click a name, or pick Rename from its menu." : treeSummary(tree)} actions={addButton} />@@ -256,7 +278,11 @@ export function SpacesTreePage() {<div role="columnheader">Agent tasks</div><div role="columnheader" aria-label="Actions" /></div>- <GroupedSection role="rowgroup">{tree.roots.flatMap((r) => [rowFor(r, 0), ...(collapsed.has(r.key) ? [] : r.children.map((c) => rowFor(c, 1)))])}</GroupedSection>+ <GroupedSection role="rowgroup">+ {shown.flatMap(branch)}+ {offlineRow}+ {showOffline ? folded.map((r) => rowFor(r, 0)) : null}+ </GroupedSection></div>{editing ? <p className="mt-4 text-[13px] text-muted-foreground">{RENAME_NOTE}</p> : null}{single ? (diff --git a/apps/cua-spaces-web/src/components/spaces/tree-parts.tsx b/apps/cua-spaces-web/src/components/spaces/tree-parts.tsxindex 93876176aa..8189c9b2e3 100644--- a/apps/cua-spaces-web/src/components/spaces/tree-parts.tsx+++ b/apps/cua-spaces-web/src/components/spaces/tree-parts.tsx@@ -64,7 +64,7 @@ function load(): ReadonlySet<string> {return cache;}-/** Folds or unfolds a computer in every tree (the sidebar and the Spaces page). */+/** Folds or unfolds a computer on the Spaces page (remembered on this device). */export function toggleCollapsed(key: string): void {const next = new Set(load());if (next.has(key)) next.delete(key);diff --git a/apps/cua-spaces-web/src/components/spaces/use-spaces-tree.ts b/apps/cua-spaces-web/src/components/spaces/use-spaces-tree.tsindex b03d403b50..d4c4253c1e 100644--- a/apps/cua-spaces-web/src/components/spaces/use-spaces-tree.ts+++ b/apps/cua-spaces-web/src/components/spaces/use-spaces-tree.ts@@ -31,7 +31,7 @@ export function useSpacesTreeData(running: ReadonlyMap<string, number> = NO_RUNSconst on = useSpacesTree();const { data: spaces, listStatus } = useSpaces();const { data: machines, refresh: refreshMachines } = useMachines();- // The tree is always on screen, so nothing else asks for the computers again: without this a computer that went+ // The sidebar counts the tree on every page, so nothing else asks for the computers again: without this a computer that went// offline keeps its green dot (and "Online, Default") while Home already says it is offline.useEffect(() => {if (!on) return;diff --git a/apps/cua-spaces-web/src/lib/spaces-tree.test.ts b/apps/cua-spaces-web/src/lib/spaces-tree.test.tsindex 7bd81cfa46..260f03e143 100644--- a/apps/cua-spaces-web/src/lib/spaces-tree.test.ts+++ b/apps/cua-spaces-web/src/lib/spaces-tree.test.ts@@ -6,7 +6,7 @@ import { describe, expect, it } from "vitest";import { resolveDefaultSpace, type Machine, type Space } from "@/bridge";import { currentTreeWhere, fallbackSentence, newSpaceTargets, treeDefault } from "./default-where";-import { buildSpacesTree, defaultCandidates, findNode, treeRows, treeSummary } from "./spaces-tree";+import { buildSpacesTree, defaultCandidates, findNode, foldOffline, treeRows, treeSummary } from "./spaces-tree";const NOW = Date.parse("2026-11-04T12:00:00Z");@@ -129,6 +129,27 @@ describe("buildSpacesTree", () => {});});+describe("foldOffline", () => {+ const old = (i: number) => machine({ id: `old-${i}`, name: `Old box ${i}`, online: false, os: "linux", lastSeen: Math.floor((NOW - 86_400_000) / 1000) });+ const oldSpaces = (n: number) => Array.from({ length: n }, (_, i) => space({ id: `relay:old-${i}`, name: `Old box ${i}` }));++ it("folds offline computers with nothing on them into one row at the end, keeping This Mac, the default and computers with Spaces", () => {+ const olds = [0, 1, 2, 3].map(old);+ const t = tree({ machines: [THIS_MAC, { ...STUDIO, online: false }, DILLON, ...olds], spaces: [...SPACES, ...oldSpaces(4)], defaultSpace: "relay:old-0" });+ const { shown, folded } = foldOffline(t.roots);+ // Studio is offline but has Spaces on it; Old box 0 is the default: both stay in the list.+ expect(shown.map((r) => r.name)).toEqual(["This Mac", "Studio Mac mini", "Dillon's PC", "Old box 0"]);+ expect(folded.map((r) => r.name)).toEqual(["Old box 1", "Old box 2", "Old box 3"]);+ });++ it("leaves a single offline computer where it is", () => {+ const t = tree({ machines: [THIS_MAC, STUDIO, DILLON, old(0)], spaces: [...SPACES, ...oldSpaces(1)] });+ const { shown, folded } = foldOffline(t.roots);+ expect(folded).toEqual([]);+ expect(shown.map((r) => r.name)).toEqual(["This Mac", "Studio Mac mini", "Dillon's PC", "Old box 0"]);+ });+});+describe("treeDefault", () => {const settings = (defaultSpace: string | null, fallback: string[] = [], fallbackOn = true) => ({ defaultSpace, fallback, fallbackOn, updatedAt: 0 });diff --git a/apps/cua-spaces-web/src/lib/spaces-tree.ts b/apps/cua-spaces-web/src/lib/spaces-tree.tsindex cd706ff8b3..d288d6bf67 100644--- a/apps/cua-spaces-web/src/lib/spaces-tree.ts+++ b/apps/cua-spaces-web/src/lib/spaces-tree.ts@@ -227,6 +227,23 @@ export function buildSpacesTree({ spaces, machines, defaultSpace, running = new};}+/** Fewer offline computers than this stay in the list as they are. */+export const OFFLINE_FOLD_MIN = 2;++/**+ * The Spaces page's top rows, with idle offline computers kept apart: an+ * offline computer with no Spaces on it that isn't This Mac or the default+ * folds into one "N offline" row at the end, so an account with many old+ * computers still reads at a glance. Fewer than `OFFLINE_FOLD_MIN` fold+ * into nothing.+ */+export function foldOffline(roots: readonly TreeNode[]): { shown: TreeNode[]; folded: TreeNode[] } {+ const idle = (n: TreeNode) => n.kind === "computer" && !n.online && !n.current && !n.isDefault && n.children.length === 0;+ const folded = roots.filter(idle);+ if (folded.length < OFFLINE_FOLD_MIN) return { shown: [...roots], folded: [] };+ return { shown: roots.filter((n) => !idle(n)), folded };+}+/** Every row, depth first. */export function treeRows(tree: Pick<SpacesTree, "roots">): TreeNode[] {return tree.roots.flatMap((r) => [r, ...r.children]);