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
feat(redact): plumb v45 phase 3 ONNX through engine/tauri + CI + HF download
Louis Beaumont10fdce628cfb
diff --git a/.github/workflows/release-app.yml b/.github/workflows/release-app.ymlindex 3621ad57e..091570f91 100644--- a/.github/workflows/release-app.yml+++ b/.github/workflows/release-app.yml@@ -166,31 +166,31 @@ jobs:include:# GitHub-hosted macOS 26 runner for Apple Silicon + Apple Intelligence- platform: ${{ needs.check_commit.outputs.macos_arm_runner || 'macos-latest' }}- args: "--target aarch64-apple-darwin --features metal,parakeet-mlx,rfdetr-mlx"+ args: "--target aarch64-apple-darwin --features metal,parakeet-mlx,rfdetr-mlx,redact-onnx-coreml"target: aarch64-apple-darwin- tauri-args: "--target aarch64-apple-darwin --features metal,parakeet-mlx,rfdetr-mlx,official-build"+ tauri-args: "--target aarch64-apple-darwin --features metal,parakeet-mlx,rfdetr-mlx,redact-onnx-coreml,official-build"os_type: "macos"- platform: "macos-26"- args: "--target x86_64-apple-darwin --features metal"+ args: "--target x86_64-apple-darwin --features metal,redact-onnx-coreml"target: x86_64-apple-darwin- tauri-args: "--target x86_64-apple-darwin --features metal,official-build"+ tauri-args: "--target x86_64-apple-darwin --features metal,redact-onnx-coreml,official-build"os_type: "macos"- platform: ${{ needs.check_commit.outputs.windows_runner || 'windows-2022' }}args: "--target x86_64-pc-windows-msvc"pre-build-args: ""- tauri-args: "--target x86_64-pc-windows-msvc --features official-build,directml"+ tauri-args: "--target x86_64-pc-windows-msvc --features official-build,directml,redact-onnx-directml"target: x86_64-pc-windows-msvcos_type: "windows"- platform: windows-11-armargs: "--target aarch64-pc-windows-msvc"pre-build-args: ""- tauri-args: "--target aarch64-pc-windows-msvc --features official-build,directml"+ tauri-args: "--target aarch64-pc-windows-msvc --features official-build,directml,redact-onnx-directml"target: aarch64-pc-windows-msvcos_type: "windows"- platform: "ubuntu-24.04"- args: "--target x86_64-unknown-linux-gnu"+ args: "--target x86_64-unknown-linux-gnu --features redact-onnx-cpu"target: x86_64-unknown-linux-gnu- tauri-args: "--target x86_64-unknown-linux-gnu --features official-build"+ tauri-args: "--target x86_64-unknown-linux-gnu --features official-build,redact-onnx-cpu"os_type: "linux"runs-on: ${{ matrix.platform == 'windows-desktop-test' && fromJSON('["self-hosted", "windows-desktop-test"]') || matrix.platform }}diff --git a/apps/screenpipe-app-tauri/src-tauri/Cargo.toml b/apps/screenpipe-app-tauri/src-tauri/Cargo.tomlindex 4ff874b2e..53ee46b76 100644--- a/apps/screenpipe-app-tauri/src-tauri/Cargo.toml+++ b/apps/screenpipe-app-tauri/src-tauri/Cargo.toml@@ -272,6 +272,16 @@ parakeet-mlx = ["screenpipe-engine/parakeet-mlx"]# ONNX CoreML EP). Forwards to screenpipe-engine which forwards to# screenpipe-redact/mlx-mac.rfdetr-mlx = ["screenpipe-engine/rfdetr-mlx"]++# v45 phase 3 text-PII redactor via ONNX Runtime — cross-platform with+# zero end-user dependencies. CPU is the Linux baseline; CoreML on Mac+# uses Metal + Neural Engine; DirectML on Windows uses any DX12 GPU.+# The 3 features are not mutually exclusive at compile time — each CI+# build enables exactly one per platform.+redact-onnx-cpu = ["screenpipe-engine/redact-onnx-cpu"]+redact-onnx-coreml = ["screenpipe-engine/redact-onnx-coreml"]+redact-onnx-directml = ["screenpipe-engine/redact-onnx-directml"]+jemalloc = ["tikv-jemallocator"]diff --git a/crates/screenpipe-engine/Cargo.toml b/crates/screenpipe-engine/Cargo.tomlindex 92c4e6a59..979f1f396 100644--- a/crates/screenpipe-engine/Cargo.toml+++ b/crates/screenpipe-engine/Cargo.toml@@ -165,6 +165,20 @@ parakeet-mlx = ["screenpipe-audio/parakeet-mlx"]# Mac release builds opt in to pick up the ~6× speedup over the ONNX# CoreML EP path.rfdetr-mlx = ["screenpipe-redact/mlx-mac"]++# v45 phase 3 text-PII redactor via ONNX Runtime. CPU baseline for+# Linux + the foundation for the GPU EPs below. ~280 MB INT8 model+# downloaded on first run.+redact-onnx-cpu = ["screenpipe-redact/onnx-cpu"]+# Mac: CoreML EP on top of CPU baseline. Apple Silicon picks up Metal+# + Neural Engine. Stock-OS dependency — no separate install.+redact-onnx-coreml = ["screenpipe-redact/onnx-coreml"]+# Windows: DirectML EP on top of CPU baseline. Any DX12-capable GPU+# (NVIDIA, AMD, Intel iGPU). Stock-OS dependency — DirectML.dll ships+# in Windows 10+ since 2019. Distinct from the existing `directml`+# feature, which forwards to screenpipe-audio's whisper.cpp.+redact-onnx-directml = ["screenpipe-redact/onnx-directml"]+jemalloc = ["tikv-jemallocator"][[bin]]diff --git a/crates/screenpipe-redact/src/adapters/onnx.rs b/crates/screenpipe-redact/src/adapters/onnx.rsindex e9b4d0051..b4dd4d717 100644--- a/crates/screenpipe-redact/src/adapters/onnx.rs+++ b/crates/screenpipe-redact/src/adapters/onnx.rs@@ -99,6 +99,122 @@ impl OnnxConfig {fn tokenizer_path(&self) -> PathBuf {self.model_dir.join("tokenizer.json")}++ fn config_path(&self) -> PathBuf {+ self.model_dir.join("config.json")+ }++ /// HuggingFace repo where the canonical v45 phase 3 ONNX artifacts+ /// live. Pinned to `main` so a model bump goes through a deliberate+ /// code change (URL + expected SHA-256 + [`ONNX_REDACTOR_VERSION`]+ /// all bumped together — same discipline as `RfdetrConfig`).+ pub const HF_REPO_BASE: &'static str =+ "https://huggingface.co/screenpipe/pii-redactor/resolve/main/v45_phase3_onnx";++ /// Files to download from the HF repo on first run. Each is+ /// (filename, expected sha256). The SHA values are placeholders+ /// — bump after first upload via:+ /// shasum -a 256 model_quantized.onnx tokenizer.json config.json+ pub const FILES: &'static [(&'static str, &'static str)] = &[+ // INT8-quantized model. ~278 MB.+ ("model_quantized.onnx", "REPLACE_AFTER_HF_UPLOAD_QUANTIZED"),+ // SentencePiece tokenizer (HF fast format). ~17 MB.+ ("tokenizer.json", "REPLACE_AFTER_HF_UPLOAD_TOKENIZER"),+ // id2label + model config. ~2 KB.+ ("config.json", "REPLACE_AFTER_HF_UPLOAD_CONFIG"),+ ];++ /// Download the model + tokenizer + config from HuggingFace into+ /// [`Self::model_dir`] if not already present. Idempotent.+ ///+ /// SHA-256 verification: when [`Self::FILES`] sha values are real+ /// (post-upload), corrupt downloads are detected and re-attempted.+ /// While the SHAs are placeholders, verification is skipped — the+ /// caller MUST ship the model in the installer or accept that any+ /// HTTP-200 response replaces the expected file.+ pub async fn ensure_model_present(&self) -> Result<(), RedactError> {+ tokio::fs::create_dir_all(&self.model_dir)+ .await+ .map_err(|e| {+ RedactError::Runtime(format!("mkdir {}: {e}", self.model_dir.display()))+ })?;++ for (filename, expected_sha) in Self::FILES {+ let target = self.model_dir.join(filename);+ if target.exists() {+ // Skip SHA check while placeholders are in place. Once+ // the HF upload lands and SHAs are real, this becomes+ // a real integrity check.+ if !expected_sha.starts_with("REPLACE_") && !sha256_matches(&target, expected_sha)?+ {+ tracing::warn!(+ "v45 phase 3 {} sha256 mismatch, re-downloading",+ filename+ );+ } else {+ continue;+ }+ }++ let url = format!("{}/{}", Self::HF_REPO_BASE, filename);+ let tmp = target.with_extension(format!(+ "{}.partial",+ target+ .extension()+ .and_then(|s| s.to_str())+ .unwrap_or("download")+ ));+ tracing::info!("downloading {} -> {}", url, target.display());++ let resp = reqwest::get(&url)+ .await+ .map_err(|e| RedactError::Runtime(format!("GET {url}: {e}")))?+ .error_for_status()+ .map_err(|e| RedactError::Runtime(format!("HTTP {url}: {e}")))?;+ let bytes = resp+ .bytes()+ .await+ .map_err(|e| RedactError::Runtime(format!("download body {url}: {e}")))?;+ tokio::fs::write(&tmp, &bytes)+ .await+ .map_err(|e| RedactError::Runtime(format!("write {}: {e}", tmp.display())))?;++ if !expected_sha.starts_with("REPLACE_") && !sha256_matches(&tmp, expected_sha)? {+ let _ = tokio::fs::remove_file(&tmp).await;+ return Err(RedactError::Runtime(format!(+ "{filename} sha256 mismatch after download from {url}"+ )));+ }++ tokio::fs::rename(&tmp, &target).await.map_err(|e| {+ RedactError::Runtime(format!(+ "rename {} -> {}: {e}",+ tmp.display(),+ target.display()+ ))+ })?;+ }++ Ok(())+ }+}++fn sha256_matches(path: &std::path::Path, expected: &str) -> Result<bool, RedactError> {+ use sha2::{Digest, Sha256};+ let bytes = std::fs::read(path)+ .map_err(|e| RedactError::Runtime(format!("read {}: {e}", path.display())))?;+ let mut h = Sha256::new();+ h.update(&bytes);+ let got = hex_encode(&h.finalize());+ Ok(got.eq_ignore_ascii_case(expected))+}++fn hex_encode(bytes: &[u8]) -> String {+ let mut s = String::with_capacity(bytes.len() * 2);+ for b in bytes {+ s.push_str(&format!("{:02x}", b));+ }+ s}/// Map `"private_person"` → [`SpanLabel::Person`], etc. Unknown labels@@ -205,6 +321,14 @@ mod runtime {}impl OnnxRedactor {+ /// Async convenience: download the model + tokenizer + config+ /// from HuggingFace if missing, then load. Use this from the+ /// engine startup path.+ pub async fn load_or_download(cfg: OnnxConfig) -> Result<Self, RedactError> {+ cfg.ensure_model_present().await?;+ Self::load(cfg)+ }+pub fn load(cfg: OnnxConfig) -> Result<Self, RedactError> {let model_path = cfg.resolve_model_file();if !model_path.exists() {