| 4712 | Technical details: ${J.message}`)}throw Error(`Failed to download marketplace from ${$}: ${d6(J)}`)}Cb(z,"Validating marketplace data");let j=de().safeParse(O.data);if(!j.success)throw KD("marketplace_url",q,"failure",performance.now()-w,"invalid_schema"),new hT(`Invalid marketplace schema from URL: ${j.error.issues.map((J)=>`${J.path.join(".")}: ${J.message}`).join(", ")}`,$,O.data);KD("marketplace_url",q,"success",performance.now()-w),Cb(z,"Saving marketplace to cache");let H=dX(K,"..");await Y.mkdir(H),$j(K,g6(j.data,null,2),{encoding:"utf-8",flush:!0})}function azY(q){return q.source==="github"?q.repo.replace("/","-"):q.source==="npm"?q.package.replace("@","").replace("/","-"):q.source==="file"?rfK(q.path).replace(".json",""):q.source==="directory"?rfK(q.path):"temp_"+Date.now()}async function m17(q,K){let z=await X8().readFile(q,{encoding:"utf-8"}),Y;try{Y=r8(z)}catch(A){throw new hT(`Invalid JSON in ${q}: ${d6(A)}`,q,z)}let $=K.safeParse(Y);if(!$.success)throw new hT(`Invalid schema: ${q} ${$.error?.issues.map((A)=>`${A.path.join(".")}: ${A.message}`).join(", ")}`,q,Y);return $.data}async function p17(q,K){let _=X8(),z=sK6();await _.mkdir(z);let Y,$,A=!1,O=azY(q);try{switch(q.source){case"url":{Y=dX(z,`${O}.json`),A=!0,await efK(q.url,Y,q.headers,K),$=Y;break}case"github":{let M=`git@github.com:${q.repo}.git`,X=`https://github.com/${q.repo}.git`;Y=dX(z,O),A=!0;let P=null;if(await tfK()){Cb(K,`Cloning via SSH: ${M}`);try{await Ba(M,Y,q.ref,q.sparsePaths,K)}catch(D){P=x1(D),H6(P),Cb(K,`SSH clone failed, retrying with HTTPS: ${X}`),N(`SSH clone failed for ${q.repo} despite SSH being configured, falling back to HTTPS`,{level:"info"}),await _.rm(Y,{recursive:!0,force:!0});try{await Ba(X,Y,q.ref,q.sparsePaths,K),P=null}catch(f){P=x1(f),H6(P)}}}else{Cb(K,`SSH not configured, cloning via HTTPS: ${X}`),N(`SSH not configured for GitHub, using HTTPS for ${q.repo}`,{level:"info"});try{await Ba(X,Y,q.ref,q.sparsePaths,K)}catch(D){P=x1(D),H6(P),Cb(K,`HTTPS clone failed, retrying with SSH: ${M}`),N(`HTTPS clone failed for ${q.repo} (${P.message}), falling back to SSH`,{level:"info"}),await _.rm(Y,{recursive:!0,force:!0});try{await Ba(M,Y,q.ref,q.sparsePaths,K),P=null}catch(f){P=x1(f),H6(P)}}}if(P)throw P;$=dX(Y,q.path||".claude-plugin/marketplace.json");break}case"git":{Y=dX(z,O),A=!0,await Ba(q.url,Y,q.ref,q.sparsePaths,K),$=dX(Y,q.path||".claude-plugin/marketplace.json");break}case"npm":throw Error("NPM marketplace sources not yet implemented");case"file":{let M=Kd(q.path);$=M,Y=u17(u17(M)),A=!1;break}case"directory":{let M=Kd(q.path);$=dX(M,".claude-plugin","marketplace.json"),Y=M,A=!1;break}case"settings":{Y=dX(z,q.name),$=dX(Y,".claude-plugin","marketplace.json"),A=!1,await _.mkdir(u17($)),await FzY($,g6({name:q.name,owner:q.owner??{name:"settings"},plugins:q.plugins},null,2));break}default:throw Error("Unsupported marketplace source type")}N(`Reading marketplace from ${$}`);let w;try{w=await m17($,de())}catch(M){if(_7(M))throw Error(`Marketplace file not found at ${$}`);throw Error(`Failed to parse marketplace file at ${$}: ${d6(M)}`)}let j=dX(z,w.name),H=Kd(j),J=Kd(z);if(!H.startsWith(J+fB8))throw Error(`Marketplace name '${w.name}' resolves to a path outside the cache directory`);if(Y!==j&&!SB(q))try{try{K?.("Cleaning up old marketplace cache…")}catch(M){N(`Progress callback error: ${d6(M)}`,{level:"warn"})}await _.rm(j,{recursive:!0,force:!0}),await _.rename(Y,j),Y=j,A=!1}catch(M){let X=d6(M);throw Error(`Failed to finalize marketplace cache. Please manually delete the directory at ${j} if it exists and try again. |