import{Q as xq,R as Fq,S as Hq,T as Jq,U as Qq,V as Xq}from"./cli-0.5.4-cj2d501t.mjs";import{W as G,X as K}from"./cli-0.5.4-mfkj6e0e.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.4-tmpy7757.mjs";import{Ac as T,Bc as S}from"./cli-0.5.4-q7qfy21z.mjs";import"./cli-0.5.4-1cnxcper.mjs";import{$H as t,AH as M,Cm as O,DH as bq,Dm as Rq,GH as c,GI as o,HH as g,JI as Tq,MH as hq,VH as u,WH as A,Xm as f,Zm as Bq,_H as p,cI as a,dI as l,en as D,fI as Uq,gI as i,gn as d,hn as yq,mI as n,qI as Vq}from"./cli-0.5.4-k5fz4zd3.mjs";import"./cli-0.5.4-wbqf44ym.mjs";import"./cli-0.5.4-9ewg9gfs.mjs";import"./cli-0.5.4-we3mspgg.mjs";import"./cli-0.5.4-jzhazry0.mjs";import"./cli-0.5.4-82sw3hrw.mjs";import"./cli-0.5.4-31v143kt.mjs";import"./cli-0.5.4-1cy7wd6s.mjs";import"./cli-0.5.4-5e0pk96f.mjs";import"./cli-0.5.4-z154a7bp.mjs";import"./cli-0.5.4-ng5p0zjs.mjs";import"./cli-0.5.4-5hp7ks3t.mjs";import"./cli-0.5.4-8hdwp78f.mjs";import"./cli-0.5.4-mr9aznxx.mjs";import"./cli-0.5.4-jevfk5q7.mjs";import"./cli-0.5.4-27dzbzdy.mjs";import"./cli-0.5.4-a5bkdqqb.mjs";import"./cli-0.5.4-j2hnw539.mjs";import"./cli-0.5.4-9w59nnw4.mjs";import"./cli-0.5.4-z5d3q8kh.mjs";import"./cli-0.5.4-c0r12dqp.mjs";import"./cli-0.5.4-kqh172jk.mjs";import"./cli-0.5.4-vv4jbgkc.mjs";import"./cli-0.5.4-s7k1f0wc.mjs";import"./cli-0.5.4-0h0yz2k5.mjs";import"./cli-0.5.4-942dm5q1.mjs";import"./cli-0.5.4-rcmp5h4y.mjs";import"./cli-0.5.4-xdcww3x8.mjs";import"./cli-0.5.4-fq32ny1h.mjs";import"./cli-0.5.4-h1m67ngp.mjs";import"./cli-0.5.4-49erze3e.mjs";import"./cli-0.5.4-jytjks37.mjs";import"./cli-0.5.4-mn22gk7g.mjs";import"./cli-0.5.4-5t3jj85n.mjs";import"./cli-0.5.4-5shjmmkz.mjs";import"./cli-0.5.4-zb412kkm.mjs";import"./cli-0.5.4-prfn3sxd.mjs";import"./cli-0.5.4-6xmgebmk.mjs";import"./cli-0.5.4-vjgejcrz.mjs";import"./cli-0.5.4-jqt00ywx.mjs";import"./cli-0.5.4-9e7rkd8e.mjs";import"./cli-0.5.4-jp4wtw87.mjs";import"./cli-0.5.4-hambpq58.mjs";import"./cli-0.5.4-syvgmg9g.mjs";import"./cli-0.5.4-w8ttefr5.mjs";import"./cli-0.5.4-j7kkqxv6.mjs";import"./cli-0.5.4-qrwczx7j.mjs";import"./cli-0.5.4-v2z6p9td.mjs";import{B6 as k,J6 as Gq,K6 as X,L6 as Wq,Z_ as I,f$ as Kq}from"./cli-0.5.4-cbq01zg3.mjs";import"./cli-0.5.4-37v5fhf1.mjs";import"./cli-0.5.4-7grzwf6q.mjs";import"./cli-0.5.4-9qmek5dq.mjs";import"./cli-0.5.4-9c6r1fjg.mjs";import"./cli-0.5.4-2dw33ms6.mjs";import"./cli-0.5.4-x1fzfxmm.mjs";import"./cli-0.5.4-e822fzaq.mjs";import{Nea as B,Pea as jq}from"./cli-0.5.4-09dvrzcr.mjs";import{sfa as C,xfa as zq}from"./cli-0.5.4-end8wj9r.mjs";import"./cli-0.5.4-4x206j04.mjs";import"./cli-0.5.4-yd3rd9qt.mjs";import{Gga as P,Nga as $q}from"./cli-0.5.4-sgcaw17t.mjs";import{Uka as y,ima as Zq}from"./cli-0.5.4-jmc3bzbn.mjs";import"./cli-0.5.4-959vxhhb.mjs";import{_ma as Yq}from"./cli-0.5.4-aacw1src.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.4-ggdp8mk6.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};
