MCPcopy Index your code
hub / github.com/liuup/claude-code-analysis / getCommands

Function getCommands

src/commands.ts:476–517  ·  view source on GitHub ↗
(cwd: string)

Source from the content-addressed store, hash-verified

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

Callers 7

commands.tsFile · 0.85
runFunction · 0.85
setupFunction · 0.85
getAllCommandsFunction · 0.85
refreshPluginStateFunction · 0.85
runHeadlessStreamingFunction · 0.85
useSkillsChangeFunction · 0.85

Calls 4

getDynamicSkillsFunction · 0.85
isCommandEnabledFunction · 0.85
hasMethod · 0.45

Tested by

no test coverage detected