MCPcopy Index your code
hub / github.com/PatrickSys/codebase-context / walk

Function walk

src/utils/project-discovery.ts:149–185  ·  view source on GitHub ↗
(currentPath: string, depth: number)

Source from the content-addressed store, hash-verified

147 const discovered = new Map<string, DiscoveredProjectCandidate>();
148
149 async function walk(currentPath: string, depth: number): Promise<void> {
150 if (depth > maxDepth) {
151 return;
152 }
153
154 let entries: Dirent[];
155 try {
156 entries = await fs.readdir(currentPath, { withFileTypes: true });
157 } catch {
158 return;
159 }
160
161 const fileNames = new Set(entries.filter((entry) => entry.isFile()).map((entry) => entry.name));
162 const directoryNames = new Set(
163 entries.filter((entry) => entry.isDirectory()).map((entry) => entry.name)
164 );
165 const classification = await classifyDirectory(currentPath, fileNames, directoryNames);
166 const currentKey = normalizePathKey(currentPath);
167 const isTrustedRoot = currentKey === normalizePathKey(resolvedTrustedRootPath);
168
169 if (classification.candidate && !isTrustedRoot) {
170 discovered.set(currentKey, classification.candidate);
171 }
172
173 const shouldContinueScanning = isTrustedRoot ? true : classification.continueScanning;
174 if (depth >= maxDepth || !shouldContinueScanning) {
175 return;
176 }
177
178 await Promise.all(
179 entries
180 .filter((entry) => entry.isDirectory())
181 .filter((entry) => !IGNORED_DIRECTORY_NAMES.has(entry.name))
182 .filter((entry) => !STRONG_DIRECTORY_MARKERS.has(entry.name))
183 .map((entry) => walk(path.join(currentPath, entry.name), depth + 1))
184 );
185 }
186
187 await walk(resolvedTrustedRootPath, 0);
188 return Array.from(discovered.values()).sort((a, b) => a.rootPath.localeCompare(b.rootPath));

Callers 1

Calls 4

classifyDirectoryFunction · 0.85
normalizePathKeyFunction · 0.85
setMethod · 0.80
hasMethod · 0.80

Tested by

no test coverage detected