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(spacesd): teleport lands a Chrome session in one profile and launches the guest's Chromium (CUA-2853) (#6180)
ddupontdbf08f753422
diff --git a/libs/cua-spacesd/crates/cua-spacesd-server/src/services/teleport.rs b/libs/cua-spacesd/crates/cua-spacesd-server/src/services/teleport.rsindex cbcbed768e..d2ea2af952 100644--- a/libs/cua-spacesd/crates/cua-spacesd-server/src/services/teleport.rs+++ b/libs/cua-spacesd/crates/cua-spacesd-server/src/services/teleport.rs@@ -246,7 +246,15 @@ async fn create_staging_file(path: &Path) -> std::io::Result<tokio::fs::File> {fn app_on_path(app: &str) -> bool {let candidates: &[&str] = match app {- "chrome" => &["google-chrome", "google-chrome-stable", "chrome"],+ // The Spaces Linux image ships Chromium, which the Chrome importer+ // lands in and launches when there is no Google Chrome.+ "chrome" => &[+ "google-chrome",+ "google-chrome-stable",+ "chrome",+ "chromium",+ "chromium-browser",+ ],"chromium" => &["chromium", "chromium-browser"],"firefox" => &["firefox", "firefox-esr"],"vscode" => &["code"],@@ -1055,8 +1063,10 @@ mod tests {let store = h.service.ledger_store().clone();let ledger = store.read("imp-1").unwrap().expect("ledger written");assert_eq!(ledger.provider, "chrome");- assert_eq!(ledger.files.len(), 1);+ // The cookies, and the note that a signed-in browser is available.+ assert_eq!(ledger.files.len(), 2, "{:?}", ledger.files);assert!(ledger.files[0].ends_with("Default/Cookies"));+ assert!(ledger.files[1].ends_with(".cua/teleport/signed-in-browser.json"));#[cfg(unix)]{assert_eq!(mode(&h.ledger), 0o700);diff --git a/libs/cua-spacesd/crates/cua-spacesd-teleport/src/importers/chrome.rs b/libs/cua-spacesd/crates/cua-spacesd-teleport/src/importers/chrome.rsindex ad2340d18d..b9629e6b87 100644--- a/libs/cua-spacesd/crates/cua-spacesd-teleport/src/importers/chrome.rs+++ b/libs/cua-spacesd/crates/cua-spacesd-teleport/src/importers/chrome.rs@@ -14,7 +14,7 @@ use cua_teleport_bundle::bundle::{BundleReader, DEFAULT_MAX_TOTAL_BYTES};use cua_teleport_bundle::chromium_crypto;use cua_teleport_bundle::cookies::COOKIES_ENTRY;use cua_teleport_bundle::layout::chrome::{- launch_program_for, remap_to_platform, user_data_dir_for, DISPLAY, ID, TABS_JSON,+ land_path, launch_program_for, user_data_dir_for, DISPLAY, ID, LINUX_BROWSERS, TABS_JSON,};use cua_teleport_bundle::local_storage::LOCAL_STORAGE_ENTRY;use cua_teleport_bundle::logins::LOGINS_ENTRY;@@ -28,8 +28,27 @@ use crate::{ImportProvider, ImportRecord, Result};/// (the main process and its helpers all live inside the bundle).const MACOS_PROCESS_PATTERN: &str = "Google Chrome.app/Contents/";+/// Where, relative to the home, an import leaves a note that a signed-in+/// browser is available, for agents and people to find.+pub const SIGNED_IN_BROWSER_NOTE: &str = ".cua/teleport/signed-in-browser.json";++/// Whether a program (absolute path, or a name on `PATH`) exists.+pub type ProgramProbe = Arc<dyn Fn(&str) -> bool + Send + Sync>;++fn program_exists(program: &str) -> bool {+ let path = Path::new(program);+ if path.is_absolute() {+ return path.is_file();+ }+ std::env::var_os("PATH")+ .map(|paths| std::env::split_paths(&paths).any(|dir| dir.join(program).is_file()))+ .unwrap_or(false)+}+/// The Chrome/Chromium importer.pub struct ChromeImporter {+ /// Finds which browser a Linux guest has.+ probe: ProgramProbe,max_total_bytes: u64,/// Ensuring this destination's own Safe Storage key (never the source's)/// goes through this host, like every other Keychain effect.@@ -45,11 +64,45 @@ impl Default for ChromeImporter {impl ChromeImporter {pub fn new() -> Self {Self {+ probe: Arc::new(program_exists),max_total_bytes: DEFAULT_MAX_TOTAL_BYTES,host: default_host(),}}+ /// Looks for the Linux guest's browser with `probe` instead of the+ /// guest's own `PATH` and files.+ pub fn with_program_probe(mut self, probe: ProgramProbe) -> Self {+ self.probe = probe;+ self+ }++ /// The browser an import into `platform` lands in and launches: Chrome+ /// on macOS and Windows; on Linux the first of+ /// [`LINUX_BROWSERS`] the guest has (Google Chrome, else Chromium, as the+ /// Spaces image ships), falling back to Google Chrome so a missing+ /// browser reads as "google-chrome: not found".+ fn target(&self, platform: Platform) -> Target {+ match platform {+ Platform::Linux => {+ let b = LINUX_BROWSERS+ .iter()+ .find(|b| (self.probe)(b.program))+ .unwrap_or(&LINUX_BROWSERS[0]);+ Target {+ name: b.name,+ program: b.program.to_string(),+ user_data_dir: b.user_data_dir,+ }+ }+ _ => Target {+ name: "google-chrome",+ program: launch_program_for(platform),+ user_data_dir: user_data_dir_for(platform),+ },+ }+ }+/// Set the total-size guard for imported bundles.pub fn with_max_total_bytes(mut self, bytes: u64) -> Self {self.max_total_bytes = bytes;@@ -63,6 +116,14 @@ impl ChromeImporter {}}+/// The browser an import lands in.+struct Target {+ name: &'static str,+ program: String,+ /// Relative to the home.+ user_data_dir: &'static str,+}+/// Writes localStorage items into `profile_dir`'s `Local State/leveldb`/// (`Local Storage/leveldb`), beside what the browser already holds. The/// destination browser is not running yet (the import launches it afterwards),@@ -94,6 +155,39 @@ pub(crate) fn write_local_storage(Ok(())}+/// Records "a signed-in browser is available: chromium, profile Default" in+/// the guest (a small JSON file under `~/.cua/teleport/`, ledgered so a wipe+/// removes it) and tells the client in a notice. Names no cookie or value.+fn note_signed_in_browser(+ dest_home: &Path,+ target: &Target,+ user_data_dir: &Path,+ source_profile: Option<&str>,+ record: &mut ImportRecord,+) -> Result<()> {+ let note = serde_json::json!({+ "signed_in_browser": true,+ "browser": target.name,+ "program": target.program,+ "user_data_dir": user_data_dir,+ "profile": "Default",+ "source_profile": source_profile,+ "launch": format!("{} --user-data-dir={:?}", target.program, user_data_dir.display().to_string()),+ });+ let path = dest_home.join(SIGNED_IN_BROWSER_NOTE);+ if let Some(dir) = path.parent() {+ record.create_dir_all(dir)?;+ }+ std::fs::write(&path, serde_json::to_vec_pretty(¬e).unwrap_or_default())?;+ record.file_written(&path);+ record.notices.push(format!(+ "Signed-in browser available: {}, profile Default ({}). Details in ~/{SIGNED_IN_BROWSER_NOTE}.",+ target.name,+ user_data_dir.display()+ ));+ Ok(())+}+impl ImportProvider for ChromeImporter {fn id(&self) -> &str {ID@@ -121,6 +215,8 @@ impl ImportProvider for ChromeImporter {if platform == Platform::MacOS {super::terminate_running(&*self.host, MACOS_PROCESS_PATTERN);}+ let target = self.target(platform);+ let mut source_profile: Option<String> = None;let mut tab_urls: Vec<String> = Vec::new();let mut cookies_entry: Option<Vec<u8>> = None;let mut local_storage_entry: Option<Vec<u8>> = None;@@ -153,19 +249,22 @@ impl ImportProvider for ChromeImporter {local_storage_entry = Some(entry.bytes);continue;}- let dest = dest_home.join(remap_to_platform(&entry.rel_path, platform));+ // One profile directory for the whole capture: the sender's+ // `Profile 1` and the cookies below all land in `Default`.+ let (landed, profile) = land_path(&entry.rel_path, target.user_data_dir);+ if source_profile.is_none() {+ source_profile = profile.map(str::to_string);+ }+ let dest = dest_home.join(landed);write_entry(&dest, &entry, false, record)?;}- let user_data_dir = dest_home.join(user_data_dir_for(platform));+ let user_data_dir = dest_home.join(target.user_data_dir);if let Some(bytes) = cookies_entry {let items = cua_teleport_bundle::cookies::parse(&bytes);if !items.is_empty() {- // Single-profile scope today, matching the sender- // (`cua_teleport::browser_cookies`): a capture names one- // profile, always landed at "Default" here. Multi-profile- // Keyvault capture is tracked as follow-up work, not silently- // guessed at.+ // A capture names one profile, always landed at "Default"+ // here, where the files above land too.let profile_dir = user_data_dir.join("Default");let service = chromium_crypto::macos_safe_storage_service(ID).unwrap_or("Chrome Safe Storage");@@ -213,8 +312,15 @@ impl ImportProvider for ChromeImporter {args.extend(tab_urls.iter().cloned());}+ note_signed_in_browser(+ dest_home,+ &target,+ &user_data_dir,+ source_profile.as_deref(),+ record,+ )?;Ok(LaunchSpec {- program: launch_program_for(platform),+ program: target.program,args,env: Vec::new(),cwd: None,@@ -265,6 +371,7 @@ mod tests {fn import_lands_in_the_linux_profile_and_restores_the_session() {let dest = tempfile::tempdir().unwrap();let spec = ChromeImporter::new()+ .with_program_probe(Arc::new(|p| p == "google-chrome")).import_to(&mut Cursor::new(profile_bundle(b"[]")),dest.path(),@@ -300,6 +407,163 @@ mod tests {}}+ /// The Spaces Linux image has Chromium and no Google Chrome: the capture+ /// lands in Chromium's own profile (`~/.config/chromium/Default`), a+ /// sender's `Profile 1` and the cookies share that one profile, the launch+ /// is Chromium's wrapper, and the guest records that a signed-in browser+ /// is available.+ #[test]+ fn a_chromium_only_guest_gets_one_chromium_profile_and_a_note() {+ use cua_teleport_bundle::cookies::CookieItem;+ let dest = tempfile::tempdir().unwrap();+ let profile = dest.path().join(".config/chromium/Default");+ std::fs::create_dir_all(&profile).unwrap();+ {+ let conn = rusqlite::Connection::open(profile.join("Cookies")).unwrap();+ conn.execute_batch(+ "CREATE TABLE cookies (+ creation_utc INTEGER NOT NULL, host_key TEXT NOT NULL, name TEXT NOT NULL,+ value TEXT NOT NULL DEFAULT '', encrypted_value BLOB NOT NULL DEFAULT '',+ path TEXT NOT NULL, expires_utc INTEGER NOT NULL,+ is_secure INTEGER NOT NULL DEFAULT 0, is_httponly INTEGER NOT NULL DEFAULT 0,+ samesite INTEGER NOT NULL DEFAULT -1,+ UNIQUE (host_key, name, path)+ );",+ )+ .unwrap();+ }+ let cookies_json = cua_teleport_bundle::cookies::serialize(&[CookieItem {+ host_key: ".github.com".into(),+ name: "user_session".into(),+ value: b"gh-session-value".to_vec(),+ path: "/".into(),+ expires_utc: 0,+ is_secure: true,+ is_httponly: true,+ samesite: 1,+ extra: Default::default(),+ }]);+ let bytes = bundle(+ "chrome",+ &[+ ("tabs.json", 0o644, b"[]"),+ (COOKIES_ENTRY, 0o600, &cookies_json),+ (+ ".config/google-chrome/Profile 1/Bookmarks",+ 0o600,+ b"{\"roots\":{}}",+ ),+ ],+ );+ let mut record = ImportRecord::default();+ let spec = ChromeImporter::new()+ .with_program_probe(Arc::new(|p| p == "/opt/cua/bin/cua-chromium"))+ .import_recorded(+ &mut Cursor::new(bytes),+ dest.path(),+ Platform::Linux,+ &mut record,+ )+ .unwrap();+ assert_eq!(spec.program, "/opt/cua/bin/cua-chromium");+ assert!(+ spec.args.contains(&format!(+ "--user-data-dir={}",+ dest.path().join(".config/chromium").display()+ )),+ "{:?}",+ spec.args+ );+ // The sender's Profile 1 file and the cookies are in the same profile.+ assert_eq!(+ std::fs::read(profile.join("Bookmarks")).unwrap(),+ b"{\"roots\":{}}"+ );+ assert!(!dest.path().join(".config/chromium/Profile 1").exists());+ assert!(!dest.path().join(".config/google-chrome").exists());+ let conn = rusqlite::Connection::open(profile.join("Cookies")).unwrap();+ let n: i64 = conn+ .query_row(+ "SELECT count(*) FROM cookies WHERE name = 'user_session'",+ [],+ |r| r.get(0),+ )+ .unwrap();+ assert_eq!(n, 1);+ // The guest says a signed-in browser is there, and where.+ let note: serde_json::Value = serde_json::from_slice(+ &std::fs::read(dest.path().join(SIGNED_IN_BROWSER_NOTE)).unwrap(),+ )+ .unwrap();+ assert_eq!(note["signed_in_browser"], true);+ assert_eq!(note["browser"], "chromium");+ assert_eq!(note["profile"], "Default");+ assert_eq!(note["source_profile"], "Profile 1");+ assert!(+ record+ .notices+ .iter()+ .any(|n| n.starts_with("Signed-in browser available: chromium, profile Default")),+ "{:?}",+ record.notices+ );+ // The note is ledgered, so a wipe removes it.+ assert!(record+ .files+ .contains(&dest.path().join(SIGNED_IN_BROWSER_NOTE)));+ // Neither the note nor the notice carries a cookie value.+ assert!(+ !std::fs::read_to_string(dest.path().join(SIGNED_IN_BROWSER_NOTE))+ .unwrap()+ .contains("gh-session-value")+ );+ }++ /// Drift guard: the browser the Spaces Linux image launches (its+ /// `launch_app` claim) is one the importer knows how to land in and start.+ #[test]+ fn the_linux_images_browser_is_one_the_importer_launches() {+ let image = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))+ .join("../../../images/linux/image.json");+ let json: serde_json::Value =+ serde_json::from_str(&std::fs::read_to_string(image).unwrap()).unwrap();+ fn find(v: &serde_json::Value) -> Option<String> {+ match v {+ serde_json::Value::Object(m) => m+ .get("launch_app")+ .and_then(|l| l.get("app"))+ .and_then(|a| a.as_str().map(str::to_string))+ .or_else(|| m.values().find_map(find)),+ serde_json::Value::Array(a) => a.iter().find_map(find),+ _ => None,+ }+ }+ let launch = find(&json).expect("launch_app.app in the Linux image.json");+ assert!(+ LINUX_BROWSERS.iter().any(|b| b.program == launch),+ "{launch} is not in LINUX_BROWSERS"+ );+ }++ /// With neither browser installed the launch names Google Chrome, as before.+ #[test]+ fn a_guest_with_no_browser_falls_back_to_google_chrome() {+ let dest = tempfile::tempdir().unwrap();+ let spec = ChromeImporter::new()+ .with_program_probe(Arc::new(|_| false))+ .import_to(+ &mut Cursor::new(profile_bundle(b"[]")),+ dest.path(),+ Platform::Linux,+ )+ .unwrap();+ assert_eq!(spec.program, "google-chrome");+ assert!(dest+ .path()+ .join(".config/google-chrome/Default/Cookies")+ .exists());+ }+#[test]fn import_lands_in_the_macos_chrome_profile() {// A macOS guest must receive the profile where macOS Chrome actuallydiff --git a/libs/cua-spacesd/crates/cua-spacesd-teleport/src/receiver.rs b/libs/cua-spacesd/crates/cua-spacesd-teleport/src/receiver.rsindex 4c10235766..bd8f847e48 100644--- a/libs/cua-spacesd/crates/cua-spacesd-teleport/src/receiver.rs+++ b/libs/cua-spacesd/crates/cua-spacesd-teleport/src/receiver.rs@@ -604,13 +604,16 @@ mod tests {.import_bytes(&chrome_bundle(), "chrome", false).unwrap();let record = &outcome.record;- assert_eq!(record.files.len(), 2, "{record:?}");+ // The two profile files, and the note that a signed-in browser is there.+ let note = h.join(crate::importers::chrome::SIGNED_IN_BROWSER_NOTE);+ assert_eq!(record.files.len(), 3, "{record:?}");+ assert!(record.files.contains(¬e));assert!(record.files.iter().all(|f| f.is_file() && f.starts_with(h)));assert!(!record.created_dirs.contains(&parent));assert!(record.created_dirs.iter()- .all(|d| d.starts_with(&parent) && d.is_dir()));+ .all(|d| (d.starts_with(&parent) || note.starts_with(d)) && d.is_dir()));let ledger = Ledger::new("i", &outcome.provider_id, record, 0, 1);let report = receiver.wipe(&ledger);assert!(report.complete() && report.refused.is_empty(), "{report:?}");diff --git a/libs/cua/crates/cua-teleport-bundle/src/layout.rs b/libs/cua/crates/cua-teleport-bundle/src/layout.rsindex c794377c5e..d9736fbb40 100644--- a/libs/cua/crates/cua-teleport-bundle/src/layout.rs+++ b/libs/cua/crates/cua-teleport-bundle/src/layout.rs@@ -224,6 +224,72 @@ pub mod chrome {}}+ /// A Chromium-family browser a Linux guest may carry.+ #[derive(Clone, Copy, Debug, PartialEq, Eq)]+ pub struct LinuxBrowser {+ /// What the browser is called to people and agents (`chromium`).+ pub name: &'static str,+ /// The program to start: absolute, or a name on `PATH`.+ pub program: &'static str,+ /// Its user-data dir, relative to the home: where a plain launch of+ /// this browser (no `--user-data-dir`) reads its profile.+ pub user_data_dir: &'static str,+ }++ /// The browsers a Linux guest is launched with, in the order preferred.+ /// Google Chrome first; the Spaces Linux image ships Chromium only, started+ /// through its wrapper (`/opt/cua/bin/cua-chromium`, which adds the sandbox+ /// flags the runtime needs) and reading `~/.config/chromium`.+ pub const LINUX_BROWSERS: &[LinuxBrowser] = &[+ LinuxBrowser {+ name: "google-chrome",+ program: "google-chrome",+ user_data_dir: LINUX_USER_DATA_DIR,+ },+ LinuxBrowser {+ name: "google-chrome",+ program: "google-chrome-stable",+ user_data_dir: LINUX_USER_DATA_DIR,+ },+ LinuxBrowser {+ name: "chromium",+ program: "/opt/cua/bin/cua-chromium",+ user_data_dir: ".config/chromium",+ },+ LinuxBrowser {+ name: "chromium",+ program: "chromium",+ user_data_dir: ".config/chromium",+ },+ LinuxBrowser {+ name: "chromium",+ program: "chromium-browser",+ user_data_dir: ".config/chromium",+ },+ ];++ /// Whether `name` is a Chrome profile directory (`Default`, `Profile 1`).+ pub fn is_profile_dir(name: &str) -> bool {+ name == "Default" || name.strip_prefix("Profile ").is_some_and(|n| !n.is_empty())+ }++ /// Where a bundle path lands under `user_data_dir` (home-relative): the+ /// canonical Linux prefix is replaced and the sender's profile directory+ /// (`Profile 1`) becomes `Default`, so everything of one capture lives in+ /// one profile, the one a plain launch opens. Returns the path and the+ /// sender's profile name when the path was inside one.+ pub fn land_path<'a>(rel_path: &'a str, user_data_dir: &str) -> (String, Option<&'a str>) {+ let Some(within) = rel_path.strip_prefix(&format!("{LINUX_USER_DATA_DIR}/")) else {+ return (rel_path.to_string(), None);+ };+ match within.split_once('/') {+ Some((profile, rest)) if is_profile_dir(profile) => {+ (format!("{user_data_dir}/Default/{rest}"), Some(profile))+ }+ _ => (format!("{user_data_dir}/{within}"), None),+ }+ }+/// Where the app is installed on a macOS source (install probe).pub const MACOS_APP: &str = "/Applications/Google Chrome.app";}@@ -825,6 +891,38 @@ pub fn landing_path(provider_id: &str, rel_path: &str, platform: Platform) -> Opmod tests {use super::*;+ #[test]+ fn a_capture_lands_in_one_profile_whatever_the_sender_profile_was() {+ use chrome::{LINUX_BROWSERS, land_path};+ let ud = ".config/chromium";+ assert_eq!(+ land_path(".config/google-chrome/Profile 1/Cookies", ud),+ (".config/chromium/Default/Cookies".into(), Some("Profile 1"))+ );+ assert_eq!(+ land_path(".config/google-chrome/Default/Local Storage/x", ud),+ (+ ".config/chromium/Default/Local Storage/x".into(),+ Some("Default")+ )+ );+ // Not inside a profile: kept (under the destination's dir), no profile.+ assert_eq!(+ land_path(".config/google-chrome/Local State", ud),+ (".config/chromium/Local State".into(), None)+ );+ assert_eq!(land_path("other/x", ud), ("other/x".into(), None));+ assert!(!chrome::is_profile_dir("Profile "));+ assert!(!chrome::is_profile_dir("Crashpad"));+ // Chromium (the Spaces image) is a candidate, after Google Chrome.+ assert_eq!(LINUX_BROWSERS[0].program, "google-chrome");+ assert!(+ LINUX_BROWSERS+ .iter()+ .any(|b| b.program == "/opt/cua/bin/cua-chromium" && b.name == "chromium")+ );+ }+#[test]fn provider_ids_are_unique_and_stable() {let mut ids = PROVIDER_IDS.to_vec();