useakit 0.2.0-dev.17 → 0.2.0-dev.18
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 +57 -55
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,71 +1,71 @@
|
|
|
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{basename as l,dirname as u,join as d,parse as f,relative as p,resolve as m}from"node:path";import{homedir as h,hostname as g,tmpdir as _,userInfo as v}from"node:os";import{execFileSync as y,spawn as b}from"node:child_process";import{appendFile as x,chmod as S,copyFile as ee,mkdir as C,open as te,readFile as w,readdir as ne,rename as re,rm as
|
|
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===``){
|
|
4
|
-
`){a&&(r+=
|
|
5
|
-
`&&(i&&
|
|
6
|
-
`)}var
|
|
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{basename as l,dirname as u,join as d,parse as f,relative as p,resolve as m}from"node:path";import{homedir as h,hostname as g,tmpdir as _,userInfo as v}from"node:os";import{execFileSync as y,spawn as b}from"node:child_process";import{appendFile as x,chmod as S,copyFile as ee,mkdir as C,open as te,readFile as w,readdir as ne,rename as re,rm as ie,stat as T,writeFile as E}from"node:fs/promises";import{createHash as ae,randomUUID as oe}from"node:crypto";import{fileURLToPath as se}from"node:url";var ce=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t,t.exports),e=null),t.exports);const le=(()=>{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}})(),ue=e=>e===12288||e>=65281&&e<=65376||e>=65504&&e<=65510,de=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,fe=/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]|\u001b\]8;[^;]*;.*?(?:\u0007|\u001b\u005c)/y,pe=/[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y,me=/(?:(?![\uFF61-\uFF9F\uFF00-\uFFEF])[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\p{Script=Tangut}]){1,1000}/uy,he=/\t{1,1000}/y,ge=/[\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,_e=/(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y,ve=/\p{M}+/gu,ye={limit:1/0,ellipsis:``},be=(e,t={},n={})=>{let r=t.limit??1/0,i=t.ellipsis??``,a=t?.ellipsisWidth??(i?be(i,ye,n).width:0),o=n.controlWidth??0,s=n.tabWidth??8,c=n.emojiWidth??2,l=n.regularWidth??1,u=n.wideWidth??2,d=[[_e,l],[fe,0],[pe,o],[he,s],[ge,c],[me,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,S=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(ve,``)){let t=e.codePointAt(0)||0;if(S=ue(t)?2:de(t)?u:l,x+S>v&&(_=Math.min(_,Math.max(y,f)+h)),x+S>r){g=!0;break outer}h+=e.length,x+=S}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===me?le(e.slice(p,n.lastIndex)):n===ge?1:n.lastIndex-p,S=h*i,x+S>v&&(_=Math.min(_,p+Math.floor((v-x)/i))),x+S>r){g=!0;break outer}x+=S,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}},xe={limit:1/0,ellipsis:``,ellipsisWidth:0},D=(e,t={})=>be(e,xe,t).width,Se=`]8;;`,Ce=RegExp(`(?:\\[(?<code>\\d+)m|\\${Se}(?<uri>.*))`,`y`),we=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},Te=e=>`[${e}m`,Ee=e=>`${Se}${e}`,De=(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(Se,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())},Oe=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(``)},ke=(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(``),De(s,r,t),c=D(s.at(-1)??``)}else{if(c+i>t&&c&&i){if(n.wordWrap===!1&&c<t){De(s,r,t),c=D(s.at(-1)??``);continue}s.push(``),c=0}c+i>t&&n.wordWrap===!1?(De(s,r,t),c=D(s.at(-1)??``)):(s[s.length-1]+=r,c+=i)}}n.trim!==!1&&(s=s.map(e=>Oe(e)));let l=s.join(`
|
|
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===``){Ce.lastIndex=e+1;let t=Ce.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
|
+
`){a&&(r+=Ee(``));let e=i?we(i):void 0;i&&e&&(r+=Te(e))}else t===`
|
|
5
|
+
`&&(i&&we(i)&&(r+=Te(i)),a&&(r+=Ee(a)))}return r},Ae=/\r?\n/;function O(e,t,n){return String(e).normalize().split(Ae).map(e=>ke(e,t,n)).join(`
|
|
6
|
+
`)}var k=(/* @__PURE__ */ ce(((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 je(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 Me(e,t){if(typeof e==`string`)return j.aliases.get(e)===t;for(let n of e)if(n!==void 0&&Me(n,t))return!0;return!1}function Ne(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 Pe=globalThis.process.platform.startsWith(`win`),Fe=Symbol(`clack:cancel`);function Ie(e){return e===Fe}function Le(e,t){let n=e;n.isTTY&&n.setRawMode(t)}function Re({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(Me([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&&!Pe&&e.setRawMode(!1),c.terminal=!1,c.close()}}const ze=e=>`columns`in e&&typeof e.columns==`number`?e.columns:80,Be=e=>`rows`in e&&typeof e.rows==`number`?e.rows:20;function M(e,t,n,r=n,a=n,o){return O(t,ze(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(
|
|
13
|
-
`);this.output.write(t[a]),this._prevFrame=e,this.output.write(
|
|
10
|
+
`)}function Ve(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 He=class{input;output;_abortSignal;rl;opts;_render;_track=!1;_prevFrame=``;_subscribers=/* @__PURE__ */ new Map;_cursor=0;state=`initial`;error=``;value;userInput=``;get accessible(){return je(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(Fe);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),Le(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),Le(this.input,!1),e(this.value)}),this.once(`cancel`,()=>{this.output.write(k.cursor.show),this.output.off(`resize`,this.render),Le(this.input,!1),e(Fe)})})}_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=Ve(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`)}Me([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
|
+
`),Le(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=Ne(this._prevFrame,e),n=Be(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
|
+
`);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(
|
|
16
|
-
`);_.push(a),v+=a.length}if(v>d){let t=0,n=0,r=v,i=e-y,a=d,o=()=>
|
|
15
|
+
`)),this._prevFrame=e;return}}this.output.write(k.erase.down())}this.output.write(e),this.state===`initial`&&(this.state=`active`),this._prevFrame=e}}},Ue=class extends He{get cursor(){return+!this.value}get _value(){return this.cursor===0}constructor(e){super(e,!1),this.value=!!e.initialValue,this.on(`userInput`,()=>{this.value=this._value}),this.on(`confirm`,e=>{this.output.write(k.cursor.move(0,-1)),this.value=e,this.state=`submit`,this.close()}),this.on(`cursor`,()=>{this.value=!this.value})}},We=class extends He{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 Ge=class extends He{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 qe=Ke(),Je=()=>process.env.CI===`true`,N=(e,t)=>qe?e:t,Ye=N(`◆`,`*`),Xe=N(`■`,`x`),Ze=N(`▲`,`x`),Qe=N(`◇`,`o`),$e=N(`┌`,`T`),P=N(`│`,`|`),F=N(`└`,`—`),et=N(`●`,`>`),tt=N(`○`,` `),nt=N(`◻`,`[•]`),rt=N(`◼`,`[+]`),it=N(`◻`,`[ ]`),at=N(`●`,`•`),ot=N(`◆`,`*`),st=N(`▲`,`!`),ct=N(`■`,`x`),lt=e=>{switch(e){case`initial`:case`active`:return t(`cyan`,Ye);case`cancel`:return t(`red`,Xe);case`error`:return t(`yellow`,Ze);case`submit`:return t(`green`,Qe);case`validating`:return t(`dim`,Ye)}},ut=e=>{switch(e){case`initial`:case`active`:return t(`cyan`,P);case`cancel`:return t(`red`,P);case`error`:return t(`yellow`,P);case`submit`:return t(`green`,P)}};function dt(e,n){let r=[`${n?`${t(`cyan`,P)} `:``}${e.join(` • `)}`];return n&&r.push(t(`cyan`,F)),r}const ft=(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}},pt=({cursor:e,options:n,style:r,output:i=process.stdout,maxItems:a=1/0,columnPadding:o=0,rowPadding:s=4})=>{let c=ze(i)-o,l=Be(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=()=>ft(_,r,0,i,a),s=()=>ft(_,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},mt=e=>{let n=e.active??`Yes`,r=e.inactive??`No`;return new Ue({active:n,inactive:r,signal:e.signal,input:e.input,output:e.output,initialValue:e.initialValue??!0,render(){let i=e.withGuide??j.withGuide,a=`${lt(this.state)} `,o=i?`${t(`gray`,P)} `:``,s=M(e.output,e.message,o,a),c=`${i?`${t(`gray`,P)}
|
|
17
17
|
`:``}${s}
|
|
18
|
-
`,l=this.value?n:r;switch(this.state){case`submit`:return`${c}${i?`${t(`gray`,
|
|
19
|
-
${t(`gray`,
|
|
20
|
-
${t(`cyan`,
|
|
21
|
-
`:` ${t(`dim`,`/`)} `}${this.value?`${t(`dim
|
|
18
|
+
`,l=this.value?n:r;switch(this.state){case`submit`:return`${c}${i?`${t(`gray`,P)} `:``}${t(`dim`,l)}`;case`cancel`:return`${c}${i?`${t(`gray`,P)} `:``}${t([`strikethrough`,`dim`],l)}${i?`
|
|
19
|
+
${t(`gray`,P)}`:``}`;default:{let a=i?`${t(`cyan`,P)} `:``,o=i?t(`cyan`,F):``;return`${c}${a}${this.value?`${t(`green`,et)} ${n}`:`${t(`dim`,tt)} ${t(`dim`,n)}`}${e.vertical?i?`
|
|
20
|
+
${t(`cyan`,P)} `:`
|
|
21
|
+
`:` ${t(`dim`,`/`)} `}${this.value?`${t(`dim`,tt)} ${t(`dim`,r)}`:`${t(`green`,et)} ${r}`}
|
|
22
22
|
${o}
|
|
23
|
-
`}}}}).prompt()},
|
|
23
|
+
`}}}}).prompt()},ht=[`${t(`dim`,`↑/↓`)} to navigate`,`${t(`dim`,`Space:`)} select`,`${t(`dim`,`Enter:`)} confirm`],I=(e,t)=>e.split(`
|
|
24
24
|
`).map(e=>t(e)).join(`
|
|
25
|
-
`),
|
|
26
|
-
${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??
|
|
25
|
+
`),gt=e=>{let n=(e,n)=>{let r=e.label??String(e.value);return n===`disabled`?`${t(`gray`,it)} ${I(r,e=>t([`strikethrough`,`gray`],e))}${e.hint?` ${t(`dim`,`(${e.hint??`disabled`})`)}`:``}`:n===`active`?`${t(`cyan`,nt)} ${r}${e.hint?` ${t(`dim`,`(${e.hint})`)}`:``}`:n===`selected`?`${t(`green`,rt)} ${I(r,e=>t(`dim`,e))}${e.hint?` ${t(`dim`,`(${e.hint})`)}`:``}`:n===`cancelled`?`${I(r,e=>t([`strikethrough`,`dim`],e))}`:n===`active-selected`?`${t(`green`,rt)} ${r}${e.hint?` ${t(`dim`,`(${e.hint})`)}`:``}`:n===`submitted`?`${I(r,e=>t(`dim`,e))}`:`${t(`dim`,it)} ${I(r,e=>t(`dim`,e))}`},r=e.required??!0,i=e.showInstructions??!0;return new We({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.
|
|
26
|
+
${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=M(e.output,e.message,r?`${ut(this.state)} `:``,`${lt(this.state)} `),o=`${r?`${t(`gray`,P)}
|
|
27
27
|
`:``}${a}
|
|
28
|
-
`,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}${
|
|
29
|
-
${t(`gray`,
|
|
30
|
-
`).map((e,n)=>n===0?`${r?`${t(`yellow`,
|
|
28
|
+
`,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}${M(e.output,i,r?`${t(`gray`,P)} `:``)}`}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`,P)}`:`${o}${M(e.output,i,r?`${t(`gray`,P)} `:``)}${r?`
|
|
29
|
+
${t(`gray`,P)}`:``}`}case`error`:{let n=r?`${t(`yellow`,P)} `:``,i=this.error.split(`
|
|
30
|
+
`).map((e,n)=>n===0?`${r?`${t(`yellow`,F)} `:``}${t(`yellow`,e)}`:` ${e}`).join(`
|
|
31
31
|
`),a=o.split(`
|
|
32
32
|
`).length,s=i.split(`
|
|
33
|
-
`).length+1;return`${o}${n}${
|
|
33
|
+
`).length+1;return`${o}${n}${pt({output:e.output,options:this.options,cursor:this.cursor,maxItems:e.maxItems,columnPadding:n.length,rowPadding:a+s,style:c}).join(`
|
|
34
34
|
${n}`)}
|
|
35
35
|
${i}
|
|
36
|
-
`}default:{let n=r?`${t(`cyan`,
|
|
37
|
-
`).length,s=i?
|
|
38
|
-
`),u=s.length+1;return`${o}${n}${
|
|
36
|
+
`}default:{let n=r?`${t(`cyan`,P)} `:``,a=o.split(`
|
|
37
|
+
`).length,s=i?dt(ht,r):r?[t(`cyan`,F)]:[],l=s.join(`
|
|
38
|
+
`),u=s.length+1;return`${o}${n}${pt({output:e.output,options:this.options,cursor:this.cursor,maxItems:e.maxItems,columnPadding:n.length,rowPadding:a+u,style:c}).join(`
|
|
39
39
|
${n}`)}
|
|
40
40
|
${l}
|
|
41
|
-
`}}}}).prompt()},
|
|
41
|
+
`}}}}).prompt()},L={message:(e=[],{symbol:n=t(`gray`,P),secondarySymbol:r=t(`gray`,P),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(`
|
|
42
42
|
`);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(`
|
|
43
43
|
`)}
|
|
44
|
-
`)},info:(e,n)=>{
|
|
44
|
+
`)},info:(e,n)=>{L.message(e,{...n,symbol:t(`blue`,at)})},success:(e,n)=>{L.message(e,{...n,symbol:t(`green`,ot)})},step:(e,n)=>{L.message(e,{...n,symbol:t(`green`,Qe)})},warn:(e,n)=>{L.message(e,{...n,symbol:t(`yellow`,st)})},warning:(e,t)=>{L.warn(e,t)},error:(e,n)=>{L.message(e,{...n,symbol:t(`red`,ct)})}},_t=(e=``,n)=>{let r=n?.output??process.stdout,i=n?.withGuide??j.withGuide?`${t(`gray`,F)} `:``;r.write(`${i}${t(`red`,e)}
|
|
45
45
|
|
|
46
|
-
`)},
|
|
47
|
-
`)},
|
|
48
|
-
${t(`gray`,
|
|
46
|
+
`)},R=(e=``,n)=>{let r=n?.output??process.stdout,i=n?.withGuide??j.withGuide?`${t(`gray`,$e)} `:``;r.write(`${i}${e}
|
|
47
|
+
`)},z=(e=``,n)=>{let r=n?.output??process.stdout,i=n?.withGuide??j.withGuide?`${t(`gray`,P)}
|
|
48
|
+
${t(`gray`,F)} `:``;r.write(`${i}${e}
|
|
49
49
|
|
|
50
|
-
`)},
|
|
51
|
-
`);let e=
|
|
52
|
-
`);e.length>1&&r.write(
|
|
53
|
-
`);let i=0,a=0;ee(),f=setInterval(()=>{if(u&&h===g)return;te(),g=h;let t=y(o[i]),n;if(u)n=`${t} ${h}...`;else if(e===`timer`)n=`${t} ${h} ${ne(_)}`;else{let e=`.`.repeat(Math.floor(a)).slice(0,3);n=`${t} ${h}${e}`}let s=
|
|
50
|
+
`)},vt=e=>t(`magenta`,e),yt=({indicator:e=`dots`,onCancel:n,output:r=process.stdout,cancelMessage:i,errorMessage:a,frames:o=qe?[`◒`,`◐`,`◓`,`◑`]:[`•`,`o`,`O`,`0`],delay:s=qe?80:120,signal:c,...l}={})=>{let u=Je(),d,f,p=!1,m=!1,h=``,g,_=performance.now(),v=ze(r),y=l?.styleFrame??vt,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)},C=()=>{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)},te=()=>{if(g===void 0)return;u&&r.write(`
|
|
51
|
+
`);let e=O(g,v,{hard:!0,trim:!1}).split(`
|
|
52
|
+
`);e.length>1&&r.write(k.cursor.up(e.length-1)),r.write(k.cursor.to(0)),r.write(k.erase.down())},w=e=>e.replace(/\.+$/,``),ne=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=Re({output:r}),h=w(n),_=performance.now(),re&&r.write(`${t(`gray`,P)}
|
|
53
|
+
`);let i=0,a=0;ee(),f=setInterval(()=>{if(u&&h===g)return;te(),g=h;let t=y(o[i]),n;if(u)n=`${t} ${h}...`;else if(e===`timer`)n=`${t} ${h} ${ne(_)}`;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),te();let o=i===0?t(`green`,Qe):i===1?t(`red`,Xe):t(`red`,Ze);h=n??h,a||(e===`timer`?r.write(`${o} ${h} ${ne(_)}
|
|
54
54
|
`):r.write(`${o} ${h}
|
|
55
|
-
`)),C(),d()};return{start:
|
|
55
|
+
`)),C(),d()};return{start:ie,stop:(e=``)=>T(e,0),message:(e=``)=>{h=w(e??h)},cancel:(e=``)=>T(e,1),error:(e=``)=>T(e,2),clear:()=>T(``,0,!0),get isCancelled(){return m}}},bt=[`${t(`dim`,`↑/↓`)} to navigate`,`${t(`dim`,`Enter:`)} confirm`],xt=(e,t)=>e.includes(`
|
|
56
56
|
`)?e.split(`
|
|
57
57
|
`).map(e=>t(e)).join(`
|
|
58
|
-
`):t(e),
|
|
58
|
+
`):t(e),St=e=>{let n=(e,n)=>{if(e===void 0)return``;let r=e.label??String(e.value);switch(n){case`disabled`:return`${t(`gray`,tt)} ${xt(r,e=>t(`gray`,e))}${e.hint?` ${t(`dim`,`(${e.hint??`disabled`})`)}`:``}`;case`selected`:return`${xt(r,e=>t(`dim`,e))}`;case`active`:return`${t(`green`,et)} ${r}${e.hint?` ${t(`dim`,`(${e.hint})`)}`:``}`;case`cancelled`:return`${xt(r,e=>t([`strikethrough`,`dim`],e))}`;default:return`${t(`dim`,tt)} ${xt(r,e=>t(`dim`,e))}`}},r=e.showInstructions??!0;return new Ge({options:e.options,signal:e.signal,input:e.input,output:e.output,initialValue:e.initialValue,render(){let i=e.withGuide??j.withGuide,a=`${lt(this.state)} `,o=`${ut(this.state)} `,s=M(e.output,e.message,o,a),c=`${i?`${t(`gray`,P)}
|
|
59
59
|
`:``}${s}
|
|
60
|
-
`;switch(this.state){case`submit`:{let r=i?`${t(`gray`,
|
|
61
|
-
${t(`gray`,
|
|
62
|
-
`).length,s=r?
|
|
63
|
-
`),u=s.length+1;return`${c}${a}${
|
|
60
|
+
`;switch(this.state){case`submit`:{let r=i?`${t(`gray`,P)} `:``;return`${c}${M(e.output,n(this.options[this.cursor],`selected`),r)}`}case`cancel`:{let r=i?`${t(`gray`,P)} `:``;return`${c}${M(e.output,n(this.options[this.cursor],`cancelled`),r)}${i?`
|
|
61
|
+
${t(`gray`,P)}`:``}`}default:{let a=i?`${t(`cyan`,P)} `:``,o=c.split(`
|
|
62
|
+
`).length,s=r?dt(bt,i):i?[t(`cyan`,F)]:[],l=s.join(`
|
|
63
|
+
`),u=s.length+1;return`${c}${a}${pt({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(`
|
|
64
64
|
${a}`)}
|
|
65
65
|
${l}
|
|
66
|
-
`}}}}).prompt()};`${t(`gray`,
|
|
67
|
-
`,{mode:384}),await S(n,384)}const
|
|
68
|
-
`)}function
|
|
66
|
+
`}}}}).prompt()};`${t(`gray`,P)}`;var Ct=`0.2.0`;const B=[{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`}],wt=e=>e===`global`?h():process.cwd();function Tt(e=h()){return B.filter(t=>c(d(e,t.marker)))}function V(e){return B.find(t=>t.id===e)}function Et(e,t,n=wt(t)){let r=e.map(e=>m(n,t===`global`?e.globalDir:e.projectDir));return[...new Set(r)]}const H=()=>!!(process.stdin.isTTY&&process.stdout.isTTY)&&!process.env.CI;function U(e){return Ie(e)&&(_t(`Cancelled.`),process.exit(130)),e}async function Dt(e,t){if(e.length>0)return e.map(e=>{let t=V(e);if(!t)throw Error(`Unknown agent "${e}". Use one of: ${B.map(e=>e.id).join(`, `)}.`);return t});let n=Tt(),r=n.length>0?n:[V(`claude-code`)];return!t||!H()?r:U(await gt({message:`Which agents should get the skills?`,options:B.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=>V(e))}async function Ot(e,t){return e?`global`:!t||!H()?`project`:U(await St({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 kt(e,t,n){if(t.length>0){let r=[];for(let i of t){let t=At(e,i);r.push(t.length===1?t[0]:await jt(t,n))}return r}if(!n||!H())throw Error("Name the skills to add, like `a-kit add my-skill`.");let r=U(await gt({message:`Which skills?`,options:e.map(e=>({value:e.id,label:W(e),hint:e.description.length>60?`${e.description.slice(0,57)}…`:e.description})),required:!0}));return e.filter(e=>r.includes(e.id))}function At(e,t){let n=t.lastIndexOf(`/`),r=t.slice(n+1),i=n===-1?null:t.slice(0,n).trim().toLowerCase(),a=e.filter(e=>e.name===r&&(i===null||e.organizationName.toLowerCase()===i));if(a.length===0)throw Error(i===null?`There's no skill named "${r}" in your agent kit. See them with \`a-kit list\`.`:`There's no skill named "${r}" in an organization called "${t.slice(0,n)}". See them with \`a-kit list\`.`);return a}async function jt(e,t){let n=e[0].name;if(!t||!H()){let t=e.map(e=>{let t=Mt(e);return`\`a-kit add ${/\s/.test(t)?`"${t}"`:t}\``});throw Error(`More than one of your organizations has a skill named "${n}". Say which one: ${t.join(` or `)}.`)}let r=U(await St({message:`More than one of your organizations has "${n}". Which one?`,options:e.map(e=>({value:e.id,label:Mt(e)}))}));return e.find(e=>e.id===r)}const Mt=e=>`${e.organizationName}/${e.name}`,W=e=>e.showOrganization?`${e.name} (${e.organizationName})`:e.name;var G=class extends Error{status;code;constructor(e,t,n){super(n),this.status=e,this.code=t}};function K(e,t,n=fetch){async function r(r,i={}){let a;try{a=await n(`${e}${r}`,{...i,headers:{"User-Agent":`a-kit/${Ct}`,...i.body?{"Content-Type":`application/json`}:{},...t?{Authorization:`Bearer ${t}`}:{},...i.headers}})}catch{throw new G(0,`NETWORK`,`Couldn't reach ${e}.`)}if(!a.ok){let e=await a.json().catch(()=>null);throw a.status===401?new G(401,`UNAUTHORIZED`,"You're not logged in. Run `a-kit login`."):new G(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`)]),n=new Map(t.map(e=>[e.id,e.name]));return e.map(e=>({...e,organizationName:n.get(e.organizationId)??``,showOrganization:t.length>1}))},listOrganizations:()=>i(`/orgs`),reportActivations:(e,t)=>i(`/activations`,{method:`POST`,body:JSON.stringify({activations:e}),signal:t}),search:e=>i(`/search?q=${encodeURIComponent(e)}`),getSkill:e=>i(`/skills/${e}`),createReport:(e,t)=>i(`/orgs/${e}/reports`,{method:`POST`,body:JSON.stringify(t)}),getBlob:async(e,t)=>new Uint8Array(await(await r(`/skills/${e}/blobs/${t}`)).arrayBuffer())}}function Nt(e){let[t,n]=process.platform===`darwin`?[`open`,[e]]:process.platform===`win32`?[`cmd`,[`/c`,`start`,``,e.replace(/&/g,`^&`)]]:[`xdg-open`,[e]];try{let e=b(t,n,{stdio:`ignore`,detached:!0});e.on(`error`,()=>{}),e.unref()}catch{}}function q(){return(process.env.AGENT_KIT_API_URL??`https://api-dev.agent-kit.fausanchez.com`??`http://localhost:8787`).replace(/\/+$/,``)}function J(){return process.env.AGENT_KIT_CONFIG_DIR?process.env.AGENT_KIT_CONFIG_DIR:process.platform===`win32`&&process.env.APPDATA?d(process.env.APPDATA,`agent-kit`):d(process.env.XDG_CONFIG_HOME??d(h(),`.config`),`agent-kit`)}const Pt=()=>d(J(),`credentials.json`);async function Ft(){try{return JSON.parse(await w(Pt(),`utf8`))}catch{return{}}}async function It(){return(await Ft())[q()]??null}async function Lt(e){let t=await Ft();e?t[q()]=e:delete t[q()];let n=Pt();await C(u(n),{recursive:!0,mode:448}),await E(n,JSON.stringify(t,null,2)+`
|
|
67
|
+
`,{mode:384}),await S(n,384)}const Rt=()=>d(J(),`settings.json`);async function zt(){try{return JSON.parse(await w(Rt(),`utf8`))}catch{return{}}}async function Bt(e){let t={...await zt(),...e};await C(J(),{recursive:!0,mode:448}),await E(Rt(),JSON.stringify(t,null,2)+`
|
|
68
|
+
`)}function Vt(e=process.env){let t=e=>e!==void 0&&[`0`,`false`,`off`,`no`].includes(e.toLowerCase());return(e=>e!==void 0&&e!==``&&!t(e))(e.DO_NOT_TRACK)||t(e.AGENT_KIT_TELEMETRY)}const Ht=e=>new Promise(t=>setTimeout(t,e));async function Ut(){let e=await K(q()).startLogin();L.step(`Your code: ${e.userCode}\nApprove it in your browser: ${e.verificationUrl}`),Nt(e.verificationUrl);let t=yt();t.start(`Waiting for you to approve it`);let n=K(q()),r=Date.now()+e.expiresIn*1e3;for(;Date.now()<r;){await Ht(e.interval*1e3);let r;try{r=await n.pollLogin(e.deviceCode)}catch(e){if(e instanceof G&&e.status===410)break;if(e instanceof G&&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 Lt(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 Wt(){let e=await It();if(!e)return null;try{let t=await K(q(),e.token).me();return{...e,user:t}}catch(e){if(e instanceof G&&e.status===401)return await Lt(null),null;throw e}}async function Y(){let e=await It();if(!e)throw Error("You're not logged in. Run `a-kit login` first.");return{api:K(q(),e.token),credentials:e}}const Gt=`report-session-issue`,Kt=/skills\/([a-z0-9][a-z0-9-]*)\/SKILL\.md/g;function qt(e,t){if(e===`Skill`){let e=t?.skill;return typeof e==`string`?[Jt(e)]:[]}return[...(typeof t==`string`?t:JSON.stringify(t??``)).matchAll(Kt)].map(e=>e[1])}const Jt=e=>e.slice(e.lastIndexOf(`:`)+1).replace(/^\//,``);function Yt(e){let t=e.events.findIndex(e=>Xt(e));if(t===-1)return e;let n=t;for(let r=t;r>=0;r--){let t=e.events[r];if(t.type===`user`&&t.message.content.some(e=>e.type===`text`)){n=r;break}}let r=e.events.slice(0,n);return{...e,events:r,loaded:[...new Set(r.flatMap(Zt))]}}function Xt(e){return Zt(e).includes(Gt)}function Zt(e){return e.type===`system`?[]:e.message.content.flatMap(t=>t.type===`tool_use`?qt(t.name,t.input):t.type===`text`&&e.type===`user`?[...t.text.matchAll(/<command-name>\/?([\w:-]+)<\/command-name>/g)].map(e=>Jt(e[1])):[])}const Qt=(e=`npx -y useakit@next`)=>`---
|
|
69
69
|
name: ${Gt}
|
|
70
70
|
description: Reports this conversation to agent kit because it went wrong, so it can become an eval. Use when the developer says the session went badly and asks to report it ("report this", "reportá esta conversación", "mandalo a agent kit"), or wants it turned into an eval.
|
|
71
71
|
---
|
|
@@ -105,29 +105,31 @@ Only the conversation up to the developer's request to report it is sent; this p
|
|
|
105
105
|
4. **Confirm.** Tell the developer in a few lines: the title, the skills it links, what was taken out, and that long tool outputs and written files are cut to 2,000 characters (\`--full-outputs\` keeps them whole). Ask before sending.
|
|
106
106
|
|
|
107
107
|
5. **Send.** Run the same command with \`--yes\` instead of \`--dry-run\`, and give the developer the link it prints. If it says they're not logged in, they run \`${e} login\` first.
|
|
108
|
-
`;async function $t(e){for(let t of e){let e=d(t,Gt);await C(e,{recursive:!0}),await
|
|
109
|
-
`)}const sn=(e=h())=>d(process.env.CLAUDE_CONFIG_DIR??d(e,`.claude`),`settings.json`),cn=(e,t)=>`node "${e}" hook claude-code --api "${t}"`,ln=e=>typeof e.command==`string`&&e.command.includes(`a-kit.mjs`)&&e.command.includes(` hook claude-code`),un=[{event:`PostToolUse`,matcher:`Skill`},{event:`UserPromptSubmit`}];function dn(e){if(!e.hooks)return e;let t={};for(let[n,r]of Object.entries(e.hooks)){if(!Array.isArray(r)){t[n]=r;continue}let e=r.map(e=>({...e,hooks:e.hooks?.filter(e=>!ln(e))})).filter((e,t)=>(e.hooks?.length??0)>0||!r[t].hooks);e.length>0&&(t[n]=e)}let{hooks:n,...r}=e;return Object.keys(t).length>0?{...r,hooks:t}:r}function fn(e,t){let n=dn(e),r={...n.hooks};for(let{event:e,matcher:n}of un){let i={type:`command`,command:t,async:!0,timeout:10};r[e]=[...r[e]??[],n?{matcher:n,hooks:[i]}:{hooks:[i]}]}return{...n,hooks:r}}function pn(e,t){return un.every(({event:n})=>e.hooks?.[n]?.some(e=>e.hooks?.some(e=>ln(e)&&(!t||e.command===t))))}function mn(e){if(e.hook_event_name===`PostToolUse`&&e.tool_name===`Skill`){let t=e.tool_input?.skill??e.tool_input?.command,n=typeof t==`string`?t.replace(/^\//,``):``;return hn(n)?{name:n,trigger:`model`}:null}if(e.hook_event_name===`UserPromptSubmit`&&typeof e.prompt==`string`){let t=e.prompt.match(/^\s*\/([^\s]+)/)?.[1]??``;return hn(t)?{name:t,trigger:`user`}:null}return null}const hn=e=>/^[a-z0-9][a-z0-9-]*$/.test(e),gn=()=>d(
|
|
110
|
-
`)}async function wn(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=
|
|
111
|
-
`),t}async function jn(e,t,n,r=/* @__PURE__ */ new Date){return{id:
|
|
108
|
+
`;async function $t(e){for(let t of e){let e=d(t,Gt);await C(e,{recursive:!0}),await E(d(e,`SKILL.md`),Qt())}}const en={maxFiles:200,maxFileBytes:1048576,maxSkillBytes:10485760,maxPathLength:255},tn=/[\u0000-\u001f\u007f\\:]/;function nn(e){if(e.trim()===``)return`The path is empty.`;if(e.length>en.maxPathLength)return`Paths can be at most ${en.maxPathLength} characters.`;if(e.startsWith(`/`))return`Use a relative path, without a leading /.`;if(tn.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 rn=e=>ae(`sha256`).update(e).digest(`hex`);async function an(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=nn(t.path);if(n)throw Error(`${r.name}: ${t.path}: ${n}`);let a=await e.getBlob(r.id,t.sha256);if(rn(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=d(e,r.name);await ie(t,{recursive:!0,force:!0});for(let e of i){let n=d(t,e.path);await C(u(n),{recursive:!0}),await E(n,e.bytes)}}return r}const X=(e,t=process.cwd())=>e===`global`?d(J(),`global.lock.json`):d(t,`agent-kit.lock.json`);async function Z(e){try{return{version:1,skills:JSON.parse(await w(e,`utf8`)).skills??{}}}catch{return{version:1,skills:{}}}}async function on(e,t){let n=Object.fromEntries(Object.entries(t.skills).sort(([e],[t])=>e.localeCompare(t)));await C(u(e),{recursive:!0}),await E(e,JSON.stringify({...t,skills:n},null,2)+`
|
|
109
|
+
`)}const sn=(e=h())=>d(process.env.CLAUDE_CONFIG_DIR??d(e,`.claude`),`settings.json`),cn=(e,t)=>`node "${e}" hook claude-code --api "${t}"`,ln=e=>typeof e.command==`string`&&e.command.includes(`a-kit.mjs`)&&e.command.includes(` hook claude-code`),un=[{event:`PostToolUse`,matcher:`Skill`},{event:`UserPromptSubmit`}];function dn(e){if(!e.hooks)return e;let t={};for(let[n,r]of Object.entries(e.hooks)){if(!Array.isArray(r)){t[n]=r;continue}let e=r.map(e=>({...e,hooks:e.hooks?.filter(e=>!ln(e))})).filter((e,t)=>(e.hooks?.length??0)>0||!r[t].hooks);e.length>0&&(t[n]=e)}let{hooks:n,...r}=e;return Object.keys(t).length>0?{...r,hooks:t}:r}function fn(e,t){let n=dn(e),r={...n.hooks};for(let{event:e,matcher:n}of un){let i={type:`command`,command:t,async:!0,timeout:10};r[e]=[...r[e]??[],n?{matcher:n,hooks:[i]}:{hooks:[i]}]}return{...n,hooks:r}}function pn(e,t){return un.every(({event:n})=>e.hooks?.[n]?.some(e=>e.hooks?.some(e=>ln(e)&&(!t||e.command===t))))}function mn(e){if(e.hook_event_name===`PostToolUse`&&e.tool_name===`Skill`){let t=e.tool_input?.skill??e.tool_input?.command,n=typeof t==`string`?t.replace(/^\//,``):``;return hn(n)?{name:n,trigger:`model`}:null}if(e.hook_event_name===`UserPromptSubmit`&&typeof e.prompt==`string`){let t=e.prompt.match(/^\s*\/([^\s]+)/)?.[1]??``;return hn(t)?{name:t,trigger:`user`}:null}return null}const hn=e=>/^[a-z0-9][a-z0-9-]*$/.test(e),gn=()=>d(J(),`bin`,`a-kit.mjs`);function _n(){let e=se(import.meta.url);return e.endsWith(`.mjs`)?e:null}async function vn(e=_n(),t=sn()){if(!e)return{status:`skipped`,reason:`not running from a build`};let n=await Sn(t);if(n===`invalid`)return{status:`skipped`,reason:`${t} isn't valid JSON`};let r=gn();await C(u(r),{recursive:!0}),e!==r&&await ee(e,r);let i=cn(r,q());return pn(n,i)?{status:`already`}:(await Cn(t,fn(n,i)),{status:`installed`})}async function yn(e=sn()){let t=await Sn(e);return t===`invalid`||!pn(t)?!1:(await Cn(e,dn(t)),!0)}async function bn(e=sn()){let t=await Sn(e);return t!==`invalid`&&pn(t)}async function xn(e){if(e.includes(`claude-code`)&&(await zt()).telemetry!==!1)try{(await vn()).status===`installed`&&L.info("Claude Code now reports to agent kit each time it loads one of these skills, so your organization sees which ones get used. Turn it off with `a-kit telemetry off`.")}catch{}}async function Sn(e){let t;try{t=await w(e,`utf8`)}catch{return{}}if(!t.trim())return{};try{let e=JSON.parse(t);return typeof e==`object`&&e&&!Array.isArray(e)?e:`invalid`}catch{return`invalid`}}async function Cn(e,t){await C(u(e),{recursive:!0}),await E(e,JSON.stringify(t,null,2)+`
|
|
110
|
+
`)}async function wn(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=Et(n,r),o=X(r),s=await Z(o),c=yt();await $t(a);for(let r of t){c.start(`Installing ${r.name}`);try{let t=await an(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 on(o,s),e}}return await on(o,s),await xn(n.map(e=>e.id)),{dirs:a,lockFile:o}}function Tn(e){let t=p(process.cwd(),e);return t&&!t.startsWith(`..`)?t:e}async function En(e,t){R(`agent kit`);let{api:n}=await Y(),r=!t.yes,{dirs:i}=await wn(n,await kt(await n.listSkills(),e,r),await Dt(t.agent,r),t.global?`global`:`project`);z(`Installed in ${i.map(Tn).join(`, `)}`)}async function Dn(e){R(`agent kit`);let t=await Wt();t?L.success(`Logged in as ${t.user.email}`):t=await Ut();let n=K(q(),t.token),r=await n.listSkills();if(r.length===0){z(`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&&!H())throw Error("`a-kit init` asks questions. Pass --yes to install every skill, or use `a-kit add <skill>`.");let a=await Ot(e.global,i),o=await Dt(e.agent,i),s=i?U(await gt({message:`Which skills?`,options:r.map(e=>({value:e.id,label:W(e)})),initialValues:r.map(e=>e.id),required:!0})):r.map(e=>e.id),{dirs:c}=await wn(n,r.filter(e=>s.includes(e.id)),o,a);z(`Installed in ${c.map(Tn).join(`, `)}`)}async function On(e,t,n,r=h()){let i=[X(`global`)],a=kn(n,r);a&&i.push(a);for(let n of i){let r=(await Z(n)).skills[e];if(r?.agents.includes(t))return r}return null}function kn(e,t){let n=e,{root:r}=f(e);for(;n&&n!==t;){let e=X(`project`,n);if(c(e))return e;if(n===r)break;n=u(n)}return null}async function An(){let e=d(J(),`machine.json`);try{let t=JSON.parse(await w(e,`utf8`));if(typeof t.id==`string`&&t.id)return t.id}catch{}let t=oe();return await C(u(e),{recursive:!0,mode:448}),await E(e,JSON.stringify({id:t},null,2)+`
|
|
111
|
+
`),t}async function jn(e,t,n,r=/* @__PURE__ */ new Date){return{id:oe(),skillId:e.id,version:e.version,agent:t,machineId:await An(),machineName:g()||null,trigger:n,occurredAt:r.toISOString()}}const Mn=()=>d(J(),`pending-activations.jsonl`);async function Nn(e,t){let n=`${Mn()}.${process.pid}`,r=[];try{await re(Mn(),n),r=Fn(await w(n,`utf8`)),await ie(n,{force:!0})}catch{}let i=[...r,t].slice(-500),a=0;for(let t=0;t<i.length;t+=100){let n=i.slice(t,t+100);try{await e(n),a+=n.length}catch(e){if(!Pn(e))continue;let n=i.slice(t);return await C(J(),{recursive:!0,mode:448}),await x(Mn(),n.map(e=>JSON.stringify(e)).join(`
|
|
112
112
|
`)+`
|
|
113
|
-
`),{sent:a,queued:n.length}}}return{sent:a,queued:0}}const Pn=e=>!(e instanceof
|
|
114
|
-
`).filter(Boolean).flatMap(e=>{try{return[JSON.parse(e)]}catch{return[]}})}async function In(e,t){try{if(t&&(process.env.AGENT_KIT_API_URL=t),e!==`claude-code`||process.stdin.isTTY||
|
|
113
|
+
`),{sent:a,queued:n.length}}}return{sent:a,queued:0}}const Pn=e=>!(e instanceof G)||e.status===0||e.status===429||e.status>=500;function Fn(e){return e.split(`
|
|
114
|
+
`).filter(Boolean).flatMap(e=>{try{return[JSON.parse(e)]}catch{return[]}})}async function In(e,t){try{if(t&&(process.env.AGENT_KIT_API_URL=t),e!==`claude-code`||process.stdin.isTTY||Vt()||(await zt()).telemetry===!1)return;let n=JSON.parse(await Ln()),r=mn(n);if(!r)return;let i=await On(r.name,e,typeof n.cwd==`string`?n.cwd:process.cwd());if(!i)return;let a=await It();if(!a)return;let o=K(q(),a.token);await Nn(async e=>{await o.reportActivations(e,AbortSignal.timeout(5e3))},await jn(i,e,r.trigger))}catch{}}async function Ln(){let e=[];for await(let t of process.stdin)e.push(t);return Buffer.concat(e).toString(`utf8`)}async function Rn(){let{api:e,credentials:t}=await Y(),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 Z(X(`project`)),i=await Z(X(`global`)),a=Math.max(...n.map(e=>W(e).length));for(let e of n){let t=[zn(`project`,r.skills[e.name]?.version,e.version),zn(`global`,i.skills[e.name]?.version,e.version)].filter(Boolean);console.log(`${W(e).padEnd(a)} v${e.version}`+(t.length?` (${t.join(`, `)})`:``))}}function zn(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 Bn(){R(`agent kit`);let e=await Ut();z(`Logged in as ${e.user.email}`)}async function Vn(){let e=await It();e?(await K(q(),e.token).logout().catch(()=>{}),await Lt(null),console.log(`Logged out ${e.user.email}.`)):console.log(`You're not logged in.`)}async function Hn(){let e=await Wt();e?console.log(e.user.email):(console.log("You're not logged in. Run `a-kit login`."),process.exitCode=1)}const Un={maxTitleLength:120,maxNoteLength:4e3,maxSkills:50,maxTranscriptBytes:8388608},Wn=[{kind:`private-key`,pattern:/-----BEGIN [A-Z ]*PRIVATE KEY-----[\s\S]*?(?:-----END [A-Z ]*PRIVATE KEY-----|$)/g,strict:!0},{kind:`anthropic-key`,pattern:/\bsk-ant-[A-Za-z0-9_-]{20,}/g,strict:!0},{kind:`openai-key`,pattern:/\bsk-(?:proj-|svcacct-)?[A-Za-z0-9_-]{32,}/g,strict:!0},{kind:`github-token`,pattern:/\b(?:gh[pousr]_[A-Za-z0-9]{36,}|github_pat_[A-Za-z0-9_]{40,})/g,strict:!0},{kind:`aws-key`,pattern:/\b(?:AKIA|ASIA)[0-9A-Z]{16}\b/g,strict:!0},{kind:`slack-token`,pattern:/\bxox[abprs]-[A-Za-z0-9-]{10,}/g,strict:!0},{kind:`stripe-key`,pattern:/\b[rs]k_(?:live|test)_[A-Za-z0-9]{16,}/g,strict:!0},{kind:`google-key`,pattern:/\bAIza[0-9A-Za-z_-]{35}\b/g,strict:!0},{kind:`jwt`,pattern:/\beyJ[A-Za-z0-9_-]{8,}\.eyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}/g,strict:!0},{kind:`url-credentials`,pattern:/\b([a-z][a-z0-9+.-]*:\/\/)[^\s:/@]+:[^\s@/]+@/gi,keep:(e,t)=>`${t}<secret>@`,strict:!1},{kind:`bearer`,pattern:/\b(Bearer\s+)[A-Za-z0-9._~+/-]{20,}=*/g,keep:(e,t)=>`${t}<secret>`,strict:!1},{kind:`assignment`,pattern:/\b([A-Za-z0-9_]*(?:secret|token|password|passwd|api_?key|private_?key|access_?key)[A-Za-z0-9_]*["']?\s*[=:]\s*)(["']?)(?!<secret)[^\s"'`,;]{8,}\2/gi,keep:(e,t,n)=>`${t}${n}<secret>${n}`,strict:!1}],Gn=/[A-Za-z0-9._%+-]+@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*\.[A-Za-z]{2,}\b/g,Kn=/\b(?:(?:25[0-5]|2[0-4]\d|1?\d?\d)\.){3}(?:25[0-5]|2[0-4]\d|1?\d?\d)\b/g,qn=/* @__PURE__ */ new Set([`127.0.0.1`,`0.0.0.0`]),Jn=/@(?:example\.(?:com|org|net)|anthropic\.com)$/i,Yn=e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);function Xn(e){let t={},n=(e,n=1)=>{t[e]=(t[e]??0)+n},r=e.paths.filter(e=>e.path.length>1).sort((e,t)=>t.path.length-e.path.length).map(e=>({...e,pattern:new RegExp(Yn(e.path),`g`)})),i=e.replacements.filter(e=>e.find.trim().length>1).sort((e,t)=>t.find.length-e.find.length).map(e=>({...e,pattern:new RegExp(e.find.length<4?`(?<![\\p{L}\\p{N}_])${Yn(e.find)}(?![\\p{L}\\p{N}_])`:Yn(e.find),`giu`)}));function a(e){let t=e;for(let e of Wn)t=t.replace(e.pattern,(t,...r)=>(n(`secret:${e.kind}`),e.keep?e.keep(t,...r):`<secret>`));for(let e of r)t=t.replace(e.pattern,()=>(n(`path:${e.as}`),e.as));for(let e of i)t=t.replace(e.pattern,()=>(n(`term:${e.find}`),e.replace));return t=t.replace(Gn,e=>Jn.test(e)?e:(n(`email`),`user@example.com`)),t=t.replace(Kn,e=>qn.has(e)?e:(n(`ip`),`192.0.2.1`)),t}function o(t){let r=e.maxToolText;return r===null||t.length<=r?t:(n(`cut`),`${t.slice(0,r)}\n… [${t.length-r} more characters left out by a-kit report]`)}function s(e){return typeof e==`string`?o(a(e)):Array.isArray(e)?e.map(s):typeof e==`object`&&e?Object.fromEntries(Object.entries(e).map(([e,t])=>[e,s(t)])):e}function c(e){return e.type===`text`?{...e,text:a(e.text)}:e.type===`tool_use`?{...e,input:s(e.input)}:{...e,content:o(a(e.content))}}function l(e){return e.map(e=>e.type===`system`?e:{...e,message:{content:e.message.content.map(c)}})}return{text:a,events:l,counts:t}}const Zn=e=>e.map(e=>JSON.stringify(e)).join(`
|
|
115
115
|
`)+`
|
|
116
116
|
`;function Qn(e){let t=[],n=null,r=null,i=null;for(let a of e.split(`
|
|
117
117
|
`)){if(!a.trim())continue;let e;try{e=JSON.parse(a)}catch{continue}if(e.type!==`user`&&e.type!==`assistant`||e.isSidechain||e.isMeta)continue;r=e.version??r,i=e.cwd??i,e.type===`assistant`&&e.message?.model&&(e.message.model.startsWith(`<`)||(n=e.message.model));let o=$n(e.message?.content);o.length>0&&t.push({type:e.type,message:{content:o}})}return{agent:`claude-code`,agentVersion:r,model:n,cwd:i,events:[{type:`system`,subtype:`init`,agent:`Claude Code`,agent_version:r,model:n},...t],loaded:[...new Set(t.flatMap(Zt))]}}function $n(e){if(typeof e==`string`)return e.trim()?[{type:`text`,text:e}]:[];if(!Array.isArray(e))return[];let t=[];for(let n of e)n.type===`text`&&typeof n.text==`string`&&n.text.trim()?t.push({type:`text`,text:n.text}):n.type===`tool_use`?t.push({type:`tool_use`,id:String(n.id??``),name:String(n.name??``),input:n.input??{}}):n.type===`tool_result`&&t.push({type:`tool_result`,tool_use_id:String(n.tool_use_id??``),content:er(n.content),...n.is_error===!0?{is_error:!0}:{}});return t}function er(e){return typeof e==`string`?e:Array.isArray(e)?e.map(e=>e.type===`text`&&typeof e.text==`string`?e.text:e.type===`image`?`[image]`:``).filter(Boolean).join(`
|
|
118
118
|
`):``}const tr=[/^# AGENTS\.md instructions/,/^<(environment_context|user_instructions|permissions instructions|turn_aborted)>/];function nr(e){let t=[],n=null,r=null,i=null,a=(e,n)=>t.push({type:e,message:{content:[n]}});for(let t of e.split(`
|
|
119
119
|
`)){if(!t.trim())continue;let e;try{e=JSON.parse(t)}catch{continue}let o=e.payload??{};if(e.type===`session_meta`)r=Q(o.cli_version)??r,i=Q(o.cwd)??i;else if(e.type===`turn_context`)n=Q(o.model)??n,i=Q(o.cwd)??i;else if(e.type===`response_item`){if(o.type===`message`){let e=o.role;if(e!==`user`&&e!==`assistant`)continue;let t=ir(o.content);if(!t.trim()||e===`user`&&tr.some(e=>e.test(t.trim())))continue;a(e,{type:`text`,text:t})}else o.type===`function_call`||o.type===`custom_tool_call`?a(`assistant`,{type:`tool_use`,id:String(o.call_id??o.id??``),name:String(o.name??``),input:o.type===`function_call`?ar(o.arguments):{input:o.input??``}}):o.type===`function_call_output`||o.type===`custom_tool_call_output`?a(`user`,{type:`tool_result`,tool_use_id:String(o.call_id??``),content:or(o.output)}):o.type===`local_shell_call`&&a(`assistant`,{type:`tool_use`,id:String(o.call_id??o.id??``),name:`shell`,input:o.action??{}})}}return{agent:`codex`,agentVersion:r,model:n,cwd:i,events:[{type:`system`,subtype:`init`,agent:`Codex`,agent_version:r,model:n},...t],loaded:[...new Set(t.flatMap(Zt))]}}function rr(e){try{let t=JSON.parse(e);return t.type===`session_meta`?Q(t.payload?.cwd):null}catch{return null}}const Q=e=>typeof e==`string`&&e?e:null;function ir(e){return typeof e==`string`?e:Array.isArray(e)?e.map(e=>typeof e.text==`string`?e.text:``).filter(Boolean).join(`
|
|
120
120
|
`):``}function ar(e){if(typeof e!=`string`)return e??{};try{return JSON.parse(e)}catch{return{arguments:e}}}function or(e){if(typeof e==`string`){try{let t=JSON.parse(e);if(typeof t?.output==`string`)return t.output}catch{}return e}if(Array.isArray(e))return ir(e);if(typeof e==`object`&&e){let{content:t,output:n}=e;if(typeof n==`string`)return n;if(t!==void 0)return or(t)}return JSON.stringify(e??``)}const sr=()=>process.env.CLAUDE_CONFIG_DIR??d(h(),`.claude`),cr=()=>process.env.CODEX_HOME??d(h(),`.codex`),lr=(e,t=sr())=>d(t,`projects`,e.replace(/[^A-Za-z0-9]/g,`-`));async function ur(e,t,n=process.cwd()){if(t&&c(t))return m(t);let r=e===`claude-code`?await pr(t,n):await mr(t,n);if(r)return r.file;throw Error(t?`No ${fr(e)} session "${t}" on this machine.`:`No ${fr(e)} session for ${n}. Run this from the folder the session runs in, or pass --session <id or path>.`)}async function dr(e=process.cwd()){if(process.env.CLAUDECODE===`1`)return`claude-code`;if(Object.keys(process.env).some(e=>e.startsWith(`CODEX_`)))return`codex`;let[t,n]=await Promise.all([pr(void 0,e),mr(void 0,e)]);if(t&&(!n||t.mtime>=n.mtime))return`claude-code`;if(n)return`codex`;throw Error(`No Claude Code or Codex session for ${e}. Pass --agent and --session.`)}const fr=e=>e===`claude-code`?`Claude Code`:`Codex`;async function pr(e,t){if(e){let t=d(sr(),`projects`),n=await $(t);for(let r of n){let n=d(t,r,`${e}.jsonl`);if(c(n))return{file:n,mtime:0}}return null}for(let e of yr(t)){let t=lr(e),n=(await $(t)).filter(e=>e.endsWith(`.jsonl`));if(n.length>0)return vr(n.map(e=>d(t,e)))}return null}async function mr(e,t){let n=d(cr(),`sessions`),r=[],i=0;outer:for(let e of hr(await $(n)))for(let t of hr(await $(d(n,e))))for(let a of hr(await $(d(n,e,t)))){let o=d(n,e,t,a);for(let e of await $(o))e.startsWith(`rollout-`)&&e.endsWith(`.jsonl`)&&r.push(d(o,e));if(r.length>=300||++i>=14)break outer}return gr(r,e,t)}const hr=e=>e.sort().reverse();async function gr(e,t,n){if(t){let n=e.find(e=>l(e).includes(t));return n?{file:n,mtime:0}:null}let r=yr(n),i=/* @__PURE__ */ new Map;for(let t of e){let e=await _r(t);e&&r.includes(e)&&i.set(e,[...i.get(e)??[],t])}for(let e of r){let t=i.get(e);if(t)return vr(t)}return null}async function _r(e){let t=await te(e,`r`);try{let e=Buffer.alloc(262144),{bytesRead:n}=await t.read(e,0,e.length,0),r=e.subarray(0,n).toString(`utf8`),i=r.indexOf(`
|
|
121
|
-
`);return rr(i===-1?r:r.slice(0,i))??(JSON.parse(`"${r.match(/"cwd":"((?:[^"\\]|\\.)*)"/)?.[1]??``}"`)||null)}finally{await t.close()}}async function vr(e){let t=null;for(let n of e){let{mtimeMs:e}=await
|
|
122
|
-
`)),Buffer.byteLength(l)>Un.maxTranscriptBytes)throw Error(`The transcript is over ${Un.maxTranscriptBytes/1024/1024} MB.${e.fullOutputs?` Leave out --full-outputs.`:``}`);if(e.dryRun){
|
|
121
|
+
`);return rr(i===-1?r:r.slice(0,i))??(JSON.parse(`"${r.match(/"cwd":"((?:[^"\\]|\\.)*)"/)?.[1]??``}"`)||null)}finally{await t.close()}}async function vr(e){let t=null;for(let n of e){let{mtimeMs:e}=await T(n);(!t||e>t.mtime)&&(t={file:n,mtime:e})}return t}async function $(e){try{return await ne(e)}catch{return[]}}function yr(e){let t=[m(e)];for(;u(t.at(-1))!==t.at(-1);)t.push(u(t.at(-1)));return t}const br=2e3;function xr(e){let t=[...e.map],n=wr(()=>v().username);n&&n.length>=3&&t.push({find:n,replace:`user`});let r=wr(()=>g());r&&r.length>=3&&r!==`localhost`&&t.push({find:r,replace:`host`});let i=Sr();if(i){t.push({find:i,replace:`acme/app`});let e=i.split(`/`)[0];e.length>=3&&t.push({find:e,replace:`acme`})}let a=wr(()=>y(`git`,[`rev-parse`,`--show-toplevel`],{encoding:`utf8`,stdio:[`ignore`,`pipe`,`ignore`]}).trim());return{replacements:t,paths:[...[...new Set([...e.cwds,a].filter(Boolean))].map(e=>({path:e,as:`<repo>`})),{path:h(),as:`~`}],maxToolText:e.fullOutputs?null:br}}function Sr(){return wr(()=>y(`git`,[`remote`,`get-url`,`origin`],{encoding:`utf8`,stdio:[`ignore`,`pipe`,`ignore`]}).trim())?.match(/[:/]([^/:]+\/[^/]+?)(?:\.git)?$/)?.[1]??null}function Cr(e){let t;try{t=JSON.parse(e)}catch{throw Error(`--map isn't valid JSON.`)}let n=Array.isArray(t)?t.map(e=>[e?.find,e?.replace]):typeof t==`object`&&t?Object.entries(t):null;if(!n||!n.every(([e,t])=>typeof e==`string`&&typeof t==`string`))throw Error(`--map must be an object of words to replace, like {"Acme Corp": "Example Inc"}.`);return n.map(([e,t])=>({find:e,replace:t}))}function wr(e){try{return e()}catch{return null}}function Tr(e,t,n){let r=new Set(t),i=/* @__PURE__ */ new Map;for(let t of n)for(let[n,a]of Object.entries(t.skills))Dr(a.agents,e)&&(i.has(n)||i.set(n,{name:n,skillId:a.id,version:a.version,triggered:r.has(n)}));for(let e of t)e===`report-session-issue`||i.has(e)||i.set(e,{name:e,skillId:null,version:null,triggered:!0});return i.delete(Gt),[...i.values()]}const Er=[`codex`,`cursor`,`gemini-cli`],Dr=(e,t)=>e.length===0||e.includes(t)||Er.includes(t)&&e.some(e=>Er.includes(e));async function Or(e){R(`agent kit report`);let t=await kr(e.agent[0]),n=await ur(t,e.session||void 0),r=await w(n,`utf8`),i=Yt(t===`claude-code`?Qn(r):nr(r));if(i.events.length<2)throw Error(`${n} has no conversation to report.`);let a=Xn(xr({map:e.map?Cr(await Ar(e.map)):[],cwds:i.cwd?[i.cwd]:[],fullOutputs:e.fullOutputs})),o=a.text(Mr(e.title,`--title`,`a short title`)),s=a.text(Mr(e.note,`--note`,`what went wrong`)),c=e.expected?a.text(e.expected):null,l=Zn(a.events(i.events)),u=await Promise.all([Z(X(`project`)),Z(X(`global`))]),f=Tr(t,i.loaded,u),p={title:o,note:s,expected:c,agent:t,agentVersion:i.agentVersion,model:i.model,skills:f,transcript:l},m=d(_(),`a-kit-report-${Date.now()}.jsonl`);if(await E(m,l),L.info([`${fr(t)} session: ${n}`,`Model: ${i.model??`unknown`}, ${i.events.length-1} messages`,`Skills: ${Pr(f)}`,`Taken out: ${Fr(a.counts)}`,`Scrubbed transcript: ${m}`].join(`
|
|
122
|
+
`)),Buffer.byteLength(l)>Un.maxTranscriptBytes)throw Error(`The transcript is over ${Un.maxTranscriptBytes/1024/1024} MB.${e.fullOutputs?` Leave out --full-outputs.`:``}`);if(e.dryRun){z(`Nothing was sent. Check the file above, then run it again without --dry-run.`);return}if(!e.yes){if(!H())throw Error(`Check the scrubbed transcript, then pass --yes to send it.`);if(!U(await mt({message:`Send this report to agent kit?`}))){z(`Not sent.`);return}}let{api:h,credentials:g}=await Y(),[v,y]=await Promise.all([h.listOrganizations(),h.listSkills()]),b=Nr(e.org,v,y,f),x=await h.createReport(b.id,p);z(`Reported: ${g.webUrl}/app/orgs/${b.id}/reports/${x.id}`)}async function kr(e){if(e===void 0)return dr();if(e===`claude-code`||e===`codex`)return e;throw Error(`a-kit report reads Claude Code and Codex sessions; --agent must be claude-code or codex.`)}const Ar=e=>e===`-`?jr():w(e,`utf8`);async function jr(){let e=[];for await(let t of process.stdin)e.push(t);return Buffer.concat(e).toString(`utf8`)}function Mr(e,t,n){if(!e?.trim())throw Error(`Pass ${t} with ${n}.`);return e}function Nr(e,t,n,r){let i=()=>t.map(e=>`${e.name} (${e.id})`).join(`, `);if(e){let n=t.filter(t=>t.id===e||t.name===e);if(n.length===1)return n[0];throw Error(`--org: none of your organizations is "${e}". Yours: ${i()}`)}let a=new Set(r.map(e=>e.skillId).filter(Boolean)),o=new Set(n.filter(e=>a.has(e.id)).map(e=>e.organizationId));if(o.size===1){let e=t.find(e=>o.has(e.id));if(e)return e}if(t.length===1)return t[0];throw Error(`Which organization is it for? Pass --org with one of: ${i()}`)}function Pr(e){return e.length===0?`none`:e.map(e=>`${e.name}${e.version?` v${e.version}`:``}${e.triggered?` (loaded)`:``}`).join(`, `)}function Fr(e){let t=Object.entries(e);return t.length===0?`nothing`:t.map(([e,t])=>e===`cut`?`${t} tool outputs cut to ${br} characters`:`${e} ×${t}`).join(`, `)}function Ir(e){return e&&e.total>0?e.passed/e.total:null}async function Lr(e){let{api:t,credentials:n}=await Y(),[r,i]=await Promise.all([t.search(e.join(` `)),t.listOrganizations()]);console.log(Rr(r,n.webUrl,i.length>1))}function Rr({skills:e,runs:t},n,r){if(e.length===0&&t.length===0)return`Nothing matches.`;let i=[];if(e.length>0){let t=e.map(e=>W({...e,showOrganization:r})),n=Math.max(...t.map(e=>e.length));i.push(`Skills`),e.forEach((e,r)=>{i.push(` ${t[r].padEnd(n)} v${e.version} a-kit add ${e.name}`)})}if(t.length>0){i.length>0&&i.push(``);let e=t.map(e=>`${e.skillName} v${e.version}`),r=Math.max(...e.map(e=>e.length));i.push(`Runs`),t.forEach((t,a)=>{let o=Ir(t.withSkill),s=o===null?`—`:`${Math.round(o*100)}%`;i.push(` ${e[a].padEnd(r)} ${s.padStart(4)} ${t.status.padEnd(9)} ${n}/app/skills/${t.skillId}?tab=runs&run=${t.id}`)})}return i.join(`
|
|
123
|
+
`)}async function zr(e){switch(e){case`on`:{await Bt({telemetry:!0});let e=await vn();e.status===`skipped`?L.warn(`Couldn't add the Claude Code hook: ${e.reason}.`):L.success(`Telemetry is on: Claude Code reports the skills it loads.`);return}case`off`:{await Bt({telemetry:!1});let e=await yn();L.success(`Telemetry is off${e?`; removed the Claude Code hook`:``}. Turn it back on with \`a-kit telemetry on\`.`);return}case void 0:case`status`:{let e=await zt(),t=await bn(),n=e.telemetry===!1?`off`:Vt()?`off in this environment (DO_NOT_TRACK or AGENT_KIT_TELEMETRY)`:`on`;console.log(`Telemetry is ${n}.`),console.log(`Claude Code: ${t?`reports the skills it loads`:`no hook installed`}.`),console.log(`
|
|
123
124
|
When an agent loads a skill installed from agent kit, it reports the skill, its version, the agent, this machine and when, so your organization sees which skills get used.
|
|
124
|
-
Turn it off with \`a-kit telemetry off\`.`);return}default:throw Error(`Unknown telemetry action "${e}". Use on, off or status.`)}}async function
|
|
125
|
+
Turn it off with \`a-kit telemetry off\`.`);return}default:throw Error(`Unknown telemetry action "${e}". Use on, off or status.`)}}async function Br(e){R(`agent kit`);let t=e.global?`global`:`project`,n=X(t),r=await Z(n),i=Object.entries(r.skills);if(i.length===0){z(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 Y(),o=i.flatMap(([,e])=>Et(e.agents.map(e=>V(e)).filter(e=>e!==void 0),t));await $t([...new Set(o)]);let s=0;for(let[e,o]of i){let i;try{i=await a.getSkill(o.id)}catch(t){if(t instanceof G&&t.status===404){L.warn(`${e} isn't in your agent kit anymore; left it as it is.`);continue}throw t}if(i.version===o.version)continue;let c=Et(o.agents.map(e=>V(e)).filter(e=>e!==void 0),t);if(await an(a,o.id,c),i.name!==e){for(let t of c)await ie(d(t,e),{recursive:!0,force:!0});delete r.skills[e]}r.skills[i.name]={...o,version:i.version},await on(n,r),L.success(`${i.name}: v${o.version} → v${i.version}`+(i.name===e?``:` (was ${e})`)),s++}await xn([...new Set(i.flatMap(([,e])=>e.agents))]),z(s===0?`Everything is up to date.`:`Updated ${s} skill${s===1?``:`s`}.`)}const Vr=`a-kit ${Ct}: your agent kit skills, in your agents.
|
|
125
126
|
|
|
126
127
|
Usage
|
|
127
128
|
a-kit init Log in and pick skills to install
|
|
128
129
|
a-kit add [skill...] Install skills (asks which when none is named)
|
|
129
130
|
a-kit update Update the installed skills to their latest version
|
|
130
131
|
a-kit list Your skills, and where they're installed
|
|
132
|
+
a-kit search <query> Find skills and eval runs (\`v9\` for a version)
|
|
131
133
|
a-kit report Send an agent session that went wrong, scrubbed
|
|
132
134
|
a-kit login Log in through the browser
|
|
133
135
|
a-kit logout Log out
|
|
@@ -136,7 +138,7 @@ Usage
|
|
|
136
138
|
|
|
137
139
|
Options
|
|
138
140
|
-g, --global Install in your home folder instead of this project
|
|
139
|
-
-a, --agent <id> Install for this agent (repeatable): ${
|
|
141
|
+
-a, --agent <id> Install for this agent (repeatable): ${B.map(e=>e.id).join(`, `)}
|
|
140
142
|
-y, --yes Don't ask; use the defaults
|
|
141
143
|
-h, --help Show this help
|
|
142
144
|
|
|
@@ -150,4 +152,4 @@ Report options (the report-session-issue skill passes them for you)
|
|
|
150
152
|
--full-outputs Keep tool outputs whole (they're cut to 2,000 characters)
|
|
151
153
|
--dry-run Scrub and show what would be sent, without sending
|
|
152
154
|
-v, --version Show the version
|
|
153
|
-
`;async function
|
|
155
|
+
`;async function Hr(){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},session:{type:`string`},title:{type:`string`},note:{type:`string`},expected:{type:`string`},map:{type:`string`},org:{type:`string`},"full-outputs":{type:`boolean`,default:!1},"dry-run":{type:`boolean`,default:!1},api:{type:`string`}}});if(t.version)return console.log(Ct);let[r,...i]=n;if(t.help||!r)return console.log(Vr);let a={global:t.global,agent:t.agent.flatMap(e=>e.split(`,`)).filter(Boolean),yes:t.yes};switch(r){case`init`:return Dn(a);case`add`:case`install`:return En(i,a);case`update`:return Br(a);case`list`:case`ls`:return Rn();case`search`:if(i.length===0)throw Error("What should it look for? Like `a-kit search pdf`.");return Lr(i);case`login`:return Bn();case`logout`:return Vn();case`whoami`:return Hn();case`report`:return Or({...a,session:t.session,title:t.title,note:t.note,expected:t.expected,map:t.map,org:t.org,fullOutputs:t[`full-outputs`],dryRun:t[`dry-run`]});case`telemetry`:return zr(i[0]);case`hook`:return In(i[0],t.api);default:throw Error(`Unknown command "${r}". Run \`a-kit --help\`.`)}}Hr().catch(e=>{L.error(e instanceof Error?e.message:String(e)),process.exitCode=1});export{};
|