MCPcopy
hub / github.com/upstash/context7 / listCommand

Function listCommand

packages/cli/src/commands/skill.ts:654–749  ·  view source on GitHub ↗
(options: ListOptions)

Source from the content-addressed store, hash-verified

652}
653
654async function listCommand(options: ListOptions): Promise<void> {
655 trackEvent("command", { name: "list" });
656 const scope: Scope = options.global ? "global" : "project";
657 const baseDir = scope === "global" ? homedir() : process.cwd();
658
659 const results: {
660 label: string;
661 displayPath: string;
662 dir: string;
663 source: string;
664 skills: string[];
665 }[] = [];
666
667 // Helper to scan a skills directory
668 async function scanDir(dir: string): Promise<string[]> {
669 try {
670 const entries = await readdir(dir, { withFileTypes: true });
671 return entries.filter((e) => e.isDirectory() || e.isSymbolicLink()).map((e) => e.name);
672 } catch {
673 return [];
674 }
675 }
676
677 if (hasExplicitIdeOption(options)) {
678 // Explicit flag mode — check the specific IDE paths
679 const ides = getSelectedIdes(options);
680 for (const ide of ides) {
681 const dir =
682 ide === "universal"
683 ? join(baseDir, scope === "global" ? UNIVERSAL_SKILLS_GLOBAL_PATH : UNIVERSAL_SKILLS_PATH)
684 : join(baseDir, (scope === "global" ? IDE_GLOBAL_PATHS : IDE_PATHS)[ide]);
685 const label = ide === "universal" ? UNIVERSAL_AGENTS_LABEL : IDE_NAMES[ide];
686 const skills = await scanDir(dir);
687 if (skills.length > 0) {
688 results.push({ label, displayPath: dir, dir, source: ide, skills });
689 }
690 }
691 } else {
692 // Default: check universal + vendor-specific
693 const universalPath = scope === "global" ? UNIVERSAL_SKILLS_GLOBAL_PATH : UNIVERSAL_SKILLS_PATH;
694 const universalDir = join(baseDir, universalPath);
695 const universalSkills = await scanDir(universalDir);
696 if (universalSkills.length > 0) {
697 results.push({
698 label: UNIVERSAL_AGENTS_LABEL,
699 displayPath: universalPath,
700 dir: universalDir,
701 source: "universal",
702 skills: universalSkills,
703 });
704 }
705
706 for (const ide of VENDOR_SPECIFIC_AGENTS) {
707 const pathMap = scope === "global" ? IDE_GLOBAL_PATHS : IDE_PATHS;
708 const dir = join(baseDir, pathMap[ide]);
709 const skills = await scanDir(dir);
710 if (skills.length > 0) {
711 results.push({

Callers 1

registerSkillCommandsFunction · 0.85

Calls 4

trackEventFunction · 0.85
hasExplicitIdeOptionFunction · 0.85
getSelectedIdesFunction · 0.85
scanDirFunction · 0.85

Tested by

no test coverage detected