import{n as e}from"./chunk-DR8-3Aex.js";import{Gs as t,Ws as n}from"./paths-Ci1iwL5Y.js";import{b as r,x as i}from"./startupProfiler-CAntGAbs.js";import{Po as a,Uo as o,dl as s,iA as c,ll as l,rA as u}from"./loadAgentsDir-C_wFhytF.js";async function d(e){let{messages:t,getAppState:n,options:{mainLoopModel:r,tools:i,agentDefinitions:o,customSystemPrompt:s,appendSystemPrompt:u}}=e,d=a(t),{messages:f}=await c(d),p=n();return l(f,r,async()=>p.toolPermissionContext,i,o,void 0,{options:{customSystemPrompt:s,appendSystemPrompt:u}},void 0,d)}async function f(e,t){return{type:`text`,value:p(await d(t))}}function p(e){let{categories:t,totalTokens:i,rawMaxTokens:a,percentage:o,model:s,memoryFiles:c,mcpTools:l,agents:u,skills:d,messageBreakdown:f,systemTools:p,systemPromptSections:m}=e,h=`## Context Usage

`;h+=`**Model:** ${s}  \n`,h+=`**Tokens:** ${r(i)} / ${r(a)} (${o}%)\n`,h+=`
`;let g=t.filter(e=>e.tokens>0&&e.name!==`Free space`&&e.name!==`Autocompact buffer`);if(g.length>0){h+=`### Estimated usage by category

`,h+=`| Category | Tokens | Percentage |
`,h+=`|----------|--------|------------|
`;for(let e of g){let t=(e.tokens/a*100).toFixed(1);h+=`| ${e.name} | ${r(e.tokens)} | ${t}% |\n`}let e=t.find(e=>e.name===`Free space`);if(e&&e.tokens>0){let t=(e.tokens/a*100).toFixed(1);h+=`| Free space | ${r(e.tokens)} | ${t}% |\n`}let n=t.find(e=>e.name===`Autocompact buffer`);if(n&&n.tokens>0){let e=(n.tokens/a*100).toFixed(1);h+=`| Autocompact buffer | ${r(n.tokens)} | ${e}% |\n`}h+=`
`}if(l.length>0){h+=`### MCP Tools

`,h+=`| Tool | Server | Tokens |
`,h+=`|------|--------|--------|
`;for(let e of l)h+=`| ${e.name} | ${e.serverName} | ${r(e.tokens)} |\n`;h+=`
`}if(p&&p.length>0&&process.env.USER_TYPE===`ant`){h+=`### [ANT-ONLY] System Tools

`,h+=`| Tool | Tokens |
`,h+=`|------|--------|
`;for(let e of p)h+=`| ${e.name} | ${r(e.tokens)} |\n`;h+=`
`}if(m&&m.length>0&&process.env.USER_TYPE===`ant`){h+=`### [ANT-ONLY] System Prompt Sections

`,h+=`| Section | Tokens |
`,h+=`|---------|--------|
`;for(let e of m)h+=`| ${e.name} | ${r(e.tokens)} |\n`;h+=`
`}if(u.length>0){h+=`### Custom Agents

`,h+=`| Agent Type | Source | Tokens |
`,h+=`|------------|--------|--------|
`;for(let e of u){let t;switch(e.source){case`projectSettings`:t=`Project`;break;case`userSettings`:t=`User`;break;case`localSettings`:t=`Local`;break;case`flagSettings`:t=`Flag`;break;case`policySettings`:t=`Policy`;break;case`plugin`:t=`Plugin`;break;case`built-in`:t=`Built-in`;break;default:t=String(e.source)}h+=`| ${e.agentType} | ${t} | ${r(e.tokens)} |\n`}h+=`
`}if(c.length>0){h+=`### Memory Files

`,h+=`| Type | Path | Tokens |
`,h+=`|------|------|--------|
`;for(let e of c)h+=`| ${e.type} | ${e.path} | ${r(e.tokens)} |\n`;h+=`
`}if(d&&d.tokens>0&&d.skillFrontmatter.length>0){h+=`### Skills

`,h+=`| Skill | Source | Tokens |
`,h+=`|-------|--------|--------|
`;for(let e of d.skillFrontmatter)h+=`| ${e.name} | ${n(e.source)} | ${r(e.tokens)} |\n`;h+=`
`}if(f&&process.env.USER_TYPE===`ant`){if(h+=`### [ANT-ONLY] Message Breakdown

`,h+=`| Category | Tokens |
`,h+=`|----------|--------|
`,h+=`| Tool calls | ${r(f.toolCallTokens)} |\n`,h+=`| Tool results | ${r(f.toolResultTokens)} |\n`,h+=`| Attachments | ${r(f.attachmentTokens)} |\n`,h+=`| Assistant messages (non-tool) | ${r(f.assistantMessageTokens)} |\n`,h+=`| User messages (non-tool-result) | ${r(f.userMessageTokens)} |\n`,h+=`
`,f.toolCallsByType.length>0){h+=`#### Top Tools

`,h+=`| Tool | Call Tokens | Result Tokens |
`,h+=`|------|-------------|---------------|
`;for(let e of f.toolCallsByType)h+=`| ${e.name} | ${r(e.callTokens)} | ${r(e.resultTokens)} |\n`;h+=`
`}if(f.attachmentsByType.length>0){h+=`#### Top Attachments

`,h+=`| Attachment | Tokens |
`,h+=`|------------|--------|
`;for(let e of f.attachmentsByType)h+=`| ${e.name} | ${r(e.tokens)} |\n`;h+=`
`}}return h}var m=e((()=>{u(),s(),i(),o(),t()}));export{d as n,m as r,f as t};