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
fix(spaces): Start an agent here uses real harness ids, teleport honors --profile (CUA-2857, CUA-2853) (#6178)
ddupont23c168b06aae
diff --git a/apps/cua-spaces-web/src/__tests__/add-agent.test.tsx b/apps/cua-spaces-web/src/__tests__/add-agent.test.tsxindex d18a9efe6d..87663648d9 100644--- a/apps/cua-spaces-web/src/__tests__/add-agent.test.tsx+++ b/apps/cua-spaces-web/src/__tests__/add-agent.test.tsx@@ -68,10 +68,10 @@ describe("Add an agent", () => {expect(qa("[data-add-agent-marks] [data-harness-mark]").map((m) => m.dataset.harnessMark)).toEqual(["hermes", "claude-code", "codex", "cursor", "openclaw", "t3code"]);});- it("Start an agent here: Hermes, Claude Code, Codex, Cursor, then OpenClaw; a free name; it joins asleep", async () => {+ it("Start an agent here: Hermes, Claude Code, Codex, then OpenClaw; a free name; it joins asleep", async () => {await app({ joinRedeemMs: null });await openSheet("start");- expect(qa("[data-start-harness]").map((h) => h.dataset.startHarness)).toEqual(["hermes", "claude-code", "codex", "cursor", "openclaw"]);+ expect(qa("[data-start-harness]").map((h) => h.dataset.startHarness)).toEqual(["hermes", "claude-code", "openai-codex", "openclaw"]);// Hermes is taken: the name moves on.expect((q("[data-start-name]") as HTMLInputElement).value).toBe("hermes-2");await click(q("[data-start-harness='openclaw']")!);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 2b6d5a31e9..67b5e028b1 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@@ -17,7 +17,7 @@ import { CheckIcon, ChevronLeftIcon, ChevronRightIcon, LinkIcon, Loader2Icon, Plimport { useEffect, useMemo, useRef, useState, type ReactNode } from "react";import { threadOpAvailable, useBridge, type ThreadRole } from "@/bridge";-import { HarnessMark, HARNESSES } from "@/components/space-thread/harness-marks";+import { HarnessMark, HARNESSES, harnessInfo } from "@/components/space-thread/harness-marks";import { Button } from "@/components/ui/button";import { Dialog, DialogDescription, DialogPopup, DialogTitle } from "@/components/ui/dialog";import { Input } from "@/components/ui/input";@@ -37,11 +37,16 @@ export interface AddAgentSpace {type Stage = "pick" | "start" | "connect";export type AddAgentStage = Stage;-/** Start an agent here lists these, in this order. */-export const START_HARNESSES = ["hermes", "claude-code", "codex", "cursor", "openclaw"] as const;-const START_NAMES: Record<string, string> = { hermes: "Hermes Agent", "claude-code": "Claude Code", codex: "Codex CLI", cursor: "Cursor CLI", openclaw: "OpenClaw" };-const SHORT: Record<string, string> = { hermes: "Hermes", "claude-code": "Claude Code", codex: "Codex", cursor: "Cursor", openclaw: "OpenClaw" };-const HANDLE: Record<string, string> = { hermes: "hermes", "claude-code": "claude", codex: "codex", cursor: "cursor", openclaw: "openclaw" };+/**+ * Start an agent here lists these, in this order. Each is a harness id of the+ * Rust registry (`cua_agents::harness`), the id `agent_add` takes verbatim;+ * a drift guard test keeps the two in step. Cursor and T3 Code are not+ * harnesses a Space can start, so they are not offered here.+ */+export const START_HARNESSES = ["hermes", "claude-code", "openai-codex", "openclaw"] as const;+const START_NAMES: Record<string, string> = { hermes: "Hermes Agent", "claude-code": "Claude Code", "openai-codex": "Codex CLI", openclaw: "OpenClaw" };+const SHORT: Record<string, string> = { hermes: "Hermes", "claude-code": "Claude Code", "openai-codex": "Codex", openclaw: "OpenClaw" };+const HANDLE: Record<string, string> = { hermes: "hermes", "claude-code": "claude", "openai-codex": "codex", openclaw: "openclaw" };/** A free handle for a new member: `hermes`, else `hermes-2`, ... */export function freeHandle(base: string, taken: readonly string[]): string {@@ -253,7 +258,7 @@ function StartAgent({ space, taken, title, onDone }: { space: AddAgentSpace; tak<HarnessMark harness={h} px={24} /></span><span className="text-[13px]">{START_NAMES[h]}</span>- <span className="flex-1 text-xs text-muted-foreground">{HARNESSES.find((x) => x.id === h)?.maker}</span>+ <span className="flex-1 text-xs text-muted-foreground">{harnessInfo(h)?.maker}</span>{harness === h ? <CheckIcon className="size-4 text-brand" /> : null}</button>))}diff --git a/libs/cua/crates/cua-agents/src/harness.rs b/libs/cua/crates/cua-agents/src/harness.rsindex 6cf809e745..23ca5fa1b9 100644--- a/libs/cua/crates/cua-agents/src/harness.rs+++ b/libs/cua/crates/cua-agents/src/harness.rs@@ -283,8 +283,15 @@ impl Harness {}}-/// A harness by id.+/// Short names people and apps use for a harness, and the id they mean.+const ALIASES: &[(&str, &str)] = &[("codex", "openai-codex"), ("claude", "claude-code")];++/// A harness by id (or by one of its short names: `codex`, `claude`).pub fn harness(id: &str) -> Option<&'static Harness> {+ let id = ALIASES+ .iter()+ .find(|(a, _)| *a == id)+ .map_or(id, |(_, c)| c);HARNESSES.iter().find(|h| h.id == id)}@@ -916,6 +923,15 @@ impl Harness {mod tests {use super::*;+ #[test]+ fn short_names_resolve_to_the_registry_id() {+ assert_eq!(harness("codex").unwrap().id, "openai-codex");+ assert_eq!(harness("claude").unwrap().id, "claude-code");+ assert_eq!(harness("openai-codex").unwrap().id, "openai-codex");+ assert!(harness("cursor").is_none());+ assert!(ids().iter().all(|id| ALIASES.iter().all(|(a, _)| a != id)));+ }+#[test]fn every_harness_installs_known_items_and_links_its_acp_binary() {for h in HARNESSES {diff --git a/libs/cua/crates/cua-spaces-cli/src/teleport.rs b/libs/cua/crates/cua-spaces-cli/src/teleport.rsindex 63537d2dfc..0cf2100844 100644--- a/libs/cua/crates/cua-spaces-cli/src/teleport.rs+++ b/libs/cua/crates/cua-spaces-cli/src/teleport.rs@@ -157,17 +157,6 @@ async fn push_through_keyvault(json: bool,out: &mut dyn Write,) -> Result<i32, CuaError> {- if args.app.profile.is_some() {- // The daemon's own Keyvault capture has no per-call profile- // selection yet (it always reads the machine's default Chrome- // profile) -- refuse rather than silently ignore an explicit- // --profile, which `--url` mode still honors in full.- return Err(CuaError::Unsupported(- "--profile is not supported for a --sandbox push yet (the Keyvault always reads \- the default profile); use --url for a specific profile"- .into(),- ));- }let t = teleporter(host, &args.app);let app_ref = app_ref(&args.app);let scope_v = scope(&args.app)?;@@ -206,7 +195,7 @@ async fn push_through_keyvault(}let spec = cua_keyvault::broker::ImportSpec {app: manifest.provider_id.clone(),- profile: None,+ profile: args.app.profile.clone(),sites: vec![],whole_app: true,cookies: cua_keyvault::broker::CookieFilter::default(),diff --git a/libs/cua/crates/cua-spaces-ext/src/daemon/keyvault.rs b/libs/cua/crates/cua-spaces-ext/src/daemon/keyvault.rsindex 05de8b50e4..e3fb488f9f 100644--- a/libs/cua/crates/cua-spaces-ext/src/daemon/keyvault.rs+++ b/libs/cua/crates/cua-spaces-ext/src/daemon/keyvault.rs@@ -78,8 +78,15 @@ pub struct DaemonBackend {/// Decrypt saved passwords with this platform's scheme (default: this/// machine's).platform: cua_teleport::Platform,+ /// Builds the providers for a capture of a named browser profile+ /// (`--profile "Profile 1"`); tests swap in hermetic ones.+ profiled: ProfiledSessions,}+/// Providers acting on a host with one browser profile selected.+pub type ProfiledSessions =+ Arc<dyn Fn(Arc<dyn cua_teleport::HostEffects>, &str) -> AppSessions + Send + Sync>;+impl DaemonBackend {/// A backend over the daemon's Spaces registry and teleport providers.pub fn new(spaces: Spaces, sessions: Arc<AppSessions>) -> Self {@@ -88,9 +95,24 @@ impl DaemonBackend {sessions,host: cua_teleport::default_host(),platform: cua_teleport::Platform::current(),+ profiled: Arc::new(|host, profile| {+ AppSessions::from_registry(+ cua_teleport::ExportRegistry::with_builtin_host_and_chrome_profile(+ host,+ Some(profile.to_string()),+ ),+ )+ }),}}+ /// Uses `build` for the providers of a named browser profile instead of+ /// the built-in ones.+ pub fn with_profiled_sessions(mut self, build: ProfiledSessions) -> Self {+ self.profiled = build;+ self+ }+/// Reads saved passwords through `host` instead of the real machine.pub fn with_host(mut self, host: Arc<dyn cua_teleport::HostEffects>) -> Self {self.host = host;@@ -177,10 +199,20 @@ impl DaemonBackend {fn export_entries(&self,app: &str,+ profile: Option<&str>,override_paths: Option<&[String]>,) -> KvResult<(String, String, Vec<PayloadEntry>)> {- let manifest = self- .sessions+ // An explicit browser profile (`--profile "Profile 1"`) is read by a+ // provider set up for it; without one, the daemon's own providers.+ let named;+ let sessions: &AppSessions = match profile.map(str::trim).filter(|p| !p.is_empty()) {+ Some(p) => {+ named = (self.profiled)(self.host.clone(), p);+ &named+ }+ None => &self.sessions,+ };+ let manifest = sessions.manifest(app, TeleportScope::Full).map_err(|e| backend_err("read manifest", e))?;let paths: Vec<String> = if let Some(p) = override_paths {@@ -206,7 +238,7 @@ impl DaemonBackend {.approving("vault-import", &paths, true).map_err(|e| backend_err("mint approval", e))?;let mut buf: Vec<u8> = Vec::new();- self.sessions+ sessions.export(&approval, &mut buf).map_err(|e| backend_err("export session", e))?;let reader =@@ -606,7 +638,8 @@ impl Backend for DaemonBackend {// or an app's files), turned into records by the app's codec. A// consent-gated file is only exported when the user picked it.if spec.whole_app {- let (scope, name, entries) = self.export_entries(&spec.app, spec.paths.as_deref())?;+ let (scope, name, entries) =+ self.export_entries(&spec.app, spec.profile.as_deref(), spec.paths.as_deref())?;display = name;let exported = record::codec_for(&provider_id).export(entries,diff --git a/libs/cua/crates/cua-spaces-ext/tests/keyvault_items.rs b/libs/cua/crates/cua-spaces-ext/tests/keyvault_items.rsindex 304b3e3eb8..6e4dbd9733 100644--- a/libs/cua/crates/cua-spaces-ext/tests/keyvault_items.rs+++ b/libs/cua/crates/cua-spaces-ext/tests/keyvault_items.rs@@ -31,6 +31,9 @@ use cua_teleport::{/// and a consent-gated `Web Data`.struct Browser {host: Arc<dyn HostEffects>,+ /// The browser profile it reads (`None`: Default), written into the+ /// bytes of each file so a test can tell which profile was captured.+ profile: Option<String>,}const PATHS: [&str; 4] = [@@ -100,7 +103,15 @@ impl ExportProvider for Browser {"Default/Web Data",] {if wants(p) {- w.add_bytes(p, 0o600, format!("bytes of {p}").as_bytes())?;+ w.add_bytes(+ p,+ 0o600,+ match &self.profile {+ Some(profile) => format!("bytes of {p} from {profile}"),+ None => format!("bytes of {p}"),+ }+ .as_bytes(),+ )?;}}if wants("Default/Cookies") {@@ -136,6 +147,7 @@ fn backend() -> (DaemonBackend, tempfile::TempDir) {let mut registry = ExportRegistry::new();registry.register(Box::new(Browser {host: Arc::new(FakeHost::new()),+ profile: None,}));let sessions = Arc::new(AppSessions::from_registry(registry));(DaemonBackend::new(spaces, sessions), reg)@@ -288,7 +300,10 @@ fn the_inventory_counts_cookies_per_site_without_decrypting_anything() {.build();let host: Arc<dyn HostEffects> = Arc::new(FakeHost::new().with_home(home.path()));let mut registry = ExportRegistry::new();- registry.register(Box::new(Browser { host: host.clone() }));+ registry.register(Box::new(Browser {+ host: host.clone(),+ profile: None,+ }));let b = DaemonBackend::new(spaces, Arc::new(AppSessions::from_registry(registry))).with_host(host).with_platform(Platform::MacOS);@@ -376,3 +391,44 @@ fn a_teleport_reads_only_the_passwords_of_the_sites_picked_for_them() {};assert!(logins(&none).is_empty(), "not ticked: no password at all");}++/// `--profile "Profile 1"` reaches the capture: the whole-app export reads+/// the named profile, not Default, and without a profile it reads Default.+#[test]+fn a_named_browser_profile_is_the_one_captured() {+ let (b, _reg) = backend();+ let b = b.with_profiled_sessions(Arc::new(|host, profile| {+ let mut registry = ExportRegistry::new();+ registry.register(Box::new(Browser {+ host,+ profile: Some(profile.to_string()),+ }));+ AppSessions::from_registry(registry)+ }));+ let files = |profile: Option<&str>| -> Vec<String> {+ let spec = ImportSpec {+ profile: profile.map(str::to_string),+ ..spec(&["Default/Bookmarks"])+ };+ b.capture(&spec)+ .unwrap()+ .iter()+ .filter(|c| c.meta.kind == ItemKind::File)+ .map(|c| {+ use base64::Engine as _;+ let rec: serde_json::Value = serde_json::from_str(&c.payload.record).unwrap();+ let bytes = base64::engine::general_purpose::STANDARD+ .decode(rec["content"].as_str().unwrap())+ .unwrap();+ String::from_utf8(bytes).unwrap()+ })+ .collect()+ };+ let default = files(None);+ let named = files(Some("Profile 1"));+ assert_eq!(default.len(), 1);+ assert_eq!(named.len(), 1);+ assert_ne!(default, named, "the named profile is not Default");+ assert!(!default[0].contains("Profile 1"), "{default:?}");+ assert!(named[0].contains("Profile 1"), "{named:?}");+}diff --git a/libs/cua/crates/cua-spaces-ext/tests/start_harness_ids.rs b/libs/cua/crates/cua-spaces-ext/tests/start_harness_ids.rsnew file mode 100644index 0000000000..bc20dca2b9--- /dev/null+++ b/libs/cua/crates/cua-spaces-ext/tests/start_harness_ids.rs@@ -0,0 +1,39 @@+// SPDX-License-Identifier: FSL-1.1-MIT+// Copyright (c) 2026 Cua AI, Inc.++//! Drift guard (CUA-2857): every harness "Start an agent here" offers is a+//! harness the registry knows by that exact id, so `agent_add` accepts what+//! the dialog sends.++use std::path::Path;++fn offered() -> Vec<String> {+ let src = Path::new(env!("CARGO_MANIFEST_DIR"))+ .join("../../../../apps/cua-spaces-web/src/components/add-agent/add-agent-sheet.tsx");+ let text = std::fs::read_to_string(&src).unwrap_or_else(|e| panic!("{}: {e}", src.display()));+ let line = text+ .lines()+ .find(|l| l.contains("export const START_HARNESSES"))+ .expect("START_HARNESSES in the Start an agent here sheet");+ let list = line+ .split('[')+ .nth(1)+ .and_then(|r| r.split(']').next())+ .expect("a list");+ list.split(',')+ .map(|s| s.trim().trim_matches('"').to_string())+ .filter(|s| !s.is_empty())+ .collect()+}++#[test]+fn every_offered_harness_is_a_registry_id_agent_add_takes_verbatim() {+ let ids = offered();+ assert!(ids.len() >= 4, "{ids:?}");+ for id in &ids {+ let h =+ cua_agents::harness::harness(id).unwrap_or_else(|| panic!("{id:?} is not a harness"));+ assert_eq!(h.id, id, "the dialog must send the canonical id");+ assert!(h.ready, "{id:?} is offered but not ready");+ }+}diff --git a/libs/cua/crates/cua-teleport/src/browser_cookies.rs b/libs/cua/crates/cua-teleport/src/browser_cookies.rsindex 771cab9676..425b248aa0 100644--- a/libs/cua/crates/cua-teleport/src/browser_cookies.rs+++ b/libs/cua/crates/cua-teleport/src/browser_cookies.rs@@ -316,6 +316,49 @@ impl ChromeCookies {})}+ /// The profile names present next to this reader's profile (a directory+ /// holding `Preferences`), `Default` first.+ pub fn available_profiles(&self) -> Vec<String> {+ let Some(root) = self+ .profile_dir()+ .ok()+ .and_then(|d| d.parent().map(Path::to_path_buf))+ else {+ return Vec::new();+ };+ let Ok(entries) = std::fs::read_dir(&root) else {+ return Vec::new();+ };+ let mut names: Vec<String> = entries+ .flatten()+ .filter(|e| e.path().join("Preferences").is_file())+ .filter_map(|e| e.file_name().into_string().ok())+ .collect();+ names.sort_by_key(|n| (n != "Default", n.clone()));+ names+ }++ /// The error for a profile with no Cookies database: it names the profile+ /// and the profiles that do exist, so a wrong `--profile` (or a Default+ /// that is not the one signed in) is not mistaken for "no cookies".+ fn missing_store(&self, dir: &Path) -> TeleportError {+ let name = dir+ .file_name()+ .map(|n| n.to_string_lossy().into_owned())+ .unwrap_or_else(|| dir.display().to_string());+ let available = self.available_profiles();+ let others = if available.is_empty() {+ "no browser profiles were found there".to_string()+ } else {+ format!("profiles found: {}", available.join(", "))+ };+ TeleportError::Provider(format!(+ "the browser profile {name:?} has no Cookies database ({}); {others}. \+ Pick one with --profile",+ dir.display()+ ))+ }+/// Every cookie, decrypted, optionally restricted to the registrable/// domains in `sites` (empty reads every cookie). A row that fails to/// decrypt fails the whole read: a partial import would silently drop a@@ -331,10 +374,7 @@ impl ChromeCookies {// `Default/Cookies` or `Default/Network/Cookies`, whichever is newer.let db = cua_teleport_bundle::layout::chrome::cookies_store(&dir);if !db.is_file() {- return Err(TeleportError::Provider(format!(- "no cookies: {} has no Cookies database",- dir.display()- )));+ return Err(self.missing_store(&dir));}let service = match self.platform {Platform::MacOS if self.service.is_some() => self.service.unwrap_or_default(),@@ -418,10 +458,7 @@ impl ChromeCookies {let dir = self.profile_dir()?;let db = cua_teleport_bundle::layout::chrome::cookies_store(&dir);if !db.is_file() {- return Err(TeleportError::Provider(format!(- "no cookies: {} has no Cookies database",- dir.display()- )));+ return Err(self.missing_store(&dir));}Ok(read_rows(&db)?.into_iter()@@ -1206,4 +1243,26 @@ mod tests {"{err}");}++ /// A profile with no Cookies database is named, with the profiles that do+ /// exist, instead of reading like an account with no cookies.+ #[test]+ fn a_profile_without_cookies_names_itself_and_the_profiles_that_exist() {+ let root = tempfile::tempdir().unwrap();+ for p in ["Default", "Profile 1"] {+ std::fs::create_dir_all(root.path().join(p)).unwrap();+ std::fs::write(root.path().join(p).join("Preferences"), "{}").unwrap();+ }+ let reader = ChromeCookies::new(Arc::new(FakeHost::new()))+ .with_platform(Platform::Linux)+ .with_profile_dir(root.path().join("Profile 2"));+ for err in [+ reader.read(&[]).unwrap_err().to_string(),+ reader.host_rows().unwrap_err().to_string(),+ ] {+ assert!(err.contains("Profile 2"), "{err}");+ assert!(err.contains("profiles found: Default, Profile 1"), "{err}");+ assert!(err.contains("--profile"), "{err}");+ }+ }}