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.
TypeScript agentai-chatai-studioall-in-onecoding-agentdesktop-appfluximage-generationlinuxllmlocal-ailocal-llmopen-sourceprivacyself-hostedstable-diffusionuncensoreduncensored-aivideo-generationwindows
Preserve memory provenance and explicit review state
David1507c715d4bc
diff --git a/e2e/memory-review.spec.ts b/e2e/memory-review.spec.tsnew file mode 100644index 00000000..9c422edf--- /dev/null+++ b/e2e/memory-review.spec.ts@@ -0,0 +1,19 @@+import { expect, test } from '@playwright/test'+test('explicit review survives reload and editing clears it', 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('Review proof')+ await page.getByPlaceholder('Details… (required)').fill('Synthetic review fact')+ await page.getByRole('button', { name: 'Save', exact: true }).click()+ await expect(page.getByText('Source: manual', { exact: true })).toBeVisible()+ await expect(page.getByText('Not reviewed', { exact: true })).toBeVisible()+ await page.getByRole('button', { name: 'Confirm reviewed' }).click()+ await expect(page.getByText(/^Reviewed:/)).toBeVisible()+ await page.reload()+ await expect(page.getByText(/^Reviewed:/)).toBeVisible()+ await page.screenshot({ path: testInfo.outputPath('memory-review.png') })+ await page.getByRole('button', { name: 'Edit entry' }).click()+ await page.locator('textarea').fill('Updated review fact')+ await page.getByRole('button', { name: 'Save', exact: true }).click()+ await expect(page.getByText('Not reviewed', { exact: true })).toBeVisible()+})diff --git a/src/components/chat/MemorySources.tsx b/src/components/chat/MemorySources.tsxindex 35b4e378..9608758f 100644--- a/src/components/chat/MemorySources.tsx+++ b/src/components/chat/MemorySources.tsx@@ -22,6 +22,7 @@ export function MemorySources({ sources }: { sources: Message['memorySources'] }<span className="font-medium">{entry.title}</span><p>{origin ? `Chat: ${origin.title}` : entry.source === 'manual' ? 'Manual entry' : 'Original source unavailable'}</p>{entry.scope && <p>Project: {entry.scope}</p>}+ {entry.sourceKind && <p>Source type: {entry.sourceKind}</p>}</li>})}</ul>diff --git a/src/components/settings/MemorySettings.tsx b/src/components/settings/MemorySettings.tsxindex da16e713..a30f7fca 100644--- a/src/components/settings/MemorySettings.tsx+++ b/src/components/settings/MemorySettings.tsx@@ -430,7 +430,7 @@ export function MemorySettings() {<div className={`w-1.5 h-1.5 rounded-full mt-1.5 shrink-0 ${TYPE_DOT_COLORS[entry.type]}`} /><div className="flex-1 min-w-0"><div className="flex items-center gap-1.5">- <p className="text-[0.65rem] font-medium text-gray-200 truncate">{entry.title}</p>+ <p className="text-[0.65rem] font-medium text-gray-800 dark:text-gray-200 truncate">{entry.title}</p>{stale && (<span className="flex items-center gap-0.5 text-[0.45rem] uppercase tracking-wider text-gray-500 border border-gray-600/40 rounded px-1 py-px shrink-0" title="Outdated, kept for reference, not injected into prompts"><Archive size={8} /> outdated@@ -439,6 +439,9 @@ export function MemorySettings() {</div><p className="text-[0.6rem] text-gray-500 break-words line-clamp-2">{entry.content}</p>{entry.scope !== undefined && <p className="text-xs text-gray-500 break-words">Project: {entry.scope}</p>}+ <p className="text-xs text-gray-500">Source: {entry.sourceKind ?? (entry.source === 'manual' ? 'manual' : 'unknown')}</p>+ <p className="text-xs text-gray-500">{entry.confirmedAt ? `Reviewed: ${new Date(entry.confirmedAt).toLocaleString('en-US')}` : 'Not reviewed'}</p>+ {!stale && <button className="text-xs text-gray-500 underline" onClick={() => useMemoryStore.getState().confirmMemory(entry.id)}>Confirm reviewed</button>}<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 })} />diff --git a/src/hooks/__tests__/memory-silent-call-gate.test.ts b/src/hooks/__tests__/memory-silent-call-gate.test.tsindex 7d3f9983..2162043f 100644--- a/src/hooks/__tests__/memory-silent-call-gate.test.ts+++ b/src/hooks/__tests__/memory-silent-call-gate.test.ts@@ -122,19 +122,30 @@ beforeEach(() => {})describe('project extraction isolation', () => {+ it('preserves project and modality when the first write fails', async () => {+ activeModel = 'qwen3:8b'+ addMemory.mockImplementationOnce(() => { throw new Error('Synthetic write failure') })+ chatStream.mockImplementation(() => (async function* () {+ yield { content: JSON.stringify({ shouldSave: true, memories: [{ type: 'project', title: 'A fact', description: 'Synthetic fact', content: 'Synthetic project fact', tags: [] }] }), done: true }+ })())+ for (let i = 0; i < RATE_LIMIT; i++) await extractMemoriesFromPair('question', LONG_REPLY, 'conv-a', { scope: 'A', sourceKind: 'screen' })+ expect(addMemory).toHaveBeenCalledTimes(2)+ expect(addMemory).toHaveBeenLastCalledWith(expect.objectContaining({ scope: 'A', source: 'conv-a', sourceKind: 'screen' }))+ })it('writes extracted facts to the captured project even if the caller changes its options', async () => {activeModel = 'qwen3:8b'chatStream.mockImplementation(() => (async function* () {yield { content: JSON.stringify({ shouldSave: true, memories: [{ type: 'project', title: 'A fact', description: 'Synthetic fact', content: 'Synthetic project fact', tags: [] }] }), done: true }})())for (let i = 0; i < RATE_LIMIT; i++) {- const options = { scope: 'A' }+ const options: { scope: string; sourceKind: MemoryFile['sourceKind'] } = { scope: 'A', sourceKind: 'voice' }const pending = extractMemoriesFromPair('question', LONG_REPLY, 'conv-a', options)options.scope = 'B'+ options.sourceKind = 'screen'await pending}expect(addMemory).toHaveBeenCalledTimes(1)- expect(addMemory).toHaveBeenCalledWith(expect.objectContaining({ scope: 'A', source: 'conv-a' }))+ expect(addMemory).toHaveBeenCalledWith(expect.objectContaining({ scope: 'A', source: 'conv-a', sourceKind: 'voice' }))})it('does not send sensitive or other-project titles to the extraction provider', async () => {activeModel = 'qwen3:8b'diff --git a/src/hooks/useMemory.ts b/src/hooks/useMemory.tsindex 954e1e51..71b443bb 100644--- a/src/hooks/useMemory.ts+++ b/src/hooks/useMemory.ts@@ -83,9 +83,10 @@ export async function extractMemoriesFromPair(userMessage: string,assistantResponse: string,conversationId: string,- options?: { scope?: string },+ options?: { scope?: string; sourceKind?: MemoryFile['sourceKind'] },): Promise<void> {const scope = options?.scope+ const sourceKind = options?.sourceKind ?? 'chat'try {const { activeModel } = useModelStore.getState()if (!activeModel) return@@ -154,7 +155,7 @@ export async function extractMemoriesFromPair(// we don't fire N concurrent inferences. Each is wrapped so one bad// memory never aborts the rest.try {- await resolveAndSaveMemory(memory, conversationId, scope)+ await resolveAndSaveMemory(memory, conversationId, scope, sourceKind)} catch {// Per-memory failure → fall back to a plain add so the fact isn't lost.memState.addMemory({@@ -164,6 +165,8 @@ export async function extractMemoriesFromPair(content: memory.content,tags: memory.tags,source: conversationId,+ scope,+ sourceKind,})}}@@ -185,7 +188,7 @@ export async function extractMemoriesFromPair(* Fire-and-forget contract: any embedding/LLM failure falls back to a plain* addMemory so a fact is never silently dropped. Never blocks the chat turn.*/-async function resolveAndSaveMemory(memory: ExtractedMemory, conversationId: string, scope?: string): Promise<void> {+async function resolveAndSaveMemory(memory: ExtractedMemory, conversationId: string, scope?: string, sourceKind?: MemoryFile['sourceKind']): Promise<void> {const memState = useMemoryStore.getState()const addPlain = (): string =>memState.addMemory({@@ -195,6 +198,7 @@ async function resolveAndSaveMemory(memory: ExtractedMemory, conversationId: strcontent: memory.content,tags: memory.tags,source: conversationId,+ sourceKind,scope,})diff --git a/src/stores/__tests__/memory-provenance.test.ts b/src/stores/__tests__/memory-provenance.test.tsnew file mode 100644index 00000000..1ef66c41--- /dev/null+++ b/src/stores/__tests__/memory-provenance.test.ts@@ -0,0 +1,45 @@+import { afterEach, beforeEach, expect, it } from 'vitest'+import { useMemoryStore, __setMemoryEmbedFn } from '../memoryStore'+beforeEach(() => { useMemoryStore.setState({ entries: [] }); __setMemoryEmbedFn(async () => []) })+afterEach(() => __setMemoryEmbedFn())+const add = (content = 'Synthetic fact') => useMemoryStore.getState().addMemory({+ type: 'user', title: 'Fact', description: content, content, tags: [], source: 'original-chat', sourceKind: 'voice', scope: 'p',+})+it('records explicit review, retains it for privacy changes and clears it when the fact changes', () => {+ const id = add()+ const store = useMemoryStore.getState()+ expect(store.entries).toHaveLength(1)+ expect(store.entries[0].confirmedAt).toBeUndefined()+ store.confirmMemory(id)+ const reviewed = useMemoryStore.getState().entries[0].confirmedAt+ expect(reviewed).toBeGreaterThan(0)+ store.updateMemory(id, { sensitive: true })+ expect(useMemoryStore.getState().entries[0].confirmedAt).toBe(reviewed)+ store.updateMemory(id, { content: 'Changed fact' })+ expect(useMemoryStore.getState().entries[0].confirmedAt).toBeUndefined()+ store.confirmMemory(id)+ store.updateMemory(id, { scope: 'different-project' })+ expect(useMemoryStore.getState().entries[0].confirmedAt).toBeUndefined()+})+it('clears human review after an automatic merge and cannot confirm outdated entries', () => {+ const targetId = add()+ const newId = add('New fact')+ useMemoryStore.getState().confirmMemory(targetId)+ useMemoryStore.getState().applyWriteDecision({ action: 'UPDATE', targetId, mergedContent: 'Merged fact' }, { newId })+ useMemoryStore.getState().confirmMemory(newId)+ expect(useMemoryStore.getState().entries.every(entry => entry.confirmedAt === undefined)).toBe(true)+})+it('round trips source identity, modality and review through JSON without inventing legacy metadata', () => {+ const id = add()+ useMemoryStore.getState().confirmMemory(id)+ const original = useMemoryStore.getState().entries[0]+ const json = useMemoryStore.getState().exportAsJSON()+ useMemoryStore.getState().clearAll()+ expect(useMemoryStore.getState().importFromJSON(json)).toBe(1)+ expect(useMemoryStore.getState().entries[0]).toMatchObject({ source: original.source, sourceKind: 'voice', confirmedAt: original.confirmedAt })+ useMemoryStore.getState().importFromJSON(JSON.stringify([{ content: 'Legacy fact' }, { content: 'Invalid metadata', sourceKind: 'forged', confirmedAt: 1e99 }]))+ for (const entry of useMemoryStore.getState().entries.slice(1)) {+ expect(entry.sourceKind).toBeUndefined()+ expect(entry.confirmedAt).toBeUndefined()+ }+})diff --git a/src/stores/memoryStore.ts b/src/stores/memoryStore.tsindex e5c56617..24d25522 100644--- a/src/stores/memoryStore.ts+++ b/src/stores/memoryStore.ts@@ -277,6 +277,7 @@ interface MemoryState {addMemory: (memory: Omit<MemoryFile, 'id' | 'createdAt' | 'updatedAt'>) => stringupdateMemory: (id: string, updates: Partial<Pick<MemoryFile, 'title' | 'description' | 'content' | 'type' | 'tags' | 'sensitive' | 'scope'>>) => voidremoveMemory: (id: string) => void+ confirmMemory: (id: string) => voidclearAll: () => void// Search & Inject@@ -414,6 +415,8 @@ function asMemoryFile(v: unknown): MemoryFile | null {createdAt: asNumber(v.createdAt) ?? now,updatedAt: asNumber(v.updatedAt) ?? asNumber(v.createdAt) ?? now,source: asString(v.source) ?? 'migration',+ sourceKind: v.sourceKind === 'chat' || v.sourceKind === 'voice' || v.sourceKind === 'screen' ? v.sourceKind : undefined,+ confirmedAt: typeof v.confirmedAt === 'number' && Number.isFinite(v.confirmedAt) && v.confirmedAt > 0 && v.confirmedAt <= now ? v.confirmedAt : undefined,sensitive: v.sensitive === true,scope: asString(v.scope),supersededBy: asString(v.supersededBy),@@ -541,7 +544,9 @@ export const useMemoryStore = create<MemoryState>()(if (updates.scope !== undefined && !updates.scope.trim()) returnset((state) => ({entries: state.entries.map((e) =>- e.id === id ? { ...e, ...updates, updatedAt: Date.now() } : e+ e.id === id ? { ...e, ...updates, updatedAt: Date.now(),+ confirmedAt: Object.keys(updates).some(key => key !== 'sensitive' && Reflect.get(e, key) !== Reflect.get(updates, key)) ? undefined : e.confirmedAt,+ } : e),lastSynced: Date.now(),}))@@ -553,6 +558,12 @@ export const useMemoryStore = create<MemoryState>()(}},+ confirmMemory: (id) => {+ const now = Date.now()+ set(state => ({ entries: state.entries.map(entry => entry.id === id && !isStale(entry)+ ? { ...entry, confirmedAt: now, updatedAt: now } : entry), lastSynced: now }))+ },+removeMemory: (id) => {set((state) => ({entries: state.entries.filter((e) => e.id !== id),@@ -737,6 +748,7 @@ export const useMemoryStore = create<MemoryState>()(return {...e,content: merged,+ confirmedAt: undefined,description: merged.substring(0, 120),updatedAt: now,validFrom: now,@@ -920,6 +932,8 @@ export const useMemoryStore = create<MemoryState>()(const content = (asString(prop(e, 'content')) ?? asString(prop(e, 'text')) ?? asString(prop(e, 'value')) ?? '').trim()if (!content) continueconst type = MEMORY_TYPES.find((t) => t === prop(e, 'type')) ?? 'user'+ const sourceKind = prop(e, 'sourceKind')+ const confirmedAt = prop(e, 'confirmedAt')newEntries.push({// Always mint a fresh id so a re-imported export can never collide// with an existing entry's id (which broke edit/remove-by-id).@@ -932,6 +946,8 @@ export const useMemoryStore = create<MemoryState>()(createdAt: asNumber(prop(e, 'createdAt')) ?? now,updatedAt: now,source: asString(prop(e, 'source')) ?? 'import',+ sourceKind: sourceKind === 'chat' || sourceKind === 'voice' || sourceKind === 'screen' ? sourceKind : undefined,+ confirmedAt: typeof confirmedAt === 'number' && Number.isFinite(confirmedAt) && confirmedAt > 0 && confirmedAt <= now ? confirmedAt : undefined,sensitive: prop(e, 'sensitive') === true,scope: asString(scope),})diff --git a/src/types/agent-mode.ts b/src/types/agent-mode.tsindex 893b4d3c..bce75f71 100644--- a/src/types/agent-mode.ts+++ b/src/types/agent-mode.ts@@ -164,6 +164,10 @@ export interface MemoryFile {createdAt: numberupdatedAt: numbersource: string // conversationId | 'manual' | 'auto:extraction'+ /** Input modality, separate from the legacy source conversation ID. */+ sourceKind?: 'chat' | 'voice' | 'screen'+ /** Explicit user review time; cleared when the remembered fact changes. */+ confirmedAt?: number/** User-marked sensitive entries stay out of AI requests and embeddings. */sensitive?: boolean/** Stable project ID. Undefined retains legacy global memory behavior. */