// @bun
import {
  init_staticRender,
  renderToAnsiString
} from "./chunk-9zyj24r6.js";
import {
  exports_operations,
  init_operations
} from "./chunk-dz7nc6rf.js";
import {
  BASH_TOOL_NAME,
  FILE_READ_TOOL_NAME,
  GREP_TOOL_NAME,
  WEB_FETCH_TOOL_NAME,
  analyzeContextUsage,
  exports_contextCollapse,
  getMessagesAfterCompactBoundary,
  init_analyzeContext,
  init_contextCollapse,
  init_messages1 as init_messages,
  init_microCompact,
  init_prompt,
  init_prompt1 as init_prompt2,
  init_prompt4 as init_prompt3,
  init_toolName,
  microcompactMessages
} from "./chunk-421yegj3.js";
import"./chunk-aaxz8a5g.js";
import"./chunk-2kcgxnvp.js";
import"./chunk-14p6wvsq.js";
import"./chunk-6s0q1s5r.js";
import"./chunk-0cpg8qh8.js";
import"./chunk-9phn5khx.js";
import"./chunk-vk9xcryd.js";
import"./chunk-9a9g5hbj.js";
import"./chunk-ptxteaeh.js";
import"./chunk-7fcmqvbz.js";
import"./chunk-rgyzsbs3.js";
import"./chunk-q3b4n194.js";
import"./chunk-zaqfb3tz.js";
import"./chunk-6hzx0kqr.js";
import"./chunk-71sdcaq6.js";
import"./chunk-9hn8e6h1.js";
import"./chunk-dxa3y9vh.js";
import"./chunk-gjvhjywj.js";
import"./chunk-1w20m7gw.js";
import"./chunk-3gam18xn.js";
import"./chunk-rpmntgyh.js";
import"./chunk-24kv69g3.js";
import"./chunk-tzcrwnrf.js";
import"./chunk-k7xszak2.js";
import"./chunk-ztmb7geg.js";
import"./chunk-tbdkekz3.js";
import"./chunk-65zbgg1n.js";
import"./chunk-4spgkgr3.js";
import"./chunk-60fkafk2.js";
import"./chunk-h5zz0vxy.js";
import"./chunk-6hygvrhn.js";
import"./chunk-7tfdhkpy.js";
import"./chunk-8gv2pjby.js";
import"./chunk-pn23dh3d.js";
import"./chunk-rpdh02rm.js";
import"./chunk-j1wktfe2.js";
import"./chunk-fjtzfz1t.js";
import"./chunk-6hr7742d.js";
import"./chunk-xyg1sk2w.js";
import"./chunk-935nrvdb.js";
import"./chunk-8zz4z1q3.js";
import"./chunk-hem4f4gz.js";
import"./chunk-hqxp6b72.js";
import"./chunk-ccw8pse0.js";
import"./chunk-wsnxtggw.js";
import"./chunk-k8nwt8yq.js";
import"./chunk-vxbjzggp.js";
import"./chunk-d6h68rz1.js";
import"./chunk-8yvsnrkr.js";
import"./chunk-5mmhfbxb.js";
import {
  getDisplayPath,
  getSourceDisplayName,
  init_constants,
  init_file,
  init_stringUtils,
  plural
} from "./chunk-s2t5anwv.js";
import"./chunk-ga1jkyqy.js";
import"./chunk-9hbhydvp.js";
import"./chunk-ck9r8hpf.js";
import"./chunk-k7hexw3v.js";
import"./chunk-trqrj23e.js";
import"./chunk-za3k6h2h.js";
import"./chunk-8kf8h7xf.js";
import"./chunk-bgan4cpf.js";
import"./chunk-jmv7k0jn.js";
import"./chunk-hjxqmtg5.js";
import"./chunk-bzyzrq0k.js";
import"./chunk-vwenx8ke.js";
import"./chunk-q2h79ncs.js";
import"./chunk-v4ypszbb.js";
import"./chunk-qfsn720k.js";
import"./chunk-7qx3xhv3.js";
import"./chunk-j9475b46.js";
import"./chunk-fdwabr8p.js";
import"./chunk-e4dsy4g1.js";
import"./chunk-326zehp8.js";
import"./chunk-kc67kt75.js";
import"./chunk-40t1d75v.js";
import"./chunk-dbts5q5p.js";
import"./chunk-e3abfxpy.js";
import"./chunk-q44zc68f.js";
import"./chunk-fejeqe61.js";
import {
  formatTokens,
  init_format
} from "./chunk-q1vrhh0q.js";
import"./chunk-hn4w9pkj.js";
import {
  StatusIcon,
  ThemedBox_default,
  ThemedText,
  init_src
} from "./chunk-2g0ytd9d.js";
import {
  require_jsx_dev_runtime
} from "./chunk-de0qnnf7.js";
import"./chunk-j1mep9ck.js";
import"./chunk-6x35ffpx.js";
import"./chunk-1zbwhcbt.js";
import"./chunk-92bjkrf2.js";
import"./chunk-10k5jfc5.js";
import"./chunk-n9g24mwe.js";
import"./chunk-e3j7m7k2.js";
import"./chunk-hzmzwte2.js";
import"./chunk-pdvg91cg.js";
import"./chunk-c696122m.js";
import"./chunk-xbj5keyy.js";
import"./chunk-c1yc761e.js";
import {
  figures_default,
  init_figures
} from "./chunk-c5g9shkw.js";
import"./chunk-aeysytks.js";
import"./chunk-s3hafnk3.js";
import"./chunk-kb3758f7.js";
import"./chunk-9h9k5vz3.js";
import"./chunk-xmpgmeb8.js";
import"./chunk-2kz09j2s.js";
import"./chunk-c0k7b0jw.js";
import"./chunk-pecy49yr.js";
import"./chunk-azbab59e.js";
import"./chunk-3nk9q8dr.js";
import {
  __esm,
  __toCommonJS,
  __toESM
} from "./chunk-hhsxm2yr.js";

