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
Cache a11y excluded app filters (#4052)
Louis Beaumont943f94417800
diff --git a/crates/screenpipe-a11y/src/config.rs b/crates/screenpipe-a11y/src/config.rsindex 558adfb98..b72c00876 100644--- a/crates/screenpipe-a11y/src/config.rs+++ b/crates/screenpipe-a11y/src/config.rs@@ -83,6 +83,11 @@ pub struct UiCaptureConfig {/// Apps to exclude from capture (case-insensitive substring match)pub excluded_apps: Vec<String>,+ /// Cached lowercase parse of `excluded_apps`.+ /// Populated by `compile_patterns()` for hot-path app filtering.+ #[serde(skip)]+ pub excluded_app_patterns: Vec<String>,+/// Window title patterns to exclude (regex)#[serde(skip)]pub excluded_window_patterns: Vec<Regex>,@@ -214,6 +219,7 @@ impl Default for UiCaptureConfig {"Keychain Access".to_string(),"Credential Manager".to_string(),],+ excluded_app_patterns: Vec::new(),excluded_window_patterns: Vec::new(),// Incognito / private browsing detection is handled by the// `crate::incognito` module with comprehensive localized matching@@ -261,10 +267,29 @@ impl UiCaptureConfig {.iter().filter_map(|s| Regex::new(s).ok()).collect();+ self.excluded_app_patterns = self+ .excluded_apps+ .iter()+ .map(|app| app.to_lowercase())+ .collect();self.ignored_window_patterns = WindowPattern::parse_list(&self.ignored_windows);self.included_window_patterns = WindowPattern::parse_list(&self.included_windows);}+ /// Lazily resolve lowercased excluded-app patterns.+ fn resolved_excluded_apps(&self) -> std::borrow::Cow<'_, [String]> {+ if self.excluded_app_patterns.is_empty() && !self.excluded_apps.is_empty() {+ std::borrow::Cow::Owned(+ self.excluded_apps+ .iter()+ .map(|app| app.to_lowercase())+ .collect(),+ )+ } else {+ std::borrow::Cow::Borrowed(&self.excluded_app_patterns)+ }+ }+/// Lazily resolve the parsed ignore patterns. Returns the cache if it's/// already populated; otherwise parses on the fly. This keeps callers/// correct even if they forget to call `compile_patterns()` after@@ -297,9 +322,9 @@ impl UiCaptureConfig {let app_lower = app_name.to_lowercase();if self- .excluded_apps+ .resolved_excluded_apps().iter()- .any(|excluded| app_lower.contains(&excluded.to_lowercase()))+ .any(|excluded| app_lower.contains(excluded)){return false;}@@ -394,6 +419,7 @@ impl UiCaptureConfig {/// Builder pattern: set excluded appspub fn with_excluded_apps(mut self, apps: Vec<String>) -> Self {self.excluded_apps = apps;+ self.compile_patterns();self}diff --git a/crates/screenpipe-engine/src/ui_recorder.rs b/crates/screenpipe-engine/src/ui_recorder.rsindex e5e0de71d..97d57642d 100644--- a/crates/screenpipe-engine/src/ui_recorder.rs+++ b/crates/screenpipe-engine/src/ui_recorder.rs@@ -203,15 +203,10 @@ impl UiRecorderConfig {config.excluded_apps.push(app.to_lowercase());}- // Add excluded window patterns- for pattern in &self.excluded_windows {- if let Ok(re) = regex::Regex::new(pattern) {- config.excluded_window_patterns.push(re);- }- }-+ config.excluded_window_pattern_strings = self.excluded_windows.clone();config.ignored_windows = self.ignored_windows.clone();config.included_windows = self.included_windows.clone();+ config.compile_patterns();config}@@ -1609,6 +1604,21 @@ mod tests {assert!(!ui_config.capture_clipboard_content);}+ #[test]+ fn to_ui_config_refreshes_filter_caches() {+ let config = UiRecorderConfig {+ excluded_apps: vec!["SecretApp".to_string()],+ excluded_windows: vec![r"(?i)private window".to_string()],+ ..Default::default()+ };++ let ui_config = config.to_ui_config();++ assert!(!ui_config.excluded_app_patterns.is_empty());+ assert!(!ui_config.should_capture_app("secretapp helper"));+ assert!(!ui_config.should_capture_window("Private Window - Browser"));+ }+#[test]fn test_stop_flag_sets_on_stop() {let handle = UiRecorderHandle {