{"version":3,"file":"agent-docs-DIYN_jL_.mjs","names":[],"sources":["../src/generators/agent-docs.ts"],"sourcesContent":["import { join } from 'node:path'\nimport { existsSync, readFileSync } from 'node:fs'\nimport { writeFileSafe } from '../utils/fs'\nimport { confirm } from '../utils/prompts'\nimport {\n  generateClaude,\n  generateAgents,\n  generateKickJsSkillFiles,\n  generateGemini,\n  generateCopilot,\n} from './templates/project-docs'\nimport { loadKickConfig } from '../config'\n\ntype ProjectTemplate = 'rest' | 'minimal' | 'fullstack'\n\n/**\n * Subdirectory (relative to the project root) where every shared\n * agent-context file lands. CLAUDE.md is the only exception — it stays\n * at the project root because Claude Code auto-loads CLAUDE.md from\n * there. CLAUDE.md is generated as a thin pointer that tells Claude\n * to read `.agents/AGENTS.md` first.\n *\n * Existing root-level AGENTS.md / kickjs-skills.md files (from older\n * scaffolds before this restructure) are left untouched — the\n * generator emits the new layout alongside them and leaves migration\n * to the adopter.\n */\nconst AGENTS_DIR = '.agents'\n\nexport interface GenerateAgentDocsOptions {\n  outDir: string\n  /** Override project name (defaults to package.json `name`). */\n  name?: string\n  /** Override package manager (defaults to package.json `packageManager` field, then 'pnpm'). */\n  pm?: string\n  /** Override template (defaults to kick.config.ts `pattern`, then 'ddd'). */\n  template?: ProjectTemplate\n  /**\n   * Which file(s) to (re)generate. All `.agents/`-bound files land in\n   * the project's `.agents/` subdirectory; `claude` is the only file\n   * that stays at the project root.\n   *\n   * - `agents`  → `.agents/AGENTS.md`\n   * - `claude`  → `CLAUDE.md` (root; thin pointer to .agents/)\n   * - `skills`  → `.agents/kickjs-skills.md`\n   * - `gemini`  → `.agents/GEMINI.md`\n   * - `copilot` → `.agents/COPILOT.md`\n   * - `both`    → `.agents/AGENTS.md` + `CLAUDE.md` (legacy alias)\n   * - `all`     → every file above\n   */\n  only?: 'agents' | 'claude' | 'skills' | 'gemini' | 'copilot' | 'both' | 'all'\n  /** Skip the overwrite prompt. */\n  force?: boolean\n}\n\nconst VALID_TEMPLATES = new Set<ProjectTemplate>(['rest', 'minimal', 'fullstack'])\n\nfunction detectName(outDir: string, override?: string): string {\n  if (override) return override\n  try {\n    const pkg = JSON.parse(readFileSync(join(outDir, 'package.json'), 'utf-8')) as { name?: string }\n    if (pkg.name) return pkg.name.replace(/^@[^/]+\\//, '')\n  } catch {\n    // No package.json — fall back to folder name\n  }\n  return outDir.split('/').findLast(Boolean) ?? 'app'\n}\n\nfunction detectPm(outDir: string, override?: string): string {\n  if (override) return override\n  try {\n    const pkg = JSON.parse(readFileSync(join(outDir, 'package.json'), 'utf-8')) as {\n      packageManager?: string\n    }\n    if (pkg.packageManager) return pkg.packageManager.split('@')[0]\n  } catch {\n    // ignore\n  }\n  return 'pnpm'\n}\n\nasync function detectTemplate(\n  outDir: string,\n  override?: ProjectTemplate,\n): Promise<ProjectTemplate> {\n  if (override) return override\n  try {\n    const cfg = await loadKickConfig(outDir)\n    const pattern = cfg?.pattern as ProjectTemplate | undefined\n    if (pattern && VALID_TEMPLATES.has(pattern)) return pattern\n  } catch {\n    // ignore\n  }\n  return 'rest'\n}\n\nexport async function generateAgentDocs(options: GenerateAgentDocsOptions): Promise<string[]> {\n  const only = options.only ?? 'all'\n  const name = detectName(options.outDir, options.name)\n  const pm = detectPm(options.outDir, options.pm)\n  const template = await detectTemplate(options.outDir, options.template)\n\n  const wantsAgents = only === 'agents' || only === 'both' || only === 'all'\n  const wantsClaude = only === 'claude' || only === 'both' || only === 'all'\n  const wantsSkills = only === 'skills' || only === 'all'\n  const wantsGemini = only === 'gemini' || only === 'all'\n  const wantsCopilot = only === 'copilot' || only === 'all'\n\n  // CLAUDE.md stays at the project root because Claude Code auto-loads\n  // it from there. Every other shared-context file lands under\n  // `.agents/` so the root stays uncluttered. `writeFileSafe` creates\n  // parent directories automatically — no need to pre-mkdir.\n  const targets: { file: string; render: () => string }[] = []\n  if (wantsAgents) {\n    targets.push({\n      file: join(options.outDir, AGENTS_DIR, 'AGENTS.md'),\n      render: () => generateAgents(name, template, pm),\n    })\n  }\n  if (wantsClaude) {\n    targets.push({\n      file: join(options.outDir, 'CLAUDE.md'),\n      render: () => generateClaude(name, template, pm),\n    })\n  }\n  if (wantsSkills) {\n    // Per-skill SKILL.md under `.agents/skills/<slug>/` so agents that\n    // auto-discover skills (Claude Code, Copilot CLI plugins, Gemini's\n    // activate_skill) pick each up by its frontmatter without needing\n    // a separate index file.\n    for (const skill of generateKickJsSkillFiles(name, template, pm)) {\n      targets.push({\n        file: join(options.outDir, AGENTS_DIR, 'skills', skill.slug, 'SKILL.md'),\n        render: () => skill.content,\n      })\n    }\n  }\n  if (wantsGemini) {\n    targets.push({\n      file: join(options.outDir, AGENTS_DIR, 'GEMINI.md'),\n      render: () => generateGemini(name, template, pm),\n    })\n  }\n  if (wantsCopilot) {\n    targets.push({\n      file: join(options.outDir, AGENTS_DIR, 'COPILOT.md'),\n      render: () => generateCopilot(name, template, pm),\n    })\n  }\n\n  const written: string[] = []\n  for (const { file, render } of targets) {\n    if (existsSync(file) && !options.force) {\n      const overwrite = await confirm({\n        message: `${file.replace(options.outDir + '/', '')} already exists. Overwrite?`,\n        initialValue: false,\n      })\n      if (!overwrite) {\n        console.log(`  Skipped — existing ${file.replace(options.outDir + '/', '')} preserved.`)\n        continue\n      }\n    }\n    await writeFileSafe(file, render())\n    written.push(file)\n  }\n  return written\n}\n"],"mappings":";;;;;;;;;;uVA2BA,MAAM,EAAa,UA4Bb,EAAkB,IAAI,IAAqB,CAAC,OAAQ,UAAW,WAAW,CAAC,EAEjF,SAAS,EAAW,EAAgB,EAA2B,CAC7D,GAAI,EAAU,OAAO,EACrB,GAAI,CACF,IAAM,EAAM,KAAK,MAAM,EAAa,EAAK,EAAQ,cAAc,EAAG,OAAO,CAAC,EAC1E,GAAI,EAAI,KAAM,OAAO,EAAI,KAAK,QAAQ,YAAa,EAAE,CACvD,MAAQ,CAER,CACA,OAAO,EAAO,MAAM,GAAG,CAAC,CAAC,SAAS,OAAO,GAAK,KAChD,CAEA,SAAS,EAAS,EAA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