slack-term 1.31.6 → 1.32.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 (3) hide show
  1. package/dist/cli.js +112 -106
  2. package/package.json +1 -1
  3. package/ts/cli.ts +178 -19
package/dist/cli.js CHANGED
@@ -1,21 +1,21 @@
1
1
  #!/usr/bin/env bun
2
2
  // @bun
3
- import{createRequire as pu}from"node:module";var ou=Object.create;var{getPrototypeOf:au,defineProperty:ni,getOwnPropertyNames:cu}=Object;var uu=Object.prototype.hasOwnProperty;function lu(e){return this[e]}var fu,du,si=(e,t,n)=>{var r=e!=null&&typeof e==="object";if(r){var s=t?fu??=new WeakMap:du??=new WeakMap,i=s.get(e);if(i)return i}n=e!=null?ou(au(e)):{};let o=t||!e||!e.__esModule?ni(n,"default",{value:e,enumerable:!0}):n;if(e&&typeof e==="object"||typeof e==="function"){for(let a of cu(e))if(!uu.call(o,a))ni(o,a,{get:lu.bind(e,a),enumerable:!0})}if(r)s.set(e,o);return o};var ri=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var Xe=pu(import.meta.url);var Ci=ri(function(dp,Fi){Fi.exports=()=>/[#*0-9]\uFE0F?\u20E3|[\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23ED-\u23EF\u23F1\u23F2\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB\u25FC\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u2648-\u2653\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u267F\u2692\u2694-\u2697\u2699\u269B\u269C\u26A0\u26A7\u26AA\u26B0\u26B1\u26BD\u26BE\u26C4\u26C8\u26CF\u26D1\u26E9\u26F0-\u26F5\u26F7\u26F8\u26FA\u2702\u2708\u2709\u270F\u2712\u2714\u2716\u271D\u2721\u2733\u2734\u2744\u2747\u2757\u2763\u27A1\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B55\u3030\u303D\u3297\u3299]\uFE0F?|[\u261D\u270C\u270D](?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?|[\u270A\u270B](?:\uD83C[\uDFFB-\uDFFF])?|[\u23E9-\u23EC\u23F0\u23F3\u25FD\u2693\u26A1\u26AB\u26C5\u26CE\u26D4\u26EA\u26FD\u2705\u2728\u274C\u274E\u2753-\u2755\u2795-\u2797\u27B0\u27BF\u2B50]|\u26D3\uFE0F?(?:\u200D\uD83D\uDCA5)?|\u26F9(?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?(?:\u200D[\u2640\u2642]\uFE0F?)?|\u2764\uFE0F?(?:\u200D(?:\uD83D\uDD25|\uD83E\uDE79))?|\uD83C(?:[\uDC04\uDD70\uDD71\uDD7E\uDD7F\uDE02\uDE37\uDF21\uDF24-\uDF2C\uDF36\uDF7D\uDF96\uDF97\uDF99-\uDF9B\uDF9E\uDF9F\uDFCD\uDFCE\uDFD4-\uDFDF\uDFF5\uDFF7]\uFE0F?|[\uDF85\uDFC2\uDFC7](?:\uD83C[\uDFFB-\uDFFF])?|[\uDFC4\uDFCA](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDFCB\uDFCC](?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDCCF\uDD8E\uDD91-\uDD9A\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF43\uDF45-\uDF4A\uDF4C-\uDF7C\uDF7E-\uDF84\uDF86-\uDF93\uDFA0-\uDFC1\uDFC5\uDFC6\uDFC8\uDFC9\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF8-\uDFFF]|\uDDE6\uD83C[\uDDE8-\uDDEC\uDDEE\uDDF1\uDDF2\uDDF4\uDDF6-\uDDFA\uDDFC\uDDFD\uDDFF]|\uDDE7\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEF\uDDF1-\uDDF4\uDDF6-\uDDF9\uDDFB\uDDFC\uDDFE\uDDFF]|\uDDE8\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDEE\uDDF0-\uDDF7\uDDFA-\uDDFF]|\uDDE9\uD83C[\uDDEA\uDDEC\uDDEF\uDDF0\uDDF2\uDDF4\uDDFF]|\uDDEA\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDED\uDDF7-\uDDFA]|\uDDEB\uD83C[\uDDEE-\uDDF0\uDDF2\uDDF4\uDDF7]|\uDDEC\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEE\uDDF1-\uDDF3\uDDF5-\uDDFA\uDDFC\uDDFE]|\uDDED\uD83C[\uDDF0\uDDF2\uDDF3\uDDF7\uDDF9\uDDFA]|\uDDEE\uD83C[\uDDE8-\uDDEA\uDDF1-\uDDF4\uDDF6-\uDDF9]|\uDDEF\uD83C[\uDDEA\uDDF2\uDDF4\uDDF5]|\uDDF0\uD83C[\uDDEA\uDDEC-\uDDEE\uDDF2\uDDF3\uDDF5\uDDF7\uDDFC\uDDFE\uDDFF]|\uDDF1\uD83C[\uDDE6-\uDDE8\uDDEE\uDDF0\uDDF7-\uDDFB\uDDFE]|\uDDF2\uD83C[\uDDE6\uDDE8-\uDDED\uDDF0-\uDDFF]|\uDDF3\uD83C[\uDDE6\uDDE8\uDDEA-\uDDEC\uDDEE\uDDF1\uDDF4\uDDF5\uDDF7\uDDFA\uDDFF]|\uDDF4\uD83C\uDDF2|\uDDF5\uD83C[\uDDE6\uDDEA-\uDDED\uDDF0-\uDDF3\uDDF7-\uDDF9\uDDFC\uDDFE]|\uDDF6\uD83C\uDDE6|\uDDF7\uD83C[\uDDEA\uDDF4\uDDF8\uDDFA\uDDFC]|\uDDF8\uD83C[\uDDE6-\uDDEA\uDDEC-\uDDF4\uDDF7-\uDDF9\uDDFB\uDDFD-\uDDFF]|\uDDF9\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDED\uDDEF-\uDDF4\uDDF7\uDDF9\uDDFB\uDDFC\uDDFF]|\uDDFA\uD83C[\uDDE6\uDDEC\uDDF2\uDDF3\uDDF8\uDDFE\uDDFF]|\uDDFB\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDEE\uDDF3\uDDFA]|\uDDFC\uD83C[\uDDEB\uDDF8]|\uDDFD\uD83C\uDDF0|\uDDFE\uD83C[\uDDEA\uDDF9]|\uDDFF\uD83C[\uDDE6\uDDF2\uDDFC]|\uDF44(?:\u200D\uD83D\uDFEB)?|\uDF4B(?:\u200D\uD83D\uDFE9)?|\uDFC3(?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D(?:[\u2640\u2642]\uFE0F?(?:\u200D\u27A1\uFE0F?)?|\u27A1\uFE0F?))?|\uDFF3\uFE0F?(?:\u200D(?:\u26A7\uFE0F?|\uD83C\uDF08))?|\uDFF4(?:\u200D\u2620\uFE0F?|\uDB40\uDC67\uDB40\uDC62\uDB40(?:\uDC65\uDB40\uDC6E\uDB40\uDC67|\uDC73\uDB40\uDC63\uDB40\uDC74|\uDC77\uDB40\uDC6C\uDB40\uDC73)\uDB40\uDC7F)?)|\uD83D(?:[\uDC3F\uDCFD\uDD49\uDD4A\uDD6F\uDD70\uDD73\uDD76-\uDD79\uDD87\uDD8A-\uDD8D\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA\uDECB\uDECD-\uDECF\uDEE0-\uDEE5\uDEE9\uDEF0\uDEF3]\uFE0F?|[\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDC8F\uDC91\uDCAA\uDD7A\uDD95\uDD96\uDE4C\uDE4F\uDEC0\uDECC](?:\uD83C[\uDFFB-\uDFFF])?|[\uDC6E-\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4\uDEB5](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDD74\uDD90](?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?|[\uDC00-\uDC07\uDC09-\uDC14\uDC16-\uDC25\uDC27-\uDC3A\uDC3C-\uDC3E\uDC40\uDC44\uDC45\uDC51-\uDC65\uDC6A\uDC79-\uDC7B\uDC7D-\uDC80\uDC84\uDC88-\uDC8E\uDC90\uDC92-\uDCA9\uDCAB-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDDA4\uDDFB-\uDE2D\uDE2F-\uDE34\uDE37-\uDE41\uDE43\uDE44\uDE48-\uDE4A\uDE80-\uDEA2\uDEA4-\uDEB3\uDEB7-\uDEBF\uDEC1-\uDEC5\uDED0-\uDED2\uDED5-\uDED8\uDEDC-\uDEDF\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB\uDFF0]|\uDC08(?:\u200D\u2B1B)?|\uDC15(?:\u200D\uD83E\uDDBA)?|\uDC26(?:\u200D(?:\u2B1B|\uD83D\uDD25))?|\uDC3B(?:\u200D\u2744\uFE0F?)?|\uDC41\uFE0F?(?:\u200D\uD83D\uDDE8\uFE0F?)?|\uDC68(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDC68\uDC69]\u200D\uD83D(?:\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?)|[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?)|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]))|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83D\uDC68\uD83C[\uDFFC-\uDFFF])|\uD83E(?:[\uDD1D\uDEEF]\u200D\uD83D\uDC68\uD83C[\uDFFC-\uDFFF]|[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83D\uDC68\uD83C[\uDFFB\uDFFD-\uDFFF])|\uD83E(?:[\uDD1D\uDEEF]\u200D\uD83D\uDC68\uD83C[\uDFFB\uDFFD-\uDFFF]|[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83D\uDC68\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|\uD83E(?:[\uDD1D\uDEEF]\u200D\uD83D\uDC68\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF]|[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83D\uDC68\uD83C[\uDFFB-\uDFFD\uDFFF])|\uD83E(?:[\uDD1D\uDEEF]\u200D\uD83D\uDC68\uD83C[\uDFFB-\uDFFD\uDFFF]|[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83D\uDC68\uD83C[\uDFFB-\uDFFE])|\uD83E(?:[\uDD1D\uDEEF]\u200D\uD83D\uDC68\uD83C[\uDFFB-\uDFFE]|[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3])))?))?|\uDC69(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?[\uDC68\uDC69]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?|\uDC69\u200D\uD83D(?:\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?))|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]))|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83D\uDC69\uD83C[\uDFFC-\uDFFF])|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFC-\uDFFF]|\uDEEF\u200D\uD83D\uDC69\uD83C[\uDFFC-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83D\uDC69\uD83C[\uDFFB\uDFFD-\uDFFF])|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB\uDFFD-\uDFFF]|\uDEEF\u200D\uD83D\uDC69\uD83C[\uDFFB\uDFFD-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83D\uDC69\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF]|\uDEEF\u200D\uD83D\uDC69\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83D\uDC69\uD83C[\uDFFB-\uDFFD\uDFFF])|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB-\uDFFD\uDFFF]|\uDEEF\u200D\uD83D\uDC69\uD83C[\uDFFB-\uDFFD\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83D\uDC69\uD83C[\uDFFB-\uDFFE])|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB-\uDFFE]|\uDEEF\u200D\uD83D\uDC69\uD83C[\uDFFB-\uDFFE])))?))?|\uDD75(?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?(?:\u200D[\u2640\u2642]\uFE0F?)?|\uDE2E(?:\u200D\uD83D\uDCA8)?|\uDE35(?:\u200D\uD83D\uDCAB)?|\uDE36(?:\u200D\uD83C\uDF2B\uFE0F?)?|\uDE42(?:\u200D[\u2194\u2195]\uFE0F?)?|\uDEB6(?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D(?:[\u2640\u2642]\uFE0F?(?:\u200D\u27A1\uFE0F?)?|\u27A1\uFE0F?))?)|\uD83E(?:[\uDD0C\uDD0F\uDD18-\uDD1F\uDD30-\uDD34\uDD36\uDD77\uDDB5\uDDB6\uDDBB\uDDD2\uDDD3\uDDD5\uDEC3-\uDEC5\uDEF0\uDEF2-\uDEF8](?:\uD83C[\uDFFB-\uDFFF])?|[\uDD26\uDD35\uDD37-\uDD39\uDD3C-\uDD3E\uDDB8\uDDB9\uDDCD\uDDCF\uDDD4\uDDD6-\uDDDD](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDDDE\uDDDF](?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDD0D\uDD0E\uDD10-\uDD17\uDD20-\uDD25\uDD27-\uDD2F\uDD3A\uDD3F-\uDD45\uDD47-\uDD76\uDD78-\uDDB4\uDDB7\uDDBA\uDDBC-\uDDCC\uDDD0\uDDE0-\uDDFF\uDE70-\uDE7C\uDE80-\uDE8A\uDE8E-\uDEC2\uDEC6\uDEC8\uDECD-\uDEDC\uDEDF-\uDEEA\uDEEF]|\uDDCE(?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D(?:[\u2640\u2642]\uFE0F?(?:\u200D\u27A1\uFE0F?)?|\u27A1\uFE0F?))?|\uDDD1(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3\uDE70]|\uDD1D\u200D\uD83E\uDDD1|\uDDD1\u200D\uD83E\uDDD2(?:\u200D\uD83E\uDDD2)?|\uDDD2(?:\u200D\uD83E\uDDD2)?))|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFC-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83E\uDDD1\uD83C[\uDFFC-\uDFFF])|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3\uDE70]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF]|\uDEEF\u200D\uD83E\uDDD1\uD83C[\uDFFC-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB\uDFFD-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83E\uDDD1\uD83C[\uDFFB\uDFFD-\uDFFF])|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3\uDE70]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF]|\uDEEF\u200D\uD83E\uDDD1\uD83C[\uDFFB\uDFFD-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83E\uDDD1\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3\uDE70]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF]|\uDEEF\u200D\uD83E\uDDD1\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB-\uDFFD\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFD\uDFFF])|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3\uDE70]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF]|\uDEEF\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFD\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB-\uDFFE]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFE])|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3\uDE70]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF]|\uDEEF\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFE])))?))?|\uDEF1(?:\uD83C(?:\uDFFB(?:\u200D\uD83E\uDEF2\uD83C[\uDFFC-\uDFFF])?|\uDFFC(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB\uDFFD-\uDFFF])?|\uDFFD(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])?|\uDFFE(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB-\uDFFD\uDFFF])?|\uDFFF(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB-\uDFFE])?))?)/g});var Yi=ri(function(eh,qi){qi.exports=function(t){if(t===void 0)t=2;if(t>=Error.stackTraceLimit)throw TypeError("getCallerFile(position) requires position be less then Error.stackTraceLimit but position was: `"+t+"` and Error.stackTraceLimit was: `"+Error.stackTraceLimit+"`");var n=Error.prepareStackTrace;Error.prepareStackTrace=function(s,i){return i};var r=Error().stack;if(Error.prepareStackTrace=n,r!==null&&typeof r==="object")return r[t]?r[t].getFileName():void 0}});import{createHash as Kf}from"crypto";import{existsSync as Gc,readFileSync as Jf,mkdirSync as zf,writeFileSync as Vc}from"fs";import{homedir as zc}from"os";import{join as ft}from"path";import{notStrictEqual as Zu,strictEqual as Qu}from"assert";var hu={right:Du,center:yu};class oi{constructor(e){var t;this.width=e.width,this.wrap=(t=e.wrap)!==null&&t!==void 0?t:!0,this.rows=[]}span(...e){let t=this.div(...e);t.span=!0}resetOutput(){this.rows=[]}div(...e){if(e.length===0)this.div("");if(this.wrap&&this.shouldApplyLayoutDSL(...e)&&typeof e[0]==="string")return this.applyLayoutDSL(e[0]);let t=e.map((n)=>{if(typeof n==="string")return this.colFromString(n);return n});return this.rows.push(t),t}shouldApplyLayoutDSL(...e){return e.length===1&&typeof e[0]==="string"&&/[\t\n]/.test(e[0])}applyLayoutDSL(e){let t=e.split(`
4
- `).map((r)=>r.split("\t")),n=0;return t.forEach((r)=>{if(r.length>1&&ke.stringWidth(r[0])>n)n=Math.min(Math.floor(this.width*0.5),ke.stringWidth(r[0]))}),t.forEach((r)=>{this.div(...r.map((s,i)=>({text:s.trim(),padding:this.measurePadding(s),width:i===0&&r.length>1?n:void 0})))}),this.rows[this.rows.length-1]}colFromString(e){return{text:e,padding:this.measurePadding(e)}}measurePadding(e){let t=ke.stripAnsi(e);return[0,t.match(/\s*$/)[0].length,0,t.match(/^\s*/)[0].length]}toString(){let e=[];return this.rows.forEach((t)=>{this.rowToString(t,e)}),e.filter((t)=>!t.hidden).map((t)=>t.text).join(`
5
- `)}rowToString(e,t){return this.rasterize(e).forEach((n,r)=>{let s="";n.forEach((i,o)=>{let{width:a}=e[o],c=this.negatePadding(e[o]),u=i;if(c>ke.stringWidth(i))u+=" ".repeat(c-ke.stringWidth(i));if(e[o].align&&e[o].align!=="left"&&this.wrap){let l=hu[e[o].align];if(u=l(u,c),ke.stringWidth(u)<c)u+=" ".repeat((a||0)-ke.stringWidth(u)-1)}let f=e[o].padding||[0,0,0,0];if(f[3])s+=" ".repeat(f[3]);if(s+=ii(e[o],u,"| "),s+=u,s+=ii(e[o],u," |"),f[1])s+=" ".repeat(f[1]);if(r===0&&t.length>0)s=this.renderInline(s,t[t.length-1])}),t.push({text:s.replace(/ +$/,""),span:e.span})}),t}renderInline(e,t){let n=e.match(/^ */),r=n?n[0].length:0,s=t.text,i=ke.stringWidth(s.trimRight());if(!t.span)return e;if(!this.wrap)return t.hidden=!0,s+e;if(r<i)return e;return t.hidden=!0,s.trimRight()+" ".repeat(r-i)+e.trimLeft()}rasterize(e){let t=[],n=this.columnWidths(e),r;return e.forEach((s,i)=>{if(s.width=n[i],this.wrap)r=ke.wrap(s.text,this.negatePadding(s),{hard:!0}).split(`
3
+ import{createRequire as Du}from"node:module";var lu=Object.create;var{getPrototypeOf:fu,defineProperty:si,getOwnPropertyNames:du}=Object;var pu=Object.prototype.hasOwnProperty;function hu(e){return this[e]}var gu,mu,ri=(e,t,n)=>{var r=e!=null&&typeof e==="object";if(r){var s=t?gu??=new WeakMap:mu??=new WeakMap,i=s.get(e);if(i)return i}n=e!=null?lu(fu(e)):{};let o=t||!e||!e.__esModule?si(n,"default",{value:e,enumerable:!0}):n;if(e&&typeof e==="object"||typeof e==="function"){for(let a of du(e))if(!pu.call(o,a))si(o,a,{get:hu.bind(e,a),enumerable:!0})}if(r)s.set(e,o);return o};var ii=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var Xe=Du(import.meta.url);var Ei=ii(function(hp,Ci){Ci.exports=()=>/[#*0-9]\uFE0F?\u20E3|[\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23ED-\u23EF\u23F1\u23F2\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB\u25FC\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u2648-\u2653\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u267F\u2692\u2694-\u2697\u2699\u269B\u269C\u26A0\u26A7\u26AA\u26B0\u26B1\u26BD\u26BE\u26C4\u26C8\u26CF\u26D1\u26E9\u26F0-\u26F5\u26F7\u26F8\u26FA\u2702\u2708\u2709\u270F\u2712\u2714\u2716\u271D\u2721\u2733\u2734\u2744\u2747\u2757\u2763\u27A1\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B55\u3030\u303D\u3297\u3299]\uFE0F?|[\u261D\u270C\u270D](?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?|[\u270A\u270B](?:\uD83C[\uDFFB-\uDFFF])?|[\u23E9-\u23EC\u23F0\u23F3\u25FD\u2693\u26A1\u26AB\u26C5\u26CE\u26D4\u26EA\u26FD\u2705\u2728\u274C\u274E\u2753-\u2755\u2795-\u2797\u27B0\u27BF\u2B50]|\u26D3\uFE0F?(?:\u200D\uD83D\uDCA5)?|\u26F9(?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?(?:\u200D[\u2640\u2642]\uFE0F?)?|\u2764\uFE0F?(?:\u200D(?:\uD83D\uDD25|\uD83E\uDE79))?|\uD83C(?:[\uDC04\uDD70\uDD71\uDD7E\uDD7F\uDE02\uDE37\uDF21\uDF24-\uDF2C\uDF36\uDF7D\uDF96\uDF97\uDF99-\uDF9B\uDF9E\uDF9F\uDFCD\uDFCE\uDFD4-\uDFDF\uDFF5\uDFF7]\uFE0F?|[\uDF85\uDFC2\uDFC7](?:\uD83C[\uDFFB-\uDFFF])?|[\uDFC4\uDFCA](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDFCB\uDFCC](?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDCCF\uDD8E\uDD91-\uDD9A\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF43\uDF45-\uDF4A\uDF4C-\uDF7C\uDF7E-\uDF84\uDF86-\uDF93\uDFA0-\uDFC1\uDFC5\uDFC6\uDFC8\uDFC9\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF8-\uDFFF]|\uDDE6\uD83C[\uDDE8-\uDDEC\uDDEE\uDDF1\uDDF2\uDDF4\uDDF6-\uDDFA\uDDFC\uDDFD\uDDFF]|\uDDE7\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEF\uDDF1-\uDDF4\uDDF6-\uDDF9\uDDFB\uDDFC\uDDFE\uDDFF]|\uDDE8\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDEE\uDDF0-\uDDF7\uDDFA-\uDDFF]|\uDDE9\uD83C[\uDDEA\uDDEC\uDDEF\uDDF0\uDDF2\uDDF4\uDDFF]|\uDDEA\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDED\uDDF7-\uDDFA]|\uDDEB\uD83C[\uDDEE-\uDDF0\uDDF2\uDDF4\uDDF7]|\uDDEC\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEE\uDDF1-\uDDF3\uDDF5-\uDDFA\uDDFC\uDDFE]|\uDDED\uD83C[\uDDF0\uDDF2\uDDF3\uDDF7\uDDF9\uDDFA]|\uDDEE\uD83C[\uDDE8-\uDDEA\uDDF1-\uDDF4\uDDF6-\uDDF9]|\uDDEF\uD83C[\uDDEA\uDDF2\uDDF4\uDDF5]|\uDDF0\uD83C[\uDDEA\uDDEC-\uDDEE\uDDF2\uDDF3\uDDF5\uDDF7\uDDFC\uDDFE\uDDFF]|\uDDF1\uD83C[\uDDE6-\uDDE8\uDDEE\uDDF0\uDDF7-\uDDFB\uDDFE]|\uDDF2\uD83C[\uDDE6\uDDE8-\uDDED\uDDF0-\uDDFF]|\uDDF3\uD83C[\uDDE6\uDDE8\uDDEA-\uDDEC\uDDEE\uDDF1\uDDF4\uDDF5\uDDF7\uDDFA\uDDFF]|\uDDF4\uD83C\uDDF2|\uDDF5\uD83C[\uDDE6\uDDEA-\uDDED\uDDF0-\uDDF3\uDDF7-\uDDF9\uDDFC\uDDFE]|\uDDF6\uD83C\uDDE6|\uDDF7\uD83C[\uDDEA\uDDF4\uDDF8\uDDFA\uDDFC]|\uDDF8\uD83C[\uDDE6-\uDDEA\uDDEC-\uDDF4\uDDF7-\uDDF9\uDDFB\uDDFD-\uDDFF]|\uDDF9\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDED\uDDEF-\uDDF4\uDDF7\uDDF9\uDDFB\uDDFC\uDDFF]|\uDDFA\uD83C[\uDDE6\uDDEC\uDDF2\uDDF3\uDDF8\uDDFE\uDDFF]|\uDDFB\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDEE\uDDF3\uDDFA]|\uDDFC\uD83C[\uDDEB\uDDF8]|\uDDFD\uD83C\uDDF0|\uDDFE\uD83C[\uDDEA\uDDF9]|\uDDFF\uD83C[\uDDE6\uDDF2\uDDFC]|\uDF44(?:\u200D\uD83D\uDFEB)?|\uDF4B(?:\u200D\uD83D\uDFE9)?|\uDFC3(?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D(?:[\u2640\u2642]\uFE0F?(?:\u200D\u27A1\uFE0F?)?|\u27A1\uFE0F?))?|\uDFF3\uFE0F?(?:\u200D(?:\u26A7\uFE0F?|\uD83C\uDF08))?|\uDFF4(?:\u200D\u2620\uFE0F?|\uDB40\uDC67\uDB40\uDC62\uDB40(?:\uDC65\uDB40\uDC6E\uDB40\uDC67|\uDC73\uDB40\uDC63\uDB40\uDC74|\uDC77\uDB40\uDC6C\uDB40\uDC73)\uDB40\uDC7F)?)|\uD83D(?:[\uDC3F\uDCFD\uDD49\uDD4A\uDD6F\uDD70\uDD73\uDD76-\uDD79\uDD87\uDD8A-\uDD8D\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA\uDECB\uDECD-\uDECF\uDEE0-\uDEE5\uDEE9\uDEF0\uDEF3]\uFE0F?|[\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDC8F\uDC91\uDCAA\uDD7A\uDD95\uDD96\uDE4C\uDE4F\uDEC0\uDECC](?:\uD83C[\uDFFB-\uDFFF])?|[\uDC6E-\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4\uDEB5](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDD74\uDD90](?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?|[\uDC00-\uDC07\uDC09-\uDC14\uDC16-\uDC25\uDC27-\uDC3A\uDC3C-\uDC3E\uDC40\uDC44\uDC45\uDC51-\uDC65\uDC6A\uDC79-\uDC7B\uDC7D-\uDC80\uDC84\uDC88-\uDC8E\uDC90\uDC92-\uDCA9\uDCAB-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDDA4\uDDFB-\uDE2D\uDE2F-\uDE34\uDE37-\uDE41\uDE43\uDE44\uDE48-\uDE4A\uDE80-\uDEA2\uDEA4-\uDEB3\uDEB7-\uDEBF\uDEC1-\uDEC5\uDED0-\uDED2\uDED5-\uDED8\uDEDC-\uDEDF\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB\uDFF0]|\uDC08(?:\u200D\u2B1B)?|\uDC15(?:\u200D\uD83E\uDDBA)?|\uDC26(?:\u200D(?:\u2B1B|\uD83D\uDD25))?|\uDC3B(?:\u200D\u2744\uFE0F?)?|\uDC41\uFE0F?(?:\u200D\uD83D\uDDE8\uFE0F?)?|\uDC68(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDC68\uDC69]\u200D\uD83D(?:\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?)|[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?)|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]))|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83D\uDC68\uD83C[\uDFFC-\uDFFF])|\uD83E(?:[\uDD1D\uDEEF]\u200D\uD83D\uDC68\uD83C[\uDFFC-\uDFFF]|[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83D\uDC68\uD83C[\uDFFB\uDFFD-\uDFFF])|\uD83E(?:[\uDD1D\uDEEF]\u200D\uD83D\uDC68\uD83C[\uDFFB\uDFFD-\uDFFF]|[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83D\uDC68\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|\uD83E(?:[\uDD1D\uDEEF]\u200D\uD83D\uDC68\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF]|[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83D\uDC68\uD83C[\uDFFB-\uDFFD\uDFFF])|\uD83E(?:[\uDD1D\uDEEF]\u200D\uD83D\uDC68\uD83C[\uDFFB-\uDFFD\uDFFF]|[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83D\uDC68\uD83C[\uDFFB-\uDFFE])|\uD83E(?:[\uDD1D\uDEEF]\u200D\uD83D\uDC68\uD83C[\uDFFB-\uDFFE]|[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3])))?))?|\uDC69(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?[\uDC68\uDC69]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?|\uDC69\u200D\uD83D(?:\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?))|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]))|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83D\uDC69\uD83C[\uDFFC-\uDFFF])|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFC-\uDFFF]|\uDEEF\u200D\uD83D\uDC69\uD83C[\uDFFC-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83D\uDC69\uD83C[\uDFFB\uDFFD-\uDFFF])|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB\uDFFD-\uDFFF]|\uDEEF\u200D\uD83D\uDC69\uD83C[\uDFFB\uDFFD-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83D\uDC69\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF]|\uDEEF\u200D\uD83D\uDC69\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83D\uDC69\uD83C[\uDFFB-\uDFFD\uDFFF])|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB-\uDFFD\uDFFF]|\uDEEF\u200D\uD83D\uDC69\uD83C[\uDFFB-\uDFFD\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83D\uDC69\uD83C[\uDFFB-\uDFFE])|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB-\uDFFE]|\uDEEF\u200D\uD83D\uDC69\uD83C[\uDFFB-\uDFFE])))?))?|\uDD75(?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?(?:\u200D[\u2640\u2642]\uFE0F?)?|\uDE2E(?:\u200D\uD83D\uDCA8)?|\uDE35(?:\u200D\uD83D\uDCAB)?|\uDE36(?:\u200D\uD83C\uDF2B\uFE0F?)?|\uDE42(?:\u200D[\u2194\u2195]\uFE0F?)?|\uDEB6(?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D(?:[\u2640\u2642]\uFE0F?(?:\u200D\u27A1\uFE0F?)?|\u27A1\uFE0F?))?)|\uD83E(?:[\uDD0C\uDD0F\uDD18-\uDD1F\uDD30-\uDD34\uDD36\uDD77\uDDB5\uDDB6\uDDBB\uDDD2\uDDD3\uDDD5\uDEC3-\uDEC5\uDEF0\uDEF2-\uDEF8](?:\uD83C[\uDFFB-\uDFFF])?|[\uDD26\uDD35\uDD37-\uDD39\uDD3C-\uDD3E\uDDB8\uDDB9\uDDCD\uDDCF\uDDD4\uDDD6-\uDDDD](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDDDE\uDDDF](?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDD0D\uDD0E\uDD10-\uDD17\uDD20-\uDD25\uDD27-\uDD2F\uDD3A\uDD3F-\uDD45\uDD47-\uDD76\uDD78-\uDDB4\uDDB7\uDDBA\uDDBC-\uDDCC\uDDD0\uDDE0-\uDDFF\uDE70-\uDE7C\uDE80-\uDE8A\uDE8E-\uDEC2\uDEC6\uDEC8\uDECD-\uDEDC\uDEDF-\uDEEA\uDEEF]|\uDDCE(?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D(?:[\u2640\u2642]\uFE0F?(?:\u200D\u27A1\uFE0F?)?|\u27A1\uFE0F?))?|\uDDD1(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3\uDE70]|\uDD1D\u200D\uD83E\uDDD1|\uDDD1\u200D\uD83E\uDDD2(?:\u200D\uD83E\uDDD2)?|\uDDD2(?:\u200D\uD83E\uDDD2)?))|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFC-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83E\uDDD1\uD83C[\uDFFC-\uDFFF])|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3\uDE70]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF]|\uDEEF\u200D\uD83E\uDDD1\uD83C[\uDFFC-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB\uDFFD-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83E\uDDD1\uD83C[\uDFFB\uDFFD-\uDFFF])|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3\uDE70]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF]|\uDEEF\u200D\uD83E\uDDD1\uD83C[\uDFFB\uDFFD-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83E\uDDD1\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3\uDE70]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF]|\uDEEF\u200D\uD83E\uDDD1\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB-\uDFFD\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFD\uDFFF])|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3\uDE70]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF]|\uDEEF\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFD\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB-\uDFFE]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC30\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFE])|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3\uDE70]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF]|\uDEEF\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFE])))?))?|\uDEF1(?:\uD83C(?:\uDFFB(?:\u200D\uD83E\uDEF2\uD83C[\uDFFC-\uDFFF])?|\uDFFC(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB\uDFFD-\uDFFF])?|\uDFFD(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])?|\uDFFE(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB-\uDFFD\uDFFF])?|\uDFFF(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB-\uDFFE])?))?)/g});var Xi=ii(function(nh,Yi){Yi.exports=function(t){if(t===void 0)t=2;if(t>=Error.stackTraceLimit)throw TypeError("getCallerFile(position) requires position be less then Error.stackTraceLimit but position was: `"+t+"` and Error.stackTraceLimit was: `"+Error.stackTraceLimit+"`");var n=Error.prepareStackTrace;Error.prepareStackTrace=function(s,i){return i};var r=Error().stack;if(Error.prepareStackTrace=n,r!==null&&typeof r==="object")return r[t]?r[t].getFileName():void 0}});import{createHash as qf}from"crypto";import{existsSync as eu,readFileSync as Yf,mkdirSync as Xf,writeFileSync as tu}from"fs";import{homedir as Hc}from"os";import{join as pt}from"path";import{notStrictEqual as nl,strictEqual as sl}from"assert";var yu={right:Fu,center:Cu};class ai{constructor(e){var t;this.width=e.width,this.wrap=(t=e.wrap)!==null&&t!==void 0?t:!0,this.rows=[]}span(...e){let t=this.div(...e);t.span=!0}resetOutput(){this.rows=[]}div(...e){if(e.length===0)this.div("");if(this.wrap&&this.shouldApplyLayoutDSL(...e)&&typeof e[0]==="string")return this.applyLayoutDSL(e[0]);let t=e.map((n)=>{if(typeof n==="string")return this.colFromString(n);return n});return this.rows.push(t),t}shouldApplyLayoutDSL(...e){return e.length===1&&typeof e[0]==="string"&&/[\t\n]/.test(e[0])}applyLayoutDSL(e){let t=e.split(`
4
+ `).map((r)=>r.split("\t")),n=0;return t.forEach((r)=>{if(r.length>1&&Se.stringWidth(r[0])>n)n=Math.min(Math.floor(this.width*0.5),Se.stringWidth(r[0]))}),t.forEach((r)=>{this.div(...r.map((s,i)=>({text:s.trim(),padding:this.measurePadding(s),width:i===0&&r.length>1?n:void 0})))}),this.rows[this.rows.length-1]}colFromString(e){return{text:e,padding:this.measurePadding(e)}}measurePadding(e){let t=Se.stripAnsi(e);return[0,t.match(/\s*$/)[0].length,0,t.match(/^\s*/)[0].length]}toString(){let e=[];return this.rows.forEach((t)=>{this.rowToString(t,e)}),e.filter((t)=>!t.hidden).map((t)=>t.text).join(`
5
+ `)}rowToString(e,t){return this.rasterize(e).forEach((n,r)=>{let s="";n.forEach((i,o)=>{let{width:a}=e[o],c=this.negatePadding(e[o]),u=i;if(c>Se.stringWidth(i))u+=" ".repeat(c-Se.stringWidth(i));if(e[o].align&&e[o].align!=="left"&&this.wrap){let l=yu[e[o].align];if(u=l(u,c),Se.stringWidth(u)<c)u+=" ".repeat((a||0)-Se.stringWidth(u)-1)}let f=e[o].padding||[0,0,0,0];if(f[3])s+=" ".repeat(f[3]);if(s+=oi(e[o],u,"| "),s+=u,s+=oi(e[o],u," |"),f[1])s+=" ".repeat(f[1]);if(r===0&&t.length>0)s=this.renderInline(s,t[t.length-1])}),t.push({text:s.replace(/ +$/,""),span:e.span})}),t}renderInline(e,t){let n=e.match(/^ */),r=n?n[0].length:0,s=t.text,i=Se.stringWidth(s.trimRight());if(!t.span)return e;if(!this.wrap)return t.hidden=!0,s+e;if(r<i)return e;return t.hidden=!0,s.trimRight()+" ".repeat(r-i)+e.trimLeft()}rasterize(e){let t=[],n=this.columnWidths(e),r;return e.forEach((s,i)=>{if(s.width=n[i],this.wrap)r=Se.wrap(s.text,this.negatePadding(s),{hard:!0}).split(`
6
6
  `);else r=s.text.split(`
7
- `);if(s.border)r.unshift("."+"-".repeat(this.negatePadding(s)+2)+"."),r.push("'"+"-".repeat(this.negatePadding(s)+2)+"'");if(s.padding)r.unshift(...Array(s.padding[0]||0).fill("")),r.push(...Array(s.padding[2]||0).fill(""));r.forEach((o,a)=>{if(!t[a])t.push([]);let c=t[a];for(let u=0;u<i;u++)if(c[u]===void 0)c.push("");c.push(o)})}),t}negatePadding(e){let t=e.width||0;if(e.padding)t-=(e.padding[3]||0)+(e.padding[1]||0);if(e.border)t-=4;return t}columnWidths(e){if(!this.wrap)return e.map((i)=>i.width||ke.stringWidth(i.text));let t=e.length,n=this.width,r=e.map((i)=>{if(i.width)return t--,n-=i.width,i.width;return}),s=t?Math.floor(n/t):0;return r.map((i,o)=>{if(i===void 0)return Math.max(s,gu(e[o]));return i})}}function ii(e,t,n){if(e.border){if(/[.']-+[.']/.test(t))return"";if(t.trim().length!==0)return n;return" "}return""}function gu(e){let t=e.padding||[],n=1+(t[3]||0)+(t[1]||0);if(e.border)return n+4;return n}function mu(){if(typeof process==="object"&&process.stdout&&process.stdout.columns)return process.stdout.columns;return 80}function Du(e,t){e=e.trim();let n=ke.stringWidth(e);if(n<t)return" ".repeat(t-n)+e;return e}function yu(e,t){e=e.trim();let n=ke.stringWidth(e);if(n>=t)return e;return" ".repeat(t-n>>1)+e}var ke;function ai(e,t){return ke=t,new oi({width:(e===null||e===void 0?void 0:e.width)||mu(),wrap:e===null||e===void 0?void 0:e.wrap})}function Ss({onlyFirst:e=!1}={}){return new RegExp("(?:\\u001B\\][\\s\\S]*?(?:\\u0007|\\u001B\\u005C|\\u009C))|[\\u001B\\u009B][[\\]()#;?]*(?:\\d{1,4}(?:[;:]\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]",e?void 0:"g")}var wu=Ss();function dt(e){if(typeof e!=="string")throw TypeError(`Expected a \`string\`, got \`${typeof e}\``);if(!e.includes("\x1B")&&!e.includes("›"))return e;return e.replace(wu,"")}var ci=161,ui=1114109,li=[161,161,164,164,167,168,170,170,173,174,176,180,182,186,188,191,198,198,208,208,215,216,222,225,230,230,232,234,236,237,240,240,242,243,247,250,252,252,254,254,257,257,273,273,275,275,283,283,294,295,299,299,305,307,312,312,319,322,324,324,328,331,333,333,338,339,358,359,363,363,462,462,464,464,466,466,468,468,470,470,472,472,474,474,476,476,593,593,609,609,708,708,711,711,713,715,717,717,720,720,728,731,733,733,735,735,768,879,913,929,931,937,945,961,963,969,1025,1025,1040,1103,1105,1105,8208,8208,8211,8214,8216,8217,8220,8221,8224,8226,8228,8231,8240,8240,8242,8243,8245,8245,8251,8251,8254,8254,8308,8308,8319,8319,8321,8324,8364,8364,8451,8451,8453,8453,8457,8457,8467,8467,8470,8470,8481,8482,8486,8486,8491,8491,8531,8532,8539,8542,8544,8555,8560,8569,8585,8585,8592,8601,8632,8633,8658,8658,8660,8660,8679,8679,8704,8704,8706,8707,8711,8712,8715,8715,8719,8719,8721,8721,8725,8725,8730,8730,8733,8736,8739,8739,8741,8741,8743,8748,8750,8750,8756,8759,8764,8765,8776,8776,8780,8780,8786,8786,8800,8801,8804,8807,8810,8811,8814,8815,8834,8835,8838,8839,8853,8853,8857,8857,8869,8869,8895,8895,8978,8978,9312,9449,9451,9547,9552,9587,9600,9615,9618,9621,9632,9633,9635,9641,9650,9651,9654,9655,9660,9661,9664,9665,9670,9672,9675,9675,9678,9681,9698,9701,9711,9711,9733,9734,9737,9737,9742,9743,9756,9756,9758,9758,9792,9792,9794,9794,9824,9825,9827,9829,9831,9834,9836,9837,9839,9839,9886,9887,9919,9919,9926,9933,9935,9939,9941,9953,9955,9955,9960,9961,9963,9969,9972,9972,9974,9977,9979,9980,9982,9983,10045,10045,10102,10111,11094,11097,12872,12879,57344,63743,65024,65039,65533,65533,127232,127242,127248,127277,127280,127337,127344,127373,127375,127376,127387,127404,917760,917999,983040,1048573,1048576,1114109],fi=12288,di=65510,pi=[12288,12288,65281,65376,65504,65510];var hi=4352,gi=262141,ks=[4352,4447,8986,8987,9001,9002,9193,9196,9200,9200,9203,9203,9725,9726,9748,9749,9776,9783,9800,9811,9855,9855,9866,9871,9875,9875,9889,9889,9898,9899,9917,9918,9924,9925,9934,9934,9940,9940,9962,9962,9970,9971,9973,9973,9978,9978,9981,9981,9989,9989,9994,9995,10024,10024,10060,10060,10062,10062,10067,10069,10071,10071,10133,10135,10160,10160,10175,10175,11035,11036,11088,11088,11093,11093,11904,11929,11931,12019,12032,12245,12272,12287,12289,12350,12353,12438,12441,12543,12549,12591,12593,12686,12688,12773,12783,12830,12832,12871,12880,42124,42128,42182,43360,43388,44032,55203,63744,64255,65040,65049,65072,65106,65108,65126,65128,65131,94176,94180,94192,94198,94208,101589,101631,101662,101760,101874,110576,110579,110581,110587,110589,110590,110592,110882,110898,110898,110928,110930,110933,110933,110948,110951,110960,111355,119552,119638,119648,119670,126980,126980,127183,127183,127374,127374,127377,127386,127488,127490,127504,127547,127552,127560,127568,127569,127584,127589,127744,127776,127789,127797,127799,127868,127870,127891,127904,127946,127951,127955,127968,127984,127988,127988,127992,128062,128064,128064,128066,128252,128255,128317,128331,128334,128336,128359,128378,128378,128405,128406,128420,128420,128507,128591,128640,128709,128716,128716,128720,128722,128725,128728,128732,128735,128747,128748,128756,128764,128992,129003,129008,129008,129292,129338,129340,129349,129351,129535,129648,129660,129664,129674,129678,129734,129736,129736,129741,129756,129759,129770,129775,129784,131072,196605,196608,262141];var kn=(e,t)=>{let n=0,r=Math.floor(e.length/2)-1;while(n<=r){let s=Math.floor((n+r)/2),i=s*2;if(t<e[i])r=s-1;else if(t>e[i+1])n=s+1;else return!0}return!1};var mi=19968,[bu,Fu]=Cu(ks);function Cu(e){let t=e[0],n=e[1];for(let r=0;r<e.length;r+=2){let s=e[r],i=e[r+1];if(mi>=s&&mi<=i)return[s,i];if(i-s>n-t)t=s,n=i}return[t,n]}var Di=(e)=>{if(e<ci||e>ui)return!1;return kn(li,e)},yi=(e)=>{if(e<fi||e>di)return!1;return kn(pi,e)};var wi=(e)=>{if(e>=bu&&e<=Fu)return!0;if(e<hi||e>gi)return!1;return kn(ks,e)};function Eu(e){if(!Number.isSafeInteger(e))throw TypeError(`Expected a code point, got \`${typeof e}\`.`)}function bi(e,{ambiguousAsWide:t=!1}={}){if(Eu(e),yi(e)||wi(e)||t&&Di(e))return 2;return 1}var Ei=si(Ci(),1),xu=new Intl.Segmenter,_u=/^\p{Default_Ignorable_Code_Point}$/u;function je(e,t={}){if(typeof e!=="string"||e.length===0)return 0;let{ambiguousIsNarrow:n=!0,countAnsiEscapeCodes:r=!1}=t;if(!r)e=dt(e);if(e.length===0)return 0;let s=0,i={ambiguousAsWide:!n};for(let{segment:o}of xu.segment(e)){let a=o.codePointAt(0);if(a<=31||a>=127&&a<=159)continue;if(a>=8203&&a<=8207||a===65279)continue;if(a>=768&&a<=879||a>=6832&&a<=6911||a>=7616&&a<=7679||a>=8400&&a<=8447||a>=65056&&a<=65071)continue;if(a>=55296&&a<=57343)continue;if(a>=65024&&a<=65039)continue;if(_u.test(o))continue;if(Ei.default().test(o)){s+=2;continue}s+=bi(a,i)}return s}var xi=(e=0)=>(t)=>`\x1B[${t+e}m`,_i=(e=0)=>(t)=>`\x1B[${38+e};5;${t}m`,Si=(e=0)=>(t,n,r)=>`\x1B[${38+e};2;${t};${n};${r}m`,re={modifier:{reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],overline:[53,55],inverse:[7,27],hidden:[8,28],strikethrough:[9,29]},color:{black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],blackBright:[90,39],gray:[90,39],grey:[90,39],redBright:[91,39],greenBright:[92,39],yellowBright:[93,39],blueBright:[94,39],magentaBright:[95,39],cyanBright:[96,39],whiteBright:[97,39]},bgColor:{bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],bgBlackBright:[100,49],bgGray:[100,49],bgGrey:[100,49],bgRedBright:[101,49],bgGreenBright:[102,49],bgYellowBright:[103,49],bgBlueBright:[104,49],bgMagentaBright:[105,49],bgCyanBright:[106,49],bgWhiteBright:[107,49]}},mp=Object.keys(re.modifier),Su=Object.keys(re.color),ku=Object.keys(re.bgColor),Dp=[...Su,...ku];function Au(){let e=new Map;for(let[t,n]of Object.entries(re)){for(let[r,s]of Object.entries(n))re[r]={open:`\x1B[${s[0]}m`,close:`\x1B[${s[1]}m`},n[r]=re[r],e.set(s[0],s[1]);Object.defineProperty(re,t,{value:n,enumerable:!1})}return Object.defineProperty(re,"codes",{value:e,enumerable:!1}),re.color.close="\x1B[39m",re.bgColor.close="\x1B[49m",re.color.ansi=xi(),re.color.ansi256=_i(),re.color.ansi16m=Si(),re.bgColor.ansi=xi(10),re.bgColor.ansi256=_i(10),re.bgColor.ansi16m=Si(10),Object.defineProperties(re,{rgbToAnsi256:{value(t,n,r){if(t===n&&n===r){if(t<8)return 16;if(t>248)return 231;return Math.round((t-8)/247*24)+232}return 16+36*Math.round(t/255*5)+6*Math.round(n/255*5)+Math.round(r/255*5)},enumerable:!1},hexToRgb:{value(t){let n=/[a-f\d]{6}|[a-f\d]{3}/i.exec(t.toString(16));if(!n)return[0,0,0];let[r]=n;if(r.length===3)r=[...r].map((i)=>i+i).join("");let s=Number.parseInt(r,16);return[s>>16&255,s>>8&255,s&255]},enumerable:!1},hexToAnsi256:{value:(t)=>re.rgbToAnsi256(...re.hexToRgb(t)),enumerable:!1},ansi256ToAnsi:{value(t){if(t<8)return 30+t;if(t<16)return 90+(t-8);let n,r,s;if(t>=232)n=((t-232)*10+8)/255,r=n,s=n;else{t-=16;let a=t%36;n=Math.floor(t/36)/5,r=Math.floor(a/6)/5,s=a%6/5}let i=Math.max(n,r,s)*2;if(i===0)return 30;let o=30+(Math.round(s)<<2|Math.round(r)<<1|Math.round(n));if(i===2)o+=60;return o},enumerable:!1},rgbToAnsi:{value:(t,n,r)=>re.ansi256ToAnsi(re.rgbToAnsi256(t,n,r)),enumerable:!1},hexToAnsi:{value:(t)=>re.ansi256ToAnsi(re.hexToAnsi256(t)),enumerable:!1}}),re}var $u=Au(),ki=$u;var $n=new Set(["\x1B","›"]),Ou=39,$s="\x07",Oi="[",Iu="]",Ii="m",An=`${Iu}8;;`,Ai=(e)=>`${$n.values().next().value}${Oi}${e}${Ii}`,$i=(e)=>`${$n.values().next().value}${An}${e}${$s}`,Tu=(e)=>e.split(" ").map((t)=>je(t)),As=(e,t,n)=>{let r=[...t],s=!1,i=!1,o=je(dt(e.at(-1)));for(let[a,c]of r.entries()){let u=je(c);if(o+u<=n)e[e.length-1]+=c;else e.push(c),o=0;if($n.has(c))s=!0,i=r.slice(a+1,a+1+An.length).join("")===An;if(s){if(i){if(c===$s)s=!1,i=!1}else if(c===Ii)s=!1;continue}if(o+=u,o===n&&a<r.length-1)e.push(""),o=0}if(!o&&e.at(-1).length>0&&e.length>1)e[e.length-2]+=e.pop()},Pu=(e)=>{let t=e.split(" "),n=t.length;while(n>0){if(je(t[n-1])>0)break;n--}if(n===t.length)return e;return t.slice(0,n).join(" ")+t.slice(n).join("")},Ru=(e,t,n={})=>{if(n.trim!==!1&&e.trim()==="")return"";let r="",s,i,o=Tu(e),a=[""];for(let[l,d]of e.split(" ").entries()){if(n.trim!==!1)a[a.length-1]=a.at(-1).trimStart();let p=je(a.at(-1));if(l!==0){if(p>=t&&(n.wordWrap===!1||n.trim===!1))a.push(""),p=0;if(p>0||n.trim===!1)a[a.length-1]+=" ",p++}if(n.hard&&o[l]>t){let m=t-p,g=1+Math.floor((o[l]-m-1)/t);if(Math.floor((o[l]-1)/t)<g)a.push("");As(a,d,t);continue}if(p+o[l]>t&&p>0&&o[l]>0){if(n.wordWrap===!1&&p<t){As(a,d,t);continue}a.push("")}if(p+o[l]>t&&n.wordWrap===!1){As(a,d,t);continue}a[a.length-1]+=d}if(n.trim!==!1)a=a.map((l)=>Pu(l));let c=a.join(`
8
- `),u=[...c],f=0;for(let[l,d]of u.entries()){if(r+=d,$n.has(d)){let{groups:m}=new RegExp(`(?:\\${Oi}(?<code>\\d+)m|\\${An}(?<uri>.*)${$s})`).exec(c.slice(f))||{groups:{}};if(m.code!==void 0){let g=Number.parseFloat(m.code);s=g===Ou?void 0:g}else if(m.uri!==void 0)i=m.uri.length===0?void 0:m.uri}let p=ki.codes.get(Number(s));if(u[l+1]===`
9
- `){if(i)r+=$i("");if(s&&p)r+=Ai(p)}else if(d===`
10
- `){if(s&&p)r+=Ai(s);if(i)r+=$i(i)}f+=d.length}return r};function Os(e,t,n){return String(e).normalize().replaceAll(`\r
7
+ `);if(s.border)r.unshift("."+"-".repeat(this.negatePadding(s)+2)+"."),r.push("'"+"-".repeat(this.negatePadding(s)+2)+"'");if(s.padding)r.unshift(...Array(s.padding[0]||0).fill("")),r.push(...Array(s.padding[2]||0).fill(""));r.forEach((o,a)=>{if(!t[a])t.push([]);let c=t[a];for(let u=0;u<i;u++)if(c[u]===void 0)c.push("");c.push(o)})}),t}negatePadding(e){let t=e.width||0;if(e.padding)t-=(e.padding[3]||0)+(e.padding[1]||0);if(e.border)t-=4;return t}columnWidths(e){if(!this.wrap)return e.map((i)=>i.width||Se.stringWidth(i.text));let t=e.length,n=this.width,r=e.map((i)=>{if(i.width)return t--,n-=i.width,i.width;return}),s=t?Math.floor(n/t):0;return r.map((i,o)=>{if(i===void 0)return Math.max(s,wu(e[o]));return i})}}function oi(e,t,n){if(e.border){if(/[.']-+[.']/.test(t))return"";if(t.trim().length!==0)return n;return" "}return""}function wu(e){let t=e.padding||[],n=1+(t[3]||0)+(t[1]||0);if(e.border)return n+4;return n}function bu(){if(typeof process==="object"&&process.stdout&&process.stdout.columns)return process.stdout.columns;return 80}function Fu(e,t){e=e.trim();let n=Se.stringWidth(e);if(n<t)return" ".repeat(t-n)+e;return e}function Cu(e,t){e=e.trim();let n=Se.stringWidth(e);if(n>=t)return e;return" ".repeat(t-n>>1)+e}var Se;function ci(e,t){return Se=t,new ai({width:(e===null||e===void 0?void 0:e.width)||bu(),wrap:e===null||e===void 0?void 0:e.wrap})}function $s({onlyFirst:e=!1}={}){return new RegExp("(?:\\u001B\\][\\s\\S]*?(?:\\u0007|\\u001B\\u005C|\\u009C))|[\\u001B\\u009B][[\\]()#;?]*(?:\\d{1,4}(?:[;:]\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]",e?void 0:"g")}var Eu=$s();function ht(e){if(typeof e!=="string")throw TypeError(`Expected a \`string\`, got \`${typeof e}\``);if(!e.includes("\x1B")&&!e.includes("›"))return e;return e.replace(Eu,"")}var ui=161,li=1114109,fi=[161,161,164,164,167,168,170,170,173,174,176,180,182,186,188,191,198,198,208,208,215,216,222,225,230,230,232,234,236,237,240,240,242,243,247,250,252,252,254,254,257,257,273,273,275,275,283,283,294,295,299,299,305,307,312,312,319,322,324,324,328,331,333,333,338,339,358,359,363,363,462,462,464,464,466,466,468,468,470,470,472,472,474,474,476,476,593,593,609,609,708,708,711,711,713,715,717,717,720,720,728,731,733,733,735,735,768,879,913,929,931,937,945,961,963,969,1025,1025,1040,1103,1105,1105,8208,8208,8211,8214,8216,8217,8220,8221,8224,8226,8228,8231,8240,8240,8242,8243,8245,8245,8251,8251,8254,8254,8308,8308,8319,8319,8321,8324,8364,8364,8451,8451,8453,8453,8457,8457,8467,8467,8470,8470,8481,8482,8486,8486,8491,8491,8531,8532,8539,8542,8544,8555,8560,8569,8585,8585,8592,8601,8632,8633,8658,8658,8660,8660,8679,8679,8704,8704,8706,8707,8711,8712,8715,8715,8719,8719,8721,8721,8725,8725,8730,8730,8733,8736,8739,8739,8741,8741,8743,8748,8750,8750,8756,8759,8764,8765,8776,8776,8780,8780,8786,8786,8800,8801,8804,8807,8810,8811,8814,8815,8834,8835,8838,8839,8853,8853,8857,8857,8869,8869,8895,8895,8978,8978,9312,9449,9451,9547,9552,9587,9600,9615,9618,9621,9632,9633,9635,9641,9650,9651,9654,9655,9660,9661,9664,9665,9670,9672,9675,9675,9678,9681,9698,9701,9711,9711,9733,9734,9737,9737,9742,9743,9756,9756,9758,9758,9792,9792,9794,9794,9824,9825,9827,9829,9831,9834,9836,9837,9839,9839,9886,9887,9919,9919,9926,9933,9935,9939,9941,9953,9955,9955,9960,9961,9963,9969,9972,9972,9974,9977,9979,9980,9982,9983,10045,10045,10102,10111,11094,11097,12872,12879,57344,63743,65024,65039,65533,65533,127232,127242,127248,127277,127280,127337,127344,127373,127375,127376,127387,127404,917760,917999,983040,1048573,1048576,1114109],di=12288,pi=65510,hi=[12288,12288,65281,65376,65504,65510];var gi=4352,mi=262141,Os=[4352,4447,8986,8987,9001,9002,9193,9196,9200,9200,9203,9203,9725,9726,9748,9749,9776,9783,9800,9811,9855,9855,9866,9871,9875,9875,9889,9889,9898,9899,9917,9918,9924,9925,9934,9934,9940,9940,9962,9962,9970,9971,9973,9973,9978,9978,9981,9981,9989,9989,9994,9995,10024,10024,10060,10060,10062,10062,10067,10069,10071,10071,10133,10135,10160,10160,10175,10175,11035,11036,11088,11088,11093,11093,11904,11929,11931,12019,12032,12245,12272,12287,12289,12350,12353,12438,12441,12543,12549,12591,12593,12686,12688,12773,12783,12830,12832,12871,12880,42124,42128,42182,43360,43388,44032,55203,63744,64255,65040,65049,65072,65106,65108,65126,65128,65131,94176,94180,94192,94198,94208,101589,101631,101662,101760,101874,110576,110579,110581,110587,110589,110590,110592,110882,110898,110898,110928,110930,110933,110933,110948,110951,110960,111355,119552,119638,119648,119670,126980,126980,127183,127183,127374,127374,127377,127386,127488,127490,127504,127547,127552,127560,127568,127569,127584,127589,127744,127776,127789,127797,127799,127868,127870,127891,127904,127946,127951,127955,127968,127984,127988,127988,127992,128062,128064,128064,128066,128252,128255,128317,128331,128334,128336,128359,128378,128378,128405,128406,128420,128420,128507,128591,128640,128709,128716,128716,128720,128722,128725,128728,128732,128735,128747,128748,128756,128764,128992,129003,129008,129008,129292,129338,129340,129349,129351,129535,129648,129660,129664,129674,129678,129734,129736,129736,129741,129756,129759,129770,129775,129784,131072,196605,196608,262141];var Sn=(e,t)=>{let n=0,r=Math.floor(e.length/2)-1;while(n<=r){let s=Math.floor((n+r)/2),i=s*2;if(t<e[i])r=s-1;else if(t>e[i+1])n=s+1;else return!0}return!1};var Di=19968,[xu,_u]=ku(Os);function ku(e){let t=e[0],n=e[1];for(let r=0;r<e.length;r+=2){let s=e[r],i=e[r+1];if(Di>=s&&Di<=i)return[s,i];if(i-s>n-t)t=s,n=i}return[t,n]}var yi=(e)=>{if(e<ui||e>li)return!1;return Sn(fi,e)},wi=(e)=>{if(e<di||e>pi)return!1;return Sn(hi,e)};var bi=(e)=>{if(e>=xu&&e<=_u)return!0;if(e<gi||e>mi)return!1;return Sn(Os,e)};function Su(e){if(!Number.isSafeInteger(e))throw TypeError(`Expected a code point, got \`${typeof e}\`.`)}function Fi(e,{ambiguousAsWide:t=!1}={}){if(Su(e),wi(e)||bi(e)||t&&yi(e))return 2;return 1}var xi=ri(Ei(),1),Au=new Intl.Segmenter,$u=/^\p{Default_Ignorable_Code_Point}$/u;function je(e,t={}){if(typeof e!=="string"||e.length===0)return 0;let{ambiguousIsNarrow:n=!0,countAnsiEscapeCodes:r=!1}=t;if(!r)e=ht(e);if(e.length===0)return 0;let s=0,i={ambiguousAsWide:!n};for(let{segment:o}of Au.segment(e)){let a=o.codePointAt(0);if(a<=31||a>=127&&a<=159)continue;if(a>=8203&&a<=8207||a===65279)continue;if(a>=768&&a<=879||a>=6832&&a<=6911||a>=7616&&a<=7679||a>=8400&&a<=8447||a>=65056&&a<=65071)continue;if(a>=55296&&a<=57343)continue;if(a>=65024&&a<=65039)continue;if($u.test(o))continue;if(xi.default().test(o)){s+=2;continue}s+=Fi(a,i)}return s}var _i=(e=0)=>(t)=>`\x1B[${t+e}m`,ki=(e=0)=>(t)=>`\x1B[${38+e};5;${t}m`,Si=(e=0)=>(t,n,r)=>`\x1B[${38+e};2;${t};${n};${r}m`,re={modifier:{reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],overline:[53,55],inverse:[7,27],hidden:[8,28],strikethrough:[9,29]},color:{black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],blackBright:[90,39],gray:[90,39],grey:[90,39],redBright:[91,39],greenBright:[92,39],yellowBright:[93,39],blueBright:[94,39],magentaBright:[95,39],cyanBright:[96,39],whiteBright:[97,39]},bgColor:{bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],bgBlackBright:[100,49],bgGray:[100,49],bgGrey:[100,49],bgRedBright:[101,49],bgGreenBright:[102,49],bgYellowBright:[103,49],bgBlueBright:[104,49],bgMagentaBright:[105,49],bgCyanBright:[106,49],bgWhiteBright:[107,49]}},yp=Object.keys(re.modifier),Ou=Object.keys(re.color),Iu=Object.keys(re.bgColor),wp=[...Ou,...Iu];function Tu(){let e=new Map;for(let[t,n]of Object.entries(re)){for(let[r,s]of Object.entries(n))re[r]={open:`\x1B[${s[0]}m`,close:`\x1B[${s[1]}m`},n[r]=re[r],e.set(s[0],s[1]);Object.defineProperty(re,t,{value:n,enumerable:!1})}return Object.defineProperty(re,"codes",{value:e,enumerable:!1}),re.color.close="\x1B[39m",re.bgColor.close="\x1B[49m",re.color.ansi=_i(),re.color.ansi256=ki(),re.color.ansi16m=Si(),re.bgColor.ansi=_i(10),re.bgColor.ansi256=ki(10),re.bgColor.ansi16m=Si(10),Object.defineProperties(re,{rgbToAnsi256:{value(t,n,r){if(t===n&&n===r){if(t<8)return 16;if(t>248)return 231;return Math.round((t-8)/247*24)+232}return 16+36*Math.round(t/255*5)+6*Math.round(n/255*5)+Math.round(r/255*5)},enumerable:!1},hexToRgb:{value(t){let n=/[a-f\d]{6}|[a-f\d]{3}/i.exec(t.toString(16));if(!n)return[0,0,0];let[r]=n;if(r.length===3)r=[...r].map((i)=>i+i).join("");let s=Number.parseInt(r,16);return[s>>16&255,s>>8&255,s&255]},enumerable:!1},hexToAnsi256:{value:(t)=>re.rgbToAnsi256(...re.hexToRgb(t)),enumerable:!1},ansi256ToAnsi:{value(t){if(t<8)return 30+t;if(t<16)return 90+(t-8);let n,r,s;if(t>=232)n=((t-232)*10+8)/255,r=n,s=n;else{t-=16;let a=t%36;n=Math.floor(t/36)/5,r=Math.floor(a/6)/5,s=a%6/5}let i=Math.max(n,r,s)*2;if(i===0)return 30;let o=30+(Math.round(s)<<2|Math.round(r)<<1|Math.round(n));if(i===2)o+=60;return o},enumerable:!1},rgbToAnsi:{value:(t,n,r)=>re.ansi256ToAnsi(re.rgbToAnsi256(t,n,r)),enumerable:!1},hexToAnsi:{value:(t)=>re.ansi256ToAnsi(re.hexToAnsi256(t)),enumerable:!1}}),re}var Pu=Tu(),Ai=Pu;var $n=new Set(["\x1B","›"]),Ru=39,Ts="\x07",Ii="[",Mu="]",Ti="m",An=`${Mu}8;;`,$i=(e)=>`${$n.values().next().value}${Ii}${e}${Ti}`,Oi=(e)=>`${$n.values().next().value}${An}${e}${Ts}`,Bu=(e)=>e.split(" ").map((t)=>je(t)),Is=(e,t,n)=>{let r=[...t],s=!1,i=!1,o=je(ht(e.at(-1)));for(let[a,c]of r.entries()){let u=je(c);if(o+u<=n)e[e.length-1]+=c;else e.push(c),o=0;if($n.has(c))s=!0,i=r.slice(a+1,a+1+An.length).join("")===An;if(s){if(i){if(c===Ts)s=!1,i=!1}else if(c===Ti)s=!1;continue}if(o+=u,o===n&&a<r.length-1)e.push(""),o=0}if(!o&&e.at(-1).length>0&&e.length>1)e[e.length-2]+=e.pop()},Nu=(e)=>{let t=e.split(" "),n=t.length;while(n>0){if(je(t[n-1])>0)break;n--}if(n===t.length)return e;return t.slice(0,n).join(" ")+t.slice(n).join("")},vu=(e,t,n={})=>{if(n.trim!==!1&&e.trim()==="")return"";let r="",s,i,o=Bu(e),a=[""];for(let[l,d]of e.split(" ").entries()){if(n.trim!==!1)a[a.length-1]=a.at(-1).trimStart();let p=je(a.at(-1));if(l!==0){if(p>=t&&(n.wordWrap===!1||n.trim===!1))a.push(""),p=0;if(p>0||n.trim===!1)a[a.length-1]+=" ",p++}if(n.hard&&o[l]>t){let m=t-p,g=1+Math.floor((o[l]-m-1)/t);if(Math.floor((o[l]-1)/t)<g)a.push("");Is(a,d,t);continue}if(p+o[l]>t&&p>0&&o[l]>0){if(n.wordWrap===!1&&p<t){Is(a,d,t);continue}a.push("")}if(p+o[l]>t&&n.wordWrap===!1){Is(a,d,t);continue}a[a.length-1]+=d}if(n.trim!==!1)a=a.map((l)=>Nu(l));let c=a.join(`
8
+ `),u=[...c],f=0;for(let[l,d]of u.entries()){if(r+=d,$n.has(d)){let{groups:m}=new RegExp(`(?:\\${Ii}(?<code>\\d+)m|\\${An}(?<uri>.*)${Ts})`).exec(c.slice(f))||{groups:{}};if(m.code!==void 0){let g=Number.parseFloat(m.code);s=g===Ru?void 0:g}else if(m.uri!==void 0)i=m.uri.length===0?void 0:m.uri}let p=Ai.codes.get(Number(s));if(u[l+1]===`
9
+ `){if(i)r+=Oi("");if(s&&p)r+=$i(p)}else if(d===`
10
+ `){if(s&&p)r+=$i(s);if(i)r+=Oi(i)}f+=d.length}return r};function Ps(e,t,n){return String(e).normalize().replaceAll(`\r
11
11
  `,`
12
12
  `).split(`
13
- `).map((r)=>Ru(r,t,n)).join(`
14
- `)}function Is(e){return ai(e,{stringWidth:je,stripAnsi:dt,wrap:Os})}import{dirname as Ti,resolve as Pi}from"path";import{readdirSync as Mu,statSync as Bu}from"fs";function Ts(e,t){let n=Pi(".",e),r;if(!Bu(n).isDirectory())n=Ti(n);while(!0){if(r=t(n,Mu(n)),r)return Pi(n,r);if(n=Ti(r=n),r===n)break}}import{inspect as el}from"util";import{fileURLToPath as Gi}from"url";import{format as ju}from"util";import{normalize as Lu,resolve as Wu}from"path";function pt(e){if(!(e!==e.toLowerCase()&&e!==e.toUpperCase()))e=e.toLowerCase();if(e.indexOf("-")===-1&&e.indexOf("_")===-1)return e;else{let n="",r=!1,s=e.match(/^-+/);for(let i=s?s[0].length:0;i<e.length;i++){let o=e.charAt(i);if(r)r=!1,o=o.toUpperCase();if(i!==0&&(o==="-"||o==="_"))r=!0;else if(o!=="-"&&o!=="_")n+=o}return n}}function On(e,t){let n=e.toLowerCase();t=t||"-";let r="";for(let s=0;s<e.length;s++){let i=n.charAt(s),o=e.charAt(s);if(i!==o&&s>0)r+=`${t}${n.charAt(s)}`;else r+=o}return r}function In(e){if(e===null||e===void 0)return!1;if(typeof e==="number")return!0;if(/^0x[0-9a-f]+$/i.test(e))return!0;if(/^0[^.]/.test(e))return!1;return/^[-]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e)}function Ri(e){if(Array.isArray(e))return e.map((o)=>typeof o!=="string"?o+"":o);e=e.trim();let t=0,n=null,r=null,s=null,i=[];for(let o=0;o<e.length;o++){if(n=r,r=e.charAt(o),r===" "&&!s){if(n!==" ")t++;continue}if(r===s)s=null;else if((r==="'"||r==='"')&&!s)s=r;if(!i[t])i[t]="";i[t]+=r}return i}var Te;(function(e){e.BOOLEAN="boolean",e.STRING="string",e.NUMBER="number",e.ARRAY="array"})(Te||(Te={}));var Qe;class Rs{constructor(e){Qe=e}parse(e,t){let n=Object.assign({alias:void 0,array:void 0,boolean:void 0,config:void 0,configObjects:void 0,configuration:void 0,coerce:void 0,count:void 0,default:void 0,envPrefix:void 0,narg:void 0,normalize:void 0,string:void 0,number:void 0,__:void 0,key:void 0},t),r=Ri(e),s=typeof e==="string",i=Nu(Object.assign(Object.create(null),n.alias)),o=Object.assign({"boolean-negation":!0,"camel-case-expansion":!0,"combine-arrays":!1,"dot-notation":!0,"duplicate-arguments-array":!0,"flatten-duplicate-arrays":!0,"greedy-arrays":!0,"halt-at-non-option":!1,"nargs-eats-options":!1,"negation-prefix":"no-","parse-numbers":!0,"parse-positional-numbers":!0,"populate--":!1,"set-placeholder-key":!1,"short-option-groups":!0,"strip-aliased":!1,"strip-dashed":!1,"unknown-options-as-args":!1},n.configuration),a=Object.assign(Object.create(null),n.default),c=n.configObjects||[],u=n.envPrefix,f=o["populate--"],l=f?"--":"_",d=Object.create(null),p=Object.create(null),m=n.__||Qe.format,g={aliases:Object.create(null),arrays:Object.create(null),bools:Object.create(null),strings:Object.create(null),numbers:Object.create(null),counts:Object.create(null),normalize:Object.create(null),configs:Object.create(null),nargs:Object.create(null),coercions:Object.create(null),keys:[]},y=/^-([0-9]+(\.[0-9]+)?|\.[0-9]+)$/,C=new RegExp("^--"+o["negation-prefix"]+"(.+)");if([].concat(n.array||[]).filter(Boolean).forEach(function(D){let b=typeof D==="object"?D.key:D,I=Object.keys(D).map(function(x){return{boolean:"bools",string:"strings",number:"numbers"}[x]}).filter(Boolean).pop();if(I)g[I][b]=!0;g.arrays[b]=!0,g.keys.push(b)}),[].concat(n.boolean||[]).filter(Boolean).forEach(function(D){g.bools[D]=!0,g.keys.push(D)}),[].concat(n.string||[]).filter(Boolean).forEach(function(D){g.strings[D]=!0,g.keys.push(D)}),[].concat(n.number||[]).filter(Boolean).forEach(function(D){g.numbers[D]=!0,g.keys.push(D)}),[].concat(n.count||[]).filter(Boolean).forEach(function(D){g.counts[D]=!0,g.keys.push(D)}),[].concat(n.normalize||[]).filter(Boolean).forEach(function(D){g.normalize[D]=!0,g.keys.push(D)}),typeof n.narg==="object")Object.entries(n.narg).forEach(([D,b])=>{if(typeof b==="number")g.nargs[D]=b,g.keys.push(D)});if(typeof n.coerce==="object")Object.entries(n.coerce).forEach(([D,b])=>{if(typeof b==="function")g.coercions[D]=b,g.keys.push(D)});if(typeof n.config<"u"){if(Array.isArray(n.config)||typeof n.config==="string")[].concat(n.config).filter(Boolean).forEach(function(D){g.configs[D]=!0});else if(typeof n.config==="object")Object.entries(n.config).forEach(([D,b])=>{if(typeof b==="boolean"||typeof b==="function")g.configs[D]=b})}Z(n.key,i,n.default,g.arrays),Object.keys(a).forEach(function(D){(g.aliases[D]||[]).forEach(function(b){a[b]=a[D]})});let F=null;_s();let k=[],S=Object.assign(Object.create(null),{_:[]}),L={};for(let D=0;D<r.length;D++){let b=r[D],I=b.replace(/^-{3,}/,"---"),x,w,U,M,J,ge;if(b!=="--"&&/^-/.test(b)&&ne(b))A(b);else if(I.match(/^---+(=|$)/)){A(b);continue}else if(b.match(/^--.+=/)||!o["short-option-groups"]&&b.match(/^-.+=/)){if(M=b.match(/^--?([^=]+)=([\s\S]*)$/),M!==null&&Array.isArray(M)&&M.length>=3)if(v(M[1],g.arrays))D=B(D,M[1],r,M[2]);else if(v(M[1],g.nargs)!==!1)D=R(D,M[1],r,M[2]);else P(M[1],M[2],!0)}else if(b.match(C)&&o["boolean-negation"]){if(M=b.match(C),M!==null&&Array.isArray(M)&&M.length>=2)w=M[1],P(w,v(w,g.arrays)?[!1]:!1)}else if(b.match(/^--.+/)||!o["short-option-groups"]&&b.match(/^-[^-]+/)){if(M=b.match(/^--?(.+)/),M!==null&&Array.isArray(M)&&M.length>=2)if(w=M[1],v(w,g.arrays))D=B(D,w,r);else if(v(w,g.nargs)!==!1)D=R(D,w,r);else if(J=r[D+1],J!==void 0&&(!J.match(/^-/)||J.match(y))&&!v(w,g.bools)&&!v(w,g.counts))P(w,J),D++;else if(/^(true|false)$/.test(J))P(w,J),D++;else P(w,G(w))}else if(b.match(/^-.\..+=/)){if(M=b.match(/^-([^=]+)=([\s\S]*)$/),M!==null&&Array.isArray(M)&&M.length>=3)P(M[1],M[2])}else if(b.match(/^-.\..+/)&&!b.match(y)){if(J=r[D+1],M=b.match(/^-(.\..+)/),M!==null&&Array.isArray(M)&&M.length>=2)if(w=M[1],J!==void 0&&!J.match(/^-/)&&!v(w,g.bools)&&!v(w,g.counts))P(w,J),D++;else P(w,G(w))}else if(b.match(/^-[^-]+/)&&!b.match(y)){U=b.slice(1,-1).split(""),x=!1;for(let Fe=0;Fe<U.length;Fe++){if(J=b.slice(Fe+2),U[Fe+1]&&U[Fe+1]==="="){if(ge=b.slice(Fe+3),w=U[Fe],v(w,g.arrays))D=B(D,w,r,ge);else if(v(w,g.nargs)!==!1)D=R(D,w,r,ge);else P(w,ge);x=!0;break}if(J==="-"){P(U[Fe],J);continue}if(/[A-Za-z]/.test(U[Fe])&&/^-?\d+(\.\d*)?(e-?\d+)?$/.test(J)&&v(J,g.bools)===!1){P(U[Fe],J),x=!0;break}if(U[Fe+1]&&U[Fe+1].match(/\W/)){P(U[Fe],J),x=!0;break}else P(U[Fe],G(U[Fe]))}if(w=b.slice(-1)[0],!x&&w!=="-")if(v(w,g.arrays))D=B(D,w,r);else if(v(w,g.nargs)!==!1)D=R(D,w,r);else if(J=r[D+1],J!==void 0&&(!/^(-|--)[^-]/.test(J)||J.match(y))&&!v(w,g.bools)&&!v(w,g.counts))P(w,J),D++;else if(/^(true|false)$/.test(J))P(w,J),D++;else P(w,G(w))}else if(b.match(/^-[0-9]$/)&&b.match(y)&&v(b.slice(1),g.bools))w=b.slice(1),P(w,G(w));else if(b==="--"){k=r.slice(D+1);break}else if(o["halt-at-non-option"]){k=r.slice(D);break}else A(b)}if(oe(S,!0),oe(S,!1),O(S),Q(),Ie(S,g.aliases,a,!0),V(S),o["set-placeholder-key"])ae(S);if(Object.keys(g.counts).forEach(function(D){if(!ee(S,D.split(".")))P(D,0)}),f&&k.length)S[l]=[];if(k.forEach(function(D){S[l].push(D)}),o["camel-case-expansion"]&&o["strip-dashed"])Object.keys(S).filter((D)=>D!=="--"&&D.includes("-")).forEach((D)=>{delete S[D]});if(o["strip-aliased"])[].concat(...Object.keys(i).map((D)=>i[D])).forEach((D)=>{if(o["camel-case-expansion"]&&D.includes("-"))delete S[D.split(".").map((b)=>pt(b)).join(".")];delete S[D]});function A(D){let b=E("_",D);if(typeof b==="string"||typeof b==="number")S._.push(b)}function R(D,b,I,x){let w,U=v(b,g.nargs);if(U=typeof U!=="number"||isNaN(U)?1:U,U===0){if(!pe(x))F=Error(m("Argument unexpected for: %s",b));return P(b,G(b)),D}let M=pe(x)?0:1;if(o["nargs-eats-options"]){if(I.length-(D+1)+M<U)F=Error(m("Not enough arguments following: %s",b));M=U}else{for(w=D+1;w<I.length;w++)if(!I[w].match(/^-[^0-9]/)||I[w].match(y)||ne(I[w]))M++;else break;if(M<U)F=Error(m("Not enough arguments following: %s",b))}let J=Math.min(M,U);if(!pe(x)&&J>0)P(b,x),J--;for(w=D+1;w<J+D+1;w++)P(b,I[w]);return D+J}function B(D,b,I,x){let w=[],U=x||I[D+1],M=v(b,g.nargs);if(v(b,g.bools)&&!/^(true|false)$/.test(U))w.push(!0);else if(pe(U)||pe(x)&&/^-/.test(U)&&!y.test(U)&&!ne(U)){if(a[b]!==void 0){let J=a[b];w=Array.isArray(J)?J:[J]}}else{if(!pe(x))w.push(_(b,x,!0));for(let J=D+1;J<I.length;J++){if(!o["greedy-arrays"]&&w.length>0||M&&typeof M==="number"&&w.length>=M)break;if(U=I[J],/^-/.test(U)&&!y.test(U)&&!ne(U))break;D=J,w.push(_(b,U,s))}}if(typeof M==="number"&&(M&&w.length<M||isNaN(M)&&w.length===0))F=Error(m("Not enough arguments following: %s",b));return P(b,w),D}function P(D,b,I=s){if(/-/.test(D)&&o["camel-case-expansion"]){let U=D.split(".").map(function(M){return pt(M)}).join(".");q(D,U)}let x=_(D,b,I),w=D.split(".");if(Se(S,w,x),g.aliases[D])g.aliases[D].forEach(function(U){let M=U.split(".");Se(S,M,x)});if(w.length>1&&o["dot-notation"])(g.aliases[w[0]]||[]).forEach(function(U){let M=U.split("."),J=[].concat(w);if(J.shift(),M=M.concat(J),!(g.aliases[D]||[]).includes(M.join(".")))Se(S,M,x)});if(v(D,g.normalize)&&!v(D,g.arrays))[D].concat(g.aliases[D]||[]).forEach(function(M){Object.defineProperty(L,M,{enumerable:!0,get(){return b},set(J){b=typeof J==="string"?Qe.normalize(J):J}})})}function q(D,b){if(!(g.aliases[D]&&g.aliases[D].length))g.aliases[D]=[b],d[b]=!0;if(!(g.aliases[b]&&g.aliases[b].length))q(b,D)}function _(D,b,I){if(I)b=vu(b);if(v(D,g.bools)||v(D,g.counts)){if(typeof b==="string")b=b==="true"}let x=Array.isArray(b)?b.map(function(w){return E(D,w)}):E(D,b);if(v(D,g.counts)&&(pe(x)||typeof x==="boolean"))x=Ps();if(v(D,g.normalize)&&v(D,g.arrays))if(Array.isArray(b))x=b.map((w)=>Qe.normalize(w));else x=Qe.normalize(b);return x}function E(D,b){if(!o["parse-positional-numbers"]&&D==="_")return b;if(!v(D,g.strings)&&!v(D,g.bools)&&!Array.isArray(b)){if(In(b)&&o["parse-numbers"]&&Number.isSafeInteger(Math.floor(parseFloat(`${b}`)))||!pe(b)&&v(D,g.numbers))b=Number(b)}return b}function O(D){let b=Object.create(null);Ie(b,g.aliases,a),Object.keys(g.configs).forEach(function(I){let x=D[I]||b[I];if(x)try{let w=null,U=Qe.resolve(Qe.cwd(),x),M=g.configs[I];if(typeof M==="function"){try{w=M(U)}catch(J){w=J}if(w instanceof Error){F=w;return}}else w=Qe.require(U);N(w)}catch(w){if(w.name==="PermissionDenied")F=w;else if(D[I])F=Error(m("Invalid JSON config file: %s",x))}})}function N(D,b){Object.keys(D).forEach(function(I){let x=D[I],w=b?b+"."+I:I;if(typeof x==="object"&&x!==null&&!Array.isArray(x)&&o["dot-notation"])N(x,w);else if(!ee(S,w.split("."))||v(w,g.arrays)&&o["combine-arrays"])P(w,x)})}function Q(){if(typeof c<"u")c.forEach(function(D){N(D)})}function oe(D,b){if(typeof u>"u")return;let I=typeof u==="string"?u:"",x=Qe.env();Object.keys(x).forEach(function(w){if(I===""||w.lastIndexOf(I,0)===0){let U=w.split("__").map(function(M,J){if(J===0)M=M.substring(I.length);return pt(M)});if((b&&g.configs[U.join(".")]||!b)&&!ee(D,U))P(U.join("."),x[w])}})}function V(D){let b,I=new Set;Object.keys(D).forEach(function(x){if(!I.has(x)){if(b=v(x,g.coercions),typeof b==="function")try{let w=E(x,b(D[x]));[].concat(g.aliases[x]||[],x).forEach((U)=>{I.add(U),D[U]=w})}catch(w){F=w}}})}function ae(D){return g.keys.forEach((b)=>{if(~b.indexOf("."))return;if(typeof D[b]>"u")D[b]=void 0}),D}function Ie(D,b,I,x=!1){Object.keys(I).forEach(function(w){if(!ee(D,w.split("."))){if(Se(D,w.split("."),I[w]),x)p[w]=!0;(b[w]||[]).forEach(function(U){if(ee(D,U.split(".")))return;Se(D,U.split("."),I[w])})}})}function ee(D,b){let I=D;if(!o["dot-notation"])b=[b.join(".")];b.slice(0,-1).forEach(function(w){I=I[w]||{}});let x=b[b.length-1];if(typeof I!=="object")return!1;else return x in I}function Se(D,b,I){let x=D;if(!o["dot-notation"])b=[b.join(".")];b.slice(0,-1).forEach(function(ge){if(ge=Mi(ge),typeof x==="object"&&x[ge]===void 0)x[ge]={};if(typeof x[ge]!=="object"||Array.isArray(x[ge])){if(Array.isArray(x[ge]))x[ge].push({});else x[ge]=[x[ge],{}];x=x[ge][x[ge].length-1]}else x=x[ge]});let w=Mi(b[b.length-1]),U=v(b.join("."),g.arrays),M=Array.isArray(I),J=o["duplicate-arguments-array"];if(!J&&v(w,g.nargs)){if(J=!0,!pe(x[w])&&g.nargs[w]===1||Array.isArray(x[w])&&x[w].length===g.nargs[w])x[w]=void 0}if(I===Ps())x[w]=Ps(x[w]);else if(Array.isArray(x[w]))if(J&&U&&M)x[w]=o["flatten-duplicate-arrays"]?x[w].concat(I):(Array.isArray(x[w][0])?x[w]:[x[w]]).concat([I]);else if(!J&&Boolean(U)===Boolean(M))x[w]=I;else x[w]=x[w].concat([I]);else if(x[w]===void 0&&U)x[w]=M?I:[I];else if(J&&!(x[w]===void 0||v(w,g.counts)||v(w,g.bools)))x[w]=[x[w],I];else x[w]=I}function Z(...D){D.forEach(function(b){Object.keys(b||{}).forEach(function(I){if(g.aliases[I])return;g.aliases[I]=[].concat(i[I]||[]),g.aliases[I].concat(I).forEach(function(x){if(/-/.test(x)&&o["camel-case-expansion"]){let w=pt(x);if(w!==I&&g.aliases[I].indexOf(w)===-1)g.aliases[I].push(w),d[w]=!0}}),g.aliases[I].concat(I).forEach(function(x){if(x.length>1&&/[A-Z]/.test(x)&&o["camel-case-expansion"]){let w=On(x,"-");if(w!==I&&g.aliases[I].indexOf(w)===-1)g.aliases[I].push(w),d[w]=!0}}),g.aliases[I].forEach(function(x){g.aliases[x]=[I].concat(g.aliases[I].filter(function(w){return x!==w}))})})})}function v(D,b){let I=[].concat(g.aliases[D]||[],D),x=Object.keys(b),w=I.find((U)=>x.includes(U));return w?b[w]:!1}function be(D){let b=Object.keys(g);return[].concat(b.map((x)=>g[x])).some(function(x){return Array.isArray(x)?x.includes(D):x[D]})}function Lt(D,...b){return[].concat(...b).some(function(x){let w=D.match(x);return w&&be(w[1])})}function z(D){if(D.match(y)||!D.match(/^-[^-]+/))return!1;let b=!0,I,x=D.slice(1).split("");for(let w=0;w<x.length;w++){if(I=D.slice(w+2),!be(x[w])){b=!1;break}if(x[w+1]&&x[w+1]==="="||I==="-"||/[A-Za-z]/.test(x[w])&&/^-?\d+(\.\d*)?(e-?\d+)?$/.test(I)||x[w+1]&&x[w+1].match(/\W/))break}return b}function ne(D){return o["unknown-options-as-args"]&&de(D)}function de(D){if(D=D.replace(/^-{3,}/,"--"),D.match(y))return!1;if(z(D))return!1;return!Lt(D,/^-+([^=]+?)=[\s\S]*$/,C,/^-+([^=]+?)$/,/^-+([^=]+?)-$/,/^-+([^=]+?\d+)$/,/^-+([^=]+?)\W+.*$/)}function G(D){if(!v(D,g.bools)&&!v(D,g.counts)&&`${D}`in a)return a[D];else return ye(ue(D))}function ye(D){return{[Te.BOOLEAN]:!0,[Te.STRING]:"",[Te.NUMBER]:void 0,[Te.ARRAY]:[]}[D]}function ue(D){let b=Te.BOOLEAN;if(v(D,g.strings))b=Te.STRING;else if(v(D,g.numbers))b=Te.NUMBER;else if(v(D,g.bools))b=Te.BOOLEAN;else if(v(D,g.arrays))b=Te.ARRAY;return b}function pe(D){return D===void 0}function _s(){Object.keys(g.counts).find((D)=>{if(v(D,g.arrays))return F=Error(m("Invalid configuration: %s, opts.count excludes opts.array.",D)),!0;else if(v(D,g.nargs))return F=Error(m("Invalid configuration: %s, opts.count excludes opts.narg.",D)),!0;return!1})}return{aliases:Object.assign({},g.aliases),argv:Object.assign(L,S),configuration:o,defaulted:Object.assign({},p),error:F,newAliases:Object.assign({},d)}}}function Nu(e){let t=[],n=Object.create(null),r=!0;Object.keys(e).forEach(function(s){t.push([].concat(e[s],s))});while(r){r=!1;for(let s=0;s<t.length;s++)for(let i=s+1;i<t.length;i++)if(t[s].filter(function(a){return t[i].indexOf(a)!==-1}).length){t[s]=t[s].concat(t[i]),t.splice(i,1),r=!0;break}}return t.forEach(function(s){s=s.filter(function(o,a,c){return c.indexOf(o)===a});let i=s.pop();if(i!==void 0&&typeof i==="string")n[i]=s}),n}function Ps(e){return e!==void 0?e+1:1}function Mi(e){if(e==="__proto__")return"___proto___";return e}function vu(e){return typeof e==="string"&&(e[0]==="'"||e[0]==='"')&&e[e.length-1]===e[0]?e.substring(1,e.length-1):e}import{readFileSync as Uu}from"fs";import{createRequire as Bi}from"node:module";var Ms,Bs,Ns,Ni=process&&process.env&&process.env.YARGS_MIN_NODE_VERSION?Number(process.env.YARGS_MIN_NODE_VERSION):20,vi=(Bs=(Ms=process===null||process===void 0?void 0:process.versions)===null||Ms===void 0?void 0:Ms.node)!==null&&Bs!==void 0?Bs:(Ns=process===null||process===void 0?void 0:process.version)===null||Ns===void 0?void 0:Ns.slice(1);if(vi){if(Number(vi.match(/^([^.]+)/)[1])<Ni)throw Error(`yargs parser supports a minimum Node.js version of ${Ni}. Read our version support policy: https://github.com/yargs/yargs-parser#supported-nodejs-versions`)}var Ku=process?process.env:{},ji=Bi?Bi(import.meta.url):void 0,Li=new Rs({cwd:process.cwd,env:()=>Ku,format:ju,normalize:Lu,resolve:Wu,require:(e)=>{if(typeof ji<"u")return ji(e);else if(e.match(/\.json$/))return JSON.parse(Uu(e,"utf8"));else throw Error("only .json config files are supported in ESM")}}),tn=function(t,n){return Li.parse(t.slice(),n).argv};tn.detailed=function(e,t){return Li.parse(e.slice(),t)};tn.camelCase=pt;tn.decamelize=On;tn.looksLikeNumber=In;var vs=tn;import{basename as tl,dirname as nl,extname as sl,relative as rl,resolve as Xi,join as il}from"path";function Wi(){if(Ju())return 0;return 1}function Ju(){return zu()&&!process.defaultApp}function zu(){return!!process.versions.electron}function js(e){return e.slice(Wi()+1)}function Ui(){return process.argv[Wi()]}import{readFileSync as Hu,statSync as qu,writeFile as Yu}from"fs";import{format as Xu}from"util";import{resolve as Gu}from"path";var Ki={fs:{readFileSync:Hu,writeFile:Yu},format:Xu,resolve:Gu,exists:(e)=>{try{return qu(e).isFile()}catch(t){return!1}}};var Le;class Ji{constructor(e){e=e||{},this.directory=e.directory||"./locales",this.updateFiles=typeof e.updateFiles==="boolean"?e.updateFiles:!0,this.locale=e.locale||"en",this.fallbackToLanguage=typeof e.fallbackToLanguage==="boolean"?e.fallbackToLanguage:!0,this.cache=Object.create(null),this.writeQueue=[]}__(...e){if(typeof arguments[0]!=="string")return this._taggedLiteral(arguments[0],...arguments);let t=e.shift(),n=function(){};if(typeof e[e.length-1]==="function")n=e.pop();if(n=n||function(){},!this.cache[this.locale])this._readLocaleFile();if(!this.cache[this.locale][t]&&this.updateFiles)this.cache[this.locale][t]=t,this._enqueueWrite({directory:this.directory,locale:this.locale,cb:n});else n();return Le.format.apply(Le.format,[this.cache[this.locale][t]||t].concat(e))}__n(){let e=Array.prototype.slice.call(arguments),t=e.shift(),n=e.shift(),r=e.shift(),s=function(){};if(typeof e[e.length-1]==="function")s=e.pop();if(!this.cache[this.locale])this._readLocaleFile();let i=r===1?t:n;if(this.cache[this.locale][t])i=this.cache[this.locale][t][r===1?"one":"other"];if(!this.cache[this.locale][t]&&this.updateFiles)this.cache[this.locale][t]={one:t,other:n},this._enqueueWrite({directory:this.directory,locale:this.locale,cb:s});else s();let o=[i];if(~i.indexOf("%d"))o.push(r);return Le.format.apply(Le.format,o.concat(e))}setLocale(e){this.locale=e}getLocale(){return this.locale}updateLocale(e){if(!this.cache[this.locale])this._readLocaleFile();for(let t in e)if(Object.prototype.hasOwnProperty.call(e,t))this.cache[this.locale][t]=e[t]}_taggedLiteral(e,...t){let n="";return e.forEach(function(r,s){let i=t[s+1];if(n+=r,typeof i<"u")n+="%s"}),this.__.apply(this,[n].concat([].slice.call(t,1)))}_enqueueWrite(e){if(this.writeQueue.push(e),this.writeQueue.length===1)this._processWriteQueue()}_processWriteQueue(){let e=this,t=this.writeQueue[0],n=t.directory,r=t.locale,s=t.cb,i=this._resolveLocaleFile(n,r),o=JSON.stringify(this.cache[r],null,2);Le.fs.writeFile(i,o,"utf-8",function(a){if(e.writeQueue.shift(),e.writeQueue.length>0)e._processWriteQueue();s(a)})}_readLocaleFile(){let e={},t=this._resolveLocaleFile(this.directory,this.locale);try{if(Le.fs.readFileSync)e=JSON.parse(Le.fs.readFileSync(t,"utf-8"))}catch(n){if(n instanceof SyntaxError)n.message="syntax error in "+t;if(n.code==="ENOENT")e={};else throw n}this.cache[this.locale]=e}_resolveLocaleFile(e,t){let n=Le.resolve(e,"./",t+".json");if(this.fallbackToLanguage&&!this._fileExistsSync(n)&&~t.lastIndexOf("_")){let r=Le.resolve(e,"./",t.split("_")[0]+".json");if(this._fileExistsSync(r))n=r}return n}_fileExistsSync(e){return Le.exists(e)}}function zi(e,t){Le=t;let n=new Ji(e);return{__:n.__.bind(n),__n:n.__n.bind(n),setLocale:n.setLocale.bind(n),getLocale:n.getLocale.bind(n),updateLocale:n.updateLocale.bind(n),locale:n.locale}}var Vu=(e)=>zi(e,Ki),Hi=Vu;var Vi=si(Yi(),1);import{createRequire as ol}from"node:module";import{readFileSync as al,readdirSync as cl}from"node:fs";var Ls=Gi(import.meta.url),ul=Ls.substring(0,Ls.lastIndexOf("node_modules")),ll=ol(import.meta.url),Ws={assert:{notStrictEqual:Zu,strictEqual:Qu},cliui:Is,findUp:Ts,getEnv:(e)=>process.env[e],inspect:el,getProcessArgvBin:Ui,mainFilename:ul||process.cwd(),Parser:vs,path:{basename:tl,dirname:nl,extname:sl,relative:rl,resolve:Xi,join:il},process:{argv:()=>process.argv,cwd:process.cwd,emitWarning:(e,t)=>process.emitWarning(e,t),execPath:()=>process.execPath,exit:(e)=>{process.exit(e)},nextTick:process.nextTick,stdColumns:typeof process.stdout.columns<"u"?process.stdout.columns:null},readFileSync:al,readdirSync:cl,require:ll,getCallerFile:()=>{let e=Vi.default(3);return e.match(/^file:\/\//)?Gi(e):e},stringWidth:je,y18n:Hi({directory:Xi(Ls,"../../../locales"),updateFiles:!1})};function Ce(e,t,n,r){n.assert.notStrictEqual(e,t,r)}function Us(e,t){t.assert.strictEqual(typeof e,"string")}function Wt(e){return Object.keys(e)}function se(e){return!!e&&!!e.then&&typeof e.then==="function"}class le extends Error{constructor(e){super(e||"yargs error");if(this.name="YError",Error.captureStackTrace)Error.captureStackTrace(this,le)}}function nt(e){let n=e.replace(/\s{2,}/g," ").split(/\s+(?![^[]*]|[^<]*>)/),r=/\.*[\][<>]/g,s=n.shift();if(!s)throw Error(`No command found in: ${e}`);let i={cmd:s.replace(r,""),demanded:[],optional:[]};return n.forEach((o,a)=>{let c=!1;if(o=o.replace(/\s/g,""),/\.+[\]>]/.test(o)&&a===n.length-1)c=!0;if(/^\[/.test(o))i.optional.push({cmd:o.replace(r,"").split("|"),variadic:c});else i.demanded.push({cmd:o.replace(r,"").split("|"),variadic:c})}),i}var fl=["first","second","third","fourth","fifth","sixth"];function j(e,t,n){function r(){return typeof e==="object"?[{demanded:[],optional:[]},e,t]:[nt(`cmd ${e}`),t,n]}try{let s=0,[i,o,a]=r(),c=[].slice.call(o);while(c.length&&c[c.length-1]===void 0)c.pop();let u=a||c.length;if(u<i.demanded.length)throw new le(`Not enough arguments provided. Expected ${i.demanded.length} but received ${c.length}.`);let f=i.demanded.length+i.optional.length;if(u>f)throw new le(`Too many arguments provided. Expected max ${f} but received ${u}.`);i.demanded.forEach((l)=>{let d=c.shift(),p=Zi(d);if(l.cmd.filter((g)=>g===p||g==="*").length===0)Qi(p,l.cmd,s);s+=1}),i.optional.forEach((l)=>{if(c.length===0)return;let d=c.shift(),p=Zi(d);if(l.cmd.filter((g)=>g===p||g==="*").length===0)Qi(p,l.cmd,s);s+=1})}catch(s){console.warn(s.stack)}}function Zi(e){if(Array.isArray(e))return"array";else if(e===null)return"null";return typeof e}function Qi(e,t,n){throw new le(`Invalid ${fl[n]||"manyith"} argument. Expected ${t.join(" or ")} but received ${e}.`)}class Ks{constructor(e){this.globalMiddleware=[],this.frozens=[],this.yargs=e}addMiddleware(e,t,n=!0,r=!1){if(j("<array|function> [boolean] [boolean] [boolean]",[e,t,n],arguments.length),Array.isArray(e)){for(let s=0;s<e.length;s++){if(typeof e[s]!=="function")throw Error("middleware must be a function");let i=e[s];i.applyBeforeValidation=t,i.global=n}Array.prototype.push.apply(this.globalMiddleware,e)}else if(typeof e==="function"){let s=e;s.applyBeforeValidation=t,s.global=n,s.mutates=r,this.globalMiddleware.push(e)}return this.yargs}addCoerceMiddleware(e,t){let n=this.yargs.getAliases();return this.globalMiddleware=this.globalMiddleware.filter((r)=>{let s=[...n[t]||[],t];if(!r.option)return!0;else return!s.includes(r.option)}),e.option=t,this.addMiddleware(e,!0,!0,!0)}getMiddleware(){return this.globalMiddleware}freeze(){this.frozens.push([...this.globalMiddleware])}unfreeze(){let e=this.frozens.pop();if(e!==void 0)this.globalMiddleware=e}reset(){this.globalMiddleware=this.globalMiddleware.filter((e)=>e.global)}}function eo(e){if(!e)return[];return e.map((t)=>(t.applyBeforeValidation=!1,t))}function ht(e,t,n,r){return n.reduce((s,i)=>{if(i.applyBeforeValidation!==r)return s;if(i.mutates){if(i.applied)return s;i.applied=!0}if(se(s))return s.then((o)=>Promise.all([o,i(o,t)])).then(([o,a])=>Object.assign(o,a));else{let o=i(s,t);return se(o)?o.then((a)=>Object.assign(s,a)):Object.assign(s,o)}},e)}function gt(e,t,n=(r)=>{throw r}){try{let r=dl(e)?e():e;return se(r)?r.then((s)=>t(s)):t(r)}catch(r){return n(r)}}function dl(e){return typeof e==="function"}var Ut=/(^\*)|(^\$0)/;class no{constructor(e,t,n,r){this.requireCache=new Set,this.handlers={},this.aliasMap={},this.frozens=[],this.shim=r,this.usage=e,this.globalMiddleware=n,this.validation=t}addDirectory(e,t,n,r){r=r||{},this.requireCache.add(n);let s=this.shim.path.resolve(this.shim.path.dirname(n),e),i=this.shim.readdirSync(s,{recursive:r.recurse?!0:!1});if(!Array.isArray(r.extensions))r.extensions=["js"];let o=typeof r.visit==="function"?r.visit:(a)=>a;for(let a of i){let c=a.toString();if(r.exclude){let f=!1;if(typeof r.exclude==="function")f=r.exclude(c);else f=r.exclude.test(c);if(f)continue}if(r.include){let f=!1;if(typeof r.include==="function")f=r.include(c);else f=r.include.test(c);if(!f)continue}let u=!1;for(let f of r.extensions)if(c.endsWith(f))u=!0;if(u){let f=this.shim.path.join(s,c),l=t(f),d=Object.create(null,Object.getOwnPropertyDescriptors({...l}));if(o(d,f,c)){if(this.requireCache.has(f))continue;else this.requireCache.add(f);if(!d.command)d.command=this.shim.path.basename(f,this.shim.path.extname(f));this.addHandler(d)}}}}addHandler(e,t,n,r,s,i){let o=[],a=eo(s);if(r=r||(()=>{}),Array.isArray(e))if(pl(e))[e,...o]=e;else for(let c of e)this.addHandler(c);else if(gl(e)){let c=Array.isArray(e.command)||typeof e.command==="string"?e.command:null;if(c===null)throw Error(`No command name given for module: ${this.shim.inspect(e)}`);if(e.aliases)c=[].concat(c).concat(e.aliases);this.addHandler(c,this.extractDesc(e),e.builder,e.handler,e.middlewares,e.deprecated);return}else if(to(n)){this.addHandler([e].concat(o),t,n.builder,n.handler,n.middlewares,n.deprecated);return}if(typeof e==="string"){let c=nt(e);o=o.map((l)=>nt(l).cmd);let u=!1,f=[c.cmd].concat(o).filter((l)=>{if(Ut.test(l))return u=!0,!1;return!0});if(f.length===0&&u)f.push("$0");if(u)c.cmd=f[0],o=f.slice(1),e=e.replace(Ut,c.cmd);if(o.forEach((l)=>{this.aliasMap[l]=c.cmd}),t!==!1)this.usage.command(e,t,u,o,i);if(this.handlers[c.cmd]={original:e,description:t,handler:r,builder:n||{},middlewares:a,deprecated:i,demanded:c.demanded,optional:c.optional},u)this.defaultCommand=this.handlers[c.cmd]}}getCommandHandlers(){return this.handlers}getCommands(){return Object.keys(this.handlers).concat(Object.keys(this.aliasMap))}hasDefaultCommand(){return!!this.defaultCommand}runCommand(e,t,n,r,s,i){let o=this.handlers[e]||this.handlers[this.aliasMap[e]]||this.defaultCommand,a=t.getInternalMethods().getContext(),c=a.commands.slice(),u=!e;if(e)a.commands.push(e),a.fullCommands.push(o.original);let f=this.applyBuilderUpdateUsageAndParse(u,o,t,n.aliases,c,r,s,i);return se(f)?f.then((l)=>this.applyMiddlewareAndGetResult(u,o,l.innerArgv,a,s,l.aliases,t)):this.applyMiddlewareAndGetResult(u,o,f.innerArgv,a,s,f.aliases,t)}applyBuilderUpdateUsageAndParse(e,t,n,r,s,i,o,a){let c=t.builder,u=n;if(Tn(c)){n.getInternalMethods().getUsageInstance().freeze();let f=c(n.getInternalMethods().reset(r),a);if(se(f))return f.then((l)=>(u=ro(l)?l:n,this.parseAndUpdateUsage(e,t,u,s,i,o)))}else if(hl(c))n.getInternalMethods().getUsageInstance().freeze(),u=n.getInternalMethods().reset(r),Object.keys(t.builder).forEach((f)=>{u.option(f,c[f])});return this.parseAndUpdateUsage(e,t,u,s,i,o)}parseAndUpdateUsage(e,t,n,r,s,i){if(e)n.getInternalMethods().getUsageInstance().unfreeze(!0);if(this.shouldUpdateUsage(n))n.getInternalMethods().getUsageInstance().usage(this.usageFromParentCommandsCommandHandler(r,t),t.description);let o=n.getInternalMethods().runYargsParserAndExecuteCommands(null,void 0,!0,s,i);return se(o)?o.then((a)=>({aliases:n.parsed.aliases,innerArgv:a})):{aliases:n.parsed.aliases,innerArgv:o}}shouldUpdateUsage(e){return!e.getInternalMethods().getUsageInstance().getUsageDisabled()&&e.getInternalMethods().getUsageInstance().getUsage().length===0}usageFromParentCommandsCommandHandler(e,t){let n=Ut.test(t.original)?t.original.replace(Ut,"").trim():t.original,r=e.filter((s)=>!Ut.test(s));return r.push(n),`$0 ${r.join(" ")}`}handleValidationAndGetResult(e,t,n,r,s,i,o,a){if(!i.getInternalMethods().getHasOutput()){let c=i.getInternalMethods().runValidation(s,a,i.parsed.error,e);n=gt(n,(u)=>(c(u),u))}if(t.handler&&!i.getInternalMethods().getHasOutput()){i.getInternalMethods().setHasOutput();let c=!!i.getOptions().configuration["populate--"];if(i.getInternalMethods().postProcess(n,c,!1,!1),n=ht(n,i,o,!1),n=gt(n,(u)=>{let f=t.handler(u);return se(f)?f.then(()=>u):u}),!e)i.getInternalMethods().getUsageInstance().cacheHelpMessage();if(se(n)&&!i.getInternalMethods().hasParseCallback())n.catch((u)=>{try{i.getInternalMethods().getUsageInstance().fail(null,u)}catch(f){}})}if(!e)r.commands.pop(),r.fullCommands.pop();return n}applyMiddlewareAndGetResult(e,t,n,r,s,i,o){let a={};if(s)return n;if(!o.getInternalMethods().getHasOutput())a=this.populatePositionals(t,n,r,o);let c=this.globalMiddleware.getMiddleware().slice(0).concat(t.middlewares),u=ht(n,o,c,!0);return se(u)?u.then((f)=>this.handleValidationAndGetResult(e,t,f,r,i,o,c,a)):this.handleValidationAndGetResult(e,t,u,r,i,o,c,a)}populatePositionals(e,t,n,r){t._=t._.slice(n.commands.length);let s=e.demanded.slice(0),i=e.optional.slice(0),o={};this.validation.positionalCount(s.length,t._.length);while(s.length){let a=s.shift();this.populatePositional(a,t,o)}while(i.length){let a=i.shift();this.populatePositional(a,t,o)}return t._=n.commands.concat(t._.map((a)=>""+a)),this.postProcessPositionals(t,o,this.cmdToParseOptions(e.original),r),o}populatePositional(e,t,n){let r=e.cmd[0];if(e.variadic)n[r]=t._.splice(0).map(String);else if(t._.length)n[r]=[String(t._.shift())]}cmdToParseOptions(e){let t={array:[],default:{},alias:{},demand:{}},n=nt(e);return n.demanded.forEach((r)=>{let[s,...i]=r.cmd;if(r.variadic)t.array.push(s),t.default[s]=[];t.alias[s]=i,t.demand[s]=!0}),n.optional.forEach((r)=>{let[s,...i]=r.cmd;if(r.variadic)t.array.push(s),t.default[s]=[];t.alias[s]=i}),t}postProcessPositionals(e,t,n,r){let s=Object.assign({},r.getOptions());s.default=Object.assign(n.default,s.default);for(let c of Object.keys(n.alias))s.alias[c]=(s.alias[c]||[]).concat(n.alias[c]);s.array=s.array.concat(n.array),s.config={};let i=[];if(Object.keys(t).forEach((c)=>{t[c].map((u)=>{if(s.configuration["unknown-options-as-args"])s.key[c]=!0;i.push(`--${c}`),i.push(u)})}),!i.length)return;let o=Object.assign({},s.configuration,{"populate--":!1}),a=this.shim.Parser.detailed(i,Object.assign({},s,{configuration:o}));if(a.error)r.getInternalMethods().getUsageInstance().fail(a.error.message,a.error);else{let c=Object.keys(t);Object.keys(t).forEach((u)=>{c.push(...a.aliases[u])}),Object.keys(a.argv).forEach((u)=>{if(c.includes(u)){if(!t[u])t[u]=a.argv[u];if(!this.isInConfigs(r,u)&&!this.isDefaulted(r,u)&&Object.prototype.hasOwnProperty.call(e,u)&&Object.prototype.hasOwnProperty.call(a.argv,u)&&(Array.isArray(e[u])||Array.isArray(a.argv[u])))e[u]=[].concat(e[u],a.argv[u]);else e[u]=a.argv[u]}})}}isDefaulted(e,t){let{default:n}=e.getOptions();return Object.prototype.hasOwnProperty.call(n,t)||Object.prototype.hasOwnProperty.call(n,this.shim.Parser.camelCase(t))}isInConfigs(e,t){let{configObjects:n}=e.getOptions();return n.some((r)=>Object.prototype.hasOwnProperty.call(r,t))||n.some((r)=>Object.prototype.hasOwnProperty.call(r,this.shim.Parser.camelCase(t)))}runDefaultBuilderOn(e){if(!this.defaultCommand)return;if(this.shouldUpdateUsage(e)){let n=Ut.test(this.defaultCommand.original)?this.defaultCommand.original:this.defaultCommand.original.replace(/^[^[\]<>]*/,"$0 ");e.getInternalMethods().getUsageInstance().usage(n,this.defaultCommand.description)}let t=this.defaultCommand.builder;if(Tn(t))return t(e,!0);else if(!to(t))Object.keys(t).forEach((n)=>{e.option(n,t[n])});return}extractDesc({describe:e,description:t,desc:n}){for(let r of[e,t,n]){if(typeof r==="string"||r===!1)return r;Ce(r,!0,this.shim)}return!1}freeze(){this.frozens.push({handlers:this.handlers,aliasMap:this.aliasMap,defaultCommand:this.defaultCommand})}unfreeze(){let e=this.frozens.pop();Ce(e,void 0,this.shim),{handlers:this.handlers,aliasMap:this.aliasMap,defaultCommand:this.defaultCommand}=e}reset(){return this.handlers={},this.aliasMap={},this.defaultCommand=void 0,this.requireCache=new Set,this}}function so(e,t,n,r){return new no(e,t,n,r)}function to(e){return typeof e==="object"&&!!e.builder&&typeof e.handler==="function"}function pl(e){return e.every((t)=>typeof t==="string")}function Tn(e){return typeof e==="function"}function hl(e){return typeof e==="object"}function gl(e){return typeof e==="object"&&!Array.isArray(e)}function st(e={},t=()=>!0){let n={};return Wt(e).forEach((r)=>{if(t(r,e[r]))n[r]=e[r]}),n}function rt(e){if(typeof process>"u")return;[process.stdout,process.stderr].forEach((t)=>{let n=t;if(n._handle&&n.isTTY&&typeof n._handle.setBlocking==="function")n._handle.setBlocking(e)})}function ml(e){return typeof e==="boolean"}function oo(e,t){let n=t.y18n.__,r={},s=[];r.failFn=function(E){s.push(E)};let i=null,o=null,a=!0;r.showHelpOnFail=function(E=!0,O){let[N,Q]=typeof E==="string"?[!0,E]:[E,O];if(e.getInternalMethods().isGlobalContext())o=Q;return i=Q,a=N,r};let c=!1;r.fail=function(E,O){let N=e.getInternalMethods().getLoggerInstance();if(s.length)for(let Q=s.length-1;Q>=0;--Q){let oe=s[Q];if(ml(oe)){if(O)throw O;else if(E)throw Error(E)}else oe(E,O,r)}else{if(e.getExitProcess())rt(!0);if(!c){if(c=!0,a)e.showHelp("error"),N.error();if(E||O)N.error(E||O);let Q=i||o;if(Q){if(E||O)N.error("");N.error(Q)}}if(O=O||new le(E),e.getExitProcess())return e.exit(1);else if(e.getInternalMethods().hasParseCallback())return e.exit(1,O);else throw O}};let u=[],f=!1;r.usage=(_,E)=>{if(_===null)return f=!0,u=[],r;return f=!1,u.push([_,E||""]),r},r.getUsage=()=>u,r.getUsageDisabled=()=>f,r.getPositionalGroupName=()=>n("Positionals:");let l=[];r.example=(_,E)=>{l.push([_,E||""])};let d=[];r.command=function(E,O,N,Q,oe=!1){if(N)d=d.map((V)=>(V[2]=!1,V));d.push([E,O||"",N,Q,oe])},r.getCommands=()=>d;let p={};r.describe=function(E,O){if(Array.isArray(E))E.forEach((N)=>{r.describe(N,O)});else if(typeof E==="object")Object.keys(E).forEach((N)=>{r.describe(N,E[N])});else p[E]=O},r.getDescriptions=()=>p;let m=[];r.epilog=(_)=>{m.push(_)};let g=!1,y;r.wrap=(_)=>{g=!0,y=_},r.getWrap=()=>{if(t.getEnv("YARGS_DISABLE_WRAP"))return null;if(!g)y=B(),g=!0;return y};let C="__yargsString__:";r.deferY18nLookup=(_)=>C+_,r.help=function(){if(S)return S;k();let E=e.customScriptName?e.$0:t.path.basename(e.$0),O=e.getDemandedOptions(),N=e.getDemandedCommands(),Q=e.getDeprecatedOptions(),oe=e.getGroups(),V=e.getOptions(),ae=[];ae=ae.concat(Object.keys(p)),ae=ae.concat(Object.keys(O)),ae=ae.concat(Object.keys(N)),ae=ae.concat(Object.keys(V.default)),ae=ae.filter(A),ae=Object.keys(ae.reduce((z,ne)=>{if(ne!=="_")z[ne]=!0;return z},{}));let Ie=r.getWrap(),ee=t.cliui({width:Ie,wrap:!!Ie});if(!f){if(u.length)u.forEach((z)=>{if(ee.div({text:`${z[0].replace(/\$0/g,E)}`}),z[1])ee.div({text:`${z[1]}`,padding:[1,0,0,0]})}),ee.div();else if(d.length){let z=null;if(N._)z=`${E} <${n("command")}>
13
+ `).map((r)=>vu(r,t,n)).join(`
14
+ `)}function Rs(e){return ci(e,{stringWidth:je,stripAnsi:ht,wrap:Ps})}import{dirname as Pi,resolve as Ri}from"path";import{readdirSync as ju,statSync as Lu}from"fs";function Ms(e,t){let n=Ri(".",e),r;if(!Lu(n).isDirectory())n=Pi(n);while(!0){if(r=t(n,ju(n)),r)return Ri(n,r);if(n=Pi(r=n),r===n)break}}import{inspect as rl}from"util";import{fileURLToPath as Vi}from"url";import{format as Ku}from"util";import{normalize as Ju,resolve as zu}from"path";function gt(e){if(!(e!==e.toLowerCase()&&e!==e.toUpperCase()))e=e.toLowerCase();if(e.indexOf("-")===-1&&e.indexOf("_")===-1)return e;else{let n="",r=!1,s=e.match(/^-+/);for(let i=s?s[0].length:0;i<e.length;i++){let o=e.charAt(i);if(r)r=!1,o=o.toUpperCase();if(i!==0&&(o==="-"||o==="_"))r=!0;else if(o!=="-"&&o!=="_")n+=o}return n}}function On(e,t){let n=e.toLowerCase();t=t||"-";let r="";for(let s=0;s<e.length;s++){let i=n.charAt(s),o=e.charAt(s);if(i!==o&&s>0)r+=`${t}${n.charAt(s)}`;else r+=o}return r}function In(e){if(e===null||e===void 0)return!1;if(typeof e==="number")return!0;if(/^0x[0-9a-f]+$/i.test(e))return!0;if(/^0[^.]/.test(e))return!1;return/^[-]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(e)}function Mi(e){if(Array.isArray(e))return e.map((o)=>typeof o!=="string"?o+"":o);e=e.trim();let t=0,n=null,r=null,s=null,i=[];for(let o=0;o<e.length;o++){if(n=r,r=e.charAt(o),r===" "&&!s){if(n!==" ")t++;continue}if(r===s)s=null;else if((r==="'"||r==='"')&&!s)s=r;if(!i[t])i[t]="";i[t]+=r}return i}var Te;(function(e){e.BOOLEAN="boolean",e.STRING="string",e.NUMBER="number",e.ARRAY="array"})(Te||(Te={}));var Qe;class Ns{constructor(e){Qe=e}parse(e,t){let n=Object.assign({alias:void 0,array:void 0,boolean:void 0,config:void 0,configObjects:void 0,configuration:void 0,coerce:void 0,count:void 0,default:void 0,envPrefix:void 0,narg:void 0,normalize:void 0,string:void 0,number:void 0,__:void 0,key:void 0},t),r=Mi(e),s=typeof e==="string",i=Wu(Object.assign(Object.create(null),n.alias)),o=Object.assign({"boolean-negation":!0,"camel-case-expansion":!0,"combine-arrays":!1,"dot-notation":!0,"duplicate-arguments-array":!0,"flatten-duplicate-arrays":!0,"greedy-arrays":!0,"halt-at-non-option":!1,"nargs-eats-options":!1,"negation-prefix":"no-","parse-numbers":!0,"parse-positional-numbers":!0,"populate--":!1,"set-placeholder-key":!1,"short-option-groups":!0,"strip-aliased":!1,"strip-dashed":!1,"unknown-options-as-args":!1},n.configuration),a=Object.assign(Object.create(null),n.default),c=n.configObjects||[],u=n.envPrefix,f=o["populate--"],l=f?"--":"_",d=Object.create(null),p=Object.create(null),m=n.__||Qe.format,g={aliases:Object.create(null),arrays:Object.create(null),bools:Object.create(null),strings:Object.create(null),numbers:Object.create(null),counts:Object.create(null),normalize:Object.create(null),configs:Object.create(null),nargs:Object.create(null),coercions:Object.create(null),keys:[]},y=/^-([0-9]+(\.[0-9]+)?|\.[0-9]+)$/,C=new RegExp("^--"+o["negation-prefix"]+"(.+)");if([].concat(n.array||[]).filter(Boolean).forEach(function(D){let b=typeof D==="object"?D.key:D,I=Object.keys(D).map(function(x){return{boolean:"bools",string:"strings",number:"numbers"}[x]}).filter(Boolean).pop();if(I)g[I][b]=!0;g.arrays[b]=!0,g.keys.push(b)}),[].concat(n.boolean||[]).filter(Boolean).forEach(function(D){g.bools[D]=!0,g.keys.push(D)}),[].concat(n.string||[]).filter(Boolean).forEach(function(D){g.strings[D]=!0,g.keys.push(D)}),[].concat(n.number||[]).filter(Boolean).forEach(function(D){g.numbers[D]=!0,g.keys.push(D)}),[].concat(n.count||[]).filter(Boolean).forEach(function(D){g.counts[D]=!0,g.keys.push(D)}),[].concat(n.normalize||[]).filter(Boolean).forEach(function(D){g.normalize[D]=!0,g.keys.push(D)}),typeof n.narg==="object")Object.entries(n.narg).forEach(([D,b])=>{if(typeof b==="number")g.nargs[D]=b,g.keys.push(D)});if(typeof n.coerce==="object")Object.entries(n.coerce).forEach(([D,b])=>{if(typeof b==="function")g.coercions[D]=b,g.keys.push(D)});if(typeof n.config<"u"){if(Array.isArray(n.config)||typeof n.config==="string")[].concat(n.config).filter(Boolean).forEach(function(D){g.configs[D]=!0});else if(typeof n.config==="object")Object.entries(n.config).forEach(([D,b])=>{if(typeof b==="boolean"||typeof b==="function")g.configs[D]=b})}Z(n.key,i,n.default,g.arrays),Object.keys(a).forEach(function(D){(g.aliases[D]||[]).forEach(function(b){a[b]=a[D]})});let F=null;As();let S=[],k=Object.assign(Object.create(null),{_:[]}),L={};for(let D=0;D<r.length;D++){let b=r[D],I=b.replace(/^-{3,}/,"---"),x,w,U,M,J,ge;if(b!=="--"&&/^-/.test(b)&&ne(b))A(b);else if(I.match(/^---+(=|$)/)){A(b);continue}else if(b.match(/^--.+=/)||!o["short-option-groups"]&&b.match(/^-.+=/)){if(M=b.match(/^--?([^=]+)=([\s\S]*)$/),M!==null&&Array.isArray(M)&&M.length>=3)if(v(M[1],g.arrays))D=B(D,M[1],r,M[2]);else if(v(M[1],g.nargs)!==!1)D=R(D,M[1],r,M[2]);else P(M[1],M[2],!0)}else if(b.match(C)&&o["boolean-negation"]){if(M=b.match(C),M!==null&&Array.isArray(M)&&M.length>=2)w=M[1],P(w,v(w,g.arrays)?[!1]:!1)}else if(b.match(/^--.+/)||!o["short-option-groups"]&&b.match(/^-[^-]+/)){if(M=b.match(/^--?(.+)/),M!==null&&Array.isArray(M)&&M.length>=2)if(w=M[1],v(w,g.arrays))D=B(D,w,r);else if(v(w,g.nargs)!==!1)D=R(D,w,r);else if(J=r[D+1],J!==void 0&&(!J.match(/^-/)||J.match(y))&&!v(w,g.bools)&&!v(w,g.counts))P(w,J),D++;else if(/^(true|false)$/.test(J))P(w,J),D++;else P(w,G(w))}else if(b.match(/^-.\..+=/)){if(M=b.match(/^-([^=]+)=([\s\S]*)$/),M!==null&&Array.isArray(M)&&M.length>=3)P(M[1],M[2])}else if(b.match(/^-.\..+/)&&!b.match(y)){if(J=r[D+1],M=b.match(/^-(.\..+)/),M!==null&&Array.isArray(M)&&M.length>=2)if(w=M[1],J!==void 0&&!J.match(/^-/)&&!v(w,g.bools)&&!v(w,g.counts))P(w,J),D++;else P(w,G(w))}else if(b.match(/^-[^-]+/)&&!b.match(y)){U=b.slice(1,-1).split(""),x=!1;for(let Fe=0;Fe<U.length;Fe++){if(J=b.slice(Fe+2),U[Fe+1]&&U[Fe+1]==="="){if(ge=b.slice(Fe+3),w=U[Fe],v(w,g.arrays))D=B(D,w,r,ge);else if(v(w,g.nargs)!==!1)D=R(D,w,r,ge);else P(w,ge);x=!0;break}if(J==="-"){P(U[Fe],J);continue}if(/[A-Za-z]/.test(U[Fe])&&/^-?\d+(\.\d*)?(e-?\d+)?$/.test(J)&&v(J,g.bools)===!1){P(U[Fe],J),x=!0;break}if(U[Fe+1]&&U[Fe+1].match(/\W/)){P(U[Fe],J),x=!0;break}else P(U[Fe],G(U[Fe]))}if(w=b.slice(-1)[0],!x&&w!=="-")if(v(w,g.arrays))D=B(D,w,r);else if(v(w,g.nargs)!==!1)D=R(D,w,r);else if(J=r[D+1],J!==void 0&&(!/^(-|--)[^-]/.test(J)||J.match(y))&&!v(w,g.bools)&&!v(w,g.counts))P(w,J),D++;else if(/^(true|false)$/.test(J))P(w,J),D++;else P(w,G(w))}else if(b.match(/^-[0-9]$/)&&b.match(y)&&v(b.slice(1),g.bools))w=b.slice(1),P(w,G(w));else if(b==="--"){S=r.slice(D+1);break}else if(o["halt-at-non-option"]){S=r.slice(D);break}else A(b)}if(oe(k,!0),oe(k,!1),O(k),Q(),Ie(k,g.aliases,a,!0),V(k),o["set-placeholder-key"])ae(k);if(Object.keys(g.counts).forEach(function(D){if(!ee(k,D.split(".")))P(D,0)}),f&&S.length)k[l]=[];if(S.forEach(function(D){k[l].push(D)}),o["camel-case-expansion"]&&o["strip-dashed"])Object.keys(k).filter((D)=>D!=="--"&&D.includes("-")).forEach((D)=>{delete k[D]});if(o["strip-aliased"])[].concat(...Object.keys(i).map((D)=>i[D])).forEach((D)=>{if(o["camel-case-expansion"]&&D.includes("-"))delete k[D.split(".").map((b)=>gt(b)).join(".")];delete k[D]});function A(D){let b=E("_",D);if(typeof b==="string"||typeof b==="number")k._.push(b)}function R(D,b,I,x){let w,U=v(b,g.nargs);if(U=typeof U!=="number"||isNaN(U)?1:U,U===0){if(!pe(x))F=Error(m("Argument unexpected for: %s",b));return P(b,G(b)),D}let M=pe(x)?0:1;if(o["nargs-eats-options"]){if(I.length-(D+1)+M<U)F=Error(m("Not enough arguments following: %s",b));M=U}else{for(w=D+1;w<I.length;w++)if(!I[w].match(/^-[^0-9]/)||I[w].match(y)||ne(I[w]))M++;else break;if(M<U)F=Error(m("Not enough arguments following: %s",b))}let J=Math.min(M,U);if(!pe(x)&&J>0)P(b,x),J--;for(w=D+1;w<J+D+1;w++)P(b,I[w]);return D+J}function B(D,b,I,x){let w=[],U=x||I[D+1],M=v(b,g.nargs);if(v(b,g.bools)&&!/^(true|false)$/.test(U))w.push(!0);else if(pe(U)||pe(x)&&/^-/.test(U)&&!y.test(U)&&!ne(U)){if(a[b]!==void 0){let J=a[b];w=Array.isArray(J)?J:[J]}}else{if(!pe(x))w.push(_(b,x,!0));for(let J=D+1;J<I.length;J++){if(!o["greedy-arrays"]&&w.length>0||M&&typeof M==="number"&&w.length>=M)break;if(U=I[J],/^-/.test(U)&&!y.test(U)&&!ne(U))break;D=J,w.push(_(b,U,s))}}if(typeof M==="number"&&(M&&w.length<M||isNaN(M)&&w.length===0))F=Error(m("Not enough arguments following: %s",b));return P(b,w),D}function P(D,b,I=s){if(/-/.test(D)&&o["camel-case-expansion"]){let U=D.split(".").map(function(M){return gt(M)}).join(".");q(D,U)}let x=_(D,b,I),w=D.split(".");if(ke(k,w,x),g.aliases[D])g.aliases[D].forEach(function(U){let M=U.split(".");ke(k,M,x)});if(w.length>1&&o["dot-notation"])(g.aliases[w[0]]||[]).forEach(function(U){let M=U.split("."),J=[].concat(w);if(J.shift(),M=M.concat(J),!(g.aliases[D]||[]).includes(M.join(".")))ke(k,M,x)});if(v(D,g.normalize)&&!v(D,g.arrays))[D].concat(g.aliases[D]||[]).forEach(function(M){Object.defineProperty(L,M,{enumerable:!0,get(){return b},set(J){b=typeof J==="string"?Qe.normalize(J):J}})})}function q(D,b){if(!(g.aliases[D]&&g.aliases[D].length))g.aliases[D]=[b],d[b]=!0;if(!(g.aliases[b]&&g.aliases[b].length))q(b,D)}function _(D,b,I){if(I)b=Uu(b);if(v(D,g.bools)||v(D,g.counts)){if(typeof b==="string")b=b==="true"}let x=Array.isArray(b)?b.map(function(w){return E(D,w)}):E(D,b);if(v(D,g.counts)&&(pe(x)||typeof x==="boolean"))x=Bs();if(v(D,g.normalize)&&v(D,g.arrays))if(Array.isArray(b))x=b.map((w)=>Qe.normalize(w));else x=Qe.normalize(b);return x}function E(D,b){if(!o["parse-positional-numbers"]&&D==="_")return b;if(!v(D,g.strings)&&!v(D,g.bools)&&!Array.isArray(b)){if(In(b)&&o["parse-numbers"]&&Number.isSafeInteger(Math.floor(parseFloat(`${b}`)))||!pe(b)&&v(D,g.numbers))b=Number(b)}return b}function O(D){let b=Object.create(null);Ie(b,g.aliases,a),Object.keys(g.configs).forEach(function(I){let x=D[I]||b[I];if(x)try{let w=null,U=Qe.resolve(Qe.cwd(),x),M=g.configs[I];if(typeof M==="function"){try{w=M(U)}catch(J){w=J}if(w instanceof Error){F=w;return}}else w=Qe.require(U);N(w)}catch(w){if(w.name==="PermissionDenied")F=w;else if(D[I])F=Error(m("Invalid JSON config file: %s",x))}})}function N(D,b){Object.keys(D).forEach(function(I){let x=D[I],w=b?b+"."+I:I;if(typeof x==="object"&&x!==null&&!Array.isArray(x)&&o["dot-notation"])N(x,w);else if(!ee(k,w.split("."))||v(w,g.arrays)&&o["combine-arrays"])P(w,x)})}function Q(){if(typeof c<"u")c.forEach(function(D){N(D)})}function oe(D,b){if(typeof u>"u")return;let I=typeof u==="string"?u:"",x=Qe.env();Object.keys(x).forEach(function(w){if(I===""||w.lastIndexOf(I,0)===0){let U=w.split("__").map(function(M,J){if(J===0)M=M.substring(I.length);return gt(M)});if((b&&g.configs[U.join(".")]||!b)&&!ee(D,U))P(U.join("."),x[w])}})}function V(D){let b,I=new Set;Object.keys(D).forEach(function(x){if(!I.has(x)){if(b=v(x,g.coercions),typeof b==="function")try{let w=E(x,b(D[x]));[].concat(g.aliases[x]||[],x).forEach((U)=>{I.add(U),D[U]=w})}catch(w){F=w}}})}function ae(D){return g.keys.forEach((b)=>{if(~b.indexOf("."))return;if(typeof D[b]>"u")D[b]=void 0}),D}function Ie(D,b,I,x=!1){Object.keys(I).forEach(function(w){if(!ee(D,w.split("."))){if(ke(D,w.split("."),I[w]),x)p[w]=!0;(b[w]||[]).forEach(function(U){if(ee(D,U.split(".")))return;ke(D,U.split("."),I[w])})}})}function ee(D,b){let I=D;if(!o["dot-notation"])b=[b.join(".")];b.slice(0,-1).forEach(function(w){I=I[w]||{}});let x=b[b.length-1];if(typeof I!=="object")return!1;else return x in I}function ke(D,b,I){let x=D;if(!o["dot-notation"])b=[b.join(".")];b.slice(0,-1).forEach(function(ge){if(ge=Bi(ge),typeof x==="object"&&x[ge]===void 0)x[ge]={};if(typeof x[ge]!=="object"||Array.isArray(x[ge])){if(Array.isArray(x[ge]))x[ge].push({});else x[ge]=[x[ge],{}];x=x[ge][x[ge].length-1]}else x=x[ge]});let w=Bi(b[b.length-1]),U=v(b.join("."),g.arrays),M=Array.isArray(I),J=o["duplicate-arguments-array"];if(!J&&v(w,g.nargs)){if(J=!0,!pe(x[w])&&g.nargs[w]===1||Array.isArray(x[w])&&x[w].length===g.nargs[w])x[w]=void 0}if(I===Bs())x[w]=Bs(x[w]);else if(Array.isArray(x[w]))if(J&&U&&M)x[w]=o["flatten-duplicate-arrays"]?x[w].concat(I):(Array.isArray(x[w][0])?x[w]:[x[w]]).concat([I]);else if(!J&&Boolean(U)===Boolean(M))x[w]=I;else x[w]=x[w].concat([I]);else if(x[w]===void 0&&U)x[w]=M?I:[I];else if(J&&!(x[w]===void 0||v(w,g.counts)||v(w,g.bools)))x[w]=[x[w],I];else x[w]=I}function Z(...D){D.forEach(function(b){Object.keys(b||{}).forEach(function(I){if(g.aliases[I])return;g.aliases[I]=[].concat(i[I]||[]),g.aliases[I].concat(I).forEach(function(x){if(/-/.test(x)&&o["camel-case-expansion"]){let w=gt(x);if(w!==I&&g.aliases[I].indexOf(w)===-1)g.aliases[I].push(w),d[w]=!0}}),g.aliases[I].concat(I).forEach(function(x){if(x.length>1&&/[A-Z]/.test(x)&&o["camel-case-expansion"]){let w=On(x,"-");if(w!==I&&g.aliases[I].indexOf(w)===-1)g.aliases[I].push(w),d[w]=!0}}),g.aliases[I].forEach(function(x){g.aliases[x]=[I].concat(g.aliases[I].filter(function(w){return x!==w}))})})})}function v(D,b){let I=[].concat(g.aliases[D]||[],D),x=Object.keys(b),w=I.find((U)=>x.includes(U));return w?b[w]:!1}function be(D){let b=Object.keys(g);return[].concat(b.map((x)=>g[x])).some(function(x){return Array.isArray(x)?x.includes(D):x[D]})}function Ut(D,...b){return[].concat(...b).some(function(x){let w=D.match(x);return w&&be(w[1])})}function z(D){if(D.match(y)||!D.match(/^-[^-]+/))return!1;let b=!0,I,x=D.slice(1).split("");for(let w=0;w<x.length;w++){if(I=D.slice(w+2),!be(x[w])){b=!1;break}if(x[w+1]&&x[w+1]==="="||I==="-"||/[A-Za-z]/.test(x[w])&&/^-?\d+(\.\d*)?(e-?\d+)?$/.test(I)||x[w+1]&&x[w+1].match(/\W/))break}return b}function ne(D){return o["unknown-options-as-args"]&&de(D)}function de(D){if(D=D.replace(/^-{3,}/,"--"),D.match(y))return!1;if(z(D))return!1;return!Ut(D,/^-+([^=]+?)=[\s\S]*$/,C,/^-+([^=]+?)$/,/^-+([^=]+?)-$/,/^-+([^=]+?\d+)$/,/^-+([^=]+?)\W+.*$/)}function G(D){if(!v(D,g.bools)&&!v(D,g.counts)&&`${D}`in a)return a[D];else return ye(ue(D))}function ye(D){return{[Te.BOOLEAN]:!0,[Te.STRING]:"",[Te.NUMBER]:void 0,[Te.ARRAY]:[]}[D]}function ue(D){let b=Te.BOOLEAN;if(v(D,g.strings))b=Te.STRING;else if(v(D,g.numbers))b=Te.NUMBER;else if(v(D,g.bools))b=Te.BOOLEAN;else if(v(D,g.arrays))b=Te.ARRAY;return b}function pe(D){return D===void 0}function As(){Object.keys(g.counts).find((D)=>{if(v(D,g.arrays))return F=Error(m("Invalid configuration: %s, opts.count excludes opts.array.",D)),!0;else if(v(D,g.nargs))return F=Error(m("Invalid configuration: %s, opts.count excludes opts.narg.",D)),!0;return!1})}return{aliases:Object.assign({},g.aliases),argv:Object.assign(L,k),configuration:o,defaulted:Object.assign({},p),error:F,newAliases:Object.assign({},d)}}}function Wu(e){let t=[],n=Object.create(null),r=!0;Object.keys(e).forEach(function(s){t.push([].concat(e[s],s))});while(r){r=!1;for(let s=0;s<t.length;s++)for(let i=s+1;i<t.length;i++)if(t[s].filter(function(a){return t[i].indexOf(a)!==-1}).length){t[s]=t[s].concat(t[i]),t.splice(i,1),r=!0;break}}return t.forEach(function(s){s=s.filter(function(o,a,c){return c.indexOf(o)===a});let i=s.pop();if(i!==void 0&&typeof i==="string")n[i]=s}),n}function Bs(e){return e!==void 0?e+1:1}function Bi(e){if(e==="__proto__")return"___proto___";return e}function Uu(e){return typeof e==="string"&&(e[0]==="'"||e[0]==='"')&&e[e.length-1]===e[0]?e.substring(1,e.length-1):e}import{readFileSync as Hu}from"fs";import{createRequire as Ni}from"node:module";var vs,js,Ls,vi=process&&process.env&&process.env.YARGS_MIN_NODE_VERSION?Number(process.env.YARGS_MIN_NODE_VERSION):20,ji=(js=(vs=process===null||process===void 0?void 0:process.versions)===null||vs===void 0?void 0:vs.node)!==null&&js!==void 0?js:(Ls=process===null||process===void 0?void 0:process.version)===null||Ls===void 0?void 0:Ls.slice(1);if(ji){if(Number(ji.match(/^([^.]+)/)[1])<vi)throw Error(`yargs parser supports a minimum Node.js version of ${vi}. Read our version support policy: https://github.com/yargs/yargs-parser#supported-nodejs-versions`)}var qu=process?process.env:{},Li=Ni?Ni(import.meta.url):void 0,Wi=new Ns({cwd:process.cwd,env:()=>qu,format:Ku,normalize:Ju,resolve:zu,require:(e)=>{if(typeof Li<"u")return Li(e);else if(e.match(/\.json$/))return JSON.parse(Hu(e,"utf8"));else throw Error("only .json config files are supported in ESM")}}),tn=function(t,n){return Wi.parse(t.slice(),n).argv};tn.detailed=function(e,t){return Wi.parse(e.slice(),t)};tn.camelCase=gt;tn.decamelize=On;tn.looksLikeNumber=In;var Ws=tn;import{basename as il,dirname as ol,extname as al,relative as cl,resolve as Gi,join as ul}from"path";function Ui(){if(Yu())return 0;return 1}function Yu(){return Xu()&&!process.defaultApp}function Xu(){return!!process.versions.electron}function Us(e){return e.slice(Ui()+1)}function Ki(){return process.argv[Ui()]}import{readFileSync as Gu,statSync as Vu,writeFile as Zu}from"fs";import{format as Qu}from"util";import{resolve as el}from"path";var Ji={fs:{readFileSync:Gu,writeFile:Zu},format:Qu,resolve:el,exists:(e)=>{try{return Vu(e).isFile()}catch(t){return!1}}};var Le;class zi{constructor(e){e=e||{},this.directory=e.directory||"./locales",this.updateFiles=typeof e.updateFiles==="boolean"?e.updateFiles:!0,this.locale=e.locale||"en",this.fallbackToLanguage=typeof e.fallbackToLanguage==="boolean"?e.fallbackToLanguage:!0,this.cache=Object.create(null),this.writeQueue=[]}__(...e){if(typeof arguments[0]!=="string")return this._taggedLiteral(arguments[0],...arguments);let t=e.shift(),n=function(){};if(typeof e[e.length-1]==="function")n=e.pop();if(n=n||function(){},!this.cache[this.locale])this._readLocaleFile();if(!this.cache[this.locale][t]&&this.updateFiles)this.cache[this.locale][t]=t,this._enqueueWrite({directory:this.directory,locale:this.locale,cb:n});else n();return Le.format.apply(Le.format,[this.cache[this.locale][t]||t].concat(e))}__n(){let e=Array.prototype.slice.call(arguments),t=e.shift(),n=e.shift(),r=e.shift(),s=function(){};if(typeof e[e.length-1]==="function")s=e.pop();if(!this.cache[this.locale])this._readLocaleFile();let i=r===1?t:n;if(this.cache[this.locale][t])i=this.cache[this.locale][t][r===1?"one":"other"];if(!this.cache[this.locale][t]&&this.updateFiles)this.cache[this.locale][t]={one:t,other:n},this._enqueueWrite({directory:this.directory,locale:this.locale,cb:s});else s();let o=[i];if(~i.indexOf("%d"))o.push(r);return Le.format.apply(Le.format,o.concat(e))}setLocale(e){this.locale=e}getLocale(){return this.locale}updateLocale(e){if(!this.cache[this.locale])this._readLocaleFile();for(let t in e)if(Object.prototype.hasOwnProperty.call(e,t))this.cache[this.locale][t]=e[t]}_taggedLiteral(e,...t){let n="";return e.forEach(function(r,s){let i=t[s+1];if(n+=r,typeof i<"u")n+="%s"}),this.__.apply(this,[n].concat([].slice.call(t,1)))}_enqueueWrite(e){if(this.writeQueue.push(e),this.writeQueue.length===1)this._processWriteQueue()}_processWriteQueue(){let e=this,t=this.writeQueue[0],n=t.directory,r=t.locale,s=t.cb,i=this._resolveLocaleFile(n,r),o=JSON.stringify(this.cache[r],null,2);Le.fs.writeFile(i,o,"utf-8",function(a){if(e.writeQueue.shift(),e.writeQueue.length>0)e._processWriteQueue();s(a)})}_readLocaleFile(){let e={},t=this._resolveLocaleFile(this.directory,this.locale);try{if(Le.fs.readFileSync)e=JSON.parse(Le.fs.readFileSync(t,"utf-8"))}catch(n){if(n instanceof SyntaxError)n.message="syntax error in "+t;if(n.code==="ENOENT")e={};else throw n}this.cache[this.locale]=e}_resolveLocaleFile(e,t){let n=Le.resolve(e,"./",t+".json");if(this.fallbackToLanguage&&!this._fileExistsSync(n)&&~t.lastIndexOf("_")){let r=Le.resolve(e,"./",t.split("_")[0]+".json");if(this._fileExistsSync(r))n=r}return n}_fileExistsSync(e){return Le.exists(e)}}function Hi(e,t){Le=t;let n=new zi(e);return{__:n.__.bind(n),__n:n.__n.bind(n),setLocale:n.setLocale.bind(n),getLocale:n.getLocale.bind(n),updateLocale:n.updateLocale.bind(n),locale:n.locale}}var tl=(e)=>Hi(e,Ji),qi=tl;var Zi=ri(Xi(),1);import{createRequire as ll}from"node:module";import{readFileSync as fl,readdirSync as dl}from"node:fs";var Ks=Vi(import.meta.url),pl=Ks.substring(0,Ks.lastIndexOf("node_modules")),hl=ll(import.meta.url),Js={assert:{notStrictEqual:nl,strictEqual:sl},cliui:Rs,findUp:Ms,getEnv:(e)=>process.env[e],inspect:rl,getProcessArgvBin:Ki,mainFilename:pl||process.cwd(),Parser:Ws,path:{basename:il,dirname:ol,extname:al,relative:cl,resolve:Gi,join:ul},process:{argv:()=>process.argv,cwd:process.cwd,emitWarning:(e,t)=>process.emitWarning(e,t),execPath:()=>process.execPath,exit:(e)=>{process.exit(e)},nextTick:process.nextTick,stdColumns:typeof process.stdout.columns<"u"?process.stdout.columns:null},readFileSync:fl,readdirSync:dl,require:hl,getCallerFile:()=>{let e=Zi.default(3);return e.match(/^file:\/\//)?Vi(e):e},stringWidth:je,y18n:qi({directory:Gi(Ks,"../../../locales"),updateFiles:!1})};function Ce(e,t,n,r){n.assert.notStrictEqual(e,t,r)}function zs(e,t){t.assert.strictEqual(typeof e,"string")}function Kt(e){return Object.keys(e)}function se(e){return!!e&&!!e.then&&typeof e.then==="function"}class le extends Error{constructor(e){super(e||"yargs error");if(this.name="YError",Error.captureStackTrace)Error.captureStackTrace(this,le)}}function nt(e){let n=e.replace(/\s{2,}/g," ").split(/\s+(?![^[]*]|[^<]*>)/),r=/\.*[\][<>]/g,s=n.shift();if(!s)throw Error(`No command found in: ${e}`);let i={cmd:s.replace(r,""),demanded:[],optional:[]};return n.forEach((o,a)=>{let c=!1;if(o=o.replace(/\s/g,""),/\.+[\]>]/.test(o)&&a===n.length-1)c=!0;if(/^\[/.test(o))i.optional.push({cmd:o.replace(r,"").split("|"),variadic:c});else i.demanded.push({cmd:o.replace(r,"").split("|"),variadic:c})}),i}var gl=["first","second","third","fourth","fifth","sixth"];function j(e,t,n){function r(){return typeof e==="object"?[{demanded:[],optional:[]},e,t]:[nt(`cmd ${e}`),t,n]}try{let s=0,[i,o,a]=r(),c=[].slice.call(o);while(c.length&&c[c.length-1]===void 0)c.pop();let u=a||c.length;if(u<i.demanded.length)throw new le(`Not enough arguments provided. Expected ${i.demanded.length} but received ${c.length}.`);let f=i.demanded.length+i.optional.length;if(u>f)throw new le(`Too many arguments provided. Expected max ${f} but received ${u}.`);i.demanded.forEach((l)=>{let d=c.shift(),p=Qi(d);if(l.cmd.filter((g)=>g===p||g==="*").length===0)eo(p,l.cmd,s);s+=1}),i.optional.forEach((l)=>{if(c.length===0)return;let d=c.shift(),p=Qi(d);if(l.cmd.filter((g)=>g===p||g==="*").length===0)eo(p,l.cmd,s);s+=1})}catch(s){console.warn(s.stack)}}function Qi(e){if(Array.isArray(e))return"array";else if(e===null)return"null";return typeof e}function eo(e,t,n){throw new le(`Invalid ${gl[n]||"manyith"} argument. Expected ${t.join(" or ")} but received ${e}.`)}class Hs{constructor(e){this.globalMiddleware=[],this.frozens=[],this.yargs=e}addMiddleware(e,t,n=!0,r=!1){if(j("<array|function> [boolean] [boolean] [boolean]",[e,t,n],arguments.length),Array.isArray(e)){for(let s=0;s<e.length;s++){if(typeof e[s]!=="function")throw Error("middleware must be a function");let i=e[s];i.applyBeforeValidation=t,i.global=n}Array.prototype.push.apply(this.globalMiddleware,e)}else if(typeof e==="function"){let s=e;s.applyBeforeValidation=t,s.global=n,s.mutates=r,this.globalMiddleware.push(e)}return this.yargs}addCoerceMiddleware(e,t){let n=this.yargs.getAliases();return this.globalMiddleware=this.globalMiddleware.filter((r)=>{let s=[...n[t]||[],t];if(!r.option)return!0;else return!s.includes(r.option)}),e.option=t,this.addMiddleware(e,!0,!0,!0)}getMiddleware(){return this.globalMiddleware}freeze(){this.frozens.push([...this.globalMiddleware])}unfreeze(){let e=this.frozens.pop();if(e!==void 0)this.globalMiddleware=e}reset(){this.globalMiddleware=this.globalMiddleware.filter((e)=>e.global)}}function to(e){if(!e)return[];return e.map((t)=>(t.applyBeforeValidation=!1,t))}function mt(e,t,n,r){return n.reduce((s,i)=>{if(i.applyBeforeValidation!==r)return s;if(i.mutates){if(i.applied)return s;i.applied=!0}if(se(s))return s.then((o)=>Promise.all([o,i(o,t)])).then(([o,a])=>Object.assign(o,a));else{let o=i(s,t);return se(o)?o.then((a)=>Object.assign(s,a)):Object.assign(s,o)}},e)}function Dt(e,t,n=(r)=>{throw r}){try{let r=ml(e)?e():e;return se(r)?r.then((s)=>t(s)):t(r)}catch(r){return n(r)}}function ml(e){return typeof e==="function"}var Jt=/(^\*)|(^\$0)/;class so{constructor(e,t,n,r){this.requireCache=new Set,this.handlers={},this.aliasMap={},this.frozens=[],this.shim=r,this.usage=e,this.globalMiddleware=n,this.validation=t}addDirectory(e,t,n,r){r=r||{},this.requireCache.add(n);let s=this.shim.path.resolve(this.shim.path.dirname(n),e),i=this.shim.readdirSync(s,{recursive:r.recurse?!0:!1});if(!Array.isArray(r.extensions))r.extensions=["js"];let o=typeof r.visit==="function"?r.visit:(a)=>a;for(let a of i){let c=a.toString();if(r.exclude){let f=!1;if(typeof r.exclude==="function")f=r.exclude(c);else f=r.exclude.test(c);if(f)continue}if(r.include){let f=!1;if(typeof r.include==="function")f=r.include(c);else f=r.include.test(c);if(!f)continue}let u=!1;for(let f of r.extensions)if(c.endsWith(f))u=!0;if(u){let f=this.shim.path.join(s,c),l=t(f),d=Object.create(null,Object.getOwnPropertyDescriptors({...l}));if(o(d,f,c)){if(this.requireCache.has(f))continue;else this.requireCache.add(f);if(!d.command)d.command=this.shim.path.basename(f,this.shim.path.extname(f));this.addHandler(d)}}}}addHandler(e,t,n,r,s,i){let o=[],a=to(s);if(r=r||(()=>{}),Array.isArray(e))if(Dl(e))[e,...o]=e;else for(let c of e)this.addHandler(c);else if(wl(e)){let c=Array.isArray(e.command)||typeof e.command==="string"?e.command:null;if(c===null)throw Error(`No command name given for module: ${this.shim.inspect(e)}`);if(e.aliases)c=[].concat(c).concat(e.aliases);this.addHandler(c,this.extractDesc(e),e.builder,e.handler,e.middlewares,e.deprecated);return}else if(no(n)){this.addHandler([e].concat(o),t,n.builder,n.handler,n.middlewares,n.deprecated);return}if(typeof e==="string"){let c=nt(e);o=o.map((l)=>nt(l).cmd);let u=!1,f=[c.cmd].concat(o).filter((l)=>{if(Jt.test(l))return u=!0,!1;return!0});if(f.length===0&&u)f.push("$0");if(u)c.cmd=f[0],o=f.slice(1),e=e.replace(Jt,c.cmd);if(o.forEach((l)=>{this.aliasMap[l]=c.cmd}),t!==!1)this.usage.command(e,t,u,o,i);if(this.handlers[c.cmd]={original:e,description:t,handler:r,builder:n||{},middlewares:a,deprecated:i,demanded:c.demanded,optional:c.optional},u)this.defaultCommand=this.handlers[c.cmd]}}getCommandHandlers(){return this.handlers}getCommands(){return Object.keys(this.handlers).concat(Object.keys(this.aliasMap))}hasDefaultCommand(){return!!this.defaultCommand}runCommand(e,t,n,r,s,i){let o=this.handlers[e]||this.handlers[this.aliasMap[e]]||this.defaultCommand,a=t.getInternalMethods().getContext(),c=a.commands.slice(),u=!e;if(e)a.commands.push(e),a.fullCommands.push(o.original);let f=this.applyBuilderUpdateUsageAndParse(u,o,t,n.aliases,c,r,s,i);return se(f)?f.then((l)=>this.applyMiddlewareAndGetResult(u,o,l.innerArgv,a,s,l.aliases,t)):this.applyMiddlewareAndGetResult(u,o,f.innerArgv,a,s,f.aliases,t)}applyBuilderUpdateUsageAndParse(e,t,n,r,s,i,o,a){let c=t.builder,u=n;if(Tn(c)){n.getInternalMethods().getUsageInstance().freeze();let f=c(n.getInternalMethods().reset(r),a);if(se(f))return f.then((l)=>(u=io(l)?l:n,this.parseAndUpdateUsage(e,t,u,s,i,o)))}else if(yl(c))n.getInternalMethods().getUsageInstance().freeze(),u=n.getInternalMethods().reset(r),Object.keys(t.builder).forEach((f)=>{u.option(f,c[f])});return this.parseAndUpdateUsage(e,t,u,s,i,o)}parseAndUpdateUsage(e,t,n,r,s,i){if(e)n.getInternalMethods().getUsageInstance().unfreeze(!0);if(this.shouldUpdateUsage(n))n.getInternalMethods().getUsageInstance().usage(this.usageFromParentCommandsCommandHandler(r,t),t.description);let o=n.getInternalMethods().runYargsParserAndExecuteCommands(null,void 0,!0,s,i);return se(o)?o.then((a)=>({aliases:n.parsed.aliases,innerArgv:a})):{aliases:n.parsed.aliases,innerArgv:o}}shouldUpdateUsage(e){return!e.getInternalMethods().getUsageInstance().getUsageDisabled()&&e.getInternalMethods().getUsageInstance().getUsage().length===0}usageFromParentCommandsCommandHandler(e,t){let n=Jt.test(t.original)?t.original.replace(Jt,"").trim():t.original,r=e.filter((s)=>!Jt.test(s));return r.push(n),`$0 ${r.join(" ")}`}handleValidationAndGetResult(e,t,n,r,s,i,o,a){if(!i.getInternalMethods().getHasOutput()){let c=i.getInternalMethods().runValidation(s,a,i.parsed.error,e);n=Dt(n,(u)=>(c(u),u))}if(t.handler&&!i.getInternalMethods().getHasOutput()){i.getInternalMethods().setHasOutput();let c=!!i.getOptions().configuration["populate--"];if(i.getInternalMethods().postProcess(n,c,!1,!1),n=mt(n,i,o,!1),n=Dt(n,(u)=>{let f=t.handler(u);return se(f)?f.then(()=>u):u}),!e)i.getInternalMethods().getUsageInstance().cacheHelpMessage();if(se(n)&&!i.getInternalMethods().hasParseCallback())n.catch((u)=>{try{i.getInternalMethods().getUsageInstance().fail(null,u)}catch(f){}})}if(!e)r.commands.pop(),r.fullCommands.pop();return n}applyMiddlewareAndGetResult(e,t,n,r,s,i,o){let a={};if(s)return n;if(!o.getInternalMethods().getHasOutput())a=this.populatePositionals(t,n,r,o);let c=this.globalMiddleware.getMiddleware().slice(0).concat(t.middlewares),u=mt(n,o,c,!0);return se(u)?u.then((f)=>this.handleValidationAndGetResult(e,t,f,r,i,o,c,a)):this.handleValidationAndGetResult(e,t,u,r,i,o,c,a)}populatePositionals(e,t,n,r){t._=t._.slice(n.commands.length);let s=e.demanded.slice(0),i=e.optional.slice(0),o={};this.validation.positionalCount(s.length,t._.length);while(s.length){let a=s.shift();this.populatePositional(a,t,o)}while(i.length){let a=i.shift();this.populatePositional(a,t,o)}return t._=n.commands.concat(t._.map((a)=>""+a)),this.postProcessPositionals(t,o,this.cmdToParseOptions(e.original),r),o}populatePositional(e,t,n){let r=e.cmd[0];if(e.variadic)n[r]=t._.splice(0).map(String);else if(t._.length)n[r]=[String(t._.shift())]}cmdToParseOptions(e){let t={array:[],default:{},alias:{},demand:{}},n=nt(e);return n.demanded.forEach((r)=>{let[s,...i]=r.cmd;if(r.variadic)t.array.push(s),t.default[s]=[];t.alias[s]=i,t.demand[s]=!0}),n.optional.forEach((r)=>{let[s,...i]=r.cmd;if(r.variadic)t.array.push(s),t.default[s]=[];t.alias[s]=i}),t}postProcessPositionals(e,t,n,r){let s=Object.assign({},r.getOptions());s.default=Object.assign(n.default,s.default);for(let c of Object.keys(n.alias))s.alias[c]=(s.alias[c]||[]).concat(n.alias[c]);s.array=s.array.concat(n.array),s.config={};let i=[];if(Object.keys(t).forEach((c)=>{t[c].map((u)=>{if(s.configuration["unknown-options-as-args"])s.key[c]=!0;i.push(`--${c}`),i.push(u)})}),!i.length)return;let o=Object.assign({},s.configuration,{"populate--":!1}),a=this.shim.Parser.detailed(i,Object.assign({},s,{configuration:o}));if(a.error)r.getInternalMethods().getUsageInstance().fail(a.error.message,a.error);else{let c=Object.keys(t);Object.keys(t).forEach((u)=>{c.push(...a.aliases[u])}),Object.keys(a.argv).forEach((u)=>{if(c.includes(u)){if(!t[u])t[u]=a.argv[u];if(!this.isInConfigs(r,u)&&!this.isDefaulted(r,u)&&Object.prototype.hasOwnProperty.call(e,u)&&Object.prototype.hasOwnProperty.call(a.argv,u)&&(Array.isArray(e[u])||Array.isArray(a.argv[u])))e[u]=[].concat(e[u],a.argv[u]);else e[u]=a.argv[u]}})}}isDefaulted(e,t){let{default:n}=e.getOptions();return Object.prototype.hasOwnProperty.call(n,t)||Object.prototype.hasOwnProperty.call(n,this.shim.Parser.camelCase(t))}isInConfigs(e,t){let{configObjects:n}=e.getOptions();return n.some((r)=>Object.prototype.hasOwnProperty.call(r,t))||n.some((r)=>Object.prototype.hasOwnProperty.call(r,this.shim.Parser.camelCase(t)))}runDefaultBuilderOn(e){if(!this.defaultCommand)return;if(this.shouldUpdateUsage(e)){let n=Jt.test(this.defaultCommand.original)?this.defaultCommand.original:this.defaultCommand.original.replace(/^[^[\]<>]*/,"$0 ");e.getInternalMethods().getUsageInstance().usage(n,this.defaultCommand.description)}let t=this.defaultCommand.builder;if(Tn(t))return t(e,!0);else if(!no(t))Object.keys(t).forEach((n)=>{e.option(n,t[n])});return}extractDesc({describe:e,description:t,desc:n}){for(let r of[e,t,n]){if(typeof r==="string"||r===!1)return r;Ce(r,!0,this.shim)}return!1}freeze(){this.frozens.push({handlers:this.handlers,aliasMap:this.aliasMap,defaultCommand:this.defaultCommand})}unfreeze(){let e=this.frozens.pop();Ce(e,void 0,this.shim),{handlers:this.handlers,aliasMap:this.aliasMap,defaultCommand:this.defaultCommand}=e}reset(){return this.handlers={},this.aliasMap={},this.defaultCommand=void 0,this.requireCache=new Set,this}}function ro(e,t,n,r){return new so(e,t,n,r)}function no(e){return typeof e==="object"&&!!e.builder&&typeof e.handler==="function"}function Dl(e){return e.every((t)=>typeof t==="string")}function Tn(e){return typeof e==="function"}function yl(e){return typeof e==="object"}function wl(e){return typeof e==="object"&&!Array.isArray(e)}function st(e={},t=()=>!0){let n={};return Kt(e).forEach((r)=>{if(t(r,e[r]))n[r]=e[r]}),n}function rt(e){if(typeof process>"u")return;[process.stdout,process.stderr].forEach((t)=>{let n=t;if(n._handle&&n.isTTY&&typeof n._handle.setBlocking==="function")n._handle.setBlocking(e)})}function bl(e){return typeof e==="boolean"}function ao(e,t){let n=t.y18n.__,r={},s=[];r.failFn=function(E){s.push(E)};let i=null,o=null,a=!0;r.showHelpOnFail=function(E=!0,O){let[N,Q]=typeof E==="string"?[!0,E]:[E,O];if(e.getInternalMethods().isGlobalContext())o=Q;return i=Q,a=N,r};let c=!1;r.fail=function(E,O){let N=e.getInternalMethods().getLoggerInstance();if(s.length)for(let Q=s.length-1;Q>=0;--Q){let oe=s[Q];if(bl(oe)){if(O)throw O;else if(E)throw Error(E)}else oe(E,O,r)}else{if(e.getExitProcess())rt(!0);if(!c){if(c=!0,a)e.showHelp("error"),N.error();if(E||O)N.error(E||O);let Q=i||o;if(Q){if(E||O)N.error("");N.error(Q)}}if(O=O||new le(E),e.getExitProcess())return e.exit(1);else if(e.getInternalMethods().hasParseCallback())return e.exit(1,O);else throw O}};let u=[],f=!1;r.usage=(_,E)=>{if(_===null)return f=!0,u=[],r;return f=!1,u.push([_,E||""]),r},r.getUsage=()=>u,r.getUsageDisabled=()=>f,r.getPositionalGroupName=()=>n("Positionals:");let l=[];r.example=(_,E)=>{l.push([_,E||""])};let d=[];r.command=function(E,O,N,Q,oe=!1){if(N)d=d.map((V)=>(V[2]=!1,V));d.push([E,O||"",N,Q,oe])},r.getCommands=()=>d;let p={};r.describe=function(E,O){if(Array.isArray(E))E.forEach((N)=>{r.describe(N,O)});else if(typeof E==="object")Object.keys(E).forEach((N)=>{r.describe(N,E[N])});else p[E]=O},r.getDescriptions=()=>p;let m=[];r.epilog=(_)=>{m.push(_)};let g=!1,y;r.wrap=(_)=>{g=!0,y=_},r.getWrap=()=>{if(t.getEnv("YARGS_DISABLE_WRAP"))return null;if(!g)y=B(),g=!0;return y};let C="__yargsString__:";r.deferY18nLookup=(_)=>C+_,r.help=function(){if(k)return k;S();let E=e.customScriptName?e.$0:t.path.basename(e.$0),O=e.getDemandedOptions(),N=e.getDemandedCommands(),Q=e.getDeprecatedOptions(),oe=e.getGroups(),V=e.getOptions(),ae=[];ae=ae.concat(Object.keys(p)),ae=ae.concat(Object.keys(O)),ae=ae.concat(Object.keys(N)),ae=ae.concat(Object.keys(V.default)),ae=ae.filter(A),ae=Object.keys(ae.reduce((z,ne)=>{if(ne!=="_")z[ne]=!0;return z},{}));let Ie=r.getWrap(),ee=t.cliui({width:Ie,wrap:!!Ie});if(!f){if(u.length)u.forEach((z)=>{if(ee.div({text:`${z[0].replace(/\$0/g,E)}`}),z[1])ee.div({text:`${z[1]}`,padding:[1,0,0,0]})}),ee.div();else if(d.length){let z=null;if(N._)z=`${E} <${n("command")}>
15
15
  `;else z=`${E} [${n("command")}]
16
- `;ee.div(`${z}`)}}if(d.length>1||d.length===1&&!d[0][2]){ee.div(n("Commands:"));let z=e.getInternalMethods().getContext(),ne=z.commands.length?`${z.commands.join(" ")} `:"";if(e.getInternalMethods().getParserConfiguration()["sort-commands"]===!0)d=d.sort((G,ye)=>G[0].localeCompare(ye[0]));let de=E?`${E} `:"";d.forEach((G)=>{let ye=`${de}${ne}${G[0].replace(/^\$0 ?/,"")}`;ee.span({text:ye,padding:[0,2,0,2],width:F(d,Ie,`${E}${ne}`)+4},{text:G[1]});let ue=[];if(G[2])ue.push(`[${n("default")}]`);if(G[3]&&G[3].length)ue.push(`[${n("aliases:")} ${G[3].join(", ")}]`);if(G[4])if(typeof G[4]==="string")ue.push(`[${n("deprecated: %s",G[4])}]`);else ue.push(`[${n("deprecated")}]`);if(ue.length)ee.div({text:ue.join(" "),padding:[0,0,0,2],align:"right"});else ee.div()}),ee.div()}let Se=(Object.keys(V.alias)||[]).concat(Object.keys(e.parsed.newAliases)||[]);ae=ae.filter((z)=>!e.parsed.newAliases[z]&&Se.every((ne)=>(V.alias[ne]||[]).indexOf(z)===-1));let Z=n("Options:");if(!oe[Z])oe[Z]=[];L(ae,V.alias,oe,Z);let v=(z)=>/^--/.test(Pn(z)),be=Object.keys(oe).filter((z)=>oe[z].length>0).map((z)=>{let ne=oe[z].filter(A).map((de)=>{if(Se.includes(de))return de;for(let G=0,ye;(ye=Se[G])!==void 0;G++)if((V.alias[ye]||[]).includes(de))return ye;return de});return{groupName:z,normalizedKeys:ne}}).filter(({normalizedKeys:z})=>z.length>0).map(({groupName:z,normalizedKeys:ne})=>{let de=ne.reduce((G,ye)=>(G[ye]=[ye].concat(V.alias[ye]||[]).map((ue)=>{if(z===r.getPositionalGroupName())return ue;else return(/^[0-9]$/.test(ue)?V.boolean.includes(ye)?"-":"--":ue.length>1?"--":"-")+ue}).sort((ue,pe)=>v(ue)===v(pe)?0:v(ue)?1:-1).join(", "),G),{});return{groupName:z,normalizedKeys:ne,switches:de}});if(be.filter(({groupName:z})=>z!==r.getPositionalGroupName()).some(({normalizedKeys:z,switches:ne})=>!z.every((de)=>v(ne[de]))))be.filter(({groupName:z})=>z!==r.getPositionalGroupName()).forEach(({normalizedKeys:z,switches:ne})=>{z.forEach((de)=>{if(v(ne[de]))ne[de]=Dl(ne[de],4)})});if(be.forEach(({groupName:z,normalizedKeys:ne,switches:de})=>{ee.div(z),ne.forEach((G)=>{let ye=de[G],ue=p[G]||"",pe=null;if(ue.includes(C))ue=n(ue.substring(C.length));if(V.boolean.includes(G))pe=`[${n("boolean")}]`;if(V.count.includes(G))pe=`[${n("count")}]`;if(V.string.includes(G))pe=`[${n("string")}]`;if(V.normalize.includes(G))pe=`[${n("string")}]`;if(V.array.includes(G))pe=`[${n("array")}]`;if(V.number.includes(G))pe=`[${n("number")}]`;let _s=(I)=>typeof I==="string"?`[${n("deprecated: %s",I)}]`:`[${n("deprecated")}]`,D=[G in Q?_s(Q[G]):null,pe,G in O?`[${n("required")}]`:null,V.choices&&V.choices[G]?`[${n("choices:")} ${r.stringifiedValues(V.choices[G])}]`:null,R(V.default[G],V.defaultDescription[G])].filter(Boolean).join(" ");ee.span({text:Pn(ye),padding:[0,2,0,2+io(ye)],width:F(de,Ie)+4},ue);let b=e.getInternalMethods().getUsageConfiguration()["hide-types"]===!0;if(D&&!b)ee.div({text:D,padding:[0,0,0,2],align:"right"});else ee.div()}),ee.div()}),l.length)ee.div(n("Examples:")),l.forEach((z)=>{z[0]=z[0].replace(/\$0/g,E)}),l.forEach((z)=>{if(z[1]==="")ee.div({text:z[0],padding:[0,2,0,2]});else ee.div({text:z[0],padding:[0,2,0,2],width:F(l,Ie)+4},{text:z[1]})}),ee.div();if(m.length>0){let z=m.map((ne)=>ne.replace(/\$0/g,E)).join(`
16
+ `;ee.div(`${z}`)}}if(d.length>1||d.length===1&&!d[0][2]){ee.div(n("Commands:"));let z=e.getInternalMethods().getContext(),ne=z.commands.length?`${z.commands.join(" ")} `:"";if(e.getInternalMethods().getParserConfiguration()["sort-commands"]===!0)d=d.sort((G,ye)=>G[0].localeCompare(ye[0]));let de=E?`${E} `:"";d.forEach((G)=>{let ye=`${de}${ne}${G[0].replace(/^\$0 ?/,"")}`;ee.span({text:ye,padding:[0,2,0,2],width:F(d,Ie,`${E}${ne}`)+4},{text:G[1]});let ue=[];if(G[2])ue.push(`[${n("default")}]`);if(G[3]&&G[3].length)ue.push(`[${n("aliases:")} ${G[3].join(", ")}]`);if(G[4])if(typeof G[4]==="string")ue.push(`[${n("deprecated: %s",G[4])}]`);else ue.push(`[${n("deprecated")}]`);if(ue.length)ee.div({text:ue.join(" "),padding:[0,0,0,2],align:"right"});else ee.div()}),ee.div()}let ke=(Object.keys(V.alias)||[]).concat(Object.keys(e.parsed.newAliases)||[]);ae=ae.filter((z)=>!e.parsed.newAliases[z]&&ke.every((ne)=>(V.alias[ne]||[]).indexOf(z)===-1));let Z=n("Options:");if(!oe[Z])oe[Z]=[];L(ae,V.alias,oe,Z);let v=(z)=>/^--/.test(Pn(z)),be=Object.keys(oe).filter((z)=>oe[z].length>0).map((z)=>{let ne=oe[z].filter(A).map((de)=>{if(ke.includes(de))return de;for(let G=0,ye;(ye=ke[G])!==void 0;G++)if((V.alias[ye]||[]).includes(de))return ye;return de});return{groupName:z,normalizedKeys:ne}}).filter(({normalizedKeys:z})=>z.length>0).map(({groupName:z,normalizedKeys:ne})=>{let de=ne.reduce((G,ye)=>(G[ye]=[ye].concat(V.alias[ye]||[]).map((ue)=>{if(z===r.getPositionalGroupName())return ue;else return(/^[0-9]$/.test(ue)?V.boolean.includes(ye)?"-":"--":ue.length>1?"--":"-")+ue}).sort((ue,pe)=>v(ue)===v(pe)?0:v(ue)?1:-1).join(", "),G),{});return{groupName:z,normalizedKeys:ne,switches:de}});if(be.filter(({groupName:z})=>z!==r.getPositionalGroupName()).some(({normalizedKeys:z,switches:ne})=>!z.every((de)=>v(ne[de]))))be.filter(({groupName:z})=>z!==r.getPositionalGroupName()).forEach(({normalizedKeys:z,switches:ne})=>{z.forEach((de)=>{if(v(ne[de]))ne[de]=Fl(ne[de],4)})});if(be.forEach(({groupName:z,normalizedKeys:ne,switches:de})=>{ee.div(z),ne.forEach((G)=>{let ye=de[G],ue=p[G]||"",pe=null;if(ue.includes(C))ue=n(ue.substring(C.length));if(V.boolean.includes(G))pe=`[${n("boolean")}]`;if(V.count.includes(G))pe=`[${n("count")}]`;if(V.string.includes(G))pe=`[${n("string")}]`;if(V.normalize.includes(G))pe=`[${n("string")}]`;if(V.array.includes(G))pe=`[${n("array")}]`;if(V.number.includes(G))pe=`[${n("number")}]`;let As=(I)=>typeof I==="string"?`[${n("deprecated: %s",I)}]`:`[${n("deprecated")}]`,D=[G in Q?As(Q[G]):null,pe,G in O?`[${n("required")}]`:null,V.choices&&V.choices[G]?`[${n("choices:")} ${r.stringifiedValues(V.choices[G])}]`:null,R(V.default[G],V.defaultDescription[G])].filter(Boolean).join(" ");ee.span({text:Pn(ye),padding:[0,2,0,2+oo(ye)],width:F(de,Ie)+4},ue);let b=e.getInternalMethods().getUsageConfiguration()["hide-types"]===!0;if(D&&!b)ee.div({text:D,padding:[0,0,0,2],align:"right"});else ee.div()}),ee.div()}),l.length)ee.div(n("Examples:")),l.forEach((z)=>{z[0]=z[0].replace(/\$0/g,E)}),l.forEach((z)=>{if(z[1]==="")ee.div({text:z[0],padding:[0,2,0,2]});else ee.div({text:z[0],padding:[0,2,0,2],width:F(l,Ie)+4},{text:z[1]})}),ee.div();if(m.length>0){let z=m.map((ne)=>ne.replace(/\$0/g,E)).join(`
17
17
  `);ee.div(`${z}
18
- `)}return ee.toString().replace(/\s*$/,"")};function F(_,E,O){let N=0;if(!Array.isArray(_))_=Object.values(_).map((Q)=>[Q]);if(_.forEach((Q)=>{N=Math.max(t.stringWidth(O?`${O} ${Pn(Q[0])}`:Pn(Q[0]))+io(Q[0]),N)}),E)N=Math.min(N,parseInt((E*0.5).toString(),10));return N}function k(){let _=e.getDemandedOptions(),E=e.getOptions();(Object.keys(E.alias)||[]).forEach((O)=>{E.alias[O].forEach((N)=>{if(p[N])r.describe(O,p[N]);if(N in _)e.demandOption(O,_[N]);if(E.boolean.includes(N))e.boolean(O);if(E.count.includes(N))e.count(O);if(E.string.includes(N))e.string(O);if(E.normalize.includes(N))e.normalize(O);if(E.array.includes(N))e.array(O);if(E.number.includes(N))e.number(O)})})}let S;r.cacheHelpMessage=function(){S=this.help()},r.clearCachedHelpMessage=function(){S=void 0},r.hasCachedHelpMessage=function(){return!!S};function L(_,E,O,N){let Q=[],oe=null;return Object.keys(O).forEach((V)=>{Q=Q.concat(O[V])}),_.forEach((V)=>{if(oe=[V].concat(E[V]),!oe.some((ae)=>Q.indexOf(ae)!==-1))O[N].push(V)}),Q}function A(_){return e.getOptions().hiddenOptions.indexOf(_)<0||e.parsed.argv[e.getOptions().showHiddenOpt]}r.showHelp=(_)=>{let E=e.getInternalMethods().getLoggerInstance();if(!_)_="error";(typeof _==="function"?_:E[_])(r.help())},r.functionDescription=(_)=>["(",_.name?t.Parser.decamelize(_.name,"-"):n("generated-value"),")"].join(""),r.stringifiedValues=function(E,O){let N="",Q=O||", ",oe=[].concat(E);if(!E||!oe.length)return N;return oe.forEach((V)=>{if(N.length)N+=Q;N+=JSON.stringify(V)}),N};function R(_,E){let O=`[${n("default:")} `;if(_===void 0&&!E)return null;if(E)O+=E;else switch(typeof _){case"string":O+=`"${_}"`;break;case"object":O+=JSON.stringify(_);break;default:O+=_}return`${O}]`}function B(){if(t.process.stdColumns)return Math.min(80,t.process.stdColumns);else return 80}let P=null;r.version=(_)=>{P=_},r.showVersion=(_)=>{let E=e.getInternalMethods().getLoggerInstance();if(!_)_="error";(typeof _==="function"?_:E[_])(P)},r.reset=function(E){return i=null,c=!1,u=[],f=!1,m=[],l=[],d=[],p=st(p,(O)=>!E[O]),r};let q=[];return r.freeze=function(){q.push({failMessage:i,failureOutput:c,usages:u,usageDisabled:f,epilogs:m,examples:l,commands:d,descriptions:p})},r.unfreeze=function(E=!1){let O=q.pop();if(!O)return;if(E)p={...O.descriptions,...p},d=[...O.commands,...d],u=[...O.usages,...u],l=[...O.examples,...l],m=[...O.epilogs,...m];else({failMessage:i,failureOutput:c,usages:u,usageDisabled:f,epilogs:m,examples:l,commands:d,descriptions:p}=O)},r}function Js(e){return typeof e==="object"}function Dl(e,t){return Js(e)?{text:e.text,indentation:e.indentation+t}:{text:e,indentation:t}}function io(e){return Js(e)?e.indentation:0}function Pn(e){return Js(e)?e.text:e}var ao=`###-begin-{{app_name}}-completions-###
18
+ `)}return ee.toString().replace(/\s*$/,"")};function F(_,E,O){let N=0;if(!Array.isArray(_))_=Object.values(_).map((Q)=>[Q]);if(_.forEach((Q)=>{N=Math.max(t.stringWidth(O?`${O} ${Pn(Q[0])}`:Pn(Q[0]))+oo(Q[0]),N)}),E)N=Math.min(N,parseInt((E*0.5).toString(),10));return N}function S(){let _=e.getDemandedOptions(),E=e.getOptions();(Object.keys(E.alias)||[]).forEach((O)=>{E.alias[O].forEach((N)=>{if(p[N])r.describe(O,p[N]);if(N in _)e.demandOption(O,_[N]);if(E.boolean.includes(N))e.boolean(O);if(E.count.includes(N))e.count(O);if(E.string.includes(N))e.string(O);if(E.normalize.includes(N))e.normalize(O);if(E.array.includes(N))e.array(O);if(E.number.includes(N))e.number(O)})})}let k;r.cacheHelpMessage=function(){k=this.help()},r.clearCachedHelpMessage=function(){k=void 0},r.hasCachedHelpMessage=function(){return!!k};function L(_,E,O,N){let Q=[],oe=null;return Object.keys(O).forEach((V)=>{Q=Q.concat(O[V])}),_.forEach((V)=>{if(oe=[V].concat(E[V]),!oe.some((ae)=>Q.indexOf(ae)!==-1))O[N].push(V)}),Q}function A(_){return e.getOptions().hiddenOptions.indexOf(_)<0||e.parsed.argv[e.getOptions().showHiddenOpt]}r.showHelp=(_)=>{let E=e.getInternalMethods().getLoggerInstance();if(!_)_="error";(typeof _==="function"?_:E[_])(r.help())},r.functionDescription=(_)=>["(",_.name?t.Parser.decamelize(_.name,"-"):n("generated-value"),")"].join(""),r.stringifiedValues=function(E,O){let N="",Q=O||", ",oe=[].concat(E);if(!E||!oe.length)return N;return oe.forEach((V)=>{if(N.length)N+=Q;N+=JSON.stringify(V)}),N};function R(_,E){let O=`[${n("default:")} `;if(_===void 0&&!E)return null;if(E)O+=E;else switch(typeof _){case"string":O+=`"${_}"`;break;case"object":O+=JSON.stringify(_);break;default:O+=_}return`${O}]`}function B(){if(t.process.stdColumns)return Math.min(80,t.process.stdColumns);else return 80}let P=null;r.version=(_)=>{P=_},r.showVersion=(_)=>{let E=e.getInternalMethods().getLoggerInstance();if(!_)_="error";(typeof _==="function"?_:E[_])(P)},r.reset=function(E){return i=null,c=!1,u=[],f=!1,m=[],l=[],d=[],p=st(p,(O)=>!E[O]),r};let q=[];return r.freeze=function(){q.push({failMessage:i,failureOutput:c,usages:u,usageDisabled:f,epilogs:m,examples:l,commands:d,descriptions:p})},r.unfreeze=function(E=!1){let O=q.pop();if(!O)return;if(E)p={...O.descriptions,...p},d=[...O.commands,...d],u=[...O.usages,...u],l=[...O.examples,...l],m=[...O.epilogs,...m];else({failMessage:i,failureOutput:c,usages:u,usageDisabled:f,epilogs:m,examples:l,commands:d,descriptions:p}=O)},r}function qs(e){return typeof e==="object"}function Fl(e,t){return qs(e)?{text:e.text,indentation:e.indentation+t}:{text:e,indentation:t}}function oo(e){return qs(e)?e.indentation:0}function Pn(e){return qs(e)?e.text:e}var co=`###-begin-{{app_name}}-completions-###
19
19
  #
20
20
  # yargs command completion script
21
21
  #
@@ -44,7 +44,7 @@ _{{app_name}}_yargs_completions()
44
44
  }
45
45
  complete -o bashdefault -o default -F _{{app_name}}_yargs_completions {{app_name}}
46
46
  ###-end-{{app_name}}-completions-###
47
- `,co=`#compdef {{app_name}}
47
+ `,uo=`#compdef {{app_name}}
48
48
  ###-begin-{{app_name}}-completions-###
49
49
  #
50
50
  # yargs command completion script
@@ -71,156 +71,162 @@ else
71
71
  compdef _{{app_name}}_yargs_completions {{app_name}}
72
72
  fi
73
73
  ###-end-{{app_name}}-completions-###
74
- `;class uo{constructor(e,t,n,r){var s,i,o;this.yargs=e,this.usage=t,this.command=n,this.shim=r,this.completionKey="get-yargs-completions",this.aliases=null,this.customCompletionFunction=null,this.indexAfterLastReset=0,this.zshShell=(o=((s=this.shim.getEnv("SHELL"))===null||s===void 0?void 0:s.includes("zsh"))||((i=this.shim.getEnv("ZSH_NAME"))===null||i===void 0?void 0:i.includes("zsh")))!==null&&o!==void 0?o:!1}defaultCompletion(e,t,n,r){let s=this.command.getCommandHandlers();for(let o=0,a=e.length;o<a;++o)if(s[e[o]]&&s[e[o]].builder){let c=s[e[o]].builder;if(Tn(c)){this.indexAfterLastReset=o+1;let u=this.yargs.getInternalMethods().reset();return c(u,!0),u.argv}}let i=[];this.commandCompletions(i,e,n),this.optionCompletions(i,e,t,n),this.choicesFromOptionsCompletions(i,e,t,n),this.choicesFromPositionalsCompletions(i,e,t,n),r(null,i)}commandCompletions(e,t,n){let r=this.yargs.getInternalMethods().getContext().commands;if(!n.match(/^-/)&&r[r.length-1]!==n&&!this.previousArgHasChoices(t))this.usage.getCommands().forEach((s)=>{let i=nt(s[0]).cmd;if(t.indexOf(i)===-1)if(!this.zshShell)e.push(i);else{let o=s[1]||"";e.push(i.replace(/:/g,"\\:")+":"+o)}})}optionCompletions(e,t,n,r){if((r.match(/^-/)||r===""&&e.length===0)&&!this.previousArgHasChoices(t)){let s=this.yargs.getOptions(),i=this.yargs.getGroups()[this.usage.getPositionalGroupName()]||[];Object.keys(s.key).forEach((o)=>{let a=!!s.configuration["boolean-negation"]&&s.boolean.includes(o);if(!i.includes(o)&&!s.hiddenOptions.includes(o)&&!this.argsContainKey(t,o,a))this.completeOptionKey(o,e,r,a&&!!s.default[o])})}}choicesFromOptionsCompletions(e,t,n,r){if(this.previousArgHasChoices(t)){let s=this.getPreviousArgChoices(t);if(s&&s.length>0)e.push(...s.map((i)=>i.replace(/:/g,"\\:")))}}choicesFromPositionalsCompletions(e,t,n,r){if(r===""&&e.length>0&&this.previousArgHasChoices(t))return;let s=this.yargs.getGroups()[this.usage.getPositionalGroupName()]||[],i=Math.max(this.indexAfterLastReset,this.yargs.getInternalMethods().getContext().commands.length+1),o=s[n._.length-i-1];if(!o)return;let a=this.yargs.getOptions().choices[o]||[];for(let c of a)if(c.startsWith(r))e.push(c.replace(/:/g,"\\:"))}getPreviousArgChoices(e){if(e.length<1)return;let t=e[e.length-1],n="";if(!t.startsWith("-")&&e.length>1)n=t,t=e[e.length-2];if(!t.startsWith("-"))return;let r=t.replace(/^-+/,""),s=this.yargs.getOptions(),i=[r,...this.yargs.getAliases()[r]||[]],o;for(let a of i)if(Object.prototype.hasOwnProperty.call(s.key,a)&&Array.isArray(s.choices[a])){o=s.choices[a];break}if(o)return o.filter((a)=>!n||a.startsWith(n))}previousArgHasChoices(e){let t=this.getPreviousArgChoices(e);return t!==void 0&&t.length>0}argsContainKey(e,t,n){let r=(s)=>e.indexOf((/^[^0-9]$/.test(s)?"-":"--")+s)!==-1;if(r(t))return!0;if(n&&r(`no-${t}`))return!0;if(this.aliases){for(let s of this.aliases[t])if(r(s))return!0}return!1}completeOptionKey(e,t,n,r){var s,i,o,a;let c=e;if(this.zshShell){let d=this.usage.getDescriptions(),p=(i=(s=this===null||this===void 0?void 0:this.aliases)===null||s===void 0?void 0:s[e])===null||i===void 0?void 0:i.find((y)=>{let C=d[y];return typeof C==="string"&&C.length>0}),m=p?d[p]:void 0,g=(a=(o=d[e])!==null&&o!==void 0?o:m)!==null&&a!==void 0?a:"";c=`${e.replace(/:/g,"\\:")}:${g.replace("__yargsString__:","").replace(/(\r\n|\n|\r)/gm," ")}`}let u=(d)=>/^--/.test(d),f=(d)=>/^[^0-9]$/.test(d),l=!u(n)&&f(e)?"-":"--";if(t.push(l+c),r)t.push(l+"no-"+c)}customCompletion(e,t,n,r){if(Ce(this.customCompletionFunction,null,this.shim),wl(this.customCompletionFunction)){let s=this.customCompletionFunction(n,t);if(se(s))return s.then((i)=>{this.shim.process.nextTick(()=>{r(null,i)})}).catch((i)=>{this.shim.process.nextTick(()=>{r(i,void 0)})});return r(null,s)}else if(bl(this.customCompletionFunction))return this.customCompletionFunction(n,t,(s=r)=>this.defaultCompletion(e,t,n,s),(s)=>{r(null,s)});else return this.customCompletionFunction(n,t,(s)=>{r(null,s)})}getCompletion(e,t){let n=e.length?e[e.length-1]:"",r=this.yargs.parse(e,!0),s=this.customCompletionFunction?(i)=>this.customCompletion(e,i,n,t):(i)=>this.defaultCompletion(e,i,n,t);return se(r)?r.then(s):s(r)}generateCompletionScript(e,t){let n=this.zshShell?co:ao,r=this.shim.path.basename(e);if(e.match(/\.js$/))e=`./${e}`;return n=n.replace(/{{app_name}}/g,r),n=n.replace(/{{completion_command}}/g,t),n.replace(/{{app_path}}/g,e)}registerFunction(e){this.customCompletionFunction=e}setParsed(e){this.aliases=e.aliases}}function lo(e,t,n,r){return new uo(e,t,n,r)}function wl(e){return e.length<3}function bl(e){return e.length>3}function fo(e,t){if(e.length===0)return t.length;if(t.length===0)return e.length;let n=[],r;for(r=0;r<=t.length;r++)n[r]=[r];let s;for(s=0;s<=e.length;s++)n[0][s]=s;for(r=1;r<=t.length;r++)for(s=1;s<=e.length;s++)if(t.charAt(r-1)===e.charAt(s-1))n[r][s]=n[r-1][s-1];else if(r>1&&s>1&&t.charAt(r-2)===e.charAt(s-1)&&t.charAt(r-1)===e.charAt(s-2))n[r][s]=n[r-2][s-2]+1;else n[r][s]=Math.min(n[r-1][s-1]+1,Math.min(n[r][s-1]+1,n[r-1][s]+1));return n[t.length][e.length]}var po=["$0","--","_"];function ho(e,t,n){let r=n.y18n.__,s=n.y18n.__n,i={};i.nonOptionCount=function(l){let d=e.getDemandedCommands(),m=l._.length+(l["--"]?l["--"].length:0)-e.getInternalMethods().getContext().commands.length;if(d._&&(m<d._.min||m>d._.max)){if(m<d._.min)if(d._.minMsg!==void 0)t.fail(d._.minMsg?d._.minMsg.replace(/\$0/g,m.toString()).replace(/\$1/,d._.min.toString()):null);else t.fail(s("Not enough non-option arguments: got %s, need at least %s","Not enough non-option arguments: got %s, need at least %s",m,m.toString(),d._.min.toString()));else if(m>d._.max)if(d._.maxMsg!==void 0)t.fail(d._.maxMsg?d._.maxMsg.replace(/\$0/g,m.toString()).replace(/\$1/,d._.max.toString()):null);else t.fail(s("Too many non-option arguments: got %s, maximum of %s","Too many non-option arguments: got %s, maximum of %s",m,m.toString(),d._.max.toString()))}},i.positionalCount=function(l,d){if(d<l)t.fail(s("Not enough non-option arguments: got %s, need at least %s","Not enough non-option arguments: got %s, need at least %s",d,d+"",l+""))},i.requiredArguments=function(l,d){let p=null;for(let m of Object.keys(d))if(!Object.prototype.hasOwnProperty.call(l,m)||typeof l[m]>"u")p=p||{},p[m]=d[m];if(p){let m=[];for(let y of Object.keys(p)){let C=p[y];if(C&&m.indexOf(C)<0)m.push(C)}let g=m.length?`
74
+ `;class lo{constructor(e,t,n,r){var s,i,o;this.yargs=e,this.usage=t,this.command=n,this.shim=r,this.completionKey="get-yargs-completions",this.aliases=null,this.customCompletionFunction=null,this.indexAfterLastReset=0,this.zshShell=(o=((s=this.shim.getEnv("SHELL"))===null||s===void 0?void 0:s.includes("zsh"))||((i=this.shim.getEnv("ZSH_NAME"))===null||i===void 0?void 0:i.includes("zsh")))!==null&&o!==void 0?o:!1}defaultCompletion(e,t,n,r){let s=this.command.getCommandHandlers();for(let o=0,a=e.length;o<a;++o)if(s[e[o]]&&s[e[o]].builder){let c=s[e[o]].builder;if(Tn(c)){this.indexAfterLastReset=o+1;let u=this.yargs.getInternalMethods().reset();return c(u,!0),u.argv}}let i=[];this.commandCompletions(i,e,n),this.optionCompletions(i,e,t,n),this.choicesFromOptionsCompletions(i,e,t,n),this.choicesFromPositionalsCompletions(i,e,t,n),r(null,i)}commandCompletions(e,t,n){let r=this.yargs.getInternalMethods().getContext().commands;if(!n.match(/^-/)&&r[r.length-1]!==n&&!this.previousArgHasChoices(t))this.usage.getCommands().forEach((s)=>{let i=nt(s[0]).cmd;if(t.indexOf(i)===-1)if(!this.zshShell)e.push(i);else{let o=s[1]||"";e.push(i.replace(/:/g,"\\:")+":"+o)}})}optionCompletions(e,t,n,r){if((r.match(/^-/)||r===""&&e.length===0)&&!this.previousArgHasChoices(t)){let s=this.yargs.getOptions(),i=this.yargs.getGroups()[this.usage.getPositionalGroupName()]||[];Object.keys(s.key).forEach((o)=>{let a=!!s.configuration["boolean-negation"]&&s.boolean.includes(o);if(!i.includes(o)&&!s.hiddenOptions.includes(o)&&!this.argsContainKey(t,o,a))this.completeOptionKey(o,e,r,a&&!!s.default[o])})}}choicesFromOptionsCompletions(e,t,n,r){if(this.previousArgHasChoices(t)){let s=this.getPreviousArgChoices(t);if(s&&s.length>0)e.push(...s.map((i)=>i.replace(/:/g,"\\:")))}}choicesFromPositionalsCompletions(e,t,n,r){if(r===""&&e.length>0&&this.previousArgHasChoices(t))return;let s=this.yargs.getGroups()[this.usage.getPositionalGroupName()]||[],i=Math.max(this.indexAfterLastReset,this.yargs.getInternalMethods().getContext().commands.length+1),o=s[n._.length-i-1];if(!o)return;let a=this.yargs.getOptions().choices[o]||[];for(let c of a)if(c.startsWith(r))e.push(c.replace(/:/g,"\\:"))}getPreviousArgChoices(e){if(e.length<1)return;let t=e[e.length-1],n="";if(!t.startsWith("-")&&e.length>1)n=t,t=e[e.length-2];if(!t.startsWith("-"))return;let r=t.replace(/^-+/,""),s=this.yargs.getOptions(),i=[r,...this.yargs.getAliases()[r]||[]],o;for(let a of i)if(Object.prototype.hasOwnProperty.call(s.key,a)&&Array.isArray(s.choices[a])){o=s.choices[a];break}if(o)return o.filter((a)=>!n||a.startsWith(n))}previousArgHasChoices(e){let t=this.getPreviousArgChoices(e);return t!==void 0&&t.length>0}argsContainKey(e,t,n){let r=(s)=>e.indexOf((/^[^0-9]$/.test(s)?"-":"--")+s)!==-1;if(r(t))return!0;if(n&&r(`no-${t}`))return!0;if(this.aliases){for(let s of this.aliases[t])if(r(s))return!0}return!1}completeOptionKey(e,t,n,r){var s,i,o,a;let c=e;if(this.zshShell){let d=this.usage.getDescriptions(),p=(i=(s=this===null||this===void 0?void 0:this.aliases)===null||s===void 0?void 0:s[e])===null||i===void 0?void 0:i.find((y)=>{let C=d[y];return typeof C==="string"&&C.length>0}),m=p?d[p]:void 0,g=(a=(o=d[e])!==null&&o!==void 0?o:m)!==null&&a!==void 0?a:"";c=`${e.replace(/:/g,"\\:")}:${g.replace("__yargsString__:","").replace(/(\r\n|\n|\r)/gm," ")}`}let u=(d)=>/^--/.test(d),f=(d)=>/^[^0-9]$/.test(d),l=!u(n)&&f(e)?"-":"--";if(t.push(l+c),r)t.push(l+"no-"+c)}customCompletion(e,t,n,r){if(Ce(this.customCompletionFunction,null,this.shim),El(this.customCompletionFunction)){let s=this.customCompletionFunction(n,t);if(se(s))return s.then((i)=>{this.shim.process.nextTick(()=>{r(null,i)})}).catch((i)=>{this.shim.process.nextTick(()=>{r(i,void 0)})});return r(null,s)}else if(xl(this.customCompletionFunction))return this.customCompletionFunction(n,t,(s=r)=>this.defaultCompletion(e,t,n,s),(s)=>{r(null,s)});else return this.customCompletionFunction(n,t,(s)=>{r(null,s)})}getCompletion(e,t){let n=e.length?e[e.length-1]:"",r=this.yargs.parse(e,!0),s=this.customCompletionFunction?(i)=>this.customCompletion(e,i,n,t):(i)=>this.defaultCompletion(e,i,n,t);return se(r)?r.then(s):s(r)}generateCompletionScript(e,t){let n=this.zshShell?uo:co,r=this.shim.path.basename(e);if(e.match(/\.js$/))e=`./${e}`;return n=n.replace(/{{app_name}}/g,r),n=n.replace(/{{completion_command}}/g,t),n.replace(/{{app_path}}/g,e)}registerFunction(e){this.customCompletionFunction=e}setParsed(e){this.aliases=e.aliases}}function fo(e,t,n,r){return new lo(e,t,n,r)}function El(e){return e.length<3}function xl(e){return e.length>3}function po(e,t){if(e.length===0)return t.length;if(t.length===0)return e.length;let n=[],r;for(r=0;r<=t.length;r++)n[r]=[r];let s;for(s=0;s<=e.length;s++)n[0][s]=s;for(r=1;r<=t.length;r++)for(s=1;s<=e.length;s++)if(t.charAt(r-1)===e.charAt(s-1))n[r][s]=n[r-1][s-1];else if(r>1&&s>1&&t.charAt(r-2)===e.charAt(s-1)&&t.charAt(r-1)===e.charAt(s-2))n[r][s]=n[r-2][s-2]+1;else n[r][s]=Math.min(n[r-1][s-1]+1,Math.min(n[r][s-1]+1,n[r-1][s]+1));return n[t.length][e.length]}var ho=["$0","--","_"];function go(e,t,n){let r=n.y18n.__,s=n.y18n.__n,i={};i.nonOptionCount=function(l){let d=e.getDemandedCommands(),m=l._.length+(l["--"]?l["--"].length:0)-e.getInternalMethods().getContext().commands.length;if(d._&&(m<d._.min||m>d._.max)){if(m<d._.min)if(d._.minMsg!==void 0)t.fail(d._.minMsg?d._.minMsg.replace(/\$0/g,m.toString()).replace(/\$1/,d._.min.toString()):null);else t.fail(s("Not enough non-option arguments: got %s, need at least %s","Not enough non-option arguments: got %s, need at least %s",m,m.toString(),d._.min.toString()));else if(m>d._.max)if(d._.maxMsg!==void 0)t.fail(d._.maxMsg?d._.maxMsg.replace(/\$0/g,m.toString()).replace(/\$1/,d._.max.toString()):null);else t.fail(s("Too many non-option arguments: got %s, maximum of %s","Too many non-option arguments: got %s, maximum of %s",m,m.toString(),d._.max.toString()))}},i.positionalCount=function(l,d){if(d<l)t.fail(s("Not enough non-option arguments: got %s, need at least %s","Not enough non-option arguments: got %s, need at least %s",d,d+"",l+""))},i.requiredArguments=function(l,d){let p=null;for(let m of Object.keys(d))if(!Object.prototype.hasOwnProperty.call(l,m)||typeof l[m]>"u")p=p||{},p[m]=d[m];if(p){let m=[];for(let y of Object.keys(p)){let C=p[y];if(C&&m.indexOf(C)<0)m.push(C)}let g=m.length?`
75
75
  ${m.join(`
76
- `)}`:"";t.fail(s("Missing required argument: %s","Missing required arguments: %s",Object.keys(p).length,Object.keys(p).join(", ")+g))}},i.unknownArguments=function(l,d,p,m,g=!0){var y;let C=e.getInternalMethods().getCommandInstance().getCommands(),F=[],k=e.getInternalMethods().getContext();if(Object.keys(l).forEach((S)=>{if(!po.includes(S)&&!Object.prototype.hasOwnProperty.call(p,S)&&!Object.prototype.hasOwnProperty.call(e.getInternalMethods().getParseContext(),S)&&!i.isValidAndSomeAliasIsNotNew(S,d))F.push(S)}),g&&(k.commands.length>0||C.length>0||m))l._.slice(k.commands.length).forEach((S)=>{if(!C.includes(""+S))F.push(""+S)});if(g){let L=((y=e.getDemandedCommands()._)===null||y===void 0?void 0:y.max)||0,A=k.commands.length+L;if(A<l._.length)l._.slice(A).forEach((R)=>{if(R=String(R),!k.commands.includes(R)&&!F.includes(R))F.push(R)})}if(F.length)t.fail(s("Unknown argument: %s","Unknown arguments: %s",F.length,F.map((S)=>S.trim()?S:`"${S}"`).join(", ")))},i.unknownCommands=function(l){let d=e.getInternalMethods().getCommandInstance().getCommands(),p=[],m=e.getInternalMethods().getContext();if(m.commands.length>0||d.length>0)l._.slice(m.commands.length).forEach((g)=>{if(!d.includes(""+g))p.push(""+g)});if(p.length>0)return t.fail(s("Unknown command: %s","Unknown commands: %s",p.length,p.join(", "))),!0;else return!1},i.isValidAndSomeAliasIsNotNew=function(l,d){if(!Object.prototype.hasOwnProperty.call(d,l))return!1;let p=e.parsed.newAliases;return[l,...d[l]].some((m)=>!Object.prototype.hasOwnProperty.call(p,m)||!p[l])},i.limitedChoices=function(l){let d=e.getOptions(),p={};if(!Object.keys(d.choices).length)return;Object.keys(l).forEach((y)=>{if(po.indexOf(y)===-1&&Object.prototype.hasOwnProperty.call(d.choices,y))[].concat(l[y]).forEach((C)=>{if(d.choices[y].indexOf(C)===-1&&C!==void 0)p[y]=(p[y]||[]).concat(C)})});let m=Object.keys(p);if(!m.length)return;let g=r("Invalid values:");m.forEach((y)=>{g+=`
76
+ `)}`:"";t.fail(s("Missing required argument: %s","Missing required arguments: %s",Object.keys(p).length,Object.keys(p).join(", ")+g))}},i.unknownArguments=function(l,d,p,m,g=!0){var y;let C=e.getInternalMethods().getCommandInstance().getCommands(),F=[],S=e.getInternalMethods().getContext();if(Object.keys(l).forEach((k)=>{if(!ho.includes(k)&&!Object.prototype.hasOwnProperty.call(p,k)&&!Object.prototype.hasOwnProperty.call(e.getInternalMethods().getParseContext(),k)&&!i.isValidAndSomeAliasIsNotNew(k,d))F.push(k)}),g&&(S.commands.length>0||C.length>0||m))l._.slice(S.commands.length).forEach((k)=>{if(!C.includes(""+k))F.push(""+k)});if(g){let L=((y=e.getDemandedCommands()._)===null||y===void 0?void 0:y.max)||0,A=S.commands.length+L;if(A<l._.length)l._.slice(A).forEach((R)=>{if(R=String(R),!S.commands.includes(R)&&!F.includes(R))F.push(R)})}if(F.length)t.fail(s("Unknown argument: %s","Unknown arguments: %s",F.length,F.map((k)=>k.trim()?k:`"${k}"`).join(", ")))},i.unknownCommands=function(l){let d=e.getInternalMethods().getCommandInstance().getCommands(),p=[],m=e.getInternalMethods().getContext();if(m.commands.length>0||d.length>0)l._.slice(m.commands.length).forEach((g)=>{if(!d.includes(""+g))p.push(""+g)});if(p.length>0)return t.fail(s("Unknown command: %s","Unknown commands: %s",p.length,p.join(", "))),!0;else return!1},i.isValidAndSomeAliasIsNotNew=function(l,d){if(!Object.prototype.hasOwnProperty.call(d,l))return!1;let p=e.parsed.newAliases;return[l,...d[l]].some((m)=>!Object.prototype.hasOwnProperty.call(p,m)||!p[l])},i.limitedChoices=function(l){let d=e.getOptions(),p={};if(!Object.keys(d.choices).length)return;Object.keys(l).forEach((y)=>{if(ho.indexOf(y)===-1&&Object.prototype.hasOwnProperty.call(d.choices,y))[].concat(l[y]).forEach((C)=>{if(d.choices[y].indexOf(C)===-1&&C!==void 0)p[y]=(p[y]||[]).concat(C)})});let m=Object.keys(p);if(!m.length)return;let g=r("Invalid values:");m.forEach((y)=>{g+=`
77
77
  ${r("Argument: %s, Given: %s, Choices: %s",y,t.stringifiedValues(p[y]),t.stringifiedValues(d.choices[y]))}`}),t.fail(g)};let o={};i.implies=function(l,d){if(j("<string|object> [array|number|string]",[l,d],arguments.length),typeof l==="object")Object.keys(l).forEach((p)=>{i.implies(p,l[p])});else{if(e.global(l),!o[l])o[l]=[];if(Array.isArray(d))d.forEach((p)=>i.implies(l,p));else Ce(d,void 0,n),o[l].push(d)}},i.getImplied=function(){return o};function a(f,l){let d=Number(l);if(l=isNaN(d)?l:d,typeof l==="number")l=f._.length>=l;else if(l.match(/^--no-.+/))l=l.match(/^--no-(.+)/)[1],l=!Object.prototype.hasOwnProperty.call(f,l);else l=Object.prototype.hasOwnProperty.call(f,l);return l}i.implications=function(l){let d=[];if(Object.keys(o).forEach((p)=>{let m=p;(o[p]||[]).forEach((g)=>{let y=m,C=g;if(y=a(l,y),g=a(l,g),y&&!g)d.push(` ${m} -> ${C}`)})}),d.length){let p=`${r("Implications failed:")}
78
- `;d.forEach((m)=>{p+=m}),t.fail(p)}};let c={};i.conflicts=function(l,d){if(j("<string|object> [array|string]",[l,d],arguments.length),typeof l==="object")Object.keys(l).forEach((p)=>{i.conflicts(p,l[p])});else{if(e.global(l),!c[l])c[l]=[];if(Array.isArray(d))d.forEach((p)=>i.conflicts(l,p));else c[l].push(d)}},i.getConflicting=()=>c,i.conflicting=function(l){if(Object.keys(l).forEach((d)=>{if(c[d])c[d].forEach((p)=>{if(p&&l[d]!==void 0&&l[p]!==void 0)t.fail(r("Arguments %s and %s are mutually exclusive",d,p))})}),e.getInternalMethods().getParserConfiguration()["strip-dashed"])Object.keys(c).forEach((d)=>{c[d].forEach((p)=>{if(p&&l[n.Parser.camelCase(d)]!==void 0&&l[n.Parser.camelCase(p)]!==void 0)t.fail(r("Arguments %s and %s are mutually exclusive",d,p))})})},i.recommendCommands=function(l,d){d=d.sort((y,C)=>C.length-y.length);let m=null,g=1/0;for(let y=0,C;(C=d[y])!==void 0;y++){let F=fo(l,C);if(F<=3&&F<g)g=F,m=C}if(m)t.fail(r("Did you mean %s?",m))},i.reset=function(l){return o=st(o,(d)=>!l[d]),c=st(c,(d)=>!l[d]),i};let u=[];return i.freeze=function(){u.push({implied:o,conflicting:c})},i.unfreeze=function(){let l=u.pop();Ce(l,void 0,n),{implied:o,conflicting:c}=l},i}var zs=[],nn;function sn(e,t,n,r){nn=r;let s={};if(Object.prototype.hasOwnProperty.call(e,"extends")){if(typeof e.extends!=="string")return s;let i=/\.json|\..*rc$/.test(e.extends),o=null;if(!i)try{o=import.meta.resolve(e.extends)}catch(a){return e}else o=Cl(t,e.extends);Fl(o),zs.push(o),s=i?JSON.parse(nn.readFileSync(o,"utf8")):r.require(e.extends),delete e.extends,s=sn(s,nn.path.dirname(o),n,nn)}return zs=[],n?go(s,e):Object.assign({},s,e)}function Fl(e){if(zs.indexOf(e)>-1)throw new le(`Circular extended configurations: '${e}'.`)}function Cl(e,t){return nn.path.resolve(e,t)}function go(e,t){let n={};function r(s){return s&&typeof s==="object"&&!Array.isArray(s)}Object.assign(n,e);for(let s of Object.keys(t))if(r(t[s])&&r(n[s]))n[s]=go(e[s],t[s]);else n[s]=t[s];return n}var W=function(e,t,n,r,s){if(r==="m")throw TypeError("Private method is not writable");if(r==="a"&&!s)throw TypeError("Private accessor was defined without a setter");if(typeof t==="function"?e!==t||!s:!t.has(e))throw TypeError("Cannot write private member to an object whose class did not declare it");return r==="a"?s.call(e,n):s?s.value=n:t.set(e,n),n},h=function(e,t,n,r){if(n==="a"&&!r)throw TypeError("Private accessor was defined without a getter");if(typeof t==="function"?e!==t||!r:!t.has(e))throw TypeError("Cannot read private member from an object whose class did not declare it");return n==="m"?r:n==="a"?r.call(e):r?r.value:t.get(e)},fe,mt,rn,xe,Ae,Rn,it,Dt,Mn,Pe,Bn,Re,Ge,$e,Me,Nn,yt,me,K,vn,jn,Oe,wt,Kt,bt,ot,Ln,H,Ft,Ct,Et,Y,Wn,Ve,ce;function Mo(e){return(t=[],n=e.process.cwd(),r)=>{let s=new Bo(t,n,r,e);return Object.defineProperty(s,"argv",{get:()=>s.parse(),enumerable:!0}),s.help(),s.version(),s}}var mo=Symbol("copyDoubleDash"),Do=Symbol("copyDoubleDash"),Hs=Symbol("deleteFromParserHintObject"),yo=Symbol("emitWarning"),wo=Symbol("freeze"),bo=Symbol("getDollarZero"),xt=Symbol("getParserConfiguration"),Fo=Symbol("getUsageConfiguration"),qs=Symbol("guessLocale"),Co=Symbol("guessVersion"),Eo=Symbol("parsePositionalNumbers"),Ys=Symbol("pkgUp"),at=Symbol("populateParserHintArray"),Jt=Symbol("populateParserHintSingleValueDictionary"),Xs=Symbol("populateParserHintArrayDictionary"),Gs=Symbol("populateParserHintDictionary"),Vs=Symbol("sanitizeKey"),Zs=Symbol("setKey"),Qs=Symbol("unfreeze"),xo=Symbol("validateAsync"),_o=Symbol("getCommandInstance"),So=Symbol("getContext"),ko=Symbol("getHasOutput"),Ao=Symbol("getLoggerInstance"),$o=Symbol("getParseContext"),Oo=Symbol("getUsageInstance"),Io=Symbol("getValidationInstance"),Un=Symbol("hasParseCallback"),To=Symbol("isGlobalContext"),_t=Symbol("postProcess"),Po=Symbol("rebase"),er=Symbol("reset"),on=Symbol("runYargsParserAndExecuteCommands"),tr=Symbol("runValidation"),Ro=Symbol("setHasOutput"),St=Symbol("kTrackManuallySetKeys"),El="en_US";class Bo{constructor(e=[],t,n,r){this.customScriptName=!1,this.parsed=!1,fe.set(this,void 0),mt.set(this,void 0),rn.set(this,{commands:[],fullCommands:[]}),xe.set(this,null),Ae.set(this,null),Rn.set(this,"show-hidden"),it.set(this,null),Dt.set(this,!0),Mn.set(this,{}),Pe.set(this,!0),Bn.set(this,[]),Re.set(this,void 0),Ge.set(this,{}),$e.set(this,!1),Me.set(this,null),Nn.set(this,!0),yt.set(this,void 0),me.set(this,""),K.set(this,void 0),vn.set(this,void 0),jn.set(this,{}),Oe.set(this,null),wt.set(this,null),Kt.set(this,{}),bt.set(this,{}),ot.set(this,void 0),Ln.set(this,!1),H.set(this,void 0),Ft.set(this,!1),Ct.set(this,!1),Et.set(this,!1),Y.set(this,void 0),Wn.set(this,{}),Ve.set(this,null),ce.set(this,void 0),W(this,H,r,"f"),W(this,ot,e,"f"),W(this,mt,t,"f"),W(this,vn,n,"f"),W(this,Re,new Ks(this),"f"),this.$0=this[bo](),this[er](),W(this,fe,h(this,fe,"f"),"f"),W(this,Y,h(this,Y,"f"),"f"),W(this,ce,h(this,ce,"f"),"f"),W(this,K,h(this,K,"f"),"f"),h(this,K,"f").showHiddenOpt=h(this,Rn,"f"),W(this,yt,this[Do](),"f"),h(this,H,"f").y18n.setLocale(El)}addHelpOpt(e,t){if(j("[string|boolean] [string]",[e,t],arguments.length),h(this,Me,"f"))this[Hs](h(this,Me,"f")),W(this,Me,null,"f");if(e===!1&&t===void 0)return this;return W(this,Me,typeof e==="string"?e:"help","f"),this.boolean(h(this,Me,"f")),this.describe(h(this,Me,"f"),t||h(this,Y,"f").deferY18nLookup("Show help")),this}help(e,t){return this.addHelpOpt(e,t)}addShowHiddenOpt(e,t){if(j("[string|boolean] [string]",[e,t],arguments.length),e===!1&&t===void 0)return this;let n=typeof e==="string"?e:h(this,Rn,"f");return this.boolean(n),this.describe(n,t||h(this,Y,"f").deferY18nLookup("Show hidden options")),h(this,K,"f").showHiddenOpt=n,this}showHidden(e,t){return this.addShowHiddenOpt(e,t)}alias(e,t){return j("<object|string|array> [string|array]",[e,t],arguments.length),this[Xs](this.alias.bind(this),"alias",e,t),this}array(e){return j("<array|string>",[e],arguments.length),this[at]("array",e),this[St](e),this}boolean(e){return j("<array|string>",[e],arguments.length),this[at]("boolean",e),this[St](e),this}check(e,t){return j("<function> [boolean]",[e,t],arguments.length),this.middleware((n,r)=>gt(()=>e(n,r.getOptions()),(s)=>{if(!s)h(this,Y,"f").fail(h(this,H,"f").y18n.__("Argument check failed: %s",e.toString()));else if(typeof s==="string"||s instanceof Error)h(this,Y,"f").fail(s.toString(),s);return n},(s)=>(h(this,Y,"f").fail(s.message?s.message:s.toString(),s),n)),!1,t),this}choices(e,t){return j("<object|string|array> [string|array]",[e,t],arguments.length),this[Xs](this.choices.bind(this),"choices",e,t),this}coerce(e,t){if(j("<object|string|array> [function]",[e,t],arguments.length),Array.isArray(e)){if(!t)throw new le("coerce callback must be provided");for(let r of e)this.coerce(r,t);return this}else if(typeof e==="object"){for(let r of Object.keys(e))this.coerce(r,e[r]);return this}if(!t)throw new le("coerce callback must be provided");let n=e;return h(this,K,"f").key[n]=!0,h(this,Re,"f").addCoerceMiddleware((r,s)=>{var i;let o=(i=s.getAliases()[n])!==null&&i!==void 0?i:[],a=[n,...o].filter((c)=>Object.prototype.hasOwnProperty.call(r,c));if(a.length===0)return r;return gt(()=>t(r[a[0]]),(c)=>(a.forEach((u)=>{r[u]=c}),r),(c)=>{throw new le(c.message)})},n),this}conflicts(e,t){return j("<string|object> [string|array]",[e,t],arguments.length),h(this,ce,"f").conflicts(e,t),this}config(e="config",t,n){if(j("[object|string] [string|function] [function]",[e,t,n],arguments.length),typeof e==="object"&&!Array.isArray(e))return e=sn(e,h(this,mt,"f"),this[xt]()["deep-merge-config"]||!1,h(this,H,"f")),h(this,K,"f").configObjects=(h(this,K,"f").configObjects||[]).concat(e),this;if(typeof t==="function")n=t,t=void 0;return this.describe(e,t||h(this,Y,"f").deferY18nLookup("Path to JSON config file")),(Array.isArray(e)?e:[e]).forEach((r)=>{h(this,K,"f").config[r]=n||!0}),this}completion(e,t,n){if(j("[string] [string|boolean|function] [function]",[e,t,n],arguments.length),typeof t==="function")n=t,t=void 0;if(W(this,Ae,e||h(this,Ae,"f")||"completion","f"),!t&&t!==!1)t="generate completion script";if(this.command(h(this,Ae,"f"),t),n)h(this,xe,"f").registerFunction(n);return this}command(e,t,n,r,s,i){return j("<string|array|object> [string|boolean] [function|object] [function] [array] [boolean|string]",[e,t,n,r,s,i],arguments.length),h(this,fe,"f").addHandler(e,t,n,r,s,i),this}commands(e,t,n,r,s,i){return this.command(e,t,n,r,s,i)}commandDir(e,t){j("<string> [object]",[e,t],arguments.length);let n=h(this,vn,"f")||h(this,H,"f").require;return h(this,fe,"f").addDirectory(e,n,h(this,H,"f").getCallerFile(),t),this}count(e){return j("<array|string>",[e],arguments.length),this[at]("count",e),this[St](e),this}default(e,t,n){if(j("<object|string|array> [*] [string]",[e,t,n],arguments.length),n)Us(e,h(this,H,"f")),h(this,K,"f").defaultDescription[e]=n;if(typeof t==="function"){if(Us(e,h(this,H,"f")),!h(this,K,"f").defaultDescription[e])h(this,K,"f").defaultDescription[e]=h(this,Y,"f").functionDescription(t);t=t.call()}return this[Jt](this.default.bind(this),"default",e,t),this}defaults(e,t,n){return this.default(e,t,n)}demandCommand(e=1,t,n,r){if(j("[number] [number|string] [string|null|undefined] [string|null|undefined]",[e,t,n,r],arguments.length),typeof t!=="number")n=t,t=1/0;return this.global("_",!1),h(this,K,"f").demandedCommands._={min:e,max:t,minMsg:n,maxMsg:r},this}demand(e,t,n){if(Array.isArray(t))t.forEach((r)=>{Ce(n,!0,h(this,H,"f")),this.demandOption(r,n)}),t=1/0;else if(typeof t!=="number")n=t,t=1/0;if(typeof e==="number")Ce(n,!0,h(this,H,"f")),this.demandCommand(e,t,n,n);else if(Array.isArray(e))e.forEach((r)=>{Ce(n,!0,h(this,H,"f")),this.demandOption(r,n)});else if(typeof n==="string")this.demandOption(e,n);else if(n===!0||typeof n>"u")this.demandOption(e);return this}demandOption(e,t){return j("<object|string|array> [string]",[e,t],arguments.length),this[Jt](this.demandOption.bind(this),"demandedOptions",e,t),this}deprecateOption(e,t){return j("<string> [string|boolean]",[e,t],arguments.length),h(this,K,"f").deprecatedOptions[e]=t,this}describe(e,t){return j("<object|string|array> [string]",[e,t],arguments.length),this[Zs](e,!0),h(this,Y,"f").describe(e,t),this}detectLocale(e){return j("<boolean>",[e],arguments.length),W(this,Dt,e,"f"),this}env(e){if(j("[string|boolean]",[e],arguments.length),e===!1)delete h(this,K,"f").envPrefix;else h(this,K,"f").envPrefix=e||"";return this}epilogue(e){return j("<string>",[e],arguments.length),h(this,Y,"f").epilog(e),this}epilog(e){return this.epilogue(e)}example(e,t){if(j("<string|array> [string]",[e,t],arguments.length),Array.isArray(e))e.forEach((n)=>this.example(...n));else h(this,Y,"f").example(e,t);return this}exit(e,t){if(W(this,$e,!0,"f"),W(this,it,t,"f"),h(this,Pe,"f"))h(this,H,"f").process.exit(e)}exitProcess(e=!0){return j("[boolean]",[e],arguments.length),W(this,Pe,e,"f"),this}fail(e){if(j("<function|boolean>",[e],arguments.length),typeof e==="boolean"&&e!==!1)throw new le("Invalid first argument. Expected function or boolean 'false'");return h(this,Y,"f").failFn(e),this}getAliases(){return this.parsed?this.parsed.aliases:{}}async getCompletion(e,t){if(j("<array> [function]",[e,t],arguments.length),!t)return new Promise((n,r)=>{h(this,xe,"f").getCompletion(e,(s,i)=>{if(s)r(s);else n(i)})});else return h(this,xe,"f").getCompletion(e,t)}getDemandedOptions(){return j([],0),h(this,K,"f").demandedOptions}getDemandedCommands(){return j([],0),h(this,K,"f").demandedCommands}getDeprecatedOptions(){return j([],0),h(this,K,"f").deprecatedOptions}getDetectLocale(){return h(this,Dt,"f")}getExitProcess(){return h(this,Pe,"f")}getGroups(){return Object.assign({},h(this,Ge,"f"),h(this,bt,"f"))}getHelp(){if(W(this,$e,!0,"f"),!h(this,Y,"f").hasCachedHelpMessage()){if(!this.parsed){let t=this[on](h(this,ot,"f"),void 0,void 0,0,!0);if(se(t))return t.then(()=>h(this,Y,"f").help())}let e=h(this,fe,"f").runDefaultBuilderOn(this);if(se(e))return e.then(()=>h(this,Y,"f").help())}return Promise.resolve(h(this,Y,"f").help())}getOptions(){return h(this,K,"f")}getStrict(){return h(this,Ft,"f")}getStrictCommands(){return h(this,Ct,"f")}getStrictOptions(){return h(this,Et,"f")}global(e,t){if(j("<string|array> [boolean]",[e,t],arguments.length),e=[].concat(e),t!==!1)h(this,K,"f").local=h(this,K,"f").local.filter((n)=>e.indexOf(n)===-1);else e.forEach((n)=>{if(!h(this,K,"f").local.includes(n))h(this,K,"f").local.push(n)});return this}group(e,t){j("<string|array> <string>",[e,t],arguments.length);let n=h(this,bt,"f")[t]||h(this,Ge,"f")[t];if(h(this,bt,"f")[t])delete h(this,bt,"f")[t];let r={};return h(this,Ge,"f")[t]=(n||[]).concat(e).filter((s)=>{if(r[s])return!1;return r[s]=!0}),this}hide(e){return j("<string>",[e],arguments.length),h(this,K,"f").hiddenOptions.push(e),this}implies(e,t){return j("<string|object> [number|string|array]",[e,t],arguments.length),h(this,ce,"f").implies(e,t),this}locale(e){if(j("[string]",[e],arguments.length),e===void 0)return this[qs](),h(this,H,"f").y18n.getLocale();return W(this,Dt,!1,"f"),h(this,H,"f").y18n.setLocale(e),this}middleware(e,t,n){return h(this,Re,"f").addMiddleware(e,!!t,n)}nargs(e,t){return j("<string|object|array> [number]",[e,t],arguments.length),this[Jt](this.nargs.bind(this),"narg",e,t),this}normalize(e){return j("<array|string>",[e],arguments.length),this[at]("normalize",e),this}number(e){return j("<array|string>",[e],arguments.length),this[at]("number",e),this[St](e),this}option(e,t){if(j("<string|object> [object]",[e,t],arguments.length),typeof e==="object")Object.keys(e).forEach((n)=>{this.options(n,e[n])});else{if(typeof t!=="object")t={};if(this[St](e),h(this,Ve,"f")&&(e==="version"||(t===null||t===void 0?void 0:t.alias)==="version"))this[yo](['"version" is a reserved word.',"Please do one of the following:",'- Disable version with `yargs.version(false)` if using "version" as an option',"- Use the built-in `yargs.version` method instead (if applicable)","- Use a different option key","https://yargs.js.org/docs/#api-reference-version"].join(`
79
- `),void 0,"versionWarning");if(h(this,K,"f").key[e]=!0,t.alias)this.alias(e,t.alias);let n=t.deprecate||t.deprecated;if(n)this.deprecateOption(e,n);let r=t.demand||t.required||t.require;if(r)this.demand(e,r);if(t.demandOption)this.demandOption(e,typeof t.demandOption==="string"?t.demandOption:void 0);if(t.conflicts)this.conflicts(e,t.conflicts);if("default"in t)this.default(e,t.default);if(t.implies!==void 0)this.implies(e,t.implies);if(t.nargs!==void 0)this.nargs(e,t.nargs);if(t.config)this.config(e,t.configParser);if(t.normalize)this.normalize(e);if(t.choices)this.choices(e,t.choices);if(t.coerce)this.coerce(e,t.coerce);if(t.group)this.group(e,t.group);if(t.boolean||t.type==="boolean"){if(this.boolean(e),t.alias)this.boolean(t.alias)}if(t.array||t.type==="array"){if(this.array(e),t.alias)this.array(t.alias)}if(t.number||t.type==="number"){if(this.number(e),t.alias)this.number(t.alias)}if(t.string||t.type==="string"){if(this.string(e),t.alias)this.string(t.alias)}if(t.count||t.type==="count")this.count(e);if(typeof t.global==="boolean")this.global(e,t.global);if(t.defaultDescription)h(this,K,"f").defaultDescription[e]=t.defaultDescription;if(t.skipValidation)this.skipValidation(e);let s=t.describe||t.description||t.desc,i=h(this,Y,"f").getDescriptions();if(!Object.prototype.hasOwnProperty.call(i,e)||typeof s==="string")this.describe(e,s);if(t.hidden)this.hide(e);if(t.requiresArg)this.requiresArg(e)}return this}options(e,t){return this.option(e,t)}parse(e,t,n){if(j("[string|array] [function|boolean|object] [function]",[e,t,n],arguments.length),this[wo](),typeof e>"u")e=h(this,ot,"f");if(typeof t==="object")W(this,wt,t,"f"),t=n;if(typeof t==="function")W(this,Oe,t,"f"),t=!1;if(!t)W(this,ot,e,"f");if(h(this,Oe,"f"))W(this,Pe,!1,"f");let r=this[on](e,!!t),s=this.parsed;if(h(this,xe,"f").setParsed(this.parsed),se(r))return r.then((i)=>{if(h(this,Oe,"f"))h(this,Oe,"f").call(this,h(this,it,"f"),i,h(this,me,"f"));return i}).catch((i)=>{if(h(this,Oe,"f"))h(this,Oe,"f")(i,this.parsed.argv,h(this,me,"f"));throw i}).finally(()=>{this[Qs](),this.parsed=s});else{if(h(this,Oe,"f"))h(this,Oe,"f").call(this,h(this,it,"f"),r,h(this,me,"f"));this[Qs](),this.parsed=s}return r}parseAsync(e,t,n){let r=this.parse(e,t,n);return!se(r)?Promise.resolve(r):r}parseSync(e,t,n){let r=this.parse(e,t,n);if(se(r))throw new le(".parseSync() must not be used with asynchronous builders, handlers, or middleware");return r}parserConfiguration(e){return j("<object>",[e],arguments.length),W(this,jn,e,"f"),this}pkgConf(e,t){j("<string> [string]",[e,t],arguments.length);let n=null,r=this[Ys](t||h(this,mt,"f"));if(r[e]&&typeof r[e]==="object")n=sn(r[e],t||h(this,mt,"f"),this[xt]()["deep-merge-config"]||!1,h(this,H,"f")),h(this,K,"f").configObjects=(h(this,K,"f").configObjects||[]).concat(n);return this}positional(e,t){j("<string> <object>",[e,t],arguments.length);let n=["default","defaultDescription","implies","normalize","choices","conflicts","coerce","type","describe","desc","description","alias"];t=st(t,(i,o)=>{if(i==="type"&&!["string","number","boolean"].includes(o))return!1;return n.includes(i)});let r=h(this,rn,"f").fullCommands[h(this,rn,"f").fullCommands.length-1],s=r?h(this,fe,"f").cmdToParseOptions(r):{array:[],alias:{},default:{},demand:{}};return Wt(s).forEach((i)=>{let o=s[i];if(Array.isArray(o)){if(o.indexOf(e)!==-1)t[i]=!0}else if(o[e]&&!(i in t))t[i]=o[e]}),this.group(e,h(this,Y,"f").getPositionalGroupName()),this.option(e,t)}recommendCommands(e=!0){return j("[boolean]",[e],arguments.length),W(this,Ln,e,"f"),this}required(e,t,n){return this.demand(e,t,n)}require(e,t,n){return this.demand(e,t,n)}requiresArg(e){if(j("<array|string|object> [number]",[e],arguments.length),typeof e==="string"&&h(this,K,"f").narg[e])return this;else this[Jt](this.requiresArg.bind(this),"narg",e,NaN);return this}showCompletionScript(e,t){return j("[string] [string]",[e,t],arguments.length),e=e||this.$0,h(this,yt,"f").log(h(this,xe,"f").generateCompletionScript(e,t||h(this,Ae,"f")||"completion")),this}showHelp(e){if(j("[string|function]",[e],arguments.length),W(this,$e,!0,"f"),!h(this,Y,"f").hasCachedHelpMessage()){if(!this.parsed){let n=this[on](h(this,ot,"f"),void 0,void 0,0,!0);if(se(n))return n.then(()=>{h(this,Y,"f").showHelp(e)}),this}let t=h(this,fe,"f").runDefaultBuilderOn(this);if(se(t))return t.then(()=>{h(this,Y,"f").showHelp(e)}),this}return h(this,Y,"f").showHelp(e),this}scriptName(e){return this.customScriptName=!0,this.$0=e,this}showHelpOnFail(e,t){return j("[boolean|string] [string]",[e,t],arguments.length),h(this,Y,"f").showHelpOnFail(e,t),this}showVersion(e){return j("[string|function]",[e],arguments.length),h(this,Y,"f").showVersion(e),this}skipValidation(e){return j("<array|string>",[e],arguments.length),this[at]("skipValidation",e),this}strict(e){return j("[boolean]",[e],arguments.length),W(this,Ft,e!==!1,"f"),this}strictCommands(e){return j("[boolean]",[e],arguments.length),W(this,Ct,e!==!1,"f"),this}strictOptions(e){return j("[boolean]",[e],arguments.length),W(this,Et,e!==!1,"f"),this}string(e){return j("<array|string>",[e],arguments.length),this[at]("string",e),this[St](e),this}terminalWidth(){return j([],0),h(this,H,"f").process.stdColumns}updateLocale(e){return this.updateStrings(e)}updateStrings(e){return j("<object>",[e],arguments.length),W(this,Dt,!1,"f"),h(this,H,"f").y18n.updateLocale(e),this}usage(e,t,n,r){if(j("<string|null|undefined> [string|boolean] [function|object] [function]",[e,t,n,r],arguments.length),t!==void 0)if(Ce(e,null,h(this,H,"f")),(e||"").match(/^\$0( |$)/))return this.command(e,t,n,r);else throw new le(".usage() description must start with $0 if being used as alias for .command()");else return h(this,Y,"f").usage(e),this}usageConfiguration(e){return j("<object>",[e],arguments.length),W(this,Wn,e,"f"),this}version(e,t,n){if(j("[boolean|string] [string] [string]",[e,t,n],arguments.length),h(this,Ve,"f"))this[Hs](h(this,Ve,"f")),h(this,Y,"f").version(void 0),W(this,Ve,null,"f");if(arguments.length===0)n=this[Co](),e="version";else if(arguments.length===1){if(e===!1)return this;n=e,e="version"}else if(arguments.length===2)n=t,t=void 0;return W(this,Ve,typeof e==="string"?e:"version","f"),t=t||h(this,Y,"f").deferY18nLookup("Show version number"),h(this,Y,"f").version(n||void 0),this.boolean(h(this,Ve,"f")),this.describe(h(this,Ve,"f"),t),this}wrap(e){return j("<number|null|undefined>",[e],arguments.length),h(this,Y,"f").wrap(e),this}[(fe=new WeakMap,mt=new WeakMap,rn=new WeakMap,xe=new WeakMap,Ae=new WeakMap,Rn=new WeakMap,it=new WeakMap,Dt=new WeakMap,Mn=new WeakMap,Pe=new WeakMap,Bn=new WeakMap,Re=new WeakMap,Ge=new WeakMap,$e=new WeakMap,Me=new WeakMap,Nn=new WeakMap,yt=new WeakMap,me=new WeakMap,K=new WeakMap,vn=new WeakMap,jn=new WeakMap,Oe=new WeakMap,wt=new WeakMap,Kt=new WeakMap,bt=new WeakMap,ot=new WeakMap,Ln=new WeakMap,H=new WeakMap,Ft=new WeakMap,Ct=new WeakMap,Et=new WeakMap,Y=new WeakMap,Wn=new WeakMap,Ve=new WeakMap,ce=new WeakMap,mo)](e){if(!e._||!e["--"])return e;e._.push.apply(e._,e["--"]);try{delete e["--"]}catch(t){}return e}[Do](){return{log:(...e)=>{if(!this[Un]())console.log(...e);if(W(this,$e,!0,"f"),h(this,me,"f").length)W(this,me,h(this,me,"f")+`
78
+ `;d.forEach((m)=>{p+=m}),t.fail(p)}};let c={};i.conflicts=function(l,d){if(j("<string|object> [array|string]",[l,d],arguments.length),typeof l==="object")Object.keys(l).forEach((p)=>{i.conflicts(p,l[p])});else{if(e.global(l),!c[l])c[l]=[];if(Array.isArray(d))d.forEach((p)=>i.conflicts(l,p));else c[l].push(d)}},i.getConflicting=()=>c,i.conflicting=function(l){if(Object.keys(l).forEach((d)=>{if(c[d])c[d].forEach((p)=>{if(p&&l[d]!==void 0&&l[p]!==void 0)t.fail(r("Arguments %s and %s are mutually exclusive",d,p))})}),e.getInternalMethods().getParserConfiguration()["strip-dashed"])Object.keys(c).forEach((d)=>{c[d].forEach((p)=>{if(p&&l[n.Parser.camelCase(d)]!==void 0&&l[n.Parser.camelCase(p)]!==void 0)t.fail(r("Arguments %s and %s are mutually exclusive",d,p))})})},i.recommendCommands=function(l,d){d=d.sort((y,C)=>C.length-y.length);let m=null,g=1/0;for(let y=0,C;(C=d[y])!==void 0;y++){let F=po(l,C);if(F<=3&&F<g)g=F,m=C}if(m)t.fail(r("Did you mean %s?",m))},i.reset=function(l){return o=st(o,(d)=>!l[d]),c=st(c,(d)=>!l[d]),i};let u=[];return i.freeze=function(){u.push({implied:o,conflicting:c})},i.unfreeze=function(){let l=u.pop();Ce(l,void 0,n),{implied:o,conflicting:c}=l},i}var Ys=[],nn;function sn(e,t,n,r){nn=r;let s={};if(Object.prototype.hasOwnProperty.call(e,"extends")){if(typeof e.extends!=="string")return s;let i=/\.json|\..*rc$/.test(e.extends),o=null;if(!i)try{o=import.meta.resolve(e.extends)}catch(a){return e}else o=kl(t,e.extends);_l(o),Ys.push(o),s=i?JSON.parse(nn.readFileSync(o,"utf8")):r.require(e.extends),delete e.extends,s=sn(s,nn.path.dirname(o),n,nn)}return Ys=[],n?mo(s,e):Object.assign({},s,e)}function _l(e){if(Ys.indexOf(e)>-1)throw new le(`Circular extended configurations: '${e}'.`)}function kl(e,t){return nn.path.resolve(e,t)}function mo(e,t){let n={};function r(s){return s&&typeof s==="object"&&!Array.isArray(s)}Object.assign(n,e);for(let s of Object.keys(t))if(r(t[s])&&r(n[s]))n[s]=mo(e[s],t[s]);else n[s]=t[s];return n}var W=function(e,t,n,r,s){if(r==="m")throw TypeError("Private method is not writable");if(r==="a"&&!s)throw TypeError("Private accessor was defined without a setter");if(typeof t==="function"?e!==t||!s:!t.has(e))throw TypeError("Cannot write private member to an object whose class did not declare it");return r==="a"?s.call(e,n):s?s.value=n:t.set(e,n),n},h=function(e,t,n,r){if(n==="a"&&!r)throw TypeError("Private accessor was defined without a getter");if(typeof t==="function"?e!==t||!r:!t.has(e))throw TypeError("Cannot read private member from an object whose class did not declare it");return n==="m"?r:n==="a"?r.call(e):r?r.value:t.get(e)},fe,yt,rn,xe,Ae,Rn,it,wt,Mn,Pe,Bn,Re,Ge,$e,Me,Nn,bt,me,K,vn,jn,Oe,Ft,zt,Ct,ot,Ln,H,Et,xt,_t,Y,Wn,Ve,ce;function Bo(e){return(t=[],n=e.process.cwd(),r)=>{let s=new No(t,n,r,e);return Object.defineProperty(s,"argv",{get:()=>s.parse(),enumerable:!0}),s.help(),s.version(),s}}var Do=Symbol("copyDoubleDash"),yo=Symbol("copyDoubleDash"),Xs=Symbol("deleteFromParserHintObject"),wo=Symbol("emitWarning"),bo=Symbol("freeze"),Fo=Symbol("getDollarZero"),kt=Symbol("getParserConfiguration"),Co=Symbol("getUsageConfiguration"),Gs=Symbol("guessLocale"),Eo=Symbol("guessVersion"),xo=Symbol("parsePositionalNumbers"),Vs=Symbol("pkgUp"),at=Symbol("populateParserHintArray"),Ht=Symbol("populateParserHintSingleValueDictionary"),Zs=Symbol("populateParserHintArrayDictionary"),Qs=Symbol("populateParserHintDictionary"),er=Symbol("sanitizeKey"),tr=Symbol("setKey"),nr=Symbol("unfreeze"),_o=Symbol("validateAsync"),ko=Symbol("getCommandInstance"),So=Symbol("getContext"),Ao=Symbol("getHasOutput"),$o=Symbol("getLoggerInstance"),Oo=Symbol("getParseContext"),Io=Symbol("getUsageInstance"),To=Symbol("getValidationInstance"),Un=Symbol("hasParseCallback"),Po=Symbol("isGlobalContext"),St=Symbol("postProcess"),Ro=Symbol("rebase"),sr=Symbol("reset"),on=Symbol("runYargsParserAndExecuteCommands"),rr=Symbol("runValidation"),Mo=Symbol("setHasOutput"),At=Symbol("kTrackManuallySetKeys"),Sl="en_US";class No{constructor(e=[],t,n,r){this.customScriptName=!1,this.parsed=!1,fe.set(this,void 0),yt.set(this,void 0),rn.set(this,{commands:[],fullCommands:[]}),xe.set(this,null),Ae.set(this,null),Rn.set(this,"show-hidden"),it.set(this,null),wt.set(this,!0),Mn.set(this,{}),Pe.set(this,!0),Bn.set(this,[]),Re.set(this,void 0),Ge.set(this,{}),$e.set(this,!1),Me.set(this,null),Nn.set(this,!0),bt.set(this,void 0),me.set(this,""),K.set(this,void 0),vn.set(this,void 0),jn.set(this,{}),Oe.set(this,null),Ft.set(this,null),zt.set(this,{}),Ct.set(this,{}),ot.set(this,void 0),Ln.set(this,!1),H.set(this,void 0),Et.set(this,!1),xt.set(this,!1),_t.set(this,!1),Y.set(this,void 0),Wn.set(this,{}),Ve.set(this,null),ce.set(this,void 0),W(this,H,r,"f"),W(this,ot,e,"f"),W(this,yt,t,"f"),W(this,vn,n,"f"),W(this,Re,new Hs(this),"f"),this.$0=this[Fo](),this[sr](),W(this,fe,h(this,fe,"f"),"f"),W(this,Y,h(this,Y,"f"),"f"),W(this,ce,h(this,ce,"f"),"f"),W(this,K,h(this,K,"f"),"f"),h(this,K,"f").showHiddenOpt=h(this,Rn,"f"),W(this,bt,this[yo](),"f"),h(this,H,"f").y18n.setLocale(Sl)}addHelpOpt(e,t){if(j("[string|boolean] [string]",[e,t],arguments.length),h(this,Me,"f"))this[Xs](h(this,Me,"f")),W(this,Me,null,"f");if(e===!1&&t===void 0)return this;return W(this,Me,typeof e==="string"?e:"help","f"),this.boolean(h(this,Me,"f")),this.describe(h(this,Me,"f"),t||h(this,Y,"f").deferY18nLookup("Show help")),this}help(e,t){return this.addHelpOpt(e,t)}addShowHiddenOpt(e,t){if(j("[string|boolean] [string]",[e,t],arguments.length),e===!1&&t===void 0)return this;let n=typeof e==="string"?e:h(this,Rn,"f");return this.boolean(n),this.describe(n,t||h(this,Y,"f").deferY18nLookup("Show hidden options")),h(this,K,"f").showHiddenOpt=n,this}showHidden(e,t){return this.addShowHiddenOpt(e,t)}alias(e,t){return j("<object|string|array> [string|array]",[e,t],arguments.length),this[Zs](this.alias.bind(this),"alias",e,t),this}array(e){return j("<array|string>",[e],arguments.length),this[at]("array",e),this[At](e),this}boolean(e){return j("<array|string>",[e],arguments.length),this[at]("boolean",e),this[At](e),this}check(e,t){return j("<function> [boolean]",[e,t],arguments.length),this.middleware((n,r)=>Dt(()=>e(n,r.getOptions()),(s)=>{if(!s)h(this,Y,"f").fail(h(this,H,"f").y18n.__("Argument check failed: %s",e.toString()));else if(typeof s==="string"||s instanceof Error)h(this,Y,"f").fail(s.toString(),s);return n},(s)=>(h(this,Y,"f").fail(s.message?s.message:s.toString(),s),n)),!1,t),this}choices(e,t){return j("<object|string|array> [string|array]",[e,t],arguments.length),this[Zs](this.choices.bind(this),"choices",e,t),this}coerce(e,t){if(j("<object|string|array> [function]",[e,t],arguments.length),Array.isArray(e)){if(!t)throw new le("coerce callback must be provided");for(let r of e)this.coerce(r,t);return this}else if(typeof e==="object"){for(let r of Object.keys(e))this.coerce(r,e[r]);return this}if(!t)throw new le("coerce callback must be provided");let n=e;return h(this,K,"f").key[n]=!0,h(this,Re,"f").addCoerceMiddleware((r,s)=>{var i;let o=(i=s.getAliases()[n])!==null&&i!==void 0?i:[],a=[n,...o].filter((c)=>Object.prototype.hasOwnProperty.call(r,c));if(a.length===0)return r;return Dt(()=>t(r[a[0]]),(c)=>(a.forEach((u)=>{r[u]=c}),r),(c)=>{throw new le(c.message)})},n),this}conflicts(e,t){return j("<string|object> [string|array]",[e,t],arguments.length),h(this,ce,"f").conflicts(e,t),this}config(e="config",t,n){if(j("[object|string] [string|function] [function]",[e,t,n],arguments.length),typeof e==="object"&&!Array.isArray(e))return e=sn(e,h(this,yt,"f"),this[kt]()["deep-merge-config"]||!1,h(this,H,"f")),h(this,K,"f").configObjects=(h(this,K,"f").configObjects||[]).concat(e),this;if(typeof t==="function")n=t,t=void 0;return this.describe(e,t||h(this,Y,"f").deferY18nLookup("Path to JSON config file")),(Array.isArray(e)?e:[e]).forEach((r)=>{h(this,K,"f").config[r]=n||!0}),this}completion(e,t,n){if(j("[string] [string|boolean|function] [function]",[e,t,n],arguments.length),typeof t==="function")n=t,t=void 0;if(W(this,Ae,e||h(this,Ae,"f")||"completion","f"),!t&&t!==!1)t="generate completion script";if(this.command(h(this,Ae,"f"),t),n)h(this,xe,"f").registerFunction(n);return this}command(e,t,n,r,s,i){return j("<string|array|object> [string|boolean] [function|object] [function] [array] [boolean|string]",[e,t,n,r,s,i],arguments.length),h(this,fe,"f").addHandler(e,t,n,r,s,i),this}commands(e,t,n,r,s,i){return this.command(e,t,n,r,s,i)}commandDir(e,t){j("<string> [object]",[e,t],arguments.length);let n=h(this,vn,"f")||h(this,H,"f").require;return h(this,fe,"f").addDirectory(e,n,h(this,H,"f").getCallerFile(),t),this}count(e){return j("<array|string>",[e],arguments.length),this[at]("count",e),this[At](e),this}default(e,t,n){if(j("<object|string|array> [*] [string]",[e,t,n],arguments.length),n)zs(e,h(this,H,"f")),h(this,K,"f").defaultDescription[e]=n;if(typeof t==="function"){if(zs(e,h(this,H,"f")),!h(this,K,"f").defaultDescription[e])h(this,K,"f").defaultDescription[e]=h(this,Y,"f").functionDescription(t);t=t.call()}return this[Ht](this.default.bind(this),"default",e,t),this}defaults(e,t,n){return this.default(e,t,n)}demandCommand(e=1,t,n,r){if(j("[number] [number|string] [string|null|undefined] [string|null|undefined]",[e,t,n,r],arguments.length),typeof t!=="number")n=t,t=1/0;return this.global("_",!1),h(this,K,"f").demandedCommands._={min:e,max:t,minMsg:n,maxMsg:r},this}demand(e,t,n){if(Array.isArray(t))t.forEach((r)=>{Ce(n,!0,h(this,H,"f")),this.demandOption(r,n)}),t=1/0;else if(typeof t!=="number")n=t,t=1/0;if(typeof e==="number")Ce(n,!0,h(this,H,"f")),this.demandCommand(e,t,n,n);else if(Array.isArray(e))e.forEach((r)=>{Ce(n,!0,h(this,H,"f")),this.demandOption(r,n)});else if(typeof n==="string")this.demandOption(e,n);else if(n===!0||typeof n>"u")this.demandOption(e);return this}demandOption(e,t){return j("<object|string|array> [string]",[e,t],arguments.length),this[Ht](this.demandOption.bind(this),"demandedOptions",e,t),this}deprecateOption(e,t){return j("<string> [string|boolean]",[e,t],arguments.length),h(this,K,"f").deprecatedOptions[e]=t,this}describe(e,t){return j("<object|string|array> [string]",[e,t],arguments.length),this[tr](e,!0),h(this,Y,"f").describe(e,t),this}detectLocale(e){return j("<boolean>",[e],arguments.length),W(this,wt,e,"f"),this}env(e){if(j("[string|boolean]",[e],arguments.length),e===!1)delete h(this,K,"f").envPrefix;else h(this,K,"f").envPrefix=e||"";return this}epilogue(e){return j("<string>",[e],arguments.length),h(this,Y,"f").epilog(e),this}epilog(e){return this.epilogue(e)}example(e,t){if(j("<string|array> [string]",[e,t],arguments.length),Array.isArray(e))e.forEach((n)=>this.example(...n));else h(this,Y,"f").example(e,t);return this}exit(e,t){if(W(this,$e,!0,"f"),W(this,it,t,"f"),h(this,Pe,"f"))h(this,H,"f").process.exit(e)}exitProcess(e=!0){return j("[boolean]",[e],arguments.length),W(this,Pe,e,"f"),this}fail(e){if(j("<function|boolean>",[e],arguments.length),typeof e==="boolean"&&e!==!1)throw new le("Invalid first argument. Expected function or boolean 'false'");return h(this,Y,"f").failFn(e),this}getAliases(){return this.parsed?this.parsed.aliases:{}}async getCompletion(e,t){if(j("<array> [function]",[e,t],arguments.length),!t)return new Promise((n,r)=>{h(this,xe,"f").getCompletion(e,(s,i)=>{if(s)r(s);else n(i)})});else return h(this,xe,"f").getCompletion(e,t)}getDemandedOptions(){return j([],0),h(this,K,"f").demandedOptions}getDemandedCommands(){return j([],0),h(this,K,"f").demandedCommands}getDeprecatedOptions(){return j([],0),h(this,K,"f").deprecatedOptions}getDetectLocale(){return h(this,wt,"f")}getExitProcess(){return h(this,Pe,"f")}getGroups(){return Object.assign({},h(this,Ge,"f"),h(this,Ct,"f"))}getHelp(){if(W(this,$e,!0,"f"),!h(this,Y,"f").hasCachedHelpMessage()){if(!this.parsed){let t=this[on](h(this,ot,"f"),void 0,void 0,0,!0);if(se(t))return t.then(()=>h(this,Y,"f").help())}let e=h(this,fe,"f").runDefaultBuilderOn(this);if(se(e))return e.then(()=>h(this,Y,"f").help())}return Promise.resolve(h(this,Y,"f").help())}getOptions(){return h(this,K,"f")}getStrict(){return h(this,Et,"f")}getStrictCommands(){return h(this,xt,"f")}getStrictOptions(){return h(this,_t,"f")}global(e,t){if(j("<string|array> [boolean]",[e,t],arguments.length),e=[].concat(e),t!==!1)h(this,K,"f").local=h(this,K,"f").local.filter((n)=>e.indexOf(n)===-1);else e.forEach((n)=>{if(!h(this,K,"f").local.includes(n))h(this,K,"f").local.push(n)});return this}group(e,t){j("<string|array> <string>",[e,t],arguments.length);let n=h(this,Ct,"f")[t]||h(this,Ge,"f")[t];if(h(this,Ct,"f")[t])delete h(this,Ct,"f")[t];let r={};return h(this,Ge,"f")[t]=(n||[]).concat(e).filter((s)=>{if(r[s])return!1;return r[s]=!0}),this}hide(e){return j("<string>",[e],arguments.length),h(this,K,"f").hiddenOptions.push(e),this}implies(e,t){return j("<string|object> [number|string|array]",[e,t],arguments.length),h(this,ce,"f").implies(e,t),this}locale(e){if(j("[string]",[e],arguments.length),e===void 0)return this[Gs](),h(this,H,"f").y18n.getLocale();return W(this,wt,!1,"f"),h(this,H,"f").y18n.setLocale(e),this}middleware(e,t,n){return h(this,Re,"f").addMiddleware(e,!!t,n)}nargs(e,t){return j("<string|object|array> [number]",[e,t],arguments.length),this[Ht](this.nargs.bind(this),"narg",e,t),this}normalize(e){return j("<array|string>",[e],arguments.length),this[at]("normalize",e),this}number(e){return j("<array|string>",[e],arguments.length),this[at]("number",e),this[At](e),this}option(e,t){if(j("<string|object> [object]",[e,t],arguments.length),typeof e==="object")Object.keys(e).forEach((n)=>{this.options(n,e[n])});else{if(typeof t!=="object")t={};if(this[At](e),h(this,Ve,"f")&&(e==="version"||(t===null||t===void 0?void 0:t.alias)==="version"))this[wo](['"version" is a reserved word.',"Please do one of the following:",'- Disable version with `yargs.version(false)` if using "version" as an option',"- Use the built-in `yargs.version` method instead (if applicable)","- Use a different option key","https://yargs.js.org/docs/#api-reference-version"].join(`
79
+ `),void 0,"versionWarning");if(h(this,K,"f").key[e]=!0,t.alias)this.alias(e,t.alias);let n=t.deprecate||t.deprecated;if(n)this.deprecateOption(e,n);let r=t.demand||t.required||t.require;if(r)this.demand(e,r);if(t.demandOption)this.demandOption(e,typeof t.demandOption==="string"?t.demandOption:void 0);if(t.conflicts)this.conflicts(e,t.conflicts);if("default"in t)this.default(e,t.default);if(t.implies!==void 0)this.implies(e,t.implies);if(t.nargs!==void 0)this.nargs(e,t.nargs);if(t.config)this.config(e,t.configParser);if(t.normalize)this.normalize(e);if(t.choices)this.choices(e,t.choices);if(t.coerce)this.coerce(e,t.coerce);if(t.group)this.group(e,t.group);if(t.boolean||t.type==="boolean"){if(this.boolean(e),t.alias)this.boolean(t.alias)}if(t.array||t.type==="array"){if(this.array(e),t.alias)this.array(t.alias)}if(t.number||t.type==="number"){if(this.number(e),t.alias)this.number(t.alias)}if(t.string||t.type==="string"){if(this.string(e),t.alias)this.string(t.alias)}if(t.count||t.type==="count")this.count(e);if(typeof t.global==="boolean")this.global(e,t.global);if(t.defaultDescription)h(this,K,"f").defaultDescription[e]=t.defaultDescription;if(t.skipValidation)this.skipValidation(e);let s=t.describe||t.description||t.desc,i=h(this,Y,"f").getDescriptions();if(!Object.prototype.hasOwnProperty.call(i,e)||typeof s==="string")this.describe(e,s);if(t.hidden)this.hide(e);if(t.requiresArg)this.requiresArg(e)}return this}options(e,t){return this.option(e,t)}parse(e,t,n){if(j("[string|array] [function|boolean|object] [function]",[e,t,n],arguments.length),this[bo](),typeof e>"u")e=h(this,ot,"f");if(typeof t==="object")W(this,Ft,t,"f"),t=n;if(typeof t==="function")W(this,Oe,t,"f"),t=!1;if(!t)W(this,ot,e,"f");if(h(this,Oe,"f"))W(this,Pe,!1,"f");let r=this[on](e,!!t),s=this.parsed;if(h(this,xe,"f").setParsed(this.parsed),se(r))return r.then((i)=>{if(h(this,Oe,"f"))h(this,Oe,"f").call(this,h(this,it,"f"),i,h(this,me,"f"));return i}).catch((i)=>{if(h(this,Oe,"f"))h(this,Oe,"f")(i,this.parsed.argv,h(this,me,"f"));throw i}).finally(()=>{this[nr](),this.parsed=s});else{if(h(this,Oe,"f"))h(this,Oe,"f").call(this,h(this,it,"f"),r,h(this,me,"f"));this[nr](),this.parsed=s}return r}parseAsync(e,t,n){let r=this.parse(e,t,n);return!se(r)?Promise.resolve(r):r}parseSync(e,t,n){let r=this.parse(e,t,n);if(se(r))throw new le(".parseSync() must not be used with asynchronous builders, handlers, or middleware");return r}parserConfiguration(e){return j("<object>",[e],arguments.length),W(this,jn,e,"f"),this}pkgConf(e,t){j("<string> [string]",[e,t],arguments.length);let n=null,r=this[Vs](t||h(this,yt,"f"));if(r[e]&&typeof r[e]==="object")n=sn(r[e],t||h(this,yt,"f"),this[kt]()["deep-merge-config"]||!1,h(this,H,"f")),h(this,K,"f").configObjects=(h(this,K,"f").configObjects||[]).concat(n);return this}positional(e,t){j("<string> <object>",[e,t],arguments.length);let n=["default","defaultDescription","implies","normalize","choices","conflicts","coerce","type","describe","desc","description","alias"];t=st(t,(i,o)=>{if(i==="type"&&!["string","number","boolean"].includes(o))return!1;return n.includes(i)});let r=h(this,rn,"f").fullCommands[h(this,rn,"f").fullCommands.length-1],s=r?h(this,fe,"f").cmdToParseOptions(r):{array:[],alias:{},default:{},demand:{}};return Kt(s).forEach((i)=>{let o=s[i];if(Array.isArray(o)){if(o.indexOf(e)!==-1)t[i]=!0}else if(o[e]&&!(i in t))t[i]=o[e]}),this.group(e,h(this,Y,"f").getPositionalGroupName()),this.option(e,t)}recommendCommands(e=!0){return j("[boolean]",[e],arguments.length),W(this,Ln,e,"f"),this}required(e,t,n){return this.demand(e,t,n)}require(e,t,n){return this.demand(e,t,n)}requiresArg(e){if(j("<array|string|object> [number]",[e],arguments.length),typeof e==="string"&&h(this,K,"f").narg[e])return this;else this[Ht](this.requiresArg.bind(this),"narg",e,NaN);return this}showCompletionScript(e,t){return j("[string] [string]",[e,t],arguments.length),e=e||this.$0,h(this,bt,"f").log(h(this,xe,"f").generateCompletionScript(e,t||h(this,Ae,"f")||"completion")),this}showHelp(e){if(j("[string|function]",[e],arguments.length),W(this,$e,!0,"f"),!h(this,Y,"f").hasCachedHelpMessage()){if(!this.parsed){let n=this[on](h(this,ot,"f"),void 0,void 0,0,!0);if(se(n))return n.then(()=>{h(this,Y,"f").showHelp(e)}),this}let t=h(this,fe,"f").runDefaultBuilderOn(this);if(se(t))return t.then(()=>{h(this,Y,"f").showHelp(e)}),this}return h(this,Y,"f").showHelp(e),this}scriptName(e){return this.customScriptName=!0,this.$0=e,this}showHelpOnFail(e,t){return j("[boolean|string] [string]",[e,t],arguments.length),h(this,Y,"f").showHelpOnFail(e,t),this}showVersion(e){return j("[string|function]",[e],arguments.length),h(this,Y,"f").showVersion(e),this}skipValidation(e){return j("<array|string>",[e],arguments.length),this[at]("skipValidation",e),this}strict(e){return j("[boolean]",[e],arguments.length),W(this,Et,e!==!1,"f"),this}strictCommands(e){return j("[boolean]",[e],arguments.length),W(this,xt,e!==!1,"f"),this}strictOptions(e){return j("[boolean]",[e],arguments.length),W(this,_t,e!==!1,"f"),this}string(e){return j("<array|string>",[e],arguments.length),this[at]("string",e),this[At](e),this}terminalWidth(){return j([],0),h(this,H,"f").process.stdColumns}updateLocale(e){return this.updateStrings(e)}updateStrings(e){return j("<object>",[e],arguments.length),W(this,wt,!1,"f"),h(this,H,"f").y18n.updateLocale(e),this}usage(e,t,n,r){if(j("<string|null|undefined> [string|boolean] [function|object] [function]",[e,t,n,r],arguments.length),t!==void 0)if(Ce(e,null,h(this,H,"f")),(e||"").match(/^\$0( |$)/))return this.command(e,t,n,r);else throw new le(".usage() description must start with $0 if being used as alias for .command()");else return h(this,Y,"f").usage(e),this}usageConfiguration(e){return j("<object>",[e],arguments.length),W(this,Wn,e,"f"),this}version(e,t,n){if(j("[boolean|string] [string] [string]",[e,t,n],arguments.length),h(this,Ve,"f"))this[Xs](h(this,Ve,"f")),h(this,Y,"f").version(void 0),W(this,Ve,null,"f");if(arguments.length===0)n=this[Eo](),e="version";else if(arguments.length===1){if(e===!1)return this;n=e,e="version"}else if(arguments.length===2)n=t,t=void 0;return W(this,Ve,typeof e==="string"?e:"version","f"),t=t||h(this,Y,"f").deferY18nLookup("Show version number"),h(this,Y,"f").version(n||void 0),this.boolean(h(this,Ve,"f")),this.describe(h(this,Ve,"f"),t),this}wrap(e){return j("<number|null|undefined>",[e],arguments.length),h(this,Y,"f").wrap(e),this}[(fe=new WeakMap,yt=new WeakMap,rn=new WeakMap,xe=new WeakMap,Ae=new WeakMap,Rn=new WeakMap,it=new WeakMap,wt=new WeakMap,Mn=new WeakMap,Pe=new WeakMap,Bn=new WeakMap,Re=new WeakMap,Ge=new WeakMap,$e=new WeakMap,Me=new WeakMap,Nn=new WeakMap,bt=new WeakMap,me=new WeakMap,K=new WeakMap,vn=new WeakMap,jn=new WeakMap,Oe=new WeakMap,Ft=new WeakMap,zt=new WeakMap,Ct=new WeakMap,ot=new WeakMap,Ln=new WeakMap,H=new WeakMap,Et=new WeakMap,xt=new WeakMap,_t=new WeakMap,Y=new WeakMap,Wn=new WeakMap,Ve=new WeakMap,ce=new WeakMap,Do)](e){if(!e._||!e["--"])return e;e._.push.apply(e._,e["--"]);try{delete e["--"]}catch(t){}return e}[yo](){return{log:(...e)=>{if(!this[Un]())console.log(...e);if(W(this,$e,!0,"f"),h(this,me,"f").length)W(this,me,h(this,me,"f")+`
80
80
  `,"f");W(this,me,h(this,me,"f")+e.join(" "),"f")},error:(...e)=>{if(!this[Un]())console.error(...e);if(W(this,$e,!0,"f"),h(this,me,"f").length)W(this,me,h(this,me,"f")+`
81
- `,"f");W(this,me,h(this,me,"f")+e.join(" "),"f")}}}[Hs](e){Wt(h(this,K,"f")).forEach((t)=>{if(((r)=>r==="configObjects")(t))return;let n=h(this,K,"f")[t];if(Array.isArray(n)){if(n.includes(e))n.splice(n.indexOf(e),1)}else if(typeof n==="object")delete n[e]}),delete h(this,Y,"f").getDescriptions()[e]}[yo](e,t,n){if(!h(this,Mn,"f")[n])h(this,H,"f").process.emitWarning(e,t),h(this,Mn,"f")[n]=!0}[wo](){h(this,Bn,"f").push({options:h(this,K,"f"),configObjects:h(this,K,"f").configObjects.slice(0),exitProcess:h(this,Pe,"f"),groups:h(this,Ge,"f"),strict:h(this,Ft,"f"),strictCommands:h(this,Ct,"f"),strictOptions:h(this,Et,"f"),completionCommand:h(this,Ae,"f"),output:h(this,me,"f"),exitError:h(this,it,"f"),hasOutput:h(this,$e,"f"),parsed:this.parsed,parseFn:h(this,Oe,"f"),parseContext:h(this,wt,"f")}),h(this,Y,"f").freeze(),h(this,ce,"f").freeze(),h(this,fe,"f").freeze(),h(this,Re,"f").freeze()}[bo](){let e="",t;if(/\b(node|iojs|electron)(\.exe)?$/.test(h(this,H,"f").process.argv()[0]))t=h(this,H,"f").process.argv().slice(1,2);else t=h(this,H,"f").process.argv().slice(0,1);if(e=t.map((n)=>{let r=this[Po](h(this,mt,"f"),n);return n.match(/^(\/|([a-zA-Z]:)?\\)/)&&r.length<n.length?r:n}).join(" ").trim(),h(this,H,"f").getEnv("_")&&h(this,H,"f").getProcessArgvBin()===h(this,H,"f").getEnv("_"))e=h(this,H,"f").getEnv("_").replace(`${h(this,H,"f").path.dirname(h(this,H,"f").process.execPath())}/`,"");return e}[xt](){return h(this,jn,"f")}[Fo](){return h(this,Wn,"f")}[qs](){if(!h(this,Dt,"f"))return;let e=h(this,H,"f").getEnv("LC_ALL")||h(this,H,"f").getEnv("LC_MESSAGES")||h(this,H,"f").getEnv("LANG")||h(this,H,"f").getEnv("LANGUAGE")||"en_US";this.locale(e.replace(/[.:].*/,""))}[Co](){return this[Ys]().version||"unknown"}[Eo](e){let t=e["--"]?e["--"]:e._;for(let n=0,r;(r=t[n])!==void 0;n++)if(h(this,H,"f").Parser.looksLikeNumber(r)&&Number.isSafeInteger(Math.floor(parseFloat(`${r}`))))t[n]=Number(r);return e}[Ys](e){let t=e||"*";if(h(this,Kt,"f")[t])return h(this,Kt,"f")[t];let n={};try{let r=e||h(this,H,"f").mainFilename;if(h(this,H,"f").path.extname(r))r=h(this,H,"f").path.dirname(r);let s=h(this,H,"f").findUp(r,(i,o)=>{if(o.includes("package.json"))return"package.json";else return});Ce(s,void 0,h(this,H,"f")),n=JSON.parse(h(this,H,"f").readFileSync(s,"utf8"))}catch(r){}return h(this,Kt,"f")[t]=n||{},h(this,Kt,"f")[t]}[at](e,t){t=[].concat(t),t.forEach((n)=>{n=this[Vs](n),h(this,K,"f")[e].push(n)})}[Jt](e,t,n,r){this[Gs](e,t,n,r,(s,i,o)=>{h(this,K,"f")[s][i]=o})}[Xs](e,t,n,r){this[Gs](e,t,n,r,(s,i,o)=>{h(this,K,"f")[s][i]=(h(this,K,"f")[s][i]||[]).concat(o)})}[Gs](e,t,n,r,s){if(Array.isArray(n))n.forEach((i)=>{e(i,r)});else if(((i)=>typeof i==="object")(n))for(let i of Wt(n))e(i,n[i]);else s(t,this[Vs](n),r)}[Vs](e){if(e==="__proto__")return"___proto___";return e}[Zs](e,t){return this[Jt](this[Zs].bind(this),"key",e,t),this}[Qs](){var e,t,n,r,s,i,o,a,c,u,f,l;let d=h(this,Bn,"f").pop();Ce(d,void 0,h(this,H,"f"));let p;e=this,t=this,n=this,r=this,s=this,i=this,o=this,a=this,c=this,u=this,f=this,l=this,{options:{set value(m){W(e,K,m,"f")}}.value,configObjects:p,exitProcess:{set value(m){W(t,Pe,m,"f")}}.value,groups:{set value(m){W(n,Ge,m,"f")}}.value,output:{set value(m){W(r,me,m,"f")}}.value,exitError:{set value(m){W(s,it,m,"f")}}.value,hasOutput:{set value(m){W(i,$e,m,"f")}}.value,parsed:this.parsed,strict:{set value(m){W(o,Ft,m,"f")}}.value,strictCommands:{set value(m){W(a,Ct,m,"f")}}.value,strictOptions:{set value(m){W(c,Et,m,"f")}}.value,completionCommand:{set value(m){W(u,Ae,m,"f")}}.value,parseFn:{set value(m){W(f,Oe,m,"f")}}.value,parseContext:{set value(m){W(l,wt,m,"f")}}.value}=d,h(this,K,"f").configObjects=p,h(this,Y,"f").unfreeze(),h(this,ce,"f").unfreeze(),h(this,fe,"f").unfreeze(),h(this,Re,"f").unfreeze()}[xo](e,t){return gt(t,(n)=>(e(n),n))}getInternalMethods(){return{getCommandInstance:this[_o].bind(this),getContext:this[So].bind(this),getHasOutput:this[ko].bind(this),getLoggerInstance:this[Ao].bind(this),getParseContext:this[$o].bind(this),getParserConfiguration:this[xt].bind(this),getUsageConfiguration:this[Fo].bind(this),getUsageInstance:this[Oo].bind(this),getValidationInstance:this[Io].bind(this),hasParseCallback:this[Un].bind(this),isGlobalContext:this[To].bind(this),postProcess:this[_t].bind(this),reset:this[er].bind(this),runValidation:this[tr].bind(this),runYargsParserAndExecuteCommands:this[on].bind(this),setHasOutput:this[Ro].bind(this)}}[_o](){return h(this,fe,"f")}[So](){return h(this,rn,"f")}[ko](){return h(this,$e,"f")}[Ao](){return h(this,yt,"f")}[$o](){return h(this,wt,"f")||{}}[Oo](){return h(this,Y,"f")}[Io](){return h(this,ce,"f")}[Un](){return!!h(this,Oe,"f")}[To](){return h(this,Nn,"f")}[_t](e,t,n,r){if(n)return e;if(se(e))return e;if(!t)e=this[mo](e);if(this[xt]()["parse-positional-numbers"]||this[xt]()["parse-positional-numbers"]===void 0)e=this[Eo](e);if(r)e=ht(e,this,h(this,Re,"f").getMiddleware(),!1);return e}[er](e={}){W(this,K,h(this,K,"f")||{},"f");let t={};t.local=h(this,K,"f").local||[],t.configObjects=h(this,K,"f").configObjects||[];let n={};t.local.forEach((i)=>{n[i]=!0,(e[i]||[]).forEach((o)=>{n[o]=!0})}),Object.assign(h(this,bt,"f"),Object.keys(h(this,Ge,"f")).reduce((i,o)=>{let a=h(this,Ge,"f")[o].filter((c)=>!(c in n));if(a.length>0)i[o]=a;return i},{})),W(this,Ge,{},"f");let r=["array","boolean","string","skipValidation","count","normalize","number","hiddenOptions"],s=["narg","key","alias","default","defaultDescription","config","choices","demandedOptions","demandedCommands","deprecatedOptions"];if(r.forEach((i)=>{t[i]=(h(this,K,"f")[i]||[]).filter((o)=>!n[o])}),s.forEach((i)=>{t[i]=st(h(this,K,"f")[i],(o)=>!n[o])}),t.envPrefix=h(this,K,"f").envPrefix,W(this,K,t,"f"),W(this,Y,h(this,Y,"f")?h(this,Y,"f").reset(n):oo(this,h(this,H,"f")),"f"),W(this,ce,h(this,ce,"f")?h(this,ce,"f").reset(n):ho(this,h(this,Y,"f"),h(this,H,"f")),"f"),W(this,fe,h(this,fe,"f")?h(this,fe,"f").reset():so(h(this,Y,"f"),h(this,ce,"f"),h(this,Re,"f"),h(this,H,"f")),"f"),!h(this,xe,"f"))W(this,xe,lo(this,h(this,Y,"f"),h(this,fe,"f"),h(this,H,"f")),"f");return h(this,Re,"f").reset(),W(this,Ae,null,"f"),W(this,me,"","f"),W(this,it,null,"f"),W(this,$e,!1,"f"),this.parsed=!1,this}[Po](e,t){return h(this,H,"f").path.relative(e,t)}[on](e,t,n,r=0,s=!1){var i,o,a,c;let u=!!n||s;e=e||h(this,ot,"f"),h(this,K,"f").__=h(this,H,"f").y18n.__,h(this,K,"f").configuration=this[xt]();let f=!!h(this,K,"f").configuration["populate--"],l=Object.assign({},h(this,K,"f").configuration,{"populate--":!0}),d=h(this,H,"f").Parser.detailed(e,Object.assign({},h(this,K,"f"),{configuration:{"parse-positional-numbers":!1,...l}})),p=Object.assign(d.argv,h(this,wt,"f")),m=void 0,g=d.aliases,y=!1,C=!1;if(Object.keys(p).forEach((F)=>{if(F===h(this,Me,"f")&&p[F])y=!0;else if(F===h(this,Ve,"f")&&p[F])C=!0}),p.$0=this.$0,this.parsed=d,r===0)h(this,Y,"f").clearCachedHelpMessage();try{if(this[qs](),t)return this[_t](p,f,!!n,!1);if(h(this,Me,"f")){if([h(this,Me,"f")].concat(g[h(this,Me,"f")]||[]).filter((A)=>A.length>1).includes(""+p._[p._.length-1]))p._.pop(),y=!0}W(this,Nn,!1,"f");let F=h(this,fe,"f").getCommands(),k=((i=h(this,xe,"f"))===null||i===void 0?void 0:i.completionKey)?[(o=h(this,xe,"f"))===null||o===void 0?void 0:o.completionKey,...(c=this.getAliases()[(a=h(this,xe,"f"))===null||a===void 0?void 0:a.completionKey])!==null&&c!==void 0?c:[]].some((L)=>Object.prototype.hasOwnProperty.call(p,L)):!1,S=y||k||s;if(p._.length){if(F.length){let L;for(let A=r||0,R;p._[A]!==void 0;A++)if(R=String(p._[A]),F.includes(R)&&R!==h(this,Ae,"f")){let B=h(this,fe,"f").runCommand(R,this,d,A+1,s,y||C||s);return this[_t](B,f,!!n,!1)}else if(!L&&R!==h(this,Ae,"f")){L=R;break}if(!h(this,fe,"f").hasDefaultCommand()&&h(this,Ln,"f")&&L&&!S)h(this,ce,"f").recommendCommands(L,F)}if(h(this,Ae,"f")&&p._.includes(h(this,Ae,"f"))&&!k){if(h(this,Pe,"f"))rt(!0);this.showCompletionScript(),this.exit(0)}}if(h(this,fe,"f").hasDefaultCommand()&&!S){let L=h(this,fe,"f").runCommand(null,this,d,0,s,y||C||s);return this[_t](L,f,!!n,!1)}if(k){if(h(this,Pe,"f"))rt(!0);e=[].concat(e);let L=e.slice(e.indexOf(`--${h(this,xe,"f").completionKey}`)+1);return h(this,xe,"f").getCompletion(L,(A,R)=>{if(A)throw new le(A.message);(R||[]).forEach((B)=>{h(this,yt,"f").log(B)}),this.exit(0)}),this[_t](p,!f,!!n,!1)}if(!h(this,$e,"f")){if(y){if(h(this,Pe,"f"))rt(!0);u=!0,this.showHelp((L)=>{h(this,yt,"f").log(L),this.exit(0)})}else if(C){if(h(this,Pe,"f"))rt(!0);u=!0,h(this,Y,"f").showVersion("log"),this.exit(0)}}if(!u&&h(this,K,"f").skipValidation.length>0)u=Object.keys(p).some((L)=>h(this,K,"f").skipValidation.indexOf(L)>=0&&p[L]===!0);if(!u){if(d.error)throw new le(d.error.message);if(!k){let L=this[tr](g,{},d.error);if(!n)m=ht(p,this,h(this,Re,"f").getMiddleware(),!0);if(m=this[xo](L,m!==null&&m!==void 0?m:p),se(m)&&!n)m=m.then(()=>ht(p,this,h(this,Re,"f").getMiddleware(),!1))}}}catch(F){if(F instanceof le)h(this,Y,"f").fail(F.message,F);else throw F}return this[_t](m!==null&&m!==void 0?m:p,f,!!n,!0)}[tr](e,t,n,r){let s={...this.getDemandedOptions()};return(i)=>{if(n)throw new le(n.message);h(this,ce,"f").nonOptionCount(i),h(this,ce,"f").requiredArguments(i,s);let o=!1;if(h(this,Ct,"f"))o=h(this,ce,"f").unknownCommands(i);if(h(this,Ft,"f")&&!o)h(this,ce,"f").unknownArguments(i,e,t,!!r);else if(h(this,Et,"f"))h(this,ce,"f").unknownArguments(i,e,{},!1,!1);h(this,ce,"f").limitedChoices(i),h(this,ce,"f").implications(i),h(this,ce,"f").conflicting(i)}}[Ro](){W(this,$e,!0,"f")}[St](e){if(typeof e==="string")h(this,K,"f").key[e]=!0;else for(let t of e)h(this,K,"f").key[t]=!0}}function ro(e){return!!e&&typeof e.getInternalMethods==="function"}var xl=Mo(Ws),No=xl;import{existsSync as Kn,readFileSync as rr,writeFileSync as nr,mkdirSync as Lo}from"node:fs";import{homedir as _l}from"node:os";import{join as kt,dirname as ir}from"node:path";function or(){return process.env.HOME||_l()}function Wo(){return kt(or(),".config","slack-cli","profiles.json")}function Jn(){return kt(process.cwd(),".slack-cli","workspace")}function zn(){return kt(or(),".slack-cli","workspace")}function an(){let e=Wo();if(!Kn(e))return{profiles:{}};return JSON.parse(rr(e,"utf8"))}function Sl(e){let t=Wo();Lo(ir(t),{recursive:!0}),nr(t,JSON.stringify(e,null,2)+`
82
- `)}function zt(e){if(!Kn(e))return;return rr(e,"utf8").trim()||void 0}function vo(e,t){let n=ir(e);Lo(n,{recursive:!0});let r=kt(n,".gitignore");if(!Kn(r))nr(r,`*
83
- `);nr(e,t+`
84
- `)}function kl(e){let t={};for(let n of e.split(`
85
- `)){let r=n.trim();if(!r||r.startsWith("#"))continue;let s=r.indexOf("=");if(s===-1)continue;let i=r.slice(0,s).trim(),o=r.slice(s+1).trim();if(o.startsWith('"')&&o.endsWith('"')||o.startsWith("'")&&o.endsWith("'"))o=o.slice(1,-1);t[i]=o}return t}function jo(e){if(!Kn(e))return{};try{return kl(rr(e,"utf8"))}catch{return{}}}function sr(e,t){let n=or(),r=e;while(!0){for(let o of[kt(r,".slack-term",".env.local"),kt(r,".env.local")]){let a=jo(o);for(let c of t)if(a[c])return a[c]}if(r===n)break;let i=ir(r);if(i===r)break;r=i}let s=jo(kt(n,".slack-term",".env.local"));for(let i of t)if(s[i])return s[i];return}function ar(){let e=an(),t=zt(Jn()),n=zt(zn()),r=t??n;return Object.entries(e.profiles).map(([s,i])=>({name:s,profile:i,current:s===r}))}function Uo(e){let t=an();if(!(e in t.profiles))throw Error(`Profile not found: ${e}`);delete t.profiles[e],Sl(t)}function Ko(e,t=!1){let n=an();if(!(e in n.profiles))throw Error(`Profile not found: ${e}`);if(t)vo(zn(),e);else vo(Jn(),e)}function cr(e){let n=an().profiles,r=Object.keys(n);if(e){let u=n[e];if(!u)throw Error(`Workspace "${e}" not found. Available: ${r.join(", ")||"(none)"}`);return u.token}if(process.env.SLACK_TOKEN)return process.env.SLACK_TOKEN;let s=process.env.SLACK_BOT_TOKEN??process.env.SLACK_MCP_XOXP_TOKEN;if(s&&r.length===0)return s;if(s&&r.length>0){let u=sr(process.cwd(),["SLACK_BOT_TOKEN","SLACK_MCP_XOXP_TOKEN"]);if(s!==u){if(!globalThis.__slackEnvWarnShown)globalThis.__slackEnvWarnShown=!0,console.error(`Warning: SLACK_MCP_XOXP_TOKEN / SLACK_BOT_TOKEN is set but workspace profiles exist — using profiles.
86
- `+" Migrate to SLACK_TOKEN=... or remove from your shell config.")}}let i=sr(process.cwd(),["SLACK_TOKEN"]);if(i)return i;let o=process.env.SLACK_WORKSPACE;if(o){let u=n[o];if(!u)throw Error(`Workspace "${o}" not found. Available: ${r.join(", ")||"(none)"}`);return u.token}let a=zt(Jn());if(a){let u=n[a];if(!u)throw Error(`Workspace "${a}" (from .slack-cli/workspace) not found in profiles.`);return u.token}let c=zt(zn());if(c){let u=n[c];if(!u)throw Error(`Workspace "${c}" (from ~/.slack-cli/workspace) not found in profiles.`);return u.token}if(r.length>0)throw Error(`Workspace not selected (${r.join(", ")} available).
81
+ `,"f");W(this,me,h(this,me,"f")+e.join(" "),"f")}}}[Xs](e){Kt(h(this,K,"f")).forEach((t)=>{if(((r)=>r==="configObjects")(t))return;let n=h(this,K,"f")[t];if(Array.isArray(n)){if(n.includes(e))n.splice(n.indexOf(e),1)}else if(typeof n==="object")delete n[e]}),delete h(this,Y,"f").getDescriptions()[e]}[wo](e,t,n){if(!h(this,Mn,"f")[n])h(this,H,"f").process.emitWarning(e,t),h(this,Mn,"f")[n]=!0}[bo](){h(this,Bn,"f").push({options:h(this,K,"f"),configObjects:h(this,K,"f").configObjects.slice(0),exitProcess:h(this,Pe,"f"),groups:h(this,Ge,"f"),strict:h(this,Et,"f"),strictCommands:h(this,xt,"f"),strictOptions:h(this,_t,"f"),completionCommand:h(this,Ae,"f"),output:h(this,me,"f"),exitError:h(this,it,"f"),hasOutput:h(this,$e,"f"),parsed:this.parsed,parseFn:h(this,Oe,"f"),parseContext:h(this,Ft,"f")}),h(this,Y,"f").freeze(),h(this,ce,"f").freeze(),h(this,fe,"f").freeze(),h(this,Re,"f").freeze()}[Fo](){let e="",t;if(/\b(node|iojs|electron)(\.exe)?$/.test(h(this,H,"f").process.argv()[0]))t=h(this,H,"f").process.argv().slice(1,2);else t=h(this,H,"f").process.argv().slice(0,1);if(e=t.map((n)=>{let r=this[Ro](h(this,yt,"f"),n);return n.match(/^(\/|([a-zA-Z]:)?\\)/)&&r.length<n.length?r:n}).join(" ").trim(),h(this,H,"f").getEnv("_")&&h(this,H,"f").getProcessArgvBin()===h(this,H,"f").getEnv("_"))e=h(this,H,"f").getEnv("_").replace(`${h(this,H,"f").path.dirname(h(this,H,"f").process.execPath())}/`,"");return e}[kt](){return h(this,jn,"f")}[Co](){return h(this,Wn,"f")}[Gs](){if(!h(this,wt,"f"))return;let e=h(this,H,"f").getEnv("LC_ALL")||h(this,H,"f").getEnv("LC_MESSAGES")||h(this,H,"f").getEnv("LANG")||h(this,H,"f").getEnv("LANGUAGE")||"en_US";this.locale(e.replace(/[.:].*/,""))}[Eo](){return this[Vs]().version||"unknown"}[xo](e){let t=e["--"]?e["--"]:e._;for(let n=0,r;(r=t[n])!==void 0;n++)if(h(this,H,"f").Parser.looksLikeNumber(r)&&Number.isSafeInteger(Math.floor(parseFloat(`${r}`))))t[n]=Number(r);return e}[Vs](e){let t=e||"*";if(h(this,zt,"f")[t])return h(this,zt,"f")[t];let n={};try{let r=e||h(this,H,"f").mainFilename;if(h(this,H,"f").path.extname(r))r=h(this,H,"f").path.dirname(r);let s=h(this,H,"f").findUp(r,(i,o)=>{if(o.includes("package.json"))return"package.json";else return});Ce(s,void 0,h(this,H,"f")),n=JSON.parse(h(this,H,"f").readFileSync(s,"utf8"))}catch(r){}return h(this,zt,"f")[t]=n||{},h(this,zt,"f")[t]}[at](e,t){t=[].concat(t),t.forEach((n)=>{n=this[er](n),h(this,K,"f")[e].push(n)})}[Ht](e,t,n,r){this[Qs](e,t,n,r,(s,i,o)=>{h(this,K,"f")[s][i]=o})}[Zs](e,t,n,r){this[Qs](e,t,n,r,(s,i,o)=>{h(this,K,"f")[s][i]=(h(this,K,"f")[s][i]||[]).concat(o)})}[Qs](e,t,n,r,s){if(Array.isArray(n))n.forEach((i)=>{e(i,r)});else if(((i)=>typeof i==="object")(n))for(let i of Kt(n))e(i,n[i]);else s(t,this[er](n),r)}[er](e){if(e==="__proto__")return"___proto___";return e}[tr](e,t){return this[Ht](this[tr].bind(this),"key",e,t),this}[nr](){var e,t,n,r,s,i,o,a,c,u,f,l;let d=h(this,Bn,"f").pop();Ce(d,void 0,h(this,H,"f"));let p;e=this,t=this,n=this,r=this,s=this,i=this,o=this,a=this,c=this,u=this,f=this,l=this,{options:{set value(m){W(e,K,m,"f")}}.value,configObjects:p,exitProcess:{set value(m){W(t,Pe,m,"f")}}.value,groups:{set value(m){W(n,Ge,m,"f")}}.value,output:{set value(m){W(r,me,m,"f")}}.value,exitError:{set value(m){W(s,it,m,"f")}}.value,hasOutput:{set value(m){W(i,$e,m,"f")}}.value,parsed:this.parsed,strict:{set value(m){W(o,Et,m,"f")}}.value,strictCommands:{set value(m){W(a,xt,m,"f")}}.value,strictOptions:{set value(m){W(c,_t,m,"f")}}.value,completionCommand:{set value(m){W(u,Ae,m,"f")}}.value,parseFn:{set value(m){W(f,Oe,m,"f")}}.value,parseContext:{set value(m){W(l,Ft,m,"f")}}.value}=d,h(this,K,"f").configObjects=p,h(this,Y,"f").unfreeze(),h(this,ce,"f").unfreeze(),h(this,fe,"f").unfreeze(),h(this,Re,"f").unfreeze()}[_o](e,t){return Dt(t,(n)=>(e(n),n))}getInternalMethods(){return{getCommandInstance:this[ko].bind(this),getContext:this[So].bind(this),getHasOutput:this[Ao].bind(this),getLoggerInstance:this[$o].bind(this),getParseContext:this[Oo].bind(this),getParserConfiguration:this[kt].bind(this),getUsageConfiguration:this[Co].bind(this),getUsageInstance:this[Io].bind(this),getValidationInstance:this[To].bind(this),hasParseCallback:this[Un].bind(this),isGlobalContext:this[Po].bind(this),postProcess:this[St].bind(this),reset:this[sr].bind(this),runValidation:this[rr].bind(this),runYargsParserAndExecuteCommands:this[on].bind(this),setHasOutput:this[Mo].bind(this)}}[ko](){return h(this,fe,"f")}[So](){return h(this,rn,"f")}[Ao](){return h(this,$e,"f")}[$o](){return h(this,bt,"f")}[Oo](){return h(this,Ft,"f")||{}}[Io](){return h(this,Y,"f")}[To](){return h(this,ce,"f")}[Un](){return!!h(this,Oe,"f")}[Po](){return h(this,Nn,"f")}[St](e,t,n,r){if(n)return e;if(se(e))return e;if(!t)e=this[Do](e);if(this[kt]()["parse-positional-numbers"]||this[kt]()["parse-positional-numbers"]===void 0)e=this[xo](e);if(r)e=mt(e,this,h(this,Re,"f").getMiddleware(),!1);return e}[sr](e={}){W(this,K,h(this,K,"f")||{},"f");let t={};t.local=h(this,K,"f").local||[],t.configObjects=h(this,K,"f").configObjects||[];let n={};t.local.forEach((i)=>{n[i]=!0,(e[i]||[]).forEach((o)=>{n[o]=!0})}),Object.assign(h(this,Ct,"f"),Object.keys(h(this,Ge,"f")).reduce((i,o)=>{let a=h(this,Ge,"f")[o].filter((c)=>!(c in n));if(a.length>0)i[o]=a;return i},{})),W(this,Ge,{},"f");let r=["array","boolean","string","skipValidation","count","normalize","number","hiddenOptions"],s=["narg","key","alias","default","defaultDescription","config","choices","demandedOptions","demandedCommands","deprecatedOptions"];if(r.forEach((i)=>{t[i]=(h(this,K,"f")[i]||[]).filter((o)=>!n[o])}),s.forEach((i)=>{t[i]=st(h(this,K,"f")[i],(o)=>!n[o])}),t.envPrefix=h(this,K,"f").envPrefix,W(this,K,t,"f"),W(this,Y,h(this,Y,"f")?h(this,Y,"f").reset(n):ao(this,h(this,H,"f")),"f"),W(this,ce,h(this,ce,"f")?h(this,ce,"f").reset(n):go(this,h(this,Y,"f"),h(this,H,"f")),"f"),W(this,fe,h(this,fe,"f")?h(this,fe,"f").reset():ro(h(this,Y,"f"),h(this,ce,"f"),h(this,Re,"f"),h(this,H,"f")),"f"),!h(this,xe,"f"))W(this,xe,fo(this,h(this,Y,"f"),h(this,fe,"f"),h(this,H,"f")),"f");return h(this,Re,"f").reset(),W(this,Ae,null,"f"),W(this,me,"","f"),W(this,it,null,"f"),W(this,$e,!1,"f"),this.parsed=!1,this}[Ro](e,t){return h(this,H,"f").path.relative(e,t)}[on](e,t,n,r=0,s=!1){var i,o,a,c;let u=!!n||s;e=e||h(this,ot,"f"),h(this,K,"f").__=h(this,H,"f").y18n.__,h(this,K,"f").configuration=this[kt]();let f=!!h(this,K,"f").configuration["populate--"],l=Object.assign({},h(this,K,"f").configuration,{"populate--":!0}),d=h(this,H,"f").Parser.detailed(e,Object.assign({},h(this,K,"f"),{configuration:{"parse-positional-numbers":!1,...l}})),p=Object.assign(d.argv,h(this,Ft,"f")),m=void 0,g=d.aliases,y=!1,C=!1;if(Object.keys(p).forEach((F)=>{if(F===h(this,Me,"f")&&p[F])y=!0;else if(F===h(this,Ve,"f")&&p[F])C=!0}),p.$0=this.$0,this.parsed=d,r===0)h(this,Y,"f").clearCachedHelpMessage();try{if(this[Gs](),t)return this[St](p,f,!!n,!1);if(h(this,Me,"f")){if([h(this,Me,"f")].concat(g[h(this,Me,"f")]||[]).filter((A)=>A.length>1).includes(""+p._[p._.length-1]))p._.pop(),y=!0}W(this,Nn,!1,"f");let F=h(this,fe,"f").getCommands(),S=((i=h(this,xe,"f"))===null||i===void 0?void 0:i.completionKey)?[(o=h(this,xe,"f"))===null||o===void 0?void 0:o.completionKey,...(c=this.getAliases()[(a=h(this,xe,"f"))===null||a===void 0?void 0:a.completionKey])!==null&&c!==void 0?c:[]].some((L)=>Object.prototype.hasOwnProperty.call(p,L)):!1,k=y||S||s;if(p._.length){if(F.length){let L;for(let A=r||0,R;p._[A]!==void 0;A++)if(R=String(p._[A]),F.includes(R)&&R!==h(this,Ae,"f")){let B=h(this,fe,"f").runCommand(R,this,d,A+1,s,y||C||s);return this[St](B,f,!!n,!1)}else if(!L&&R!==h(this,Ae,"f")){L=R;break}if(!h(this,fe,"f").hasDefaultCommand()&&h(this,Ln,"f")&&L&&!k)h(this,ce,"f").recommendCommands(L,F)}if(h(this,Ae,"f")&&p._.includes(h(this,Ae,"f"))&&!S){if(h(this,Pe,"f"))rt(!0);this.showCompletionScript(),this.exit(0)}}if(h(this,fe,"f").hasDefaultCommand()&&!k){let L=h(this,fe,"f").runCommand(null,this,d,0,s,y||C||s);return this[St](L,f,!!n,!1)}if(S){if(h(this,Pe,"f"))rt(!0);e=[].concat(e);let L=e.slice(e.indexOf(`--${h(this,xe,"f").completionKey}`)+1);return h(this,xe,"f").getCompletion(L,(A,R)=>{if(A)throw new le(A.message);(R||[]).forEach((B)=>{h(this,bt,"f").log(B)}),this.exit(0)}),this[St](p,!f,!!n,!1)}if(!h(this,$e,"f")){if(y){if(h(this,Pe,"f"))rt(!0);u=!0,this.showHelp((L)=>{h(this,bt,"f").log(L),this.exit(0)})}else if(C){if(h(this,Pe,"f"))rt(!0);u=!0,h(this,Y,"f").showVersion("log"),this.exit(0)}}if(!u&&h(this,K,"f").skipValidation.length>0)u=Object.keys(p).some((L)=>h(this,K,"f").skipValidation.indexOf(L)>=0&&p[L]===!0);if(!u){if(d.error)throw new le(d.error.message);if(!S){let L=this[rr](g,{},d.error);if(!n)m=mt(p,this,h(this,Re,"f").getMiddleware(),!0);if(m=this[_o](L,m!==null&&m!==void 0?m:p),se(m)&&!n)m=m.then(()=>mt(p,this,h(this,Re,"f").getMiddleware(),!1))}}}catch(F){if(F instanceof le)h(this,Y,"f").fail(F.message,F);else throw F}return this[St](m!==null&&m!==void 0?m:p,f,!!n,!0)}[rr](e,t,n,r){let s={...this.getDemandedOptions()};return(i)=>{if(n)throw new le(n.message);h(this,ce,"f").nonOptionCount(i),h(this,ce,"f").requiredArguments(i,s);let o=!1;if(h(this,xt,"f"))o=h(this,ce,"f").unknownCommands(i);if(h(this,Et,"f")&&!o)h(this,ce,"f").unknownArguments(i,e,t,!!r);else if(h(this,_t,"f"))h(this,ce,"f").unknownArguments(i,e,{},!1,!1);h(this,ce,"f").limitedChoices(i),h(this,ce,"f").implications(i),h(this,ce,"f").conflicting(i)}}[Mo](){W(this,$e,!0,"f")}[At](e){if(typeof e==="string")h(this,K,"f").key[e]=!0;else for(let t of e)h(this,K,"f").key[t]=!0}}function io(e){return!!e&&typeof e.getInternalMethods==="function"}var Al=Bo(Js),vo=Al;import{existsSync as Kn,readFileSync as ar,writeFileSync as ir,mkdirSync as Wo}from"node:fs";import{homedir as $l}from"node:os";import{join as $t,dirname as cr}from"node:path";function ur(){return process.env.HOME||$l()}function Uo(){return $t(ur(),".config","slack-cli","profiles.json")}function Jn(){return $t(process.cwd(),".slack-cli","workspace")}function zn(){return $t(ur(),".slack-cli","workspace")}function an(){let e=Uo();if(!Kn(e))return{profiles:{}};return JSON.parse(ar(e,"utf8"))}function Ol(e){let t=Uo();Wo(cr(t),{recursive:!0}),ir(t,JSON.stringify(e,null,2)+`
82
+ `)}function qt(e){if(!Kn(e))return;return ar(e,"utf8").trim()||void 0}function jo(e,t){let n=cr(e);Wo(n,{recursive:!0});let r=$t(n,".gitignore");if(!Kn(r))ir(r,`*
83
+ `);ir(e,t+`
84
+ `)}function Il(e){let t={};for(let n of e.split(`
85
+ `)){let r=n.trim();if(!r||r.startsWith("#"))continue;let s=r.indexOf("=");if(s===-1)continue;let i=r.slice(0,s).trim(),o=r.slice(s+1).trim();if(o.startsWith('"')&&o.endsWith('"')||o.startsWith("'")&&o.endsWith("'"))o=o.slice(1,-1);t[i]=o}return t}function Lo(e){if(!Kn(e))return{};try{return Il(ar(e,"utf8"))}catch{return{}}}function or(e,t){let n=ur(),r=e;while(!0){for(let o of[$t(r,".slack-term",".env.local"),$t(r,".env.local")]){let a=Lo(o);for(let c of t)if(a[c])return a[c]}if(r===n)break;let i=cr(r);if(i===r)break;r=i}let s=Lo($t(n,".slack-term",".env.local"));for(let i of t)if(s[i])return s[i];return}function lr(){let e=an(),t=qt(Jn()),n=qt(zn()),r=t??n;return Object.entries(e.profiles).map(([s,i])=>({name:s,profile:i,current:s===r}))}function Ko(e){let t=an();if(!(e in t.profiles))throw Error(`Profile not found: ${e}`);delete t.profiles[e],Ol(t)}function Jo(e,t=!1){let n=an();if(!(e in n.profiles))throw Error(`Profile not found: ${e}`);if(t)jo(zn(),e);else jo(Jn(),e)}function fr(e){let n=an().profiles,r=Object.keys(n);if(e){let u=n[e];if(!u)throw Error(`Workspace "${e}" not found. Available: ${r.join(", ")||"(none)"}`);return u.token}if(process.env.SLACK_TOKEN)return process.env.SLACK_TOKEN;let s=process.env.SLACK_BOT_TOKEN??process.env.SLACK_MCP_XOXP_TOKEN;if(s&&r.length===0)return s;if(s&&r.length>0){let u=or(process.cwd(),["SLACK_BOT_TOKEN","SLACK_MCP_XOXP_TOKEN"]);if(s!==u){if(!globalThis.__slackEnvWarnShown)globalThis.__slackEnvWarnShown=!0,console.error(`Warning: SLACK_MCP_XOXP_TOKEN / SLACK_BOT_TOKEN is set but workspace profiles exist — using profiles.
86
+ `+" Migrate to SLACK_TOKEN=... or remove from your shell config.")}}let i=or(process.cwd(),["SLACK_TOKEN"]);if(i)return i;let o=process.env.SLACK_WORKSPACE;if(o){let u=n[o];if(!u)throw Error(`Workspace "${o}" not found. Available: ${r.join(", ")||"(none)"}`);return u.token}let a=qt(Jn());if(a){let u=n[a];if(!u)throw Error(`Workspace "${a}" (from .slack-cli/workspace) not found in profiles.`);return u.token}let c=qt(zn());if(c){let u=n[c];if(!u)throw Error(`Workspace "${c}" (from ~/.slack-cli/workspace) not found in profiles.`);return u.token}if(r.length>0)throw Error(`Workspace not selected (${r.join(", ")} available).
87
87
  Select locally: slack auth use <name> (writes .slack-cli/workspace)
88
88
  Select globally: slack auth use -g <name> (writes ~/.slack-cli/workspace)`);throw Error(`No Slack token found.
89
89
  Run one of:
90
90
  `+` slack auth token — paste an existing xoxp-/xoxb- token
91
91
  `+` slack auth chrome — import from Chrome browser (macOS)
92
92
  `+` slack auth app — guided Slack app creation
93
- `+" Or set SLACK_TOKEN=xoxp-... in .slack-term/.env.local")}function Ht(){let e=process.env.SLACK_BOT_TOKEN;return e&&e.startsWith("xoxb-")?e:void 0}function Jo(e){let n=an().profiles;if(e)return n[e]?.cookie;if(process.env.SLACK_COOKIE)return process.env.SLACK_COOKIE;if(process.env.SLACK_MCP_XOXD_COOKIE)return process.env.SLACK_MCP_XOXD_COOKIE;if(process.env.SLACK_MCP_XOXP_TOKEN&&Object.keys(n).length===0)return process.env.SLACK_MCP_XOXD_COOKIE;let s=sr(process.cwd(),["SLACK_COOKIE"]);if(s)return s;let i=process.env.SLACK_WORKSPACE;if(i)return n[i]?.cookie;let o=zt(Jn());if(o)return n[o]?.cookie;let a=zt(zn());if(a)return n[a]?.cookie;return}class We extends Error{retryAfter;constructor(e){super(`Slack rate limited — retry after ${e}s`);this.name="RateLimitError",this.retryAfter=e}}function lr(){return(process.env.SLACK_API_BASE??"https://slack.com/api").replace(/\/$/,"")}async function Yo(e,t,n,r){let s={};if(r)s.Cookie=`d=${r}`;let i=await fetch(`${lr()}/${t}`,{...n,headers:{...n.headers??{},Authorization:`Bearer ${e}`,...s}});if(i.status===429){let a=parseInt(i.headers.get("retry-after")??"60",10);throw new We(isNaN(a)?60:a)}let o=await i.json();if(o.ok!==!0){let a=o.error??"unknown";if(a==="ratelimited")throw new We(60);if(a==="invalid_auth"&&e.startsWith("xoxc-")&&!r)throw Error(`Desktop app token (xoxc-) needs its session cookie to be accepted by the public Slack API.
93
+ `+" Or set SLACK_TOKEN=xoxp-... in .slack-term/.env.local")}function Ot(){let e=process.env.SLACK_BOT_TOKEN;return e&&e.startsWith("xoxb-")?e:void 0}function zo(e){let n=an().profiles;if(e)return n[e]?.cookie;if(process.env.SLACK_COOKIE)return process.env.SLACK_COOKIE;if(process.env.SLACK_MCP_XOXD_COOKIE)return process.env.SLACK_MCP_XOXD_COOKIE;if(process.env.SLACK_MCP_XOXP_TOKEN&&Object.keys(n).length===0)return process.env.SLACK_MCP_XOXD_COOKIE;let s=or(process.cwd(),["SLACK_COOKIE"]);if(s)return s;let i=process.env.SLACK_WORKSPACE;if(i)return n[i]?.cookie;let o=qt(Jn());if(o)return n[o]?.cookie;let a=qt(zn());if(a)return n[a]?.cookie;return}class We extends Error{retryAfter;constructor(e){super(`Slack rate limited — retry after ${e}s`);this.name="RateLimitError",this.retryAfter=e}}function pr(){return(process.env.SLACK_API_BASE??"https://slack.com/api").replace(/\/$/,"")}async function Xo(e,t,n,r){let s={};if(r)s.Cookie=`d=${r}`;let i=await fetch(`${pr()}/${t}`,{...n,headers:{...n.headers??{},Authorization:`Bearer ${e}`,...s}});if(i.status===429){let a=parseInt(i.headers.get("retry-after")??"60",10);throw new We(isNaN(a)?60:a)}let o=await i.json();if(o.ok!==!0){let a=o.error??"unknown";if(a==="ratelimited")throw new We(60);if(a==="invalid_auth"&&e.startsWith("xoxc-")&&!r)throw Error(`Desktop app token (xoxc-) needs its session cookie to be accepted by the public Slack API.
94
94
  Attach it: slack auth chrome (macOS) or slack auth firefox
95
95
  Or replace the token with an xoxp- user token:
96
96
  slack auth token`);if((a==="missing_scope"||a==="cannot_dm_bot")&&e.startsWith("xoxb-"))throw Error(`Slack error on ${t}: ${a} — ${a==="cannot_dm_bot"?`you're authenticated as a bot, so "@you" is the bot itself and it can't DM itself`:"this bot token lacks the user scope this action needs"}.
97
97
  Tailing/DMing people and listing users need a user session, not a bot token.
98
98
  Switch workspace: slack auth ls then slack auth use <name>
99
- Or import your Slack desktop session: slack auth login`);throw Error(`Slack error on ${t}: ${a}`)}return o}async function Al(e,t,n,r){let s={};if(r)s.Cookie=`d=${r}`;let i=await fetch(`${lr()}/${t}`,{...n,headers:{...n.headers??{},Authorization:`Bearer ${e}`,...s}});if(i.status===429){let a=parseInt(i.headers.get("retry-after")??"60",10);throw new We(isNaN(a)?60:a)}let o=await i.json();if(o.ok!==!0){let a=o.error??"unknown";if(a==="ratelimited")throw new We(60);if((a==="invalid_auth"||a==="not_authed")&&!e.startsWith("xoxc-"))throw Error(`The draft API requires a desktop app session token (xoxc-).
99
+ Or import your Slack desktop session: slack auth login`);throw Error(`Slack error on ${t}: ${a}`)}return o}async function Tl(e,t,n,r){let s={};if(r)s.Cookie=`d=${r}`;let i=await fetch(`${pr()}/${t}`,{...n,headers:{...n.headers??{},Authorization:`Bearer ${e}`,...s}});if(i.status===429){let a=parseInt(i.headers.get("retry-after")??"60",10);throw new We(isNaN(a)?60:a)}let o=await i.json();if(o.ok!==!0){let a=o.error??"unknown";if(a==="ratelimited")throw new We(60);if((a==="invalid_auth"||a==="not_authed")&&!e.startsWith("xoxc-"))throw Error(`The draft API requires a desktop app session token (xoxc-).
100
100
  Import from Slack desktop: slack auth login`);if((a==="invalid_auth"||a==="not_authed")&&!r)throw Error(`drafts.list also requires the xoxd session cookie.
101
- Attach it with: slack auth chrome (macOS) or slack auth firefox`);throw Error(`Slack error on ${t}: ${a}`)}return o}function $l(e,t,n={},r){let s=new URLSearchParams({token:e,...n});return Al(e,t,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:s.toString()},r)}function we(e,t,n,r){let s=new URLSearchParams(n).toString();return Yo(e,`${t}?${s}`,{method:"GET"},r)}function fr(e,t,n,r){return Yo(e,t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)},r)}async function qt(e,t){let n=await we(e,"auth.test",{},t);return{team:n.team??"",teamId:n.team_id??"",url:n.url??"",user:n.user??"",userId:n.user_id??""}}async function Xo(e,t){let n={Authorization:`Bearer ${e}`};if(t)n.Cookie=`d=${t}`;let r=await fetch(`${lr()}/auth.test`,{method:"GET",headers:n});if(r.status===429){let o=parseInt(r.headers.get("retry-after")??"60",10);throw new We(isNaN(o)?60:o)}let s=r.headers.get("x-oauth-scopes")??"",i=await r.json();if(i.ok!==!0)throw Error(`Slack error on auth.test: ${i.error??"unknown"}`);return{userId:i.user_id??"",user:i.user??"",botId:i.bot_id??"",team:i.team??"",url:i.url??"",scopes:s.split(",").map((o)=>o.trim()).filter(Boolean)}}async function Go(e,t,n){let r=await we(e,"bots.info",{bot:t},n);return{appId:r.bot?.app_id??"",userId:r.bot?.user_id??""}}async function un(e,t,n=20,r,s,i,o){let a={channel:t,limit:String(n)};if(r!==void 0)a.oldest=r;if(s!==void 0)a.cursor=s;if(o)a.inclusive="true";return we(e,"conversations.history",a,i)}async function Vo(e,t,n,r=50,s){return we(e,"conversations.replies",{channel:t,ts:n,limit:String(r)},s)}async function Hn(e,t,n,r,s){await fr(e,"reactions.add",{channel:t,timestamp:n,name:r},s)}async function Zo(e,t,n,r){return((await we(e,"reactions.get",{channel:t,timestamp:n,full:"true"},r)).message?.reactions??[]).map((i)=>({name:String(i.name??""),users:Array.isArray(i.users)?i.users.map(String):[]}))}async function qn(e,t,n,r,s){await fr(e,"reactions.remove",{channel:t,timestamp:n,name:r},s)}async function Ol(e,t,n){let s=(await fr(e,"conversations.open",{users:t},n)).channel?.id;if(!s)throw Error(`Failed to open DM with user ${t}`);return s}async function Qo(e,t,n){let r="";while(!0){let s={types:"im",limit:"200"};if(r)s.cursor=r;let i=await we(e,"conversations.list",s,n);for(let o of i.channels??[])if(o.user===t)return String(o.id??"");if(r=i.response_metadata?.next_cursor??"",!r)break}return""}async function ur(e,t,n,r){let s=await Qo(e,t,n);if(s)return s;let i=r?`${r} (${t})`:t;throw Error(`No existing DM with ${i}. Open it once in Slack first.`)}function cn(e){return e.toLowerCase().replace(/[-_\s]/g,"")}function zo(e,t){let n=cn(e.name??""),r=cn(e.real_name??e.profile?.real_name??""),s=cn(e.profile?.display_name??"");return n===t||r===t||!!s&&s===t}var ea=200;async function Il(e,t,n){let r=0,s=new Set,i="";while(!0){let f={limit:"200"};if(i)f.cursor=i;let l=await we(e,"users.list",f,n);for(let d of l.members??[]){if(r++,d.id)s.add(d.id);if(zo(d,t))return{id:d.id??"",workspaceCount:r,connectCount:0,skipped:0,capped:!1}}if(i=l.response_metadata?.next_cursor??"",!i)break}let o=0,a=0,c=!1,u="";while(!0){let f={types:"im",limit:"200"};if(u)f.cursor=u;let l=await we(e,"conversations.list",f,n);for(let d of l.channels??[]){let p=d.user;if(!p||s.has(p))continue;if(o>=ea){c=!0;break}s.add(p),o++;let m;try{m=(await we(e,"users.info",{user:p},n)).user}catch(g){if(g instanceof We)throw g;a++;continue}if(m&&zo(m,t))return{id:p,dm:String(d.id??""),workspaceCount:r,connectCount:o,skipped:a,capped:c}}if(c)break;if(u=l.response_metadata?.next_cursor??"",!u)break}return{id:"",workspaceCount:r,connectCount:o,skipped:a,capped:c}}function Tl(e,t){if(t.workspaceCount===0)return Error(`Cannot resolve ${e}: users.list returned no members at all, so nothing could have matched.
101
+ Attach it with: slack auth chrome (macOS) or slack auth firefox`);throw Error(`Slack error on ${t}: ${a}`)}return o}function Pl(e,t,n={},r){let s=new URLSearchParams({token:e,...n});return Tl(e,t,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:s.toString()},r)}function we(e,t,n,r){let s=new URLSearchParams(n).toString();return Xo(e,`${t}?${s}`,{method:"GET"},r)}function hr(e,t,n,r){return Xo(e,t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)},r)}async function Yt(e,t){let n=await we(e,"auth.test",{},t);return{team:n.team??"",teamId:n.team_id??"",url:n.url??"",user:n.user??"",userId:n.user_id??""}}async function Go(e,t){let n={Authorization:`Bearer ${e}`};if(t)n.Cookie=`d=${t}`;let r=await fetch(`${pr()}/auth.test`,{method:"GET",headers:n});if(r.status===429){let o=parseInt(r.headers.get("retry-after")??"60",10);throw new We(isNaN(o)?60:o)}let s=r.headers.get("x-oauth-scopes")??"",i=await r.json();if(i.ok!==!0)throw Error(`Slack error on auth.test: ${i.error??"unknown"}`);return{userId:i.user_id??"",user:i.user??"",botId:i.bot_id??"",team:i.team??"",url:i.url??"",scopes:s.split(",").map((o)=>o.trim()).filter(Boolean)}}async function Vo(e,t,n){let r=await we(e,"bots.info",{bot:t},n);return{appId:r.bot?.app_id??"",userId:r.bot?.user_id??""}}async function un(e,t,n=20,r,s,i,o){let a={channel:t,limit:String(n)};if(r!==void 0)a.oldest=r;if(s!==void 0)a.cursor=s;if(o)a.inclusive="true";return we(e,"conversations.history",a,i)}async function Zo(e,t,n,r=50,s){return we(e,"conversations.replies",{channel:t,ts:n,limit:String(r)},s)}async function Hn(e,t,n,r,s){await hr(e,"reactions.add",{channel:t,timestamp:n,name:r},s)}async function Qo(e,t,n,r){return((await we(e,"reactions.get",{channel:t,timestamp:n,full:"true"},r)).message?.reactions??[]).map((i)=>({name:String(i.name??""),users:Array.isArray(i.users)?i.users.map(String):[]}))}async function qn(e,t,n,r,s){await hr(e,"reactions.remove",{channel:t,timestamp:n,name:r},s)}async function Rl(e,t,n){let s=(await hr(e,"conversations.open",{users:t},n)).channel?.id;if(!s)throw Error(`Failed to open DM with user ${t}`);return s}async function ea(e,t,n){let r="";while(!0){let s={types:"im",limit:"200"};if(r)s.cursor=r;let i=await we(e,"conversations.list",s,n);for(let o of i.channels??[])if(o.user===t)return String(o.id??"");if(r=i.response_metadata?.next_cursor??"",!r)break}return""}async function dr(e,t,n,r){let s=await ea(e,t,n);if(s)return s;let i=r?`${r} (${t})`:t;throw Error(`No existing DM with ${i}. Open it once in Slack first.`)}function cn(e){return e.toLowerCase().replace(/[-_\s]/g,"")}function Ho(e,t){let n=cn(e.name??""),r=cn(e.real_name??e.profile?.real_name??""),s=cn(e.profile?.display_name??"");return n===t||r===t||!!s&&s===t}var ta=200;async function Ml(e,t,n){let r=0,s=new Set,i="";while(!0){let f={limit:"200"};if(i)f.cursor=i;let l=await we(e,"users.list",f,n);for(let d of l.members??[]){if(r++,d.id)s.add(d.id);if(Ho(d,t))return{id:d.id??"",workspaceCount:r,connectCount:0,skipped:0,capped:!1}}if(i=l.response_metadata?.next_cursor??"",!i)break}let o=0,a=0,c=!1,u="";while(!0){let f={types:"im",limit:"200"};if(u)f.cursor=u;let l=await we(e,"conversations.list",f,n);for(let d of l.channels??[]){let p=d.user;if(!p||s.has(p))continue;if(o>=ta){c=!0;break}s.add(p),o++;let m;try{m=(await we(e,"users.info",{user:p},n)).user}catch(g){if(g instanceof We)throw g;a++;continue}if(m&&Ho(m,t))return{id:p,dm:String(d.id??""),workspaceCount:r,connectCount:o,skipped:a,capped:c}}if(c)break;if(u=l.response_metadata?.next_cursor??"",!u)break}return{id:"",workspaceCount:r,connectCount:o,skipped:a,capped:c}}function Bl(e,t){if(t.workspaceCount===0)return Error(`Cannot resolve ${e}: users.list returned no members at all, so nothing could have matched.
102
102
  `+`That is a token or scope fault, not a wrong handle — this says nothing about whether ${e} exists.
103
- Check who you are: slack auth ls`);let n=t.connectCount?`${t.workspaceCount} workspace account(s) and ${t.connectCount} Slack Connect DM partner(s)`:`${t.workspaceCount} workspace account(s)`,r=[];if(t.capped)r.push(`stopped after ${ea} Slack Connect DM partners, so there may be more`);if(t.skipped)r.push(`${t.skipped} DM partner profile(s) could not be read and were never compared`);return Error(`User not found: ${e} — searched ${n}, none matched.
103
+ Check who you are: slack auth ls`);let n=t.connectCount?`${t.workspaceCount} workspace account(s) and ${t.connectCount} Slack Connect DM partner(s)`:`${t.workspaceCount} workspace account(s)`,r=[];if(t.capped)r.push(`stopped after ${ta} Slack Connect DM partners, so there may be more`);if(t.skipped)r.push(`${t.skipped} DM partner profile(s) could not be read and were never compared`);return Error(`User not found: ${e} — searched ${n}, none matched.
104
104
  `+(r.length?`This search was incomplete: ${r.join("; ")}.
105
105
  `:"")+`Slack Connect people from another workspace are not in users.list, so if they never
106
106
  DMed you they cannot be found by name at all. Look them up and use their ID:
107
- slack user ls --external`)}function dr(e){let t=e.match(/(?:app\.slack\.com\/client\/T[A-Za-z0-9]+|[A-Za-z0-9-]+\.slack\.com\/archives)\/([A-Za-z0-9]+)(?:\/p(\d{10})(\d{6}))?/);if(!t)return;let n=t[1],r=t[2]&&t[3]?`${t[2]}.${t[3]}`:void 0,s=e.indexOf("?"),i=s>=0?new URLSearchParams(e.slice(s)):void 0,o=i?.get("thread_ts")??void 0,u={channel:i?.get("cid")??void 0??n};if(r)u.ts=r;if(o)u.threadTs=o;return u}function Pl(e){return dr(e)?.channel}function Ho(e){return/^[CDG][A-Z0-9]{8,}$/.test(e)}function qo(e){return/^[UW][A-Z0-9]{6,}$/.test(e)}async function ta(e,t,n){let r=Pl(t);if(r)return r;if(!t.startsWith("@")&&!t.startsWith("#")){if(Ho(t))return t;if(qo(t))return ur(e,t,n);throw Error(`Target must start with # or @ (or be a Slack URL/ID), got: ${t}`)}if(t.startsWith("#")&&Ho(t.slice(1)))return t.slice(1);let s=t.startsWith("@"),i=t.slice(1),o=cn(i);if(s){if(qo(i))return ur(e,i,n);let u=await we(e,"auth.test",{},n);if(o==="you"||o==="me"||cn(u.user??"")===o){let d=u.user_id;if(!d)throw Error("auth.test did not return user_id");return await Qo(e,d,n)||Ol(e,d,n)}let l=await Il(e,o,n);if(!l.id)throw Tl(t,l);if(l.dm)return l.dm;return ur(e,l.id,n,t)}let a=i.toLowerCase(),c="";while(!0){let u={limit:"200",types:"public_channel,private_channel",exclude_archived:"true"};if(c)u.cursor=c;let f=await we(e,"conversations.list",u,n);for(let l of f.channels??[])if(String(l.name??"").toLowerCase()===a)return String(l.id??"");if(c=f.response_metadata?.next_cursor??"",!c)break}throw Error(`channel not found: ${t}`)}async function Yn(e,t,n){try{let r=await we(e,"users.info",{user:t},n),s=r.user?.profile?.display_name,i=s&&s.length>0?s:r.user?.real_name??r.user?.name??t,o=r.user?.name??t;return[i,o]}catch{return[t,t]}}async function Xn(e,t,n){try{let r=await we(e,"users.info",{user:t},n),s=r.user?.profile?.display_name;if(s&&s.length>0)return s;return r.user?.real_name??r.user?.name??t}catch{return t}}async function Gn(e,t){let n=[],r="";while(!0){let s={limit:"200"};if(r)s.cursor=r;let i=await we(e,"users.list",s,t);if(n.push(...i.members??[]),r=i.response_metadata?.next_cursor??"",!r)break}return{members:n}}async function pr(e,t,n){let r=[],s="";while(!0){let i={channel:t,limit:"200"};if(s)i.cursor=s;let o=await we(e,"conversations.members",i,n);if(r.push(...o.members??[]),s=o.response_metadata?.next_cursor??"",!s)break}return r}async function hr(e,t,n){return we(e,"users.info",{user:t},n)}async function na(e,t,n){return we(e,"conversations.info",{channel:t},n)}async function sa(e,t){let n=await $l(e,"client.boot",{},t),r=typeof n.url==="string"?n.url:void 0;if(!r){let i=Object.keys(n).join(", ");throw Error(`client.boot did not return a WebSocket URL. Keys: ${i}`)}let s=n.self&&typeof n.self==="object"&&!Array.isArray(n.self)?n.self:{};return{wsUrl:r,selfId:typeof s.id==="string"?s.id:""}}var Rl=["chat:write","im:write"],Ml=["im:history","im:read"];async function gr(e){let{userId:t,botId:n,team:r,scopes:s}=await Xo(e),i="";if(n)try{i=(await Go(e,n)).appId}catch{i=""}let o=(u)=>s.includes(u),a=Rl.filter((u)=>!o(u)),c=Ml.filter((u)=>!o(u));return{canSend:a.length===0,canReceiveReplies:c.length===0,ok:a.length===0&&c.length===0,botUserId:t,appId:i,team:r,grantedScopes:s,missingSendScopes:a,missingReplyScopes:c}}function ra(e){return["",` Bot user: ${e.botUserId||"(unknown)"}`,` App ID: ${e.appId||"(unknown — bots.info unavailable)"}`,` Granted scopes: ${e.grantedScopes.join(", ")||"(none reported)"}`]}function mr(e,t=!1){let n=e.appId?`https://api.slack.com/apps/${e.appId}`:"https://api.slack.com/apps";if(e.ok){let s=["✓ Bot DM scopes are complete (send + read replies)."," Two-way replies also require the Messages Tab, which is not API-detectable.",' If recipients see "Sending messages to this app is turned off", enable it:',` ${n} → App Home → "Messages Tab" ON + "Allow users to send messages".`];return t?s:[...s,...ra(e)]}let r=[];if(!e.canSend)r.push(`⚠ This bot CANNOT send DMs — missing scope(s): ${e.missingSendScopes.join(", ")}.`);else r.push("⚠ This bot can send DMs, but the user's replies will NOT be readable.");return r.push(" Make escalation DMs two-way:"),r.push(` 1. ${n} → App Home → enable "Messages Tab" and check`),r.push(' "Allow users to send Slash commands and messages".'),r.push(` 2. OAuth & Permissions → add Bot Token Scopes: ${[...e.missingSendScopes,...e.missingReplyScopes].join(", ")}`),r.push(" 3. Reinstall the app to apply the new scopes."),t?r:[...r,...ra(e)]}import{createInterface as $t}from"node:readline/promises";import{join as Er}from"node:path";import{homedir as Yl}from"node:os";import{existsSync as Dr,readFileSync as yr,writeFileSync as oa,mkdirSync as aa}from"node:fs";import{homedir as Bl}from"node:os";import{join as wr,dirname as ca}from"node:path";function ua(){return process.env.HOME||Bl()}function la(){return wr(ua(),".config","slack-cli","profiles.json")}function Nl(){return wr(process.cwd(),".slack-cli","workspace")}function vl(){return wr(ua(),".slack-cli","workspace")}function br(){let e=la();if(!Dr(e))return{profiles:{}};return JSON.parse(yr(e,"utf8"))}function fa(e){let t=la();aa(ca(t),{recursive:!0}),oa(t,JSON.stringify(e,null,2)+`
108
- `)}function ia(e){if(!Dr(e))return;return yr(e,"utf8").trim()||void 0}function da(e,t){aa(ca(e),{recursive:!0});let n=Dr(e)?yr(e,"utf8"):"",r=n?n.split(`
109
- `):[];for(let[s,i]of Object.entries(t)){let o=r.findIndex((c)=>{let u=c.trim();return u.startsWith(s+"=")||u.startsWith(s+" =")}),a=`${s}=${i}`;if(o!==-1)r[o]=a;else r.push(a)}oa(e,r.join(`
107
+ slack user ls --external`)}function gr(e){let t=e.match(/(?:app\.slack\.com\/client\/T[A-Za-z0-9]+|[A-Za-z0-9-]+\.slack\.com\/archives)\/([A-Za-z0-9]+)(?:\/p(\d{10})(\d{6}))?/);if(!t)return;let n=t[1],r=t[2]&&t[3]?`${t[2]}.${t[3]}`:void 0,s=e.indexOf("?"),i=s>=0?new URLSearchParams(e.slice(s)):void 0,o=i?.get("thread_ts")??void 0,u={channel:i?.get("cid")??void 0??n};if(r)u.ts=r;if(o)u.threadTs=o;return u}function Nl(e){return gr(e)?.channel}function qo(e){return/^[CDG][A-Z0-9]{8,}$/.test(e)}function Yo(e){return/^[UW][A-Z0-9]{6,}$/.test(e)}async function na(e,t,n){let r=Nl(t);if(r)return r;if(!t.startsWith("@")&&!t.startsWith("#")){if(qo(t))return t;if(Yo(t))return dr(e,t,n);throw Error(`Target must start with # or @ (or be a Slack URL/ID), got: ${t}`)}if(t.startsWith("#")&&qo(t.slice(1)))return t.slice(1);let s=t.startsWith("@"),i=t.slice(1),o=cn(i);if(s){if(Yo(i))return dr(e,i,n);let u=await we(e,"auth.test",{},n);if(o==="you"||o==="me"||cn(u.user??"")===o){let d=u.user_id;if(!d)throw Error("auth.test did not return user_id");return await ea(e,d,n)||Rl(e,d,n)}let l=await Ml(e,o,n);if(!l.id)throw Bl(t,l);if(l.dm)return l.dm;return dr(e,l.id,n,t)}let a=i.toLowerCase(),c="";while(!0){let u={limit:"200",types:"public_channel,private_channel",exclude_archived:"true"};if(c)u.cursor=c;let f=await we(e,"conversations.list",u,n);for(let l of f.channels??[])if(String(l.name??"").toLowerCase()===a)return String(l.id??"");if(c=f.response_metadata?.next_cursor??"",!c)break}throw Error(`channel not found: ${t}`)}async function Yn(e,t,n){try{let r=await we(e,"users.info",{user:t},n),s=r.user?.profile?.display_name,i=s&&s.length>0?s:r.user?.real_name??r.user?.name??t,o=r.user?.name??t;return[i,o]}catch{return[t,t]}}async function Xn(e,t,n){try{let r=await we(e,"users.info",{user:t},n),s=r.user?.profile?.display_name;if(s&&s.length>0)return s;return r.user?.real_name??r.user?.name??t}catch{return t}}async function Gn(e,t){let n=[],r="";while(!0){let s={limit:"200"};if(r)s.cursor=r;let i=await we(e,"users.list",s,t);if(n.push(...i.members??[]),r=i.response_metadata?.next_cursor??"",!r)break}return{members:n}}async function mr(e,t,n){let r=[],s="";while(!0){let i={channel:t,limit:"200"};if(s)i.cursor=s;let o=await we(e,"conversations.members",i,n);if(r.push(...o.members??[]),s=o.response_metadata?.next_cursor??"",!s)break}return r}async function Dr(e,t,n){return we(e,"users.info",{user:t},n)}async function sa(e,t,n){return we(e,"conversations.info",{channel:t},n)}async function ra(e,t){let n=await Pl(e,"client.boot",{},t),r=typeof n.url==="string"?n.url:void 0;if(!r){let i=Object.keys(n).join(", ");throw Error(`client.boot did not return a WebSocket URL. Keys: ${i}`)}let s=n.self&&typeof n.self==="object"&&!Array.isArray(n.self)?n.self:{};return{wsUrl:r,selfId:typeof s.id==="string"?s.id:""}}var vl=["chat:write","im:write"],jl=["im:history","im:read"];async function Vn(e){let{userId:t,botId:n,team:r,scopes:s}=await Go(e),i="";if(n)try{i=(await Vo(e,n)).appId}catch{i=""}let o=(u)=>s.includes(u),a=vl.filter((u)=>!o(u)),c=jl.filter((u)=>!o(u));return{canSend:a.length===0,canReceiveReplies:c.length===0,ok:a.length===0&&c.length===0,botUserId:t,appId:i,team:r,grantedScopes:s,missingSendScopes:a,missingReplyScopes:c}}function ia(e){return["",` Bot user: ${e.botUserId||"(unknown)"}`,` App ID: ${e.appId||"(unknown — bots.info unavailable)"}`,` Granted scopes: ${e.grantedScopes.join(", ")||"(none reported)"}`]}function Zn(e,t=!1){let n=e.appId?`https://api.slack.com/apps/${e.appId}`:"https://api.slack.com/apps";if(e.ok){let s=["✓ Bot DM scopes are complete (send + read replies)."," Two-way replies also require the Messages Tab, which is not API-detectable.",' If recipients see "Sending messages to this app is turned off", enable it:',` ${n} → App Home → "Messages Tab" ON + "Allow users to send messages".`];return t?s:[...s,...ia(e)]}let r=[];if(!e.canSend)r.push(`⚠ This bot CANNOT send DMs — missing scope(s): ${e.missingSendScopes.join(", ")}.`);else r.push("⚠ This bot can send DMs, but the user's replies will NOT be readable.");return r.push(" Make escalation DMs two-way:"),r.push(` 1. ${n} → App Home → enable "Messages Tab" and check`),r.push(' "Allow users to send Slash commands and messages".'),r.push(` 2. OAuth & Permissions → add Bot Token Scopes: ${[...e.missingSendScopes,...e.missingReplyScopes].join(", ")}`),r.push(" 3. Reinstall the app to apply the new scopes."),t?r:[...r,...ia(e)]}import{createInterface as Tt}from"node:readline/promises";import{join as xr}from"node:path";import{homedir as Zl}from"node:os";import{existsSync as yr,readFileSync as wr,writeFileSync as aa,mkdirSync as ca}from"node:fs";import{homedir as Ll}from"node:os";import{join as br,dirname as ua}from"node:path";function la(){return process.env.HOME||Ll()}function fa(){return br(la(),".config","slack-cli","profiles.json")}function Wl(){return br(process.cwd(),".slack-cli","workspace")}function Ul(){return br(la(),".slack-cli","workspace")}function Fr(){let e=fa();if(!yr(e))return{profiles:{}};return JSON.parse(wr(e,"utf8"))}function da(e){let t=fa();ca(ua(t),{recursive:!0}),aa(t,JSON.stringify(e,null,2)+`
108
+ `)}function oa(e){if(!yr(e))return;return wr(e,"utf8").trim()||void 0}function pa(e,t){ca(ua(e),{recursive:!0});let n=yr(e)?wr(e,"utf8"):"",r=n?n.split(`
109
+ `):[];for(let[s,i]of Object.entries(t)){let o=r.findIndex((c)=>{let u=c.trim();return u.startsWith(s+"=")||u.startsWith(s+" =")}),a=`${s}=${i}`;if(o!==-1)r[o]=a;else r.push(a)}aa(e,r.join(`
110
110
  `).trimEnd()+`
111
- `)}function Vn(){let e=br(),t=ia(Nl()),n=ia(vl()),r=t??n;return Object.entries(e.profiles).map(([s,i])=>({name:s,profile:i,current:s===r}))}function Fr(e,t){let n=br();n.profiles[e]=t,fa(n)}function Cr(e,t){let n=br();if(!(e in n.profiles))throw Error(`Profile not found: ${e}`);n.profiles[e].cookie=t,fa(n)}import{readdirSync as Zn,readFileSync as ln,existsSync as At,copyFileSync as pa,unlinkSync as ha}from"node:fs";import{homedir as Qn,tmpdir as ga}from"node:os";import{join as he,dirname as jl}from"node:path";import{pbkdf2Sync as ma,createDecipheriv as Da}from"node:crypto";import{execSync as ya}from"node:child_process";function Ll(){let e=Qn();if(process.platform==="darwin")return he(e,"Library","Application Support","Slack","Local Storage","leveldb");if(process.platform==="linux")return he(e,".config","Slack","Local Storage","leveldb");if(process.platform==="win32"){let t=process.env.APPDATA??he(e,"AppData","Roaming");return he(t,"Slack","Local Storage","leveldb")}throw Error(`Unsupported platform: ${process.platform}`)}function Wl(){let e=Qn();if(process.platform==="darwin")return he(e,"Library","Application Support","Slack","Cookies");return""}function Ul(e,t){if(e.length<35||e.slice(0,3).toString()!=="v10")throw Error("Not a v10 encrypted cookie");let n=e.slice(19,35),r=e.slice(35),s=Da("aes-128-cbc",t,n);return s.setAutoPadding(!0),Buffer.concat([s.update(r),s.final()]).toString("utf8")}function Kl(){if(process.platform!=="darwin")return;let e=Wl();if(!At(e))return;let t;try{t=ya('security find-generic-password -w -s "Slack Safe Storage" -a "Slack Key"',{encoding:"utf8",stdio:["ignore","pipe","ignore"]}).trimEnd()}catch{return}let n=ma(t,"saltysalt",1003,16,"sha1");try{let{default:r}=Xe("bun:sqlite"),s=new r(e,{readonly:!0}),i=s.prepare("SELECT encrypted_value FROM cookies WHERE name='d' AND host_key LIKE '%slack%'").get();if(s.close(),!i)return;return Ul(Buffer.from(i.encrypted_value),n)}catch{return}}async function wa(){let e=Ll();if(!At(e))throw Error(`Slack desktop app LevelDB not found at:
111
+ `)}function Qn(){let e=Fr(),t=oa(Wl()),n=oa(Ul()),r=t??n;return Object.entries(e.profiles).map(([s,i])=>({name:s,profile:i,current:s===r}))}function Cr(e,t){let n=Fr();n.profiles[e]=t,da(n)}function Er(e,t){let n=Fr();if(!(e in n.profiles))throw Error(`Profile not found: ${e}`);n.profiles[e].cookie=t,da(n)}import{readdirSync as es,readFileSync as ln,existsSync as It,copyFileSync as ha,unlinkSync as ga}from"node:fs";import{homedir as ts,tmpdir as ma}from"node:os";import{join as he,dirname as Kl}from"node:path";import{pbkdf2Sync as Da,createDecipheriv as ya}from"node:crypto";import{execSync as wa}from"node:child_process";function Jl(){let e=ts();if(process.platform==="darwin")return he(e,"Library","Application Support","Slack","Local Storage","leveldb");if(process.platform==="linux")return he(e,".config","Slack","Local Storage","leveldb");if(process.platform==="win32"){let t=process.env.APPDATA??he(e,"AppData","Roaming");return he(t,"Slack","Local Storage","leveldb")}throw Error(`Unsupported platform: ${process.platform}`)}function zl(){let e=ts();if(process.platform==="darwin")return he(e,"Library","Application Support","Slack","Cookies");return""}function Hl(e,t){if(e.length<35||e.slice(0,3).toString()!=="v10")throw Error("Not a v10 encrypted cookie");let n=e.slice(19,35),r=e.slice(35),s=ya("aes-128-cbc",t,n);return s.setAutoPadding(!0),Buffer.concat([s.update(r),s.final()]).toString("utf8")}function ql(){if(process.platform!=="darwin")return;let e=zl();if(!It(e))return;let t;try{t=wa('security find-generic-password -w -s "Slack Safe Storage" -a "Slack Key"',{encoding:"utf8",stdio:["ignore","pipe","ignore"]}).trimEnd()}catch{return}let n=Da(t,"saltysalt",1003,16,"sha1");try{let{default:r}=Xe("bun:sqlite"),s=new r(e,{readonly:!0}),i=s.prepare("SELECT encrypted_value FROM cookies WHERE name='d' AND host_key LIKE '%slack%'").get();if(s.close(),!i)return;return Hl(Buffer.from(i.encrypted_value),n)}catch{return}}async function ba(){let e=Jl();if(!It(e))throw Error(`Slack desktop app LevelDB not found at:
112
112
  ${e}
113
- Is Slack installed and opened at least once?`);let t=Zn(e).filter((a)=>a.endsWith(".ldb")||a.endsWith(".log"));if(t.length===0)throw Error(`No LevelDB data files found in ${e}`);let n=new Map;for(let a of t){let c;try{c=ln(he(e,a),"latin1")}catch{continue}if(a.endsWith(".log"))for(let u of c.matchAll(/"token":"(xoxc-[^"]+)"/g)){let f=u[1],l=f.split("-")[1]??"";if(!l||f.length<40)continue;let d=Math.max(0,u.index-2000),p=Math.min(c.length,u.index+2000),m=c.slice(d,p),g=m.match(/"url":"(https:\/\/[a-z0-9-]+\.slack\.com\/)"/),y=m.match(/"(?:team_name|name)":"([^"]{2,60})"/),C=n.get(l);if(!C||f.length>C.token.length){let F={token:f,teamId:l},k=g?.[1]??C?.url,S=y?.[1]??C?.teamName;if(k)F.url=k;if(S)F.teamName=S;n.set(l,F)}}else for(let u of c.matchAll(/xoxc-(\d+)-(\d+)-(\d+)/g)){let f=u[1];if(n.has(f))continue;let l=u.index+u[0].length,d=Math.min(l+10,c.length);while(l<d&&(c.charCodeAt(l)<48||c.charCodeAt(l)>57))l++;let p="";while(l<c.length&&c.charCodeAt(l)>=48&&c.charCodeAt(l)<=57)p+=c[l++];if(c[l]!=="-")continue;l++;let m="";while(l<c.length){let y=c.charCodeAt(l);if(y>=48&&y<=57||y>=97&&y<=102)m+=c[l++];else break}if(m.length<20)continue;let g=`${u[0]}${p}-${m}`;n.set(f,{token:g,teamId:f})}}let s=Zn(e).filter((a)=>a.endsWith(".ldb")||a.endsWith(".log")).map((a)=>{try{return ln(he(e,a),"latin1").replace(/[^\x20-\x7e]/g," ")}catch{return""}}).join(" ");for(let a of n.values()){if(a.teamName)continue;let c=s.indexOf(a.teamId);if(c!==-1){let u=Math.max(0,c-500),f=Math.min(s.length,c+500),d=s.slice(u,f).match(/"(?:team_name|name)":"([^"]{2,60})"/);if(d?.[1]){a.teamName=d[1];continue}}if(!a.teamName&&a.url){let u=a.url.match(/https:\/\/([a-z0-9-]+)\.slack\.com\//)?.[1];if(u){let f=s.indexOf(u);if(f!==-1){let l=Math.max(0,f-500),d=Math.min(s.length,f+500),m=s.slice(l,d).match(/"(?:team_name|name)":"([^"]{2,60})"/);if(m?.[1]){a.teamName=m[1];continue}}a.teamName=u.split("-").map((l)=>l.charAt(0).toUpperCase()+l.slice(1)).join(" ")}}}let i=Kl(),o=[...n.values()];if(i)for(let a of o)a.cookie=i;return o}function Jl(e,t){let n=(r,s)=>{try{let i=Da("aes-128-cbc",t,r);i.setAutoPadding(!0);let o=Buffer.concat([i.update(s),i.final()]).toString("utf8");return o.startsWith("xoxd-")?o:void 0}catch{return}};return n(Buffer.alloc(16,32),e.slice(3))??(e.length>=35?n(e.slice(19,35),e.slice(35)):void 0)}function zl(e,t){let n=(r,s)=>{if(r&&s)return`${r} (${s})`;return r||s||t};try{let s=JSON.parse(ln(he(e,"Local State"),"utf8")).profile?.info_cache?.[t];if(s&&(s.name||s.user_name))return n(s.name??"",s.user_name??"")}catch{}try{let s=JSON.parse(ln(he(e,t,"Preferences"),"utf8")).profile;return n(s?.name??"",s?.user_name??"")}catch{return t}}function ba(){if(process.platform!=="darwin")return{candidates:[],totalProfiles:0};let e=he(Qn(),"Library","Application Support","Google","Chrome");if(!At(e))return{candidates:[],totalProfiles:0};let t;try{t=ya('security find-generic-password -a Chrome -s "Chrome Safe Storage" -w',{encoding:"utf8",stdio:["ignore","pipe","ignore"]}).trimEnd()}catch{return{candidates:[],totalProfiles:0}}if(!t)return{candidates:[],totalProfiles:0};let n=ma(t,"saltysalt",1003,16,"sha1"),r=["Default",...Zn(e).filter((i)=>i.startsWith("Profile "))],s=[];for(let i of r){let o=he(e,i,"Cookies");if(!At(o))continue;let a=he(ga(),`slack-chrome-cookies-${Date.now()}-${i}.db`);try{pa(o,a);let{default:c}=Xe("bun:sqlite"),u=new c(a,{readonly:!0}),f=u.prepare("SELECT encrypted_value FROM cookies WHERE name='d' AND host_key LIKE '%slack%'").get();if(u.close(),!f)continue;let l=Buffer.from(f.encrypted_value),d=l.slice(0,3).toString();if(d==="v10"){let p=Jl(l,n);if(!p)continue;s.push({profileDir:i,profileName:zl(e,i),cookie:p})}else if(d==="v20")throw Error(`Chrome cookie uses v20 (app-bound AES-256-GCM) which is not supported yet. Prefix found: ${l.slice(0,4).toString("hex")}`);else throw Error(`Unknown cookie encryption prefix: ${l.slice(0,4).toString("hex")}`)}catch(c){if(c instanceof Error&&(c.message.includes("app-bound")||c.message.includes("Unknown cookie")))throw c}finally{try{ha(a)}catch{}}}return{candidates:s,totalProfiles:r.length}}function Hl(){let e=Qn();if(process.platform==="darwin")return he(e,"Library","Application Support","Firefox","Profiles");if(process.platform==="linux")return he(e,".mozilla","firefox");if(process.platform==="win32")return he(process.env.APPDATA??he(e,"AppData","Roaming"),"Mozilla","Firefox","Profiles");return""}function ql(e){let t=he(jl(e),"profiles.ini"),n={};if(!At(t))return n;try{let r=ln(t,"utf8"),s="",i="";for(let o of r.split(`
114
- `)){let a=o.trim();if(a.startsWith("[")){s="",i="";continue}let c=a.indexOf("=");if(c===-1)continue;let u=a.slice(0,c).trim().toLowerCase(),f=a.slice(c+1).trim();if(u==="name")s=f;if(u==="path")i=f.split(/[\\/]/).pop()??f;if(s&&i)n[i]=s,s="",i=""}}catch{}return n}function Fa(){let e=Hl();if(!e||!At(e))return[];let t=ql(e),n=[],r;try{r=Zn(e)}catch{return[]}for(let s of r){let i=he(e,s,"cookies.sqlite");if(!At(i))continue;let o=he(ga(),`slack-firefox-cookies-${Date.now()}-${s}.db`);try{pa(i,o);let{default:a}=Xe("bun:sqlite"),c=new a(o,{readonly:!0}),u=c.prepare("SELECT value FROM moz_cookies WHERE name='d' AND host LIKE '%slack%' LIMIT 1").get();if(c.close(),!u?.value||!u.value.startsWith("xoxd-"))continue;let f=t[s]??s;n.push({profileDir:s,profileName:f,cookie:u.value})}catch{}finally{try{ha(o)}catch{}}}return n}var Xl=["search:read","channels:history","groups:history","im:history","mpim:history","channels:read","groups:read","im:read","mpim:read","users:read","chat:write","files:write"],Gl=["channels:history","groups:history","im:history","mpim:history","channels:read","groups:read","im:read","mpim:read","users:read","chat:write","files:write"];function es(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")}function Vl(){return JSON.stringify({display_information:{name:"slack-term"},oauth_config:{scopes:{user:Xl}},settings:{org_deploy_enabled:!1,socket_mode_enabled:!1,token_rotation_enabled:!1}},null,2)}function Zl(){return JSON.stringify({display_information:{name:"slack-term"},features:{bot_user:{display_name:"slack-term",always_online:!1}},oauth_config:{scopes:{bot:Gl}},settings:{org_deploy_enabled:!1,socket_mode_enabled:!1,token_rotation_enabled:!1}},null,2)}async function Ot(e,t){return(await e.question(t)).trim()}async function It(e,t,n,r){console.error("Verifying token...");let s=await qt(t),i=es(s.team),o;if(n)o=n;else if(e)o=await Ot(e,`Workspace name [${i}]: `)||i;else o=i;let a=null;if(e){console.log(""),console.log("Where to save the token?"),console.log(" 1) ./.env.local (current directory) [default]"),console.log(" 2) ./.slack-term/.env.local (current directory, slack-specific)"),console.log(" 3) ~/.slack-term/.env.local (global, available everywhere)"),console.log(" 4) profiles.json (multi-workspace: slack auth use)"),console.log("");let c=await Ot(e,"Choice [1/2/3/4, Enter=1]: ");if(c==="2")a=Er(process.cwd(),".slack-term",".env.local");else if(c==="3")a=Er(Yl(),".slack-term",".env.local");else if(c==="4")a=null;else a=Er(process.cwd(),".env.local")}if(a===null)if(Fr(o,{token:t,...s,...r?{cookie:r}:{}}),console.log(`Saved workspace "${o}" to profiles.json: ${s.team} (${s.user})`),process.env.SLACK_MCP_XOXP_TOKEN)console.log(""),console.log("Warning: SLACK_MCP_XOXP_TOKEN is set — it conflicts with profiles."),console.log(" Unset it: unset SLACK_MCP_XOXP_TOKEN (and remove from ~/.zshrc / ~/.bashrc)");else console.log(` Run: slack auth use -g ${o}`);else{let c={SLACK_TOKEN:t};if(r)c.SLACK_COOKIE=r;da(a,c),console.log(`Saved token to ${a}`),console.log(" SLACK_TOKEN will be picked up automatically in this directory tree.")}return o}async function Ql(e){console.error("Scanning Slack desktop app...");let t=await wa();if(t.length===0)console.error("No sessions found. Make sure Slack is installed and you have signed in at least once."),process.exit(1);if(t.length===1&&e){let n=t[0],r=n.teamName??n.teamId;console.log(`Found workspace: ${r}${n.cookie?" (+ xoxd cookie)":""}`),await It(e,n.token,es(r),n.cookie),console.log(""),console.log("Note: desktop app tokens (xoxc-) are internal Slack tokens."),console.log("If API calls fail, replace with an xoxp- token: slack auth login");return}for(let n of t){let r=n.teamName??n.teamId,s=es(r);Fr(s,{token:n.token,team:r,teamId:n.teamId,url:n.url??"",user:"",...n.cookie?{cookie:n.cookie}:{}}),console.log(`Added workspace "${s}": ${r}${n.cookie?" + xoxd cookie":""}`)}if(console.log(""),t.length===1){let n=es(t[0].teamName??t[0].teamId);console.log(`Run: slack auth use -g ${n}`)}else console.log("Run: slack auth ls then: slack auth use -g <name>");console.log(""),console.log("Note: desktop app tokens (xoxc-) are internal Slack tokens."),console.log("If API calls fail, replace with an xoxp- user token by re-running: slack auth login")}async function Ca(e){console.log("Which token type does your app use?"),console.log(""),console.log(" 1) User token (xoxp-) -full access including search [recommended]"),console.log(" 2) Bot token (xoxb-) -search and news unavailable"),console.log("");let n=await Ot(e,"Choice [1/2]: ")==="2"?"bot":"user",r=n==="user"?"xoxp-":"xoxb-",s=n==="user"?"User OAuth Token":"Bot User OAuth Token";console.log(""),console.log("Find your token here:"),console.log(" https://api.slack.com/apps"),console.log(" -> Select your app -> OAuth & Permissions"),console.log(` -> Copy the "${s}" (starts with ${r})`),console.log("");let i=await Ot(e,"Paste your token: ");if(!i)console.error("No token provided."),process.exit(1);if(!i.startsWith(r))console.error(`Expected a ${r} token, got: ${i.slice(0,10)}...`),process.exit(1);await It(e,i)}async function ts(e,t){let n=t==="user"?Vl():Zl(),r=t==="user"?"User OAuth Token (xoxp-...)":"Bot User OAuth Token (xoxb-...)",s=t==="user"?"xoxp-":"xoxb-";if(t==="bot")console.log("Note: bot tokens cannot use search:read (user-only scope)."),console.log(" The news and search commands will not work with a bot token."),console.log("");console.log("Step 1 -Create your Slack app:"),console.log(" Open: https://api.slack.com/apps"),console.log(' Click "Create New App" -> "From a manifest" -> select your workspace'),console.log(" Paste this manifest (JSON tab):"),console.log(""),console.log("-------------------------------------------------------------"),console.log(n),console.log("-------------------------------------------------------------"),console.log(""),console.log('Step 2 -Install: "Install App" -> "Install to Workspace" -> Authorize'),console.log(""),console.log("Step 3 -Copy your token:"),console.log(` OAuth & Permissions -> ${r}`),console.log("");let i=await Ot(e,"Paste your token: ");if(!i)console.error("No token provided."),process.exit(1);if(!i.startsWith(s))console.error(`Expected a ${s} token, got: ${i.slice(0,10)}...`),process.exit(1);await It(e,i)}async function Ea(e={}){if(process.platform!=="darwin")console.error("Chrome cookie extraction is only supported on macOS."),process.exit(1);let t=Vn();if(t.length===0)console.error("No workspaces configured. Run: slack auth login"),process.exit(1);let n;if(e.workspace){if(!t.find((c)=>c.name===e.workspace))console.error(`Workspace "${e.workspace}" not found. Available: ${t.map((c)=>c.name).join(", ")}`),process.exit(1);n=e.workspace}else if(t.length===1)n=t[0].name;else{let a=t.find((c)=>c.current);if(a)n=a.name,console.log(`Using active workspace: ${n}`);else{console.log("Multiple workspaces found. Choose one:"),t.forEach((l,d)=>console.log(` ${d+1}) ${l.name} (${l.profile.team})`));let c=$t({input:process.stdin,output:process.stdout}),u=(await c.question("Choice: ")).trim();c.close();let f=parseInt(u,10)-1;if(isNaN(f)||f<0||f>=t.length)console.error("Invalid choice."),process.exit(1);n=t[f].name}}if(t.find((a)=>a.name===n).profile.token.startsWith("xoxb-")){console.error(`
113
+ Is Slack installed and opened at least once?`);let t=es(e).filter((a)=>a.endsWith(".ldb")||a.endsWith(".log"));if(t.length===0)throw Error(`No LevelDB data files found in ${e}`);let n=new Map;for(let a of t){let c;try{c=ln(he(e,a),"latin1")}catch{continue}if(a.endsWith(".log"))for(let u of c.matchAll(/"token":"(xoxc-[^"]+)"/g)){let f=u[1],l=f.split("-")[1]??"";if(!l||f.length<40)continue;let d=Math.max(0,u.index-2000),p=Math.min(c.length,u.index+2000),m=c.slice(d,p),g=m.match(/"url":"(https:\/\/[a-z0-9-]+\.slack\.com\/)"/),y=m.match(/"(?:team_name|name)":"([^"]{2,60})"/),C=n.get(l);if(!C||f.length>C.token.length){let F={token:f,teamId:l},S=g?.[1]??C?.url,k=y?.[1]??C?.teamName;if(S)F.url=S;if(k)F.teamName=k;n.set(l,F)}}else for(let u of c.matchAll(/xoxc-(\d+)-(\d+)-(\d+)/g)){let f=u[1];if(n.has(f))continue;let l=u.index+u[0].length,d=Math.min(l+10,c.length);while(l<d&&(c.charCodeAt(l)<48||c.charCodeAt(l)>57))l++;let p="";while(l<c.length&&c.charCodeAt(l)>=48&&c.charCodeAt(l)<=57)p+=c[l++];if(c[l]!=="-")continue;l++;let m="";while(l<c.length){let y=c.charCodeAt(l);if(y>=48&&y<=57||y>=97&&y<=102)m+=c[l++];else break}if(m.length<20)continue;let g=`${u[0]}${p}-${m}`;n.set(f,{token:g,teamId:f})}}let s=es(e).filter((a)=>a.endsWith(".ldb")||a.endsWith(".log")).map((a)=>{try{return ln(he(e,a),"latin1").replace(/[^\x20-\x7e]/g," ")}catch{return""}}).join(" ");for(let a of n.values()){if(a.teamName)continue;let c=s.indexOf(a.teamId);if(c!==-1){let u=Math.max(0,c-500),f=Math.min(s.length,c+500),d=s.slice(u,f).match(/"(?:team_name|name)":"([^"]{2,60})"/);if(d?.[1]){a.teamName=d[1];continue}}if(!a.teamName&&a.url){let u=a.url.match(/https:\/\/([a-z0-9-]+)\.slack\.com\//)?.[1];if(u){let f=s.indexOf(u);if(f!==-1){let l=Math.max(0,f-500),d=Math.min(s.length,f+500),m=s.slice(l,d).match(/"(?:team_name|name)":"([^"]{2,60})"/);if(m?.[1]){a.teamName=m[1];continue}}a.teamName=u.split("-").map((l)=>l.charAt(0).toUpperCase()+l.slice(1)).join(" ")}}}let i=ql(),o=[...n.values()];if(i)for(let a of o)a.cookie=i;return o}function Yl(e,t){let n=(r,s)=>{try{let i=ya("aes-128-cbc",t,r);i.setAutoPadding(!0);let o=Buffer.concat([i.update(s),i.final()]).toString("utf8");return o.startsWith("xoxd-")?o:void 0}catch{return}};return n(Buffer.alloc(16,32),e.slice(3))??(e.length>=35?n(e.slice(19,35),e.slice(35)):void 0)}function Xl(e,t){let n=(r,s)=>{if(r&&s)return`${r} (${s})`;return r||s||t};try{let s=JSON.parse(ln(he(e,"Local State"),"utf8")).profile?.info_cache?.[t];if(s&&(s.name||s.user_name))return n(s.name??"",s.user_name??"")}catch{}try{let s=JSON.parse(ln(he(e,t,"Preferences"),"utf8")).profile;return n(s?.name??"",s?.user_name??"")}catch{return t}}function Fa(){if(process.platform!=="darwin")return{candidates:[],totalProfiles:0};let e=he(ts(),"Library","Application Support","Google","Chrome");if(!It(e))return{candidates:[],totalProfiles:0};let t;try{t=wa('security find-generic-password -a Chrome -s "Chrome Safe Storage" -w',{encoding:"utf8",stdio:["ignore","pipe","ignore"]}).trimEnd()}catch{return{candidates:[],totalProfiles:0}}if(!t)return{candidates:[],totalProfiles:0};let n=Da(t,"saltysalt",1003,16,"sha1"),r=["Default",...es(e).filter((i)=>i.startsWith("Profile "))],s=[];for(let i of r){let o=he(e,i,"Cookies");if(!It(o))continue;let a=he(ma(),`slack-chrome-cookies-${Date.now()}-${i}.db`);try{ha(o,a);let{default:c}=Xe("bun:sqlite"),u=new c(a,{readonly:!0}),f=u.prepare("SELECT encrypted_value FROM cookies WHERE name='d' AND host_key LIKE '%slack%'").get();if(u.close(),!f)continue;let l=Buffer.from(f.encrypted_value),d=l.slice(0,3).toString();if(d==="v10"){let p=Yl(l,n);if(!p)continue;s.push({profileDir:i,profileName:Xl(e,i),cookie:p})}else if(d==="v20")throw Error(`Chrome cookie uses v20 (app-bound AES-256-GCM) which is not supported yet. Prefix found: ${l.slice(0,4).toString("hex")}`);else throw Error(`Unknown cookie encryption prefix: ${l.slice(0,4).toString("hex")}`)}catch(c){if(c instanceof Error&&(c.message.includes("app-bound")||c.message.includes("Unknown cookie")))throw c}finally{try{ga(a)}catch{}}}return{candidates:s,totalProfiles:r.length}}function Gl(){let e=ts();if(process.platform==="darwin")return he(e,"Library","Application Support","Firefox","Profiles");if(process.platform==="linux")return he(e,".mozilla","firefox");if(process.platform==="win32")return he(process.env.APPDATA??he(e,"AppData","Roaming"),"Mozilla","Firefox","Profiles");return""}function Vl(e){let t=he(Kl(e),"profiles.ini"),n={};if(!It(t))return n;try{let r=ln(t,"utf8"),s="",i="";for(let o of r.split(`
114
+ `)){let a=o.trim();if(a.startsWith("[")){s="",i="";continue}let c=a.indexOf("=");if(c===-1)continue;let u=a.slice(0,c).trim().toLowerCase(),f=a.slice(c+1).trim();if(u==="name")s=f;if(u==="path")i=f.split(/[\\/]/).pop()??f;if(s&&i)n[i]=s,s="",i=""}}catch{}return n}function Ca(){let e=Gl();if(!e||!It(e))return[];let t=Vl(e),n=[],r;try{r=es(e)}catch{return[]}for(let s of r){let i=he(e,s,"cookies.sqlite");if(!It(i))continue;let o=he(ma(),`slack-firefox-cookies-${Date.now()}-${s}.db`);try{ha(i,o);let{default:a}=Xe("bun:sqlite"),c=new a(o,{readonly:!0}),u=c.prepare("SELECT value FROM moz_cookies WHERE name='d' AND host LIKE '%slack%' LIMIT 1").get();if(c.close(),!u?.value||!u.value.startsWith("xoxd-"))continue;let f=t[s]??s;n.push({profileDir:s,profileName:f,cookie:u.value})}catch{}finally{try{ga(o)}catch{}}}return n}var Ql=["search:read","channels:history","groups:history","im:history","mpim:history","channels:read","groups:read","im:read","mpim:read","users:read","chat:write","files:write"],ef=["channels:history","groups:history","im:history","mpim:history","channels:read","groups:read","im:read","mpim:read","users:read","chat:write","files:write"];function ns(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")}function tf(){return JSON.stringify({display_information:{name:"slack-term"},oauth_config:{scopes:{user:Ql}},settings:{org_deploy_enabled:!1,socket_mode_enabled:!1,token_rotation_enabled:!1}},null,2)}function nf(){return JSON.stringify({display_information:{name:"slack-term"},features:{bot_user:{display_name:"slack-term",always_online:!1}},oauth_config:{scopes:{bot:ef}},settings:{org_deploy_enabled:!1,socket_mode_enabled:!1,token_rotation_enabled:!1}},null,2)}async function Pt(e,t){return(await e.question(t)).trim()}async function Rt(e,t,n,r){console.error("Verifying token...");let s=await Yt(t),i=ns(s.team),o;if(n)o=n;else if(e)o=await Pt(e,`Workspace name [${i}]: `)||i;else o=i;let a=null;if(e){console.log(""),console.log("Where to save the token?"),console.log(" 1) ./.env.local (current directory) [default]"),console.log(" 2) ./.slack-term/.env.local (current directory, slack-specific)"),console.log(" 3) ~/.slack-term/.env.local (global, available everywhere)"),console.log(" 4) profiles.json (multi-workspace: slack auth use)"),console.log("");let c=await Pt(e,"Choice [1/2/3/4, Enter=1]: ");if(c==="2")a=xr(process.cwd(),".slack-term",".env.local");else if(c==="3")a=xr(Zl(),".slack-term",".env.local");else if(c==="4")a=null;else a=xr(process.cwd(),".env.local")}if(a===null)if(Cr(o,{token:t,...s,...r?{cookie:r}:{}}),console.log(`Saved workspace "${o}" to profiles.json: ${s.team} (${s.user})`),process.env.SLACK_MCP_XOXP_TOKEN)console.log(""),console.log("Warning: SLACK_MCP_XOXP_TOKEN is set — it conflicts with profiles."),console.log(" Unset it: unset SLACK_MCP_XOXP_TOKEN (and remove from ~/.zshrc / ~/.bashrc)");else console.log(` Run: slack auth use -g ${o}`);else{let c={SLACK_TOKEN:t};if(r)c.SLACK_COOKIE=r;pa(a,c),console.log(`Saved token to ${a}`),console.log(" SLACK_TOKEN will be picked up automatically in this directory tree.")}return o}async function sf(e){console.error("Scanning Slack desktop app...");let t=await ba();if(t.length===0)console.error("No sessions found. Make sure Slack is installed and you have signed in at least once."),process.exit(1);if(t.length===1&&e){let n=t[0],r=n.teamName??n.teamId;console.log(`Found workspace: ${r}${n.cookie?" (+ xoxd cookie)":""}`),await Rt(e,n.token,ns(r),n.cookie),console.log(""),console.log("Note: desktop app tokens (xoxc-) are internal Slack tokens."),console.log("If API calls fail, replace with an xoxp- token: slack auth login");return}for(let n of t){let r=n.teamName??n.teamId,s=ns(r);Cr(s,{token:n.token,team:r,teamId:n.teamId,url:n.url??"",user:"",...n.cookie?{cookie:n.cookie}:{}}),console.log(`Added workspace "${s}": ${r}${n.cookie?" + xoxd cookie":""}`)}if(console.log(""),t.length===1){let n=ns(t[0].teamName??t[0].teamId);console.log(`Run: slack auth use -g ${n}`)}else console.log("Run: slack auth ls then: slack auth use -g <name>");console.log(""),console.log("Note: desktop app tokens (xoxc-) are internal Slack tokens."),console.log("If API calls fail, replace with an xoxp- user token by re-running: slack auth login")}async function Ea(e){console.log("Which token type does your app use?"),console.log(""),console.log(" 1) User token (xoxp-) -full access including search [recommended]"),console.log(" 2) Bot token (xoxb-) -search and news unavailable"),console.log("");let n=await Pt(e,"Choice [1/2]: ")==="2"?"bot":"user",r=n==="user"?"xoxp-":"xoxb-",s=n==="user"?"User OAuth Token":"Bot User OAuth Token";console.log(""),console.log("Find your token here:"),console.log(" https://api.slack.com/apps"),console.log(" -> Select your app -> OAuth & Permissions"),console.log(` -> Copy the "${s}" (starts with ${r})`),console.log("");let i=await Pt(e,"Paste your token: ");if(!i)console.error("No token provided."),process.exit(1);if(!i.startsWith(r))console.error(`Expected a ${r} token, got: ${i.slice(0,10)}...`),process.exit(1);await Rt(e,i)}async function ss(e,t){let n=t==="user"?tf():nf(),r=t==="user"?"User OAuth Token (xoxp-...)":"Bot User OAuth Token (xoxb-...)",s=t==="user"?"xoxp-":"xoxb-";if(t==="bot")console.log("Note: bot tokens cannot use search:read (user-only scope)."),console.log(" The news and search commands will not work with a bot token."),console.log("");console.log("Step 1 -Create your Slack app:"),console.log(" Open: https://api.slack.com/apps"),console.log(' Click "Create New App" -> "From a manifest" -> select your workspace'),console.log(" Paste this manifest (JSON tab):"),console.log(""),console.log("-------------------------------------------------------------"),console.log(n),console.log("-------------------------------------------------------------"),console.log(""),console.log('Step 2 -Install: "Install App" -> "Install to Workspace" -> Authorize'),console.log(""),console.log("Step 3 -Copy your token:"),console.log(` OAuth & Permissions -> ${r}`),console.log("");let i=await Pt(e,"Paste your token: ");if(!i)console.error("No token provided."),process.exit(1);if(!i.startsWith(s))console.error(`Expected a ${s} token, got: ${i.slice(0,10)}...`),process.exit(1);await Rt(e,i)}async function xa(e={}){if(process.platform!=="darwin")console.error("Chrome cookie extraction is only supported on macOS."),process.exit(1);let t=Qn();if(t.length===0)console.error("No workspaces configured. Run: slack auth login"),process.exit(1);let n;if(e.workspace){if(!t.find((c)=>c.name===e.workspace))console.error(`Workspace "${e.workspace}" not found. Available: ${t.map((c)=>c.name).join(", ")}`),process.exit(1);n=e.workspace}else if(t.length===1)n=t[0].name;else{let a=t.find((c)=>c.current);if(a)n=a.name,console.log(`Using active workspace: ${n}`);else{console.log("Multiple workspaces found. Choose one:"),t.forEach((l,d)=>console.log(` ${d+1}) ${l.name} (${l.profile.team})`));let c=Tt({input:process.stdin,output:process.stdout}),u=(await c.question("Choice: ")).trim();c.close();let f=parseInt(u,10)-1;if(isNaN(f)||f<0||f>=t.length)console.error("Invalid choice."),process.exit(1);n=t[f].name}}if(t.find((a)=>a.name===n).profile.token.startsWith("xoxb-")){console.error(`
115
115
  Workspace "${n}" uses a bot token (xoxb-). A Chrome session cookie only
116
116
  `+`augments a user session token (xoxc-) — it has no effect on a bot token, so user-level
117
- `+"actions (tail @user, DMs, listing users) would still fail.");let a=t.filter((c)=>c.profile.token.startsWith("xoxc-")||c.profile.token.startsWith("xoxp-"));if(a.length>0)console.error(` Target a user-token workspace instead: ${a.map((c)=>c.name).join(", ")}`),console.error(` slack auth chrome -w ${a[0].name}`);else console.error(" Import your Slack desktop user session instead: slack auth login");process.exit(1)}console.log("Scanning Chrome profiles for Slack session..."),console.log("macOS may show a dialog asking for your login password — click Allow.");let s,i;try{({candidates:s,totalProfiles:i}=ba())}catch(a){console.error(`Failed: ${a instanceof Error?a.message:String(a)}`),process.exit(1)}if(s.length===0)console.error(`No Slack session found in Chrome (scanned ${i} profile${i!==1?"s":""}). Possible reasons:`),console.error(" - You denied the keychain dialog (try running again and click Allow)"),console.error(" - Chrome is not installed or has no Slack session"),console.error(" - You're not logged in to Slack in Chrome"),process.exit(1);let o;if(s.length===1&&i<=1)o=s[0].cookie,console.log(`Found session in Chrome profile: ${s[0].profileName}`);else{let a=s.length===1?`Found 1 Slack session across ${i} Chrome profiles:`:`Found ${s.length} Slack sessions across ${i} Chrome profiles:`;console.log(a),s.forEach((d,p)=>console.log(` ${p+1}) ${d.profileName} [${d.profileDir}]`)),console.log("");let c=$t({input:process.stdin,output:process.stdout}),u=s.length===1?" [Enter=1]":"",f=(await c.question(`Choice [1-${s.length}]${u}: `)).trim();c.close();let l=f===""&&s.length===1?0:parseInt(f,10)-1;if(isNaN(l)||l<0||l>=s.length)console.error("Invalid choice."),process.exit(1);o=s[l].cookie}Cr(n,o),console.log(`Saved xoxd cookie to workspace "${n}".`),console.log("RTM WebSocket mode is now available: slack tail @you")}async function xa(e={}){let t=Vn();if(t.length===0)console.error("No workspaces configured. Run: slack auth token"),process.exit(1);let n;if(e.workspace){if(!t.find((o)=>o.name===e.workspace))console.error(`Workspace "${e.workspace}" not found. Available: ${t.map((o)=>o.name).join(", ")}`),process.exit(1);n=e.workspace}else if(t.length===1)n=t[0].name;else{let i=t.find((o)=>o.current);if(i)n=i.name,console.log(`Using active workspace: ${n}`);else{console.log("Multiple workspaces found. Choose one:"),t.forEach((u,f)=>console.log(` ${f+1}) ${u.name} (${u.profile.team})`));let o=$t({input:process.stdin,output:process.stdout}),a=(await o.question("Choice: ")).trim();o.close();let c=parseInt(a,10)-1;if(isNaN(c)||c<0||c>=t.length)console.error("Invalid choice."),process.exit(1);n=t[c].name}}console.log("Scanning Firefox profiles for Slack session...");let r=Fa();if(r.length===0)console.error("No Slack session found in Firefox. Possible reasons:"),console.error(" - Firefox is not installed"),console.error(" - You are not logged in to Slack in Firefox"),process.exit(1);let s;if(r.length===1)s=r[0].cookie,console.log(`Found session in Firefox profile: ${r[0].profileName}`);else{console.log("Multiple Firefox profiles have a Slack session. Choose one:"),r.forEach((c,u)=>console.log(` ${u+1}) ${c.profileName} [${c.profileDir}]`));let i=$t({input:process.stdin,output:process.stdout}),o=(await i.question("Choice: ")).trim();i.close();let a=parseInt(o,10)-1;if(isNaN(a)||a<0||a>=r.length)console.error("Invalid choice."),process.exit(1);s=r[a].cookie}Cr(n,s),console.log(`Saved xoxd cookie to workspace "${n}".`),console.log("RTM WebSocket mode is now available: slack tail @you")}async function _a(e={}){if(e.token){await It(null,e.token,e.name);return}if(!process.stdin.isTTY){let n=[];for await(let s of process.stdin)n.push(s);let r=Buffer.concat(n).toString("utf8").trim();if(!r)console.error("No token provided on stdin."),process.exit(1);await It(null,r,e.name);return}let t=$t({input:process.stdin,output:process.stdout});try{await Ca(t)}finally{t.close()}}async function Sa(e={}){let t=$t({input:process.stdin,output:process.stdout});try{if(e.bot!==void 0){await ts(t,e.bot?"bot":"user");return}console.log("Which token type?"),console.log(" 1) User token (xoxp-) -full access including search [default]"),console.log(" 2) Bot token (xoxb-) -search and news unavailable"),console.log("");let n=await Ot(t,"Choice [1/2, Enter=1]: ");await ts(t,n==="2"?"bot":"user")}finally{t.close()}}async function ns(e={}){let t=Vn();if(t.length>0){console.log("Currently logged in:");for(let{name:r,profile:s,current:i}of t)console.log(` ${i?"*":" "} ${r} ${s.team} (${s.user||"unknown"})`);console.log(""),console.log("Adding another workspace:"),console.log("")}if(e.token){await It(null,e.token,e.name);return}if(!process.stdin.isTTY){let r=[];for await(let i of process.stdin)r.push(i);let s=Buffer.concat(r).toString("utf8").trim();if(!s)console.error("No token provided on stdin."),process.exit(1);await It(null,s,e.name);return}console.log("How would you like to authenticate with Slack?"),console.log(""),console.log(" 1) Slack desktop app - import session token"),console.log(" Reads the xoxc- token directly from the installed app."),console.log(" Token: all platforms | xoxd cookie: macOS only"),console.log(""),console.log(" 2) Connect existing Slack app [recommended if you have one]"),console.log(" Paste a token from an app you already created."),console.log(""),console.log(" 3) Create new Slack app - user token (xoxp-)"),console.log(" Guided setup with manifest. Full access including search."),console.log(""),console.log(" 4) Create new Slack app - bot token (xoxb-)"),console.log(" Bot is invited to channels. Search and news unavailable."),console.log("");let n=$t({input:process.stdin,output:process.stdout});try{let r=await Ot(n,"Choice [1/2/3/4]: ");if(console.log(""),r==="1")await Ql(n);else if(r==="2")await Ca(n);else if(r==="3")await ts(n,"user");else if(r==="4")await ts(n,"bot");else console.error(`Invalid choice: "${r}". Enter 1, 2, 3, or 4.`),process.exit(1)}finally{n.close()}}async function ss(e,t,n,r){let s=t,i=[],o=s,a=0;while(!0){let c=o.indexOf("<@U",a);if(c===-1)break;let u=o.slice(c+2),f=u.search(/[>|]/),l=f===-1?u:u.slice(0,f);if(l.length>=9)i.push(l);a=c+1}for(let c of i){if(!n.has(c))n.set(c,await Xn(e,c,r));let u=n.get(c)??c;s=s.replaceAll(`<@${c}>`,`@${u}`),s=s.replace(new RegExp(`<@${c}\\|[^>]*>`,"g"),`@${u}`)}return s}function rs(e){return e.replace(/<!date\^(\d+)\^[^|>]*(?:\|([^>]*))?>/g,(t,n,r)=>{let s=Number(n);if(!Number.isFinite(s))return r??"date";let i=new Date(s*1000);if(Number.isNaN(i.getTime()))return r??"date";let o=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],a=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],c=o[i.getUTCDay()]??"",u=a[i.getUTCMonth()]??"";return`${c}, ${u} ${String(i.getUTCDate()).padStart(2,"0")}, ${i.getUTCFullYear()}`})}function Aa(e){let t=typeof e.ts==="string"?e.ts:"",n=typeof e.thread_ts==="string"?e.thread_ts:"";return n!==""&&n!==t}function ef(e){let[t,n="000000"]=e.split("."),r=new Date(Number(t)*1000),s=r.getUTCFullYear(),i=String(r.getUTCMonth()+1).padStart(2,"0"),o=String(r.getUTCDate()).padStart(2,"0"),a=String(r.getUTCHours()).padStart(2,"0"),c=String(r.getUTCMinutes()).padStart(2,"0"),u=String(r.getUTCSeconds()).padStart(2,"0"),f=n.padEnd(6,"0").slice(0,6);return`${s}-${i}-${o}T${a}:${c}:${u}.${f}`}async function tf(e,t,n){let r=typeof t.ts==="string"?t.ts:"0.000000",s=ef(r),i="?";if(typeof t.user==="string"){let l=t.user,d="@"+l;if(!n.has(d)){let[,p]=await Yn(e,l);n.set(d,p)}i=n.get(d)??l}else if(typeof t.username==="string")i=t.username;let o=typeof t.text==="string"?t.text:"",c=rs(await ss(e,o,n)).split(`
117
+ `+"actions (tail @user, DMs, listing users) would still fail.");let a=t.filter((c)=>c.profile.token.startsWith("xoxc-")||c.profile.token.startsWith("xoxp-"));if(a.length>0)console.error(` Target a user-token workspace instead: ${a.map((c)=>c.name).join(", ")}`),console.error(` slack auth chrome -w ${a[0].name}`);else console.error(" Import your Slack desktop user session instead: slack auth login");process.exit(1)}console.log("Scanning Chrome profiles for Slack session..."),console.log("macOS may show a dialog asking for your login password — click Allow.");let s,i;try{({candidates:s,totalProfiles:i}=Fa())}catch(a){console.error(`Failed: ${a instanceof Error?a.message:String(a)}`),process.exit(1)}if(s.length===0)console.error(`No Slack session found in Chrome (scanned ${i} profile${i!==1?"s":""}). Possible reasons:`),console.error(" - You denied the keychain dialog (try running again and click Allow)"),console.error(" - Chrome is not installed or has no Slack session"),console.error(" - You're not logged in to Slack in Chrome"),process.exit(1);let o;if(s.length===1&&i<=1)o=s[0].cookie,console.log(`Found session in Chrome profile: ${s[0].profileName}`);else{let a=s.length===1?`Found 1 Slack session across ${i} Chrome profiles:`:`Found ${s.length} Slack sessions across ${i} Chrome profiles:`;console.log(a),s.forEach((d,p)=>console.log(` ${p+1}) ${d.profileName} [${d.profileDir}]`)),console.log("");let c=Tt({input:process.stdin,output:process.stdout}),u=s.length===1?" [Enter=1]":"",f=(await c.question(`Choice [1-${s.length}]${u}: `)).trim();c.close();let l=f===""&&s.length===1?0:parseInt(f,10)-1;if(isNaN(l)||l<0||l>=s.length)console.error("Invalid choice."),process.exit(1);o=s[l].cookie}Er(n,o),console.log(`Saved xoxd cookie to workspace "${n}".`),console.log("RTM WebSocket mode is now available: slack tail @you")}async function _a(e={}){let t=Qn();if(t.length===0)console.error("No workspaces configured. Run: slack auth token"),process.exit(1);let n;if(e.workspace){if(!t.find((o)=>o.name===e.workspace))console.error(`Workspace "${e.workspace}" not found. Available: ${t.map((o)=>o.name).join(", ")}`),process.exit(1);n=e.workspace}else if(t.length===1)n=t[0].name;else{let i=t.find((o)=>o.current);if(i)n=i.name,console.log(`Using active workspace: ${n}`);else{console.log("Multiple workspaces found. Choose one:"),t.forEach((u,f)=>console.log(` ${f+1}) ${u.name} (${u.profile.team})`));let o=Tt({input:process.stdin,output:process.stdout}),a=(await o.question("Choice: ")).trim();o.close();let c=parseInt(a,10)-1;if(isNaN(c)||c<0||c>=t.length)console.error("Invalid choice."),process.exit(1);n=t[c].name}}console.log("Scanning Firefox profiles for Slack session...");let r=Ca();if(r.length===0)console.error("No Slack session found in Firefox. Possible reasons:"),console.error(" - Firefox is not installed"),console.error(" - You are not logged in to Slack in Firefox"),process.exit(1);let s;if(r.length===1)s=r[0].cookie,console.log(`Found session in Firefox profile: ${r[0].profileName}`);else{console.log("Multiple Firefox profiles have a Slack session. Choose one:"),r.forEach((c,u)=>console.log(` ${u+1}) ${c.profileName} [${c.profileDir}]`));let i=Tt({input:process.stdin,output:process.stdout}),o=(await i.question("Choice: ")).trim();i.close();let a=parseInt(o,10)-1;if(isNaN(a)||a<0||a>=r.length)console.error("Invalid choice."),process.exit(1);s=r[a].cookie}Er(n,s),console.log(`Saved xoxd cookie to workspace "${n}".`),console.log("RTM WebSocket mode is now available: slack tail @you")}async function ka(e={}){if(e.token){await Rt(null,e.token,e.name);return}if(!process.stdin.isTTY){let n=[];for await(let s of process.stdin)n.push(s);let r=Buffer.concat(n).toString("utf8").trim();if(!r)console.error("No token provided on stdin."),process.exit(1);await Rt(null,r,e.name);return}let t=Tt({input:process.stdin,output:process.stdout});try{await Ea(t)}finally{t.close()}}async function Sa(e={}){let t=Tt({input:process.stdin,output:process.stdout});try{if(e.bot!==void 0){await ss(t,e.bot?"bot":"user");return}console.log("Which token type?"),console.log(" 1) User token (xoxp-) -full access including search [default]"),console.log(" 2) Bot token (xoxb-) -search and news unavailable"),console.log("");let n=await Pt(t,"Choice [1/2, Enter=1]: ");await ss(t,n==="2"?"bot":"user")}finally{t.close()}}async function rs(e={}){let t=Qn();if(t.length>0){console.log("Currently logged in:");for(let{name:r,profile:s,current:i}of t)console.log(` ${i?"*":" "} ${r} ${s.team} (${s.user||"unknown"})`);console.log(""),console.log("Adding another workspace:"),console.log("")}if(e.token){await Rt(null,e.token,e.name);return}if(!process.stdin.isTTY){let r=[];for await(let i of process.stdin)r.push(i);let s=Buffer.concat(r).toString("utf8").trim();if(!s)console.error("No token provided on stdin."),process.exit(1);await Rt(null,s,e.name);return}console.log("How would you like to authenticate with Slack?"),console.log(""),console.log(" 1) Slack desktop app - import session token"),console.log(" Reads the xoxc- token directly from the installed app."),console.log(" Token: all platforms | xoxd cookie: macOS only"),console.log(""),console.log(" 2) Connect existing Slack app [recommended if you have one]"),console.log(" Paste a token from an app you already created."),console.log(""),console.log(" 3) Create new Slack app - user token (xoxp-)"),console.log(" Guided setup with manifest. Full access including search."),console.log(""),console.log(" 4) Create new Slack app - bot token (xoxb-)"),console.log(" Bot is invited to channels. Search and news unavailable."),console.log("");let n=Tt({input:process.stdin,output:process.stdout});try{let r=await Pt(n,"Choice [1/2/3/4]: ");if(console.log(""),r==="1")await sf(n);else if(r==="2")await Ea(n);else if(r==="3")await ss(n,"user");else if(r==="4")await ss(n,"bot");else console.error(`Invalid choice: "${r}". Enter 1, 2, 3, or 4.`),process.exit(1)}finally{n.close()}}async function is(e,t,n,r){let s=t,i=[],o=s,a=0;while(!0){let c=o.indexOf("<@U",a);if(c===-1)break;let u=o.slice(c+2),f=u.search(/[>|]/),l=f===-1?u:u.slice(0,f);if(l.length>=9)i.push(l);a=c+1}for(let c of i){if(!n.has(c))n.set(c,await Xn(e,c,r));let u=n.get(c)??c;s=s.replaceAll(`<@${c}>`,`@${u}`),s=s.replace(new RegExp(`<@${c}\\|[^>]*>`,"g"),`@${u}`)}return s}function os(e){return e.replace(/<!date\^(\d+)\^[^|>]*(?:\|([^>]*))?>/g,(t,n,r)=>{let s=Number(n);if(!Number.isFinite(s))return r??"date";let i=new Date(s*1000);if(Number.isNaN(i.getTime()))return r??"date";let o=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],a=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],c=o[i.getUTCDay()]??"",u=a[i.getUTCMonth()]??"";return`${c}, ${u} ${String(i.getUTCDate()).padStart(2,"0")}, ${i.getUTCFullYear()}`})}function $a(e){let t=typeof e.ts==="string"?e.ts:"",n=typeof e.thread_ts==="string"?e.thread_ts:"";return n!==""&&n!==t}function rf(e){let[t,n="000000"]=e.split("."),r=new Date(Number(t)*1000),s=r.getUTCFullYear(),i=String(r.getUTCMonth()+1).padStart(2,"0"),o=String(r.getUTCDate()).padStart(2,"0"),a=String(r.getUTCHours()).padStart(2,"0"),c=String(r.getUTCMinutes()).padStart(2,"0"),u=String(r.getUTCSeconds()).padStart(2,"0"),f=n.padEnd(6,"0").slice(0,6);return`${s}-${i}-${o}T${a}:${c}:${u}.${f}`}async function of(e,t,n){let r=typeof t.ts==="string"?t.ts:"0.000000",s=rf(r),i="?";if(typeof t.user==="string"){let l=t.user,d="@"+l;if(!n.has(d)){let[,p]=await Yn(e,l);n.set(d,p)}i=n.get(d)??l}else if(typeof t.username==="string")i=t.username;let o=typeof t.text==="string"?t.text:"",c=os(await is(e,o,n)).split(`
118
118
  `),u=c[0]+(c.length>1?`
119
119
  `+c.slice(1).map((l)=>` ${l}`).join(`
120
- `):""),f=Aa(t)?"↳ ":"";return`${s} ${f}@${i}: ${u}`}async function nf(e,t,n,r,s,i,o,a){if(a?.aborted)return;return new Promise((c)=>{let u=new e(n);a?.addEventListener("abort",()=>{u.close(),c()},{once:!0}),u.addEventListener("open",()=>{process.stderr.write(`Connected via RTM (experimental).
121
- `)}),u.addEventListener("close",()=>c()),u.addEventListener("error",()=>c()),u.addEventListener("message",(f)=>{(async()=>{try{let l;try{l=JSON.parse(String(f.data))}catch{return}let d=typeof l.type==="string"?l.type:"";if(d==="ping"){u.send(JSON.stringify({type:"pong",reply_to:l.id??0}));return}if(d!=="message")return;if((typeof l.channel==="string"?l.channel:"")!==r)return;let m=typeof l.ts==="string"?l.ts:"";if(!m||i.has(m))return;let g=typeof l.subtype==="string"?l.subtype:"";if(g==="message_changed"||g==="message_deleted")return;if(s.thread){if((typeof l.thread_ts==="string"?l.thread_ts:m)!==s.thread&&m!==s.thread)return}if(s.watchThread&&Aa(l)){if((typeof l.thread_ts==="string"?l.thread_ts:"")!==s.watchThread)return}if(s.me&&s.myUserId){if(!(typeof l.text==="string"?l.text:"").includes(`<@${s.myUserId}>`))return}if(i.add(m),i.size>1000){let C=i.values().next().value;if(C!==void 0)i.delete(C)}let y=await tf(t,l,o);process.stdout.write(y+`
120
+ `):""),f=$a(t)?"↳ ":"";return`${s} ${f}@${i}: ${u}`}async function af(e,t,n,r,s,i,o,a){if(a?.aborted)return;return new Promise((c)=>{let u=new e(n);a?.addEventListener("abort",()=>{u.close(),c()},{once:!0}),u.addEventListener("open",()=>{process.stderr.write(`Connected via RTM (experimental).
121
+ `)}),u.addEventListener("close",()=>c()),u.addEventListener("error",()=>c()),u.addEventListener("message",(f)=>{(async()=>{try{let l;try{l=JSON.parse(String(f.data))}catch{return}let d=typeof l.type==="string"?l.type:"";if(d==="ping"){u.send(JSON.stringify({type:"pong",reply_to:l.id??0}));return}if(d!=="message")return;if((typeof l.channel==="string"?l.channel:"")!==r)return;let m=typeof l.ts==="string"?l.ts:"";if(!m||i.has(m))return;let g=typeof l.subtype==="string"?l.subtype:"";if(g==="message_changed"||g==="message_deleted")return;if(s.thread){if((typeof l.thread_ts==="string"?l.thread_ts:m)!==s.thread&&m!==s.thread)return}if(s.watchThread&&$a(l)){if((typeof l.thread_ts==="string"?l.thread_ts:"")!==s.watchThread)return}if(s.me&&s.myUserId){if(!(typeof l.text==="string"?l.text:"").includes(`<@${s.myUserId}>`))return}if(i.add(m),i.size>1000){let C=i.values().next().value;if(C!==void 0)i.delete(C)}let y=await of(t,l,o);process.stdout.write(y+`
122
122
  `)}catch(l){process.stderr.write(`RTM message error: ${l instanceof Error?l.message:String(l)}
123
- `)}})()})})}var ka=3,sf=2000,xr={sleep:(e)=>new Promise((t)=>setTimeout(t,e)),clientBoot:sa,getWebSocket:()=>{let e=globalThis.WebSocket;return typeof e==="function"?e:void 0}};async function $a(e,t,n,r,s,i,o){let a=xr.getWebSocket();if(!a)return;for(let c=0;c<ka;c++){if(o?.aborted)return;try{let{wsUrl:u}=await xr.clientBoot(e,t);await nf(a,e,u,n,r,s,i,o)}catch{}if(o?.aborted)return;if(c<ka-1)await xr.sleep(sf)}}function Oa(e){let t=e.match(/^(\d+(?:\.\d+)?)(s|m|h|d)$/);if(!t)throw Error(`Invalid --since format: "${e}" (expected e.g. 10m, 2h, 1d)`);let n=parseFloat(t[1]);switch(t[2]){case"s":return n;case"m":return n*60;case"h":return n*3600;case"d":return n*86400}}var Ue={sleep:(e)=>new Promise((t)=>setTimeout(t,e)),now:()=>Date.now(),tailRTM:$a};function et(e){return e&&typeof e==="object"&&!Array.isArray(e)?e:{}}function _r(e){return Array.isArray(e)?e:[]}function Ia(e){return Number(e)||0}function Ta(e){let t=typeof e.ts==="string"?e.ts:"",n=typeof e.thread_ts==="string"?e.thread_ts:"";return n!==""&&n!==t}function rf(e){let[t,n="000000"]=e.split("."),r=new Date(Number(t)*1000),s=r.getUTCFullYear(),i=String(r.getUTCMonth()+1).padStart(2,"0"),o=String(r.getUTCDate()).padStart(2,"0"),a=String(r.getUTCHours()).padStart(2,"0"),c=String(r.getUTCMinutes()).padStart(2,"0"),u=String(r.getUTCSeconds()).padStart(2,"0"),f=n.padEnd(6,"0").slice(0,6);return`${s}-${i}-${o}T${a}:${c}:${u}.${f}`}async function of(e,t,n,r,s){let i=typeof t.ts==="string"?t.ts:"0.000000",o=rf(i),a="?";if(typeof t.user==="string"){let m=t.user,g="@"+m;if(!n.has(g)){let[,y]=await Yn(e,m,s);n.set(g,y)}a=n.get(g)??m}else if(typeof t.username==="string")a=t.username;let c=typeof t.text==="string"?t.text:"",f=rs(await ss(e,c,n,s)).split(`
123
+ `)}})()})})}var Aa=3,cf=2000,_r={sleep:(e)=>new Promise((t)=>setTimeout(t,e)),clientBoot:ra,getWebSocket:()=>{let e=globalThis.WebSocket;return typeof e==="function"?e:void 0}};async function Oa(e,t,n,r,s,i,o){let a=_r.getWebSocket();if(!a)return;for(let c=0;c<Aa;c++){if(o?.aborted)return;try{let{wsUrl:u}=await _r.clientBoot(e,t);await af(a,e,u,n,r,s,i,o)}catch{}if(o?.aborted)return;if(c<Aa-1)await _r.sleep(cf)}}function Ia(e){let t=e.match(/^(\d+(?:\.\d+)?)(s|m|h|d)$/);if(!t)throw Error(`Invalid --since format: "${e}" (expected e.g. 10m, 2h, 1d)`);let n=parseFloat(t[1]);switch(t[2]){case"s":return n;case"m":return n*60;case"h":return n*3600;case"d":return n*86400}}var Ue={sleep:(e)=>new Promise((t)=>setTimeout(t,e)),now:()=>Date.now(),tailRTM:Oa};function et(e){return e&&typeof e==="object"&&!Array.isArray(e)?e:{}}function kr(e){return Array.isArray(e)?e:[]}function Ta(e){return Number(e)||0}function Pa(e){let t=typeof e.ts==="string"?e.ts:"",n=typeof e.thread_ts==="string"?e.thread_ts:"";return n!==""&&n!==t}function uf(e){let[t,n="000000"]=e.split("."),r=new Date(Number(t)*1000),s=r.getUTCFullYear(),i=String(r.getUTCMonth()+1).padStart(2,"0"),o=String(r.getUTCDate()).padStart(2,"0"),a=String(r.getUTCHours()).padStart(2,"0"),c=String(r.getUTCMinutes()).padStart(2,"0"),u=String(r.getUTCSeconds()).padStart(2,"0"),f=n.padEnd(6,"0").slice(0,6);return`${s}-${i}-${o}T${a}:${c}:${u}.${f}`}async function lf(e,t,n,r,s){let i=typeof t.ts==="string"?t.ts:"0.000000",o=uf(i),a="?";if(typeof t.user==="string"){let m=t.user,g="@"+m;if(!n.has(g)){let[,y]=await Yn(e,m,s);n.set(g,y)}a=n.get(g)??m}else if(typeof t.username==="string")a=t.username;let c=typeof t.text==="string"?t.text:"",f=os(await is(e,c,n,s)).split(`
124
124
  `),l=f[0]+(f.length>1?`
125
125
  `+f.slice(1).map((m)=>` ${m}`).join(`
126
- `):""),d=Ta(t)?"↳ ":"",p=r?`${r} @${a}`:`@${a}`;return`${o} ${d}${p}: ${l}`}async function af(e,t,n,r,s,i,o){let a=et(await un(e,t,20,o?void 0:n||void 0,o,r.cookie)),c=_r(a.messages).map(et).reverse(),u=et(a.response_metadata),f=a.has_more===!0&&typeof u.next_cursor==="string"?u.next_cursor:void 0,l=[];if(r.watchThread&&!o){let y=et(await Vo(e,t,r.watchThread,50,r.cookie));l=_r(y.messages).map(et).filter((C)=>(typeof C.ts==="string"?C.ts:"")!==r.watchThread)}let d=[...c.map((y)=>({m:y,fromHistory:!0})),...l.map((y)=>({m:y,fromHistory:!1}))].sort((y,C)=>Ia(typeof y.m.ts==="string"?y.m.ts:"")-Ia(typeof C.m.ts==="string"?C.m.ts:"")),p=[],m=n,g=!1;for(let{m:y,fromHistory:C}of d){let F=typeof y.ts==="string"?y.ts:"";if(!F||s.has(F))continue;let k=typeof y.subtype==="string"?y.subtype:"";if(k==="message_changed"||k==="message_deleted")continue;if(r.thread){if((typeof y.thread_ts==="string"?y.thread_ts:F)!==r.thread&&F!==r.thread)continue}if(r.watchThread&&Ta(y)){if((typeof y.thread_ts==="string"?y.thread_ts:"")!==r.watchThread)continue}if(r.me&&r.myUserId){if(!(typeof y.text==="string"?y.text:"").includes(`<@${r.myUserId}>`))continue}if(s.add(F),s.size>1000){let L=s.values().next().value;if(L!==void 0)s.delete(L)}if(p.push(await of(e,y,i,void 0,r.cookie)),C)m=F;let S=typeof y.user==="string"?y.user:"";if(!r.myUserId||S!==r.myUserId)g=!0}return{newCursor:m,lines:p,hasMore:a.has_more===!0,nextPageCursor:f,emittedOther:g}}function cf(e){if(e.includes("slack.com")){let t=dr(e),n=t?.threadTs??t?.ts;if(n)return n;throw Error(`--watch-thread: could not extract a timestamp from "${e}"`)}if(/^\d{10}\.\d{6}$/.test(e))return e;if(/^\d{16}$/.test(e))return`${e.slice(0,10)}.${e.slice(10)}`;throw Error(`--watch-thread: "${e}" is not a valid ts or permalink`)}async function Pa(e,t,n={},r){if(n.me&&!t)console.error(`slack tail --me requires a <target> channel.
126
+ `):""),d=Pa(t)?"↳ ":"",p=r?`${r} @${a}`:`@${a}`;return`${o} ${d}${p}: ${l}`}async function ff(e,t,n,r,s,i,o){let a=et(await un(e,t,20,o?void 0:n||void 0,o,r.cookie)),c=kr(a.messages).map(et).reverse(),u=et(a.response_metadata),f=a.has_more===!0&&typeof u.next_cursor==="string"?u.next_cursor:void 0,l=[];if(r.watchThread&&!o){let y=et(await Zo(e,t,r.watchThread,50,r.cookie));l=kr(y.messages).map(et).filter((C)=>(typeof C.ts==="string"?C.ts:"")!==r.watchThread)}let d=[...c.map((y)=>({m:y,fromHistory:!0})),...l.map((y)=>({m:y,fromHistory:!1}))].sort((y,C)=>Ta(typeof y.m.ts==="string"?y.m.ts:"")-Ta(typeof C.m.ts==="string"?C.m.ts:"")),p=[],m=n,g=!1;for(let{m:y,fromHistory:C}of d){let F=typeof y.ts==="string"?y.ts:"";if(!F||s.has(F))continue;let S=typeof y.subtype==="string"?y.subtype:"";if(S==="message_changed"||S==="message_deleted")continue;if(r.thread){if((typeof y.thread_ts==="string"?y.thread_ts:F)!==r.thread&&F!==r.thread)continue}if(r.watchThread&&Pa(y)){if((typeof y.thread_ts==="string"?y.thread_ts:"")!==r.watchThread)continue}if(r.me&&r.myUserId){if(!(typeof y.text==="string"?y.text:"").includes(`<@${r.myUserId}>`))continue}if(s.add(F),s.size>1000){let L=s.values().next().value;if(L!==void 0)s.delete(L)}if(p.push(await lf(e,y,i,void 0,r.cookie)),C)m=F;let k=typeof y.user==="string"?y.user:"";if(!r.myUserId||k!==r.myUserId)g=!0}return{newCursor:m,lines:p,hasMore:a.has_more===!0,nextPageCursor:f,emittedOther:g}}function df(e){if(e.includes("slack.com")){let t=gr(e),n=t?.threadTs??t?.ts;if(n)return n;throw Error(`--watch-thread: could not extract a timestamp from "${e}"`)}if(/^\d{10}\.\d{6}$/.test(e))return e;if(/^\d{16}$/.test(e))return`${e.slice(0,10)}.${e.slice(10)}`;throw Error(`--watch-thread: "${e}" is not a valid ts or permalink`)}async function Ra(e,t,n={},r){if(n.me&&!t)console.error(`slack tail --me requires a <target> channel.
127
127
  Cross-channel mention streaming is not yet supported.
128
- Use: slack tail "#channel" --me`),process.exit(1);if(!t)console.error("Usage: slack tail <#channel|@user>\n Run `slack tail --help` for details."),process.exit(1);let s=await ta(e,t,n.cookie),i=n.interval??60000,o=n.timeout?Ue.now()+Oa(n.timeout)*1000:1/0,a=new Map,c=new Set;try{let g=et(await na(e,s,n.cookie));if(et(g.channel).is_archived===!0)console.error("Warning: this channel is archived — no new messages will arrive.")}catch(g){let y=g instanceof Error?g.message:String(g);if(y.includes("not_in_channel"))console.error("Error: you are not a member of that channel. Join it in Slack first, then retry."),process.exit(1);if(y.includes("missing_scope"))console.error("Error: token lacks the required history scope. Check your token's channels:history (or groups:history) permission."),process.exit(1);if(y.includes("channel_not_found"))console.error("Error: channel not found — it may be a private channel inaccessible with your token."),process.exit(1);console.error(`Warning: preflight check failed: ${y}`)}let u="";if(n.since){let g=Oa(n.since);u=(Ue.now()/1000-g).toFixed(6)}else{let g=et(await un(e,s,1,void 0,void 0,n.cookie)),y=_r(g.messages).map(et);if(y.length>0&&typeof y[0]?.ts==="string")u=y[0].ts,c.add(u);else u=(Ue.now()/1000).toFixed(6)}let f;if(n.me||n.exitOnMessage)f=(await qt(e,n.cookie)).userId||void 0;let l;if(n.watchThread!==void 0)try{l=cf(n.watchThread)}catch(g){console.error(g instanceof Error?g.message:String(g)),process.exit(1)}let d={...n.thread!==void 0?{thread:n.thread}:{},...l!==void 0?{watchThread:l}:{},...n.me!==void 0?{me:n.me}:{},...f!==void 0?{myUserId:f}:{},...n.cookie!==void 0?{cookie:n.cookie}:{}};if(e.startsWith("xoxc-")&&n.cookie!==void 0&&n.noRtm!==!0&&n.since===void 0&&n.timeout===void 0&&n.exitOnMessage!==!0){if(await Ue.tailRTM(e,n.cookie,s,d,c,a,r),r?.aborted)return;console.error("RTM unavailable — switching to polling.")}let p=!0,m=Ue.now();while(!r?.aborted){if(Ue.now()>=o)return;let g=!1;try{let F=Ue.now()-m,k=i>0&&F>i*5,S,L=!0;do{let{newCursor:A,lines:R,nextPageCursor:B,emittedOther:P}=await af(e,s,u,d,c,a,S);if(u=A,p&&L&&n.since&&R.length===0)process.stdout.write(`(no messages in the last ${n.since} — watching for new)
128
+ Use: slack tail "#channel" --me`),process.exit(1);if(!t)console.error("Usage: slack tail <#channel|@user>\n Run `slack tail --help` for details."),process.exit(1);let s=await na(e,t,n.cookie),i=n.interval??60000,o=n.timeout?Ue.now()+Ia(n.timeout)*1000:1/0,a=new Map,c=new Set;try{let g=et(await sa(e,s,n.cookie));if(et(g.channel).is_archived===!0)console.error("Warning: this channel is archived — no new messages will arrive.")}catch(g){let y=g instanceof Error?g.message:String(g);if(y.includes("not_in_channel"))console.error("Error: you are not a member of that channel. Join it in Slack first, then retry."),process.exit(1);if(y.includes("missing_scope"))console.error("Error: token lacks the required history scope. Check your token's channels:history (or groups:history) permission."),process.exit(1);if(y.includes("channel_not_found"))console.error("Error: channel not found — it may be a private channel inaccessible with your token."),process.exit(1);console.error(`Warning: preflight check failed: ${y}`)}let u="";if(n.since){let g=Ia(n.since);u=(Ue.now()/1000-g).toFixed(6)}else{let g=et(await un(e,s,1,void 0,void 0,n.cookie)),y=kr(g.messages).map(et);if(y.length>0&&typeof y[0]?.ts==="string")u=y[0].ts,c.add(u);else u=(Ue.now()/1000).toFixed(6)}let f;if(n.me||n.exitOnMessage)f=(await Yt(e,n.cookie)).userId||void 0;let l;if(n.watchThread!==void 0)try{l=df(n.watchThread)}catch(g){console.error(g instanceof Error?g.message:String(g)),process.exit(1)}let d={...n.thread!==void 0?{thread:n.thread}:{},...l!==void 0?{watchThread:l}:{},...n.me!==void 0?{me:n.me}:{},...f!==void 0?{myUserId:f}:{},...n.cookie!==void 0?{cookie:n.cookie}:{}};if(e.startsWith("xoxc-")&&n.cookie!==void 0&&n.noRtm!==!0&&n.since===void 0&&n.timeout===void 0&&n.exitOnMessage!==!0){if(await Ue.tailRTM(e,n.cookie,s,d,c,a,r),r?.aborted)return;console.error("RTM unavailable — switching to polling.")}let p=!0,m=Ue.now();while(!r?.aborted){if(Ue.now()>=o)return;let g=!1;try{let F=Ue.now()-m,S=i>0&&F>i*5,k,L=!0;do{let{newCursor:A,lines:R,nextPageCursor:B,emittedOther:P}=await ff(e,s,u,d,c,a,k);if(u=A,p&&L&&n.since&&R.length===0)process.stdout.write(`(no messages in the last ${n.since} — watching for new)
129
129
  `);L=!1;for(let q of R)process.stdout.write(q+`
130
- `);if(P)g=!0;S=k?B:void 0}while(S);p=!1}catch(C){if(C instanceof We){console.error(`Warning: Slack rate limit hit — backing off for ${C.retryAfter}s`),await Ue.sleep(C.retryAfter*1000);continue}throw C}if(n.exitOnMessage&&g)return;m=Ue.now();let y=o-Ue.now();if(y<=0)return;await Ue.sleep(Math.min(i,y))}}var Ke=[{name:"one",glyph:"1️⃣"},{name:"two",glyph:"2️⃣"},{name:"three",glyph:"3️⃣"},{name:"four",glyph:"4️⃣"},{name:"five",glyph:"5️⃣"},{name:"six",glyph:"6️⃣"},{name:"seven",glyph:"7️⃣"},{name:"eight",glyph:"8️⃣"},{name:"nine",glyph:"9️⃣"},{name:"keycap_ten",glyph:"\uD83D\uDD1F"}],os=Ke.length,as="question";function Sr(e){let t=e.split(`
131
- `),n=t[t.length-2];if(n===void 0||!n.startsWith("_:warning: 同時に複数選ばれているため回答として数えていません — どれか 1 つだけ残してください: ")||!n.endsWith("_"))return[];return[...n.matchAll(/<@([UW][A-Z0-9]+)>/g)].map((r)=>r[1])}function kr(e,t){let n=e.split(`
130
+ `);if(P)g=!0;k=S?B:void 0}while(k);p=!1}catch(C){if(C instanceof We){console.error(`Warning: Slack rate limit hit — backing off for ${C.retryAfter}s`),await Ue.sleep(C.retryAfter*1000);continue}throw C}if(n.exitOnMessage&&g)return;m=Ue.now();let y=o-Ue.now();if(y<=0)return;await Ue.sleep(Math.min(i,y))}}var Ke=[{name:"one",glyph:"1️⃣"},{name:"two",glyph:"2️⃣"},{name:"three",glyph:"3️⃣"},{name:"four",glyph:"4️⃣"},{name:"five",glyph:"5️⃣"},{name:"six",glyph:"6️⃣"},{name:"seven",glyph:"7️⃣"},{name:"eight",glyph:"8️⃣"},{name:"nine",glyph:"9️⃣"},{name:"keycap_ten",glyph:"\uD83D\uDD1F"}],cs=Ke.length,us="question";function Sr(e){let t=e.split(`
131
+ `),n=t[t.length-2];if(n===void 0||!n.startsWith("_:warning: 同時に複数選ばれているため回答として数えていません — どれか 1 つだけ残してください: ")||!n.endsWith("_"))return[];return[...n.matchAll(/<@([UW][A-Z0-9]+)>/g)].map((r)=>r[1])}function Ar(e,t){let n=e.split(`
132
132
  `);if(n.length<2)return e;if(Sr(e).length)n.splice(n.length-2,1);if(t.length)n.splice(n.length-1,0,`${"_:warning: 同時に複数選ばれているため回答として数えていません — どれか 1 つだけ残してください: "}${t.map((s)=>`<@${s}>`).join(", ")}_`);let r=n.join(`
133
- `);return r===e?e:r}function uf(e){return e!==void 0&&e.startsWith("_:warning: 同時に複数選ばれているため回答として数えていません — どれか 1 つだけ残してください: ")&&e.endsWith("_")}var Ar="white_check_mark",is=`:${Ar}: `;function Ra(e){return`:${Ke[e].name}:`}function Ma(e,t){let n=Ke[t];for(let r of[Ra(t),n.glyph]){if(e.startsWith(`${r} `))return e.slice(r.length+1);if(e===r)return""}return null}function lf(e){return Ke.some((t,n)=>Ma(e,n)!==null)}function fn(e){return e.replace(/\s*\n\s*/g," ")}function Ba(e,t,n,r,s){let i=[`:question: *${e}*`];if(t)i.push("",t);if(n.length){if(i.push(""),i.push(...n.map((o,a)=>`${Ra(a)} ${fn(o)}`)),r.length)i.push(""),i.push(...r.map((o,a)=>`(${a+11}) ${fn(o)}`)),i.push("_11 番目以降はリアクションがないので、返信で答えてください。_");i.push(""),i.push(s?"_下のリアクションを 1 つ押すと回答になります。当てはまるものがなければ、このメッセージの *スレッド* で返信してください (チャンネルへの通常投稿は回答として拾いません)。_":"_下のリアクションを 1 つ押すと回答になります。当てはまるものがなければ、このメッセージに返信してください。_")}else i.push(""),i.push(s?"_このメッセージの *スレッド* で返信してください。本文がそのまま回答になります (チャンネルへの通常投稿は回答として拾いません)。_":"_このメッセージに返信してください。本文がそのまま回答になります。_");return i.join(`
134
- `)}function Na(e,t,n){let r=t.answer.split(`
133
+ `);return r===e?e:r}function pf(e){return e!==void 0&&e.startsWith("_:warning: 同時に複数選ばれているため回答として数えていません — どれか 1 つだけ残してください: ")&&e.endsWith("_")}var $r="white_check_mark",as=`:${$r}: `;function Ma(e){return`:${Ke[e].name}:`}function Ba(e,t){let n=Ke[t];for(let r of[Ma(t),n.glyph]){if(e.startsWith(`${r} `))return e.slice(r.length+1);if(e===r)return""}return null}function hf(e){return Ke.some((t,n)=>Ba(e,n)!==null)}function fn(e){return e.replace(/\s*\n\s*/g," ")}function Na(e,t,n,r,s){let i=[`:question: *${e}*`];if(t)i.push("",t);if(n.length){if(i.push(""),i.push(...n.map((o,a)=>`${Ma(a)} ${fn(o)}`)),r.length)i.push(""),i.push(...r.map((o,a)=>`(${a+11}) ${fn(o)}`)),i.push("_11 番目以降はリアクションがないので、返信で答えてください。_");i.push(""),i.push(s?"_下のリアクションを 1 つ押すと回答になります。当てはまるものがなければ、このメッセージの *スレッド* で返信してください (チャンネルへの通常投稿は回答として拾いません)。_":"_下のリアクションを 1 つ押すと回答になります。当てはまるものがなければ、このメッセージに返信してください。_")}else i.push(""),i.push(s?"_このメッセージの *スレッド* で返信してください。本文がそのまま回答になります (チャンネルへの通常投稿は回答として拾いません)。_":"_このメッセージに返信してください。本文がそのまま回答になります。_");return i.join(`
134
+ `)}function va(e,t,n){let r=t.answer.split(`
135
135
  `).map((s)=>`> ${s}`).join(`
136
- `);return`${is}*${e}*
136
+ `);return`${as}*${e}*
137
137
  _${t.how}で回答済み${n?` (${n})`:""}_
138
138
 
139
- ${r}`}function va(e){if(!e.trim())return"本文が空です (bot 投稿や添付のみのメッセージかもしれません)";let t=e.split(`
140
- `),n=t[t.length-1]??"";if(e.startsWith(is))return"回答済みマーク付きですが、引用された回答本文が見つかりません";if(!/_$/.test(n))return"末尾が `ask` の案内文ではありません — このメッセージは `slack ask` で投稿されたものではないか、本文が編集されています";if(!t[0].startsWith(":question: ")&&!t[0].startsWith("*"))return"先頭が質問文 (太字) ではありません — 本文が編集されている可能性があります";return"選択肢の並びを読み取れません — 番号が 1 から連番になっていないか、本文が編集されています"}function ja(e){let t=e.split(`
141
- `);if(e.startsWith(is)){let l=t[0].slice(is.length).replace(/^\*/,"").replace(/\*$/,""),d=t.filter((p)=>p.startsWith("> ")).map((p)=>p.slice(2)).join(`
139
+ ${r}`}function ja(e){if(!e.trim())return"本文が空です (bot 投稿や添付のみのメッセージかもしれません)";let t=e.split(`
140
+ `),n=t[t.length-1]??"";if(e.startsWith(as))return"回答済みマーク付きですが、引用された回答本文が見つかりません";if(!/_$/.test(n))return"末尾が `ask` の案内文ではありません — このメッセージは `slack ask` で投稿されたものではないか、本文が編集されています";if(!t[0].startsWith(":question: ")&&!t[0].startsWith("*"))return"先頭が質問文 (太字) ではありません — 本文が編集されている可能性があります";return"選択肢の並びを読み取れません — 番号が 1 から連番になっていないか、本文が編集されています"}function La(e){let t=e.split(`
141
+ `);if(e.startsWith(as)){let l=t[0].slice(as.length).replace(/^\*/,"").replace(/\*$/,""),d=t.filter((p)=>p.startsWith("> ")).map((p)=>p.slice(2)).join(`
142
142
  `);if(!d)return{kind:"other"};return{kind:"resolved",question:l,answer:d}}let n=t[t.length-1]??"",r,s;switch(n){case"_下のリアクションを 1 つ押すと回答になります。当てはまるものがなければ、このメッセージの *スレッド* で返信してください (チャンネルへの通常投稿は回答として拾いません)。_":r=!0,s=!0;break;case"_下のリアクションを 1 つ押すと回答になります。当てはまるものがなければ、このメッセージに返信してください。_":r=!1,s=!0;break;case"_このメッセージの *スレッド* で返信してください。本文がそのまま回答になります (チャンネルへの通常投稿は回答として拾いません)。_":r=!0,s=!1;break;case"_このメッセージに返信してください。本文がそのまま回答になります。_":r=!1,s=!1;break;default:return{kind:"other"}}let i=t[0].startsWith(":question: ")?t[0].slice(11):t[0];if(t[0]=i,!t[0].startsWith("*"))return{kind:"other"};let o=0;while(o<t.length&&!(t[o].endsWith("*")&&(o>0||t[0].length>1)))o++;if(o>=t.length)return{kind:"other"};let a=t.slice(0,o+1).join(`
143
- `).replace(/^\*/,"").replace(/\*$/,""),c=[],u=[];if(s){let f=t.length-2;if(uf(t[f]))f--;if(t[f]!=="")return{kind:"other"};if(f--,t[f]==="_11 番目以降はリアクションがないので、返信で答えてください。_"){f--;while(f>=0&&/^\(\d+\) /.test(t[f]))u.unshift(t[f].replace(/^\(\d+\) /,"")),f--;if(t[f]!=="")return{kind:"other"};f--}let l=[];while(f>=0){let d=t[f];if(!lf(d))break;l.unshift(d),f--}if(!l.length||l.length>os)return{kind:"other"};for(let d=0;d<l.length;d++){let p=Ma(l[d],d);if(p===null)return{kind:"other"};c.push(p)}if(t[f]!=="")return{kind:"other"};if(f<o+1)return{kind:"other"};for(let d=0;d<u.length;d++)if(!t.includes(`(${d+11}) ${u[d]}`))return{kind:"other"}}return{kind:"open",question:a,reactable:c,overflow:u,threadOnly:r}}var $r=[{name:"one",glyph:"1️⃣"},{name:"two",glyph:"2️⃣"},{name:"three",glyph:"3️⃣"},{name:"four",glyph:"4️⃣"},{name:"five",glyph:"5️⃣"},{name:"six",glyph:"6️⃣"},{name:"seven",glyph:"7️⃣"},{name:"eight",glyph:"8️⃣"},{name:"nine",glyph:"9️⃣"},{name:"keycap_ten",glyph:"\uD83D\uDD1F"}],tm=$r.length;function Or(e){let t=e.split(`
144
- `),n=t[t.length-2];if(n===void 0||!n.startsWith("_:warning: 同時に複数選ばれているため回答として数えていません — どれか 1 つだけ残してください: ")||!n.endsWith("_"))return[];return[...n.matchAll(/<@([UW][A-Z0-9]+)>/g)].map((r)=>r[1])}function La(e,t){let n=e.split(`
145
- `);if(n.length<2)return e;if(Or(e).length)n.splice(n.length-2,1);if(t.length)n.splice(n.length-1,0,`${"_:warning: 同時に複数選ばれているため回答として数えていません — どれか 1 つだけ残してください: "}${t.map((s)=>`<@${s}>`).join(", ")}_`);let r=n.join(`
146
- `);return r===e?e:r}function Wa(e){return e!==void 0&&e.startsWith("_:warning: 同時に複数選ばれているため回答として数えていません — どれか 1 つだけ残してください: ")&&e.endsWith("_")}var ff="white_check_mark",nm=`:${ff}: `;var Je=$r,Yt=Je.length,pn="ballot_box_with_ballot",Ir=`:${pn}: `,Ka="_下のリアクションで投票してください (1 人 1 票、押し直しで変更できます)。_",Ja="_下のリアクションで投票してください (当てはまるものを *いくつでも* 押せます)。_",cs="_締切: ",us="_",Pr="bar_chart",Tr=`:${Pr}: `;function ls(e){return`:${Je[e].name}:`}function Ua(e,t){for(let n of[ls(t),Je[t].glyph])if(e.startsWith(`${n} `))return e.slice(n.length+1);return null}function df(e){return Je.some((t,n)=>e.startsWith(`${ls(n)} `)||e.startsWith(`${t.glyph} `))}function dn(e){return e.replace(/\s*\n\s*/g," ")}function za(e,t,n,r={}){let s=!!r.multi,i=r.deadline??"",o=r.invalid??[];if(!n.length||n.length>Yt)throw Error(`poll needs 1..${Yt} choices, got ${n.length}`);let a=[`${Ir}*${e}*`];if(t)a.push("",t);if(a.push(""),a.push(...n.map((c,u)=>`${ls(u)} ${dn(c)}`)),a.push(""),i)a.push(`${cs}${dn(i)}${us}`);return a.push(s?Ja:Ka),La(a.join(`
147
- `),s?[]:o)}function Ha(e,t){let n=t.reduce((s,i)=>s+i.count,0),r=[`${Tr}*${e}*`,`_投票終了 (計 ${n} 票)_`,""];return r.push(...t.map((s,i)=>`${ls(i)} ×${s.count} ${dn(s.choice)}`)),r.join(`
148
- `)}function qa(e){let t=e.split(`
149
- `);if(e.startsWith(Tr)){let d=t[0].slice(Tr.length).replace(/^\*/,"").replace(/\*$/,""),p=[];for(let m=0;m<Je.length;m++){let g=t.map((C)=>Ua(C,m)).find((C)=>C!==null&&C.startsWith("×"));if(g===void 0)break;let y=/^×(\d+) (.*)$/.exec(g);if(!y)return{kind:"other"};p.push({choice:y[2],count:Number(y[1])})}if(!p.length)return{kind:"other"};return{kind:"closed",question:d,tallies:p}}let n=t[t.length-1]??"",r;if(n===Ka)r=!1;else if(n===Ja)r=!0;else return{kind:"other"};if(t[0].startsWith(Ir))t[0]=t[0].slice(Ir.length);if(!t[0].startsWith("*"))return{kind:"other"};let s=0;while(s<t.length&&!(t[s].endsWith("*")&&(s>0||t[0].length>1)))s++;if(s>=t.length)return{kind:"other"};let i=t.slice(0,s+1).join(`
150
- `).replace(/^\*/,"").replace(/\*$/,""),o=t.length-2,a=Or(e);if(Wa(t[o]))o--;let c="",u=t[o];if(u!==void 0&&u.startsWith(cs)&&u.endsWith(us)&&u.length>cs.length+us.length)c=u.slice(cs.length,-us.length),o--;if(t[o]!=="")return{kind:"other"};o--;let f=[];while(o>=0){let d=t[o];if(!df(d))break;f.unshift(d),o--}if(!f.length||f.length>Yt)return{kind:"other"};let l=[];for(let d=0;d<f.length;d++){let p=Ua(f[d],d);if(p===null)return{kind:"other"};l.push(p)}if(t[o]!=="")return{kind:"other"};if(o<s+1)return{kind:"other"};return{kind:"open",question:i,choices:l,multi:r,deadline:c,invalid:a}}function Ya(e,t,n,r){let s=new Map(t.map((u)=>[u.name,u.users])),i=e.map((u,f)=>(s.get(Je[f].name)??[]).filter((l)=>!n.has(l))),o=[];if(!r){let u=new Map;for(let f of i)for(let l of f)u.set(l,(u.get(l)??0)+1);for(let[f,l]of u)if(l>1)o.push(f)}let a=new Set(o),c=i.map((u)=>u.filter((f)=>!a.has(f)));return{tallies:e.map((u,f)=>({choice:u,count:c[f].length})),voters:c,ambiguous:o}}function pf(e=process.env){return!!e.VITEST||e.NODE_ENV==="test"||!!e.BUN_TEST}var Xa={isTestEnv:()=>pf(),sleep:(e)=>Xa.isTestEnv()?Promise.resolve():new Promise((t)=>setTimeout(t,e))};function hf(e=process.env){let t=e.SLACK_REACTION_SEED_GAP_MS;if(t===void 0||t==="")return 1100;let n=Number(t);if(!Number.isFinite(n)||n<0)return 1100;return n}async function Rr(e,t,n,r=hf()){for(let s=0;s<e.length;s++){let i=!0;try{await t(e[s])}catch(o){i=!1,n(e[s],o)}if(i&&r>0&&s<e.length-1)await Xa.sleep(r)}}class Pt extends Error{retryAfter;constructor(e){super(`Slack rate limited — retry after ${e}s`);this.name="RateLimitError",this.retryAfter=e}}function Nr(){return(process.env.SLACK_API_BASE??"https://slack.com/api").replace(/\/$/,"")}async function Za(e,t,n,r){let s={};if(r)s.Cookie=`d=${r}`;let i=await fetch(`${Nr()}/${t}`,{...n,headers:{...n.headers??{},Authorization:`Bearer ${e}`,...s}});if(i.status===429){let a=parseInt(i.headers.get("retry-after")??"60",10);throw new Pt(isNaN(a)?60:a)}let o=await i.json();if(o.ok!==!0){let a=o.error??"unknown";if(a==="ratelimited")throw new Pt(60);if(a==="invalid_auth"&&e.startsWith("xoxc-")&&!r)throw Error(`Desktop app token (xoxc-) needs its session cookie to be accepted by the public Slack API.
143
+ `).replace(/^\*/,"").replace(/\*$/,""),c=[],u=[];if(s){let f=t.length-2;if(pf(t[f]))f--;if(t[f]!=="")return{kind:"other"};if(f--,t[f]==="_11 番目以降はリアクションがないので、返信で答えてください。_"){f--;while(f>=0&&/^\(\d+\) /.test(t[f]))u.unshift(t[f].replace(/^\(\d+\) /,"")),f--;if(t[f]!=="")return{kind:"other"};f--}let l=[];while(f>=0){let d=t[f];if(!hf(d))break;l.unshift(d),f--}if(!l.length||l.length>cs)return{kind:"other"};for(let d=0;d<l.length;d++){let p=Ba(l[d],d);if(p===null)return{kind:"other"};c.push(p)}if(t[f]!=="")return{kind:"other"};if(f<o+1)return{kind:"other"};for(let d=0;d<u.length;d++)if(!t.includes(`(${d+11}) ${u[d]}`))return{kind:"other"}}return{kind:"open",question:a,reactable:c,overflow:u,threadOnly:r}}var Or=[{name:"one",glyph:"1️⃣"},{name:"two",glyph:"2️⃣"},{name:"three",glyph:"3️⃣"},{name:"four",glyph:"4️⃣"},{name:"five",glyph:"5️⃣"},{name:"six",glyph:"6️⃣"},{name:"seven",glyph:"7️⃣"},{name:"eight",glyph:"8️⃣"},{name:"nine",glyph:"9️⃣"},{name:"keycap_ten",glyph:"\uD83D\uDD1F"}],sm=Or.length;function Ir(e){let t=e.split(`
144
+ `),n=t[t.length-2];if(n===void 0||!n.startsWith("_:warning: 同時に複数選ばれているため回答として数えていません — どれか 1 つだけ残してください: ")||!n.endsWith("_"))return[];return[...n.matchAll(/<@([UW][A-Z0-9]+)>/g)].map((r)=>r[1])}function Wa(e,t){let n=e.split(`
145
+ `);if(n.length<2)return e;if(Ir(e).length)n.splice(n.length-2,1);if(t.length)n.splice(n.length-1,0,`${"_:warning: 同時に複数選ばれているため回答として数えていません — どれか 1 つだけ残してください: "}${t.map((s)=>`<@${s}>`).join(", ")}_`);let r=n.join(`
146
+ `);return r===e?e:r}function Ua(e){return e!==void 0&&e.startsWith("_:warning: 同時に複数選ばれているため回答として数えていません — どれか 1 つだけ残してください: ")&&e.endsWith("_")}var gf="white_check_mark",rm=`:${gf}: `;var Je=Or,Xt=Je.length,pn="ballot_box_with_ballot",Tr=`:${pn}: `,Ja="_下のリアクションで投票してください (1 人 1 票、押し直しで変更できます)。_",za="_下のリアクションで投票してください (当てはまるものを *いくつでも* 押せます)。_",ls="_締切: ",fs="_",Rr="bar_chart",Pr=`:${Rr}: `;function ds(e){return`:${Je[e].name}:`}function Ka(e,t){for(let n of[ds(t),Je[t].glyph])if(e.startsWith(`${n} `))return e.slice(n.length+1);return null}function mf(e){return Je.some((t,n)=>e.startsWith(`${ds(n)} `)||e.startsWith(`${t.glyph} `))}function dn(e){return e.replace(/\s*\n\s*/g," ")}function Ha(e,t,n,r={}){let s=!!r.multi,i=r.deadline??"",o=r.invalid??[];if(!n.length||n.length>Xt)throw Error(`poll needs 1..${Xt} choices, got ${n.length}`);let a=[`${Tr}*${e}*`];if(t)a.push("",t);if(a.push(""),a.push(...n.map((c,u)=>`${ds(u)} ${dn(c)}`)),a.push(""),i)a.push(`${ls}${dn(i)}${fs}`);return a.push(s?za:Ja),Wa(a.join(`
147
+ `),s?[]:o)}function qa(e,t){let n=t.reduce((s,i)=>s+i.count,0),r=[`${Pr}*${e}*`,`_投票終了 (計 ${n} 票)_`,""];return r.push(...t.map((s,i)=>`${ds(i)} ×${s.count} ${dn(s.choice)}`)),r.join(`
148
+ `)}function Ya(e){let t=e.split(`
149
+ `);if(e.startsWith(Pr)){let d=t[0].slice(Pr.length).replace(/^\*/,"").replace(/\*$/,""),p=[];for(let m=0;m<Je.length;m++){let g=t.map((C)=>Ka(C,m)).find((C)=>C!==null&&C.startsWith("×"));if(g===void 0)break;let y=/^×(\d+) (.*)$/.exec(g);if(!y)return{kind:"other"};p.push({choice:y[2],count:Number(y[1])})}if(!p.length)return{kind:"other"};return{kind:"closed",question:d,tallies:p}}let n=t[t.length-1]??"",r;if(n===Ja)r=!1;else if(n===za)r=!0;else return{kind:"other"};if(t[0].startsWith(Tr))t[0]=t[0].slice(Tr.length);if(!t[0].startsWith("*"))return{kind:"other"};let s=0;while(s<t.length&&!(t[s].endsWith("*")&&(s>0||t[0].length>1)))s++;if(s>=t.length)return{kind:"other"};let i=t.slice(0,s+1).join(`
150
+ `).replace(/^\*/,"").replace(/\*$/,""),o=t.length-2,a=Ir(e);if(Ua(t[o]))o--;let c="",u=t[o];if(u!==void 0&&u.startsWith(ls)&&u.endsWith(fs)&&u.length>ls.length+fs.length)c=u.slice(ls.length,-fs.length),o--;if(t[o]!=="")return{kind:"other"};o--;let f=[];while(o>=0){let d=t[o];if(!mf(d))break;f.unshift(d),o--}if(!f.length||f.length>Xt)return{kind:"other"};let l=[];for(let d=0;d<f.length;d++){let p=Ka(f[d],d);if(p===null)return{kind:"other"};l.push(p)}if(t[o]!=="")return{kind:"other"};if(o<s+1)return{kind:"other"};return{kind:"open",question:i,choices:l,multi:r,deadline:c,invalid:a}}function Xa(e,t,n,r){let s=new Map(t.map((u)=>[u.name,u.users])),i=e.map((u,f)=>(s.get(Je[f].name)??[]).filter((l)=>!n.has(l))),o=[];if(!r){let u=new Map;for(let f of i)for(let l of f)u.set(l,(u.get(l)??0)+1);for(let[f,l]of u)if(l>1)o.push(f)}let a=new Set(o),c=i.map((u)=>u.filter((f)=>!a.has(f)));return{tallies:e.map((u,f)=>({choice:u,count:c[f].length})),voters:c,ambiguous:o}}function Df(e=process.env){return!!e.VITEST||e.NODE_ENV==="test"||!!e.BUN_TEST}var Ga={isTestEnv:()=>Df(),sleep:(e)=>Ga.isTestEnv()?Promise.resolve():new Promise((t)=>setTimeout(t,e))};function yf(e=process.env){let t=e.SLACK_REACTION_SEED_GAP_MS;if(t===void 0||t==="")return 1100;let n=Number(t);if(!Number.isFinite(n)||n<0)return 1100;return n}async function Mr(e,t,n,r=yf()){for(let s=0;s<e.length;s++){let i=!0;try{await t(e[s])}catch(o){i=!1,n(e[s],o)}if(i&&r>0&&s<e.length-1)await Ga.sleep(r)}}class Bt extends Error{retryAfter;constructor(e){super(`Slack rate limited — retry after ${e}s`);this.name="RateLimitError",this.retryAfter=e}}function vr(){return(process.env.SLACK_API_BASE??"https://slack.com/api").replace(/\/$/,"")}async function Qa(e,t,n,r){let s={};if(r)s.Cookie=`d=${r}`;let i=await fetch(`${vr()}/${t}`,{...n,headers:{...n.headers??{},Authorization:`Bearer ${e}`,...s}});if(i.status===429){let a=parseInt(i.headers.get("retry-after")??"60",10);throw new Bt(isNaN(a)?60:a)}let o=await i.json();if(o.ok!==!0){let a=o.error??"unknown";if(a==="ratelimited")throw new Bt(60);if(a==="invalid_auth"&&e.startsWith("xoxc-")&&!r)throw Error(`Desktop app token (xoxc-) needs its session cookie to be accepted by the public Slack API.
151
151
  Attach it: slack auth chrome (macOS) or slack auth firefox
152
152
  Or replace the token with an xoxp- user token:
153
153
  slack auth token`);if((a==="missing_scope"||a==="cannot_dm_bot")&&e.startsWith("xoxb-"))throw Error(`Slack error on ${t}: ${a} — ${a==="cannot_dm_bot"?`you're authenticated as a bot, so "@you" is the bot itself and it can't DM itself`:"this bot token lacks the user scope this action needs"}.
154
154
  Tailing/DMing people and listing users need a user session, not a bot token.
155
155
  Switch workspace: slack auth ls then slack auth use <name>
156
- Or import your Slack desktop session: slack auth login`);throw Error(`Slack error on ${t}: ${a}`)}return o}async function gf(e,t,n,r){let s={};if(r)s.Cookie=`d=${r}`;let i=await fetch(`${Nr()}/${t}`,{...n,headers:{...n.headers??{},Authorization:`Bearer ${e}`,...s}});if(i.status===429){let a=parseInt(i.headers.get("retry-after")??"60",10);throw new Pt(isNaN(a)?60:a)}let o=await i.json();if(o.ok!==!0){let a=o.error??"unknown";if(a==="ratelimited")throw new Pt(60);if((a==="invalid_auth"||a==="not_authed")&&!e.startsWith("xoxc-"))throw Error(`The draft API requires a desktop app session token (xoxc-).
156
+ Or import your Slack desktop session: slack auth login`);throw Error(`Slack error on ${t}: ${a}`)}return o}async function wf(e,t,n,r){let s={};if(r)s.Cookie=`d=${r}`;let i=await fetch(`${vr()}/${t}`,{...n,headers:{...n.headers??{},Authorization:`Bearer ${e}`,...s}});if(i.status===429){let a=parseInt(i.headers.get("retry-after")??"60",10);throw new Bt(isNaN(a)?60:a)}let o=await i.json();if(o.ok!==!0){let a=o.error??"unknown";if(a==="ratelimited")throw new Bt(60);if((a==="invalid_auth"||a==="not_authed")&&!e.startsWith("xoxc-"))throw Error(`The draft API requires a desktop app session token (xoxc-).
157
157
  Import from Slack desktop: slack auth login`);if((a==="invalid_auth"||a==="not_authed")&&!r)throw Error(`drafts.list also requires the xoxd session cookie.
158
- Attach it with: slack auth chrome (macOS) or slack auth firefox`);throw Error(`Slack error on ${t}: ${a}`)}return o}function Rt(e,t,n={},r){let s=new URLSearchParams({token:e,...n});return gf(e,t,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:s.toString()},r)}function ie(e,t,n,r){let s=new URLSearchParams(n).toString();return Za(e,`${t}?${s}`,{method:"GET"},r)}function ze(e,t,n,r){return Za(e,t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)},r)}async function Qa(e,t){let n=await ie(e,"auth.test",{},t);return{team:n.team??"",teamId:n.team_id??"",url:n.url??"",user:n.user??"",userId:n.user_id??""}}async function ec(e,t){let n={Authorization:`Bearer ${e}`};if(t)n.Cookie=`d=${t}`;let r=await fetch(`${Nr()}/auth.test`,{method:"GET",headers:n});if(r.status===429){let o=parseInt(r.headers.get("retry-after")??"60",10);throw new Pt(isNaN(o)?60:o)}let s=r.headers.get("x-oauth-scopes")??"",i=await r.json();if(i.ok!==!0)throw Error(`Slack error on auth.test: ${i.error??"unknown"}`);return{userId:i.user_id??"",user:i.user??"",botId:i.bot_id??"",team:i.team??"",url:i.url??"",scopes:s.split(",").map((o)=>o.trim()).filter(Boolean)}}async function Ze(e,t,n=20,r,s,i,o){let a={channel:t,limit:String(n)};if(r!==void 0)a.oldest=r;if(s!==void 0)a.cursor=s;if(o)a.inclusive="true";return ie(e,"conversations.history",a,i)}async function He(e,t,n,r=50,s){return ie(e,"conversations.replies",{channel:t,ts:n,limit:String(r)},s)}async function tc(e,t,n){return ie(e,"files.info",{file:t},n)}async function nc(e,t={},n){let r={count:String(Math.min(Math.max(t.count??100,1),200)),page:String(Math.max(t.page??1,1))};if(t.types)r.types=t.types;if(t.channel)r.channel=t.channel;if(t.user)r.user=t.user;return ie(e,"files.list",r,n)}async function sc(e,t,n={},r){let s={list_id:t};if(n.limit)s.limit=String(n.limit);if(n.cursor)s.cursor=n.cursor;return Rt(e,"lists.records.list",s,r)}async function rc(e,t,n,r,s){return ie(e,"search.messages",{query:t,sort:"timestamp",sort_dir:"desc",count:String(Math.min(Math.max(n,1),100)),page:String(Math.max(r,1))},s)}async function ic(e,t,n){return rc(e,t,100,1,n)}async function vr(e,t,n,r){let i=1,o=[],a={ok:!0,messages:{}};while(!0){let u=await rc(e,t,100,i,r),f=hn(u,["messages","matches"]),l=Array.isArray(f)?f:[];o.push(...l);let d=Number(hn(u,["messages","paging","pages"])??1);if(a=u,l.length===0||i>=d||o.length>=n)break;i+=1}let c=a;if(!c.messages)c.messages={};return c.messages.matches=o.slice(0,n),c}async function fs(e,t,n,r,s,i,o){let a=o?{channel:t,text:n}:{channel:t,text:n,blocks:[{type:"markdown",text:n}]};if(r!==void 0)a.thread_ts=r;if(s&&r!==void 0)a.reply_broadcast=!0;return(await ze(e,"chat.postMessage",a,i)).ts??""}async function oc(e,t,n,r,s,i){let o={channel:t,text:n,post_at:r,blocks:[{type:"markdown",text:n}]};if(s!==void 0)o.thread_ts=s;return(await ze(e,"chat.scheduleMessage",o,i)).scheduled_message_id??""}async function ac(e,t,n){let r={};if(t)r.channel=t;return ie(e,"chat.scheduledMessages.list",r,n)}async function cc(e,t,n,r){await ze(e,"chat.deleteScheduledMessage",{channel:t,scheduled_message_id:n},r)}async function gn(e,t,n,r){return(await ie(e,"chat.getPermalink",{channel:t,message_ts:n},r)).permalink??""}async function Xt(e,t,n,r,s,i){return(await ze(e,"chat.update",i?{channel:t,ts:n,text:r}:{channel:t,ts:n,text:r,blocks:[{type:"markdown",text:r}]},s)).ts??n}async function uc(e,t,n,r){await ze(e,"chat.delete",{channel:t,ts:n},r)}async function Gt(e,t,n,r,s){await ze(e,"reactions.add",{channel:t,timestamp:n,name:r},s)}async function lc(e,t,n,r){return((await ie(e,"reactions.get",{channel:t,timestamp:n,full:"true"},r)).message?.reactions??[]).map((i)=>({name:String(i.name??""),users:Array.isArray(i.users)?i.users.map(String):[]}))}async function mn(e,t,n,r,s){await ze(e,"reactions.remove",{channel:t,timestamp:n,name:r},s)}async function fc(e,t,n=!1,r){let s=await ze(e,"conversations.create",{name:t,is_private:n},r);return{id:s.channel?.id??"",name:s.channel?.name??t}}async function dc(e,t,n,r){await ze(e,"conversations.invite",{channel:t,users:n.join(",")},r)}async function Dn(e,t){let n=[],r="";while(!0){let s={limit:"200",types:"public_channel,private_channel,im,mpim"};if(r)s.cursor=r;let i=await ie(e,"conversations.list",s,t);if(n.push(...i.channels??[]),r=i.response_metadata?.next_cursor??"",!r)break}return{channels:n}}async function Mt(e,t,n){let s=(await ze(e,"conversations.open",{users:t},n)).channel?.id;if(!s)throw Error(`Failed to open DM with user ${t}`);return s}async function pc(e,t,n){let r="";while(!0){let s={types:"im",limit:"200"};if(r)s.cursor=r;let i=await ie(e,"conversations.list",s,n);for(let o of i.channels??[])if(o.user===t)return String(o.id??"");if(r=i.response_metadata?.next_cursor??"",!r)break}return""}async function Mr(e,t,n,r){let s=await pc(e,t,n);if(s)return s;let i=r?`${r} (${t})`:t;throw Error(`No existing DM with ${i}. Open it once in Slack first.`)}function Tt(e){return e.toLowerCase().replace(/[-_\s]/g,"")}function Ga(e,t){let n=Tt(e.name??""),r=Tt(e.real_name??e.profile?.real_name??""),s=Tt(e.profile?.display_name??"");return n===t||r===t||!!s&&s===t}var hc=200;async function gc(e,t,n){let r=0,s=new Set,i="";while(!0){let f={limit:"200"};if(i)f.cursor=i;let l=await ie(e,"users.list",f,n);for(let d of l.members??[]){if(r++,d.id)s.add(d.id);if(Ga(d,t))return{id:d.id??"",workspaceCount:r,connectCount:0,skipped:0,capped:!1}}if(i=l.response_metadata?.next_cursor??"",!i)break}let o=0,a=0,c=!1,u="";while(!0){let f={types:"im",limit:"200"};if(u)f.cursor=u;let l=await ie(e,"conversations.list",f,n);for(let d of l.channels??[]){let p=d.user;if(!p||s.has(p))continue;if(o>=hc){c=!0;break}s.add(p),o++;let m;try{m=(await ie(e,"users.info",{user:p},n)).user}catch(g){if(g instanceof Pt)throw g;a++;continue}if(m&&Ga(m,t))return{id:p,dm:String(d.id??""),workspaceCount:r,connectCount:o,skipped:a,capped:c}}if(c)break;if(u=l.response_metadata?.next_cursor??"",!u)break}return{id:"",workspaceCount:r,connectCount:o,skipped:a,capped:c}}function mc(e,t){if(t.workspaceCount===0)return Error(`Cannot resolve ${e}: users.list returned no members at all, so nothing could have matched.
158
+ Attach it with: slack auth chrome (macOS) or slack auth firefox`);throw Error(`Slack error on ${t}: ${a}`)}return o}function Nt(e,t,n={},r){let s=new URLSearchParams({token:e,...n});return wf(e,t,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:s.toString()},r)}function ie(e,t,n,r){let s=new URLSearchParams(n).toString();return Qa(e,`${t}?${s}`,{method:"GET"},r)}function ze(e,t,n,r){return Qa(e,t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)},r)}async function ec(e,t){let n=await ie(e,"auth.test",{},t);return{team:n.team??"",teamId:n.team_id??"",url:n.url??"",user:n.user??"",userId:n.user_id??""}}async function tc(e,t){let n={Authorization:`Bearer ${e}`};if(t)n.Cookie=`d=${t}`;let r=await fetch(`${vr()}/auth.test`,{method:"GET",headers:n});if(r.status===429){let o=parseInt(r.headers.get("retry-after")??"60",10);throw new Bt(isNaN(o)?60:o)}let s=r.headers.get("x-oauth-scopes")??"",i=await r.json();if(i.ok!==!0)throw Error(`Slack error on auth.test: ${i.error??"unknown"}`);return{userId:i.user_id??"",user:i.user??"",botId:i.bot_id??"",team:i.team??"",url:i.url??"",scopes:s.split(",").map((o)=>o.trim()).filter(Boolean)}}async function Ze(e,t,n=20,r,s,i,o){let a={channel:t,limit:String(n)};if(r!==void 0)a.oldest=r;if(s!==void 0)a.cursor=s;if(o)a.inclusive="true";return ie(e,"conversations.history",a,i)}async function He(e,t,n,r=50,s){return ie(e,"conversations.replies",{channel:t,ts:n,limit:String(r)},s)}async function nc(e,t,n){return ie(e,"files.info",{file:t},n)}async function sc(e,t={},n){let r={count:String(Math.min(Math.max(t.count??100,1),200)),page:String(Math.max(t.page??1,1))};if(t.types)r.types=t.types;if(t.channel)r.channel=t.channel;if(t.user)r.user=t.user;return ie(e,"files.list",r,n)}async function rc(e,t,n={},r){let s={list_id:t};if(n.limit)s.limit=String(n.limit);if(n.cursor)s.cursor=n.cursor;return Nt(e,"lists.records.list",s,r)}async function ic(e,t,n,r,s){return ie(e,"search.messages",{query:t,sort:"timestamp",sort_dir:"desc",count:String(Math.min(Math.max(n,1),100)),page:String(Math.max(r,1))},s)}async function oc(e,t,n){return ic(e,t,100,1,n)}async function jr(e,t,n,r){let i=1,o=[],a={ok:!0,messages:{}};while(!0){let u=await ic(e,t,100,i,r),f=hn(u,["messages","matches"]),l=Array.isArray(f)?f:[];o.push(...l);let d=Number(hn(u,["messages","paging","pages"])??1);if(a=u,l.length===0||i>=d||o.length>=n)break;i+=1}let c=a;if(!c.messages)c.messages={};return c.messages.matches=o.slice(0,n),c}async function ps(e,t,n,r,s,i,o){let a=o?{channel:t,text:n}:{channel:t,text:n,blocks:[{type:"markdown",text:n}]};if(r!==void 0)a.thread_ts=r;if(s&&r!==void 0)a.reply_broadcast=!0;return(await ze(e,"chat.postMessage",a,i)).ts??""}async function ac(e,t,n,r,s,i){let o={channel:t,text:n,post_at:r,blocks:[{type:"markdown",text:n}]};if(s!==void 0)o.thread_ts=s;return(await ze(e,"chat.scheduleMessage",o,i)).scheduled_message_id??""}async function cc(e,t,n){let r={};if(t)r.channel=t;return ie(e,"chat.scheduledMessages.list",r,n)}async function uc(e,t,n,r){await ze(e,"chat.deleteScheduledMessage",{channel:t,scheduled_message_id:n},r)}async function gn(e,t,n,r){return(await ie(e,"chat.getPermalink",{channel:t,message_ts:n},r)).permalink??""}async function Gt(e,t,n,r,s,i){return(await ze(e,"chat.update",i?{channel:t,ts:n,text:r}:{channel:t,ts:n,text:r,blocks:[{type:"markdown",text:r}]},s)).ts??n}async function lc(e,t,n,r){await ze(e,"chat.delete",{channel:t,ts:n},r)}async function Vt(e,t,n,r,s){await ze(e,"reactions.add",{channel:t,timestamp:n,name:r},s)}async function fc(e,t,n,r){return((await ie(e,"reactions.get",{channel:t,timestamp:n,full:"true"},r)).message?.reactions??[]).map((i)=>({name:String(i.name??""),users:Array.isArray(i.users)?i.users.map(String):[]}))}async function mn(e,t,n,r,s){await ze(e,"reactions.remove",{channel:t,timestamp:n,name:r},s)}async function dc(e,t,n=!1,r){let s=await ze(e,"conversations.create",{name:t,is_private:n},r);return{id:s.channel?.id??"",name:s.channel?.name??t}}async function pc(e,t,n,r){await ze(e,"conversations.invite",{channel:t,users:n.join(",")},r)}async function Dn(e,t){let n=[],r="";while(!0){let s={limit:"200",types:"public_channel,private_channel,im,mpim"};if(r)s.cursor=r;let i=await ie(e,"conversations.list",s,t);if(n.push(...i.channels??[]),r=i.response_metadata?.next_cursor??"",!r)break}return{channels:n}}async function ct(e,t,n){let s=(await ze(e,"conversations.open",{users:t},n)).channel?.id;if(!s)throw Error(`Failed to open DM with user ${t}`);return s}async function hc(e,t,n){let r="";while(!0){let s={types:"im",limit:"200"};if(r)s.cursor=r;let i=await ie(e,"conversations.list",s,n);for(let o of i.channels??[])if(o.user===t)return String(o.id??"");if(r=i.response_metadata?.next_cursor??"",!r)break}return""}async function Br(e,t,n,r){let s=await hc(e,t,n);if(s)return s;let i=r?`${r} (${t})`:t;throw Error(`No existing DM with ${i}. Open it once in Slack first.`)}function Mt(e){return e.toLowerCase().replace(/[-_\s]/g,"")}function Va(e,t){let n=Mt(e.name??""),r=Mt(e.real_name??e.profile?.real_name??""),s=Mt(e.profile?.display_name??"");return n===t||r===t||!!s&&s===t}var gc=200;async function mc(e,t,n){let r=0,s=new Set,i="";while(!0){let f={limit:"200"};if(i)f.cursor=i;let l=await ie(e,"users.list",f,n);for(let d of l.members??[]){if(r++,d.id)s.add(d.id);if(Va(d,t))return{id:d.id??"",workspaceCount:r,connectCount:0,skipped:0,capped:!1}}if(i=l.response_metadata?.next_cursor??"",!i)break}let o=0,a=0,c=!1,u="";while(!0){let f={types:"im",limit:"200"};if(u)f.cursor=u;let l=await ie(e,"conversations.list",f,n);for(let d of l.channels??[]){let p=d.user;if(!p||s.has(p))continue;if(o>=gc){c=!0;break}s.add(p),o++;let m;try{m=(await ie(e,"users.info",{user:p},n)).user}catch(g){if(g instanceof Bt)throw g;a++;continue}if(m&&Va(m,t))return{id:p,dm:String(d.id??""),workspaceCount:r,connectCount:o,skipped:a,capped:c}}if(c)break;if(u=l.response_metadata?.next_cursor??"",!u)break}return{id:"",workspaceCount:r,connectCount:o,skipped:a,capped:c}}function Dc(e,t){if(t.workspaceCount===0)return Error(`Cannot resolve ${e}: users.list returned no members at all, so nothing could have matched.
159
159
  `+`That is a token or scope fault, not a wrong handle — this says nothing about whether ${e} exists.
160
- Check who you are: slack auth ls`);let n=t.connectCount?`${t.workspaceCount} workspace account(s) and ${t.connectCount} Slack Connect DM partner(s)`:`${t.workspaceCount} workspace account(s)`,r=[];if(t.capped)r.push(`stopped after ${hc} Slack Connect DM partners, so there may be more`);if(t.skipped)r.push(`${t.skipped} DM partner profile(s) could not be read and were never compared`);return Error(`User not found: ${e} — searched ${n}, none matched.
160
+ Check who you are: slack auth ls`);let n=t.connectCount?`${t.workspaceCount} workspace account(s) and ${t.connectCount} Slack Connect DM partner(s)`:`${t.workspaceCount} workspace account(s)`,r=[];if(t.capped)r.push(`stopped after ${gc} Slack Connect DM partners, so there may be more`);if(t.skipped)r.push(`${t.skipped} DM partner profile(s) could not be read and were never compared`);return Error(`User not found: ${e} — searched ${n}, none matched.
161
161
  `+(r.length?`This search was incomplete: ${r.join("; ")}.
162
162
  `:"")+`Slack Connect people from another workspace are not in users.list, so if they never
163
163
  DMed you they cannot be found by name at all. Look them up and use their ID:
164
- slack user ls --external`)}async function Vt(e,t,n){let r=t.startsWith("@")?t.slice(1):t;if(Br(r))return r;if(!t.startsWith("@"))throw Error(`Expected @user or a user ID, got: ${t}`);let s=Tt(r),i=await ie(e,"auth.test",{},n);if(s==="you"||s==="me"||Tt(i.user??"")===s){if(!i.user_id)throw Error("auth.test did not return user_id");return i.user_id}let o=await gc(e,s,n);if(o.id)return o.id;throw mc(t,o)}function Bt(e){let t=e.match(/(?:app\.slack\.com\/client\/T[A-Za-z0-9]+|[A-Za-z0-9-]+\.slack\.com\/archives)\/([A-Za-z0-9]+)(?:\/p(\d{10})(\d{6}))?/);if(!t)return;let n=t[1],r=t[2]&&t[3]?`${t[2]}.${t[3]}`:void 0,s=e.indexOf("?"),i=s>=0?new URLSearchParams(e.slice(s)):void 0,o=i?.get("thread_ts")??void 0,u={channel:i?.get("cid")??void 0??n};if(r)u.ts=r;if(o)u.threadTs=o;return u}function mf(e){return Bt(e)?.channel}function Va(e){return/^[CDG][A-Z0-9]{8,}$/.test(e)}function Br(e){return/^[UW][A-Z0-9]{6,}$/.test(e)}async function De(e,t,n){let r=mf(t);if(r)return r;if(!t.startsWith("@")&&!t.startsWith("#")){if(Va(t))return t;if(Br(t))return Mr(e,t,n);throw Error(`Target must start with # or @ (or be a Slack URL/ID), got: ${t}`)}if(t.startsWith("#")&&Va(t.slice(1)))return t.slice(1);let s=t.startsWith("@"),i=t.slice(1),o=Tt(i);if(s){if(Br(i))return Mr(e,i,n);let u=await ie(e,"auth.test",{},n);if(o==="you"||o==="me"||Tt(u.user??"")===o){let d=u.user_id;if(!d)throw Error("auth.test did not return user_id");return await pc(e,d,n)||Mt(e,d,n)}let l=await gc(e,o,n);if(!l.id)throw mc(t,l);if(l.dm)return l.dm;return Mr(e,l.id,n,t)}let a=i.toLowerCase(),c="";while(!0){let u={limit:"200",types:"public_channel,private_channel",exclude_archived:"true"};if(c)u.cursor=c;let f=await ie(e,"conversations.list",u,n);for(let l of f.channels??[])if(String(l.name??"").toLowerCase()===a)return String(l.id??"");if(c=f.response_metadata?.next_cursor??"",!c)break}throw Error(`channel not found: ${t}`)}async function yn(e,t,n){try{let r=await ie(e,"users.info",{user:t},n),s=r.user?.profile?.display_name,i=s&&s.length>0?s:r.user?.real_name??r.user?.name??t,o=r.user?.name??t;return[i,o]}catch{return[t,t]}}async function qe(e,t,n){try{let r=await ie(e,"users.info",{user:t},n),s=r.user?.profile?.display_name;if(s&&s.length>0)return s;return r.user?.real_name??r.user?.name??t}catch{return t}}async function Dc(e,t){let n=[],r="";while(!0){let s={limit:"200"};if(r)s.cursor=r;let i=await ie(e,"users.list",s,t);if(n.push(...i.members??[]),r=i.response_metadata?.next_cursor??"",!r)break}return{members:n}}async function yc(e,t,n){let r=[],s="";while(!0){let i={channel:t,limit:"200"};if(s)i.cursor=s;let o=await ie(e,"conversations.members",i,n);if(r.push(...o.members??[]),s=o.response_metadata?.next_cursor??"",!s)break}return r}async function wn(e,t){return Rt(e,"drafts.list",{},t)}async function wc(e,t,n,r){let{randomUUID:s}=await import("node:crypto"),i=JSON.stringify([{type:"rich_text",elements:[{type:"rich_text_section",elements:[{type:"text",text:n}]}]}]);return Rt(e,"drafts.create",{client_msg_id:s(),destinations:JSON.stringify([{channel_id:t}]),blocks:i,file_ids:JSON.stringify([]),is_from_composer:"true"},r)}async function bc(e,t,n,r,s){let i=JSON.stringify([{type:"rich_text",elements:[{type:"rich_text_section",elements:[{type:"text",text:r}]}]}]),o=(Date.now()/1000).toFixed(6);return Rt(e,"drafts.update",{draft_id:t,client_last_updated_ts:o,destinations:JSON.stringify([{channel_id:n}]),blocks:i,file_ids:JSON.stringify([])},s)}async function Fc(e,t,n){return Rt(e,"conversations.info",{channel:t},n)}async function bn(e,t,n){return ie(e,"users.info",{user:t},n)}async function Fn(e,t,n){return ie(e,"conversations.info",{channel:t},n)}async function Cc(e,t,n){let r=(Date.now()/1000).toFixed(6);return Rt(e,"drafts.delete",{draft_id:t,client_last_updated_ts:r},n)}async function jr(e,t){let n=await Rt(e,"auth.test",{},t);return{userId:String(n.user_id??""),teamId:String(n.team_id??"")}}async function Ec(e,t,n,r={},s){let{statSync:i,readFileSync:o}=await import("node:fs"),{basename:a}=await import("node:path"),c=i(n),u=a(n),f=await ie(e,"files.getUploadURLExternal",{filename:u,length:String(c.size)},s),l=f.upload_url,d=f.file_id;if(!l||!d)throw Error("files.getUploadURLExternal returned no upload_url/file_id");let p=o(n),m=await fetch(l,{method:"POST",headers:{"Content-Type":"application/octet-stream"},body:p});if(!m.ok)throw Error(`Upload PUT failed: ${m.status} ${m.statusText}`);let g={files:[{id:d,title:r.title??u}],channel_id:t};if(r.threadTs)g.thread_ts=r.threadTs;if(r.initialComment)g.initial_comment=r.initialComment;let y=await ze(e,"files.completeUploadExternal",g,s),C={fileId:d},F=y.files?.[0]?.permalink;if(F)C.permalink=F;return C}function hn(e,t){let n=e;for(let r of t){if(n===void 0||n===null)return;if(typeof r==="number"){if(!Array.isArray(n))return;n=n[r]??void 0}else{if(typeof n!=="object"||Array.isArray(n))return;n=n[r]}}return n}import{existsSync as Sf,readFileSync as kf}from"node:fs";import{homedir as Af}from"node:os";import{join as $f}from"node:path";import{existsSync as Df,mkdirSync as yf,readFileSync as wf,writeFileSync as bf}from"node:fs";import{homedir as Ff}from"node:os";import{dirname as Cf,join as Ef}from"node:path";var xf=3600000,ds={now:()=>Date.now(),path:()=>Ef(process.env.HOME||Ff(),".config","slack-cli","cache.json")},ps=!0,ct;function xc(){return{channels:{},users:{}}}function Lr(){if(ct)return ct;if(ct=xc(),!ps)return ct;try{let e=ds.path();if(!Df(e))return ct;let t=JSON.parse(wf(e,"utf8"));for(let n of["channels","users"]){let r=t?.[n];if(!r||typeof r!=="object"||Array.isArray(r))continue;for(let[s,i]of Object.entries(r))if(i&&typeof i==="object"&&typeof i.value==="string"&&typeof i.expires==="number")ct[n][s]={value:i.value,expires:i.expires}}}catch{ct=xc()}return ct}function _f(e){if(!ps)return;try{let t=ds.path();yf(Cf(t),{recursive:!0}),bf(t,JSON.stringify(e,null,2)+`
165
- `)}catch{}}function _c(e,t){return e?`${e} ${t}`:void 0}function hs(e,t,n){if(!ps)return;let r=_c(t,n);if(!r)return;let s=Lr()[e][r];if(!s)return;if(s.expires<=ds.now()){delete Lr()[e][r];return}return s.value}function gs(e,t,n,r,s=xf){if(!ps)return;let i=_c(t,n);if(!i)return;let o=Lr();o[e][i]={value:r,expires:ds.now()+s},_f(o)}var Wr={marker:"pushpin",progress:{done:"white_check_mark",dropped:"no_entry_sign",doing:"eyes",pending:"hourglass_flowing_sand"},flags:{alert:"exclamation","needs-discussion":"thinking_face",waiting:"speech_balloon",blocked:"lock"}},Zt=["done","dropped","doing","pending"],$c=["alert","needs-discussion","waiting","blocked"];function Of(){return $f(process.env.HOME||Af(),".config","slack-cli","todo.json")}function ms(e){return e.replace(/^:+|:+$/g,"")}function Cn(e=Of()){let t={marker:Wr.marker,progress:{...Wr.progress},flags:{...Wr.flags}};try{if(!Sf(e))return t;let n=JSON.parse(kf(e,"utf8"));if(typeof n.marker==="string"&&n.marker.trim())t.marker=ms(n.marker.trim());for(let r of Zt){let s=n.progress?.[r];if(typeof s==="string"&&s.trim())t.progress[r]=ms(s.trim())}for(let r of $c){let s=n.flags?.[r];if(typeof s==="string"&&s.trim())t.flags[r]=ms(s.trim())}}catch{}return t}function Sc(e,t,n=!1){return`${n?"-":""}${t?"has":"hasmy"}::${ms(e)}:`}function Oc(e,t,n={}){let r=n.shared===!0,s=(a)=>Sc(a,r),i=(a)=>Sc(a,r,!0),o=[];if(e==="untriaged")o.push(s(t.marker),...Zt.map((a)=>i(t.progress[a])));else if(e==="stuck")o.push(s(t.marker),i(t.progress.done),i(t.progress.dropped),`(${$c.map((a)=>s(t.flags[a])).join(" OR ")})`);else if(e==="open")o.push(s(t.marker),i(t.progress.done),i(t.progress.dropped));else{let a=Zt.indexOf(e);o.push(s(t.progress[e]));for(let c of Zt.slice(0,a))o.push(i(t.progress[c]))}if(n.in){let a=n.in.startsWith("#")||n.in.startsWith("@")?n.in:`#${n.in}`;o.push(`in:${a}`)}if(n.from){let a=n.from==="me"||n.from.startsWith("@")?n.from:`@${n.from}`;o.push(`from:${a}`)}return o.join(" ")}var If=3,Tf={sleep:(e)=>Pf()?Promise.resolve():new Promise((t)=>setTimeout(t,e))};function Pf(){return!!process.env.VITEST||!1||!!process.env.BUN_TEST}async function _e(e,t,n=If){for(let r=0;;r++)try{return await t()}catch(s){if(!(s instanceof We))throw s;if(r>=n)throw Error(`Slack rate limit hit on ${e} — gave up after ${n} retries. Try again in a minute.`);console.error(`Warning: Slack rate limit hit on ${e} — backing off for ${s.retryAfter}s`),await Tf.sleep(s.retryAfter*1000)}}var kc=new Map;async function Ic(e,t){let n=kc.get(e);if(n)return n;let r=await _e("auth.test",()=>qt(e,t)),s={userId:r.userId,teamId:r.teamId};return kc.set(e,s),s}async function Tc(e,t){return(await Ic(e,t)).userId}async function Ur(e,t){try{return(await Ic(e,t)).teamId}catch{return""}}async function Kr(e,t,n,r){if(!t.startsWith("#"))return n(e,t,r);let s=await Ur(e,r),i=hs("channels",s,t);if(i)return i;let o=await _e("resolveChannel",()=>n(e,t,r));return gs("channels",s,t,o),o}async function Pc(e,t,n,r){let s=await Ur(e,r),i=hs("users",s,t);if(i)return i;let o=await _e("users.info",()=>n(e,t,r));if(o&&o!==t)gs("users",s,t,o);return o}async function Rc(e,t,n,r){let s=await Ur(e,r),i=hs("users",s,`tz:${t}`);if(i)return i==="?"?null:i;let o=null;try{let a=await _e("users.info",()=>n(e,t,r));if(a?.user?.is_bot===!0||t==="USLACKBOT")return Ac(s,t,null);let c=a?.user?.tz;o=typeof c==="string"&&c?c:null}catch{return null}return Ac(s,t,o)}function Ac(e,t,n){return gs("users",e,`tz:${t}`,n??"?"),n}async function Mc(e,t,n,r,s,i){let o=s.progress[r],a=await Tc(e,i),c=await _e("reactions.get",()=>Zo(e,t,n,i)),u=new Set(c.filter((p)=>p.users.includes(a)).map((p)=>p.name)),f=Zt.map((p)=>s.progress[p]).filter((p)=>u.has(p));if(f.length===1&&f[0]===o)return{noop:!0,removed:[],leftover:[]};if(!u.has(o))await _e("reactions.add",()=>Hn(e,t,n,o,i));let l=[],d=[];for(let p of f){if(p===o)continue;try{await _e("reactions.remove",()=>qn(e,t,n,p,i)),l.push(p)}catch{d.push(p)}}return{noop:!1,added:r,removed:l,leftover:d}}async function Bc(e,t,n,r,s,i,o){let a=s.flags[r];if(i)await _e("reactions.remove",()=>qn(e,t,n,a,o));else await _e("reactions.add",()=>Hn(e,t,n,a,o));return a}var Jr=1000;async function Nc(e,t,n,r={}){let s=r.limit??Jr,i=r.cookie,o=await Tc(e,i),a=Zt.map((d)=>n.progress[d]),c=[],u=0,f,l=!1;while(u<s){let d=Math.min(200,s-u),p=await _e("conversations.history",()=>un(e,t,d,void 0,f,i)),m=p.messages??[];u+=m.length;for(let g of m){let y=String(g.ts??"");if(!y)continue;let C=new Set((g.reactions??[]).filter((k)=>(k.users??[]).map(String).includes(o)).map((k)=>String(k.name??""))),F=a.filter((k)=>C.has(k));if(F.length<2)continue;c.push({ts:y,text:String(g.text??"").split(`
166
- `)[0]??"",emoji:F,keep:F[0]})}if(f=p.response_metadata?.next_cursor||void 0,!f||m.length===0)break;if(u>=s){l=!0;break}}if(r.fix)for(let d of c)try{try{await _e("reactions.add",()=>Hn(e,t,d.ts,d.keep,i))}catch(p){if(!(p instanceof Error)||!/already_reacted/.test(p.message))throw p}for(let p of d.emoji){if(p===d.keep)continue;await _e("reactions.remove",()=>qn(e,t,d.ts,p,i))}d.fixed=!0}catch(p){d.fixed=!1,d.error=p instanceof Error?p.message:String(p)}return{scanned:u,findings:c,truncated:l}}var Rf=!0,Mf;function zr(e){if(Rf=e,!e)Mf=void 0}function ut(e){return e.replace(new RegExp(`[${"\\\\¥"}](.)`,"gs"),(t,n)=>{switch(n){case"n":return`
167
- `;case"t":return"\t";case"\\":case"¥":return n==="¥"?"¥":"\\";default:return t}})}function Nt(e){return e.toLowerCase().replace(/[-_\s]/g,"")}function lt(e){return e&&typeof e==="object"&&!Array.isArray(e)?e:{}}function Bf(e,t){let n=Nt(t),r=lt(e.profile);for(let i of[e.name,e.real_name,r.display_name,r.real_name])if(typeof i==="string"&&i&&Nt(i)===n)return!0;let s=typeof r.email==="string"?r.email.toLowerCase():"";return s!==""&&s===t.toLowerCase()}function Nf(e){let t=lt(e.profile),n=new Set;for(let r of[t.display_name,e.real_name,e.name,t.real_name])if(typeof r==="string"&&r){let s=Nt(r);if(s.length>=2)n.add(s)}return[...n]}function vf(e,t){let n=Nt(e),r,s=!1;for(let i of t){let o=typeof i.id==="string"?i.id:"";if(!o)continue;for(let a of Nf(i)){let c=-1;if(n===a)c=e.length;else for(let u of jc)if(e.length>u.length&&e.endsWith(u)&&Nt(e.slice(0,e.length-u.length))===a){c=e.length-u.length;break}if(c<0)continue;if(!r||a.length>r.formLen)r={userId:o,matchLen:c,formLen:a.length,display:Yr(i)},s=!1;else if(a.length===r.formLen&&r.userId!==o)s=!0}}if(!r)return;return s?"ambiguous":{userId:r.userId,matchLen:r.matchLen,display:r.display}}async function vt(e,t,n,r){let s=`[${Lc}ー]+`,i=`${s}(?:[._-]+${s})*`,o=new RegExp(`(?<![A-Za-z0-9._@<-])@(${i})`,"gu"),a=new Set;for(let F of t.matchAll(o))a.add(F[1]);if(a.size===0)return{text:t,resolved:[],unresolved:[]};let c=new Map;for(let F of a)c.set(F,{status:"pending"});let u=(F)=>{for(let k of a){if(c.get(k).status!=="pending")continue;if(qr(k)){let S=vf(k,F);if(S==="ambiguous")c.set(k,{status:"ambiguous"});else if(S)c.set(k,{status:"resolved",userId:S.userId,matchLen:S.matchLen,display:S.display})}else{let S=F.filter((A)=>Bf(A,k)),L=new Set(S.map((A)=>typeof A.id==="string"?A.id:"").filter(Boolean));if(L.size===1){let A=S.find((R)=>typeof R.id==="string");c.set(k,{status:"resolved",userId:A.id,matchLen:k.length,display:Yr(A)})}else if(L.size>1)c.set(k,{status:"ambiguous"})}}},f=!1;try{let F=await Gn(e,r);u((F.members??[]).map(lt)),f=!0}catch{f=!1}let l=[...a].some((F)=>c.get(F).status==="pending"),d=!1,p=!0;if(l&&n){d=!0;try{let F=await pr(e,n,r),k=[];for(let S of F){let L=lt(await hr(e,S,r)),A=lt(L.user);if(typeof A.id!=="string")A.id=S;k.push(A)}u(k)}catch{p=!1}}let m=f&&(n?d&&p:!0),g=[],y=[];for(let F of a){let k=c.get(F);if(k.status==="resolved")g.push({surface:`@${F.slice(0,k.matchLen)}`,display:k.display,userId:k.userId});else if(k.status==="ambiguous")y.push({surface:`@${F}`,reason:"ambiguous"});else y.push({surface:`@${F}`,reason:m?"no-match":"unavailable"})}return{text:t.replace(o,(F,k)=>{let S=c.get(k);if(S&&S.status==="resolved")return`<@${S.userId}>${k.slice(S.matchLen)}`;return F}),resolved:g,unresolved:y}}function En(e){let t=[],n=!1;for(let r of e)if(r.reason==="ambiguous")t.push(`${r.surface} matches multiple people — not tagged, sent as plain text (use <@USERID> to tag)`);else if(r.reason==="unavailable"){if(n)continue;t.push("could not fetch the user list (users:read missing or an API/connection error) — @mentions not tagged, sent as plain text"),n=!0}else t.push(`${r.surface} matched no one — not tagged, sent as plain text`);return t}async function vc(e,t,n,r={}){let s=r.warn??((o)=>process.stderr.write(`${o}
168
- `)),i=await vt(e,t,n,r.cookie);for(let o of En(i.unresolved))s(`warn: ${o}`);return i.text}var jc=["さん","さま","様","君","くん","ちゃん","氏","先生","先輩","殿","老师","老師","兄","姐","哥","姐妹"],Lc="\\p{Script=Han}\\p{Script=Hiragana}\\p{Script=Katakana}A-Za-z0-9";function qr(e){return/[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}]/u.test(e)}function jf(e){let t=[],n=new RegExp(`([${Lc}]{1,12})(${jc.join("|")})`,"gu");for(let r of e.matchAll(n))t.push({ref:r[1],honorific:r[2]});for(let r of e.matchAll(/\b(?:dear|hi|hello|hey)\b[ \t]+([A-Z][A-Za-z'’-]{1,20})/gi))t.push({ref:r[1],honorific:""});for(let r of e.matchAll(/(?:^|\n)[ \t]*([A-Z][A-Za-z'’-]{1,20}),/g))t.push({ref:r[1],honorific:""});return t}function Lf(e){let t=lt(e.profile),n=new Set;for(let r of[e.name,e.real_name,t.display_name,t.real_name]){if(typeof r!=="string"||!r)continue;for(let s of[r,...r.split(/\s+/)]){let i=Nt(s);if(i.length>=2)n.add(i)}}return[...n]}function Wf(e,t){let n=Nt(e);if(n.length<2)return;for(let r of t)if(n===r)return r;if(qr(e)){for(let r of t)if(n.includes(r)||r.includes(n))return r}return}function Yr(e){return[lt(e.profile).display_name,e.real_name,e.name].filter((r)=>typeof r==="string"&&r!=="")[0]??String(e.id??"?")}async function Wc(e,t,n){let r=jf(t);if(r.length===0)return[];let s=new Set;for(let u of t.matchAll(/<@([A-Z0-9]+)(?:\|[^>]*)?>/g))s.add(u[1]);let o=((await Gn(e,n)).members??[]).map(lt).filter((u)=>u.deleted!==!0&&u.is_bot!==!0&&u.id!=="USLACKBOT").map((u)=>({id:typeof u.id==="string"?u.id:"",forms:Lf(u),display:Yr(u)})).filter((u)=>u.id!==""),a=[],c=new Set;for(let{ref:u,honorific:f}of r)for(let l of o){let d=Wf(u,l.forms);if(!d)continue;if(s.has(l.id)||c.has(l.id))break;c.add(l.id),a.push({surface:qr(u)?`${d}${f}`:u,display:l.display,userId:l.id});break}return a}async function Qt(e,t,n,r){let s=t,i=[],o=s,a=0;while(!0){let c=o.indexOf("<@U",a);if(c===-1)break;let u=o.slice(c+2),f=u.search(/[>|]/),l=f===-1?u:u.slice(0,f);if(l.length>=9)i.push(l);a=c+1}for(let c of i){if(!n.has(c))n.set(c,await Xn(e,c,r));let u=n.get(c)??c;s=s.replaceAll(`<@${c}>`,`@${u}`),s=s.replace(new RegExp(`<@${c}\\|[^>]*>`,"g"),`@${u}`)}return s}function xn(e){return e.replace(/<!date\^(\d+)\^[^|>]*(?:\|([^>]*))?>/g,(t,n,r)=>{let s=Number(n);if(!Number.isFinite(s))return r??"date";let i=new Date(s*1000);if(Number.isNaN(i.getTime()))return r??"date";let o=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],a=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],c=o[i.getUTCDay()]??"",u=a[i.getUTCMonth()]??"";return`${c}, ${u} ${String(i.getUTCDate()).padStart(2,"0")}, ${i.getUTCFullYear()}`})}function Uc(e,t=new Date){let n=new Date(e*1000),r=Hr(t),s=Hr(new Date(t.getTime()-86400000)),i=Hr(n);if(i===r)return"Today";if(i===s)return"Yesterday";let o=n.toLocaleDateString("en-US",{weekday:"long"}),a=n.toLocaleDateString("en-US",{month:"short"});return`${o}, ${a} ${String(n.getDate()).padStart(2,"0")}`}function Hr(e){return`${e.getFullYear()}-${e.getMonth()}-${e.getDate()}`}function Kc(e){let t=new Date(e*1000),n=t.getFullYear(),r=String(t.getMonth()+1).padStart(2,"0"),s=String(t.getDate()).padStart(2,"0"),i=String(t.getHours()).padStart(2,"0"),o=String(t.getMinutes()).padStart(2,"0");return`${n}-${r}-${s} ${i}:${o}`}function Jc(e=new Date,t){let n=process.env.SLACK_QUIET_TZ??"Asia/Tokyo",r=!!t&&Uf(t),s=r?t:n,i=Number(process.env.SLACK_QUIET_START??23),o=Number(process.env.SLACK_QUIET_END??8),a,c;try{let p=new Intl.DateTimeFormat("en-GB",{timeZone:s,hour12:!1,weekday:"short",year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"});c=p.format(e),a=Number(p.formatToParts(e).find((m)=>m.type==="hour")?.value??"12")}catch{return null}let u=i>o?a>=i||a<o:a>=i&&a<o,f=r?`${s}, recipient`:`${s}, sender — recipient's timezone unknown`,l=`\uD83D\uDD50 ${c} (${f})`;if(!u)return l;return`${l}
169
- ⚠ QUIET HOURS (${i}:00-${o}:00) — this will buzz a phone.${r?"":" Their local time may differ."} Send only for a production incident; otherwise hold it until morning.`}function Uf(e){try{return new Intl.DateTimeFormat("en-GB",{timeZone:e}),!0}catch{return!1}}function _n(e){if(!Gc(e))return;let t=Jf(e,"utf8");for(let n of t.split(`
170
- `)){let r=n.trim();if(!r||r.startsWith("#"))continue;let s=r.indexOf("=");if(s===-1)continue;let i=r.slice(0,s).trim(),o=r.slice(s+1).trim();if(o.startsWith('"')&&o.endsWith('"')||o.startsWith("'")&&o.endsWith("'"))o=o.slice(1,-1);if(!(i in process.env))process.env[i]=o}}function Hf(e){zf(e,{recursive:!0});let t=ft(e,".gitignore");if(!Gc(t))Vc(t,`*
171
- `)}function qf(){_n(ft(zc(),".slack-cli",".env.local")),_n(ft(zc(),".config/slack-cli",".env")),_n(ft(process.cwd(),".slack-cli",".env.local")),_n(ft(process.cwd(),".env.local")),_n(ft(process.cwd(),".env"))}function Yf(e){return Kf("sha256").update(e).digest("hex")}function T(e){return e&&typeof e==="object"&&!Array.isArray(e)?e:{}}function X(e){return Array.isArray(e)?e:[]}function Ds(e){return Number(e.ts??0)}async function Zc(e,t,n){let r=t.user;if(typeof r==="string"){if(!n.has(r))n.set(r,await qe(e,r));return n.get(r)??r}return typeof t.username==="string"?t.username:"bot"}function Xr(e){let t=new Date(e*1000),n=t.getUTCFullYear(),r=String(t.getUTCMonth()+1).padStart(2,"0"),s=String(t.getUTCDate()).padStart(2,"0"),i=String(t.getUTCHours()).padStart(2,"0"),o=String(t.getUTCMinutes()).padStart(2,"0"),a=String(t.getUTCSeconds()).padStart(2,"0");return`${n}-${r}-${s} ${i}:${o}:${a}`}function Vr(e){let[t,n="000000"]=e.split("."),r=Number(t),s=new Date(r*1000),i=s.getUTCFullYear(),o=String(s.getUTCMonth()+1).padStart(2,"0"),a=String(s.getUTCDate()).padStart(2,"0"),c=String(s.getUTCHours()).padStart(2,"0"),u=String(s.getUTCMinutes()).padStart(2,"0"),f=String(s.getUTCSeconds()).padStart(2,"0"),l=n.padEnd(6,"0").slice(0,6);return`${i}-${o}-${a}T${c}:${u}:${f}.${l}`}function Zr(e){let t=e.match(/^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2})\.(\d{6})$/);if(!t)throw Error(`Invalid message timestamp "${e}" \u2014 expected 2026-05-11T06:01:04.000100`);let n=Date.parse(t[1]+"Z");if(isNaN(n))throw Error(`Cannot parse date in "${e}"`);return`${Math.floor(n/1000)}.${t[2]}`}function Xf(e){return/^\d{4}-\d{2}-\d{2}T/.test(e)?Zr(e):e}async function bs(e,t,n,r,s){let i=typeof t.ts==="string"?t.ts:`${Ds(t)}.000000`,o=Vr(i),a="?";if(typeof t.user==="string"){let F=t.user,k="@"+F;if(!n.has(k)){let S=await Pc(e,F,async(L,A,R)=>(await yn(L,A,R))[1],s);n.set(k,S)}a=n.get(k)??F}else if(typeof t.username==="string")a=t.username;let c=typeof t.text==="string"?t.text:"",f=xn(await Qt(e,c,n,s)).split(`
164
+ slack user ls --external`)}async function ut(e,t,n){let r=t.startsWith("@")?t.slice(1):t;if(Nr(r))return r;if(!t.startsWith("@"))throw Error(`Expected @user or a user ID, got: ${t}`);let s=Mt(r),i=await ie(e,"auth.test",{},n);if(s==="you"||s==="me"||Mt(i.user??"")===s){if(!i.user_id)throw Error("auth.test did not return user_id");return i.user_id}let o=await mc(e,s,n);if(o.id)return o.id;throw Dc(t,o)}function vt(e){let t=e.match(/(?:app\.slack\.com\/client\/T[A-Za-z0-9]+|[A-Za-z0-9-]+\.slack\.com\/archives)\/([A-Za-z0-9]+)(?:\/p(\d{10})(\d{6}))?/);if(!t)return;let n=t[1],r=t[2]&&t[3]?`${t[2]}.${t[3]}`:void 0,s=e.indexOf("?"),i=s>=0?new URLSearchParams(e.slice(s)):void 0,o=i?.get("thread_ts")??void 0,u={channel:i?.get("cid")??void 0??n};if(r)u.ts=r;if(o)u.threadTs=o;return u}function bf(e){return vt(e)?.channel}function Za(e){return/^[CDG][A-Z0-9]{8,}$/.test(e)}function Nr(e){return/^[UW][A-Z0-9]{6,}$/.test(e)}async function De(e,t,n){let r=bf(t);if(r)return r;if(!t.startsWith("@")&&!t.startsWith("#")){if(Za(t))return t;if(Nr(t))return Br(e,t,n);throw Error(`Target must start with # or @ (or be a Slack URL/ID), got: ${t}`)}if(t.startsWith("#")&&Za(t.slice(1)))return t.slice(1);let s=t.startsWith("@"),i=t.slice(1),o=Mt(i);if(s){if(Nr(i))return Br(e,i,n);let u=await ie(e,"auth.test",{},n);if(o==="you"||o==="me"||Mt(u.user??"")===o){let d=u.user_id;if(!d)throw Error("auth.test did not return user_id");return await hc(e,d,n)||ct(e,d,n)}let l=await mc(e,o,n);if(!l.id)throw Dc(t,l);if(l.dm)return l.dm;return Br(e,l.id,n,t)}let a=i.toLowerCase(),c="";while(!0){let u={limit:"200",types:"public_channel,private_channel",exclude_archived:"true"};if(c)u.cursor=c;let f=await ie(e,"conversations.list",u,n);for(let l of f.channels??[])if(String(l.name??"").toLowerCase()===a)return String(l.id??"");if(c=f.response_metadata?.next_cursor??"",!c)break}throw Error(`channel not found: ${t}`)}async function yn(e,t,n){try{let r=await ie(e,"users.info",{user:t},n),s=r.user?.profile?.display_name,i=s&&s.length>0?s:r.user?.real_name??r.user?.name??t,o=r.user?.name??t;return[i,o]}catch{return[t,t]}}async function qe(e,t,n){try{let r=await ie(e,"users.info",{user:t},n),s=r.user?.profile?.display_name;if(s&&s.length>0)return s;return r.user?.real_name??r.user?.name??t}catch{return t}}async function yc(e,t){let n=[],r="";while(!0){let s={limit:"200"};if(r)s.cursor=r;let i=await ie(e,"users.list",s,t);if(n.push(...i.members??[]),r=i.response_metadata?.next_cursor??"",!r)break}return{members:n}}async function wc(e,t,n){let r=[],s="";while(!0){let i={channel:t,limit:"200"};if(s)i.cursor=s;let o=await ie(e,"conversations.members",i,n);if(r.push(...o.members??[]),s=o.response_metadata?.next_cursor??"",!s)break}return r}async function wn(e,t){return Nt(e,"drafts.list",{},t)}async function bc(e,t,n,r){let{randomUUID:s}=await import("node:crypto"),i=JSON.stringify([{type:"rich_text",elements:[{type:"rich_text_section",elements:[{type:"text",text:n}]}]}]);return Nt(e,"drafts.create",{client_msg_id:s(),destinations:JSON.stringify([{channel_id:t}]),blocks:i,file_ids:JSON.stringify([]),is_from_composer:"true"},r)}async function Fc(e,t,n,r,s){let i=JSON.stringify([{type:"rich_text",elements:[{type:"rich_text_section",elements:[{type:"text",text:r}]}]}]),o=(Date.now()/1000).toFixed(6);return Nt(e,"drafts.update",{draft_id:t,client_last_updated_ts:o,destinations:JSON.stringify([{channel_id:n}]),blocks:i,file_ids:JSON.stringify([])},s)}async function Cc(e,t,n){return Nt(e,"conversations.info",{channel:t},n)}async function bn(e,t,n){return ie(e,"users.info",{user:t},n)}async function Fn(e,t,n){return ie(e,"conversations.info",{channel:t},n)}async function Ec(e,t,n){let r=(Date.now()/1000).toFixed(6);return Nt(e,"drafts.delete",{draft_id:t,client_last_updated_ts:r},n)}async function Lr(e,t){let n=await Nt(e,"auth.test",{},t);return{userId:String(n.user_id??""),teamId:String(n.team_id??"")}}async function xc(e,t,n,r={},s){let{statSync:i,readFileSync:o}=await import("node:fs"),{basename:a}=await import("node:path"),c=i(n),u=a(n),f=await ie(e,"files.getUploadURLExternal",{filename:u,length:String(c.size)},s),l=f.upload_url,d=f.file_id;if(!l||!d)throw Error("files.getUploadURLExternal returned no upload_url/file_id");let p=o(n),m=await fetch(l,{method:"POST",headers:{"Content-Type":"application/octet-stream"},body:p});if(!m.ok)throw Error(`Upload PUT failed: ${m.status} ${m.statusText}`);let g={files:[{id:d,title:r.title??u}],channel_id:t};if(r.threadTs)g.thread_ts=r.threadTs;if(r.initialComment)g.initial_comment=r.initialComment;let y=await ze(e,"files.completeUploadExternal",g,s),C={fileId:d},F=y.files?.[0]?.permalink;if(F)C.permalink=F;return C}function hn(e,t){let n=e;for(let r of t){if(n===void 0||n===null)return;if(typeof r==="number"){if(!Array.isArray(n))return;n=n[r]??void 0}else{if(typeof n!=="object"||Array.isArray(n))return;n=n[r]}}return n}import{existsSync as Of,readFileSync as If}from"node:fs";import{homedir as Tf}from"node:os";import{join as Pf}from"node:path";import{existsSync as Ff,mkdirSync as Cf,readFileSync as Ef,writeFileSync as xf}from"node:fs";import{homedir as _f}from"node:os";import{dirname as kf,join as Sf}from"node:path";var Af=3600000,hs={now:()=>Date.now(),path:()=>Sf(process.env.HOME||_f(),".config","slack-cli","cache.json")},gs=!0,lt;function _c(){return{channels:{},users:{}}}function Wr(){if(lt)return lt;if(lt=_c(),!gs)return lt;try{let e=hs.path();if(!Ff(e))return lt;let t=JSON.parse(Ef(e,"utf8"));for(let n of["channels","users"]){let r=t?.[n];if(!r||typeof r!=="object"||Array.isArray(r))continue;for(let[s,i]of Object.entries(r))if(i&&typeof i==="object"&&typeof i.value==="string"&&typeof i.expires==="number")lt[n][s]={value:i.value,expires:i.expires}}}catch{lt=_c()}return lt}function $f(e){if(!gs)return;try{let t=hs.path();Cf(kf(t),{recursive:!0}),xf(t,JSON.stringify(e,null,2)+`
165
+ `)}catch{}}function kc(e,t){return e?`${e} ${t}`:void 0}function ms(e,t,n){if(!gs)return;let r=kc(t,n);if(!r)return;let s=Wr()[e][r];if(!s)return;if(s.expires<=hs.now()){delete Wr()[e][r];return}return s.value}function Ds(e,t,n,r,s=Af){if(!gs)return;let i=kc(t,n);if(!i)return;let o=Wr();o[e][i]={value:r,expires:hs.now()+s},$f(o)}var Ur={marker:"pushpin",progress:{done:"white_check_mark",dropped:"no_entry_sign",doing:"eyes",pending:"hourglass_flowing_sand"},flags:{alert:"exclamation","needs-discussion":"thinking_face",waiting:"speech_balloon",blocked:"lock"}},Zt=["done","dropped","doing","pending"],Oc=["alert","needs-discussion","waiting","blocked"];function Rf(){return Pf(process.env.HOME||Tf(),".config","slack-cli","todo.json")}function ys(e){return e.replace(/^:+|:+$/g,"")}function Cn(e=Rf()){let t={marker:Ur.marker,progress:{...Ur.progress},flags:{...Ur.flags}};try{if(!Of(e))return t;let n=JSON.parse(If(e,"utf8"));if(typeof n.marker==="string"&&n.marker.trim())t.marker=ys(n.marker.trim());for(let r of Zt){let s=n.progress?.[r];if(typeof s==="string"&&s.trim())t.progress[r]=ys(s.trim())}for(let r of Oc){let s=n.flags?.[r];if(typeof s==="string"&&s.trim())t.flags[r]=ys(s.trim())}}catch{}return t}function Sc(e,t,n=!1){return`${n?"-":""}${t?"has":"hasmy"}::${ys(e)}:`}function Ic(e,t,n={}){let r=n.shared===!0,s=(a)=>Sc(a,r),i=(a)=>Sc(a,r,!0),o=[];if(e==="untriaged")o.push(s(t.marker),...Zt.map((a)=>i(t.progress[a])));else if(e==="stuck")o.push(s(t.marker),i(t.progress.done),i(t.progress.dropped),`(${Oc.map((a)=>s(t.flags[a])).join(" OR ")})`);else if(e==="open")o.push(s(t.marker),i(t.progress.done),i(t.progress.dropped));else{let a=Zt.indexOf(e);o.push(s(t.progress[e]));for(let c of Zt.slice(0,a))o.push(i(t.progress[c]))}if(n.in){let a=n.in.startsWith("#")||n.in.startsWith("@")?n.in:`#${n.in}`;o.push(`in:${a}`)}if(n.from){let a=n.from==="me"||n.from.startsWith("@")?n.from:`@${n.from}`;o.push(`from:${a}`)}return o.join(" ")}var Mf=3,Bf={sleep:(e)=>Nf()?Promise.resolve():new Promise((t)=>setTimeout(t,e))};function Nf(){return!!process.env.VITEST||!1||!!process.env.BUN_TEST}async function _e(e,t,n=Mf){for(let r=0;;r++)try{return await t()}catch(s){if(!(s instanceof We))throw s;if(r>=n)throw Error(`Slack rate limit hit on ${e} — gave up after ${n} retries. Try again in a minute.`);console.error(`Warning: Slack rate limit hit on ${e} — backing off for ${s.retryAfter}s`),await Bf.sleep(s.retryAfter*1000)}}var Ac=new Map;async function Tc(e,t){let n=Ac.get(e);if(n)return n;let r=await _e("auth.test",()=>Yt(e,t)),s={userId:r.userId,teamId:r.teamId};return Ac.set(e,s),s}async function Pc(e,t){return(await Tc(e,t)).userId}async function Kr(e,t){try{return(await Tc(e,t)).teamId}catch{return""}}async function Jr(e,t,n,r){if(!t.startsWith("#"))return n(e,t,r);let s=await Kr(e,r),i=ms("channels",s,t);if(i)return i;let o=await _e("resolveChannel",()=>n(e,t,r));return Ds("channels",s,t,o),o}async function Rc(e,t,n,r){let s=await Kr(e,r),i=ms("users",s,t);if(i)return i;let o=await _e("users.info",()=>n(e,t,r));if(o&&o!==t)Ds("users",s,t,o);return o}async function Mc(e,t,n,r){let s=await Kr(e,r),i=ms("users",s,`tz:${t}`);if(i)return i==="?"?null:i;let o=null;try{let a=await _e("users.info",()=>n(e,t,r));if(a?.user?.is_bot===!0||t==="USLACKBOT")return $c(s,t,null);let c=a?.user?.tz;o=typeof c==="string"&&c?c:null}catch{return null}return $c(s,t,o)}function $c(e,t,n){return Ds("users",e,`tz:${t}`,n??"?"),n}async function Bc(e,t,n,r,s,i){let o=s.progress[r],a=await Pc(e,i),c=await _e("reactions.get",()=>Qo(e,t,n,i)),u=new Set(c.filter((p)=>p.users.includes(a)).map((p)=>p.name)),f=Zt.map((p)=>s.progress[p]).filter((p)=>u.has(p));if(f.length===1&&f[0]===o)return{noop:!0,removed:[],leftover:[]};if(!u.has(o))await _e("reactions.add",()=>Hn(e,t,n,o,i));let l=[],d=[];for(let p of f){if(p===o)continue;try{await _e("reactions.remove",()=>qn(e,t,n,p,i)),l.push(p)}catch{d.push(p)}}return{noop:!1,added:r,removed:l,leftover:d}}async function Nc(e,t,n,r,s,i,o){let a=s.flags[r];if(i)await _e("reactions.remove",()=>qn(e,t,n,a,o));else await _e("reactions.add",()=>Hn(e,t,n,a,o));return a}var zr=1000;async function vc(e,t,n,r={}){let s=r.limit??zr,i=r.cookie,o=await Pc(e,i),a=Zt.map((d)=>n.progress[d]),c=[],u=0,f,l=!1;while(u<s){let d=Math.min(200,s-u),p=await _e("conversations.history",()=>un(e,t,d,void 0,f,i)),m=p.messages??[];u+=m.length;for(let g of m){let y=String(g.ts??"");if(!y)continue;let C=new Set((g.reactions??[]).filter((S)=>(S.users??[]).map(String).includes(o)).map((S)=>String(S.name??""))),F=a.filter((S)=>C.has(S));if(F.length<2)continue;c.push({ts:y,text:String(g.text??"").split(`
166
+ `)[0]??"",emoji:F,keep:F[0]})}if(f=p.response_metadata?.next_cursor||void 0,!f||m.length===0)break;if(u>=s){l=!0;break}}if(r.fix)for(let d of c)try{try{await _e("reactions.add",()=>Hn(e,t,d.ts,d.keep,i))}catch(p){if(!(p instanceof Error)||!/already_reacted/.test(p.message))throw p}for(let p of d.emoji){if(p===d.keep)continue;await _e("reactions.remove",()=>qn(e,t,d.ts,p,i))}d.fixed=!0}catch(p){d.fixed=!1,d.error=p instanceof Error?p.message:String(p)}return{scanned:u,findings:c,truncated:l}}var vf=!0,jf;function Hr(e){if(vf=e,!e)jf=void 0}function ft(e){return e.replace(new RegExp(`[${"\\\\¥"}](.)`,"gs"),(t,n)=>{switch(n){case"n":return`
167
+ `;case"t":return"\t";case"\\":case"¥":return n==="¥"?"¥":"\\";default:return t}})}function jt(e){return e.toLowerCase().replace(/[-_\s]/g,"")}function dt(e){return e&&typeof e==="object"&&!Array.isArray(e)?e:{}}function Lf(e,t){let n=jt(t),r=dt(e.profile);for(let i of[e.name,e.real_name,r.display_name,r.real_name])if(typeof i==="string"&&i&&jt(i)===n)return!0;let s=typeof r.email==="string"?r.email.toLowerCase():"";return s!==""&&s===t.toLowerCase()}function Wf(e){let t=dt(e.profile),n=new Set;for(let r of[t.display_name,e.real_name,e.name,t.real_name])if(typeof r==="string"&&r){let s=jt(r);if(s.length>=2)n.add(s)}return[...n]}function Uf(e,t){let n=jt(e),r,s=!1;for(let i of t){let o=typeof i.id==="string"?i.id:"";if(!o)continue;for(let a of Wf(i)){let c=-1;if(n===a)c=e.length;else for(let u of Lc)if(e.length>u.length&&e.endsWith(u)&&jt(e.slice(0,e.length-u.length))===a){c=e.length-u.length;break}if(c<0)continue;if(!r||a.length>r.formLen)r={userId:o,matchLen:c,formLen:a.length,display:Xr(i)},s=!1;else if(a.length===r.formLen&&r.userId!==o)s=!0}}if(!r)return;return s?"ambiguous":{userId:r.userId,matchLen:r.matchLen,display:r.display}}async function Lt(e,t,n,r){let s=`[${Wc}ー]+`,i=`${s}(?:[._-]+${s})*`,o=new RegExp(`(?<![A-Za-z0-9._@<-])@(${i})`,"gu"),a=new Set;for(let F of t.matchAll(o))a.add(F[1]);if(a.size===0)return{text:t,resolved:[],unresolved:[]};let c=new Map;for(let F of a)c.set(F,{status:"pending"});let u=(F)=>{for(let S of a){if(c.get(S).status!=="pending")continue;if(Yr(S)){let k=Uf(S,F);if(k==="ambiguous")c.set(S,{status:"ambiguous"});else if(k)c.set(S,{status:"resolved",userId:k.userId,matchLen:k.matchLen,display:k.display})}else{let k=F.filter((A)=>Lf(A,S)),L=new Set(k.map((A)=>typeof A.id==="string"?A.id:"").filter(Boolean));if(L.size===1){let A=k.find((R)=>typeof R.id==="string");c.set(S,{status:"resolved",userId:A.id,matchLen:S.length,display:Xr(A)})}else if(L.size>1)c.set(S,{status:"ambiguous"})}}},f=!1;try{let F=await Gn(e,r);u((F.members??[]).map(dt)),f=!0}catch{f=!1}let l=[...a].some((F)=>c.get(F).status==="pending"),d=!1,p=!0;if(l&&n){d=!0;try{let F=await mr(e,n,r),S=[];for(let k of F){let L=dt(await Dr(e,k,r)),A=dt(L.user);if(typeof A.id!=="string")A.id=k;S.push(A)}u(S)}catch{p=!1}}let m=f&&(n?d&&p:!0),g=[],y=[];for(let F of a){let S=c.get(F);if(S.status==="resolved")g.push({surface:`@${F.slice(0,S.matchLen)}`,display:S.display,userId:S.userId});else if(S.status==="ambiguous")y.push({surface:`@${F}`,reason:"ambiguous"});else y.push({surface:`@${F}`,reason:m?"no-match":"unavailable"})}return{text:t.replace(o,(F,S)=>{let k=c.get(S);if(k&&k.status==="resolved")return`<@${k.userId}>${S.slice(k.matchLen)}`;return F}),resolved:g,unresolved:y}}function En(e){let t=[],n=!1;for(let r of e)if(r.reason==="ambiguous")t.push(`${r.surface} matches multiple people — not tagged, sent as plain text (use <@USERID> to tag)`);else if(r.reason==="unavailable"){if(n)continue;t.push("could not fetch the user list (users:read missing or an API/connection error) — @mentions not tagged, sent as plain text"),n=!0}else t.push(`${r.surface} matched no one — not tagged, sent as plain text`);return t}async function jc(e,t,n,r={}){let s=r.warn??((o)=>process.stderr.write(`${o}
168
+ `)),i=await Lt(e,t,n,r.cookie);for(let o of En(i.unresolved))s(`warn: ${o}`);return i.text}var Lc=["さん","さま","様","君","くん","ちゃん","氏","先生","先輩","殿","老师","老師","兄","姐","哥","姐妹"],Wc="\\p{Script=Han}\\p{Script=Hiragana}\\p{Script=Katakana}A-Za-z0-9";function Yr(e){return/[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}]/u.test(e)}function Kf(e){let t=[],n=new RegExp(`([${Wc}]{1,12})(${Lc.join("|")})`,"gu");for(let r of e.matchAll(n))t.push({ref:r[1],honorific:r[2]});for(let r of e.matchAll(/\b(?:dear|hi|hello|hey)\b[ \t]+([A-Z][A-Za-z'’-]{1,20})/gi))t.push({ref:r[1],honorific:""});for(let r of e.matchAll(/(?:^|\n)[ \t]*([A-Z][A-Za-z'’-]{1,20}),/g))t.push({ref:r[1],honorific:""});return t}function Jf(e){let t=dt(e.profile),n=new Set;for(let r of[e.name,e.real_name,t.display_name,t.real_name]){if(typeof r!=="string"||!r)continue;for(let s of[r,...r.split(/\s+/)]){let i=jt(s);if(i.length>=2)n.add(i)}}return[...n]}function zf(e,t){let n=jt(e);if(n.length<2)return;for(let r of t)if(n===r)return r;if(Yr(e)){for(let r of t)if(n.includes(r)||r.includes(n))return r}return}function Xr(e){return[dt(e.profile).display_name,e.real_name,e.name].filter((r)=>typeof r==="string"&&r!=="")[0]??String(e.id??"?")}async function Uc(e,t,n){let r=Kf(t);if(r.length===0)return[];let s=new Set;for(let u of t.matchAll(/<@([A-Z0-9]+)(?:\|[^>]*)?>/g))s.add(u[1]);let o=((await Gn(e,n)).members??[]).map(dt).filter((u)=>u.deleted!==!0&&u.is_bot!==!0&&u.id!=="USLACKBOT").map((u)=>({id:typeof u.id==="string"?u.id:"",forms:Jf(u),display:Xr(u)})).filter((u)=>u.id!==""),a=[],c=new Set;for(let{ref:u,honorific:f}of r)for(let l of o){let d=zf(u,l.forms);if(!d)continue;if(s.has(l.id)||c.has(l.id))break;c.add(l.id),a.push({surface:Yr(u)?`${d}${f}`:u,display:l.display,userId:l.id});break}return a}async function Qt(e,t,n,r){let s=t,i=[],o=s,a=0;while(!0){let c=o.indexOf("<@U",a);if(c===-1)break;let u=o.slice(c+2),f=u.search(/[>|]/),l=f===-1?u:u.slice(0,f);if(l.length>=9)i.push(l);a=c+1}for(let c of i){if(!n.has(c))n.set(c,await Xn(e,c,r));let u=n.get(c)??c;s=s.replaceAll(`<@${c}>`,`@${u}`),s=s.replace(new RegExp(`<@${c}\\|[^>]*>`,"g"),`@${u}`)}return s}function xn(e){return e.replace(/<!date\^(\d+)\^[^|>]*(?:\|([^>]*))?>/g,(t,n,r)=>{let s=Number(n);if(!Number.isFinite(s))return r??"date";let i=new Date(s*1000);if(Number.isNaN(i.getTime()))return r??"date";let o=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],a=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],c=o[i.getUTCDay()]??"",u=a[i.getUTCMonth()]??"";return`${c}, ${u} ${String(i.getUTCDate()).padStart(2,"0")}, ${i.getUTCFullYear()}`})}function Kc(e,t=new Date){let n=new Date(e*1000),r=qr(t),s=qr(new Date(t.getTime()-86400000)),i=qr(n);if(i===r)return"Today";if(i===s)return"Yesterday";let o=n.toLocaleDateString("en-US",{weekday:"long"}),a=n.toLocaleDateString("en-US",{month:"short"});return`${o}, ${a} ${String(n.getDate()).padStart(2,"0")}`}function qr(e){return`${e.getFullYear()}-${e.getMonth()}-${e.getDate()}`}function Jc(e){let t=new Date(e*1000),n=t.getFullYear(),r=String(t.getMonth()+1).padStart(2,"0"),s=String(t.getDate()).padStart(2,"0"),i=String(t.getHours()).padStart(2,"0"),o=String(t.getMinutes()).padStart(2,"0");return`${n}-${r}-${s} ${i}:${o}`}function zc(e=new Date,t){let n=process.env.SLACK_QUIET_TZ??"Asia/Tokyo",r=!!t&&Hf(t),s=r?t:n,i=Number(process.env.SLACK_QUIET_START??23),o=Number(process.env.SLACK_QUIET_END??8),a,c;try{let p=new Intl.DateTimeFormat("en-GB",{timeZone:s,hour12:!1,weekday:"short",year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"});c=p.format(e),a=Number(p.formatToParts(e).find((m)=>m.type==="hour")?.value??"12")}catch{return null}let u=i>o?a>=i||a<o:a>=i&&a<o,f=r?`${s}, recipient`:`${s}, sender — recipient's timezone unknown`,l=`\uD83D\uDD50 ${c} (${f})`;if(!u)return l;return`${l}
169
+ ⚠ QUIET HOURS (${i}:00-${o}:00) — this will buzz a phone.${r?"":" Their local time may differ."} Send only for a production incident; otherwise hold it until morning.`}function Hf(e){try{return new Intl.DateTimeFormat("en-GB",{timeZone:e}),!0}catch{return!1}}function _n(e){if(!eu(e))return;let t=Yf(e,"utf8");for(let n of t.split(`
170
+ `)){let r=n.trim();if(!r||r.startsWith("#"))continue;let s=r.indexOf("=");if(s===-1)continue;let i=r.slice(0,s).trim(),o=r.slice(s+1).trim();if(o.startsWith('"')&&o.endsWith('"')||o.startsWith("'")&&o.endsWith("'"))o=o.slice(1,-1);if(!(i in process.env))process.env[i]=o}}function Gf(e){Xf(e,{recursive:!0});let t=pt(e,".gitignore");if(!eu(t))tu(t,`*
171
+ `)}function Vf(){_n(pt(Hc(),".slack-cli",".env.local")),_n(pt(Hc(),".config/slack-cli",".env")),_n(pt(process.cwd(),".slack-cli",".env.local")),_n(pt(process.cwd(),".env.local")),_n(pt(process.cwd(),".env"))}function Zf(e){return qf("sha256").update(e).digest("hex")}function T(e){return e&&typeof e==="object"&&!Array.isArray(e)?e:{}}function X(e){return Array.isArray(e)?e:[]}function ws(e){return Number(e.ts??0)}async function nu(e,t,n){let r=t.user;if(typeof r==="string"){if(!n.has(r))n.set(r,await qe(e,r));return n.get(r)??r}return typeof t.username==="string"?t.username:"bot"}function Vr(e){let t=new Date(e*1000),n=t.getUTCFullYear(),r=String(t.getUTCMonth()+1).padStart(2,"0"),s=String(t.getUTCDate()).padStart(2,"0"),i=String(t.getUTCHours()).padStart(2,"0"),o=String(t.getUTCMinutes()).padStart(2,"0"),a=String(t.getUTCSeconds()).padStart(2,"0");return`${n}-${r}-${s} ${i}:${o}:${a}`}function Qr(e){let[t,n="000000"]=e.split("."),r=Number(t),s=new Date(r*1000),i=s.getUTCFullYear(),o=String(s.getUTCMonth()+1).padStart(2,"0"),a=String(s.getUTCDate()).padStart(2,"0"),c=String(s.getUTCHours()).padStart(2,"0"),u=String(s.getUTCMinutes()).padStart(2,"0"),f=String(s.getUTCSeconds()).padStart(2,"0"),l=n.padEnd(6,"0").slice(0,6);return`${i}-${o}-${a}T${c}:${u}:${f}.${l}`}function ei(e){let t=e.match(/^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2})\.(\d{6})$/);if(!t)throw Error(`Invalid message timestamp "${e}" \u2014 expected 2026-05-11T06:01:04.000100`);let n=Date.parse(t[1]+"Z");if(isNaN(n))throw Error(`Cannot parse date in "${e}"`);return`${Math.floor(n/1000)}.${t[2]}`}function Qf(e){return/^\d{4}-\d{2}-\d{2}T/.test(e)?ei(e):e}async function Cs(e,t,n,r,s){let i=typeof t.ts==="string"?t.ts:`${ws(t)}.000000`,o=Qr(i),a="?";if(typeof t.user==="string"){let F=t.user,S="@"+F;if(!n.has(S)){let k=await Rc(e,F,async(L,A,R)=>(await yn(L,A,R))[1],s);n.set(S,k)}a=n.get(S)??F}else if(typeof t.username==="string")a=t.username;let c=typeof t.text==="string"?t.text:"",f=xn(await Qt(e,c,n,s)).split(`
172
172
  `),l=f[0]+(f.length>1?`
173
173
  `+f.slice(1).map((F)=>` ${F}`).join(`
174
- `):""),d=r?`${r} @${a}`:`@${a}`,p=X(t.reactions).map(T).map((F)=>{let k=typeof F.name==="string"?F.name:"",S=Number(F.count??X(F.users).length??0);return k?`:${k}:\xD7${S}`:""}).filter(Boolean).join(" "),m=X(t.files).map(T).map((F)=>{let k=typeof F.name==="string"?F.name:typeof F.title==="string"?F.title:"(file)",S=typeof F.size==="number"?` (${Fs(F.size)})`:"",L=typeof F.id==="string"?` [${F.id}]`:"";return`
175
- \uD83D\uDCCE ${k}${S}${L}`}).join(""),g=Number(t.reply_count??0),y=g>0?` [+${g} ${g===1?"reply":"replies"}]`:"",C=(p?`
176
- ${p}`:"")+m;return`${o} ${d}: ${l}${y}${C}`}function Fs(e){return e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(1)} MB`}function Gf(e){return X(e.files).map(T).map((t)=>({id:t.id??null,name:t.name??t.title??null,mimetype:t.mimetype??null,size:t.size??null,url_private_download:t.url_private_download??t.url_private??null,permalink:t.permalink??null}))}function Qc(e){let t=Gf(e);return{ts:e.ts??null,user:e.user??null,username:e.username??null,bot_id:e.bot_id??null,thread_ts:e.thread_ts??null,text:typeof e.text==="string"?e.text:"",...Array.isArray(e.reactions)&&e.reactions.length?{reactions:X(e.reactions).map(T).map((n)=>({name:n.name??null,count:n.count??null,users:Array.isArray(n.users)?n.users:[]}))}:{},...e.reply_count!==void 0?{reply_count:e.reply_count}:{},...e.reply_users_count!==void 0?{reply_users_count:e.reply_users_count}:{},...e.latest_reply!==void 0?{latest_reply:e.latest_reply}:{},...t.length>0?{files:t}:{}}}async function Vf(e,t,n,r,s){let i=[];for(let o of n){let a=o;if(Number(o.reply_count??0)>0&&typeof o.ts==="string"){let c=await He(e,t,o.ts,200,s),u=X(c.messages).map(T);a=u[u.length-1]??o}if(a.user!==r)i.push(o)}return i}async function Zf(e,t,n,r="text",s=!1,i){let o=Bt(t),a=await De(e,t,i),c=new Map,f=await(async()=>{if(o?.threadTs){let d=await He(e,a,o.threadTs,n,i);return X(d.messages).map(T)}let l=await Ze(e,a,n,void 0,void 0,i);return X(l.messages).map(T).reverse()})();if(s){let{userId:l}=await Qa(e,i);f=await Vf(e,a,f,l,i)}if(r==="jsonl"){for(let l of f)console.log(JSON.stringify(Qc(l)));return}for(let l of f)console.log(await bs(e,l,c,void 0,i))}async function Qf(e,t,n,r,s="text",i){let o=await De(e,t,i),a=await He(e,o,Xf(n),r,i),c=X(a.messages).map(T);if(s==="jsonl"){for(let f of c)console.log(JSON.stringify(Qc(f)));return}let u=new Map;for(let f of c)console.log(await bs(e,f,u,void 0,i))}async function ed(e){let t=await Dn(e),n=X(t.channels).map(T).filter((s)=>s.is_member===!0).sort((s,i)=>Number(i.updated??0)-Number(s.updated??0)).slice(0,10),r=new Map;for(let s of n){let i=String(s.id??""),o=typeof s.name==="string"?s.name:typeof s.user==="string"?s.user:i,a=await Ze(e,i,5),c=X(a.messages).map(T).filter((u)=>u.subtype===void 0||u.subtype===null).filter((u)=>{let f=typeof u.text==="string"?u.text:"";return f.length>0&&!f.startsWith("<@")}).slice(0,3).reverse();if(c.length===0)continue;console.log(`-- #${o} --------------------------------`);for(let u of c){let f=await Zc(e,u,r),l=(typeof u.text==="string"?u.text:"").split(`
177
- `)[0]??"",d=await Qt(e,l,r);console.log(` ${f}: ${d}`)}}}async function td(e,t){let n=await ic(e,"to:me"),r=X(hn(n,["messages","matches"])).map(T).slice(0,t),s=new Map,i=[];for(let o of r){let a=Uc(Ds(o)),c=i[i.length-1];if(c?.label===a)c.msgs.push(o);else i.push({label:a,msgs:[o]})}for(let o=0;o<i.length;o++){let{label:a,msgs:c}=i[o];if(o>0)console.log("");console.log(` ${a}`),console.log(" ----------------------------");for(let u of[...c].reverse()){let f=T(u.channel),l=f.is_im===!0,d=typeof f.name==="string"?f.name:"dm",p;if(l&&d.startsWith("U")){let m="@"+d;if(!s.has(m)){let[,g]=await yn(e,d);s.set(m,g)}p=`@${s.get(m)??d}`}else if(l)p=`@${d}`;else p=`#${d}`;console.log(await bs(e,u,s,p))}}}async function nd(e,t,n,r,s="text"){let i=await Dn(e),o=X(i.channels).map(T).filter((a)=>r||a.is_member===!0).filter((a)=>{if(!n)return!0;return(typeof a.name==="string"?a.name:"").toLowerCase().includes(n.toLowerCase())}).sort((a,c)=>Number(c.updated??0)-Number(a.updated??0)).slice(0,t);if(s==="jsonl"){for(let a of o)console.log(JSON.stringify(a));return}for(let a of o){let c=String(a.id??""),u=typeof a.name==="string"?a.name:typeof a.user==="string"?a.user:c,f=a.is_im===!0,l=a.is_mpim===!0,d=f||l?"@":"#",p=a.is_member===!0?"":" (not joined)",m=typeof T(a.purpose).value==="string"?String(T(a.purpose).value):"",g=m?` ${m.split(`
178
- `)[0]?.slice(0,60)}`:"";console.log(`${d}${u} ${c}${p}${g}`)}}function sd(e){let t=(s)=>s.startsWith("xoxp-")||s.startsWith("xoxc-"),n=ar(),r=n.find((s)=>s.profile.token===e);if(!r)return;return n.find((s)=>t(s.profile.token)&&s.profile.teamId===r.profile.teamId)}async function eu(e,t,n,r,s){let i=e,o=s,a;try{a=await vr(i,t,n,o)}catch(f){let l=f instanceof Error?f.message:String(f);if(e.startsWith("xoxb-")&&l.includes("not_allowed_token_type")){let d=sd(e);if(d)console.error(`Note: search.messages needs a user token \u2014 the active profile is a bot token (xoxb-); falling back to profile "${d.name}".`),i=d.profile.token,o=d.profile.cookie,a=await vr(i,t,n,o);else console.error(`Error: search requires a user token (xoxp-/xoxc-) \u2014 the active profile is a bot token (xoxb-), which Slack rejects for search.messages.
174
+ `):""),d=r?`${r} @${a}`:`@${a}`,p=X(t.reactions).map(T).map((F)=>{let S=typeof F.name==="string"?F.name:"",k=Number(F.count??X(F.users).length??0);return S?`:${S}:\xD7${k}`:""}).filter(Boolean).join(" "),m=X(t.files).map(T).map((F)=>{let S=typeof F.name==="string"?F.name:typeof F.title==="string"?F.title:"(file)",k=typeof F.size==="number"?` (${Es(F.size)})`:"",L=typeof F.id==="string"?` [${F.id}]`:"";return`
175
+ \uD83D\uDCCE ${S}${k}${L}`}).join(""),g=Number(t.reply_count??0),y=g>0?` [+${g} ${g===1?"reply":"replies"}]`:"",C=(p?`
176
+ ${p}`:"")+m;return`${o} ${d}: ${l}${y}${C}`}function Es(e){return e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(1)} MB`}function ed(e){return X(e.files).map(T).map((t)=>({id:t.id??null,name:t.name??t.title??null,mimetype:t.mimetype??null,size:t.size??null,url_private_download:t.url_private_download??t.url_private??null,permalink:t.permalink??null}))}function su(e){let t=ed(e);return{ts:e.ts??null,user:e.user??null,username:e.username??null,bot_id:e.bot_id??null,thread_ts:e.thread_ts??null,text:typeof e.text==="string"?e.text:"",...Array.isArray(e.reactions)&&e.reactions.length?{reactions:X(e.reactions).map(T).map((n)=>({name:n.name??null,count:n.count??null,users:Array.isArray(n.users)?n.users:[]}))}:{},...e.reply_count!==void 0?{reply_count:e.reply_count}:{},...e.reply_users_count!==void 0?{reply_users_count:e.reply_users_count}:{},...e.latest_reply!==void 0?{latest_reply:e.latest_reply}:{},...t.length>0?{files:t}:{}}}async function td(e,t,n,r,s){let i=[];for(let o of n){let a=o;if(Number(o.reply_count??0)>0&&typeof o.ts==="string"){let c=await He(e,t,o.ts,200,s),u=X(c.messages).map(T);a=u[u.length-1]??o}if(a.user!==r)i.push(o)}return i}async function nd(e,t,n,r="text",s=!1,i){let o=vt(t),a=await De(e,t,i),c=new Map,f=await(async()=>{if(o?.threadTs){let d=await He(e,a,o.threadTs,n,i);return X(d.messages).map(T)}let l=await Ze(e,a,n,void 0,void 0,i);return X(l.messages).map(T).reverse()})();if(s){let{userId:l}=await ec(e,i);f=await td(e,a,f,l,i)}if(r==="jsonl"){for(let l of f)console.log(JSON.stringify(su(l)));return}for(let l of f)console.log(await Cs(e,l,c,void 0,i))}async function sd(e,t,n,r,s="text",i){let o=await De(e,t,i),a=await He(e,o,Qf(n),r,i),c=X(a.messages).map(T);if(s==="jsonl"){for(let f of c)console.log(JSON.stringify(su(f)));return}let u=new Map;for(let f of c)console.log(await Cs(e,f,u,void 0,i))}async function rd(e){let t=await Dn(e),n=X(t.channels).map(T).filter((s)=>s.is_member===!0).sort((s,i)=>Number(i.updated??0)-Number(s.updated??0)).slice(0,10),r=new Map;for(let s of n){let i=String(s.id??""),o=typeof s.name==="string"?s.name:typeof s.user==="string"?s.user:i,a=await Ze(e,i,5),c=X(a.messages).map(T).filter((u)=>u.subtype===void 0||u.subtype===null).filter((u)=>{let f=typeof u.text==="string"?u.text:"";return f.length>0&&!f.startsWith("<@")}).slice(0,3).reverse();if(c.length===0)continue;console.log(`-- #${o} --------------------------------`);for(let u of c){let f=await nu(e,u,r),l=(typeof u.text==="string"?u.text:"").split(`
177
+ `)[0]??"",d=await Qt(e,l,r);console.log(` ${f}: ${d}`)}}}async function id(e,t){let n=await oc(e,"to:me"),r=X(hn(n,["messages","matches"])).map(T).slice(0,t),s=new Map,i=[];for(let o of r){let a=Kc(ws(o)),c=i[i.length-1];if(c?.label===a)c.msgs.push(o);else i.push({label:a,msgs:[o]})}for(let o=0;o<i.length;o++){let{label:a,msgs:c}=i[o];if(o>0)console.log("");console.log(` ${a}`),console.log(" ----------------------------");for(let u of[...c].reverse()){let f=T(u.channel),l=f.is_im===!0,d=typeof f.name==="string"?f.name:"dm",p;if(l&&d.startsWith("U")){let m="@"+d;if(!s.has(m)){let[,g]=await yn(e,d);s.set(m,g)}p=`@${s.get(m)??d}`}else if(l)p=`@${d}`;else p=`#${d}`;console.log(await Cs(e,u,s,p))}}}async function od(e,t,n,r,s="text"){let i=await Dn(e),o=X(i.channels).map(T).filter((a)=>r||a.is_member===!0).filter((a)=>{if(!n)return!0;return(typeof a.name==="string"?a.name:"").toLowerCase().includes(n.toLowerCase())}).sort((a,c)=>Number(c.updated??0)-Number(a.updated??0)).slice(0,t);if(s==="jsonl"){for(let a of o)console.log(JSON.stringify(a));return}for(let a of o){let c=String(a.id??""),u=typeof a.name==="string"?a.name:typeof a.user==="string"?a.user:c,f=a.is_im===!0,l=a.is_mpim===!0,d=f||l?"@":"#",p=a.is_member===!0?"":" (not joined)",m=typeof T(a.purpose).value==="string"?String(T(a.purpose).value):"",g=m?` ${m.split(`
178
+ `)[0]?.slice(0,60)}`:"";console.log(`${d}${u} ${c}${p}${g}`)}}function ad(e){let t=(s)=>s.startsWith("xoxp-")||s.startsWith("xoxc-"),n=lr(),r=n.find((s)=>s.profile.token===e);if(!r)return;return n.find((s)=>t(s.profile.token)&&s.profile.teamId===r.profile.teamId)}async function ru(e,t,n,r,s){let i=e,o=s,a;try{a=await jr(i,t,n,o)}catch(f){let l=f instanceof Error?f.message:String(f);if(e.startsWith("xoxb-")&&l.includes("not_allowed_token_type")){let d=ad(e);if(d)console.error(`Note: search.messages needs a user token \u2014 the active profile is a bot token (xoxb-); falling back to profile "${d.name}".`),i=d.profile.token,o=d.profile.cookie,a=await jr(i,t,n,o);else console.error(`Error: search requires a user token (xoxp-/xoxc-) \u2014 the active profile is a bot token (xoxb-), which Slack rejects for search.messages.
179
179
  `+` Add a user-token profile: slack auth login (or slack auth token)
180
- Then select it: slack auth use <name> (or pass --workspace <name>)`),process.exit(1)}else throw f}if(r){console.log(JSON.stringify(a,null,2));return}let c=X(hn(a,["messages","matches"])).map(T),u=new Map;for(let f of c){let l=T(f.channel),d=l.is_im===!0,p=typeof l.name==="string"?l.name:"dm",m;if(d&&p.startsWith("U")){let g="@"+p;if(!u.has(g)){let[,y]=await yn(i,p,o);u.set(g,y)}m=`@${u.get(g)??p}`}else if(d)m=`@${p}`;else m=`#${p}`;console.log(await bs(i,f,u,m,o))}}async function tu(e,t,n,r){let{ref:s,ts:i}=Cs(t);if(!i)console.error("Error: target must embed a message ts (e.g. #chan:1700000000.000100 or a Slack permalink URL)"),process.exit(2);return{channelId:n??await Kr(e,s,De,r),ts:i}}async function rd(e,t){let n=Cn(),r={};if(!t.mine)r.shared=!0;if(t.in)r.in=t.in;if(t.from)r.from=t.from;let s=Oc(t.state,n,r);if(!t.json){let i=await en(e,t.cookie),o=t.mine?"your reactions only [hasmy:]":"anyone's reactions [has:]";console.error(`(From: ${su(i)} \xB7 matching ${o})`),console.error(`(query: ${s})`)}await _e("search.messages",()=>eu(e,s,t.count,t.json,t.cookie))}async function id(e,t){let n=Cn(),{channelId:r,ts:s}=await tu(e,t.target,t.channelId,t.cookie),i=await Mc(e,r,s,t.state,n,t.cookie);if(i.noop){console.log(`= Already ${t.state} (ts: ${s})`);return}let o=i.removed.length?`, removed ${i.removed.map((a)=>`:${a}:`).join(" ")}`:"";if(console.log(`\u2713 ${t.state} :${n.progress[t.state]}: (ts: ${s})${o}`),i.leftover.length)console.error(`\u26A0 ${i.leftover.map((a)=>`:${a}:`).join(" ")} could not be removed \u2014 this message now carries more than one `+"progress reaction. Readers collapse by priority so nothing is lost; repair with: slack todo doctor --in <#chan> --fix")}async function od(e,t){let n=Cn(),{channelId:r,ts:s}=await tu(e,t.target,t.channelId,t.cookie),i=await Bc(e,r,s,t.flag,n,t.remove===!0,t.cookie);console.log(`\u2713 ${t.remove?"Cleared":"Flagged"} ${t.flag} :${i}: (ts: ${s})`)}async function ad(e,t){let n=Cn(),r=t.channelId??await Kr(e,t.channel,De,t.cookie),s={limit:t.limit};if(t.fix)s.fix=!0;if(t.cookie)s.cookie=t.cookie;let i=await Nc(e,r,n,s);if(i.findings.length===0)console.log(`\u2713 No multi-state tasks in ${i.scanned} message(s).`);else{for(let o of i.findings){let a=o.fixed===!0?"fixed":o.fixed===!1?`FAILED: ${o.error??"?"}`:"needs --fix";console.log(`${o.ts} ${o.emoji.map((c)=>`:${c}:`).join(" ")} \u2192 keep :${o.keep}: [${a}] ${te(o.text).slice(0,60)}`)}console.log(`${i.findings.length} multi-state task(s) in ${i.scanned} message(s).`)}if(i.truncated)console.error(`\u26A0 Scan limit reached (${t.limit} messages) \u2014 older history was NOT checked. Raise it with --limit N.`)}async function cd(e,t,n,r){let s=Math.floor(Date.now()/1000)-t*86400,i=await Dn(e),o=X(i.channels).map(T).filter((f)=>f.is_member===!0&&f.is_im!==!0&&f.is_mpim!==!0).filter((f)=>{if(!r)return!0;return(typeof f.name==="string"?f.name:"").toLowerCase().includes(r.toLowerCase())}).sort((f,l)=>Number(l.updated??0)-Number(f.updated??0)),a=new Map,c=0,u=0;for(let f of o){let l=String(f.id??""),d=typeof f.name==="string"?f.name:l,p;try{p=await Ze(e,l,n)}catch(g){console.error(` SKIP #${d}: ${g.message}`);continue}let m=X(p.messages).map(T).filter((g)=>(g.subtype===void 0||g.subtype===null)&&Ds(g)>=s);if(m.length===0)continue;u+=1,c+=m.length,console.log(`## #${d} (${m.length} msgs)
181
- `);for(let g of[...m].reverse()){let y=await Zc(e,g,a),C=typeof g.text==="string"?g.text:"",k=xn(await Qt(e,C,a)).split(`
182
- `).join(" \u21B5 ");console.log(`[${Kc(Ds(g))}] ${y}: ${k}`)}console.log("")}console.error(`Dumped ${c} messages across ${u} channels (cutoff: ${t}d)`)}function ud(e){let t=[];function n(r){if(typeof r==="string"){t.push(r);return}if(Array.isArray(r)){for(let s of r)n(s);return}if(r&&typeof r==="object"){let s=r;if(typeof s.text==="string"){t.push(s.text);return}if(Array.isArray(s.elements))n(s.elements);else if(Array.isArray(s.content))n(s.content)}}for(let r of e)n(r);return t.join("").trim()}async function nu(e,t,n){let r=new Map;return async(s)=>{if(!s)return"(unknown)";if(r.has(s))return r.get(s);try{let i=await Fc(e,s,t),o=T(i.channel),a;if(o.is_im===!0){let c=typeof o.user==="string"?o.user:"";if(!c||c===n)a="@self";else{let[u]=await yn(e,c);a=`@${u}`}}else a=`#${typeof o.name==="string"?o.name:s}`;return r.set(s,a),a}catch{return s}}}function Qr(e){let t=T(X(e.destinations)[0]);return String(t.channel_id??e.channel_id??e.channel??"")}function ys(e){return ud(X(e.blocks))||(typeof e.text==="string"?e.text:"(no text)")}async function ld(e,t,n=!1){let r=await wn(e,t),s=X(r.drafts??r.messages??[]).map(T).filter((u)=>u.is_deleted!==!0),i=n?s:s.filter((u)=>u.is_sent!==!0);if(i.length===0){console.log(n?"No drafts.":"No pending drafts. Run with --all to include sent.");return}let o="";try{({userId:o}=await jr(e,t))}catch{}let a=await nu(e,t,o),c=new Map;for(let u of i){let f=Qr(u),l=ys(u),d=Number(u.date_created??u.date_create??0),p=d?Xr(d):"?",m=await a(f),g=typeof u.id==="string"?u.id:"",y=u.is_sent===!0?" [SENT]":"",C=xn(await Qt(e,l,c));console.log(`-- ${g} ${m} [${p}]${y}`);for(let F of C.split(`
183
- `))console.log(` ${F}`)}}async function fd(e,t,n){let r=await wn(e,t),s=X(r.drafts).map(T).find((m)=>String(m.id)===n);if(!s)console.error(`Draft not found: ${n}`),process.exit(1);let i="";try{({userId:i}=await jr(e,t))}catch{}let o=await nu(e,t,i),a=Qr(s),c=ys(s),u=Number(s.date_created??0),f=String(s.last_updated_ts??"?"),l=await o(a),p=xn(await Qt(e,c,new Map));console.log(`id: ${s.id}`),console.log(`channel: ${l} (${a})`),console.log(`created: ${u?Xr(u):"?"}`),console.log(`updated: ${Xr(Number(f.split(".")[0]))}`),console.log(`status: ${s.is_sent===!0?"sent":"pending"}`),console.log("---"),console.log(p)}function Ye(...e){return Yf(e.join(`
184
- `)).slice(0,4)}function te(e){return e.replace(/\x1b\[[0-9;:?]*[ -/]*[@-~]/g,"").replace(/[\x00-\x1f\x7f-\x9f]/g,"").replace(/[\u061c\u200e\u200f\u202a-\u202e\u2066-\u2069]/g,"")}var dd={"reactions.add":"reactions:write","reactions.remove":"reactions:write","chat.postMessage":"chat:write","chat.update":"chat:write","chat.delete":"chat:write","conversations.replies":"channels:history (or groups:history)","conversations.history":"channels:history (or groups:history)"};function tt(e){let t=e instanceof Error?e.message:String(e),n=t.match(/Slack error on (\S+): (\w+)/);if(!n)return t;let[,r,s]=n;switch(s){case"missing_scope":return`Error: token lacks the ${dd[r]??"the required"} scope (needed for ${r}). Add it to your Slack App's User Token Scopes (or Bot Token Scopes if you use a bot token / --as-bot) \u2014 it must be on the token type the CLI actually uses \u2014 then reinstall to the workspace.`;case"invalid_name":return"Error: not a valid emoji shortcode \u2014 use the name without colons (e.g. white_check_mark), and make sure it exists in the workspace.";case"already_reacted":return"Error: you've already added that reaction to the message.";case"no_reaction":return"Error: that reaction isn't on the message \u2014 nothing to remove.";case"message_not_found":return"Error: no message found at that timestamp in the channel \u2014 check the target ts/permalink.";case"channel_not_found":return"Error: channel not found \u2014 check the target.";default:return t}}async function ei(e,t,n){if(!t.startsWith("D"))return null;try{let r=await xs(e,t,n);if(!r)return null;return await Rc(e,r,bn,n)}catch{return null}}function Ne(e,t,n,r){for(let i of n)console.log(i);let s=Jc(new Date,r);if(s)console.log(s);if(e!==void 0)console.error(`Code mismatch (got ${e}, expected ${t})`);console.error(`Rerun with --code=${t}`),process.exit(1)}function Cs(e){let t=Bt(e);if(t)return t.ts?{ref:t.channel,ts:t.ts}:{ref:t.channel};if(e.startsWith("#")||e.startsWith("@")){let n=e.indexOf(":");if(n>0){let r=e.slice(n+1);if(/^\d{10}\.\d{6}$/.test(r))return{ref:e.slice(0,n),ts:r};if(/^\d{4}-\d{2}-\d{2}T/.test(r))return{ref:e.slice(0,n),ts:Zr(r)}}}return{ref:e}}function Sn(e,t=!0){let n=Bt(e);if(n){if(!t)return{ref:n.channel};let s=n.threadTs??n.ts;return s?{ref:n.channel,threadTs:s}:{ref:n.channel}}let r=e.indexOf(":");if(r>0){let s=e.slice(r+1);if(/^\d{10}\.\d{6}$/.test(s))return{ref:e.slice(0,r),threadTs:s};if(/^\d{4}-\d{2}-\d{2}T/.test(s))return{ref:e.slice(0,r),threadTs:Zr(s)}}return{ref:e}}async function Es(e,t,n,r){let s=n;if(/^#?[CDG][A-Z0-9]{8,}$/.test(n)||!n.startsWith("#")&&!n.startsWith("@"))try{let o=T(await Fn(e,t,r)),a=T(o.channel);if(a.is_im===!0){let c=typeof a.user==="string"?a.user:"";s=c?`@${await qe(e,c,r)}`:t}else s=typeof a.name==="string"?`#${a.name}`:t}catch{s=t}return s===t?t:`${s} (${t})`}async function en(e,t){try{return await ec(e,t)}catch{return null}}function jt(e,t){let n;return async()=>{if(n===void 0)n=await en(e,t);return n}}function su(e,t){let n=t?" [as bot]":"";if(!e)return`(unknown \u2014 auth.test failed)${n}`;let r=te(e.user||e.userId||"?"),s=e.userId?` (${e.userId})`:"",i=e.team?` \u2014 ${te(e.team)}`:"";return`@${r}${s}${i}${n}`}function ve(e,t={}){return` ${"From:".padEnd(t.pad??6)}${su(e,t.asBot)}`}async function Gr(e,t,n=60,r){let s=typeof t.user==="string"?await qe(e,t.user,r):typeof t.username==="string"?t.username:"?",i=(typeof t.text==="string"?t.text:"").split(`
185
- `)[0]??"",o=i.length>n?`${i.slice(0,n)}\u2026`:i,a=typeof t.ts==="string"?t.ts:"";return`${a?Vr(a).slice(0,16).replace("T"," "):""} @${s}${o?`: ${o}`:""}`}async function pd(e,t,n,r){let s=n.find((i)=>String(i.ts)===t)??n[0];if(!s)return t;return Gr(e,s,40,r)}function Hc(e){return e.toLowerCase().replace(/<[@#!][^>]+>/g," ").replace(/[^\p{L}\p{N}\s]/gu," ").replace(/\s+/g," ").trim()}function hd(e,t){let n=Hc(e),r=Hc(t);if(!n||!r)return 0;if(n===r)return 1;let s=(u)=>{let f=new Map;for(let l=0;l<u.length-1;l++){let d=u.slice(l,l+2);f.set(d,(f.get(d)??0)+1)}return f},i=s(n),o=s(r);if(i.size===0||o.size===0)return 0;let a=0;for(let[u,f]of i){let l=o.get(u);if(l)a+=Math.min(f,l)}let c=qc(i)+qc(o);return c===0?0:2*a/c}function qc(e){let t=0;for(let n of e.values())t+=n;return t}async function gd(e,t){let n=jt(e,t.cookie),{ref:r,ts:s}=Cs(t.target);if(!s)console.error("Error: target must embed a message ts (e.g. #chan:2026-05-11T06:01:04.000100 or a Slack permalink URL)"),process.exit(2);let i;if(t.channelId)i=t.channelId;else i=await De(e,r,t.cookie);let o=await He(e,i,s,1,t.cookie),c=X(o.messages).map(T).find((m)=>String(m.ts)===s);if(!c)console.error(`Message not found at ts=${s} in channel ${i}`),process.exit(1);let u=typeof c.text==="string"?c.text:"",f=t.mentions?await vc(e,t.newText,i,t.cookie?{cookie:t.cookie}:{}):t.newText,l=await n(),d=Ye(u,f,l?.userId??"");if(t.code!==d)Ne(t.code,d,["--- Editing as -------------------------------",ve(l),"--- Original message -------------------------",...u.split(`
180
+ Then select it: slack auth use <name> (or pass --workspace <name>)`),process.exit(1)}else throw f}if(r){console.log(JSON.stringify(a,null,2));return}let c=X(hn(a,["messages","matches"])).map(T),u=new Map;for(let f of c){let l=T(f.channel),d=l.is_im===!0,p=typeof l.name==="string"?l.name:"dm",m;if(d&&p.startsWith("U")){let g="@"+p;if(!u.has(g)){let[,y]=await yn(i,p,o);u.set(g,y)}m=`@${u.get(g)??p}`}else if(d)m=`@${p}`;else m=`#${p}`;console.log(await Cs(i,f,u,m,o))}}async function iu(e,t,n,r){let{ref:s,ts:i}=_s(t);if(!i)console.error("Error: target must embed a message ts (e.g. #chan:1700000000.000100 or a Slack permalink URL)"),process.exit(2);return{channelId:n??await Jr(e,s,De,r),ts:i}}async function cd(e,t){let n=Cn(),r={};if(!t.mine)r.shared=!0;if(t.in)r.in=t.in;if(t.from)r.from=t.from;let s=Ic(t.state,n,r);if(!t.json){let i=await en(e,t.cookie),o=t.mine?"your reactions only [hasmy:]":"anyone's reactions [has:]";console.error(`(From: ${au(i)} \xB7 matching ${o})`),console.error(`(query: ${s})`)}await _e("search.messages",()=>ru(e,s,t.count,t.json,t.cookie))}async function ud(e,t){let n=Cn(),{channelId:r,ts:s}=await iu(e,t.target,t.channelId,t.cookie),i=await Bc(e,r,s,t.state,n,t.cookie);if(i.noop){console.log(`= Already ${t.state} (ts: ${s})`);return}let o=i.removed.length?`, removed ${i.removed.map((a)=>`:${a}:`).join(" ")}`:"";if(console.log(`\u2713 ${t.state} :${n.progress[t.state]}: (ts: ${s})${o}`),i.leftover.length)console.error(`\u26A0 ${i.leftover.map((a)=>`:${a}:`).join(" ")} could not be removed \u2014 this message now carries more than one `+"progress reaction. Readers collapse by priority so nothing is lost; repair with: slack todo doctor --in <#chan> --fix")}async function ld(e,t){let n=Cn(),{channelId:r,ts:s}=await iu(e,t.target,t.channelId,t.cookie),i=await Nc(e,r,s,t.flag,n,t.remove===!0,t.cookie);console.log(`\u2713 ${t.remove?"Cleared":"Flagged"} ${t.flag} :${i}: (ts: ${s})`)}async function fd(e,t){let n=Cn(),r=t.channelId??await Jr(e,t.channel,De,t.cookie),s={limit:t.limit};if(t.fix)s.fix=!0;if(t.cookie)s.cookie=t.cookie;let i=await vc(e,r,n,s);if(i.findings.length===0)console.log(`\u2713 No multi-state tasks in ${i.scanned} message(s).`);else{for(let o of i.findings){let a=o.fixed===!0?"fixed":o.fixed===!1?`FAILED: ${o.error??"?"}`:"needs --fix";console.log(`${o.ts} ${o.emoji.map((c)=>`:${c}:`).join(" ")} \u2192 keep :${o.keep}: [${a}] ${te(o.text).slice(0,60)}`)}console.log(`${i.findings.length} multi-state task(s) in ${i.scanned} message(s).`)}if(i.truncated)console.error(`\u26A0 Scan limit reached (${t.limit} messages) \u2014 older history was NOT checked. Raise it with --limit N.`)}async function dd(e,t,n,r){let s=Math.floor(Date.now()/1000)-t*86400,i=await Dn(e),o=X(i.channels).map(T).filter((f)=>f.is_member===!0&&f.is_im!==!0&&f.is_mpim!==!0).filter((f)=>{if(!r)return!0;return(typeof f.name==="string"?f.name:"").toLowerCase().includes(r.toLowerCase())}).sort((f,l)=>Number(l.updated??0)-Number(f.updated??0)),a=new Map,c=0,u=0;for(let f of o){let l=String(f.id??""),d=typeof f.name==="string"?f.name:l,p;try{p=await Ze(e,l,n)}catch(g){console.error(` SKIP #${d}: ${g.message}`);continue}let m=X(p.messages).map(T).filter((g)=>(g.subtype===void 0||g.subtype===null)&&ws(g)>=s);if(m.length===0)continue;u+=1,c+=m.length,console.log(`## #${d} (${m.length} msgs)
181
+ `);for(let g of[...m].reverse()){let y=await nu(e,g,a),C=typeof g.text==="string"?g.text:"",S=xn(await Qt(e,C,a)).split(`
182
+ `).join(" \u21B5 ");console.log(`[${Jc(ws(g))}] ${y}: ${S}`)}console.log("")}console.error(`Dumped ${c} messages across ${u} channels (cutoff: ${t}d)`)}function pd(e){let t=[];function n(r){if(typeof r==="string"){t.push(r);return}if(Array.isArray(r)){for(let s of r)n(s);return}if(r&&typeof r==="object"){let s=r;if(typeof s.text==="string"){t.push(s.text);return}if(Array.isArray(s.elements))n(s.elements);else if(Array.isArray(s.content))n(s.content)}}for(let r of e)n(r);return t.join("").trim()}async function ou(e,t,n){let r=new Map;return async(s)=>{if(!s)return"(unknown)";if(r.has(s))return r.get(s);try{let i=await Cc(e,s,t),o=T(i.channel),a;if(o.is_im===!0){let c=typeof o.user==="string"?o.user:"";if(!c||c===n)a="@self";else{let[u]=await yn(e,c);a=`@${u}`}}else a=`#${typeof o.name==="string"?o.name:s}`;return r.set(s,a),a}catch{return s}}}function ti(e){let t=T(X(e.destinations)[0]);return String(t.channel_id??e.channel_id??e.channel??"")}function bs(e){return pd(X(e.blocks))||(typeof e.text==="string"?e.text:"(no text)")}async function hd(e,t,n=!1){let r=await wn(e,t),s=X(r.drafts??r.messages??[]).map(T).filter((u)=>u.is_deleted!==!0),i=n?s:s.filter((u)=>u.is_sent!==!0);if(i.length===0){console.log(n?"No drafts.":"No pending drafts. Run with --all to include sent.");return}let o="";try{({userId:o}=await Lr(e,t))}catch{}let a=await ou(e,t,o),c=new Map;for(let u of i){let f=ti(u),l=bs(u),d=Number(u.date_created??u.date_create??0),p=d?Vr(d):"?",m=await a(f),g=typeof u.id==="string"?u.id:"",y=u.is_sent===!0?" [SENT]":"",C=xn(await Qt(e,l,c));console.log(`-- ${g} ${m} [${p}]${y}`);for(let F of C.split(`
183
+ `))console.log(` ${F}`)}}async function gd(e,t,n){let r=await wn(e,t),s=X(r.drafts).map(T).find((m)=>String(m.id)===n);if(!s)console.error(`Draft not found: ${n}`),process.exit(1);let i="";try{({userId:i}=await Lr(e,t))}catch{}let o=await ou(e,t,i),a=ti(s),c=bs(s),u=Number(s.date_created??0),f=String(s.last_updated_ts??"?"),l=await o(a),p=xn(await Qt(e,c,new Map));console.log(`id: ${s.id}`),console.log(`channel: ${l} (${a})`),console.log(`created: ${u?Vr(u):"?"}`),console.log(`updated: ${Vr(Number(f.split(".")[0]))}`),console.log(`status: ${s.is_sent===!0?"sent":"pending"}`),console.log("---"),console.log(p)}function Ye(...e){return Zf(e.join(`
184
+ `)).slice(0,4)}function te(e){return e.replace(/\x1b\[[0-9;:?]*[ -/]*[@-~]/g,"").replace(/[\x00-\x1f\x7f-\x9f]/g,"").replace(/[\u061c\u200e\u200f\u202a-\u202e\u2066-\u2069]/g,"")}var md={"reactions.add":"reactions:write","reactions.remove":"reactions:write","chat.postMessage":"chat:write","chat.update":"chat:write","chat.delete":"chat:write","conversations.replies":"channels:history (or groups:history)","conversations.history":"channels:history (or groups:history)"};function tt(e){let t=e instanceof Error?e.message:String(e),n=t.match(/Slack error on (\S+): (\w+)/);if(!n)return t;let[,r,s]=n;switch(s){case"missing_scope":return`Error: token lacks the ${md[r]??"the required"} scope (needed for ${r}). Add it to your Slack App's User Token Scopes (or Bot Token Scopes if you use a bot token / --as-bot) \u2014 it must be on the token type the CLI actually uses \u2014 then reinstall to the workspace.`;case"invalid_name":return"Error: not a valid emoji shortcode \u2014 use the name without colons (e.g. white_check_mark), and make sure it exists in the workspace.";case"already_reacted":return"Error: you've already added that reaction to the message.";case"no_reaction":return"Error: that reaction isn't on the message \u2014 nothing to remove.";case"message_not_found":return"Error: no message found at that timestamp in the channel \u2014 check the target ts/permalink.";case"channel_not_found":return"Error: channel not found \u2014 check the target.";default:return t}}async function xs(e,t,n){if(!t.startsWith("D"))return null;try{let r=await Ss(e,t,n);if(!r)return null;return await Mc(e,r,bn,n)}catch{return null}}function Ne(e,t,n,r,s=new Date){for(let o of n)console.log(o);let i=zc(s,r);if(i)console.log(i);if(e!==void 0)console.error(`Code mismatch (got ${e}, expected ${t})`);console.error(`Rerun with --code=${t}`),process.exit(1)}function _s(e){let t=vt(e);if(t)return t.ts?{ref:t.channel,ts:t.ts}:{ref:t.channel};if(e.startsWith("#")||e.startsWith("@")){let n=e.indexOf(":");if(n>0){let r=e.slice(n+1);if(/^\d{10}\.\d{6}$/.test(r))return{ref:e.slice(0,n),ts:r};if(/^\d{4}-\d{2}-\d{2}T/.test(r))return{ref:e.slice(0,n),ts:ei(r)}}}return{ref:e}}function kn(e,t=!0){let n=vt(e);if(n){if(!t)return{ref:n.channel};let s=n.threadTs??n.ts;return s?{ref:n.channel,threadTs:s}:{ref:n.channel}}let r=e.indexOf(":");if(r>0){let s=e.slice(r+1);if(/^\d{10}\.\d{6}$/.test(s))return{ref:e.slice(0,r),threadTs:s};if(/^\d{4}-\d{2}-\d{2}T/.test(s))return{ref:e.slice(0,r),threadTs:ei(s)}}return{ref:e}}async function ks(e,t,n,r){let s=n;if(/^#?[CDG][A-Z0-9]{8,}$/.test(n)||!n.startsWith("#")&&!n.startsWith("@"))try{let o=T(await Fn(e,t,r)),a=T(o.channel);if(a.is_im===!0){let c=typeof a.user==="string"?a.user:"";s=c?`@${await qe(e,c,r)}`:t}else s=typeof a.name==="string"?`#${a.name}`:t}catch{s=t}return s===t?t:`${s} (${t})`}async function en(e,t){try{return await tc(e,t)}catch{return null}}function Wt(e,t){let n;return async()=>{if(n===void 0)n=await en(e,t);return n}}function au(e,t){let n=t?" [as bot]":"";if(!e)return`(unknown \u2014 auth.test failed)${n}`;let r=te(e.user||e.userId||"?"),s=e.userId?` (${e.userId})`:"",i=e.team?` \u2014 ${te(e.team)}`:"";return`@${r}${s}${i}${n}`}function ve(e,t={}){return` ${"From:".padEnd(t.pad??6)}${au(e,t.asBot)}`}async function Zr(e,t,n=60,r){let s=typeof t.user==="string"?await qe(e,t.user,r):typeof t.username==="string"?t.username:"?",i=(typeof t.text==="string"?t.text:"").split(`
185
+ `)[0]??"",o=i.length>n?`${i.slice(0,n)}\u2026`:i,a=typeof t.ts==="string"?t.ts:"";return`${a?Qr(a).slice(0,16).replace("T"," "):""} @${s}${o?`: ${o}`:""}`}async function Dd(e,t,n,r){let s=n.find((i)=>String(i.ts)===t)??n[0];if(!s)return t;return Zr(e,s,40,r)}function qc(e){return e.toLowerCase().replace(/<[@#!][^>]+>/g," ").replace(/[^\p{L}\p{N}\s]/gu," ").replace(/\s+/g," ").trim()}function yd(e,t){let n=qc(e),r=qc(t);if(!n||!r)return 0;if(n===r)return 1;let s=(u)=>{let f=new Map;for(let l=0;l<u.length-1;l++){let d=u.slice(l,l+2);f.set(d,(f.get(d)??0)+1)}return f},i=s(n),o=s(r);if(i.size===0||o.size===0)return 0;let a=0;for(let[u,f]of i){let l=o.get(u);if(l)a+=Math.min(f,l)}let c=Yc(i)+Yc(o);return c===0?0:2*a/c}function Yc(e){let t=0;for(let n of e.values())t+=n;return t}async function wd(e,t){let n=Wt(e,t.cookie),{ref:r,ts:s}=_s(t.target);if(!s)console.error("Error: target must embed a message ts (e.g. #chan:2026-05-11T06:01:04.000100 or a Slack permalink URL)"),process.exit(2);let i;if(t.channelId)i=t.channelId;else i=await De(e,r,t.cookie);let o=await He(e,i,s,1,t.cookie),c=X(o.messages).map(T).find((m)=>String(m.ts)===s);if(!c)console.error(`Message not found at ts=${s} in channel ${i}`),process.exit(1);let u=typeof c.text==="string"?c.text:"",f=t.mentions?await jc(e,t.newText,i,t.cookie?{cookie:t.cookie}:{}):t.newText,l=await n(),d=Ye(u,f,l?.userId??"");if(t.code!==d)Ne(t.code,d,["--- Editing as -------------------------------",ve(l),"--- Original message -------------------------",...u.split(`
186
186
  `).map((m)=>` ${m}`),"--- Replacing with ---------------------------",...f.split(`
187
- `).map((m)=>` ${m}`),"--------------------------------\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"]);let p=await Xt(e,i,s,f,t.cookie);console.log(`\u2713 Edited (ts: ${p})`)}async function md(e,t){let n=jt(e,t.cookie),{ref:r,ts:s}=Cs(t.target);if(!s)console.error("Error: target must embed a message ts (e.g. #chan:2026-05-11T06:01:04.000100 or a Slack permalink URL)"),process.exit(2);let i;if(t.channelId)i=t.channelId;else i=await De(e,r,t.cookie);let o=await He(e,i,s,1,t.cookie),c=X(o.messages).map(T).find((d)=>String(d.ts)===s);if(!c)console.error(`Message not found at ts=${s} in channel ${i}`),process.exit(1);let u=typeof c.text==="string"?c.text:"",f=await n(),l=Ye(i,s,u,f?.userId??"");if(t.code!==l){let d=await Es(e,i,r,t.cookie);Ne(t.code,l,["--- Deleting message -------------------------",ve(f),` \u2192 ${d} at ${Vr(s)}`,...u.split(`
188
- `).map((p)=>` ${p}`),"---------------------------------------------"])}await uc(e,i,s,t.cookie),console.log(`\u2713 Deleted (ts: ${s})`)}async function Dd(e,t){let{ref:n,ts:r}=Cs(t.target);if(!r)console.error("Error: target must embed a message ts (e.g. #chan:2026-05-11T06:01:04.000100 or a Slack permalink URL)"),process.exit(2);let s=t.emoji.replace(/^:|:$/g,""),i;if(t.channelId)i=t.channelId;else i=await De(e,n,t.cookie);if(t.remove)await mn(e,i,r,s,t.cookie),console.log(`\u2713 Removed :${s}: (ts: ${r})`);else await Gt(e,i,r,s,t.cookie),console.log(`\u2713 Reacted :${s}: (ts: ${r})`)}async function ti(e,t,n,r){if(!n||!t.startsWith("D"))return!1;try{let s=T(await Fn(e,t,r)),i=T(s.channel);return i.is_im===!0&&i.user===n}catch{return!1}}async function yd(e,t){let{ref:n,threadTs:r}=Sn(t.target),s=t.cookie,i=jt(e,s),o;if(t.channelId)o=t.channelId;else if(t.userId)o=await Mt(e,t.userId,s);else o=await De(e,n,s);if(!t.asBot&&await ti(e,o,(await i())?.userId,s))console.error(`Warning: "${t.target}" is a DM to yourself \u2014 Slack will NOT notify you of your own message.
189
- `+` To reach yourself with a notification, send as the bot: slack send '${t.target}' '...' --as-bot`);let a=ut(t.message),c=a,u=null;if(t.mentions){u=await vt(t.mentionToken??e,a,o,t.mentionCookie),c=u.text;for(let A of En(u.unresolved))console.error(`\u26A0 ${te(A)}`)}try{for(let A of await Wc(t.mentionToken??e,c,t.mentionCookie))console.error(`\u26A0 possible untagged mention: ${te(A.surface)} \u2014 @${te(A.display)} won't be notified (did you mean <@${A.userId}>?)`)}catch{}let f=[];if(u&&(u.resolved.length>0||u.unresolved.length>0)){f.push("--- Mentions ---------------------------------");for(let A of u.resolved)f.push(` \u2713 ${te(A.surface)} \u2192 @${te(A.display)} (${A.userId}) \u2014 will notify`);for(let A of u.unresolved){let R=A.reason==="ambiguous"?"ambiguous":A.reason==="unavailable"?"lookup unavailable":"no match";f.push(` \u26A0 ${te(A.surface)} \u2014 plain text, NOT notified (${R})`)}}let l="",d="?",p=[],m,g,y;if(r)try{let A=await He(e,o,r,100,s);p=X(A.messages).map(T);let R=p[p.length-1];l=typeof R?.text==="string"?R.text:"",m=typeof R?.user==="string"?R.user:void 0,g=typeof R?.bot_id==="string"?R.bot_id:void 0,y=typeof R?.ts==="string"?R.ts:void 0}catch{}else try{let A=await Ze(e,o,1,void 0,void 0,s),R=X(A.messages).map(T),B=R.filter((q)=>q.subtype===void 0||q.subtype===null)[0];l=typeof B?.text==="string"?B.text:"",d=typeof B?.user==="string"?await qe(e,B.user,s):typeof B?.username==="string"?B.username:"?";let P=R[0];m=typeof P?.user==="string"?P.user:void 0,g=typeof P?.bot_id==="string"?P.bot_id:void 0,y=typeof P?.ts==="string"?P.ts:void 0}catch{}if(process.env.SLACK_UNREPLIED_WARN!=="0"&&y&&(m||g))try{let A=await i();if(!!A&&(!!m&&!!A.userId&&A.userId===m||!!g&&!!A.botId&&A.botId===g)){let B=`slack edit "#${o}:${y}" "<\u65B0\u3057\u3044\u672C\u6587>" --channel-id ${o}`;try{let P=await gn(e,o,y,s);if(P)B=`slack edit "${P}" "<\u65B0\u3057\u3044\u672C\u6587>"`}catch{}console.error("\u26A0 \u76F8\u624B\u306F\u307E\u3060\u8FD4\u4FE1\u3057\u3066\u3044\u307E\u305B\u3093(\u6700\u5F8C\u306E\u30E1\u30C3\u30BB\u30FC\u30B8\u306F\u3042\u306A\u305F\u306E\u3082\u306E\u3067\u3059)\u3002"),console.error(" \u9023\u6295\u3092\u907F\u3051\u308B\u305F\u3081\u3001\u65B0\u898F\u9001\u4FE1\u3067\u306A\u304F\u76F4\u524D\u306E\u30E1\u30C3\u30BB\u30FC\u30B8\u306E edit \u3092\u691C\u8A0E\u3057\u3066\u304F\u3060\u3055\u3044:"),console.error(` ${B}`),console.error(" \u3053\u306E\u307E\u307E\u9001\u4FE1\u3059\u308B\u5834\u5408\u306F --code=XXXX \u3067\u78BA\u5B9A\u3002")}}catch{}if(r&&p.length){let A={sim:0,msg:null};for(let R of p){let B=typeof R.text==="string"?R.text:"";if(!B)continue;let P=hd(c,B);if(P>A.sim)A={sim:P,msg:R}}if(A.msg&&A.sim>=0.82){let R=Math.round(A.sim*100);console.error(`\u26A0 possible duplicate: ${R}% similar to an existing thread message \u2014 ${await Gr(e,A.msg,60,s)}`)}}let C=await i(),F=await ei(e,o,s),k=Ye(o,r??"",l,c,C?.userId??"");if(t.code!==k){let A=await Es(e,o,n,s),R=ve(C,{asBot:t.asBot});if(r){let B=await pd(e,r,p,s),P=p.slice(-3),q=P.length?await Promise.all(P.map(async(_)=>` ${await Gr(e,_,60,s)}`)):[" (thread context unavailable)"];Ne(t.code,k,["--- Recent messages in thread ----------------",...q,...f,"--- Sending ----------------------------------",R,` \u2192 ${A} thread of ${B} \u2014 THREAD REPLY`,` Message: ${c}`,"--------------------------------\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"],F)}else Ne(t.code,k,["--- Last message in channel ------------------",` ${d}: ${l.split(`
190
- `)[0]?.slice(0,100)??"(empty)"}`,...f,"--- Sending ----------------------------------",R,` \u2192 ${A} \u2014 NEW top-level message`,` Message: ${c}`,"--------------------------------\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"],F)}let S=await fs(e,o,c,r,t.broadcast,s),L="";try{L=await gn(e,o,S,s)}catch{}if(L)console.log(`\u2713 Sent: ${L}`);else console.log(`\u2713 Sent (ts: ${S})`);if(t.asBot&&o.startsWith("D"))try{let A=await gr(e);if(!A.ok)for(let R of mr(A,!0))console.error(R);else{let R=A.appId?`https://api.slack.com/apps/${A.appId}`:"https://api.slack.com/apps";console.error(`Note: if ${t.target} can't reply (app messaging may be off), enable Messages Tab: ${R} \u2192 App Home.`)}}catch{}}var wd=2,Ee=3,bd=1.618033988749895,Fd=1000,Cd=5000,Yc=8,Ed=(e)=>new Promise((t)=>setTimeout(t,e)),xd=new Set(["thread_broadcast"]),_d=/(?<![A-Za-z0-9._@<-])@(here|channel|everyone)(?![A-Za-z0-9._-])/giu;function ws(e){let t=new Set;return{text:e.replace(_d,(r,s)=>{let i=s.toLowerCase();return t.add(i),`<!${i}>`}),kinds:t}}async function xs(e,t,n){if(!t.startsWith("D"))return;try{let r=T(await Fn(e,t,n)),s=T(r.channel);return s.is_im===!0&&typeof s.user==="string"?s.user:void 0}catch{return}}async function ru(e,t){let{channelId:n,ts:r,question:s,reactable:i,threadOnly:o,audience:a,broadcast:c,cookie:u,timeout:f,shown:l}=t,d=t.askerUserId,p=t.askerBotId,m=(B)=>typeof B==="string"&&!!B&&B!==d&&(c||a.has(B));function g(B){let P=X(B.reactions).map(T),q=[];for(let _=0;_<i.length;_++){let E=P.find((N)=>N.name===Ke[_].name),O=E?X(E.users).filter(m):[];if(O.length)q.push({index:_,users:O})}return q}async function y(B,P){let q=typeof B.text==="string"?B.text:"";if(!q)return;let _=kr(q,P);if(_===q)return;try{await Xt(e,n,r,_,u,!0)}catch(E){console.error(` (\u8CEA\u554F\u6587\u306B\u6CE8\u610F\u66F8\u304D\u3092\u5165\u308C\u3089\u308C\u307E\u305B\u3093\u3067\u3057\u305F: ${E instanceof Error?E.message:String(E)})`)}}async function C(B){let P=g(B);if(P.length<=1&&Sr(typeof B.text==="string"?B.text:"").length)await y(B,[]);if(!P.length)return null;if(P.length===1){let{index:E,users:O}=P[0];return{answer:i[E],how:`\u30EA\u30A2\u30AF\u30B7\u30E7\u30F3 ${Ke[E].glyph}`,who:O[0]}}let q=P.map((E)=>Ke[E.index].glyph).join(" / ");console.error(` (${q} \u304C\u540C\u6642\u306B\u9078\u3070\u308C\u3066\u3044\u307E\u3059\u30021 \u3064\u306B\u7D5E\u3063\u3066\u3082\u3089\u3046\u307E\u3067\u5F85\u3061\u307E\u3059)`);let _=[...new Set(P.flatMap((E)=>E.users))].sort();return await y(B,_),null}function F(B,P=1/0){let q=[...B].sort((_,E)=>Number(_.ts)-Number(E.ts));for(let _ of q){if(!(Number(_.ts)>Number(r)))continue;if(!m(_.user))continue;if(typeof _.subtype==="string"&&!xd.has(_.subtype))continue;if(Number(_.ts)>=P)break;let E=typeof _.text==="string"?_.text.trim():"";if(E)return{answer:E,how:"\u8FD4\u4FE1",who:_.user}}return null}async function k(){if(t.threadParentTs){let _=T(await He(e,n,t.threadParentTs,100,u)),E=X(_.messages).map(T),O=E.find((N)=>N.ts===r);if(O){let N=await C(O);if(N)return N}return F(E)}let B=T(await Ze(e,n,30,r,void 0,u,!0)),P=X(B.messages).map(T),q=P.find((_)=>_.ts===r);if(q){let _=await C(q);if(_)return _}if(!o){let _=P.filter((O)=>Number(O.ts)>Number(r)&&(p&&O.bot_id===p||d&&O.user===d)).reduce((O,N)=>Math.min(O,Number(N.ts)),1/0),E=F(P,_);if(E)return E}if(q&&Number(q.reply_count)>0){let _=T(await He(e,n,r,30,u)),E=F(X(_.messages).map(T));if(E)return E}return null}async function S(B){for(let q=0;q<i.length;q++)try{await mn(e,n,r,Ke[q].name,u)}catch{}let P="";if(B.who)try{P=await qe(e,B.who,u)}catch{P=B.who}if(P)console.error(` \u56DE\u7B54\u8005: ${te(P)}`);try{await Xt(e,n,r,Na(s,B,P),u,!0);try{await Gt(e,n,r,Ar,u),await mn(e,n,r,as,u)}catch{}}catch(q){console.error(` (\u5143\u30E1\u30C3\u30BB\u30FC\u30B8\u306E\u66F4\u65B0\u306B\u5931\u6557: ${q instanceof Error?q.message:String(q)})`)}}let L=Date.now()+f*1000,A=0,R=Fd;for(;;){let B=null;try{B=await k(),A=0}catch(P){if(A++,A>=Yc)console.error(`Error: Slack \u3078\u306E\u554F\u3044\u5408\u308F\u305B\u306B ${A} \u56DE\u9023\u7D9A\u3067\u5931\u6557\u3057\u307E\u3057\u305F: ${P instanceof Error?P.message:String(P)}`),process.exit(Ee);console.error(` (Slack \u30A8\u30E9\u30FC ${A}/${Yc}, \u518D\u8A66\u884C\u3057\u307E\u3059: ${P instanceof Error?P.message:String(P)})`)}if(B)await S(B),console.log(B.answer),process.exit(0);if(Date.now()>=L)break;await Ed(Math.min(R,Math.max(0,L-Date.now()))),R=Math.min(R*bd,Cd)}if(f===0)console.error(`\u307E\u3060\u56DE\u7B54\u304C\u3042\u308A\u307E\u305B\u3093: ${l}`);else console.error(`Error: ${f}s \u4EE5\u5185\u306B\u56DE\u7B54\u304C\u3042\u308A\u307E\u305B\u3093\u3067\u3057\u305F (\u30E1\u30C3\u30BB\u30FC\u30B8\u306F\u305D\u306E\u307E\u307E\u6B8B\u3063\u3066\u3044\u307E\u3059)`),console.error(` ${l}`),console.error(` \u3042\u3068\u3067\u56DE\u53CE\u3059\u308B: ${iu(l,t.asBot)}`);process.exit(wd)}function iu(e,t){return`slack ask --waitFor='${e}'${t?" --as-bot":""}`}async function Sd(e,t){let{ref:n,threadTs:r}=Sn(t.target,!1),s=t.cookie,i=jt(e,s),o;if(t.channelId)o=t.channelId;else if(t.userId)o=await Mt(e,t.userId,s);else o=await De(e,n,s);let a=(await i())?.userId??"",c=await xs(e,o,s);if(!t.asBot&&!!a&&c===a)console.error(`Warning: "${t.target}" is a DM to yourself \u2014 Slack will NOT notify you of your own message.
191
- `+` To reach yourself with a notification, ask as the bot: slack ask '${t.target}' '...' --as-bot`);let u=ws(ut(t.question)),f=ws(ut(t.body??"")),l=new Set([...u.kinds,...f.kinds]),d=t.mentionToken??e,p=await vt(d,u.text,o,t.mentionCookie),m=f.text?await vt(d,f.text,o,t.mentionCookie):{text:"",resolved:[],unresolved:[]},g=p.text,y=m.text,C=[...p.resolved,...m.resolved],F=[...p.unresolved,...m.unresolved];for(let Z of En(F))console.error(`\u26A0 ${te(Z)}`);let k=l.size>0,S=new Set(C.map((Z)=>Z.userId).filter((Z)=>Z!==a)),L=new Map(C.map((Z)=>[Z.userId,Z.display])),A;if(k)A=`anyone in ${n} (${[...l].map((Z)=>`@${Z}`).join(", ")})`;else{if(!S.size&&c&&c!==a)S.add(c),L.set(c,await qe(e,c,s));if(!S.size)console.error("Error: `ask` will not post a question nobody is addressed to \u2014 no one is tagged.\n"+(F.length?` (${F.map((Z)=>te(Z.surface)).join(", ")} matched no one, so it names nobody.)
187
+ `).map((m)=>` ${m}`),"--------------------------------\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"]);let p=await Gt(e,i,s,f,t.cookie);console.log(`\u2713 Edited (ts: ${p})`)}async function bd(e,t){let n=Wt(e,t.cookie),{ref:r,ts:s}=_s(t.target);if(!s)console.error("Error: target must embed a message ts (e.g. #chan:2026-05-11T06:01:04.000100 or a Slack permalink URL)"),process.exit(2);let i;if(t.channelId)i=t.channelId;else i=await De(e,r,t.cookie);let o=await He(e,i,s,1,t.cookie),c=X(o.messages).map(T).find((d)=>String(d.ts)===s);if(!c)console.error(`Message not found at ts=${s} in channel ${i}`),process.exit(1);let u=typeof c.text==="string"?c.text:"",f=await n(),l=Ye(i,s,u,f?.userId??"");if(t.code!==l){let d=await ks(e,i,r,t.cookie);Ne(t.code,l,["--- Deleting message -------------------------",ve(f),` \u2192 ${d} at ${Qr(s)}`,...u.split(`
188
+ `).map((p)=>` ${p}`),"---------------------------------------------"])}await lc(e,i,s,t.cookie),console.log(`\u2713 Deleted (ts: ${s})`)}async function Fd(e,t){let{ref:n,ts:r}=_s(t.target);if(!r)console.error("Error: target must embed a message ts (e.g. #chan:2026-05-11T06:01:04.000100 or a Slack permalink URL)"),process.exit(2);let s=t.emoji.replace(/^:|:$/g,""),i;if(t.channelId)i=t.channelId;else i=await De(e,n,t.cookie);if(t.remove)await mn(e,i,r,s,t.cookie),console.log(`\u2713 Removed :${s}: (ts: ${r})`);else await Vt(e,i,r,s,t.cookie),console.log(`\u2713 Reacted :${s}: (ts: ${r})`)}async function ni(e,t,n,r){if(!n||!t.startsWith("D"))return!1;try{let s=T(await Fn(e,t,r)),i=T(s.channel);return i.is_im===!0&&i.user===n}catch{return!1}}async function Cd(e,t){let{ref:n,threadTs:r}=kn(t.target),s=t.cookie,i=Wt(e,s),o;if(t.channelId)o=t.channelId;else if(t.userId)o=await ct(e,t.userId,s);else o=await De(e,n,s);if(!t.asBot&&await ni(e,o,(await i())?.userId,s))console.error(`Warning: "${t.target}" is a DM to yourself \u2014 Slack will NOT notify you of your own message.
189
+ `+` To reach yourself with a notification, send as the bot: slack send '${t.target}' '...' --as-bot`);let a=ft(t.message),c=a,u=null;if(t.mentions){u=await Lt(t.mentionToken??e,a,o,t.mentionCookie),c=u.text;for(let A of En(u.unresolved))console.error(`\u26A0 ${te(A)}`)}try{for(let A of await Uc(t.mentionToken??e,c,t.mentionCookie))console.error(`\u26A0 possible untagged mention: ${te(A.surface)} \u2014 @${te(A.display)} won't be notified (did you mean <@${A.userId}>?)`)}catch{}let f=[];if(u&&(u.resolved.length>0||u.unresolved.length>0)){f.push("--- Mentions ---------------------------------");for(let A of u.resolved)f.push(` \u2713 ${te(A.surface)} \u2192 @${te(A.display)} (${A.userId}) \u2014 will notify`);for(let A of u.unresolved){let R=A.reason==="ambiguous"?"ambiguous":A.reason==="unavailable"?"lookup unavailable":"no match";f.push(` \u26A0 ${te(A.surface)} \u2014 plain text, NOT notified (${R})`)}}let l="",d="?",p=[],m,g,y;if(r)try{let A=await He(e,o,r,100,s);p=X(A.messages).map(T);let R=p[p.length-1];l=typeof R?.text==="string"?R.text:"",m=typeof R?.user==="string"?R.user:void 0,g=typeof R?.bot_id==="string"?R.bot_id:void 0,y=typeof R?.ts==="string"?R.ts:void 0}catch{}else try{let A=await Ze(e,o,1,void 0,void 0,s),R=X(A.messages).map(T),B=R.filter((q)=>q.subtype===void 0||q.subtype===null)[0];l=typeof B?.text==="string"?B.text:"",d=typeof B?.user==="string"?await qe(e,B.user,s):typeof B?.username==="string"?B.username:"?";let P=R[0];m=typeof P?.user==="string"?P.user:void 0,g=typeof P?.bot_id==="string"?P.bot_id:void 0,y=typeof P?.ts==="string"?P.ts:void 0}catch{}if(process.env.SLACK_UNREPLIED_WARN!=="0"&&y&&(m||g))try{let A=await i();if(!!A&&(!!m&&!!A.userId&&A.userId===m||!!g&&!!A.botId&&A.botId===g)){let B=`slack edit "#${o}:${y}" "<\u65B0\u3057\u3044\u672C\u6587>" --channel-id ${o}`;try{let P=await gn(e,o,y,s);if(P)B=`slack edit "${P}" "<\u65B0\u3057\u3044\u672C\u6587>"`}catch{}console.error("\u26A0 \u76F8\u624B\u306F\u307E\u3060\u8FD4\u4FE1\u3057\u3066\u3044\u307E\u305B\u3093(\u6700\u5F8C\u306E\u30E1\u30C3\u30BB\u30FC\u30B8\u306F\u3042\u306A\u305F\u306E\u3082\u306E\u3067\u3059)\u3002"),console.error(" \u9023\u6295\u3092\u907F\u3051\u308B\u305F\u3081\u3001\u65B0\u898F\u9001\u4FE1\u3067\u306A\u304F\u76F4\u524D\u306E\u30E1\u30C3\u30BB\u30FC\u30B8\u306E edit \u3092\u691C\u8A0E\u3057\u3066\u304F\u3060\u3055\u3044:"),console.error(` ${B}`),console.error(" \u3053\u306E\u307E\u307E\u9001\u4FE1\u3059\u308B\u5834\u5408\u306F --code=XXXX \u3067\u78BA\u5B9A\u3002")}}catch{}if(r&&p.length){let A={sim:0,msg:null};for(let R of p){let B=typeof R.text==="string"?R.text:"";if(!B)continue;let P=yd(c,B);if(P>A.sim)A={sim:P,msg:R}}if(A.msg&&A.sim>=0.82){let R=Math.round(A.sim*100);console.error(`\u26A0 possible duplicate: ${R}% similar to an existing thread message \u2014 ${await Zr(e,A.msg,60,s)}`)}}let C=await i(),F=await xs(e,o,s),S=Ye(o,r??"",l,c,C?.userId??"");if(t.code!==S){let A=await ks(e,o,n,s),R=ve(C,{asBot:t.asBot});if(r){let B=await Dd(e,r,p,s),P=p.slice(-3),q=P.length?await Promise.all(P.map(async(_)=>` ${await Zr(e,_,60,s)}`)):[" (thread context unavailable)"];Ne(t.code,S,["--- Recent messages in thread ----------------",...q,...f,"--- Sending ----------------------------------",R,` \u2192 ${A} thread of ${B} \u2014 THREAD REPLY`,` Message: ${c}`,"--------------------------------\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"],F)}else Ne(t.code,S,["--- Last message in channel ------------------",` ${d}: ${l.split(`
190
+ `)[0]?.slice(0,100)??"(empty)"}`,...f,"--- Sending ----------------------------------",R,` \u2192 ${A} \u2014 NEW top-level message`,` Message: ${c}`,"--------------------------------\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"],F)}let k=await ps(e,o,c,r,t.broadcast,s),L="";try{L=await gn(e,o,k,s)}catch{}if(L)console.log(`\u2713 Sent: ${L}`);else console.log(`\u2713 Sent (ts: ${k})`);if(t.asBot&&o.startsWith("D"))try{let A=await Vn(e);if(!A.ok)for(let R of Zn(A,!0))console.error(R);else{let R=A.appId?`https://api.slack.com/apps/${A.appId}`:"https://api.slack.com/apps";console.error(`Note: if ${t.target} can't reply (app messaging may be off), enable Messages Tab: ${R} \u2192 App Home.`)}}catch{}}var Ed=2,Ee=3,xd=1.618033988749895,_d=1000,kd=5000,Xc=8,Sd=(e)=>new Promise((t)=>setTimeout(t,e)),Ad=new Set(["thread_broadcast"]),$d=/(?<![A-Za-z0-9._@<-])@(here|channel|everyone)(?![A-Za-z0-9._-])/giu;function Fs(e){let t=new Set;return{text:e.replace($d,(r,s)=>{let i=s.toLowerCase();return t.add(i),`<!${i}>`}),kinds:t}}async function Ss(e,t,n){if(!t.startsWith("D"))return;try{let r=T(await Fn(e,t,n)),s=T(r.channel);return s.is_im===!0&&typeof s.user==="string"?s.user:void 0}catch{return}}async function cu(e,t){let{channelId:n,ts:r,question:s,reactable:i,threadOnly:o,audience:a,broadcast:c,cookie:u,timeout:f,shown:l}=t,d=t.askerUserId,p=t.askerBotId,m=(B)=>typeof B==="string"&&!!B&&B!==d&&(c||a.has(B));function g(B){let P=X(B.reactions).map(T),q=[];for(let _=0;_<i.length;_++){let E=P.find((N)=>N.name===Ke[_].name),O=E?X(E.users).filter(m):[];if(O.length)q.push({index:_,users:O})}return q}async function y(B,P){let q=typeof B.text==="string"?B.text:"";if(!q)return;let _=Ar(q,P);if(_===q)return;try{await Gt(e,n,r,_,u,!0)}catch(E){console.error(` (\u8CEA\u554F\u6587\u306B\u6CE8\u610F\u66F8\u304D\u3092\u5165\u308C\u3089\u308C\u307E\u305B\u3093\u3067\u3057\u305F: ${E instanceof Error?E.message:String(E)})`)}}async function C(B){let P=g(B);if(P.length<=1&&Sr(typeof B.text==="string"?B.text:"").length)await y(B,[]);if(!P.length)return null;if(P.length===1){let{index:E,users:O}=P[0];return{answer:i[E],how:`\u30EA\u30A2\u30AF\u30B7\u30E7\u30F3 ${Ke[E].glyph}`,who:O[0]}}let q=P.map((E)=>Ke[E.index].glyph).join(" / ");console.error(` (${q} \u304C\u540C\u6642\u306B\u9078\u3070\u308C\u3066\u3044\u307E\u3059\u30021 \u3064\u306B\u7D5E\u3063\u3066\u3082\u3089\u3046\u307E\u3067\u5F85\u3061\u307E\u3059)`);let _=[...new Set(P.flatMap((E)=>E.users))].sort();return await y(B,_),null}function F(B,P=1/0){let q=[...B].sort((_,E)=>Number(_.ts)-Number(E.ts));for(let _ of q){if(!(Number(_.ts)>Number(r)))continue;if(!m(_.user))continue;if(typeof _.subtype==="string"&&!Ad.has(_.subtype))continue;if(Number(_.ts)>=P)break;let E=typeof _.text==="string"?_.text.trim():"";if(E)return{answer:E,how:"\u8FD4\u4FE1",who:_.user}}return null}async function S(){if(t.threadParentTs){let _=T(await He(e,n,t.threadParentTs,100,u)),E=X(_.messages).map(T),O=E.find((N)=>N.ts===r);if(O){let N=await C(O);if(N)return N}return F(E)}let B=T(await Ze(e,n,30,r,void 0,u,!0)),P=X(B.messages).map(T),q=P.find((_)=>_.ts===r);if(q){let _=await C(q);if(_)return _}if(!o){let _=P.filter((O)=>Number(O.ts)>Number(r)&&(p&&O.bot_id===p||d&&O.user===d)).reduce((O,N)=>Math.min(O,Number(N.ts)),1/0),E=F(P,_);if(E)return E}if(q&&Number(q.reply_count)>0){let _=T(await He(e,n,r,30,u)),E=F(X(_.messages).map(T));if(E)return E}return null}async function k(B){for(let q=0;q<i.length;q++)try{await mn(e,n,r,Ke[q].name,u)}catch{}let P="";if(B.who)try{P=await qe(e,B.who,u)}catch{P=B.who}if(P)console.error(` \u56DE\u7B54\u8005: ${te(P)}`);try{await Gt(e,n,r,va(s,B,P),u,!0);try{await Vt(e,n,r,$r,u),await mn(e,n,r,us,u)}catch{}}catch(q){console.error(` (\u5143\u30E1\u30C3\u30BB\u30FC\u30B8\u306E\u66F4\u65B0\u306B\u5931\u6557: ${q instanceof Error?q.message:String(q)})`)}}let L=Date.now()+f*1000,A=0,R=_d;for(;;){let B=null;try{B=await S(),A=0}catch(P){if(A++,A>=Xc)console.error(`Error: Slack \u3078\u306E\u554F\u3044\u5408\u308F\u305B\u306B ${A} \u56DE\u9023\u7D9A\u3067\u5931\u6557\u3057\u307E\u3057\u305F: ${P instanceof Error?P.message:String(P)}`),process.exit(Ee);console.error(` (Slack \u30A8\u30E9\u30FC ${A}/${Xc}, \u518D\u8A66\u884C\u3057\u307E\u3059: ${P instanceof Error?P.message:String(P)})`)}if(B)await k(B),console.log(B.answer),process.exit(0);if(Date.now()>=L)break;await Sd(Math.min(R,Math.max(0,L-Date.now()))),R=Math.min(R*xd,kd)}if(f===0)console.error(`\u307E\u3060\u56DE\u7B54\u304C\u3042\u308A\u307E\u305B\u3093: ${l}`);else console.error(`Error: ${f}s \u4EE5\u5185\u306B\u56DE\u7B54\u304C\u3042\u308A\u307E\u305B\u3093\u3067\u3057\u305F (\u30E1\u30C3\u30BB\u30FC\u30B8\u306F\u305D\u306E\u307E\u307E\u6B8B\u3063\u3066\u3044\u307E\u3059)`),console.error(` ${l}`),console.error(` \u3042\u3068\u3067\u56DE\u53CE\u3059\u308B: ${uu(l,t.asBot)}`);process.exit(Ed)}function uu(e,t){return`slack ask --waitFor='${e}'${t?" --as-bot":""}`}async function Od(e,t){let{ref:n,threadTs:r}=kn(t.target,!1),s=t.cookie,i=Wt(e,s),o;if(t.channelId)o=t.channelId;else if(t.userId)o=await ct(e,t.userId,s);else o=await De(e,n,s);let a=(await i())?.userId??"",c=await Ss(e,o,s);if(!t.asBot&&!!a&&c===a)console.error(`Warning: "${t.target}" is a DM to yourself \u2014 Slack will NOT notify you of your own message.
191
+ `+` To reach yourself with a notification, ask as the bot: slack ask '${t.target}' '...' --as-bot`);let u=Fs(ft(t.question)),f=Fs(ft(t.body??"")),l=new Set([...u.kinds,...f.kinds]),d=t.mentionToken??e,p=await Lt(d,u.text,o,t.mentionCookie),m=f.text?await Lt(d,f.text,o,t.mentionCookie):{text:"",resolved:[],unresolved:[]},g=p.text,y=m.text,C=[...p.resolved,...m.resolved],F=[...p.unresolved,...m.unresolved];for(let Z of En(F))console.error(`\u26A0 ${te(Z)}`);let S=l.size>0,k=new Set(C.map((Z)=>Z.userId).filter((Z)=>Z!==a)),L=new Map(C.map((Z)=>[Z.userId,Z.display])),A;if(S)A=`anyone in ${n} (${[...l].map((Z)=>`@${Z}`).join(", ")})`;else{if(!k.size&&c&&c!==a)k.add(c),L.set(c,await qe(e,c,s));if(!k.size)console.error("Error: `ask` will not post a question nobody is addressed to \u2014 no one is tagged.\n"+(F.length?` (${F.map((Z)=>te(Z.surface)).join(", ")} matched no one, so it names nobody.)
192
192
  `:"")+` Tag the person who should answer: slack ask '${t.target}' '@alice ${t.question}' ...
193
193
  Or open it to the whole channel: slack ask '${t.target}' '@here ${t.question}' ...
194
- (In a 1:1 DM the other person counts automatically.)`),process.exit(Ee);A=[...S].map((Z)=>`@${te(L.get(Z)??Z)} (${Z})`).join(", ")}let R=t.choices.map(ut),B=R.slice(0,os),P=R.slice(os),q=!o.startsWith("D")||!!r,_=Ba(g,y,B,P,q),E="",O="?";try{let Z=await Ze(e,o,1,void 0,void 0,s),v=X(Z.messages).map(T).filter((be)=>be.subtype===void 0||be.subtype===null)[0];E=typeof v?.text==="string"?v.text:"",O=typeof v?.user==="string"?await qe(e,v.user,s):typeof v?.username==="string"?v.username:"?"}catch{}let N=await i(),Q=await ei(e,o,s),oe=Ye(o,r??"",E,_,N?.userId??"");if(t.code!==oe){let Z=await Es(e,o,n,s),v=B.length?["--- Choices (seeded as reactions) ------------",...B.map((be,Lt)=>` ${Ke[Lt].glyph} ${fn(be)}`),...P.map((be,Lt)=>` (${Lt+11}) ${fn(be)} \u2014 text answer only`)]:["--- Choices ----------------------------------"," (none \u2014 free-text reply)"];Ne(t.code,oe,["--- Last message in channel ------------------",` ${O}: ${E.split(`
195
- `)[0]?.slice(0,100)??"(empty)"}`,...v,"--- Asking -----------------------------------",ve(N,{asBot:t.asBot}),` \u2192 ${Z}${r?" \u2014 THREAD REPLY":" \u2014 NEW top-level message"}`,` Question: ${g}`,` Answerable by: ${A}`,` Via: ${q?"reactions or thread replies":"reactions or replies in this DM"}`,"--------------------------------\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"],Q)}let V=await fs(e,o,_,r,!1,s,!0);await Rr([as,...B.map((Z,v)=>Ke[v].name)],(Z)=>Gt(e,o,V,Z,s),(Z,v)=>{let be=v instanceof Error?v.message:String(v);if(Z===as)console.error(` (marker ${Z} \u3092\u4ED8\u3051\u3089\u308C\u307E\u305B\u3093\u3067\u3057\u305F: ${be})`);else console.error(` (\u30EA\u30A2\u30AF\u30B7\u30E7\u30F3 ${Z} \u3092\u4ED8\u3051\u3089\u308C\u307E\u305B\u3093\u3067\u3057\u305F: ${be})`)});let ae="";try{ae=await gn(e,o,V,s)}catch{}let Ie=ae||`${o}:${V}`;if(console.error(`\u2713 Asked: ${Ie}`),!t.wait){console.log(iu(Ie,!!t.asBot));return}let ee=t.timeout??3600;console.error(` \u56DE\u7B54\u3092\u5F85\u3063\u3066\u3044\u307E\u3059 (\u6700\u5927 ${ee}s)\u2026 Ctrl-C \u3067\u4E2D\u65AD`);let Se={channelId:o,ts:V,question:g,reactable:B,threadOnly:q,audience:S,broadcast:k,askerUserId:N?.userId??"",askerBotId:N?.botId??"",timeout:ee,shown:Ie,asBot:!!t.asBot};if(r)Se.threadParentTs=r;if(s)Se.cookie=s;await ru(e,Se)}async function kd(e,t){let n=Bt(t.link),r,s,i;if(n?.ts)r=n.channel,s=n.ts,i=n.threadTs&&n.threadTs!==n.ts?n.threadTs:void 0;else{let m=t.link.match(/^([A-Za-z0-9]+):(\d{10}\.\d{6})$/);if(!m)console.error(`Error: --waitFor needs the permalink of a question (or 'C\u2026:1700000000.000100').
196
- `+` Got: ${te(t.link)}`),process.exit(Ee);r=m[1],s=m[2]}let o;if(i){let m=T(await He(e,r,i,100,t.cookie));o=X(m.messages).map(T).find((g)=>g.ts===s)}else{let m=T(await Ze(e,r,1,s,void 0,t.cookie,!0));o=X(m.messages).map(T).find((g)=>g.ts===s)}if(!o)console.error(`Error: \u305D\u306E\u30E1\u30C3\u30BB\u30FC\u30B8\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093: ${te(t.link)}`),process.exit(Ee);let a=typeof o.text==="string"?o.text:"",c=ja(a);if(c.kind==="other")console.error("Error: \u3053\u308C\u306F `slack ask` \u306E\u8CEA\u554F\u3068\u3057\u3066\u8AAD\u307F\u53D6\u308C\u307E\u305B\u3093\u3002\n"+` \u7406\u7531: ${va(a)}
194
+ (In a 1:1 DM the other person counts automatically.)`),process.exit(Ee);A=[...k].map((Z)=>`@${te(L.get(Z)??Z)} (${Z})`).join(", ")}let R=t.choices.map(ft),B=R.slice(0,cs),P=R.slice(cs),q=!o.startsWith("D")||!!r,_=Na(g,y,B,P,q),E="",O="?";try{let Z=await Ze(e,o,1,void 0,void 0,s),v=X(Z.messages).map(T).filter((be)=>be.subtype===void 0||be.subtype===null)[0];E=typeof v?.text==="string"?v.text:"",O=typeof v?.user==="string"?await qe(e,v.user,s):typeof v?.username==="string"?v.username:"?"}catch{}let N=await i(),Q=await xs(e,o,s),oe=Ye(o,r??"",E,_,N?.userId??"");if(t.code!==oe){let Z=await ks(e,o,n,s),v=B.length?["--- Choices (seeded as reactions) ------------",...B.map((be,Ut)=>` ${Ke[Ut].glyph} ${fn(be)}`),...P.map((be,Ut)=>` (${Ut+11}) ${fn(be)} \u2014 text answer only`)]:["--- Choices ----------------------------------"," (none \u2014 free-text reply)"];Ne(t.code,oe,["--- Last message in channel ------------------",` ${O}: ${E.split(`
195
+ `)[0]?.slice(0,100)??"(empty)"}`,...v,"--- Asking -----------------------------------",ve(N,{asBot:t.asBot}),` \u2192 ${Z}${r?" \u2014 THREAD REPLY":" \u2014 NEW top-level message"}`,` Question: ${g}`,` Answerable by: ${A}`,` Via: ${q?"reactions or thread replies":"reactions or replies in this DM"}`,"--------------------------------\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"],Q)}let V=await ps(e,o,_,r,!1,s,!0);await Mr([us,...B.map((Z,v)=>Ke[v].name)],(Z)=>Vt(e,o,V,Z,s),(Z,v)=>{let be=v instanceof Error?v.message:String(v);if(Z===us)console.error(` (marker ${Z} \u3092\u4ED8\u3051\u3089\u308C\u307E\u305B\u3093\u3067\u3057\u305F: ${be})`);else console.error(` (\u30EA\u30A2\u30AF\u30B7\u30E7\u30F3 ${Z} \u3092\u4ED8\u3051\u3089\u308C\u307E\u305B\u3093\u3067\u3057\u305F: ${be})`)});let ae="";try{ae=await gn(e,o,V,s)}catch{}let Ie=ae||`${o}:${V}`;if(console.error(`\u2713 Asked: ${Ie}`),!t.wait){console.log(uu(Ie,!!t.asBot));return}let ee=t.timeout??3600;console.error(` \u56DE\u7B54\u3092\u5F85\u3063\u3066\u3044\u307E\u3059 (\u6700\u5927 ${ee}s)\u2026 Ctrl-C \u3067\u4E2D\u65AD`);let ke={channelId:o,ts:V,question:g,reactable:B,threadOnly:q,audience:k,broadcast:S,askerUserId:N?.userId??"",askerBotId:N?.botId??"",timeout:ee,shown:Ie,asBot:!!t.asBot};if(r)ke.threadParentTs=r;if(s)ke.cookie=s;await cu(e,ke)}async function Id(e,t){let n=vt(t.link),r,s,i;if(n?.ts)r=n.channel,s=n.ts,i=n.threadTs&&n.threadTs!==n.ts?n.threadTs:void 0;else{let m=t.link.match(/^([A-Za-z0-9]+):(\d{10}\.\d{6})$/);if(!m)console.error(`Error: --waitFor needs the permalink of a question (or 'C\u2026:1700000000.000100').
196
+ `+` Got: ${te(t.link)}`),process.exit(Ee);r=m[1],s=m[2]}let o;if(i){let m=T(await He(e,r,i,100,t.cookie));o=X(m.messages).map(T).find((g)=>g.ts===s)}else{let m=T(await Ze(e,r,1,s,void 0,t.cookie,!0));o=X(m.messages).map(T).find((g)=>g.ts===s)}if(!o)console.error(`Error: \u305D\u306E\u30E1\u30C3\u30BB\u30FC\u30B8\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093: ${te(t.link)}`),process.exit(Ee);let a=typeof o.text==="string"?o.text:"",c=La(a);if(c.kind==="other")console.error("Error: \u3053\u308C\u306F `slack ask` \u306E\u8CEA\u554F\u3068\u3057\u3066\u8AAD\u307F\u53D6\u308C\u307E\u305B\u3093\u3002\n"+` \u7406\u7531: ${ja(a)}
197
197
  ${te(t.link)}
198
- `+` (\u62BC\u3055\u308C\u305F\u30EA\u30A2\u30AF\u30B7\u30E7\u30F3\u306F\u6B8B\u3063\u3066\u3044\u307E\u3059: slack read '${te(t.link)}' \u3067\u78BA\u8A8D\u3067\u304D\u307E\u3059)`),process.exit(Ee);if(c.kind==="resolved"){console.error(`\u2713 \u56DE\u7B54\u6E08\u307F: ${te(c.question)}`),console.log(c.answer);return}let u=typeof o.user==="string"?o.user:"",f=typeof o.bot_id==="string"?o.bot_id:"",l=/<!(here|channel|everyone)(\^[^>]*)?(\|[^>]*)?>/.test(a),d=new Set;for(let m of a.matchAll(/<@([UW][A-Z0-9]+)>/g))if(m[1]!==u)d.add(m[1]);if(!d.size&&!l){let m=await xs(e,r,t.cookie);if(m&&m!==u)d.add(m)}if(!d.size&&!l)console.error(`Error: \u3053\u306E\u8CEA\u554F\u306F\u8AB0\u306B\u3082\u5B9B\u3066\u3089\u308C\u3066\u3044\u306A\u3044\u305F\u3081\u3001\u6709\u52B9\u306A\u56DE\u7B54\u8005\u3092\u5224\u5B9A\u3067\u304D\u307E\u305B\u3093: ${te(t.link)}`),process.exit(Ee);if(t.timeout>0)console.error(` \u56DE\u7B54\u3092\u5F85\u3063\u3066\u3044\u307E\u3059 (\u6700\u5927 ${t.timeout}s)\u2026 Ctrl-C \u3067\u4E2D\u65AD`);let p={channelId:r,ts:s,question:c.question,reactable:c.reactable,threadOnly:c.threadOnly,audience:d,broadcast:l,askerUserId:u,askerBotId:f,timeout:t.timeout,shown:t.link,asBot:t.asBot};if(i)p.threadParentTs=i;if(t.cookie)p.cookie=t.cookie;await ru(e,p)}var Be=3;function Ad(e){return`slack poll --results='${e}'`}async function $d(e,t){let{ref:n,threadTs:r}=Sn(t.target,!1),s=t.cookie,i=jt(e,s),o;if(t.channelId)o=t.channelId;else if(t.userId)o=await Mt(e,t.userId,s);else o=await De(e,n,s);let a=(await i())?.userId??"",c=await xs(e,o,s);if(!t.asBot&&!!a&&c===a)console.error(`Warning: "${t.target}" is a DM to yourself \u2014 Slack will NOT notify you of your own message.
199
- `+` To reach yourself with a notification, post as the bot: slack poll '${t.target}' '...' --as-bot`);let u=ws(ut(t.question)),f=ws(ut(t.body??"")),l=t.mentionToken??e,d=await vt(l,u.text,o,t.mentionCookie),p=f.text?await vt(l,f.text,o,t.mentionCookie):{text:"",resolved:[],unresolved:[]},m=d.text,g=p.text;for(let E of En([...d.unresolved,...p.unresolved]))console.error(`\u26A0 ${te(E)}`);let y=t.choices.map(ut),C=!!t.multi,F=t.until??"",k=za(m,g,y,{multi:C,deadline:F}),S="",L="?";try{let E=await Ze(e,o,1,void 0,void 0,s),O=X(E.messages).map(T).filter((N)=>N.subtype===void 0||N.subtype===null)[0];S=typeof O?.text==="string"?O.text:"",L=typeof O?.user==="string"?await qe(e,O.user,s):typeof O?.username==="string"?O.username:"?"}catch{}let A=await i(),R=await ei(e,o,s),B=Ye(o,r??"",S,k,A?.userId??"");if(t.code!==B){let E=await Es(e,o,n,s);Ne(t.code,B,["--- Last message in channel ------------------",` ${L}: ${S.split(`
200
- `)[0]?.slice(0,100)??"(empty)"}`,"--- Ballot (seeded as reactions) -------------",...y.map((O,N)=>` ${Je[N].glyph} ${dn(O)}`),"--- Posting ----------------------------------",ve(A,{asBot:t.asBot}),` \u2192 ${E}${r?" \u2014 THREAD REPLY":" \u2014 NEW top-level message"}`,` Question: ${m}`,` Rule: ${C?"1 \u4EBA \u4F55\u7968\u3067\u3082 (--multi)":"1 \u4EBA 1 \u7968"}${F?` \u2014 \u7DE0\u5207 ${F}`:""}`," Note: \u3042\u306A\u305F\u81EA\u8EAB\u306E\u7968\u306F\u6570\u3048\u307E\u305B\u3093 (\u30D4\u30EB\u306F\u3042\u306A\u305F\u304C\u4ED8\u3051\u305F\u7A2E\u306A\u306E\u3067\u533A\u5225\u3067\u304D\u307E\u305B\u3093)","--------------------------------\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"],R)}let P=await fs(e,o,k,r,!1,s,!0);await Rr([pn,...y.map((E,O)=>Je[O].name)],(E)=>Gt(e,o,P,E,s),(E,O)=>{let N=O instanceof Error?O.message:String(O);if(E===pn)console.error(` (marker ${E} \u3092\u4ED8\u3051\u3089\u308C\u307E\u305B\u3093\u3067\u3057\u305F: ${N})`);else console.error(` (\u30EA\u30A2\u30AF\u30B7\u30E7\u30F3 ${E} \u3092\u4ED8\u3051\u3089\u308C\u307E\u305B\u3093\u3067\u3057\u305F: ${N})`)});let q="";try{q=await gn(e,o,P,s)}catch{}let _=q||`${o}:${P}`;console.error(`\u2713 Posted: ${_}`),console.log(Ad(_)),console.error(` \u7DE0\u3081\u5207\u308B: slack poll --close='${_}'${t.asBot?" --as-bot":""}`)}async function Od(e,t,n){let r=Bt(t),s,i,o;if(r?.ts)s=r.channel,i=r.ts,o=r.threadTs&&r.threadTs!==r.ts?r.threadTs:void 0;else{let c=t.match(/^([A-Za-z0-9]+):(\d{10}\.\d{6})$/);if(!c)console.error(`Error: --results/--close needs the permalink of a poll (or 'C\u2026:1700000000.000100').
201
- `+` Got: ${te(t)}`),process.exit(Be);s=c[1],i=c[2]}let a;if(o){let c=T(await He(e,s,o,100,n));a=X(c.messages).map(T).find((u)=>u.ts===i)}else{let c=T(await Ze(e,s,1,i,void 0,n,!0));a=X(c.messages).map(T).find((u)=>u.ts===i)}if(!a)console.error(`Error: \u305D\u306E\u30E1\u30C3\u30BB\u30FC\u30B8\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093: ${te(t)}`),process.exit(Be);return{channelId:s,ts:i,msg:a}}function Xc(e){let t=Math.max(1,...e.map((n)=>n.count));return e.map((n,r)=>`${Je[r].glyph} ${String(n.count).padStart(3)} ${"\u2588".repeat(Math.round(n.count/t*20))}${n.count?" ":""}${n.choice}`)}async function Id(e,t){let{channelId:n,ts:r,msg:s}=await Od(e,t.link,t.cookie),i=typeof s.text==="string"?s.text:"",o=qa(i);if(o.kind==="other")console.error("Error: \u3053\u308C\u306F `slack poll` \u306E\u6295\u7968\u3067\u306F\u3042\u308A\u307E\u305B\u3093 (\u7968\u306E\u6570\u3048\u65B9\u304C\u5206\u304B\u308A\u307E\u305B\u3093)\u3002\n"+` ${te(t.link)}`),process.exit(Be);if(o.kind==="closed"){console.error(`\u2713 \u6295\u7968\u7D42\u4E86: ${te(o.question)}`);for(let p of Xc(o.tallies))console.log(p);return}let a=new Set;if(typeof s.user==="string"&&s.user)a.add(s.user);let c=await lc(e,n,r,t.cookie),u=Ya(o.choices,c,a,o.multi);console.error(`${te(o.question)}${o.deadline?` (\u7DE0\u5207 ${o.deadline})`:""}`);for(let p of Xc(u.tallies))console.log(p);let f=u.tallies.reduce((p,m)=>p+m.count,0);if(console.error(` \u8A08 ${f} \u7968${o.multi?" (\u8907\u6570\u9078\u629E\u53EF)":""}`),t.names)for(let p=0;p<u.voters.length;p++){if(!u.voters[p].length)continue;let m=await Promise.all(u.voters[p].map((g)=>qe(e,g,t.cookie)));console.error(` ${Je[p].glyph} ${m.map((g)=>`@${te(g)}`).join(", ")}`)}let l=o.multi?[]:u.ambiguous,d=kr(i,l);if(d!==i&&!t.noNotify)try{await Xt(t.writeToken??e,n,r,d,t.writeToken?t.writeCookie:t.cookie,!0)}catch(p){console.error(` (\u6295\u7968\u6587\u306B\u6CE8\u610F\u66F8\u304D\u3092\u5165\u308C\u3089\u308C\u307E\u305B\u3093\u3067\u3057\u305F: ${p instanceof Error?p.message:String(p)})
202
- `+" \u30E1\u30C3\u30BB\u30FC\u30B8\u3092\u66F8\u304D\u63DB\u3048\u3089\u308C\u308B\u306E\u306F\u6295\u7A3F\u8005\u3060\u3051\u3067\u3059 \u2014 bot \u304C\u6295\u7A3F\u3057\u305F\u6295\u7968\u306A\u3089 --as-bot \u3092\u4ED8\u3051\u3066\u304F\u3060\u3055\u3044\u3002")}if(u.ambiguous.length){let p=await Promise.all(u.ambiguous.map((m)=>qe(e,m,t.cookie)));console.error(`\u26A0 1 \u4EBA 1 \u7968\u306A\u306E\u306B\u8907\u6570\u62BC\u3057\u3066\u3044\u308B\u4EBA\u304C\u3044\u307E\u3059 (\u7121\u52B9\u7968): ${p.map((m)=>`@${te(m)}`).join(", ")}`)}if(!t.close)return;await Xt(t.writeToken??e,n,r,Ha(o.question,u.tallies),t.writeToken?t.writeCookie:t.cookie,!0);try{await Gt(t.writeToken??e,n,r,Pr,t.writeToken?t.writeCookie:t.cookie),await mn(t.writeToken??e,n,r,pn,t.writeToken?t.writeCookie:t.cookie)}catch{}console.error(`\u2713 \u6295\u7968\u3092\u7DE0\u3081\u5207\u308A\u307E\u3057\u305F: ${te(t.link)}`)}async function Td(e){let t=await gr(e);for(let n of mr(t,!1))console.log(n);if(!t.ok)process.exit(1)}function Pd(e){if(/^\d{10,}$/.test(e))return parseInt(e,10);let t=new Date(e.replace(" ","T"));if(isNaN(t.getTime()))throw Error(`Cannot parse time: ${e}`);return Math.floor(t.getTime()/1000)}function Rd(e){let t=new Date(e*1000);return`${new Intl.DateTimeFormat("sv-SE",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1,timeZoneName:"short"}).format(t).replace(/\u2212/g,"-")} (local) / ${t.toISOString()} (Unix: ${e})`}async function Md(e,t){let n=jt(e,t.cookie),{ref:r,threadTs:s}=Sn(t.target),i;if(t.channelId)i=t.channelId;else if(t.userId)i=await Mt(e,t.userId,t.cookie);else i=await De(e,r,t.cookie);let o=Pd(t.at),a=new Date(o*1000).toISOString(),c=await n();if(await ti(e,i,c?.userId,t.cookie))console.error(`Warning: "${t.target}" is a DM to yourself \u2014 Slack will NOT notify you when this fires.`);let u=Ye(i,t.message,String(o),c?.userId??"");if(t.code!==u)Ne(t.code,u,["--- Scheduling message -----------------------",ve(c,{pad:9}),` To: ${r}${s?` (thread ${s})`:""}`,` At: ${Rd(o)}`,` Message: ${t.message}`,"---------------------------------------------"]);let f=await oc(e,i,t.message,o,s,t.cookie);console.log(`\u2713 Scheduled (id: ${f}, at: ${a})`)}async function Bd(e,t,n,r){let s;if(n)s=n;else if(t)s=await De(e,t,r);let o=(await ac(e,s,r)).scheduled_messages??[];if(o.length===0){console.log("(no scheduled messages)");return}for(let a of o){let c=new Date(a.post_at*1000).toISOString();console.log(`${a.id} ${c} [${a.channel_id}] ${a.text.split(`
203
- `)[0]?.slice(0,80)??""}`)}}async function Nd(e,t){let n;if(t.channelId)n=t.channelId;else n=await De(e,t.target,t.cookie);let r=await en(e,t.cookie),s=Ye(n,t.id,r?.userId??"");if(t.code!==s)Ne(t.code,s,["--- Deleting scheduled message ---------------",ve(r,{pad:9}),` Channel: ${t.target}`,` ID: ${t.id}`,"---------------------------------------------"]);await cc(e,n,t.id,t.cookie),console.log(`\u2713 Deleted scheduled message ${t.id}`)}async function vd(e,t){let n=jt(e,t.cookie),{statSync:r,existsSync:s}=await import("fs"),{basename:i}=await import("path");for(let m of t.filePaths)if(!s(m))console.error(`Error: file not found: ${m}`),process.exit(1);let{ref:o,threadTs:a}=Sn(t.target),c;if(t.channelId)c=t.channelId;else if(t.userId)c=await Mt(e,t.userId,t.cookie);else c=await De(e,o,t.cookie);if(await ti(e,c,(await n())?.userId,t.cookie))console.error(`Warning: "${t.target}" is a DM to yourself \u2014 Slack will NOT notify you of your own upload.`);let u=t.filePaths.length>1,f=t.filePaths.map((m)=>{let g=i(m),y=u?g:t.title??g;return{fp:m,filename:g,title:y,sizeFmt:Fs(r(m).size)}}),l=await n(),d=Ye(c,...f.flatMap((m)=>[m.fp,m.title]),l?.userId??"");if(t.code!==d){let m=` To: ${o}${a?` (thread ${a})`:""}`,g=u?[`--- Uploading ${f.length} files ------------------------`,ve(l,{pad:7}),m,...f.map((y)=>` ${y.filename} (${y.sizeFmt})`),"--------------------------------\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"]:["--- Uploading file ---------------------------",ve(l,{pad:7}),m,` File: ${f[0].fp}`,` Title: ${f[0].title}`,` Size: ${f[0].sizeFmt}`,"--------------------------------\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"];Ne(t.code,d,g)}let p=f.length;for(let m=0;m<p;m++){let g=f[m],y={title:g.title};if(a!==void 0)y.threadTs=a;if(t.comment!==void 0&&m===0)y.initialComment=t.comment;let{fileId:C,permalink:F}=await Ec(e,c,g.fp,y,t.cookie),k=p>1?`[${m+1}/${p}] `:"";console.log(`${k}\u2713 Uploaded (file_id: ${C}${F?`, url: ${F}`:""})`)}}async function jd(e,t,n){let r=n.channel?await De(e,n.channel,t):void 0,s=[],i=1,o=1;do{let c={page:i,count:200};if(n.types)c.types=n.types;if(r)c.channel=r;if(n.user)c.user=n.user;let u=T(await nc(e,c,t));for(let f of X(u.files))s.push(T(f));o=Number(T(u.paging).pages??1),i++}while(s.length<n.limit&&i<=o);let a=s.slice(0,n.limit);if(n.format==="jsonl"){for(let c of a)console.log(JSON.stringify({id:c.id??null,name:c.name??c.title??null,filetype:c.filetype??null,size:c.size??null,user:c.user??null,created:c.created??null,permalink:c.permalink??null}));return}for(let c of a){let u=String(c.id??""),f=typeof c.name==="string"?c.name:typeof c.title==="string"?c.title:u,l=typeof c.filetype==="string"?c.filetype:"?",d=typeof c.size==="number"?Fs(c.size):"";console.log(`${u} ${l.padEnd(7)} ${d.padStart(9)} ${f}`)}}function Ld(e){if(/^F[A-Z0-9]+$/i.test(e))return e;return e.match(/\/lists\/[A-Za-z0-9]+\/(F[A-Za-z0-9]+)/i)?.[1]??e.match(/\/lists\/(F[A-Za-z0-9]+)/i)?.[1]}function Wd(e){if(typeof e.text==="string"&&e.text)return e.text;let t=e.value;if(typeof t==="string"||typeof t==="number"||typeof t==="boolean")return String(t);if(Array.isArray(t))return t.map((n)=>typeof n==="string"?n:String(T(n).text??T(n).name??T(n).value??"")).filter(Boolean).join(", ");for(let n of["rich_text","select","user","date","number","checkbox","email","phone"]){let r=e[n];if(r!=null)return typeof r==="object"?JSON.stringify(r):String(r)}return""}async function Ud(e,t,n,r){let s=Ld(n);if(!s)throw Error(`Not a list ID or list URL: ${n}
204
- `+"Expected F\u2026 or https://<ws>.slack.com/lists/<TEAM>/<F-id>");let i=[],o;do{let c={limit:200};if(o)c.cursor=o;let u=T(await sc(e,s,c,t));for(let l of X(u.items??u.records))i.push(T(l));let f=T(u.response_metadata).next_cursor;o=typeof f==="string"&&f?f:void 0}while(o&&i.length<r.limit);let a=i.slice(0,r.limit);if(r.format==="jsonl"){for(let c of a)console.log(JSON.stringify(c));return}for(let c of a){let u=String(c.id??""),f=X(c.fields).map(T).map((l)=>{let d=String(l.key??l.column_id??"?"),p=Wd(l);return p?`${d}=${p}`:""}).filter(Boolean);console.log(`${u} ${f.join(" | ")}`)}}function Kd(e){if(/^F[A-Z0-9]+$/i.test(e))return e;return e.match(/\/files\/[A-Za-z0-9]+\/(F[A-Za-z0-9]+)/)?.[1]}async function Jd(e,t,n,r){let s=Kd(n);if(!s)throw Error(`Not a file ID or file permalink: ${n}
205
- `+"Expected F\u2026 or https://<ws>.slack.com/files/<UID>/<FID>/<name>");let i=T(await tc(e,s,t)),o=T(i.file),a=typeof o.name==="string"?o.name:typeof o.title==="string"?o.title:s,c=typeof o.url_private_download==="string"?o.url_private_download:typeof o.url_private==="string"?o.url_private:"";if(!c)throw Error(`files.info returned no download URL for ${s}`);let u={Authorization:`Bearer ${e}`};if(t)u.Cookie=`d=${t}`;let f=await fetch(c,{headers:u});if(!f.ok)throw Error(`Download failed: HTTP ${f.status} ${f.statusText}`);let l=Buffer.from(await f.arrayBuffer()),{statSync:d,existsSync:p}=await import("fs"),{basename:m}=await import("path"),g=r??a;if(r&&p(r)&&d(r).isDirectory())g=ft(r,m(a));Vc(g,l),console.log(`\u2713 Downloaded ${a} (${Fs(l.length)}) \u2192 ${g}`)}async function zd(){qf();let e=(s)=>cr(s.workspace),t=(s)=>Jo(s.workspace),n={state:{type:"string",choices:["open","untriaged","pending","doing","done","dropped","stuck"],default:"open",describe:"open (default) = marked and not done/dropped; untriaged = marked with no progress; stuck = unfinished with a reason flag"},in:{type:"string",describe:"Limit to a channel (#chan)"},from:{type:"string",describe:"Limit to a sender (@user, or 'me') \u2014 usually the person a task is waiting on"},n:{alias:"count",type:"number",default:50,describe:"Max results"},json:{type:"boolean",default:!1}},r=async(s,i)=>{let o={state:s.state??"open",mine:i||s.mine===!0,count:s.n??50,json:s.json===!0};if(s.in)o.in=s.in;if(s.from)o.from=s.from;let a=t(s);if(a)o.cookie=a;await rd(e(s),o)};await No(js(process.argv)).scriptName("slack").showHelpOnFail(!1).fail((s,i,o)=>{if(i)console.error(i.message),process.exit(1);console.error(s),console.error(""),o.showHelp(),process.exit(1)}).option("workspace",{alias:"w",type:"string",describe:"Workspace name"}).middleware(async(s)=>{let i=String((s._??[])[0]??"");if(!i||i==="auth"||i==="login")return;try{cr(s.workspace)}catch(o){if((o instanceof Error?o.message:String(o)).startsWith("No profiles configured"))console.log(`No workspace configured. Let's set that up:
206
- `),await ns(),process.exit(0);throw o}},!0).command(["read [target]","msgs [target]"],"Browse messages",(s)=>s.positional("target",{type:"string",describe:"#channel, @user, or URL"}).option("limit",{alias:"n",type:"number",default:20,describe:"Number of messages"}).option("format",{type:"string",choices:["text","jsonl"],default:"text",describe:"jsonl exposes raw ts/user/text (incl. external-guest user IDs)"}).option("json",{type:"boolean",default:!1,describe:"Alias for --format=jsonl"}).option("unreplied",{type:"boolean",default:!1,describe:"Only messages whose last word (incl. thread replies) is not yours \u2014 i.e. awaiting your answer"}),async(s)=>{let i=e(s),o=s.json?"jsonl":s.format;if(s.target)await Zf(i,s.target,s.limit,o,s.unreplied,t(s));else await ed(i)}).command("thread <target> <ts>","Show thread messages",(s)=>s.positional("target",{type:"string",demandOption:!0}).positional("ts",{type:"string",demandOption:!0}).option("limit",{alias:"n",type:"number",default:100}).option("format",{type:"string",choices:["text","jsonl"],default:"text",describe:"jsonl exposes raw ts/user/text (incl. external-guest user IDs)"}).option("json",{type:"boolean",default:!1,describe:"Alias for --format=jsonl"}),async(s)=>{let i=s.json?"jsonl":s.format;await Qf(e(s),s.target,s.ts,s.limit,i,t(s))}).command(["channel","channels","ch"],"Channel commands",(s)=>s.command(["ls","list"],"List channels",(i)=>i.option("limit",{alias:"n",type:"number",default:200}).option("filter",{alias:"f",type:"string"}).option("all",{type:"boolean",default:!1}).option("format",{type:"string",choices:["text","jsonl"],default:"text"}).option("json",{type:"boolean",default:!1,describe:"Alias for --format=jsonl"}),async(i)=>{await nd(e(i),i.limit,i.filter,i.all,i.json?"jsonl":i.format)}).command("get <channel>","Show channel details",(i)=>i.positional("channel",{type:"string",demandOption:!0,describe:"#name or channel ID"}),async(i)=>{let o=e(i),a=t(i),c=i.channel,u=c.startsWith("#")||c.startsWith("@")||c.startsWith("C")||c.startsWith("G")||c.startsWith("D")?c:`#${c}`,f=await De(o,u,a),l=T(await Fn(o,f,a)),d=T(l.channel),p=typeof d.name==="string"?d.name:f,g=d.is_im===!0?"@":"#",y=String(T(d.purpose).value??""),C=String(T(d.topic).value??""),F=d.num_members??d.member_count??"";if(console.log(`${g}${p} ${f}`),C)console.log(`topic: ${C}`);if(y)console.log(`purpose: ${y}`);if(F)console.log(`members: ${F}`);console.log(`private: ${d.is_private===!0}`)}).command(["create <name>","new <name>"],"Create a channel (confirm-hash safety gate)",(i)=>i.positional("name",{type:"string",demandOption:!0,describe:"Channel name (Slack lowercases it; no spaces)"}).option("private",{type:"boolean",default:!1,describe:"Create a private channel"}).option("invite",{type:"string",array:!0,default:[],describe:"Users to invite after creating (@handle or Uxxxx, repeatable)"}).option("code",{type:"string",describe:"Safety hash to confirm create"}),async(i)=>{let o=e(i),a=t(i),c=i.name.replace(/^#/,"").toLowerCase(),u=i.private===!0,f=i.invite.filter(Boolean),l=await en(o,a),d=Ye(c,String(u),f.join(","),l?.userId??"");if(i.code!==d)Ne(i.code,d,["--- Creating channel -------------------------",ve(l,{pad:9}),` name: ${u?"\uD83D\uDD12 ":"#"}${c}`,` private: ${u}`,...f.length?[` invite: ${f.join(", ")}`]:[],"--------------------------------\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"]);let p;try{p=await fc(o,c,u,a)}catch(m){console.error(m instanceof Error?m.message:String(m)),process.exit(1)}if(console.log(`\u2713 Created ${u?"\uD83D\uDD12 ":"#"}${p.name} (${p.id})`),f.length){let m=[];for(let g of f)try{m.push(g.startsWith("U")||g.startsWith("W")?g:await Vt(o,g,a))}catch(y){console.error(` ! could not resolve ${g}: ${y instanceof Error?y.message:String(y)}`)}for(let g of m)try{let y=T(await bn(o,g,a)),C=T(y.user);if(C.is_ultra_restricted===!0)console.error(`\u26A0 ${g} is a single-channel guest \u2014 Slack restricts them to their one existing channel; this invite will likely report success but not actually add them.`);else if(C.is_restricted===!0)console.error(`\u26A0 ${g} is a multi-channel guest \u2014 double-check they were actually added (guest invites can silently no-op depending on workspace restrictions).`)}catch{}if(m.length)try{await dc(o,p.id,m,a),console.log(`\u2713 Invited ${m.length} member${m.length===1?"":"s"}`)}catch(g){console.error(` ! invite failed: ${g instanceof Error?g.message:String(g)}`)}}}).demandCommand(1,"").showHelpOnFail(!0)).command(["user","usr"],"User commands",(s)=>s.command(["ls","list"],"List workspace members",(i)=>i.option("limit",{alias:"n",type:"number",default:200}).option("filter",{alias:"f",type:"string"}).option("format",{type:"string",choices:["text","jsonl","yaml"],default:"text"}).option("json",{type:"boolean",default:!1,describe:"Alias for --format=jsonl"}).option("external",{type:"boolean",default:!1,describe:"Also include people reachable only through Slack Connect shared channels \u2014 they are in ANOTHER workspace, so users.list never returns them (costs one API call per shared channel)"}),async(i)=>{let o=i.json?"jsonl":i.format,a=e(i),c=t(i),u=await Dc(a,c),f=i.filter?.toLowerCase(),l=X(u.members).map(T);if(i.external){let g=new Set(l.map((k)=>String(k.id))),y=T(await Dn(a,c)),C=X(y.channels).map(T).filter((k)=>k.is_ext_shared===!0&&!!k.name),F=new Set;for(let k of C)try{for(let S of await yc(a,String(k.id),c))if(!g.has(S))F.add(S)}catch{}for(let k of F)try{let S=T(await bn(a,k,c)),L=T(S.user);if(L.id)l.push(L)}catch{}}let d=l.filter((g)=>g.deleted!==!0&&g.is_bot!==!0&&String(g.id)!=="USLACKBOT").filter((g)=>{if(!f)return!0;let y=String(g.name??"").toLowerCase(),C=String(T(g.profile).real_name??"").toLowerCase(),F=String(T(g.profile).email??"").toLowerCase();return y.includes(f)||C.includes(f)||F.includes(f)}).slice(0,i.limit);if(o==="jsonl"){for(let g of d)console.log(JSON.stringify(g));return}if(o==="yaml"){for(let g of d){let y=function(C,F=""){if(C===null)return"null";if(typeof C==="string")return C.includes(`
198
+ `+` (\u62BC\u3055\u308C\u305F\u30EA\u30A2\u30AF\u30B7\u30E7\u30F3\u306F\u6B8B\u3063\u3066\u3044\u307E\u3059: slack read '${te(t.link)}' \u3067\u78BA\u8A8D\u3067\u304D\u307E\u3059)`),process.exit(Ee);if(c.kind==="resolved"){console.error(`\u2713 \u56DE\u7B54\u6E08\u307F: ${te(c.question)}`),console.log(c.answer);return}let u=typeof o.user==="string"?o.user:"",f=typeof o.bot_id==="string"?o.bot_id:"",l=/<!(here|channel|everyone)(\^[^>]*)?(\|[^>]*)?>/.test(a),d=new Set;for(let m of a.matchAll(/<@([UW][A-Z0-9]+)>/g))if(m[1]!==u)d.add(m[1]);if(!d.size&&!l){let m=await Ss(e,r,t.cookie);if(m&&m!==u)d.add(m)}if(!d.size&&!l)console.error(`Error: \u3053\u306E\u8CEA\u554F\u306F\u8AB0\u306B\u3082\u5B9B\u3066\u3089\u308C\u3066\u3044\u306A\u3044\u305F\u3081\u3001\u6709\u52B9\u306A\u56DE\u7B54\u8005\u3092\u5224\u5B9A\u3067\u304D\u307E\u305B\u3093: ${te(t.link)}`),process.exit(Ee);if(t.timeout>0)console.error(` \u56DE\u7B54\u3092\u5F85\u3063\u3066\u3044\u307E\u3059 (\u6700\u5927 ${t.timeout}s)\u2026 Ctrl-C \u3067\u4E2D\u65AD`);let p={channelId:r,ts:s,question:c.question,reactable:c.reactable,threadOnly:c.threadOnly,audience:d,broadcast:l,askerUserId:u,askerBotId:f,timeout:t.timeout,shown:t.link,asBot:t.asBot};if(i)p.threadParentTs=i;if(t.cookie)p.cookie=t.cookie;await cu(e,p)}var Be=3;function Td(e){return`slack poll --results='${e}'`}async function Pd(e,t){let{ref:n,threadTs:r}=kn(t.target,!1),s=t.cookie,i=Wt(e,s),o;if(t.channelId)o=t.channelId;else if(t.userId)o=await ct(e,t.userId,s);else o=await De(e,n,s);let a=(await i())?.userId??"",c=await Ss(e,o,s);if(!t.asBot&&!!a&&c===a)console.error(`Warning: "${t.target}" is a DM to yourself \u2014 Slack will NOT notify you of your own message.
199
+ `+` To reach yourself with a notification, post as the bot: slack poll '${t.target}' '...' --as-bot`);let u=Fs(ft(t.question)),f=Fs(ft(t.body??"")),l=t.mentionToken??e,d=await Lt(l,u.text,o,t.mentionCookie),p=f.text?await Lt(l,f.text,o,t.mentionCookie):{text:"",resolved:[],unresolved:[]},m=d.text,g=p.text;for(let E of En([...d.unresolved,...p.unresolved]))console.error(`\u26A0 ${te(E)}`);let y=t.choices.map(ft),C=!!t.multi,F=t.until??"",S=Ha(m,g,y,{multi:C,deadline:F}),k="",L="?";try{let E=await Ze(e,o,1,void 0,void 0,s),O=X(E.messages).map(T).filter((N)=>N.subtype===void 0||N.subtype===null)[0];k=typeof O?.text==="string"?O.text:"",L=typeof O?.user==="string"?await qe(e,O.user,s):typeof O?.username==="string"?O.username:"?"}catch{}let A=await i(),R=await xs(e,o,s),B=Ye(o,r??"",k,S,A?.userId??"");if(t.code!==B){let E=await ks(e,o,n,s);Ne(t.code,B,["--- Last message in channel ------------------",` ${L}: ${k.split(`
200
+ `)[0]?.slice(0,100)??"(empty)"}`,"--- Ballot (seeded as reactions) -------------",...y.map((O,N)=>` ${Je[N].glyph} ${dn(O)}`),"--- Posting ----------------------------------",ve(A,{asBot:t.asBot}),` \u2192 ${E}${r?" \u2014 THREAD REPLY":" \u2014 NEW top-level message"}`,` Question: ${m}`,` Rule: ${C?"1 \u4EBA \u4F55\u7968\u3067\u3082 (--multi)":"1 \u4EBA 1 \u7968"}${F?` \u2014 \u7DE0\u5207 ${F}`:""}`," Note: \u3042\u306A\u305F\u81EA\u8EAB\u306E\u7968\u306F\u6570\u3048\u307E\u305B\u3093 (\u30D4\u30EB\u306F\u3042\u306A\u305F\u304C\u4ED8\u3051\u305F\u7A2E\u306A\u306E\u3067\u533A\u5225\u3067\u304D\u307E\u305B\u3093)","--------------------------------\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"],R)}let P=await ps(e,o,S,r,!1,s,!0);await Mr([pn,...y.map((E,O)=>Je[O].name)],(E)=>Vt(e,o,P,E,s),(E,O)=>{let N=O instanceof Error?O.message:String(O);if(E===pn)console.error(` (marker ${E} \u3092\u4ED8\u3051\u3089\u308C\u307E\u305B\u3093\u3067\u3057\u305F: ${N})`);else console.error(` (\u30EA\u30A2\u30AF\u30B7\u30E7\u30F3 ${E} \u3092\u4ED8\u3051\u3089\u308C\u307E\u305B\u3093\u3067\u3057\u305F: ${N})`)});let q="";try{q=await gn(e,o,P,s)}catch{}let _=q||`${o}:${P}`;console.error(`\u2713 Posted: ${_}`),console.log(Td(_)),console.error(` \u7DE0\u3081\u5207\u308B: slack poll --close='${_}'${t.asBot?" --as-bot":""}`)}async function Rd(e,t,n){let r=vt(t),s,i,o;if(r?.ts)s=r.channel,i=r.ts,o=r.threadTs&&r.threadTs!==r.ts?r.threadTs:void 0;else{let c=t.match(/^([A-Za-z0-9]+):(\d{10}\.\d{6})$/);if(!c)console.error(`Error: --results/--close needs the permalink of a poll (or 'C\u2026:1700000000.000100').
201
+ `+` Got: ${te(t)}`),process.exit(Be);s=c[1],i=c[2]}let a;if(o){let c=T(await He(e,s,o,100,n));a=X(c.messages).map(T).find((u)=>u.ts===i)}else{let c=T(await Ze(e,s,1,i,void 0,n,!0));a=X(c.messages).map(T).find((u)=>u.ts===i)}if(!a)console.error(`Error: \u305D\u306E\u30E1\u30C3\u30BB\u30FC\u30B8\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093: ${te(t)}`),process.exit(Be);return{channelId:s,ts:i,msg:a}}function Gc(e){let t=Math.max(1,...e.map((n)=>n.count));return e.map((n,r)=>`${Je[r].glyph} ${String(n.count).padStart(3)} ${"\u2588".repeat(Math.round(n.count/t*20))}${n.count?" ":""}${n.choice}`)}async function Md(e,t){let{channelId:n,ts:r,msg:s}=await Rd(e,t.link,t.cookie),i=typeof s.text==="string"?s.text:"",o=Ya(i);if(o.kind==="other")console.error("Error: \u3053\u308C\u306F `slack poll` \u306E\u6295\u7968\u3067\u306F\u3042\u308A\u307E\u305B\u3093 (\u7968\u306E\u6570\u3048\u65B9\u304C\u5206\u304B\u308A\u307E\u305B\u3093)\u3002\n"+` ${te(t.link)}`),process.exit(Be);if(o.kind==="closed"){console.error(`\u2713 \u6295\u7968\u7D42\u4E86: ${te(o.question)}`);for(let p of Gc(o.tallies))console.log(p);return}let a=new Set;if(typeof s.user==="string"&&s.user)a.add(s.user);let c=await fc(e,n,r,t.cookie),u=Xa(o.choices,c,a,o.multi);console.error(`${te(o.question)}${o.deadline?` (\u7DE0\u5207 ${o.deadline})`:""}`);for(let p of Gc(u.tallies))console.log(p);let f=u.tallies.reduce((p,m)=>p+m.count,0);if(console.error(` \u8A08 ${f} \u7968${o.multi?" (\u8907\u6570\u9078\u629E\u53EF)":""}`),t.names)for(let p=0;p<u.voters.length;p++){if(!u.voters[p].length)continue;let m=await Promise.all(u.voters[p].map((g)=>qe(e,g,t.cookie)));console.error(` ${Je[p].glyph} ${m.map((g)=>`@${te(g)}`).join(", ")}`)}let l=o.multi?[]:u.ambiguous,d=Ar(i,l);if(d!==i&&!t.noNotify)try{await Gt(t.writeToken??e,n,r,d,t.writeToken?t.writeCookie:t.cookie,!0)}catch(p){console.error(` (\u6295\u7968\u6587\u306B\u6CE8\u610F\u66F8\u304D\u3092\u5165\u308C\u3089\u308C\u307E\u305B\u3093\u3067\u3057\u305F: ${p instanceof Error?p.message:String(p)})
202
+ `+" \u30E1\u30C3\u30BB\u30FC\u30B8\u3092\u66F8\u304D\u63DB\u3048\u3089\u308C\u308B\u306E\u306F\u6295\u7A3F\u8005\u3060\u3051\u3067\u3059 \u2014 bot \u304C\u6295\u7A3F\u3057\u305F\u6295\u7968\u306A\u3089 --as-bot \u3092\u4ED8\u3051\u3066\u304F\u3060\u3055\u3044\u3002")}if(u.ambiguous.length){let p=await Promise.all(u.ambiguous.map((m)=>qe(e,m,t.cookie)));console.error(`\u26A0 1 \u4EBA 1 \u7968\u306A\u306E\u306B\u8907\u6570\u62BC\u3057\u3066\u3044\u308B\u4EBA\u304C\u3044\u307E\u3059 (\u7121\u52B9\u7968): ${p.map((m)=>`@${te(m)}`).join(", ")}`)}if(!t.close)return;await Gt(t.writeToken??e,n,r,qa(o.question,u.tallies),t.writeToken?t.writeCookie:t.cookie,!0);try{await Vt(t.writeToken??e,n,r,Rr,t.writeToken?t.writeCookie:t.cookie),await mn(t.writeToken??e,n,r,pn,t.writeToken?t.writeCookie:t.cookie)}catch{}console.error(`\u2713 \u6295\u7968\u3092\u7DE0\u3081\u5207\u308A\u307E\u3057\u305F: ${te(t.link)}`)}async function Bd(e){let t=await Vn(e);for(let n of Zn(t,!1))console.log(n);if(!t.ok)process.exit(1)}function Gr(){let e=Ot();if(!e)console.error(`Error: --as-bot needs a bot token, but no xoxb- token was found.
203
+ Set SLACK_BOT_TOKEN=xoxb-... in ~/.config/slack-cli/.env (or your shell).`),process.exit(1);return e}async function Vc(e,t,n,r){let s=await ut(n,e,r);return ct(t,s)}function Nd(e){if(/^\d{10,}$/.test(e))return parseInt(e,10);let t=new Date(e.replace(" ","T"));if(isNaN(t.getTime()))throw Error(`Cannot parse time: ${e}`);return Math.floor(t.getTime()/1000)}function vd(e){let t=new Date(e*1000);return`${new Intl.DateTimeFormat("sv-SE",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1,timeZoneName:"short"}).format(t).replace(/\u2212/g,"-")} (local) / ${t.toISOString()} (Unix: ${e})`}async function jd(e,t){let n=Wt(e,t.cookie),{ref:r,threadTs:s}=kn(t.target),i;if(t.channelId)i=t.channelId;else if(t.userId)i=await ct(e,t.userId,t.cookie);else i=await De(e,r,t.cookie);let o=Nd(t.at),a=new Date(o*1000).toISOString(),c=await n();if(!t.asBot&&await ni(e,i,c?.userId,t.cookie))console.error(`Warning: "${t.target}" is a DM to yourself \u2014 Slack will NOT notify you when this fires.
204
+ `+` To be notified, schedule it as the bot: slack schedule send '${t.target}' '...' --at '${t.at}' --as-bot`);let u=Ye(i,t.message,String(o),c?.userId??""),f=t.targetOverride?` [${t.targetOverride} \u2192 ${i}]`:"";if(t.code!==u){let d=await xs(e,i,t.cookie);Ne(t.code,u,["--- Scheduling message -----------------------",ve(c,{asBot:t.asBot,pad:9}),` To: ${r}${s?` (thread ${s})`:""}${f}`,` At: ${vd(o)}`,` Message: ${t.message}`,"---------------------------------------------"],d,new Date(o*1000))}let l=await ac(e,i,t.message,o,s,t.cookie);if(console.log(`\u2713 Scheduled (id: ${l}, at: ${a})`),t.asBot){if(console.error(` Scheduled as the bot \u2014 the user token cannot see or cancel it. Use the same flag:
205
+ `+` slack schedule ls --as-bot
206
+ slack schedule rm '${t.target}' ${l} --as-bot`),i.startsWith("D"))try{let d=await Vn(e);if(!d.ok)for(let p of Zn(d,!0))console.error(p);else{let p=d.appId?`https://api.slack.com/apps/${d.appId}`:"https://api.slack.com/apps";console.error(`Note: if ${t.target} can't reply (app messaging may be off), enable Messages Tab: ${p} \u2192 App Home.`)}}catch{}}}async function Zc(e,t,n,r){let s;if(n)s=n;else if(t)s=await De(e,t,r);let o=(await cc(e,s,r)).scheduled_messages??[];if(o.length===0){console.log("(no scheduled messages)");return}for(let a of o){let c=new Date(a.post_at*1000).toISOString();console.log(`${a.id} ${c} [${a.channel_id}] ${a.text.split(`
207
+ `)[0]?.slice(0,80)??""}`)}}async function Qc(e,t){let n;if(t.channelId)n=t.channelId;else n=await De(e,t.target,t.cookie);let r=await en(e,t.cookie),s=Ye(n,t.id,r?.userId??"");if(t.code!==s)Ne(t.code,s,["--- Deleting scheduled message ---------------",ve(r,{asBot:t.asBot,pad:9}),` Channel: ${t.target}${t.targetOverride?` [${t.targetOverride} \u2192 ${n}]`:""}`,` ID: ${t.id}`,"---------------------------------------------"]);await uc(e,n,t.id,t.cookie),console.log(`\u2713 Deleted scheduled message ${t.id}`)}async function Ld(e,t){let n=Wt(e,t.cookie),{statSync:r,existsSync:s}=await import("fs"),{basename:i}=await import("path");for(let m of t.filePaths)if(!s(m))console.error(`Error: file not found: ${m}`),process.exit(1);let{ref:o,threadTs:a}=kn(t.target),c;if(t.channelId)c=t.channelId;else if(t.userId)c=await ct(e,t.userId,t.cookie);else c=await De(e,o,t.cookie);if(await ni(e,c,(await n())?.userId,t.cookie))console.error(`Warning: "${t.target}" is a DM to yourself \u2014 Slack will NOT notify you of your own upload.`);let u=t.filePaths.length>1,f=t.filePaths.map((m)=>{let g=i(m),y=u?g:t.title??g;return{fp:m,filename:g,title:y,sizeFmt:Es(r(m).size)}}),l=await n(),d=Ye(c,...f.flatMap((m)=>[m.fp,m.title]),l?.userId??"");if(t.code!==d){let m=` To: ${o}${a?` (thread ${a})`:""}`,g=u?[`--- Uploading ${f.length} files ------------------------`,ve(l,{pad:7}),m,...f.map((y)=>` ${y.filename} (${y.sizeFmt})`),"--------------------------------\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"]:["--- Uploading file ---------------------------",ve(l,{pad:7}),m,` File: ${f[0].fp}`,` Title: ${f[0].title}`,` Size: ${f[0].sizeFmt}`,"--------------------------------\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"];Ne(t.code,d,g)}let p=f.length;for(let m=0;m<p;m++){let g=f[m],y={title:g.title};if(a!==void 0)y.threadTs=a;if(t.comment!==void 0&&m===0)y.initialComment=t.comment;let{fileId:C,permalink:F}=await xc(e,c,g.fp,y,t.cookie),S=p>1?`[${m+1}/${p}] `:"";console.log(`${S}\u2713 Uploaded (file_id: ${C}${F?`, url: ${F}`:""})`)}}async function Wd(e,t,n){let r=n.channel?await De(e,n.channel,t):void 0,s=[],i=1,o=1;do{let c={page:i,count:200};if(n.types)c.types=n.types;if(r)c.channel=r;if(n.user)c.user=n.user;let u=T(await sc(e,c,t));for(let f of X(u.files))s.push(T(f));o=Number(T(u.paging).pages??1),i++}while(s.length<n.limit&&i<=o);let a=s.slice(0,n.limit);if(n.format==="jsonl"){for(let c of a)console.log(JSON.stringify({id:c.id??null,name:c.name??c.title??null,filetype:c.filetype??null,size:c.size??null,user:c.user??null,created:c.created??null,permalink:c.permalink??null}));return}for(let c of a){let u=String(c.id??""),f=typeof c.name==="string"?c.name:typeof c.title==="string"?c.title:u,l=typeof c.filetype==="string"?c.filetype:"?",d=typeof c.size==="number"?Es(c.size):"";console.log(`${u} ${l.padEnd(7)} ${d.padStart(9)} ${f}`)}}function Ud(e){if(/^F[A-Z0-9]+$/i.test(e))return e;return e.match(/\/lists\/[A-Za-z0-9]+\/(F[A-Za-z0-9]+)/i)?.[1]??e.match(/\/lists\/(F[A-Za-z0-9]+)/i)?.[1]}function Kd(e){if(typeof e.text==="string"&&e.text)return e.text;let t=e.value;if(typeof t==="string"||typeof t==="number"||typeof t==="boolean")return String(t);if(Array.isArray(t))return t.map((n)=>typeof n==="string"?n:String(T(n).text??T(n).name??T(n).value??"")).filter(Boolean).join(", ");for(let n of["rich_text","select","user","date","number","checkbox","email","phone"]){let r=e[n];if(r!=null)return typeof r==="object"?JSON.stringify(r):String(r)}return""}async function Jd(e,t,n,r){let s=Ud(n);if(!s)throw Error(`Not a list ID or list URL: ${n}
208
+ `+"Expected F\u2026 or https://<ws>.slack.com/lists/<TEAM>/<F-id>");let i=[],o;do{let c={limit:200};if(o)c.cursor=o;let u=T(await rc(e,s,c,t));for(let l of X(u.items??u.records))i.push(T(l));let f=T(u.response_metadata).next_cursor;o=typeof f==="string"&&f?f:void 0}while(o&&i.length<r.limit);let a=i.slice(0,r.limit);if(r.format==="jsonl"){for(let c of a)console.log(JSON.stringify(c));return}for(let c of a){let u=String(c.id??""),f=X(c.fields).map(T).map((l)=>{let d=String(l.key??l.column_id??"?"),p=Kd(l);return p?`${d}=${p}`:""}).filter(Boolean);console.log(`${u} ${f.join(" | ")}`)}}function zd(e){if(/^F[A-Z0-9]+$/i.test(e))return e;return e.match(/\/files\/[A-Za-z0-9]+\/(F[A-Za-z0-9]+)/)?.[1]}async function Hd(e,t,n,r){let s=zd(n);if(!s)throw Error(`Not a file ID or file permalink: ${n}
209
+ `+"Expected F\u2026 or https://<ws>.slack.com/files/<UID>/<FID>/<name>");let i=T(await nc(e,s,t)),o=T(i.file),a=typeof o.name==="string"?o.name:typeof o.title==="string"?o.title:s,c=typeof o.url_private_download==="string"?o.url_private_download:typeof o.url_private==="string"?o.url_private:"";if(!c)throw Error(`files.info returned no download URL for ${s}`);let u={Authorization:`Bearer ${e}`};if(t)u.Cookie=`d=${t}`;let f=await fetch(c,{headers:u});if(!f.ok)throw Error(`Download failed: HTTP ${f.status} ${f.statusText}`);let l=Buffer.from(await f.arrayBuffer()),{statSync:d,existsSync:p}=await import("fs"),{basename:m}=await import("path"),g=r??a;if(r&&p(r)&&d(r).isDirectory())g=pt(r,m(a));tu(g,l),console.log(`\u2713 Downloaded ${a} (${Es(l.length)}) \u2192 ${g}`)}async function qd(){Vf();let e=(s)=>fr(s.workspace),t=(s)=>zo(s.workspace),n={state:{type:"string",choices:["open","untriaged","pending","doing","done","dropped","stuck"],default:"open",describe:"open (default) = marked and not done/dropped; untriaged = marked with no progress; stuck = unfinished with a reason flag"},in:{type:"string",describe:"Limit to a channel (#chan)"},from:{type:"string",describe:"Limit to a sender (@user, or 'me') \u2014 usually the person a task is waiting on"},n:{alias:"count",type:"number",default:50,describe:"Max results"},json:{type:"boolean",default:!1}},r=async(s,i)=>{let o={state:s.state??"open",mine:i||s.mine===!0,count:s.n??50,json:s.json===!0};if(s.in)o.in=s.in;if(s.from)o.from=s.from;let a=t(s);if(a)o.cookie=a;await cd(e(s),o)};await vo(Us(process.argv)).scriptName("slack").showHelpOnFail(!1).fail((s,i,o)=>{if(i)console.error(i.message),process.exit(1);console.error(s),console.error(""),o.showHelp(),process.exit(1)}).option("workspace",{alias:"w",type:"string",describe:"Workspace name"}).middleware(async(s)=>{let i=String((s._??[])[0]??"");if(!i||i==="auth"||i==="login")return;try{fr(s.workspace)}catch(o){if((o instanceof Error?o.message:String(o)).startsWith("No profiles configured"))console.log(`No workspace configured. Let's set that up:
210
+ `),await rs(),process.exit(0);throw o}},!0).command(["read [target]","msgs [target]"],"Browse messages",(s)=>s.positional("target",{type:"string",describe:"#channel, @user, or URL"}).option("limit",{alias:"n",type:"number",default:20,describe:"Number of messages"}).option("format",{type:"string",choices:["text","jsonl"],default:"text",describe:"jsonl exposes raw ts/user/text (incl. external-guest user IDs)"}).option("json",{type:"boolean",default:!1,describe:"Alias for --format=jsonl"}).option("unreplied",{type:"boolean",default:!1,describe:"Only messages whose last word (incl. thread replies) is not yours \u2014 i.e. awaiting your answer"}),async(s)=>{let i=e(s),o=s.json?"jsonl":s.format;if(s.target)await nd(i,s.target,s.limit,o,s.unreplied,t(s));else await rd(i)}).command("thread <target> <ts>","Show thread messages",(s)=>s.positional("target",{type:"string",demandOption:!0}).positional("ts",{type:"string",demandOption:!0}).option("limit",{alias:"n",type:"number",default:100}).option("format",{type:"string",choices:["text","jsonl"],default:"text",describe:"jsonl exposes raw ts/user/text (incl. external-guest user IDs)"}).option("json",{type:"boolean",default:!1,describe:"Alias for --format=jsonl"}),async(s)=>{let i=s.json?"jsonl":s.format;await sd(e(s),s.target,s.ts,s.limit,i,t(s))}).command(["channel","channels","ch"],"Channel commands",(s)=>s.command(["ls","list"],"List channels",(i)=>i.option("limit",{alias:"n",type:"number",default:200}).option("filter",{alias:"f",type:"string"}).option("all",{type:"boolean",default:!1}).option("format",{type:"string",choices:["text","jsonl"],default:"text"}).option("json",{type:"boolean",default:!1,describe:"Alias for --format=jsonl"}),async(i)=>{await od(e(i),i.limit,i.filter,i.all,i.json?"jsonl":i.format)}).command("get <channel>","Show channel details",(i)=>i.positional("channel",{type:"string",demandOption:!0,describe:"#name or channel ID"}),async(i)=>{let o=e(i),a=t(i),c=i.channel,u=c.startsWith("#")||c.startsWith("@")||c.startsWith("C")||c.startsWith("G")||c.startsWith("D")?c:`#${c}`,f=await De(o,u,a),l=T(await Fn(o,f,a)),d=T(l.channel),p=typeof d.name==="string"?d.name:f,g=d.is_im===!0?"@":"#",y=String(T(d.purpose).value??""),C=String(T(d.topic).value??""),F=d.num_members??d.member_count??"";if(console.log(`${g}${p} ${f}`),C)console.log(`topic: ${C}`);if(y)console.log(`purpose: ${y}`);if(F)console.log(`members: ${F}`);console.log(`private: ${d.is_private===!0}`)}).command(["create <name>","new <name>"],"Create a channel (confirm-hash safety gate)",(i)=>i.positional("name",{type:"string",demandOption:!0,describe:"Channel name (Slack lowercases it; no spaces)"}).option("private",{type:"boolean",default:!1,describe:"Create a private channel"}).option("invite",{type:"string",array:!0,default:[],describe:"Users to invite after creating (@handle or Uxxxx, repeatable)"}).option("code",{type:"string",describe:"Safety hash to confirm create"}),async(i)=>{let o=e(i),a=t(i),c=i.name.replace(/^#/,"").toLowerCase(),u=i.private===!0,f=i.invite.filter(Boolean),l=await en(o,a),d=Ye(c,String(u),f.join(","),l?.userId??"");if(i.code!==d)Ne(i.code,d,["--- Creating channel -------------------------",ve(l,{pad:9}),` name: ${u?"\uD83D\uDD12 ":"#"}${c}`,` private: ${u}`,...f.length?[` invite: ${f.join(", ")}`]:[],"--------------------------------\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"]);let p;try{p=await dc(o,c,u,a)}catch(m){console.error(m instanceof Error?m.message:String(m)),process.exit(1)}if(console.log(`\u2713 Created ${u?"\uD83D\uDD12 ":"#"}${p.name} (${p.id})`),f.length){let m=[];for(let g of f)try{m.push(g.startsWith("U")||g.startsWith("W")?g:await ut(o,g,a))}catch(y){console.error(` ! could not resolve ${g}: ${y instanceof Error?y.message:String(y)}`)}for(let g of m)try{let y=T(await bn(o,g,a)),C=T(y.user);if(C.is_ultra_restricted===!0)console.error(`\u26A0 ${g} is a single-channel guest \u2014 Slack restricts them to their one existing channel; this invite will likely report success but not actually add them.`);else if(C.is_restricted===!0)console.error(`\u26A0 ${g} is a multi-channel guest \u2014 double-check they were actually added (guest invites can silently no-op depending on workspace restrictions).`)}catch{}if(m.length)try{await pc(o,p.id,m,a),console.log(`\u2713 Invited ${m.length} member${m.length===1?"":"s"}`)}catch(g){console.error(` ! invite failed: ${g instanceof Error?g.message:String(g)}`)}}}).demandCommand(1,"").showHelpOnFail(!0)).command(["user","usr"],"User commands",(s)=>s.command(["ls","list"],"List workspace members",(i)=>i.option("limit",{alias:"n",type:"number",default:200}).option("filter",{alias:"f",type:"string"}).option("format",{type:"string",choices:["text","jsonl","yaml"],default:"text"}).option("json",{type:"boolean",default:!1,describe:"Alias for --format=jsonl"}).option("external",{type:"boolean",default:!1,describe:"Also include people reachable only through Slack Connect shared channels \u2014 they are in ANOTHER workspace, so users.list never returns them (costs one API call per shared channel)"}),async(i)=>{let o=i.json?"jsonl":i.format,a=e(i),c=t(i),u=await yc(a,c),f=i.filter?.toLowerCase(),l=X(u.members).map(T);if(i.external){let g=new Set(l.map((S)=>String(S.id))),y=T(await Dn(a,c)),C=X(y.channels).map(T).filter((S)=>S.is_ext_shared===!0&&!!S.name),F=new Set;for(let S of C)try{for(let k of await wc(a,String(S.id),c))if(!g.has(k))F.add(k)}catch{}for(let S of F)try{let k=T(await bn(a,S,c)),L=T(k.user);if(L.id)l.push(L)}catch{}}let d=l.filter((g)=>g.deleted!==!0&&g.is_bot!==!0&&String(g.id)!=="USLACKBOT").filter((g)=>{if(!f)return!0;let y=String(g.name??"").toLowerCase(),C=String(T(g.profile).real_name??"").toLowerCase(),F=String(T(g.profile).email??"").toLowerCase();return y.includes(f)||C.includes(f)||F.includes(f)}).slice(0,i.limit);if(o==="jsonl"){for(let g of d)console.log(JSON.stringify(g));return}if(o==="yaml"){for(let g of d){let y=function(C,F=""){if(C===null)return"null";if(typeof C==="string")return C.includes(`
207
211
  `)?`|
208
212
  ${C.split(`
209
213
  `).join(`
210
- `)}`:C;if(typeof C!=="object")return String(C);if(Array.isArray(C))return C.map((k)=>`
211
- ${F} - ${y(k,F+" ")}`).join("");return Object.entries(C).map(([k,S])=>`
212
- ${F} ${k}: ${y(S,F+" ")}`).join("")};console.log("---");for(let[C,F]of Object.entries(g))console.log(`${C}: ${y(F)}`)}return}let p=Intl.DateTimeFormat().resolvedOptions().timeZone,m=d.length?String(T(X(u.members).map(T)[0]??{}).team_id??""):"";for(let g of d){let y=T(g.profile),C=String(g.name??g.id),F=String(g.id??""),k=String(y.display_name||""),S=String(y.real_name||""),L=String(y.email||""),A=String(g.tz??""),B=[...new Set([k,S].filter((O)=>O&&O!==C))].join(" / "),P=A&&A!==p?A:"",q=String(g.team_id??""),_=g.is_stranger===!0||m&&q&&q!==m?`external:${q||"?"}`:g.is_ultra_restricted===!0?"single-channel guest":g.is_restricted===!0?"guest":"",E=[L,P].filter(Boolean).join(" ");console.log(`@${C} ${F} ${B}${E?" "+E:""}${_?` [${_}]`:""}`)}}).command("get <user>","Show user details",(i)=>i.positional("user",{type:"string",demandOption:!0,describe:"@handle or user ID"}),async(i)=>{let o=e(i),a=t(i),c=i.user.startsWith("@")?i.user:`@${i.user}`,u="";try{u=await Vt(o,c,a)}catch(R){console.error(R instanceof Error?R.message:String(R)),process.exit(1)}let f=T(await bn(o,u,a)),l=T(f.user),d=T(l.profile),p=Intl.DateTimeFormat().resolvedOptions().timeZone,m=String(l.name??u),g=String(l.id??u),y=String(d.display_name||""),C=String(d.real_name||""),F=String(d.email||""),k=String(l.tz??""),S=String(d.phone||""),L=String(d.title||"");console.log(`@${m} ${g}`);let A=[...new Set([y,C].filter((R)=>R&&R!==m))];if(A.length)console.log(`name: ${A.join(" / ")}`);if(F)console.log(`email: ${F}`);if(S)console.log(`phone: ${S}`);if(L)console.log(`title: ${L}`);if(k&&k!==p)console.log(`tz: ${k}`)}).demandCommand(1,"").showHelpOnFail(!0)).command("news","Activity feed (mentions to you)",(s)=>s.option("limit",{alias:"l",type:"number",default:20}),async(s)=>{await td(e(s),s.limit)}).command("search <query>","Full-text search",(s)=>s.positional("query",{type:"string",demandOption:!0}).option("count",{alias:"n",type:"number",default:100}).option("json",{type:"boolean",default:!1,describe:"Output raw JSON"}),async(s)=>{await eu(e(s),s.query,s.count,s.json,t(s))}).command("send <target> <message>","Send a message (confirm-hash safety gate)",(s)=>s.positional("target",{type:"string",demandOption:!0,describe:"#chan, @user, #chan:thread_ts, or permalink (a message permalink replies in its thread)"}).positional("message",{type:"string",demandOption:!0}).option("code",{type:"string",describe:"Safety hash to confirm send"}).option("channel-id",{type:"string",describe:"Raw channel ID"}).option("user-id",{type:"string",describe:"Raw user ID (opens DM)"}).option("as-bot",{type:"boolean",default:!1,describe:"Send via the bot token (xoxb / SLACK_BOT_TOKEN) so a DM notifies the recipient and can be two-way"}).option("broadcast",{type:"boolean",default:!1,describe:`Also send to channel: broadcast a threaded reply back to the channel (Slack's "Also send to #channel" checkbox). Only effective with a thread target.`}).option("mentions",{type:"boolean",default:!0,describe:"Convert @handle tokens to real <@USERID> mentions (on by default; resolves via users.list, then channel members for Slack Connect guests). Unresolved handles stay as plain text. The confirm preview shows the converted message before sending. Disable with --no-mentions for literal @text."}),async(s)=>{let i={target:s.target,message:s.message};if(s.code)i.code=s.code;if(s["channel-id"])i.channelId=s["channel-id"];if(s["user-id"])i.userId=s["user-id"];if(s.broadcast)i.broadcast=!0;if(s.mentions!==!1){i.mentions=!0,i.mentionToken=e(s);let a=t(s);if(a)i.mentionCookie=a}let o;if(s["as-bot"]){let a=Ht();if(!a)console.error(`Error: --as-bot needs a bot token, but no xoxb- token was found.
213
- Set SLACK_BOT_TOKEN=xoxb-... in ~/.config/slack-cli/.env (or your shell).`),process.exit(1);if(!i.channelId&&!i.userId&&i.target.startsWith("@"))try{i.userId=await Vt(e(s),i.target,t(s))}catch(c){console.error(`Error: could not resolve ${i.target} to a user for the bot DM.
214
+ `)}`:C;if(typeof C!=="object")return String(C);if(Array.isArray(C))return C.map((S)=>`
215
+ ${F} - ${y(S,F+" ")}`).join("");return Object.entries(C).map(([S,k])=>`
216
+ ${F} ${S}: ${y(k,F+" ")}`).join("")};console.log("---");for(let[C,F]of Object.entries(g))console.log(`${C}: ${y(F)}`)}return}let p=Intl.DateTimeFormat().resolvedOptions().timeZone,m=d.length?String(T(X(u.members).map(T)[0]??{}).team_id??""):"";for(let g of d){let y=T(g.profile),C=String(g.name??g.id),F=String(g.id??""),S=String(y.display_name||""),k=String(y.real_name||""),L=String(y.email||""),A=String(g.tz??""),B=[...new Set([S,k].filter((O)=>O&&O!==C))].join(" / "),P=A&&A!==p?A:"",q=String(g.team_id??""),_=g.is_stranger===!0||m&&q&&q!==m?`external:${q||"?"}`:g.is_ultra_restricted===!0?"single-channel guest":g.is_restricted===!0?"guest":"",E=[L,P].filter(Boolean).join(" ");console.log(`@${C} ${F} ${B}${E?" "+E:""}${_?` [${_}]`:""}`)}}).command("get <user>","Show user details",(i)=>i.positional("user",{type:"string",demandOption:!0,describe:"@handle or user ID"}),async(i)=>{let o=e(i),a=t(i),c=i.user.startsWith("@")?i.user:`@${i.user}`,u="";try{u=await ut(o,c,a)}catch(R){console.error(R instanceof Error?R.message:String(R)),process.exit(1)}let f=T(await bn(o,u,a)),l=T(f.user),d=T(l.profile),p=Intl.DateTimeFormat().resolvedOptions().timeZone,m=String(l.name??u),g=String(l.id??u),y=String(d.display_name||""),C=String(d.real_name||""),F=String(d.email||""),S=String(l.tz??""),k=String(d.phone||""),L=String(d.title||"");console.log(`@${m} ${g}`);let A=[...new Set([y,C].filter((R)=>R&&R!==m))];if(A.length)console.log(`name: ${A.join(" / ")}`);if(F)console.log(`email: ${F}`);if(k)console.log(`phone: ${k}`);if(L)console.log(`title: ${L}`);if(S&&S!==p)console.log(`tz: ${S}`)}).demandCommand(1,"").showHelpOnFail(!0)).command("news","Activity feed (mentions to you)",(s)=>s.option("limit",{alias:"l",type:"number",default:20}),async(s)=>{await id(e(s),s.limit)}).command("search <query>","Full-text search",(s)=>s.positional("query",{type:"string",demandOption:!0}).option("count",{alias:"n",type:"number",default:100}).option("json",{type:"boolean",default:!1,describe:"Output raw JSON"}),async(s)=>{await ru(e(s),s.query,s.count,s.json,t(s))}).command("send <target> <message>","Send a message (confirm-hash safety gate)",(s)=>s.positional("target",{type:"string",demandOption:!0,describe:"#chan, @user, #chan:thread_ts, or permalink (a message permalink replies in its thread)"}).positional("message",{type:"string",demandOption:!0}).option("code",{type:"string",describe:"Safety hash to confirm send"}).option("channel-id",{type:"string",describe:"Raw channel ID"}).option("user-id",{type:"string",describe:"Raw user ID (opens DM)"}).option("as-bot",{type:"boolean",default:!1,describe:"Send via the bot token (xoxb / SLACK_BOT_TOKEN) so a DM notifies the recipient and can be two-way"}).option("broadcast",{type:"boolean",default:!1,describe:`Also send to channel: broadcast a threaded reply back to the channel (Slack's "Also send to #channel" checkbox). Only effective with a thread target.`}).option("mentions",{type:"boolean",default:!0,describe:"Convert @handle tokens to real <@USERID> mentions (on by default; resolves via users.list, then channel members for Slack Connect guests). Unresolved handles stay as plain text. The confirm preview shows the converted message before sending. Disable with --no-mentions for literal @text."}),async(s)=>{let i={target:s.target,message:s.message};if(s.code)i.code=s.code;if(s["channel-id"])i.channelId=s["channel-id"];if(s["user-id"])i.userId=s["user-id"];if(s.broadcast)i.broadcast=!0;if(s.mentions!==!1){i.mentions=!0,i.mentionToken=e(s);let a=t(s);if(a)i.mentionCookie=a}let o;if(s["as-bot"]){let a=Ot();if(!a)console.error(`Error: --as-bot needs a bot token, but no xoxb- token was found.
217
+ Set SLACK_BOT_TOKEN=xoxb-... in ~/.config/slack-cli/.env (or your shell).`),process.exit(1);if(!i.channelId&&!i.userId&&i.target.startsWith("@"))try{i.userId=await ut(e(s),i.target,t(s))}catch(c){console.error(`Error: could not resolve ${i.target} to a user for the bot DM.
214
218
  ${c instanceof Error?c.message:String(c)}
215
- Tip: pass --user-id <Uxxxx> to skip the lookup.`),process.exit(1)}o=a,i.asBot=!0}else{o=e(s);let a=t(s);if(a)i.cookie=a}try{await yd(o,i)}catch(a){console.error(tt(a)),process.exit(1)}}).command("ask [target] [question] [choices..]","Ask a question with its choices pre-seeded as 1\uFE0F\u20E3..\uD83D\uDD1F reactions (confirm-hash safety gate)",(s)=>s.positional("target",{type:"string",describe:"#chan, @user, #chan:thread_ts, or permalink (omit with --waitFor)"}).positional("question",{type:"string",describe:"The question. Must @tag whoever may answer (@alice), or the whole channel (@here / @channel / @everyone) \u2014 only their answer counts. In a 1:1 DM the other party counts automatically."}).positional("choices",{type:"string",array:!0,describe:"Up to 10 choices, seeded as 1\uFE0F\u20E3..\uD83D\uDD1F reactions. Beyond 10 they are listed but answerable only by text. With none, the question asks for a free-text reply."}).option("code",{type:"string",describe:"Safety hash to confirm the ask"}).option("body",{type:"string",describe:"Extra context shown under the question"}).option("wait",{type:"boolean",default:!1,describe:"Block until answered; print ONLY the answer on stdout. Exit 0 = answered, 2 = timed out, 3 = transport failure."}).option("waitFor",{type:"string",describe:"Collect the answer to a question already posted: pass its permalink. Nothing is posted. Same stdout/exit contract as --wait; --timeout 0 checks once and exits 2 if still open."}).option("timeout",{type:"number",default:3600,describe:"Overall limit for --wait / --waitFor, in seconds (0 with --waitFor = check once)"}).option("channel-id",{type:"string",describe:"Raw channel ID"}).option("user-id",{type:"string",describe:"Raw user ID (opens DM)"}).option("as-bot",{type:"boolean",default:!1,describe:"Ask via the bot token (xoxb / SLACK_BOT_TOKEN) so a DM notifies the recipient"}),async(s)=>{let i=s.waitFor?String(s.waitFor):"",o=Number(s.timeout);if(!Number.isFinite(o)||o<0||o===0&&!i)console.error("Error: --timeout must be a positive number of seconds"),process.exit(Ee);if(i){if(s.target||s.question||s.choices?.length)console.error("Error: --waitFor collects an existing question \u2014 do not also pass a target/question/choices."),process.exit(Ee);let l,d;if(s["as-bot"]){let p=Ht();if(!p)console.error(`Error: --as-bot needs a bot token, but no xoxb- token was found.
216
- Set SLACK_BOT_TOKEN=xoxb-... in ~/.config/slack-cli/.env (or your shell).`),process.exit(Ee);l=p}else l=e(s),d=t(s);try{let p={link:i,timeout:o,asBot:!!s["as-bot"]};if(d)p.cookie=d;await kd(l,p)}catch(p){console.error(tt(p)),process.exit(Ee)}return}if(!s.target)console.error("Error: target is required (or use --waitFor <permalink> to collect an answer)"),process.exit(Ee);let a=String(s.question??"").trim();if(!a)console.error("Error: question is empty"),process.exit(Ee);let c={target:s.target,question:a,choices:(s.choices??[]).map((l)=>String(l).trim()).filter(Boolean),timeout:o};if(s.code)c.code=s.code;if(s.body)c.body=s.body;if(s.wait)c.wait=!0;if(s["channel-id"])c.channelId=s["channel-id"];if(s["user-id"])c.userId=s["user-id"];c.mentionToken=e(s);let u=t(s);if(u)c.mentionCookie=u;let f;if(s["as-bot"]){let l=Ht();if(!l)console.error(`Error: --as-bot needs a bot token, but no xoxb- token was found.
217
- Set SLACK_BOT_TOKEN=xoxb-... in ~/.config/slack-cli/.env (or your shell).`),process.exit(Ee);if(!c.channelId&&!c.userId&&c.target.startsWith("@"))try{c.userId=await Vt(e(s),c.target,t(s))}catch(d){console.error(`Error: could not resolve ${c.target} to a user for the bot DM.
219
+ Tip: pass --user-id <Uxxxx> to skip the lookup.`),process.exit(1)}o=a,i.asBot=!0}else{o=e(s);let a=t(s);if(a)i.cookie=a}try{await Cd(o,i)}catch(a){console.error(tt(a)),process.exit(1)}}).command("ask [target] [question] [choices..]","Ask a question with its choices pre-seeded as 1\uFE0F\u20E3..\uD83D\uDD1F reactions (confirm-hash safety gate)",(s)=>s.positional("target",{type:"string",describe:"#chan, @user, #chan:thread_ts, or permalink (omit with --waitFor)"}).positional("question",{type:"string",describe:"The question. Must @tag whoever may answer (@alice), or the whole channel (@here / @channel / @everyone) \u2014 only their answer counts. In a 1:1 DM the other party counts automatically."}).positional("choices",{type:"string",array:!0,describe:"Up to 10 choices, seeded as 1\uFE0F\u20E3..\uD83D\uDD1F reactions. Beyond 10 they are listed but answerable only by text. With none, the question asks for a free-text reply."}).option("code",{type:"string",describe:"Safety hash to confirm the ask"}).option("body",{type:"string",describe:"Extra context shown under the question"}).option("wait",{type:"boolean",default:!1,describe:"Block until answered; print ONLY the answer on stdout. Exit 0 = answered, 2 = timed out, 3 = transport failure."}).option("waitFor",{type:"string",describe:"Collect the answer to a question already posted: pass its permalink. Nothing is posted. Same stdout/exit contract as --wait; --timeout 0 checks once and exits 2 if still open."}).option("timeout",{type:"number",default:3600,describe:"Overall limit for --wait / --waitFor, in seconds (0 with --waitFor = check once)"}).option("channel-id",{type:"string",describe:"Raw channel ID"}).option("user-id",{type:"string",describe:"Raw user ID (opens DM)"}).option("as-bot",{type:"boolean",default:!1,describe:"Ask via the bot token (xoxb / SLACK_BOT_TOKEN) so a DM notifies the recipient"}),async(s)=>{let i=s.waitFor?String(s.waitFor):"",o=Number(s.timeout);if(!Number.isFinite(o)||o<0||o===0&&!i)console.error("Error: --timeout must be a positive number of seconds"),process.exit(Ee);if(i){if(s.target||s.question||s.choices?.length)console.error("Error: --waitFor collects an existing question \u2014 do not also pass a target/question/choices."),process.exit(Ee);let l,d;if(s["as-bot"]){let p=Ot();if(!p)console.error(`Error: --as-bot needs a bot token, but no xoxb- token was found.
220
+ Set SLACK_BOT_TOKEN=xoxb-... in ~/.config/slack-cli/.env (or your shell).`),process.exit(Ee);l=p}else l=e(s),d=t(s);try{let p={link:i,timeout:o,asBot:!!s["as-bot"]};if(d)p.cookie=d;await Id(l,p)}catch(p){console.error(tt(p)),process.exit(Ee)}return}if(!s.target)console.error("Error: target is required (or use --waitFor <permalink> to collect an answer)"),process.exit(Ee);let a=String(s.question??"").trim();if(!a)console.error("Error: question is empty"),process.exit(Ee);let c={target:s.target,question:a,choices:(s.choices??[]).map((l)=>String(l).trim()).filter(Boolean),timeout:o};if(s.code)c.code=s.code;if(s.body)c.body=s.body;if(s.wait)c.wait=!0;if(s["channel-id"])c.channelId=s["channel-id"];if(s["user-id"])c.userId=s["user-id"];c.mentionToken=e(s);let u=t(s);if(u)c.mentionCookie=u;let f;if(s["as-bot"]){let l=Ot();if(!l)console.error(`Error: --as-bot needs a bot token, but no xoxb- token was found.
221
+ Set SLACK_BOT_TOKEN=xoxb-... in ~/.config/slack-cli/.env (or your shell).`),process.exit(Ee);if(!c.channelId&&!c.userId&&c.target.startsWith("@"))try{c.userId=await ut(e(s),c.target,t(s))}catch(d){console.error(`Error: could not resolve ${c.target} to a user for the bot DM.
218
222
  ${d instanceof Error?d.message:String(d)}
219
- Tip: pass --user-id <Uxxxx> to skip the lookup.`),process.exit(Ee)}f=l,c.asBot=!0}else{f=e(s);let l=t(s);if(l)c.cookie=l}try{await Sd(f,c)}catch(l){console.error(tt(l)),process.exit(Ee)}}).command(["poll [target] [question] [choices..]","vote [target] [question] [choices..]"],"Post a poll with its choices pre-seeded as 1\uFE0F\u20E3..\uD83D\uDD1F reactions, then count them (confirm-hash safety gate)",(s)=>s.positional("target",{type:"string",describe:"#chan, @user, #chan:thread_ts, or permalink (omit with --results/--close)"}).positional("question",{type:"string",describe:"The question. @tags are optional here \u2014 unlike `ask`, a poll needs no addressee: anyone who can see it may vote."}).positional("choices",{type:"string",array:!0,describe:"2..10 choices, seeded as 1\uFE0F\u20E3..\uD83D\uDD1F reactions for voters to click"}).option("multi",{type:"boolean",default:!1,describe:"Let one person pick several choices (default: 1 \u4EBA 1 \u7968)"}).option("until",{type:"string",describe:"Deadline shown in the message (display only \u2014 closing is still `--close`)"}).option("results",{type:"string",describe:"Count an existing poll: pass its permalink. Posts nothing; only edit is the invalid-ballot notice in the poll itself (--no-notify to suppress)."}).option("close",{type:"string",describe:"Count an existing poll AND freeze the tally into the message. Only the poster can do this."}).option("names",{type:"boolean",default:!1,describe:"Also list who voted for what (stderr)"}).option("no-notify",{type:"boolean",default:!1,describe:"With --results: do not write the invalid-ballot notice back into the message (keeps it strictly read-only)"}).option("code",{type:"string",describe:"Safety hash to confirm the post"}).option("body",{type:"string",describe:"Extra context shown under the question"}).option("channel-id",{type:"string",describe:"Raw channel ID"}).option("user-id",{type:"string",describe:"Raw user ID (opens DM)"}).option("as-bot",{type:"boolean",default:!1,describe:"Post via the bot token (xoxb / SLACK_BOT_TOKEN) so a DM notifies the recipient \u2014 and so YOUR OWN vote counts, since the seeds are then the bot's"}),async(s)=>{let i=s.close?String(s.close):s.results?String(s.results):"";if(s.results&&s.close)console.error("Error: pass --results or --close, not both (--close counts as well)."),process.exit(Be);let o=()=>{let d=Ht();if(!d)console.error(`Error: --as-bot needs a bot token, but no xoxb- token was found.
220
- Set SLACK_BOT_TOKEN=xoxb-... in ~/.config/slack-cli/.env (or your shell).`),process.exit(Be);return d};if(i){if(s.target||s.question||s.choices?.length)console.error("Error: --results/--close reads an existing poll \u2014 do not also pass a target/question/choices."),process.exit(Be);let d=e(s),p=t(s);try{let m={link:i};if(s.close)m.close=!0;if(s.names)m.names=!0;if(s["no-notify"])m.noNotify=!0;if(p)m.cookie=p;if(s["as-bot"])m.writeToken=o();await Id(d,m)}catch(m){console.error(tt(m)),process.exit(Be)}return}if(!s.target)console.error("Error: target is required (or use --results <permalink> to count a poll)"),process.exit(Be);let a=String(s.question??"").trim();if(!a)console.error("Error: question is empty"),process.exit(Be);let c=(s.choices??[]).map((d)=>String(d).trim()).filter(Boolean);if(c.length<2||c.length>Yt)console.error(`Error: poll needs 2..${Yt} choices (got ${c.length}). For a free-text question use \`slack ask\`.`),process.exit(Be);let u={target:s.target,question:a,choices:c};if(s.multi)u.multi=!0;if(s.until)u.until=String(s.until);if(s.code)u.code=s.code;if(s.body)u.body=s.body;if(s["channel-id"])u.channelId=s["channel-id"];if(s["user-id"])u.userId=s["user-id"];u.mentionToken=e(s);let f=t(s);if(f)u.mentionCookie=f;let l;if(s["as-bot"]){let d=o();if(!u.channelId&&!u.userId&&u.target.startsWith("@"))try{u.userId=await Vt(e(s),u.target,t(s))}catch(p){console.error(`Error: could not resolve ${u.target} to a user for the bot DM.
223
+ Tip: pass --user-id <Uxxxx> to skip the lookup.`),process.exit(Ee)}f=l,c.asBot=!0}else{f=e(s);let l=t(s);if(l)c.cookie=l}try{await Od(f,c)}catch(l){console.error(tt(l)),process.exit(Ee)}}).command(["poll [target] [question] [choices..]","vote [target] [question] [choices..]"],"Post a poll with its choices pre-seeded as 1\uFE0F\u20E3..\uD83D\uDD1F reactions, then count them (confirm-hash safety gate)",(s)=>s.positional("target",{type:"string",describe:"#chan, @user, #chan:thread_ts, or permalink (omit with --results/--close)"}).positional("question",{type:"string",describe:"The question. @tags are optional here \u2014 unlike `ask`, a poll needs no addressee: anyone who can see it may vote."}).positional("choices",{type:"string",array:!0,describe:"2..10 choices, seeded as 1\uFE0F\u20E3..\uD83D\uDD1F reactions for voters to click"}).option("multi",{type:"boolean",default:!1,describe:"Let one person pick several choices (default: 1 \u4EBA 1 \u7968)"}).option("until",{type:"string",describe:"Deadline shown in the message (display only \u2014 closing is still `--close`)"}).option("results",{type:"string",describe:"Count an existing poll: pass its permalink. Posts nothing; only edit is the invalid-ballot notice in the poll itself (--no-notify to suppress)."}).option("close",{type:"string",describe:"Count an existing poll AND freeze the tally into the message. Only the poster can do this."}).option("names",{type:"boolean",default:!1,describe:"Also list who voted for what (stderr)"}).option("no-notify",{type:"boolean",default:!1,describe:"With --results: do not write the invalid-ballot notice back into the message (keeps it strictly read-only)"}).option("code",{type:"string",describe:"Safety hash to confirm the post"}).option("body",{type:"string",describe:"Extra context shown under the question"}).option("channel-id",{type:"string",describe:"Raw channel ID"}).option("user-id",{type:"string",describe:"Raw user ID (opens DM)"}).option("as-bot",{type:"boolean",default:!1,describe:"Post via the bot token (xoxb / SLACK_BOT_TOKEN) so a DM notifies the recipient \u2014 and so YOUR OWN vote counts, since the seeds are then the bot's"}),async(s)=>{let i=s.close?String(s.close):s.results?String(s.results):"";if(s.results&&s.close)console.error("Error: pass --results or --close, not both (--close counts as well)."),process.exit(Be);let o=()=>{let d=Ot();if(!d)console.error(`Error: --as-bot needs a bot token, but no xoxb- token was found.
224
+ Set SLACK_BOT_TOKEN=xoxb-... in ~/.config/slack-cli/.env (or your shell).`),process.exit(Be);return d};if(i){if(s.target||s.question||s.choices?.length)console.error("Error: --results/--close reads an existing poll \u2014 do not also pass a target/question/choices."),process.exit(Be);let d=e(s),p=t(s);try{let m={link:i};if(s.close)m.close=!0;if(s.names)m.names=!0;if(s["no-notify"])m.noNotify=!0;if(p)m.cookie=p;if(s["as-bot"])m.writeToken=o();await Md(d,m)}catch(m){console.error(tt(m)),process.exit(Be)}return}if(!s.target)console.error("Error: target is required (or use --results <permalink> to count a poll)"),process.exit(Be);let a=String(s.question??"").trim();if(!a)console.error("Error: question is empty"),process.exit(Be);let c=(s.choices??[]).map((d)=>String(d).trim()).filter(Boolean);if(c.length<2||c.length>Xt)console.error(`Error: poll needs 2..${Xt} choices (got ${c.length}). For a free-text question use \`slack ask\`.`),process.exit(Be);let u={target:s.target,question:a,choices:c};if(s.multi)u.multi=!0;if(s.until)u.until=String(s.until);if(s.code)u.code=s.code;if(s.body)u.body=s.body;if(s["channel-id"])u.channelId=s["channel-id"];if(s["user-id"])u.userId=s["user-id"];u.mentionToken=e(s);let f=t(s);if(f)u.mentionCookie=f;let l;if(s["as-bot"]){let d=o();if(!u.channelId&&!u.userId&&u.target.startsWith("@"))try{u.userId=await ut(e(s),u.target,t(s))}catch(p){console.error(`Error: could not resolve ${u.target} to a user for the bot DM.
221
225
  ${p instanceof Error?p.message:String(p)}
222
- Tip: pass --user-id <Uxxxx> to skip the lookup.`),process.exit(Be)}l=d,u.asBot=!0}else{l=e(s);let d=t(s);if(d)u.cookie=d}try{await $d(l,u)}catch(d){console.error(tt(d)),process.exit(Be)}}).command("doctor","Check the bot token (xoxb) can carry a two-way DM (scopes + Messages Tab)",(s)=>s,async()=>{let s=Ht();if(!s)console.error(`Error: slack doctor checks the bot token, but no xoxb- token was found.
223
- Set SLACK_BOT_TOKEN=xoxb-... in ~/.config/slack-cli/.env (or your shell).`),process.exit(1);await Td(s)}).command("schedule","Manage scheduled messages",(s)=>s.command("send <target> <message>","Schedule a message for later delivery",(i)=>i.positional("target",{type:"string",demandOption:!0,describe:"#chan, @user, #chan:thread_ts, or permalink (a message permalink replies in its thread)"}).positional("message",{type:"string",demandOption:!0}).option("at",{type:"string",demandOption:!0,describe:"Delivery time (ISO datetime or Unix ts)"}).option("code",{type:"string",describe:"Safety hash to confirm"}).option("channel-id",{type:"string",describe:"Raw channel ID"}).option("user-id",{type:"string",describe:"Raw user ID (opens DM)"}),async(i)=>{let o={target:i.target,message:i.message,at:i.at};if(i.code)o.code=i.code;if(i["channel-id"])o.channelId=i["channel-id"];if(i["user-id"])o.userId=i["user-id"];let a=t(i);if(a)o.cookie=a;await Md(e(i),o)}).command(["ls","list"],"List pending scheduled messages",(i)=>i.positional("target",{type:"string",describe:"#channel to filter by"}).option("channel-id",{type:"string",describe:"Raw channel ID"}),async(i)=>{await Bd(e(i),i.target,i["channel-id"],t(i))}).command("rm <target> <id>","Delete a scheduled message",(i)=>i.positional("target",{type:"string",demandOption:!0,describe:"#channel or @user"}).positional("id",{type:"string",demandOption:!0,describe:"Scheduled message ID"}).option("code",{type:"string",describe:"Safety hash to confirm"}).option("channel-id",{type:"string",describe:"Raw channel ID"}),async(i)=>{let o={target:i.target,id:i.id};if(i.code)o.code=i.code;let a=t(i);if(a)o.cookie=a;if(i["channel-id"])o.channelId=i["channel-id"];await Nd(e(i),o)}).demandCommand(1,"").showHelpOnFail(!0),()=>{}).command("edit <target> <newText>","Edit a sent message",(s)=>s.positional("target",{type:"string",demandOption:!0,describe:"#chan:ts, @user:ts, or permalink"}).positional("newText",{type:"string",demandOption:!0}).option("code",{type:"string",describe:"Safety hash to confirm edit"}).option("channel-id",{type:"string",describe:"Raw channel ID"}).option("mentions",{type:"boolean",default:!0,describe:"Convert @handle tokens in the new text to real <@USERID> mentions (on by default). Unresolved handles stay as plain text. Disable with --no-mentions for literal @text."}),async(s)=>{let i={target:s.target,newText:s.newText};if(s.code)i.code=s.code;if(s["channel-id"])i.channelId=s["channel-id"];if(s.mentions!==!1)i.mentions=!0;let o=t(s);if(o)i.cookie=o;await gd(e(s),i)}).command("delete <target>","Delete a sent message (confirm-hash safety gate)",(s)=>s.positional("target",{type:"string",demandOption:!0,describe:"#chan:ts, @user:ts, or permalink"}).option("code",{type:"string",describe:"Safety hash to confirm delete"}).option("channel-id",{type:"string",describe:"Raw channel ID"}),async(s)=>{let i={target:s.target};if(s.code)i.code=s.code;if(s["channel-id"])i.channelId=s["channel-id"];let o=t(s);if(o)i.cookie=o;await md(e(s),i)}).command("react <target> <emoji>","Add (or --remove) an emoji reaction \u2014 a lightweight ack that doesn't grow the thread",(s)=>s.positional("target",{type:"string",demandOption:!0,describe:"#chan:ts, @user:ts, or permalink"}).positional("emoji",{type:"string",demandOption:!0,describe:"Emoji shortcode without colons (e.g. eyes, white_check_mark, hourglass)"}).option("remove",{type:"boolean",default:!1,describe:"Remove the reaction instead of adding it"}).option("channel-id",{type:"string",describe:"Raw channel ID"}),async(s)=>{let i={target:s.target,emoji:s.emoji};if(s.remove)i.remove=!0;if(s["channel-id"])i.channelId=s["channel-id"];let o=t(s);if(o)i.cookie=o;try{await Dd(e(s),i)}catch(a){console.error(tt(a)),process.exit(1)}}).command("todo","Reaction-backed task tracking (:pushpin: marks a task, progress lives in a second reaction)",(s)=>s.option("cache",{type:"boolean",default:!0,describe:"Use ~/.config/slack-cli/cache.json for channel/user lookups (--no-cache to bypass)"}).middleware((i)=>{if(i.cache===!1)zr(!1)}).command(["ls","list"],"List everyone's tasks (has: \u2014 read-only, one search per run)",(i)=>i.options(n).option("mine",{type:"boolean",default:!1,describe:"Only your own reactions (hasmy:) \u2014 same as `slack mytodo ls`"}).option("shared",{type:"boolean",default:!1,hidden:!0,describe:"Deprecated \u2014 anyone's reactions is the default for `todo ls`"}),async(i)=>{await r(i,!1)}).command("set <target> <state>","Move a task to a progress state (adds the new reaction before removing the old one)",(i)=>i.positional("target",{type:"string",demandOption:!0,describe:"#chan:ts or permalink"}).positional("state",{type:"string",demandOption:!0,choices:["pending","doing","done","dropped"]}).option("channel-id",{type:"string",describe:"Raw channel ID"}),async(i)=>{let o={target:i.target,state:i.state};if(i["channel-id"])o.channelId=i["channel-id"];let a=t(i);if(a)o.cookie=a;try{await id(e(i),o)}catch(c){console.error(tt(c)),process.exit(1)}}).command("flag <target> <flag>","Add (or --remove) a reason flag (alert | needs-discussion | waiting | blocked) \u2014 flags stack, independent of progress",(i)=>i.positional("target",{type:"string",demandOption:!0,describe:"#chan:ts or permalink"}).positional("flag",{type:"string",demandOption:!0,choices:["alert","needs-discussion","waiting","blocked"],describe:"waiting = the other party in this conversation owes a reply; blocked = stuck on something outside it"}).option("remove",{type:"boolean",default:!1,describe:"Remove the flag instead of adding it"}).option("channel-id",{type:"string",describe:"Raw channel ID"}),async(i)=>{let o={target:i.target,flag:i.flag};if(i.remove)o.remove=!0;if(i["channel-id"])o.channelId=i["channel-id"];let a=t(i);if(a)o.cookie=a;try{await od(e(i),o)}catch(c){console.error(tt(c)),process.exit(1)}}).command("doctor","Find messages carrying two or more progress reactions (--fix repairs them)",(i)=>i.option("in",{type:"string",demandOption:!0,describe:"Channel to scan (#chan)"}).option("fix",{type:"boolean",default:!1,describe:"Repair findings (keeps the highest-priority state)"}).option("limit",{type:"number",default:Jr,describe:"Max messages to scan"}).option("channel-id",{type:"string",describe:"Raw channel ID"}),async(i)=>{let o={channel:i.in,limit:i.limit};if(i.fix)o.fix=!0;if(i["channel-id"])o.channelId=i["channel-id"];let a=t(i);if(a)o.cookie=a;await ad(e(i),o)}).demandCommand(1,"Specify a todo subcommand (ls, set, flag, doctor)"),()=>{}).command("mytodo","Tasks carrying YOUR reactions (hasmy:) \u2014 the my-only half of `todo`",(s)=>s.option("cache",{type:"boolean",default:!0,describe:"Use ~/.config/slack-cli/cache.json for channel/user lookups (--no-cache to bypass)"}).middleware((i)=>{if(i.cache===!1)zr(!1)}).command(["ls","list"],"List tasks you have reacted to (hasmy: \u2014 read-only, one search per run)",(i)=>i.options(n),async(i)=>{await r(i,!0)}).demandCommand(1,"Specify a mytodo subcommand (ls)"),()=>{}).command("upload <target> <file..>","Upload one or more files to a channel or DM",(s)=>s.positional("target",{type:"string",demandOption:!0,describe:"#chan, @user, #chan:thread_ts, or permalink (a message permalink replies in its thread)"}).positional("file",{type:"string",array:!0,demandOption:!0,describe:"Path(s) to file(s)"}).option("title",{type:"string",describe:"Title (single file only)"}).option("comment",{type:"string",describe:"Initial comment (first file)"}).option("code",{type:"string",describe:"4-hex safety code to confirm upload"}).option("channel-id",{type:"string"}).option("user-id",{type:"string"}),async(s)=>{let i={target:s.target,filePaths:s.file};if(s.title)i.title=s.title;if(s.comment)i.comment=s.comment;if(s.code)i.code=s.code;if(s["channel-id"])i.channelId=s["channel-id"];if(s["user-id"])i.userId=s["user-id"];let o=t(s);if(o)i.cookie=o;await vd(e(s),i)}).command("files","File commands",(s)=>s.command(["ls","list"],"List files visible to you (files.list)",(i)=>i.option("limit",{alias:"l",type:"number",default:100,describe:"Max files to list"}).option("type",{alias:"t",type:"string",describe:"Slack type filter: images, pdfs, gdocs, snippets, zips, spaces, all"}).option("channel",{alias:"c",type:"string",describe:"Only files in this channel (#name, @user, ID, or permalink)"}).option("user",{alias:"u",type:"string",describe:"Only files from this raw user ID"}).option("format",{type:"string",choices:["text","jsonl"],default:"text"}).option("json",{type:"boolean",default:!1,describe:"Alias for --format=jsonl"}),async(i)=>{let o={limit:i.limit,format:i.json?"jsonl":i.format};if(i.type)o.types=i.type;if(i.channel)o.channel=i.channel;if(i.user)o.user=i.user;await jd(e(i),t(i),o)}).demandCommand(1,"").showHelpOnFail(!0),()=>{}).command("lists <ref>","Read a Slack List's rows (by list URL or F-id) \u2014 read-only",(s)=>s.positional("ref",{type:"string",demandOption:!0,describe:"List URL (\u2026/lists/<TEAM>/<F-id>) or bare F-id"}).option("limit",{alias:"l",type:"number",default:100,describe:"Max rows to show"}).option("format",{type:"string",choices:["text","jsonl"],default:"text"}).option("json",{type:"boolean",default:!1,describe:"Alias for --format=jsonl (raw records)"}),async(s)=>{let i=s.json?"jsonl":s.format;try{await Ud(e(s),t(s),s.ref,{limit:s.limit,format:i})}catch(o){console.error(tt(o)),process.exit(1)}}).command("download <ref> [dest]","Download a file attachment (by file ID or file permalink) to disk",(s)=>s.positional("ref",{type:"string",demandOption:!0,describe:"File ID (F\u2026) or Slack file permalink"}).positional("dest",{type:"string",describe:"Output path or directory (default: ./<filename>)"}),async(s)=>{await Jd(e(s),t(s),s.ref,s.dest)}).command("dump","Bulk export channel history as markdown",(s)=>s.option("days",{alias:"d",type:"number",default:7,describe:"Days of history"}).option("limit",{alias:"l",type:"number",default:200}).option("filter",{alias:"f",type:"string",describe:"Filter channel names"}),async(s)=>{await cd(e(s),s.days,s.limit,s.filter)}).command("drafts","Manage message drafts (requires xoxc desktop token)",(s)=>s.command(["$0","ls","list"],"List pending drafts",(i)=>i.option("all",{alias:"a",type:"boolean",default:!1,describe:"Include sent drafts"}),async(i)=>{await ld(e(i),t(i),i.all)}).command(["new <channel> [text..]","save <channel> [text..]"],"Create a draft",(i)=>i.positional("channel",{type:"string",demandOption:!0}).positional("text",{type:"string",array:!0,default:[]}),async(i)=>{let o=e(i),a=t(i),c=i.text.join(" ");if(!c)console.error("Usage: slack drafts new <#channel|@user> <text>"),process.exit(2);let u=await De(o,i.channel,a),f=await wc(o,u,c,a);console.log(`\u2713 Draft created (id: ${T(f.draft).id??"?"})`)}).command("get <id>","Show a draft",(i)=>i.positional("id",{type:"string",demandOption:!0}),async(i)=>{await fd(e(i),t(i),i.id)}).command(["edit <id> [text..]","update <id> [text..]"],"Edit a draft",(i)=>i.positional("id",{type:"string",demandOption:!0}).positional("text",{type:"string",array:!0,default:[]}).option("code",{type:"string"}),async(i)=>{let o=e(i),a=t(i),c=i.text.join(" ");if(!c)console.error("Usage: slack drafts edit <id> <new-text>"),process.exit(2);let u=await wn(o,a),f=X(u.drafts).map(T).find((g)=>String(g.id)===i.id);if(!f)console.error(`Draft not found: ${i.id}`),process.exit(1);let l=ys(f),d=await en(o,a),p=Ye(l,c,d?.userId??"");if(i.code!==p)Ne(i.code,p,["--- Editing draft as -------------------------",ve(d),"--- Current draft ----------------------------",...l.split(`
226
+ Tip: pass --user-id <Uxxxx> to skip the lookup.`),process.exit(Be)}l=d,u.asBot=!0}else{l=e(s);let d=t(s);if(d)u.cookie=d}try{await Pd(l,u)}catch(d){console.error(tt(d)),process.exit(Be)}}).command("doctor","Check the bot token (xoxb) can carry a two-way DM (scopes + Messages Tab)",(s)=>s,async()=>{let s=Ot();if(!s)console.error(`Error: slack doctor checks the bot token, but no xoxb- token was found.
227
+ Set SLACK_BOT_TOKEN=xoxb-... in ~/.config/slack-cli/.env (or your shell).`),process.exit(1);await Bd(s)}).command("schedule","Manage scheduled messages",(s)=>s.command("send <target> <message>","Schedule a message for later delivery",(i)=>i.positional("target",{type:"string",demandOption:!0,describe:"#chan, @user, #chan:thread_ts, or permalink (a message permalink replies in its thread)"}).positional("message",{type:"string",demandOption:!0}).option("at",{type:"string",demandOption:!0,describe:"Delivery time (ISO datetime or Unix ts)"}).option("code",{type:"string",describe:"Safety hash to confirm"}).option("channel-id",{type:"string",describe:"Raw channel ID"}).option("user-id",{type:"string",describe:"Raw user ID (opens DM)"}).option("as-bot",{type:"boolean",default:!1,describe:"Schedule via the bot token (xoxb / SLACK_BOT_TOKEN) so a DM notifies the recipient. Without it a scheduled DM to yourself is posted by you, and Slack never notifies you of your own message \u2014 it fires into silence."}),async(i)=>{let o={target:i.target,message:i.message,at:i.at};if(i.code)o.code=i.code;if(i["channel-id"])o.channelId=i["channel-id"],o.targetOverride=`--channel-id ${i["channel-id"]}`;if(i["user-id"])o.userId=i["user-id"],o.targetOverride=`--user-id ${i["user-id"]}`;let a;if(i["as-bot"]){let c=Gr();if(!o.channelId&&!o.userId&&o.target.startsWith("@"))try{o.userId=await ut(e(i),o.target,t(i))}catch(u){console.error(`Error: could not resolve ${o.target} to a user for the bot DM.
228
+ ${u instanceof Error?u.message:String(u)}
229
+ Tip: pass --user-id <Uxxxx> to skip the lookup.`),process.exit(1)}a=c,o.asBot=!0}else{a=e(i);let c=t(i);if(c)o.cookie=c}await jd(a,o)}).command(["ls","list"],"List pending scheduled messages",(i)=>i.positional("target",{type:"string",describe:"#channel to filter by"}).option("channel-id",{type:"string",describe:"Raw channel ID"}).option("as-bot",{type:"boolean",default:!1,describe:"List what the BOT token scheduled. A message from `schedule send --as-bot` belongs to the app, so the user token's listing does not contain it \u2014 and an invisible pending message cannot be cancelled."}),async(i)=>{let o=i.target;if(i["as-bot"]){let a=Gr(),c=i["channel-id"];if(!c&&o?.startsWith("@"))c=await Vc(o,a,e(i),t(i));await Zc(a,o,c);return}await Zc(e(i),o,i["channel-id"],t(i))}).command("rm <target> <id>","Delete a scheduled message",(i)=>i.positional("target",{type:"string",demandOption:!0,describe:"#channel or @user"}).positional("id",{type:"string",demandOption:!0,describe:"Scheduled message ID"}).option("code",{type:"string",describe:"Safety hash to confirm"}).option("channel-id",{type:"string",describe:"Raw channel ID"}).option("as-bot",{type:"boolean",default:!1,describe:"Cancel a message scheduled with `schedule send --as-bot`. It belongs to the bot token, so the user token cannot delete it."}),async(i)=>{let o={target:i.target,id:i.id};if(i.code)o.code=i.code;if(i["channel-id"])o.channelId=i["channel-id"],o.targetOverride=`--channel-id ${i["channel-id"]}`;if(i["as-bot"]){let c=Gr();if(!o.channelId&&o.target.startsWith("@"))o.channelId=await Vc(o.target,c,e(i),t(i));o.asBot=!0,await Qc(c,o);return}let a=t(i);if(a)o.cookie=a;await Qc(e(i),o)}).demandCommand(1,"").showHelpOnFail(!0),()=>{}).command("edit <target> <newText>","Edit a sent message",(s)=>s.positional("target",{type:"string",demandOption:!0,describe:"#chan:ts, @user:ts, or permalink"}).positional("newText",{type:"string",demandOption:!0}).option("code",{type:"string",describe:"Safety hash to confirm edit"}).option("channel-id",{type:"string",describe:"Raw channel ID"}).option("mentions",{type:"boolean",default:!0,describe:"Convert @handle tokens in the new text to real <@USERID> mentions (on by default). Unresolved handles stay as plain text. Disable with --no-mentions for literal @text."}),async(s)=>{let i={target:s.target,newText:s.newText};if(s.code)i.code=s.code;if(s["channel-id"])i.channelId=s["channel-id"];if(s.mentions!==!1)i.mentions=!0;let o=t(s);if(o)i.cookie=o;await wd(e(s),i)}).command("delete <target>","Delete a sent message (confirm-hash safety gate)",(s)=>s.positional("target",{type:"string",demandOption:!0,describe:"#chan:ts, @user:ts, or permalink"}).option("code",{type:"string",describe:"Safety hash to confirm delete"}).option("channel-id",{type:"string",describe:"Raw channel ID"}),async(s)=>{let i={target:s.target};if(s.code)i.code=s.code;if(s["channel-id"])i.channelId=s["channel-id"];let o=t(s);if(o)i.cookie=o;await bd(e(s),i)}).command("react <target> <emoji>","Add (or --remove) an emoji reaction \u2014 a lightweight ack that doesn't grow the thread",(s)=>s.positional("target",{type:"string",demandOption:!0,describe:"#chan:ts, @user:ts, or permalink"}).positional("emoji",{type:"string",demandOption:!0,describe:"Emoji shortcode without colons (e.g. eyes, white_check_mark, hourglass)"}).option("remove",{type:"boolean",default:!1,describe:"Remove the reaction instead of adding it"}).option("channel-id",{type:"string",describe:"Raw channel ID"}),async(s)=>{let i={target:s.target,emoji:s.emoji};if(s.remove)i.remove=!0;if(s["channel-id"])i.channelId=s["channel-id"];let o=t(s);if(o)i.cookie=o;try{await Fd(e(s),i)}catch(a){console.error(tt(a)),process.exit(1)}}).command("todo","Reaction-backed task tracking (:pushpin: marks a task, progress lives in a second reaction)",(s)=>s.option("cache",{type:"boolean",default:!0,describe:"Use ~/.config/slack-cli/cache.json for channel/user lookups (--no-cache to bypass)"}).middleware((i)=>{if(i.cache===!1)Hr(!1)}).command(["ls","list"],"List everyone's tasks (has: \u2014 read-only, one search per run)",(i)=>i.options(n).option("mine",{type:"boolean",default:!1,describe:"Only your own reactions (hasmy:) \u2014 same as `slack mytodo ls`"}).option("shared",{type:"boolean",default:!1,hidden:!0,describe:"Deprecated \u2014 anyone's reactions is the default for `todo ls`"}),async(i)=>{await r(i,!1)}).command("set <target> <state>","Move a task to a progress state (adds the new reaction before removing the old one)",(i)=>i.positional("target",{type:"string",demandOption:!0,describe:"#chan:ts or permalink"}).positional("state",{type:"string",demandOption:!0,choices:["pending","doing","done","dropped"]}).option("channel-id",{type:"string",describe:"Raw channel ID"}),async(i)=>{let o={target:i.target,state:i.state};if(i["channel-id"])o.channelId=i["channel-id"];let a=t(i);if(a)o.cookie=a;try{await ud(e(i),o)}catch(c){console.error(tt(c)),process.exit(1)}}).command("flag <target> <flag>","Add (or --remove) a reason flag (alert | needs-discussion | waiting | blocked) \u2014 flags stack, independent of progress",(i)=>i.positional("target",{type:"string",demandOption:!0,describe:"#chan:ts or permalink"}).positional("flag",{type:"string",demandOption:!0,choices:["alert","needs-discussion","waiting","blocked"],describe:"waiting = the other party in this conversation owes a reply; blocked = stuck on something outside it"}).option("remove",{type:"boolean",default:!1,describe:"Remove the flag instead of adding it"}).option("channel-id",{type:"string",describe:"Raw channel ID"}),async(i)=>{let o={target:i.target,flag:i.flag};if(i.remove)o.remove=!0;if(i["channel-id"])o.channelId=i["channel-id"];let a=t(i);if(a)o.cookie=a;try{await ld(e(i),o)}catch(c){console.error(tt(c)),process.exit(1)}}).command("doctor","Find messages carrying two or more progress reactions (--fix repairs them)",(i)=>i.option("in",{type:"string",demandOption:!0,describe:"Channel to scan (#chan)"}).option("fix",{type:"boolean",default:!1,describe:"Repair findings (keeps the highest-priority state)"}).option("limit",{type:"number",default:zr,describe:"Max messages to scan"}).option("channel-id",{type:"string",describe:"Raw channel ID"}),async(i)=>{let o={channel:i.in,limit:i.limit};if(i.fix)o.fix=!0;if(i["channel-id"])o.channelId=i["channel-id"];let a=t(i);if(a)o.cookie=a;await fd(e(i),o)}).demandCommand(1,"Specify a todo subcommand (ls, set, flag, doctor)"),()=>{}).command("mytodo","Tasks carrying YOUR reactions (hasmy:) \u2014 the my-only half of `todo`",(s)=>s.option("cache",{type:"boolean",default:!0,describe:"Use ~/.config/slack-cli/cache.json for channel/user lookups (--no-cache to bypass)"}).middleware((i)=>{if(i.cache===!1)Hr(!1)}).command(["ls","list"],"List tasks you have reacted to (hasmy: \u2014 read-only, one search per run)",(i)=>i.options(n),async(i)=>{await r(i,!0)}).demandCommand(1,"Specify a mytodo subcommand (ls)"),()=>{}).command("upload <target> <file..>","Upload one or more files to a channel or DM",(s)=>s.positional("target",{type:"string",demandOption:!0,describe:"#chan, @user, #chan:thread_ts, or permalink (a message permalink replies in its thread)"}).positional("file",{type:"string",array:!0,demandOption:!0,describe:"Path(s) to file(s)"}).option("title",{type:"string",describe:"Title (single file only)"}).option("comment",{type:"string",describe:"Initial comment (first file)"}).option("code",{type:"string",describe:"4-hex safety code to confirm upload"}).option("channel-id",{type:"string"}).option("user-id",{type:"string"}),async(s)=>{let i={target:s.target,filePaths:s.file};if(s.title)i.title=s.title;if(s.comment)i.comment=s.comment;if(s.code)i.code=s.code;if(s["channel-id"])i.channelId=s["channel-id"];if(s["user-id"])i.userId=s["user-id"];let o=t(s);if(o)i.cookie=o;await Ld(e(s),i)}).command("files","File commands",(s)=>s.command(["ls","list"],"List files visible to you (files.list)",(i)=>i.option("limit",{alias:"l",type:"number",default:100,describe:"Max files to list"}).option("type",{alias:"t",type:"string",describe:"Slack type filter: images, pdfs, gdocs, snippets, zips, spaces, all"}).option("channel",{alias:"c",type:"string",describe:"Only files in this channel (#name, @user, ID, or permalink)"}).option("user",{alias:"u",type:"string",describe:"Only files from this raw user ID"}).option("format",{type:"string",choices:["text","jsonl"],default:"text"}).option("json",{type:"boolean",default:!1,describe:"Alias for --format=jsonl"}),async(i)=>{let o={limit:i.limit,format:i.json?"jsonl":i.format};if(i.type)o.types=i.type;if(i.channel)o.channel=i.channel;if(i.user)o.user=i.user;await Wd(e(i),t(i),o)}).demandCommand(1,"").showHelpOnFail(!0),()=>{}).command("lists <ref>","Read a Slack List's rows (by list URL or F-id) \u2014 read-only",(s)=>s.positional("ref",{type:"string",demandOption:!0,describe:"List URL (\u2026/lists/<TEAM>/<F-id>) or bare F-id"}).option("limit",{alias:"l",type:"number",default:100,describe:"Max rows to show"}).option("format",{type:"string",choices:["text","jsonl"],default:"text"}).option("json",{type:"boolean",default:!1,describe:"Alias for --format=jsonl (raw records)"}),async(s)=>{let i=s.json?"jsonl":s.format;try{await Jd(e(s),t(s),s.ref,{limit:s.limit,format:i})}catch(o){console.error(tt(o)),process.exit(1)}}).command("download <ref> [dest]","Download a file attachment (by file ID or file permalink) to disk",(s)=>s.positional("ref",{type:"string",demandOption:!0,describe:"File ID (F\u2026) or Slack file permalink"}).positional("dest",{type:"string",describe:"Output path or directory (default: ./<filename>)"}),async(s)=>{await Hd(e(s),t(s),s.ref,s.dest)}).command("dump","Bulk export channel history as markdown",(s)=>s.option("days",{alias:"d",type:"number",default:7,describe:"Days of history"}).option("limit",{alias:"l",type:"number",default:200}).option("filter",{alias:"f",type:"string",describe:"Filter channel names"}),async(s)=>{await dd(e(s),s.days,s.limit,s.filter)}).command("drafts","Manage message drafts (requires xoxc desktop token)",(s)=>s.command(["$0","ls","list"],"List pending drafts",(i)=>i.option("all",{alias:"a",type:"boolean",default:!1,describe:"Include sent drafts"}),async(i)=>{await hd(e(i),t(i),i.all)}).command(["new <channel> [text..]","save <channel> [text..]"],"Create a draft",(i)=>i.positional("channel",{type:"string",demandOption:!0}).positional("text",{type:"string",array:!0,default:[]}),async(i)=>{let o=e(i),a=t(i),c=i.text.join(" ");if(!c)console.error("Usage: slack drafts new <#channel|@user> <text>"),process.exit(2);let u=await De(o,i.channel,a),f=await bc(o,u,c,a);console.log(`\u2713 Draft created (id: ${T(f.draft).id??"?"})`)}).command("get <id>","Show a draft",(i)=>i.positional("id",{type:"string",demandOption:!0}),async(i)=>{await gd(e(i),t(i),i.id)}).command(["edit <id> [text..]","update <id> [text..]"],"Edit a draft",(i)=>i.positional("id",{type:"string",demandOption:!0}).positional("text",{type:"string",array:!0,default:[]}).option("code",{type:"string"}),async(i)=>{let o=e(i),a=t(i),c=i.text.join(" ");if(!c)console.error("Usage: slack drafts edit <id> <new-text>"),process.exit(2);let u=await wn(o,a),f=X(u.drafts).map(T).find((g)=>String(g.id)===i.id);if(!f)console.error(`Draft not found: ${i.id}`),process.exit(1);let l=bs(f),d=await en(o,a),p=Ye(l,c,d?.userId??"");if(i.code!==p)Ne(i.code,p,["--- Editing draft as -------------------------",ve(d),"--- Current draft ----------------------------",...l.split(`
224
230
  `).map((g)=>` ${g}`),"--- Replacing with ---------------------------",...c.split(`
225
- `).map((g)=>` ${g}`),"--------------------------------\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"]);let m=await bc(o,i.id,Qr(f),c,a);console.log(`\u2713 Draft updated (id: ${T(m.draft).id??"?"})`)}).command(["delete <id>","rm <id>"],"Delete a draft",(i)=>i.positional("id",{type:"string",demandOption:!0}).option("code",{type:"string"}),async(i)=>{let o=e(i),a=t(i),c=await wn(o,a),u=X(c.drafts).map(T).find((p)=>String(p.id)===i.id);if(!u)console.error(`Draft not found: ${i.id}`),process.exit(1);let f=ys(u),l=await en(o,a),d=Ye(i.id,f,l?.userId??"");if(i.code!==d)Ne(i.code,d,["\u2500-- Deleting draft \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500",ve(l),` id: ${i.id}`,...f.split(`
226
- `).map((p)=>` ${p}`),"--------------------------------\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"]);await Cc(o,i.id,a),console.log(`\u2713 Draft deleted (id: ${i.id})`)})).command("auth","Authentication and workspace management",(s)=>s.command("token","Add a workspace \u2014 paste an existing xoxp-/xoxb- token",(i)=>i.option("token",{type:"string",describe:"Token to save directly (non-interactive)"}).option("name",{type:"string",describe:"Workspace name (used with --token)"}),async(i)=>{await _a({...i.token!==void 0?{token:i.token}:{},...i.name!==void 0?{name:i.name}:{}})}).command("app","Create a new Slack app and obtain a token (guided wizard)",(i)=>i.option("bot",{type:"boolean",describe:"Create a bot token (xoxb-) instead of user (xoxp-)"}),async(i)=>{await Sa({...i.bot!==void 0?{bot:i.bot}:{}})}).command("login","Interactive auth wizard (all auth methods: desktop app, token, new app)",(i)=>i.option("token",{type:"string",describe:"Token to save directly (non-interactive)"}).option("name",{type:"string",describe:"Workspace name (used with --token)"}),async(i)=>{await ns({...i.token!==void 0?{token:i.token}:{},...i.name!==void 0?{name:i.name}:{}})}).command(["ls","status"],"Show auth status",()=>{},()=>{let i=ar();if(i.length===0){console.log("No workspaces configured. Run: slack auth login");return}for(let{name:o,profile:a,current:c}of i)console.log(`${c?"* ":" "}${o} ${a.team} (${a.user}) ${a.url??""}`)}).command("use <name>","Switch active workspace",(i)=>i.positional("name",{type:"string",demandOption:!0}).option("g",{type:"boolean",default:!1,describe:"Write global lockfile (~/.slack-cli/workspace)"}),(i)=>{if(!i.g)Hf(ft(process.cwd(),".slack-cli"));Ko(i.name,i.g),console.log(`Switched to workspace "${i.name}" ${i.g?"globally":"locally"}`)}).command(["logout <name>","rm <name>","remove <name>"],"Remove a workspace",(i)=>i.positional("name",{type:"string",demandOption:!0}),(i)=>{Uo(i.name),console.log(`Removed workspace "${i.name}"`)}).command(["chrome","cookie"],"Attach Chrome browser xoxd cookie to a workspace (macOS, interactive)",(i)=>i.option("workspace",{type:"string",alias:"w",describe:"Workspace name to update (default: active)"}),async(i)=>{await Ea({...i.workspace!==void 0?{workspace:i.workspace}:{}})}).command("firefox","Attach Firefox browser xoxd cookie to a workspace (all platforms)",(i)=>i.option("workspace",{type:"string",alias:"w",describe:"Workspace name to update (default: active)"}),async(i)=>{await xa({...i.workspace!==void 0?{workspace:i.workspace}:{}})}).command("$0",!1,()=>{},()=>{s.showHelp(),process.exit(0)})).command("tail [target]","Stream new messages in real time (like tail -f)",(s)=>s.positional("target",{type:"string",describe:"#channel or @user to follow"}).option("since",{type:"string",describe:"Backfill from N ago (e.g. 10m, 2h, 1d)"}).option("thread",{type:"string",describe:"Follow a single thread by timestamp"}).option("watch-thread",{type:"string",describe:"Watch the channel's top-level timeline AND one thread's replies together (ts or permalink)"}).option("me",{type:"boolean",default:!1,describe:"Filter to messages that mention you"}).option("interval",{type:"number",default:60000,describe:"Poll interval in ms (default 60s; use --interval=3000 for near-real-time)"}).option("timeout",{type:"string",describe:"Auto-stop after this long (e.g. 30m, 2h). Exit code 0 even if nothing arrived."}).option("exit-on-message",{type:"boolean",default:!1,describe:"Stop as soon as the first new message from someone else arrives (wait-for-reply)"}).option("rtm",{type:"boolean",default:!0,describe:"Use RTM WebSocket when available (xoxc + cookie); pass --no-rtm to force polling"}),async(s)=>{let i=e(s),o=t(s),a=new AbortController;process.on("SIGINT",()=>{a.abort(),process.exit(0)}),await Pa(i,s.target,{...s.since!==void 0?{since:s.since}:{},...s.thread!==void 0?{thread:s.thread}:{},...s["watch-thread"]!==void 0?{watchThread:s["watch-thread"]}:{},me:s.me,interval:s.interval,...s.timeout!==void 0?{timeout:s.timeout}:{},...s["exit-on-message"]===!0?{exitOnMessage:!0}:{},...o!==void 0?{cookie:o}:{},...s.rtm===!1?{noRtm:!0}:{}},a.signal)}).command("login",!1,(s)=>s.option("token",{type:"string"}).option("name",{type:"string"}),async(s)=>{await ns({...s.token!==void 0?{token:s.token}:{},...s.name!==void 0?{name:s.name}:{}})}).demandCommand(1,"Specify a command. Run with --help for usage.").strict().help().alias("help","h").parseAsync()}zd().catch((e)=>{console.error(e instanceof Error?e.message:String(e)),process.exit(1)});
231
+ `).map((g)=>` ${g}`),"--------------------------------\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"]);let m=await Fc(o,i.id,ti(f),c,a);console.log(`\u2713 Draft updated (id: ${T(m.draft).id??"?"})`)}).command(["delete <id>","rm <id>"],"Delete a draft",(i)=>i.positional("id",{type:"string",demandOption:!0}).option("code",{type:"string"}),async(i)=>{let o=e(i),a=t(i),c=await wn(o,a),u=X(c.drafts).map(T).find((p)=>String(p.id)===i.id);if(!u)console.error(`Draft not found: ${i.id}`),process.exit(1);let f=bs(u),l=await en(o,a),d=Ye(i.id,f,l?.userId??"");if(i.code!==d)Ne(i.code,d,["\u2500-- Deleting draft \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500",ve(l),` id: ${i.id}`,...f.split(`
232
+ `).map((p)=>` ${p}`),"--------------------------------\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"]);await Ec(o,i.id,a),console.log(`\u2713 Draft deleted (id: ${i.id})`)})).command("auth","Authentication and workspace management",(s)=>s.command("token","Add a workspace \u2014 paste an existing xoxp-/xoxb- token",(i)=>i.option("token",{type:"string",describe:"Token to save directly (non-interactive)"}).option("name",{type:"string",describe:"Workspace name (used with --token)"}),async(i)=>{await ka({...i.token!==void 0?{token:i.token}:{},...i.name!==void 0?{name:i.name}:{}})}).command("app","Create a new Slack app and obtain a token (guided wizard)",(i)=>i.option("bot",{type:"boolean",describe:"Create a bot token (xoxb-) instead of user (xoxp-)"}),async(i)=>{await Sa({...i.bot!==void 0?{bot:i.bot}:{}})}).command("login","Interactive auth wizard (all auth methods: desktop app, token, new app)",(i)=>i.option("token",{type:"string",describe:"Token to save directly (non-interactive)"}).option("name",{type:"string",describe:"Workspace name (used with --token)"}),async(i)=>{await rs({...i.token!==void 0?{token:i.token}:{},...i.name!==void 0?{name:i.name}:{}})}).command(["ls","status"],"Show auth status",()=>{},()=>{let i=lr();if(i.length===0){console.log("No workspaces configured. Run: slack auth login");return}for(let{name:o,profile:a,current:c}of i)console.log(`${c?"* ":" "}${o} ${a.team} (${a.user}) ${a.url??""}`)}).command("use <name>","Switch active workspace",(i)=>i.positional("name",{type:"string",demandOption:!0}).option("g",{type:"boolean",default:!1,describe:"Write global lockfile (~/.slack-cli/workspace)"}),(i)=>{if(!i.g)Gf(pt(process.cwd(),".slack-cli"));Jo(i.name,i.g),console.log(`Switched to workspace "${i.name}" ${i.g?"globally":"locally"}`)}).command(["logout <name>","rm <name>","remove <name>"],"Remove a workspace",(i)=>i.positional("name",{type:"string",demandOption:!0}),(i)=>{Ko(i.name),console.log(`Removed workspace "${i.name}"`)}).command(["chrome","cookie"],"Attach Chrome browser xoxd cookie to a workspace (macOS, interactive)",(i)=>i.option("workspace",{type:"string",alias:"w",describe:"Workspace name to update (default: active)"}),async(i)=>{await xa({...i.workspace!==void 0?{workspace:i.workspace}:{}})}).command("firefox","Attach Firefox browser xoxd cookie to a workspace (all platforms)",(i)=>i.option("workspace",{type:"string",alias:"w",describe:"Workspace name to update (default: active)"}),async(i)=>{await _a({...i.workspace!==void 0?{workspace:i.workspace}:{}})}).command("$0",!1,()=>{},()=>{s.showHelp(),process.exit(0)})).command("tail [target]","Stream new messages in real time (like tail -f)",(s)=>s.positional("target",{type:"string",describe:"#channel or @user to follow"}).option("since",{type:"string",describe:"Backfill from N ago (e.g. 10m, 2h, 1d)"}).option("thread",{type:"string",describe:"Follow a single thread by timestamp"}).option("watch-thread",{type:"string",describe:"Watch the channel's top-level timeline AND one thread's replies together (ts or permalink)"}).option("me",{type:"boolean",default:!1,describe:"Filter to messages that mention you"}).option("interval",{type:"number",default:60000,describe:"Poll interval in ms (default 60s; use --interval=3000 for near-real-time)"}).option("timeout",{type:"string",describe:"Auto-stop after this long (e.g. 30m, 2h). Exit code 0 even if nothing arrived."}).option("exit-on-message",{type:"boolean",default:!1,describe:"Stop as soon as the first new message from someone else arrives (wait-for-reply)"}).option("rtm",{type:"boolean",default:!0,describe:"Use RTM WebSocket when available (xoxc + cookie); pass --no-rtm to force polling"}),async(s)=>{let i=e(s),o=t(s),a=new AbortController;process.on("SIGINT",()=>{a.abort(),process.exit(0)}),await Ra(i,s.target,{...s.since!==void 0?{since:s.since}:{},...s.thread!==void 0?{thread:s.thread}:{},...s["watch-thread"]!==void 0?{watchThread:s["watch-thread"]}:{},me:s.me,interval:s.interval,...s.timeout!==void 0?{timeout:s.timeout}:{},...s["exit-on-message"]===!0?{exitOnMessage:!0}:{},...o!==void 0?{cookie:o}:{},...s.rtm===!1?{noRtm:!0}:{}},a.signal)}).command("login",!1,(s)=>s.option("token",{type:"string"}).option("name",{type:"string"}),async(s)=>{await rs({...s.token!==void 0?{token:s.token}:{},...s.name!==void 0?{name:s.name}:{}})}).demandCommand(1,"Specify a command. Run with --help for usage.").strict().help().alias("help","h").parseAsync()}qd().catch((e)=>{console.error(e instanceof Error?e.message:String(e)),process.exit(1)});