// @bun
import {
  init_staticRender,
  renderToAnsiString
} from "./chunk-446yy2hr.js";
import {
  analyzeContextUsage,
  getMessagesAfterCompactBoundary,
  init_analyzeContext,
  init_messages1 as init_messages,
  init_microCompact,
  microcompactMessages
} from "./chunk-4vz571bb.js";
import"./chunk-14p6wvsq.js";
import"./chunk-8hseq8b1.js";
import"./chunk-ddtxq6k5.js";
import"./chunk-28jd8qjx.js";
import"./chunk-djt39ze3.js";
import"./chunk-ptxteaeh.js";
import"./chunk-wd53a7m4.js";
import"./chunk-hms8ge0k.js";
import"./chunk-whpphypt.js";
import"./chunk-pht800m5.js";
import"./chunk-pjkqh1kq.js";
import"./chunk-9a9g5hbj.js";
import"./chunk-9hn8e6h1.js";
import"./chunk-rgyzsbs3.js";
import"./chunk-qn6me9n1.js";
import"./chunk-qd3r2s2n.js";
import"./chunk-djzd7tef.js";
import"./chunk-gyhnpbkx.js";
import"./chunk-71sdcaq6.js";
import"./chunk-60gf7p5s.js";
import"./chunk-sj3d0nqx.js";
import"./chunk-9pk9rk2w.js";
import"./chunk-javpza6a.js";
import"./chunk-6v7bre98.js";
import"./chunk-24kv69g3.js";
import"./chunk-fcqebw9m.js";
import"./chunk-dnfd3c9s.js";
import"./chunk-15ezj4ww.js";
import"./chunk-1h284c6e.js";
import"./chunk-582g9yce.js";
import"./chunk-y3ztgztb.js";
import"./chunk-4spgkgr3.js";
import"./chunk-n8kbhswc.js";
import"./chunk-60fkafk2.js";
import"./chunk-fgbkrbk3.js";
import {
  BASH_TOOL_NAME,
  FILE_READ_TOOL_NAME,
  GREP_TOOL_NAME,
  WEB_FETCH_TOOL_NAME,
  init_prompt,
  init_prompt1 as init_prompt2,
  init_prompt4 as init_prompt3,
  init_toolName
} from "./chunk-ssw61jfd.js";
import"./chunk-093ej2sf.js";
import"./chunk-7tfdhkpy.js";
import"./chunk-nde5ym6a.js";
import"./chunk-k8wq4qsj.js";
import"./chunk-g7d3xx1p.js";
import"./chunk-3wrx2943.js";
import"./chunk-7p9kkh0f.js";
import"./chunk-qp8cgz66.js";
import"./chunk-1mg610h2.js";
import"./chunk-93hc149s.js";
import"./chunk-935nrvdb.js";
import"./chunk-8zz4z1q3.js";
import"./chunk-nnat9jw5.js";
import"./chunk-hqxp6b72.js";
import"./chunk-4jzkqgf1.js";
import"./chunk-33rd41ng.js";
import"./chunk-f257kqw9.js";
import"./chunk-w5hnghah.js";
import"./chunk-36twraxy.js";
import"./chunk-1bkvnj0y.js";
import"./chunk-akdpcc5p.js";
import {
  getDisplayPath,
  getSourceDisplayName,
  init_constants,
  init_file,
  init_stringUtils
} from "./chunk-7rrkrej7.js";
import"./chunk-6r0bxrh6.js";
import"./chunk-d6500tvx.js";
import"./chunk-jg4bw4hp.js";
import"./chunk-epvbnq43.js";
import"./chunk-tn2sx7j6.js";
import"./chunk-6tzyv21c.js";
import"./chunk-8kf8h7xf.js";
import"./chunk-bgan4cpf.js";
import"./chunk-jmv7k0jn.js";
import"./chunk-ch4pgvwq.js";
import"./chunk-99jc4tcw.js";
import"./chunk-fghczfqt.js";
import"./chunk-vwenx8ke.js";
import"./chunk-f86mwfyd.js";
import"./chunk-v4ypszbb.js";
import"./chunk-bk6ck5c2.js";
import"./chunk-ym6j0wv1.js";
import"./chunk-hjmatcgt.js";
import"./chunk-6mdh70q0.js";
import"./chunk-ch92ycde.js";
import"./chunk-e4dsy4g1.js";
import"./chunk-326zehp8.js";
import"./chunk-kc67kt75.js";
import"./chunk-40t1d75v.js";
import"./chunk-nt5dmk8q.js";
import"./chunk-e3abfxpy.js";
import"./chunk-q44zc68f.js";
import"./chunk-fejeqe61.js";
import {
  formatTokens,
  init_format
} from "./chunk-0gp4q8aq.js";
import"./chunk-hn4w9pkj.js";
import {
  StatusIcon,
  ThemedBox_default,
  ThemedText,
  init_src
} from "./chunk-0r6npc3t.js";
import {
  require_jsx_runtime
} from "./chunk-gxyx8b8w.js";
import"./chunk-j1mep9ck.js";
import"./chunk-6x35ffpx.js";
import"./chunk-1zbwhcbt.js";
import"./chunk-t0450ma3.js";
import"./chunk-0cqw3y8h.js";
import"./chunk-k1sw7km0.js";
import"./chunk-e3j7m7k2.js";
import"./chunk-sc9ycxra.js";
import"./chunk-hhta0nge.js";
import"./chunk-8wsj9fff.js";
import"./chunk-m28vg9w4.js";
import"./chunk-f8prtxs3.js";
import"./chunk-41a6f2kv.js";
import"./chunk-c1yc761e.js";
import {
  figures_default,
  init_figures
} from "./chunk-c5g9shkw.js";
import"./chunk-byd20vdq.js";
import"./chunk-kb3758f7.js";
import"./chunk-3j8w0rq8.js";
import"./chunk-tj0dzck2.js";
import"./chunk-aeysytks.js";
import"./chunk-ns1htxgd.js";
import"./chunk-ztqzmfx1.js";
import"./chunk-6k1rsk85.js";
import"./chunk-nxzx0ey9.js";
import"./chunk-yes1my80.js";
import"./chunk-pecy49yr.js";
import"./chunk-azbab59e.js";
import"./chunk-3nk9q8dr.js";
import {
  __esm,
  __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_runtime.jsxs(ThemedBox_default, {
    flexDirection: "column",
    marginTop: 1,
    children: [
      /* @__PURE__ */ jsx_runtime.jsx(ThemedText, {
        bold: true,
        children: "Suggestions"
      }),
      suggestions.map((suggestion, i) => /* @__PURE__ */ jsx_runtime.jsxs(ThemedBox_default, {
        flexDirection: "column",
        marginTop: i === 0 ? 0 : 1,
        children: [
          /* @__PURE__ */ jsx_runtime.jsxs(ThemedBox_default, {
            children: [
              /* @__PURE__ */ jsx_runtime.jsx(StatusIcon, {
                status: suggestion.severity,
                withSpace: true
              }),
              /* @__PURE__ */ jsx_runtime.jsx(ThemedText, {
                bold: true,
                children: suggestion.title
              }),
              suggestion.savingsTokens ? /* @__PURE__ */ jsx_runtime.jsxs(ThemedText, {
                dimColor: true,
                children: [
                  " ",
                  figures_default.arrowRight,
                  " save ~",
                  formatTokens(suggestion.savingsTokens)
                ]
              }) : null
            ]
          }),
          /* @__PURE__ */ jsx_runtime.jsx(ThemedBox_default, {
            marginLeft: 2,
            children: /* @__PURE__ */ jsx_runtime.jsx(ThemedText, {
              dimColor: true,
              children: suggestion.detail
            })
          })
        ]
      }, i))
    ]
  });
}
var jsx_runtime;
var init_ContextSuggestions = __esm(() => {
  init_figures();
  init_src();
  init_format();
  jsx_runtime = __toESM(require_jsx_runtime(), 1);
});

