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
fix(privacy): a capture category no longer deletes the user's own rules
Louis Beaumont4450aaa82d30
diff --git a/apps/screenpipe-app-tauri/components/settings/capture-filters/content-filters-card.tsx b/apps/screenpipe-app-tauri/components/settings/capture-filters/content-filters-card.tsxindex 291aa78a4..f104d16a5 100644--- a/apps/screenpipe-app-tauri/components/settings/capture-filters/content-filters-card.tsx+++ b/apps/screenpipe-app-tauri/components/settings/capture-filters/content-filters-card.tsx@@ -26,6 +26,7 @@ import {import {setCategoryEnabled,type CaptureCategory,+ type CategoryOwnedFilters,type CategoryTargets,} from "@/lib/settings/capture-categories";import { AppFilterList } from "./app-filter-list";@@ -36,6 +37,8 @@ import { WebsiteFilterList, type ObservedDomain } from "./website-filter-list";export interface ContentFiltersCardProps {rules: WindowRules;ignoredUrls: string[];+ /** Entries the category switches created, so turning one off spares the user's own. */+ categoryOwned?: CategoryOwnedFilters;observedWindows: ObservedWindow[];observedDomains: ObservedDomain[];installedApps: string[];@@ -61,6 +64,7 @@ export interface ContentFiltersCardProps {export function ContentFiltersCard({rules,ignoredUrls,+ categoryOwned,observedWindows,observedDomains,installedApps,@@ -145,8 +149,10 @@ export function ContentFiltersCard({const handleCategoryToggle = useCallback((category: CaptureCategory, enabled: boolean) =>- onTargetsChange(setCategoryEnabled({ rules, ignoredUrls }, category, enabled)),- [rules, ignoredUrls, onTargetsChange],+ onTargetsChange(+ setCategoryEnabled({ rules, ignoredUrls, owned: categoryOwned }, category, enabled),+ ),+ [rules, ignoredUrls, categoryOwned, onTargetsChange],);const handleAdvancedChange = useCallback(diff --git a/apps/screenpipe-app-tauri/components/settings/privacy-section.tsx b/apps/screenpipe-app-tauri/components/settings/privacy-section.tsxindex 1877d9d7b..d4301c59f 100644--- a/apps/screenpipe-app-tauri/components/settings/privacy-section.tsx+++ b/apps/screenpipe-app-tauri/components/settings/privacy-section.tsx@@ -1647,6 +1647,7 @@ export function PrivacySection() {<ContentFiltersCardrules={windowRules}ignoredUrls={settings.ignoredUrls || []}+ categoryOwned={settings.categoryOwnedFilters}observedWindows={windowItems || []}observedDomains={urlItems || []}installedApps={installedApps}@@ -1661,6 +1662,7 @@ export function PrivacySection() {ignoredWindows: next.rules.ignored,includedWindows: next.rules.included,ignoredUrls: next.ignoredUrls,+ categoryOwnedFilters: next.owned ?? { apps: [], domains: [] },},true)diff --git a/apps/screenpipe-app-tauri/lib/hooks/use-settings.tsx b/apps/screenpipe-app-tauri/lib/hooks/use-settings.tsxindex 3e4f066e6..e29a0d1e4 100644--- a/apps/screenpipe-app-tauri/lib/hooks/use-settings.tsx+++ b/apps/screenpipe-app-tauri/lib/hooks/use-settings.tsx@@ -284,6 +284,11 @@ export type Settings = SettingsStore & {updateChannel?: UpdateChannel;chatHistory?: ChatHistoryStore;ignoredUrls?: string[];+ /**+ * Entries the capture-category switches created, so turning a category off+ * removes only those and never a rule the user wrote by hand.+ */+ categoryOwnedFilters?: { apps: string[]; domains: string[] };searchShortcut?: string;lockVaultShortcut?: string;/** When true, audio devices follow system default and auto-switch on changes */diff --git a/apps/screenpipe-app-tauri/lib/settings/__tests__/capture-categories.test.ts b/apps/screenpipe-app-tauri/lib/settings/__tests__/capture-categories.test.tsindex 15e86a82d..b3ab41ffa 100644--- a/apps/screenpipe-app-tauri/lib/settings/__tests__/capture-categories.test.ts+++ b/apps/screenpipe-app-tauri/lib/settings/__tests__/capture-categories.test.ts@@ -19,6 +19,12 @@ import { parseRule, resolveAppState, type WindowRules } from "../capture-filtersconst empty: CategoryTargets = { rules: { ignored: [], included: [] }, ignoredUrls: [] };+/**+ * `empty` after a category has been switched on and back off. Identical rules+ * and domains, plus the emptied record of what the category had created.+ */+const cleared: CategoryTargets = { ...empty, owned: { apps: [], domains: [] } };+const passwords = findCategory("password-managers")!;const messaging = findCategory("personal-messaging")!;const banking = findCategory("banking-finance")!;@@ -173,7 +179,7 @@ describe("enableCategory", () => {describe("disableCategory", () => {it("removes everything it added", () => {const on = enableCategory(empty, passwords);- expect(disableCategory(on, passwords)).toEqual(empty);+ expect(disableCategory(on, passwords)).toEqual(cleared);});it("leaves a rule the user wrote by hand for the same app", () => {@@ -196,7 +202,7 @@ describe("disableCategory", () => {});it("is idempotent", () => {- expect(disableCategory(empty, passwords)).toEqual(empty);+ expect(disableCategory(empty, passwords)).toEqual(cleared);});it("removes a domain the user wrote in another form", () => {@@ -212,7 +218,7 @@ describe("setCategoryEnabled", () => {it("round-trips cleanly", () => {const on = setCategoryEnabled(empty, passwords, true);expect(categoryState(passwords, on.rules, on.ignoredUrls)).toBe("on");- expect(setCategoryEnabled(on, passwords, false)).toEqual(empty);+ expect(setCategoryEnabled(on, passwords, false)).toEqual(cleared);});it("completes a partial category when switched on", () => {@@ -275,3 +281,71 @@ describe("category rules survive the filter helpers", () => {}});});++describe("a category never deletes the user's own work", () => {+ // Regression for the 2026-08-12 chaos finding: enabling a category adopted a+ // byte-identical entry the user had typed, and disabling it deleted their+ // privacy exclusion with no warning. Domains are the realistic path — they+ // have no scoped form, so `chase.com` is `chase.com` whoever wrote it.+ it("keeps a hand-written domain that a category also ships", () => {+ const userTyped = banking.domains[0];+ const mine: CategoryTargets = {+ rules: { ignored: [], included: [] },+ ignoredUrls: [userTyped],+ };++ const on = enableCategory(mine, banking);+ expect(on.ignoredUrls).toContain(userTyped);+ expect(on.owned?.domains ?? []).not.toContain(userTyped);++ const off = disableCategory(on, banking);+ expect(off.ignoredUrls).toContain(userTyped);+ // and the category's own domains are still cleaned up+ for (const d of banking.domains.slice(1)) expect(off.ignoredUrls).not.toContain(d);+ });++ it("keeps a hand-written app rule that a category also ships", () => {+ const userTyped = passwords.apps[0];+ const mine: CategoryTargets = {+ rules: { ignored: [userTyped], included: [] },+ ignoredUrls: [],+ };++ const off = disableCategory(enableCategory(mine, passwords), passwords);+ expect(off.rules.ignored).toContain(userTyped);+ });++ it("still removes everything it actually created", () => {+ const off = disableCategory(enableCategory(empty, messaging), messaging);+ expect(off.rules.ignored).toEqual([]);+ expect(off.ignoredUrls).toEqual([]);+ expect(off.owned?.domains ?? []).toEqual([]);+ expect(off.owned?.apps ?? []).toEqual([]);+ });++ it("survives the every-category domain sweep that used to fail 5 of 5", () => {+ for (const category of CAPTURE_CATEGORIES) {+ if (category.domains.length === 0) continue;+ const userTyped = category.domains[0];+ const mine: CategoryTargets = {+ rules: { ignored: [], included: [] },+ ignoredUrls: [userTyped],+ };+ const off = disableCategory(enableCategory(mine, category), category);+ expect(off.ignoredUrls, `${category.id} deleted the user's ${userTyped}`).toContain(+ userTyped,+ );+ }+ });++ it("does not claim an entry a second category already created", () => {+ const first = enableCategory(empty, banking);+ const both = enableCategory(first, messaging);+ expect(both.owned?.domains ?? []).toEqual(+ expect.arrayContaining([...banking.domains, ...messaging.domains]),+ );+ // turning one off leaves the other's entries alone+ const off = disableCategory(both, banking);+ for (const d of messaging.domains) expect(off.ignoredUrls).toContain(d);+ });+});diff --git a/apps/screenpipe-app-tauri/lib/settings/capture-categories.ts b/apps/screenpipe-app-tauri/lib/settings/capture-categories.tsindex 765e8cfe5..695a4e1c8 100644--- a/apps/screenpipe-app-tauri/lib/settings/capture-categories.ts+++ b/apps/screenpipe-app-tauri/lib/settings/capture-categories.ts@@ -12,8 +12,14 @@** A category is just a named bundle of ordinary rules. Turning it on appends* them, turning it off removes exactly the ones it owns, and everything the- * user wrote by hand is left alone. There is no new stored field and no engine- * change: the recorder keeps matching the same two string arrays it always did.+ * user wrote by hand is left alone. There is no engine change: the recorder+ * keeps matching the same two string arrays it always did.+ *+ * Honouring "exactly the ones it owns" does need one stored field. Exact-string+ * matching cannot separate a category's `chase.com` from the user's, so the+ * entries a category actually created are recorded alongside them. Without that+ * record, enabling a category adopted the user's identical entry and disabling+ * it deleted their privacy exclusion outright.** The tradeoff that buys: if a category's contents change in a later release,* users who already enabled it keep the rules they got. That is the price of@@ -185,43 +191,99 @@ export function categoryState(return present === total ? "on" : "partial";}+/**+ * The entries this app added on behalf of a category.+ *+ * Exact-string matching is not enough to tell them apart from the user's own+ * work. `chase.com` typed by hand into the domain blocklist is byte-identical+ * to the one the banking category ships, so enabling the category silently+ * adopted it and disabling the category deleted it — a privacy exclusion+ * vanishing with no warning. Domains have no scoped form to disambiguate,+ * so provenance has to be recorded.+ *+ * Declared as a type alias, not an interface: this is persisted in the+ * settings store, whose values must satisfy a `JsonValue` index signature, and+ * only a type alias gets one implicitly.+ */+export type CategoryOwnedFilters = {+ apps: string[];+ domains: string[];+};+export interface CategoryTargets {rules: WindowRules;ignoredUrls: string[];+ /** Absent on state written before provenance was recorded — see `disableCategory`. */+ owned?: CategoryOwnedFilters;}-/** Apply every rule a category owns. Idempotent. */+/**+ * Apply every rule a category owns. Idempotent.+ *+ * An entry that is already present belongs to the user. The category still+ * relies on it for matching, but does not claim it, so turning the category+ * back off leaves it in place.+ */export function enableCategory(targets: CategoryTargets,category: CaptureCategory,): CategoryTargets {let rules = targets.rules;- for (const app of category.apps) rules = addRule(rules, app, "ignored");-let ignoredUrls = [...targets.ignoredUrls];- for (const domain of category.domains) ignoredUrls = addDomain(ignoredUrls, domain);+ const apps = [...(targets.owned?.apps ?? [])];+ const domains = [...(targets.owned?.domains ?? [])];- return { rules, ignoredUrls };+ for (const app of category.apps) {+ const userAlreadyHadIt = hasRule(rules.ignored, app);+ rules = addRule(rules, app, "ignored");+ if (!userAlreadyHadIt && !apps.includes(app)) apps.push(app);+ }++ for (const domain of category.domains) {+ const userAlreadyHadIt = hasDomain(ignoredUrls, domain);+ ignoredUrls = addDomain(ignoredUrls, domain);+ if (!userAlreadyHadIt && !domains.includes(domain)) domains.push(domain);+ }++ return { rules, ignoredUrls, owned: { apps, domains } };}/**- * Remove every rule a category owns, and nothing else.+ * Remove only the entries this app added, and nothing else.*- * Matching is by exact entry, so a rule the user wrote themselves survives even- * when it targets the same app. Turning a category off must never delete work- * the user did by hand.+ * Turning a category off must never delete work the user did by hand, so an+ * entry the user already had when the category was switched on is left behind.+ *+ * Legacy state carries no provenance, because it was written before this was+ * recorded. Such a category falls back to removing everything it names, which+ * is the old behaviour: the alternative is a switch that can never turn off.+ * A hand-written entry colliding with a category the user enabled *before*+ * upgrading is therefore still lost on its first disable; from the next enable+ * onward provenance is recorded and the entry is safe.*/export function disableCategory(targets: CategoryTargets,category: CaptureCategory,): CategoryTargets {+ const legacyStateWithoutProvenance = targets.owned === undefined;+ const apps = new Set(targets.owned?.apps ?? []);+ const domains = new Set(targets.owned?.domains ?? []);+let rules = targets.rules;- for (const app of category.apps) rules = removeRule(rules, app, "ignored");+ for (const app of category.apps) {+ if (!legacyStateWithoutProvenance && !apps.has(app)) continue;+ rules = removeRule(rules, app, "ignored");+ apps.delete(app);+ }let ignoredUrls = [...targets.ignoredUrls];- for (const domain of category.domains) ignoredUrls = removeDomain(ignoredUrls, domain);+ for (const domain of category.domains) {+ if (!legacyStateWithoutProvenance && !domains.has(domain)) continue;+ ignoredUrls = removeDomain(ignoredUrls, domain);+ domains.delete(domain);+ }- return { rules, ignoredUrls };+ return { rules, ignoredUrls, owned: { apps: [...apps], domains: [...domains] } };}/**