@settlemint/sdk-mcp 2.3.0 → 2.3.1-pr9c56c214

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/dist/mcp.js +625 -248
  2. package/dist/mcp.js.map +14 -14
  3. package/package.json +5 -5
package/dist/mcp.js CHANGED
@@ -36456,18 +36456,18 @@ var require_help = __commonJS((exports) => {
36456
36456
  class Help {
36457
36457
  constructor() {
36458
36458
  this.helpWidth = undefined;
36459
+ this.minWidthToWrap = 40;
36459
36460
  this.sortSubcommands = false;
36460
36461
  this.sortOptions = false;
36461
36462
  this.showGlobalOptions = false;
36462
36463
  }
36464
+ prepareContext(contextOptions) {
36465
+ this.helpWidth = this.helpWidth ?? contextOptions.helpWidth ?? 80;
36466
+ }
36463
36467
  visibleCommands(cmd) {
36464
36468
  const visibleCommands = cmd.commands.filter((cmd2) => !cmd2._hidden);
36465
- if (cmd._hasImplicitHelpCommand()) {
36466
- const [, helpName, helpArgs] = cmd._helpCommandnameAndArgs.match(/([^ ]+) *(.*)/);
36467
- const helpCommand = cmd.createCommand(helpName).helpOption(false);
36468
- helpCommand.description(cmd._helpCommandDescription);
36469
- if (helpArgs)
36470
- helpCommand.arguments(helpArgs);
36469
+ const helpCommand = cmd._getHelpCommand();
36470
+ if (helpCommand && !helpCommand._hidden) {
36471
36471
  visibleCommands.push(helpCommand);
36472
36472
  }
36473
36473
  if (this.sortSubcommands) {
@@ -36485,18 +36485,17 @@ var require_help = __commonJS((exports) => {
36485
36485
  }
36486
36486
  visibleOptions(cmd) {
36487
36487
  const visibleOptions = cmd.options.filter((option) => !option.hidden);
36488
- const showShortHelpFlag = cmd._hasHelpOption && cmd._helpShortFlag && !cmd._findOption(cmd._helpShortFlag);
36489
- const showLongHelpFlag = cmd._hasHelpOption && !cmd._findOption(cmd._helpLongFlag);
36490
- if (showShortHelpFlag || showLongHelpFlag) {
36491
- let helpOption;
36492
- if (!showShortHelpFlag) {
36493
- helpOption = cmd.createOption(cmd._helpLongFlag, cmd._helpDescription);
36494
- } else if (!showLongHelpFlag) {
36495
- helpOption = cmd.createOption(cmd._helpShortFlag, cmd._helpDescription);
36496
- } else {
36497
- helpOption = cmd.createOption(cmd._helpFlags, cmd._helpDescription);
36488
+ const helpOption = cmd._getHelpOption();
36489
+ if (helpOption && !helpOption.hidden) {
36490
+ const removeShort = helpOption.short && cmd._findOption(helpOption.short);
36491
+ const removeLong = helpOption.long && cmd._findOption(helpOption.long);
36492
+ if (!removeShort && !removeLong) {
36493
+ visibleOptions.push(helpOption);
36494
+ } else if (helpOption.long && !removeLong) {
36495
+ visibleOptions.push(cmd.createOption(helpOption.long, helpOption.description));
36496
+ } else if (helpOption.short && !removeShort) {
36497
+ visibleOptions.push(cmd.createOption(helpOption.short, helpOption.description));
36498
36498
  }
36499
- visibleOptions.push(helpOption);
36500
36499
  }
36501
36500
  if (this.sortOptions) {
36502
36501
  visibleOptions.sort(this.compareOptions);
@@ -36539,22 +36538,22 @@ var require_help = __commonJS((exports) => {
36539
36538
  }
36540
36539
  longestSubcommandTermLength(cmd, helper) {
36541
36540
  return helper.visibleCommands(cmd).reduce((max, command) => {
36542
- return Math.max(max, helper.subcommandTerm(command).length);
36541
+ return Math.max(max, this.displayWidth(helper.styleSubcommandTerm(helper.subcommandTerm(command))));
36543
36542
  }, 0);
36544
36543
  }
36545
36544
  longestOptionTermLength(cmd, helper) {
36546
36545
  return helper.visibleOptions(cmd).reduce((max, option) => {
36547
- return Math.max(max, helper.optionTerm(option).length);
36546
+ return Math.max(max, this.displayWidth(helper.styleOptionTerm(helper.optionTerm(option))));
36548
36547
  }, 0);
36549
36548
  }
36550
36549
  longestGlobalOptionTermLength(cmd, helper) {
36551
36550
  return helper.visibleGlobalOptions(cmd).reduce((max, option) => {
36552
- return Math.max(max, helper.optionTerm(option).length);
36551
+ return Math.max(max, this.displayWidth(helper.styleOptionTerm(helper.optionTerm(option))));
36553
36552
  }, 0);
36554
36553
  }
36555
36554
  longestArgumentTermLength(cmd, helper) {
36556
36555
  return helper.visibleArguments(cmd).reduce((max, argument) => {
36557
- return Math.max(max, helper.argumentTerm(argument).length);
36556
+ return Math.max(max, this.displayWidth(helper.styleArgumentTerm(helper.argumentTerm(argument))));
36558
36557
  }, 0);
36559
36558
  }
36560
36559
  commandUsage(cmd) {
@@ -36592,7 +36591,11 @@ var require_help = __commonJS((exports) => {
36592
36591
  extraInfo.push(`env: ${option.envVar}`);
36593
36592
  }
36594
36593
  if (extraInfo.length > 0) {
36595
- return `${option.description} (${extraInfo.join(", ")})`;
36594
+ const extraDescription = `(${extraInfo.join(", ")})`;
36595
+ if (option.description) {
36596
+ return `${option.description} ${extraDescription}`;
36597
+ }
36598
+ return extraDescription;
36596
36599
  }
36597
36600
  return option.description;
36598
36601
  }
@@ -36605,95 +36608,202 @@ var require_help = __commonJS((exports) => {
36605
36608
  extraInfo.push(`default: ${argument.defaultValueDescription || JSON.stringify(argument.defaultValue)}`);
36606
36609
  }
36607
36610
  if (extraInfo.length > 0) {
36608
- const extraDescripton = `(${extraInfo.join(", ")})`;
36611
+ const extraDescription = `(${extraInfo.join(", ")})`;
36609
36612
  if (argument.description) {
36610
- return `${argument.description} ${extraDescripton}`;
36613
+ return `${argument.description} ${extraDescription}`;
36611
36614
  }
36612
- return extraDescripton;
36615
+ return extraDescription;
36613
36616
  }
36614
36617
  return argument.description;
36615
36618
  }
36619
+ formatItemList(heading, items, helper) {
36620
+ if (items.length === 0)
36621
+ return [];
36622
+ return [helper.styleTitle(heading), ...items, ""];
36623
+ }
36624
+ groupItems(unsortedItems, visibleItems, getGroup) {
36625
+ const result = new Map;
36626
+ unsortedItems.forEach((item) => {
36627
+ const group = getGroup(item);
36628
+ if (!result.has(group))
36629
+ result.set(group, []);
36630
+ });
36631
+ visibleItems.forEach((item) => {
36632
+ const group = getGroup(item);
36633
+ if (!result.has(group)) {
36634
+ result.set(group, []);
36635
+ }
36636
+ result.get(group).push(item);
36637
+ });
36638
+ return result;
36639
+ }
36616
36640
  formatHelp(cmd, helper) {
36617
36641
  const termWidth = helper.padWidth(cmd, helper);
36618
- const helpWidth = helper.helpWidth || 80;
36619
- const itemIndentWidth = 2;
36620
- const itemSeparatorWidth = 2;
36621
- function formatItem(term, description) {
36622
- if (description) {
36623
- const fullText = `${term.padEnd(termWidth + itemSeparatorWidth)}${description}`;
36624
- return helper.wrap(fullText, helpWidth - itemIndentWidth, termWidth + itemSeparatorWidth);
36625
- }
36626
- return term;
36642
+ const helpWidth = helper.helpWidth ?? 80;
36643
+ function callFormatItem(term, description) {
36644
+ return helper.formatItem(term, termWidth, description, helper);
36627
36645
  }
36628
- function formatList(textArray) {
36629
- return textArray.join(`
36630
- `).replace(/^/gm, " ".repeat(itemIndentWidth));
36631
- }
36632
- let output = [`Usage: ${helper.commandUsage(cmd)}`, ""];
36646
+ let output = [
36647
+ `${helper.styleTitle("Usage:")} ${helper.styleUsage(helper.commandUsage(cmd))}`,
36648
+ ""
36649
+ ];
36633
36650
  const commandDescription = helper.commandDescription(cmd);
36634
36651
  if (commandDescription.length > 0) {
36635
- output = output.concat([helper.wrap(commandDescription, helpWidth, 0), ""]);
36652
+ output = output.concat([
36653
+ helper.boxWrap(helper.styleCommandDescription(commandDescription), helpWidth),
36654
+ ""
36655
+ ]);
36636
36656
  }
36637
36657
  const argumentList = helper.visibleArguments(cmd).map((argument) => {
36638
- return formatItem(helper.argumentTerm(argument), helper.argumentDescription(argument));
36658
+ return callFormatItem(helper.styleArgumentTerm(helper.argumentTerm(argument)), helper.styleArgumentDescription(helper.argumentDescription(argument)));
36639
36659
  });
36640
- if (argumentList.length > 0) {
36641
- output = output.concat(["Arguments:", formatList(argumentList), ""]);
36642
- }
36643
- const optionList = helper.visibleOptions(cmd).map((option) => {
36644
- return formatItem(helper.optionTerm(option), helper.optionDescription(option));
36660
+ output = output.concat(this.formatItemList("Arguments:", argumentList, helper));
36661
+ const optionGroups = this.groupItems(cmd.options, helper.visibleOptions(cmd), (option) => option.helpGroupHeading ?? "Options:");
36662
+ optionGroups.forEach((options, group) => {
36663
+ const optionList = options.map((option) => {
36664
+ return callFormatItem(helper.styleOptionTerm(helper.optionTerm(option)), helper.styleOptionDescription(helper.optionDescription(option)));
36665
+ });
36666
+ output = output.concat(this.formatItemList(group, optionList, helper));
36645
36667
  });
36646
- if (optionList.length > 0) {
36647
- output = output.concat(["Options:", formatList(optionList), ""]);
36648
- }
36649
- if (this.showGlobalOptions) {
36668
+ if (helper.showGlobalOptions) {
36650
36669
  const globalOptionList = helper.visibleGlobalOptions(cmd).map((option) => {
36651
- return formatItem(helper.optionTerm(option), helper.optionDescription(option));
36670
+ return callFormatItem(helper.styleOptionTerm(helper.optionTerm(option)), helper.styleOptionDescription(helper.optionDescription(option)));
36652
36671
  });
36653
- if (globalOptionList.length > 0) {
36654
- output = output.concat(["Global Options:", formatList(globalOptionList), ""]);
36655
- }
36672
+ output = output.concat(this.formatItemList("Global Options:", globalOptionList, helper));
36656
36673
  }
36657
- const commandList = helper.visibleCommands(cmd).map((cmd2) => {
36658
- return formatItem(helper.subcommandTerm(cmd2), helper.subcommandDescription(cmd2));
36674
+ const commandGroups = this.groupItems(cmd.commands, helper.visibleCommands(cmd), (sub) => sub.helpGroup() || "Commands:");
36675
+ commandGroups.forEach((commands, group) => {
36676
+ const commandList = commands.map((sub) => {
36677
+ return callFormatItem(helper.styleSubcommandTerm(helper.subcommandTerm(sub)), helper.styleSubcommandDescription(helper.subcommandDescription(sub)));
36678
+ });
36679
+ output = output.concat(this.formatItemList(group, commandList, helper));
36659
36680
  });
36660
- if (commandList.length > 0) {
36661
- output = output.concat(["Commands:", formatList(commandList), ""]);
36662
- }
36663
36681
  return output.join(`
36664
36682
  `);
36665
36683
  }
36684
+ displayWidth(str) {
36685
+ return stripColor(str).length;
36686
+ }
36687
+ styleTitle(str) {
36688
+ return str;
36689
+ }
36690
+ styleUsage(str) {
36691
+ return str.split(" ").map((word) => {
36692
+ if (word === "[options]")
36693
+ return this.styleOptionText(word);
36694
+ if (word === "[command]")
36695
+ return this.styleSubcommandText(word);
36696
+ if (word[0] === "[" || word[0] === "<")
36697
+ return this.styleArgumentText(word);
36698
+ return this.styleCommandText(word);
36699
+ }).join(" ");
36700
+ }
36701
+ styleCommandDescription(str) {
36702
+ return this.styleDescriptionText(str);
36703
+ }
36704
+ styleOptionDescription(str) {
36705
+ return this.styleDescriptionText(str);
36706
+ }
36707
+ styleSubcommandDescription(str) {
36708
+ return this.styleDescriptionText(str);
36709
+ }
36710
+ styleArgumentDescription(str) {
36711
+ return this.styleDescriptionText(str);
36712
+ }
36713
+ styleDescriptionText(str) {
36714
+ return str;
36715
+ }
36716
+ styleOptionTerm(str) {
36717
+ return this.styleOptionText(str);
36718
+ }
36719
+ styleSubcommandTerm(str) {
36720
+ return str.split(" ").map((word) => {
36721
+ if (word === "[options]")
36722
+ return this.styleOptionText(word);
36723
+ if (word[0] === "[" || word[0] === "<")
36724
+ return this.styleArgumentText(word);
36725
+ return this.styleSubcommandText(word);
36726
+ }).join(" ");
36727
+ }
36728
+ styleArgumentTerm(str) {
36729
+ return this.styleArgumentText(str);
36730
+ }
36731
+ styleOptionText(str) {
36732
+ return str;
36733
+ }
36734
+ styleArgumentText(str) {
36735
+ return str;
36736
+ }
36737
+ styleSubcommandText(str) {
36738
+ return str;
36739
+ }
36740
+ styleCommandText(str) {
36741
+ return str;
36742
+ }
36666
36743
  padWidth(cmd, helper) {
36667
36744
  return Math.max(helper.longestOptionTermLength(cmd, helper), helper.longestGlobalOptionTermLength(cmd, helper), helper.longestSubcommandTermLength(cmd, helper), helper.longestArgumentTermLength(cmd, helper));
36668
36745
  }
36669
- wrap(str, width, indent2, minColumnWidth = 40) {
36670
- const indents = " \\f\\t\\v   -    \uFEFF";
36671
- const manualIndent = new RegExp(`[\\n][${indents}]+`);
36672
- if (str.match(manualIndent))
36673
- return str;
36674
- const columnWidth = width - indent2;
36675
- if (columnWidth < minColumnWidth)
36746
+ preformatted(str) {
36747
+ return /\n[^\S\r\n]/.test(str);
36748
+ }
36749
+ formatItem(term, termWidth, description, helper) {
36750
+ const itemIndent = 2;
36751
+ const itemIndentStr = " ".repeat(itemIndent);
36752
+ if (!description)
36753
+ return itemIndentStr + term;
36754
+ const paddedTerm = term.padEnd(termWidth + term.length - helper.displayWidth(term));
36755
+ const spacerWidth = 2;
36756
+ const helpWidth = this.helpWidth ?? 80;
36757
+ const remainingWidth = helpWidth - termWidth - spacerWidth - itemIndent;
36758
+ let formattedDescription;
36759
+ if (remainingWidth < this.minWidthToWrap || helper.preformatted(description)) {
36760
+ formattedDescription = description;
36761
+ } else {
36762
+ const wrappedDescription = helper.boxWrap(description, remainingWidth);
36763
+ formattedDescription = wrappedDescription.replace(/\n/g, `
36764
+ ` + " ".repeat(termWidth + spacerWidth));
36765
+ }
36766
+ return itemIndentStr + paddedTerm + " ".repeat(spacerWidth) + formattedDescription.replace(/\n/g, `
36767
+ ${itemIndentStr}`);
36768
+ }
36769
+ boxWrap(str, width) {
36770
+ if (width < this.minWidthToWrap)
36676
36771
  return str;
36677
- const leadingStr = str.slice(0, indent2);
36678
- const columnText = str.slice(indent2).replace(`\r
36679
- `, `
36680
- `);
36681
- const indentString = " ".repeat(indent2);
36682
- const zeroWidthSpace = "​";
36683
- const breaks = `\\s${zeroWidthSpace}`;
36684
- const regex = new RegExp(`
36685
- |.{1,${columnWidth - 1}}([${breaks}]|$)|[^${breaks}]+?([${breaks}]|$)`, "g");
36686
- const lines = columnText.match(regex) || [];
36687
- return leadingStr + lines.map((line, i) => {
36688
- if (line === `
36689
- `)
36690
- return "";
36691
- return (i > 0 ? indentString : "") + line.trimEnd();
36692
- }).join(`
36772
+ const rawLines = str.split(/\r\n|\n/);
36773
+ const chunkPattern = /[\s]*[^\s]+/g;
36774
+ const wrappedLines = [];
36775
+ rawLines.forEach((line) => {
36776
+ const chunks = line.match(chunkPattern);
36777
+ if (chunks === null) {
36778
+ wrappedLines.push("");
36779
+ return;
36780
+ }
36781
+ let sumChunks = [chunks.shift()];
36782
+ let sumWidth = this.displayWidth(sumChunks[0]);
36783
+ chunks.forEach((chunk) => {
36784
+ const visibleWidth = this.displayWidth(chunk);
36785
+ if (sumWidth + visibleWidth <= width) {
36786
+ sumChunks.push(chunk);
36787
+ sumWidth += visibleWidth;
36788
+ return;
36789
+ }
36790
+ wrappedLines.push(sumChunks.join(""));
36791
+ const nextChunk = chunk.trimStart();
36792
+ sumChunks = [nextChunk];
36793
+ sumWidth = this.displayWidth(nextChunk);
36794
+ });
36795
+ wrappedLines.push(sumChunks.join(""));
36796
+ });
36797
+ return wrappedLines.join(`
36693
36798
  `);
36694
36799
  }
36695
36800
  }
36801
+ function stripColor(str) {
36802
+ const sgrPattern = /\x1b\[\d*(;\d*)*m/g;
36803
+ return str.replace(sgrPattern, "");
36804
+ }
36696
36805
  exports.Help = Help;
36806
+ exports.stripColor = stripColor;
36697
36807
  });
36698
36808
 
36699
36809
  // ../../node_modules/commander/lib/option.js
@@ -36724,6 +36834,7 @@ var require_option = __commonJS((exports) => {
36724
36834
  this.argChoices = undefined;
36725
36835
  this.conflictsWith = [];
36726
36836
  this.implied = undefined;
36837
+ this.helpGroupHeading = undefined;
36727
36838
  }
36728
36839
  default(value, description) {
36729
36840
  this.defaultValue = value;
@@ -36788,7 +36899,14 @@ var require_option = __commonJS((exports) => {
36788
36899
  return this.short.replace(/^-/, "");
36789
36900
  }
36790
36901
  attributeName() {
36791
- return camelcase(this.name().replace(/^no-/, ""));
36902
+ if (this.negate) {
36903
+ return camelcase(this.name().replace(/^no-/, ""));
36904
+ }
36905
+ return camelcase(this.name());
36906
+ }
36907
+ helpGroup(heading) {
36908
+ this.helpGroupHeading = heading;
36909
+ return this;
36792
36910
  }
36793
36911
  is(arg) {
36794
36912
  return this.short === arg || this.long === arg;
@@ -36833,18 +36951,41 @@ var require_option = __commonJS((exports) => {
36833
36951
  function splitOptionFlags(flags) {
36834
36952
  let shortFlag;
36835
36953
  let longFlag;
36836
- const flagParts = flags.split(/[ |,]+/);
36837
- if (flagParts.length > 1 && !/^[[<]/.test(flagParts[1]))
36954
+ const shortFlagExp = /^-[^-]$/;
36955
+ const longFlagExp = /^--[^-]/;
36956
+ const flagParts = flags.split(/[ |,]+/).concat("guard");
36957
+ if (shortFlagExp.test(flagParts[0]))
36958
+ shortFlag = flagParts.shift();
36959
+ if (longFlagExp.test(flagParts[0]))
36960
+ longFlag = flagParts.shift();
36961
+ if (!shortFlag && shortFlagExp.test(flagParts[0]))
36838
36962
  shortFlag = flagParts.shift();
36839
- longFlag = flagParts.shift();
36840
- if (!shortFlag && /^-[^-]$/.test(longFlag)) {
36963
+ if (!shortFlag && longFlagExp.test(flagParts[0])) {
36841
36964
  shortFlag = longFlag;
36842
- longFlag = undefined;
36843
- }
36965
+ longFlag = flagParts.shift();
36966
+ }
36967
+ if (flagParts[0].startsWith("-")) {
36968
+ const unsupportedFlag = flagParts[0];
36969
+ const baseError = `option creation failed due to '${unsupportedFlag}' in option flags '${flags}'`;
36970
+ if (/^-[^-][^-]/.test(unsupportedFlag))
36971
+ throw new Error(`${baseError}
36972
+ - a short flag is a single dash and a single character
36973
+ - either use a single dash and a single character (for a short flag)
36974
+ - or use a double dash for a long option (and can have two, like '--ws, --workspace')`);
36975
+ if (shortFlagExp.test(unsupportedFlag))
36976
+ throw new Error(`${baseError}
36977
+ - too many short flags`);
36978
+ if (longFlagExp.test(unsupportedFlag))
36979
+ throw new Error(`${baseError}
36980
+ - too many long flags`);
36981
+ throw new Error(`${baseError}
36982
+ - unrecognised flag format`);
36983
+ }
36984
+ if (shortFlag === undefined && longFlag === undefined)
36985
+ throw new Error(`option creation failed due to no flags found in '${flags}'.`);
36844
36986
  return { shortFlag, longFlag };
36845
36987
  }
36846
36988
  exports.Option = Option;
36847
- exports.splitOptionFlags = splitOptionFlags;
36848
36989
  exports.DualOptions = DualOptions;
36849
36990
  });
36850
36991
 
@@ -36923,15 +37064,15 @@ var require_suggestSimilar = __commonJS((exports) => {
36923
37064
 
36924
37065
  // ../../node_modules/commander/lib/command.js
36925
37066
  var require_command = __commonJS((exports) => {
36926
- var EventEmitter2 = __require("events").EventEmitter;
36927
- var childProcess = __require("child_process");
36928
- var path2 = __require("path");
36929
- var fs = __require("fs");
36930
- var process3 = __require("process");
37067
+ var EventEmitter2 = __require("node:events").EventEmitter;
37068
+ var childProcess = __require("node:child_process");
37069
+ var path2 = __require("node:path");
37070
+ var fs = __require("node:fs");
37071
+ var process3 = __require("node:process");
36931
37072
  var { Argument, humanReadableArgName } = require_argument();
36932
37073
  var { CommanderError } = require_error3();
36933
- var { Help } = require_help();
36934
- var { Option, splitOptionFlags, DualOptions } = require_option();
37074
+ var { Help, stripColor } = require_help();
37075
+ var { Option, DualOptions } = require_option();
36935
37076
  var { suggestSimilar } = require_suggestSimilar();
36936
37077
 
36937
37078
  class Command extends EventEmitter2 {
@@ -36941,7 +37082,7 @@ var require_command = __commonJS((exports) => {
36941
37082
  this.options = [];
36942
37083
  this.parent = null;
36943
37084
  this._allowUnknownOption = false;
36944
- this._allowExcessArguments = true;
37085
+ this._allowExcessArguments = false;
36945
37086
  this.registeredArguments = [];
36946
37087
  this._args = this.registeredArguments;
36947
37088
  this.args = [];
@@ -36968,35 +37109,30 @@ var require_command = __commonJS((exports) => {
36968
37109
  this._lifeCycleHooks = {};
36969
37110
  this._showHelpAfterError = false;
36970
37111
  this._showSuggestionAfterError = true;
37112
+ this._savedState = null;
36971
37113
  this._outputConfiguration = {
36972
37114
  writeOut: (str) => process3.stdout.write(str),
36973
37115
  writeErr: (str) => process3.stderr.write(str),
37116
+ outputError: (str, write) => write(str),
36974
37117
  getOutHelpWidth: () => process3.stdout.isTTY ? process3.stdout.columns : undefined,
36975
37118
  getErrHelpWidth: () => process3.stderr.isTTY ? process3.stderr.columns : undefined,
36976
- outputError: (str, write) => write(str)
37119
+ getOutHasColors: () => useColor() ?? (process3.stdout.isTTY && process3.stdout.hasColors?.()),
37120
+ getErrHasColors: () => useColor() ?? (process3.stderr.isTTY && process3.stderr.hasColors?.()),
37121
+ stripColor: (str) => stripColor(str)
36977
37122
  };
36978
37123
  this._hidden = false;
36979
- this._hasHelpOption = true;
36980
- this._helpFlags = "-h, --help";
36981
- this._helpDescription = "display help for command";
36982
- this._helpShortFlag = "-h";
36983
- this._helpLongFlag = "--help";
37124
+ this._helpOption = undefined;
36984
37125
  this._addImplicitHelpCommand = undefined;
36985
- this._helpCommandName = "help";
36986
- this._helpCommandnameAndArgs = "help [command]";
36987
- this._helpCommandDescription = "display help for command";
37126
+ this._helpCommand = undefined;
36988
37127
  this._helpConfiguration = {};
37128
+ this._helpGroupHeading = undefined;
37129
+ this._defaultCommandGroup = undefined;
37130
+ this._defaultOptionGroup = undefined;
36989
37131
  }
36990
37132
  copyInheritedSettings(sourceCommand) {
36991
37133
  this._outputConfiguration = sourceCommand._outputConfiguration;
36992
- this._hasHelpOption = sourceCommand._hasHelpOption;
36993
- this._helpFlags = sourceCommand._helpFlags;
36994
- this._helpDescription = sourceCommand._helpDescription;
36995
- this._helpShortFlag = sourceCommand._helpShortFlag;
36996
- this._helpLongFlag = sourceCommand._helpLongFlag;
36997
- this._helpCommandName = sourceCommand._helpCommandName;
36998
- this._helpCommandnameAndArgs = sourceCommand._helpCommandnameAndArgs;
36999
- this._helpCommandDescription = sourceCommand._helpCommandDescription;
37134
+ this._helpOption = sourceCommand._helpOption;
37135
+ this._helpCommand = sourceCommand._helpCommand;
37000
37136
  this._helpConfiguration = sourceCommand._helpConfiguration;
37001
37137
  this._exitCallback = sourceCommand._exitCallback;
37002
37138
  this._storeOptionsAsProperties = sourceCommand._storeOptionsAsProperties;
@@ -37034,7 +37170,7 @@ var require_command = __commonJS((exports) => {
37034
37170
  cmd._executableFile = opts.executableFile || null;
37035
37171
  if (args)
37036
37172
  cmd.arguments(args);
37037
- this.commands.push(cmd);
37173
+ this._registerCommand(cmd);
37038
37174
  cmd.parent = this;
37039
37175
  cmd.copyInheritedSettings(this);
37040
37176
  if (desc)
@@ -37056,7 +37192,7 @@ var require_command = __commonJS((exports) => {
37056
37192
  configureOutput(configuration) {
37057
37193
  if (configuration === undefined)
37058
37194
  return this._outputConfiguration;
37059
- Object.assign(this._outputConfiguration, configuration);
37195
+ this._outputConfiguration = Object.assign({}, this._outputConfiguration, configuration);
37060
37196
  return this;
37061
37197
  }
37062
37198
  showHelpAfterError(displayHelp = true) {
@@ -37079,19 +37215,20 @@ var require_command = __commonJS((exports) => {
37079
37215
  this._defaultCommandName = cmd._name;
37080
37216
  if (opts.noHelp || opts.hidden)
37081
37217
  cmd._hidden = true;
37082
- this.commands.push(cmd);
37218
+ this._registerCommand(cmd);
37083
37219
  cmd.parent = this;
37220
+ cmd._checkForBrokenPassThrough();
37084
37221
  return this;
37085
37222
  }
37086
37223
  createArgument(name, description) {
37087
37224
  return new Argument(name, description);
37088
37225
  }
37089
- argument(name, description, fn, defaultValue) {
37226
+ argument(name, description, parseArg, defaultValue) {
37090
37227
  const argument = this.createArgument(name, description);
37091
- if (typeof fn === "function") {
37092
- argument.default(defaultValue).argParser(fn);
37228
+ if (typeof parseArg === "function") {
37229
+ argument.default(defaultValue).argParser(parseArg);
37093
37230
  } else {
37094
- argument.default(fn);
37231
+ argument.default(parseArg);
37095
37232
  }
37096
37233
  this.addArgument(argument);
37097
37234
  return this;
@@ -37113,24 +37250,48 @@ var require_command = __commonJS((exports) => {
37113
37250
  this.registeredArguments.push(argument);
37114
37251
  return this;
37115
37252
  }
37116
- addHelpCommand(enableOrNameAndArgs, description) {
37117
- if (enableOrNameAndArgs === false) {
37118
- this._addImplicitHelpCommand = false;
37119
- } else {
37120
- this._addImplicitHelpCommand = true;
37121
- if (typeof enableOrNameAndArgs === "string") {
37122
- this._helpCommandName = enableOrNameAndArgs.split(" ")[0];
37123
- this._helpCommandnameAndArgs = enableOrNameAndArgs;
37253
+ helpCommand(enableOrNameAndArgs, description) {
37254
+ if (typeof enableOrNameAndArgs === "boolean") {
37255
+ this._addImplicitHelpCommand = enableOrNameAndArgs;
37256
+ if (enableOrNameAndArgs && this._defaultCommandGroup) {
37257
+ this._initCommandGroup(this._getHelpCommand());
37124
37258
  }
37125
- this._helpCommandDescription = description || this._helpCommandDescription;
37259
+ return this;
37126
37260
  }
37261
+ const nameAndArgs = enableOrNameAndArgs ?? "help [command]";
37262
+ const [, helpName, helpArgs] = nameAndArgs.match(/([^ ]+) *(.*)/);
37263
+ const helpDescription = description ?? "display help for command";
37264
+ const helpCommand = this.createCommand(helpName);
37265
+ helpCommand.helpOption(false);
37266
+ if (helpArgs)
37267
+ helpCommand.arguments(helpArgs);
37268
+ if (helpDescription)
37269
+ helpCommand.description(helpDescription);
37270
+ this._addImplicitHelpCommand = true;
37271
+ this._helpCommand = helpCommand;
37272
+ if (enableOrNameAndArgs || description)
37273
+ this._initCommandGroup(helpCommand);
37127
37274
  return this;
37128
37275
  }
37129
- _hasImplicitHelpCommand() {
37130
- if (this._addImplicitHelpCommand === undefined) {
37131
- return this.commands.length && !this._actionHandler && !this._findCommand("help");
37276
+ addHelpCommand(helpCommand, deprecatedDescription) {
37277
+ if (typeof helpCommand !== "object") {
37278
+ this.helpCommand(helpCommand, deprecatedDescription);
37279
+ return this;
37280
+ }
37281
+ this._addImplicitHelpCommand = true;
37282
+ this._helpCommand = helpCommand;
37283
+ this._initCommandGroup(helpCommand);
37284
+ return this;
37285
+ }
37286
+ _getHelpCommand() {
37287
+ const hasImplicitHelpCommand = this._addImplicitHelpCommand ?? (this.commands.length && !this._actionHandler && !this._findCommand("help"));
37288
+ if (hasImplicitHelpCommand) {
37289
+ if (this._helpCommand === undefined) {
37290
+ this.helpCommand(undefined, undefined);
37291
+ }
37292
+ return this._helpCommand;
37132
37293
  }
37133
- return this._addImplicitHelpCommand;
37294
+ return null;
37134
37295
  }
37135
37296
  hook(event, listener) {
37136
37297
  const allowedValues = ["preSubcommand", "preAction", "postAction"];
@@ -37192,7 +37353,31 @@ Expecting one of '${allowedValues.join("', '")}'`);
37192
37353
  throw err;
37193
37354
  }
37194
37355
  }
37356
+ _registerOption(option) {
37357
+ const matchingOption = option.short && this._findOption(option.short) || option.long && this._findOption(option.long);
37358
+ if (matchingOption) {
37359
+ const matchingFlag = option.long && this._findOption(option.long) ? option.long : option.short;
37360
+ throw new Error(`Cannot add option '${option.flags}'${this._name && ` to command '${this._name}'`} due to conflicting flag '${matchingFlag}'
37361
+ - already used by option '${matchingOption.flags}'`);
37362
+ }
37363
+ this._initOptionGroup(option);
37364
+ this.options.push(option);
37365
+ }
37366
+ _registerCommand(command) {
37367
+ const knownBy = (cmd) => {
37368
+ return [cmd.name()].concat(cmd.aliases());
37369
+ };
37370
+ const alreadyUsed = knownBy(command).find((name) => this._findCommand(name));
37371
+ if (alreadyUsed) {
37372
+ const existingCmd = knownBy(this._findCommand(alreadyUsed)).join("|");
37373
+ const newCmd = knownBy(command).join("|");
37374
+ throw new Error(`cannot add command '${newCmd}' as already have command '${existingCmd}'`);
37375
+ }
37376
+ this._initCommandGroup(command);
37377
+ this.commands.push(command);
37378
+ }
37195
37379
  addOption(option) {
37380
+ this._registerOption(option);
37196
37381
  const oname = option.name();
37197
37382
  const name = option.attributeName();
37198
37383
  if (option.negate) {
@@ -37203,7 +37388,6 @@ Expecting one of '${allowedValues.join("', '")}'`);
37203
37388
  } else if (option.defaultValue !== undefined) {
37204
37389
  this.setOptionValueWithSource(name, option.defaultValue, "default");
37205
37390
  }
37206
- this.options.push(option);
37207
37391
  const handleOptionValue = (val, invalidValueMessage, valueSource) => {
37208
37392
  if (val == null && option.presetArg !== undefined) {
37209
37393
  val = option.presetArg;
@@ -37281,15 +37465,21 @@ Expecting one of '${allowedValues.join("', '")}'`);
37281
37465
  }
37282
37466
  passThroughOptions(passThrough = true) {
37283
37467
  this._passThroughOptions = !!passThrough;
37284
- if (!!this.parent && passThrough && !this.parent._enablePositionalOptions) {
37285
- throw new Error("passThroughOptions can not be used without turning on enablePositionalOptions for parent command(s)");
37286
- }
37468
+ this._checkForBrokenPassThrough();
37287
37469
  return this;
37288
37470
  }
37471
+ _checkForBrokenPassThrough() {
37472
+ if (this.parent && this._passThroughOptions && !this.parent._enablePositionalOptions) {
37473
+ throw new Error(`passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`);
37474
+ }
37475
+ }
37289
37476
  storeOptionsAsProperties(storeAsProperties = true) {
37290
37477
  if (this.options.length) {
37291
37478
  throw new Error("call .storeOptionsAsProperties() before adding options");
37292
37479
  }
37480
+ if (Object.keys(this._optionValues).length) {
37481
+ throw new Error("call .storeOptionsAsProperties() before setting option values");
37482
+ }
37293
37483
  this._storeOptionsAsProperties = !!storeAsProperties;
37294
37484
  return this;
37295
37485
  }
@@ -37328,11 +37518,17 @@ Expecting one of '${allowedValues.join("', '")}'`);
37328
37518
  throw new Error("first parameter to parse must be array or undefined");
37329
37519
  }
37330
37520
  parseOptions = parseOptions || {};
37331
- if (argv === undefined) {
37332
- argv = process3.argv;
37333
- if (process3.versions && process3.versions.electron) {
37521
+ if (argv === undefined && parseOptions.from === undefined) {
37522
+ if (process3.versions?.electron) {
37334
37523
  parseOptions.from = "electron";
37335
37524
  }
37525
+ const execArgv = process3.execArgv ?? [];
37526
+ if (execArgv.includes("-e") || execArgv.includes("--eval") || execArgv.includes("-p") || execArgv.includes("--print")) {
37527
+ parseOptions.from = "eval";
37528
+ }
37529
+ }
37530
+ if (argv === undefined) {
37531
+ argv = process3.argv;
37336
37532
  }
37337
37533
  this.rawArgs = argv.slice();
37338
37534
  let userArgs;
@@ -37353,6 +37549,9 @@ Expecting one of '${allowedValues.join("', '")}'`);
37353
37549
  case "user":
37354
37550
  userArgs = argv.slice(0);
37355
37551
  break;
37552
+ case "eval":
37553
+ userArgs = argv.slice(1);
37554
+ break;
37356
37555
  default:
37357
37556
  throw new Error(`unexpected parse option { from: '${parseOptions.from}' }`);
37358
37557
  }
@@ -37362,15 +37561,53 @@ Expecting one of '${allowedValues.join("', '")}'`);
37362
37561
  return userArgs;
37363
37562
  }
37364
37563
  parse(argv, parseOptions) {
37564
+ this._prepareForParse();
37365
37565
  const userArgs = this._prepareUserArgs(argv, parseOptions);
37366
37566
  this._parseCommand([], userArgs);
37367
37567
  return this;
37368
37568
  }
37369
37569
  async parseAsync(argv, parseOptions) {
37570
+ this._prepareForParse();
37370
37571
  const userArgs = this._prepareUserArgs(argv, parseOptions);
37371
37572
  await this._parseCommand([], userArgs);
37372
37573
  return this;
37373
37574
  }
37575
+ _prepareForParse() {
37576
+ if (this._savedState === null) {
37577
+ this.saveStateBeforeParse();
37578
+ } else {
37579
+ this.restoreStateBeforeParse();
37580
+ }
37581
+ }
37582
+ saveStateBeforeParse() {
37583
+ this._savedState = {
37584
+ _name: this._name,
37585
+ _optionValues: { ...this._optionValues },
37586
+ _optionValueSources: { ...this._optionValueSources }
37587
+ };
37588
+ }
37589
+ restoreStateBeforeParse() {
37590
+ if (this._storeOptionsAsProperties)
37591
+ throw new Error(`Can not call parse again when storeOptionsAsProperties is true.
37592
+ - either make a new Command for each call to parse, or stop storing options as properties`);
37593
+ this._name = this._savedState._name;
37594
+ this._scriptPath = null;
37595
+ this.rawArgs = [];
37596
+ this._optionValues = { ...this._savedState._optionValues };
37597
+ this._optionValueSources = { ...this._savedState._optionValueSources };
37598
+ this.args = [];
37599
+ this.processedArgs = [];
37600
+ }
37601
+ _checkForMissingExecutable(executableFile, executableDir, subcommandName) {
37602
+ if (fs.existsSync(executableFile))
37603
+ return;
37604
+ const executableDirMessage = executableDir ? `searched for local subcommand relative to directory '${executableDir}'` : "no directory for search for local subcommand, use .executableDir() to supply a custom directory";
37605
+ const executableMissing = `'${executableFile}' does not exist
37606
+ - if '${subcommandName}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
37607
+ - if the default executable name is not suitable, use the executableFile option to supply a custom name or path
37608
+ - ${executableDirMessage}`;
37609
+ throw new Error(executableMissing);
37610
+ }
37374
37611
  _executeSubCommand(subcommand, args) {
37375
37612
  args = args.slice();
37376
37613
  let launchWithNode = false;
@@ -37394,7 +37631,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
37394
37631
  let resolvedScriptPath;
37395
37632
  try {
37396
37633
  resolvedScriptPath = fs.realpathSync(this._scriptPath);
37397
- } catch (err) {
37634
+ } catch {
37398
37635
  resolvedScriptPath = this._scriptPath;
37399
37636
  }
37400
37637
  executableDir = path2.resolve(path2.dirname(resolvedScriptPath), executableDir);
@@ -37420,6 +37657,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
37420
37657
  proc2 = childProcess.spawn(executableFile, args, { stdio: "inherit" });
37421
37658
  }
37422
37659
  } else {
37660
+ this._checkForMissingExecutable(executableFile, executableDir, subcommand._name);
37423
37661
  args.unshift(executableFile);
37424
37662
  args = incrementNodeInspectorPort(process3.execArgv).concat(args);
37425
37663
  proc2 = childProcess.spawn(process3.execPath, args, { stdio: "inherit" });
@@ -37435,21 +37673,17 @@ Expecting one of '${allowedValues.join("', '")}'`);
37435
37673
  });
37436
37674
  }
37437
37675
  const exitCallback = this._exitCallback;
37438
- if (!exitCallback) {
37439
- proc2.on("close", process3.exit.bind(process3));
37440
- } else {
37441
- proc2.on("close", () => {
37442
- exitCallback(new CommanderError(process3.exitCode || 0, "commander.executeSubCommandAsync", "(close)"));
37443
- });
37444
- }
37676
+ proc2.on("close", (code) => {
37677
+ code = code ?? 1;
37678
+ if (!exitCallback) {
37679
+ process3.exit(code);
37680
+ } else {
37681
+ exitCallback(new CommanderError(code, "commander.executeSubCommandAsync", "(close)"));
37682
+ }
37683
+ });
37445
37684
  proc2.on("error", (err) => {
37446
37685
  if (err.code === "ENOENT") {
37447
- const executableDirMessage = executableDir ? `searched for local subcommand relative to directory '${executableDir}'` : "no directory for search for local subcommand, use .executableDir() to supply a custom directory";
37448
- const executableMissing = `'${executableFile}' does not exist
37449
- - if '${subcommand._name}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
37450
- - if the default executable name is not suitable, use the executableFile option to supply a custom name or path
37451
- - ${executableDirMessage}`;
37452
- throw new Error(executableMissing);
37686
+ this._checkForMissingExecutable(executableFile, executableDir, subcommand._name);
37453
37687
  } else if (err.code === "EACCES") {
37454
37688
  throw new Error(`'${executableFile}' not executable`);
37455
37689
  }
@@ -37467,6 +37701,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
37467
37701
  const subCommand = this._findCommand(commandName);
37468
37702
  if (!subCommand)
37469
37703
  this.help({ error: true });
37704
+ subCommand._prepareForParse();
37470
37705
  let promiseChain;
37471
37706
  promiseChain = this._chainOrCallSubCommandHook(promiseChain, subCommand, "preSubcommand");
37472
37707
  promiseChain = this._chainOrCall(promiseChain, () => {
@@ -37486,9 +37721,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
37486
37721
  if (subCommand && !subCommand._executableHandler) {
37487
37722
  subCommand.help();
37488
37723
  }
37489
- return this._dispatchSubcommand(subcommandName, [], [
37490
- this._helpLongFlag || this._helpShortFlag
37491
- ]);
37724
+ return this._dispatchSubcommand(subcommandName, [], [this._getHelpOption()?.long ?? this._getHelpOption()?.short ?? "--help"]);
37492
37725
  }
37493
37726
  _checkNumberOfArguments() {
37494
37727
  this.registeredArguments.forEach((arg, i) => {
@@ -37582,17 +37815,17 @@ Expecting one of '${allowedValues.join("', '")}'`);
37582
37815
  if (operands && this._findCommand(operands[0])) {
37583
37816
  return this._dispatchSubcommand(operands[0], operands.slice(1), unknown2);
37584
37817
  }
37585
- if (this._hasImplicitHelpCommand() && operands[0] === this._helpCommandName) {
37818
+ if (this._getHelpCommand() && operands[0] === this._getHelpCommand().name()) {
37586
37819
  return this._dispatchHelpCommand(operands[1]);
37587
37820
  }
37588
37821
  if (this._defaultCommandName) {
37589
- outputHelpIfRequested(this, unknown2);
37822
+ this._outputHelpIfRequested(unknown2);
37590
37823
  return this._dispatchSubcommand(this._defaultCommandName, operands, unknown2);
37591
37824
  }
37592
37825
  if (this.commands.length && this.args.length === 0 && !this._actionHandler && !this._defaultCommandName) {
37593
37826
  this.help({ error: true });
37594
37827
  }
37595
- outputHelpIfRequested(this, parsed.unknown);
37828
+ this._outputHelpIfRequested(parsed.unknown);
37596
37829
  this._checkForMissingMandatoryOptions();
37597
37830
  this._checkForConflictingOptions();
37598
37831
  const checkForUnknownOptions = () => {
@@ -37685,6 +37918,11 @@ Expecting one of '${allowedValues.join("', '")}'`);
37685
37918
  function maybeOption(arg) {
37686
37919
  return arg.length > 1 && arg[0] === "-";
37687
37920
  }
37921
+ const negativeNumberArg = (arg) => {
37922
+ if (!/^-\d*\.?\d+(e[+-]?\d+)?$/.test(arg))
37923
+ return false;
37924
+ return !this._getCommandAndAncestors().some((cmd) => cmd.options.map((opt) => opt.short).some((short) => /^-\d$/.test(short)));
37925
+ };
37688
37926
  let activeVariadicOption = null;
37689
37927
  while (args.length) {
37690
37928
  const arg = args.shift();
@@ -37694,7 +37932,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
37694
37932
  dest.push(...args);
37695
37933
  break;
37696
37934
  }
37697
- if (activeVariadicOption && !maybeOption(arg)) {
37935
+ if (activeVariadicOption && (!maybeOption(arg) || negativeNumberArg(arg))) {
37698
37936
  this.emit(`option:${activeVariadicOption.name()}`, arg);
37699
37937
  continue;
37700
37938
  }
@@ -37709,7 +37947,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
37709
37947
  this.emit(`option:${option.name()}`, value);
37710
37948
  } else if (option.optional) {
37711
37949
  let value = null;
37712
- if (args.length > 0 && !maybeOption(args[0])) {
37950
+ if (args.length > 0 && (!maybeOption(args[0]) || negativeNumberArg(args[0]))) {
37713
37951
  value = args.shift();
37714
37952
  }
37715
37953
  this.emit(`option:${option.name()}`, value);
@@ -37740,7 +37978,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
37740
37978
  continue;
37741
37979
  }
37742
37980
  }
37743
- if (maybeOption(arg)) {
37981
+ if (dest === operands && maybeOption(arg) && !(this.commands.length === 0 && negativeNumberArg(arg))) {
37744
37982
  dest = unknown2;
37745
37983
  }
37746
37984
  if ((this._enablePositionalOptions || this._passThroughOptions) && operands.length === 0 && unknown2.length === 0) {
@@ -37749,7 +37987,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
37749
37987
  if (args.length > 0)
37750
37988
  unknown2.push(...args);
37751
37989
  break;
37752
- } else if (arg === this._helpCommandName && this._hasImplicitHelpCommand()) {
37990
+ } else if (this._getHelpCommand() && arg === this._getHelpCommand().name()) {
37753
37991
  operands.push(arg);
37754
37992
  if (args.length > 0)
37755
37993
  operands.push(...args);
@@ -37911,7 +38149,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
37911
38149
  description = description || "output the version number";
37912
38150
  const versionOption = this.createOption(flags, description);
37913
38151
  this._versionOptionName = versionOption.attributeName();
37914
- this.options.push(versionOption);
38152
+ this._registerOption(versionOption);
37915
38153
  this.on("option:" + versionOption.name(), () => {
37916
38154
  this._outputConfiguration.writeOut(`${str}
37917
38155
  `);
@@ -37943,6 +38181,11 @@ Expecting one of '${allowedValues.join("', '")}'`);
37943
38181
  }
37944
38182
  if (alias === command._name)
37945
38183
  throw new Error("Command alias can't be the same as its name");
38184
+ const matchingCommand = this.parent?._findCommand(alias);
38185
+ if (matchingCommand) {
38186
+ const existingCmd = [matchingCommand.name()].concat(matchingCommand.aliases()).join("|");
38187
+ throw new Error(`cannot add alias '${alias}' to command '${this.name()}' as already have command '${existingCmd}'`);
38188
+ }
37946
38189
  command._aliases.push(alias);
37947
38190
  return this;
37948
38191
  }
@@ -37959,7 +38202,7 @@ Expecting one of '${allowedValues.join("', '")}'`);
37959
38202
  const args = this.registeredArguments.map((arg) => {
37960
38203
  return humanReadableArgName(arg);
37961
38204
  });
37962
- return [].concat(this.options.length || this._hasHelpOption ? "[options]" : [], this.commands.length ? "[command]" : [], this.registeredArguments.length ? args : []).join(" ");
38205
+ return [].concat(this.options.length || this._helpOption !== null ? "[options]" : [], this.commands.length ? "[command]" : [], this.registeredArguments.length ? args : []).join(" ");
37963
38206
  }
37964
38207
  this._usage = str;
37965
38208
  return this;
@@ -37970,6 +38213,32 @@ Expecting one of '${allowedValues.join("', '")}'`);
37970
38213
  this._name = str;
37971
38214
  return this;
37972
38215
  }
38216
+ helpGroup(heading) {
38217
+ if (heading === undefined)
38218
+ return this._helpGroupHeading ?? "";
38219
+ this._helpGroupHeading = heading;
38220
+ return this;
38221
+ }
38222
+ commandsGroup(heading) {
38223
+ if (heading === undefined)
38224
+ return this._defaultCommandGroup ?? "";
38225
+ this._defaultCommandGroup = heading;
38226
+ return this;
38227
+ }
38228
+ optionsGroup(heading) {
38229
+ if (heading === undefined)
38230
+ return this._defaultOptionGroup ?? "";
38231
+ this._defaultOptionGroup = heading;
38232
+ return this;
38233
+ }
38234
+ _initOptionGroup(option) {
38235
+ if (this._defaultOptionGroup && !option.helpGroupHeading)
38236
+ option.helpGroup(this._defaultOptionGroup);
38237
+ }
38238
+ _initCommandGroup(cmd) {
38239
+ if (this._defaultCommandGroup && !cmd.helpGroup())
38240
+ cmd.helpGroup(this._defaultCommandGroup);
38241
+ }
37973
38242
  nameFromFilename(filename) {
37974
38243
  this._name = path2.basename(filename, path2.extname(filename));
37975
38244
  return this;
@@ -37982,23 +38251,38 @@ Expecting one of '${allowedValues.join("', '")}'`);
37982
38251
  }
37983
38252
  helpInformation(contextOptions) {
37984
38253
  const helper = this.createHelp();
37985
- if (helper.helpWidth === undefined) {
37986
- helper.helpWidth = contextOptions && contextOptions.error ? this._outputConfiguration.getErrHelpWidth() : this._outputConfiguration.getOutHelpWidth();
37987
- }
37988
- return helper.formatHelp(this, helper);
38254
+ const context = this._getOutputContext(contextOptions);
38255
+ helper.prepareContext({
38256
+ error: context.error,
38257
+ helpWidth: context.helpWidth,
38258
+ outputHasColors: context.hasColors
38259
+ });
38260
+ const text = helper.formatHelp(this, helper);
38261
+ if (context.hasColors)
38262
+ return text;
38263
+ return this._outputConfiguration.stripColor(text);
37989
38264
  }
37990
- _getHelpContext(contextOptions) {
38265
+ _getOutputContext(contextOptions) {
37991
38266
  contextOptions = contextOptions || {};
37992
- const context = { error: !!contextOptions.error };
37993
- let write;
37994
- if (context.error) {
37995
- write = (arg) => this._outputConfiguration.writeErr(arg);
38267
+ const error = !!contextOptions.error;
38268
+ let baseWrite;
38269
+ let hasColors2;
38270
+ let helpWidth;
38271
+ if (error) {
38272
+ baseWrite = (str) => this._outputConfiguration.writeErr(str);
38273
+ hasColors2 = this._outputConfiguration.getErrHasColors();
38274
+ helpWidth = this._outputConfiguration.getErrHelpWidth();
37996
38275
  } else {
37997
- write = (arg) => this._outputConfiguration.writeOut(arg);
37998
- }
37999
- context.write = contextOptions.write || write;
38000
- context.command = this;
38001
- return context;
38276
+ baseWrite = (str) => this._outputConfiguration.writeOut(str);
38277
+ hasColors2 = this._outputConfiguration.getOutHasColors();
38278
+ helpWidth = this._outputConfiguration.getOutHelpWidth();
38279
+ }
38280
+ const write = (str) => {
38281
+ if (!hasColors2)
38282
+ str = this._outputConfiguration.stripColor(str);
38283
+ return baseWrite(str);
38284
+ };
38285
+ return { error, write, hasColors: hasColors2, helpWidth };
38002
38286
  }
38003
38287
  outputHelp(contextOptions) {
38004
38288
  let deprecatedCallback;
@@ -38006,38 +38290,60 @@ Expecting one of '${allowedValues.join("', '")}'`);
38006
38290
  deprecatedCallback = contextOptions;
38007
38291
  contextOptions = undefined;
38008
38292
  }
38009
- const context = this._getHelpContext(contextOptions);
38010
- this._getCommandAndAncestors().reverse().forEach((command) => command.emit("beforeAllHelp", context));
38011
- this.emit("beforeHelp", context);
38012
- let helpInformation = this.helpInformation(context);
38293
+ const outputContext = this._getOutputContext(contextOptions);
38294
+ const eventContext = {
38295
+ error: outputContext.error,
38296
+ write: outputContext.write,
38297
+ command: this
38298
+ };
38299
+ this._getCommandAndAncestors().reverse().forEach((command) => command.emit("beforeAllHelp", eventContext));
38300
+ this.emit("beforeHelp", eventContext);
38301
+ let helpInformation = this.helpInformation({ error: outputContext.error });
38013
38302
  if (deprecatedCallback) {
38014
38303
  helpInformation = deprecatedCallback(helpInformation);
38015
38304
  if (typeof helpInformation !== "string" && !Buffer.isBuffer(helpInformation)) {
38016
38305
  throw new Error("outputHelp callback must return a string or a Buffer");
38017
38306
  }
38018
38307
  }
38019
- context.write(helpInformation);
38020
- if (this._helpLongFlag) {
38021
- this.emit(this._helpLongFlag);
38308
+ outputContext.write(helpInformation);
38309
+ if (this._getHelpOption()?.long) {
38310
+ this.emit(this._getHelpOption().long);
38022
38311
  }
38023
- this.emit("afterHelp", context);
38024
- this._getCommandAndAncestors().forEach((command) => command.emit("afterAllHelp", context));
38312
+ this.emit("afterHelp", eventContext);
38313
+ this._getCommandAndAncestors().forEach((command) => command.emit("afterAllHelp", eventContext));
38025
38314
  }
38026
38315
  helpOption(flags, description) {
38027
38316
  if (typeof flags === "boolean") {
38028
- this._hasHelpOption = flags;
38317
+ if (flags) {
38318
+ if (this._helpOption === null)
38319
+ this._helpOption = undefined;
38320
+ if (this._defaultOptionGroup) {
38321
+ this._initOptionGroup(this._getHelpOption());
38322
+ }
38323
+ } else {
38324
+ this._helpOption = null;
38325
+ }
38029
38326
  return this;
38030
38327
  }
38031
- this._helpFlags = flags || this._helpFlags;
38032
- this._helpDescription = description || this._helpDescription;
38033
- const helpFlags = splitOptionFlags(this._helpFlags);
38034
- this._helpShortFlag = helpFlags.shortFlag;
38035
- this._helpLongFlag = helpFlags.longFlag;
38328
+ this._helpOption = this.createOption(flags ?? "-h, --help", description ?? "display help for command");
38329
+ if (flags || description)
38330
+ this._initOptionGroup(this._helpOption);
38331
+ return this;
38332
+ }
38333
+ _getHelpOption() {
38334
+ if (this._helpOption === undefined) {
38335
+ this.helpOption(undefined, undefined);
38336
+ }
38337
+ return this._helpOption;
38338
+ }
38339
+ addHelpOption(option) {
38340
+ this._helpOption = option;
38341
+ this._initOptionGroup(option);
38036
38342
  return this;
38037
38343
  }
38038
38344
  help(contextOptions) {
38039
38345
  this.outputHelp(contextOptions);
38040
- let exitCode = process3.exitCode || 0;
38346
+ let exitCode = Number(process3.exitCode ?? 0);
38041
38347
  if (exitCode === 0 && contextOptions && typeof contextOptions !== "function" && contextOptions.error) {
38042
38348
  exitCode = 1;
38043
38349
  }
@@ -38064,12 +38370,13 @@ Expecting one of '${allowedValues.join("', '")}'`);
38064
38370
  });
38065
38371
  return this;
38066
38372
  }
38067
- }
38068
- function outputHelpIfRequested(cmd, args) {
38069
- const helpOption = cmd._hasHelpOption && args.find((arg) => arg === cmd._helpLongFlag || arg === cmd._helpShortFlag);
38070
- if (helpOption) {
38071
- cmd.outputHelp();
38072
- cmd._exit(0, "commander.helpDisplayed", "(outputHelp)");
38373
+ _outputHelpIfRequested(args) {
38374
+ const helpOption = this._getHelpOption();
38375
+ const helpRequested = helpOption && args.find((arg) => helpOption.is(arg));
38376
+ if (helpRequested) {
38377
+ this.outputHelp();
38378
+ this._exit(0, "commander.helpDisplayed", "(outputHelp)");
38379
+ }
38073
38380
  }
38074
38381
  }
38075
38382
  function incrementNodeInspectorPort(args) {
@@ -38101,18 +38408,28 @@ Expecting one of '${allowedValues.join("', '")}'`);
38101
38408
  return arg;
38102
38409
  });
38103
38410
  }
38411
+ function useColor() {
38412
+ if (process3.env.NO_COLOR || process3.env.FORCE_COLOR === "0" || process3.env.FORCE_COLOR === "false")
38413
+ return false;
38414
+ if (process3.env.FORCE_COLOR || process3.env.CLICOLOR_FORCE !== undefined)
38415
+ return true;
38416
+ return;
38417
+ }
38104
38418
  exports.Command = Command;
38419
+ exports.useColor = useColor;
38105
38420
  });
38106
38421
 
38107
38422
  // ../../node_modules/commander/index.js
38108
- var require_commander = __commonJS((exports, module) => {
38423
+ var require_commander = __commonJS((exports) => {
38109
38424
  var { Argument } = require_argument();
38110
38425
  var { Command } = require_command();
38111
38426
  var { CommanderError, InvalidArgumentError } = require_error3();
38112
38427
  var { Help } = require_help();
38113
38428
  var { Option } = require_option();
38114
- exports = module.exports = new Command;
38115
- exports.program = exports;
38429
+ exports.program = new Command;
38430
+ exports.createCommand = (name) => new Command(name);
38431
+ exports.createOption = (flags, description) => new Option(flags, description);
38432
+ exports.createArgument = (name, description) => new Argument(name, description);
38116
38433
  exports.Command = Command;
38117
38434
  exports.Option = Option;
38118
38435
  exports.Argument = Argument;
@@ -53834,8 +54151,14 @@ var ToolSchema = z.object({
53834
54151
  description: z.optional(z.string()),
53835
54152
  inputSchema: z.object({
53836
54153
  type: z.literal("object"),
53837
- properties: z.optional(z.object({}).passthrough())
54154
+ properties: z.optional(z.object({}).passthrough()),
54155
+ required: z.optional(z.array(z.string()))
53838
54156
  }).passthrough(),
54157
+ outputSchema: z.optional(z.object({
54158
+ type: z.literal("object"),
54159
+ properties: z.optional(z.object({}).passthrough()),
54160
+ required: z.optional(z.array(z.string()))
54161
+ }).passthrough()),
53839
54162
  annotations: z.optional(ToolAnnotationsSchema)
53840
54163
  }).passthrough();
53841
54164
  var ListToolsRequestSchema = PaginatedRequestSchema.extend({
@@ -53844,10 +54167,26 @@ var ListToolsRequestSchema = PaginatedRequestSchema.extend({
53844
54167
  var ListToolsResultSchema = PaginatedResultSchema.extend({
53845
54168
  tools: z.array(ToolSchema)
53846
54169
  });
53847
- var CallToolResultSchema = ResultSchema.extend({
53848
- content: z.array(z.union([TextContentSchema, ImageContentSchema, AudioContentSchema, EmbeddedResourceSchema])),
53849
- isError: z.boolean().default(false).optional()
54170
+ var ContentListSchema = z.array(z.union([
54171
+ TextContentSchema,
54172
+ ImageContentSchema,
54173
+ AudioContentSchema,
54174
+ EmbeddedResourceSchema
54175
+ ]));
54176
+ var CallToolUnstructuredResultSchema = ResultSchema.extend({
54177
+ content: ContentListSchema,
54178
+ structuredContent: z.never().optional(),
54179
+ isError: z.optional(z.boolean())
53850
54180
  });
54181
+ var CallToolStructuredResultSchema = ResultSchema.extend({
54182
+ structuredContent: z.object({}).passthrough(),
54183
+ content: z.optional(ContentListSchema),
54184
+ isError: z.optional(z.boolean())
54185
+ });
54186
+ var CallToolResultSchema = z.union([
54187
+ CallToolUnstructuredResultSchema,
54188
+ CallToolStructuredResultSchema
54189
+ ]);
53851
54190
  var CompatibilityCallToolResultSchema = CallToolResultSchema.or(ResultSchema.extend({
53852
54191
  toolResult: z.unknown()
53853
54192
  }));
@@ -55766,7 +56105,7 @@ class McpServer {
55766
56105
  });
55767
56106
  this.server.setRequestHandler(ListToolsRequestSchema, () => ({
55768
56107
  tools: Object.entries(this._registeredTools).filter(([, tool]) => tool.enabled).map(([name, tool]) => {
55769
- return {
56108
+ const toolDefinition = {
55770
56109
  name,
55771
56110
  description: tool.description,
55772
56111
  inputSchema: tool.inputSchema ? zodToJsonSchema(tool.inputSchema, {
@@ -55774,6 +56113,10 @@ class McpServer {
55774
56113
  }) : EMPTY_OBJECT_JSON_SCHEMA,
55775
56114
  annotations: tool.annotations
55776
56115
  };
56116
+ if (tool.outputSchema) {
56117
+ toolDefinition.outputSchema = zodToJsonSchema(tool.outputSchema, { strictUnions: true });
56118
+ }
56119
+ return toolDefinition;
55777
56120
  })
55778
56121
  }));
55779
56122
  this.server.setRequestHandler(CallToolRequestSchema, async (request, extra) => {
@@ -55784,6 +56127,7 @@ class McpServer {
55784
56127
  if (!tool.enabled) {
55785
56128
  throw new McpError(ErrorCode.InvalidParams, `Tool ${request.params.name} disabled`);
55786
56129
  }
56130
+ let result;
55787
56131
  if (tool.inputSchema) {
55788
56132
  const parseResult = await tool.inputSchema.safeParseAsync(request.params.arguments);
55789
56133
  if (!parseResult.success) {
@@ -55792,9 +56136,9 @@ class McpServer {
55792
56136
  const args = parseResult.data;
55793
56137
  const cb = tool.callback;
55794
56138
  try {
55795
- return await Promise.resolve(cb(args, extra));
56139
+ result = await Promise.resolve(cb(args, extra));
55796
56140
  } catch (error) {
55797
- return {
56141
+ result = {
55798
56142
  content: [
55799
56143
  {
55800
56144
  type: "text",
@@ -55807,9 +56151,9 @@ class McpServer {
55807
56151
  } else {
55808
56152
  const cb = tool.callback;
55809
56153
  try {
55810
- return await Promise.resolve(cb(extra));
56154
+ result = await Promise.resolve(cb(extra));
55811
56155
  } catch (error) {
55812
- return {
56156
+ result = {
55813
56157
  content: [
55814
56158
  {
55815
56159
  type: "text",
@@ -55820,6 +56164,27 @@ class McpServer {
55820
56164
  };
55821
56165
  }
55822
56166
  }
56167
+ if (tool.outputSchema) {
56168
+ if (!result.structuredContent && !result.isError) {
56169
+ throw new McpError(ErrorCode.InternalError, `Tool ${request.params.name} has outputSchema but returned no structuredContent`);
56170
+ }
56171
+ if (result.structuredContent && !result.content) {
56172
+ result.content = [
56173
+ {
56174
+ type: "text",
56175
+ text: JSON.stringify(result.structuredContent, null, 2)
56176
+ }
56177
+ ];
56178
+ }
56179
+ } else {
56180
+ if (!result.content && !result.isError) {
56181
+ throw new McpError(ErrorCode.InternalError, `Tool ${request.params.name} has no outputSchema and must return content`);
56182
+ }
56183
+ if (result.structuredContent) {
56184
+ throw new McpError(ErrorCode.InternalError, `Tool ${request.params.name} has no outputSchema but returned structuredContent`);
56185
+ }
56186
+ }
56187
+ return result;
55823
56188
  });
55824
56189
  this._toolHandlersInitialized = true;
55825
56190
  }
@@ -56053,33 +56418,13 @@ class McpServer {
56053
56418
  return registeredResourceTemplate;
56054
56419
  }
56055
56420
  }
56056
- tool(name, ...rest) {
56057
- if (this._registeredTools[name]) {
56058
- throw new Error(`Tool ${name} is already registered`);
56059
- }
56060
- let description;
56061
- if (typeof rest[0] === "string") {
56062
- description = rest.shift();
56063
- }
56064
- let paramsSchema;
56065
- let annotations;
56066
- if (rest.length > 1) {
56067
- const firstArg = rest[0];
56068
- if (isZodRawShape(firstArg)) {
56069
- paramsSchema = rest.shift();
56070
- if (rest.length > 1 && typeof rest[0] === "object" && rest[0] !== null && !isZodRawShape(rest[0])) {
56071
- annotations = rest.shift();
56072
- }
56073
- } else if (typeof firstArg === "object" && firstArg !== null) {
56074
- annotations = rest.shift();
56075
- }
56076
- }
56077
- const cb = rest[0];
56421
+ _createRegisteredTool(name, description, inputSchema, outputSchema, annotations, callback) {
56078
56422
  const registeredTool = {
56079
56423
  description,
56080
- inputSchema: paramsSchema === undefined ? undefined : z.object(paramsSchema),
56424
+ inputSchema: inputSchema === undefined ? undefined : z.object(inputSchema),
56425
+ outputSchema: outputSchema === undefined ? undefined : z.object(outputSchema),
56081
56426
  annotations,
56082
- callback: cb,
56427
+ callback,
56083
56428
  enabled: true,
56084
56429
  disable: () => registeredTool.update({ enabled: false }),
56085
56430
  enable: () => registeredTool.update({ enabled: true }),
@@ -56108,6 +56453,38 @@ class McpServer {
56108
56453
  this.sendToolListChanged();
56109
56454
  return registeredTool;
56110
56455
  }
56456
+ tool(name, ...rest) {
56457
+ if (this._registeredTools[name]) {
56458
+ throw new Error(`Tool ${name} is already registered`);
56459
+ }
56460
+ let description;
56461
+ let inputSchema;
56462
+ let outputSchema;
56463
+ let annotations;
56464
+ if (typeof rest[0] === "string") {
56465
+ description = rest.shift();
56466
+ }
56467
+ if (rest.length > 1) {
56468
+ const firstArg = rest[0];
56469
+ if (isZodRawShape(firstArg)) {
56470
+ inputSchema = rest.shift();
56471
+ if (rest.length > 1 && typeof rest[0] === "object" && rest[0] !== null && !isZodRawShape(rest[0])) {
56472
+ annotations = rest.shift();
56473
+ }
56474
+ } else if (typeof firstArg === "object" && firstArg !== null) {
56475
+ annotations = rest.shift();
56476
+ }
56477
+ }
56478
+ const callback = rest[0];
56479
+ return this._createRegisteredTool(name, description, inputSchema, outputSchema, annotations, callback);
56480
+ }
56481
+ registerTool(name, config, cb) {
56482
+ if (this._registeredTools[name]) {
56483
+ throw new Error(`Tool ${name} is already registered`);
56484
+ }
56485
+ const { description, inputSchema, outputSchema, annotations } = config;
56486
+ return this._createRegisteredTool(name, description, inputSchema, outputSchema, annotations, cb);
56487
+ }
56111
56488
  prompt(name, ...rest) {
56112
56489
  if (this._registeredPrompts[name]) {
56113
56490
  throw new Error(`Prompt ${name} is already registered`);
@@ -56300,7 +56677,7 @@ class StdioServerTransport {
56300
56677
  }
56301
56678
 
56302
56679
  // ../utils/dist/environment.mjs
56303
- import { join as join2 } from "node:path";
56680
+ import { join as join2 } from "path";
56304
56681
 
56305
56682
  // ../../node_modules/yoctocolors/base.js
56306
56683
  import tty from "node:tty";
@@ -61874,7 +62251,7 @@ var {
61874
62251
  var package_default = {
61875
62252
  name: "@settlemint/sdk-mcp",
61876
62253
  description: "MCP interface for SettleMint SDK, providing development tools and project management capabilities",
61877
- version: "2.3.0",
62254
+ version: "2.3.1-pr9c56c214",
61878
62255
  type: "module",
61879
62256
  private: false,
61880
62257
  license: "FSL-1.1-MIT",
@@ -61915,11 +62292,11 @@ var package_default = {
61915
62292
  dependencies: {
61916
62293
  "@graphql-tools/load": "8.1.0",
61917
62294
  "@graphql-tools/url-loader": "8.0.31",
61918
- "@modelcontextprotocol/sdk": "1.11.3",
61919
- "@settlemint/sdk-js": "2.3.0",
61920
- "@settlemint/sdk-utils": "2.3.0",
62295
+ "@modelcontextprotocol/sdk": "1.11.4",
62296
+ "@settlemint/sdk-js": "2.3.1-pr9c56c214",
62297
+ "@settlemint/sdk-utils": "2.3.1-pr9c56c214",
61921
62298
  "@commander-js/extra-typings": "11.1.0",
61922
- commander: "11.1.0",
62299
+ commander: "14.0.0",
61923
62300
  zod: "3.24.4"
61924
62301
  },
61925
62302
  devDependencies: {},
@@ -64207,7 +64584,7 @@ function initGraphQLTada() {
64207
64584
  var t3 = initGraphQLTada();
64208
64585
 
64209
64586
  // ../js/dist/settlemint.mjs
64210
- import { createHash } from "node:crypto";
64587
+ import { createHash } from "crypto";
64211
64588
  var graphql = initGraphQLTada();
64212
64589
  var WorkspaceFragment = graphql(`
64213
64590
  fragment Workspace on Workspace {
@@ -67687,4 +68064,4 @@ await main().catch((error2) => {
67687
68064
  process.exit(1);
67688
68065
  });
67689
68066
 
67690
- //# debugId=433800AB979D17CA64756E2164756E21
68067
+ //# debugId=401A80C2AAF1B2E464756E2164756E21