skilless 0.0.4 → 0.0.5

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 (2) hide show
  1. package/dist/bin.mjs +4 -4
  2. package/package.json +1 -1
package/dist/bin.mjs CHANGED
@@ -79,7 +79,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
79
79
  `:``;return rl(S.dirname(n)),a.appendFileSync(n,`${c}${s}${o.join(`
80
80
  `)}\n`,`utf8`),!0}function vl(e,t){let n=hl(e);if(!n||!R(n))return;let r=new Set(t),i=a.readFileSync(n,`utf8`).split(`
81
81
  `).filter(e=>!r.has(e.trim()));a.writeFileSync(n,i.join(`
82
- `),`utf8`)}const yl=process.env.SKILLESS_HOME?S.resolve(process.env.SKILLESS_HOME):S.join(s.homedir(),`.skilless`),bl=S.join(yl,`skills`),xl=S.join(yl,`auth.json`),Sl=S.join(yl,`state.json`),Cl=S.join(yl,`cache.json`),wl=S.join(yl,`sources.json`),Tl=S.join(yl,`pending.json`),El=S.join(yl,`config.json`),Dl=S.join(yl,`conflicts`);function Ol(e){return S.join(bl,e)}const kl=`.agents/skills`,Al=`.claude/skills`;function jl(){return process.env.CLAUDE_CONFIG_DIR?S.resolve(process.env.CLAUDE_CONFIG_DIR):S.join(s.homedir(),`.claude`)}function Ml(){return S.join(s.homedir(),kl)}function Nl(){return S.join(jl(),`skills`)}function Pl(){let e=ol(Cl,{});return{version:1,library:e.library?.map(e=>({...e,source:e.source??null}))??null,projects:e.projects??{}}}function Fl(e){let t=Pl();t.library=e.map(({name:e,contentHash:t,editedAt:n,updatedAt:r,global:i,source:a})=>({name:e,contentHash:t,editedAt:n,updatedAt:r,global:i,source:a})),sl(Cl,t)}function Il(e,t){let n=Pl();n.projects[e]=t.filter(e=>!e.global).map(e=>e.name),sl(Cl,n)}const Ll=`SKILL.md`,Rl=new Set([`.git`,`node_modules`,`.DS_Store`,`.skilless.json`]),zl=/^[a-z0-9][a-z0-9._-]*$/;function Bl(e){return Rl.has(e)}function Vl(e){return e.length<=64&&zl.test(e)}function Hl(e){if(!Vl(e))throw new L(`${e} is not a valid skill name.`,{suggestion:`Use lowercase letters, digits, dots, dashes and underscores, starting with a letter or digit.`})}function Ul(e){let t=c.createHash(`sha256`);for(let n of[...e].sort((e,t)=>e.path.localeCompare(t.path)))t.update(n.path),t.update(`\0`),t.update(n.contents),t.update(`\0`);return t.digest(`hex`)}function Wl(e,t){if(!R(S.join(e,Ll)))throw new L(`${t} has no ${Ll}.`,{suggestion:`Every skill needs a ${Ll} at its root.`});let n=il(e,Bl),r=[],i=0,o=0;for(let s of n){let n=S.join(e,s),c=a.readFileSync(n);if(c.includes(0))throw new L(`${t}/${s} looks like a binary file.`,{suggestion:`v0 syncs text only. Remove the file or keep it outside the skill.`});if(o+=c.byteLength,o>1048576)throw new L(`${t} is larger than 1MB.`,{suggestion:`Skills are prose. Move large assets out of the skill directory.`});r.push({path:s,contents:c.toString(`utf8`)}),i=Math.max(i,a.statSync(n).mtimeMs)}return{name:t,dir:e,files:r,contentHash:Ul(r),editedAt:i}}function Gl(e,t,n){let r=Ol(e);z(r),rl(r);for(let e of t)al(S.join(r,e.path),e.contents);if(n!==void 0){let e=new Date(n);for(let n of t)a.utimesSync(S.join(r,n.path),e,e)}}function Kl(){return R(bl)?a.readdirSync(bl,{withFileTypes:!0}).filter(e=>e.isDirectory()&&!Bl(e.name)).map(e=>e.name).sort():[]}function ql(){return Kl().map(e=>Wl(Ol(e),e))}function Jl(e){let t=Ol(e);return R(t)?Wl(t,e):null}function Yl(e,t){return[{path:Ll,contents:`---\nname: ${e}\ndescription: ${t}\n---\n\n# ${e}\n\nDescribe what this skill does and when an agent should reach for it.\n`}]}function Xl(e){return{agents:S.join(e,kl),claude:S.join(e,Al),repo:e}}function Zl(){return{agents:Ml(),claude:Nl(),repo:null}}function Ql(e){return typeof e==`string`?Xl(e):e}const $l=`.agents/skills/.skilless.json`;function eu(e){let t;try{t=S.normalize(a.realpathSync(e))}catch{t=S.normalize(e)}return process.platform===`win32`?t.toLowerCase():t}function tu(e,t){try{return eu(S.resolve(S.dirname(e),a.readlinkSync(e)))===eu(t)}catch{return!1}}function nu(e,t){let n=S.join(e.agents,t);return tu(n,Ol(t))?!0:tu(S.join(e.claude,t),n)}function ru(e){let t=Ql(e);return R(t.agents)?a.readdirSync(t.agents).filter(e=>!e.startsWith(`.`)).filter(e=>nu(t,e)).sort():[]}function iu(e){return R(e.claude)&&eu(e.claude)===eu(e.agents)}function au(e,t){let n=S.join(e.agents,t),r=S.join(e.claude,t),i=[];return R(n)&&!nu(e,t)&&i.push(n),!iu(e)&&R(r)&&!tu(r,n)&&i.push(r),i}function ou(e){return e.flatMap(e=>[`/${kl}/${e}`,`/${Al}/${e}`])}function su(e,t){process.platform===`win32`?a.symlinkSync(S.resolve(S.dirname(t),e),t,`junction`):a.symlinkSync(e,t,`dir`)}function cu(e,t,n){rl(S.dirname(t));try{su(e,t)}catch{n()}}function lu(e,t,n){let r=Ql(e),{repo:i}=r;i&&z(S.join(i,$l));let a=[],o=[];for(let e of t){if(i&&(gl(i,`${kl}/${e.name}`)||gl(i,`${Al}/${e.name}`))){o.push({name:e.name,reason:`tracked`});continue}let t=au(r,e.name);if(t.length>0){o.push({name:e.name,reason:`occupied`,...i?{}:{user:!0},occupied:{paths:t,scope:r,skill:e}});continue}uu(r,e,n),a.push(e.name)}return i&&(vl(i,[`/${$l}`]),_l(i,ou(ru(r)))),{written:a,skipped:o}}function uu(e,t,n){let r=S.join(e.agents,t.name),i=S.join(e.claude,t.name),a=!iu(e);if(z(r),a&&z(i),n.copy){rl(r);for(let e of t.files??[])al(S.join(r,e.path),e.contents)}else{let e=Ol(t.name);cu(e,r,()=>cl(e,r))}a&&cu(S.relative(S.dirname(i),r),i,()=>cl(r,i))}function du(e,t){if(!e.occupied)return;let{scope:n,skill:r,paths:i}=e.occupied;for(let e of i)z(e);uu(n,r,t),n.repo&&_l(n.repo,ou([r.name]))}function fu(e,t){let n=Ql(e),r=[];for(let e of t){if(!nu(n,e))continue;let t=S.join(n.agents,e),i=S.join(n.claude,e);!iu(n)&&tu(i,t)&&z(i),z(t),r.push(e)}return n.repo&&vl(n.repo,ou(r)),r}function pu(e){let t=Ql(e),n=ru(t).filter(e=>!a.existsSync(S.join(t.agents,e)));return n.length===0?[]:fu(t,n)}function mu(e){return ul(e)??e}function hu(){return process.env.SKILLESS_TOKEN||ol(xl,{}).token}function gu(e){sl(xl,{token:e},384)}function _u(){z(xl)}function vu(){return(process.env.SKILLESS_API_URL??`https://skilless.dev`).replace(/\/$/,``)}function yu(){let e=hu()??``,t=l(`sha256`).update(e).digest(`hex`).slice(0,16);return`${vu()}#${t}`}function bu(){let e=ol(Sl,{}),t=yu();return e.remote===t?{version:1,remote:t,skills:e.skills??{}}:{version:1,remote:t,skills:{}}}function xu(e){sl(Sl,{...e,remote:yu()})}function Su(e){return e??!R(bl)}async function Cu(e,t,n={}){let r=Su(n.copy),i=[];if(!r){let e=bu();for(let n of t)Jl(n.name)||(Gl(n.name,n.files,n.editedAt),e.skills[n.name]={contentHash:n.contentHash,editedAt:n.editedAt,syncedAt:Date.now()},i.push(n.name));xu(e)}let a=lu(e,t,{copy:r}),o=n.reconcile?fu(e,ru(e).filter(e=>!t.some(t=>t.name===e))):[];return{...a,fetched:i,removed:o}}async function wu(e,t,n){let r=pu(e),i=new Set(ru(e)),a=await Cu(e,t,{copy:n.copy,reconcile:!0});return{...a,pruned:r,added:a.written.filter(e=>!i.has(e))}}async function Tu(e,t,n,r={}){let i=await e.getBindings(n);return Il(n,i),Eu(t,i,r)}async function Eu(e,t,n={}){let r=await wu(e,t.filter(e=>!e.global),n),i=await wu(Zl(),t.filter(e=>e.global),n);return{project:r,user:i,skipped:[...r.skipped,...i.skipped],count:t.length}}function Du(e){let t=Zl(),n=pu(t),r=new Set(ru(t)),i=lu(t,e.filter(e=>R(Ol(e))).map(e=>({name:e})),{copy:!1}),a=fu(t,ru(t).filter(t=>!e.includes(t)));return{...i,fetched:[],removed:a,pruned:n,added:i.written.filter(e=>!r.has(e))}}function Ou(){let e=ol(Tl,{});return{version:1,projects:e.projects??{},globals:e.globals??{},sources:e.sources??{},deletes:e.deletes??[]}}function ku(e){if(Au(e)){z(Tl);return}sl(Tl,e)}function Au(e){return Object.keys(e.projects).length===0&&Object.keys(e.globals).length===0&&Object.keys(e.sources).length===0&&e.deletes.length===0}function ju(e,t){return e.projects[t]??={add:[],remove:[]},e.projects[t]}function Mu(e,t){let n=Ou(),r=ju(n,e);r.add=[...new Set([...r.add,...t])],r.remove=r.remove.filter(e=>!t.includes(e)),ku(n)}function Nu(e,t){let n=Ou(),r=ju(n,e);r.remove=[...new Set([...r.remove,...t])],r.add=r.add.filter(e=>!t.includes(e)),ku(n)}function Pu(e,t){let n=Ou();for(let r of e)n.globals[r]=t;ku(n)}function Fu(e,t){let n=Ou();n.sources[e]=t,ku(n)}function Iu(e){let t=Ou();t.deletes=[...new Set([...t.deletes,...e])];for(let n of e)delete t.globals[n],delete t.sources[n];for(let n of Object.values(t.projects))n.add=n.add.filter(t=>!e.includes(t));ku(t)}async function Lu(e){let t=Ou();if(Au(t))return 0;let n=new Set((await e.listSkills()).map(e=>e.name)),r=e=>Kl().includes(e),i=0;for(let r of[...t.deletes])n.has(r)&&(await e.deleteSkill(r),n.delete(r),i++),t.deletes=t.deletes.filter(e=>e!==r),ku(t);for(let[a,o]of Object.entries(t.globals)){if(n.has(a))await e.setGlobal(a,o),i++;else if(r(a))continue;delete t.globals[a],ku(t)}for(let[a,o]of Object.entries(t.sources)){if(n.has(a))await e.setSource(a,o),i++;else if(r(a))continue;delete t.sources[a],ku(t)}for(let[n,a]of Object.entries(t.projects)){let o=(await e.getBindings(n)).filter(e=>!e.global).map(e=>e.name),s=[...new Set([...o,...a.add])].filter(e=>!a.remove.includes(e)),c=await e.setBindings(n,s),l=new Set(c.unknown);i+=a.add.filter(e=>!l.has(e)).length+a.remove.length,a.add=a.add.filter(e=>l.has(e)&&r(e)),a.remove=[],a.add.length===0&&delete t.projects[n],ku(t)}return i}function Ru(){return ol(wl,{}).skills??{}}function zu(e){if(Object.keys(e).length===0){z(wl);return}sl(wl,{version:1,skills:e})}function Bu(e,t){return e?.url===t?.url&&e?.ref===t?.ref&&e?.path===t?.path&&e?.hash===t?.hash}function Vu(e,t){let n=Ru();Bu(n[e],t)||(t?n[e]=t:delete n[e],zu(n),Fu(e,t))}function Hu(e){let t=Ru();for(let n of e)delete t[n];zu(t)}function Uu(e){let t=Ru(),n=Ou().sources,r=new Set(e.map(e=>e.name)),i=new Set(Kl());for(let r of e)r.name in n||(r.source?t[r.name]=r.source:delete t[r.name]);for(let e of Object.keys(t))!r.has(e)&&!i.has(e)&&!(e in n)&&delete t[e];zu(t)}async function B(e){await e.try(e=>Lu(e))}async function Wu(e){let t=await e.try(e=>e.listSkills());t&&(Fl(t),Uu(t));let n=t??Pl().library??[],r=Ou(),i=bu(),a=Ru(),o=new Map(ql().map(e=>[e.name,e])),s=new Map(n.map(e=>[e.name,e]));return{entries:[...new Set([...o.keys(),...s.keys()])].filter(e=>!r.deletes.includes(e)).sort().map(e=>{let t=o.get(e)??null,n=s.get(e)??null;return{name:e,global:r.globals[e]??n?.global??!1,local:t,remote:n,unsynced:t!==null&&i.skills[e]?.contentHash!==t.contentHash,source:a[e]??null}}),live:t!==void 0}}async function Gu(e,t){let n=await e.try(e=>e.getBindings(t));n&&Il(t,n);let r=n?n.filter(e=>!e.global).map(e=>e.name):Pl().projects[t]??[],i=Ou(),a=i.projects[t]??{add:[],remove:[]};return[...new Set([...r,...a.add])].filter(e=>!a.remove.includes(e)&&!i.deletes.includes(e)).sort()}function Ku(e,t){let n=new Set(t);return e.entries.filter(e=>e.global||n.has(e.name))}async function qu(e,t,n,r={}){let i=await e.try(e=>e.getBindings(n));if(i)return Il(n,i),{...await Eu(t,i,{copy:r.copy}),missing:[]};let a=Ku(await Wu(e),await Gu(e,n)),o=a.filter(e=>!e.global),s=a.filter(e=>e.global),c=Ou(),l=new Set(c.deletes),u=e=>Ju(c,e),d=Su(r.copy),f=Yu(t,o,new Set([...c.projects[n]?.remove??[],...l,...u(!0)]),d),p=Yu(Zl(),s,new Set([...l,...u(!1)]),d);return{project:f,user:p,skipped:[...f.skipped,...p.skipped],missing:a.filter(e=>!e.local).map(e=>e.name)}}function Ju(e,t){return Object.entries(e.globals).filter(([,e])=>e===t).map(([e])=>e)}function Yu(e,t,n,r){let i=new Set(t.map(e=>e.name));pu(e);let a=fu(e,ru(e).filter(e=>n.has(e)&&!i.has(e)));return{...lu(e,t.flatMap(e=>e.local?[e.local]:[]),{copy:r}),removed:a}}async function Xu(e){let t=await Wu(e),n=t.entries.filter(e=>e.global),r=n.filter(e=>!e.local).map(e=>e.name);if(t.live)return{...Du(n.map(e=>e.name)),missing:r};let i=Ou(),a=new Set([...i.deletes,...Ju(i,!1)]);return{...Yu(Zl(),n,a,!1),missing:r}}async function Zu(e,t,n,r=new Map){let i=bu();for(let a of t){Vu(a.name,r.get(a.name)??null),Gl(a.name,a.files,a.editedAt);let t=await e.try(e=>e.putSkill(a.name,a.files,a.editedAt)),o=n.get(a.name)?.remote;t?i.skills[a.name]={contentHash:a.contentHash,editedAt:a.editedAt,syncedAt:Date.now()}:o?i.skills[a.name]={contentHash:o.contentHash,editedAt:o.editedAt,syncedAt:Date.now()}:delete i.skills[a.name]}return xu(i),await B(e),t.map(e=>e.name)}var Qu=v(((e,t)=>{let n=typeof process<`u`&&process.env.TERM_PROGRAM===`Hyper`,r=typeof process<`u`&&process.platform===`win32`,i=typeof process<`u`&&process.platform===`linux`,a={ballotDisabled:`☒`,ballotOff:`☐`,ballotOn:`☑`,bullet:`•`,bulletWhite:`◦`,fullBlock:`█`,heart:`❤`,identicalTo:`≡`,line:`─`,mark:`※`,middot:`·`,minus:`-`,multiplication:`×`,obelus:`÷`,pencilDownRight:`✎`,pencilRight:`✏`,pencilUpRight:`✐`,percent:`%`,pilcrow2:`❡`,pilcrow:`¶`,plusMinus:`±`,question:`?`,section:`§`,starsOff:`☆`,starsOn:`★`,upDownArrow:`↕`},o=Object.assign({},a,{check:`√`,cross:`×`,ellipsisLarge:`...`,ellipsis:`...`,info:`i`,questionSmall:`?`,pointer:`>`,pointerSmall:`»`,radioOff:`( )`,radioOn:`(*)`,warning:`‼`}),s=Object.assign({},a,{ballotCross:`✘`,check:`✔`,cross:`✖`,ellipsisLarge:`⋯`,ellipsis:`…`,info:`ℹ`,questionFull:`?`,questionSmall:`﹖`,pointer:i?`▸`:`❯`,pointerSmall:i?`‣`:`›`,radioOff:`◯`,radioOn:`◉`,warning:`⚠`});t.exports=r&&!n?o:s,Reflect.defineProperty(t.exports,`common`,{enumerable:!1,value:a}),Reflect.defineProperty(t.exports,`windows`,{enumerable:!1,value:o}),Reflect.defineProperty(t.exports,`other`,{enumerable:!1,value:s})})),$u=v(((e,t)=>{let n=e=>typeof e==`object`&&!!e&&!Array.isArray(e),r=/[\u001b\u009b][[\]#;?()]*(?:(?:(?:[^\W_]*;?[^\W_]*)\u0007)|(?:(?:[0-9]{1,4}(;[0-9]{0,4})*)?[~0-9=<>cf-nqrtyA-PRZ]))/g,i=()=>typeof process<`u`?process.env.FORCE_COLOR!==`0`:!1,a=()=>{let e={enabled:i(),visible:!0,styles:{},keys:{}},t=e=>{let t=e.open=`\u001b[${e.codes[0]}m`,n=e.close=`\u001b[${e.codes[1]}m`,r=e.regex=RegExp(`\\u001b\\[${e.codes[1]}m`,`g`);return e.wrap=(e,i)=>{e.includes(n)&&(e=e.replace(r,n+t));let a=t+e+n;return i?a.replace(/\r*\n/g,`${n}$&${t}`):a},e},a=(e,t,n)=>typeof e==`function`?e(t):e.wrap(t,n),o=(t,n)=>{if(t===``||t==null)return``;if(e.enabled===!1)return t;if(e.visible===!1)return``;let r=``+t,i=r.includes(`
82
+ `),`utf8`)}const yl=process.env.SKILLESS_HOME?S.resolve(process.env.SKILLESS_HOME):S.join(s.homedir(),`.skilless`),bl=S.join(yl,`skills`),xl=S.join(yl,`auth.json`),Sl=S.join(yl,`state.json`),Cl=S.join(yl,`cache.json`),wl=S.join(yl,`sources.json`),Tl=S.join(yl,`pending.json`),El=S.join(yl,`config.json`),Dl=S.join(yl,`conflicts`);function Ol(e){return S.join(bl,e)}const kl=`.agents/skills`,Al=`.claude/skills`;function jl(){return process.env.CLAUDE_CONFIG_DIR?S.resolve(process.env.CLAUDE_CONFIG_DIR):S.join(s.homedir(),`.claude`)}function Ml(){return S.join(s.homedir(),kl)}function Nl(){return S.join(jl(),`skills`)}function Pl(){let e=ol(Cl,{});return{version:1,library:e.library?.map(e=>({...e,source:e.source??null}))??null,projects:e.projects??{}}}function Fl(e){let t=Pl();t.library=e.map(({name:e,contentHash:t,editedAt:n,updatedAt:r,global:i,source:a})=>({name:e,contentHash:t,editedAt:n,updatedAt:r,global:i,source:a})),sl(Cl,t)}function Il(e,t){let n=Pl();n.projects[e]=t.filter(e=>!e.global).map(e=>e.name),sl(Cl,n)}const Ll=`SKILL.md`,Rl=new Set([`.git`,`node_modules`,`.DS_Store`,`.skilless.json`]),zl=/^[a-z0-9][a-z0-9._-]*$/;function Bl(e){return Rl.has(e)}function Vl(e){return e.length<=64&&zl.test(e)}function Hl(e){if(!Vl(e))throw new L(`${e} is not a valid skill name.`,{suggestion:`Use lowercase letters, digits, dots, dashes and underscores, starting with a letter or digit.`})}function Ul(e){let t=c.createHash(`sha256`);for(let n of[...e].sort((e,t)=>e.path.localeCompare(t.path)))t.update(n.path),t.update(`\0`),t.update(n.contents),t.update(`\0`);return t.digest(`hex`)}function Wl(e,t){if(!R(S.join(e,Ll)))throw new L(`${t} has no ${Ll}.`,{suggestion:`Every skill needs a ${Ll} at its root.`});let n=il(e,Bl),r=[],i=0,o=0;for(let s of n){let n=S.join(e,s),c=a.readFileSync(n);if(c.includes(0))throw new L(`${t}/${s} looks like a binary file.`,{suggestion:`v0 syncs text only. Remove the file or keep it outside the skill.`});if(o+=c.byteLength,o>1048576)throw new L(`${t} is larger than 1MB.`,{suggestion:`Skills are prose. Move large assets out of the skill directory.`});r.push({path:s,contents:c.toString(`utf8`)}),i=Math.max(i,a.statSync(n).mtimeMs)}return{name:t,dir:e,files:r,contentHash:Ul(r),editedAt:i}}function Gl(e,t,n){let r=Ol(e);z(r),rl(r);for(let e of t)al(S.join(r,e.path),e.contents);if(n!==void 0){let e=new Date(n);for(let n of t)a.utimesSync(S.join(r,n.path),e,e)}}function Kl(){return R(bl)?a.readdirSync(bl,{withFileTypes:!0}).filter(e=>e.isDirectory()&&!Bl(e.name)).map(e=>e.name).sort():[]}function ql(){return Kl().map(e=>Wl(Ol(e),e))}function Jl(e){let t=Ol(e);return R(t)?Wl(t,e):null}function Yl(e,t){return[{path:Ll,contents:`---\nname: ${e}\ndescription: ${t}\n---\n\n# ${e}\n\nDescribe what this skill does and when an agent should reach for it.\n`}]}function Xl(e){return{agents:S.join(e,kl),claude:S.join(e,Al),repo:e}}function Zl(){return{agents:Ml(),claude:Nl(),repo:null}}function Ql(e){return typeof e==`string`?Xl(e):e}const $l=`.agents/skills/.skilless.json`;function eu(e){let t;try{t=S.normalize(a.realpathSync(e))}catch{t=S.normalize(e)}return process.platform===`win32`?t.toLowerCase():t}function tu(e,t){try{return eu(S.resolve(S.dirname(e),a.readlinkSync(e)))===eu(t)}catch{return!1}}function nu(e,t){let n=S.join(e.agents,t);return tu(n,Ol(t))?!0:tu(S.join(e.claude,t),n)}function ru(e){let t=Ql(e);return R(t.agents)?a.readdirSync(t.agents).filter(e=>!e.startsWith(`.`)).filter(e=>nu(t,e)).sort():[]}function iu(e){return R(e.claude)&&eu(e.claude)===eu(e.agents)}function au(e,t){let n=S.join(e.agents,t),r=S.join(e.claude,t),i=[];return R(n)&&!nu(e,t)&&i.push(n),!iu(e)&&R(r)&&!tu(r,n)&&i.push(r),i}function ou(e){return e.flatMap(e=>[`/${kl}/${e}`,`/${Al}/${e}`])}function su(e,t){process.platform===`win32`?a.symlinkSync(S.resolve(S.dirname(t),e),t,`junction`):a.symlinkSync(e,t,`dir`)}function cu(e,t,n){rl(S.dirname(t));try{su(e,t)}catch{n()}}function lu(e,t,n){let r=Ql(e),{repo:i}=r;i&&z(S.join(i,$l));let a=[],o=[];for(let e of t){if(i&&(gl(i,`${kl}/${e.name}`)||gl(i,`${Al}/${e.name}`))){o.push({name:e.name,reason:`tracked`});continue}let t=au(r,e.name);if(t.length>0){o.push({name:e.name,reason:`occupied`,...i?{}:{user:!0},occupied:{paths:t,scope:r,skill:e}});continue}uu(r,e,n),a.push(e.name)}return i&&(vl(i,[`/${$l}`]),_l(i,ou(ru(r)))),{written:a,skipped:o}}function uu(e,t,n){let r=S.join(e.agents,t.name),i=S.join(e.claude,t.name),a=!iu(e);if(z(r),a&&z(i),n.copy){rl(r);for(let e of t.files??[])al(S.join(r,e.path),e.contents)}else{let e=Ol(t.name);cu(e,r,()=>cl(e,r))}a&&cu(S.relative(S.dirname(i),r),i,()=>cl(r,i))}function du(e,t){if(!e.occupied)return;let{scope:n,skill:r,paths:i}=e.occupied;for(let e of i)z(e);uu(n,r,t),n.repo&&_l(n.repo,ou([r.name]))}function fu(e,t){let n=Ql(e),r=[];for(let e of t){if(!nu(n,e))continue;let t=S.join(n.agents,e),i=S.join(n.claude,e);!iu(n)&&tu(i,t)&&z(i),z(t),r.push(e)}return n.repo&&vl(n.repo,ou(r)),r}function pu(e){let t=Ql(e),n=ru(t).filter(e=>!a.existsSync(S.join(t.agents,e)));return n.length===0?[]:fu(t,n)}function mu(e){return ul(e)??e}function hu(){return process.env.SKILLESS_TOKEN||ol(xl,{}).token}function gu(e){sl(xl,{token:e},384)}function _u(){z(xl)}function vu(){return(process.env.SKILLESS_API_URL??`https://skilless.dev`).replace(/\/$/,``)}function yu(){let e=hu()??``,t=l(`sha256`).update(e).digest(`hex`).slice(0,16);return`${vu()}#${t}`}function bu(){let e=ol(Sl,{}),t=yu();return e.remote===t?{version:1,remote:t,skills:e.skills??{}}:{version:1,remote:t,skills:{}}}function xu(e){sl(Sl,{...e,remote:yu()})}function Su(e){return e??!R(bl)}async function Cu(e,t,n={}){let r=Su(n.copy),i=[];if(!r){let e=bu();for(let n of t)Jl(n.name)||(Gl(n.name,n.files,n.editedAt),e.skills[n.name]={contentHash:n.contentHash,editedAt:n.editedAt,syncedAt:Date.now()},i.push(n.name));xu(e)}let a=lu(e,t,{copy:r}),o=n.reconcile?fu(e,ru(e).filter(e=>!t.some(t=>t.name===e))):[];return{...a,fetched:i,removed:o}}async function wu(e,t,n){let r=pu(e),i=new Set(ru(e)),a=await Cu(e,t,{copy:n.copy,reconcile:!0});return{...a,pruned:r,added:a.written.filter(e=>!i.has(e))}}async function Tu(e,t,n,r={}){let i=await e.getBindings(n);return Il(n,i),Eu(t,i,r)}async function Eu(e,t,n={}){let r=await wu(e,t.filter(e=>!e.global),n),i=await wu(Zl(),t.filter(e=>e.global),n);return{project:r,user:i,skipped:[...r.skipped,...i.skipped],count:t.length}}function Du(e){let t=Zl(),n=pu(t),r=new Set(ru(t)),i=lu(t,e.filter(e=>R(Ol(e))).map(e=>({name:e})),{copy:!1}),a=fu(t,ru(t).filter(t=>!e.includes(t)));return{...i,fetched:[],removed:a,pruned:n,added:i.written.filter(e=>!r.has(e))}}function Ou(){let e=ol(Tl,{});return{version:1,projects:e.projects??{},globals:e.globals??{},sources:e.sources??{},deletes:e.deletes??[]}}function ku(e){if(Au(e)){z(Tl);return}sl(Tl,e)}function Au(e){return Object.keys(e.projects).length===0&&Object.keys(e.globals).length===0&&Object.keys(e.sources).length===0&&e.deletes.length===0}function ju(e,t){return e.projects[t]??={add:[],remove:[]},e.projects[t]}function Mu(e,t){let n=Ou(),r=ju(n,e);r.add=[...new Set([...r.add,...t])],r.remove=r.remove.filter(e=>!t.includes(e)),ku(n)}function Nu(e,t){let n=Ou(),r=ju(n,e);r.remove=[...new Set([...r.remove,...t])],r.add=r.add.filter(e=>!t.includes(e)),ku(n)}function Pu(e,t){let n=Ou();for(let r of e)n.globals[r]=t;ku(n)}function Fu(e,t){let n=Ou();n.sources[e]=t,ku(n)}function Iu(e){let t=Ou();t.deletes=[...new Set([...t.deletes,...e])];for(let n of e)delete t.globals[n],delete t.sources[n];for(let n of Object.values(t.projects))n.add=n.add.filter(t=>!e.includes(t));ku(t)}async function Lu(e,t){let n=Ou();if(Au(n))return 0;let r=new Set((t??await e.listSkills()).map(e=>e.name)),i=e=>Kl().includes(e),a=0;for(let t of[...n.deletes])r.has(t)&&(await e.deleteSkill(t),r.delete(t),a++),n.deletes=n.deletes.filter(e=>e!==t),ku(n);for(let[t,o]of Object.entries(n.globals)){if(r.has(t))await e.setGlobal(t,o),a++;else if(i(t))continue;delete n.globals[t],ku(n)}for(let[t,o]of Object.entries(n.sources)){if(r.has(t))await e.setSource(t,o),a++;else if(i(t))continue;delete n.sources[t],ku(n)}for(let[t,r]of Object.entries(n.projects)){let o=(await e.getBindings(t)).filter(e=>!e.global).map(e=>e.name),s=[...new Set([...o,...r.add])].filter(e=>!r.remove.includes(e)),c=await e.setBindings(t,s),l=new Set(c.unknown);a+=r.add.filter(e=>!l.has(e)).length+r.remove.length,r.add=r.add.filter(e=>l.has(e)&&i(e)),r.remove=[],r.add.length===0&&delete n.projects[t],ku(n)}return a}function Ru(){return ol(wl,{}).skills??{}}function zu(e){if(Object.keys(e).length===0){z(wl);return}sl(wl,{version:1,skills:e})}function Bu(e,t){return e?.url===t?.url&&e?.ref===t?.ref&&e?.path===t?.path&&e?.hash===t?.hash}function Vu(e,t){let n=Ru();Bu(n[e],t)||(t?n[e]=t:delete n[e],zu(n),Fu(e,t))}function Hu(e){let t=Ru();for(let n of e)delete t[n];zu(t)}function Uu(e){let t=Ru(),n=Ou().sources,r=new Set(e.map(e=>e.name)),i=new Set(Kl());for(let r of e)r.name in n||(r.source?t[r.name]=r.source:delete t[r.name]);for(let e of Object.keys(t))!r.has(e)&&!i.has(e)&&!(e in n)&&delete t[e];zu(t)}async function B(e){await e.try(e=>Lu(e))}async function Wu(e){let t=await e.try(e=>e.listSkills());t&&(Fl(t),Uu(t));let n=t??Pl().library??[],r=Ou(),i=bu(),a=Ru(),o=new Map(ql().map(e=>[e.name,e])),s=new Map(n.map(e=>[e.name,e]));return{entries:[...new Set([...o.keys(),...s.keys()])].filter(e=>!r.deletes.includes(e)).sort().map(e=>{let t=o.get(e)??null,n=s.get(e)??null;return{name:e,global:r.globals[e]??n?.global??!1,local:t,remote:n,unsynced:t!==null&&i.skills[e]?.contentHash!==t.contentHash,source:a[e]??null}}),live:t!==void 0}}async function Gu(e,t){let n=await e.try(e=>e.getBindings(t));n&&Il(t,n);let r=n?n.filter(e=>!e.global).map(e=>e.name):Pl().projects[t]??[],i=Ou(),a=i.projects[t]??{add:[],remove:[]};return[...new Set([...r,...a.add])].filter(e=>!a.remove.includes(e)&&!i.deletes.includes(e)).sort()}function Ku(e,t){let n=new Set(t);return e.entries.filter(e=>e.global||n.has(e.name))}async function qu(e,t,n,r={}){let i=await e.try(e=>e.getBindings(n));if(i)return Il(n,i),{...await Eu(t,i,{copy:r.copy}),missing:[]};let a=Ku(await Wu(e),await Gu(e,n)),o=a.filter(e=>!e.global),s=a.filter(e=>e.global),c=Ou(),l=new Set(c.deletes),u=e=>Ju(c,e),d=Su(r.copy),f=Yu(t,o,new Set([...c.projects[n]?.remove??[],...l,...u(!0)]),d),p=Yu(Zl(),s,new Set([...l,...u(!1)]),d);return{project:f,user:p,skipped:[...f.skipped,...p.skipped],missing:a.filter(e=>!e.local).map(e=>e.name)}}function Ju(e,t){return Object.entries(e.globals).filter(([,e])=>e===t).map(([e])=>e)}function Yu(e,t,n,r){let i=new Set(t.map(e=>e.name));pu(e);let a=fu(e,ru(e).filter(e=>n.has(e)&&!i.has(e)));return{...lu(e,t.flatMap(e=>e.local?[e.local]:[]),{copy:r}),removed:a}}async function Xu(e){let t=await Wu(e),n=t.entries.filter(e=>e.global),r=n.filter(e=>!e.local).map(e=>e.name);if(t.live)return{...Du(n.map(e=>e.name)),missing:r};let i=Ou(),a=new Set([...i.deletes,...Ju(i,!1)]);return{...Yu(Zl(),n,a,!1),missing:r}}async function Zu(e,t,n,r=new Map){let i=bu();for(let a of t){Vu(a.name,r.get(a.name)??null),Gl(a.name,a.files,a.editedAt);let t=await e.try(e=>e.putSkill(a.name,a.files,a.editedAt)),o=n.get(a.name)?.remote;t?i.skills[a.name]={contentHash:a.contentHash,editedAt:a.editedAt,syncedAt:Date.now()}:o?i.skills[a.name]={contentHash:o.contentHash,editedAt:o.editedAt,syncedAt:Date.now()}:delete i.skills[a.name]}return xu(i),await B(e),t.map(e=>e.name)}var Qu=v(((e,t)=>{let n=typeof process<`u`&&process.env.TERM_PROGRAM===`Hyper`,r=typeof process<`u`&&process.platform===`win32`,i=typeof process<`u`&&process.platform===`linux`,a={ballotDisabled:`☒`,ballotOff:`☐`,ballotOn:`☑`,bullet:`•`,bulletWhite:`◦`,fullBlock:`█`,heart:`❤`,identicalTo:`≡`,line:`─`,mark:`※`,middot:`·`,minus:`-`,multiplication:`×`,obelus:`÷`,pencilDownRight:`✎`,pencilRight:`✏`,pencilUpRight:`✐`,percent:`%`,pilcrow2:`❡`,pilcrow:`¶`,plusMinus:`±`,question:`?`,section:`§`,starsOff:`☆`,starsOn:`★`,upDownArrow:`↕`},o=Object.assign({},a,{check:`√`,cross:`×`,ellipsisLarge:`...`,ellipsis:`...`,info:`i`,questionSmall:`?`,pointer:`>`,pointerSmall:`»`,radioOff:`( )`,radioOn:`(*)`,warning:`‼`}),s=Object.assign({},a,{ballotCross:`✘`,check:`✔`,cross:`✖`,ellipsisLarge:`⋯`,ellipsis:`…`,info:`ℹ`,questionFull:`?`,questionSmall:`﹖`,pointer:i?`▸`:`❯`,pointerSmall:i?`‣`:`›`,radioOff:`◯`,radioOn:`◉`,warning:`⚠`});t.exports=r&&!n?o:s,Reflect.defineProperty(t.exports,`common`,{enumerable:!1,value:a}),Reflect.defineProperty(t.exports,`windows`,{enumerable:!1,value:o}),Reflect.defineProperty(t.exports,`other`,{enumerable:!1,value:s})})),$u=v(((e,t)=>{let n=e=>typeof e==`object`&&!!e&&!Array.isArray(e),r=/[\u001b\u009b][[\]#;?()]*(?:(?:(?:[^\W_]*;?[^\W_]*)\u0007)|(?:(?:[0-9]{1,4}(;[0-9]{0,4})*)?[~0-9=<>cf-nqrtyA-PRZ]))/g,i=()=>typeof process<`u`?process.env.FORCE_COLOR!==`0`:!1,a=()=>{let e={enabled:i(),visible:!0,styles:{},keys:{}},t=e=>{let t=e.open=`\u001b[${e.codes[0]}m`,n=e.close=`\u001b[${e.codes[1]}m`,r=e.regex=RegExp(`\\u001b\\[${e.codes[1]}m`,`g`);return e.wrap=(e,i)=>{e.includes(n)&&(e=e.replace(r,n+t));let a=t+e+n;return i?a.replace(/\r*\n/g,`${n}$&${t}`):a},e},a=(e,t,n)=>typeof e==`function`?e(t):e.wrap(t,n),o=(t,n)=>{if(t===``||t==null)return``;if(e.enabled===!1)return t;if(e.visible===!1)return``;let r=``+t,i=r.includes(`
83
83
  `),o=n.length;for(o>0&&n.includes(`unstyle`)&&(n=[...new Set([`unstyle`,...n])].reverse());o-- >0;)r=a(e.styles[n[o]],r,i);return r},s=(n,r,i)=>{e.styles[n]=t({name:n,codes:r}),(e.keys[i]||(e.keys[i]=[])).push(n),Reflect.defineProperty(e,n,{configurable:!0,enumerable:!0,set(t){e.alias(n,t)},get(){let t=e=>o(e,t.stack);return Reflect.setPrototypeOf(t,e),t.stack=this.stack?this.stack.concat(n):[n],t}})};return s(`reset`,[0,0],`modifier`),s(`bold`,[1,22],`modifier`),s(`dim`,[2,22],`modifier`),s(`italic`,[3,23],`modifier`),s(`underline`,[4,24],`modifier`),s(`inverse`,[7,27],`modifier`),s(`hidden`,[8,28],`modifier`),s(`strikethrough`,[9,29],`modifier`),s(`black`,[30,39],`color`),s(`red`,[31,39],`color`),s(`green`,[32,39],`color`),s(`yellow`,[33,39],`color`),s(`blue`,[34,39],`color`),s(`magenta`,[35,39],`color`),s(`cyan`,[36,39],`color`),s(`white`,[37,39],`color`),s(`gray`,[90,39],`color`),s(`grey`,[90,39],`color`),s(`bgBlack`,[40,49],`bg`),s(`bgRed`,[41,49],`bg`),s(`bgGreen`,[42,49],`bg`),s(`bgYellow`,[43,49],`bg`),s(`bgBlue`,[44,49],`bg`),s(`bgMagenta`,[45,49],`bg`),s(`bgCyan`,[46,49],`bg`),s(`bgWhite`,[47,49],`bg`),s(`blackBright`,[90,39],`bright`),s(`redBright`,[91,39],`bright`),s(`greenBright`,[92,39],`bright`),s(`yellowBright`,[93,39],`bright`),s(`blueBright`,[94,39],`bright`),s(`magentaBright`,[95,39],`bright`),s(`cyanBright`,[96,39],`bright`),s(`whiteBright`,[97,39],`bright`),s(`bgBlackBright`,[100,49],`bgBright`),s(`bgRedBright`,[101,49],`bgBright`),s(`bgGreenBright`,[102,49],`bgBright`),s(`bgYellowBright`,[103,49],`bgBright`),s(`bgBlueBright`,[104,49],`bgBright`),s(`bgMagentaBright`,[105,49],`bgBright`),s(`bgCyanBright`,[106,49],`bgBright`),s(`bgWhiteBright`,[107,49],`bgBright`),e.ansiRegex=r,e.hasColor=e.hasAnsi=t=>(e.ansiRegex.lastIndex=0,typeof t==`string`&&t!==``&&e.ansiRegex.test(t)),e.alias=(t,n)=>{let r=typeof n==`string`?e[n]:n;if(typeof r!=`function`)throw TypeError(`Expected alias to be the name of an existing color (string) or a function`);r.stack||=(Reflect.defineProperty(r,`name`,{value:t}),e.styles[t]=r,[t]),Reflect.defineProperty(e,t,{configurable:!0,enumerable:!0,set(n){e.alias(t,n)},get(){let t=e=>o(e,t.stack);return Reflect.setPrototypeOf(t,e),t.stack=this.stack?this.stack.concat(r.stack):r.stack,t}})},e.theme=t=>{if(!n(t))throw TypeError(`Expected theme to be an object`);for(let n of Object.keys(t))e.alias(n,t[n]);return e},e.alias(`unstyle`,t=>typeof t==`string`&&t!==``?(e.ansiRegex.lastIndex=0,t.replace(e.ansiRegex,``)):``),e.alias(`noop`,e=>e),e.none=e.clear=e.noop,e.stripColor=e.unstyle,e.symbols=Qu(),e.define=s,e};t.exports=a(),t.exports.create=a})),V=v((e=>{let t=Object.prototype.toString,n=$u(),r=!1,i=new Set,a={yellow:`blue`,cyan:`red`,green:`magenta`,black:`white`,blue:`yellow`,red:`cyan`,magenta:`green`,white:`black`};e.longest=(e,t)=>e.reduce((e,n)=>Math.max(e,t?n[t].length:n.length),0),e.hasColor=e=>!!e&&n.hasColor(e);let o=e.isObject=e=>typeof e==`object`&&!!e&&!Array.isArray(e);e.nativeType=e=>t.call(e).slice(8,-1).toLowerCase().replace(/\s/g,``),e.isAsyncFn=t=>e.nativeType(t)===`asyncfunction`,e.isPrimitive=e=>e!=null&&typeof e!=`object`&&typeof e!=`function`,e.resolve=(e,t,...n)=>typeof t==`function`?t.call(e,...n):t,e.scrollDown=(e=[])=>[...e.slice(1),e[0]],e.scrollUp=(e=[])=>[e.pop(),...e],e.reorder=(e=[])=>{let t=e.slice();return t.sort((e,t)=>e.index>t.index?1:e.index<t.index?-1:0),t},e.swap=(e,t,n)=>{let r=e.length,i=n===r?0:n<0?r-1:n,a=e[t];e[t]=e[i],e[i]=a},e.width=(e,t=80)=>{let n=e&&e.columns?e.columns:t;return e&&typeof e.getWindowSize==`function`&&(n=e.getWindowSize()[0]),process.platform===`win32`?n-1:n},e.height=(e,t=20)=>{let n=e&&e.rows?e.rows:t;return e&&typeof e.getWindowSize==`function`&&(n=e.getWindowSize()[1]),n},e.wordWrap=(e,t={})=>{if(!e)return e;typeof t==`number`&&(t={width:t});let{indent:n=``,newline:r=`
