"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 github_exports = {};
__export(github_exports, {
  githubFilter: () => githubFilter
});
module.exports = __toCommonJS(github_exports);
const githubFilter = {
  name: "gh",
  matches(command) {
    return /\bgh\s/.test(command);
  },
  filter(command, rawOutput, level) {
    if (/gh\s+pr\s+list/.test(command)) return filterPrList(rawOutput, level);
    if (/gh\s+pr\s+view/.test(command)) return filterPrView(rawOutput, level);
    if (/gh\s+pr\s+checks/.test(command)) return filterPrChecks(rawOutput, level);
    if (/gh\s+issue\s+list/.test(command)) return filterIssueList(rawOutput, level);
    if (/gh\s+run\s+list/.test(command)) return filterRunList(rawOutput, level);
    if (/gh\s+run\s+view/.test(command)) return filterRunView(rawOutput, level);
    return { output: rawOutput, strategy: "gh:passthrough" };
  }
};
function filterPrList(raw, level) {
  const lines = raw.split("\n").filter((l) => l.trim());
  if (lines.length === 0) return { output: "no open PRs", strategy: "gh:pr-list:empty" };
  if (level === "ultra") {
    return { output: `${lines.length} PRs`, strategy: "gh:pr-list:ultra" };
  }
  const compact = lines.map((l) => {
    const parts = l.split("	");
    if (parts.length >= 3) {
      const [num, title, branch] = parts;
      return `#${num} ${title} (${branch})`;
    }
    return l;
  });
  const maxLines = level === "aggressive" ? 10 : 20;
  const shown = compact.slice(0, maxLines).join("\n");
  const extra = compact.length > maxLines ? `
\u2026+${compact.length - maxLines} more` : "";
  return { output: `${compact.length} PRs:
${shown}${extra}`, strategy: "gh:pr-list" };
}
function filterPrView(raw, level) {
  const lines = raw.split("\n");
  if (level === "ultra") {
    const titleLine = lines.find((l) => l.startsWith("title:") || /^#\d+/.test(l.trim()));
    const stateLine = lines.find((l) => l.includes("OPEN") || l.includes("MERGED") || l.includes("CLOSED"));
    return { output: (titleLine || lines[0] || "").trim() + (stateLine ? ` [${stateLine.trim()}]` : ""), strategy: "gh:pr-view:ultra" };
  }
  const important = lines.filter((l) => {
    const trimmed = l.trim();
    if (!trimmed) return false;
    if (trimmed.startsWith("--")) return false;
    return true;
  });
  const maxLines = level === "aggressive" ? 20 : 40;
  if (important.length <= maxLines) return { output: important.join("\n"), strategy: "gh:pr-view" };
  return { output: important.slice(0, maxLines).join("\n") + `
\u2026+${important.length - maxLines} more lines`, strategy: "gh:pr-view" };
}
function filterPrChecks(raw, level) {
  const lines = raw.split("\n").filter((l) => l.trim());
  if (lines.length === 0) return { output: "no checks", strategy: "gh:pr-checks:empty" };
  const passed = lines.filter((l) => l.includes("pass") || l.includes("\u2713")).length;
  const failed = lines.filter((l) => l.includes("fail") || l.includes("\u2717") || l.includes("X")).length;
  if (level === "ultra") {
    return { output: failed > 0 ? `\u2717 ${failed} failed, ${passed} passed` : `\u2713 ${passed} passed`, strategy: "gh:pr-checks:ultra" };
  }
  return { output: raw, strategy: "gh:pr-checks" };
}
function filterIssueList(raw, level) {
  const lines = raw.split("\n").filter((l) => l.trim());
  if (lines.length === 0) return { output: "no open issues", strategy: "gh:issue-list:empty" };
  if (level === "ultra") {
    return { output: `${lines.length} issues`, strategy: "gh:issue-list:ultra" };
  }
  const compact = lines.map((l) => {
    const parts = l.split("	");
    if (parts.length >= 3) {
      const [num, title] = parts;
      return `#${num} ${title}`;
    }
    return l;
  });
  const maxLines = level === "aggressive" ? 10 : 20;
  const shown = compact.slice(0, maxLines).join("\n");
  const extra = compact.length > maxLines ? `
\u2026+${compact.length - maxLines} more` : "";
  return { output: `${compact.length} issues:
${shown}${extra}`, strategy: "gh:issue-list" };
}
function filterRunList(raw, level) {
  const lines = raw.split("\n").filter((l) => l.trim());
  if (lines.length === 0) return { output: "no runs", strategy: "gh:run-list:empty" };
  if (level === "ultra") {
    const failed = lines.filter((l) => l.includes("failure") || l.includes("X")).length;
    return { output: failed > 0 ? `${lines.length} runs (${failed} failed)` : `${lines.length} runs`, strategy: "gh:run-list:ultra" };
  }
  const maxLines = level === "aggressive" ? 10 : 20;
  const shown = lines.slice(0, maxLines).join("\n");
  const extra = lines.length > maxLines ? `
\u2026+${lines.length - maxLines} more` : "";
  return { output: `${shown}${extra}`, strategy: "gh:run-list" };
}
function filterRunView(raw, level) {
  const lines = raw.split("\n").filter((l) => l.trim());
  if (level === "ultra") {
    const statusLine = lines.find((l) => l.includes("completed") || l.includes("in_progress") || l.includes("failure"));
    return { output: statusLine || lines[0] || "", strategy: "gh:run-view:ultra" };
  }
  const maxLines = level === "aggressive" ? 20 : 40;
  if (lines.length <= maxLines) return { output: raw, strategy: "gh:run-view" };
  return { output: lines.slice(0, maxLines).join("\n") + `
\u2026+${lines.length - maxLines} more`, strategy: "gh:run-view" };
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  githubFilter
});
//# sourceMappingURL=github.js.map
