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

feat: pii removal in cli

Louis Beaumont93c2a944295e
diff --git a/screenpipe-core/src/lib.rs b/screenpipe-core/src/lib.rs
index abddd787c..22163824c 100644
--- a/screenpipe-core/src/lib.rs
+++ b/screenpipe-core/src/lib.rs
@@ -7,4 +7,6 @@ pub mod pipes;
#[cfg(feature = "pipes")]
pub use pipes::*;
#[cfg(feature = "security")]
-mod pii_removal;
+pub mod pii_removal;
+#[cfg(feature = "security")]
+pub use pii_removal::*;
diff --git a/screenpipe-server/Cargo.toml b/screenpipe-server/Cargo.toml
index 045ec56ce..8d300daf4 100644
--- a/screenpipe-server/Cargo.toml
+++ b/screenpipe-server/Cargo.toml
@@ -15,7 +15,7 @@ serde_json = "1.0"
screenpipe-vision = { path = "../screenpipe-vision" }
screenpipe-audio = { path = "../screenpipe-audio" }
-screenpipe-core = { path = "../screenpipe-core" }
+screenpipe-core = { path = "../screenpipe-core", features = ["security"] }
# Image processing
image = { workspace = true }
diff --git a/screenpipe-server/src/bin/screenpipe-server.rs b/screenpipe-server/src/bin/screenpipe-server.rs
index 27d48cbd0..e43778f73 100644
--- a/screenpipe-server/src/bin/screenpipe-server.rs
+++ b/screenpipe-server/src/bin/screenpipe-server.rs
@@ -296,6 +296,7 @@ async fn main() -> anyhow::Result<()> {
ocr_engine,
friend_wearable_uid_clone, // Use the cloned version
monitor_id,
+ cli.use_pii_removal,
)
.await;
diff --git a/screenpipe-server/src/cli.rs b/screenpipe-server/src/cli.rs
index 3ab6abb21..2a11fbf96 100644
--- a/screenpipe-server/src/cli.rs
+++ b/screenpipe-server/src/cli.rs
@@ -142,4 +142,8 @@ pub struct Cli {
/// File path for the pipe
#[arg(long)]
pub pipe: Vec<String>,
+
+ /// Enable PII removal from OCR text property that is saved to db and returned in search results
+ #[arg(long, default_value_t = false)]
+ pub use_pii_removal: bool,
}
\ No newline at end of file
diff --git a/screenpipe-server/src/core.rs b/screenpipe-server/src/core.rs
index 3a7b71cef..a9b5a9604 100644
--- a/screenpipe-server/src/core.rs
+++ b/screenpipe-server/src/core.rs
@@ -7,6 +7,7 @@ use screenpipe_audio::{
create_whisper_channel, record_and_transcribe, AudioDevice, AudioInput,
AudioTranscriptionEngine, DeviceControl, TranscriptionResult,
};
+use screenpipe_core::pii_removal::remove_pii;
use screenpipe_integrations::friend_wearable::initialize_friend_wearable_loop;
use screenpipe_vision::OcrEngine;
use std::collections::HashMap;
@@ -16,7 +17,6 @@ use std::sync::Arc;
use std::time::Duration;
use tokio::sync::mpsc::{UnboundedReceiver, UnboundedSender};
use tokio::task::JoinHandle;
-
pub enum RecorderControl {
Pause,
Resume,
@@ -56,6 +56,7 @@ pub async fn start_continuous_recording(
ocr_engine: Arc<OcrEngine>,
friend_wearable_uid: Option<String>,
monitor_id: u32,
+ use_pii_removal: bool,
) -> Result<()> {
let (whisper_sender, whisper_receiver) =
create_whisper_channel(audio_transcription_engine.clone()).await?;
@@ -88,6 +89,7 @@ pub async fn start_continuous_recording(
ocr_engine,
friend_wearable_uid_video,
monitor_id,
+ use_pii_removal,
)
.await
});
@@ -129,6 +131,7 @@ async fn record_video(
ocr_engine: Arc<OcrEngine>,
_friend_wearable_uid: Option<String>,
monitor_id: u32,
+ use_pii_removal: bool,
) -> Result<()> {
debug!("record_video: Starting");
let db_chunk_callback = Arc::clone(&db);
@@ -161,10 +164,15 @@ async fn record_video(
let text_json =
serde_json::to_string(&window_result.text_json).unwrap_or_default();
+ let text = if use_pii_removal {
+ &remove_pii(&window_result.text)
+ } else {
+ &window_result.text
+ };
if let Err(e) = db
.insert_ocr_text(
frame_id,
- &window_result.text,
+ text,
&text_json,
&window_result.app_name,
&window_result.window_name,
diff --git a/screenpipe-vision/src/core.rs b/screenpipe-vision/src/core.rs
index 23d62f457..ec71d677b 100644
--- a/screenpipe-vision/src/core.rs
+++ b/screenpipe-vision/src/core.rs
@@ -2,7 +2,6 @@ use image::DynamicImage;
use log::{debug, error};
use screenpipe_integrations::unstructured_ocr::perform_ocr_cloud;
use serde_json;
-use std::sync::atomic::{AtomicBool, Ordering};
use std::{
collections::HashMap,
sync::Arc,
@@ -57,7 +56,6 @@ pub async fn continuous_capture(
"continuous_capture: Starting using monitor: {:?}",
monitor_id
);
- let ocr_task_running = Arc::new(AtomicBool::new(false));
let mut frame_counter: u64 = 0;
let mut previous_image: Option<Arc<DynamicImage>> = None;
let mut max_average: Option<MaxAverageFrame> = None;
@@ -128,41 +126,33 @@ pub async fn continuous_capture(
previous_image = Some(Arc::new(image.clone()));
- if !ocr_task_running.load(Ordering::SeqCst) {
- if let Some(max_avg_frame) = max_average.take() {
- let ocr_task_data = OcrTaskData {
- image: max_avg_frame.image.clone(),
- window_images: max_avg_frame.window_images.clone(),
- frame_number: max_avg_frame.frame_number,
- timestamp: max_avg_frame.timestamp,
- result_tx: max_avg_frame.result_tx.clone(),
- };
-
- let ocr_task_running_clone = ocr_task_running.clone();
-
- ocr_task_running.store(true, Ordering::SeqCst);
- let ocr_engine_clone = ocr_engine.clone();
-
- tokio::spawn(async move {
- if let Err(e) = process_ocr_task(
- ocr_task_data.image,
- ocr_task_data.window_images,
- ocr_task_data.frame_number,
- ocr_task_data.timestamp,
- ocr_task_data.result_tx,
- save_text_files_flag,
- ocr_engine_clone,
- )
- .await
- {
- error!("Error processing OCR task: {}", e);
- }
- ocr_task_running_clone.store(false, Ordering::SeqCst);
- });
-
- frame_counter = 0;
- max_avg_value = 0.0;
+ if let Some(max_avg_frame) = max_average.take() {
+ let ocr_task_data = OcrTaskData {
+ image: max_avg_frame.image.clone(),
+ window_images: max_avg_frame.window_images.clone(),
+ frame_number: max_avg_frame.frame_number,
+ timestamp: max_avg_frame.timestamp,
+ result_tx: max_avg_frame.result_tx.clone(),
+ };
+
+ let ocr_engine_clone = ocr_engine.clone();
+
+ if let Err(e) = process_ocr_task(
+ ocr_task_data.image,
+ ocr_task_data.window_images,
+ ocr_task_data.frame_number,
+ ocr_task_data.timestamp,
+ ocr_task_data.result_tx,
+ save_text_files_flag,
+ ocr_engine_clone,
+ )
+ .await
+ {
+ error!("Error processing OCR task: {}", e);
}
+
+ frame_counter = 0;
+ max_avg_value = 0.0;
}
} else {
// Skip this iteration if capture failed