useakit 0.2.0-dev.15 → 0.2.0-dev.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +12 -0
  2. package/dist/index.mjs +63 -54
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -28,4 +28,16 @@ Installing skills also installs `report-session-issue`. Tell your agent "report
28
28
  - links the agent kit skills installed here, and whether the agent loaded each;
29
29
  - writes the scrubbed transcript to a file to check (`--dry-run` stops there), then sends it to your organization's Reports.
30
30
 
31
+ ## Telemetry
32
+
33
+ Installing skills for Claude Code also adds a hook to `~/.claude/settings.json`, so each time Claude Code loads a skill installed from agent kit (on its own or because you typed `/<skill>`), it reports the skill, its version, the agent, this machine (a random id and its hostname) and when. Your organization sees it on the skills table and each skill's page. Nothing else is sent: not your prompts, not your code. Reports that can't be sent wait in `~/.config/agent-kit/` for the next one.
34
+
35
+ ```sh
36
+ a-kit telemetry # whether it's on
37
+ a-kit telemetry off # stop reporting and remove the hook
38
+ a-kit telemetry on # turn it back on
39
+ ```
40
+
41
+ `DO_NOT_TRACK=1` or `AGENT_KIT_TELEMETRY=0` also stop it.
42
+
31
43
  Needs Node.js 20.12 or newer.
