@visulima/cerebro 3.0.0-alpha.26 → 3.0.0-alpha.28

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.
@@ -0,0 +1,6 @@
1
+ var ne=Object.defineProperty;var u=(e,i)=>ne(e,"name",{value:i,configurable:!0});import{createRequire as ae}from"node:module";import{h as $,H as j,E as q}from"./constants-DmzZF6_u-BmMwILI_.js";import{createTable as x}from"@visulima/tabular";import{NO_BORDER as E}from"@visulima/tabular/style";import le from"terminal-size";import de from"@visulima/colorize/template";import{d as ue}from"./runtime-process-DKHFvYkv.js";import{bold as fe}from"@visulima/colorize";const oe=ae(import.meta.url),v=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,se=u(e=>{if(typeof v<"u"&&v.versions&&v.versions.node){const[i,r]=v.versions.node.split(".").map(Number);if(i>22||i===22&&r>=3||i===20&&r>=16)return v.getBuiltinModule(e)}return oe(e)},"__cjs_getBuiltinModule"),ce=se("node:os");var he=Object.defineProperty,V=u((e,i)=>he(e,"name",{value:i,configurable:!0}),"u$1"),pe=Object.defineProperty,S=V((e,i)=>pe(e,"name",{value:i,configurable:!0}),"l");const me=[161,161,164,164,167,168,170,170,173,174,176,180,182,186,188,191,198,198,208,208,215,216,222,225,230,230,232,234,236,237,240,240,242,243,247,250,252,252,254,254,257,257,273,273,275,275,283,283,294,295,299,299,305,307,312,312,319,322,324,324,328,331,333,333,338,339,358,359,363,363,462,462,464,464,466,466,468,468,470,470,472,472,474,474,476,476,593,593,609,609,708,708,711,711,713,715,717,717,720,720,728,731,733,733,735,735,768,879,913,929,931,937,945,961,963,969,1025,1025,1040,1103,1105,1105,8208,8208,8211,8214,8216,8217,8220,8221,8224,8226,8228,8231,8240,8240,8242,8243,8245,8245,8251,8251,8254,8254,8308,8308,8319,8319,8321,8324,8364,8364,8451,8451,8453,8453,8457,8457,8467,8467,8470,8470,8481,8482,8486,8486,8491,8491,8531,8532,8539,8542,8544,8555,8560,8569,8585,8585,8592,8601,8632,8633,8658,8658,8660,8660,8679,8679,8704,8704,8706,8707,8711,8712,8715,8715,8719,8719,8721,8721,8725,8725,8730,8730,8733,8736,8739,8739,8741,8741,8743,8748,8750,8750,8756,8759,8764,8765,8776,8776,8780,8780,8786,8786,8800,8801,8804,8807,8810,8811,8814,8815,8834,8835,8838,8839,8853,8853,8857,8857,8869,8869,8895,8895,8978,8978,9312,9449,9451,9547,9552,9587,9600,9615,9618,9621,9632,9633,9635,9641,9650,9651,9654,9655,9660,9661,9664,9665,9670,9672,9675,9675,9678,9681,9698,9701,9711,9711,9733,9734,9737,9737,9742,9743,9756,9756,9758,9758,9792,9792,9794,9794,9824,9825,9827,9829,9831,9834,9836,9837,9839,9839,9886,9887,9919,9919,9926,9933,9935,9939,9941,9953,9955,9955,9960,9961,9963,9969,9972,9972,9974,9977,9979,9980,9982,9983,10045,10045,10102,10111,11094,11097,12872,12879,57344,63743,65024,65039,65533,65533,127232,127242,127248,127277,127280,127337,127344,127373,127375,127376,127387,127404,917760,917999,983040,1048573,1048576,1114109],ge=12288,we=65510,be=[12288,12288,65281,65376,65504,65510],ye=8361,ve=65518,$e=[8361,8361,65377,65470,65474,65479,65482,65487,65490,65495,65498,65500,65512,65518],We=32,Oe=10630,Ie=[32,126,162,163,165,166,172,172,175,175,10214,10221,10629,10630],Ae=4352,je=262141,Q=[4352,4447,8986,8987,9001,9002,9193,9196,9200,9200,9203,9203,9725,9726,9748,9749,9776,9783,9800,9811,9855,9855,9866,9871,9875,9875,9889,9889,9898,9899,9917,9918,9924,9925,9934,9934,9940,9940,9962,9962,9970,9971,9973,9973,9978,9978,9981,9981,9989,9989,9994,9995,10024,10024,10060,10060,10062,10062,10067,10069,10071,10071,10133,10135,10160,10160,10175,10175,11035,11036,11088,11088,11093,11093,11904,11929,11931,12019,12032,12245,12272,12287,12289,12350,12353,12438,12441,12543,12549,12591,12593,12686,12688,12773,12783,12830,12832,12871,12880,42124,42128,42182,43360,43388,44032,55203,63744,64255,65040,65049,65072,65106,65108,65126,65128,65131,94176,94180,94192,94198,94208,101589,101631,101662,101760,101874,110576,110579,110581,110587,110589,110590,110592,110882,110898,110898,110928,110930,110933,110933,110948,110951,110960,111355,119552,119638,119648,119670,126980,126980,127183,127183,127374,127374,127377,127386,127488,127490,127504,127547,127552,127560,127568,127569,127584,127589,127744,127776,127789,127797,127799,127868,127870,127891,127904,127946,127951,127955,127968,127984,127988,127988,127992,128062,128064,128064,128066,128252,128255,128317,128331,128334,128336,128359,128378,128378,128405,128406,128420,128420,128507,128591,128640,128709,128716,128716,128720,128722,128725,128728,128732,128735,128747,128748,128756,128764,128992,129003,129008,129008,129292,129338,129340,129349,129351,129535,129648,129660,129664,129674,129678,129734,129736,129736,129741,129756,129759,129770,129775,129784,131072,196605,196608,262141];var Ne=Object.defineProperty,xe=S((e,i)=>Ne(e,"name",{value:i,configurable:!0}),"r$1");const O=xe((e,i)=>{let r=0,a=Math.floor(e.length/2)-1;for(;r<=a;){const o=Math.floor((r+a)/2),s=o*2;if(i<e[s])a=o-1;else if(i>e[s+1])r=o+1;else return!0}return!1},"isInRange");var Ee=Object.defineProperty,g=S((e,i)=>Ee(e,"name",{value:i,configurable:!0}),"r");const G=19968,[Pe,Me]=T(Q);function T(e){let i=e[0],r=e[1];for(let a=0;a<e.length;a+=2){const o=e[a],s=e[a+1];if(G>=o&&G<=s)return[o,s];s-o>r-i&&(i=o,r=s)}return[i,r]}u(T,"c$2");V(T,"f");S(T,"k");g(T,"findWideFastPathRange");const X=g(e=>e<161||e>1114109?!1:O(me,e),"isAmbiguous"),Z=g(e=>e<ge||e>we?!1:O(be,e),"isFullWidth"),ke=g(e=>e<ye||e>ve?!1:O($e,e),"isHalfWidth"),Se=g(e=>e<We||e>Oe?!1:O(Ie,e),"isNarrow"),ee=g(e=>e>=Pe&&e<=Me?!0:e<Ae||e>je?!1:O(Q,e),"isWide");function R(e){return X(e)?"ambiguous":Z(e)?"fullwidth":ke(e)?"halfwidth":Se(e)?"narrow":ee(e)?"wide":"neutral"}u(R,"g$3");V(R,"S");S(R,"getCategory");g(R,"getCategory");var Te=Object.defineProperty,C=u((e,i)=>Te(e,"name",{value:i,configurable:!0}),"i$2"),Re=Object.defineProperty,_=C((e,i)=>Re(e,"name",{value:i,configurable:!0}),"a"),Ce=Object.defineProperty,Y=_((e,i)=>Ce(e,"name",{value:i,configurable:!0}),"e");function I(e){if(!Number.isSafeInteger(e))throw new TypeError(`Expected a code point, got \`${typeof e}\`.`)}u(I,"s$1");C(I,"s");_(I,"r");Y(I,"validate");function A(e){return I(e),R(e)}u(A,"r$3");C(A,"p");_(A,"eastAsianWidthType");Y(A,"eastAsianWidthType");function D(e,{ambiguousAsWide:i=!1}={}){return I(e),Z(e)||ee(e)||i&&X(e)?2:1}u(D,"o$2");C(D,"W");_(D,"eastAsianWidth");Y(D,"eastAsianWidth");var _e=Object.defineProperty,Le=u((e,i)=>_e(e,"name",{value:i,configurable:!0}),"E"),Fe=Object.defineProperty,Be=Le((e,i)=>Fe(e,"name",{value:i,configurable:!0}),"A"),He=Object.defineProperty,L=Be((e,i)=>He(e,"name",{value:i,configurable:!0}),"d");const K=new Map,N=/(?:[\u0020-\u007E\u00A0-\u00FF](?!\uFE0F)){1,1000}/y,P=L(e=>e>=32&&e<=126?"latin":e===8203||e===8204||e===8205||e===8288?"zero":e<=31||e>=127&&e<=159?"control":e>=160&&e<=255||e>=9472&&e<=9599?"latin":e>=4352&&e<=4607||e>=11904&&e<=40959||e>=44032&&e<=55215||e>=63744&&e<=64255||e>=65280&&e<=65519&&!(e>=65377&&e<=65439)||e>=12352&&e<=12543?"wide":e===8230?"latin":"other","getCharType"),qe=L((e,i)=>{const r=Math.floor(e/65536),a=e%65536;let o=K.get(r);if(o||(o=new Map,K.set(r,o)),o.has(a))return o.get(a);let s;if(P(e)==="latin")s=i.width.regular;else if(P(e)==="control")s=i.width.control;else if(P(e)==="wide")s=i.width.wide;else switch(A(e)){case"ambiguous":{s=i.width.ambiguousIsNarrow?i.width.regular:i.width.wide;break}case"fullwidth":{s=i.width.fullWidth;break}case"wide":{s=i.width.wide;break}default:s=i.width.regular}return o.set(a,s),s},"getCachedCharWidth"),ze=L(e=>e>=768&&e<=879||e>=6832&&e<=6911||e>=7616&&e<=7679||e>=8400&&e<=8447||e>=65056&&e<=65071||e>=917760&&e<=917999||e>=65024&&e<=65039||e>=3633&&e<=3642||e>=3655&&e<=3662||e>=3761&&e<=3769||e>=3771&&e<=3772||e>=3784&&e<=3789||e>=2304&&e<=2307||e>=2362&&e<=2383||e>=2385&&e<=2391||e>=2402&&e<=2403||e>=2433&&e<=2435||e>=2492&&e<=2500||e>=2509&&e<=2509||e>=2561&&e<=2563||e>=2620&&e<=2637||e>=1611&&e<=1631||e>=1648&&e<=1648||e>=1750&&e<=1773||e>=2276&&e<=2302||e>=1425&&e<=1469||e>=1471&&e<=1471||e>=1473&&e<=1474||e>=1476&&e<=1477||e>=1479&&e<=1479||e>=3893&&e<=3893||e>=3895&&e<=3895||e>=3897&&e<=3897||e>=3953&&e<=3966||e>=3968&&e<=3972||e>=3974&&e<=3975?!0:e>=768&&e<=777||e>=803&&e<=803,"isCombiningCharacter"),z=L((e,i={})=>{if(!e||e.length===0)return{ellipsed:!1,index:0,truncated:!1,width:0};const r={truncation:{countAnsiEscapeCodes:i.countAnsiEscapeCodes??!1,ellipsis:i.ellipsis??"",ellipsisWidth:i.ellipsisWidth??(i.ellipsis?z(i.ellipsis,{...i,ellipsis:"",ellipsisWidth:0,limit:Number.POSITIVE_INFINITY}).width:0),limit:i.limit??Number.POSITIVE_INFINITY},width:{ambiguousIsNarrow:i.ambiguousIsNarrow??!1,ansi:i.ansiWidth??0,control:i.controlWidth??0,emoji:i.emojiWidth??2,fullWidth:i.fullWidth??2,halfWidth:i.halfWidth??1,regular:i.regularWidth??1,tab:i.tabWidth??8,wide:i.wideWidth??2}},a=Math.max(0,r.truncation.limit-r.truncation.ellipsisWidth),{length:o}=e,s=o>1e4;let t=0,n=0,l=o,d=!1;const w=e.includes("\x1B")||e.includes("›");for(;t<o;){if(w&&(e[t]==="\x1B"||e[t]==="›")){if(e.startsWith("\x1B]8;;",t)){const h="\x1B]8;;\x07",m=h.length,F=e.indexOf("\x07",t+5);if(F!==-1){const B=e.indexOf(h,F+1);if(B!==-1){const re=B+m,te=e.slice(F+1,B).replace($,""),U=z(te,{ambiguousIsNarrow:r.width.ambiguousIsNarrow,ansiWidth:r.width.ansi,controlWidth:r.width.control,countAnsiEscapeCodes:!1,ellipsis:r.truncation.ellipsis,ellipsisWidth:r.truncation.ellipsisWidth,emojiWidth:r.width.emoji,fullWidth:r.width.fullWidth,halfWidth:r.width.halfWidth,limit:Math.max(0,a-n),regularWidth:r.width.regular,tabWidth:r.width.tab,wideWidth:r.width.wide}),H=U.width;if(U.truncated)d=!0,l=Math.min(l,t);else if(n+H>a&&(l=Math.min(l,t),d=!0,n+H>r.truncation.limit))break;if(n+=H,t=re,d&&n>=r.truncation.limit)break;continue}}}if($.lastIndex=t,$.test(e)){const h=$.lastIndex-t,m=r.truncation.countAnsiEscapeCodes?h:r.width.ansi;if(n+m>a&&(l=Math.min(l,t),n+m>r.truncation.limit)){d=!0;break}n+=m,t=$.lastIndex;continue}}const p=e.codePointAt(t);if(p===8203||p===65279||p>=8288&&p<=8292){t+=1;continue}if(p===9){if(n+r.width.tab>a&&(l=Math.min(l,t),n+r.width.tab>r.truncation.limit)){d=!0;break}n+=r.width.tab,t+=1;continue}if(N.lastIndex=t,N.test(e)){const h=(N.lastIndex-t)*r.width.regular;if(n+h>a){const m=Math.floor((a-n)/r.width.regular);if(l=Math.min(l,t+m),n+h>r.truncation.limit){d=!0;break}}n+=h,t=N.lastIndex;continue}if((p<=31||p>=127&&p<=159)&&(j.lastIndex=t,j.test(e))){const h=(j.lastIndex-t)*r.width.control;if(n+h>a&&(l=Math.min(l,t+Math.floor((a-n)/r.width.control)),n+h>r.truncation.limit)){d=!0;break}n+=h,t=j.lastIndex;continue}if(q.lastIndex=t,q.test(e)){if(n+r.width.emoji>a&&(l=Math.min(l,t),n+r.width.emoji>r.truncation.limit)){d=!0;break}n+=r.width.emoji,t=q.lastIndex;continue}const b=e.codePointAt(t)??0;if(ze(b)){t+=b>65535?2:1;continue}let f;if(s)f=qe(b,r);else switch(P(b)){case"control":{f=r.width.control;break}case"latin":{f=r.width.regular;break}case"wide":{f=r.width.wide;break}case"zero":{f=0;break}default:switch(A(b)){case"ambiguous":{f=r.width.ambiguousIsNarrow?r.width.regular:r.width.wide;break}case"fullwidth":{f=r.width.fullWidth;break}case"wide":{f=r.width.wide;break}default:f=r.width.regular}}if(n+f>a&&(l=Math.min(l,t),n+f>r.truncation.limit)){d=!0;break}n+=f,t+=b>65535?2:1}let y=n,J=!1;return d&&r.truncation.limit>=r.truncation.ellipsisWidth&&(y=r.truncation.limit,J=!0),{ellipsed:J,index:d?l:o,truncated:d,width:y}},"getStringTruncatedWidth");var Ve=Object.defineProperty,Ye=u((e,i)=>Ve(e,"name",{value:i,configurable:!0}),"i$1"),De=Object.defineProperty,Je=Ye((e,i)=>De(e,"name",{value:i,configurable:!0}),"e"),Ue=Object.defineProperty,Ge=Je((e,i)=>Ue(e,"name",{value:i,configurable:!0}),"r");const Ke=Ge((e,i={})=>z(e,{...i,ellipsis:"",ellipsisWidth:0,limit:Number.POSITIVE_INFINITY}).width,"getStringWidth");var Qe=Object.defineProperty,Xe=u((e,i)=>Qe(e,"name",{value:i,configurable:!0}),"s");const W=new Map,Ze=500,c=Xe(e=>{if(!e||e==="")return"";const i=W.get(e);if(i!==void 0)return i;const r=de(Object.assign([],{raw:[e]}));if(W.size>=Ze){const a=W.keys().next().value;a!==void 0&&W.delete(a)}return W.set(e,r),r},"templateFormat");var ei=Object.defineProperty,ii=u((e,i)=>ei(e,"name",{value:i,configurable:!0}),"t$1");const M=ii(()=>{const e=ue().CEREBRO_TERMINAL_WIDTH;if(e===void 0)return;const i=Number.parseInt(e,10);if(!(Number.isNaN(i)||i<=0))return i},"getTerminalWidth");var ri=Object.defineProperty,ti=u((e,i)=>ri(e,"name",{value:i,configurable:!0}),"t");class ie{static{u(this,"n")}static{ti(this,"BaseSection")}lines;constructor(){this.lines=[]}add(i){this.lines.push(i)}toString(){return this.lines.join(ce.EOL)}header(i){this.add(fe(i)),this.lines.push("")}}var ni=Object.defineProperty,k=u((e,i)=>ni(e,"name",{value:i,configurable:!0}),"g");const ai=k(e=>e!==void 0&&e>0?e:le().columns,"resolveTerminalWidth"),oi=k((e,i,r,a)=>{if(e.length===0||e.some(d=>d.length!==2))return;let o=0;for(const d of e){const w=d[0];if(w===void 0)continue;const y=Ke(w);y>o&&(o=y)}if(o===0)return;const s=r+a,t=o+s,n=20+s;if(t+n>i)return;const l=i-t;return[t,l]},"computeColumnWidths");class si extends ie{static{u(this,"S")}static{k(this,"ContentSection")}constructor(i){if(super(),i.header&&this.header(c(i.header)),i.content){if(i.raw)if(Array.isArray(i.content)&&i.content.every(r=>typeof r=="string"))i.content.forEach(r=>{Array.isArray(r)?r.forEach(a=>{this.add(c(a))}):this.add(c(r))});else if(typeof i.content=="string")this.add(c(i.content));else throw new TypeError("Invalid raw content, must be a string or array of strings.");else this.add(this.getContentLines(i.content));this.add("")}}getContentLines(i){if(typeof i=="string"){const r=x({showHeader:!1,style:{border:E,paddingLeft:4,paddingRight:1},terminalWidth:M(),truncateOverflow:!1,wordWrap:!0});return r.addRow([c(i)]),r.toString()}if(Array.isArray(i)&&i.every(r=>typeof r=="string"||Array.isArray(r)&&r.every(a=>typeof a=="string"))){const r=ai(M()),a=k(n=>Array.isArray(n)?n.map(l=>c(l)):[c(n)],"formatRow"),o=i.map(n=>a(n)),s=oi(o,r,4,1),t=x({columnWidths:s,showHeader:!1,style:{border:E,paddingLeft:4,paddingRight:1},terminalWidth:r,truncateOverflow:!1,wordWrap:!0});return o.forEach(n=>{s!==void 0&&n.length===2?t.addRow([{content:n[0],wordWrap:!1},n[1]]):t.addRow(n)}),t.toString()}if(typeof i=="object"){const r=i;if(!r.options||!r.data)throw new Error(`Must have an "options" or "data" property
2
+ ${JSON.stringify(i)}`);const a=x({showHeader:!1,style:{border:E,paddingLeft:4,paddingRight:1},terminalWidth:M(),truncateOverflow:!1,wordWrap:!0});return r.data.forEach(o=>{Array.isArray(o)?a.addRow(o.map(s=>c(s))):a.addRow([c(o)])}),a.toString()}throw new Error(`invalid input - 'content' must be a string, array of strings or a object:
3
+
4
+ ${JSON.stringify(i)}`)}}var li=Object.defineProperty,di=u((e,i)=>li(e,"name",{value:i,configurable:!0}),"m");class ui extends ie{static{u(this,"O")}static{di(this,"OptionListSection")}constructor(i){super();let r=i.optionList??[];const a=Array.isArray(i.hide)?i.hide:[i.hide].filter(t=>typeof t=="string"),o=Array.isArray(i.group)?i.group:[i.group].filter(t=>typeof t=="string");a.length>0&&(r=r.filter(t=>!a.includes(t.name))),i.header&&this.header(c(i.header)),o.length>0&&(r=r.filter(t=>{const n=t,l=o.includes("_none")&&!n.group,d=n.group,w=this.intersect(Array.isArray(d)?d:[d],o);return l||w?t:void 0}));const s=x({showHeader:!1,style:{border:E,paddingLeft:2,paddingRight:1,...i.tableOptions?.style},terminalWidth:M()??i.tableOptions?.terminalWidth,truncateOverflow:!1,wordWrap:i.tableOptions?.wordWrap??!0,...i.tableOptions});r.forEach(t=>{const n=t;s.addRow([this.getOptionNames(n,i.reverseNameOrder??!1,i.isArgument??!1),c(n.description)])}),this.add(s.toString()),this.lines.push("")}getOptionNames(i,r,a){if(!i.name)throw new TypeError("Invalid option definition, name is required.");let o=i.type?i.type.name.toLowerCase():"string";const s=i.multiple||i.lazyMultiple?"[]":"";o=c(i.typeLabel??`{underline ${o}${s}}`);let t;if(i.alias)if(i.name){const n=a?i.name:`{yellow --${i.name}}`;t=c(r?`{bold ${n}}, {bold -${i.alias}} ${o}`:`{bold -${i.alias}}, {bold ${n}} ${o}`)}else r?t=c(`{bold -${i.alias}} ${o}`):t=c(`{bold -${i.alias}} ${o}`);else t=c(`{bold ${a?i.name:`{yellow --${i.name}}`}} ${o}`);return t}intersect(i,r){return i.some(a=>r.includes(a))}}var ci=Object.defineProperty,fi=u((e,i)=>ci(e,"name",{value:i,configurable:!0}),"o");const Wi=fi(e=>(Array.isArray(e)?e:[e]).length===0?"":`
5
+ ${e.map(i=>i.optionList?new ui(i).toString():new si(i).toString()).join(`
6
+ `)}`,"commandLineUsage");export{c as f,Wi as p};
@@ -64,6 +64,60 @@ interface Content {
64
64
  */
65
65
  type Options = Record<string | symbol, unknown>;
66
66
  /**
67
+ * Runtime-injected filesystem adapter. A subset of `node:fs/promises` covering
68
+ * the operations commonly used by CLI commands (config files, credentials,
69
+ * cache paths). Defaults to `node:fs/promises` at runtime, but can be swapped
70
+ * for an in-memory adapter in tests or a sandbox in MCP/JustBash environments.
71
+ */
72
+ interface CerebroFs {
73
+ access: (path: string, mode?: number) => Promise<void>;
74
+ mkdir: (path: string, options?: {
75
+ recursive?: boolean;
76
+ }) => Promise<string | undefined>;
77
+ readdir: (path: string) => Promise<string[]>;
78
+ readFile: ((path: string) => Promise<Uint8Array>) & ((path: string, encoding: BufferEncoding) => Promise<string>);
79
+ rm: (path: string, options?: {
80
+ force?: boolean;
81
+ recursive?: boolean;
82
+ }) => Promise<void>;
83
+ stat: (path: string) => Promise<{
84
+ isDirectory: () => boolean;
85
+ isFile: () => boolean;
86
+ }>;
87
+ writeFile: (path: string, data: string | Uint8Array, encoding?: BufferEncoding) => Promise<void>;
88
+ }
89
+ /**
90
+ * Runtime-injected process info. Snapshot of cwd / env / argv / platform / arch
91
+ * captured at CLI construction time, plus an `exit` function and a `stdin`
92
+ * buffer for tests and sandbox runtimes.
93
+ *
94
+ * Prefer reading these from the toolbox over reaching for global `process` so
95
+ * commands stay portable across Node, Deno, Bun, and mocked test runtimes.
96
+ */
97
+ interface CerebroProcess {
98
+ /** CPU architecture, e.g. "x64", "arm64". */
99
+ arch: string;
100
+ /** The full command-line arguments array (same shape as `process.argv`). */
101
+ argv: ReadonlyArray<string>;
102
+ /** Working directory the CLI was constructed with. */
103
+ cwd: string;
104
+ /** Environment variables. May be the host `process.env` or an injected snapshot. */
105
+ env: Record<string, string | undefined>;
106
+ /**
107
+ * Terminate the process with the given exit code. Defaults to the
108
+ * runtime-agnostic exit helper, but can be overridden via `CliOptions.exit`
109
+ * to capture exit codes in tests instead of killing the runner.
110
+ */
111
+ exit: (code?: number) => void;
112
+ /** OS platform, e.g. "linux", "darwin", "win32". */
113
+ platform: string;
114
+ /**
115
+ * Buffered stdin content. Empty string when there is no piped input.
116
+ * Tests and sandbox runtimes can populate this without wiring real streams.
117
+ */
118
+ stdin: string;
119
+ }
120
+ /**
67
121
  * Type-safe Toolbox interface with customizable options and environment variable types.
68
122
  * @template TLogger - The logger type (defaults to Console)
69
123
  * @template TOptions - The options type (defaults to Options/Record&lt;string, unknown>)
@@ -101,6 +155,13 @@ interface Toolbox<TLogger extends Console = Console, TOptions extends Record<str
101
155
  */
102
156
  commandName: string;
103
157
  /**
158
+ * Alias for `logger`. Exposed under the `console` name so commands can
159
+ * write portable `({ console }) => console.log(...)` code without reaching
160
+ * for the global `console`. The injected value is the same object as
161
+ * `toolbox.logger`, so verbosity-aware methods (`debug`) keep working.
162
+ */
163
+ console: TLogger;
164
+ /**
104
165
  * Environment variables processed from the command definition.
105
166
  * Values are transformed according to their type definitions and default values.
106
167
  * @example
@@ -122,6 +183,13 @@ interface Toolbox<TLogger extends Console = Console, TOptions extends Record<str
122
183
  * ```
123
184
  */
124
185
  env: TEnv;
186
+ /**
187
+ * Filesystem adapter. Defaults to `node:fs/promises`, but can be swapped via
188
+ * `CliOptions.fs` for tests (in-memory adapter) or sandboxed runtimes
189
+ * (JustBash, MCP). Prefer `toolbox.fs` over a direct `node:fs/promises`
190
+ * import inside command actions to keep them portable and testable.
191
+ */
192
+ fs: CerebroFs;
125
193
  /** The logger instance. */
126
194
  logger: TLogger;
127
195
  /**
@@ -152,6 +220,14 @@ interface Toolbox<TLogger extends Console = Console, TOptions extends Record<str
152
220
  */
153
221
  options: TOptions;
154
222
  /**
223
+ * Runtime process info — cwd, env, argv, exit, platform, arch, stdin —
224
+ * captured at CLI construction. Prefer `toolbox.process` over reaching for
225
+ * the global `process` so commands stay portable across Node, Deno, Bun,
226
+ * and mocked test runtimes. `process.exit` honors the `CliOptions.exit`
227
+ * override, which lets tests assert exit codes without killing the runner.
228
+ */
229
+ process: CerebroProcess;
230
+ /**
155
231
  * Raw tokens that command-line-args could not assign to a defined
156
232
  * option — typically everything after a `--` separator, since
157
233
  * cerebro runs the parser with `stopAtFirstUnknown: true`.
@@ -541,4 +617,4 @@ declare class PluginManager<T extends Logger = Logger> {
541
617
  */
542
618
  private validateDependencies;
543
619
  }
