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
cleanup: remove dead Arc AppleScript code, use AXIdentifier only
Louis Beaumont71890295f6ee
diff --git a/crates/screenpipe-a11y/src/incognito/macos.rs b/crates/screenpipe-a11y/src/incognito/macos.rsindex 495617725..960ae678e 100644--- a/crates/screenpipe-a11y/src/incognito/macos.rs+++ b/crates/screenpipe-a11y/src/incognito/macos.rs@@ -4,14 +4,14 @@//! macOS incognito detector using AppleScript window properties.//!-//! Chromium-based browsers (Chrome, Edge, Brave, Arc) expose `mode` and-//! `incognito` properties on each window. We iterate **all** windows and+//! Chromium-based browsers (Chrome, Edge, Brave, Vivaldi, Opera) expose `mode`+//! and `incognito` properties on each window. We iterate **all** windows and//! match by title, since the captured window may not be the front window.//! This is **locale-independent** and reliable for those browsers.//!-//! For Arc specifically, we also collect tab URLs and titles from incognito-//! windows because Arc's accessibility tree reports the Space name (e.g.-//! "Space 1") instead of the page title, causing title-only matching to fail.+//! Arc is **not** handled here — Arc 1.138+ broke its AppleScript bridge+//! entirely. Arc incognito detection is handled in the tree walker via+//! `AXIdentifier` (which contains "bigIncognitoBrowserWindow" for incognito).//!//! For non-Chromium browsers (Firefox, Safari) we fall back to title-based//! detection via [`super::titles::is_title_private`].@@ -33,7 +33,8 @@ use super::IncognitoDetector;const CACHE_TTL: Duration = Duration::from_secs(2);/// Chromium-based browser names (lowercased) for which the AppleScript-/// window properties API is available.+/// window properties API is available. Arc is excluded — its AppleScript+/// bridge is broken since v1.138.const CHROMIUM_BROWSERS: &[&str] = &["google chrome","chrome",@@ -42,53 +43,28 @@ const CHROMIUM_BROWSERS: &[&str] = &["edge","brave browser","brave",- "arc","vivaldi","opera",];/// Maps an app name to the AppleScript application identifier.-///-/// Some apps have short display names ("Arc") that match their AppleScript-/// dict, while others need the full name ("Google Chrome").fn applescript_app_name(app_name: &str) -> &str {let lower = app_name.to_lowercase();match lower.as_str() {"chrome" => "Google Chrome","edge" => "Microsoft Edge","brave" => "Brave Browser",- _ => app_name, // "Google Chrome", "Arc", "Vivaldi", "Opera" work as-is+ _ => app_name, // "Google Chrome", "Vivaldi", "Opera" work as-is}}-/// Batch cache: stores incognito window titles, tab titles, and tab URLs.-/// One AppleScript call fetches everything, so switching between windows-/// within the TTL is free (no extra osascript spawns).+/// Batch cache: stores incognito window titles from a single AppleScript call.struct BatchCache {app_name: String,- /// Window titles of incognito windows (from AppleScript `name of w`)incognito_window_titles: HashSet<String>,- /// Tab titles inside incognito windows (for Arc where window title != tab title)- incognito_tab_titles: HashSet<String>,- /// Tab URLs inside incognito windows (most reliable for Arc matching)- incognito_tab_urls: HashSet<String>,timestamp: Instant,}-impl BatchCache {- fn is_incognito(&self, window_title: &str) -> bool {- self.incognito_window_titles.contains(window_title)- || self.incognito_tab_titles.contains(window_title)- }-- fn has_incognito_url(&self, url: &str) -> bool {- if url.is_empty() {- return false;- }- self.incognito_tab_urls.contains(url)- }-}-pub struct MacOSIncognitoDetector {cache: Mutex<Option<BatchCache>>,}@@ -101,74 +77,18 @@ impl MacOSIncognitoDetector {}/// Returns `true` if the app name (lowercased) is a known Chromium- /// browser that supports window property queries.+ /// browser that supports window property queries (excludes Arc).fn is_chromium_browser(app_name: &str) -> bool {let lower = app_name.to_lowercase();CHROMIUM_BROWSERS.iter().any(|b| lower.contains(b))}- fn is_arc(app_name: &str) -> bool {- app_name.to_lowercase() == "arc"- }-- /// Batch-query all incognito window titles (+ tab info for Arc) via AppleScript.- ///- /// Returns `Some(BatchCache data)` or `None` if the script failed.- ///- /// For Arc, the script also collects tab URLs and titles from incognito- /// windows because Arc's accessibility tree uses Space names instead of- /// page titles for the window name.- fn query_incognito_data(app_name: &str) -> Option<(HashSet<String>, HashSet<String>, HashSet<String>)> {+ /// Query all incognito window titles via AppleScript.+ fn query_incognito_titles(app_name: &str) -> Option<HashSet<String>> {let as_name = applescript_app_name(app_name);- let is_arc = Self::is_arc(app_name);-- // For Arc: collect window names, tab titles, and tab URLs from incognito windows.- // For other Chromium browsers: just collect window names (they match the a11y title).- // Format: "WINDOW:title|||TAB:tab_title|||URL:tab_url" separated by "~~~"- let script = if is_arc {- format!(- r#"if application "{name}" is running then- tell application "{name}"- set result_list to ""- repeat with w in every window- set dominated to false- try- if mode of w is "incognito" then set dominated to true- end try- if not dominated then- try- if incognito of w then set dominated to true- end try- end if- if dominated then- set wname to name of w- set entry to "WINDOW:" & wname- repeat with t in every tab of w- try- set entry to entry & "|||TAB:" & (title of t)- end try- try- set entry to entry & "|||URL:" & (URL of t)- end try- end repeat- if result_list is "" then- set result_list to entry- else- set result_list to result_list & "~~~" & entry- end if- end if- end repeat- if result_list is "" then return "none"- return result_list- end tell-else- return "not_running"-end if"#,- name = as_name,- )- } else {- format!(- r#"if application "{name}" is running then++ let script = format!(+ r#"if application "{name}" is running thentell application "{name}"set result_list to ""repeat with w in every window@@ -183,9 +103,9 @@ end if"#,end ifif dominated thenif result_list is "" then- set result_list to "WINDOW:" & name of w+ set result_list to name of welse- set result_list to result_list & "~~~" & "WINDOW:" & name of w+ set result_list to result_list & "~~~" & name of wend ifend ifend repeat@@ -195,9 +115,8 @@ end if"#,elsereturn "not_running"end if"#,- name = as_name,- )- };+ name = as_name,+ );let output = match Command::new("osascript").arg("-e").arg(&script).output() {Ok(o) => o,@@ -227,37 +146,18 @@ end if"#,}"none" => {debug!("incognito: {} has no incognito windows", as_name);- Some((HashSet::new(), HashSet::new(), HashSet::new()))+ Some(HashSet::new())}_ => {- let mut window_titles = HashSet::new();- let mut tab_titles = HashSet::new();- let mut tab_urls = HashSet::new();-- for window_entry in result.split("~~~") {- for part in window_entry.split("|||") {- if let Some(title) = part.strip_prefix("WINDOW:") {- window_titles.insert(title.to_string());- } else if let Some(title) = part.strip_prefix("TAB:") {- tab_titles.insert(title.to_string());- } else if let Some(url) = part.strip_prefix("URL:") {- tab_urls.insert(url.to_string());- }- }- }-+ let titles: HashSet<String> =+ result.split("~~~").map(|s| s.to_string()).collect();debug!(- "incognito: {} has {} incognito window(s), {} tab title(s), {} url(s)",+ "incognito: {} has {} incognito window(s): {:?}",as_name,- window_titles.len(),- tab_titles.len(),- tab_urls.len(),+ titles.len(),+ titles,);- debug!("incognito: window_titles={:?}", window_titles);- debug!("incognito: tab_titles={:?}", tab_titles);- debug!("incognito: tab_urls={:?}", tab_urls);-- Some((window_titles, tab_titles, tab_urls))+ Some(titles)}}}@@ -265,59 +165,35 @@ end if"#,/// Check if a window title belongs to an incognito window, using the/// batch cache. One AppleScript call per browser per TTL interval.fn check_with_cache(&self, app_name: &str, window_title: &str) -> Option<bool> {- // Check cache while holding the lock briefly.{let cache = self.cache.lock().unwrap_or_else(|e| e.into_inner());if let Some(entry) = cache.as_ref() {if entry.app_name.eq_ignore_ascii_case(app_name)&& entry.timestamp.elapsed() < CACHE_TTL{- return Some(entry.is_incognito(window_title));+ return Some(entry.incognito_window_titles.contains(window_title));}}}- // Lock released — safe to do slow I/O.- let (window_titles, tab_titles, tab_urls) = Self::query_incognito_data(app_name)?;- let is_incognito = window_titles.contains(window_title)- || tab_titles.contains(window_title);+ let titles = Self::query_incognito_titles(app_name)?;+ let is_incognito = titles.contains(window_title);- // Re-acquire lock to store the result.{let mut cache = self.cache.lock().unwrap_or_else(|e| e.into_inner());*cache = Some(BatchCache {app_name: app_name.to_string(),- incognito_window_titles: window_titles,- incognito_tab_titles: tab_titles,- incognito_tab_urls: tab_urls,+ incognito_window_titles: titles,timestamp: Instant::now(),});}Some(is_incognito)}-- /// Check if a URL belongs to an incognito tab (used as fallback when- /// window title matching fails, especially for Arc).- pub fn is_url_incognito(&self, app_name: &str, url: &str) -> bool {- if url.is_empty() {- return false;- }- let cache = self.cache.lock().unwrap_or_else(|e| e.into_inner());- if let Some(entry) = cache.as_ref() {- if entry.app_name.eq_ignore_ascii_case(app_name)- && entry.timestamp.elapsed() < CACHE_TTL- {- return entry.has_incognito_url(url);- }- }- false- }}impl IncognitoDetector for MacOSIncognitoDetector {fn is_incognito(&self, app_name: &str, _process_id: i32, window_title: &str) -> bool {- // Strategy 1: AppleScript query for Chromium browsers — checks all- // windows and matches by title (+ tab titles/URLs for Arc).+ // Strategy 1: AppleScript query for Chromium browsers (not Arc).if Self::is_chromium_browser(app_name) {if let Some(is_private) = self.check_with_cache(app_name, window_title) {return is_private;@@ -329,10 +205,7 @@ impl IncognitoDetector for MacOSIncognitoDetector {is_title_private(window_title)}- fn is_url_incognito(&self, app_name: &str, url: &str) -> bool {- // Delegate to the inherent method which checks the batch cache.- MacOSIncognitoDetector::is_url_incognito(self, app_name, url)- }+ // Arc's is_url_incognito is no longer needed — AXIdentifier handles it.}#[cfg(test)]@@ -343,38 +216,29 @@ mod tests {fn test_is_chromium_browser() {assert!(MacOSIncognitoDetector::is_chromium_browser("Google Chrome"));assert!(MacOSIncognitoDetector::is_chromium_browser("google chrome"));- assert!(MacOSIncognitoDetector::is_chromium_browser("Arc"));assert!(MacOSIncognitoDetector::is_chromium_browser("Microsoft Edge"));assert!(MacOSIncognitoDetector::is_chromium_browser("Brave Browser"));assert!(MacOSIncognitoDetector::is_chromium_browser("Vivaldi"));+ // Arc is NOT in the list — handled via AXIdentifier+ assert!(!MacOSIncognitoDetector::is_chromium_browser("Arc"));assert!(!MacOSIncognitoDetector::is_chromium_browser("Firefox"));assert!(!MacOSIncognitoDetector::is_chromium_browser("Safari"));assert!(!MacOSIncognitoDetector::is_chromium_browser("TextEdit"));}- #[test]- fn test_is_arc() {- assert!(MacOSIncognitoDetector::is_arc("Arc"));- assert!(MacOSIncognitoDetector::is_arc("arc"));- assert!(!MacOSIncognitoDetector::is_arc("Google Chrome"));- assert!(!MacOSIncognitoDetector::is_arc("ArcGIS")); // should not match- }-#[test]fn test_applescript_app_name_mapping() {assert_eq!(applescript_app_name("Chrome"), "Google Chrome");assert_eq!(applescript_app_name("Edge"), "Microsoft Edge");assert_eq!(applescript_app_name("Brave"), "Brave Browser");- assert_eq!(applescript_app_name("Arc"), "Arc");assert_eq!(applescript_app_name("Google Chrome"), "Google Chrome");}#[test]fn test_fallback_to_title_for_firefox() {let detector = MacOSIncognitoDetector::new();- // Firefox is not a Chromium browser, so it should fall back to title.assert!(detector.is_incognito("Firefox", 0, "Mozilla Firefox (Private Browsing)"));assert!(!detector.is_incognito("Firefox", 0, "Reddit - Mozilla Firefox"));}@@ -382,7 +246,6 @@ mod tests {#[test]fn test_fallback_to_title_for_safari() {let detector = MacOSIncognitoDetector::new();- // Safari private windows don't change title, so this returns false.assert!(!detector.is_incognito("Safari", 0, "Apple"));}@@ -390,7 +253,6 @@ mod tests {fn test_batch_cache_with_window_titles() {let detector = MacOSIncognitoDetector::new();- // Seed cache with known incognito window titles.{let mut cache = detector.cache.lock().unwrap();*cache = Some(BatchCache {@@ -401,97 +263,15 @@ mod tests {s.insert("Dog".to_string());s},- incognito_tab_titles: HashSet::new(),- incognito_tab_urls: HashSet::new(),timestamp: Instant::now(),});}- // Both incognito titles should be detected.assert!(detector.is_incognito("Google Chrome", 0, "Dog"));assert!(detector.is_incognito("Google Chrome", 0, "Secret Page"));- // Normal title should return false.assert!(!detector.is_incognito("Google Chrome", 0, "GitHub"));}- #[test]- fn test_arc_tab_title_matching() {- // Arc reports "Space 1" as window_name in a11y, but the actual page- // title is "The Browser Company". The cache should store tab titles- // from the AppleScript query, so matching by tab title works.- let detector = MacOSIncognitoDetector::new();-- {- let mut cache = detector.cache.lock().unwrap();- *cache = Some(BatchCache {- app_name: "Arc".to_string(),- incognito_window_titles: {- let mut s = HashSet::new();- s.insert("The Browser Company".to_string());- s- },- incognito_tab_titles: {- let mut s = HashSet::new();- s.insert("The Browser Company - YouTube".to_string());- s.insert("Secret Doc - Google Docs".to_string());- s- },- incognito_tab_urls: {- let mut s = HashSet::new();- s.insert("https://www.youtube.com/c/TheBrowserCompany".to_string());- s.insert("https://docs.google.com/secret".to_string());- s- },- timestamp: Instant::now(),- });- }-- // Window title from AppleScript matches- assert!(detector.is_incognito("Arc", 0, "The Browser Company"));- // Tab title matches (this is the key fix - tab title != window title in Arc)- assert!(detector.is_incognito("Arc", 0, "The Browser Company - YouTube"));- assert!(detector.is_incognito("Arc", 0, "Secret Doc - Google Docs"));- // Space name from a11y tree does NOT match (expected — but URL check will catch it)- assert!(!detector.is_incognito("Arc", 0, "Space 1"));- // Normal window should not be flagged- assert!(!detector.is_incognito("Arc", 0, "Google Meet"));- }-- #[test]- fn test_arc_url_matching() {- let detector = MacOSIncognitoDetector::new();-- {- let mut cache = detector.cache.lock().unwrap();- *cache = Some(BatchCache {- app_name: "Arc".to_string(),- incognito_window_titles: {- let mut s = HashSet::new();- s.insert("The Browser Company".to_string());- s- },- incognito_tab_titles: HashSet::new(),- incognito_tab_urls: {- let mut s = HashSet::new();- s.insert("https://www.youtube.com/c/TheBrowserCompany".to_string());- s.insert("https://secret-site.com/page".to_string());- s- },- timestamp: Instant::now(),- });- }-- // URL matching works even when window title is "Space 1"- assert!(detector.is_url_incognito("Arc", "https://www.youtube.com/c/TheBrowserCompany"));- assert!(detector.is_url_incognito("Arc", "https://secret-site.com/page"));- // Non-incognito URL- assert!(!detector.is_url_incognito("Arc", "https://meet.google.com/landing"));- // Empty URL- assert!(!detector.is_url_incognito("Arc", ""));- // Wrong app name (cache miss)- assert!(!detector.is_url_incognito("Google Chrome", "https://www.youtube.com/c/TheBrowserCompany"));- }-#[test]fn test_cache_different_app_misses() {let detector = MacOSIncognitoDetector::new();@@ -505,15 +285,12 @@ mod tests {s.insert("Dog".to_string());s},- incognito_tab_titles: HashSet::new(),- incognito_tab_urls: HashSet::new(),timestamp: Instant::now(),});}- // Different app should miss cache and fall through to osascript or title check- let result = detector.check_with_cache("Arc", "Dog");- // Result depends on whether Arc is running+ // Different app should miss cache+ let result = detector.check_with_cache("Brave Browser", "Dog");if let Some(val) = result {let _ = val;}@@ -528,8 +305,6 @@ mod tests {*cache = Some(BatchCache {app_name: "Google Chrome".to_string(),incognito_window_titles: HashSet::new(),- incognito_tab_titles: HashSet::new(),- incognito_tab_urls: HashSet::new(),timestamp: Instant::now() - Duration::from_secs(10),});}@@ -540,113 +315,4 @@ mod tests {let _ = val;}}-- #[test]- fn test_url_check_with_expired_cache() {- let detector = MacOSIncognitoDetector::new();-- {- let mut cache = detector.cache.lock().unwrap();- *cache = Some(BatchCache {- app_name: "Arc".to_string(),- incognito_window_titles: HashSet::new(),- incognito_tab_titles: HashSet::new(),- incognito_tab_urls: {- let mut s = HashSet::new();- s.insert("https://secret.com".to_string());- s- },- timestamp: Instant::now() - Duration::from_secs(10),- });- }-- // Expired cache should return false (not stale data)- assert!(!detector.is_url_incognito("Arc", "https://secret.com"));- }-- #[test]- fn test_arc_multiple_incognito_windows() {- let detector = MacOSIncognitoDetector::new();-- {- let mut cache = detector.cache.lock().unwrap();- *cache = Some(BatchCache {- app_name: "Arc".to_string(),- incognito_window_titles: {- let mut s = HashSet::new();- s.insert("Page A".to_string());- s.insert("Page B".to_string());- s- },- incognito_tab_titles: {- let mut s = HashSet::new();- s.insert("Tab A1".to_string());- s.insert("Tab A2".to_string());- s.insert("Tab B1".to_string());- s- },- incognito_tab_urls: {- let mut s = HashSet::new();- s.insert("https://a1.com".to_string());- s.insert("https://a2.com".to_string());- s.insert("https://b1.com".to_string());- s- },- timestamp: Instant::now(),- });- }-- // All incognito entries should match- assert!(detector.is_incognito("Arc", 0, "Page A"));- assert!(detector.is_incognito("Arc", 0, "Tab A1"));- assert!(detector.is_incognito("Arc", 0, "Tab B1"));- assert!(detector.is_url_incognito("Arc", "https://a1.com"));- assert!(detector.is_url_incognito("Arc", "https://b1.com"));- // Normal entries should not- assert!(!detector.is_incognito("Arc", 0, "Google Meet"));- assert!(!detector.is_url_incognito("Arc", "https://meet.google.com"));- }-- // --- Live test: only runs if Arc is actually running with incognito windows ---- // Run with: cargo test -p screenpipe-a11y -- --ignored test_live_arc- #[test]- #[ignore]- fn test_live_arc_incognito_detection() {- let detector = MacOSIncognitoDetector::new();-- // This will actually call AppleScript against Arc- let data = MacOSIncognitoDetector::query_incognito_data("Arc");- match data {- Some((window_titles, tab_titles, tab_urls)) => {- println!("Arc incognito window titles: {:?}", window_titles);- println!("Arc incognito tab titles: {:?}", tab_titles);- println!("Arc incognito tab URLs: {:?}", tab_urls);-- if window_titles.is_empty() {- println!("No incognito windows found — open one in Arc to test");- } else {- // Verify that the detector works with the live data- for title in &window_titles {- assert!(- detector.is_incognito("Arc", 0, title),- "Window title '{}' should be detected as incognito",- title- );- }-- // After is_incognito call, cache should be populated- for url in &tab_urls {- assert!(- detector.is_url_incognito("Arc", url),- "URL '{}' should be detected as incognito",- url- );- }- }- }- None => {- println!("Arc is not running or AppleScript failed — skipping live test");- }- }- }}diff --git a/crates/screenpipe-a11y/src/incognito/mod.rs b/crates/screenpipe-a11y/src/incognito/mod.rsindex facac7d33..600cf4992 100644--- a/crates/screenpipe-a11y/src/incognito/mod.rs+++ b/crates/screenpipe-a11y/src/incognito/mod.rs@@ -53,18 +53,6 @@ pub trait IncognitoDetector: Send + Sync {/// definitely normal, or falls back to title-based detection when the/// platform API is unavailable for this browser.fn is_incognito(&self, app_name: &str, process_id: i32, window_title: &str) -> bool;-- /// Check whether a browser URL belongs to an incognito tab.- ///- /// This is a fallback for browsers like Arc where the accessibility tree- /// reports a different window name (Space name) than the AppleScript- /// window title. The URL is extracted after the tree walk and can be- /// checked against the cached incognito tab URLs.- ///- /// Default implementation returns `false` (no URL-based detection).- fn is_url_incognito(&self, _app_name: &str, _url: &str) -> bool {- false- }}/// Create the platform-appropriate incognito detector.diff --git a/crates/screenpipe-a11y/src/tree/macos.rs b/crates/screenpipe-a11y/src/tree/macos.rsindex 05cc9e55c..37a9bf611 100644--- a/crates/screenpipe-a11y/src/tree/macos.rs+++ b/crates/screenpipe-a11y/src/tree/macos.rs@@ -348,19 +348,6 @@ impl MacosTreeWalker {None};- // Second-pass incognito check using browser URL (catches Arc where- // the a11y window name is the Space name, not the page title).- // The first check at line ~266 uses window_title which may not match- // for Arc. This URL-based check uses the cached incognito tab URLs- // populated by the earlier is_incognito() call.- if self.config.ignore_incognito_windows {- if let Some(ref url) = browser_url {- if self.incognito_detector.is_url_incognito(&app_name, url) {- return Ok(TreeWalkResult::Skipped(SkipReason::Incognito));- }- }- }-debug!("tree walk: app={}, window={}, nodes={}, text_len={}, url={:?}, duration={:?}",app_name,