// src/components/ContextVisualization.tsx
function CollapseStatus() {
  if (false) {}
  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,
    cacheHitRate,
    cacheThreshold
  } = 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_runtime2.jsxs(ThemedBox_default, {
    flexDirection: "column",
    paddingLeft: 1,
    children: [
      /* @__PURE__ */ jsx_runtime2.jsx(ThemedText, {
        bold: true,
        children: "Context Usage"
      }),
      /* @__PURE__ */ jsx_runtime2.jsxs(ThemedBox_default, {
        flexDirection: "row",
        gap: 2,
        children: [
          /* @__PURE__ */ jsx_runtime2.jsx(ThemedBox_default, {
            flexDirection: "column",
            flexShrink: 0,
            children: gridRows.map((row, rowIndex) => /* @__PURE__ */ jsx_runtime2.jsx(ThemedBox_default, {
              flexDirection: "row",
              marginLeft: -1,
              children: row.map((square, colIndex) => {
                if (square.categoryName === "Free space") {
                  return /* @__PURE__ */ jsx_runtime2.jsx(ThemedText, {
                    dimColor: true,
                    children: "\u26F6 "
                  }, colIndex);
                }
                if (square.categoryName === RESERVED_CATEGORY_NAME) {
                  return /* @__PURE__ */ jsx_runtime2.jsx(ThemedText, {
                    color: square.color,
                    children: "\u26DD "
                  }, colIndex);
                }
                return /* @__PURE__ */ jsx_runtime2.jsx(ThemedText, {
                  color: square.color,
                  children: square.squareFullness >= 0.7 ? "\u26C1 " : "\u26C0 "
                }, colIndex);
              })
            }, rowIndex))
          }),
          /* @__PURE__ */ jsx_runtime2.jsxs(ThemedBox_default, {
            flexDirection: "column",
            gap: 0,
            flexShrink: 0,
            children: [
              /* @__PURE__ */ jsx_runtime2.jsxs(ThemedText, {
                dimColor: true,
                children: [
                  model,
                  " \xB7 ",
                  formatTokens(totalTokens),
                  "/",
                  formatTokens(rawMaxTokens),
                  " tokens (",
                  percentage,
                  "%)"
                ]
              }),
              /* @__PURE__ */ jsx_runtime2.jsx(CollapseStatus, {}),
              cacheHitRate !== undefined && cacheThreshold !== undefined && /* @__PURE__ */ jsx_runtime2.jsxs(ThemedText, {
                color: cacheHitRate < cacheThreshold ? "warning" : undefined,
                children: [
                  "Cache hit rate: ",
                  cacheHitRate.toFixed(0),
                  "%",
                  cacheHitRate < cacheThreshold ? ` (below ${cacheThreshold}% threshold)` : ""
                ]
              }),
              /* @__PURE__ */ jsx_runtime2.jsx(ThemedText, {
                children: " "
              }),
              /* @__PURE__ */ jsx_runtime2.jsx(ThemedText, {
                dimColor: true,
                italic: true,
                children: "Estimated usage by category"
              }),
              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_runtime2.jsxs(ThemedBox_default, {
                  children: [
                    /* @__PURE__ */ jsx_runtime2.jsx(ThemedText, {
                      color: cat.color,
                      children: symbol
                    }),
                    /* @__PURE__ */ jsx_runtime2.jsxs(ThemedText, {
                      children: [
                        " ",
                        displayName,
                        ": "
                      ]
                    }),
                    /* @__PURE__ */ jsx_runtime2.jsxs(ThemedText, {
                      dimColor: true,
                      children: [
                        tokenDisplay,
                        " tokens (",
                        percentDisplay,
                        ")"
                      ]
                    })
                  ]
                }, index);
              }),
              (categories.find((c) => c.name === "Free space")?.tokens ?? 0) > 0 && /* @__PURE__ */ jsx_runtime2.jsxs(ThemedBox_default, {
                children: [
                  /* @__PURE__ */ jsx_runtime2.jsx(ThemedText, {
                    dimColor: true,
                    children: "\u26F6"
                  }),
                  /* @__PURE__ */ jsx_runtime2.jsx(ThemedText, {
                    children: " Free space: "
                  }),
                  /* @__PURE__ */ jsx_runtime2.jsxs(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),
                      "%)"
                    ]
                  })
                ]
              }),
              autocompactCategory && autocompactCategory.tokens > 0 && /* @__PURE__ */ jsx_runtime2.jsxs(ThemedBox_default, {
                children: [
                  /* @__PURE__ */ jsx_runtime2.jsx(ThemedText, {
                    color: autocompactCategory.color,
                    children: "\u26DD"
                  }),
                  /* @__PURE__ */ jsx_runtime2.jsxs(ThemedText, {
                    dimColor: true,
                    children: [
                      " ",
                      autocompactCategory.name,
                      ": "
                    ]
                  }),
                  /* @__PURE__ */ jsx_runtime2.jsxs(ThemedText, {
                    dimColor: true,
                    children: [
                      formatTokens(autocompactCategory.tokens),
                      " tokens (",
                      (autocompactCategory.tokens / rawMaxTokens * 100).toFixed(1),
                      "%)"
                    ]
                  })
                ]
              })
            ]
          })
        ]
      }),
      /* @__PURE__ */ jsx_runtime2.jsxs(ThemedBox_default, {
        flexDirection: "column",
        marginLeft: -1,
        children: [
          mcpTools.length > 0 && /* @__PURE__ */ jsx_runtime2.jsxs(ThemedBox_default, {
            flexDirection: "column",
            marginTop: 1,
            children: [
              /* @__PURE__ */ jsx_runtime2.jsxs(ThemedBox_default, {
                children: [
                  /* @__PURE__ */ jsx_runtime2.jsx(ThemedText, {
                    bold: true,
                    children: "MCP tools"
                  }),
                  /* @__PURE__ */ jsx_runtime2.jsxs(ThemedText, {
                    dimColor: true,
                    children: [
                      " \xB7 /mcp",
                      hasDeferredMcpTools ? " (loaded on-demand)" : ""
                    ]
                  })
                ]
              }),
              mcpTools.some((t) => t.isLoaded) && /* @__PURE__ */ jsx_runtime2.jsxs(ThemedBox_default, {
                flexDirection: "column",
                marginTop: 1,
                children: [
                  /* @__PURE__ */ jsx_runtime2.jsx(ThemedText, {
                    dimColor: true,
                    children: "Loaded"
                  }),
                  mcpTools.filter((t) => t.isLoaded).map((tool, i) => /* @__PURE__ */ jsx_runtime2.jsxs(ThemedBox_default, {
                    children: [
                      /* @__PURE__ */ jsx_runtime2.jsxs(ThemedText, {
                        children: [
                          "\u2514 ",
                          tool.name,
                          ": "
                        ]
                      }),
                      /* @__PURE__ */ jsx_runtime2.jsxs(ThemedText, {
                        dimColor: true,
                        children: [
                          formatTokens(tool.tokens),
                          " tokens"
                        ]
                      })
                    ]
                  }, i))
                ]
              }),
              hasDeferredMcpTools && mcpTools.some((t) => !t.isLoaded) && /* @__PURE__ */ jsx_runtime2.jsxs(ThemedBox_default, {
                flexDirection: "column",
                marginTop: 1,
                children: [
                  /* @__PURE__ */ jsx_runtime2.jsx(ThemedText, {
                    dimColor: true,
                    children: "Available"
                  }),
                  mcpTools.filter((t) => !t.isLoaded).map((tool, i) => /* @__PURE__ */ jsx_runtime2.jsx(ThemedBox_default, {
                    children: /* @__PURE__ */ jsx_runtime2.jsxs(ThemedText, {
                      dimColor: true,
                      children: [
                        "\u2514 ",
                        tool.name
                      ]
                    })
                  }, i))
                ]
              }),
              !hasDeferredMcpTools && mcpTools.map((tool, i) => /* @__PURE__ */ jsx_runtime2.jsxs(ThemedBox_default, {
                children: [
                  /* @__PURE__ */ jsx_runtime2.jsxs(ThemedText, {
                    children: [
                      "\u2514 ",
                      tool.name,
                      ": "
                    ]
                  }),
                  /* @__PURE__ */ jsx_runtime2.jsxs(ThemedText, {
                    dimColor: true,
                    children: [
                      formatTokens(tool.tokens),
                      " tokens"
                    ]
                  })
                ]
              }, i))
            ]
          }),
          (systemTools && systemTools.length > 0 || hasDeferredBuiltinTools) && process.env.USER_TYPE === "ant" && /* @__PURE__ */ jsx_runtime2.jsxs(ThemedBox_default, {
            flexDirection: "column",
            marginTop: 1,
            children: [
              /* @__PURE__ */ jsx_runtime2.jsxs(ThemedBox_default, {
                children: [
                  /* @__PURE__ */ jsx_runtime2.jsx(ThemedText, {
                    bold: true,
                    children: "[ANT-ONLY] System tools"
                  }),
                  hasDeferredBuiltinTools && /* @__PURE__ */ jsx_runtime2.jsx(ThemedText, {
                    dimColor: true,
                    children: " (some loaded on-demand)"
                  })
                ]
              }),
              /* @__PURE__ */ jsx_runtime2.jsxs(ThemedBox_default, {
                flexDirection: "column",
                marginTop: 1,
                children: [
                  /* @__PURE__ */ jsx_runtime2.jsx(ThemedText, {
                    dimColor: true,
                    children: "Loaded"
                  }),
                  systemTools?.map((tool, i) => /* @__PURE__ */ jsx_runtime2.jsxs(ThemedBox_default, {
                    children: [
                      /* @__PURE__ */ jsx_runtime2.jsxs(ThemedText, {
                        children: [
                          "\u2514 ",
                          tool.name,
                          ": "
                        ]
                      }),
                      /* @__PURE__ */ jsx_runtime2.jsxs(ThemedText, {
                        dimColor: true,
                        children: [
                          formatTokens(tool.tokens),
                          " tokens"
                        ]
                      })
                    ]
                  }, `sys-${i}`)),
                  deferredBuiltinTools.filter((t) => t.isLoaded).map((tool, i) => /* @__PURE__ */ jsx_runtime2.jsxs(ThemedBox_default, {
                    children: [
                      /* @__PURE__ */ jsx_runtime2.jsxs(ThemedText, {
                        children: [
                          "\u2514 ",
                          tool.name,
                          ": "
                        ]
                      }),
                      /* @__PURE__ */ jsx_runtime2.jsxs(ThemedText, {
                        dimColor: true,
                        children: [
                          formatTokens(tool.tokens),
                          " tokens"
                        ]
                      })
                    ]
                  }, `def-${i}`))
                ]
              }),
              hasDeferredBuiltinTools && deferredBuiltinTools.some((t) => !t.isLoaded) && /* @__PURE__ */ jsx_runtime2.jsxs(ThemedBox_default, {
                flexDirection: "column",
                marginTop: 1,
                children: [
                  /* @__PURE__ */ jsx_runtime2.jsx(ThemedText, {
                    dimColor: true,
                    children: "Available"
                  }),
                  deferredBuiltinTools.filter((t) => !t.isLoaded).map((tool, i) => /* @__PURE__ */ jsx_runtime2.jsx(ThemedBox_default, {
                    children: /* @__PURE__ */ jsx_runtime2.jsxs(ThemedText, {
                      dimColor: true,
                      children: [
                        "\u2514 ",
                        tool.name
                      ]
                    })
                  }, i))
                ]
              })
            ]
          }),
          systemPromptSections && systemPromptSections.length > 0 && process.env.USER_TYPE === "ant" && /* @__PURE__ */ jsx_runtime2.jsxs(ThemedBox_default, {
            flexDirection: "column",
            marginTop: 1,
            children: [
              /* @__PURE__ */ jsx_runtime2.jsx(ThemedText, {
                bold: true,
                children: "[ANT-ONLY] System prompt sections"
              }),
              systemPromptSections.map((section, i) => /* @__PURE__ */ jsx_runtime2.jsxs(ThemedBox_default, {
                children: [
                  /* @__PURE__ */ jsx_runtime2.jsxs(ThemedText, {
                    children: [
                      "\u2514 ",
                      section.name,
                      ": "
                    ]
                  }),
                  /* @__PURE__ */ jsx_runtime2.jsxs(ThemedText, {
                    dimColor: true,
                    children: [
                      formatTokens(section.tokens),
                      " tokens"
                    ]
                  })
                ]
              }, i))
            ]
          }),
          agents.length > 0 && /* @__PURE__ */ jsx_runtime2.jsxs(ThemedBox_default, {
            flexDirection: "column",
            marginTop: 1,
            children: [
              /* @__PURE__ */ jsx_runtime2.jsxs(ThemedBox_default, {
                children: [
                  /* @__PURE__ */ jsx_runtime2.jsx(ThemedText, {
                    bold: true,
                    children: "Custom agents"
                  }),
                  /* @__PURE__ */ jsx_runtime2.jsx(ThemedText, {
                    dimColor: true,
                    children: " \xB7 /agents"
                  })
                ]
              }),
              Array.from(groupBySource(agents).entries()).map(([sourceDisplay, sourceAgents]) => /* @__PURE__ */ jsx_runtime2.jsxs(ThemedBox_default, {
                flexDirection: "column",
                marginTop: 1,
                children: [
                  /* @__PURE__ */ jsx_runtime2.jsx(ThemedText, {
                    dimColor: true,
                    children: sourceDisplay
                  }),
                  sourceAgents.map((agent, i) => /* @__PURE__ */ jsx_runtime2.jsxs(ThemedBox_default, {
                    children: [
                      /* @__PURE__ */ jsx_runtime2.jsxs(ThemedText, {
                        children: [
                          "\u2514 ",
                          agent.agentType,
                          ": "
                        ]
                      }),
                      /* @__PURE__ */ jsx_runtime2.jsxs(ThemedText, {
                        dimColor: true,
                        children: [
                          formatTokens(agent.tokens),
                          " tokens"
                        ]
                      })
                    ]
                  }, i))
                ]
              }, sourceDisplay))
            ]
          }),
          memoryFiles.length > 0 && /* @__PURE__ */ jsx_runtime2.jsxs(ThemedBox_default, {
            flexDirection: "column",
            marginTop: 1,
            children: [
              /* @__PURE__ */ jsx_runtime2.jsxs(ThemedBox_default, {
                children: [
                  /* @__PURE__ */ jsx_runtime2.jsx(ThemedText, {
                    bold: true,
                    children: "Memory files"
                  }),
                  /* @__PURE__ */ jsx_runtime2.jsx(ThemedText, {
                    dimColor: true,
                    children: " \xB7 /memory"
                  })
                ]
              }),
              memoryFiles.map((file, i) => /* @__PURE__ */ jsx_runtime2.jsxs(ThemedBox_default, {
                children: [
                  /* @__PURE__ */ jsx_runtime2.jsxs(ThemedText, {
                    children: [
                      "\u2514 ",
                      getDisplayPath(file.path),
                      ": "
                    ]
                  }),
                  /* @__PURE__ */ jsx_runtime2.jsxs(ThemedText, {
                    dimColor: true,
                    children: [
                      formatTokens(file.tokens),
                      " tokens"
                    ]
                  })
                ]
              }, i))
            ]
          }),
          skills && skills.tokens > 0 && /* @__PURE__ */ jsx_runtime2.jsxs(ThemedBox_default, {
            flexDirection: "column",
            marginTop: 1,
            children: [
              /* @__PURE__ */ jsx_runtime2.jsxs(ThemedBox_default, {
                children: [
                  /* @__PURE__ */ jsx_runtime2.jsx(ThemedText, {
                    bold: true,
                    children: "Skills"
                  }),
                  /* @__PURE__ */ jsx_runtime2.jsx(ThemedText, {
                    dimColor: true,
                    children: " \xB7 /skills"
                  })
                ]
              }),
              Array.from(groupBySource(skills.skillFrontmatter).entries()).map(([sourceDisplay, sourceSkills]) => /* @__PURE__ */ jsx_runtime2.jsxs(ThemedBox_default, {
                flexDirection: "column",
                marginTop: 1,
                children: [
                  /* @__PURE__ */ jsx_runtime2.jsx(ThemedText, {
                    dimColor: true,
                    children: sourceDisplay
                  }),
                  sourceSkills.map((skill, i) => /* @__PURE__ */ jsx_runtime2.jsxs(ThemedBox_default, {
                    children: [
                      /* @__PURE__ */ jsx_runtime2.jsxs(ThemedText, {
                        children: [
                          "\u2514 ",
                          skill.name,
                          ": "
                        ]
                      }),
                      /* @__PURE__ */ jsx_runtime2.jsxs(ThemedText, {
                        dimColor: true,
                        children: [
                          formatTokens(skill.tokens),
                          " tokens"
                        ]
                      })
                    ]
                  }, i))
                ]
              }, sourceDisplay))
            ]
          }),
          messageBreakdown && process.env.USER_TYPE === "ant" && /* @__PURE__ */ jsx_runtime2.jsxs(ThemedBox_default, {
            flexDirection: "column",
            marginTop: 1,
            children: [
              /* @__PURE__ */ jsx_runtime2.jsx(ThemedText, {
                bold: true,
                children: "[ANT-ONLY] Message breakdown"
              }),
              /* @__PURE__ */ jsx_runtime2.jsxs(ThemedBox_default, {
                flexDirection: "column",
                marginLeft: 1,
                children: [
                  /* @__PURE__ */ jsx_runtime2.jsxs(ThemedBox_default, {
                    children: [
                      /* @__PURE__ */ jsx_runtime2.jsx(ThemedText, {
                        children: "Tool calls: "
                      }),
                      /* @__PURE__ */ jsx_runtime2.jsxs(ThemedText, {
                        dimColor: true,
                        children: [
                          formatTokens(messageBreakdown.toolCallTokens),
                          " tokens"
                        ]
                      })
                    ]
                  }),
                  /* @__PURE__ */ jsx_runtime2.jsxs(ThemedBox_default, {
                    children: [
                      /* @__PURE__ */ jsx_runtime2.jsx(ThemedText, {
                        children: "Tool results: "
                      }),
                      /* @__PURE__ */ jsx_runtime2.jsxs(ThemedText, {
                        dimColor: true,
                        children: [
                          formatTokens(messageBreakdown.toolResultTokens),
                          " tokens"
                        ]
                      })
                    ]
                  }),
                  /* @__PURE__ */ jsx_runtime2.jsxs(ThemedBox_default, {
                    children: [
                      /* @__PURE__ */ jsx_runtime2.jsx(ThemedText, {
                        children: "Attachments: "
                      }),
                      /* @__PURE__ */ jsx_runtime2.jsxs(ThemedText, {
                        dimColor: true,
                        children: [
                          formatTokens(messageBreakdown.attachmentTokens),
                          " tokens"
                        ]
                      })
                    ]
                  }),
                  /* @__PURE__ */ jsx_runtime2.jsxs(ThemedBox_default, {
                    children: [
                      /* @__PURE__ */ jsx_runtime2.jsx(ThemedText, {
                        children: "Assistant messages (non-tool): "
                      }),
                      /* @__PURE__ */ jsx_runtime2.jsxs(ThemedText, {
                        dimColor: true,
                        children: [
                          formatTokens(messageBreakdown.assistantMessageTokens),
                          " tokens"
                        ]
                      })
                    ]
                  }),
                  /* @__PURE__ */ jsx_runtime2.jsxs(ThemedBox_default, {
                    children: [
                      /* @__PURE__ */ jsx_runtime2.jsx(ThemedText, {
                        children: "User messages (non-tool-result): "
                      }),
                      /* @__PURE__ */ jsx_runtime2.jsxs(ThemedText, {
                        dimColor: true,
                        children: [
                          formatTokens(messageBreakdown.userMessageTokens),
                          " tokens"
                        ]
                      })
                    ]
                  })
                ]
              }),
              messageBreakdown.toolCallsByType.length > 0 && /* @__PURE__ */ jsx_runtime2.jsxs(ThemedBox_default, {
                flexDirection: "column",
                marginTop: 1,
                children: [
                  /* @__PURE__ */ jsx_runtime2.jsx(ThemedText, {
                    bold: true,
                    children: "[ANT-ONLY] Top tools"
                  }),
                  messageBreakdown.toolCallsByType.slice(0, 5).map((tool, i) => /* @__PURE__ */ jsx_runtime2.jsxs(ThemedBox_default, {
                    marginLeft: 1,
                    children: [
                      /* @__PURE__ */ jsx_runtime2.jsxs(ThemedText, {
                        children: [
                          "\u2514 ",
                          tool.name,
                          ": "
                        ]
                      }),
                      /* @__PURE__ */ jsx_runtime2.jsxs(ThemedText, {
                        dimColor: true,
                        children: [
                          "calls ",
                          formatTokens(tool.callTokens),
                          ", results ",
                          formatTokens(tool.resultTokens)
                        ]
                      })
                    ]
                  }, i))
                ]
              }),
              messageBreakdown.attachmentsByType.length > 0 && /* @__PURE__ */ jsx_runtime2.jsxs(ThemedBox_default, {
                flexDirection: "column",
                marginTop: 1,
                children: [
                  /* @__PURE__ */ jsx_runtime2.jsx(ThemedText, {
                    bold: true,
                    children: "[ANT-ONLY] Top attachments"
                  }),
                  messageBreakdown.attachmentsByType.slice(0, 5).map((attachment, i) => /* @__PURE__ */ jsx_runtime2.jsxs(ThemedBox_default, {
                    marginLeft: 1,
                    children: [
                      /* @__PURE__ */ jsx_runtime2.jsxs(ThemedText, {
                        children: [
                          "\u2514 ",
                          attachment.name,
                          ": "
                        ]
                      }),
                      /* @__PURE__ */ jsx_runtime2.jsxs(ThemedText, {
                        dimColor: true,
                        children: [
                          formatTokens(attachment.tokens),
                          " tokens"
                        ]
                      })
                    ]
                  }, i))
                ]
              })
            ]
          })
        ]
      }),
      /* @__PURE__ */ jsx_runtime2.jsx(ContextSuggestions, {
        suggestions: generateContextSuggestions(data)
      })
    ]
  });
}
var jsx_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_runtime2 = __toESM(require_jsx_runtime(), 1);
  SOURCE_DISPLAY_ORDER = ["Project", "User", "Managed", "Plugin", "Built-in"];
});

// src/commands/context/context.tsx
function toApiView(messages) {
  let view = getMessagesAfterCompactBoundary(messages);
  if (false) {}
  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_runtime3.jsx(ContextVisualization, {
    data
  }));
  onDone(output);
  return null;
}
var jsx_runtime3;
var init_context = __esm(() => {
  init_ContextVisualization();
  init_microCompact();
  init_analyzeContext();
  init_messages();
  init_staticRender();
  jsx_runtime3 = __toESM(require_jsx_runtime(), 1);
});
init_context();

export {
  call
};

//# debugId=681CDCFCF4807A1B64756E2164756E21
//# sourceMappingURL=chunk-y2w1zzx0.js.map
