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

Function extractIncludes

src/memory/loader.ts:49–70  ·  view source on GitHub ↗

* Extract `@path` references from leaf text (not inside code spans/blocks). * A simple, conservative parser: skips fenced code blocks and inline code.

(content: string, baseDir: string)

Source from the content-addressed store, hash-verified

47 * A simple, conservative parser: skips fenced code blocks and inline code.
48 */
49function extractIncludes(content: string, baseDir: string): string[] {
50 const refs: string[] = []
51 let inFence = false
52 for (const line of content.split(/\r?\n/)) {
53 if (/^```/.test(line.trim())) {
54 inFence = !inFence
55 continue
56 }
57 if (inFence) continue
58 // Strip inline code spans before scanning for @refs.
59 const stripped = line.replace(/`[^`]*`/g, "")
60 const regex = /(?:^|\s)@((?:\.\/|~\/|\/)?[^\s]+)/g
61 let match: RegExpExecArray | null
62 while ((match = regex.exec(stripped)) !== null) {
63 const ref = match[1].replace(/\\ /g, " ")
64 // Avoid matching emails, @mentions, etc.
65 if (!/^[A-Za-z0-9._~/-]/.test(ref)) continue
66 refs.push(resolveInclude(ref, baseDir))
67 }
68 }
69 return refs
70}
71
72/** Recursively load a memory file and all its @includes. */
73function loadWithIncludes(

Callers 1

loadWithIncludesFunction · 0.85

Calls 1

resolveIncludeFunction · 0.85

Tested by

no test coverage detected