// src/lib/claudeMdTemplate.ts
import {
  readdirSync,
  readFileSync,
  statSync
} from "node:fs";
import { createRequire } from "node:module";
import PATH from "node:path";
var require2 = createRequire(import.meta.url);
var packageRoot = PATH.dirname(require2.resolve("@xylabs/toolchain/package.json"));
var templatesDir = PATH.resolve(packageRoot, "templates", "claude");
function applyPackageManager(content, pm) {
  const xyCommand = pm === "npm" ? "npm exec -- xy" : pm === "bun" ? "bun run xy" : `${pm} xy`;
  const addCommand = pm === "npm" ? "npm install" : pm === "bun" ? "bun add" : `${pm} add`;
  return content.replaceAll("yarn xy", xyCommand).replaceAll("pnpm xy", xyCommand).replaceAll("yarn add", addCommand).replaceAll("pnpm add", addCommand);
}
var XYLABS_RULES_PREFIX = "xylabs-";
var XYLABS_COMMANDS_PREFIX = "xy-";
var LEGACY_COMMANDS_PREFIX = "xylabs-";
var XYLABS_SKILLS_PREFIX = "xylabs-";
var claudeMdRuleTemplates = () => {
  const rulesDir = PATH.resolve(templatesDir, "rules");
  const files = readdirSync(rulesDir).filter((f) => f.startsWith(XYLABS_RULES_PREFIX) && f.endsWith(".md"));
  const result = {};
  for (const file of files) {
    result[file] = readFileSync(PATH.resolve(rulesDir, file), "utf8");
  }
  return result;
};
var claudeCommandTemplates = () => {
  const commandsDir = PATH.resolve(templatesDir, "commands");
  const files = readdirSync(commandsDir).filter((f) => f.startsWith(XYLABS_COMMANDS_PREFIX) && f.endsWith(".md"));
  const result = {};
  for (const file of files) {
    result[file] = readFileSync(PATH.resolve(commandsDir, file), "utf8");
  }
  return result;
};
var claudeSkillTemplates = () => {
  const skillsDir = PATH.resolve(templatesDir, "skills");
  const dirs = readdirSync(skillsDir).filter(
    (f) => f.startsWith(XYLABS_SKILLS_PREFIX) && statSync(PATH.resolve(skillsDir, f)).isDirectory()
  );
  const result = {};
  for (const dir of dirs) {
    const dirPath = PATH.resolve(skillsDir, dir);
    const files = readdirSync(dirPath, { recursive: true, encoding: "utf8" });
    result[dir] = {};
    for (const file of files) {
      if (statSync(PATH.resolve(dirPath, file)).isFile()) {
        result[dir][file] = readFileSync(PATH.resolve(dirPath, file), "utf8");
      }
    }
  }
  return result;
};
var claudeMdLocalTemplate = () => readFileSync(PATH.resolve(templatesDir, "CLAUDE-local.md"), "utf8");

// src/lib/crossSpawn.ts
import crossSpawn from "cross-spawn";
function spawnSync(command, args, options) {
  return crossSpawn.sync(command, args, options);
}

// src/pm/workspaces.ts
import { existsSync, readFileSync as readFileSync2 } from "node:fs";
import PATH2 from "node:path";
import { globSync } from "glob";
function readJsonFile(path) {
  if (!existsSync(path)) return void 0;
  try {
    return JSON.parse(readFileSync2(path, "utf8"));
  } catch {
    return void 0;
  }
}
function readRootPackageJson(cwd = process.cwd()) {
  return readJsonFile(PATH2.resolve(cwd, "package.json"));
}
function detectPackageManagerFromPackageJson(cwd = process.cwd()) {
  const packageManager = readRootPackageJson(cwd)?.packageManager;
  if (!packageManager) return void 0;
  return packageManager.split("@")[0];
}

// src/pm/detectPackageManager.ts
import { existsSync as existsSync2 } from "node:fs";
var knownPackageManagers = /* @__PURE__ */ new Set(["bun", "npm", "pnpm", "yarn"]);
function detectPackageManager() {
  const packageManager = detectPackageManagerFromPackageJson();
  if (packageManager && knownPackageManagers.has(packageManager)) {
    return packageManager;
  }
  if (existsSync2("pnpm-lock.yaml") || existsSync2("pnpm-workspace.yaml")) return "pnpm";
  if (existsSync2("bun.lock") || existsSync2("bun.lockb")) return "bun";
  if (existsSync2("yarn.lock") || existsSync2(".yarnrc.yml")) return "yarn";
  if (existsSync2("package-lock.json") || existsSync2("npm-shrinkwrap.json")) return "npm";
  return "yarn";
}