package/dist/index.mjs CHANGED
@@ -1,71 +1,72 @@
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,relative as f,resolve as p}from"node:path";import{homedir as m,hostname as h,tmpdir as g,userInfo as _}from"node:os";import{execFileSync as v,spawn as y}from"node:child_process";import{chmod as b,mkdir as x,open as S,readFile as C,readdir as ee,rm as w,stat as te,writeFile as T}from"node:fs/promises";import{createHash as ne}from"node:crypto";var re=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t,t.exports),e=null),t.exports);const E=(()=>{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}})(),ie=e=>e===12288||e>=65281&&e<=65376||e>=65504&&e<=65510,ae=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,oe=/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]|\u001b\]8;[^;]*;.*?(?:\u0007|\u001b\u005c)/y,se=/[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y,ce=/(?:(?![\uFF61-\uFF9F\uFF00-\uFFEF])[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\p{Script=Tangut}]){1,1000}/uy,le=/\t{1,1000}/y,ue=/[\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,de=/(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y,fe=/\p{M}+/gu,pe={limit:1/0,ellipsis:``},me=(e,t={},n={})=>{let r=t.limit??1/0,i=t.ellipsis??``,a=t?.ellipsisWidth??(i?me(i,pe,n).width:0),o=n.controlWidth??0,s=n.tabWidth??8,c=n.emojiWidth??2,l=n.regularWidth??1,u=n.wideWidth??2,d=[[de,l],[oe,0],[se,o],[le,s],[ue,c],[ce,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(fe,``)){let t=e.codePointAt(0)||0;if(S=ie(t)?2:ae(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===ce?E(e.slice(p,n.lastIndex)):n===ue?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}},he={limit:1/0,ellipsis:``,ellipsisWidth:0},D=(e,t={})=>me(e,he,t).width,ge=`]8;;`,_e=RegExp(`(?:\\[(?<code>\\d+)m|\\${ge}(?<uri>.*))`,`y`),ve=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},ye=e=>`[${e}m`,be=e=>`${ge}${e}`,xe=(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(ge,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())},Se=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(``)},Ce=(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(``),xe(s,r,t),c=D(s.at(-1)??``)}else{if(c+i>t&&c&&i){if(n.wordWrap===!1&&c<t){xe(s,r,t),c=D(s.at(-1)??``);continue}s.push(``),c=0}c+i>t&&n.wordWrap===!1?(xe(s,r,t),c=D(s.at(-1)??``)):(s[s.length-1]+=r,c+=i)}}n.trim!==!1&&(s=s.map(e=>Se(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===`›`){_e.lastIndex=e+1;let t=_e.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+=be(``));let e=i?ve(i):void 0;i&&e&&(r+=ye(e))}else t===`
5
- `&&(i&&ve(i)&&(r+=ye(i)),a&&(r+=be(a)))}return r},we=/\r?\n/;function O(e,t,n){return String(e).normalize().split(we).map(e=>Ce(e,t,n)).join(`
6
- `)}var k=(/* @__PURE__ */ re(((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 Te(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 Ee(e,t){if(typeof e==`string`)return j.aliases.get(e)===t;for(let n of e)if(n!==void 0&&Ee(n,t))return!0;return!1}function De(e,t){if(e===t)return;let n=e.split(`
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 T,stat as E,writeFile as D}from"node:fs/promises";import{createHash as ie,randomUUID as ae}from"node:crypto";import{fileURLToPath as oe}from"node:url";var se=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t,t.exports),e=null),t.exports);const ce=(()=>{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}})(),le=e=>e===12288||e>=65281&&e<=65376||e>=65504&&e<=65510,ue=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,de=/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]|\u001b\]8;[^;]*;.*?(?:\u0007|\u001b\u005c)/y,fe=/[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y,pe=/(?:(?![\uFF61-\uFF9F\uFF00-\uFFEF])[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\p{Script=Tangut}]){1,1000}/uy,me=/\t{1,1000}/y,he=/[\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,ge=/(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y,_e=/\p{M}+/gu,ve={limit:1/0,ellipsis:``},ye=(e,t={},n={})=>{let r=t.limit??1/0,i=t.ellipsis??``,a=t?.ellipsisWidth??(i?ye(i,ve,n).width:0),o=n.controlWidth??0,s=n.tabWidth??8,c=n.emojiWidth??2,l=n.regularWidth??1,u=n.wideWidth??2,d=[[ge,l],[de,0],[fe,o],[me,s],[he,c],[pe,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(_e,``)){let t=e.codePointAt(0)||0;if(S=le(t)?2:ue(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===pe?ce(e.slice(p,n.lastIndex)):n===he?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}},be={limit:1/0,ellipsis:``,ellipsisWidth:0},O=(e,t={})=>ye(e,be,t).width,xe=`]8;;`,Se=RegExp(`(?:\\[(?<code>\\d+)m|\\${xe}(?<uri>.*))`,`y`),Ce=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},we=e=>`[${e}m`,Te=e=>`${xe}${e}`,Ee=(e,t,n)=>{let r=t[Symbol.iterator](),i=!1,a=!1,o=e.at(-1),s=o===void 0?0:O(o),c=r.next(),l=r.next(),u=0;for(;!c.done;){let o=c.value,d=O(o);s+d<=n?e[e.length-1]+=o:(e.push(o),s=0),(o===`\x1B`||o===`›`)&&(i=!0,a=t.startsWith(xe,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())},De=e=>{let t=e.split(` `),n=t.length;for(;n&&!O(t[n-1]);)n--;return n===t.length?e:t.slice(0,n).join(` `)+t.slice(n).join(``)},Oe=(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=O(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=O(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(``),Ee(s,r,t),c=O(s.at(-1)??``)}else{if(c+i>t&&c&&i){if(n.wordWrap===!1&&c<t){Ee(s,r,t),c=O(s.at(-1)??``);continue}s.push(``),c=0}c+i>t&&n.wordWrap===!1?(Ee(s,r,t),c=O(s.at(-1)??``)):(s[s.length-1]+=r,c+=i)}}n.trim!==!1&&(s=s.map(e=>De(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===`›`){Se.lastIndex=e+1;let t=Se.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+=Te(``));let e=i?Ce(i):void 0;i&&e&&(r+=we(e))}else t===`
5
+ `&&(i&&Ce(i)&&(r+=we(i)),a&&(r+=Te(a)))}return r},ke=/\r?\n/;function k(e,t,n){return String(e).normalize().split(ke).map(e=>Oe(e,t,n)).join(`
6
+ `)}var A=(/* @__PURE__ */ se(((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 j(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?j(a,t<0?-1:1,n):a}const M={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 Ae(e){if(e!==void 0)return e;if(M.accessible!==void 0)return M.accessible;let t=process.env.ACCESSIBLE;return t!==void 0&&t!==``&&t!==`0`&&t!==`false`}function je(e,t){if(typeof e==`string`)return M.aliases.get(e)===t;for(let n of e)if(n!==void 0&&je(n,t))return!0;return!1}function Me(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 Oe=globalThis.process.platform.startsWith(`win`),ke=Symbol(`clack:cancel`);function Ae(e){return e===ke}function je(e,t){let n=e;n.isTTY&&n.setRawMode(t)}function Me({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(Ee([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&&!Oe&&e.setRawMode(!1),c.terminal=!1,c.close()}}const Ne=e=>`columns`in e&&typeof e.columns==`number`?e.columns:80,Pe=e=>`rows`in e&&typeof e.rows==`number`?e.rows:20;function M(e,t,n,r=n,a=n,o){return O(t,Ne(e??i)-n.length,{hard:!0,trim:!1}).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 Ne=globalThis.process.platform.startsWith(`win`),Pe=Symbol(`clack:cancel`);function Fe(e){return e===Pe}function N(e,t){let n=e;n.isTTY&&n.setRawMode(t)}function Ie({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(je([String(r),i,s],`cancel`)){a&&t.write(A.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(A.cursor.hide),e.once(`keypress`,l),()=>{e.off(`keypress`,l),a&&t.write(A.cursor.show),e instanceof s&&e.isTTY&&!Ne&&e.setRawMode(!1),c.terminal=!1,c.close()}}const Le=e=>`columns`in e&&typeof e.columns==`number`?e.columns:80,Re=e=>`rows`in e&&typeof e.rows==`number`?e.rows:20;function P(e,t,n,r=n,a=n,o){return k(t,Le(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 Fe(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 Ie=class{input;output;_abortSignal;rl;opts;_render;_track=!1;_prevFrame=``;_subscribers=/* @__PURE__ */ new Map;_cursor=0;state=`initial`;error=``;value;userInput=``;get accessible(){return Te(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(ke);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),je(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),je(this.input,!1),e(this.value)}),this.once(`cancel`,()=>{this.output.write(k.cursor.show),this.output.off(`resize`,this.render),je(this.input,!1),e(ke)})})}_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=Fe(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`)}Ee([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
- `),je(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=De(this._prevFrame,e),n=Pe(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(`
10
+ `)}function ze(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 Be=class{input;output;_abortSignal;rl;opts;_render;_track=!1;_prevFrame=``;_subscribers=/* @__PURE__ */ new Map;_cursor=0;state=`initial`;error=``;value;userInput=``;get accessible(){return Ae(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(Pe);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(A.cursor.show),this.output.off(`resize`,this.render),N(this.input,!1),e(this.value)}),this.once(`cancel`,()=>{this.output.write(A.cursor.show),this.output.off(`resize`,this.render),N(this.input,!1),e(Pe)})})}_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&&M.aliases.has(t.name)&&this.emit(`cursor`,M.aliases.get(t.name)),M.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=ze(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`)}je([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=k(this._prevFrame,process.stdout.columns,{hard:!0,trim:!1}).split(`
12
+ `).length-1;this.output.write(A.cursor.move(-999,e*-1))}render(){let e=k(this._render(this)??``,process.stdout.columns,{hard:!0,trim:!1});if(e!==this._prevFrame){if(this.state===`initial`)this.output.write(A.cursor.hide);else{let t=Me(this._prevFrame,e),n=Re(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(A.cursor.move(0,a-i)),this.output.write(A.erase.lines(1));let t=e.split(`
13
+ `);this.output.write(t[a]),this._prevFrame=e,this.output.write(A.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(A.cursor.move(0,e))}this.output.write(A.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}}},Le=class extends Ie{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})}},Re=class extends Ie{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 ze=class extends Ie{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 Be(){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 Ve=Be(),He=()=>process.env.CI===`true`,N=(e,t)=>Ve?e:t,Ue=N(`◆`,`*`),We=N(`■`,`x`),Ge=N(`▲`,`x`),Ke=N(`◇`,`o`),qe=N(`┌`,`T`),P=N(`│`,`|`),F=N(`└`,`—`),Je=N(`●`,`>`),I=N(`○`,` `),Ye=N(`◻`,`[•]`),Xe=N(`◼`,`[+]`),Ze=N(`◻`,`[ ]`),Qe=N(`●`,`•`),$e=N(`◆`,`*`),et=N(`▲`,`!`),tt=N(`■`,`x`),nt=e=>{switch(e){case`initial`:case`active`:return t(`cyan`,Ue);case`cancel`:return t(`red`,We);case`error`:return t(`yellow`,Ge);case`submit`:return t(`green`,Ke);case`validating`:return t(`dim`,Ue)}},rt=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 it(e,n){let r=[`${n?`${t(`cyan`,P)} `:``}${e.join(` • `)}`];return n&&r.push(t(`cyan`,F)),r}const at=(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}},ot=({cursor:e,options:n,style:r,output:i=process.stdout,maxItems:a=1/0,columnPadding:o=0,rowPadding:s=4})=>{let c=Ne(i)-o,l=Pe(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=()=>at(_,r,0,i,a),s=()=>at(_,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},st=e=>{let n=e.active??`Yes`,r=e.inactive??`No`;return new Le({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=`${nt(this.state)} `,o=i?`${t(`gray`,P)} `:``,s=M(e.output,e.message,o,a),c=`${i?`${t(`gray`,P)}
15
+ `)),this._prevFrame=e;return}}this.output.write(A.erase.down())}this.output.write(e),this.state===`initial`&&(this.state=`active`),this._prevFrame=e}}},Ve=class extends Be{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(A.cursor.move(0,-1)),this.value=e,this.state=`submit`,this.close()}),this.on(`cursor`,()=>{this.value=!this.value})}},He=class extends Be{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?j(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=j(this.cursor,-1,this.options);break;case`down`:case`right`:this.cursor=j(this.cursor,1,this.options);break;case`space`:this.toggleValue()}})}};let Ue=class extends Be{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?j(n,1,this.options):n,this.changeValue(),this.on(`cursor`,e=>{switch(e){case`left`:case`up`:this.cursor=j(this.cursor,-1,this.options);break;case`down`:case`right`:this.cursor=j(this.cursor,1,this.options)}this.changeValue()})}};function We(){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 Ge=We(),Ke=()=>process.env.CI===`true`,F=(e,t)=>Ge?e:t,qe=F(`◆`,`*`),Je=F(`■`,`x`),Ye=F(`▲`,`x`),Xe=F(`◇`,`o`),Ze=F(`┌`,`T`),I=F(`│`,`|`),L=F(`└`,`—`),Qe=F(`●`,`>`),$e=F(`○`,` `),et=F(`◻`,`[•]`),tt=F(`◼`,`[+]`),nt=F(`◻`,`[ ]`),rt=F(`●`,`•`),it=F(`◆`,`*`),at=F(`▲`,`!`),ot=F(`■`,`x`),st=e=>{switch(e){case`initial`:case`active`:return t(`cyan`,qe);case`cancel`:return t(`red`,Je);case`error`:return t(`yellow`,Ye);case`submit`:return t(`green`,Xe);case`validating`:return t(`dim`,qe)}},ct=e=>{switch(e){case`initial`:case`active`:return t(`cyan`,I);case`cancel`:return t(`red`,I);case`error`:return t(`yellow`,I);case`submit`:return t(`green`,I)}};function lt(e,n){let r=[`${n?`${t(`cyan`,I)} `:``}${e.join(` • `)}`];return n&&r.push(t(`cyan`,L)),r}const ut=(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}},dt=({cursor:e,options:n,style:r,output:i=process.stdout,maxItems:a=1/0,columnPadding:o=0,rowPadding:s=4})=>{let c=Le(i)-o,l=Re(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=k(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=()=>ut(_,r,0,i,a),s=()=>ut(_,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},ft=e=>{let n=e.active??`Yes`,r=e.inactive??`No`;return new Ve({active:n,inactive:r,signal:e.signal,input:e.input,output:e.output,initialValue:e.initialValue??!0,render(){let i=e.withGuide??M.withGuide,a=`${st(this.state)} `,o=i?`${t(`gray`,I)} `:``,s=P(e.output,e.message,o,a),c=`${i?`${t(`gray`,I)}
17
17
  `:``}${s}
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`,Je)} ${n}`:`${t(`dim`,I)} ${t(`dim`,n)}`}${e.vertical?i?`
20
- ${t(`cyan`,P)} `:`
21
- `:` ${t(`dim`,`/`)} `}${this.value?`${t(`dim`,I)} ${t(`dim`,r)}`:`${t(`green`,Je)} ${r}`}
18
+ `,l=this.value?n:r;switch(this.state){case`submit`:return`${c}${i?`${t(`gray`,I)} `:``}${t(`dim`,l)}`;case`cancel`:return`${c}${i?`${t(`gray`,I)} `:``}${t([`strikethrough`,`dim`],l)}${i?`
19
+ ${t(`gray`,I)}`:``}`;default:{let a=i?`${t(`cyan`,I)} `:``,o=i?t(`cyan`,L):``;return`${c}${a}${this.value?`${t(`green`,Qe)} ${n}`:`${t(`dim`,$e)} ${t(`dim`,n)}`}${e.vertical?i?`
20
+ ${t(`cyan`,I)} `:`
21
+ `:` ${t(`dim`,`/`)} `}${this.value?`${t(`dim`,$e)} ${t(`dim`,r)}`:`${t(`green`,Qe)} ${r}`}
22
22
  ${o}
23
- `}}}}).prompt()},ct=[`${t(`dim`,`↑/↓`)} to navigate`,`${t(`dim`,`Space:`)} select`,`${t(`dim`,`Enter:`)} confirm`],L=(e,t)=>e.split(`
23
+ `}}}}).prompt()},pt=[`${t(`dim`,`↑/↓`)} to navigate`,`${t(`dim`,`Space:`)} select`,`${t(`dim`,`Enter:`)} confirm`],R=(e,t)=>e.split(`
24
24
  `).map(e=>t(e)).join(`
25
- `),lt=e=>{let n=(e,n)=>{let r=e.label??String(e.value);return n===`disabled`?`${t(`gray`,Ze)} ${L(r,e=>t([`strikethrough`,`gray`],e))}${e.hint?` ${t(`dim`,`(${e.hint??`disabled`})`)}`:``}`:n===`active`?`${t(`cyan`,Ye)} ${r}${e.hint?` ${t(`dim`,`(${e.hint})`)}`:``}`:n===`selected`?`${t(`green`,Xe)} ${L(r,e=>t(`dim`,e))}${e.hint?` ${t(`dim`,`(${e.hint})`)}`:``}`:n===`cancelled`?`${L(r,e=>t([`strikethrough`,`dim`],e))}`:n===`active-selected`?`${t(`green`,Xe)} ${r}${e.hint?` ${t(`dim`,`(${e.hint})`)}`:``}`:n===`submitted`?`${L(r,e=>t(`dim`,e))}`:`${t(`dim`,Ze)} ${L(r,e=>t(`dim`,e))}`},r=e.required??!0,i=e.showInstructions??!0;return new Re({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?`${rt(this.state)} `:``,`${nt(this.state)} `),o=`${r?`${t(`gray`,P)}
25
+ `),mt=e=>{let n=(e,n)=>{let r=e.label??String(e.value);return n===`disabled`?`${t(`gray`,nt)} ${R(r,e=>t([`strikethrough`,`gray`],e))}${e.hint?` ${t(`dim`,`(${e.hint??`disabled`})`)}`:``}`:n===`active`?`${t(`cyan`,et)} ${r}${e.hint?` ${t(`dim`,`(${e.hint})`)}`:``}`:n===`selected`?`${t(`green`,tt)} ${R(r,e=>t(`dim`,e))}${e.hint?` ${t(`dim`,`(${e.hint})`)}`:``}`:n===`cancelled`?`${R(r,e=>t([`strikethrough`,`dim`],e))}`:n===`active-selected`?`${t(`green`,tt)} ${r}${e.hint?` ${t(`dim`,`(${e.hint})`)}`:``}`:n===`submitted`?`${R(r,e=>t(`dim`,e))}`:`${t(`dim`,nt)} ${R(r,e=>t(`dim`,e))}`},r=e.required??!0,i=e.showInstructions??!0;return new He({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??M.withGuide,a=P(e.output,e.message,r?`${ct(this.state)} `:``,`${st(this.state)} `),o=`${r?`${t(`gray`,I)}
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}${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(`
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}${P(e.output,i,r?`${t(`gray`,I)} `:``)}`}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`,I)}`:`${o}${P(e.output,i,r?`${t(`gray`,I)} `:``)}${r?`
29
+ ${t(`gray`,I)}`:``}`}case`error`:{let n=r?`${t(`yellow`,I)} `:``,i=this.error.split(`
30
+ `).map((e,n)=>n===0?`${r?`${t(`yellow`,L)} `:``}${t(`yellow`,e)}`:` ${e}`).join(`
31
31
  `),a=o.split(`
32
32
  `).length,s=i.split(`
33
- `).length+1;return`${o}${n}${ot({output:e.output,options:this.options,cursor:this.cursor,maxItems:e.maxItems,columnPadding:n.length,rowPadding:a+s,style:c}).join(`
33
+ `).length+1;return`${o}${n}${dt({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`,P)} `:``,a=o.split(`
37
- `).length,s=i?it(ct,r):r?[t(`cyan`,F)]:[],l=s.join(`
38
- `),u=s.length+1;return`${o}${n}${ot({output:e.output,options:this.options,cursor:this.cursor,maxItems:e.maxItems,columnPadding:n.length,rowPadding:a+u,style:c}).join(`
36
+ `}default:{let n=r?`${t(`cyan`,I)} `:``,a=o.split(`
37
+ `).length,s=i?lt(pt,r):r?[t(`cyan`,L)]:[],l=s.join(`
38
+ `),u=s.length+1;return`${o}${n}${dt({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()},R={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(`
41
+ `}}}}).prompt()},z={message:(e=[],{symbol:n=t(`gray`,I),secondarySymbol:r=t(`gray`,I),output:i=process.stdout,spacing:a=1,withGuide:o}={})=>{let s=[],c=o??M.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)=>{R.message(e,{...n,symbol:t(`blue`,Qe)})},success:(e,n)=>{R.message(e,{...n,symbol:t(`green`,$e)})},step:(e,n)=>{R.message(e,{...n,symbol:t(`green`,Ke)})},warn:(e,n)=>{R.message(e,{...n,symbol:t(`yellow`,et)})},warning:(e,t)=>{R.warn(e,t)},error:(e,n)=>{R.message(e,{...n,symbol:t(`red`,tt)})}},ut=(e=``,n)=>{let r=n?.output??process.stdout,i=n?.withGuide??j.withGuide?`${t(`gray`,F)} `:``;r.write(`${i}${t(`red`,e)}
44
+ `)},info:(e,n)=>{z.message(e,{...n,symbol:t(`blue`,rt)})},success:(e,n)=>{z.message(e,{...n,symbol:t(`green`,it)})},step:(e,n)=>{z.message(e,{...n,symbol:t(`green`,Xe)})},warn:(e,n)=>{z.message(e,{...n,symbol:t(`yellow`,at)})},warning:(e,t)=>{z.warn(e,t)},error:(e,n)=>{z.message(e,{...n,symbol:t(`red`,ot)})}},ht=(e=``,n)=>{let r=n?.output??process.stdout,i=n?.withGuide??M.withGuide?`${t(`gray`,L)} `:``;r.write(`${i}${t(`red`,e)}
45
45
 
46
- `)},z=(e=``,n)=>{let r=n?.output??process.stdout,i=n?.withGuide??j.withGuide?`${t(`gray`,qe)} `:``;r.write(`${i}${e}
47
- `)},B=(e=``,n)=>{let r=n?.output??process.stdout,i=n?.withGuide??j.withGuide?`${t(`gray`,P)}
48
- ${t(`gray`,F)} `:``;r.write(`${i}${e}
46
+ `)},B=(e=``,n)=>{let r=n?.output??process.stdout,i=n?.withGuide??M.withGuide?`${t(`gray`,Ze)} `:``;r.write(`${i}${e}
47
+ `)},V=(e=``,n)=>{let r=n?.output??process.stdout,i=n?.withGuide??M.withGuide?`${t(`gray`,I)}
48
+ ${t(`gray`,L)} `:``;r.write(`${i}${e}
49
49
 
50
- `)},dt=e=>t(`magenta`,e),ft=({indicator:e=`dots`,onCancel:n,output:r=process.stdout,cancelMessage:i,errorMessage:a,frames:o=Ve?[`◒`,`◐`,`◓`,`◑`]:[`•`,`o`,`O`,`0`],delay:s=Ve?80:120,signal:c,...l}={})=>{let u=He(),d,f,p=!1,m=!1,h=``,g,_=performance.now(),v=Ne(r),y=l?.styleFrame??dt,b=e=>{let t=e>1?a??j.messages.error:i??j.messages.cancel;m=e===1,p&&(E(t,e),m&&typeof n==`function`&&n())},x=()=>b(2),S=()=>b(1),C=()=>{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)},ee=()=>{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)},w=()=>{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())},te=e=>e.replace(/\.+$/,``),T=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]`},ne=l.withGuide??j.withGuide,re=(n=``)=>{p=!0,d=Me({output:r}),h=te(n),_=performance.now(),ne&&r.write(`${t(`gray`,P)}
53
- `);let i=0,a=0;C(),f=setInterval(()=>{if(u&&h===g)return;w(),g=h;let t=y(o[i]),n;if(u)n=`${t} ${h}...`;else if(e===`timer`)n=`${t} ${h} ${T(_)}`;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)},E=(n=``,i=0,a=!1)=>{if(!p)return;p=!1,clearInterval(f),w();let o=i===0?t(`green`,Ke):i===1?t(`red`,We):t(`red`,Ge);h=n??h,a||(e===`timer`?r.write(`${o} ${h} ${T(_)}
50
+ `)},gt=e=>t(`magenta`,e),_t=({indicator:e=`dots`,onCancel:n,output:r=process.stdout,cancelMessage:i,errorMessage:a,frames:o=Ge?[`◒`,`◐`,`◓`,`◑`]:[`•`,`o`,`O`,`0`],delay:s=Ge?80:120,signal:c,...l}={})=>{let u=Ke(),d,f,p=!1,m=!1,h=``,g,_=performance.now(),v=Le(r),y=l?.styleFrame??gt,b=e=>{let t=e>1?a??M.messages.error:i??M.messages.cancel;m=e===1,p&&(E(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=k(g,v,{hard:!0,trim:!1}).split(`
52
+ `);e.length>1&&r.write(A.cursor.up(e.length-1)),r.write(A.cursor.to(0)),r.write(A.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??M.withGuide,T=(n=``)=>{p=!0,d=Ie({output:r}),h=w(n),_=performance.now(),re&&r.write(`${t(`gray`,I)}
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=k(n,v,{hard:!0,trim:!1});r.write(s),i=i+1<o.length?i+1:0,a=a<4?a+.125:0},s)},E=(n=``,i=0,a=!1)=>{if(!p)return;p=!1,clearInterval(f),te();let o=i===0?t(`green`,Xe):i===1?t(`red`,Je):t(`red`,Ye);h=n??h,a||(e===`timer`?r.write(`${o} ${h} ${ne(_)}
54
54
  `):r.write(`${o} ${h}
55
- `)),ee(),d()};return{start:re,stop:(e=``)=>E(e,0),message:(e=``)=>{h=te(e??h)},cancel:(e=``)=>E(e,1),error:(e=``)=>E(e,2),clear:()=>E(``,0,!0),get isCancelled(){return m}}},pt=[`${t(`dim`,`↑/↓`)} to navigate`,`${t(`dim`,`Enter:`)} confirm`],V=(e,t)=>e.includes(`
55
+ `)),C(),d()};return{start:T,stop:(e=``)=>E(e,0),message:(e=``)=>{h=w(e??h)},cancel:(e=``)=>E(e,1),error:(e=``)=>E(e,2),clear:()=>E(``,0,!0),get isCancelled(){return m}}},vt=[`${t(`dim`,`↑/↓`)} to navigate`,`${t(`dim`,`Enter:`)} confirm`],yt=(e,t)=>e.includes(`
56
56
  `)?e.split(`
57
57
  `).map(e=>t(e)).join(`
58
- `):t(e),mt=e=>{let n=(e,n)=>{if(e===void 0)return``;let r=e.label??String(e.value);switch(n){case`disabled`:return`${t(`gray`,I)} ${V(r,e=>t(`gray`,e))}${e.hint?` ${t(`dim`,`(${e.hint??`disabled`})`)}`:``}`;case`selected`:return`${V(r,e=>t(`dim`,e))}`;case`active`:return`${t(`green`,Je)} ${r}${e.hint?` ${t(`dim`,`(${e.hint})`)}`:``}`;case`cancelled`:return`${V(r,e=>t([`strikethrough`,`dim`],e))}`;default:return`${t(`dim`,I)} ${V(r,e=>t(`dim`,e))}`}},r=e.showInstructions??!0;return new ze({options:e.options,signal:e.signal,input:e.input,output:e.output,initialValue:e.initialValue,render(){let i=e.withGuide??j.withGuide,a=`${nt(this.state)} `,o=`${rt(this.state)} `,s=M(e.output,e.message,o,a),c=`${i?`${t(`gray`,P)}
58
+ `):t(e),bt=e=>{let n=(e,n)=>{if(e===void 0)return``;let r=e.label??String(e.value);switch(n){case`disabled`:return`${t(`gray`,$e)} ${yt(r,e=>t(`gray`,e))}${e.hint?` ${t(`dim`,`(${e.hint??`disabled`})`)}`:``}`;case`selected`:return`${yt(r,e=>t(`dim`,e))}`;case`active`:return`${t(`green`,Qe)} ${r}${e.hint?` ${t(`dim`,`(${e.hint})`)}`:``}`;case`cancelled`:return`${yt(r,e=>t([`strikethrough`,`dim`],e))}`;default:return`${t(`dim`,$e)} ${yt(r,e=>t(`dim`,e))}`}},r=e.showInstructions??!0;return new Ue({options:e.options,signal:e.signal,input:e.input,output:e.output,initialValue:e.initialValue,render(){let i=e.withGuide??M.withGuide,a=`${st(this.state)} `,o=`${ct(this.state)} `,s=P(e.output,e.message,o,a),c=`${i?`${t(`gray`,I)}
59
59
  `:``}${s}
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?it(pt,i):i?[t(`cyan`,F)]:[],l=s.join(`
63
- `),u=s.length+1;return`${c}${a}${ot({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(`
60
+ `;switch(this.state){case`submit`:{let r=i?`${t(`gray`,I)} `:``;return`${c}${P(e.output,n(this.options[this.cursor],`selected`),r)}`}case`cancel`:{let r=i?`${t(`gray`,I)} `:``;return`${c}${P(e.output,n(this.options[this.cursor],`cancelled`),r)}${i?`
61
+ ${t(`gray`,I)}`:``}`}default:{let a=i?`${t(`cyan`,I)} `:``,o=c.split(`
62
+ `).length,s=r?lt(vt,i):i?[t(`cyan`,L)]:[],l=s.join(`
63
+ `),u=s.length+1;return`${c}${a}${dt({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`,P)}`;var ht=`0.2.0`;const H=[{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`}],gt=e=>e===`global`?m():process.cwd();function _t(e=m()){return H.filter(t=>c(d(e,t.marker)))}function U(e){return H.find(t=>t.id===e)}function vt(e,t,n=gt(t)){let r=e.map(e=>p(n,t===`global`?e.globalDir:e.projectDir));return[...new Set(r)]}const W=()=>!!(process.stdin.isTTY&&process.stdout.isTTY)&&!process.env.CI;function G(e){return Ae(e)&&(ut(`Cancelled.`),process.exit(130)),e}async function yt(e,t){if(e.length>0)return e.map(e=>{let t=U(e);if(!t)throw Error(`Unknown agent "${e}". Use one of: ${H.map(e=>e.id).join(`, `)}.`);return t});let n=_t(),r=n.length>0?n:[U(`claude-code`)];return!t||!W()?r:G(await lt({message:`Which agents should get the skills?`,options:H.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=>U(e))}async function bt(e,t){return e?`global`:!t||!W()?`project`:G(await mt({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 xt(e,t,n){if(t.length>0){let r=[];for(let i of t){let t=St(e,i);r.push(t.length===1?t[0]:await Ct(t,n))}return r}if(!n||!W())throw Error("Name the skills to add, like `a-kit add my-skill`.");let r=G(await lt({message:`Which skills?`,options:e.map(e=>({value:e.id,label:K(e),hint:e.description.length>60?`${e.description.slice(0,57)}…`:e.description})),required:!0}));return e.filter(e=>r.includes(e.id))}function St(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 Ct(e,t){let n=e[0].name;if(!t||!W()){let t=e.map(e=>{let t=wt(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=G(await mt({message:`More than one of your organizations has "${n}". Which one?`,options:e.map(e=>({value:e.id,label:wt(e)}))}));return e.find(e=>e.id===r)}const wt=e=>`${e.organizationName}/${e.name}`,K=e=>e.showOrganization?`${e.name} (${e.organizationName})`:e.name;var q=class extends Error{status;code;constructor(e,t,n){super(n),this.status=e,this.code=t}};function J(e,t,n=fetch){async function r(r,i={}){let a;try{a=await n(`${e}${r}`,{...i,headers:{"User-Agent":`a-kit/${ht}`,...i.body?{"Content-Type":`application/json`}:{},...t?{Authorization:`Bearer ${t}`}:{},...i.headers}})}catch{throw new q(0,`NETWORK`,`Couldn't reach ${e}.`)}if(!a.ok){let e=await a.json().catch(()=>null);throw a.status===401?new q(401,`UNAUTHORIZED`,"You're not logged in. Run `a-kit login`."):new q(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`),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 Tt(e){let[t,n]=process.platform===`darwin`?[`open`,[e]]:process.platform===`win32`?[`cmd`,[`/c`,`start`,``,e.replace(/&/g,`^&`)]]:[`xdg-open`,[e]];try{let e=y(t,n,{stdio:`ignore`,detached:!0});e.on(`error`,()=>{}),e.unref()}catch{}}function Y(){return(process.env.AGENT_KIT_API_URL??`https://api-dev.agent-kit.fausanchez.com`??`http://localhost:8787`).replace(/\/+$/,``)}function Et(){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(m(),`.config`),`agent-kit`)}const Dt=()=>d(Et(),`credentials.json`);async function Ot(){try{return JSON.parse(await C(Dt(),`utf8`))}catch{return{}}}async function kt(){return(await Ot())[Y()]??null}async function At(e){let t=await Ot();e?t[Y()]=e:delete t[Y()];let n=Dt();await x(u(n),{recursive:!0,mode:448}),await T(n,JSON.stringify(t,null,2)+`
67
- `,{mode:384}),await b(n,384)}const jt=e=>new Promise(t=>setTimeout(t,e));async function Mt(){let e=await J(Y()).startLogin();R.step(`Your code: ${e.userCode}\nApprove it in your browser: ${e.verificationUrl}`),Tt(e.verificationUrl);let t=ft();t.start(`Waiting for you to approve it`);let n=J(Y()),r=Date.now()+e.expiresIn*1e3;for(;Date.now()<r;){await jt(e.interval*1e3);let r;try{r=await n.pollLogin(e.deviceCode)}catch(e){if(e instanceof q&&e.status===410)break;if(e instanceof q&&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 At(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 Nt(){let e=await kt();if(!e)return null;try{let t=await J(Y(),e.token).me();return{...e,user:t}}catch(e){if(e instanceof q&&e.status===401)return await At(null),null;throw e}}async function Pt(){let e=await kt();if(!e)throw Error("You're not logged in. Run `a-kit login` first.");return{api:J(Y(),e.token),credentials:e}}const Ft=`report-session-issue`,It=/skills\/([a-z0-9][a-z0-9-]*)\/SKILL\.md/g;function Lt(e,t){if(e===`Skill`){let e=t?.skill;return typeof e==`string`?[Rt(e)]:[]}return[...(typeof t==`string`?t:JSON.stringify(t??``)).matchAll(It)].map(e=>e[1])}const Rt=e=>e.slice(e.lastIndexOf(`:`)+1).replace(/^\//,``);function zt(e){let t=e.events.findIndex(e=>Bt(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(Vt))]}}function Bt(e){return Vt(e).includes(Ft)}function Vt(e){return e.type===`system`?[]:e.message.content.flatMap(t=>t.type===`tool_use`?Lt(t.name,t.input):t.type===`text`&&e.type===`user`?[...t.text.matchAll(/<command-name>\/?([\w:-]+)<\/command-name>/g)].map(e=>Rt(e[1])):[])}const Ht=(e=`npx -y useakit@next`)=>`---
68
- name: ${Ft}
66
+ `}}}}).prompt()};`${t(`gray`,I)}`;var xt=`0.2.0`;const H=[{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`}],St=e=>e===`global`?h():process.cwd();function Ct(e=h()){return H.filter(t=>c(d(e,t.marker)))}function U(e){return H.find(t=>t.id===e)}function wt(e,t,n=St(t)){let r=e.map(e=>m(n,t===`global`?e.globalDir:e.projectDir));return[...new Set(r)]}const W=()=>!!(process.stdin.isTTY&&process.stdout.isTTY)&&!process.env.CI;function G(e){return Fe(e)&&(ht(`Cancelled.`),process.exit(130)),e}async function Tt(e,t){if(e.length>0)return e.map(e=>{let t=U(e);if(!t)throw Error(`Unknown agent "${e}". Use one of: ${H.map(e=>e.id).join(`, `)}.`);return t});let n=Ct(),r=n.length>0?n:[U(`claude-code`)];return!t||!W()?r:G(await mt({message:`Which agents should get the skills?`,options:H.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=>U(e))}async function Et(e,t){return e?`global`:!t||!W()?`project`:G(await bt({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 Dt(e,t,n){if(t.length>0){let r=[];for(let i of t){let t=Ot(e,i);r.push(t.length===1?t[0]:await kt(t,n))}return r}if(!n||!W())throw Error("Name the skills to add, like `a-kit add my-skill`.");let r=G(await mt({message:`Which skills?`,options:e.map(e=>({value:e.id,label:jt(e),hint:e.description.length>60?`${e.description.slice(0,57)}…`:e.description})),required:!0}));return e.filter(e=>r.includes(e.id))}function Ot(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 kt(e,t){let n=e[0].name;if(!t||!W()){let t=e.map(e=>{let t=At(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=G(await bt({message:`More than one of your organizations has "${n}". Which one?`,options:e.map(e=>({value:e.id,label:At(e)}))}));return e.find(e=>e.id===r)}const At=e=>`${e.organizationName}/${e.name}`,jt=e=>e.showOrganization?`${e.name} (${e.organizationName})`:e.name;var K=class extends Error{status;code;constructor(e,t,n){super(n),this.status=e,this.code=t}};function q(e,t,n=fetch){async function r(r,i={}){let a;try{a=await n(`${e}${r}`,{...i,headers:{"User-Agent":`a-kit/${xt}`,...i.body?{"Content-Type":`application/json`}:{},...t?{Authorization:`Bearer ${t}`}:{},...i.headers}})}catch{throw new K(0,`NETWORK`,`Couldn't reach ${e}.`)}if(!a.ok){let e=await a.json().catch(()=>null);throw a.status===401?new K(401,`UNAUTHORIZED`,"You're not logged in. Run `a-kit login`."):new K(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}),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 Mt(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 J(){return(process.env.AGENT_KIT_API_URL??`https://api-dev.agent-kit.fausanchez.com`??`http://localhost:8787`).replace(/\/+$/,``)}function Y(){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 Nt=()=>d(Y(),`credentials.json`);async function Pt(){try{return JSON.parse(await w(Nt(),`utf8`))}catch{return{}}}async function Ft(){return(await Pt())[J()]??null}async function It(e){let t=await Pt();e?t[J()]=e:delete t[J()];let n=Nt();await C(u(n),{recursive:!0,mode:448}),await D(n,JSON.stringify(t,null,2)+`
67
+ `,{mode:384}),await S(n,384)}const Lt=()=>d(Y(),`settings.json`);async function Rt(){try{return JSON.parse(await w(Lt(),`utf8`))}catch{return{}}}async function zt(e){let t={...await Rt(),...e};await C(Y(),{recursive:!0,mode:448}),await D(Lt(),JSON.stringify(t,null,2)+`
68
+ `)}function Bt(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 Vt=e=>new Promise(t=>setTimeout(t,e));async function Ht(){let e=await q(J()).startLogin();z.step(`Your code: ${e.userCode}\nApprove it in your browser: ${e.verificationUrl}`),Mt(e.verificationUrl);let t=_t();t.start(`Waiting for you to approve it`);let n=q(J()),r=Date.now()+e.expiresIn*1e3;for(;Date.now()<r;){await Vt(e.interval*1e3);let r;try{r=await n.pollLogin(e.deviceCode)}catch(e){if(e instanceof K&&e.status===410)break;if(e instanceof K&&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 It(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 Ut(){let e=await Ft();if(!e)return null;try{let t=await q(J(),e.token).me();return{...e,user:t}}catch(e){if(e instanceof K&&e.status===401)return await It(null),null;throw e}}async function Wt(){let e=await Ft();if(!e)throw Error("You're not logged in. Run `a-kit login` first.");return{api:q(J(),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
+ name: ${Gt}
69
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.
70
71
  ---
71
72
 
@@ -104,16 +105,23 @@ Only the conversation up to the developer's request to report it is sent; this p
104
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.
105
106
 
106
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.
107
- `;async function Ut(e){for(let t of e){let e=d(t,Ft);await x(e,{recursive:!0}),await T(d(e,`SKILL.md`),Ht())}}const Wt={maxFiles:200,maxFileBytes:1048576,maxSkillBytes:10485760,maxPathLength:255},Gt=/[\u0000-\u001f\u007f\\:]/;function Kt(e){if(e.trim()===``)return`The path is empty.`;if(e.length>Wt.maxPathLength)return`Paths can be at most ${Wt.maxPathLength} characters.`;if(e.startsWith(`/`))return`Use a relative path, without a leading /.`;if(Gt.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 qt=e=>ne(`sha256`).update(e).digest(`hex`);async function Jt(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=Kt(t.path);if(n)throw Error(`${r.name}: ${t.path}: ${n}`);let a=await e.getBlob(r.id,t.sha256);if(qt(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 w(t,{recursive:!0,force:!0});for(let e of i){let n=d(t,e.path);await x(u(n),{recursive:!0}),await T(n,e.bytes)}}return r}const X=(e,t=process.cwd())=>e===`global`?d(Et(),`global.lock.json`):d(t,`agent-kit.lock.json`);async function Z(e){try{return{version:1,skills:JSON.parse(await C(e,`utf8`)).skills??{}}}catch{return{version:1,skills:{}}}}async function Yt(e,t){let n=Object.fromEntries(Object.entries(t.skills).sort(([e],[t])=>e.localeCompare(t)));await x(u(e),{recursive:!0}),await T(e,JSON.stringify({...t,skills:n},null,2)+`
108
- `)}async function Xt(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=vt(n,r),o=X(r),s=await Z(o),c=ft();await Ut(a);for(let r of t){c.start(`Installing ${r.name}`);try{let t=await Jt(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 Yt(o,s),e}}return await Yt(o,s),{dirs:a,lockFile:o}}function Zt(e){let t=f(process.cwd(),e);return t&&!t.startsWith(`..`)?t:e}async function Qt(e,t){z(`agent kit`);let{api:n}=await Pt(),r=!t.yes,{dirs:i}=await Xt(n,await xt(await n.listSkills(),e,r),await yt(t.agent,r),t.global?`global`:`project`);B(`Installed in ${i.map(Zt).join(`, `)}`)}async function $t(e){z(`agent kit`);let t=await Nt();t?R.success(`Logged in as ${t.user.email}`):t=await Mt();let n=J(Y(),t.token),r=await n.listSkills();if(r.length===0){B(`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&&!W())throw Error("`a-kit init` asks questions. Pass --yes to install every skill, or use `a-kit add <skill>`.");let a=await bt(e.global,i),o=await yt(e.agent,i),s=i?G(await lt({message:`Which skills?`,options:r.map(e=>({value:e.id,label:K(e)})),initialValues:r.map(e=>e.id),required:!0})):r.map(e=>e.id),{dirs:c}=await Xt(n,r.filter(e=>s.includes(e.id)),o,a);B(`Installed in ${c.map(Zt).join(`, `)}`)}async function en(){let{api:e,credentials:t}=await Pt(),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=>K(e).length));for(let e of n){let t=[tn(`project`,r.skills[e.name]?.version,e.version),tn(`global`,i.skills[e.name]?.version,e.version)].filter(Boolean);console.log(`${K(e).padEnd(a)} v${e.version}`+(t.length?` (${t.join(`, `)})`:``))}}function tn(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 nn(){z(`agent kit`);let e=await Mt();B(`Logged in as ${e.user.email}`)}async function rn(){let e=await kt();e?(await J(Y(),e.token).logout().catch(()=>{}),await At(null),console.log(`Logged out ${e.user.email}.`)):console.log(`You're not logged in.`)}async function an(){let e=await Nt();e?console.log(e.user.email):(console.log("You're not logged in. Run `a-kit login`."),process.exitCode=1)}const on={maxTitleLength:120,maxNoteLength:4e3,maxSkills:50,maxTranscriptBytes:8388608},sn=[{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}],cn=/[A-Za-z0-9._%+-]+@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*\.[A-Za-z]{2,}\b/g,ln=/\b(?:(?:25[0-5]|2[0-4]\d|1?\d?\d)\.){3}(?:25[0-5]|2[0-4]\d|1?\d?\d)\b/g,un=/* @__PURE__ */ new Set([`127.0.0.1`,`0.0.0.0`]),dn=/@(?:example\.(?:com|org|net)|anthropic\.com)$/i,fn=e=>e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);function pn(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(fn(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}_])${fn(e.find)}(?![\\p{L}\\p{N}_])`:fn(e.find),`giu`)}));function a(e){let t=e;for(let e of sn)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(cn,e=>dn.test(e)?e:(n(`email`),`user@example.com`)),t=t.replace(ln,e=>un.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 mn=e=>e.map(e=>JSON.stringify(e)).join(`
108
+ `;async function $t(e){for(let t of e){let e=d(t,Gt);await C(e,{recursive:!0}),await D(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=>ie(`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 T(t,{recursive:!0,force:!0});for(let e of i){let n=d(t,e.path);await C(u(n),{recursive:!0}),await D(n,e.bytes)}}return r}const X=(e,t=process.cwd())=>e===`global`?d(Y(),`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 D(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(Y(),`bin`,`a-kit.mjs`);function _n(){let e=oe(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,J());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 Rt()).telemetry!==!1)try{(await vn()).status===`installed`&&z.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 D(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=wt(n,r),o=X(r),s=await Z(o),c=_t();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){B(`agent kit`);let{api:n}=await Wt(),r=!t.yes,{dirs:i}=await wn(n,await Dt(await n.listSkills(),e,r),await Tt(t.agent,r),t.global?`global`:`project`);V(`Installed in ${i.map(Tn).join(`, `)}`)}async function Dn(e){B(`agent kit`);let t=await Ut();t?z.success(`Logged in as ${t.user.email}`):t=await Ht();let n=q(J(),t.token),r=await n.listSkills();if(r.length===0){V(`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&&!W())throw Error("`a-kit init` asks questions. Pass --yes to install every skill, or use `a-kit add <skill>`.");let a=await Et(e.global,i),o=await Tt(e.agent,i),s=i?G(await mt({message:`Which skills?`,options:r.map(e=>({value:e.id,label:jt(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);V(`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(Y(),`machine.json`);try{let t=JSON.parse(await w(e,`utf8`));if(typeof t.id==`string`&&t.id)return t.id}catch{}let t=ae();return await C(u(e),{recursive:!0,mode:448}),await D(e,JSON.stringify({id:t},null,2)+`
111
+ `),t}async function jn(e,t,n,r=/* @__PURE__ */ new Date){return{id:ae(),skillId:e.id,version:e.version,agent:t,machineId:await An(),machineName:g()||null,trigger:n,occurredAt:r.toISOString()}}const Mn=()=>d(Y(),`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 T(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(Y(),{recursive:!0,mode:448}),await x(Mn(),n.map(e=>JSON.stringify(e)).join(`
109
112
  `)+`
110
- `;function hn(e){let t=[],n=null,r=null,i=null;for(let a of e.split(`
111
- `)){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=gn(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(Vt))]}}function gn(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:_n(n.content),...n.is_error===!0?{is_error:!0}:{}});return t}function _n(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(`
112
- `):``}const vn=[/^# AGENTS\.md instructions/,/^<(environment_context|user_instructions|permissions instructions|turn_aborted)>/];function yn(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(`
113
- `)){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=xn(o.content);if(!t.trim()||e===`user`&&vn.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`?Sn(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:Cn(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(Vt))]}}function bn(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 xn(e){return typeof e==`string`?e:Array.isArray(e)?e.map(e=>typeof e.text==`string`?e.text:``).filter(Boolean).join(`
114
- `):``}function Sn(e){if(typeof e!=`string`)return e??{};try{return JSON.parse(e)}catch{return{arguments:e}}}function Cn(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 xn(e);if(typeof e==`object`&&e){let{content:t,output:n}=e;if(typeof n==`string`)return n;if(t!==void 0)return Cn(t)}return JSON.stringify(e??``)}const wn=()=>process.env.CLAUDE_CONFIG_DIR??d(m(),`.claude`),Tn=()=>process.env.CODEX_HOME??d(m(),`.codex`),En=(e,t=wn())=>d(t,`projects`,e.replace(/[^A-Za-z0-9]/g,`-`));async function Dn(e,t,n=process.cwd()){if(t&&c(t))return p(t);let r=e===`claude-code`?await An(t,n):await jn(t,n);if(r)return r.file;throw Error(t?`No ${kn(e)} session "${t}" on this machine.`:`No ${kn(e)} session for ${n}. Run this from the folder the session runs in, or pass --session <id or path>.`)}async function On(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([An(void 0,e),jn(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 kn=e=>e===`claude-code`?`Claude Code`:`Codex`;async function An(e,t){if(e){let t=d(wn(),`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 In(t)){let t=En(e),n=(await $(t)).filter(e=>e.endsWith(`.jsonl`));if(n.length>0)return Fn(n.map(e=>d(t,e)))}return null}async function jn(e,t){let n=d(Tn(),`sessions`),r=[],i=0;outer:for(let e of Mn(await $(n)))for(let t of Mn(await $(d(n,e))))for(let a of Mn(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 Nn(r,e,t)}const Mn=e=>e.sort().reverse();async function Nn(e,t,n){if(t){let n=e.find(e=>l(e).includes(t));return n?{file:n,mtime:0}:null}let r=In(n),i=/* @__PURE__ */ new Map;for(let t of e){let e=await Pn(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 Fn(t)}return null}async function Pn(e){let t=await S(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(`
115
- `);return bn(i===-1?r:r.slice(0,i))??(JSON.parse(`"${r.match(/"cwd":"((?:[^"\\]|\\.)*)"/)?.[1]??``}"`)||null)}finally{await t.close()}}async function Fn(e){let t=null;for(let n of e){let{mtimeMs:e}=await te(n);(!t||e>t.mtime)&&(t={file:n,mtime:e})}return t}async function $(e){try{return await ee(e)}catch{return[]}}function In(e){let t=[p(e)];for(;u(t.at(-1))!==t.at(-1);)t.push(u(t.at(-1)));return t}const Ln=2e3;function Rn(e){let t=[...e.map],n=Vn(()=>_().username);n&&n.length>=3&&t.push({find:n,replace:`user`});let r=Vn(()=>h());r&&r.length>=3&&r!==`localhost`&&t.push({find:r,replace:`host`});let i=zn();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=Vn(()=>v(`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:m(),as:`~`}],maxToolText:e.fullOutputs?null:Ln}}function zn(){return Vn(()=>v(`git`,[`remote`,`get-url`,`origin`],{encoding:`utf8`,stdio:[`ignore`,`pipe`,`ignore`]}).trim())?.match(/[:/]([^/:]+\/[^/]+?)(?:\.git)?$/)?.[1]??null}function Bn(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 Vn(e){try{return e()}catch{return null}}function Hn(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))Wn(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(Ft),[...i.values()]}const Un=[`codex`,`cursor`,`gemini-cli`],Wn=(e,t)=>e.length===0||e.includes(t)||Un.includes(t)&&e.some(e=>Un.includes(e));async function Gn(e){z(`agent kit report`);let t=await Kn(e.agent[0]),n=await Dn(t,e.session||void 0),r=await C(n,`utf8`),i=zt(t===`claude-code`?hn(r):yn(r));if(i.events.length<2)throw Error(`${n} has no conversation to report.`);let a=pn(Rn({map:e.map?Bn(await qn(e.map)):[],cwds:i.cwd?[i.cwd]:[],fullOutputs:e.fullOutputs})),o=a.text(Yn(e.title,`--title`,`a short title`)),s=a.text(Yn(e.note,`--note`,`what went wrong`)),c=e.expected?a.text(e.expected):null,l=mn(a.events(i.events)),u=await Promise.all([Z(X(`project`)),Z(X(`global`))]),f=Hn(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(g(),`a-kit-report-${Date.now()}.jsonl`);if(await T(m,l),R.info([`${kn(t)} session: ${n}`,`Model: ${i.model??`unknown`}, ${i.events.length-1} messages`,`Skills: ${Zn(f)}`,`Taken out: ${Qn(a.counts)}`,`Scrubbed transcript: ${m}`].join(`
116
- `)),Buffer.byteLength(l)>on.maxTranscriptBytes)throw Error(`The transcript is over ${on.maxTranscriptBytes/1024/1024} MB.${e.fullOutputs?` Leave out --full-outputs.`:``}`);if(e.dryRun){B(`Nothing was sent. Check the file above, then run it again without --dry-run.`);return}if(!e.yes){if(!W())throw Error(`Check the scrubbed transcript, then pass --yes to send it.`);if(!G(await st({message:`Send this report to agent kit?`}))){B(`Not sent.`);return}}let{api:h,credentials:_}=await Pt(),[v,y]=await Promise.all([h.listOrganizations(),h.listSkills()]),b=Xn(e.org,v,y,f),x=await h.createReport(b.id,p);B(`Reported: ${_.webUrl}/app/orgs/${b.id}/reports/${x.id}`)}async function Kn(e){if(e===void 0)return On();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 qn=e=>e===`-`?Jn():C(e,`utf8`);async function Jn(){let e=[];for await(let t of process.stdin)e.push(t);return Buffer.concat(e).toString(`utf8`)}function Yn(e,t,n){if(!e?.trim())throw Error(`Pass ${t} with ${n}.`);return e}function Xn(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 Zn(e){return e.length===0?`none`:e.map(e=>`${e.name}${e.version?` v${e.version}`:``}${e.triggered?` (loaded)`:``}`).join(`, `)}function Qn(e){let t=Object.entries(e);return t.length===0?`nothing`:t.map(([e,t])=>e===`cut`?`${t} tool outputs cut to ${Ln} characters`:`${e} ×${t}`).join(`, `)}async function $n(e){z(`agent kit`);let t=e.global?`global`:`project`,n=X(t),r=await Z(n),i=Object.entries(r.skills);if(i.length===0){B(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 Pt(),o=i.flatMap(([,e])=>vt(e.agents.map(e=>U(e)).filter(e=>e!==void 0),t));await Ut([...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 q&&t.status===404){R.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=vt(o.agents.map(e=>U(e)).filter(e=>e!==void 0),t);if(await Jt(a,o.id,c),i.name!==e){for(let t of c)await w(d(t,e),{recursive:!0,force:!0});delete r.skills[e]}r.skills[i.name]={...o,version:i.version},await Yt(n,r),R.success(`${i.name}: v${o.version} → v${i.version}`+(i.name===e?``:` (was ${e})`)),s++}B(s===0?`Everything is up to date.`:`Updated ${s} skill${s===1?``:`s`}.`)}const er=`a-kit ${ht}: your agent kit skills, in your agents.
113
+ `),{sent:a,queued:n.length}}}return{sent:a,queued:0}}const Pn=e=>!(e instanceof K)||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||Bt()||(await Rt()).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 Ft();if(!a)return;let o=q(J(),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 Wt(),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=>jt(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(`${jt(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(){B(`agent kit`);let e=await Ht();V(`Logged in as ${e.user.email}`)}async function Vn(){let e=await Ft();e?(await q(J(),e.token).logout().catch(()=>{}),await It(null),console.log(`Logged out ${e.user.email}.`)):console.log(`You're not logged in.`)}async function Hn(){let e=await Ut();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
+ `)+`
116
+ `;function Qn(e){let t=[],n=null,r=null,i=null;for(let a of e.split(`
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
+ `):``}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
+ `)){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
+ `):``}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 E(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){B(`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 D(m,l),z.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){V(`Nothing was sent. Check the file above, then run it again without --dry-run.`);return}if(!e.yes){if(!W())throw Error(`Check the scrubbed transcript, then pass --yes to send it.`);if(!G(await ft({message:`Send this report to agent kit?`}))){V(`Not sent.`);return}}let{api:h,credentials:g}=await Wt(),[v,y]=await Promise.all([h.listOrganizations(),h.listSkills()]),b=Nr(e.org,v,y,f),x=await h.createReport(b.id,p);V(`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(`, `)}async function Ir(e){switch(e){case`on`:{await zt({telemetry:!0});let e=await vn();e.status===`skipped`?z.warn(`Couldn't add the Claude Code hook: ${e.reason}.`):z.success(`Telemetry is on: Claude Code reports the skills it loads.`);return}case`off`:{await zt({telemetry:!1});let e=await yn();z.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 Rt(),t=await bn(),n=e.telemetry===!1?`off`:Bt()?`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
+ 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 Lr(e){B(`agent kit`);let t=e.global?`global`:`project`,n=X(t),r=await Z(n),i=Object.entries(r.skills);if(i.length===0){V(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 Wt(),o=i.flatMap(([,e])=>wt(e.agents.map(e=>U(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 K&&t.status===404){z.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=wt(o.agents.map(e=>U(e)).filter(e=>e!==void 0),t);if(await an(a,o.id,c),i.name!==e){for(let t of c)await T(d(t,e),{recursive:!0,force:!0});delete r.skills[e]}r.skills[i.name]={...o,version:i.version},await on(n,r),z.success(`${i.name}: v${o.version} → v${i.version}`+(i.name===e?``:` (was ${e})`)),s++}await xn([...new Set(i.flatMap(([,e])=>e.agents))]),V(s===0?`Everything is up to date.`:`Updated ${s} skill${s===1?``:`s`}.`)}const Rr=`a-kit ${xt}: your agent kit skills, in your agents.
117
125
 
118
126
  Usage
119
127
  a-kit init Log in and pick skills to install
@@ -124,6 +132,7 @@ Usage
124
132
  a-kit login Log in through the browser
125
133
  a-kit logout Log out
126
134
  a-kit whoami Who you're logged in as
135
+ a-kit telemetry [on|off] Whether your agents report the skills they load
127
136
 
128
137
  Options
129
138
  -g, --global Install in your home folder instead of this project
@@ -141,4 +150,4 @@ Report options (the report-session-issue skill passes them for you)
141
150
  --full-outputs Keep tool outputs whole (they're cut to 2,000 characters)
142
151
  --dry-run Scrub and show what would be sent, without sending
143
152
  -v, --version Show the version
144
- `;async function tr(){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}}});if(t.version)return console.log(ht);let[r,...i]=n;if(t.help||!r)return console.log(er);let a={global:t.global,agent:t.agent.flatMap(e=>e.split(`,`)).filter(Boolean),yes:t.yes};switch(r){case`init`:return $t(a);case`add`:case`install`:return Qt(i,a);case`update`:return $n(a);case`list`:case`ls`:return en();case`login`:return nn();case`logout`:return rn();case`whoami`:return an();case`report`:return Gn({...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`]});default:throw Error(`Unknown command "${r}". Run \`a-kit --help\`.`)}}tr().catch(e=>{R.error(e instanceof Error?e.message:String(e)),process.exitCode=1});export{};
153
+ `;async function zr(){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(xt);let[r,...i]=n;if(t.help||!r)return console.log(Rr);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 Lr(a);case`list`:case`ls`:return Rn();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 Ir(i[0]);case`hook`:return In(i[0],t.api);default:throw Error(`Unknown command "${r}". Run \`a-kit --help\`.`)}}zr().catch(e=>{z.error(e instanceof Error?e.message:String(e)),process.exitCode=1});export{};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "useakit",
3
- "version": "0.2.0-dev.15",
3
+ "version": "0.2.0-dev.16",
4
4
  "description": "Install your agent kit skills into Claude Code, Codex, Cursor and Gemini CLI.",
5
5
  "keywords": [
6
6
  "agent-kit",