"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 kilo_exports = {};
__export(kilo_exports, {
  installKiloEarly: () => installKiloEarly,
  installKiloLate: () => installKiloLate,
  printKiloNextSteps: () => printKiloNextSteps,
  uninitKilo: () => uninitKilo
});
module.exports = __toCommonJS(kilo_exports);
var fs = __toESM(require("fs"));
var path = __toESM(require("path"));
var import_common = require("../common");
var import_instructions = require("../instructions");
const KILO_MCP_NAME = "kirograph";
const KILO_RULES_FILE = ".kilo/rules/kirograph.md";
function installKiloEarly(projectRoot) {
  const configPath = path.join(projectRoot, "kilo.json");
  const config = (0, import_common.readJson)(configPath);
  config.mcp = config.mcp ?? {};
  config.mcp[KILO_MCP_NAME] = {
    type: "local",
    command: [import_common.KIROGRAPH_COMMAND, ...import_common.KIROGRAPH_MCP_ARGS],
    enabled: true
  };
  (0, import_common.writeJson)(configPath, config);
  console.log(`  \u2713 Kilo Code MCP server registered in ${configPath}`);
}
function installKiloLate(projectRoot, cavemanMode, shellCompressionLevel, enableMemory) {
  const opts = (0, import_common.buildInstructionOpts)(cavemanMode, shellCompressionLevel, enableMemory);
  const instructionsPath = path.join(projectRoot, ".kirograph", "kilo.md");
  (0, import_common.ensureDir)(path.dirname(instructionsPath));
  fs.writeFileSync(instructionsPath, (0, import_instructions.buildAgentInstructions)(opts));
  console.log(`  \u2713 Kilo Code instructions written to ${instructionsPath}`);
  const rulesDir = path.join(projectRoot, ".kilo", "rules");
  (0, import_common.ensureDir)(rulesDir);
  const rulePath = path.join(rulesDir, "kirograph.md");
  fs.writeFileSync(rulePath, (0, import_instructions.buildAgentInstructions)(opts));
  console.log(`  \u2713 Kilo Code rule written to ${rulePath}`);
  const jsoncPath = path.join(projectRoot, "kilo.jsonc");
  const jsonPath = path.join(projectRoot, "kilo.json");
  const cfgPath = fs.existsSync(jsoncPath) ? jsoncPath : jsonPath;
  const cfg = (0, import_common.readJson)(cfgPath);
  const instructions = cfg.instructions ?? [];
  if (!instructions.includes(KILO_RULES_FILE)) {
    instructions.push(KILO_RULES_FILE);
  }
  cfg.instructions = instructions;
  (0, import_common.writeJson)(cfgPath, cfg);
  console.log(`  \u2713 Kilo Code instructions referenced in ${cfgPath}`);
}
function uninitKilo(projectRoot) {
  const configPath = path.join(projectRoot, "kilo.json");
  if (fs.existsSync(configPath)) {
    const config = (0, import_common.readJson)(configPath);
    if (config.mcp?.[KILO_MCP_NAME]) {
      delete config.mcp[KILO_MCP_NAME];
      if (Object.keys(config.mcp).length === 0) delete config.mcp;
      (0, import_common.writeJson)(configPath, config);
      console.log(`  \u2713 Removed kirograph from kilo.json mcp`);
    }
  }
  const jsoncPath = path.join(projectRoot, "kilo.jsonc");
  const jsonPath = path.join(projectRoot, "kilo.json");
  const cfgPath = fs.existsSync(jsoncPath) ? jsoncPath : jsonPath;
  if (fs.existsSync(cfgPath)) {
    const cfg = (0, import_common.readJson)(cfgPath);
    if (Array.isArray(cfg.instructions)) {
      const idx = cfg.instructions.indexOf(KILO_RULES_FILE);
      if (idx !== -1) {
        cfg.instructions.splice(idx, 1);
        if (cfg.instructions.length === 0) delete cfg.instructions;
        (0, import_common.writeJson)(cfgPath, cfg);
        console.log(`  \u2713 Removed kirograph instructions from ${cfgPath}`);
      }
    }
  }
  const rulePath = path.join(projectRoot, ".kilo", "rules", "kirograph.md");
  if (fs.existsSync(rulePath)) {
    fs.unlinkSync(rulePath);
    console.log(`  \u2713 Removed .kilo/rules/kirograph.md`);
  }
}
function printKiloNextSteps() {
  console.log("\n  Done! Restart Kilo Code for the MCP server to load.");
  console.log("  MCP is in kilo.json");
  console.log("  KiroGraph rule is in .kilo/rules/kirograph.md\n");
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  installKiloEarly,
  installKiloLate,
  printKiloNextSteps,
  uninitKilo
});
//# sourceMappingURL=kilo.js.map
