MCPcopy Create free account
hub / github.com/MatterAIOrg/OrbCode / loadWithIncludes

Function loadWithIncludes

src/memory/loader.ts:73–96  ·  view source on GitHub ↗

Recursively load a memory file and all its @includes.

(
	filePath: string,
	type: MemoryFile["type"],
	processed: Set<string>,
	depth: number,
)

Source from the content-addressed store, hash-verified

71
72/** Recursively load a memory file and all its @includes. */
73function loadWithIncludes(
74 filePath: string,
75 type: MemoryFile["type"],
76 processed: Set<string>,
77 depth: number,
78): MemoryFile[] {
79 const real = safeRealpath(filePath)
80 if (processed.has(real) || depth >= MAX_INCLUDE_DEPTH) return []
81 const raw = readText(filePath)
82 if (raw === undefined) return []
83 processed.add(real)
84
85 const baseDir = path.dirname(filePath)
86 const includePaths = extractIncludes(raw, baseDir)
87 const results: MemoryFile[] = []
88
89 // Includes come first (so they appear before the including file's content).
90 for (const includePath of includePaths) {
91 results.push(...loadWithIncludes(includePath, type, processed, depth + 1))
92 }
93
94 results.push({ path: filePath, content: raw, type })
95 return results
96}
97
98/** realpathSync that never throws (falls back to the input path). */
99function safeRealpath(p: string): string {

Callers 1

loadMemoryFilesFunction · 0.85

Calls 3

safeRealpathFunction · 0.85
readTextFunction · 0.85
extractIncludesFunction · 0.85

Tested by

no test coverage detected