@caveman-ai/cli 1.2.0 → 1.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/learn-tui.js CHANGED
@@ -1,61 +1,61 @@
1
1
  // Bundled interactive UI. @clack/prompts remains a build-time dependency only.
2
- var te=Object.create;var It=Object.defineProperty;var ee=Object.getOwnPropertyDescriptor;var se=Object.getOwnPropertyNames;var ie=Object.getPrototypeOf,re=Object.prototype.hasOwnProperty;var ne=(t,e)=>()=>{try{return e||t((e={exports:{}}).exports,e),e.exports}catch(s){throw e=0,s}};var oe=(t,e,s,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of se(e))!re.call(t,n)&&n!==s&&It(t,n,{get:()=>e[n],enumerable:!(i=ee(e,n))||i.enumerable});return t};var St=(t,e,s)=>(s=t!=null?te(ie(t)):{},oe(e||!t||!t.__esModule?It(s,"default",{value:t,enumerable:!0}):s,t));var dt=ne((as,kt)=>{"use strict";var pt={to(t,e){return e?`\x1B[${e+1};${t+1}H`:`\x1B[${t+1}G`},move(t,e){let s="";return t<0?s+=`\x1B[${-t}D`:t>0&&(s+=`\x1B[${t}C`),e<0?s+=`\x1B[${-e}A`:e>0&&(s+=`\x1B[${e}B`),s},up:(t=1)=>`\x1B[${t}A`,down:(t=1)=>`\x1B[${t}B`,forward:(t=1)=>`\x1B[${t}C`,backward:(t=1)=>`\x1B[${t}D`,nextLine:(t=1)=>"\x1B[E".repeat(t),prevLine:(t=1)=>"\x1B[F".repeat(t),left:"\x1B[G",hide:"\x1B[?25l",show:"\x1B[?25h",save:"\x1B7",restore:"\x1B8"},we={up:(t=1)=>"\x1B[S".repeat(t),down:(t=1)=>"\x1B[T".repeat(t)},Ie={screen:"\x1B[2J",up:(t=1)=>"\x1B[1J".repeat(t),down:(t=1)=>"\x1B[J".repeat(t),line:"\x1B[2K",lineEnd:"\x1B[K",lineStart:"\x1B[1K",lines(t){let e="";for(let s=0;s<t;s++)e+=this.line+(s<t-1?pt.up():"");return t&&(e+=pt.left),e}};kt.exports={cursor:pt,scroll:we,erase:Ie,beep:"\x07"}});import{styleText as Se}from"node:util";import{stdout as gt,stdin as Dt}from"node:process";import*as G from"node:readline";import be from"node:readline";var bt=(()=>{let t=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g;return e=>{let s=0;for(t.lastIndex=0;t.test(e);)s+=1;return e.length-s}})(),_t=t=>t===12288||t>=65281&&t<=65376||t>=65504&&t<=65510,xt=t=>t===8987||t===9001||t>=12272&&t<=12287||t>=12289&&t<=12350||t>=12441&&t<=12543||t>=12549&&t<=12591||t>=12593&&t<=12686||t>=12688&&t<=12771||t>=12783&&t<=12830||t>=12832&&t<=12871||t>=12880&&t<=19903||t>=65040&&t<=65049||t>=65072&&t<=65106||t>=65108&&t<=65126||t>=65128&&t<=65131||t>=127488&&t<=127490||t>=127504&&t<=127547||t>=127552&&t<=127560||t>=131072&&t<=196605||t>=196608&&t<=262141;var ae=/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]|\u001b\]8;[^;]*;.*?(?:\u0007|\u001b\u005c)/y,ue=/[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y,Et=/(?:(?![\uFF61-\uFF9F\uFF00-\uFFEF])[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\p{Script=Tangut}]){1,1000}/yu,le=/\t{1,1000}/y,Ct=new RegExp("[\\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?))*","yu"),ce=/(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y,he=new RegExp("\\p{M}+","gu"),pe={limit:1/0,ellipsis:""},Tt=(t,e={},s={})=>{let i=e.limit??1/0,n=e.ellipsis??"",u=e?.ellipsisWidth??(n?Tt(n,pe,s).width:0),o=0,r=s.controlWidth??0,l=s.tabWidth??8,d=s.emojiWidth??2,g=2,h=s.regularWidth??1,p=s.wideWidth??g,m=[[ce,h],[ae,o],[ue,r],[le,l],[Ct,d],[Et,p]],c=0,$=0,b=t.length,A=0,R=!1,V=b,F=Math.max(0,i-u),v=0,_=0,I=0,S=0;t:for(;;){if(_>v||$>=b&&$>c){let x=t.slice(v,_)||t.slice(c,$);A=0;for(let P of x.replaceAll(he,"")){let C=P.codePointAt(0)||0;if(_t(C)?S=g:xt(C)?S=p:S=h,I+S>F&&(V=Math.min(V,Math.max(v,c)+A)),I+S>i){R=!0;break t}A+=P.length,I+=S}v=_=0}if($>=b)break t;for(let x=0,P=m.length;x<P;x++){let[C,J]=m[x];if(C.lastIndex=$,C.test(t)){if(A=C===Et?bt(t.slice($,C.lastIndex)):C===Ct?1:C.lastIndex-$,S=A*J,I+S>F&&(V=Math.min(V,$+Math.floor((F-I)/J))),I+S>i){R=!0;break t}I+=S,v=c,_=$,$=c=C.lastIndex;continue t}}$+=1}return{width:R?F:I,index:R?V:b,truncated:R,ellipsed:R&&i>=u}},Mt=Tt;var de={limit:1/0,ellipsis:"",ellipsisWidth:0},me=(t,e={})=>Mt(t,de,e).width,T=me;var z="\x1B",Ot="\x9B",ge=39,ct="\x07",Rt="[",fe="]",Pt="m",ht=`${fe}8;;`,At=new RegExp(`(?:\\${Rt}(?<code>\\d+)m|\\${ht}(?<uri>.*)${ct})`,"y"),Ft=t=>{if(t>=30&&t<=37||t>=90&&t<=97)return 39;if(t>=40&&t<=47||t>=100&&t<=107)return 49;if(t===1||t===2)return 22;if(t===3)return 23;if(t===4)return 24;if(t===7)return 27;if(t===8)return 28;if(t===9)return 29;if(t===0)return 0},Vt=t=>`${z}${Rt}${t}${Pt}`,Lt=t=>`${z}${ht}${t}${ct}`,lt=(t,e,s)=>{let i=e[Symbol.iterator](),n=!1,u=!1,o=t.at(-1),r=o===void 0?0:T(o),l=i.next(),d=i.next(),g=0;for(;!l.done;){let h=l.value,p=T(h);r+p<=s?t[t.length-1]+=h:(t.push(h),r=0),(h===z||h===Ot)&&(n=!0,u=e.startsWith(ht,g+1)),n?u?h===ct&&(n=!1,u=!1):h===Pt&&(n=!1):(r+=p,r===s&&!d.done&&(t.push(""),r=0)),l=d,d=i.next(),g+=h.length}o=t.at(-1),!r&&o!==void 0&&o.length&&t.length>1&&(t[t.length-2]+=t.pop())},$e=t=>{let e=t.split(" "),s=e.length;for(;s&&!T(e[s-1]);)s--;return s===e.length?t:e.slice(0,s).join(" ")+e.slice(s).join("")},ve=(t,e,s={})=>{if(s.trim!==!1&&t.trim()==="")return"";let i="",n,u,o=t.split(" "),r=[""],l=0;for(let h=0;h<o.length;h++){let p=o[h];if(s.trim!==!1){let c=r.at(-1)??"",$=c.trimStart();c.length!==$.length&&(r[r.length-1]=$,l=T($))}h!==0&&(l>=e&&(s.wordWrap===!1||s.trim===!1)&&(r.push(""),l=0),(l||s.trim===!1)&&(r[r.length-1]+=" ",l++));let m=T(p);if(s.hard&&m>e){let c=e-l,$=1+Math.floor((m-c-1)/e);Math.floor((m-1)/e)<$&&r.push(""),lt(r,p,e),l=T(r.at(-1)??"");continue}if(l+m>e&&l&&m){if(s.wordWrap===!1&&l<e){lt(r,p,e),l=T(r.at(-1)??"");continue}r.push(""),l=0}if(l+m>e&&s.wordWrap===!1){lt(r,p,e),l=T(r.at(-1)??"");continue}r[r.length-1]+=p,l+=m}s.trim!==!1&&(r=r.map(h=>$e(h)));let d=r.join(`
3
- `),g=!1;for(let h=0;h<d.length;h++){let p=d[h];if(i+=p,g)g=!1;else if(g=p>="\uD800"&&p<="\uDBFF",g)continue;if(p===z||p===Ot){At.lastIndex=h+1;let c=At.exec(d)?.groups;if(c?.code!==void 0){let $=Number.parseFloat(c.code);n=$===ge?void 0:$}else c?.uri!==void 0&&(u=c.uri.length===0?void 0:c.uri)}if(d[h+1]===`
4
- `){u&&(i+=Lt(""));let m=n?Ft(n):void 0;n&&m&&(i+=Vt(m))}else p===`
5
- `&&(n&&Ft(n)&&(i+=Vt(n)),u&&(i+=Lt(u)))}return i},ye=/\r?\n/;function k(t,e,s){return String(t).normalize().split(ye).map(i=>ve(i,e,s)).join(`
6
- `)}var M=St(dt(),1);import{ReadStream as Nt}from"node:tty";function Q(t,e,s){if(!s.some(o=>!o.disabled))return t;let i=t+e,n=Math.max(s.length-1,0),u=i<0?n:i>n?0:i;return s[u]?.disabled?Q(u,e<0?-1:1,s):u}var _e=["up","down","left","right","space","enter","cancel"],xe=["January","February","March","April","May","June","July","August","September","October","November","December"],E={actions:new Set(_e),aliases:new Map([["k","up"],["j","down"],["h","left"],["l","right"],["","cancel"],["escape","cancel"]]),messages:{cancel:"Canceled",error:"Something went wrong"},withGuide:!0,date:{monthNames:[...xe],messages:{required:"Please enter a valid date",invalidMonth:"There are only 12 months in a year",invalidDay:(t,e)=>`There are only ${t} days in ${e}`,afterMin:t=>`Date must be on or after ${t.toISOString().slice(0,10)}`,beforeMax:t=>`Date must be on or before ${t.toISOString().slice(0,10)}`}}};function ft(t,e){if(typeof t=="string")return E.aliases.get(t)===e;for(let s of t)if(s!==void 0&&ft(s,e))return!0;return!1}function Ee(t,e){if(t===e)return;let s=t.split(`
2
+ var ee=Object.create;var It=Object.defineProperty;var se=Object.getOwnPropertyDescriptor;var ie=Object.getOwnPropertyNames;var re=Object.getPrototypeOf,ne=Object.prototype.hasOwnProperty;var oe=(t,e)=>()=>{try{return e||t((e={exports:{}}).exports,e),e.exports}catch(s){throw e=0,s}};var ae=(t,e,s,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of ie(e))!ne.call(t,o)&&o!==s&&It(t,o,{get:()=>e[o],enumerable:!(i=se(e,o))||i.enumerable});return t};var St=(t,e,s)=>(s=t!=null?ee(re(t)):{},ae(e||!t||!t.__esModule?It(s,"default",{value:t,enumerable:!0}):s,t));var dt=oe((us,kt)=>{"use strict";var pt={to(t,e){return e?`\x1B[${e+1};${t+1}H`:`\x1B[${t+1}G`},move(t,e){let s="";return t<0?s+=`\x1B[${-t}D`:t>0&&(s+=`\x1B[${t}C`),e<0?s+=`\x1B[${-e}A`:e>0&&(s+=`\x1B[${e}B`),s},up:(t=1)=>`\x1B[${t}A`,down:(t=1)=>`\x1B[${t}B`,forward:(t=1)=>`\x1B[${t}C`,backward:(t=1)=>`\x1B[${t}D`,nextLine:(t=1)=>"\x1B[E".repeat(t),prevLine:(t=1)=>"\x1B[F".repeat(t),left:"\x1B[G",hide:"\x1B[?25l",show:"\x1B[?25h",save:"\x1B7",restore:"\x1B8"},Ie={up:(t=1)=>"\x1B[S".repeat(t),down:(t=1)=>"\x1B[T".repeat(t)},Se={screen:"\x1B[2J",up:(t=1)=>"\x1B[1J".repeat(t),down:(t=1)=>"\x1B[J".repeat(t),line:"\x1B[2K",lineEnd:"\x1B[K",lineStart:"\x1B[1K",lines(t){let e="";for(let s=0;s<t;s++)e+=this.line+(s<t-1?pt.up():"");return t&&(e+=pt.left),e}};kt.exports={cursor:pt,scroll:Ie,erase:Se,beep:"\x07"}});import{styleText as be}from"node:util";import{stdout as gt,stdin as Dt}from"node:process";import*as G from"node:readline";import _e from"node:readline";var bt=(()=>{let t=/[\uD800-\uDBFF][\uDC00-\uDFFF]/g;return e=>{let s=0;for(t.lastIndex=0;t.test(e);)s+=1;return e.length-s}})(),_t=t=>t===12288||t>=65281&&t<=65376||t>=65504&&t<=65510,xt=t=>t===8987||t===9001||t>=12272&&t<=12287||t>=12289&&t<=12350||t>=12441&&t<=12543||t>=12549&&t<=12591||t>=12593&&t<=12686||t>=12688&&t<=12771||t>=12783&&t<=12830||t>=12832&&t<=12871||t>=12880&&t<=19903||t>=65040&&t<=65049||t>=65072&&t<=65106||t>=65108&&t<=65126||t>=65128&&t<=65131||t>=127488&&t<=127490||t>=127504&&t<=127547||t>=127552&&t<=127560||t>=131072&&t<=196605||t>=196608&&t<=262141;var ue=/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]|\u001b\]8;[^;]*;.*?(?:\u0007|\u001b\u005c)/y,le=/[\x00-\x08\x0A-\x1F\x7F-\x9F]{1,1000}/y,Et=/(?:(?![\uFF61-\uFF9F\uFF00-\uFFEF])[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\p{Script=Tangut}]){1,1000}/yu,ce=/\t{1,1000}/y,Ct=new RegExp("[\\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?))*","yu"),he=/(?:[\x20-\x7E\xA0-\xFF](?!\uFE0F)){1,1000}/y,pe=new RegExp("\\p{M}+","gu"),de={limit:1/0,ellipsis:""},Tt=(t,e={},s={})=>{let i=e.limit??1/0,o=e.ellipsis??"",u=e?.ellipsisWidth??(o?Tt(o,de,s).width:0),n=0,r=s.controlWidth??0,l=s.tabWidth??8,d=s.emojiWidth??2,g=2,h=s.regularWidth??1,p=s.wideWidth??g,m=[[he,h],[ue,n],[le,r],[ce,l],[Ct,d],[Et,p]],c=0,$=0,b=t.length,A=0,R=!1,L=b,F=Math.max(0,i-u),v=0,_=0,I=0,S=0;t:for(;;){if(_>v||$>=b&&$>c){let x=t.slice(v,_)||t.slice(c,$);A=0;for(let P of x.replaceAll(pe,"")){let C=P.codePointAt(0)||0;if(_t(C)?S=g:xt(C)?S=p:S=h,I+S>F&&(L=Math.min(L,Math.max(v,c)+A)),I+S>i){R=!0;break t}A+=P.length,I+=S}v=_=0}if($>=b)break t;for(let x=0,P=m.length;x<P;x++){let[C,Y]=m[x];if(C.lastIndex=$,C.test(t)){if(A=C===Et?bt(t.slice($,C.lastIndex)):C===Ct?1:C.lastIndex-$,S=A*Y,I+S>F&&(L=Math.min(L,$+Math.floor((F-I)/Y))),I+S>i){R=!0;break t}I+=S,v=c,_=$,$=c=C.lastIndex;continue t}}$+=1}return{width:R?F:I,index:R?L:b,truncated:R,ellipsed:R&&i>=u}},Mt=Tt;var me={limit:1/0,ellipsis:"",ellipsisWidth:0},ge=(t,e={})=>Mt(t,me,e).width,T=ge;var X="\x1B",Ot="\x9B",fe=39,ct="\x07",Rt="[",$e="]",Pt="m",ht=`${$e}8;;`,At=new RegExp(`(?:\\${Rt}(?<code>\\d+)m|\\${ht}(?<uri>.*)${ct})`,"y"),Ft=t=>{if(t>=30&&t<=37||t>=90&&t<=97)return 39;if(t>=40&&t<=47||t>=100&&t<=107)return 49;if(t===1||t===2)return 22;if(t===3)return 23;if(t===4)return 24;if(t===7)return 27;if(t===8)return 28;if(t===9)return 29;if(t===0)return 0},Lt=t=>`${X}${Rt}${t}${Pt}`,Vt=t=>`${X}${ht}${t}${ct}`,lt=(t,e,s)=>{let i=e[Symbol.iterator](),o=!1,u=!1,n=t.at(-1),r=n===void 0?0:T(n),l=i.next(),d=i.next(),g=0;for(;!l.done;){let h=l.value,p=T(h);r+p<=s?t[t.length-1]+=h:(t.push(h),r=0),(h===X||h===Ot)&&(o=!0,u=e.startsWith(ht,g+1)),o?u?h===ct&&(o=!1,u=!1):h===Pt&&(o=!1):(r+=p,r===s&&!d.done&&(t.push(""),r=0)),l=d,d=i.next(),g+=h.length}n=t.at(-1),!r&&n!==void 0&&n.length&&t.length>1&&(t[t.length-2]+=t.pop())},ve=t=>{let e=t.split(" "),s=e.length;for(;s&&!T(e[s-1]);)s--;return s===e.length?t:e.slice(0,s).join(" ")+e.slice(s).join("")},ye=(t,e,s={})=>{if(s.trim!==!1&&t.trim()==="")return"";let i="",o,u,n=t.split(" "),r=[""],l=0;for(let h=0;h<n.length;h++){let p=n[h];if(s.trim!==!1){let c=r.at(-1)??"",$=c.trimStart();c.length!==$.length&&(r[r.length-1]=$,l=T($))}h!==0&&(l>=e&&(s.wordWrap===!1||s.trim===!1)&&(r.push(""),l=0),(l||s.trim===!1)&&(r[r.length-1]+=" ",l++));let m=T(p);if(s.hard&&m>e){let c=e-l,$=1+Math.floor((m-c-1)/e);Math.floor((m-1)/e)<$&&r.push(""),lt(r,p,e),l=T(r.at(-1)??"");continue}if(l+m>e&&l&&m){if(s.wordWrap===!1&&l<e){lt(r,p,e),l=T(r.at(-1)??"");continue}r.push(""),l=0}if(l+m>e&&s.wordWrap===!1){lt(r,p,e),l=T(r.at(-1)??"");continue}r[r.length-1]+=p,l+=m}s.trim!==!1&&(r=r.map(h=>ve(h)));let d=r.join(`
3
+ `),g=!1;for(let h=0;h<d.length;h++){let p=d[h];if(i+=p,g)g=!1;else if(g=p>="\uD800"&&p<="\uDBFF",g)continue;if(p===X||p===Ot){At.lastIndex=h+1;let c=At.exec(d)?.groups;if(c?.code!==void 0){let $=Number.parseFloat(c.code);o=$===fe?void 0:$}else c?.uri!==void 0&&(u=c.uri.length===0?void 0:c.uri)}if(d[h+1]===`
4
+ `){u&&(i+=Vt(""));let m=o?Ft(o):void 0;o&&m&&(i+=Lt(m))}else p===`
5
+ `&&(o&&Ft(o)&&(i+=Lt(o)),u&&(i+=Vt(u)))}return i},we=/\r?\n/;function k(t,e,s){return String(t).normalize().split(we).map(i=>ye(i,e,s)).join(`
6
+ `)}var M=St(dt(),1);import{ReadStream as Nt}from"node:tty";function Z(t,e,s){if(!s.some(n=>!n.disabled))return t;let i=t+e,o=Math.max(s.length-1,0),u=i<0?o:i>o?0:i;return s[u]?.disabled?Z(u,e<0?-1:1,s):u}var xe=["up","down","left","right","space","enter","cancel"],Ee=["January","February","March","April","May","June","July","August","September","October","November","December"],E={actions:new Set(xe),aliases:new Map([["k","up"],["j","down"],["h","left"],["l","right"],["","cancel"],["escape","cancel"]]),messages:{cancel:"Canceled",error:"Something went wrong"},withGuide:!0,date:{monthNames:[...Ee],messages:{required:"Please enter a valid date",invalidMonth:"There are only 12 months in a year",invalidDay:(t,e)=>`There are only ${t} days in ${e}`,afterMin:t=>`Date must be on or after ${t.toISOString().slice(0,10)}`,beforeMax:t=>`Date must be on or before ${t.toISOString().slice(0,10)}`}}};function ft(t,e){if(typeof t=="string")return E.aliases.get(t)===e;for(let s of t)if(s!==void 0&&ft(s,e))return!0;return!1}function Ce(t,e){if(t===e)return;let s=t.split(`
7
7
  `),i=e.split(`
8
- `),n=Math.max(s.length,i.length),u=[];for(let o=0;o<n;o++)s[o]!==i[o]&&u.push(o);return{lines:u,numLinesBefore:s.length,numLinesAfter:i.length,numLines:n}}var Ce=globalThis.process.platform.startsWith("win"),mt=Symbol("clack:cancel");function W(t){return t===mt}function X(t,e){let s=t;s.isTTY&&s.setRawMode(e)}function Gt({input:t=Dt,output:e=gt,overwrite:s=!0,hideCursor:i=!0}={}){let n=G.createInterface({input:t,output:e,prompt:"",tabSize:1});G.emitKeypressEvents(t,n),t instanceof Nt&&t.isTTY&&t.setRawMode(!0);let u=(o,{name:r,sequence:l})=>{let d=String(o);if(ft([d,r,l],"cancel")){i&&e.write(M.cursor.show),process.exit(0);return}if(!s)return;G.moveCursor(e,r==="return"?0:-1,r==="return"?-1:0,()=>{G.clearLine(e,1,()=>{t.once("keypress",u)})})};return i&&e.write(M.cursor.hide),t.once("keypress",u),()=>{t.off("keypress",u),i&&e.write(M.cursor.show),t instanceof Nt&&t.isTTY&&!Ce&&t.setRawMode(!1),n.terminal=!1,n.close()}}var K=t=>"columns"in t&&typeof t.columns=="number"?t.columns:80,$t=t=>"rows"in t&&typeof t.rows=="number"?t.rows:20;function et(t,e,s,i=s,n=s,u){let o=K(t??gt);return k(e,o-s.length,{hard:!0,trim:!1}).split(`
9
- `).map((r,l,d)=>{let g=u?u(r,l):r;return l===0?`${i}${g}`:l===d.length-1?`${n}${g}`:`${s}${g}`}).join(`
10
- `)}function jt(t,e){if("~standard"in t){let s=t["~standard"].validate(e);if(s instanceof Promise)throw new TypeError("Schema validation must be synchronous. Update `validate()` and remove any asynchronous logic.");return s.issues?.at(0)?.message}return t(e)}var Z=class{input;output;_abortSignal;rl;opts;_render;_track=!1;_prevFrame="";_subscribers=new Map;_cursor=0;state="initial";error="";value;userInput="";constructor(e,s=!0){let{input:i=Dt,output:n=gt,render:u,signal:o,...r}=e;this.opts=r,this.onKeypress=this.onKeypress.bind(this),this.close=this.close.bind(this),this.render=this.render.bind(this),this._render=u.bind(this),this._track=s,this._abortSignal=o,this.input=i,this.output=n}unsubscribe(){this._subscribers.clear()}setSubscriber(e,s){let i=this._subscribers.get(e)??[];i.push(s),this._subscribers.set(e,i)}on(e,s){this.setSubscriber(e,{cb:s})}once(e,s){this.setSubscriber(e,{cb:s,once:!0})}emit(e,...s){let i=this._subscribers.get(e)??[],n=[];for(let u of i)u.cb(...s),u.once&&n.push(()=>i.splice(i.indexOf(u),1));for(let u of n)u()}prompt(){return new Promise(e=>{if(this._abortSignal){if(this._abortSignal.aborted)return this.state="cancel",this.close(),e(mt);this._abortSignal.addEventListener("abort",()=>{this.state="cancel",this.close()},{once:!0})}this.rl=be.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),X(this.input,!0),this.output.on("resize",this.render),this.render(),this.once("submit",()=>{this.output.write(M.cursor.show),this.output.off("resize",this.render),X(this.input,!1),e(this.value)}),this.once("cancel",()=>{this.output.write(M.cursor.show),this.output.off("resize",this.render),X(this.input,!1),e(mt)})})}_isActionKey(e,s){return e===" "}_shouldSubmit(e,s){return!0}_setValue(e){this.value=e,this.emit("value",this.value)}_setUserInput(e,s){this.userInput=e??"",this.emit("userInput",this.userInput),s&&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("")}onKeypress(e,s){if(this._track&&s.name!=="return"&&(s.name&&this._isActionKey(e,s)&&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"),s?.name&&(!this._track&&E.aliases.has(s.name)&&this.emit("cursor",E.aliases.get(s.name)),E.actions.has(s.name)&&this.emit("cursor",s.name)),e&&(e.toLowerCase()==="y"||e.toLowerCase()==="n")&&this.emit("confirm",e.toLowerCase()==="y"),this.emit("key",e,s),s?.name==="return"&&this._shouldSubmit(e,s)){if(this.opts.validate){let i=jt(this.opts.validate,this.value);i&&(this.error=i instanceof Error?i.message:i,this.state="error",this.rl?.write(this.userInput))}this.state!=="error"&&(this.state="submit")}ft([e,s?.name,s?.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
- `),X(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(M.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(M.cursor.hide);else{let s=Ee(this._prevFrame,e),i=$t(this.output);if(this.restoreCursor(),s){let n=Math.max(0,s.numLinesAfter-i),u=Math.max(0,s.numLinesBefore-i),o=s.lines.find(r=>r>=n);if(o===void 0){this._prevFrame=e;return}if(s.lines.length===1){this.output.write(M.cursor.move(0,o-u)),this.output.write(M.erase.lines(1));let r=e.split(`
13
- `);this.output.write(r[o]),this._prevFrame=e,this.output.write(M.cursor.move(0,r.length-o-1));return}else if(s.lines.length>1){if(n<u)o=n;else{let l=o-u;l>0&&this.output.write(M.cursor.move(0,l))}this.output.write(M.erase.down());let r=e.split(`
14
- `).slice(o);this.output.write(r.join(`
15
- `)),this._prevFrame=e;return}}this.output.write(M.erase.down())}this.output.write(e),this.state==="initial"&&(this.state="active"),this._prevFrame=e}}};var Wt=class extends Z{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 s=this.options.findIndex(({value:n})=>n===e.initialValue),i=s===-1?0:s;this.cursor=this.options[i]?.disabled?Q(i,1,this.options):i,this.changeValue(),this.on("cursor",n=>{switch(n){case"left":case"up":this.cursor=Q(this.cursor,-1,this.options);break;case"down":case"right":this.cursor=Q(this.cursor,1,this.options);break}this.changeValue()})}};var tt=class extends Z{get userInputWithCursor(){if(this.state==="submit")return this.userInput;let e=this.userInput;if(this.cursor>=e.length)return`${this.userInput}\u2588`;let s=e.slice(0,this.cursor),i=e.slice(this.cursor,this.cursor+1),n=e.slice(this.cursor+1);return`${s}${Se("inverse",i)}${n}`}get cursor(){return this._cursor}constructor(e){super({...e,initialUserInput:e.initialUserInput??e.initialValue}),this.on("userInput",s=>{this._setValue(s)}),this.on("finalize",()=>{this.value||(this.value=e.defaultValue),this.value===void 0&&(this.value="")})}};import{styleText as a,stripVTControlCharacters as Es}from"node:util";import O from"node:process";var H=St(dt(),1);function Te(){return O.platform!=="win32"?O.env.TERM!=="linux":!!O.env.CI||!!O.env.WT_SESSION||!!O.env.TERMINUS_SUBLIME||O.env.ConEmuTask==="{cmd::Cmder}"||O.env.TERM_PROGRAM==="Terminus-Sublime"||O.env.TERM_PROGRAM==="vscode"||O.env.TERM==="xterm-256color"||O.env.TERM==="alacritty"||O.env.TERMINAL_EMULATOR==="JetBrains-JediTerm"}var vt=Te(),Me=()=>process.env.CI==="true";var f=(t,e)=>vt?t:e,Ae=f("\u25C6","*"),Ht=f("\u25A0","x"),qt=f("\u25B2","x"),it=f("\u25C7","o"),Fe=f("\u250C","T"),y=f("\u2502","|"),U=f("\u2514","\u2014"),As=f("\u2510","T"),Fs=f("\u2518","\u2014"),Ve=f("\u25CF",">"),Ut=f("\u25CB"," "),Vs=f("\u25FB","[\u2022]"),Ls=f("\u25FC","[+]"),Os=f("\u25FB","[ ]"),Rs=f("\u25AA","\u2022"),Bt=f("\u2500","-"),Le=f("\u256E","+"),Oe=f("\u251C","+"),Re=f("\u256F","+"),Pe=f("\u2570","+"),Ps=f("\u256D","+"),ke=f("\u25CF","\u2022"),Ne=f("\u25C6","*"),De=f("\u25B2","!"),Ge=f("\u25A0","x"),Jt=t=>{switch(t){case"initial":case"active":return a("cyan",Ae);case"cancel":return a("red",Ht);case"error":return a("yellow",qt);case"submit":return a("green",it)}},je=t=>{switch(t){case"initial":case"active":return a("cyan",y);case"cancel":return a("red",y);case"error":return a("yellow",y);case"submit":return a("green",y)}};function We(t,e){let s=[`${e?`${a("cyan",y)} `:""}${t.join(" \u2022 ")}`];return e&&s.push(a("cyan",U)),s}var Kt=(t,e,s,i,n,u=!1)=>{let o=e,r=0;if(u)for(let l=i-1;l>=s;l--){let d=t[l];if(d&&(o-=d.length),r++,o<=n)break}else for(let l=s;l<i;l++){let d=t[l];if(d&&(o-=d.length),r++,o<=n)break}return{lineCount:o,removals:r}},Ue=({cursor:t,options:e,style:s,output:i=process.stdout,maxItems:n=Number.POSITIVE_INFINITY,columnPadding:u=0,rowPadding:o=4})=>{let r=K(i)-u,l=$t(i),d=a("dim","..."),g=Math.max(l-o,0),h=Math.max(Math.min(n,g),5),p=0;t>=h-3&&(p=Math.max(Math.min(t-h+3,e.length-h),0));let m=h<e.length&&p>0,c=h<e.length&&p+h<e.length,$=Math.min(p+h,e.length),b=[],A=0;m&&A++,c&&A++;let R=p+(m?1:0),V=$-(c?1:0);for(let v=R;v<V;v++){let _=e[v],I=_?s(_,v===t):"",S=k(I,r,{hard:!0,trim:!1}).split(`
16
- `);b.push(S),A+=S.length}if(A>g){let v=0,_=0,I=A,S=t-R,x=g,P=()=>Kt(b,I,0,S,x),C=()=>Kt(b,I,S+1,b.length,x,!0);m?({lineCount:I,removals:v}=P(),I>x&&(c||(x-=1),{lineCount:I,removals:_}=C())):(c||(x-=1),{lineCount:I,removals:_}=C(),I>x&&(x-=1,{lineCount:I,removals:v}=P())),v>0&&(m=!0,b.splice(0,v)),_>0&&(c=!0,b.splice(b.length-_,_))}let F=[];m&&F.push(d);for(let v of b)for(let _ of v)F.push(_);return c&&F.push(d),F};var ks=[`${a("dim","\u2191/\u2193")} to navigate`,`${a("dim","Space:")} select`,`${a("dim","Enter:")} confirm`];var j={message:(t=[],{symbol:e=a("gray",y),secondarySymbol:s=a("gray",y),output:i=process.stdout,spacing:n=1,withGuide:u}={})=>{let o=[],r=u??E.withGuide,l=r?s:"",d=r?`${e} `:"",g=r?`${s} `:"";for(let p=0;p<n;p++)o.push(l);let h=Array.isArray(t)?t:t.split(`
17
- `);if(h.length>0){let[p,...m]=h;p.length>0?o.push(`${d}${p}`):o.push(r?e:"");for(let c of m)c.length>0?o.push(`${g}${c}`):o.push(r?s:"")}i.write(`${o.join(`
8
+ `),o=Math.max(s.length,i.length),u=[];for(let n=0;n<o;n++)s[n]!==i[n]&&u.push(n);return{lines:u,numLinesBefore:s.length,numLinesAfter:i.length,numLines:o}}var Te=globalThis.process.platform.startsWith("win"),mt=Symbol("clack:cancel");function W(t){return t===mt}function Q(t,e){let s=t;s.isTTY&&s.setRawMode(e)}function Gt({input:t=Dt,output:e=gt,overwrite:s=!0,hideCursor:i=!0}={}){let o=G.createInterface({input:t,output:e,prompt:"",tabSize:1});G.emitKeypressEvents(t,o),t instanceof Nt&&t.isTTY&&t.setRawMode(!0);let u=(n,{name:r,sequence:l})=>{let d=String(n);if(ft([d,r,l],"cancel")){i&&e.write(M.cursor.show),process.exit(0);return}if(!s)return;G.moveCursor(e,r==="return"?0:-1,r==="return"?-1:0,()=>{G.clearLine(e,1,()=>{t.once("keypress",u)})})};return i&&e.write(M.cursor.hide),t.once("keypress",u),()=>{t.off("keypress",u),i&&e.write(M.cursor.show),t instanceof Nt&&t.isTTY&&!Te&&t.setRawMode(!1),o.terminal=!1,o.close()}}var K=t=>"columns"in t&&typeof t.columns=="number"?t.columns:80,$t=t=>"rows"in t&&typeof t.rows=="number"?t.rows:20;function st(t,e,s,i=s,o=s,u){let n=K(t??gt);return k(e,n-s.length,{hard:!0,trim:!1}).split(`
9
+ `).map((r,l,d)=>{let g=u?u(r,l):r;return l===0?`${i}${g}`:l===d.length-1?`${o}${g}`:`${s}${g}`}).join(`
10
+ `)}function jt(t,e){if("~standard"in t){let s=t["~standard"].validate(e);if(s instanceof Promise)throw new TypeError("Schema validation must be synchronous. Update `validate()` and remove any asynchronous logic.");return s.issues?.at(0)?.message}return t(e)}var tt=class{input;output;_abortSignal;rl;opts;_render;_track=!1;_prevFrame="";_subscribers=new Map;_cursor=0;state="initial";error="";value;userInput="";constructor(e,s=!0){let{input:i=Dt,output:o=gt,render:u,signal:n,...r}=e;this.opts=r,this.onKeypress=this.onKeypress.bind(this),this.close=this.close.bind(this),this.render=this.render.bind(this),this._render=u.bind(this),this._track=s,this._abortSignal=n,this.input=i,this.output=o}unsubscribe(){this._subscribers.clear()}setSubscriber(e,s){let i=this._subscribers.get(e)??[];i.push(s),this._subscribers.set(e,i)}on(e,s){this.setSubscriber(e,{cb:s})}once(e,s){this.setSubscriber(e,{cb:s,once:!0})}emit(e,...s){let i=this._subscribers.get(e)??[],o=[];for(let u of i)u.cb(...s),u.once&&o.push(()=>i.splice(i.indexOf(u),1));for(let u of o)u()}prompt(){return new Promise(e=>{if(this._abortSignal){if(this._abortSignal.aborted)return this.state="cancel",this.close(),e(mt);this._abortSignal.addEventListener("abort",()=>{this.state="cancel",this.close()},{once:!0})}this.rl=_e.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),Q(this.input,!0),this.output.on("resize",this.render),this.render(),this.once("submit",()=>{this.output.write(M.cursor.show),this.output.off("resize",this.render),Q(this.input,!1),e(this.value)}),this.once("cancel",()=>{this.output.write(M.cursor.show),this.output.off("resize",this.render),Q(this.input,!1),e(mt)})})}_isActionKey(e,s){return e===" "}_shouldSubmit(e,s){return!0}_setValue(e){this.value=e,this.emit("value",this.value)}_setUserInput(e,s){this.userInput=e??"",this.emit("userInput",this.userInput),s&&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("")}onKeypress(e,s){if(this._track&&s.name!=="return"&&(s.name&&this._isActionKey(e,s)&&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"),s?.name&&(!this._track&&E.aliases.has(s.name)&&this.emit("cursor",E.aliases.get(s.name)),E.actions.has(s.name)&&this.emit("cursor",s.name)),e&&(e.toLowerCase()==="y"||e.toLowerCase()==="n")&&this.emit("confirm",e.toLowerCase()==="y"),this.emit("key",e,s),s?.name==="return"&&this._shouldSubmit(e,s)){if(this.opts.validate){let i=jt(this.opts.validate,this.value);i&&(this.error=i instanceof Error?i.message:i,this.state="error",this.rl?.write(this.userInput))}this.state!=="error"&&(this.state="submit")}ft([e,s?.name,s?.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
+ `),Q(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(M.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(M.cursor.hide);else{let s=Ce(this._prevFrame,e),i=$t(this.output);if(this.restoreCursor(),s){let o=Math.max(0,s.numLinesAfter-i),u=Math.max(0,s.numLinesBefore-i),n=s.lines.find(r=>r>=o);if(n===void 0){this._prevFrame=e;return}if(s.lines.length===1){this.output.write(M.cursor.move(0,n-u)),this.output.write(M.erase.lines(1));let r=e.split(`
13
+ `);this.output.write(r[n]),this._prevFrame=e,this.output.write(M.cursor.move(0,r.length-n-1));return}else if(s.lines.length>1){if(o<u)n=o;else{let l=n-u;l>0&&this.output.write(M.cursor.move(0,l))}this.output.write(M.erase.down());let r=e.split(`
14
+ `).slice(n);this.output.write(r.join(`
15
+ `)),this._prevFrame=e;return}}this.output.write(M.erase.down())}this.output.write(e),this.state==="initial"&&(this.state="active"),this._prevFrame=e}}};var Wt=class extends tt{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 s=this.options.findIndex(({value:o})=>o===e.initialValue),i=s===-1?0:s;this.cursor=this.options[i]?.disabled?Z(i,1,this.options):i,this.changeValue(),this.on("cursor",o=>{switch(o){case"left":case"up":this.cursor=Z(this.cursor,-1,this.options);break;case"down":case"right":this.cursor=Z(this.cursor,1,this.options);break}this.changeValue()})}};var et=class extends tt{get userInputWithCursor(){if(this.state==="submit")return this.userInput;let e=this.userInput;if(this.cursor>=e.length)return`${this.userInput}\u2588`;let s=e.slice(0,this.cursor),i=e.slice(this.cursor,this.cursor+1),o=e.slice(this.cursor+1);return`${s}${be("inverse",i)}${o}`}get cursor(){return this._cursor}constructor(e){super({...e,initialUserInput:e.initialUserInput??e.initialValue}),this.on("userInput",s=>{this._setValue(s)}),this.on("finalize",()=>{this.value||(this.value=e.defaultValue),this.value===void 0&&(this.value="")})}};import{styleText as a,stripVTControlCharacters as Cs}from"node:util";import O from"node:process";var H=St(dt(),1);function Me(){return O.platform!=="win32"?O.env.TERM!=="linux":!!O.env.CI||!!O.env.WT_SESSION||!!O.env.TERMINUS_SUBLIME||O.env.ConEmuTask==="{cmd::Cmder}"||O.env.TERM_PROGRAM==="Terminus-Sublime"||O.env.TERM_PROGRAM==="vscode"||O.env.TERM==="xterm-256color"||O.env.TERM==="alacritty"||O.env.TERMINAL_EMULATOR==="JetBrains-JediTerm"}var vt=Me(),Ae=()=>process.env.CI==="true";var f=(t,e)=>vt?t:e,Fe=f("\u25C6","*"),Ht=f("\u25A0","x"),qt=f("\u25B2","x"),rt=f("\u25C7","o"),Le=f("\u250C","T"),y=f("\u2502","|"),U=f("\u2514","\u2014"),Fs=f("\u2510","T"),Ls=f("\u2518","\u2014"),Ve=f("\u25CF",">"),Ut=f("\u25CB"," "),Vs=f("\u25FB","[\u2022]"),Os=f("\u25FC","[+]"),Rs=f("\u25FB","[ ]"),Ps=f("\u25AA","\u2022"),Bt=f("\u2500","-"),Oe=f("\u256E","+"),Re=f("\u251C","+"),Pe=f("\u256F","+"),ke=f("\u2570","+"),ks=f("\u256D","+"),Ne=f("\u25CF","\u2022"),De=f("\u25C6","*"),Ge=f("\u25B2","!"),je=f("\u25A0","x"),Jt=t=>{switch(t){case"initial":case"active":return a("cyan",Fe);case"cancel":return a("red",Ht);case"error":return a("yellow",qt);case"submit":return a("green",rt)}},We=t=>{switch(t){case"initial":case"active":return a("cyan",y);case"cancel":return a("red",y);case"error":return a("yellow",y);case"submit":return a("green",y)}};function Ue(t,e){let s=[`${e?`${a("cyan",y)} `:""}${t.join(" \u2022 ")}`];return e&&s.push(a("cyan",U)),s}var Kt=(t,e,s,i,o,u=!1)=>{let n=e,r=0;if(u)for(let l=i-1;l>=s;l--){let d=t[l];if(d&&(n-=d.length),r++,n<=o)break}else for(let l=s;l<i;l++){let d=t[l];if(d&&(n-=d.length),r++,n<=o)break}return{lineCount:n,removals:r}},Be=({cursor:t,options:e,style:s,output:i=process.stdout,maxItems:o=Number.POSITIVE_INFINITY,columnPadding:u=0,rowPadding:n=4})=>{let r=K(i)-u,l=$t(i),d=a("dim","..."),g=Math.max(l-n,0),h=Math.max(Math.min(o,g),5),p=0;t>=h-3&&(p=Math.max(Math.min(t-h+3,e.length-h),0));let m=h<e.length&&p>0,c=h<e.length&&p+h<e.length,$=Math.min(p+h,e.length),b=[],A=0;m&&A++,c&&A++;let R=p+(m?1:0),L=$-(c?1:0);for(let v=R;v<L;v++){let _=e[v],I=_?s(_,v===t):"",S=k(I,r,{hard:!0,trim:!1}).split(`
16
+ `);b.push(S),A+=S.length}if(A>g){let v=0,_=0,I=A,S=t-R,x=g,P=()=>Kt(b,I,0,S,x),C=()=>Kt(b,I,S+1,b.length,x,!0);m?({lineCount:I,removals:v}=P(),I>x&&(c||(x-=1),{lineCount:I,removals:_}=C())):(c||(x-=1),{lineCount:I,removals:_}=C(),I>x&&(x-=1,{lineCount:I,removals:v}=P())),v>0&&(m=!0,b.splice(0,v)),_>0&&(c=!0,b.splice(b.length-_,_))}let F=[];m&&F.push(d);for(let v of b)for(let _ of v)F.push(_);return c&&F.push(d),F};var Ns=[`${a("dim","\u2191/\u2193")} to navigate`,`${a("dim","Space:")} select`,`${a("dim","Enter:")} confirm`];var j={message:(t=[],{symbol:e=a("gray",y),secondarySymbol:s=a("gray",y),output:i=process.stdout,spacing:o=1,withGuide:u}={})=>{let n=[],r=u??E.withGuide,l=r?s:"",d=r?`${e} `:"",g=r?`${s} `:"";for(let p=0;p<o;p++)n.push(l);let h=Array.isArray(t)?t:t.split(`
17
+ `);if(h.length>0){let[p,...m]=h;p.length>0?n.push(`${d}${p}`):n.push(r?e:"");for(let c of m)c.length>0?n.push(`${g}${c}`):n.push(r?s:"")}i.write(`${n.join(`
18
18
  `)}
19
- `)},info:(t,e)=>{j.message(t,{...e,symbol:a("blue",ke)})},success:(t,e)=>{j.message(t,{...e,symbol:a("green",Ne)})},step:(t,e)=>{j.message(t,{...e,symbol:a("green",it)})},warn:(t,e)=>{j.message(t,{...e,symbol:a("yellow",De)})},warning:(t,e)=>{j.warn(t,e)},error:(t,e)=>{j.message(t,{...e,symbol:a("red",Ge)})}},rt=(t="",e)=>{let s=e?.output??process.stdout,i=e?.withGuide??E.withGuide?`${a("gray",U)} `:"";s.write(`${i}${a("red",t)}
19
+ `)},info:(t,e)=>{j.message(t,{...e,symbol:a("blue",Ne)})},success:(t,e)=>{j.message(t,{...e,symbol:a("green",De)})},step:(t,e)=>{j.message(t,{...e,symbol:a("green",rt)})},warn:(t,e)=>{j.message(t,{...e,symbol:a("yellow",Ge)})},warning:(t,e)=>{j.warn(t,e)},error:(t,e)=>{j.message(t,{...e,symbol:a("red",je)})}},nt=(t="",e)=>{let s=e?.output??process.stdout,i=e?.withGuide??E.withGuide?`${a("gray",U)} `:"";s.write(`${i}${a("red",t)}
20
20
 
21
- `)},Yt=(t="",e)=>{let s=e?.output??process.stdout,i=e?.withGuide??E.withGuide?`${a("gray",Fe)} `:"";s.write(`${i}${t}
21
+ `)},Yt=(t="",e)=>{let s=e?.output??process.stdout,i=e?.withGuide??E.withGuide?`${a("gray",Le)} `:"";s.write(`${i}${t}
22
22
  `)},q=(t="",e)=>{let s=e?.output??process.stdout,i=e?.withGuide??E.withGuide?`${a("gray",y)}
23
23
  ${a("gray",U)} `:"";s.write(`${i}${t}
24
24
 
25
- `)};var Be=t=>t,Ke=(t,e,s)=>{let i={hard:!0,trim:!1},n=k(t,e,i).split(`
26
- `),u=n.reduce((l,d)=>Math.max(T(d),l),0),o=n.map(s).reduce((l,d)=>Math.max(T(d),l),0),r=e-(o-u);return k(t,r,i)},nt=(t="",e="",s)=>{let i=s?.output??O.stdout,n=s?.withGuide??E.withGuide,u=s?.format??Be,o=["",...Ke(t,K(i)-6,u).split(`
27
- `).map(u),""],r=T(e),l=Math.max(o.reduce((p,m)=>{let c=T(m);return c>p?c:p},0),r)+2,d=o.map(p=>`${a("gray",y)} ${p}${" ".repeat(l-T(p))}${a("gray",y)}`).join(`
28
- `),g=n?`${a("gray",y)}
29
- `:"",h=n?Oe:Pe;i.write(`${g}${a("green",it)} ${a("reset",e)} ${a("gray",Bt.repeat(Math.max(l-r-1,1))+Le)}
25
+ `)};var Ke=t=>t,He=(t,e,s)=>{let i={hard:!0,trim:!1},o=k(t,e,i).split(`
26
+ `),u=o.reduce((l,d)=>Math.max(T(d),l),0),n=o.map(s).reduce((l,d)=>Math.max(T(d),l),0),r=e-(n-u);return k(t,r,i)},ot=(t="",e="",s)=>{let i=s?.output??O.stdout,o=s?.withGuide??E.withGuide,u=s?.format??Ke,n=["",...He(t,K(i)-6,u).split(`
27
+ `).map(u),""],r=T(e),l=Math.max(n.reduce((p,m)=>{let c=T(m);return c>p?c:p},0),r)+2,d=n.map(p=>`${a("gray",y)} ${p}${" ".repeat(l-T(p))}${a("gray",y)}`).join(`
28
+ `),g=o?`${a("gray",y)}
29
+ `:"",h=o?Re:ke;i.write(`${g}${a("green",rt)} ${a("reset",e)} ${a("gray",Bt.repeat(Math.max(l-r-1,1))+Oe)}
30
30
  ${d}
31
- ${a("gray",h+Bt.repeat(l+2)+Re)}
32
- `)};var He=t=>a("magenta",t),zt=({indicator:t="dots",onCancel:e,output:s=process.stdout,cancelMessage:i,errorMessage:n,frames:u=vt?["\u25D2","\u25D0","\u25D3","\u25D1"]:["\u2022","o","O","0"],delay:o=vt?80:120,signal:r,...l}={})=>{let d=Me(),g,h,p=!1,m=!1,c="",$,b=performance.now(),A=K(s),R=l?.styleFrame??He,V=w=>{let L=w>1?n??E.messages.error:i??E.messages.cancel;m=w===1,p&&(B(L,w),m&&typeof e=="function"&&e())},F=()=>V(2),v=()=>V(1),_=()=>{process.on("uncaughtExceptionMonitor",F),process.on("unhandledRejection",F),process.on("SIGINT",v),process.on("SIGTERM",v),process.on("exit",V),r&&r.addEventListener("abort",v)},I=()=>{process.removeListener("uncaughtExceptionMonitor",F),process.removeListener("unhandledRejection",F),process.removeListener("SIGINT",v),process.removeListener("SIGTERM",v),process.removeListener("exit",V),r&&r.removeEventListener("abort",v)},S=()=>{if($===void 0)return;d&&s.write(`
31
+ ${a("gray",h+Bt.repeat(l+2)+Pe)}
32
+ `)};var qe=t=>a("magenta",t),zt=({indicator:t="dots",onCancel:e,output:s=process.stdout,cancelMessage:i,errorMessage:o,frames:u=vt?["\u25D2","\u25D0","\u25D3","\u25D1"]:["\u2022","o","O","0"],delay:n=vt?80:120,signal:r,...l}={})=>{let d=Ae(),g,h,p=!1,m=!1,c="",$,b=performance.now(),A=K(s),R=l?.styleFrame??qe,L=w=>{let V=w>1?o??E.messages.error:i??E.messages.cancel;m=w===1,p&&(B(V,w),m&&typeof e=="function"&&e())},F=()=>L(2),v=()=>L(1),_=()=>{process.on("uncaughtExceptionMonitor",F),process.on("unhandledRejection",F),process.on("SIGINT",v),process.on("SIGTERM",v),process.on("exit",L),r&&r.addEventListener("abort",v)},I=()=>{process.removeListener("uncaughtExceptionMonitor",F),process.removeListener("unhandledRejection",F),process.removeListener("SIGINT",v),process.removeListener("SIGTERM",v),process.removeListener("exit",L),r&&r.removeEventListener("abort",v)},S=()=>{if($===void 0)return;d&&s.write(`
33
33
  `);let w=k($,A,{hard:!0,trim:!1}).split(`
34
- `);w.length>1&&s.write(H.cursor.up(w.length-1)),s.write(H.cursor.to(0)),s.write(H.erase.down())},x=w=>w.replace(/\.+$/,""),P=w=>{let L=(performance.now()-w)/1e3,N=Math.floor(L/60),D=Math.floor(L%60);return N>0?`[${N}m ${D}s]`:`[${D}s]`},C=l.withGuide??E.withGuide,J=(w="")=>{p=!0,g=Gt({output:s}),c=x(w),b=performance.now(),C&&s.write(`${a("gray",y)}
35
- `);let L=0,N=0;_(),h=setInterval(()=>{if(d&&c===$)return;S(),$=c;let D=R(u[L]),Y;if(d)Y=`${D} ${c}...`;else if(t==="timer")Y=`${D} ${c} ${P(b)}`;else{let Zt=".".repeat(Math.floor(N)).slice(0,3);Y=`${D} ${c}${Zt}`}let Qt=k(Y,A,{hard:!0,trim:!1});s.write(Qt),L=L+1<u.length?L+1:0,N=N<4?N+.125:0},o)},B=(w="",L=0,N=!1)=>{if(!p)return;p=!1,clearInterval(h),S();let D=L===0?a("green",it):L===1?a("red",Ht):a("red",qt);c=w??c,N||(t==="timer"?s.write(`${D} ${c} ${P(b)}
34
+ `);w.length>1&&s.write(H.cursor.up(w.length-1)),s.write(H.cursor.to(0)),s.write(H.erase.down())},x=w=>w.replace(/\.+$/,""),P=w=>{let V=(performance.now()-w)/1e3,N=Math.floor(V/60),D=Math.floor(V%60);return N>0?`[${N}m ${D}s]`:`[${D}s]`},C=l.withGuide??E.withGuide,Y=(w="")=>{p=!0,g=Gt({output:s}),c=x(w),b=performance.now(),C&&s.write(`${a("gray",y)}
35
+ `);let V=0,N=0;_(),h=setInterval(()=>{if(d&&c===$)return;S(),$=c;let D=R(u[V]),z;if(d)z=`${D} ${c}...`;else if(t==="timer")z=`${D} ${c} ${P(b)}`;else{let te=".".repeat(Math.floor(N)).slice(0,3);z=`${D} ${c}${te}`}let Zt=k(z,A,{hard:!0,trim:!1});s.write(Zt),V=V+1<u.length?V+1:0,N=N<4?N+.125:0},n)},B=(w="",V=0,N=!1)=>{if(!p)return;p=!1,clearInterval(h),S();let D=V===0?a("green",rt):V===1?a("red",Ht):a("red",qt);c=w??c,N||(t==="timer"?s.write(`${D} ${c} ${P(b)}
36
36
  `):s.write(`${D} ${c}
37
- `)),I(),g()};return{start:J,stop:(w="")=>B(w,0),message:(w="")=>{c=x(w??c)},cancel:(w="")=>B(w,1),error:(w="")=>B(w,2),clear:()=>B("",0,!0),get isCancelled(){return m}}},Ns={light:f("\u2500","-"),heavy:f("\u2501","="),block:f("\u2588","#")};var qe=[`${a("dim","\u2191/\u2193")} to navigate`,`${a("dim","Enter:")} confirm`],st=(t,e)=>t.includes(`
37
+ `)),I(),g()};return{start:Y,stop:(w="")=>B(w,0),message:(w="")=>{c=x(w??c)},cancel:(w="")=>B(w,1),error:(w="")=>B(w,2),clear:()=>B("",0,!0),get isCancelled(){return m}}},Ds={light:f("\u2500","-"),heavy:f("\u2501","="),block:f("\u2588","#")};var Je=[`${a("dim","\u2191/\u2193")} to navigate`,`${a("dim","Enter:")} confirm`],it=(t,e)=>t.includes(`
38
38
  `)?t.split(`
39
39
  `).map(s=>e(s)).join(`
40
- `):e(t),yt=t=>{let e=(i,n)=>{if(i===void 0)return"";let u=i.label??String(i.value);switch(n){case"disabled":return`${a("gray",Ut)} ${st(u,o=>a("gray",o))}${i.hint?` ${a("dim",`(${i.hint??"disabled"})`)}`:""}`;case"selected":return`${st(u,o=>a("dim",o))}`;case"active":return`${a("green",Ve)} ${u}${i.hint?` ${a("dim",`(${i.hint})`)}`:""}`;case"cancelled":return`${st(u,o=>a(["strikethrough","dim"],o))}`;default:return`${a("dim",Ut)} ${st(u,o=>a("dim",o))}`}},s=t.showInstructions??!0;return new Wt({options:t.options,signal:t.signal,input:t.input,output:t.output,initialValue:t.initialValue,render(){let i=t.withGuide??E.withGuide,n=`${Jt(this.state)} `,u=`${je(this.state)} `,o=et(t.output,t.message,u,n),r=`${i?`${a("gray",y)}
41
- `:""}${o}
42
- `;switch(this.state){case"submit":{let l=i?`${a("gray",y)} `:"",d=et(t.output,e(this.options[this.cursor],"selected"),l);return`${r}${d}`}case"cancel":{let l=i?`${a("gray",y)} `:"",d=et(t.output,e(this.options[this.cursor],"cancelled"),l);return`${r}${d}${i?`
40
+ `):e(t),yt=t=>{let e=(i,o)=>{if(i===void 0)return"";let u=i.label??String(i.value);switch(o){case"disabled":return`${a("gray",Ut)} ${it(u,n=>a("gray",n))}${i.hint?` ${a("dim",`(${i.hint??"disabled"})`)}`:""}`;case"selected":return`${it(u,n=>a("dim",n))}`;case"active":return`${a("green",Ve)} ${u}${i.hint?` ${a("dim",`(${i.hint})`)}`:""}`;case"cancelled":return`${it(u,n=>a(["strikethrough","dim"],n))}`;default:return`${a("dim",Ut)} ${it(u,n=>a("dim",n))}`}},s=t.showInstructions??!0;return new Wt({options:t.options,signal:t.signal,input:t.input,output:t.output,initialValue:t.initialValue,render(){let i=t.withGuide??E.withGuide,o=`${Jt(this.state)} `,u=`${We(this.state)} `,n=st(t.output,t.message,u,o),r=`${i?`${a("gray",y)}
41
+ `:""}${n}
42
+ `;switch(this.state){case"submit":{let l=i?`${a("gray",y)} `:"",d=st(t.output,e(this.options[this.cursor],"selected"),l);return`${r}${d}`}case"cancel":{let l=i?`${a("gray",y)} `:"",d=st(t.output,e(this.options[this.cursor],"cancelled"),l);return`${r}${d}${i?`
43
43
  ${a("gray",y)}`:""}`}default:{let l=i?`${a("cyan",y)} `:"",d=r.split(`
44
- `).length,g=s?We(qe,i):i?[a("cyan",U)]:[],h=g.join(`
45
- `),p=g.length+1;return`${r}${l}${Ue({output:t.output,cursor:this.cursor,options:this.options,maxItems:t.maxItems,columnPadding:l.length,rowPadding:d+p,style:(m,c)=>e(m,m.disabled?"disabled":c?"active":"inactive")}).join(`
44
+ `).length,g=s?Ue(Je,i):i?[a("cyan",U)]:[],h=g.join(`
45
+ `),p=g.length+1;return`${r}${l}${Be({output:t.output,cursor:this.cursor,options:this.options,maxItems:t.maxItems,columnPadding:l.length,rowPadding:d+p,style:(m,c)=>e(m,m.disabled?"disabled":c?"active":"inactive")}).join(`
46
46
  ${l}`)}
47
47
  ${h}
48
- `}}}}).prompt()};var Ds=`${a("gray",y)} `;var Xt=t=>new tt({validate:t.validate,placeholder:t.placeholder,defaultValue:t.defaultValue,initialValue:t.initialValue,output:t.output,signal:t.signal,input:t.input,render(){let e=t?.withGuide??E.withGuide,s=`${`${e?`${a("gray",y)}
48
+ `}}}}).prompt()};var Gs=`${a("gray",y)} `;var Xt=t=>new et({validate:t.validate,placeholder:t.placeholder,defaultValue:t.defaultValue,initialValue:t.initialValue,output:t.output,signal:t.signal,input:t.input,render(){let e=t?.withGuide??E.withGuide,s=`${`${e?`${a("gray",y)}
49
49
  `:""}${Jt(this.state)} `}${t.message}
50
- `,i=t.placeholder&&t.placeholder.length>0?a("inverse",t.placeholder[0])+a("dim",t.placeholder.slice(1)):a(["inverse","hidden"],"_"),n=this.userInput?this.userInputWithCursor:i,u=this.value??"";switch(this.state){case"error":{let o=this.error?` ${a("yellow",this.error)}`:"",r=e?`${a("yellow",y)} `:"",l=e?a("yellow",U):"";return`${s.trim()}
51
- ${r}${n}
52
- ${l}${o}
53
- `}case"submit":{let o=u?` ${a("dim",u)}`:"",r=e?a("gray",y):"";return`${s}${r}${o}`}case"cancel":{let o=u?` ${a(["strikethrough","dim"],u)}`:"",r=e?a("gray",y):"";return`${s}${r}${o}${u.trim()?`
54
- ${r}`:""}`}default:{let o=e?`${a("cyan",y)} `:"",r=e?a("cyan",U):"";return`${s}${o}${n}
50
+ `,i=t.placeholder&&t.placeholder.length>0?a("inverse",t.placeholder[0])+a("dim",t.placeholder.slice(1)):a(["inverse","hidden"],"_"),o=this.userInput?this.userInputWithCursor:i,u=this.value??"";switch(this.state){case"error":{let n=this.error?` ${a("yellow",this.error)}`:"",r=e?`${a("yellow",y)} `:"",l=e?a("yellow",U):"";return`${s.trim()}
51
+ ${r}${o}
52
+ ${l}${n}
53
+ `}case"submit":{let n=u?` ${a("dim",u)}`:"",r=e?a("gray",y):"";return`${s}${r}${n}`}case"cancel":{let n=u?` ${a(["strikethrough","dim"],u)}`:"",r=e?a("gray",y):"";return`${s}${r}${n}${u.trim()?`
54
+ ${r}`:""}`}default:{let n=e?`${a("cyan",y)} `:"",r=e?a("cyan",U):"";return`${s}${n}${o}
55
55
  ${r}
56
- `}}}}).prompt();var Ye=!process.env.NO_COLOR&&!!process.stdout.isTTY,ut=(t,e)=>Ye?`\x1B[${t}m${e}\x1B[0m`:e,ot=t=>ut("1",t),at=t=>ut("2",t),wt=t=>ut("32",t),ze=t=>ut("33",t);function Xe(t,e=24){let s=Math.max(0,Math.min(100,Math.round(t))),i=Math.round(s/100*e);return`${"\u2501".repeat(i)}${"\u2500".repeat(e-i)}`}function Qe(t){return[ot(t.title),wt(t.detail),...t.action?[at(t.action)]:[]].join(`
57
- `)}function js(){let t=zt();return{start(e){t.start(e)},update(e){t.message(e)},stop(e){t.stop(e)},fail(e){t.error(e)}}}async function Ws(t){let e=await yt({message:"Implement findings with",options:t});return W(e)?(rt("Implementation cancelled"),null):e}async function Us(t){if(Yt(`${wt(ot(" CAVEMAN "))} ${at("LEARN / LOCAL SETUP")}`),t.score!==null){let i=Math.max(0,Math.min(100,Math.round(t.score))),n=[`${wt(Xe(i))} ${ot(`${i}/100`)}`,at(t.scope),t.sessions,...t.diff?[ze(t.diff)]:[]].join(`
58
- `);nt(n,"SETUP SCORE")}else nt([t.sessions,...t.status?[t.status]:[]].join(`
59
- `),"LEARN RESULT");if(t.moves.length>0){let i=t.moves.map((n,u)=>`${at(String(u+1).padStart(2,"0"))} ${Qe(n)}`);nt(i.join(`
56
+ `}}}}).prompt();var ze=!process.env.NO_COLOR&&!!process.stdout.isTTY,ut=(t,e)=>ze?`\x1B[${t}m${e}\x1B[0m`:e,at=t=>ut("1",t),J=t=>ut("2",t),wt=t=>ut("32",t),Xe=t=>ut("33",t);function Qe(t,e=24){let s=Math.max(0,Math.min(100,Math.round(t))),i=Math.round(s/100*e);return`${"\u2501".repeat(i)}${"\u2500".repeat(e-i)}`}function Ze(t){return[at(t.title),wt(t.detail),...t.action?[J(t.action)]:[]].join(`
57
+ `)}function Qt(t){let e=t.confirmed&&t.confirmed>0?J(`${t.confirmed} fixes measured since you applied them \u2014 run caveman learn --all`):void 0;if(t.score===null)return[t.sessions,...t.status?[t.status]:[],...e?[e]:[]].join(`
58
+ `);let s=Math.max(0,Math.min(100,Math.round(t.score)));return[`${wt(Qe(s))} ${at(`${s}/100`)}`,...e?[e]:[],J(t.scope),t.sessions,...t.diff?[Xe(t.diff)]:[]].join(`
59
+ `)}function Ws(){let t=zt();return{start(e){t.start(e)},update(e){t.message(e)},stop(e){t.stop(e)},fail(e){t.error(e)}}}async function Us(t){let e=await yt({message:"Implement findings with",options:t});return W(e)?(nt("Implementation cancelled"),null):e}async function Bs(t){if(Yt(`${wt(at(" CAVEMAN "))} ${J("LEARN / LOCAL SETUP")}`),t.score!==null?ot(Qt(t),"SETUP SCORE"):ot(Qt(t),"LEARN RESULT"),t.moves.length>0){let i=t.moves.map((o,u)=>`${J(String(u+1).padStart(2,"0"))} ${Ze(o)}`);ot(i.join(`
60
60
 
61
- `),"TOP MOVES")}t.protected&&j.warn(`${ot("Protected")} ${t.protected}`);let e=[];t.moves.length>0&&e.push({value:"implement",label:"Implement with agent",hint:"Claude Code or Codex \xB7 approval before edits"}),t.findings>0&&e.push({value:"details",label:`Show all ${t.findings} findings`,hint:"full ids, evidence, and suggestions"}),e.push({value:"report",label:"Open visual report",hint:t.report},{value:"done",label:"Done"});let s=await yt({message:"Choose next step",initialValue:t.moves.length>0?"implement":"report",options:e});if(W(s))return rt("Done"),{action:"done"};if(s==="implement"){let i=await Xt({message:"Anything agent should focus on?",placeholder:"Press Enter to work through all top moves",defaultValue:""});return W(i)?(rt("Implementation cancelled"),{action:"done"}):(q("Opening implementation agent"),i.trim()?{action:"implement",focus:i.trim()}:{action:"implement"})}else s==="details"?q("Showing complete findings"):s==="report"?q("Opening local report"):q(`Saved report \xB7 ${t.report}`);return{action:s}}export{js as createLearnProgress,Qe as learnMoveBody,Xe as learnScoreBar,Us as renderLearnTui,Ws as selectLearnAgent};
61
+ `),"TOP MOVES")}t.protected&&j.warn(`${at("Protected")} ${t.protected}`);let e=[];t.moves.length>0&&e.push({value:"implement",label:"Implement with agent",hint:"Claude Code or Codex \xB7 approval before edits"}),t.findings>0&&e.push({value:"details",label:`Show all ${t.findings} findings`,hint:"full ids, evidence, and suggestions"}),e.push({value:"report",label:"Open visual report",hint:t.report},{value:"done",label:"Done"});let s=await yt({message:"Choose next step",initialValue:t.moves.length>0?"implement":"report",options:e});if(W(s))return nt("Done"),{action:"done"};if(s==="implement"){let i=await Xt({message:"Anything agent should focus on?",placeholder:"Press Enter to work through all top moves",defaultValue:""});return W(i)?(nt("Implementation cancelled"),{action:"done"}):(q("Opening implementation agent"),i.trim()?{action:"implement",focus:i.trim()}:{action:"implement"})}else s==="details"?q("Showing complete findings"):s==="report"?q("Opening local report"):q(`Saved report \xB7 ${t.report}`);return{action:s}}export{Ws as createLearnProgress,Ze as learnMoveBody,Qe as learnScoreBar,Qt as learnScoreBody,Bs as renderLearnTui,Us as selectLearnAgent};
@@ -78,6 +78,11 @@ function profile() {
78
78
  const mode = policyMode();
79
79
  return mode === "record" ? "record-only" : mode === "max" ? "full-max" : "full-safe";
80
80
  }
81
+ // Return as soon as the accumulated bytes parse as one complete JSON payload
82
+ // instead of waiting for EOF. The host writes one object and closes, but under
83
+ // the Windows pipe implementation that close can lag arbitrarily (#729/#833),
84
+ // and a hook that blocks on EOF spends the host's whole budget waiting for a
85
+ // close it already has all the data for.
81
86
  async function stdin() {
82
87
  const chunks = [];
83
88
  let bytes = 0;
@@ -87,6 +92,15 @@ async function stdin() {
87
92
  if (bytes > 2 * 1024 * 1024)
88
93
  throw new Error("hook payload too large");
89
94
  chunks.push(value);
95
+ const joined = Buffer.concat(chunks);
96
+ // A partial payload throws and we wait for more bytes.
97
+ try {
98
+ JSON.parse(joined.toString("utf8"));
99
+ }
100
+ catch {
101
+ continue;
102
+ }
103
+ return joined;
90
104
  }
91
105
  return Buffer.concat(chunks);
92
106
  }
@@ -378,9 +392,16 @@ function fallback(entry) {
378
392
  }
379
393
  catch { /* host remains fail-open */ }
380
394
  }
395
+ // Budget for the delegated child. This runs inside a host hook, so an
396
+ // unbounded spawnSync could block the user's turn forever if index.js stalls,
397
+ // and on Windows process spawn is ~10x macOS before antivirus (#819) — the
398
+ // double-spawn alone can exceed the host's cap. Cap it below the host's and
399
+ // fall through to the fail-open path on expiry, the way every other subprocess
400
+ // in this package already does (#799).
401
+ const DELEGATE_TIMEOUT_MS = 3000;
381
402
  function delegateToFullCLI(raw, agent) {
382
403
  const cli = join(dirname(fileURLToPath(import.meta.url)), "index.js");
383
- const result = spawnSync(process.execPath, [cli, "native-hook", agent], { input: raw, maxBuffer: 3 * 1024 * 1024, env: process.env });
404
+ const result = spawnSync(process.execPath, [cli, "native-hook", agent], { input: raw, maxBuffer: 3 * 1024 * 1024, env: process.env, timeout: DELEGATE_TIMEOUT_MS });
384
405
  if (!result.error && result.status === 0) {
385
406
  if (result.stdout?.length)
386
407
  process.stdout.write(result.stdout);
@@ -390,7 +411,7 @@ function delegateToFullCLI(raw, agent) {
390
411
  }
391
412
  async function main() {
392
413
  const agentArg = process.argv[2] === "native-hook" ? process.argv[3] : process.argv[2];
393
- const agent = agentArg === "claude" || agentArg === "codex" || agentArg === "hermes" || agentArg === "gemini" || agentArg === "opencode" ? agentArg : undefined;
414
+ const agent = agentArg === "claude" || agentArg === "codex" || agentArg === "hermes" || agentArg === "gemini" || agentArg === "opencode" || agentArg === "pi" ? agentArg : undefined;
394
415
  if (!agent)
395
416
  return;
396
417
  let raw;
@@ -449,7 +470,7 @@ async function main() {
449
470
  else if (mode !== "record" && agent === "claude" && eventName === "PostToolUse" && response?.output_replacement) {
450
471
  process.stdout.write(JSON.stringify({ hookSpecificOutput: { hookEventName: "PostToolUse", updatedToolOutput: response.output_replacement } }));
451
472
  }
452
- else if (mode !== "record" && agent === "opencode" && eventName === "PostToolUse" && response) {
473
+ else if (mode !== "record" && (agent === "opencode" || agent === "pi") && (eventName === "PostToolUse" || eventName === "PostToolUseFailure") && response) {
453
474
  process.stdout.write(JSON.stringify(response));
454
475
  }
455
476
  }
@@ -1,28 +1,72 @@
1
- import { readFileSync, statSync } from "node:fs";
2
- import { dirname, resolve } from "node:path";
1
+ import { existsSync, readFileSync, statSync } from "node:fs";
2
+ import { dirname, extname, isAbsolute, join, resolve } from "node:path";
3
3
  export function parseWindowsNodeShim(source) {
4
4
  for (const line of source.split(/\r?\n/)) {
5
5
  if (!/(?:\bnode(?:\.exe)?\b|_prog)/i.test(line) || !/%\*/.test(line))
6
6
  continue;
7
- const match = line.match(/"%(?:dp0%|~dp0)\\([^"\r\n]+\.(?:cjs|mjs|js))"\s+%\*/i);
7
+ // Shim-relative target (npm cmd-shim, pnpm/yarn-classic @zkochan forms), or
8
+ // a drive-absolute target (pnpm emits one when the global bin dir and the
9
+ // store sit on different drives — path.relative crosses drives as absolute).
10
+ const match = line.match(/"%(?:dp0%|~dp0)\\([^"\r\n]+\.(?:cjs|mjs|js))"\s+%\*/i)
11
+ ?? line.match(/"([A-Za-z]:[\\/][^"\r\n]+\.(?:cjs|mjs|js))"\s+%\*/i);
8
12
  if (match)
9
13
  return match[1];
10
14
  }
11
15
  return null;
12
16
  }
13
- export function portableInvocation(command, args, platform = process.platform) {
14
- if (platform !== "win32" || !/\.(?:cmd|bat)$/i.test(command)) {
15
- return { command, args: [...args] };
17
+ function envValue(env, name) {
18
+ const key = Object.keys(env).find((candidate) => candidate.toLowerCase() === name.toLowerCase());
19
+ return key === undefined ? undefined : env[key];
20
+ }
21
+ // Resolve a bare command through PATH/PATHEXT the way Windows does. This used
22
+ // to be the caller's job, and the contract was invisible: hand this function a
23
+ // bare "npx" on win32 and the .cmd test below missed, so it handed the bare
24
+ // name straight to spawn(), which fails with EINVAL rather than launching
25
+ // anything. Every other copy of this helper in the repo resolves internally;
26
+ // so does this one now. Extensionless names resolve only through PATHEXT —
27
+ // npm/pnpm .bin dirs park a non-executable Unix shim under the bare name next
28
+ // to the real .CMD, and probing the bare name first picks the wrong one (#834).
29
+ export function resolveWindowsCommand(command, env) {
30
+ const pathExt = envValue(env, "PATHEXT") ?? ".COM;.EXE;.BAT;.CMD";
31
+ const names = extname(command)
32
+ ? [command]
33
+ : pathExt.split(";").map((extension) => `${command}${extension.startsWith(".") ? extension : `.${extension}`}`);
34
+ // A path skips PATH lookup but NOT PATHEXT: handing an extensionless file
35
+ // straight to execFile is the exact EFTYPE this function exists to prevent.
36
+ if (isAbsolute(command) || /[\\/]/.test(command)) {
37
+ for (const name of names)
38
+ if (existsSync(name))
39
+ return name;
40
+ return existsSync(command) ? command : undefined;
41
+ }
42
+ for (const directory of (envValue(env, "PATH") ?? "").split(";")) {
43
+ if (!directory)
44
+ continue;
45
+ for (const name of names) {
46
+ const candidate = join(directory, name);
47
+ if (existsSync(candidate))
48
+ return candidate;
49
+ }
16
50
  }
17
- const stat = statSync(command);
51
+ return undefined;
52
+ }
53
+ export function portableInvocation(command, args, platform = process.platform, env = process.env) {
54
+ if (platform !== "win32")
55
+ return { command, args: [...args] };
56
+ const executable = resolveWindowsCommand(command, env) ?? command;
57
+ if (!/\.(?:cmd|bat)$/i.test(executable))
58
+ return { command: executable, args: [...args] };
59
+ const stat = statSync(executable);
18
60
  if (!stat.isFile() || stat.size > 256 * 1024) {
19
- throw new Error(`cannot safely launch Windows command shim: ${command}`);
61
+ throw new Error(`cannot safely launch Windows command shim: ${executable}`);
20
62
  }
21
- const relativeScript = parseWindowsNodeShim(readFileSync(command, "utf8"));
22
- if (!relativeScript) {
23
- throw new Error(`cannot safely launch non-Node Windows command shim: ${command}; install a native .exe`);
63
+ const shimScript = parseWindowsNodeShim(readFileSync(executable, "utf8"));
64
+ if (!shimScript) {
65
+ throw new Error(`cannot safely launch non-Node Windows command shim: ${executable}; install a native .exe`);
24
66
  }
25
- const script = resolve(dirname(command), ...relativeScript.split(/[\\/]+/));
67
+ const script = /^[A-Za-z]:[\\/]/.test(shimScript)
68
+ ? shimScript
69
+ : resolve(dirname(executable), ...shimScript.split(/[\\/]+/));
26
70
  if (!statSync(script).isFile()) {
27
71
  throw new Error(`Windows command shim target is missing: ${script}`);
28
72
  }
@@ -26,20 +26,30 @@ function resolveWindowsCommand(command, env) {
26
26
  return null;
27
27
  }
28
28
 
29
+ export function parseWindowsNodeShim(source) {
30
+ for (const line of source.split(/\r?\n/)) {
31
+ if (!/(?:\bnode(?:\.exe)?\b|_prog)/i.test(line) || !/%\*/.test(line)) continue;
32
+ // Shim-relative target (npm cmd-shim, pnpm/yarn-classic @zkochan forms), or
33
+ // a drive-absolute target (pnpm emits one when the global bin dir and the
34
+ // store sit on different drives — path.relative crosses drives as absolute).
35
+ const match = line.match(/"%(?:dp0%|~dp0)\\([^"\r\n]+\.(?:cjs|mjs|js))"\s+%\*/i)
36
+ || line.match(/"([A-Za-z]:[\\/][^"\r\n]+\.(?:cjs|mjs|js))"\s+%\*/i);
37
+ if (match) return match[1];
38
+ }
39
+ return null;
40
+ }
41
+
29
42
  export function portableInvocation(command, args, platform = process.platform, env = process.env) {
30
43
  if (platform !== "win32") return { command, args: [...args] };
31
44
  const executable = resolveWindowsCommand(command, env) ?? command;
32
45
  if (!/\.(?:cmd|bat)$/i.test(executable)) return { command: executable, args: [...args] };
33
46
  const stat = statSync(executable);
34
47
  if (!stat.isFile() || stat.size > 256 * 1024) throw new Error(`unsafe Windows command shim: ${executable}`);
35
- let relativeScript = null;
36
- for (const line of readFileSync(executable, "utf8").split(/\r?\n/)) {
37
- if (!/(?:\bnode(?:\.exe)?\b|_prog)/i.test(line) || !/%\*/.test(line)) continue;
38
- const match = line.match(/"%(?:dp0%|~dp0)\\([^"\r\n]+\.(?:cjs|mjs|js))"\s+%\*/i);
39
- if (match) { relativeScript = match[1]; break; }
40
- }
48
+ const relativeScript = parseWindowsNodeShim(readFileSync(executable, "utf8"));
41
49
  if (!relativeScript) throw new Error(`non-Node Windows command shim: ${executable}`);
42
- const script = resolve(dirname(executable), ...relativeScript.split(/[\\/]+/));
50
+ const script = /^[A-Za-z]:[\\/]/.test(relativeScript)
51
+ ? relativeScript
52
+ : resolve(dirname(executable), ...relativeScript.split(/[\\/]+/));
43
53
  if (!statSync(script).isFile()) throw new Error(`Windows command shim target missing: ${script}`);
44
54
  return { command: process.execPath, args: [script, ...args] };
45
55
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@caveman-ai/cli",
3
- "version": "1.2.0",
3
+ "version": "1.2.3",
4
4
  "description": "Caveman CLI — wrap coding agents with recoverable local context compression and truthful metering (`caveman claude`), then drive Caveman Cloud from terminal. Compression and metering run in companion Go binaries: run `caveman setup` to see install state. Local savings stay inferred until verified.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -26,12 +26,12 @@
26
26
  "LICENSE"
27
27
  ],
28
28
  "scripts": {
29
- "build": "node scripts/gen-binaries.mjs && node scripts/gen-wedge-installer.mjs && node scripts/compile-registries.mjs && tsc && node scripts/bundle-delegate.mjs && node scripts/bundle-tui.mjs && node scripts/shebang.mjs",
29
+ "build": "node scripts/gen-binaries.mjs && node scripts/gen-wedge-installer.mjs && node scripts/compile-registries.mjs && tsc && node scripts/bundle-delegate.mjs && node scripts/bundle-tui.mjs && node scripts/bundle-pi-extension.mjs && node scripts/shebang.mjs",
30
30
  "prepack": "npm run build",
31
31
  "lint": "tsc --noEmit",
32
- "test": "node scripts/gen-binaries.mjs && node scripts/gen-wedge-installer.mjs && node scripts/compile-registries.mjs && tsc && node scripts/bundle-delegate.mjs && node scripts/bundle-tui.mjs && node scripts/shebang.mjs && node --test --test-concurrency=4 tests/*.runtime.mjs",
32
+ "test": "node scripts/gen-binaries.mjs && node scripts/gen-wedge-installer.mjs && node scripts/compile-registries.mjs && tsc && node scripts/bundle-delegate.mjs && node scripts/bundle-tui.mjs && node scripts/bundle-pi-extension.mjs && node scripts/shebang.mjs && node --test --test-force-exit --test-concurrency=4 tests/*.runtime.mjs",
33
33
  "bench:native": "node scripts/benchmark-native-hooks.mjs",
34
- "test:fast": "node scripts/gen-binaries.mjs && node scripts/gen-wedge-installer.mjs && node scripts/compile-registries.mjs && tsc && node scripts/bundle-delegate.mjs && node scripts/bundle-tui.mjs && node --test --test-concurrency=4 --test-reporter=dot tests/agent-native.runtime.mjs tests/billing.runtime.mjs tests/capability-config.runtime.mjs tests/login.runtime.mjs tests/mcp-surface.runtime.mjs tests/porcelain.runtime.mjs tests/practice-registry.runtime.mjs tests/skills.runtime.mjs tests/status.runtime.mjs tests/subscription-recovery.runtime.mjs tests/wrap-gate.runtime.mjs"
34
+ "test:fast": "node scripts/gen-binaries.mjs && node scripts/gen-wedge-installer.mjs && node scripts/compile-registries.mjs && tsc && node scripts/bundle-delegate.mjs && node scripts/bundle-tui.mjs && node scripts/bundle-pi-extension.mjs && node --test --test-force-exit --test-concurrency=4 --test-reporter=dot tests/agent-native.runtime.mjs tests/billing.runtime.mjs tests/capability-config.runtime.mjs tests/login.runtime.mjs tests/mcp-surface.runtime.mjs tests/porcelain.runtime.mjs tests/practice-registry.runtime.mjs tests/skills.runtime.mjs tests/status.runtime.mjs tests/subscription-recovery.runtime.mjs tests/wrap-gate.runtime.mjs"
35
35
  },
36
36
  "dependencies": {},
37
37
  "devDependencies": {