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) die App liest ihren eigenen Markdown-Export wieder

Davide4958b379bb4
diff --git a/src/stores/__tests__/der-eigene-export-liest-sich-wieder-ein.test.ts b/src/stores/__tests__/der-eigene-export-liest-sich-wieder-ein.test.ts
new file mode 100644
index 00000000..7803a9ac
--- /dev/null
+++ b/src/stores/__tests__/der-eigene-export-liest-sich-wieder-ein.test.ts
@@ -0,0 +1,126 @@
+/**
+ * Die App muss ihren eigenen Erinnerungs-Export wieder lesen koennen.
+ *
+ * Der Anlass, am 05.09.2026 am Quelltext nachgeschlagen: der Strich-Sweep
+ * `01a352bf` (25.07.2026) hat im Export das Trennzeichen zwischen Titel und
+ * Inhalt von einem langen Strich auf ein Komma umgestellt. Der Ausdruck im
+ * Import verlangte weiter den Strich. Seitdem kam beim Zurueckladen des
+ * eigenen Exports der Titel als `**Titel**, Inhalt ...` an, und Marken, Quelle
+ * und Datum fielen ersatzlos weg.
+ *
+ * Gefunden hat es niemand, weil der einzige vorhandene Test den Import mit dem
+ * ALTEN Format von Hand fuetterte (`stores.test.ts`) und kein Test je das
+ * Ergebnis von `exportAsMarkdown` durch `importFromMarkdown` schickte. Genau
+ * diese Luecke schliesst diese Datei: sie prueft den RUNDLAUF, nicht die
+ * Bestandteile.
+ *
+ * Run: npx vitest run src/stores/__tests__/der-eigene-export-liest-sich-wieder-ein.test.ts
+ */
+import { describe, it, expect, beforeEach } from 'vitest'
+import { useMemoryStore } from '../memoryStore'
+import type { MemoryFile } from '../../types/agent-mode'
+
+const EINTRAG: MemoryFile = {
+ id: 'rundlauf-1',
+ type: 'user',
+ title: 'Arbeitet auf Deutsch',
+ content: 'Der Kunde schreibt und liest auf Deutsch, erwartet aber englische Fehlermeldungen, und das gilt auch fuer lange Saetze mit Komma.',
+ description: 'Der Kunde schreibt und liest auf Deutsch',
+ tags: ['sprache', 'wichtig'],
+ source: 'david',
+ createdAt: Date.UTC(2026, 6, 14),
+ updatedAt: Date.UTC(2026, 6, 14),
+}
+
+function leerenUndSetzen(eintraege: MemoryFile[]) {
+ useMemoryStore.setState({ entries: eintraege })
+}
+
+function rundlauf(eintraege: MemoryFile[]): MemoryFile[] {
+ leerenUndSetzen(eintraege)
+ const md = useMemoryStore.getState().exportAsMarkdown()
+ leerenUndSetzen([])
+ const zahl = useMemoryStore.getState().importFromMarkdown(md)
+ expect(zahl).toBe(eintraege.length)
+ return useMemoryStore.getState().entries
+}
+
+beforeEach(() => {
+ leerenUndSetzen([])
+})
+
+describe('der eigene Markdown-Export laesst sich wieder einlesen', () => {
+ it('HAUPTFALL: Titel, Inhalt, Marken und Quelle kommen unveraendert zurueck', () => {
+ const [zurueck] = rundlauf([EINTRAG])
+
+ expect(zurueck.title).toBe('Arbeitet auf Deutsch')
+ expect(zurueck.content).toBe(EINTRAG.content)
+ expect(zurueck.tags).toEqual(['sprache', 'wichtig'])
+ expect(zurueck.source).toBe('david')
+ expect(zurueck.type).toBe('user')
+ })
+
+ it('HAUPTFALL: der Titel ist NICHT die ganze rohe Zeile', () => {
+ // Genau das war der Schaden: der Titel wurde zu `**Titel**, Inhalt ...`,
+ // auf 60 Zeichen abgeschnitten, und der Inhalt trug die Auszeichnung mit.
+ const [zurueck] = rundlauf([EINTRAG])
+
+ expect(zurueck.title).not.toContain('**')
+ expect(zurueck.content).not.toContain('**')
+ expect(zurueck.content).not.toContain('*(david)*')
+ expect(zurueck.content).not.toContain('[sprache')
+ })
+
+ it('das Datum ueberlebt den Rundlauf, weil der Export es als ISO schreibt', () => {
+ const [zurueck] = rundlauf([EINTRAG])
+
+ expect(new Date(zurueck.updatedAt).toISOString().slice(0, 10)).toBe('2026-07-14')
+ expect(useMemoryStore.getState().exportAsMarkdown()).toContain('2026-07-14')
+ })
+
+ it('ein Komma im Inhalt bleibt ein Komma im Inhalt', () => {
+ const mitKomma: MemoryFile = { ...EINTRAG, tags: [], source: 'import', content: 'Erst dies, dann das, und zuletzt jenes.' }
+ const [zurueck] = rundlauf([mitKomma])
+
+ expect(zurueck.content).toBe('Erst dies, dann das, und zuletzt jenes.')
+ })
+
+ it('mehrere Eintraege ueber mehrere Abschnitte finden ihren Typ wieder', () => {
+ const zweiter: MemoryFile = { ...EINTRAG, id: 'rundlauf-2', type: 'feedback', title: 'Keine Striche', content: 'Nirgends ein langer Strich, auch nicht im Code.', tags: [], source: 'david' }
+ const zurueck = rundlauf([EINTRAG, zweiter])
+
+ expect(zurueck.map((e) => e.type).sort()).toEqual(['feedback', 'user'])
+ expect(zurueck.find((e) => e.type === 'feedback')?.title).toBe('Keine Striche')
+ })
+
+ it('TRENNKONTROLLE: der alte Export mit dem langen Strich geht weiterhin ein', () => {
+ // Wer seine Erinnerungen vor dem 25.07.2026 gesichert hat, haelt eine
+ // Datei im alten Format in der Hand. Die darf nicht kaputtgehen, nur weil
+ // das neue Format dazugekommen ist.
+ const alt = [
+ '# Memory',
+ '',
+ '## User',
+ '',
+ // Der lange Strich steht als Code-Punkt da, weil die Hausregel das
+ // Zeichen selbst aus dem Baum haelt. Die Zeile ist trotzdem exakt die,
+ // die der Export vor dem 25.07.2026 geschrieben hat.
+ `- **Arbeitet auf Deutsch** \u2014 ${EINTRAG.content} [sprache, wichtig] *(david)* \u2014 14.07.2026`,
+ '',
+ ].join('\n')
+
+ leerenUndSetzen([])
+ expect(useMemoryStore.getState().importFromMarkdown(alt)).toBe(1)
+ const [zurueck] = useMemoryStore.getState().entries
+ expect(zurueck.title).toBe('Arbeitet auf Deutsch')
+ expect(zurueck.content).toBe(EINTRAG.content)
+ expect(zurueck.tags).toEqual(['sprache', 'wichtig'])
+ expect(zurueck.source).toBe('david')
+ })
+
+ it('POSITIVKONTROLLE: der schlichte Strichpunkt ohne Auszeichnung geht auch ein', () => {
+ leerenUndSetzen([])
+ expect(useMemoryStore.getState().importFromMarkdown('## User\n\n- Ein blanker Satz ohne alles\n')).toBe(1)
+ expect(useMemoryStore.getState().entries[0].content).toBe('Ein blanker Satz ohne alles')
+ })
+})
diff --git a/src/stores/memoryStore.ts b/src/stores/memoryStore.ts
index e6f954e8..4aa0fb8a 100644
--- a/src/stores/memoryStore.ts
+++ b/src/stores/memoryStore.ts
@@ -413,6 +413,55 @@ export function migrateMemoryState(persistedState: unknown, version: number): Me
return state as MemoryState
}
+/**
+ * One line of the markdown export, taken apart again.
+ *
+ * WHY THIS IS A NAMED CONSTANT WITH A STORY. Until 2026-07-25 the export wrote
+ * the title, a long dash, then the content, and this expression required that
+ * dash. The dash sweep (01a352bf) changed the EXPORT to a comma and left the
+ * expression alone, so from 2.5.9 on the app could no longer read its own
+ * export: the title came back as `**Title**, content ...` and tags, source and
+ * date were dropped on the floor. Nobody noticed, because the only test fed the
+ * OLD format in by hand.
+ *
+ * The separator is therefore a comma OR one of the two old dashes, and those
+ * two are written as code points on purpose: the house rule bans the characters
+ * themselves from this tree, and a character class is no exception.
+ *
+ * The trailing date is only stripped when it follows the `*(source)*` group. A
+ * bare `content, with a comma` keeps its comma, because there is no source to
+ * anchor a date to.
+ */
+const MD_ITEM =
+ /^-\s+(?:\*\*(.+?)\*\*\s*(?:,|[\u2013\u2014])\s*)?(.+?)(?:\s+\[([^\]]+)\])?(?:\s+\*\(([^)]+)\)\*(?:\s*(?:,|[\u2013\u2014])\s*(.+?))?)?$/
+
+/**
+ * The date the export writes: `YYYY-MM-DD`, not a locale string.
+ *
+ * `toLocaleDateString()` produced `9/5/2026` on one machine and `05.09.2026` on
+ * the next, and neither is readable back, so an exported memory always came
+ * home stamped with today. Falls back to today when the entry carries a broken
+ * timestamp, because an export must not throw.
+ */
+function isoTag(ms: number): string {
+ const d = new Date(ms)
+ return Number.isNaN(d.getTime()) ? new Date().toISOString().slice(0, 10) : d.toISOString().slice(0, 10)
+}
+
+/**
+ * The way back. STRICT on purpose: only `YYYY-MM-DD` is read, never a locale
+ * string. `9/5/2026` is the ninth of May in one place and the fifth of
+ * September in another, and a memory dated a wrong day is worse than one dated
+ * today.
+ */
+function isoBack(tag: string | undefined): number | null {
+ const m = tag?.trim().match(/^(\d{4})-(\d{2})-(\d{2})$/)
+ if (!m) return null
+ const ms = Date.parse(`${m[1]}-${m[2]}-${m[3]}T00:00:00Z`)
+ return Number.isNaN(ms) ? null : ms
+}
+
+
// ── Store ─────────────────────────────────────────────────────
export const useMemoryStore = create<MemoryState>()(
@@ -726,7 +775,7 @@ export const useMemoryStore = create<MemoryState>()(
md += `## ${typeTitles[type]}\n\n`
for (const entry of typeEntries) {
- const date = new Date(entry.updatedAt).toLocaleDateString()
+ const date = isoTag(entry.updatedAt)
md += `- **${entry.title}**, ${entry.content}`
if (entry.tags.length > 0) md += ` [${entry.tags.join(', ')}]`
md += ` *(${entry.source})*, ${date}\n`
@@ -756,12 +805,13 @@ export const useMemoryStore = create<MemoryState>()(
continue
}
- const itemMatch = line.match(/^-\s+(?:\*\*(.+?)\*\*\s*—\s*)?(.+?)(?:\s+\[(.+?)\])?(?:\s+\*\((.+?)\)\*)?(?:\s+—\s+.+)?$/)
+ const itemMatch = line.match(MD_ITEM)
if (itemMatch) {
const title = itemMatch[1] || itemMatch[2].substring(0, 60)
const content = itemMatch[2].trim()
- const tags = itemMatch[3] ? itemMatch[3].split(',').map(t => t.trim()) : []
+ const tags = itemMatch[3] ? itemMatch[3].split(',').map(t => t.trim()).filter(Boolean) : []
const source = itemMatch[4] || 'import'
+ const stand = isoBack(itemMatch[5]) ?? Date.now()
if (content) {
newEntries.push({
@@ -771,8 +821,8 @@ export const useMemoryStore = create<MemoryState>()(
description: content.substring(0, 120),
content,
tags,
- createdAt: Date.now(),
- updatedAt: Date.now(),
+ createdAt: stand,
+ updatedAt: stand,
source,
})
}