"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 continue_exports = {};
__export(continue_exports, {
  installContinueEarly: () => installContinueEarly,
  installContinueLate: () => installContinueLate,
  printContinueNextSteps: () => printContinueNextSteps,
  uninitContinue: () => uninitContinue
});
module.exports = __toCommonJS(continue_exports);
var fs = __toESM(require("fs"));
var path = __toESM(require("path"));
var import_common = require("../common");
var import_instructions = require("../instructions");
const MCP_FILE = "kirograph.json";
const RULES_FILE = "kirograph.md";
function installContinueEarly(projectRoot) {
  const mcpDir = path.join(projectRoot, ".continue", "mcpServers");
  (0, import_common.ensureDir)(mcpDir);
  const mcpPath = path.join(mcpDir, MCP_FILE);
  const config = {
    mcpServers: {
      kirograph: {
        command: import_common.KIROGRAPH_COMMAND,
        args: import_common.KIROGRAPH_MCP_ARGS
      }
    }
  };
  (0, import_common.writeJson)(mcpPath, config);
  console.log(`  \u2713 Continue MCP server registered in ${mcpPath}`);
}
function installContinueLate(projectRoot, cavemanMode, shellCompressionLevel, enableMemory) {
  const opts = (0, import_common.buildInstructionOpts)(cavemanMode, shellCompressionLevel, enableMemory);
  const instructionsPath = path.join(projectRoot, ".kirograph", "continue.md");
  (0, import_common.ensureDir)(path.dirname(instructionsPath));
  fs.writeFileSync(instructionsPath, (0, import_instructions.buildAgentInstructions)(opts));
  console.log(`  \u2713 Continue instructions written to ${instructionsPath}`);
  const rulesDir = path.join(projectRoot, ".continue", "rules");
  (0, import_common.ensureDir)(rulesDir);
  const rulePath = path.join(rulesDir, RULES_FILE);
  fs.writeFileSync(rulePath, (0, import_instructions.buildAgentInstructions)(opts));
  console.log(`  \u2713 Continue rule written to ${rulePath}`);
}
function uninitContinue(projectRoot) {
  const mcpPath = path.join(projectRoot, ".continue", "mcpServers", MCP_FILE);
  if (fs.existsSync(mcpPath)) {
    fs.unlinkSync(mcpPath);
    console.log(`  \u2713 Removed .continue/mcpServers/${MCP_FILE}`);
  }
  const rulePath = path.join(projectRoot, ".continue", "rules", RULES_FILE);
  if (fs.existsSync(rulePath)) {
    fs.unlinkSync(rulePath);
    console.log(`  \u2713 Removed .continue/rules/${RULES_FILE}`);
  }
  const legacyPath = path.join(projectRoot, ".continue", "config.json");
  if (fs.existsSync(legacyPath)) {
    try {
      const config = JSON.parse(fs.readFileSync(legacyPath, "utf8"));
      if (config.mcpServers?.kirograph) {
        delete config.mcpServers.kirograph;
        if (Object.keys(config.mcpServers).length === 0) delete config.mcpServers;
        fs.writeFileSync(legacyPath, JSON.stringify(config, null, 2) + "\n");
        console.log(`  \u2713 Removed legacy kirograph from .continue/config.json`);
      }
    } catch {
    }
  }
}
function printContinueNextSteps() {
  console.log("\n  Done! Restart Continue for the MCP server to load.");
  console.log("  MCP is in .continue/mcpServers/kirograph.json");
  console.log("  KiroGraph rule is in .continue/rules/kirograph.md\n");
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  installContinueEarly,
  installContinueLate,
  printContinueNextSteps,
  uninitContinue
});
//# sourceMappingURL=continue.js.map
