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: move clipboard read + PII regex out of Windows LL keyboard hook
Louis Beaumontbe5d5f1b3ad7
diff --git a/crates/screenpipe-a11y/src/platform/windows.rs b/crates/screenpipe-a11y/src/platform/windows.rsindex 0fa762732..2351c15b8 100644--- a/crates/screenpipe-a11y/src/platform/windows.rs+++ b/crates/screenpipe-a11y/src/platform/windows.rs@@ -279,6 +279,16 @@ impl UiRecorder {// Thread-local state for hook callbacks// ============================================================================+/// A deferred clipboard read request, queued from the LL hook and processed+/// in the message loop where blocking is safe.+struct PendingClipboard {+ operation: char,+ timestamp: chrono::DateTime<Utc>,+ relative_ms: u64,+ app_name: Option<String>,+ window_title: Option<String>,+}+struct HookState {tx: Sender<UiEvent>,start: Instant,@@ -291,6 +301,8 @@ struct HookState {activity_feed: Option<ActivityFeed>,click_queue: Arc<Mutex<Vec<ClickElementRequest>>>,focused_element: Arc<Mutex<Option<ElementContext>>>,+ /// Clipboard operations deferred from the LL hook to the message loop.+ pending_clipboard: Vec<PendingClipboard>,}// Thread-local storage for hook state@@ -331,6 +343,7 @@ fn run_native_hooks(activity_feed,click_queue,focused_element,+ pending_clipboard: Vec::new(),}));});@@ -381,6 +394,38 @@ fn run_native_hooks(flush_text_buffer(s);}}++ // Process deferred clipboard operations — safe to block here+ // since we're in the message loop, not a LL hook callback.+ if !s.pending_clipboard.is_empty() {+ let pending = std::mem::take(&mut s.pending_clipboard);+ let capture_content = s.config.capture_clipboard_content;+ let apply_pii = s.config.apply_pii_removal;+ for p in pending {+ let content = if capture_content {+ get_clipboard_text().map(|c| {+ if apply_pii { remove_pii(&c) } else { c }+ })+ } else {+ None+ };+ let event = UiEvent {+ id: None,+ timestamp: p.timestamp,+ relative_ms: p.relative_ms,+ data: EventData::Clipboard {+ operation: p.operation,+ content,+ },+ app_name: p.app_name,+ window_title: p.window_title,+ browser_url: None,+ element: None,+ frame_id: None,+ };+ let _ = s.tx.try_send(event);+ }+ }}}});@@ -472,98 +517,26 @@ unsafe extern "system" fn keyboard_hook_proc(code: i32, wparam: WPARAM, lparam:}// Check for clipboard operations (Ctrl+C, Ctrl+X, Ctrl+V)+ // IMPORTANT: Do NOT read clipboard or apply PII regex here — this is+ // a low-level hook callback that must return in <10ms or it stalls the+ // entire system input queue. Instead, defer to the message loop.if mods & 0x02 != 0 && s.config.capture_clipboard {// Ctrl is pressed- let apply_pii = s.config.apply_pii_removal;- match vk_code {- 0x43 => {- // C- let event = UiEvent {- id: None,- timestamp,- relative_ms: t,- data: EventData::Clipboard {- operation: 'c',- content: if s.config.capture_clipboard_content {- get_clipboard_text().map(|c| {- if apply_pii {- remove_pii(&c)- } else {- c- }- })- } else {- None- },- },- app_name: app_name.clone(),- window_title: window_title.clone(),- browser_url: None,- element: None,- frame_id: None,- };- let _ = s.tx.try_send(event);- return;- }- 0x58 => {- // X- let event = UiEvent {- id: None,- timestamp,- relative_ms: t,- data: EventData::Clipboard {- operation: 'x',- content: if s.config.capture_clipboard_content {- get_clipboard_text().map(|c| {- if apply_pii {- remove_pii(&c)- } else {- c- }- })- } else {- None- },- },- app_name: app_name.clone(),- window_title: window_title.clone(),- browser_url: None,- element: None,- frame_id: None,- };- let _ = s.tx.try_send(event);- return;- }- 0x56 => {- // V- let event = UiEvent {- id: None,- timestamp,- relative_ms: t,- data: EventData::Clipboard {- operation: 'v',- content: if s.config.capture_clipboard_content {- get_clipboard_text().map(|c| {- if apply_pii {- remove_pii(&c)- } else {- c- }- })- } else {- None- },- },- app_name: app_name.clone(),- window_title: window_title.clone(),- browser_url: None,- element: None,- frame_id: None,- };- let _ = s.tx.try_send(event);- return;- }- _ => {}+ let op = match vk_code {+ 0x43 => Some('c'), // C+ 0x58 => Some('x'), // X+ 0x56 => Some('v'), // V+ _ => None,+ };+ if let Some(operation) = op {+ s.pending_clipboard.push(PendingClipboard {+ operation,+ timestamp,+ relative_ms: t,+ app_name: app_name.clone(),+ window_title: window_title.clone(),+ });+ return;}}@@ -1420,6 +1393,7 @@ mod tests {activity_feed: None,click_queue: Arc::new(parking_lot::Mutex::new(Vec::new())),focused_element: Arc::new(parking_lot::Mutex::new(None)),+ pending_clipboard: Vec::new(),}}