"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var docker_exports = {};
__export(docker_exports, {
  dockerFilter: () => dockerFilter
});
module.exports = __toCommonJS(docker_exports);
const dockerFilter = {
  name: "docker",
  matches(command) {
    return /\b(docker|kubectl|podman)\b/.test(command);
  },
  filter(command, rawOutput, level) {
    if (/docker\s+ps/.test(command)) return filterDockerPs(rawOutput, level);
    if (/docker\s+images/.test(command)) return filterDockerImages(rawOutput, level);
    if (/docker\s+logs/.test(command)) return filterDockerLogs(rawOutput, level);
    if (/docker\s+compose\s+ps/.test(command)) return filterComposePs(rawOutput, level);
    if (/kubectl.*pods/.test(command) || /kubectl\s+get\s+po/.test(command)) return filterKubectlPods(rawOutput, level);
    if (/kubectl.*logs/.test(command)) return filterKubectlLogs(rawOutput, level);
    if (/kubectl.*services/.test(command) || /kubectl\s+get\s+svc/.test(command)) return filterKubectlServices(rawOutput, level);
    return { output: rawOutput, strategy: "docker:passthrough" };
  }
};
function filterDockerPs(raw, level) {
  const lines = raw.split("\n").filter((l) => l.trim());
  if (lines.length <= 1) return { output: "no containers running", strategy: "docker-ps:empty" };
  const header = lines[0];
  const rows = lines.slice(1);
  if (level === "ultra") {
    return { output: `${rows.length} containers running`, strategy: "docker-ps:ultra" };
  }
  const containers = rows.map((row) => {
    const parts = row.split(/\s{2,}/);
    const name = parts[parts.length - 1] || "";
    const status = parts.find((p) => /Up|Exited|Created/.test(p)) || "";
    const image = parts[1] || "";
    return { name: name.trim(), status: status.trim(), image: image.trim() };
  }).filter((c) => c.name);
  if (level === "aggressive") {
    const compact = containers.map((c) => `${c.name}: ${c.status}`).join("\n");
    return { output: `${containers.length} containers:
${compact}`, strategy: "docker-ps:compact" };
  }
  const detailed = containers.map((c) => `${c.name} (${c.image}) - ${c.status}`).join("\n");
  return { output: `${containers.length} containers:
${detailed}`, strategy: "docker-ps:detailed" };
}
function filterDockerImages(raw, level) {
  const lines = raw.split("\n").filter((l) => l.trim());
  if (lines.length <= 1) return { output: "no images", strategy: "docker-images:empty" };
  const rows = lines.slice(1);
  if (level === "ultra") {
    return { output: `${rows.length} images`, strategy: "docker-images:ultra" };
  }
  const images = rows.map((row) => {
    const parts = row.split(/\s{2,}/);
    return { repo: parts[0] || "", tag: parts[1] || "", size: parts[parts.length - 1] || "" };
  }).filter((i) => i.repo && i.repo !== "<none>");
  const compact = images.slice(0, level === "aggressive" ? 10 : 20).map((i) => `${i.repo}:${i.tag} (${i.size})`).join("\n");
  const extra = images.length > 20 ? `
\u2026+${images.length - 20} more` : "";
  return { output: `${images.length} images:
${compact}${extra}`, strategy: "docker-images:compact" };
}
function filterDockerLogs(raw, level) {
  return deduplicateLogLines(raw, level, "docker-logs");
}
function filterComposePs(raw, level) {
  const lines = raw.split("\n").filter((l) => l.trim());
  if (lines.length <= 1) return { output: "no services", strategy: "compose-ps:empty" };
  const rows = lines.slice(1);
  if (level === "ultra") {
    return { output: `${rows.length} services`, strategy: "compose-ps:ultra" };
  }
  return { output: lines.join("\n"), strategy: "compose-ps:table" };
}
function filterKubectlPods(raw, level) {
  const lines = raw.split("\n").filter((l) => l.trim());
  if (lines.length <= 1) return { output: "no pods", strategy: "kubectl-pods:empty" };
  const rows = lines.slice(1);
  if (level === "ultra") {
    const running = rows.filter((r) => r.includes("Running")).length;
    const other = rows.length - running;
    return { output: `${rows.length} pods (${running} running${other > 0 ? `, ${other} other` : ""})`, strategy: "kubectl-pods:ultra" };
  }
  const maxRows = level === "aggressive" ? 15 : 30;
  if (rows.length <= maxRows) return { output: raw, strategy: "kubectl-pods:short" };
  const shown = [lines[0], ...rows.slice(0, maxRows)].join("\n");
  return { output: `${shown}
\u2026+${rows.length - maxRows} more pods`, strategy: "kubectl-pods:truncated" };
}
function filterKubectlLogs(raw, level) {
  return deduplicateLogLines(raw, level, "kubectl-logs");
}
function filterKubectlServices(raw, level) {
  const lines = raw.split("\n").filter((l) => l.trim());
  if (lines.length <= 1) return { output: "no services", strategy: "kubectl-svc:empty" };
  if (level === "ultra") {
    return { output: `${lines.length - 1} services`, strategy: "kubectl-svc:ultra" };
  }
  return { output: raw, strategy: "kubectl-svc:table" };
}
function deduplicateLogLines(raw, level, prefix) {
  const lines = raw.split("\n");
  if (lines.length <= 20) return { output: raw, strategy: `${prefix}:short` };
  const result = [];
  let lastPattern = "";
  let repeatCount = 0;
  for (const line of lines) {
    const pattern = line.replace(/\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}:\d{2}[.\d]*Z?/g, "<ts>").replace(/\b\d+\b/g, "<n>");
    if (pattern === lastPattern) {
      repeatCount++;
    } else {
      if (repeatCount > 1) {
        result.push(`  \u2026repeated ${repeatCount} times`);
      }
      result.push(line);
      lastPattern = pattern;
      repeatCount = 1;
    }
  }
  if (repeatCount > 1) {
    result.push(`  \u2026repeated ${repeatCount} times`);
  }
  const maxLines = level === "ultra" ? 20 : level === "aggressive" ? 40 : 60;
  if (result.length <= maxLines) {
    return { output: result.join("\n"), strategy: `${prefix}:deduped` };
  }
  const shown = result.slice(-maxLines).join("\n");
  return { output: `\u2026(${result.length - maxLines} earlier lines omitted)
${shown}`, strategy: `${prefix}:deduped+truncated` };
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  dockerFilter
});
//# sourceMappingURL=docker.js.map
