import{n as e}from"./chunk-DR8-3Aex.js";import{cn as t,ot as n}from"./state-sIHsFpDu.js";import{U as r,l as i,p as a,z as o}from"./debug-otxXY3j-.js";import{o as s,s as c}from"./log-DSV4Ht5l.js";import{Bh as l,Gh as u,Hh as d,Oc as f,Wh as p,Yp as m,gc as h,hc as g,i as _,kc as v,nT as y,o as b,oy as x,qp as S,sy as C,tT as w,vs as T,ys as E}from"./loadAgentsDir-C_wFhytF.js";async function D(e){a(`refreshActivePlugins: clearing all plugin caches`),g(),S();let t=await E(),[r,i]=await Promise.all([f(),_(n())]),{enabled:s,disabled:l,errors:p}=t,[m,h]=await Promise.all([Promise.all(s.map(async e=>{if(e.mcpServers)return Object.keys(e.mcpServers).length;let t=await y(e,p);return t&&(e.mcpServers=t),t?Object.keys(t).length:0})),Promise.all(s.map(async e=>{if(e.lspServers)return Object.keys(e.lspServers).length;let t=await u(e,p);return t&&(e.lspServers=t),t?Object.keys(t).length:0}))]),v=m.reduce((e,t)=>e+t,0),b=h.reduce((e,t)=>e+t,0);e(e=>({...e,plugins:{...e.plugins,enabled:s,disabled:l,commands:r,errors:O(e.plugins.errors,p),needsRefresh:!1},agentDefinitions:i,mcp:{...e.mcp,pluginReconnectKey:e.mcp.pluginReconnectKey+1}})),d();let x=!1;try{await C()}catch(e){x=!0,c(e),a(`refreshActivePlugins: loadPluginHooks failed: ${o(e)}`)}let w=s.reduce((e,t)=>t.hooksConfig?e+Object.values(t.hooksConfig).reduce((e,t)=>e+(t?.reduce((e,t)=>e+t.hooks.length,0)??0),0):e,0);return a(`refreshActivePlugins: ${s.length} enabled, ${r.length} commands, ${i.allAgents.length} agents, ${w} hooks, ${v} MCP, ${b} LSP`),{enabled_count:s.length,disabled_count:l.length,command_count:r.length,agent_count:i.allAgents.length,hook_count:w,mcp_count:v,lsp_count:b,error_count:p.length+ +!!x,agentDefinitions:i,pluginCommands:r}}function O(e,t){let n=e.filter(e=>e.source===`lsp-manager`||e.source.startsWith(`plugin:`)),r=new Set(t.map(k));return[...n.filter(e=>!r.has(k(e))),...t]}function k(e){return e.type===`generic-error`?`generic-error:${e.source}:${e.error}`:`${e.type}:${e.source}`}var A=e((()=>{t(),l(),b(),i(),r(),s(),h(),v(),x(),p(),w(),m(),T()}));export{D as n,A as t};