@visulima/cerebro 3.0.0-alpha.15 → 3.0.0-alpha.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,22 @@
1
+ ## @visulima/cerebro [3.0.0-alpha.17](https://github.com/visulima/visulima/compare/@visulima/cerebro@3.0.0-alpha.16...@visulima/cerebro@3.0.0-alpha.17) (2026-05-07)
2
+
3
+ ### Bug Fixes
4
+
5
+ * **cerebro:** catch and report errors thrown from [#execute](https://github.com/visulima/visulima/issues/execute)CommandInternal ([1580aa0](https://github.com/visulima/visulima/commit/1580aa081152052010e0458f6c38bbc0cf6bfa57)), closes [#executeCommandInternal](https://github.com/visulima/visulima/issues/executeCommandInternal)
6
+
7
+
8
+ ### Dependencies
9
+
10
+ * **@visulima/error:** upgraded to 6.0.0-alpha.18
11
+
12
+ ## @visulima/cerebro [3.0.0-alpha.16](https://github.com/visulima/visulima/compare/@visulima/cerebro@3.0.0-alpha.15...@visulima/cerebro@3.0.0-alpha.16) (2026-05-06)
13
+
14
+
15
+ ### Dependencies
16
+
17
+ * **@visulima/error:** upgraded to 6.0.0-alpha.17
18
+ * **@visulima/pail:** upgraded to 4.0.0-alpha.14
19
+
1
20
  ## @visulima/cerebro [3.0.0-alpha.15](https://github.com/visulima/visulima/compare/@visulima/cerebro@3.0.0-alpha.14...@visulima/cerebro@3.0.0-alpha.15) (2026-05-06)
2
21
 
3
22
  ### Miscellaneous Chores
package/LICENSE.md CHANGED
@@ -115,11 +115,14 @@ Repository: git+https://github.com/visulima/visulima.git
115
115
  > >
116
116
  > >
117
117
  > > # Licenses of bundled dependencies
118
+ > >
118
119
  > > The published @visulima/error artifact additionally contains code with the following licenses:
119
120
  > > MIT
120
121
  > >
121
122
  > > # Bundled dependencies:
123
+ > >
122
124
  > > ## is-plain-obj
125
+ > >
123
126
  > > License: MIT
124
127
  > > By: Sindre Sorhus
125
128
  > > Repository: sindresorhus/is-plain-obj
@@ -133,6 +136,33 @@ Repository: git+https://github.com/visulima/visulima.git
133
136
  > > > The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
134
137
  > > >
135
138
  > > > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
139
+ > >
140
+ > >
141
+ > >
142
+ > >
143
+ > >
144
+ > > # Licenses of bundled types
145
+ > > The published @visulima/error artifact additionally contains code with the following licenses:
146
+ > > Apache-2.0
147
+ > >
148
+ > > # Bundled types:
149
+ > > ## ai
150
+ > > License: Apache-2.0
151
+ > > Repository: https://github.com/vercel/ai
152
+ > >
153
+ > > > Copyright 2023 Vercel, Inc.
154
+ > > >
155
+ > > > Licensed under the Apache License, Version 2.0 (the "License");
156
+ > > > you may not use this file except in compliance with the License.
157
+ > > > You may obtain a copy of the License at
158
+ > > >
159
+ > > > http://www.apache.org/licenses/LICENSE-2.0
160
+ > > >
161
+ > > > Unless required by applicable law or agreed to in writing, software
162
+ > > > distributed under the License is distributed on an "AS IS" BASIS,
163
+ > > > WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
164
+ > > > See the License for the specific language governing permissions and
165
+ > > > limitations under the License.
136
166
  >
137
167
  >
138
168
  >
@@ -210,11 +240,14 @@ Repository: git+https://github.com/visulima/visulima.git
210
240
  > >
211
241
  > >
212
242
  > > # Licenses of bundled dependencies
243
+ > >
213
244
  > > The published @visulima/error artifact additionally contains code with the following licenses:
214
245
  > > MIT
215
246
  > >
216
247
  > > # Bundled dependencies:
248
+ > >
217
249
  > > ## is-plain-obj
250
+ > >
218
251
  > > License: MIT
219
252
  > > By: Sindre Sorhus
220
253
  > > Repository: sindresorhus/is-plain-obj
@@ -228,6 +261,33 @@ Repository: git+https://github.com/visulima/visulima.git
228
261
  > > > The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
229
262
  > > >
230
263
  > > > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
264
+ > >
265
+ > >
266
+ > >
267
+ > >
268
+ > >
269
+ > > # Licenses of bundled types
270
+ > > The published @visulima/error artifact additionally contains code with the following licenses:
271
+ > > Apache-2.0
272
+ > >
273
+ > > # Bundled types:
274
+ > > ## ai
275
+ > > License: Apache-2.0
276
+ > > Repository: https://github.com/vercel/ai
277
+ > >
278
+ > > > Copyright 2023 Vercel, Inc.
279
+ > > >
280
+ > > > Licensed under the Apache License, Version 2.0 (the "License");
281
+ > > > you may not use this file except in compliance with the License.
282
+ > > > You may obtain a copy of the License at
283
+ > > >
284
+ > > > http://www.apache.org/licenses/LICENSE-2.0
285
+ > > >
286
+ > > > Unless required by applicable law or agreed to in writing, software
287
+ > > > distributed under the License is distributed on an "AS IS" BASIS,
288
+ > > > WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
289
+ > > > See the License for the specific language governing permissions and
290
+ > > > limitations under the License.
231
291
  >
232
292
  >
233
293
  > >
@@ -1227,11 +1287,14 @@ Repository: git+https://github.com/visulima/visulima.git
1227
1287
  > >
1228
1288
  > >
1229
1289
  > > # Licenses of bundled dependencies
1290
+ > >
1230
1291
  > > The published @visulima/error artifact additionally contains code with the following licenses:
1231
1292
  > > MIT
1232
1293
  > >
1233
1294
  > > # Bundled dependencies:
1295
+ > >
1234
1296
  > > ## is-plain-obj
1297
+ > >
1235
1298
  > > License: MIT
1236
1299
  > > By: Sindre Sorhus
1237
1300
  > > Repository: sindresorhus/is-plain-obj
@@ -1245,6 +1308,33 @@ Repository: git+https://github.com/visulima/visulima.git
1245
1308
  > > > The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
1246
1309
  > > >
1247
1310
  > > > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1311
+ > >
1312
+ > >
1313
+ > >
1314
+ > >
1315
+ > >
1316
+ > > # Licenses of bundled types
1317
+ > > The published @visulima/error artifact additionally contains code with the following licenses:
1318
+ > > Apache-2.0
1319
+ > >
1320
+ > > # Bundled types:
1321
+ > > ## ai
1322
+ > > License: Apache-2.0
1323
+ > > Repository: https://github.com/vercel/ai
1324
+ > >
1325
+ > > > Copyright 2023 Vercel, Inc.
1326
+ > > >
1327
+ > > > Licensed under the Apache License, Version 2.0 (the "License");
1328
+ > > > you may not use this file except in compliance with the License.
1329
+ > > > You may obtain a copy of the License at
1330
+ > > >
1331
+ > > > http://www.apache.org/licenses/LICENSE-2.0
1332
+ > > >
1333
+ > > > Unless required by applicable law or agreed to in writing, software
1334
+ > > > distributed under the License is distributed on an "AS IS" BASIS,
1335
+ > > > WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1336
+ > > > See the License for the specific language governing permissions and
1337
+ > > > limitations under the License.
1248
1338
  >
1249
1339
  > <!-- /DEPENDENCIES -->
1250
1340
  >
@@ -1322,11 +1412,14 @@ Repository: git+https://github.com/visulima/visulima.git
1322
1412
  > >
1323
1413
  > >
1324
1414
  > > # Licenses of bundled dependencies
1415
+ > >
1325
1416
  > > The published @visulima/error artifact additionally contains code with the following licenses:
1326
1417
  > > MIT
1327
1418
  > >
1328
1419
  > > # Bundled dependencies:
1420
+ > >
1329
1421
  > > ## is-plain-obj
1422
+ > >
1330
1423
  > > License: MIT
1331
1424
  > > By: Sindre Sorhus
1332
1425
  > > Repository: sindresorhus/is-plain-obj
@@ -1340,6 +1433,33 @@ Repository: git+https://github.com/visulima/visulima.git
1340
1433
  > > > The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
1341
1434
  > > >
1342
1435
  > > > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1436
+ > >
1437
+ > >
1438
+ > >
1439
+ > >
1440
+ > >
1441
+ > > # Licenses of bundled types
1442
+ > > The published @visulima/error artifact additionally contains code with the following licenses:
1443
+ > > Apache-2.0
1444
+ > >
1445
+ > > # Bundled types:
1446
+ > > ## ai
1447
+ > > License: Apache-2.0
1448
+ > > Repository: https://github.com/vercel/ai
1449
+ > >
1450
+ > > > Copyright 2023 Vercel, Inc.
1451
+ > > >
1452
+ > > > Licensed under the Apache License, Version 2.0 (the "License");
1453
+ > > > you may not use this file except in compliance with the License.
1454
+ > > > You may obtain a copy of the License at
1455
+ > > >
1456
+ > > > http://www.apache.org/licenses/LICENSE-2.0
1457
+ > > >
1458
+ > > > Unless required by applicable law or agreed to in writing, software
1459
+ > > > distributed under the License is distributed on an "AS IS" BASIS,
1460
+ > > > WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1461
+ > > > See the License for the specific language governing permissions and
1462
+ > > > limitations under the License.
1343
1463
  >
1344
1464
  > <!-- /DEPENDENCIES -->
1345
1465
  > >
@@ -1516,11 +1636,14 @@ Repository: git+https://github.com/visulima/visulima.git
1516
1636
  > >
1517
1637
  > >
1518
1638
  > > # Licenses of bundled dependencies
1639
+ > >
1519
1640
  > > The published @visulima/error artifact additionally contains code with the following licenses:
1520
1641
  > > MIT
1521
1642
  > >
1522
1643
  > > # Bundled dependencies:
1644
+ > >
1523
1645
  > > ## is-plain-obj
1646
+ > >
1524
1647
  > > License: MIT
1525
1648
  > > By: Sindre Sorhus
1526
1649
  > > Repository: sindresorhus/is-plain-obj
@@ -1534,6 +1657,33 @@ Repository: git+https://github.com/visulima/visulima.git
1534
1657
  > > > The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
1535
1658
  > > >
1536
1659
  > > > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1660
+ > >
1661
+ > >
1662
+ > >
1663
+ > >
1664
+ > >
1665
+ > > # Licenses of bundled types
1666
+ > > The published @visulima/error artifact additionally contains code with the following licenses:
1667
+ > > Apache-2.0
1668
+ > >
1669
+ > > # Bundled types:
1670
+ > > ## ai
1671
+ > > License: Apache-2.0
1672
+ > > Repository: https://github.com/vercel/ai
1673
+ > >
1674
+ > > > Copyright 2023 Vercel, Inc.
1675
+ > > >
1676
+ > > > Licensed under the Apache License, Version 2.0 (the "License");
1677
+ > > > you may not use this file except in compliance with the License.
1678
+ > > > You may obtain a copy of the License at
1679
+ > > >
1680
+ > > > http://www.apache.org/licenses/LICENSE-2.0
1681
+ > > >
1682
+ > > > Unless required by applicable law or agreed to in writing, software
1683
+ > > > distributed under the License is distributed on an "AS IS" BASIS,
1684
+ > > > WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1685
+ > > > See the License for the specific language governing permissions and
1686
+ > > > limitations under the License.
1537
1687
  >
1538
1688
  > ---------------------------------------
1539
1689
  >
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- var a=Object.defineProperty;var o=(r,e)=>a(r,"name",{value:e,configurable:!0});import{Cli as t}from"./packem_shared/Cerebro-Cnr7AGMP.js";import{VERBOSITY_DEBUG as R,VERBOSITY_NORMAL as V,VERBOSITY_QUIET as b,VERBOSITY_VERBOSE as c}from"./packem_shared/VERBOSITY_QUIET-XPultrIA.js";import{lazyNamed as n}from"./packem_shared/lazyNamed-DOmefeJM.js";import{p as S}from"./packem_shared/isVisulimaError-jVZgumOU-C4fgdbWg.js";var E=Object.defineProperty,m=o((r,e)=>E(r,"name",{value:e,configurable:!0}),"t");const f=m((r,e)=>new t(r,e),"createCerebro");export{t as Cerebro,R as VERBOSITY_DEBUG,V as VERBOSITY_NORMAL,b as VERBOSITY_QUIET,c as VERBOSITY_VERBOSE,S as VisulimaError,f as createCerebro,n as lazyNamed};
1
+ var a=Object.defineProperty;var o=(r,e)=>a(r,"name",{value:e,configurable:!0});import{Cli as t}from"./packem_shared/Cerebro-DVWKQlmP.js";import{VERBOSITY_DEBUG as R,VERBOSITY_NORMAL as V,VERBOSITY_QUIET as b,VERBOSITY_VERBOSE as c}from"./packem_shared/VERBOSITY_QUIET-XPultrIA.js";import{lazyNamed as n}from"./packem_shared/lazyNamed-DOmefeJM.js";import{p as S}from"./packem_shared/isVisulimaError-jVZgumOU-C4fgdbWg.js";var E=Object.defineProperty,m=o((r,e)=>E(r,"name",{value:e,configurable:!0}),"t");const f=m((r,e)=>new t(r,e),"createCerebro");export{t as Cerebro,R as VERBOSITY_DEBUG,V as VERBOSITY_NORMAL,b as VERBOSITY_QUIET,c as VERBOSITY_VERBOSE,S as VisulimaError,f as createCerebro,n as lazyNamed};
@@ -0,0 +1,4 @@
1
+ var Dt=Object.defineProperty;var O=(t,e)=>Dt(t,"name",{value:e,configurable:!0});import{createRequire as Rt}from"node:module";import{VERBOSITY_DEBUG as F,POSITIONALS_KEY as oe,VERBOSITY_QUIET as Wt,VERBOSITY_VERBOSE as Ft,VERBOSITY_NORMAL as je}from"./VERBOSITY_QUIET-XPultrIA.js";import{c as C}from"./cerebro-error-BnJTixb2.js";import{d as G,h as Ce,e as X,o as Le,a as qt,i as Gt,f as Ht}from"./runtime-process-DKHFvYkv.js";import{distance as Kt}from"fastest-levenshtein";const Bt=Rt(import.meta.url),J=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,zt=O(t=>{if(typeof J<"u"&&J.versions&&J.versions.node){const[e,n]=J.versions.node.split(".").map(Number);if(e>22||e===22&&n>=3||e===20&&n>=16)return J.getBuiltinModule(t)}return Bt(t)},"__cjs_getBuiltinModule"),{createRequire:Yt}=zt("node:module"),ae=[{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 Jt=Object.defineProperty,Qt=O((t,e)=>Jt(t,"name",{value:e,configurable:!0}),"t$9");let B=class extends C{static{O(this,"a")}static{Qt(this,"CommandNotFoundError")}commandName;constructor(e,n=[]){const i=`Command "${e}" not found${n.length>0?`. Did you mean: ${n.join(", ")}?`:""}`;super(i,"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 Zt=Object.defineProperty,Xt=O((t,e)=>Zt(t,"name",{value:e,configurable:!0}),"e$7");let nt=class extends C{static{O(this,"o")}static{Xt(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 en=Object.defineProperty,tn=O((t,e)=>en(t,"name",{value:e,configurable:!0}),"e$6");let nn=class extends C{static{O(this,"o")}static{tn(this,"PluginError")}pluginName;constructor(e,n,i){super(`Plugin "${e}" error: ${n}`,"PLUGIN_ERROR",{originalError:i,pluginName:e}),this.name="PluginError",this.pluginName=e,i&&(this.cause=i)}};var an=Object.defineProperty,Ie=O((t,e)=>an(t,"name",{value:e,configurable:!0}),"d$7");let on=class{static{O(this,"p")}static{Ie(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`);G().CEREBRO_OUTPUT_LEVEL===String(F)&&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 i of n)if(typeof i.init=="function"){this.logger.debug(`initializing plugin: ${i.name}`);try{await i.init(e)}catch(r){const a=new nn(i.name,`Failed to initialize: ${r instanceof Error?r.message:String(r)}`,r instanceof Error?r:void 0);throw this.logger.error(a.message),a}}this.initialized=!0}async executeLifecycle(e,n,i){if(!this.initialized)throw new Error("PluginManager not initialized");if(this.plugins.size===0)return;const r=this.getDependencyOrder();for(const a of r){const c=a[e];if(typeof c=="function"){this.logger.debug(`executing ${e} hook for plugin: ${a.name}`);try{await(e==="afterCommand"?c(n,i):c(n))}catch(s){throw this.logger.error(`Error in ${e} hook for plugin "${a.name}":`,s),s}}}}async executeErrorHandlers(e,n){if(!this.initialized||this.plugins.size===0)return;const i=this.getDependencyOrder();for(const r of i)if(typeof r.onError=="function"){this.logger.debug(`executing error handler for plugin: ${r.name}`);try{await r.onError(e,n)}catch(a){this.logger.error(`Error in error handler for plugin "${r.name}":`,a)}}}getDependencyOrder(){if(this.cachedDependencyOrder!==void 0)return this.cachedDependencyOrder;const e=[],n=new Set,i=new Set,r=Ie(a=>{if(n.has(a))return;if(i.has(a))throw new Error(`Circular dependency detected involving plugin "${a}"`);const c=this.plugins.get(a);if(!c)throw new Error(`Plugin "${a}" not found`);if(i.add(a),c.dependencies)for(const s of c.dependencies)r(s);i.delete(a),n.add(a),e.push(c)},"visit");for(const a of this.plugins.keys())r(a);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 rn=Object.defineProperty,sn=O((t,e)=>rn(t,"name",{value:e,configurable:!0}),"n$c");const te=sn(t=>t.type?.name==="Boolean","optionIsBoolean");var ln=Object.defineProperty,at=O((t,e)=>ln(t,"name",{value:e,configurable:!0}),"p$a");const cn=at(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"),Se=at(t=>(te(t)||(t.typeLabel=t.typeLabel??cn(t),t.defaultOption&&(t.typeLabel=`${t.typeLabel} (D)`),t.required&&(t.typeLabel=`${t.typeLabel} (R)`)),t),"mapOptionTypeLabel");var un=Object.defineProperty,it=O((t,e)=>un(t,"name",{value:e,configurable:!0}),"e$4");const pn=new RegExp(/^-([^\d-])$/),fn=new RegExp(/^--(\S+)/),hn=new RegExp(/^-([^\d-]{2,})$/),dn=it(t=>pn.test(t)||fn.test(t)||hn.test(t),"isOption"),mn=it((t,e)=>{const n=e[0]&&dn(e[0])||e.length===0?null:e.shift()??null;if(!t.includes(n)){const i=new Error(`Command not recognised: ${String(n)}`);throw i.command=n,i.name="INVALID_COMMAND",i}return{argv:e,command:n}},"commandLineCommands");var gn=Object.defineProperty,ot=O((t,e)=>gn(t,"name",{value:e,configurable:!0}),"i$b"),vn=Object.defineProperty,rt=ot((t,e)=>vn(t,"name",{value:e,configurable:!0}),"i"),wn=Object.defineProperty,st=rt((t,e)=>wn(t,"name",{value:e,configurable:!0}),"s"),yn=Object.defineProperty,lt=st((t,e)=>yn(t,"name",{value:e,configurable:!0}),"i"),bn=Object.defineProperty,ct=lt((t,e)=>bn(t,"name",{value:e,configurable:!0}),"t");ct(t=>t instanceof Error&&t.type==="VisulimaError","isVisulimaError");let le=class extends Error{static{O(this,"v")}static{ot(this,"g")}static{rt(this,"p")}static{st(this,"V")}static{lt(this,"VisulimaError")}static{ct(this,"VisulimaError")}loc;title;hint;type="VisulimaError";constructor({cause:e,hint:n,location:i,message:r,name:a,stack:c,title:s}){super(r,{cause:e}),this.title=s,this.name=a,this.stack=c??this.stack,this.loc=i,this.hint=n}setLocation(e){this.loc=e}setName(e){this.name=e}setMessage(e){this.message=e}setHint(e){this.hint=e}};var $n=Object.defineProperty,ut=O((t,e)=>$n(t,"name",{value:e,configurable:!0}),"o$b"),On=Object.defineProperty,pt=ut((t,e)=>On(t,"name",{value:e,configurable:!0}),"o"),Pn=Object.defineProperty,En=pt((t,e)=>Pn(t,"name",{value:e,configurable:!0}),"i");let An=class ft extends le{static{O(this,"a")}static{ut(this,"a")}static{pt(this,"t")}static{En(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,ft.prototype)}};var Cn=Object.defineProperty,ht=O((t,e)=>Cn(t,"name",{value:e,configurable:!0}),"t$7"),Nn=Object.defineProperty,dt=ht((t,e)=>Nn(t,"name",{value:e,configurable:!0}),"e"),xn=Object.defineProperty,kn=dt((t,e)=>xn(t,"name",{value:e,configurable:!0}),"e");let Me=class mt extends le{static{O(this,"n")}static{ht(this,"n")}static{dt(this,"o")}static{kn(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,mt.prototype)}};var _n=Object.defineProperty,gt=O((t,e)=>_n(t,"name",{value:e,configurable:!0}),"a$a"),jn=Object.defineProperty,vt=gt((t,e)=>jn(t,"name",{value:e,configurable:!0}),"a"),Ln=Object.defineProperty,In=vt((t,e)=>Ln(t,"name",{value:e,configurable:!0}),"o");let Sn=class wt extends le{static{O(this,"n")}static{gt(this,"o")}static{vt(this,"e")}static{In(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,wt.prototype)}};var Mn=Object.defineProperty,yt=O((t,e)=>Mn(t,"name",{value:e,configurable:!0}),"i$8"),Un=Object.defineProperty,bt=yt((t,e)=>Un(t,"name",{value:e,configurable:!0}),"i"),Tn=Object.defineProperty,Vn=bt((t,e)=>Tn(t,"name",{value:e,configurable:!0}),"i");let j=class $t extends le{static{O(this,"a")}static{yt(this,"o")}static{bt(this,"e")}static{Vn(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,$t.prototype)}};var Dn=Object.defineProperty,Rn=O((t,e)=>Dn(t,"name",{value:e,configurable:!0}),"z$1"),Bn=Object.defineProperty,K=Rn((t,e)=>Bn(t,"name",{value:e,configurable:!0}),"S"),zn=Object.defineProperty,ce=K((t,e)=>zn(t,"name",{value:e,configurable:!0}),"o");const Ue=ce(t=>t===Boolean||typeof t=="function"&&t.name.startsWith("Boolean"),"isBooleanType"),Te=ce(t=>t===Number||typeof t=="function"&&t.name==="Number","isNumberType"),Ve=ce(t=>t===String||typeof t=="function"&&t.name==="String","isStringType"),Wn=ce((t,e)=>Array.isArray(t)?Ue(e)?t.map(Boolean):Te(e)?t.map(Number):Ve(e)?t.map(String):t.map(n=>e(String(n))):t===null?null:Ue(e)?!!t:Te(e)?Number(t):Ve(e)?typeof t=="string"?t:String(t):e(typeof t=="string"?t:String(t)),"convertValue");var Fn=Object.defineProperty,qn=K((t,e)=>Fn(t,"name",{value:e,configurable:!0}),"e");const _=qn((t,e,n,...i)=>{t&&console.debug(`[command-line-args:${n}] ${e}`,...i)},"debug");var Gn=Object.defineProperty,D=K((t,e)=>Gn(t,"name",{value:e,configurable:!0}),"h$1");const Hn=/-([a-z])/g,Kn=/^\d+$/,ve=D(t=>t===Boolean||typeof t=="function"&&t.name.startsWith("Boolean"),"isBooleanType"),Yn=D(t=>t.codePointAt(0)===95,"isSpecialKey"),De=D((t,e)=>Array.isArray(t)?[...t,...e]:[t,...e],"appendToArrayMultiple"),Re=D(t=>t==="__proto__"||t==="constructor"||t==="prototype","isUnsafeKey"),Be=D((t,e,n,i=!1)=>{t[e]===void 0?t[e]=i?[n]:n:i&&Array.isArray(t[e])?t[e].push(n):t[e]=[t[e],n]},"createOrAppendArray"),Jn=D((t,e,n,i,r)=>{let a=e.get(t)??n.get(t);if(!a&&i){const c=t.toLowerCase();a=i.get(c)??r?.get(c)}return a},"getDefinition"),Qn=D((t,e,n,i)=>{const r=n.debug??!1;_(r,"resolveArgs called with options:","resolver",{partial:n.partial,stopAtFirstUnknown:n.stopAtFirstUnknown}),_(r,"Starting argument resolution","resolver"),_(r,"Tokens:","resolver",t),_(r,"Definitions:","resolver",e),_(r,"Processing tokens...","resolver");const a=new Map,c=new Map,s=n.caseInsensitive?new Map:void 0,m=n.caseInsensitive?new Map:void 0,o=n.camelCase?new Map:void 0,u=n.camelCase?new Map:void 0;for(const f of e)if(a.set(f.name,f),f.alias&&c.set(f.alias,f),n.caseInsensitive&&s&&(s.set(f.name.toLowerCase(),f),f.alias&&m&&m.set(f.alias.toLowerCase(),f)),n.camelCase&&o&&u){const h=f.name.replaceAll(Hn,(v,w)=>w.toUpperCase());o.set(f.name,h),u.set(h,f.name)}const d={},l={},g=[],p=new Set;let b=!1;const $=e.find(f=>f.defaultOption),y=e.some(f=>f.group),E=e.some(f=>f.type===Number);for(let f=0;f<t.length;f++){const h=t[f];if(h.kind==="option-terminator"){d._unknown=i.slice(h.index),b=!0;break}if(h.kind==="option"&&h.name){let v=Jn(h.name,a,c,s,m);if(!v&&h.value===void 0&&E&&Kn.test(h.name)){const A=e.find(S=>S.type===Number);A&&(v=A,h.value=h.name,h.name=A.name)}const w=v?v.name:h.name,P=v?.multiple,k=v?.lazyMultiple;if(l[w]!==void 0&&!P&&!k&&!n.partial)throw new An(w);if(!v&&n.partial){const A=h.rawName??`--${h.name}${h.value!==void 0&&h.inlineValue?`=${h.value}`:""}`;g.push({index:h.index,value:A});continue}if(!v&&n.stopAtFirstUnknown){d._unknown=i.slice(h.index);break}if(!v&&!n.partial)throw new Me(h.name);if(h.value===void 0){const A=t[f+1],S=A?.kind==="option"&&!("name"in A)&&A.value!==void 0,I=A&&v&&!(v.type&&ve(v.type))&&(A.kind==="positional"||S),Vt=v&&v.defaultOption&&!v.multiple&&!v.lazyMultiple;if(I&&(!v?.defaultOption||Vt))if(P){let M=f+1;const ge=[];for(;M<t.length&&(t[M].kind==="positional"||t[M].kind==="option"&&!("name"in t[M])&&t[M].value!==void 0);)ge.push(t[M].value),p.add(t[M].index),M++;l[w]=l[w]===void 0?ge:De(l[w],ge),f=M-1}else k?(Be(l,w,A.value,!0),p.add(A.index),f++):(l[w]=A.value,p.add(A.index),f++);else v?.type&&ve(v.type)?Be(l,w,!0,P):l[w]=P?[]:null}else{let{value:A}=h;if(v?.type&&ve(v.type))switch(A){case"":{if(n.partial)l._unknown??=[],l._unknown.push(`${h.rawName??`--${h.name}`}${h.value?`=${h.value}`:""}`),A=!0;else throw new Me(h.name);break}case"false":{A=!1;break}case"true":{A=!0;break}default:A=!0}const S=[A];if(P){let I=f+1;for(;I<t.length&&t[I].kind==="positional";)S.push(t[I].value),p.add(t[I].index),I++;f=I-1}l[w]===void 0?l[w]=P||k?S:A:P||k?l[w]=De(l[w],S):l[w]=A}}else if(h.kind==="positional"&&n.stopAtFirstUnknown&&!p.has(h.index)&&!$){_(r,`Found unconsumed positional token at index ${String(h.index)}, stopping processing`,"resolver"),d._unknown=i.slice(h.index);break}}for(const[f,h]of Object.entries(l)){const v=a.get(f);v&&(v.multiple||v.lazyMultiple)&&!Array.isArray(h)&&(l[f]=[h])}let N=Number.POSITIVE_INFINITY;if(n.stopAtFirstUnknown&&!b){for(const f of t)if(f.kind==="option"&&!a.has(f.name??"")&&!c.has(f.name??"")&&(!n.caseInsensitive||!s?.has(f.name?.toLowerCase()??"")&&!m?.has(f.name?.toLowerCase()??""))){N=f.index;break}}if($){const f=[],h=[];for(const v of t)v.kind==="positional"&&!p.has(v.index)&&v.index<N&&(f.push(v.value),h.push(v));if(f.length>0){const v=l[$.name],w=$.multiple??$.lazyMultiple;v===void 0?w?(h.forEach(P=>p.add(P.index)),l[$.name]=f):(p.add(h[0].index),l[$.name]=f[0]):w&&(h.forEach(P=>p.add(P.index)),l[$.name]=Array.isArray(v)?[...f,...v]:[...f,v])}}if(!n.partial){for(const f of t)if(f.kind==="positional"&&!p.has(f.index))throw new Sn(i[f.index])}if(n.partial&&!n.stopAtFirstUnknown){const f=[...g];if(l._unknown){const h=new Map;for(const[v,w]of i.entries())h.set(w,v);for(const v of l._unknown){const w=h.get(v);w!==void 0&&f.push({index:w,value:v})}}for(const h of t)h.kind==="positional"&&!p.has(h.index)&&f.push({index:h.index,value:i[h.index]});f.length>0&&(f.sort((h,v)=>h.index-v.index),d._unknown=f.map(h=>h.value))}if(n.stopAtFirstUnknown&&!b){const f=t.findIndex(w=>w.kind==="option"&&!a.has(w.name??"")&&!c.has(w.name??"")&&(!n.caseInsensitive||!s?.has(w.name?.toLowerCase()??"")&&!m?.has(w.name?.toLowerCase()??""))),h=t.findIndex(w=>w.kind==="positional"&&!p.has(w.index));let v=-1;if(f!==-1&&h!==-1?v=Math.min(f,h):f!==-1?v=f:h!==-1&&(v=h),v>=0){const w=t[v].index;d._unknown=i.slice(w)}}else g.length>0&&!n.partial&&(d._unknown=g.map(f=>f.value));for(const[f,h]of Object.entries(l)){const v=n.camelCase?o?.get(f)??f:f,w=a.get(f);d[v]=w?.type?Wn(h,w.type):h===void 0?null:h}for(const f of e){const h=n.camelCase?o?.get(f.name)??f.name:f.name;!(h in d)&&f.defaultValue!==void 0&&(f.multiple??f.lazyMultiple?d[h]=Array.isArray(f.defaultValue)?[...f.defaultValue]:[f.defaultValue]:d[h]=f.defaultValue)}if(y){const f={},h={},v={};for(const P of e)if(P.group){const k=Array.isArray(P.group)?P.group:[P.group];for(const A of k)Re(A)||(f[A]??={})}for(const P of Object.keys(d))if(!Yn(P)){h[P]=d[P];let k=P;n.camelCase&&(k=u?.get(P)??P);const A=a.get(k);if(A?.group){const S=Array.isArray(A.group)?A.group:[A.group];for(const I of S)Re(I)||f[I]&&(f[I][P]=d[P])}else v[P]=d[P]}const w={_all:h};for(const[P,k]of Object.entries(f))w[P]=k;Object.keys(v).length>0&&(w._none=v),d._unknown&&(w._unknown=d._unknown),Object.keys(d).forEach(P=>delete d[P]),Object.assign(d,w)}return _(r,"Final parsed result:","resolver",d),d},"resolveArgs");var Zn=Object.defineProperty,R=K((t,e)=>Zn(t,"name",{value:e,configurable:!0}),"l");const V="-".codePointAt(0),T="=",Xn=T.codePointAt(0),ea="--",ta="-",na="--",Ot=R(t=>t.length>2&&t.startsWith(na),"hasLongOptionPrefix"),aa=R(t=>Ot(t)&&!t.includes(T,3),"isLongOption"),ia=R(t=>Ot(t)&&t.includes(T,3),"isLongOptionAndValue"),oa=R(t=>t!==void 0&&t.length>0&&t.codePointAt(0)!==V,"hasOptionValue"),ra=R(t=>{if(t.length!==2||t.codePointAt(0)!==V||t.codePointAt(1)===V)return!1;const e=t.codePointAt(1);return e!==void 0&&(e<48||e>57)},"isShortOption"),sa=R(t=>!(t.length<=2||t.codePointAt(0)!==V||t.codePointAt(1)===V),"isShortOptionGroup"),la=R(t=>{const e=[],n=[...t];let i=-1,r=0;for(;n.length>0;){const a=n.shift();if(a===void 0)break;const c=n[0];if(r>0?r--:i++,a===ea){e.push({index:i,kind:"option-terminator"});const s=n.map((m,o)=>({index:i+o+1,kind:"positional",value:m}));e.push(...s),i+=n.length;break}if(ra(a)){const s=a.charAt(1);let m;r?(e.push({index:i,kind:"option",name:s,rawName:a,value:m}),r===1&&oa(c)&&(m=n.shift(),e.push({index:i,kind:"option",value:m}))):e.push({index:i,kind:"option",name:s,rawName:a,value:m}),m!==void 0&&++i;continue}if(sa(a)&&!a.includes(T)){const s=[];let m="",o=!1;for(let u=1;u<a.length;u++){const d=a.charAt(u);o?m+=d:d.codePointAt(0)===Xn?o=!0:s.push(`${ta}${d}`)}if(o)if(s.length>0){const u=s.pop();s.push(`${u}=${m}`)}else s.push(m);n.unshift(...s),r=s.length;continue}if(aa(a)){const s=a.slice(2);e.push({index:i,kind:"option",name:s,rawName:a});continue}if(ia(a)){const s=a.indexOf(T),m=a.slice(2,s),o=a.slice(s+1);e.push({index:i,inlineValue:!0,kind:"option",name:m,rawName:a,value:o});continue}if(a.length>2&&a.codePointAt(0)===V&&a.codePointAt(1)!==V&&a.includes(T)){const s=a.indexOf(T),m=a.charAt(1),o=a.slice(s+1);e.push({index:i,inlineValue:!0,kind:"option",name:m,rawName:a,value:o});continue}e.push({index:i,kind:"positional",value:a})}return e},"parseArgsTokens");var ca=Object.defineProperty,xe=K((t,e)=>ca(t,"name",{value:e,configurable:!0}),"d");const ua=/\d/,pa=xe(t=>t!=null&&(t===Boolean||typeof t=="function"&&t.name.startsWith("Boolean")),"isBooleanType"),fa=xe(t=>typeof t=="function","isValidCustomTypeFunction"),ha=xe((t,e,n)=>{const i=n?.debug??!1;_(i,"Validating definitions:","validation",t,"caseInsensitive:",e);const r=new Set,a=new Set,c=new Set,s=new Set;let m=0;for(const o of t){if(_(i,"Checking definition:","validation",o),!o.name)throw _(i,"Validation failed: name is required","validation"),new j("Invalid option definition: name is required");if(typeof o.name!="string")throw new j("Invalid option definition: name must be a string");if(o.name.trim()==="")throw new j("Invalid option definition: name cannot be empty");const u=e?o.name.toLowerCase():"";if(r.has(o.name)||e&&c.has(u))throw new j(`Invalid option definition: duplicate name '${o.name}'`);if(a.has(o.name)||e&&s.has(u))throw new j(`Invalid option definition: name '${o.name}' conflicts with an existing alias`);if(r.add(o.name),e&&c.add(u),o.alias!==void 0){if(typeof o.alias!="string")throw new j("Invalid option definition: alias must be a string");if(o.alias.length!==1)throw new j("Invalid option definition: alias must be a single character");if(ua.test(o.alias))throw new j("Invalid option definition: alias cannot be numeric");if(o.alias==="-")throw new j('Invalid option definition: alias cannot be "-"');const d=e?o.alias.toLowerCase():"";if(a.has(o.alias)||e&&s.has(d))throw new j(`Invalid option definition: duplicate alias '${o.alias}'`);if(r.has(o.alias)||e&&c.has(d))throw new j(`Invalid option definition: alias '${o.alias}' conflicts with an existing option name`);a.add(o.alias),e&&s.add(d)}if(o.defaultOption&&(m++,o.type!==void 0&&pa(o.type)))throw new j("Invalid option definition: defaultOption cannot be Boolean type");if(o.type!==void 0&&!(o.type===Boolean||o.type===Number||o.type===String||typeof o.type=="function"&&fa(o.type)))throw new j("Invalid option definition: invalid type")}if(m>1)throw _(i,"Validation failed: multiple defaultOptions not allowed","validation"),new j("Invalid option definition: multiple defaultOptions not allowed");_(i,"Validation completed successfully","validation")},"validateDefinitions");var da=Object.defineProperty,ma=K((t,e)=>da(t,"name",{value:e,configurable:!0}),"O");const ga=ma((t,e={})=>{const n=e.debug??!1;_(n,"Starting command-line-args parsing","index"),_(n,"Options:","index",e);const i={...e};i.stopAtFirstUnknown&&(i.partial=!0);const r=Array.isArray(t)?t:[t];_(n,"Normalized definitions:","index",r),ha(r,i.caseInsensitive,n?i:void 0);let{argv:a}=i;if(!a&&(a=process.argv.slice(2),process.execArgv.length>0)){const o=new Set(process.execArgv);a=a.filter(u=>!o.has(u))}_(n,"Using argv:","index",a);let c=a;i.caseInsensitive&&(c=a.map(o=>{if(o.startsWith("--")){const u=o.indexOf("="),d=(u===-1?o.slice(2):o.slice(2,u)).toLowerCase();return u===-1?`--${d}`:`--${d}${o.slice(u)}`}if(o.startsWith("-")&&!o.startsWith("--")&&o.length>1){const u=o.slice(1).split("=",2),d=u[0],l=u[1];if(!d)return o;const g=d.toLowerCase();return l===void 0?`-${g}`:`-${g}=${l}`}return o}));const s=la(c.map(String));_(n,"Tokenized arguments:","index",s);const m=Qn(s,r,i,a);return _(n,"Command-line-args parsing completed","index"),m},"commandLineArgs");var va=Object.defineProperty,wa=O((t,e)=>va(t,"name",{value:e,configurable:!0}),"n$8");let ya=class{static{O(this,"a")}static{wa(this,"EmptyToolbox")}result;argv;options;argument;command;commandName;env;logger;runtime;rawUnknown;constructor(e,n){this.commandName=e,this.command=n}};var ba=Object.defineProperty,$a=O((t,e)=>ba(t,"name",{value:e,configurable:!0}),"n$7");let we=class extends C{static{O(this,"i")}static{$a(this,"CommandLoaderError")}commandName;constructor(e,n,i){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.",i!==void 0&&(this.cause=i)}};var Oa=Object.defineProperty,Pa=O((t,e)=>Oa(t,"name",{value:e,configurable:!0}),"f$5");const Ea=/^-{1,2}(\w+)(=(.+))?$/,Pt=Pa((t,e,n,i)=>{const r=Ea.exec(t);if(r===null)return{};const a=r[1];if(!a)return{};const c=n&&i?n.get(a)??i.get(a):e.find(s=>s.name===a||s.alias===a);return c!==void 0?{argName:c.name,argValue:r[3],option:c}:{}},"getParameterOption");var Aa=Object.defineProperty,Ne=O((t,e)=>Aa(t,"name",{value:e,configurable:!0}),"e$3");const ze=Ne((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"),Ca=new Set(["0","1","false","true"]),Na=Ne((t,e,n,i)=>{if(e.length===0||t.length===0)return{};const r=Ne((a,c)=>{const{argName:s,argValue:m,option:o}=Pt(c,e,n,i),{lastOption:u}=a;return o&&te(o)&&m&&s?a.partial[s]=ze(m,o):a.lastName&&u&&te(u)&&Ca.has(c)&&(a.partial[a.lastName]=ze(c,u)),{lastName:s,lastOption:o,partial:a.partial}},"getBooleanValue");return t.reduce(r,{partial:{}}).partial},"getBooleanValues");var xa=Object.defineProperty,We=O((t,e)=>xa(t,"name",{value:e,configurable:!0}),"s$8");const ka=new Set(["0","1","false","true"]),_a=We((t,e,n,i)=>{if(e.length===0||t.length===0)return t;const r=We((a,c)=>{const{argValue:s,option:m}=Pt(c,e,n,i),{lastOption:o}=a;if(o&&te(o)&&ka.has(c)){const{args:u}=a;return{args:u.slice(0,-1)}}return m&&te(m)&&s?{args:a.args}:{args:[...a.args,c],lastOption:m}},"removeBooleanArguments");return t.reduce(r,{args:[]}).args},"removeBooleanValues");var ja=Object.defineProperty,La=O((t,e)=>ja(t,"name",{value:e,configurable:!0}),"o$8");const Fe=La(t=>{const e=new Map;for(const n of t){const i=e.get(n.name);i?e.set(n.name,{...i,...n}):e.set(n.name,n)}return[...e.values()]},"mergeArguments");var Ia=Object.defineProperty,ue=O((t,e)=>Ia(t,"name",{value:e,configurable:!0}),"o$7");const Sa=ue(t=>{if(t===void 0)return;const e=t.toLowerCase().trim();return e==="true"||e==="1"||e==="yes"||e==="on"},"transformBooleanEnv"),Ma=ue((t,e)=>{if(!t.type)return e;if(e!==void 0){if(t.type===Boolean||typeof t.type=="function"&&t.type.name==="Boolean")return Sa(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"),Ua=/_./g,Ta=/^[A-Z]/,Va=ue(t=>t.toLowerCase().replaceAll(Ua,e=>e[1]?.toUpperCase()??e).replace(Ta,e=>e.toLowerCase()),"toCamelCase"),Da=ue(t=>{if(!t||t.length===0)return{};const e={},n=G();for(const i of t){const r=n[i.name],a=Ma(i,r),c=a===void 0?i.defaultValue:a,s=Va(i.name);e[s]=c}return e},"processEnvVariables");var Ra=Object.defineProperty,ne=O((t,e)=>Ra(t,"name",{value:e,configurable:!0}),"a$5");const Ba=ne(t=>{const e=new Map,n=new Map;for(const i of t)if(e.set(i.name,i),i.alias){const r=Array.isArray(i.alias)?i.alias:[i.alias];for(const a of r)n.set(a,i)}return{optionMapByAlias:n,optionMapByName:e}},"buildOptionMaps"),za=ne(async t=>{if(typeof t.__resolvedExecute__=="function")return t.__resolvedExecute__;if(typeof t.loader!="function")throw new we(t.name,"no execute or loader defined");let e;try{e=await t.loader()}catch(i){throw new we(t.name,i instanceof Error?i.message:String(i),i)}const n=e.default;if(typeof n!="function")throw new we(t.name,"loader did not return a module with a default-exported handler function");return t.__resolvedExecute__=n,n},"loadLazyHandler"),Wa=ne((t,e,n,i)=>{const r=new ya(t.name,t),{_all:a,_unknown:c,positionals:s}=e,m=Object.keys(n).length>0?{...a,...n}:a;oe in m&&delete m[oe],r.argument=s?.[oe]??[],r.rawUnknown=[...c??[]];const o=Object.keys(i).length>0;return r.options=o?{...m,...i}:m,r.env=Da(t.env),r},"prepareToolbox"),Fa=ne((t,e,n)=>{const i=t.options??[],r=i.length>0;let a=Fe(r?[...i,...n]:n);if(a.length>0){for(const o of a)if(o.multiple&&o.lazyMultiple)throw new Error(`Argument "${o.name}" cannot have both multiple and lazyMultiple options, please choose one.`)}t.argument&&(a=[{defaultOption:!0,description:t.argument.description,group:"positionals",multiple:!0,name:oe,type:t.argument.type,typeLabel:t.argument.typeLabel},...a]);let c,s;if(r){const{optionMapByAlias:o,optionMapByName:u}=Ba(i);c=_a(e,i,u,o),s=Na(e,i,u,o)}else c=e,s={};const m=ga(a,{argv:c,camelCase:!0,partial:!0,stopAtFirstUnknown:!0});return{arguments_:a,booleanValues:s,parsedArgs:m}},"processCommandArgs"),z=ne(async(t,e,n)=>typeof t.execute=="function"?t.execute(e):(await za(t))(e),"executeCommand");var qa=Object.defineProperty,Ga=O((t,e)=>qa(t,"name",{value:e,configurable:!0}),"n$6");let Ha=class extends C{static{O(this,"s")}static{Ga(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 Ka=Object.defineProperty,Ya=O((t,e)=>Ka(t,"name",{value:e,configurable:!0}),"t$5");const qe=Ya((t,e,n=!1)=>{const i=[];for(const r of t)if(!(!n&&!r.required)&&e[r.name]===void 0){if(r.type?.name==="Boolean"){e[r.name]=!1;continue}i.push(r)}return i},"listMissingArguments");var Ja=Object.defineProperty,Et=O((t,e)=>Ja(t,"name",{value:e,configurable:!0}),"n$5");const Qa=Et((t,e)=>e.includes(t)?!0:Math.abs(t.length-e.length)>t.length/2?!1:Kt(t,e)<=t.length/3,"isSimilar"),q=Et((t,e)=>{const n=t.toLowerCase();return e.filter(i=>Qa(i.toLowerCase(),n))},"findAlternatives");var Za=Object.defineProperty,pe=O((t,e)=>Za(t,"name",{value:e,configurable:!0}),"a$4");const Xa=pe((t,e)=>{const n=[];if(t._unknown&&t._unknown.forEach(i=>{const r=i.startsWith("--");let a=`Found unknown ${r?"option":"argument"} "${i}"`;if(r){const c=q(i.replace("--",""),(e.options??[]).map(s=>s.name));if(c.length>0){const[s,...m]=c.map(o=>`--${o}`);a+=m.length>0?`, did you mean ${s??""} or ${m.join(", ")}?`:`, did you mean ${s??""}?`}}n.push(a)}),n.length>0)throw new Error(n.join(`
2
+ `))},"validateUnknownOptions"),ei=pe((t,e,n)=>{const i=n.__requiredOptions__,r=i?qe(i,e,!0):qe(t,e,!1);if(r.length>0)throw new Ha(n.name,r.map(a=>a.name));e._unknown&&e._unknown.length>0&&!n.argument&&Xa(e,n)},"validateRequiredOptions"),ti=pe((t,e,n)=>{const i=n.__conflictingOptions__??t.filter(r=>r.conflicts!==void 0);if(i.length>0){const r=i.find(a=>Array.isArray(a.conflicts)?a.conflicts.some(c=>e[c]!==void 0)&&e[a.name]!==void 0:e[a.conflicts]!==void 0&&e[a.name]!==void 0);if(r)throw new nt(r.name,typeof r.conflicts=="string"?r.conflicts:r.conflicts?.[0]??"unknown")}},"validateConflictingOptions"),ni=pe(t=>{if(!Array.isArray(t.options))return;const e=new Map,n=new Map;for(const r of t.options){if(r.name){const a=e.get(r.name)??[];a.push(r),e.set(r.name,a)}if(typeof r.alias=="string"&&r.alias.length>0){const a=n.get(r.alias)??[];a.push(r),n.set(r.alias,a)}else if(Array.isArray(r.alias)){for(const a of r.alias)if(a.length>0){const c=n.get(a)??[];c.push(r),n.set(a,c)}}}const i=[];for(const[r,a]of e)a.length>1&&i.push(`Duplicate option name "${r}" in command "${t.name}": ${JSON.stringify(a)}`);for(const[r,a]of n)a.length>1&&i.push(`Duplicate option alias "-${r}" used by options ${a.map(c=>`"${c.name}"`).join(", ")} in command "${t.name}"`);if(i.length>0)throw new Error(i.join(`
3
+ `))},"validateDuplicateOptions");var ai=Object.defineProperty,ke=O((t,e)=>ai(t,"name",{value:e,configurable:!0}),"s$4");const ii=ke((t,e)=>{if(e.length===0)return{argv:[],commandPath:void 0};const n=[];let i;for(let r=1;r<=e.length;r+=1){const a=e[r-1];if(a===void 0||a.startsWith("-"))break;n.push(a);const c=n.join(" ");t.has(c)&&(i={commandPath:[...n],depth:r})}return i?{argv:e.slice(i.depth),commandPath:i.commandPath}:{argv:e,commandPath:void 0}},"parseNestedCommand"),Q=ke(t=>t.join(" "),"getCommandPathKey"),oi=ke((t,e)=>e&&e.length>0?[...e,t]:[t],"getFullCommandPath");var ri=Object.defineProperty,si=O((t,e)=>ri(t,"name",{value:e,configurable:!0}),"p$4"),li=Object.defineProperty,At=si((t,e)=>li(t,"name",{value:e,configurable:!0}),"e"),ci=Object.defineProperty,ui=At((t,e)=>ci(t,"name",{value:e,configurable:!0}),"E");const Ct=String.raw,Ge=Ct`\p{Emoji}(?:\p{EMod}|[\u{E0020}-\u{E007E}]+\u{E007F}|\uFE0F?\u20E3?)`,pi=ui(()=>new RegExp(Ct`\p{RI}{2}|(?![#*\d](?!\uFE0F?\u20E3))${Ge}(?:\u200D${Ge})*`,"gu"),"default");var fi=Object.defineProperty,hi=At((t,e)=>fi(t,"name",{value:e,configurable:!0}),"p");Object.freeze(new Map([[0,0],[1,22],[2,22],[3,23],[4,24],[7,27],[8,28],[9,29],[30,39],[31,39],[32,39],[33,39],[34,39],[35,39],[36,39],[37,39],[40,49],[41,49],[42,49],[43,49],[44,49],[45,49],[46,49],[47,49],[90,39]]));const H=pi(),di=/[-_./\s]+/g,ee=/(\u001B\[[0-9;]*[a-z])/i,He=new RegExp("\\p{Script=Arabic}","u"),mi=new RegExp("\\p{Script=Bengali}","u"),W=new RegExp("\\p{Script=Cyrillic}","u"),gi=new RegExp("\\p{Script=Devanagari}","u"),vi=new RegExp("\\p{Script=Ethiopic}","u"),ye=new RegExp("\\p{Script=Greek}","u"),Ke=new RegExp("\\p{Script=Greek}+|\\p{Script=Latin}+|[^\\p{Script=Greek}\\p{Script=Latin}]+","gu"),wi=new RegExp("\\p{Script=Gujarati}","u"),yi=new RegExp("\\p{Script=Gurmukhi}","u"),Ye=new RegExp("\\p{Script=Hangul}","u"),Je=new RegExp("\\p{Script=Hebrew}","u"),bi=new RegExp("\\p{Script=Hiragana}","u"),Qe=new RegExp("\\p{Script=Han}","u"),$i=new RegExp("\\p{Script=Kannada}","u"),Oi=new RegExp("\\p{Script=Katakana}","u"),Pi=new RegExp("\\p{Script=Khmer}","u"),Ei=new RegExp("\\p{Script=Lao}","u"),L=new RegExp("\\p{Script=Latin}","u"),Ai=new RegExp("\\p{Script=Malayalam}","u"),Ci=new RegExp("\\p{Script=Myanmar}","u"),Ni=new RegExp("\\p{Script=Oriya}","u"),xi=new RegExp("\\p{Script=Sinhala}","u"),ki=new RegExp("\\p{Script=Tamil}","u"),_i=new RegExp("\\p{Script=Telugu}","u"),ji=new RegExp("\\p{Script=Thai}","u"),Li=new RegExp("\\p{Script=Tibetan}","u"),Ze=/[\u02BB\u02BC\u0027]/u,Ii=hi(t=>t.replace(H,""),"stripEmoji");var Si=Object.defineProperty,Nt=O((t,e)=>Si(t,"name",{value:e,configurable:!0}),"i$5"),Mi=Object.defineProperty,xt=Nt((t,e)=>Mi(t,"name",{value:e,configurable:!0}),"r"),Ui=Object.defineProperty,Ti=xt((t,e)=>Ui(t,"name",{value:e,configurable:!0}),"c");let kt=class{static{O(this,"l")}static{Nt(this,"y")}static{xt(this,"s")}static{Ti(this,"LRUCache")}capacity;cache;keyOrder;constructor(e){this.capacity=e,this.cache=new Map,this.keyOrder=[]}get(e){if(this.cache.has(e))return this.keyOrder=this.keyOrder.filter(n=>n!==e),this.keyOrder.push(e),this.cache.get(e)}has(e){return this.cache.has(e)}set(e,n){if(this.cache.has(e))this.keyOrder=this.keyOrder.filter(i=>i!==e);else if(this.cache.size>=this.capacity){const i=this.keyOrder.shift();i!==void 0&&this.cache.delete(i)}this.cache.set(e,n),this.keyOrder.push(e)}delete(e){this.cache.delete(e),this.keyOrder=this.keyOrder.filter(n=>n!==e)}clear(){this.cache.clear(),this.keyOrder=[]}size(){return this.cache.size}};var Vi=Object.defineProperty,Di=O((t,e)=>Vi(t,"name",{value:e,configurable:!0}),"r$5"),Ri=Object.defineProperty,Bi=Di((t,e)=>Ri(t,"name",{value:e,configurable:!0}),"a"),zi=Object.defineProperty,Wi=Bi((t,e)=>zi(t,"name",{value:e,configurable:!0}),"s");const Fi=Wi((t,e)=>typeof t!="string"||t===""?"":(e?.locale?t[0].toLocaleLowerCase(e.locale):t[0].toLowerCase())+t.slice(1),"lowerFirst");var qi=Object.defineProperty,Gi=O((t,e)=>qi(t,"name",{value:e,configurable:!0}),"I"),Hi=Object.defineProperty,fe=Gi((t,e)=>Hi(t,"name",{value:e,configurable:!0}),"W");const Ki=Yt(import.meta.url),Z=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,Yi=fe(t=>{if(typeof Z<"u"&&Z.versions&&Z.versions.node){const[e,n]=Z.versions.node.split(".").map(Number);if(e>22||e===22&&n>=3||e===20&&n>=16)return Z.getBuiltinModule(t)}return Ki(t)},"__cjs_getBuiltinModule"),{stripVTControlCharacters:Ji}=Yi("node:util");var Qi=Object.defineProperty,Zi=fe((t,e)=>Qi(t,"name",{value:e,configurable:!0}),"g");const be=new kt(1e3),Xi=/[.*+?^${}()|[\]\\]/g,eo=Zi(t=>{const e=t.join("");if(be.has(e))return be.get(e);const n=t.map(r=>r.replaceAll(Xi,String.raw`\$&`)).join("|"),i=new RegExp(n,"g");return be.set(e,i),i},"getSeparatorsRegex");var to=Object.defineProperty,no=fe((t,e)=>to(t,"name",{value:e,configurable:!0}),"t");const ao=no(t=>{const e=[];let n=0,i;for(H.lastIndex=0;(i=H.exec(t))!==null;)i.index>n&&e.push(t.slice(n,i.index)),e.push(i[0]),n=H.lastIndex;return n<t.length&&e.push(t.slice(n)),e.filter(Boolean)},"splitByEmoji");var io=Object.defineProperty,x=fe((t,e)=>io(t,"name",{value:e,configurable:!0}),"u");const oo=/[ČŠŽĐ]/i,_t=new Uint8Array(128),jt=new Uint8Array(128),Lt=new Uint8Array(128);for(let t=0;t<128;t++)_t[t]=t>=65&&t<=90?1:0,jt[t]=t>=97&&t<=122?1:0,Lt[t]=t>=48&&t<=57?1:0;const $e=x(t=>_t[t],"isUpper"),Xe=x(t=>jt[t],"isLower"),Oe=x(t=>Lt[t],"isDigit"),U=x((t,e,n,i,r)=>{if(t.length===0)return[];let a=!1;const c=Object.values(e);for(const g of c)if(g(t[0])){a=!0;break}if(!a&&!n)return[t];const s=[...t],m=[];let o=s[0],u="other";const d=Object.entries(e);for(const g of d){const[p,b]=g;if(b(s[0])){u=p;break}}let l=n&&i?s[0]===s[0].toLocaleUpperCase(i):!1;for(let g=1;g<s.length;g++){const p=s[g];let b="other";for(const E of d){const[N,f]=E;if(f(p)){b=N;break}}const $=n&&i?p===p.toLocaleUpperCase(i):!1;let y=!1;r?y=r(u,b,l,$,p,g,s):(u!==b&&u!=="other"&&b!=="other"&&(y=!0),n&&b!=="other"&&!l&&$&&(y=!0)),y?(m.push(o),o=p):o+=p,u=b,n&&(l=$)}return o&&o.length>0&&m.push(o),m.length>0?m:[t]},"handleScriptTransitions"),ro=x((t,e,n,i)=>{if(n.size===0)return e;for(const r of n)if(t.startsWith(r,e))return i.push(r),e+r.length;return e},"detectAndProcessAcronym"),It=x((t,e=new Set)=>{if(t.length===0)return[];if(t.toUpperCase()===t)return[t];let n=0;const i=[],r=t.length;for(let a=1;a<r;a++){const c=ro(t,n,e,i);if(c!==n){n=c,a=n-1;continue}const s=t.codePointAt(a-1),m=t.codePointAt(a),o=s&&s<128&&$e(s),u=m&&m<128&&$e(m),d=s&&s<128&&Xe(s),l=s&&s<128&&Oe(s),g=m&&m<128&&Oe(m);if(d&&u){i.push(t.slice(n,a)),n=a;continue}if(l&&!g||!l&&g){i.push(t.slice(n,a)),n=a;continue}if(g&&!l){let p=!1,b=!1;if(a+1<r){const $=t.codePointAt(a+1);p=$&&$<128&&$e($),b=$&&$<128&&Oe($)}if(!b&&p){i.push(t.slice(n,a),t.slice(a,a+1)),n=a+1;continue}}if(a+1<r){const p=t.codePointAt(a+1),b=p&&p<128&&Xe(p);if(o&&u&&b){const $=t.slice(n,a+1);e.has($)||(i.push(t.slice(n,a)),n=a)}}}return n<r&&i.push(t.slice(n)),i.filter(a=>a!=="")},"splitCamelCaseFast"),St=x((t,e,n)=>{if(t.length===0)return[];const i=t===t.toLocaleUpperCase(e);if(e.startsWith("de")){if(!i&&t.replaceAll("ß","SS")===t.toLocaleUpperCase(e))return[t];const o=[...t],u=o.length,d=[];let l=o[0],g=o[0]===o[0].toLocaleUpperCase(e),p=g,b=g?0:-1;for(let $=1;$<u;$++){const y=o[$],E=y===y.toLocaleUpperCase(e);if(E===g)l+=y;else if(E)l&&l.length>0&&(d.push(l),l=y),p=!0,b=$;else{if(p&&$-b>1){const N=o[$-1],f=l.slice(0,-1);f&&f.length>0&&d.push(f),l=N+y}else l+=y;p=!1,b=-1}g=E}return l&&l.length>0&&d.push(l),d}if(e.startsWith("uk")||e.startsWith("ru")||e.startsWith("bg")||e.startsWith("sr")||e.startsWith("mk")||e.startsWith("be")){if(!W.test(t)&&!L.test(t))return[t];const o=[...t],u=o.length,d=[];let l=o[0];const g=o[0];let p;W.test(g)?p=1:L.test(g)?p=2:p=0;let b=g===g.toLocaleUpperCase(e);for(let y=1;y<u;y++){const E=o[y];let N;W.test(E)?N=1:L.test(E)?N=2:N=0;const f=E===E.toLocaleUpperCase(e);p!==N&&(p===1||p===2)&&(N===1||N===2)||N===p&&!b&&f?(d.push(l),l=E):l+=E,p=N,b=f}l&&l.length>0&&d.push(l);const $=[];for(let y=0;y<d.length;y++)y<d.length-1&&d[y].length===1&&L.test(d[y])&&W.test(d[y+1][0])?($.push(d[y]+d[y+1]),y+=1):$.push(d[y]);return $}if(e.startsWith("el")){if(!ye.test(t)&&!L.test(t))return[t];const o=[];Ke.lastIndex=0;let u;for(;(u=Ke.exec(t))!==null;)o.push(u[0]);o.length===0&&o.push(t);const d=[];if(o.length===1){const l=o[0];if(!l||!ye.test(l[0])||l.length===1)return[l??t]}for(const l of o){if(!l)continue;if(!ye.test(l[0])||l.length===1){d.push(l);continue}const g=l.length;let p=l[0],b=l[0]===l[0].toLocaleUpperCase(e);for(let $=1;$<g;$++){const y=l[$],E=y===y.toLocaleUpperCase(e);!b&&E?(d.push(p),p=y):p+=y,b=E}p&&d.push(p)}return d}if(e.startsWith("ja")||e.startsWith("ko")){const o=e.startsWith("ja"),u=o?{hiragana:x(l=>bi.test(l),"hiragana"),kanji:x(l=>Qe.test(l),"kanji"),katakana:x(l=>Oi.test(l),"katakana"),latin:x(l=>L.test(l),"latin")}:{hangul:x(l=>Ye.test(l),"hangul"),latin:x(l=>L.test(l),"latin")},d=new Set(["が","で","と","に","の","は","へ","も","や","を"]);if(o){const l=U(t,u,!1,e,(p,b)=>p==="hiragana"&&b==="katakana"||p==="katakana"&&b==="hiragana"||p==="hiragana"&&b==="latin"||p==="katakana"&&b==="latin"||p==="kanji"&&b==="latin"||p==="latin"&&(b==="hiragana"||b==="katakana"||b==="kanji")),g=[];for(const p of l){const b=p;b.length===1&&d.has(b)&&g.length>0?g[g.length-1]=g.at(-1)+b:g.push(b)}return g.length>0?g:[t]}return U(t,u,!1,e,(l,g)=>l==="hangul"&&g==="latin"||l==="latin"&&g==="hangul")}if(e.startsWith("sl")){const o=[...t],u=o.length,d=[];let l=o[0],g=o[0]===o[0].toLocaleUpperCase(e);for(let p=1;p<u;p++){const b=o[p],$=b===b.toLocaleUpperCase(e),y=oo.test(b),E=p<u-1&&o[p+1]===o[p+1].toLocaleUpperCase(e);!g&&$||y&&E?(d.push(l),l=b,y&&E&&(d.push(l),l="")):l+=b,g=$}return l&&l.length>0&&d.push(l),d}if(e.startsWith("zh"))return U(t,{han:x(o=>Qe.test(o),"han"),latin:x(o=>L.test(o),"latin")},!1,e);if(["ar","fa","he","ur"].includes(e.split("-")[0])){const o=x(u=>Je.test(u)||He.test(u),"isRtlChar");return U(t,{latin:x(u=>L.test(u),"latin"),rtl:x(u=>o(u),"rtl")},!1,e)}if(["am","bn","gu","hi","km","kn","lo","ml","mr","ne","or","pa","si","ta","te","th"].includes(e.split("-")[0])){const o=x(u=>gi.test(u)||mi.test(u)||wi.test(u)||yi.test(u)||$i.test(u)||ki.test(u)||_i.test(u)||Ai.test(u)||xi.test(u)||ji.test(u)||Ei.test(u)||Li.test(u)||Ci.test(u)||vi.test(u)||Pi.test(u)||Ni.test(u),"isIndicChar");return U(t,{indic:x(u=>o(u),"indic"),latin:x(u=>L.test(u),"latin")},!1,e)}if(["be","bg","ru","sr","uk"].includes(e))return U(t,{cyrillic:x(o=>W.test(o),"cyrillic"),latin:x(o=>L.test(o),"latin")},!0,e);if(["ar","fa","he"].includes(e))return U(t,{latin:x(o=>L.test(o),"latin"),rtl:x(o=>Je.test(o)||He.test(o),"rtl")},!1,e);if(e.startsWith("ko"))return U(t,{hangul:x(o=>Ye.test(o),"hangul"),latin:x(o=>L.test(o),"latin")},!1,e);if(e.startsWith("uz")){if(!W.test(t)&&!L.test(t))return[t];const o=[...t],u=o.length,d=[];let l=o[0],g=o[0]===o[0].toLocaleUpperCase(e);for(let p=1;p<u;p++){const b=o[p],$=b===b.toLocaleUpperCase(e);if(Ze.test(b)||Ze.test(o[p-1])){l+=b;continue}!g&&$?(d.push(l),l=b):l+=b,g=$}return l&&l.length>0&&d.push(l),d}const r=[...t],a=r.length,c=[];let s=r[0],m=r[0]===r[0].toLocaleUpperCase(e);for(const o of n)if(t.startsWith(o)){c.push(o),s=r[o.length],m=s===s.toLocaleUpperCase(e);break}for(let o=1;o<a;o++){const u=r[o],d=u===u.toLocaleUpperCase(e);let l=0;for(const g of n)if(t.startsWith(g,o)){c.push(s,g),l=g.length,s="";const p=g.at(-1);p&&(m=p===p.toLocaleUpperCase(e));break}if(l>0){o+=l-1;continue}!m&&d?(c.push(s),s=u):s+=u,m=d}return s&&c.push(s),c},"splitCamelCaseLocale"),so=x((t,e,n)=>{const i=[],r=ee.test(t)?t.split(ee).filter(Boolean):[t];for(const a of r){const c=a;if(ee.test(c))i.push(c);else{const s=H.test(c)?ao(c).filter(Boolean):[c];for(const m of s)if(H.test(m))i.push(m);else if(e){const o=e.toLowerCase().split("-")[0];i.push(...St(m,o,n))}else i.push(...It(m,n))}}return i},"processTextWithAnsiEmoji"),lo=x((t,e={})=>{if(!t||typeof t!="string")return[];const{handleAnsi:n=!1,handleEmoji:i=!1,knownAcronyms:r=[],locale:a,normalize:c=!1,separators:s,stripAnsi:m=!1,stripEmoji:o=!1}=e,u=new Set([...r].toSorted((y,E)=>E.length-y.length));let d=t;m&&(d=Ji(d)),o&&(d=Ii(d));let l;Array.isArray(s)?l=eo(s):s instanceof RegExp?l=s:l=di;const g=[];let p=d;const b=l.flags.includes("g")?l:new RegExp(l.source,`${l.flags}g`);for(;p.length>0;){const y=b.exec(p);if(!y){p===".."?g.push(".."):p==="."?g.push("."):p.length>0&&g.push(p);break}const E=y.index,N=y[0],f=N.length,h=p.slice(0,E),v=p.slice(E+f);if(N.startsWith("../"))g.push(".."),p=p.slice(E+3);else if(N.startsWith("./"))g.push("."),p=p.slice(E+2);else if(E===0&&N==="..")g.push(".."),p=p.slice(2);else if(E===0&&N===".")g.push("."),p=p.slice(1);else{h.length>0&&g.push(h);let w=0;for(;(w=N.indexOf("../",w))!==-1;)g.push(".."),w+=3;for(w=0;(w=N.indexOf("./",w))!==-1;)(w===0||N[w-1]!==".")&&g.push("."),w+=2;let P=v;for(;P.startsWith("../");)g.push(".."),P=P.slice(3);for(;P.startsWith("./");)g.push("."),P=P.slice(2);if(P===".."){g.push("..");break}else if(P==="."){g.push(".");break}else p=P}b.lastIndex=0}if(g.length===0){const y=d.split(l).filter(Boolean);g.push(...y)}let $=[];for(const y of g)n||i?$.push(...so(y,a,u)):a?$.push(...St(y,a,u)):$.push(...It(y,u));return c&&($=$.map(y=>u.has(y)?y:a&&y===y.toLocaleUpperCase(a)?y[0]+y.slice(1).toLocaleLowerCase(a):y.toUpperCase()===y&&!u.has(y)?y.slice(0,1)+y.slice(1).toLowerCase():y)),$},"splitByCase");var co=Object.defineProperty,uo=O((t,e)=>co(t,"name",{value:e,configurable:!0}),"r$4"),po=Object.defineProperty,fo=uo((t,e)=>po(t,"name",{value:e,configurable:!0}),"o"),ho=Object.defineProperty,mo=fo((t,e)=>ho(t,"name",{value:e,configurable:!0}),"s");const go=mo((t,e)=>typeof t!="string"||t===""?"":(e?.locale?t[0].toLocaleUpperCase(e.locale):t[0].toUpperCase())+t.slice(1),"upperFirst");var vo=Object.defineProperty,wo=O((t,e)=>vo(t,"name",{value:e,configurable:!0}),"r$3"),yo=Object.defineProperty,bo=wo((t,e)=>yo(t,"name",{value:e,configurable:!0}),"r"),$o=Object.defineProperty,Oo=bo((t,e)=>$o(t,"name",{value:e,configurable:!0}),"n");const Po=Oo((t,e)=>`${t}::${e?.joiner??""}::${e?.locale??""}::${e?.knownAcronyms?.join(",")??""}::${e?.normalize?"true":"false"}`,"generateCacheKey");var Eo=Object.defineProperty,Ao=O((t,e)=>Eo(t,"name",{value:e,configurable:!0}),"i$3"),Co=Object.defineProperty,No=Ao((t,e)=>Co(t,"name",{value:e,configurable:!0}),"f"),xo=Object.defineProperty,ko=No((t,e)=>xo(t,"name",{value:e,configurable:!0}),"l");const _o=ko((t,e)=>{const{length:n}=t;if(n===0)return"";if(n===1)return t[0];const i=[];let r="",a="";for(let c=0;c<n;c++){const s=t[c];if(ee.test(s)){r?(i.push(r+a+s),r="",a=""):(i.length>0&&i.push(e),r=s);continue}r?(a&&(a+=e),a+=s):(i.length>0&&i.push(e),i.push(s))}return i.join("")},"joinSegments");var jo=Object.defineProperty,Lo=O((t,e)=>jo(t,"name",{value:e,configurable:!0}),"r$2"),Io=Object.defineProperty,So=Lo((t,e)=>Io(t,"name",{value:e,configurable:!0}),"a"),Mo=Object.defineProperty,Uo=So((t,e)=>Mo(t,"name",{value:e,configurable:!0}),"e");const To=/(?<![a-zß])SS(?![a-z])/g,Vo=Uo(t=>t.replaceAll(To,"ß"),"normalizeGermanEszett");var Do=Object.defineProperty,Ro=O((t,e)=>Do(t,"name",{value:e,configurable:!0}),"c$2"),Bo=Object.defineProperty,zo=Ro((t,e)=>Bo(t,"name",{value:e,configurable:!0}),"c"),Wo=Object.defineProperty,Fo=zo((t,e)=>Wo(t,"name",{value:e,configurable:!0}),"o");const qo=new kt(1e3),Mt=Fo((t,e)=>{if(typeof t!="string"||!t)return"";const n=e?.cache??!1,i=e?.cacheStore??qo;let r;if(n&&(r=Po(t,e)),n&&r&&i.has(r))return i.get(r);let a=!0;const c=_o(lo(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=>{if(e?.handleAnsi&&ee.test(s))return s;const m=e?.locale?.startsWith("de")?Vo(s):s,o=e?.locale?m.toLocaleLowerCase(e.locale):m.toLowerCase();return a?(a=!1,Fi(o,e)):go(o,e)}),"");return n&&r&&i.set(r,c),c},"camelCase");var Go=Object.defineProperty,he=O((t,e)=>Go(t,"name",{value:e,configurable:!0}),"a$2");const Ho=he(t=>{t.options?.forEach(e=>{e.__camelCaseName__=Mt(e.name)})},"processOptionNames"),Ko=he(t=>{if(!Array.isArray(t.options)||t.options.length===0)return;const e=new Set;for(const i of t.options)e.add(i.name);const n=[];for(const i of t.options)if(i.name.startsWith("no-")){const r=i.name.replace("no-","");if(!e.has(r)){if(i.type!==Boolean)throw new Error(`Cannot add negated option "${i.name}" to command "${t.name}" because it is not a boolean.`);const a={...i,defaultValue:i.defaultValue===void 0?!0:!i.defaultValue,name:r};n.push(a),e.add(r)}}n.length>0&&t.options.push(...n)},"addNegatableOptions"),Yo=he((t,e)=>{if(!e.options||e.options.length===0)return;const{options:n}=t,i=new Map;for(const a of e.options)if(a.name.startsWith("no-")){const c=Mt(a.name);i.set(c,a)}const r=Object.keys(n).filter(a=>i.has(a));if(r.length!==0)for(const a of r){const c=a.charAt(2);if(!c)continue;const s=c.toLowerCase()+a.slice(3),m=i.get(a);m&&(m.__negated__=!0),n[s]=!n[a],Reflect.deleteProperty(n,a)}},"mapNegatableOptions"),Jo=he((t,e)=>{if(!e.options||e.options.length===0)return;const n=new Map;for(const r of e.options)r.__camelCaseName__&&r.__negated__===void 0&&r.implies!==void 0&&n.set(r.__camelCaseName__,r);if(n.size===0)return;const{options:i}=t;for(const r of Object.keys(i)){const a=n.get(r);if(a?.implies){const{implies:c}=a;for(const[s,m]of Object.entries(c))i[s]===void 0&&(i[s]=m)}}},"mapImpliedOptions");var Qo=Object.defineProperty,de=O((t,e)=>Qo(t,"name",{value:e,configurable:!0}),"e$2");const Zo=de(()=>!!process.versions.electron,"isElectronApp"),Xo=de(()=>Zo()&&!process.defaultApp,"isBundledElectronApp"),er=de(()=>Xo()?0:1,"getProcessArgvBinIndex"),tr=de(t=>t.slice(er()+1),"hideBin");var nr=Object.defineProperty,Ut=O((t,e)=>nr(t,"name",{value:e,configurable:!0}),"e$1");const ar=" ",ir=Ut((t,e)=>t===e?!0:t.length!==e.length?!1:t.every((n,i)=>n===e[i]),"equals"),or=Ut(t=>{if(typeof t=="string")return t.split(ar);const e=Ce();return ir(t,e)?tr(t):t},"parseRawCommand");var rr=Object.defineProperty,Pe=O((t,e)=>rr(t,"name",{value:e,configurable:!0}),"r");const sr=Pe(t=>{const e=Pe(a=>{t.error(`Uncaught exception: ${a.message||a}`),a.stack&&t.error(a.stack),X(1)},"uncaughtExceptionHandler"),n=Pe((a,c)=>{if(a instanceof Error)t.error(`Promise rejection: ${a.message||a}`),a.stack&&t.error(a.stack);else{let s;if(typeof a=="string")s=a;else try{s=JSON.stringify(a)}catch{s=String(a)}t.error(`Promise rejection: ${s}`)}X(1)},"unhandledRejectionHandler"),i=Le("uncaughtException",e),r=Le("unhandledRejection",n);return()=>{i(),r()}},"registerExceptionHandler");var lr=Object.defineProperty,Y=O((t,e)=>lr(t,"name",{value:e,configurable:!0}),"e");const se=100,Tt=/^[a-z][\w-]*$/i,_e=Y((t,e)=>{if(typeof t!="string"||t.trim().length===0)throw new C(`${e} must be a non-empty string`,"INVALID_INPUT",{fieldName:e,value:t});return t.trim()},"validateNonEmptyString"),et=Y((t,e)=>{if(!Array.isArray(t)||!t.every(n=>typeof n=="string"))throw new C(`${e} must be an array of strings`,"INVALID_INPUT",{fieldName:e,value:t});return t},"validateStringArray");Y((t,e)=>{if(typeof t!="function")throw new C(`${e} must be a function`,"INVALID_INPUT",{fieldName:e,value:t});return t},"validateFunction");const Ee=Y((t,e)=>{if(typeof t!="object"||t===null)throw new C(`${e} must be an object`,"INVALID_INPUT",{fieldName:e,value:t});return t},"validateObject"),ie=Y(t=>{const e=_e(t,"Command name");if(e.length>se)throw new C(`Command name is too long (maximum ${String(se)} characters)`,"INVALID_COMMAND_NAME",{commandName:e,length:e.length});if(e.includes("..")||e.includes("/")||e.includes("\\")||e.includes(";")||e.includes("|")||e.includes("&"))throw new C(`Command name "${e}" contains invalid characters`,"INVALID_COMMAND_NAME",{commandName:e});if(!Tt.test(e))throw new C(`Command name "${e}" must start with a letter and contain only letters, numbers, hyphens, and underscores`,"INVALID_COMMAND_NAME",{commandName:e});return e},"validateCommandName");Y(t=>{const e=_e(t,"Plugin name");if(e.length>se)throw new C(`Plugin name is too long (maximum ${String(se)} characters)`,"INVALID_PLUGIN_NAME",{length:e.length,pluginName:e});if(e.includes("..")||e.includes("/")||e.includes("\\")||e.includes(";")||e.includes("|")||e.includes("&"))throw new C(`Plugin name "${e}" contains invalid characters`,"INVALID_PLUGIN_NAME",{pluginName:e});if(!Tt.test(e))throw new C(`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 cr=Object.defineProperty,me=O((t,e)=>cr(t,"name",{value:e,configurable:!0}),"s");const ur=new Set([`
4
+ `,"\r"," ","\0",'"',"$","&","'","(",")",";","<",">","[","\\","]","`","{","|","}"]),pr=/^[A-Z]:/i,fr=me(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(ur.has(e))throw new Error(`Argument contains dangerous character: ${e}`);return t.trim()},"sanitizeArgument"),tt=me(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=>fr(e))},"sanitizeArguments");me(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("/")||pr.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 Lr{static{O(this,"RateLimiter")}static{me(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(),i=this.attempts.get(e);return!i||n>i.resetTime?(this.attempts.set(e,{count:1,resetTime:n+this.windowMs}),this.cleanup(n),!0):i.count>=this.maxAttempts?!1:(i.count+=1,!0)}reset(e){this.attempts.delete(e)}cleanup(e){for(const[n,i]of this.attempts.entries())e>i.resetTime&&this.attempts.delete(n)}}var hr=Object.defineProperty,re=O((t,e)=>hr(t,"name",{value:e,configurable:!0}),"v");const dr=/^-([^\d-])$/,mr=/^--(\S+)/,gr=/^-([^\d-]{2,})$/,Ae=re(t=>dr.test(t)||mr.test(t)||gr.test(t),"isOption");class Ir{static{O(this,"Cli")}static{re(this,"Cli")}#t;#e;#o;#c;#v;#u;#w;#r;#n;#a;#p;#s;#l;#f=!1;#y;#b=!1;#h;#d;#m;#g=[];#A(){return this.#h===void 0&&(this.#h=[...this.#a.keys()]),this.#h}#$(){return this.#d===void 0&&(this.#d=[...this.#n.keys()]),this.#d}#i(){return this.#m===void 0&&(this.#m=[...this.#A(),...this.#$()]),this.#m}#O(){return this.#g.length===0?ae:[...ae,...this.#g]}#C(){this.#h=void 0,this.#d=void 0,this.#m=void 0}#P(){if(this.#o===void 0){const e=or(this.#e.argv);this.#o=tt(e),this.#N()}return this.#o}#N(){if(!this.#o)return;const e=G();let n=!1;for(const i of this.#o){if(i==="--quiet"||i==="-q"){e.CEREBRO_OUTPUT_LEVEL=String(Wt),n=!0;break}if(i==="--verbose"||i==="-v"){e.CEREBRO_OUTPUT_LEVEL=String(Ft),n=!0;break}if(i==="--debug"||i==="-vvv"){e.CEREBRO_OUTPUT_LEVEL=String(F),n=!0;break}}n||(e.CEREBRO_OUTPUT_LEVEL=Object.hasOwn(e,"DEBUG")?String(F):String(je))}#x(){this.#b||(this.#y=sr(this.#t),this.#b=!0)}#E(e,n,i,r){this.#t.debug(`command '${r}' found, parsing command args: ${n.join(", ")}`);const{arguments_:a,booleanValues:c,parsedArgs:s}=Fa(e,n,this.#O()),m=Object.keys(c).length>0;let o=s;m&&(o={...s,_all:{...s._all,...c}}),ei(a,o,e);const u=Wa(e,s,c,i);u.runtime=this,u.argv=this.#P();const d=e.options&&e.options.length>0;if(d&&e.options){const l=e.options.filter(g=>g.name.startsWith("no-"));for(const g of l){const p=g.name.replace("no-",""),b=`--${g.name}`,$=`--${p}`,y=n.includes(b),E=n.includes($);if(y&&E)throw new nt(p,g.name)}}return d&&(Yo(u,e),Jo(u,e)),ti(a,u.options,e),G().CEREBRO_OUTPUT_LEVEL===String(F)&&(this.#t.debug("command options parsed from options:"),this.#t.debug(JSON.stringify(u.options,null,2)),this.#t.debug("command argument parsed from argument:"),this.#t.debug(JSON.stringify(u.argument,null,2))),{arguments_:a,booleanValues:c,commandArgs:o,parsedArgs:s,toolbox:u}}constructor(e,n={}){if(typeof e!="string"||e.trim().length===0)throw new C("CLI name must be a non-empty string","INVALID_INPUT",{cliName:e});this.#v=e.trim();const i=n.argv??Ce(),r=n.cwd??qt();if(this.#e={...n,argv:i,cwd:r},this.#e.argv&&!Array.isArray(this.#e.argv))throw new C("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 C("CLI cwd option must be a string","INVALID_INPUT",{cwd:this.#e.cwd});if(this.#e.packageName&&typeof this.#e.packageName!="string")throw new C("CLI packageName option must be a string","INVALID_INPUT",{packageName:this.#e.packageName});if(this.#e.packageVersion&&typeof this.#e.packageVersion!="string")throw new C("CLI packageVersion option must be a string","INVALID_INPUT",{packageVersion:this.#e.packageVersion});const a=G();if(a.CEREBRO_OUTPUT_LEVEL=String(je),typeof this.#e.logger=="object"){const c=["debug","error","info","log","warn"],s=[],m=this.#e.logger;for(const o of c)typeof m[o]!="function"&&s.push(o);if(s.length>0)throw new C(`Logger object is missing required methods: ${s.join(", ")}`,"INVALID_INPUT",{logger:this.#e.logger,missingMethods:s});this.#t=this.#e.logger}else this.#t={...console,debug:re((...c)=>{a.CEREBRO_OUTPUT_LEVEL===String(F)&&console.debug(...c)},"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.#a=new Map,this.#p=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){Ee(e,"Command"),ie(e.name);const n=typeof e.execute=="function",i=typeof e.loader=="function";if(n&&i)throw new C(`Command "${e.name}" cannot define both "execute" and "loader" — choose one`,"INVALID_COMMAND",{commandName:e.name});if(!n&&!i)throw new C(`Command "${e.name}" must define either "execute" or "loader"`,"INVALID_COMMAND",{commandName:e.name});e.alias&&(typeof e.alias=="string"?ie(e.alias):et(e.alias,"Command alias").forEach(c=>ie(c))),e.argument&&Ee(e.argument,"Command argument"),e.options&&Ee(e.options,"Command options"),e.commandPath&&(et(e.commandPath,"Command commandPath"),e.commandPath.forEach(c=>{ie(c)}));const r=oi(e.name,e.commandPath),a=Q(r);if(this.#a.has(a))throw new C(`Command with path "${a}" already exists`,"DUPLICATE_COMMAND",{commandName:e.name,commandPath:e.commandPath});if(this.#n.has(e.name)&&!e.commandPath)throw new C(`Command with name "${e.name}" already exists`,"DUPLICATE_COMMAND",{commandName:e.name});if(e.options)for(const c of e.options)Se(c);if(ni(e),Ko(e),Ho(e),e.options&&(e.__conflictingOptions__=e.options.filter(c=>c.conflicts!==void 0),e.__requiredOptions__=e.options.filter(c=>c.required===!0)),this.#n.set(e.name,e),this.#a.set(a,r),this.#p.set(a,e),this.#C(),e.alias!==void 0){const c=typeof e.alias=="string"?[e.alias]:e.alias;for(const s of c){if(G().CEREBRO_OUTPUT_LEVEL===String(F)&&this.#t.debug("adding alias",s),this.#n.has(s))throw new C(`Command alias "${s}" conflicts with existing command`,"DUPLICATE_COMMAND",{alias:s,commandName:e.name});this.#n.set(s,e)}}return this}addGlobalOption(e){const n=e,i=new Set(ae.map(a=>a.name)),r=new Set(ae.map(a=>a.alias).filter(Boolean));if(i.has(n.name))throw new C(`Cannot add global option "--${n.name}": it conflicts with a built-in global option`,"DUPLICATE_OPTION",{optionName:n.name});if(n.alias&&r.has(n.alias))throw new C(`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(a=>a.name)).has(n.name))throw new C(`Global option "--${n.name}" has already been added`,"DUPLICATE_OPTION",{optionName:n.name});return n.group="global",Se(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 on(this.#t),this.#r.register({description:"Attaches the logger to the toolbox",execute:re(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:i=!0,...r}=e;if(!this.#n.has("help")){const{default:h}=await import("../commands/help-command.js");this.addCommand(new h(this.#n))}const a=this.#$(),c=this.#a;this.#x();const s=this.#P();let m,o=[...s];const u=Gt(),d=Ht(),l=Ce();this.#t.debug(`process.execPath: ${u}`),this.#t.debug(`process.execArgv: ${d.join(" ")}`),this.#t.debug(`process.argv: ${l.join(" ")}`);const g=ii(c,[...s]);if(g.commandPath)m=g.commandPath,o=g.argv;else{if(s.length>1&&s[0]&&s[1]&&!Ae(s[0])&&!Ae(s[1])){const v=[];let w=0;for(;w<s.length;){const k=s[w];if(!k||Ae(k))break;v.push(k),w+=1}const P=Q(v);if(v[0]&&!a.includes(v[0])){const k=this.#i(),A=q(P,k);throw new B(P,A)}}let h;try{h=mn([null,...a],[...s])}catch(v){if(v instanceof Error&&v.name==="INVALID_COMMAND"&&"command"in v){const w=v.command,P=this.#i(),k=q(w,P);throw new B(w,k)}throw v}h.command&&(m=[h.command],o=h.argv)}if(!m)if(this.#s)m=[this.#s];else{const h=this.#i();throw new B("",h)}const p=Q(m),b=this.#a.get(p);let $;if(b){if($=this.#p.get(p),!$||Q(b)!==p){const h=this.#i(),v=q(p,h);throw new B(p,v)}}else{const h=m.at(-1);if($=h?this.#n.get(h):void 0,!$){const v=this.#i(),w=q(p,v);throw new B(p,w)}}if(typeof $.execute!="function"&&typeof $.loader!="function")return this.#t.error(`Command "${$.name}" has no function to execute.`),i?X(1):void 0;const y=o;let E,N;try{({commandArgs:E,toolbox:N}=this.#E($,y,r,p))}catch(h){if(this.#t.error(h),i)return X(1);throw h}const f=this.getPluginManager();try{!this.#f&&f.hasPlugins()&&(await f.init({cli:this,cwd:this.#c,logger:this.#t}),this.#f=!0),await f.executeLifecycle("execute",N),await f.executeLifecycle("beforeCommand",N);let h;const v=E.global;if(v?.help){const w=this.#n.get("help");if(!w)throw new C("Help command not found","COMMAND_NOT_FOUND");h=await z(w,N,E)}else if(v?.version??v?.V){const w=this.#n.get("version");if(!w)throw new C("Version command not found","COMMAND_NOT_FOUND");h=await z(w,N,E)}else h=await z($,N,E);return await f.executeLifecycle("afterCommand",N,h),i?X(0):void 0}catch(h){throw await f.executeErrorHandlers(h,N),h}finally{n&&this.dispose()}}async runCommand(e,n={}){const{argv:i=[],...r}=n;_e(e,"Command name");const a=e.split(" ").filter(Boolean),c=Q(a),s=this.#a.get(c)?this.#p.get(c):this.#n.get(e);if(!s){const l=this.#i(),g=q(c||e,l);throw new B(e,g)}if(typeof s.execute!="function"&&typeof s.loader!="function")throw new C(`Command "${s.name}" has no function to execute`,"INVALID_COMMAND",{commandName:s.name});const m=[...tt(i)];this.#t.debug(`running command '${e}' programmatically with args: ${m.join(", ")}`);const{commandArgs:o,toolbox:u}=this.#E(s,m,r,c||e),d=this.getPluginManager();try{!this.#f&&d.hasPlugins()&&(await d.init({cli:this,cwd:this.#c,logger:this.#t}),this.#f=!0),await d.executeLifecycle("execute",u),await d.executeLifecycle("beforeCommand",u);let l;const g=o.global;if(g?.help){const p=this.#n.get("help");if(!p)throw new C("Help command not found","COMMAND_NOT_FOUND");l=await z(p,u,o)}else if(g?.version??g?.V){const p=this.#n.get("version");if(!p)throw new C("Version command not found","COMMAND_NOT_FOUND");l=await z(p,u,o)}else l=await z(s,u,o);return await d.executeLifecycle("afterCommand",u,l),l}catch(l){throw await d.executeErrorHandlers(l,u),l}}}export{Ir as Cli};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@visulima/cerebro",
3
- "version": "3.0.0-alpha.15",
3
+ "version": "3.0.0-alpha.17",
4
4
  "description": "A delightful toolkit for building cross-runtime CLIs for Node.js, Deno, and Bun.",
5
5
  "keywords": [
6
6
  "ansi",
@@ -128,7 +128,7 @@
128
128
  "@bomb.sh/tab": "0.0.15",
129
129
  "@visulima/boxen": "3.0.0-alpha.10",
130
130
  "@visulima/find-cache-dir": "3.0.0-alpha.9",
131
- "@visulima/pail": "4.0.0-alpha.13",
131
+ "@visulima/pail": "4.0.0-alpha.14",
132
132
  "github-slugger": "2.0.0"
133
133
  },
134
134
  "peerDependenciesMeta": {
@@ -1,4 +0,0 @@
1
- var Tt=Object.defineProperty;var O=(t,e)=>Tt(t,"name",{value:e,configurable:!0});import{createRequire as Vt}from"node:module";import{VERBOSITY_DEBUG as F,POSITIONALS_KEY as ie,VERBOSITY_QUIET as Bt,VERBOSITY_VERBOSE as zt,VERBOSITY_NORMAL as je}from"./VERBOSITY_QUIET-XPultrIA.js";import{c as C}from"./cerebro-error-BnJTixb2.js";import{d as G,h as Ce,e as re,o as Le,a as Wt,i as Ft,f as qt}from"./runtime-process-DKHFvYkv.js";import{distance as Gt}from"fastest-levenshtein";const Dt=Vt(import.meta.url),J=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,Rt=O(t=>{if(typeof J<"u"&&J.versions&&J.versions.node){const[e,n]=J.versions.node.split(".").map(Number);if(e>22||e===22&&n>=3||e===20&&n>=16)return J.getBuiltinModule(t)}return Dt(t)},"__cjs_getBuiltinModule"),{createRequire:Ht}=Rt("node:module"),ne=[{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 Kt=Object.defineProperty,Yt=O((t,e)=>Kt(t,"name",{value:e,configurable:!0}),"t$9");let B=class extends C{static{O(this,"a")}static{Yt(this,"CommandNotFoundError")}commandName;constructor(e,n=[]){const i=`Command "${e}" not found${n.length>0?`. Did you mean: ${n.join(", ")}?`:""}`;super(i,"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 Jt=Object.defineProperty,Qt=O((t,e)=>Jt(t,"name",{value:e,configurable:!0}),"e$7");let nt=class extends C{static{O(this,"o")}static{Qt(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 Zt=Object.defineProperty,Xt=O((t,e)=>Zt(t,"name",{value:e,configurable:!0}),"e$6");let en=class extends C{static{O(this,"o")}static{Xt(this,"PluginError")}pluginName;constructor(e,n,i){super(`Plugin "${e}" error: ${n}`,"PLUGIN_ERROR",{originalError:i,pluginName:e}),this.name="PluginError",this.pluginName=e,i&&(this.cause=i)}};var tn=Object.defineProperty,Ie=O((t,e)=>tn(t,"name",{value:e,configurable:!0}),"d$7");let nn=class{static{O(this,"p")}static{Ie(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`);G().CEREBRO_OUTPUT_LEVEL===String(F)&&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 i of n)if(typeof i.init=="function"){this.logger.debug(`initializing plugin: ${i.name}`);try{await i.init(e)}catch(r){const a=new en(i.name,`Failed to initialize: ${r instanceof Error?r.message:String(r)}`,r instanceof Error?r:void 0);throw this.logger.error(a.message),a}}this.initialized=!0}async executeLifecycle(e,n,i){if(!this.initialized)throw new Error("PluginManager not initialized");if(this.plugins.size===0)return;const r=this.getDependencyOrder();for(const a of r){const c=a[e];if(typeof c=="function"){this.logger.debug(`executing ${e} hook for plugin: ${a.name}`);try{await(e==="afterCommand"?c(n,i):c(n))}catch(s){throw this.logger.error(`Error in ${e} hook for plugin "${a.name}":`,s),s}}}}async executeErrorHandlers(e,n){if(!this.initialized||this.plugins.size===0)return;const i=this.getDependencyOrder();for(const r of i)if(typeof r.onError=="function"){this.logger.debug(`executing error handler for plugin: ${r.name}`);try{await r.onError(e,n)}catch(a){this.logger.error(`Error in error handler for plugin "${r.name}":`,a)}}}getDependencyOrder(){if(this.cachedDependencyOrder!==void 0)return this.cachedDependencyOrder;const e=[],n=new Set,i=new Set,r=Ie(a=>{if(n.has(a))return;if(i.has(a))throw new Error(`Circular dependency detected involving plugin "${a}"`);const c=this.plugins.get(a);if(!c)throw new Error(`Plugin "${a}" not found`);if(i.add(a),c.dependencies)for(const s of c.dependencies)r(s);i.delete(a),n.add(a),e.push(c)},"visit");for(const a of this.plugins.keys())r(a);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 an=Object.defineProperty,on=O((t,e)=>an(t,"name",{value:e,configurable:!0}),"n$c");const ee=on(t=>t.type?.name==="Boolean","optionIsBoolean");var rn=Object.defineProperty,at=O((t,e)=>rn(t,"name",{value:e,configurable:!0}),"p$8");const sn=at(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"),Se=at(t=>(ee(t)||(t.typeLabel=t.typeLabel??sn(t),t.defaultOption&&(t.typeLabel=`${t.typeLabel} (D)`),t.required&&(t.typeLabel=`${t.typeLabel} (R)`)),t),"mapOptionTypeLabel");var ln=Object.defineProperty,it=O((t,e)=>ln(t,"name",{value:e,configurable:!0}),"e$4");const cn=new RegExp(/^-([^\d-])$/),un=new RegExp(/^--(\S+)/),pn=new RegExp(/^-([^\d-]{2,})$/),fn=it(t=>cn.test(t)||un.test(t)||pn.test(t),"isOption"),dn=it((t,e)=>{const n=e[0]&&fn(e[0])||e.length===0?null:e.shift()??null;if(!t.includes(n)){const i=new Error(`Command not recognised: ${String(n)}`);throw i.command=n,i.name="INVALID_COMMAND",i}return{argv:e,command:n}},"commandLineCommands");var hn=Object.defineProperty,ot=O((t,e)=>hn(t,"name",{value:e,configurable:!0}),"i$b"),mn=Object.defineProperty,rt=ot((t,e)=>mn(t,"name",{value:e,configurable:!0}),"i"),gn=Object.defineProperty,st=rt((t,e)=>gn(t,"name",{value:e,configurable:!0}),"i");st(t=>t instanceof Error&&t.type==="VisulimaError","isVisulimaError");let le=class extends Error{static{O(this,"p")}static{ot(this,"E")}static{rt(this,"m")}static{st(this,"VisulimaError")}loc;title;hint;type="VisulimaError";constructor({cause:e,hint:n,location:i,message:r,name:a,stack:c,title:s}){super(r,{cause:e}),this.title=s,this.name=a,this.stack=c??this.stack,this.loc=i,this.hint=n}setLocation(e){this.loc=e}setName(e){this.name=e}setMessage(e){this.message=e}setHint(e){this.hint=e}};var vn=Object.defineProperty,lt=O((t,e)=>vn(t,"name",{value:e,configurable:!0}),"o$b"),wn=Object.defineProperty,ct=lt((t,e)=>wn(t,"name",{value:e,configurable:!0}),"o"),yn=Object.defineProperty,bn=ct((t,e)=>yn(t,"name",{value:e,configurable:!0}),"i");let $n=class ut extends le{static{O(this,"a")}static{lt(this,"a")}static{ct(this,"t")}static{bn(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,ut.prototype)}};var On=Object.defineProperty,pt=O((t,e)=>On(t,"name",{value:e,configurable:!0}),"t$7"),En=Object.defineProperty,ft=pt((t,e)=>En(t,"name",{value:e,configurable:!0}),"e"),Pn=Object.defineProperty,An=ft((t,e)=>Pn(t,"name",{value:e,configurable:!0}),"e");let Ue=class dt extends le{static{O(this,"n")}static{pt(this,"n")}static{ft(this,"o")}static{An(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,dt.prototype)}};var Cn=Object.defineProperty,ht=O((t,e)=>Cn(t,"name",{value:e,configurable:!0}),"a$a"),Nn=Object.defineProperty,mt=ht((t,e)=>Nn(t,"name",{value:e,configurable:!0}),"a"),xn=Object.defineProperty,kn=mt((t,e)=>xn(t,"name",{value:e,configurable:!0}),"o");let _n=class gt extends le{static{O(this,"n")}static{ht(this,"o")}static{mt(this,"e")}static{kn(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,gt.prototype)}};var jn=Object.defineProperty,vt=O((t,e)=>jn(t,"name",{value:e,configurable:!0}),"i$8"),Ln=Object.defineProperty,wt=vt((t,e)=>Ln(t,"name",{value:e,configurable:!0}),"i"),In=Object.defineProperty,Sn=wt((t,e)=>In(t,"name",{value:e,configurable:!0}),"i");let j=class yt extends le{static{O(this,"a")}static{vt(this,"o")}static{wt(this,"e")}static{Sn(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,yt.prototype)}};var Un=Object.defineProperty,Mn=O((t,e)=>Un(t,"name",{value:e,configurable:!0}),"z$1"),Tn=Object.defineProperty,K=Mn((t,e)=>Tn(t,"name",{value:e,configurable:!0}),"S"),Vn=Object.defineProperty,ce=K((t,e)=>Vn(t,"name",{value:e,configurable:!0}),"o");const Me=ce(t=>t===Boolean||typeof t=="function"&&t.name.startsWith("Boolean"),"isBooleanType"),Te=ce(t=>t===Number||typeof t=="function"&&t.name==="Number","isNumberType"),Ve=ce(t=>t===String||typeof t=="function"&&t.name==="String","isStringType"),Dn=ce((t,e)=>Array.isArray(t)?Me(e)?t.map(Boolean):Te(e)?t.map(Number):Ve(e)?t.map(String):t.map(n=>e(String(n))):t===null?null:Me(e)?!!t:Te(e)?Number(t):Ve(e)?typeof t=="string"?t:String(t):e(typeof t=="string"?t:String(t)),"convertValue");var Rn=Object.defineProperty,Bn=K((t,e)=>Rn(t,"name",{value:e,configurable:!0}),"e");const _=Bn((t,e,n,...i)=>{t&&console.debug(`[command-line-args:${n}] ${e}`,...i)},"debug");var zn=Object.defineProperty,D=K((t,e)=>zn(t,"name",{value:e,configurable:!0}),"h$1");const Wn=/-([a-z])/g,Fn=/^\d+$/,ve=D(t=>t===Boolean||typeof t=="function"&&t.name.startsWith("Boolean"),"isBooleanType"),qn=D(t=>t.codePointAt(0)===95,"isSpecialKey"),De=D((t,e)=>Array.isArray(t)?[...t,...e]:[t,...e],"appendToArrayMultiple"),Re=D(t=>t==="__proto__"||t==="constructor"||t==="prototype","isUnsafeKey"),Be=D((t,e,n,i=!1)=>{t[e]===void 0?t[e]=i?[n]:n:i&&Array.isArray(t[e])?t[e].push(n):t[e]=[t[e],n]},"createOrAppendArray"),Gn=D((t,e,n,i,r)=>{let a=e.get(t)??n.get(t);if(!a&&i){const c=t.toLowerCase();a=i.get(c)??r?.get(c)}return a},"getDefinition"),Hn=D((t,e,n,i)=>{const r=n.debug??!1;_(r,"resolveArgs called with options:","resolver",{partial:n.partial,stopAtFirstUnknown:n.stopAtFirstUnknown}),_(r,"Starting argument resolution","resolver"),_(r,"Tokens:","resolver",t),_(r,"Definitions:","resolver",e),_(r,"Processing tokens...","resolver");const a=new Map,c=new Map,s=n.caseInsensitive?new Map:void 0,m=n.caseInsensitive?new Map:void 0,o=n.camelCase?new Map:void 0,u=n.camelCase?new Map:void 0;for(const f of e)if(a.set(f.name,f),f.alias&&c.set(f.alias,f),n.caseInsensitive&&s&&(s.set(f.name.toLowerCase(),f),f.alias&&m&&m.set(f.alias.toLowerCase(),f)),n.camelCase&&o&&u){const h=f.name.replaceAll(Wn,(v,w)=>w.toUpperCase());o.set(f.name,h),u.set(h,f.name)}const d={},l={},g=[],p=new Set;let b=!1;const $=e.find(f=>f.defaultOption),y=e.some(f=>f.group),P=e.some(f=>f.type===Number);for(let f=0;f<t.length;f++){const h=t[f];if(h.kind==="option-terminator"){d._unknown=i.slice(h.index),b=!0;break}if(h.kind==="option"&&h.name){let v=Gn(h.name,a,c,s,m);if(!v&&h.value===void 0&&P&&Fn.test(h.name)){const A=e.find(S=>S.type===Number);A&&(v=A,h.value=h.name,h.name=A.name)}const w=v?v.name:h.name,E=v?.multiple,k=v?.lazyMultiple;if(l[w]!==void 0&&!E&&!k&&!n.partial)throw new $n(w);if(!v&&n.partial){const A=h.rawName??`--${h.name}${h.value!==void 0&&h.inlineValue?`=${h.value}`:""}`;g.push({index:h.index,value:A});continue}if(!v&&n.stopAtFirstUnknown){d._unknown=i.slice(h.index);break}if(!v&&!n.partial)throw new Ue(h.name);if(h.value===void 0){const A=t[f+1],S=A?.kind==="option"&&!("name"in A)&&A.value!==void 0,I=A&&v&&!(v.type&&ve(v.type))&&(A.kind==="positional"||S),Mt=v&&v.defaultOption&&!v.multiple&&!v.lazyMultiple;if(I&&(!v?.defaultOption||Mt))if(E){let U=f+1;const ge=[];for(;U<t.length&&(t[U].kind==="positional"||t[U].kind==="option"&&!("name"in t[U])&&t[U].value!==void 0);)ge.push(t[U].value),p.add(t[U].index),U++;l[w]=l[w]===void 0?ge:De(l[w],ge),f=U-1}else k?(Be(l,w,A.value,!0),p.add(A.index),f++):(l[w]=A.value,p.add(A.index),f++);else v?.type&&ve(v.type)?Be(l,w,!0,E):l[w]=E?[]:null}else{let{value:A}=h;if(v?.type&&ve(v.type))switch(A){case"":{if(n.partial)l._unknown??=[],l._unknown.push(`${h.rawName??`--${h.name}`}${h.value?`=${h.value}`:""}`),A=!0;else throw new Ue(h.name);break}case"false":{A=!1;break}case"true":{A=!0;break}default:A=!0}const S=[A];if(E){let I=f+1;for(;I<t.length&&t[I].kind==="positional";)S.push(t[I].value),p.add(t[I].index),I++;f=I-1}l[w]===void 0?l[w]=E||k?S:A:E||k?l[w]=De(l[w],S):l[w]=A}}else if(h.kind==="positional"&&n.stopAtFirstUnknown&&!p.has(h.index)&&!$){_(r,`Found unconsumed positional token at index ${String(h.index)}, stopping processing`,"resolver"),d._unknown=i.slice(h.index);break}}for(const[f,h]of Object.entries(l)){const v=a.get(f);v&&(v.multiple||v.lazyMultiple)&&!Array.isArray(h)&&(l[f]=[h])}let N=Number.POSITIVE_INFINITY;if(n.stopAtFirstUnknown&&!b){for(const f of t)if(f.kind==="option"&&!a.has(f.name??"")&&!c.has(f.name??"")&&(!n.caseInsensitive||!s?.has(f.name?.toLowerCase()??"")&&!m?.has(f.name?.toLowerCase()??""))){N=f.index;break}}if($){const f=[],h=[];for(const v of t)v.kind==="positional"&&!p.has(v.index)&&v.index<N&&(f.push(v.value),h.push(v));if(f.length>0){const v=l[$.name],w=$.multiple??$.lazyMultiple;v===void 0?w?(h.forEach(E=>p.add(E.index)),l[$.name]=f):(p.add(h[0].index),l[$.name]=f[0]):w&&(h.forEach(E=>p.add(E.index)),l[$.name]=Array.isArray(v)?[...f,...v]:[...f,v])}}if(!n.partial){for(const f of t)if(f.kind==="positional"&&!p.has(f.index))throw new _n(i[f.index])}if(n.partial&&!n.stopAtFirstUnknown){const f=[...g];if(l._unknown){const h=new Map;for(const[v,w]of i.entries())h.set(w,v);for(const v of l._unknown){const w=h.get(v);w!==void 0&&f.push({index:w,value:v})}}for(const h of t)h.kind==="positional"&&!p.has(h.index)&&f.push({index:h.index,value:i[h.index]});f.length>0&&(f.sort((h,v)=>h.index-v.index),d._unknown=f.map(h=>h.value))}if(n.stopAtFirstUnknown&&!b){const f=t.findIndex(w=>w.kind==="option"&&!a.has(w.name??"")&&!c.has(w.name??"")&&(!n.caseInsensitive||!s?.has(w.name?.toLowerCase()??"")&&!m?.has(w.name?.toLowerCase()??""))),h=t.findIndex(w=>w.kind==="positional"&&!p.has(w.index));let v=-1;if(f!==-1&&h!==-1?v=Math.min(f,h):f!==-1?v=f:h!==-1&&(v=h),v>=0){const w=t[v].index;d._unknown=i.slice(w)}}else g.length>0&&!n.partial&&(d._unknown=g.map(f=>f.value));for(const[f,h]of Object.entries(l)){const v=n.camelCase?o?.get(f)??f:f,w=a.get(f);d[v]=w?.type?Dn(h,w.type):h===void 0?null:h}for(const f of e){const h=n.camelCase?o?.get(f.name)??f.name:f.name;!(h in d)&&f.defaultValue!==void 0&&(f.multiple??f.lazyMultiple?d[h]=Array.isArray(f.defaultValue)?[...f.defaultValue]:[f.defaultValue]:d[h]=f.defaultValue)}if(y){const f={},h={},v={};for(const E of e)if(E.group){const k=Array.isArray(E.group)?E.group:[E.group];for(const A of k)Re(A)||(f[A]??={})}for(const E of Object.keys(d))if(!qn(E)){h[E]=d[E];let k=E;n.camelCase&&(k=u?.get(E)??E);const A=a.get(k);if(A?.group){const S=Array.isArray(A.group)?A.group:[A.group];for(const I of S)Re(I)||f[I]&&(f[I][E]=d[E])}else v[E]=d[E]}const w={_all:h};for(const[E,k]of Object.entries(f))w[E]=k;Object.keys(v).length>0&&(w._none=v),d._unknown&&(w._unknown=d._unknown),Object.keys(d).forEach(E=>delete d[E]),Object.assign(d,w)}return _(r,"Final parsed result:","resolver",d),d},"resolveArgs");var Kn=Object.defineProperty,R=K((t,e)=>Kn(t,"name",{value:e,configurable:!0}),"l");const V="-".codePointAt(0),T="=",Yn=T.codePointAt(0),Jn="--",Qn="-",Zn="--",bt=R(t=>t.length>2&&t.startsWith(Zn),"hasLongOptionPrefix"),Xn=R(t=>bt(t)&&!t.includes(T,3),"isLongOption"),ea=R(t=>bt(t)&&t.includes(T,3),"isLongOptionAndValue"),ta=R(t=>t!==void 0&&t.length>0&&t.codePointAt(0)!==V,"hasOptionValue"),na=R(t=>{if(t.length!==2||t.codePointAt(0)!==V||t.codePointAt(1)===V)return!1;const e=t.codePointAt(1);return e!==void 0&&(e<48||e>57)},"isShortOption"),aa=R(t=>!(t.length<=2||t.codePointAt(0)!==V||t.codePointAt(1)===V),"isShortOptionGroup"),ia=R(t=>{const e=[],n=[...t];let i=-1,r=0;for(;n.length>0;){const a=n.shift();if(a===void 0)break;const c=n[0];if(r>0?r--:i++,a===Jn){e.push({index:i,kind:"option-terminator"});const s=n.map((m,o)=>({index:i+o+1,kind:"positional",value:m}));e.push(...s),i+=n.length;break}if(na(a)){const s=a.charAt(1);let m;r?(e.push({index:i,kind:"option",name:s,rawName:a,value:m}),r===1&&ta(c)&&(m=n.shift(),e.push({index:i,kind:"option",value:m}))):e.push({index:i,kind:"option",name:s,rawName:a,value:m}),m!==void 0&&++i;continue}if(aa(a)&&!a.includes(T)){const s=[];let m="",o=!1;for(let u=1;u<a.length;u++){const d=a.charAt(u);o?m+=d:d.codePointAt(0)===Yn?o=!0:s.push(`${Qn}${d}`)}if(o)if(s.length>0){const u=s.pop();s.push(`${u}=${m}`)}else s.push(m);n.unshift(...s),r=s.length;continue}if(Xn(a)){const s=a.slice(2);e.push({index:i,kind:"option",name:s,rawName:a});continue}if(ea(a)){const s=a.indexOf(T),m=a.slice(2,s),o=a.slice(s+1);e.push({index:i,inlineValue:!0,kind:"option",name:m,rawName:a,value:o});continue}if(a.length>2&&a.codePointAt(0)===V&&a.codePointAt(1)!==V&&a.includes(T)){const s=a.indexOf(T),m=a.charAt(1),o=a.slice(s+1);e.push({index:i,inlineValue:!0,kind:"option",name:m,rawName:a,value:o});continue}e.push({index:i,kind:"positional",value:a})}return e},"parseArgsTokens");var oa=Object.defineProperty,xe=K((t,e)=>oa(t,"name",{value:e,configurable:!0}),"d");const ra=/\d/,sa=xe(t=>t!=null&&(t===Boolean||typeof t=="function"&&t.name.startsWith("Boolean")),"isBooleanType"),la=xe(t=>typeof t=="function","isValidCustomTypeFunction"),ca=xe((t,e,n)=>{const i=n?.debug??!1;_(i,"Validating definitions:","validation",t,"caseInsensitive:",e);const r=new Set,a=new Set,c=new Set,s=new Set;let m=0;for(const o of t){if(_(i,"Checking definition:","validation",o),!o.name)throw _(i,"Validation failed: name is required","validation"),new j("Invalid option definition: name is required");if(typeof o.name!="string")throw new j("Invalid option definition: name must be a string");if(o.name.trim()==="")throw new j("Invalid option definition: name cannot be empty");const u=e?o.name.toLowerCase():"";if(r.has(o.name)||e&&c.has(u))throw new j(`Invalid option definition: duplicate name '${o.name}'`);if(a.has(o.name)||e&&s.has(u))throw new j(`Invalid option definition: name '${o.name}' conflicts with an existing alias`);if(r.add(o.name),e&&c.add(u),o.alias!==void 0){if(typeof o.alias!="string")throw new j("Invalid option definition: alias must be a string");if(o.alias.length!==1)throw new j("Invalid option definition: alias must be a single character");if(ra.test(o.alias))throw new j("Invalid option definition: alias cannot be numeric");if(o.alias==="-")throw new j('Invalid option definition: alias cannot be "-"');const d=e?o.alias.toLowerCase():"";if(a.has(o.alias)||e&&s.has(d))throw new j(`Invalid option definition: duplicate alias '${o.alias}'`);if(r.has(o.alias)||e&&c.has(d))throw new j(`Invalid option definition: alias '${o.alias}' conflicts with an existing option name`);a.add(o.alias),e&&s.add(d)}if(o.defaultOption&&(m++,o.type!==void 0&&sa(o.type)))throw new j("Invalid option definition: defaultOption cannot be Boolean type");if(o.type!==void 0&&!(o.type===Boolean||o.type===Number||o.type===String||typeof o.type=="function"&&la(o.type)))throw new j("Invalid option definition: invalid type")}if(m>1)throw _(i,"Validation failed: multiple defaultOptions not allowed","validation"),new j("Invalid option definition: multiple defaultOptions not allowed");_(i,"Validation completed successfully","validation")},"validateDefinitions");var ua=Object.defineProperty,pa=K((t,e)=>ua(t,"name",{value:e,configurable:!0}),"O");const fa=pa((t,e={})=>{const n=e.debug??!1;_(n,"Starting command-line-args parsing","index"),_(n,"Options:","index",e);const i={...e};i.stopAtFirstUnknown&&(i.partial=!0);const r=Array.isArray(t)?t:[t];_(n,"Normalized definitions:","index",r),ca(r,i.caseInsensitive,n?i:void 0);let{argv:a}=i;if(!a&&(a=process.argv.slice(2),process.execArgv.length>0)){const o=new Set(process.execArgv);a=a.filter(u=>!o.has(u))}_(n,"Using argv:","index",a);let c=a;i.caseInsensitive&&(c=a.map(o=>{if(o.startsWith("--")){const u=o.indexOf("="),d=(u===-1?o.slice(2):o.slice(2,u)).toLowerCase();return u===-1?`--${d}`:`--${d}${o.slice(u)}`}if(o.startsWith("-")&&!o.startsWith("--")&&o.length>1){const u=o.slice(1).split("=",2),d=u[0],l=u[1];if(!d)return o;const g=d.toLowerCase();return l===void 0?`-${g}`:`-${g}=${l}`}return o}));const s=ia(c.map(String));_(n,"Tokenized arguments:","index",s);const m=Hn(s,r,i,a);return _(n,"Command-line-args parsing completed","index"),m},"commandLineArgs");var da=Object.defineProperty,ha=O((t,e)=>da(t,"name",{value:e,configurable:!0}),"n$8");let ma=class{static{O(this,"a")}static{ha(this,"EmptyToolbox")}result;argv;options;argument;command;commandName;env;logger;runtime;rawUnknown;constructor(e,n){this.commandName=e,this.command=n}};var ga=Object.defineProperty,va=O((t,e)=>ga(t,"name",{value:e,configurable:!0}),"n$7");let we=class extends C{static{O(this,"i")}static{va(this,"CommandLoaderError")}commandName;constructor(e,n,i){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.",i!==void 0&&(this.cause=i)}};var wa=Object.defineProperty,ya=O((t,e)=>wa(t,"name",{value:e,configurable:!0}),"f$5");const ba=/^-{1,2}(\w+)(=(.+))?$/,$t=ya((t,e,n,i)=>{const r=ba.exec(t);if(r===null)return{};const a=r[1];if(!a)return{};const c=n&&i?n.get(a)??i.get(a):e.find(s=>s.name===a||s.alias===a);return c!==void 0?{argName:c.name,argValue:r[3],option:c}:{}},"getParameterOption");var $a=Object.defineProperty,Ne=O((t,e)=>$a(t,"name",{value:e,configurable:!0}),"e$3");const ze=Ne((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"),Oa=new Set(["0","1","false","true"]),Ea=Ne((t,e,n,i)=>{if(e.length===0||t.length===0)return{};const r=Ne((a,c)=>{const{argName:s,argValue:m,option:o}=$t(c,e,n,i),{lastOption:u}=a;return o&&ee(o)&&m&&s?a.partial[s]=ze(m,o):a.lastName&&u&&ee(u)&&Oa.has(c)&&(a.partial[a.lastName]=ze(c,u)),{lastName:s,lastOption:o,partial:a.partial}},"getBooleanValue");return t.reduce(r,{partial:{}}).partial},"getBooleanValues");var Pa=Object.defineProperty,We=O((t,e)=>Pa(t,"name",{value:e,configurable:!0}),"s$8");const Aa=new Set(["0","1","false","true"]),Ca=We((t,e,n,i)=>{if(e.length===0||t.length===0)return t;const r=We((a,c)=>{const{argValue:s,option:m}=$t(c,e,n,i),{lastOption:o}=a;if(o&&ee(o)&&Aa.has(c)){const{args:u}=a;return{args:u.slice(0,-1)}}return m&&ee(m)&&s?{args:a.args}:{args:[...a.args,c],lastOption:m}},"removeBooleanArguments");return t.reduce(r,{args:[]}).args},"removeBooleanValues");var Na=Object.defineProperty,xa=O((t,e)=>Na(t,"name",{value:e,configurable:!0}),"o$8");const Fe=xa(t=>{const e=new Map;for(const n of t){const i=e.get(n.name);i?e.set(n.name,{...i,...n}):e.set(n.name,n)}return[...e.values()]},"mergeArguments");var ka=Object.defineProperty,ue=O((t,e)=>ka(t,"name",{value:e,configurable:!0}),"o$7");const _a=ue(t=>{if(t===void 0)return;const e=t.toLowerCase().trim();return e==="true"||e==="1"||e==="yes"||e==="on"},"transformBooleanEnv"),ja=ue((t,e)=>{if(!t.type)return e;if(e!==void 0){if(t.type===Boolean||typeof t.type=="function"&&t.type.name==="Boolean")return _a(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"),La=/_./g,Ia=/^[A-Z]/,Sa=ue(t=>t.toLowerCase().replaceAll(La,e=>e[1]?.toUpperCase()??e).replace(Ia,e=>e.toLowerCase()),"toCamelCase"),Ua=ue(t=>{if(!t||t.length===0)return{};const e={},n=G();for(const i of t){const r=n[i.name],a=ja(i,r),c=a===void 0?i.defaultValue:a,s=Sa(i.name);e[s]=c}return e},"processEnvVariables");var Ma=Object.defineProperty,te=O((t,e)=>Ma(t,"name",{value:e,configurable:!0}),"a$5");const Ta=te(t=>{const e=new Map,n=new Map;for(const i of t)if(e.set(i.name,i),i.alias){const r=Array.isArray(i.alias)?i.alias:[i.alias];for(const a of r)n.set(a,i)}return{optionMapByAlias:n,optionMapByName:e}},"buildOptionMaps"),Va=te(async t=>{if(typeof t.__resolvedExecute__=="function")return t.__resolvedExecute__;if(typeof t.loader!="function")throw new we(t.name,"no execute or loader defined");let e;try{e=await t.loader()}catch(i){throw new we(t.name,i instanceof Error?i.message:String(i),i)}const n=e.default;if(typeof n!="function")throw new we(t.name,"loader did not return a module with a default-exported handler function");return t.__resolvedExecute__=n,n},"loadLazyHandler"),Da=te((t,e,n,i)=>{const r=new ma(t.name,t),{_all:a,_unknown:c,positionals:s}=e,m=Object.keys(n).length>0?{...a,...n}:a;ie in m&&delete m[ie],r.argument=s?.[ie]??[],r.rawUnknown=[...c??[]];const o=Object.keys(i).length>0;return r.options=o?{...m,...i}:m,r.env=Ua(t.env),r},"prepareToolbox"),Ra=te((t,e,n)=>{const i=t.options??[],r=i.length>0;let a=Fe(r?[...i,...n]:n);if(a.length>0){for(const o of a)if(o.multiple&&o.lazyMultiple)throw new Error(`Argument "${o.name}" cannot have both multiple and lazyMultiple options, please choose one.`)}t.argument&&(a=[{defaultOption:!0,description:t.argument.description,group:"positionals",multiple:!0,name:ie,type:t.argument.type,typeLabel:t.argument.typeLabel},...a]);let c,s;if(r){const{optionMapByAlias:o,optionMapByName:u}=Ta(i);c=Ca(e,i,u,o),s=Ea(e,i,u,o)}else c=e,s={};const m=fa(a,{argv:c,camelCase:!0,partial:!0,stopAtFirstUnknown:!0});return{arguments_:a,booleanValues:s,parsedArgs:m}},"processCommandArgs"),z=te(async(t,e,n)=>typeof t.execute=="function"?t.execute(e):(await Va(t))(e),"executeCommand");var Ba=Object.defineProperty,za=O((t,e)=>Ba(t,"name",{value:e,configurable:!0}),"n$6");let Wa=class extends C{static{O(this,"s")}static{za(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 Fa=Object.defineProperty,qa=O((t,e)=>Fa(t,"name",{value:e,configurable:!0}),"t$5");const qe=qa((t,e,n=!1)=>{const i=[];for(const r of t)if(!(!n&&!r.required)&&e[r.name]===void 0){if(r.type?.name==="Boolean"){e[r.name]=!1;continue}i.push(r)}return i},"listMissingArguments");var Ga=Object.defineProperty,Ot=O((t,e)=>Ga(t,"name",{value:e,configurable:!0}),"n$5");const Ha=Ot((t,e)=>e.includes(t)?!0:Math.abs(t.length-e.length)>t.length/2?!1:Gt(t,e)<=t.length/3,"isSimilar"),q=Ot((t,e)=>{const n=t.toLowerCase();return e.filter(i=>Ha(i.toLowerCase(),n))},"findAlternatives");var Ka=Object.defineProperty,pe=O((t,e)=>Ka(t,"name",{value:e,configurable:!0}),"a$4");const Ya=pe((t,e)=>{const n=[];if(t._unknown&&t._unknown.forEach(i=>{const r=i.startsWith("--");let a=`Found unknown ${r?"option":"argument"} "${i}"`;if(r){const c=q(i.replace("--",""),(e.options??[]).map(s=>s.name));if(c.length>0){const[s,...m]=c.map(o=>`--${o}`);a+=m.length>0?`, did you mean ${s??""} or ${m.join(", ")}?`:`, did you mean ${s??""}?`}}n.push(a)}),n.length>0)throw new Error(n.join(`
2
- `))},"validateUnknownOptions"),Ja=pe((t,e,n)=>{const i=n.__requiredOptions__,r=i?qe(i,e,!0):qe(t,e,!1);if(r.length>0)throw new Wa(n.name,r.map(a=>a.name));e._unknown&&e._unknown.length>0&&!n.argument&&Ya(e,n)},"validateRequiredOptions"),Qa=pe((t,e,n)=>{const i=n.__conflictingOptions__??t.filter(r=>r.conflicts!==void 0);if(i.length>0){const r=i.find(a=>Array.isArray(a.conflicts)?a.conflicts.some(c=>e[c]!==void 0)&&e[a.name]!==void 0:e[a.conflicts]!==void 0&&e[a.name]!==void 0);if(r)throw new nt(r.name,typeof r.conflicts=="string"?r.conflicts:r.conflicts?.[0]??"unknown")}},"validateConflictingOptions"),Za=pe(t=>{if(!Array.isArray(t.options))return;const e=new Map,n=new Map;for(const r of t.options){if(r.name){const a=e.get(r.name)??[];a.push(r),e.set(r.name,a)}if(typeof r.alias=="string"&&r.alias.length>0){const a=n.get(r.alias)??[];a.push(r),n.set(r.alias,a)}else if(Array.isArray(r.alias)){for(const a of r.alias)if(a.length>0){const c=n.get(a)??[];c.push(r),n.set(a,c)}}}const i=[];for(const[r,a]of e)a.length>1&&i.push(`Duplicate option name "${r}" in command "${t.name}": ${JSON.stringify(a)}`);for(const[r,a]of n)a.length>1&&i.push(`Duplicate option alias "-${r}" used by options ${a.map(c=>`"${c.name}"`).join(", ")} in command "${t.name}"`);if(i.length>0)throw new Error(i.join(`
3
- `))},"validateDuplicateOptions");var Xa=Object.defineProperty,ke=O((t,e)=>Xa(t,"name",{value:e,configurable:!0}),"s$4");const ei=ke((t,e)=>{if(e.length===0)return{argv:[],commandPath:void 0};const n=[];let i;for(let r=1;r<=e.length;r+=1){const a=e[r-1];if(a===void 0||a.startsWith("-"))break;n.push(a);const c=n.join(" ");t.has(c)&&(i={commandPath:[...n],depth:r})}return i?{argv:e.slice(i.depth),commandPath:i.commandPath}:{argv:e,commandPath:void 0}},"parseNestedCommand"),Q=ke(t=>t.join(" "),"getCommandPathKey"),ti=ke((t,e)=>e&&e.length>0?[...e,t]:[t],"getFullCommandPath");var ni=Object.defineProperty,ai=O((t,e)=>ni(t,"name",{value:e,configurable:!0}),"p$4"),ii=Object.defineProperty,Et=ai((t,e)=>ii(t,"name",{value:e,configurable:!0}),"e"),oi=Object.defineProperty,ri=Et((t,e)=>oi(t,"name",{value:e,configurable:!0}),"E");const Pt=String.raw,Ge=Pt`\p{Emoji}(?:\p{EMod}|[\u{E0020}-\u{E007E}]+\u{E007F}|\uFE0F?\u20E3?)`,si=ri(()=>new RegExp(Pt`\p{RI}{2}|(?![#*\d](?!\uFE0F?\u20E3))${Ge}(?:\u200D${Ge})*`,"gu"),"default");var li=Object.defineProperty,ci=Et((t,e)=>li(t,"name",{value:e,configurable:!0}),"p");Object.freeze(new Map([[0,0],[1,22],[2,22],[3,23],[4,24],[7,27],[8,28],[9,29],[30,39],[31,39],[32,39],[33,39],[34,39],[35,39],[36,39],[37,39],[40,49],[41,49],[42,49],[43,49],[44,49],[45,49],[46,49],[47,49],[90,39]]));const H=si(),ui=/[-_./\s]+/g,X=/(\u001B\[[0-9;]*[a-z])/i,He=new RegExp("\\p{Script=Arabic}","u"),pi=new RegExp("\\p{Script=Bengali}","u"),W=new RegExp("\\p{Script=Cyrillic}","u"),fi=new RegExp("\\p{Script=Devanagari}","u"),di=new RegExp("\\p{Script=Ethiopic}","u"),ye=new RegExp("\\p{Script=Greek}","u"),Ke=new RegExp("\\p{Script=Greek}+|\\p{Script=Latin}+|[^\\p{Script=Greek}\\p{Script=Latin}]+","gu"),hi=new RegExp("\\p{Script=Gujarati}","u"),mi=new RegExp("\\p{Script=Gurmukhi}","u"),Ye=new RegExp("\\p{Script=Hangul}","u"),Je=new RegExp("\\p{Script=Hebrew}","u"),gi=new RegExp("\\p{Script=Hiragana}","u"),Qe=new RegExp("\\p{Script=Han}","u"),vi=new RegExp("\\p{Script=Kannada}","u"),wi=new RegExp("\\p{Script=Katakana}","u"),yi=new RegExp("\\p{Script=Khmer}","u"),bi=new RegExp("\\p{Script=Lao}","u"),L=new RegExp("\\p{Script=Latin}","u"),$i=new RegExp("\\p{Script=Malayalam}","u"),Oi=new RegExp("\\p{Script=Myanmar}","u"),Ei=new RegExp("\\p{Script=Oriya}","u"),Pi=new RegExp("\\p{Script=Sinhala}","u"),Ai=new RegExp("\\p{Script=Tamil}","u"),Ci=new RegExp("\\p{Script=Telugu}","u"),Ni=new RegExp("\\p{Script=Thai}","u"),xi=new RegExp("\\p{Script=Tibetan}","u"),Ze=/[\u02BB\u02BC\u0027]/u,ki=ci(t=>t.replace(H,""),"stripEmoji");var _i=Object.defineProperty,At=O((t,e)=>_i(t,"name",{value:e,configurable:!0}),"i$5"),ji=Object.defineProperty,Ct=At((t,e)=>ji(t,"name",{value:e,configurable:!0}),"r"),Li=Object.defineProperty,Ii=Ct((t,e)=>Li(t,"name",{value:e,configurable:!0}),"c");let Nt=class{static{O(this,"l")}static{At(this,"y")}static{Ct(this,"s")}static{Ii(this,"LRUCache")}capacity;cache;keyOrder;constructor(e){this.capacity=e,this.cache=new Map,this.keyOrder=[]}get(e){if(this.cache.has(e))return this.keyOrder=this.keyOrder.filter(n=>n!==e),this.keyOrder.push(e),this.cache.get(e)}has(e){return this.cache.has(e)}set(e,n){if(this.cache.has(e))this.keyOrder=this.keyOrder.filter(i=>i!==e);else if(this.cache.size>=this.capacity){const i=this.keyOrder.shift();i!==void 0&&this.cache.delete(i)}this.cache.set(e,n),this.keyOrder.push(e)}delete(e){this.cache.delete(e),this.keyOrder=this.keyOrder.filter(n=>n!==e)}clear(){this.cache.clear(),this.keyOrder=[]}size(){return this.cache.size}};var Si=Object.defineProperty,Ui=O((t,e)=>Si(t,"name",{value:e,configurable:!0}),"r$5"),Mi=Object.defineProperty,Ti=Ui((t,e)=>Mi(t,"name",{value:e,configurable:!0}),"a"),Vi=Object.defineProperty,Di=Ti((t,e)=>Vi(t,"name",{value:e,configurable:!0}),"s");const Ri=Di((t,e)=>typeof t!="string"||t===""?"":(e?.locale?t[0].toLocaleLowerCase(e.locale):t[0].toLowerCase())+t.slice(1),"lowerFirst");var Bi=Object.defineProperty,zi=O((t,e)=>Bi(t,"name",{value:e,configurable:!0}),"I"),Wi=Object.defineProperty,fe=zi((t,e)=>Wi(t,"name",{value:e,configurable:!0}),"W");const Fi=Ht(import.meta.url),Z=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,qi=fe(t=>{if(typeof Z<"u"&&Z.versions&&Z.versions.node){const[e,n]=Z.versions.node.split(".").map(Number);if(e>22||e===22&&n>=3||e===20&&n>=16)return Z.getBuiltinModule(t)}return Fi(t)},"__cjs_getBuiltinModule"),{stripVTControlCharacters:Gi}=qi("node:util");var Hi=Object.defineProperty,Ki=fe((t,e)=>Hi(t,"name",{value:e,configurable:!0}),"g");const be=new Nt(1e3),Yi=/[.*+?^${}()|[\]\\]/g,Ji=Ki(t=>{const e=t.join("");if(be.has(e))return be.get(e);const n=t.map(r=>r.replaceAll(Yi,String.raw`\$&`)).join("|"),i=new RegExp(n,"g");return be.set(e,i),i},"getSeparatorsRegex");var Qi=Object.defineProperty,Zi=fe((t,e)=>Qi(t,"name",{value:e,configurable:!0}),"t");const Xi=Zi(t=>{const e=[];let n=0,i;for(H.lastIndex=0;(i=H.exec(t))!==null;)i.index>n&&e.push(t.slice(n,i.index)),e.push(i[0]),n=H.lastIndex;return n<t.length&&e.push(t.slice(n)),e.filter(Boolean)},"splitByEmoji");var eo=Object.defineProperty,x=fe((t,e)=>eo(t,"name",{value:e,configurable:!0}),"u");const to=/[ČŠŽĐ]/i,xt=new Uint8Array(128),kt=new Uint8Array(128),_t=new Uint8Array(128);for(let t=0;t<128;t++)xt[t]=t>=65&&t<=90?1:0,kt[t]=t>=97&&t<=122?1:0,_t[t]=t>=48&&t<=57?1:0;const $e=x(t=>xt[t],"isUpper"),Xe=x(t=>kt[t],"isLower"),Oe=x(t=>_t[t],"isDigit"),M=x((t,e,n,i,r)=>{if(t.length===0)return[];let a=!1;const c=Object.values(e);for(const g of c)if(g(t[0])){a=!0;break}if(!a&&!n)return[t];const s=[...t],m=[];let o=s[0],u="other";const d=Object.entries(e);for(const g of d){const[p,b]=g;if(b(s[0])){u=p;break}}let l=n&&i?s[0]===s[0].toLocaleUpperCase(i):!1;for(let g=1;g<s.length;g++){const p=s[g];let b="other";for(const P of d){const[N,f]=P;if(f(p)){b=N;break}}const $=n&&i?p===p.toLocaleUpperCase(i):!1;let y=!1;r?y=r(u,b,l,$,p,g,s):(u!==b&&u!=="other"&&b!=="other"&&(y=!0),n&&b!=="other"&&!l&&$&&(y=!0)),y?(m.push(o),o=p):o+=p,u=b,n&&(l=$)}return o&&o.length>0&&m.push(o),m.length>0?m:[t]},"handleScriptTransitions"),no=x((t,e,n,i)=>{if(n.size===0)return e;for(const r of n)if(t.startsWith(r,e))return i.push(r),e+r.length;return e},"detectAndProcessAcronym"),jt=x((t,e=new Set)=>{if(t.length===0)return[];if(t.toUpperCase()===t)return[t];let n=0;const i=[],r=t.length;for(let a=1;a<r;a++){const c=no(t,n,e,i);if(c!==n){n=c,a=n-1;continue}const s=t.codePointAt(a-1),m=t.codePointAt(a),o=s&&s<128&&$e(s),u=m&&m<128&&$e(m),d=s&&s<128&&Xe(s),l=s&&s<128&&Oe(s),g=m&&m<128&&Oe(m);if(d&&u){i.push(t.slice(n,a)),n=a;continue}if(l&&!g||!l&&g){i.push(t.slice(n,a)),n=a;continue}if(g&&!l){let p=!1,b=!1;if(a+1<r){const $=t.codePointAt(a+1);p=$&&$<128&&$e($),b=$&&$<128&&Oe($)}if(!b&&p){i.push(t.slice(n,a),t.slice(a,a+1)),n=a+1;continue}}if(a+1<r){const p=t.codePointAt(a+1),b=p&&p<128&&Xe(p);if(o&&u&&b){const $=t.slice(n,a+1);e.has($)||(i.push(t.slice(n,a)),n=a)}}}return n<r&&i.push(t.slice(n)),i.filter(a=>a!=="")},"splitCamelCaseFast"),Lt=x((t,e,n)=>{if(t.length===0)return[];const i=t===t.toLocaleUpperCase(e);if(e.startsWith("de")){if(!i&&t.replaceAll("ß","SS")===t.toLocaleUpperCase(e))return[t];const o=[...t],u=o.length,d=[];let l=o[0],g=o[0]===o[0].toLocaleUpperCase(e),p=g,b=g?0:-1;for(let $=1;$<u;$++){const y=o[$],P=y===y.toLocaleUpperCase(e);if(P===g)l+=y;else if(P)l&&l.length>0&&(d.push(l),l=y),p=!0,b=$;else{if(p&&$-b>1){const N=o[$-1],f=l.slice(0,-1);f&&f.length>0&&d.push(f),l=N+y}else l+=y;p=!1,b=-1}g=P}return l&&l.length>0&&d.push(l),d}if(e.startsWith("uk")||e.startsWith("ru")||e.startsWith("bg")||e.startsWith("sr")||e.startsWith("mk")||e.startsWith("be")){if(!W.test(t)&&!L.test(t))return[t];const o=[...t],u=o.length,d=[];let l=o[0];const g=o[0];let p;W.test(g)?p=1:L.test(g)?p=2:p=0;let b=g===g.toLocaleUpperCase(e);for(let y=1;y<u;y++){const P=o[y];let N;W.test(P)?N=1:L.test(P)?N=2:N=0;const f=P===P.toLocaleUpperCase(e);p!==N&&(p===1||p===2)&&(N===1||N===2)||N===p&&!b&&f?(d.push(l),l=P):l+=P,p=N,b=f}l&&l.length>0&&d.push(l);const $=[];for(let y=0;y<d.length;y++)y<d.length-1&&d[y].length===1&&L.test(d[y])&&W.test(d[y+1][0])?($.push(d[y]+d[y+1]),y+=1):$.push(d[y]);return $}if(e.startsWith("el")){if(!ye.test(t)&&!L.test(t))return[t];const o=[];Ke.lastIndex=0;let u;for(;(u=Ke.exec(t))!==null;)o.push(u[0]);o.length===0&&o.push(t);const d=[];if(o.length===1){const l=o[0];if(!l||!ye.test(l[0])||l.length===1)return[l??t]}for(const l of o){if(!l)continue;if(!ye.test(l[0])||l.length===1){d.push(l);continue}const g=l.length;let p=l[0],b=l[0]===l[0].toLocaleUpperCase(e);for(let $=1;$<g;$++){const y=l[$],P=y===y.toLocaleUpperCase(e);!b&&P?(d.push(p),p=y):p+=y,b=P}p&&d.push(p)}return d}if(e.startsWith("ja")||e.startsWith("ko")){const o=e.startsWith("ja"),u=o?{hiragana:x(l=>gi.test(l),"hiragana"),kanji:x(l=>Qe.test(l),"kanji"),katakana:x(l=>wi.test(l),"katakana"),latin:x(l=>L.test(l),"latin")}:{hangul:x(l=>Ye.test(l),"hangul"),latin:x(l=>L.test(l),"latin")},d=new Set(["が","で","と","に","の","は","へ","も","や","を"]);if(o){const l=M(t,u,!1,e,(p,b)=>p==="hiragana"&&b==="katakana"||p==="katakana"&&b==="hiragana"||p==="hiragana"&&b==="latin"||p==="katakana"&&b==="latin"||p==="kanji"&&b==="latin"||p==="latin"&&(b==="hiragana"||b==="katakana"||b==="kanji")),g=[];for(const p of l){const b=p;b.length===1&&d.has(b)&&g.length>0?g[g.length-1]=g.at(-1)+b:g.push(b)}return g.length>0?g:[t]}return M(t,u,!1,e,(l,g)=>l==="hangul"&&g==="latin"||l==="latin"&&g==="hangul")}if(e.startsWith("sl")){const o=[...t],u=o.length,d=[];let l=o[0],g=o[0]===o[0].toLocaleUpperCase(e);for(let p=1;p<u;p++){const b=o[p],$=b===b.toLocaleUpperCase(e),y=to.test(b),P=p<u-1&&o[p+1]===o[p+1].toLocaleUpperCase(e);!g&&$||y&&P?(d.push(l),l=b,y&&P&&(d.push(l),l="")):l+=b,g=$}return l&&l.length>0&&d.push(l),d}if(e.startsWith("zh"))return M(t,{han:x(o=>Qe.test(o),"han"),latin:x(o=>L.test(o),"latin")},!1,e);if(["ar","fa","he","ur"].includes(e.split("-")[0])){const o=x(u=>Je.test(u)||He.test(u),"isRtlChar");return M(t,{latin:x(u=>L.test(u),"latin"),rtl:x(u=>o(u),"rtl")},!1,e)}if(["am","bn","gu","hi","km","kn","lo","ml","mr","ne","or","pa","si","ta","te","th"].includes(e.split("-")[0])){const o=x(u=>fi.test(u)||pi.test(u)||hi.test(u)||mi.test(u)||vi.test(u)||Ai.test(u)||Ci.test(u)||$i.test(u)||Pi.test(u)||Ni.test(u)||bi.test(u)||xi.test(u)||Oi.test(u)||di.test(u)||yi.test(u)||Ei.test(u),"isIndicChar");return M(t,{indic:x(u=>o(u),"indic"),latin:x(u=>L.test(u),"latin")},!1,e)}if(["be","bg","ru","sr","uk"].includes(e))return M(t,{cyrillic:x(o=>W.test(o),"cyrillic"),latin:x(o=>L.test(o),"latin")},!0,e);if(["ar","fa","he"].includes(e))return M(t,{latin:x(o=>L.test(o),"latin"),rtl:x(o=>Je.test(o)||He.test(o),"rtl")},!1,e);if(e.startsWith("ko"))return M(t,{hangul:x(o=>Ye.test(o),"hangul"),latin:x(o=>L.test(o),"latin")},!1,e);if(e.startsWith("uz")){if(!W.test(t)&&!L.test(t))return[t];const o=[...t],u=o.length,d=[];let l=o[0],g=o[0]===o[0].toLocaleUpperCase(e);for(let p=1;p<u;p++){const b=o[p],$=b===b.toLocaleUpperCase(e);if(Ze.test(b)||Ze.test(o[p-1])){l+=b;continue}!g&&$?(d.push(l),l=b):l+=b,g=$}return l&&l.length>0&&d.push(l),d}const r=[...t],a=r.length,c=[];let s=r[0],m=r[0]===r[0].toLocaleUpperCase(e);for(const o of n)if(t.startsWith(o)){c.push(o),s=r[o.length],m=s===s.toLocaleUpperCase(e);break}for(let o=1;o<a;o++){const u=r[o],d=u===u.toLocaleUpperCase(e);let l=0;for(const g of n)if(t.startsWith(g,o)){c.push(s,g),l=g.length,s="";const p=g.at(-1);p&&(m=p===p.toLocaleUpperCase(e));break}if(l>0){o+=l-1;continue}!m&&d?(c.push(s),s=u):s+=u,m=d}return s&&c.push(s),c},"splitCamelCaseLocale"),ao=x((t,e,n)=>{const i=[],r=X.test(t)?t.split(X).filter(Boolean):[t];for(const a of r){const c=a;if(X.test(c))i.push(c);else{const s=H.test(c)?Xi(c).filter(Boolean):[c];for(const m of s)if(H.test(m))i.push(m);else if(e){const o=e.toLowerCase().split("-")[0];i.push(...Lt(m,o,n))}else i.push(...jt(m,n))}}return i},"processTextWithAnsiEmoji"),io=x((t,e={})=>{if(!t||typeof t!="string")return[];const{handleAnsi:n=!1,handleEmoji:i=!1,knownAcronyms:r=[],locale:a,normalize:c=!1,separators:s,stripAnsi:m=!1,stripEmoji:o=!1}=e,u=new Set([...r].toSorted((y,P)=>P.length-y.length));let d=t;m&&(d=Gi(d)),o&&(d=ki(d));let l;Array.isArray(s)?l=Ji(s):s instanceof RegExp?l=s:l=ui;const g=[];let p=d;const b=l.flags.includes("g")?l:new RegExp(l.source,`${l.flags}g`);for(;p.length>0;){const y=b.exec(p);if(!y){p===".."?g.push(".."):p==="."?g.push("."):p.length>0&&g.push(p);break}const P=y.index,N=y[0],f=N.length,h=p.slice(0,P),v=p.slice(P+f);if(N.startsWith("../"))g.push(".."),p=p.slice(P+3);else if(N.startsWith("./"))g.push("."),p=p.slice(P+2);else if(P===0&&N==="..")g.push(".."),p=p.slice(2);else if(P===0&&N===".")g.push("."),p=p.slice(1);else{h.length>0&&g.push(h);let w=0;for(;(w=N.indexOf("../",w))!==-1;)g.push(".."),w+=3;for(w=0;(w=N.indexOf("./",w))!==-1;)(w===0||N[w-1]!==".")&&g.push("."),w+=2;let E=v;for(;E.startsWith("../");)g.push(".."),E=E.slice(3);for(;E.startsWith("./");)g.push("."),E=E.slice(2);if(E===".."){g.push("..");break}else if(E==="."){g.push(".");break}else p=E}b.lastIndex=0}if(g.length===0){const y=d.split(l).filter(Boolean);g.push(...y)}let $=[];for(const y of g)n||i?$.push(...ao(y,a,u)):a?$.push(...Lt(y,a,u)):$.push(...jt(y,u));return c&&($=$.map(y=>u.has(y)?y:a&&y===y.toLocaleUpperCase(a)?y[0]+y.slice(1).toLocaleLowerCase(a):y.toUpperCase()===y&&!u.has(y)?y.slice(0,1)+y.slice(1).toLowerCase():y)),$},"splitByCase");var oo=Object.defineProperty,ro=O((t,e)=>oo(t,"name",{value:e,configurable:!0}),"r$4"),so=Object.defineProperty,lo=ro((t,e)=>so(t,"name",{value:e,configurable:!0}),"o"),co=Object.defineProperty,uo=lo((t,e)=>co(t,"name",{value:e,configurable:!0}),"s");const po=uo((t,e)=>typeof t!="string"||t===""?"":(e?.locale?t[0].toLocaleUpperCase(e.locale):t[0].toUpperCase())+t.slice(1),"upperFirst");var fo=Object.defineProperty,ho=O((t,e)=>fo(t,"name",{value:e,configurable:!0}),"r$3"),mo=Object.defineProperty,go=ho((t,e)=>mo(t,"name",{value:e,configurable:!0}),"r"),vo=Object.defineProperty,wo=go((t,e)=>vo(t,"name",{value:e,configurable:!0}),"n");const yo=wo((t,e)=>`${t}::${e?.joiner??""}::${e?.locale??""}::${e?.knownAcronyms?.join(",")??""}::${e?.normalize?"true":"false"}`,"generateCacheKey");var bo=Object.defineProperty,$o=O((t,e)=>bo(t,"name",{value:e,configurable:!0}),"i$3"),Oo=Object.defineProperty,Eo=$o((t,e)=>Oo(t,"name",{value:e,configurable:!0}),"f"),Po=Object.defineProperty,Ao=Eo((t,e)=>Po(t,"name",{value:e,configurable:!0}),"l");const Co=Ao((t,e)=>{const{length:n}=t;if(n===0)return"";if(n===1)return t[0];const i=[];let r="",a="";for(let c=0;c<n;c++){const s=t[c];if(X.test(s)){r?(i.push(r+a+s),r="",a=""):(i.length>0&&i.push(e),r=s);continue}r?(a&&(a+=e),a+=s):(i.length>0&&i.push(e),i.push(s))}return i.join("")},"joinSegments");var No=Object.defineProperty,xo=O((t,e)=>No(t,"name",{value:e,configurable:!0}),"r$2"),ko=Object.defineProperty,_o=xo((t,e)=>ko(t,"name",{value:e,configurable:!0}),"a"),jo=Object.defineProperty,Lo=_o((t,e)=>jo(t,"name",{value:e,configurable:!0}),"e");const Io=/(?<![a-zß])SS(?![a-z])/g,So=Lo(t=>t.replaceAll(Io,"ß"),"normalizeGermanEszett");var Uo=Object.defineProperty,Mo=O((t,e)=>Uo(t,"name",{value:e,configurable:!0}),"c$2"),To=Object.defineProperty,Vo=Mo((t,e)=>To(t,"name",{value:e,configurable:!0}),"c"),Do=Object.defineProperty,Ro=Vo((t,e)=>Do(t,"name",{value:e,configurable:!0}),"o");const Bo=new Nt(1e3),It=Ro((t,e)=>{if(typeof t!="string"||!t)return"";const n=e?.cache??!1,i=e?.cacheStore??Bo;let r;if(n&&(r=yo(t,e)),n&&r&&i.has(r))return i.get(r);let a=!0;const c=Co(io(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=>{if(e?.handleAnsi&&X.test(s))return s;const m=e?.locale?.startsWith("de")?So(s):s,o=e?.locale?m.toLocaleLowerCase(e.locale):m.toLowerCase();return a?(a=!1,Ri(o,e)):po(o,e)}),"");return n&&r&&i.set(r,c),c},"camelCase");var zo=Object.defineProperty,de=O((t,e)=>zo(t,"name",{value:e,configurable:!0}),"a$2");const Wo=de(t=>{t.options?.forEach(e=>{e.__camelCaseName__=It(e.name)})},"processOptionNames"),Fo=de(t=>{if(!Array.isArray(t.options)||t.options.length===0)return;const e=new Set;for(const i of t.options)e.add(i.name);const n=[];for(const i of t.options)if(i.name.startsWith("no-")){const r=i.name.replace("no-","");if(!e.has(r)){if(i.type!==Boolean)throw new Error(`Cannot add negated option "${i.name}" to command "${t.name}" because it is not a boolean.`);const a={...i,defaultValue:i.defaultValue===void 0?!0:!i.defaultValue,name:r};n.push(a),e.add(r)}}n.length>0&&t.options.push(...n)},"addNegatableOptions"),qo=de((t,e)=>{if(!e.options||e.options.length===0)return;const{options:n}=t,i=new Map;for(const a of e.options)if(a.name.startsWith("no-")){const c=It(a.name);i.set(c,a)}const r=Object.keys(n).filter(a=>i.has(a));if(r.length!==0)for(const a of r){const c=a.charAt(2);if(!c)continue;const s=c.toLowerCase()+a.slice(3),m=i.get(a);m&&(m.__negated__=!0),n[s]=!n[a],Reflect.deleteProperty(n,a)}},"mapNegatableOptions"),Go=de((t,e)=>{if(!e.options||e.options.length===0)return;const n=new Map;for(const r of e.options)r.__camelCaseName__&&r.__negated__===void 0&&r.implies!==void 0&&n.set(r.__camelCaseName__,r);if(n.size===0)return;const{options:i}=t;for(const r of Object.keys(i)){const a=n.get(r);if(a?.implies){const{implies:c}=a;for(const[s,m]of Object.entries(c))i[s]===void 0&&(i[s]=m)}}},"mapImpliedOptions");var Ho=Object.defineProperty,he=O((t,e)=>Ho(t,"name",{value:e,configurable:!0}),"e$2");const Ko=he(()=>!!process.versions.electron,"isElectronApp"),Yo=he(()=>Ko()&&!process.defaultApp,"isBundledElectronApp"),Jo=he(()=>Yo()?0:1,"getProcessArgvBinIndex"),Qo=he(t=>t.slice(Jo()+1),"hideBin");var Zo=Object.defineProperty,St=O((t,e)=>Zo(t,"name",{value:e,configurable:!0}),"e$1");const Xo=" ",er=St((t,e)=>t===e?!0:t.length!==e.length?!1:t.every((n,i)=>n===e[i]),"equals"),tr=St(t=>{if(typeof t=="string")return t.split(Xo);const e=Ce();return er(t,e)?Qo(t):t},"parseRawCommand");var nr=Object.defineProperty,Ee=O((t,e)=>nr(t,"name",{value:e,configurable:!0}),"r");const ar=Ee(t=>{const e=Ee(a=>{t.error(`Uncaught exception: ${a.message||a}`),a.stack&&t.error(a.stack),re(1)},"uncaughtExceptionHandler"),n=Ee((a,c)=>{if(a instanceof Error)t.error(`Promise rejection: ${a.message||a}`),a.stack&&t.error(a.stack);else{let s;if(typeof a=="string")s=a;else try{s=JSON.stringify(a)}catch{s=String(a)}t.error(`Promise rejection: ${s}`)}re(1)},"unhandledRejectionHandler"),i=Le("uncaughtException",e),r=Le("unhandledRejection",n);return()=>{i(),r()}},"registerExceptionHandler");var ir=Object.defineProperty,Y=O((t,e)=>ir(t,"name",{value:e,configurable:!0}),"e");const se=100,Ut=/^[a-z][\w-]*$/i,_e=Y((t,e)=>{if(typeof t!="string"||t.trim().length===0)throw new C(`${e} must be a non-empty string`,"INVALID_INPUT",{fieldName:e,value:t});return t.trim()},"validateNonEmptyString"),et=Y((t,e)=>{if(!Array.isArray(t)||!t.every(n=>typeof n=="string"))throw new C(`${e} must be an array of strings`,"INVALID_INPUT",{fieldName:e,value:t});return t},"validateStringArray");Y((t,e)=>{if(typeof t!="function")throw new C(`${e} must be a function`,"INVALID_INPUT",{fieldName:e,value:t});return t},"validateFunction");const Pe=Y((t,e)=>{if(typeof t!="object"||t===null)throw new C(`${e} must be an object`,"INVALID_INPUT",{fieldName:e,value:t});return t},"validateObject"),ae=Y(t=>{const e=_e(t,"Command name");if(e.length>se)throw new C(`Command name is too long (maximum ${String(se)} characters)`,"INVALID_COMMAND_NAME",{commandName:e,length:e.length});if(e.includes("..")||e.includes("/")||e.includes("\\")||e.includes(";")||e.includes("|")||e.includes("&"))throw new C(`Command name "${e}" contains invalid characters`,"INVALID_COMMAND_NAME",{commandName:e});if(!Ut.test(e))throw new C(`Command name "${e}" must start with a letter and contain only letters, numbers, hyphens, and underscores`,"INVALID_COMMAND_NAME",{commandName:e});return e},"validateCommandName");Y(t=>{const e=_e(t,"Plugin name");if(e.length>se)throw new C(`Plugin name is too long (maximum ${String(se)} characters)`,"INVALID_PLUGIN_NAME",{length:e.length,pluginName:e});if(e.includes("..")||e.includes("/")||e.includes("\\")||e.includes(";")||e.includes("|")||e.includes("&"))throw new C(`Plugin name "${e}" contains invalid characters`,"INVALID_PLUGIN_NAME",{pluginName:e});if(!Ut.test(e))throw new C(`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 or=Object.defineProperty,me=O((t,e)=>or(t,"name",{value:e,configurable:!0}),"s");const rr=new Set([`
4
- `,"\r"," ","\0",'"',"$","&","'","(",")",";","<",">","[","\\","]","`","{","|","}"]),sr=/^[A-Z]:/i,lr=me(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(rr.has(e))throw new Error(`Argument contains dangerous character: ${e}`);return t.trim()},"sanitizeArgument"),tt=me(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=>lr(e))},"sanitizeArguments");me(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("/")||sr.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 xr{static{O(this,"RateLimiter")}static{me(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(),i=this.attempts.get(e);return!i||n>i.resetTime?(this.attempts.set(e,{count:1,resetTime:n+this.windowMs}),this.cleanup(n),!0):i.count>=this.maxAttempts?!1:(i.count+=1,!0)}reset(e){this.attempts.delete(e)}cleanup(e){for(const[n,i]of this.attempts.entries())e>i.resetTime&&this.attempts.delete(n)}}var cr=Object.defineProperty,oe=O((t,e)=>cr(t,"name",{value:e,configurable:!0}),"T");const ur=/^-([^\d-])$/,pr=/^--(\S+)/,fr=/^-([^\d-]{2,})$/,Ae=oe(t=>ur.test(t)||pr.test(t)||fr.test(t),"isOption");class kr{static{O(this,"Cli")}static{oe(this,"Cli")}#t;#e;#o;#c;#v;#u;#w;#r;#n;#a;#p;#s;#l;#f=!1;#y;#b=!1;#d;#h;#m;#g=[];#A(){return this.#d===void 0&&(this.#d=[...this.#a.keys()]),this.#d}#$(){return this.#h===void 0&&(this.#h=[...this.#n.keys()]),this.#h}#i(){return this.#m===void 0&&(this.#m=[...this.#A(),...this.#$()]),this.#m}#O(){return this.#g.length===0?ne:[...ne,...this.#g]}#C(){this.#d=void 0,this.#h=void 0,this.#m=void 0}#E(){if(this.#o===void 0){const e=tr(this.#e.argv);this.#o=tt(e),this.#N()}return this.#o}#N(){if(!this.#o)return;const e=G();let n=!1;for(const i of this.#o){if(i==="--quiet"||i==="-q"){e.CEREBRO_OUTPUT_LEVEL=String(Bt),n=!0;break}if(i==="--verbose"||i==="-v"){e.CEREBRO_OUTPUT_LEVEL=String(zt),n=!0;break}if(i==="--debug"||i==="-vvv"){e.CEREBRO_OUTPUT_LEVEL=String(F),n=!0;break}}n||(e.CEREBRO_OUTPUT_LEVEL=Object.hasOwn(e,"DEBUG")?String(F):String(je))}#x(){this.#b||(this.#y=ar(this.#t),this.#b=!0)}#P(e,n,i,r){this.#t.debug(`command '${r}' found, parsing command args: ${n.join(", ")}`);const{arguments_:a,booleanValues:c,parsedArgs:s}=Ra(e,n,this.#O()),m=Object.keys(c).length>0;let o=s;m&&(o={...s,_all:{...s._all,...c}}),Ja(a,o,e);const u=Da(e,s,c,i);u.runtime=this,u.argv=this.#E();const d=e.options&&e.options.length>0;if(d&&e.options){const l=e.options.filter(g=>g.name.startsWith("no-"));for(const g of l){const p=g.name.replace("no-",""),b=`--${g.name}`,$=`--${p}`,y=n.includes(b),P=n.includes($);if(y&&P)throw new nt(p,g.name)}}return d&&(qo(u,e),Go(u,e)),Qa(a,u.options,e),G().CEREBRO_OUTPUT_LEVEL===String(F)&&(this.#t.debug("command options parsed from options:"),this.#t.debug(JSON.stringify(u.options,null,2)),this.#t.debug("command argument parsed from argument:"),this.#t.debug(JSON.stringify(u.argument,null,2))),{arguments_:a,booleanValues:c,commandArgs:o,parsedArgs:s,toolbox:u}}constructor(e,n={}){if(typeof e!="string"||e.trim().length===0)throw new C("CLI name must be a non-empty string","INVALID_INPUT",{cliName:e});this.#v=e.trim();const i=n.argv??Ce(),r=n.cwd??Wt();if(this.#e={...n,argv:i,cwd:r},this.#e.argv&&!Array.isArray(this.#e.argv))throw new C("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 C("CLI cwd option must be a string","INVALID_INPUT",{cwd:this.#e.cwd});if(this.#e.packageName&&typeof this.#e.packageName!="string")throw new C("CLI packageName option must be a string","INVALID_INPUT",{packageName:this.#e.packageName});if(this.#e.packageVersion&&typeof this.#e.packageVersion!="string")throw new C("CLI packageVersion option must be a string","INVALID_INPUT",{packageVersion:this.#e.packageVersion});const a=G();if(a.CEREBRO_OUTPUT_LEVEL=String(je),typeof this.#e.logger=="object"){const c=["debug","error","info","log","warn"],s=[],m=this.#e.logger;for(const o of c)typeof m[o]!="function"&&s.push(o);if(s.length>0)throw new C(`Logger object is missing required methods: ${s.join(", ")}`,"INVALID_INPUT",{logger:this.#e.logger,missingMethods:s});this.#t=this.#e.logger}else this.#t={...console,debug:oe((...c)=>{a.CEREBRO_OUTPUT_LEVEL===String(F)&&console.debug(...c)},"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.#a=new Map,this.#p=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){Pe(e,"Command"),ae(e.name);const n=typeof e.execute=="function",i=typeof e.loader=="function";if(n&&i)throw new C(`Command "${e.name}" cannot define both "execute" and "loader" — choose one`,"INVALID_COMMAND",{commandName:e.name});if(!n&&!i)throw new C(`Command "${e.name}" must define either "execute" or "loader"`,"INVALID_COMMAND",{commandName:e.name});e.alias&&(typeof e.alias=="string"?ae(e.alias):et(e.alias,"Command alias").forEach(c=>ae(c))),e.argument&&Pe(e.argument,"Command argument"),e.options&&Pe(e.options,"Command options"),e.commandPath&&(et(e.commandPath,"Command commandPath"),e.commandPath.forEach(c=>{ae(c)}));const r=ti(e.name,e.commandPath),a=Q(r);if(this.#a.has(a))throw new C(`Command with path "${a}" already exists`,"DUPLICATE_COMMAND",{commandName:e.name,commandPath:e.commandPath});if(this.#n.has(e.name)&&!e.commandPath)throw new C(`Command with name "${e.name}" already exists`,"DUPLICATE_COMMAND",{commandName:e.name});if(e.options)for(const c of e.options)Se(c);if(Za(e),Fo(e),Wo(e),e.options&&(e.__conflictingOptions__=e.options.filter(c=>c.conflicts!==void 0),e.__requiredOptions__=e.options.filter(c=>c.required===!0)),this.#n.set(e.name,e),this.#a.set(a,r),this.#p.set(a,e),this.#C(),e.alias!==void 0){const c=typeof e.alias=="string"?[e.alias]:e.alias;for(const s of c){if(G().CEREBRO_OUTPUT_LEVEL===String(F)&&this.#t.debug("adding alias",s),this.#n.has(s))throw new C(`Command alias "${s}" conflicts with existing command`,"DUPLICATE_COMMAND",{alias:s,commandName:e.name});this.#n.set(s,e)}}return this}addGlobalOption(e){const n=e,i=new Set(ne.map(a=>a.name)),r=new Set(ne.map(a=>a.alias).filter(Boolean));if(i.has(n.name))throw new C(`Cannot add global option "--${n.name}": it conflicts with a built-in global option`,"DUPLICATE_OPTION",{optionName:n.name});if(n.alias&&r.has(n.alias))throw new C(`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(a=>a.name)).has(n.name))throw new C(`Global option "--${n.name}" has already been added`,"DUPLICATE_OPTION",{optionName:n.name});return n.group="global",Se(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 nn(this.#t),this.#r.register({description:"Attaches the logger to the toolbox",execute:oe(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:i=!0,...r}=e;if(!this.#n.has("help")){const{default:h}=await import("../commands/help-command.js");this.addCommand(new h(this.#n))}const a=this.#$(),c=this.#a;this.#x();const s=this.#E();let m,o=[...s];const u=Ft(),d=qt(),l=Ce();this.#t.debug(`process.execPath: ${u}`),this.#t.debug(`process.execArgv: ${d.join(" ")}`),this.#t.debug(`process.argv: ${l.join(" ")}`);const g=ei(c,[...s]);if(g.commandPath)m=g.commandPath,o=g.argv;else{if(s.length>1&&s[0]&&s[1]&&!Ae(s[0])&&!Ae(s[1])){const v=[];let w=0;for(;w<s.length;){const k=s[w];if(!k||Ae(k))break;v.push(k),w+=1}const E=Q(v);if(v[0]&&!a.includes(v[0])){const k=this.#i(),A=q(E,k);throw new B(E,A)}}let h;try{h=dn([null,...a],[...s])}catch(v){if(v instanceof Error&&v.name==="INVALID_COMMAND"&&"command"in v){const w=v.command,E=this.#i(),k=q(w,E);throw new B(w,k)}throw v}h.command&&(m=[h.command],o=h.argv)}if(!m)if(this.#s)m=[this.#s];else{const h=this.#i();throw new B("",h)}const p=Q(m),b=this.#a.get(p);let $;if(b){if($=this.#p.get(p),!$||Q(b)!==p){const h=this.#i(),v=q(p,h);throw new B(p,v)}}else{const h=m.at(-1);if($=h?this.#n.get(h):void 0,!$){const v=this.#i(),w=q(p,v);throw new B(p,w)}}if(typeof $.execute!="function"&&typeof $.loader!="function")return this.#t.error(`Command "${$.name}" has no function to execute.`),i?re(1):void 0;const y=o,{commandArgs:P,toolbox:N}=this.#P($,y,r,p),f=this.getPluginManager();try{!this.#f&&f.hasPlugins()&&(await f.init({cli:this,cwd:this.#c,logger:this.#t}),this.#f=!0),await f.executeLifecycle("execute",N),await f.executeLifecycle("beforeCommand",N);let h;const v=P.global;if(v?.help){const w=this.#n.get("help");if(!w)throw new C("Help command not found","COMMAND_NOT_FOUND");h=await z(w,N,P)}else if(v?.version??v?.V){const w=this.#n.get("version");if(!w)throw new C("Version command not found","COMMAND_NOT_FOUND");h=await z(w,N,P)}else h=await z($,N,P);return await f.executeLifecycle("afterCommand",N,h),i?re(0):void 0}catch(h){throw await f.executeErrorHandlers(h,N),h}finally{n&&this.dispose()}}async runCommand(e,n={}){const{argv:i=[],...r}=n;_e(e,"Command name");const a=e.split(" ").filter(Boolean),c=Q(a),s=this.#a.get(c)?this.#p.get(c):this.#n.get(e);if(!s){const l=this.#i(),g=q(c||e,l);throw new B(e,g)}if(typeof s.execute!="function"&&typeof s.loader!="function")throw new C(`Command "${s.name}" has no function to execute`,"INVALID_COMMAND",{commandName:s.name});const m=[...tt(i)];this.#t.debug(`running command '${e}' programmatically with args: ${m.join(", ")}`);const{commandArgs:o,toolbox:u}=this.#P(s,m,r,c||e),d=this.getPluginManager();try{!this.#f&&d.hasPlugins()&&(await d.init({cli:this,cwd:this.#c,logger:this.#t}),this.#f=!0),await d.executeLifecycle("execute",u),await d.executeLifecycle("beforeCommand",u);let l;const g=o.global;if(g?.help){const p=this.#n.get("help");if(!p)throw new C("Help command not found","COMMAND_NOT_FOUND");l=await z(p,u,o)}else if(g?.version??g?.V){const p=this.#n.get("version");if(!p)throw new C("Version command not found","COMMAND_NOT_FOUND");l=await z(p,u,o)}else l=await z(s,u,o);return await d.executeLifecycle("afterCommand",u,l),l}catch(l){throw await d.executeErrorHandlers(l,u),l}}}export{kr as Cli};