{"version":3,"sources":["../src/index.ts"],"names":["__dirname","dirname","fileURLToPath","PKG_ROOT","resolve","resolveAsset","name","fromDist","join","existsSync","fromSrc","SKILLS_DIR","skillCache","loadSkills","cache","entries","readdirSync","err","dir","statSync","manifestPath","manifest","readFileSync","files","file","baseName","listSkills","getSkill","getAllSkills","getSkillFile","skillName","fileName","clearCache"],"mappings":"+JAqBA,IAAMA,CAAAA,CAAYC,YAAAA,CAAQC,iBAAAA,CAAc,2PAAe,CAAC,CAAA,CAClDC,CAAAA,CAAWC,YAAAA,CAAQJ,CAAAA,CAAW,IAAI,CAAA,CAOxC,SAASK,CAAAA,CAAaC,CAAAA,CAAsB,CAC1C,IAAMC,CAAAA,CAAWC,SAAAA,CAAKL,CAAAA,CAAUG,CAAI,CAAA,CACpC,GAAIG,aAAAA,CAAWF,CAAQ,CAAA,CACrB,OAAOA,CAAAA,CAGT,IAAMG,CAAAA,CAAUF,SAAAA,CAAKL,CAAAA,CAAU,IAAA,CAAMG,CAAI,CAAA,CACzC,OAAIG,aAAAA,CAAWC,CAAO,CAAA,CACbA,EAGFH,CACT,CAEA,IAAMI,CAAAA,CAAaN,CAAAA,CAAa,QAAQ,CAAA,CAgBpCO,CAAAA,CAAwC,IAAA,CAE5C,SAASC,CAAAA,EAAiC,CACxC,GAAID,CAAAA,CACF,OAAOA,CAAAA,CAGT,IAAME,CAAAA,CAAQ,IAAI,GAAA,CACdC,CAAAA,CACJ,GAAI,CACFA,CAAAA,CAAUC,cAAAA,CAAYL,CAAU,EAClC,CAAA,MAASM,CAAAA,CAAc,CACrB,GAAKA,CAAAA,CAA8B,IAAA,GAAS,QAAA,CAC1C,OAAAL,CAAAA,CAAaE,CAAAA,CACNA,CAAAA,CAET,MAAMG,CACR,CAEA,IAAA,IAAWX,CAAAA,IAAQS,CAAAA,CAAS,CAC1B,IAAMG,CAAAA,CAAMV,SAAAA,CAAKG,CAAAA,CAAYL,CAAI,CAAA,CACjC,GAAI,CAACa,WAAAA,CAASD,CAA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C,CAAQ,CACxD,CAMO,SAASC,CAAAA,EAAmB,CACjCpB,CAAAA,CAAa,KACf","file":"index.cjs","sourcesContent":["/**\n * Programmatic API for `@directive-run/claude-plugin`.\n *\n * The canonical install path for end users is Claude Code's plugin\n * marketplace (`/plugin marketplace add directive-run/directive`\n * then `/plugin install directive@directive-plugins`). This module\n * is the alternative install path for tool authors who want to\n * consume the skill bundles programmatically — custom skill\n * registries, doc-generation pipelines, eval harnesses, or AI\n * orchestrators that want to expose Directive skills via their own\n * routing layer.\n *\n * The package ships the pre-built skill bundles in `skills/`. This\n * module exposes them as functions: list the skills, read a SKILL.md,\n * read a supporting knowledge file, or grab the whole skill tree.\n */\n\nimport { existsSync, readFileSync, readdirSync, statSync } from \"node:fs\";\nimport { dirname, join, resolve } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\nconst __dirname = dirname(fileURLToPath(import.meta.url));\nconst PKG_ROOT = resolve(__dirname, \"..\");\n\n/**\n * Resolve a path relative to the package root. Tries the published\n * layout (`dist/` sibling of `skills/`) first, then the dev layout\n * (running from `src/` in the monorepo).\n */\nfunction resolveAsset(name: string): string {\n  const fromDist = join(PKG_ROOT, name);\n  if (existsSync(fromDist)) {\n    return fromDist;\n  }\n\n  const fromSrc = join(PKG_ROOT, \"..\", name);\n  if (existsSync(fromSrc)) {\n    return fromSrc;\n  }\n\n  return fromDist;\n}\n\nconst SKILLS_DIR = resolveAsset(\"skills\");\n\n/**\n * One bundled skill — the `SKILL.md` plus its supporting knowledge\n * files (which are copied in from `@directive-run/knowledge` at\n * build time) and the auto-generated `examples.md` when present.\n */\nexport interface Skill {\n  /** Skill name (matches the directory under `skills/`). */\n  name: string;\n  /** Full `SKILL.md` contents — the Claude-facing skill manifest. */\n  manifest: string;\n  /** Supporting files keyed by base name (no `.md` suffix). */\n  files: Map<string, string>;\n}\n\nlet skillCache: Map<string, Skill> | null = null;\n\nfunction loadSkills(): Map<string, Skill> {\n  if (skillCache) {\n    return skillCache;\n  }\n\n  const cache = new Map<string, Skill>();\n  let entries: string[];\n  try {\n    entries = readdirSync(SKILLS_DIR);\n  } catch (err: unknown) {\n    if ((err as NodeJS.ErrnoException).code === \"ENOENT\") {\n      skillCache = cache;\n      return cache;\n    }\n    throw err;\n  }\n\n  for (const name of entries) {\n    const dir = join(SKILLS_DIR, name);\n    if (!statSync(dir).isDirectory()) {\n      continue;\n    }\n\n    const manifestPath = join(dir, \"SKILL.md\");\n    if (!existsSync(manifestPath)) {\n      continue;\n    }\n\n    const manifest = readFileSync(manifestPath, \"utf-8\");\n    const files = new Map<string, string>();\n    for (const file of readdirSync(dir)) {\n      if (!file.endsWith(\".md\") || file === \"SKILL.md\") {\n        continue;\n      }\n      const baseName = file.replace(/\\.md$/, \"\");\n      files.set(baseName, readFileSync(join(dir, file), \"utf-8\"));\n    }\n\n    cache.set(name, { name, manifest, files });\n  }\n\n  skillCache = cache;\n  return cache;\n}\n\n/**\n * List the names of every bundled skill.\n *\n * Returns an alphabetically-sorted array — stable for snapshot tests.\n */\nexport function listSkills(): string[] {\n  return Array.from(loadSkills().keys()).sort();\n}\n\n/**\n * Get a single skill by name.\n *\n * @param name - Skill name (e.g. `\"writing-directive-modules\"`).\n * @returns The skill, or `undefined` if no skill by that name exists.\n */\nexport function getSkill(name: string): Skill | undefined {\n  return loadSkills().get(name);\n}\n\n/**\n * Get every bundled skill, keyed by name.\n *\n * Returns a defensive copy — mutating the returned Map won't affect\n * subsequent calls.\n */\nexport function getAllSkills(): Map<string, Skill> {\n  return new Map(loadSkills());\n}\n\n/**\n * Read one supporting file from a skill bundle.\n *\n * @param skillName - Skill name (e.g. `\"writing-directive-modules\"`).\n * @param fileName - Supporting file base name without `.md`\n *   (e.g. `\"core-patterns\"`, `\"anti-patterns\"`, `\"examples\"`).\n * @returns File contents, or `undefined` if the skill or file is not\n *   present.\n */\nexport function getSkillFile(\n  skillName: string,\n  fileName: string,\n): string | undefined {\n  return loadSkills().get(skillName)?.files.get(fileName);\n}\n\n/**\n * Clear the in-memory skill cache. Useful in tests or watch-mode\n * tooling that regenerates the `skills/` directory between calls.\n */\nexport function clearCache(): void {\n  skillCache = null;\n}\n"]}