import{U as e,l as t,p as n,z as r}from"./debug-otxXY3j-.js";import{Ms as i,Rs as a,Ws as o,Ys as s,qs as c}from"./loadAgentsDir-C_wFhytF.js";import{d as l,s as u}from"./pluginOperations-gZ-iCmhu.js";import{i as d,n as f,r as p,t as m}from"./pluginFlagging-BiTDVP10.js";u(),t(),e(),i(),c(),p();function h(e,t,n){let r=new Set(t.plugins.map(e=>e.name)),i=`@${n}`,a=[];for(let t of Object.keys(e.plugins)){if(!t.endsWith(i))continue;let e=t.slice(0,-i.length);r.has(e)||a.push(t)}return a}async function g(){await d();let e=a(),t=f(),i=await s(),c=[];for(let a of Object.keys(i))try{let i=await o(a);if(!i.forceRemoveDeletedPlugins)continue;let s=h(e,i,a);for(let i of s){if(i in t)continue;let a=e.plugins[i]??[];if(a.some(e=>e.scope===`user`||e.scope===`project`||e.scope===`local`)){for(let e of a){let{scope:t}=e;if(!(t!==`user`&&t!==`project`&&t!==`local`))try{await l(i,t)}catch(e){n(`Failed to auto-uninstall delisted plugin ${i} from ${t}: ${r(e)}`,{level:`error`})}}await m(i),c.push(i)}}}catch(e){n(`Failed to check for delisted plugins in "${a}": ${r(e)}`,{level:`warn`})}return c}export{g as t};