// src/utils/contextSuggestions.ts
function generateContextSuggestions(data) {
  const suggestions = [];
  checkNearCapacity(data, suggestions);
  checkLargeToolResults(data, suggestions);
  checkReadResultBloat(data, suggestions);
  checkMemoryBloat(data, suggestions);
  checkAutoCompactDisabled(data, suggestions);
  suggestions.sort((a, b) => {
    if (a.severity !== b.severity) {
      return a.severity === "warning" ? -1 : 1;
    }
    return (b.savingsTokens ?? 0) - (a.savingsTokens ?? 0);
  });
  return suggestions;
}
function checkNearCapacity(data, suggestions) {
  if (data.percentage >= NEAR_CAPACITY_PERCENT) {
    suggestions.push({
      severity: "warning",
      title: `Context is ${data.percentage}% full`,
      detail: data.isAutoCompactEnabled ? "Autocompact will trigger soon, which discards older messages. Use /compact now to control what gets kept." : "Autocompact is disabled. Use /compact to free space, or enable autocompact in /config."
    });
  }
}
function checkLargeToolResults(data, suggestions) {
  if (!data.messageBreakdown)
    return;
  for (const tool of data.messageBreakdown.toolCallsByType) {
    const totalToolTokens = tool.callTokens + tool.resultTokens;
    const percent = totalToolTokens / data.rawMaxTokens * 100;
    if (percent < LARGE_TOOL_RESULT_PERCENT || totalToolTokens < LARGE_TOOL_RESULT_TOKENS) {
      continue;
    }
    const suggestion = getLargeToolSuggestion(tool.name, totalToolTokens, percent);
    if (suggestion) {
      suggestions.push(suggestion);
    }
  }
}
function getLargeToolSuggestion(toolName, tokens, percent) {
  const tokenStr = formatTokens(tokens);
  switch (toolName) {
    case BASH_TOOL_NAME:
      return {
        severity: "warning",
        title: `Bash results using ${tokenStr} tokens (${percent.toFixed(0)}%)`,
        detail: "Pipe output through head, tail, or grep to reduce result size. Avoid cat on large files \u2014 use Read with offset/limit instead.",
        savingsTokens: Math.floor(tokens * 0.5)
      };
    case FILE_READ_TOOL_NAME:
      return {
        severity: "info",
        title: `Read results using ${tokenStr} tokens (${percent.toFixed(0)}%)`,
        detail: "Use offset and limit parameters to read only the sections you need. Avoid re-reading entire files when you only need a few lines.",
        savingsTokens: Math.floor(tokens * 0.3)
      };
    case GREP_TOOL_NAME:
      return {
        severity: "info",
        title: `Grep results using ${tokenStr} tokens (${percent.toFixed(0)}%)`,
        detail: "Add more specific patterns or use the glob or type parameter to narrow file types. Consider Glob for file discovery instead of Grep.",
        savingsTokens: Math.floor(tokens * 0.3)
      };
    case WEB_FETCH_TOOL_NAME:
      return {
        severity: "info",
        title: `WebFetch results using ${tokenStr} tokens (${percent.toFixed(0)}%)`,
        detail: "Web page content can be very large. Consider extracting only the specific information needed.",
        savingsTokens: Math.floor(tokens * 0.4)
      };
    default:
      if (percent >= 20) {
        return {
          severity: "info",
          title: `${toolName} using ${tokenStr} tokens (${percent.toFixed(0)}%)`,
          detail: `This tool is consuming a significant portion of context.`,
          savingsTokens: Math.floor(tokens * 0.2)
        };
      }
      return null;
  }
}
function checkReadResultBloat(data, suggestions) {
  if (!data.messageBreakdown)
    return;
  const callsByType = data.messageBreakdown.toolCallsByType;
  const readTool = callsByType.find((t) => t.name === FILE_READ_TOOL_NAME);
  if (!readTool)
    return;
  const totalReadTokens = readTool.callTokens + readTool.resultTokens;
  const totalReadPercent = totalReadTokens / data.rawMaxTokens * 100;
  const readPercent = readTool.resultTokens / data.rawMaxTokens * 100;
  if (totalReadPercent >= LARGE_TOOL_RESULT_PERCENT && totalReadTokens >= LARGE_TOOL_RESULT_TOKENS) {
    return;
  }
  if (readPercent >= READ_BLOAT_PERCENT && readTool.resultTokens >= LARGE_TOOL_RESULT_TOKENS) {
    suggestions.push({
      severity: "info",
      title: `File reads using ${formatTokens(readTool.resultTokens)} tokens (${readPercent.toFixed(0)}%)`,
      detail: "If you are re-reading files, consider referencing earlier reads. Use offset/limit for large files.",
      savingsTokens: Math.floor(readTool.resultTokens * 0.3)
    });
  }
}
function checkMemoryBloat(data, suggestions) {
  const totalMemoryTokens = data.memoryFiles.reduce((sum, f) => sum + f.tokens, 0);
  const memoryPercent = totalMemoryTokens / data.rawMaxTokens * 100;
  if (memoryPercent >= MEMORY_HIGH_PERCENT && totalMemoryTokens >= MEMORY_HIGH_TOKENS) {
    const largestFiles = [...data.memoryFiles].sort((a, b) => b.tokens - a.tokens).slice(0, 3).map((f) => {
      const name = getDisplayPath(f.path);
      return `${name} (${formatTokens(f.tokens)})`;
    }).join(", ");
    suggestions.push({
      severity: "info",
      title: `Memory files using ${formatTokens(totalMemoryTokens)} tokens (${memoryPercent.toFixed(0)}%)`,
      detail: `Largest: ${largestFiles}. Use /memory to review and prune stale entries.`,
      savingsTokens: Math.floor(totalMemoryTokens * 0.3)
    });
  }
}
function checkAutoCompactDisabled(data, suggestions) {
  if (!data.isAutoCompactEnabled && data.percentage >= 50 && data.percentage < NEAR_CAPACITY_PERCENT) {
    suggestions.push({
      severity: "info",
      title: "Autocompact is disabled",
      detail: "Without autocompact, you will hit context limits and lose the conversation. Enable it in /config or use /compact manually."
    });
  }
}
var LARGE_TOOL_RESULT_PERCENT = 15, LARGE_TOOL_RESULT_TOKENS = 1e4, READ_BLOAT_PERCENT = 5, NEAR_CAPACITY_PERCENT = 80, MEMORY_HIGH_PERCENT = 5, MEMORY_HIGH_TOKENS = 5000;
var init_contextSuggestions = __esm(() => {
  init_toolName();
  init_prompt2();
  init_prompt();
  init_prompt3();
  init_file();
  init_format();
});

