import{n as e,t}from"./figures-gfT9mM8P.js";import{U as n,z as r}from"./debug-otxXY3j-.js";import{n as i,r as a}from"./analytics-DqMQntaB.js";import{n as o,o as s}from"./process-DMKLUQIO.js";import{o as c,s as l}from"./log-DSV4Ht5l.js";import{As as u,SE as d,bv as f,js as p,vv as m,wE as h,yv as g}from"./loadAgentsDir-C_wFhytF.js";import{i as _,o as v}from"./xml-CVF7dWfi.js";import{a as y,c as b,d as x,f as S,i as C,r as w,s as T}from"./pluginOperations-gZ-iCmhu.js";e(),n(),h(),c(),p(),_(),o(),f(),i(),T();function E(e,n,i){l(e);let o=i?`${n} plugin "${i}"`:n===`disable-all`?`disable all plugins`:`${n} plugins`;console.error(`${t.cross} Failed to ${o}: ${r(e)}`);let s=i?(()=>{let{name:e,marketplace:t}=v(i);return{_PROTO_plugin_name:e,...t&&{_PROTO_marketplace_name:t},...m(e,t,u())}})():{};a(`tengu_plugin_command_failed`,{command:n,error_category:g(e),...s}),process.exit(1)}async function D(e,n=`user`){try{console.log(`Installing plugin "${e}"...`);let r=await b(e,n);if(!r.success)throw Error(r.message);console.log(`${t.tick} ${r.message}`);let{name:i,marketplace:o}=v(r.pluginId||e);a(`tengu_plugin_installed_cli`,{_PROTO_plugin_name:i,...o&&{_PROTO_marketplace_name:o},scope:r.scope||n,install_source:`cli-explicit`,...m(i,o,u())}),process.exit(0)}catch(t){E(t,`install`,e)}}async function O(e,n=`user`,r=!1){try{let i=await x(e,n,!r);if(!i.success)throw Error(i.message);console.log(`${t.tick} ${i.message}`);let{name:o,marketplace:s}=v(i.pluginId||e);a(`tengu_plugin_uninstalled_cli`,{_PROTO_plugin_name:o,...s&&{_PROTO_marketplace_name:s},scope:i.scope||n,...m(o,s,u())}),process.exit(0)}catch(t){E(t,`uninstall`,e)}}async function k(e,n){try{let r=await y(e,n);if(!r.success)throw Error(r.message);console.log(`${t.tick} ${r.message}`);let{name:i,marketplace:o}=v(r.pluginId||e);a(`tengu_plugin_enabled_cli`,{_PROTO_plugin_name:i,...o&&{_PROTO_marketplace_name:o},scope:r.scope,...m(i,o,u())}),process.exit(0)}catch(t){E(t,`enable`,e)}}async function A(e,n){try{let r=await C(e,n);if(!r.success)throw Error(r.message);console.log(`${t.tick} ${r.message}`);let{name:i,marketplace:o}=v(r.pluginId||e);a(`tengu_plugin_disabled_cli`,{_PROTO_plugin_name:i,...o&&{_PROTO_marketplace_name:o},scope:r.scope,...m(i,o,u())}),process.exit(0)}catch(t){E(t,`disable`,e)}}async function j(){try{let e=await w();if(!e.success)throw Error(e.message);console.log(`${t.tick} ${e.message}`),a(`tengu_plugin_disabled_all_cli`,{}),process.exit(0)}catch(e){E(e,`disable-all`)}}async function M(e,n){try{s(`Checking for updates for plugin "${e}" at ${n} scope…\n`);let r=await S(e,n);if(!r.success)throw Error(r.message);if(s(`${t.tick} ${r.message}\n`),!r.alreadyUpToDate){let{name:t,marketplace:n}=v(r.pluginId||e);a(`tengu_plugin_updated_cli`,{_PROTO_plugin_name:t,...n&&{_PROTO_marketplace_name:n},old_version:r.oldVersion||`unknown`,new_version:r.newVersion||`unknown`,...m(t,n,u())})}await d(0)}catch(t){E(t,`update`,e)}}export{O as a,D as i,A as n,M as o,k as r,j as t};