MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / scanMemoryFiles

Function scanMemoryFiles

source code/memdir/memoryScan.ts:37–79  ·  view source on GitHub ↗
(
  memoryDir: string,
  signal: AbortSignal,
)

Source from the content-addressed store, hash-verified

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

Tested by

no test coverage detected