( filePath: string, type: MemoryType, processedPaths: Set<string>, includeExternal: boolean, depth: number = 0, parent?: string, )
| 788 | * Returns an array of MemoryFileInfo objects with includes first, then main file |
| 789 | */ |
| 790 | export async function processMemoryFile( |
| 791 | filePath: string, |
| 792 | type: MemoryType, |
| 793 | processedPaths: Set<string>, |
| 794 | includeExternal: boolean, |
| 795 | depth: number = 0, |
| 796 | parent?: string, |
| 797 | ): Promise<MemoryFileInfo[]> { |
| 798 | // Skip if already processed or max depth exceeded. |
| 799 | // Normalize paths for comparison to handle Windows drive letter casing |
| 800 | // differences (e.g., C:\Users vs c:\Users). |
| 801 | const normalizedPath = normalizePathForComparison(filePath) |
| 802 | if (processedPaths.has(normalizedPath) || depth >= MAX_INCLUDE_DEPTH) { |
| 803 | return [] |
| 804 | } |
| 805 | |
| 806 | // Skip if path is excluded by claudeMdExcludes setting |
| 807 | if (isClaudeMdExcluded(filePath, type)) { |
| 808 | return [] |
| 809 | } |
| 810 | |
| 811 | // Resolve symlink path early for @import resolution |
| 812 | const { resolvedPath, isSymlink } = safeResolvePath( |
| 813 | getFsImplementation(), |
| 814 | filePath, |
| 815 | ) |
| 816 | |
| 817 | processedPaths.add(normalizedPath) |
| 818 | if (isSymlink) { |
| 819 | processedPaths.add(normalizePathForComparison(resolvedPath)) |
| 820 | } |
| 821 | |
| 822 | const { info: memoryFile, includePaths: resolvedIncludePaths } = |
| 823 | await safelyReadMemoryFileAsync(filePath, type, resolvedPath) |
| 824 | if (!memoryFile || !memoryFile.content.trim()) { |
| 825 | return [] |
| 826 | } |
| 827 | |
| 828 | // Add parent information |
| 829 | if (parent) { |
| 830 | memoryFile.parent = parent |
| 831 | } |
| 832 | |
| 833 | const result: MemoryFileInfo[] = [] |
| 834 | |
| 835 | // Add the main file first (parent before children) |
| 836 | result.push(memoryFile) |
| 837 | |
| 838 | for (const resolvedIncludePath of resolvedIncludePaths) { |
| 839 | const isExternal = !pathInOriginalCwd(resolvedIncludePath) |
| 840 | if (isExternal && !includeExternal) { |
| 841 | continue |
| 842 | } |
| 843 | |
| 844 | // Recursively process included files with this file as parent |
| 845 | const includedFiles = await processMemoryFile( |
| 846 | resolvedIncludePath, |
| 847 | type, |
no test coverage detected