@easbot/skills 0.3.11 → 0.3.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/README.en.md +166 -59
  2. package/README.md +172 -62
  3. package/dist/chunks/blob-DOVEGVIE.cjs +1 -0
  4. package/dist/chunks/blob-JSMTOYEN.mjs +1 -0
  5. package/dist/chunks/chunk-2VZUPTI7.cjs +1 -0
  6. package/dist/chunks/chunk-2YVJ7YP6.mjs +22 -0
  7. package/dist/chunks/chunk-4R6NKPNW.mjs +3 -0
  8. package/dist/chunks/chunk-676OG55M.mjs +5 -0
  9. package/dist/chunks/chunk-6PJ3YQA7.mjs +2 -0
  10. package/dist/chunks/chunk-72DXY4B7.mjs +1 -0
  11. package/dist/chunks/chunk-CFMOYU7R.mjs +2 -0
  12. package/dist/chunks/chunk-GR2NJUJ6.mjs +255 -0
  13. package/dist/chunks/chunk-JFEBB5CL.cjs +22 -0
  14. package/dist/chunks/chunk-KV7EP6AW.cjs +255 -0
  15. package/dist/chunks/chunk-OWG6N2K6.cjs +5 -0
  16. package/dist/chunks/chunk-RWSBKHQ2.cjs +3 -0
  17. package/dist/chunks/chunk-RWZ4LFSN.mjs +1 -0
  18. package/dist/chunks/chunk-S6YNGR7S.cjs +2 -0
  19. package/dist/chunks/chunk-TCFGU43L.cjs +2 -0
  20. package/dist/chunks/chunk-VRHWDHQV.cjs +1 -0
  21. package/dist/chunks/chunk-WQGSYA5D.mjs +1 -0
  22. package/dist/chunks/chunk-XGUPIAAF.cjs +1 -0
  23. package/dist/chunks/cli-handler-RAJ42VDN.mjs +1 -0
  24. package/dist/chunks/cli-handler-YAJ5J5VA.cjs +1 -0
  25. package/dist/chunks/installer-FB26E7JZ.mjs +1 -0
  26. package/dist/chunks/installer-GOQTCUJ4.cjs +1 -0
  27. package/dist/chunks/interfaces-S47ZGORM.mjs +1 -0
  28. package/dist/chunks/interfaces-UIS44Q7A.cjs +1 -0
  29. package/dist/chunks/local-lock-4AA55ORE.cjs +1 -0
  30. package/dist/chunks/local-lock-LG5YL33V.mjs +1 -0
  31. package/dist/chunks/scan-QEVID2TF.mjs +1 -0
  32. package/dist/chunks/scan-XWU3FCE3.cjs +1 -0
  33. package/dist/chunks/skill-lock-KHPVP7AD.mjs +1 -0
  34. package/dist/chunks/skill-lock-LET33FVT.cjs +1 -0
  35. package/dist/chunks/store-3NRBE47N.mjs +1 -0
  36. package/dist/chunks/store-EHYH46YY.cjs +1 -0
  37. package/dist/chunks/telemetry-7T6MUW5A.mjs +1 -0
  38. package/dist/chunks/telemetry-LCGTSJDM.cjs +1 -0
  39. package/dist/cli.cjs +1 -1
  40. package/dist/cli.mjs +1 -1
  41. package/dist/index.cjs +1 -1
  42. package/dist/index.d.cts +242 -127
  43. package/dist/index.d.ts +242 -127
  44. package/dist/index.mjs +1 -1
  45. package/package.json +4 -4
  46. package/dist/chunks/blob-LYSE5I24.mjs +0 -1
  47. package/dist/chunks/blob-NYUAIVUS.cjs +0 -1
  48. package/dist/chunks/chunk-4IO7TNWC.mjs +0 -223
  49. package/dist/chunks/chunk-IWCI7DET.mjs +0 -6
  50. package/dist/chunks/chunk-KJPMAUXZ.cjs +0 -1
  51. package/dist/chunks/chunk-L6KE3VIY.mjs +0 -2
  52. package/dist/chunks/chunk-PGDLW2JN.cjs +0 -2
  53. package/dist/chunks/chunk-S76WRD5J.cjs +0 -6
  54. package/dist/chunks/chunk-WQJKBJSM.cjs +0 -223
  55. package/dist/chunks/chunk-Y2X6FBMZ.mjs +0 -1
  56. package/dist/chunks/scan-47YPOLJX.mjs +0 -1
  57. package/dist/chunks/scan-5G765ZEF.cjs +0 -1
