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
Bump app to v2.4.180 — feat(redact): auto-download local OPF v3 from HF on first launch — release-app
Louis Beaumontc55b7336d90b
diff --git a/apps/screenpipe-app-tauri/src-tauri/Cargo.lock b/apps/screenpipe-app-tauri/src-tauri/Cargo.lockindex 1ea06c9a7..fca895ab0 100644--- a/apps/screenpipe-app-tauri/src-tauri/Cargo.lock+++ b/apps/screenpipe-app-tauri/src-tauri/Cargo.lock@@ -10557,7 +10557,7 @@ dependencies = [[[package]]name = "screenpipe-app"-version = "2.4.178"+version = "2.4.180"dependencies = ["aes","anyhow",@@ -10676,7 +10676,7 @@ dependencies = [[[package]]name = "screenpipe-audio"-version = "0.3.325"+version = "0.3.326"dependencies = ["anyhow","audiopipe",@@ -10732,7 +10732,7 @@ dependencies = [[[package]]name = "screenpipe-config"-version = "0.3.325"+version = "0.3.326"dependencies = ["dirs 6.0.0","serde",@@ -10744,7 +10744,7 @@ dependencies = [[[package]]name = "screenpipe-connect"-version = "0.3.325"+version = "0.3.326"dependencies = ["anyhow","async-trait",@@ -10777,7 +10777,7 @@ dependencies = [[[package]]name = "screenpipe-core"-version = "0.3.325"+version = "0.3.326"dependencies = ["accessibility","accessibility-sys",@@ -10825,7 +10825,7 @@ dependencies = [[[package]]name = "screenpipe-db"-version = "0.3.325"+version = "0.3.326"dependencies = ["anyhow","chrono",@@ -10850,7 +10850,7 @@ dependencies = [[[package]]name = "screenpipe-engine"-version = "0.3.325"+version = "0.3.326"dependencies = ["anyhow","arc-swap",@@ -10918,7 +10918,7 @@ dependencies = [[[package]]name = "screenpipe-events"-version = "0.3.325"+version = "0.3.326"dependencies = ["anyhow","chrono",@@ -10934,7 +10934,7 @@ dependencies = [[[package]]name = "screenpipe-redact"-version = "0.3.325"+version = "0.3.326"dependencies = ["anyhow","async-trait",@@ -10960,7 +10960,7 @@ dependencies = [[[package]]name = "screenpipe-screen"-version = "0.3.325"+version = "0.3.326"dependencies = ["accessibility-sys","anyhow",@@ -11013,7 +11013,7 @@ dependencies = [[[package]]name = "screenpipe-vault"-version = "0.3.325"+version = "0.3.326"dependencies = ["argon2","chacha20poly1305",diff --git a/apps/screenpipe-app-tauri/src-tauri/Cargo.toml b/apps/screenpipe-app-tauri/src-tauri/Cargo.tomlindex f5dddfabb..495f1060b 100644--- a/apps/screenpipe-app-tauri/src-tauri/Cargo.toml+++ b/apps/screenpipe-app-tauri/src-tauri/Cargo.toml@@ -1,6 +1,6 @@[package]name = "screenpipe-app"-version = "2.4.179"+version = "2.4.180"description = "24/7 memory for your desktop. 100% local."authors = ["you"]license = ""diff --git a/apps/screenpipe-app-tauri/src-tauri/src/server_core.rs b/apps/screenpipe-app-tauri/src-tauri/src/server_core.rsindex 09e64531a..d7d005908 100644--- a/apps/screenpipe-app-tauri/src-tauri/src/server_core.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/server_core.rs@@ -485,16 +485,18 @@ impl ServerCore {let use_tinfoil = matches!(backend, "tinfoil" | "cloud" | "enclave");if config.async_pii_redaction {- use screenpipe_redact::adapters::opf::OpfAdapter;+ use screenpipe_redact::adapters::opf::{OpfAdapter, OpfConfig};use screenpipe_redact::adapters::tinfoil::TinfoilRedactor;use screenpipe_redact::pipeline::{Pipeline, PipelineConfig};use screenpipe_redact::worker::{Worker, WorkerConfig, ALL_TARGET_TABLES};- use screenpipe_redact::{RedactError, Redactor};+ use screenpipe_redact::Redactor;// Backend selection for the text "AI" step:- // - "local" → on-device candle OPF v3 (opf-rs). Falls- // back to regex-only if the 2.8 GB- // checkpoint isn't on disk yet.+ // - "local" → on-device candle OPF v3 (opf-rs). First+ // run downloads ~2.8 GB from+ // huggingface.co/screenpipe/pii-text-redactor+ // in the background; until the download+ // finishes the worker runs regex-only.// - "tinfoil" → Tinfoil confidential-compute enclave.//// The worker is destructive-only: it overwrites the source@@ -503,43 +505,54 @@ impl ServerCore {// `*_redacted_at`. That's what the user-facing "AI PII// removal" toggle means. The 20260507 migration drops the// dead duplicate columns the old non-destructive mode used.- let pipeline = if use_tinfoil {+ if use_tinfoil {info!("starting async text-PII reconciliation worker (backend=tinfoil)");let ai: Arc<dyn Redactor> = Arc::new(TinfoilRedactor::from_env());- Pipeline::regex_then_ai(ai, PipelineConfig::default())+ let pipeline = Pipeline::regex_then_ai(ai, PipelineConfig::default());+ let pipeline_arc = Arc::new(pipeline) as Arc<dyn Redactor>;+ let cfg = WorkerConfig {+ tables: ALL_TARGET_TABLES.to_vec(),+ ..Default::default()+ };+ let _ = Worker::new(db.pool.clone(), pipeline_arc, cfg).spawn();} else {- match OpfAdapter::load_default() {- Ok(adapter) => {- info!(- "starting async text-PII reconciliation worker (backend=local, opf-rs)"- );- let ai: Arc<dyn Redactor> = Arc::new(adapter);- Pipeline::regex_then_ai(ai, PipelineConfig::default())- }- Err(RedactError::Unavailable(msg)) => {- warn!(- "OPF checkpoint not staged ({msg}); running text-PII worker in \- regex-only mode. Drop the v3 checkpoint at \- ~/.screenpipe/models/opf-v3/ to enable AI redaction, or switch \- backend to 'tinfoil' in Settings → Privacy → AI PII removal."- );- Pipeline::regex_only()- }- Err(e) => {- warn!(- "failed to load local OPF redactor ({e}); falling back to regex-only \- text-PII worker"- );- Pipeline::regex_only()- }- }- };- let pipeline_arc = Arc::new(pipeline) as Arc<dyn Redactor>;- let cfg = WorkerConfig {- tables: ALL_TARGET_TABLES.to_vec(),- ..Default::default()- };- let _ = Worker::new(db.pool.clone(), pipeline_arc, cfg).spawn();+ // Local mode: spawn the download+load off the boot path+ // so a slow first-run HF pull doesn't block the app+ // launch. The worker is created inside the spawned+ // task once the model is ready.+ let pool = db.pool.clone();+ tokio::spawn(async move {+ info!(+ "fetching local OPF v3 checkpoint (~2.8 GB on first run, cached at \+ ~/.screenpipe/models/opf-v3/)"+ );+ let pipeline = match OpfAdapter::load_or_download(OpfConfig::default()).await {+ Ok(adapter) => {+ info!(+ "starting async text-PII reconciliation worker (backend=local, \+ opf-rs)"+ );+ let ai: Arc<dyn Redactor> = Arc::new(adapter);+ Pipeline::regex_then_ai(ai, PipelineConfig::default())+ }+ Err(e) => {+ warn!(+ "couldn't load local OPF redactor ({e}); running text-PII \+ worker in regex-only mode. Switch backend to 'tinfoil' in \+ Settings → Privacy → AI PII removal to use the cloud enclave \+ instead."+ );+ Pipeline::regex_only()+ }+ };+ let pipeline_arc = Arc::new(pipeline) as Arc<dyn Redactor>;+ let cfg = WorkerConfig {+ tables: ALL_TARGET_TABLES.to_vec(),+ ..Default::default()+ };+ let _ = Worker::new(pool, pipeline_arc, cfg).spawn();+ });+ }}if config.async_image_pii_redaction {diff --git a/crates/screenpipe-engine/src/bin/screenpipe-engine.rs b/crates/screenpipe-engine/src/bin/screenpipe-engine.rsindex b3f4c4607..e732e45a5 100644--- a/crates/screenpipe-engine/src/bin/screenpipe-engine.rs+++ b/crates/screenpipe-engine/src/bin/screenpipe-engine.rs@@ -1496,10 +1496,13 @@ async fn main() -> anyhow::Result<()> {// The capture path is unaffected either way.if record_args.async_pii_redaction {use screenpipe_redact::{- adapters::{opf::OpfAdapter, tinfoil::TinfoilRedactor},+ adapters::{+ opf::{OpfAdapter, OpfConfig},+ tinfoil::TinfoilRedactor,+ },pipeline::{Pipeline, PipelineConfig},worker::{Worker, WorkerConfig, ALL_TARGET_TABLES},- RedactError, Redactor,+ Redactor,};use std::sync::Arc;@@ -1509,55 +1512,56 @@ async fn main() -> anyhow::Result<()> {// structural PII deterministically and on-device. AI step// resolves to:// 1. local opf-rs (candle, ~74 ms p50 on Mac CPU, 41 ms on- // Metal) when the v3 checkpoint is staged at- // ~/.screenpipe/models/opf-v3/+ // Metal). First run downloads ~2.8 GB from+ // huggingface.co/screenpipe/pii-text-redactor and verifies+ // SHA-256 before landing at ~/.screenpipe/models/opf-v3/.+ // Spawned off the boot path so a slow first-run pull+ // doesn't block the engine.// 2. Tinfoil confidential-compute enclave when TINFOIL_*- // env vars are set+ // env vars are set and local opf-rs is unavailable.// 3. regex-only otherwise (still destructive — overwrites- // regex-redacted text into the source columns)- let pipeline = match OpfAdapter::load_default() {- Ok(adapter) => {- info!("text-PII AI step: local opf-rs (candle)");- let ai: Arc<dyn Redactor> = Arc::new(adapter);- Pipeline::regex_then_ai(ai, PipelineConfig::default())- }- Err(RedactError::Unavailable(msg)) => {- if std::env::var("TINFOIL_API_KEY").is_ok()- || std::env::var("TINFOIL_BASE_URL").is_ok()- {- info!("text-PII AI step: tinfoil enclave (local opf-rs unavailable: {msg})");- let ai: Arc<dyn Redactor> = Arc::new(TinfoilRedactor::from_env());+ // regex-redacted text into the source columns).+ let pool = db.pool.clone();+ tokio::spawn(async move {+ info!(+ "fetching local OPF v3 checkpoint (~2.8 GB on first run, cached at \+ ~/.screenpipe/models/opf-v3/)"+ );+ let pipeline = match OpfAdapter::load_or_download(OpfConfig::default()).await {+ Ok(adapter) => {+ info!("text-PII AI step: local opf-rs (candle)");+ let ai: Arc<dyn Redactor> = Arc::new(adapter);Pipeline::regex_then_ai(ai, PipelineConfig::default())- } else {- tracing::warn!(- "text-PII AI step disabled — local opf-rs unavailable ({msg}) and no \- TINFOIL_* env vars set. Worker will run regex-only. Stage the OPF v3 \- checkpoint at ~/.screenpipe/models/opf-v3/ to enable on-device AI \- redaction."- );- Pipeline::regex_only()}- }- Err(e) => {- tracing::warn!(- "text-PII AI step failed to load local opf-rs ({e}); falling back to \- regex-only worker"- );- Pipeline::regex_only()- }- };- let pipeline_arc = Arc::new(pipeline) as Arc<dyn Redactor>;+ Err(e) => {+ if std::env::var("TINFOIL_API_KEY").is_ok()+ || std::env::var("TINFOIL_BASE_URL").is_ok()+ {+ info!("text-PII AI step: tinfoil enclave (local opf-rs unavailable: {e})");+ let ai: Arc<dyn Redactor> = Arc::new(TinfoilRedactor::from_env());+ Pipeline::regex_then_ai(ai, PipelineConfig::default())+ } else {+ tracing::warn!(+ "text-PII AI step disabled — local opf-rs unavailable ({e}) and no \+ TINFOIL_* env vars set. Worker will run regex-only."+ );+ Pipeline::regex_only()+ }+ }+ };+ let pipeline_arc = Arc::new(pipeline) as Arc<dyn Redactor>;- let worker_cfg = WorkerConfig {- tables: ALL_TARGET_TABLES.to_vec(),- ..Default::default()- };- let _worker_handle = Worker::new(db.pool.clone(), pipeline_arc, worker_cfg).spawn();- // The worker runs for the lifetime of the engine. We don't- // join its handle — when the process exits the runtime- // tears down the task. If we ever want graceful shutdown- // (drain in-flight HTTP calls), wire `_worker_handle` into- // the shutdown_tx flow.+ let worker_cfg = WorkerConfig {+ tables: ALL_TARGET_TABLES.to_vec(),+ ..Default::default()+ };+ let _worker_handle = Worker::new(pool, pipeline_arc, worker_cfg).spawn();+ // The worker runs for the lifetime of the engine. We don't+ // join its handle — when the process exits the runtime+ // tears down the task. If we ever want graceful shutdown+ // (drain in-flight HTTP calls), wire `_worker_handle` into+ // the shutdown_tx flow.+ });}// Image-PII reconciliation worker (issue #3185 follow-up).diff --git a/crates/screenpipe-redact/src/adapters/opf.rs b/crates/screenpipe-redact/src/adapters/opf.rsindex cf015fc33..ed15481d9 100644--- a/crates/screenpipe-redact/src/adapters/opf.rs+++ b/crates/screenpipe-redact/src/adapters/opf.rs@@ -35,7 +35,7 @@#![cfg(feature = "opf-text")]-use std::path::PathBuf;+use std::path::{Path, PathBuf};use async_trait::async_trait;@@ -50,9 +50,11 @@ const OPF_TEXT_VERSION: u32 = 3;/// canonical screenpipe install layout.#[derive(Debug, Clone)]pub struct OpfConfig {- /// Directory containing `config.json` + `model.safetensors`. Default:- /// `~/.screenpipe/models/opf-v3` (we'll add an HF-hub auto-download- /// path later — for now callers stage the checkpoint themselves).+ /// Directory containing `config.json` + `model.safetensors`.+ /// Default: `~/.screenpipe/models/opf-v3`. First-run is created+ /// lazily by [`OpfAdapter::load_or_download`] which fetches the+ /// 2.8 GB checkpoint from HuggingFace and verifies SHA-256 before+ /// landing.pub model_dir: PathBuf,/// Hard cap on tokens per call. Anything longer is truncated. The/// model was fine-tuned at n_ctx=256 and degrades past that.@@ -76,6 +78,30 @@ fn default_model_dir() -> PathBuf {.join("opf-v3")}+/// HuggingFace base URL for the canonical v3 fine-tune. Pinned to+/// `main` so a model bump goes through a deliberate code change+/// (URLs + expected SHA-256s + [`OPF_TEXT_VERSION`] all bumped+/// together).+const HF_BASE_URL: &str =+ "https://huggingface.co/screenpipe/pii-text-redactor/resolve/main";++/// File-by-file SHA-256 manifest for v3. Verified after every download+/// before landing the file at its final path. If a future training run+/// produces a new best, bump [`OPF_TEXT_VERSION`], re-publish to HF,+/// update these constants. Note: the worker is destructive-only and+/// does NOT re-redact already-processed rows, so a model-version bump+/// only takes effect for newly-captured text going forward.+const V3_FILES: &[(&str, &str)] = &[+ (+ "config.json",+ "48cd9b76d5684c445cccd86d2d3cd9887eb0136505f9e1b35c2fd2c5a3707885",+ ),+ (+ "model.safetensors",+ "4be4d5657db2fa72d7b6190949da334053c09ba0a7c2dffe69d65c3585f38bc8",+ ),+];+pub struct OpfAdapter {inner: opf::Redactor,}@@ -104,6 +130,118 @@ impl OpfAdapter {pub fn load_default() -> Result<Self, RedactError> {Self::load(OpfConfig::default())}++ /// Async constructor: download the checkpoint from HuggingFace+ /// (~2.8 GB, first-run only) and load it. Idempotent — returns+ /// instantly when files are already present with matching+ /// SHA-256s. Recommended call site for production.+ pub async fn load_or_download(cfg: OpfConfig) -> Result<Self, RedactError> {+ ensure_checkpoint_present(&cfg.model_dir).await?;+ Self::load(cfg)+ }++ /// Download to the default location and load. One-shot+ /// convenience for the typical desktop install path.+ pub async fn load_or_download_default() -> Result<Self, RedactError> {+ Self::load_or_download(OpfConfig::default()).await+ }+}++/// Make sure `config.json` + `model.safetensors` are present at+/// `model_dir` with the SHA-256s pinned in [`V3_FILES`]. Idempotent.+/// Atomic semantics: each download lands at `<file>.partial`, gets+/// verified, then renames over `<file>`. A killed process leaves at+/// most a `.partial` that the next call cleans up.+async fn ensure_checkpoint_present(model_dir: &Path) -> Result<(), RedactError> {+ if model_dir.exists() && V3_FILES.iter().all(|(name, sha)| {+ let p = model_dir.join(name);+ p.exists() && sha256_matches_file(&p, sha).unwrap_or(false)+ }) {+ return Ok(());+ }++ tokio::fs::create_dir_all(model_dir).await.map_err(|e| {+ RedactError::Runtime(format!("mkdir {}: {e}", model_dir.display()))+ })?;++ for (name, expected_sha) in V3_FILES {+ let dst = model_dir.join(name);+ if dst.exists() && sha256_matches_file(&dst, expected_sha).unwrap_or(false) {+ continue;+ }+ download_one(name, expected_sha, &dst).await?;+ }+ Ok(())+}++async fn download_one(+ name: &str,+ expected_sha: &str,+ dst: &Path,+) -> Result<(), RedactError> {+ let url = format!("{HF_BASE_URL}/{name}");+ let tmp = dst.with_extension("partial");+ let _ = tokio::fs::remove_file(&tmp).await;++ tracing::info!(+ url = %url,+ target = %dst.display(),+ "downloading {name} (first-run only)"+ );+ let resp = reqwest::Client::new()+ .get(&url)+ .send()+ .await+ .map_err(|e| RedactError::Runtime(format!("opf {name} GET: {e}")))?;+ if !resp.status().is_success() {+ return Err(RedactError::Runtime(format!(+ "opf {name} returned {}",+ resp.status()+ )));+ }+ let bytes = resp+ .bytes()+ .await+ .map_err(|e| RedactError::Runtime(format!("opf {name} body: {e}")))?;++ let actual = hex_sha256(&bytes);+ if actual != expected_sha {+ return Err(RedactError::Runtime(format!(+ "opf {name} checksum mismatch: got {actual}, want {expected_sha}"+ )));+ }++ tokio::fs::write(&tmp, &bytes)+ .await+ .map_err(|e| RedactError::Runtime(format!("opf {name} write tmp: {e}")))?;+ tokio::fs::rename(&tmp, dst)+ .await+ .map_err(|e| RedactError::Runtime(format!("opf {name} rename: {e}")))?;+ tracing::info!(+ target = %dst.display(),+ bytes = bytes.len(),+ "{name} ready"+ );+ Ok(())+}++fn hex_sha256(bytes: &[u8]) -> String {+ use sha2::{Digest, Sha256};+ let mut hasher = Sha256::new();+ hasher.update(bytes);+ let digest = hasher.finalize();+ let mut s = String::with_capacity(64);+ for b in digest {+ use std::fmt::Write;+ let _ = write!(&mut s, "{b:02x}");+ }+ s+}++fn sha256_matches_file(path: &Path, expected: &str) -> Result<bool, RedactError> {+ let bytes = std::fs::read(path)+ .map_err(|e| RedactError::Runtime(format!("read {}: {e}", path.display())))?;+ Ok(hex_sha256(&bytes) == expected)}fn map_label(l: opf::SpanLabel) -> SpanLabel {