| 4704 | Original error: ${O.stderr}`}}if(!O.stderr)return{code:O.code,stderr:O.error||`git clone exited with code ${O.code} (no stderr output). Run with --debug to see the full command.`};return O}function Cb(q,K){if(!q)return;try{q(K)}catch(_){N(`Progress callback error: ${d6(_)}`,{level:"warn"})}}async function rzY(q,K){let _={...process.env,...b18};if(K&&K.length>0)return S7(L7(),["sparse-checkout","set","--cone","--",...K],{cwd:q,timeout:ga(),stdin:"ignore",env:_});let z=await S7(L7(),["config","--get","core.sparseCheckout"],{cwd:q,stdin:"ignore",env:_});if(z.code===0&&z.stdout.trim()==="true")return{code:1,stderr:"sparsePaths removed from config but repository is sparse; re-cloning for full checkout"};return{code:0,stderr:""}}async function Ba(q,K,_,z,Y,$){let A=X8(),O=Math.round(ga()/1000);Cb(Y,`Refreshing marketplace cache (timeout: ${O}s)…`);let w=await rzY(K,z);if(w.code===0){let M=performance.now(),X=await lzY(K,_,{disableCredentialHelper:$?.disableCredentialHelper,sparsePaths:z});if(KD("marketplace_pull",q,X.code===0?"success":"failure",performance.now()-M,X.code===0?void 0:zC(X.stderr)),X.code===0)return;N(`git pull failed, will re-clone: ${X.stderr}`,{level:"warn"})}else N(`sparse-checkout reconcile requires re-clone: ${w.stderr}`);try{await A.rm(K,{recursive:!0}),N(`Found stale marketplace directory at ${K}, cleaning up to allow re-clone`,{level:"warn"}),Cb(Y,"Found stale directory, cleaning up and re-cloning…")}catch(M){if(!_7(M)){let X=d6(M);throw Error(`Failed to clean up existing marketplace directory. Please manually delete the directory at ${K} and try again. |
| 4706 | Technical details: ${X}`)}}let j=_?` (ref: ${_})`:"";Cb(Y,`Cloning repository (timeout: ${O}s): ${EH6(q)}${j}`);let H=performance.now(),J=await izY(q,K,_,z);if(KD("marketplace_clone",q,J.code===0?"success":"failure",performance.now()-H,J.code===0?void 0:zC(J.stderr)),J.code!==0){try{await A.rm(K,{recursive:!0,force:!0})}catch{}throw Error(`Failed to clone marketplace repository: ${J.stderr}`)}Cb(Y,"Clone complete, validating marketplace…")}function ozY(q){return Object.fromEntries(Object.entries(q).map(([K])=>[K,"***REDACTED***"]))}function EH6(q){try{let K=new URL(q);if((K.protocol==="http:"||K.protocol==="https:")&&(K.username||K.password)){if(K.username)K.username="***";if(K.password)K.password="***";return K.toString()}}catch{}return q}async function efK(q,K,_,z){let Y=X8(),$=EH6(q);if(Cb(z,`Downloading marketplace from ${$}`),N(`Downloading marketplace from URL: ${$}`),_&&Object.keys(_).length>0)N(`Using custom headers: ${g6(ozY(_))}`);let A={..._,"User-Agent":"Claude-Code-Plugin-Manager"},O,w=performance.now();try{O=await $1.get(q,{timeout:1e4,headers:A})}catch(J){if(KD("marketplace_url",q,"failure",performance.now()-w,zC(J)),$1.isAxiosError(J)){if(J.code==="ECONNREFUSED"||J.code==="ENOTFOUND")throw Error(`Could not connect to ${$}. Please check your internet connection and verify the URL is correct. |
| 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. |