@visulima/cerebro 3.0.3 → 3.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/LICENSE.md +346 -0
  3. package/dist/commands/completion-command.d.ts +3 -3
  4. package/dist/commands/completion-command.js +1 -1
  5. package/dist/commands/help-command.d.ts +1 -1
  6. package/dist/commands/help-command.js +1 -1
  7. package/dist/commands/readme-command.d.ts +3 -3
  8. package/dist/commands/readme-command.js +17 -17
  9. package/dist/commands/version-command.d.ts +1 -1
  10. package/dist/index.d.ts +403 -433
  11. package/dist/index.js +1 -1
  12. package/dist/logger/create-pail-logger.d.ts +533 -555
  13. package/dist/logger/create-pail-logger.js +1 -1
  14. package/dist/packem_chunks/has-new-version.js +1 -1
  15. package/dist/packem_shared/Cerebro-58LHN3_T.js +4 -0
  16. package/dist/packem_shared/VisulimaError-k1qGkvab.js +76 -0
  17. package/dist/packem_shared/cerebro-error-DWpjBY_M.js +1 -0
  18. package/dist/packem_shared/command.d-B_G9vIYJ.d.ts +633 -0
  19. package/dist/packem_shared/{index-DvVGK4kr.js → index-Dpm7gUHe.js} +12 -12
  20. package/dist/packem_shared/index.d-CnnVYgSZ.d.ts +117 -0
  21. package/dist/packem_shared/renderError-BISXNU8L-B47ZikMV.js +27 -0
  22. package/dist/packem_shared/runtime-process-BEw54Ar-.js +1 -0
  23. package/dist/packem_shared/split-by-case-BZ6XOTIf.js +1 -0
  24. package/dist/plugins/error-handler-plugin.d.ts +18 -7
  25. package/dist/plugins/error-handler-plugin.js +1 -1
  26. package/dist/plugins/runtime-version-check-plugin.d.ts +5 -5
  27. package/dist/plugins/runtime-version-check-plugin.js +1 -1
  28. package/dist/plugins/update-notifier/update-notifier-plugin.d.ts +11 -10
  29. package/dist/plugins/update-notifier/update-notifier-plugin.js +1 -1
  30. package/dist/util/general/compile-cache.d.ts +37 -37
  31. package/dist/util/general/heap-tuning.d.ts +11 -11
  32. package/dist/util/general/heap-tuning.js +1 -1
  33. package/package.json +6 -6
  34. package/dist/packem_shared/Cerebro-Czc4t-75.js +0 -4
  35. package/dist/packem_shared/VisulimaError-C90oeIMu.js +0 -76
  36. package/dist/packem_shared/cerebro-error-BjBcYVRO.js +0 -1
  37. package/dist/packem_shared/command.d-DbhtfXF4.d.ts +0 -639
  38. package/dist/packem_shared/index.d-BL4NtVR3.d.ts +0 -127
  39. package/dist/packem_shared/renderError-B3ePOoBG-BmZlyMcr.js +0 -25
  40. package/dist/packem_shared/runtime-process-Dmz0vCJy.js +0 -1
  41. package/dist/packem_shared/split-by-case-Dbpgd7rf.js +0 -1
