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(mesh): the mesh is on by default for every client (CUA-1947) (#5630)
dduponte5d09e40291a
diff --git a/apps/cua-spaces-desktop/src/mesh-channel.ts b/apps/cua-spaces-desktop/src/mesh-channel.tsdeleted file mode 100644index 43c3befce4..0000000000--- a/apps/cua-spaces-desktop/src/mesh-channel.ts+++ /dev/null@@ -1,27 +0,0 @@-// SPDX-License-Identifier: FSL-1.1-MIT-// Copyright (c) 2026 Cua AI, Inc.--// The update channel, recorded where the app's cua daemon and this-// machine's host read it (`<cua home>/app-update-channel`, cua_mesh::policy):-// the WireGuard-based mesh follows it once it is turned on for Beta. In this-// release the mesh is off on every channel unless CUA_MESH asks for it, so-// the file changes nothing yet.-import { mkdirSync, renameSync, writeFileSync } from "node:fs";-import * as path from "node:path";-import { cuaHome } from "./model/daemon";--/** cua_mesh::policy::CHANNEL_FILE. */-export const CHANNEL_FILE = "app-update-channel";--/** Writes `channel` to `<home>/app-update-channel` (atomically; a failure is only logged). */-export function recordUpdateChannel(channel: "stable" | "beta", home: string = cuaHome()): void {- try {- mkdirSync(home, { recursive: true });- const file = path.join(home, CHANNEL_FILE);- const tmp = `${file}.tmp`;- writeFileSync(tmp, `${channel}\n`);- renameSync(tmp, file);- } catch (error) {- console.warn("[cua-spaces] could not record the update channel:", error);- }-}diff --git a/apps/cua-spaces-desktop/src/updater.ts b/apps/cua-spaces-desktop/src/updater.tsindex f2bca479e9..4c6ff65e8b 100644--- a/apps/cua-spaces-desktop/src/updater.ts+++ b/apps/cua-spaces-desktop/src/updater.ts@@ -25,7 +25,6 @@ import { app, BrowserWindow, dialog } from "electron";import { existsSync } from "node:fs";import * as path from "node:path";import { electronUpdater } from "./electron-updater";-import { recordUpdateChannel } from "./mesh-channel";import type { UpdaterDriving } from "./model/updates";import { readSettings, writeSettings } from "./settings";import { autoCheckPref, autoInstallPref, channelPref, type UpdateChannel } from "./update-prefs";@@ -88,8 +87,6 @@ export class ElectronUpdater implements UpdaterDriving {/** The updater for this build; null in a development run (no feed). */static start(): ElectronUpdater | null {- // Where the cua daemon and this machine's host read it (mesh-channel.ts).- if (app.isPackaged) recordUpdateChannel(updateChannel());if (!hasFeed()) return null;const u = new ElectronUpdater();u.schedule();@@ -129,7 +126,6 @@ export class ElectronUpdater implements UpdaterDriving {// The model sets the channel it shows at launch: only a change is the user's choice.if (channel === updateChannel()) return;writeSettings({ updateChannel: channel, updateChannelChosen: true });- recordUpdateChannel(channel);this.loaded = null;this.schedule();}diff --git a/apps/cua-spaces-desktop/test/mesh-channel.test.ts b/apps/cua-spaces-desktop/test/mesh-channel.test.tsdeleted file mode 100644index 97fced26f2..0000000000--- a/apps/cua-spaces-desktop/test/mesh-channel.test.ts+++ /dev/null@@ -1,27 +0,0 @@-// SPDX-License-Identifier: FSL-1.1-MIT-// Copyright (c) 2026 Cua AI, Inc.--// The update channel the app records for its daemon and this machine's host-// (cua_mesh::policy reads `<cua home>/app-update-channel`).-import { mkdtempSync, readFileSync, rmSync } from "node:fs";-import { tmpdir } from "node:os";-import * as path from "node:path";-import { afterAll, describe, expect, it } from "vitest";-import { CHANNEL_FILE, recordUpdateChannel } from "../src/mesh-channel";--const scratch = mkdtempSync(path.join(tmpdir(), "cua-mesh-channel-test-"));-afterAll(() => rmSync(scratch, { recursive: true, force: true }));--describe("recordUpdateChannel", () => {- it("writes the channel into the cua home, and follows a switch", () => {- const home = path.join(scratch, "home", ".cua");- recordUpdateChannel("beta", home);- expect(readFileSync(path.join(home, CHANNEL_FILE), "utf8")).toBe("beta\n");- recordUpdateChannel("stable", home);- expect(readFileSync(path.join(home, CHANNEL_FILE), "utf8")).toBe("stable\n");- });-- it("never throws when the home cannot be written", () => {- expect(() => recordUpdateChannel("beta", "/dev/null/not-a-dir")).not.toThrow();- });-});diff --git a/docs/content/docs/redirects.json b/docs/content/docs/redirects.jsonindex fc3e96c225..354c9c6468 100644--- a/docs/content/docs/redirects.json+++ b/docs/content/docs/redirects.json@@ -481,7 +481,7 @@"spaces/guides/send-files": "spaces/guides/cua-volume#send-a-file-into-a-space","spaces/guides/site-login": "spaces/guides/keyvault#let-an-agent-sign-in-to-a-site","spaces/guides/troubleshoot-create": "spaces/guides/troubleshoot",- "spaces/guides/mesh": "spaces/guides/relay-security#end-to-end-encrypted-connections-beta",+ "spaces/guides/mesh": "spaces/guides/relay-security#end-to-end-encrypted-connections","spaces/examples/other-languages": "spaces/guides/create-a-space-with-the-sdk#examples-in-other-languages","cua-cli/reference/cli/spaces": "cua-cli/reference/cli/spaces-and-computers#cua-spaces","cua-cli/reference/cli/host": "cua-cli/reference/cli/spaces-and-computers#cua-host",diff --git a/docs/content/docs/spaces/guides/relay-security.mdx b/docs/content/docs/spaces/guides/relay-security.mdxindex 8a5aedcd76..5767c95d04 100644--- a/docs/content/docs/spaces/guides/relay-security.mdx+++ b/docs/content/docs/spaces/guides/relay-security.mdx@@ -1,6 +1,6 @@---title: What the relay can see-description: 'A plain accounting of what relay.cua.ai can and cannot see, what we have done and are still doing about it, and the opt-in end-to-end encrypted connections (beta) that keep the relay from reading a session.'+description: 'A plain accounting of what relay.cua.ai can and cannot see, what we have done and are still doing about it, and the end-to-end encrypted connections (on by default) that keep the relay from reading a session.'---import { Callout } from 'fumadocs-ui/components/callout';@@ -29,14 +29,15 @@ bug in this page: tell us.through it: it can mint assertions the computers still trust, and readwhatever crosses it meanwhile.-## The mesh (beta, opt-in)+## The mesh (on by default)-[End-to-end encrypted connections](#end-to-end-encrypted-connections-beta) are-off by default. When you turn them on, a `relay:` Space no longer goes through+[End-to-end encrypted connections](#end-to-end-encrypted-connections) are+on by default. When both ends and the relay support them, a `relay:` Space no longer goes throughthe HTTPS path, and the relay forwards only ciphertext it cannot read or change.Everything in the next sections describes the HTTPS path, which stays in use foreverything else: the browser viewer, web-hosted agents, computers and devices-without the mesh, and `prefer` when the mesh is not available.+without the mesh, and anything where the mesh is not available (or you set+`CUA_MESH=off`).## What crosses the relay@@ -108,13 +109,14 @@ path, so there is nothing to seal against.computer) is off by default**, and time-boxed to an announced rolloutwindow when it does run.-## End-to-end encrypted connections (beta)+## End-to-end encrypted connections<Callout type="info">- **Beta, off by default.** Nothing changes unless you turn the mesh on with- `CUA_MESH` (below). It is meant for the Beta channel of the Cua Spaces app- and will be on by default there in a later beta; stable releases keep the- relay's HTTPS path.+ **On by default** in the Cua Spaces app (every channel), the `cua` CLI and+ hosted computers, once they are on a version that includes it. Where the mesh+ cannot be used (a self-hosted relay without one, an older computer, a+ network that blocks it) Cua uses the relay's HTTPS path, as before. To turn+ it off, set `CUA_MESH=off` (below).</Callout>With the mesh on, a device that opens a Space on one of your computers@@ -135,25 +137,26 @@ screen and Keyvault deliveries cross it only as ciphertext.conflicts with Tailscale or another VPN you already run, and it carriesSpaces traffic only.-### Turn it on+### Turn it off, or require it-Both ends opt in: the device you connect from and the computer you host.+Both ends use the mesh when it is available: the device you connect from and+the computer you host. Each end decides for itself with `CUA_MESH`.| `CUA_MESH` | Behavior ||---|---|-| unset or `off` (default) | The relay's HTTPS path only, as before. |-| `prefer` | The mesh when both ends and the relay support it; the relay's HTTPS path otherwise, with a log line saying why. |+| unset or `prefer` (default) | The mesh when both ends and the relay support it; the relay's HTTPS path otherwise, with a log line saying why. |+| `off` | The relay's HTTPS path only, as before the mesh. || `require` | The mesh or nothing: a relay that could read the session is never used. |- **On the device:** set `CUA_MESH` where `cua` runs (your shell, or theenvironment of the cua daemon; restart the daemon with `cua daemon stop`after changing it).-- **On a hosted computer:** run `cua host setup` with `CUA_MESH=prefer` set.- The setting is kept for the host's service until you run setup again- without it.+- **On a hosted computer:** to turn it off there, run `cua host setup` with+ `CUA_MESH=off` set. The setting is kept for the host's service until you run+ setup again without it.`cua spaces ls` lists the same computers either way. With `prefer`, a computer-or relay that does not speak the mesh yet is used over HTTPS, so mixing+or relay that does not speak the mesh is used over HTTPS, so mixingupdated and older computers works.### Who can connect@@ -190,8 +193,8 @@ going through the relay resumes when the relay is back.- The **browser viewer** and **web or Cloudflare-hosted agents** that cannotrun Cua: they reach `https://<relay>/m/<machine>/…` as before. See[what the relay can see](#the-short-version).-- Computers and devices without the mesh turned on, or on a version of Cua- from before it.+- Computers and devices with `CUA_MESH=off`, or on a version of Cua from+ before the mesh.- Relays that do not coordinate a mesh, such as a self-hosted `cua-relay`:`prefer` uses their HTTPS path quietly.diff --git a/libs/cua-spacesd/crates/cua-spacesd-server/src/context.rs b/libs/cua-spacesd/crates/cua-spacesd-server/src/context.rsindex e91e2ee1f4..f0ac88edb9 100644--- a/libs/cua-spacesd/crates/cua-spacesd-server/src/context.rs+++ b/libs/cua-spacesd/crates/cua-spacesd-server/src/context.rs@@ -520,11 +520,6 @@ impl ServerContext {};let quic_port = self.config().media_quic_port;let auth = self.inner.auth.clone();- let home = self- .config()- .data_dir- .parent()- .map(std::path::Path::to_path_buf);crate::mesh_host::MeshHostConfig {relay_url: relay_url.to_owned(),relay_token: relay_token.to_owned(),@@ -536,7 +531,7 @@ impl ServerContext {account,env_token: Arc::new(move || auth.token().map(|t| t.to_string())),name: cua_mesh::node::hostname(),- policy: Arc::new(move || cua_mesh::Policy::current(home.as_deref())),+ policy: Arc::new(cua_mesh::Policy::current),recheck: crate::mesh_host::GATE_RECHECK,}}diff --git a/libs/cua-spacesd/crates/cua-spacesd-server/src/mesh_host.rs b/libs/cua-spacesd/crates/cua-spacesd-server/src/mesh_host.rsindex 2609cee218..e25a96d1c5 100644--- a/libs/cua-spacesd/crates/cua-spacesd-server/src/mesh_host.rs+++ b/libs/cua-spacesd/crates/cua-spacesd-server/src/mesh_host.rs@@ -34,11 +34,9 @@//! A relay without a mesh (an older one) is simply not used: the machine//! keeps serving over its relay connection and checks again later.//!-//! The node runs only while [`cua_mesh::policy`] allows it: `CUA_MESH` in-//! the service's environment, else the update channel the Cua Spaces app-//! recorded in this machine's Cua home (off on every channel in this-//! release). Until then nothing is asked of the relay, and the machine-//! serves over its relay connection exactly as before.+//! The node runs unless [`cua_mesh::policy`] turns it off: `CUA_MESH=off`+//! in the service's environment keeps the machine on its relay connection+//! alone, and nothing is asked of the relay.use std::collections::HashMap;use std::net::SocketAddr;diff --git a/libs/cua-spacesd/crates/cua-spacesd-server/tests/mesh_gate.rs b/libs/cua-spacesd/crates/cua-spacesd-server/tests/mesh_gate.rsindex 464b7fc099..5bcfea6345 100644--- a/libs/cua-spacesd/crates/cua-spacesd-server/tests/mesh_gate.rs+++ b/libs/cua-spacesd/crates/cua-spacesd-server/tests/mesh_gate.rs@@ -1,10 +1,9 @@// SPDX-License-Identifier: FSL-1.1-MIT// Copyright (c) 2026 Cua AI, Inc.-//! The machine side of the mesh is off unless allowed (`CUA_MESH`, or the-//! app's channel with the Beta switch on): while it is off the machine-//! never asks its relay about the mesh, and it starts asking once the-//! policy allows it, without a restart.+//! The machine side of the mesh is on unless `CUA_MESH=off`: while it is off+//! the machine never asks its relay about the mesh, and it starts asking once+//! the policy allows it, without a restart.use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};use std::sync::Arc;@@ -98,7 +97,7 @@ async fn an_off_machine_never_asks_its_relay_about_the_mesh() {"an off machine made a node");- // Allowed (CUA_MESH=prefer, or the Beta switch): the next recheck asks,+ // Allowed (CUA_MESH no longer off): the next recheck asks,// with no restart. This relay has no mesh, so it asks once and waits.on.store(true, Ordering::SeqCst);assert!(wait_for(&count, 1).await, "an allowed machine never asked");@@ -117,13 +116,9 @@ async fn an_off_machine_never_asks_its_relay_about_the_mesh() {}#[tokio::test]-async fn the_default_policy_is_off() {- // No CUA_MESH and no app channel: the machine stays on the relay path.- let dir = tempfile::tempdir().unwrap();+async fn the_default_policy_is_prefer() {+ // No CUA_MESH: the machine joins the mesh when the relay has one.if std::env::var(cua_mesh::policy::ENV).is_err() {- assert_eq!(Policy::current(Some(dir.path())), Policy::Off);- std::fs::write(dir.path().join(cua_mesh::policy::CHANNEL_FILE), "beta").unwrap();- // The Beta switch is off in this release.- assert_eq!(Policy::current(Some(dir.path())), Policy::Off);+ assert_eq!(Policy::current(), Policy::Prefer);}}diff --git a/libs/cua-spacesd/crates/cua-spacesd/src/main.rs b/libs/cua-spacesd/crates/cua-spacesd/src/main.rsindex 91100058f9..645e3ac490 100644--- a/libs/cua-spacesd/crates/cua-spacesd/src/main.rs+++ b/libs/cua-spacesd/crates/cua-spacesd/src/main.rs@@ -375,12 +375,34 @@ enum Exit {type BoxError = Box<dyn std::error::Error + Send + Sync>;+/// The log filter spec for `CUA_ENV_LOG` (`None`: not set): the spec, or+/// `info`, without the WireGuard library's own timer messages (`boringtun`)+/// unless the spec names it. It logs a warning every few seconds while a mesh+/// peer that went away is retried and an error when it gives up: normal churn+/// that would otherwise fill a host's log (every short-lived `cua` client+/// leaves one), including for hosts whose service was installed with+/// `CUA_ENV_LOG=info`. `CUA_ENV_LOG=info,boringtun=debug` brings them back.+fn log_filter_spec(env: Option<&str>) -> String {+ let base = env+ .map(str::trim)+ .filter(|s| !s.is_empty())+ .unwrap_or("info");+ if base.contains("boringtun") {+ base.to_owned()+ } else {+ format!("{base},boringtun=off")+ }+}++fn log_filter() -> tracing_subscriber::EnvFilter {+ let spec = log_filter_spec(std::env::var("CUA_ENV_LOG").ok().as_deref());+ tracing_subscriber::EnvFilter::try_new(&spec)+ .unwrap_or_else(|_| tracing_subscriber::EnvFilter::new(log_filter_spec(None)))+}+fn init_tracing() {let _ = tracing_subscriber::fmt()- .with_env_filter(- tracing_subscriber::EnvFilter::try_from_env("CUA_ENV_LOG")- .unwrap_or_else(|_| tracing_subscriber::EnvFilter::new("info")),- )+ .with_env_filter(log_filter()).with_writer(std::io::stderr).with_ansi(std::io::IsTerminal::is_terminal(&std::io::stderr())).try_init();@@ -866,6 +888,58 @@ fn write_private_file(path: &std::path::Path, bytes: &[u8]) -> std::io::Result<(mod tests {use super::*;+ /// The WireGuard library's retry/expiry messages stay out of the log+ /// (also when a service was installed with `CUA_ENV_LOG=info`), unless+ /// the filter names them.+ #[test]+ fn the_log_filter_hides_the_wireguard_timers_unless_asked_for() {+ use std::io::Write;+ #[derive(Clone, Default)]+ struct Buf(std::sync::Arc<std::sync::Mutex<Vec<u8>>>);+ impl Write for Buf {+ fn write(&mut self, b: &[u8]) -> std::io::Result<usize> {+ self.0.lock().unwrap().extend_from_slice(b);+ Ok(b.len())+ }+ fn flush(&mut self) -> std::io::Result<()> {+ Ok(())+ }+ }+ impl<'a> tracing_subscriber::fmt::MakeWriter<'a> for Buf {+ type Writer = Buf;+ fn make_writer(&'a self) -> Buf {+ self.clone()+ }+ }+ let run = |spec: Option<&str>| {+ let buf = Buf::default();+ let subscriber = tracing_subscriber::fmt()+ .with_env_filter(tracing_subscriber::EnvFilter::new(log_filter_spec(spec)))+ .with_writer(buf.clone())+ .finish();+ tracing::subscriber::with_default(subscriber, || {+ tracing::warn!(target: "boringtun::noise::timers", "HANDSHAKE(REKEY_TIMEOUT)");+ tracing::error!(target: "boringtun::noise::timers", "CONNECTION_EXPIRED(REKEY_ATTEMPT_TIME)");+ tracing::warn!(target: "cua_mesh::node", "kept warning");+ });+ let bytes = buf.0.lock().unwrap().clone();+ String::from_utf8(bytes).unwrap()+ };+ for spec in [None, Some(""), Some("info"), Some("debug"), Some(" warn ")] {+ let out = run(spec);+ assert!(+ !out.contains("HANDSHAKE") && !out.contains("CONNECTION_EXPIRED"),+ "{spec:?}: {out}"+ );+ assert!(out.contains("kept warning"), "{spec:?}: {out}");+ }+ let out = run(Some("info,boringtun=debug"));+ assert!(+ out.contains("HANDSHAKE") && out.contains("CONNECTION_EXPIRED"),+ "{out}"+ );+ }+fn parse(args: &[&str]) -> Cli {Cli::try_parse_from(std::iter::once("cua-spacesd").chain(args.iter().copied())).unwrap()}diff --git a/libs/cua/Cargo.lock b/libs/cua/Cargo.lockindex 689ee2c442..8ba9ee94e3 100644--- a/libs/cua/Cargo.lock+++ b/libs/cua/Cargo.lock@@ -2404,6 +2404,7 @@ dependencies = ["tempfile","tokio","tokio-tungstenite 0.29.0",+ "tracing","tracing-subscriber","url","windows-sys 0.61.2",diff --git a/libs/cua/crates/cua-cli/Cargo.toml b/libs/cua/crates/cua-cli/Cargo.tomlindex 42454d6549..6844717ee7 100644--- a/libs/cua/crates/cua-cli/Cargo.toml+++ b/libs/cua/crates/cua-cli/Cargo.toml@@ -87,5 +87,7 @@ cua-daemon = { workspace = true, features = ["server", "client", "test-fixtures"cua-spacesd-client = { workspace = true, features = ["testing"] }cua-sandbox-core = { workspace = true, features = ["testing"] }tempfile.workspace = true+# The default log filter test emits events.+tracing.workspace = true# Drives the interactive onboarding prompts through a real PTY.portable-pty = "0.9"diff --git a/libs/cua/crates/cua-cli/src/host.rs b/libs/cua/crates/cua-cli/src/host.rsindex f8df1a3dcf..1f0e9acc6e 100644--- a/libs/cua/crates/cua-cli/src/host.rs+++ b/libs/cua/crates/cua-cli/src/host.rs@@ -27,6 +27,8 @@ pub enum HostCmd {# Add this computer with a one-time code from the Cua Spaces app# (Add a computer) or `cua host pair`: no sign-in needed herecua host setup --pair K7QM-4XPB-2RHD+ # Keep this computer off the end-to-end encrypted mesh (relay HTTPS only):+ # run setup with CUA_MESH=off in the environment# Self-hosting teams: cua help advanced")]Setup {/// Relay URL (default $CUA_RELAY_URL, else the CUA_ENV relay, https://relay.cua.ai in production).diff --git a/libs/cua/crates/cua-cli/src/lib.rs b/libs/cua/crates/cua-cli/src/lib.rsindex 08ee6196bd..02e042a2cb 100644--- a/libs/cua/crates/cua-cli/src/lib.rs+++ b/libs/cua/crates/cua-cli/src/lib.rs@@ -64,13 +64,31 @@ use cua_sdk::{Cua, CuaConfig, CuaError, SpacesdClient};use std::{io::Write, path::PathBuf, sync::Arc, time::Duration};use util::line;+/// The log filter spec for `CUA_LOG` (`None`: not set): the spec, else+/// warnings (info in the background daemon), without the WireGuard library's+/// own timer messages (`boringtun`) unless the spec names it. It logs a+/// warning every few seconds while a mesh peer that went away is retried and+/// an error when it gives up: normal churn that says nothing a user can act+/// on. `CUA_LOG=warn,boringtun=debug` brings them back.+fn log_filter_spec(env: Option<&str>, daemon_log: bool) -> String {+ let base = env+ .map(str::trim)+ .filter(|s| !s.is_empty())+ .unwrap_or(if daemon_log { "info" } else { "warn" });+ if base.contains("boringtun") {+ base.to_owned()+ } else {+ format!("{base},boringtun=off")+ }+}+#[derive(Parser, Debug)]#[command(name = "cua",version = cua_sdk::VERSION,disable_version_flag = true,about = "Cua: sandboxes, computer actions, MCP, skills and the cua daemon",- after_help = "Docs: https://cua.ai/docs/cua-cli/reference/cli"+ after_help = "Remote Spaces use the end-to-end encrypted mesh when both ends and the relay\nsupport it, and the relay's HTTPS path otherwise. CUA_MESH=off turns the mesh\noff; CUA_MESH=require refuses any other path.\n\nDocs: https://cua.ai/docs/cua-cli/reference/cli")]struct Cli {/// Print the version.@@ -2451,13 +2469,11 @@ pub fn main() {})) && std::env::var("CUA_DAEMON_LOG").as_deref() != Ok("off");let filter = || {- tracing_subscriber::EnvFilter::try_from_env("CUA_LOG").unwrap_or_else(|_| {- if daemon_log {- "info".into()- } else {- "warn".into()- }- })+ tracing_subscriber::EnvFilter::try_new(log_filter_spec(+ std::env::var("CUA_LOG").ok().as_deref(),+ daemon_log,+ ))+ .unwrap_or_else(|_| log_filter_spec(None, daemon_log).into())};let file = daemon_log.then(|| {@@ -2633,6 +2649,62 @@ fn runtime_setup_output(mod tests {use super::*;+ /// The WireGuard library's retry/expiry messages stay out of the log+ /// (also with `CUA_LOG=info`, as a service sets), unless+ /// the filter names them.+ #[test]+ fn the_log_filter_hides_the_wireguard_timers_unless_asked_for() {+ use std::io::Write;+ #[derive(Clone, Default)]+ struct Buf(std::sync::Arc<std::sync::Mutex<Vec<u8>>>);+ impl Write for Buf {+ fn write(&mut self, b: &[u8]) -> std::io::Result<usize> {+ self.0.lock().unwrap().extend_from_slice(b);+ Ok(b.len())+ }+ fn flush(&mut self) -> std::io::Result<()> {+ Ok(())+ }+ }+ impl<'a> tracing_subscriber::fmt::MakeWriter<'a> for Buf {+ type Writer = Buf;+ fn make_writer(&'a self) -> Buf {+ self.clone()+ }+ }+ let run = |spec: Option<&str>, daemon: bool| {+ let buf = Buf::default();+ let subscriber = tracing_subscriber::fmt()+ .with_env_filter(tracing_subscriber::EnvFilter::new(log_filter_spec(+ spec, daemon,+ )))+ .with_writer(buf.clone())+ .finish();+ tracing::subscriber::with_default(subscriber, || {+ tracing::warn!(target: "boringtun::noise::timers", "HANDSHAKE(REKEY_TIMEOUT)");+ tracing::error!(target: "boringtun::noise::timers", "CONNECTION_EXPIRED(REKEY_ATTEMPT_TIME)");+ tracing::warn!(target: "cua_mesh::node", "kept warning");+ });+ let bytes = buf.0.lock().unwrap().clone();+ String::from_utf8(bytes).unwrap()+ };+ for daemon in [false, true] {+ for spec in [None, Some(""), Some("info"), Some("debug"), Some(" warn ")] {+ let out = run(spec, daemon);+ assert!(+ !out.contains("HANDSHAKE") && !out.contains("CONNECTION_EXPIRED"),+ "{spec:?}: {out}"+ );+ assert!(out.contains("kept warning"), "{spec:?}: {out}");+ }+ }+ let out = run(Some("warn,boringtun=debug"), false);+ assert!(+ out.contains("HANDSHAKE") && out.contains("CONNECTION_EXPIRED"),+ "{out}"+ );+ }+/// Self-hosting stays out of every `--help` but `cua help advanced`;/// the flags still parse.#[test]diff --git a/libs/cua/crates/cua-host/src/host.rs b/libs/cua/crates/cua-host/src/host.rsindex 6c752099c3..a59ee00774 100644--- a/libs/cua/crates/cua-host/src/host.rs+++ b/libs/cua/crates/cua-host/src/host.rs@@ -294,8 +294,7 @@ pub struct HostConfig {pub paused_signed_out: bool,/// `CUA_MESH` as it was set where `cua host setup` ran (an explicit/// opt-in to the WireGuard®-based mesh, or out of it): passed on to the- /// service. Unset, the service follows its own default (off unless the- /// Cua Spaces app's channel turns it on).+ /// service. Unset, the service follows its own default (prefer).#[serde(default, skip_serializing_if = "Option::is_none")]pub mesh: Option<String>,}diff --git a/libs/cua/crates/cua-host/src/tests.rs b/libs/cua/crates/cua-host/src/tests.rsindex 2c82fe1138..3416f85b03 100644--- a/libs/cua/crates/cua-host/src/tests.rs+++ b/libs/cua/crates/cua-host/src/tests.rs@@ -1672,8 +1672,8 @@ async fn a_pause_keeps_the_owners_choice_and_skips_direct_mode() {assert!(g.manager.calls.lock().unwrap().is_empty());}-/// The mesh stays off on a hosted machine unless asked for: a setup without-/// `CUA_MESH` installs the same service as before, and an explicit+/// A setup without `CUA_MESH` installs the same service as before (the+/// service defaults to prefer), and an explicit/// `CUA_MESH` at setup reaches the service.#[test]fn the_service_gets_cua_mesh_only_when_setup_was_given_it() {diff --git a/libs/cua/crates/cua-mesh/src/lib.rs b/libs/cua/crates/cua-mesh/src/lib.rsindex 1b0354a303..16852c1c3a 100644--- a/libs/cua/crates/cua-mesh/src/lib.rs+++ b/libs/cua/crates/cua-mesh/src/lib.rs@@ -51,7 +51,7 @@ pub use coord::{AuthFuture, AuthProvider, ControlState, PairVerifier};pub use engine::Path;pub use key::{NodeIdentity, PublicKey, SecretKey};pub use node::{Forward, IncomingStream, MEDIA_UDP_PORT, Mesh, MeshConfig, PeerStatus, Status};-pub use policy::{Channel, Policy};+pub use policy::Policy;pub use proto::{Grant, MeshInfo, Mode, NodeKind, PeerInfo, PeerUsage, VERSION};pub use quic::{MeshStream, STREAM_PORT, StreamHeader};diff --git a/libs/cua/crates/cua-mesh/src/policy.rs b/libs/cua/crates/cua-mesh/src/policy.rsindex 2fbbee7942..2d6a5eacfb 100644--- a/libs/cua/crates/cua-mesh/src/policy.rs+++ b/libs/cua/crates/cua-mesh/src/policy.rs@@ -1,52 +1,31 @@// SPDX-License-Identifier: MIT// Copyright (c) 2026 Cua AI, Inc.-//! When to use the mesh: off unless asked for.+//! When to use the mesh: on, unless turned off.//!//! - `CUA_MESH=prefer|require|off`, where the process runs, always wins//! (`cua`, the SDK, the cua daemon, a hosted machine's service).-//! - Otherwise the Cua Spaces app's update channel decides for the app's-//! own processes (its cua daemon and this machine's host): the app-//! records it in `<cua home>/app-update-channel` ([`CHANNEL_FILE`]).-//! [`ON_IN_BETA`] is the single switch that turns the mesh on for the-//! Beta channel; it is off in this release, so the mesh is opt-in on-//! every channel.-//! - Anything else: [`Policy::Off`], the relay's HTTPS path, as before the-//! mesh existed.--use std::path::Path;+//! - Anything else: [`Policy::Prefer`], on every channel of the Cua Spaces+//! app and for the CLI alone: the mesh when both ends and the relay speak+//! it, the relay's HTTPS path otherwise (an older machine, a relay with no+//! mesh such as a self-hosted `cua-relay`, a mesh that does not answer).+//! `CUA_MESH=off` is the escape hatch back to the HTTPS path only./// The environment variable that chooses the policy explicitly.pub const ENV: &str = "CUA_MESH";-/// The file, in a Cua home, where the Cua Spaces app records its update-/// channel (`beta` or `stable`).-pub const CHANNEL_FILE: &str = "app-update-channel";--/// Whether the Beta-channel app uses the mesh without `CUA_MESH`. Off: the-/// mesh is opt-in on every channel until it is turned on for Beta.-pub const ON_IN_BETA: bool = false;-/// How relay connections use the mesh.#[derive(Debug, Clone, Copy, PartialEq, Eq)]pub enum Policy {- /// The mesh when both sides speak it, the relay's HTTPS path otherwise.+ /// The mesh when both sides speak it, the relay's HTTPS path otherwise+ /// (the default).Prefer,/// The mesh only (a relay that can read sessions is never used).Require,- /// The relay's HTTPS path only (the default).+ /// The relay's HTTPS path only (`CUA_MESH=off`).Off,}-/// The Cua Spaces app's update channel.-#[derive(Debug, Clone, Copy, PartialEq, Eq)]-pub enum Channel {- /// Stable releases.- Stable,- /// Beta (pre)releases.- Beta,-}-impl Policy {/// A `CUA_MESH` value; `None` when it does not choose (unset, empty or/// unknown).@@ -59,28 +38,14 @@ impl Policy {}}- /// The policy from an explicit `CUA_MESH` value, else the app's channel- /// (when this process is the app's), else off.- pub fn resolve(explicit: Option<&str>, channel: Option<Channel>, on_in_beta: bool) -> Self {- if let Some(p) = explicit.and_then(Self::parse) {- return p;- }- match channel {- Some(Channel::Beta) if on_in_beta => Self::Prefer,- _ => Self::Off,- }+ /// The policy from an explicit `CUA_MESH` value, else [`Self::Prefer`].+ pub fn resolve(explicit: Option<&str>) -> Self {+ explicit.and_then(Self::parse).unwrap_or(Self::Prefer)}- /// The policy now: `CUA_MESH`, else the channel recorded in `app_home`- /// (the Cua home of the app this process belongs to; `None` for a- /// process that is not the app's, such as a plain `cua` run).- pub fn current(app_home: Option<&Path>) -> Self {- let explicit = std::env::var(ENV).ok();- if let Some(p) = explicit.as_deref().and_then(Self::parse) {- return p;- }- let channel = app_home.and_then(read_channel);- Self::resolve(None, channel, ON_IN_BETA)+ /// The policy now: `CUA_MESH`, else [`Self::Prefer`].+ pub fn current() -> Self {+ Self::resolve(std::env::var(ENV).ok().as_deref())}/// Whether this policy uses the mesh at all.@@ -89,82 +54,30 @@ impl Policy {}}-/// The channel the app recorded in `home` ([`CHANNEL_FILE`]).-pub fn read_channel(home: &Path) -> Option<Channel> {- let raw = std::fs::read_to_string(home.join(CHANNEL_FILE)).ok()?;- match raw.trim().to_ascii_lowercase().as_str() {- "beta" => Some(Channel::Beta),- "stable" => Some(Channel::Stable),- _ => None,- }-}-#[cfg(test)]mod tests {use super::*;#[test]- fn off_unless_asked_for() {- assert_eq!(Policy::resolve(None, None, ON_IN_BETA), Policy::Off);- assert_eq!(- Policy::resolve(None, Some(Channel::Stable), ON_IN_BETA),- Policy::Off- );- // Unknown and empty values do not choose.- assert_eq!(Policy::resolve(Some(""), None, ON_IN_BETA), Policy::Off);- assert_eq!(- Policy::resolve(Some("maybe"), None, ON_IN_BETA),- Policy::Off- );+ fn prefer_by_default() {+ assert_eq!(Policy::resolve(None), Policy::Prefer);+ // Unknown and empty values do not choose, so they keep the default.+ assert_eq!(Policy::resolve(Some("")), Policy::Prefer);+ assert_eq!(Policy::resolve(Some("maybe")), Policy::Prefer);+ assert!(Policy::resolve(None).uses_mesh());}#[test]- fn the_beta_channel_is_off_in_this_release() {- // The one switch: flipping it is the "on for Beta" change, and this- // test changes with it.- const { assert!(!ON_IN_BETA) };- assert_eq!(- Policy::resolve(None, Some(Channel::Beta), ON_IN_BETA),- Policy::Off- );- }-- #[test]- fn with_the_switch_on_only_beta_prefers_the_mesh() {- assert_eq!(- Policy::resolve(None, Some(Channel::Beta), true),- Policy::Prefer- );- assert_eq!(- Policy::resolve(None, Some(Channel::Stable), true),- Policy::Off- );- assert_eq!(Policy::resolve(None, None, true), Policy::Off);- }-- #[test]- fn cua_mesh_always_wins() {- for channel in [None, Some(Channel::Stable), Some(Channel::Beta)] {- for on in [false, true] {- assert_eq!(Policy::resolve(Some("prefer"), channel, on), Policy::Prefer);- assert_eq!(- Policy::resolve(Some(" REQUIRE "), channel, on),- Policy::Require- );- assert_eq!(Policy::resolve(Some("off"), channel, on), Policy::Off);- }+ fn cua_mesh_off_and_require_win() {+ for v in ["off", "OFF", " 0 ", "false", "no"] {+ assert_eq!(Policy::resolve(Some(v)), Policy::Off, "{v}");+ }+ assert!(!Policy::resolve(Some("off")).uses_mesh());+ for v in ["require", " REQUIRE ", "required", "only"] {+ assert_eq!(Policy::resolve(Some(v)), Policy::Require, "{v}");+ }+ for v in ["prefer", "on", "1", "true", "yes"] {+ assert_eq!(Policy::resolve(Some(v)), Policy::Prefer, "{v}");}- }-- #[test]- fn the_app_records_its_channel_in_the_cua_home() {- let dir = tempfile::tempdir().unwrap();- assert_eq!(read_channel(dir.path()), None);- std::fs::write(dir.path().join(CHANNEL_FILE), "beta\n").unwrap();- assert_eq!(read_channel(dir.path()), Some(Channel::Beta));- std::fs::write(dir.path().join(CHANNEL_FILE), "stable").unwrap();- assert_eq!(read_channel(dir.path()), Some(Channel::Stable));- std::fs::write(dir.path().join(CHANNEL_FILE), "nightly").unwrap();- assert_eq!(read_channel(dir.path()), None);}}diff --git a/libs/cua/crates/cua-spaces/src/mesh.rs b/libs/cua/crates/cua-spaces/src/mesh.rsindex b5b4711ec0..364f1818a4 100644--- a/libs/cua/crates/cua-spaces/src/mesh.rs+++ b/libs/cua/crates/cua-spaces/src/mesh.rs@@ -17,11 +17,10 @@//! proving it holds the env token (the machine checks it; the relay only//! passes the proof along), then sends the env token inside WireGuard.//!-//! The mesh is off unless asked for ([`cua_mesh::policy`]): `CUA_MESH`-//! picks the policy, and without it the Cua Spaces app's daemon follows the-//! app's update channel (off on every channel in this release):-//! - `off` (default): the relay's HTTPS path only, as before the mesh;-//! - `prefer`: the mesh when both sides support it, the relay's HTTPS path+//! The mesh is on unless turned off ([`cua_mesh::policy`]): `CUA_MESH`+//! picks the policy, and without it the policy is `prefer`:+//! - `off`: the relay's HTTPS path only, as before the mesh;+//! - `prefer` (default): the mesh when both sides support it, the relay's HTTPS path//! otherwise (an older relay or machine, or a mesh that does not answer),//! with a log line saying so;//! - `require`: the mesh or nothing (a relay that can read sessions is@@ -39,16 +38,10 @@ use crate::relay::RelayAccount;/// How relay Spaces use the mesh (`CUA_MESH`, see [`cua_mesh::policy`]).pub use cua_mesh::policy::Policy as MeshPolicy;-/// Set on the cua daemon the Cua Spaces app starts.-const STARTED_BY_ENV: &str = "CUA_DAEMON_STARTED_BY";--/// The policy for this process now: `CUA_MESH`, else (in the daemon the-/// Cua Spaces app started) the app's update channel, else off. Read on-/// every connect, so a change applies to the next connection.+/// The policy for this process now: `CUA_MESH`, else prefer. Read on every+/// connect, so a change applies to the next connection.pub fn policy() -> MeshPolicy {- let app = std::env::var(STARTED_BY_ENV).is_ok_and(|v| v == "app");- let home = app.then(cua_home::cua_home);- MeshPolicy::current(home.as_deref())+ MeshPolicy::current()}/// Which node: the account's (one per relay) or an anonymous one for adiff --git a/scripts/docs-generators/cli-specs/cua.json b/scripts/docs-generators/cli-specs/cua.jsonindex 53eb645246..18852f5ea9 100644--- a/scripts/docs-generators/cli-specs/cua.json+++ b/scripts/docs-generators/cli-specs/cua.json@@ -9004,7 +9004,7 @@"subcommands": [{"abstract": "Set this computer up for unattended access: install cua-spacesd as a service that joins the cua.ai relay as your account",- "after_help": "Examples:\n # Join the cua.ai relay as your account (shares this desktop)\n cua host setup\n # A spare computer: do not share its desktop, run Spaces for your devices\n cua host setup --profile spare --name \"Mac mini (spare)\"\n cua host setup --no-desktop --provide-spaces\n # Add this computer with a one-time code from the Cua Spaces app\n # (Add a computer) or `cua host pair`: no sign-in needed here\n cua host setup --pair K7QM-4XPB-2RHD\n # Self-hosting teams: cua help advanced",+ "after_help": "Examples:\n # Join the cua.ai relay as your account (shares this desktop)\n cua host setup\n # A spare computer: do not share its desktop, run Spaces for your devices\n cua host setup --profile spare --name \"Mac mini (spare)\"\n cua host setup --no-desktop --provide-spaces\n # Add this computer with a one-time code from the Cua Spaces app\n # (Add a computer) or `cua host pair`: no sign-in needed here\n cua host setup --pair K7QM-4XPB-2RHD\n # Keep this computer off the end-to-end encrypted mesh (relay HTTPS only):\n # run setup with CUA_MESH=off in the environment\n # Self-hosting teams: cua help advanced","aliases": [],"arguments": [],"flags": [