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): eckige Klammern am Ende eines Inhalts ueberleben den Import

purplee16d71aee960
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
index 9f837b5b..8bac822e 100644
--- 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
@@ -118,6 +118,45 @@ describe('der eigene Markdown-Export laesst sich wieder einlesen', () => {
expect(zurueck.source).toBe('david')
})
+ // R2-35: der Importausdruck las die Klammergruppe direkt hinter dem Inhalt,
+ // also verlor jeder Inhalt, der auf eine Klammergruppe endet, sie an die
+ // Marken. Der Weg dorthin war der eigene Export, deshalb steht der Fall hier
+ // beim Rundlauf und nicht bei den Bestandteilen.
+ it('HAUPTFALL R2-35: ein Inhalt, der auf eckige Klammern endet, ueberlebt den Rundlauf', () => {
+ const mitKlammer: MemoryFile = { ...EINTRAG, tags: [], title: 'Startbefehl', content: 'Start the app with [debug]' }
+ const [zurueck] = rundlauf([mitKlammer])
+
+ expect(zurueck.content).toBe('Start the app with [debug]')
+ expect(zurueck.tags).toEqual([])
+ })
+
+ it('R2-35: eine von Hand geschriebene Zeile, die auf Klammern endet, behaelt sie', () => {
+ leerenUndSetzen([])
+ expect(useMemoryStore.getState().importFromMarkdown('## User\n\n- Start the app with [debug]\n').added).toBe(1)
+ const [zurueck] = useMemoryStore.getState().entries
+ expect(zurueck.content).toBe('Start the app with [debug]')
+ expect(zurueck.tags).toEqual([])
+ })
+
+ it('NEGATIVKONTROLLE R2-35: echte Marken werden weiter zerlegt, auch neben einem Klammerinhalt', () => {
+ // Die Sperre darf die Marken nicht mitnehmen: eine Zeile mit Quelle traegt
+ // ihre Marken weiterhin, und sie tut es auch dann, wenn der Inhalt selbst
+ // auf eine Klammergruppe endet.
+ const mitBeidem: MemoryFile = { ...EINTRAG, title: 'Startbefehl', content: 'Start the app with [debug]' }
+ const [zurueck] = rundlauf([mitBeidem])
+
+ expect(zurueck.content).toBe('Start the app with [debug]')
+ expect(zurueck.tags).toEqual(['sprache', 'wichtig'])
+ })
+
+ it('NEGATIVKONTROLLE R2-35: Klammern mitten im Satz bleiben unberuehrt', () => {
+ leerenUndSetzen([])
+ expect(useMemoryStore.getState().importFromMarkdown('## User\n\n- Array syntax is a[0] and b[1]\n').added).toBe(1)
+ const [zurueck] = useMemoryStore.getState().entries
+ expect(zurueck.content).toBe('Array syntax is a[0] and b[1]')
+ expect(zurueck.tags).toEqual([])
+ })
+
it('POSITIVKONTROLLE: der schlichte Strichpunkt ohne Auszeichnung geht auch ein', () => {
leerenUndSetzen([])
expect(useMemoryStore.getState().importFromMarkdown('## User\n\n- Ein blanker Satz ohne alles\n').added).toBe(1)
diff --git a/src/stores/memoryStore.ts b/src/stores/memoryStore.ts
index 756fdd1e..9c7b307c 100644
--- a/src/stores/memoryStore.ts
+++ b/src/stores/memoryStore.ts
@@ -552,9 +552,22 @@ export function migrateMemoryState(persistedState: unknown, version: number): Me
* 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.
+ *
+ * WHY THE TAG GROUP SITS INSIDE THE SOURCE GROUP. It used to hang free right
+ * behind the lazy content, so any line that merely ENDED in a bracket group lost
+ * it: `- Start the app with [debug]` came back as the content `Start the app
+ * with` plus a tag `debug` nobody ever set. The bracket group is now only read
+ * when the `*(source)*` group follows it, which is the only shape this app's own
+ * export writes. A bracket at the end of a bare line stays part of the content.
+ *
+ * The remaining ambiguity is a content that ends in a bracket group AND carries a
+ * source. `exportAsMarkdown` resolves it from the writing side: when there are no
+ * tags and the content ends in `]`, it writes an empty group `[]`, so the tag
+ * slot is always occupied and the content keeps its own bracket. That is why the
+ * group accepts an EMPTY body.
*/
const MD_ITEM =
- /^-\s+(?:\*\*(.+?)\*\*\s*(?:,|[\u2013\u2014])\s*)?(.+?)(?:\s+\[([^\]]+)\])?(?:\s+\*\(([^)]+)\)\*(?:\s*(?:,|[\u2013\u2014])\s*(.+?))?)?$/
+ /^-\s+(?:\*\*(.+?)\*\*\s*(?:,|[\u2013\u2014])\s*)?(.+?)(?:(?:\s+\[([^\]]*)\])?\s+\*\(([^)]+)\)\*(?:\s*(?:,|[\u2013\u2014])\s*(.+?))?)?$/
/**
* The date the export writes: `YYYY-MM-DD`, not a locale string.
@@ -968,6 +981,10 @@ export const useMemoryStore = create<MemoryState>()(
const date = isoTag(entry.updatedAt)
md += `- **${entry.title}**, ${entry.content}`
if (entry.tags.length > 0) md += ` [${entry.tags.join(', ')}]`
+ // A content that ends in a bracket group would otherwise read back
+ // as a tag list on import. The empty group occupies the tag slot,
+ // so the content keeps its own bracket. See MD_ITEM.
+ else if (entry.content.endsWith(']')) md += ' []'
md += ` *(${entry.source})*, ${date}\n`
}
md += '\n'