useakit 0.1.0-dev.7 → 0.1.0-dev.9
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.
- package/dist/index.mjs +31 -31
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,64 +1,64 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{parseArgs as e,styleText as t}from"node:util";import n,{stdin as r,stdout as i}from"node:process";import a,*as o from"node:readline";import{ReadStream as s}from"node:tty";import{existsSync as c}from"node:fs";import{dirname as l,join as u,relative as d,resolve as f}from"node:path";import{homedir as p}from"node:os";import{spawn as m}from"node:child_process";import{chmod as h,mkdir as g,readFile as _,rm as v,writeFile as y}from"node:fs/promises";import{createHash as b}from"node:crypto";var x=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t,t.exports),e=null),t.exports);const S=(()=>{let e=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g;return t=>{let n=0;for(e.lastIndex=0;e.test(t);)n+=1;return t.length-n}})(),ee=e=>e===12288||e>=65281&&e<=65376||e>=65504&&e<=65510,te=e=>e===8987||e===9001||e>=12272&&e<=12287||e>=12289&&e<=12350||e>=12441&&e<=12543||e>=12549&&e<=12591||e>=12593&&e<=12686||e>=12688&&e<=12771||e>=12783&&e<=12830||e>=12832&&e<=12871||e>=12880&&e<=19903||e>=65040&&e<=65049||e>=65072&&e<=65106||e>=65108&&e<=65126||e>=65128&&e<=65131||e>=127488&&e<=127490||e>=127504&&e<=127547||e>=127552&&e<=127560||e>=131072&&e<=196605||e>=196608&&e<=262141,ne=/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]|\u001b\]8;[^;]*;.*?(?:\u0007|\u001b\u005c)/y,
|
|
2
|
+
import{parseArgs as e,styleText as t}from"node:util";import n,{stdin as r,stdout as i}from"node:process";import a,*as o from"node:readline";import{ReadStream as s}from"node:tty";import{existsSync as c}from"node:fs";import{dirname as l,join as u,relative as d,resolve as f}from"node:path";import{homedir as p}from"node:os";import{spawn as m}from"node:child_process";import{chmod as h,mkdir as g,readFile as _,rm as v,writeFile as y}from"node:fs/promises";import{createHash as b}from"node:crypto";var x=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t,t.exports),e=null),t.exports);const S=(()=>{let e=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g;return t=>{let n=0;for(e.lastIndex=0;e.test(t);)n+=1;return t.length-n}})(),ee=e=>e===12288||e>=65281&&e<=65376||e>=65504&&e<=65510,te=e=>e===8987||e===9001||e>=12272&&e<=12287||e>=12289&&e<=12350||e>=12441&&e<=12543||e>=12549&&e<=12591||e>=12593&&e<=12686||e>=12688&&e<=12771||e>=12783&&e<=12830||e>=12832&&e<=12871||e>=12880&&e<=19903||e>=65040&&e<=65049||e>=65072&&e<=65106||e>=65108&&e<=65126||e>=65128&&e<=65131||e>=127488&&e<=127490||e>=127504&&e<=127547||e>=127552&&e<=127560||e>=131072&&e<=196605||e>=196608&&e<=262141,ne=/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]|\u001b\]8;[^;]*;.*?(?:\u0007|\u001b\u005c)/y,C=/[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y,w=/(?:(?![\uFF61-\uFF9F\uFF00-\uFFEF])[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\p{Script=Tangut}]){1,1000}/uy,re=/\t{1,1000}/y,ie=/[\u{1F1E6}-\u{1F1FF}]{2}|\u{1F3F4}[\u{E0061}-\u{E007A}]{2}[\u{E0030}-\u{E0039}\u{E0061}-\u{E007A}]{1,3}\u{E007F}|(?:\p{Emoji}\uFE0F\u20E3?|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation})(?:\u200D(?:\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F\u20E3?))*/uy,T=/(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y,ae=/\p{M}+/gu,oe={limit:1/0,ellipsis:``},se=(e,t={},n={})=>{let r=t.limit??1/0,i=t.ellipsis??``,a=t?.ellipsisWidth??(i?se(i,oe,n).width:0),o=n.controlWidth??0,s=n.tabWidth??8,c=n.emojiWidth??2,l=n.regularWidth??1,u=n.wideWidth??2,d=[[T,l],[ne,0],[C,o],[re,s],[ie,c],[w,u]],f=0,p=0,m=e.length,h=0,g=!1,_=m,v=Math.max(0,r-a),y=0,b=0,x=0,E=0;outer:for(;;){if(b>y||p>=m&&p>f){let t=e.slice(y,b)||e.slice(f,p);h=0;for(let e of t.replaceAll(ae,``)){let t=e.codePointAt(0)||0;if(E=ee(t)?2:te(t)?u:l,x+E>v&&(_=Math.min(_,Math.max(y,f)+h)),x+E>r){g=!0;break outer}h+=e.length,x+=E}y=b=0}if(p>=m)break outer;for(let t=0,n=d.length;t<n;t++){let[n,i]=d[t];if(n.lastIndex=p,n.test(e)){if(h=n===w?S(e.slice(p,n.lastIndex)):n===ie?1:n.lastIndex-p,E=h*i,x+E>v&&(_=Math.min(_,p+Math.floor((v-x)/i))),x+E>r){g=!0;break outer}x+=E,y=f,b=p,p=f=n.lastIndex;continue outer}}p+=1}return{width:g?v:x,index:g?_:m,truncated:g,ellipsed:g&&r>=a}},E={limit:1/0,ellipsis:``,ellipsisWidth:0},D=(e,t={})=>se(e,E,t).width,ce=`]8;;`,le=RegExp(`(?:\\[(?<code>\\d+)m|\\${ce}(?<uri>.*))`,`y`),ue=e=>{if(e>=30&&e<=37||e>=90&&e<=97)return 39;if(e>=40&&e<=47||e>=100&&e<=107)return 49;if(e===1||e===2)return 22;if(e===3)return 23;if(e===4)return 24;if(e===7)return 27;if(e===8)return 28;if(e===9)return 29;if(e===0)return 0},de=e=>`[${e}m`,fe=e=>`${ce}${e}`,pe=(e,t,n)=>{let r=t[Symbol.iterator](),i=!1,a=!1,o=e.at(-1),s=o===void 0?0:D(o),c=r.next(),l=r.next(),u=0;for(;!c.done;){let o=c.value,d=D(o);s+d<=n?e[e.length-1]+=o:(e.push(o),s=0),(o===`\x1B`||o===``)&&(i=!0,a=t.startsWith(ce,u+1)),i?a?o===`\x07`&&(i=!1,a=!1):o===`m`&&(i=!1):(s+=d,s===n&&!l.done&&(e.push(``),s=0)),c=l,l=r.next(),u+=o.length}o=e.at(-1),!s&&o!==void 0&&o.length&&e.length>1&&(e[e.length-2]+=e.pop())},me=e=>{let t=e.split(` `),n=t.length;for(;n&&!D(t[n-1]);)n--;return n===t.length?e:t.slice(0,n).join(` `)+t.slice(n).join(``)},he=(e,t,n={})=>{if(n.trim!==!1&&e.trim()===``)return``;let r=``,i,a,o=e.split(` `),s=[``],c=0;for(let e=0;e<o.length;e++){let r=o[e];if(n.trim!==!1){let e=s.at(-1)??``,t=e.trimStart();e.length!==t.length&&(s[s.length-1]=t,c=D(t))}e!==0&&(c>=t&&(n.wordWrap===!1||n.trim===!1)&&(s.push(``),c=0),(c||n.trim===!1)&&(s[s.length-1]+=` `,c++));let i=D(r);if(n.hard&&i>t){let e=t-c,n=1+Math.floor((i-e-1)/t);Math.floor((i-1)/t)<n&&s.push(``),pe(s,r,t),c=D(s.at(-1)??``)}else{if(c+i>t&&c&&i){if(n.wordWrap===!1&&c<t){pe(s,r,t),c=D(s.at(-1)??``);continue}s.push(``),c=0}c+i>t&&n.wordWrap===!1?(pe(s,r,t),c=D(s.at(-1)??``)):(s[s.length-1]+=r,c+=i)}}n.trim!==!1&&(s=s.map(e=>me(e)));let l=s.join(`
|
|
3
3
|
`),u=!1;for(let e=0;e<l.length;e++){let t=l[e];if(r+=t,u)u=!1;else if(u=t>=`\ud800`&&t<=`\udbff`,u)continue;if(t===`\x1B`||t===``){le.lastIndex=e+1;let t=le.exec(l)?.groups;if(t?.code!==void 0){let e=Number.parseFloat(t.code);i=e===39?void 0:e}else t?.uri!==void 0&&(a=t.uri.length===0?void 0:t.uri)}if(l[e+1]===`
|
|
4
4
|
`){a&&(r+=fe(``));let e=i?ue(i):void 0;i&&e&&(r+=de(e))}else t===`
|
|
5
5
|
`&&(i&&ue(i)&&(r+=de(i)),a&&(r+=fe(a)))}return r},ge=/\r?\n/;function O(e,t,n){return String(e).normalize().split(ge).map(e=>he(e,t,n)).join(`
|
|
6
|
-
`)}var k=(/* @__PURE__ */ x(((e,t)=>{let n={to(e,t){return t?`[${t+1};${e+1}H`:`[${e+1}G`},move(e,t){let n=``;return e<0?n+=`[${-e}D`:e>0&&(n+=`[${e}C`),t<0?n+=`[${-t}A`:t>0&&(n+=`[${t}B`),n},up:(e=1)=>`[${e}A`,down:(e=1)=>`[${e}B`,forward:(e=1)=>`[${e}C`,backward:(e=1)=>`[${e}D`,nextLine:(e=1)=>`\x1B[E`.repeat(e),prevLine:(e=1)=>`\x1B[F`.repeat(e),left:`\x1B[G`,hide:`\x1B[?25l`,show:`\x1B[?25h`,save:`\x1B7`,restore:`\x1B8`};t.exports={cursor:n,scroll:{up:(e=1)=>`\x1B[S`.repeat(e),down:(e=1)=>`\x1B[T`.repeat(e)},erase:{screen:`\x1B[2J`,up:(e=1)=>`\x1B[1J`.repeat(e),down:(e=1)=>`\x1B[J`.repeat(e),line:`\x1B[2K`,lineEnd:`\x1B[K`,lineStart:`\x1B[1K`,lines(e){let t=``;for(let r=0;r<e;r++)t+=this.line+(r<e-1?n.up():``);return e&&(t+=n.left),t}},beep:`\x07`}})))();function A(e,t,n){if(!n.some(e=>!e.disabled))return e;let r=e+t,i=Math.max(n.length-1,0),a=r<0?i:r>i?0:r;return n[a]?.disabled?A(a,t<0?-1:1,n):a}const j={actions:/* @__PURE__ */ new Set([`up`,`down`,`left`,`right`,`space`,`enter`,`cancel`]),aliases:/* @__PURE__ */ new Map([[`k`,`up`],[`j`,`down`],[`h`,`left`],[`l`,`right`],[``,`cancel`],[`escape`,`cancel`]]),messages:{cancel:`Canceled`,error:`Something went wrong`},withGuide:!0,accessible:void 0,date:{monthNames:[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`],messages:{required:`Please enter a valid date`,invalidMonth:`There are only 12 months in a year`,invalidDay:(e,t)=>`There are only ${e} days in ${t}`,afterMin:e=>`Date must be on or after ${e.toISOString().slice(0,10)}`,beforeMax:e=>`Date must be on or before ${e.toISOString().slice(0,10)}`}}};function _e(e){if(e!==void 0)return e;if(j.accessible!==void 0)return j.accessible;let t=process.env.ACCESSIBLE;return t!==void 0&&t!==``&&t!==`0`&&t!==`false`}function
|
|
6
|
+
`)}var k=(/* @__PURE__ */ x(((e,t)=>{let n={to(e,t){return t?`[${t+1};${e+1}H`:`[${e+1}G`},move(e,t){let n=``;return e<0?n+=`[${-e}D`:e>0&&(n+=`[${e}C`),t<0?n+=`[${-t}A`:t>0&&(n+=`[${t}B`),n},up:(e=1)=>`[${e}A`,down:(e=1)=>`[${e}B`,forward:(e=1)=>`[${e}C`,backward:(e=1)=>`[${e}D`,nextLine:(e=1)=>`\x1B[E`.repeat(e),prevLine:(e=1)=>`\x1B[F`.repeat(e),left:`\x1B[G`,hide:`\x1B[?25l`,show:`\x1B[?25h`,save:`\x1B7`,restore:`\x1B8`};t.exports={cursor:n,scroll:{up:(e=1)=>`\x1B[S`.repeat(e),down:(e=1)=>`\x1B[T`.repeat(e)},erase:{screen:`\x1B[2J`,up:(e=1)=>`\x1B[1J`.repeat(e),down:(e=1)=>`\x1B[J`.repeat(e),line:`\x1B[2K`,lineEnd:`\x1B[K`,lineStart:`\x1B[1K`,lines(e){let t=``;for(let r=0;r<e;r++)t+=this.line+(r<e-1?n.up():``);return e&&(t+=n.left),t}},beep:`\x07`}})))();function A(e,t,n){if(!n.some(e=>!e.disabled))return e;let r=e+t,i=Math.max(n.length-1,0),a=r<0?i:r>i?0:r;return n[a]?.disabled?A(a,t<0?-1:1,n):a}const j={actions:/* @__PURE__ */ new Set([`up`,`down`,`left`,`right`,`space`,`enter`,`cancel`]),aliases:/* @__PURE__ */ new Map([[`k`,`up`],[`j`,`down`],[`h`,`left`],[`l`,`right`],[``,`cancel`],[`escape`,`cancel`]]),messages:{cancel:`Canceled`,error:`Something went wrong`},withGuide:!0,accessible:void 0,date:{monthNames:[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`],messages:{required:`Please enter a valid date`,invalidMonth:`There are only 12 months in a year`,invalidDay:(e,t)=>`There are only ${e} days in ${t}`,afterMin:e=>`Date must be on or after ${e.toISOString().slice(0,10)}`,beforeMax:e=>`Date must be on or before ${e.toISOString().slice(0,10)}`}}};function _e(e){if(e!==void 0)return e;if(j.accessible!==void 0)return j.accessible;let t=process.env.ACCESSIBLE;return t!==void 0&&t!==``&&t!==`0`&&t!==`false`}function M(e,t){if(typeof e==`string`)return j.aliases.get(e)===t;for(let n of e)if(n!==void 0&&M(n,t))return!0;return!1}function ve(e,t){if(e===t)return;let n=e.split(`
|
|
7
7
|
`),r=t.split(`
|
|
8
|
-
`),i=Math.max(n.length,r.length),a=[];for(let e=0;e<i;e++)n[e]!==r[e]&&a.push(e);return{lines:a,numLinesBefore:n.length,numLinesAfter:r.length,numLines:i}}const
|
|
8
|
+
`),i=Math.max(n.length,r.length),a=[];for(let e=0;e<i;e++)n[e]!==r[e]&&a.push(e);return{lines:a,numLinesBefore:n.length,numLinesAfter:r.length,numLines:i}}const ye=globalThis.process.platform.startsWith(`win`),be=Symbol(`clack:cancel`);function xe(e){return e===be}function N(e,t){let n=e;n.isTTY&&n.setRawMode(t)}function Se({input:e=r,output:t=i,overwrite:n=!0,hideCursor:a=!0}={}){let c=o.createInterface({input:e,output:t,prompt:``,tabSize:1});o.emitKeypressEvents(e,c),e instanceof s&&e.isTTY&&e.setRawMode(!0);let l=(r,{name:i,sequence:s})=>{if(M([String(r),i,s],`cancel`)){a&&t.write(k.cursor.show),process.exit(0);return}if(!n)return;let c=i===`return`?0:-1,u=i===`return`?-1:0;o.moveCursor(t,c,u,()=>{o.clearLine(t,1,()=>{e.once(`keypress`,l)})})};return a&&t.write(k.cursor.hide),e.once(`keypress`,l),()=>{e.off(`keypress`,l),a&&t.write(k.cursor.show),e instanceof s&&e.isTTY&&!ye&&e.setRawMode(!1),c.terminal=!1,c.close()}}const Ce=e=>`columns`in e&&typeof e.columns==`number`?e.columns:80,we=e=>`rows`in e&&typeof e.rows==`number`?e.rows:20;function P(e,t,n,r=n,a=n,o){return O(t,Ce(e??i)-n.length,{hard:!0,trim:!1}).split(`
|
|
9
9
|
`).map((e,t,i)=>{let s=o?o(e,t):e;return t===0?`${r}${s}`:t===i.length-1?`${a}${s}`:`${n}${s}`}).join(`
|
|
10
|
-
`)}function
|
|
11
|
-
`),
|
|
12
|
-
`).length-1;this.output.write(k.cursor.move(-999,e*-1))}render(){let e=O(this._render(this)??``,process.stdout.columns,{hard:!0,trim:!1});if(e!==this._prevFrame){if(this.state===`initial`)this.output.write(k.cursor.hide);else{let t=
|
|
10
|
+
`)}function Te(e,t){if(`~standard`in e){let n=e[`~standard`].validate(t);return n instanceof Promise?n.then(e=>e.issues?.at(0)?.message):n.issues?.at(0)?.message}return e(t)}var Ee=class{input;output;_abortSignal;rl;opts;_render;_track=!1;_prevFrame=``;_subscribers=/* @__PURE__ */ new Map;_cursor=0;state=`initial`;error=``;value;userInput=``;get accessible(){return _e(this.opts.accessible)}constructor(e,t=!0){let{input:n=r,output:a=i,render:o,signal:s,...c}=e;this.opts=c,this.onKeypress=this.onKeypress.bind(this),this.close=this.close.bind(this),this.render=this.render.bind(this),this._render=o.bind(this),this._track=t,this._abortSignal=s,this.input=n,this.output=a}unsubscribe(){this._subscribers.clear()}setSubscriber(e,t){let n=this._subscribers.get(e)??[];n.push(t),this._subscribers.set(e,n)}on(e,t){this.setSubscriber(e,{cb:t})}once(e,t){this.setSubscriber(e,{cb:t,once:!0})}emit(e,...t){let n=this._subscribers.get(e)??[],r=[];for(let e of n)e.cb(...t),e.once&&r.push(()=>n.splice(n.indexOf(e),1));for(let e of r)e()}prompt(){return new Promise(e=>{if(this._abortSignal){if(this._abortSignal.aborted)return this.state=`cancel`,this.close(),e(be);this._abortSignal.addEventListener(`abort`,()=>{this.state=`cancel`,this.close()},{once:!0})}this.rl=a.createInterface({input:this.input,tabSize:2,prompt:``,escapeCodeTimeout:50,terminal:!0}),this.rl.prompt(),this.opts.initialUserInput!==void 0&&this._setUserInput(this.opts.initialUserInput,!0),this.input.on(`keypress`,this.onKeypress),N(this.input,!0),this.output.on(`resize`,this.render),this.render(),this.once(`submit`,()=>{this.output.write(k.cursor.show),this.output.off(`resize`,this.render),N(this.input,!1),e(this.value)}),this.once(`cancel`,()=>{this.output.write(k.cursor.show),this.output.off(`resize`,this.render),N(this.input,!1),e(be)})})}_isActionKey(e,t){return e===` `}_shouldSubmit(e,t){return!0}_setValue(e){this.value=e,this.emit(`value`,this.value)}_setUserInput(e,t){this.userInput=e??``,this.emit(`userInput`,this.userInput),t&&this._track&&this.rl&&(this.rl.write(this.userInput),this._cursor=this.rl.cursor)}_clearUserInput(){this.rl?.write(null,{ctrl:!0,name:`u`}),this._setUserInput(``)}async onKeypress(e,t){if(this.state!==`validating`){if(this._track&&t.name!==`return`&&(t.name&&this._isActionKey(e,t)&&this.rl?.write(null,{ctrl:!0,name:`h`}),this._cursor=this.rl?.cursor??0,this._setUserInput(this.rl?.line)),this.state===`error`&&(this.state=`active`),t?.name&&(!this._track&&j.aliases.has(t.name)&&this.emit(`cursor`,j.aliases.get(t.name)),j.actions.has(t.name)&&this.emit(`cursor`,t.name)),e&&(e.toLowerCase()===`y`||e.toLowerCase()===`n`)&&this.emit(`confirm`,e.toLowerCase()===`y`),this.emit(`key`,e,t),t?.name===`return`&&this._shouldSubmit(e,t)){if(this.opts.validate){let e=Te(this.opts.validate,this.value),t;e instanceof Promise?(this.state=`validating`,this.render(),t=await e):t=e,t&&(this.error=t instanceof Error?t.message:t,this.state=`error`,this.rl?.write(this.userInput))}this.state!==`error`&&(this.state=`submit`)}M([e,t?.name,t?.sequence],`cancel`)&&(this.state=`cancel`),(this.state===`submit`||this.state===`cancel`)&&this.emit(`finalize`),this.render(),(this.state===`submit`||this.state===`cancel`)&&this.close()}}close(){this.input.unpipe(),this.input.removeListener(`keypress`,this.onKeypress),this.output.write(`
|
|
11
|
+
`),N(this.input,!1),this.rl?.close(),this.rl=void 0,this.emit(`${this.state}`,this.value),this.unsubscribe()}restoreCursor(){let e=O(this._prevFrame,process.stdout.columns,{hard:!0,trim:!1}).split(`
|
|
12
|
+
`).length-1;this.output.write(k.cursor.move(-999,e*-1))}render(){let e=O(this._render(this)??``,process.stdout.columns,{hard:!0,trim:!1});if(e!==this._prevFrame){if(this.state===`initial`)this.output.write(k.cursor.hide);else{let t=ve(this._prevFrame,e),n=we(this.output);if(this.restoreCursor(),t){let r=Math.max(0,t.numLinesAfter-n),i=Math.max(0,t.numLinesBefore-n),a=t.lines.find(e=>e>=r);if(a===void 0){this._prevFrame=e;return}if(t.lines.length===1){this.output.write(k.cursor.move(0,a-i)),this.output.write(k.erase.lines(1));let t=e.split(`
|
|
13
13
|
`);this.output.write(t[a]),this._prevFrame=e,this.output.write(k.cursor.move(0,t.length-a-1));return}if(t.lines.length>1){if(r<i)a=r;else{let e=a-i;e>0&&this.output.write(k.cursor.move(0,e))}this.output.write(k.erase.down());let t=e.split(`
|
|
14
14
|
`).slice(a);this.output.write(t.join(`
|
|
15
|
-
`)),this._prevFrame=e;return}}this.output.write(k.erase.down())}this.output.write(e),this.state===`initial`&&(this.state=`active`),this._prevFrame=e}}},
|
|
16
|
-
`);_.push(a),v+=a.length}if(v>d){let t=0,n=0,r=v,i=e-y,a=d,o=()=>Je(_,r,0,i,a),s=()=>Je(_,r,i+1,_.length,a,!0);m?({lineCount:r,removals:t}=o(),r>a&&(h||--a,{lineCount:r,removals:n}=s())):(h||--a,{lineCount:r,removals:n}=s(),r>a&&(--a,{lineCount:r,removals:t}=o())),t>0&&(m=!0,_.splice(0,t)),n>0&&(h=!0,_.splice(_.length-n,n))}let x=[];m&&x.push(u);for(let e of _)for(let t of e)x.push(t);return h&&x.push(u),x},
|
|
15
|
+
`)),this._prevFrame=e;return}}this.output.write(k.erase.down())}this.output.write(e),this.state===`initial`&&(this.state=`active`),this._prevFrame=e}}},De=class extends Ee{options;cursor=0;get _value(){return this.options[this.cursor]?.value}get _enabledOptions(){return this.options.filter(e=>e.disabled!==!0)}toggleAll(){let e=this._enabledOptions,t=this.value!==void 0&&this.value.length===e.length;this.value=t?[]:e.map(e=>e.value)}toggleInvert(){let e=this.value;if(!e)return;let t=this._enabledOptions.filter(t=>!e.includes(t.value));this.value=t.map(e=>e.value)}toggleValue(){this.value===void 0&&(this.value=[]);let e=this.value.includes(this._value);this.value=e?this.value.filter(e=>e!==this._value):[...this.value,this._value]}constructor(e){super(e,!1),this.options=e.options,this.value=[...e.initialValues??[]];let t=Math.max(this.options.findIndex(({value:t})=>t===e.cursorAt),0);this.cursor=this.options[t]?.disabled?A(t,1,this.options):t,this.on(`key`,(e,t)=>{t.name===`a`&&this.toggleAll(),t.name===`i`&&this.toggleInvert()}),this.on(`cursor`,e=>{switch(e){case`left`:case`up`:this.cursor=A(this.cursor,-1,this.options);break;case`down`:case`right`:this.cursor=A(this.cursor,1,this.options);break;case`space`:this.toggleValue()}})}};let Oe=class extends Ee{options;cursor=0;get _selectedValue(){return this.options[this.cursor]}changeValue(){let e=this._selectedValue;this.value=e===void 0?void 0:e.value}constructor(e){super(e,!1),this.options=e.options;let t=this.options.findIndex(({value:t})=>t===e.initialValue),n=t===-1?0:t;this.cursor=this.options[n]?.disabled?A(n,1,this.options):n,this.changeValue(),this.on(`cursor`,e=>{switch(e){case`left`:case`up`:this.cursor=A(this.cursor,-1,this.options);break;case`down`:case`right`:this.cursor=A(this.cursor,1,this.options)}this.changeValue()})}};function ke(){return n.platform===`win32`?!!n.env.CI||!!n.env.WT_SESSION||!!n.env.TERMINUS_SUBLIME||n.env.ConEmuTask===`{cmd::Cmder}`||n.env.TERM_PROGRAM===`Terminus-Sublime`||n.env.TERM_PROGRAM===`vscode`||n.env.TERM===`xterm-256color`||n.env.TERM===`alacritty`||n.env.TERMINAL_EMULATOR===`JetBrains-JediTerm`:n.env.TERM!==`linux`}const F=ke(),Ae=()=>process.env.CI===`true`,I=(e,t)=>F?e:t,je=I(`◆`,`*`),Me=I(`■`,`x`),Ne=I(`▲`,`x`),Pe=I(`◇`,`o`),Fe=I(`┌`,`T`),L=I(`│`,`|`),R=I(`└`,`—`),Ie=I(`●`,`>`),Le=I(`○`,` `),Re=I(`◻`,`[•]`),ze=I(`◼`,`[+]`),Be=I(`◻`,`[ ]`),Ve=I(`●`,`•`),He=I(`◆`,`*`),Ue=I(`▲`,`!`),We=I(`■`,`x`),Ge=e=>{switch(e){case`initial`:case`active`:return t(`cyan`,je);case`cancel`:return t(`red`,Me);case`error`:return t(`yellow`,Ne);case`submit`:return t(`green`,Pe);case`validating`:return t(`dim`,je)}},Ke=e=>{switch(e){case`initial`:case`active`:return t(`cyan`,L);case`cancel`:return t(`red`,L);case`error`:return t(`yellow`,L);case`submit`:return t(`green`,L)}};function qe(e,n){let r=[`${n?`${t(`cyan`,L)} `:``}${e.join(` • `)}`];return n&&r.push(t(`cyan`,R)),r}const Je=(e,t,n,r,i,a=!1)=>{let o=t,s=0;if(a)for(let t=r-1;t>=n;t--){let n=e[t];if(n&&(o-=n.length),s++,o<=i)break}else for(let t=n;t<r;t++){let n=e[t];if(n&&(o-=n.length),s++,o<=i)break}return{lineCount:o,removals:s}},Ye=({cursor:e,options:n,style:r,output:i=process.stdout,maxItems:a=1/0,columnPadding:o=0,rowPadding:s=4})=>{let c=Ce(i)-o,l=we(i),u=t(`dim`,`...`),d=Math.max(l-s,0),f=Math.max(Math.min(a,d),5),p=0;e>=f-3&&(p=Math.max(Math.min(e-f+3,n.length-f),0));let m=f<n.length&&p>0,h=f<n.length&&p+f<n.length,g=Math.min(p+f,n.length),_=[],v=0;m&&v++,h&&v++;let y=p+ +!!m,b=g-+!!h;for(let t=y;t<b;t++){let i=n[t],a=O(i?r(i,t===e):``,c,{hard:!0,trim:!1}).split(`
|
|
16
|
+
`);_.push(a),v+=a.length}if(v>d){let t=0,n=0,r=v,i=e-y,a=d,o=()=>Je(_,r,0,i,a),s=()=>Je(_,r,i+1,_.length,a,!0);m?({lineCount:r,removals:t}=o(),r>a&&(h||--a,{lineCount:r,removals:n}=s())):(h||--a,{lineCount:r,removals:n}=s(),r>a&&(--a,{lineCount:r,removals:t}=o())),t>0&&(m=!0,_.splice(0,t)),n>0&&(h=!0,_.splice(_.length-n,n))}let x=[];m&&x.push(u);for(let e of _)for(let t of e)x.push(t);return h&&x.push(u),x},Xe=[`${t(`dim`,`↑/↓`)} to navigate`,`${t(`dim`,`Space:`)} select`,`${t(`dim`,`Enter:`)} confirm`],z=(e,t)=>e.split(`
|
|
17
17
|
`).map(e=>t(e)).join(`
|
|
18
|
-
`),
|
|
19
|
-
${t(`reset`,t(`dim`,`Press ${t([`gray`,`bgWhite`,`inverse`],` space `)} to select, ${t(`gray`,t(`bgWhite`,t(`inverse`,` enter `)))} to submit`))}`},render(){let r=e.withGuide??j.withGuide,a=
|
|
18
|
+
`),Ze=e=>{let n=(e,n)=>{let r=e.label??String(e.value);return n===`disabled`?`${t(`gray`,Be)} ${z(r,e=>t([`strikethrough`,`gray`],e))}${e.hint?` ${t(`dim`,`(${e.hint??`disabled`})`)}`:``}`:n===`active`?`${t(`cyan`,Re)} ${r}${e.hint?` ${t(`dim`,`(${e.hint})`)}`:``}`:n===`selected`?`${t(`green`,ze)} ${z(r,e=>t(`dim`,e))}${e.hint?` ${t(`dim`,`(${e.hint})`)}`:``}`:n===`cancelled`?`${z(r,e=>t([`strikethrough`,`dim`],e))}`:n===`active-selected`?`${t(`green`,ze)} ${r}${e.hint?` ${t(`dim`,`(${e.hint})`)}`:``}`:n===`submitted`?`${z(r,e=>t(`dim`,e))}`:`${t(`dim`,Be)} ${z(r,e=>t(`dim`,e))}`},r=e.required??!0,i=e.showInstructions??!0;return new De({options:e.options,signal:e.signal,input:e.input,output:e.output,initialValues:e.initialValues,required:r,cursorAt:e.cursorAt,validate(e){if(r&&(e===void 0||e.length===0))return`Please select at least one option.
|
|
19
|
+
${t(`reset`,t(`dim`,`Press ${t([`gray`,`bgWhite`,`inverse`],` space `)} to select, ${t(`gray`,t(`bgWhite`,t(`inverse`,` enter `)))} to submit`))}`},render(){let r=e.withGuide??j.withGuide,a=P(e.output,e.message,r?`${Ke(this.state)} `:``,`${Ge(this.state)} `),o=`${r?`${t(`gray`,L)}
|
|
20
20
|
`:``}${a}
|
|
21
|
-
`,s=this.value??[],c=(e,t)=>{if(e.disabled)return n(e,`disabled`);let r=s.includes(e.value);return t&&r?n(e,`active-selected`):r?n(e,`selected`):n(e,t?`active`:`inactive`)};switch(this.state){case`submit`:{let i=this.options.filter(({value:e})=>s.includes(e)).map(e=>n(e,`submitted`)).join(t(`dim`,`, `))||t(`dim`,`none`);return`${o}${
|
|
21
|
+
`,s=this.value??[],c=(e,t)=>{if(e.disabled)return n(e,`disabled`);let r=s.includes(e.value);return t&&r?n(e,`active-selected`):r?n(e,`selected`):n(e,t?`active`:`inactive`)};switch(this.state){case`submit`:{let i=this.options.filter(({value:e})=>s.includes(e)).map(e=>n(e,`submitted`)).join(t(`dim`,`, `))||t(`dim`,`none`);return`${o}${P(e.output,i,r?`${t(`gray`,L)} `:``)}`}case`cancel`:{let i=this.options.filter(({value:e})=>s.includes(e)).map(e=>n(e,`cancelled`)).join(t(`dim`,`, `));return i.trim()===``?`${o}${t(`gray`,L)}`:`${o}${P(e.output,i,r?`${t(`gray`,L)} `:``)}${r?`
|
|
22
22
|
${t(`gray`,L)}`:``}`}case`error`:{let n=r?`${t(`yellow`,L)} `:``,i=this.error.split(`
|
|
23
23
|
`).map((e,n)=>n===0?`${r?`${t(`yellow`,R)} `:``}${t(`yellow`,e)}`:` ${e}`).join(`
|
|
24
24
|
`),a=o.split(`
|
|
25
25
|
`).length,s=i.split(`
|
|
26
|
-
`).length+1;return`${o}${n}${
|
|
26
|
+
`).length+1;return`${o}${n}${Ye({output:e.output,options:this.options,cursor:this.cursor,maxItems:e.maxItems,columnPadding:n.length,rowPadding:a+s,style:c}).join(`
|
|
27
27
|
${n}`)}
|
|
28
28
|
${i}
|
|
29
29
|
`}default:{let n=r?`${t(`cyan`,L)} `:``,a=o.split(`
|
|
30
|
-
`).length,s=i?qe(
|
|
31
|
-
`),u=s.length+1;return`${o}${n}${
|
|
30
|
+
`).length,s=i?qe(Xe,r):r?[t(`cyan`,R)]:[],l=s.join(`
|
|
31
|
+
`),u=s.length+1;return`${o}${n}${Ye({output:e.output,options:this.options,cursor:this.cursor,maxItems:e.maxItems,columnPadding:n.length,rowPadding:a+u,style:c}).join(`
|
|
32
32
|
${n}`)}
|
|
33
33
|
${l}
|
|
34
|
-
`}}}}).prompt()},
|
|
34
|
+
`}}}}).prompt()},B={message:(e=[],{symbol:n=t(`gray`,L),secondarySymbol:r=t(`gray`,L),output:i=process.stdout,spacing:a=1,withGuide:o}={})=>{let s=[],c=o??j.withGuide,l=c?r:``,u=c?`${n} `:``,d=c?`${r} `:``;for(let e=0;e<a;e++)s.push(l);let f=Array.isArray(e)?e:e.split(`
|
|
35
35
|
`);if(f.length>0){let[e,...t]=f;e.length>0?s.push(`${u}${e}`):s.push(c?n:``);for(let e of t)e.length>0?s.push(`${d}${e}`):s.push(c?r:``)}i.write(`${s.join(`
|
|
36
36
|
`)}
|
|
37
|
-
`)},info:(e,n)=>{
|
|
37
|
+
`)},info:(e,n)=>{B.message(e,{...n,symbol:t(`blue`,Ve)})},success:(e,n)=>{B.message(e,{...n,symbol:t(`green`,He)})},step:(e,n)=>{B.message(e,{...n,symbol:t(`green`,Pe)})},warn:(e,n)=>{B.message(e,{...n,symbol:t(`yellow`,Ue)})},warning:(e,t)=>{B.warn(e,t)},error:(e,n)=>{B.message(e,{...n,symbol:t(`red`,We)})}},Qe=(e=``,n)=>{let r=n?.output??process.stdout,i=n?.withGuide??j.withGuide?`${t(`gray`,R)} `:``;r.write(`${i}${t(`red`,e)}
|
|
38
38
|
|
|
39
|
-
`)},
|
|
40
|
-
`)},
|
|
39
|
+
`)},V=(e=``,n)=>{let r=n?.output??process.stdout,i=n?.withGuide??j.withGuide?`${t(`gray`,Fe)} `:``;r.write(`${i}${e}
|
|
40
|
+
`)},H=(e=``,n)=>{let r=n?.output??process.stdout,i=n?.withGuide??j.withGuide?`${t(`gray`,L)}
|
|
41
41
|
${t(`gray`,R)} `:``;r.write(`${i}${e}
|
|
42
42
|
|
|
43
|
-
`)}
|
|
43
|
+
`)},$e=e=>t(`magenta`,e),et=({indicator:e=`dots`,onCancel:n,output:r=process.stdout,cancelMessage:i,errorMessage:a,frames:o=F?[`◒`,`◐`,`◓`,`◑`]:[`•`,`o`,`O`,`0`],delay:s=F?80:120,signal:c,...l}={})=>{let u=Ae(),d,f,p=!1,m=!1,h=``,g,_=performance.now(),v=Ce(r),y=l?.styleFrame??$e,b=e=>{let t=e>1?a??j.messages.error:i??j.messages.cancel;m=e===1,p&&(T(t,e),m&&typeof n==`function`&&n())},x=()=>b(2),S=()=>b(1),ee=()=>{process.on(`uncaughtExceptionMonitor`,x),process.on(`unhandledRejection`,x),process.on(`SIGINT`,S),process.on(`SIGTERM`,S),process.on(`exit`,b),c&&c.addEventListener(`abort`,S)},te=()=>{process.removeListener(`uncaughtExceptionMonitor`,x),process.removeListener(`unhandledRejection`,x),process.removeListener(`SIGINT`,S),process.removeListener(`SIGTERM`,S),process.removeListener(`exit`,b),c&&c.removeEventListener(`abort`,S)},ne=()=>{if(g===void 0)return;u&&r.write(`
|
|
44
44
|
`);let e=O(g,v,{hard:!0,trim:!1}).split(`
|
|
45
|
-
`);e.length>1&&r.write(k.cursor.up(e.length-1)),r.write(k.cursor.to(0)),r.write(k.erase.down())},
|
|
46
|
-
`);let i=0,a=0;ee(),f=setInterval(()=>{if(u&&h===g)return;ne(),g=h;let t=y(o[i]),n;if(u)n=`${t} ${h}...`;else if(e===`timer`)n=`${t} ${h} ${
|
|
45
|
+
`);e.length>1&&r.write(k.cursor.up(e.length-1)),r.write(k.cursor.to(0)),r.write(k.erase.down())},C=e=>e.replace(/\.+$/,``),w=e=>{let t=(performance.now()-e)/1e3,n=Math.floor(t/60),r=Math.floor(t%60);return n>0?`[${n}m ${r}s]`:`[${r}s]`},re=l.withGuide??j.withGuide,ie=(n=``)=>{p=!0,d=Se({output:r}),h=C(n),_=performance.now(),re&&r.write(`${t(`gray`,L)}
|
|
46
|
+
`);let i=0,a=0;ee(),f=setInterval(()=>{if(u&&h===g)return;ne(),g=h;let t=y(o[i]),n;if(u)n=`${t} ${h}...`;else if(e===`timer`)n=`${t} ${h} ${w(_)}`;else{let e=`.`.repeat(Math.floor(a)).slice(0,3);n=`${t} ${h}${e}`}let s=O(n,v,{hard:!0,trim:!1});r.write(s),i=i+1<o.length?i+1:0,a=a<4?a+.125:0},s)},T=(n=``,i=0,a=!1)=>{if(!p)return;p=!1,clearInterval(f),ne();let o=i===0?t(`green`,Pe):i===1?t(`red`,Me):t(`red`,Ne);h=n??h,a||(e===`timer`?r.write(`${o} ${h} ${w(_)}
|
|
47
47
|
`):r.write(`${o} ${h}
|
|
48
|
-
`)),te(),d()};return{start:
|
|
48
|
+
`)),te(),d()};return{start:ie,stop:(e=``)=>T(e,0),message:(e=``)=>{h=C(e??h)},cancel:(e=``)=>T(e,1),error:(e=``)=>T(e,2),clear:()=>T(``,0,!0),get isCancelled(){return m}}},tt=[`${t(`dim`,`↑/↓`)} to navigate`,`${t(`dim`,`Enter:`)} confirm`],U=(e,t)=>e.includes(`
|
|
49
49
|
`)?e.split(`
|
|
50
50
|
`).map(e=>t(e)).join(`
|
|
51
|
-
`):t(e),
|
|
51
|
+
`):t(e),nt=e=>{let n=(e,n)=>{if(e===void 0)return``;let r=e.label??String(e.value);switch(n){case`disabled`:return`${t(`gray`,Le)} ${U(r,e=>t(`gray`,e))}${e.hint?` ${t(`dim`,`(${e.hint??`disabled`})`)}`:``}`;case`selected`:return`${U(r,e=>t(`dim`,e))}`;case`active`:return`${t(`green`,Ie)} ${r}${e.hint?` ${t(`dim`,`(${e.hint})`)}`:``}`;case`cancelled`:return`${U(r,e=>t([`strikethrough`,`dim`],e))}`;default:return`${t(`dim`,Le)} ${U(r,e=>t(`dim`,e))}`}},r=e.showInstructions??!0;return new Oe({options:e.options,signal:e.signal,input:e.input,output:e.output,initialValue:e.initialValue,render(){let i=e.withGuide??j.withGuide,a=`${Ge(this.state)} `,o=`${Ke(this.state)} `,s=P(e.output,e.message,o,a),c=`${i?`${t(`gray`,L)}
|
|
52
52
|
`:``}${s}
|
|
53
|
-
`;switch(this.state){case`submit`:{let r=i?`${t(`gray`,L)} `:``;return`${c}${
|
|
53
|
+
`;switch(this.state){case`submit`:{let r=i?`${t(`gray`,L)} `:``;return`${c}${P(e.output,n(this.options[this.cursor],`selected`),r)}`}case`cancel`:{let r=i?`${t(`gray`,L)} `:``;return`${c}${P(e.output,n(this.options[this.cursor],`cancelled`),r)}${i?`
|
|
54
54
|
${t(`gray`,L)}`:``}`}default:{let a=i?`${t(`cyan`,L)} `:``,o=c.split(`
|
|
55
|
-
`).length,s=r?qe(
|
|
56
|
-
`),u=s.length+1;return`${c}${a}${
|
|
55
|
+
`).length,s=r?qe(tt,i):i?[t(`cyan`,R)]:[],l=s.join(`
|
|
56
|
+
`),u=s.length+1;return`${c}${a}${Ye({output:e.output,cursor:this.cursor,options:this.options,maxItems:e.maxItems,columnPadding:a.length,rowPadding:o+u,style:(e,t)=>n(e,e.disabled?`disabled`:t?`active`:`inactive`)}).join(`
|
|
57
57
|
${a}`)}
|
|
58
58
|
${l}
|
|
59
|
-
`}}}}).prompt()};`${t(`gray`,L)}`;var
|
|
60
|
-
`,{mode:384}),await h(n,384)}const
|
|
61
|
-
`)}async function
|
|
59
|
+
`}}}}).prompt()};`${t(`gray`,L)}`;var rt=`0.1.0`;const W=[{id:`claude-code`,name:`Claude Code`,projectDir:`.claude/skills`,globalDir:`.claude/skills`,marker:`.claude`},{id:`codex`,name:`Codex`,projectDir:`.agents/skills`,globalDir:`.agents/skills`,marker:`.codex`},{id:`cursor`,name:`Cursor`,projectDir:`.agents/skills`,globalDir:`.cursor/skills`,marker:`.cursor`},{id:`gemini-cli`,name:`Gemini CLI`,projectDir:`.agents/skills`,globalDir:`.gemini/skills`,marker:`.gemini`}],it=e=>e===`global`?p():process.cwd();function at(e=p()){return W.filter(t=>c(u(e,t.marker)))}function G(e){return W.find(t=>t.id===e)}function ot(e,t,n=it(t)){let r=e.map(e=>f(n,t===`global`?e.globalDir:e.projectDir));return[...new Set(r)]}const K=()=>!!(process.stdin.isTTY&&process.stdout.isTTY)&&!process.env.CI;function q(e){return xe(e)&&(Qe(`Cancelled.`),process.exit(130)),e}async function st(e,t){if(e.length>0)return e.map(e=>{let t=G(e);if(!t)throw Error(`Unknown agent "${e}". Use one of: ${W.map(e=>e.id).join(`, `)}.`);return t});let n=at(),r=n.length>0?n:[G(`claude-code`)];return!t||!K()?r:q(await Ze({message:`Which agents should get the skills?`,options:W.map(e=>({value:e.id,label:e.name,hint:n.includes(e)?`detected`:void 0})),initialValues:r.map(e=>e.id),required:!0})).map(e=>G(e))}async function ct(e,t){return e?`global`:!t||!K()?`project`:q(await nt({message:`Where should they go?`,options:[{value:`project`,label:`This project`,hint:process.cwd()},{value:`global`,label:`Everywhere`,hint:`your home folder`}],initialValue:`project`}))}async function lt(e,t,n){if(t.length>0)return t.map(t=>{let n=e.filter(e=>e.name===t);if(n.length===0)throw Error(`There's no skill named "${t}" in your agent kit. See them with \`a-kit list\`.`);if(n.length>1)throw Error(`More than one of your organizations has a skill named "${t}" (${n.map(e=>e.organizationName).join(`, `)}). Run \`a-kit add\` and pick it from the list.`);return n[0]});if(!n||!K())throw Error("Name the skills to add, like `a-kit add my-skill`.");let r=q(await Ze({message:`Which skills?`,options:e.map(e=>({value:e.id,label:J(e),hint:e.description.length>60?`${e.description.slice(0,57)}…`:e.description})),required:!0}));return e.filter(e=>r.includes(e.id))}const J=e=>e.organizationName?`${e.name} (${e.organizationName})`:e.name;var Y=class extends Error{status;code;constructor(e,t,n){super(n),this.status=e,this.code=t}};function X(e,t,n=fetch){async function r(r,i={}){let a;try{a=await n(`${e}${r}`,{...i,headers:{"User-Agent":`a-kit/${rt}`,...i.body?{"Content-Type":`application/json`}:{},...t?{Authorization:`Bearer ${t}`}:{},...i.headers}})}catch{throw new Y(0,`NETWORK`,`Couldn't reach ${e}.`)}if(!a.ok){let e=await a.json().catch(()=>null);throw a.status===401?new Y(401,`UNAUTHORIZED`,"You're not logged in. Run `a-kit login`."):new Y(a.status,e?.code??`HTTP_ERROR`,e?.message??`${i.method??`GET`} ${r} failed (${a.status})`)}return a}let i=async(e,t)=>await(await r(e,t)).json();return{me:()=>i(`/me`),logout:()=>r(`/auth/logout`,{method:`POST`}),startLogin:()=>i(`/auth/cli`,{method:`POST`}),pollLogin:e=>i(`/auth/cli/token`,{method:`POST`,body:JSON.stringify({deviceCode:e})}),listSkills:async()=>{let[e,t]=await Promise.all([i(`/skills`),i(`/orgs`)]);if(t.length<2)return e;let n=new Map(t.map(e=>[e.id,e.name]));return e.map(e=>({...e,organizationName:n.get(e.organizationId)}))},getSkill:e=>i(`/skills/${e}`),getBlob:async(e,t)=>new Uint8Array(await(await r(`/skills/${e}/blobs/${t}`)).arrayBuffer())}}function ut(e){let[t,n]=process.platform===`darwin`?[`open`,[e]]:process.platform===`win32`?[`cmd`,[`/c`,`start`,``,e.replace(/&/g,`^&`)]]:[`xdg-open`,[e]];try{let e=m(t,n,{stdio:`ignore`,detached:!0});e.on(`error`,()=>{}),e.unref()}catch{}}function Z(){return(process.env.AGENT_KIT_API_URL??`https://api-dev.agent-kit.fausanchez.com`??`http://localhost:8787`).replace(/\/+$/,``)}function dt(){return process.env.AGENT_KIT_CONFIG_DIR?process.env.AGENT_KIT_CONFIG_DIR:process.platform===`win32`&&process.env.APPDATA?u(process.env.APPDATA,`agent-kit`):u(process.env.XDG_CONFIG_HOME??u(p(),`.config`),`agent-kit`)}const ft=()=>u(dt(),`credentials.json`);async function pt(){try{return JSON.parse(await _(ft(),`utf8`))}catch{return{}}}async function mt(){return(await pt())[Z()]??null}async function ht(e){let t=await pt();e?t[Z()]=e:delete t[Z()];let n=ft();await g(l(n),{recursive:!0,mode:448}),await y(n,JSON.stringify(t,null,2)+`
|
|
60
|
+
`,{mode:384}),await h(n,384)}const gt=e=>new Promise(t=>setTimeout(t,e));async function _t(){let e=await X(Z()).startLogin();B.step(`Your code: ${e.userCode}\nApprove it in your browser: ${e.verificationUrl}`),ut(e.verificationUrl);let t=et();t.start(`Waiting for you to approve it`);let n=X(Z()),r=Date.now()+e.expiresIn*1e3;for(;Date.now()<r;){await gt(e.interval*1e3);let r;try{r=await n.pollLogin(e.deviceCode)}catch(e){if(e instanceof Y&&e.status===410)break;if(e instanceof Y&&e.code===`NETWORK`)continue;throw t.error(`Login failed`),e}if(r.status===`approved`){let n={token:r.token,user:r.user,webUrl:new URL(e.verificationUrl).origin};return await ht(n),t.stop(`Logged in as ${r.user.email}`),n}}throw t.error(`The code expired`),Error(`The login expired before it was approved. Run it again.`)}async function vt(){let e=await mt();if(!e)return null;try{let t=await X(Z(),e.token).me();return{...e,user:t}}catch(e){if(e instanceof Y&&e.status===401)return await ht(null),null;throw e}}async function yt(){let e=await mt();if(!e)throw Error("You're not logged in. Run `a-kit login` first.");return{api:X(Z(),e.token),credentials:e}}const bt={maxFiles:200,maxFileBytes:1048576,maxSkillBytes:10485760,maxPathLength:255},xt=/[\u0000-\u001f\u007f\\:]/;function St(e){if(e.trim()===``)return`The path is empty.`;if(e.length>bt.maxPathLength)return`Paths can be at most ${bt.maxPathLength} characters.`;if(e.startsWith(`/`))return`Use a relative path, without a leading /.`;if(xt.test(e))return`Paths can't contain \\, : or control characters.`;for(let t of e.split(`/`)){if(t===``)return`The path has an empty folder name (//).`;if(t===`.`||t===`..`)return`The path can't contain . or .. folders.`;if(t!==t.trim())return`Names can't start or end with a space.`}return null}const Ct=e=>b(`sha256`).update(e).digest(`hex`);async function wt(e,t,n){let r=await e.getSkill(t);if(!/^[a-z0-9-]+$/.test(r.name))throw Error(`"${r.name}" isn't a valid skill name.`);let i=[];for(let t of r.files){let n=St(t.path);if(n)throw Error(`${r.name}: ${t.path}: ${n}`);let a=await e.getBlob(r.id,t.sha256);if(Ct(a)!==t.sha256)throw Error(`${r.name}: ${t.path} didn't download intact.`);i.push({path:t.path,bytes:a})}for(let e of n){let t=u(e,r.name);await v(t,{recursive:!0,force:!0});for(let e of i){let n=u(t,e.path);await g(l(n),{recursive:!0}),await y(n,e.bytes)}}return r}const Q=(e,t=process.cwd())=>e===`global`?u(dt(),`global.lock.json`):u(t,`agent-kit.lock.json`);async function $(e){try{return{version:1,skills:JSON.parse(await _(e,`utf8`)).skills??{}}}catch{return{version:1,skills:{}}}}async function Tt(e,t){let n=Object.fromEntries(Object.entries(t.skills).sort(([e],[t])=>e.localeCompare(t)));await g(l(e),{recursive:!0}),await y(e,JSON.stringify({...t,skills:n},null,2)+`
|
|
61
|
+
`)}async function Et(e,t,n,r){let i=t.find((e,n)=>t.some((t,r)=>r<n&&t.name===e.name));if(i)throw Error(`You picked more than one skill named "${i.name}"; they'd install to the same folder. Pick one.`);let a=ot(n,r),o=Q(r),s=await $(o),c=et();for(let r of t){c.start(`Installing ${r.name}`);try{let t=await wt(e,r.id,a);s.skills[t.name]={id:t.id,version:t.version,agents:n.map(e=>e.id)},c.stop(`${t.name} v${t.version}`)}catch(e){throw c.error(`${r.name} failed`),await Tt(o,s),e}}return await Tt(o,s),{dirs:a,lockFile:o}}function Dt(e){let t=d(process.cwd(),e);return t&&!t.startsWith(`..`)?t:e}async function Ot(e,t){V(`agent kit`);let{api:n}=await yt(),r=!t.yes,{dirs:i}=await Et(n,await lt(await n.listSkills(),e,r),await st(t.agent,r),t.global?`global`:`project`);H(`Installed in ${i.map(Dt).join(`, `)}`)}async function kt(e){V(`agent kit`);let t=await vt();t?B.success(`Logged in as ${t.user.email}`):t=await _t();let n=X(Z(),t.token),r=await n.listSkills();if(r.length===0){H(`You don't have skills yet. Create one at ${t.webUrl}/app/skills, then run \`a-kit add\`.`);return}let i=!e.yes;if(i&&!K())throw Error("`a-kit init` asks questions. Pass --yes to install every skill, or use `a-kit add <skill>`.");let a=await ct(e.global,i),o=await st(e.agent,i),s=i?q(await Ze({message:`Which skills?`,options:r.map(e=>({value:e.id,label:J(e)})),initialValues:r.map(e=>e.id),required:!0})):r.map(e=>e.id),{dirs:c}=await Et(n,r.filter(e=>s.includes(e.id)),o,a);H(`Installed in ${c.map(Dt).join(`, `)}`)}async function At(){let{api:e,credentials:t}=await yt(),n=await e.listSkills();if(n.length===0){console.log(`You don't have skills yet. Create one at ${t.webUrl}/app/skills`);return}let r=await $(Q(`project`)),i=await $(Q(`global`)),a=Math.max(...n.map(e=>J(e).length));for(let e of n){let t=[jt(`project`,r.skills[e.name]?.version,e.version),jt(`global`,i.skills[e.name]?.version,e.version)].filter(Boolean);console.log(`${J(e).padEnd(a)} v${e.version}`+(t.length?` (${t.join(`, `)})`:``))}}function jt(e,t,n){return t===void 0?null:t===n?`in ${e}`:`in ${e} at v${t}, run a-kit update${e===`global`?` -g`:``}`}async function Mt(){V(`agent kit`);let e=await _t();H(`Logged in as ${e.user.email}`)}async function Nt(){let e=await mt();e?(await X(Z(),e.token).logout().catch(()=>{}),await ht(null),console.log(`Logged out ${e.user.email}.`)):console.log(`You're not logged in.`)}async function Pt(){let e=await vt();e?console.log(e.user.email):(console.log("You're not logged in. Run `a-kit login`."),process.exitCode=1)}async function Ft(e){V(`agent kit`);let t=e.global?`global`:`project`,n=Q(t),r=await $(n),i=Object.entries(r.skills);if(i.length===0){H(e.global?"No skills installed everywhere yet. Add some with `a-kit add -g`.":"No skills installed in this project yet. Add some with `a-kit add`.");return}let{api:a}=await yt(),o=0;for(let[e,s]of i){let i;try{i=await a.getSkill(s.id)}catch(t){if(t instanceof Y&&t.status===404){B.warn(`${e} isn't in your agent kit anymore; left it as it is.`);continue}throw t}if(i.version===s.version)continue;let c=ot(s.agents.map(e=>G(e)).filter(e=>e!==void 0),t);if(await wt(a,s.id,c),i.name!==e){for(let t of c)await v(u(t,e),{recursive:!0,force:!0});delete r.skills[e]}r.skills[i.name]={...s,version:i.version},await Tt(n,r),B.success(`${i.name}: v${s.version} → v${i.version}`+(i.name===e?``:` (was ${e})`)),o++}H(o===0?`Everything is up to date.`:`Updated ${o} skill${o===1?``:`s`}.`)}const It=`a-kit ${rt}: your agent kit skills, in your agents.
|
|
62
62
|
|
|
63
63
|
Usage
|
|
64
64
|
a-kit init Log in and pick skills to install
|
|
@@ -71,8 +71,8 @@ Usage
|
|
|
71
71
|
|
|
72
72
|
Options
|
|
73
73
|
-g, --global Install in your home folder instead of this project
|
|
74
|
-
-a, --agent <id> Install for this agent (repeatable): ${
|
|
74
|
+
-a, --agent <id> Install for this agent (repeatable): ${W.map(e=>e.id).join(`, `)}
|
|
75
75
|
-y, --yes Don't ask; use the defaults
|
|
76
76
|
-h, --help Show this help
|
|
77
77
|
-v, --version Show the version
|
|
78
|
-
`;async function
|
|
78
|
+
`;async function Lt(){let{values:t,positionals:n}=e({allowPositionals:!0,options:{global:{type:`boolean`,short:`g`,default:!1},agent:{type:`string`,short:`a`,multiple:!0,default:[]},yes:{type:`boolean`,short:`y`,default:!1},help:{type:`boolean`,short:`h`,default:!1},version:{type:`boolean`,short:`v`,default:!1}}});if(t.version)return console.log(rt);let[r,...i]=n;if(t.help||!r)return console.log(It);let a={global:t.global,agent:t.agent.flatMap(e=>e.split(`,`)).filter(Boolean),yes:t.yes};switch(r){case`init`:return kt(a);case`add`:case`install`:return Ot(i,a);case`update`:return Ft(a);case`list`:case`ls`:return At();case`login`:return Mt();case`logout`:return Nt();case`whoami`:return Pt();default:throw Error(`Unknown command "${r}". Run \`a-kit --help\`.`)}}Lt().catch(e=>{B.error(e instanceof Error?e.message:String(e)),process.exitCode=1});export{};
|