"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var uninit_exports = {};
__export(uninit_exports, {
  UNINIT_FAREWELLS: () => UNINIT_FAREWELLS,
  register: () => register
});
module.exports = __toCommonJS(uninit_exports);
var path = __toESM(require("path"));
var fs = __toESM(require("fs"));
var readline = __toESM(require("readline"));
var import_banner = require("../banner");
var import_ui = require("../ui");
var import_prompts = require("../installer/prompts");
const UNINIT_FAREWELLS = [
  "Oh. So it's come to this.",
  "We're sorry to see you go. (Are we? Yes. We are.)",
  "Deleting months of carefully indexed knowledge. Bold move.",
  "Fine. We'll just sit here in the dark.",
  "You can always come back. We won't mention this.",
  "The graph remembers everything. Except, soon, anything.",
  "Somewhere a tree-sitter is crying.",
  "Uninstalling... and pretending it doesn't hurt.",
  "574 embeddings. Gone. Just like that.",
  "See you on the other side of `kirograph install`."
];
const UNINIT_TARGETS = ["kiro", "claude", "codex", "all"];
async function runUninit(projectPath, opts) {
  const target = path.resolve(projectPath ?? process.cwd());
  const integration = (opts.target ?? "kiro").toLowerCase();
  if (!UNINIT_TARGETS.includes(integration)) {
    console.error(`Unknown uninit target: ${opts.target}. Choose from: kiro, claude, codex, all`);
    process.exit(1);
  }
  const dir = path.join(target, ".kirograph");
  if (!fs.existsSync(dir)) {
    console.log("Not initialized.");
    return;
  }
  let removeIntegration = true;
  let removeGraph = opts.force === true;
  if (!opts.force) {
    (0, import_banner.printBanner)();
    const farewell = UNINIT_FAREWELLS[Math.floor(Math.random() * UNINIT_FAREWELLS.length)];
    console.log(`  ${import_ui.violet}${import_ui.bold}${farewell}${import_ui.reset}`);
    console.log(`
  ${import_ui.dim}This can remove ${integration} integration files and, separately, the shared .kirograph/ data.${import_ui.reset}`);
    console.log(`  ${import_ui.dim}Your source code is untouched.${import_ui.reset}`);
    const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
    removeIntegration = await (0, import_prompts.askToggle)(rl, `Remove ${integration} integration files?`, "Removes hooks, steering, MCP config, and agent instructions for this target.", false);
    removeGraph = await (0, import_prompts.askToggle)(rl, "Remove shared .kirograph/ data too?", "Deletes the graph database, snapshots, and all indexed data. Cannot be undone.", false);
    rl.close();
    if (!removeIntegration && !removeGraph) {
      console.log(`
  ${import_ui.dim}Cancelled. Nothing removed.${import_ui.reset}
`);
      return;
    }
    console.log();
  }
  if (removeGraph) {
    fs.rmSync(dir, { recursive: true, force: true });
    console.log(`  ${import_ui.green}\u2713${import_ui.reset} Removed .kirograph/`);
  }
  if (removeIntegration && (integration === "kiro" || integration === "all")) {
    const kiroHooks = [
      "kirograph-mark-dirty-on-save.kiro.hook",
      "kirograph-mark-dirty-on-create.kiro.hook",
      "kirograph-sync-on-delete.kiro.hook",
      "kirograph-sync-if-dirty.kiro.hook",
      "kirograph-compress-hint.kiro.hook",
      "kirograph-mem-capture.kiro.hook",
      // Legacy .json filenames
      "kirograph-mark-dirty-on-save.json",
      "kirograph-mark-dirty-on-create.json",
      "kirograph-sync-on-delete.json",
      "kirograph-sync-if-dirty.json",
      "kirograph-sync-on-save.json",
      "kirograph-sync-on-create.json",
      "kirograph-compress-hint.json",
      "kirograph-mem-capture.json"
    ];
    const hooksDir = path.join(target, ".kiro", "hooks");
    let removedHooks = 0;
    for (const hook of kiroHooks) {
      const p = path.join(hooksDir, hook);
      if (fs.existsSync(p)) {
        fs.unlinkSync(p);
        removedHooks++;
      }
    }
    if (removedHooks > 0) console.log(`  ${import_ui.green}\u2713${import_ui.reset} Removed ${removedHooks} hook(s) from .kiro/hooks/`);
    const steeringPath = path.join(target, ".kiro", "steering", "kirograph.md");
    if (fs.existsSync(steeringPath)) {
      fs.unlinkSync(steeringPath);
      console.log(`  ${import_ui.green}\u2713${import_ui.reset} Removed .kiro/steering/kirograph.md`);
    }
    const agentPath = path.join(target, ".kiro", "agents", "kirograph.json");
    if (fs.existsSync(agentPath)) {
      fs.unlinkSync(agentPath);
      console.log(`  ${import_ui.green}\u2713${import_ui.reset} Removed .kiro/agents/kirograph.json`);
    }
    const { removeMcpServersConfig } = await Promise.resolve().then(() => require("../installer/common.js"));
    const mcpPath = path.join(target, ".kiro", "settings", "mcp.json");
    if (removeMcpServersConfig(mcpPath)) {
      console.log(`  ${import_ui.green}\u2713${import_ui.reset} Removed kirograph from .kiro/settings/mcp.json`);
    }
  }
  if (removeIntegration && (integration === "claude" || integration === "all")) {
    const { uninitClaude } = await Promise.resolve().then(() => require("../installer/targets/claude.js"));
    uninitClaude(target);
  }
  if (removeIntegration && (integration === "codex" || integration === "all")) {
    const { uninitCodex } = await Promise.resolve().then(() => require("../installer/targets/codex.js"));
    uninitCodex(target);
  }
  console.log(`
  ${import_ui.dim}Done. Run ${import_ui.violet}kirograph install --target ${integration === "all" ? "kiro" : integration}${import_ui.reset}${import_ui.dim} to come back anytime.${import_ui.reset}
`);
}
function register(program) {
  program.command("uninit [projectPath]").description("Remove KiroGraph from a project").option("--force", "Skip confirmation").option("--target <target>", "Integration target to clean up: kiro, claude, codex, or all", "kiro").action(runUninit);
  program.command("uninstall [projectPath]").description("Alias for uninit. Remove KiroGraph from a project").option("--force", "Skip confirmation").option("--target <target>", "Integration target to clean up: kiro, claude, codex, or all", "kiro").action(runUninit);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  UNINIT_FAREWELLS,
  register
});
//# sourceMappingURL=uninit.js.map
