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: add opt-in dollar amount text redaction (#7638)
Louis Beaumontd41b1d22e442
diff --git a/apps/screenpipe-app-tauri/components/settings/privacy-section.tsx b/apps/screenpipe-app-tauri/components/settings/privacy-section.tsxindex 2c044ba5a..4cbc408af 100644--- a/apps/screenpipe-app-tauri/components/settings/privacy-section.tsx+++ b/apps/screenpipe-app-tauri/components/settings/privacy-section.tsx@@ -24,7 +24,7 @@ export const searchIndex: SettingsField[] = [keywords: ["private", "browser", "enhanced", "automation"],},{ label: msg("Help improve Workflows", {}), keywords: ["sharing", "training", "consent", "delete shared chats"] },- { label: msg("PII masking", {}), keywords: ["mask", "redact", "columns", "url", "fields"] },+ { label: msg("PII masking", {}), keywords: ["mask", "redact", "columns", "url", "fields", "dollar", "amount", "currency", "USD"] },{label: msg("Remote support logs", {}),keywords: ["support", "diagnostic", "troubleshooting", "remote", "logs"],@@ -610,6 +610,7 @@ export function PrivacySection() {label: string;desc: string;always?: boolean;+ textOnly?: boolean;}[] = [{ value: "secret", label: ui("Passwords & keys"), desc: "passwords, API keys, tokens", always: true },{ value: "id", label: ui("ID numbers"), desc: "SSNs, credit cards, account & license numbers" },@@ -620,6 +621,7 @@ export function PrivacySection() {{ value: "url", label: ui("Links with tokens"), desc: "links carrying tokens or session IDs" },{ value: "date", label: ui("Dates"), desc: "dates of birth, timestamps" },{ value: "sensitive", label: ui("Health & financial details"), desc: "health, financial, identity context" },+ { value: "dollar_amount", label: ui("Dollar amounts in text"), desc: "explicit $ or USD amounts; leaves screenshots and unmarked numbers unchanged", textOnly: true },];const piiRedactionLabels = useMemo<string[]>(() => {@@ -1532,14 +1534,14 @@ export function PrivacySection() {key={opt.value}className={cn("flex items-start gap-2 text-xs",- opt.always ? "cursor-default" : "cursor-pointer",+ opt.always || (opt.textOnly && !textRedactionOn) ? "cursor-default" : "cursor-pointer",)}><inputtype="checkbox"className="mt-0.5"checked={checked}- disabled={opt.always}+ disabled={opt.always || (opt.textOnly && !textRedactionOn)}onChange={(e) =>handlePiiLabelToggle(opt.value, e.target.checked)}@@ -1563,6 +1565,11 @@ export function PrivacySection() {{textRedactionOn && (<RedactionExamplePreview labels={piiRedactionLabels} />)}+ <p className="text-[11px] text-muted-foreground">+ Dollar masking requires Text above. It applies to new text+ processed by the background worker; previously processed+ history is not changed.+ </p><p className="text-[11px] text-muted-foreground pt-0.5">Unselected types stay visible so your timeline remainssearchable. Secrets are always removed in both modes.diff --git a/crates/screenpipe-engine/src/cli/mod.rs b/crates/screenpipe-engine/src/cli/mod.rsindex cc6c1c124..21cf6f438 100644--- a/crates/screenpipe-engine/src/cli/mod.rs+++ b/crates/screenpipe-engine/src/cli/mod.rs@@ -570,7 +570,8 @@ pub struct RecordArgs {/// Which PII classes the AI redaction workers rewrite when enabled./// Comma-separated canonical labels: secret, person, email, phone,/// address, sensitive, url, company, repo, handle, channel, id,- /// date. Also accepts fine-grained structured-ID sub-types handled by+ /// date, dollar_amount (explicit $ / USD amounts, text only).+ /// Also accepts fine-grained structured-ID sub-types handled by/// the deterministic detector: us_ssn, credit_card, iban, spain_dni,/// brazil_cpf, india_aadhaar, canada_sin, imei (enable one without/// turning on the whole `id` class). `secret` is always includeddiff --git a/crates/screenpipe-redact/src/adapters/mod.rs b/crates/screenpipe-redact/src/adapters/mod.rsindex e74902edf..de260f738 100644--- a/crates/screenpipe-redact/src/adapters/mod.rs+++ b/crates/screenpipe-redact/src/adapters/mod.rs@@ -51,3 +51,14 @@ pub mod opf;pub mod rfdetr;pub mod rfdetr_mlx;++/// Strip local-only categories without turning an explicit narrow request into+/// the enclave's empty-list (all categories) default.+fn model_labels(mut labels: Vec<String>) -> Vec<String> {+ let previous_len = labels.len();+ labels.retain(|label| !label.trim().eq_ignore_ascii_case("dollar_amount"));+ if labels.is_empty() && previous_len != 0 {+ labels.push("secret".into());+ }+ labels+}diff --git a/crates/screenpipe-redact/src/adapters/regex.rs b/crates/screenpipe-redact/src/adapters/regex.rsindex 2a7a14c5c..8ba008e17 100644--- a/crates/screenpipe-redact/src/adapters/regex.rs+++ b/crates/screenpipe-redact/src/adapters/regex.rs@@ -32,7 +32,7 @@ use crate::{/// Bumped whenever we add or change a pattern in [`PATTERNS`]. Invalidates/// in-memory pipeline cache entries; the database worker does not replay rows/// that were already redacted.-pub const REGEX_REDACTOR_VERSION: u32 = 5;+pub const REGEX_REDACTOR_VERSION: u32 = 6;struct Pattern {re: Regex,@@ -126,6 +126,22 @@ static PATTERNS: Lazy<Vec<Pattern>> = Lazy::new(|| {r"\beyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+",SpanLabel::Secret,),+ // Explicit dollar amounts only. Horizontal whitespace cannot bridge+ // unrelated lines/cells. Bounds are validated below so malformed+ // grouping or identifier suffixes never cause partial redaction.+ (+ r"(?ix)+ (?:[+−-][\t\x20\x{00a0}]*|\([\t\x20\x{00a0}]*)?+ (?:+ (?:\$|\bUSD\b)[\t\x20\x{00a0}]*[+−-]?[\t\x20\x{00a0}]*+ (?:[0-9]{1,3}(?:,[0-9]{3})+|[0-9]+)(?:\.[0-9]+)?+ |+ (?:[0-9]{1,3}(?:,[0-9]{3})+|[0-9]+)(?:\.[0-9]+)?+ [\t\x20\x{00a0}]+USD\b+ )+ (?:[\t\x20\x{00a0}]*\))?",+ SpanLabel::DollarAmount,+ ),// ---- Contact info ----(r"\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b",@@ -1689,6 +1705,17 @@ static ENGINE: Lazy<Engine> = Lazy::new(|| {/// Single-text path — synchronous. Public for use inside the/// [`crate::pipeline::Pipeline`] without going through the async trait.pub fn redact_one(text: &str) -> RedactionOutput {+ detect(text, None)+}++/// Filter ineligible patterns before overlap suppression. Otherwise an+/// unselected category can consume a selected match (e.g. an amount whose+/// digits also resemble an ID), leaving it visible after policy filtering.+pub fn redact_one_with_policy(text: &str, policy: &crate::TextRedactionPolicy) -> RedactionOutput {+ detect(text, Some(policy))+}++fn detect(text: &str, policy: Option<&crate::TextRedactionPolicy>) -> RedactionOutput {let lower = text.to_lowercase();// No-context patterns that the small DFA flagged...@@ -1731,8 +1758,16 @@ pub fn redact_one(text: &str) -> RedactionOutput {for idx in cand {let pat = &PATTERNS[idx];+ if policy.is_some_and(|policy| !policy.allows(pat.label, pat.subtype)) {+ continue;+ }for m in pat.re.find_iter(text) {let matched = &text[m.start()..m.end()];+ if pat.label == SpanLabel::DollarAmount+ && !dollar_amount_boundaries(text, m.start(), m.end())+ {+ continue;+ }// Structural validator (checksum) — drop shapes that don't// check out (a 16-digit DB ID that fails Luhn, a random@@ -1779,6 +1814,27 @@ pub fn redact_one(text: &str) -> RedactionOutput {}}+/// Do not take a numeric substring of an identifier, malformed number or+/// unsupported locale format. Punctuation followed by prose is a delimiter.+fn dollar_amount_boundaries(text: &str, start: usize, end: usize) -> bool {+ let before = text[..start].chars().next_back();+ let after = text[end..].chars().next();+ if before.is_some_and(|c| c.is_alphanumeric() || matches!(c, '_' | '$' | '.' | ','))+ || after.is_some_and(|c| c.is_alphanumeric() || c == '_')+ {+ return false;+ }+ if matches!(after, Some('.' | ','))+ && text[end..]+ .chars()+ .nth(1)+ .is_some_and(|c| c.is_ascii_digit())+ {+ return false;+ }+ true+}+/// Whole-word (boundary-anchored) substring test. `needle` must be/// lowercase; `hay` is lowercased by the caller. This is what stops the/// 3-letter keyword `sin` from matching inside `business` while still@@ -1852,6 +1908,81 @@ mod tests {redact_one(text)}+ #[test]+ fn explicit_dollar_formats_and_boundaries() {+ let policy = crate::TextRedactionPolicy::from_labels(&["dollar_amount".into()]);+ for amount in [+ "$1",+ "$1,250.00",+ "$1250",+ "USD 1,250.75",+ "usd 500",+ "-$500",+ "$-500.25",+ "+$500",+ "−$500",+ "($500)",+ "(USD 500.00)",+ "1,250.00 USD",+ "(1,250 USD)",+ "$0.000125",+ "$ 50",+ "$\u{a0}50",+ ] {+ let input = format!("Total: {amount}; next.");+ let out = redact_one_with_policy(&input, &policy);+ assert_eq!(out.redacted, "Total: [DOLLAR_AMOUNT]; next.", "{input}");+ assert_eq!(out.spans.len(), 1, "{input}");+ assert_eq!(out.spans[0].text, amount);+ }+ for input in [+ "Total 1,250.00",+ "12%",+ "2026-10-14",+ "Order 125000",+ "$HOME",+ "USDT 500",+ "USD_RATE 500",+ "foo$500bar",+ "USD 500abc",+ "foo500 USD",+ "$1,23",+ "$1.234,56",+ "1.234,56 USD",+ "$500.12.34",+ "$500_00",+ "$\n500",+ "500\nUSD",+ "$1.2M",+ "EUR 500",+ ] {+ assert_eq!(+ redact_one_with_policy(input, &policy).redacted,+ input,+ "{input}"+ );+ }+ let adjacent = "Paid $500, received $250. Total USD 750.";+ assert_eq!(+ redact_one_with_policy(adjacent, &policy).redacted,+ "Paid [DOLLAR_AMOUNT], received [DOLLAR_AMOUNT]. Total [DOLLAR_AMOUNT]."+ );+ }++ #[test]+ fn selected_dollar_amount_does_not_steal_other_selected_pii() {+ let text = "Charge $4111111111111111; password=$123456; [email protected]";+ let dollars = crate::TextRedactionPolicy::from_labels(&["dollar_amount".into()]);+ let out = redact_one_with_policy(text, &dollars);+ assert_eq!(+ out.redacted,+ "Charge [DOLLAR_AMOUNT]; [SECRET]; [email protected]"+ );+ let ids = crate::TextRedactionPolicy::from_labels(&["id".into()]);+ let out = redact_one_with_policy(text, &ids);+ assert_eq!(out.redacted, "Charge $[ID]; [SECRET]; [email protected]");+ }+#[test]fn email_caught() {let out = run("Contact: [email protected] for details");diff --git a/crates/screenpipe-redact/src/adapters/tinfoil.rs b/crates/screenpipe-redact/src/adapters/tinfoil.rsindex 9104cf672..4dcd91b9e 100644--- a/crates/screenpipe-redact/src/adapters/tinfoil.rs+++ b/crates/screenpipe-redact/src/adapters/tinfoil.rs@@ -221,7 +221,9 @@ impl TinfoilRedactor {repo,bearer,timeout: cfg.timeout.unwrap_or(DEFAULT_TIMEOUT),- labels: cfg.labels,+ // Dollar amounts are handled by the local text regex pre-pass.+ // The deployed enclave taxonomy has no such model category.+ labels: super::model_labels(cfg.labels),client: RwLock::new(None),has_auth,}@@ -443,6 +445,18 @@ mod tests {}}+ #[test]+ fn dollar_amount_is_not_forwarded_to_enclave() {+ let mut config = cfg("never.invalid");+ config.labels = vec!["secret".into(), " Dollar_Amount ".into(), "person".into()];+ let redactor = TinfoilRedactor::new(config);+ assert_eq!(redactor.labels, ["secret", "person"]);+ let mut config = cfg("never.invalid");+ config.labels = vec!["dollar_amount".into()];+ assert_eq!(TinfoilRedactor::new(config).labels, ["secret"]);+ assert!(TinfoilRedactor::new(cfg("never.invalid")).labels.is_empty());+ }+#[tokio::test]async fn short_text_bypasses_round_trip() {// Bypass fires before lazy attestation, so the bogus enclavediff --git a/crates/screenpipe-redact/src/adapters/tinfoil_image.rs b/crates/screenpipe-redact/src/adapters/tinfoil_image.rsindex 7c199fad1..70e05475a 100644--- a/crates/screenpipe-redact/src/adapters/tinfoil_image.rs+++ b/crates/screenpipe-redact/src/adapters/tinfoil_image.rs@@ -181,7 +181,9 @@ impl TinfoilImageRedactor {bearer,timeout: cfg.timeout.unwrap_or(DEFAULT_TIMEOUT),threshold,- labels: cfg.labels,+ // Dollar amounts are handled by the local text regex pre-pass.+ // The deployed enclave taxonomy has no such model category.+ labels: super::model_labels(cfg.labels),client: RwLock::new(None),has_auth,}@@ -355,6 +357,18 @@ fn parse_label(s: &str) -> Option<SpanLabel> {mod tests {use super::*;+ #[test]+ fn dollar_amount_is_not_forwarded_to_enclave() {+ let mut config = cfg();+ config.labels = vec!["secret".into(), " Dollar_Amount ".into(), "person".into()];+ let redactor = TinfoilImageRedactor::new(config);+ assert_eq!(redactor.labels, ["secret", "person"]);+ let mut config = cfg();+ config.labels = vec!["dollar_amount".into()];+ assert_eq!(TinfoilImageRedactor::new(config).labels, ["secret"]);+ assert!(TinfoilImageRedactor::new(cfg()).labels.is_empty());+ }+#[test]fn version_is_stable() {let r = TinfoilImageRedactor::from_env();diff --git a/crates/screenpipe-redact/src/pipeline.rs b/crates/screenpipe-redact/src/pipeline.rsindex 65ebf4dff..6b84c56f7 100644--- a/crates/screenpipe-redact/src/pipeline.rs+++ b/crates/screenpipe-redact/src/pipeline.rs@@ -303,7 +303,7 @@ impl Pipeline {continue;}- let regex_out = regex_adapter::redact_one(text);+ let regex_out = regex_adapter::redact_one_with_policy(text, &self.cfg.policy);let current = apply_policy(regex_out, &self.cfg.policy, self.pseudonyms.as_deref());let want_ai = current.input.chars().count() >= self.cfg.ai_min_chars&& current.spans.len() < self.cfg.ai_skip_if_regex_spans;@@ -535,7 +535,7 @@ impl Redactor for Pipeline {return Ok((*hit).clone());}let mut current = apply_policy(- regex_adapter::redact_one(text),+ regex_adapter::redact_one_with_policy(text, &self.cfg.policy),&self.cfg.policy,self.pseudonyms.as_deref(),);@@ -609,7 +609,7 @@ impl Redactor for Pipeline {continue;}- let regex_out = regex_adapter::redact_one(text);+ let regex_out = regex_adapter::redact_one_with_policy(text, &self.cfg.policy);// Apply policy to the regex pass: drop non-allowed labels +// re-render `redacted` from `input` so the AI fallback sees// a string with only allowed-class placeholders (currently:@@ -896,6 +896,49 @@ mod tests {}}+ #[tokio::test]+ async fn dollar_amounts_are_opt_in_and_leave_unmarked_numbers() {+ let text = "Invoice $12,450.75; credit (USD 500.00); quantity 1250; rate 12%.";+ let default = Pipeline::regex_only()+ .redact_batch(&[text.into()])+ .await+ .unwrap();+ assert_eq!(default[0].redacted, text);+ let pipeline = Pipeline::regex_only_with_policy(TextRedactionPolicy::from_labels(&[+ "dollar_amount".into(),+ ]));+ let out = pipeline.redact_batch(&[text.into()]).await.unwrap();+ assert_eq!(+ out[0].redacted,+ "Invoice [DOLLAR_AMOUNT]; credit [DOLLAR_AMOUNT]; quantity 1250; rate 12%."+ );+ }++ #[tokio::test]+ async fn dollar_amounts_survive_serial_and_batched_ai_processing() {+ let text = "Invoice total: $12,450.75. Keep the workflow description.";+ for ai in [+ Arc::new(UppercaseAi::new()) as Arc<dyn Redactor>,+ Arc::new(BatchingAi::new()) as Arc<dyn Redactor>,+ ] {+ let pipeline = Pipeline::regex_then_ai(+ ai,+ PipelineConfig {+ policy: TextRedactionPolicy::from_labels(&["dollar_amount".into()]),+ ..Default::default()+ },+ );+ let out = pipeline.redact_batch(&[text.into()]).await.unwrap();+ assert_eq!(+ out[0].redacted,+ "INVOICE TOTAL: [DOLLAR_AMOUNT]. KEEP THE WORKFLOW DESCRIPTION."+ );+ assert_eq!(out[0].spans[0].text, "$12,450.75");+ let strict = pipeline.redact_complete(text).await.unwrap();+ assert_eq!(strict.redacted, out[0].redacted);+ }+ }+#[tokio::test]async fn regex_only_runs_without_ai_secret_policy() {// Default policy is `allow=[Secret]`, so a bare email is NOTdiff --git a/crates/screenpipe-redact/src/span.rs b/crates/screenpipe-redact/src/span.rsindex 06497a10e..44b70f784 100644--- a/crates/screenpipe-redact/src/span.rs+++ b/crates/screenpipe-redact/src/span.rs@@ -43,6 +43,8 @@ pub enum SpanLabel {/// AND a separate `Sensitive` span. Emitted by the v45 phase 3/// model; older adapters always return zero of these.Sensitive,+ /// Explicit dollar / USD amounts in text. Regex-only, opt-in; no image coverage.+ DollarAmount,}impl SpanLabel {@@ -63,6 +65,7 @@ impl SpanLabel {Self::Date => "[DATE]",Self::Secret => "[SECRET]",Self::Sensitive => "[SENSITIVE]",+ Self::DollarAmount => "[DOLLAR_AMOUNT]",}}@@ -86,6 +89,7 @@ impl SpanLabel {"date" => Self::Date,"secret" => Self::Secret,"sensitive" => Self::Sensitive,+ "dollar_amount" => Self::DollarAmount,_ => return None,})}diff --git a/docs/pr-assets/dollar-amount-redaction/after.png b/docs/pr-assets/dollar-amount-redaction/after.pngnew file mode 100644index 000000000..ab772a381Binary files /dev/null and b/docs/pr-assets/dollar-amount-redaction/after.png differdiff --git a/docs/pr-assets/dollar-amount-redaction/before.png b/docs/pr-assets/dollar-amount-redaction/before.pngnew file mode 100644index 000000000..560764f43Binary files /dev/null and b/docs/pr-assets/dollar-amount-redaction/before.png differ