"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 compression_exports = {};
__export(compression_exports, {
  register: () => register
});
module.exports = __toCommonJS(compression_exports);
var path = __toESM(require("path"));
var fs = __toESM(require("fs"));
var import_config = require("../../config");
var import_steering = require("../installer/steering");
var import_hooks = require("../installer/hooks");
var import_ui = require("../ui");
const LEVELS = [
  { name: "off", desc: "no compression hook or steering (tool still available)" },
  { name: "normal", desc: "balanced: removes noise, keeps structure" },
  { name: "aggressive", desc: "more compact: groups by category, limits output" },
  { name: "ultra", desc: "maximum compression: counts and summaries only" }
];
function register(program) {
  program.command("compression [level]").description("Set shell compression level for kirograph_exec (off | normal | aggressive | ultra)").action(async (level) => {
    const cwd = process.cwd();
    if (!level) {
      let current = "normal";
      try {
        const config2 = await (0, import_config.loadConfig)(cwd);
        current = config2.shellCompressionLevel ?? "normal";
      } catch {
      }
      console.log();
      console.log(`  ${import_ui.dim}Shell compression${import_ui.reset}  ${import_ui.violet}${import_ui.bold}${current}${import_ui.reset}`);
      console.log();
      console.log(`  ${import_ui.dim}Available levels:${import_ui.reset}`);
      for (const l of LEVELS) {
        const active = l.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}${l.name}${import_ui.reset}` : `${import_ui.dim}${l.name}${import_ui.reset}`;
        const nameW = l.name.length;
        const pad = " ".repeat(12 - nameW);
        console.log(`    ${marker} ${nameStr}${pad}${import_ui.dim}${l.desc}${import_ui.reset}`);
      }
      console.log();
      console.log(`  ${import_ui.dim}Change:${import_ui.reset} kg compression ${import_ui.dim}<level>${import_ui.reset}`);
      console.log();
      return;
    }
    const normalized = level.toLowerCase() === "on" ? "normal" : level.toLowerCase();
    const valid = LEVELS.map((l) => l.name);
    if (!valid.includes(normalized)) {
      console.error(`  ${import_ui.dim}Unknown level:${import_ui.reset} ${normalized}${import_ui.dim}. Choose from: off, normal, aggressive, ultra${import_ui.reset}`);
      process.exit(1);
    }
    const shellCompressionLevel = normalized;
    const config = await (0, import_config.updateConfig)(cwd, { shellCompressionLevel });
    const enableCompression = shellCompressionLevel !== "off";
    const kiroDir = path.join(cwd, ".kiro");
    const steeringPath = path.join(kiroDir, "steering", "kirograph.md");
    if (fs.existsSync(steeringPath)) {
      (0, import_steering.writeSteering)(kiroDir, { cavemanMode: config.cavemanMode, enableCompression, shellCompressionLevel });
    }
    const hooksDir = path.join(kiroDir, "hooks");
    if (fs.existsSync(hooksDir)) {
      (0, import_hooks.writeHooks)(kiroDir, { enableCompression });
    }
    console.log();
    if (shellCompressionLevel === "off") {
      console.log(`  ${import_ui.green}\u2713${import_ui.reset} Shell compression ${import_ui.violet}${import_ui.bold}off${import_ui.reset}`);
      console.log(`  ${import_ui.dim}kirograph_exec is still available but the agent won't be prompted to use it.${import_ui.reset}`);
      console.log(`  ${import_ui.dim}The compression hook and steering section have been removed.${import_ui.reset}`);
    } else {
      console.log(`  ${import_ui.green}\u2713${import_ui.reset} Shell compression set to ${import_ui.violet}${import_ui.bold}${shellCompressionLevel}${import_ui.reset}`);
      console.log(`  ${import_ui.dim}kirograph_exec will use "${shellCompressionLevel}" as the default level.${import_ui.reset}`);
      console.log(`  ${import_ui.dim}The agent will be guided to use it for git, test, lint, build, and docker commands.${import_ui.reset}`);
    }
    console.log(`  ${import_ui.dim}Takes effect on next agent session.${import_ui.reset}`);
    console.log();
  });
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  register
});
//# sourceMappingURL=compression.js.map
