"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 cline_exports = {};
__export(cline_exports, {
  installClineEarly: () => installClineEarly,
  installClineLate: () => installClineLate,
  printClineNextSteps: () => printClineNextSteps,
  uninitCline: () => uninitCline
});
module.exports = __toCommonJS(cline_exports);
var fs = __toESM(require("fs"));
var path = __toESM(require("path"));
var import_common = require("../common");
var import_instructions = require("../instructions");
const CLINE_RULES_FILE = "kirograph.md";
const CLINE_HOOK_SCRIPT = "#!/bin/sh\nkirograph sync --quiet 2>/dev/null || true\n";
function installClineEarly(_projectRoot) {
}
function installClineLate(projectRoot, cavemanMode, shellCompressionLevel, enableMemory) {
  const opts = (0, import_common.buildInstructionOpts)(cavemanMode, shellCompressionLevel, enableMemory, true);
  const instructionsPath = path.join(projectRoot, ".kirograph", "cline.md");
  (0, import_common.ensureDir)(path.dirname(instructionsPath));
  fs.writeFileSync(instructionsPath, (0, import_instructions.buildAgentInstructions)(opts));
  console.log(`  \u2713 Cline instructions written to ${instructionsPath}`);
  const rulesDir = path.join(projectRoot, ".clinerules");
  if (fs.existsSync(rulesDir) && fs.statSync(rulesDir).isFile()) {
    fs.unlinkSync(rulesDir);
  }
  (0, import_common.ensureDir)(rulesDir);
  const rulePath = path.join(rulesDir, CLINE_RULES_FILE);
  fs.writeFileSync(rulePath, (0, import_instructions.buildAgentInstructions)(opts));
  console.log(`  \u2713 Cline rule written to ${rulePath}`);
  const hooksDir = path.join(projectRoot, ".clinerules", "hooks");
  (0, import_common.ensureDir)(hooksDir);
  const hookPath = path.join(hooksDir, "task_completed");
  fs.writeFileSync(hookPath, CLINE_HOOK_SCRIPT, { mode: 493 });
  console.log(`  \u2713 Cline hook written to ${hookPath}`);
}
function uninitCline(projectRoot) {
  const rulePath = path.join(projectRoot, ".clinerules", CLINE_RULES_FILE);
  if (fs.existsSync(rulePath)) {
    fs.unlinkSync(rulePath);
    console.log(`  \u2713 Removed .clinerules/${CLINE_RULES_FILE}`);
  }
  const hookPath = path.join(projectRoot, ".clinerules", "hooks", "task_completed");
  if (fs.existsSync(hookPath)) {
    const content = fs.readFileSync(hookPath, "utf8");
    if (content.includes("kirograph")) {
      fs.unlinkSync(hookPath);
      console.log(`  \u2713 Removed Cline hook .clinerules/hooks/task_completed`);
    }
  }
}
function printClineNextSteps(projectRoot) {
  console.log("\n  Done! KiroGraph rule and hook are in .clinerules/");
  (0, import_common.printMcpSetup)("~/.cline/mcp.json", projectRoot);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  installClineEarly,
  installClineLate,
  printClineNextSteps,
  uninitCline
});
//# sourceMappingURL=cline.js.map
