MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / scanDirectory

Function scanDirectory

cli/src/utils/local-agent-registry.ts:112–142  ·  view source on GitHub ↗
(dir: string)

Source from the content-addressed store, hash-verified

110 const idRegex = /id\s*:\s*['"`]([^'"`]+)['"`]/i
111
112 const scanDirectory = (dir: string): void => {
113 try {
114 const entries = fs.readdirSync(dir, { withFileTypes: true })
115 for (const entry of entries) {
116 const fullPath = path.join(dir, entry.name)
117 if (entry.isDirectory() && !entry.name.startsWith('.')) {
118 scanDirectory(fullPath)
119 continue
120 }
121 if (
122 !entry.isFile() ||
123 !entry.name.endsWith('.ts') ||
124 entry.name.endsWith('.d.ts') ||
125 entry.name.endsWith('.test.ts')
126 ) {
127 continue
128 }
129 try {
130 const content = fs.readFileSync(fullPath, 'utf8')
131 const match = content.match(idRegex)
132 if (match?.[1]) {
133 idToPath.set(match[1], fullPath)
134 }
135 } catch {
136 // Skip files that can't be read
137 }
138 }
139 } catch {
140 // Skip directories that can't be read
141 }
142 }
143
144 // Scan all directories - later directories override earlier ones
145 for (const agentsDir of agentsDirs) {

Callers 1

buildAgentFilePathMapFunction · 0.85

Calls 1

setMethod · 0.80

Tested by

no test coverage detected