544
- export { ArgumentDefinition as A, Command as C, EnvDefinition as E, LazyCommandModule as L, OptionDefinition as O, Plugin as P, RunCommandOptions as R, Toolbox as T, VERBOSITY_LEVEL as V, CommandSection as a, PluginManager as b, CliRunOptions as c, Cli as d, CommandExecute as e, OutputType as f, PluginContext as g };
620
+ export { ArgumentDefinition as A, Command as C, EnvDefinition as E, LazyCommandModule as L, OptionDefinition as O, Plugin as P, RunCommandOptions as R, Toolbox as T, VERBOSITY_LEVEL as V, CerebroFs as a, CommandSection as b, PluginManager as c, CliRunOptions as d, CommandExecute as e, Cli as f, CerebroProcess as g, OutputType as h, PluginContext as i };
@@ -0,0 +1,24 @@
1
+ var Q=Object.defineProperty;var N=(r,e)=>Q(r,"name",{value:e,configurable:!0});import{createRequire as Y}from"node:module";const X=Y(import.meta.url),S=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,Z=N(r=>{if(typeof S<"u"&&S.versions&&S.versions.node){const[e,t]=S.versions.node.split(".").map(Number);if(e>22||e===22&&t>=3||e===20&&t>=16)return S.getBuiltinModule(r)}return X(r)},"__cjs_getBuiltinModule"),{createRequire:ee}=Z("node:module");var re=Object.defineProperty,te=N((r,e)=>re(r,"name",{value:e,configurable:!0}),"A$2"),ie=Object.defineProperty,L=te((r,e)=>ie(r,"name",{value:e,configurable:!0}),"$"),ne=Object.defineProperty,oe=L((r,e)=>ne(r,"name",{value:e,configurable:!0}),"r$1");const se=oe(r=>r.replaceAll(/\r\n|\r(?!\n)|\n/gu,`
2
+ `),"normalizeLF"),ae=globalThis.process??Object.create(null),P={versions:{}},_=new Proxy(ae,{get(r,e){if(e in r)return r[e];if(e in P)return P[e]}});var le=Object.defineProperty,ce=L((r,e)=>le(r,"name",{value:e,configurable:!0}),"b");const de=ce((r,e,t,i)=>{const s={column:0,line:-1,...r.start},o={...s,...r.end},n=s.line,l=s.column,d=o.line,c=o.column;let a=Math.max(n-(t+1),0),p=Math.min(e.length,d+i);n===-1&&(a=0),d===-1&&(p=e.length);const g=d-n,m={};if(g)for(let u=0;u<=g;u++){const $=u+n;if(!l)m[$]=!0;else if(u===0){const h=e[$-1]?.length;m[$]=[l,(h??0)-l+1]}else if(u===g)m[$]=[0,c];else{const h=e[$-u]?.length;m[$]=[0,h]}}else l===c?m[n]=l?[l,0]:!0:m[n]=[l,(c??0)-(l??0)];return{end:p,markerLines:m,start:a}},"getMarkerLines");var ue=Object.defineProperty,E=L((r,e)=>ue(r,"name",{value:e,configurable:!0}),"t");const fe=_.platform==="win32"&&!_.env?.WT_SESSION?">":"❯",me=E((r,e,t)=>{const i={linesAbove:2,linesBelow:3,prefix:"",showGutter:!0,tabWidth:4,...t,color:{gutter:E(u=>u,"gutter"),marker:E(u=>u,"marker"),message:E(u=>u,"message"),...t?.color}},s=typeof e.start.column=="number";let o=se(r).split(`
3
+ `);typeof i.tabWidth=="number"&&(o=o.map(u=>u.replaceAll(" "," ".repeat(i.tabWidth))));const{end:n,markerLines:l,start:d}=de(e,o,i.linesAbove,i.linesBelow),c=String(n).length,{gutter:a,marker:p,message:g}=i.color;let m=o.slice(d,n).map((u,$)=>{const h=d+1+$,k=l[h],D=` ${String(h)}`.slice(-c),U=!l[h+1],j=` ${D}${i.showGutter?" |":""}`;if(k){let O="";if(Array.isArray(k)){const H=u.replaceAll(/[^\t]/g," ").slice(0,Math.max(k[0]-1,0)),K=k[1]||1;O=[`
4
+ `,i.prefix+a(j.replaceAll(/\d/g," "))," ",H,p("^").repeat(K)].join(""),U&&i.message&&(O+=` ${g(i.message)}`)}return[i.prefix+p(fe),a(j),u.length>0?` ${u}`:"",O].join("")}return`${i.prefix} ${a(j)}${u.length>0?` ${u}`:""}`}).join(`
5
+ `);return i.message&&!s&&(m=`${i.prefix+" ".repeat(c+1)+i.message}
6
+ ${m}`),m},"codeFrame");var pe=Object.defineProperty,ve=N((r,e)=>pe(r,"name",{value:e,configurable:!0}),"x$1"),ge=Object.defineProperty,$e=ve((r,e)=>ge(r,"name",{value:e,configurable:!0}),"x"),he=Object.defineProperty,v=$e((r,e)=>he(r,"name",{value:e,configurable:!0}),"u");const b=v((r,...e)=>{process.env.DEBUG&&process.env.DEBUG==="true"&&console.debug(`error:parse-stacktrace: ${r}`,...e)},"debugLog"),y="<unknown>",be=/^.*?\s*at\s(?:(.+?\)(?:\s\[.+\])?|\(?.*?)\s?\((?:address\sat\s)?)?(?:async\s)?((?:<anonymous>|[-a-z]+:|.*bundle|\/)?.*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i,ye=/\((\S+)\),\s(<[^>]+>)?:(\d+)?:(\d+)?\)?/,xe=/(.*?):(\d+):(\d+)(?:\s<-\s.+:\d+:\d+)?/,we=/eval\sat\s(<anonymous>)\s\((.*)\)?:(\d+)?:(\d+)\),\s*<anonymous>?:(\d+)?:(\d+)/,Ne=/^\s*in\s(?:([^\\/]+(?:\s\[as\s\S+\])?)\s\(?)?\(at?\s?(.*?):(\d+)(?::(\d+))?\)?\s*$/,Se=/in\s(.*)\s\(at\s(.+)\)\sat/,ke=/^(?:.*@)?(.*):(\d+):(\d+)$/,Ee=/^\s*(.*?)(?:\((.*?)\))?(?:^|@)?((?:[-a-z]+)?:\/.*?|\[native code\]|[^@]*(?:bundle|\d+\.js)|\/[\w\-. \/=]+)(?::(\d+))?(?::(\d+))?\s*$/i,je=/(\S+) line (\d+)(?: > eval line \d+)* > eval/i,Oe=/(\S[^\s[]*\[.*\]|.*?)@(.*):(\d+):(\d+)/,T=/\(error: (.*)\)/,Le=/at\s/,Ae=/^(\S+):(\d+):(\d+)$|^(\S+):(\d+)$/,Me=/\S*(?:Error: |AggregateError:)/,C=/^Anonymous function$/,Pe=/^\s*in\s.*/,_e=/^.*?\s*at\s.*/,Te=/^.*?\s*@.*|\[native code\]/,B=v((r,e)=>{const t=r.includes("safari-extension"),i=r.includes("safari-web-extension");return t||i?[r.includes("@")?r.split("@")[0]:y,t?`safari-extension:${e}`:`safari-web-extension:${e}`]:[r,e]},"extractSafariExtensionDetails"),W=v((r,e)=>{const t=xe.exec(e);t&&(r.file=t[1],r.line=+t[2],r.column=+t[3])},"parseMapped"),Ce=v(r=>{const e=Se.exec(r);if(e){b(`parse nested node error stack line: "${r}"`,`found: ${JSON.stringify(e)}`);const i=e[2].split(":");return{column:i[2]?+i[2]:void 0,file:i[0],line:i[1]?+i[1]:void 0,methodName:e[1]??y,raw:r,type:void 0}}const t=Ne.exec(r);if(t){b(`parse node error stack line: "${r}"`,`found: ${JSON.stringify(t)}`);const i={column:t[4]?+t[4]:void 0,file:t[2]?t[2].replace(Le,""):void 0,line:t[3]?+t[3]:void 0,methodName:t[1]??y,raw:r,type:r.startsWith("internal")?"internal":void 0};return W(i,`${t[2]}:${t[3]}:${t[4]}`),i}},"parseNode"),Be=v(r=>{const e=be.exec(r);if(e){b(`parse chrome error stack line: "${r}"`,`found: ${JSON.stringify(e)}`);const t=e[2]?.startsWith("native"),i=e[2]?.startsWith("eval")||e[1]?.startsWith("eval");let s,o;if(i){const c=ye.exec(r);if(c){const a=Ae.exec(c[1]);a?(e[2]=a[4]??a[1],e[3]=a[5]??a[2],e[4]=a[3]):c[2]&&(e[2]=c[1]),c[2]&&(s={column:c[4]?+c[4]:void 0,file:c[2],line:c[3]?+c[3]:void 0,methodName:"eval",raw:r,type:"eval"})}else{const a=we.exec(r);a&&(o={column:a[4]?+a[4]:void 0,file:a[2],line:a[3]?+a[3]:void 0},s={column:a[6]?+a[6]:void 0,file:a[1],line:a[5]?+a[5]:void 0,methodName:"eval",raw:a[0],type:"eval"})}}const[n,l]=B(e[1]?e[1].replace(C,"<anonymous>"):y,e[2]),d={column:e[4]?+e[4]:void 0,evalOrigin:s,file:l,line:e[3]?+e[3]:void 0,methodName:n,raw:r,type:i?"eval":t?"native":void 0};return o?(d.column=o.column,d.file=o.file,d.line=o.line):W(d,`${l}:${e[3]}:${e[4]}`),d}},"parseChromium"),We=v((r,e)=>{const t=Ee.exec(r);if(t){b(`parse gecko error stack line: "${r}"`,`found: ${JSON.stringify(t)}`);const i=t[3]?.includes(" > eval"),s=i&&t[3]&&je.exec(t[3]);let o;i&&s&&(t[3]=s[1],o={column:t[5]?+t[5]:void 0,file:t[3],line:t[4]?+t[4]:void 0,methodName:"eval",raw:r,type:"eval"},t[4]=s[2]);const[n,l]=B(t[1]?t[1].replace(C,"<anonymous>"):y,t[3]);let d;(e?.type==="safari"||!i&&e?.type==="firefox")&&e.column?d=e.column:!i&&t[5]&&(d=+t[5]);let c;return(e?.type==="safari"||!i&&e?.type==="firefox")&&e.line?c=e.line:t[4]&&(c=+t[4]),{column:d,evalOrigin:o,file:l,line:c,methodName:n,raw:r,type:i?"eval":l.includes("[native code]")?"native":void 0}}},"parseGecko"),Ge=v((r,e)=>{const t=Oe.exec(r);if(!(t&&t[2].includes(" > eval"))&&t)return b(`parse firefox error stack line: "${r}"`,`found: ${JSON.stringify(t)}`),{column:t[4]?+t[4]:e?.column??void 0,file:t[2],line:t[3]?+t[3]:e?.line??void 0,methodName:t[1]||y,raw:r,type:void 0}},"parseFirefox"),Re=v(r=>{const e=ke.exec(r);if(e)return b(`parse react android native error stack line: "${r}"`,`found: ${JSON.stringify(e)}`),{column:e[3]?+e[3]:void 0,file:e[1],line:e[2]?+e[2]:void 0,methodName:y,raw:r,type:void 0}},"parseReactAndroidNative"),G=v((r,{filter:e,frameLimit:t=50}={})=>{const i=r;let s=(typeof i.stacktrace=="string"?i.stacktrace:r.stack??"").split(`
7
+ `).map(o=>(T.test(o)?o.replace(T,"$1"):o).trim()).filter(o=>!Me.test(o)&&o!=="eval code");return e&&(s=s.filter(o=>e(o))),s=s.slice(0,t),s.reduce((o,n,l)=>{if(!n||n.length>1024)return o;let d;if(Pe.test(n))d=Ce(n);else if(_e.test(n))d=Be(n);else if(Te.test(n)){let c;if(l===0){const a=r,p=a.columnNumber,g=a.lineNumber,m=a.line,u=a.column;p||g?c={column:p,line:g,type:"firefox"}:(m||u)&&(c={column:u,line:m,type:"safari"})}d=Ge(n,c)??We(n,c)}else d=Re(n);return d?o.push(d):b(`parse error stack line: "${n}"`,"not parser found"),o},[])},"parseStacktrace");var Ve=Object.defineProperty,Fe=N((r,e)=>Ve(r,"name",{value:e,configurable:!0}),"p"),Ie=Object.defineProperty,R=Fe((r,e)=>Ie(r,"name",{value:e,configurable:!0}),"m");const Je=ee(import.meta.url),x=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,A=R(r=>{if(typeof x<"u"&&x.versions&&x.versions.node){const[e,t]=x.versions.node.split(".").map(Number);if(e>22||e===22&&t>=3||e===20&&t>=16)return x.getBuiltinModule(r)}return Je(r)},"__cjs_getBuiltinModule"),{existsSync:qe,readFileSync:ze}=A("node:fs"),{relative:De}=A("node:path"),{cwd:Ue}=x,{fileURLToPath:He}=A("node:url");var Ke=Object.defineProperty,f=R((r,e)=>Ke(r,"name",{value:e,configurable:!0}),"o");const w=f((r,e,t)=>t===0?r:e===" "?r+" ".repeat(t):r+" ".repeat(e*t),"getPrefix"),Qe=f((r,e)=>{const t=r.replace("async file:","file:");return De(e,t.startsWith("file:")?He(t):t)},"getRelativePath"),Ye=f((r,e,t)=>{if(e)return t.title(r.message);const i=r.message?`: ${r.message}`:"";return t.title(r.name+i)},"getTitleText"),V=f((r,{color:e,hideErrorTitle:t,indentation:i,prefix:s},o)=>`${w(s,i,o)}${Ye(r,t,e)}
8
+ `,"getMessage"),F=f((r,{color:e,indentation:t,prefix:i},s)=>{if(r.hint===void 0)return;const o=w(i,t,s);let n="";if(Array.isArray(r.hint))for(const l of r.hint)n+=`${o+l}
9
+ `;else n+=o+r.hint;return e.hint(n)},"getHint"),M=f((r,{color:e,cwd:t,displayShortPath:i,indentation:s,prefix:o},n=0)=>{const l=i?Qe(r.file,t):r.file,{fileLine:d,method:c}=e;return`${w(o,s,n)}at ${r.methodName?`${c(r.methodName)} `:""}${d(l)}:${d(r.line?.toString()??"")}`},"getMainFrame"),I=f((r,{color:e,indentation:t,linesAbove:i,linesBelow:s,prefix:o,showGutter:n,showLineNumbers:l,tabWidth:d},c)=>{if(r.file===void 0)return;const a=r.file.replace("file://","");if(!qe(a))return;const p=ze(a,"utf8");return me(p,{start:{column:r.column,line:r.line}},{color:e,linesAbove:i,linesBelow:s,prefix:w(o,t,c),showGutter:n,showLineNumbers:l,tabWidth:d})},"getCode"),J=f((r,e,t)=>{if(r.errors.length===0)return;let i=`${w(e.prefix,e.indentation,t)}Errors:
10
+
11
+ `,s=!0;for(const o of r.errors)s?s=!1:i+=`
12
+
13
+ `,i+=z(o,{...e,framesMaxLimit:1,hideErrorCodeView:e.hideErrorErrorsCodeView},t+1);return`
14
+ ${i}`},"getErrors"),q=f((r,e,t)=>{let i=`${w(e.prefix,e.indentation,t)}Caused by:
15
+
16
+ `;const s=r.cause;i+=V(s,e,t);const o=G(s).shift(),n=F(s,e,t);if(n&&(i+=`${n}
17
+ `),o&&(i+=M(o,e,t),!e.hideErrorCauseCodeView)){const l=I(o,e,t);l!==void 0&&(i+=`
18
+ ${l}`)}if(s.cause)i+=`
19
+ ${q(s,e,t+1)}`;else if(s instanceof AggregateError){const l=J(s,e,t);l!==void 0&&(i+=`
20
+ ${l}`)}return`
21
+ ${i}`},"getCause"),Xe=f((r,e)=>(r.length>0?`
22
+ `:"")+r.map(t=>M(t,e)).join(`
23
+ `),"getStacktrace"),z=f((r,e,t)=>{const i={cwd:Ue(),displayShortPath:!1,filterStacktrace:void 0,framesMaxLimit:Number.POSITIVE_INFINITY,hideErrorCauseCodeView:!1,hideErrorCodeView:!1,hideErrorErrorsCodeView:!1,hideErrorTitle:!1,hideMessage:!1,indentation:4,linesAbove:2,linesBelow:3,prefix:"",showGutter:!0,showLineNumbers:!0,tabWidth:4,...e,color:{fileLine:f(n=>n,"fileLine"),gutter:f(n=>n,"gutter"),hint:f(n=>n,"hint"),marker:f(n=>n,"marker"),message:f(n=>n,"message"),method:f(n=>n,"method"),title:f(n=>n,"title"),...e.color}},s=G(r,{filter:e.filterStacktrace,frameLimit:i.framesMaxLimit}),o=s.shift();return[e.hideMessage?void 0:V(r,i,t),F(r,i,t),o?M(o,i,t):void 0,o&&!i.hideErrorCodeView?I(o,i,t):void 0,r instanceof AggregateError?J(r,i,t):void 0,r.cause===void 0?void 0:q(r,i,t),s.length>0?Xe(s,i):void 0].filter(Boolean).join(`
24
+ `).replaceAll("\\","/")},"internalRenderError"),rr=f((r,e={})=>{if(e.framesMaxLimit!==void 0&&e.framesMaxLimit<=0)throw new RangeError("The 'framesMaxLimit' option must be a positive number");return z(r,e,0)},"renderError");export{rr as G,me as N,G as Q,fe as k};
@@ -1,5 +1,5 @@
1
1
  import { O as Options$1 } from "../packem_shared/index.d-Br8HpP0A.js";
2
- import { P as Plugin } from "../packem_shared/plugin-manager.d-Dz-wu1tI.js";
2
+ import { P as Plugin } from "../packem_shared/plugin-manager.d-BSQtHbWS.js";
3
3
  import '@visulima/tabular';
4
4
  type ErrorHandlerOptions = {
5
5
  /** Show detailed error information including stack traces and code frames (default: false) */
@@ -1 +1 @@
1
- var u=Object.defineProperty;var n=(e,r)=>u(e,"name",{value:r,configurable:!0});import{G as h}from"../packem_shared/renderError-B_XyYPKJ-B65kP-Ou.js";import{e as p}from"../packem_shared/runtime-process-DKHFvYkv.js";var E=Object.defineProperty,a=n((e,r)=>E(e,"name",{value:r,configurable:!0}),"n");const P=a((e={})=>({description:"Enhanced error handling and reporting with beautiful code frames",name:"error-handler",onError:a((r,t)=>{const{logger:o,runtime:l}=t,{detailed:s=!1,exitOnError:d=!0,formatter:i,logErrors:f=!0,renderOptions:g={}}=e;if(f)if(i)o.error(i(r));else if(s){const c=l.getCwd(),m=h(r,{cwd:c,hideErrorCodeView:!1,hideErrorTitle:!1,hideMessage:!1,linesAbove:2,linesBelow:3,...g});o.error(m)}else o.error(r);d&&p(1)},"handleError"),version:"1.0.0"}),"errorHandlerPlugin");export{P as errorHandlerPlugin};
1
+ var u=Object.defineProperty;var n=(e,r)=>u(e,"name",{value:r,configurable:!0});import{G as h}from"../packem_shared/renderError-DxgI44AK-DFDWFoCr.js";import{e as p}from"../packem_shared/runtime-process-DKHFvYkv.js";var E=Object.defineProperty,a=n((e,r)=>E(e,"name",{value:r,configurable:!0}),"n");const P=a((e={})=>({description:"Enhanced error handling and reporting with beautiful code frames",name:"error-handler",onError:a((r,t)=>{const{logger:o,runtime:l}=t,{detailed:s=!1,exitOnError:d=!0,formatter:i,logErrors:f=!0,renderOptions:g={}}=e;if(f)if(i)o.error(i(r));else if(s){const c=l.getCwd(),m=h(r,{cwd:c,hideErrorCodeView:!1,hideErrorTitle:!1,hideMessage:!1,linesAbove:2,linesBelow:3,...g});o.error(m)}else o.error(r);d&&p(1)},"handleError"),version:"1.0.0"}),"errorHandlerPlugin");export{P as errorHandlerPlugin};
@@ -1,4 +1,4 @@
1
- import { P as Plugin } from "../packem_shared/plugin-manager.d-Dz-wu1tI.js";
1
+ import { P as Plugin } from "../packem_shared/plugin-manager.d-BSQtHbWS.js";
2
2
  import '@visulima/tabular';
3
3
  type RuntimeType = "bun" | "deno" | "node";
4
4
  type RuntimeVersionRequirement = {
@@ -1,4 +1,4 @@
1
- import { P as Plugin } from "../../packem_shared/plugin-manager.d-Dz-wu1tI.js";
1
+ import { P as Plugin } from "../../packem_shared/plugin-manager.d-BSQtHbWS.js";
2
2
  import '@visulima/tabular';
3
3
  type UpdateNotifierOptions = {
4
4
  alwaysRun?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@visulima/cerebro",
3
- "version": "3.0.0-alpha.26",
3
+ "version": "3.0.0-alpha.28",
4
4
  "description": "A delightful toolkit for building cross-runtime CLIs for Node.js, Deno, and Bun.",
5
5
  "keywords": [
6
6
  "ansi",
@@ -32,9 +32,7 @@
32
32
  "yargs"
33
33
  ],
34
34
  "homepage": "https://visulima.com/packages/cerebro",
35
- "bugs": {
36
- "url": "https://github.com/visulima/visulima/issues"
37
- },
35
+ "bugs": "https://github.com/visulima/visulima/issues",
38
36
  "repository": {
39
37
  "type": "git",
40
38
  "url": "git+https://github.com/visulima/visulima.git",
@@ -111,17 +109,16 @@
111
109
  "LICENSE.md"
112
110
  ],
113
111
  "dependencies": {
114
- "@visulima/colorize": "2.0.0-alpha.11",
115
- "@visulima/string": "3.0.0-alpha.13",
116
- "@visulima/tabular": "4.0.0-alpha.11",
112
+ "@visulima/colorize": "2.0.0-alpha.12",
113
+ "@visulima/tabular": "4.0.0-alpha.12",
117
114
  "fastest-levenshtein": "^1.0.16",
118
115
  "terminal-size": "^4.0.1"
119
116
  },
120
117
  "peerDependencies": {
121
118
  "@bomb.sh/tab": "0.0.15",
122
- "@visulima/boxen": "3.0.0-alpha.10",
123
- "@visulima/find-cache-dir": "3.0.0-alpha.9",
124
- "@visulima/pail": "4.0.0-alpha.16",
119
+ "@visulima/boxen": "3.0.0-alpha.11",
120
+ "@visulima/find-cache-dir": "3.0.0-alpha.10",
121
+ "@visulima/pail": "4.0.0-alpha.18",
125
122
  "github-slugger": "2.0.0"
126
123
  },
127
124
  "peerDependenciesMeta": {
@@ -1,4 +0,0 @@
1
- var ct=Object.defineProperty;var h=(t,e)=>ct(t,"name",{value:e,configurable:!0});import{VERBOSITY_DEBUG as B,POSITIONALS_KEY as Z,VERBOSITY_QUIET as ut,VERBOSITY_VERBOSE as dt,VERBOSITY_NORMAL as we}from"./VERBOSITY_QUIET-XPultrIA.js";import{c as b}from"./cerebro-error-BnJTixb2.js";import{d as z,h as pe,e as G,o as ye,a as mt,i as pt,f as ft}from"./runtime-process-DKHFvYkv.js";import{distance as ht}from"fastest-levenshtein";import De from"@visulima/string/case/camel-case";const Y=[{description:"Turn on verbose output",group:"global",name:"verbose",type:Boolean},{description:"Turn on debugging output",group:"global",name:"debug",type:Boolean},{alias:"h",description:"Print out helpful usage information",group:"global",name:"help",type:Boolean},{alias:"q",description:"Silence output",group:"global",name:"quiet",type:Boolean},{alias:"V",description:"Print version info",group:"global",name:"version",type:Boolean},{description:"Turn off colored output",group:"global",name:"no-color",type:Boolean},{description:"Force colored output",group:"global",name:"color",type:Boolean}];var gt=Object.defineProperty,vt=h((t,e)=>gt(t,"name",{value:e,configurable:!0}),"t$5");let T=class extends b{static{h(this,"a")}static{vt(this,"CommandNotFoundError")}commandName;constructor(e,n=[]){const o=`Command "${e}" not found${n.length>0?`. Did you mean: ${n.join(", ")}?`:""}`;super(o,"COMMAND_NOT_FOUND",{commandName:e,suggestions:n}),this.name="CommandNotFoundError",this.commandName=e,n.length>0&&(this.hint=`Try one of these commands: ${n.join(", ")}`)}};var wt=Object.defineProperty,yt=h((t,e)=>wt(t,"name",{value:e,configurable:!0}),"e$7");let Te=class extends b{static{h(this,"o")}static{yt(this,"ConflictingOptionsError")}option1;option2;constructor(e,n){super(`Options "${e}" and "${n}" cannot be used together`,"CONFLICTING_OPTIONS",{option1:e,option2:n}),this.name="ConflictingOptionsError",this.option1=e,this.option2=n,this.hint=`Remove either --${e} or --${n}`}};var bt=Object.defineProperty,$t=h((t,e)=>bt(t,"name",{value:e,configurable:!0}),"e$6");let Ot=class extends b{static{h(this,"o")}static{$t(this,"PluginError")}pluginName;constructor(e,n,o){super(`Plugin "${e}" error: ${n}`,"PLUGIN_ERROR",{originalError:o,pluginName:e}),this.name="PluginError",this.pluginName=e,o&&(this.cause=o)}};var Nt=Object.defineProperty,be=h((t,e)=>Nt(t,"name",{value:e,configurable:!0}),"d$4");let At=class{static{h(this,"p")}static{be(this,"PluginManager")}logger;plugins=new Map;initialized=!1;cachedDependencyOrder=void 0;constructor(e){this.logger=e}hasPlugins(){return this.plugins.size>0}register(e){if(this.initialized)throw new Error(`Cannot register plugin "${e.name}" after initialization`);if(this.plugins.has(e.name))throw new Error(`Plugin "${e.name}" is already registered`);z().CEREBRO_OUTPUT_LEVEL===String(B)&&this.logger.debug(`registering plugin: ${e.name}`),this.plugins.set(e.name,e),this.cachedDependencyOrder=void 0}async init(e){if(this.initialized)throw new Error("PluginManager already initialized");if(this.plugins.size===0){this.logger.debug("no plugins registered, skipping initialization"),this.initialized=!0;return}this.validateDependencies();const n=this.getDependencyOrder();this.logger.debug(`initializing ${String(n.length)} plugin(s)...`);for(const o of n)if(typeof o.init=="function"){this.logger.debug(`initializing plugin: ${o.name}`);try{await o.init(e)}catch(a){const i=new Ot(o.name,`Failed to initialize: ${a instanceof Error?a.message:String(a)}`,a instanceof Error?a:void 0);throw this.logger.error(i.message),i}}this.initialized=!0}async executeLifecycle(e,n,o){if(!this.initialized)throw new Error("PluginManager not initialized");if(this.plugins.size===0)return;const a=this.getDependencyOrder();for(const i of a){const u=i[e];if(typeof u=="function"){this.logger.debug(`executing ${e} hook for plugin: ${i.name}`);try{await(e==="afterCommand"?u(n,o):u(n))}catch(r){throw this.logger.error(`Error in ${e} hook for plugin "${i.name}":`,r),r}}}}async executeErrorHandlers(e,n){if(!this.initialized||this.plugins.size===0)return;const o=this.getDependencyOrder();for(const a of o)if(typeof a.onError=="function"){this.logger.debug(`executing error handler for plugin: ${a.name}`);try{await a.onError(e,n)}catch(i){this.logger.error(`Error in error handler for plugin "${a.name}":`,i)}}}getDependencyOrder(){if(this.cachedDependencyOrder!==void 0)return this.cachedDependencyOrder;const e=[],n=new Set,o=new Set,a=be(i=>{if(n.has(i))return;if(o.has(i))throw new Error(`Circular dependency detected involving plugin "${i}"`);const u=this.plugins.get(i);if(!u)throw new Error(`Plugin "${i}" not found`);if(o.add(i),u.dependencies)for(const r of u.dependencies)a(r);o.delete(i),n.add(i),e.push(u)},"visit");for(const i of this.plugins.keys())a(i);return this.cachedDependencyOrder=e,e}validateDependencies(){for(const e of this.plugins.values())if(e.dependencies){for(const n of e.dependencies)if(!this.plugins.has(n))throw new Error(`Plugin "${e.name}" depends on "${n}" which is not registered`)}}};var Pt=Object.defineProperty,Et=h((t,e)=>Pt(t,"name",{value:e,configurable:!0}),"n$8");const H=Et(t=>t.type?.name==="Boolean","optionIsBoolean");var _t=Object.defineProperty,Se=h((t,e)=>_t(t,"name",{value:e,configurable:!0}),"p$6");const Ct=Se(t=>{let e=t.type?t.type.name.toLowerCase():"string";const n=t.multiple??t.lazyMultiple?"[]":"";return e&&(e=e==="boolean"?"":`{underline ${e}${n}}`),e},"getTypeLabel"),$e=Se(t=>(H(t)||(t.typeLabel=t.typeLabel??Ct(t),t.defaultOption&&(t.typeLabel=`${t.typeLabel} (D)`),t.required&&(t.typeLabel=`${t.typeLabel} (R)`)),t),"mapOptionTypeLabel");var xt=Object.defineProperty,Ue=h((t,e)=>xt(t,"name",{value:e,configurable:!0}),"e$4");const It=new RegExp(/^-([^\d-])$/),kt=new RegExp(/^--(\S+)/),Lt=new RegExp(/^-([^\d-]{2,})$/),jt=Ue(t=>It.test(t)||kt.test(t)||Lt.test(t),"isOption"),Mt=Ue((t,e)=>{const n=e[0]&&jt(e[0])||e.length===0?null:e.shift()??null;if(!t.includes(n)){const o=new Error(`Command not recognised: ${String(n)}`);throw o.command=n,o.name="INVALID_COMMAND",o}return{argv:e,command:n}},"commandLineCommands");var Vt=Object.defineProperty,Be=h((t,e)=>Vt(t,"name",{value:e,configurable:!0}),"i$7"),Dt=Object.defineProperty,Re=Be((t,e)=>Dt(t,"name",{value:e,configurable:!0}),"i"),Tt=Object.defineProperty,ze=Re((t,e)=>Tt(t,"name",{value:e,configurable:!0}),"s"),St=Object.defineProperty,Fe=ze((t,e)=>St(t,"name",{value:e,configurable:!0}),"i"),Ut=Object.defineProperty,qe=Fe((t,e)=>Ut(t,"name",{value:e,configurable:!0}),"t");qe(t=>t instanceof Error&&t.type==="VisulimaError","isVisulimaError");class ee extends Error{static{h(this,"v")}static{Be(this,"g")}static{Re(this,"p")}static{ze(this,"V")}static{Fe(this,"VisulimaError")}static{qe(this,"VisulimaError")}loc;title;hint;type="VisulimaError";constructor({cause:e,hint:n,location:o,message:a,name:i,stack:u,title:r}){super(a,{cause:e}),this.title=r,this.name=i,this.stack=u??this.stack,this.loc=o,this.hint=n}setLocation(e){this.loc=e}setName(e){this.name=e}setMessage(e){this.message=e}setHint(e){this.hint=e}}var Bt=Object.defineProperty,We=h((t,e)=>Bt(t,"name",{value:e,configurable:!0}),"o$7"),Rt=Object.defineProperty,Ge=We((t,e)=>Rt(t,"name",{value:e,configurable:!0}),"o"),zt=Object.defineProperty,Ft=Ge((t,e)=>zt(t,"name",{value:e,configurable:!0}),"i");let qt=class He extends ee{static{h(this,"a")}static{We(this,"a")}static{Ge(this,"t")}static{Ft(this,"AlreadySetError")}optionName;constructor(e){super({cause:void 0,hint:`Remove the duplicate option '${e}' from your command line arguments.`,location:void 0,message:`Option '${e}' is already set`,name:"ALREADY_SET",stack:void 0,title:"Option Already Set"}),this.optionName=e,Object.setPrototypeOf(this,He.prototype)}};var Wt=Object.defineProperty,Ke=h((t,e)=>Wt(t,"name",{value:e,configurable:!0}),"t$3"),Gt=Object.defineProperty,Ye=Ke((t,e)=>Gt(t,"name",{value:e,configurable:!0}),"e"),Ht=Object.defineProperty,Kt=Ye((t,e)=>Ht(t,"name",{value:e,configurable:!0}),"e");let Oe=class Je extends ee{static{h(this,"n")}static{Ke(this,"n")}static{Ye(this,"o")}static{Kt(this,"UnknownOptionError")}optionName;constructor(e){super({cause:void 0,hint:`Check your option definitions or remove the unknown option '${e}' from your command line arguments.`,location:void 0,message:`Unknown option: --${e}`,name:"UNKNOWN_OPTION",stack:void 0,title:"Unknown Option"}),this.optionName=`--${e}`,Object.setPrototypeOf(this,Je.prototype)}};var Yt=Object.defineProperty,Ze=h((t,e)=>Yt(t,"name",{value:e,configurable:!0}),"a$9"),Jt=Object.defineProperty,Qe=Ze((t,e)=>Jt(t,"name",{value:e,configurable:!0}),"a"),Zt=Object.defineProperty,Qt=Qe((t,e)=>Zt(t,"name",{value:e,configurable:!0}),"o");let Xt=class Xe extends ee{static{h(this,"n")}static{Ze(this,"o")}static{Qe(this,"e")}static{Qt(this,"UnknownValueError")}value;constructor(e){super({hint:"Use a defined option or add a defaultOption to capture this value.",message:`Unknown value: ${e}`,name:"UNKNOWN_VALUE",title:"Unknown Value"}),this.value=e,Object.setPrototypeOf(this,Xe.prototype)}};var en=Object.defineProperty,et=h((t,e)=>en(t,"name",{value:e,configurable:!0}),"i$4"),tn=Object.defineProperty,tt=et((t,e)=>tn(t,"name",{value:e,configurable:!0}),"i"),nn=Object.defineProperty,on=tt((t,e)=>nn(t,"name",{value:e,configurable:!0}),"i");let E=class nt extends ee{static{h(this,"a")}static{et(this,"o")}static{tt(this,"e")}static{on(this,"InvalidDefinitionsError")}constructor(e,n){super({cause:void 0,hint:n,location:void 0,message:e,name:"INVALID_DEFINITIONS",stack:void 0,title:"Invalid Option Definition"}),Object.setPrototypeOf(this,nt.prototype)}};var an=Object.defineProperty,rn=h((t,e)=>an(t,"name",{value:e,configurable:!0}),"z"),sn=Object.defineProperty,F=rn((t,e)=>sn(t,"name",{value:e,configurable:!0}),"S"),ln=Object.defineProperty,te=F((t,e)=>ln(t,"name",{value:e,configurable:!0}),"o");const Ne=te(t=>t===Boolean||typeof t=="function"&&t.name.startsWith("Boolean"),"isBooleanType"),Ae=te(t=>t===Number||typeof t=="function"&&t.name==="Number","isNumberType"),Pe=te(t=>t===String||typeof t=="function"&&t.name==="String","isStringType"),cn=te((t,e)=>Array.isArray(t)?Ne(e)?t.map(Boolean):Ae(e)?t.map(Number):Pe(e)?t.map(String):t.map(n=>e(String(n))):t===null?null:Ne(e)?!!t:Ae(e)?Number(t):Pe(e)?typeof t=="string"?t:String(t):e(typeof t=="string"?t:String(t)),"convertValue");var un=Object.defineProperty,dn=F((t,e)=>un(t,"name",{value:e,configurable:!0}),"e");const P=dn((t,e,n,...o)=>{t&&console.debug(`[command-line-args:${n}] ${e}`,...o)},"debug");var mn=Object.defineProperty,V=F((t,e)=>mn(t,"name",{value:e,configurable:!0}),"h$1");const pn=/-([a-z])/g,fn=/^\d+$/,le=V(t=>t===Boolean||typeof t=="function"&&t.name.startsWith("Boolean"),"isBooleanType"),hn=V(t=>t.codePointAt(0)===95,"isSpecialKey"),Ee=V((t,e)=>Array.isArray(t)?[...t,...e]:[t,...e],"appendToArrayMultiple"),_e=V(t=>t==="__proto__"||t==="constructor"||t==="prototype","isUnsafeKey"),Ce=V((t,e,n,o=!1)=>{t[e]===void 0?t[e]=o?[n]:n:o&&Array.isArray(t[e])?t[e].push(n):t[e]=[t[e],n]},"createOrAppendArray"),gn=V((t,e,n,o,a)=>{let i=e.get(t)??n.get(t);if(!i&&o){const u=t.toLowerCase();i=o.get(u)??a?.get(u)}return i},"getDefinition"),vn=V((t,e,n,o)=>{const a=n.debug??!1;P(a,"resolveArgs called with options:","resolver",{partial:n.partial,stopAtFirstUnknown:n.stopAtFirstUnknown}),P(a,"Starting argument resolution","resolver"),P(a,"Tokens:","resolver",t),P(a,"Definitions:","resolver",e),P(a,"Processing tokens...","resolver");const i=new Map,u=new Map,r=n.caseInsensitive?new Map:void 0,m=n.caseInsensitive?new Map:void 0,s=n.camelCase?new Map:void 0,f=n.camelCase?new Map:void 0;for(const c of e)if(i.set(c.name,c),c.alias&&u.set(c.alias,c),n.caseInsensitive&&r&&(r.set(c.name.toLowerCase(),c),c.alias&&m&&m.set(c.alias.toLowerCase(),c)),n.camelCase&&s&&f){const l=c.name.replaceAll(pn,(d,p)=>p.toUpperCase());s.set(c.name,l),f.set(l,c.name)}const g={},v={},O=[],$=new Set;let L=!1;const N=e.find(c=>c.defaultOption),W=e.some(c=>c.group),x=e.some(c=>c.type===Number);for(let c=0;c<t.length;c++){const l=t[c];if(l.kind==="option-terminator"){g._unknown=o.slice(l.index),L=!0;break}if(l.kind==="option"&&l.name){let d=gn(l.name,i,u,r,m);if(!d&&l.value===void 0&&x&&fn.test(l.name)){const y=e.find(I=>I.type===Number);y&&(d=y,l.value=l.name,l.name=y.name)}const p=d?d.name:l.name,w=d?.multiple,A=d?.lazyMultiple;if(v[p]!==void 0&&!w&&!A&&!n.partial)throw new qt(p);if(!d&&n.partial){const y=l.rawName??`--${l.name}${l.value!==void 0&&l.inlineValue?`=${l.value}`:""}`;O.push({index:l.index,value:y});continue}if(!d&&n.stopAtFirstUnknown){g._unknown=o.slice(l.index);break}if(!d&&!n.partial)throw new Oe(l.name);if(l.value===void 0){const y=t[c+1],I=y?.kind==="option"&&!("name"in y)&&y.value!==void 0,_=y&&d&&!(d.type&&le(d.type))&&(y.kind==="positional"||I),lt=d&&d.defaultOption&&!d.multiple&&!d.lazyMultiple;if(_&&(!d?.defaultOption||lt))if(w){let k=c+1;const se=[];for(;k<t.length&&(t[k].kind==="positional"||t[k].kind==="option"&&!("name"in t[k])&&t[k].value!==void 0);)se.push(t[k].value),$.add(t[k].index),k++;v[p]=v[p]===void 0?se:Ee(v[p],se),c=k-1}else A?(Ce(v,p,y.value,!0),$.add(y.index),c++):(v[p]=y.value,$.add(y.index),c++);else d?.type&&le(d.type)?Ce(v,p,!0,w):v[p]=w?[]:null}else{let{value:y}=l;if(d?.type&&le(d.type))switch(y){case"":{if(n.partial)v._unknown??=[],v._unknown.push(`${l.rawName??`--${l.name}`}${l.value?`=${l.value}`:""}`),y=!0;else throw new Oe(l.name);break}case"false":{y=!1;break}case"true":{y=!0;break}default:y=!0}const I=[y];if(w){let _=c+1;for(;_<t.length&&t[_].kind==="positional";)I.push(t[_].value),$.add(t[_].index),_++;c=_-1}v[p]===void 0?v[p]=w||A?I:y:w||A?v[p]=Ee(v[p],I):v[p]=y}}else if(l.kind==="positional"&&n.stopAtFirstUnknown&&!$.has(l.index)&&!N){P(a,`Found unconsumed positional token at index ${String(l.index)}, stopping processing`,"resolver"),g._unknown=o.slice(l.index);break}}for(const[c,l]of Object.entries(v)){const d=i.get(c);d&&(d.multiple||d.lazyMultiple)&&!Array.isArray(l)&&(v[c]=[l])}let C=Number.POSITIVE_INFINITY;if(n.stopAtFirstUnknown&&!L){for(const c of t)if(c.kind==="option"&&!i.has(c.name??"")&&!u.has(c.name??"")&&(!n.caseInsensitive||!r?.has(c.name?.toLowerCase()??"")&&!m?.has(c.name?.toLowerCase()??""))){C=c.index;break}}if(N){const c=[],l=[];for(const d of t)d.kind==="positional"&&!$.has(d.index)&&d.index<C&&(c.push(d.value),l.push(d));if(c.length>0){const d=v[N.name],p=N.multiple??N.lazyMultiple;d===void 0?p?(l.forEach(w=>$.add(w.index)),v[N.name]=c):($.add(l[0].index),v[N.name]=c[0]):p&&(l.forEach(w=>$.add(w.index)),v[N.name]=Array.isArray(d)?[...c,...d]:[...c,d])}}if(!n.partial){for(const c of t)if(c.kind==="positional"&&!$.has(c.index))throw new Xt(o[c.index])}if(n.partial&&!n.stopAtFirstUnknown){const c=[...O];if(v._unknown){const l=new Map;for(const[d,p]of o.entries())l.set(p,d);for(const d of v._unknown){const p=l.get(d);p!==void 0&&c.push({index:p,value:d})}}for(const l of t)l.kind==="positional"&&!$.has(l.index)&&c.push({index:l.index,value:o[l.index]});c.length>0&&(c.sort((l,d)=>l.index-d.index),g._unknown=c.map(l=>l.value))}if(n.stopAtFirstUnknown&&!L){const c=t.findIndex(p=>p.kind==="option"&&!i.has(p.name??"")&&!u.has(p.name??"")&&(!n.caseInsensitive||!r?.has(p.name?.toLowerCase()??"")&&!m?.has(p.name?.toLowerCase()??""))),l=t.findIndex(p=>p.kind==="positional"&&!$.has(p.index));let d=-1;if(c!==-1&&l!==-1?d=Math.min(c,l):c!==-1?d=c:l!==-1&&(d=l),d>=0){const p=t[d].index;g._unknown=o.slice(p)}}else O.length>0&&!n.partial&&(g._unknown=O.map(c=>c.value));for(const[c,l]of Object.entries(v)){const d=n.camelCase?s?.get(c)??c:c,p=i.get(c);g[d]=p?.type?cn(l,p.type):l===void 0?null:l}for(const c of e){const l=n.camelCase?s?.get(c.name)??c.name:c.name;!(l in g)&&c.defaultValue!==void 0&&(c.multiple??c.lazyMultiple?g[l]=Array.isArray(c.defaultValue)?[...c.defaultValue]:[c.defaultValue]:g[l]=c.defaultValue)}if(W){const c={},l={},d={};for(const w of e)if(w.group){const A=Array.isArray(w.group)?w.group:[w.group];for(const y of A)_e(y)||(c[y]??={})}for(const w of Object.keys(g))if(!hn(w)){l[w]=g[w];let A=w;n.camelCase&&(A=f?.get(w)??w);const y=i.get(A);if(y?.group){const I=Array.isArray(y.group)?y.group:[y.group];for(const _ of I)_e(_)||c[_]&&(c[_][w]=g[w])}else d[w]=g[w]}const p={_all:l};for(const[w,A]of Object.entries(c))p[w]=A;Object.keys(d).length>0&&(p._none=d),g._unknown&&(p._unknown=g._unknown),Object.keys(g).forEach(w=>delete g[w]),Object.assign(g,p)}return P(a,"Final parsed result:","resolver",g),g},"resolveArgs");var wn=Object.defineProperty,D=F((t,e)=>wn(t,"name",{value:e,configurable:!0}),"l");const M="-".codePointAt(0),j="=",yn=j.codePointAt(0),bn="--",$n="-",On="--",it=D(t=>t.length>2&&t.startsWith(On),"hasLongOptionPrefix"),Nn=D(t=>it(t)&&!t.includes(j,3),"isLongOption"),An=D(t=>it(t)&&t.includes(j,3),"isLongOptionAndValue"),Pn=D(t=>t!==void 0&&t.length>0&&t.codePointAt(0)!==M,"hasOptionValue"),En=D(t=>{if(t.length!==2||t.codePointAt(0)!==M||t.codePointAt(1)===M)return!1;const e=t.codePointAt(1);return e!==void 0&&(e<48||e>57)},"isShortOption"),_n=D(t=>!(t.length<=2||t.codePointAt(0)!==M||t.codePointAt(1)===M),"isShortOptionGroup"),Cn=D(t=>{const e=[],n=[...t];let o=-1,a=0;for(;n.length>0;){const i=n.shift();if(i===void 0)break;const u=n[0];if(a>0?a--:o++,i===bn){e.push({index:o,kind:"option-terminator"});const r=n.map((m,s)=>({index:o+s+1,kind:"positional",value:m}));e.push(...r),o+=n.length;break}if(En(i)){const r=i.charAt(1);let m;a?(e.push({index:o,kind:"option",name:r,rawName:i,value:m}),a===1&&Pn(u)&&(m=n.shift(),e.push({index:o,kind:"option",value:m}))):e.push({index:o,kind:"option",name:r,rawName:i,value:m}),m!==void 0&&++o;continue}if(_n(i)&&!i.includes(j)){const r=[];let m="",s=!1;for(let f=1;f<i.length;f++){const g=i.charAt(f);s?m+=g:g.codePointAt(0)===yn?s=!0:r.push(`${$n}${g}`)}if(s)if(r.length>0){const f=r.pop();r.push(`${f}=${m}`)}else r.push(m);n.unshift(...r),a=r.length;continue}if(Nn(i)){const r=i.slice(2);e.push({index:o,kind:"option",name:r,rawName:i});continue}if(An(i)){const r=i.indexOf(j),m=i.slice(2,r),s=i.slice(r+1);e.push({index:o,inlineValue:!0,kind:"option",name:m,rawName:i,value:s});continue}if(i.length>2&&i.codePointAt(0)===M&&i.codePointAt(1)!==M&&i.includes(j)){const r=i.indexOf(j),m=i.charAt(1),s=i.slice(r+1);e.push({index:o,inlineValue:!0,kind:"option",name:m,rawName:i,value:s});continue}e.push({index:o,kind:"positional",value:i})}return e},"parseArgsTokens");var xn=Object.defineProperty,he=F((t,e)=>xn(t,"name",{value:e,configurable:!0}),"d");const In=/\d/,kn=he(t=>t!=null&&(t===Boolean||typeof t=="function"&&t.name.startsWith("Boolean")),"isBooleanType"),Ln=he(t=>typeof t=="function","isValidCustomTypeFunction"),jn=he((t,e,n)=>{const o=n?.debug??!1;P(o,"Validating definitions:","validation",t,"caseInsensitive:",e);const a=new Set,i=new Set,u=new Set,r=new Set;let m=0;for(const s of t){if(P(o,"Checking definition:","validation",s),!s.name)throw P(o,"Validation failed: name is required","validation"),new E("Invalid option definition: name is required");if(typeof s.name!="string")throw new E("Invalid option definition: name must be a string");if(s.name.trim()==="")throw new E("Invalid option definition: name cannot be empty");const f=e?s.name.toLowerCase():"";if(a.has(s.name)||e&&u.has(f))throw new E(`Invalid option definition: duplicate name '${s.name}'`);if(i.has(s.name)||e&&r.has(f))throw new E(`Invalid option definition: name '${s.name}' conflicts with an existing alias`);if(a.add(s.name),e&&u.add(f),s.alias!==void 0){if(typeof s.alias!="string")throw new E("Invalid option definition: alias must be a string");if(s.alias.length!==1)throw new E("Invalid option definition: alias must be a single character");if(In.test(s.alias))throw new E("Invalid option definition: alias cannot be numeric");if(s.alias==="-")throw new E('Invalid option definition: alias cannot be "-"');const g=e?s.alias.toLowerCase():"";if(i.has(s.alias)||e&&r.has(g))throw new E(`Invalid option definition: duplicate alias '${s.alias}'`);if(a.has(s.alias)||e&&u.has(g))throw new E(`Invalid option definition: alias '${s.alias}' conflicts with an existing option name`);i.add(s.alias),e&&r.add(g)}if(s.defaultOption&&(m++,s.type!==void 0&&kn(s.type)))throw new E("Invalid option definition: defaultOption cannot be Boolean type");if(s.type!==void 0&&!(s.type===Boolean||s.type===Number||s.type===String||typeof s.type=="function"&&Ln(s.type)))throw new E("Invalid option definition: invalid type")}if(m>1)throw P(o,"Validation failed: multiple defaultOptions not allowed","validation"),new E("Invalid option definition: multiple defaultOptions not allowed");P(o,"Validation completed successfully","validation")},"validateDefinitions");var Mn=Object.defineProperty,Vn=F((t,e)=>Mn(t,"name",{value:e,configurable:!0}),"O");const Dn=Vn((t,e={})=>{const n=e.debug??!1;P(n,"Starting command-line-args parsing","index"),P(n,"Options:","index",e);const o={...e};o.stopAtFirstUnknown&&(o.partial=!0);const a=Array.isArray(t)?t:[t];P(n,"Normalized definitions:","index",a),jn(a,o.caseInsensitive,n?o:void 0);let{argv:i}=o;if(!i&&(i=process.argv.slice(2),process.execArgv.length>0)){const s=new Set(process.execArgv);i=i.filter(f=>!s.has(f))}P(n,"Using argv:","index",i);let u=i;o.caseInsensitive&&(u=i.map(s=>{if(s.startsWith("--")){const f=s.indexOf("="),g=(f===-1?s.slice(2):s.slice(2,f)).toLowerCase();return f===-1?`--${g}`:`--${g}${s.slice(f)}`}if(s.startsWith("-")&&!s.startsWith("--")&&s.length>1){const f=s.slice(1).split("=",2),g=f[0],v=f[1];if(!g)return s;const O=g.toLowerCase();return v===void 0?`-${O}`:`-${O}=${v}`}return s}));const r=Cn(u.map(String));P(n,"Tokenized arguments:","index",r);const m=vn(r,a,o,i);return P(n,"Command-line-args parsing completed","index"),m},"commandLineArgs");var Tn=Object.defineProperty,Sn=h((t,e)=>Tn(t,"name",{value:e,configurable:!0}),"n$4");let Un=class{static{h(this,"a")}static{Sn(this,"EmptyToolbox")}result;argv;options;argument;command;commandName;env;logger;runtime;rawUnknown;constructor(e,n){this.commandName=e,this.command=n}};var Bn=Object.defineProperty,Rn=h((t,e)=>Bn(t,"name",{value:e,configurable:!0}),"n$3");let ce=class extends b{static{h(this,"i")}static{Rn(this,"CommandLoaderError")}commandName;constructor(e,n,o){super(`Failed to load command "${e}": ${n}`,"COMMAND_LOADER_ERROR",{commandName:e,reason:n}),this.name="CommandLoaderError",this.commandName=e,this.hint="Ensure the loader resolves to a module with a default export that is the command handler function.",o!==void 0&&(this.cause=o)}};var zn=Object.defineProperty,Fn=h((t,e)=>zn(t,"name",{value:e,configurable:!0}),"f$3");const qn=/^-{1,2}(\w+)(=(.+))?$/,ot=Fn((t,e,n,o)=>{const a=qn.exec(t);if(a===null)return{};const i=a[1];if(!i)return{};const u=n&&o?n.get(i)??o.get(i):e.find(r=>r.name===i||r.alias===i);return u!==void 0?{argName:u.name,argValue:a[3],option:u}:{}},"getParameterOption");var Wn=Object.defineProperty,fe=h((t,e)=>Wn(t,"name",{value:e,configurable:!0}),"e$3");const xe=fe((t,e)=>{if(e.type===void 0)return t;if(e.type.name==="Boolean"){if(t==="true"||t==="1")return e.type(!0);if(t==="false"||t==="0")return e.type(!1)}return e.type(t)},"convertType"),Gn=new Set(["0","1","false","true"]),Hn=fe((t,e,n,o)=>{if(e.length===0||t.length===0)return{};const a=fe((i,u)=>{const{argName:r,argValue:m,option:s}=ot(u,e,n,o),{lastOption:f}=i;return s&&H(s)&&m&&r?i.partial[r]=xe(m,s):i.lastName&&f&&H(f)&&Gn.has(u)&&(i.partial[i.lastName]=xe(u,f)),{lastName:r,lastOption:s,partial:i.partial}},"getBooleanValue");return t.reduce(a,{partial:{}}).partial},"getBooleanValues");var Kn=Object.defineProperty,Ie=h((t,e)=>Kn(t,"name",{value:e,configurable:!0}),"s$6");const Yn=new Set(["0","1","false","true"]),Jn=Ie((t,e,n,o)=>{if(e.length===0||t.length===0)return t;const a=Ie((i,u)=>{const{argValue:r,option:m}=ot(u,e,n,o),{lastOption:s}=i;if(s&&H(s)&&Yn.has(u)){const{args:f}=i;return{args:f.slice(0,-1)}}return m&&H(m)&&r?{args:i.args}:{args:[...i.args,u],lastOption:m}},"removeBooleanArguments");return t.reduce(a,{args:[]}).args},"removeBooleanValues");var Zn=Object.defineProperty,Qn=h((t,e)=>Zn(t,"name",{value:e,configurable:!0}),"o$4");const ke=Qn(t=>{const e=new Map;for(const n of t){const o=e.get(n.name);o?e.set(n.name,{...o,...n}):e.set(n.name,n)}return[...e.values()]},"mergeArguments");var Xn=Object.defineProperty,ne=h((t,e)=>Xn(t,"name",{value:e,configurable:!0}),"o$3");const ei=ne(t=>{if(t===void 0)return;const e=t.toLowerCase().trim();return e==="true"||e==="1"||e==="yes"||e==="on"},"transformBooleanEnv"),ti=ne((t,e)=>{if(!t.type)return e;if(e!==void 0){if(t.type===Boolean||typeof t.type=="function"&&t.type.name==="Boolean")return ei(e);if(t.type===Number||typeof t.type=="function"&&t.type.name==="Number"){const n=Number.parseFloat(e);return Number.isNaN(n)?void 0:n}return t.type===String||typeof t.type=="function"&&t.type.name==="String"?e:t.type(e)}},"transformEnvValue"),ni=/_./g,ii=/^[A-Z]/,oi=ne(t=>t.toLowerCase().replaceAll(ni,e=>e[1]?.toUpperCase()??e).replace(ii,e=>e.toLowerCase()),"toCamelCase"),ai=ne(t=>{if(!t||t.length===0)return{};const e={},n=z();for(const o of t){const a=n[o.name],i=ti(o,a),u=i===void 0?o.defaultValue:i,r=oi(o.name);e[r]=u}return e},"processEnvVariables");var ri=Object.defineProperty,K=h((t,e)=>ri(t,"name",{value:e,configurable:!0}),"a$4");const si=K(t=>{const e=new Map,n=new Map;for(const o of t)if(e.set(o.name,o),o.alias){const a=Array.isArray(o.alias)?o.alias:[o.alias];for(const i of a)n.set(i,o)}return{optionMapByAlias:n,optionMapByName:e}},"buildOptionMaps"),li=K(async t=>{if(typeof t.__resolvedExecute__=="function")return t.__resolvedExecute__;if(typeof t.loader!="function")throw new ce(t.name,"no execute or loader defined");let e;try{e=await t.loader()}catch(o){throw new ce(t.name,o instanceof Error?o.message:String(o),o)}const n=e.default;if(typeof n!="function")throw new ce(t.name,"loader did not return a module with a default-exported handler function");return t.__resolvedExecute__=n,n},"loadLazyHandler"),ci=K((t,e,n,o)=>{const a=new Un(t.name,t),{_all:i,_unknown:u,positionals:r}=e,m=Object.keys(n).length>0?{...i,...n}:i;Z in m&&delete m[Z],a.argument=r?.[Z]??[],a.rawUnknown=[...u??[]];const s=Object.keys(o).length>0;return a.options=s?{...m,...o}:m,a.env=ai(t.env),a},"prepareToolbox"),ui=K((t,e,n)=>{const o=t.options??[],a=o.length>0;let i=ke(a?[...o,...n]:n);if(i.length>0){for(const s of i)if(s.multiple&&s.lazyMultiple)throw new Error(`Argument "${s.name}" cannot have both multiple and lazyMultiple options, please choose one.`)}t.argument&&(i=[{defaultOption:!0,description:t.argument.description,group:"positionals",multiple:!0,name:Z,type:t.argument.type,typeLabel:t.argument.typeLabel},...i]);let u,r;if(a){const{optionMapByAlias:s,optionMapByName:f}=si(o);u=Jn(e,o,f,s),r=Hn(e,o,f,s)}else u=e,r={};const m=Dn(i,{argv:u,camelCase:!0,partial:!0,stopAtFirstUnknown:!0});return{arguments_:i,booleanValues:r,parsedArgs:m}},"processCommandArgs"),S=K(async(t,e,n)=>typeof t.execute=="function"?t.execute(e):(await li(t))(e),"executeCommand");var di=Object.defineProperty,mi=h((t,e)=>di(t,"name",{value:e,configurable:!0}),"n$2");let pi=class extends b{static{h(this,"s")}static{mi(this,"CommandValidationError")}commandName;missingOptions;constructor(e,n){super(`Command "${e}" is missing required options: ${n.join(", ")}`,"COMMAND_VALIDATION_ERROR",{commandName:e,missingOptions:n}),this.name="CommandValidationError",this.commandName=e,this.missingOptions=n,this.hint=`Provide the following required options: ${n.join(", ")}`}};var fi=Object.defineProperty,hi=h((t,e)=>fi(t,"name",{value:e,configurable:!0}),"t$1");const Le=hi((t,e,n=!1)=>{const o=[];for(const a of t)if(!(!n&&!a.required)&&e[a.name]===void 0){if(a.type?.name==="Boolean"){e[a.name]=!1;continue}o.push(a)}return o},"listMissingArguments");var gi=Object.defineProperty,at=h((t,e)=>gi(t,"name",{value:e,configurable:!0}),"n$1");const vi=at((t,e)=>e.includes(t)?!0:Math.abs(t.length-e.length)>t.length/2?!1:ht(t,e)<=t.length/3,"isSimilar"),R=at((t,e)=>{const n=t.toLowerCase();return e.filter(o=>vi(o.toLowerCase(),n))},"findAlternatives");var wi=Object.defineProperty,ie=h((t,e)=>wi(t,"name",{value:e,configurable:!0}),"a$3");const yi=ie((t,e)=>{const n=[];if(t._unknown&&t._unknown.forEach(o=>{const a=o.startsWith("--");let i=`Found unknown ${a?"option":"argument"} "${o}"`;if(a){const u=R(o.replace("--",""),(e.options??[]).map(r=>r.name));if(u.length>0){const[r,...m]=u.map(s=>`--${s}`);i+=m.length>0?`, did you mean ${r??""} or ${m.join(", ")}?`:`, did you mean ${r??""}?`}}n.push(i)}),n.length>0)throw new Error(n.join(`
2
- `))},"validateUnknownOptions"),bi=ie((t,e,n)=>{const o=n.__requiredOptions__,a=o?Le(o,e,!0):Le(t,e,!1);if(a.length>0)throw new pi(n.name,a.map(i=>i.name));e._unknown&&e._unknown.length>0&&!n.argument&&yi(e,n)},"validateRequiredOptions"),$i=ie((t,e,n)=>{const o=n.__conflictingOptions__??t.filter(a=>a.conflicts!==void 0);if(o.length>0){const a=o.find(i=>Array.isArray(i.conflicts)?i.conflicts.some(u=>e[u]!==void 0)&&e[i.name]!==void 0:e[i.conflicts]!==void 0&&e[i.name]!==void 0);if(a)throw new Te(a.name,typeof a.conflicts=="string"?a.conflicts:a.conflicts?.[0]??"unknown")}},"validateConflictingOptions"),Oi=ie(t=>{if(!Array.isArray(t.options))return;const e=new Map,n=new Map;for(const a of t.options){if(a.name){const i=e.get(a.name)??[];i.push(a),e.set(a.name,i)}if(typeof a.alias=="string"&&a.alias.length>0){const i=n.get(a.alias)??[];i.push(a),n.set(a.alias,i)}else if(Array.isArray(a.alias)){for(const i of a.alias)if(i.length>0){const u=n.get(i)??[];u.push(a),n.set(i,u)}}}const o=[];for(const[a,i]of e)i.length>1&&o.push(`Duplicate option name "${a}" in command "${t.name}": ${JSON.stringify(i)}`);for(const[a,i]of n)i.length>1&&o.push(`Duplicate option alias "-${a}" used by options ${i.map(u=>`"${u.name}"`).join(", ")} in command "${t.name}"`);if(o.length>0)throw new Error(o.join(`
3
- `))},"validateDuplicateOptions");var Ni=Object.defineProperty,ge=h((t,e)=>Ni(t,"name",{value:e,configurable:!0}),"s$2");const Ai=ge((t,e)=>{if(e.length===0)return{argv:[],commandPath:void 0};const n=[];let o;for(let a=1;a<=e.length;a+=1){const i=e[a-1];if(i===void 0||i.startsWith("-"))break;n.push(i);const u=n.join(" ");t.has(u)&&(o={commandPath:[...n],depth:a})}return o?{argv:e.slice(o.depth),commandPath:o.commandPath}:{argv:e,commandPath:void 0}},"parseNestedCommand"),U=ge(t=>t.join(" "),"getCommandPathKey"),je=ge((t,e)=>e&&e.length>0?[...e,t]:[t],"getFullCommandPath");var Pi=Object.defineProperty,oe=h((t,e)=>Pi(t,"name",{value:e,configurable:!0}),"a$2");const Ei=oe(t=>{t.options?.forEach(e=>{e.__camelCaseName__=De(e.name)})},"processOptionNames"),_i=oe(t=>{if(!Array.isArray(t.options)||t.options.length===0)return;const e=new Set;for(const o of t.options)e.add(o.name);const n=[];for(const o of t.options)if(o.name.startsWith("no-")){const a=o.name.replace("no-","");if(!e.has(a)){if(o.type!==Boolean)throw new Error(`Cannot add negated option "${o.name}" to command "${t.name}" because it is not a boolean.`);const i={...o,defaultValue:o.defaultValue===void 0?!0:!o.defaultValue,name:a};n.push(i),e.add(a)}}n.length>0&&t.options.push(...n)},"addNegatableOptions"),Ci=oe((t,e)=>{if(!e.options||e.options.length===0)return;const{options:n}=t,o=new Map;for(const i of e.options)if(i.name.startsWith("no-")){const u=De(i.name);o.set(u,i)}const a=Object.keys(n).filter(i=>o.has(i));if(a.length!==0)for(const i of a){const u=i.charAt(2);if(!u)continue;const r=u.toLowerCase()+i.slice(3),m=o.get(i);m&&(m.__negated__=!0),n[r]=!n[i],Reflect.deleteProperty(n,i)}},"mapNegatableOptions"),xi=oe((t,e)=>{if(!e.options||e.options.length===0)return;const n=new Map;for(const a of e.options)a.__camelCaseName__&&a.__negated__===void 0&&a.implies!==void 0&&n.set(a.__camelCaseName__,a);if(n.size===0)return;const{options:o}=t;for(const a of Object.keys(o)){const i=n.get(a);if(i?.implies){const{implies:u}=i;for(const[r,m]of Object.entries(u))o[r]===void 0&&(o[r]=m)}}},"mapImpliedOptions");var Ii=Object.defineProperty,ae=h((t,e)=>Ii(t,"name",{value:e,configurable:!0}),"e$2");const ki=ae(()=>!!process.versions.electron,"isElectronApp"),Li=ae(()=>ki()&&!process.defaultApp,"isBundledElectronApp"),ji=ae(()=>Li()?0:1,"getProcessArgvBinIndex"),Mi=ae(t=>t.slice(ji()+1),"hideBin");var Vi=Object.defineProperty,rt=h((t,e)=>Vi(t,"name",{value:e,configurable:!0}),"e$1");const Di=" ",Ti=rt((t,e)=>t===e?!0:t.length!==e.length?!1:t.every((n,o)=>n===e[o]),"equals"),Si=rt(t=>{if(typeof t=="string")return t.split(Di);const e=pe();return Ti(t,e)?Mi(t):t},"parseRawCommand");var Ui=Object.defineProperty,ue=h((t,e)=>Ui(t,"name",{value:e,configurable:!0}),"r");const Bi=ue(t=>{const e=ue(i=>{t.error(`Uncaught exception: ${i.message||i}`),i.stack&&t.error(i.stack),G(1)},"uncaughtExceptionHandler"),n=ue((i,u)=>{if(i instanceof Error)t.error(`Promise rejection: ${i.message||i}`),i.stack&&t.error(i.stack);else{let r;if(typeof i=="string")r=i;else try{r=JSON.stringify(i)}catch{r=String(i)}t.error(`Promise rejection: ${r}`)}G(1)},"unhandledRejectionHandler"),o=ye("uncaughtException",e),a=ye("unhandledRejection",n);return()=>{o(),a()}},"registerExceptionHandler");var Ri=Object.defineProperty,q=h((t,e)=>Ri(t,"name",{value:e,configurable:!0}),"e");const X=100,st=/^[a-z][\w-]*$/i,ve=q((t,e)=>{if(typeof t!="string"||t.trim().length===0)throw new b(`${e} must be a non-empty string`,"INVALID_INPUT",{fieldName:e,value:t});return t.trim()},"validateNonEmptyString"),Me=q((t,e)=>{if(!Array.isArray(t)||!t.every(n=>typeof n=="string"))throw new b(`${e} must be an array of strings`,"INVALID_INPUT",{fieldName:e,value:t});return t},"validateStringArray");q((t,e)=>{if(typeof t!="function")throw new b(`${e} must be a function`,"INVALID_INPUT",{fieldName:e,value:t});return t},"validateFunction");const de=q((t,e)=>{if(typeof t!="object"||t===null)throw new b(`${e} must be an object`,"INVALID_INPUT",{fieldName:e,value:t});return t},"validateObject"),J=q(t=>{const e=ve(t,"Command name");if(e.length>X)throw new b(`Command name is too long (maximum ${String(X)} characters)`,"INVALID_COMMAND_NAME",{commandName:e,length:e.length});if(e.includes("..")||e.includes("/")||e.includes("\\")||e.includes(";")||e.includes("|")||e.includes("&"))throw new b(`Command name "${e}" contains invalid characters`,"INVALID_COMMAND_NAME",{commandName:e});if(!st.test(e))throw new b(`Command name "${e}" must start with a letter and contain only letters, numbers, hyphens, and underscores`,"INVALID_COMMAND_NAME",{commandName:e});return e},"validateCommandName");q(t=>{const e=ve(t,"Plugin name");if(e.length>X)throw new b(`Plugin name is too long (maximum ${String(X)} characters)`,"INVALID_PLUGIN_NAME",{length:e.length,pluginName:e});if(e.includes("..")||e.includes("/")||e.includes("\\")||e.includes(";")||e.includes("|")||e.includes("&"))throw new b(`Plugin name "${e}" contains invalid characters`,"INVALID_PLUGIN_NAME",{pluginName:e});if(!st.test(e))throw new b(`Plugin name "${e}" must start with a letter and contain only letters, numbers, hyphens, and underscores`,"INVALID_PLUGIN_NAME",{pluginName:e});return e},"validatePluginName");var zi=Object.defineProperty,re=h((t,e)=>zi(t,"name",{value:e,configurable:!0}),"s");const Fi=new Set([`
4
- `,"\r"," ","\0",'"',"$","&","'","(",")",";","<",">","[","\\","]","`","{","|","}"]),qi=/^[A-Z]:/i,Wi=re(t=>{if(typeof t!="string")throw new TypeError("Argument must be a string");if(t.length>1e4)throw new Error(`Argument is too long (maximum ${String(1e4)} characters)`);for(const e of t)if(Fi.has(e))throw new Error(`Argument contains dangerous character: ${e}`);return t.trim()},"sanitizeArgument"),Ve=re(t=>{if(!Array.isArray(t))throw new TypeError("Arguments must be an array");if(t.length>100)throw new Error(`Too many arguments (maximum ${String(100)})`);return t.map(e=>Wi(e))},"sanitizeArguments");re(t=>{if(typeof t!="string")throw new TypeError("Path must be a string");const e=t.trim();if(e.includes("..")||e.includes("../")||e.includes("..\\"))throw new Error("Path contains directory traversal sequences");if(e.startsWith("/")||qi.test(e))throw new Error("Absolute paths are not allowed");if(e.length>1e3)throw new Error("Path is too long");return e},"validateSafePath");class co{static{h(this,"RateLimiter")}static{re(this,"RateLimiter")}attempts=new Map;maxAttempts;windowMs;constructor(e=5,n=6e4){if(e<=0||n<=0)throw new Error("maxAttempts and windowMs must be positive numbers");this.maxAttempts=e,this.windowMs=n}checkLimit(e){const n=Date.now(),o=this.attempts.get(e);return!o||n>o.resetTime?(this.attempts.set(e,{count:1,resetTime:n+this.windowMs}),this.cleanup(n),!0):o.count>=this.maxAttempts?!1:(o.count+=1,!0)}reset(e){this.attempts.delete(e)}cleanup(e){for(const[n,o]of this.attempts.entries())e>o.resetTime&&this.attempts.delete(n)}}var Gi=Object.defineProperty,Q=h((t,e)=>Gi(t,"name",{value:e,configurable:!0}),"A");const Hi=/^-([^\d-])$/,Ki=/^--(\S+)/,Yi=/^-([^\d-]{2,})$/,me=Q(t=>Hi.test(t)||Ki.test(t)||Yi.test(t),"isOption");class uo{static{h(this,"Cli")}static{Q(this,"Cli")}#t;#e;#a;#c;#v;#u;#w;#r;#n;#i;#d;#s;#l;#m=!1;#y;#b=!1;#p;#f;#h;#g=[];#P(){return this.#p===void 0&&(this.#p=[...this.#i.keys()]),this.#p}#$(){return this.#f===void 0&&(this.#f=[...this.#n.keys()]),this.#f}#o(){return this.#h===void 0&&(this.#h=[...this.#P(),...this.#$()]),this.#h}#O(){return this.#g.length===0?Y:[...Y,...this.#g]}#E(){this.#p=void 0,this.#f=void 0,this.#h=void 0}#N(){if(this.#a===void 0){const e=Si(this.#e.argv);this.#a=Ve(e),this.#_()}return this.#a}#_(){if(!this.#a)return;const e=z();let n=!1;for(const o of this.#a){if(o==="--quiet"||o==="-q"){e.CEREBRO_OUTPUT_LEVEL=String(ut),n=!0;break}if(o==="--verbose"||o==="-v"){e.CEREBRO_OUTPUT_LEVEL=String(dt),n=!0;break}if(o==="--debug"||o==="-vvv"){e.CEREBRO_OUTPUT_LEVEL=String(B),n=!0;break}}n||(e.CEREBRO_OUTPUT_LEVEL=Object.hasOwn(e,"DEBUG")?String(B):String(we))}#C(){this.#b||(this.#y=Bi(this.#t),this.#b=!0)}#A(e,n,o,a){this.#t.debug(`command '${a}' found, parsing command args: ${n.join(", ")}`);const{arguments_:i,booleanValues:u,parsedArgs:r}=ui(e,n,this.#O()),m=Object.keys(u).length>0;let s=r;m&&(s={...r,_all:{...r._all,...u}}),bi(i,s,e);const f=ci(e,r,u,o);f.runtime=this,f.argv=this.#N();const g=e.options&&e.options.length>0;if(g&&e.options){const v=e.options.filter(O=>O.name.startsWith("no-"));for(const O of v){const $=O.name.replace("no-",""),L=`--${O.name}`,N=`--${$}`,W=n.includes(L),x=n.includes(N);if(W&&x)throw new Te($,O.name)}}return g&&(Ci(f,e),xi(f,e)),$i(i,f.options,e),z().CEREBRO_OUTPUT_LEVEL===String(B)&&(this.#t.debug("command options parsed from options:"),this.#t.debug(JSON.stringify(f.options,null,2)),this.#t.debug("command argument parsed from argument:"),this.#t.debug(JSON.stringify(f.argument,null,2))),{arguments_:i,booleanValues:u,commandArgs:s,parsedArgs:r,toolbox:f}}constructor(e,n={}){if(typeof e!="string"||e.trim().length===0)throw new b("CLI name must be a non-empty string","INVALID_INPUT",{cliName:e});this.#v=e.trim();const o=n.argv??pe(),a=n.cwd??mt();if(this.#e={...n,argv:o,cwd:a},this.#e.argv&&!Array.isArray(this.#e.argv))throw new b("CLI argv option must be an array of strings","INVALID_INPUT",{argv:this.#e.argv});if(this.#e.cwd&&typeof this.#e.cwd!="string")throw new b("CLI cwd option must be a string","INVALID_INPUT",{cwd:this.#e.cwd});if(this.#e.packageName&&typeof this.#e.packageName!="string")throw new b("CLI packageName option must be a string","INVALID_INPUT",{packageName:this.#e.packageName});if(this.#e.packageVersion&&typeof this.#e.packageVersion!="string")throw new b("CLI packageVersion option must be a string","INVALID_INPUT",{packageVersion:this.#e.packageVersion});const i=z();if(i.CEREBRO_OUTPUT_LEVEL=String(we),typeof this.#e.logger=="object"){const u=["debug","error","info","log","warn"],r=[],m=this.#e.logger;for(const s of u)typeof m[s]!="function"&&r.push(s);if(r.length>0)throw new b(`Logger object is missing required methods: ${r.join(", ")}`,"INVALID_INPUT",{logger:this.#e.logger,missingMethods:r});this.#t=this.#e.logger}else this.#t={...console,debug:Q((...u)=>{i.CEREBRO_OUTPUT_LEVEL===String(B)&&console.debug(...u)},"debug")};this.#u=this.#e.packageVersion,this.#w=this.#e.packageName,this.#c=this.#e.cwd,this.#s="help",this.#l={},this.#n=new Map,this.#i=new Map,this.#d=new Map}setCommandSection(e){return this.#l=e,this}getCommandSection(){return this.#l.header||(this.#l.header=`${this.#v}${this.#u?` v${this.#u}`:""}`),this.#l}setDefaultCommand(e){return this.#s=e,this}get defaultCommand(){return this.#s}addCommand(e){de(e,"Command"),J(e.name);const n=typeof e.execute=="function",o=typeof e.loader=="function";if(n&&o)throw new b(`Command "${e.name}" cannot define both "execute" and "loader" — choose one`,"INVALID_COMMAND",{commandName:e.name});if(!n&&!o)throw new b(`Command "${e.name}" must define either "execute" or "loader"`,"INVALID_COMMAND",{commandName:e.name});e.alias&&(typeof e.alias=="string"?J(e.alias):Me(e.alias,"Command alias").forEach(s=>J(s))),e.argument&&de(e.argument,"Command argument"),e.options&&de(e.options,"Command options"),e.commandPath&&(Me(e.commandPath,"Command commandPath"),e.commandPath.forEach(s=>{J(s)}));const a=je(e.name,e.commandPath),i=U(a);if(this.#i.has(i))throw new b(`Command with path "${i}" already exists`,"DUPLICATE_COMMAND",{commandName:e.name,commandPath:e.commandPath});const u=Array.isArray(e.commandPath)&&e.commandPath.length>0,r=this.#n.get(e.name),m=r!==void 0&&(r.commandPath===void 0||r.commandPath.length===0);if(!u&&m)throw new b(`Command with name "${e.name}" already exists`,"DUPLICATE_COMMAND",{commandName:e.name});if(e.options)for(const s of e.options)$e(s);if(Oi(e),_i(e),Ei(e),e.options&&(e.__conflictingOptions__=e.options.filter(s=>s.conflicts!==void 0),e.__requiredOptions__=e.options.filter(s=>s.required===!0)),u&&r!==void 0)this.#n.set(i,e);else{if(!u&&r!==void 0&&!m){const s=je(r.name,r.commandPath);this.#n.set(U(s),r)}this.#n.set(e.name,e)}if(this.#i.set(i,a),this.#d.set(i,e),this.#E(),e.alias!==void 0){const s=typeof e.alias=="string"?[e.alias]:e.alias;for(const f of s){if(z().CEREBRO_OUTPUT_LEVEL===String(B)&&this.#t.debug("adding alias",f),this.#n.has(f))throw new b(`Command alias "${f}" conflicts with existing command`,"DUPLICATE_COMMAND",{alias:f,commandName:e.name});this.#n.set(f,e)}}return this}addGlobalOption(e){const n=e,o=new Set(Y.map(i=>i.name)),a=new Set(Y.map(i=>i.alias).filter(Boolean));if(o.has(n.name))throw new b(`Cannot add global option "--${n.name}": it conflicts with a built-in global option`,"DUPLICATE_OPTION",{optionName:n.name});if(n.alias&&a.has(n.alias))throw new b(`Cannot add global option with alias "-${n.alias}": it conflicts with a built-in global option alias`,"DUPLICATE_OPTION",{alias:n.alias,optionName:n.name});if(new Set(this.#g.map(i=>i.name)).has(n.name))throw new b(`Global option "--${n.name}" has already been added`,"DUPLICATE_OPTION",{optionName:n.name});return n.group="global",$e(n),this.#g.push(n),this}getGlobalOptions(){return this.#O()}addPlugin(e){return this.getPluginManager().register(e),this}getPluginManager(){return this.#r?this.#r:(this.#r=new At(this.#t),this.#r.register({description:"Attaches the logger to the toolbox",execute:Q(e=>{e.logger=this.#t},"execute"),name:"logger"}),this.#r)}getCliName(){return this.#v}getPackageVersion(){return this.#u}getPackageName(){return this.#w}getCommands(){return this.#n}getCwd(){return this.#c}dispose(){this.#y?.()}async run(e={}){const{autoDispose:n=!0,shouldExitProcess:o=!0,...a}=e;if(!this.#n.has("help")){const{default:l}=await import("../commands/help-command.js");this.addCommand(new l(this.#n))}const i=this.#$(),u=this.#i;this.#C();const r=this.#N();let m,s=[...r];const f=pt(),g=ft(),v=pe();this.#t.debug(`process.execPath: ${f}`),this.#t.debug(`process.execArgv: ${g.join(" ")}`),this.#t.debug(`process.argv: ${v.join(" ")}`);const O=Ai(u,[...r]);if(O.commandPath)m=O.commandPath,s=O.argv;else{if(r.length>1&&r[0]&&r[1]&&!me(r[0])&&!me(r[1])){const d=[];let p=0;for(;p<r.length;){const A=r[p];if(!A||me(A))break;d.push(A),p+=1}const w=U(d);if(d[0]&&!i.includes(d[0])){const A=this.#o(),y=R(w,A);throw new T(w,y)}}let l;try{l=Mt([null,...i],[...r])}catch(d){if(d instanceof Error&&d.name==="INVALID_COMMAND"&&"command"in d){const p=d.command,w=this.#o(),A=R(p,w);throw new T(p,A)}throw d}l.command&&(m=[l.command],s=l.argv)}if(!m)if(this.#s)m=[this.#s];else{const l=this.#o();throw new T("",l)}const $=U(m),L=this.#i.get($);let N;if(L){if(N=this.#d.get($),!N||U(L)!==$){const l=this.#o(),d=R($,l);throw new T($,d)}}else{const l=m.at(-1);if(N=l?this.#n.get(l):void 0,!N){const d=this.#o(),p=R($,d);throw new T($,p)}}if(typeof N.execute!="function"&&typeof N.loader!="function")return this.#t.error(`Command "${N.name}" has no function to execute.`),o?G(1):void 0;const W=s;let x,C;try{({commandArgs:x,toolbox:C}=this.#A(N,W,a,$))}catch(l){if(this.#t.error(l),o)return G(1);throw l}const c=this.getPluginManager();try{!this.#m&&c.hasPlugins()&&(await c.init({cli:this,cwd:this.#c,logger:this.#t}),this.#m=!0),await c.executeLifecycle("execute",C),await c.executeLifecycle("beforeCommand",C);let l;const d=x.global;if(d?.help){const p=this.#n.get("help");if(!p)throw new b("Help command not found","COMMAND_NOT_FOUND");l=await S(p,C,x)}else if(d?.version??d?.V){const p=this.#n.get("version");if(!p)throw new b("Version command not found","COMMAND_NOT_FOUND");l=await S(p,C,x)}else l=await S(N,C,x);return await c.executeLifecycle("afterCommand",C,l),o?G(0):void 0}catch(l){throw await c.executeErrorHandlers(l,C),l}finally{n&&this.dispose()}}async runCommand(e,n={}){const{argv:o=[],...a}=n;ve(e,"Command name");const i=e.split(" ").filter(Boolean),u=U(i),r=this.#i.get(u)?this.#d.get(u):this.#n.get(e);if(!r){const v=this.#o(),O=R(u||e,v);throw new T(e,O)}if(typeof r.execute!="function"&&typeof r.loader!="function")throw new b(`Command "${r.name}" has no function to execute`,"INVALID_COMMAND",{commandName:r.name});const m=[...Ve(o)];this.#t.debug(`running command '${e}' programmatically with args: ${m.join(", ")}`);const{commandArgs:s,toolbox:f}=this.#A(r,m,a,u||e),g=this.getPluginManager();try{!this.#m&&g.hasPlugins()&&(await g.init({cli:this,cwd:this.#c,logger:this.#t}),this.#m=!0),await g.executeLifecycle("execute",f),await g.executeLifecycle("beforeCommand",f);let v;const O=s.global;if(O?.help){const $=this.#n.get("help");if(!$)throw new b("Help command not found","COMMAND_NOT_FOUND");v=await S($,f,s)}else if(O?.version??O?.V){const $=this.#n.get("version");if(!$)throw new b("Version command not found","COMMAND_NOT_FOUND");v=await S($,f,s)}else v=await S(r,f,s);return await g.executeLifecycle("afterCommand",f,v),v}catch(v){throw await g.executeErrorHandlers(v,f),v}}}export{uo as Cli};
@@ -1,6 +0,0 @@
1
- var O=Object.defineProperty;var l=(r,e)=>O(r,"name",{value:e,configurable:!0});import{createRequire as $}from"node:module";import{getStringWidth as W}from"@visulima/string";import{createTable as g}from"@visulima/tabular";import{NO_BORDER as m}from"@visulima/tabular/style";import j from"terminal-size";import _ from"@visulima/colorize/template";import{d as E}from"./runtime-process-DKHFvYkv.js";import{bold as S}from"@visulima/colorize";const A=$(import.meta.url),u=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,R=l(r=>{if(typeof u<"u"&&u.versions&&u.versions.node){const[e,t]=u.versions.node.split(".").map(Number);if(e>22||e===22&&t>=3||e===20&&t>=16)return u.getBuiltinModule(r)}return A(r)},"__cjs_getBuiltinModule"),L=R("node:os");var N=Object.defineProperty,T=l((r,e)=>N(r,"name",{value:e,configurable:!0}),"s");const p=new Map,C=500,s=T(r=>{if(!r||r==="")return"";const e=p.get(r);if(e!==void 0)return e;const t=_(Object.assign([],{raw:[r]}));if(p.size>=C){const i=p.keys().next().value;i!==void 0&&p.delete(i)}return p.set(r,t),t},"templateFormat");var P=Object.defineProperty,M=l((r,e)=>P(r,"name",{value:e,configurable:!0}),"t$1");const y=M(()=>{const r=E().CEREBRO_TERMINAL_WIDTH;if(r===void 0)return;const e=Number.parseInt(r,10);if(!(Number.isNaN(e)||e<=0))return e},"getTerminalWidth");var B=Object.defineProperty,H=l((r,e)=>B(r,"name",{value:e,configurable:!0}),"t");class w{static{l(this,"n")}static{H(this,"BaseSection")}lines;constructor(){this.lines=[]}add(e){this.lines.push(e)}toString(){return this.lines.join(L.EOL)}header(e){this.add(S(e)),this.lines.push("")}}var I=Object.defineProperty,v=l((r,e)=>I(r,"name",{value:e,configurable:!0}),"g");const q=v(r=>r!==void 0&&r>0?r:j().columns,"resolveTerminalWidth"),x=v((r,e,t,i)=>{if(r.length===0||r.some(c=>c.length!==2))return;let o=0;for(const c of r){const h=c[0];if(h===void 0)continue;const b=W(h);b>o&&(o=b)}if(o===0)return;const d=t+i,n=o+d,a=20+d;if(n+a>e)return;const f=e-n;return[n,f]},"computeColumnWidths");class z extends w{static{l(this,"S")}static{v(this,"ContentSection")}constructor(e){if(super(),e.header&&this.header(s(e.header)),e.content){if(e.raw)if(Array.isArray(e.content)&&e.content.every(t=>typeof t=="string"))e.content.forEach(t=>{Array.isArray(t)?t.forEach(i=>{this.add(s(i))}):this.add(s(t))});else if(typeof e.content=="string")this.add(s(e.content));else throw new TypeError("Invalid raw content, must be a string or array of strings.");else this.add(this.getContentLines(e.content));this.add("")}}getContentLines(e){if(typeof e=="string"){const t=g({showHeader:!1,style:{border:m,paddingLeft:4,paddingRight:1},terminalWidth:y(),truncateOverflow:!1,wordWrap:!0});return t.addRow([s(e)]),t.toString()}if(Array.isArray(e)&&e.every(t=>typeof t=="string"||Array.isArray(t)&&t.every(i=>typeof i=="string"))){const t=q(y()),i=v(a=>Array.isArray(a)?a.map(f=>s(f)):[s(a)],"formatRow"),o=e.map(a=>i(a)),d=x(o,t,4,1),n=g({columnWidths:d,showHeader:!1,style:{border:m,paddingLeft:4,paddingRight:1},terminalWidth:t,truncateOverflow:!1,wordWrap:!0});return o.forEach(a=>{d!==void 0&&a.length===2?n.addRow([{content:a[0],wordWrap:!1},a[1]]):n.addRow(a)}),n.toString()}if(typeof e=="object"){const t=e;if(!t.options||!t.data)throw new Error(`Must have an "options" or "data" property
2
- ${JSON.stringify(e)}`);const i=g({showHeader:!1,style:{border:m,paddingLeft:4,paddingRight:1},terminalWidth:y(),truncateOverflow:!1,wordWrap:!0});return t.data.forEach(o=>{Array.isArray(o)?i.addRow(o.map(d=>s(d))):i.addRow([s(o)])}),i.toString()}throw new Error(`invalid input - 'content' must be a string, array of strings or a object:
3
-
4
- ${JSON.stringify(e)}`)}}var D=Object.defineProperty,J=l((r,e)=>D(r,"name",{value:e,configurable:!0}),"m");class k extends w{static{l(this,"O")}static{J(this,"OptionListSection")}constructor(e){super();let t=e.optionList??[];const i=Array.isArray(e.hide)?e.hide:[e.hide].filter(n=>typeof n=="string"),o=Array.isArray(e.group)?e.group:[e.group].filter(n=>typeof n=="string");i.length>0&&(t=t.filter(n=>!i.includes(n.name))),e.header&&this.header(s(e.header)),o.length>0&&(t=t.filter(n=>{const a=n,f=o.includes("_none")&&!a.group,c=a.group,h=this.intersect(Array.isArray(c)?c:[c],o);return f||h?n:void 0}));const d=g({showHeader:!1,style:{border:m,paddingLeft:2,paddingRight:1,...e.tableOptions?.style},terminalWidth:y()??e.tableOptions?.terminalWidth,truncateOverflow:!1,wordWrap:e.tableOptions?.wordWrap??!0,...e.tableOptions});t.forEach(n=>{const a=n;d.addRow([this.getOptionNames(a,e.reverseNameOrder??!1,e.isArgument??!1),s(a.description)])}),this.add(d.toString()),this.lines.push("")}getOptionNames(e,t,i){if(!e.name)throw new TypeError("Invalid option definition, name is required.");let o=e.type?e.type.name.toLowerCase():"string";const d=e.multiple||e.lazyMultiple?"[]":"";o=s(e.typeLabel??`{underline ${o}${d}}`);let n;if(e.alias)if(e.name){const a=i?e.name:`{yellow --${e.name}}`;n=s(t?`{bold ${a}}, {bold -${e.alias}} ${o}`:`{bold -${e.alias}}, {bold ${a}} ${o}`)}else t?n=s(`{bold -${e.alias}} ${o}`):n=s(`{bold -${e.alias}} ${o}`);else n=s(`{bold ${i?e.name:`{yellow --${e.name}}`}} ${o}`);return n}intersect(e,t){return e.some(i=>t.includes(i))}}var F=Object.defineProperty,U=l((r,e)=>F(r,"name",{value:e,configurable:!0}),"o");const te=U(r=>(Array.isArray(r)?r:[r]).length===0?"":`
5
- ${r.map(e=>e.optionList?new k(e).toString():new z(e).toString()).join(`
6
- `)}`,"commandLineUsage");export{s as f,te as p};
@@ -1,24 +0,0 @@
1
- var Q=Object.defineProperty;var N=(r,e)=>Q(r,"name",{value:e,configurable:!0});import{createRequire as X}from"node:module";const Y=X(import.meta.url),S=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,Z=N(r=>{if(typeof S<"u"&&S.versions&&S.versions.node){const[e,t]=S.versions.node.split(".").map(Number);if(e>22||e===22&&t>=3||e===20&&t>=16)return S.getBuiltinModule(r)}return Y(r)},"__cjs_getBuiltinModule"),{createRequire:ee}=Z("node:module");var re=Object.defineProperty,te=N((r,e)=>re(r,"name",{value:e,configurable:!0}),"A$2"),ie=Object.defineProperty,A=te((r,e)=>ie(r,"name",{value:e,configurable:!0}),"$"),ne=Object.defineProperty,oe=A((r,e)=>ne(r,"name",{value:e,configurable:!0}),"r$1");const se=oe(r=>r.replaceAll(/\r\n|\r(?!\n)|\n/gu,`
2
- `),"normalizeLF"),ae=globalThis.process??Object.create(null),P={versions:{}},T=new Proxy(ae,{get(r,e){if(e in r)return r[e];if(e in P)return P[e]}});var le=Object.defineProperty,ce=A((r,e)=>le(r,"name",{value:e,configurable:!0}),"b");const de=ce((r,e,t,i)=>{const s={column:0,line:-1,...r.start},o={...s,...r.end},n=s.line,l=s.column,d=o.line,c=o.column;let a=Math.max(n-(t+1),0),p=Math.min(e.length,d+i);n===-1&&(a=0),d===-1&&(p=e.length);const g=d-n,m={};if(g)for(let u=0;u<=g;u++){const $=u+n;if(!l)m[$]=!0;else if(u===0){const h=e[$-1]?.length;m[$]=[l,(h??0)-l+1]}else if(u===g)m[$]=[0,c];else{const h=e[$-u]?.length;m[$]=[0,h]}}else l===c?m[n]=l?[l,0]:!0:m[n]=[l,(c??0)-(l??0)];return{end:p,markerLines:m,start:a}},"getMarkerLines");var ue=Object.defineProperty,E=A((r,e)=>ue(r,"name",{value:e,configurable:!0}),"t");const fe=T.platform==="win32"&&!T.env?.WT_SESSION?">":"❯",me=E((r,e,t)=>{const i={linesAbove:2,linesBelow:3,prefix:"",showGutter:!0,tabWidth:4,...t,color:{gutter:E(u=>u,"gutter"),marker:E(u=>u,"marker"),message:E(u=>u,"message"),...t?.color}},s=typeof e.start.column=="number";let o=se(r).split(`
3
- `);typeof i.tabWidth=="number"&&(o=o.map(u=>u.replaceAll(" "," ".repeat(i.tabWidth))));const{end:n,markerLines:l,start:d}=de(e,o,i.linesAbove,i.linesBelow),c=String(n).length,{gutter:a,marker:p,message:g}=i.color;let m=o.slice(d,n).map((u,$)=>{const h=d+1+$,k=l[h],D=` ${String(h)}`.slice(-c),U=!l[h+1],j=` ${D}${i.showGutter?" |":""}`;if(k){let O="";if(Array.isArray(k)){const H=u.replaceAll(/[^\t]/g," ").slice(0,Math.max(k[0]-1,0)),K=k[1]||1;O=[`
4
- `,i.prefix+a(j.replaceAll(/\d/g," "))," ",H,p("^").repeat(K)].join(""),U&&i.message&&(O+=` ${g(i.message)}`)}return[i.prefix+p(fe),a(j),u.length>0?` ${u}`:"",O].join("")}return`${i.prefix} ${a(j)}${u.length>0?` ${u}`:""}`}).join(`
5
- `);return i.message&&!s&&(m=`${i.prefix+" ".repeat(c+1)+i.message}
6
- ${m}`),m},"codeFrame");var pe=Object.defineProperty,ve=N((r,e)=>pe(r,"name",{value:e,configurable:!0}),"x$1"),ge=Object.defineProperty,$e=ve((r,e)=>ge(r,"name",{value:e,configurable:!0}),"x"),he=Object.defineProperty,v=$e((r,e)=>he(r,"name",{value:e,configurable:!0}),"u");const b=v((r,...e)=>{process.env.DEBUG&&process.env.DEBUG==="true"&&console.debug(`error:parse-stacktrace: ${r}`,...e)},"debugLog"),y="<unknown>",be=/^.*?\s*at\s(?:(.+?\)(?:\s\[.+\])?|\(?.*?)\s?\((?:address\sat\s)?)?(?:async\s)?((?:<anonymous>|[-a-z]+:|.*bundle|\/)?.*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i,ye=/\((\S+)\),\s(<[^>]+>)?:(\d+)?:(\d+)?\)?/,xe=/(.*?):(\d+):(\d+)(?:\s<-\s.+:\d+:\d+)?/,we=/eval\sat\s(<anonymous>)\s\((.*)\)?:(\d+)?:(\d+)\),\s*<anonymous>?:(\d+)?:(\d+)/,Ne=/^\s*in\s(?:([^\\/]+(?:\s\[as\s\S+\])?)\s\(?)?\(at?\s?(.*?):(\d+)(?::(\d+))?\)?\s*$/,Se=/in\s(.*)\s\(at\s(.+)\)\sat/,ke=/^(?:.*@)?(.*):(\d+):(\d+)$/,Ee=/^\s*(.*?)(?:\((.*?)\))?(?:^|@)?((?:[-a-z]+)?:\/.*?|\[native code\]|[^@]*(?:bundle|\d+\.js)|\/[\w\-. \/=]+)(?::(\d+))?(?::(\d+))?\s*$/i,je=/(\S+) line (\d+)(?: > eval line \d+)* > eval/i,Oe=/(\S[^\s[]*\[.*\]|.*?)@(.*):(\d+):(\d+)/,_=/\(error: (.*)\)/,Ae=/at\s/,Le=/^(\S+):(\d+):(\d+)$|^(\S+):(\d+)$/,Me=/^\s+|\s+$/g,Pe=/\S*(?:Error: |AggregateError:)/,C=/^Anonymous function$/,Te=/^\s*in\s.*/,_e=/^.*?\s*at\s.*/,Ce=/^.*?\s*@.*|\[native code\]/,B=v((r,e)=>{const t=r.includes("safari-extension"),i=r.includes("safari-web-extension");return t||i?[r.includes("@")?r.split("@")[0]:y,t?`safari-extension:${e}`:`safari-web-extension:${e}`]:[r,e]},"extractSafariExtensionDetails"),W=v((r,e)=>{const t=xe.exec(e);t&&(r.file=t[1],r.line=+t[2],r.column=+t[3])},"parseMapped"),Be=v(r=>{const e=Se.exec(r);if(e){b(`parse nested node error stack line: "${r}"`,`found: ${JSON.stringify(e)}`);const i=e[2].split(":");return{column:i[2]?+i[2]:void 0,file:i[0],line:i[1]?+i[1]:void 0,methodName:e[1]??y,raw:r,type:void 0}}const t=Ne.exec(r);if(t){b(`parse node error stack line: "${r}"`,`found: ${JSON.stringify(t)}`);const i={column:t[4]?+t[4]:void 0,file:t[2]?t[2].replace(Ae,""):void 0,line:t[3]?+t[3]:void 0,methodName:t[1]??y,raw:r,type:r.startsWith("internal")?"internal":void 0};return W(i,`${t[2]}:${t[3]}:${t[4]}`),i}},"parseNode"),We=v(r=>{const e=be.exec(r);if(e){b(`parse chrome error stack line: "${r}"`,`found: ${JSON.stringify(e)}`);const t=e[2]?.startsWith("native"),i=e[2]?.startsWith("eval")||e[1]?.startsWith("eval");let s,o;if(i){const c=ye.exec(r);if(c){const a=Le.exec(c[1]);a?(e[2]=a[4]??a[1],e[3]=a[5]??a[2],e[4]=a[3]):c[2]&&(e[2]=c[1]),c[2]&&(s={column:c[4]?+c[4]:void 0,file:c[2],line:c[3]?+c[3]:void 0,methodName:"eval",raw:r,type:"eval"})}else{const a=we.exec(r);a&&(o={column:a[4]?+a[4]:void 0,file:a[2],line:a[3]?+a[3]:void 0},s={column:a[6]?+a[6]:void 0,file:a[1],line:a[5]?+a[5]:void 0,methodName:"eval",raw:a[0],type:"eval"})}}const[n,l]=B(e[1]?e[1].replace(C,"<anonymous>"):y,e[2]),d={column:e[4]?+e[4]:void 0,evalOrigin:s,file:l,line:e[3]?+e[3]:void 0,methodName:n,raw:r,type:i?"eval":t?"native":void 0};return o?(d.column=o.column,d.file=o.file,d.line=o.line):W(d,`${l}:${e[3]}:${e[4]}`),d}},"parseChromium"),Ge=v((r,e)=>{const t=Ee.exec(r);if(t){b(`parse gecko error stack line: "${r}"`,`found: ${JSON.stringify(t)}`);const i=t[3]?.includes(" > eval"),s=i&&t[3]&&je.exec(t[3]);let o;i&&s&&(t[3]=s[1],o={column:t[5]?+t[5]:void 0,file:t[3],line:t[4]?+t[4]:void 0,methodName:"eval",raw:r,type:"eval"},t[4]=s[2]);const[n,l]=B(t[1]?t[1].replace(C,"<anonymous>"):y,t[3]);let d;(e?.type==="safari"||!i&&e?.type==="firefox")&&e.column?d=e.column:!i&&t[5]&&(d=+t[5]);let c;return(e?.type==="safari"||!i&&e?.type==="firefox")&&e.line?c=e.line:t[4]&&(c=+t[4]),{column:d,evalOrigin:o,file:l,line:c,methodName:n,raw:r,type:i?"eval":l.includes("[native code]")?"native":void 0}}},"parseGecko"),Re=v((r,e)=>{const t=Oe.exec(r);if(!(t&&t[2].includes(" > eval"))&&t)return b(`parse firefox error stack line: "${r}"`,`found: ${JSON.stringify(t)}`),{column:t[4]?+t[4]:e?.column??void 0,file:t[2],line:t[3]?+t[3]:e?.line??void 0,methodName:t[1]||y,raw:r,type:void 0}},"parseFirefox"),Fe=v(r=>{const e=ke.exec(r);if(e)return b(`parse react android native error stack line: "${r}"`,`found: ${JSON.stringify(e)}`),{column:e[3]?+e[3]:void 0,file:e[1],line:e[2]?+e[2]:void 0,methodName:y,raw:r,type:void 0}},"parseReactAndroidNative"),G=v((r,{filter:e,frameLimit:t=50}={})=>{const i=r;let s=(typeof i.stacktrace=="string"?i.stacktrace:r.stack??"").split(`
7
- `).map(o=>(_.test(o)?o.replace(_,"$1"):o).replaceAll(Me,"")).filter(o=>!Pe.test(o)&&o!=="eval code");return e&&(s=s.filter(o=>e(o))),s=s.slice(0,t),s.reduce((o,n,l)=>{if(!n||n.length>1024)return o;let d;if(Te.test(n))d=Be(n);else if(_e.test(n))d=We(n);else if(Ce.test(n)){let c;if(l===0){const a=r,p=a.columnNumber,g=a.lineNumber,m=a.line,u=a.column;p||g?c={column:p,line:g,type:"firefox"}:(m||u)&&(c={column:u,line:m,type:"safari"})}d=Re(n,c)??Ge(n,c)}else d=Fe(n);return d?o.push(d):b(`parse error stack line: "${n}"`,"not parser found"),o},[])},"parseStacktrace");var Ie=Object.defineProperty,Ve=N((r,e)=>Ie(r,"name",{value:e,configurable:!0}),"p"),Je=Object.defineProperty,R=Ve((r,e)=>Je(r,"name",{value:e,configurable:!0}),"m");const qe=ee(import.meta.url),x=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,L=R(r=>{if(typeof x<"u"&&x.versions&&x.versions.node){const[e,t]=x.versions.node.split(".").map(Number);if(e>22||e===22&&t>=3||e===20&&t>=16)return x.getBuiltinModule(r)}return qe(r)},"__cjs_getBuiltinModule"),{existsSync:ze,readFileSync:De}=L("node:fs"),{relative:Ue}=L("node:path"),{cwd:He}=x,{fileURLToPath:Ke}=L("node:url");var Qe=Object.defineProperty,f=R((r,e)=>Qe(r,"name",{value:e,configurable:!0}),"o");const w=f((r,e,t)=>t===0?r:e===" "?r+" ".repeat(t):r+" ".repeat(e*t),"getPrefix"),Xe=f((r,e)=>{const t=r.replace("async file:","file:");return Ue(e,t.startsWith("file:")?Ke(t):t)},"getRelativePath"),Ye=f((r,e,t)=>{if(e)return t.title(r.message);const i=r.message?`: ${r.message}`:"";return t.title(r.name+i)},"getTitleText"),F=f((r,{color:e,hideErrorTitle:t,indentation:i,prefix:s},o)=>`${w(s,i,o)}${Ye(r,t,e)}
8
- `,"getMessage"),I=f((r,{color:e,indentation:t,prefix:i},s)=>{if(r.hint===void 0)return;const o=w(i,t,s);let n="";if(Array.isArray(r.hint))for(const l of r.hint)n+=`${o+l}
9
- `;else n+=o+r.hint;return e.hint(n)},"getHint"),M=f((r,{color:e,cwd:t,displayShortPath:i,indentation:s,prefix:o},n=0)=>{const l=i?Xe(r.file,t):r.file,{fileLine:d,method:c}=e;return`${w(o,s,n)}at ${r.methodName?`${c(r.methodName)} `:""}${d(l)}:${d(r.line?.toString()??"")}`},"getMainFrame"),V=f((r,{color:e,indentation:t,linesAbove:i,linesBelow:s,prefix:o,showGutter:n,showLineNumbers:l,tabWidth:d},c)=>{if(r.file===void 0)return;const a=r.file.replace("file://","");if(!ze(a))return;const p=De(a,"utf8");return me(p,{start:{column:r.column,line:r.line}},{color:e,linesAbove:i,linesBelow:s,prefix:w(o,t,c),showGutter:n,showLineNumbers:l,tabWidth:d})},"getCode"),J=f((r,e,t)=>{if(r.errors.length===0)return;let i=`${w(e.prefix,e.indentation,t)}Errors:
10
-
11
- `,s=!0;for(const o of r.errors)s?s=!1:i+=`
12
-
13
- `,i+=z(o,{...e,framesMaxLimit:1,hideErrorCodeView:e.hideErrorErrorsCodeView},t+1);return`
14
- ${i}`},"getErrors"),q=f((r,e,t)=>{let i=`${w(e.prefix,e.indentation,t)}Caused by:
15
-
16
- `;const s=r.cause;i+=F(s,e,t);const o=G(s).shift(),n=I(s,e,t);if(n&&(i+=`${n}
17
- `),o&&(i+=M(o,e,t),!e.hideErrorCauseCodeView)){const l=V(o,e,t);l!==void 0&&(i+=`
18
- ${l}`)}if(s.cause)i+=`
19
- ${q(s,e,t+1)}`;else if(s instanceof AggregateError){const l=J(s,e,t);l!==void 0&&(i+=`
20
- ${l}`)}return`
21
- ${i}`},"getCause"),Ze=f((r,e)=>(r.length>0?`
22
- `:"")+r.map(t=>M(t,e)).join(`
23
- `),"getStacktrace"),z=f((r,e,t)=>{const i={cwd:He(),displayShortPath:!1,filterStacktrace:void 0,framesMaxLimit:Number.POSITIVE_INFINITY,hideErrorCauseCodeView:!1,hideErrorCodeView:!1,hideErrorErrorsCodeView:!1,hideErrorTitle:!1,hideMessage:!1,indentation:4,linesAbove:2,linesBelow:3,prefix:"",showGutter:!0,showLineNumbers:!0,tabWidth:4,...e,color:{fileLine:f(n=>n,"fileLine"),gutter:f(n=>n,"gutter"),hint:f(n=>n,"hint"),marker:f(n=>n,"marker"),message:f(n=>n,"message"),method:f(n=>n,"method"),title:f(n=>n,"title"),...e.color}},s=G(r,{filter:e.filterStacktrace,frameLimit:i.framesMaxLimit}),o=s.shift();return[e.hideMessage?void 0:F(r,i,t),I(r,i,t),o?M(o,i,t):void 0,o&&!i.hideErrorCodeView?V(o,i,t):void 0,r instanceof AggregateError?J(r,i,t):void 0,r.cause===void 0?void 0:q(r,i,t),s.length>0?Ze(s,i):void 0].filter(Boolean).join(`
24
- `).replaceAll("\\","/")},"internalRenderError"),tr=f((r,e={})=>{if(e.framesMaxLimit!==void 0&&e.framesMaxLimit<=0)throw new RangeError("The 'framesMaxLimit' option must be a positive number");return z(r,e,0)},"renderError");export{tr as G,me as N,G as Q,fe as k};