(cwd: string)
| 561 | * auth changes (e.g. /login) take effect immediately. |
| 562 | */ |
| 563 | export async function getCommands(cwd: string): Promise<Command[]> { |
| 564 | const allCommands = await loadAllCommands(cwd) |
| 565 | |
| 566 | // Get dynamic skills discovered during file operations |
| 567 | const dynamicSkills = getDynamicSkills() |
| 568 | |
| 569 | // Build base commands without dynamic skills |
| 570 | const baseCommands = allCommands.filter( |
| 571 | _ => meetsAvailabilityRequirement(_) && isCommandEnabled(_), |
| 572 | ) |
| 573 | |
| 574 | if (dynamicSkills.length === 0) { |
| 575 | return baseCommands |
| 576 | } |
| 577 | |
| 578 | // Dedupe dynamic skills - only add if not already present |
| 579 | const baseCommandNames = new Set(baseCommands.map(c => c.name)) |
| 580 | const uniqueDynamicSkills = dynamicSkills.filter( |
| 581 | s => |
| 582 | !baseCommandNames.has(s.name) && |
| 583 | meetsAvailabilityRequirement(s) && |
| 584 | isCommandEnabled(s), |
| 585 | ) |
| 586 | |
| 587 | if (uniqueDynamicSkills.length === 0) { |
| 588 | return baseCommands |
| 589 | } |
| 590 | |
| 591 | // Insert dynamic skills after plugin skills but before built-in commands |
| 592 | const builtInNames = new Set(COMMANDS().map(c => c.name)) |
| 593 | const insertIndex = baseCommands.findIndex(c => builtInNames.has(c.name)) |
| 594 | |
| 595 | if (insertIndex === -1) { |
| 596 | return [...baseCommands, ...uniqueDynamicSkills] |
| 597 | } |
| 598 | |
| 599 | return [ |
| 600 | ...baseCommands.slice(0, insertIndex), |
| 601 | ...uniqueDynamicSkills, |
| 602 | ...baseCommands.slice(insertIndex), |
| 603 | ] |
| 604 | } |
| 605 | |
| 606 | /** |
| 607 | * Clears only the memoization caches for commands, WITHOUT clearing skill caches. |
no test coverage detected