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.

fix(erinnerungen): das Anlegen-Formular verschluckt die Eingabe nicht mehr

purple9df410275b60
diff --git a/src/components/settings/MemorySettings.tsx b/src/components/settings/MemorySettings.tsx
index 75fb9c9e..598d1574 100644
--- a/src/components/settings/MemorySettings.tsx
+++ b/src/components/settings/MemorySettings.tsx
@@ -230,7 +230,7 @@ function MemorySettingsPanel() {
// so the Save button never looks broken.
if (!newTitle.trim()) { setAddError('Add a title.'); return }
if (!newContent.trim()) { setAddError('Add some details.'); return }
- useMemoryStore.getState().addMemory({
+ const id = useMemoryStore.getState().addMemory({
type: 'user',
title: newTitle.trim().substring(0, 60),
description: newContent.trim().substring(0, 120),
@@ -240,6 +240,11 @@ function MemorySettingsPanel() {
sensitive: newSensitive,
scope: useProject ? conversation?.memoryScope : undefined,
})
+ // An empty id means the store refused the record, and the only reason left
+ // after the two checks above is a memory that is already there. Saying so
+ // beats clearing the fields and closing the form, which is what this did
+ // until R5-32: the text was gone and the page looked like it had saved.
+ if (!id) { setAddError('This memory is already saved.'); return }
setNewTitle('')
setNewContent('')
setNewSensitive(false)
diff --git a/src/components/settings/__tests__/das-erinnerungsformular-verschluckt-nichts.test.tsx b/src/components/settings/__tests__/das-erinnerungsformular-verschluckt-nichts.test.tsx
new file mode 100644
index 00000000..b120e1c0
--- /dev/null
+++ b/src/components/settings/__tests__/das-erinnerungsformular-verschluckt-nichts.test.tsx
@@ -0,0 +1,117 @@
+// @vitest-environment jsdom
+/**
+ * R5-32: was der Kunde ins Erinnerungsformular tippt, verschwindet nicht stumm.
+ *
+ * Zwei Haelften desselben Fundes, und beide kommen beim Kunden an:
+ *
+ * 1. `addMemory` sperrte gegen JEDEN inhaltsgleichen Eintrag, auch gegen
+ * einen veralteten, einen abgeloesten und einen mit der anderen Marke.
+ * Das sind genau die Datensaetze, die der Kunde in der Liste nicht mehr
+ * sieht, also wurde er gegen einen Zwilling abgewiesen, den es fuer ihn
+ * nicht gibt. Das Web hat die drei Bedingungen schon
+ * (apps/web/stores/memoryStore.ts:356-357).
+ * 2. Die Aufrufstelle las den Rueckgabewert nicht. Bei einer Abweisung
+ * leerte sie trotzdem beide Felder und schloss das Formular, also sah die
+ * Oberflaeche aus wie nach einem erfolgreichen Speichern, waehrend der
+ * Text weg war.
+ *
+ * Run: npx vitest run src/components/settings/__tests__/das-erinnerungsformular-verschluckt-nichts.test.tsx
+ */
+import { beforeEach, describe, expect, it } from 'vitest'
+import { cleanup, fireEvent, render, screen } from '@testing-library/react'
+import { useMemoryStore, __setMemoryEmbedFn } from '../../../stores/memoryStore'
+import type { MemoryFile } from '../../../types/agent-mode'
+import { MemorySettings } from '../MemorySettings'
+
+const ZWILLING: MemoryFile = {
+ id: 'zwilling',
+ type: 'user',
+ title: 'Arbeitet auf Deutsch',
+ description: 'Der Kunde schreibt auf Deutsch',
+ content: 'Der Kunde schreibt auf Deutsch.',
+ tags: [],
+ source: 'manual',
+ createdAt: 1,
+ updatedAt: 1,
+}
+
+const store = () => useMemoryStore.getState()
+
+/** Das Formular oeffnen und beide Felder fuellen, wie ein Kunde es tut. */
+function tippen(titel: string, inhalt: string) {
+ fireEvent.click(screen.getByText('Add Memory'))
+ fireEvent.change(screen.getByPlaceholderText('What should I remember?'), { target: { value: titel } })
+ fireEvent.change(screen.getByPlaceholderText('Details… (required)'), { target: { value: inhalt } })
+ fireEvent.click(screen.getByText('Save'))
+}
+
+beforeEach(() => {
+ cleanup()
+ __setMemoryEmbedFn(async () => [])
+ useMemoryStore.setState({ entries: [], localEntries: [], activeMemoryOwner: null })
+})
+
+describe('das Erinnerungsformular', () => {
+ it('HAUPTFALL: ein veralteter Zwilling blockiert die Neuaufnahme nicht mehr', () => {
+ useMemoryStore.setState({ entries: [{ ...ZWILLING, stale: true }] })
+ render(<MemorySettings />)
+
+ tippen('Arbeitet auf Deutsch', ZWILLING.content)
+
+ expect(store().entries.filter((e) => !e.stale)).toHaveLength(1)
+ expect(store().entries.filter((e) => !e.stale)[0].content).toBe(ZWILLING.content)
+ })
+
+ it('HAUPTFALL: ein abgeloester Zwilling blockiert die Neuaufnahme nicht mehr', () => {
+ useMemoryStore.setState({ entries: [{ ...ZWILLING, supersededBy: 'neuer' }] })
+ render(<MemorySettings />)
+
+ tippen('Arbeitet auf Deutsch', ZWILLING.content)
+
+ expect(store().entries).toHaveLength(2)
+ })
+
+ it('HAUPTFALL: ein sensibel markierter Zwilling ist ein anderer Datensatz', () => {
+ useMemoryStore.setState({ entries: [{ ...ZWILLING, sensitive: true }] })
+ render(<MemorySettings />)
+
+ tippen('Arbeitet auf Deutsch', ZWILLING.content)
+
+ expect(store().entries).toHaveLength(2)
+ expect(store().entries.filter((e) => e.sensitive === true)).toHaveLength(1)
+ })
+
+ it('NEGATIVKONTROLLE: ein wirklich gleicher Eintrag wird weiter abgewiesen', () => {
+ useMemoryStore.setState({ entries: [ZWILLING] })
+ render(<MemorySettings />)
+
+ tippen('Arbeitet auf Deutsch', ZWILLING.content)
+
+ expect(store().entries).toHaveLength(1)
+ })
+
+ it('NEGATIVKONTROLLE: und der Kunde liest jetzt, warum, statt in ein leeres Feld zu sehen', () => {
+ useMemoryStore.setState({ entries: [ZWILLING] })
+ render(<MemorySettings />)
+
+ tippen('Arbeitet auf Deutsch', ZWILLING.content)
+
+ expect(screen.getByText('This memory is already saved.')).toBeTruthy()
+ // Das Formular steht noch offen und haelt den Text, den der Kunde getippt
+ // hat. Genau das ging vorher verloren.
+ expect((screen.getByPlaceholderText('What should I remember?') as HTMLInputElement).value)
+ .toBe('Arbeitet auf Deutsch')
+ expect((screen.getByPlaceholderText('Details… (required)') as HTMLTextAreaElement).value)
+ .toBe(ZWILLING.content)
+ })
+
+ it('POSITIVKONTROLLE: ohne Zwilling speichert das Formular und raeumt sich auf', () => {
+ render(<MemorySettings />)
+
+ tippen('Neue Sache', 'Etwas, das noch nicht in der Sammlung steht.')
+
+ expect(store().entries).toHaveLength(1)
+ expect(screen.queryByPlaceholderText('What should I remember?')).toBeNull()
+ expect(screen.getByText('Add Memory')).toBeTruthy()
+ })
+})
diff --git a/src/stores/memoryStore.ts b/src/stores/memoryStore.ts
index 9c7b307c..b1ceec28 100644
--- a/src/stores/memoryStore.ts
+++ b/src/stores/memoryStore.ts
@@ -645,9 +645,19 @@ export const useMemoryStore = create<MemoryState>()(
const trimmedContent = memory.content.trim()
if (!trimmedContent) return ''
- // Deduplicate: don't add if the same memory is already in the collection
+ // Deduplicate: don't add if the same memory is already in the collection.
+ //
+ // The three extra conditions are the web's (R5-32), and each one is a
+ // record the user can no longer reach: an outdated twin, one that a
+ // newer record superseded, and one that is marked sensitive while this
+ // one is not (or the other way round, which is a different record to
+ // the app). Without them the form refused an entry against a twin the
+ // collection no longer shows, and the caller reads the empty id, so the
+ // user gets told why instead of watching the input vanish.
const candidate = { content: trimmedContent, type: memory.type, scope: memory.scope }
- if (get().entries.some(e => isSameMemory(e, candidate))) return ''
+ if (get().entries.some(e => isSameMemory(e, candidate) &&
+ (e.sensitive === true) === (memory.sensitive === true) &&
+ !e.stale && !e.supersededBy)) return ''
const id = uuid()
set((state) => ({