@task-handoff/server 0.0.3-alpha.5 → 0.0.3-alpha.6
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/dist/server-cli.js +1 -1
- package/package.json +4 -4
package/dist/server-cli.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var t=require("node:events"),e=require("node:child_process"),n=require("node:path"),i=require("node:fs"),o=require("node:process"),r=require("node:http");function s(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var a,h,l={},u={},c={};function p(){if(a)return c;a=1;class t extends Error{constructor(t,e,n){super(n),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name,this.code=e,this.exitCode=t,this.nestedError=void 0}}return c.CommanderError=t,c.InvalidArgumentError=class extends t{constructor(t){super(1,"commander.invalidArgument",t),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name}},c}function d(){if(h)return u;h=1;const{InvalidArgumentError:t}=p();return u.Argument=class{constructor(t,e){switch(this.description=e||"",this.variadic=!1,this.parseArg=void 0,this.defaultValue=void 0,this.defaultValueDescription=void 0,this.argChoices=void 0,t[0]){case"<":this.required=!0,this._name=t.slice(1,-1);break;case"[":this.required=!1,this._name=t.slice(1,-1);break;default:this.required=!0,this._name=t}this._name.endsWith("...")&&(this.variadic=!0,this._name=this._name.slice(0,-3))}name(){return this._name}_collectValue(t,e){return e!==this.defaultValue&&Array.isArray(e)?(e.push(t),e):[t]}default(t,e){return this.defaultValue=t,this.defaultValueDescription=e,this}argParser(t){return this.parseArg=t,this}choices(e){return this.argChoices=e.slice(),this.parseArg=(e,n)=>{if(!this.argChoices.includes(e))throw new t(`Allowed choices are ${this.argChoices.join(", ")}.`);return this.variadic?this._collectValue(e,n):e},this}argRequired(){return this.required=!0,this}argOptional(){return this.required=!1,this}},u.humanReadableArgName=function(t){const e=t.name()+(!0===t.variadic?"...":"");return t.required?"<"+e+">":"["+e+"]"},u}var m,g={},f={};function _(){if(m)return f;m=1;const{humanReadableArgName:t}=d();function e(t){return t.replace(/\x1b\[\d*(;\d*)*m/g,"")}return f.Help=class{constructor(){this.helpWidth=void 0,this.minWidthToWrap=40,this.sortSubcommands=!1,this.sortOptions=!1,this.showGlobalOptions=!1}prepareContext(t){this.helpWidth=this.helpWidth??t.helpWidth??80}visibleCommands(t){const e=t.commands.filter(t=>!t._hidden),n=t._getHelpCommand();return n&&!n._hidden&&e.push(n),this.sortSubcommands&&e.sort((t,e)=>t.name().localeCompare(e.name())),e}compareOptions(t,e){const n=t=>t.short?t.short.replace(/^-/,""):t.long.replace(/^--/,"");return n(t).localeCompare(n(e))}visibleOptions(t){const e=t.options.filter(t=>!t.hidden),n=t._getHelpOption();if(n&&!n.hidden){const i=n.short&&t._findOption(n.short),o=n.long&&t._findOption(n.long);i||o?n.long&&!o?e.push(t.createOption(n.long,n.description)):n.short&&!i&&e.push(t.createOption(n.short,n.description)):e.push(n)}return this.sortOptions&&e.sort(this.compareOptions),e}visibleGlobalOptions(t){if(!this.showGlobalOptions)return[];const e=[];for(let n=t.parent;n;n=n.parent){const t=n.options.filter(t=>!t.hidden);e.push(...t)}return this.sortOptions&&e.sort(this.compareOptions),e}visibleArguments(t){return t._argsDescription&&t.registeredArguments.forEach(e=>{e.description=e.description||t._argsDescription[e.name()]||""}),t.registeredArguments.find(t=>t.description)?t.registeredArguments:[]}subcommandTerm(e){const n=e.registeredArguments.map(e=>t(e)).join(" ");return e._name+(e._aliases[0]?"|"+e._aliases[0]:"")+(e.options.length?" [options]":"")+(n?" "+n:"")}optionTerm(t){return t.flags}argumentTerm(t){return t.name()}longestSubcommandTermLength(t,e){return e.visibleCommands(t).reduce((t,n)=>Math.max(t,this.displayWidth(e.styleSubcommandTerm(e.subcommandTerm(n)))),0)}longestOptionTermLength(t,e){return e.visibleOptions(t).reduce((t,n)=>Math.max(t,this.displayWidth(e.styleOptionTerm(e.optionTerm(n)))),0)}longestGlobalOptionTermLength(t,e){return e.visibleGlobalOptions(t).reduce((t,n)=>Math.max(t,this.displayWidth(e.styleOptionTerm(e.optionTerm(n)))),0)}longestArgumentTermLength(t,e){return e.visibleArguments(t).reduce((t,n)=>Math.max(t,this.displayWidth(e.styleArgumentTerm(e.argumentTerm(n)))),0)}commandUsage(t){let e=t._name;t._aliases[0]&&(e=e+"|"+t._aliases[0]);let n="";for(let e=t.parent;e;e=e.parent)n=e.name()+" "+n;return n+e+" "+t.usage()}commandDescription(t){return t.description()}subcommandDescription(t){return t.summary()||t.description()}optionDescription(t){const e=[];if(t.argChoices&&e.push(`choices: ${t.argChoices.map(t=>JSON.stringify(t)).join(", ")}`),void 0!==t.defaultValue&&(t.required||t.optional||t.isBoolean()&&"boolean"==typeof t.defaultValue)&&e.push(`default: ${t.defaultValueDescription||JSON.stringify(t.defaultValue)}`),void 0!==t.presetArg&&t.optional&&e.push(`preset: ${JSON.stringify(t.presetArg)}`),void 0!==t.envVar&&e.push(`env: ${t.envVar}`),e.length>0){const n=`(${e.join(", ")})`;return t.description?`${t.description} ${n}`:n}return t.description}argumentDescription(t){const e=[];if(t.argChoices&&e.push(`choices: ${t.argChoices.map(t=>JSON.stringify(t)).join(", ")}`),void 0!==t.defaultValue&&e.push(`default: ${t.defaultValueDescription||JSON.stringify(t.defaultValue)}`),e.length>0){const n=`(${e.join(", ")})`;return t.description?`${t.description} ${n}`:n}return t.description}formatItemList(t,e,n){return 0===e.length?[]:[n.styleTitle(t),...e,""]}groupItems(t,e,n){const i=new Map;return t.forEach(t=>{const e=n(t);i.has(e)||i.set(e,[])}),e.forEach(t=>{const e=n(t);i.has(e)||i.set(e,[]),i.get(e).push(t)}),i}formatHelp(t,e){const n=e.padWidth(t,e),i=e.helpWidth??80;function o(t,i){return e.formatItem(t,n,i,e)}let r=[`${e.styleTitle("Usage:")} ${e.styleUsage(e.commandUsage(t))}`,""];const s=e.commandDescription(t);s.length>0&&(r=r.concat([e.boxWrap(e.styleCommandDescription(s),i),""]));const a=e.visibleArguments(t).map(t=>o(e.styleArgumentTerm(e.argumentTerm(t)),e.styleArgumentDescription(e.argumentDescription(t))));r=r.concat(this.formatItemList("Arguments:",a,e));const h=this.groupItems(t.options,e.visibleOptions(t),t=>t.helpGroupHeading??"Options:");if(h.forEach((t,n)=>{const i=t.map(t=>o(e.styleOptionTerm(e.optionTerm(t)),e.styleOptionDescription(e.optionDescription(t))));r=r.concat(this.formatItemList(n,i,e))}),e.showGlobalOptions){const n=e.visibleGlobalOptions(t).map(t=>o(e.styleOptionTerm(e.optionTerm(t)),e.styleOptionDescription(e.optionDescription(t))));r=r.concat(this.formatItemList("Global Options:",n,e))}return this.groupItems(t.commands,e.visibleCommands(t),t=>t.helpGroup()||"Commands:").forEach((t,n)=>{const i=t.map(t=>o(e.styleSubcommandTerm(e.subcommandTerm(t)),e.styleSubcommandDescription(e.subcommandDescription(t))));r=r.concat(this.formatItemList(n,i,e))}),r.join("\n")}displayWidth(t){return e(t).length}styleTitle(t){return t}styleUsage(t){return t.split(" ").map(t=>"[options]"===t?this.styleOptionText(t):"[command]"===t?this.styleSubcommandText(t):"["===t[0]||"<"===t[0]?this.styleArgumentText(t):this.styleCommandText(t)).join(" ")}styleCommandDescription(t){return this.styleDescriptionText(t)}styleOptionDescription(t){return this.styleDescriptionText(t)}styleSubcommandDescription(t){return this.styleDescriptionText(t)}styleArgumentDescription(t){return this.styleDescriptionText(t)}styleDescriptionText(t){return t}styleOptionTerm(t){return this.styleOptionText(t)}styleSubcommandTerm(t){return t.split(" ").map(t=>"[options]"===t?this.styleOptionText(t):"["===t[0]||"<"===t[0]?this.styleArgumentText(t):this.styleSubcommandText(t)).join(" ")}styleArgumentTerm(t){return this.styleArgumentText(t)}styleOptionText(t){return t}styleArgumentText(t){return t}styleSubcommandText(t){return t}styleCommandText(t){return t}padWidth(t,e){return Math.max(e.longestOptionTermLength(t,e),e.longestGlobalOptionTermLength(t,e),e.longestSubcommandTermLength(t,e),e.longestArgumentTermLength(t,e))}preformatted(t){return/\n[^\S\r\n]/.test(t)}formatItem(t,e,n,i){const o=" ".repeat(2);if(!n)return o+t;const r=t.padEnd(e+t.length-i.displayWidth(t)),s=(this.helpWidth??80)-e-2-2;let a;return a=s<this.minWidthToWrap||i.preformatted(n)?n:i.boxWrap(n,s).replace(/\n/g,"\n"+" ".repeat(e+2)),o+r+" ".repeat(2)+a.replace(/\n/g,`\n${o}`)}boxWrap(t,e){if(e<this.minWidthToWrap)return t;const n=t.split(/\r\n|\n/),i=/[\s]*[^\s]+/g,o=[];return n.forEach(t=>{const n=t.match(i);if(null===n)return void o.push("");let r=[n.shift()],s=this.displayWidth(r[0]);n.forEach(t=>{const n=this.displayWidth(t);if(s+n<=e)return r.push(t),void(s+=n);o.push(r.join(""));const i=t.trimStart();r=[i],s=this.displayWidth(i)}),o.push(r.join(""))}),o.join("\n")}},f.stripColor=e,f}var O,v={};function A(){if(O)return v;O=1;const{InvalidArgumentError:t}=p();function e(t){return t.split("-").reduce((t,e)=>t+e[0].toUpperCase()+e.slice(1))}return v.Option=class{constructor(t,e){this.flags=t,this.description=e||"",this.required=t.includes("<"),this.optional=t.includes("["),this.variadic=/\w\.\.\.[>\]]$/.test(t),this.mandatory=!1;const n=function(t){let e,n;const i=/^-[^-]$/,o=/^--[^-]/,r=t.split(/[ |,]+/).concat("guard");if(i.test(r[0])&&(e=r.shift()),o.test(r[0])&&(n=r.shift()),!e&&i.test(r[0])&&(e=r.shift()),!e&&o.test(r[0])&&(e=n,n=r.shift()),r[0].startsWith("-")){const e=r[0],n=`option creation failed due to '${e}' in option flags '${t}'`;if(/^-[^-][^-]/.test(e))throw new Error(`${n}\n- a short flag is a single dash and a single character\n - either use a single dash and a single character (for a short flag)\n - or use a double dash for a long option (and can have two, like '--ws, --workspace')`);if(i.test(e))throw new Error(`${n}\n- too many short flags`);if(o.test(e))throw new Error(`${n}\n- too many long flags`);throw new Error(`${n}\n- unrecognised flag format`)}if(void 0===e&&void 0===n)throw new Error(`option creation failed due to no flags found in '${t}'.`);return{shortFlag:e,longFlag:n}}(t);this.short=n.shortFlag,this.long=n.longFlag,this.negate=!1,this.long&&(this.negate=this.long.startsWith("--no-")),this.defaultValue=void 0,this.defaultValueDescription=void 0,this.presetArg=void 0,this.envVar=void 0,this.parseArg=void 0,this.hidden=!1,this.argChoices=void 0,this.conflictsWith=[],this.implied=void 0,this.helpGroupHeading=void 0}default(t,e){return this.defaultValue=t,this.defaultValueDescription=e,this}preset(t){return this.presetArg=t,this}conflicts(t){return this.conflictsWith=this.conflictsWith.concat(t),this}implies(t){let e=t;return"string"==typeof t&&(e={[t]:!0}),this.implied=Object.assign(this.implied||{},e),this}env(t){return this.envVar=t,this}argParser(t){return this.parseArg=t,this}makeOptionMandatory(t=!0){return this.mandatory=!!t,this}hideHelp(t=!0){return this.hidden=!!t,this}_collectValue(t,e){return e!==this.defaultValue&&Array.isArray(e)?(e.push(t),e):[t]}choices(e){return this.argChoices=e.slice(),this.parseArg=(e,n)=>{if(!this.argChoices.includes(e))throw new t(`Allowed choices are ${this.argChoices.join(", ")}.`);return this.variadic?this._collectValue(e,n):e},this}name(){return this.long?this.long.replace(/^--/,""):this.short.replace(/^-/,"")}attributeName(){return this.negate?e(this.name().replace(/^no-/,"")):e(this.name())}helpGroup(t){return this.helpGroupHeading=t,this}is(t){return this.short===t||this.long===t}isBoolean(){return!this.required&&!this.optional&&!this.negate}},v.DualOptions=class{constructor(t){this.positiveOptions=new Map,this.negativeOptions=new Map,this.dualOptions=new Set,t.forEach(t=>{t.negate?this.negativeOptions.set(t.attributeName(),t):this.positiveOptions.set(t.attributeName(),t)}),this.negativeOptions.forEach((t,e)=>{this.positiveOptions.has(e)&&this.dualOptions.add(e)})}valueFromOption(t,e){const n=e.attributeName();if(!this.dualOptions.has(n))return!0;const i=this.negativeOptions.get(n).presetArg,o=void 0!==i&&i;return e.negate===(o===t)}},v}var C,b,w,y={};function E(){return C||(C=1,y.suggestSimilar=function(t,e){if(!e||0===e.length)return"";e=Array.from(new Set(e));const n=t.startsWith("--");n&&(t=t.slice(2),e=e.map(t=>t.slice(2)));let i=[],o=3;return e.forEach(e=>{if(e.length<=1)return;const n=function(t,e){if(Math.abs(t.length-e.length)>3)return Math.max(t.length,e.length);const n=[];for(let e=0;e<=t.length;e++)n[e]=[e];for(let t=0;t<=e.length;t++)n[0][t]=t;for(let i=1;i<=e.length;i++)for(let o=1;o<=t.length;o++){let r=1;r=t[o-1]===e[i-1]?0:1,n[o][i]=Math.min(n[o-1][i]+1,n[o][i-1]+1,n[o-1][i-1]+r),o>1&&i>1&&t[o-1]===e[i-2]&&t[o-2]===e[i-1]&&(n[o][i]=Math.min(n[o][i],n[o-2][i-2]+1))}return n[t.length][e.length]}(t,e),r=Math.max(t.length,e.length);(r-n)/r>.4&&(n<o?(o=n,i=[e]):n===o&&i.push(e))}),i.sort((t,e)=>t.localeCompare(e)),n&&(i=i.map(t=>`--${t}`)),i.length>1?`\n(Did you mean one of ${i.join(", ")}?)`:1===i.length?`\n(Did you mean ${i[0]}?)`:""}),y}var $=function(){if(w)return l;w=1;const{Argument:r}=d(),{Command:s}=function(){if(b)return g;b=1;const r=t.EventEmitter,s=e,a=n,h=i,l=o,{Argument:u,humanReadableArgName:c}=d(),{CommanderError:m}=p(),{Help:f,stripColor:O}=_(),{Option:v,DualOptions:C}=A(),{suggestSimilar:w}=E();class y extends r{constructor(t){super(),this.commands=[],this.options=[],this.parent=null,this._allowUnknownOption=!1,this._allowExcessArguments=!1,this.registeredArguments=[],this._args=this.registeredArguments,this.args=[],this.rawArgs=[],this.processedArgs=[],this._scriptPath=null,this._name=t||"",this._optionValues={},this._optionValueSources={},this._storeOptionsAsProperties=!1,this._actionHandler=null,this._executableHandler=!1,this._executableFile=null,this._executableDir=null,this._defaultCommandName=null,this._exitCallback=null,this._aliases=[],this._combineFlagAndOptionalValue=!0,this._description="",this._summary="",this._argsDescription=void 0,this._enablePositionalOptions=!1,this._passThroughOptions=!1,this._lifeCycleHooks={},this._showHelpAfterError=!1,this._showSuggestionAfterError=!0,this._savedState=null,this._outputConfiguration={writeOut:t=>l.stdout.write(t),writeErr:t=>l.stderr.write(t),outputError:(t,e)=>e(t),getOutHelpWidth:()=>l.stdout.isTTY?l.stdout.columns:void 0,getErrHelpWidth:()=>l.stderr.isTTY?l.stderr.columns:void 0,getOutHasColors:()=>x()??(l.stdout.isTTY&&l.stdout.hasColors?.()),getErrHasColors:()=>x()??(l.stderr.isTTY&&l.stderr.hasColors?.()),stripColor:t=>O(t)},this._hidden=!1,this._helpOption=void 0,this._addImplicitHelpCommand=void 0,this._helpCommand=void 0,this._helpConfiguration={},this._helpGroupHeading=void 0,this._defaultCommandGroup=void 0,this._defaultOptionGroup=void 0}copyInheritedSettings(t){return this._outputConfiguration=t._outputConfiguration,this._helpOption=t._helpOption,this._helpCommand=t._helpCommand,this._helpConfiguration=t._helpConfiguration,this._exitCallback=t._exitCallback,this._storeOptionsAsProperties=t._storeOptionsAsProperties,this._combineFlagAndOptionalValue=t._combineFlagAndOptionalValue,this._allowExcessArguments=t._allowExcessArguments,this._enablePositionalOptions=t._enablePositionalOptions,this._showHelpAfterError=t._showHelpAfterError,this._showSuggestionAfterError=t._showSuggestionAfterError,this}_getCommandAndAncestors(){const t=[];for(let e=this;e;e=e.parent)t.push(e);return t}command(t,e,n){let i=e,o=n;"object"==typeof i&&null!==i&&(o=i,i=null),o=o||{};const[,r,s]=t.match(/([^ ]+) *(.*)/),a=this.createCommand(r);return i&&(a.description(i),a._executableHandler=!0),o.isDefault&&(this._defaultCommandName=a._name),a._hidden=!(!o.noHelp&&!o.hidden),a._executableFile=o.executableFile||null,s&&a.arguments(s),this._registerCommand(a),a.parent=this,a.copyInheritedSettings(this),i?this:a}createCommand(t){return new y(t)}createHelp(){return Object.assign(new f,this.configureHelp())}configureHelp(t){return void 0===t?this._helpConfiguration:(this._helpConfiguration=t,this)}configureOutput(t){return void 0===t?this._outputConfiguration:(this._outputConfiguration={...this._outputConfiguration,...t},this)}showHelpAfterError(t=!0){return"string"!=typeof t&&(t=!!t),this._showHelpAfterError=t,this}showSuggestionAfterError(t=!0){return this._showSuggestionAfterError=!!t,this}addCommand(t,e){if(!t._name)throw new Error("Command passed to .addCommand() must have a name\n- specify the name in Command constructor or using .name()");return(e=e||{}).isDefault&&(this._defaultCommandName=t._name),(e.noHelp||e.hidden)&&(t._hidden=!0),this._registerCommand(t),t.parent=this,t._checkForBrokenPassThrough(),this}createArgument(t,e){return new u(t,e)}argument(t,e,n,i){const o=this.createArgument(t,e);return"function"==typeof n?o.default(i).argParser(n):o.default(n),this.addArgument(o),this}arguments(t){return t.trim().split(/ +/).forEach(t=>{this.argument(t)}),this}addArgument(t){const e=this.registeredArguments.slice(-1)[0];if(e?.variadic)throw new Error(`only the last argument can be variadic '${e.name()}'`);if(t.required&&void 0!==t.defaultValue&&void 0===t.parseArg)throw new Error(`a default value for a required argument is never used: '${t.name()}'`);return this.registeredArguments.push(t),this}helpCommand(t,e){if("boolean"==typeof t)return this._addImplicitHelpCommand=t,t&&this._defaultCommandGroup&&this._initCommandGroup(this._getHelpCommand()),this;const n=t??"help [command]",[,i,o]=n.match(/([^ ]+) *(.*)/),r=e??"display help for command",s=this.createCommand(i);return s.helpOption(!1),o&&s.arguments(o),r&&s.description(r),this._addImplicitHelpCommand=!0,this._helpCommand=s,(t||e)&&this._initCommandGroup(s),this}addHelpCommand(t,e){return"object"!=typeof t?(this.helpCommand(t,e),this):(this._addImplicitHelpCommand=!0,this._helpCommand=t,this._initCommandGroup(t),this)}_getHelpCommand(){return this._addImplicitHelpCommand??(this.commands.length&&!this._actionHandler&&!this._findCommand("help"))?(void 0===this._helpCommand&&this.helpCommand(void 0,void 0),this._helpCommand):null}hook(t,e){const n=["preSubcommand","preAction","postAction"];if(!n.includes(t))throw new Error(`Unexpected value for event passed to hook : '${t}'.\nExpecting one of '${n.join("', '")}'`);return this._lifeCycleHooks[t]?this._lifeCycleHooks[t].push(e):this._lifeCycleHooks[t]=[e],this}exitOverride(t){return this._exitCallback=t||(t=>{if("commander.executeSubCommandAsync"!==t.code)throw t}),this}_exit(t,e,n){this._exitCallback&&this._exitCallback(new m(t,e,n)),l.exit(t)}action(t){return this._actionHandler=e=>{const n=this.registeredArguments.length,i=e.slice(0,n);return this._storeOptionsAsProperties?i[n]=this:i[n]=this.opts(),i.push(this),t.apply(this,i)},this}createOption(t,e){return new v(t,e)}_callParseArg(t,e,n,i){try{return t.parseArg(e,n)}catch(t){if("commander.invalidArgument"===t.code){const e=`${i} ${t.message}`;this.error(e,{exitCode:t.exitCode,code:t.code})}throw t}}_registerOption(t){const e=t.short&&this._findOption(t.short)||t.long&&this._findOption(t.long);if(e){const n=t.long&&this._findOption(t.long)?t.long:t.short;throw new Error(`Cannot add option '${t.flags}'${this._name&&` to command '${this._name}'`} due to conflicting flag '${n}'\n- already used by option '${e.flags}'`)}this._initOptionGroup(t),this.options.push(t)}_registerCommand(t){const e=t=>[t.name()].concat(t.aliases()),n=e(t).find(t=>this._findCommand(t));if(n){const i=e(this._findCommand(n)).join("|"),o=e(t).join("|");throw new Error(`cannot add command '${o}' as already have command '${i}'`)}this._initCommandGroup(t),this.commands.push(t)}addOption(t){this._registerOption(t);const e=t.name(),n=t.attributeName();if(t.negate){const e=t.long.replace(/^--no-/,"--");this._findOption(e)||this.setOptionValueWithSource(n,void 0===t.defaultValue||t.defaultValue,"default")}else void 0!==t.defaultValue&&this.setOptionValueWithSource(n,t.defaultValue,"default");const i=(e,i,o)=>{null==e&&void 0!==t.presetArg&&(e=t.presetArg);const r=this.getOptionValue(n);null!==e&&t.parseArg?e=this._callParseArg(t,e,r,i):null!==e&&t.variadic&&(e=t._collectValue(e,r)),null==e&&(e=!t.negate&&(!(!t.isBoolean()&&!t.optional)||"")),this.setOptionValueWithSource(n,e,o)};return this.on("option:"+e,e=>{const n=`error: option '${t.flags}' argument '${e}' is invalid.`;i(e,n,"cli")}),t.envVar&&this.on("optionEnv:"+e,e=>{const n=`error: option '${t.flags}' value '${e}' from env '${t.envVar}' is invalid.`;i(e,n,"env")}),this}_optionEx(t,e,n,i,o){if("object"==typeof e&&e instanceof v)throw new Error("To add an Option object use addOption() instead of option() or requiredOption()");const r=this.createOption(e,n);if(r.makeOptionMandatory(!!t.mandatory),"function"==typeof i)r.default(o).argParser(i);else if(i instanceof RegExp){const t=i;i=(e,n)=>{const i=t.exec(e);return i?i[0]:n},r.default(o).argParser(i)}else r.default(i);return this.addOption(r)}option(t,e,n,i){return this._optionEx({},t,e,n,i)}requiredOption(t,e,n,i){return this._optionEx({mandatory:!0},t,e,n,i)}combineFlagAndOptionalValue(t=!0){return this._combineFlagAndOptionalValue=!!t,this}allowUnknownOption(t=!0){return this._allowUnknownOption=!!t,this}allowExcessArguments(t=!0){return this._allowExcessArguments=!!t,this}enablePositionalOptions(t=!0){return this._enablePositionalOptions=!!t,this}passThroughOptions(t=!0){return this._passThroughOptions=!!t,this._checkForBrokenPassThrough(),this}_checkForBrokenPassThrough(){if(this.parent&&this._passThroughOptions&&!this.parent._enablePositionalOptions)throw new Error(`passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`)}storeOptionsAsProperties(t=!0){if(this.options.length)throw new Error("call .storeOptionsAsProperties() before adding options");if(Object.keys(this._optionValues).length)throw new Error("call .storeOptionsAsProperties() before setting option values");return this._storeOptionsAsProperties=!!t,this}getOptionValue(t){return this._storeOptionsAsProperties?this[t]:this._optionValues[t]}setOptionValue(t,e){return this.setOptionValueWithSource(t,e,void 0)}setOptionValueWithSource(t,e,n){return this._storeOptionsAsProperties?this[t]=e:this._optionValues[t]=e,this._optionValueSources[t]=n,this}getOptionValueSource(t){return this._optionValueSources[t]}getOptionValueSourceWithGlobals(t){let e;return this._getCommandAndAncestors().forEach(n=>{void 0!==n.getOptionValueSource(t)&&(e=n.getOptionValueSource(t))}),e}_prepareUserArgs(t,e){if(void 0!==t&&!Array.isArray(t))throw new Error("first parameter to parse must be array or undefined");if(e=e||{},void 0===t&&void 0===e.from){l.versions?.electron&&(e.from="electron");const t=l.execArgv??[];(t.includes("-e")||t.includes("--eval")||t.includes("-p")||t.includes("--print"))&&(e.from="eval")}let n;switch(void 0===t&&(t=l.argv),this.rawArgs=t.slice(),e.from){case void 0:case"node":this._scriptPath=t[1],n=t.slice(2);break;case"electron":l.defaultApp?(this._scriptPath=t[1],n=t.slice(2)):n=t.slice(1);break;case"user":n=t.slice(0);break;case"eval":n=t.slice(1);break;default:throw new Error(`unexpected parse option { from: '${e.from}' }`)}return!this._name&&this._scriptPath&&this.nameFromFilename(this._scriptPath),this._name=this._name||"program",n}parse(t,e){this._prepareForParse();const n=this._prepareUserArgs(t,e);return this._parseCommand([],n),this}async parseAsync(t,e){this._prepareForParse();const n=this._prepareUserArgs(t,e);return await this._parseCommand([],n),this}_prepareForParse(){null===this._savedState?this.saveStateBeforeParse():this.restoreStateBeforeParse()}saveStateBeforeParse(){this._savedState={_name:this._name,_optionValues:{...this._optionValues},_optionValueSources:{...this._optionValueSources}}}restoreStateBeforeParse(){if(this._storeOptionsAsProperties)throw new Error("Can not call parse again when storeOptionsAsProperties is true.\n- either make a new Command for each call to parse, or stop storing options as properties");this._name=this._savedState._name,this._scriptPath=null,this.rawArgs=[],this._optionValues={...this._savedState._optionValues},this._optionValueSources={...this._savedState._optionValueSources},this.args=[],this.processedArgs=[]}_checkForMissingExecutable(t,e,n){if(!h.existsSync(t))throw new Error(`'${t}' does not exist\n - if '${n}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead\n - if the default executable name is not suitable, use the executableFile option to supply a custom name or path\n - ${e?`searched for local subcommand relative to directory '${e}'`:"no directory for search for local subcommand, use .executableDir() to supply a custom directory"}`)}_executeSubCommand(t,e){e=e.slice();let n=!1;const i=[".js",".ts",".tsx",".mjs",".cjs"];function o(t,e){const n=a.resolve(t,e);if(h.existsSync(n))return n;if(i.includes(a.extname(e)))return;const o=i.find(t=>h.existsSync(`${n}${t}`));return o?`${n}${o}`:void 0}this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let r,u=t._executableFile||`${this._name}-${t._name}`,c=this._executableDir||"";if(this._scriptPath){let t;try{t=h.realpathSync(this._scriptPath)}catch{t=this._scriptPath}c=a.resolve(a.dirname(t),c)}if(c){let e=o(c,u);if(!e&&!t._executableFile&&this._scriptPath){const n=a.basename(this._scriptPath,a.extname(this._scriptPath));n!==this._name&&(e=o(c,`${n}-${t._name}`))}u=e||u}n=i.includes(a.extname(u)),"win32"!==l.platform?n?(e.unshift(u),e=$(l.execArgv).concat(e),r=s.spawn(l.argv[0],e,{stdio:"inherit"})):r=s.spawn(u,e,{stdio:"inherit"}):(this._checkForMissingExecutable(u,c,t._name),e.unshift(u),e=$(l.execArgv).concat(e),r=s.spawn(l.execPath,e,{stdio:"inherit"})),r.killed||["SIGUSR1","SIGUSR2","SIGTERM","SIGINT","SIGHUP"].forEach(t=>{l.on(t,()=>{!1===r.killed&&null===r.exitCode&&r.kill(t)})});const p=this._exitCallback;r.on("close",t=>{t=t??1,p?p(new m(t,"commander.executeSubCommandAsync","(close)")):l.exit(t)}),r.on("error",e=>{if("ENOENT"===e.code)this._checkForMissingExecutable(u,c,t._name);else if("EACCES"===e.code)throw new Error(`'${u}' not executable`);if(p){const t=new m(1,"commander.executeSubCommandAsync","(error)");t.nestedError=e,p(t)}else l.exit(1)}),this.runningCommand=r}_dispatchSubcommand(t,e,n){const i=this._findCommand(t);let o;return i||this.help({error:!0}),i._prepareForParse(),o=this._chainOrCallSubCommandHook(o,i,"preSubcommand"),o=this._chainOrCall(o,()=>{if(!i._executableHandler)return i._parseCommand(e,n);this._executeSubCommand(i,e.concat(n))}),o}_dispatchHelpCommand(t){t||this.help();const e=this._findCommand(t);return e&&!e._executableHandler&&e.help(),this._dispatchSubcommand(t,[],[this._getHelpOption()?.long??this._getHelpOption()?.short??"--help"])}_checkNumberOfArguments(){this.registeredArguments.forEach((t,e)=>{t.required&&null==this.args[e]&&this.missingArgument(t.name())}),this.registeredArguments.length>0&&this.registeredArguments[this.registeredArguments.length-1].variadic||this.args.length>this.registeredArguments.length&&this._excessArguments(this.args)}_processArguments(){const t=(t,e,n)=>{let i=e;if(null!==e&&t.parseArg){const o=`error: command-argument value '${e}' is invalid for argument '${t.name()}'.`;i=this._callParseArg(t,e,n,o)}return i};this._checkNumberOfArguments();const e=[];this.registeredArguments.forEach((n,i)=>{let o=n.defaultValue;n.variadic?i<this.args.length?(o=this.args.slice(i),n.parseArg&&(o=o.reduce((e,i)=>t(n,i,e),n.defaultValue))):void 0===o&&(o=[]):i<this.args.length&&(o=this.args[i],n.parseArg&&(o=t(n,o,n.defaultValue))),e[i]=o}),this.processedArgs=e}_chainOrCall(t,e){return t?.then&&"function"==typeof t.then?t.then(()=>e()):e()}_chainOrCallHooks(t,e){let n=t;const i=[];return this._getCommandAndAncestors().reverse().filter(t=>void 0!==t._lifeCycleHooks[e]).forEach(t=>{t._lifeCycleHooks[e].forEach(e=>{i.push({hookedCommand:t,callback:e})})}),"postAction"===e&&i.reverse(),i.forEach(t=>{n=this._chainOrCall(n,()=>t.callback(t.hookedCommand,this))}),n}_chainOrCallSubCommandHook(t,e,n){let i=t;return void 0!==this._lifeCycleHooks[n]&&this._lifeCycleHooks[n].forEach(t=>{i=this._chainOrCall(i,()=>t(this,e))}),i}_parseCommand(t,e){const n=this.parseOptions(e);if(this._parseOptionsEnv(),this._parseOptionsImplied(),t=t.concat(n.operands),e=n.unknown,this.args=t.concat(e),t&&this._findCommand(t[0]))return this._dispatchSubcommand(t[0],t.slice(1),e);if(this._getHelpCommand()&&t[0]===this._getHelpCommand().name())return this._dispatchHelpCommand(t[1]);if(this._defaultCommandName)return this._outputHelpIfRequested(e),this._dispatchSubcommand(this._defaultCommandName,t,e);!this.commands.length||0!==this.args.length||this._actionHandler||this._defaultCommandName||this.help({error:!0}),this._outputHelpIfRequested(n.unknown),this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();const i=()=>{n.unknown.length>0&&this.unknownOption(n.unknown[0])},o=`command:${this.name()}`;if(this._actionHandler){let n;return i(),this._processArguments(),n=this._chainOrCallHooks(n,"preAction"),n=this._chainOrCall(n,()=>this._actionHandler(this.processedArgs)),this.parent&&(n=this._chainOrCall(n,()=>{this.parent.emit(o,t,e)})),n=this._chainOrCallHooks(n,"postAction"),n}if(this.parent?.listenerCount(o))i(),this._processArguments(),this.parent.emit(o,t,e);else if(t.length){if(this._findCommand("*"))return this._dispatchSubcommand("*",t,e);this.listenerCount("command:*")?this.emit("command:*",t,e):this.commands.length?this.unknownCommand():(i(),this._processArguments())}else this.commands.length?(i(),this.help({error:!0})):(i(),this._processArguments())}_findCommand(t){if(t)return this.commands.find(e=>e._name===t||e._aliases.includes(t))}_findOption(t){return this.options.find(e=>e.is(t))}_checkForMissingMandatoryOptions(){this._getCommandAndAncestors().forEach(t=>{t.options.forEach(e=>{e.mandatory&&void 0===t.getOptionValue(e.attributeName())&&t.missingMandatoryOptionValue(e)})})}_checkForConflictingLocalOptions(){const t=this.options.filter(t=>{const e=t.attributeName();return void 0!==this.getOptionValue(e)&&"default"!==this.getOptionValueSource(e)}),e=t.filter(t=>t.conflictsWith.length>0);e.forEach(e=>{const n=t.find(t=>e.conflictsWith.includes(t.attributeName()));n&&this._conflictingOption(e,n)})}_checkForConflictingOptions(){this._getCommandAndAncestors().forEach(t=>{t._checkForConflictingLocalOptions()})}parseOptions(t){const e=[],n=[];let i=e;function o(t){return t.length>1&&"-"===t[0]}const r=t=>!!/^-(\d+|\d*\.\d+)(e[+-]?\d+)?$/.test(t)&&!this._getCommandAndAncestors().some(t=>t.options.map(t=>t.short).some(t=>/^-\d$/.test(t)));let s=null,a=null,h=0;for(;h<t.length||a;){const l=a??t[h++];if(a=null,"--"===l){i===n&&i.push(l),i.push(...t.slice(h));break}if(!s||o(l)&&!r(l)){if(s=null,o(l)){const e=this._findOption(l);if(e){if(e.required){const n=t[h++];void 0===n&&this.optionMissingArgument(e),this.emit(`option:${e.name()}`,n)}else if(e.optional){let n=null;h<t.length&&(!o(t[h])||r(t[h]))&&(n=t[h++]),this.emit(`option:${e.name()}`,n)}else this.emit(`option:${e.name()}`);s=e.variadic?e:null;continue}}if(l.length>2&&"-"===l[0]&&"-"!==l[1]){const t=this._findOption(`-${l[1]}`);if(t){t.required||t.optional&&this._combineFlagAndOptionalValue?this.emit(`option:${t.name()}`,l.slice(2)):(this.emit(`option:${t.name()}`),a=`-${l.slice(2)}`);continue}}if(/^--[^=]+=/.test(l)){const t=l.indexOf("="),e=this._findOption(l.slice(0,t));if(e&&(e.required||e.optional)){this.emit(`option:${e.name()}`,l.slice(t+1));continue}}if(i!==e||!o(l)||0===this.commands.length&&r(l)||(i=n),(this._enablePositionalOptions||this._passThroughOptions)&&0===e.length&&0===n.length){if(this._findCommand(l)){e.push(l),n.push(...t.slice(h));break}if(this._getHelpCommand()&&l===this._getHelpCommand().name()){e.push(l,...t.slice(h));break}if(this._defaultCommandName){n.push(l,...t.slice(h));break}}if(this._passThroughOptions){i.push(l,...t.slice(h));break}i.push(l)}else this.emit(`option:${s.name()}`,l)}return{operands:e,unknown:n}}opts(){if(this._storeOptionsAsProperties){const t={},e=this.options.length;for(let n=0;n<e;n++){const e=this.options[n].attributeName();t[e]=e===this._versionOptionName?this._version:this[e]}return t}return this._optionValues}optsWithGlobals(){return this._getCommandAndAncestors().reduce((t,e)=>Object.assign(t,e.opts()),{})}error(t,e){this._outputConfiguration.outputError(`${t}\n`,this._outputConfiguration.writeErr),"string"==typeof this._showHelpAfterError?this._outputConfiguration.writeErr(`${this._showHelpAfterError}\n`):this._showHelpAfterError&&(this._outputConfiguration.writeErr("\n"),this.outputHelp({error:!0}));const n=e||{},i=n.exitCode||1,o=n.code||"commander.error";this._exit(i,o,t)}_parseOptionsEnv(){this.options.forEach(t=>{if(t.envVar&&t.envVar in l.env){const e=t.attributeName();(void 0===this.getOptionValue(e)||["default","config","env"].includes(this.getOptionValueSource(e)))&&(t.required||t.optional?this.emit(`optionEnv:${t.name()}`,l.env[t.envVar]):this.emit(`optionEnv:${t.name()}`))}})}_parseOptionsImplied(){const t=new C(this.options),e=t=>void 0!==this.getOptionValue(t)&&!["default","implied"].includes(this.getOptionValueSource(t));this.options.filter(n=>void 0!==n.implied&&e(n.attributeName())&&t.valueFromOption(this.getOptionValue(n.attributeName()),n)).forEach(t=>{Object.keys(t.implied).filter(t=>!e(t)).forEach(e=>{this.setOptionValueWithSource(e,t.implied[e],"implied")})})}missingArgument(t){const e=`error: missing required argument '${t}'`;this.error(e,{code:"commander.missingArgument"})}optionMissingArgument(t){const e=`error: option '${t.flags}' argument missing`;this.error(e,{code:"commander.optionMissingArgument"})}missingMandatoryOptionValue(t){const e=`error: required option '${t.flags}' not specified`;this.error(e,{code:"commander.missingMandatoryOptionValue"})}_conflictingOption(t,e){const n=t=>{const e=t.attributeName(),n=this.getOptionValue(e),i=this.options.find(t=>t.negate&&e===t.attributeName()),o=this.options.find(t=>!t.negate&&e===t.attributeName());return i&&(void 0===i.presetArg&&!1===n||void 0!==i.presetArg&&n===i.presetArg)?i:o||t},i=t=>{const e=n(t),i=e.attributeName();return"env"===this.getOptionValueSource(i)?`environment variable '${e.envVar}'`:`option '${e.flags}'`},o=`error: ${i(t)} cannot be used with ${i(e)}`;this.error(o,{code:"commander.conflictingOption"})}unknownOption(t){if(this._allowUnknownOption)return;let e="";if(t.startsWith("--")&&this._showSuggestionAfterError){let n=[],i=this;do{const t=i.createHelp().visibleOptions(i).filter(t=>t.long).map(t=>t.long);n=n.concat(t),i=i.parent}while(i&&!i._enablePositionalOptions);e=w(t,n)}const n=`error: unknown option '${t}'${e}`;this.error(n,{code:"commander.unknownOption"})}_excessArguments(t){if(this._allowExcessArguments)return;const e=this.registeredArguments.length,n=1===e?"":"s",i=`error: too many arguments${this.parent?` for '${this.name()}'`:""}. Expected ${e} argument${n} but got ${t.length}.`;this.error(i,{code:"commander.excessArguments"})}unknownCommand(){const t=this.args[0];let e="";if(this._showSuggestionAfterError){const n=[];this.createHelp().visibleCommands(this).forEach(t=>{n.push(t.name()),t.alias()&&n.push(t.alias())}),e=w(t,n)}const n=`error: unknown command '${t}'${e}`;this.error(n,{code:"commander.unknownCommand"})}version(t,e,n){if(void 0===t)return this._version;this._version=t,e=e||"-V, --version",n=n||"output the version number";const i=this.createOption(e,n);return this._versionOptionName=i.attributeName(),this._registerOption(i),this.on("option:"+i.name(),()=>{this._outputConfiguration.writeOut(`${t}\n`),this._exit(0,"commander.version",t)}),this}description(t,e){return void 0===t&&void 0===e?this._description:(this._description=t,e&&(this._argsDescription=e),this)}summary(t){return void 0===t?this._summary:(this._summary=t,this)}alias(t){if(void 0===t)return this._aliases[0];let e=this;if(0!==this.commands.length&&this.commands[this.commands.length-1]._executableHandler&&(e=this.commands[this.commands.length-1]),t===e._name)throw new Error("Command alias can't be the same as its name");const n=this.parent?._findCommand(t);if(n){const e=[n.name()].concat(n.aliases()).join("|");throw new Error(`cannot add alias '${t}' to command '${this.name()}' as already have command '${e}'`)}return e._aliases.push(t),this}aliases(t){return void 0===t?this._aliases:(t.forEach(t=>this.alias(t)),this)}usage(t){if(void 0===t){if(this._usage)return this._usage;const t=this.registeredArguments.map(t=>c(t));return[].concat(this.options.length||null!==this._helpOption?"[options]":[],this.commands.length?"[command]":[],this.registeredArguments.length?t:[]).join(" ")}return this._usage=t,this}name(t){return void 0===t?this._name:(this._name=t,this)}helpGroup(t){return void 0===t?this._helpGroupHeading??"":(this._helpGroupHeading=t,this)}commandsGroup(t){return void 0===t?this._defaultCommandGroup??"":(this._defaultCommandGroup=t,this)}optionsGroup(t){return void 0===t?this._defaultOptionGroup??"":(this._defaultOptionGroup=t,this)}_initOptionGroup(t){this._defaultOptionGroup&&!t.helpGroupHeading&&t.helpGroup(this._defaultOptionGroup)}_initCommandGroup(t){this._defaultCommandGroup&&!t.helpGroup()&&t.helpGroup(this._defaultCommandGroup)}nameFromFilename(t){return this._name=a.basename(t,a.extname(t)),this}executableDir(t){return void 0===t?this._executableDir:(this._executableDir=t,this)}helpInformation(t){const e=this.createHelp(),n=this._getOutputContext(t);e.prepareContext({error:n.error,helpWidth:n.helpWidth,outputHasColors:n.hasColors});const i=e.formatHelp(this,e);return n.hasColors?i:this._outputConfiguration.stripColor(i)}_getOutputContext(t){const e=!!(t=t||{}).error;let n,i,o;return e?(n=t=>this._outputConfiguration.writeErr(t),i=this._outputConfiguration.getErrHasColors(),o=this._outputConfiguration.getErrHelpWidth()):(n=t=>this._outputConfiguration.writeOut(t),i=this._outputConfiguration.getOutHasColors(),o=this._outputConfiguration.getOutHelpWidth()),{error:e,write:t=>(i||(t=this._outputConfiguration.stripColor(t)),n(t)),hasColors:i,helpWidth:o}}outputHelp(t){let e;"function"==typeof t&&(e=t,t=void 0);const n=this._getOutputContext(t),i={error:n.error,write:n.write,command:this};this._getCommandAndAncestors().reverse().forEach(t=>t.emit("beforeAllHelp",i)),this.emit("beforeHelp",i);let o=this.helpInformation({error:n.error});if(e&&(o=e(o),"string"!=typeof o&&!Buffer.isBuffer(o)))throw new Error("outputHelp callback must return a string or a Buffer");n.write(o),this._getHelpOption()?.long&&this.emit(this._getHelpOption().long),this.emit("afterHelp",i),this._getCommandAndAncestors().forEach(t=>t.emit("afterAllHelp",i))}helpOption(t,e){return"boolean"==typeof t?(t?(null===this._helpOption&&(this._helpOption=void 0),this._defaultOptionGroup&&this._initOptionGroup(this._getHelpOption())):this._helpOption=null,this):(this._helpOption=this.createOption(t??"-h, --help",e??"display help for command"),(t||e)&&this._initOptionGroup(this._helpOption),this)}_getHelpOption(){return void 0===this._helpOption&&this.helpOption(void 0,void 0),this._helpOption}addHelpOption(t){return this._helpOption=t,this._initOptionGroup(t),this}help(t){this.outputHelp(t);let e=Number(l.exitCode??0);0===e&&t&&"function"!=typeof t&&t.error&&(e=1),this._exit(e,"commander.help","(outputHelp)")}addHelpText(t,e){const n=["beforeAll","before","after","afterAll"];if(!n.includes(t))throw new Error(`Unexpected value for position to addHelpText.\nExpecting one of '${n.join("', '")}'`);const i=`${t}Help`;return this.on(i,t=>{let n;n="function"==typeof e?e({error:t.error,command:t.command}):e,n&&t.write(`${n}\n`)}),this}_outputHelpIfRequested(t){const e=this._getHelpOption();e&&t.find(t=>e.is(t))&&(this.outputHelp(),this._exit(0,"commander.helpDisplayed","(outputHelp)"))}}function $(t){return t.map(t=>{if(!t.startsWith("--inspect"))return t;let e,n,i="127.0.0.1",o="9229";return null!==(n=t.match(/^(--inspect(-brk)?)$/))?e=n[1]:null!==(n=t.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))?(e=n[1],/^\d+$/.test(n[3])?o=n[3]:i=n[3]):null!==(n=t.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))&&(e=n[1],i=n[3],o=n[4]),e&&"0"!==o?`${e}=${i}:${parseInt(o)+1}`:t})}function x(){return!l.env.NO_COLOR&&"0"!==l.env.FORCE_COLOR&&"false"!==l.env.FORCE_COLOR&&(!(!l.env.FORCE_COLOR&&void 0===l.env.CLICOLOR_FORCE)||void 0)}return g.Command=y,g.useColor=x,g}(),{CommanderError:a,InvalidArgumentError:h}=p(),{Help:u}=_(),{Option:c}=A();return l.program=new s,l.createCommand=t=>new s(t),l.createOption=(t,e)=>new c(t,e),l.createArgument=(t,e)=>new r(t,e),l.Command=s,l.Option=c,l.Argument=r,l.Help=u,l.CommanderError=a,l.InvalidArgumentError=h,l.InvalidOptionArgumentError=h,l}(),x=s($);const{program:k,createCommand:H,createArgument:S,createOption:T,CommanderError:V,InvalidArgumentError:D,InvalidOptionArgumentError:P,Command:N,Argument:F,Option:G,Help:W}=x,I=n.resolve(__dirname,".."),j=JSON.parse(i.readFileSync(n.join(I,"package.json"),"utf8")),M=process.env.TASK_HANDOFF_NPM_COMMAND||"npm",R=new Set(["stable","beta","alpha"]);function q(t,n,i={}){const o=e.spawnSync(t,n,{encoding:"utf8",...i});if(0!==o.status){const e=[o.stdout,o.stderr].filter(Boolean).join("\n").trim();throw new Error(`${t} ${n.join(" ")} failed${e?`:\n${e}`:""}`)}return String(o.stdout||"").trim()}function L(t){const e={};if(!i.existsSync(t))return e;for(const n of i.readFileSync(t,"utf8").split(/\r?\n/)){if(!n||n.startsWith("#"))continue;const t=n.indexOf("=");t>0&&(e[n.slice(0,t)]=n.slice(t+1))}return e}function U(){const t="/etc/systemd/system/task-handoff-node-agent.service";return i.existsSync(t)&&i.readFileSync(t,"utf8").match(/^User=(.+)$/m)?.[1]||"root"}function B(t){const n=e.spawnSync("systemctl",["is-active",t],{encoding:"utf8"});return String(n.stdout||"unknown").trim()||"unknown"}function K(t,e){if(!R.has(t))throw new Error("--channel must be stable, beta, or alpha.");if(e&&!/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/.test(e))throw new Error("--to must be an exact semantic version.");return e||("stable"===t?"latest":t)}function J(t,e){const n=["view",`@task-handoff/server@${t}`,"version","--json"];e&&n.push("--registry",e);const i=JSON.parse(q(M,n));if("string"!=typeof i)throw new Error(`npm target ${t} did not resolve to one version.`);return i}function Y(){if("function"==typeof process.getuid&&0!==process.getuid())throw new Error("Run this command as root so system packages and services can be changed.")}function z(t){return[["--service-user",t.serviceUser],["--control-plane-data-dir",t.controlPlaneDataDir],["--node-agent-data-dir",t.nodeAgentDataDir],["--control-plane-host",t.controlPlaneHost],["--control-plane-port",t.controlPlanePort],["--node-agent-host",t.nodeAgentHost],["--node-agent-port",t.nodeAgentPort],["--node-agent-ipc-path",t.nodeAgentIpcPath],["--auth-mode",t.authMode],["--static-dir",t.staticDir]].flatMap(([t,e])=>void 0===e?[]:[t,e])}(async function(){const t=(new N).name("task-handoff").description("Manage a TaskHandoff server and run its installed runtimes.").version(j.version).showSuggestionAfterError();t.command("control-plane","Run the installed control-plane runtime.",{executableFile:"task-handoff-control-plane"}),t.command("node-agent","Run the installed node-agent runtime.",{executableFile:"task-handoff-node-agent"}),t.command("controlled-instance","Run the installed controlled-instance runtime.",{executableFile:"task-handoff-controlled-instance"}),t.command("install").description("Install or regenerate the server systemd services.").option("--service-user <user>").option("--control-plane-data-dir <path>").option("--node-agent-data-dir <path>").option("--control-plane-host <host>").option("--control-plane-port <port>").option("--node-agent-host <host>").option("--node-agent-port <port>").option("--node-agent-ipc-path <path>").option("--auth-mode <mode>").option("--static-dir <path>").action(t=>{Y(),q(process.execPath,[n.join(I,"bin","task-handoff-install-server"),...z(t)],{stdio:"inherit"})}),t.command("status").description("Show the installed version and service state.").action(()=>{console.log(`Package: @task-handoff/server ${j.version}`),console.log(`Node agent: ${B("task-handoff-node-agent.service")}`),console.log(`Control plane: ${B("task-handoff-control-plane.service")}`)}),t.command("check").description("Check npm for an available server version.").option("--channel <channel>","stable, beta, or alpha","stable").option("--registry <url>").action(t=>{const e=K(t.channel),n=J(e,t.registry);console.log(`Installed: ${j.version}`),console.log(`Available (${t.channel} channel, npm ${e}): ${n}`),console.log(n===j.version?"Up to date.":`Update available: task-handoff update --to ${n}`)}),t.command("update").description("Update the server package set and restart services safely.").option("--channel <channel>","stable, beta, or alpha","stable").option("--to <version>").option("--registry <url>").option("--force").action(async t=>{if(Y(),t.to&&process.argv.includes("--channel"))throw new Error("Use either --channel or --to, not both.");const e=K(t.channel,t.to),o=e===j.version?j.version:J(e,t.registry);if(o===j.version&&!t.force)return void console.log(`@task-handoff/server ${j.version} is already installed.`);const s=function(){const t="/run/task-handoff-server-update.lock";try{i.mkdirSync(t)}catch(t){if("EEXIST"===t?.code)throw new Error("Another TaskHandoff server update is already running.");throw t}return()=>i.rmSync(t,{recursive:!0,force:!0})}();try{const e=function(){let t=I;for(;t!==n.dirname(t);){if("node_modules"===n.basename(t)&&"lib"===n.basename(n.dirname(t)))return n.dirname(n.dirname(t));t=n.dirname(t)}throw new Error(`Cannot determine the npm global prefix from ${I}.`)}(),s=function(){const t=L("/etc/task-handoff/control-plane.env"),e=L("/etc/task-handoff/node-agent.env");return["--service-user",U(),"--control-plane-data-dir",t.TASK_HANDOFF_CONTROL_PLANE_DATA_DIR||"/var/lib/task-handoff/control-plane","--node-agent-data-dir",e.TASK_HANDOFF_NODE_AGENT_DATA_DIR||"/var/lib/task-handoff/node-agent","--control-plane-host",t.TASK_HANDOFF_CONTROL_PLANE_HOST||"0.0.0.0","--control-plane-port",t.TASK_HANDOFF_CONTROL_PLANE_PORT||"8081","--node-agent-host",e.TASK_HANDOFF_NODE_AGENT_HOST||"127.0.0.1","--node-agent-port",e.TASK_HANDOFF_NODE_AGENT_PORT||"8091","--node-agent-ipc-path",e.TASK_HANDOFF_NODE_AGENT_IPC_PATH||"/run/task-handoff/node-agent.sock","--auth-mode",t.TASK_HANDOFF_CONTROL_PLANE_AUTH_MODE||"password"]}(),a=s[s.indexOf("--node-agent-ipc-path")+1],h=Number(s[s.indexOf("--control-plane-port")+1]),l=["install","--global","--prefix",e,`@task-handoff/server@${o}`];t.registry&&l.push("--registry",t.registry),console.log(`Updating @task-handoff/server ${j.version} -> ${o}`),q(M,l,{stdio:"inherit"}),q(n.join(e,"bin","task-handoff"),["install",...s],{stdio:"inherit"}),q("systemctl",["restart","task-handoff-node-agent.service"]),function(t,e=3e4){const n=Date.now()+e;for(;Date.now()<n;){try{if(i.statSync(t).isSocket())return}catch{}Atomics.wait(new Int32Array(new SharedArrayBuffer(4)),0,0,250)}throw new Error(`Node agent socket was not ready after ${e}ms: ${t}`)}(a),q("systemctl",["restart","task-handoff-control-plane.service"]),await function(t,e=3e4){return new Promise((n,i)=>{const o=Date.now()+e,s=()=>{const e=r.get({host:"127.0.0.1",port:t,path:"/api/health",timeout:1e3},t=>{if(t.resume(),200===t.statusCode)return n();a()});e.on("timeout",()=>e.destroy()),e.on("error",a)},a=()=>Date.now()>=o?i(new Error(`Control plane was not healthy on port ${t} after ${e}ms.`)):setTimeout(s,250);s()})}(h),console.log(`Updated TaskHandoff server to ${o}.`)}catch(t){throw console.error(`Update failed. To reinstall the previous version, run: npm install -g @task-handoff/server@${j.version}`),t}finally{s()}}),await t.parseAsync(process.argv)})().catch(t=>{console.error(`Error: ${t instanceof Error?t.message:String(t)}`),process.exitCode=1});
|
|
1
|
+
"use strict";var t=require("node:events"),e=require("node:child_process"),r=require("node:path"),n=require("node:fs"),i=require("node:process"),s=require("node:http");function o(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var a,l,h={},c={},u={};function p(){if(a)return u;a=1;class t extends Error{constructor(t,e,r){super(r),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name,this.code=e,this.exitCode=t,this.nestedError=void 0}}return u.CommanderError=t,u.InvalidArgumentError=class extends t{constructor(t){super(1,"commander.invalidArgument",t),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name}},u}function m(){if(l)return c;l=1;const{InvalidArgumentError:t}=p();return c.Argument=class{constructor(t,e){switch(this.description=e||"",this.variadic=!1,this.parseArg=void 0,this.defaultValue=void 0,this.defaultValueDescription=void 0,this.argChoices=void 0,t[0]){case"<":this.required=!0,this._name=t.slice(1,-1);break;case"[":this.required=!1,this._name=t.slice(1,-1);break;default:this.required=!0,this._name=t}this._name.endsWith("...")&&(this.variadic=!0,this._name=this._name.slice(0,-3))}name(){return this._name}_collectValue(t,e){return e!==this.defaultValue&&Array.isArray(e)?(e.push(t),e):[t]}default(t,e){return this.defaultValue=t,this.defaultValueDescription=e,this}argParser(t){return this.parseArg=t,this}choices(e){return this.argChoices=e.slice(),this.parseArg=(e,r)=>{if(!this.argChoices.includes(e))throw new t(`Allowed choices are ${this.argChoices.join(", ")}.`);return this.variadic?this._collectValue(e,r):e},this}argRequired(){return this.required=!0,this}argOptional(){return this.required=!1,this}},c.humanReadableArgName=function(t){const e=t.name()+(!0===t.variadic?"...":"");return t.required?"<"+e+">":"["+e+"]"},c}var d,f={},g={};function E(){if(d)return g;d=1;const{humanReadableArgName:t}=m();function e(t){return t.replace(/\x1b\[\d*(;\d*)*m/g,"")}return g.Help=class{constructor(){this.helpWidth=void 0,this.minWidthToWrap=40,this.sortSubcommands=!1,this.sortOptions=!1,this.showGlobalOptions=!1}prepareContext(t){this.helpWidth=this.helpWidth??t.helpWidth??80}visibleCommands(t){const e=t.commands.filter(t=>!t._hidden),r=t._getHelpCommand();return r&&!r._hidden&&e.push(r),this.sortSubcommands&&e.sort((t,e)=>t.name().localeCompare(e.name())),e}compareOptions(t,e){const r=t=>t.short?t.short.replace(/^-/,""):t.long.replace(/^--/,"");return r(t).localeCompare(r(e))}visibleOptions(t){const e=t.options.filter(t=>!t.hidden),r=t._getHelpOption();if(r&&!r.hidden){const n=r.short&&t._findOption(r.short),i=r.long&&t._findOption(r.long);n||i?r.long&&!i?e.push(t.createOption(r.long,r.description)):r.short&&!n&&e.push(t.createOption(r.short,r.description)):e.push(r)}return this.sortOptions&&e.sort(this.compareOptions),e}visibleGlobalOptions(t){if(!this.showGlobalOptions)return[];const e=[];for(let r=t.parent;r;r=r.parent){const t=r.options.filter(t=>!t.hidden);e.push(...t)}return this.sortOptions&&e.sort(this.compareOptions),e}visibleArguments(t){return t._argsDescription&&t.registeredArguments.forEach(e=>{e.description=e.description||t._argsDescription[e.name()]||""}),t.registeredArguments.find(t=>t.description)?t.registeredArguments:[]}subcommandTerm(e){const r=e.registeredArguments.map(e=>t(e)).join(" ");return e._name+(e._aliases[0]?"|"+e._aliases[0]:"")+(e.options.length?" [options]":"")+(r?" "+r:"")}optionTerm(t){return t.flags}argumentTerm(t){return t.name()}longestSubcommandTermLength(t,e){return e.visibleCommands(t).reduce((t,r)=>Math.max(t,this.displayWidth(e.styleSubcommandTerm(e.subcommandTerm(r)))),0)}longestOptionTermLength(t,e){return e.visibleOptions(t).reduce((t,r)=>Math.max(t,this.displayWidth(e.styleOptionTerm(e.optionTerm(r)))),0)}longestGlobalOptionTermLength(t,e){return e.visibleGlobalOptions(t).reduce((t,r)=>Math.max(t,this.displayWidth(e.styleOptionTerm(e.optionTerm(r)))),0)}longestArgumentTermLength(t,e){return e.visibleArguments(t).reduce((t,r)=>Math.max(t,this.displayWidth(e.styleArgumentTerm(e.argumentTerm(r)))),0)}commandUsage(t){let e=t._name;t._aliases[0]&&(e=e+"|"+t._aliases[0]);let r="";for(let e=t.parent;e;e=e.parent)r=e.name()+" "+r;return r+e+" "+t.usage()}commandDescription(t){return t.description()}subcommandDescription(t){return t.summary()||t.description()}optionDescription(t){const e=[];if(t.argChoices&&e.push(`choices: ${t.argChoices.map(t=>JSON.stringify(t)).join(", ")}`),void 0!==t.defaultValue&&(t.required||t.optional||t.isBoolean()&&"boolean"==typeof t.defaultValue)&&e.push(`default: ${t.defaultValueDescription||JSON.stringify(t.defaultValue)}`),void 0!==t.presetArg&&t.optional&&e.push(`preset: ${JSON.stringify(t.presetArg)}`),void 0!==t.envVar&&e.push(`env: ${t.envVar}`),e.length>0){const r=`(${e.join(", ")})`;return t.description?`${t.description} ${r}`:r}return t.description}argumentDescription(t){const e=[];if(t.argChoices&&e.push(`choices: ${t.argChoices.map(t=>JSON.stringify(t)).join(", ")}`),void 0!==t.defaultValue&&e.push(`default: ${t.defaultValueDescription||JSON.stringify(t.defaultValue)}`),e.length>0){const r=`(${e.join(", ")})`;return t.description?`${t.description} ${r}`:r}return t.description}formatItemList(t,e,r){return 0===e.length?[]:[r.styleTitle(t),...e,""]}groupItems(t,e,r){const n=new Map;return t.forEach(t=>{const e=r(t);n.has(e)||n.set(e,[])}),e.forEach(t=>{const e=r(t);n.has(e)||n.set(e,[]),n.get(e).push(t)}),n}formatHelp(t,e){const r=e.padWidth(t,e),n=e.helpWidth??80;function i(t,n){return e.formatItem(t,r,n,e)}let s=[`${e.styleTitle("Usage:")} ${e.styleUsage(e.commandUsage(t))}`,""];const o=e.commandDescription(t);o.length>0&&(s=s.concat([e.boxWrap(e.styleCommandDescription(o),n),""]));const a=e.visibleArguments(t).map(t=>i(e.styleArgumentTerm(e.argumentTerm(t)),e.styleArgumentDescription(e.argumentDescription(t))));s=s.concat(this.formatItemList("Arguments:",a,e));const l=this.groupItems(t.options,e.visibleOptions(t),t=>t.helpGroupHeading??"Options:");if(l.forEach((t,r)=>{const n=t.map(t=>i(e.styleOptionTerm(e.optionTerm(t)),e.styleOptionDescription(e.optionDescription(t))));s=s.concat(this.formatItemList(r,n,e))}),e.showGlobalOptions){const r=e.visibleGlobalOptions(t).map(t=>i(e.styleOptionTerm(e.optionTerm(t)),e.styleOptionDescription(e.optionDescription(t))));s=s.concat(this.formatItemList("Global Options:",r,e))}return this.groupItems(t.commands,e.visibleCommands(t),t=>t.helpGroup()||"Commands:").forEach((t,r)=>{const n=t.map(t=>i(e.styleSubcommandTerm(e.subcommandTerm(t)),e.styleSubcommandDescription(e.subcommandDescription(t))));s=s.concat(this.formatItemList(r,n,e))}),s.join("\n")}displayWidth(t){return e(t).length}styleTitle(t){return t}styleUsage(t){return t.split(" ").map(t=>"[options]"===t?this.styleOptionText(t):"[command]"===t?this.styleSubcommandText(t):"["===t[0]||"<"===t[0]?this.styleArgumentText(t):this.styleCommandText(t)).join(" ")}styleCommandDescription(t){return this.styleDescriptionText(t)}styleOptionDescription(t){return this.styleDescriptionText(t)}styleSubcommandDescription(t){return this.styleDescriptionText(t)}styleArgumentDescription(t){return this.styleDescriptionText(t)}styleDescriptionText(t){return t}styleOptionTerm(t){return this.styleOptionText(t)}styleSubcommandTerm(t){return t.split(" ").map(t=>"[options]"===t?this.styleOptionText(t):"["===t[0]||"<"===t[0]?this.styleArgumentText(t):this.styleSubcommandText(t)).join(" ")}styleArgumentTerm(t){return this.styleArgumentText(t)}styleOptionText(t){return t}styleArgumentText(t){return t}styleSubcommandText(t){return t}styleCommandText(t){return t}padWidth(t,e){return Math.max(e.longestOptionTermLength(t,e),e.longestGlobalOptionTermLength(t,e),e.longestSubcommandTermLength(t,e),e.longestArgumentTermLength(t,e))}preformatted(t){return/\n[^\S\r\n]/.test(t)}formatItem(t,e,r,n){const i=" ".repeat(2);if(!r)return i+t;const s=t.padEnd(e+t.length-n.displayWidth(t)),o=(this.helpWidth??80)-e-2-2;let a;return a=o<this.minWidthToWrap||n.preformatted(r)?r:n.boxWrap(r,o).replace(/\n/g,"\n"+" ".repeat(e+2)),i+s+" ".repeat(2)+a.replace(/\n/g,`\n${i}`)}boxWrap(t,e){if(e<this.minWidthToWrap)return t;const r=t.split(/\r\n|\n/),n=/[\s]*[^\s]+/g,i=[];return r.forEach(t=>{const r=t.match(n);if(null===r)return void i.push("");let s=[r.shift()],o=this.displayWidth(s[0]);r.forEach(t=>{const r=this.displayWidth(t);if(o+r<=e)return s.push(t),void(o+=r);i.push(s.join(""));const n=t.trimStart();s=[n],o=this.displayWidth(n)}),i.push(s.join(""))}),i.join("\n")}},g.stripColor=e,g}var _,v={};function O(){if(_)return v;_=1;const{InvalidArgumentError:t}=p();function e(t){return t.split("-").reduce((t,e)=>t+e[0].toUpperCase()+e.slice(1))}return v.Option=class{constructor(t,e){this.flags=t,this.description=e||"",this.required=t.includes("<"),this.optional=t.includes("["),this.variadic=/\w\.\.\.[>\]]$/.test(t),this.mandatory=!1;const r=function(t){let e,r;const n=/^-[^-]$/,i=/^--[^-]/,s=t.split(/[ |,]+/).concat("guard");if(n.test(s[0])&&(e=s.shift()),i.test(s[0])&&(r=s.shift()),!e&&n.test(s[0])&&(e=s.shift()),!e&&i.test(s[0])&&(e=r,r=s.shift()),s[0].startsWith("-")){const e=s[0],r=`option creation failed due to '${e}' in option flags '${t}'`;if(/^-[^-][^-]/.test(e))throw new Error(`${r}\n- a short flag is a single dash and a single character\n - either use a single dash and a single character (for a short flag)\n - or use a double dash for a long option (and can have two, like '--ws, --workspace')`);if(n.test(e))throw new Error(`${r}\n- too many short flags`);if(i.test(e))throw new Error(`${r}\n- too many long flags`);throw new Error(`${r}\n- unrecognised flag format`)}if(void 0===e&&void 0===r)throw new Error(`option creation failed due to no flags found in '${t}'.`);return{shortFlag:e,longFlag:r}}(t);this.short=r.shortFlag,this.long=r.longFlag,this.negate=!1,this.long&&(this.negate=this.long.startsWith("--no-")),this.defaultValue=void 0,this.defaultValueDescription=void 0,this.presetArg=void 0,this.envVar=void 0,this.parseArg=void 0,this.hidden=!1,this.argChoices=void 0,this.conflictsWith=[],this.implied=void 0,this.helpGroupHeading=void 0}default(t,e){return this.defaultValue=t,this.defaultValueDescription=e,this}preset(t){return this.presetArg=t,this}conflicts(t){return this.conflictsWith=this.conflictsWith.concat(t),this}implies(t){let e=t;return"string"==typeof t&&(e={[t]:!0}),this.implied=Object.assign(this.implied||{},e),this}env(t){return this.envVar=t,this}argParser(t){return this.parseArg=t,this}makeOptionMandatory(t=!0){return this.mandatory=!!t,this}hideHelp(t=!0){return this.hidden=!!t,this}_collectValue(t,e){return e!==this.defaultValue&&Array.isArray(e)?(e.push(t),e):[t]}choices(e){return this.argChoices=e.slice(),this.parseArg=(e,r)=>{if(!this.argChoices.includes(e))throw new t(`Allowed choices are ${this.argChoices.join(", ")}.`);return this.variadic?this._collectValue(e,r):e},this}name(){return this.long?this.long.replace(/^--/,""):this.short.replace(/^-/,"")}attributeName(){return this.negate?e(this.name().replace(/^no-/,"")):e(this.name())}helpGroup(t){return this.helpGroupHeading=t,this}is(t){return this.short===t||this.long===t}isBoolean(){return!this.required&&!this.optional&&!this.negate}},v.DualOptions=class{constructor(t){this.positiveOptions=new Map,this.negativeOptions=new Map,this.dualOptions=new Set,t.forEach(t=>{t.negate?this.negativeOptions.set(t.attributeName(),t):this.positiveOptions.set(t.attributeName(),t)}),this.negativeOptions.forEach((t,e)=>{this.positiveOptions.has(e)&&this.dualOptions.add(e)})}valueFromOption(t,e){const r=e.attributeName();if(!this.dualOptions.has(r))return!0;const n=this.negativeOptions.get(r).presetArg,i=void 0!==n&&n;return e.negate===(i===t)}},v}var A,$,C,w={};function b(){return A||(A=1,w.suggestSimilar=function(t,e){if(!e||0===e.length)return"";e=Array.from(new Set(e));const r=t.startsWith("--");r&&(t=t.slice(2),e=e.map(t=>t.slice(2)));let n=[],i=3;return e.forEach(e=>{if(e.length<=1)return;const r=function(t,e){if(Math.abs(t.length-e.length)>3)return Math.max(t.length,e.length);const r=[];for(let e=0;e<=t.length;e++)r[e]=[e];for(let t=0;t<=e.length;t++)r[0][t]=t;for(let n=1;n<=e.length;n++)for(let i=1;i<=t.length;i++){let s=1;s=t[i-1]===e[n-1]?0:1,r[i][n]=Math.min(r[i-1][n]+1,r[i][n-1]+1,r[i-1][n-1]+s),i>1&&n>1&&t[i-1]===e[n-2]&&t[i-2]===e[n-1]&&(r[i][n]=Math.min(r[i][n],r[i-2][n-2]+1))}return r[t.length][e.length]}(t,e),s=Math.max(t.length,e.length);(s-r)/s>.4&&(r<i?(i=r,n=[e]):r===i&&n.push(e))}),n.sort((t,e)=>t.localeCompare(e)),r&&(n=n.map(t=>`--${t}`)),n.length>1?`\n(Did you mean one of ${n.join(", ")}?)`:1===n.length?`\n(Did you mean ${n[0]}?)`:""}),w}var I=function(){if(C)return h;C=1;const{Argument:s}=m(),{Command:o}=function(){if($)return f;$=1;const s=t.EventEmitter,o=e,a=r,l=n,h=i,{Argument:c,humanReadableArgName:u}=m(),{CommanderError:d}=p(),{Help:g,stripColor:_}=E(),{Option:v,DualOptions:A}=O(),{suggestSimilar:C}=b();class w extends s{constructor(t){super(),this.commands=[],this.options=[],this.parent=null,this._allowUnknownOption=!1,this._allowExcessArguments=!1,this.registeredArguments=[],this._args=this.registeredArguments,this.args=[],this.rawArgs=[],this.processedArgs=[],this._scriptPath=null,this._name=t||"",this._optionValues={},this._optionValueSources={},this._storeOptionsAsProperties=!1,this._actionHandler=null,this._executableHandler=!1,this._executableFile=null,this._executableDir=null,this._defaultCommandName=null,this._exitCallback=null,this._aliases=[],this._combineFlagAndOptionalValue=!0,this._description="",this._summary="",this._argsDescription=void 0,this._enablePositionalOptions=!1,this._passThroughOptions=!1,this._lifeCycleHooks={},this._showHelpAfterError=!1,this._showSuggestionAfterError=!0,this._savedState=null,this._outputConfiguration={writeOut:t=>h.stdout.write(t),writeErr:t=>h.stderr.write(t),outputError:(t,e)=>e(t),getOutHelpWidth:()=>h.stdout.isTTY?h.stdout.columns:void 0,getErrHelpWidth:()=>h.stderr.isTTY?h.stderr.columns:void 0,getOutHasColors:()=>y()??(h.stdout.isTTY&&h.stdout.hasColors?.()),getErrHasColors:()=>y()??(h.stderr.isTTY&&h.stderr.hasColors?.()),stripColor:t=>_(t)},this._hidden=!1,this._helpOption=void 0,this._addImplicitHelpCommand=void 0,this._helpCommand=void 0,this._helpConfiguration={},this._helpGroupHeading=void 0,this._defaultCommandGroup=void 0,this._defaultOptionGroup=void 0}copyInheritedSettings(t){return this._outputConfiguration=t._outputConfiguration,this._helpOption=t._helpOption,this._helpCommand=t._helpCommand,this._helpConfiguration=t._helpConfiguration,this._exitCallback=t._exitCallback,this._storeOptionsAsProperties=t._storeOptionsAsProperties,this._combineFlagAndOptionalValue=t._combineFlagAndOptionalValue,this._allowExcessArguments=t._allowExcessArguments,this._enablePositionalOptions=t._enablePositionalOptions,this._showHelpAfterError=t._showHelpAfterError,this._showSuggestionAfterError=t._showSuggestionAfterError,this}_getCommandAndAncestors(){const t=[];for(let e=this;e;e=e.parent)t.push(e);return t}command(t,e,r){let n=e,i=r;"object"==typeof n&&null!==n&&(i=n,n=null),i=i||{};const[,s,o]=t.match(/([^ ]+) *(.*)/),a=this.createCommand(s);return n&&(a.description(n),a._executableHandler=!0),i.isDefault&&(this._defaultCommandName=a._name),a._hidden=!(!i.noHelp&&!i.hidden),a._executableFile=i.executableFile||null,o&&a.arguments(o),this._registerCommand(a),a.parent=this,a.copyInheritedSettings(this),n?this:a}createCommand(t){return new w(t)}createHelp(){return Object.assign(new g,this.configureHelp())}configureHelp(t){return void 0===t?this._helpConfiguration:(this._helpConfiguration=t,this)}configureOutput(t){return void 0===t?this._outputConfiguration:(this._outputConfiguration={...this._outputConfiguration,...t},this)}showHelpAfterError(t=!0){return"string"!=typeof t&&(t=!!t),this._showHelpAfterError=t,this}showSuggestionAfterError(t=!0){return this._showSuggestionAfterError=!!t,this}addCommand(t,e){if(!t._name)throw new Error("Command passed to .addCommand() must have a name\n- specify the name in Command constructor or using .name()");return(e=e||{}).isDefault&&(this._defaultCommandName=t._name),(e.noHelp||e.hidden)&&(t._hidden=!0),this._registerCommand(t),t.parent=this,t._checkForBrokenPassThrough(),this}createArgument(t,e){return new c(t,e)}argument(t,e,r,n){const i=this.createArgument(t,e);return"function"==typeof r?i.default(n).argParser(r):i.default(r),this.addArgument(i),this}arguments(t){return t.trim().split(/ +/).forEach(t=>{this.argument(t)}),this}addArgument(t){const e=this.registeredArguments.slice(-1)[0];if(e?.variadic)throw new Error(`only the last argument can be variadic '${e.name()}'`);if(t.required&&void 0!==t.defaultValue&&void 0===t.parseArg)throw new Error(`a default value for a required argument is never used: '${t.name()}'`);return this.registeredArguments.push(t),this}helpCommand(t,e){if("boolean"==typeof t)return this._addImplicitHelpCommand=t,t&&this._defaultCommandGroup&&this._initCommandGroup(this._getHelpCommand()),this;const r=t??"help [command]",[,n,i]=r.match(/([^ ]+) *(.*)/),s=e??"display help for command",o=this.createCommand(n);return o.helpOption(!1),i&&o.arguments(i),s&&o.description(s),this._addImplicitHelpCommand=!0,this._helpCommand=o,(t||e)&&this._initCommandGroup(o),this}addHelpCommand(t,e){return"object"!=typeof t?(this.helpCommand(t,e),this):(this._addImplicitHelpCommand=!0,this._helpCommand=t,this._initCommandGroup(t),this)}_getHelpCommand(){return this._addImplicitHelpCommand??(this.commands.length&&!this._actionHandler&&!this._findCommand("help"))?(void 0===this._helpCommand&&this.helpCommand(void 0,void 0),this._helpCommand):null}hook(t,e){const r=["preSubcommand","preAction","postAction"];if(!r.includes(t))throw new Error(`Unexpected value for event passed to hook : '${t}'.\nExpecting one of '${r.join("', '")}'`);return this._lifeCycleHooks[t]?this._lifeCycleHooks[t].push(e):this._lifeCycleHooks[t]=[e],this}exitOverride(t){return this._exitCallback=t||(t=>{if("commander.executeSubCommandAsync"!==t.code)throw t}),this}_exit(t,e,r){this._exitCallback&&this._exitCallback(new d(t,e,r)),h.exit(t)}action(t){return this._actionHandler=e=>{const r=this.registeredArguments.length,n=e.slice(0,r);return this._storeOptionsAsProperties?n[r]=this:n[r]=this.opts(),n.push(this),t.apply(this,n)},this}createOption(t,e){return new v(t,e)}_callParseArg(t,e,r,n){try{return t.parseArg(e,r)}catch(t){if("commander.invalidArgument"===t.code){const e=`${n} ${t.message}`;this.error(e,{exitCode:t.exitCode,code:t.code})}throw t}}_registerOption(t){const e=t.short&&this._findOption(t.short)||t.long&&this._findOption(t.long);if(e){const r=t.long&&this._findOption(t.long)?t.long:t.short;throw new Error(`Cannot add option '${t.flags}'${this._name&&` to command '${this._name}'`} due to conflicting flag '${r}'\n- already used by option '${e.flags}'`)}this._initOptionGroup(t),this.options.push(t)}_registerCommand(t){const e=t=>[t.name()].concat(t.aliases()),r=e(t).find(t=>this._findCommand(t));if(r){const n=e(this._findCommand(r)).join("|"),i=e(t).join("|");throw new Error(`cannot add command '${i}' as already have command '${n}'`)}this._initCommandGroup(t),this.commands.push(t)}addOption(t){this._registerOption(t);const e=t.name(),r=t.attributeName();if(t.negate){const e=t.long.replace(/^--no-/,"--");this._findOption(e)||this.setOptionValueWithSource(r,void 0===t.defaultValue||t.defaultValue,"default")}else void 0!==t.defaultValue&&this.setOptionValueWithSource(r,t.defaultValue,"default");const n=(e,n,i)=>{null==e&&void 0!==t.presetArg&&(e=t.presetArg);const s=this.getOptionValue(r);null!==e&&t.parseArg?e=this._callParseArg(t,e,s,n):null!==e&&t.variadic&&(e=t._collectValue(e,s)),null==e&&(e=!t.negate&&(!(!t.isBoolean()&&!t.optional)||"")),this.setOptionValueWithSource(r,e,i)};return this.on("option:"+e,e=>{const r=`error: option '${t.flags}' argument '${e}' is invalid.`;n(e,r,"cli")}),t.envVar&&this.on("optionEnv:"+e,e=>{const r=`error: option '${t.flags}' value '${e}' from env '${t.envVar}' is invalid.`;n(e,r,"env")}),this}_optionEx(t,e,r,n,i){if("object"==typeof e&&e instanceof v)throw new Error("To add an Option object use addOption() instead of option() or requiredOption()");const s=this.createOption(e,r);if(s.makeOptionMandatory(!!t.mandatory),"function"==typeof n)s.default(i).argParser(n);else if(n instanceof RegExp){const t=n;n=(e,r)=>{const n=t.exec(e);return n?n[0]:r},s.default(i).argParser(n)}else s.default(n);return this.addOption(s)}option(t,e,r,n){return this._optionEx({},t,e,r,n)}requiredOption(t,e,r,n){return this._optionEx({mandatory:!0},t,e,r,n)}combineFlagAndOptionalValue(t=!0){return this._combineFlagAndOptionalValue=!!t,this}allowUnknownOption(t=!0){return this._allowUnknownOption=!!t,this}allowExcessArguments(t=!0){return this._allowExcessArguments=!!t,this}enablePositionalOptions(t=!0){return this._enablePositionalOptions=!!t,this}passThroughOptions(t=!0){return this._passThroughOptions=!!t,this._checkForBrokenPassThrough(),this}_checkForBrokenPassThrough(){if(this.parent&&this._passThroughOptions&&!this.parent._enablePositionalOptions)throw new Error(`passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`)}storeOptionsAsProperties(t=!0){if(this.options.length)throw new Error("call .storeOptionsAsProperties() before adding options");if(Object.keys(this._optionValues).length)throw new Error("call .storeOptionsAsProperties() before setting option values");return this._storeOptionsAsProperties=!!t,this}getOptionValue(t){return this._storeOptionsAsProperties?this[t]:this._optionValues[t]}setOptionValue(t,e){return this.setOptionValueWithSource(t,e,void 0)}setOptionValueWithSource(t,e,r){return this._storeOptionsAsProperties?this[t]=e:this._optionValues[t]=e,this._optionValueSources[t]=r,this}getOptionValueSource(t){return this._optionValueSources[t]}getOptionValueSourceWithGlobals(t){let e;return this._getCommandAndAncestors().forEach(r=>{void 0!==r.getOptionValueSource(t)&&(e=r.getOptionValueSource(t))}),e}_prepareUserArgs(t,e){if(void 0!==t&&!Array.isArray(t))throw new Error("first parameter to parse must be array or undefined");if(e=e||{},void 0===t&&void 0===e.from){h.versions?.electron&&(e.from="electron");const t=h.execArgv??[];(t.includes("-e")||t.includes("--eval")||t.includes("-p")||t.includes("--print"))&&(e.from="eval")}let r;switch(void 0===t&&(t=h.argv),this.rawArgs=t.slice(),e.from){case void 0:case"node":this._scriptPath=t[1],r=t.slice(2);break;case"electron":h.defaultApp?(this._scriptPath=t[1],r=t.slice(2)):r=t.slice(1);break;case"user":r=t.slice(0);break;case"eval":r=t.slice(1);break;default:throw new Error(`unexpected parse option { from: '${e.from}' }`)}return!this._name&&this._scriptPath&&this.nameFromFilename(this._scriptPath),this._name=this._name||"program",r}parse(t,e){this._prepareForParse();const r=this._prepareUserArgs(t,e);return this._parseCommand([],r),this}async parseAsync(t,e){this._prepareForParse();const r=this._prepareUserArgs(t,e);return await this._parseCommand([],r),this}_prepareForParse(){null===this._savedState?this.saveStateBeforeParse():this.restoreStateBeforeParse()}saveStateBeforeParse(){this._savedState={_name:this._name,_optionValues:{...this._optionValues},_optionValueSources:{...this._optionValueSources}}}restoreStateBeforeParse(){if(this._storeOptionsAsProperties)throw new Error("Can not call parse again when storeOptionsAsProperties is true.\n- either make a new Command for each call to parse, or stop storing options as properties");this._name=this._savedState._name,this._scriptPath=null,this.rawArgs=[],this._optionValues={...this._savedState._optionValues},this._optionValueSources={...this._savedState._optionValueSources},this.args=[],this.processedArgs=[]}_checkForMissingExecutable(t,e,r){if(!l.existsSync(t))throw new Error(`'${t}' does not exist\n - if '${r}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead\n - if the default executable name is not suitable, use the executableFile option to supply a custom name or path\n - ${e?`searched for local subcommand relative to directory '${e}'`:"no directory for search for local subcommand, use .executableDir() to supply a custom directory"}`)}_executeSubCommand(t,e){e=e.slice();let r=!1;const n=[".js",".ts",".tsx",".mjs",".cjs"];function i(t,e){const r=a.resolve(t,e);if(l.existsSync(r))return r;if(n.includes(a.extname(e)))return;const i=n.find(t=>l.existsSync(`${r}${t}`));return i?`${r}${i}`:void 0}this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let s,c=t._executableFile||`${this._name}-${t._name}`,u=this._executableDir||"";if(this._scriptPath){let t;try{t=l.realpathSync(this._scriptPath)}catch{t=this._scriptPath}u=a.resolve(a.dirname(t),u)}if(u){let e=i(u,c);if(!e&&!t._executableFile&&this._scriptPath){const r=a.basename(this._scriptPath,a.extname(this._scriptPath));r!==this._name&&(e=i(u,`${r}-${t._name}`))}c=e||c}r=n.includes(a.extname(c)),"win32"!==h.platform?r?(e.unshift(c),e=I(h.execArgv).concat(e),s=o.spawn(h.argv[0],e,{stdio:"inherit"})):s=o.spawn(c,e,{stdio:"inherit"}):(this._checkForMissingExecutable(c,u,t._name),e.unshift(c),e=I(h.execArgv).concat(e),s=o.spawn(h.execPath,e,{stdio:"inherit"})),s.killed||["SIGUSR1","SIGUSR2","SIGTERM","SIGINT","SIGHUP"].forEach(t=>{h.on(t,()=>{!1===s.killed&&null===s.exitCode&&s.kill(t)})});const p=this._exitCallback;s.on("close",t=>{t=t??1,p?p(new d(t,"commander.executeSubCommandAsync","(close)")):h.exit(t)}),s.on("error",e=>{if("ENOENT"===e.code)this._checkForMissingExecutable(c,u,t._name);else if("EACCES"===e.code)throw new Error(`'${c}' not executable`);if(p){const t=new d(1,"commander.executeSubCommandAsync","(error)");t.nestedError=e,p(t)}else h.exit(1)}),this.runningCommand=s}_dispatchSubcommand(t,e,r){const n=this._findCommand(t);let i;return n||this.help({error:!0}),n._prepareForParse(),i=this._chainOrCallSubCommandHook(i,n,"preSubcommand"),i=this._chainOrCall(i,()=>{if(!n._executableHandler)return n._parseCommand(e,r);this._executeSubCommand(n,e.concat(r))}),i}_dispatchHelpCommand(t){t||this.help();const e=this._findCommand(t);return e&&!e._executableHandler&&e.help(),this._dispatchSubcommand(t,[],[this._getHelpOption()?.long??this._getHelpOption()?.short??"--help"])}_checkNumberOfArguments(){this.registeredArguments.forEach((t,e)=>{t.required&&null==this.args[e]&&this.missingArgument(t.name())}),this.registeredArguments.length>0&&this.registeredArguments[this.registeredArguments.length-1].variadic||this.args.length>this.registeredArguments.length&&this._excessArguments(this.args)}_processArguments(){const t=(t,e,r)=>{let n=e;if(null!==e&&t.parseArg){const i=`error: command-argument value '${e}' is invalid for argument '${t.name()}'.`;n=this._callParseArg(t,e,r,i)}return n};this._checkNumberOfArguments();const e=[];this.registeredArguments.forEach((r,n)=>{let i=r.defaultValue;r.variadic?n<this.args.length?(i=this.args.slice(n),r.parseArg&&(i=i.reduce((e,n)=>t(r,n,e),r.defaultValue))):void 0===i&&(i=[]):n<this.args.length&&(i=this.args[n],r.parseArg&&(i=t(r,i,r.defaultValue))),e[n]=i}),this.processedArgs=e}_chainOrCall(t,e){return t?.then&&"function"==typeof t.then?t.then(()=>e()):e()}_chainOrCallHooks(t,e){let r=t;const n=[];return this._getCommandAndAncestors().reverse().filter(t=>void 0!==t._lifeCycleHooks[e]).forEach(t=>{t._lifeCycleHooks[e].forEach(e=>{n.push({hookedCommand:t,callback:e})})}),"postAction"===e&&n.reverse(),n.forEach(t=>{r=this._chainOrCall(r,()=>t.callback(t.hookedCommand,this))}),r}_chainOrCallSubCommandHook(t,e,r){let n=t;return void 0!==this._lifeCycleHooks[r]&&this._lifeCycleHooks[r].forEach(t=>{n=this._chainOrCall(n,()=>t(this,e))}),n}_parseCommand(t,e){const r=this.parseOptions(e);if(this._parseOptionsEnv(),this._parseOptionsImplied(),t=t.concat(r.operands),e=r.unknown,this.args=t.concat(e),t&&this._findCommand(t[0]))return this._dispatchSubcommand(t[0],t.slice(1),e);if(this._getHelpCommand()&&t[0]===this._getHelpCommand().name())return this._dispatchHelpCommand(t[1]);if(this._defaultCommandName)return this._outputHelpIfRequested(e),this._dispatchSubcommand(this._defaultCommandName,t,e);!this.commands.length||0!==this.args.length||this._actionHandler||this._defaultCommandName||this.help({error:!0}),this._outputHelpIfRequested(r.unknown),this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();const n=()=>{r.unknown.length>0&&this.unknownOption(r.unknown[0])},i=`command:${this.name()}`;if(this._actionHandler){let r;return n(),this._processArguments(),r=this._chainOrCallHooks(r,"preAction"),r=this._chainOrCall(r,()=>this._actionHandler(this.processedArgs)),this.parent&&(r=this._chainOrCall(r,()=>{this.parent.emit(i,t,e)})),r=this._chainOrCallHooks(r,"postAction"),r}if(this.parent?.listenerCount(i))n(),this._processArguments(),this.parent.emit(i,t,e);else if(t.length){if(this._findCommand("*"))return this._dispatchSubcommand("*",t,e);this.listenerCount("command:*")?this.emit("command:*",t,e):this.commands.length?this.unknownCommand():(n(),this._processArguments())}else this.commands.length?(n(),this.help({error:!0})):(n(),this._processArguments())}_findCommand(t){if(t)return this.commands.find(e=>e._name===t||e._aliases.includes(t))}_findOption(t){return this.options.find(e=>e.is(t))}_checkForMissingMandatoryOptions(){this._getCommandAndAncestors().forEach(t=>{t.options.forEach(e=>{e.mandatory&&void 0===t.getOptionValue(e.attributeName())&&t.missingMandatoryOptionValue(e)})})}_checkForConflictingLocalOptions(){const t=this.options.filter(t=>{const e=t.attributeName();return void 0!==this.getOptionValue(e)&&"default"!==this.getOptionValueSource(e)}),e=t.filter(t=>t.conflictsWith.length>0);e.forEach(e=>{const r=t.find(t=>e.conflictsWith.includes(t.attributeName()));r&&this._conflictingOption(e,r)})}_checkForConflictingOptions(){this._getCommandAndAncestors().forEach(t=>{t._checkForConflictingLocalOptions()})}parseOptions(t){const e=[],r=[];let n=e;function i(t){return t.length>1&&"-"===t[0]}const s=t=>!!/^-(\d+|\d*\.\d+)(e[+-]?\d+)?$/.test(t)&&!this._getCommandAndAncestors().some(t=>t.options.map(t=>t.short).some(t=>/^-\d$/.test(t)));let o=null,a=null,l=0;for(;l<t.length||a;){const h=a??t[l++];if(a=null,"--"===h){n===r&&n.push(h),n.push(...t.slice(l));break}if(!o||i(h)&&!s(h)){if(o=null,i(h)){const e=this._findOption(h);if(e){if(e.required){const r=t[l++];void 0===r&&this.optionMissingArgument(e),this.emit(`option:${e.name()}`,r)}else if(e.optional){let r=null;l<t.length&&(!i(t[l])||s(t[l]))&&(r=t[l++]),this.emit(`option:${e.name()}`,r)}else this.emit(`option:${e.name()}`);o=e.variadic?e:null;continue}}if(h.length>2&&"-"===h[0]&&"-"!==h[1]){const t=this._findOption(`-${h[1]}`);if(t){t.required||t.optional&&this._combineFlagAndOptionalValue?this.emit(`option:${t.name()}`,h.slice(2)):(this.emit(`option:${t.name()}`),a=`-${h.slice(2)}`);continue}}if(/^--[^=]+=/.test(h)){const t=h.indexOf("="),e=this._findOption(h.slice(0,t));if(e&&(e.required||e.optional)){this.emit(`option:${e.name()}`,h.slice(t+1));continue}}if(n!==e||!i(h)||0===this.commands.length&&s(h)||(n=r),(this._enablePositionalOptions||this._passThroughOptions)&&0===e.length&&0===r.length){if(this._findCommand(h)){e.push(h),r.push(...t.slice(l));break}if(this._getHelpCommand()&&h===this._getHelpCommand().name()){e.push(h,...t.slice(l));break}if(this._defaultCommandName){r.push(h,...t.slice(l));break}}if(this._passThroughOptions){n.push(h,...t.slice(l));break}n.push(h)}else this.emit(`option:${o.name()}`,h)}return{operands:e,unknown:r}}opts(){if(this._storeOptionsAsProperties){const t={},e=this.options.length;for(let r=0;r<e;r++){const e=this.options[r].attributeName();t[e]=e===this._versionOptionName?this._version:this[e]}return t}return this._optionValues}optsWithGlobals(){return this._getCommandAndAncestors().reduce((t,e)=>Object.assign(t,e.opts()),{})}error(t,e){this._outputConfiguration.outputError(`${t}\n`,this._outputConfiguration.writeErr),"string"==typeof this._showHelpAfterError?this._outputConfiguration.writeErr(`${this._showHelpAfterError}\n`):this._showHelpAfterError&&(this._outputConfiguration.writeErr("\n"),this.outputHelp({error:!0}));const r=e||{},n=r.exitCode||1,i=r.code||"commander.error";this._exit(n,i,t)}_parseOptionsEnv(){this.options.forEach(t=>{if(t.envVar&&t.envVar in h.env){const e=t.attributeName();(void 0===this.getOptionValue(e)||["default","config","env"].includes(this.getOptionValueSource(e)))&&(t.required||t.optional?this.emit(`optionEnv:${t.name()}`,h.env[t.envVar]):this.emit(`optionEnv:${t.name()}`))}})}_parseOptionsImplied(){const t=new A(this.options),e=t=>void 0!==this.getOptionValue(t)&&!["default","implied"].includes(this.getOptionValueSource(t));this.options.filter(r=>void 0!==r.implied&&e(r.attributeName())&&t.valueFromOption(this.getOptionValue(r.attributeName()),r)).forEach(t=>{Object.keys(t.implied).filter(t=>!e(t)).forEach(e=>{this.setOptionValueWithSource(e,t.implied[e],"implied")})})}missingArgument(t){const e=`error: missing required argument '${t}'`;this.error(e,{code:"commander.missingArgument"})}optionMissingArgument(t){const e=`error: option '${t.flags}' argument missing`;this.error(e,{code:"commander.optionMissingArgument"})}missingMandatoryOptionValue(t){const e=`error: required option '${t.flags}' not specified`;this.error(e,{code:"commander.missingMandatoryOptionValue"})}_conflictingOption(t,e){const r=t=>{const e=t.attributeName(),r=this.getOptionValue(e),n=this.options.find(t=>t.negate&&e===t.attributeName()),i=this.options.find(t=>!t.negate&&e===t.attributeName());return n&&(void 0===n.presetArg&&!1===r||void 0!==n.presetArg&&r===n.presetArg)?n:i||t},n=t=>{const e=r(t),n=e.attributeName();return"env"===this.getOptionValueSource(n)?`environment variable '${e.envVar}'`:`option '${e.flags}'`},i=`error: ${n(t)} cannot be used with ${n(e)}`;this.error(i,{code:"commander.conflictingOption"})}unknownOption(t){if(this._allowUnknownOption)return;let e="";if(t.startsWith("--")&&this._showSuggestionAfterError){let r=[],n=this;do{const t=n.createHelp().visibleOptions(n).filter(t=>t.long).map(t=>t.long);r=r.concat(t),n=n.parent}while(n&&!n._enablePositionalOptions);e=C(t,r)}const r=`error: unknown option '${t}'${e}`;this.error(r,{code:"commander.unknownOption"})}_excessArguments(t){if(this._allowExcessArguments)return;const e=this.registeredArguments.length,r=1===e?"":"s",n=`error: too many arguments${this.parent?` for '${this.name()}'`:""}. Expected ${e} argument${r} but got ${t.length}.`;this.error(n,{code:"commander.excessArguments"})}unknownCommand(){const t=this.args[0];let e="";if(this._showSuggestionAfterError){const r=[];this.createHelp().visibleCommands(this).forEach(t=>{r.push(t.name()),t.alias()&&r.push(t.alias())}),e=C(t,r)}const r=`error: unknown command '${t}'${e}`;this.error(r,{code:"commander.unknownCommand"})}version(t,e,r){if(void 0===t)return this._version;this._version=t,e=e||"-V, --version",r=r||"output the version number";const n=this.createOption(e,r);return this._versionOptionName=n.attributeName(),this._registerOption(n),this.on("option:"+n.name(),()=>{this._outputConfiguration.writeOut(`${t}\n`),this._exit(0,"commander.version",t)}),this}description(t,e){return void 0===t&&void 0===e?this._description:(this._description=t,e&&(this._argsDescription=e),this)}summary(t){return void 0===t?this._summary:(this._summary=t,this)}alias(t){if(void 0===t)return this._aliases[0];let e=this;if(0!==this.commands.length&&this.commands[this.commands.length-1]._executableHandler&&(e=this.commands[this.commands.length-1]),t===e._name)throw new Error("Command alias can't be the same as its name");const r=this.parent?._findCommand(t);if(r){const e=[r.name()].concat(r.aliases()).join("|");throw new Error(`cannot add alias '${t}' to command '${this.name()}' as already have command '${e}'`)}return e._aliases.push(t),this}aliases(t){return void 0===t?this._aliases:(t.forEach(t=>this.alias(t)),this)}usage(t){if(void 0===t){if(this._usage)return this._usage;const t=this.registeredArguments.map(t=>u(t));return[].concat(this.options.length||null!==this._helpOption?"[options]":[],this.commands.length?"[command]":[],this.registeredArguments.length?t:[]).join(" ")}return this._usage=t,this}name(t){return void 0===t?this._name:(this._name=t,this)}helpGroup(t){return void 0===t?this._helpGroupHeading??"":(this._helpGroupHeading=t,this)}commandsGroup(t){return void 0===t?this._defaultCommandGroup??"":(this._defaultCommandGroup=t,this)}optionsGroup(t){return void 0===t?this._defaultOptionGroup??"":(this._defaultOptionGroup=t,this)}_initOptionGroup(t){this._defaultOptionGroup&&!t.helpGroupHeading&&t.helpGroup(this._defaultOptionGroup)}_initCommandGroup(t){this._defaultCommandGroup&&!t.helpGroup()&&t.helpGroup(this._defaultCommandGroup)}nameFromFilename(t){return this._name=a.basename(t,a.extname(t)),this}executableDir(t){return void 0===t?this._executableDir:(this._executableDir=t,this)}helpInformation(t){const e=this.createHelp(),r=this._getOutputContext(t);e.prepareContext({error:r.error,helpWidth:r.helpWidth,outputHasColors:r.hasColors});const n=e.formatHelp(this,e);return r.hasColors?n:this._outputConfiguration.stripColor(n)}_getOutputContext(t){const e=!!(t=t||{}).error;let r,n,i;return e?(r=t=>this._outputConfiguration.writeErr(t),n=this._outputConfiguration.getErrHasColors(),i=this._outputConfiguration.getErrHelpWidth()):(r=t=>this._outputConfiguration.writeOut(t),n=this._outputConfiguration.getOutHasColors(),i=this._outputConfiguration.getOutHelpWidth()),{error:e,write:t=>(n||(t=this._outputConfiguration.stripColor(t)),r(t)),hasColors:n,helpWidth:i}}outputHelp(t){let e;"function"==typeof t&&(e=t,t=void 0);const r=this._getOutputContext(t),n={error:r.error,write:r.write,command:this};this._getCommandAndAncestors().reverse().forEach(t=>t.emit("beforeAllHelp",n)),this.emit("beforeHelp",n);let i=this.helpInformation({error:r.error});if(e&&(i=e(i),"string"!=typeof i&&!Buffer.isBuffer(i)))throw new Error("outputHelp callback must return a string or a Buffer");r.write(i),this._getHelpOption()?.long&&this.emit(this._getHelpOption().long),this.emit("afterHelp",n),this._getCommandAndAncestors().forEach(t=>t.emit("afterAllHelp",n))}helpOption(t,e){return"boolean"==typeof t?(t?(null===this._helpOption&&(this._helpOption=void 0),this._defaultOptionGroup&&this._initOptionGroup(this._getHelpOption())):this._helpOption=null,this):(this._helpOption=this.createOption(t??"-h, --help",e??"display help for command"),(t||e)&&this._initOptionGroup(this._helpOption),this)}_getHelpOption(){return void 0===this._helpOption&&this.helpOption(void 0,void 0),this._helpOption}addHelpOption(t){return this._helpOption=t,this._initOptionGroup(t),this}help(t){this.outputHelp(t);let e=Number(h.exitCode??0);0===e&&t&&"function"!=typeof t&&t.error&&(e=1),this._exit(e,"commander.help","(outputHelp)")}addHelpText(t,e){const r=["beforeAll","before","after","afterAll"];if(!r.includes(t))throw new Error(`Unexpected value for position to addHelpText.\nExpecting one of '${r.join("', '")}'`);const n=`${t}Help`;return this.on(n,t=>{let r;r="function"==typeof e?e({error:t.error,command:t.command}):e,r&&t.write(`${r}\n`)}),this}_outputHelpIfRequested(t){const e=this._getHelpOption();e&&t.find(t=>e.is(t))&&(this.outputHelp(),this._exit(0,"commander.helpDisplayed","(outputHelp)"))}}function I(t){return t.map(t=>{if(!t.startsWith("--inspect"))return t;let e,r,n="127.0.0.1",i="9229";return null!==(r=t.match(/^(--inspect(-brk)?)$/))?e=r[1]:null!==(r=t.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))?(e=r[1],/^\d+$/.test(r[3])?i=r[3]:n=r[3]):null!==(r=t.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))&&(e=r[1],n=r[3],i=r[4]),e&&"0"!==i?`${e}=${n}:${parseInt(i)+1}`:t})}function y(){return!h.env.NO_COLOR&&"0"!==h.env.FORCE_COLOR&&"false"!==h.env.FORCE_COLOR&&(!(!h.env.FORCE_COLOR&&void 0===h.env.CLICOLOR_FORCE)||void 0)}return f.Command=w,f.useColor=y,f}(),{CommanderError:a,InvalidArgumentError:l}=p(),{Help:c}=E(),{Option:u}=O();return h.program=new o,h.createCommand=t=>new o(t),h.createOption=(t,e)=>new u(t,e),h.createArgument=(t,e)=>new s(t,e),h.Command=o,h.Option=u,h.Argument=s,h.Help=c,h.CommanderError=a,h.InvalidArgumentError=l,h.InvalidOptionArgumentError=l,h}(),y=o(I);const{program:S,createCommand:R,createArgument:T,createOption:N,CommanderError:L,InvalidArgumentError:x,InvalidOptionArgumentError:P,Command:k,Argument:H,Option:D,Help:F}=y;var G,V,M,j,U,W,X,q,B,Y,K,z,J,Z,Q,tt,et,rt,nt,it,st,ot,at,lt,ht,ct,ut,pt,mt,dt,ft,gt,Et,_t,vt,Ot,At,$t,Ct,wt,bt,It,yt,St,Rt,Tt,Nt,Lt,xt,Pt,kt,Ht,Dt,Ft,Gt,Vt,Mt,jt,Ut,Wt,Xt,qt,Bt,Yt,Kt,zt,Jt,Zt,Qt,te,ee,re,ne,ie,se,oe,ae,le,he,ce,ue,pe,me,de,fe,ge,Ee,_e,ve,Oe,Ae,$e={exports:{}};function Ce(){if(V)return G;V=1;const t=Number.MAX_SAFE_INTEGER||9007199254740991;return G={MAX_LENGTH:256,MAX_SAFE_COMPONENT_LENGTH:16,MAX_SAFE_BUILD_LENGTH:250,MAX_SAFE_INTEGER:t,RELEASE_TYPES:["major","premajor","minor","preminor","patch","prepatch","prerelease"],SEMVER_SPEC_VERSION:"2.0.0",FLAG_INCLUDE_PRERELEASE:1,FLAG_LOOSE:2}}function we(){if(j)return M;j=1;const t="object"==typeof process&&process.env&&process.env.NODE_DEBUG&&/\bsemver\b/i.test(process.env.NODE_DEBUG)?(...t)=>console.error("SEMVER",...t):()=>{};return M=t}function be(){return U||(U=1,function(t,e){const{MAX_SAFE_COMPONENT_LENGTH:r,MAX_SAFE_BUILD_LENGTH:n,MAX_LENGTH:i}=Ce(),s=we(),o=(e=t.exports={}).re=[],a=e.safeRe=[],l=e.src=[],h=e.safeSrc=[],c=e.t={};let u=0;const p="[a-zA-Z0-9-]",m=[["\\s",1],["\\d",i],[p,n]],d=(t,e,r)=>{const n=(t=>{for(const[e,r]of m)t=t.split(`${e}*`).join(`${e}{0,${r}}`).split(`${e}+`).join(`${e}{1,${r}}`);return t})(e),i=u++;s(t,i,e),c[t]=i,l[i]=e,h[i]=n,o[i]=new RegExp(e,r?"g":void 0),a[i]=new RegExp(n,r?"g":void 0)};d("NUMERICIDENTIFIER","0|[1-9]\\d*"),d("NUMERICIDENTIFIERLOOSE","\\d+"),d("NONNUMERICIDENTIFIER",`\\d*[a-zA-Z-]${p}*`),d("MAINVERSION",`(${l[c.NUMERICIDENTIFIER]})\\.(${l[c.NUMERICIDENTIFIER]})\\.(${l[c.NUMERICIDENTIFIER]})`),d("MAINVERSIONLOOSE",`(${l[c.NUMERICIDENTIFIERLOOSE]})\\.(${l[c.NUMERICIDENTIFIERLOOSE]})\\.(${l[c.NUMERICIDENTIFIERLOOSE]})`),d("PRERELEASEIDENTIFIER",`(?:${l[c.NONNUMERICIDENTIFIER]}|${l[c.NUMERICIDENTIFIER]})`),d("PRERELEASEIDENTIFIERLOOSE",`(?:${l[c.NONNUMERICIDENTIFIER]}|${l[c.NUMERICIDENTIFIERLOOSE]})`),d("PRERELEASE",`(?:-(${l[c.PRERELEASEIDENTIFIER]}(?:\\.${l[c.PRERELEASEIDENTIFIER]})*))`),d("PRERELEASELOOSE",`(?:-?(${l[c.PRERELEASEIDENTIFIERLOOSE]}(?:\\.${l[c.PRERELEASEIDENTIFIERLOOSE]})*))`),d("BUILDIDENTIFIER",`${p}+`),d("BUILD",`(?:\\+(${l[c.BUILDIDENTIFIER]}(?:\\.${l[c.BUILDIDENTIFIER]})*))`),d("FULLPLAIN",`v?${l[c.MAINVERSION]}${l[c.PRERELEASE]}?${l[c.BUILD]}?`),d("FULL",`^${l[c.FULLPLAIN]}$`),d("LOOSEPLAIN",`[v=\\s]*${l[c.MAINVERSIONLOOSE]}${l[c.PRERELEASELOOSE]}?${l[c.BUILD]}?`),d("LOOSE",`^${l[c.LOOSEPLAIN]}$`),d("GTLT","((?:<|>)?=?)"),d("XRANGEIDENTIFIERLOOSE",`${l[c.NUMERICIDENTIFIERLOOSE]}|x|X|\\*`),d("XRANGEIDENTIFIER",`${l[c.NUMERICIDENTIFIER]}|x|X|\\*`),d("XRANGEPLAIN",`[v=\\s]*(${l[c.XRANGEIDENTIFIER]})(?:\\.(${l[c.XRANGEIDENTIFIER]})(?:\\.(${l[c.XRANGEIDENTIFIER]})(?:${l[c.PRERELEASE]})?${l[c.BUILD]}?)?)?`),d("XRANGEPLAINLOOSE",`[v=\\s]*(${l[c.XRANGEIDENTIFIERLOOSE]})(?:\\.(${l[c.XRANGEIDENTIFIERLOOSE]})(?:\\.(${l[c.XRANGEIDENTIFIERLOOSE]})(?:${l[c.PRERELEASELOOSE]})?${l[c.BUILD]}?)?)?`),d("XRANGE",`^${l[c.GTLT]}\\s*${l[c.XRANGEPLAIN]}$`),d("XRANGELOOSE",`^${l[c.GTLT]}\\s*${l[c.XRANGEPLAINLOOSE]}$`),d("COERCEPLAIN",`(^|[^\\d])(\\d{1,${r}})(?:\\.(\\d{1,${r}}))?(?:\\.(\\d{1,${r}}))?`),d("COERCE",`${l[c.COERCEPLAIN]}(?:$|[^\\d])`),d("COERCEFULL",l[c.COERCEPLAIN]+`(?:${l[c.PRERELEASE]})?`+`(?:${l[c.BUILD]})?(?:$|[^\\d])`),d("COERCERTL",l[c.COERCE],!0),d("COERCERTLFULL",l[c.COERCEFULL],!0),d("LONETILDE","(?:~>?)"),d("TILDETRIM",`(\\s*)${l[c.LONETILDE]}\\s+`,!0),e.tildeTrimReplace="$1~",d("TILDE",`^${l[c.LONETILDE]}${l[c.XRANGEPLAIN]}$`),d("TILDELOOSE",`^${l[c.LONETILDE]}${l[c.XRANGEPLAINLOOSE]}$`),d("LONECARET","(?:\\^)"),d("CARETTRIM",`(\\s*)${l[c.LONECARET]}\\s+`,!0),e.caretTrimReplace="$1^",d("CARET",`^${l[c.LONECARET]}${l[c.XRANGEPLAIN]}$`),d("CARETLOOSE",`^${l[c.LONECARET]}${l[c.XRANGEPLAINLOOSE]}$`),d("COMPARATORLOOSE",`^${l[c.GTLT]}\\s*(${l[c.LOOSEPLAIN]})$|^$`),d("COMPARATOR",`^${l[c.GTLT]}\\s*(${l[c.FULLPLAIN]})$|^$`),d("COMPARATORTRIM",`(\\s*)${l[c.GTLT]}\\s*(${l[c.LOOSEPLAIN]}|${l[c.XRANGEPLAIN]})`,!0),e.comparatorTrimReplace="$1$2$3",d("HYPHENRANGE",`^\\s*(${l[c.XRANGEPLAIN]})\\s+-\\s+(${l[c.XRANGEPLAIN]})\\s*$`),d("HYPHENRANGELOOSE",`^\\s*(${l[c.XRANGEPLAINLOOSE]})\\s+-\\s+(${l[c.XRANGEPLAINLOOSE]})\\s*$`),d("STAR","(<|>)?=?\\s*\\*"),d("GTE0","^\\s*>=\\s*0\\.0\\.0\\s*$"),d("GTE0PRE","^\\s*>=\\s*0\\.0\\.0-0\\s*$")}($e,$e.exports)),$e.exports}function Ie(){if(X)return W;X=1;const t=Object.freeze({loose:!0}),e=Object.freeze({});return W=r=>r?"object"!=typeof r?t:r:e}function ye(){if(B)return q;B=1;const t=/^[0-9]+$/,e=(e,r)=>{if("number"==typeof e&&"number"==typeof r)return e===r?0:e<r?-1:1;const n=t.test(e),i=t.test(r);return n&&i&&(e=+e,r=+r),e===r?0:n&&!i?-1:i&&!n?1:e<r?-1:1};return q={compareIdentifiers:e,rcompareIdentifiers:(t,r)=>e(r,t)}}function Se(){if(K)return Y;K=1;const t=we(),{MAX_LENGTH:e,MAX_SAFE_INTEGER:r}=Ce(),{safeRe:n,t:i}=be(),s=Ie(),{compareIdentifiers:o}=ye();class a{constructor(o,l){if(l=s(l),o instanceof a){if(o.loose===!!l.loose&&o.includePrerelease===!!l.includePrerelease)return o;o=o.version}else if("string"!=typeof o)throw new TypeError(`Invalid version. Must be a string. Got type "${typeof o}".`);if(o.length>e)throw new TypeError(`version is longer than ${e} characters`);t("SemVer",o,l),this.options=l,this.loose=!!l.loose,this.includePrerelease=!!l.includePrerelease;const h=o.trim().match(l.loose?n[i.LOOSE]:n[i.FULL]);if(!h)throw new TypeError(`Invalid Version: ${o}`);if(this.raw=o,this.major=+h[1],this.minor=+h[2],this.patch=+h[3],this.major>r||this.major<0)throw new TypeError("Invalid major version");if(this.minor>r||this.minor<0)throw new TypeError("Invalid minor version");if(this.patch>r||this.patch<0)throw new TypeError("Invalid patch version");h[4]?this.prerelease=h[4].split(".").map(t=>{if(/^[0-9]+$/.test(t)){const e=+t;if(e>=0&&e<r)return e}return t}):this.prerelease=[],this.build=h[5]?h[5].split("."):[],this.format()}format(){return this.version=`${this.major}.${this.minor}.${this.patch}`,this.prerelease.length&&(this.version+=`-${this.prerelease.join(".")}`),this.version}toString(){return this.version}compare(e){if(t("SemVer.compare",this.version,this.options,e),!(e instanceof a)){if("string"==typeof e&&e===this.version)return 0;e=new a(e,this.options)}return e.version===this.version?0:this.compareMain(e)||this.comparePre(e)}compareMain(t){return t instanceof a||(t=new a(t,this.options)),this.major<t.major?-1:this.major>t.major?1:this.minor<t.minor?-1:this.minor>t.minor?1:this.patch<t.patch?-1:this.patch>t.patch?1:0}comparePre(e){if(e instanceof a||(e=new a(e,this.options)),this.prerelease.length&&!e.prerelease.length)return-1;if(!this.prerelease.length&&e.prerelease.length)return 1;if(!this.prerelease.length&&!e.prerelease.length)return 0;let r=0;do{const n=this.prerelease[r],i=e.prerelease[r];if(t("prerelease compare",r,n,i),void 0===n&&void 0===i)return 0;if(void 0===i)return 1;if(void 0===n)return-1;if(n!==i)return o(n,i)}while(++r)}compareBuild(e){e instanceof a||(e=new a(e,this.options));let r=0;do{const n=this.build[r],i=e.build[r];if(t("build compare",r,n,i),void 0===n&&void 0===i)return 0;if(void 0===i)return 1;if(void 0===n)return-1;if(n!==i)return o(n,i)}while(++r)}inc(t,e,r){if(t.startsWith("pre")){if(!e&&!1===r)throw new Error("invalid increment argument: identifier is empty");if(e){const t=`-${e}`.match(this.options.loose?n[i.PRERELEASELOOSE]:n[i.PRERELEASE]);if(!t||t[1]!==e)throw new Error(`invalid identifier: ${e}`)}}switch(t){case"premajor":this.prerelease.length=0,this.patch=0,this.minor=0,this.major++,this.inc("pre",e,r);break;case"preminor":this.prerelease.length=0,this.patch=0,this.minor++,this.inc("pre",e,r);break;case"prepatch":this.prerelease.length=0,this.inc("patch",e,r),this.inc("pre",e,r);break;case"prerelease":0===this.prerelease.length&&this.inc("patch",e,r),this.inc("pre",e,r);break;case"release":if(0===this.prerelease.length)throw new Error(`version ${this.raw} is not a prerelease`);this.prerelease.length=0;break;case"major":0===this.minor&&0===this.patch&&0!==this.prerelease.length||this.major++,this.minor=0,this.patch=0,this.prerelease=[];break;case"minor":0===this.patch&&0!==this.prerelease.length||this.minor++,this.patch=0,this.prerelease=[];break;case"patch":0===this.prerelease.length&&this.patch++,this.prerelease=[];break;case"pre":{const t=Number(r)?1:0;if(0===this.prerelease.length)this.prerelease=[t];else{let n=this.prerelease.length;for(;--n>=0;)"number"==typeof this.prerelease[n]&&(this.prerelease[n]++,n=-2);if(-1===n){if(e===this.prerelease.join(".")&&!1===r)throw new Error("invalid increment argument: identifier already exists");this.prerelease.push(t)}}if(e){let n=[e,t];if(!1===r&&(n=[e]),((t,e)=>{const r=e.split(".");if(r.length>t.length)return!1;for(let e=0;e<r.length;e++)if(0!==o(t[e],r[e]))return!1;return!0})(this.prerelease,e)){const t=this.prerelease[e.split(".").length];isNaN(t)&&(this.prerelease=n)}else this.prerelease=n}break}default:throw new Error(`invalid increment argument: ${t}`)}return this.raw=this.format(),this.build.length&&(this.raw+=`+${this.build.join(".")}`),this}}return Y=a}function Re(){if(J)return z;J=1;const t=Se();return z=(e,r,n=!1)=>{if(e instanceof t)return e;try{return new t(e,r)}catch(t){if(!n)return null;throw t}}}function Te(){if(ft)return dt;ft=1;const t=Se();return dt=(e,r,n)=>new t(e,n).compare(new t(r,n))}function Ne(){if(At)return Ot;At=1;const t=Se();return Ot=(e,r,n)=>{const i=new t(e,n),s=new t(r,n);return i.compare(s)||i.compareBuild(s)}}function Le(){if(yt)return It;yt=1;const t=Te();return It=(e,r,n)=>t(e,r,n)>0}function xe(){if(Rt)return St;Rt=1;const t=Te();return St=(e,r,n)=>t(e,r,n)<0}function Pe(){if(Nt)return Tt;Nt=1;const t=Te();return Tt=(e,r,n)=>0===t(e,r,n)}function ke(){if(xt)return Lt;xt=1;const t=Te();return Lt=(e,r,n)=>0!==t(e,r,n)}function He(){if(kt)return Pt;kt=1;const t=Te();return Pt=(e,r,n)=>t(e,r,n)>=0}function De(){if(Dt)return Ht;Dt=1;const t=Te();return Ht=(e,r,n)=>t(e,r,n)<=0}function Fe(){if(Gt)return Ft;Gt=1;const t=Pe(),e=ke(),r=Le(),n=He(),i=xe(),s=De();return Ft=(o,a,l,h)=>{switch(a){case"===":return"object"==typeof o&&(o=o.version),"object"==typeof l&&(l=l.version),o===l;case"!==":return"object"==typeof o&&(o=o.version),"object"==typeof l&&(l=l.version),o!==l;case"":case"=":case"==":return t(o,l,h);case"!=":return e(o,l,h);case">":return r(o,l,h);case">=":return n(o,l,h);case"<":return i(o,l,h);case"<=":return s(o,l,h);default:throw new TypeError(`Invalid operator: ${a}`)}}}function Ge(){if(Bt)return qt;Bt=1;const t=/\s+/g;class e{constructor(r,s){if(s=n(s),r instanceof e)return r.loose===!!s.loose&&r.includePrerelease===!!s.includePrerelease?r:new e(r.raw,s);if(r instanceof i)return this.raw=r.value,this.set=[[r]],this.formatted=void 0,this;if(this.options=s,this.loose=!!s.loose,this.includePrerelease=!!s.includePrerelease,this.raw=r.trim().replace(t," "),this.set=this.raw.split("||").map(t=>this.parseRange(t.trim())).filter(t=>t.length),!this.set.length)throw new TypeError(`Invalid SemVer Range: ${this.raw}`);if(this.set.length>1){const t=this.set[0];if(this.set=this.set.filter(t=>!g(t[0])),0===this.set.length)this.set=[t];else if(this.set.length>1)for(const t of this.set)if(1===t.length&&E(t[0])){this.set=[t];break}}this.formatted=void 0}get range(){if(void 0===this.formatted){this.formatted="";for(let t=0;t<this.set.length;t++){t>0&&(this.formatted+="||");const e=this.set[t];for(let t=0;t<e.length;t++)t>0&&(this.formatted+=" "),this.formatted+=e[t].toString().trim()}}return this.formatted}format(){return this.range}toString(){return this.range}parseRange(t){t=t.replace(f,"");const e=((this.options.includePrerelease&&m)|(this.options.loose&&d))+":"+t,n=r.get(e);if(n)return n;const o=this.options.loose,l=o?a[h.HYPHENRANGELOOSE]:a[h.HYPHENRANGE];t=t.replace(l,R(this.options.includePrerelease)),s("hyphen replace",t),t=t.replace(a[h.COMPARATORTRIM],c),s("comparator trim",t),t=t.replace(a[h.TILDETRIM],u),s("tilde trim",t),t=t.replace(a[h.CARETTRIM],p),s("caret trim",t);let E=t.split(" ").map(t=>v(t,this.options)).join(" ").split(/\s+/).map(t=>S(t,this.options));o&&(E=E.filter(t=>(s("loose invalid filter",t,this.options),!!t.match(a[h.COMPARATORLOOSE])))),s("range list",E);const _=new Map,O=E.map(t=>new i(t,this.options));for(const t of O){if(g(t))return[t];_.set(t.value,t)}_.size>1&&_.has("")&&_.delete("");const A=[..._.values()];return r.set(e,A),A}intersects(t,r){if(!(t instanceof e))throw new TypeError("a Range is required");return this.set.some(e=>_(e,r)&&t.set.some(t=>_(t,r)&&e.every(e=>t.every(t=>e.intersects(t,r)))))}test(t){if(!t)return!1;if("string"==typeof t)try{t=new o(t,this.options)}catch(t){return!1}for(let e=0;e<this.set.length;e++)if(T(this.set[e],t,this.options))return!0;return!1}}qt=e;const r=new(Xt?Wt:(Xt=1,Wt=class{constructor(){this.max=1e3,this.map=new Map}get(t){const e=this.map.get(t);return void 0===e?void 0:(this.map.delete(t),this.map.set(t,e),e)}delete(t){return this.map.delete(t)}set(t,e){if(!this.delete(t)&&void 0!==e){if(this.map.size>=this.max){const t=this.map.keys().next().value;this.delete(t)}this.map.set(t,e)}return this}})),n=Ie(),i=Ve(),s=we(),o=Se(),{safeRe:a,src:l,t:h,comparatorTrimReplace:c,tildeTrimReplace:u,caretTrimReplace:p}=be(),{FLAG_INCLUDE_PRERELEASE:m,FLAG_LOOSE:d}=Ce(),f=new RegExp(l[h.BUILD],"g"),g=t=>"<0.0.0-0"===t.value,E=t=>""===t.value,_=(t,e)=>{let r=!0;const n=t.slice();let i=n.pop();for(;r&&n.length;)r=n.every(t=>i.intersects(t,e)),i=n.pop();return r},v=(t,e)=>(t=t.replace(a[h.BUILD],""),s("comp",t,e),t=C(t,e),s("caret",t),t=A(t,e),s("tildes",t),t=b(t,e),s("xrange",t),t=y(t,e),s("stars",t),t),O=t=>!t||"x"===t.toLowerCase()||"*"===t,A=(t,e)=>t.trim().split(/\s+/).map(t=>$(t,e)).join(" "),$=(t,e)=>{const r=e.loose?a[h.TILDELOOSE]:a[h.TILDE],n=e.includePrerelease?"-0":"";return t.replace(r,(e,r,i,o,a)=>{let l;return s("tilde",t,e,r,i,o,a),O(r)?l="":O(i)?l=`>=${r}.0.0${n} <${+r+1}.0.0-0`:O(o)?l=`>=${r}.${i}.0${n} <${r}.${+i+1}.0-0`:a?(s("replaceTilde pr",a),l=`>=${r}.${i}.${o}-${a} <${r}.${+i+1}.0-0`):l=`>=${r}.${i}.${o} <${r}.${+i+1}.0-0`,s("tilde return",l),l})},C=(t,e)=>t.trim().split(/\s+/).map(t=>w(t,e)).join(" "),w=(t,e)=>{s("caret",t,e);const r=e.loose?a[h.CARETLOOSE]:a[h.CARET],n=e.includePrerelease?"-0":"";return t.replace(r,(e,r,i,o,a)=>{let l;return s("caret",t,e,r,i,o,a),O(r)?l="":O(i)?l=`>=${r}.0.0${n} <${+r+1}.0.0-0`:O(o)?l="0"===r?`>=${r}.${i}.0${n} <${r}.${+i+1}.0-0`:`>=${r}.${i}.0${n} <${+r+1}.0.0-0`:a?(s("replaceCaret pr",a),l="0"===r?"0"===i?`>=${r}.${i}.${o}-${a} <${r}.${i}.${+o+1}-0`:`>=${r}.${i}.${o}-${a} <${r}.${+i+1}.0-0`:`>=${r}.${i}.${o}-${a} <${+r+1}.0.0-0`):(s("no pr"),l="0"===r?"0"===i?`>=${r}.${i}.${o} <${r}.${i}.${+o+1}-0`:`>=${r}.${i}.${o} <${r}.${+i+1}.0-0`:`>=${r}.${i}.${o} <${+r+1}.0.0-0`),s("caret return",l),l})},b=(t,e)=>(s("replaceXRanges",t,e),t.split(/\s+/).map(t=>I(t,e)).join(" ")),I=(t,e)=>{t=t.trim();const r=e.loose?a[h.XRANGELOOSE]:a[h.XRANGE];return t.replace(r,(r,n,i,o,a,l)=>{if(s("xRange",t,r,n,i,o,a,l),((t,e,r)=>O(t)&&!O(e)||O(e)&&r&&!O(r))(i,o,a))return t;const h=O(i),c=h||O(o),u=c||O(a),p=u;return"="===n&&p&&(n=""),l=e.includePrerelease?"-0":"",h?r=">"===n||"<"===n?"<0.0.0-0":"*":n&&p?(c&&(o=0),a=0,">"===n?(n=">=",c?(i=+i+1,o=0,a=0):(o=+o+1,a=0)):"<="===n&&(n="<",c?i=+i+1:o=+o+1),"<"===n&&(l="-0"),r=`${n+i}.${o}.${a}${l}`):c?r=`>=${i}.0.0${l} <${+i+1}.0.0-0`:u&&(r=`>=${i}.${o}.0${l} <${i}.${+o+1}.0-0`),s("xRange return",r),r})},y=(t,e)=>(s("replaceStars",t,e),t.trim().replace(a[h.STAR],"")),S=(t,e)=>(s("replaceGTE0",t,e),t.trim().replace(a[e.includePrerelease?h.GTE0PRE:h.GTE0],"")),R=t=>(e,r,n,i,s,o,a,l,h,c,u,p)=>`${r=O(n)?"":O(i)?`>=${n}.0.0${t?"-0":""}`:O(s)?`>=${n}.${i}.0${t?"-0":""}`:o?`>=${r}`:`>=${r}${t?"-0":""}`} ${l=O(h)?"":O(c)?`<${+h+1}.0.0-0`:O(u)?`<${h}.${+c+1}.0-0`:p?`<=${h}.${c}.${u}-${p}`:t?`<${h}.${c}.${+u+1}-0`:`<=${l}`}`.trim(),T=(t,e,r)=>{for(let r=0;r<t.length;r++)if(!t[r].test(e))return!1;if(e.prerelease.length&&!r.includePrerelease){for(let r=0;r<t.length;r++)if(s(t[r].semver),t[r].semver!==i.ANY&&t[r].semver.prerelease.length>0){const n=t[r].semver;if(n.major===e.major&&n.minor===e.minor&&n.patch===e.patch)return!0}return!1}return!0};return qt}function Ve(){if(Kt)return Yt;Kt=1;const t=Symbol("SemVer ANY");class e{static get ANY(){return t}constructor(n,i){if(i=r(i),n instanceof e){if(n.loose===!!i.loose)return n;n=n.value}n=n.trim().split(/\s+/).join(" "),o("comparator",n,i),this.options=i,this.loose=!!i.loose,this.parse(n),this.semver===t?this.value="":this.value=this.operator+this.semver.version,o("comp",this)}parse(e){const r=this.options.loose?n[i.COMPARATORLOOSE]:n[i.COMPARATOR],s=e.match(r);if(!s)throw new TypeError(`Invalid comparator: ${e}`);this.operator=void 0!==s[1]?s[1]:"","="===this.operator&&(this.operator=""),s[2]?this.semver=new a(s[2],this.options.loose):this.semver=t}toString(){return this.value}test(e){if(o("Comparator.test",e,this.options.loose),this.semver===t||e===t)return!0;if("string"==typeof e)try{e=new a(e,this.options)}catch(t){return!1}return s(e,this.operator,this.semver,this.options)}intersects(t,n){if(!(t instanceof e))throw new TypeError("a Comparator is required");return""===this.operator?""===this.value||new l(t.value,n).test(this.value):""===t.operator?""===t.value||new l(this.value,n).test(t.semver):!((n=r(n)).includePrerelease&&("<0.0.0-0"===this.value||"<0.0.0-0"===t.value)||!n.includePrerelease&&(this.value.startsWith("<0.0.0")||t.value.startsWith("<0.0.0"))||(!this.operator.startsWith(">")||!t.operator.startsWith(">"))&&(!this.operator.startsWith("<")||!t.operator.startsWith("<"))&&(this.semver.version!==t.semver.version||!this.operator.includes("=")||!t.operator.includes("="))&&!(s(this.semver,"<",t.semver,n)&&this.operator.startsWith(">")&&t.operator.startsWith("<"))&&!(s(this.semver,">",t.semver,n)&&this.operator.startsWith("<")&&t.operator.startsWith(">")))}}Yt=e;const r=Ie(),{safeRe:n,t:i}=be(),s=Fe(),o=we(),a=Se(),l=Ge();return Yt}function Me(){if(Jt)return zt;Jt=1;const t=Ge();return zt=(e,r,n)=>{try{r=new t(r,n)}catch(t){return!1}return r.test(e)},zt}function je(){if(ae)return oe;ae=1;const t=Ge();return oe=(e,r)=>{try{return new t(e,r).range||"*"}catch(t){return null}},oe}function Ue(){if(he)return le;he=1;const t=Se(),e=Ve(),{ANY:r}=e,n=Ge(),i=Me(),s=Le(),o=xe(),a=De(),l=He();return le=(h,c,u,p)=>{let m,d,f,g,E;switch(h=new t(h,p),c=new n(c,p),u){case">":m=s,d=a,f=o,g=">",E=">=";break;case"<":m=o,d=l,f=s,g="<",E="<=";break;default:throw new TypeError('Must provide a hilo val of "<" or ">"')}if(i(h,c,p))return!1;for(let t=0;t<c.set.length;++t){const n=c.set[t];let i=null,s=null;if(n.forEach(t=>{t.semver===r&&(t=new e(">=0.0.0")),i=i||t,s=s||t,m(t.semver,i.semver,p)?i=t:f(t.semver,s.semver,p)&&(s=t)}),i.operator===g||i.operator===E)return!1;if((!s.operator||s.operator===g)&&d(h,s.semver))return!1;if(s.operator===E&&f(h,s.semver))return!1}return!0},le}var We=function(){if(Ae)return Oe;Ae=1;const t=be(),e=Ce(),r=Se(),n=ye(),i=Re(),s=function(){if(Q)return Z;Q=1;const t=Re();return Z=(e,r)=>{const n=t(e,r);return n?n.version:null}}(),o=function(){if(et)return tt;et=1;const t=Re();return tt=(e,r)=>{const n=t(e.trim().replace(/^[=v]+/,""),r);return n?n.version:null}}(),a=function(){if(nt)return rt;nt=1;const t=Se();return rt=(e,r,n,i,s)=>{"string"==typeof n&&(s=i,i=n,n=void 0);try{return new t(e instanceof t?e.version:e,n).inc(r,i,s).version}catch(t){return null}}}(),l=function(){if(st)return it;st=1;const t=Re();return it=(e,r)=>{const n=t(e,null,!0),i=t(r,null,!0),s=n.compare(i);if(0===s)return null;const o=s>0,a=o?n:i,l=o?i:n,h=!!a.prerelease.length;if(l.prerelease.length&&!h){if(!l.patch&&!l.minor)return"major";if(0===l.compareMain(a))return l.minor&&!l.patch?"minor":"patch"}const c=h?"pre":"";return n.major!==i.major?c+"major":n.minor!==i.minor?c+"minor":n.patch!==i.patch?c+"patch":"prerelease"}}(),h=function(){if(at)return ot;at=1;const t=Se();return ot=(e,r)=>new t(e,r).major}(),c=function(){if(ht)return lt;ht=1;const t=Se();return lt=(e,r)=>new t(e,r).minor}(),u=function(){if(ut)return ct;ut=1;const t=Se();return ct=(e,r)=>new t(e,r).patch}(),p=function(){if(mt)return pt;mt=1;const t=Re();return pt=(e,r)=>{const n=t(e,r);return n&&n.prerelease.length?n.prerelease:null}}(),m=Te(),d=function(){if(Et)return gt;Et=1;const t=Te();return gt=(e,r,n)=>t(r,e,n)}(),f=function(){if(vt)return _t;vt=1;const t=Te();return _t=(e,r)=>t(e,r,!0)}(),g=Ne(),E=function(){if(Ct)return $t;Ct=1;const t=Ne();return $t=(e,r)=>e.sort((e,n)=>t(e,n,r))}(),_=function(){if(bt)return wt;bt=1;const t=Ne();return wt=(e,r)=>e.sort((e,n)=>t(n,e,r))}(),v=Le(),O=xe(),A=Pe(),$=ke(),C=He(),w=De(),b=Fe(),I=function(){if(Mt)return Vt;Mt=1;const t=Se(),e=Re(),{safeRe:r,t:n}=be();return Vt=(i,s)=>{if(i instanceof t)return i;if("number"==typeof i&&(i=String(i)),"string"!=typeof i)return null;let o=null;if((s=s||{}).rtl){const t=s.includePrerelease?r[n.COERCERTLFULL]:r[n.COERCERTL];let e;for(;(e=t.exec(i))&&(!o||o.index+o[0].length!==i.length);)o&&e.index+e[0].length===o.index+o[0].length||(o=e),t.lastIndex=e.index+e[1].length+e[2].length;t.lastIndex=-1}else o=i.match(s.includePrerelease?r[n.COERCEFULL]:r[n.COERCE]);if(null===o)return null;const a=o[2],l=o[3]||"0",h=o[4]||"0",c=s.includePrerelease&&o[5]?`-${o[5]}`:"",u=s.includePrerelease&&o[6]?`+${o[6]}`:"";return e(`${a}.${l}.${h}${c}${u}`,s)}}(),y=function(){if(Ut)return jt;Ut=1;const t=Re(),e=Ce(),r=Se(),n=t=>t.startsWith("pre");return jt=(i,s,o)=>{if(!e.RELEASE_TYPES.includes(s))return null;const a=((e,n)=>{const i=e instanceof r?e.version:e;return t(i,n)})(i,o);return a&&((t,e)=>{if(n(e))return t.version;switch(t.prerelease=[],e){case"major":t.minor=0,t.patch=0;break;case"minor":t.patch=0}return t.format()})(a,s)}}(),S=Ve(),R=Ge(),T=Me(),N=function(){if(Qt)return Zt;Qt=1;const t=Ge();return Zt=(e,r)=>new t(e,r).set.map(t=>t.map(t=>t.value).join(" ").trim().split(" ")),Zt}(),L=function(){if(ee)return te;ee=1;const t=Se(),e=Ge();return te=(r,n,i)=>{let s=null,o=null,a=null;try{a=new e(n,i)}catch(t){return null}return r.forEach(e=>{a.test(e)&&(s&&-1!==o.compare(e)||(s=e,o=new t(s,i)))}),s},te}(),x=function(){if(ne)return re;ne=1;const t=Se(),e=Ge();return re=(r,n,i)=>{let s=null,o=null,a=null;try{a=new e(n,i)}catch(t){return null}return r.forEach(e=>{a.test(e)&&(s&&1!==o.compare(e)||(s=e,o=new t(s,i)))}),s},re}(),P=function(){if(se)return ie;se=1;const t=Se(),e=Ge(),r=Le();return ie=(n,i)=>{n=new e(n,i);let s=new t("0.0.0");if(n.test(s))return s;if(s=new t("0.0.0-0"),n.test(s))return s;s=null;for(let e=0;e<n.set.length;++e){const i=n.set[e];let o=null;i.forEach(e=>{const n=new t(e.semver.version);switch(e.operator){case">":0===n.prerelease.length?n.patch++:n.prerelease.push(0),n.raw=n.format();case"":case">=":o&&!r(n,o)||(o=n);break;case"<":case"<=":break;default:throw new Error(`Unexpected operation: ${e.operator}`)}}),!o||s&&!r(s,o)||(s=o)}return s&&n.test(s)?s:null},ie}(),k=je(),H=Ue(),D=function(){if(ue)return ce;ue=1;const t=Ue();return ce=(e,r,n)=>t(e,r,">",n),ce}(),F=function(){if(me)return pe;me=1;const t=Ue();return pe=(e,r,n)=>t(e,r,"<",n),pe}(),G=function(){if(fe)return de;fe=1;const t=Ge();return de=(e,r,n)=>(e=new t(e,n),r=new t(r,n),e.intersects(r,n))}(),V=function(){if(Ee)return ge;Ee=1;const t=Me(),e=Te();return ge=(r,n,i)=>{const s=[];let o=null,a=null;const l=r.sort((t,r)=>e(t,r,i));for(const e of l)t(e,n,i)?(a=e,o||(o=e)):(a&&s.push([o,a]),a=null,o=null);o&&s.push([o,null]);const h=[];for(const[t,e]of s)t===e?h.push(t):e||t!==l[0]?e?t===l[0]?h.push(`<=${e}`):h.push(`${t} - ${e}`):h.push(`>=${t}`):h.push("*");const c=h.join(" || "),u="string"==typeof n.raw?n.raw:String(n);return c.length<u.length?c:n},ge}(),M=function(){if(ve)return _e;ve=1;const t=Ge(),e=Ve(),{ANY:r}=e,n=Me(),i=Te(),s=[new e(">=0.0.0-0")],o=[new e(">=0.0.0")],a=(t,e,a)=>{if(t===e)return!0;if(1===t.length&&t[0].semver===r){if(1===e.length&&e[0].semver===r)return!0;t=a.includePrerelease?s:o}if(1===e.length&&e[0].semver===r){if(a.includePrerelease)return!0;e=o}const c=new Set;let u,p,m,d,f,g,E;for(const e of t)">"===e.operator||">="===e.operator?u=l(u,e,a):"<"===e.operator||"<="===e.operator?p=h(p,e,a):c.add(e.semver);if(c.size>1)return null;if(u&&p){if(m=i(u.semver,p.semver,a),m>0)return null;if(0===m&&(">="!==u.operator||"<="!==p.operator))return null}for(const t of c){if(u&&!n(t,String(u),a))return null;if(p&&!n(t,String(p),a))return null;for(const r of e)if(!n(t,String(r),a))return!1;return!0}let _=!(!p||a.includePrerelease||!p.semver.prerelease.length)&&p.semver,v=!(!u||a.includePrerelease||!u.semver.prerelease.length)&&u.semver;_&&1===_.prerelease.length&&"<"===p.operator&&0===_.prerelease[0]&&(_=!1);for(const t of e){if(E=E||">"===t.operator||">="===t.operator,g=g||"<"===t.operator||"<="===t.operator,u)if(v&&t.semver.prerelease&&t.semver.prerelease.length&&t.semver.major===v.major&&t.semver.minor===v.minor&&t.semver.patch===v.patch&&(v=!1),">"===t.operator||">="===t.operator){if(d=l(u,t,a),d===t&&d!==u)return!1}else if(">="===u.operator&&!t.test(u.semver))return!1;if(p)if(_&&t.semver.prerelease&&t.semver.prerelease.length&&t.semver.major===_.major&&t.semver.minor===_.minor&&t.semver.patch===_.patch&&(_=!1),"<"===t.operator||"<="===t.operator){if(f=h(p,t,a),f===t&&f!==p)return!1}else if("<="===p.operator&&!t.test(p.semver))return!1;if(!t.operator&&(p||u)&&0!==m)return!1}return!(u&&g&&!p&&0!==m||p&&E&&!u&&0!==m||v||_)},l=(t,e,r)=>{if(!t)return e;const n=i(t.semver,e.semver,r);return n>0?t:n<0||">"===e.operator&&">="===t.operator?e:t},h=(t,e,r)=>{if(!t)return e;const n=i(t.semver,e.semver,r);return n<0?t:n>0||"<"===e.operator&&"<="===t.operator?e:t};return _e=(e,r,n={})=>{if(e===r)return!0;e=new t(e,n),r=new t(r,n);let i=!1;t:for(const t of e.set){for(const e of r.set){const r=a(t,e,n);if(i=i||null!==r,r)continue t}if(i)return!1}return!0}}();return Oe={parse:i,valid:s,clean:o,inc:a,diff:l,major:h,minor:c,patch:u,prerelease:p,compare:m,rcompare:d,compareLoose:f,compareBuild:g,sort:E,rsort:_,gt:v,lt:O,eq:A,neq:$,gte:C,lte:w,cmp:b,coerce:I,truncate:y,Comparator:S,Range:R,satisfies:T,toComparators:N,maxSatisfying:L,minSatisfying:x,minVersion:P,validRange:k,outside:H,gtr:D,ltr:F,intersects:G,simplifyRange:V,subset:M,SemVer:r,re:t.re,src:t.src,tokens:t.t,SEMVER_SPEC_VERSION:e.SEMVER_SPEC_VERSION,RELEASE_TYPES:e.RELEASE_TYPES,compareIdentifiers:n.compareIdentifiers,rcompareIdentifiers:n.rcompareIdentifiers}}(),Xe=o(We);const qe=r.resolve(__dirname,".."),Be=JSON.parse(n.readFileSync(r.join(qe,"package.json"),"utf8")),Ye=process.env.TASK_HANDOFF_NPM_COMMAND||"npm",Ke=function(t){const e=Xe.prerelease(t)?.[0];return"alpha"===e||"beta"===e?e:"stable"}(Be.version);function ze(t,r,n={}){const i=e.spawnSync(t,r,{encoding:"utf8",...n});if(0!==i.status){const e=[i.stdout,i.stderr].filter(Boolean).join("\n").trim();throw new Error(`${t} ${r.join(" ")} failed${e?`:\n${e}`:""}`)}return String(i.stdout||"").trim()}function Je(t){const e={};if(!n.existsSync(t))return e;for(const r of n.readFileSync(t,"utf8").split(/\r?\n/)){if(!r||r.startsWith("#"))continue;const t=r.indexOf("=");t>0&&(e[r.slice(0,t)]=r.slice(t+1))}return e}function Ze(){const t="/etc/systemd/system/task-handoff-node-agent.service";return n.existsSync(t)&&n.readFileSync(t,"utf8").match(/^User=(.+)$/m)?.[1]||"root"}function Qe(){const t=Je("/etc/task-handoff/control-plane.env"),e=Je("/etc/task-handoff/node-agent.env");return["--service-user",Ze(),"--control-plane-data-dir",t.TASK_HANDOFF_CONTROL_PLANE_DATA_DIR||"/var/lib/task-handoff/control-plane","--node-agent-data-dir",e.TASK_HANDOFF_NODE_AGENT_DATA_DIR||"/var/lib/task-handoff/node-agent","--control-plane-host",t.TASK_HANDOFF_CONTROL_PLANE_HOST||"0.0.0.0","--control-plane-port",t.TASK_HANDOFF_CONTROL_PLANE_PORT||"8081","--node-agent-host",e.TASK_HANDOFF_NODE_AGENT_HOST||"127.0.0.1","--node-agent-port",e.TASK_HANDOFF_NODE_AGENT_PORT||"8091","--node-agent-ipc-path",e.TASK_HANDOFF_NODE_AGENT_IPC_PATH||"/run/task-handoff/node-agent.sock","--auth-mode",t.TASK_HANDOFF_CONTROL_PLANE_AUTH_MODE||"password"]}function tr(t){const r=e.spawnSync("systemctl",["is-active",t],{encoding:"utf8"});return String(r.stdout||"unknown").trim()||"unknown"}async function er(t){or();const e=Qe(),r=e[e.indexOf("--node-agent-ipc-path")+1],n=Number(e[e.indexOf("--control-plane-port")+1]);if("stop"===t)return ze("systemctl",["stop","task-handoff-control-plane.service"],{stdio:"inherit"}),ze("systemctl",["stop","task-handoff-node-agent.service"],{stdio:"inherit"}),void console.log("Stopped TaskHandoff server services.");ze("systemctl",[t,"task-handoff-node-agent.service"],{stdio:"inherit"}),ar(r),ze("systemctl",[t,"task-handoff-control-plane.service"],{stdio:"inherit"}),await lr(n),console.log(("start"===t?"Started":"Restarted")+" TaskHandoff server services.")}function rr(t,e){return e||("stable"===t?"latest":t)}function nr(t){if((e=t).trim()!==e||/^[v=]/.test(e)||null===Xe.valid(e))throw new x("must be an exact semantic version");var e;return t}function ir(){return new D("--channel <channel>","stable, beta, or alpha").choices(["stable","beta","alpha"]).default(Ke).conflicts("to")}function sr(t,e){const r=["view",`@task-handoff/server@${t}`,"version","--json"];e&&r.push("--registry",e);const n=JSON.parse(ze(Ye,r));if("string"!=typeof n)throw new Error(`npm target ${t} did not resolve to one version.`);return n}function or(){if("function"==typeof process.getuid&&0!==process.getuid())throw new Error("Run this command as root so system packages and services can be changed.")}function ar(t,e=3e4){const r=Date.now()+e;for(;Date.now()<r;){try{if(n.statSync(t).isSocket())return}catch{}Atomics.wait(new Int32Array(new SharedArrayBuffer(4)),0,0,250)}throw new Error(`Node agent socket was not ready after ${e}ms: ${t}`)}function lr(t,e=3e4){return new Promise((r,n)=>{const i=Date.now()+e,o=()=>{const e=s.get({host:"127.0.0.1",port:t,path:"/api/health",timeout:1e3},t=>{if(t.resume(),200===t.statusCode)return r();a()});e.on("timeout",()=>e.destroy()),e.on("error",a)},a=()=>Date.now()>=i?n(new Error(`Control plane was not healthy on port ${t} after ${e}ms.`)):setTimeout(o,250);o()})}function hr(t){return[["--service-user",t.serviceUser],["--control-plane-data-dir",t.controlPlaneDataDir],["--node-agent-data-dir",t.nodeAgentDataDir],["--control-plane-host",t.controlPlaneHost],["--control-plane-port",t.controlPlanePort],["--node-agent-host",t.nodeAgentHost],["--node-agent-port",t.nodeAgentPort],["--node-agent-ipc-path",t.nodeAgentIpcPath],["--auth-mode",t.authMode],["--static-dir",t.staticDir]].flatMap(([t,e])=>void 0===e?[]:[t,e])}(async function(){const t=(new k).name("task-handoff").description("Manage a TaskHandoff server and run its installed runtimes.").version(Be.version).showSuggestionAfterError();t.command("control-plane","Run the installed control-plane runtime.",{executableFile:"task-handoff-control-plane"}),t.command("node-agent","Run the installed node-agent runtime.",{executableFile:"task-handoff-node-agent"}),t.command("controlled-instance","Run the installed controlled-instance runtime.",{executableFile:"task-handoff-controlled-instance"}),t.command("install").description("Install or regenerate the server systemd services.").option("--service-user <user>").option("--control-plane-data-dir <path>").option("--node-agent-data-dir <path>").option("--control-plane-host <host>").option("--control-plane-port <port>").option("--node-agent-host <host>").option("--node-agent-port <port>").option("--node-agent-ipc-path <path>").option("--auth-mode <mode>").option("--static-dir <path>").action(t=>{or(),ze(process.execPath,[r.join(qe,"bin","task-handoff-install-server"),...hr(t)],{stdio:"inherit"})}),t.command("status").description("Show the installed version and service state.").action(()=>{console.log(`Package: @task-handoff/server ${Be.version}`),console.log(`Node agent: ${tr("task-handoff-node-agent.service")}`),console.log(`Control plane: ${tr("task-handoff-control-plane.service")}`)}),t.command("start").description("Start the node agent and control plane services.").action(()=>er("start")),t.command("stop").description("Stop the control plane and node agent services.").action(()=>er("stop")),t.command("restart").description("Restart the node agent and control plane services safely.").action(()=>er("restart")),t.command("check").description("Check npm for an available server version.").addOption(ir()).option("--registry <url>").action(t=>{const e=rr(t.channel),r=sr(e,t.registry);console.log(`Installed: ${Be.version}`),console.log(`Available (${t.channel} channel, npm ${e}): ${r}`),console.log(r===Be.version?"Up to date.":`Update available: task-handoff update --to ${r}`)}),t.command("update").description("Update the server package set and restart services safely.").addOption(ir()).option("--to <version>","exact semantic version",nr).option("--registry <url>").option("--force").action(async t=>{or();const e=rr(t.channel,t.to),i=e===Be.version?Be.version:sr(e,t.registry);if(i===Be.version&&!t.force)return void console.log(`@task-handoff/server ${Be.version} is already installed.`);const s=function(){const t="/run/task-handoff-server-update.lock";try{n.mkdirSync(t)}catch(t){if("EEXIST"===t?.code)throw new Error("Another TaskHandoff server update is already running.");throw t}return()=>n.rmSync(t,{recursive:!0,force:!0})}();try{const e=function(){let t=qe;for(;t!==r.dirname(t);){if("node_modules"===r.basename(t)&&"lib"===r.basename(r.dirname(t)))return r.dirname(r.dirname(t));t=r.dirname(t)}throw new Error(`Cannot determine the npm global prefix from ${qe}.`)}(),n=Qe(),s=n[n.indexOf("--node-agent-ipc-path")+1],o=Number(n[n.indexOf("--control-plane-port")+1]),a=["install","--global","--prefix",e,`@task-handoff/server@${i}`];t.registry&&a.push("--registry",t.registry),console.log(`Updating @task-handoff/server ${Be.version} -> ${i}`),ze(Ye,a,{stdio:"inherit"}),ze(r.join(e,"bin","task-handoff"),["install",...n],{stdio:"inherit"}),ze("systemctl",["restart","task-handoff-node-agent.service"]),ar(s),ze("systemctl",["restart","task-handoff-control-plane.service"]),await lr(o),console.log(`Updated TaskHandoff server to ${i}.`)}catch(t){throw console.error(`Update failed. To reinstall the previous version, run: npm install -g @task-handoff/server@${Be.version}`),t}finally{s()}}),await t.parseAsync(process.argv)})().catch(t=>{console.error(`Error: ${t instanceof Error?t.message:String(t)}`),process.exitCode=1});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@task-handoff/server",
|
|
3
|
-
"version": "0.0.3-alpha.
|
|
3
|
+
"version": "0.0.3-alpha.6",
|
|
4
4
|
"description": "Complete TaskHandoff server package.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -16,9 +16,9 @@
|
|
|
16
16
|
"node": ">=22.22.2"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@task-handoff/control-plane": "0.0.3-alpha.
|
|
20
|
-
"@task-handoff/node-agent": "0.0.3-alpha.
|
|
21
|
-
"@task-handoff/controlled-instance": "0.0.3-alpha.
|
|
19
|
+
"@task-handoff/control-plane": "0.0.3-alpha.6",
|
|
20
|
+
"@task-handoff/node-agent": "0.0.3-alpha.6",
|
|
21
|
+
"@task-handoff/controlled-instance": "0.0.3-alpha.6"
|
|
22
22
|
},
|
|
23
23
|
"publishConfig": {
|
|
24
24
|
"access": "public"
|