@@ -1 +1 @@
1
- import a from"@visulima/pail/processor/caller";import m from"@visulima/pail/processor/message-formatter";import{createPail as l}from"@visulima/pail/server";import{VERBOSITY_DEBUG as p,VERBOSITY_QUIET as E}from"../packem_shared/VERBOSITY_DEBUG-XPultrIA.js";import{c}from"../packem_shared/runtime-process-Dmz0vCJy.js";const d=o=>{const i={16:"informational",32:"informational",64:"trace",128:"debug",256:"debug"},t=[new m],r=c().CEREBRO_OUTPUT_LEVEL;(r===String(128)||r===String(p))&&t.push(new a);const n=(r&&i[r])??"informational",s={...o,logLevel:o?.logLevel??n,processors:o?.processors?[...t,...o.processors]:t},e=l(s);return r===String(E)&&e.disable(),e};export{d as default};
1
+ import a from"@visulima/pail/processor/caller";import m from"@visulima/pail/processor/message-formatter";import{createPail as l}from"@visulima/pail/server";import{VERBOSITY_DEBUG as p,VERBOSITY_QUIET as E}from"../packem_shared/VERBOSITY_DEBUG-XPultrIA.js";import{c}from"../packem_shared/runtime-process-BEw54Ar-.js";const d=o=>{const i={16:"informational",32:"informational",64:"trace",128:"debug",256:"debug"},t=[new m],r=c().CEREBRO_OUTPUT_LEVEL;(r===String(128)||r===String(p))&&t.push(new a);const n=(r&&i[r])??"informational",s={...o,logLevel:o?.logLevel??n,processors:o?.processors?[...t,...o.processors]:t},e=l(s);return r===String(E)&&e.disable(),e};export{d as default};
@@ -1 +1 @@
1
- import{createRequire as k}from"node:module";import{findCacheDirSync as $}from"@visulima/find-cache-dir";import{t as F}from"../packem_shared/cerebro-error-BjBcYVRO.js";const T=k(import.meta.url),g=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,w=e=>{if(typeof g<"u"&&g.versions&&g.versions.node){const[r,t]=g.versions.node.split(".").map(Number);if(r>22||r===22&&t>=3||r===20&&t>=16)return g.getBuiltinModule(e)}return T(e)},{writeFile:b,readFile:R,mkdir:I,access:S}=w("node:fs/promises"),{get:U}=w("node:https"),N=e=>{const[r,t]=e.split("-");return{nums:r.split(".").map(s=>Number.parseInt(s,10)||0),pre:t}},A=(e,r)=>{const t=N(e),s=N(r),o=Math.max(t.nums.length,s.nums.length);for(let i=0;i<o;i+=1){const n=t.nums[i]??0,u=s.nums[i]??0;if(n>u)return!0;if(n<u)return!1}if(t.pre===void 0&&s.pre!==void 0)return!0;if(t.pre!==void 0&&s.pre===void 0||t.pre===void 0&&s.pre===void 0)return!1;const c=t.pre.split("."),l=s.pre.split("."),a=Math.max(c.length,l.length);for(let i=0;i<a;i+=1){const n=c[i],u=l[i];if(n===void 0)return!1;if(u===void 0)return!0;if(n===u)continue;const d=Number.parseInt(n,10),f=Number.parseInt(u,10),h=!Number.isNaN(d)&&String(d)===n,_=!Number.isNaN(f)&&String(f)===u;return h&&_?d>f:h?!1:_?!0:n>u}return!1},x=/^[A-Z]:\//i,v=(e="")=>e&&e.replaceAll("\\","/").replace(x,r=>r.toUpperCase()),j=/^[/\\]{2}/,D=/^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Z]:[/\\]/i,E=/^[A-Z]:$/i,H=/\/$/,M=(e,r)=>{let t="",s=0,o=-1,c=0,l;for(let a=0;a<=e.length;++a){if(a<e.length)l=e[a];else{if(l==="/")break;l="/"}if(l==="/"){if(!(o===a-1||c===1))if(c===2){if(t.length<2||s!==2||!t.endsWith(".")||t.at(-2)!=="."){if(t.length>2){const i=t.lastIndexOf("/");i===-1?(t="",s=0):(t=t.slice(0,i),s=t.length-1-t.lastIndexOf("/")),o=a,c=0;continue}else if(t.length>0){t="",s=0,o=a,c=0;continue}}r&&(t+=t.length>0?"/..":"..",s=2)}else t.length>0?t+=`/${e.slice(o+1,a)}`:t=e.slice(o+1,a),s=a-o-1;o=a,c=0}else l==="."&&c!==-1?++c:c=-1}return t},m=e=>D.test(e),P=function(e){if(e.length===0)return".";e=v(e);const r=j.exec(e),t=m(e),s=e.at(-1)==="/";return e=M(e,!t),e.length===0?t?"/":s?"./":".":(s&&(e+="/"),E.test(e)&&(e+="/"),r?t?`//${e}`:`//./${e}`:t&&!m(e)?`/${e}`:e)},V=(...e)=>{let r="";for(const t of e)if(t)if(r.length>0){const s=r.at(-1)==="/",o=t[0]==="/";s&&o?r+=t.slice(1):r+=s||o?t:`/${t}`}else r+=t;return P(r)},q=e=>{const r=v(e).replace(H,""),t=r.lastIndexOf("/");if(t===-1)return m(e)?"/":".";const s=r.slice(0,t);return E.test(s)?`${s}/`:s||(m(e)?"/":".")};class p extends F{constructor(r,t="UPDATE_NOTIFIER_ERROR",s){super(r,t,s),this.name="UpdateNotifierError"}}const J="last-update-check.json",y={access:(e,r)=>S(e,r),mkdir:(e,r)=>I(e,r),readFile:(async(e,r)=>r===void 0?R(e):R(e,r)),writeFile:(e,r,t)=>b(e,r,t)},O=async(e,r)=>{try{return await e.access(r),!0}catch{return!1}},C=e=>{const r=$(e);if(r===void 0)throw new p("Could not find cache directory","CACHE_DIRECTORY_NOT_FOUND",{packageName:e});return V(r,J)},L=async(e,r=y)=>{const t=C(e);try{if(!await O(r,t))return;const{lastUpdateCheck:s}=JSON.parse(await r.readFile(t,"utf8"));return s}catch{return}},Z=async(e,r=y)=>{const t=C(e),s=q(t);await O(r,s)||await r.mkdir(s,{recursive:!0}),await r.writeFile(t,JSON.stringify({lastUpdateCheck:Date.now()}),"utf8")},B=5e3,W=async(e,r,t,s=B)=>{const o=t.replace("__NAME__",e),c=512*1024;return await new Promise((l,a)=>{const i=U(o,{timeout:s},n=>{if(n.statusCode!==void 0&&(n.statusCode<200||n.statusCode>=300)){a(new p(`Unexpected status code ${String(n.statusCode)}`,"VERSION_FETCH_ERROR",{distributionTag:r,packageName:e})),n.resume();return}let u="",d=!1;n.on("data",f=>{d||(u+=String(f),u.length>c&&(d=!0,a(new p("Response too large","VERSION_FETCH_ERROR",{distributionTag:r,packageName:e})),n.destroy()))}),n.on("end",()=>{if(!d)try{const f=JSON.parse(u)[r];if(!f){a(new p("Error getting version","VERSION_FETCH_ERROR",{distributionTag:r,packageName:e}));return}l(f)}catch{a(new p("Could not parse version response","VERSION_PARSE_ERROR",{distributionTag:r,packageName:e}))}})});i.on("timeout",()=>{i.destroy(new p("Request timed out","VERSION_FETCH_ERROR",{distributionTag:r,packageName:e}))}),i.on("error",n=>{a(n)})})},G=async({alwaysRun:e,debug:r,distTag:t="latest",fs:s,pkg:o,registryUrl:c="https://registry.npmjs.org/-/package/__NAME__/dist-tags",timeout:l,updateCheckInterval:a=1e3*60*60*24})=>{const i=await L(o.name,s);if(e||!i||i<Date.now()-a){const n=await W(o.name,t,c,l);if(await Z(o.name,s),A(n,o.version))return n;r&&console.error(`Latest version (${n}) not newer than current version (${o.version})`)}else r&&console.error(`Too recent to check for a new update. simpleUpdateNotifier() interval set to ${String(a)}ms but only ${String(Date.now()-i)}ms since last check.`)};export{G as default};
1
+ import{createRequire as T}from"node:module";import{findCacheDirSync as F}from"@visulima/find-cache-dir";import{t as U}from"../packem_shared/cerebro-error-DWpjBY_M.js";let b;const k=e=>(b??=T(import.meta.url))(e),g=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,w=e=>{if(typeof g<"u"&&g.versions&&g.versions.node){const[r,t]=g.versions.node.split(".").map(Number);if(r>22||r===22&&t>=3||r===20&&t>=16)return g.getBuiltinModule(e)}return k(e)},{writeFile:I,readFile:R,mkdir:S,access:$}=w("node:fs/promises"),{get:x}=w("node:https"),N=e=>{const[r,t]=e.split("-");return{nums:r.split(".").map(s=>Number.parseInt(s,10)||0),pre:t}},A=(e,r)=>{const t=N(e),s=N(r),o=Math.max(t.nums.length,s.nums.length);for(let i=0;i<o;i+=1){const n=t.nums[i]??0,l=s.nums[i]??0;if(n>l)return!0;if(n<l)return!1}if(t.pre===void 0&&s.pre!==void 0)return!0;if(t.pre!==void 0&&s.pre===void 0||t.pre===void 0&&s.pre===void 0)return!1;const c=t.pre.split("."),u=s.pre.split("."),a=Math.max(c.length,u.length);for(let i=0;i<a;i+=1){const n=c[i],l=u[i];if(n===void 0)return!1;if(l===void 0)return!0;if(n===l)continue;const f=Number.parseInt(n,10),d=Number.parseInt(l,10),h=!Number.isNaN(f)&&String(f)===n,_=!Number.isNaN(d)&&String(d)===l;return h&&_?f>d:h?!1:_?!0:n>l}return!1},j=/^[A-Z]:\//i,v=(e="")=>e&&e.replaceAll("\\","/").replace(j,r=>r.toUpperCase()),D=/^[/\\]{2}/,M=/^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Z]:[/\\]/i,E=/^[A-Z]:$/i,q=/\/$/,H=(e,r)=>{let t="",s=0,o=-1,c=0,u;for(let a=0;a<=e.length;++a){if(a<e.length)u=e[a];else{if(u==="/")break;u="/"}if(u==="/"){if(!(o===a-1||c===1))if(c===2){if(t.length<2||s!==2||!t.endsWith(".")||t.at(-2)!=="."){if(t.length>2){const i=t.lastIndexOf("/");i===-1?(t="",s=0):(t=t.slice(0,i),s=t.length-1-t.lastIndexOf("/")),o=a,c=0;continue}else if(t.length>0){t="",s=0,o=a,c=0;continue}}r&&(t+=t.length>0?"/..":"..",s=2)}else t.length>0?t+=`/${e.slice(o+1,a)}`:t=e.slice(o+1,a),s=a-o-1;o=a,c=0}else u==="."&&c!==-1?++c:c=-1}return t},m=e=>M.test(e),V=function(e){if(e.length===0)return".";e=v(e);const r=D.exec(e),t=m(e),s=e.at(-1)==="/";return e=H(e,!t),e.length===0?t?"/":s?"./":".":(s&&(e+="/"),E.test(e)&&(e+="/"),r?t?`//${e}`:`//./${e}`:t&&!m(e)?`/${e}`:e)},J=(...e)=>{let r="";for(const t of e)if(t)if(r.length>0){const s=r.at(-1)==="/",o=t[0]==="/";s&&o?r+=t.slice(1):r+=s||o?t:`/${t}`}else r+=t;return V(r)},P=e=>{const r=v(e).replace(q,""),t=r.lastIndexOf("/");if(t===-1)return m(e)?"/":".";const s=r.slice(0,t);return E.test(s)?`${s}/`:s||(m(e)?"/":".")};class p extends U{constructor(r,t="UPDATE_NOTIFIER_ERROR",s){super(r,t,s),this.name="UpdateNotifierError"}}const B="last-update-check.json",y={access:(e,r)=>$(e,r),mkdir:(e,r)=>S(e,r),readFile:(async(e,r)=>r===void 0?R(e):R(e,r)),writeFile:(e,r,t)=>I(e,r,t)},O=async(e,r)=>{try{return await e.access(r),!0}catch{return!1}},C=e=>{const r=F(e);if(r===void 0)throw new p("Could not find cache directory","CACHE_DIRECTORY_NOT_FOUND",{packageName:e});return J(r,B)},L=async(e,r=y)=>{const t=C(e);try{if(!await O(r,t))return;const{lastUpdateCheck:s}=JSON.parse(await r.readFile(t,"utf8"));return s}catch{return}},Z=async(e,r=y)=>{const t=C(e),s=P(t);await O(r,s)||await r.mkdir(s,{recursive:!0}),await r.writeFile(t,JSON.stringify({lastUpdateCheck:Date.now()}),"utf8")},W=5e3,Y=async(e,r,t,s=W)=>{const o=t.replace("__NAME__",e),c=512*1024;return await new Promise((u,a)=>{const i=x(o,{timeout:s},n=>{if(n.statusCode!==void 0&&(n.statusCode<200||n.statusCode>=300)){a(new p(`Unexpected status code ${String(n.statusCode)}`,"VERSION_FETCH_ERROR",{distributionTag:r,packageName:e})),n.resume();return}let l="",f=!1;n.on("data",d=>{f||(l+=String(d),l.length>c&&(f=!0,a(new p("Response too large","VERSION_FETCH_ERROR",{distributionTag:r,packageName:e})),n.destroy()))}),n.on("end",()=>{if(!f)try{const d=JSON.parse(l)[r];if(!d){a(new p("Error getting version","VERSION_FETCH_ERROR",{distributionTag:r,packageName:e}));return}u(d)}catch{a(new p("Could not parse version response","VERSION_PARSE_ERROR",{distributionTag:r,packageName:e}))}})});i.on("timeout",()=>{i.destroy(new p("Request timed out","VERSION_FETCH_ERROR",{distributionTag:r,packageName:e}))}),i.on("error",n=>{a(n)})})},Q=async({alwaysRun:e,debug:r,distTag:t="latest",fs:s,pkg:o,registryUrl:c="https://registry.npmjs.org/-/package/__NAME__/dist-tags",timeout:u,updateCheckInterval:a=1e3*60*60*24})=>{const i=await L(o.name,s);if(e||!i||i<Date.now()-a){const n=await Y(o.name,t,c,u);if(await Z(o.name,s),A(n,o.version))return n;r&&console.error(`Latest version (${n}) not newer than current version (${o.version})`)}else r&&console.error(`Too recent to check for a new update. simpleUpdateNotifier() interval set to ${String(a)}ms but only ${String(Date.now()-i)}ms since last check.`)};export{Q as default};
@@ -0,0 +1,4 @@
1
+ import{createRequire as je}from"node:module";import{VERBOSITY_DEBUG as M,POSITIONALS_KEY as Z,VERBOSITY_NORMAL as ee,VERBOSITY_QUIET as Ge,VERBOSITY_VERBOSE as Ye}from"./VERBOSITY_DEBUG-XPultrIA.js";import{t as w}from"./cerebro-error-DWpjBY_M.js";import{c as Q,d as ae,o as ue,e as U,a as He,b as Ke,f as Je,h as Ze,i as Qe}from"./runtime-process-BEw54Ar-.js";import{h as Y}from"./VisulimaError-DTMgXonA-CzaryRgZ.js";import{k as Xe,W as et}from"./split-by-case-BZ6XOTIf.js";import{distance as tt}from"fastest-levenshtein";let Se;const Te=t=>(Se??=je(import.meta.url))(t),W=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,Ue=t=>{if(typeof W<"u"&&W.versions&&W.versions.node){const[e,n]=W.versions.node.split(".").map(Number);if(e>22||e===22&&n>=3||e===20&&n>=16)return W.getBuiltinModule(t)}return Te(t)},{writeFile:Be,stat:Re,rm:ze,readFile:de,readdir:Fe,mkdir:qe,access:We}=Ue("node:fs/promises"),K=[{alias:"v",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}];let S=class extends w{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(", ")}`)}},Ce=class extends w{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}`}},nt=class extends w{unknownOptions;constructor(e,n){const o=e.join(", "),s=`Found unknown ${e.length===1?"option":"options"}: ${o}`;super(s,"UNKNOWN_OPTION",{suggestions:n,unknownOptions:e}),this.name="UnknownOptionError",this.unknownOptions=e,n&&n.length>0&&(this.hint=`Did you mean: ${n.join(", ")}?`)}},ot=class extends w{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)}},it=class{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`);Q().CEREBRO_OUTPUT_LEVEL===String(M)&&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(s){const i=new ot(o.name,`Failed to initialize: ${s instanceof Error?s.message:String(s)}`,s instanceof Error?s: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 s=this.getDependencyOrder();for(const i of s){const l=i[e];if(typeof l=="function"){this.logger.debug(`executing ${e} hook for plugin: ${i.name}`);try{await(e==="afterCommand"?l(n,o):l(n))}catch(a){throw this.logger.error(`Error in ${e} hook for plugin "${i.name}":`,a),a}}}}async executeErrorHandlers(e,n){if(!this.initialized||this.plugins.size===0)return;const o=this.getDependencyOrder();for(const s of o)if(typeof s.onError=="function"){this.logger.debug(`executing error handler for plugin: ${s.name}`);try{await s.onError(e,n)}catch(i){this.logger.error(`Error in error handler for plugin "${s.name}":`,i)}}}getDependencyOrder(){if(this.cachedDependencyOrder!==void 0)return this.cachedDependencyOrder;const e=[],n=new Set,o=new Set,s=i=>{if(n.has(i))return;if(o.has(i))throw new Error(`Circular dependency detected involving plugin "${i}"`);const l=this.plugins.get(i);if(!l)throw new Error(`Plugin "${i}" not found`);if(o.add(i),l.dependencies)for(const a of l.dependencies)s(a);o.delete(i),n.add(i),e.push(l)};for(const i of this.plugins.keys())s(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`)}}};const G=t=>t.type?.name==="Boolean",st=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},me=t=>(G(t)||(t.typeLabel=t.typeLabel??st(t),t.defaultOption&&(t.typeLabel=`${t.typeLabel} (D)`),t.required&&(t.typeLabel=`${t.typeLabel} (R)`)),t),at=new RegExp(/^-([^\d-])$/),rt=new RegExp(/^--(\S+)/),lt=new RegExp(/^-([^\d-]{2,})$/),ct=t=>at.test(t)||rt.test(t)||lt.test(t),dt=(t,e)=>{const n=e[0]&&ct(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}};let ut=class xe extends Y{optionName;value;constructor(e,n,o){super({hint:`Pass a valid ${o} value for '${e}'.`,message:`Invalid ${o} value '${n}' for option '${e}'`,name:"INVALID_VALUE",title:"Invalid Value"}),this.optionName=e,this.value=n,Object.setPrototypeOf(this,xe.prototype)}},mt=class Ie extends Y{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,Ie.prototype)}},he=class ke extends Y{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,ke.prototype)}},ht=class Ee extends Y{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,Ee.prototype)}};class O extends Y{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,O.prototype)}}const B=t=>t===Boolean||typeof t=="function"&&t.name==="Boolean",re=t=>t===Number||typeof t=="function"&&t.name==="Number",pe=t=>t===String||typeof t=="function"&&t.name==="String",fe=(t,e,n)=>{const o=Number(t);if(e&&Number.isNaN(o)&&String(t).trim().toLowerCase()!=="nan")throw new ut(n??"",String(t),"Number");return o},pt=(t,e,n={})=>{const{optionName:o,strictTypes:s}=n;return Array.isArray(t)?B(e)?t.map(Boolean):re(e)?t.map(i=>fe(i,s,o)):pe(e)?t.map(String):t.map(i=>e(String(i))):t===null?null:B(e)?!!t:re(e)?fe(t,s,o):pe(e)?typeof t=="string"?t:String(t):e(typeof t=="string"?t:String(t))},b=(t,e,n,...o)=>{t&&console.debug(`[command-line-args:${n}] ${e}`,...o)},ft=/-([a-z])/g,gt=/^\d+$/,wt=t=>t.codePointAt(0)===95,ge=(t,e)=>Array.isArray(t)?[...t,...e]:[t,...e],we=t=>t==="__proto__"||t==="constructor"||t==="prototype",te=(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]},ye=(t,e,n,o,s)=>{let i=e.get(t)??n.get(t);if(!i&&o){const l=t.toLowerCase();i=o.get(l)??s?.get(l)}return i},yt=(t,e,n,o)=>{const s=n.debug??!1;b(s,"resolveArgs called with options:","resolver",{partial:n.partial,stopAtFirstUnknown:n.stopAtFirstUnknown}),b(s,"Starting argument resolution","resolver"),b(s,"Tokens:","resolver",t),b(s,"Definitions:","resolver",e),b(s,"Processing tokens...","resolver");const i=new Map,l=new Map,a=n.caseInsensitive?new Map:void 0,d=n.caseInsensitive?new Map:void 0,r=n.camelCase?new Map:void 0,m=n.camelCase?new Map:void 0;for(const c of e)if(i.set(c.name,c),c.alias&&l.set(c.alias,c),n.caseInsensitive&&a&&(a.set(c.name.toLowerCase(),c),c.alias&&d&&d.set(c.alias.toLowerCase(),c)),n.camelCase&&r&&m){const u=c.name.replaceAll(ft,(p,_)=>_.toUpperCase());r.set(c.name,u),m.set(u,c.name)}const h=Object.create(null),f=Object.create(null),N=[],P=[],A=new Set;let V=!1;const y=e.find(c=>c.defaultOption),$=e.some(c=>c.group),E=e.find(c=>re(c.type));for(let c=0;c<t.length;c++){const u=t[c];if(u.kind==="option-terminator"){h._unknown=o.slice(u.index),V=!0;break}if(u.kind==="option"&&u.name){let p=ye(u.name,i,l,a,d);!p&&u.value===void 0&&E&&gt.test(u.name)&&(p=E,u.value=u.name,u.name=E.name);let _=!1;if(!p&&n.negation&&u.value===void 0&&u.name.startsWith("no-")){const v=u.name.slice(3),k=ye(v,i,l,a,d);k?.type&&B(k.type)&&(p=k,_=!0)}const g=p?p.name:u.name,x=p?.multiple,I=p?.lazyMultiple;if(Object.hasOwn(f,g)&&f[g]!==void 0&&!x&&!I&&!n.partial)throw new mt(g);if(!p&&n.partial){const v=u.rawName??`--${u.name}${u.value!==void 0&&u.inlineValue?`=${u.value}`:""}`;N.push({index:u.index,value:v});continue}if(!p&&n.stopAtFirstUnknown){h._unknown=o.slice(u.index);break}if(!p&&!n.partial)throw new he(u.name);if(u.value===void 0){const v=t[c+1],k=v?.kind==="option"&&!("name"in v)&&v.value!==void 0,L=v&&p&&!(p.type&&B(p.type))&&(v.kind==="positional"||k),Ve=p&&p.defaultOption&&!p.multiple&&!p.lazyMultiple;if(L&&(!p?.defaultOption||Ve))if(x){let D=c+1;const X=[];for(;D<t.length&&(t[D].kind==="positional"||t[D].kind==="option"&&!("name"in t[D])&&t[D].value!==void 0);)X.push(t[D].value),A.add(t[D].index),D++;f[g]=f[g]===void 0?X:ge(f[g],X),c=D-1}else I?(te(f,g,v.value,!0),A.add(v.index),c++):(f[g]=v.value,A.add(v.index),c++);else p?.type&&B(p.type)?te(f,g,!_,x):(x||I)&&f[g]!==void 0?te(f,g,null,!0):f[g]=x?[]:null}else{let{value:v}=u;if(p?.type&&B(p.type))switch(v){case"":{if(n.partial){const L=`${u.rawName??`--${u.name}`}${u.value?`=${u.value}`:""}`;P.push({index:u.index,value:L}),v=!0}else throw new he(u.name);break}case"false":{v=!1;break}case"true":{v=!0;break}default:v=!0}const k=[v];if(x){let L=c+1;for(;L<t.length&&t[L].kind==="positional";)k.push(t[L].value),A.add(t[L].index),L++;c=L-1}f[g]===void 0?f[g]=x||I?k:v:x||I?f[g]=ge(f[g],k):f[g]=v}}else if(u.kind==="positional"&&n.stopAtFirstUnknown&&!A.has(u.index)&&!y){b(s,`Found unconsumed positional token at index ${String(u.index)}, stopping processing`,"resolver"),h._unknown=o.slice(u.index);break}}for(const[c,u]of Object.entries(f)){const p=i.get(c);p&&(p.multiple||p.lazyMultiple)&&!Array.isArray(u)&&(f[c]=[u])}const z=c=>c.kind==="option"&&!i.has(c.name??"")&&!l.has(c.name??"")&&(!n.caseInsensitive||!a?.has(c.name?.toLowerCase()??"")&&!d?.has(c.name?.toLowerCase()??""));let C=-1,H=Number.POSITIVE_INFINITY;if(n.stopAtFirstUnknown&&!V&&(C=t.findIndex(c=>z(c)),C!==-1&&(H=t[C].index)),y){const c=[],u=[];for(const p of t)p.kind==="positional"&&!A.has(p.index)&&p.index<H&&(c.push(p.value),u.push(p));if(c.length>0){const p=f[y.name],_=y.multiple??y.lazyMultiple;p===void 0?_?(u.forEach(g=>A.add(g.index)),f[y.name]=c):(A.add(u[0].index),f[y.name]=c[0]):_&&(u.forEach(g=>A.add(g.index)),f[y.name]=Array.isArray(p)?[...c,...p]:[...c,p])}}if(!n.partial){for(const c of t)if(c.kind==="positional"&&!A.has(c.index))throw new ht(o[c.index])}if(n.partial&&!n.stopAtFirstUnknown){const c=[...N];for(const u of P)c.push({index:u.index,value:u.value});for(const u of t)u.kind==="positional"&&!A.has(u.index)&&c.push({index:u.index,value:o[u.index]});c.length>0&&(c.sort((u,p)=>u.index-p.index),h._unknown=c.map(u=>u.value))}if(n.stopAtFirstUnknown&&!V){const c=t.findIndex(p=>p.kind==="positional"&&!A.has(p.index));let u=-1;if(C!==-1&&c!==-1?u=Math.min(C,c):C!==-1?u=C:c!==-1&&(u=c),u>=0){const p=t[u].index;h._unknown=o.slice(p)}}for(const[c,u]of Object.entries(f)){const p=n.camelCase?r?.get(c)??c:c,_=i.get(c);_?.type?h[p]=pt(u,_.type,{optionName:_.name,strictTypes:n.strictTypes}):h[p]=u===void 0?null:u}for(const c of e){const u=n.camelCase?r?.get(c.name)??c.name:c.name;!(u in h)&&c.defaultValue!==void 0&&(c.multiple??c.lazyMultiple?h[u]=Array.isArray(c.defaultValue)?[...c.defaultValue]:[c.defaultValue]:h[u]=c.defaultValue)}if($){const c={},u={},p={};for(const g of e)if(g.group){const x=Array.isArray(g.group)?g.group:[g.group];for(const I of x)we(I)||(c[I]??={})}for(const g of Object.keys(h))if(!wt(g)){u[g]=h[g];let x=g;n.camelCase&&(x=m?.get(g)??g);const I=i.get(x);if(I?.group){const v=Array.isArray(I.group)?I.group:[I.group];for(const k of v)we(k)||c[k]&&(c[k][g]=h[g])}else p[g]=h[g]}const _={_all:u};for(const[g,x]of Object.entries(c))_[g]=x;Object.keys(p).length>0&&(_._none=p),h._unknown&&(_._unknown=h._unknown),Object.keys(h).forEach(g=>delete h[g]),Object.assign(h,_)}const ce=Object.defineProperties({},Object.getOwnPropertyDescriptors(h));return b(s,"Final parsed result:","resolver",ce),ce},q="-".codePointAt(0),R="=",vt=R.codePointAt(0),Nt="--",$t="-",bt="--",Pe=t=>t.length>2&&t.startsWith(bt),At=t=>Pe(t)&&!t.includes(R,3),_t=t=>Pe(t)&&t.includes(R,3),Ot=t=>{if(t.length!==2||t.codePointAt(0)!==q||t.codePointAt(1)===q)return!1;const e=t.codePointAt(1);return e!==void 0&&(e<48||e>57)},Ct=t=>{if(t.length<=2||t.codePointAt(0)!==q||t.codePointAt(1)===q)return!1;const e=t.codePointAt(1);return!(e!==void 0&&e>=48&&e<=57)},xt=t=>{const e=[];let n=0,o=[],s=0,i=-1,l=0;for(;s<o.length||n<t.length;){let a;if(s<o.length?(a=o[s],s++):(a=t[n],n++),l>0?l--:i++,a===Nt){e.push({index:i,kind:"option-terminator"});const d=[...o.slice(s),...t.slice(n)],r=d.map((m,h)=>({index:i+h+1,kind:"positional",value:m}));e.push(...r),i+=d.length;break}if(Ot(a)){const d=a.charAt(1);e.push({index:i,kind:"option",name:d,rawName:a});continue}if(Ct(a)&&!a.includes(R)){const d=[];let r="",m=!1;for(let h=1;h<a.length;h++){const f=a.charAt(h);m?r+=f:f.codePointAt(0)===vt?m=!0:d.push(`${$t}${f}`)}if(m)if(d.length>0){const h=d.pop();d.push(`${h}=${r}`)}else d.push(r);o=s<o.length?[...d,...o.slice(s)]:d,s=0,l=d.length;continue}if(At(a)){const d=a.slice(2);e.push({index:i,kind:"option",name:d,rawName:a});continue}if(_t(a)){const d=a.indexOf(R),r=a.slice(2,d),m=a.slice(d+1);e.push({index:i,inlineValue:!0,kind:"option",name:r,rawName:a,value:m});continue}if(a.length>2&&a.codePointAt(0)===q&&a.codePointAt(1)!==q&&a.includes(R)){const d=a.indexOf(R),r=a.charAt(1),m=a.slice(d+1);e.push({index:i,inlineValue:!0,kind:"option",name:r,rawName:a,value:m});continue}e.push({index:i,kind:"positional",value:a})}return e},It=/\d/,kt=t=>typeof t=="function",Et=(t,e,n)=>{const o=n?.debug??!1;b(o,"Validating definitions:","validation",t,"caseInsensitive:",e);const s=new Set,i=new Set,l=new Set,a=new Set;let d=0;for(const r of t){if(b(o,"Checking definition:","validation",r),!r.name)throw b(o,"Validation failed: name is required","validation"),new O("Invalid option definition: name is required");if(typeof r.name!="string")throw new O("Invalid option definition: name must be a string");if(r.name.trim()==="")throw new O("Invalid option definition: name cannot be empty");const m=e?r.name.toLowerCase():"";if(s.has(r.name)||e&&l.has(m))throw new O(`Invalid option definition: duplicate name '${r.name}'`);if(i.has(r.name)||e&&a.has(m))throw new O(`Invalid option definition: name '${r.name}' conflicts with an existing alias`);if(s.add(r.name),e&&l.add(m),r.alias!==void 0){if(typeof r.alias!="string")throw new O("Invalid option definition: alias must be a string");if(r.alias.length!==1)throw new O("Invalid option definition: alias must be a single character");if(It.test(r.alias))throw new O("Invalid option definition: alias cannot be numeric");if(r.alias==="-")throw new O('Invalid option definition: alias cannot be "-"');const h=e?r.alias.toLowerCase():"";if(i.has(r.alias)||e&&a.has(h))throw new O(`Invalid option definition: duplicate alias '${r.alias}'`);if(s.has(r.alias)||e&&l.has(h))throw new O(`Invalid option definition: alias '${r.alias}' conflicts with an existing option name`);i.add(r.alias),e&&a.add(h)}if(r.defaultOption&&(d++,r.type!==void 0&&B(r.type)))throw new O("Invalid option definition: defaultOption cannot be Boolean type");if(r.type!==void 0&&!(r.type===Boolean||r.type===Number||r.type===String||typeof r.type=="function"&&kt(r.type)))throw new O("Invalid option definition: invalid type")}if(d>1)throw b(o,"Validation failed: multiple defaultOptions not allowed","validation"),new O("Invalid option definition: multiple defaultOptions not allowed");b(o,"Validation completed successfully","validation")};function Pt(t,e={}){const n=e.debug??!1;b(n,"Starting command-line-args parsing","index"),b(n,"Options:","index",e);const o={...e};o.stopAtFirstUnknown&&(o.partial=!0);const s=Array.isArray(t)?t:[t];b(n,"Normalized definitions:","index",s),Et(s,o.caseInsensitive,n?o:void 0);let{argv:i}=o;i??=process.argv.slice(2),b(n,"Using argv:","index",i);let l=i;o.caseInsensitive&&(l=i.map(r=>{if(r.startsWith("--")){const m=r.indexOf("="),h=(m===-1?r.slice(2):r.slice(2,m)).toLowerCase();return m===-1?`--${h}`:`--${h}${r.slice(m)}`}if(r.startsWith("-")&&!r.startsWith("--")&&r.length>1){const m=r.indexOf("="),h=m===-1?r.slice(1):r.slice(1,m);if(!h)return r;const f=h.toLowerCase();return m===-1?`-${f}`:`-${f}${r.slice(m)}`}return r}));const a=xt(l.map(String));b(n,"Tokenized arguments:","index",a);const d=yt(a,s,o,i);return b(n,"Command-line-args parsing completed","index"),d}class Lt{result;argv;options;argument;command;commandName;env;logger;console;fs;process;runtime;rawUnknown;constructor(e,n){this.commandName=e,this.command=n}}let ne=class extends w{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)}};const Dt=/^-{1,2}(\w+)(=(.+))?$/,Le=(t,e,n,o)=>{const s=Dt.exec(t);if(s===null)return{};const i=s[1];if(!i)return{};const l=n&&o?n.get(i)??o.get(i):e.find(a=>a.name===i||a.alias===i);return l!==void 0?{argName:l.name,argValue:s[3],option:l}:{}},ve=(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)},Mt=new Set(["0","1","false","true"]),Vt=(t,e,n,o)=>{if(e.length===0||t.length===0)return{};const s=(i,l)=>{const{argName:a,argValue:d,option:r}=Le(l,e,n,o),{lastOption:m}=i;return r&&G(r)&&d&&a?i.partial[a]=ve(d,r):i.lastName&&m&&G(m)&&Mt.has(l)&&(i.partial[i.lastName]=ve(l,m)),{lastName:a,lastOption:r,partial:i.partial}};return t.reduce(s,{partial:{}}).partial},jt=new Set(["0","1","false","true"]),St=(t,e,n,o)=>{if(e.length===0||t.length===0)return t;const s=(i,l)=>{const{argValue:a,option:d}=Le(l,e,n,o),{lastOption:r}=i;if(r&&G(r)&&jt.has(l)){const{args:m}=i;return{args:m.slice(0,-1)}}return d&&G(d)&&a?{args:i.args}:{args:[...i.args,l],lastOption:d}};return t.reduce(s,{args:[]}).args},Ne=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()]},Tt=t=>{if(t===void 0)return;const e=t.toLowerCase().trim();return e==="true"||e==="1"||e==="yes"||e==="on"},Ut=(t,e)=>{if(!t.type)return e;if(e!==void 0){if(t.type===Boolean||typeof t.type=="function"&&t.type.name==="Boolean")return Tt(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)}},Bt=/_./g,Rt=/^[A-Z]/,zt=t=>t.toLowerCase().replaceAll(Bt,e=>e[1]?.toUpperCase()??e).replace(Rt,e=>e.toLowerCase()),Ft=(t,e=Q())=>{if(!t||t.length===0)return{};const n={};for(const o of t){const s=e[o.name],i=Ut(o,s),l=i===void 0?o.defaultValue:i,a=zt(o.name);n[a]=l}return n},qt=t=>{const e=new Map,n=new Map;for(const o of t)if(e.set(o.name,o),o.alias){const s=Array.isArray(o.alias)?o.alias:[o.alias];for(const i of s)n.set(i,o)}return{optionMapByAlias:n,optionMapByName:e}},De=async t=>{if(typeof t.__resolvedExecute__=="function")return t.__resolvedExecute__;if(typeof t.loader!="function")throw new ne(t.name,"no execute or loader defined");let e;try{e=await t.loader()}catch(o){throw new ne(t.name,o instanceof Error?o.message:String(o),o)}const n=e.default;if(typeof n!="function")throw new ne(t.name,"loader did not return a module with a default-exported handler function");return t.__resolvedExecute__=n,n},Wt=(t,e,n,o,s)=>{const i=new Lt(t.name,t),{_all:l,_unknown:a,positionals:d}=e,r=Object.keys(n).length>0?{...l,...n}:l;Z in r&&delete r[Z],i.argument=d?.[Z]??[],i.rawUnknown=[...a??[]];const m=Object.keys(o).length>0;return i.options=m?{...r,...o}:r,i.env=Ft(t.env,s),i},Gt=(t,e,n)=>{const o=t.options??[],s=o.length>0;let i=Ne(s?[...o,...n]:n);if(i.length>0){for(const r of i)if(r.multiple&&r.lazyMultiple)throw new Error(`Argument "${r.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 l,a;if(s){const{optionMapByAlias:r,optionMapByName:m}=qt(o);l=St(e,o,m,r),a=Vt(e,o,m,r)}else l=e,a={};const d=Pt(i,{argv:l,camelCase:!0,partial:!0,stopAtFirstUnknown:!0});return{arguments_:i,booleanValues:a,parsedArgs:d}},oe=async(t,e,n)=>typeof t.execute=="function"?t.execute(e):(await De(t))(e),Yt=(t,e)=>typeof t!="string"||t===""?"":t[0].toLowerCase()+t.slice(1),Ht=(t,e)=>typeof t!="string"||t===""?"":t[0].toUpperCase()+t.slice(1),Kt=(t,e)=>{const{length:n}=t;if(n===0)return"";if(n===1)return t[0];const o=[];let s="",i="";for(let l=0;l<n;l++){const a=t[l];if(Xe.test(a)){s?(o.push(s+i+a),s="",i=""):(o.length>0&&o.push(e),s=a);continue}s?(i&&(i+=e),i+=a):(o.length>0&&o.push(e),o.push(a))}return o.join("")},F=(t,e)=>{if(typeof t!="string"||!t)return"";let n=!0;return Kt(et(t,{handleAnsi:e?.handleAnsi,handleEmoji:e?.handleEmoji,knownAcronyms:e?.knownAcronyms,locale:e?.locale,normalize:e?.normalize,separators:void 0,stripAnsi:e?.stripAnsi,stripEmoji:e?.stripEmoji}).map(s=>{const i=s,l=i.toLowerCase();return n?(n=!1,Yt(l)):Ht(l)}),"")};let Jt=class extends w{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(", ")}`}},Zt=class extends w{choices;option;value;constructor(e,n,o){super(`Invalid value "${n}" for option "${e}". Allowed values: ${o.join(", ")}`,"INVALID_CHOICE",{choices:o,option:e,value:n}),this.name="InvalidChoiceError",this.option=e,this.value=n,this.choices=o,this.hint=`Use one of: ${o.map(s=>`--${e} ${s}`).join(", ")}`}};const $e=(t,e,n=!1)=>{const o=[],s=e._all??e;for(const i of t){if(!n&&!i.required)continue;const l=i.__camelCaseName__??i.name;if(s[l]===void 0){if(i.type?.name==="Boolean"){e[l]=!1;continue}o.push(i)}}return o},Qt=(t,e)=>e.includes(t)?!0:Math.abs(t.length-e.length)>t.length/2?!1:tt(t,e)<=t.length/3,j=(t,e)=>{const n=t.toLowerCase();return e.filter(o=>Qt(o.toLowerCase(),n))},Xt=(t,e)=>{const n=[];if(t._unknown&&t._unknown.forEach(o=>{const s=o.startsWith("--");let i=`Found unknown ${s?"option":"argument"} "${o}"`;if(s){const l=j(o.replace("--",""),(e.options??[]).map(a=>a.name));if(l.length>0){const[a,...d]=l.map(r=>`--${r}`);i+=d.length>0?`, did you mean ${a??""} or ${d.join(", ")}?`:`, did you mean ${a??""}?`}}n.push(i)}),n.length>0)throw new Error(n.join(`
2
+ `))},en=(t,e,n)=>{const o=n.__requiredOptions__,s=o?$e(o,e,!0):$e(t,e,!1);if(s.length>0)throw new Jt(n.name,s.map(i=>i.name));e._unknown&&e._unknown.length>0&&!n.argument&&Xt(e,n)},tn=(t,e,n)=>{const o=n.__conflictingOptions__??t.filter(s=>s.conflicts!==void 0);if(o.length>0){const s=o.find(i=>{const l=i.__camelCaseName__??F(i.name);return Array.isArray(i.conflicts)?i.conflicts.some(a=>e[F(a)]!==void 0)&&e[l]!==void 0:e[F(i.conflicts)]!==void 0&&e[l]!==void 0});if(s)throw new Ce(s.name,typeof s.conflicts=="string"?s.conflicts:s.conflicts?.[0]??"unknown")}},nn=(t,e)=>{const n=e.options;if(n)for(const o of n){if(!o.choices||o.choices.length===0)continue;const s=o.__camelCaseName__??F(o.name),i=t[s];if(i==null)continue;const l=Array.isArray(i)?i:[i];for(const a of l){const d=String(a);if(!o.choices.includes(d))throw new Zt(o.name,d,o.choices)}}},on=t=>{if(!Array.isArray(t.options))return;const e=new Map,n=new Map;for(const s of t.options){if(s.name){const i=e.get(s.name)??[];i.push(s),e.set(s.name,i)}if(typeof s.alias=="string"&&s.alias.length>0){const i=n.get(s.alias)??[];i.push(s),n.set(s.alias,i)}else if(Array.isArray(s.alias)){for(const i of s.alias)if(i.length>0){const l=n.get(i)??[];l.push(s),n.set(i,l)}}}const o=[];for(const[s,i]of e)i.length>1&&o.push(`Duplicate option name "${s}" in command "${t.name}": ${JSON.stringify(i)}`);for(const[s,i]of n)i.length>1&&o.push(`Duplicate option alias "-${s}" used by options ${i.map(l=>`"${l.name}"`).join(", ")} in command "${t.name}"`);if(o.length>0)throw new Error(o.join(`
3
+ `))},sn=(t,e)=>{if(e.length===0)return{argv:[],commandPath:void 0};const n=[];let o;for(let s=1;s<=e.length;s+=1){const i=e[s-1];if(i===void 0||i.startsWith("-"))break;n.push(i);const l=n.join(" ");t.has(l)&&(o={commandPath:[...n],depth:s})}return o?{argv:e.slice(o.depth),commandPath:o.commandPath}:{argv:e,commandPath:void 0}},T=t=>t.join(" "),be=(t,e)=>e&&e.length>0?[...e,t]:[t],an=/^no-/,rn=t=>{t.options?.forEach(e=>{e.__camelCaseName__=F(e.name)})},ln=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 s=o.name.replace(an,"");if(!e.has(s)){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:s};n.push(i),e.add(s)}}n.length>0&&t.options.push(...n)},cn=(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 l=F(i.name);o.set(l,i)}const s=Object.keys(n).filter(i=>o.has(i));if(s.length!==0)for(const i of s){const l=i.charAt(2);if(!l)continue;const a=l.toLowerCase()+i.slice(3),d=o.get(i);d&&(d.__negated__=!0),n[a]=!n[i],Reflect.deleteProperty(n,i)}},dn=(t,e)=>{if(!e.options||e.options.length===0)return;const n=new Map;for(const s of e.options)s.__camelCaseName__&&s.__negated__===void 0&&s.implies!==void 0&&n.set(s.__camelCaseName__,s);if(n.size===0)return;const{options:o}=t;for(const s of Object.keys(o)){const i=n.get(s);if(i?.implies){const{implies:l}=i;for(const[a,d]of Object.entries(l))o[a]===void 0&&(o[a]=d)}}},un=()=>!!process.versions.electron,mn=()=>un()&&!process.defaultApp,hn=()=>mn()?0:1,pn=t=>t.slice(hn()+1),fn=" ",gn=(t,e)=>t===e?!0:t.length!==e.length?!1:t.every((n,o)=>n===e[o]),wn=t=>{if(typeof t=="string")return t.split(fn);const e=ae();return gn(t,e)?pn(t):t},yn=t=>{const e=i=>{t.error(`Uncaught exception: ${i.message||i}`),i.stack&&t.error(i.stack),U(1)},n=(i,l)=>{if(i instanceof Error)t.error(`Promise rejection: ${i.message||i}`),i.stack&&t.error(i.stack);else{let a;if(typeof i=="string")a=i;else try{a=JSON.stringify(i)}catch{a=String(i)}t.error(`Promise rejection: ${a}`)}U(1)},o=ue("uncaughtException",e),s=ue("unhandledRejection",n);return()=>{o(),s()}},Ae=100,vn=/^[a-z][\w-]*$/i,le=(t,e)=>{if(typeof t!="string"||t.trim().length===0)throw new w(`${e} must be a non-empty string`,"INVALID_INPUT",{fieldName:e,value:t});return t.trim()},_e=(t,e)=>{if(!Array.isArray(t)||!t.every(n=>typeof n=="string"))throw new w(`${e} must be an array of strings`,"INVALID_INPUT",{fieldName:e,value:t});return t},ie=(t,e)=>{if(typeof t!="object"||t===null)throw new w(`${e} must be an object`,"INVALID_INPUT",{fieldName:e,value:t});return t},J=t=>{const e=le(t,"Command name");if(e.length>Ae)throw new w(`Command name is too long (maximum ${String(Ae)} characters)`,"INVALID_COMMAND_NAME",{commandName:e,length:e.length});if(e.includes("..")||e.includes("/")||e.includes("\\")||e.includes(";")||e.includes("|")||e.includes("&"))throw new w(`Command name "${e}" contains invalid characters`,"INVALID_COMMAND_NAME",{commandName:e});if(!vn.test(e))throw new w(`Command name "${e}" must start with a letter and contain only letters, numbers, hyphens, and underscores`,"INVALID_COMMAND_NAME",{commandName:e});return e},Nn=new Set([`
4
+ `,"\r"," ","\0",'"',"$","&","'","(",")",";","<",">","[","\\","]","`","{","|","}"]),$n=(t,e={})=>{if(typeof t!="string")throw new TypeError("Argument must be a string");const n=typeof e=="boolean"?{checkDangerousChars:e}:e,o=n.maxArgumentLength??1e6;if(Number.isFinite(o)&&o>0&&t.length>o)throw new Error(`Argument is too long (maximum ${String(o)} characters)`);if(n.checkDangerousChars){for(const s of t)if(Nn.has(s))throw new Error(`Argument contains dangerous character: ${s}`)}return n.trim?t.trim():t},Oe=(t,e={})=>{if(!Array.isArray(t))throw new TypeError("Arguments must be an array");const n=typeof e=="boolean"?{checkDangerousChars:e}:e,o=n.maxArguments??1e5;if(Number.isFinite(o)&&o>0&&t.length>o)throw new Error(`Too many arguments (maximum ${String(o)})`);return t.map(s=>$n(s,n))},bn=/^-([^\d-])$/,An=/^--(\S+)/,_n=/^-([^\d-]{2,})$/,se=t=>bn.test(t)||An.test(t)||_n.test(t),On={access:(t,e)=>We(t,e),mkdir:(t,e)=>qe(t,e),readdir:t=>Fe(t),readFile:(async(t,e)=>e===void 0?de(t):de(t,e)),rm:(t,e)=>ze(t,e),stat:t=>Re(t),writeFile:(t,e,n)=>Be(t,e,n)},Cn=(t,e,n)=>{const o=e.indexOf("--"),s=o===-1?new Set:new Set(e.slice(o+1)),i=n.filter(d=>d.startsWith("--")&&d!=="--"&&!s.has(d));if(i.length===0)return;const l=(t.options??[]).map(d=>d.name),a=i.flatMap(d=>j(d.slice(2),l).map(r=>`--${r}`));throw new nt(i,a)};class Me{#t;#e;#d;#m;#h;#p;#_;#O;#C;#N;#x;#$;#I;#b=ee;#u;#n;#o;#i;#s;#a;#k=!1;#E;#P=!1;#f;#g;#w;#l=[];#S(){return this.#f===void 0&&(this.#f=[...this.#o.keys()]),this.#f}#L(){return this.#g===void 0&&(this.#g=[...this.#n.keys()]),this.#g}#r(){return this.#w===void 0&&(this.#w=[...this.#S(),...this.#L()]),this.#w}#D(){return this.#l.length===0?K:[...K,...this.#l]}#M(){this.#f=void 0,this.#g=void 0,this.#w=void 0}#A(){if(this.#d===void 0){const e=wn(this.#e.argv);this.#d=Oe(e,{maxArguments:this.#$}),this.#T()}return this.#d}#y(){return this.#N??Q()}#v(e){this.#b=e,this.#y().CEREBRO_OUTPUT_LEVEL=String(e)}#c(){return this.#b}#T(){if(!this.#d)return;let e=!1;for(const n of this.#d){if(n==="--quiet"||n==="-q"){this.#v(Ge),e=!0;break}if(n==="--verbose"||n==="-v"){this.#v(Ye),e=!0;break}if(n==="--debug"){this.#v(M),e=!0;break}}e||this.#v(Object.hasOwn(this.#y(),"DEBUG")?M:ee)}#U(){this.#P||(this.#E=yn(this.#t),this.#P=!0)}#B(){return{arch:Ke(),argv:this.#A(),cwd:this.#m,env:this.#N??Q(),exit:this.#C??(e=>U(e??0)),platform:He(),stdin:this.#x}}#V(e,n,o,s){this.#c()===M&&this.#t.debug(`command '${s}' found, parsing command args: ${n.join(", ")}`);const{arguments_:i,booleanValues:l,parsedArgs:a}=Gt(e,n,this.#D()),d=Object.keys(l).length>0;let r=a;d&&(r={...a,_all:{...a._all,...l}}),en(i,r,e);const m=Wt(e,a,l,o,this.#y());m.runtime=this,m.argv=this.#A(),m.fs=this.#O??On,m.process=this.#B(),m.console=this.#t;const h=e.options&&e.options.length>0;if(h&&e.options){const f=e.options.filter(N=>N.name.startsWith("no-"));for(const N of f){const P=N.name.slice(3),A=`--${N.name}`,V=`--${P}`,y=n.includes(A),$=n.includes(V);if(y&&$)throw new Ce(P,N.name)}}return h&&(cn(m,e),dn(m,e)),tn(i,m.options,e),nn(m.options,e),this.#I&&Cn(e,n,m.rawUnknown),this.#c()===M&&(this.#t.debug("command options parsed from options:"),this.#t.debug(JSON.stringify(m.options,null,2)),this.#t.debug("command argument parsed from argument:"),this.#t.debug(JSON.stringify(m.argument,null,2))),{arguments_:i,booleanValues:l,commandArgs:r,parsedArgs:a,toolbox:m}}async#j(e,n,o){const s=this.getPluginManager();try{!this.#k&&s.hasPlugins()&&(await s.init({cli:this,cwd:this.#m,logger:this.#t}),this.#k=!0),await s.executeLifecycle("execute",n),await s.executeLifecycle("beforeCommand",n);let i;const l=o.global;if(l?.help){const a=this.#n.get("help");if(!a)throw new w("Help command not found","COMMAND_NOT_FOUND");i=await oe(a,n)}else if(l?.version??l?.V){const a=this.#n.get("version");if(!a)throw new w("Version command not found","COMMAND_NOT_FOUND");i=await oe(a,n)}else i=await oe(e,n);return await s.executeLifecycle("afterCommand",n,i),i}catch(i){throw await s.executeErrorHandlers(i,n),i}}constructor(e,n={}){if(typeof e!="string"||e.trim().length===0)throw new w("CLI name must be a non-empty string","INVALID_INPUT",{cliName:e});this.#h=e.trim();const o=n.argv??ae(),s=n.cwd??Je();if(this.#e={...n,argv:o,cwd:s},this.#e.argv&&!Array.isArray(this.#e.argv))throw new w("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 w("CLI cwd option must be a string","INVALID_INPUT",{cwd:this.#e.cwd});if(this.#e.packageName&&typeof this.#e.packageName!="string")throw new w("CLI packageName option must be a string","INVALID_INPUT",{packageName:this.#e.packageName});if(this.#e.packageVersion&&typeof this.#e.packageVersion!="string")throw new w("CLI packageVersion option must be a string","INVALID_INPUT",{packageVersion:this.#e.packageVersion});if(typeof this.#e.logger=="object"){const h=["debug","error","info","log","warn"],f=[],N=this.#e.logger;for(const P of h)typeof N[P]!="function"&&f.push(P);if(f.length>0)throw new w(`Logger object is missing required methods: ${f.join(", ")}`,"INVALID_INPUT",{logger:this.#e.logger,missingMethods:f});this.#t=this.#e.logger}else this.#t={...console,debug:(...h)=>{this.#c()===M&&console.debug(...h)}};this.#p=this.#e.packageVersion,this.#_=this.#e.packageName,this.#m=this.#e.cwd,this.#s="help",this.#a={};const i=n.fs;if(i!==void 0&&(typeof i!="object"||i===null))throw new w("CLI fs option must be an object implementing the CerebroFs interface","INVALID_INPUT",{fs:n.fs});const l=n.exit;if(l!==void 0&&typeof l!="function")throw new w("CLI exit option must be a function","INVALID_INPUT",{exit:n.exit});const a=n.env;if(a!==void 0&&(typeof a!="object"||a===null))throw new w("CLI env option must be a record of string keys","INVALID_INPUT",{env:n.env});const d=n.stdin;if(d!==void 0&&typeof d!="string")throw new w("CLI stdin option must be a string","INVALID_INPUT",{stdin:n.stdin});this.#O=n.fs,this.#C=n.exit,this.#N=n.env,this.#x=n.stdin??"",this.#$=n.maxArguments,this.#I=n.strictOptions??!1;const r=this.#y().CEREBRO_OUTPUT_LEVEL,m=r===void 0?Number.NaN:Number(r);this.#b=Number.isNaN(m)?ee:m,this.#n=new Map,this.#o=new Map,this.#i=new Map}setCommandSection(e){return this.#a=e,this}getCommandSection(){return this.#a.header||(this.#a.header=`${this.#h}${this.#p?` v${this.#p}`:""}`),this.#a}setDefaultCommand(e){return this.#s=e,this}get defaultCommand(){return this.#s}addCommand(e){ie(e,"Command"),J(e.name);const n=typeof e.execute=="function",o=typeof e.loader=="function";if(n&&o)throw new w(`Command "${e.name}" cannot define both "execute" and "loader" — choose one`,"INVALID_COMMAND",{commandName:e.name});if(!n&&!o)throw new w(`Command "${e.name}" must define either "execute" or "loader"`,"INVALID_COMMAND",{commandName:e.name});e.alias&&(typeof e.alias=="string"?J(e.alias):_e(e.alias,"Command alias").forEach(r=>J(r))),e.argument&&ie(e.argument,"Command argument"),e.options&&ie(e.options,"Command options"),e.commandPath&&(_e(e.commandPath,"Command commandPath"),e.commandPath.forEach(r=>{J(r)}));const s=be(e.name,e.commandPath),i=T(s);if(this.#o.has(i))throw new w(`Command with path "${i}" already exists`,"DUPLICATE_COMMAND",{commandName:e.name,commandPath:e.commandPath});const l=Array.isArray(e.commandPath)&&e.commandPath.length>0,a=this.#n.get(e.name),d=a!==void 0&&(a.commandPath===void 0||a.commandPath.length===0);if(!l&&d)throw new w(`Command with name "${e.name}" already exists`,"DUPLICATE_COMMAND",{commandName:e.name});if(e.options)for(const r of e.options)me(r);if(on(e),ln(e),rn(e),e.options&&(e.__conflictingOptions__=e.options.filter(r=>r.conflicts!==void 0),e.__requiredOptions__=e.options.filter(r=>r.required===!0)),l&&a!==void 0)this.#n.set(i,e);else{if(!l&&a!==void 0&&!d){const r=be(a.name,a.commandPath);this.#n.set(T(r),a)}this.#n.set(e.name,e)}if(this.#o.set(i,s),this.#i.set(i,e),this.#M(),e.alias!==void 0){const r=typeof e.alias=="string"?[e.alias]:e.alias;for(const m of r){if(this.#c()===M&&this.#t.debug("adding alias",m),this.#n.has(m))throw new w(`Command alias "${m}" conflicts with existing command`,"DUPLICATE_COMMAND",{alias:m,commandName:e.name});this.#n.set(m,e)}}return this}addGlobalOption(e){const n=e,o=new Set(K.map(i=>i.name)),s=new Set(K.map(i=>i.alias).filter(Boolean));if(o.has(n.name))throw new w(`Cannot add global option "--${n.name}": it conflicts with a built-in global option`,"DUPLICATE_OPTION",{optionName:n.name});if(n.alias&&s.has(n.alias))throw new w(`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.#l.map(i=>i.name)).has(n.name))throw new w(`Global option "--${n.name}" has already been added`,"DUPLICATE_OPTION",{optionName:n.name});return n.group="global",me(n),this.#l.push(n),this}getGlobalOptions(){return this.#D()}addPlugin(e){return this.getPluginManager().register(e),this}getPluginManager(){return this.#u?this.#u:(this.#u=new it(this.#t),this.#u.register({description:"Attaches the logger to the toolbox",execute:e=>{e.logger=this.#t,e.console=e.logger},name:"logger"}),this.#u)}getCliName(){return this.#h}getPackageVersion(){return this.#p}getPackageName(){return this.#_}getCommands(){return this.#n}getCwd(){return this.#m}dispose(){this.#E?.()}async run(e={}){const{autoDispose:n=!0,shouldExitProcess:o=!0,...s}=e;if(!this.#n.has("help")){const{default:y}=await import("../commands/help-command.js");this.addCommand(new y(this.#n))}const i=this.#L(),l=this.#o;this.#U();const a=this.#A();let d,r=[...a];this.#c()===M&&(this.#t.debug(`process.execPath: ${Ze()}`),this.#t.debug(`process.execArgv: ${Qe().join(" ")}`),this.#t.debug(`process.argv: ${ae().join(" ")}`));const m=sn(l,[...a]);if(m.commandPath)d=m.commandPath,r=m.argv;else{if(a.length>1&&a[0]&&a[1]&&!se(a[0])&&!se(a[1])){const $=[];let E=0;for(;E<a.length;){const C=a[E];if(!C||se(C))break;$.push(C),E+=1}const z=T($);if($[0]&&!i.includes($[0])){const C=this.#r(),H=j(z,C);throw new S(z,H)}}let y;try{y=dt([null,...i],[...a])}catch($){if($ instanceof Error&&$.name==="INVALID_COMMAND"&&"command"in $){const E=$.command,z=this.#r(),C=j(E,z);throw new S(E,C)}throw $}y.command&&(d=[y.command],r=y.argv)}if(!d)if(this.#s)d=[this.#s];else{const y=this.#r();throw new S("",y)}const h=T(d),f=this.#o.get(h);let N;if(f){if(N=this.#i.get(h),!N||T(f)!==h){const y=this.#r(),$=j(h,y);throw new S(h,$)}}else{const y=d.at(-1);if(N=y?this.#n.get(y):void 0,!N){const $=this.#r(),E=j(h,$);throw new S(h,E)}}if(typeof N.execute!="function"&&typeof N.loader!="function")return this.#t.error(`Command "${N.name}" has no function to execute.`),o?U(1):void 0;const P=r;let A,V;try{({commandArgs:A,toolbox:V}=this.#V(N,P,s,h))}catch(y){if(this.#t.error(y),o)return U(1);throw y}try{return await this.#j(N,V,A),o?U(0):void 0}catch(y){if(o)return this.#t.error(y),U(1);throw y}finally{n&&this.dispose()}}async runCommand(e,n={}){const{argv:o=[],...s}=n;le(e,"Command name");const i=e.split(" ").filter(Boolean),l=T(i),a=this.#o.get(l)?this.#i.get(l):this.#n.get(e);if(!a){const h=this.#r(),f=j(l||e,h);throw new S(e,f)}if(typeof a.execute!="function"&&typeof a.loader!="function")throw new w(`Command "${a.name}" has no function to execute`,"INVALID_COMMAND",{commandName:a.name});const d=[...Oe(o,{maxArguments:this.#$})];this.#c()===M&&this.#t.debug(`running command '${e}' programmatically with args: ${d.join(", ")}`);const{commandArgs:r,toolbox:m}=this.#V(a,d,s,l||e);return this.#j(a,m,r)}clone(e){const n={...this.#e,...e},o=new Me(this.#h,n);for(const[s,i]of this.#n)o.#n.set(s,i);for(const[s,i]of this.#o)o.#o.set(s,[...i]);for(const[s,i]of this.#i)o.#i.set(s,i);for(const s of this.#l)o.#l.push(s);return o.#s=this.#s,o.#a={...this.#a},o.#M(),o}async getAction(e){le(e,"Command name");const n=e.split(" ").filter(Boolean),o=T(n),s=this.#o.get(o)?this.#i.get(o):this.#n.get(e);if(!s){const i=this.#r(),l=j(o||e,i);throw new S(e,l)}if(typeof s.execute=="function")return s.execute;if(typeof s.loader=="function")return De(s);throw new w(`Command "${s.name}" has no execute or loader defined`,"INVALID_COMMAND",{commandName:s.name})}}export{Me as Cli};
@@ -0,0 +1,76 @@
1
+ import{t as P}from"./renderError-BISXNU8L-B47ZikMV.js";import{S as fe,W as pe,X as me,Y as de,G as ye,R as he}from"./renderError-BISXNU8L-B47ZikMV.js";import{h as be,c as ve}from"./VisulimaError-DTMgXonA-CzaryRgZ.js";const E=(e,r)=>{let t=0,n=r.length-2;for(;t<n;){const o=t+(n-t>>1);if(e<r[o])n=o-1;else if(e>=r[o+1])t=o+1;else{t=o;break}}return t},T=/\n|\r(?!\n)/,I=e=>e.split(T).reduce((r,t)=>(r.push(r.at(-1)+t.length+1),r),[0]),G=(e,r,t)=>{const n=t?.skipChecks??!1;if(!n&&(!Array.isArray(e)&&typeof e!="string"||(typeof e=="string"||Array.isArray(e))&&e.length===0))return{column:0,line:0};if(!n&&(typeof r!="number"||typeof e=="string"&&r>=e.length||Array.isArray(e)&&r+1>=e.at(-1)))return{column:0,line:0};if(typeof e=="string"){const a=I(e),s=E(r,a);return{column:r-a[s]+1,line:s+1}}const o=E(r,e);return{column:r-e[o]+1,line:o+1}},Q=({applicationType:e,error:r,file:t})=>`You are a very skilled ${t.language??"unknown"} programmer.
2
+
3
+ ${e?`You are working on a ${e} application.`:""}
4
+
5
+ Use the following context to find a possible fix for the exception message at the end. Limit your answer to 4 or 5 sentences. Also include a few links to documentation that might help.
6
+
7
+ Use this format in your answer, make sure links are json:
8
+
9
+ FIX
10
+ insert the possible fix here
11
+ ENDFIX
12
+ LINKS
13
+ {"title": "Title link 1", "url": "URL link 1"}
14
+ {"title": "Title link 2", "url": "URL link 2"}
15
+ ENDLINKS
16
+ ---
17
+
18
+ Here comes the context and the exception message:
19
+
20
+ Line: ${String(t.line)}
21
+
22
+ File:
23
+ ${t.file}
24
+
25
+ Snippet including line numbers:
26
+ ${t.snippet??""}
27
+
28
+ Exception class:
29
+ ${r.name}
30
+
31
+ Exception message:
32
+ ${r.message}`,d=e=>e.replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;").replaceAll('"',"&quot;").replaceAll("'","&#39;"),_=e=>{try{const{protocol:r}=new URL(e);return r==="http:"||r==="https:"}catch{return!1}},$=(e,r,t)=>{const n=t.indexOf(e);if(n===-1)return"";const o=n+e.length,a=t.indexOf(r,o);return a===-1?"":t.slice(o,a).trim()},Z=e=>{const r=$("FIX","ENDFIX",e);if(!r)return["No solution found.",'Provide this response to the Maintainer of <a href="https://github.com/visulima/visulima/issues/new?assignees=&labels=s%3A+pending+triage%2Cc%3A+bug&projects=&template=bug_report.yml" target="_blank" rel="noopener noreferrer" class="text-blue-500 hover:underline inline-flex items-center text-sm">@visulima/error</a>.',`"${d(e)}"`].join("</br></br>");const t=$("LINKS","ENDLINKS",e),n=t?t.split(`
33
+ `).map(a=>a.trim()).filter(Boolean).map(a=>{try{const s=JSON.parse(a);return typeof s.url=="string"&&typeof s.title=="string"&&_(s.url)?{title:s.title,url:s.url}:void 0}catch{return}}).filter(a=>a!==void 0):[],o=n.length>0?`
34
+
35
+ ## Links
36
+
37
+ ${n.map(a=>`- <a href="${d(a.url)}" target="_blank" rel="noopener noreferrer">${d(a.title)}</a>`).join(`
38
+ `)}`:"";return`${d(r).replaceAll(/&quot;(.*?)&quot;(?:\s|\.)/g,"<code>$1</code> ")}${o}
39
+
40
+ --------------------
41
+ This solution was generated with the <a href="https://sdk.vercel.ai/" target="_blank" rel="noopener noreferrer">AI SDK</a> and may not be 100% accurate.`},ee={handle:e=>e.hint===void 0?Promise.resolve(void 0):typeof e.hint=="string"&&e.hint!==""?Promise.resolve({body:e.hint}):typeof e.hint=="object"&&typeof e.hint.body=="string"?Promise.resolve(e.hint):Array.isArray(e.hint)?Promise.resolve({body:e.hint.join(`
42
+ `)}):Promise.resolve(void 0),name:"errorHint",priority:1},C=e=>`\`\`\`
43
+ ${e.trim()}
44
+ \`\`\``,y=e=>`\`\`\`bash
45
+ ${e.trim()}
46
+ \`\`\``,h=e=>`\`\`\`ts
47
+ ${e.trim()}
48
+ \`\`\``,D=e=>`\`\`\`js
49
+ ${e.trim()}
50
+ \`\`\``,c=(e,...r)=>{const t=e.toLowerCase();return r.some(n=>t.includes(n.toLowerCase()))},J=[{name:"esm-cjs-interop",test:e=>{const{message:r}=e;if(c(r,"err_require_esm","cannot use import statement outside a module","must use import to load es module","require() of es module","does not provide an export named"))return{md:["Your project or a dependency may be mixing CommonJS and ES Modules.","","Try:","- Ensure package.json has the correct `type` (either `module` or `commonjs`).","- Use dynamic `import()` when requiring ESM from CJS.","- Prefer ESM-compatible entrypoints from dependencies.","- In Node, align `module` resolution with your bundler config.","","Check Node resolution:",y(`node -v
51
+ cat package.json | jq .type`),"","Example dynamic import in CJS:",D("(async () => { const mod = await import('some-esm'); mod.default(); })();")].join(`
52
+ `),title:"ESM/CJS interop"}}},{name:"missing-default-export",test:e=>{const{message:r}=e;if(c(r,"default export not found","has no default export","does not provide an export named 'default'","is not exported from"))return{md:["Verify your import/export shapes.","","Default export example:",h(`export default function Component() {}
53
+ // import Component from './file'`),"","Named export example:",h(`export function Component() {}
54
+ // import { Component } from './file'`)].join(`
55
+ `),title:"Export mismatch (default vs named)"}}},{name:"port-in-use",test:e=>{const{message:r}=e;if(c(r,"eaddrinuse","address already in use","listen eaddrinuse"))return{md:["Another process is using the port.","","Change the port or stop the other process.","","On macOS/Linux:",y(`lsof -i :3000
56
+ kill -9 <PID>`),"","On Windows (PowerShell):",y(`netstat -ano | findstr :3000
57
+ taskkill /PID <PID> /F`)].join(`
58
+ `),title:"Port already in use"}}},{name:"file-not-found-or-case",test:(e,r)=>{const{message:t}=e;if(c(t,"enoent","module not found","cannot find module"))return{md:["Check the import path and filename case (Linux/macOS are case-sensitive).","If using TS path aliases, verify `tsconfig.paths` and bundler aliases.","","Current file:",C(`${r.file}:${String(r.line)}`)].join(`
59
+ `),title:"Missing file or path case mismatch"}}},{name:"ts-path-mapping",test:e=>{const{message:r}=e;if(c(r,"ts2307","cannot find module")||r.includes("TS2307"))return{md:["If you use path aliases, align TS `paths` with Vite/Webpack resolve aliases.","Ensure file extensions are correct and included in resolver.","","tsconfig.json excerpt:",h(`{
60
+ "compilerOptions": {
61
+ "baseUrl": ".",
62
+ "paths": { "@/*": ["src/*"] }
63
+ }
64
+ }`)].join(`
65
+ `),title:"TypeScript path mapping / resolution"}}},{name:"network-dns-enotfound",test:e=>{const{message:r}=e;if(c(r,"enotfound","getaddrinfo","dns lookup","fetch failed","econnrefused"))return{md:["The host may be unreachable or misconfigured.","","Try:","- Verify the hostname and protocol (http/https).","- Check VPN/proxy and firewall.","- Confirm the service is running and listening on the expected port.","",y(`ping <host>
66
+ nslookup <host>
67
+ curl -v http://<host>:<port>`)].join(`
68
+ `),title:"Network/DNS connection issue"}}},{name:"undefined-property",test:e=>{const{message:r}=e;if(c(r,"cannot read properties of undefined","reading '"))return{md:["A variable or function returned `undefined`.","","Mitigations:","- Add nullish checks before property access.","- Validate function return values and input props/state.","",h("const value = maybe?.prop; // or: if (maybe) { use(maybe.prop) }")].join(`
69
+ `),title:"Accessing property of undefined"}}}],re={handle:(e,r)=>{try{const t=J.map(o=>({match:o.test(e,r),rule:o})).filter(o=>!!o.match);if(t.length===0)return Promise.resolve(void 0);const n=t.toSorted((o,a)=>(o.match.priority??0)-(a.match.priority??0)).map(o=>`#### ${o.match.title}
70
+
71
+ ${o.match.md}`).join(`
72
+
73
+ ---
74
+
75
+ `);return n===""?Promise.resolve(void 0):Promise.resolve({body:n,header:"### Potential fixes detected"})}catch{return Promise.resolve(void 0)}},name:"ruleBasedHints",priority:0};let p=class extends Error{constructor(r){super(r),this.name="NonError"}};const ne=()=>{if(!Error.captureStackTrace)return;const e=new Error;return Error.captureStackTrace(e),e.stack},v=new Map([["Error",Error],["EvalError",EvalError],["RangeError",RangeError],["ReferenceError",ReferenceError],["SyntaxError",SyntaxError],["TypeError",TypeError],["URIError",URIError],...typeof AggregateError>"u"?[]:[["AggregateError",AggregateError]]]),oe=(e,r)=>{let t;try{t=new e}catch(o){throw new Error(`The error constructor "${e.name}" is not compatible`,{cause:o})}const n=r??t.name;if(v.has(n))throw new Error(`The error constructor "${n}" is already known.`);v.set(n,e)},x=e=>v.get(e),b=e=>e!==null&&typeof e=="object"&&typeof e.name=="string"&&typeof e.message=="string"&&(x(e.name)!==void 0||e.name==="Error"),k=e=>{if(typeof e!="object"||e===null)return!1;const r=Object.getPrototypeOf(e);return r===null||r===Object.prototype||Object.getPrototypeOf(r)===null},L={maxDepth:Number.POSITIVE_INFINITY},N=(e,r,t=0)=>b(e)?S(e,r,t):r.maxDepth!==void 0&&t>=r.maxDepth?new p(JSON.stringify(e)):new p(JSON.stringify(e)),F=(e,r,t,n,o)=>{const a=r.map(s=>l(s,n,o+1));return new e(a,t)},S=(e,r,t)=>{if(r.maxDepth!==void 0&&t>=r.maxDepth)return new p(JSON.stringify(e));const{cause:n,errors:o,message:a,name:s,stack:i,...m}=e,w=x(s)??Error,u=s==="AggregateError"&&Array.isArray(o)?F(w,o,a,r,t):new w(a);return!u.name&&s&&(u.name=s),a!==void 0&&(u.message=a),i&&(u.stack=i),R(u,m,n,s,r,t),n!==void 0&&(u.cause=l(n,r,t+1)),M(u,e),u},l=(e,r,t)=>{if(k(e)){if(e.__dataType==="Map"&&Array.isArray(e.value))return new Map(e.value.map(([o,a])=>[l(o,r,t+1),l(a,r,t+1)]));if(e.__dataType==="Set"&&Array.isArray(e.value))return new Set(e.value.map(o=>l(o,r,t+1)));if(b(e))return N(e,r,t);const n={};for(const[o,a]of Object.entries(e))o==="__proto__"||o==="constructor"||o==="prototype"||(n[o]=l(a,r,t+1));return n}return Array.isArray(e)?e.map(n=>l(n,r,t)):e},R=(e,r,t,n,o,a)=>{const s=e;for(const[i,m]of Object.entries(r))if(!(i==="__proto__"||i==="constructor"||i==="prototype")){if(i==="cause"&&t!==void 0||i==="errors"&&n==="AggregateError")continue;Object.defineProperty(s,i,{configurable:!0,enumerable:!0,value:l(m,o,a+1),writable:!0})}},M=(e,r)=>{const t=new Set(["message","name","stack"]);for(const n of Object.keys(r))t.add(n);for(const n of t)if(n in e){const o=Object.getOwnPropertyDescriptor(e,n);o&&!o.enumerable&&Object.defineProperty(e,n,{...o,enumerable:!0})}},j=e=>new p(JSON.stringify(e)),U=e=>new p(JSON.stringify(e)),V=(e,r)=>b(e)?S(e,r,0):N(e,r),ae=(e,r={})=>{const t={...L,...r};return e instanceof Error?e:e===null?j(null):typeof e=="string"||typeof e=="number"||typeof e=="boolean"?j(e):Array.isArray(e)?U(e):b(e)?S(e,t,0):k(e)?V(e,t):new p(JSON.stringify(e))},q=P("node:util"),Y=e=>{try{return q().inspect(e)}catch{}try{return String(e)}catch{return"<unprintable>"}},se=e=>{const r=new Set,t=[];let n=e;for(;n;){if(r.has(n)){console.error(`Circular reference detected in error causes: ${Y(e)}`);break}if(t.push(n),r.add(n),typeof n!="object"||!("cause"in n))break;n=n.cause}return t},K=e=>{const r=e.methodName&&e.methodName!=="<unknown>"?`${e.methodName} `:"",t=e.file??"<unknown>",n=String(e.line??0),o=String(e.column??0);return r.trim()?` at ${r}(${t}:${n}:${o})`:` at ${t}:${n}:${o}`},ie=(e,r)=>{const t=[];if(r?.header&&(r.header.name||r.header.message)){const n=r.header.name??"Error",o=r.header.message??"";t.push(`${n}${o?": ":""}${o}`)}for(const n of e)t.push(K(n));return t.join(`
76
+ `)},B=Object.create({},{cause:{enumerable:!1,value:void 0,writable:!0},code:{enumerable:!0,value:void 0,writable:!0},errors:{enumerable:!1,value:void 0,writable:!0},message:{enumerable:!1,value:void 0,writable:!0},name:{enumerable:!1,value:void 0,writable:!0},stack:{enumerable:!1,value:void 0,writable:!0}}),X=e=>{if(typeof e!="object"||e===null)return!1;const r=Object.getPrototypeOf(e);return r===null||r===Object.prototype||Object.getPrototypeOf(r)===null},O=new WeakSet,H=e=>{if(Object.hasOwn(e,"name")&&typeof e.name=="string"&&e.name!=="")return e.name;const r=e.constructor?.name;return typeof r=="string"&&r!==""?r:e.name},A=e=>{const r=Object.getOwnPropertyNames(e);for(const t of r){const n=Object.getOwnPropertyDescriptor(e,t);n&&(n.enumerable||Object.defineProperty(e,t,{...n,enumerable:!0}),n.value&&typeof n.value=="object"&&!Array.isArray(n.value)&&(Object.getPrototypeOf(n.value)===Object.prototype||Object.getPrototypeOf(n.value)===null)&&A(n.value))}},W=e=>{O.add(e);const r=e.toJSON();return O.delete(e),Object.isExtensible(r)&&A(r),r},f=(e,r,t,n,o=new Set)=>{if(e&&e instanceof Uint8Array&&e.constructor.name==="Buffer")return"[object Buffer]";if(e!==null&&typeof e=="object"&&"pipe"in e&&typeof e.pipe=="function")return"[object Stream]";if(e instanceof Error)return r.has(e)?"[Circular]":(t+=1,g(e,n,r,t));if(n.useToJSON&&e!==null&&typeof e=="object"&&"toJSON"in e&&typeof e.toJSON=="function")return e.toJSON();if(e instanceof Date)return e.toISOString();if(e instanceof RegExp)return e.toString();if(typeof URL<"u"&&e instanceof URL)return e.href;if(e instanceof Map){const a=[];for(const[s,i]of e.entries())a.push([f(s,r,t,n,o),f(i,r,t,n,o)]);return{__dataType:"Map",value:a}}if(e instanceof Set){const a=[];for(const s of e.values())a.push(f(s,r,t,n,o));return{__dataType:"Set",value:a}}if(typeof e=="function")return`[Function: ${e.name||"anonymous"}]`;if(typeof e=="bigint")return`${String(e)}n`;if(X(e)){if(o.has(e))return"[Circular]";if(n.maxDepth!==void 0&&n.maxDepth!==Number.POSITIVE_INFINITY&&t+1>=n.maxDepth)return{};t+=1,o.add(e);const a={};for(const s in e)a[s]=f(e[s],r,t,n,o);return o.delete(e),a}try{return e}catch{return"[Not Available]"}},g=(e,r,t,n)=>{if(t.add(e),r.maxDepth===0)return{};if(r.useToJSON&&typeof e.toJSON=="function"&&!O.has(e))return W(e);const o=Object.create(B);if(Object.defineProperty(o,"name",{configurable:!0,enumerable:!0,value:H(e),writable:!0}),Object.defineProperty(o,"message",{configurable:!0,enumerable:!0,value:e.message,writable:!0}),Object.defineProperty(o,"stack",{configurable:!0,enumerable:!0,value:e.stack,writable:!0}),Array.isArray(e.errors)){const s=[];for(const i of e.errors){if(!(i instanceof Error))throw new TypeError("All errors in the 'errors' property must be instances of Error");if(t.has(i))return Object.defineProperty(o,"errors",{configurable:!0,enumerable:!0,value:[],writable:!0}),o;s.push(g(i,r,t,n))}Object.defineProperty(o,"errors",{configurable:!0,enumerable:!0,value:s,writable:!0})}const a=e.cause;if(a!=null)if(a instanceof Error)t.has(a)?Object.defineProperty(o,"cause",{configurable:!0,enumerable:!0,value:"[Circular]",writable:!0}):Object.defineProperty(o,"cause",{configurable:!0,enumerable:!0,value:g(a,r,t,n),writable:!0});else{const s=f(a,t,n,r);Object.defineProperty(o,"cause",{configurable:!0,enumerable:!0,value:s,writable:!0})}for(const s in e){if(s==="name"||s==="message"||s==="stack"||s==="cause"||s==="errors")continue;const i=e[s],m=f(i,t,n,r);Object.defineProperty(o,s,{configurable:!0,enumerable:!0,value:m,writable:!0})}if(Array.isArray(r.exclude)&&r.exclude.length>0)for(const s of r.exclude)try{delete o[s]}catch{}return o},ue=(e,r={})=>g(e,{exclude:r.exclude??[],maxDepth:r.maxDepth??Number.POSITIVE_INFINITY,useToJSON:r.useToJSON??!1},new Set,0);export{fe as CODE_FRAME_POINTER,p as NonError,be as VisulimaError,oe as addKnownErrorConstructor,Q as aiPrompt,Z as aiSolutionResponse,ne as captureRawStackTrace,pe as codeFrame,me as composeFilters,ae as deserializeError,ee as errorHintFinder,K as formatStackFrameLine,ie as formatStacktrace,se as getErrorCauses,G as indexToLineColumn,b as isErrorLike,ve as isVisulimaError,de as parseStacktrace,ye as renderError,re as ruleBasedFinder,ue as serializeError,he as stackFilters};
@@ -0,0 +1 @@
1
+ import{h as r}from"./VisulimaError-DTMgXonA-CzaryRgZ.js";class n extends r{code;context;constructor(e,t,o){super({message:e,name:"CerebroError"}),this.code=t,this.context=o}}export{n as t};