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.

chore(cua): keep Teams experimental behind CUA_EXPERIMENTAL_TEAMS (#5049)

Francesco Bonacci698401050258
diff --git a/docs/content/docs/cua-cli/reference/cli/host.mdx b/docs/content/docs/cua-cli/reference/cli/host.mdx
index 1daef3428f..bee199c66c 100644
--- a/docs/content/docs/cua-cli/reference/cli/host.mdx
+++ b/docs/content/docs/cua-cli/reference/cli/host.mdx
@@ -88,7 +88,7 @@ cua host pair [OPTIONS]
| Flag | Type | Default | Description |
| --- | --- | --- | --- |
-| <span id="cua-host-pair--team"></span>`--team` | string | | Add the machine for this team (its id). |
+| <span id="cua-host-pair--team"></span>`--team` | string | | Add the machine for this team (its id). Experimental: needs CUA_EXPERIMENTAL_TEAMS=1. |
| <span id="cua-host-pair--name"></span>`--name` | string | | Name the machine gets (default: its own host name). |
| <span id="cua-host-pair--expires"></span>`--expires` | integer | `30` | Minutes until the code expires (1 to 1440). |
| <span id="cua-host-pair--revoke"></span>`--revoke` | string | | Revoke an unused code by id (`pc_…`). |
@@ -99,7 +99,7 @@ cua host pair [OPTIONS]
```bash test="cli-shape" id="ref-cua-host-pair"
cua host pair
-cua host pair --team team-aigis --expires 60
+cua host pair --name build-box --expires 60
cua host pair --list
cua host pair --revoke pc_0123456789abcdef
```
diff --git a/docs/content/docs/cua-cli/reference/cli/index.mdx b/docs/content/docs/cua-cli/reference/cli/index.mdx
index 5502f66bb6..c924edf19e 100644
--- a/docs/content/docs/cua-cli/reference/cli/index.mdx
+++ b/docs/content/docs/cua-cli/reference/cli/index.mdx
@@ -166,13 +166,13 @@ Enroll this device on the relay, approve, rename and revoke devices, and read th
| --- | --- | --- |
| <span id="cua-devices-status"></span><span id="cua-devices-enroll"></span><span id="cua-devices-approve"></span><span id="cua-devices-ls"></span><span id="cua-devices-rename"></span><span id="cua-devices-revoke"></span><span id="cua-devices-audit"></span>[`cua devices`](/cua-cli/reference/cli/devices#cua-devices) | This device as a client of your cua.ai account on the relay: enroll (second factor), approve other devices, list, rename, revoke, and the audit log of who accessed what. | [`status`](/cua-cli/reference/cli/devices#cua-devices-status), [`enroll`](/cua-cli/reference/cli/devices#cua-devices-enroll), [`approve`](/cua-cli/reference/cli/devices#cua-devices-approve), [`ls`](/cua-cli/reference/cli/devices#cua-devices-ls), [`rename`](/cua-cli/reference/cli/devices#cua-devices-rename), [`revoke`](/cua-cli/reference/cli/devices#cua-devices-revoke), [`audit`](/cua-cli/reference/cli/devices#cua-devices-audit) |
-### `cua team`
+### `cua team (experimental)`
-Create a team, invite members, share machines with them, approve their devices and read the team audit log. [Reference](/cua-cli/reference/cli/team).
+Experimental, not available yet (needs `CUA_EXPERIMENTAL_TEAMS=1`): teams, their members, machines, device approvals and audit log. [Reference](/cua-cli/reference/cli/team).
| Command | Description | Subcommands |
| --- | --- | --- |
-| <span id="cua-team-create"></span><span id="cua-team-ls"></span><span id="cua-team-show"></span><span id="cua-team-invite"></span><span id="cua-team-join"></span><span id="cua-team-leave"></span><span id="cua-team-remove-member"></span><span id="cua-team-set-role"></span><span id="cua-team-devices"></span><span id="cua-team-approve"></span><span id="cua-team-deny"></span><span id="cua-team-request"></span><span id="cua-team-add-machine"></span><span id="cua-team-remove-machine"></span><span id="cua-team-audit"></span><span id="cua-team-delete"></span>[`cua team`](/cua-cli/reference/cli/team#cua-team) | Teams: share machines with every member and their agents. | [`create`](/cua-cli/reference/cli/team#cua-team-create), [`ls`](/cua-cli/reference/cli/team#cua-team-ls), [`show`](/cua-cli/reference/cli/team#cua-team-show), [`invite`](/cua-cli/reference/cli/team#cua-team-invite), [`join`](/cua-cli/reference/cli/team#cua-team-join), [`leave`](/cua-cli/reference/cli/team#cua-team-leave), [`remove-member`](/cua-cli/reference/cli/team#cua-team-remove-member), [`set-role`](/cua-cli/reference/cli/team#cua-team-set-role), [`devices`](/cua-cli/reference/cli/team#cua-team-devices), [`approve`](/cua-cli/reference/cli/team#cua-team-approve), [`deny`](/cua-cli/reference/cli/team#cua-team-deny), [`request`](/cua-cli/reference/cli/team#cua-team-request), [`add-machine`](/cua-cli/reference/cli/team#cua-team-add-machine), [`remove-machine`](/cua-cli/reference/cli/team#cua-team-remove-machine), [`audit`](/cua-cli/reference/cli/team#cua-team-audit), [`delete`](/cua-cli/reference/cli/team#cua-team-delete) |
+| <span id="cua-team"></span><span id="cua-team-create"></span><span id="cua-team-ls"></span><span id="cua-team-show"></span><span id="cua-team-invite"></span><span id="cua-team-join"></span><span id="cua-team-leave"></span><span id="cua-team-remove-member"></span><span id="cua-team-set-role"></span><span id="cua-team-devices"></span><span id="cua-team-approve"></span><span id="cua-team-deny"></span><span id="cua-team-request"></span><span id="cua-team-add-machine"></span><span id="cua-team-remove-machine"></span><span id="cua-team-audit"></span><span id="cua-team-delete"></span>[`cua team`](/cua-cli/reference/cli/team#cua-team) | Experimental, not available yet (set CUA_EXPERIMENTAL_TEAMS=1): teams share machines with every member and their agents. | [`create`](/cua-cli/reference/cli/team#cua-team-create), [`ls`](/cua-cli/reference/cli/team#cua-team-ls), [`show`](/cua-cli/reference/cli/team#cua-team-show), [`invite`](/cua-cli/reference/cli/team#cua-team-invite), [`join`](/cua-cli/reference/cli/team#cua-team-join), [`leave`](/cua-cli/reference/cli/team#cua-team-leave), [`remove-member`](/cua-cli/reference/cli/team#cua-team-remove-member), [`set-role`](/cua-cli/reference/cli/team#cua-team-set-role), [`devices`](/cua-cli/reference/cli/team#cua-team-devices), [`approve`](/cua-cli/reference/cli/team#cua-team-approve), [`deny`](/cua-cli/reference/cli/team#cua-team-deny), [`request`](/cua-cli/reference/cli/team#cua-team-request), [`add-machine`](/cua-cli/reference/cli/team#cua-team-add-machine), [`remove-machine`](/cua-cli/reference/cli/team#cua-team-remove-machine), [`audit`](/cua-cli/reference/cli/team#cua-team-audit), [`delete`](/cua-cli/reference/cli/team#cua-team-delete) |
### `cua usage`
diff --git a/docs/content/docs/cua-cli/reference/cli/team.mdx b/docs/content/docs/cua-cli/reference/cli/team.mdx
index 43dfe8847c..55bfa12c9e 100644
--- a/docs/content/docs/cua-cli/reference/cli/team.mdx
+++ b/docs/content/docs/cua-cli/reference/cli/team.mdx
@@ -1,6 +1,6 @@
---
-title: "cua team"
-description: "Create a team, invite members, share machines with them, approve their devices and read the team audit log."
+title: "cua team (experimental)"
+description: "Experimental, not available yet (needs `CUA_EXPERIMENTAL_TEAMS=1`): teams, their members, machines, device approvals and audit log."
---
{/*
@@ -33,7 +33,7 @@ Every command also accepts the [global options](/cua-cli/reference/cli#global-op
<span id="cua-team"></span>
-Teams: share machines with every member and their agents. Owners and admins invite (email or link), approve member devices, add machines and read the audit log.
+Experimental, not available yet (set CUA_EXPERIMENTAL_TEAMS=1): teams share machines with every member and their agents. Owners and admins invite (email or link), approve member devices, add machines and read the audit log.
```text output
cua team [OPTIONS] <COMMAND>
diff --git a/docs/content/docs/cua-cli/reference/index.mdx b/docs/content/docs/cua-cli/reference/index.mdx
index 7b4c1535d4..861cb9064c 100644
--- a/docs/content/docs/cua-cli/reference/index.mdx
+++ b/docs/content/docs/cua-cli/reference/index.mdx
@@ -32,7 +32,7 @@ description: "Every cua command and every cua MCP tool, generated from the CLI d
| [`cua cloud`](/cua-cli/reference/cli/cloud) | Your own AWS, Google Cloud or Modal account as a place for sandboxes and Spaces: connect, test, status, sweep. |
| [`cua host`](/cua-cli/reference/cli/host) | Set this machine up for unattended access. |
| [`cua devices`](/cua-cli/reference/cli/devices) | Enroll this device on the relay, approve, rename and revoke devices, and read the access log. |
-| [`cua team`](/cua-cli/reference/cli/team) | Create a team, invite members, share machines with them, approve their devices and read the team audit log. |
+| [`cua team (experimental)`](/cua-cli/reference/cli/team) | Experimental, not available yet (needs `CUA_EXPERIMENTAL_TEAMS=1`): teams, their members, machines, device approvals and audit log. |
| [`cua usage`](/cua-cli/reference/cli/usage) | Your hosted relay allowance this month: live sessions and relay hours. |
| [`cua teleport`](/cua-cli/reference/cli/teleport) | Move a desktop app session into a sandbox. |
| [`cua volume`](/cua-cli/reference/cli/volume) | Cua Volume: files, versions, grants, access requests and audit of the volume every Space and agent shares. |
diff --git a/libs/cua/crates/cua-cli/src/host.rs b/libs/cua/crates/cua-cli/src/host.rs
index 07fa9dad80..607ece10cf 100644
--- a/libs/cua/crates/cua-cli/src/host.rs
+++ b/libs/cua/crates/cua-cli/src/host.rs
@@ -98,11 +98,12 @@ pub enum HostCmd {
/// from an enrolled device.
#[command(after_help = "Examples:
cua host pair
- cua host pair --team team-aigis --expires 60
+ cua host pair --name build-box --expires 60
cua host pair --list
cua host pair --revoke pc_0123456789abcdef")]
Pair {
- /// Add the machine for this team (its id).
+ /// Add the machine for this team (its id). Experimental: needs
+ /// CUA_EXPERIMENTAL_TEAMS=1.
#[arg(long)]
team: Option<String>,
/// Name the machine gets (default: its own host name).
diff --git a/libs/cua/crates/cua-cli/src/lib.rs b/libs/cua/crates/cua-cli/src/lib.rs
index ee4e2ddc83..e493d625b7 100644
--- a/libs/cua/crates/cua-cli/src/lib.rs
+++ b/libs/cua/crates/cua-cli/src/lib.rs
@@ -232,7 +232,8 @@ enum Command {
cua devices audit"
)]
Devices(devices_cmd::DevicesCmd),
- /// Teams: share machines with every member and their agents. Owners
+ /// Experimental, not available yet (set CUA_EXPERIMENTAL_TEAMS=1):
+ /// teams share machines with every member and their agents. Owners
/// and admins invite (email or link), approve member devices, add
/// machines and read the audit log.
#[command(
@@ -1296,6 +1297,13 @@ async fn env_at(
async fn run(cli: Cli, out: &mut dyn Write) -> Result<i32, CuaError> {
let json = cli.json;
+ // Teams are experimental: refused (before any sign-in, daemon or relay
+ // call) unless CUA_EXPERIMENTAL_TEAMS is set.
+ if uses_teams(&cli.command) && !cua_home::experimental::teams_enabled() {
+ return Err(CuaError::InvalidArgument(
+ cua_home::experimental::TEAMS_UNAVAILABLE.into(),
+ ));
+ }
// Commands that need no SDK handle.
match &cli.command {
Command::Images(cmd) => {
@@ -2497,6 +2505,33 @@ fn notice_mode(started_by: Option<&str>) -> cua_telemetry::NoticeMode {
}
}
+/// Whether `cmd` is a Teams command: `cua team`, `cua host pair --team`,
+/// or sharing a Space with (or unsharing it from) `team:<id>`.
+fn uses_teams(cmd: &Command) -> bool {
+ let team = |who: &str| who.trim().starts_with("team:");
+ match cmd {
+ Command::Team(_) => true,
+ Command::Host(host::HostCmd::Pair { team: Some(_), .. }) => true,
+ Command::Spaces(host::SpacesCmd::Share { who, .. }) => team(who),
+ Command::Spaces(host::SpacesCmd::Unshare { who: Some(who), .. }) => team(who),
+ _ => false,
+ }
+}
+
+/// The clap command `cua` parses with. Teams are experimental: without
+/// them, `cua team` and `cua host pair --team` stay out of help (they still
+/// parse, and are refused with a short reason).
+fn cli_command(teams: bool) -> clap::Command {
+ let cmd = Cli::command();
+ if teams {
+ return cmd;
+ }
+ cmd.mut_subcommand("team", |c| c.hide(true))
+ .mut_subcommand("host", |h| {
+ h.mut_subcommand("pair", |p| p.mut_arg("team", |a| a.hide(true)))
+ })
+}
+
/// The `cua` command: parses this process's arguments, runs them and exits.
/// The Cua Spaces build registers its [`extension`] first.
pub fn main() {
@@ -2513,7 +2548,7 @@ pub fn main() {
// `CUA_HOME` for a non-production `CUA_ENV` so every component and
// child process (the daemon) uses that environment's home.
unsafe { cua_home::env::pin_home() };
- let matches = Cli::command().get_matches();
+ let matches = cli_command(cua_home::experimental::teams_enabled()).get_matches();
let command = command_path(&matches);
let cli = Cli::from_arg_matches(&matches).unwrap_or_else(|e| e.exit());
let daemon_process = matches!(cli.command, Command::Daemon(DaemonCmd::Start { .. }));
diff --git a/libs/cua/crates/cua-cli/tests/experimental_teams.rs b/libs/cua/crates/cua-cli/tests/experimental_teams.rs
new file mode 100644
index 0000000000..ce463f0665
--- /dev/null
+++ b/libs/cua/crates/cua-cli/tests/experimental_teams.rs
@@ -0,0 +1,91 @@
+//! Teams are experimental: `cua team`, `cua host pair --team` and sharing
+//! with `team:<id>` stay out of help and are refused unless
+//! CUA_EXPERIMENTAL_TEAMS is set.
+
+use std::process::{Command, Output, Stdio};
+
+const UNAVAILABLE: &str = "Teams isn't available yet.";
+
+fn cua(teams: Option<&str>, args: &[&str]) -> Output {
+ let home = tempfile::tempdir().unwrap();
+ let mut cmd = Command::new(env!("CARGO_BIN_EXE_cua"));
+ cmd.args(args)
+ .env("HOME", home.path())
+ .env("CUA_HOME", home.path().join(".cua"))
+ .env("CUA_TELEMETRY", "0")
+ .env("CUA_RELAY_URL", "http://127.0.0.1:9")
+ .env_remove("CUA_ENV")
+ .env_remove("CUA_API_KEY")
+ .stdin(Stdio::null());
+ match teams {
+ Some(v) => cmd.env("CUA_EXPERIMENTAL_TEAMS", v),
+ None => cmd.env_remove("CUA_EXPERIMENTAL_TEAMS"),
+ };
+ cmd.output().expect("run cua")
+}
+
+fn text(out: &Output) -> String {
+ format!(
+ "{}{}",
+ String::from_utf8_lossy(&out.stdout),
+ String::from_utf8_lossy(&out.stderr)
+ )
+}
+
+fn lists_team(help: &str) -> bool {
+ help.lines().any(|l| l.trim_start().starts_with("team "))
+}
+
+#[test]
+fn without_the_flag_teams_are_hidden_and_refused() {
+ for off in [None, Some("0")] {
+ let help = text(&cua(off, &["--help"]));
+ assert!(help.contains("spaces"), "{help}");
+ assert!(!lists_team(&help), "{help}");
+ assert!(!text(&cua(off, &["host", "pair", "--help"])).contains("--team"));
+
+ for args in [
+ &["team", "ls"][..],
+ &["team", "create", "AIGIS"][..],
+ &["host", "pair", "--team", "team-aigis"][..],
+ &[
+ "spaces",
+ "share",
+ "local:studio",
+ "team:team-aigis",
+ "--yes",
+ ][..],
+ &["spaces", "unshare", "local:studio", "team:team-aigis"][..],
+ ] {
+ let out = cua(off, args);
+ assert!(!out.status.success(), "{args:?}: {out:?}");
+ assert!(text(&out).contains(UNAVAILABLE), "{args:?}: {}", text(&out));
+ }
+ }
+}
+
+#[test]
+fn with_the_flag_teams_work_as_before() {
+ let help = text(&cua(Some("1"), &["--help"]));
+ assert!(lists_team(&help), "{help}");
+ assert!(text(&cua(Some("1"), &["host", "pair", "--help"])).contains("--team"));
+ // Past the gate: they fail here only for want of a sign-in or relay.
+ for args in [
+ &["team", "ls"][..],
+ &["host", "pair", "--team", "team-aigis"][..],
+ &[
+ "spaces",
+ "share",
+ "local:studio",
+ "team:team-aigis",
+ "--yes",
+ ][..],
+ ] {
+ let out = cua(Some("1"), args);
+ assert!(
+ !text(&out).contains(UNAVAILABLE),
+ "{args:?}: {}",
+ text(&out)
+ );
+ }
+}
diff --git a/libs/cua/crates/cua-home/src/experimental.rs b/libs/cua/crates/cua-home/src/experimental.rs
new file mode 100644
index 0000000000..3fd84a6db8
--- /dev/null
+++ b/libs/cua/crates/cua-home/src/experimental.rs
@@ -0,0 +1,70 @@
+//! Opt-in gates for features that are not customer-facing yet.
+//!
+//! Teams (`cua team`, sharing with `team:<id>`, `cua host pair --team`) are
+//! a stopgap stored in the relay until Teams move to the identity provider's
+//! organizations and billing entitlements. They stay off unless
+//! `CUA_EXPERIMENTAL_TEAMS` is set (to anything but `0`, `false` or empty),
+//! for internal and staging use.
+
+use std::sync::atomic::{AtomicU8, Ordering};
+
+/// Environment variable that turns Teams on.
+pub const TEAMS_ENV: &str = "CUA_EXPERIMENTAL_TEAMS";
+
+/// What a Teams call says while Teams are off.
+pub const TEAMS_UNAVAILABLE: &str = "Teams isn't available yet.";
+
+/// 0: follow the environment; 1: off; 2: on.
+static TEAMS_OVERRIDE: AtomicU8 = AtomicU8::new(0);
+
+/// Whether Teams are on in this process: the override, else
+/// [`TEAMS_ENV`].
+pub fn teams_enabled() -> bool {
+ match TEAMS_OVERRIDE.load(Ordering::Relaxed) {
+ 1 => false,
+ 2 => true,
+ _ => flag_on(std::env::var(TEAMS_ENV).ok().as_deref()),
+ }
+}
+
+/// Turns Teams on or off for this whole process (`None` follows
+/// [`TEAMS_ENV`] again). For tests and embedders, which cannot safely set
+/// an environment variable once threads run.
+pub fn set_teams_enabled(on: Option<bool>) {
+ let v = match on {
+ None => 0,
+ Some(false) => 1,
+ Some(true) => 2,
+ };
+ TEAMS_OVERRIDE.store(v, Ordering::Relaxed);
+}
+
+/// Whether a flag value turns its feature on.
+pub fn flag_on(value: Option<&str>) -> bool {
+ match value.map(str::trim) {
+ None | Some("") | Some("0") => false,
+ Some(v) => !v.eq_ignore_ascii_case("false"),
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::flag_on;
+
+ #[test]
+ fn only_a_set_non_false_value_turns_a_flag_on() {
+ for off in [
+ None,
+ Some(""),
+ Some(" "),
+ Some("0"),
+ Some("false"),
+ Some("FALSE"),
+ ] {
+ assert!(!flag_on(off), "{off:?}");
+ }
+ for on in [Some("1"), Some("true"), Some("yes")] {
+ assert!(flag_on(on), "{on:?}");
+ }
+ }
+}
diff --git a/libs/cua/crates/cua-home/src/lib.rs b/libs/cua/crates/cua-home/src/lib.rs
index 88c07bc62c..1101d8f134 100644
--- a/libs/cua/crates/cua-home/src/lib.rs
+++ b/libs/cua/crates/cua-home/src/lib.rs
@@ -26,6 +26,7 @@ use std::io;
use std::path::{Path, PathBuf};
pub mod env;
+pub mod experimental;
/// Environment variable that marks a test process.
pub const CUA_TEST_ENV: &str = "CUA_TEST";
diff --git a/libs/cua/crates/cua-host/src/pairing.rs b/libs/cua/crates/cua-host/src/pairing.rs
index a819fbb336..13820d21ce 100644
--- a/libs/cua/crates/cua-host/src/pairing.rs
+++ b/libs/cua/crates/cua-host/src/pairing.rs
@@ -200,6 +200,17 @@ struct PairingCodeList {
codes: Vec<PairingCode>,
}
+/// A code for a team needs Teams on ([`cua_home::experimental`]).
+fn check_pairing_team(req: &PairingCodeRequest, teams: bool) -> Result<()> {
+ if req.team.is_some() && !teams {
+ return Err(Error::InvalidArgument(format!(
+ "{} A pairing code adds the machine to your account; leave out the team.",
+ cua_home::experimental::TEAMS_UNAVAILABLE
+ )));
+ }
+ Ok(())
+}
+
impl RelayClient {
/// Mints a one-time pairing code (from an enrolled device: needs
/// [`RelayClient::with_device_session`]).
@@ -208,6 +219,7 @@ impl RelayClient {
account_token: &str,
req: &PairingCodeRequest,
) -> Result<PairingCode> {
+ check_pairing_team(req, cua_home::experimental::teams_enabled())?;
self.send_json(
reqwest::Method::POST,
"/v1/pairing-codes",
@@ -256,6 +268,18 @@ impl RelayClient {
mod tests {
use super::*;
+ #[test]
+ fn a_team_pairing_code_needs_teams_on() {
+ let team = PairingCodeRequest {
+ team: Some("team-aigis".into()),
+ ..Default::default()
+ };
+ let err = check_pairing_team(&team, false).unwrap_err().to_string();
+ assert!(err.contains("Teams isn't available yet."), "{err}");
+ check_pairing_team(&team, true).unwrap();
+ check_pairing_team(&PairingCodeRequest::default(), false).unwrap();
+ }
+
#[test]
fn codes_read_the_way_people_type_them() {
assert_eq!(
diff --git a/libs/cua/crates/cua-spaces-app-core/parity/golden/share-sheet.json b/libs/cua/crates/cua-spaces-app-core/parity/golden/share-sheet.json
index 8e9416873d..940512e2a0 100644
--- a/libs/cua/crates/cua-spaces-app-core/parity/golden/share-sheet.json
+++ b/libs/cua/crates/cua-spaces-app-core/parity/golden/share-sheet.json
@@ -213,7 +213,7 @@
"disabled": null,
"empty": "Only you",
"error": null,
- "field": "Email or account ID [team:design] Enter a team as team:<id>, as `cua team ls` shows it. as editor",
+ "field": "Email or account ID [team:design] Teams isn't available yet. Share with people, one at a time. as editor",
"request": null,
"roles": "viewer=Can view, editor=Can edit",
"rows": [],
diff --git a/libs/cua/crates/cua-spaces-app-core/src/share.rs b/libs/cua/crates/cua-spaces-app-core/src/share.rs
index d6325b0e45..177b2b5156 100644
--- a/libs/cua/crates/cua-spaces-app-core/src/share.rs
+++ b/libs/cua/crates/cua-spaces-app-core/src/share.rs
@@ -185,11 +185,22 @@ pub struct ShareSheetView {
}
/// Why `who` is not an email or account id, or its normalized form.
+/// A team (`team:<id>`) only while Teams are on ([`cua_home::experimental`]).
pub fn validate_who(who: &str) -> Result<String, String> {
+ validate_who_with(who, cua_home::experimental::teams_enabled())
+}
+
+fn validate_who_with(who: &str, teams: bool) -> Result<String, String> {
let w = who.trim();
if w.is_empty() {
return Err("Enter an email or account ID.".into());
}
+ if !teams && ["team:", "org:", "group:"].iter().any(|p| w.starts_with(p)) {
+ return Err(format!(
+ "{} Share with people, one at a time.",
+ cua_home::experimental::TEAMS_UNAVAILABLE
+ ));
+ }
if let Some(team) = w.strip_prefix("team:") {
// A team (`team:<id>` as `cua team ls` or the Teams page shows it):
// every member gets the Space, from a device an admin approved.
@@ -434,26 +445,30 @@ mod tests {
);
assert_eq!(s.error.as_deref(), Some("not shared: you declined"));
assert!(!s.busy);
+ }
+
+ #[test]
+ fn teams_are_shared_with_only_while_teams_are_on() {
+ // On (CUA_EXPERIMENTAL_TEAMS=1): a team id, always for full use.
assert_eq!(
- validate_who("team:design").unwrap_err(),
+ validate_who_with("team:design", true).unwrap_err(),
"Enter a team as team:<id>, as `cua team ls` shows it."
);
- assert_eq!(validate_who(" team:team-0a1b ").unwrap(), "team:team-0a1b");
- // A team is always shared for full use.
- let s = share_reduce(
- &i,
- &share_initial(),
- &ShareSheetAction::SetWho {
- who: "team:team-0a1b".into(),
- },
+ assert_eq!(
+ validate_who_with(" team:team-0a1b ", true).unwrap(),
+ "team:team-0a1b"
);
+ assert_eq!(role_for("team:team-0a1b", "viewer"), "editor");
+ // Off: refused, whatever the id.
+ for who in ["team:team-0a1b", "team:design", "org:acme"] {
+ assert_eq!(
+ validate_who_with(who, false).unwrap_err(),
+ "Teams isn't available yet. Share with people, one at a time."
+ );
+ }
assert_eq!(
- share_reduce(&i, &s, &ShareSheetAction::Submit).request,
- Some(ShareRequest::Share {
- space: "local:studio".into(),
- who: "team:team-0a1b".into(),
- role: "editor".into()
- })
+ validate_who_with("[email protected]", false).unwrap(),
);
}
diff --git a/libs/cua/crates/cua-spaces/src/share.rs b/libs/cua/crates/cua-spaces/src/share.rs
index 9fba12276d..1e9dd337f8 100644
--- a/libs/cua/crates/cua-spaces/src/share.rs
+++ b/libs/cua/crates/cua-spaces/src/share.rs
@@ -147,9 +147,11 @@ pub fn normalize_who(who: &str) -> Result<String> {
)));
}
if w.starts_with("team:") || w.starts_with("org:") || w.starts_with("group:") {
- return Err(Error::invalid(
- "share with an account (email or account id), or with a team as team:<id> (`cua team ls`)",
- ));
+ return Err(Error::invalid(if cua_home::experimental::teams_enabled() {
+ "share with an account (email or account id), or with a team as team:<id> (`cua team ls`)"
+ } else {
+ "share with an account (email or account id)"
+ }));
}
if w.contains('@') {
let (local, domain) = w.split_once('@').unwrap_or_default();
@@ -177,8 +179,20 @@ pub fn normalize_who(who: &str) -> Result<String> {
/// Sharing with a team makes the Space a team machine: every member (and
/// their agents) sees it and opens it as an editor from a device a team
/// admin approved.
+/// Teams are experimental: with them off ([`cua_home::experimental`]) a
+/// `team:<id>` invitee is refused.
pub fn team_of(who: &str) -> Option<Result<String>> {
+ team_of_with(who, cua_home::experimental::teams_enabled())
+}
+
+fn team_of_with(who: &str, teams: bool) -> Option<Result<String>> {
let id = who.trim().strip_prefix("team:")?;
+ if !teams {
+ return Some(Err(Error::invalid(format!(
+ "{} Share with people (email or account id).",
+ cua_home::experimental::TEAMS_UNAVAILABLE
+ ))));
+ }
let ok = id.starts_with("team-")
&& id.len() <= 64
&& id
@@ -399,8 +413,13 @@ impl Spaces {
let m = client.machine(&token, machine).await?;
let mut shares = entries(&m);
// Teams it is a machine of (best effort: a relay without teams, or
- // a device not enrolled, lists none).
- if let Ok(list) = client.teams(&token).await {
+ // a device not enrolled, lists none; none while Teams are off).
+ let teams = if cua_home::experimental::teams_enabled() {
+ client.teams(&token).await.ok()
+ } else {
+ None
+ };
+ if let Some(list) = teams {
shares.extend(
list.teams
.iter()
@@ -810,11 +829,20 @@ mod tests {
"{bad}"
);
}
- let e = normalize_who("team:design").unwrap_err().to_string();
- assert!(e.contains("team:<id>"), "{e}");
- assert_eq!(team_of("team:team-0a1b").unwrap().unwrap(), "team-0a1b");
- assert!(team_of("team:design").unwrap().is_err());
- assert!(team_of("[email protected]").is_none());
+ assert!(normalize_who("team:design").is_err());
+ assert_eq!(
+ team_of_with("team:team-0a1b", true).unwrap().unwrap(),
+ "team-0a1b"
+ );
+ assert!(team_of_with("team:design", true).unwrap().is_err());
+ assert!(team_of_with("[email protected]", true).is_none());
+ assert!(team_of_with("[email protected]", false).is_none());
+ // With Teams off, a team is refused whatever its id.
+ let e = team_of_with("team:team-0a1b", false)
+ .unwrap()
+ .unwrap_err()
+ .to_string();
+ assert!(e.contains("Teams isn't available yet."), "{e}");
}
#[test]
diff --git a/libs/cua/crates/cua-spaces/tests/share.rs b/libs/cua/crates/cua-spaces/tests/share.rs
index 43d2de73ab..d870fc66a0 100644
--- a/libs/cua/crates/cua-spaces/tests/share.rs
+++ b/libs/cua/crates/cua-spaces/tests/share.rs
@@ -692,6 +692,8 @@ async fn only_the_owner_removes_a_relay_record() {
/// takes it off.
#[tokio::test]
async fn sharing_with_a_team_adds_a_team_machine_and_refuses_macos() {
+ // Teams are experimental (off unless CUA_EXPERIMENTAL_TEAMS is set).
+ cua_home::experimental::set_teams_enabled(Some(true));
let relay = FakeRelay::start().await;
relay.add_account("ada-token", "ada", Some("[email protected]"));
let home = tempfile::tempdir().unwrap();
diff --git a/scripts/docs-generators/cli-specs/cua.json b/scripts/docs-generators/cli-specs/cua.json
index cc83361662..b634c0f298 100644
--- a/scripts/docs-generators/cli-specs/cua.json
+++ b/scripts/docs-generators/cli-specs/cua.json
@@ -9491,7 +9491,7 @@
},
{
"abstract": "Make a one-time code (with a link and the install command) that adds another computer to your account: run the command it prints on that computer. Codes work once and expire (30 minutes by default). Run from an enrolled device",
- "after_help": "Examples:\n cua host pair\n cua host pair --team team-aigis --expires 60\n cua host pair --list\n cua host pair --revoke pc_0123456789abcdef",
+ "after_help": "Examples:\n cua host pair\n cua host pair --name build-box --expires 60\n cua host pair --list\n cua host pair --revoke pc_0123456789abcdef",
"aliases": [],
"arguments": [],
"flags": [
@@ -9515,7 +9515,7 @@
"aliases": [],
"default_value": null,
"env": null,
- "help": "Add the machine for this team (its id)",
+ "help": "Add the machine for this team (its id). Experimental: needs CUA_EXPERIMENTAL_TEAMS=1",
"hidden": false,
"is_optional": true,
"multiple_values": false,
@@ -11259,7 +11259,7 @@
"usage": "cua devices [OPTIONS] <COMMAND>"
},
{
- "abstract": "Teams: share machines with every member and their agents. Owners and admins invite (email or link), approve member devices, add machines and read the audit log",
+ "abstract": "Experimental, not available yet (set CUA_EXPERIMENTAL_TEAMS=1): teams share machines with every member and their agents. Owners and admins invite (email or link), approve member devices, add machines and read the audit log",
"after_help": "Examples:\n cua team create AIGIS\n cua team invite AIGIS [email protected]\n cua team add-machine AIGIS local:build-box\n cua team approve AIGIS dev_0123456789abcdef01234567\n cua team audit AIGIS",
"aliases": [],
"arguments": [],
diff --git a/scripts/docs-generators/cua-cli.ts b/scripts/docs-generators/cua-cli.ts
index 571bbf7d81..94d6676524 100644
--- a/scripts/docs-generators/cua-cli.ts
+++ b/scripts/docs-generators/cua-cli.ts
@@ -121,7 +121,7 @@ export const CLI_GROUPS: CliGroup[] = [
{ slug: 'cloud', title: 'cua cloud', summary: 'Your own AWS, Google Cloud or Modal account as a place for sandboxes and Spaces: connect, test, status, sweep', commands: ['cloud'] },
{ slug: 'host', title: 'cua host', summary: 'Set this machine up for unattended access', commands: ['host'] },
{ slug: 'devices', title: 'cua devices', summary: 'Enroll this device on the relay, approve, rename and revoke devices, and read the access log', commands: ['devices'] },
- { slug: 'team', title: 'cua team', summary: 'Create a team, invite members, share machines with them, approve their devices and read the team audit log', commands: ['team'] },
+ { slug: 'team', title: 'cua team (experimental)', summary: 'Experimental, not available yet (needs `CUA_EXPERIMENTAL_TEAMS=1`): teams, their members, machines, device approvals and audit log', commands: ['team'] },
{ slug: 'usage', title: 'cua usage', summary: 'Your hosted relay allowance this month: live sessions and relay hours', commands: ['usage'] },
{ slug: 'teleport', title: 'cua teleport', summary: 'Move a desktop app session into a sandbox', commands: ['teleport'] },
{ slug: 'volume', title: 'cua volume', summary: 'Cua Volume: files, versions, grants, access requests and audit of the volume every Space and agent shares', commands: ['volume'] },