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

Function findAgentsDirectory

cli/src/utils/local-agent-registry.ts:187–228  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

185let cachedAgentsDir: string | null = null
186
187export const findAgentsDirectory = (): string | null => {
188 if (cachedAgentsDir && fs.existsSync(cachedAgentsDir)) {
189 return cachedAgentsDir
190 }
191
192 const projectRoot = getProjectRoot() || process.cwd()
193 if (projectRoot) {
194 const rootCandidate = path.join(projectRoot, AGENTS_DIR_NAME)
195 if (
196 fs.existsSync(rootCandidate) &&
197 fs.statSync(rootCandidate).isDirectory()
198 ) {
199 cachedAgentsDir = rootCandidate
200 return cachedAgentsDir
201 }
202 }
203
204 let currentDir = process.cwd()
205 const filesystemRoot = path.parse(currentDir).root
206
207 while (true) {
208 const candidate = path.join(currentDir, AGENTS_DIR_NAME)
209 if (fs.existsSync(candidate) && fs.statSync(candidate).isDirectory()) {
210 cachedAgentsDir = candidate
211 return cachedAgentsDir
212 }
213
214 if (currentDir === filesystemRoot) {
215 break
216 }
217
218 const parentDir = path.dirname(currentDir)
219 if (parentDir === currentDir) {
220 break
221 }
222
223 currentDir = parentDir
224 }
225
226 cachedAgentsDir = null
227 return null
228}
229
230// ============================================================================
231// Agent loading - LocalAgentInfo (lightweight, for UI/listing)

Callers 4

announceLoadedAgentsFunction · 0.85
getLoadedAgentsMessageFunction · 0.85
getLoadedAgentsDataFunction · 0.85

Calls 2

getProjectRootFunction · 0.90
parseMethod · 0.80

Tested by

no test coverage detected