MCPcopy Create free account
hub / github.com/ChinaSiro/claude-code-sourcemap / EB8

Function EB8

package/cli.js:4721–4725  ·  view source on GitHub ↗
(q,K,_)

Source from the content-addressed store, hash-verified

4719${q==="claude-code-plugins"?`We've deprecated "claude-code-plugins" in favor of "claude-plugins-official".`:"This marketplace may have been deprecated or moved to a new location."}
4720Source: ${w}
4721
4722You can remove this marketplace with: claude plugin marketplace remove "${q}"`)}}else if(A.source==="url")await efK(A.url,$,A.headers,K);else if(SB(A))Cb(K,"Validating local marketplace"),await x18($);else throw Error("Unsupported marketplace source type for refresh");z[q].lastUpdated=new Date().toISOString(),await _d(z),N(`Successfully refreshed marketplace: ${q}`)}catch($){let A=$ instanceof Error?$.message:String($);throw N(`Failed to refresh marketplace ${q}: ${A}`,{level:"error"}),Error(`Failed to refresh marketplace '${q}': ${A}`)}}async function K0K(q,K){let _=await r_(),z=_[q];if(!z)throw Error(`Marketplace '${q}' not found. Available marketplaces: ${Object.keys(_).join(", ")}`);let Y=u18(z.installLocation);if(Y)throw Error(`Marketplace '${q}' is seed-managed (${Y}) and auto-update is always disabled for seed content. To update: ask your admin to update the seed.`);if(z.autoUpdate===K)return;_[q]={...z,autoUpdate:K},await _d(_);let $=UzY(q);if($){let A=v1($)?.extraKnownMarketplaces?.[q];if(A)I18(q,{source:A.source,autoUpdate:K},$)}N(`Set autoUpdate=${K} for marketplace: ${q}`)}var b18,czY=120000,r0;var Nw=y(()=>{CK();Ee();F4();o1();_8();m8();y8();XK();e7();E5();E8();U1();l8();UG8();Jy();kn6();pX();qd();oi();I17();aV();hP();mu();BZ();b18={GIT_TERMINAL_PROMPT:"0",GIT_ASKPASS:""};r0=_1(async(q)=>{let K=await r_(),_=K[q];if(!_)throw Error(`Marketplace '${q}' not found in configuration. Available marketplaces: ${Object.keys(K).join(", ")}`);if(SB(_.source)&&!sfK(_.source.path))throw Error(`Marketplace "${q}" has a relative source path (${_.source.path}) `+"in known_marketplaces.json — this is stale state from an older "+`Claude Code version. Run 'claude marketplace remove ${q}' and re-add it from the original project directory.`);try{return await x18(_.installLocation)}catch(Y){N(`Cache corrupted or missing for marketplace ${q}, re-fetching from source: ${d6(Y)}`,{level:"warn"})}let z;try{({marketplace:z}=await p17(_.source))}catch(Y){throw Error(`Failed to load marketplace "${q}" from source (${_.source.source}): ${d6(Y)}`)}return K[q].lastUpdated=new Date().toISOString(),await _d(K),z})});import{dirname as ZUw,join as LH6}from"path";function B18(){return LH6(GX(),"installed_plugins.json")}function szY(){return LH6(GX(),"installed_plugins_v2.json")}function tzY(){if(p18)return;let q=X8(),K=B18(),_=szY();try{try{q.renameSync(_,K),N("Renamed installed_plugins_v2.json to installed_plugins.json");let A=cX();z0K(A),p18=!0;return}catch(A){if(!_7(A))throw A}let z;try{z=q.readFileSync(K,{encoding:"utf-8"})}catch(A){if(!_7(A))throw A;p18=!0;return}let Y=r8(z);if((typeof Y?.version==="number"?Y.version:1)===1){let A=Tp6().parse(Y),O=U17(A);$j(K,g6(O,null,2),{encoding:"utf-8",flush:!0}),N(`Converted installed_plugins.json from V1 to V2 format (${Object.keys(A.plugins).length} plugins)`),z0K(O)}p18=!0}catch(z){let Y=d6(z);N(`Failed to migrate plugin files: ${Y}`,{level:"error"}),H6(x1(z)),p18=!0}}function z0K(q){let K=X8(),_=jh6();try{let z=new Set;for(let $ of Object.values(q.plugins))for(let A of $)z.add(A.installPath);let Y=K.readdirSync(_);for(let $ of Y){if(!$.isDirectory())continue;let A=$.name,O=LH6(_,A);if(K.readdirSync(O).some((H)=>{if(!H.isDirectory())return!1;let J=LH6(O,H.name);return K.readdirSync(J).some((X)=>X.isDirectory())}))continue;if(!z.has(O))K.rmSync(O,{recursive:!0,force:!0}),N(`Cleaned up legacy cache directory: ${A}`)}}catch(z){let Y=d6(z);N(`Failed to clean up legacy cache: ${Y}`,{level:"warn"})}}function F17(){let q=X8(),K=B18(),_;try{_=q.readFileSync(K,{encoding:"utf-8"})}catch($){if(_7($))return null;throw $}let z=r8(_);return{version:typeof z?.version==="number"?z.version:1,data:z}}function U17(q){let K={};for(let[_,z]of Object.entries(q.plugins)){let Y=Pp(_,z.version);K[_]=[{scope:"user",installPath:Y,version:z.version,installedAt:z.installedAt,lastUpdated:z.lastUpdated,gitCommitSha:z.gitCommitSha}]}return{version:2,plugins:K}}function cX(){if($d!==null)return $d;let q=B18();try{let K=F17();if(K){if(K.version===2){let Y=vp6().parse(K.data);return $d=Y,N(`Loaded ${Object.keys(Y.plugins).length} installed plugins from ${q}`),Y}let _=Tp6().parse(K.data),z=U17(_);return $d=z,N(`Loaded and converted ${Object.keys(_.plugins).length} plugins from V1 format`),z}return N("installed_plugins.json doesn't exist, returning empty V2 object"),$d={version:2,plugins:{}},$d}catch(K){let _=d6(K);return N(`Failed to load installed_plugins.json: ${_}. Starting with empty state.`,{level:"error"}),H6(x1(K)),$d={version:2,plugins:{}},$d}}function vB8(q){let K=X8(),_=B18();try{K.mkdirSync(GX());let z=g6(q,null,2);$j(_,z,{encoding:"utf-8",flush:!0}),$d=q,N(`Saved ${Object.keys(q.plugins).length} installed plugins to ${_}`)}catch(z){let Y=d6(z);throw H6(x1(z)),z}}function $0K(q,K,_){let z=Mp(),Y=z.plugins[q];if(!Y)return;if(z.plugins[q]=Y.filter(($)=>!($.scope===K&&$.projectPath===_)),z.plugins[q].length===0)delete z.plugins[q];vB8(z),N(`Removed installation for ${q} at scope ${K}`)}function g18(){if(g17===null)g17=cX();return g17}function Mp(){try{let q=F17();if(q){if(q.version===2)return vp6().parse(q.data);let K=Tp6().parse(q.data);return U17(K)}return{version:2,plugins:{}}}catch(q){let K=d6(q);return N(`Failed to load installed plugins from disk: ${K}`,{level:"error"}),{version:2,plugins:{}}}}function A0K(q,K,_,z,Y,$){let A=Mp(),O=A.plugins[q];if(!O){N(`Cannot update ${q} on disk: plugin not found in installed plugins`);return}let w=O.find((j)=>j.scope===K&&j.projectPath===_);if(w){if(w.installPath=z,w.version=Y,w.lastUpdated=new Date().toISOString(),$!==void 0)w.gitCommitSha=$;let j=B18();$j(j,g6(A,null,2),{encoding:"utf-8",flush:!0}),$d=null,N(`Updated ${q} on disk to version ${Y} at ${z}`)}else N(`Cannot update ${q} on disk: no installation for scope ${K}`)}async function Q17(){tzY();try{await l17()}catch(K){H6(K)}let q=g18();N(`Initialized versioned plugins system with ${Object.keys(q.plugins).length} plugins`)}function _0K(q){if(!q)return{orphanedPaths:[],removedPluginIds:[]};let K=Mp(),_=`@${q}`,z=new Set,Y=[];for(let $ of Object.keys(K.plugins)){if(!$.endsWith(_))continue;for(let A of K.plugins[$]??[])if(A.installPath)z.add(A.installPath);delete K.plugins[$],Y.push($),N(`Removed installed plugin for marketplace removal: ${$}`)}if(Y.length>0)vB8(K);return{orphanedPaths:Array.from(z),removedPluginIds:Y}}function d17(q){return q.scope==="user"||q.scope==="managed"||q.projectPath===r1()}function Zb(q){let _=cX().plugins[q];if(!_||_.length===0)return!1;if(!_.some(d17))return!1;return Z7().enabledPlugins?.[q]!==void 0}function Xh6(q){let _=cX().plugins[q];if(!_||_.length===0)return!1;if(!_.some((Y)=>Y.scope==="user"||Y.scope==="managed"))return!1;return Z7().enabledPlugins?.[q]!==void 0}function c17(q,K,_="user",z){let Y=Mp(),$={scope:_,installPath:K.installPath,version:K.version,installedAt:K.installedAt,lastUpdated:K.lastUpdated,gitCommitSha:K.gitCommitSha,...z&&{projectPath:z}},A=Y.plugins[q]||[],O=A.findIndex((j)=>j.scope===_&&j.projectPath===z),w=O>=0;if(w)A[O]=$;else A.push($);Y.plugins[q]=A,vB8(Y),N(`${w?"Updated":"Added"} installed plugin: ${q} (scope: ${_})`)}async function TB8(q){return await r$8(q)??void 0}function Y0K(q,K){let _=X8(),z=LH6(q,".claude-plugin","plugin.json");try{let Y=_.readFileSync(z,{encoding:"utf-8"});return r8(Y).version||"unknown"}catch{return N(`Could not read version from manifest for ${K}`),"unknown"}}async function l17(){let K=Z7().enabledPlugins||{};if(Object.keys(K).length===0)return;let _=F17(),z=_!==null;if(z&&_?.version===2&&_){let M=vp6().safeParse(_.data);if(M?.success){let X=M.data.plugins;if(Object.keys(K).filter((W)=>W.includes("@")).every((W)=>{let D=X[W];return D&&D.length>0})){N("All plugins already exist, skipping migration");return}}}N(z?"Syncing installed_plugins.json with enabledPlugins from all settings.json files":"Creating installed_plugins.json from settings.json files");let $=new Date().toISOString(),A=Z8(),O=new Map,w=["userSettings","projectSettings","localSettings"];for(let M of w){let P=v1(M)?.enabledPlugins||{};for(let W of Object.keys(P)){if(!W.includes("@"))continue;let D=WK4(M);O.set(W,{scope:D,projectPath:D==="user"?void 0:A})}}let j={};if(z)j={...cX().plugins};let H=0,J=0;for(let[M,X]of O){let P=j[M];if(P&&P.length>0){let W=P[0];if(W&&(W.scope!==X.scope||W.projectPath!==X.projectPath)){if(W.scope=X.scope,X.projectPath)W.projectPath=X.projectPath;else delete W.projectPath;W.lastUpdated=$,H++,N(`Updated ${M} scope to ${X.scope} (settings.json is source of truth)`)}}else{let{name:W,marketplace:D}=Z4(M);if(!W||!D)continue;try{N(`Looking up plugin ${M} in marketplace ${D}`);let f=await aG(M);if(!f){N(`Plugin ${M} not found in any marketplace, skipping`);continue}let{entry:G,marketplaceInstallLocation:Z}=f,T,v="unknown",V=void 0;if(typeof G.source==="string")T=LH6(Z,G.source),v=Y0K(T,M),V=await TB8(T);else{let E=jh6(),S=W.replace(/[^a-zA-Z0-9-_]/g,"-"),R=LH6(E,S),x;try{x=(await X8().readdir(R)).map((I)=>typeof I==="string"?I:I.name)}catch(I){if(!_7(I))throw I;N(`External plugin ${M} not in cache, skipping`);continue}if(T=R,x.includes(".claude-plugin"))v=Y0K(R,M);V=await TB8(R)}if(v==="unknown"&&G.version)v=G.version;if(v==="unknown"&&V)v=V.substring(0,12);j[M]=[{scope:X.scope,installPath:Pp(M,v),version:v,installedAt:$,lastUpdated:$,gitCommitSha:V,...X.projectPath&&{projectPath:X.projectPath}}],J++,N(`Added ${M} with scope ${X.scope}`)}catch(f){N(`Failed to add plugin ${M}: ${f}`)}}}if(!z||H>0||J>0)vB8({version:2,plugins:j}),N(`Sync completed: ${J} added, ${H} updated in installed_plugins.json`)}var p18=!1,$d=null,g17=null;var pX=y(()=>{_8();y8();e7();E8();l8();aV();BZ();v8();I7();Hl();U1();Nw();hP();bj()});function wR(){let q=v1("policySettings")?.enabledPlugins;if(!q)return null;let K=new Set;for(let[_,z]of Object.entries(q)){if(typeof z!=="boolean"||!_.includes("@"))continue;let Y=_.split("@")[0];if(Y)K.add(Y)}return K.size>0?K:null}var F18=y(()=>{U1()});import{createHash as ezY}from"crypto";async function Fa(q,K,_,z,Y,$){if(_?.version)return N(`Using manifest version for ${q}: ${_.version}`),_.version;if(Y)return N(`Using provided version for ${q}: ${Y}`),Y;if($){let A=$.substring(0,12);if(typeof K==="object"&&K.source==="git-subdir"){let O=K.path.replace(/\\/g,"/").replace(/^\.\//,"").replace(/\/+$/,""),w=ezY("sha256").update(O).digest("hex").substring(0,8),j=`${A}-${w}`;return N(`Using git-subdir SHA+path version for ${q}: ${j} (path=${O})`),j}return N(`Using pre-resolved git SHA for ${q}: ${A}`),A}if(z){let A=await qYY(z);if(A){let O=A.substring(0,12);return N(`Using git SHA for ${q}: ${O}`),O}}return N(`No version found for ${q}, using 'unknown'`),"unknown"}function qYY(q){return r$8(q)}var kB8=y(()=>{_8();Hl()});import{randomBytes as KYY}from"crypto";import{rename as n17,rm as _YY}from"fs/promises";import{dirname as i17,join as zYY,resolve as r17,sep as o17}from"path";function O0K(){return new Date().toISOString()}function VB8(q,K){let _=r17(q,K),z=r17(q)+o17;if(!_.startsWith(z)&&_!==r17(q))throw Error(`Path traversal detected: "${K}" would escape the base directory`);return _}async function U18(q,K,_="user",z,Y){let $=typeof K.source==="string"&&Y?Y:K.source,A=await Q18($,{manifest:K}),O=Y||A.path,w=A.gitCommitSha??await TB8(O),j=O0K(),H=await Fa(q,K.source,A.manifest,O,K.version,A.gitCommitSha),J=Pp(q,H),M=A.path;if(A.path!==J){await X8().mkdir(i17(J)),await _YY(J,{recursive:!0,force:!0});let X=A.path.endsWith(o17)?A.path:A.path+o17;if(J.startsWith(X)){let W=zYY(i17(A.path),`.claude-plugin-temp-${Date.now()}-${KYY(4).toString("hex")}`);await n17(A.path,W),await X8().mkdir(i17(J)),await n17(W,J)}else await n17(A.path,J);M=J}if(Sb()){let X=Ph6(q,H);await MB8(M,X),M=X}return c17(q,{version:H,installedAt:j,lastUpdated:j,installPath:M,gitCommitSha:w},_,z),M}function w0K(q,K="user",_){let z=O0K();c17(q.pluginId,{version:q.version||"unknown",installedAt:z,lastUpdated:z,installPath:q.installPath},K,_)}function a17(q){switch(q.reason){case"cycle":return`Dependency cycle: ${q.chain.join(" → ")}`;case"cross-marketplace":{let K=Z4(q.dependency).marketplace,_=K?`marketplace "${K}"`:"a different marketplace",z=K?` Add "${K}" to allowCrossMarketplaceDependenciesOn in the ROOT marketplace's marketplace.json (the marketplace of the plugin you're installing — only its allowlist applies; no transitive trust).`:"";return`Dependency "${q.dependency}" (required by ${q.requiredBy}) is in ${_}, which is not in the allowlist — cross-marketplace dependencies are blocked by default. Install it manually first.${z}`}case"not-found":{let{marketplace:K}=Z4(q.missing);return K?`Dependency "${q.missing}" (required by ${q.requiredBy}) not found. Is the "${K}" marketplace added?`:`Dependency "${q.missing}" (required by ${q.requiredBy}) not found in any configured marketplace`}}}async function s17({pluginId:q,entry:K,scope:_,marketplaceInstallLocation:z}){let Y=hF(_);if(zR(q))return{ok:!1,reason:"blocked-by-policy",pluginName:K.name};let $=new Map;if(Gp6(K.source)&&!z)return{ok:!1,reason:"local-source-no-location",pluginName:K.name};if(z)$.set(q,{entry:K,marketplaceInstallLocation:z});let A=Z4(q).marketplace,O=new Set((A?(await m18(A))?.allowCrossMarketplaceDependenciesOn:void 0)??[]),w=await DK4(q,async(X)=>{if($.has(X))return $.get(X).entry;if(X===q)return K;let P=await aG(X);if(P)$.set(X,P);return P?.entry??null},ZK4(Y),O);if(!w.ok)return{ok:!1,reason:"resolution-failed",resolution:w};for(let X of w.closure)if(X!==q&&zR(X))return{ok:!1,reason:"dependency-blocked-by-policy",pluginName:K.name,blockedDependency:X};let j={};for(let X of w.closure)j[X]=!0;let{error:H}=W7(Y,{enabledPlugins:{...v1(Y)?.enabledPlugins,...j}});if(H)return{ok:!1,reason:"settings-write-failed",message:H.message};let J=_!=="user"?Z8():void 0;for(let X of w.closure){let P=$.get(X);if(!P&&X===q){let f=(await aG(X))?.marketplaceInstallLocation;if(f)P={entry:K,marketplaceInstallLocation:f}}if(!P)continue;let W,{source:D}=P.entry;if(Gp6(D))W=VB8(P.marketplaceInstallLocation,D);await U18(X,P.entry,_,J,W)}Sz();let M=GK4(w.closure.filter((X)=>X!==q));return{ok:!0,closure:w.closure,depNote:M}}async function K56({pluginId:q,entry:K,marketplaceName:_,scope:z="user",trigger:Y="user"}){try{let A=(await aG(q))?.marketplaceInstallLocation,O=await s17({pluginId:q,entry:K,scope:z,marketplaceInstallLocation:A});if(!O.ok)switch(O.reason){case"local-source-no-location":return{success:!1,error:`Cannot install local plugin "${O.pluginName}" without marketplace install location`};case"settings-write-failed":return{success:!1,error:`Failed to update settings: ${O.message}`};case"resolution-failed":return{success:!1,error:a17(O.resolution)};case"blocked-by-policy":return{success:!1,error:`Plugin "${O.pluginName}" is blocked by your organization's policy and cannot be installed`};case"dependency-blocked-by-policy":return{success:!1,error:`Cannot install "${O.pluginName}": dependency "${O.blockedDependency}" is blocked by your organization's policy`}}return d("tengu_plugin_installed",{_PROTO_plugin_name:K.name,_PROTO_marketplace_name:_,plugin_id:Ru(_)?q:"third-party",trigger:Y,install_source:Y==="hint"?"ui-suggestion":"ui-discover",...Pb(K.name,_,wR()),...K.version&&{version:K.version}}),{success:!0,message:`✓ Installed ${K.name}${O.depNote}. Run /reload-plugins to activate.`}}catch($){let A=$ instanceof Error?$.message:String($);return H6(x1($)),{success:!1,error:`Failed to install: ${A}`}}}var _56=y(()=>{k8();I7();y8();e7();E8();U1();lE6();Jy();QG8();pX();F18();Nw();hP();bj();Sj6();kB8();BZ();Oh6()});import{copyFile as YYY,readdir as Wh6,readFile as d18,readlink as $YY,realpath as NB8,rename as P0K,rm as RH6,rmdir as AYY,stat as W0K,symlink as t17}from"fs/promises";import{basename as OYY,dirname as e17,join as __,relative as j0K,resolve as wYY,sep as H0K}from"path";function jh6(){return __(GX(),"cache")}function q77(q,K,_){let{name:z,marketplace:Y}=Z4(K),$=(Y||"unknown").replace(/[^a-zA-Z0-9\-_]/g,"-"),A=(z||K).replace(/[^a-zA-Z0-9\-_]/g,"-"),O=_.replace(/[^a-zA-Z0-9\-_.]/g,"-");return __(q,"cache",$,A,O)}function Pp(q,K){return q77(GX(),q,K)}function Ph6(q,K){return`${Pp(q,K)}.zip`}async function D0K(q,K){for(let _ of w76()){let z=q77(_,q,K);try{if((await Wh6(z)).length>0)return z}catch{}}return null}async function jYY(q){for(let K of w76()){let _=e17(q77(K,q,"_"));try{let z=await Wh6(_);if(z.length!==1)continue;let Y=__(_,z[0]);if((await Wh6(Y)).length>0)return Y}catch{}}return null}async function c18(q,K){await X8().mkdir(K);let _=await Wh6(q,{withFileTypes:!0});for(let z of _){let Y=__(q,z.name),$=__(K,z.name);if(z.isDirectory())await c18(Y,$);else if(z.isFile())await YYY(Y,$);else if(z.isSymbolicLink()){let A=await $YY(Y),O;try{O=await NB8(Y)}catch{await t17(A,$);continue}let w;try{w=await NB8(q)}catch{w=q}let j=w.endsWith(H0K)?w:w+H0K;if(O.startsWith(j)||O===w){let H=j0K(w,O),J=__(K,H),M=j0K(e17($),J);await t17(M,$)}else await t17(O,$)}}}async function yB8(q,K,_,z,Y){let $=Sb(),A=Pp(K,_),O=Ph6(K,_);if($){if(await u5(O))return N(`Plugin ${K} version ${_} already cached at ${O}`),O}else if(await u5(A)){if((await Wh6(A)).length>0)return N(`Plugin ${K} version ${_} already cached at ${A}`),A;N(`Removing empty cache directory for ${K} at ${A}`),await AYY(A)}let w=await D0K(K,_);if(w)return N(`Using seed cache for ${K}@${_} at ${w}`),w;if(await X8().mkdir(e17(A)),z&&typeof z.source==="string"&&Y){let J=VB8(Y,z.source);N(`Copying source directory ${z.source} for plugin ${K}`);try{await c18(J,A)}catch(M){if(_7(M)&&BH7(M)===J)throw Error(`Plugin source directory not found: ${J} (from entry.source: ${z.source})`);throw M}}else N(`Copying plugin ${K} to versioned cache (fallback to full copy)`),await c18(q,A);let j=__(A,".git");if(await RH6(j,{recursive:!0,force:!0}),(await Wh6(A)).length===0)throw Error(`Failed to copy plugin ${K} to versioned cache: destination is empty after copy`);if($)return await MB8(A,O),N(`Successfully cached plugin ${K} as ZIP at ${O}`),O;return N(`Successfully cached plugin ${K} at ${A}`),A}function f0K(q){try{let K=new URL(q);if(!["https:","http:","file:"].includes(K.protocol)){if(!/^git@[a-zA-Z0-9.-]+:/.test(q))throw Error(`Invalid git URL protocol: ${K.protocol}. Only HTTPS, HTTP, file:// and SSH (git@) URLs are supported.`)}return q}catch{if(/^git@[a-zA-Z0-9.-]+:/.test(q))return q;throw Error(`Invalid git URL: ${q}`)}}async function HYY(q,K,_={}){let z=__(GX(),"npm-cache");await X8().mkdir(z);let Y=_.version?`${q}@${_.version}`:q,$=__(z,"node_modules",q);if(!await u5($)){N(`Installing npm package ${Y} to cache`);let O=["install",Y,"--prefix",z];if(_.registry)O.push("--registry",_.registry);let w=await a8("npm",O,{useCwd:!1});if(w.code!==0)throw Error(`Failed to install npm package: ${w.stderr}`)}await c18($,K),N(`Copied npm package ${q} from cache to ${K}`)}async function JYY(q,K,_,z){let Y=["clone","--depth","1","--recurse-submodules","--shallow-submodules"];if(_)Y.push("--branch",_);if(z)Y.push("--no-checkout");Y.push(q,K);let $=performance.now(),A=await a8(L7(),Y);if(A.code!==0)throw KD("plugin_clone",q,"failure",performance.now()-$,zC(A.stderr)),Error(`Failed to clone repository: ${A.stderr}`);if(z){if((await S7(L7(),["fetch","--depth","1","origin",z],{cwd:K})).code!==0){N(`Shallow fetch of SHA ${z} failed, falling back to unshallow fetch`);let j=await S7(L7(),["fetch","--unshallow"],{cwd:K});if(j.code!==0)throw KD("plugin_clone",q,"failure",performance.now()-$,zC(j.stderr)),Error(`Failed to fetch commit ${z}: ${j.stderr}`)}let w=await S7(L7(),["checkout",z],{cwd:K});if(w.code!==0)throw KD("plugin_clone",q,"failure",performance.now()-$,zC(w.stderr)),Error(`Failed to checkout commit ${z}: ${w.stderr}`)}KD("plugin_clone",q,"success",performance.now()-$)}async function Z0K(q,K,_,z){let Y=f0K(q);await JYY(Y,K,_,z);let $=_?` (ref: ${_})`:"";N(`Cloned repository from ${Y}${$} to ${K}`)}async function MYY(q,K,_,z){if(!/^[a-zA-Z0-9-_.]+\/[a-zA-Z0-9-_.]+$/.test(q))throw Error(`Invalid GitHub repository format: ${q}. Expected format: owner/repo`);let Y=i6(process.env.CLAUDE_CODE_REMOTE)?`https://github.com/${q}.git`:`git@github.com:${q}.git`;return Z0K(Y,K,_,z)}function XYY(q){if(/^[a-zA-Z0-9-_.]+\/[a-zA-Z0-9-_.]+$/.test(q))return i6(process.env.CLAUDE_CODE_REMOTE)?`https://github.com/${q}.git`:`git@github.com:${q}.git`;return f0K(q)}async function PYY(q,K,_,z,Y){if(!await mA6())throw Error("git-subdir plugin source requires git to be installed and on PATH. Install git (version 2.25 or later for sparse-checkout cone mode) and try again.");let $=XYY(q),A=`${K}.clone`,O=["clone","--depth","1","--filter=tree:0","--no-checkout"];if(z)O.push("--branch",z);O.push($,A);let w=await a8(L7(),O);if(w.code!==0)throw Error(`Failed to clone repository for git-subdir source: ${w.stderr}`);try{let j=await S7(L7(),["sparse-checkout","set","--cone","--",_],{cwd:A});if(j.code!==0)throw Error(`git sparse-checkout set failed (git >= 2.25 required for cone mode): ${j.stderr}`);let H;if(Y){if((await S7(L7(),["fetch","--depth","1","origin",Y],{cwd:A})).code!==0){N(`Shallow fetch of SHA ${Y} failed for git-subdir, falling back to unshallow fetch`);let D=await S7(L7(),["fetch","--unshallow"],{cwd:A});if(D.code!==0)throw Error(`Failed to fetch commit ${Y}: ${D.stderr}`)}let W=await S7(L7(),["checkout",Y],{cwd:A});if(W.code!==0)throw Error(`Failed to checkout commit ${Y}: ${W.stderr}`);H=Y}else{let[P,W]=await Promise.all([S7(L7(),["checkout","HEAD"],{cwd:A}),S7(L7(),["rev-parse","HEAD"],{cwd:A})]);if(P.code!==0)throw Error(`git checkout after sparse-checkout failed: ${P.stderr}`);if(W.code===0)H=W.stdout.trim()}let J=VB8(A,_);try{await P0K(J,K)}catch(P){if(_7(P))throw Error(`Subdirectory '${_}' not found in repository ${$}${z?` (ref: ${z})`:""}. Check that the path is correct and exists at the specified ref/sha.`);throw P}let M=z?` ref=${z}`:"",X=H?` sha=${H}`:"";return N(`Extracted subdir ${_} from ${$}${M}${X} to ${K}`),H}finally{await RH6(A,{recursive:!0,force:!0})}}async function WYY(q,K){if(!await u5(q))throw Error(`Source path does not exist: ${q}`);await c18(q,K);let _=__(K,".git");await RH6(_,{recursive:!0,force:!0})}function DYY(q){let K=Date.now(),_=Math.random().toString(36).substring(2,8),z;if(typeof q==="string")z="local";else switch(q.source){case"npm":z="npm";break;case"pip":z="pip";break;case"github":z="github";break;case"url":z="git";break;case"git-subdir":z="subdir";break;default:z="unknown"}return`temp_${z}_${K}_${_}`}async function Q18(q,K){let _=jh6();await X8().mkdir(_);let z=DYY(q),Y=__(_,z),$=!1,A;try{if(N(`Caching plugin from source: ${g6(q)} to temporary path ${Y}`),$=!0,typeof q==="string")await WYY(q,Y);else switch(q.source){case"npm":await HYY(q.package,Y,{registry:q.registry,version:q.version});break;case"github":await MYY(q.repo,Y,q.ref,q.sha);break;case"url":await Z0K(q.url,Y,q.ref,q.sha);break;case"git-subdir":A=await PYY(q.url,Y,q.path,q.ref,q.sha);break;case"pip":throw Error("Python package plugins are not yet supported");default:throw Error("Unsupported plugin source type")}}catch(M){if($&&await u5(Y)){N(`Cleaning up failed installation at ${Y}`);try{await RH6(Y,{recursive:!0,force:!0})}catch(X){N(`Failed to clean up installation: ${X}`,{level:"error"})}}throw M}let O=__(Y,".claude-plugin","plugin.json"),w=__(Y,"plugin.json"),j;if(await u5(O))try{let M=await d18(O,{encoding:"utf-8"}),X=r8(M),P=Z_6().safeParse(X);if(P.success)j=P.data;else{let W=P.error.issues.map((D)=>`${D.path.join(".")}: ${D.message}`).join(", ");throw N(`Invalid manifest at ${O}: ${W}`,{level:"error"}),Error(`Plugin has an invalid manifest file at ${O}. Validation errors: ${W}`)}}catch(M){if(M instanceof Error&&M.message.includes("invalid manifest file"))throw M;let X=d6(M);throw N(`Failed to parse manifest at ${O}: ${X}`,{level:"error"}),Error(`Plugin has a corrupt manifest file at ${O}. JSON parse error: ${X}`)}else if(await u5(w))try{let M=await d18(w,{encoding:"utf-8"}),X=r8(M),P=Z_6().safeParse(X);if(P.success)j=P.data;else{let W=P.error.issues.map((D)=>`${D.path.join(".")}: ${D.message}`).join(", ");throw N(`Invalid legacy manifest at ${w}: ${W}`,{level:"error"}),Error(`Plugin has an invalid manifest file at ${w}. Validation errors: ${W}`)}}catch(M){if(M instanceof Error&&M.message.includes("invalid manifest file"))throw M;let X=d6(M);throw N(`Failed to parse legacy manifest at ${w}: ${X}`,{level:"error"}),Error(`Plugin has a corrupt manifest file at ${w}. JSON parse error: ${X}`)}else j=K?.manifest||{name:z,description:`Plugin cached from ${typeof q==="string"?q:q.source}`};let H=j.name.replace(/[^a-zA-Z0-9-_]/g,"-"),J=__(_,H);if(await u5(J))N(`Removing old cached version at ${J}`),await RH6(J,{recursive:!0,force:!0});return await P0K(Y,J),N(`Successfully cached plugin ${j.name} to ${J}`),{path:J,manifest:j,...A&&{gitCommitSha:A}}}async function EB8(q,K,_){if(!await u5(q))return{name:K,description:`Plugin from ${_}`};try{let z=await d18(q,{encoding:"utf-8"}),Y=r8(z),$=Z_6().safeParse(Y);if($.success)return $.data;let A=$.error.issues.map((O)=>O.path.length>0?`${O.path.join(".")}: ${O.message}`:O.message).join(", ");throw N(`Plugin ${K} has an invalid manifest file at ${q}. Validation errors: ${A}`,{level:"error"}),Error(`Plugin ${K} has an invalid manifest file at ${q}.
4723
4724Validation errors: ${A}`)}catch(z){if(z instanceof Error&&z.message.includes("invalid manifest file"))throw z;let Y=d6(z);throw N(`Plugin ${K} has a corrupt manifest file at ${q}. Parse error: ${Y}`,{level:"error"}),Error(`Plugin ${K} has a corrupt manifest file at ${q}.
4725
4726JSON parse error: ${Y}`)}}async function J0K(q,K){if(!await u5(q))throw Error(`Hooks file not found at ${q} for plugin ${K}. If the manifest declares hooks, the file must exist.`);let _=await d18(q,{encoding:"utf-8"}),z=r8(_);return ZA8().parse(z).hooks}async function z56(q,K,_,z,Y,$,A,O){let w=await Promise.all(q.map(async(H)=>{let J=__(K,H);return{relPath:H,fullPath:J,exists:await u5(J)}})),j=[];for(let{relPath:H,fullPath:J,exists:M}of w)if(M)j.push(J);else N(`${$} path ${H} ${A} not found at ${J} for ${_}`,{level:"warn"}),H6(Error(`Plugin component file not found: ${J} for ${_}`)),O.push({type:"path-not-found",source:z,plugin:_,path:J,component:Y});return j}async function G0K(q,K,_,z,Y=!0){let $=[],A=__(q,".claude-plugin","plugin.json"),O=await EB8(A,z,K),w={name:O.name,manifest:O,path:q,source:K,repository:K,enabled:_},[j,H,J,M]=await Promise.all([!O.commands?u5(__(q,"commands")):!1,!O.agents?u5(__(q,"agents")):!1,!O.skills?u5(__(q,"skills")):!1,!O.outputStyles?u5(__(q,"output-styles")):!1]),X=__(q,"commands");if(j)w.commandsPath=X;if(O.commands){let v=Object.values(O.commands)[0];if(typeof O.commands==="object"&&!Array.isArray(O.commands)&&v&&typeof v==="object"&&(("source"in v)||("content"in v))){let V={},E=[],S=Object.entries(O.commands),R=await Promise.all(S.map(async([x,I])=>{if(!I||typeof I!=="object")return{commandName:x,metadata:I,kind:"skip"};if(I.source){let B=__(q,I.source);return{commandName:x,metadata:I,kind:"source",fullPath:B,exists:await u5(B)}}if(I.content)return{commandName:x,metadata:I,kind:"content"};return{commandName:x,metadata:I,kind:"skip"}}));for(let x of R){if(x.kind==="skip")continue;if(x.kind==="content"){V[x.commandName]=x.metadata;continue}if(x.exists)E.push(x.fullPath),V[x.commandName]=x.metadata;else N(`Command ${x.commandName} path ${x.metadata.source} specified in manifest but not found at ${x.fullPath} for ${O.name}`,{level:"warn"}),H6(Error(`Plugin component file not found: ${x.fullPath} for ${O.name}`)),$.push({type:"path-not-found",source:K,plugin:O.name,path:x.fullPath,component:"commands"})}if(E.length>0)w.commandsPaths=E;if(Object.keys(V).length>0)w.commandsMetadata=V}else{let V=Array.isArray(O.commands)?O.commands:[O.commands],E=await Promise.all(V.map(async(R)=>{if(typeof R!=="string")return{cmdPath:R,kind:"invalid"};let x=__(q,R);return{cmdPath:R,kind:"path",fullPath:x,exists:await u5(x)}})),S=[];for(let R of E){if(R.kind==="invalid"){N(`Unexpected command format in manifest for ${O.name}`,{level:"error"});continue}if(R.exists)S.push(R.fullPath);else N(`Command path ${R.cmdPath} specified in manifest but not found at ${R.fullPath} for ${O.name}`,{level:"warn"}),H6(Error(`Plugin component file not found: ${R.fullPath} for ${O.name}`)),$.push({type:"path-not-found",source:K,plugin:O.name,path:R.fullPath,component:"commands"})}if(S.length>0)w.commandsPaths=S}}let P=__(q,"agents");if(H)w.agentsPath=P;if(O.agents){let v=Array.isArray(O.agents)?O.agents:[O.agents],V=await z56(v,q,O.name,K,"agents","Agent","specified in manifest but",$);if(V.length>0)w.agentsPaths=V}let W=__(q,"skills");if(J)w.skillsPath=W;if(O.skills){let v=Array.isArray(O.skills)?O.skills:[O.skills],V=await z56(v,q,O.name,K,"skills","Skill","specified in manifest but",$);if(V.length>0)w.skillsPaths=V}let D=__(q,"output-styles");if(M)w.outputStylesPath=D;if(O.outputStyles){let v=Array.isArray(O.outputStyles)?O.outputStyles:[O.outputStyles],V=await z56(v,q,O.name,K,"output-styles","Output style","specified in manifest but",$);if(V.length>0)w.outputStylesPaths=V}let f,G=new Set,Z=__(q,"hooks","hooks.json");if(await u5(Z))try{f=await J0K(Z,O.name);try{G.add(await NB8(Z))}catch{G.add(Z)}N(`Loaded hooks from standard location for plugin ${O.name}: ${Z}`)}catch(v){let V=d6(v);N(`Failed to load hooks for ${O.name}: ${V}`,{level:"error"}),H6(x1(v)),$.push({type:"hook-load-failed",source:K,plugin:O.name,hookPath:Z,reason:V})}if(O.hooks){let v=Array.isArray(O.hooks)?O.hooks:[O.hooks];for(let V of v)if(typeof V==="string"){let E=__(q,V);if(!await u5(E)){N(`Hooks file ${V} specified in manifest but not found at ${E} for ${O.name}`,{level:"error"}),H6(Error(`Plugin component file not found: ${E} for ${O.name}`)),$.push({type:"path-not-found",source:K,plugin:O.name,path:E,component:"hooks"});continue}let S;try{S=await NB8(E)}catch{S=E}if(G.has(S)){if(N(`Skipping duplicate hooks file for plugin ${O.name}: ${V} (resolves to already-loaded file: ${S})`),Y){let R=`Duplicate hooks file detected: ${V} resolves to already-loaded file ${S}. The standard hooks/hooks.json is loaded automatically, so manifest.hooks should only reference additional hook files.`;H6(Error(R)),$.push({type:"hook-load-failed",source:K,plugin:O.name,hookPath:E,reason:R})}continue}try{let R=await J0K(E,O.name);try{f=X0K(f,R),G.add(S),N(`Loaded and merged hooks from manifest for plugin ${O.name}: ${V}`)}catch(x){let I=d6(x);N(`Failed to merge hooks from ${V} for ${O.name}: ${I}`,{level:"error"}),H6(x1(x)),$.push({type:"hook-load-failed",source:K,plugin:O.name,hookPath:E,reason:`Failed to merge: ${I}`})}}catch(R){let x=d6(R);N(`Failed to load hooks from ${V} for ${O.name}: ${x}`,{level:"error"}),H6(x1(R)),$.push({type:"hook-load-failed",source:K,plugin:O.name,hookPath:E,reason:x})}}else if(typeof V==="object")f=X0K(f,V)}if(f)w.hooksConfig=f;let T=await ZYY(q,O);if(T)w.settings=T;return{plugin:w,errors:$}}function M0K(q){let K=fYY().safeParse(q);if(!K.success)return;let _=K.data;if(Object.keys(_).length===0)return;return _}async function ZYY(q,K){let _=__(q,"settings.json");try{let z=await d18(_,{encoding:"utf-8"}),Y=r8(z);if(yYY(Y)){let $=M0K(Y);if($)return N(`Loaded settings from settings.json for plugin ${K.name}`),$}}catch(z){if(!e3(z))N(`Failed to parse settings.json for plugin ${K.name}: ${z}`,{level:"warn"})}if(K.settings){let z=M0K(K.settings);if(z)return N(`Loaded settings from manifest for plugin ${K.name}`),z}return}function X0K(q,K){if(!q)return K;let _={...q};for(let[z,Y]of Object.entries(K))if(!_[z])_[z]=Y;else _[z]=[..._[z]||[],...Y];return _}async function T0K({cacheOnly:q}){let K=Z7(),_={...uA6(),...K.enabledPlugins||{}},z=[],Y=[],$=Object.entries(_).filter(([P,W])=>{if(!AD6().safeParse(P).success||W===void 0)return!1;let{marketplace:f}=Z4(P);return f!==Tn6}),A=await eK6(),O=aK6(),w=C17(),j=O!==null||w!==null&&w.length>0,H=new Set($.map(([P])=>Z4(P).marketplace).filter((P)=>!!P)),J=new Map;await Promise.all([...H].map(async(P)=>{J.set(P,await m18(P))}));let M=g18(),X=await Promise.allSettled($.map(async([P,W])=>{let{name:D,marketplace:f}=Z4(P),G=A[f];if(!G&&j)return Y.push({type:"marketplace-blocked-by-policy",source:P,plugin:D,marketplace:f,blockedByBlocklist:O===null,allowedSources:(O??[]).map((V)=>yH6(V))}),null;if(G&&!NH6(G.source)){let V=S18(G.source),E=aK6()||[];return Y.push({type:"marketplace-blocked-by-policy",source:P,plugin:D,marketplace:f,blockedByBlocklist:V,allowedSources:V?[]:E.map((S)=>yH6(S))}),null}let Z=null,T=J.get(f);if(T&&G){let V=T.plugins.find((E)=>E.name===D);if(V)Z={entry:V,marketplaceInstallLocation:G.installLocation}}else Z=await B17(P);if(!Z)return Y.push({type:"plugin-not-found",source:P,pluginId:D,marketplace:f}),null;let v=M.plugins[P]?.[0];return q?GYY(Z.entry,Z.marketplaceInstallLocation,P,W===!0,Y,v?.installPath):TYY(Z.entry,Z.marketplaceInstallLocation,P,W===!0,Y,v?.version)}));for(let[P,W]of X.entries())if(W.status==="fulfilled"&&W.value)z.push(W.value);else if(W.status==="rejected"){let D=x1(W.reason);H6(D);let f=$[P][0];Y.push({type:"generic-error",source:f,plugin:f.split("@")[0],error:D.message})}return{plugins:z,errors:Y}}async function GYY(q,K,_,z,Y,$){let A;if(typeof q.source==="string"){let O;try{O=(await W0K(K)).isDirectory()?K:__(K,"..")}catch{return Y.push({type:"plugin-cache-miss",source:_,plugin:q.name,installPath:K}),null}A=__(O,q.source)}else{if(!$||!await u5($))return Y.push({type:"plugin-cache-miss",source:_,plugin:q.name,installPath:$??"(not recorded)"}),null;A=$}if(Sb()&&A.endsWith(".zip")){let O=await E17(),w=__(O,_.replace(/[^a-zA-Z0-9@\-_]/g,"-"));try{await L17(A,w),A=w}catch(j){return N(`Failed to extract plugin ZIP ${A}: ${j}`,{level:"error"}),Y.push({type:"plugin-cache-miss",source:_,plugin:q.name,installPath:A}),null}}return v0K(q,_,z,Y,A)}async function TYY(q,K,_,z,Y,$){N(`Loading plugin ${q.name} from source: ${g6(q.source)}`);let A;if(typeof q.source==="string"){let O=(await W0K(K)).isDirectory()?K:__(K,".."),w=__(O,q.source);if(!await u5(w)){let j=Error(`Plugin path not found: ${w}`);return N(`Plugin path not found: ${w}`,{level:"error"}),H6(j),Y.push({type:"generic-error",source:_,error:`Plugin directory not found at path: ${w}. Check that the marketplace entry has the correct path.`}),null}try{let j=__(w,".claude-plugin","plugin.json"),H;try{H=await EB8(j,q.name,q.source)}catch{}let J=await Fa(_,q.source,H,O,q.version);A=await yB8(w,_,J,q,O),N(`Resolved local plugin ${q.name} to versioned cache: ${A}`)}catch(j){let H=d6(j);N(`Failed to copy plugin ${q.name} to versioned cache: ${H}. Using marketplace path.`,{level:"warn"}),A=w}}else try{let O=await Fa(_,q.source,void 0,void 0,$??q.version,"sha"in q.source?q.source.sha:void 0),w=Pp(_,O),j=Ph6(_,O);if(Sb()&&await u5(j))N(`Using versioned cached plugin ZIP ${q.name} from ${j}`),A=j;else if(await u5(w))N(`Using versioned cached plugin ${q.name} from ${w}`),A=w;else{let H=await D0K(_,O)??(O==="unknown"?await jYY(_):null);if(H)A=H,N(`Using seed cache for external plugin ${q.name} at ${H}`);else{let J=await Q18(q.source,{manifest:{name:q.name}}),M=O!=="unknown"?O:await Fa(_,q.source,J.manifest,J.path,$??q.version,J.gitCommitSha);if(A=await yB8(J.path,_,M,q,void 0),J.path!==A)await RH6(J.path,{recursive:!0,force:!0})}}}catch(O){let w=d6(O);return N(`Failed to cache plugin ${q.name}: ${w}`,{level:"error"}),H6(x1(O)),Y.push({type:"generic-error",source:_,error:`Failed to download/cache plugin ${q.name}: ${w}`}),null}if(Sb()&&A.endsWith(".zip")){let O=await E17(),w=__(O,_.replace(/[^a-zA-Z0-9@\-_]/g,"-"));try{await L17(A,w),N(`Extracted plugin ZIP to session dir: ${w}`),A=w}catch(j){throw N(`Failed to extract plugin ZIP ${A}, deleting corrupt file: ${j}`),await RH6(A,{force:!0}).catch(()=>{}),j}}return v0K(q,_,z,Y,A)}async function v0K(q,K,_,z,Y){let $=[],A=__(Y,".claude-plugin","plugin.json"),O=await u5(A),{plugin:w,errors:j}=await G0K(Y,K,_,q.name,q.strict??!0);if($.push(...j),typeof q.source==="object"&&"sha"in q.source&&q.source.sha)w.sha=q.source.sha;if(!O){if(w.manifest={...q,id:void 0,source:void 0,strict:void 0},w.name=w.manifest.name,q.commands){let H=Object.values(q.commands)[0];if(typeof q.commands==="object"&&!Array.isArray(q.commands)&&H&&typeof H==="object"&&(("source"in H)||("content"in H))){let J={},M=[],X=Object.entries(q.commands),P=await Promise.all(X.map(async([W,D])=>{if(!D||typeof D!=="object"||!D.source)return{commandName:W,metadata:D,skip:!0};let f=__(Y,D.source);return{commandName:W,metadata:D,skip:!1,fullPath:f,exists:await u5(f)}}));for(let W of P){if(W.skip)continue;if(W.exists)M.push(W.fullPath),J[W.commandName]=W.metadata;else N(`Command ${W.commandName} path ${W.metadata.source} from marketplace entry not found at ${W.fullPath} for ${q.name}`,{level:"warn"}),H6(Error(`Plugin component file not found: ${W.fullPath} for ${q.name}`)),$.push({type:"path-not-found",source:K,plugin:q.name,path:W.fullPath,component:"commands"})}if(M.length>0)w.commandsPaths=M,w.commandsMetadata=J}else{let J=Array.isArray(q.commands)?q.commands:[q.commands],M=await Promise.all(J.map(async(P)=>{if(typeof P!=="string")return{cmdPath:P,kind:"invalid"};let W=__(Y,P);return{cmdPath:P,kind:"path",fullPath:W,exists:await u5(W)}})),X=[];for(let P of M){if(P.kind==="invalid"){N(`Unexpected command format in marketplace entry for ${q.name}`,{level:"error"});continue}if(P.exists)X.push(P.fullPath);else N(`Command path ${P.cmdPath} from marketplace entry not found at ${P.fullPath} for ${q.name}`,{level:"warn"}),H6(Error(`Plugin component file not found: ${P.fullPath} for ${q.name}`)),$.push({type:"path-not-found",source:K,plugin:q.name,path:P.fullPath,component:"commands"})}if(X.length>0)w.commandsPaths=X}}if(q.agents){let H=Array.isArray(q.agents)?q.agents:[q.agents],J=await z56(H,Y,q.name,K,"agents","Agent","from marketplace entry",$);if(J.length>0)w.agentsPaths=J}if(q.skills){N(`Processing ${Array.isArray(q.skills)?q.skills.length:1} skill paths for plugin ${q.name}`);let H=Array.isArray(q.skills)?q.skills:[q.skills],J=await Promise.all(H.map(async(X)=>{let P=__(Y,X);return{skillPath:X,fullPath:P,exists:await u5(P)}})),M=[];for(let{skillPath:X,fullPath:P,exists:W}of J)if(N(`Checking skill path: ${X} -> ${P} (exists: ${W})`),W)M.push(P);else N(`Skill path ${X} from marketplace entry not found at ${P} for ${q.name}`,{level:"warn"}),H6(Error(`Plugin component file not found: ${P} for ${q.name}`)),$.push({type:"path-not-found",source:K,plugin:q.name,path:P,component:"skills"});if(N(`Found ${M.length} valid skill paths for plugin ${q.name}, setting skillsPaths`),M.length>0)w.skillsPaths=M}else N(`Plugin ${q.name} has no entry.skills defined`);if(q.outputStyles){let H=Array.isArray(q.outputStyles)?q.outputStyles:[q.outputStyles],J=await z56(H,Y,q.name,K,"output-styles","Output style","from marketplace entry",$);if(J.length>0)w.outputStylesPaths=J}if(q.hooks)w.hooksConfig=q.hooks}else if(!q.strict&&O&&(q.commands||q.agents||q.skills||q.hooks||q.outputStyles)){let H=Error(`Plugin ${q.name} has both plugin.json and marketplace manifest entries for commands/agents/skills/hooks/outputStyles. This is a conflict.`);return N(`Plugin ${q.name} has both plugin.json and marketplace manifest entries for commands/agents/skills/hooks/outputStyles. This is a conflict.`,{level:"error"}),H6(H),z.push({type:"generic-error",source:K,error:`Plugin ${q.name} has conflicting manifests: both plugin.json and marketplace entry specify components. Set strict: true in marketplace entry or remove component specs from one location.`}),null}else if(O){if(q.commands){let H=Object.values(q.commands)[0];if(typeof q.commands==="object"&&!Array.isArray(q.commands)&&H&&typeof H==="object"&&(("source"in H)||("content"in H))){let J={...w.commandsMetadata||{}},M=[],X=Object.entries(q.commands),P=await Promise.all(X.map(async([W,D])=>{if(!D||typeof D!=="object"||!D.source)return{commandName:W,metadata:D,skip:!0};let f=__(Y,D.source);return{commandName:W,metadata:D,skip:!1,fullPath:f,exists:await u5(f)}}));for(let W of P){if(W.skip)continue;if(W.exists)M.push(W.fullPath),J[W.commandName]=W.metadata;else N(`Command ${W.commandName} path ${W.metadata.source} from marketplace entry not found at ${W.fullPath} for ${q.name}`,{level:"warn"}),H6(Error(`Plugin component file not found: ${W.fullPath} for ${q.name}`)),$.push({type:"path-not-found",source:K,plugin:q.name,path:W.fullPath,component:"commands"})}if(M.length>0)w.commandsPaths=[...w.commandsPaths||[],...M],w.commandsMetadata=J}else{let J=Array.isArray(q.commands)?q.commands:[q.commands],M=await Promise.all(J.map(async(P)=>{if(typeof P!=="string")return{cmdPath:P,kind:"invalid"};let W=__(Y,P);return{cmdPath:P,kind:"path",fullPath:W,exists:await u5(W)}})),X=[];for(let P of M){if(P.kind==="invalid"){N(`Unexpected command format in marketplace entry for ${q.name}`,{level:"error"});continue}if(P.exists)X.push(P.fullPath);else N(`Command path ${P.cmdPath} from marketplace entry not found at ${P.fullPath} for ${q.name}`,{level:"warn"}),H6(Error(`Plugin component file not found: ${P.fullPath} for ${q.name}`)),$.push({type:"path-not-found",source:K,plugin:q.name,path:P.fullPath,component:"commands"})}if(X.length>0)w.commandsPaths=[...w.commandsPaths||[],...X]}}if(q.agents){let H=Array.isArray(q.agents)?q.agents:[q.agents],J=await z56(H,Y,q.name,K,"agents","Agent","from marketplace entry",$);if(J.length>0)w.agentsPaths=[...w.agentsPaths||[],...J]}if(q.skills){let H=Array.isArray(q.skills)?q.skills:[q.skills],J=await z56(H,Y,q.name,K,"skills","Skill","from marketplace entry",$);if(J.length>0)w.skillsPaths=[...w.skillsPaths||[],...J]}if(q.outputStyles){let H=Array.isArray(q.outputStyles)?q.outputStyles:[q.outputStyles],J=await z56(H,Y,q.name,K,"output-styles","Output style","from marketplace entry",$);if(J.length>0)w.outputStylesPaths=[...w.outputStylesPaths||[],...J]}if(q.hooks)w.hooksConfig={...w.hooksConfig||{},...q.hooks}}return z.push(...$),w}async function vYY(q){if(q.length===0)return{plugins:[],errors:[]};let K=[],_=[];for(let[z,Y]of q.entries())try{let $=wYY(Y);if(!await u5($)){N(`Plugin path does not exist: ${$}, skipping`,{level:"warn"}),_.push({type:"path-not-found",source:`inline[${z}]`,path:$,component:"commands"});continue}let A=OYY($),{plugin:O,errors:w}=await G0K($,`${A}@inline`,!0,A);O.source=`${O.name}@inline`,O.repository=`${O.name}@inline`,K.push(O),_.push(...w),N(`Loaded inline plugin from path: ${O.name}`)}catch($){let A=d6($);N(`Failed to load session plugin from ${Y}: ${A}`,{level:"warn"}),_.push({type:"generic-error",source:`inline[${z}]`,error:`Failed to load plugin: ${A}`})}if(K.length>0)N(`Loaded ${K.length} session-only plugins from --plugin-dir`);return{plugins:K,errors:_}}function kYY(q){let K=[],_=q.managedNames,z=q.session.filter((A)=>{if(_?.has(A.name))return N(`Plugin "${A.name}" from --plugin-dir is blocked by managed settings`,{level:"warn"}),K.push({type:"generic-error",source:A.source,plugin:A.name,error:`--plugin-dir copy of "${A.name}" ignored: plugin is locked by managed settings`}),!1;return!0}),Y=new Set(z.map((A)=>A.name)),$=q.marketplace.filter((A)=>{if(Y.has(A.name))return N(`Plugin "${A.name}" from --plugin-dir overrides installed version`),!1;return!0});return{plugins:[...z,...$,...q.builtin],errors:K}}async function k0K(q){let K=ep(),[_,z]=await Promise.all([q(),K.length>0?vYY(K):Promise.resolve({plugins:[],errors:[]})]),Y=Nh1(),{plugins:$,errors:A}=kYY({session:z.plugins,marketplace:_.plugins,builtin:[...Y.enabled,...Y.disabled],managedNames:wR()}),O=[..._.errors,...z.errors,...A],{demoted:w,errors:j}=fK4($);for(let J of $)if(w.has(J.source))J.enabled=!1;O.push(...j);let H=$.filter((J)=>J.enabled);return N(`Found ${$.length} plugins (${H.length} enabled, ${$.length-H.length} disabled)`),NYY(H),{enabled:H,disabled:$.filter((J)=>!J.enabled),errors:O}}function Yk(q){if(q)N(`clearPluginCache: invalidating loadAllPlugins cache (${q})`);if(LM.cache?.clear?.(),ZJ.cache?.clear?.(),i58()!==void 0)DW();Gj7()}function VYY(q){let K;for(let _ of q){if(!_.settings)continue;if(!K)K={};for(let[z,Y]of Object.entries(_.settings)){if(z in K)N(`Plugin "${_.name}" overrides setting "${z}" (previously set by another plugin)`);K[z]=Y}}return K}function NYY(q){let K=VYY(q);if(Zj7(K),K&&Object.keys(K).length>0)DW(),N(`Cached plugin settings with keys: ${Object.keys(K).join(", ")}`)}function yYY(q){return typeof q==="object"&&q!==null&&!Array.isArray(q)}var fYY,LM,ZJ;var bj=y(()=>{F4();v8();vn6();_8();m8();y8();XK();bK();e7();E5();E8();U1();Zc();vh();l8();UG8();QG8();kn6();dG8();pX();F18();qd();Nw();aV();hP();_56();kB8();BZ();Oh6();fYY=B6(()=>EW().pick({agent:!0}).strip());LM=_1(async()=>{let q=await k0K(()=>T0K({cacheOnly:!1}));return ZJ.cache?.set(void 0,Promise.resolve(q)),q}),ZJ=_1(async()=>{if(i6(process.env.CLAUDE_CODE_SYNC_PLUGIN_INSTALL))return LM();return k0K(()=>T0K({cacheOnly:!0}))})});import{basename as EYY}from"path";async function V0K(q,K,_){let z=[];return await Vk6(q,async(Y)=>{let $=await N0K(Y,K,_);if($)z.push($)},{logLabel:"output-styles"}),z}async function N0K(q,K,_){let z=X8();if(Cc(z,q,_))return null;try{let Y=await z.readFile(q,{encoding:"utf-8"}),{frontmatter:$,content:A}=kH(Y,q),O=EYY(q,".md"),w=$.name||O,j=`${K}:${w}`,H=Lu($.description,j)??z76(A,`Output style from ${K} plugin`),J=$["force-for-plugin"],M=J===!0||J==="true"?!0:J===!1||J==="false"?!1:void 0;return{name:j,description:H,prompt:A.trim(),source:"plugin",forceForPlugin:M}}catch(Y){return N(`Failed to load output style from ${q}: ${Y}`,{level:"error"}),null}}function S17(){K77.cache?.clear?.()}var K77;var WB8=y(()=>{F4();_8();rV();e7();ri();bj();wk8();K77=_1(async()=>{let{enabled:q,errors:K}=await ZJ(),_=[];if(K.length>0)N(`Plugin loading errors: ${K.map((z)=>$M(z)).join(", ")}`);for(let z of q){let Y=new Set;if(z.outputStylesPath)try{let $=await V0K(z.outputStylesPath,z.name,Y);if(_.push(...$),$.length>0)N(`Loaded ${$.length} output styles from plugin ${z.name} default directory`)}catch($){N(`Failed to load output styles from plugin ${z.name} default directory: ${$}`,{level:"error"})}if(z.outputStylesPaths)for(let $ of z.outputStylesPaths)try{let O=await X8().stat($);if(O.isDirectory()){let w=await V0K($,z.name,Y);if(_.push(...w),w.length>0)N(`Loaded ${w.length} output styles from plugin ${z.name} custom path: ${$}`)}else if(O.isFile()&&$.endsWith(".md")){let w=await N0K($,z.name,Y);if(w)_.push(w),N(`Loaded output style from plugin ${z.name} custom file: ${$}`)}}catch(A){N(`Failed to load output styles from plugin ${z.name} custom path ${$}: ${A}`,{level:"error"})}}return N(`Total plugin output styles loaded: ${_.length}`),_})});import{basename as LYY}from"path";var y0K;var E0K=y(()=>{F4();_8();rV();E8();ri();WB8();y0K=_1(async(q)=>{try{return(await ii("output-styles",q)).map(({filePath:z,frontmatter:Y,content:$,source:A})=>{try{let w=LYY(z).replace(/\.md$/,""),j=Y.name||w,H=Lu(Y.description,w)??z76($,`Custom ${w} output style`),J=Y["keep-coding-instructions"],M=J===!0||J==="true"?!0:J===!1||J==="false"?!1:void 0;if(Y["force-for-plugin"]!==void 0)N(`Output style "${j}" has force-for-plugin set, but this option only applies to plugin output styles. Ignoring.`,{level:"warn"});return{name:j,description:H,prompt:$.trim(),source:A,keepCodingInstructions:M}}catch(O){return H6(O),null}}).filter((z)=>z!==null)}catch(K){return H6(K),[]}})});function pfK(){Dh6.cache?.clear?.()}async function R0K(){let q=await Dh6(Z8()),K=Object.values(q).filter(($)=>$!==null&&$.source==="plugin"&&$.forceForPlugin===!0),_=K[0];if(_){if(K.length>1)N(`Multiple plugins have forced output styles: ${K.map(($)=>$.name).join(", ")}. Using: ${_.name}`,{level:"warn"});return N(`Using forced plugin output style: ${_.name}`),_}let Y=Z7()?.outputStyle||iv;return q[Y]??null}var L0K,iv="default",Hw6,Dh6;var TU=y(()=>{bq();F4();E0K();I7();_8();WB8();U1();L0K=`
4727## Insights
4728In order to encourage learning, before and after writing code, always provide brief educational explanations about implementation choices using (with backticks):

Callers 3

G0KFunction · 0.85
TYYFunction · 0.85
mMYFunction · 0.85

Calls 7

u5Function · 0.85
r8Function · 0.85
NFunction · 0.85
d6Function · 0.85
safeParseMethod · 0.80
includesMethod · 0.80
joinMethod · 0.45

Tested by

no test coverage detected