import { basename, join } from "node:path";

import {
  RULESYNC_CURATED_SKILLS_RELATIVE_DIR_PATH,
  RULESYNC_SKILLS_RELATIVE_DIR_PATH,
} from "../../constants/rulesync-paths.js";
import { directoryExists, findFilesByGlobs } from "../../utils/file.js";

/**
 * Returns the set of local skill directory names (excluding `.curated`).
 */
export async function getLocalSkillDirNames(outputRoot: string): Promise<Set<string>> {
  const skillsDir = join(outputRoot, RULESYNC_SKILLS_RELATIVE_DIR_PATH);
  const names = new Set<string>();

  if (!(await directoryExists(skillsDir))) {
    return names;
  }

  const dirPaths = await findFilesByGlobs(join(skillsDir, "*"), { type: "dir" });
  for (const dirPath of dirPaths) {
    const name = basename(dirPath);
    // Skip the .curated directory itself
    if (name === basename(RULESYNC_CURATED_SKILLS_RELATIVE_DIR_PATH)) continue;
    names.add(name);
  }

  return names;
}
