(cwd: string)
| 476 | * auth changes (e.g. /login) take effect immediately. |
| 477 | */ |
| 478 | export async function getCommands(cwd: string): Promise<Command[]> { |
| 479 | const allCommands = await loadAllCommands(cwd) |
| 480 | |
| 481 | // Get dynamic skills discovered during file operations |
| 482 | const dynamicSkills = getDynamicSkills() |
| 483 | |
| 484 | // Build base commands without dynamic skills |
| 485 | const baseCommands = allCommands.filter( |
| 486 | _ => meetsAvailabilityRequirement(_) && isCommandEnabled(_), |
| 487 | ) |
| 488 | |
| 489 | if (dynamicSkills.length === 0) { |
| 490 | return baseCommands |
| 491 | } |
| 492 | |
| 493 | // Dedupe dynamic skills - only add if not already present |
| 494 | const baseCommandNames = new Set(baseCommands.map(c => c.name)) |
| 495 | const uniqueDynamicSkills = dynamicSkills.filter( |
| 496 | s => |
| 497 | !baseCommandNames.has(s.name) && |
| 498 | meetsAvailabilityRequirement(s) && |
| 499 | isCommandEnabled(s), |
| 500 | ) |
| 501 | |
| 502 | if (uniqueDynamicSkills.length === 0) { |
| 503 | return baseCommands |
| 504 | } |
| 505 | |
| 506 | // Insert dynamic skills after plugin skills but before built-in commands |
| 507 | const builtInNames = new Set(COMMANDS().map(c => c.name)) |
| 508 | const insertIndex = baseCommands.findIndex(c => builtInNames.has(c.name)) |
| 509 | |
| 510 | if (insertIndex === -1) { |
| 511 | return [...baseCommands, ...uniqueDynamicSkills] |
| 512 | } |
| 513 | |
| 514 | return [ |
| 515 | ...baseCommands.slice(0, insertIndex), |
| 516 | ...uniqueDynamicSkills, |
| 517 | ...baseCommands.slice(insertIndex), |
| 518 | ] |
| 519 | } |
| 520 | |
| 521 | /** |
| 522 | * Clears only the memoization caches for commands, WITHOUT clearing skill caches. |
no test coverage detected