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): Share and Add an agent lead to each other (#6053)
ddupontb661cfa468c2
diff --git a/apps/cua-spaces-web/src/__tests__/add-agent.test.tsx b/apps/cua-spaces-web/src/__tests__/add-agent.test.tsxindex 1d6d587524..db128fbcd2 100644--- a/apps/cua-spaces-web/src/__tests__/add-agent.test.tsx+++ b/apps/cua-spaces-web/src/__tests__/add-agent.test.tsx@@ -58,11 +58,13 @@ async function openSheet(row?: "start" | "connect") {const line = () => q("[data-join-line]") as HTMLTextAreaElement | null;describe("Add an agent", () => {- it("+ opens two rows and the marks of the agents that work", async () => {+ it("+ opens two rows, Share with a person, and the marks of the agents that work", async () => {await app({ joinRedeemMs: null });await openSheet();expect(q("[data-add-agent='pick']")?.textContent).toContain("Add an agent to ubuntu-build");- expect(qa("[data-add-row]").map((r) => r.dataset.addRow)).toEqual(["start", "connect"]);+ // Share with a person leads back to Share, where the page can share.+ expect(qa("[data-add-row]").map((r) => r.dataset.addRow)).toEqual(["start", "connect", "share"]);+ expect(q("[data-add-row='share']")?.textContent).toContain("Share with a person");expect(qa("[data-add-agent-marks] [data-harness-mark]").map((m) => m.dataset.harnessMark)).toEqual(["hermes", "claude-code", "codex", "cursor", "openclaw", "t3code"]);});diff --git a/apps/cua-spaces-web/src/__tests__/share-add-agent.test.tsx b/apps/cua-spaces-web/src/__tests__/share-add-agent.test.tsxnew file mode 100644index 0000000000..9fde05cb8f--- /dev/null+++ b/apps/cua-spaces-web/src/__tests__/share-add-agent.test.tsx@@ -0,0 +1,75 @@+// SPDX-License-Identifier: FSL-1.1-MIT+// Copyright (c) 2026 Cua AI, Inc.++// Share and Add an agent lead to each other on the redesigned Space page:+// Share's footer has "Add an agent" left of Done, and Add an agent has+// "Share with a person". Each replaces the other (one dialog at a time,+// focus in the one that opened, Escape closes it). With the redesign off+// the Share sheet stays as it was.++import { act, cleanup, fireEvent, screen, waitFor } from "@testing-library/react";+import { afterEach, describe, expect, it, vi } from "vitest";++import { wasmBuilt } from "@/bridge/__tests__/testCore";+import { DEMO_THREAD_SPACE } from "@/bridge/adapters/demo/thread";+import { mountApp, stubBrowserApis } from "./app-harness";++stubBrowserApis();+afterEach(() => {+ cleanup();+ vi.unstubAllEnvs();+});++const HOST = { failsCreates: false, listsGhost: false };+const path = `/spaces/${encodeURIComponent(DEMO_THREAD_SPACE)}`;+const q = (sel: string) => document.querySelector<HTMLElement>(sel);+const dialogs = () => document.querySelectorAll("[role=dialog]").length;+const flag = (on: boolean) => vi.stubEnv("VITE_CUA_FLAG_SPACES_REDESIGN", on ? "1" : "0");++async function openShare() {+ const share = await screen.findAllByRole("button", { name: "Share" });+ await act(async () => {+ fireEvent.click(share[0]!);+ });+ await waitFor(() => expect(q("[data-share-sheet]")).not.toBeNull());+}++describe.skipIf(!wasmBuilt)("Share and Add an agent", () => {+ it("redesign: Share opens Add an agent in its place, and Add an agent opens Share back", async () => {+ flag(true);+ await mountApp(path, HOST);+ await waitFor(() => expect(q("[data-composer]")).not.toBeNull());+ await openShare();+ const add = await waitFor(() => {+ const b = q("[data-share-add-agent]");+ expect(b).not.toBeNull();+ return b!;+ });+ expect(add.textContent).toBe("Add an agent");+ // Left of Done, in the footer.+ expect(add.nextElementSibling?.textContent).toBe("Done");+ await act(async () => {+ fireEvent.click(add);+ });+ await waitFor(() => expect(q("[data-add-agent]")).not.toBeNull());+ await waitFor(() => expect(q("[data-share-sheet]")).toBeNull());+ expect(dialogs()).toBe(1);+ expect(document.body.textContent).toContain("Add an agent to");++ await act(async () => {+ fireEvent.click(q("[data-add-row=share]")!);+ });+ await waitFor(() => expect(q("[data-share-sheet]")).not.toBeNull());+ await waitFor(() => expect(q("[data-add-agent]")).toBeNull());+ expect(dialogs()).toBe(1);+ });++ it("redesign off: the Share sheet has no Add an agent", async () => {+ flag(false);+ await mountApp(path, HOST);+ await waitFor(() => expect(document.body.textContent).toContain("ubuntu-build"));+ await openShare();+ expect(q("[data-share-add-agent]")).toBeNull();+ expect(screen.getByRole("button", { name: "Done" })).toBeTruthy();+ });+});diff --git a/apps/cua-spaces-web/src/components/add-agent/add-agent-launcher.ts b/apps/cua-spaces-web/src/components/add-agent/add-agent-launcher.tsnew file mode 100644index 0000000000..5490cf712c--- /dev/null+++ b/apps/cua-spaces-web/src/components/add-agent/add-agent-launcher.ts@@ -0,0 +1,31 @@+// SPDX-License-Identifier: FSL-1.1-MIT+// Copyright (c) 2026 Cua AI, Inc.++/**+ * Who can open "Add an agent" for a Space right now. The Space page's call+ * layout registers its own opener while it shows (and while you may add+ * agents there); the Share sheet, which opens from anywhere, offers+ * "Add an agent" only when the Space it shares has one. Pages without the+ * thread (the classic Space page, the Spaces list's menu) register none, so+ * their Share sheet stays as it was.+ */++import { create } from "zustand";++const useLaunchers = create<{ bySpace: Record<string, () => void> }>(() => ({ bySpace: {} }));++/** Registers `open` for `spaceId`; returns the unregister. */+export function registerAddAgent(spaceId: string, open: () => void): () => void {+ useLaunchers.setState((s) => ({ bySpace: { ...s.bySpace, [spaceId]: open } }));+ return () =>+ useLaunchers.setState((s) => {+ if (s.bySpace[spaceId] !== open) return s;+ const { [spaceId]: _gone, ...rest } = s.bySpace;+ return { bySpace: rest };+ });+}++/** The opener for `spaceId`, when its page offers one. */+export function useAddAgentLauncher(spaceId: string | null | undefined): (() => void) | null {+ return useLaunchers((s) => (spaceId ? (s.bySpace[spaceId] ?? null) : null));+}diff --git a/apps/cua-spaces-web/src/components/add-agent/add-agent-sheet.tsx b/apps/cua-spaces-web/src/components/add-agent/add-agent-sheet.tsxindex 1dd3476cc7..2b6d5a31e9 100644--- a/apps/cua-spaces-web/src/components/add-agent/add-agent-sheet.tsx+++ b/apps/cua-spaces-web/src/components/add-agent/add-agent-sheet.tsx@@ -13,7 +13,7 @@* New agent opens it with `spaces`, and the title becomes a Space picker.*/-import { CheckIcon, ChevronLeftIcon, ChevronRightIcon, LinkIcon, Loader2Icon, PlayIcon } from "lucide-react";+import { CheckIcon, ChevronLeftIcon, ChevronRightIcon, LinkIcon, Loader2Icon, PlayIcon, UserPlusIcon } from "lucide-react";import { useEffect, useMemo, useRef, useState, type ReactNode } from "react";import { threadOpAvailable, useBridge, type ThreadRole } from "@/bridge";@@ -69,6 +69,7 @@ export function AddAgentSheet({role,taken = [],initialStage = "pick",+ onShare,}: {open: boolean;onOpenChange: (open: boolean) => void;@@ -83,6 +84,8 @@ export function AddAgentSheet({taken?: readonly string[];/** Open straight on a row (the Agents tab's empty state). */initialStage?: Stage;+ /** Share the Space with a person or your team instead (this sheet gives way to Share). */+ onShare?: () => void;}) {const { data } = useBridge();const [stage, setStage] = useState<Stage>("pick");@@ -148,6 +151,7 @@ export function AddAgentSheet({disabled={!canConnect || !space}onClick={() => setStage("connect")}/>+ {onShare ? <Row data="share" icon={<UserPlusIcon className="size-3.5" />} title="Share with a person" detail="Or with your team" onClick={onShare} /> : null}</div><div className="mt-4 flex items-center justify-between gap-4"><span className="flex items-center gap-1" data-add-agent-marks="">diff --git a/apps/cua-spaces-web/src/components/share-sheet.tsx b/apps/cua-spaces-web/src/components/share-sheet.tsxindex 93a93eab5a..f028dd27b5 100644--- a/apps/cua-spaces-web/src/components/share-sheet.tsx+++ b/apps/cua-spaces-web/src/components/share-sheet.tsx@@ -11,6 +11,7 @@ import {useShareSheet,useTeamChoices,} from "@/bridge";+import { useAddAgentLauncher } from "@/components/add-agent/add-agent-launcher";import { Button } from "@/components/ui/button";import { GroupedRow, GroupedSection } from "@/components/ui/grouped";import { Dialog, DialogPopup, DialogTitle } from "@/components/ui/dialog";@@ -36,6 +37,8 @@ export default function ShareSheet() {const { openExternal } = useSession();const { hasTeam } = choices;const cards = useFlag("upsell_cards");+ // The Space page that shows this Space's thread can add an agent to it instead.+ const addAgent = useAddAgentLauncher(session?.input.spaceId);useEffect(() => {sharing?.setHasTeam(hasTeam);}, [sharing, hasTeam, session?.input.spaceId]);@@ -152,6 +155,19 @@ export default function ShareSheet() {) : null}</div><div /* design-ok: full-width dialog footer */ className="flex items-center justify-end gap-2 border-t bg-muted/60 px-5 py-3">+ {addAgent ? (+ <Button+ variant="outline"+ data-share-add-agent=""+ onClick={() => {+ // One sheet at a time: this one closes, then Add an agent opens in its place.+ sharing.close();+ addAgent();+ }}+ >+ Add an agent+ </Button>+ ) : null}<Button onClick={() => sharing.close()}>{v.doneLabel}</Button></div></DialogPopup>diff --git a/apps/cua-spaces-web/src/components/space-thread/space-call.tsx b/apps/cua-spaces-web/src/components/space-thread/space-call.tsxindex 57b10948db..2960d6247b 100644--- a/apps/cua-spaces-web/src/components/space-thread/space-call.tsx+++ b/apps/cua-spaces-web/src/components/space-thread/space-call.tsx@@ -2,13 +2,14 @@// Copyright (c) 2026 Cua AI, Inc.import { XIcon } from "lucide-react";-import { useMemo, useState, type ReactNode } from "react";+import { useEffect, useMemo, useState, type ReactNode } from "react";import { harnessName, useBridge, type SpaceFact, type SpaceThread, type StreamRow, type ThreadAttachment, type ThreadView as PostView } from "@/bridge";import { Dialog, DialogPopup, DialogTitle } from "@/components/ui/dialog";import { toast } from "@/components/ui/toast";import { AddAgentSheet } from "@/components/add-agent/add-agent-sheet";+import { registerAddAgent } from "@/components/add-agent/add-agent-launcher";import { CallSplit } from "./call-split";import { Composer } from "./composer";@@ -42,6 +43,7 @@ export function SpaceCall({view,onStream,presence,+ onShare,}: {/** The Space's id (Add an agent joins agents to it). */spaceId: string;@@ -68,6 +70,8 @@ export function SpaceCall({/** Opens a row in its own window. */onStream: (row: StreamRow) => void;presence?: MemberPresence;+ /** Opens Share for this Space (Add an agent offers it; absent: sharing isn't offered here). */+ onShare?: () => void;}) {const { core, data } = useBridge();const [folded, setFolded] = useState(false);@@ -77,6 +81,10 @@ export function SpaceCall({() => buildRoster({ members: thread.members, shares: thread.shares, entries: thread.entries, me: thread.me, identity, role: thread.role, harnessName: (h) => harnessName(core, h) }),[thread.members, thread.shares, thread.entries, thread.me, thread.role, identity, core],);+ // Anyone who can post can add an agent; a guest only reads.+ const canAddAgent = thread.status === "ready" && thread.role !== "guest";+ // Share's "Add an agent" opens this page's sheet for this Space.+ useEffect(() => (canAddAgent ? registerAddAgent(spaceId, () => setAddOpen(true)) : undefined), [canAddAgent, spaceId]);const harnessOf = (handle: string) => roster.agents.find((a) => a.name === handle)?.harness ?? "";// Attachments are Cua Volume paths: show the file where the Volume is mounted.const openAttachment = (a: ThreadAttachment) => {@@ -140,11 +148,20 @@ export function SpaceCall({// The owner and admins change agents' rights (a daemon that does not say your role: you are its owner).onSetRights={thread.role === null || thread.role === "owner" || thread.role === "admin" ? thread.setRights : undefined}onRemoveAgent={thread.removeAgent ?? undefined}- // Anyone who can post can add an agent; a guest only reads.- onAddAgent={thread.status === "ready" && thread.role !== "guest" ? () => setAddOpen(true) : undefined}+ onAddAgent={canAddAgent ? () => setAddOpen(true) : undefined}/></div>- <AddAgentSheet open={addOpen} onOpenChange={setAddOpen} space={{ id: spaceId, name: spaceName }} role={thread.role} taken={roster.agents.map((a) => a.name)} />+ <AddAgentSheet open={addOpen} onOpenChange={setAddOpen} space={{ id: spaceId, name: spaceName }} role={thread.role} taken={roster.agents.map((a) => a.name)}+ onShare={+ onShare+ ? () => {+ // One sheet at a time: this one closes, then Share opens in its place.+ setAddOpen(false);+ onShare();+ }+ : undefined+ }+ /><Dialog open={moreOpen} onOpenChange={setMoreOpen}><DialogPopup data-call-more-sheet="" className="top-[8vh] flex max-h-[84vh] w-[min(820px,calc(100vw-2rem))] flex-col"><div className="flex h-12 shrink-0 items-center justify-between border-b pr-3 pl-5">diff --git a/apps/cua-spaces-web/src/routes/spaces/$spaceId.tsx b/apps/cua-spaces-web/src/routes/spaces/$spaceId.tsxindex a33dd910af..8894ca27c3 100644--- a/apps/cua-spaces-web/src/routes/spaces/$spaceId.tsx+++ b/apps/cua-spaces-web/src/routes/spaces/$spaceId.tsx@@ -451,6 +451,7 @@ function SpaceDetailPage() {onSelect={(row) => setShown(row.kind === "window" ? { spaceId: space.id, row: row.id } : null)}view={shownView}onStream={(row) => void onPip(row)}+ onShare={shareAction?.enabled ? share : undefined}/>{dialogs}</>