// src/components/ContextSuggestions.tsx
function ContextSuggestions({ suggestions }) {
  if (suggestions.length === 0)
    return null;
  return /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ThemedBox_default, {
    flexDirection: "column",
    marginTop: 1,
    children: [
      /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ThemedText, {
        bold: true,
        children: "Suggestions"
      }, undefined, false, undefined, this),
      suggestions.map((suggestion, i) => /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ThemedBox_default, {
        flexDirection: "column",
        marginTop: i === 0 ? 0 : 1,
        children: [
          /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ThemedBox_default, {
            children: [
              /* @__PURE__ */ jsx_dev_runtime.jsxDEV(StatusIcon, {
                status: suggestion.severity,
                withSpace: true
              }, undefined, false, undefined, this),
              /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ThemedText, {
                bold: true,
                children: suggestion.title
              }, undefined, false, undefined, this),
              suggestion.savingsTokens ? /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ThemedText, {
                dimColor: true,
                children: [
                  " ",
                  figures_default.arrowRight,
                  " save ~",
                  formatTokens(suggestion.savingsTokens)
                ]
              }, undefined, true, undefined, this) : null
            ]
          }, undefined, true, undefined, this),
          /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ThemedBox_default, {
            marginLeft: 2,
            children: /* @__PURE__ */ jsx_dev_runtime.jsxDEV(ThemedText, {
              dimColor: true,
              children: suggestion.detail
            }, undefined, false, undefined, this)
          }, undefined, false, undefined, this)
        ]
      }, i, true, undefined, this))
    ]
  }, undefined, true, undefined, this);
}
var jsx_dev_runtime;
var init_ContextSuggestions = __esm(() => {
  init_figures();
  init_src();
  init_format();
  jsx_dev_runtime = __toESM(require_jsx_dev_runtime(), 1);
});