@@ -0,0 +1,22 @@
1
+ 'use strict';var chunkTCFGU43L_cjs=require('./chunk-TCFGU43L.cjs'),chunkXGUPIAAF_cjs=require('./chunk-XGUPIAAF.cjs'),chunkVRHWDHQV_cjs=require('./chunk-VRHWDHQV.cjs'),promises=require('fs/promises'),path=require('path'),crypto=require('crypto'),fs=require('fs'),ue=require('simple-git'),utils=require('@easbot/utils'),os=require('os'),child_process=require('child_process'),util=require('util'),zlib=require('zlib');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var ue__default=/*#__PURE__*/_interopDefault(ue);var K=6;function ae(n){let t=n.indexOf(":");return t<0||t===n.length-1?null:{marketId:n.slice(0,t),pluginSlug:n.slice(t+1)}}function ce(n){let t=ae(n);return t?`plugins/${t.pluginSlug}`:null}function yt(n,t,e){if(!n.marketId||!n.pluginId)return null;let r=ce(n.pluginId);return r?`${t.replace(/\\/g,"/").replace(/\/+$/,"")}/${n.marketId}/${r}/${e}`:null}var Et=3e5,J=(()=>{let n=process.env.SKILLS_CLONE_TIMEOUT;if(!n)return Et;let t=Number.parseInt(n,10);return Number.isFinite(t)&&t>0?t:Et})(),Pt=util.promisify(child_process.execFile),L=class extends Error{constructor(e,r,i=false,s=false){super(e);chunkVRHWDHQV_cjs.b(this,"url");chunkVRHWDHQV_cjs.b(this,"isTimeout");chunkVRHWDHQV_cjs.b(this,"isAuthError");this.name="GitCloneError",this.url=r,this.isTimeout=i,this.isAuthError=s;}};function ye(n){let t=n.match(/^git@github\.com:([^/]+)\/([^/]+?)(?:\.git)?$/i);if(t){let e=t[1],r=t[2];return {owner:e,repo:r,slug:`${e}/${r}`,sshUrl:`git@github.com:${e}/${r}.git`}}try{let e=new URL(n);if(e.hostname!=="github.com")return null;let r=e.pathname.match(/^\/([^/]+)\/([^/]+?)(?:\.git)?\/?$/);if(!r)return null;let i=r[1],s=r[2];return {owner:i,repo:s,slug:`${i}/${s}`,sshUrl:`git@github.com:${i}/${s}.git`}}catch{return null}}function Se(n){try{let t=new URL(n);return t.protocol==="https:"&&t.hostname==="github.com"}catch{return false}}function vt(n){let t=n.toLowerCase();return t.includes("saml sso")||t.includes("enforced sso")||t.includes("enabled or enforced saml")||t.includes("re-authorize the oauth application")}function xe(n){return n.includes("Authentication failed")||n.includes("could not read Username")||n.includes("Permission denied")||n.includes("Repository not found")||n.includes("requested URL returned error: 403")||vt(n)}function X(n){let t={...process.env};return delete t.GIT_ASKPASS,delete t.GIT_EDITOR,delete t.GIT_SEQUENCE_EDITOR,delete t.GIT_PAGER,delete t.GIT_SSH_COMMAND,delete t.GIT_CONFIG_GLOBAL,delete t.GIT_CONFIG_SYSTEM,delete t.PAGER,delete t.EDITOR,delete t.VISUAL,t.GIT_TERMINAL_PROMPT="0",t.GIT_LFS_SKIP_SMUDGE="1",Object.assign(t,n),ue__default.default({timeout:{block:J},config:["filter.lfs.required=false","protocol.version=2","remote.origin.promisor=false"]}).env(t)}async function bt(n){try{await promises.rm(n,{recursive:!0,force:!0});}catch{}await promises.mkdir(n,{recursive:true});}async function Ee(n,t,e){let r=n.slug;try{let{stdout:s,stderr:o}=await Pt("gh",["auth","status","-h","github.com"],{timeout:5e3,env:{...process.env,GIT_TERMINAL_PROMPT:"0"}}),l=`${s}${o}`;/Git operations protocol:\s+ssh/i.test(l)&&(r=n.sshUrl);}catch{return false}return await Pt("gh",["repo","clone",r,t,"--",...e?["--depth=1","--branch",e]:["--depth=1"]],{timeout:J,env:{...process.env,GIT_TERMINAL_PROMPT:"0"}}),true}function Pe(n,t,e){return t&&vt(e)?`GitHub blocked HTTPS access to ${n} because the organization enforces SAML SSO.
2
+ skills tried your existing git credentials and available fallbacks, but none succeeded.
3
+ - Re-authorize your GitHub credentials/app for that org's SSO policy
4
+ - Or rerun with SSH: easbot skills add ${t.sshUrl}
5
+ - Verify access with: gh auth status -h github.com or ssh -T git@github.com`:t?`Authentication failed for ${n}.
6
+ - For private repos, ensure you have access
7
+ - Retry with SSH: easbot skills add ${t.sshUrl}
8
+ - Check access with: gh auth status -h github.com or ssh -T git@github.com`:`Authentication failed for ${n}.
9
+ - For private repos, ensure you have access
10
+ - For SSH: Check your keys with 'ssh -T git@github.com'
11
+ - For HTTPS: Run 'gh auth login' or configure git credentials`}async function It(n,t,e){if(e){await utils.Filesystem.mkdir(path.dirname(e),{recursive:true});let o=t?["--depth","1","--branch",t]:["--depth","1"];try{return await X().clone(n,e,o),e}catch(l){throw await promises.rm(e,{recursive:true,force:true}).catch(()=>{}),l}}let r=await promises.mkdtemp(path.join(os.tmpdir(),"skills-")),i=t?["--depth","1","--branch",t]:["--depth","1"],s=ye(n);try{return await X().clone(n,r,i),r}catch(o){let l=o instanceof Error?o.message:String(o),a=l.includes("block timeout")||l.includes("timed out"),c=xe(l);if(a){try{await promises.rm(r,{recursive:!0,force:!0});}catch{}let f=Math.round(J/1e3);throw new L(`Clone timed out after ${f}s. Common causes:
12
+ - Large repository: raise the timeout with SKILLS_CLONE_TIMEOUT=600000 (10m)
13
+ - Slow network: retry, or clone manually and pass the local path to 'skills add'
14
+ - Private repo without credentials: ensure auth is configured
15
+ - For SSH: ssh-add -l (to check loaded keys)
16
+ - For HTTPS: gh auth status (if using GitHub CLI)`,n,true,false)}if(c&&s&&Se(n)){try{if(await bt(r),await Ee(s,r,t))return r}catch{}try{return await bt(r),await X({GIT_SSH_COMMAND:process.env.GIT_SSH_COMMAND??"ssh -o BatchMode=yes"}).clone(s.sshUrl,r,i),r}catch{}}try{await promises.rm(r,{recursive:!0,force:!0});}catch{}if(c)throw new L(Pe(n,s,l),n,false,true);let u=l.includes("filter.smudge")?`
17
+ - The repo defines a smudge/clean filter that Git considers unsafe.
18
+ Enable it with: git config --global protocol.allowUnsafeFilter true
19
+ Or upgrade Git, or unset filter.<driver>.* in the source repo.`:"";throw new L(`Failed to clone ${n}: ${l}${u}`,n,false,false)}}async function vn(n){let t=path.normalize(path.resolve(n)),e=path.normalize(path.resolve(os.tmpdir()));if(!t.startsWith(e+path.sep)&&t!==e)throw new Error("Attempted to clean up directory outside of temp directory");await promises.rm(n,{recursive:true,force:true});}function Y(n){if(n.type==="local")return null;let t=n.url.match(/^git@[^:]+:(.+)$/);if(t){let e=t[1];return e=e.replace(/\.git$/,""),e.includes("/")?e:null}if(n.url.startsWith("ssh://"))try{let r=new URL(n.url).pathname.slice(1);return r=r.replace(/\.git$/,""),r.includes("/")?r:null}catch{return null}if(!n.url.startsWith("http://")&&!n.url.startsWith("https://"))return null;try{let r=new URL(n.url).pathname.slice(1);if(r=r.replace(/\.git$/,""),r.includes("/"))return r}catch{}return null}function Wn(n){let t=n.match(/^([^/]+)\/([^/]+)$/);return t?{owner:t[1],repo:t[2]}:null}async function Kn(n,t){try{let e=await fetch(`https://api.github.com/repos/${n}/${t}`);return e.ok?(await e.json()).private===!0:null}catch{return null}}async function Rt(n,t){try{let e=await fetch(`https://api.github.com/repos/${n}/${t}`,{headers:{Accept:"application/vnd.github+json"}});if(!e.ok)return null;let r=await e.json();return typeof r.default_branch=="string"&&r.default_branch.length>0?r.default_branch:null}catch{return null}}function _(n){let e=n.replace(/\\/g,"/").split("/");for(let r of e)if(r==="..")throw new Error(`Unsafe subpath: "${n}" contains path traversal segments. Subpaths must not contain ".." components.`);return n}function ve(n){return path.isAbsolute(n)||n.startsWith("./")||n.startsWith("../")||n==="."||n===".."||/^[a-zA-Z]:[/\\]/.test(n)}var Ie={"coinbase/agentWallet":"coinbase/agentic-wallet-skills"};function Z(n){try{return decodeURIComponent(n)}catch{return n}}function $e(n){if(n.startsWith("github:")||n.startsWith("gitlab:")||n.startsWith("git@")||/^ssh:\/\/.+\.git(?:$|[/?])/i.test(n))return true;if(n.startsWith("http://")||n.startsWith("https://"))try{let t=new URL(n),e=t.pathname;if(t.hostname==="github.com")return /^\/[^/]+\/[^/]+(?:\.git)?(?:\/tree\/[^/]+(?:\/.*)?)?\/?$/.test(e);if(t.hostname==="gitlab.com")return /^\/.+?\/[^/]+(?:\.git)?(?:\/-\/tree\/[^/]+(?:\/.*)?)?\/?$/.test(e)}catch{}return /^https?:\/\/.+\.git(?:$|[/?])/i.test(n)?true:!n.includes(":")&&!n.startsWith(".")&&!n.startsWith("/")&&/^([^/]+)\/([^/]+)(?:\/(.+)|@(.+))?$/.test(n)}function Ae(n){let t=n.indexOf("#");if(t<0)return {inputWithoutFragment:n};let e=n.slice(0,t),r=n.slice(t+1);if(!r)return {inputWithoutFragment:e};if(!$e(e))return {inputWithoutFragment:n};let i=r.indexOf("@");if(i===-1)return {inputWithoutFragment:e,ref:Z(r)};let s=r.slice(0,i),o=r.slice(i+1);return {inputWithoutFragment:e,ref:s?Z(s):void 0,subpath:o?Z(o):void 0}}function $t(n,t,e){return t?`${n}#${t}${e?`@${e}`:""}`:n}function At(n){if(ve(n)){let g=path.resolve(n);return {type:"local",url:g,localPath:g}}let{inputWithoutFragment:t,ref:e,subpath:r}=Ae(n);n=t;let i=Ie[n];i&&(n=i);let s=n.match(/^github:(.+)$/);if(s)return At($t(s[1],e,r));let o=n.match(/^gitlab:(.+)$/);if(o)return At($t(`https://gitlab.com/${o[1]}`,e,r));let l=n.match(/github\.com\/([^/]+)\/([^/]+)\/tree\/([^/]+)\/(.+)/);if(l){let[,g,m,w,S]=l;return {type:"github",url:`https://github.com/${g}/${m}.git`,ref:w||e,subpath:S&&_(S)}}let a=n.match(/github\.com\/([^/]+)\/([^/]+)\/tree\/([^/]+)$/);if(a){let[,g,m,w]=a;return {type:"github",url:`https://github.com/${g}/${m}.git`,ref:w||e}}let c=n.match(/github\.com\/([^/]+)\/([^/]+)/);if(c){let[,g,m]=c,w=m.replace(/\.git$/,"");return {type:"github",url:`https://github.com/${g}/${w}.git`,...e?{ref:e}:{}}}let u=n.match(/^(https?):\/\/([^/]+)\/(.+?)\/-\/tree\/([^/]+)\/(.+)/);if(u){let[,g,m,w,S,p]=u;if(m!=="github.com"&&w)return {type:"gitlab",url:`${g}://${m}/${w.replace(/\.git$/,"")}.git`,ref:S||e,subpath:p&&_(p)}}let f=n.match(/^(https?):\/\/([^/]+)\/(.+?)\/-\/tree\/([^/]+)$/);if(f){let[,g,m,w,S]=f;if(m!=="github.com"&&w)return {type:"gitlab",url:`${g}://${m}/${w.replace(/\.git$/,"")}.git`,ref:S||e}}let k=n.match(/gitlab\.com\/(.+?)(?:\.git)?\/?$/);if(k){let g=k[1];if(g.includes("/"))return {type:"gitlab",url:`https://gitlab.com/${g}.git`,...e?{ref:e}:{}}}let E=n.match(/^([^/@]+)\/([^/@]+)@(.+)?$/);if(E&&!n.includes(":")&&!n.startsWith(".")&&!n.startsWith("/")){let g=E[1],m=E[2],w=E[3];if(!w)return {type:"github",url:`https://github.com/${g}/${m}.git`,...e?{ref:e}:{}};let S=_(w);return {type:"github",url:`https://github.com/${g}/${m}.git`,...e?{ref:e}:{},...S?{subpath:S}:{}}}let P=n.match(/^([^/@]+)\/([^/@]+)(?:\/(.+?))?\/?$/);if(P&&!n.includes(":")&&!n.startsWith(".")&&!n.startsWith("/")){let[,g,m,w]=P;return {type:"github",url:`https://github.com/${g}/${m}.git`,...e?{ref:e}:{},subpath:r??(w&&_(w))}}return Re(n)?{type:"well-known",url:n}:{type:"git",url:n,...e?{ref:e}:{},...r?{subpath:r}:{}}}function Re(n){if(!n.startsWith("http://")&&!n.startsWith("https://"))return false;try{let t=new URL(n);return !(["github.com","gitlab.com","raw.githubusercontent.com"].includes(t.hostname)||n.endsWith(".git"))}catch{return false}}var Wt="https://schemas.agentskills.io/discovery/0.2.0/schema.json",Ne=/\/schemas\/agent-skills\/index\.v1\.json$/,De=50*1024*1024,Fe=1e3;function Ce(n,t){let e=n.skillPath;if(typeof e=="string"&&e.trim()!==""&&e!==null)return e.replace(/^\/+/,"").replace(/\/+$/,"");if(typeof n.sourceUrl=="string"&&n.sourceUrl)try{let i=new URL(n.sourceUrl).pathname,s=/\/\.well-known\/(?:agent-skills|skills)\/(.*?)\/SKILL\.md$/,o=i.match(s);if(o?.[1])return o[1];let l=i.match(/^(.*?)\/[^/]+\/SKILL\.md$/);if(l?.[1])return l[1]}catch{}if(typeof n.installName=="string"&&n.installName){let r=n.installName.lastIndexOf("@");if(r>=0){let i=n.installName.slice(r+1);if(i.includes("/"))return i.replace(/^\/+/,"")}}return t}var Q=class{constructor(){chunkVRHWDHQV_cjs.b(this,"id","well-known");chunkVRHWDHQV_cjs.b(this,"displayName","Well-Known Skills");chunkVRHWDHQV_cjs.b(this,"WELL_KNOWN_PATHS",[".well-known/agent-skills",".well-known/skills"]);chunkVRHWDHQV_cjs.b(this,"INDEX_FILE","index.json");}match(t){if(!t.startsWith("http://")&&!t.startsWith("https://"))return {matches:false};try{let e=new URL(t);return ["github.com","gitlab.com","huggingface.co"].includes(e.hostname)?{matches:!1}:{matches:!0,sourceIdentifier:`wellknown/${e.hostname}`}}catch{return {matches:false}}}async fetchIndex(t){return (await this.fetchIndexCandidates(t))[0]??null}async fetchIndexCandidates(t){try{let e=new URL(t),r=e.pathname.replace(/\/$/,""),i=[],s=r.match(/\/\.well-known\/(agent-skills|skills)\/?$/);if(s?.[1]){let l=`.well-known/${s[1]}`;i.push({indexUrl:`${e.protocol}//${e.host}${r}/${this.INDEX_FILE}`,baseUrl:`${e.protocol}//${e.host}${r.replace(/\/\.well-known\/(?:agent-skills|skills)$/,"")}`,wellKnownPath:l});}for(let l of this.WELL_KNOWN_PATHS)i.push({indexUrl:`${e.protocol}//${e.host}${r}/${l}/${this.INDEX_FILE}`,baseUrl:`${e.protocol}//${e.host}${r}`,wellKnownPath:l}),r&&r!==""&&i.push({indexUrl:`${e.protocol}//${e.host}/${l}/${this.INDEX_FILE}`,baseUrl:`${e.protocol}//${e.host}`,wellKnownPath:l});let o=[];for(let{indexUrl:l,baseUrl:a,wellKnownPath:c}of i)try{let u=await fetch(l);if(!u.ok)continue;let f=await u.json(),k=this.normalizeIndex(f,l,c);if(!k)continue;o.push({index:k.index,entries:k.entries,resolvedBaseUrl:a,resolvedWellKnownPath:c,indexUrl:l});}catch{}return o}catch{return []}}normalizeIndex(t,e,r){if(!t||typeof t!="object")return null;let i=t;if(!Array.isArray(i.skills))return null;let s=i.$schema;if(s===Wt){let a=[],c=[];for(let u of i.skills){if(!this.isValidSkillEntryV2(u))continue;let f=new URL(u.url,e).toString();a.push({version:"0.2.0",name:u.name,description:u.description,type:u.type,artifactUrl:f,digest:u.digest,indexEntry:u}),c.push(u);}return a.length===0?null:{index:{$schema:Wt,skills:c},entries:a}}if(typeof s=="string"&&Ne.test(s)){let a=[],c=[];for(let u of i.skills){if(!this.isValidSkillEntryEasbotV1(u))continue;let f=new URL(u.sourceUrl,e).toString();a.push({version:"easbot-v1",name:u.name,description:u.description,skillMdUrl:f,installName:u.installName,indexEntry:u}),c.push(u);}return a.length===0?null:{index:{$schema:s,skills:c},entries:a}}if(s!==void 0)return null;let o=[],l=[];for(let a of i.skills){if(!this.isValidSkillEntryV1(a))return null;o.push(a),l.push({version:"0.1.0",name:a.name,description:a.description,files:a.files,baseUrl:this.getLegacySkillBaseUrl(e,r),wellKnownPath:r,indexEntry:a});}return {index:{skills:o},entries:l}}getLegacySkillBaseUrl(t,e){let r=new URL(t),i=`/${e}/${this.INDEX_FILE}`;return `${r.protocol}//${r.host}${r.pathname.slice(0,-i.length)}`}isValidSkillName(t){return !(typeof t!="string"||t.length===0||t.length>64||!/^[a-z0-9-]+$/.test(t)||t.startsWith("-")||t.endsWith("-")||t.includes("--"))}isSafeLegacyFilePath(t){return !(typeof t!="string"||t.length===0||t.startsWith("/")||t.startsWith("\\")||t.includes("..")||t.includes("\0"))}isValidSkillEntryEasbotV1(t){if(!t||typeof t!="object")return false;let e=t;if(!this.isValidSkillName(e.name)||typeof e.description!="string"||!e.description||e.description.length>1024||typeof e.sourceUrl!="string"||!e.sourceUrl)return false;try{new URL(e.sourceUrl,"https://easbot.cn/.well-known/agent-skills/index.json");}catch{return false}return true}isValidSkillEntryV1(t){if(!t||typeof t!="object")return false;let e=t;if(!this.isValidSkillName(e.name)||typeof e.description!="string"||!e.description||!Array.isArray(e.files)||e.files.length===0)return false;for(let i of e.files)if(!this.isSafeLegacyFilePath(i))return false;return e.files.some(i=>typeof i=="string"&&i.toLowerCase()==="skill.md")}isValidSkillEntryV2(t){if(!t||typeof t!="object")return false;let e=t;if(!this.isValidSkillName(e.name)||typeof e.description!="string"||!e.description||e.description.length>1024||e.type!=="skill-md"&&e.type!=="archive"||typeof e.url!="string"||!e.url||typeof e.digest!="string"||!/^sha256:[a-f0-9]{64}$/.test(e.digest))return false;try{new URL(e.url,"https://example.com/.well-known/agent-skills/index.json");}catch{return false}return true}async fetchSkill(t){try{let e=new URL(t),r=await this.fetchIndexCandidates(t);for(let i of r){let{entries:s}=i,o=null,l=e.pathname.match(/\/.well-known\/(?:agent-skills|skills)\/([^/]+)\/?$/);if(l?.[1]&&l[1]!=="index.json"?o=l[1]:s.length===1&&(o=s[0].name),!o)continue;let a=s.find(u=>u.name===o);if(!a)continue;let c=await this.fetchSkillByEntry(a);if(c)return c}return null}catch{return null}}async fetchSkillByEntry(t,e,r){return typeof t=="string"?e?this.fetchLegacySkillByEntry({version:"0.1.0",name:e.name,description:e.description,files:e.files,baseUrl:t,wellKnownPath:r??this.WELL_KNOWN_PATHS[0],indexEntry:e}):null:t.version==="0.1.0"?this.fetchLegacySkillByEntry(t):t.version==="easbot-v1"?this.fetchEasbotV1SkillByEntry(t):this.fetchArtifactSkillByEntry(t)}async fetchEasbotV1SkillByEntry(t){try{let e=await fetch(t.skillMdUrl);if(!e.ok)return null;let r=await e.text(),{data:i}=chunkTCFGU43L_cjs.c(r);if(typeof i.name!="string"||typeof i.description!="string")return null;let s=new Map;s.set("SKILL.md",r);let o=Ce(t.indexEntry,i.name);return this.createSkill({name:i.name,description:i.description,content:r,installName:o,sourceUrl:t.skillMdUrl,metadata:i.metadata,files:s,indexEntry:t.indexEntry})}catch{return null}}async fetchLegacySkillByEntry(t){try{let e=`${t.baseUrl.replace(/\/$/,"")}/${t.wellKnownPath}/${t.name}`,r=`${e}/SKILL.md`,i=await fetch(r);if(!i.ok)return null;let s=await i.text(),{data:o}=chunkTCFGU43L_cjs.c(s);if(typeof o.name!="string"||typeof o.description!="string")return null;let l=new Map;l.set("SKILL.md",s);let c=t.files.filter(f=>f.toLowerCase()!=="skill.md").map(async f=>{try{let k=`${e}/${f}`,E=await fetch(k);if(E.ok){let P=await E.arrayBuffer();return {path:f,content:new Uint8Array(P)}}}catch{}return null}),u=await Promise.all(c);for(let f of u)f&&l.set(f.path,f.content);return this.createSkill({name:o.name,description:o.description,content:s,installName:t.name,sourceUrl:r,metadata:o.metadata,files:l,indexEntry:t.indexEntry})}catch{return null}}async fetchArtifactSkillByEntry(t){try{let e=await fetch(t.artifactUrl);if(!e.ok)return null;let r=e.headers.get("content-type")??"",i=new Uint8Array(await e.arrayBuffer());if(this.computeDigest(i)!==t.digest)return null;if(t.type==="skill-md"){let c=new TextDecoder().decode(i),{data:u}=chunkTCFGU43L_cjs.c(c);if(typeof u.name!="string"||typeof u.description!="string")return null;let f=new Map;return f.set("SKILL.md",c),this.createSkill({name:u.name,description:u.description,content:c,installName:t.name,sourceUrl:t.artifactUrl,metadata:u.metadata,files:f,indexEntry:t.indexEntry})}let s=this.extractArchive(i,t.artifactUrl,r),o=s.get("SKILL.md");if(!o)return null;let l=typeof o=="string"?o:new TextDecoder().decode(o);s.set("SKILL.md",l);let{data:a}=chunkTCFGU43L_cjs.c(l);return typeof a.name!="string"||typeof a.description!="string"?null:this.createSkill({name:a.name,description:a.description,content:l,installName:t.name,sourceUrl:t.artifactUrl,metadata:a.metadata,files:s,indexEntry:t.indexEntry})}catch{return null}}createSkill(t){return {name:chunkTCFGU43L_cjs.b(t.name),description:chunkTCFGU43L_cjs.b(t.description),content:t.content,installName:t.installName,sourceUrl:t.sourceUrl,metadata:t.metadata&&typeof t.metadata=="object"?t.metadata:void 0,files:t.files,indexEntry:t.indexEntry}}async fetchAllSkills(t){try{let e=await this.fetchIndexCandidates(t);for(let r of e){let i=r.entries.map(l=>this.fetchSkillByEntry(l)),o=(await Promise.all(i)).filter(l=>l!==null);if(o.length>0)return o}return []}catch{return []}}computeDigest(t){return `sha256:${crypto.createHash("sha256").update(t).digest("hex")}`}extractArchive(t,e,r){if(this.isZipArchive(t,e,r))return this.extractZip(t);if(this.isTarGzArchive(t,e,r))return this.extractTarGz(t);throw new Error("Unsupported archive format")}isZipArchive(t,e,r){return r.includes("application/zip")||e.toLowerCase().endsWith(".zip")||t[0]===80&&t[1]===75}isTarGzArchive(t,e,r){let i=e.toLowerCase();return r.includes("application/gzip")||r.includes("application/x-gzip")||i.endsWith(".tar.gz")||i.endsWith(".tgz")||t[0]===31&&t[1]===139}normalizeArchivePath(t){if(!t||t.includes("\0")||t.startsWith("/")||t.startsWith("\\")||/^[A-Za-z]:/.test(t)||t.includes("\\"))return null;let e=t.split("/").filter(Boolean);return e.length===0||e.some(r=>r==="."||r==="..")?null:e.join("/")}addArchiveFile(t,e,r,i){let s=this.normalizeArchivePath(e);if(!s)throw new Error(`Unsafe archive path: ${e}`);if(i.bytes+=r.byteLength,i.bytes>De)throw new Error("Archive exceeds maximum unpacked size");if(t.size>=Fe)throw new Error("Archive contains too many files");t.set(s,r);}extractTarGz(t){let e=zlib.gunzipSync(Buffer.from(t)),r=new Map,i={bytes:0},s=0;for(;s+512<=e.length;){let o=e.subarray(s,s+512);if(o.every(P=>P===0))break;let l=this.readTarString(o,0,100),a=this.readTarString(o,124,12).trim(),c=o[156],u=this.readTarString(o,345,155),f=u?`${u}/${l}`:l,k=Number.parseInt(a||"0",8);if(!Number.isFinite(k)||k<0)throw new Error("Invalid tar entry size");if(s+=512,c===50||c===49)throw new Error("Archive links are not supported");if(c===0||c===48){let P=e.subarray(s,s+k);this.addArchiveFile(r,f,new Uint8Array(P),i);}s+=Math.ceil(k/512)*512;}if(!r.has("SKILL.md"))throw new Error("Archive missing root SKILL.md");return r}readTarString(t,e,r){let i=t.subarray(e,e+r),s=i.indexOf(0);return new TextDecoder().decode(s>=0?i.subarray(0,s):i)}extractZip(t){let e=Buffer.from(t),r=this.findZipEndOfCentralDirectory(e);if(r<0)throw new Error("Invalid zip archive");let i=e.readUInt16LE(r+10),s=e.readUInt32LE(r+16),o=new Map,l={bytes:0},a=s;for(let c=0;c<i;c++){if(e.readUInt32LE(a)!==33639248)throw new Error("Invalid zip directory");let u=e.readUInt16LE(a+8),f=e.readUInt16LE(a+10),k=e.readUInt32LE(a+20),E=e.readUInt32LE(a+24),P=e.readUInt16LE(a+28),g=e.readUInt16LE(a+30),m=e.readUInt16LE(a+32),w=e.readUInt32LE(a+38),S=e.readUInt32LE(a+42),p=a+46,y=e.subarray(p,p+P),x=new TextDecoder(u&2048?"utf-8":void 0).decode(y);if(a=p+P+g+m,x.endsWith("/"))continue;if(u&1)throw new Error("Encrypted zip entries are not supported");let T=w>>>16&61440;if(T===40960||T===4096)throw new Error("Archive links are not supported");if(e.readUInt32LE(S)!==67324752)throw new Error("Invalid zip local header");let M=e.readUInt16LE(S+26),le=e.readUInt16LE(S+28),pt=S+30+M+le,ht=e.subarray(pt,pt+k),z;if(f===0)z=ht;else if(f===8)z=zlib.inflateRawSync(ht);else throw new Error(`Unsupported zip compression method: ${f}`);if(z.byteLength!==E)throw new Error("Zip entry size mismatch");this.addArchiveFile(o,x,new Uint8Array(z),l);}if(!o.has("SKILL.md"))throw new Error("Archive missing root SKILL.md");return o}findZipEndOfCentralDirectory(t){let e=Math.max(0,t.length-65535-22);for(let r=t.length-22;r>=e;r--)if(t.readUInt32LE(r)===101010256)return r;return -1}toRawUrl(t){try{let e=new URL(t);if(t.toLowerCase().endsWith("/skill.md"))return t;let r=this.WELL_KNOWN_PATHS[0],i=e.pathname.match(/\/.well-known\/(?:agent-skills|skills)\/([^/]+)\/?$/);if(i?.[1]){let o=e.pathname.replace(/\/.well-known\/(?:agent-skills|skills)\/.*$/,"");return `${e.protocol}//${e.host}${o}/${r}/${i[1]}/SKILL.md`}let s=e.pathname.replace(/\/$/,"");return `${e.protocol}//${e.host}${s}/${r}/${this.INDEX_FILE}`}catch{return t}}getSourceIdentifier(t){try{return new URL(t).hostname.replace(/^www\./,"")}catch{return "unknown"}}async hasSkillsIndex(t){return await this.fetchIndex(t)!==null}},Kt=new Q;function tt(n,t){let e=path.normalize(path.resolve(t)),r=path.normalize(path.resolve(n));return r.startsWith(e+path.sep)||r===e}function O(n){return n.startsWith("./")}async function Dt(n){let t=new Map;try{let e=await promises.readFile(path.join(n,".claude-plugin/marketplace.json"),"utf-8"),r=JSON.parse(e),i=r.metadata?.pluginRoot;if(i===void 0||O(i))for(let o of r.plugins??[]){if(!o.name||typeof o.source!="string"&&o.source!==void 0||o.source!==void 0&&!O(o.source))continue;let l=path.join(n,i??"",o.source??"");if(tt(l,n)&&o.skills&&o.skills.length>0)for(let a of o.skills){if(!O(a))continue;let c=path.join(l,a);tt(c,n)&&t.set(path.resolve(c),o.name);}}}catch{}try{let e=await promises.readFile(path.join(n,".claude-plugin/plugin.json"),"utf-8"),r=JSON.parse(e);if(r.name&&r.skills&&r.skills.length>0)for(let i of r.skills){if(!O(i))continue;let s=path.join(n,i);tt(s,n)&&t.set(path.resolve(s),r.name);}}catch{}return t}var Oe=["node_modules",".git","dist","build","__pycache__"];async function je(n){let t=path.join(n,".gitignore");try{let e=await promises.readFile(t,"utf-8");return utils.Glob.parseGitignoreContent(e)}catch{return []}}function et(n){return n.toLowerCase().replace(/[\s_]+/g,"-")}function He(n){return n.split(path.sep).join("/").replace(/\/+/g,"/")}function Ve(){let n=process.env.INSTALL_INTERNAL_SKILLS;return n==="1"||n==="true"}async function Ot(n){try{let t=path.join(n,"SKILL.md");return (await promises.stat(t)).isFile()}catch{return false}}async function Ct(n,t){try{let e=await promises.readFile(n,"utf-8"),{data:r}=chunkTCFGU43L_cjs.c(e);if(!r.name||!r.description||typeof r.name!="string"||typeof r.description!="string")return null;let i=r.metadata&&typeof r.metadata=="object"&&!Array.isArray(r.metadata)?r.metadata:void 0;return i?.internal===!0&&!Ve()&&!t?.includeInternal?null:{name:chunkTCFGU43L_cjs.b(r.name),description:chunkTCFGU43L_cjs.b(r.description),path:path.dirname(n),rawContent:e,metadata:i}}catch{return null}}async function jt(n,t=0,e=5){if(t>e)return [];try{let[r,i]=await Promise.all([Ot(n),promises.readdir(n,{withFileTypes:!0}).catch(()=>[])]),s=r?[n]:[],o=await Promise.all(i.filter(l=>l.isDirectory()&&!Oe.includes(l.name)).map(l=>jt(path.join(n,l.name),t+1,e)));return [...s,...o.flat()]}catch{return []}}function Ge(n,t){let e=path.normalize(path.resolve(n)),r=path.normalize(path.resolve(path.join(n,t)));return r.startsWith(e+path.sep)||r===e}async function it(n,t,e){let r=[],i=new Set,s=await V(n),o=new Set(Object.keys(s.skills).map(et));if(t&&!Ge(n,t))throw new Error(`Invalid subpath: "${t}" resolves outside the repository directory. Subpath must not contain ".." segments that escape the base path.`);let l=t?path.join(n,t):n,a=await Dt(l),c=p=>{let y=path.resolve(p.path);return a.has(y)&&(p.pluginName=a.get(y)),p},u=chunkTCFGU43L_cjs.n(),f=p=>{if(o.size===0)return false;let y=He(path.relative(n,p.path));if(!u.some(M=>y===M||y.startsWith(`${M}/`)))return false;let gt=et(p.name),T=et(path.basename(p.path));return o.has(gt)||o.has(T)},k=async p=>{if(!await Ot(p))return false;let y=await Ct(path.join(p,"SKILL.md"),e);return !y||i.has(y.name)||f(y)||(y=c(y),r.push(y),i.add(y.name)),true},E=t?t.replace(/^\/+|\/+$/g,"").split("/").filter(p=>p.length>0):[],P=E.length>0?`**/${E.join("/")}/**/SKILL.md`:"**/SKILL.md",g=await utils.Glob.scan(P,{cwd:l,absolute:true,ignore:[...utils.Glob.DEFAULT_IGNORE_PATTERNS,...await je(l)]}),m="/",w=l.split(path.sep).join(m);g.sort((p,y)=>p.split(m).length-y.split(m).length);let S=[];for(let p of g){if(S.some(x=>p.startsWith(`${x}${m}`)||p===x))continue;let y=path.dirname(p);if(await k(y)){let x=y.split(path.sep).join(m);if(x===w)continue;S.push(x);}}if(r.length===0||e?.fullDepth){let p=await jt(l);for(let y of p){let x=await Ct(path.join(y,"SKILL.md"),e);x&&!i.has(x.name)&&!f(x)&&(x=c(x),r.push(x),i.add(x.name));}}return r}function Be(n){return n.name||path.basename(n.path)}function er(n,t){let e=t.map(r=>r.toLowerCase());return n.filter(r=>{let i=r.name.toLowerCase(),s=Be(r).toLowerCase();return e.some(o=>o===i||o===s)})}var Ht="*";function nr(n,t){if(!n||n.length===0)return [];let e=new Set(t),r=[];for(let i of n)if(i!==Ht){if(i.includes("/")||i.includes("**")){r.push(i);continue}Vt.test(i)?t.some(s=>utils.Wildcard.match(s,i))||r.push(i):e.has(i)||r.push(i);}return r}function rr(n,t){let e={wildcard:false,matched:[],invalid:[]};if(!n||n.length===0)return e;let r=new Set(t),i=new Set;for(let s of n){if(s===Ht){e.wildcard=true;continue}if(s.includes("/")||s.includes("**")){e.invalid.push(s);continue}if(Vt.test(s))for(let o of t)utils.Wildcard.match(o,s)&&i.add(o);else r.has(s)?i.add(s):e.invalid.push(s);}return e.matched=Array.from(i),e}var Vt=/[*?[{}]/;var st="houjallen/agent-skills";async function Sr(n){let t=n.defaultPlugin;if(!t||typeof t.marketId!="string"||t.marketId.length===0)return st;let e=n.markets[t.marketId];if(!e)return st;let r=e.localPath??e.url;if(!r)return st;let i=r;return e.subpath&&(i=`${i}@${e.subpath}`),e.ref&&(i=`${i}#${e.ref}`),i}function Qe(n){if(!n||typeof n!="object"||Array.isArray(n))return null;let t=n;if(typeof t.marketId!="string"||t.marketId.length===0)return null;let e={marketId:t.marketId};return typeof t.pluginId=="string"&&t.pluginId.length>0&&(e.pluginId=t.pluginId),e}function h(n){return utils.Filesystem.normalize(n)}function Bt(n){if(n==="general"||n==="coder"||n==="all")return n}function tn({scope:n}){let t=n==="project"?chunkXGUPIAAF_cjs.p():chunkXGUPIAAF_cjs.m(),e=utils.Filesystem.join(t,n==="project"?".easbot":"easbot","skills");return utils.Filesystem.normalize(e)}function C(){return utils.Filesystem.join(chunkXGUPIAAF_cjs.m(),"skills","store")}function Zt(){return utils.Filesystem.join(C(),"index.json")}function at(n){let t=`${n.type}|${n.url}|${n.ref??""}`;return crypto.createHash("sha256").update(t).digest("hex")}function Yt(n){let t=at(n);return utils.Filesystem.join(C(),t)}function N(){return utils.Filesystem.join(chunkXGUPIAAF_cjs.o(),"skills","cache")}function en(n,t,e){if(e&&e.length>0)return U(e);let r=nn(n);if(r)return r;if(t?.includes("/")){let i=t.split("/")[0];if(i)return U(i)}return "default"}function nn(n){let t=n.localPath??n.url;if(!t)return null;if(n.type==="well-known")try{let i=new URL(t),s=i.hostname.replace(/^www\./,"").replace(/\./g,"-"),o=i.pathname.replace(/^\/+/,"").split("/")[0]||"";return o&&!s.endsWith(`-${o}`)?U(`${s}-${o}`):U(s)}catch{return null}let e=t.match(/^(?:https?:\/\/[^/]+\/|git@[^:]+:)([^/]+)\/([^/]+?)(?:\.git)?\/?$/);if(e)return U(e[2]??"");let r=t.split(/[\\/]/).filter(Boolean).pop();return r?U(r.replace(/\.git$/,"")):null}function U(n){let t=n.trim().replace(/[:\\/\0]/g,"-").replace(/\.git$/,"").replace(/\s+/g,"-");return t.length>64&&(t=t.slice(0,64)),t.length>0?t:"default"}function ft(n){if(n.type==="well-known")return rn(n.url);let t=Y(n);if(t)return utils.Filesystem.join(N(),n.type,t);let e=n.url.replace(/^https?:\/\//,"").replace(/^git@[^:]+:/,"").replace(/\.git$/,"").replace(/[/:]/g,"-");return utils.Filesystem.join(N(),n.type,e)}function rn(n){let t,e;try{let r=new URL(n);t=r.hostname.replace(/^www\./,"");let i=r.pathname.match(/\/\.well-known\/(agent-skills|skills)/);i?.[1]?e=`.well-known/${i[1]}`:e=".well-known/agent-skills";}catch{let r=crypto.createHash("sha256").update(n).digest("hex").slice(0,16);return utils.Filesystem.join(N(),"wellknown",`unknown-${r}`)}return utils.Filesystem.join(N(),"wellknown",t,e)}async function Qt(n){n.skillNames??[];if(n.type==="local")return sn(n);let e=n.mode??"install",{cacheDir:r,source:i,cloneError:s}=await on(n,e);return {tempDir:r,cacheHit:false,source:i,cloneError:s}}var ct=class extends Error{constructor(e){super(`Local source path does not exist: ${e}`);chunkVRHWDHQV_cjs.b(this,"localPath",e);this.name="LocalPathNotFoundError";}};async function sn(n,t){let e=n.localPath??n.url;if(!fs.existsSync(e))throw new ct(e);let r=Yt(n);return fs.existsSync(r)&&await te(r)?{tempDir:r,cacheHit:true,source:"local-cp",cloneError:null}:{tempDir:e,cacheHit:false,source:"local-cp",cloneError:null}}async function on(n,t){let e=n.ref;if(!e){let l=Y(n);if(l){let[a,c]=l.split("/");if(a&&c){let u=await Rt(a,c);u&&(e=u);}}}e||(e="HEAD");let r=ft(n);if(n.type==="well-known")return fs.existsSync(r)?{cacheDir:r,source:"cache-pull",cloneError:null}:(await utils.Filesystem.mkdir(h(r),{recursive:true}),await un(n.url,r),{cacheDir:r,source:"well-known-fetch",cloneError:null});if(fs.existsSync(r))try{let l=ue__default.default(r);return t==="update"?(await l.fetch(),await l.checkout(e),{cacheDir:r,source:"cache-pull",cloneError:null}):(await l.checkout(e),{cacheDir:r,source:"cache-pull",cloneError:null})}catch{return {cacheDir:r,source:"cache-pull",cloneError:null}}async function i(l,a,c){return It(l,a,c)}let s=null,o=null;try{return await utils.Filesystem.mkdir(h(utils.Filesystem.dirname(r)),{recursive:!0}),s=`${r}.clone-tmp`,await i(n.url,e,s),await promises.rename(h(s),h(r)),{cacheDir:r,source:"cache-clone",cloneError:null}}catch(l){return l instanceof L?o=l:l instanceof Error&&(o=new L(`Failed to clone ${n.url}: ${l.message}`,n.url,false,false)),await utils.Filesystem.mkdir(h(r),{recursive:true}).catch(()=>{}),{cacheDir:r,source:"cache-pull",cloneError:o}}finally{if(s)try{await promises.rm(h(s),{recursive:!0,force:!0});}catch{}}}async function R(){let n=h(Zt()),t;try{t=await utils.Filesystem.readText(n);}catch{return {version:6,markets:{}}}let e;try{e=JSON.parse(t);}catch{try{await promises.rename(h(n),`${h(n)}.corrupt-${Date.now()}`);}catch{}return {version:6,markets:{}}}let r=e;if(r.version!==6||!r.markets)return {version:6,markets:{}};let i={version:6,markets:r.markets};if("defaultPlugin"in r){let s=Qe(r.defaultPlugin);s&&(i.defaultPlugin=s);}return i}async function B(n){await utils.Filesystem.writeJson(h(Zt()),n);}async function xr(){let n=await R(),t={};for(let e of Object.values(n.markets))for(let r of Object.values(e.plugins))for(let[i,s]of Object.entries(r.skills))t[i]={marketId:e.id,pluginId:r.id,pluginName:r.name,storePath:e.storePath,pluginSlug:r.id.split(":").slice(1).join(":")||r.id,url:e.url,type:e.type,localPath:e.localPath,subpath:e.subpath,ref:e.ref,addedAt:e.addedAt,skillPath:s.skillPath,computedHash:s.computedHash,sourceKey:e.id,sourcePath:e.localPath??e.storePath};return t}async function Er(n,t,e,r,i){let s=await R(),o=s.markets[n];o||(o={...i,id:n,addedAt:i.addedAt??new Date().toISOString(),plugins:{}},s.markets[n]=o);let l=o.plugins[t];l||(l={id:t,name:t.split(":").slice(1).join(":")||t,skills:{}},o.plugins[t]=l),l.skills[e]=r,await B(s);}async function ln(){let n=await R(),t=[];for(let e of Object.values(n.markets))for(let r of Object.values(e.plugins))for(let i of Object.values(r.skills))t.push({skillName:i.name,marketId:e.id,pluginId:r.id,entry:i});return t.sort((e,r)=>{let i=e.marketId.localeCompare(r.marketId);if(i!==0)return i;let s=e.pluginId.localeCompare(r.pluginId);return s!==0?s:e.skillName.localeCompare(r.skillName)}),t}async function an(n){return (await ln()).filter(e=>e.skillName===n)}async function Pr(n,t,e){let i=(await R()).markets[n];if(!i)return;let s=i.plugins[t];if(!s)return;let o=s.skills[e];if(o)return {skillName:o.name,marketId:n,pluginId:t,entry:o}}async function br(n,t,e){let r=await R(),i=r.markets[n];if(!i)return false;let s=i.plugins[t];return !s||!(e in s.skills)?false:(delete s.skills[e],await B(r),true)}async function cn(n){let t=await an(n);if(t.length===0)return [];let e=await R(),r=[];for(let i of t){let s=e.markets[i.marketId]?.plugins[i.pluginId];s&&n in s.skills&&(delete s.skills[n],r.push(i));}return r.length>0&&await B(e),r}async function Lr(n,t,e,r,i,s,o){await ut([{skillName:n,parsed:t,sourceKey:e,sourcePath:r,storePath:i,skillPath:s,...o&&{computedHash:o}}]);}async function ut(n){if(n.length===0)return;let t=await R(),e=new Date().toISOString();for(let r of n){let i=r.sourceKey,s=en(r.parsed,r.skillPath,r.pluginName),o=`${i}:${s}`,l=t.markets[i];if(!l){let u=r.parsed.type==="local"?r.parsed.localPath??r.parsed.url:ft(r.parsed);l={id:i,type:r.parsed.type,url:r.parsed.url,localPath:r.parsed.localPath,subpath:r.parsed.subpath,ref:r.parsed.ref,storePath:r.storePath,cachePath:u,addedAt:e,plugins:{}},t.markets[i]=l;}let a=l.plugins[o];a||(a={id:o,name:s,sourcePath:r.parsed.subpath,skills:{}},l.plugins[o]=a);let c={name:r.skillName,description:r.description??"",skillPath:r.skillPath,computedHash:r.computedHash};r.scope&&(c.scope=r.scope),a.skills[r.skillName]=c;}await B(t);}async function vr(n){return (await cn(n)).length>0}async function un(n,t){let e;try{e=await Kt.fetchAllSkills(n);}catch{return}if(e.length!==0)for(let r of e)try{await fn(r,t);}catch{}}async function fn(n,t){let e=utils.Filesystem.join(t,n.installName),r=utils.Filesystem.normalize(e),i=utils.Filesystem.normalize(t);if(!r.startsWith(`${i}/`)&&r!==i)throw new Error(`Unsafe skill dir: ${n.installName}`);await promises.mkdir(h(e),{recursive:true});for(let[s,o]of n.files){let l=utils.Filesystem.join(e,s),a=utils.Filesystem.normalize(l);if(!a.startsWith(`${r}/`)&&a!==r||s.includes("\0"))continue;let c=path.dirname(h(l));c!==h(e)&&await promises.mkdir(c,{recursive:true}),await promises.writeFile(h(l),typeof o=="string"?o:Buffer.from(o));}}async function Ir(n){return (await Qt({type:"git",url:n.url,ref:n.ref})).tempDir}async function $r(n,t={}){let e=Yt(n),r=false;if(fs.existsSync(e)&&(r=await te(e),!r))try{await promises.rmdir(h(e));}catch{}if(r){let a=await it(e,void 0,{includeInternal:t.includeInternal,fullDepth:t.fullDepth});if(a.length>0){let u=await Promise.all(a.map(async f=>{let k=ot(e,f.path);return {skillName:f.name,parsed:n,sourceKey:at(n),sourcePath:e,storePath:e,skillPath:k,description:f.description,scope:Bt(f.metadata?.scope),...f.pluginName&&{pluginName:f.pluginName},computedHash:await lt(f.path)}}));await ut(u);}let c=n.type==="local"?"local-cp":"cache-pull";return {storeDir:e,cacheHit:true,source:c,skills:a,blobSkills:[],cloneError:null}}let i=await Qt(n);await utils.Filesystem.mkdir(h(e),{recursive:true}).catch(()=>{});let s=await it(i.tempDir,void 0,{includeInternal:t.includeInternal,fullDepth:t.fullDepth}),o=[],l=utils.Filesystem.normalize(e).replace(/\\/g,"/");for(let a of s){let c=ot(i.tempDir,a.path),u=utils.Filesystem.join(e,c),f=`${ot(i.tempDir,a.path)}/SKILL.md`,k=utils.Filesystem.normalize(u).replace(/\\/g,"/"),E="/",P=l.endsWith(E)?l:l+E;if(!k.startsWith(P)&&k!==l)throw new Error(`[INVARIANT 0048-yyy] cp target escapes storeRoot: target=${k} storeRoot=${l}
20
+ source skill path=${a.path} (parsed.type=${n.type})
21
+ \u4E1A\u52A1\u4EFB\u4F55\u65F6\u5019\u4E0D\u80FD\u64CD\u4F5C\u7528\u6237\u7684 local \u76EE\u5F55\u6216\u6587\u4EF6\u3002`);let g;try{await utils.Filesystem.mkdir(h(utils.Filesystem.dirname(u)),{recursive:!0}),await promises.cp(h(a.path),h(u),{recursive:!0}),g=await lt(u);}catch{}a.path=u,o.push({skill:a,skillRel:c,sourceSkillPath:f,targetPath:u,computedHash:g});}if(o.length>0){let a=o.filter(c=>c.computedHash).map(c=>({skillName:c.skill.name,parsed:n,sourceKey:at(n),sourcePath:i.tempDir,storePath:e,skillPath:c.skillRel,description:c.skill.description,scope:Bt(c.skill.metadata?.scope),...c.skill.pluginName&&{pluginName:c.skill.pluginName},computedHash:c.computedHash}));await ut(a);}return {storeDir:e,cacheHit:i.cacheHit,source:i.source,skills:s,blobSkills:[],cloneError:i.cloneError??null}}function ot(n,t){let r=utils.Filesystem.normalize(n).replace(/\\/g,"/"),i=utils.Filesystem.normalize(t).replace(/\\/g,"/"),s=r.toLowerCase();return i.toLowerCase().startsWith(`${s}/`)?i.slice(s.length+1):""}async function te(n){try{return (await promises.readdir(h(n))).length>0}catch{return false}}function Ar(n){try{let t=utils.Filesystem.normalize(n);for(let e of [N(),C()]){let r=utils.Filesystem.normalize(e);if(t===r||t.startsWith(`${r}/`))return !0}return !1}catch{return false}}async function Rr({cachePath:n,skillName:t,scope:e}){let r=utils.Filesystem.join(tn({scope:e}),t);return fs.existsSync(r)&&await promises.rm(h(r),{recursive:true,force:true}),await promises.cp(h(n),h(r),{recursive:true}),r}async function Wr(n){let t=ft(n);fs.existsSync(t)&&await promises.rm(h(t),{recursive:true,force:true});}async function Kr(){let n=N();fs.existsSync(n)&&await promises.rm(h(n),{recursive:true,force:true});}var mn="skills-lock.json",re=4;function ie(n){return path.join(n||process.cwd(),mn)}function _r(n,t){return n?yt(n,C(),t):null}async function V(n){let t=ie(n);try{let e=await promises.readFile(t,"utf-8"),r=JSON.parse(e);return typeof r.version!="number"||!r.skills||r.version<re?dt():r}catch{return dt()}}async function se(n,t){let e=ie(t),r={};for(let o of Object.keys(n.skills).sort())r[o]=n.skills[o];let i={version:n.version,skills:r},s=JSON.stringify(i,null,2)+`
22
+ `;await promises.writeFile(e,s,"utf-8");}async function lt(n){let t=[];await oe(n,n,t),t.sort((r,i)=>r.relativePath.localeCompare(i.relativePath));let e=crypto.createHash("sha256");for(let r of t)e.update(r.relativePath),e.update(r.content);return e.digest("hex")}async function oe(n,t,e){let r=await promises.readdir(t,{withFileTypes:true});await Promise.all(r.map(async i=>{let s=path.join(t,i.name);if(i.isDirectory()){if(i.name===".git"||i.name==="node_modules")return;await oe(n,s,e);}else if(i.isFile()){let o=await promises.readFile(s),l=path.relative(n,s).split("\\").join("/");e.push({relativePath:l,content:o});}}));}async function Or(n,t,e){let r=await V(e),i=new Date().toISOString(),s=r.skills[n];r.skills[n]={...t,installedAt:s?.installedAt??i,updatedAt:i},await se(r,e);}async function jr(n,t){let e=await V(t);return n in e.skills?(delete e.skills[n],await se(e,t),true):false}function dt(){return {version:re,skills:{}}}exports.$=cn;exports.A=Ge;exports.B=it;exports.C=Be;exports.D=er;exports.E=nr;exports.F=rr;exports.G=st;exports.H=Sr;exports.I=Qe;exports.J=tn;exports.K=C;exports.L=Zt;exports.M=at;exports.N=Yt;exports.O=N;exports.P=en;exports.Q=ft;exports.R=Qt;exports.S=ct;exports.T=R;exports.U=B;exports.V=xr;exports.W=Er;exports.X=ln;exports.Y=an;exports.Z=Pr;exports._=br;exports.a=Y;exports.aa=Lr;exports.b=Wn;exports.ba=ut;exports.c=Kn;exports.ca=vr;exports.d=_;exports.da=Ir;exports.e=At;exports.ea=$r;exports.f=Et;exports.fa=ot;exports.g=L;exports.ga=te;exports.h=ye;exports.ha=Ar;exports.i=Se;exports.ia=Rr;exports.j=vt;exports.ja=Wr;exports.k=It;exports.ka=Kr;exports.l=vn;exports.m=Q;exports.n=Kt;exports.o=K;exports.p=yt;exports.q=re;exports.r=ie;exports.s=_r;exports.t=V;exports.u=se;exports.v=lt;exports.w=Or;exports.x=jr;exports.y=Ve;exports.z=Ct;