Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions desktop/windows/src/main/memoryImport/parse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,23 @@ describe('parseMemoryDump', () => {
])
})

it('handles common pasted markdown list markers', () => {
const dump = `— Enjoys tea
‣ Uses Windows
⁃ Keeps notes in Obsidian`
expect(parseMemoryDump(dump)).toEqual(['Enjoys tea', 'Uses Windows', 'Keeps notes in Obsidian'])
})

it('handles numbered lists', () => {
const dump = `1. Lives in Seattle\n2) Is learning Spanish`
expect(parseMemoryDump(dump)).toEqual(['Lives in Seattle', 'Is learning Spanish'])
})

it('drops markdown code fences around copied dumps', () => {
const dump = '```markdown\n- Likes coffee\n- Prefers short replies\n```'
expect(parseMemoryDump(dump)).toEqual(['Likes coffee', 'Prefers short replies'])
})

it('drops conversational scaffolding but keeps real memories', () => {
const dump = `Sure! Here are your saved memories:
- Has a dog
Expand Down
10 changes: 8 additions & 2 deletions desktop/windows/src/main/memoryImport/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ const SCAFFOLDING = [
/^i (?:currently )?(?:remember|have stored|don'?t have)\b.*(?:memor|the following|about you)/i
]

// Remove a single leading list marker: -, *, •, –, or "1." / "1)".
// Remove a single leading list marker: -, *, common bullet/dash markers,
// or "1." / "1)".
function stripMarker(line: string): string {
return line.replace(/^\s*(?:[-*•–]\s+|\d+[.)]\s+)/, '')
return line.replace(/^\s*(?:[-*\u2022\u2013\u2014\u2023\u2043]\s+|\d+[.)]\s+)/, '')
}

// Strip surrounding markdown emphasis / heading syntax.
Expand All @@ -34,10 +35,15 @@ function stripFormatting(s: string): string {
return t.trim()
}

function isMarkdownFence(line: string): boolean {
return /^\s*(?:```|~~~)/.test(line)
}

export function parseMemoryDump(dump: string): string[] {
const out: string[] = []
const seen = new Set<string>()
for (const raw of dump.split(/\r?\n/)) {
if (isMarkdownFence(raw)) continue
const stripped = stripFormatting(stripMarker(raw))
if (stripped.length < 3) continue // blank lines, stray numbering/punctuation
if (SCAFFOLDING.some((re) => re.test(stripped))) continue
Expand Down
Loading