| 4717 | git@your-github-host.com:${_.repo}.git`;throw Error(M)}let z=await r_();for(let[j,H]of Object.entries(z))if(QJ(H.source,_))return N(`Source already materialized as '${j}', skipping clone`),{name:j,alreadyMaterialized:!0,resolvedSource:_};let{marketplace:Y,cachePath:$}=await p17(_,K),A=ah7(Y.name,_);if(A)throw Error(A);let O=await r_(),w=O[Y.name];if(w){let j=u18(w.installLocation);if(j)throw Error(`Marketplace '${Y.name}' is seed-managed (${j}). To use a different source, ask your admin to update the seed, or use a different marketplace name.`);if(N(`Marketplace '${Y.name}' exists with different source — overwriting`),!SB(w.source)){let H=Kd(sK6()),J=Kd(w.installLocation),M=Kd($);if(J===M);else if(J===H||J.startsWith(H+fB8))await X8().rm(w.installLocation,{recursive:!0,force:!0});else N(`Skipping cleanup of old installLocation (${w.installLocation}) — `+`outside ${H}. The path is corrupted; leaving it alone and overwriting the config entry.`,{level:"warn"})}}return O[Y.name]={source:_,installLocation:$,lastUpdated:new Date().toISOString()},await _d(O),N(`Added marketplace source: ${Y.name}`),{name:Y.name,alreadyMaterialized:!1,resolvedSource:_}}async function Mh6(q){let K=await r_();if(!K[q])throw Error(`Marketplace '${q}' not found`);let _=K[q],z=u18(_.installLocation);if(z)throw Error(`Marketplace '${q}' is registered from the read-only seed directory (${z}) and will be re-registered on next startup. To stop using its plugins: claude plugin disable <plugin>@${q}`);delete K[q],await _d(K);let Y=X8(),$=sK6(),A=dX($,q);await Y.rm(A,{recursive:!0,force:!0});let O=dX($,`${q}.json`);await Y.rm(O,{force:!0});let w=["userSettings","projectSettings","localSettings"];for(let J of w){let M=v1(J);if(!M)continue;let X=!1,P={};if(M.extraKnownMarketplaces?.[q]){let W={...M.extraKnownMarketplaces};W[q]=void 0,P.extraKnownMarketplaces=W,X=!0}if(M.enabledPlugins){let W=`@${q}`,D={...M.enabledPlugins},f=!1;for(let G in D)if(G.endsWith(W))D[G]=void 0,f=!0;if(f)P.enabledPlugins=D,X=!0}if(X){let W=W7(J,P);if(W.error)H6(W.error),N(`Failed to clean up marketplace '${q}' from ${J} settings: ${W.error.message}`);else N(`Cleaned up marketplace '${q}' from ${J} settings`)}}let{orphanedPaths:j,removedPluginIds:H}=_0K(q);for(let J of j)await wh6(J);for(let J of H)Ak8(J),await WT8(J);N(`Removed marketplace source: ${q}`)}async function x18(q){let K=dX(q,".claude-plugin","marketplace.json");try{return await m17(K,de())}catch(_){if(_ instanceof hT)throw _;let z=s1(_);if(z!=="ENOENT"&&z!=="ENOTDIR")throw _}return await m17(q,de())}async function m18(q){let K=X8(),_=ZB8();try{let z=await K.readFile(_,{encoding:"utf-8"}),$=r8(z)[q];if(!$)return null;return await x18($.installLocation)}catch(z){if(_7(z))return null;return N(`Failed to read cached marketplace ${q}: ${d6(z)}`,{level:"warn"}),null}}async function B17(q){let{name:K,marketplace:_}=Z4(q);if(!K||!_)return null;let z=X8(),Y=ZB8();try{let $=await z.readFile(Y,{encoding:"utf-8"}),O=r8($)[_];if(!O)return null;let w=await m18(_);if(!w)return null;let j=w.plugins.find((H)=>H.name===K);if(!j)return null;return{entry:j,marketplaceInstallLocation:O.installLocation}}catch{return null}}async function aG(q){let K=await B17(q);if(K)return K;let{name:_,marketplace:z}=Z4(q);if(!_||!z)return null;try{let $=(await r_())[z];if(!$)return null;let O=(await r0(z)).plugins.find((w)=>w.name===_);if(!O)return null;return{entry:O,marketplaceInstallLocation:$.installLocation}}catch(Y){return N(`Could not find plugin ${q}: ${d6(Y)}`,{level:"debug"}),null}}async function q0K(){let q=await r_();for(let[K,_]of Object.entries(q)){if(u18(_.installLocation)){N(`Skipping seed-managed marketplace '${K}' in bulk refresh`);continue}if(_.source.source==="settings")continue;if(K===C2){if(await C18(_.installLocation,sK6())!==null){q[K].lastUpdated=new Date().toISOString();continue}if(!g8("tengu_plugin_official_mkt_git_fallback",!0)){N("Skipping official marketplace bulk refresh: GCS failed, git fallback disabled");continue}}try{let{cachePath:z}=await p17(_.source);q[K].lastUpdated=new Date().toISOString(),q[K].installLocation=z}catch(z){N(`Failed to refresh marketplace ${K}: ${d6(z)}`,{level:"error"})}}await _d(q)}async function q56(q,K,_){let z=await r_(),Y=z[q];if(!Y)throw Error(`Marketplace '${q}' not found. Available marketplaces: ${Object.keys(z).join(", ")}`);if(r0.cache?.delete?.(q),Y.source.source==="settings"){N(`Skipping refresh for settings-sourced marketplace '${q}' — no upstream`);return}try{let{installLocation:$,source:A}=Y,O=u18($);if(O)throw Error(`Marketplace '${q}' is seed-managed (${O}) and its content is controlled by the seed image. To update: ask your admin to update the seed.`);if(!SB(A)){let w=Kd(sK6()),j=Kd($);if(j!==w&&!j.startsWith(w+fB8))throw Error(`Marketplace '${q}' has a corrupted installLocation (${$}) — expected a path inside ${w}. This can happen after cross-platform path writes or manual edits to known_marketplaces.json. Run: claude plugin marketplace remove "${q}" and re-add it.`)}if(q===C2){if(await C18($,sK6())!==null){z[q]={...Y,lastUpdated:new Date().toISOString()},await _d(z);return}if(!g8("tengu_plugin_official_mkt_git_fallback",!0))throw Error("Official marketplace GCS fetch failed and git fallback is disabled");N("Official marketplace GCS failed; falling back to git",{level:"warn"})}if(A.source==="github"||A.source==="git"){if(A.source==="github"){let w=`git@github.com:${A.repo}.git`,j=`https://github.com/${A.repo}.git`;if(i6(process.env.CLAUDE_CODE_REMOTE))await Ba(j,$,A.ref,A.sparsePaths,K,_);else{let H=await tfK(),J=H?w:j,M=H?j:w;try{await Ba(J,$,A.ref,A.sparsePaths,K,_)}catch{N(`Marketplace refresh failed with ${H?"SSH":"HTTPS"} for ${A.repo}, falling back to ${H?"HTTPS":"SSH"}`,{level:"info"}),await Ba(M,$,A.ref,A.sparsePaths,K,_)}}}else await Ba(A.url,$,A.ref,A.sparsePaths,K,_);try{await x18($)}catch{let w=A.source==="github"?A.repo:EH6(A.url);throw Error(`The marketplace.json file is no longer present in this repository. |