import{o as e}from"./chunk-DR8-3Aex.js";import{Rn as t}from"./src-Di342QoJ.js";import{J as n,U as r,l as i,p as a}from"./debug-otxXY3j-.js";import{n as o,r as s}from"./analytics-DqMQntaB.js";import{F as c,P as l}from"./git-C0IuvuIy.js";import{o as u,s as d}from"./log-DSV4Ht5l.js";import{b as f,x as p}from"./teammate-CbskW5G9.js";import{Ac as m,Bh as h,Gh as g,Hh as _,Oc as v,Wh as y,fC as b,jc as x,kc as S,lC as C,nT as w,oC as T,oy as E,sC as D,sy as O,tT as k,uC as A,vs as j,ys as M}from"./loadAgentsDir-C_wFhytF.js";import{n as N,r as P}from"./pluginFlagging-BiTDVP10.js";import{t as F}from"./pluginBlocklist-B1LVo0j_.js";var I=e(t(),1);T(),o(),h(),C(),p(),i(),l(),r(),u(),m(),S(),E(),y(),k(),P(),j();function L({enabled:e=!0}={}){let t=b(),r=A(e=>e.plugins.needsRefresh),{addNotification:i}=D(),o=(0,I.useCallback)(async()=>{try{let{enabled:e,disabled:n,errors:r}=await M();await F();let o=N();Object.keys(o).length>0&&i({key:`plugin-delisted-flagged`,text:`Plugins flagged. Check /plugins`,color:`warning`,priority:`high`});let s=[],c=[];try{s=await v()}catch(e){let t=e instanceof Error?e.message:String(e);r.push({type:`generic-error`,source:`plugin-commands`,error:`Failed to load plugin commands: ${t}`})}try{c=await x()}catch(e){let t=e instanceof Error?e.message:String(e);r.push({type:`generic-error`,source:`plugin-agents`,error:`Failed to load plugin agents: ${t}`})}try{await O()}catch(e){let t=e instanceof Error?e.message:String(e);r.push({type:`generic-error`,source:`plugin-hooks`,error:`Failed to load plugin hooks: ${t}`})}let l=(await Promise.all(e.map(async e=>{if(e.mcpServers)return Object.keys(e.mcpServers).length;let t=await w(e,r);return t&&(e.mcpServers=t),t?Object.keys(t).length:0}))).reduce((e,t)=>e+t,0),u=(await Promise.all(e.map(async e=>{if(e.lspServers)return Object.keys(e.lspServers).length;let t=await g(e,r);return t&&(e.lspServers=t),t?Object.keys(t).length:0}))).reduce((e,t)=>e+t,0);_(),t(t=>{let i=t.plugins.errors.filter(e=>e.source===`lsp-manager`||e.source.startsWith(`plugin:`)),a=new Set(r.map(e=>e.type===`generic-error`?`generic-error:${e.source}:${e.error}`:`${e.type}:${e.source}`)),o=[...i.filter(e=>{let t=e.type===`generic-error`?`generic-error:${e.source}:${e.error}`:`${e.type}:${e.source}`;return!a.has(t)}),...r];return{...t,plugins:{...t.plugins,enabled:e,disabled:n,commands:s,errors:o}}}),a(`Loaded plugins - Enabled: ${e.length}, Disabled: ${n.length}, Commands: ${s.length}, Agents: ${c.length}, Errors: ${r.length}`);let d=e.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{enabled_count:e.length,disabled_count:n.length,inline_count:f(e,e=>e.source.endsWith(`@inline`)),marketplace_count:f(e,e=>!e.source.endsWith(`@inline`)),error_count:r.length,skill_count:s.length,agent_count:c.length,hook_count:d,mcp_count:l,lsp_count:u,ant_enabled_names:process.env.USER_TYPE===`ant`&&e.length>0?e.map(e=>e.name).sort().join(`,`):void 0}}catch(e){let r=n(e);return d(r),a(`Error loading plugins: ${e}`),t(e=>{let t=e.plugins.errors.filter(e=>e.source===`lsp-manager`||e.source.startsWith(`plugin:`)),n={type:`generic-error`,source:`plugin-system`,error:r.message};return{...e,plugins:{...e.plugins,enabled:[],disabled:[],commands:[],errors:[...t,n]}}}),{enabled_count:0,disabled_count:0,inline_count:0,marketplace_count:0,error_count:1,skill_count:0,agent_count:0,hook_count:0,mcp_count:0,lsp_count:0,load_failed:!0,ant_enabled_names:void 0}}},[t,i]);(0,I.useEffect)(()=>{e&&o().then(e=>{let{ant_enabled_names:t,...n}=e,r={...n,has_custom_plugin_cache_dir:!!process.env.CLAUDE_CODE_PLUGIN_CACHE_DIR};s(`tengu_plugins_loaded`,{...r,...t!==void 0&&{enabled_names:t}}),c(`info`,`tengu_plugins_loaded`,r)})},[o,e]),(0,I.useEffect)(()=>{!e||!r||i({key:`plugin-reload-pending`,text:`Plugins changed. Run /reload-plugins to activate.`,color:`suggestion`,priority:`low`})},[e,r,i])}export{L as t};