YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context
Rust agentsagiaiai-memoryaudio-recordingcomputer-visionhermeshermes-agentllmlocal-ailocal-firstmachine-learningmcpmultimodalopenclawprivacyrewindscreen-recordingspeech-to-textycombinator
fix: replace subprocess clipboard reads with native arboard crate
Louis Beaumont6a1bfa9e73fb
diff --git a/Cargo.lock b/Cargo.lockindex 4e2f9a84d..718197671 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -271,6 +271,26 @@ dependencies = ["derive_arbitrary",]+[[package]]+name = "arboard"+version = "3.6.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "0348a1c054491f4bfe6ab86a7b6ab1e44e45d899005de92f58b3df180b36ddaf"+dependencies = [+ "clipboard-win",+ "image",+ "log",+ "objc2",+ "objc2-app-kit",+ "objc2-core-foundation",+ "objc2-core-graphics",+ "objc2-foundation",+ "parking_lot",+ "percent-encoding",+ "windows-sys 0.60.2",+ "x11rb",+]+[[package]]name = "arc-swap"version = "1.9.1"@@ -1233,6 +1253,15 @@ version = "1.1.0"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "c8d4a3bb8b1e0c1050499d1815f5ab16d04f0959b233085fb31653fbfc9d98f9"+[[package]]+name = "clipboard-win"+version = "5.4.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "bde03770d3df201d4fb868f2c9c59e66a3e4e2bd06692a0fe701e7103c7e84d4"+dependencies = [+ "error-code",+]+[[package]]name = "cmake"version = "0.1.58"@@ -1986,7 +2015,7 @@ dependencies = ["libc","option-ext","redox_users 0.5.2",- "windows-sys 0.59.0",+ "windows-sys 0.61.2",][[package]]@@ -2276,9 +2305,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb"dependencies = ["libc",- "windows-sys 0.59.0",+ "windows-sys 0.61.2",]+[[package]]+name = "error-code"+version = "3.3.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "dea2df4cf52843e0452895c455a1a2cfbb842a1e7329671acf418fdc53ed4c59"+[[package]]name = "esaxx-rs"version = "0.1.10"@@ -2749,6 +2784,16 @@ dependencies = ["typenum",]+[[package]]+name = "gethostname"+version = "1.1.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "1bd49230192a3797a9a4d6abe9b3eed6f7fa4c8a8a4947977c6f80025f92cbd8"+dependencies = [+ "rustix 1.1.4",+ "windows-link 0.2.1",+]+[[package]]name = "getrandom"version = "0.2.17"@@ -3242,7 +3287,7 @@ dependencies = ["hyper","libc","pin-project-lite",- "socket2 0.5.10",+ "socket2 0.6.3","tokio","tower-service","tracing",@@ -3592,7 +3637,7 @@ checksum = "3640c1c38b8e4e43584d8df18be5fc6b0aa314ce6ebf51b53313d4306cca8e46"dependencies = ["hermit-abi","libc",- "windows-sys 0.59.0",+ "windows-sys 0.61.2",][[package]]@@ -4551,7 +4596,7 @@ version = "0.50.3"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5"dependencies = [- "windows-sys 0.59.0",+ "windows-sys 0.61.2",][[package]]@@ -5801,7 +5846,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "8a56d757972c98b346a9b766e3f02746cde6dd1cd1d1d563472929fdd74bec4d"dependencies = ["anyhow",- "itertools 0.10.5",+ "itertools 0.14.0","proc-macro2","quote","syn 2.0.117",@@ -5878,7 +5923,7 @@ dependencies = ["quinn-udp","rustc-hash 2.1.2","rustls 0.23.37",- "socket2 0.5.10",+ "socket2 0.6.3","thiserror 2.0.18","tokio","tracing",@@ -5915,9 +5960,9 @@ dependencies = ["cfg_aliases","libc","once_cell",- "socket2 0.5.10",+ "socket2 0.6.3","tracing",- "windows-sys 0.59.0",+ "windows-sys 0.60.2",][[package]]@@ -6516,7 +6561,7 @@ dependencies = ["errno","libc","linux-raw-sys 0.12.1",- "windows-sys 0.59.0",+ "windows-sys 0.61.2",][[package]]@@ -6729,6 +6774,7 @@ name = "screenpipe-a11y"version = "0.1.0"dependencies = ["anyhow",+ "arboard","arc-swap","chrono","cidre 0.13.1",@@ -8294,7 +8340,7 @@ dependencies = ["getrandom 0.4.2","once_cell","rustix 1.1.4",- "windows-sys 0.59.0",+ "windows-sys 0.61.2",][[package]]@@ -9570,7 +9616,7 @@ version = "0.1.11"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22"dependencies = [- "windows-sys 0.48.0",+ "windows-sys 0.61.2",][[package]]@@ -10275,6 +10321,23 @@ dependencies = ["tap",]+[[package]]+name = "x11rb"+version = "0.13.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "9993aa5be5a26815fe2c3eacfc1fde061fc1a1f094bf1ad2a18bf9c495dd7414"+dependencies = [+ "gethostname",+ "rustix 1.1.4",+ "x11rb-protocol",+]++[[package]]+name = "x11rb-protocol"+version = "0.13.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "ea6fc2961e4ef194dcbfe56bb845534d0dc8098940c7e5c012a258bfec6701bd"+[[package]]name = "xattr"version = "1.6.1"diff --git a/crates/screenpipe-a11y/Cargo.toml b/crates/screenpipe-a11y/Cargo.tomlindex 000ef3c56..d3ad94aa6 100644--- a/crates/screenpipe-a11y/Cargo.toml+++ b/crates/screenpipe-a11y/Cargo.toml@@ -29,6 +29,9 @@ arc-swap = "1"# Regex for privacy patternsregex = "1.10"+# Clipboard access (native NSPasteboard/Win32/X11 — no subprocess)+arboard = "3"+[target.'cfg(target_os = "macos")'.dependencies]cidre = { version = "0.13", features = ["ax", "cg", "blocks", "ns", "app"] }diff --git a/crates/screenpipe-a11y/src/platform/linux.rs b/crates/screenpipe-a11y/src/platform/linux.rsindex a1fdbd15b..d72631290 100644--- a/crates/screenpipe-a11y/src/platform/linux.rs+++ b/crates/screenpipe-a11y/src/platform/linux.rs@@ -1101,42 +1101,15 @@ fn run_activity_only_evdev(activity_feed: ActivityFeed, stop: Arc<AtomicBool>) {// Clipboard helpers// ============================================================================-/// Get clipboard content. Tries wl-paste (Wayland) first, then xclip (X11).+/// Get clipboard content using arboard (native Wayland/X11 support).fn get_clipboard() -> Option<String> {- // Try wl-paste (Wayland)- if let Ok(output) = std::process::Command::new("wl-paste")- .args(["--no-newline"])- .output()- {- if output.status.success() {- let content = String::from_utf8_lossy(&output.stdout).to_string();- if !content.is_empty() {- return Some(content);- }- }- }-- // Try xclip (X11)- if let Ok(output) = std::process::Command::new("xclip")- .args(["-o", "-selection", "clipboard"])- .output()- {- if output.status.success() {- let content = String::from_utf8_lossy(&output.stdout).to_string();- if !content.is_empty() {- return Some(content);- }- }+ let mut clipboard = arboard::Clipboard::new().ok()?;+ let text = clipboard.get_text().ok()?;+ if text.is_empty() {+ None+ } else {+ Some(text)}-- // Try xsel (X11 alternative)- std::process::Command::new("xsel")- .args(["--clipboard", "--output"])- .output()- .ok()- .filter(|o| o.status.success())- .map(|o| String::from_utf8_lossy(&o.stdout).to_string())- .filter(|s| !s.is_empty())}// ============================================================================diff --git a/crates/screenpipe-a11y/src/platform/macos.rs b/crates/screenpipe-a11y/src/platform/macos.rsindex 139d6a6de..47adce7f9 100644--- a/crates/screenpipe-a11y/src/platform/macos.rs+++ b/crates/screenpipe-a11y/src/platform/macos.rs@@ -1143,12 +1143,13 @@ fn get_focused_element_context(config: &UiCaptureConfig) -> Option<ElementContex}fn get_clipboard() -> Option<String> {- std::process::Command::new("pbpaste")- .output()- .ok()- .filter(|o| o.status.success())- .map(|o| String::from_utf8_lossy(&o.stdout).to_string())- .filter(|s| !s.is_empty())+ let mut clipboard = arboard::Clipboard::new().ok()?;+ let text = clipboard.get_text().ok()?;+ if text.is_empty() {+ None+ } else {+ Some(text)+ }}fn truncate(s: &str, max: usize) -> String {@@ -1484,4 +1485,85 @@ mod tests {assert_eq!(truncate("hello", 10), "hello");assert_eq!(truncate("hello world", 8), "hello...");}++ #[test]+ fn test_get_clipboard_returns_option() {+ // Should not panic regardless of clipboard state+ let result = get_clipboard();+ // Result is either Some(non-empty string) or None+ if let Some(ref text) = result {+ assert!(+ !text.is_empty(),+ "get_clipboard should never return Some(\"\")"+ );+ }+ }++ #[test]+ fn test_get_clipboard_no_subprocess() {+ // Verify arboard doesn't spawn pbpaste by checking it completes fast.+ // pbpaste fork+exec takes >1ms; native NSPasteboard is <0.5ms.+ let start = std::time::Instant::now();+ for _ in 0..10 {+ let _ = get_clipboard();+ }+ let elapsed = start.elapsed();+ // 10 calls should complete in under 50ms with native API+ // (pbpaste would take 20-100ms+ due to process spawning)+ assert!(+ elapsed < std::time::Duration::from_millis(200),+ "10 clipboard reads took {:?} — too slow, may be spawning subprocesses",+ elapsed+ );+ }++ #[test]+ fn test_get_clipboard_set_and_read() {+ // Round-trip: set clipboard text, then read it back+ let test_text = "screenpipe_clipboard_test_12345";+ {+ let mut clipboard = arboard::Clipboard::new().expect("clipboard init");+ clipboard.set_text(test_text).expect("clipboard set");+ }+ let result = get_clipboard();+ assert_eq!(result, Some(test_text.to_string()));+ }++ #[test]+ fn test_get_clipboard_empty_returns_none() {+ // Set clipboard to empty string, should return None+ {+ let mut clipboard = arboard::Clipboard::new().expect("clipboard init");+ clipboard.set_text("").expect("clipboard set empty");+ }+ let result = get_clipboard();+ assert!(result.is_none(), "empty clipboard should return None");+ }++ #[test]+ fn test_get_clipboard_unicode() {+ let unicode_text = "日本語テスト 🎉 émojis ñ";+ {+ let mut clipboard = arboard::Clipboard::new().expect("clipboard init");+ clipboard+ .set_text(unicode_text)+ .expect("clipboard set unicode");+ }+ let result = get_clipboard();+ assert_eq!(result, Some(unicode_text.to_string()));+ }++ #[test]+ fn test_get_clipboard_large_content() {+ // 100KB of text — should not OOM or hang+ let large_text: String = "x".repeat(100_000);+ {+ let mut clipboard = arboard::Clipboard::new().expect("clipboard init");+ clipboard+ .set_text(&large_text)+ .expect("clipboard set large");+ }+ let result = get_clipboard();+ assert_eq!(result, Some(large_text));+ }}diff --git a/crates/screenpipe-a11y/src/platform/windows_uia.rs b/crates/screenpipe-a11y/src/platform/windows_uia.rsindex 01a5ed647..6efb390ff 100644--- a/crates/screenpipe-a11y/src/platform/windows_uia.rs+++ b/crates/screenpipe-a11y/src/platform/windows_uia.rs@@ -882,42 +882,12 @@ fn get_window_info(hwnd: HWND) -> (String, Option<String>, u32) {/// Get text content from the Windows clipboardpub fn get_clipboard_text_impl() -> Option<String> {- use windows::Win32::Foundation::HANDLE;- use windows::Win32::Foundation::HGLOBAL;- use windows::Win32::System::DataExchange::{CloseClipboard, GetClipboardData, OpenClipboard};- use windows::Win32::System::Memory::{GlobalLock, GlobalUnlock};- use windows::Win32::System::Ole::CF_UNICODETEXT;-- unsafe {- if OpenClipboard(HWND::default()).is_err() {- return None;- }-- let result = (|| -> Option<String> {- let handle: HANDLE = GetClipboardData(CF_UNICODETEXT.0 as u32).ok()?;- let hglobal = HGLOBAL(handle.0);- let ptr = GlobalLock(hglobal) as *const u16;- if ptr.is_null() {- return None;- }-- // Find null terminator- let mut len = 0;- while *ptr.add(len) != 0 {- len += 1;- if len > 1_000_000 {- break; // Safety cap: 1M chars- }- }-- let slice = std::slice::from_raw_parts(ptr, len);- let text = String::from_utf16_lossy(slice);- let _ = GlobalUnlock(hglobal);- Some(text)- })();-- let _ = CloseClipboard();- result+ let mut clipboard = arboard::Clipboard::new().ok()?;+ let text = clipboard.get_text().ok()?;+ if text.is_empty() {+ None+ } else {+ Some(text)}}