forge-terminal 0.3.9 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/README.md +107 -11
  2. package/dist/chunks/{about-credits-NCKQZJMR.js → about-credits-GRSA5RLZ.js} +1 -1
  3. package/dist/chunks/args-VJZHLGIY.js +3 -0
  4. package/dist/chunks/{available-QN6QAGCU.js → available-GYIHVSRX.js} +1 -1
  5. package/dist/chunks/boot-HVIAAJMY.js +3 -0
  6. package/dist/chunks/{catalog-O3V24DK7.js → catalog-YSMT3PXT.js} +1 -1
  7. package/dist/chunks/check-KAR72Y4X.js +3 -0
  8. package/dist/chunks/chunk-3UEQ2OX6.js +3 -0
  9. package/dist/chunks/chunk-5B5XXH22.js +3 -0
  10. package/dist/chunks/chunk-5IS7O673.js +6 -0
  11. package/dist/chunks/chunk-6FUVEO3A.js +78 -0
  12. package/dist/chunks/chunk-6L6C3GJU.js +3 -0
  13. package/dist/chunks/chunk-AAXBN572.js +4 -0
  14. package/dist/chunks/chunk-CKUIRXDS.js +4 -0
  15. package/dist/chunks/chunk-DERIWZAT.js +3 -0
  16. package/dist/chunks/chunk-DOWMSJ6R.js +3 -0
  17. package/dist/chunks/chunk-EEQSUBBL.js +3 -0
  18. package/dist/chunks/chunk-EGIKV2GZ.js +4 -0
  19. package/dist/chunks/{chunk-3GVFOZ7M.js → chunk-EHARO6IS.js} +1 -1
  20. package/dist/chunks/{chunk-ZRP5CWIK.js → chunk-EX7KZBI6.js} +1 -1
  21. package/dist/chunks/chunk-EXLXSKRH.js +3 -0
  22. package/dist/chunks/chunk-FH3R2YYD.js +19 -0
  23. package/dist/chunks/chunk-FHORNIVW.js +3 -0
  24. package/dist/chunks/{chunk-TEO2EUS3.js → chunk-GJ2GZHRI.js} +1 -1
  25. package/dist/chunks/chunk-HZDYZ5RD.js +3 -0
  26. package/dist/chunks/chunk-I63TO22X.js +3 -0
  27. package/dist/chunks/chunk-IGF6ZFTM.js +4 -0
  28. package/dist/chunks/{chunk-MBTGANIR.js → chunk-IWFVEMDN.js} +1 -1
  29. package/dist/chunks/{chunk-SAWVMQAD.js → chunk-JFJ3ZJQL.js} +2 -2
  30. package/dist/chunks/chunk-JSMGNA55.js +3 -0
  31. package/dist/chunks/chunk-KAHWYWNT.js +3 -0
  32. package/dist/chunks/chunk-LDKF7KIZ.js +6 -0
  33. package/dist/chunks/chunk-LNB5D67B.js +3 -0
  34. package/dist/chunks/chunk-M66BUNYO.js +3 -0
  35. package/dist/chunks/chunk-MKVBI37R.js +63 -0
  36. package/dist/chunks/chunk-PSEIJXGT.js +3 -0
  37. package/dist/chunks/chunk-QR6QHTC3.js +3 -0
  38. package/dist/chunks/chunk-SMBK6BTC.js +3 -0
  39. package/dist/chunks/chunk-TDW6KQH6.js +3 -0
  40. package/dist/chunks/chunk-TMQDQLY7.js +21 -0
  41. package/dist/chunks/chunk-VGS5Z5RD.js +66 -0
  42. package/dist/chunks/chunk-YWKMG5WO.js +3 -0
  43. package/dist/chunks/{chunk-I6QBBRCE.js → chunk-YYB3TTGT.js} +1 -1
  44. package/dist/chunks/clip-command-264DPO6I.js +3 -0
  45. package/dist/chunks/colour-4NH6H4HA.js +3 -0
  46. package/dist/chunks/command-I5M275ZV.js +3 -0
  47. package/dist/chunks/config-command-TYNYVUMP.js +3 -0
  48. package/dist/chunks/entry-26YSXWT4.js +6 -0
  49. package/dist/chunks/execute-GSC2NMDW.js +3 -0
  50. package/dist/chunks/extensions-ADGECS5U.js +3 -0
  51. package/dist/chunks/{extensions-command-UGXZIFRI.js → extensions-command-TGOF36YW.js} +1 -1
  52. package/dist/chunks/ffmpeg-PF3VLTHK.js +3 -0
  53. package/dist/chunks/image-J4FT4ACZ.js +3 -0
  54. package/dist/chunks/install-2A5BGKQU.js +3 -0
  55. package/dist/chunks/install-V62EEK54.js +3 -0
  56. package/dist/chunks/launch-KBYCYAZR.js +5 -0
  57. package/dist/chunks/lock-KN7CF4YN.js +3 -0
  58. package/dist/chunks/manager-J7377NNA.js +4 -0
  59. package/dist/chunks/{paths-H2WS22BA.js → paths-5XI5L4KW.js} +1 -1
  60. package/dist/chunks/pdf-compress-U2E3CNXG.js +3 -0
  61. package/dist/chunks/preferences-4VETUGMN.js +3 -0
  62. package/dist/chunks/preset-command-HORY7KZQ.js +3 -0
  63. package/dist/chunks/run-6BK4REXK.js +4 -0
  64. package/dist/chunks/{server-XOMQGAIG.js → server-OAJFUZDM.js} +16 -15
  65. package/dist/chunks/{theme-ZSHECPGW.js → theme-WGCMV4T4.js} +1 -1
  66. package/dist/chunks/transcribe-command-YUSBCQEQ.js +3 -0
  67. package/dist/chunks/update-command-GMBG7BK6.js +3 -0
  68. package/dist/chunks/update-note-6YGNGYUB.js +3 -0
  69. package/dist/chunks/watch-command-HOG4TM3X.js +3 -0
  70. package/dist/helpers/forge-transcribe +0 -0
  71. package/dist/index.js +15 -63
  72. package/package.json +23 -1
  73. package/skills/forge/SKILL.md +7 -0
  74. package/dist/chunks/boot-ZJLZZHA7.js +0 -3
  75. package/dist/chunks/check-BRP6EKSA.js +0 -3
  76. package/dist/chunks/chunk-32VJ2RDH.js +0 -3
  77. package/dist/chunks/chunk-3V4DKIWP.js +0 -66
  78. package/dist/chunks/chunk-4QQEJ6YG.js +0 -3
  79. package/dist/chunks/chunk-C7YNQXXO.js +0 -3
  80. package/dist/chunks/chunk-DVJAGA5L.js +0 -19
  81. package/dist/chunks/chunk-F4ZPFXWD.js +0 -4
  82. package/dist/chunks/chunk-GGBNT4WI.js +0 -3
  83. package/dist/chunks/chunk-GNLE6JXL.js +0 -3
  84. package/dist/chunks/chunk-H2IUSPAK.js +0 -4
  85. package/dist/chunks/chunk-J3VS5AUZ.js +0 -4
  86. package/dist/chunks/chunk-LW2QEXDT.js +0 -3
  87. package/dist/chunks/chunk-MMRDELHW.js +0 -3
  88. package/dist/chunks/chunk-X54KIHCN.js +0 -4
  89. package/dist/chunks/chunk-YILLB45O.js +0 -3
  90. package/dist/chunks/colour-54Z3FBNN.js +0 -3
  91. package/dist/chunks/config-command-TXQUYFA6.js +0 -3
  92. package/dist/chunks/execute-4OBEIICQ.js +0 -3
  93. package/dist/chunks/extensions-7RTIGFIG.js +0 -3
  94. package/dist/chunks/image-F5D73JPQ.js +0 -3
  95. package/dist/chunks/install-YG43OJ7P.js +0 -3
  96. package/dist/chunks/launch-2I52TGLD.js +0 -4
  97. package/dist/chunks/lock-6KTGUFBY.js +0 -3
  98. package/dist/chunks/manager-XN7WNMEW.js +0 -4
  99. package/dist/chunks/pdf-compress-IMRFBLZF.js +0 -3
  100. package/dist/chunks/preferences-YL6SRNZR.js +0 -3
  101. package/dist/chunks/restart-RO6DM5N3.js +0 -3
  102. package/dist/chunks/run-XQYPVWFI.js +0 -4
  103. package/dist/chunks/update-command-6VNVMAYO.js +0 -3
  104. package/dist/chunks/update-note-MJPR4GHH.js +0 -3
