import{Q as xq,R as Fq,S as Hq,T as Jq,U as Qq,V as Xq}from"./cli-0.5.3-bbjy95xk.mjs";import{W as G,X as K}from"./cli-0.5.3-am51crcp.mjs";import{$b as Nq,_b as s,ac as r,cc as wq,dc as e,ec as qq,fc as Dq}from"./cli-0.5.3-c0nykds9.mjs";import{Ac as T,Bc as S}from"./cli-0.5.3-jxz68zfe.mjs";import"./cli-0.5.3-gngvzsr7.mjs";import{Am as O,BH as bq,Bm as Rq,EH as c,EI as o,FH as g,HI as Tq,KH as hq,TH as u,UH as A,Vm as f,Xm as Bq,YH as p,ZH as t,aI as a,bI as l,cn as D,dI as Uq,eI as i,en as d,fn as yq,kI as n,oI as Vq,yH as M}from"./cli-0.5.3-jbzr8k4s.mjs";import"./cli-0.5.3-me9jkw92.mjs";import"./cli-0.5.3-bqmztzjc.mjs";import"./cli-0.5.3-ytqxzjff.mjs";import"./cli-0.5.3-h6n812td.mjs";import"./cli-0.5.3-hg8c6qbh.mjs";import"./cli-0.5.3-39jr2yrx.mjs";import"./cli-0.5.3-42e2paz8.mjs";import"./cli-0.5.3-mn45xfck.mjs";import"./cli-0.5.3-m884a3pk.mjs";import"./cli-0.5.3-4f9xxrem.mjs";import"./cli-0.5.3-gr8nsa2k.mjs";import"./cli-0.5.3-yj9nbd9d.mjs";import"./cli-0.5.3-55kd38ff.mjs";import"./cli-0.5.3-e6bjcfwg.mjs";import"./cli-0.5.3-4dbxtwh3.mjs";import"./cli-0.5.3-m0kfmb79.mjs";import"./cli-0.5.3-8zq9vdtg.mjs";import"./cli-0.5.3-vmx7agj7.mjs";import"./cli-0.5.3-h8xs2818.mjs";import"./cli-0.5.3-wcx7cnw5.mjs";import"./cli-0.5.3-9zbakvbf.mjs";import"./cli-0.5.3-hx550gz2.mjs";import"./cli-0.5.3-842pf3t4.mjs";import"./cli-0.5.3-wxead1ct.mjs";import"./cli-0.5.3-s1hz35ye.mjs";import"./cli-0.5.3-g0svn6bx.mjs";import"./cli-0.5.3-sfdh3pkx.mjs";import"./cli-0.5.3-d8tjnxcj.mjs";import"./cli-0.5.3-6zfw1732.mjs";import"./cli-0.5.3-ptjdgcsy.mjs";import"./cli-0.5.3-tp3jye12.mjs";import"./cli-0.5.3-vqmxwet2.mjs";import"./cli-0.5.3-rch86nhn.mjs";import"./cli-0.5.3-zg2apr51.mjs";import"./cli-0.5.3-ngnshpb7.mjs";import"./cli-0.5.3-e58xste9.mjs";import"./cli-0.5.3-6163zevg.mjs";import"./cli-0.5.3-jmkkd5ph.mjs";import"./cli-0.5.3-1vt6twff.mjs";import"./cli-0.5.3-7017ez65.mjs";import"./cli-0.5.3-ea94acj4.mjs";import"./cli-0.5.3-3k22nqvy.mjs";import"./cli-0.5.3-63q4g3zt.mjs";import"./cli-0.5.3-dyhbm5kp.mjs";import"./cli-0.5.3-vpcrbd8n.mjs";import"./cli-0.5.3-jdw3ajfv.mjs";import"./cli-0.5.3-qg4a557t.mjs";import{H6 as Gq,I6 as X,J6 as Wq,X_ as I,d$ as Kq,z6 as k}from"./cli-0.5.3-t65dek0m.mjs";import"./cli-0.5.3-kavpx97n.mjs";import"./cli-0.5.3-9bdwhdys.mjs";import"./cli-0.5.3-ttc72eq3.mjs";import"./cli-0.5.3-g75gdzrp.mjs";import"./cli-0.5.3-1rg2r7n7.mjs";import"./cli-0.5.3-6j2jk6dt.mjs";import"./cli-0.5.3-66650sba.mjs";import{Lea as B,Nea as jq}from"./cli-0.5.3-9vh3vpap.mjs";import{qfa as C,vfa as zq}from"./cli-0.5.3-n3cxyxpg.mjs";import"./cli-0.5.3-kbvzmaax.mjs";import"./cli-0.5.3-7wdgps7z.mjs";import{Ega as P,Lga as $q}from"./cli-0.5.3-c8bcrqa4.mjs";import{Ska as y,gma as Zq}from"./cli-0.5.3-qrvd6cmy.mjs";import"./cli-0.5.3-2dk1sk8w.mjs";import{Yma as Yq}from"./cli-0.5.3-0df3r78b.mjs";Wq();Zq();jq();import{basename as _q,dirname as E}from"path";Rq();$q();Gq();bq();wq();Vq();hq();Uq();Bq();Nq();yq();Tq();Dq();zq();Kq();function L(F,q){k(F),G(`${X.cross} Failed to ${q}: ${P(F)}`)}function m(F){if(F.errors.length>0)console.log(`${X.cross} Found ${F.errors.length} ${I(F.errors.length,"error")}:
`),F.errors.forEach((q)=>{console.log(`  ${X.pointer} ${q.path}: ${q.message}`)}),console.log("");if(F.warnings.length>0)console.log(`${X.warning} Found ${F.warnings.length} ${I(F.warnings.length,"warning")}:
`),F.warnings.forEach((q)=>{console.log(`  ${X.pointer} ${q.path}: ${q.message}`)}),console.log("")}async function iq(F,q){if(q.cowork)y(!0);try{let x=await qq(F);console.log(`Validating ${x.fileType} manifest: ${x.filePath}
`),m(x);let H=[];if(x.fileType==="plugin"){let Z=E(x.filePath);if(_q(Z)===".claude-plugin"){H=await e(E(Z));for(let U of H)console.log(`Validating ${U.fileType}: ${U.filePath}
`),m(U)}}let J=x.success&&H.every((Z)=>Z.success),Y=x.warnings.length>0||H.some((Z)=>Z.warnings.length>0);if(J)K(Y?`${X.tick} Validation passed with warnings`:`${X.tick} Validation passed`);else console.log(`${X.cross} Validation failed`),process.exit(1)}catch(x){k(x),console.error(`${X.cross} Unexpected error during validation: ${P(x)}`),process.exit(2)}}async function nq(F){if(F.cowork)y(!0);B("tengu_plugin_list_command",{});let q=i(),{getPluginEditableScopes:x}=await import("./pluginStartupCheck-0.5.3-z5910fgv.mjs"),H=x(),J=Object.keys(q.plugins),{enabled:Y,disabled:Z,errors:U}=await o(),v=[...Y,...Z],_=v.filter(($)=>$.source.endsWith("@inline")),N=U.filter(($)=>$.source.endsWith("@inline")||$.source.startsWith("inline["));if(F.json){let $=new Map(v.map((Q)=>[Q.source,Q])),j=[];for(let Q of J.sort()){let z=q.plugins[Q];if(!z||z.length===0)continue;let R=D(Q).name,b=U.filter((W)=>W.source===Q||("plugin"in W)&&W.plugin===R).map(O);for(let W of z){let w=$.get(Q),h;if(w){let V=w.mcpServers||await f(w);if(V&&Object.keys(V).length>0)h=V}j.push({id:Q,version:W.version||"unknown",scope:W.scope,enabled:H.has(Q),installPath:W.installPath,installedAt:W.installedAt,lastUpdated:W.lastUpdated,projectPath:W.projectPath,mcpServers:h,errors:b.length>0?b:void 0})}}for(let Q of _){let z=Q.mcpServers||await f(Q),R=N.filter((b)=>b.source===Q.source||("plugin"in b)&&b.plugin===Q.name).map(O);j.push({id:Q.source,version:Q.manifest.version??"unknown",scope:"session",enabled:Q.enabled!==!1,installPath:Q.path,mcpServers:z&&Object.keys(z).length>0?z:void 0,errors:R.length>0?R:void 0})}for(let Q of N.filter((z)=>z.source.startsWith("inline[")))j.push({id:Q.source,version:"unknown",scope:"session",enabled:!1,installPath:"path"in Q?Q.path:"",errors:[O(Q)]});if(F.available){let Q=[];try{let[z,R]=await Promise.all([A(),r()]),{marketplaces:b}=await g(z);for(let{name:W,data:w}of b)if(w)for(let h of w.plugins){let V=c(h.name,W);if(!n(V))Q.push({pluginId:V,name:h.name,description:h.description,marketplaceName:W,version:h.version,source:h.source,installCount:R?.get(V)})}}catch{}K(C({installed:j,available:Q},null,2))}else K(C(j,null,2))}if(J.length===0&&_.length===0){if(N.length===0)K("No plugins installed. Use `claude plugin install` to install a plugin.")}if(J.length>0)console.log(`Installed plugins:
`);for(let $ of J.sort()){let j=q.plugins[$];if(!j||j.length===0)continue;let Q=D($).name,z=U.filter((R)=>R.source===$||("plugin"in R)&&R.plugin===Q);for(let R of j){let b=H.has($),W=z.length>0?`${X.cross} failed to load`:b?`${X.tick} enabled`:`${X.cross} disabled`,w=R.version||"unknown",h=R.scope;console.log(`  ${X.pointer} ${$}`),console.log(`    Version: ${w}`),console.log(`    Scope: ${h}`),console.log(`    Status: ${W}`);for(let V of z)console.log(`    Error: ${O(V)}`);console.log("")}}if(_.length>0||N.length>0){console.log(`Session-only plugins (--plugin-dir):
`);for(let $ of _){let j=N.filter((z)=>z.source===$.source||("plugin"in z)&&z.plugin===$.name),Q=j.length>0?`${X.cross} loaded with errors`:`${X.tick} loaded`;console.log(`  ${X.pointer} ${$.source}`),console.log(`    Version: ${$.manifest.version??"unknown"}`),console.log(`    Path: ${$.path}`),console.log(`    Status: ${Q}`);for(let z of j)console.log(`    Error: ${O(z)}`);console.log("")}for(let $ of N.filter((j)=>j.source.startsWith("inline[")))console.log(`  ${X.pointer} ${$.source}: ${X.cross} ${O($)}
`)}K()}async function oq(F,q){if(q.cowork)y(!0);try{let x=await s(F);if(!x)G(`${X.cross} Invalid marketplace source format. Try: owner/repo, https://..., or ./path`);if("error"in x)G(`${X.cross} ${x.error}`);let H=q.scope??"user";if(H!=="user"&&H!=="project"&&H!=="local")G(`${X.cross} Invalid scope '${H}'. Use: user, project, or local`);let J=d(H),Y=x;if(q.sparse&&q.sparse.length>0)if(Y.source==="github"||Y.source==="git")Y={...Y,sparsePaths:q.sparse};else G(`${X.cross} --sparse is only supported for github and git marketplace sources (got: ${Y.source})`);console.log("Adding marketplace...");let{name:Z,alreadyMaterialized:U,resolvedSource:v}=await p(Y,(N)=>{console.log(N)});u(Z,{source:v},J),M();let _=Y.source;if(Y.source==="github")_=Y.repo;B("tengu_marketplace_added",{source_type:_}),K(U?`${X.tick} Marketplace '${Z}' already on disk — declared in ${H} settings`:`${X.tick} Successfully added marketplace: ${Z} (declared in ${H} settings)`)}catch(x){L(x,"add marketplace")}}async function sq(F){if(F.cowork)y(!0);try{let q=await A(),x=Object.keys(q);if(F.json){let H=x.sort().map((J)=>{let Y=q[J],Z=Y?.source;return{name:J,source:Z?.source,...Z?.source==="github"&&{repo:Z.repo},...Z?.source==="git"&&{url:Z.url},...Z?.source==="url"&&{url:Z.url},...Z?.source==="directory"&&{path:Z.path},...Z?.source==="file"&&{path:Z.path},installLocation:Y?.installLocation}});K(C(H,null,2))}if(x.length===0)K("No marketplaces configured");console.log(`Configured marketplaces:
`),x.forEach((H)=>{let J=q[H];if(console.log(`  ${X.pointer} ${H}`),J?.source){let Y=J.source;if(Y.source==="github")console.log(`    Source: GitHub (${Y.repo})`);else if(Y.source==="git")console.log(`    Source: Git (${Y.url})`);else if(Y.source==="url")console.log(`    Source: URL (${Y.url})`);else if(Y.source==="directory")console.log(`    Source: Directory (${Y.path})`);else if(Y.source==="file")console.log(`    Source: File (${Y.path})`)}console.log("")}),K()}catch(q){L(q,"list marketplaces")}}async function rq(F,q){if(q.cowork)y(!0);try{await t(F),M(),B("tengu_marketplace_removed",{marketplace_name:F}),K(`${X.tick} Successfully removed marketplace: ${F}`)}catch(x){L(x,"remove marketplace")}}async function eq(F,q){if(q.cowork)y(!0);try{if(F)console.log(`Updating marketplace: ${F}...`),await l(F,(x)=>{console.log(x)}),M(),B("tengu_marketplace_updated",{marketplace_name:F}),K(`${X.tick} Successfully updated marketplace: ${F}`);else{let x=await A(),H=Object.keys(x);if(H.length===0)K("No marketplaces configured");console.log(`Updating ${H.length} marketplace(s)...`),await a(),M(),B("tengu_marketplace_updated_all",{count:H.length}),K(`${X.tick} Successfully updated ${H.length} marketplace(s)`)}}catch(x){L(x,"update marketplace(s)")}}async function qx(F,q){if(q.cowork)y(!0);let x=q.scope||"user";if(q.cowork&&x!=="user")G("--cowork can only be used with user scope");if(!T.includes(x))G(`Invalid scope: ${x}. Must be one of: ${T.join(", ")}.`);let{name:H,marketplace:J}=D(F);B("tengu_plugin_install_command",{_PROTO_plugin_name:H,...J&&{_PROTO_marketplace_name:J},scope:x}),await xq(F,x)}async function xx(F,q){if(q.cowork)y(!0);let x=q.scope||"user";if(q.cowork&&x!=="user")G("--cowork can only be used with user scope");if(!T.includes(x))G(`Invalid scope: ${x}. Must be one of: ${T.join(", ")}.`);let{name:H,marketplace:J}=D(F);B("tengu_plugin_uninstall_command",{_PROTO_plugin_name:H,...J&&{_PROTO_marketplace_name:J},scope:x}),await Fq(F,x,q.keepData)}async function Fx(F,q){if(q.cowork)y(!0);let x;if(q.scope){if(!T.includes(q.scope))G(`Invalid scope "${q.scope}". Valid scopes: ${T.join(", ")}`);x=q.scope}if(q.cowork&&x!==void 0&&x!=="user")G("--cowork can only be used with user scope");if(q.cowork&&x===void 0)x="user";let{name:H,marketplace:J}=D(F);B("tengu_plugin_enable_command",{_PROTO_plugin_name:H,...J&&{_PROTO_marketplace_name:J},scope:x??"auto"}),await Hq(F,x)}async function Hx(F,q){if(q.all&&F)G("Cannot use --all with a specific plugin");if(!q.all&&!F)G("Please specify a plugin name or use --all to disable all plugins");if(q.cowork)y(!0);if(q.all){if(q.scope)G("Cannot use --scope with --all");B("tengu_plugin_disable_command",{}),await Qq();return}let x;if(q.scope){if(!T.includes(q.scope))G(`Invalid scope "${q.scope}". Valid scopes: ${T.join(", ")}`);x=q.scope}if(q.cowork&&x!==void 0&&x!=="user")G("--cowork can only be used with user scope");if(q.cowork&&x===void 0)x="user";let{name:H,marketplace:J}=D(F);B("tengu_plugin_disable_command",{_PROTO_plugin_name:H,...J&&{_PROTO_marketplace_name:J},scope:x??"auto"}),await Jq(F,x)}async function Jx(F,q){if(q.cowork)y(!0);let{name:x,marketplace:H}=D(F);B("tengu_plugin_update_command",{_PROTO_plugin_name:x,...H&&{_PROTO_marketplace_name:H}});let J="user";if(q.scope){if(!S.includes(q.scope))G(`Invalid scope "${q.scope}". Valid scopes: ${S.join(", ")}`);J=q.scope}if(q.cowork&&J!=="user")G("--cowork can only be used with user scope");await Xq(F,J)}export{iq as pluginValidateHandler,Jx as pluginUpdateHandler,xx as pluginUninstallHandler,nq as pluginListHandler,qx as pluginInstallHandler,Fx as pluginEnableHandler,Hx as pluginDisableHandler,eq as marketplaceUpdateHandler,rq as marketplaceRemoveHandler,sq as marketplaceListHandler,oq as marketplaceAddHandler,L as handleMarketplaceError,S as VALID_UPDATE_SCOPES,T as VALID_INSTALLABLE_SCOPES};