// src/components/ContextVisualization.tsx
function CollapseStatus() {
  if (true) {
    const { getStats, isContextCollapseEnabled } = (init_contextCollapse(), __toCommonJS(exports_contextCollapse));
    if (!isContextCollapseEnabled())
      return null;
    const s = getStats();
    const { health: h } = s;
    const parts = [];
    if (s.collapsedSpans > 0) {
      parts.push(`${s.collapsedSpans} ${plural(s.collapsedSpans, "span")} summarized (${s.collapsedMessages} msgs)`);
    }
    if (s.stagedSpans > 0)
      parts.push(`${s.stagedSpans} staged`);
    const summary = parts.length > 0 ? parts.join(", ") : h.totalSpawns > 0 ? `${h.totalSpawns} ${plural(h.totalSpawns, "spawn")}, nothing staged yet` : "waiting for first trigger";
    let line2 = null;
    if (h.totalErrors > 0) {
      line2 = /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
        color: "warning",
        children: [
          "Collapse errors: ",
          h.totalErrors,
          "/",
          h.totalSpawns,
          " spawns failed",
          h.lastError ? ` (last: ${h.lastError.slice(0, 60)})` : ""
        ]
      }, undefined, true, undefined, this);
    } else if (h.emptySpawnWarningEmitted) {
      line2 = /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
        color: "warning",
        children: [
          "Collapse idle: ",
          h.totalEmptySpawns,
          " consecutive empty runs"
        ]
      }, undefined, true, undefined, this);
    }
    return /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(jsx_dev_runtime2.Fragment, {
      children: [
        /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
          dimColor: true,
          children: [
            "Context strategy: collapse (",
            summary,
            ")"
          ]
        }, undefined, true, undefined, this),
        line2
      ]
    }, undefined, true, undefined, this);
  }
  return null;
}
function groupBySource(items) {
  const groups = new Map;
  for (const item of items) {
    const key = getSourceDisplayName(item.source);
    const existing = groups.get(key) || [];
    existing.push(item);
    groups.set(key, existing);
  }
  for (const [key, group] of groups.entries()) {
    groups.set(key, group.sort((a, b) => b.tokens - a.tokens));
  }
  const orderedGroups = new Map;
  for (const source of SOURCE_DISPLAY_ORDER) {
    const group = groups.get(source);
    if (group) {
      orderedGroups.set(source, group);
    }
  }
  return orderedGroups;
}
function ContextVisualization({ data }) {
  const {
    categories,
    totalTokens,
    rawMaxTokens,
    percentage,
    gridRows,
    model,
    memoryFiles,
    mcpTools,
    deferredBuiltinTools = [],
    systemTools,
    systemPromptSections,
    agents,
    skills,
    messageBreakdown
  } = data;
  const visibleCategories = categories.filter((cat) => cat.tokens > 0 && cat.name !== "Free space" && cat.name !== RESERVED_CATEGORY_NAME && !cat.isDeferred);
  const hasDeferredMcpTools = categories.some((cat) => cat.isDeferred && cat.name.includes("MCP"));
  const hasDeferredBuiltinTools = deferredBuiltinTools.length > 0;
  const autocompactCategory = categories.find((cat) => cat.name === RESERVED_CATEGORY_NAME);
  return /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedBox_default, {
    flexDirection: "column",
    paddingLeft: 1,
    children: [
      /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
        bold: true,
        children: "Context Usage"
      }, undefined, false, undefined, this),
      /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedBox_default, {
        flexDirection: "row",
        gap: 2,
        children: [
          /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedBox_default, {
            flexDirection: "column",
            flexShrink: 0,
            children: gridRows.map((row, rowIndex) => /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedBox_default, {
              flexDirection: "row",
              marginLeft: -1,
              children: row.map((square, colIndex) => {
                if (square.categoryName === "Free space") {
                  return /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                    dimColor: true,
                    children: "\u26F6 "
                  }, colIndex, false, undefined, this);
                }
                if (square.categoryName === RESERVED_CATEGORY_NAME) {
                  return /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                    color: square.color,
                    children: "\u26DD "
                  }, colIndex, false, undefined, this);
                }
                return /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                  color: square.color,
                  children: square.squareFullness >= 0.7 ? "\u26C1 " : "\u26C0 "
                }, colIndex, false, undefined, this);
              })
            }, rowIndex, false, undefined, this))
          }, undefined, false, undefined, this),
          /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedBox_default, {
            flexDirection: "column",
            gap: 0,
            flexShrink: 0,
            children: [
              /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                dimColor: true,
                children: [
                  model,
                  " \xB7 ",
                  formatTokens(totalTokens),
                  "/",
                  formatTokens(rawMaxTokens),
                  " tokens (",
                  percentage,
                  "%)"
                ]
              }, undefined, true, undefined, this),
              /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(CollapseStatus, {}, undefined, false, undefined, this),
              /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                children: " "
              }, undefined, false, undefined, this),
              /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                dimColor: true,
                italic: true,
                children: "Estimated usage by category"
              }, undefined, false, undefined, this),
              visibleCategories.map((cat, index) => {
                const tokenDisplay = formatTokens(cat.tokens);
                const percentDisplay = cat.isDeferred ? "N/A" : `${(cat.tokens / rawMaxTokens * 100).toFixed(1)}%`;
                const isReserved = cat.name === RESERVED_CATEGORY_NAME;
                const displayName = cat.name;
                const symbol = cat.isDeferred ? " " : isReserved ? "\u26DD" : "\u26C1";
                return /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedBox_default, {
                  children: [
                    /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                      color: cat.color,
                      children: symbol
                    }, undefined, false, undefined, this),
                    /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                      children: [
                        " ",
                        displayName,
                        ": "
                      ]
                    }, undefined, true, undefined, this),
                    /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                      dimColor: true,
                      children: [
                        tokenDisplay,
                        " tokens (",
                        percentDisplay,
                        ")"
                      ]
                    }, undefined, true, undefined, this)
                  ]
                }, index, true, undefined, this);
              }),
              (categories.find((c) => c.name === "Free space")?.tokens ?? 0) > 0 && /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedBox_default, {
                children: [
                  /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                    dimColor: true,
                    children: "\u26F6"
                  }, undefined, false, undefined, this),
                  /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                    children: " Free space: "
                  }, undefined, false, undefined, this),
                  /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                    dimColor: true,
                    children: [
                      formatTokens(categories.find((c) => c.name === "Free space")?.tokens || 0),
                      " (",
                      ((categories.find((c) => c.name === "Free space")?.tokens || 0) / rawMaxTokens * 100).toFixed(1),
                      "%)"
                    ]
                  }, undefined, true, undefined, this)
                ]
              }, undefined, true, undefined, this),
              autocompactCategory && autocompactCategory.tokens > 0 && /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedBox_default, {
                children: [
                  /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                    color: autocompactCategory.color,
                    children: "\u26DD"
                  }, undefined, false, undefined, this),
                  /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                    dimColor: true,
                    children: [
                      " ",
                      autocompactCategory.name,
                      ": "
                    ]
                  }, undefined, true, undefined, this),
                  /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                    dimColor: true,
                    children: [
                      formatTokens(autocompactCategory.tokens),
                      " tokens (",
                      (autocompactCategory.tokens / rawMaxTokens * 100).toFixed(1),
                      "%)"
                    ]
                  }, undefined, true, undefined, this)
                ]
              }, undefined, true, undefined, this)
            ]
          }, undefined, true, undefined, this)
        ]
      }, undefined, true, undefined, this),
      /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedBox_default, {
        flexDirection: "column",
        marginLeft: -1,
        children: [
          mcpTools.length > 0 && /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedBox_default, {
            flexDirection: "column",
            marginTop: 1,
            children: [
              /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedBox_default, {
                children: [
                  /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                    bold: true,
                    children: "MCP tools"
                  }, undefined, false, undefined, this),
                  /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                    dimColor: true,
                    children: [
                      " \xB7 /mcp",
                      hasDeferredMcpTools ? " (loaded on-demand)" : ""
                    ]
                  }, undefined, true, undefined, this)
                ]
              }, undefined, true, undefined, this),
              mcpTools.some((t) => t.isLoaded) && /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedBox_default, {
                flexDirection: "column",
                marginTop: 1,
                children: [
                  /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                    dimColor: true,
                    children: "Loaded"
                  }, undefined, false, undefined, this),
                  mcpTools.filter((t) => t.isLoaded).map((tool, i) => /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedBox_default, {
                    children: [
                      /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                        children: [
                          "\u2514 ",
                          tool.name,
                          ": "
                        ]
                      }, undefined, true, undefined, this),
                      /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                        dimColor: true,
                        children: [
                          formatTokens(tool.tokens),
                          " tokens"
                        ]
                      }, undefined, true, undefined, this)
                    ]
                  }, i, true, undefined, this))
                ]
              }, undefined, true, undefined, this),
              hasDeferredMcpTools && mcpTools.some((t) => !t.isLoaded) && /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedBox_default, {
                flexDirection: "column",
                marginTop: 1,
                children: [
                  /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                    dimColor: true,
                    children: "Available"
                  }, undefined, false, undefined, this),
                  mcpTools.filter((t) => !t.isLoaded).map((tool, i) => /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedBox_default, {
                    children: /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                      dimColor: true,
                      children: [
                        "\u2514 ",
                        tool.name
                      ]
                    }, undefined, true, undefined, this)
                  }, i, false, undefined, this))
                ]
              }, undefined, true, undefined, this),
              !hasDeferredMcpTools && mcpTools.map((tool, i) => /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedBox_default, {
                children: [
                  /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                    children: [
                      "\u2514 ",
                      tool.name,
                      ": "
                    ]
                  }, undefined, true, undefined, this),
                  /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                    dimColor: true,
                    children: [
                      formatTokens(tool.tokens),
                      " tokens"
                    ]
                  }, undefined, true, undefined, this)
                ]
              }, i, true, undefined, this))
            ]
          }, undefined, true, undefined, this),
          (systemTools && systemTools.length > 0 || hasDeferredBuiltinTools) && process.env.USER_TYPE === "ant" && /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedBox_default, {
            flexDirection: "column",
            marginTop: 1,
            children: [
              /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedBox_default, {
                children: [
                  /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                    bold: true,
                    children: "[ANT-ONLY] System tools"
                  }, undefined, false, undefined, this),
                  hasDeferredBuiltinTools && /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                    dimColor: true,
                    children: " (some loaded on-demand)"
                  }, undefined, false, undefined, this)
                ]
              }, undefined, true, undefined, this),
              /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedBox_default, {
                flexDirection: "column",
                marginTop: 1,
                children: [
                  /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                    dimColor: true,
                    children: "Loaded"
                  }, undefined, false, undefined, this),
                  systemTools?.map((tool, i) => /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedBox_default, {
                    children: [
                      /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                        children: [
                          "\u2514 ",
                          tool.name,
                          ": "
                        ]
                      }, undefined, true, undefined, this),
                      /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                        dimColor: true,
                        children: [
                          formatTokens(tool.tokens),
                          " tokens"
                        ]
                      }, undefined, true, undefined, this)
                    ]
                  }, `sys-${i}`, true, undefined, this)),
                  deferredBuiltinTools.filter((t) => t.isLoaded).map((tool, i) => /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedBox_default, {
                    children: [
                      /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                        children: [
                          "\u2514 ",
                          tool.name,
                          ": "
                        ]
                      }, undefined, true, undefined, this),
                      /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                        dimColor: true,
                        children: [
                          formatTokens(tool.tokens),
                          " tokens"
                        ]
                      }, undefined, true, undefined, this)
                    ]
                  }, `def-${i}`, true, undefined, this))
                ]
              }, undefined, true, undefined, this),
              hasDeferredBuiltinTools && deferredBuiltinTools.some((t) => !t.isLoaded) && /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedBox_default, {
                flexDirection: "column",
                marginTop: 1,
                children: [
                  /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                    dimColor: true,
                    children: "Available"
                  }, undefined, false, undefined, this),
                  deferredBuiltinTools.filter((t) => !t.isLoaded).map((tool, i) => /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedBox_default, {
                    children: /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                      dimColor: true,
                      children: [
                        "\u2514 ",
                        tool.name
                      ]
                    }, undefined, true, undefined, this)
                  }, i, false, undefined, this))
                ]
              }, undefined, true, undefined, this)
            ]
          }, undefined, true, undefined, this),
          systemPromptSections && systemPromptSections.length > 0 && process.env.USER_TYPE === "ant" && /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedBox_default, {
            flexDirection: "column",
            marginTop: 1,
            children: [
              /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                bold: true,
                children: "[ANT-ONLY] System prompt sections"
              }, undefined, false, undefined, this),
              systemPromptSections.map((section, i) => /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedBox_default, {
                children: [
                  /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                    children: [
                      "\u2514 ",
                      section.name,
                      ": "
                    ]
                  }, undefined, true, undefined, this),
                  /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                    dimColor: true,
                    children: [
                      formatTokens(section.tokens),
                      " tokens"
                    ]
                  }, undefined, true, undefined, this)
                ]
              }, i, true, undefined, this))
            ]
          }, undefined, true, undefined, this),
          agents.length > 0 && /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedBox_default, {
            flexDirection: "column",
            marginTop: 1,
            children: [
              /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedBox_default, {
                children: [
                  /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                    bold: true,
                    children: "Custom agents"
                  }, undefined, false, undefined, this),
                  /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                    dimColor: true,
                    children: " \xB7 /agents"
                  }, undefined, false, undefined, this)
                ]
              }, undefined, true, undefined, this),
              Array.from(groupBySource(agents).entries()).map(([sourceDisplay, sourceAgents]) => /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedBox_default, {
                flexDirection: "column",
                marginTop: 1,
                children: [
                  /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                    dimColor: true,
                    children: sourceDisplay
                  }, undefined, false, undefined, this),
                  sourceAgents.map((agent, i) => /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedBox_default, {
                    children: [
                      /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                        children: [
                          "\u2514 ",
                          agent.agentType,
                          ": "
                        ]
                      }, undefined, true, undefined, this),
                      /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                        dimColor: true,
                        children: [
                          formatTokens(agent.tokens),
                          " tokens"
                        ]
                      }, undefined, true, undefined, this)
                    ]
                  }, i, true, undefined, this))
                ]
              }, sourceDisplay, true, undefined, this))
            ]
          }, undefined, true, undefined, this),
          memoryFiles.length > 0 && /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedBox_default, {
            flexDirection: "column",
            marginTop: 1,
            children: [
              /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedBox_default, {
                children: [
                  /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                    bold: true,
                    children: "Memory files"
                  }, undefined, false, undefined, this),
                  /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                    dimColor: true,
                    children: " \xB7 /memory"
                  }, undefined, false, undefined, this)
                ]
              }, undefined, true, undefined, this),
              memoryFiles.map((file, i) => /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedBox_default, {
                children: [
                  /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                    children: [
                      "\u2514 ",
                      getDisplayPath(file.path),
                      ": "
                    ]
                  }, undefined, true, undefined, this),
                  /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                    dimColor: true,
                    children: [
                      formatTokens(file.tokens),
                      " tokens"
                    ]
                  }, undefined, true, undefined, this)
                ]
              }, i, true, undefined, this))
            ]
          }, undefined, true, undefined, this),
          skills && skills.tokens > 0 && /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedBox_default, {
            flexDirection: "column",
            marginTop: 1,
            children: [
              /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedBox_default, {
                children: [
                  /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                    bold: true,
                    children: "Skills"
                  }, undefined, false, undefined, this),
                  /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                    dimColor: true,
                    children: " \xB7 /skills"
                  }, undefined, false, undefined, this)
                ]
              }, undefined, true, undefined, this),
              Array.from(groupBySource(skills.skillFrontmatter).entries()).map(([sourceDisplay, sourceSkills]) => /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedBox_default, {
                flexDirection: "column",
                marginTop: 1,
                children: [
                  /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                    dimColor: true,
                    children: sourceDisplay
                  }, undefined, false, undefined, this),
                  sourceSkills.map((skill, i) => /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedBox_default, {
                    children: [
                      /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                        children: [
                          "\u2514 ",
                          skill.name,
                          ": "
                        ]
                      }, undefined, true, undefined, this),
                      /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                        dimColor: true,
                        children: [
                          formatTokens(skill.tokens),
                          " tokens"
                        ]
                      }, undefined, true, undefined, this)
                    ]
                  }, i, true, undefined, this))
                ]
              }, sourceDisplay, true, undefined, this))
            ]
          }, undefined, true, undefined, this),
          messageBreakdown && process.env.USER_TYPE === "ant" && /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedBox_default, {
            flexDirection: "column",
            marginTop: 1,
            children: [
              /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                bold: true,
                children: "[ANT-ONLY] Message breakdown"
              }, undefined, false, undefined, this),
              /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedBox_default, {
                flexDirection: "column",
                marginLeft: 1,
                children: [
                  /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedBox_default, {
                    children: [
                      /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                        children: "Tool calls: "
                      }, undefined, false, undefined, this),
                      /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                        dimColor: true,
                        children: [
                          formatTokens(messageBreakdown.toolCallTokens),
                          " tokens"
                        ]
                      }, undefined, true, undefined, this)
                    ]
                  }, undefined, true, undefined, this),
                  /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedBox_default, {
                    children: [
                      /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                        children: "Tool results: "
                      }, undefined, false, undefined, this),
                      /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                        dimColor: true,
                        children: [
                          formatTokens(messageBreakdown.toolResultTokens),
                          " tokens"
                        ]
                      }, undefined, true, undefined, this)
                    ]
                  }, undefined, true, undefined, this),
                  /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedBox_default, {
                    children: [
                      /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                        children: "Attachments: "
                      }, undefined, false, undefined, this),
                      /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                        dimColor: true,
                        children: [
                          formatTokens(messageBreakdown.attachmentTokens),
                          " tokens"
                        ]
                      }, undefined, true, undefined, this)
                    ]
                  }, undefined, true, undefined, this),
                  /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedBox_default, {
                    children: [
                      /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                        children: "Assistant messages (non-tool): "
                      }, undefined, false, undefined, this),
                      /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                        dimColor: true,
                        children: [
                          formatTokens(messageBreakdown.assistantMessageTokens),
                          " tokens"
                        ]
                      }, undefined, true, undefined, this)
                    ]
                  }, undefined, true, undefined, this),
                  /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedBox_default, {
                    children: [
                      /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                        children: "User messages (non-tool-result): "
                      }, undefined, false, undefined, this),
                      /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                        dimColor: true,
                        children: [
                          formatTokens(messageBreakdown.userMessageTokens),
                          " tokens"
                        ]
                      }, undefined, true, undefined, this)
                    ]
                  }, undefined, true, undefined, this)
                ]
              }, undefined, true, undefined, this),
              messageBreakdown.toolCallsByType.length > 0 && /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedBox_default, {
                flexDirection: "column",
                marginTop: 1,
                children: [
                  /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                    bold: true,
                    children: "[ANT-ONLY] Top tools"
                  }, undefined, false, undefined, this),
                  messageBreakdown.toolCallsByType.slice(0, 5).map((tool, i) => /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedBox_default, {
                    marginLeft: 1,
                    children: [
                      /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                        children: [
                          "\u2514 ",
                          tool.name,
                          ": "
                        ]
                      }, undefined, true, undefined, this),
                      /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                        dimColor: true,
                        children: [
                          "calls ",
                          formatTokens(tool.callTokens),
                          ", results ",
                          formatTokens(tool.resultTokens)
                        ]
                      }, undefined, true, undefined, this)
                    ]
                  }, i, true, undefined, this))
                ]
              }, undefined, true, undefined, this),
              messageBreakdown.attachmentsByType.length > 0 && /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedBox_default, {
                flexDirection: "column",
                marginTop: 1,
                children: [
                  /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                    bold: true,
                    children: "[ANT-ONLY] Top attachments"
                  }, undefined, false, undefined, this),
                  messageBreakdown.attachmentsByType.slice(0, 5).map((attachment, i) => /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedBox_default, {
                    marginLeft: 1,
                    children: [
                      /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                        children: [
                          "\u2514 ",
                          attachment.name,
                          ": "
                        ]
                      }, undefined, true, undefined, this),
                      /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ThemedText, {
                        dimColor: true,
                        children: [
                          formatTokens(attachment.tokens),
                          " tokens"
                        ]
                      }, undefined, true, undefined, this)
                    ]
                  }, i, true, undefined, this))
                ]
              }, undefined, true, undefined, this)
            ]
          }, undefined, true, undefined, this)
        ]
      }, undefined, true, undefined, this),
      /* @__PURE__ */ jsx_dev_runtime2.jsxDEV(ContextSuggestions, {
        suggestions: generateContextSuggestions(data)
      }, undefined, false, undefined, this)
    ]
  }, undefined, true, undefined, this);
}
var jsx_dev_runtime2, RESERVED_CATEGORY_NAME = "Autocompact buffer", SOURCE_DISPLAY_ORDER;
var init_ContextVisualization = __esm(() => {
  init_src();
  init_contextSuggestions();
  init_file();
  init_format();
  init_constants();
  init_stringUtils();
  init_ContextSuggestions();
  jsx_dev_runtime2 = __toESM(require_jsx_dev_runtime(), 1);
  SOURCE_DISPLAY_ORDER = ["Project", "User", "Managed", "Plugin", "Built-in"];
});

