MCPcopy
hub / github.com/claude-code-best/claude-code / scanMemoryFiles

Function scanMemoryFiles

src/memdir/memoryScan.ts:35–77  ·  view source on GitHub ↗
(
  memoryDir: string,
  signal: AbortSignal,
)

Source from the content-addressed store, hash-verified

33 * extra small files but still avoid the double-stat on the surviving 200.
34 */
35export async function scanMemoryFiles(
36 memoryDir: string,
37 signal: AbortSignal,
38): Promise<MemoryHeader[]> {
39 try {
40 const entries = await readdir(memoryDir, { recursive: true })
41 const mdFiles = entries.filter(
42 f => f.endsWith('.md') && basename(f) !== 'MEMORY.md',
43 )
44
45 const headerResults = await Promise.allSettled(
46 mdFiles.map(async (relativePath): Promise<MemoryHeader> => {
47 const filePath = join(memoryDir, relativePath)
48 const { content, mtimeMs } = await readFileInRange(
49 filePath,
50 0,
51 FRONTMATTER_MAX_LINES,
52 undefined,
53 signal,
54 )
55 const { frontmatter } = parseFrontmatter(content, filePath)
56 return {
57 filename: relativePath,
58 filePath,
59 mtimeMs,
60 description: frontmatter.description || null,
61 type: parseMemoryType(frontmatter.type),
62 }
63 }),
64 )
65
66 return headerResults
67 .filter(
68 (r): r is PromiseFulfilledResult<MemoryHeader> =>
69 r.status === 'fulfilled',
70 )
71 .map(r => r.value)
72 .sort((a, b) => b.mtimeMs - a.mtimeMs)
73 .slice(0, MAX_MEMORY_FILES)
74 } catch {
75 return []
76 }
77}
78
79/**
80 * Format memory headers as a text manifest: one line per file with

Callers 2

runExtractionFunction · 0.85
findRelevantMemoriesFunction · 0.85

Calls 4

readdirFunction · 0.85
readFileInRangeFunction · 0.85
parseMemoryTypeFunction · 0.85
parseFrontmatterFunction · 0.50

Tested by

no test coverage detected