@@ -0,0 +1,63 @@
1
+ import { createRequire as __forgeCreateRequire } from 'node:module';
2
+ const require = __forgeCreateRequire(import.meta.url);
3
+ import{a as B}from"./chunk-U5TEGDGH.js";import{a as K,b as Y}from"./chunk-HZDYZ5RD.js";import{h as W}from"./chunk-QR6QHTC3.js";import{b as J}from"./chunk-EEQSUBBL.js";import{a as D}from"./chunk-YYB3TTGT.js";import{l as L,n as U}from"./chunk-KAHWYWNT.js";import{F as d,I as H}from"./chunk-3UEQ2OX6.js";import{d as R}from"./chunk-J7FLFHQJ.js";import{a as X}from"./chunk-EGIKV2GZ.js";import{b as z}from"./chunk-M66BUNYO.js";var x=class extends Error{constructor(e,t,n){super(n),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name,this.code=t,this.exitCode=e,this.nestedError=void 0}},v=class extends x{constructor(e){super(1,"commander.invalidArgument",e),Error.captureStackTrace(this,this.constructor),this.name=this.constructor.name}};var E=class{constructor(e,t){switch(this.description=t||"",this.variadic=!1,this.parseArg=void 0,this.defaultValue=void 0,this.defaultValueDescription=void 0,this.argChoices=void 0,e[0]){case"<":this.required=!0,this._name=e.slice(1,-1);break;case"[":this.required=!1,this._name=e.slice(1,-1);break;default:this.required=!0,this._name=e;break}this._name.endsWith("...")&&(this.variadic=!0,this._name=this._name.slice(0,-3))}name(){return this._name}_collectValue(e,t){return t===this.defaultValue||!Array.isArray(t)?[e]:(t.push(e),t)}default(e,t){return this.defaultValue=e,this.defaultValueDescription=t,this}argParser(e){return this.parseArg=e,this}choices(e){return this.argChoices=e.slice(),this.parseArg=(t,n)=>{if(!this.argChoices.includes(t))throw new v(`Allowed choices are ${this.argChoices.join(", ")}.`);return this.variadic?this._collectValue(t,n):t},this}argRequired(){return this.required=!0,this}argOptional(){return this.required=!1,this}};function V(s){let e=s.name()+(s.variadic===!0?"...":"");return s.required?"<"+e+">":"["+e+"]"}import{EventEmitter as ae}from"node:events";import G from"node:child_process";import C from"node:path";import F from"node:fs";import m from"node:process";import{stripVTControlCharacters as ue}from"node:util";import{stripVTControlCharacters as re}from"node:util";var T=class{constructor(){this.helpWidth=void 0,this.minWidthToWrap=40,this.sortSubcommands=!1,this.sortOptions=!1,this.showGlobalOptions=!1}prepareContext(e){this.helpWidth=this.helpWidth??e.helpWidth??80}visibleCommands(e){let t=e.commands.filter(i=>!i._hidden),n=e._getHelpCommand();return n&&!n._hidden&&t.push(n),this.sortSubcommands&&t.sort((i,r)=>i.name().localeCompare(r.name())),t}compareOptions(e,t){let n=i=>i.short?i.short.replace(/^-/,""):i.long.replace(/^--/,"");return n(e).localeCompare(n(t))}visibleOptions(e){let t=e.options.filter(i=>!i.hidden),n=e._getHelpOption();if(n&&!n.hidden){let i=n.short&&e._findOption(n.short),r=n.long&&e._findOption(n.long);!i&&!r?t.push(n):n.long&&!r?t.push(e.createOption(n.long,n.description)):n.short&&!i&&t.push(e.createOption(n.short,n.description))}return this.sortOptions&&t.sort(this.compareOptions),t}visibleGlobalOptions(e){if(!this.showGlobalOptions)return[];let t=[];for(let n=e.parent;n;n=n.parent){let i=n.options.filter(r=>!r.hidden);t.push(...i)}return this.sortOptions&&t.sort(this.compareOptions),t}visibleArguments(e){return e._argsDescription&&e.registeredArguments.forEach(t=>{t.description=t.description||e._argsDescription[t.name()]||""}),e.registeredArguments.find(t=>t.description)?e.registeredArguments:[]}subcommandTerm(e){let t=e.registeredArguments.map(n=>V(n)).join(" ");return e._name+(e._aliases[0]?"|"+e._aliases[0]:"")+(e.options.length?" [options]":"")+(t?" "+t:"")}optionTerm(e){return e.flags}argumentTerm(e){return e.name()}longestSubcommandTermLength(e,t){return t.visibleCommands(e).reduce((n,i)=>Math.max(n,this.displayWidth(t.styleSubcommandTerm(t.subcommandTerm(i)))),0)}longestOptionTermLength(e,t){return t.visibleOptions(e).reduce((n,i)=>Math.max(n,this.displayWidth(t.styleOptionTerm(t.optionTerm(i)))),0)}longestGlobalOptionTermLength(e,t){return t.visibleGlobalOptions(e).reduce((n,i)=>Math.max(n,this.displayWidth(t.styleOptionTerm(t.optionTerm(i)))),0)}longestArgumentTermLength(e,t){return t.visibleArguments(e).reduce((n,i)=>Math.max(n,this.displayWidth(t.styleArgumentTerm(t.argumentTerm(i)))),0)}commandUsage(e){let t=e._name;e._aliases[0]&&(t=t+"|"+e._aliases[0]);let n="";for(let i=e.parent;i;i=i.parent)n=i.name()+" "+n;return n+t+" "+e.usage()}commandDescription(e){return e.description()}subcommandDescription(e){return e.summary()||e.description()}optionDescription(e){let t=[];if(e.argChoices&&t.push(`choices: ${e.argChoices.map(n=>JSON.stringify(n)).join(", ")}`),e.defaultValue!==void 0&&(e.required||e.optional||e.isBoolean()&&typeof e.defaultValue=="boolean")&&t.push(`default: ${e.defaultValueDescription||JSON.stringify(e.defaultValue)}`),e.presetArg!==void 0&&e.optional&&t.push(`preset: ${JSON.stringify(e.presetArg)}`),e.envVar!==void 0&&t.push(`env: ${e.envVar}`),t.length>0){let n=`(${t.join(", ")})`;return e.description?`${e.description} ${n}`:n}return e.description}argumentDescription(e){let t=[];if(e.argChoices&&t.push(`choices: ${e.argChoices.map(n=>JSON.stringify(n)).join(", ")}`),e.defaultValue!==void 0&&t.push(`default: ${e.defaultValueDescription||JSON.stringify(e.defaultValue)}`),t.length>0){let n=`(${t.join(", ")})`;return e.description?`${e.description} ${n}`:n}return e.description}formatItemList(e,t,n){return t.length===0?[]:[n.styleTitle(e),...t,""]}groupItems(e,t,n){let i=new Map;return e.forEach(r=>{let o=n(r);i.has(o)||i.set(o,[])}),t.forEach(r=>{let o=n(r);i.has(o)||i.set(o,[]),i.get(o).push(r)}),i}formatHelp(e,t){let n=t.padWidth(e,t),i=t.helpWidth??80;function r(c,p){return t.formatItem(c,n,p,t)}let o=[`${t.styleTitle("Usage:")} ${t.styleUsage(t.commandUsage(e))}`,""],u=t.commandDescription(e);u.length>0&&(o=o.concat([t.boxWrap(t.styleCommandDescription(u),i),""]));let l=t.visibleArguments(e).map(c=>r(t.styleArgumentTerm(t.argumentTerm(c)),t.styleArgumentDescription(t.argumentDescription(c))));if(o=o.concat(this.formatItemList("Arguments:",l,t)),this.groupItems(e.options,t.visibleOptions(e),c=>c.helpGroupHeading??"Options:").forEach((c,p)=>{let O=c.map(_=>r(t.styleOptionTerm(t.optionTerm(_)),t.styleOptionDescription(t.optionDescription(_))));o=o.concat(this.formatItemList(p,O,t))}),t.showGlobalOptions){let c=t.visibleGlobalOptions(e).map(p=>r(t.styleOptionTerm(t.optionTerm(p)),t.styleOptionDescription(t.optionDescription(p))));o=o.concat(this.formatItemList("Global Options:",c,t))}return this.groupItems(e.commands,t.visibleCommands(e),c=>c.helpGroup()||"Commands:").forEach((c,p)=>{let O=c.map(_=>r(t.styleSubcommandTerm(t.subcommandTerm(_)),t.styleSubcommandDescription(t.subcommandDescription(_))));o=o.concat(this.formatItemList(p,O,t))}),o.join(`
4
+ `)}displayWidth(e){return re(e).length}styleTitle(e){return e}styleUsage(e){return e.split(" ").map(t=>t==="[options]"?this.styleOptionText(t):t==="[command]"?this.styleSubcommandText(t):t[0]==="["||t[0]==="<"?this.styleArgumentText(t):this.styleCommandText(t)).join(" ")}styleCommandDescription(e){return this.styleDescriptionText(e)}styleOptionDescription(e){return this.styleDescriptionText(e)}styleSubcommandDescription(e){return this.styleDescriptionText(e)}styleArgumentDescription(e){return this.styleDescriptionText(e)}styleDescriptionText(e){return e}styleOptionTerm(e){return this.styleOptionText(e)}styleSubcommandTerm(e){return e.split(" ").map(t=>t==="[options]"?this.styleOptionText(t):t[0]==="["||t[0]==="<"?this.styleArgumentText(t):this.styleSubcommandText(t)).join(" ")}styleArgumentTerm(e){return this.styleArgumentText(e)}styleOptionText(e){return e}styleArgumentText(e){return e}styleSubcommandText(e){return e}styleCommandText(e){return e}padWidth(e,t){return Math.max(t.longestOptionTermLength(e,t),t.longestGlobalOptionTermLength(e,t),t.longestSubcommandTermLength(e,t),t.longestArgumentTermLength(e,t))}preformatted(e){return/\n[^\S\r\n]/.test(e)}formatItem(e,t,n,i){let o=" ".repeat(2);if(!n)return o+e;let u=e.padEnd(t+e.length-i.displayWidth(e)),l=2,a=(this.helpWidth??80)-t-l-2,c;return a<this.minWidthToWrap||i.preformatted(n)?c=n:c=i.boxWrap(n,a).replace(/\n/g,`
5
+ `+" ".repeat(t+l)),o+u+" ".repeat(l)+c.replace(/\n/g,`
6
+ ${o}`)}boxWrap(e,t){if(t<this.minWidthToWrap)return e;let n=e.split(/\r\n|\n/),i=/[\s]*[^\s]+/g,r=[];return n.forEach(o=>{let u=o.match(i);if(u===null){r.push("");return}let l=[u.shift()],h=this.displayWidth(l[0]);u.forEach(a=>{let c=this.displayWidth(a);if(h+c<=t){l.push(a),h+=c;return}r.push(l.join(""));let p=a.trimStart();l=[p],h=this.displayWidth(p)}),r.push(l.join(""))}),r.join(`
7
+ `)}};var A=class{constructor(e,t){this.flags=e,this.description=t||"",this.required=e.includes("<"),this.optional=e.includes("["),this.variadic=/\w\.\.\.[>\]]$/.test(e),this.mandatory=!1;let n=oe(e);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(e,t){return this.defaultValue=e,this.defaultValueDescription=t,this}preset(e){return this.presetArg=e,this}conflicts(e){return this.conflictsWith=this.conflictsWith.concat(e),this}implies(e){let t=e;return typeof e=="string"&&(t={[e]:!0}),this.implied=Object.assign(this.implied||{},t),this}env(e){return this.envVar=e,this}argParser(e){return this.parseArg=e,this}makeOptionMandatory(e=!0){return this.mandatory=!!e,this}hideHelp(e=!0){return this.hidden=!!e,this}_collectValue(e,t){return t===this.defaultValue||!Array.isArray(t)?[e]:(t.push(e),t)}choices(e){return this.argChoices=e.slice(),this.parseArg=(t,n)=>{if(!this.argChoices.includes(t))throw new v(`Allowed choices are ${this.argChoices.join(", ")}.`);return this.variadic?this._collectValue(t,n):t},this}name(){return this.long?this.long.replace(/^--/,""):this.short.replace(/^-/,"")}attributeName(){return this.negate?Q(this.name().replace(/^no-/,"")):Q(this.name())}helpGroup(e){return this.helpGroupHeading=e,this}is(e){return this.short===e||this.long===e}isBoolean(){return!this.required&&!this.optional&&!this.negate}},N=class{constructor(e){this.positiveOptions=new Map,this.negativeOptions=new Map,this.dualOptions=new Set,e.forEach(t=>{t.negate?this.negativeOptions.set(t.attributeName(),t):this.positiveOptions.set(t.attributeName(),t)}),this.negativeOptions.forEach((t,n)=>{this.positiveOptions.has(n)&&this.dualOptions.add(n)})}valueFromOption(e,t){let n=t.attributeName();if(!this.dualOptions.has(n))return!0;let i=this.negativeOptions.get(n).presetArg,r=i!==void 0?i:!1;return t.negate===(r===e)}};function Q(s){return s.split("-").reduce((e,t)=>e+t[0].toUpperCase()+t.slice(1))}function oe(s){let e,t,n=/^-[^-]$/,i=/^--[^-]/,r=s.split(/[ |,]+/).concat("guard");if(n.test(r[0])&&(e=r.shift()),i.test(r[0])&&(t=r.shift()),!e&&n.test(r[0])&&(e=r.shift()),!e&&i.test(r[0])&&(e=t,t=r.shift()),r[0].startsWith("-")){let o=r[0],u=`option creation failed due to '${o}' in option flags '${s}'`;throw/^-[^-][^-]/.test(o)?new Error(`${u}
8
+ - a short flag is a single dash and a single character
9
+ - either use a single dash and a single character (for a short flag)
10
+ - or use a double dash for a long option (and can have two, like '--ws, --workspace')`):n.test(o)?new Error(`${u}
11
+ - too many short flags`):i.test(o)?new Error(`${u}
12
+ - too many long flags`):new Error(`${u}
13
+ - unrecognised flag format`)}if(e===void 0&&t===void 0)throw new Error(`option creation failed due to no flags found in '${s}'.`);return{shortFlag:e,longFlag:t}}function se(s,e){if(Math.abs(s.length-e.length)>3)return Math.max(s.length,e.length);let t=[];for(let n=0;n<=s.length;n++)t[n]=[n];for(let n=0;n<=e.length;n++)t[0][n]=n;for(let n=1;n<=e.length;n++)for(let i=1;i<=s.length;i++){let r;s[i-1]===e[n-1]?r=0:r=1,t[i][n]=Math.min(t[i-1][n]+1,t[i][n-1]+1,t[i-1][n-1]+r),i>1&&n>1&&s[i-1]===e[n-2]&&s[i-2]===e[n-1]&&(t[i][n]=Math.min(t[i][n],t[i-2][n-2]+1))}return t[s.length][e.length]}function q(s,e){if(!e||e.length===0)return"";e=Array.from(new Set(e));let t=s.startsWith("--");t&&(s=s.slice(2),e=e.map(o=>o.slice(2)));let n=[],i=3,r=.4;return e.forEach(o=>{if(o.length<=1)return;let u=se(s,o),l=Math.max(s.length,o.length);(l-u)/l>r&&(u<i?(i=u,n=[o]):u===i&&n.push(o))}),n.sort((o,u)=>o.localeCompare(u)),t&&(n=n.map(o=>`--${o}`)),n.length>1?`
14
+ (Did you mean one of ${n.join(", ")}?)`:n.length===1?`
15
+ (Did you mean ${n[0]}?)`:""}var $=class s extends ae{constructor(e){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=e||"",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=>m.stdout.write(t),writeErr:t=>m.stderr.write(t),outputError:(t,n)=>n(t),getOutHelpWidth:()=>m.stdout.isTTY?m.stdout.columns:void 0,getErrHelpWidth:()=>m.stderr.isTTY?m.stderr.columns:void 0,getOutHasColors:()=>ee()??(m.stdout.isTTY&&m.stdout.hasColors?.()),getErrHasColors:()=>ee()??(m.stderr.isTTY&&m.stderr.hasColors?.()),stripColor:t=>ue(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(e){return this._outputConfiguration=e._outputConfiguration,this._helpOption=e._helpOption,this._helpCommand=e._helpCommand,this._helpConfiguration=e._helpConfiguration,this._exitCallback=e._exitCallback,this._storeOptionsAsProperties=e._storeOptionsAsProperties,this._combineFlagAndOptionalValue=e._combineFlagAndOptionalValue,this._allowExcessArguments=e._allowExcessArguments,this._enablePositionalOptions=e._enablePositionalOptions,this._showHelpAfterError=e._showHelpAfterError,this._showSuggestionAfterError=e._showSuggestionAfterError,this}_getCommandAndAncestors(){let e=[];for(let t=this;t;t=t.parent)e.push(t);return e}command(e,t,n){let i=t,r=n;typeof i=="object"&&i!==null&&(r=i,i=null),r=r||{};let[,o,u]=e.match(/([^ ]+) *(.*)/),l=this.createCommand(o);return i&&(l.description(i),l._executableHandler=!0),r.isDefault&&(this._defaultCommandName=l._name),l._hidden=!!(r.noHelp||r.hidden),l._executableFile=r.executableFile||null,u&&l.arguments(u),this._registerCommand(l),l.parent=this,l.copyInheritedSettings(this),i?this:l}createCommand(e){return new s(e)}createHelp(){return Object.assign(new T,this.configureHelp())}configureHelp(e){return e===void 0?this._helpConfiguration:(this._helpConfiguration=e,this)}configureOutput(e){return e===void 0?this._outputConfiguration:(this._outputConfiguration={...this._outputConfiguration,...e},this)}showHelpAfterError(e=!0){return typeof e!="string"&&(e=!!e),this._showHelpAfterError=e,this}showSuggestionAfterError(e=!0){return this._showSuggestionAfterError=!!e,this}addCommand(e,t){if(!e._name)throw new Error(`Command passed to .addCommand() must have a name
16
+ - specify the name in Command constructor or using .name()`);return t=t||{},t.isDefault&&(this._defaultCommandName=e._name),(t.noHelp||t.hidden)&&(e._hidden=!0),this._registerCommand(e),e.parent=this,e._checkForBrokenPassThrough(),this}createArgument(e,t){return new E(e,t)}argument(e,t,n,i){let r=this.createArgument(e,t);return typeof n=="function"?r.default(i).argParser(n):r.default(n),this.addArgument(r),this}arguments(e){return e.trim().split(/ +/).forEach(t=>{this.argument(t)}),this}addArgument(e){let t=this.registeredArguments.slice(-1)[0];if(t?.variadic)throw new Error(`only the last argument can be variadic '${t.name()}'`);if(e.required&&e.defaultValue!==void 0&&e.parseArg===void 0)throw new Error(`a default value for a required argument is never used: '${e.name()}'`);return this.registeredArguments.push(e),this}helpCommand(e,t){if(typeof e=="boolean")return this._addImplicitHelpCommand=e,e&&this._defaultCommandGroup&&this._initCommandGroup(this._getHelpCommand()),this;let n=e??"help [command]",[,i,r]=n.match(/([^ ]+) *(.*)/),o=t??"display help for command",u=this.createCommand(i);return u.helpOption(!1),r&&u.arguments(r),o&&u.description(o),this._addImplicitHelpCommand=!0,this._helpCommand=u,(e||t)&&this._initCommandGroup(u),this}addHelpCommand(e,t){return typeof e!="object"?(this.helpCommand(e,t),this):(this._addImplicitHelpCommand=!0,this._helpCommand=e,this._initCommandGroup(e),this)}_getHelpCommand(){return this._addImplicitHelpCommand??(this.commands.length&&!this._actionHandler&&!this._findCommand("help"))?(this._helpCommand===void 0&&this.helpCommand(void 0,void 0),this._helpCommand):null}hook(e,t){let n=["preSubcommand","preAction","postAction"];if(!n.includes(e))throw new Error(`Unexpected value for event passed to hook : '${e}'.
17
+ Expecting one of '${n.join("', '")}'`);return this._lifeCycleHooks[e]?this._lifeCycleHooks[e].push(t):this._lifeCycleHooks[e]=[t],this}exitOverride(e){return e?this._exitCallback=e:this._exitCallback=t=>{if(t.code!=="commander.executeSubCommandAsync")throw t},this}_exit(e,t,n){this._exitCallback&&this._exitCallback(new x(e,t,n)),m.exit(e)}action(e){let t=n=>{let i=this.registeredArguments.length,r=n.slice(0,i);return this._storeOptionsAsProperties?r[i]=this:r[i]=this.opts(),r.push(this),e.apply(this,r)};return this._actionHandler=t,this}createOption(e,t){return new A(e,t)}_callParseArg(e,t,n,i){try{return e.parseArg(t,n)}catch(r){if(r.code==="commander.invalidArgument"){let o=`${i} ${r.message}`;this.error(o,{exitCode:r.exitCode,code:r.code})}throw r}}_registerOption(e){let t=e.short&&this._findOption(e.short)||e.long&&this._findOption(e.long);if(t){let n=e.long&&this._findOption(e.long)?e.long:e.short;throw new Error(`Cannot add option '${e.flags}'${this._name&&` to command '${this._name}'`} due to conflicting flag '${n}'
18
+ - already used by option '${t.flags}'`)}this._initOptionGroup(e),this.options.push(e)}_registerCommand(e){let t=i=>[i.name()].concat(i.aliases()),n=t(e).find(i=>this._findCommand(i));if(n){let i=t(this._findCommand(n)).join("|"),r=t(e).join("|");throw new Error(`cannot add command '${r}' as already have command '${i}'`)}this._initCommandGroup(e),this.commands.push(e)}addOption(e){this._registerOption(e);let t=e.name(),n=e.attributeName();e.defaultValue!==void 0&&this.setOptionValueWithSource(n,e.defaultValue,"default");let i=(r,o,u)=>{r==null&&e.presetArg!==void 0&&(r=e.presetArg);let l=this.getOptionValue(n);r!==null&&e.parseArg?r=this._callParseArg(e,r,l,o):r!==null&&e.variadic&&(r=e._collectValue(r,l)),r==null&&(e.negate?r=!1:e.isBoolean()||e.optional?r=!0:r=""),this.setOptionValueWithSource(n,r,u)};return this.on("option:"+t,r=>{let o=`error: option '${e.flags}' argument '${r}' is invalid.`;i(r,o,"cli")}),e.envVar&&this.on("optionEnv:"+t,r=>{let o=`error: option '${e.flags}' value '${r}' from env '${e.envVar}' is invalid.`;i(r,o,"env")}),this}_optionEx(e,t,n,i,r){if(typeof t=="object"&&t instanceof A)throw new Error("To add an Option object use addOption() instead of option() or requiredOption()");let o=this.createOption(t,n);if(o.makeOptionMandatory(!!e.mandatory),typeof i=="function")o.default(r).argParser(i);else if(i instanceof RegExp){let u=i;i=(l,h)=>{let a=u.exec(l);return a?a[0]:h},o.default(r).argParser(i)}else o.default(i);return this.addOption(o)}option(e,t,n,i){return this._optionEx({},e,t,n,i)}requiredOption(e,t,n,i){return this._optionEx({mandatory:!0},e,t,n,i)}combineFlagAndOptionalValue(e=!0){return this._combineFlagAndOptionalValue=!!e,this}allowUnknownOption(e=!0){return this._allowUnknownOption=!!e,this}allowExcessArguments(e=!0){return this._allowExcessArguments=!!e,this}enablePositionalOptions(e=!0){return this._enablePositionalOptions=!!e,this}passThroughOptions(e=!0){return this._passThroughOptions=!!e,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(e=!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=!!e,this}getOptionValue(e){return this._storeOptionsAsProperties?this[e]:this._optionValues[e]}setOptionValue(e,t){return this.setOptionValueWithSource(e,t,void 0)}setOptionValueWithSource(e,t,n){return this._storeOptionsAsProperties?this[e]=t:this._optionValues[e]=t,this._optionValueSources[e]=n,this}getOptionValueSource(e){return this._optionValueSources[e]}getOptionValueSourceWithGlobals(e){let t;return this._getCommandAndAncestors().forEach(n=>{n.getOptionValueSource(e)!==void 0&&(t=n.getOptionValueSource(e))}),t}_prepareUserArgs(e,t){if(e!==void 0&&!Array.isArray(e))throw new Error("first parameter to parse must be array or undefined");if(t=t||{},e===void 0&&t.from===void 0){m.versions?.electron&&(t.from="electron");let i=m.execArgv??[];(i.includes("-e")||i.includes("--eval")||i.includes("-p")||i.includes("--print"))&&(t.from="eval")}e===void 0&&(e=m.argv),this.rawArgs=e.slice();let n;switch(t.from){case void 0:case"node":this._scriptPath=e[1],n=e.slice(2);break;case"electron":m.defaultApp?(this._scriptPath=e[1],n=e.slice(2)):n=e.slice(1);break;case"user":n=e.slice(0);break;case"eval":n=e.slice(1);break;default:throw new Error(`unexpected parse option { from: '${t.from}' }`)}return!this._name&&this._scriptPath&&this.nameFromFilename(this._scriptPath),this._name=this._name||"program",n}parse(e,t){this._prepareForParse();let n=this._prepareUserArgs(e,t);return this._parseCommand([],n),this}async parseAsync(e,t){this._prepareForParse();let n=this._prepareUserArgs(e,t);return await this._parseCommand([],n),this}_prepareForParse(){this._savedState===null?(this.options.filter(e=>e.negate&&e.defaultValue===void 0&&this.getOptionValue(e.attributeName())===void 0).forEach(e=>{let t=e.long.replace(/^--no-/,"--");this._findOption(t)||this.setOptionValueWithSource(e.attributeName(),!0,"default")}),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.
19
+ - 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(e,t,n){if(F.existsSync(e))return;let i=t?`searched for local subcommand relative to directory '${t}'`:"no directory for search for local subcommand, use .executableDir() to supply a custom directory",r=`'${e}' does not exist
20
+ - if '${n}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
21
+ - if the default executable name is not suitable, use the executableFile option to supply a custom name or path
22
+ - ${i}`;throw new Error(r)}_executeSubCommand(e,t){t=t.slice();let n=[".js",".ts",".tsx",".mjs",".cjs"];function i(a,c){let p=C.resolve(a,c);if(F.existsSync(p))return p;if(n.includes(C.extname(c)))return;let O=n.find(_=>F.existsSync(`${p}${_}`));if(O)return`${p}${O}`}this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let r=e._executableFile||`${this._name}-${e._name}`,o=this._executableDir||"";if(this._scriptPath){let a;try{a=F.realpathSync(this._scriptPath)}catch{a=this._scriptPath}o=C.resolve(C.dirname(a),o)}if(o){let a=i(o,r);if(!a&&!e._executableFile&&this._scriptPath){let c=C.basename(this._scriptPath,C.extname(this._scriptPath));c!==this._name&&(a=i(o,`${c}-${e._name}`))}r=a||r}let u=n.includes(C.extname(r)),l;m.platform!=="win32"?u?(t.unshift(r),t=Z(m.execArgv).concat(t),l=G.spawn(m.argv[0],t,{stdio:"inherit"})):l=G.spawn(r,t,{stdio:"inherit"}):(this._checkForMissingExecutable(r,o,e._name),t.unshift(r),t=Z(m.execArgv).concat(t),l=G.spawn(m.execPath,t,{stdio:"inherit"})),l.killed||["SIGUSR1","SIGUSR2","SIGTERM","SIGINT","SIGHUP"].forEach(c=>{m.on(c,()=>{l.killed===!1&&l.exitCode===null&&l.kill(c)})});let h=this._exitCallback;l.on("close",a=>{a=a??1,h?h(new x(a,"commander.executeSubCommandAsync","(close)")):m.exit(a)}),l.on("error",a=>{if(a.code==="ENOENT")this._checkForMissingExecutable(r,o,e._name);else if(a.code==="EACCES")throw new Error(`'${r}' not executable`);if(!h)m.exit(1);else{let c=new x(1,"commander.executeSubCommandAsync","(error)");c.nestedError=a,h(c)}}),this.runningCommand=l}_dispatchSubcommand(e,t,n){let i=this._findCommand(e);i||this.help({error:!0}),i._prepareForParse();let r;return r=this._chainOrCallSubCommandHook(r,i,"preSubcommand"),r=this._chainOrCall(r,()=>{if(i._executableHandler)this._executeSubCommand(i,t.concat(n));else return i._parseCommand(t,n)}),r}_dispatchHelpCommand(e){e||this.help();let t=this._findCommand(e);return t&&!t._executableHandler&&t.help(),this._dispatchSubcommand(e,[],[this._getHelpOption()?.long??this._getHelpOption()?.short??"--help"])}_checkNumberOfArguments(){this.registeredArguments.forEach((e,t)=>{e.required&&this.args[t]==null&&this.missingArgument(e.name())}),!(this.registeredArguments.length>0&&this.registeredArguments[this.registeredArguments.length-1].variadic)&&this.args.length>this.registeredArguments.length&&this._excessArguments(this.args)}_processArguments(){let e=(n,i,r)=>{let o=i;if(i!==null&&n.parseArg){let u=`error: command-argument value '${i}' is invalid for argument '${n.name()}'.`;o=this._callParseArg(n,i,r,u)}return o};this._checkNumberOfArguments();let t=[];this.registeredArguments.forEach((n,i)=>{let r=n.defaultValue;n.variadic?i<this.args.length?(r=this.args.slice(i),n.parseArg&&(r=r.reduce((o,u)=>e(n,u,o),n.defaultValue))):r===void 0&&(r=[]):i<this.args.length&&(r=this.args[i],n.parseArg&&(r=e(n,r,n.defaultValue))),t[i]=r}),this.processedArgs=t}_chainOrCall(e,t){return e?.then&&typeof e.then=="function"?e.then(()=>t()):t()}_chainOrCallHooks(e,t){let n=e,i=[];return this._getCommandAndAncestors().reverse().filter(r=>r._lifeCycleHooks[t]!==void 0).forEach(r=>{r._lifeCycleHooks[t].forEach(o=>{i.push({hookedCommand:r,callback:o})})}),t==="postAction"&&i.reverse(),i.forEach(r=>{n=this._chainOrCall(n,()=>r.callback(r.hookedCommand,this))}),n}_chainOrCallSubCommandHook(e,t,n){let i=e;return this._lifeCycleHooks[n]!==void 0&&this._lifeCycleHooks[n].forEach(r=>{i=this._chainOrCall(i,()=>r(this,t))}),i}_parseCommand(e,t){let n=this.parseOptions(t);if(this._parseOptionsEnv(),this._parseOptionsImplied(),e=e.concat(n.operands),t=n.unknown,this.args=e.concat(t),e&&this._findCommand(e[0]))return this._dispatchSubcommand(e[0],e.slice(1),t);if(this._getHelpCommand()&&e[0]===this._getHelpCommand().name())return this._dispatchHelpCommand(e[1]);if(this._defaultCommandName)return this._outputHelpIfRequested(t),this._dispatchSubcommand(this._defaultCommandName,e,t);this.commands.length&&this.args.length===0&&!this._actionHandler&&!this._defaultCommandName&&this.help({error:!0}),this._outputHelpIfRequested(n.unknown),this._checkForMissingMandatoryOptions(),this._checkForConflictingOptions();let i=()=>{n.unknown.length>0&&this.unknownOption(n.unknown[0])},r=`command:${this.name()}`;if(this._actionHandler){i(),this._processArguments();let o;return o=this._chainOrCallHooks(o,"preAction"),o=this._chainOrCall(o,()=>this._actionHandler(this.processedArgs)),this.parent&&(o=this._chainOrCall(o,()=>{this.parent.emit(r,e,t)})),o=this._chainOrCallHooks(o,"postAction"),o}if(this.parent?.listenerCount(r))i(),this._processArguments(),this.parent.emit(r,e,t);else if(e.length){if(this._findCommand("*"))return this._dispatchSubcommand("*",e,t);this.listenerCount("command:*")?this.emit("command:*",e,t):this.commands.length?this.unknownCommand():(i(),this._processArguments())}else this.commands.length?(i(),this.help({error:!0})):(i(),this._processArguments())}_findCommand(e){if(e)return this.commands.find(t=>t._name===e||t._aliases.includes(e))}_findOption(e){return this.options.find(t=>t.is(e))}_checkForMissingMandatoryOptions(){this._getCommandAndAncestors().forEach(e=>{e.options.forEach(t=>{t.mandatory&&e.getOptionValue(t.attributeName())===void 0&&e.missingMandatoryOptionValue(t)})})}_checkForConflictingLocalOptions(){let e=this.options.filter(n=>{let i=n.attributeName();return this.getOptionValue(i)===void 0?!1:this.getOptionValueSource(i)!=="default"});e.filter(n=>n.conflictsWith.length>0).forEach(n=>{let i=e.find(r=>n.conflictsWith.includes(r.attributeName()));i&&this._conflictingOption(n,i)})}_checkForConflictingOptions(){this._getCommandAndAncestors().forEach(e=>{e._checkForConflictingLocalOptions()})}parseOptions(e){let t=[],n=[],i=t;function r(a){return a.length>1&&a[0]==="-"}let o=a=>/^-(\d+|\d*\.\d+)(e[+-]?\d+)?$/.test(a)?!this._getCommandAndAncestors().some(c=>c.options.map(p=>p.short).some(p=>/^-\d$/.test(p))):!1,u=null,l=null,h=0;for(;h<e.length||l;){let a=l??e[h++];if(l=null,a==="--"){i===n&&i.push(a),i.push(...e.slice(h));break}if(u&&(!r(a)||o(a))){this.emit(`option:${u.name()}`,a);continue}if(u=null,r(a)){let c=this._findOption(a);if(c){if(c.required){let p=e[h++];p===void 0&&this.optionMissingArgument(c),this.emit(`option:${c.name()}`,p)}else if(c.optional){let p=null;h<e.length&&(!r(e[h])||o(e[h]))&&(p=e[h++]),this.emit(`option:${c.name()}`,p)}else this.emit(`option:${c.name()}`);u=c.variadic?c:null;continue}}if(a.length>2&&a[0]==="-"&&a[1]!=="-"){let c=this._findOption(`-${a[1]}`);if(c){c.required||c.optional&&this._combineFlagAndOptionalValue?this.emit(`option:${c.name()}`,a.slice(2)):(this.emit(`option:${c.name()}`),l=`-${a.slice(2)}`);continue}}if(/^--[^=]+=/.test(a)){let c=a.indexOf("="),p=this._findOption(a.slice(0,c));if(p&&(p.required||p.optional)){this.emit(`option:${p.name()}`,a.slice(c+1));continue}}if(i===t&&r(a)&&!(this.commands.length===0&&o(a))&&(i=n),(this._enablePositionalOptions||this._passThroughOptions)&&t.length===0&&n.length===0){if(this._findCommand(a)){t.push(a),n.push(...e.slice(h));break}else if(this._getHelpCommand()&&a===this._getHelpCommand().name()){t.push(a,...e.slice(h));break}else if(this._defaultCommandName){n.push(a,...e.slice(h));break}}if(this._passThroughOptions){i.push(a,...e.slice(h));break}i.push(a)}return{operands:t,unknown:n}}opts(){if(this._storeOptionsAsProperties){let e={},t=this.options.length;for(let n=0;n<t;n++){let i=this.options[n].attributeName();e[i]=i===this._versionOptionName?this._version:this[i]}return e}return this._optionValues}optsWithGlobals(){return this._getCommandAndAncestors().reduce((e,t)=>Object.assign(e,t.opts()),{})}error(e,t){this._outputConfiguration.outputError(`${e}
23
+ `,this._outputConfiguration.writeErr),typeof this._showHelpAfterError=="string"?this._outputConfiguration.writeErr(`${this._showHelpAfterError}
24
+ `):this._showHelpAfterError&&(this._outputConfiguration.writeErr(`
25
+ `),this.outputHelp({error:!0}));let n=t||{},i=n.exitCode||1,r=n.code||"commander.error";this._exit(i,r,e)}_parseOptionsEnv(){this.options.forEach(e=>{if(e.envVar&&e.envVar in m.env){let t=e.attributeName();(this.getOptionValue(t)===void 0||["default","config","env"].includes(this.getOptionValueSource(t)))&&(e.required||e.optional?this.emit(`optionEnv:${e.name()}`,m.env[e.envVar]):this.emit(`optionEnv:${e.name()}`))}})}_parseOptionsImplied(){let e=new N(this.options),t=n=>this.getOptionValue(n)!==void 0&&!["default","implied"].includes(this.getOptionValueSource(n));this.options.filter(n=>n.implied!==void 0&&t(n.attributeName())&&e.valueFromOption(this.getOptionValue(n.attributeName()),n)).forEach(n=>{Object.keys(n.implied).filter(i=>!t(i)).forEach(i=>{this.setOptionValueWithSource(i,n.implied[i],"implied")})})}missingArgument(e){let t=`error: missing required argument '${e}'`;this.error(t,{code:"commander.missingArgument"})}optionMissingArgument(e){let t=`error: option '${e.flags}' argument missing`;this.error(t,{code:"commander.optionMissingArgument"})}missingMandatoryOptionValue(e){let t=`error: required option '${e.flags}' not specified`;this.error(t,{code:"commander.missingMandatoryOptionValue"})}_conflictingOption(e,t){let n=o=>{let u=o.attributeName(),l=this.getOptionValue(u),h=this.options.find(c=>c.negate&&u===c.attributeName()),a=this.options.find(c=>!c.negate&&u===c.attributeName());return h&&(h.presetArg===void 0&&l===!1||h.presetArg!==void 0&&l===h.presetArg)?h:a||o},i=o=>{let u=n(o),l=u.attributeName();return this.getOptionValueSource(l)==="env"?`environment variable '${u.envVar}'`:`option '${u.flags}'`},r=`error: ${i(e)} cannot be used with ${i(t)}`;this.error(r,{code:"commander.conflictingOption"})}unknownOption(e){if(this._allowUnknownOption)return;let t="";if(e.startsWith("--")&&this._showSuggestionAfterError){let i=[],r=this;do{let o=r.createHelp().visibleOptions(r).filter(u=>u.long).map(u=>u.long);i=i.concat(o),r=r.parent}while(r&&!r._enablePositionalOptions);t=q(e,i)}let n=`error: unknown option '${e}'${t}`;this.error(n,{code:"commander.unknownOption"})}_excessArguments(e){if(this._allowExcessArguments)return;let t=this.registeredArguments.length,n=t===1?"":"s",i=e.length,r=this.parent?` for '${this.name()}'`:"",o=e.join(", "),u=`error: too many arguments${r}. Expected ${t} argument${n} but got ${i}: ${o}.`;this.error(u,{code:"commander.excessArguments"})}unknownCommand(){let e=this.args[0],t="";if(this._showSuggestionAfterError){let i=[];this.createHelp().visibleCommands(this).forEach(r=>{i.push(r.name()),r.alias()&&i.push(r.alias())}),t=q(e,i)}let n=`error: unknown command '${e}'${t}`;this.error(n,{code:"commander.unknownCommand"})}version(e,t,n){if(e===void 0)return this._version;this._version=e,t=t||"-V, --version",n=n||"output the version number";let i=this.createOption(t,n);return this._versionOptionName=i.attributeName(),this._registerOption(i),this.on("option:"+i.name(),()=>{this._outputConfiguration.writeOut(`${e}
26
+ `),this._exit(0,"commander.version",e)}),this}description(e,t){return e===void 0&&t===void 0?this._description:(this._description=e,t&&(this._argsDescription=t),this)}summary(e){return e===void 0?this._summary:(this._summary=e,this)}alias(e){if(e===void 0)return this._aliases[0];let t=this;if(this.commands.length!==0&&this.commands[this.commands.length-1]._executableHandler&&(t=this.commands[this.commands.length-1]),e===t._name)throw new Error("Command alias can't be the same as its name");let n=this.parent?._findCommand(e);if(n){let i=[n.name()].concat(n.aliases()).join("|");throw new Error(`cannot add alias '${e}' to command '${this.name()}' as already have command '${i}'`)}return t._aliases.push(e),this}aliases(e){return e===void 0?this._aliases:(e.forEach(t=>this.alias(t)),this)}usage(e){if(e===void 0){if(this._usage)return this._usage;let t=this.registeredArguments.map(n=>V(n));return[].concat(this.options.length||this._helpOption!==null?"[options]":[],this.commands.length?"[command]":[],this.registeredArguments.length?t:[]).join(" ")}return this._usage=e,this}name(e){return e===void 0?this._name:(this._name=e,this)}helpGroup(e){return e===void 0?this._helpGroupHeading??"":(this._helpGroupHeading=e,this)}commandsGroup(e){return e===void 0?this._defaultCommandGroup??"":(this._defaultCommandGroup=e,this)}optionsGroup(e){return e===void 0?this._defaultOptionGroup??"":(this._defaultOptionGroup=e,this)}_initOptionGroup(e){this._defaultOptionGroup&&!e.helpGroupHeading&&e.helpGroup(this._defaultOptionGroup)}_initCommandGroup(e){this._defaultCommandGroup&&!e.helpGroup()&&e.helpGroup(this._defaultCommandGroup)}nameFromFilename(e){return this._name=C.basename(e,C.extname(e)),this}executableDir(e){return e===void 0?this._executableDir:(this._executableDir=e,this)}helpInformation(e){let t=this.createHelp(),n=this._getOutputContext(e);t.prepareContext({error:n.error,helpWidth:n.helpWidth,outputHasColors:n.hasColors});let i=t.formatHelp(this,t);return n.hasColors?i:this._outputConfiguration.stripColor(i)}_getOutputContext(e){e=e||{};let t=!!e.error,n,i,r;return t?(n=u=>this._outputConfiguration.writeErr(u),i=this._outputConfiguration.getErrHasColors(),r=this._outputConfiguration.getErrHelpWidth()):(n=u=>this._outputConfiguration.writeOut(u),i=this._outputConfiguration.getOutHasColors(),r=this._outputConfiguration.getOutHelpWidth()),{error:t,write:u=>(i||(u=this._outputConfiguration.stripColor(u)),n(u)),hasColors:i,helpWidth:r}}outputHelp(e){let t;typeof e=="function"&&(t=e,e=void 0);let n=this._getOutputContext(e),i={error:n.error,write:n.write,command:this};this._getCommandAndAncestors().reverse().forEach(o=>o.emit("beforeAllHelp",i)),this.emit("beforeHelp",i);let r=this.helpInformation({error:n.error});if(t&&(r=t(r),typeof r!="string"&&!Buffer.isBuffer(r)))throw new Error("outputHelp callback must return a string or a Buffer");n.write(r),this._getHelpOption()?.long&&this.emit(this._getHelpOption().long),this.emit("afterHelp",i),this._getCommandAndAncestors().forEach(o=>o.emit("afterAllHelp",i))}helpOption(e,t){return typeof e=="boolean"?(e?(this._helpOption===null&&(this._helpOption=void 0),this._defaultOptionGroup&&this._initOptionGroup(this._getHelpOption())):this._helpOption=null,this):(this._helpOption=this.createOption(e??"-h, --help",t??"display help for command"),(e||t)&&this._initOptionGroup(this._helpOption),this)}_getHelpOption(){return this._helpOption===void 0&&this.helpOption(void 0,void 0),this._helpOption}addHelpOption(e){return this._helpOption=e,this._initOptionGroup(e),this}help(e){this.outputHelp(e);let t=Number(m.exitCode??0);t===0&&e&&typeof e!="function"&&e.error&&(t=1),this._exit(t,"commander.help","(outputHelp)")}addHelpText(e,t){let n=["beforeAll","before","after","afterAll"];if(!n.includes(e))throw new Error(`Unexpected value for position to addHelpText.
27
+ Expecting one of '${n.join("', '")}'`);let i=`${e}Help`;return this.on(i,r=>{let o;typeof t=="function"?o=t({error:r.error,command:r.command}):o=t,o&&r.write(`${o}
28
+ `)}),this}_outputHelpIfRequested(e){let t=this._getHelpOption();t&&e.find(i=>t.is(i))&&(this.outputHelp(),this._exit(0,"commander.helpDisplayed","(outputHelp)"))}};function Z(s){return s.map(e=>{if(!e.startsWith("--inspect"))return e;let t,n="127.0.0.1",i="9229",r;return(r=e.match(/^(--inspect(-brk)?)$/))!==null?t=r[1]:(r=e.match(/^(--inspect(-brk|-port)?)=([^:]+)$/))!==null?(t=r[1],/^\d+$/.test(r[3])?i=r[3]:n=r[3]):(r=e.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/))!==null&&(t=r[1],n=r[3],i=r[4]),t&&i!=="0"?`${t}=${n}:${parseInt(i)+1}`:e})}function ee(){if(m.env.NO_COLOR||m.env.FORCE_COLOR==="0"||m.env.FORCE_COLOR==="false")return!1;if(m.env.FORCE_COLOR||m.env.CLICOLOR_FORCE!==void 0)return!0}var Xe=new $;function le(s){let[,e,t,...n]=s;if(e===void 0||e==="list")return{kind:"config",action:"list"};if(e==="path")return{kind:"config",action:"path"};if(e==="set"){if(t===void 0||!D.includes(t))throw d(`Unknown config setting ${t??"(none)"}.`,`Try one of: ${D.join(", ")}.`);let i=n.join(" ");if(i.length===0)throw d(`forge config set ${t} needs a value.`);return{kind:"config",action:"set",key:t,value:i}}throw d(`Unknown config action ${e}.`,"Try: forge config list, forge config set <setting> <value>, or forge config path.")}var he={jpg:"jpeg",tif:"tiff",heif:"heic"};function I(s){let e=s.toLowerCase().replace(/^\./,""),t=z(he[e]??e);if(!t)throw d(`${s} is not a format Forge knows.`,"Run forge --formats to see what is available.");return t.id}function P(s,e,t,n,i){let r=Number(String(e).replace(/k$/i,""));if(!Number.isFinite(r)||r<t||r>n)throw d(`${s} takes ${t} to ${n}, not ${e}.`,`For example ${s} ${i}.`);return r}function ce(s){let e={};if(s.cut!==void 0){let t=J(String(s.cut));if(!t)throw d(`--cut takes a start and an end, the end after the start, not ${s.cut}.`,"For example --cut 0:03.2-0:41, or --cut 0:10- to keep from 0:10 to the end.");e.cut=t.end===void 0?{start:t.start}:{start:t.start,end:t.end}}return s.mute&&(e.mute=!0),s.speed!==void 0&&(e.speed=P("--speed",s.speed,.25,4,"2")),s.fps!==void 0&&(e.fps=P("--fps",s.fps,1,120,"30")),s.bitrate!==void 0&&(e.bitrate=Math.round(P("--bitrate",s.bitrate,32,320,"128k"))),s.loudness!==void 0&&(e.loudness=P("--loudness",s.loudness,-70,-5,"-16")),Object.keys(e).length?e:void 0}function S(s){let e=Number(s);if(!Number.isInteger(e)||e<1||e>100)throw d(`Quality must be a whole number between 1 and 100, not ${s}.`);return e}function te(s,e){let t=/^\d+$/.test(String(e))?Number(e):Number.NaN;if(!Number.isInteger(t)||t<1)throw d(`${s} takes a whole number of pixels, at least 1, not ${e}.`);return t}function de(s){let e=String(s),t=/^\d+(\.\d+)?%?$/.test(e)?Number.parseFloat(e):Number.NaN;if(!(t>=1&&t<=W))throw d(`--resize takes a percent from 1 to ${W}, not ${s}.`,"Try --resize 50% to halve, or --width 1200 for an exact width.");return t}function j(s){let e=Number(s);if(!Number.isInteger(e)||e<1)throw d(`Concurrency must be a positive whole number, not ${s}.`);return e}var pe=`
29
+ Exit codes:
30
+ 0 every input succeeded
31
+ 1 the command was understood, and at least one input failed or was refused
32
+ 2 the command itself was invalid: an unknown flag, a missing argument, contradictory flags`,fe=`
33
+ Other commands:
34
+ forge probe <files...> what each file is and what Forge can do with it
35
+ forge palette <image> an image's main colours (--json, --svg, --inside <hex>)
36
+ forge scale <colour> 50\u2013950 from one colour, with it at 500 (--json, --svg)
37
+ forge clip compress the copied image and put it back (--to, --quality,
38
+ --max-size, --save [folder], --undo)
39
+ forge transcribe <file | link>
40
+ a video or audio file, or a YouTube link, into Markdown
41
+ (--to all | notes | transcript, --detail brief | standard | detailed,
42
+ --language <id>, -o <path>, --force)
43
+ forge watch <folder> --to <format>
44
+ convert the folder, then every file added to it, until ctrl-c
45
+ (--quality, --dpi, -o <folder>, --new-only, --json)
46
+ forge config [list | path | set <setting> <value>]
47
+ forge extensions [add | remove <id>] optional extras, such as boost and remove-background
48
+ forge update install a newer Forge, if there is one
49
+ forge uninstall take Forge out of the right-click menu, then remove it
50
+ forge mcp run as a local MCP server over stdio, for AI agents`;function M(s){let e=R(String(s));if(e===void 0)throw d(`${s} is not a size.`,"Try a number with a unit, for example 500kb, 2mb or 1.5mb.");return e}function me(s){let e=s.slice(1).filter(n=>n!=="--json"),t=e.find(n=>n.startsWith("-"));if(t!==void 0)throw d(`forge probe takes files, not ${t}.`,"Try: forge probe photo.jpg --json");if(e.length===0)throw d("No files given.","Name a file, for example: forge probe scan.pdf --json");return{kind:"probe",inputs:e}}function ge(s){let e={kind:"clip",undo:!1,debug:!1},t=s.slice(1),n=(i,r)=>{let o=t[r+1];if(o===void 0||o.startsWith("-"))throw d(`${i} needs a value.`);return o};for(let i=0;i<t.length;i++){let r=t[i];if(r!=="--json")if(r==="--debug")e.debug=!0;else if(r==="--undo")e.undo=!0;else if(r==="--to"||r==="-t")e.target=I(n(r,i++));else if(r==="--quality"||r==="-q")e.quality=S(n(r,i++));else if(r==="--max-size")e.maxBytes=M(n(r,i++));else if(r==="--save"){let o=t[i+1];e.save=o===void 0||o.startsWith("-")?!0:t[++i]}else throw r.startsWith("-")?d(`forge clip does not take ${r}.`,"Try: forge --help"):d(`forge clip takes no files: it reads the clipboard, not ${r}.`,`To compress a file, try: forge ${r} --quality 80`)}if(e.undo&&Object.keys(e).some(i=>!["kind","undo","debug"].includes(i)))throw d("--undo takes no other flag.","Try: forge clip --undo");if(e.quality!==void 0&&e.maxBytes!==void 0)throw d("Use either --quality or --max-size, not both.","They are two ways of asking for the same thing, and Forge will not guess which wins.");return e}function be(s){let e=s.slice(1),t=[],n={kind:"transcribe",input:"",notes:!0,transcript:!0,detail:Y,force:!1,debug:!1},i=(l,h)=>{let a=e[h+1];if(a===void 0||a.startsWith("-"))throw d(`${l} needs a value.`);return a},r="Try: forge transcribe talk.mp4";for(let l=0;l<e.length;l++){let h=e[l];if(h==="--debug")n.debug=!0;else if(h==="--force"||h==="-f")n.force=!0;else if(h==="--language"||h==="-l")n.language=i(h,l++);else if(h==="--output"||h==="-o")n.output=i(h,l++);else if(h==="--detail"){let a=i(h,l++).toLowerCase();if(!K.includes(a))throw d(`forge transcribe writes notes in brief, standard or detailed, not ${a}.`,"Try: forge transcribe talk.mp4 --detail brief");n.detail=a}else if(h==="--to"||h==="-t"){let a=i(h,l++).toLowerCase();if(a!=="all"&&a!=="notes"&&a!=="transcript")throw d(`forge transcribe makes all, notes or a transcript, not ${a}.`,"Try: forge transcribe talk.mp4 --to transcript");n.notes=a!=="transcript",n.transcript=a!=="notes"}else{if(h.startsWith("-"))throw d(`forge transcribe does not take ${h}.`,r);t.push(h)}}let[o,...u]=t;if(o===void 0)throw d("forge transcribe needs a file or a link.",r);if(u.length>0)throw d("forge transcribe takes one file or link at a time.",r);return{...n,input:o}}function _e(s){let e=s.slice(1),t=[],n,i={kind:"watch",newOnly:!1,debug:!1},r={},o=(h,a)=>{let c=e[a+1];if(c===void 0||c.startsWith("-"))throw d(`${h} needs a value.`);return c};for(let h=0;h<e.length;h++){let a=e[h];if(a!=="--json")if(a==="--debug")i.debug=!0;else if(a==="--new-only")i.newOnly=!0;else if(a==="--to"||a==="-t")n=I(o(a,h++));else if(a==="--quality"||a==="-q")r.quality=S(o(a,h++));else if(a==="--output"||a==="-o")r.output=o(a,h++);else if(a==="--dpi"){let c=o(a,h++),p=Number(c);if(!Number.isInteger(p)||p<36||p>600)throw H(c);r.dpi=p}else{if(a.startsWith("-"))throw d(`forge watch does not take ${a}.`,"Try: forge watch ./images --to webp");t.push(a)}}let[u,...l]=t;if(u===void 0)throw d("forge watch needs a folder.","Try: forge watch ./images --to webp");if(l.length>0)throw d("forge watch watches one folder at a time.",`Try: forge watch ${u} --to webp`);if(n===void 0)throw d("forge watch needs a format to convert to.",`Try: forge watch ${u} --to webp`);return{kind:"watch",folder:u,target:n,...r.quality===void 0?{}:{quality:r.quality},...r.dpi===void 0?{}:{dpi:r.dpi},...r.output===void 0?{}:{output:r.output},newOnly:i.newOnly,debug:i.debug}}function we(s){let e=s.slice(1).filter(o=>o!=="--json"),t=e.find(o=>o.startsWith("-"));if(t!==void 0)throw d(`forge extensions does not take ${t}.`,"Try: forge extensions, forge extensions add <id>, or forge extensions remove <id>.");let[n,i,...r]=e;if(n===void 0)return{kind:"extensions",action:"list"};if(n!=="add"&&n!=="remove")throw d(`Unknown extensions action ${n}.`,"Try: forge extensions, forge extensions add <id>, or forge extensions remove <id>.");if(i===void 0||r.length>0)throw d(`forge extensions ${n} takes exactly one extension.`,`Try: forge extensions ${n} boost`);return{kind:"extensions",action:n,id:i}}function ne(s){if(s===void 0)throw d("No colour given.","Try: forge scale 6579FD \u2014 or quote it, '#6579FD', because an unquoted # starts a comment in the shell.");let e=B(s)?.rgb;if(!e)throw d(`${s} is not a colour.`,"Try a hex code (6579FD), rgb(), hsl(), oklch() or a colour name, quoted: 'rgb(101 121 253)'.");return e}var ye={palette:`Usage: forge palette <image> [--json] [--svg] [--inside <hex>]
51
+
52
+ An image's main colours, most of the image first.
53
+ --json one JSON document: palette.colours[] with hex, rgb, oklch, share
54
+ --svg a card of swatches; pipe to pbcopy and paste into Figma
55
+ --inside <hex> the shades of the palette colour nearest <hex>
56
+ `,scale:`Usage: forge scale <colour> [--json] [--svg]
57
+
58
+ 50\u2013950 built in OKLCH, with <colour> at 500. Pass the hex without #, or quote it.
59
+ --json one JSON document: scale.steps[] with hex, oklch, white, black
60
+ --svg a card of swatches; pipe to pbcopy and paste into Figma
61
+ `};function Oe(s){let[e,...t]=s;if(t.includes("--help")||t.includes("-h"))throw process.stdout.write(ye[e==="scale"?"scale":"palette"]),new x(0,"commander.helpDisplayed","(outputHelp)");let n=t.filter(l=>l!=="--json"&&l!=="--svg"),i=t.includes("--svg"),r=n.indexOf("--inside"),o=r===-1?void 0:n[r+1];r!==-1&&n.splice(r,2);let u=n.find(l=>l.startsWith("-"));if(u!==void 0)throw d(`forge ${e} does not take ${u}.`,`Try: forge ${e} --help`);if(e==="scale"){if(r!==-1)throw d("--inside is for forge palette.","Try: forge palette photo.jpg --inside F26E69");if(n.length>1)throw d("forge scale takes one colour.","Try: forge scale 6579FD");return{kind:"scale",colour:ne(n[0]),svg:i}}if(n.length!==1)throw d(n.length===0?"No image given.":"forge palette takes one image.","Try: forge palette photo.jpg");return{kind:"palette",input:n[0],svg:i,...r===-1?{}:{inside:ne(o)}}}function ct(s){let e=s.indexOf("--");return(e===-1?s:s.slice(0,e)).includes("--json")}function xe(s){let e=s.indexOf("--"),t=e===-1?s:s.slice(0,e),n=e===-1?[]:s.slice(e),i=[],r;for(let o=0;o<t.length;o++){let u=t[o],l=u.startsWith("--boost=")?u.slice(8):void 0;if(u!=="--boost"&&l===void 0){i.push(u);continue}let h=l;if(h===void 0&&/^\d+$/.test(t[o+1]??"")&&(h=t[++o]),h!==void 0&&h!=="2"&&h!=="3"&&h!=="4")throw d(`--boost takes 2, 3 or 4, not ${h}.`,"Try --boost, --boost 2, --boost 3 or --boost 4.");r=h==="4"?4:h==="3"?3:2}return{rest:[...i,...n],...r===void 0?{}:{scale:r}}}function dt(s){let e=s;if(e[0]==="clip"||e[0]==="watch"||e[0]==="transcribe"||e[0]==="config"||e[0]==="probe"||e[0]==="extensions"||e[0]==="palette"||e[0]==="scale"||e[0]==="update"||e[0]==="uninstall")return Ce(e);let t=xe(e);return ke(t.rest,t.scale)}function Ce(s){if(s[0]==="update"){let e=s.slice(1).filter(t=>t!=="--json");if(e.length>0)throw d(`forge update takes nothing else, got: ${e.join(" ")}.`,"Try: forge update");return{kind:"update"}}if(s[0]==="uninstall"){let e=s.slice(1);if(e.length>0)throw d(`forge uninstall takes nothing else, got: ${e.join(" ")}.`,"Try: forge uninstall");return{kind:"uninstall"}}return s[0]==="clip"?ge(s):s[0]==="watch"?_e(s):s[0]==="transcribe"?be(s):s[0]==="config"?le(s.filter(e=>e!=="--json")):s[0]==="probe"?me(s):s[0]==="palette"||s[0]==="scale"?Oe(s):we(s)}function ke(s,e){let t=new $().name("forge").description("Convert \u2014 transform your files from the terminal").argument("[inputs...]","files, folders or globs").option("-t, --to <format>","target format").option("-o, --output <path>","output file or directory").option("-q, --quality <n>","quality for lossy formats, 1-100").option("--background <colour>","fill colour when flattening transparency","#ffffff").option("--keep-metadata","preserve EXIF and GPS data",!1).option("--recursive","descend into subfolders",!1).option("--force","allow overwriting existing files",!1).option("--max-size <size>","compress until the file fits, e.g. 500kb").option("--concurrency <n>","how many files to convert at once").option("--debug","show underlying errors",!1).option("--formats","list supported formats",!1).option("--merge","combine several PDFs into one").option("--split <mode>","every-page | every=N | at=N,N").option("--extract <pages>","keep only these pages, e.g. 3-7,12").option("--delete <pages>","drop these pages").option("--rotate <degrees>","90, 180 or 270").option("--separate","with --extract, write one file per page").option("--sharpen","sharpen at the same size; needs the boost extension").option("--boost [2|3|4]","sharpen and enlarge 2x (default), 3x or 4x; needs the boost extension").option("--trim","cut transparent or solid-colour edges; keeps the format").option("--crop <W:H>","cut to a shape, e.g. 1:1, 4:5, 16:9; keeps the subject").option("--resize <percent>","resize to a percent of the size, 1-200, e.g. 50%").option("--width <px>","resize to this width; the height follows").option("--height <px>","resize to this height; the width follows").option("--remove-bg","cut out the subject; needs the remove-background extension").option("--cut <start-end>","video or audio: keep from start to end, e.g. 0:03.2-0:41").option("--mute","video: take the sound out").option("--speed <x>","video or audio: play faster or slower, 0.25-4").option("--fps <n>","video: frames per second").option("--bitrate <kbps>","audio: bitrate, e.g. 128k").option("--loudness <LUFS>","audio: even out loudness to this level, e.g. -16").option("--preset <name>","run a preset saved from Done, e.g. --preset blog").option("--pages <ranges>","with --to, which pages to render, e.g. 3-7,12").option("--dpi <n>","rasterisation resolution, 36-600","150").option("--password-stdin","read an encrypted PDF's password from stdin").option("--json","print one JSON document on stdout instead of text").helpOption("-h, --help","show this help").version(X,"-V, --version","show the version").addHelpText("after",`${fe}
62
+ ${pe}`).configureOutput({outputError:()=>{}}).exitOverride().allowExcessArguments(!1);try{t.parse(s,{from:"user"})}catch(f){if(f instanceof x&&f.code!=="commander.helpDisplayed"&&f.code!=="commander.version"){let[g="",...b]=f.message.replace(/^error: /,"").split(`
63
+ `),w=b.join(" ").trim().replace(/^\((.*)\)\.?$/,"$1");throw d(`${g.charAt(0).toUpperCase()}${g.slice(1).replace(/\.$/,"")}.`,w||"Run forge --help to see what Forge accepts.")}throw f}let n=t.opts(),i=t.args;if(n.formats)return{kind:"formats"};let r=ce(n);if(r!==void 0&&n.trim)throw d("--trim cuts the empty edges of an image.","To keep part of a video or audio file, use --cut, for example --cut 0:03-0:41.");if(n.preset!==void 0){let f=[["to","--to"],["quality","--quality"],["maxSize","--max-size"],["merge","--merge"],["split","--split"],["extract","--extract"],["delete","--delete"],["rotate","--rotate"],["sharpen","--sharpen"],["trim","--trim"],["crop","--crop"],["resize","--resize"],["width","--width"],["height","--height"],["removeBg","--remove-bg"],["pages","--pages"]].filter(([g])=>n[g]!==void 0&&n[g]!==!1).map(([,g])=>g);if(e!==void 0&&f.push("--boost"),f.length>0)throw d(`--preset already says what to do \u2014 leave out ${f.join(" and ")}.`,"Run the preset alone, or change it from Done with \u2192 continue editing.");return{kind:"preset",inputs:i,name:String(n.preset),...n.output===void 0?{}:{output:String(n.output)},force:n.force===!0,recursive:n.recursive===!0,debug:n.debug===!0}}if(n.pages!==void 0&&n.to===void 0)throw d("--pages needs --to: it chooses which pages to render.");let o=["merge","split","extract","delete","rotate"].filter(f=>n[f]!==void 0);if(o.length>1)throw d(`Use one operation at a time \u2014 got ${o.map(f=>`--${f}`).join(" and ")}.`);let u=[...n.sharpen?["--sharpen"]:[],...e!==void 0?["--boost"]:[],...n.removeBg?["--remove-bg"]:[]],l=[...n.resize!==void 0?["--resize"]:[],...n.width!==void 0?["--width"]:[],...n.height!==void 0?["--height"]:[]],h=r!==void 0&&!n.to&&n.quality===void 0&&n.maxSize===void 0;if(n.trim||n.crop!==void 0||l.length>0||h){if(l.length>1)throw d(`Use one of --resize, --width and --height \u2014 got ${l.join(" and ")}.`);let f=n.crop!==void 0?"--crop":l[0]??(n.trim?"--trim":"--cut"),g=[...n.crop!==void 0&&n.trim?["--trim"]:[],...u,...n.maxSize!==void 0?["--max-size"]:[],...n.pages!==void 0?["--pages"]:[],...o.map(ie=>`--${ie}`)][0];if(g!==void 0)throw d(`${f} cannot be combined with ${g}.`,g!=="--max-size"?"Run them one after the other.":f==="--crop"?"Crop first, then compress the result: forge photo-cropped-1x1.jpg --max-size 500kb":"Resize first, then compress the result: forge photo-1200x900.jpg --max-size 500kb");let b=n.crop!==void 0?{aspect:L(String(n.crop))}:void 0,w=n.resize!==void 0?{percent:de(n.resize)}:n.width!==void 0?{width:te("--width",n.width)}:n.height!==void 0?{height:te("--height",n.height)}:void 0;if(i.length===0)throw d("No files given.","Name an image, for example: forge photo.jpg --resize 50%");let k={background:String(n.background),keepMetadata:!!n.keepMetadata};n.quality!==void 0&&(k.quality=S(String(n.quality)));let y={kind:"edit",inputs:i,trim:!!n.trim,options:k,force:!!n.force,recursive:!!n.recursive,debug:!!n.debug};return b!==void 0&&(y.crop=b),w!==void 0&&(y.resize=w),r!==void 0&&(y.media=r),n.to&&(y.target=I(String(n.to))),n.output!==void 0&&(y.output=String(n.output)),n.concurrency!==void 0&&(y.concurrency=j(String(n.concurrency))),y}let a=n.sharpen?1:e,c=a!==void 0?"boost":n.removeBg?"remove-background":null;if(c!==null){if(u.length>1)throw d(`Use one operation at a time \u2014 got ${u.join(" and ")}.`);let f=u[0];if(o.length>0)throw d(`${f} cannot be combined with --${o[0]}.`);if(n.maxSize!==void 0||n.pages!==void 0)throw d(`${f} cannot be combined with ${n.maxSize!==void 0?"--max-size":"--pages"}.`);if(i.length===0)throw d("No files given.",`Name an image, for example: forge photo.jpg ${f}`);let g=n.to?I(String(n.to)):"png";if(c==="remove-background"){let k=U(g);if(k)throw k}let b={background:String(n.background),keepMetadata:!!n.keepMetadata};n.quality!==void 0&&(b.quality=S(String(n.quality)));let w={kind:"extension-op",op:c,inputs:i,target:g,options:b,force:!!n.force,recursive:!!n.recursive,debug:!!n.debug};return a!==void 0&&(w.scale=a),n.output!==void 0&&(w.output=String(n.output)),n.concurrency!==void 0&&(w.concurrency=j(String(n.concurrency))),w}if(o.length===1){let f=o[0];if(i.length===0)throw d("No files given.",`Name a PDF, for example: forge doc.pdf --${f}`);if(n.separate&&f!=="extract")throw d(`--separate only applies to --extract, not --${f}.`);if(n.output!==void 0)throw d(`--output does not apply to --${f}.`,"Page operations name their own outputs, beside the source. Rename the result afterwards.");let g={kind:"pageop",action:f,inputs:i,force:!!n.force,debug:!!n.debug};if(f==="rotate"){let b=Number(n.rotate);if(!Number.isInteger(b)||b%90!==0||b===0||b>=360)throw d(`--rotate takes a multiple of 90 below 360, not "${n.rotate}".`);g.rotate=b}if((f==="extract"||f==="delete")&&(g.pages=String(n[f]),f==="extract"&&n.separate&&(g.separate=!0)),f==="split"){let b=String(n.split),w=b.match(/^every=(\d+)$/),k=b.match(/^at=([\d,\s]+)$/);if(b==="every-page")g.split={mode:"every-page"};else if(w?.[1]!==void 0){let y=Number(w[1]);if(!Number.isInteger(y)||y<1)throw d(`--split every=N takes a whole number of pages, at least 1, not "${w[1]}".`);g.split={mode:"every-n",n:y}}else if(k?.[1])g.split={mode:"points",after:k[1].split(",").map(y=>Number(y.trim()))};else throw d(`--split takes every-page, every=N or at=N,N \u2014 not "${b}".`)}return g}if(i.length===0&&!n.to&&n.quality===void 0&&n.maxSize===void 0)return{kind:"shell"};if(n.quality!==void 0&&n.maxSize!==void 0)throw d("Use either --quality or --max-size, not both.","They are two ways of asking for the same thing, and Forge will not guess which wins.");if(!n.to&&(n.quality!==void 0||n.maxSize!==void 0)){if(i.length===0)throw d("No files given.","Name a file, for example: forge photo.jpg --max-size 500kb");let f={background:String(n.background),keepMetadata:!!n.keepMetadata};r!==void 0&&(f.media=r);let g={kind:"compress",inputs:i,options:f,force:!!n.force,recursive:!!n.recursive,debug:!!n.debug};if(n.quality!==void 0&&(g.quality=S(String(n.quality))),n.maxSize!==void 0&&(g.maxBytes=M(n.maxSize)),n.output!==void 0&&(g.output=String(n.output)),t.getOptionValueSource("dpi")==="cli"){let b=Number(n.dpi);if(!Number.isInteger(b)||b<36||b>600)throw H(n.dpi);g.dpi=b}return n.concurrency!==void 0&&(g.concurrency=j(String(n.concurrency))),g}if(!n.to)throw d("No target format given.","Add --to <format>, for example: forge photo.jpg --to webp");if(i.length===0)throw d("No files given.","Name a file, a folder or a glob, for example: forge photo.jpg --to webp");let p={background:String(n.background),keepMetadata:!!n.keepMetadata};n.quality!==void 0&&(p.quality=S(String(n.quality))),r!==void 0&&(p.media=r);let O=Number(n.dpi);if(!Number.isInteger(O)||O<36||O>600)throw H(n.dpi);let _={kind:"convert",inputs:i,target:I(String(n.to)),options:p,force:!!n.force,recursive:!!n.recursive,debug:!!n.debug,dpi:O,passwordStdin:!!n.passwordStdin};return n.output!==void 0&&(_.output=String(n.output)),n.pages!==void 0&&(_.pages=String(n.pages)),n.maxSize!==void 0&&(_.maxBytes=M(n.maxSize)),n.concurrency!==void 0&&(_.concurrency=j(String(n.concurrency))),_}export{pe as a,fe as b,ct as c,dt as d};
@@ -0,0 +1,3 @@
1
+ import { createRequire as __forgeCreateRequire } from 'node:module';
2
+ const require = __forgeCreateRequire(import.meta.url);
3
+ function o(e){switch(e.op){case"convert":return e.options.crop&&e.options.resize?"cropped and resized":e.options.crop?"cropped":e.options.trim&&e.options.resize?"trimmed and resized":e.options.resize?"resized":e.options.trim?"trimmed":e.target===e.sources[0].format?"compressed":"converted";case"merge":return"merged";case"split":return"split";case"extract":return"extracted";case"delete":return"deleted from";case"rotate":return"rotated";case"boost":return e.scale===1?"sharpened":"boosted";case"remove-background":return"cut out";default:{let t=e;throw new Error(`describeResult has no verb for ${JSON.stringify(t)}`)}}}function i(e){let{job:t}=e,r=t.sources.map(n=>({path:n.path,bytes:n.bytes})),s=r.length===1&&t.outputs.length===1?r[0]:void 0;return{verb:o(t),sources:r,outputs:[...t.outputs],outputBytes:e.outputBytes,...s?{size:{from:s.bytes,to:e.outputBytes}}:{},warnings:e.warnings}}export{i as a};
@@ -0,0 +1,3 @@
1
+ import { createRequire as __forgeCreateRequire } from 'node:module';
2
+ const require = __forgeCreateRequire(import.meta.url);
3
+ import{f as m,g as i}from"./chunk-6L6C3GJU.js";import{F as f}from"./chunk-3UEQ2OX6.js";import{a as r}from"./chunk-M66BUNYO.js";function a(t){let e=Object.keys(r);return[...t].sort((o,n)=>e.indexOf(o)-e.indexOf(n))}function s(t){let e=new Set;for(let o of i)if(o.reads.has(t.format))for(let n of o.writesFor?.(t)??o.writes)r[n].keepsOnly&&n!==t.format||e.add(n);return a([...e])}function u(t){return s(t).map(e=>({id:e,label:r[e].label,hint:r[e].hint,lossy:r[e].lossy}))}function d(){let t=new Set;for(let e of i)for(let o of e.reads)t.add(o);return a([...t])}function p(){let t=new Set;for(let e of i)for(let o of e.writes)t.add(o);return a([...t])}function F(t){return m.writes.has(t)}function g(){let t=new Set(d()),e=new Set(p());return a([...new Set([...t,...e])]).map(o=>({id:o,label:r[o].label,extensions:[...r[o].extensions],read:t.has(o),write:e.has(o),lossy:r[o].lossy}))}var z=5,R=200,O=5;function $(t){return t.format==="heic"?"jpeg":s(t).includes(t.format)?t.format:"png"}function j(t,e){let o=i.find(n=>n.id==="image")?.writes;if(!o?.has(t))return f(`Cannot ${e} into ${r[t].label}; only an image format can take the edit.`,`Choose one of: ${[...o??[]].join(", ")}.`)}var T=t=>`${t.width}x${t.height}`,C=t=>"percent"in t?`${t.percent}pct`:"width"in t?`${t.width}w`:`${t.height}h`;export{s as a,u as b,d as c,p as d,F as e,g as f,z as g,R as h,O as i,$ as j,j as k,T as l,C as m};
@@ -0,0 +1,3 @@
1
+ import { createRequire as __forgeCreateRequire } from 'node:module';
2
+ const require = __forgeCreateRequire(import.meta.url);
3
+ import{b as f}from"./chunk-EXLXSKRH.js";import{B as c,C as a,D as m}from"./chunk-3UEQ2OX6.js";import{randomBytes as p}from"node:crypto";import{constants as u}from"node:fs";import{access as S,mkdir as h,rename as w,rm as y,writeFile as P}from"node:fs/promises";import{basename as g,dirname as E,extname as x,join as A}from"node:path";function N(r,e=p(6).toString("hex")){let t=x(r);return A(E(r),f(`.forge-${e}-${g(r,t)}`,t))}async function T(r){let e=E(r);try{await h(e,{recursive:!0})}catch(t){let i=a(r,t);throw i===t?m(r,t):i}try{await S(e,u.W_OK)}catch(t){throw c(r,t)}}var W=new Set(["EPERM","EBUSY","EACCES"]),l=5,B=9;async function _(r,e,t=process.platform,i=o=>new Promise(n=>setTimeout(n,o)),d=l){if(t!=="win32"){await w(r,e);return}for(let o=1;;o++)try{await w(r,e);return}catch(n){let s=n.code;if(o>=d||!s||!W.has(s))throw n;await i(Math.min(50*2**(o-1),1e3))}}async function I(r,e){await T(r);let t=N(r);try{return await P(t,e),await _(t,r),e.byteLength}catch(i){throw await y(t,{force:!0}).catch(()=>{}),a(r,i)}}export{N as a,T as b,B as c,_ as d,I as e};
@@ -0,0 +1,3 @@
1
+ import { createRequire as __forgeCreateRequire } from 'node:module';
2
+ const require = __forgeCreateRequire(import.meta.url);
3
+ import{a as E,c as w}from"./chunk-YWKMG5WO.js";import{a as M,b as j,e as S,i as P}from"./chunk-DOWMSJ6R.js";import{watch as k}from"node:fs";import{readdir as I,stat as W}from"node:fs/promises";import{join as z,resolve as x}from"node:path";function A(e,s,n){let r=x(e),c=n.settleMs??1e3,d=n.pollMs??500,i=new Set([...s].map(m=>x(m))),l=new Map,t=!1,a=!1,g=!1,p=async()=>{if(!t){if(a){g=!0;return}a=!0;try{let m=await I(r,{withFileTypes:!0}).catch(()=>[]),h=new Set;for(let o of m){if(!o.isFile()||M(o.name))continue;let f=z(r,o.name);if(h.add(f),i.has(f)||n.ignore?.(f))continue;let y=await W(f).catch(()=>{});if(!y||t)continue;let F=Date.now(),b=l.get(f);if(!b||b.size!==y.size||b.mtimeMs!==y.mtimeMs){l.set(f,{size:y.size,mtimeMs:y.mtimeMs,since:F});continue}F-b.since<c||(l.delete(f),i.add(f),n.onFile(f))}for(let o of[...i,...l.keys()])h.has(o)||(i.delete(o),l.delete(o))}finally{a=!1,g&&!t&&(g=!1,p())}}},v=setInterval(()=>{p()},d),u;try{u=k(r,{persistent:!1},()=>{p()}),u.on("error",()=>{})}catch{}return p(),{close(){t=!0,clearInterval(v),u?.close()}}}function K(e,s,n,r){let c=[],d=[];for(let i of e){let l=s[j(i)];if(!l){d.push({path:i.path,reason:R(s)});continue}let t=P(i,l,n,r);"job"in t?c.push(t.job):d.push({path:i.path,reason:t.left})}return{jobs:c,left:d}}async function G(e,s,n={}){let r=new Set,{jobs:c,left:d}=K(e.sources,s,r,n.destination);return{outcome:await w(c,{force:!1,...n.concurrency===void 0?{}:{concurrency:n.concurrency},...n.onEvent?{onEvent:n.onEvent}:{},...n.signal?{signal:n.signal}:{}}),left:d,claimed:r,jobs:c}}var O={images:"an image",pdfs:"a PDF",documents:"a document",videos:"a video",audio:"audio",other:"a file Forge reads"};function R(e){let s=Object.keys(e).filter(r=>e[r]);if(s.length===0)return"not supported";let n=s.map(r=>O[r]);return`not ${n.length===1?n[0]:`${n.slice(0,-1).join(", ")} or ${n.at(-1)}`}`}var J=(e,s)=>e==="other"?s==="text"?"a text file":"not supported":"not yet supported";function H(e){let s=E(e.concurrency),n=[],r=new Set,c=!1,d=async t=>{e.onEvent({type:"arrived",path:t}),e.onEvent({type:"phase",path:t,phase:"reading"});let a=await S(t);if(a.kind==="failed"){e.onEvent({type:"failed",path:t,error:a.failure.error});return}if(a.kind!=="source"){e.onEvent({type:"left",path:t,reason:J(a.kind,a.sniffed)});return}let{jobs:g,left:p}=K([a.source],e.answers,e.claimed,e.destination),[v]=p;if(v){e.onEvent({type:"left",path:t,reason:v.reason});return}let u=await w(g,{force:!1,concurrency:1,onEvent:o=>{o.type==="job:phase"&&"phase"in o.progress&&o.progress.phase!=="page"&&o.progress.phase!=="time"&&e.onEvent({type:"phase",path:t,phase:o.progress.phase,job:o.job})}}),[m]=u.results,h=[...u.refusals,...u.failures][0];m?e.onEvent({type:"converted",path:t,result:m}):h&&e.onEvent({type:"failed",path:t,error:h.error})},i=()=>{for(;!c&&r.size<s&&n.length>0;){let t=n.shift(),a=d(t).catch(()=>{}).finally(()=>{r.delete(a),i()});r.add(a)}},l=A(e.dir,e.known,{...e.settleMs===void 0?{}:{settleMs:e.settleMs},...e.pollMs===void 0?{}:{pollMs:e.pollMs},ignore:t=>e.claimed.has(t),onFile:t=>{n.push(t),i()}});return{async stop(){c=!0,l.close(),n.length=0,await Promise.all([...r])}}}export{K as a,G as b,H as c};
@@ -0,0 +1,21 @@
1
+ import { createRequire as __forgeCreateRequire } from 'node:module';
2
+ const require = __forgeCreateRequire(import.meta.url);
3
+ import{d as l,e as f}from"./chunk-SMBK6BTC.js";import{f as g}from"./chunk-EXLXSKRH.js";import{execFile as S}from"node:child_process";import{mkdir as v,rename as N,rm as O}from"node:fs/promises";import{join as d}from"node:path";import{promisify as k}from"node:util";var F=k(S),j=async(e,r)=>{let{stdout:t}=await F("osascript",["-l","JavaScript","-e",e,...r],{timeout:5e3});return t.trim()},b=[{uti:"public.png",ext:"png"},{uti:"public.jpeg",ext:"jpg"},{uti:"org.webmproject.webp",ext:"webp"},{uti:"public.heic",ext:"heic"},{uti:"public.avif",ext:"avif"},{uti:"com.compuserve.gif",ext:"gif"},{uti:"public.tiff",ext:"tiff"}];function I(e){let r=e.includes("public.file-url");return b.find(t=>e.includes(t.uti)&&!(r&&t.uti==="public.tiff"))?.uti??null}function X(e=process.platform,r=process.env){return e==="darwin"&&!r.SSH_CONNECTION&&!r.SSH_TTY}var T={png:"public.png",jpeg:"public.jpeg",webp:"org.webmproject.webp",heic:"public.heic",avif:"public.avif",gif:"com.compuserve.gif",tiff:"public.tiff"};function $(e){return T[e]??"public.data"}var A=`ObjC.import('AppKit')
4
+ const pb = $.NSPasteboard.generalPasteboard
5
+ JSON.stringify({ types: ObjC.deepUnwrap(pb.types) || [], count: Number(pb.changeCount) })`,E=`function run(argv) {
6
+ ObjC.import('AppKit')
7
+ const pb = $.NSPasteboard.generalPasteboard
8
+ const data = pb.dataForType(argv[0])
9
+ if (data.isNil()) return JSON.stringify({ ok: false })
10
+ const ok = data.writeToFileAtomically(argv[1], true)
11
+ return JSON.stringify({ ok: ok, count: Number(pb.changeCount) })
12
+ }`,J=`function run(argv) {
13
+ ObjC.import('AppKit')
14
+ const pb = $.NSPasteboard.generalPasteboard
15
+ const item = $.NSPasteboardItem.alloc.init
16
+ item.setDataForType($.NSData.dataWithContentsOfFile(argv[0]), argv[1])
17
+ item.setStringForType($.NSURL.fileURLWithPath(argv[0]).absoluteString, 'public.file-url')
18
+ pb.clearContents
19
+ pb.writeObjects($.NSArray.arrayWithObject(item))
20
+ return JSON.stringify({ count: Number(pb.changeCount) })
21
+ }`;function z(e=j){let r=async()=>{try{let{types:t,count:n}=JSON.parse(await e(A,[]));return{changeCount:n,image:I(t),text:t.includes("public.utf8-plain-text")}}catch{return{changeCount:-1,image:null,text:!1}}};return{peek:r,async read(t){let{image:n}=await r(),a=b.find(C=>C.uti===n);if(!a)return null;await v(t,{recursive:!0});let i=d(t,`Copied image.${a.ext}`),s=JSON.parse(await e(E,[a.uti,i]));if(!s.ok||s.count===void 0)return null;if(a.uti!=="public.tiff")return{path:i,changeCount:s.count};let{default:x}=await import("sharp"),c=d(t,"Copied image.png");return await x(i).keepIccProfile().png().toFile(`${c}.part`),await N(`${c}.part`,c),await O(i,{force:!0}),{path:c,changeCount:s.count}},async write(t,n){let{count:a}=JSON.parse(await e(J,[t,$(n)]));return a}}}import{randomBytes as h}from"node:crypto";import{copyFile as R,mkdir as y,readdir as P,readFile as D,rename as _,rm as p,stat as K}from"node:fs/promises";import{tmpdir as U}from"node:os";import{extname as u,join as o}from"node:path";function m(){return o(U(),"forge-clip")}var W=5,w={".png":"png",".jpg":"jpeg",".jpeg":"jpeg",".webp":"webp",".heic":"heic",".avif":"avif",".gif":"gif",".tiff":"tiff"};async function at(e,r=m()){let t=`${Date.now().toString(36)}-${h(3).toString("hex")}`,n=o(r,t),a=await e.read(o(n,"in"));if(!a)return await p(n,{recursive:!0,force:!0}),null;let i=o(n,"out");await y(i,{recursive:!0}),await L(r,a.path);let s=o(n,"in","Copied image");return await _(a.path,s),await B(r,t),{source:s,outDir:i,changeCount:a.changeCount}}async function L(e,r){let t=o(e,"last"),n=`Copied image${u(r)}`,a=o(e,`.last-${h(4).toString("hex")}`);await y(a,{recursive:!0}),await R(r,o(a,n)),await p(t,{recursive:!0,force:!0}),await l(a,t)}async function B(e,r){let t=await P(e,{withFileTypes:!0}).catch(()=>[]),a=(await Promise.all(t.filter(i=>i.isDirectory()&&i.name!=="last"&&!i.name.startsWith(".")).map(async i=>({name:i.name,at:(await K(o(e,i.name)).catch(()=>null))?.mtimeMs??0})))).filter(i=>i.name!==r).sort((i,s)=>s.at-i.at).slice(W-1);await Promise.all(a.map(i=>p(o(e,i.name),{recursive:!0,force:!0})))}async function M(e=m()){let r=o(e,"last"),t=(await P(r).catch(()=>[])).find(n=>w[u(n).toLowerCase()]!==void 0);return t===void 0?null:{path:o(r,t),format:w[u(t).toLowerCase()]}}async function nt(e,r,t,n){let{changeCount:a}=await e.peek();return a!==r.changeCount?"changed":(await e.write(t,n),"placed")}async function ot(e,r=m()){let t=await M(r);return t?(await e.write(t.path,t.format),!0):!1}async function st(e,r){let t=g(o(r,`Copied image${u(e)}`));return await f(t,await D(e)),t}export{X as a,z as b,at as c,nt as d,ot as e,st as f};