// src/commands/context/context.tsx
function toApiView(messages) {
  let view = getMessagesAfterCompactBoundary(messages);
  if (true) {
    const { projectView } = (init_operations(), __toCommonJS(exports_operations));
    view = projectView(view);
  }
  return view;
}
async function call(onDone, context) {
  const {
    messages,
    getAppState,
    options: { mainLoopModel, tools }
  } = context;
  const apiView = toApiView(messages);
  const { messages: compactedMessages } = await microcompactMessages(apiView);
  const terminalWidth = process.stdout.columns || 80;
  const appState = getAppState();
  const data = await analyzeContextUsage(compactedMessages, mainLoopModel, async () => appState.toolPermissionContext, tools, appState.agentDefinitions, terminalWidth, context, undefined, apiView);
  const output = await renderToAnsiString(/* @__PURE__ */ jsx_dev_runtime3.jsxDEV(ContextVisualization, {
    data
  }, undefined, false, undefined, this));
  onDone(output);
  return null;
}
var jsx_dev_runtime3;
var init_context = __esm(() => {
  init_ContextVisualization();
  init_microCompact();
  init_analyzeContext();
  init_messages();
  init_staticRender();
  jsx_dev_runtime3 = __toESM(require_jsx_dev_runtime(), 1);
});
init_context();

export {
  call
};
