// src/actions/claude-settings.ts
import {
  existsSync,
  mkdirSync,
  writeFileSync
} from "node:fs";
import PATH from "node:path";
import { createInterface } from "node:readline";
import chalk from "chalk";

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

// src/actions/claude-settings.ts
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 = PATH.resolve(cwd, ".claude");
  const settingsPath = PATH.resolve(claudeDir, "settings.local.json");
  mkdirSync(claudeDir, { recursive: true });
  if (existsSync(settingsPath)) {
    const confirmed = await askConfirmation(
      chalk.yellow(`${settingsPath} already exists. Replace it? (y/N) `)
    );
    if (!confirmed) {
      console.log(chalk.gray("Skipped \u2014 existing settings.local.json preserved"));
      return 0;
    }
  }
  const settings = buildSettings(level);
  writeFileSync(settingsPath, `${JSON.stringify(settings, null, 2)}
`, "utf8");
  console.log(chalk.green(`Generated .claude/settings.local.json (${level})`));
  return 0;
}
export {
  claudeSettings
};
//# sourceMappingURL=claude-settings.mjs.map
