"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 caveman_exports = {};
__export(caveman_exports, {
  register: () => register
});
module.exports = __toCommonJS(caveman_exports);
var path = __toESM(require("path"));
var fs = __toESM(require("fs"));
var import_config = require("../../config");
var import_caveman = require("../installer/caveman");
var import_steering = require("../installer/steering");
var import_cli_agent = require("../installer/cli-agent");
var import_common = require("../installer/common");
var import_instructions = require("../installer/instructions");
var import_ui = require("../ui");
const JOKES = [
  "Ugh. Words hard. Code easy.",
  "Caveman not need article. Caveman have rock.",
  "Why say lot word when few word do trick?",
  "Token saved = mammoth fed.",
  "Caveman compress speech. Caveman also compress mammoth.",
  "Me not lazy. Me efficient.",
  "Short answer good answer. Long answer... ugh.",
  "Caveman invent fire. Caveman invent brief response.",
  "No filler word. Only meat.",
  "Grunt once. Mean much."
];
function joke() {
  const line = JOKES[Math.floor(Math.random() * JOKES.length)];
  return `
  ${import_ui.violet}\u{1FAA8}  ${line}${import_ui.reset}`;
}
const MODES = [
  { name: "off", desc: "normal responses" },
  { name: "lite", desc: "compact, no filler, full sentences" },
  { name: "full", desc: "fragments, no articles, short synonyms" },
  { name: "ultra", desc: "maximum compression, abbreviations, \u2192 for causality" }
];
function register(program) {
  program.command("caveman [mode]").description("Set caveman communication style for the Kiro agent (off | lite | full | ultra)").action(async (mode) => {
    const cwd = process.cwd();
    if (!mode) {
      let current = "off";
      try {
        const config = await (0, import_config.loadConfig)(cwd);
        current = config.cavemanMode ?? "off";
      } catch {
      }
      console.log();
      console.log(`  ${import_ui.dim}Caveman mode${import_ui.reset}  ${import_ui.violet}${import_ui.bold}${current}${import_ui.reset}`);
      console.log();
      console.log(`  ${import_ui.dim}Available modes:${import_ui.reset}`);
      for (const m of MODES) {
        const active = m.name === current;
        const marker = active ? `${import_ui.green}\u25CF${import_ui.reset}` : `${import_ui.dim}\u25CB${import_ui.reset}`;
        const nameStr = active ? `${import_ui.violet}${import_ui.bold}${m.name}${import_ui.reset}` : `${import_ui.dim}${m.name}${import_ui.reset}`;
        const nameW = m.name.length;
        const pad = " ".repeat(6 - nameW);
        console.log(`    ${marker} ${nameStr}${pad}${import_ui.dim}${m.desc}${import_ui.reset}`);
      }
      console.log();
      console.log(`  ${import_ui.dim}Change:${import_ui.reset} kg caveman ${import_ui.dim}<mode>${import_ui.reset}`);
      console.log(joke());
      console.log();
      return;
    }
    const normalized = mode.toLowerCase();
    const valid = MODES.map((m) => m.name);
    if (!valid.includes(normalized)) {
      console.error(`  ${import_ui.dim}Unknown mode:${import_ui.reset} ${normalized}${import_ui.dim}. Choose from: off, lite, full, ultra${import_ui.reset}`);
      process.exit(1);
    }
    await (0, import_config.updateConfig)(cwd, { cavemanMode: normalized });
    const kiroDir = path.join(cwd, ".kiro");
    const steeringPath = path.join(kiroDir, "steering", "kirograph.md");
    if (fs.existsSync(steeringPath)) {
      const config = await (0, import_config.loadConfig)(cwd);
      (0, import_steering.writeSteering)(kiroDir, {
        cavemanMode: normalized,
        enableCompression: config.shellCompressionLevel !== "off",
        shellCompressionLevel: config.shellCompressionLevel
      });
    }
    const agentPath = path.join(kiroDir, "agents", "kirograph.json");
    if (fs.existsSync(agentPath)) {
      (0, import_cli_agent.writeCliAgent)(kiroDir);
    }
    for (const file of ["claude.md", "codex.md"]) {
      const instructionsPath = path.join(cwd, ".kirograph", file);
      if (fs.existsSync(instructionsPath)) {
        fs.writeFileSync(instructionsPath, (0, import_instructions.buildAgentInstructions)(normalized));
      }
    }
    const agentsPath = path.join(cwd, "AGENTS.md");
    if (fs.existsSync(agentsPath) && fs.readFileSync(agentsPath, "utf8").includes("<!-- kirograph:codex:start -->")) {
      (0, import_common.upsertGeneratedBlock)(agentsPath, "codex", "## KiroGraph", (0, import_instructions.buildAgentInstructions)(normalized));
    }
    console.log();
    if (normalized === "off") {
      console.log(`  ${import_ui.green}\u2713${import_ui.reset} Caveman mode ${import_ui.violet}${import_ui.bold}off${import_ui.reset}${import_ui.dim} . Agent will respond normally from next session.${import_ui.reset}`);
      console.log(joke());
    } else {
      console.log(`  ${import_ui.green}\u2713${import_ui.reset} Caveman mode set to ${import_ui.violet}${import_ui.bold}${normalized}${import_ui.reset}`);
      console.log(`  ${import_ui.dim}Takes effect on next agent session.${import_ui.reset}`);
      console.log();
      console.log(`  ${import_ui.dim}Rules preview:${import_ui.reset}`);
      console.log();
      for (const line of import_caveman.CAVEMAN_RULES[normalized].split("\n")) {
        if (line.startsWith("## ")) {
          console.log(`  ${import_ui.violet}${import_ui.bold}${line.slice(3)}${import_ui.reset}`);
        } else if (line === "") {
          console.log();
        } else {
          console.log(`  ${import_ui.dim}${line}${import_ui.reset}`);
        }
      }
      console.log(joke());
    }
    console.log();
  });
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  register
});
//# sourceMappingURL=caveman.js.map
