MCPcopy Index your code
hub / github.com/PatrickSys/codebase-context / normalizeMemory

Function normalizeMemory

src/memory/store.ts:56–86  ·  view source on GitHub ↗
(raw: unknown)

Source from the content-addressed store, hash-verified

54}
55
56export function normalizeMemory(raw: unknown): Memory | null {
57 if (!isRecord(raw)) return null;
58 const m = raw as RawMemory;
59
60 const id = typeof m.id === 'string' ? m.id : undefined;
61 const type = typeof m.type === 'string' ? (m.type as MemoryType) : 'decision';
62 const category = typeof m.category === 'string' ? (m.category as MemoryCategory) : undefined;
63 const memory =
64 typeof m.memory === 'string'
65 ? m.memory
66 : typeof m.decision === 'string'
67 ? m.decision
68 : undefined;
69 const reason = typeof m.reason === 'string' ? m.reason : undefined;
70 const date = typeof m.date === 'string' ? m.date : undefined;
71
72 if (!id || !category || !memory || !reason || !date) return null;
73
74 const source = m.source === 'git' ? ('git' as const) : undefined;
75 const scope = normalizeMemoryScope(m.scope);
76 return {
77 id,
78 type,
79 category,
80 memory,
81 reason,
82 date,
83 ...(source && { source }),
84 ...(scope && { scope })
85 };
86}
87
88export function normalizeMemories(raw: unknown): Memory[] {
89 if (!Array.isArray(raw)) return [];

Callers 3

normalizeMemoriesFunction · 0.85

Calls 2

normalizeMemoryScopeFunction · 0.85
isRecordFunction · 0.70

Tested by

no test coverage detected