@visulima/cerebro 3.1.0 → 3.1.2

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,25 @@
1
+ ## @visulima/cerebro [3.1.2](https://github.com/visulima/visulima/compare/@visulima/cerebro@3.1.1...@visulima/cerebro@3.1.2) (2026-09-21)
2
+
3
+ ### Bug Fixes
4
+
5
+ * **vis:** surface release in help and fix doctor cause ([#868](https://github.com/visulima/visulima/issues/868)) ([e826ef9](https://github.com/visulima/visulima/commit/e826ef96162a6d59443f1174f4ca75240cf6e917)), closes [#863](https://github.com/visulima/visulima/issues/863)
6
+
7
+ ### Miscellaneous Chores
8
+
9
+ * point every Discord link at the anolilab server ([#858](https://github.com/visulima/visulima/issues/858)) ([4002bfc](https://github.com/visulima/visulima/commit/4002bfcd8d3c748d7008efe208e6aaae7bd18753))
10
+
11
+ ## @visulima/cerebro [3.1.1](https://github.com/visulima/visulima/compare/@visulima/cerebro@3.1.0...@visulima/cerebro@3.1.1) (2026-09-03)
12
+
13
+ ### Bug Fixes
14
+
15
+ * stop vis ci, cache, preflight and inference failing silently ([#854](https://github.com/visulima/visulima/issues/854)) ([45a97b0](https://github.com/visulima/visulima/commit/45a97b02684c8336662f23a3f2cd2f7227c14692))
16
+
17
+
18
+ ### Dependencies
19
+
20
+ * **@visulima/boxen:** upgraded to 5.0.0
21
+ * **@visulima/pail:** upgraded to 5.0.0
22
+
1
23
  ## @visulima/cerebro [3.1.0](https://github.com/visulima/visulima/compare/%40visulima%2Fcerebro%403.0.6...%40visulima%2Fcerebro%403.1.0) (2026-08-19)
2
24
 
3
25
  ## @visulima/cerebro [3.0.6](https://github.com/visulima/visulima/compare/%40visulima%2Fcerebro%403.0.5...%40visulima%2Fcerebro%403.0.6) (2026-08-08)
package/LICENSE.md CHANGED
@@ -559,6 +559,36 @@ Repository: git+https://github.com/visulima/visulima.git
559
559
  > MIT
560
560
  >
561
561
  > # Bundled dependencies:
562
+ > ## codsen-format-diagnostic-value
563
+ > License: MIT
564
+ > By: Roy Revelt
565
+ > Repository: git+https://github.com/codsen/codsen.git
566
+ >
567
+ > > MIT License
568
+ > >
569
+ > > Copyright © 2010-2026 Roy Revelt and other contributors
570
+ > >
571
+ > > Permission is hereby granted, free of charge, to any person obtaining
572
+ > > a copy of this software and associated documentation files (the
573
+ > > "Software"), to deal in the Software without restriction, including
574
+ > > without limitation the rights to use, copy, modify, merge, publish,
575
+ > > distribute, sublicense, and/or sell copies of the Software, and to
576
+ > > permit persons to whom the Software is furnished to do so, subject to
577
+ > > the following conditions:
578
+ > >
579
+ > > The above copyright notice and this permission notice shall be
580
+ > > included in all copies or substantial portions of the Software.
581
+ > >
582
+ > > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
583
+ > > EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
584
+ > > MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
585
+ > > NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
586
+ > > LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
587
+ > > OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
588
+ > > WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
589
+ >
590
+ > ---------------------------------------
591
+ >
562
592
  > ## codsen-utils
563
593
  > License: MIT
564
594
  > By: Roy Revelt
@@ -566,7 +596,7 @@ Repository: git+https://github.com/visulima/visulima.git
566
596
  >
567
597
  > > MIT License
568
598
  > >
569
- > > Copyright © 2010-2025 Roy Revelt and other contributors
599
+ > > Copyright © 2010-2026 Roy Revelt and other contributors
570
600
  > >
571
601
  > > Permission is hereby granted, free of charge, to any person obtaining
572
602
  > > a copy of this software and associated documentation files (the
@@ -664,68 +694,14 @@ Repository: git+https://github.com/visulima/visulima.git
664
694
  >
665
695
  > ---------------------------------------
666
696
  >
667
- > ## html-entities
668
- > License: MIT
669
- > By: Marat Dulin
670
- > Repository: https://github.com/mdevils/html-entities.git
671
- >
672
- > > Copyright (c) 2021 Dulin Marat
673
- > >
674
- > > Permission is hereby granted, free of charge, to any person obtaining a copy
675
- > > of this software and associated documentation files (the "Software"), to deal
676
- > > in the Software without restriction, including without limitation the rights
677
- > > to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
678
- > > copies of the Software, and to permit persons to whom the Software is
679
- > > furnished to do so, subject to the following conditions:
680
- > >
681
- > > The above copyright notice and this permission notice shall be included in
682
- > > all copies or substantial portions of the Software.
683
- > >
684
- > > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
685
- > > IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
686
- > > FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
687
- > > AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
688
- > > LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
689
- > > OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
690
- > > THE SOFTWARE.
691
- >
692
- > ---------------------------------------
693
- >
694
- > ## indent-string
697
+ > ## html-entity-codec
695
698
  > License: MIT
696
- > By: Sindre Sorhus
697
- > Repository: sindresorhus/indent-string
699
+ > By: Roy Revelt
700
+ > Repository: git+https://github.com/codsen/codsen.git
698
701
  >
699
702
  > > MIT License
700
703
  > >
701
- > > Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
702
- > >
703
- > > Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
704
- > >
705
- > > The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
706
- > >
707
- > > 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.
708
- >
709
- > ---------------------------------------
710
- >
711
- > ## lodash-es
712
- > License: MIT
713
- > By: John-David Dalton, Mathias Bynens
714
- > Repository: lodash/lodash
715
- >
716
- > > Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
717
- > >
718
- > > Based on Underscore.js, copyright Jeremy Ashkenas,
719
- > > DocumentCloud and Investigative Reporters & Editors <http://underscorejs.org/>
720
- > >
721
- > > This software consists of voluntary contributions made by many
722
- > > individuals. For exact contribution history, see the revision history
723
- > > available at https://github.com/lodash/lodash
724
- > >
725
- > > The following license applies to all parts of this software except as
726
- > > documented below:
727
- > >
728
- > > ====
704
+ > > Copyright © 2010-2026 Roy Revelt and other contributors
729
705
  > >
730
706
  > > Permission is hereby granted, free of charge, to any person obtaining
731
707
  > > a copy of this software and associated documentation files (the
@@ -745,21 +721,23 @@ Repository: git+https://github.com/visulima/visulima.git
745
721
  > > LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
746
722
  > > OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
747
723
  > > WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
724
+ >
725
+ > ---------------------------------------
726
+ >
727
+ > ## indent-string
728
+ > License: MIT
729
+ > By: Sindre Sorhus
730
+ > Repository: sindresorhus/indent-string
731
+ >
732
+ > > MIT License
748
733
  > >
749
- > > ====
750
- > >
751
- > > Copyright and related rights for sample code are waived via CC0. Sample
752
- > > code is defined as all source code displayed within the prose of the
753
- > > documentation.
734
+ > > Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
754
735
  > >
755
- > > CC0: http://creativecommons.org/publicdomain/zero/1.0/
736
+ > > Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
756
737
  > >
757
- > > ====
738
+ > > The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
758
739
  > >
759
- > > Files located in the node_modules and vendor directories are externally
760
- > > maintained libraries used by this software which have their own
761
- > > licenses; we recommend you read them, as their terms may differ from the
762
- > > terms above.
740
+ > > 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.
763
741
  >
764
742
  > ---------------------------------------
765
743
  >
@@ -770,7 +748,7 @@ Repository: git+https://github.com/visulima/visulima.git
770
748
  >
771
749
  > > MIT License
772
750
  > >
773
- > > Copyright © 2010-2025 Roy Revelt and other contributors
751
+ > > Copyright © 2010-2026 Roy Revelt and other contributors
774
752
  > >
775
753
  > > Permission is hereby granted, free of charge, to any person obtaining
776
754
  > > a copy of this software and associated documentation files (the
@@ -800,7 +778,7 @@ Repository: git+https://github.com/visulima/visulima.git
800
778
  >
801
779
  > > MIT License
802
780
  > >
803
- > > Copyright © 2010-2025 Roy Revelt and other contributors
781
+ > > Copyright © 2010-2026 Roy Revelt and other contributors
804
782
  > >
805
783
  > > Permission is hereby granted, free of charge, to any person obtaining
806
784
  > > a copy of this software and associated documentation files (the
@@ -830,7 +808,7 @@ Repository: git+https://github.com/visulima/visulima.git
830
808
  >
831
809
  > > MIT License
832
810
  > >
833
- > > Copyright © 2010-2025 Roy Revelt and other contributors
811
+ > > Copyright © 2010-2026 Roy Revelt and other contributors
834
812
  > >
835
813
  > > Permission is hereby granted, free of charge, to any person obtaining
836
814
  > > a copy of this software and associated documentation files (the
@@ -860,7 +838,7 @@ Repository: git+https://github.com/visulima/visulima.git
860
838
  >
861
839
  > > MIT License
862
840
  > >
863
- > > Copyright © 2010-2025 Roy Revelt and other contributors
841
+ > > Copyright © 2010-2026 Roy Revelt and other contributors
864
842
  > >
865
843
  > > Permission is hereby granted, free of charge, to any person obtaining
866
844
  > > a copy of this software and associated documentation files (the
@@ -900,29 +878,6 @@ Repository: git+https://github.com/visulima/visulima.git
900
878
  >
901
879
  > ---------------------------------------
902
880
  >
903
- > ## rfdc
904
- > License: MIT
905
- > By: David Mark Clements
906
- > Repository: git+https://github.com/davidmarkclements/rfdc.git
907
- >
908
- > > Copyright 2019 "David Mark Clements <david.mark.clements@gmail.com>"
909
- > >
910
- > > Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
911
- > > documentation files (the "Software"), to deal in the Software without restriction, including without limitation
912
- > > the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
913
- > > to permit persons to whom the Software is furnished to do so, subject to the following conditions:
914
- > >
915
- > > The above copyright notice and this permission notice shall be included in all copies or substantial portions
916
- > > of the Software.
917
- > >
918
- > > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
919
- > > TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
920
- > > THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
921
- > > CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
922
- > > IN THE SOFTWARE.
923
- >
924
- > ---------------------------------------
925
- >
926
881
  > ## string-collapse-leading-whitespace
927
882
  > License: MIT
928
883
  > By: Roy Revelt
@@ -930,7 +885,7 @@ Repository: git+https://github.com/visulima/visulima.git
930
885
  >
931
886
  > > MIT License
932
887
  > >
933
- > > Copyright © 2010-2025 Roy Revelt and other contributors
888
+ > > Copyright © 2010-2026 Roy Revelt and other contributors
934
889
  > >
935
890
  > > Permission is hereby granted, free of charge, to any person obtaining
936
891
  > > a copy of this software and associated documentation files (the
@@ -960,7 +915,7 @@ Repository: git+https://github.com/visulima/visulima.git
960
915
  >
961
916
  > > MIT License
962
917
  > >
963
- > > Copyright © 2010-2025 Roy Revelt and other contributors
918
+ > > Copyright © 2010-2026 Roy Revelt and other contributors
964
919
  > >
965
920
  > > Permission is hereby granted, free of charge, to any person obtaining
966
921
  > > a copy of this software and associated documentation files (the
@@ -990,7 +945,7 @@ Repository: git+https://github.com/visulima/visulima.git
990
945
  >
991
946
  > > MIT License
992
947
  > >
993
- > > Copyright © 2010-2025 Roy Revelt and other contributors
948
+ > > Copyright © 2010-2026 Roy Revelt and other contributors
994
949
  > >
995
950
  > > Permission is hereby granted, free of charge, to any person obtaining
996
951
  > > a copy of this software and associated documentation files (the
@@ -1028,35 +983,6 @@ Repository: git+https://github.com/visulima/visulima.git
1028
983
  > >
1029
984
  > > 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.
1030
985
  >
1031
- > ---------------------------------------
1032
- >
1033
- > ## tiny-invariant
1034
- > License: MIT
1035
- > By: Alex Reardon
1036
- > Repository: https://github.com/alexreardon/tiny-invariant.git
1037
- >
1038
- > > MIT License
1039
- > >
1040
- > > Copyright (c) 2019 Alexander Reardon
1041
- > >
1042
- > > Permission is hereby granted, free of charge, to any person obtaining a copy
1043
- > > of this software and associated documentation files (the "Software"), to deal
1044
- > > in the Software without restriction, including without limitation the rights
1045
- > > to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1046
- > > copies of the Software, and to permit persons to whom the Software is
1047
- > > furnished to do so, subject to the following conditions:
1048
- > >
1049
- > > The above copyright notice and this permission notice shall be included in all
1050
- > > copies or substantial portions of the Software.
1051
- > >
1052
- > > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1053
- > > IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1054
- > > FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1055
- > > AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1056
- > > LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1057
- > > OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1058
- > > SOFTWARE.
1059
- >
1060
986
  >
1061
987
  >
1062
988
  >
package/README.md CHANGED
@@ -663,7 +663,7 @@ The visulima package is open-sourced software licensed under the [MIT][license]
663
663
  [npm-downloads]: https://www.npmjs.com/package/@visulima/cerebro
664
664
  [prs-welcome-badge]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=for-the-badge
665
665
  [prs-welcome]: https://github.com/visulima/visulima/blob/main/.github/CONTRIBUTING.md
666
- [chat-badge]: https://img.shields.io/discord/932323359193186354.svg?style=for-the-badge
667
- [chat]: https://discord.gg/TtFJY8xkFK
666
+ [chat-badge]: https://img.shields.io/discord/902465130518949899.svg?style=for-the-badge
667
+ [chat]: https://discord.gg/eajEZvk2PG
668
668
  [typescript-badge]: https://img.shields.io/badge/Typescript-294E80.svg?style=for-the-badge&logo=typescript
669
669
  [typescript-url]: https://www.typescriptlang.org/
@@ -1,4 +1,4 @@
1
- import { C as Command } from "../packem_shared/command.d-CLlirnwR.js";
1
+ import { C as Command } from "../packem_shared/command.d-Dz7hkMI0.js";
2
2
  import '@visulima/tabular';
3
3
  /**
4
4
  * Generates shell completion scripts for the CLI application.
@@ -1,4 +1,4 @@
1
- import { O as OptionDefinition, A as ArgumentDefinition, C as Command, T as Toolbox } from "../packem_shared/command.d-CLlirnwR.js";
1
+ import { O as OptionDefinition, A as ArgumentDefinition, C as Command, T as Toolbox } from "../packem_shared/command.d-Dz7hkMI0.js";
2
2
  import '@visulima/tabular';
3
3
  declare class HelpCommand<TLogger extends Console = Console> implements Command<OptionDefinition<string>, TLogger> {
4
4
  argument: ArgumentDefinition<string>;
@@ -1 +1 @@
1
- import{inverse as d,cyan as f,green as h,yellow as y}from"@visulima/colorize";import{t as v,c as b,f as E}from"../packem_shared/format-positional-usage-DWL9qN10.js";const N=[{defaultValue:"32",description:"Controls the verbosity level of output. Valid values: '16' (quiet), '32' (normal), '64' (verbose), '128' (debug)",name:"CEREBRO_OUTPUT_LEVEL",type:String},{description:"Sets the minimum required Node.js version. Overrides the default minimum version check",name:"CEREBRO_MIN_NODE_VERSION",type:Number},{defaultValue:!1,description:"When set, disables the update notifier check",name:"NO_UPDATE_NOTIFIER",type:Boolean},{description:"Standard Node.js environment variable. When set to 'test', disables update notifier",name:"NODE_ENV",type:String},{defaultValue:!1,description:"When set, enables debug output (same as --debug flag)",name:"DEBUG",type:Boolean},{description:"Sets the terminal width for table rendering. Useful for testing and consistent output",name:"CEREBRO_TERMINAL_WIDTH",type:Number}],$="__Other",C=r=>r.charAt(0).toUpperCase()+r.slice(1),w=(r,s,l,o)=>{r.debug("no command given, printing general help...");let m=[...new Set(l.values())].filter(t=>!t.hidden);o&&(m=m.filter(t=>t.group===o));const e=m.reduce((t,i)=>{const p=i.group??$;return t[p]??=[],t[p].push(i),t},{}),a=t=>t.map(i=>{let p="";typeof i.alias=="string"?p=i.alias:Array.isArray(i.alias)&&(p=i.alias.join(", ")),p!==""&&(p=` [${p}]`);let u=i.name;return i.commandPath&&i.commandPath.length>0&&(u=`${i.commandPath.join(" ")} ${i.name}`),[`${h(u)}${p}`,i.description??""]});(r.raw??r.log)(b([{content:`${f(s.getCliName())} ${h("<command>")} [positional arguments] ${y("[options]")}`,header:d.cyan(" Usage ")},...Object.keys(e).map(t=>{const i=o?` ${C(o)}`:"";return{content:a(e[t]),header:t===$||o?d.green(` Available${i} Commands `):` ${d.green(` ${C(t)} `)}`}}),l.has("help")?{header:d.yellow(" Command Options "),optionList:l.get("help").options?.filter(t=>!t.hidden)}:void 0,{header:d.yellow(" Global Options "),optionList:s.getGlobalOptions()},{content:N.filter(t=>!t.hidden).map(t=>[t.name,t.description??""]),header:d.magenta(" Environment Variables ")},{content:`Run "${f(s.getCliName())} ${h("help <command>")}" or "${f(s.getCliName())} ${h("<command>")} ${y("--help")}" for help with a specific command.`,raw:!0}].filter(Boolean)))},P=(r,s)=>{const l=[];for(const o of r.values()){if(o.hidden)continue;const m=o.commandPath??[];if(m.length!==s.length)continue;let e=!0;for(const[a,t]of s.entries())if(m[a]!==t){e=!1;break}e&&l.push(o)}return l},O=(r,s,l,o)=>{const m=l.join(" "),e=[{content:`${f(s.getCliName())} ${h(m)} ${h("<subcommand>")} [positional arguments] ${y("[options]")}`,header:d.cyan(" Usage ")},{content:o.map(a=>{const t=[...a.commandPath??[],a.name].join(" ");return[h(t),a.description??""]}),header:d.green(" Subcommands ")},{header:d.yellow(" Global Options "),optionList:s.getGlobalOptions()},{content:`Run "${f(s.getCliName())} ${h(`${m} <subcommand>`)} ${y("--help")}" for help with a specific subcommand.`,raw:!0}];(r.raw??r.log)(b(e))},A=(r,s,l,o,m)=>{let e=m??l.get(o);if(!e)for(const n of l.values()){const c=n.commandPath?[...n.commandPath,n.name]:[n.name];if(c.at(-1)===o||c.join(" ")===o){e=n;break}}if(!e){const n=o.split(" ").filter(Boolean),c=n.length>0?P(l,n):[];if(c.length>0){O(r,s,n,c);return}r.error(`Command "${o}" not found`);return}const a=[],i=(e.commandPath?[...e.commandPath,e.name]:[e.name]).join(" ");a.push({content:`${f(s.getCliName())} ${h(i)}${E(e)}${e.options?" [options]":""}`,header:d.cyan(" Usage ")}),e.description&&a.push({content:e.description,header:d.green(" Description ")});const p=(e.argument?[e.argument]:e.arguments??[]).filter(n=>!n.hidden);if(p.length>0&&a.push({header:"Command Positional Arguments",isArgument:!0,optionList:p}),Array.isArray(e.options)&&e.options.length>0&&a.push({header:d.yellow(" Command Options "),optionList:e.options.filter(n=>!n.hidden)}),a.push({header:d.yellow(" Global Options "),optionList:s.getGlobalOptions()}),Array.isArray(e.env)&&e.env.length>0){const n=e.env.filter(c=>!c.hidden);n.length>0&&a.push({content:n.map(c=>[c.name,c.description??""]),header:d.magenta(" Environment Variables ")})}if(e.alias!==void 0&&e.alias.length>0){let n=e.alias;typeof e.alias=="string"&&(n=[e.alias]),a.splice(1,0,{content:n,header:"Alias(es)"})}Array.isArray(e.examples)&&e.examples.length>0&&a.push({content:e.examples,header:"Examples"});const u=[...e.commandPath??[],e.name],g=P(l,u);g.length>0&&a.push({content:g.map(n=>{const c=[...n.commandPath??[],n.name].join(" ");return[h(c),n.description??""]}),header:d.green(" Subcommands ")}),(r.raw??r.log)(b(a))};class S{argument={description:"Command to show help for (subcommand path supported, e.g. `cli help docker build`)",name:"command",type:String};name="help";options=[{description:"Display only the specified group",name:"group",type:String}];commands;constructor(s){this.commands=s}execute(s){const{argument:l,command:o,commandName:m,logger:e,options:a,runtime:t}=s,{footer:i,header:p}=t.getCommandSection();p&&(e.raw??e.log)(v(p));const u=m==="help"&&Array.isArray(l)&&l.length>0?l.join(" "):void 0;if(m==="help"&&u===void 0)w(e,t,this.commands,typeof a?.group=="string"?a.group:void 0);else{const g=u!==void 0||o===void 0||o.name==="help"?void 0:o;A(e,t,this.commands,u??m,g)}i&&(e.raw??e.log)(v(i))}}export{S as default};
1
+ import{inverse as d,cyan as f,green as h,yellow as y}from"@visulima/colorize";import{t as v,c as b,f as E}from"../packem_shared/format-positional-usage-DWL9qN10.js";const N=[{defaultValue:"32",description:"Controls the verbosity level of output. Valid values: '16' (quiet), '32' (normal), '64' (verbose), '128' (debug)",name:"CEREBRO_OUTPUT_LEVEL",type:String},{description:"Sets the minimum required Node.js version. Overrides the default minimum version check",name:"CEREBRO_MIN_NODE_VERSION",type:Number},{defaultValue:!1,description:"When set, disables the update notifier check",name:"NO_UPDATE_NOTIFIER",type:Boolean},{description:"Standard Node.js environment variable. When set to 'test', disables update notifier",name:"NODE_ENV",type:String},{defaultValue:!1,description:"When set, enables debug output (same as --debug flag)",name:"DEBUG",type:Boolean},{description:"Sets the terminal width for table rendering. Useful for testing and consistent output",name:"CEREBRO_TERMINAL_WIDTH",type:Number}],$="__Other",C=r=>r.charAt(0).toUpperCase()+r.slice(1),w=(r,s,l,o)=>{r.debug("no command given, printing general help...");let m=[...new Set(l.values())].filter(t=>!t.hidden);o&&(m=m.filter(t=>t.group===o));const e=m.reduce((t,i)=>{const p=i.group??$;return t[p]??=[],t[p].push(i),t},{}),a=t=>t.map(i=>{let p="";typeof i.alias=="string"?p=i.alias:Array.isArray(i.alias)&&(p=i.alias.join(", ")),p!==""&&(p=` [${p}]`);let u=i.name;return i.commandPath&&i.commandPath.length>0&&(u=`${i.commandPath.join(" ")} ${i.name}`),[`${h(u)}${p}`,i.description??""]});(r.raw??r.log)(b([{content:`${f(s.getCliName())} ${h("<command>")} [positional arguments] ${y("[options]")}`,header:d.cyan(" Usage ")},...Object.keys(e).map(t=>{const i=o?` ${C(o)}`:"";return{content:a(e[t]),header:t===$||o?d.green(` Available${i} Commands `):` ${d.green(` ${C(t)} `)}`}}),l.has("help")?{header:d.yellow(" Command Options "),optionList:l.get("help").options?.filter(t=>!t.hidden)}:void 0,{header:d.yellow(" Global Options "),optionList:s.getGlobalOptions()},{content:N.filter(t=>!t.hidden).map(t=>[t.name,t.description??""]),header:d.magenta(" Environment Variables ")},{content:`Run "${f(s.getCliName())} ${h("help <command>")}" or "${f(s.getCliName())} ${h("<command>")} ${y("--help")}" for help with a specific command.`,raw:!0}].filter(Boolean)))},P=(r,s)=>{const l=[];for(const o of r.values()){if(o.hidden)continue;const m=o.commandPath??[];if(m.length<s.length)continue;let e=!0;for(const[a,t]of s.entries())if(m[a]!==t){e=!1;break}e&&l.push(o)}return l},O=(r,s,l,o)=>{const m=l.join(" "),e=[{content:`${f(s.getCliName())} ${h(m)} ${h("<subcommand>")} [positional arguments] ${y("[options]")}`,header:d.cyan(" Usage ")},{content:o.map(a=>{const t=[...a.commandPath??[],a.name].join(" ");return[h(t),a.description??""]}),header:d.green(" Subcommands ")},{header:d.yellow(" Global Options "),optionList:s.getGlobalOptions()},{content:`Run "${f(s.getCliName())} ${h(`${m} <subcommand>`)} ${y("--help")}" for help with a specific subcommand.`,raw:!0}];(r.raw??r.log)(b(e))},A=(r,s,l,o,m)=>{let e=m??l.get(o);if(!e)for(const n of l.values()){const c=n.commandPath?[...n.commandPath,n.name]:[n.name];if(c.at(-1)===o||c.join(" ")===o){e=n;break}}if(!e){const n=o.split(" ").filter(Boolean),c=n.length>0?P(l,n):[];if(c.length>0){O(r,s,n,c);return}r.error(`Command "${o}" not found`);return}const a=[],i=(e.commandPath?[...e.commandPath,e.name]:[e.name]).join(" ");a.push({content:`${f(s.getCliName())} ${h(i)}${E(e)}${e.options?" [options]":""}`,header:d.cyan(" Usage ")}),e.description&&a.push({content:e.description,header:d.green(" Description ")});const p=(e.argument?[e.argument]:e.arguments??[]).filter(n=>!n.hidden);if(p.length>0&&a.push({header:"Command Positional Arguments",isArgument:!0,optionList:p}),Array.isArray(e.options)&&e.options.length>0&&a.push({header:d.yellow(" Command Options "),optionList:e.options.filter(n=>!n.hidden)}),a.push({header:d.yellow(" Global Options "),optionList:s.getGlobalOptions()}),Array.isArray(e.env)&&e.env.length>0){const n=e.env.filter(c=>!c.hidden);n.length>0&&a.push({content:n.map(c=>[c.name,c.description??""]),header:d.magenta(" Environment Variables ")})}if(e.alias!==void 0&&e.alias.length>0){let n=e.alias;typeof e.alias=="string"&&(n=[e.alias]),a.splice(1,0,{content:n,header:"Alias(es)"})}Array.isArray(e.examples)&&e.examples.length>0&&a.push({content:e.examples,header:"Examples"});const u=[...e.commandPath??[],e.name],g=P(l,u);g.length>0&&a.push({content:g.map(n=>{const c=[...n.commandPath??[],n.name].join(" ");return[h(c),n.description??""]}),header:d.green(" Subcommands ")}),(r.raw??r.log)(b(a))};class S{argument={description:"Command to show help for (subcommand path supported, e.g. `cli help docker build`)",name:"command",type:String};name="help";options=[{description:"Display only the specified group",name:"group",type:String}];commands;constructor(s){this.commands=s}execute(s){const{argument:l,command:o,commandName:m,logger:e,options:a,runtime:t}=s,{footer:i,header:p}=t.getCommandSection();p&&(e.raw??e.log)(v(p));const u=m==="help"&&Array.isArray(l)&&l.length>0?l.join(" "):void 0;if(m==="help"&&u===void 0)w(e,t,this.commands,typeof a?.group=="string"?a.group:void 0);else{const g=u!==void 0||o===void 0||o.name==="help"?void 0:o;A(e,t,this.commands,u??m,g)}i&&(e.raw??e.log)(v(i))}}export{S as default};
@@ -1,4 +1,4 @@
1
- import { C as Command } from "../packem_shared/command.d-CLlirnwR.js";
1
+ import { C as Command } from "../packem_shared/command.d-Dz7hkMI0.js";
2
2
  import '@visulima/tabular';
3
3
  /**
4
4
  * Generates README documentation for cerebro CLI commands.
@@ -1,4 +1,4 @@
1
- import { C as Command } from "../packem_shared/command.d-CLlirnwR.js";
1
+ import { C as Command } from "../packem_shared/command.d-Dz7hkMI0.js";
2
2
  import '@visulima/tabular';
3
3
  declare const _default: Command;
4
4
  export { _default as default };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { a as CerebroFs, b as CommandSection, O as OptionDefinition, T as Toolbox, c as CommandInput, P as Plugin, d as PluginManager, C as Command, e as CliRunOptions, R as RunCommandOptions, f as CommandExecute, g as Cli$1, h as OptionDefinitionRecord, E as EnvDefinitionRecord, A as ArgumentDefinition, L as LazyCommandModule } from "./packem_shared/command.d-CLlirnwR.js";
2
- export type { i as AnyCommandInput, j as CerebroProcess, k as EnvDefinition, l as OutputType, m as PluginContext, V as VERBOSITY_LEVEL } from "./packem_shared/command.d-CLlirnwR.js";
1
+ import { a as CerebroFs, b as CommandSection, O as OptionDefinition, T as Toolbox, c as CommandInput, P as Plugin, d as PluginManager, C as Command, e as CliRunOptions, R as RunCommandOptions, f as CommandExecute, g as Cli$1, h as OptionDefinitionRecord, E as EnvDefinitionRecord, A as ArgumentDefinition, L as LazyCommandModule } from "./packem_shared/command.d-Dz7hkMI0.js";
2
+ export type { i as AnyCommandInput, j as CerebroProcess, k as EnvDefinition, l as OutputType, m as PluginContext, V as VERBOSITY_LEVEL } from "./packem_shared/command.d-Dz7hkMI0.js";
3
3
  import { V as VisulimaError } from "./packem_shared/index.d-CnnVYgSZ.js";
4
4
  import '@visulima/tabular';
5
5
  type CliOptions<T extends Console = Console> = {
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{Cli as o}from"./packem_shared/Cerebro-Dh8am0pz.js";import{VERBOSITY_DEBUG as E,VERBOSITY_NORMAL as s,VERBOSITY_QUIET as p,VERBOSITY_VERBOSE as u}from"./packem_shared/VERBOSITY_DEBUG-D7HfSD5l.js";import{default as l}from"./packem_shared/defineCommand-C_isHeEs.js";import{default as d}from"./packem_shared/InvalidArgumentChoiceError-BpovuqrZ.js";import{default as B}from"./packem_shared/MissingArgumentError-D78kza2a.js";import{default as O}from"./packem_shared/SurplusArgumentError-BLwT9lo0.js";import{lazyNamed as S}from"./packem_shared/lazyNamed-BKSCmVsV.js";import{c as C}from"./packem_shared/VisulimaError-BDqtOVL5-Db_MJ_p7.js";const a=(r,e)=>new o(r,e);export{o as Cerebro,d as InvalidArgumentChoiceError,B as MissingArgumentError,O as SurplusArgumentError,E as VERBOSITY_DEBUG,s as VERBOSITY_NORMAL,p as VERBOSITY_QUIET,u as VERBOSITY_VERBOSE,C as VisulimaError,a as createCerebro,l as defineCommand,S as lazyNamed};
1
+ import{Cli as o}from"./packem_shared/Cerebro-B02RU3RC.js";import{VERBOSITY_DEBUG as E,VERBOSITY_NORMAL as s,VERBOSITY_QUIET as p,VERBOSITY_VERBOSE as u}from"./packem_shared/VERBOSITY_DEBUG-D7HfSD5l.js";import{default as l}from"./packem_shared/defineCommand-C_isHeEs.js";import{default as d}from"./packem_shared/InvalidArgumentChoiceError-BpovuqrZ.js";import{default as B}from"./packem_shared/MissingArgumentError-D78kza2a.js";import{default as O}from"./packem_shared/SurplusArgumentError-BLwT9lo0.js";import{lazyNamed as S}from"./packem_shared/lazyNamed-BKSCmVsV.js";import{c as C}from"./packem_shared/VisulimaError-BDqtOVL5-Db_MJ_p7.js";const a=(r,e)=>new o(r,e);export{o as Cerebro,d as InvalidArgumentChoiceError,B as MissingArgumentError,O as SurplusArgumentError,E as VERBOSITY_DEBUG,s as VERBOSITY_NORMAL,p as VERBOSITY_QUIET,u as VERBOSITY_VERBOSE,C as VisulimaError,a as createCerebro,l as defineCommand,S as lazyNamed};
@@ -0,0 +1,4 @@
1
+ import{createRequire as ct}from"node:module";import{VERBOSITY_DEBUG as V,POSITIONALS_KEY as oe,VERBOSITY_NORMAL as le,VERBOSITY_QUIET as vt,VERBOSITY_VERBOSE as At}from"./VERBOSITY_DEBUG-D7HfSD5l.js";import{C as b}from"./cerebro-error-Dv3FuXO8.js";import{c as re,d as we,o as be,e as F,a as Ct,b as Nt,f as bt,h as Ot,i as _t}from"./runtime-process-BN-eTlwy.js";import{c as ee}from"./VisulimaError-BDqtOVL5-Db_MJ_p7.js";import Et from"./InvalidArgumentChoiceError-BpovuqrZ.js";import xt from"./MissingArgumentError-D78kza2a.js";import kt from"./SurplusArgumentError-BLwT9lo0.js";import{X as It,O as $t,H as ie,c as q,M as X,k as P,F as ce,m as Oe,Q as _e,Y as Pt,U as Ee,$ as Lt,W as xe,d as ke,C as Ie,D as Ut,G as Mt,P as Tt,l as St,y as Dt,z as Vt,Z as jt,b as Rt,f as Bt,q as zt,j as Ft,v as Wt,J as qt,K as Kt,h as Gt,V as Ht}from"./constants-BKuEbBw1-BRv49X2l.js";import{E as Xt,f as Yt}from"./format-user-facing-error-Cb7ySnUi.js";import{distance as Jt}from"fastest-levenshtein";let ht;const ut=t=>(ht??=ct(import.meta.url))(t),Z=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,pt=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 ut(t)},{writeFile:ft,stat:dt,rm:gt,readFile:Ne,readdir:mt,mkdir:wt,access:yt}=pt("node:fs/promises"),te=[{alias:"v",description:"Turn on verbose output",group:"global",name:"verbose",type:Boolean},{description:"Turn on debugging output",group:"global",name:"debug",type:Boolean},{alias:"h",description:"Print out helpful usage information",group:"global",name:"help",type:Boolean},{alias:"q",description:"Silence output",group:"global",name:"quiet",type:Boolean},{alias:"V",description:"Print version info",group:"global",name:"version",type:Boolean},{description:"Turn off colored output",group:"global",name:"no-color",type:Boolean},{description:"Force colored output",group:"global",name:"color",type:Boolean}];class B extends b{commandName;constructor(e,n=[]){const s=`Command "${e}" not found${n.length>0?`. Did you mean: ${n.join(", ")}?`:""}`;super(s,"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(", ")}`)}}class Ge extends b{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}`}}class Zt extends b{unknownOptions;constructor(e,n){const s=e.join(", "),i=`Found unknown ${e.length===1?"option":"options"}: ${s}`;super(i,"UNKNOWN_OPTION",{suggestions:n,unknownOptions:e}),this.name="UnknownOptionError",this.unknownOptions=e,n&&n.length>0&&(this.hint=`Did you mean: ${n.join(", ")}?`)}}class Qt extends b{pluginName;constructor(e,n,s){super(`Plugin "${e}" error: ${n}`,"PLUGIN_ERROR",{originalError:s,pluginName:e}),this.name="PluginError",this.pluginName=e,s&&(this.cause=s)}}class en{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`);re().CEREBRO_OUTPUT_LEVEL===String(V)&&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 s of n)if(typeof s.init=="function"){this.logger.debug(`initializing plugin: ${s.name}`);try{await s.init(e)}catch(i){const o=new Qt(s.name,`Failed to initialize: ${i instanceof Error?i.message:String(i)}`,i instanceof Error?i:void 0);throw this.logger.error(o.message),o}}this.initialized=!0}async executeLifecycle(e,n,s){if(!this.initialized)throw new Error("PluginManager not initialized");if(this.plugins.size===0)return;const i=this.getDependencyOrder();for(const o of i){const l=o[e];if(typeof l=="function"){this.logger.debug(`executing ${e} hook for plugin: ${o.name}`);try{await(e==="afterCommand"?l(n,s):l(n))}catch(a){throw this.logger.error(`Error in ${e} hook for plugin "${o.name}":`,a),a}}}}async executeErrorHandlers(e,n){if(!this.initialized||this.plugins.size===0)return;const s=this.getDependencyOrder();for(const i of s)if(typeof i.onError=="function"){this.logger.debug(`executing error handler for plugin: ${i.name}`);try{await i.onError(e,n)}catch(o){this.logger.error(`Error in error handler for plugin "${i.name}":`,o)}}}getDependencyOrder(){if(this.cachedDependencyOrder!==void 0)return this.cachedDependencyOrder;const e=[],n=new Set,s=new Set,i=o=>{if(n.has(o))return;if(s.has(o))throw new Error(`Circular dependency detected involving plugin "${o}"`);const l=this.plugins.get(o);if(!l)throw new Error(`Plugin "${o}" not found`);if(s.add(o),l.dependencies)for(const a of l.dependencies)i(a);s.delete(o),n.add(o),e.push(l)};for(const o of this.plugins.keys())i(o);return this.cachedDependencyOrder=e,e}validateDependencies(){for(const e of this.plugins.values())if(e.dependencies){for(const n of e.dependencies)if(!this.plugins.has(n))throw new Error(`Plugin "${e.name}" depends on "${n}" which is not registered`)}}}const Q=t=>t.type?.name==="Boolean",tn=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},$e=t=>(Q(t)||(t.typeLabel=t.typeLabel??tn(t),t.defaultOption&&(t.typeLabel=`${t.typeLabel} (D)`),t.required&&(t.typeLabel=`${t.typeLabel} (R)`)),t),nn=new RegExp(/^-([^\d-])$/),sn=new RegExp(/^--(\S+)/),on=new RegExp(/^-([^\d-]{2,})$/),rn=t=>nn.test(t)||sn.test(t)||on.test(t),an=(t,e)=>{const n=e[0]&&rn(e[0])||e.length===0?null:e.shift()??null;if(!t.includes(n)){const s=new Error(`Command not recognised: ${String(n)}`);throw s.command=n,s.name="INVALID_COMMAND",s}return{argv:e,command:n}};class Ae extends ee{optionName;value;constructor(e,n,s){super({hint:`Pass a valid ${s} value for '${e}'.`,message:`Invalid ${s} value '${n}' for option '${e}'`,name:"INVALID_VALUE",title:"Invalid Value"}),this.optionName=e,this.value=n,Object.setPrototypeOf(this,Ae.prototype)}}let ln=class He extends ee{optionName;constructor(e){super({cause:void 0,hint:`Remove the duplicate option '${e}' from your command line arguments.`,location:void 0,message:`Option '${e}' is already set`,name:"ALREADY_SET",stack:void 0,title:"Option Already Set"}),this.optionName=e,Object.setPrototypeOf(this,He.prototype)}},Pe=class Xe extends ee{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,Xe.prototype)}};class Ce extends ee{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,Ce.prototype)}}let L=class Ye extends ee{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,Ye.prototype)}};const K=t=>t===Boolean||typeof t=="function"&&t.name==="Boolean",ye=t=>t===Number||typeof t=="function"&&t.name==="Number",Le=t=>t===String||typeof t=="function"&&t.name==="String",Ue=(t,e,n)=>{const s=Number(t);if(e&&Number.isNaN(s)&&String(t).trim().toLowerCase()!=="nan")throw new Ae(n??"",String(t),"Number");return s},cn=(t,e,n={})=>{const{optionName:s,strictTypes:i}=n;return Array.isArray(t)?K(e)?t.map(Boolean):ye(e)?t.map(o=>Ue(o,i,s)):Le(e)?t.map(String):t.map(o=>e(String(o))):t===null?null:K(e)?!!t:ye(e)?Ue(t,i,s):Le(e)?typeof t=="string"?t:String(t):e(typeof t=="string"?t:String(t))},x=(t,e,n,...s)=>{t&&console.debug(`[command-line-args:${n}] ${e}`,...s)},hn=/-([a-z])/g,un=/^\d+$/,pn=t=>t.codePointAt(0)===95,Me=(t,e)=>Array.isArray(t)?[...t,...e]:[t,...e],Te=t=>t==="__proto__"||t==="constructor"||t==="prototype",he=(t,e,n,s=!1)=>{t[e]===void 0?t[e]=s?[n]:n:s&&Array.isArray(t[e])?t[e].push(n):t[e]=[t[e],n]},Se=(t,e,n,s,i)=>{let o=e.get(t)??n.get(t);if(!o&&s){const l=t.toLowerCase();o=s.get(l)??i?.get(l)}return o},fn=(t,e,n,s)=>{const i=n.debug??!1;x(i,"resolveArgs called with options:","resolver",{partial:n.partial,stopAtFirstUnknown:n.stopAtFirstUnknown}),x(i,"Starting argument resolution","resolver"),x(i,"Tokens:","resolver",t),x(i,"Definitions:","resolver",e),x(i,"Processing tokens...","resolver");const o=new Map,l=new Map,a=n.caseInsensitive?new Map:void 0,u=n.caseInsensitive?new Map:void 0,r=n.camelCase?new Map:void 0,c=n.camelCase?new Map:void 0;for(const f of e)if(o.set(f.name,f),f.alias&&l.set(f.alias,f),n.caseInsensitive&&a&&(a.set(f.name.toLowerCase(),f),f.alias&&u&&u.set(f.alias.toLowerCase(),f)),n.camelCase&&r&&c){const w=f.name.replaceAll(hn,(v,I)=>I.toUpperCase());r.set(f.name,w),c.set(w,f.name)}const p=Object.create(null),h=Object.create(null),m=[],g=[],y=new Set;let A=!1;const d=e.find(f=>f.defaultOption),C=e.some(f=>f.group),O=e.find(f=>ye(f.type));for(let f=0;f<t.length;f++){const w=t[f];if(w.kind==="option-terminator"){p._unknown=s.slice(w.index),A=!0;break}if(w.kind==="option"&&w.name){let v=Se(w.name,o,l,a,u);!v&&w.value===void 0&&O&&un.test(w.name)&&(v=O,w.value=w.name,w.name=O.name);let I=!1;if(!v&&n.negation&&w.value===void 0&&w.name.startsWith("no-")){const _=w.name.slice(3),M=Se(_,o,l,a,u);M?.type&&K(M.type)&&(v=M,I=!0)}const N=v?v.name:w.name,$=v?.multiple,U=v?.lazyMultiple;if(Object.hasOwn(h,N)&&h[N]!==void 0&&!$&&!U&&!n.partial)throw new ln(N);if(!v&&n.partial){const _=w.rawName??`--${w.name}${w.value!==void 0&&w.inlineValue?`=${w.value}`:""}`;m.push({index:w.index,value:_});continue}if(!v&&n.stopAtFirstUnknown){p._unknown=s.slice(w.index);break}if(!v&&!n.partial)throw new Pe(w.name);if(w.value===void 0){const _=t[f+1],M=_?.kind==="option"&&!("name"in _)&&_.value!==void 0,S=_&&v&&!(v.type&&K(v.type))&&(_.kind==="positional"||M),lt=v&&v.defaultOption&&!v.multiple&&!v.lazyMultiple;if(S&&(!v?.defaultOption||lt))if($){let D=f+1;const ae=[];for(;D<t.length&&(t[D].kind==="positional"||t[D].kind==="option"&&!("name"in t[D])&&t[D].value!==void 0);)ae.push(t[D].value),y.add(t[D].index),D++;h[N]=h[N]===void 0?ae:Me(h[N],ae),f=D-1}else U?(he(h,N,_.value,!0),y.add(_.index),f++):(h[N]=_.value,y.add(_.index),f++);else v?.type&&K(v.type)?he(h,N,!I,$):($||U)&&h[N]!==void 0?he(h,N,null,!0):h[N]=$?[]:null}else{let{value:_}=w;if(v?.type&&K(v.type))switch(_){case"":{if(n.partial){const S=`${w.rawName??`--${w.name}`}${w.value?`=${w.value}`:""}`;g.push({index:w.index,value:S}),_=!0}else throw new Pe(w.name);break}case"false":{_=!1;break}case"true":{_=!0;break}default:_=!0}const M=[_];if($){let S=f+1;for(;S<t.length&&t[S].kind==="positional";)M.push(t[S].value),y.add(t[S].index),S++;f=S-1}h[N]===void 0?h[N]=$||U?M:_:$||U?h[N]=Me(h[N],M):h[N]=_}}else if(w.kind==="positional"&&n.stopAtFirstUnknown&&!y.has(w.index)&&!d){x(i,`Found unconsumed positional token at index ${String(w.index)}, stopping processing`,"resolver"),p._unknown=s.slice(w.index);break}}for(const[f,w]of Object.entries(h)){const v=o.get(f);v&&(v.multiple||v.lazyMultiple)&&!Array.isArray(w)&&(h[f]=[w])}const k=f=>f.kind==="option"&&!o.has(f.name??"")&&!l.has(f.name??"")&&(!n.caseInsensitive||!a?.has(f.name?.toLowerCase()??"")&&!u?.has(f.name?.toLowerCase()??""));let E=-1,H=Number.POSITIVE_INFINITY;if(n.stopAtFirstUnknown&&!A&&(E=t.findIndex(f=>k(f)),E!==-1&&(H=t[E].index)),d){const f=[],w=[];for(const v of t)v.kind==="positional"&&!y.has(v.index)&&v.index<H&&(f.push(v.value),w.push(v));if(f.length>0){const v=h[d.name],I=d.multiple??d.lazyMultiple;v===void 0?I?(w.forEach(N=>y.add(N.index)),h[d.name]=f):(y.add(w[0].index),h[d.name]=f[0]):I&&(w.forEach(N=>y.add(N.index)),h[d.name]=Array.isArray(v)?[...f,...v]:[...f,v])}}if(!n.partial){for(const f of t)if(f.kind==="positional"&&!y.has(f.index))throw new Ce(s[f.index])}if(n.partial&&!n.stopAtFirstUnknown){const f=[...m];for(const w of g)f.push({index:w.index,value:w.value});for(const w of t)w.kind==="positional"&&!y.has(w.index)&&f.push({index:w.index,value:s[w.index]});f.length>0&&(f.sort((w,v)=>w.index-v.index),p._unknown=f.map(w=>w.value))}if(n.stopAtFirstUnknown&&!A){const f=t.findIndex(v=>v.kind==="positional"&&!y.has(v.index));let w=-1;if(E!==-1&&f!==-1?w=Math.min(E,f):E!==-1?w=E:f!==-1&&(w=f),w>=0){const v=t[w].index;p._unknown=s.slice(v)}}for(const[f,w]of Object.entries(h)){const v=n.camelCase?r?.get(f)??f:f,I=o.get(f);I?.type?p[v]=cn(w,I.type,{optionName:I.name,strictTypes:n.strictTypes}):p[v]=w===void 0?null:w}for(const f of e){const w=n.camelCase?r?.get(f.name)??f.name:f.name;!(w in p)&&f.defaultValue!==void 0&&(f.multiple??f.lazyMultiple?p[w]=Array.isArray(f.defaultValue)?[...f.defaultValue]:[f.defaultValue]:p[w]=f.defaultValue)}if(C){const f={},w={},v={};for(const N of e)if(N.group){const $=Array.isArray(N.group)?N.group:[N.group];for(const U of $)Te(U)||(f[U]??={})}for(const N of Object.keys(p))if(!pn(N)){w[N]=p[N];let $=N;n.camelCase&&($=c?.get(N)??N);const U=o.get($);if(U?.group){const _=Array.isArray(U.group)?U.group:[U.group];for(const M of _)Te(M)||f[M]&&(f[M][N]=p[N])}else v[N]=p[N]}const I={_all:w};for(const[N,$]of Object.entries(f))I[N]=$;Object.keys(v).length>0&&(I._none=v),p._unknown&&(I._unknown=p._unknown),Object.keys(p).forEach(N=>delete p[N]),Object.assign(p,I)}const T=Object.defineProperties({},Object.getOwnPropertyDescriptors(p));return x(i,"Final parsed result:","resolver",T),T},Je="-",J=Je.codePointAt(0),G="=",dn=G.codePointAt(0),gn="--",mn=Je,wn="--",Ze=t=>t.length>2&&t.startsWith(wn),yn=t=>Ze(t)&&!t.includes(G,3),vn=t=>Ze(t)&&t.includes(G,3),An=t=>{if(t.length!==2||t.codePointAt(0)!==J||t.codePointAt(1)===J)return!1;const e=t.codePointAt(1);return e!==void 0&&(e<48||e>57)},Cn=t=>{if(t.length<=2||t.codePointAt(0)!==J||t.codePointAt(1)===J)return!1;const e=t.codePointAt(1);return!(e!==void 0&&e>=48&&e<=57)},Nn=t=>{const e=[];let n=0,s=[],i=0,o=-1,l=0;for(;i<s.length||n<t.length;){let a;if(i<s.length?(a=s[i],i++):(a=t[n],n++),l>0?l--:o++,a===gn){e.push({index:o,kind:"option-terminator"});const u=[...s.slice(i),...t.slice(n)],r=u.map((c,p)=>({index:o+p+1,kind:"positional",value:c}));e.push(...r),o+=u.length;break}if(An(a)){const u=a.charAt(1);e.push({index:o,kind:"option",name:u,rawName:a});continue}if(Cn(a)&&!a.includes(G)){const u=[];let r="",c=!1;for(let p=1;p<a.length;p++){const h=a.charAt(p);c?r+=h:h.codePointAt(0)===dn?c=!0:u.push(`${mn}${h}`)}if(c)if(u.length>0){const p=u.pop();u.push(`${p}=${r}`)}else u.push(r);s=i<s.length?[...u,...s.slice(i)]:u,i=0,l=u.length;continue}if(yn(a)){const u=a.slice(2);e.push({index:o,kind:"option",name:u,rawName:a});continue}if(vn(a)){const u=a.indexOf(G),r=a.slice(2,u),c=a.slice(u+1);e.push({index:o,inlineValue:!0,kind:"option",name:r,rawName:a,value:c});continue}if(a.length>2&&a.codePointAt(0)===J&&a.codePointAt(1)!==J&&a.includes(G)){const u=a.indexOf(G),r=a.charAt(1),c=a.slice(u+1);e.push({index:o,inlineValue:!0,kind:"option",name:r,rawName:a,value:c});continue}e.push({index:o,kind:"positional",value:a})}return e},bn=/\d/,On=t=>typeof t=="function",_n=(t,e,n)=>{const s=n?.debug??!1;x(s,"Validating definitions:","validation",t,"caseInsensitive:",e);const i=new Set,o=new Set,l=new Set,a=new Set;let u=0;for(const r of t){if(x(s,"Checking definition:","validation",r),!r.name)throw x(s,"Validation failed: name is required","validation"),new L("Invalid option definition: name is required");if(typeof r.name!="string")throw new L("Invalid option definition: name must be a string");if(r.name.trim()==="")throw new L("Invalid option definition: name cannot be empty");const c=e?r.name.toLowerCase():"";if(i.has(r.name)||e&&l.has(c))throw new L(`Invalid option definition: duplicate name '${r.name}'`);if(o.has(r.name)||e&&a.has(c))throw new L(`Invalid option definition: name '${r.name}' conflicts with an existing alias`);if(i.add(r.name),e&&l.add(c),r.alias!==void 0){if(typeof r.alias!="string")throw new L("Invalid option definition: alias must be a string");if(r.alias.length!==1)throw new L("Invalid option definition: alias must be a single character");if(bn.test(r.alias))throw new L("Invalid option definition: alias cannot be numeric");if(r.alias==="-")throw new L('Invalid option definition: alias cannot be "-"');const p=e?r.alias.toLowerCase():"";if(o.has(r.alias)||e&&a.has(p))throw new L(`Invalid option definition: duplicate alias '${r.alias}'`);if(i.has(r.alias)||e&&l.has(p))throw new L(`Invalid option definition: alias '${r.alias}' conflicts with an existing option name`);o.add(r.alias),e&&a.add(p)}if(r.defaultOption&&(u++,r.type!==void 0&&K(r.type)))throw new L("Invalid option definition: defaultOption cannot be Boolean type");if(r.type!==void 0&&!(r.type===Boolean||r.type===Number||r.type===String||typeof r.type=="function"&&On(r.type)))throw new L("Invalid option definition: invalid type")}if(u>1)throw x(s,"Validation failed: multiple defaultOptions not allowed","validation"),new L("Invalid option definition: multiple defaultOptions not allowed");x(s,"Validation completed successfully","validation")};function En(t,e={}){const n=e.debug??!1;x(n,"Starting command-line-args parsing","index"),x(n,"Options:","index",e);const s={...e};s.stopAtFirstUnknown&&(s.partial=!0);const i=Array.isArray(t)?t:[t];x(n,"Normalized definitions:","index",i),_n(i,s.caseInsensitive,n?s:void 0);let{argv:o}=s;o??=process.argv.slice(2),x(n,"Using argv:","index",o);let l=o;s.caseInsensitive&&(l=o.map(r=>{if(r.startsWith("--")){const c=r.indexOf("="),p=(c===-1?r.slice(2):r.slice(2,c)).toLowerCase();return c===-1?`--${p}`:`--${p}${r.slice(c)}`}if(r.startsWith("-")&&!r.startsWith("--")&&r.length>1){const c=r.indexOf("="),p=c===-1?r.slice(1):r.slice(1,c);if(!p)return r;const h=p.toLowerCase();return c===-1?`-${h}`:`-${h}${r.slice(c)}`}return r}));const a=Nn(l.map(String));x(n,"Tokenized arguments:","index",a);const u=fn(a,i,s,o);return x(n,"Command-line-args parsing completed","index"),u}class xn{result;argv;options;argument;args;command;commandName;env;logger;console;fs;process;runtime;rawUnknown;rawArgv;constructor(e,n){this.commandName=e,this.command=n}}class ue extends b{commandName;constructor(e,n,s){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.",s!==void 0&&(this.cause=s)}}const kn=/^-{1,2}(\w+)(=(.+))?$/,Qe=(t,e,n,s)=>{const i=kn.exec(t);if(i===null)return{};const o=i[1];if(!o)return{};const l=n&&s?n.get(o)??s.get(o):e.find(a=>a.name===o||a.alias===o);return l!==void 0?{argName:l.name,argValue:i[3],option:l}:{}},De=(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)},In=new Set(["0","1","false","true"]),$n=(t,e,n,s)=>{if(e.length===0||t.length===0)return{};const i=(o,l)=>{const{argName:a,argValue:u,option:r}=Qe(l,e,n,s),{lastOption:c}=o;return r&&Q(r)&&u&&a?o.partial[a]=De(u,r):o.lastName&&c&&Q(c)&&In.has(l)&&(o.partial[o.lastName]=De(l,c)),{lastName:a,lastOption:r,partial:o.partial}};return t.reduce(i,{partial:{}}).partial},Pn=new Set(["0","1","false","true"]),Ln=(t,e,n,s)=>{if(e.length===0||t.length===0)return t;const i=(o,l)=>{const{argValue:a,option:u}=Qe(l,e,n,s),{lastOption:r}=o;if(r&&Q(r)&&Pn.has(l)){const{args:p}=o;return{args:p.slice(0,-1)}}return u&&Q(u)&&a?{args:o.args}:{args:[...o.args,l],lastOption:u}};return t.reduce(i,{args:[]}).args},Ve=t=>{const e=new Map;for(const n of t){const s=e.get(n.name);s?e.set(n.name,{...s,...n}):e.set(n.name,n)}return[...e.values()]},Un=t=>{if(t===void 0)return;const e=t.toLowerCase().trim();return e==="true"||e==="1"||e==="yes"||e==="on"},Mn=(t,e)=>{if(!t.type)return e;if(e===void 0)return;if(t.type===Boolean||typeof t.type=="function"&&t.type.name==="Boolean")return Un(e);if(t.type===Number||typeof t.type=="function"&&t.type.name==="Number"){const o=Number.parseFloat(e);return Number.isNaN(o)?void 0:o}return t.type===String||typeof t.type=="function"&&t.type.name==="String"?e:t.type(e)},Tn=/_./g,Sn=/^[A-Z]/,Dn=t=>t.toLowerCase().replaceAll(Tn,e=>e[1]?.toUpperCase()??e).replace(Sn,e=>e.toLowerCase()),Vn=(t,e=re())=>{if(!t||t.length===0)return{};const n={};for(const s of t){const i=e[s.name],o=Mn(s,i),l=o===void 0?s.defaultValue:o,a=Dn(s.name);n[a]=l}return n},jn=/-([a-z])/g,et=t=>t.replaceAll(jn,(e,n)=>n.toUpperCase()),je=(t,e)=>t.type===void 0?e:t.type(e),Rn=(t,e)=>{const{choices:n}=t;if(!n||n.length===0)return[];const s=[];for(const i of e)n.includes(i)||s.push({choices:n,name:t.name,value:i});return s},Bn=(t,e)=>e&&t.defaultValue!==void 0&&!Array.isArray(t.defaultValue)?[t.defaultValue]:t.defaultValue,zn=(t,e)=>{const n={},s=[],i=[],o=t.length-1;let l=0;for(const[a,u]of t.entries()){const r=et(u.name),c=a===o&&u.multiple===!0,p=c?e.slice(a):e.slice(a,a+1);if(p.length===0){u.required===!0&&s.push(u.name),n[r]=Bn(u,c);continue}i.push(...Rn(u,p)),l=a+p.length,n[r]=c?p.map(h=>je(u,h)):je(u,p[0])}return{invalid:i,missing:s,resolved:n,surplus:e.slice(l)}},Fn=t=>{const e=new Map,n=new Map;for(const s of t)if(e.set(s.name,s),s.alias){const i=Array.isArray(s.alias)?s.alias:[s.alias];for(const o of i)n.set(o,s)}return{optionMapByAlias:n,optionMapByName:e}},tt=async t=>{if(typeof t.__resolvedExecute__=="function")return t.__resolvedExecute__;if(typeof t.loader!="function")throw new ue(t.name,"no execute or loader defined");let e;try{e=await t.loader()}catch(s){throw new ue(t.name,s instanceof Error?s.message:String(s),s)}const n=e.default;if(typeof n!="function")throw new ue(t.name,"loader did not return a module with a default-exported handler function");return t.__resolvedExecute__=n,n},Wn=(t,e,n,s,i,o=[])=>{const l=new xn(t.name,t),{_all:a,_unknown:u,positionals:r}=e,p=Object.keys(n).length>0?{...a,...n}:a;oe in p&&delete p[oe],l.argument=r?.[oe]??[],l.args={},l.rawUnknown=[...u??[]],l.rawArgv=[...o];const h=Object.keys(s).length>0;return l.options=h?{...p,...s}:p,l.env=Vn(t.env,i),l},qn=(t,e,n)=>{const s=t.options??[],i=s.length>0;let o=Ve(i?[...s,...n]:n);if(o.length>0){for(const c of o)if(c.multiple&&c.lazyMultiple)throw new Error(`Argument "${c.name}" cannot have both multiple and lazyMultiple options, please choose one.`)}const l=t.arguments!==void 0&&t.arguments.length>0;(t.argument||l)&&(o=[{defaultOption:!0,description:t.argument?.description,group:"positionals",multiple:!0,name:oe,type:t.argument?.type??String,typeLabel:t.argument?.typeLabel},...o]);let a,u;if(i){const{optionMapByAlias:c,optionMapByName:p}=Fn(s);a=Ln(e,s,p,c),u=$n(e,s,p,c)}else a=e,u={};const r=En(o,{argv:a,camelCase:!0,partial:!0,stopAtFirstUnknown:!0});return{arguments_:o,booleanValues:u,parsedArgs:r}},pe=async(t,e,n)=>typeof t.execute=="function"?t.execute(e):(await tt(t))(e),Kn=(t,e)=>{if(!t.arguments||t.arguments.length===0)return;const n=e.rawUnknown.indexOf("--"),s=n===-1?[]:e.rawUnknown.slice(n+1),i=s.length===0?e.argument:e.argument.slice(0,Math.max(0,e.argument.length-s.length)),o=zn(t.arguments,i);if(e.args=o.resolved,o.missing.length>0)throw new xt(t.name,o.missing);const[l]=o.invalid;if(l)throw new Et(l.name,l.value,l.choices);if(o.surplus.length>0)throw new kt(t.name,o.surplus,t.arguments.length)};let Gn=class{capacity;cache;constructor(e){this.capacity=e,this.cache=new Map}get(e){if(!this.cache.has(e))return;const n=this.cache.get(e);return this.cache.delete(e),this.cache.set(e,n),n}has(e){return this.cache.has(e)}set(e,n){if(this.cache.has(e))this.cache.delete(e);else if(this.cache.size>=this.capacity){const s=this.cache.keys().next().value;s!==void 0&&this.cache.delete(s)}this.cache.set(e,n)}delete(e){this.cache.delete(e)}clear(){this.cache.clear()}size(){return this.cache.size}};const Hn=(t,e)=>typeof t!="string"||t===""?"":t[0].toLowerCase()+t.slice(1),Xn=new RegExp("[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d/#&.:=?%@~_]*)*)?(?:\\u0007|\\u001B\\u005C|\\u009C))|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))","g"),Yn=t=>{if(typeof t!="string")throw new TypeError(`The "value" argument must be of type string. Received ${typeof t}`);return t.replaceAll(Xn,"")},fe=new Gn(1e3),Jn=/[.*+?^${}()|[\]\\]/g,Zn=t=>{const e=t.join("");if(fe.has(e)){const i=fe.get(e);return i.lastIndex=0,i}const n=t.map(i=>i.replaceAll(Jn,String.raw`\$&`)).join("|"),s=new RegExp(n,"g");return fe.set(e,s),s},Qn=t=>{const e=[];let n=0,s;for(q.lastIndex=0;(s=q.exec(t))!==null;)s.index>n&&e.push(t.slice(n,s.index)),e.push(s[0]),n=q.lastIndex;return n<t.length&&e.push(t.slice(n)),e.filter(Boolean)},es=/[ČŠŽĐ]/i,nt=new Uint8Array(128),st=new Uint8Array(128),ot=new Uint8Array(128);for(let t=0;t<128;t++)nt[t]=t>=65&&t<=90?1:0,st[t]=t>=97&&t<=122?1:0,ot[t]=t>=48&&t<=57?1:0;const de=t=>nt[t],Re=t=>st[t],ge=t=>ot[t],j=(t,e,n,s,i)=>{if(t.length===0)return[];let o=!1;const l=Object.values(e);for(const m of l)if(m(t[0])){o=!0;break}if(!o&&!n)return[t];const a=[...t],u=[];let r=a[0],c="other";const p=Object.entries(e);for(const m of p){const[g,y]=m;if(y(a[0])){c=g;break}}let h=n&&s?a[0]===a[0].toLocaleUpperCase(s):!1;for(let m=1;m<a.length;m++){const g=a[m];let y="other";for(const C of p){const[O,k]=C;if(k(g)){y=O;break}}const A=n&&s?g===g.toLocaleUpperCase(s):!1;let d=!1;i?d=i(c,y,h,A,g,m,a):(c!==y&&c!=="other"&&y!=="other"&&(d=!0),n&&y!=="other"&&!h&&A&&(d=!0)),d?(u.push(r),r=g):r+=g,c=y,n&&(h=A)}return r&&r.length>0&&u.push(r),u.length>0?u:[t]},ts=(t,e,n,s)=>{if(n.size===0)return e;for(const i of n)if(t.startsWith(i,e))return s.push(i),e+i.length;return e},it=(t,e=new Set)=>{if(t.length===0)return[];if(t.toUpperCase()===t)return[t];let n=0;const s=[],i=t.length;for(let o=1;o<i;o++){const l=ts(t,n,e,s);if(l!==n){n=l,o=n-1;continue}const a=t.codePointAt(o-1),u=t.codePointAt(o),r=a&&a<128&&de(a),c=u&&u<128&&de(u),p=a&&a<128&&Re(a),h=a&&a<128&&ge(a),m=u&&u<128&&ge(u);if(p&&c){s.push(t.slice(n,o)),n=o;continue}if(h&&!m||!h&&m){s.push(t.slice(n,o)),n=o;continue}if(m&&!h){let g=!1,y=!1;if(o+1<i){const A=t.codePointAt(o+1);g=A&&A<128&&de(A),y=A&&A<128&&ge(A)}if(!y&&g){s.push(t.slice(n,o),t.slice(o,o+1)),n=o+1;continue}}if(o+1<i){const g=t.codePointAt(o+1),y=g&&g<128&&Re(g);if(r&&c&&y){const A=t.slice(n,o+1);e.has(A)||(s.push(t.slice(n,o)),n=o)}}}return n<i&&s.push(t.slice(n)),s.filter(o=>o!=="")},rt=(t,e,n)=>{if(t.length===0)return[];const s=t===t.toLocaleUpperCase(e);if(e.startsWith("de")){if(!s&&t.replaceAll("ß","SS")===t.toLocaleUpperCase(e))return[t];const r=[...t],c=r.length,p=[];let h=r[0],m=r[0]===r[0].toLocaleUpperCase(e),g=m,y=m?0:-1;for(let A=1;A<c;A++){const d=r[A],C=d===d.toLocaleUpperCase(e);if(C===m)h+=d;else if(C)h&&h.length>0&&(p.push(h),h=d),g=!0,y=A;else{if(g&&A-y>1){const O=r[A-1],k=h.slice(0,-1);k&&k.length>0&&p.push(k),h=O+d}else h+=d;g=!1,y=-1}m=C}return h&&h.length>0&&p.push(h),p}if(e.startsWith("uk")||e.startsWith("ru")||e.startsWith("bg")||e.startsWith("sr")||e.startsWith("mk")||e.startsWith("be")){if(!X.test(t)&&!P.test(t))return[t];const r=[...t],c=r.length,p=[];let h=r[0];const m=r[0];let g;X.test(m)?g=1:P.test(m)?g=2:g=0;let y=m===m.toLocaleUpperCase(e);for(let d=1;d<c;d++){const C=r[d];let O;X.test(C)?O=1:P.test(C)?O=2:O=0;const k=C===C.toLocaleUpperCase(e);g!==O&&(g===1||g===2)&&(O===1||O===2)||O===g&&!y&&k?(p.push(h),h=C):h+=C,g=O,y=k}h&&h.length>0&&p.push(h);const A=[];for(let d=0;d<p.length;d++)d<p.length-1&&p[d].length===1&&P.test(p[d])&&X.test(p[d+1][0])?(A.push(p[d]+p[d+1]),d+=1):A.push(p[d]);return A}if(e.startsWith("el")){if(!ce.test(t)&&!P.test(t))return[t];const r=[];Oe.lastIndex=0;let c;for(;(c=Oe.exec(t))!==null;)r.push(c[0]);r.length===0&&r.push(t);const p=[];if(r.length===1){const h=r[0];if(!h||!ce.test(h[0])||h.length===1)return[h??t]}for(const h of r){if(!h)continue;if(!ce.test(h[0])||h.length===1){p.push(h);continue}const m=h.length;let g=h[0],y=h[0]===h[0].toLocaleUpperCase(e);for(let A=1;A<m;A++){const d=h[A],C=d===d.toLocaleUpperCase(e);!y&&C?(p.push(g),g=d):g+=d,y=C}g&&p.push(g)}return p}if(e.startsWith("ja")||e.startsWith("ko")){const r=e.startsWith("ja"),c=r?{hiragana:h=>Lt.test(h),kanji:h=>Ee.test(h),katakana:h=>Pt.test(h),latin:h=>P.test(h)}:{hangul:h=>xe.test(h),latin:h=>P.test(h)},p=new Set(["が","で","と","に","の","は","へ","も","や","を"]);if(r){const h=j(t,c,!1,e,(g,y)=>g==="hiragana"&&y==="katakana"||g==="katakana"&&y==="hiragana"||g==="hiragana"&&y==="latin"||g==="katakana"&&y==="latin"||g==="kanji"&&y==="latin"||g==="latin"&&(y==="hiragana"||y==="katakana"||y==="kanji")),m=[];for(const g of h){const y=g;y.length===1&&p.has(y)&&m.length>0?m[m.length-1]=m.at(-1)+y:m.push(y)}return m.length>0?m:[t]}return j(t,c,!1,e,(h,m)=>h==="hangul"&&m==="latin"||h==="latin"&&m==="hangul")}if(e.startsWith("sl")){const r=[...t],c=r.length,p=[];let h=r[0],m=r[0]===r[0].toLocaleUpperCase(e);for(let g=1;g<c;g++){const y=r[g],A=y===y.toLocaleUpperCase(e),d=es.test(y),C=g<c-1&&r[g+1]===r[g+1].toLocaleUpperCase(e);!m&&A||d&&C?(p.push(h),h=y,d&&C&&(p.push(h),h="")):h+=y,m=A}return h&&h.length>0&&p.push(h),p}if(e.startsWith("zh"))return j(t,{han:r=>Ee.test(r),latin:r=>P.test(r)},!1,e);if(["ar","fa","he","ur"].includes(e.split("-")[0])){const r=c=>ke.test(c)||Ie.test(c);return j(t,{latin:c=>P.test(c),rtl:c=>r(c)},!1,e)}if(["am","bn","gu","hi","km","kn","lo","ml","mr","ne","or","pa","si","ta","te","th"].includes(e.split("-")[0])){const r=c=>Ut.test(c)||Mt.test(c)||Tt.test(c)||St.test(c)||Dt.test(c)||Vt.test(c)||jt.test(c)||Rt.test(c)||Bt.test(c)||zt.test(c)||Ft.test(c)||Wt.test(c)||qt.test(c)||Kt.test(c)||Gt.test(c)||Ht.test(c);return j(t,{indic:c=>r(c),latin:c=>P.test(c)},!1,e)}if(["be","bg","ru","sr","uk"].includes(e))return j(t,{cyrillic:r=>X.test(r),latin:r=>P.test(r)},!0,e);if(["ar","fa","he"].includes(e))return j(t,{latin:r=>P.test(r),rtl:r=>ke.test(r)||Ie.test(r)},!1,e);if(e.startsWith("ko"))return j(t,{hangul:r=>xe.test(r),latin:r=>P.test(r)},!1,e);if(e.startsWith("uz")){if(!X.test(t)&&!P.test(t))return[t];const r=[...t],c=r.length,p=[];let h=r[0],m=r[0]===r[0].toLocaleUpperCase(e);for(let g=1;g<c;g++){const y=r[g],A=y===y.toLocaleUpperCase(e);if(_e.test(y)||_e.test(r[g-1])){h+=y;continue}!m&&A?(p.push(h),h=y):h+=y,m=A}return h&&h.length>0&&p.push(h),p}const i=[...t],o=i.length,l=[];let a=i[0],u=i[0]===i[0].toLocaleUpperCase(e);for(const r of n)if(t.startsWith(r)){l.push(r),a=i[r.length],u=a===a.toLocaleUpperCase(e);break}for(let r=1;r<o;r++){const c=i[r],p=c===c.toLocaleUpperCase(e);let h=0;for(const m of n)if(t.startsWith(m,r)){l.push(a,m),h=m.length,a="";const g=m.at(-1);g&&(u=g===g.toLocaleUpperCase(e));break}if(h>0){r+=h-1;continue}!u&&p?(l.push(a),a=c):a+=c,u=p}return a&&l.push(a),l},ns=(t,e,n)=>{const s=[],i=ie.test(t)?t.split(ie).filter(Boolean):[t];for(const o of i){const l=o;if(ie.test(l))s.push(l);else{q.lastIndex=0;const a=q.test(l)?Qn(l).filter(Boolean):[l];for(const u of a)if(q.lastIndex=0,q.test(u))s.push(u);else if(e){const r=e.toLowerCase().split("-")[0];s.push(...rt(u,r,n))}else s.push(...it(u,n))}}return s},ss=(t,e={})=>{if(!t||typeof t!="string")return[];const{handleAnsi:n=!1,handleEmoji:s=!1,knownAcronyms:i=[],locale:o,normalize:l=!1,separators:a,stripAnsi:u=!1,stripEmoji:r=!1}=e,c=new Set([...i].toSorted((d,C)=>C.length-d.length));let p=t;u&&(p=Yn(p)),r&&(p=It(p));let h;Array.isArray(a)?h=Zn(a):a instanceof RegExp?h=a:h=$t;const m=[];let g=p;const y=h.flags.includes("g")?h:new RegExp(h.source,`${h.flags}g`);for(;g.length>0;){const d=y.exec(g);if(!d){g===".."?m.push(".."):g==="."?m.push("."):g.length>0&&m.push(g);break}const C=d.index,O=d[0],k=O.length,E=g.slice(0,C),H=g.slice(C+k);if(O.startsWith("../"))m.push(".."),g=g.slice(C+3);else if(O.startsWith("./"))m.push("."),g=g.slice(C+2);else if(C===0&&O==="..")m.push(".."),g=g.slice(2);else if(C===0&&O===".")m.push("."),g=g.slice(1);else{E.length>0&&m.push(E);let T=0;for(;(T=O.indexOf("../",T))!==-1;)m.push(".."),T+=3;for(T=0;(T=O.indexOf("./",T))!==-1;)(T===0||O[T-1]!==".")&&m.push("."),T+=2;let f=H;for(;f.startsWith("../");)m.push(".."),f=f.slice(3);for(;f.startsWith("./");)m.push("."),f=f.slice(2);if(f===".."){m.push("..");break}else if(f==="."){m.push(".");break}else g=f}y.lastIndex=0}if(m.length===0){const d=p.split(h).filter(Boolean);m.push(...d)}let A=[];for(const d of m)n||s?A.push(...ns(d,o,c)):o?A.push(...rt(d,o,c)):A.push(...it(d,c));return l&&(A=A.map(d=>c.has(d)?d:o&&d===d.toLocaleUpperCase(o)?d[0]+d.slice(1).toLocaleLowerCase(o):d.toUpperCase()===d&&!c.has(d)?d.slice(0,1)+d.slice(1).toLowerCase():d)),A},os=(t,e)=>typeof t!="string"||t===""?"":t[0].toUpperCase()+t.slice(1),is=(t,e)=>{const{length:n}=t;if(n===0)return"";if(n===1)return t[0];const s=[];let i="",o="";for(let l=0;l<n;l++){const a=t[l];if(ie.test(a)){i?(s.push(i+o+a),i="",o=""):(s.length>0&&s.push(e),i=a);continue}i?(o&&(o+=e),o+=a):(s.length>0&&s.push(e),s.push(a))}return s.join("")},Y=(t,e)=>{if(typeof t!="string"||!t)return"";let n=!0;return is(ss(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(i=>{const o=i,l=o.toLowerCase();return n?(n=!1,Hn(l)):os(l)}),"")};class rs extends b{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(", ")}`}}class as extends b{choices;option;value;constructor(e,n,s){super(`Invalid value "${n}" for option "${e}". Allowed values: ${s.join(", ")}`,"INVALID_CHOICE",{choices:s,option:e,value:n}),this.name="InvalidChoiceError",this.option=e,this.value=n,this.choices=s,this.hint=`Use one of: ${s.map(i=>`--${e} ${i}`).join(", ")}`}}const Be=(t,e,n=!1)=>{const s=[],i=e._all??e;for(const o of t){if(!n&&!o.required)continue;const l=o.__camelCaseName__??o.name;if(i[l]===void 0){if(o.type?.name==="Boolean"){e[l]=!1;continue}s.push(o)}}return s},ls=(t,e)=>e.includes(t)?!0:Math.abs(t.length-e.length)>t.length/2?!1:Jt(t,e)<=t.length/3,R=(t,e)=>{const n=t.toLowerCase();return e.filter(s=>ls(s.toLowerCase(),n))},cs=(t,e)=>{const n=[];if(t._unknown&&t._unknown.forEach(s=>{const i=s.startsWith("--");let o=`Found unknown ${i?"option":"argument"} "${s}"`;if(i){const l=R(s.replace("--",""),(e.options??[]).map(a=>a.name));if(l.length>0){const[a,...u]=l.map(r=>`--${r}`);o+=u.length>0?`, did you mean ${a??""} or ${u.join(", ")}?`:`, did you mean ${a??""}?`}}n.push(o)}),n.length>0)throw new b(n.join(`
2
+ `),Xt.UNKNOWN_OPTION,{unknownOptions:[...t._unknown??[]]})},W=(t,e)=>new b(`Command "${t}" ${e}`,"INVALID_COMMAND",{commandName:t}),hs=(t,e)=>{const n=new Set;for(const[s,i]of t.entries()){if(typeof i!="object"||i===null)throw W(e,`has a positional argument at index ${String(s)} that is not an object`);const{name:o}=i;if(typeof o!="string"||o.length===0)throw W(e,`has a positional argument at index ${String(s)} without a name`);const l=et(o);if(n.has(l))throw W(e,`declares duplicate positional argument "${o}"`);n.add(l);const a=s===0?void 0:t[s-1];if(i.required===!0&&a!==void 0&&a.required!==!0)throw W(e,`declares required positional "${o}" after an optional one, which can never be satisfied`);if(i.multiple===!0&&s!==t.length-1)throw W(e,`declares a variadic positional "${o}" that is not the last one`)}},us=(t,e,n)=>{const s=n.__requiredOptions__,i=s?Be(s,e,!0):Be(t,e,!1);if(i.length>0)throw new rs(n.name,i.map(o=>o.name));e._unknown&&e._unknown.length>0&&!n.argument&&!n.arguments?.length&&cs(e,n)},ps=(t,e,n)=>{const s=n.__conflictingOptions__??t.filter(i=>i.conflicts!==void 0);if(s.length>0){const i=s.find(o=>{const l=o.__camelCaseName__??Y(o.name);return Array.isArray(o.conflicts)?o.conflicts.some(a=>e[Y(a)]!==void 0)&&e[l]!==void 0:e[Y(o.conflicts)]!==void 0&&e[l]!==void 0});if(i)throw new Ge(i.name,typeof i.conflicts=="string"?i.conflicts:i.conflicts?.[0]??"unknown")}},fs=(t,e)=>{const n=e.options;if(n)for(const s of n){if(!s.choices||s.choices.length===0)continue;const i=s.__camelCaseName__??Y(s.name),o=t[i];if(o==null)continue;const l=Array.isArray(o)?o:[o];for(const a of l){const u=String(a);if(!s.choices.includes(u))throw new as(s.name,u,s.choices)}}},ds=t=>{if(!Array.isArray(t.options))return;const e=new Map,n=new Map;for(const i of t.options){if(i.name){const o=e.get(i.name)??[];o.push(i),e.set(i.name,o)}if(typeof i.alias=="string"&&i.alias.length>0){const o=n.get(i.alias)??[];o.push(i),n.set(i.alias,o)}else if(Array.isArray(i.alias)){for(const o of i.alias)if(o.length>0){const l=n.get(o)??[];l.push(i),n.set(o,l)}}}const s=[];for(const[i,o]of e)o.length>1&&s.push(`Duplicate option name "${i}" in command "${t.name}": ${JSON.stringify(o)}`);for(const[i,o]of n)o.length>1&&s.push(`Duplicate option alias "-${i}" used by options ${o.map(l=>`"${l.name}"`).join(", ")} in command "${t.name}"`);if(s.length>0)throw new Error(s.join(`
3
+ `))},gs=t=>{const{arguments:e}=t;if(e!==void 0){if(!Array.isArray(e))throw W(t.name,'must declare "arguments" as an array — slot order is significant, so a record cannot express it');if(t.argument!==void 0)throw W(t.name,'cannot define both "argument" and "arguments" — choose one');hs(e,t.name)}},ms=(t,e)=>{if(e.length===0)return{argv:[],commandPath:void 0};const n=[];let s;for(let i=1;i<=e.length;i+=1){const o=e[i-1];if(o===void 0||o.startsWith("-"))break;n.push(o);const l=n.join(" ");t.has(l)&&(s={commandPath:[...n],depth:i})}return s?{argv:e.slice(s.depth),commandPath:s.commandPath}:{argv:e,commandPath:void 0}},z=t=>t.join(" "),ze=(t,e)=>e&&e.length>0?[...e,t]:[t],Fe=t=>t===void 0||Array.isArray(t)?t:Object.entries(t).map(([e,n])=>({...n,name:e})),ws=t=>{const e=Fe(t.options),n=Fe(t.env);return e===t.options&&n===t.env?t:Object.assign(Object.create(Object.getPrototypeOf(t)),t,{env:n,options:e})},ys=/^no-/,vs=t=>{t.options?.forEach(e=>{e.__camelCaseName__=Y(e.name)})},As=t=>{if(!Array.isArray(t.options)||t.options.length===0)return;const e=new Set;for(const s of t.options)e.add(s.name);const n=[];for(const s of t.options)if(s.name.startsWith("no-")){const i=s.name.replace(ys,"");if(!e.has(i)){if(s.type!==Boolean)throw new Error(`Cannot add negated option "${s.name}" to command "${t.name}" because it is not a boolean.`);const o={...s,alias:void 0,defaultValue:s.defaultValue===void 0?!0:!s.defaultValue,description:`Inverse of --${s.name}.`,name:i};n.push(o),e.add(i)}}n.length>0&&t.options.push(...n)},Cs=(t,e)=>{if(!e.options||e.options.length===0)return;const{options:n}=t,s=new Map;for(const o of e.options)if(o.name.startsWith("no-")){const l=Y(o.name);s.set(l,o)}const i=Object.keys(n).filter(o=>s.has(o));if(i.length!==0)for(const o of i){const l=o.charAt(2);if(!l)continue;const a=l.toLowerCase()+o.slice(3),u=s.get(o);u&&(u.__negated__=!0),n[a]=!n[o],Reflect.deleteProperty(n,o)}},Ns=(t,e)=>{if(!e.options||e.options.length===0)return;const n=new Map;for(const i of e.options)i.__camelCaseName__&&i.__negated__===void 0&&i.implies!==void 0&&n.set(i.__camelCaseName__,i);if(n.size===0)return;const{options:s}=t;for(const i of Object.keys(s)){const o=n.get(i);if(o?.implies){const{implies:l}=o;for(const[a,u]of Object.entries(l))s[a]===void 0&&(s[a]=u)}}},bs=()=>!!process.versions.electron,Os=()=>bs()&&!process.defaultApp,_s=()=>Os()?0:1,Es=t=>t.slice(_s()+1),xs=" ",ks=(t,e)=>t===e?!0:t.length!==e.length?!1:t.every((n,s)=>n===e[s]),Is=t=>{if(typeof t=="string")return t.split(xs);const e=we();return ks(t,e)?Es(t):t},$s=t=>{const e=o=>{t.error(`Uncaught exception: ${o.message||o}`),o.stack&&t.error(o.stack),F(1)},n=(o,l)=>{if(o instanceof Error)t.error(`Promise rejection: ${o.message||o}`),o.stack&&t.error(o.stack);else{let a;if(typeof o=="string")a=o;else try{a=JSON.stringify(o)}catch{a=String(o)}t.error(`Promise rejection: ${a}`)}F(1)},s=be("uncaughtException",e),i=be("unhandledRejection",n);return()=>{s(),i()}},We=100,Ps=/^[a-z][\w-]*$/i,ve=(t,e)=>{if(typeof t!="string"||t.trim().length===0)throw new b(`${e} must be a non-empty string`,"INVALID_INPUT",{fieldName:e,value:t});return t.trim()},qe=(t,e)=>{if(!Array.isArray(t)||!t.every(n=>typeof n=="string"))throw new b(`${e} must be an array of strings`,"INVALID_INPUT",{fieldName:e,value:t});return t},ne=(t,e)=>{if(typeof t!="object"||t===null)throw new b(`${e} must be an object`,"INVALID_INPUT",{fieldName:e,value:t});return t},se=t=>{const e=ve(t,"Command name");if(e.length>We)throw new b(`Command name is too long (maximum ${String(We)} characters)`,"INVALID_COMMAND_NAME",{commandName:e,length:e.length});if(e.includes("..")||e.includes("/")||e.includes("\\")||e.includes(";")||e.includes("|")||e.includes("&"))throw new b(`Command name "${e}" contains invalid characters`,"INVALID_COMMAND_NAME",{commandName:e});if(!Ps.test(e))throw new b(`Command name "${e}" must start with a letter and contain only letters, numbers, hyphens, and underscores`,"INVALID_COMMAND_NAME",{commandName:e});return e},Ls=1e6,Us=1e5,Ms=new Set([`
4
+ `,"\r"," ","\0",'"',"$","&","'","(",")",";","<",">","[","\\","]","`","{","|","}"]),Ts=(t,e={})=>{if(typeof t!="string")throw new TypeError("Argument must be a string");const n=typeof e=="boolean"?{checkDangerousChars:e}:e,s=n.maxArgumentLength??Ls;if(Number.isFinite(s)&&s>0&&t.length>s)throw new Error(`Argument is too long (maximum ${String(s)} characters)`);if(n.checkDangerousChars){for(const i of t)if(Ms.has(i))throw new Error(`Argument contains dangerous character: ${i}`)}return n.trim?t.trim():t},Ke=(t,e={})=>{if(!Array.isArray(t))throw new TypeError("Arguments must be an array");const n=typeof e=="boolean"?{checkDangerousChars:e}:e,s=n.maxArguments??Us;if(Number.isFinite(s)&&s>0&&t.length>s)throw new Error(`Too many arguments (maximum ${String(s)})`);return t.map(i=>Ts(i,n))},Ss=/^-([^\d-])$/,Ds=/^--(\S+)/,Vs=/^-([^\d-]{2,})$/,me=t=>Ss.test(t)||Ds.test(t)||Vs.test(t),js={access:(t,e)=>yt(t,e),mkdir:(t,e)=>wt(t,e),readdir:t=>mt(t),readFile:(async(t,e)=>e===void 0?Ne(t):Ne(t,e)),rm:(t,e)=>gt(t,e),stat:t=>dt(t),writeFile:(t,e,n)=>ft(t,e,n)},Rs=(t,e,n)=>{const s=e.indexOf("--"),i=s===-1?new Set:new Set(e.slice(s+1)),o=n.filter(u=>u.startsWith("--")&&u!=="--"&&!i.has(u));if(o.length===0)return;const l=(t.options??[]).map(u=>u.name),a=o.flatMap(u=>R(u.slice(2),l).map(r=>`--${r}`));throw new Zt(o,a)};class at{#t;#e;#h;#p;#f;#d;#O;#_;#E;#A;#x;#C;#k;#N=le;#u;#n;#s;#o;#i;#r;#I=!1;#$;#P=!1;#g;#m;#w;#l=[];#D(){return this.#g===void 0&&(this.#g=[...this.#s.keys()]),this.#g}#L(){return this.#m===void 0&&(this.#m=[...this.#n.keys()]),this.#m}#a(){return this.#w===void 0&&(this.#w=[...this.#D(),...this.#L()]),this.#w}#U(){return this.#l.length===0?te:[...te,...this.#l]}#M(){this.#g=void 0,this.#m=void 0,this.#w=void 0}#b(){if(this.#h===void 0){const e=Is(this.#e.argv);this.#h=Ke(e,{maxArguments:this.#C}),this.#V()}return this.#h}#y(){return this.#A??re()}#v(e){this.#N=e,this.#y().CEREBRO_OUTPUT_LEVEL=String(e)}#c(){return this.#N}#V(){if(!this.#h)return;let e=!1;for(const n of this.#h){if(n==="--quiet"||n==="-q"){this.#v(vt),e=!0;break}if(n==="--verbose"||n==="-v"){this.#v(At),e=!0;break}if(n==="--debug"){this.#v(V),e=!0;break}}e||this.#v(Object.hasOwn(this.#y(),"DEBUG")?V:le)}#j(){this.#P||(this.#$=$s(this.#t),this.#P=!0)}#R(){return{arch:Nt(),argv:this.#b(),cwd:this.#p,env:this.#A??re(),exit:this.#E??(e=>F(e??0)),platform:Ct(),stdin:this.#x}}#T(e,n,s,i){this.#c()===V&&this.#t.debug(`command '${i}' found, parsing command args: ${n.join(", ")}`);const{arguments_:o,booleanValues:l,parsedArgs:a}=qn(e,n,this.#U()),u=Object.keys(l).length>0;let r=a;u&&(r={...a,_all:{...a._all,...l}}),us(o,r,e);const c=Wn(e,a,l,s,this.#y(),n);c.runtime=this,c.argv=this.#b(),c.fs=this.#_??js,c.process=this.#R(),c.console=this.#t,Kn(e,c);const p=e.options&&e.options.length>0;if(p&&e.options){const h=e.options.filter(m=>m.name.startsWith("no-"));for(const m of h){const g=m.name.slice(3),y=`--${m.name}`,A=`--${g}`,d=n.includes(y),C=n.includes(A);if(d&&C)throw new Ge(g,m.name)}}return p&&(Cs(c,e),Ns(c,e)),ps(o,c.options,e),fs(c.options,e),this.#k&&Rs(e,n,c.rawUnknown),this.#c()===V&&(this.#t.debug("command options parsed from options:"),this.#t.debug(JSON.stringify(c.options,null,2)),this.#t.debug("command argument parsed from argument:"),this.#t.debug(JSON.stringify(c.argument,null,2))),{arguments_:o,booleanValues:l,commandArgs:r,parsedArgs:a,toolbox:c}}async#S(e,n,s){const i=this.getPluginManager();try{!this.#I&&i.hasPlugins()&&(await i.init({cli:this,cwd:this.#p,logger:this.#t}),this.#I=!0),await i.executeLifecycle("execute",n),await i.executeLifecycle("beforeCommand",n);let o;const l=s.global;if(l?.help){const a=this.#n.get("help");if(!a)throw new b("Help command not found","COMMAND_NOT_FOUND");o=await pe(a,n,s)}else if(l?.version??l?.V){const a=this.#n.get("version");if(!a)throw new b("Version command not found","COMMAND_NOT_FOUND");o=await pe(a,n,s)}else o=await pe(e,n,s);return await i.executeLifecycle("afterCommand",n,o),o}catch(o){throw await i.executeErrorHandlers(o,n),o}}constructor(e,n={}){if(typeof e!="string"||e.trim().length===0)throw new b("CLI name must be a non-empty string","INVALID_INPUT",{cliName:e});this.#f=e.trim();const s=n.argv??we(),i=n.cwd??bt();if(this.#e={...n,argv:s,cwd:i},this.#e.argv&&!Array.isArray(this.#e.argv))throw new b("CLI argv option must be an array of strings","INVALID_INPUT",{argv:this.#e.argv});if(this.#e.cwd&&typeof this.#e.cwd!="string")throw new b("CLI cwd option must be a string","INVALID_INPUT",{cwd:this.#e.cwd});if(this.#e.packageName&&typeof this.#e.packageName!="string")throw new b("CLI packageName option must be a string","INVALID_INPUT",{packageName:this.#e.packageName});if(this.#e.packageVersion&&typeof this.#e.packageVersion!="string")throw new b("CLI packageVersion option must be a string","INVALID_INPUT",{packageVersion:this.#e.packageVersion});if(typeof this.#e.logger=="object"){const p=["debug","error","info","log","warn"],h=[],m=this.#e.logger;for(const g of p)typeof m[g]!="function"&&h.push(g);if(h.length>0)throw new b(`Logger object is missing required methods: ${h.join(", ")}`,"INVALID_INPUT",{logger:this.#e.logger,missingMethods:h});this.#t=this.#e.logger}else this.#t={...console,debug:(...p)=>{this.#c()===V&&console.debug(...p)}};this.#d=this.#e.packageVersion,this.#O=this.#e.packageName,this.#p=this.#e.cwd,this.#i="help",this.#r={};const o=n.fs;if(o!==void 0&&(typeof o!="object"||o===null))throw new b("CLI fs option must be an object implementing the CerebroFs interface","INVALID_INPUT",{fs:n.fs});const l=n.exit;if(l!==void 0&&typeof l!="function")throw new b("CLI exit option must be a function","INVALID_INPUT",{exit:n.exit});const a=n.env;if(a!==void 0&&(typeof a!="object"||a===null))throw new b("CLI env option must be a record of string keys","INVALID_INPUT",{env:n.env});const u=n.stdin;if(u!==void 0&&typeof u!="string")throw new b("CLI stdin option must be a string","INVALID_INPUT",{stdin:n.stdin});this.#_=n.fs,this.#E=n.exit,this.#A=n.env,this.#x=n.stdin??"",this.#C=n.maxArguments,this.#k=n.strictOptions??!1;const r=this.#y().CEREBRO_OUTPUT_LEVEL,c=r===void 0?Number.NaN:Number(r);this.#N=Number.isNaN(c)?le:c,this.#n=new Map,this.#s=new Map,this.#o=new Map}setCommandSection(e){return this.#r=e,this}getCommandSection(){return this.#r.header||(this.#r.header=`${this.#f}${this.#d?` v${this.#d}`:""}`),this.#r}setDefaultCommand(e){return this.#i=e,this}get defaultCommand(){return this.#i}addCommand(e){ne(e,"Command"),se(e.name),e.options!==void 0&&ne(e.options,"Command options"),e.env!==void 0&&ne(e.env,"Command env"),gs(e);const n=ws(e),s=typeof n.execute=="function",i=typeof n.loader=="function";if(s&&i)throw new b(`Command "${n.name}" cannot define both "execute" and "loader" — choose one`,"INVALID_COMMAND",{commandName:n.name});if(!s&&!i)throw new b(`Command "${n.name}" must define either "execute" or "loader"`,"INVALID_COMMAND",{commandName:n.name});n.alias&&(typeof n.alias=="string"?se(n.alias):qe(n.alias,"Command alias").forEach(c=>se(c))),n.argument&&ne(n.argument,"Command argument"),n.commandPath&&(qe(n.commandPath,"Command commandPath"),n.commandPath.forEach(c=>{se(c)}));const o=ze(n.name,n.commandPath),l=z(o);if(this.#s.has(l))throw new b(`Command with path "${l}" already exists`,"DUPLICATE_COMMAND",{commandName:n.name,commandPath:n.commandPath});const a=Array.isArray(n.commandPath)&&n.commandPath.length>0,u=this.#n.get(n.name),r=u!==void 0&&(u.commandPath===void 0||u.commandPath.length===0);if(!a&&r)throw new b(`Command with name "${n.name}" already exists`,"DUPLICATE_COMMAND",{commandName:n.name});if(n.options)for(const c of n.options)$e(c);if(ds(n),As(n),vs(n),n.options&&(n.__conflictingOptions__=n.options.filter(c=>c.conflicts!==void 0),n.__requiredOptions__=n.options.filter(c=>c.required===!0)),a&&u!==void 0)this.#n.set(l,n);else{if(!a&&u!==void 0&&!r){const c=ze(u.name,u.commandPath);this.#n.set(z(c),u)}this.#n.set(n.name,n)}if(this.#s.set(l,o),this.#o.set(l,n),this.#M(),n.alias!==void 0){const c=typeof n.alias=="string"?[n.alias]:n.alias;for(const p of c){if(this.#c()===V&&this.#t.debug("adding alias",p),this.#n.has(p))throw new b(`Command alias "${p}" conflicts with existing command`,"DUPLICATE_COMMAND",{alias:p,commandName:n.name});this.#n.set(p,n)}}return this}addGlobalOption(e){const n=e,s=new Set(te.map(l=>l.name)),i=new Set(te.map(l=>l.alias).filter(Boolean));if(s.has(n.name))throw new b(`Cannot add global option "--${n.name}": it conflicts with a built-in global option`,"DUPLICATE_OPTION",{optionName:n.name});if(n.alias&&i.has(n.alias))throw new b(`Cannot add global option with alias "-${n.alias}": it conflicts with a built-in global option alias`,"DUPLICATE_OPTION",{alias:n.alias,optionName:n.name});if(new Set(this.#l.map(l=>l.name)).has(n.name))throw new b(`Global option "--${n.name}" has already been added`,"DUPLICATE_OPTION",{optionName:n.name});return n.group="global",$e(n),this.#l.push(n),this}getGlobalOptions(){return this.#U()}addPlugin(e){return this.getPluginManager().register(e),this}getPluginManager(){return this.#u?this.#u:(this.#u=new en(this.#t),this.#u.register({description:"Attaches the logger to the toolbox",execute:e=>{e.logger=this.#t,e.console=e.logger},name:"logger"}),this.#u)}getCliName(){return this.#f}getPackageVersion(){return this.#d}getPackageName(){return this.#O}getCommands(){return this.#n}getCwd(){return this.#p}dispose(){this.#$?.()}async run(e={}){const{autoDispose:n=!0,shouldExitProcess:s=!0,...i}=e;if(!this.#n.has("help")){const{default:d}=await import("../commands/help-command.js");this.addCommand(new d(this.#n))}const o=this.#L(),l=this.#s;this.#j();const a=this.#b();let u,r=[...a];this.#c()===V&&(this.#t.debug(`process.execPath: ${Ot()}`),this.#t.debug(`process.execArgv: ${_t().join(" ")}`),this.#t.debug(`process.argv: ${we().join(" ")}`));const c=ms(l,[...a]);if(c.commandPath)u=c.commandPath,r=c.argv;else{if(a.length>1&&a[0]&&a[1]&&!me(a[0])&&!me(a[1])){const C=[];let O=0;for(;O<a.length;){const E=a[O];if(!E||me(E))break;C.push(E),O+=1}const k=z(C);if(C[0]&&!o.includes(C[0])){const E=this.#a(),H=R(k,E);throw new B(k,H)}}let d;try{d=an([null,...o],[...a])}catch(C){if(C instanceof Error&&C.name==="INVALID_COMMAND"&&"command"in C){const O=C.command,k=this.#a(),E=R(O,k);throw new B(O,E)}throw C}d.command&&(u=[d.command],r=d.argv)}if(!u)if(this.#i)u=[this.#i];else{const d=this.#a();throw new B("",d)}const p=z(u),h=this.#s.get(p);let m;if(h){if(m=this.#o.get(p),!m||z(h)!==p){const d=this.#a(),C=R(p,d);throw new B(p,C)}}else{const d=u.at(-1);if(m=d?this.#n.get(d):void 0,!m){const C=this.#a(),O=R(p,C);throw new B(p,O)}}if(typeof m.execute!="function"&&typeof m.loader!="function")return this.#t.error(`Command "${m.name}" has no function to execute.`),s?F(1):void 0;const g=r;let y,A;try{({commandArgs:y,toolbox:A}=this.#T(m,g,i,p))}catch(d){const C=Yt(d);if(this.#t.error(C??d),s)return F(1);throw d}try{return await this.#S(m,A,y),s?F(0):void 0}catch(d){if(s)return this.#t.error(d),F(1);throw d}finally{n&&this.dispose()}}async runCommand(e,n={}){const{argv:s=[],...i}=n;ve(e,"Command name");const o=e.split(" ").filter(Boolean),l=z(o),u=this.#s.get(l)?this.#o.get(l):this.#n.get(e);if(!u){const m=this.#a(),g=R(l||e,m);throw new B(e,g)}if(typeof u.execute!="function"&&typeof u.loader!="function")throw new b(`Command "${u.name}" has no function to execute`,"INVALID_COMMAND",{commandName:u.name});const c=[...Ke(s,{maxArguments:this.#C})];this.#c()===V&&this.#t.debug(`running command '${e}' programmatically with args: ${c.join(", ")}`);const{commandArgs:p,toolbox:h}=this.#T(u,c,i,l||e);return this.#S(u,h,p)}clone(e){const n={...this.#e,...e},s=new at(this.#f,n);for(const[i,o]of this.#n)s.#n.set(i,o);for(const[i,o]of this.#s)s.#s.set(i,[...o]);for(const[i,o]of this.#o)s.#o.set(i,o);for(const i of this.#l)s.#l.push(i);return s.#i=this.#i,s.#r={...this.#r},s.#M(),s}async getAction(e){ve(e,"Command name");const n=e.split(" ").filter(Boolean),s=z(n),o=this.#s.get(s)?this.#o.get(s):this.#n.get(e);if(!o){const l=this.#a(),a=R(s||e,l);throw new B(e,a)}if(typeof o.execute=="function")return o.execute;if(typeof o.loader=="function")return tt(o);throw new b(`Command "${o.name}" has no execute or loader defined`,"INVALID_COMMAND",{commandName:o.name})}}export{at as Cli};
@@ -460,6 +460,18 @@ interface Toolbox<TLogger extends Console = Console, TOptions extends Record<str
460
460
  * override, which lets tests assert exit codes without killing the runner.
461
461
  */
462
462
  process: CerebroProcess;
463
+ /**
464
+ * The argument tokens this command was invoked with, exactly as the
465
+ * caller supplied them — the argv tail for a CLI run, or the `argv`
466
+ * array for a programmatic `runtime.runCommand()` call.
467
+ *
468
+ * Use this, never `process.argv`, when a command forwards its own
469
+ * arguments on to another command. Scanning `process.argv` for the
470
+ * command's own name works only for a direct CLI invocation: called
471
+ * programmatically the token isn't there, the scan yields nothing, and
472
+ * the inner command silently runs with no arguments at all.
473
+ */
474
+ rawArgv: ReadonlyArray<string>;
463
475
  /**
464
476
  * Raw tokens that command-line-args could not assign to a defined
465
477
  * option — typically everything after a `--` separator, since
@@ -0,0 +1,2 @@
1
+ const N={COMMAND_NOT_FOUND:"COMMAND_NOT_FOUND",COMMAND_VALIDATION_ERROR:"COMMAND_VALIDATION_ERROR",CONFLICTING_OPTIONS:"CONFLICTING_OPTIONS",INVALID_ARGUMENT:"INVALID_ARGUMENT",INVALID_CHOICE:"INVALID_CHOICE",INVALID_INPUT:"INVALID_INPUT",MISSING_ARGUMENT:"MISSING_ARGUMENT",SURPLUS_ARGUMENT:"SURPLUS_ARGUMENT",UNKNOWN_OPTION:"UNKNOWN_OPTION"},U=new Set([N.COMMAND_NOT_FOUND,N.COMMAND_VALIDATION_ERROR,N.CONFLICTING_OPTIONS,N.INVALID_ARGUMENT,N.INVALID_CHOICE,N.INVALID_INPUT,N.MISSING_ARGUMENT,N.SURPLUS_ARGUMENT,N.UNKNOWN_OPTION]),r=O=>{const I=O?.code;return typeof I=="string"&&U.has(I)},R=O=>{if(!r(O))return;const{hint:I,message:_}=O,A=(Array.isArray(I)?I:[I]).filter(T=>typeof T=="string"&&T.length>0);return A.length>0?[_,...A].join(`
2
+ `):_};export{N as E,R as f};
@@ -1,4 +1,4 @@
1
- import { P as Plugin } from "../packem_shared/command.d-CLlirnwR.js";
1
+ import { P as Plugin } from "../packem_shared/command.d-Dz7hkMI0.js";
2
2
  import { O as Options$1 } from "../packem_shared/index.d-CnnVYgSZ.js";
3
3
  import '@visulima/tabular';
4
4
  type ErrorHandlerOptions = {
@@ -1 +1 @@
1
- import{z as h}from"../packem_shared/renderError-CIIYTTfx-BdX-afLI.js";import{e as m}from"../packem_shared/runtime-process-BN-eTlwy.js";const w=(i={})=>({description:"Enhanced error handling and reporting with beautiful code frames",name:"error-handler",onError:(e,s)=>{const{logger:r,runtime:t}=s,{concise:l,detailed:o=!1,exitOnError:d=!0,formatter:n,logErrors:a=!0,renderOptions:f={}}=i;if(a)if(n)r.error(n(e));else if(!o&&l?.(e))r.error(e.message);else if(o){const c=t.getCwd(),g=h(e,{cwd:c,hideErrorCodeView:!1,hideErrorTitle:!1,hideMessage:!1,linesAbove:2,linesBelow:3,...f});r.error(g)}else r.error(e);d&&m(1)},version:"1.0.0"});export{w as errorHandlerPlugin};
1
+ import{z as E}from"../packem_shared/renderError-CIIYTTfx-BdX-afLI.js";import{f as n}from"../packem_shared/format-user-facing-error-Cb7ySnUi.js";import{e as h}from"../packem_shared/runtime-process-BN-eTlwy.js";const x=(s={})=>({description:"Enhanced error handling and reporting with beautiful code frames",name:"error-handler",onError:(r,t)=>{const{logger:e,runtime:a}=t,{concise:d,detailed:o=!1,exitOnError:l=!0,formatter:i,logErrors:f=!0,renderOptions:c={}}=s;if(f)if(i)e.error(i(r));else if(!o&&(d?.(r)||n(r)!==void 0))e.error(n(r)??r.message);else if(o){const m=a.getCwd(),g=E(r,{cwd:m,hideErrorCodeView:!1,hideErrorTitle:!1,hideMessage:!1,linesAbove:2,linesBelow:3,...c});e.error(g)}else e.error(r);l&&h(1)},version:"1.0.0"});export{x as errorHandlerPlugin};
@@ -1,4 +1,4 @@
1
- import { P as Plugin } from "../packem_shared/command.d-CLlirnwR.js";
1
+ import { P as Plugin } from "../packem_shared/command.d-Dz7hkMI0.js";
2
2
  import '@visulima/tabular';
3
3
  type RuntimeType = "bun" | "deno" | "node";
4
4
  type RuntimeVersionRequirement = {
@@ -1,4 +1,4 @@
1
- import { a as CerebroFs, P as Plugin } from "../../packem_shared/command.d-CLlirnwR.js";
1
+ import { a as CerebroFs, P as Plugin } from "../../packem_shared/command.d-Dz7hkMI0.js";
2
2
  import '@visulima/tabular';
3
3
  type UpdateNotifierOptions = {
4
4
  alwaysRun?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@visulima/cerebro",
3
- "version": "3.1.0",
3
+ "version": "3.1.2",
4
4
  "description": "A delightful toolkit for building cross-runtime CLIs for Node.js, Deno, and Bun.",
5
5
  "keywords": [
6
6
  "ansi",
@@ -125,9 +125,9 @@
125
125
  },
126
126
  "peerDependencies": {
127
127
  "@bomb.sh/tab": ">=0.0.22",
128
- "@visulima/boxen": "4.0.0",
128
+ "@visulima/boxen": "5.0.0",
129
129
  "@visulima/find-cache-dir": "3.0.1",
130
- "@visulima/pail": "4.1.1",
130
+ "@visulima/pail": "5.0.0",
131
131
  "github-slugger": ">=2.0.0"
132
132
  },
133
133
  "peerDependenciesMeta": {
@@ -1,4 +0,0 @@
1
- import{createRequire as ct}from"node:module";import{VERBOSITY_DEBUG as V,POSITIONALS_KEY as oe,VERBOSITY_NORMAL as le,VERBOSITY_QUIET as vt,VERBOSITY_VERBOSE as At}from"./VERBOSITY_DEBUG-D7HfSD5l.js";import{C as N}from"./cerebro-error-Dv3FuXO8.js";import{c as re,d as we,o as Ne,e as F,a as Ct,b as bt,f as Nt,h as Ot,i as _t}from"./runtime-process-BN-eTlwy.js";import{c as ee}from"./VisulimaError-BDqtOVL5-Db_MJ_p7.js";import xt from"./InvalidArgumentChoiceError-BpovuqrZ.js";import Et from"./MissingArgumentError-D78kza2a.js";import kt from"./SurplusArgumentError-BLwT9lo0.js";import{X as It,O as $t,H as ie,c as q,M as X,k as P,F as ce,m as Oe,Q as _e,Y as Pt,U as xe,$ as Lt,W as Ee,d as ke,C as Ie,D as Ut,G as Mt,P as St,l as Tt,y as Dt,z as Vt,Z as jt,b as Rt,f as Bt,q as zt,j as Ft,v as Wt,J as qt,K as Gt,h as Kt,V as Ht}from"./constants-BKuEbBw1-BRv49X2l.js";import{distance as Xt}from"fastest-levenshtein";let ht;const ut=t=>(ht??=ct(import.meta.url))(t),Z=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,pt=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 ut(t)},{writeFile:ft,stat:dt,rm:gt,readFile:be,readdir:mt,mkdir:wt,access:yt}=pt("node:fs/promises"),te=[{alias:"v",description:"Turn on verbose output",group:"global",name:"verbose",type:Boolean},{description:"Turn on debugging output",group:"global",name:"debug",type:Boolean},{alias:"h",description:"Print out helpful usage information",group:"global",name:"help",type:Boolean},{alias:"q",description:"Silence output",group:"global",name:"quiet",type:Boolean},{alias:"V",description:"Print version info",group:"global",name:"version",type:Boolean},{description:"Turn off colored output",group:"global",name:"no-color",type:Boolean},{description:"Force colored output",group:"global",name:"color",type:Boolean}];class B extends N{commandName;constructor(e,n=[]){const s=`Command "${e}" not found${n.length>0?`. Did you mean: ${n.join(", ")}?`:""}`;super(s,"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(", ")}`)}}class Ke extends N{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}`}}class Yt extends N{unknownOptions;constructor(e,n){const s=e.join(", "),i=`Found unknown ${e.length===1?"option":"options"}: ${s}`;super(i,"UNKNOWN_OPTION",{suggestions:n,unknownOptions:e}),this.name="UnknownOptionError",this.unknownOptions=e,n&&n.length>0&&(this.hint=`Did you mean: ${n.join(", ")}?`)}}class Jt extends N{pluginName;constructor(e,n,s){super(`Plugin "${e}" error: ${n}`,"PLUGIN_ERROR",{originalError:s,pluginName:e}),this.name="PluginError",this.pluginName=e,s&&(this.cause=s)}}class Zt{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`);re().CEREBRO_OUTPUT_LEVEL===String(V)&&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 s of n)if(typeof s.init=="function"){this.logger.debug(`initializing plugin: ${s.name}`);try{await s.init(e)}catch(i){const o=new Jt(s.name,`Failed to initialize: ${i instanceof Error?i.message:String(i)}`,i instanceof Error?i:void 0);throw this.logger.error(o.message),o}}this.initialized=!0}async executeLifecycle(e,n,s){if(!this.initialized)throw new Error("PluginManager not initialized");if(this.plugins.size===0)return;const i=this.getDependencyOrder();for(const o of i){const c=o[e];if(typeof c=="function"){this.logger.debug(`executing ${e} hook for plugin: ${o.name}`);try{await(e==="afterCommand"?c(n,s):c(n))}catch(a){throw this.logger.error(`Error in ${e} hook for plugin "${o.name}":`,a),a}}}}async executeErrorHandlers(e,n){if(!this.initialized||this.plugins.size===0)return;const s=this.getDependencyOrder();for(const i of s)if(typeof i.onError=="function"){this.logger.debug(`executing error handler for plugin: ${i.name}`);try{await i.onError(e,n)}catch(o){this.logger.error(`Error in error handler for plugin "${i.name}":`,o)}}}getDependencyOrder(){if(this.cachedDependencyOrder!==void 0)return this.cachedDependencyOrder;const e=[],n=new Set,s=new Set,i=o=>{if(n.has(o))return;if(s.has(o))throw new Error(`Circular dependency detected involving plugin "${o}"`);const c=this.plugins.get(o);if(!c)throw new Error(`Plugin "${o}" not found`);if(s.add(o),c.dependencies)for(const a of c.dependencies)i(a);s.delete(o),n.add(o),e.push(c)};for(const o of this.plugins.keys())i(o);return this.cachedDependencyOrder=e,e}validateDependencies(){for(const e of this.plugins.values())if(e.dependencies){for(const n of e.dependencies)if(!this.plugins.has(n))throw new Error(`Plugin "${e.name}" depends on "${n}" which is not registered`)}}}const Q=t=>t.type?.name==="Boolean",Qt=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},$e=t=>(Q(t)||(t.typeLabel=t.typeLabel??Qt(t),t.defaultOption&&(t.typeLabel=`${t.typeLabel} (D)`),t.required&&(t.typeLabel=`${t.typeLabel} (R)`)),t),en=new RegExp(/^-([^\d-])$/),tn=new RegExp(/^--(\S+)/),nn=new RegExp(/^-([^\d-]{2,})$/),sn=t=>en.test(t)||tn.test(t)||nn.test(t),on=(t,e)=>{const n=e[0]&&sn(e[0])||e.length===0?null:e.shift()??null;if(!t.includes(n)){const s=new Error(`Command not recognised: ${String(n)}`);throw s.command=n,s.name="INVALID_COMMAND",s}return{argv:e,command:n}};class Ae extends ee{optionName;value;constructor(e,n,s){super({hint:`Pass a valid ${s} value for '${e}'.`,message:`Invalid ${s} value '${n}' for option '${e}'`,name:"INVALID_VALUE",title:"Invalid Value"}),this.optionName=e,this.value=n,Object.setPrototypeOf(this,Ae.prototype)}}let rn=class He extends ee{optionName;constructor(e){super({cause:void 0,hint:`Remove the duplicate option '${e}' from your command line arguments.`,location:void 0,message:`Option '${e}' is already set`,name:"ALREADY_SET",stack:void 0,title:"Option Already Set"}),this.optionName=e,Object.setPrototypeOf(this,He.prototype)}},Pe=class Xe extends ee{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,Xe.prototype)}};class Ce extends ee{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,Ce.prototype)}}let L=class Ye extends ee{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,Ye.prototype)}};const G=t=>t===Boolean||typeof t=="function"&&t.name==="Boolean",ye=t=>t===Number||typeof t=="function"&&t.name==="Number",Le=t=>t===String||typeof t=="function"&&t.name==="String",Ue=(t,e,n)=>{const s=Number(t);if(e&&Number.isNaN(s)&&String(t).trim().toLowerCase()!=="nan")throw new Ae(n??"",String(t),"Number");return s},an=(t,e,n={})=>{const{optionName:s,strictTypes:i}=n;return Array.isArray(t)?G(e)?t.map(Boolean):ye(e)?t.map(o=>Ue(o,i,s)):Le(e)?t.map(String):t.map(o=>e(String(o))):t===null?null:G(e)?!!t:ye(e)?Ue(t,i,s):Le(e)?typeof t=="string"?t:String(t):e(typeof t=="string"?t:String(t))},E=(t,e,n,...s)=>{t&&console.debug(`[command-line-args:${n}] ${e}`,...s)},ln=/-([a-z])/g,cn=/^\d+$/,hn=t=>t.codePointAt(0)===95,Me=(t,e)=>Array.isArray(t)?[...t,...e]:[t,...e],Se=t=>t==="__proto__"||t==="constructor"||t==="prototype",he=(t,e,n,s=!1)=>{t[e]===void 0?t[e]=s?[n]:n:s&&Array.isArray(t[e])?t[e].push(n):t[e]=[t[e],n]},Te=(t,e,n,s,i)=>{let o=e.get(t)??n.get(t);if(!o&&s){const c=t.toLowerCase();o=s.get(c)??i?.get(c)}return o},un=(t,e,n,s)=>{const i=n.debug??!1;E(i,"resolveArgs called with options:","resolver",{partial:n.partial,stopAtFirstUnknown:n.stopAtFirstUnknown}),E(i,"Starting argument resolution","resolver"),E(i,"Tokens:","resolver",t),E(i,"Definitions:","resolver",e),E(i,"Processing tokens...","resolver");const o=new Map,c=new Map,a=n.caseInsensitive?new Map:void 0,u=n.caseInsensitive?new Map:void 0,r=n.camelCase?new Map:void 0,l=n.camelCase?new Map:void 0;for(const f of e)if(o.set(f.name,f),f.alias&&c.set(f.alias,f),n.caseInsensitive&&a&&(a.set(f.name.toLowerCase(),f),f.alias&&u&&u.set(f.alias.toLowerCase(),f)),n.camelCase&&r&&l){const w=f.name.replaceAll(ln,(v,I)=>I.toUpperCase());r.set(f.name,w),l.set(w,f.name)}const p=Object.create(null),h=Object.create(null),m=[],d=[],y=new Set;let A=!1;const g=e.find(f=>f.defaultOption),C=e.some(f=>f.group),O=e.find(f=>ye(f.type));for(let f=0;f<t.length;f++){const w=t[f];if(w.kind==="option-terminator"){p._unknown=s.slice(w.index),A=!0;break}if(w.kind==="option"&&w.name){let v=Te(w.name,o,c,a,u);!v&&w.value===void 0&&O&&cn.test(w.name)&&(v=O,w.value=w.name,w.name=O.name);let I=!1;if(!v&&n.negation&&w.value===void 0&&w.name.startsWith("no-")){const _=w.name.slice(3),M=Te(_,o,c,a,u);M?.type&&G(M.type)&&(v=M,I=!0)}const b=v?v.name:w.name,$=v?.multiple,U=v?.lazyMultiple;if(Object.hasOwn(h,b)&&h[b]!==void 0&&!$&&!U&&!n.partial)throw new rn(b);if(!v&&n.partial){const _=w.rawName??`--${w.name}${w.value!==void 0&&w.inlineValue?`=${w.value}`:""}`;m.push({index:w.index,value:_});continue}if(!v&&n.stopAtFirstUnknown){p._unknown=s.slice(w.index);break}if(!v&&!n.partial)throw new Pe(w.name);if(w.value===void 0){const _=t[f+1],M=_?.kind==="option"&&!("name"in _)&&_.value!==void 0,T=_&&v&&!(v.type&&G(v.type))&&(_.kind==="positional"||M),lt=v&&v.defaultOption&&!v.multiple&&!v.lazyMultiple;if(T&&(!v?.defaultOption||lt))if($){let D=f+1;const ae=[];for(;D<t.length&&(t[D].kind==="positional"||t[D].kind==="option"&&!("name"in t[D])&&t[D].value!==void 0);)ae.push(t[D].value),y.add(t[D].index),D++;h[b]=h[b]===void 0?ae:Me(h[b],ae),f=D-1}else U?(he(h,b,_.value,!0),y.add(_.index),f++):(h[b]=_.value,y.add(_.index),f++);else v?.type&&G(v.type)?he(h,b,!I,$):($||U)&&h[b]!==void 0?he(h,b,null,!0):h[b]=$?[]:null}else{let{value:_}=w;if(v?.type&&G(v.type))switch(_){case"":{if(n.partial){const T=`${w.rawName??`--${w.name}`}${w.value?`=${w.value}`:""}`;d.push({index:w.index,value:T}),_=!0}else throw new Pe(w.name);break}case"false":{_=!1;break}case"true":{_=!0;break}default:_=!0}const M=[_];if($){let T=f+1;for(;T<t.length&&t[T].kind==="positional";)M.push(t[T].value),y.add(t[T].index),T++;f=T-1}h[b]===void 0?h[b]=$||U?M:_:$||U?h[b]=Me(h[b],M):h[b]=_}}else if(w.kind==="positional"&&n.stopAtFirstUnknown&&!y.has(w.index)&&!g){E(i,`Found unconsumed positional token at index ${String(w.index)}, stopping processing`,"resolver"),p._unknown=s.slice(w.index);break}}for(const[f,w]of Object.entries(h)){const v=o.get(f);v&&(v.multiple||v.lazyMultiple)&&!Array.isArray(w)&&(h[f]=[w])}const k=f=>f.kind==="option"&&!o.has(f.name??"")&&!c.has(f.name??"")&&(!n.caseInsensitive||!a?.has(f.name?.toLowerCase()??"")&&!u?.has(f.name?.toLowerCase()??""));let x=-1,H=Number.POSITIVE_INFINITY;if(n.stopAtFirstUnknown&&!A&&(x=t.findIndex(f=>k(f)),x!==-1&&(H=t[x].index)),g){const f=[],w=[];for(const v of t)v.kind==="positional"&&!y.has(v.index)&&v.index<H&&(f.push(v.value),w.push(v));if(f.length>0){const v=h[g.name],I=g.multiple??g.lazyMultiple;v===void 0?I?(w.forEach(b=>y.add(b.index)),h[g.name]=f):(y.add(w[0].index),h[g.name]=f[0]):I&&(w.forEach(b=>y.add(b.index)),h[g.name]=Array.isArray(v)?[...f,...v]:[...f,v])}}if(!n.partial){for(const f of t)if(f.kind==="positional"&&!y.has(f.index))throw new Ce(s[f.index])}if(n.partial&&!n.stopAtFirstUnknown){const f=[...m];for(const w of d)f.push({index:w.index,value:w.value});for(const w of t)w.kind==="positional"&&!y.has(w.index)&&f.push({index:w.index,value:s[w.index]});f.length>0&&(f.sort((w,v)=>w.index-v.index),p._unknown=f.map(w=>w.value))}if(n.stopAtFirstUnknown&&!A){const f=t.findIndex(v=>v.kind==="positional"&&!y.has(v.index));let w=-1;if(x!==-1&&f!==-1?w=Math.min(x,f):x!==-1?w=x:f!==-1&&(w=f),w>=0){const v=t[w].index;p._unknown=s.slice(v)}}for(const[f,w]of Object.entries(h)){const v=n.camelCase?r?.get(f)??f:f,I=o.get(f);I?.type?p[v]=an(w,I.type,{optionName:I.name,strictTypes:n.strictTypes}):p[v]=w===void 0?null:w}for(const f of e){const w=n.camelCase?r?.get(f.name)??f.name:f.name;!(w in p)&&f.defaultValue!==void 0&&(f.multiple??f.lazyMultiple?p[w]=Array.isArray(f.defaultValue)?[...f.defaultValue]:[f.defaultValue]:p[w]=f.defaultValue)}if(C){const f={},w={},v={};for(const b of e)if(b.group){const $=Array.isArray(b.group)?b.group:[b.group];for(const U of $)Se(U)||(f[U]??={})}for(const b of Object.keys(p))if(!hn(b)){w[b]=p[b];let $=b;n.camelCase&&($=l?.get(b)??b);const U=o.get($);if(U?.group){const _=Array.isArray(U.group)?U.group:[U.group];for(const M of _)Se(M)||f[M]&&(f[M][b]=p[b])}else v[b]=p[b]}const I={_all:w};for(const[b,$]of Object.entries(f))I[b]=$;Object.keys(v).length>0&&(I._none=v),p._unknown&&(I._unknown=p._unknown),Object.keys(p).forEach(b=>delete p[b]),Object.assign(p,I)}const S=Object.defineProperties({},Object.getOwnPropertyDescriptors(p));return E(i,"Final parsed result:","resolver",S),S},Je="-",J=Je.codePointAt(0),K="=",pn=K.codePointAt(0),fn="--",dn=Je,gn="--",Ze=t=>t.length>2&&t.startsWith(gn),mn=t=>Ze(t)&&!t.includes(K,3),wn=t=>Ze(t)&&t.includes(K,3),yn=t=>{if(t.length!==2||t.codePointAt(0)!==J||t.codePointAt(1)===J)return!1;const e=t.codePointAt(1);return e!==void 0&&(e<48||e>57)},vn=t=>{if(t.length<=2||t.codePointAt(0)!==J||t.codePointAt(1)===J)return!1;const e=t.codePointAt(1);return!(e!==void 0&&e>=48&&e<=57)},An=t=>{const e=[];let n=0,s=[],i=0,o=-1,c=0;for(;i<s.length||n<t.length;){let a;if(i<s.length?(a=s[i],i++):(a=t[n],n++),c>0?c--:o++,a===fn){e.push({index:o,kind:"option-terminator"});const u=[...s.slice(i),...t.slice(n)],r=u.map((l,p)=>({index:o+p+1,kind:"positional",value:l}));e.push(...r),o+=u.length;break}if(yn(a)){const u=a.charAt(1);e.push({index:o,kind:"option",name:u,rawName:a});continue}if(vn(a)&&!a.includes(K)){const u=[];let r="",l=!1;for(let p=1;p<a.length;p++){const h=a.charAt(p);l?r+=h:h.codePointAt(0)===pn?l=!0:u.push(`${dn}${h}`)}if(l)if(u.length>0){const p=u.pop();u.push(`${p}=${r}`)}else u.push(r);s=i<s.length?[...u,...s.slice(i)]:u,i=0,c=u.length;continue}if(mn(a)){const u=a.slice(2);e.push({index:o,kind:"option",name:u,rawName:a});continue}if(wn(a)){const u=a.indexOf(K),r=a.slice(2,u),l=a.slice(u+1);e.push({index:o,inlineValue:!0,kind:"option",name:r,rawName:a,value:l});continue}if(a.length>2&&a.codePointAt(0)===J&&a.codePointAt(1)!==J&&a.includes(K)){const u=a.indexOf(K),r=a.charAt(1),l=a.slice(u+1);e.push({index:o,inlineValue:!0,kind:"option",name:r,rawName:a,value:l});continue}e.push({index:o,kind:"positional",value:a})}return e},Cn=/\d/,bn=t=>typeof t=="function",Nn=(t,e,n)=>{const s=n?.debug??!1;E(s,"Validating definitions:","validation",t,"caseInsensitive:",e);const i=new Set,o=new Set,c=new Set,a=new Set;let u=0;for(const r of t){if(E(s,"Checking definition:","validation",r),!r.name)throw E(s,"Validation failed: name is required","validation"),new L("Invalid option definition: name is required");if(typeof r.name!="string")throw new L("Invalid option definition: name must be a string");if(r.name.trim()==="")throw new L("Invalid option definition: name cannot be empty");const l=e?r.name.toLowerCase():"";if(i.has(r.name)||e&&c.has(l))throw new L(`Invalid option definition: duplicate name '${r.name}'`);if(o.has(r.name)||e&&a.has(l))throw new L(`Invalid option definition: name '${r.name}' conflicts with an existing alias`);if(i.add(r.name),e&&c.add(l),r.alias!==void 0){if(typeof r.alias!="string")throw new L("Invalid option definition: alias must be a string");if(r.alias.length!==1)throw new L("Invalid option definition: alias must be a single character");if(Cn.test(r.alias))throw new L("Invalid option definition: alias cannot be numeric");if(r.alias==="-")throw new L('Invalid option definition: alias cannot be "-"');const p=e?r.alias.toLowerCase():"";if(o.has(r.alias)||e&&a.has(p))throw new L(`Invalid option definition: duplicate alias '${r.alias}'`);if(i.has(r.alias)||e&&c.has(p))throw new L(`Invalid option definition: alias '${r.alias}' conflicts with an existing option name`);o.add(r.alias),e&&a.add(p)}if(r.defaultOption&&(u++,r.type!==void 0&&G(r.type)))throw new L("Invalid option definition: defaultOption cannot be Boolean type");if(r.type!==void 0&&!(r.type===Boolean||r.type===Number||r.type===String||typeof r.type=="function"&&bn(r.type)))throw new L("Invalid option definition: invalid type")}if(u>1)throw E(s,"Validation failed: multiple defaultOptions not allowed","validation"),new L("Invalid option definition: multiple defaultOptions not allowed");E(s,"Validation completed successfully","validation")};function On(t,e={}){const n=e.debug??!1;E(n,"Starting command-line-args parsing","index"),E(n,"Options:","index",e);const s={...e};s.stopAtFirstUnknown&&(s.partial=!0);const i=Array.isArray(t)?t:[t];E(n,"Normalized definitions:","index",i),Nn(i,s.caseInsensitive,n?s:void 0);let{argv:o}=s;o??=process.argv.slice(2),E(n,"Using argv:","index",o);let c=o;s.caseInsensitive&&(c=o.map(r=>{if(r.startsWith("--")){const l=r.indexOf("="),p=(l===-1?r.slice(2):r.slice(2,l)).toLowerCase();return l===-1?`--${p}`:`--${p}${r.slice(l)}`}if(r.startsWith("-")&&!r.startsWith("--")&&r.length>1){const l=r.indexOf("="),p=l===-1?r.slice(1):r.slice(1,l);if(!p)return r;const h=p.toLowerCase();return l===-1?`-${h}`:`-${h}${r.slice(l)}`}return r}));const a=An(c.map(String));E(n,"Tokenized arguments:","index",a);const u=un(a,i,s,o);return E(n,"Command-line-args parsing completed","index"),u}class _n{result;argv;options;argument;args;command;commandName;env;logger;console;fs;process;runtime;rawUnknown;constructor(e,n){this.commandName=e,this.command=n}}class ue extends N{commandName;constructor(e,n,s){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.",s!==void 0&&(this.cause=s)}}const xn=/^-{1,2}(\w+)(=(.+))?$/,Qe=(t,e,n,s)=>{const i=xn.exec(t);if(i===null)return{};const o=i[1];if(!o)return{};const c=n&&s?n.get(o)??s.get(o):e.find(a=>a.name===o||a.alias===o);return c!==void 0?{argName:c.name,argValue:i[3],option:c}:{}},De=(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)},En=new Set(["0","1","false","true"]),kn=(t,e,n,s)=>{if(e.length===0||t.length===0)return{};const i=(o,c)=>{const{argName:a,argValue:u,option:r}=Qe(c,e,n,s),{lastOption:l}=o;return r&&Q(r)&&u&&a?o.partial[a]=De(u,r):o.lastName&&l&&Q(l)&&En.has(c)&&(o.partial[o.lastName]=De(c,l)),{lastName:a,lastOption:r,partial:o.partial}};return t.reduce(i,{partial:{}}).partial},In=new Set(["0","1","false","true"]),$n=(t,e,n,s)=>{if(e.length===0||t.length===0)return t;const i=(o,c)=>{const{argValue:a,option:u}=Qe(c,e,n,s),{lastOption:r}=o;if(r&&Q(r)&&In.has(c)){const{args:p}=o;return{args:p.slice(0,-1)}}return u&&Q(u)&&a?{args:o.args}:{args:[...o.args,c],lastOption:u}};return t.reduce(i,{args:[]}).args},Ve=t=>{const e=new Map;for(const n of t){const s=e.get(n.name);s?e.set(n.name,{...s,...n}):e.set(n.name,n)}return[...e.values()]},Pn=t=>{if(t===void 0)return;const e=t.toLowerCase().trim();return e==="true"||e==="1"||e==="yes"||e==="on"},Ln=(t,e)=>{if(!t.type)return e;if(e===void 0)return;if(t.type===Boolean||typeof t.type=="function"&&t.type.name==="Boolean")return Pn(e);if(t.type===Number||typeof t.type=="function"&&t.type.name==="Number"){const o=Number.parseFloat(e);return Number.isNaN(o)?void 0:o}return t.type===String||typeof t.type=="function"&&t.type.name==="String"?e:t.type(e)},Un=/_./g,Mn=/^[A-Z]/,Sn=t=>t.toLowerCase().replaceAll(Un,e=>e[1]?.toUpperCase()??e).replace(Mn,e=>e.toLowerCase()),Tn=(t,e=re())=>{if(!t||t.length===0)return{};const n={};for(const s of t){const i=e[s.name],o=Ln(s,i),c=o===void 0?s.defaultValue:o,a=Sn(s.name);n[a]=c}return n},Dn=/-([a-z])/g,et=t=>t.replaceAll(Dn,(e,n)=>n.toUpperCase()),je=(t,e)=>t.type===void 0?e:t.type(e),Vn=(t,e)=>{const{choices:n}=t;if(!n||n.length===0)return[];const s=[];for(const i of e)n.includes(i)||s.push({choices:n,name:t.name,value:i});return s},jn=(t,e)=>e&&t.defaultValue!==void 0&&!Array.isArray(t.defaultValue)?[t.defaultValue]:t.defaultValue,Rn=(t,e)=>{const n={},s=[],i=[],o=t.length-1;let c=0;for(const[a,u]of t.entries()){const r=et(u.name),l=a===o&&u.multiple===!0,p=l?e.slice(a):e.slice(a,a+1);if(p.length===0){u.required===!0&&s.push(u.name),n[r]=jn(u,l);continue}i.push(...Vn(u,p)),c=a+p.length,n[r]=l?p.map(h=>je(u,h)):je(u,p[0])}return{invalid:i,missing:s,resolved:n,surplus:e.slice(c)}},Bn=t=>{const e=new Map,n=new Map;for(const s of t)if(e.set(s.name,s),s.alias){const i=Array.isArray(s.alias)?s.alias:[s.alias];for(const o of i)n.set(o,s)}return{optionMapByAlias:n,optionMapByName:e}},tt=async t=>{if(typeof t.__resolvedExecute__=="function")return t.__resolvedExecute__;if(typeof t.loader!="function")throw new ue(t.name,"no execute or loader defined");let e;try{e=await t.loader()}catch(s){throw new ue(t.name,s instanceof Error?s.message:String(s),s)}const n=e.default;if(typeof n!="function")throw new ue(t.name,"loader did not return a module with a default-exported handler function");return t.__resolvedExecute__=n,n},zn=(t,e,n,s,i)=>{const o=new _n(t.name,t),{_all:c,_unknown:a,positionals:u}=e,l=Object.keys(n).length>0?{...c,...n}:c;oe in l&&delete l[oe],o.argument=u?.[oe]??[],o.args={},o.rawUnknown=[...a??[]];const p=Object.keys(s).length>0;return o.options=p?{...l,...s}:l,o.env=Tn(t.env,i),o},Fn=(t,e,n)=>{const s=t.options??[],i=s.length>0;let o=Ve(i?[...s,...n]:n);if(o.length>0){for(const l of o)if(l.multiple&&l.lazyMultiple)throw new Error(`Argument "${l.name}" cannot have both multiple and lazyMultiple options, please choose one.`)}const c=t.arguments!==void 0&&t.arguments.length>0;(t.argument||c)&&(o=[{defaultOption:!0,description:t.argument?.description,group:"positionals",multiple:!0,name:oe,type:t.argument?.type??String,typeLabel:t.argument?.typeLabel},...o]);let a,u;if(i){const{optionMapByAlias:l,optionMapByName:p}=Bn(s);a=$n(e,s,p,l),u=kn(e,s,p,l)}else a=e,u={};const r=On(o,{argv:a,camelCase:!0,partial:!0,stopAtFirstUnknown:!0});return{arguments_:o,booleanValues:u,parsedArgs:r}},pe=async(t,e,n)=>typeof t.execute=="function"?t.execute(e):(await tt(t))(e),Wn=(t,e)=>{if(!t.arguments||t.arguments.length===0)return;const n=e.rawUnknown.indexOf("--"),s=n===-1?[]:e.rawUnknown.slice(n+1),i=s.length===0?e.argument:e.argument.slice(0,Math.max(0,e.argument.length-s.length)),o=Rn(t.arguments,i);if(e.args=o.resolved,o.missing.length>0)throw new Et(t.name,o.missing);const[c]=o.invalid;if(c)throw new xt(c.name,c.value,c.choices);if(o.surplus.length>0)throw new kt(t.name,o.surplus,t.arguments.length)};let qn=class{capacity;cache;constructor(e){this.capacity=e,this.cache=new Map}get(e){if(!this.cache.has(e))return;const n=this.cache.get(e);return this.cache.delete(e),this.cache.set(e,n),n}has(e){return this.cache.has(e)}set(e,n){if(this.cache.has(e))this.cache.delete(e);else if(this.cache.size>=this.capacity){const s=this.cache.keys().next().value;s!==void 0&&this.cache.delete(s)}this.cache.set(e,n)}delete(e){this.cache.delete(e)}clear(){this.cache.clear()}size(){return this.cache.size}};const Gn=(t,e)=>typeof t!="string"||t===""?"":t[0].toLowerCase()+t.slice(1),Kn=new RegExp("[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d/#&.:=?%@~_]*)*)?(?:\\u0007|\\u001B\\u005C|\\u009C))|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))","g"),Hn=t=>{if(typeof t!="string")throw new TypeError(`The "value" argument must be of type string. Received ${typeof t}`);return t.replaceAll(Kn,"")},fe=new qn(1e3),Xn=/[.*+?^${}()|[\]\\]/g,Yn=t=>{const e=t.join("");if(fe.has(e)){const i=fe.get(e);return i.lastIndex=0,i}const n=t.map(i=>i.replaceAll(Xn,String.raw`\$&`)).join("|"),s=new RegExp(n,"g");return fe.set(e,s),s},Jn=t=>{const e=[];let n=0,s;for(q.lastIndex=0;(s=q.exec(t))!==null;)s.index>n&&e.push(t.slice(n,s.index)),e.push(s[0]),n=q.lastIndex;return n<t.length&&e.push(t.slice(n)),e.filter(Boolean)},Zn=/[ČŠŽĐ]/i,nt=new Uint8Array(128),st=new Uint8Array(128),ot=new Uint8Array(128);for(let t=0;t<128;t++)nt[t]=t>=65&&t<=90?1:0,st[t]=t>=97&&t<=122?1:0,ot[t]=t>=48&&t<=57?1:0;const de=t=>nt[t],Re=t=>st[t],ge=t=>ot[t],j=(t,e,n,s,i)=>{if(t.length===0)return[];let o=!1;const c=Object.values(e);for(const m of c)if(m(t[0])){o=!0;break}if(!o&&!n)return[t];const a=[...t],u=[];let r=a[0],l="other";const p=Object.entries(e);for(const m of p){const[d,y]=m;if(y(a[0])){l=d;break}}let h=n&&s?a[0]===a[0].toLocaleUpperCase(s):!1;for(let m=1;m<a.length;m++){const d=a[m];let y="other";for(const C of p){const[O,k]=C;if(k(d)){y=O;break}}const A=n&&s?d===d.toLocaleUpperCase(s):!1;let g=!1;i?g=i(l,y,h,A,d,m,a):(l!==y&&l!=="other"&&y!=="other"&&(g=!0),n&&y!=="other"&&!h&&A&&(g=!0)),g?(u.push(r),r=d):r+=d,l=y,n&&(h=A)}return r&&r.length>0&&u.push(r),u.length>0?u:[t]},Qn=(t,e,n,s)=>{if(n.size===0)return e;for(const i of n)if(t.startsWith(i,e))return s.push(i),e+i.length;return e},it=(t,e=new Set)=>{if(t.length===0)return[];if(t.toUpperCase()===t)return[t];let n=0;const s=[],i=t.length;for(let o=1;o<i;o++){const c=Qn(t,n,e,s);if(c!==n){n=c,o=n-1;continue}const a=t.codePointAt(o-1),u=t.codePointAt(o),r=a&&a<128&&de(a),l=u&&u<128&&de(u),p=a&&a<128&&Re(a),h=a&&a<128&&ge(a),m=u&&u<128&&ge(u);if(p&&l){s.push(t.slice(n,o)),n=o;continue}if(h&&!m||!h&&m){s.push(t.slice(n,o)),n=o;continue}if(m&&!h){let d=!1,y=!1;if(o+1<i){const A=t.codePointAt(o+1);d=A&&A<128&&de(A),y=A&&A<128&&ge(A)}if(!y&&d){s.push(t.slice(n,o),t.slice(o,o+1)),n=o+1;continue}}if(o+1<i){const d=t.codePointAt(o+1),y=d&&d<128&&Re(d);if(r&&l&&y){const A=t.slice(n,o+1);e.has(A)||(s.push(t.slice(n,o)),n=o)}}}return n<i&&s.push(t.slice(n)),s.filter(o=>o!=="")},rt=(t,e,n)=>{if(t.length===0)return[];const s=t===t.toLocaleUpperCase(e);if(e.startsWith("de")){if(!s&&t.replaceAll("ß","SS")===t.toLocaleUpperCase(e))return[t];const r=[...t],l=r.length,p=[];let h=r[0],m=r[0]===r[0].toLocaleUpperCase(e),d=m,y=m?0:-1;for(let A=1;A<l;A++){const g=r[A],C=g===g.toLocaleUpperCase(e);if(C===m)h+=g;else if(C)h&&h.length>0&&(p.push(h),h=g),d=!0,y=A;else{if(d&&A-y>1){const O=r[A-1],k=h.slice(0,-1);k&&k.length>0&&p.push(k),h=O+g}else h+=g;d=!1,y=-1}m=C}return h&&h.length>0&&p.push(h),p}if(e.startsWith("uk")||e.startsWith("ru")||e.startsWith("bg")||e.startsWith("sr")||e.startsWith("mk")||e.startsWith("be")){if(!X.test(t)&&!P.test(t))return[t];const r=[...t],l=r.length,p=[];let h=r[0];const m=r[0];let d;X.test(m)?d=1:P.test(m)?d=2:d=0;let y=m===m.toLocaleUpperCase(e);for(let g=1;g<l;g++){const C=r[g];let O;X.test(C)?O=1:P.test(C)?O=2:O=0;const k=C===C.toLocaleUpperCase(e);d!==O&&(d===1||d===2)&&(O===1||O===2)||O===d&&!y&&k?(p.push(h),h=C):h+=C,d=O,y=k}h&&h.length>0&&p.push(h);const A=[];for(let g=0;g<p.length;g++)g<p.length-1&&p[g].length===1&&P.test(p[g])&&X.test(p[g+1][0])?(A.push(p[g]+p[g+1]),g+=1):A.push(p[g]);return A}if(e.startsWith("el")){if(!ce.test(t)&&!P.test(t))return[t];const r=[];Oe.lastIndex=0;let l;for(;(l=Oe.exec(t))!==null;)r.push(l[0]);r.length===0&&r.push(t);const p=[];if(r.length===1){const h=r[0];if(!h||!ce.test(h[0])||h.length===1)return[h??t]}for(const h of r){if(!h)continue;if(!ce.test(h[0])||h.length===1){p.push(h);continue}const m=h.length;let d=h[0],y=h[0]===h[0].toLocaleUpperCase(e);for(let A=1;A<m;A++){const g=h[A],C=g===g.toLocaleUpperCase(e);!y&&C?(p.push(d),d=g):d+=g,y=C}d&&p.push(d)}return p}if(e.startsWith("ja")||e.startsWith("ko")){const r=e.startsWith("ja"),l=r?{hiragana:h=>Lt.test(h),kanji:h=>xe.test(h),katakana:h=>Pt.test(h),latin:h=>P.test(h)}:{hangul:h=>Ee.test(h),latin:h=>P.test(h)},p=new Set(["が","で","と","に","の","は","へ","も","や","を"]);if(r){const h=j(t,l,!1,e,(d,y)=>d==="hiragana"&&y==="katakana"||d==="katakana"&&y==="hiragana"||d==="hiragana"&&y==="latin"||d==="katakana"&&y==="latin"||d==="kanji"&&y==="latin"||d==="latin"&&(y==="hiragana"||y==="katakana"||y==="kanji")),m=[];for(const d of h){const y=d;y.length===1&&p.has(y)&&m.length>0?m[m.length-1]=m.at(-1)+y:m.push(y)}return m.length>0?m:[t]}return j(t,l,!1,e,(h,m)=>h==="hangul"&&m==="latin"||h==="latin"&&m==="hangul")}if(e.startsWith("sl")){const r=[...t],l=r.length,p=[];let h=r[0],m=r[0]===r[0].toLocaleUpperCase(e);for(let d=1;d<l;d++){const y=r[d],A=y===y.toLocaleUpperCase(e),g=Zn.test(y),C=d<l-1&&r[d+1]===r[d+1].toLocaleUpperCase(e);!m&&A||g&&C?(p.push(h),h=y,g&&C&&(p.push(h),h="")):h+=y,m=A}return h&&h.length>0&&p.push(h),p}if(e.startsWith("zh"))return j(t,{han:r=>xe.test(r),latin:r=>P.test(r)},!1,e);if(["ar","fa","he","ur"].includes(e.split("-")[0])){const r=l=>ke.test(l)||Ie.test(l);return j(t,{latin:l=>P.test(l),rtl:l=>r(l)},!1,e)}if(["am","bn","gu","hi","km","kn","lo","ml","mr","ne","or","pa","si","ta","te","th"].includes(e.split("-")[0])){const r=l=>Ut.test(l)||Mt.test(l)||St.test(l)||Tt.test(l)||Dt.test(l)||Vt.test(l)||jt.test(l)||Rt.test(l)||Bt.test(l)||zt.test(l)||Ft.test(l)||Wt.test(l)||qt.test(l)||Gt.test(l)||Kt.test(l)||Ht.test(l);return j(t,{indic:l=>r(l),latin:l=>P.test(l)},!1,e)}if(["be","bg","ru","sr","uk"].includes(e))return j(t,{cyrillic:r=>X.test(r),latin:r=>P.test(r)},!0,e);if(["ar","fa","he"].includes(e))return j(t,{latin:r=>P.test(r),rtl:r=>ke.test(r)||Ie.test(r)},!1,e);if(e.startsWith("ko"))return j(t,{hangul:r=>Ee.test(r),latin:r=>P.test(r)},!1,e);if(e.startsWith("uz")){if(!X.test(t)&&!P.test(t))return[t];const r=[...t],l=r.length,p=[];let h=r[0],m=r[0]===r[0].toLocaleUpperCase(e);for(let d=1;d<l;d++){const y=r[d],A=y===y.toLocaleUpperCase(e);if(_e.test(y)||_e.test(r[d-1])){h+=y;continue}!m&&A?(p.push(h),h=y):h+=y,m=A}return h&&h.length>0&&p.push(h),p}const i=[...t],o=i.length,c=[];let a=i[0],u=i[0]===i[0].toLocaleUpperCase(e);for(const r of n)if(t.startsWith(r)){c.push(r),a=i[r.length],u=a===a.toLocaleUpperCase(e);break}for(let r=1;r<o;r++){const l=i[r],p=l===l.toLocaleUpperCase(e);let h=0;for(const m of n)if(t.startsWith(m,r)){c.push(a,m),h=m.length,a="";const d=m.at(-1);d&&(u=d===d.toLocaleUpperCase(e));break}if(h>0){r+=h-1;continue}!u&&p?(c.push(a),a=l):a+=l,u=p}return a&&c.push(a),c},es=(t,e,n)=>{const s=[],i=ie.test(t)?t.split(ie).filter(Boolean):[t];for(const o of i){const c=o;if(ie.test(c))s.push(c);else{q.lastIndex=0;const a=q.test(c)?Jn(c).filter(Boolean):[c];for(const u of a)if(q.lastIndex=0,q.test(u))s.push(u);else if(e){const r=e.toLowerCase().split("-")[0];s.push(...rt(u,r,n))}else s.push(...it(u,n))}}return s},ts=(t,e={})=>{if(!t||typeof t!="string")return[];const{handleAnsi:n=!1,handleEmoji:s=!1,knownAcronyms:i=[],locale:o,normalize:c=!1,separators:a,stripAnsi:u=!1,stripEmoji:r=!1}=e,l=new Set([...i].toSorted((g,C)=>C.length-g.length));let p=t;u&&(p=Hn(p)),r&&(p=It(p));let h;Array.isArray(a)?h=Yn(a):a instanceof RegExp?h=a:h=$t;const m=[];let d=p;const y=h.flags.includes("g")?h:new RegExp(h.source,`${h.flags}g`);for(;d.length>0;){const g=y.exec(d);if(!g){d===".."?m.push(".."):d==="."?m.push("."):d.length>0&&m.push(d);break}const C=g.index,O=g[0],k=O.length,x=d.slice(0,C),H=d.slice(C+k);if(O.startsWith("../"))m.push(".."),d=d.slice(C+3);else if(O.startsWith("./"))m.push("."),d=d.slice(C+2);else if(C===0&&O==="..")m.push(".."),d=d.slice(2);else if(C===0&&O===".")m.push("."),d=d.slice(1);else{x.length>0&&m.push(x);let S=0;for(;(S=O.indexOf("../",S))!==-1;)m.push(".."),S+=3;for(S=0;(S=O.indexOf("./",S))!==-1;)(S===0||O[S-1]!==".")&&m.push("."),S+=2;let f=H;for(;f.startsWith("../");)m.push(".."),f=f.slice(3);for(;f.startsWith("./");)m.push("."),f=f.slice(2);if(f===".."){m.push("..");break}else if(f==="."){m.push(".");break}else d=f}y.lastIndex=0}if(m.length===0){const g=p.split(h).filter(Boolean);m.push(...g)}let A=[];for(const g of m)n||s?A.push(...es(g,o,l)):o?A.push(...rt(g,o,l)):A.push(...it(g,l));return c&&(A=A.map(g=>l.has(g)?g:o&&g===g.toLocaleUpperCase(o)?g[0]+g.slice(1).toLocaleLowerCase(o):g.toUpperCase()===g&&!l.has(g)?g.slice(0,1)+g.slice(1).toLowerCase():g)),A},ns=(t,e)=>typeof t!="string"||t===""?"":t[0].toUpperCase()+t.slice(1),ss=(t,e)=>{const{length:n}=t;if(n===0)return"";if(n===1)return t[0];const s=[];let i="",o="";for(let c=0;c<n;c++){const a=t[c];if(ie.test(a)){i?(s.push(i+o+a),i="",o=""):(s.length>0&&s.push(e),i=a);continue}i?(o&&(o+=e),o+=a):(s.length>0&&s.push(e),s.push(a))}return s.join("")},Y=(t,e)=>{if(typeof t!="string"||!t)return"";let n=!0;return ss(ts(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(i=>{const o=i,c=o.toLowerCase();return n?(n=!1,Gn(c)):ns(c)}),"")};class os extends N{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(", ")}`}}class is extends N{choices;option;value;constructor(e,n,s){super(`Invalid value "${n}" for option "${e}". Allowed values: ${s.join(", ")}`,"INVALID_CHOICE",{choices:s,option:e,value:n}),this.name="InvalidChoiceError",this.option=e,this.value=n,this.choices=s,this.hint=`Use one of: ${s.map(i=>`--${e} ${i}`).join(", ")}`}}const Be=(t,e,n=!1)=>{const s=[],i=e._all??e;for(const o of t){if(!n&&!o.required)continue;const c=o.__camelCaseName__??o.name;if(i[c]===void 0){if(o.type?.name==="Boolean"){e[c]=!1;continue}s.push(o)}}return s},rs=(t,e)=>e.includes(t)?!0:Math.abs(t.length-e.length)>t.length/2?!1:Xt(t,e)<=t.length/3,R=(t,e)=>{const n=t.toLowerCase();return e.filter(s=>rs(s.toLowerCase(),n))},as=(t,e)=>{const n=[];if(t._unknown&&t._unknown.forEach(s=>{const i=s.startsWith("--");let o=`Found unknown ${i?"option":"argument"} "${s}"`;if(i){const c=R(s.replace("--",""),(e.options??[]).map(a=>a.name));if(c.length>0){const[a,...u]=c.map(r=>`--${r}`);o+=u.length>0?`, did you mean ${a??""} or ${u.join(", ")}?`:`, did you mean ${a??""}?`}}n.push(o)}),n.length>0)throw new Error(n.join(`
2
- `))},W=(t,e)=>new N(`Command "${t}" ${e}`,"INVALID_COMMAND",{commandName:t}),ls=(t,e)=>{const n=new Set;for(const[s,i]of t.entries()){if(typeof i!="object"||i===null)throw W(e,`has a positional argument at index ${String(s)} that is not an object`);const{name:o}=i;if(typeof o!="string"||o.length===0)throw W(e,`has a positional argument at index ${String(s)} without a name`);const c=et(o);if(n.has(c))throw W(e,`declares duplicate positional argument "${o}"`);n.add(c);const a=s===0?void 0:t[s-1];if(i.required===!0&&a!==void 0&&a.required!==!0)throw W(e,`declares required positional "${o}" after an optional one, which can never be satisfied`);if(i.multiple===!0&&s!==t.length-1)throw W(e,`declares a variadic positional "${o}" that is not the last one`)}},cs=(t,e,n)=>{const s=n.__requiredOptions__,i=s?Be(s,e,!0):Be(t,e,!1);if(i.length>0)throw new os(n.name,i.map(o=>o.name));e._unknown&&e._unknown.length>0&&!n.argument&&!n.arguments?.length&&as(e,n)},hs=(t,e,n)=>{const s=n.__conflictingOptions__??t.filter(i=>i.conflicts!==void 0);if(s.length>0){const i=s.find(o=>{const c=o.__camelCaseName__??Y(o.name);return Array.isArray(o.conflicts)?o.conflicts.some(a=>e[Y(a)]!==void 0)&&e[c]!==void 0:e[Y(o.conflicts)]!==void 0&&e[c]!==void 0});if(i)throw new Ke(i.name,typeof i.conflicts=="string"?i.conflicts:i.conflicts?.[0]??"unknown")}},us=(t,e)=>{const n=e.options;if(n)for(const s of n){if(!s.choices||s.choices.length===0)continue;const i=s.__camelCaseName__??Y(s.name),o=t[i];if(o==null)continue;const c=Array.isArray(o)?o:[o];for(const a of c){const u=String(a);if(!s.choices.includes(u))throw new is(s.name,u,s.choices)}}},ps=t=>{if(!Array.isArray(t.options))return;const e=new Map,n=new Map;for(const i of t.options){if(i.name){const o=e.get(i.name)??[];o.push(i),e.set(i.name,o)}if(typeof i.alias=="string"&&i.alias.length>0){const o=n.get(i.alias)??[];o.push(i),n.set(i.alias,o)}else if(Array.isArray(i.alias)){for(const o of i.alias)if(o.length>0){const c=n.get(o)??[];c.push(i),n.set(o,c)}}}const s=[];for(const[i,o]of e)o.length>1&&s.push(`Duplicate option name "${i}" in command "${t.name}": ${JSON.stringify(o)}`);for(const[i,o]of n)o.length>1&&s.push(`Duplicate option alias "-${i}" used by options ${o.map(c=>`"${c.name}"`).join(", ")} in command "${t.name}"`);if(s.length>0)throw new Error(s.join(`
3
- `))},fs=t=>{const{arguments:e}=t;if(e!==void 0){if(!Array.isArray(e))throw W(t.name,'must declare "arguments" as an array — slot order is significant, so a record cannot express it');if(t.argument!==void 0)throw W(t.name,'cannot define both "argument" and "arguments" — choose one');ls(e,t.name)}},ds=(t,e)=>{if(e.length===0)return{argv:[],commandPath:void 0};const n=[];let s;for(let i=1;i<=e.length;i+=1){const o=e[i-1];if(o===void 0||o.startsWith("-"))break;n.push(o);const c=n.join(" ");t.has(c)&&(s={commandPath:[...n],depth:i})}return s?{argv:e.slice(s.depth),commandPath:s.commandPath}:{argv:e,commandPath:void 0}},z=t=>t.join(" "),ze=(t,e)=>e&&e.length>0?[...e,t]:[t],Fe=t=>t===void 0||Array.isArray(t)?t:Object.entries(t).map(([e,n])=>({...n,name:e})),gs=t=>{const e=Fe(t.options),n=Fe(t.env);return e===t.options&&n===t.env?t:Object.assign(Object.create(Object.getPrototypeOf(t)),t,{env:n,options:e})},ms=/^no-/,ws=t=>{t.options?.forEach(e=>{e.__camelCaseName__=Y(e.name)})},ys=t=>{if(!Array.isArray(t.options)||t.options.length===0)return;const e=new Set;for(const s of t.options)e.add(s.name);const n=[];for(const s of t.options)if(s.name.startsWith("no-")){const i=s.name.replace(ms,"");if(!e.has(i)){if(s.type!==Boolean)throw new Error(`Cannot add negated option "${s.name}" to command "${t.name}" because it is not a boolean.`);const o={...s,defaultValue:s.defaultValue===void 0?!0:!s.defaultValue,name:i};n.push(o),e.add(i)}}n.length>0&&t.options.push(...n)},vs=(t,e)=>{if(!e.options||e.options.length===0)return;const{options:n}=t,s=new Map;for(const o of e.options)if(o.name.startsWith("no-")){const c=Y(o.name);s.set(c,o)}const i=Object.keys(n).filter(o=>s.has(o));if(i.length!==0)for(const o of i){const c=o.charAt(2);if(!c)continue;const a=c.toLowerCase()+o.slice(3),u=s.get(o);u&&(u.__negated__=!0),n[a]=!n[o],Reflect.deleteProperty(n,o)}},As=(t,e)=>{if(!e.options||e.options.length===0)return;const n=new Map;for(const i of e.options)i.__camelCaseName__&&i.__negated__===void 0&&i.implies!==void 0&&n.set(i.__camelCaseName__,i);if(n.size===0)return;const{options:s}=t;for(const i of Object.keys(s)){const o=n.get(i);if(o?.implies){const{implies:c}=o;for(const[a,u]of Object.entries(c))s[a]===void 0&&(s[a]=u)}}},Cs=()=>!!process.versions.electron,bs=()=>Cs()&&!process.defaultApp,Ns=()=>bs()?0:1,Os=t=>t.slice(Ns()+1),_s=" ",xs=(t,e)=>t===e?!0:t.length!==e.length?!1:t.every((n,s)=>n===e[s]),Es=t=>{if(typeof t=="string")return t.split(_s);const e=we();return xs(t,e)?Os(t):t},ks=t=>{const e=o=>{t.error(`Uncaught exception: ${o.message||o}`),o.stack&&t.error(o.stack),F(1)},n=(o,c)=>{if(o instanceof Error)t.error(`Promise rejection: ${o.message||o}`),o.stack&&t.error(o.stack);else{let a;if(typeof o=="string")a=o;else try{a=JSON.stringify(o)}catch{a=String(o)}t.error(`Promise rejection: ${a}`)}F(1)},s=Ne("uncaughtException",e),i=Ne("unhandledRejection",n);return()=>{s(),i()}},We=100,Is=/^[a-z][\w-]*$/i,ve=(t,e)=>{if(typeof t!="string"||t.trim().length===0)throw new N(`${e} must be a non-empty string`,"INVALID_INPUT",{fieldName:e,value:t});return t.trim()},qe=(t,e)=>{if(!Array.isArray(t)||!t.every(n=>typeof n=="string"))throw new N(`${e} must be an array of strings`,"INVALID_INPUT",{fieldName:e,value:t});return t},ne=(t,e)=>{if(typeof t!="object"||t===null)throw new N(`${e} must be an object`,"INVALID_INPUT",{fieldName:e,value:t});return t},se=t=>{const e=ve(t,"Command name");if(e.length>We)throw new N(`Command name is too long (maximum ${String(We)} characters)`,"INVALID_COMMAND_NAME",{commandName:e,length:e.length});if(e.includes("..")||e.includes("/")||e.includes("\\")||e.includes(";")||e.includes("|")||e.includes("&"))throw new N(`Command name "${e}" contains invalid characters`,"INVALID_COMMAND_NAME",{commandName:e});if(!Is.test(e))throw new N(`Command name "${e}" must start with a letter and contain only letters, numbers, hyphens, and underscores`,"INVALID_COMMAND_NAME",{commandName:e});return e},$s=1e6,Ps=1e5,Ls=new Set([`
4
- `,"\r"," ","\0",'"',"$","&","'","(",")",";","<",">","[","\\","]","`","{","|","}"]),Us=(t,e={})=>{if(typeof t!="string")throw new TypeError("Argument must be a string");const n=typeof e=="boolean"?{checkDangerousChars:e}:e,s=n.maxArgumentLength??$s;if(Number.isFinite(s)&&s>0&&t.length>s)throw new Error(`Argument is too long (maximum ${String(s)} characters)`);if(n.checkDangerousChars){for(const i of t)if(Ls.has(i))throw new Error(`Argument contains dangerous character: ${i}`)}return n.trim?t.trim():t},Ge=(t,e={})=>{if(!Array.isArray(t))throw new TypeError("Arguments must be an array");const n=typeof e=="boolean"?{checkDangerousChars:e}:e,s=n.maxArguments??Ps;if(Number.isFinite(s)&&s>0&&t.length>s)throw new Error(`Too many arguments (maximum ${String(s)})`);return t.map(i=>Us(i,n))},Ms=/^-([^\d-])$/,Ss=/^--(\S+)/,Ts=/^-([^\d-]{2,})$/,me=t=>Ms.test(t)||Ss.test(t)||Ts.test(t),Ds={access:(t,e)=>yt(t,e),mkdir:(t,e)=>wt(t,e),readdir:t=>mt(t),readFile:(async(t,e)=>e===void 0?be(t):be(t,e)),rm:(t,e)=>gt(t,e),stat:t=>dt(t),writeFile:(t,e,n)=>ft(t,e,n)},Vs=(t,e,n)=>{const s=e.indexOf("--"),i=s===-1?new Set:new Set(e.slice(s+1)),o=n.filter(u=>u.startsWith("--")&&u!=="--"&&!i.has(u));if(o.length===0)return;const c=(t.options??[]).map(u=>u.name),a=o.flatMap(u=>R(u.slice(2),c).map(r=>`--${r}`));throw new Yt(o,a)};class at{#t;#e;#h;#p;#f;#d;#O;#_;#x;#A;#E;#C;#k;#b=le;#u;#n;#s;#o;#i;#r;#I=!1;#$;#P=!1;#g;#m;#w;#l=[];#D(){return this.#g===void 0&&(this.#g=[...this.#s.keys()]),this.#g}#L(){return this.#m===void 0&&(this.#m=[...this.#n.keys()]),this.#m}#a(){return this.#w===void 0&&(this.#w=[...this.#D(),...this.#L()]),this.#w}#U(){return this.#l.length===0?te:[...te,...this.#l]}#M(){this.#g=void 0,this.#m=void 0,this.#w=void 0}#N(){if(this.#h===void 0){const e=Es(this.#e.argv);this.#h=Ge(e,{maxArguments:this.#C}),this.#V()}return this.#h}#y(){return this.#A??re()}#v(e){this.#b=e,this.#y().CEREBRO_OUTPUT_LEVEL=String(e)}#c(){return this.#b}#V(){if(!this.#h)return;let e=!1;for(const n of this.#h){if(n==="--quiet"||n==="-q"){this.#v(vt),e=!0;break}if(n==="--verbose"||n==="-v"){this.#v(At),e=!0;break}if(n==="--debug"){this.#v(V),e=!0;break}}e||this.#v(Object.hasOwn(this.#y(),"DEBUG")?V:le)}#j(){this.#P||(this.#$=ks(this.#t),this.#P=!0)}#R(){return{arch:bt(),argv:this.#N(),cwd:this.#p,env:this.#A??re(),exit:this.#x??(e=>F(e??0)),platform:Ct(),stdin:this.#E}}#S(e,n,s,i){this.#c()===V&&this.#t.debug(`command '${i}' found, parsing command args: ${n.join(", ")}`);const{arguments_:o,booleanValues:c,parsedArgs:a}=Fn(e,n,this.#U()),u=Object.keys(c).length>0;let r=a;u&&(r={...a,_all:{...a._all,...c}}),cs(o,r,e);const l=zn(e,a,c,s,this.#y());l.runtime=this,l.argv=this.#N(),l.fs=this.#_??Ds,l.process=this.#R(),l.console=this.#t,Wn(e,l);const p=e.options&&e.options.length>0;if(p&&e.options){const h=e.options.filter(m=>m.name.startsWith("no-"));for(const m of h){const d=m.name.slice(3),y=`--${m.name}`,A=`--${d}`,g=n.includes(y),C=n.includes(A);if(g&&C)throw new Ke(d,m.name)}}return p&&(vs(l,e),As(l,e)),hs(o,l.options,e),us(l.options,e),this.#k&&Vs(e,n,l.rawUnknown),this.#c()===V&&(this.#t.debug("command options parsed from options:"),this.#t.debug(JSON.stringify(l.options,null,2)),this.#t.debug("command argument parsed from argument:"),this.#t.debug(JSON.stringify(l.argument,null,2))),{arguments_:o,booleanValues:c,commandArgs:r,parsedArgs:a,toolbox:l}}async#T(e,n,s){const i=this.getPluginManager();try{!this.#I&&i.hasPlugins()&&(await i.init({cli:this,cwd:this.#p,logger:this.#t}),this.#I=!0),await i.executeLifecycle("execute",n),await i.executeLifecycle("beforeCommand",n);let o;const c=s.global;if(c?.help){const a=this.#n.get("help");if(!a)throw new N("Help command not found","COMMAND_NOT_FOUND");o=await pe(a,n,s)}else if(c?.version??c?.V){const a=this.#n.get("version");if(!a)throw new N("Version command not found","COMMAND_NOT_FOUND");o=await pe(a,n,s)}else o=await pe(e,n,s);return await i.executeLifecycle("afterCommand",n,o),o}catch(o){throw await i.executeErrorHandlers(o,n),o}}constructor(e,n={}){if(typeof e!="string"||e.trim().length===0)throw new N("CLI name must be a non-empty string","INVALID_INPUT",{cliName:e});this.#f=e.trim();const s=n.argv??we(),i=n.cwd??Nt();if(this.#e={...n,argv:s,cwd:i},this.#e.argv&&!Array.isArray(this.#e.argv))throw new N("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 N("CLI cwd option must be a string","INVALID_INPUT",{cwd:this.#e.cwd});if(this.#e.packageName&&typeof this.#e.packageName!="string")throw new N("CLI packageName option must be a string","INVALID_INPUT",{packageName:this.#e.packageName});if(this.#e.packageVersion&&typeof this.#e.packageVersion!="string")throw new N("CLI packageVersion option must be a string","INVALID_INPUT",{packageVersion:this.#e.packageVersion});if(typeof this.#e.logger=="object"){const p=["debug","error","info","log","warn"],h=[],m=this.#e.logger;for(const d of p)typeof m[d]!="function"&&h.push(d);if(h.length>0)throw new N(`Logger object is missing required methods: ${h.join(", ")}`,"INVALID_INPUT",{logger:this.#e.logger,missingMethods:h});this.#t=this.#e.logger}else this.#t={...console,debug:(...p)=>{this.#c()===V&&console.debug(...p)}};this.#d=this.#e.packageVersion,this.#O=this.#e.packageName,this.#p=this.#e.cwd,this.#i="help",this.#r={};const o=n.fs;if(o!==void 0&&(typeof o!="object"||o===null))throw new N("CLI fs option must be an object implementing the CerebroFs interface","INVALID_INPUT",{fs:n.fs});const c=n.exit;if(c!==void 0&&typeof c!="function")throw new N("CLI exit option must be a function","INVALID_INPUT",{exit:n.exit});const a=n.env;if(a!==void 0&&(typeof a!="object"||a===null))throw new N("CLI env option must be a record of string keys","INVALID_INPUT",{env:n.env});const u=n.stdin;if(u!==void 0&&typeof u!="string")throw new N("CLI stdin option must be a string","INVALID_INPUT",{stdin:n.stdin});this.#_=n.fs,this.#x=n.exit,this.#A=n.env,this.#E=n.stdin??"",this.#C=n.maxArguments,this.#k=n.strictOptions??!1;const r=this.#y().CEREBRO_OUTPUT_LEVEL,l=r===void 0?Number.NaN:Number(r);this.#b=Number.isNaN(l)?le:l,this.#n=new Map,this.#s=new Map,this.#o=new Map}setCommandSection(e){return this.#r=e,this}getCommandSection(){return this.#r.header||(this.#r.header=`${this.#f}${this.#d?` v${this.#d}`:""}`),this.#r}setDefaultCommand(e){return this.#i=e,this}get defaultCommand(){return this.#i}addCommand(e){ne(e,"Command"),se(e.name),e.options!==void 0&&ne(e.options,"Command options"),e.env!==void 0&&ne(e.env,"Command env"),fs(e);const n=gs(e),s=typeof n.execute=="function",i=typeof n.loader=="function";if(s&&i)throw new N(`Command "${n.name}" cannot define both "execute" and "loader" — choose one`,"INVALID_COMMAND",{commandName:n.name});if(!s&&!i)throw new N(`Command "${n.name}" must define either "execute" or "loader"`,"INVALID_COMMAND",{commandName:n.name});n.alias&&(typeof n.alias=="string"?se(n.alias):qe(n.alias,"Command alias").forEach(l=>se(l))),n.argument&&ne(n.argument,"Command argument"),n.commandPath&&(qe(n.commandPath,"Command commandPath"),n.commandPath.forEach(l=>{se(l)}));const o=ze(n.name,n.commandPath),c=z(o);if(this.#s.has(c))throw new N(`Command with path "${c}" already exists`,"DUPLICATE_COMMAND",{commandName:n.name,commandPath:n.commandPath});const a=Array.isArray(n.commandPath)&&n.commandPath.length>0,u=this.#n.get(n.name),r=u!==void 0&&(u.commandPath===void 0||u.commandPath.length===0);if(!a&&r)throw new N(`Command with name "${n.name}" already exists`,"DUPLICATE_COMMAND",{commandName:n.name});if(n.options)for(const l of n.options)$e(l);if(ps(n),ys(n),ws(n),n.options&&(n.__conflictingOptions__=n.options.filter(l=>l.conflicts!==void 0),n.__requiredOptions__=n.options.filter(l=>l.required===!0)),a&&u!==void 0)this.#n.set(c,n);else{if(!a&&u!==void 0&&!r){const l=ze(u.name,u.commandPath);this.#n.set(z(l),u)}this.#n.set(n.name,n)}if(this.#s.set(c,o),this.#o.set(c,n),this.#M(),n.alias!==void 0){const l=typeof n.alias=="string"?[n.alias]:n.alias;for(const p of l){if(this.#c()===V&&this.#t.debug("adding alias",p),this.#n.has(p))throw new N(`Command alias "${p}" conflicts with existing command`,"DUPLICATE_COMMAND",{alias:p,commandName:n.name});this.#n.set(p,n)}}return this}addGlobalOption(e){const n=e,s=new Set(te.map(c=>c.name)),i=new Set(te.map(c=>c.alias).filter(Boolean));if(s.has(n.name))throw new N(`Cannot add global option "--${n.name}": it conflicts with a built-in global option`,"DUPLICATE_OPTION",{optionName:n.name});if(n.alias&&i.has(n.alias))throw new N(`Cannot add global option with alias "-${n.alias}": it conflicts with a built-in global option alias`,"DUPLICATE_OPTION",{alias:n.alias,optionName:n.name});if(new Set(this.#l.map(c=>c.name)).has(n.name))throw new N(`Global option "--${n.name}" has already been added`,"DUPLICATE_OPTION",{optionName:n.name});return n.group="global",$e(n),this.#l.push(n),this}getGlobalOptions(){return this.#U()}addPlugin(e){return this.getPluginManager().register(e),this}getPluginManager(){return this.#u?this.#u:(this.#u=new Zt(this.#t),this.#u.register({description:"Attaches the logger to the toolbox",execute:e=>{e.logger=this.#t,e.console=e.logger},name:"logger"}),this.#u)}getCliName(){return this.#f}getPackageVersion(){return this.#d}getPackageName(){return this.#O}getCommands(){return this.#n}getCwd(){return this.#p}dispose(){this.#$?.()}async run(e={}){const{autoDispose:n=!0,shouldExitProcess:s=!0,...i}=e;if(!this.#n.has("help")){const{default:g}=await import("../commands/help-command.js");this.addCommand(new g(this.#n))}const o=this.#L(),c=this.#s;this.#j();const a=this.#N();let u,r=[...a];this.#c()===V&&(this.#t.debug(`process.execPath: ${Ot()}`),this.#t.debug(`process.execArgv: ${_t().join(" ")}`),this.#t.debug(`process.argv: ${we().join(" ")}`));const l=ds(c,[...a]);if(l.commandPath)u=l.commandPath,r=l.argv;else{if(a.length>1&&a[0]&&a[1]&&!me(a[0])&&!me(a[1])){const C=[];let O=0;for(;O<a.length;){const x=a[O];if(!x||me(x))break;C.push(x),O+=1}const k=z(C);if(C[0]&&!o.includes(C[0])){const x=this.#a(),H=R(k,x);throw new B(k,H)}}let g;try{g=on([null,...o],[...a])}catch(C){if(C instanceof Error&&C.name==="INVALID_COMMAND"&&"command"in C){const O=C.command,k=this.#a(),x=R(O,k);throw new B(O,x)}throw C}g.command&&(u=[g.command],r=g.argv)}if(!u)if(this.#i)u=[this.#i];else{const g=this.#a();throw new B("",g)}const p=z(u),h=this.#s.get(p);let m;if(h){if(m=this.#o.get(p),!m||z(h)!==p){const g=this.#a(),C=R(p,g);throw new B(p,C)}}else{const g=u.at(-1);if(m=g?this.#n.get(g):void 0,!m){const C=this.#a(),O=R(p,C);throw new B(p,O)}}if(typeof m.execute!="function"&&typeof m.loader!="function")return this.#t.error(`Command "${m.name}" has no function to execute.`),s?F(1):void 0;const d=r;let y,A;try{({commandArgs:y,toolbox:A}=this.#S(m,d,i,p))}catch(g){if(this.#t.error(g),s)return F(1);throw g}try{return await this.#T(m,A,y),s?F(0):void 0}catch(g){if(s)return this.#t.error(g),F(1);throw g}finally{n&&this.dispose()}}async runCommand(e,n={}){const{argv:s=[],...i}=n;ve(e,"Command name");const o=e.split(" ").filter(Boolean),c=z(o),u=this.#s.get(c)?this.#o.get(c):this.#n.get(e);if(!u){const m=this.#a(),d=R(c||e,m);throw new B(e,d)}if(typeof u.execute!="function"&&typeof u.loader!="function")throw new N(`Command "${u.name}" has no function to execute`,"INVALID_COMMAND",{commandName:u.name});const l=[...Ge(s,{maxArguments:this.#C})];this.#c()===V&&this.#t.debug(`running command '${e}' programmatically with args: ${l.join(", ")}`);const{commandArgs:p,toolbox:h}=this.#S(u,l,i,c||e);return this.#T(u,h,p)}clone(e){const n={...this.#e,...e},s=new at(this.#f,n);for(const[i,o]of this.#n)s.#n.set(i,o);for(const[i,o]of this.#s)s.#s.set(i,[...o]);for(const[i,o]of this.#o)s.#o.set(i,o);for(const i of this.#l)s.#l.push(i);return s.#i=this.#i,s.#r={...this.#r},s.#M(),s}async getAction(e){ve(e,"Command name");const n=e.split(" ").filter(Boolean),s=z(n),o=this.#s.get(s)?this.#o.get(s):this.#n.get(e);if(!o){const c=this.#a(),a=R(s||e,c);throw new B(e,a)}if(typeof o.execute=="function")return o.execute;if(typeof o.loader=="function")return tt(o);throw new N(`Command "${o.name}" has no execute or loader defined`,"INVALID_COMMAND",{commandName:o.name})}}export{at as Cli};