// src/lib/initCwd.ts
function INIT_CWD() {
  return process.env.INIT_CWD ?? process.cwd();
}

// src/lib/reporting/runWithEnvelope.ts
import { performance as performance2 } from "node:perf_hooks";

// src/lib/reporting/xyReporter.ts
import { performance } from "node:perf_hooks";
var jsonMode = false;
var originalStdoutWrite;
var envelopeEmitted = false;
var currentCommand = "unknown";
var startTime = 0;
function isJsonMode() {
  return jsonMode;
}
function setCurrentCommand(name) {
  currentCommand = name;
  startTime = performance.now();
  envelopeEmitted = false;
}
function emitJson(envelope) {
  if (envelopeEmitted) return;
  envelopeEmitted = true;
  const json = JSON.stringify(envelope) + "\n";
  if (originalStdoutWrite) {
    originalStdoutWrite(json);
  } else {
    process.stdout.write(json);
  }
}

// src/lib/reporting/runWithEnvelope.ts
async function runWithEnvelope(command, action) {
  setCurrentCommand(command);
  const start = performance2.now();
  let exitCode;
  let envelope;
  try {
    const ret = await action();
    if (typeof ret === "number") {
      exitCode = ret;
    } else {
      exitCode = ret.exitCode;
      envelope = ret.envelope;
    }
  } catch (ex) {
    exitCode = 1;
    const message = ex instanceof Error ? ex.message : String(ex);
    envelope = {
      errorCount: 1,
      errors: [{ message }]
    };
    if (!isJsonMode()) {
      console.error(message);
    }
  }
  if (isJsonMode()) {
    emitJson({
      command,
      data: envelope?.data,
      durationMs: Math.round(performance2.now() - start),
      errorCount: envelope?.errorCount ?? (exitCode === 0 ? 0 : 1),
      errors: envelope?.errors,
      exitCode,
      schemaVersion: 1,
      success: exitCode === 0,
      warningCount: envelope?.warningCount ?? 0,
      warnings: envelope?.warnings
    });
  }
  return exitCode;
}
async function withEnvelope(command, action) {
  process.exitCode = await runWithEnvelope(command, action);
}

