MCPcopy Create free account
hub / github.com/QodeXcli/QodeX / walkSource

Function walkSource

src/context/retrieval.ts:45–71  ·  view source on GitHub ↗
(root: string, maxFiles: number)

Source from the content-addressed store, hash-verified

43}
44
45export async function walkSource(root: string, maxFiles: number): Promise<{ abs: string; rel: string; content: string }[]> {
46 const out: { abs: string; rel: string; content: string }[] = [];
47 const stack = [root];
48 while (stack.length > 0 && out.length < maxFiles) {
49 const dir = stack.pop()!;
50 let entries;
51 try { entries = await fs.readdir(dir, { withFileTypes: true }); } catch { continue; }
52 for (const e of entries) {
53 if (out.length >= maxFiles) break;
54 if (e.isDirectory()) {
55 if (SKIP_DIRS.has(e.name) || e.name.startsWith('.')) continue;
56 stack.push(path.join(dir, e.name));
57 } else if (e.isFile()) {
58 const ext = path.extname(e.name).toLowerCase();
59 if (!SOURCE_EXTS.has(ext)) continue;
60 const abs = path.join(dir, e.name);
61 try {
62 const stat = await fs.stat(abs);
63 if (stat.size > 500_000) continue;
64 const content = await fs.readFile(abs, 'utf-8');
65 out.push({ abs, rel: path.relative(root, abs), content });
66 } catch { /* skip */ }
67 }
68 }
69 }
70 return out;
71}
72
73export function chunkFile(rel: string, content: string, chunkLines: number, overlap: number): Chunk[] {
74 const lines = content.split('\n');

Callers 3

getSymbolGraphFunction · 0.70
buildIndexFunction · 0.70
expandRankedViaGraphFunction · 0.70

Calls 2

hasMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected