This repository was archived by the owner on Jun 3, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathmemory.ts
More file actions
35 lines (31 loc) · 1.35 KB
/
memory.ts
File metadata and controls
35 lines (31 loc) · 1.35 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
export const MEMORY_CATEGORIES = [
"preference",
"architecture",
"error-solution",
"project-config",
"learned-pattern",
"conversation",
] as const
export type MemoryCategory = (typeof MEMORY_CATEGORIES)[number]
export function detectCategory(text: string): MemoryCategory {
const value = text.toLowerCase()
if (/(prefer|preference|style|always|never)/.test(value)) return "preference"
if (/(architecture|design|pattern|module|service|api)/.test(value)) return "architecture"
if (/(bug|error|fix|failure|root cause|regression)/.test(value)) return "error-solution"
if (/(config|env|setting|secret|deploy|command)/.test(value)) return "project-config"
if (/(learned|lesson|note|remember)/.test(value)) return "learned-pattern"
return "conversation"
}
export function redactSecrets(text: string): string {
return String(text || "")
.replace(/xmem_[A-Za-z0-9_-]{12,}/g, "[redacted-xmem-key]")
.replace(/sk-[A-Za-z0-9_-]{16,}/g, "[redacted-api-key]")
.replace(/(authorization\s*[:=]\s*bearer\s+)[^\s"'`]+/gi, "$1[redacted]")
.replace(/(bearer\s+)[^\s"'`]+/gi, "$1[redacted]")
.replace(/((?:api[_-]?key|authorization|token)\s*[:=]\s*)[^\s"'`]+/gi, "$1[redacted]")
}
export function truncate(text: string, limit = 12000): string {
const value = String(text || "").trim()
if (value.length <= limit) return value
return `${value.slice(0, limit)}\n\n[truncated]`
}