MCPcopy Index your code
hub / github.com/ChatLab/ChatLab / walk

Function walk

packages/parser/src/index.ts:263–285  ·  view source on GitHub ↗
(current: string, depth: number)

Source from the content-addressed store, hash-verified

261 */
262export function findEntryFileInDirectory(dirPath: string, maxDepth = 1): string | null {
263 function walk(current: string, depth: number): string | null {
264 if (depth > maxDepth) return null
265 let entries: fs.Dirent[]
266 try {
267 entries = fs.readdirSync(current, { withFileTypes: true })
268 } catch {
269 return null
270 }
271 for (const entry of entries) {
272 const full = path.join(current, entry.name)
273 if (entry.isFile() && entry.name.endsWith('.json')) {
274 const format = detectFormat(full)
275 if (format) return full
276 }
277 }
278 for (const entry of entries) {
279 if (entry.isDirectory()) {
280 const found = walk(path.join(current, entry.name), depth + 1)
281 if (found) return found
282 }
283 }
284 return null
285 }
286
287 return walk(dirPath, 0)
288}

Callers 1

findEntryFileInDirectoryFunction · 0.70

Calls 1

detectFormatFunction · 0.85

Tested by

no test coverage detected