Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

Let users exclude sensitive memories from AI requests

David4a7a26dcf08b
diff --git a/e2e/memory-sensitive-proof.html b/e2e/memory-sensitive-proof.html
new file mode 100644
index 00000000..d2cee87e
--- /dev/null
+++ b/e2e/memory-sensitive-proof.html
@@ -0,0 +1,4 @@
+<!doctype html>
+<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Memory privacy proof</title></head>
+<body><div id="root"></div><button id="retrieve">Preview AI memory context</button><pre id="result"></pre>
+<script type="module" src="/e2e/memory-sensitive-proof.ts"></script></body></html>
diff --git a/e2e/memory-sensitive-proof.ts b/e2e/memory-sensitive-proof.ts
new file mode 100644
index 00000000..e462a994
--- /dev/null
+++ b/e2e/memory-sensitive-proof.ts
@@ -0,0 +1,13 @@
+import { createElement } from 'react'
+import { createRoot } from 'react-dom/client'
+import { MemorySettings } from '../src/components/settings/MemorySettings'
+import { useMemoryStore, __setMemoryEmbedFn } from '../src/stores/memoryStore'
+import '../src/index.css'
+
+await useMemoryStore.persist.rehydrate()
+__setMemoryEmbedFn(async () => [])
+createRoot(document.getElementById('root')!).render(createElement(MemorySettings))
+document.getElementById('retrieve')!.addEventListener('click', async () => {
+ document.getElementById('result')!.textContent =
+ await useMemoryStore.getState().getMemoriesForPromptAsync('private', 8192) || 'No eligible memories'
+})
diff --git a/e2e/memory-sensitive.spec.ts b/e2e/memory-sensitive.spec.ts
new file mode 100644
index 00000000..b091161f
--- /dev/null
+++ b/e2e/memory-sensitive.spec.ts
@@ -0,0 +1,21 @@
+import { expect, test } from '@playwright/test'
+
+test('real memory settings protect a new entry across reload and allow explicit unmarking', async ({ page }, testInfo) => {
+ await page.goto('/e2e/memory-sensitive-proof.html')
+ await page.getByRole('button', { name: 'Add Memory', exact: true }).click()
+ await page.getByPlaceholder('What should I remember?').fill('Private preference')
+ await page.getByPlaceholder('Details… (required)').fill('Synthetic private preference')
+ await page.getByLabel('Sensitive: exclude from AI requests').check()
+ await page.getByRole('button', { name: 'Save', exact: true }).click()
+ await page.getByRole('button', { name: 'Preview AI memory context' }).click()
+ await expect(page.locator('#result')).toHaveText('No eligible memories')
+ await page.reload()
+ await expect(page.getByLabel('Sensitive: exclude from AI requests')).toBeChecked()
+ await page.setViewportSize({ width: 390, height: 844 })
+ await page.screenshot({ path: testInfo.outputPath('memory-sensitive-mobile.png'), fullPage: true })
+ await page.getByRole('button', { name: 'Preview AI memory context' }).click()
+ await expect(page.locator('#result')).toHaveText('No eligible memories')
+ await page.getByLabel('Sensitive: exclude from AI requests').uncheck()
+ await page.getByRole('button', { name: 'Preview AI memory context' }).click()
+ await expect(page.locator('#result')).toContainText('Synthetic private preference')
+})
diff --git a/src/components/settings/MemorySettings.tsx b/src/components/settings/MemorySettings.tsx
index 99a2f565..9ddabeda 100644
--- a/src/components/settings/MemorySettings.tsx
+++ b/src/components/settings/MemorySettings.tsx
@@ -49,6 +49,7 @@ export function MemorySettings() {
// ── New memory form state ───────────────────────────────────
const [newTitle, setNewTitle] = useState('')
const [newContent, setNewContent] = useState('')
+ const [newSensitive, setNewSensitive] = useState(false)
const [addError, setAddError] = useState<string | null>(null)
// ── Edit form state ─────────────────────────────────────────
@@ -174,9 +175,11 @@ export function MemorySettings() {
content: newContent.trim(),
tags: [],
source: 'manual',
+ sensitive: newSensitive,
})
setNewTitle('')
setNewContent('')
+ setNewSensitive(false)
setAddError(null)
setAddingNew(false)
}
@@ -270,6 +273,7 @@ export function MemorySettings() {
</div>
{/* Search */}
+ <p className="text-xs text-gray-500">Mark sensitive memories to exclude them from AI requests and embeddings. This does not detect secrets automatically or erase earlier requests. Markdown export omits marked entries; JSON export includes them and their sensitivity flags.</p>
<div className="relative">
<Search size={12} className="absolute left-2.5 top-1/2 -translate-y-1/2 text-gray-500" />
<input
@@ -318,6 +322,10 @@ export function MemorySettings() {
{addError && (
<p className="text-[0.55rem] text-red-400 px-0.5">{addError}</p>
)}
+ <label className="flex gap-2 text-xs">
+ <input type="checkbox" checked={newSensitive} onChange={e => setNewSensitive(e.target.checked)} />
+ Sensitive: exclude from AI requests
+ </label>
<div className="flex gap-1.5">
<button
onClick={handleAddMemory}
@@ -389,6 +397,11 @@ export function MemorySettings() {
)}
</div>
<p className="text-[0.6rem] text-gray-500 break-words line-clamp-2">{entry.content}</p>
+ <label className="flex gap-2 text-xs text-gray-500">
+ <input type="checkbox" checked={entry.sensitive === true}
+ onChange={e => updateMemory(entry.id, { sensitive: e.target.checked })} />
+ Sensitive: exclude from AI requests
+ </label>
</div>
<div className="flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity shrink-0">
{/* Outdated entries are read-only — no edit affordance. */}
diff --git a/src/hooks/useMemory.ts b/src/hooks/useMemory.ts
index 84490015..650e9aa1 100644
--- a/src/hooks/useMemory.ts
+++ b/src/hooks/useMemory.ts
@@ -200,7 +200,7 @@ async function resolveAndSaveMemory(memory: ExtractedMemory, conversationId: str
// Same-type, non-stale existing memories are the only merge candidates —
// a "user" fact never merges into a "reference", etc.
const sameType: MemoryFile[] = memState.entries.filter(
- (e) => e.type === memory.type && e.stale !== true,
+ (e) => e.type === memory.type && e.stale !== true && !e.sensitive,
)
if (sameType.length === 0) {
addPlain()
@@ -271,6 +271,8 @@ async function resolveAndSaveMemory(memory: ExtractedMemory, conversationId: str
const call = resolveSilentCall(activeModel)
if (!call) return
const { provider, modelId } = call
+ const currentEntries = useMemoryStore.getState().entries
+ if (topK.some(candidate => !currentEntries.some(entry => entry.id === candidate.id && !entry.sensitive && entry.content === candidate.content))) return
const messages = buildResolutionPrompt(
{ title: memory.title, content: memory.content },
topK,
diff --git a/src/stores/__tests__/memory-sensitive.test.ts b/src/stores/__tests__/memory-sensitive.test.ts
new file mode 100644
index 00000000..5e062c78
--- /dev/null
+++ b/src/stores/__tests__/memory-sensitive.test.ts
@@ -0,0 +1,41 @@
+import { afterEach, beforeEach, expect, it, vi } from 'vitest'
+import { useMemoryStore, __setMemoryEmbedFn } from '../memoryStore'
+
+const embed = vi.fn(async () => [[1, 0]])
+beforeEach(() => {
+ useMemoryStore.setState({ entries: [] })
+ embed.mockClear()
+ __setMemoryEmbedFn(embed)
+})
+afterEach(() => __setMemoryEmbedFn())
+const add = () => useMemoryStore.getState().addMemory({
+ type: 'user', title: 'Private preference', description: 'Synthetic only',
+ content: 'Synthetic private preference', tags: [], source: 'manual', sensitive: true,
+})
+
+it('excludes marked entries from sync, async and embedding backfill', async () => {
+ add()
+ expect(useMemoryStore.getState().getMemoriesForPrompt('private', 8192)).toBe('')
+ expect(await useMemoryStore.getState().getMemoriesForPromptAsync('private', 8192)).toBe('')
+ await useMemoryStore.getState().ensureMemoryEmbeddings()
+ expect(embed).not.toHaveBeenCalled()
+})
+it('preserves sensitivity through JSON export/import and omits it from Markdown', () => {
+ add()
+ const json = useMemoryStore.getState().exportAsJSON()
+ expect(useMemoryStore.getState().exportAsMarkdown()).not.toContain('Synthetic private')
+ useMemoryStore.getState().clearAll()
+ expect(useMemoryStore.getState().importFromJSON(json)).toBe(1)
+ expect(useMemoryStore.getState().entries[0].sensitive).toBe(true)
+ expect(useMemoryStore.getState().getMemoriesForPrompt('private', 8192)).toBe('')
+})
+it('lets an explicit user unmark restore eligibility', () => {
+ const id = add()
+ useMemoryStore.getState().updateMemory(id, { sensitive: false })
+ expect(useMemoryStore.getState().getMemoriesForPrompt('private', 8192)).toContain('Synthetic private')
+})
+it('does not let an automatic resolution modify a protected target', () => {
+ const id = add()
+ useMemoryStore.getState().applyWriteDecision({ action: 'UPDATE', targetId: id, mergedContent: 'Changed' })
+ expect(useMemoryStore.getState().entries[0].content).toBe('Synthetic private preference')
+})
diff --git a/src/stores/memoryStore.ts b/src/stores/memoryStore.ts
index ef20a04f..7e693ed0 100644
--- a/src/stores/memoryStore.ts
+++ b/src/stores/memoryStore.ts
@@ -72,7 +72,7 @@ async function enqueueEmbedding(entry: Pick<MemoryFile, 'id' | 'title' | 'conten
const contentHash = hashContent(text)
const isCurrent = () => {
const current = useMemoryStore.getState().entries.find((item) => item.id === entry.id)
- return !!current && !isStale(current) && embedText(current) === text
+ return !!current && !current.sensitive && !isStale(current) && embedText(current) === text
}
const existing = await loadVectors([entry.id])
if (!isCurrent()) return
@@ -253,7 +253,7 @@ interface MemoryState {
// CRUD
addMemory: (memory: Omit<MemoryFile, 'id' | 'createdAt' | 'updatedAt'>) => string
- updateMemory: (id: string, updates: Partial<Pick<MemoryFile, 'title' | 'description' | 'content' | 'type' | 'tags'>>) => void
+ updateMemory: (id: string, updates: Partial<Pick<MemoryFile, 'title' | 'description' | 'content' | 'type' | 'tags' | 'sensitive'>>) => void
removeMemory: (id: string) => void
clearAll: () => void
@@ -390,6 +390,7 @@ function asMemoryFile(v: unknown): MemoryFile | null {
createdAt: asNumber(v.createdAt) ?? now,
updatedAt: asNumber(v.updatedAt) ?? asNumber(v.createdAt) ?? now,
source: asString(v.source) ?? 'migration',
+ sensitive: v.sensitive === true,
supersededBy: asString(v.supersededBy),
supersedesId: asString(v.supersedesId),
stale: v.stale === true,
@@ -517,6 +518,7 @@ export const useMemoryStore = create<MemoryState>()(
),
lastSynced: Date.now(),
}))
+ if (updates.sensitive === true) void deleteVector(id)
// Re-embed when title/content changed (hashContent skips a no-op).
if (updates.title !== undefined || updates.content !== undefined) {
const updated = get().entries.find((e) => e.id === id)
@@ -572,7 +574,7 @@ export const useMemoryStore = create<MemoryState>()(
if (budget.budgetTokens === 0 || budget.maxMemories === 0) return ''
const words = query.toLowerCase().split(/\s+/).filter(w => w.length > 2)
- let candidates = get().entries.filter(e => !isStale(e))
+ let candidates = get().entries.filter(e => !e.sensitive && !isStale(e))
if (opts?.excludeToolResults) {
candidates = candidates.filter(e => !isToolResultMemory(e))
}
@@ -613,7 +615,7 @@ export const useMemoryStore = create<MemoryState>()(
// stubbed sync method in tests is honoured).
if (budget.budgetTokens === 0 || budget.maxMemories === 0) return fallback()
- let candidates = get().entries.filter(e => !isStale(e))
+ let candidates = get().entries.filter(e => !e.sensitive && !isStale(e))
if (opts?.excludeToolResults) {
candidates = candidates.filter(e => !isToolResultMemory(e))
}
@@ -685,7 +687,7 @@ export const useMemoryStore = create<MemoryState>()(
const { targetId, mergedContent } = decision
if (!targetId || !mergedContent) return
const target = get().entries.find((e) => e.id === targetId)
- if (!target) return
+ if (!target || target.sensitive) return
const merged = mergedContent.trim()
if (!merged) return
@@ -733,7 +735,7 @@ export const useMemoryStore = create<MemoryState>()(
ensureMemoryEmbeddings: async (batchSize = 8) => {
let embedded = 0
try {
- const entries = get().entries.filter((e) => !isStale(e))
+ const entries = get().entries.filter((e) => !e.sensitive && !isStale(e))
if (entries.length === 0) return 0
const ids = entries.map((e) => e.id)
const existing = await loadVectors(ids)
@@ -768,7 +770,7 @@ export const useMemoryStore = create<MemoryState>()(
// ── Export / Import ─────────────────────────────────────
exportAsMarkdown: () => {
- const entries = get().entries
+ const entries = get().entries.filter(e => !e.sensitive)
if (entries.length === 0) return '# Memory\n\nNo entries yet.\n'
const typeOrder: MemoryType[] = ['user', 'feedback', 'project', 'reference']
@@ -890,6 +892,7 @@ export const useMemoryStore = create<MemoryState>()(
createdAt: asNumber(prop(e, 'createdAt')) ?? now,
updatedAt: now,
source: asString(prop(e, 'source')) ?? 'import',
+ sensitive: prop(e, 'sensitive') === true,
})
}
if (newEntries.length > 0) {
diff --git a/src/types/agent-mode.ts b/src/types/agent-mode.ts
index 9a2ccdbb..af7137cb 100644
--- a/src/types/agent-mode.ts
+++ b/src/types/agent-mode.ts
@@ -164,6 +164,8 @@ export interface MemoryFile {
createdAt: number
updatedAt: number
source: string // conversationId | 'manual' | 'auto:extraction'
+ /** User-marked sensitive entries stay out of AI requests and embeddings. */
+ sensitive?: boolean
// ── Staleness / supersession (Feature FF, v2.5.0) ─────────────
// All OPTIONAL so pre-v2.5 persisted memories rehydrate unchanged; the
// store's migrate() leaves them undefined and the retrieval layer treats