"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 codex_exports = {};
__export(codex_exports, {
  installCodexEarly: () => installCodexEarly,
  installCodexLate: () => installCodexLate,
  printCodexNextSteps: () => printCodexNextSteps,
  uninitCodex: () => uninitCodex
});
module.exports = __toCommonJS(codex_exports);
var fs = __toESM(require("fs"));
var path = __toESM(require("path"));
var import_common = require("../common");
var import_instructions = require("../instructions");
const CODEX_BLOCK_ID = "codex";
function installCodexEarly(_projectRoot) {
}
function installCodexLate(projectRoot, cavemanMode, _shellCompressionLevel, _enableMemory) {
  const instructionsPath = path.join(projectRoot, ".kirograph", "codex.md");
  (0, import_common.ensureDir)(path.dirname(instructionsPath));
  fs.writeFileSync(instructionsPath, (0, import_instructions.buildAgentInstructions)(cavemanMode));
  console.log(`  \u2713 Codex instructions written to ${instructionsPath}`);
  const agentsPath = path.join(projectRoot, "AGENTS.md");
  const changed = (0, import_common.upsertGeneratedBlock)(agentsPath, CODEX_BLOCK_ID, "## KiroGraph", (0, import_instructions.buildAgentInstructions)(cavemanMode));
  console.log(changed ? `  \u2713 Codex project instructions updated in ${agentsPath}` : `  \u2713 Codex project instructions already up to date`);
}
function uninitCodex(projectRoot) {
  const agentsPath = path.join(projectRoot, "AGENTS.md");
  if ((0, import_common.removeGeneratedBlock)(agentsPath, CODEX_BLOCK_ID)) {
    console.log(`  \u2713 Removed KiroGraph block from AGENTS.md`);
  }
}
function printCodexNextSteps(projectRoot) {
  const escapedPath = projectRoot.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
  console.log("\n  Done! Codex project instructions are installed.");
  console.log("  Add the MCP server to Codex with:");
  console.log(`    codex mcp add kirograph -- kirograph serve --mcp --path "${escapedPath}"`);
  console.log("\n  Or add this to ~/.codex/config.toml:");
  console.log("    [mcp_servers.kirograph]");
  console.log('    command = "kirograph"');
  console.log(`    args = ["serve", "--mcp", "--path", "${escapedPath}"]
`);
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  installCodexEarly,
  installCodexLate,
  printCodexNextSteps,
  uninitCodex
});
//# sourceMappingURL=codex.js.map
