| 106 | const agentFileExtensions = new Set(['.ts', '.tsx', '.js', '.mjs', '.cjs']) |
| 107 | |
| 108 | const getAllAgentFiles = (dir: string): string[] => { |
| 109 | const files: string[] = [] |
| 110 | try { |
| 111 | const entries = fs.readdirSync(dir, { withFileTypes: true }) |
| 112 | for (const entry of entries) { |
| 113 | const fullPath = path.join(dir, entry.name) |
| 114 | if (entry.isDirectory()) { |
| 115 | if (entry.name === 'skills') continue |
| 116 | files.push(...getAllAgentFiles(fullPath)) |
| 117 | continue |
| 118 | } |
| 119 | const extension = path.extname(entry.name).toLowerCase() |
| 120 | const isAgentFile = |
| 121 | entry.isFile() && |
| 122 | agentFileExtensions.has(extension) && |
| 123 | !entry.name.endsWith('.d.ts') && |
| 124 | !entry.name.endsWith('.test.ts') |
| 125 | if (isAgentFile) { |
| 126 | files.push(fullPath) |
| 127 | } |
| 128 | } |
| 129 | } catch { |
| 130 | // Expected for user agent directories that may not exist |
| 131 | } |
| 132 | return files |
| 133 | } |
| 134 | |
| 135 | const getDefaultAgentDirs = () => { |
| 136 | const cwdAgents = path.join(process.cwd(), '.agents') |