Recursively reads all files in a directory, returning a map of relative paths to contents.
(baseDir: string, prefix = '')
| 265 | |
| 266 | /** Recursively reads all files in a directory, returning a map of relative paths to contents. */ |
| 267 | async function readDirRecursive(baseDir: string, prefix = ''): Promise<Map<string, string>> { |
| 268 | const contents = new Map<string, string>() |
| 269 | const entries = await fs.readdir(path.join(baseDir, prefix), { withFileTypes: true }) |
| 270 | |
| 271 | for (const entry of entries) { |
| 272 | const relativePath = path.join(prefix, entry.name) |
| 273 | if (entry.isDirectory()) { |
| 274 | const sub = await readDirRecursive(baseDir, relativePath) |
| 275 | for (const [key, value] of sub) { |
| 276 | contents.set(key, value) |
| 277 | } |
| 278 | } else { |
| 279 | contents.set(relativePath, await fs.readFile(path.join(baseDir, relativePath), 'utf8')) |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | return contents |
| 284 | } |
| 285 | |
| 286 | async function detectAgents(baseDir: string, isGlobal: boolean, agentFilter?: string): Promise<AgentConfig[]> { |
| 287 | if (agentFilter) { |