84
84
  `+n,width:i=80}=t,a=(r+n).match(/[^\S\n]/g)||[];i-=a.length;let o=`.{1,${i}}([\\s\\u200B]+|$)|[^\\s\\u200B]+?([\\s\\u200B]+|$)`,s=e.trim(),c=new RegExp(o,`g`),l=s.match(c)||[];return l=l.map(e=>e.replace(/\n$/,``)),t.padEnd&&(l=l.map(e=>e.padEnd(i,` `))),t.padStart&&(l=l.map(e=>e.padStart(i,` `))),n+l.join(r)},e.unmute=e=>{let t=e.stack.find(e=>n.keys.color.includes(e));return t?n[t]:e.stack.find(e=>e.slice(2)===`bg`)?n[t.slice(2)]:e=>e},e.pascal=e=>e?e[0].toUpperCase()+e.slice(1):``,e.inverse=t=>{if(!t||!t.stack)return t;let r=t.stack.find(e=>n.keys.color.includes(e));if(r){let i=n[`bg`+e.pascal(r)];return i?i.black:t}let i=t.stack.find(e=>e.slice(0,2)===`bg`);return i?n[i.slice(2).toLowerCase()]||t:n.none},e.complement=t=>{if(!t||!t.stack)return t;let r=t.stack.find(e=>n.keys.color.includes(e)),i=t.stack.find(e=>e.slice(0,2)===`bg`);if(r&&!i)return n[a[r]||r];if(i){let r=a[i.slice(2).toLowerCase()];return r&&n[`bg`+e.pascal(r)]||t}return n.none},e.meridiem=e=>{let t=e.getHours(),n=e.getMinutes(),r=t>=12?`pm`:`am`;t%=12;let i=t===0?12:t,a=n<10?`0`+n:n;return i+`:`+a+` `+r},e.set=(t={},n=``,r)=>n.split(`.`).reduce((t,n,i,a)=>{let o=a.length-1>i?t[n]||{}:r;return!e.isObject(o)&&i<a.length-1&&(o={}),t[n]=o},t),e.get=(e={},t=``,n)=>(e[t]==null?t.split(`.`).reduce((e,t)=>e&&e[t],e):e[t])??n,e.mixin=(t,n)=>{if(!o(t))return n;if(!o(n))return t;for(let r of Object.keys(n)){let i=Object.getOwnPropertyDescriptor(n,r);if(hasOwnProperty.call(i,`value`))if(hasOwnProperty.call(t,r)&&o(i.value)){let a=Object.getOwnPropertyDescriptor(t,r);o(a.value)&&a.value!==i.value?t[r]=e.merge({},t[r],n[r]):Reflect.defineProperty(t,r,i)}else Reflect.defineProperty(t,r,i);else Reflect.defineProperty(t,r,i)}return t},e.merge=(...t)=>{let n={};for(let r of t)e.mixin(n,r);return n},e.mixinEmitter=(t,n)=>{let r=n.constructor.prototype;for(let i of Object.keys(r)){let a=r[i];typeof a==`function`?e.define(t,i,a.bind(n)):e.define(t,i,a)}};let s=(e,t)=>{r||(r=!0,i.forEach(e=>e()),e===!0&&process.exit(128+t))},c=s.bind(null,!0,15),l=s.bind(null,!0,2);e.onExit=e=>(i.size===0&&(process.once(`SIGTERM`,c),process.once(`SIGINT`,l),process.once(`exit`,s)),i.add(e),()=>{i.delete(e),i.size===0&&(process.off(`SIGTERM`,c),process.off(`SIGINT`,l),process.off(`exit`,s))}),e.define=(e,t,n)=>{Reflect.defineProperty(e,t,{value:n})},e.defineExport=(e,t,n)=>{let r;Reflect.defineProperty(e,t,{enumerable:!0,configurable:!0,set(e){r=e},get(){return r?r():n()}})}})),ed=v(((e,t)=>{t.exports=({onlyFirst:e=!1}={})=>{let t=[`[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)`,`(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))`].join(`|`);return new RegExp(t,e?void 0:`g`)}})),td=v(((e,t)=>{let n=ed();t.exports=e=>typeof e==`string`?e.replace(n(),``):e})),nd=v((e=>{e.ctrl={a:`first`,b:`backward`,c:`cancel`,d:`deleteForward`,e:`last`,f:`forward`,g:`reset`,i:`tab`,k:`cutForward`,l:`reset`,n:`newItem`,m:`cancel`,j:`submit`,p:`search`,r:`remove`,s:`save`,u:`undo`,w:`cutLeft`,x:`toggleCursor`,v:`paste`},e.shift={up:`shiftUp`,down:`shiftDown`,left:`shiftLeft`,right:`shiftRight`,tab:`prev`},e.fn={up:`pageUp`,down:`pageDown`,left:`pageLeft`,right:`pageRight`,delete:`deleteForward`},e.option={b:`backward`,f:`forward`,d:`cutRight`,left:`cutLeft`,up:`altUp`,down:`altDown`},e.keys={pageup:`pageUp`,pagedown:`pageDown`,home:`home`,end:`end`,cancel:`cancel`,delete:`deleteForward`,backspace:`delete`,down:`down`,enter:`submit`,escape:`cancel`,left:`left`,space:`space`,number:`number`,return:`submit`,right:`right`,tab:`next`,up:`up`}})),rd=v(((e,t)=>{t.exports=class{_queue=[];_executing=!1;_jobRunner=null;constructor(e){this._jobRunner=e}enqueue=(...e)=>{this._queue.push(e),this._dequeue()};destroy(){this._queue.length=0,this._jobRunner=null}_dequeue(){this._executing||!this._queue.length||(this._executing=!0,this._jobRunner(...this._queue.shift()),setTimeout(()=>{this._executing=!1,this._dequeue()}))}}})),id=v(((e,t)=>{let n=y(`readline`),r=nd(),i=rd(),a=/^(?:\x1b)([a-zA-Z0-9])$/,o=/^(?:\x1b+)(O|N|\[|\[\[)(?:(\d+)(?:;(\d+))?([~^$])|(?:1;)?(\d+)?([a-zA-Z]))/,s={OP:`f1`,OQ:`f2`,OR:`f3`,OS:`f4`,"[11~":`f1`,"[12~":`f2`,"[13~":`f3`,"[14~":`f4`,"[[A":`f1`,"[[B":`f2`,"[[C":`f3`,"[[D":`f4`,"[[E":`f5`,"[15~":`f5`,"[17~":`f6`,"[18~":`f7`,"[19~":`f8`,"[20~":`f9`,"[21~":`f10`,"[23~":`f11`,"[24~":`f12`,"[A":`up`,"[B":`down`,"[C":`right`,"[D":`left`,"[E":`clear`,"[F":`end`,"[H":`home`,OA:`up`,OB:`down`,OC:`right`,OD:`left`,OE:`clear`,OF:`end`,OH:`home`,"[1~":`home`,"[2~":`insert`,"[3~":`delete`,"[4~":`end`,"[5~":`pageup`,"[6~":`pagedown`,"[[5~":`pageup`,"[[6~":`pagedown`,"[7~":`home`,"[8~":`end`,"[a":`up`,"[b":`down`,"[c":`right`,"[d":`left`,"[e":`clear`,"[2$":`insert`,"[3$":`delete`,"[5$":`pageup`,"[6$":`pagedown`,"[7$":`home`,"[8$":`end`,Oa:`up`,Ob:`down`,Oc:`right`,Od:`left`,Oe:`clear`,"[2^":`insert`,"[3^":`delete`,"[5^":`pageup`,"[6^":`pagedown`,"[7^":`home`,"[8^":`end`,"[Z":`tab`};function c(e){return[`[a`,`[b`,`[c`,`[d`,`[e`,`[2$`,`[3$`,`[5$`,`[6$`,`[7$`,`[8$`,`[Z`].includes(e)}function l(e){return[`Oa`,`Ob`,`Oc`,`Od`,`Oe`,`[2^`,`[3^`,`[5^`,`[6^`,`[7^`,`[8^`].includes(e)}let u=(e=``,t={})=>{let n,r={name:t.name,ctrl:!1,meta:!1,shift:!1,option:!1,sequence:e,raw:e,...t};if(Buffer.isBuffer(e)?e[0]>127&&e[1]===void 0?(e[0]-=128,e=`\x1B`+String(e)):e=String(e):e!==void 0&&typeof e!=`string`?e=String(e):e||=r.sequence||``,r.sequence=r.sequence||e||r.name,e===`\r`)r.raw=void 0,r.name=`return`;else if(e===`
85
85
  `)r.name=`enter`;else if(e===` `)r.name=`tab`;else if(e===`\b`||e===``||e===`\x1B`||e===`\x1B\b`)r.name=`backspace`,r.meta=e.charAt(0)===`\x1B`;else if(e===`\x1B`||e===`\x1B\x1B`)r.name=`escape`,r.meta=e.length===2;else if(e===` `||e===`\x1B `)r.name=`space`,r.meta=e.length===2;else if(e<=``)r.name=String.fromCharCode(e.charCodeAt(0)+97-1),r.ctrl=!0;else if(e.length===1&&e>=`0`&&e<=`9`)r.name=`number`;else if(e.length===1&&e>=`a`&&e<=`z`)r.name=e;else if(e.length===1&&e>=`A`&&e<=`Z`)r.name=e.toLowerCase(),r.shift=!0;else if(n=a.exec(e))r.meta=!0,r.shift=/^[A-Z]$/.test(n[1]);else if(n=o.exec(e)){let t=[...e];t[0]===`\x1B`&&t[1]===`\x1B`&&(r.option=!0);let i=[n[1],n[2],n[4],n[6]].filter(Boolean).join(``),a=(n[3]||n[5]||1)-1;r.ctrl=!!(a&4),r.meta=!!(a&10),r.shift=!!(a&1),r.code=i,r.name=s[i],r.shift=c(i)||r.shift,r.ctrl=l(i)||r.ctrl}return r};u.listen=(e={},t)=>{let{stdin:r}=e;if(!r||r!==process.stdin&&!r.isTTY)throw Error(`Invalid stream passed`);let a=n.createInterface({terminal:!0,input:r});n.emitKeypressEvents(r,a);let o=new i((e,n)=>t(e,u(e,n),a)),s=r.isRaw;return r.isTTY&&r.setRawMode(!0),r.on(`keypress`,o.enqueue),a.resume(),()=>{r.isTTY&&r.setRawMode(s),r.removeListener(`keypress`,o.enqueue),o.destroy(),a.pause(),a.close()}},u.action=(e,t,n)=>{let i={...r,...n};return t.ctrl?(t.action=i.ctrl[t.name],t):t.option&&i.option?(t.action=i.option[t.name],t):t.shift?(t.action=i.shift[t.name],t):(t.action=i.keys[t.name],t)},t.exports=u})),ad=v(((e,t)=>{t.exports=e=>{e.timers=e.timers||{};let t=e.options.timers;if(t)for(let r of Object.keys(t)){let i=t[r];typeof i==`number`&&(i={interval:i}),n(e,r,i)}};function n(e,t,n={}){let r=e.timers[t]={name:t,start:Date.now(),ms:0,tick:0},i=n.interval||120;r.frames=n.frames||[],r.loading=!0;let a=setInterval(()=>{r.ms=Date.now()-r.start,r.tick++,e.render()},i);return r.stop=()=>{r.loading=!1,clearInterval(a)},Reflect.defineProperty(r,`interval`,{value:a}),e.once(`close`,()=>r.stop()),r.stop}})),od=v(((e,t)=>{let{define:n,width:r}=V();t.exports=class{constructor(e){let t=e.options;n(this,`_prompt`,e),this.type=e.type,this.name=e.name,this.message=``,this.header=``,this.footer=``,this.error=``,this.hint=``,this.input=``,this.cursor=0,this.index=0,this.lines=0,this.tick=0,this.prompt=``,this.buffer=``,this.width=r(t.stdout||process.stdout),Object.assign(this,t),this.name=this.name||this.message,this.message=this.message||this.name,this.symbols=e.symbols,this.styles=e.styles,this.required=new Set,this.cancelled=!1,this.submitted=!1}clone(){let e={...this};return e.status=this.status,e.buffer=Buffer.from(e.buffer),delete e.clone,e}set color(e){this._color=e}get color(){let e=this.prompt.styles;if(this.cancelled)return e.cancelled;if(this.submitted)return e.submitted;let t=this._color||e[this.status];return typeof t==`function`?t:e.pending}set loading(e){this._loading=e}get loading(){return typeof this._loading==`boolean`?this._loading:this.loadingChoices?`choices`:!1}get status(){return this.cancelled?`cancelled`:this.submitted?`submitted`:`pending`}}})),sd=v(((e,t)=>{let n=V(),r=$u(),i={default:r.noop,noop:r.noop,set inverse(e){this._inverse=e},get inverse(){return this._inverse||n.inverse(this.primary)},set complement(e){this._complement=e},get complement(){return this._complement||n.complement(this.primary)},primary:r.cyan,success:r.green,danger:r.magenta,strong:r.bold,warning:r.yellow,muted:r.dim,disabled:r.gray,dark:r.dim.gray,underline:r.underline,set info(e){this._info=e},get info(){return this._info||this.primary},set em(e){this._em=e},get em(){return this._em||this.primary.underline},set heading(e){this._heading=e},get heading(){return this._heading||this.muted.underline},set pending(e){this._pending=e},get pending(){return this._pending||this.primary},set submitted(e){this._submitted=e},get submitted(){return this._submitted||this.success},set cancelled(e){this._cancelled=e},get cancelled(){return this._cancelled||this.danger},set typing(e){this._typing=e},get typing(){return this._typing||this.dim},set placeholder(e){this._placeholder=e},get placeholder(){return this._placeholder||this.primary.dim},set highlight(e){this._highlight=e},get highlight(){return this._highlight||this.inverse}};i.merge=(e={})=>{e.styles&&typeof e.styles.enabled==`boolean`&&(r.enabled=e.styles.enabled),e.styles&&typeof e.styles.visible==`boolean`&&(r.visible=e.styles.visible);let t=n.merge({},i,e.styles);delete t.merge;for(let e of Object.keys(r))hasOwnProperty.call(t,e)||Reflect.defineProperty(t,e,{get:()=>r[e]});for(let e of Object.keys(r.styles))hasOwnProperty.call(t,e)||Reflect.defineProperty(t,e,{get:()=>r[e]});return t},t.exports=i})),cd=v(((e,t)=>{let n=process.platform===`win32`,r=$u(),i=V(),a={...r.symbols,upDownDoubleArrow:`⇕`,upDownDoubleArrow2:`⬍`,upDownArrow:`↕`,asterisk:`*`,asterism:`⁂`,bulletWhite:`◦`,electricArrow:`⌁`,ellipsisLarge:`⋯`,ellipsisSmall:`…`,fullBlock:`█`,identicalTo:`≡`,indicator:r.symbols.check,leftAngle:`‹`,mark:`※`,minus:`−`,multiplication:`×`,obelus:`÷`,percent:`%`,pilcrow:`¶`,pilcrow2:`❡`,pencilUpRight:`✐`,pencilDownRight:`✎`,pencilRight:`✏`,plus:`+`,plusMinus:`±`,pointRight:`☞`,rightAngle:`›`,section:`§`,hexagon:{off:`⬡`,on:`⬢`,disabled:`⬢`},ballot:{on:`☑`,off:`☐`,disabled:`☒`},stars:{on:`★`,off:`☆`,disabled:`☆`},folder:{on:`▼`,off:`▶`,disabled:`▶`},prefix:{pending:r.symbols.question,submitted:r.symbols.check,cancelled:r.symbols.cross},separator:{pending:r.symbols.pointerSmall,submitted:r.symbols.middot,cancelled:r.symbols.middot},radio:{off:n?`( )`:`◯`,on:n?`(*)`:`◉`,disabled:n?`(|)`:`Ⓘ`},numbers:`⓪.①.②.③.④.⑤.⑥.⑦.⑧.⑨.⑩.⑪.⑫.⑬.⑭.⑮.⑯.⑰.⑱.⑲.⑳.㉑.㉒.㉓.㉔.㉕.㉖.㉗.㉘.㉙.㉚.㉛.㉜.㉝.㉞.㉟.㊱.㊲.㊳.㊴.㊵.㊶.㊷.㊸.㊹.㊺.㊻.㊼.㊽.㊾.㊿`.split(`.`)};a.merge=e=>{let t=i.merge({},r.symbols,a,e.symbols);return delete t.merge,t},t.exports=a})),ld=v(((e,t)=>{let n=sd(),r=cd(),i=V();t.exports=e=>{e.options=i.merge({},e.options.theme,e.options),e.symbols=r.merge(e.options),e.styles=n.merge(e.options)}})),ud=v(((e,t)=>{let n=process.env.TERM_PROGRAM===`Apple_Terminal`,r=td(),i=V(),a=t.exports=e,o=!1,s=a.code={bell:`\x07`,beep:`\x07`,beginning:`\x1B[G`,down:`\x1B[J`,esc:`\x1B[`,getPosition:`\x1B[6n`,hide:`\x1B[?25l`,line:`\x1B[2K`,lineEnd:`\x1B[K`,lineStart:`\x1B[1K`,restorePosition:`\x1B[`+(n?`8`:`u`),savePosition:`\x1B[`+(n?`7`:`s`),screen:`\x1B[2J`,show:`\x1B[?25h`,up:`\x1B[1J`},c=a.cursor={get hidden(){return o},hide(){return o=!0,s.hide},show(){return o=!1,s.show},forward:(e=1)=>`[${e}C`,backward:(e=1)=>`[${e}D`,nextLine:(e=1)=>`\x1B[E`.repeat(e),prevLine:(e=1)=>`\x1B[F`.repeat(e),up:(e=1)=>e?`[${e}A`:``,down:(e=1)=>e?`[${e}B`:``,right:(e=1)=>e?`[${e}C`:``,left:(e=1)=>e?`[${e}D`:``,to(e,t){return t?`[${t+1};${e+1}H`:`[${e+1}G`},move(e=0,t=0){let n=``;return n+=e<0?c.left(-e):e>0?c.right(e):``,n+=t<0?c.up(-t):t>0?c.down(t):``,n},strLen(e){for(var t=0,n=e.length,r=-1,i=0;i<n;i++)r=e.charCodeAt(i),r>=0&&r<=128?t+=1:t+=2;return t},restore(e={}){let{after:t,cursor:n,initial:r,input:o,prompt:s,size:c,value:l}=e;if(r=i.isPrimitive(r)?String(r):``,o=i.isPrimitive(o)?String(o):``,l=i.isPrimitive(l)?String(l):``,c){let e=a.cursor.up(c)+a.cursor.to(this.strLen(s)),t=o.length-n;return t>0&&(e+=a.cursor.left(t)),e}if(l||t){let e=!o&&r?-this.strLen(r):-this.strLen(o)+n;return t&&(e-=this.strLen(t)),o===``&&r&&!s.includes(r)&&(e+=this.strLen(r)),a.cursor.move(e)}}},l=a.erase={screen:s.screen,up:s.up,down:s.down,line:s.line,lineEnd:s.lineEnd,lineStart:s.lineStart,lines(e){let t=``;for(let n=0;n<e;n++)t+=a.erase.line+(n<e-1?a.cursor.up(1):``);return e&&(t+=a.code.beginning),t}};a.clear=(e=``,t=process.stdout.columns)=>{if(!t)return l.line+c.to(0);let n=e=>[...r(e)].length,i=e.split(/\r?\n/),a=0;for(let e of i)a+=1+Math.floor(Math.max(n(e)-1,0)/t);return(l.line+c.prevLine()).repeat(a-1)+l.line+c.to(0)}})),dd=v(((e,t)=>{let n=y(`events`),r=td(),i=id(),a=ad(),o=od(),s=ld(),c=V(),l=ud();var u=class e extends n{constructor(e={}){super(),this.name=e.name,this.type=e.type,this.options=e,s(this),a(this),this.state=new o(this),this.initial=[e.initial,e.default].find(e=>e!=null),this.stdout=e.stdout||process.stdout,this.stdin=e.stdin||process.stdin,this.scale=e.scale||1,this.term=this.options.term||process.env.TERM_PROGRAM,this.margin=f(this.options.margin),this.setMaxListeners(0),d(this)}async keypress(e,t={}){this.keypressed=!0;let n=i.action(e,i(e,t),this.options.actions);this.state.keypress=n,this.emit(`keypress`,e,n),this.emit(`state`,this.state.clone());let r=this.options[n.action]||this[n.action]||this.dispatch;if(typeof r==`function`)return await r.call(this,e,n);this.alert()}alert(){delete this.state.alert,this.options.show===!1?this.emit(`alert`):this.stdout.write(l.code.beep)}cursorHide(){this.stdout.write(l.cursor.hide());let e=c.onExit(()=>this.cursorShow());this.on(`close`,()=>{this.cursorShow(),e()})}cursorShow(){this.stdout.write(l.cursor.show())}write(e){e&&(this.stdout&&this.state.show!==!1&&this.stdout.write(e),this.state.buffer+=e)}clear(e=0){let t=this.state.buffer;this.state.buffer=``,!(!t&&!e||this.options.show===!1)&&this.stdout.write(l.cursor.down(e)+l.clear(t,this.width))}restore(){if(this.state.closed||this.options.show===!1)return;let{prompt:e,after:t,rest:n}=this.sections(),{cursor:r,initial:i=``,input:a=``,value:o=``}=this,s={after:t,cursor:r,initial:i,input:a,prompt:e,size:this.state.size=n.length,value:o},c=l.cursor.restore(s);c&&this.stdout.write(c)}sections(){let{buffer:e,input:t,prompt:n}=this.state;n=r(n);let i=r(e),a=i.indexOf(n),o=i.slice(0,a),s=i.slice(a).split(`
@@ -120,6 +120,6 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
120
120
  `),t=a-1;n=[...e.slice(0,t),`... (content truncated to fit terminal)`].join(`
121
121
  `)}this.#p(()=>this.#a.write(n))===!1&&this.#a.isTTY&&(this.#l=()=>{this.#l=void 0,this.#m()},this.#a.once(`drain`,this.#l)),this.#e=this.#C(n,r)}finally{t&&this.#p(()=>this.#a.write(`\x1B[?2026l`))}return this}start(e){if(e!==void 0&&(this.text=e),this.isSilent)return this;if(!this.isEnabled){let e=this.text?`-`:``,t=` `.repeat(this.#r.indent)+this.#y(e,this.text,this.#r.prefixText,this.#r.suffixText);return t.trim()!==``&&this.#p(()=>this.#a.write(t+`
122
122
  `)),this}return this.isSpinning?this:(this.#r.hideCursor&&Qf.hide(this.#a),this.#r.discardStdin&&o.stdin.isTTY&&(Kp.start(),this.#d=!0),this.#T(),this.render(),this.#o=setInterval(this.render.bind(this),this.interval),this)}stop(){return clearInterval(this.#o),this.#o=void 0,this.#t=-1,this.#n=0,this.#v(),this.#E(),this.#l&&=(this.#a.removeListener(`drain`,this.#l),void 0),this.isEnabled&&(this.clear(),this.#r.hideCursor&&Qf.show(this.#a)),this.#d&&(this.#d=!1,Kp.stop()),this}succeed(e){return this.stopAndPersist({symbol:cp,text:e})}fail(e){return this.stopAndPersist({symbol:up,text:e})}warn(e){return this.stopAndPersist({symbol:lp,text:e})}info(e){return this.stopAndPersist({symbol:sp,text:e})}stopAndPersist(e={}){if(this.isSilent)return this;let t=e.symbol??` `,n=e.text??this.text,r=e.prefixText??this.#r.prefixText,i=e.suffixText??this.#r.suffixText,a=this.#y(t,n,r,i)+`
123
- `;return this.stop(),this.#p(()=>this.#a.write(a)),this}};function Xp(e){return new Yp(e)}var G=ne(v(((e,t)=>{let n=process||{},r=n.argv||[],i=n.env||{},a=!(i.NO_COLOR||r.includes(`--no-color`))&&(!!i.FORCE_COLOR||r.includes(`--color`)||n.platform===`win32`||(n.stdout||{}).isTTY&&i.TERM!==`dumb`||!!i.CI),o=(e,t,n=e)=>r=>{let i=``+r,a=i.indexOf(t,e.length);return~a?e+s(i,t,n,a)+t:e+i+t},s=(e,t,n,r)=>{let i=``,a=0;do i+=e.substring(a,r)+n,a=r+t.length,r=e.indexOf(t,a);while(~r);return i+e.substring(a)},c=(e=a)=>{let t=e?o:()=>String;return{isColorSupported:e,reset:t(`\x1B[0m`,`\x1B[0m`),bold:t(`\x1B[1m`,`\x1B[22m`,`\x1B[22m\x1B[1m`),dim:t(`\x1B[2m`,`\x1B[22m`,`\x1B[22m\x1B[2m`),italic:t(`\x1B[3m`,`\x1B[23m`),underline:t(`\x1B[4m`,`\x1B[24m`),inverse:t(`\x1B[7m`,`\x1B[27m`),hidden:t(`\x1B[8m`,`\x1B[28m`),strikethrough:t(`\x1B[9m`,`\x1B[29m`),black:t(`\x1B[30m`,`\x1B[39m`),red:t(`\x1B[31m`,`\x1B[39m`),green:t(`\x1B[32m`,`\x1B[39m`),yellow:t(`\x1B[33m`,`\x1B[39m`),blue:t(`\x1B[34m`,`\x1B[39m`),magenta:t(`\x1B[35m`,`\x1B[39m`),cyan:t(`\x1B[36m`,`\x1B[39m`),white:t(`\x1B[37m`,`\x1B[39m`),gray:t(`\x1B[90m`,`\x1B[39m`),bgBlack:t(`\x1B[40m`,`\x1B[49m`),bgRed:t(`\x1B[41m`,`\x1B[49m`),bgGreen:t(`\x1B[42m`,`\x1B[49m`),bgYellow:t(`\x1B[43m`,`\x1B[49m`),bgBlue:t(`\x1B[44m`,`\x1B[49m`),bgMagenta:t(`\x1B[45m`,`\x1B[49m`),bgCyan:t(`\x1B[46m`,`\x1B[49m`),bgWhite:t(`\x1B[47m`,`\x1B[49m`),blackBright:t(`\x1B[90m`,`\x1B[39m`),redBright:t(`\x1B[91m`,`\x1B[39m`),greenBright:t(`\x1B[92m`,`\x1B[39m`),yellowBright:t(`\x1B[93m`,`\x1B[39m`),blueBright:t(`\x1B[94m`,`\x1B[39m`),magentaBright:t(`\x1B[95m`,`\x1B[39m`),cyanBright:t(`\x1B[96m`,`\x1B[39m`),whiteBright:t(`\x1B[97m`,`\x1B[39m`),bgBlackBright:t(`\x1B[100m`,`\x1B[49m`),bgRedBright:t(`\x1B[101m`,`\x1B[49m`),bgGreenBright:t(`\x1B[102m`,`\x1B[49m`),bgYellowBright:t(`\x1B[103m`,`\x1B[49m`),bgBlueBright:t(`\x1B[104m`,`\x1B[49m`),bgMagentaBright:t(`\x1B[105m`,`\x1B[49m`),bgCyanBright:t(`\x1B[106m`,`\x1B[49m`),bgWhiteBright:t(`\x1B[107m`,`\x1B[49m`)}};t.exports=c(),t.exports.createColors=c}))(),1);const Zp=Hd.default.prompt;function Qp(){process.stdout.write(`\r\x1B[0J`),process.stdin.isTTY&&process.stdin.setRawMode(!1),tm()}const $p={limit:10,up(){if(this.index>0)return this.index--,this.render();if(this.choices[0]?.index!==0)return this.scrollUp()},down(){if(this.index<this.visible.length-1)return this.index++,this.render();if(this.visible.at(-1)?.index!==this.choices.length-1)return this.scrollDown()}};async function em(e,t){cm();try{return await Zp({...e,cancel:Qp})}catch{return tm(),t}finally{lm()}}function tm(){cm(),process.stdout.write(`${G.default.yellow(`!`)} Cancelled\n`),process.exit(1)}async function nm(e,t=!1){return(await em({type:`confirm`,name:`value`,message:e,initial:t},{value:!1})).value}const rm=!!(process.stdin.isTTY&&process.stdout.isTTY);async function im(e,t={}){return(await em({type:`input`,name:`value`,message:e,initial:t.initial,validate:t.validate?e=>t.validate((e??``).trim()):void 0},{value:``})).value.trim()}async function am(e,t){return t.length===0?[]:(await em({type:`multiselect`,name:`value`,message:e,choices:t,...$p},{value:[]})).value}async function om(e,t,n){let r=n?t.findIndex(e=>e.name===n):-1;return(await em({type:`select`,name:`value`,message:e,choices:t,initial:r===-1?0:r,...$p},{value:``})).value}let K=null;function sm(e){let t=e.step%3+1;return`${e.message}${`.`.repeat(t)}${` `.repeat(3-t)}`}function cm(){K?.ora.isSpinning&&K.ora.stop()}function lm(){K&&!K.ora.isSpinning&&K.ora.start(sm(K))}async function q(e,t){if(!process.stdout.isTTY||!process.stdout.columns)return t();if(K){let n=K.message;K.message=e;try{return await t()}finally{K&&(K.message=n)}}let n={ora:Xp({stream:process.stdout,color:`cyan`,discardStdin:!1}),message:e,step:0,dots:setInterval(()=>{n.step++,n.ora.text=sm(n)},300)};K=n,lm();try{return await t()}finally{clearInterval(n.dots),cm(),K=null}}function um(e,t){let n=K?.ora.isSpinning===!0;n&&K.ora.clear(),e.write(t),n&&K.ora.render()}const dm=e=>G.default.isColorSupported?`\x1b[48;2;95;95;95m\x1b[38;2;250;250;250m${e}\x1b[39m\x1b[49m`:e,J={intro(e){um(process.stdout,`${dm(` skilless `)}${G.default.gray(` v${e}`)}\n\n`)},info(e){um(process.stdout,`${G.default.blue(`·`)} ${e}\n`)},step(e){um(process.stdout,`${G.default.green(`✓`)} ${e}\n`)},warn(e){um(process.stdout,`${G.default.yellow(`!`)} ${e}\n`)},error(e){um(process.stderr,`${G.default.red(`✖`)} ${e}\n`)},dim(e){um(process.stdout,`${G.default.gray(e)}\n`)},blank(){um(process.stdout,`
124
- `)}},fm=Cc({path:P(),contents:P()}),pm=Cc({url:P(),ref:P().optional(),path:P(),hash:P()}),mm=Cc({name:P(),contentHash:P(),editedAt:fc(),updatedAt:fc(),global:I(),source:pm.nullable().default(null)}),hm=mm.extend({files:xc(fm)}),gm=Cc({bound:xc(P()),unknown:xc(P())}),_m=Cc({error:P(),message:P().optional()}),vm=new Set([502,503,504]);function ym(e){try{return JSON.parse(e)}catch{return null}}var bm=class{#e;#t;#n=!1;constructor(e,t){this.#e=e,this.#t=t}get baseUrl(){return this.#t}async#r(e,t,n){if(this.#n)throw new tl(this.#t);let r;for(let i=0;i<2;i++){i>0&&await new Promise(e=>setTimeout(e,500));try{let i=await fetch(`${this.#t}/api/v1${t}`,{method:e,headers:{Authorization:`Bearer ${this.#e}`,...n===void 0?{}:{"Content-Type":`application/json`}},body:n===void 0?void 0:JSON.stringify(n),signal:AbortSignal.timeout(1e4)}),a=await i.text();if(vm.has(i.status)){r=Error(`${e} ${t} returned ${i.status}.`);continue}return{status:i.status,text:a}}catch(e){r=e}}throw this.#n=!0,new tl(this.#t,r)}async#i(e,t,n,r){let i=await this.#r(e,t,r);if(i.status===401)throw new $c;if(i.status<200||i.status>=300){let n=_m.safeParse(ym(i.text));throw new L(n.success?n.data.message??n.data.error:`${e} ${t} failed with ${i.status}.`)}if(i.status===204)return n.parse(void 0);let a=n.safeParse(ym(i.text));if(!a.success)throw new L(`Unexpected response from ${e} ${t}.`,{suggestion:`This is likely a version mismatch. Try updating skilless.`});return a.data}async listSkills(){return await this.#i(`GET`,`/skills`,xc(mm))}async getSkill(e){return await this.#i(`GET`,`/skills/${encodeURIComponent(e)}`,hm.nullable())}async putSkill(e,t,n){return await this.#i(`PUT`,`/skills/${encodeURIComponent(e)}`,mm,{files:t,editedAt:n})}async setGlobal(e,t){await this.#i(`PUT`,`/skills/${encodeURIComponent(e)}/global`,_c(),{global:t})}async setSource(e,t){await this.#i(`PUT`,`/skills/${encodeURIComponent(e)}/source`,_c(),{source:t})}async deleteSkill(e){await this.#i(`DELETE`,`/skills/${encodeURIComponent(e)}`,_c())}async getBindings(e){return await this.#i(`GET`,`/projects/skills?key=${encodeURIComponent(e)}`,xc(hm))}async setBindings(e,t){return await this.#i(`PUT`,`/projects/skills`,gm,{key:e,names:t})}},xm=class{api;#e=null;constructor(){let e=hu();this.api=e?new bm(e,vu()):null}get online(){return this.api!==null&&this.#e===null}async try(e){if(!(!this.api||this.#e))try{return await e(this.api)}catch(e){if(e instanceof tl||e instanceof $c){this.#e=e;return}throw e}}report(){if(this.#e){if(J.blank(),this.#e instanceof tl){J.warn(`Couldn't reach ${this.#e.url}. Run \`skilless sync\` to sync your skills with the cloud.`);return}J.warn(`Your sign-in was rejected, so this only changed this machine.`),J.dim("Run `skilless auth` to sign in again, then `skilless sync` to sync your skills.")}}};function Sm(e){return e.includes(`/`)||e.includes(`:`)}function Cm(e){let t=e.trim(),n,r=t.indexOf(`#`);if(r>=0&&(n=t.slice(r+1)||void 0,t=t.slice(0,r)),/^ext::/i.test(t))throw new L(`The ext:: git transport is not supported.`);let i=/^(github|gitlab):(.+)$/.exec(t);i&&(t=i[1]===`gitlab`?`https://gitlab.com/${i[2]}`:i[2]??``);let a;return a=/^https?:\/\//i.test(t)?wm(t,n):/^[a-z][a-z0-9+.-]*:\/\//i.test(t)||/^[^@/\s]+@[^:/\s]+:/.test(t)?{url:t,ref:n}:Tm(t,n),a.subpath&&=Em(a.subpath),{...a,label:fl(a.url)??a.url}}function wm(e,t){let n;try{n=new URL(e)}catch{throw new L(`${e} is not a valid URL.`)}let r=n.pathname.split(`/`).filter(Boolean).map(decodeURIComponent),i=`${n.protocol}//${n.host}`;if(n.hostname===`github.com`&&r.length>=2){let[e,n,a,o,...s]=r,c=`${i}/${e}/${n?.replace(/\.git$/,``)}.git`;return(a===`tree`||a===`blob`)&&o?{url:c,ref:o,subpath:s.join(`/`)||void 0}:{url:c,ref:t}}let a=r.indexOf(`-`);return a>0&&r[a+1]===`tree`&&r[a+2]?{url:`${i}/${r.slice(0,a).join(`/`).replace(/\.git$/,``)}.git`,ref:r[a+2],subpath:r.slice(a+3).join(`/`)||void 0}:{url:e,ref:t}}function Tm(e,t){let n=/^([^/@\s]+)\/([^/@\s]+)@([^/\s]+)$/.exec(e);if(n)return{url:`https://github.com/${n[1]}/${n[2]}.git`,ref:t,skill:n[3]};let r=/^([^/\s.][^/\s]*)\/([^/\s]+?)(?:\/(.+?))?\/?$/.exec(e);if(!r)throw new L(`Can't tell where ${e} points.`,{suggestion:"Pass `owner/repo` for GitHub, or a full git URL for anywhere else."});return{url:`https://github.com/${r[1]}/${r[2]?.replace(/\.git$/,``)}.git`,ref:t,subpath:r[3]}}function Em(e){let t=e.replace(/\\/g,`/`).split(`/`).filter(Boolean);if(t.includes(`..`))throw new L(`${e} reaches outside the repository.`);return t.join(`/`)}async function Dm(e,t,r){let i=a.mkdtempSync(S.join(s.tmpdir(),`skilless-`));try{let o=[`clone`,`--depth`,`1`,`--quiet`];e.ref&&o.push(`--branch`,e.ref),o.push(`--`,e.url,i);try{await q(`Cloning ${e.label}${e.ref?`#${e.ref}`:``}`,()=>Om(o,{...process.env,GIT_TERMINAL_PROMPT:`0`,GIT_SSH_COMMAND:process.env.GIT_SSH_COMMAND??`ssh -o BatchMode=yes`}))}catch(t){if(!r.interactive)throw km(e,t);z(i),a.mkdirSync(i);try{n(`git`,o,{stdio:[`inherit`,`ignore`,`pipe`],encoding:`utf8`})}catch(t){throw km(e,t)}}return await t(i)}finally{z(i)}}function Om(e,n){return new Promise((r,i)=>{t(`git`,e,{env:n,encoding:`utf8`},(e,t,n)=>{e?i(Object.assign(e,{stderr:n})):r()})})}function km(e,t){let n=t.stderr?.trim();return new L(`Couldn't clone ${e.label}.`,{suggestion:n||`Check the address, and that you have access to the repository.`,cause:t})}const Am=new Set([`node_modules`,`.git`,`dist`,`build`,`__pycache__`]),jm=[`skills`,`skills/.curated`,`skills/.experimental`,`skills/.system`,`.agents/skills`,`.claude/skills`];function Mm(e,t){let n=t?S.join(e,t):e;if(!R(n))throw new L(`${t} does not exist in the repository.`);let r=new Map,i=e=>{let t=Im(e);r.has(t.name)||r.set(t.name,t)};if(Pm(n))return i(n),[...r.values()];Fm(n,1,i);for(let e of jm)Fm(S.join(n,e),3,i);return r.size===0&&Fm(n,5,i),[...r.values()].sort((e,t)=>e.name.localeCompare(t.name))}function Nm(e,t,n){try{let n=Em(t);if(Pm(S.join(e,n)))return{dir:S.join(e,n),path:n}}catch{}let r=Mm(e).find(e=>e.name===n);return r?{dir:r.dir,path:S.relative(e,r.dir)}:null}function Pm(e){return a.existsSync(S.join(e,Ll))}function Fm(e,t,n){let r;try{r=a.readdirSync(e,{withFileTypes:!0})}catch{return}for(let i of r.sort((e,t)=>e.name.localeCompare(t.name))){if(!i.isDirectory()||Am.has(i.name))continue;let r=S.join(e,i.name);Pm(r)?n(r):t>1&&Fm(r,t-1,n)}}function Im(e){let t=Lm(a.readFileSync(S.join(e,Ll),`utf8`)),n=t.name?.toLowerCase().replace(/[\s_]+/g,`-`);return{name:n&&Vl(n)?n:S.basename(e).toLowerCase(),dir:e,description:t.description}}function Lm(e){let t=/^---\r?\n([\s\S]*?)\r?\n---/.exec(e)?.[1];if(!t)return{};let n=e=>{let n=RegExp(`^${e}:[ \\t]*(.+)$`,`m`).exec(t)?.[1]?.trim();if(!(!n||n===`|`||n===`>`))return n.replace(/^(['"])(.*)\1$/,`$2`)};return{name:n(`name`),description:n(`description`)}}var Rm=`skilless`,zm=`Author skills once, sync them everywhere, install them per project.`;const Y=`0.0.4`,Bm=Rm,Vm=zm,Hm=`SKILLESS_TRACE`,Um=Cc({cwd:P()}),X={cwd:new x(`--cwd <path>`,`The current working directory.`).default(process.cwd()),yes:new x(`-y, --yes`,`Skip confirmation prompts.`).default(!1),project:new x(`--project <key>`,`Override the project key. Defaults to the normalized git remote.`)};function Z(e,t){let n=e.safeParse(t);return n.success?n.data:Wm(new L(`Invalid options.`,{suggestion:n.error.issues.map(e=>` ${e.message}`).join(`
125
- `)}))}function Wm(e){process.env[Hm]===`1`?console.trace(e):J.error(G.default.red(e.toString())),process.exit(1)}async function Q(e){try{return await e()}catch(e){return e instanceof L?Wm(e):Wm(new L(e instanceof Error?e.message:String(e),{suggestion:`Run with ${Hm}=1 for a stack trace.`,cause:e}))}}function Gm(){let e=hu();if(!e)throw new $c;return new bm(e,vu())}function Km(e,t){if(t)return t;let n=pl(e);if(!n)throw new el;return n}const qm=`~/.agents/skills`;function Jm(e){let t=S.normalize(s.homedir());return e===t||e.startsWith(`${t}/`)?`~${e.slice(t.length)}`:e}async function Ym(e,t={}){for(let n of e.skipped){if(n.reason===`tracked`){J.warn(`\`${n.name}\` is tracked by git here, so it was left alone.`);continue}let e=(n.occupied?.paths??[]).map(Jm).join(` and `);if(!(t.yes||rm&&await nm(`Overwrite ${e}?`,!1))){rm?J.dim(`Kept ${e}, so ${n.name} is not linked there.`):(J.warn(`Skipped ${n.name}: ${e} was not made by skilless.`),J.dim(` Run this in a terminal to overwrite it, or pass --yes.`));continue}du(n,{copy:Su(t.copy)}),J.step(`Overwrote ${e}.`)}for(let t of e.missing??[])J.warn(`${t} is not on this machine yet, so it will be linked on the next sync.`)}const Xm=Um.extend({project:P().optional(),copy:I().optional(),global:I().optional(),notGlobal:I().optional(),overwrite:I(),yes:I()}),Zm=new b(`add`).description(`Add skills to this project, from your library or from a git repository.`).argument(`[skills...]`,"Skills to add, or a repo (`owner/repo` or any git URL) then the skills to take from it. Omit the skills to pick from a list.").option(`-g, --global`,`Make these skills global: linked once into ~/.agents/skills and ~/.claude/skills, so every project has them, including cloud agents.`).option(`--not-global`,`Stop treating these skills as global, and unlink them from your user-level skills.`).option(`--copy`,`Write real files instead of symlinking into the store.`).option(`--overwrite`,`From a repo: replace library skills of the same name.`,!1).addOption(X.yes).addOption(X.project).addOption(X.cwd).action(async(e,t)=>{let n=Z(Xm,t);J.intro(Y),await Q(async()=>{let t=new xm,[r,...i]=e;if(r&&Sm(r)){await eh(t,Cm(r),i,n);return}let a=e.find(Sm);if(a)throw new L(`${a} is a repository, not a skill.`,{suggestion:`Name the repository first: \`skilless add ${a} <skills...>\`.`});let{entries:o,live:s}=await q(`Loading your library`,async()=>(await B(t),Wu(t))),c=e=>s||e.local!==null,l=e=>{let t=o.filter(t=>e.includes(t.name)&&!c(t)).map(e=>e.name);if(t.length!==0)throw new L(`${t.join(`, `)} ${t.length===1?`is`:`are`} not on this machine, and the server can't be reached to fetch ${t.length===1?`it`:`them`}.`,{suggestion:"Run `skilless sync` once you are back online, then try again."})},u=new Set(o.map(e=>e.name)),d=e.filter(e=>!u.has(e));if(d.length>0)throw new L(`Not in your library: ${d.join(`, `)}`,{suggestion:"Run `skilless list` to see what you have."});if(n.global||n.notGlobal){let r=n.global===!0,i=e;if(i.length===0){let e=o.filter(e=>e.global!==r&&(!r||c(e)));if(e.length===0){J.info(r?`Every skill in your library is already global.`:`No skills in your library are global.`);return}if(i=await am(r?`Make global`:`Stop being global`,e.map(e=>({name:e.name}))),i.length===0){J.info(`Nothing selected.`);return}}r&&l(i),await Qm(t,i,r,n),t.report();return}let f=Km(n.cwd,n.project),p=new Set(await q(`Loading ${f}`,()=>Gu(t,f))),m=e;if(m.length===0){let e=o.filter(e=>!p.has(e.name)&&c(e));if(e.length===0){J.info(s?`Every skill in your library is already in this project.`:`Every skill on this machine is already in this project.`),t.report();return}if(m=await am(`Add to ${f}`,e.map(e=>({name:e.name}))),m.length===0){J.info(`Nothing selected.`);return}}let h=o.filter(e=>e.global).map(e=>e.name);l(m.filter(e=>!h.includes(e))),await $m(t,f,m,h,n),t.report()})});async function Qm(e,t,n,r){Pu(t,n),await q(`Saving to skilless.dev`,()=>B(e));for(let e of t)J.step(n?`${e} is now global, so every project has it.`:`${e} is no longer global.`);let i=r.project??pl(r.cwd),a=mu(r.cwd),[o,s]=await q(`Updating your skills`,async()=>{if(!i){let t=await Xu(e);return[t,t]}let t=await qu(e,a,i,{copy:r.copy});return[t,t.user]});for(let e of s.written.filter(e=>t.includes(e)))J.dim(`Linked ${e} into ${qm}.`);for(let e of s.removed)J.dim(`Unlinked ${e} from ${qm}.`);if(`project`in o){for(let e of o.project.removed)J.dim(`Moved ${e} out of this project.`);for(let e of o.project.written.filter(e=>t.includes(e)))J.dim(`${e} is still added to this project, so it is linked here again.`)}await Ym(o,r)}async function $m(e,t,n,r,i){for(let e of n)r.includes(e)&&J.dim(`${e} is global, so it is already in this project.`);let a=n.filter(e=>!r.includes(e));Mu(t,a);let o=mu(i.cwd),s=await q(`Updating this project`,async()=>(await B(e),qu(e,o,t,{copy:i.copy})));for(let e of a)J.step(`Added ${e} to this project.`);await Ym(s,i)}async function eh(e,t,n,r){if(r.notGlobal)throw new L(`--not-global only applies to skills already in your library.`);let i=r.global?null:r.project??pl(r.cwd),a=await q(`Loading your library`,async()=>(await B(e),Wu(e))),o=new Map(a.entries.map(e=>[e.name,e])),s=[...n,...t.skill?[t.skill]:[]],c=await Dm(t,async e=>{let n=Mm(e,t.subpath);if(n.length===0)throw new L(`No skills found in ${t.label}.`,{suggestion:`A skill is a directory containing a SKILL.md.`});let i=n;if(s.length>0){let e=e=>n.find(t=>t.name===e.toLowerCase()||t.dir.split(`/`).at(-1)?.toLowerCase()===e.toLowerCase()),r=s.filter(t=>!e(t));if(r.length>0)throw new L(`Not in ${t.label}: ${r.join(`, `)}`,{suggestion:`It has: ${n.map(e=>e.name).join(`, `)}`});i=[...new Set(s.map(t=>e(t)))]}else if(n.length>1&&!r.yes){if(!rm)throw new L(`${t.label} has ${n.length} skills.`,{suggestion:`Name the ones you want after the repository, or pass --yes for all of them: ${n.map(e=>e.name).join(`, `)}`});let e=await am(`Add from ${t.label}`,n.map(e=>({name:e.name,hint:th(e.description)})));i=n.filter(t=>e.includes(t.name))}let a=[];for(let t of i)try{Hl(t.name),a.push({skill:Wl(t.dir,t.name),path:S.relative(e,t.dir)})}catch(e){J.warn(`Skipped ${t.name}: ${e instanceof L?e.message:e}`)}return a},{interactive:rm});if(c.length===0){J.info(`Nothing selected.`),e.report();return}let l=[],u=[],d=new Map;for(let{skill:e,path:n}of c){d.set(e.name,{url:t.url,...t.ref?{ref:t.ref}:{},path:n,hash:e.contentHash});let i=o.get(e.name),a=i?.local?.contentHash??i?.remote?.contentHash;if(!i||a===e.contentHash){i?Vu(e.name,d.get(e.name)):l.push(e),u.push(e.name);continue}if(!(r.overwrite||rm&&!r.yes&&await nm(`${e.name} is already in your library. Replace it with the one from ${t.label}?`))){J.warn(`Kept your own ${e.name}. Pass --overwrite to replace it.`);continue}l.push(e),u.push(e.name)}let f=await q(`Saving ${l.length} skill(s) to your library`,()=>Zu(e,l,o,d));for(let e of f)J.step(`Copied ${e} into your library from ${t.label}.`);if(u.length===0){e.report();return}r.global?await Qm(e,u,!0,r):i?await $m(e,i,u,(await q(`Loading your library`,()=>Wu(e))).entries.filter(e=>e.global).map(e=>e.name),r):(J.blank(),J.dim(`This directory has no git remote, so ${u.length===1?`it is`:`they are`} only in your library. Run \`skilless add ${u[0]}\` inside a project to add ${u.length===1?`it`:`them`} there.`)),e.report()}function th(e){if(e)return e.length>60?`${e.slice(0,57)}...`:e}function nh(e){switch(process.platform){case`darwin`:return[`open`,[e]];case`win32`:return[`rundll32`,[`url.dll,FileProtocolHandler`,e]];default:return[`xdg-open`,[e]]}}function rh(e){let[t,n]=nh(e);try{let e=r(t,n,{stdio:`ignore`,detached:!0,windowsHide:!0});e.on(`error`,()=>{}),e.unref()}catch{}}async function ih(){let e=c.randomBytes(16).toString(`hex`),t=vu(),n=new URL(t).origin,r={"Access-Control-Allow-Origin":n,"Access-Control-Allow-Methods":`POST, OPTIONS`,"Access-Control-Allow-Headers":`Content-Type`,"Access-Control-Allow-Private-Network":`true`},i,a=new Promise((e,t)=>{i={resolve:e,reject:t}}),o=f.createServer((t,n)=>{if(t.method===`OPTIONS`){n.writeHead(204,r),n.end();return}if(t.method!==`POST`){n.writeHead(405,r),n.end();return}let a=``;t.on(`data`,e=>{a+=e}),t.on(`end`,()=>{let t;try{t=JSON.parse(a)}catch{n.writeHead(400,r),n.end();return}if(t.state!==e||!t.token){n.writeHead(400,r),n.end();return}n.writeHead(200,{...r,"Content-Type":`application/json`}),n.end(JSON.stringify({ok:!0})),i.resolve(t.token)})}),s=setTimeout(()=>{i.reject(new L(`Timed out waiting for sign in.`,{suggestion:"Run `skilless auth` again, or paste a token with `skilless auth --token <token>`."}))},3e5);try{await new Promise((e,t)=>{o.once(`error`,t),o.listen(0,`127.0.0.1`,e)});let{port:n}=o.address(),r=`${t}/cli/auth?port=${n}&state=${e}`;J.info(`Opening your browser to sign in…`),J.dim(r),J.blank(),rh(r),gu(await q(`Waiting for you to sign in`,()=>a))}finally{clearTimeout(s),o.close()}}const ah=Um.extend({logout:I(),token:P().optional()}),oh=new b(`auth`).description(`Sign in to skilless.dev, or sign out.`).addOption(new x(`--logout`,`Sign out on this machine.`).default(!1)).addOption(new x(`--token <token>`,`Save a token directly, for when the browser flow cannot reach localhost.`)).addOption(X.cwd).action(async e=>{let t=Z(ah,e);J.intro(Y),await Q(async()=>{if(t.logout){if(!hu()){J.info(`You were not signed in.`);return}_u(),J.step(`Signed out on this machine.`);return}if(t.token){gu(t.token),J.step(`Token saved. You are signed in to skilless.dev.`);return}await ih(),J.step(`Signed in to skilless.dev.`)})}),sh=s.homedir(),ch=process.env.LOCALAPPDATA??S.join(sh,`AppData`,`Local`),lh=process.env.ProgramFiles??`C:/Program Files`,$={cursor:{label:`Cursor`,cli:`cursor`,fallbacks:{darwin:[`/Applications/Cursor.app/Contents/Resources/app/bin/cursor`,`${sh}/Applications/Cursor.app/Contents/Resources/app/bin/cursor`],win32:[S.join(ch,`Programs/cursor/resources/app/bin/cursor.cmd`)],linux:[`/usr/share/cursor/bin/cursor`,`/opt/Cursor/resources/app/bin/cursor`]}},vscode:{label:`VS Code`,cli:`code`,fallbacks:{darwin:[`/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code`,`${sh}/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code`],win32:[S.join(ch,`Programs/Microsoft VS Code/bin/code.cmd`),S.join(lh,`Microsoft VS Code/bin/code.cmd`)],linux:[`/usr/share/code/bin/code`,`/snap/bin/code`]}},windsurf:{label:`Windsurf`,cli:`windsurf`,fallbacks:{darwin:[`/Applications/Windsurf.app/Contents/Resources/app/bin/windsurf`,`${sh}/Applications/Windsurf.app/Contents/Resources/app/bin/windsurf`],win32:[S.join(ch,`Programs/Windsurf/bin/windsurf.cmd`)],linux:[`/usr/share/windsurf/bin/windsurf`]}},zed:{label:`Zed`,cli:`zed`,fallbacks:{darwin:[`/Applications/Zed.app/Contents/MacOS/cli`,`${sh}/Applications/Zed.app/Contents/MacOS/cli`],win32:[S.join(ch,`Programs/Zed/bin/zed.exe`)],linux:[`${sh}/.local/bin/zed`]}},sublime:{label:`Sublime Text`,cli:`subl`,fallbacks:{darwin:[`/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl`],win32:[S.join(lh,`Sublime Text/subl.exe`)],linux:[`/opt/sublime_text/sublime_text`]}},neovim:{label:`Neovim`,cli:`nvim`,terminal:!0},vim:{label:`Vim`,cli:`vim`,terminal:!0}},uh=Object.keys($);function dh(e){return Object.hasOwn($,e)}function fh(e){let t=i(process.platform===`win32`?`where`:`which`,[e],{encoding:`utf8`,windowsHide:!0});if(t.status!==0||!t.stdout)return null;let n=t.stdout.split(/\r?\n/).map(e=>e.trim()).filter(Boolean);return process.platform===`win32`?n.find(e=>/\.(exe|cmd|bat)$/i.test(e))??n[0]??null:n[0]??null}function ph(e){let t=$[e],n=fh(t.cli);if(n)return n;let r=process.platform;return t.fallbacks?.[r]?.find(e=>R(e))??null}function mh(){return uh.filter(e=>ph(e)!==null)}function hh(e){return $[e].terminal===!0}function gh(e,t){let n=ph(e);if(!n)return Promise.reject(Error(`${$[e].label} was not found. Is \`${$[e].cli}\` on your PATH?`));let i=hh(e);return new Promise((e,a)=>{let o=r(n,[t],{cwd:S.dirname(t),stdio:i?`inherit`:`ignore`,detached:!i,windowsHide:!0,shell:process.platform===`win32`&&/\.(cmd|bat)$/i.test(n)});o.on(`error`,a),i?o.on(`exit`,()=>e()):(o.unref(),setImmediate(e))})}function _h(){let e=ol(El,{});return e.editor!==void 0&&!dh(e.editor)&&delete e.editor,e}function vh(e){sl(El,e)}function yh(e){let t={..._h(),...e};for(let e of Object.keys(t))t[e]===void 0&&delete t[e];return vh(t),t}const bh=`none`,xh=Cc({unset:I()}),Sh=new b(`editor`).description("Choose the editor `skilless create` opens a new skill in.").argument(`[editor]`,`Set it directly: ${uh.join(`, `)}.`).addOption(new x(`--unset`,`Stop opening new skills in an editor.`).default(!1)).action(async(e,t)=>{let n=Z(xh,t);J.intro(Y),await Q(async()=>{let t=_h().editor;if(n.unset){yh({editor:void 0}),J.step(`New skills will no longer open in an editor.`);return}if(e){if(!dh(e))throw new L(`${e} is not an editor skilless knows.`,{suggestion:`Pick one of: ${uh.join(`, `)}.`});yh({editor:e}),J.step(`New skills will open in ${$[e].label}.`);return}if(!rm){J.info(t?`Editor: ${$[t].label}`:`No editor set.`);return}let r=mh();if(r.length===0)throw new L(`None of the editors skilless knows are installed.`,{suggestion:`skilless looks for: ${uh.map(e=>$[e].cli).join(`, `)}.`});let i=await om(`Open new skills in`,[...r.map(e=>({name:e,message:$[e].label,hint:e===t?G.default.gray(`current`):void 0})),{name:bh,message:`None`,hint:t?void 0:G.default.gray(`current`)}],t??bh);if(i===bh){yh({editor:void 0}),J.step(`New skills will not open in an editor.`);return}dh(i)&&(yh({editor:i}),J.step(`New skills will open in ${$[i].label}.`))})}),Ch=new b(`config`).description(`View or change your skilless settings.`).addCommand(Sh).action(async()=>{J.intro(Y),await Q(async()=>{let e=_h();J.info(`editor ${e.editor?$[e.editor].label:G.default.gray(`not set`)}`),J.blank(),J.dim(`Stored in ${El}`)})}),wh=Um.extend({description:P().optional(),project:P().optional(),global:I().optional(),open:I()}),Th=new b(`create`).description(`Create a skill, add it to this project, and print the path to edit it.`).argument(`[name]`,`The name of the skill. You will be asked if you leave it out.`).option(`-d, --description <description>`,`What the skill does, for the frontmatter.`).option(`-g, --global`,`Make it global: linked once into ~/.agents/skills and ~/.claude/skills, so every project has it, including cloud agents.`).option(`--no-open`,"Do not open SKILL.md in your editor (see `skilless config editor`).").addOption(X.project).addOption(X.cwd).action(async(e,t)=>{let n=Z(wh,t);J.intro(Y),await Q(async()=>{let t=new xm,r=await q(`Loading your library`,async()=>(await B(t),Wu(t))),i=new Set(r.entries.map(e=>e.name)),a=e;if(!a){if(!rm)throw new L(`No name given.`,{suggestion:"Run `skilless create <name>`."});a=await im(`Name`,{validate:e=>e?Vl(e)?i.has(e)?`${e} already exists in your library.`:!0:`Use lowercase letters, digits, dots, dashes and underscores.`:`A name is required.`})}if(Hl(a),Jl(a))throw new L(`${a} already exists in your library.`,{suggestion:`Edit it at ${S.join(Ol(a),`SKILL.md`)}`});if(i.has(a))throw new L(`${a} already exists in your library.`,{suggestion:`Run \`skilless sync\` to bring ${a} down to this machine.`});let o=n.description??await im(`What does this skill do?`);Gl(a,Yl(a,o));let s=Wl(Ol(a),a);if(await q(`Creating ${a}`,()=>t.try(e=>e.putSkill(a,s.files,s.editedAt)))){let e=bu();e.skills[a]={contentHash:s.contentHash,editedAt:s.editedAt,syncedAt:Date.now()},xu(e)}J.step(`Created ${a} in your library.`),n.global&&Pu([a],!0);let c=n.project??pl(n.cwd);if(c){n.global||Mu(c,[a]);let e=mu(n.cwd);await Ym(await q(`Updating this project`,async()=>(await B(t),qu(t,e,c))))}else n.global?await Ym(await q(`Linking your global skills`,async()=>(await B(t),Xu(t)))):await q(`Saving to skilless.dev`,()=>B(t));n.global?J.step(`${a} is now global, so every project has it.`):c?J.step(`Added ${a} to ${c}.`):J.warn(`No git remote here, so ${a} was not added to a project.`);let l=S.join(Ol(a),`SKILL.md`),u=n.open?_h().editor:void 0,d=u&&(!hh(u)||rm);if(J.blank(),u&&d)try{J.dim(`Opening ${a} in ${$[u].label}...`),await gh(u,l)}catch(e){J.warn(e instanceof Error?e.message:String(e)),J.dim(`Edit ${a} at ${l}`)}else J.dim(`Edit ${a} at ${l}`);t.api&&J.dim("Run `skilless sync` to save your changes."),t.report()})}),Eh=Um.extend({yes:I()}),Dh=new b(`delete`).description(`Delete skills from your library, everywhere.`).argument(`<skills...>`,`Skills to delete.`).addOption(X.yes).addOption(X.cwd).action(async(e,t)=>{let n=Z(Eh,t);J.intro(Y),await Q(async()=>{let t=new xm,r=await q(`Loading your library`,async()=>(await B(t),Wu(t))),i=new Set(r.entries.map(e=>e.name)),a=e.filter(e=>!i.has(e));if(a.length>0)throw new L(`Not in your library: ${a.join(`, `)}`,{suggestion:"Run `skilless list` to see what you have."});if(J.warn(`This deletes ${e.join(`, `)} from every project, on every machine.`),J.dim(`Run \`skilless remove ${e.join(` `)}\` to take ${e.length===1?`it`:`them`} out of just this project.`),!(n.yes||await nm(`Delete ${e.join(`, `)}?`,!1))){J.info(`Nothing was deleted.`);return}Iu(e),Hu(e);let o=bu(),s=mu(n.cwd);for(let t of e)z(Ol(t)),delete o.skills[t],J.step(`Deleted ${t} from your library.`);xu(o),fu(s,e),fu(Zl(),e),await q(`Deleting from skilless.dev`,()=>B(t)),J.blank(),J.dim("Other checkouts will clean up on their next `skilless install`."),J.dim(`Restore at skilless.dev/skills within 30 days.`),t.report()})}),Oh=Um.extend({yes:I(),overwrite:I()});function kh(e){return a.readdirSync(e,{withFileTypes:!0}).filter(e=>e.isDirectory()).map(t=>({name:t.name,dir:S.join(e,t.name)})).filter(e=>R(S.join(e.dir,Ll))).sort((e,t)=>e.name.localeCompare(t.name))}const Ah=new b(`import`).description(`Import a directory of existing skills into your library.`).argument(`<dir>`,`A directory whose subdirectories each contain a SKILL.md.`).option(`--overwrite`,`Replace skills that already exist.`,!1).addOption(X.yes).addOption(X.cwd).action(async(e,t)=>{let n=Z(Oh,t);J.intro(Y),await Q(async()=>{let t=new xm,r=S.resolve(n.cwd,e);if(!R(r))throw new L(`${r} does not exist.`);let i=kh(r);if(i.length===0)throw new L(`No skills found in ${r}.`,{suggestion:`A skill is a directory containing a ${Ll}.`});let a=await q(`Loading your library`,async()=>(await B(t),Wu(t))),o=new Map(a.entries.map(e=>[e.name,e])),s=[],c=[];for(let e of i){if(!Vl(e.name)){c.push({name:e.name,reason:`invalid name`});continue}if(o.has(e.name)&&!n.overwrite){c.push({name:e.name,reason:`already in your library`});continue}try{s.push(Wl(e.dir,e.name))}catch(t){c.push({name:e.name,reason:t instanceof Error?t.message:`unreadable`})}}for(let e of c)J.warn(`Skipped ${e.name}: ${e.reason}.`);if(s.length===0){J.info(`Nothing to import.`),t.report();return}if(J.blank(),J.info(`Importing: ${s.map(e=>e.name).join(`, `)}`),!(n.yes||await nm(`Import ${s.length} skill(s)?`,!0)))return;let l=await q(`Importing ${s.length} skill(s)`,()=>Zu(t,s,o));for(let e of l)J.step(`Imported ${e} into your library.`);J.blank(),J.dim(`Run \`skilless add ${s[0]?.name??`<skill>`}\` to add one to this project.`),t.report()})}),jh=new b(`init`).description(`Create the local skilless directory.`).addOption(X.cwd).action(async e=>{Z(Um,e),J.intro(Y),await Q(async()=>{let e=!R(bl);rl(bl),J.step(`${e?`Created`:`Found`} your library at ${yl}.`),J.blank(),J.dim("Run `skilless create <name>` to make a skill."),J.dim("Run `skilless import <dir>` to bring in skills you already have."),hu()||J.dim("Run `skilless auth` to sync your skills with the cloud.")})}),Mh=Um.extend({project:P().optional(),copy:I().optional()}),Nh=new b(`install`).description(`Install every skill added to this project, and your global skills at the user level.`).option(`--copy`,`Write real files instead of symlinking into the store.`).addOption(X.project).addOption(X.cwd).action(async e=>{let t=Z(Mh,e);J.intro(Y),await Q(async()=>{let e=Gm(),n=Km(t.cwd,t.project),r=mu(t.cwd),i=await q(`Installing ${n}'s skills`,async()=>(await Lu(e),Tu(e,r,n,{copy:t.copy}))),{project:a,user:o}=i;for(let e of[...a.pruned,...o.pruned])J.dim(`Pruned ${e}, which is no longer in your library.`);for(let e of[...a.fetched,...o.fetched])J.dim(`Fetched ${e} from your library.`);for(let e of a.removed)J.dim(`Removed ${e}, which is no longer in this project.`);for(let e of o.removed)J.dim(`Removed ${e} from ${qm}, since it is no longer global.`);for(let e of a.written)J.step(`Installed ${e}.`);for(let e of o.written)J.step(`Installed ${e} globally.`);if(i.count===0){J.info(`No skills added to ${n} yet.`),J.dim("Run `skilless add <skill>` to add one.");return}await Ym(i,{copy:t.copy}),J.blank(),J.dim(Su(t.copy)?`Wrote real files into .agents/skills, and global skills into ~/.agents/skills.`:`Linked .agents/skills, and global skills in ~/.agents/skills, to your library.`)})}),Ph=Um.extend({project:Tc([I(),P()]).optional()});function Fh(e,t){let n=[];return e.global&&n.push(`global`),e.source&&n.push(`from ${fl(e.source.url)??e.source.url}`),e.local?t&&e.unsynced&&n.push(`not synced`):n.push(`not on this machine`),n.map(e=>` · ${e}`).join(``)}const Ih=new b(`list`).description(`List your skills, or the ones added to this project.`).option(`-p, --project [key]`,`List this project’s skills instead of your library.`).addOption(X.cwd).action(async e=>{let t=Z(Ph,e);J.intro(Y),await Q(async()=>{let e=new xm,n=await q(`Loading your library`,async()=>(await B(e),Wu(e)));if(t.project!==void 0){let r=Km(t.cwd,typeof t.project==`string`?t.project:void 0),i=Ku(n,await q(`Loading ${r}`,()=>Gu(e,r)));J.info(`${G.default.bold(r)}`),J.blank(),i.length===0&&J.dim("No skills in this project. Run `skilless add <skill>` to add one.");for(let t of i)J.dim(` ${t.name}${G.default.gray(Fh(t,e.api!==null))}`);e.report();return}n.entries.length===0&&J.dim("Your library is empty. Run `skilless create <name>` to make one.");for(let t of n.entries){let n=t.local?.editedAt??t.remote?.updatedAt??0,r=new Date(n).toISOString().slice(0,10);J.dim(` ${t.name.padEnd(28)} ${G.default.gray(r+Fh(t,e.api!==null))}`)}e.report()})}),Lh=Um.extend({yes:I(),user:I().optional()});function Rh(e,t){return R(e)?a.readdirSync(e,{withFileTypes:!0}).filter(e=>e.isDirectory()&&!e.isSymbolicLink()).map(n=>({name:n.name,dir:S.join(e,n.name),scope:t})).filter(e=>R(S.join(e.dir,Ll))):[]}const zh=new b(`migrate`).description(`Move this project's skills into your library and link them back. Offers your user-level skills too, as globals linked back at the user level.`).option(`--user`,`Migrate your user-level skills too, without asking.`).addOption(X.yes).addOption(X.cwd).action(async e=>{let t=Z(Lh,e);J.intro(Y),await Q(async()=>{let e=new xm,n=mu(t.cwd),r=pl(t.cwd),i=r?[kl,Al].flatMap(e=>Rh(S.join(n,e),`project`).filter(e=>{let t=gl(n,S.relative(n,e.dir));return t&&J.warn(`${e.name} is committed to this repo, so it was left alone. Remove it from git first to migrate it.`),!t})):[],a=[...Rh(Nl(),`user`),...Rh(Ml(),`user`)];if(r||J.dim(`No git remote here, so there are no project skills to migrate.`),i.length===0&&a.length===0){J.info(`Nothing to migrate.`);return}let o=await q(`Loading your library`,async()=>(await B(e),Wu(e))),s=new Map(o.entries.map(e=>[e.name,e])),c=async e=>{let t=new Map;for(let n of e)t.set(n.name,[...t.get(n.name)??[],n]);let n=[];for(let[e,r]of[...t].sort(([e],[t])=>e.localeCompare(t))){if(!Vl(e)){J.warn(`Skipped ${e}: not a valid skill name.`);continue}let t;try{t=r.map(t=>Wl(t.dir,e))}catch(t){J.warn(`Skipped ${e}: ${t instanceof Error?t.message:`unreadable`}.`);continue}let i=t[0];if(!i)continue;if(t.some(e=>e.contentHash!==i.contentHash)){J.warn(`Skipped ${e}: found more than one version (${r.map(e=>e.dir).join(`, `)}).`);continue}let a=s.get(e),o=a?.local?.contentHash??a?.remote?.contentHash;if(o&&o!==i.contentHash){J.warn(`Skipped ${e}: a different ${e} is already in your library. Rename one to migrate it.`);continue}n.push({skill:i,dirs:r.map(e=>e.dir),scope:r.some(e=>e.scope===`user`)?`user`:`project`,adopted:o!==void 0})}return n},l=await c(i);if(l.length>0&&(J.info(`Project skills in ${r}: ${l.map(e=>e.skill.name).join(`, `)}`),t.yes||await nm(`Move ${l.length} skill(s) into skilless and link them here?`,!0)||(l=[])),a.length>0){let e=[...new Set(a.map(e=>e.name))].sort();if(J.info(`User-level skills: ${e.join(`, `)}`),t.user||!t.yes&&rm&&await nm(`Would you also like to migrate your user-level skills? They become global and are linked back into ~/.agents/skills, so every project still gets them.`,!1)){let e=new Set(l.map(e=>e.skill.name)),t=await c([...a,...i.filter(e=>a.some(t=>t.name===e.name))]);l=[...l.filter(e=>!t.some(t=>t.skill.name===e.skill.name)),...t];for(let t of e)l.some(e=>e.skill.name===t)||J.warn(`Skipped ${t}: its project and user-level copies differ.`)}}if(l.length===0){J.info(`Nothing was migrated.`);return}let u=bu();for(let{skill:t,adopted:n}of l)Gl(t.name,t.files,t.editedAt),!n&&(await q(`Saving ${t.name} to your library`,()=>e.try(e=>e.putSkill(t.name,t.files,t.editedAt)))?u.skills[t.name]={contentHash:t.contentHash,editedAt:t.editedAt,syncedAt:Date.now()}:delete u.skills[t.name]);xu(u);for(let{dirs:e}of l)for(let t of e)z(t);let d=l.filter(e=>e.scope===`user`).map(e=>e.skill.name),f=l.filter(e=>e.scope===`project`).map(e=>e.skill.name);d.length>0&&Pu(d,!0),r&&f.length>0&&Mu(r,f),await q(`Saving to skilless.dev`,()=>B(e));for(let e of f)J.step(`Migrated ${e} into your library and this project.`);for(let e of d)J.step(`Migrated ${e} into your library as a global skill.`);r?await Ym(await q(`Updating this project`,()=>qu(e,n,r)),{yes:t.yes}):d.length>0&&await Ym(await q(`Linking your global skills`,()=>Xu(e)),{yes:t.yes}),e.report()})}),Bh=Um.extend({project:P().optional(),copy:I().optional()}),Vh=new b(`remove`).description(`Remove skills from this project. They stay in your library.`).argument(`<skills...>`,`Skills to remove.`).option(`--copy`,`Write real files instead of symlinking into the store.`).addOption(X.project).addOption(X.cwd).action(async(e,t)=>{let n=Z(Bh,t);J.intro(Y),await Q(async()=>{let t=new xm,r=Km(n.cwd,n.project),[i,a]=await q(`Loading your library`,async()=>(await B(t),[await Wu(t),new Set(await Gu(t,r))])),o=new Set(i.entries.filter(e=>e.global).map(e=>e.name)),s=[];for(let t of e){if(o.has(t)){J.warn(`${t} is global, so it is in every project.`),J.dim(` Run \`skilless add --not-global ${t}\` to take it out of every project.`);continue}if(!a.has(t)){J.warn(`${t} is not in this project.`);continue}s.push(t)}if(s.length===0){t.report();return}Nu(r,s);let c=mu(n.cwd),l=await q(`Updating this project`,async()=>(await B(t),qu(t,c,r,{copy:n.copy})));for(let e of s)J.step(`Removed ${e} from this project.`);await Ym(l,{copy:n.copy}),J.blank(),J.dim(`Run \`skilless delete ${s.join(` `)}\` to delete ${s.length===1?`it`:`them`}.`),t.report()})});function Hh(e,t,n,r){let i=[...new Set([...e.keys(),...t.keys()])].sort(),a=[];for(let o of i){let i=e.get(o),s=t.get(o),c=n.skills[o];if(i&&s){if(i.contentHash===s.contentHash){a.push({type:`noop`,name:o});continue}let e=!c||c.contentHash!==i.contentHash,t=!c||c.contentHash!==s.contentHash;if(e&&!t)a.push({type:`push`,name:o});else if(!e&&t)a.push({type:`pull`,name:o});else{let e=r??(i.editedAt>=s.editedAt?`push`:`pull`);a.push({type:e===`push`?`conflict-push`:`conflict-pull`,name:o})}continue}if(i&&!s){a.push({type:c?`delete-local`:`push`,name:o});continue}!i&&s&&a.push({type:c?`delete-remote`:`pull`,name:o})}return a}function Uh(e,t,n){return Wh(e,t===`push`?`remote`:`local`,n)}function Wh(e,t,n){let r=new Date().toISOString().replace(/[:.]/g,`-`),i=S.join(Dl,e,`${r}-${t}`);for(let e of n)al(S.join(i,e.path),e.contents);return i}async function Gh(e,t,n){let r={actions:[],conflicts:[],skipped:[]},i=Date.now();for(let a of t){let{name:t}=a,o=n.local.get(t);switch(a.type){case`noop`:o&&(n.state.skills[t]={contentHash:o.contentHash,editedAt:o.editedAt,syncedAt:i});break;case`push`:case`conflict-push`:if(!o)break;if(a.type===`conflict-push`){let n=await e.getSkill(t);n&&r.conflicts.push({name:t,kept:`push`,stashedAt:Uh(t,`push`,n.files)})}await e.putSkill(t,o.files,o.editedAt),n.state.skills[t]={contentHash:o.contentHash,editedAt:o.editedAt,syncedAt:i};break;case`pull`:case`conflict-pull`:{let s=await e.getSkill(t);if(!s)break;a.type===`conflict-pull`&&o&&r.conflicts.push({name:t,kept:`pull`,stashedAt:Uh(t,`pull`,o.files)}),Gl(t,s.files,s.editedAt),n.state.skills[t]={contentHash:s.contentHash,editedAt:s.editedAt,syncedAt:i};break}case`delete-local`:if(!(n.yes||await nm(`Delete ${t} from this machine? It was deleted elsewhere.`,!0))){r.skipped.push(t);continue}z(Ol(t)),delete n.state.skills[t];break;case`delete-remote`:if(!(n.yes||await nm(`Delete ${t} everywhere? It was deleted on this machine.`,!0))){r.skipped.push(t);continue}await e.deleteSkill(t),delete n.state.skills[t];break}r.actions.push(a)}return r}function Kh(e){switch(e.type){case`push`:return`Pushed ${e.name} to skilless.dev.`;case`pull`:return`Pulled ${e.name} from skilless.dev.`;case`conflict-push`:return`${e.name} changed in both places. Kept the copy on this machine.`;case`conflict-pull`:return`${e.name} changed in both places. Kept the copy from skilless.dev.`;case`delete-local`:return`Deleted ${e.name} from this machine.`;case`delete-remote`:return`Deleted ${e.name} everywhere.`;default:return null}}const qh=Um.extend({yes:I(),push:I().optional(),pull:I().optional()}),Jh=new b(`sync`).description(`Sync your library with skilless.dev, in both directions, and update this project's skills and your global ones.`).option(`--push`,`On a conflict, keep the local copy.`).option(`--pull`,`On a conflict, keep the remote copy.`).addOption(X.yes).addOption(X.cwd).action(async e=>{let t=Z(qh,e);J.intro(Y),await Q(async()=>{let e=Gm(),[n,r]=await q(`Checking skilless.dev`,async()=>[await Lu(e),await e.listSkills()]),i=new Map(ql().map(e=>[e.name,e])),a=new Map(r.map(e=>[e.name,e])),o=bu(),s=Hh(i,a,o,t.push?`push`:t.pull?`pull`:void 0),c=await q(`Syncing your library`,()=>Gh(e,s,{local:i,state:o,yes:t.yes}));xu(o);let l=c.actions.map(Kh).filter(e=>e!==null);for(let e of l)J.step(e);let[u,d]=await q(`Syncing your library`,async()=>{let t=n+await Lu(e);return[t,l.length>0||t>0?await e.listSkills():r]});u>0&&J.step(`Sent ${u} change(s) made while offline.`),Fl(d),Uu(d);let f=pl(t.cwd),p=await q(f?`Updating this project`:`Updating your global skills`,async()=>{if(!f)return{user:Du(d.filter(e=>e.global).map(e=>e.name))};let n=await Tu(e,mu(t.cwd),f);return{...n,project:n.project}}),m=`project`in p?p.project:void 0,{user:h}=p;if(m){for(let e of m.added)J.step(`Linked ${e} into this project.`);for(let e of m.removed)J.step(`Unlinked ${e}, which is no longer in this project.`);for(let e of m.pruned)J.step(`Unlinked ${e}, which is no longer in your library.`)}for(let e of h.added)J.step(`Linked ${e} into ${qm}.`);for(let e of h.removed)J.step(`Unlinked ${e} from ${qm}, since it is no longer global.`);for(let e of h.pruned)J.step(`Unlinked ${e} from ${qm}, since it is no longer in your library.`);let ee=[m,h].reduce((e,t)=>e+(t?t.added.length+t.removed.length+t.pruned.length:0),0);if(l.length===0&&ee===0&&u===0&&J.info(`Everything is already in sync.`),c.conflicts.length>0){J.blank(),J.warn(`${c.conflicts.length} skill(s) changed in two places. The copy that lost is kept here:`);for(let e of c.conflicts)J.dim(` ${e.stashedAt}`)}await Ym({skipped:[...m?.skipped??[],...h.skipped]},{yes:t.yes}),c.skipped.length>0&&(J.blank(),J.dim(`Skipped ${c.skipped.join(`, `)}.`))})}),Yh=Um.extend({yes:I(),force:I()});function Xh(e){let t=fl(e.url)??e.url;return e.ref?`${t}#${e.ref}`:t}const Zh=new b(`update`).description(`Update skills added from a git repository to what the repository has now.`).argument(`[skills...]`,`Skills to update. Omit to update every skill added from a repository.`).option(`-f, --force`,`Replace skills you have edited too. Your copy is kept first.`,!1).addOption(X.yes).addOption(X.cwd).action(async(e,t)=>{let n=Z(Yh,t);J.intro(Y),await Q(async()=>{let t=new xm,r=await q(`Loading your library`,async()=>(await B(t),Wu(t))),i=new Map(r.entries.map(e=>[e.name,e])),a=r.entries.filter(e=>e.source!==null);if(e.length>0){let t=e.filter(e=>!i.has(e));if(t.length>0)throw new L(`Not in your library: ${t.join(`, `)}`,{suggestion:"Run `skilless list` to see what you have."});let n=e.filter(e=>!i.get(e)?.source);if(n.length>0)throw new L(`${n.join(`, `)} ${n.length===1?`was`:`were`} not added from a repository, so there is nothing to update from.`)}let o=e.length>0?a.filter(t=>e.includes(t.name)):a;if(o.length===0){J.info(`None of your skills were added from a repository.`),J.dim("Run `skilless add owner/repo` to add some."),t.report();return}let s=new Map;for(let e of o){let t=`${e.source.url}#${e.source.ref??``}`;s.set(t,[...s.get(t)??[],e])}let c=[],l=new Map,u=[],d=[],f=[],p=[];for(let e of s.values()){let r=e[0].source,i=Xh(r);await Dm({url:r.url,ref:r.ref,label:i},async r=>{for(let a of e){let e=Nm(r,a.source.path,a.name);if(!e){J.warn(`${a.name} is no longer in ${i}.`);continue}let o;try{o=Wl(e.dir,a.name)}catch(e){J.warn(`Skipped ${a.name}: ${e instanceof Error?e.message:e}`);continue}let s={...a.source,path:e.path,hash:o.contentHash},p=a.local?.contentHash??a.remote?.contentHash;if(o.contentHash===a.source.hash||p===o.contentHash){Vu(a.name,s),u.push(a.name);continue}if(p!==a.source.hash){if(!(n.force||rm&&!n.yes&&await nm(`You have edited ${a.name} since it came from ${i}. Replace your edits with what it has now?`))){d.push(a.name);continue}let e=a.local?.files??(await q(`Fetching your copy of ${a.name}`,()=>t.try(e=>e.getSkill(a.name))))?.files;if(!e){J.warn(`Couldn't fetch your copy of ${a.name} to keep it, so it was left alone.`);continue}f.push({name:a.name,dir:Wh(a.name,`update`,e)})}c.push(o),l.set(a.name,s)}},{interactive:rm}).then(()=>!0,e=>{if(!(e instanceof L))throw e;return J.warn(e.toString()),!1})||p.push(...e.map(e=>e.name))}J.blank();let m=await q(`Saving ${c.length} skill(s) to your library`,()=>Zu(t,c,i,l));for(let e of m)J.step(`Updated ${e}.`);if(u.length>0&&J.info(u.length===1?`${u[0]} is already up to date.`:`${u.length} skills are already up to date.`),d.length>0&&J.warn(`Kept your edits to ${d.join(`, `)}. Run \`skilless update ${d.join(` `)} --force\` to replace them.`),p.length>0&&J.warn(`Couldn't check ${p.join(`, `)}.`),f.length>0){J.blank(),J.dim(`Your edited copies are kept here:`);for(let e of f)J.dim(` ${e.dir}`)}t.report()})});le.name(Bm).description(Vm).version(Y).addCommand(jh).addCommand(oh).addCommand(Th).addCommand(Zm).addCommand(Zh).addCommand(Vh).addCommand(Dh).addCommand(Nh).addCommand(Jh).addCommand(Ah).addCommand(zh).addCommand(Ih).addCommand(Ch).parse();export{};
123
+ `;return this.stop(),this.#p(()=>this.#a.write(a)),this}};function Xp(e){return new Yp(e)}var G=ne(v(((e,t)=>{let n=process||{},r=n.argv||[],i=n.env||{},a=!(i.NO_COLOR||r.includes(`--no-color`))&&(!!i.FORCE_COLOR||r.includes(`--color`)||n.platform===`win32`||(n.stdout||{}).isTTY&&i.TERM!==`dumb`||!!i.CI),o=(e,t,n=e)=>r=>{let i=``+r,a=i.indexOf(t,e.length);return~a?e+s(i,t,n,a)+t:e+i+t},s=(e,t,n,r)=>{let i=``,a=0;do i+=e.substring(a,r)+n,a=r+t.length,r=e.indexOf(t,a);while(~r);return i+e.substring(a)},c=(e=a)=>{let t=e?o:()=>String;return{isColorSupported:e,reset:t(`\x1B[0m`,`\x1B[0m`),bold:t(`\x1B[1m`,`\x1B[22m`,`\x1B[22m\x1B[1m`),dim:t(`\x1B[2m`,`\x1B[22m`,`\x1B[22m\x1B[2m`),italic:t(`\x1B[3m`,`\x1B[23m`),underline:t(`\x1B[4m`,`\x1B[24m`),inverse:t(`\x1B[7m`,`\x1B[27m`),hidden:t(`\x1B[8m`,`\x1B[28m`),strikethrough:t(`\x1B[9m`,`\x1B[29m`),black:t(`\x1B[30m`,`\x1B[39m`),red:t(`\x1B[31m`,`\x1B[39m`),green:t(`\x1B[32m`,`\x1B[39m`),yellow:t(`\x1B[33m`,`\x1B[39m`),blue:t(`\x1B[34m`,`\x1B[39m`),magenta:t(`\x1B[35m`,`\x1B[39m`),cyan:t(`\x1B[36m`,`\x1B[39m`),white:t(`\x1B[37m`,`\x1B[39m`),gray:t(`\x1B[90m`,`\x1B[39m`),bgBlack:t(`\x1B[40m`,`\x1B[49m`),bgRed:t(`\x1B[41m`,`\x1B[49m`),bgGreen:t(`\x1B[42m`,`\x1B[49m`),bgYellow:t(`\x1B[43m`,`\x1B[49m`),bgBlue:t(`\x1B[44m`,`\x1B[49m`),bgMagenta:t(`\x1B[45m`,`\x1B[49m`),bgCyan:t(`\x1B[46m`,`\x1B[49m`),bgWhite:t(`\x1B[47m`,`\x1B[49m`),blackBright:t(`\x1B[90m`,`\x1B[39m`),redBright:t(`\x1B[91m`,`\x1B[39m`),greenBright:t(`\x1B[92m`,`\x1B[39m`),yellowBright:t(`\x1B[93m`,`\x1B[39m`),blueBright:t(`\x1B[94m`,`\x1B[39m`),magentaBright:t(`\x1B[95m`,`\x1B[39m`),cyanBright:t(`\x1B[96m`,`\x1B[39m`),whiteBright:t(`\x1B[97m`,`\x1B[39m`),bgBlackBright:t(`\x1B[100m`,`\x1B[49m`),bgRedBright:t(`\x1B[101m`,`\x1B[49m`),bgGreenBright:t(`\x1B[102m`,`\x1B[49m`),bgYellowBright:t(`\x1B[103m`,`\x1B[49m`),bgBlueBright:t(`\x1B[104m`,`\x1B[49m`),bgMagentaBright:t(`\x1B[105m`,`\x1B[49m`),bgCyanBright:t(`\x1B[106m`,`\x1B[49m`),bgWhiteBright:t(`\x1B[107m`,`\x1B[49m`)}};t.exports=c(),t.exports.createColors=c}))(),1);const Zp=Hd.default.prompt;function Qp(){process.stdout.write(`\r\x1B[0J`),process.stdin.isTTY&&process.stdin.setRawMode(!1),tm()}const $p={limit:10,up(){if(this.index>0)return this.index--,this.render();if(this.choices[0]?.index!==0)return this.scrollUp()},down(){if(this.index<this.visible.length-1)return this.index++,this.render();if(this.visible.at(-1)?.index!==this.choices.length-1)return this.scrollDown()}};async function em(e,t){cm();try{return await Zp({...e,cancel:Qp})}catch{return tm(),t}finally{lm()}}function tm(){cm(),process.stdout.write(`${G.default.yellow(`!`)} Cancelled\n`),process.exit(1)}async function nm(e,t=!1){return(await em({type:`confirm`,name:`value`,message:e,initial:t},{value:!1})).value}const rm=!!(process.stdin.isTTY&&process.stdout.isTTY);async function im(e,t={}){return(await em({type:`input`,name:`value`,message:e,initial:t.initial,validate:t.validate?e=>t.validate((e??``).trim()):void 0},{value:``})).value.trim()}async function am(e,t){return t.every(e=>e.disabled)?[]:(await em({type:`multiselect`,name:`value`,message:e,choices:t,...$p},{value:[]})).value}async function om(e,t,n){let r=n?t.findIndex(e=>e.name===n):-1;return(await em({type:`select`,name:`value`,message:e,choices:t,initial:r===-1?0:r,...$p},{value:``})).value}let K=null;function sm(e){let t=e.step%3+1;return`${e.message}${`.`.repeat(t)}${` `.repeat(3-t)}`}function cm(){K?.ora.isSpinning&&K.ora.stop()}function lm(){K&&!K.ora.isSpinning&&K.ora.start(sm(K))}async function q(e,t){if(!process.stdout.isTTY||!process.stdout.columns)return t();if(K){let n=K.message;K.message=e;try{return await t()}finally{K&&(K.message=n)}}let n={ora:Xp({stream:process.stdout,color:`cyan`,discardStdin:!1}),message:e,step:0,dots:setInterval(()=>{n.step++,n.ora.text=sm(n)},300)};K=n,lm();try{return await t()}finally{clearInterval(n.dots),cm(),K=null}}function um(e,t){let n=K?.ora.isSpinning===!0;n&&K.ora.clear(),e.write(t),n&&K.ora.render()}const dm=e=>G.default.isColorSupported?`\x1b[48;2;95;95;95m\x1b[38;2;250;250;250m${e}\x1b[39m\x1b[49m`:e,J={intro(e){um(process.stdout,`${dm(` skilless `)}${G.default.gray(` v${e}`)}\n\n`)},info(e){um(process.stdout,`${G.default.blue(`·`)} ${e}\n`)},step(e){um(process.stdout,`${G.default.green(`✓`)} ${e}\n`)},warn(e){um(process.stdout,`${G.default.yellow(`!`)} ${e}\n`)},error(e){um(process.stderr,`${G.default.red(`✖`)} ${e}\n`)},dim(e){um(process.stdout,`${G.default.gray(e)}\n`)},blank(){um(process.stdout,`
124
+ `)}},fm=Cc({path:P(),contents:P()}),pm=Cc({url:P(),ref:P().optional(),path:P(),hash:P()}),mm=Cc({name:P(),contentHash:P(),editedAt:fc(),updatedAt:fc(),global:I(),source:pm.nullable().default(null)}),hm=mm.extend({files:xc(fm)}),gm=Cc({bound:xc(P()),unknown:xc(P())}),_m=Cc({error:P(),message:P().optional()}),vm=new Set([502,503,504]);function ym(e){try{return JSON.parse(e)}catch{return null}}var bm=class{#e;#t;#n=!1;constructor(e,t){this.#e=e,this.#t=t}get baseUrl(){return this.#t}async#r(e,t,n){if(this.#n)throw new tl(this.#t);let r;for(let i=0;i<2;i++){i>0&&await new Promise(e=>setTimeout(e,500));try{let i=await fetch(`${this.#t}/api/v1${t}`,{method:e,headers:{Authorization:`Bearer ${this.#e}`,...n===void 0?{}:{"Content-Type":`application/json`}},body:n===void 0?void 0:JSON.stringify(n),signal:AbortSignal.timeout(1e4)}),a=await i.text();if(vm.has(i.status)){r=Error(`${e} ${t} returned ${i.status}.`);continue}return{status:i.status,text:a}}catch(e){r=e}}throw this.#n=!0,new tl(this.#t,r)}async#i(e,t,n,r){let i=await this.#r(e,t,r);if(i.status===401)throw new $c;if(i.status<200||i.status>=300){let n=_m.safeParse(ym(i.text));throw new L(n.success?n.data.message??n.data.error:`${e} ${t} failed with ${i.status}.`)}if(i.status===204)return n.parse(void 0);let a=n.safeParse(ym(i.text));if(!a.success)throw new L(`Unexpected response from ${e} ${t}.`,{suggestion:`This is likely a version mismatch. Try updating skilless.`});return a.data}async listSkills(){return await this.#i(`GET`,`/skills`,xc(mm))}async getSkill(e){return await this.#i(`GET`,`/skills/${encodeURIComponent(e)}`,hm.nullable())}async putSkill(e,t,n){return await this.#i(`PUT`,`/skills/${encodeURIComponent(e)}`,mm,{files:t,editedAt:n})}async setGlobal(e,t){await this.#i(`PUT`,`/skills/${encodeURIComponent(e)}/global`,_c(),{global:t})}async setSource(e,t){await this.#i(`PUT`,`/skills/${encodeURIComponent(e)}/source`,_c(),{source:t})}async deleteSkill(e){await this.#i(`DELETE`,`/skills/${encodeURIComponent(e)}`,_c())}async getBindings(e){return await this.#i(`GET`,`/projects/skills?key=${encodeURIComponent(e)}`,xc(hm))}async setBindings(e,t){return await this.#i(`PUT`,`/projects/skills`,gm,{key:e,names:t})}},xm=class{api;#e=null;constructor(){let e=hu();this.api=e?new bm(e,vu()):null}get online(){return this.api!==null&&this.#e===null}async try(e){if(!(!this.api||this.#e))try{return await e(this.api)}catch(e){if(e instanceof tl||e instanceof $c){this.#e=e;return}throw e}}report(){if(this.#e){if(J.blank(),this.#e instanceof tl){J.warn(`Couldn't reach ${this.#e.url}. Run \`skilless sync\` to sync your skills with the cloud.`);return}J.warn(`Your sign-in was rejected, so this only changed this machine.`),J.dim("Run `skilless auth` to sign in again, then `skilless sync` to sync your skills.")}}};function Sm(e){return e.includes(`/`)||e.includes(`:`)}function Cm(e){let t=e.trim(),n,r=t.indexOf(`#`);if(r>=0&&(n=t.slice(r+1)||void 0,t=t.slice(0,r)),/^ext::/i.test(t))throw new L(`The ext:: git transport is not supported.`);let i=/^(github|gitlab):(.+)$/.exec(t);i&&(t=i[1]===`gitlab`?`https://gitlab.com/${i[2]}`:i[2]??``);let a;return a=/^https?:\/\//i.test(t)?wm(t,n):/^[a-z][a-z0-9+.-]*:\/\//i.test(t)||/^[^@/\s]+@[^:/\s]+:/.test(t)?{url:t,ref:n}:Tm(t,n),a.subpath&&=Em(a.subpath),{...a,label:fl(a.url)??a.url}}function wm(e,t){let n;try{n=new URL(e)}catch{throw new L(`${e} is not a valid URL.`)}let r=n.pathname.split(`/`).filter(Boolean).map(decodeURIComponent),i=`${n.protocol}//${n.host}`;if(n.hostname===`github.com`&&r.length>=2){let[e,n,a,o,...s]=r,c=`${i}/${e}/${n?.replace(/\.git$/,``)}.git`;return(a===`tree`||a===`blob`)&&o?{url:c,ref:o,subpath:s.join(`/`)||void 0}:{url:c,ref:t}}let a=r.indexOf(`-`);return a>0&&r[a+1]===`tree`&&r[a+2]?{url:`${i}/${r.slice(0,a).join(`/`).replace(/\.git$/,``)}.git`,ref:r[a+2],subpath:r.slice(a+3).join(`/`)||void 0}:{url:e,ref:t}}function Tm(e,t){let n=/^([^/@\s]+)\/([^/@\s]+)@([^/\s]+)$/.exec(e);if(n)return{url:`https://github.com/${n[1]}/${n[2]}.git`,ref:t,skill:n[3]};let r=/^([^/\s.][^/\s]*)\/([^/\s]+?)(?:\/(.+?))?\/?$/.exec(e);if(!r)throw new L(`Can't tell where ${e} points.`,{suggestion:"Pass `owner/repo` for GitHub, or a full git URL for anywhere else."});return{url:`https://github.com/${r[1]}/${r[2]?.replace(/\.git$/,``)}.git`,ref:t,subpath:r[3]}}function Em(e){let t=e.replace(/\\/g,`/`).split(`/`).filter(Boolean);if(t.includes(`..`))throw new L(`${e} reaches outside the repository.`);return t.join(`/`)}async function Dm(e,t,r){let i=a.mkdtempSync(S.join(s.tmpdir(),`skilless-`));try{let o=[`clone`,`--depth`,`1`,`--quiet`];e.ref&&o.push(`--branch`,e.ref),o.push(`--`,e.url,i);try{await q(`Cloning ${e.label}${e.ref?`#${e.ref}`:``}`,()=>Om(o,{...process.env,GIT_TERMINAL_PROMPT:`0`,GIT_SSH_COMMAND:process.env.GIT_SSH_COMMAND??`ssh -o BatchMode=yes`}))}catch(t){if(!r.interactive)throw km(e,t);z(i),a.mkdirSync(i);try{n(`git`,o,{stdio:[`inherit`,`ignore`,`pipe`],encoding:`utf8`})}catch(t){throw km(e,t)}}return await t(i)}finally{z(i)}}function Om(e,n){return new Promise((r,i)=>{t(`git`,e,{env:n,encoding:`utf8`},(e,t,n)=>{e?i(Object.assign(e,{stderr:n})):r()})})}function km(e,t){let n=t.stderr?.trim();return new L(`Couldn't clone ${e.label}.`,{suggestion:n||`Check the address, and that you have access to the repository.`,cause:t})}const Am=new Set([`node_modules`,`.git`,`dist`,`build`,`__pycache__`]),jm=[`skills`,`skills/.curated`,`skills/.experimental`,`skills/.system`,`.agents/skills`,`.claude/skills`];function Mm(e,t){let n=t?S.join(e,t):e;if(!R(n))throw new L(`${t} does not exist in the repository.`);let r=new Map,i=e=>{let t=Im(e);r.has(t.name)||r.set(t.name,t)};if(Pm(n))return i(n),[...r.values()];Fm(n,1,i);for(let e of jm)Fm(S.join(n,e),3,i);return r.size===0&&Fm(n,5,i),[...r.values()].sort((e,t)=>e.name.localeCompare(t.name))}function Nm(e,t,n){try{let n=Em(t);if(Pm(S.join(e,n)))return{dir:S.join(e,n),path:n}}catch{}let r=Mm(e).find(e=>e.name===n);return r?{dir:r.dir,path:S.relative(e,r.dir)}:null}function Pm(e){return a.existsSync(S.join(e,Ll))}function Fm(e,t,n){let r;try{r=a.readdirSync(e,{withFileTypes:!0})}catch{return}for(let i of r.sort((e,t)=>e.name.localeCompare(t.name))){if(!i.isDirectory()||Am.has(i.name))continue;let r=S.join(e,i.name);Pm(r)?n(r):t>1&&Fm(r,t-1,n)}}function Im(e){let t=Lm(a.readFileSync(S.join(e,Ll),`utf8`)),n=t.name?.toLowerCase().replace(/[\s_]+/g,`-`);return{name:n&&Vl(n)?n:S.basename(e).toLowerCase(),dir:e,description:t.description}}function Lm(e){let t=/^---\r?\n([\s\S]*?)\r?\n---/.exec(e)?.[1];if(!t)return{};let n=e=>{let n=RegExp(`^${e}:[ \\t]*(.+)$`,`m`).exec(t)?.[1]?.trim();if(!(!n||n===`|`||n===`>`))return n.replace(/^(['"])(.*)\1$/,`$2`)};return{name:n(`name`),description:n(`description`)}}var Rm=`skilless`,zm=`Author skills once, sync them everywhere, install them per project.`;const Y=`0.0.5`,Bm=Rm,Vm=zm,Hm=`SKILLESS_TRACE`,Um=Cc({cwd:P()}),X={cwd:new x(`--cwd <path>`,`The current working directory.`).default(process.cwd()),yes:new x(`-y, --yes`,`Skip confirmation prompts.`).default(!1),project:new x(`--project <key>`,`Override the project key. Defaults to the normalized git remote.`)};function Z(e,t){let n=e.safeParse(t);return n.success?n.data:Wm(new L(`Invalid options.`,{suggestion:n.error.issues.map(e=>` ${e.message}`).join(`
125
+ `)}))}function Wm(e){process.env[Hm]===`1`?console.trace(e):J.error(G.default.red(e.toString())),process.exit(1)}async function Q(e){try{return await e()}catch(e){return e instanceof L?Wm(e):Wm(new L(e instanceof Error?e.message:String(e),{suggestion:`Run with ${Hm}=1 for a stack trace.`,cause:e}))}}function Gm(){let e=hu();if(!e)throw new $c;return new bm(e,vu())}function Km(e,t){if(t)return t;let n=pl(e);if(!n)throw new el;return n}const qm=`~/.agents/skills`;function Jm(e){let t=S.normalize(s.homedir());return e===t||e.startsWith(`${t}/`)?`~${e.slice(t.length)}`:e}async function Ym(e,t={}){for(let n of e.skipped){if(n.reason===`tracked`){J.warn(`\`${n.name}\` is tracked by git here, so it was left alone.`);continue}let e=(n.occupied?.paths??[]).map(Jm).join(` and `);if(!(t.yes||rm&&await nm(`Overwrite ${e}?`,!1))){rm?J.dim(`Kept ${e}, so ${n.name} is not linked there.`):(J.warn(`Skipped ${n.name}: ${e} was not made by skilless.`),J.dim(` Run this in a terminal to overwrite it, or pass --yes.`));continue}du(n,{copy:Su(t.copy)}),J.step(`Overwrote ${e}.`)}for(let t of e.missing??[])J.warn(`${t} is not on this machine yet, so it will be linked on the next sync.`)}const Xm=Um.extend({project:P().optional(),copy:I().optional(),global:I().optional(),notGlobal:I().optional(),overwrite:I(),yes:I()}),Zm=new b(`add`).description(`Add skills to this project, from your library or from a git repository.`).argument(`[skills...]`,"Skills to add, or a repo (`owner/repo` or any git URL) then the skills to take from it. Omit the skills to pick from a list.").option(`-g, --global`,`Make these skills global: linked once into ~/.agents/skills and ~/.claude/skills, so every project has them, including cloud agents.`).option(`--not-global`,`Stop treating these skills as global, and unlink them from your user-level skills.`).option(`--copy`,`Write real files instead of symlinking into the store.`).option(`--overwrite`,`From a repo: replace library skills of the same name.`,!1).addOption(X.yes).addOption(X.project).addOption(X.cwd).action(async(e,t)=>{let n=Z(Xm,t);J.intro(Y),await Q(async()=>{let t=new xm,[r,...i]=e;if(r&&Sm(r)){await eh(t,Cm(r),i,n);return}let a=e.find(Sm);if(a)throw new L(`${a} is a repository, not a skill.`,{suggestion:`Name the repository first: \`skilless add ${a} <skills...>\`.`});let{entries:o,live:s}=await q(`Loading your library`,async()=>(await B(t),Wu(t))),c=e=>s||e.local!==null,l=e=>{let t=o.filter(t=>e.includes(t.name)&&!c(t)).map(e=>e.name);if(t.length!==0)throw new L(`${t.join(`, `)} ${t.length===1?`is`:`are`} not on this machine, and the server can't be reached to fetch ${t.length===1?`it`:`them`}.`,{suggestion:"Run `skilless sync` once you are back online, then try again."})},u=new Set(o.map(e=>e.name)),d=e.filter(e=>!u.has(e));if(d.length>0)throw new L(`Not in your library: ${d.join(`, `)}`,{suggestion:"Run `skilless list` to see what you have."});if(n.global||n.notGlobal){let r=n.global===!0,i=e;if(i.length===0){let e=o.filter(e=>e.global!==r&&(!r||c(e)));if(e.length===0){J.info(r?`Every skill in your library is already global.`:`No skills in your library are global.`);return}if(i=await am(r?`Make global`:`Stop being global`,e.map(e=>({name:e.name}))),i.length===0){J.info(`Nothing selected.`);return}}r&&l(i),await Qm(t,i,r,n),t.report();return}let f=Km(n.cwd,n.project),p=new Set(await q(`Loading ${f}`,()=>Gu(t,f))),m=e;if(m.length===0){if(o.filter(e=>!p.has(e.name)&&c(e)).length===0){J.info(s?`Every skill in your library is already in this project.`:`Every skill on this machine is already in this project.`),t.report();return}if(m=await am(`Add to ${f}`,o.filter(e=>p.has(e.name)||c(e)).map(e=>p.has(e.name)?{name:e.name,disabled:`already added`}:{name:e.name})),m.length===0){J.info(`Nothing selected.`);return}}let h=o.filter(e=>e.global).map(e=>e.name);l(m.filter(e=>!h.includes(e))),await $m(t,f,m,h,n),t.report()})});async function Qm(e,t,n,r){Pu(t,n),await q(`Saving to skilless.dev`,()=>B(e));for(let e of t)J.step(n?`${e} is now global, so every project has it.`:`${e} is no longer global.`);let i=r.project??pl(r.cwd),a=mu(r.cwd),[o,s]=await q(`Updating your skills`,async()=>{if(!i){let t=await Xu(e);return[t,t]}let t=await qu(e,a,i,{copy:r.copy});return[t,t.user]});for(let e of s.written.filter(e=>t.includes(e)))J.dim(`Linked ${e} into ${qm}.`);for(let e of s.removed)J.dim(`Unlinked ${e} from ${qm}.`);if(`project`in o){for(let e of o.project.removed)J.dim(`Moved ${e} out of this project.`);for(let e of o.project.written.filter(e=>t.includes(e)))J.dim(`${e} is still added to this project, so it is linked here again.`)}await Ym(o,r)}async function $m(e,t,n,r,i){for(let e of n)r.includes(e)&&J.dim(`${e} is global, so it is already in this project.`);let a=n.filter(e=>!r.includes(e));Mu(t,a);let o=mu(i.cwd),s=await q(`Updating this project`,async()=>(await B(e),qu(e,o,t,{copy:i.copy})));for(let e of a)J.step(`Added ${e} to this project.`);await Ym(s,i)}async function eh(e,t,n,r){if(r.notGlobal)throw new L(`--not-global only applies to skills already in your library.`);let i=r.global?null:r.project??pl(r.cwd),a=await q(`Loading your library`,async()=>(await B(e),Wu(e))),o=new Map(a.entries.map(e=>[e.name,e])),s=[...n,...t.skill?[t.skill]:[]],c=await Dm(t,async e=>{let n=Mm(e,t.subpath);if(n.length===0)throw new L(`No skills found in ${t.label}.`,{suggestion:`A skill is a directory containing a SKILL.md.`});let i=n;if(s.length>0){let e=e=>n.find(t=>t.name===e.toLowerCase()||t.dir.split(`/`).at(-1)?.toLowerCase()===e.toLowerCase()),r=s.filter(t=>!e(t));if(r.length>0)throw new L(`Not in ${t.label}: ${r.join(`, `)}`,{suggestion:`It has: ${n.map(e=>e.name).join(`, `)}`});i=[...new Set(s.map(t=>e(t)))]}else if(n.length>1&&!r.yes){if(!rm)throw new L(`${t.label} has ${n.length} skills.`,{suggestion:`Name the ones you want after the repository, or pass --yes for all of them: ${n.map(e=>e.name).join(`, `)}`});let e=await am(`Add from ${t.label}`,n.map(e=>({name:e.name,hint:th(e.description)})));i=n.filter(t=>e.includes(t.name))}let a=[];for(let t of i)try{Hl(t.name),a.push({skill:Wl(t.dir,t.name),path:S.relative(e,t.dir)})}catch(e){J.warn(`Skipped ${t.name}: ${e instanceof L?e.message:e}`)}return a},{interactive:rm});if(c.length===0){J.info(`Nothing selected.`),e.report();return}let l=[],u=[],d=new Map;for(let{skill:e,path:n}of c){d.set(e.name,{url:t.url,...t.ref?{ref:t.ref}:{},path:n,hash:e.contentHash});let i=o.get(e.name),a=i?.local?.contentHash??i?.remote?.contentHash;if(!i||a===e.contentHash){i?Vu(e.name,d.get(e.name)):l.push(e),u.push(e.name);continue}if(!(r.overwrite||rm&&!r.yes&&await nm(`${e.name} is already in your library. Replace it with the one from ${t.label}?`))){J.warn(`Kept your own ${e.name}. Pass --overwrite to replace it.`);continue}l.push(e),u.push(e.name)}let f=await q(`Saving ${l.length} skill(s) to your library`,()=>Zu(e,l,o,d));for(let e of f)J.step(`Copied ${e} into your library from ${t.label}.`);if(u.length===0){e.report();return}r.global?await Qm(e,u,!0,r):i?await $m(e,i,u,(await q(`Loading your library`,()=>Wu(e))).entries.filter(e=>e.global).map(e=>e.name),r):(J.blank(),J.dim(`This directory has no git remote, so ${u.length===1?`it is`:`they are`} only in your library. Run \`skilless add ${u[0]}\` inside a project to add ${u.length===1?`it`:`them`} there.`)),e.report()}function th(e){if(e)return e.length>60?`${e.slice(0,57)}...`:e}function nh(e){switch(process.platform){case`darwin`:return[`open`,[e]];case`win32`:return[`rundll32`,[`url.dll,FileProtocolHandler`,e]];default:return[`xdg-open`,[e]]}}function rh(e){let[t,n]=nh(e);try{let e=r(t,n,{stdio:`ignore`,detached:!0,windowsHide:!0});e.on(`error`,()=>{}),e.unref()}catch{}}async function ih(){let e=c.randomBytes(16).toString(`hex`),t=vu(),n=new URL(t).origin,r={"Access-Control-Allow-Origin":n,"Access-Control-Allow-Methods":`POST, OPTIONS`,"Access-Control-Allow-Headers":`Content-Type`,"Access-Control-Allow-Private-Network":`true`},i,a=new Promise((e,t)=>{i={resolve:e,reject:t}}),o=f.createServer((t,n)=>{if(t.method===`OPTIONS`){n.writeHead(204,r),n.end();return}if(t.method!==`POST`){n.writeHead(405,r),n.end();return}let a=``;t.on(`data`,e=>{a+=e}),t.on(`end`,()=>{let t;try{t=JSON.parse(a)}catch{n.writeHead(400,r),n.end();return}if(t.state!==e||!t.token){n.writeHead(400,r),n.end();return}n.writeHead(200,{...r,"Content-Type":`application/json`}),n.end(JSON.stringify({ok:!0})),i.resolve(t.token)})}),s=setTimeout(()=>{i.reject(new L(`Timed out waiting for sign in.`,{suggestion:"Run `skilless auth` again, or paste a token with `skilless auth --token <token>`."}))},3e5);try{await new Promise((e,t)=>{o.once(`error`,t),o.listen(0,`127.0.0.1`,e)});let{port:n}=o.address(),r=`${t}/cli/auth?port=${n}&state=${e}`;J.info(`Opening your browser to sign in…`),J.dim(r),J.blank(),rh(r),gu(await q(`Waiting for you to sign in`,()=>a))}finally{clearTimeout(s),o.close()}}const ah=Um.extend({logout:I(),token:P().optional()}),oh=new b(`auth`).description(`Sign in to skilless.dev, or sign out.`).addOption(new x(`--logout`,`Sign out on this machine.`).default(!1)).addOption(new x(`--token <token>`,`Save a token directly, for when the browser flow cannot reach localhost.`)).addOption(X.cwd).action(async e=>{let t=Z(ah,e);J.intro(Y),await Q(async()=>{if(t.logout){if(!hu()){J.info(`You were not signed in.`);return}_u(),J.step(`Signed out on this machine.`);return}if(t.token){gu(t.token),J.step(`Token saved. You are signed in to skilless.dev.`);return}await ih(),J.step(`Signed in to skilless.dev.`)})}),sh=s.homedir(),ch=process.env.LOCALAPPDATA??S.join(sh,`AppData`,`Local`),lh=process.env.ProgramFiles??`C:/Program Files`,$={cursor:{label:`Cursor`,cli:`cursor`,fallbacks:{darwin:[`/Applications/Cursor.app/Contents/Resources/app/bin/cursor`,`${sh}/Applications/Cursor.app/Contents/Resources/app/bin/cursor`],win32:[S.join(ch,`Programs/cursor/resources/app/bin/cursor.cmd`)],linux:[`/usr/share/cursor/bin/cursor`,`/opt/Cursor/resources/app/bin/cursor`]}},vscode:{label:`VS Code`,cli:`code`,fallbacks:{darwin:[`/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code`,`${sh}/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code`],win32:[S.join(ch,`Programs/Microsoft VS Code/bin/code.cmd`),S.join(lh,`Microsoft VS Code/bin/code.cmd`)],linux:[`/usr/share/code/bin/code`,`/snap/bin/code`]}},windsurf:{label:`Windsurf`,cli:`windsurf`,fallbacks:{darwin:[`/Applications/Windsurf.app/Contents/Resources/app/bin/windsurf`,`${sh}/Applications/Windsurf.app/Contents/Resources/app/bin/windsurf`],win32:[S.join(ch,`Programs/Windsurf/bin/windsurf.cmd`)],linux:[`/usr/share/windsurf/bin/windsurf`]}},zed:{label:`Zed`,cli:`zed`,fallbacks:{darwin:[`/Applications/Zed.app/Contents/MacOS/cli`,`${sh}/Applications/Zed.app/Contents/MacOS/cli`],win32:[S.join(ch,`Programs/Zed/bin/zed.exe`)],linux:[`${sh}/.local/bin/zed`]}},sublime:{label:`Sublime Text`,cli:`subl`,fallbacks:{darwin:[`/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl`],win32:[S.join(lh,`Sublime Text/subl.exe`)],linux:[`/opt/sublime_text/sublime_text`]}},neovim:{label:`Neovim`,cli:`nvim`,terminal:!0},vim:{label:`Vim`,cli:`vim`,terminal:!0}},uh=Object.keys($);function dh(e){return Object.hasOwn($,e)}function fh(e){let t=i(process.platform===`win32`?`where`:`which`,[e],{encoding:`utf8`,windowsHide:!0});if(t.status!==0||!t.stdout)return null;let n=t.stdout.split(/\r?\n/).map(e=>e.trim()).filter(Boolean);return process.platform===`win32`?n.find(e=>/\.(exe|cmd|bat)$/i.test(e))??n[0]??null:n[0]??null}function ph(e){let t=$[e],n=fh(t.cli);if(n)return n;let r=process.platform;return t.fallbacks?.[r]?.find(e=>R(e))??null}function mh(){return uh.filter(e=>ph(e)!==null)}function hh(e){return $[e].terminal===!0}function gh(e,t){let n=ph(e);if(!n)return Promise.reject(Error(`${$[e].label} was not found. Is \`${$[e].cli}\` on your PATH?`));let i=hh(e);return new Promise((e,a)=>{let o=r(n,[t],{cwd:S.dirname(t),stdio:i?`inherit`:`ignore`,detached:!i,windowsHide:!0,shell:process.platform===`win32`&&/\.(cmd|bat)$/i.test(n)});o.on(`error`,a),i?o.on(`exit`,()=>e()):(o.unref(),setImmediate(e))})}function _h(){let e=ol(El,{});return e.editor!==void 0&&!dh(e.editor)&&delete e.editor,e}function vh(e){sl(El,e)}function yh(e){let t={..._h(),...e};for(let e of Object.keys(t))t[e]===void 0&&delete t[e];return vh(t),t}const bh=`none`,xh=Cc({unset:I()}),Sh=new b(`editor`).description("Choose the editor `skilless create` opens a new skill in.").argument(`[editor]`,`Set it directly: ${uh.join(`, `)}.`).addOption(new x(`--unset`,`Stop opening new skills in an editor.`).default(!1)).action(async(e,t)=>{let n=Z(xh,t);J.intro(Y),await Q(async()=>{let t=_h().editor;if(n.unset){yh({editor:void 0}),J.step(`New skills will no longer open in an editor.`);return}if(e){if(!dh(e))throw new L(`${e} is not an editor skilless knows.`,{suggestion:`Pick one of: ${uh.join(`, `)}.`});yh({editor:e}),J.step(`New skills will open in ${$[e].label}.`);return}if(!rm){J.info(t?`Editor: ${$[t].label}`:`No editor set.`);return}let r=mh();if(r.length===0)throw new L(`None of the editors skilless knows are installed.`,{suggestion:`skilless looks for: ${uh.map(e=>$[e].cli).join(`, `)}.`});let i=await om(`Open new skills in`,[...r.map(e=>({name:e,message:$[e].label,hint:e===t?G.default.gray(`current`):void 0})),{name:bh,message:`None`,hint:t?void 0:G.default.gray(`current`)}],t??bh);if(i===bh){yh({editor:void 0}),J.step(`New skills will not open in an editor.`);return}dh(i)&&(yh({editor:i}),J.step(`New skills will open in ${$[i].label}.`))})}),Ch=new b(`config`).description(`View or change your skilless settings.`).addCommand(Sh).action(async()=>{J.intro(Y),await Q(async()=>{let e=_h();J.info(`editor ${e.editor?$[e.editor].label:G.default.gray(`not set`)}`),J.blank(),J.dim(`Stored in ${El}`)})}),wh=Um.extend({description:P().optional(),project:P().optional(),global:I().optional(),open:I()}),Th=new b(`create`).description(`Create a skill, add it to this project, and print the path to edit it.`).argument(`[name]`,`The name of the skill. You will be asked if you leave it out.`).option(`-d, --description <description>`,`What the skill does, for the frontmatter.`).option(`-g, --global`,`Make it global: linked once into ~/.agents/skills and ~/.claude/skills, so every project has it, including cloud agents.`).option(`--no-open`,"Do not open SKILL.md in your editor (see `skilless config editor`).").addOption(X.project).addOption(X.cwd).action(async(e,t)=>{let n=Z(wh,t);J.intro(Y),await Q(async()=>{let t=new xm,r=await q(`Loading your library`,async()=>(await B(t),Wu(t))),i=new Set(r.entries.map(e=>e.name)),a=e;if(!a){if(!rm)throw new L(`No name given.`,{suggestion:"Run `skilless create <name>`."});a=await im(`Name`,{validate:e=>e?Vl(e)?i.has(e)?`${e} already exists in your library.`:!0:`Use lowercase letters, digits, dots, dashes and underscores.`:`A name is required.`})}if(Hl(a),Jl(a))throw new L(`${a} already exists in your library.`,{suggestion:`Edit it at ${S.join(Ol(a),`SKILL.md`)}`});if(i.has(a))throw new L(`${a} already exists in your library.`,{suggestion:`Run \`skilless sync\` to bring ${a} down to this machine.`});let o=n.description??await im(`What does this skill do?`);Gl(a,Yl(a,o));let s=Wl(Ol(a),a);if(await q(`Creating ${a}`,()=>t.try(e=>e.putSkill(a,s.files,s.editedAt)))){let e=bu();e.skills[a]={contentHash:s.contentHash,editedAt:s.editedAt,syncedAt:Date.now()},xu(e)}J.step(`Created ${a} in your library.`),n.global&&Pu([a],!0);let c=n.project??pl(n.cwd);if(c){n.global||Mu(c,[a]);let e=mu(n.cwd);await Ym(await q(`Updating this project`,async()=>(await B(t),qu(t,e,c))))}else n.global?await Ym(await q(`Linking your global skills`,async()=>(await B(t),Xu(t)))):await q(`Saving to skilless.dev`,()=>B(t));n.global?J.step(`${a} is now global, so every project has it.`):c?J.step(`Added ${a} to ${c}.`):J.warn(`No git remote here, so ${a} was not added to a project.`);let l=S.join(Ol(a),`SKILL.md`),u=n.open?_h().editor:void 0,d=u&&(!hh(u)||rm);if(J.blank(),u&&d)try{J.dim(`Opening ${a} in ${$[u].label}...`),await gh(u,l)}catch(e){J.warn(e instanceof Error?e.message:String(e)),J.dim(`Edit ${a} at ${l}`)}else J.dim(`Edit ${a} at ${l}`);t.api&&J.dim("Run `skilless sync` to save your changes."),t.report()})}),Eh=Um.extend({yes:I()}),Dh=new b(`delete`).description(`Delete skills from your library, everywhere.`).argument(`<skills...>`,`Skills to delete.`).addOption(X.yes).addOption(X.cwd).action(async(e,t)=>{let n=Z(Eh,t);J.intro(Y),await Q(async()=>{let t=new xm,r=await q(`Loading your library`,async()=>(await B(t),Wu(t))),i=new Set(r.entries.map(e=>e.name)),a=e.filter(e=>!i.has(e));if(a.length>0)throw new L(`Not in your library: ${a.join(`, `)}`,{suggestion:"Run `skilless list` to see what you have."});if(J.warn(`This deletes ${e.join(`, `)} from every project, on every machine.`),J.dim(`Run \`skilless remove ${e.join(` `)}\` to take ${e.length===1?`it`:`them`} out of just this project.`),!(n.yes||await nm(`Delete ${e.join(`, `)}?`,!1))){J.info(`Nothing was deleted.`);return}Iu(e),Hu(e);let o=bu(),s=mu(n.cwd);for(let t of e)z(Ol(t)),delete o.skills[t],J.step(`Deleted ${t} from your library.`);xu(o),fu(s,e),fu(Zl(),e),await q(`Deleting from skilless.dev`,()=>B(t)),J.blank(),J.dim("Other checkouts will clean up on their next `skilless install`."),J.dim(`Restore at skilless.dev/skills within 30 days.`),t.report()})}),Oh=Um.extend({yes:I(),overwrite:I()});function kh(e){return a.readdirSync(e,{withFileTypes:!0}).filter(e=>e.isDirectory()).map(t=>({name:t.name,dir:S.join(e,t.name)})).filter(e=>R(S.join(e.dir,Ll))).sort((e,t)=>e.name.localeCompare(t.name))}const Ah=new b(`import`).description(`Import a directory of existing skills into your library.`).argument(`<dir>`,`A directory whose subdirectories each contain a SKILL.md.`).option(`--overwrite`,`Replace skills that already exist.`,!1).addOption(X.yes).addOption(X.cwd).action(async(e,t)=>{let n=Z(Oh,t);J.intro(Y),await Q(async()=>{let t=new xm,r=S.resolve(n.cwd,e);if(!R(r))throw new L(`${r} does not exist.`);let i=kh(r);if(i.length===0)throw new L(`No skills found in ${r}.`,{suggestion:`A skill is a directory containing a ${Ll}.`});let a=await q(`Loading your library`,async()=>(await B(t),Wu(t))),o=new Map(a.entries.map(e=>[e.name,e])),s=[],c=[];for(let e of i){if(!Vl(e.name)){c.push({name:e.name,reason:`invalid name`});continue}if(o.has(e.name)&&!n.overwrite){c.push({name:e.name,reason:`already in your library`});continue}try{s.push(Wl(e.dir,e.name))}catch(t){c.push({name:e.name,reason:t instanceof Error?t.message:`unreadable`})}}for(let e of c)J.warn(`Skipped ${e.name}: ${e.reason}.`);if(s.length===0){J.info(`Nothing to import.`),t.report();return}if(J.blank(),J.info(`Importing: ${s.map(e=>e.name).join(`, `)}`),!(n.yes||await nm(`Import ${s.length} skill(s)?`,!0)))return;let l=await q(`Importing ${s.length} skill(s)`,()=>Zu(t,s,o));for(let e of l)J.step(`Imported ${e} into your library.`);J.blank(),J.dim(`Run \`skilless add ${s[0]?.name??`<skill>`}\` to add one to this project.`),t.report()})}),jh=new b(`init`).description(`Create the local skilless directory.`).addOption(X.cwd).action(async e=>{Z(Um,e),J.intro(Y),await Q(async()=>{let e=!R(bl);rl(bl),J.step(`${e?`Created`:`Found`} your library at ${yl}.`),J.blank(),J.dim("Run `skilless create <name>` to make a skill."),J.dim("Run `skilless import <dir>` to bring in skills you already have."),hu()||J.dim("Run `skilless auth` to sync your skills with the cloud.")})}),Mh=Um.extend({project:P().optional(),copy:I().optional()}),Nh=new b(`install`).description(`Install every skill added to this project, and your global skills at the user level.`).option(`--copy`,`Write real files instead of symlinking into the store.`).addOption(X.project).addOption(X.cwd).action(async e=>{let t=Z(Mh,e);J.intro(Y),await Q(async()=>{let e=Gm(),n=Km(t.cwd,t.project),r=mu(t.cwd),i=await q(`Installing ${n}'s skills`,async()=>(await Lu(e),Tu(e,r,n,{copy:t.copy}))),{project:a,user:o}=i;for(let e of[...a.pruned,...o.pruned])J.dim(`Pruned ${e}, which is no longer in your library.`);for(let e of[...a.fetched,...o.fetched])J.dim(`Fetched ${e} from your library.`);for(let e of a.removed)J.dim(`Removed ${e}, which is no longer in this project.`);for(let e of o.removed)J.dim(`Removed ${e} from ${qm}, since it is no longer global.`);for(let e of a.written)J.step(`Installed ${e}.`);for(let e of o.written)J.step(`Installed ${e} globally.`);if(i.count===0){J.info(`No skills added to ${n} yet.`),J.dim("Run `skilless add <skill>` to add one.");return}await Ym(i,{copy:t.copy}),J.blank(),J.dim(Su(t.copy)?`Wrote real files into .agents/skills, and global skills into ~/.agents/skills.`:`Linked .agents/skills, and global skills in ~/.agents/skills, to your library.`)})}),Ph=Um.extend({project:Tc([I(),P()]).optional()});function Fh(e,t){let n=[];return e.global&&n.push(`global`),e.source&&n.push(`from ${fl(e.source.url)??e.source.url}`),e.local?t&&e.unsynced&&n.push(`not synced`):n.push(`not on this machine`),n.map(e=>` · ${e}`).join(``)}const Ih=new b(`list`).description(`List your skills, or the ones added to this project.`).option(`-p, --project [key]`,`List this project’s skills instead of your library.`).addOption(X.cwd).action(async e=>{let t=Z(Ph,e);J.intro(Y),await Q(async()=>{let e=new xm,n=await q(`Loading your library`,async()=>(await B(e),Wu(e)));if(t.project!==void 0){let r=Km(t.cwd,typeof t.project==`string`?t.project:void 0),i=Ku(n,await q(`Loading ${r}`,()=>Gu(e,r)));J.info(`${G.default.bold(r)}`),J.blank(),i.length===0&&J.dim("No skills in this project. Run `skilless add <skill>` to add one.");for(let t of i)J.dim(` ${t.name}${G.default.gray(Fh(t,e.api!==null))}`);e.report();return}n.entries.length===0&&J.dim("Your library is empty. Run `skilless create <name>` to make one.");for(let t of n.entries){let n=t.local?.editedAt??t.remote?.updatedAt??0,r=new Date(n).toISOString().slice(0,10);J.dim(` ${t.name.padEnd(28)} ${G.default.gray(r+Fh(t,e.api!==null))}`)}e.report()})}),Lh=Um.extend({yes:I(),user:I().optional()});function Rh(e,t){return R(e)?a.readdirSync(e,{withFileTypes:!0}).filter(e=>e.isDirectory()&&!e.isSymbolicLink()).map(n=>({name:n.name,dir:S.join(e,n.name),scope:t})).filter(e=>R(S.join(e.dir,Ll))):[]}const zh=new b(`migrate`).description(`Move this project's skills into your library and link them back. Offers your user-level skills too, as globals linked back at the user level.`).option(`--user`,`Migrate your user-level skills too, without asking.`).addOption(X.yes).addOption(X.cwd).action(async e=>{let t=Z(Lh,e);J.intro(Y),await Q(async()=>{let e=new xm,n=mu(t.cwd),r=pl(t.cwd),i=r?[kl,Al].flatMap(e=>Rh(S.join(n,e),`project`).filter(e=>{let t=gl(n,S.relative(n,e.dir));return t&&J.warn(`${e.name} is committed to this repo, so it was left alone. Remove it from git first to migrate it.`),!t})):[],a=[...Rh(Nl(),`user`),...Rh(Ml(),`user`)];if(r||J.dim(`No git remote here, so there are no project skills to migrate.`),i.length===0&&a.length===0){J.info(`Nothing to migrate.`);return}let o=await q(`Loading your library`,async()=>(await B(e),Wu(e))),s=new Map(o.entries.map(e=>[e.name,e])),c=async e=>{let t=new Map;for(let n of e)t.set(n.name,[...t.get(n.name)??[],n]);let n=[];for(let[e,r]of[...t].sort(([e],[t])=>e.localeCompare(t))){if(!Vl(e)){J.warn(`Skipped ${e}: not a valid skill name.`);continue}let t;try{t=r.map(t=>Wl(t.dir,e))}catch(t){J.warn(`Skipped ${e}: ${t instanceof Error?t.message:`unreadable`}.`);continue}let i=t[0];if(!i)continue;if(t.some(e=>e.contentHash!==i.contentHash)){J.warn(`Skipped ${e}: found more than one version (${r.map(e=>e.dir).join(`, `)}).`);continue}let a=s.get(e),o=a?.local?.contentHash??a?.remote?.contentHash;if(o&&o!==i.contentHash){J.warn(`Skipped ${e}: a different ${e} is already in your library. Rename one to migrate it.`);continue}n.push({skill:i,dirs:r.map(e=>e.dir),scope:r.some(e=>e.scope===`user`)?`user`:`project`,adopted:o!==void 0})}return n},l=await c(i);if(l.length>0&&(J.info(`Project skills in ${r}: ${l.map(e=>e.skill.name).join(`, `)}`),t.yes||await nm(`Move ${l.length} skill(s) into skilless and link them here?`,!0)||(l=[])),a.length>0){let e=[...new Set(a.map(e=>e.name))].sort();if(J.info(`User-level skills: ${e.join(`, `)}`),t.user||!t.yes&&rm&&await nm(`Would you also like to migrate your user-level skills? They become global and are linked back into ~/.agents/skills, so every project still gets them.`,!1)){let e=new Set(l.map(e=>e.skill.name)),t=await c([...a,...i.filter(e=>a.some(t=>t.name===e.name))]);l=[...l.filter(e=>!t.some(t=>t.skill.name===e.skill.name)),...t];for(let t of e)l.some(e=>e.skill.name===t)||J.warn(`Skipped ${t}: its project and user-level copies differ.`)}}if(l.length===0){J.info(`Nothing was migrated.`);return}let u=bu();for(let{skill:t,adopted:n}of l)Gl(t.name,t.files,t.editedAt),!n&&(await q(`Saving ${t.name} to your library`,()=>e.try(e=>e.putSkill(t.name,t.files,t.editedAt)))?u.skills[t.name]={contentHash:t.contentHash,editedAt:t.editedAt,syncedAt:Date.now()}:delete u.skills[t.name]);xu(u);for(let{dirs:e}of l)for(let t of e)z(t);let d=l.filter(e=>e.scope===`user`).map(e=>e.skill.name),f=l.filter(e=>e.scope===`project`).map(e=>e.skill.name);d.length>0&&Pu(d,!0),r&&f.length>0&&Mu(r,f),await q(`Saving to skilless.dev`,()=>B(e));for(let e of f)J.step(`Migrated ${e} into your library and this project.`);for(let e of d)J.step(`Migrated ${e} into your library as a global skill.`);r?await Ym(await q(`Updating this project`,()=>qu(e,n,r)),{yes:t.yes}):d.length>0&&await Ym(await q(`Linking your global skills`,()=>Xu(e)),{yes:t.yes}),e.report()})}),Bh=Um.extend({project:P().optional(),copy:I().optional()}),Vh=new b(`remove`).description(`Remove skills from this project. They stay in your library.`).argument(`<skills...>`,`Skills to remove.`).option(`--copy`,`Write real files instead of symlinking into the store.`).addOption(X.project).addOption(X.cwd).action(async(e,t)=>{let n=Z(Bh,t);J.intro(Y),await Q(async()=>{let t=new xm,r=Km(n.cwd,n.project),[i,a]=await q(`Loading your library`,async()=>(await B(t),[await Wu(t),new Set(await Gu(t,r))])),o=new Set(i.entries.filter(e=>e.global).map(e=>e.name)),s=[];for(let t of e){if(o.has(t)){J.warn(`${t} is global, so it is in every project.`),J.dim(` Run \`skilless add --not-global ${t}\` to take it out of every project.`);continue}if(!a.has(t)){J.warn(`${t} is not in this project.`);continue}s.push(t)}if(s.length===0){t.report();return}Nu(r,s);let c=mu(n.cwd),l=await q(`Updating this project`,async()=>(await B(t),qu(t,c,r,{copy:n.copy})));for(let e of s)J.step(`Removed ${e} from this project.`);await Ym(l,{copy:n.copy}),J.blank(),J.dim(`Run \`skilless delete ${s.join(` `)}\` to delete ${s.length===1?`it`:`them`}.`),t.report()})});function Hh(e,t,n,r){let i=[...new Set([...e.keys(),...t.keys()])].sort(),a=[];for(let o of i){let i=e.get(o),s=t.get(o),c=n.skills[o];if(i&&s){if(i.contentHash===s.contentHash){a.push({type:`noop`,name:o});continue}let e=!c||c.contentHash!==i.contentHash,t=!c||c.contentHash!==s.contentHash;if(e&&!t)a.push({type:`push`,name:o});else if(!e&&t)a.push({type:`pull`,name:o});else{let e=r??(i.editedAt>=s.editedAt?`push`:`pull`);a.push({type:e===`push`?`conflict-push`:`conflict-pull`,name:o})}continue}if(i&&!s){a.push({type:c?`delete-local`:`push`,name:o});continue}!i&&s&&a.push({type:c?`delete-remote`:`pull`,name:o})}return a}function Uh(e,t,n){return Wh(e,t===`push`?`remote`:`local`,n)}function Wh(e,t,n){let r=new Date().toISOString().replace(/[:.]/g,`-`),i=S.join(Dl,e,`${r}-${t}`);for(let e of n)al(S.join(i,e.path),e.contents);return i}async function Gh(e,t,n){let r=Array(e.length),i=0;return await Promise.all(Array.from({length:Math.min(t,e.length)},async()=>{for(;i<e.length;){let t=i++;r[t]=await n(e[t])}})),r}async function Kh(e,t,n){let r={actions:[],conflicts:[],skipped:[]},i=Date.now(),a=new Set;for(let e of t)e.type!==`delete-local`&&e.type!==`delete-remote`||(n.yes||await nm(e.type===`delete-local`?`Delete ${e.name} from this machine? It was deleted elsewhere.`:`Delete ${e.name} everywhere? It was deleted on this machine.`,!0)?a.add(e):r.skipped.push(e.name));let o=await Gh(t,8,async t=>{let{name:o}=t,s=n.local.get(o);switch(t.type){case`noop`:return s&&(n.state.skills[o]={contentHash:s.contentHash,editedAt:s.editedAt,syncedAt:i}),!0;case`push`:case`conflict-push`:if(!s)return!0;if(t.type===`conflict-push`){let t=await e.getSkill(o);t&&r.conflicts.push({name:o,kept:`push`,stashedAt:Uh(o,`push`,t.files)})}return n.remote.set(o,await e.putSkill(o,s.files,s.editedAt)),n.state.skills[o]={contentHash:s.contentHash,editedAt:s.editedAt,syncedAt:i},!0;case`pull`:case`conflict-pull`:{let a=await e.getSkill(o);return a?(t.type===`conflict-pull`&&s&&r.conflicts.push({name:o,kept:`pull`,stashedAt:Uh(o,`pull`,s.files)}),Gl(o,a.files,a.editedAt),n.state.skills[o]={contentHash:a.contentHash,editedAt:a.editedAt,syncedAt:i},!0):!0}case`delete-local`:return a.has(t)?(z(Ol(o)),delete n.state.skills[o],!0):!1;case`delete-remote`:return a.has(t)?(await e.deleteSkill(o),n.remote.delete(o),delete n.state.skills[o],!0):!1}});return r.actions=t.filter((e,t)=>o[t]),r.conflicts.sort((e,t)=>e.name.localeCompare(t.name)),r}function qh(e){switch(e.type){case`push`:return`Pushed ${e.name} to skilless.dev.`;case`pull`:return`Pulled ${e.name} from skilless.dev.`;case`conflict-push`:return`${e.name} changed in both places. Kept the copy on this machine.`;case`conflict-pull`:return`${e.name} changed in both places. Kept the copy from skilless.dev.`;case`delete-local`:return`Deleted ${e.name} from this machine.`;case`delete-remote`:return`Deleted ${e.name} everywhere.`;default:return null}}const Jh=Um.extend({yes:I(),push:I().optional(),pull:I().optional()}),Yh=new b(`sync`).description(`Sync your library with skilless.dev, in both directions, and update this project's skills and your global ones.`).option(`--push`,`On a conflict, keep the local copy.`).option(`--pull`,`On a conflict, keep the remote copy.`).addOption(X.yes).addOption(X.cwd).action(async e=>{let t=Z(Jh,e);J.intro(Y),await Q(async()=>{let e=Gm(),[n,r]=await q(`Checking skilless.dev`,async()=>{let t=await e.listSkills(),n=await Lu(e,t);return[n,n>0?await e.listSkills():t]}),i=new Map(ql().map(e=>[e.name,e])),a=new Map(r.map(e=>[e.name,e])),o=bu(),s=Hh(i,a,o,t.push?`push`:t.pull?`pull`:void 0),c=await q(`Syncing your library`,()=>Kh(e,s,{local:i,remote:a,state:o,yes:t.yes}));xu(o);let l=c.actions.map(qh).filter(e=>e!==null);for(let e of l)J.step(e);let[u,d]=await q(`Syncing your library`,async()=>{let t=[...a.values()],r=await Lu(e,t);return[n+r,r>0?await e.listSkills():t]});u>0&&J.step(`Sent ${u} change(s) made while offline.`),Fl(d),Uu(d);let f=pl(t.cwd),p=await q(f?`Updating this project`:`Updating your global skills`,async()=>{if(!f)return{user:Du(d.filter(e=>e.global).map(e=>e.name))};let n=await Tu(e,mu(t.cwd),f);return{...n,project:n.project}}),m=`project`in p?p.project:void 0,{user:h}=p;if(m){for(let e of m.added)J.step(`Linked ${e} into this project.`);for(let e of m.removed)J.step(`Unlinked ${e}, which is no longer in this project.`);for(let e of m.pruned)J.step(`Unlinked ${e}, which is no longer in your library.`)}for(let e of h.added)J.step(`Linked ${e} into ${qm}.`);for(let e of h.removed)J.step(`Unlinked ${e} from ${qm}, since it is no longer global.`);for(let e of h.pruned)J.step(`Unlinked ${e} from ${qm}, since it is no longer in your library.`);let ee=[m,h].reduce((e,t)=>e+(t?t.added.length+t.removed.length+t.pruned.length:0),0);if(l.length===0&&ee===0&&u===0&&J.info(`Everything is already in sync.`),c.conflicts.length>0){J.blank(),J.warn(`${c.conflicts.length} skill(s) changed in two places. The copy that lost is kept here:`);for(let e of c.conflicts)J.dim(` ${e.stashedAt}`)}await Ym({skipped:[...m?.skipped??[],...h.skipped]},{yes:t.yes}),c.skipped.length>0&&(J.blank(),J.dim(`Skipped ${c.skipped.join(`, `)}.`))})}),Xh=Um.extend({yes:I(),force:I()});function Zh(e){let t=fl(e.url)??e.url;return e.ref?`${t}#${e.ref}`:t}const Qh=new b(`update`).description(`Update skills added from a git repository to what the repository has now.`).argument(`[skills...]`,`Skills to update. Omit to update every skill added from a repository.`).option(`-f, --force`,`Replace skills you have edited too. Your copy is kept first.`,!1).addOption(X.yes).addOption(X.cwd).action(async(e,t)=>{let n=Z(Xh,t);J.intro(Y),await Q(async()=>{let t=new xm,r=await q(`Loading your library`,async()=>(await B(t),Wu(t))),i=new Map(r.entries.map(e=>[e.name,e])),a=r.entries.filter(e=>e.source!==null);if(e.length>0){let t=e.filter(e=>!i.has(e));if(t.length>0)throw new L(`Not in your library: ${t.join(`, `)}`,{suggestion:"Run `skilless list` to see what you have."});let n=e.filter(e=>!i.get(e)?.source);if(n.length>0)throw new L(`${n.join(`, `)} ${n.length===1?`was`:`were`} not added from a repository, so there is nothing to update from.`)}let o=e.length>0?a.filter(t=>e.includes(t.name)):a;if(o.length===0){J.info(`None of your skills were added from a repository.`),J.dim("Run `skilless add owner/repo` to add some."),t.report();return}let s=new Map;for(let e of o){let t=`${e.source.url}#${e.source.ref??``}`;s.set(t,[...s.get(t)??[],e])}let c=[],l=new Map,u=[],d=[],f=[],p=[];for(let e of s.values()){let r=e[0].source,i=Zh(r);await Dm({url:r.url,ref:r.ref,label:i},async r=>{for(let a of e){let e=Nm(r,a.source.path,a.name);if(!e){J.warn(`${a.name} is no longer in ${i}.`);continue}let o;try{o=Wl(e.dir,a.name)}catch(e){J.warn(`Skipped ${a.name}: ${e instanceof Error?e.message:e}`);continue}let s={...a.source,path:e.path,hash:o.contentHash},p=a.local?.contentHash??a.remote?.contentHash;if(o.contentHash===a.source.hash||p===o.contentHash){Vu(a.name,s),u.push(a.name);continue}if(p!==a.source.hash){if(!(n.force||rm&&!n.yes&&await nm(`You have edited ${a.name} since it came from ${i}. Replace your edits with what it has now?`))){d.push(a.name);continue}let e=a.local?.files??(await q(`Fetching your copy of ${a.name}`,()=>t.try(e=>e.getSkill(a.name))))?.files;if(!e){J.warn(`Couldn't fetch your copy of ${a.name} to keep it, so it was left alone.`);continue}f.push({name:a.name,dir:Wh(a.name,`update`,e)})}c.push(o),l.set(a.name,s)}},{interactive:rm}).then(()=>!0,e=>{if(!(e instanceof L))throw e;return J.warn(e.toString()),!1})||p.push(...e.map(e=>e.name))}J.blank();let m=await q(`Saving ${c.length} skill(s) to your library`,()=>Zu(t,c,i,l));for(let e of m)J.step(`Updated ${e}.`);if(u.length>0&&J.info(u.length===1?`${u[0]} is already up to date.`:`${u.length} skills are already up to date.`),d.length>0&&J.warn(`Kept your edits to ${d.join(`, `)}. Run \`skilless update ${d.join(` `)} --force\` to replace them.`),p.length>0&&J.warn(`Couldn't check ${p.join(`, `)}.`),f.length>0){J.blank(),J.dim(`Your edited copies are kept here:`);for(let e of f)J.dim(` ${e.dir}`)}t.report()})});le.name(Bm).description(Vm).version(Y).addCommand(jh).addCommand(oh).addCommand(Th).addCommand(Zm).addCommand(Qh).addCommand(Vh).addCommand(Dh).addCommand(Nh).addCommand(Yh).addCommand(Ah).addCommand(zh).addCommand(Ih).addCommand(Ch).parse();export{};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "skilless",
3
3
  "description": "Author skills once, sync them everywhere, install them per project.",
4
- "version": "0.0.4",
4
+ "version": "0.0.5",
5
5
  "license": "MIT",
6
6
  "homepage": "https://skilless.dev",
7
7
  "author": {