forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse.ts
More file actions
69 lines (63 loc) · 2.79 KB
/
Copy pathparse.ts
File metadata and controls
69 lines (63 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Parse a pasted ChatGPT/Claude "memory dump" — the assistant's full response
// when asked to list everything it remembers — into individual memory strings.
// Mirrors the macOS import path: strip list markup + conversational scaffolding,
// dedupe, and keep the rest. The Settings UI shows the result for review before
// anything is sent to the backend, so erring toward keeping a line is safe.
// Opener/closer scaffolding lines that are not memories themselves. Kept tight
// so real third-person memory lines ("Has two cats", "Prefers concise answers")
// are never dropped.
const SCAFFOLDING = [
/^sure[,!. ]/i,
/^here(?:'s| is| are)\b.*\bmemor/i,
/^below (?:is|are)\b/i,
/^these are\b.*\bmemor/i,
/^(?:your |the )?saved memories\b/i,
/^(?:here are )?the (?:things|details) (?:i|that i) (?:remember|know)/i,
/^let me know\b/i,
/^(?:and )?that'?s (?:all|everything)\b/i,
/^is there anything\b/i,
/^i (?:currently )?(?:remember|have stored|don'?t have)\b.*(?:memor|the following|about you)/i,
// Omi's own export stamp ("_Exported <date> · N memories_", italics already
// stripped) — so a user who exports and re-imports doesn't inject it as a memory.
/^exported\s+\d{4}-\d{2}-\d{2}\b/i
]
// Remove a single leading list marker: -, *, common bullet/dash markers,
// or "1." / "1)".
function stripMarker(line: string): string {
return line.replace(/^\s*(?:[-*\u2022\u2013\u2014\u2023\u2043]\s+|\d+[.)]\s+)/, '')
}
// Strip surrounding markdown emphasis / heading syntax.
function stripFormatting(s: string): string {
let t = s.trim()
t = t.replace(/^#{1,6}\s+/, '') // markdown heading
t = t.replace(/^\*\*([\s\S]*)\*\*$/, '$1') // **bold**
t = t.replace(/^_([\s\S]*)_$/, '$1') // _italic_
return t.trim()
}
function isMarkdownFence(line: string): boolean {
return /^\s*(?:```|~~~)/.test(line)
}
// A markdown heading line is structural, never a memory. The exporter renders
// its title ("# Omi Memories") and every category ("## Personal") as headings,
// and section headers in any pasted dump are labels, not memories. Detected on
// the RAW line — before stripFormatting would turn "## Personal" into the bogus
// memory "Personal".
function isMarkdownHeading(line: string): boolean {
return /^\s*#{1,6}\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
if (isMarkdownHeading(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
const key = stripped.toLowerCase()
if (seen.has(key)) continue
seen.add(key)
out.push(stripped)
}
return out
}