"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 amp_exports = {};
__export(amp_exports, {
  installAmpEarly: () => installAmpEarly,
  installAmpLate: () => installAmpLate,
  printAmpNextSteps: () => printAmpNextSteps,
  uninitAmp: () => uninitAmp
});
module.exports = __toCommonJS(amp_exports);
var fs = __toESM(require("fs"));
var path = __toESM(require("path"));
var import_common = require("../common");
var import_instructions = require("../instructions");
var import_common2 = require("../common");
function installAmpEarly(projectRoot) {
  const configPath = path.join(projectRoot, ".amp", "config.json");
  (0, import_common.ensureDir)(path.dirname(configPath));
  const config = (0, import_common.readJson)(configPath);
  config.mcpServers = config.mcpServers ?? {};
  config.mcpServers[import_common.KIROGRAPH_SERVER_NAME] = {
    command: import_common.KIROGRAPH_COMMAND,
    args: import_common.KIROGRAPH_MCP_ARGS
  };
  (0, import_common.writeJson)(configPath, config);
  console.log(`  \u2713 Sourcegraph Amp MCP server registered in ${configPath}`);
}
function installAmpLate(projectRoot, cavemanMode, shellCompressionLevel, enableMemory) {
  const instructionsPath = path.join(projectRoot, ".kirograph", "amp.md");
  (0, import_common.ensureDir)(path.dirname(instructionsPath));
  fs.writeFileSync(instructionsPath, (0, import_instructions.buildAgentInstructions)((0, import_common2.buildInstructionOpts)(cavemanMode, shellCompressionLevel, enableMemory)));
  console.log(`  \u2713 Amp instructions written to ${instructionsPath}`);
  const ampInstructionsPath = path.join(projectRoot, ".amp", "instructions.md");
  (0, import_common.ensureDir)(path.dirname(ampInstructionsPath));
  fs.writeFileSync(ampInstructionsPath, (0, import_instructions.buildAgentInstructions)((0, import_common2.buildInstructionOpts)(cavemanMode, shellCompressionLevel, enableMemory)));
  console.log(`  \u2713 Amp instructions written to ${ampInstructionsPath}`);
}
function uninitAmp(projectRoot) {
  const configPath = path.join(projectRoot, ".amp", "config.json");
  if (fs.existsSync(configPath)) {
    const config = (0, import_common.readJson)(configPath);
    if (config.mcpServers?.[import_common.KIROGRAPH_SERVER_NAME]) {
      delete config.mcpServers[import_common.KIROGRAPH_SERVER_NAME];
      (0, import_common.writeJson)(configPath, config);
      console.log(`  \u2713 Removed kirograph from .amp/config.json`);
    }
  }
  const ampInstructionsPath = path.join(projectRoot, ".amp", "instructions.md");
  if (fs.existsSync(ampInstructionsPath)) {
    fs.unlinkSync(ampInstructionsPath);
    console.log(`  \u2713 Removed .amp/instructions.md`);
  }
}
function printAmpNextSteps() {
  console.log("\n  Done! Restart Sourcegraph Amp for the MCP server to load.");
  console.log("  KiroGraph instructions are in .amp/instructions.md\n");
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  installAmpEarly,
  installAmpLate,
  printAmpNextSteps,
  uninitAmp
});
//# sourceMappingURL=amp.js.map