// src/actions/claude-check.ts
import {
  existsSync as existsSync3,
  readdirSync as readdirSync2,
  readFileSync as readFileSync3,
  statSync as statSync2
} from "node:fs";
import PATH3 from "node:path";
import chalk from "chalk";
var checkCommands = (commandsDir) => {
  const pm = detectPackageManager();
  const rawTemplates = claudeCommandTemplates();
  const templates = {};
  for (const [name, content] of Object.entries(rawTemplates)) {
    templates[name] = applyPackageManager(content, pm);
  }
  const missing = [];
  const outdated = [];
  for (const [filename, content] of Object.entries(templates)) {
    const targetPath = PATH3.resolve(commandsDir, filename);
    if (!existsSync3(targetPath)) {
      missing.push(filename);
    } else if (readFileSync3(targetPath, "utf8") !== content) {
      outdated.push(filename);
    }
  }
  const templateNames = new Set(Object.keys(templates));
  const stale = existsSync3(commandsDir) ? readdirSync2(commandsDir).filter((f) => f.startsWith(XYLABS_COMMANDS_PREFIX) && f.endsWith(".md") && !templateNames.has(f)) : [];
  return {
    missing,
    outdated,
    stale
  };
};
var checkRules = (rulesDir) => {
  const pm = detectPackageManager();
  const rawTemplates = claudeMdRuleTemplates();
  const templates = {};
  for (const [name, content] of Object.entries(rawTemplates)) {
    templates[name] = applyPackageManager(content, pm);
  }
  const missing = [];
  const outdated = [];
  for (const [filename, content] of Object.entries(templates)) {
    const targetPath = PATH3.resolve(rulesDir, filename);
    if (!existsSync3(targetPath)) {
      missing.push(filename);
    } else if (readFileSync3(targetPath, "utf8") !== content) {
      outdated.push(filename);
    }
  }
  const templateNames = new Set(Object.keys(templates));
  const stale = existsSync3(rulesDir) ? readdirSync2(rulesDir).filter((f) => f.startsWith(XYLABS_RULES_PREFIX) && f.endsWith(".md") && !templateNames.has(f)) : [];
  return {
    missing,
    outdated,
    stale
  };
};
var checkSkills = (skillsDir) => {
  const pm = detectPackageManager();
  const rawTemplates = claudeSkillTemplates();
  const missing = [];
  const outdated = [];
  for (const [skillName, files] of Object.entries(rawTemplates)) {
    const skillDir = PATH3.resolve(skillsDir, skillName);
    if (!existsSync3(skillDir)) {
      missing.push(skillName);
      continue;
    }
    for (const [filename, rawContent] of Object.entries(files)) {
      const content = applyPackageManager(rawContent, pm);
      const targetPath = PATH3.resolve(skillDir, filename);
      if (!existsSync3(targetPath)) {
        missing.push(`${skillName}/${filename}`);
      } else if (readFileSync3(targetPath, "utf8") !== content) {
        outdated.push(`${skillName}/${filename}`);
      }
    }
  }
  const templateNames = new Set(Object.keys(rawTemplates));
  const stale = existsSync3(skillsDir) ? readdirSync2(skillsDir).filter(
    (f) => f.startsWith(XYLABS_SKILLS_PREFIX) && statSync2(PATH3.resolve(skillsDir, f)).isDirectory() && !templateNames.has(f)
  ) : [];
  return {
    missing,
    outdated,
    stale
  };
};
var logSection = (label, result) => {
  const issues = [...result.missing, ...result.outdated, ...result.stale];
  if (issues.length === 0) {
    console.log(chalk.green(`  \u2714 ${label}`));
    return true;
  }
  console.log(chalk.red(`  \u2718 ${label}`));
  for (const file of result.missing) {
    console.log(chalk.yellow(`      missing: ${file}`));
  }
  for (const file of result.outdated) {
    console.log(chalk.yellow(`      outdated: ${file}`));
  }
  for (const file of result.stale) {
    console.log(chalk.yellow(`      stale: ${file}`));
  }
  return false;
};
function claudeCheck() {
  const cwd = INIT_CWD();
  const claudeDir = PATH3.resolve(cwd, ".claude");
  console.log(chalk.bold("Claude configuration check:"));
  console.log();
  const commandsResult = checkCommands(PATH3.resolve(claudeDir, "commands"));
  const rulesResult = checkRules(PATH3.resolve(claudeDir, "rules"));
  const skillsResult = checkSkills(PATH3.resolve(claudeDir, "skills"));
  const commandsOk = logSection("commands", commandsResult);
  const rulesOk = logSection("rules", rulesResult);
  const skillsOk = logSection("skills", skillsResult);
  console.log();
  if (commandsOk && rulesOk && skillsOk) {
    console.log(chalk.green("All Claude configuration is up to date."));
  } else {
    console.log(chalk.yellow("Run `xy claude init` to sync all configuration."));
  }
  return 0;
}

// src/actions/claude-clean.ts
import {
  existsSync as existsSync4,
  readdirSync as readdirSync3,
  rmSync,
  unlinkSync
} from "node:fs";
import PATH4 from "node:path";
import chalk2 from "chalk";
function removeFile(filePath, label) {
  if (existsSync4(filePath)) {
    unlinkSync(filePath);
    console.log(chalk2.yellow(`  Removed ${label}`));
    return true;
  }
  return false;
}
function removeDir(dirPath, label) {
  if (existsSync4(dirPath)) {
    rmSync(dirPath, { recursive: true });
    console.log(chalk2.yellow(`  Removed ${label}`));
    return true;
  }
  return false;
}
function claudeClean() {
  console.log(chalk2.green("Clean Claude configuration"));
  const cwd = INIT_CWD();
  let removed = 0;
  const rootFiles = ["CLAUDE.md", "CLAUDE.local.md"];
  for (const file of rootFiles) {
    if (removeFile(PATH4.resolve(cwd, file), file)) removed++;
  }
  if (removeDir(PATH4.resolve(cwd, ".claude"), ".claude/")) removed++;
  const packagesDir = PATH4.resolve(cwd, "packages");
  if (existsSync4(packagesDir)) {
    const findClaudeFiles = (dir, prefix) => {
      const entries = readdirSync3(dir, { withFileTypes: true });
      for (const entry of entries) {
        const fullPath = PATH4.resolve(dir, entry.name);
        const label = `${prefix}${entry.name}`;
        if (entry.isFile() && (entry.name === "CLAUDE.md" || entry.name === "CLAUDE.local.md")) {
          if (removeFile(fullPath, label)) removed++;
        } else if (entry.isDirectory() && entry.name === ".claude") {
          if (removeDir(fullPath, `${label}/`)) removed++;
        } else if (entry.isDirectory() && entry.name !== "node_modules" && entry.name !== "dist") {
          findClaudeFiles(fullPath, `${label}/`);
        }
      }
    };
    findClaudeFiles(packagesDir, "packages/");
  }
  if (removed > 0) {
    console.log(chalk2.green(`  Removed ${removed} item(s)`));
  } else {
    console.log(chalk2.gray("  Nothing to clean"));
  }
  return 0;
}

