Skip to content

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

fix(capture): checkpoint workflow input triggers

Louis Beaumont4d43994e3021
diff --git a/crates/screenpipe-a11y/src/config.rs b/crates/screenpipe-a11y/src/config.rs
index 6bef4b545..558adfb98 100644
--- a/crates/screenpipe-a11y/src/config.rs
+++ b/crates/screenpipe-a11y/src/config.rs
@@ -31,7 +31,7 @@ pub struct UiCaptureConfig {
/// Capture app switches
pub capture_app_switch: bool,
- /// Capture window focus changes (high volume - disabled by default)
+ /// Capture window focus changes
pub capture_window_focus: bool,
/// Capture scroll events (very high volume - disabled by default)
@@ -187,8 +187,8 @@ impl Default for UiCaptureConfig {
capture_text: true,
capture_keystrokes: false, // Privacy risk
capture_app_switch: true,
- capture_window_focus: false, // High volume
- capture_scroll: false, // Very high volume
+ capture_window_focus: true,
+ capture_scroll: false, // Very high volume
capture_clipboard: true,
capture_clipboard_content: true,
capture_context: true,
@@ -429,6 +429,7 @@ mod tests {
let config = UiCaptureConfig::new();
assert!(config.enabled);
assert!(config.capture_clicks);
+ assert!(config.capture_window_focus);
assert!(!config.capture_keystrokes); // Should be off by default
assert!(config.capture_clipboard_content); // On by default
}
diff --git a/crates/screenpipe-a11y/src/tree/windows.rs b/crates/screenpipe-a11y/src/tree/windows.rs
index 47acfb8e6..ccfd816b6 100644
--- a/crates/screenpipe-a11y/src/tree/windows.rs
+++ b/crates/screenpipe-a11y/src/tree/windows.rs
@@ -830,6 +830,7 @@ mod tests {
&None, // monitor_rect
&None, // window_rect
&[],
+ "",
&mut false,
);
@@ -900,6 +901,7 @@ mod tests {
&None, // monitor_rect
&None, // window_rect
&[],
+ "",
&mut false,
);
@@ -975,7 +977,8 @@ mod tests {
..Default::default()
};
- let ignored = vec!["bit".to_string()];
+ let ignored_raw = vec!["bit".to_string()];
+ let ignored = WindowPattern::parse_list(&ignored_raw);
let mut buf = String::new();
let mut nodes = Vec::new();
let mut url = None;
@@ -991,6 +994,7 @@ mod tests {
&None, // monitor_rect
&None, // window_rect
&ignored,
+ "",
&mut hit,
);
diff --git a/crates/screenpipe-engine/src/event_driven_capture.rs b/crates/screenpipe-engine/src/event_driven_capture.rs
index c8b46b97c..0a70d2300 100644
--- a/crates/screenpipe-engine/src/event_driven_capture.rs
+++ b/crates/screenpipe-engine/src/event_driven_capture.rs
@@ -239,14 +239,11 @@ pub struct EventDrivenCaptureConfig {
/// Whether to capture on clicks.
pub capture_on_click: bool,
/// Whether to capture on key events when the a11y layer has
- /// `capture_keystrokes=true`. Recording sessions force this on; the
- /// lower-level default stays conservative for library callers.
+ /// `capture_keystrokes=true`. Raw key/text DB persistence is
+ /// controlled separately by the recorder.
pub capture_on_keystroke: bool,
- /// Whether to capture on clipboard changes. **Off by default**:
- /// taking a full paired capture (screenshot + tree walk + OCR) on
- /// every Ctrl+C/X/V costs 250-800ms of blocking work and can cause
- /// visible input lag on USB HID devices. Clipboard row persistence
- /// is controlled separately by the UI recorder.
+ /// Whether to capture on clipboard changes. Clipboard row/content
+ /// persistence is controlled separately by the UI recorder.
pub capture_on_clipboard: bool,
/// Interval (ms) between visual-change checks (screenshot + frame diff).
/// Set to 0 to disable visual change detection.
@@ -262,8 +259,8 @@ impl Default for EventDrivenCaptureConfig {
idle_capture_interval_ms: 30_000, // 30 seconds
jpeg_quality: 80,
capture_on_click: true,
- capture_on_keystroke: false,
- capture_on_clipboard: false,
+ capture_on_keystroke: true,
+ capture_on_clipboard: true,
visual_check_interval_ms: 3_000, // check every 3 seconds
visual_change_threshold: 0.05, // ~5% difference triggers capture
}
@@ -1173,7 +1170,17 @@ pub async fn event_driven_capture_loop(
last_elements_cache.remove(&device_name);
}
- if state.can_capture() {
+ let can_capture = state.can_capture();
+ let debounce_exempt = is_workflow_checkpoint_trigger(&trigger);
+ if can_capture || debounce_exempt {
+ if !can_capture && debounce_exempt {
+ debug!(
+ "event capture bypassing debounce (trigger={}, monitor={})",
+ trigger.as_str(),
+ monitor_id
+ );
+ }
+
// Pre-capture DRM gate: check BEFORE any SCK call.
// Uses AX APIs only — prevents even a single leaked frame.
{
@@ -1630,15 +1637,30 @@ fn terminal_ocr_throttled(app_name: &str) -> bool {
/// hash dedup would otherwise drop. While HD is on we capture every change
/// at the HD interval and let the visual-change trigger + `min_capture_
/// interval_ms` debounce be the only rate limiters.
-/// - `Idle`/`Manual` triggers: fallback captures that must always write so the
-/// timeline is never completely empty.
+/// - semantic workflow-boundary triggers: focus changes, typing/scroll stops,
+/// clipboard actions, and shortcut keypresses must leave a durable checkpoint
+/// even when visible text is unchanged.
/// - the 30s time-floor has elapsed: forces a write even if the hash matches.
fn dedup_applies(trigger: &CaptureTrigger, hd_active: bool, since_last_db_write: Duration) -> bool {
!hd_active
- && !matches!(trigger, CaptureTrigger::Idle | CaptureTrigger::Manual)
+ && !is_workflow_checkpoint_trigger(trigger)
&& since_last_db_write < Duration::from_secs(30)
}
+fn is_workflow_checkpoint_trigger(trigger: &CaptureTrigger) -> bool {
+ matches!(
+ trigger,
+ CaptureTrigger::AppSwitch { .. }
+ | CaptureTrigger::WindowFocus { .. }
+ | CaptureTrigger::TypingPause
+ | CaptureTrigger::ScrollStop
+ | CaptureTrigger::KeyPress
+ | CaptureTrigger::Clipboard
+ | CaptureTrigger::Idle
+ | CaptureTrigger::Manual
+ )
+}
+
/// Perform a single event-driven capture.
///
/// When `previous_content_hash` is `Some` and matches the current accessibility
@@ -2110,12 +2132,51 @@ mod tests {
"app_switch"
);
assert_eq!(CaptureTrigger::Click { x: 10, y: 20 }.as_str(), "click");
+ assert_eq!(
+ CaptureTrigger::WindowFocus {
+ window_name: "Inbox".to_string(),
+ target: None,
+ }
+ .as_str(),
+ "window_focus"
+ );
assert_eq!(CaptureTrigger::TypingPause.as_str(), "typing_pause");
+ assert_eq!(CaptureTrigger::ScrollStop.as_str(), "scroll_stop");
+ assert_eq!(CaptureTrigger::KeyPress.as_str(), "key_press");
+ assert_eq!(CaptureTrigger::Clipboard.as_str(), "clipboard");
assert_eq!(CaptureTrigger::VisualChange.as_str(), "visual_change");
assert_eq!(CaptureTrigger::Idle.as_str(), "idle");
assert_eq!(CaptureTrigger::Manual.as_str(), "manual");
}
+ #[test]
+ fn workflow_checkpoint_trigger_classification() {
+ assert!(is_workflow_checkpoint_trigger(&CaptureTrigger::AppSwitch {
+ app_name: "Code".into(),
+ target: None,
+ }));
+ assert!(is_workflow_checkpoint_trigger(
+ &CaptureTrigger::WindowFocus {
+ window_name: "main.rs".into(),
+ target: None,
+ }
+ ));
+ assert!(is_workflow_checkpoint_trigger(&CaptureTrigger::TypingPause));
+ assert!(is_workflow_checkpoint_trigger(&CaptureTrigger::ScrollStop));
+ assert!(is_workflow_checkpoint_trigger(&CaptureTrigger::KeyPress));
+ assert!(is_workflow_checkpoint_trigger(&CaptureTrigger::Clipboard));
+ assert!(is_workflow_checkpoint_trigger(&CaptureTrigger::Idle));
+ assert!(is_workflow_checkpoint_trigger(&CaptureTrigger::Manual));
+
+ assert!(!is_workflow_checkpoint_trigger(&CaptureTrigger::Click {
+ x: 10,
+ y: 20,
+ }));
+ assert!(!is_workflow_checkpoint_trigger(
+ &CaptureTrigger::VisualChange
+ ));
+ }
+
#[test]
fn test_dedup_applies() {
let recent = Duration::from_secs(5);
@@ -2128,6 +2189,26 @@ mod tests {
false,
recent
));
+ assert!(!dedup_applies(
+ &CaptureTrigger::AppSwitch {
+ app_name: "Code".into(),
+ target: None,
+ },
+ false,
+ recent
+ ));
+ assert!(!dedup_applies(
+ &CaptureTrigger::WindowFocus {
+ window_name: "main.rs".into(),
+ target: None,
+ },
+ false,
+ recent
+ ));
+ assert!(!dedup_applies(&CaptureTrigger::TypingPause, false, recent));
+ assert!(!dedup_applies(&CaptureTrigger::ScrollStop, false, recent));
+ assert!(!dedup_applies(&CaptureTrigger::KeyPress, false, recent));
+ assert!(!dedup_applies(&CaptureTrigger::Clipboard, false, recent));
// HD active → dedup is bypassed even for an otherwise-eligible trigger.
// This is the fix: video/demo replay moves pixels but not AX text, so
@@ -2147,6 +2228,13 @@ mod tests {
assert!(!dedup_applies(&CaptureTrigger::VisualChange, false, stale));
}
+ #[test]
+ fn default_config_captures_key_and_clipboard_triggers() {
+ let config = EventDrivenCaptureConfig::default();
+ assert!(config.capture_on_keystroke);
+ assert!(config.capture_on_clipboard);
+ }
+
#[test]
fn test_debounce() {
let config = EventDrivenCaptureConfig {
@@ -2337,14 +2425,8 @@ mod tests {
assert_eq!(config.idle_capture_interval_ms, 30_000);
assert_eq!(config.jpeg_quality, 80);
assert!(config.capture_on_click);
- assert!(
- !config.capture_on_clipboard,
- "off by default — HID latency trade-off; opt in for frame_id linkage"
- );
- assert!(
- !config.capture_on_keystroke,
- "off by default — capture-per-keystroke would be a storm during typing"
- );
+ assert!(config.capture_on_clipboard);
+ assert!(config.capture_on_keystroke);
assert_eq!(config.visual_check_interval_ms, 3_000);
assert!((config.visual_change_threshold - 0.05).abs() < f64::EPSILON);
}
diff --git a/crates/screenpipe-engine/src/recording_config.rs b/crates/screenpipe-engine/src/recording_config.rs
index 5d1b6740d..3d92b2c92 100644
--- a/crates/screenpipe-engine/src/recording_config.rs
+++ b/crates/screenpipe-engine/src/recording_config.rs
@@ -179,7 +179,7 @@ pub struct RecordingConfig {
/// `disable_keyboard_capture`.
pub capture_on_keystroke: Option<bool>,
/// Override `EventDrivenCaptureConfig::capture_on_clipboard`.
- /// None = engine default (false). See `RecordingSettings.capture_on_clipboard`.
+ /// None = engine default (true). See `RecordingSettings.capture_on_clipboard`.
pub capture_on_clipboard: Option<bool>,
/// Override `UiRecorderConfig::capture_scroll`.
/// None = engine default (false). See `RecordingSettings.capture_scroll`.
diff --git a/crates/screenpipe-engine/src/ui_recorder.rs b/crates/screenpipe-engine/src/ui_recorder.rs
index 947b6d0af..b0ecfc289 100644
--- a/crates/screenpipe-engine/src/ui_recorder.rs
+++ b/crates/screenpipe-engine/src/ui_recorder.rs
@@ -144,11 +144,11 @@ impl Default for UiRecorderConfig {
capture_clipboard: true,
capture_clipboard_content: true,
capture_app_switch: true,
- capture_window_focus: false,
+ capture_window_focus: true,
capture_scroll: false,
capture_context: true,
- capture_on_keystroke: false,
- capture_on_clipboard: false,
+ capture_on_keystroke: true,
+ capture_on_clipboard: true,
excluded_apps: Vec::new(),
excluded_windows: Vec::new(),
ignored_windows: Vec::new(),
@@ -176,10 +176,15 @@ impl UiRecorderConfig {
config.capture_mouse_move = self.capture_mouse_move;
config.capture_text = self.capture_text;
config.capture_keystrokes = self.capture_keystrokes;
- config.capture_clipboard = self.capture_clipboard;
- config.capture_clipboard_content = self.capture_clipboard_content;
+ // Clipboard detection is needed for trigger-only captures even when
+ // clipboard event storage/content is disabled for privacy.
+ config.capture_clipboard = self.capture_clipboard || self.capture_on_clipboard;
+ config.capture_clipboard_content = self.capture_clipboard && self.capture_clipboard_content;
config.capture_app_switch = self.capture_app_switch;
- config.capture_window_focus = self.capture_window_focus;
+ // Window focus changes are workflow boundaries. Keep them enabled
+ // for both CLI and desktop-app runs even if an older caller carries
+ // a false value in UiRecorderConfig.
+ config.capture_window_focus = true;
config.capture_scroll = self.capture_scroll;
config.capture_context = self.capture_context;
config.prioritize_input_latency = self.prioritize_input_latency;
@@ -927,10 +932,9 @@ fn capture_trigger_kind(
// recent Scroll's correlation_id until the burst ends, then
// emits a single ScrollStop trigger.
screenpipe_db::UiEventType::Scroll => None,
- // Key events fire a KeyPress trigger only when the capture loop
- // is configured to honor them. With the gate off we don't mint a
- // corr_id, so the row stays NULL without leaving a doomed
- // pending_event in the frame linker.
+ // Key events fire a KeyPress trigger when the capture loop is
+ // configured to honor them. The caller may send this as trigger-only
+ // if privacy settings suppress storing the key row.
screenpipe_db::UiEventType::Key if gates.capture_on_keystroke => {
Some(CaptureTrigger::KeyPress)
}
@@ -1158,6 +1162,17 @@ mod capture_trigger_kind_tests {
));
}
+ #[test]
+ fn key_event_can_trigger_without_being_stored() {
+ let event = evt(UiEventType::Key);
+
+ assert!(!should_record_input_event(&event, false, true));
+ assert!(matches!(
+ capture_trigger_kind(&event, &[], gates(true, true)),
+ Some(CaptureTrigger::KeyPress)
+ ));
+ }
+
#[test]
fn clipboard_event_suppressed_when_clipboard_gate_off() {
let result = capture_trigger_kind(&evt(UiEventType::Clipboard), &[], gates(false, false));
@@ -1188,6 +1203,17 @@ mod capture_trigger_kind_tests {
assert!(matches!(result, Some(CaptureTrigger::Clipboard)));
}
+ #[test]
+ fn clipboard_event_can_trigger_without_being_stored() {
+ let event = evt(UiEventType::Clipboard);
+
+ assert!(!should_record_input_event(&event, true, false));
+ assert!(matches!(
+ capture_trigger_kind(&event, &[], gates(true, true)),
+ Some(CaptureTrigger::Clipboard)
+ ));
+ }
+
#[test]
fn text_event_unaffected_by_gates() {
// TypingPause / ScrollStop don't have a capture-loop gate, so
@@ -1295,6 +1321,28 @@ mod scroll_burst_tests {
mod tests {
use super::*;
+ #[test]
+ fn window_focus_capture_is_always_enabled() {
+ assert!(UiRecorderConfig::default().capture_window_focus);
+
+ let mut config = UiRecorderConfig::default();
+ config.capture_window_focus = false;
+ assert!(config.to_ui_config().capture_window_focus);
+ }
+
+ #[test]
+ fn clipboard_trigger_detection_does_not_require_clipboard_storage() {
+ let mut config = UiRecorderConfig::default();
+ config.capture_clipboard = false;
+ config.capture_clipboard_content = true;
+ config.capture_on_clipboard = true;
+
+ let ui_config = config.to_ui_config();
+
+ assert!(ui_config.capture_clipboard);
+ assert!(!ui_config.capture_clipboard_content);
+ }
+
#[test]
fn test_stop_flag_sets_on_stop() {
let handle = UiRecorderHandle {