(cwd: string)
| 125 | * Priority order: project > global > built-in (later sources override earlier ones) |
| 126 | */ |
| 127 | export async function getCommands(cwd: string): Promise<Command[]> { |
| 128 | const commands = new Map<string, Command>() |
| 129 | |
| 130 | // Add built-in commands first (lowest priority) |
| 131 | const builtInCommands = await getBuiltInCommands() |
| 132 | for (const command of builtInCommands) { |
| 133 | commands.set(command.name, command) |
| 134 | } |
| 135 | |
| 136 | // Scan global commands (override built-in) |
| 137 | const globalDir = path.join(getGlobalRooDirectory(), "commands") |
| 138 | await scanCommandDirectory(globalDir, "global", commands) |
| 139 | |
| 140 | // Scan project commands (highest priority - override both global and built-in) |
| 141 | const projectDir = path.join(getProjectRooDirectoryForCwd(cwd), "commands") |
| 142 | await scanCommandDirectory(projectDir, "project", commands) |
| 143 | |
| 144 | return Array.from(commands.values()) |
| 145 | } |
| 146 | |
| 147 | /** |
| 148 | * Get a specific command by name (optimized to avoid scanning all commands) |
no test coverage detected