// src/actions/claude-commands.ts
import {
  existsSync as existsSync5,
  mkdirSync,
  readdirSync as readdirSync4,
  readFileSync as readFileSync4,
  unlinkSync as unlinkSync2,
  writeFileSync
} from "node:fs";
import PATH5 from "node:path";
import chalk3 from "chalk";
var syncCommandFiles = (commandsDir) => {
  const pm = detectPackageManager();
  const rawTemplates = claudeCommandTemplates();
  const templates = {};
  for (const [name, content] of Object.entries(rawTemplates)) {
    templates[name] = applyPackageManager(content, pm);
  }
  const templateNames = new Set(Object.keys(templates));
  let updated = 0;
  let created = 0;
  for (const [filename, content] of Object.entries(templates)) {
    const targetPath = PATH5.resolve(commandsDir, filename);
    const existing = existsSync5(targetPath) ? readFileSync4(targetPath, "utf8") : void 0;
    if (existing === content) continue;
    writeFileSync(targetPath, content, "utf8");
    if (existing) {
      updated++;
    } else {
      created++;
    }
  }
  return {
    created,
    templateNames,
    updated
  };
};
var removeStaleCommands = (commandsDir, templateNames) => {
  const existingCommands = readdirSync4(commandsDir).filter((f) => f.startsWith(XYLABS_COMMANDS_PREFIX) && f.endsWith(".md"));
  let removed = 0;
  for (const file of existingCommands) {
    if (!templateNames.has(file)) {
      unlinkSync2(PATH5.resolve(commandsDir, file));
      removed++;
    }
  }
  return removed;
};
var removeLegacyCommands = (commandsDir) => {
  const legacyFiles = readdirSync4(commandsDir).filter((f) => f.startsWith(LEGACY_COMMANDS_PREFIX) && f.endsWith(".md"));
  for (const file of legacyFiles) {
    unlinkSync2(PATH5.resolve(commandsDir, file));
  }
  return legacyFiles.length;
};
var logCommandsResult = (created, updated, removed) => {
  if (created || updated || removed) {
    const parts = [
      created ? `${created} created` : "",
      updated ? `${updated} updated` : "",
      removed ? `${removed} removed` : ""
    ].filter(Boolean);
    console.log(chalk3.green(`.claude/commands/${XYLABS_COMMANDS_PREFIX}*.md: ${parts.join(", ")}`));
  } else {
    console.log(chalk3.gray(`.claude/commands/${XYLABS_COMMANDS_PREFIX}*.md: already up to date`));
  }
};
var claudeCommands = () => {
  const cwd = INIT_CWD();
  const commandsDir = PATH5.resolve(cwd, ".claude", "commands");
  mkdirSync(commandsDir, { recursive: true });
  const legacy = removeLegacyCommands(commandsDir);
  const {
    created,
    templateNames,
    updated
  } = syncCommandFiles(commandsDir);
  const removed = removeStaleCommands(commandsDir, templateNames);
  logCommandsResult(created, updated, removed + legacy);
  return 0;
};

// src/actions/claude-rules.ts
import {
  existsSync as existsSync6,
  mkdirSync as mkdirSync2,
  readdirSync as readdirSync5,
  readFileSync as readFileSync5,
  unlinkSync as unlinkSync3,
  writeFileSync as writeFileSync2
} from "node:fs";
import PATH6 from "node:path";
import chalk4 from "chalk";
var syncRuleFiles = (rulesDir) => {
  const pm = detectPackageManager();
  const rawTemplates = claudeMdRuleTemplates();
  const templates = {};
  for (const [name, content] of Object.entries(rawTemplates)) {
    templates[name] = applyPackageManager(content, pm);
  }
  const templateNames = new Set(Object.keys(templates));
  let updated = 0;
  let created = 0;
  for (const [filename, content] of Object.entries(templates)) {
    const targetPath = PATH6.resolve(rulesDir, filename);
    const existing = existsSync6(targetPath) ? readFileSync5(targetPath, "utf8") : void 0;
    if (existing === content) continue;
    writeFileSync2(targetPath, content, "utf8");
    if (existing) {
      updated++;
    } else {
      created++;
    }
  }
  return {
    created,
    templateNames,
    updated
  };
};
var removeStaleRules = (rulesDir, templateNames) => {
  const existingRules = readdirSync5(rulesDir).filter((f) => f.startsWith(XYLABS_RULES_PREFIX) && f.endsWith(".md"));
  let removed = 0;
  for (const file of existingRules) {
    if (!templateNames.has(file)) {
      unlinkSync3(PATH6.resolve(rulesDir, file));
      removed++;
    }
  }
  return removed;
};
var logRulesResult = (created, updated, removed) => {
  if (created || updated || removed) {
    const parts = [
      created ? `${created} created` : "",
      updated ? `${updated} updated` : "",
      removed ? `${removed} removed` : ""
    ].filter(Boolean);
    console.log(chalk4.green(`.claude/rules/${XYLABS_RULES_PREFIX}*.md: ${parts.join(", ")}`));
  } else {
    console.log(chalk4.gray(`.claude/rules/${XYLABS_RULES_PREFIX}*.md: already up to date`));
  }
};
var ensureProjectClaudeMd = (cwd, force) => {
  const projectPath = PATH6.resolve(cwd, "CLAUDE.md");
  if (!existsSync6(projectPath) || force) {
    if (force && existsSync6(projectPath)) {
      console.log(chalk4.yellow("Regenerating CLAUDE.md"));
    }
    console.log(chalk4.green("Generating CLAUDE.md via claude /init..."));
    const result = spawnSync("claude", ["-p", "/init", "--allowedTools", "Read", "Write", "Glob", "Grep"], {
      cwd,
      stdio: "inherit"
    });
    if (result.status !== 0) {
      console.error(chalk4.red("claude /init failed \u2014 is Claude Code installed?"));
      return 1;
    }
  } else {
    console.log(chalk4.gray("CLAUDE.md already exists (skipped, use --force to regenerate)"));
  }
  return 0;
};
var ensureLocalClaudeMd = (cwd) => {
  const localPath = PATH6.resolve(cwd, "CLAUDE.local.md");
  if (existsSync6(localPath)) {
    console.log(chalk4.gray("CLAUDE.local.md already exists (skipped)"));
  } else {
    writeFileSync2(localPath, claudeMdLocalTemplate(), "utf8");
    console.log(chalk4.green("Generated CLAUDE.local.md"));
  }
};
var claudeRules = ({ force } = {}) => {
  const cwd = INIT_CWD();
  const rulesDir = PATH6.resolve(cwd, ".claude", "rules");
  mkdirSync2(rulesDir, { recursive: true });
  const {
    created,
    templateNames,
    updated
  } = syncRuleFiles(rulesDir);
  const removed = removeStaleRules(rulesDir, templateNames);
  logRulesResult(created, updated, removed);
  const claudeMdResult = ensureProjectClaudeMd(cwd, force);
  ensureLocalClaudeMd(cwd);
  return claudeMdResult ?? 0;
};

// src/actions/claude-settings.ts
import {
  existsSync as existsSync7,
  mkdirSync as mkdirSync3,
  writeFileSync as writeFileSync3
} from "node:fs";
import PATH7 from "node:path";
import { createInterface } from "node:readline";
import chalk5 from "chalk";
var DENY_LIST = [
  "Bash(git push --force *)",
  "Bash(git reset --hard *)",
  "Bash(rm -rf /*)"
];
var RESTRICTIVE_ALLOW = [
  "Bash(git *)",
  "Bash(yarn *)",
  "Bash(pnpm *)",
  "Bash(npx *)",
  "Bash(ls *)",
  "Bash(mkdir *)",
  "Bash(cp *)",
  "Bash(mv *)",
  "Bash(rm *)",
  "Bash(cat *)",
  "Bash(head *)",
  "Bash(tail *)",
  "Bash(echo *)",
  "Bash(pwd)",
  "Bash(which *)",
  "Bash(grep *)",
  "Bash(find *)",
  "Bash(wc *)",
  "Bash(npm view *)",
  "Bash(gh *)",
  "Read",
  "Edit",
  "Write",
  "Glob",
  "Grep",
  "Skill"
];
var PERMISSIVE_ALLOW = [
  ...RESTRICTIVE_ALLOW,
  "Bash(node *)",
  "Bash(python3 *)",
  "Bash(claude *)",
  "Bash(sed *)",
  "Bash(xargs *)",
  "Bash(tee *)"
];
function buildSettings(level) {
  return {
    permissions: {
      allow: level === "restrictive" ? RESTRICTIVE_ALLOW : PERMISSIVE_ALLOW,
      deny: DENY_LIST
    }
  };
}
function askConfirmation(question) {
  const rl = createInterface({ input: process.stdin, output: process.stdout });
  return new Promise((resolve) => {
    rl.question(question, (answer) => {
      rl.close();
      resolve(answer.toLowerCase() === "y" || answer.toLowerCase() === "yes");
    });
  });
}
async function claudeSettings({ level = "permissive" } = {}) {
  const cwd = INIT_CWD();
  const claudeDir = PATH7.resolve(cwd, ".claude");
  const settingsPath = PATH7.resolve(claudeDir, "settings.local.json");
  mkdirSync3(claudeDir, { recursive: true });
  if (existsSync7(settingsPath)) {
    const confirmed = await askConfirmation(
      chalk5.yellow(`${settingsPath} already exists. Replace it? (y/N) `)
    );
    if (!confirmed) {
      console.log(chalk5.gray("Skipped \u2014 existing settings.local.json preserved"));
      return 0;
    }
  }
  const settings = buildSettings(level);
  writeFileSync3(settingsPath, `${JSON.stringify(settings, null, 2)}
`, "utf8");
  console.log(chalk5.green(`Generated .claude/settings.local.json (${level})`));
  return 0;
}

// src/actions/claude-skills.ts
import {
  existsSync as existsSync8,
  mkdirSync as mkdirSync4,
  readdirSync as readdirSync6,
  readFileSync as readFileSync6,
  rmSync as rmSync2,
  statSync as statSync3,
  writeFileSync as writeFileSync4
} from "node:fs";
import PATH8 from "node:path";
import chalk6 from "chalk";
var syncSkillFiles = (skillsDir) => {
  const pm = detectPackageManager();
  const rawTemplates = claudeSkillTemplates();
  const templateNames = new Set(Object.keys(rawTemplates));
  let updated = 0;
  let created = 0;
  for (const [skillName, files] of Object.entries(rawTemplates)) {
    const skillDir = PATH8.resolve(skillsDir, skillName);
    mkdirSync4(skillDir, { recursive: true });
    for (const [filename, rawContent] of Object.entries(files)) {
      const content = applyPackageManager(rawContent, pm);
      const targetPath = PATH8.resolve(skillDir, filename);
      mkdirSync4(PATH8.dirname(targetPath), { recursive: true });
      const existing = existsSync8(targetPath) ? readFileSync6(targetPath, "utf8") : void 0;
      if (existing === content) continue;
      writeFileSync4(targetPath, content, "utf8");
      if (existing) {
        updated++;
      } else {
        created++;
      }
    }
  }
  return {
    created,
    templateNames,
    updated
  };
};
var removeStaleSkills = (skillsDir, templateNames) => {
  const existingSkills = readdirSync6(skillsDir).filter(
    (f) => f.startsWith(XYLABS_SKILLS_PREFIX) && statSync3(PATH8.resolve(skillsDir, f)).isDirectory()
  );
  let removed = 0;
  for (const dir of existingSkills) {
    if (!templateNames.has(dir)) {
      rmSync2(PATH8.resolve(skillsDir, dir), { recursive: true });
      removed++;
    }
  }
  return removed;
};
var logSkillsResult = (created, updated, removed) => {
  if (created || updated || removed) {
    const parts = [
      created ? `${created} created` : "",
      updated ? `${updated} updated` : "",
      removed ? `${removed} removed` : ""
    ].filter(Boolean);
    console.log(chalk6.green(`.claude/skills/${XYLABS_SKILLS_PREFIX}*/: ${parts.join(", ")}`));
  } else {
    console.log(chalk6.gray(`.claude/skills/${XYLABS_SKILLS_PREFIX}*/: already up to date`));
  }
};
var claudeSkills = () => {
  const cwd = INIT_CWD();
  const skillsDir = PATH8.resolve(cwd, ".claude", "skills");
  mkdirSync4(skillsDir, { recursive: true });
  const {
    created,
    templateNames,
    updated
  } = syncSkillFiles(skillsDir);
  const removed = removeStaleSkills(skillsDir, templateNames);
  logSkillsResult(created, updated, removed);
  return 0;
};

// src/xy/common/claude/checkCommand.ts
var checkCommand = {
  command: "check",
  describe: "Check if Claude configuration is up to date with templates",
  handler: async (argv) => {
    if (argv.verbose) console.log("Claude Check");
    await withEnvelope("claude check", () => claudeCheck());
  }
};

// src/xy/common/claude/cleanCommand.ts
var cleanCommand = {
  command: "clean",
  describe: "Remove all Claude configuration files from the repo",
  handler: async (argv) => {
    if (argv.verbose) console.log("Claude Clean");
    await withEnvelope("claude clean", () => claudeClean());
  }
};

// src/xy/common/claude/commandsCommand.ts
var commandsCommand = {
  command: "commands",
  describe: "Sync XY Labs standard Claude slash commands to .claude/commands/",
  handler: async (argv) => {
    if (argv.verbose) console.log("Claude Commands");
    await withEnvelope("claude commands", () => claudeCommands());
  }
};

// src/xy/common/claude/initCommand.ts
var initCommand = {
  builder: (yargs) => {
    return yargs.option("force", {
      alias: "f",
      default: false,
      description: "Overwrite existing CLAUDE.md",
      type: "boolean"
    }).option("level", {
      choices: ["restrictive", "permissive"],
      default: "permissive",
      description: "Permission level for settings (restrictive omits node, python3, claude, sed, xargs, tee)",
      type: "string"
    });
  },
  command: "init",
  describe: "Initialize all Claude configuration (commands, rules, skills, settings)",
  handler: async (argv) => {
    if (argv.verbose) console.log("Claude Init");
    await withEnvelope("claude init", async () => {
      const commandsResult = claudeCommands();
      const rulesResult = claudeRules({ force: argv.force });
      const skillsResult = claudeSkills();
      const settingsResult = await claudeSettings({ level: argv.level });
      return commandsResult || rulesResult || skillsResult || settingsResult;
    });
  }
};

// src/xy/common/claude/rulesCommand.ts
var rulesCommand = {
  builder: (yargs) => {
    return yargs.option("force", {
      alias: "f",
      default: false,
      description: "Overwrite existing CLAUDE.md",
      type: "boolean"
    });
  },
  command: "rules",
  describe: "Sync XY Labs standard Claude rules to .claude/rules/",
  handler: async (argv) => {
    if (argv.verbose) console.log("Claude Rules");
    await withEnvelope("claude rules", () => claudeRules({ force: argv.force }));
  }
};

// src/xy/common/claude/settingsCommand.ts
var settingsCommand = {
  builder: (yargs) => {
    return yargs.option("level", {
      choices: ["restrictive", "permissive"],
      default: "permissive",
      description: "Permission level (restrictive omits node, python3, claude, sed, xargs, tee)",
      type: "string"
    });
  },
  command: "settings",
  describe: "Initialize .claude/settings.local.json with XY Labs defaults",
  handler: async (argv) => {
    if (argv.verbose) console.log("Claude Settings");
    await withEnvelope("claude settings", () => claudeSettings({ level: argv.level }));
  }
};

// src/xy/common/claude/skillsCommand.ts
var skillsCommand = {
  builder: (yargs) => yargs,
  command: "skills",
  describe: "Sync XY Labs standard Claude skills to .claude/skills/",
  handler: async (argv) => {
    if (argv.verbose) console.log("Claude Skills");
    await withEnvelope("claude skills", () => claudeSkills());
  }
};

// src/xy/common/claude/index.ts
var claudeCommand = {
  builder: (yargs) => {
    return yargs.command(checkCommand).command(cleanCommand).command(commandsCommand).command(initCommand).command(rulesCommand).command(settingsCommand).command(skillsCommand).demandCommand(1, "Please specify a claude subcommand").strictCommands();
  },
  command: "claude",
  describe: "Claude - Claude Code configuration utilities",
  handler: () => {
  }
};
export {
  claudeCommand
};
//# sourceMappingURL=index.mjs.map
