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

// src/actions/claude-clean.ts
import {
  existsSync,
  readdirSync,
  rmSync,
  unlinkSync
} from "fs";
import PATH from "path";
import chalk from "chalk";
function removeFile(filePath, label) {
  if (existsSync(filePath)) {
    unlinkSync(filePath);
    console.log(chalk.yellow(`  Removed ${label}`));
    return true;
  }
  return false;
}
function removeDir(dirPath, label) {
  if (existsSync(dirPath)) {
    rmSync(dirPath, { recursive: true });
    console.log(chalk.yellow(`  Removed ${label}`));
    return true;
  }
  return false;
}
function claudeClean() {
  console.log(chalk.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(PATH.resolve(cwd, file), file)) removed++;
  }
  if (removeDir(PATH.resolve(cwd, ".claude"), ".claude/")) removed++;
  const packagesDir = PATH.resolve(cwd, "packages");
  if (existsSync(packagesDir)) {
    const findClaudeFiles = (dir, prefix) => {
      const entries = readdirSync(dir, { withFileTypes: true });
      for (const entry of entries) {
        const fullPath = PATH.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(chalk.green(`  Removed ${removed} item(s)`));
  } else {
    console.log(chalk.gray("  Nothing to clean"));
  }
  return 0;
}

// src/xy/common/claude/cleanCommand.ts
var cleanCommand = {
  command: "clean",
  describe: "Remove all Claude configuration files from the repo",
  handler: (argv) => {
    if (argv.verbose) console.log("Claude Clean");
    process.exitCode = claudeClean();
  }
};
export {
  cleanCommand
};
//# sourceMappingURL=cleanCommand.mjs.map