()
| 185 | let cachedAgentsDir: string | null = null |
| 186 | |
| 187 | export 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) |
no test coverage detected