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

Function processMemoryFile

src/utils/claudemd.ts:617–684  ·  view source on GitHub ↗
(
  filePath: string,
  type: MemoryType,
  processedPaths: Set<string>,
  includeExternal: boolean,
  depth: number = 0,
  parent?: string,
)

Source from the content-addressed store, hash-verified

615 * Returns an array of MemoryFileInfo objects with includes first, then main file
616 */
617export async function processMemoryFile(
618 filePath: string,
619 type: MemoryType,
620 processedPaths: Set<string>,
621 includeExternal: boolean,
622 depth: number = 0,
623 parent?: string,
624): Promise<MemoryFileInfo[]> {
625 // Skip if already processed or max depth exceeded.
626 // Normalize paths for comparison to handle Windows drive letter casing
627 // differences (e.g., C:\Users vs c:\Users).
628 const normalizedPath = normalizePathForComparison(filePath)
629 if (processedPaths.has(normalizedPath) || depth >= MAX_INCLUDE_DEPTH) {
630 return []
631 }
632
633 // Skip if path is excluded by claudeMdExcludes setting
634 if (isClaudeMdExcluded(filePath, type)) {
635 return []
636 }
637
638 // Resolve symlink path early for @import resolution
639 const { resolvedPath, isSymlink } = safeResolvePath(
640 getFsImplementation(),
641 filePath,
642 )
643
644 processedPaths.add(normalizedPath)
645 if (isSymlink) {
646 processedPaths.add(normalizePathForComparison(resolvedPath))
647 }
648
649 const { info: memoryFile, includePaths: resolvedIncludePaths } =
650 await safelyReadMemoryFileAsync(filePath, type, resolvedPath)
651 if (!memoryFile || !memoryFile.content.trim()) {
652 return []
653 }
654
655 // Add parent information
656 if (parent) {
657 memoryFile.parent = parent
658 }
659
660 const result: MemoryFileInfo[] = []
661
662 // Add the main file first (parent before children)
663 result.push(memoryFile)
664
665 for (const resolvedIncludePath of resolvedIncludePaths) {
666 const isExternal = !pathInOriginalCwd(resolvedIncludePath)
667 if (isExternal && !includeExternal) {
668 continue
669 }
670
671 // Recursively process included files with this file as parent
672 const includedFiles = await processMemoryFile(
673 resolvedIncludePath,
674 type,

Callers 3

processMdRulesFunction · 0.85
claudemd.tsFile · 0.85

Calls 9

isClaudeMdExcludedFunction · 0.85
safeResolvePathFunction · 0.85
getFsImplementationFunction · 0.85
pathInOriginalCwdFunction · 0.85
hasMethod · 0.45
addMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected