import{n as e}from"./chunk-DR8-3Aex.js";import{Qa as t,fs as n,lo as r,oo as i,us as a}from"./paths-Ci1iwL5Y.js";import{l as o,p as s}from"./debug-otxXY3j-.js";import{n as c,t as l}from"./cwd--iizewsn.js";import{o as u,s as d}from"./log-DSV4Ht5l.js";import{Ds as f,Ks as p,Ms as m,Ss as h,aj as g,oj as _,qs as v,ws as y}from"./loadAgentsDir-C_wFhytF.js";import{i as b,s as x}from"./xml-CVF7dWfi.js";import{join as S}from"path";function C(){let e=new Map,n=g();for(let[t,r]of Object.entries(n))t.includes(`@`)&&(r===!0?e.set(t,`flag`):r===!1&&e.delete(t));for(let{scope:r,source:i}of[{scope:`managed`,source:`policySettings`},{scope:`user`,source:`userSettings`},{scope:`project`,source:`projectSettings`},{scope:`local`,source:`localSettings`},{scope:`flag`,source:`flagSettings`}]){let a=t(i);if(a?.enabledPlugins)for(let[t,o]of Object.entries(a.enabledPlugins))t.includes(`@`)&&(t in n&&n[t]!==o&&s(`Plugin ${t} from --add-dir (${n[t]}) overridden by ${i} (${o})`),o===!0?e.set(t,r):o===!1&&e.delete(t))}return s(`Found ${e.size} enabled plugins with scopes: ${Array.from(e.entries()).map(([e,t])=>`${e}(${t})`).join(`, `)}`),e}async function w(e,i,a=`user`){let o=a===`user`?void 0:l(),s=x(a),c=t(s),u={...c?.enabledPlugins},m=[],g=[];for(let t=0;t<e.length;t++){let r=e[t];if(r){i&&i(r,t+1,e.length);try{let e=await p(r);if(!e){g.push({name:r,error:`Plugin not found in any marketplace`});continue}let{entry:t,marketplaceInstallLocation:i}=e;n(t.source)?f({pluginId:r,installPath:S(i,t.source),version:t.version},a,o):await h(r,t,a,o),u[r]=!0,m.push(r)}catch(e){let t=e instanceof Error?e.message:String(e);g.push({name:r,error:t}),d(e)}}}return r(s,{...c,enabledPlugins:u}),{installed:m,failed:g}}var T=e((()=>{c(),o(),u(),i(),_(),m(),v(),b(),y(),a()}));export{T as n,w as r,C as t};