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.

refactor(cua-driver): remove the PiP backend factory registry (#3752)

injaneityf2472854c100
diff --git a/libs/cua-driver/rust/Cargo.lock b/libs/cua-driver/rust/Cargo.lock
index 1f4c36cfba..4ef66cf308 100644
--- a/libs/cua-driver/rust/Cargo.lock
+++ b/libs/cua-driver/rust/Cargo.lock
@@ -3242,9 +3242,7 @@ checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd"
name = "pip-preview"
version = "0.28.0"
dependencies = [
- "anyhow",
"serde_json",
- "tracing",
]
[[package]]
diff --git a/libs/cua-driver/rust/crates/cua-driver/src/main.rs b/libs/cua-driver/rust/crates/cua-driver/src/main.rs
index 7939402c6a..5d6ac1f147 100644
--- a/libs/cua-driver/rust/crates/cua-driver/src/main.rs
+++ b/libs/cua-driver/rust/crates/cua-driver/src/main.rs
@@ -226,7 +226,7 @@ fn run_cursor_theme_command(args: &[String]) -> ! {
/// enough to be useful).
///
/// No-op when `--experimental-pip` is not on argv. On Windows / Linux
-/// the factory returns "not yet implemented" — we log and continue
+/// startup returns "not yet implemented" — we log and continue
/// without a window so the rest of the daemon keeps working.
fn maybe_init_pip() {
let cfg = match pip_preview::default_config_path() {
@@ -237,16 +237,14 @@ fn maybe_init_pip() {
return;
}
- // Register the platform factory. The set is idempotent so multiple
- // entry points calling this in the same process is safe.
#[cfg(target_os = "macos")]
- pip_preview::set_pip_backend_factory(Box::new(platform_macos::pip::MacosPipBackendFactory));
+ let backend = platform_macos::pip::start(&cfg);
#[cfg(target_os = "windows")]
- pip_preview::set_pip_backend_factory(Box::new(platform_windows::pip::WindowsPipBackendFactory));
+ let backend = platform_windows::pip::start(&cfg);
#[cfg(target_os = "linux")]
- pip_preview::set_pip_backend_factory(Box::new(platform_linux::pip::LinuxPipBackendFactory));
+ let backend = platform_linux::pip::start(&cfg);
- match pip_preview::start_pip(&cfg) {
+ match backend {
Ok(backend) => {
// Bridge: when the tool dispatcher in cua-driver-core wants
// to push a frame, forward to the live backend handle.
diff --git a/libs/cua-driver/rust/crates/pip-preview/Cargo.toml b/libs/cua-driver/rust/crates/pip-preview/Cargo.toml
index 5d504210d7..1c9f84b1ce 100644
--- a/libs/cua-driver/rust/crates/pip-preview/Cargo.toml
+++ b/libs/cua-driver/rust/crates/pip-preview/Cargo.toml
@@ -4,6 +4,4 @@ version.workspace = true
edition.workspace = true
[dependencies]
-anyhow = { workspace = true }
-tracing = { workspace = true }
serde_json = { workspace = true }
diff --git a/libs/cua-driver/rust/crates/pip-preview/src/lib.rs b/libs/cua-driver/rust/crates/pip-preview/src/lib.rs
index f8efa30b7e..8679316321 100644
--- a/libs/cua-driver/rust/crates/pip-preview/src/lib.rs
+++ b/libs/cua-driver/rust/crates/pip-preview/src/lib.rs
@@ -6,16 +6,13 @@
//! of the target window plus a one-line label summarising the tool
//! call. It mirrors the architecture used by `cursor-overlay` (shared
//! config/types here, platform-specific renderer in each `platform-*`
-//! crate) and the registration pattern used by `cua_driver_core::video`
-//! (a `OnceLock` factory set once at startup by `main.rs`).
+//! crate).
//!
//! macOS is the first working implementation (NSWindow + NSImageView).
//! Windows + Linux ship as compile-clean stubs whose `start()` returns
//! a clear "not yet implemented" error so the rest of the daemon
//! continues without a PiP window.
-use std::sync::OnceLock;
-
/// Canonical `~/.cua-driver/config.json` path matching what the per-platform
/// `set_config` tools write to. Resolves `$HOME` first (Unix/macOS) and falls
/// back to `%USERPROFILE%` (Windows, where `HOME` is usually unset). Returns
@@ -145,13 +142,10 @@ impl PipGeometry {
}
}
-/// Configuration for the PiP window. Built by `main.rs` from CLI
-/// flags and handed to `PipBackendFactory::start`.
+/// Configuration for the PiP window. Built by `main.rs` from CLI flags.
#[derive(Debug, Clone)]
pub struct PipConfig {
- /// `--experimental-pip` is on argv. The factory is only consulted
- /// when this is true; the field is kept here so backends that
- /// share a `start()` path can early-return.
+ /// `--experimental-pip` is on argv.
pub enabled: bool,
pub geometry: PipGeometry,
/// Window title — kept here so the "experimental" label stays in
@@ -280,29 +274,3 @@ pub trait PipBackend: Send + Sync {
/// `main.rs` on shutdown.
fn shutdown(self: Box<Self>);
}
-
-/// Spawns a fresh PiP window. Registered once at startup via
-/// `set_pip_backend_factory`.
-pub trait PipBackendFactory: Send + Sync {
- fn start(&self, cfg: &PipConfig) -> anyhow::Result<Box<dyn PipBackend>>;
-}
-
-static PIP_FACTORY: OnceLock<Box<dyn PipBackendFactory>> = OnceLock::new();
-
-/// Register the platform's PiP backend factory. Idempotent — subsequent
-/// calls are silently ignored, matching the other startup-callback
-/// setters in `cua_driver_core`.
-pub fn set_pip_backend_factory(factory: Box<dyn PipBackendFactory>) {
- let _ = PIP_FACTORY.set(factory);
-}
-
-/// Start a PiP window using the registered backend. Returns an error
-/// when no backend has been registered for this platform — `main.rs`
-/// treats that as "PiP unavailable on this OS" and continues without
-/// the window.
-pub fn start_pip(cfg: &PipConfig) -> anyhow::Result<Box<dyn PipBackend>> {
- let factory = PIP_FACTORY
- .get()
- .ok_or_else(|| anyhow::anyhow!("no PiP backend registered for this platform"))?;
- factory.start(cfg)
-}
diff --git a/libs/cua-driver/rust/crates/platform-linux/src/pip/mod.rs b/libs/cua-driver/rust/crates/platform-linux/src/pip/mod.rs
index 805c0eb4e6..04960db480 100644
--- a/libs/cua-driver/rust/crates/platform-linux/src/pip/mod.rs
+++ b/libs/cua-driver/rust/crates/platform-linux/src/pip/mod.rs
@@ -9,15 +9,25 @@
//! can log "PiP unavailable on this platform" and continue without
//! the window.
-use pip_preview::{PipBackend, PipBackendFactory, PipConfig};
+use pip_preview::{PipBackend, PipConfig};
-pub struct LinuxPipBackendFactory;
+pub fn start(_cfg: &PipConfig) -> anyhow::Result<Box<dyn PipBackend>> {
+ Err(anyhow::anyhow!(
+ "PiP preview is not yet implemented on Linux — track \
+ trycua/cua follow-up issue for status"
+ ))
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
-impl PipBackendFactory for LinuxPipBackendFactory {
- fn start(&self, _cfg: &PipConfig) -> anyhow::Result<Box<dyn PipBackend>> {
- Err(anyhow::anyhow!(
- "PiP preview is not yet implemented on Linux — track \
- trycua/cua follow-up issue for status"
- ))
+ #[test]
+ fn start_reports_unsupported() {
+ let error = start(&PipConfig::default()).err().expect("unsupported PiP");
+ assert_eq!(
+ error.to_string(),
+ "PiP preview is not yet implemented on Linux — track trycua/cua follow-up issue for status"
+ );
}
}
diff --git a/libs/cua-driver/rust/crates/platform-macos/src/pip/mod.rs b/libs/cua-driver/rust/crates/platform-macos/src/pip/mod.rs
index 587fa0fc03..5ffe2afea3 100644
--- a/libs/cua-driver/rust/crates/platform-macos/src/pip/mod.rs
+++ b/libs/cua-driver/rust/crates/platform-macos/src/pip/mod.rs
@@ -35,7 +35,7 @@
//! ## Init lifecycle
//!
//! Because the cursor overlay already owns the main thread when
-//! enabled, `MacosPipBackend::start` cannot block on it. Instead it
+//! enabled, `start` cannot block on it. Instead it
//! posts the window-creation block onto the main queue and returns
//! immediately. The first frame may arrive before the window exists;
//! that's fine — the push path reads the window pointer from a
@@ -44,7 +44,7 @@
use std::ffi::c_void;
use std::sync::Mutex;
-use pip_preview::{PipBackend, PipBackendFactory, PipConfig, PipFrame};
+use pip_preview::{PipBackend, PipConfig, PipFrame};
// ── CGColor objc2 encoding shim ────────────────────────────────────────────
//
@@ -217,20 +217,14 @@ pub fn run_appkit_main_loop() {
}
}
-// ── Factory ──────────────────────────────────────────────────────────────
-
-pub struct MacosPipBackendFactory;
-
-impl PipBackendFactory for MacosPipBackendFactory {
- fn start(&self, cfg: &PipConfig) -> anyhow::Result<Box<dyn PipBackend>> {
- // Window construction must happen on the main thread. We hand
- // off via dispatch_async_f and return immediately — the first
- // few frames may be dropped while init races, which is fine
- // for a live-preview UX.
- let cfg_clone = cfg.clone();
- dispatch_to_main(cfg_clone, init_cb);
- Ok(Box::new(MacosPipBackend))
- }
+pub fn start(cfg: &PipConfig) -> anyhow::Result<Box<dyn PipBackend>> {
+ // Window construction must happen on the main thread. We hand
+ // off via dispatch_async_f and return immediately — the first
+ // few frames may be dropped while init races, which is fine
+ // for a live-preview UX.
+ let cfg_clone = cfg.clone();
+ dispatch_to_main(cfg_clone, init_cb);
+ Ok(Box::new(MacosPipBackend))
}
unsafe extern "C" fn init_cb(ctx: *mut c_void) {
diff --git a/libs/cua-driver/rust/crates/platform-windows/src/pip/mod.rs b/libs/cua-driver/rust/crates/platform-windows/src/pip/mod.rs
index 6f8666fced..27ff16b232 100644
--- a/libs/cua-driver/rust/crates/platform-windows/src/pip/mod.rs
+++ b/libs/cua-driver/rust/crates/platform-windows/src/pip/mod.rs
@@ -10,15 +10,25 @@
//! can log "PiP unavailable on this platform" and continue without
//! the window.
-use pip_preview::{PipBackend, PipBackendFactory, PipConfig};
+use pip_preview::{PipBackend, PipConfig};
-pub struct WindowsPipBackendFactory;
+pub fn start(_cfg: &PipConfig) -> anyhow::Result<Box<dyn PipBackend>> {
+ Err(anyhow::anyhow!(
+ "PiP preview is not yet implemented on Windows — track \
+ trycua/cua follow-up issue for status"
+ ))
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
-impl PipBackendFactory for WindowsPipBackendFactory {
- fn start(&self, _cfg: &PipConfig) -> anyhow::Result<Box<dyn PipBackend>> {
- Err(anyhow::anyhow!(
- "PiP preview is not yet implemented on Windows — track \
- trycua/cua follow-up issue for status"
- ))
+ #[test]
+ fn start_reports_unsupported() {
+ let error = start(&PipConfig::default()).err().expect("unsupported PiP");
+ assert_eq!(
+ error.to_string(),
+ "PiP preview is not yet implemented on Windows — track trycua/cua follow-up issue for status"
+ );
}
}