slack-term 1.27.1 → 1.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -1,21 +1,21 @@
1
1
  #!/usr/bin/env bun
2
2
  // @bun
3
- import{createRequire as G6}from"node:module";var E6=Object.create;var{getPrototypeOf:B6,defineProperty:P2,getOwnPropertyNames:C6}=Object;var $6=Object.prototype.hasOwnProperty;function z6(D){return this[D]}var Z6,J6,T2=(D,F,u)=>{var B=D!=null&&typeof D==="object";if(B){var E=F?Z6??=new WeakMap:J6??=new WeakMap,C=E.get(D);if(C)return C}u=D!=null?E6(B6(D)):{};let $=F||!D||!D.__esModule?P2(u,"default",{value:D,enumerable:!0}):u;for(let z of C6(D))if(!$6.call($,z))P2($,z,{get:z6.bind(D,z),enumerable:!0});if(B)E.set(D,$);return $};var R2=(D,F)=>()=>(F||D((F={exports:{}}).exports,F),F.exports);var gD=G6(import.meta.url);var n2=R2((t4,l2)=>{l2.exports=()=>{return/[#*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 U8=R2((hE,j8)=>{j8.exports=function(F){if(F===void 0)F=2;if(F>=Error.stackTraceLimit)throw TypeError("getCallerFile(position) requires position be less then Error.stackTraceLimit but position was: `"+F+"` and Error.stackTraceLimit was: `"+Error.stackTraceLimit+"`");var u=Error.prepareStackTrace;Error.prepareStackTrace=function(E,C){return C};var B=Error().stack;if(Error.prepareStackTrace=u,B!==null&&typeof B==="object")return B[F]?B[F].getFileName():void 0}});import{createHash as R9}from"crypto";import{existsSync as l3,readFileSync as S9,mkdirSync as w9,writeFileSync as n3}from"fs";import{homedir as g3}from"os";import{join as $F}from"path";import{notStrictEqual as o6,strictEqual as s6}from"assert";var Q6={right:W6,center:V6};class w2{constructor(D){var F;this.width=D.width,this.wrap=(F=D.wrap)!==null&&F!==void 0?F:!0,this.rows=[]}span(...D){let F=this.div(...D);F.span=!0}resetOutput(){this.rows=[]}div(...D){if(D.length===0)this.div("");if(this.wrap&&this.shouldApplyLayoutDSL(...D)&&typeof D[0]==="string")return this.applyLayoutDSL(D[0]);let F=D.map((u)=>{if(typeof u==="string")return this.colFromString(u);return u});return this.rows.push(F),F}shouldApplyLayoutDSL(...D){return D.length===1&&typeof D[0]==="string"&&/[\t\n]/.test(D[0])}applyLayoutDSL(D){let F=D.split(`
4
- `).map((B)=>B.split("\t")),u=0;return F.forEach((B)=>{if(B.length>1&&_D.stringWidth(B[0])>u)u=Math.min(Math.floor(this.width*0.5),_D.stringWidth(B[0]))}),F.forEach((B)=>{this.div(...B.map((E,C)=>{return{text:E.trim(),padding:this.measurePadding(E),width:C===0&&B.length>1?u:void 0}}))}),this.rows[this.rows.length-1]}colFromString(D){return{text:D,padding:this.measurePadding(D)}}measurePadding(D){let F=_D.stripAnsi(D);return[0,F.match(/\s*$/)[0].length,0,F.match(/^\s*/)[0].length]}toString(){let D=[];return this.rows.forEach((F)=>{this.rowToString(F,D)}),D.filter((F)=>!F.hidden).map((F)=>F.text).join(`
5
- `)}rowToString(D,F){return this.rasterize(D).forEach((u,B)=>{let E="";u.forEach((C,$)=>{let{width:z}=D[$],Z=this.negatePadding(D[$]),J=C;if(Z>_D.stringWidth(C))J+=" ".repeat(Z-_D.stringWidth(C));if(D[$].align&&D[$].align!=="left"&&this.wrap){let G=Q6[D[$].align];if(J=G(J,Z),_D.stringWidth(J)<Z)J+=" ".repeat((z||0)-_D.stringWidth(J)-1)}let Q=D[$].padding||[0,0,0,0];if(Q[3])E+=" ".repeat(Q[3]);if(E+=S2(D[$],J,"| "),E+=J,E+=S2(D[$],J," |"),Q[1])E+=" ".repeat(Q[1]);if(B===0&&F.length>0)E=this.renderInline(E,F[F.length-1])}),F.push({text:E.replace(/ +$/,""),span:D.span})}),F}renderInline(D,F){let u=D.match(/^ */),B=u?u[0].length:0,E=F.text,C=_D.stringWidth(E.trimRight());if(!F.span)return D;if(!this.wrap)return F.hidden=!0,E+D;if(B<C)return D;return F.hidden=!0,E.trimRight()+" ".repeat(B-C)+D.trimLeft()}rasterize(D){let F=[],u=this.columnWidths(D),B;return D.forEach((E,C)=>{if(E.width=u[C],this.wrap)B=_D.wrap(E.text,this.negatePadding(E),{hard:!0}).split(`
6
- `);else B=E.text.split(`
7
- `);if(E.border)B.unshift("."+"-".repeat(this.negatePadding(E)+2)+"."),B.push("'"+"-".repeat(this.negatePadding(E)+2)+"'");if(E.padding)B.unshift(...Array(E.padding[0]||0).fill("")),B.push(...Array(E.padding[2]||0).fill(""));B.forEach(($,z)=>{if(!F[z])F.push([]);let Z=F[z];for(let J=0;J<C;J++)if(Z[J]===void 0)Z.push("");Z.push($)})}),F}negatePadding(D){let F=D.width||0;if(D.padding)F-=(D.padding[3]||0)+(D.padding[1]||0);if(D.border)F-=4;return F}columnWidths(D){if(!this.wrap)return D.map((C)=>{return C.width||_D.stringWidth(C.text)});let F=D.length,u=this.width,B=D.map((C)=>{if(C.width)return F--,u-=C.width,C.width;return}),E=F?Math.floor(u/F):0;return B.map((C,$)=>{if(C===void 0)return Math.max(E,X6(D[$]));return C})}}function S2(D,F,u){if(D.border){if(/[.']-+[.']/.test(F))return"";if(F.trim().length!==0)return u;return" "}return""}function X6(D){let F=D.padding||[],u=1+(F[3]||0)+(F[1]||0);if(D.border)return u+4;return u}function Y6(){if(typeof process==="object"&&process.stdout&&process.stdout.columns)return process.stdout.columns;return 80}function W6(D,F){D=D.trim();let u=_D.stringWidth(D);if(u<F)return" ".repeat(F-u)+D;return D}function V6(D,F){D=D.trim();let u=_D.stringWidth(D);if(u>=F)return D;return" ".repeat(F-u>>1)+D}var _D;function x2(D,F){return _D=F,new w2({width:(D===null||D===void 0?void 0:D.width)||Y6(),wrap:D===null||D===void 0?void 0:D.wrap})}function uu({onlyFirst:D=!1}={}){return new RegExp("(?:\\u001B\\][\\s\\S]*?(?:\\u0007|\\u001B\\u005C|\\u009C))|[\\u001B\\u009B][[\\]()#;?]*(?:\\d{1,4}(?:[;:]\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]",D?void 0:"g")}var H6=uu();function zF(D){if(typeof D!=="string")throw TypeError(`Expected a \`string\`, got \`${typeof D}\``);if(!D.includes("\x1B")&&!D.includes("›"))return D;return D.replace(H6,"")}var I2=161,b2=1114109,f2=[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],h2=12288,v2=65510,y2=[12288,12288,65281,65376,65504,65510];var p2=4352,m2=262141,Eu=[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 Z0=(D,F)=>{let u=0,B=Math.floor(D.length/2)-1;while(u<=B){let E=Math.floor((u+B)/2),C=E*2;if(F<D[C])B=E-1;else if(F>D[C+1])u=E+1;else return!0}return!1};var g2=19968,[q6,j6]=U6(Eu);function U6(D){let F=D[0],u=D[1];for(let B=0;B<D.length;B+=2){let E=D[B],C=D[B+1];if(g2>=E&&g2<=C)return[E,C];if(C-E>u-F)F=E,u=C}return[F,u]}var c2=(D)=>{if(D<I2||D>b2)return!1;return Z0(f2,D)},k2=(D)=>{if(D<h2||D>v2)return!1;return Z0(y2,D)};var d2=(D)=>{if(D>=q6&&D<=j6)return!0;if(D<p2||D>m2)return!1;return Z0(Eu,D)};function K6(D){if(!Number.isSafeInteger(D))throw TypeError(`Expected a code point, got \`${typeof D}\`.`)}function i2(D,{ambiguousAsWide:F=!1}={}){if(K6(D),k2(D)||d2(D)||F&&c2(D))return 2;return 1}var t2=T2(n2(),1),O6=new Intl.Segmenter,M6=/^\p{Default_Ignorable_Code_Point}$/u;function fD(D,F={}){if(typeof D!=="string"||D.length===0)return 0;let{ambiguousIsNarrow:u=!0,countAnsiEscapeCodes:B=!1}=F;if(!B)D=zF(D);if(D.length===0)return 0;let E=0,C={ambiguousAsWide:!u};for(let{segment:$}of O6.segment(D)){let z=$.codePointAt(0);if(z<=31||z>=127&&z<=159)continue;if(z>=8203&&z<=8207||z===65279)continue;if(z>=768&&z<=879||z>=6832&&z<=6911||z>=7616&&z<=7679||z>=8400&&z<=8447||z>=65056&&z<=65071)continue;if(z>=55296&&z<=57343)continue;if(z>=65024&&z<=65039)continue;if(M6.test($))continue;if(t2.default().test($)){E+=2;continue}E+=i2(z,C)}return E}var o2=(D=0)=>(F)=>`\x1B[${F+D}m`,s2=(D=0)=>(F)=>`\x1B[${38+D};5;${F}m`,r2=(D=0)=>(F,u,B)=>`\x1B[${38+D};2;${F};${u};${B}m`,FD={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]}},a4=Object.keys(FD.modifier),_6=Object.keys(FD.color),N6=Object.keys(FD.bgColor),e4=[..._6,...N6];function L6(){let D=new Map;for(let[F,u]of Object.entries(FD)){for(let[B,E]of Object.entries(u))FD[B]={open:`\x1B[${E[0]}m`,close:`\x1B[${E[1]}m`},u[B]=FD[B],D.set(E[0],E[1]);Object.defineProperty(FD,F,{value:u,enumerable:!1})}return Object.defineProperty(FD,"codes",{value:D,enumerable:!1}),FD.color.close="\x1B[39m",FD.bgColor.close="\x1B[49m",FD.color.ansi=o2(),FD.color.ansi256=s2(),FD.color.ansi16m=r2(),FD.bgColor.ansi=o2(10),FD.bgColor.ansi256=s2(10),FD.bgColor.ansi16m=r2(10),Object.defineProperties(FD,{rgbToAnsi256:{value(F,u,B){if(F===u&&u===B){if(F<8)return 16;if(F>248)return 231;return Math.round((F-8)/247*24)+232}return 16+36*Math.round(F/255*5)+6*Math.round(u/255*5)+Math.round(B/255*5)},enumerable:!1},hexToRgb:{value(F){let u=/[a-f\d]{6}|[a-f\d]{3}/i.exec(F.toString(16));if(!u)return[0,0,0];let[B]=u;if(B.length===3)B=[...B].map((C)=>C+C).join("");let E=Number.parseInt(B,16);return[E>>16&255,E>>8&255,E&255]},enumerable:!1},hexToAnsi256:{value:(F)=>FD.rgbToAnsi256(...FD.hexToRgb(F)),enumerable:!1},ansi256ToAnsi:{value(F){if(F<8)return 30+F;if(F<16)return 90+(F-8);let u,B,E;if(F>=232)u=((F-232)*10+8)/255,B=u,E=u;else{F-=16;let z=F%36;u=Math.floor(F/36)/5,B=Math.floor(z/6)/5,E=z%6/5}let C=Math.max(u,B,E)*2;if(C===0)return 30;let $=30+(Math.round(E)<<2|Math.round(B)<<1|Math.round(u));if(C===2)$+=60;return $},enumerable:!1},rgbToAnsi:{value:(F,u,B)=>FD.ansi256ToAnsi(FD.rgbToAnsi256(F,u,B)),enumerable:!1},hexToAnsi:{value:(F)=>FD.ansi256ToAnsi(FD.hexToAnsi256(F)),enumerable:!1}}),FD}var A6=L6(),a2=A6;var G0=new Set(["\x1B","›"]),P6=39,Cu="\x07",F8="[",T6="]",u8="m",J0=`${T6}8;;`,e2=(D)=>`${G0.values().next().value}${F8}${D}${u8}`,D8=(D)=>`${G0.values().next().value}${J0}${D}${Cu}`,R6=(D)=>D.split(" ").map((F)=>fD(F)),Bu=(D,F,u)=>{let B=[...F],E=!1,C=!1,$=fD(zF(D.at(-1)));for(let[z,Z]of B.entries()){let J=fD(Z);if($+J<=u)D[D.length-1]+=Z;else D.push(Z),$=0;if(G0.has(Z))E=!0,C=B.slice(z+1,z+1+J0.length).join("")===J0;if(E){if(C){if(Z===Cu)E=!1,C=!1}else if(Z===u8)E=!1;continue}if($+=J,$===u&&z<B.length-1)D.push(""),$=0}if(!$&&D.at(-1).length>0&&D.length>1)D[D.length-2]+=D.pop()},S6=(D)=>{let F=D.split(" "),u=F.length;while(u>0){if(fD(F[u-1])>0)break;u--}if(u===F.length)return D;return F.slice(0,u).join(" ")+F.slice(u).join("")},w6=(D,F,u={})=>{if(u.trim!==!1&&D.trim()==="")return"";let B="",E,C,$=R6(D),z=[""];for(let[G,X]of D.split(" ").entries()){if(u.trim!==!1)z[z.length-1]=z.at(-1).trimStart();let V=fD(z.at(-1));if(G!==0){if(V>=F&&(u.wordWrap===!1||u.trim===!1))z.push(""),V=0;if(V>0||u.trim===!1)z[z.length-1]+=" ",V++}if(u.hard&&$[G]>F){let H=F-V,W=1+Math.floor(($[G]-H-1)/F);if(Math.floor(($[G]-1)/F)<W)z.push("");Bu(z,X,F);continue}if(V+$[G]>F&&V>0&&$[G]>0){if(u.wordWrap===!1&&V<F){Bu(z,X,F);continue}z.push("")}if(V+$[G]>F&&u.wordWrap===!1){Bu(z,X,F);continue}z[z.length-1]+=X}if(u.trim!==!1)z=z.map((G)=>S6(G));let Z=z.join(`
8
- `),J=[...Z],Q=0;for(let[G,X]of J.entries()){if(B+=X,G0.has(X)){let{groups:H}=new RegExp(`(?:\\${F8}(?<code>\\d+)m|\\${J0}(?<uri>.*)${Cu})`).exec(Z.slice(Q))||{groups:{}};if(H.code!==void 0){let W=Number.parseFloat(H.code);E=W===P6?void 0:W}else if(H.uri!==void 0)C=H.uri.length===0?void 0:H.uri}let V=a2.codes.get(Number(E));if(J[G+1]===`
9
- `){if(C)B+=D8("");if(E&&V)B+=e2(V)}else if(X===`
10
- `){if(E&&V)B+=e2(E);if(C)B+=D8(C)}Q+=X.length}return B};function $u(D,F,u){return String(D).normalize().replaceAll(`\r
3
+ import{createRequire as zc}from"node:module";var vc=Object.create;var{getPrototypeOf:jc,defineProperty:Xi,getOwnPropertyNames:Lc}=Object;var Wc=Object.prototype.hasOwnProperty;function Uc(e){return this[e]}var Jc,Kc,Gi=(e,t,n)=>{var i=e!=null&&typeof e==="object";if(i){var s=t?Jc??=new WeakMap:Kc??=new WeakMap,r=s.get(e);if(r)return r}n=e!=null?vc(jc(e)):{};let o=t||!e||!e.__esModule?Xi(n,"default",{value:e,enumerable:!0}):n;if(e&&typeof e==="object"||typeof e==="function"){for(let a of Lc(e))if(!Wc.call(o,a))Xi(o,a,{get:Uc.bind(e,a),enumerable:!0})}if(i)s.set(e,o);return o};var Vi=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var qe=zc(import.meta.url);var gr=Vi(function(Nd,hr){hr.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 Wr=Vi(function(_p,Lr){Lr.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,r){return r};var i=Error().stack;if(Error.prepareStackTrace=n,i!==null&&typeof i==="object")return i[t]?i[t].getFileName():void 0}});import{createHash as hf}from"crypto";import{existsSync as Ac,readFileSync as gf,mkdirSync as mf,writeFileSync as $c}from"fs";import{homedir as Ec}from"os";import{join as ft}from"path";import{notStrictEqual as Ou,strictEqual as Iu}from"assert";var Hc={right:Xc,center:Gc};class Qi{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((i)=>i.split("\t")),n=0;return t.forEach((i)=>{if(i.length>1&&xe.stringWidth(i[0])>n)n=Math.min(Math.floor(this.width*0.5),xe.stringWidth(i[0]))}),t.forEach((i)=>{this.div(...i.map((s,r)=>({text:s.trim(),padding:this.measurePadding(s),width:r===0&&i.length>1?n:void 0})))}),this.rows[this.rows.length-1]}colFromString(e){return{text:e,padding:this.measurePadding(e)}}measurePadding(e){let t=xe.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,i)=>{let s="";n.forEach((r,o)=>{let{width:a}=e[o],c=this.negatePadding(e[o]),u=r;if(c>xe.stringWidth(r))u+=" ".repeat(c-xe.stringWidth(r));if(e[o].align&&e[o].align!=="left"&&this.wrap){let l=Hc[e[o].align];if(u=l(u,c),xe.stringWidth(u)<c)u+=" ".repeat((a||0)-xe.stringWidth(u)-1)}let f=e[o].padding||[0,0,0,0];if(f[3])s+=" ".repeat(f[3]);if(s+=Zi(e[o],u,"| "),s+=u,s+=Zi(e[o],u," |"),f[1])s+=" ".repeat(f[1]);if(i===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(/^ */),i=n?n[0].length:0,s=t.text,r=xe.stringWidth(s.trimRight());if(!t.span)return e;if(!this.wrap)return t.hidden=!0,s+e;if(i<r)return e;return t.hidden=!0,s.trimRight()+" ".repeat(i-r)+e.trimLeft()}rasterize(e){let t=[],n=this.columnWidths(e),i;return e.forEach((s,r)=>{if(s.width=n[r],this.wrap)i=xe.wrap(s.text,this.negatePadding(s),{hard:!0}).split(`
6
+ `);else i=s.text.split(`
7
+ `);if(s.border)i.unshift("."+"-".repeat(this.negatePadding(s)+2)+"."),i.push("'"+"-".repeat(this.negatePadding(s)+2)+"'");if(s.padding)i.unshift(...Array(s.padding[0]||0).fill("")),i.push(...Array(s.padding[2]||0).fill(""));i.forEach((o,a)=>{if(!t[a])t.push([]);let c=t[a];for(let u=0;u<r;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((r)=>r.width||xe.stringWidth(r.text));let t=e.length,n=this.width,i=e.map((r)=>{if(r.width)return t--,n-=r.width,r.width;return}),s=t?Math.floor(n/t):0;return i.map((r,o)=>{if(r===void 0)return Math.max(s,qc(e[o]));return r})}}function Zi(e,t,n){if(e.border){if(/[.']-+[.']/.test(t))return"";if(t.trim().length!==0)return n;return" "}return""}function qc(e){let t=e.padding||[],n=1+(t[3]||0)+(t[1]||0);if(e.border)return n+4;return n}function Yc(){if(typeof process==="object"&&process.stdout&&process.stdout.columns)return process.stdout.columns;return 80}function Xc(e,t){e=e.trim();let n=xe.stringWidth(e);if(n<t)return" ".repeat(t-n)+e;return e}function Gc(e,t){e=e.trim();let n=xe.stringWidth(e);if(n>=t)return e;return" ".repeat(t-n>>1)+e}var xe;function er(e,t){return xe=t,new Qi({width:(e===null||e===void 0?void 0:e.width)||Yc(),wrap:e===null||e===void 0?void 0:e.wrap})}function ys({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 Vc=ys();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(Vc,"")}var tr=161,nr=1114109,sr=[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],ir=12288,rr=65510,or=[12288,12288,65281,65376,65504,65510];var ar=4352,cr=262141,ws=[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 Cn=(e,t)=>{let n=0,i=Math.floor(e.length/2)-1;while(n<=i){let s=Math.floor((n+i)/2),r=s*2;if(t<e[r])i=s-1;else if(t>e[r+1])n=s+1;else return!0}return!1};var ur=19968,[Zc,Qc]=eu(ws);function eu(e){let t=e[0],n=e[1];for(let i=0;i<e.length;i+=2){let s=e[i],r=e[i+1];if(ur>=s&&ur<=r)return[s,r];if(r-s>n-t)t=s,n=r}return[t,n]}var lr=(e)=>{if(e<tr||e>nr)return!1;return Cn(sr,e)},fr=(e)=>{if(e<ir||e>rr)return!1;return Cn(or,e)};var dr=(e)=>{if(e>=Zc&&e<=Qc)return!0;if(e<ar||e>cr)return!1;return Cn(ws,e)};function tu(e){if(!Number.isSafeInteger(e))throw TypeError(`Expected a code point, got \`${typeof e}\`.`)}function pr(e,{ambiguousAsWide:t=!1}={}){if(tu(e),fr(e)||dr(e)||t&&lr(e))return 2;return 1}var mr=Gi(gr(),1),nu=new Intl.Segmenter,su=/^\p{Default_Ignorable_Code_Point}$/u;function Le(e,t={}){if(typeof e!=="string"||e.length===0)return 0;let{ambiguousIsNarrow:n=!0,countAnsiEscapeCodes:i=!1}=t;if(!i)e=dt(e);if(e.length===0)return 0;let s=0,r={ambiguousAsWide:!n};for(let{segment:o}of nu.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(su.test(o))continue;if(mr.default().test(o)){s+=2;continue}s+=pr(a,r)}return s}var Dr=(e=0)=>(t)=>`\x1B[${t+e}m`,yr=(e=0)=>(t)=>`\x1B[${38+e};5;${t}m`,wr=(e=0)=>(t,n,i)=>`\x1B[${38+e};2;${t};${n};${i}m`,se={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]}},Wd=Object.keys(se.modifier),iu=Object.keys(se.color),ru=Object.keys(se.bgColor),Ud=[...iu,...ru];function ou(){let e=new Map;for(let[t,n]of Object.entries(se)){for(let[i,s]of Object.entries(n))se[i]={open:`\x1B[${s[0]}m`,close:`\x1B[${s[1]}m`},n[i]=se[i],e.set(s[0],s[1]);Object.defineProperty(se,t,{value:n,enumerable:!1})}return Object.defineProperty(se,"codes",{value:e,enumerable:!1}),se.color.close="\x1B[39m",se.bgColor.close="\x1B[49m",se.color.ansi=Dr(),se.color.ansi256=yr(),se.color.ansi16m=wr(),se.bgColor.ansi=Dr(10),se.bgColor.ansi256=yr(10),se.bgColor.ansi16m=wr(10),Object.defineProperties(se,{rgbToAnsi256:{value(t,n,i){if(t===n&&n===i){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(i/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[i]=n;if(i.length===3)i=[...i].map((r)=>r+r).join("");let s=Number.parseInt(i,16);return[s>>16&255,s>>8&255,s&255]},enumerable:!1},hexToAnsi256:{value:(t)=>se.rgbToAnsi256(...se.hexToRgb(t)),enumerable:!1},ansi256ToAnsi:{value(t){if(t<8)return 30+t;if(t<16)return 90+(t-8);let n,i,s;if(t>=232)n=((t-232)*10+8)/255,i=n,s=n;else{t-=16;let a=t%36;n=Math.floor(t/36)/5,i=Math.floor(a/6)/5,s=a%6/5}let r=Math.max(n,i,s)*2;if(r===0)return 30;let o=30+(Math.round(s)<<2|Math.round(i)<<1|Math.round(n));if(r===2)o+=60;return o},enumerable:!1},rgbToAnsi:{value:(t,n,i)=>se.ansi256ToAnsi(se.rgbToAnsi256(t,n,i)),enumerable:!1},hexToAnsi:{value:(t)=>se.ansi256ToAnsi(se.hexToAnsi256(t)),enumerable:!1}}),se}var au=ou(),br=au;var xn=new Set(["\x1B","›"]),cu=39,Fs="\x07",Er="[",uu="]",xr="m",En=`${uu}8;;`,Fr=(e)=>`${xn.values().next().value}${Er}${e}${xr}`,Cr=(e)=>`${xn.values().next().value}${En}${e}${Fs}`,lu=(e)=>e.split(" ").map((t)=>Le(t)),bs=(e,t,n)=>{let i=[...t],s=!1,r=!1,o=Le(dt(e.at(-1)));for(let[a,c]of i.entries()){let u=Le(c);if(o+u<=n)e[e.length-1]+=c;else e.push(c),o=0;if(xn.has(c))s=!0,r=i.slice(a+1,a+1+En.length).join("")===En;if(s){if(r){if(c===Fs)s=!1,r=!1}else if(c===xr)s=!1;continue}if(o+=u,o===n&&a<i.length-1)e.push(""),o=0}if(!o&&e.at(-1).length>0&&e.length>1)e[e.length-2]+=e.pop()},fu=(e)=>{let t=e.split(" "),n=t.length;while(n>0){if(Le(t[n-1])>0)break;n--}if(n===t.length)return e;return t.slice(0,n).join(" ")+t.slice(n).join("")},du=(e,t,n={})=>{if(n.trim!==!1&&e.trim()==="")return"";let i="",s,r,o=lu(e),a=[""];for(let[l,d]of e.split(" ").entries()){if(n.trim!==!1)a[a.length-1]=a.at(-1).trimStart();let h=Le(a.at(-1));if(l!==0){if(h>=t&&(n.wordWrap===!1||n.trim===!1))a.push(""),h=0;if(h>0||n.trim===!1)a[a.length-1]+=" ",h++}if(n.hard&&o[l]>t){let m=t-h,p=1+Math.floor((o[l]-m-1)/t);if(Math.floor((o[l]-1)/t)<p)a.push("");bs(a,d,t);continue}if(h+o[l]>t&&h>0&&o[l]>0){if(n.wordWrap===!1&&h<t){bs(a,d,t);continue}a.push("")}if(h+o[l]>t&&n.wordWrap===!1){bs(a,d,t);continue}a[a.length-1]+=d}if(n.trim!==!1)a=a.map((l)=>fu(l));let c=a.join(`
8
+ `),u=[...c],f=0;for(let[l,d]of u.entries()){if(i+=d,xn.has(d)){let{groups:m}=new RegExp(`(?:\\${Er}(?<code>\\d+)m|\\${En}(?<uri>.*)${Fs})`).exec(c.slice(f))||{groups:{}};if(m.code!==void 0){let p=Number.parseFloat(m.code);s=p===cu?void 0:p}else if(m.uri!==void 0)r=m.uri.length===0?void 0:m.uri}let h=br.codes.get(Number(s));if(u[l+1]===`
9
+ `){if(r)i+=Cr("");if(s&&h)i+=Fr(h)}else if(d===`
10
+ `){if(s&&h)i+=Fr(s);if(r)i+=Cr(r)}f+=d.length}return i};function Cs(e,t,n){return String(e).normalize().replaceAll(`\r
11
11
  `,`
12
12
  `).split(`
13
- `).map((B)=>w6(B,F,u)).join(`
14
- `)}function zu(D){return x2(D,{stringWidth:fD,stripAnsi:zF,wrap:$u})}import{dirname as E8,resolve as B8}from"path";import{readdirSync as x6,statSync as I6}from"fs";function Zu(D,F){let u=B8(".",D),B;if(!I6(u).isDirectory())u=E8(u);while(!0){if(B=F(u,x6(u)),B)return B8(u,B);if(u=E8(B=u),B===u)break}}import{inspect as r6}from"util";import{fileURLToPath as O8}from"url";import{format as h6}from"util";import{normalize as v6,resolve as y6}from"path";function ZF(D){if(!(D!==D.toLowerCase()&&D!==D.toUpperCase()))D=D.toLowerCase();if(D.indexOf("-")===-1&&D.indexOf("_")===-1)return D;else{let u="",B=!1,E=D.match(/^-+/);for(let C=E?E[0].length:0;C<D.length;C++){let $=D.charAt(C);if(B)B=!1,$=$.toUpperCase();if(C!==0&&($==="-"||$==="_"))B=!0;else if($!=="-"&&$!=="_")u+=$}return u}}function Q0(D,F){let u=D.toLowerCase();F=F||"-";let B="";for(let E=0;E<D.length;E++){let C=u.charAt(E),$=D.charAt(E);if(C!==$&&E>0)B+=`${F}${u.charAt(E)}`;else B+=$}return B}function X0(D){if(D===null||D===void 0)return!1;if(typeof D==="number")return!0;if(/^0x[0-9a-f]+$/i.test(D))return!0;if(/^0[^.]/.test(D))return!1;return/^[-]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(D)}function C8(D){if(Array.isArray(D))return D.map(($)=>typeof $!=="string"?$+"":$);D=D.trim();let F=0,u=null,B=null,E=null,C=[];for(let $=0;$<D.length;$++){if(u=B,B=D.charAt($),B===" "&&!E){if(u!==" ")F++;continue}if(B===E)E=null;else if((B==="'"||B==='"')&&!E)E=B;if(!C[F])C[F]="";C[F]+=B}return C}var SD;(function(D){D.BOOLEAN="boolean",D.STRING="string",D.NUMBER="number",D.ARRAY="array"})(SD||(SD={}));var tD;class Gu{constructor(D){tD=D}parse(D,F){let u=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},F),B=C8(D),E=typeof D==="string",C=b6(Object.assign(Object.create(null),u.alias)),$=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},u.configuration),z=Object.assign(Object.create(null),u.default),Z=u.configObjects||[],J=u.envPrefix,Q=$["populate--"],G=Q?"--":"_",X=Object.create(null),V=Object.create(null),H=u.__||tD.format,W={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:[]},j=/^-([0-9]+(\.[0-9]+)?|\.[0-9]+)$/,N=new RegExp("^--"+$["negation-prefix"]+"(.+)");if([].concat(u.array||[]).filter(Boolean).forEach(function(q){let K=typeof q==="object"?q.key:q,P=Object.keys(q).map(function(_){return{boolean:"bools",string:"strings",number:"numbers"}[_]}).filter(Boolean).pop();if(P)W[P][K]=!0;W.arrays[K]=!0,W.keys.push(K)}),[].concat(u.boolean||[]).filter(Boolean).forEach(function(q){W.bools[q]=!0,W.keys.push(q)}),[].concat(u.string||[]).filter(Boolean).forEach(function(q){W.strings[q]=!0,W.keys.push(q)}),[].concat(u.number||[]).filter(Boolean).forEach(function(q){W.numbers[q]=!0,W.keys.push(q)}),[].concat(u.count||[]).filter(Boolean).forEach(function(q){W.counts[q]=!0,W.keys.push(q)}),[].concat(u.normalize||[]).filter(Boolean).forEach(function(q){W.normalize[q]=!0,W.keys.push(q)}),typeof u.narg==="object")Object.entries(u.narg).forEach(([q,K])=>{if(typeof K==="number")W.nargs[q]=K,W.keys.push(q)});if(typeof u.coerce==="object")Object.entries(u.coerce).forEach(([q,K])=>{if(typeof K==="function")W.coercions[q]=K,W.keys.push(q)});if(typeof u.config<"u"){if(Array.isArray(u.config)||typeof u.config==="string")[].concat(u.config).filter(Boolean).forEach(function(q){W.configs[q]=!0});else if(typeof u.config==="object")Object.entries(u.config).forEach(([q,K])=>{if(typeof K==="boolean"||typeof K==="function")W.configs[q]=K})}RD(u.key,C,u.default,W.arrays),Object.keys(z).forEach(function(q){(W.aliases[q]||[]).forEach(function(K){z[K]=z[q]})});let O=null;Fu();let T=[],M=Object.assign(Object.create(null),{_:[]}),R={};for(let q=0;q<B.length;q++){let K=B[q],P=K.replace(/^-{3,}/,"---"),_,U,v,x,g,YD;if(K!=="--"&&/^-/.test(K)&&e(K))I(K);else if(P.match(/^---+(=|$)/)){I(K);continue}else if(K.match(/^--.+=/)||!$["short-option-groups"]&&K.match(/^-.+=/)){if(x=K.match(/^--?([^=]+)=([\s\S]*)$/),x!==null&&Array.isArray(x)&&x.length>=3)if(c(x[1],W.arrays))q=l(q,x[1],B,x[2]);else if(c(x[1],W.nargs)!==!1)q=y(q,x[1],B,x[2]);else h(x[1],x[2],!0)}else if(K.match(N)&&$["boolean-negation"]){if(x=K.match(N),x!==null&&Array.isArray(x)&&x.length>=2)U=x[1],h(U,c(U,W.arrays)?[!1]:!1)}else if(K.match(/^--.+/)||!$["short-option-groups"]&&K.match(/^-[^-]+/)){if(x=K.match(/^--?(.+)/),x!==null&&Array.isArray(x)&&x.length>=2)if(U=x[1],c(U,W.arrays))q=l(q,U,B);else if(c(U,W.nargs)!==!1)q=y(q,U,B);else if(g=B[q+1],g!==void 0&&(!g.match(/^-/)||g.match(j))&&!c(U,W.bools)&&!c(U,W.counts))h(U,g),q++;else if(/^(true|false)$/.test(g))h(U,g),q++;else h(U,t(U))}else if(K.match(/^-.\..+=/)){if(x=K.match(/^-([^=]+)=([\s\S]*)$/),x!==null&&Array.isArray(x)&&x.length>=3)h(x[1],x[2])}else if(K.match(/^-.\..+/)&&!K.match(j)){if(g=B[q+1],x=K.match(/^-(.\..+)/),x!==null&&Array.isArray(x)&&x.length>=2)if(U=x[1],g!==void 0&&!g.match(/^-/)&&!c(U,W.bools)&&!c(U,W.counts))h(U,g),q++;else h(U,t(U))}else if(K.match(/^-[^-]+/)&&!K.match(j)){v=K.slice(1,-1).split(""),_=!1;for(let UD=0;UD<v.length;UD++){if(g=K.slice(UD+2),v[UD+1]&&v[UD+1]==="="){if(YD=K.slice(UD+3),U=v[UD],c(U,W.arrays))q=l(q,U,B,YD);else if(c(U,W.nargs)!==!1)q=y(q,U,B,YD);else h(U,YD);_=!0;break}if(g==="-"){h(v[UD],g);continue}if(/[A-Za-z]/.test(v[UD])&&/^-?\d+(\.\d*)?(e-?\d+)?$/.test(g)&&c(g,W.bools)===!1){h(v[UD],g),_=!0;break}if(v[UD+1]&&v[UD+1].match(/\W/)){h(v[UD],g),_=!0;break}else h(v[UD],t(v[UD]))}if(U=K.slice(-1)[0],!_&&U!=="-")if(c(U,W.arrays))q=l(q,U,B);else if(c(U,W.nargs)!==!1)q=y(q,U,B);else if(g=B[q+1],g!==void 0&&(!/^(-|--)[^-]/.test(g)||g.match(j))&&!c(U,W.bools)&&!c(U,W.counts))h(U,g),q++;else if(/^(true|false)$/.test(g))h(U,g),q++;else h(U,t(U))}else if(K.match(/^-[0-9]$/)&&K.match(j)&&c(K.slice(1),W.bools))U=K.slice(1),h(U,t(U));else if(K==="--"){T=B.slice(q+1);break}else if($["halt-at-non-option"]){T=B.slice(q);break}else I(K)}if(uD(M,!0),uD(M,!1),S(M),r(),TD(M,W.aliases,z,!0),s(M),$["set-placeholder-key"])ED(M);if(Object.keys(W.counts).forEach(function(q){if(!k(M,q.split(".")))h(q,0)}),Q&&T.length)M[G]=[];if(T.forEach(function(q){M[G].push(q)}),$["camel-case-expansion"]&&$["strip-dashed"])Object.keys(M).filter((q)=>q!=="--"&&q.includes("-")).forEach((q)=>{delete M[q]});if($["strip-aliased"])[].concat(...Object.keys(C).map((q)=>C[q])).forEach((q)=>{if($["camel-case-expansion"]&&q.includes("-"))delete M[q.split(".").map((K)=>ZF(K)).join(".")];delete M[q]});function I(q){let K=A("_",q);if(typeof K==="string"||typeof K==="number")M._.push(K)}function y(q,K,P,_){let U,v=c(K,W.nargs);if(v=typeof v!=="number"||isNaN(v)?1:v,v===0){if(!QD(_))O=Error(H("Argument unexpected for: %s",K));return h(K,t(K)),q}let x=QD(_)?0:1;if($["nargs-eats-options"]){if(P.length-(q+1)+x<v)O=Error(H("Not enough arguments following: %s",K));x=v}else{for(U=q+1;U<P.length;U++)if(!P[U].match(/^-[^0-9]/)||P[U].match(j)||e(P[U]))x++;else break;if(x<v)O=Error(H("Not enough arguments following: %s",K))}let g=Math.min(x,v);if(!QD(_)&&g>0)h(K,_),g--;for(U=q+1;U<g+q+1;U++)h(K,P[U]);return q+g}function l(q,K,P,_){let U=[],v=_||P[q+1],x=c(K,W.nargs);if(c(K,W.bools)&&!/^(true|false)$/.test(v))U.push(!0);else if(QD(v)||QD(_)&&/^-/.test(v)&&!j.test(v)&&!e(v)){if(z[K]!==void 0){let g=z[K];U=Array.isArray(g)?g:[g]}}else{if(!QD(_))U.push(L(K,_,!0));for(let g=q+1;g<P.length;g++){if(!$["greedy-arrays"]&&U.length>0||x&&typeof x==="number"&&U.length>=x)break;if(v=P[g],/^-/.test(v)&&!j.test(v)&&!e(v))break;q=g,U.push(L(K,v,E))}}if(typeof x==="number"&&(x&&U.length<x||isNaN(x)&&U.length===0))O=Error(H("Not enough arguments following: %s",K));return h(K,U),q}function h(q,K,P=E){if(/-/.test(q)&&$["camel-case-expansion"]){let v=q.split(".").map(function(x){return ZF(x)}).join(".");a(q,v)}let _=L(q,K,P),U=q.split(".");if(BD(M,U,_),W.aliases[q])W.aliases[q].forEach(function(v){let x=v.split(".");BD(M,x,_)});if(U.length>1&&$["dot-notation"])(W.aliases[U[0]]||[]).forEach(function(v){let x=v.split("."),g=[].concat(U);if(g.shift(),x=x.concat(g),!(W.aliases[q]||[]).includes(x.join(".")))BD(M,x,_)});if(c(q,W.normalize)&&!c(q,W.arrays))[q].concat(W.aliases[q]||[]).forEach(function(x){Object.defineProperty(R,x,{enumerable:!0,get(){return K},set(g){K=typeof g==="string"?tD.normalize(g):g}})})}function a(q,K){if(!(W.aliases[q]&&W.aliases[q].length))W.aliases[q]=[K],X[K]=!0;if(!(W.aliases[K]&&W.aliases[K].length))a(K,q)}function L(q,K,P){if(P)K=f6(K);if(c(q,W.bools)||c(q,W.counts)){if(typeof K==="string")K=K==="true"}let _=Array.isArray(K)?K.map(function(U){return A(q,U)}):A(q,K);if(c(q,W.counts)&&(QD(_)||typeof _==="boolean"))_=Ju();if(c(q,W.normalize)&&c(q,W.arrays))if(Array.isArray(K))_=K.map((U)=>{return tD.normalize(U)});else _=tD.normalize(K);return _}function A(q,K){if(!$["parse-positional-numbers"]&&q==="_")return K;if(!c(q,W.strings)&&!c(q,W.bools)&&!Array.isArray(K)){if(X0(K)&&$["parse-numbers"]&&Number.isSafeInteger(Math.floor(parseFloat(`${K}`)))||!QD(K)&&c(q,W.numbers))K=Number(K)}return K}function S(q){let K=Object.create(null);TD(K,W.aliases,z),Object.keys(W.configs).forEach(function(P){let _=q[P]||K[P];if(_)try{let U=null,v=tD.resolve(tD.cwd(),_),x=W.configs[P];if(typeof x==="function"){try{U=x(v)}catch(g){U=g}if(U instanceof Error){O=U;return}}else U=tD.require(v);p(U)}catch(U){if(U.name==="PermissionDenied")O=U;else if(q[P])O=Error(H("Invalid JSON config file: %s",_))}})}function p(q,K){Object.keys(q).forEach(function(P){let _=q[P],U=K?K+"."+P:P;if(typeof _==="object"&&_!==null&&!Array.isArray(_)&&$["dot-notation"])p(_,U);else if(!k(M,U.split("."))||c(U,W.arrays)&&$["combine-arrays"])h(U,_)})}function r(){if(typeof Z<"u")Z.forEach(function(q){p(q)})}function uD(q,K){if(typeof J>"u")return;let P=typeof J==="string"?J:"",_=tD.env();Object.keys(_).forEach(function(U){if(P===""||U.lastIndexOf(P,0)===0){let v=U.split("__").map(function(x,g){if(g===0)x=x.substring(P.length);return ZF(x)});if((K&&W.configs[v.join(".")]||!K)&&!k(q,v))h(v.join("."),_[U])}})}function s(q){let K,P=new Set;Object.keys(q).forEach(function(_){if(!P.has(_)){if(K=c(_,W.coercions),typeof K==="function")try{let U=A(_,K(q[_]));[].concat(W.aliases[_]||[],_).forEach((v)=>{P.add(v),q[v]=U})}catch(U){O=U}}})}function ED(q){return W.keys.forEach((K)=>{if(~K.indexOf("."))return;if(typeof q[K]>"u")q[K]=void 0}),q}function TD(q,K,P,_=!1){Object.keys(P).forEach(function(U){if(!k(q,U.split("."))){if(BD(q,U.split("."),P[U]),_)V[U]=!0;(K[U]||[]).forEach(function(v){if(k(q,v.split(".")))return;BD(q,v.split("."),P[U])})}})}function k(q,K){let P=q;if(!$["dot-notation"])K=[K.join(".")];K.slice(0,-1).forEach(function(U){P=P[U]||{}});let _=K[K.length-1];if(typeof P!=="object")return!1;else return _ in P}function BD(q,K,P){let _=q;if(!$["dot-notation"])K=[K.join(".")];K.slice(0,-1).forEach(function(YD){if(YD=$8(YD),typeof _==="object"&&_[YD]===void 0)_[YD]={};if(typeof _[YD]!=="object"||Array.isArray(_[YD])){if(Array.isArray(_[YD]))_[YD].push({});else _[YD]=[_[YD],{}];_=_[YD][_[YD].length-1]}else _=_[YD]});let U=$8(K[K.length-1]),v=c(K.join("."),W.arrays),x=Array.isArray(P),g=$["duplicate-arguments-array"];if(!g&&c(U,W.nargs)){if(g=!0,!QD(_[U])&&W.nargs[U]===1||Array.isArray(_[U])&&_[U].length===W.nargs[U])_[U]=void 0}if(P===Ju())_[U]=Ju(_[U]);else if(Array.isArray(_[U]))if(g&&v&&x)_[U]=$["flatten-duplicate-arrays"]?_[U].concat(P):(Array.isArray(_[U][0])?_[U]:[_[U]]).concat([P]);else if(!g&&Boolean(v)===Boolean(x))_[U]=P;else _[U]=_[U].concat([P]);else if(_[U]===void 0&&v)_[U]=x?P:[P];else if(g&&!(_[U]===void 0||c(U,W.counts)||c(U,W.bools)))_[U]=[_[U],P];else _[U]=P}function RD(...q){q.forEach(function(K){Object.keys(K||{}).forEach(function(P){if(W.aliases[P])return;W.aliases[P]=[].concat(C[P]||[]),W.aliases[P].concat(P).forEach(function(_){if(/-/.test(_)&&$["camel-case-expansion"]){let U=ZF(_);if(U!==P&&W.aliases[P].indexOf(U)===-1)W.aliases[P].push(U),X[U]=!0}}),W.aliases[P].concat(P).forEach(function(_){if(_.length>1&&/[A-Z]/.test(_)&&$["camel-case-expansion"]){let U=Q0(_,"-");if(U!==P&&W.aliases[P].indexOf(U)===-1)W.aliases[P].push(U),X[U]=!0}}),W.aliases[P].forEach(function(_){W.aliases[_]=[P].concat(W.aliases[P].filter(function(U){return _!==U}))})})})}function c(q,K){let P=[].concat(W.aliases[q]||[],q),_=Object.keys(K),U=P.find((v)=>_.includes(v));return U?K[U]:!1}function SF(q){let K=Object.keys(W);return[].concat(K.map((_)=>W[_])).some(function(_){return Array.isArray(_)?_.includes(q):_[q]})}function A2(q,...K){return[].concat(...K).some(function(_){let U=q.match(_);return U&&SF(U[1])})}function d(q){if(q.match(j)||!q.match(/^-[^-]+/))return!1;let K=!0,P,_=q.slice(1).split("");for(let U=0;U<_.length;U++){if(P=q.slice(U+2),!SF(_[U])){K=!1;break}if(_[U+1]&&_[U+1]==="="||P==="-"||/[A-Za-z]/.test(_[U])&&/^-?\d+(\.\d*)?(e-?\d+)?$/.test(P)||_[U+1]&&_[U+1].match(/\W/))break}return K}function e(q){return $["unknown-options-as-args"]&&GD(q)}function GD(q){if(q=q.replace(/^-{3,}/,"--"),q.match(j))return!1;if(d(q))return!1;return!A2(q,/^-+([^=]+?)=[\s\S]*$/,N,/^-+([^=]+?)$/,/^-+([^=]+?)-$/,/^-+([^=]+?\d+)$/,/^-+([^=]+?)\W+.*$/)}function t(q){if(!c(q,W.bools)&&!c(q,W.counts)&&`${q}`in z)return z[q];else return HD(zD(q))}function HD(q){return{[SD.BOOLEAN]:!0,[SD.STRING]:"",[SD.NUMBER]:void 0,[SD.ARRAY]:[]}[q]}function zD(q){let K=SD.BOOLEAN;if(c(q,W.strings))K=SD.STRING;else if(c(q,W.numbers))K=SD.NUMBER;else if(c(q,W.bools))K=SD.BOOLEAN;else if(c(q,W.arrays))K=SD.ARRAY;return K}function QD(q){return q===void 0}function Fu(){Object.keys(W.counts).find((q)=>{if(c(q,W.arrays))return O=Error(H("Invalid configuration: %s, opts.count excludes opts.array.",q)),!0;else if(c(q,W.nargs))return O=Error(H("Invalid configuration: %s, opts.count excludes opts.narg.",q)),!0;return!1})}return{aliases:Object.assign({},W.aliases),argv:Object.assign(R,M),configuration:$,defaulted:Object.assign({},V),error:O,newAliases:Object.assign({},X)}}}function b6(D){let F=[],u=Object.create(null),B=!0;Object.keys(D).forEach(function(E){F.push([].concat(D[E],E))});while(B){B=!1;for(let E=0;E<F.length;E++)for(let C=E+1;C<F.length;C++)if(F[E].filter(function(z){return F[C].indexOf(z)!==-1}).length){F[E]=F[E].concat(F[C]),F.splice(C,1),B=!0;break}}return F.forEach(function(E){E=E.filter(function($,z,Z){return Z.indexOf($)===z});let C=E.pop();if(C!==void 0&&typeof C==="string")u[C]=E}),u}function Ju(D){return D!==void 0?D+1:1}function $8(D){if(D==="__proto__")return"___proto___";return D}function f6(D){return typeof D==="string"&&(D[0]==="'"||D[0]==='"')&&D[D.length-1]===D[0]?D.substring(1,D.length-1):D}import{readFileSync as p6}from"fs";import{createRequire as z8}from"node:module";var Qu,Xu,Yu,Z8=process&&process.env&&process.env.YARGS_MIN_NODE_VERSION?Number(process.env.YARGS_MIN_NODE_VERSION):20,J8=(Xu=(Qu=process===null||process===void 0?void 0:process.versions)===null||Qu===void 0?void 0:Qu.node)!==null&&Xu!==void 0?Xu:(Yu=process===null||process===void 0?void 0:process.version)===null||Yu===void 0?void 0:Yu.slice(1);if(J8){if(Number(J8.match(/^([^.]+)/)[1])<Z8)throw Error(`yargs parser supports a minimum Node.js version of ${Z8}. Read our version support policy: https://github.com/yargs/yargs-parser#supported-nodejs-versions`)}var m6=process?process.env:{},G8=z8?z8(import.meta.url):void 0,Q8=new Gu({cwd:process.cwd,env:()=>{return m6},format:h6,normalize:v6,resolve:y6,require:(D)=>{if(typeof G8<"u")return G8(D);else if(D.match(/\.json$/))return JSON.parse(p6(D,"utf8"));else throw Error("only .json config files are supported in ESM")}}),dF=function(F,u){return Q8.parse(F.slice(),u).argv};dF.detailed=function(D,F){return Q8.parse(D.slice(),F)};dF.camelCase=ZF;dF.decamelize=Q0;dF.looksLikeNumber=X0;var Wu=dF;import{basename as a6,dirname as e6,extname as D7,relative as F7,resolve as K8,join as u7}from"path";function X8(){if(g6())return 0;return 1}function g6(){return c6()&&!process.defaultApp}function c6(){return!!process.versions.electron}function Vu(D){return D.slice(X8()+1)}function Y8(){return process.argv[X8()]}import{readFileSync as k6,statSync as d6,writeFile as i6}from"fs";import{format as l6}from"util";import{resolve as n6}from"path";var W8={fs:{readFileSync:k6,writeFile:i6},format:l6,resolve:n6,exists:(D)=>{try{return d6(D).isFile()}catch(F){return!1}}};var hD;class V8{constructor(D){D=D||{},this.directory=D.directory||"./locales",this.updateFiles=typeof D.updateFiles==="boolean"?D.updateFiles:!0,this.locale=D.locale||"en",this.fallbackToLanguage=typeof D.fallbackToLanguage==="boolean"?D.fallbackToLanguage:!0,this.cache=Object.create(null),this.writeQueue=[]}__(...D){if(typeof arguments[0]!=="string")return this._taggedLiteral(arguments[0],...arguments);let F=D.shift(),u=function(){};if(typeof D[D.length-1]==="function")u=D.pop();if(u=u||function(){},!this.cache[this.locale])this._readLocaleFile();if(!this.cache[this.locale][F]&&this.updateFiles)this.cache[this.locale][F]=F,this._enqueueWrite({directory:this.directory,locale:this.locale,cb:u});else u();return hD.format.apply(hD.format,[this.cache[this.locale][F]||F].concat(D))}__n(){let D=Array.prototype.slice.call(arguments),F=D.shift(),u=D.shift(),B=D.shift(),E=function(){};if(typeof D[D.length-1]==="function")E=D.pop();if(!this.cache[this.locale])this._readLocaleFile();let C=B===1?F:u;if(this.cache[this.locale][F])C=this.cache[this.locale][F][B===1?"one":"other"];if(!this.cache[this.locale][F]&&this.updateFiles)this.cache[this.locale][F]={one:F,other:u},this._enqueueWrite({directory:this.directory,locale:this.locale,cb:E});else E();let $=[C];if(~C.indexOf("%d"))$.push(B);return hD.format.apply(hD.format,$.concat(D))}setLocale(D){this.locale=D}getLocale(){return this.locale}updateLocale(D){if(!this.cache[this.locale])this._readLocaleFile();for(let F in D)if(Object.prototype.hasOwnProperty.call(D,F))this.cache[this.locale][F]=D[F]}_taggedLiteral(D,...F){let u="";return D.forEach(function(B,E){let C=F[E+1];if(u+=B,typeof C<"u")u+="%s"}),this.__.apply(this,[u].concat([].slice.call(F,1)))}_enqueueWrite(D){if(this.writeQueue.push(D),this.writeQueue.length===1)this._processWriteQueue()}_processWriteQueue(){let D=this,F=this.writeQueue[0],u=F.directory,B=F.locale,E=F.cb,C=this._resolveLocaleFile(u,B),$=JSON.stringify(this.cache[B],null,2);hD.fs.writeFile(C,$,"utf-8",function(z){if(D.writeQueue.shift(),D.writeQueue.length>0)D._processWriteQueue();E(z)})}_readLocaleFile(){let D={},F=this._resolveLocaleFile(this.directory,this.locale);try{if(hD.fs.readFileSync)D=JSON.parse(hD.fs.readFileSync(F,"utf-8"))}catch(u){if(u instanceof SyntaxError)u.message="syntax error in "+F;if(u.code==="ENOENT")D={};else throw u}this.cache[this.locale]=D}_resolveLocaleFile(D,F){let u=hD.resolve(D,"./",F+".json");if(this.fallbackToLanguage&&!this._fileExistsSync(u)&&~F.lastIndexOf("_")){let B=hD.resolve(D,"./",F.split("_")[0]+".json");if(this._fileExistsSync(B))u=B}return u}_fileExistsSync(D){return hD.exists(D)}}function H8(D,F){hD=F;let u=new V8(D);return{__:u.__.bind(u),__n:u.__n.bind(u),setLocale:u.setLocale.bind(u),getLocale:u.getLocale.bind(u),updateLocale:u.updateLocale.bind(u),locale:u.locale}}var t6=(D)=>{return H8(D,W8)},q8=t6;var M8=T2(U8(),1);import{createRequire as E7}from"node:module";import{readFileSync as B7,readdirSync as C7}from"node:fs";var Hu=O8(import.meta.url),$7=Hu.substring(0,Hu.lastIndexOf("node_modules")),z7=E7(import.meta.url),qu={assert:{notStrictEqual:o6,strictEqual:s6},cliui:zu,findUp:Zu,getEnv:(D)=>{return process.env[D]},inspect:r6,getProcessArgvBin:Y8,mainFilename:$7||process.cwd(),Parser:Wu,path:{basename:a6,dirname:e6,extname:D7,relative:F7,resolve:K8,join:u7},process:{argv:()=>process.argv,cwd:process.cwd,emitWarning:(D,F)=>process.emitWarning(D,F),execPath:()=>process.execPath,exit:(D)=>{process.exit(D)},nextTick:process.nextTick,stdColumns:typeof process.stdout.columns<"u"?process.stdout.columns:null},readFileSync:B7,readdirSync:C7,require:z7,getCallerFile:()=>{let D=M8.default(3);return D.match(/^file:\/\//)?O8(D):D},stringWidth:fD,y18n:q8({directory:K8(Hu,"../../../locales"),updateFiles:!1})};function KD(D,F,u,B){u.assert.notStrictEqual(D,F,B)}function ju(D,F){F.assert.strictEqual(typeof D,"string")}function wF(D){return Object.keys(D)}function DD(D){return!!D&&!!D.then&&typeof D.then==="function"}class ZD extends Error{constructor(D){super(D||"yargs error");if(this.name="YError",Error.captureStackTrace)Error.captureStackTrace(this,ZD)}}function sD(D){let u=D.replace(/\s{2,}/g," ").split(/\s+(?![^[]*]|[^<]*>)/),B=/\.*[\][<>]/g,E=u.shift();if(!E)throw Error(`No command found in: ${D}`);let C={cmd:E.replace(B,""),demanded:[],optional:[]};return u.forEach(($,z)=>{let Z=!1;if($=$.replace(/\s/g,""),/\.+[\]>]/.test($)&&z===u.length-1)Z=!0;if(/^\[/.test($))C.optional.push({cmd:$.replace(B,"").split("|"),variadic:Z});else C.demanded.push({cmd:$.replace(B,"").split("|"),variadic:Z})}),C}var Z7=["first","second","third","fourth","fifth","sixth"];function b(D,F,u){function B(){return typeof D==="object"?[{demanded:[],optional:[]},D,F]:[sD(`cmd ${D}`),F,u]}try{let E=0,[C,$,z]=B(),Z=[].slice.call($);while(Z.length&&Z[Z.length-1]===void 0)Z.pop();let J=z||Z.length;if(J<C.demanded.length)throw new ZD(`Not enough arguments provided. Expected ${C.demanded.length} but received ${Z.length}.`);let Q=C.demanded.length+C.optional.length;if(J>Q)throw new ZD(`Too many arguments provided. Expected max ${Q} but received ${J}.`);C.demanded.forEach((G)=>{let X=Z.shift(),V=_8(X);if(G.cmd.filter((W)=>W===V||W==="*").length===0)N8(V,G.cmd,E);E+=1}),C.optional.forEach((G)=>{if(Z.length===0)return;let X=Z.shift(),V=_8(X);if(G.cmd.filter((W)=>W===V||W==="*").length===0)N8(V,G.cmd,E);E+=1})}catch(E){console.warn(E.stack)}}function _8(D){if(Array.isArray(D))return"array";else if(D===null)return"null";return typeof D}function N8(D,F,u){throw new ZD(`Invalid ${Z7[u]||"manyith"} argument. Expected ${F.join(" or ")} but received ${D}.`)}class Uu{constructor(D){this.globalMiddleware=[],this.frozens=[],this.yargs=D}addMiddleware(D,F,u=!0,B=!1){if(b("<array|function> [boolean] [boolean] [boolean]",[D,F,u],arguments.length),Array.isArray(D)){for(let E=0;E<D.length;E++){if(typeof D[E]!=="function")throw Error("middleware must be a function");let C=D[E];C.applyBeforeValidation=F,C.global=u}Array.prototype.push.apply(this.globalMiddleware,D)}else if(typeof D==="function"){let E=D;E.applyBeforeValidation=F,E.global=u,E.mutates=B,this.globalMiddleware.push(D)}return this.yargs}addCoerceMiddleware(D,F){let u=this.yargs.getAliases();return this.globalMiddleware=this.globalMiddleware.filter((B)=>{let E=[...u[F]||[],F];if(!B.option)return!0;else return!E.includes(B.option)}),D.option=F,this.addMiddleware(D,!0,!0,!0)}getMiddleware(){return this.globalMiddleware}freeze(){this.frozens.push([...this.globalMiddleware])}unfreeze(){let D=this.frozens.pop();if(D!==void 0)this.globalMiddleware=D}reset(){this.globalMiddleware=this.globalMiddleware.filter((D)=>D.global)}}function L8(D){if(!D)return[];return D.map((F)=>{return F.applyBeforeValidation=!1,F})}function JF(D,F,u,B){return u.reduce((E,C)=>{if(C.applyBeforeValidation!==B)return E;if(C.mutates){if(C.applied)return E;C.applied=!0}if(DD(E))return E.then(($)=>Promise.all([$,C($,F)])).then(([$,z])=>Object.assign($,z));else{let $=C(E,F);return DD($)?$.then((z)=>Object.assign(E,z)):Object.assign(E,$)}},D)}function GF(D,F,u=(B)=>{throw B}){try{let B=J7(D)?D():D;return DD(B)?B.then((E)=>F(E)):F(B)}catch(B){return u(B)}}function J7(D){return typeof D==="function"}var xF=/(^\*)|(^\$0)/;class P8{constructor(D,F,u,B){this.requireCache=new Set,this.handlers={},this.aliasMap={},this.frozens=[],this.shim=B,this.usage=D,this.globalMiddleware=u,this.validation=F}addDirectory(D,F,u,B){B=B||{},this.requireCache.add(u);let E=this.shim.path.resolve(this.shim.path.dirname(u),D),C=this.shim.readdirSync(E,{recursive:B.recurse?!0:!1});if(!Array.isArray(B.extensions))B.extensions=["js"];let $=typeof B.visit==="function"?B.visit:(z)=>z;for(let z of C){let Z=z.toString();if(B.exclude){let Q=!1;if(typeof B.exclude==="function")Q=B.exclude(Z);else Q=B.exclude.test(Z);if(Q)continue}if(B.include){let Q=!1;if(typeof B.include==="function")Q=B.include(Z);else Q=B.include.test(Z);if(!Q)continue}let J=!1;for(let Q of B.extensions)if(Z.endsWith(Q))J=!0;if(J){let Q=this.shim.path.join(E,Z),G=F(Q),X=Object.create(null,Object.getOwnPropertyDescriptors({...G}));if($(X,Q,Z)){if(this.requireCache.has(Q))continue;else this.requireCache.add(Q);if(!X.command)X.command=this.shim.path.basename(Q,this.shim.path.extname(Q));this.addHandler(X)}}}}addHandler(D,F,u,B,E,C){let $=[],z=L8(E);if(B=B||(()=>{}),Array.isArray(D))if(G7(D))[D,...$]=D;else for(let Z of D)this.addHandler(Z);else if(X7(D)){let Z=Array.isArray(D.command)||typeof D.command==="string"?D.command:null;if(Z===null)throw Error(`No command name given for module: ${this.shim.inspect(D)}`);if(D.aliases)Z=[].concat(Z).concat(D.aliases);this.addHandler(Z,this.extractDesc(D),D.builder,D.handler,D.middlewares,D.deprecated);return}else if(A8(u)){this.addHandler([D].concat($),F,u.builder,u.handler,u.middlewares,u.deprecated);return}if(typeof D==="string"){let Z=sD(D);$=$.map((G)=>sD(G).cmd);let J=!1,Q=[Z.cmd].concat($).filter((G)=>{if(xF.test(G))return J=!0,!1;return!0});if(Q.length===0&&J)Q.push("$0");if(J)Z.cmd=Q[0],$=Q.slice(1),D=D.replace(xF,Z.cmd);if($.forEach((G)=>{this.aliasMap[G]=Z.cmd}),F!==!1)this.usage.command(D,F,J,$,C);if(this.handlers[Z.cmd]={original:D,description:F,handler:B,builder:u||{},middlewares:z,deprecated:C,demanded:Z.demanded,optional:Z.optional},J)this.defaultCommand=this.handlers[Z.cmd]}}getCommandHandlers(){return this.handlers}getCommands(){return Object.keys(this.handlers).concat(Object.keys(this.aliasMap))}hasDefaultCommand(){return!!this.defaultCommand}runCommand(D,F,u,B,E,C){let $=this.handlers[D]||this.handlers[this.aliasMap[D]]||this.defaultCommand,z=F.getInternalMethods().getContext(),Z=z.commands.slice(),J=!D;if(D)z.commands.push(D),z.fullCommands.push($.original);let Q=this.applyBuilderUpdateUsageAndParse(J,$,F,u.aliases,Z,B,E,C);return DD(Q)?Q.then((G)=>this.applyMiddlewareAndGetResult(J,$,G.innerArgv,z,E,G.aliases,F)):this.applyMiddlewareAndGetResult(J,$,Q.innerArgv,z,E,Q.aliases,F)}applyBuilderUpdateUsageAndParse(D,F,u,B,E,C,$,z){let Z=F.builder,J=u;if(Y0(Z)){u.getInternalMethods().getUsageInstance().freeze();let Q=Z(u.getInternalMethods().reset(B),z);if(DD(Q))return Q.then((G)=>{return J=R8(G)?G:u,this.parseAndUpdateUsage(D,F,J,E,C,$)})}else if(Q7(Z))u.getInternalMethods().getUsageInstance().freeze(),J=u.getInternalMethods().reset(B),Object.keys(F.builder).forEach((Q)=>{J.option(Q,Z[Q])});return this.parseAndUpdateUsage(D,F,J,E,C,$)}parseAndUpdateUsage(D,F,u,B,E,C){if(D)u.getInternalMethods().getUsageInstance().unfreeze(!0);if(this.shouldUpdateUsage(u))u.getInternalMethods().getUsageInstance().usage(this.usageFromParentCommandsCommandHandler(B,F),F.description);let $=u.getInternalMethods().runYargsParserAndExecuteCommands(null,void 0,!0,E,C);return DD($)?$.then((z)=>({aliases:u.parsed.aliases,innerArgv:z})):{aliases:u.parsed.aliases,innerArgv:$}}shouldUpdateUsage(D){return!D.getInternalMethods().getUsageInstance().getUsageDisabled()&&D.getInternalMethods().getUsageInstance().getUsage().length===0}usageFromParentCommandsCommandHandler(D,F){let u=xF.test(F.original)?F.original.replace(xF,"").trim():F.original,B=D.filter((E)=>{return!xF.test(E)});return B.push(u),`$0 ${B.join(" ")}`}handleValidationAndGetResult(D,F,u,B,E,C,$,z){if(!C.getInternalMethods().getHasOutput()){let Z=C.getInternalMethods().runValidation(E,z,C.parsed.error,D);u=GF(u,(J)=>{return Z(J),J})}if(F.handler&&!C.getInternalMethods().getHasOutput()){C.getInternalMethods().setHasOutput();let Z=!!C.getOptions().configuration["populate--"];if(C.getInternalMethods().postProcess(u,Z,!1,!1),u=JF(u,C,$,!1),u=GF(u,(J)=>{let Q=F.handler(J);return DD(Q)?Q.then(()=>J):J}),!D)C.getInternalMethods().getUsageInstance().cacheHelpMessage();if(DD(u)&&!C.getInternalMethods().hasParseCallback())u.catch((J)=>{try{C.getInternalMethods().getUsageInstance().fail(null,J)}catch(Q){}})}if(!D)B.commands.pop(),B.fullCommands.pop();return u}applyMiddlewareAndGetResult(D,F,u,B,E,C,$){let z={};if(E)return u;if(!$.getInternalMethods().getHasOutput())z=this.populatePositionals(F,u,B,$);let Z=this.globalMiddleware.getMiddleware().slice(0).concat(F.middlewares),J=JF(u,$,Z,!0);return DD(J)?J.then((Q)=>this.handleValidationAndGetResult(D,F,Q,B,C,$,Z,z)):this.handleValidationAndGetResult(D,F,J,B,C,$,Z,z)}populatePositionals(D,F,u,B){F._=F._.slice(u.commands.length);let E=D.demanded.slice(0),C=D.optional.slice(0),$={};this.validation.positionalCount(E.length,F._.length);while(E.length){let z=E.shift();this.populatePositional(z,F,$)}while(C.length){let z=C.shift();this.populatePositional(z,F,$)}return F._=u.commands.concat(F._.map((z)=>""+z)),this.postProcessPositionals(F,$,this.cmdToParseOptions(D.original),B),$}populatePositional(D,F,u){let B=D.cmd[0];if(D.variadic)u[B]=F._.splice(0).map(String);else if(F._.length)u[B]=[String(F._.shift())]}cmdToParseOptions(D){let F={array:[],default:{},alias:{},demand:{}},u=sD(D);return u.demanded.forEach((B)=>{let[E,...C]=B.cmd;if(B.variadic)F.array.push(E),F.default[E]=[];F.alias[E]=C,F.demand[E]=!0}),u.optional.forEach((B)=>{let[E,...C]=B.cmd;if(B.variadic)F.array.push(E),F.default[E]=[];F.alias[E]=C}),F}postProcessPositionals(D,F,u,B){let E=Object.assign({},B.getOptions());E.default=Object.assign(u.default,E.default);for(let Z of Object.keys(u.alias))E.alias[Z]=(E.alias[Z]||[]).concat(u.alias[Z]);E.array=E.array.concat(u.array),E.config={};let C=[];if(Object.keys(F).forEach((Z)=>{F[Z].map((J)=>{if(E.configuration["unknown-options-as-args"])E.key[Z]=!0;C.push(`--${Z}`),C.push(J)})}),!C.length)return;let $=Object.assign({},E.configuration,{"populate--":!1}),z=this.shim.Parser.detailed(C,Object.assign({},E,{configuration:$}));if(z.error)B.getInternalMethods().getUsageInstance().fail(z.error.message,z.error);else{let Z=Object.keys(F);Object.keys(F).forEach((J)=>{Z.push(...z.aliases[J])}),Object.keys(z.argv).forEach((J)=>{if(Z.includes(J)){if(!F[J])F[J]=z.argv[J];if(!this.isInConfigs(B,J)&&!this.isDefaulted(B,J)&&Object.prototype.hasOwnProperty.call(D,J)&&Object.prototype.hasOwnProperty.call(z.argv,J)&&(Array.isArray(D[J])||Array.isArray(z.argv[J])))D[J]=[].concat(D[J],z.argv[J]);else D[J]=z.argv[J]}})}}isDefaulted(D,F){let{default:u}=D.getOptions();return Object.prototype.hasOwnProperty.call(u,F)||Object.prototype.hasOwnProperty.call(u,this.shim.Parser.camelCase(F))}isInConfigs(D,F){let{configObjects:u}=D.getOptions();return u.some((B)=>Object.prototype.hasOwnProperty.call(B,F))||u.some((B)=>Object.prototype.hasOwnProperty.call(B,this.shim.Parser.camelCase(F)))}runDefaultBuilderOn(D){if(!this.defaultCommand)return;if(this.shouldUpdateUsage(D)){let u=xF.test(this.defaultCommand.original)?this.defaultCommand.original:this.defaultCommand.original.replace(/^[^[\]<>]*/,"$0 ");D.getInternalMethods().getUsageInstance().usage(u,this.defaultCommand.description)}let F=this.defaultCommand.builder;if(Y0(F))return F(D,!0);else if(!A8(F))Object.keys(F).forEach((u)=>{D.option(u,F[u])});return}extractDesc({describe:D,description:F,desc:u}){for(let B of[D,F,u]){if(typeof B==="string"||B===!1)return B;KD(B,!0,this.shim)}return!1}freeze(){this.frozens.push({handlers:this.handlers,aliasMap:this.aliasMap,defaultCommand:this.defaultCommand})}unfreeze(){let D=this.frozens.pop();KD(D,void 0,this.shim),{handlers:this.handlers,aliasMap:this.aliasMap,defaultCommand:this.defaultCommand}=D}reset(){return this.handlers={},this.aliasMap={},this.defaultCommand=void 0,this.requireCache=new Set,this}}function T8(D,F,u,B){return new P8(D,F,u,B)}function A8(D){return typeof D==="object"&&!!D.builder&&typeof D.handler==="function"}function G7(D){return D.every((F)=>typeof F==="string")}function Y0(D){return typeof D==="function"}function Q7(D){return typeof D==="object"}function X7(D){return typeof D==="object"&&!Array.isArray(D)}function rD(D={},F=()=>!0){let u={};return wF(D).forEach((B)=>{if(F(B,D[B]))u[B]=D[B]}),u}function aD(D){if(typeof process>"u")return;[process.stdout,process.stderr].forEach((F)=>{let u=F;if(u._handle&&u.isTTY&&typeof u._handle.setBlocking==="function")u._handle.setBlocking(D)})}function Y7(D){return typeof D==="boolean"}function w8(D,F){let u=F.y18n.__,B={},E=[];B.failFn=function(A){E.push(A)};let C=null,$=null,z=!0;B.showHelpOnFail=function(A=!0,S){let[p,r]=typeof A==="string"?[!0,A]:[A,S];if(D.getInternalMethods().isGlobalContext())$=r;return C=r,z=p,B};let Z=!1;B.fail=function(A,S){let p=D.getInternalMethods().getLoggerInstance();if(E.length)for(let r=E.length-1;r>=0;--r){let uD=E[r];if(Y7(uD)){if(S)throw S;else if(A)throw Error(A)}else uD(A,S,B)}else{if(D.getExitProcess())aD(!0);if(!Z){if(Z=!0,z)D.showHelp("error"),p.error();if(A||S)p.error(A||S);let r=C||$;if(r){if(A||S)p.error("");p.error(r)}}if(S=S||new ZD(A),D.getExitProcess())return D.exit(1);else if(D.getInternalMethods().hasParseCallback())return D.exit(1,S);else throw S}};let J=[],Q=!1;B.usage=(L,A)=>{if(L===null)return Q=!0,J=[],B;return Q=!1,J.push([L,A||""]),B},B.getUsage=()=>{return J},B.getUsageDisabled=()=>{return Q},B.getPositionalGroupName=()=>{return u("Positionals:")};let G=[];B.example=(L,A)=>{G.push([L,A||""])};let X=[];B.command=function(A,S,p,r,uD=!1){if(p)X=X.map((s)=>{return s[2]=!1,s});X.push([A,S||"",p,r,uD])},B.getCommands=()=>X;let V={};B.describe=function(A,S){if(Array.isArray(A))A.forEach((p)=>{B.describe(p,S)});else if(typeof A==="object")Object.keys(A).forEach((p)=>{B.describe(p,A[p])});else V[A]=S},B.getDescriptions=()=>V;let H=[];B.epilog=(L)=>{H.push(L)};let W=!1,j;B.wrap=(L)=>{W=!0,j=L},B.getWrap=()=>{if(F.getEnv("YARGS_DISABLE_WRAP"))return null;if(!W)j=l(),W=!0;return j};let N="__yargsString__:";B.deferY18nLookup=(L)=>N+L,B.help=function(){if(M)return M;T();let A=D.customScriptName?D.$0:F.path.basename(D.$0),S=D.getDemandedOptions(),p=D.getDemandedCommands(),r=D.getDeprecatedOptions(),uD=D.getGroups(),s=D.getOptions(),ED=[];ED=ED.concat(Object.keys(V)),ED=ED.concat(Object.keys(S)),ED=ED.concat(Object.keys(p)),ED=ED.concat(Object.keys(s.default)),ED=ED.filter(I),ED=Object.keys(ED.reduce((d,e)=>{if(e!=="_")d[e]=!0;return d},{}));let TD=B.getWrap(),k=F.cliui({width:TD,wrap:!!TD});if(!Q){if(J.length)J.forEach((d)=>{if(k.div({text:`${d[0].replace(/\$0/g,A)}`}),d[1])k.div({text:`${d[1]}`,padding:[1,0,0,0]})}),k.div();else if(X.length){let d=null;if(p._)d=`${A} <${u("command")}>
15
- `;else d=`${A} [${u("command")}]
16
- `;k.div(`${d}`)}}if(X.length>1||X.length===1&&!X[0][2]){k.div(u("Commands:"));let d=D.getInternalMethods().getContext(),e=d.commands.length?`${d.commands.join(" ")} `:"";if(D.getInternalMethods().getParserConfiguration()["sort-commands"]===!0)X=X.sort((t,HD)=>t[0].localeCompare(HD[0]));let GD=A?`${A} `:"";X.forEach((t)=>{let HD=`${GD}${e}${t[0].replace(/^\$0 ?/,"")}`;k.span({text:HD,padding:[0,2,0,2],width:O(X,TD,`${A}${e}`)+4},{text:t[1]});let zD=[];if(t[2])zD.push(`[${u("default")}]`);if(t[3]&&t[3].length)zD.push(`[${u("aliases:")} ${t[3].join(", ")}]`);if(t[4])if(typeof t[4]==="string")zD.push(`[${u("deprecated: %s",t[4])}]`);else zD.push(`[${u("deprecated")}]`);if(zD.length)k.div({text:zD.join(" "),padding:[0,0,0,2],align:"right"});else k.div()}),k.div()}let BD=(Object.keys(s.alias)||[]).concat(Object.keys(D.parsed.newAliases)||[]);ED=ED.filter((d)=>!D.parsed.newAliases[d]&&BD.every((e)=>(s.alias[e]||[]).indexOf(d)===-1));let RD=u("Options:");if(!uD[RD])uD[RD]=[];R(ED,s.alias,uD,RD);let c=(d)=>/^--/.test(W0(d)),SF=Object.keys(uD).filter((d)=>uD[d].length>0).map((d)=>{let e=uD[d].filter(I).map((GD)=>{if(BD.includes(GD))return GD;for(let t=0,HD;(HD=BD[t])!==void 0;t++)if((s.alias[HD]||[]).includes(GD))return HD;return GD});return{groupName:d,normalizedKeys:e}}).filter(({normalizedKeys:d})=>d.length>0).map(({groupName:d,normalizedKeys:e})=>{let GD=e.reduce((t,HD)=>{return t[HD]=[HD].concat(s.alias[HD]||[]).map((zD)=>{if(d===B.getPositionalGroupName())return zD;else return(/^[0-9]$/.test(zD)?s.boolean.includes(HD)?"-":"--":zD.length>1?"--":"-")+zD}).sort((zD,QD)=>c(zD)===c(QD)?0:c(zD)?1:-1).join(", "),t},{});return{groupName:d,normalizedKeys:e,switches:GD}});if(SF.filter(({groupName:d})=>d!==B.getPositionalGroupName()).some(({normalizedKeys:d,switches:e})=>!d.every((GD)=>c(e[GD]))))SF.filter(({groupName:d})=>d!==B.getPositionalGroupName()).forEach(({normalizedKeys:d,switches:e})=>{d.forEach((GD)=>{if(c(e[GD]))e[GD]=W7(e[GD],4)})});if(SF.forEach(({groupName:d,normalizedKeys:e,switches:GD})=>{k.div(d),e.forEach((t)=>{let HD=GD[t],zD=V[t]||"",QD=null;if(zD.includes(N))zD=u(zD.substring(N.length));if(s.boolean.includes(t))QD=`[${u("boolean")}]`;if(s.count.includes(t))QD=`[${u("count")}]`;if(s.string.includes(t))QD=`[${u("string")}]`;if(s.normalize.includes(t))QD=`[${u("string")}]`;if(s.array.includes(t))QD=`[${u("array")}]`;if(s.number.includes(t))QD=`[${u("number")}]`;let Fu=(P)=>typeof P==="string"?`[${u("deprecated: %s",P)}]`:`[${u("deprecated")}]`,q=[t in r?Fu(r[t]):null,QD,t in S?`[${u("required")}]`:null,s.choices&&s.choices[t]?`[${u("choices:")} ${B.stringifiedValues(s.choices[t])}]`:null,y(s.default[t],s.defaultDescription[t])].filter(Boolean).join(" ");k.span({text:W0(HD),padding:[0,2,0,2+S8(HD)],width:O(GD,TD)+4},zD);let K=D.getInternalMethods().getUsageConfiguration()["hide-types"]===!0;if(q&&!K)k.div({text:q,padding:[0,0,0,2],align:"right"});else k.div()}),k.div()}),G.length)k.div(u("Examples:")),G.forEach((d)=>{d[0]=d[0].replace(/\$0/g,A)}),G.forEach((d)=>{if(d[1]==="")k.div({text:d[0],padding:[0,2,0,2]});else k.div({text:d[0],padding:[0,2,0,2],width:O(G,TD)+4},{text:d[1]})}),k.div();if(H.length>0){let d=H.map((e)=>e.replace(/\$0/g,A)).join(`
17
- `);k.div(`${d}
18
- `)}return k.toString().replace(/\s*$/,"")};function O(L,A,S){let p=0;if(!Array.isArray(L))L=Object.values(L).map((r)=>[r]);if(L.forEach((r)=>{p=Math.max(F.stringWidth(S?`${S} ${W0(r[0])}`:W0(r[0]))+S8(r[0]),p)}),A)p=Math.min(p,parseInt((A*0.5).toString(),10));return p}function T(){let L=D.getDemandedOptions(),A=D.getOptions();(Object.keys(A.alias)||[]).forEach((S)=>{A.alias[S].forEach((p)=>{if(V[p])B.describe(S,V[p]);if(p in L)D.demandOption(S,L[p]);if(A.boolean.includes(p))D.boolean(S);if(A.count.includes(p))D.count(S);if(A.string.includes(p))D.string(S);if(A.normalize.includes(p))D.normalize(S);if(A.array.includes(p))D.array(S);if(A.number.includes(p))D.number(S)})})}let M;B.cacheHelpMessage=function(){M=this.help()},B.clearCachedHelpMessage=function(){M=void 0},B.hasCachedHelpMessage=function(){return!!M};function R(L,A,S,p){let r=[],uD=null;return Object.keys(S).forEach((s)=>{r=r.concat(S[s])}),L.forEach((s)=>{if(uD=[s].concat(A[s]),!uD.some((ED)=>r.indexOf(ED)!==-1))S[p].push(s)}),r}function I(L){return D.getOptions().hiddenOptions.indexOf(L)<0||D.parsed.argv[D.getOptions().showHiddenOpt]}B.showHelp=(L)=>{let A=D.getInternalMethods().getLoggerInstance();if(!L)L="error";(typeof L==="function"?L:A[L])(B.help())},B.functionDescription=(L)=>{return["(",L.name?F.Parser.decamelize(L.name,"-"):u("generated-value"),")"].join("")},B.stringifiedValues=function(A,S){let p="",r=S||", ",uD=[].concat(A);if(!A||!uD.length)return p;return uD.forEach((s)=>{if(p.length)p+=r;p+=JSON.stringify(s)}),p};function y(L,A){let S=`[${u("default:")} `;if(L===void 0&&!A)return null;if(A)S+=A;else switch(typeof L){case"string":S+=`"${L}"`;break;case"object":S+=JSON.stringify(L);break;default:S+=L}return`${S}]`}function l(){if(F.process.stdColumns)return Math.min(80,F.process.stdColumns);else return 80}let h=null;B.version=(L)=>{h=L},B.showVersion=(L)=>{let A=D.getInternalMethods().getLoggerInstance();if(!L)L="error";(typeof L==="function"?L:A[L])(h)},B.reset=function(A){return C=null,Z=!1,J=[],Q=!1,H=[],G=[],X=[],V=rD(V,(S)=>!A[S]),B};let a=[];return B.freeze=function(){a.push({failMessage:C,failureOutput:Z,usages:J,usageDisabled:Q,epilogs:H,examples:G,commands:X,descriptions:V})},B.unfreeze=function(A=!1){let S=a.pop();if(!S)return;if(A)V={...S.descriptions,...V},X=[...S.commands,...X],J=[...S.usages,...J],G=[...S.examples,...G],H=[...S.epilogs,...H];else({failMessage:C,failureOutput:Z,usages:J,usageDisabled:Q,epilogs:H,examples:G,commands:X,descriptions:V}=S)},B}function Ku(D){return typeof D==="object"}function W7(D,F){return Ku(D)?{text:D.text,indentation:D.indentation+F}:{text:D,indentation:F}}function S8(D){return Ku(D)?D.indentation:0}function W0(D){return Ku(D)?D.text:D}var x8=`###-begin-{{app_name}}-completions-###
13
+ `).map((i)=>du(i,t,n)).join(`
14
+ `)}function Es(e){return er(e,{stringWidth:Le,stripAnsi:dt,wrap:Cs})}import{dirname as _r,resolve as Sr}from"path";import{readdirSync as pu,statSync as hu}from"fs";function xs(e,t){let n=Sr(".",e),i;if(!hu(n).isDirectory())n=_r(n);while(!0){if(i=t(n,pu(n)),i)return Sr(n,i);if(n=_r(i=n),i===n)break}}import{inspect as Pu}from"util";import{fileURLToPath as Jr}from"url";import{format as Du}from"util";import{normalize as yu,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="",i=!1,s=e.match(/^-+/);for(let r=s?s[0].length:0;r<e.length;r++){let o=e.charAt(r);if(i)i=!1,o=o.toUpperCase();if(r!==0&&(o==="-"||o==="_"))i=!0;else if(o!=="-"&&o!=="_")n+=o}return n}}function _n(e,t){let n=e.toLowerCase();t=t||"-";let i="";for(let s=0;s<e.length;s++){let r=n.charAt(s),o=e.charAt(s);if(r!==o&&s>0)i+=`${t}${n.charAt(s)}`;else i+=o}return i}function Sn(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 kr(e){if(Array.isArray(e))return e.map((o)=>typeof o!=="string"?o+"":o);e=e.trim();let t=0,n=null,i=null,s=null,r=[];for(let o=0;o<e.length;o++){if(n=i,i=e.charAt(o),i===" "&&!s){if(n!==" ")t++;continue}if(i===s)s=null;else if((i==="'"||i==='"')&&!s)s=i;if(!r[t])r[t]="";r[t]+=i}return r}var Ie;(function(e){e.BOOLEAN="boolean",e.STRING="string",e.NUMBER="number",e.ARRAY="array"})(Ie||(Ie={}));var Qe;class Ss{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),i=kr(e),s=typeof e==="string",r=gu(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),h=Object.create(null),m=n.__||Qe.format,p={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]+)$/,E=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(_){return{boolean:"bools",string:"strings",number:"numbers"}[_]}).filter(Boolean).pop();if(I)p[I][b]=!0;p.arrays[b]=!0,p.keys.push(b)}),[].concat(n.boolean||[]).filter(Boolean).forEach(function(D){p.bools[D]=!0,p.keys.push(D)}),[].concat(n.string||[]).filter(Boolean).forEach(function(D){p.strings[D]=!0,p.keys.push(D)}),[].concat(n.number||[]).filter(Boolean).forEach(function(D){p.numbers[D]=!0,p.keys.push(D)}),[].concat(n.count||[]).filter(Boolean).forEach(function(D){p.counts[D]=!0,p.keys.push(D)}),[].concat(n.normalize||[]).filter(Boolean).forEach(function(D){p.normalize[D]=!0,p.keys.push(D)}),typeof n.narg==="object")Object.entries(n.narg).forEach(([D,b])=>{if(typeof b==="number")p.nargs[D]=b,p.keys.push(D)});if(typeof n.coerce==="object")Object.entries(n.coerce).forEach(([D,b])=>{if(typeof b==="function")p.coercions[D]=b,p.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){p.configs[D]=!0});else if(typeof n.config==="object")Object.entries(n.config).forEach(([D,b])=>{if(typeof b==="boolean"||typeof b==="function")p.configs[D]=b})}Oe(n.key,r,n.default,p.arrays),Object.keys(a).forEach(function(D){(p.aliases[D]||[]).forEach(function(b){a[b]=a[D]})});let F=null;Ds();let k=[],C=Object.assign(Object.create(null),{_:[]}),A={};for(let D=0;D<i.length;D++){let b=i[D],I=b.replace(/^-{3,}/,"---"),_,w,j,M,K,ge;if(b!=="--"&&/^-/.test(b)&&ee(b))T(b);else if(I.match(/^---+(=|$)/)){T(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(z(M[1],p.arrays))D=L(D,M[1],i,M[2]);else if(z(M[1],p.nargs)!==!1)D=v(D,M[1],i,M[2]);else R(M[1],M[2],!0)}else if(b.match(E)&&o["boolean-negation"]){if(M=b.match(E),M!==null&&Array.isArray(M)&&M.length>=2)w=M[1],R(w,z(w,p.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],z(w,p.arrays))D=L(D,w,i);else if(z(w,p.nargs)!==!1)D=v(D,w,i);else if(K=i[D+1],K!==void 0&&(!K.match(/^-/)||K.match(y))&&!z(w,p.bools)&&!z(w,p.counts))R(w,K),D++;else if(/^(true|false)$/.test(K))R(w,K),D++;else R(w,V(w))}else if(b.match(/^-.\..+=/)){if(M=b.match(/^-([^=]+)=([\s\S]*)$/),M!==null&&Array.isArray(M)&&M.length>=3)R(M[1],M[2])}else if(b.match(/^-.\..+/)&&!b.match(y)){if(K=i[D+1],M=b.match(/^-(.\..+)/),M!==null&&Array.isArray(M)&&M.length>=2)if(w=M[1],K!==void 0&&!K.match(/^-/)&&!z(w,p.bools)&&!z(w,p.counts))R(w,K),D++;else R(w,V(w))}else if(b.match(/^-[^-]+/)&&!b.match(y)){j=b.slice(1,-1).split(""),_=!1;for(let be=0;be<j.length;be++){if(K=b.slice(be+2),j[be+1]&&j[be+1]==="="){if(ge=b.slice(be+3),w=j[be],z(w,p.arrays))D=L(D,w,i,ge);else if(z(w,p.nargs)!==!1)D=v(D,w,i,ge);else R(w,ge);_=!0;break}if(K==="-"){R(j[be],K);continue}if(/[A-Za-z]/.test(j[be])&&/^-?\d+(\.\d*)?(e-?\d+)?$/.test(K)&&z(K,p.bools)===!1){R(j[be],K),_=!0;break}if(j[be+1]&&j[be+1].match(/\W/)){R(j[be],K),_=!0;break}else R(j[be],V(j[be]))}if(w=b.slice(-1)[0],!_&&w!=="-")if(z(w,p.arrays))D=L(D,w,i);else if(z(w,p.nargs)!==!1)D=v(D,w,i);else if(K=i[D+1],K!==void 0&&(!/^(-|--)[^-]/.test(K)||K.match(y))&&!z(w,p.bools)&&!z(w,p.counts))R(w,K),D++;else if(/^(true|false)$/.test(K))R(w,K),D++;else R(w,V(w))}else if(b.match(/^-[0-9]$/)&&b.match(y)&&z(b.slice(1),p.bools))w=b.slice(1),R(w,V(w));else if(b==="--"){k=i.slice(D+1);break}else if(o["halt-at-non-option"]){k=i.slice(D);break}else T(b)}if(re(C,!0),re(C,!1),O(C),Z(),$e(C,p.aliases,a,!0),Q(C),o["set-placeholder-key"])oe(C);if(Object.keys(p.counts).forEach(function(D){if(!J(C,D.split(".")))R(D,0)}),f&&k.length)C[l]=[];if(k.forEach(function(D){C[l].push(D)}),o["camel-case-expansion"]&&o["strip-dashed"])Object.keys(C).filter((D)=>D!=="--"&&D.includes("-")).forEach((D)=>{delete C[D]});if(o["strip-aliased"])[].concat(...Object.keys(r).map((D)=>r[D])).forEach((D)=>{if(o["camel-case-expansion"]&&D.includes("-"))delete C[D.split(".").map((b)=>pt(b)).join(".")];delete C[D]});function T(D){let b=x("_",D);if(typeof b==="string"||typeof b==="number")C._.push(b)}function v(D,b,I,_){let w,j=z(b,p.nargs);if(j=typeof j!=="number"||isNaN(j)?1:j,j===0){if(!pe(_))F=Error(m("Argument unexpected for: %s",b));return R(b,V(b)),D}let M=pe(_)?0:1;if(o["nargs-eats-options"]){if(I.length-(D+1)+M<j)F=Error(m("Not enough arguments following: %s",b));M=j}else{for(w=D+1;w<I.length;w++)if(!I[w].match(/^-[^0-9]/)||I[w].match(y)||ee(I[w]))M++;else break;if(M<j)F=Error(m("Not enough arguments following: %s",b))}let K=Math.min(M,j);if(!pe(_)&&K>0)R(b,_),K--;for(w=D+1;w<K+D+1;w++)R(b,I[w]);return D+K}function L(D,b,I,_){let w=[],j=_||I[D+1],M=z(b,p.nargs);if(z(b,p.bools)&&!/^(true|false)$/.test(j))w.push(!0);else if(pe(j)||pe(_)&&/^-/.test(j)&&!y.test(j)&&!ee(j)){if(a[b]!==void 0){let K=a[b];w=Array.isArray(K)?K:[K]}}else{if(!pe(_))w.push(S(b,_,!0));for(let K=D+1;K<I.length;K++){if(!o["greedy-arrays"]&&w.length>0||M&&typeof M==="number"&&w.length>=M)break;if(j=I[K],/^-/.test(j)&&!y.test(j)&&!ee(j))break;D=K,w.push(S(b,j,s))}}if(typeof M==="number"&&(M&&w.length<M||isNaN(M)&&w.length===0))F=Error(m("Not enough arguments following: %s",b));return R(b,w),D}function R(D,b,I=s){if(/-/.test(D)&&o["camel-case-expansion"]){let j=D.split(".").map(function(M){return pt(M)}).join(".");G(D,j)}let _=S(D,b,I),w=D.split(".");if(ae(C,w,_),p.aliases[D])p.aliases[D].forEach(function(j){let M=j.split(".");ae(C,M,_)});if(w.length>1&&o["dot-notation"])(p.aliases[w[0]]||[]).forEach(function(j){let M=j.split("."),K=[].concat(w);if(K.shift(),M=M.concat(K),!(p.aliases[D]||[]).includes(M.join(".")))ae(C,M,_)});if(z(D,p.normalize)&&!z(D,p.arrays))[D].concat(p.aliases[D]||[]).forEach(function(M){Object.defineProperty(A,M,{enumerable:!0,get(){return b},set(K){b=typeof K==="string"?Qe.normalize(K):K}})})}function G(D,b){if(!(p.aliases[D]&&p.aliases[D].length))p.aliases[D]=[b],d[b]=!0;if(!(p.aliases[b]&&p.aliases[b].length))G(b,D)}function S(D,b,I){if(I)b=mu(b);if(z(D,p.bools)||z(D,p.counts)){if(typeof b==="string")b=b==="true"}let _=Array.isArray(b)?b.map(function(w){return x(D,w)}):x(D,b);if(z(D,p.counts)&&(pe(_)||typeof _==="boolean"))_=_s();if(z(D,p.normalize)&&z(D,p.arrays))if(Array.isArray(b))_=b.map((w)=>Qe.normalize(w));else _=Qe.normalize(b);return _}function x(D,b){if(!o["parse-positional-numbers"]&&D==="_")return b;if(!z(D,p.strings)&&!z(D,p.bools)&&!Array.isArray(b)){if(Sn(b)&&o["parse-numbers"]&&Number.isSafeInteger(Math.floor(parseFloat(`${b}`)))||!pe(b)&&z(D,p.numbers))b=Number(b)}return b}function O(D){let b=Object.create(null);$e(b,p.aliases,a),Object.keys(p.configs).forEach(function(I){let _=D[I]||b[I];if(_)try{let w=null,j=Qe.resolve(Qe.cwd(),_),M=p.configs[I];if(typeof M==="function"){try{w=M(j)}catch(K){w=K}if(w instanceof Error){F=w;return}}else w=Qe.require(j);W(w)}catch(w){if(w.name==="PermissionDenied")F=w;else if(D[I])F=Error(m("Invalid JSON config file: %s",_))}})}function W(D,b){Object.keys(D).forEach(function(I){let _=D[I],w=b?b+"."+I:I;if(typeof _==="object"&&_!==null&&!Array.isArray(_)&&o["dot-notation"])W(_,w);else if(!J(C,w.split("."))||z(w,p.arrays)&&o["combine-arrays"])R(w,_)})}function Z(){if(typeof c<"u")c.forEach(function(D){W(D)})}function re(D,b){if(typeof u>"u")return;let I=typeof u==="string"?u:"",_=Qe.env();Object.keys(_).forEach(function(w){if(I===""||w.lastIndexOf(I,0)===0){let j=w.split("__").map(function(M,K){if(K===0)M=M.substring(I.length);return pt(M)});if((b&&p.configs[j.join(".")]||!b)&&!J(D,j))R(j.join("."),_[w])}})}function Q(D){let b,I=new Set;Object.keys(D).forEach(function(_){if(!I.has(_)){if(b=z(_,p.coercions),typeof b==="function")try{let w=x(_,b(D[_]));[].concat(p.aliases[_]||[],_).forEach((j)=>{I.add(j),D[j]=w})}catch(w){F=w}}})}function oe(D){return p.keys.forEach((b)=>{if(~b.indexOf("."))return;if(typeof D[b]>"u")D[b]=void 0}),D}function $e(D,b,I,_=!1){Object.keys(I).forEach(function(w){if(!J(D,w.split("."))){if(ae(D,w.split("."),I[w]),_)h[w]=!0;(b[w]||[]).forEach(function(j){if(J(D,j.split(".")))return;ae(D,j.split("."),I[w])})}})}function J(D,b){let I=D;if(!o["dot-notation"])b=[b.join(".")];b.slice(0,-1).forEach(function(w){I=I[w]||{}});let _=b[b.length-1];if(typeof I!=="object")return!1;else return _ in I}function ae(D,b,I){let _=D;if(!o["dot-notation"])b=[b.join(".")];b.slice(0,-1).forEach(function(ge){if(ge=Ar(ge),typeof _==="object"&&_[ge]===void 0)_[ge]={};if(typeof _[ge]!=="object"||Array.isArray(_[ge])){if(Array.isArray(_[ge]))_[ge].push({});else _[ge]=[_[ge],{}];_=_[ge][_[ge].length-1]}else _=_[ge]});let w=Ar(b[b.length-1]),j=z(b.join("."),p.arrays),M=Array.isArray(I),K=o["duplicate-arguments-array"];if(!K&&z(w,p.nargs)){if(K=!0,!pe(_[w])&&p.nargs[w]===1||Array.isArray(_[w])&&_[w].length===p.nargs[w])_[w]=void 0}if(I===_s())_[w]=_s(_[w]);else if(Array.isArray(_[w]))if(K&&j&&M)_[w]=o["flatten-duplicate-arrays"]?_[w].concat(I):(Array.isArray(_[w][0])?_[w]:[_[w]]).concat([I]);else if(!K&&Boolean(j)===Boolean(M))_[w]=I;else _[w]=_[w].concat([I]);else if(_[w]===void 0&&j)_[w]=M?I:[I];else if(K&&!(_[w]===void 0||z(w,p.counts)||z(w,p.bools)))_[w]=[_[w],I];else _[w]=I}function Oe(...D){D.forEach(function(b){Object.keys(b||{}).forEach(function(I){if(p.aliases[I])return;p.aliases[I]=[].concat(r[I]||[]),p.aliases[I].concat(I).forEach(function(_){if(/-/.test(_)&&o["camel-case-expansion"]){let w=pt(_);if(w!==I&&p.aliases[I].indexOf(w)===-1)p.aliases[I].push(w),d[w]=!0}}),p.aliases[I].concat(I).forEach(function(_){if(_.length>1&&/[A-Z]/.test(_)&&o["camel-case-expansion"]){let w=_n(_,"-");if(w!==I&&p.aliases[I].indexOf(w)===-1)p.aliases[I].push(w),d[w]=!0}}),p.aliases[I].forEach(function(_){p.aliases[_]=[I].concat(p.aliases[I].filter(function(w){return _!==w}))})})})}function z(D,b){let I=[].concat(p.aliases[D]||[],D),_=Object.keys(b),w=I.find((j)=>_.includes(j));return w?b[w]:!1}function vt(D){let b=Object.keys(p);return[].concat(b.map((_)=>p[_])).some(function(_){return Array.isArray(_)?_.includes(D):_[D]})}function Yi(D,...b){return[].concat(...b).some(function(_){let w=D.match(_);return w&&vt(w[1])})}function H(D){if(D.match(y)||!D.match(/^-[^-]+/))return!1;let b=!0,I,_=D.slice(1).split("");for(let w=0;w<_.length;w++){if(I=D.slice(w+2),!vt(_[w])){b=!1;break}if(_[w+1]&&_[w+1]==="="||I==="-"||/[A-Za-z]/.test(_[w])&&/^-?\d+(\.\d*)?(e-?\d+)?$/.test(I)||_[w+1]&&_[w+1].match(/\W/))break}return b}function ee(D){return o["unknown-options-as-args"]&&de(D)}function de(D){if(D=D.replace(/^-{3,}/,"--"),D.match(y))return!1;if(H(D))return!1;return!Yi(D,/^-+([^=]+?)=[\s\S]*$/,E,/^-+([^=]+?)$/,/^-+([^=]+?)-$/,/^-+([^=]+?\d+)$/,/^-+([^=]+?)\W+.*$/)}function V(D){if(!z(D,p.bools)&&!z(D,p.counts)&&`${D}`in a)return a[D];else return ye(ue(D))}function ye(D){return{[Ie.BOOLEAN]:!0,[Ie.STRING]:"",[Ie.NUMBER]:void 0,[Ie.ARRAY]:[]}[D]}function ue(D){let b=Ie.BOOLEAN;if(z(D,p.strings))b=Ie.STRING;else if(z(D,p.numbers))b=Ie.NUMBER;else if(z(D,p.bools))b=Ie.BOOLEAN;else if(z(D,p.arrays))b=Ie.ARRAY;return b}function pe(D){return D===void 0}function Ds(){Object.keys(p.counts).find((D)=>{if(z(D,p.arrays))return F=Error(m("Invalid configuration: %s, opts.count excludes opts.array.",D)),!0;else if(z(D,p.nargs))return F=Error(m("Invalid configuration: %s, opts.count excludes opts.narg.",D)),!0;return!1})}return{aliases:Object.assign({},p.aliases),argv:Object.assign(A,C),configuration:o,defaulted:Object.assign({},h),error:F,newAliases:Object.assign({},d)}}}function gu(e){let t=[],n=Object.create(null),i=!0;Object.keys(e).forEach(function(s){t.push([].concat(e[s],s))});while(i){i=!1;for(let s=0;s<t.length;s++)for(let r=s+1;r<t.length;r++)if(t[s].filter(function(a){return t[r].indexOf(a)!==-1}).length){t[s]=t[s].concat(t[r]),t.splice(r,1),i=!0;break}}return t.forEach(function(s){s=s.filter(function(o,a,c){return c.indexOf(o)===a});let r=s.pop();if(r!==void 0&&typeof r==="string")n[r]=s}),n}function _s(e){return e!==void 0?e+1:1}function Ar(e){if(e==="__proto__")return"___proto___";return e}function mu(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 bu}from"fs";import{createRequire as $r}from"node:module";var ks,As,$s,Or=process&&process.env&&process.env.YARGS_MIN_NODE_VERSION?Number(process.env.YARGS_MIN_NODE_VERSION):20,Ir=(As=(ks=process===null||process===void 0?void 0:process.versions)===null||ks===void 0?void 0:ks.node)!==null&&As!==void 0?As:($s=process===null||process===void 0?void 0:process.version)===null||$s===void 0?void 0:$s.slice(1);if(Ir){if(Number(Ir.match(/^([^.]+)/)[1])<Or)throw Error(`yargs parser supports a minimum Node.js version of ${Or}. Read our version support policy: https://github.com/yargs/yargs-parser#supported-nodejs-versions`)}var Fu=process?process.env:{},Pr=$r?$r(import.meta.url):void 0,Tr=new Ss({cwd:process.cwd,env:()=>Fu,format:Du,normalize:yu,resolve:wu,require:(e)=>{if(typeof Pr<"u")return Pr(e);else if(e.match(/\.json$/))return JSON.parse(bu(e,"utf8"));else throw Error("only .json config files are supported in ESM")}}),Zt=function(t,n){return Tr.parse(t.slice(),n).argv};Zt.detailed=function(e,t){return Tr.parse(e.slice(),t)};Zt.camelCase=pt;Zt.decamelize=_n;Zt.looksLikeNumber=Sn;var Os=Zt;import{basename as Tu,dirname as Ru,extname as Mu,relative as Bu,resolve as Ur,join as Nu}from"path";function Rr(){if(Cu())return 0;return 1}function Cu(){return Eu()&&!process.defaultApp}function Eu(){return!!process.versions.electron}function Is(e){return e.slice(Rr()+1)}function Mr(){return process.argv[Rr()]}import{readFileSync as xu,statSync as _u,writeFile as Su}from"fs";import{format as ku}from"util";import{resolve as Au}from"path";var Br={fs:{readFileSync:xu,writeFile:Su},format:ku,resolve:Au,exists:(e)=>{try{return _u(e).isFile()}catch(t){return!1}}};var We;class Nr{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 We.format.apply(We.format,[this.cache[this.locale][t]||t].concat(e))}__n(){let e=Array.prototype.slice.call(arguments),t=e.shift(),n=e.shift(),i=e.shift(),s=function(){};if(typeof e[e.length-1]==="function")s=e.pop();if(!this.cache[this.locale])this._readLocaleFile();let r=i===1?t:n;if(this.cache[this.locale][t])r=this.cache[this.locale][t][i===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=[r];if(~r.indexOf("%d"))o.push(i);return We.format.apply(We.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(i,s){let r=t[s+1];if(n+=i,typeof r<"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,i=t.locale,s=t.cb,r=this._resolveLocaleFile(n,i),o=JSON.stringify(this.cache[i],null,2);We.fs.writeFile(r,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(We.fs.readFileSync)e=JSON.parse(We.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=We.resolve(e,"./",t+".json");if(this.fallbackToLanguage&&!this._fileExistsSync(n)&&~t.lastIndexOf("_")){let i=We.resolve(e,"./",t.split("_")[0]+".json");if(this._fileExistsSync(i))n=i}return n}_fileExistsSync(e){return We.exists(e)}}function vr(e,t){We=t;let n=new Nr(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 $u=(e)=>vr(e,Br),jr=$u;var Kr=Gi(Wr(),1);import{createRequire as vu}from"node:module";import{readFileSync as ju,readdirSync as Lu}from"node:fs";var Ps=Jr(import.meta.url),Wu=Ps.substring(0,Ps.lastIndexOf("node_modules")),Uu=vu(import.meta.url),Ts={assert:{notStrictEqual:Ou,strictEqual:Iu},cliui:Es,findUp:xs,getEnv:(e)=>process.env[e],inspect:Pu,getProcessArgvBin:Mr,mainFilename:Wu||process.cwd(),Parser:Os,path:{basename:Tu,dirname:Ru,extname:Mu,relative:Bu,resolve:Ur,join:Nu},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:ju,readdirSync:Lu,require:Uu,getCallerFile:()=>{let e=Kr.default(3);return e.match(/^file:\/\//)?Jr(e):e},stringWidth:Le,y18n:jr({directory:Ur(Ps,"../../../locales"),updateFiles:!1})};function Fe(e,t,n,i){n.assert.notStrictEqual(e,t,i)}function Rs(e,t){t.assert.strictEqual(typeof e,"string")}function jt(e){return Object.keys(e)}function ne(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+(?![^[]*]|[^<]*>)/),i=/\.*[\][<>]/g,s=n.shift();if(!s)throw Error(`No command found in: ${e}`);let r={cmd:s.replace(i,""),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))r.optional.push({cmd:o.replace(i,"").split("|"),variadic:c});else r.demanded.push({cmd:o.replace(i,"").split("|"),variadic:c})}),r}var Ju=["first","second","third","fourth","fifth","sixth"];function B(e,t,n){function i(){return typeof e==="object"?[{demanded:[],optional:[]},e,t]:[nt(`cmd ${e}`),t,n]}try{let s=0,[r,o,a]=i(),c=[].slice.call(o);while(c.length&&c[c.length-1]===void 0)c.pop();let u=a||c.length;if(u<r.demanded.length)throw new le(`Not enough arguments provided. Expected ${r.demanded.length} but received ${c.length}.`);let f=r.demanded.length+r.optional.length;if(u>f)throw new le(`Too many arguments provided. Expected max ${f} but received ${u}.`);r.demanded.forEach((l)=>{let d=c.shift(),h=zr(d);if(l.cmd.filter((p)=>p===h||p==="*").length===0)Hr(h,l.cmd,s);s+=1}),r.optional.forEach((l)=>{if(c.length===0)return;let d=c.shift(),h=zr(d);if(l.cmd.filter((p)=>p===h||p==="*").length===0)Hr(h,l.cmd,s);s+=1})}catch(s){console.warn(s.stack)}}function zr(e){if(Array.isArray(e))return"array";else if(e===null)return"null";return typeof e}function Hr(e,t,n){throw new le(`Invalid ${Ju[n]||"manyith"} argument. Expected ${t.join(" or ")} but received ${e}.`)}class Ms{constructor(e){this.globalMiddleware=[],this.frozens=[],this.yargs=e}addMiddleware(e,t,n=!0,i=!1){if(B("<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 r=e[s];r.applyBeforeValidation=t,r.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=i,this.globalMiddleware.push(e)}return this.yargs}addCoerceMiddleware(e,t){let n=this.yargs.getAliases();return this.globalMiddleware=this.globalMiddleware.filter((i)=>{let s=[...n[t]||[],t];if(!i.option)return!0;else return!s.includes(i.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 qr(e){if(!e)return[];return e.map((t)=>(t.applyBeforeValidation=!1,t))}function ht(e,t,n,i){return n.reduce((s,r)=>{if(r.applyBeforeValidation!==i)return s;if(r.mutates){if(r.applied)return s;r.applied=!0}if(ne(s))return s.then((o)=>Promise.all([o,r(o,t)])).then(([o,a])=>Object.assign(o,a));else{let o=r(s,t);return ne(o)?o.then((a)=>Object.assign(s,a)):Object.assign(s,o)}},e)}function gt(e,t,n=(i)=>{throw i}){try{let i=Ku(e)?e():e;return ne(i)?i.then((s)=>t(s)):t(i)}catch(i){return n(i)}}function Ku(e){return typeof e==="function"}var Lt=/(^\*)|(^\$0)/;class Xr{constructor(e,t,n,i){this.requireCache=new Set,this.handlers={},this.aliasMap={},this.frozens=[],this.shim=i,this.usage=e,this.globalMiddleware=n,this.validation=t}addDirectory(e,t,n,i){i=i||{},this.requireCache.add(n);let s=this.shim.path.resolve(this.shim.path.dirname(n),e),r=this.shim.readdirSync(s,{recursive:i.recurse?!0:!1});if(!Array.isArray(i.extensions))i.extensions=["js"];let o=typeof i.visit==="function"?i.visit:(a)=>a;for(let a of r){let c=a.toString();if(i.exclude){let f=!1;if(typeof i.exclude==="function")f=i.exclude(c);else f=i.exclude.test(c);if(f)continue}if(i.include){let f=!1;if(typeof i.include==="function")f=i.include(c);else f=i.include.test(c);if(!f)continue}let u=!1;for(let f of i.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,i,s,r){let o=[],a=qr(s);if(i=i||(()=>{}),Array.isArray(e))if(zu(e))[e,...o]=e;else for(let c of e)this.addHandler(c);else if(qu(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(Yr(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(Lt.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(Lt,c.cmd);if(o.forEach((l)=>{this.aliasMap[l]=c.cmd}),t!==!1)this.usage.command(e,t,u,o,r);if(this.handlers[c.cmd]={original:e,description:t,handler:i,builder:n||{},middlewares:a,deprecated:r,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,i,s,r){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,i,s,r);return ne(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,i,s,r,o,a){let c=t.builder,u=n;if(kn(c)){n.getInternalMethods().getUsageInstance().freeze();let f=c(n.getInternalMethods().reset(i),a);if(ne(f))return f.then((l)=>(u=Vr(l)?l:n,this.parseAndUpdateUsage(e,t,u,s,r,o)))}else if(Hu(c))n.getInternalMethods().getUsageInstance().freeze(),u=n.getInternalMethods().reset(i),Object.keys(t.builder).forEach((f)=>{u.option(f,c[f])});return this.parseAndUpdateUsage(e,t,u,s,r,o)}parseAndUpdateUsage(e,t,n,i,s,r){if(e)n.getInternalMethods().getUsageInstance().unfreeze(!0);if(this.shouldUpdateUsage(n))n.getInternalMethods().getUsageInstance().usage(this.usageFromParentCommandsCommandHandler(i,t),t.description);let o=n.getInternalMethods().runYargsParserAndExecuteCommands(null,void 0,!0,s,r);return ne(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=Lt.test(t.original)?t.original.replace(Lt,"").trim():t.original,i=e.filter((s)=>!Lt.test(s));return i.push(n),`$0 ${i.join(" ")}`}handleValidationAndGetResult(e,t,n,i,s,r,o,a){if(!r.getInternalMethods().getHasOutput()){let c=r.getInternalMethods().runValidation(s,a,r.parsed.error,e);n=gt(n,(u)=>(c(u),u))}if(t.handler&&!r.getInternalMethods().getHasOutput()){r.getInternalMethods().setHasOutput();let c=!!r.getOptions().configuration["populate--"];if(r.getInternalMethods().postProcess(n,c,!1,!1),n=ht(n,r,o,!1),n=gt(n,(u)=>{let f=t.handler(u);return ne(f)?f.then(()=>u):u}),!e)r.getInternalMethods().getUsageInstance().cacheHelpMessage();if(ne(n)&&!r.getInternalMethods().hasParseCallback())n.catch((u)=>{try{r.getInternalMethods().getUsageInstance().fail(null,u)}catch(f){}})}if(!e)i.commands.pop(),i.fullCommands.pop();return n}applyMiddlewareAndGetResult(e,t,n,i,s,r,o){let a={};if(s)return n;if(!o.getInternalMethods().getHasOutput())a=this.populatePositionals(t,n,i,o);let c=this.globalMiddleware.getMiddleware().slice(0).concat(t.middlewares),u=ht(n,o,c,!0);return ne(u)?u.then((f)=>this.handleValidationAndGetResult(e,t,f,i,r,o,c,a)):this.handleValidationAndGetResult(e,t,u,i,r,o,c,a)}populatePositionals(e,t,n,i){t._=t._.slice(n.commands.length);let s=e.demanded.slice(0),r=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(r.length){let a=r.shift();this.populatePositional(a,t,o)}return t._=n.commands.concat(t._.map((a)=>""+a)),this.postProcessPositionals(t,o,this.cmdToParseOptions(e.original),i),o}populatePositional(e,t,n){let i=e.cmd[0];if(e.variadic)n[i]=t._.splice(0).map(String);else if(t._.length)n[i]=[String(t._.shift())]}cmdToParseOptions(e){let t={array:[],default:{},alias:{},demand:{}},n=nt(e);return n.demanded.forEach((i)=>{let[s,...r]=i.cmd;if(i.variadic)t.array.push(s),t.default[s]=[];t.alias[s]=r,t.demand[s]=!0}),n.optional.forEach((i)=>{let[s,...r]=i.cmd;if(i.variadic)t.array.push(s),t.default[s]=[];t.alias[s]=r}),t}postProcessPositionals(e,t,n,i){let s=Object.assign({},i.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 r=[];if(Object.keys(t).forEach((c)=>{t[c].map((u)=>{if(s.configuration["unknown-options-as-args"])s.key[c]=!0;r.push(`--${c}`),r.push(u)})}),!r.length)return;let o=Object.assign({},s.configuration,{"populate--":!1}),a=this.shim.Parser.detailed(r,Object.assign({},s,{configuration:o}));if(a.error)i.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(i,u)&&!this.isDefaulted(i,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((i)=>Object.prototype.hasOwnProperty.call(i,t))||n.some((i)=>Object.prototype.hasOwnProperty.call(i,this.shim.Parser.camelCase(t)))}runDefaultBuilderOn(e){if(!this.defaultCommand)return;if(this.shouldUpdateUsage(e)){let n=Lt.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(kn(t))return t(e,!0);else if(!Yr(t))Object.keys(t).forEach((n)=>{e.option(n,t[n])});return}extractDesc({describe:e,description:t,desc:n}){for(let i of[e,t,n]){if(typeof i==="string"||i===!1)return i;Fe(i,!0,this.shim)}return!1}freeze(){this.frozens.push({handlers:this.handlers,aliasMap:this.aliasMap,defaultCommand:this.defaultCommand})}unfreeze(){let e=this.frozens.pop();Fe(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 Gr(e,t,n,i){return new Xr(e,t,n,i)}function Yr(e){return typeof e==="object"&&!!e.builder&&typeof e.handler==="function"}function zu(e){return e.every((t)=>typeof t==="string")}function kn(e){return typeof e==="function"}function Hu(e){return typeof e==="object"}function qu(e){return typeof e==="object"&&!Array.isArray(e)}function st(e={},t=()=>!0){let n={};return jt(e).forEach((i)=>{if(t(i,e[i]))n[i]=e[i]}),n}function it(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 Yu(e){return typeof e==="boolean"}function Qr(e,t){let n=t.y18n.__,i={},s=[];i.failFn=function(x){s.push(x)};let r=null,o=null,a=!0;i.showHelpOnFail=function(x=!0,O){let[W,Z]=typeof x==="string"?[!0,x]:[x,O];if(e.getInternalMethods().isGlobalContext())o=Z;return r=Z,a=W,i};let c=!1;i.fail=function(x,O){let W=e.getInternalMethods().getLoggerInstance();if(s.length)for(let Z=s.length-1;Z>=0;--Z){let re=s[Z];if(Yu(re)){if(O)throw O;else if(x)throw Error(x)}else re(x,O,i)}else{if(e.getExitProcess())it(!0);if(!c){if(c=!0,a)e.showHelp("error"),W.error();if(x||O)W.error(x||O);let Z=r||o;if(Z){if(x||O)W.error("");W.error(Z)}}if(O=O||new le(x),e.getExitProcess())return e.exit(1);else if(e.getInternalMethods().hasParseCallback())return e.exit(1,O);else throw O}};let u=[],f=!1;i.usage=(S,x)=>{if(S===null)return f=!0,u=[],i;return f=!1,u.push([S,x||""]),i},i.getUsage=()=>u,i.getUsageDisabled=()=>f,i.getPositionalGroupName=()=>n("Positionals:");let l=[];i.example=(S,x)=>{l.push([S,x||""])};let d=[];i.command=function(x,O,W,Z,re=!1){if(W)d=d.map((Q)=>(Q[2]=!1,Q));d.push([x,O||"",W,Z,re])},i.getCommands=()=>d;let h={};i.describe=function(x,O){if(Array.isArray(x))x.forEach((W)=>{i.describe(W,O)});else if(typeof x==="object")Object.keys(x).forEach((W)=>{i.describe(W,x[W])});else h[x]=O},i.getDescriptions=()=>h;let m=[];i.epilog=(S)=>{m.push(S)};let p=!1,y;i.wrap=(S)=>{p=!0,y=S},i.getWrap=()=>{if(t.getEnv("YARGS_DISABLE_WRAP"))return null;if(!p)y=L(),p=!0;return y};let E="__yargsString__:";i.deferY18nLookup=(S)=>E+S,i.help=function(){if(C)return C;k();let x=e.customScriptName?e.$0:t.path.basename(e.$0),O=e.getDemandedOptions(),W=e.getDemandedCommands(),Z=e.getDeprecatedOptions(),re=e.getGroups(),Q=e.getOptions(),oe=[];oe=oe.concat(Object.keys(h)),oe=oe.concat(Object.keys(O)),oe=oe.concat(Object.keys(W)),oe=oe.concat(Object.keys(Q.default)),oe=oe.filter(T),oe=Object.keys(oe.reduce((H,ee)=>{if(ee!=="_")H[ee]=!0;return H},{}));let $e=i.getWrap(),J=t.cliui({width:$e,wrap:!!$e});if(!f){if(u.length)u.forEach((H)=>{if(J.div({text:`${H[0].replace(/\$0/g,x)}`}),H[1])J.div({text:`${H[1]}`,padding:[1,0,0,0]})}),J.div();else if(d.length){let H=null;if(W._)H=`${x} <${n("command")}>
15
+ `;else H=`${x} [${n("command")}]
16
+ `;J.div(`${H}`)}}if(d.length>1||d.length===1&&!d[0][2]){J.div(n("Commands:"));let H=e.getInternalMethods().getContext(),ee=H.commands.length?`${H.commands.join(" ")} `:"";if(e.getInternalMethods().getParserConfiguration()["sort-commands"]===!0)d=d.sort((V,ye)=>V[0].localeCompare(ye[0]));let de=x?`${x} `:"";d.forEach((V)=>{let ye=`${de}${ee}${V[0].replace(/^\$0 ?/,"")}`;J.span({text:ye,padding:[0,2,0,2],width:F(d,$e,`${x}${ee}`)+4},{text:V[1]});let ue=[];if(V[2])ue.push(`[${n("default")}]`);if(V[3]&&V[3].length)ue.push(`[${n("aliases:")} ${V[3].join(", ")}]`);if(V[4])if(typeof V[4]==="string")ue.push(`[${n("deprecated: %s",V[4])}]`);else ue.push(`[${n("deprecated")}]`);if(ue.length)J.div({text:ue.join(" "),padding:[0,0,0,2],align:"right"});else J.div()}),J.div()}let ae=(Object.keys(Q.alias)||[]).concat(Object.keys(e.parsed.newAliases)||[]);oe=oe.filter((H)=>!e.parsed.newAliases[H]&&ae.every((ee)=>(Q.alias[ee]||[]).indexOf(H)===-1));let Oe=n("Options:");if(!re[Oe])re[Oe]=[];A(oe,Q.alias,re,Oe);let z=(H)=>/^--/.test(An(H)),vt=Object.keys(re).filter((H)=>re[H].length>0).map((H)=>{let ee=re[H].filter(T).map((de)=>{if(ae.includes(de))return de;for(let V=0,ye;(ye=ae[V])!==void 0;V++)if((Q.alias[ye]||[]).includes(de))return ye;return de});return{groupName:H,normalizedKeys:ee}}).filter(({normalizedKeys:H})=>H.length>0).map(({groupName:H,normalizedKeys:ee})=>{let de=ee.reduce((V,ye)=>(V[ye]=[ye].concat(Q.alias[ye]||[]).map((ue)=>{if(H===i.getPositionalGroupName())return ue;else return(/^[0-9]$/.test(ue)?Q.boolean.includes(ye)?"-":"--":ue.length>1?"--":"-")+ue}).sort((ue,pe)=>z(ue)===z(pe)?0:z(ue)?1:-1).join(", "),V),{});return{groupName:H,normalizedKeys:ee,switches:de}});if(vt.filter(({groupName:H})=>H!==i.getPositionalGroupName()).some(({normalizedKeys:H,switches:ee})=>!H.every((de)=>z(ee[de]))))vt.filter(({groupName:H})=>H!==i.getPositionalGroupName()).forEach(({normalizedKeys:H,switches:ee})=>{H.forEach((de)=>{if(z(ee[de]))ee[de]=Xu(ee[de],4)})});if(vt.forEach(({groupName:H,normalizedKeys:ee,switches:de})=>{J.div(H),ee.forEach((V)=>{let ye=de[V],ue=h[V]||"",pe=null;if(ue.includes(E))ue=n(ue.substring(E.length));if(Q.boolean.includes(V))pe=`[${n("boolean")}]`;if(Q.count.includes(V))pe=`[${n("count")}]`;if(Q.string.includes(V))pe=`[${n("string")}]`;if(Q.normalize.includes(V))pe=`[${n("string")}]`;if(Q.array.includes(V))pe=`[${n("array")}]`;if(Q.number.includes(V))pe=`[${n("number")}]`;let Ds=(I)=>typeof I==="string"?`[${n("deprecated: %s",I)}]`:`[${n("deprecated")}]`,D=[V in Z?Ds(Z[V]):null,pe,V in O?`[${n("required")}]`:null,Q.choices&&Q.choices[V]?`[${n("choices:")} ${i.stringifiedValues(Q.choices[V])}]`:null,v(Q.default[V],Q.defaultDescription[V])].filter(Boolean).join(" ");J.span({text:An(ye),padding:[0,2,0,2+Zr(ye)],width:F(de,$e)+4},ue);let b=e.getInternalMethods().getUsageConfiguration()["hide-types"]===!0;if(D&&!b)J.div({text:D,padding:[0,0,0,2],align:"right"});else J.div()}),J.div()}),l.length)J.div(n("Examples:")),l.forEach((H)=>{H[0]=H[0].replace(/\$0/g,x)}),l.forEach((H)=>{if(H[1]==="")J.div({text:H[0],padding:[0,2,0,2]});else J.div({text:H[0],padding:[0,2,0,2],width:F(l,$e)+4},{text:H[1]})}),J.div();if(m.length>0){let H=m.map((ee)=>ee.replace(/\$0/g,x)).join(`
17
+ `);J.div(`${H}
18
+ `)}return J.toString().replace(/\s*$/,"")};function F(S,x,O){let W=0;if(!Array.isArray(S))S=Object.values(S).map((Z)=>[Z]);if(S.forEach((Z)=>{W=Math.max(t.stringWidth(O?`${O} ${An(Z[0])}`:An(Z[0]))+Zr(Z[0]),W)}),x)W=Math.min(W,parseInt((x*0.5).toString(),10));return W}function k(){let S=e.getDemandedOptions(),x=e.getOptions();(Object.keys(x.alias)||[]).forEach((O)=>{x.alias[O].forEach((W)=>{if(h[W])i.describe(O,h[W]);if(W in S)e.demandOption(O,S[W]);if(x.boolean.includes(W))e.boolean(O);if(x.count.includes(W))e.count(O);if(x.string.includes(W))e.string(O);if(x.normalize.includes(W))e.normalize(O);if(x.array.includes(W))e.array(O);if(x.number.includes(W))e.number(O)})})}let C;i.cacheHelpMessage=function(){C=this.help()},i.clearCachedHelpMessage=function(){C=void 0},i.hasCachedHelpMessage=function(){return!!C};function A(S,x,O,W){let Z=[],re=null;return Object.keys(O).forEach((Q)=>{Z=Z.concat(O[Q])}),S.forEach((Q)=>{if(re=[Q].concat(x[Q]),!re.some((oe)=>Z.indexOf(oe)!==-1))O[W].push(Q)}),Z}function T(S){return e.getOptions().hiddenOptions.indexOf(S)<0||e.parsed.argv[e.getOptions().showHiddenOpt]}i.showHelp=(S)=>{let x=e.getInternalMethods().getLoggerInstance();if(!S)S="error";(typeof S==="function"?S:x[S])(i.help())},i.functionDescription=(S)=>["(",S.name?t.Parser.decamelize(S.name,"-"):n("generated-value"),")"].join(""),i.stringifiedValues=function(x,O){let W="",Z=O||", ",re=[].concat(x);if(!x||!re.length)return W;return re.forEach((Q)=>{if(W.length)W+=Z;W+=JSON.stringify(Q)}),W};function v(S,x){let O=`[${n("default:")} `;if(S===void 0&&!x)return null;if(x)O+=x;else switch(typeof S){case"string":O+=`"${S}"`;break;case"object":O+=JSON.stringify(S);break;default:O+=S}return`${O}]`}function L(){if(t.process.stdColumns)return Math.min(80,t.process.stdColumns);else return 80}let R=null;i.version=(S)=>{R=S},i.showVersion=(S)=>{let x=e.getInternalMethods().getLoggerInstance();if(!S)S="error";(typeof S==="function"?S:x[S])(R)},i.reset=function(x){return r=null,c=!1,u=[],f=!1,m=[],l=[],d=[],h=st(h,(O)=>!x[O]),i};let G=[];return i.freeze=function(){G.push({failMessage:r,failureOutput:c,usages:u,usageDisabled:f,epilogs:m,examples:l,commands:d,descriptions:h})},i.unfreeze=function(x=!1){let O=G.pop();if(!O)return;if(x)h={...O.descriptions,...h},d=[...O.commands,...d],u=[...O.usages,...u],l=[...O.examples,...l],m=[...O.epilogs,...m];else({failMessage:r,failureOutput:c,usages:u,usageDisabled:f,epilogs:m,examples:l,commands:d,descriptions:h}=O)},i}function Bs(e){return typeof e==="object"}function Xu(e,t){return Bs(e)?{text:e.text,indentation:e.indentation+t}:{text:e,indentation:t}}function Zr(e){return Bs(e)?e.indentation:0}function An(e){return Bs(e)?e.text:e}var eo=`###-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
- `,I8=`#compdef {{app_name}}
47
+ `,to=`#compdef {{app_name}}
48
48
  ###-begin-{{app_name}}-completions-###
49
49
  #
50
50
  # yargs command completion script
@@ -71,122 +71,139 @@ else
71
71
  compdef _{{app_name}}_yargs_completions {{app_name}}
72
72
  fi
73
73
  ###-end-{{app_name}}-completions-###
74
- `;class b8{constructor(D,F,u,B){var E,C,$;this.yargs=D,this.usage=F,this.command=u,this.shim=B,this.completionKey="get-yargs-completions",this.aliases=null,this.customCompletionFunction=null,this.indexAfterLastReset=0,this.zshShell=($=((E=this.shim.getEnv("SHELL"))===null||E===void 0?void 0:E.includes("zsh"))||((C=this.shim.getEnv("ZSH_NAME"))===null||C===void 0?void 0:C.includes("zsh")))!==null&&$!==void 0?$:!1}defaultCompletion(D,F,u,B){let E=this.command.getCommandHandlers();for(let $=0,z=D.length;$<z;++$)if(E[D[$]]&&E[D[$]].builder){let Z=E[D[$]].builder;if(Y0(Z)){this.indexAfterLastReset=$+1;let J=this.yargs.getInternalMethods().reset();return Z(J,!0),J.argv}}let C=[];this.commandCompletions(C,D,u),this.optionCompletions(C,D,F,u),this.choicesFromOptionsCompletions(C,D,F,u),this.choicesFromPositionalsCompletions(C,D,F,u),B(null,C)}commandCompletions(D,F,u){let B=this.yargs.getInternalMethods().getContext().commands;if(!u.match(/^-/)&&B[B.length-1]!==u&&!this.previousArgHasChoices(F))this.usage.getCommands().forEach((E)=>{let C=sD(E[0]).cmd;if(F.indexOf(C)===-1)if(!this.zshShell)D.push(C);else{let $=E[1]||"";D.push(C.replace(/:/g,"\\:")+":"+$)}})}optionCompletions(D,F,u,B){if((B.match(/^-/)||B===""&&D.length===0)&&!this.previousArgHasChoices(F)){let E=this.yargs.getOptions(),C=this.yargs.getGroups()[this.usage.getPositionalGroupName()]||[];Object.keys(E.key).forEach(($)=>{let z=!!E.configuration["boolean-negation"]&&E.boolean.includes($);if(!C.includes($)&&!E.hiddenOptions.includes($)&&!this.argsContainKey(F,$,z))this.completeOptionKey($,D,B,z&&!!E.default[$])})}}choicesFromOptionsCompletions(D,F,u,B){if(this.previousArgHasChoices(F)){let E=this.getPreviousArgChoices(F);if(E&&E.length>0)D.push(...E.map((C)=>C.replace(/:/g,"\\:")))}}choicesFromPositionalsCompletions(D,F,u,B){if(B===""&&D.length>0&&this.previousArgHasChoices(F))return;let E=this.yargs.getGroups()[this.usage.getPositionalGroupName()]||[],C=Math.max(this.indexAfterLastReset,this.yargs.getInternalMethods().getContext().commands.length+1),$=E[u._.length-C-1];if(!$)return;let z=this.yargs.getOptions().choices[$]||[];for(let Z of z)if(Z.startsWith(B))D.push(Z.replace(/:/g,"\\:"))}getPreviousArgChoices(D){if(D.length<1)return;let F=D[D.length-1],u="";if(!F.startsWith("-")&&D.length>1)u=F,F=D[D.length-2];if(!F.startsWith("-"))return;let B=F.replace(/^-+/,""),E=this.yargs.getOptions(),C=[B,...this.yargs.getAliases()[B]||[]],$;for(let z of C)if(Object.prototype.hasOwnProperty.call(E.key,z)&&Array.isArray(E.choices[z])){$=E.choices[z];break}if($)return $.filter((z)=>!u||z.startsWith(u))}previousArgHasChoices(D){let F=this.getPreviousArgChoices(D);return F!==void 0&&F.length>0}argsContainKey(D,F,u){let B=(E)=>D.indexOf((/^[^0-9]$/.test(E)?"-":"--")+E)!==-1;if(B(F))return!0;if(u&&B(`no-${F}`))return!0;if(this.aliases){for(let E of this.aliases[F])if(B(E))return!0}return!1}completeOptionKey(D,F,u,B){var E,C,$,z;let Z=D;if(this.zshShell){let X=this.usage.getDescriptions(),V=(C=(E=this===null||this===void 0?void 0:this.aliases)===null||E===void 0?void 0:E[D])===null||C===void 0?void 0:C.find((j)=>{let N=X[j];return typeof N==="string"&&N.length>0}),H=V?X[V]:void 0,W=(z=($=X[D])!==null&&$!==void 0?$:H)!==null&&z!==void 0?z:"";Z=`${D.replace(/:/g,"\\:")}:${W.replace("__yargsString__:","").replace(/(\r\n|\n|\r)/gm," ")}`}let J=(X)=>/^--/.test(X),Q=(X)=>/^[^0-9]$/.test(X),G=!J(u)&&Q(D)?"-":"--";if(F.push(G+Z),B)F.push(G+"no-"+Z)}customCompletion(D,F,u,B){if(KD(this.customCompletionFunction,null,this.shim),H7(this.customCompletionFunction)){let E=this.customCompletionFunction(u,F);if(DD(E))return E.then((C)=>{this.shim.process.nextTick(()=>{B(null,C)})}).catch((C)=>{this.shim.process.nextTick(()=>{B(C,void 0)})});return B(null,E)}else if(q7(this.customCompletionFunction))return this.customCompletionFunction(u,F,(E=B)=>this.defaultCompletion(D,F,u,E),(E)=>{B(null,E)});else return this.customCompletionFunction(u,F,(E)=>{B(null,E)})}getCompletion(D,F){let u=D.length?D[D.length-1]:"",B=this.yargs.parse(D,!0),E=this.customCompletionFunction?(C)=>this.customCompletion(D,C,u,F):(C)=>this.defaultCompletion(D,C,u,F);return DD(B)?B.then(E):E(B)}generateCompletionScript(D,F){let u=this.zshShell?I8:x8,B=this.shim.path.basename(D);if(D.match(/\.js$/))D=`./${D}`;return u=u.replace(/{{app_name}}/g,B),u=u.replace(/{{completion_command}}/g,F),u.replace(/{{app_path}}/g,D)}registerFunction(D){this.customCompletionFunction=D}setParsed(D){this.aliases=D.aliases}}function f8(D,F,u,B){return new b8(D,F,u,B)}function H7(D){return D.length<3}function q7(D){return D.length>3}function h8(D,F){if(D.length===0)return F.length;if(F.length===0)return D.length;let u=[],B;for(B=0;B<=F.length;B++)u[B]=[B];let E;for(E=0;E<=D.length;E++)u[0][E]=E;for(B=1;B<=F.length;B++)for(E=1;E<=D.length;E++)if(F.charAt(B-1)===D.charAt(E-1))u[B][E]=u[B-1][E-1];else if(B>1&&E>1&&F.charAt(B-2)===D.charAt(E-1)&&F.charAt(B-1)===D.charAt(E-2))u[B][E]=u[B-2][E-2]+1;else u[B][E]=Math.min(u[B-1][E-1]+1,Math.min(u[B][E-1]+1,u[B-1][E]+1));return u[F.length][D.length]}var v8=["$0","--","_"];function y8(D,F,u){let B=u.y18n.__,E=u.y18n.__n,C={};C.nonOptionCount=function(G){let X=D.getDemandedCommands(),H=G._.length+(G["--"]?G["--"].length:0)-D.getInternalMethods().getContext().commands.length;if(X._&&(H<X._.min||H>X._.max)){if(H<X._.min)if(X._.minMsg!==void 0)F.fail(X._.minMsg?X._.minMsg.replace(/\$0/g,H.toString()).replace(/\$1/,X._.min.toString()):null);else F.fail(E("Not enough non-option arguments: got %s, need at least %s","Not enough non-option arguments: got %s, need at least %s",H,H.toString(),X._.min.toString()));else if(H>X._.max)if(X._.maxMsg!==void 0)F.fail(X._.maxMsg?X._.maxMsg.replace(/\$0/g,H.toString()).replace(/\$1/,X._.max.toString()):null);else F.fail(E("Too many non-option arguments: got %s, maximum of %s","Too many non-option arguments: got %s, maximum of %s",H,H.toString(),X._.max.toString()))}},C.positionalCount=function(G,X){if(X<G)F.fail(E("Not enough non-option arguments: got %s, need at least %s","Not enough non-option arguments: got %s, need at least %s",X,X+"",G+""))},C.requiredArguments=function(G,X){let V=null;for(let H of Object.keys(X))if(!Object.prototype.hasOwnProperty.call(G,H)||typeof G[H]>"u")V=V||{},V[H]=X[H];if(V){let H=[];for(let j of Object.keys(V)){let N=V[j];if(N&&H.indexOf(N)<0)H.push(N)}let W=H.length?`
75
- ${H.join(`
76
- `)}`:"";F.fail(E("Missing required argument: %s","Missing required arguments: %s",Object.keys(V).length,Object.keys(V).join(", ")+W))}},C.unknownArguments=function(G,X,V,H,W=!0){var j;let N=D.getInternalMethods().getCommandInstance().getCommands(),O=[],T=D.getInternalMethods().getContext();if(Object.keys(G).forEach((M)=>{if(!v8.includes(M)&&!Object.prototype.hasOwnProperty.call(V,M)&&!Object.prototype.hasOwnProperty.call(D.getInternalMethods().getParseContext(),M)&&!C.isValidAndSomeAliasIsNotNew(M,X))O.push(M)}),W&&(T.commands.length>0||N.length>0||H))G._.slice(T.commands.length).forEach((M)=>{if(!N.includes(""+M))O.push(""+M)});if(W){let R=((j=D.getDemandedCommands()._)===null||j===void 0?void 0:j.max)||0,I=T.commands.length+R;if(I<G._.length)G._.slice(I).forEach((y)=>{if(y=String(y),!T.commands.includes(y)&&!O.includes(y))O.push(y)})}if(O.length)F.fail(E("Unknown argument: %s","Unknown arguments: %s",O.length,O.map((M)=>M.trim()?M:`"${M}"`).join(", ")))},C.unknownCommands=function(G){let X=D.getInternalMethods().getCommandInstance().getCommands(),V=[],H=D.getInternalMethods().getContext();if(H.commands.length>0||X.length>0)G._.slice(H.commands.length).forEach((W)=>{if(!X.includes(""+W))V.push(""+W)});if(V.length>0)return F.fail(E("Unknown command: %s","Unknown commands: %s",V.length,V.join(", "))),!0;else return!1},C.isValidAndSomeAliasIsNotNew=function(G,X){if(!Object.prototype.hasOwnProperty.call(X,G))return!1;let V=D.parsed.newAliases;return[G,...X[G]].some((H)=>!Object.prototype.hasOwnProperty.call(V,H)||!V[G])},C.limitedChoices=function(G){let X=D.getOptions(),V={};if(!Object.keys(X.choices).length)return;Object.keys(G).forEach((j)=>{if(v8.indexOf(j)===-1&&Object.prototype.hasOwnProperty.call(X.choices,j))[].concat(G[j]).forEach((N)=>{if(X.choices[j].indexOf(N)===-1&&N!==void 0)V[j]=(V[j]||[]).concat(N)})});let H=Object.keys(V);if(!H.length)return;let W=B("Invalid values:");H.forEach((j)=>{W+=`
77
- ${B("Argument: %s, Given: %s, Choices: %s",j,F.stringifiedValues(V[j]),F.stringifiedValues(X.choices[j]))}`}),F.fail(W)};let $={};C.implies=function(G,X){if(b("<string|object> [array|number|string]",[G,X],arguments.length),typeof G==="object")Object.keys(G).forEach((V)=>{C.implies(V,G[V])});else{if(D.global(G),!$[G])$[G]=[];if(Array.isArray(X))X.forEach((V)=>C.implies(G,V));else KD(X,void 0,u),$[G].push(X)}},C.getImplied=function(){return $};function z(Q,G){let X=Number(G);if(G=isNaN(X)?G:X,typeof G==="number")G=Q._.length>=G;else if(G.match(/^--no-.+/))G=G.match(/^--no-(.+)/)[1],G=!Object.prototype.hasOwnProperty.call(Q,G);else G=Object.prototype.hasOwnProperty.call(Q,G);return G}C.implications=function(G){let X=[];if(Object.keys($).forEach((V)=>{let H=V;($[V]||[]).forEach((W)=>{let j=H,N=W;if(j=z(G,j),W=z(G,W),j&&!W)X.push(` ${H} -> ${N}`)})}),X.length){let V=`${B("Implications failed:")}
78
- `;X.forEach((H)=>{V+=H}),F.fail(V)}};let Z={};C.conflicts=function(G,X){if(b("<string|object> [array|string]",[G,X],arguments.length),typeof G==="object")Object.keys(G).forEach((V)=>{C.conflicts(V,G[V])});else{if(D.global(G),!Z[G])Z[G]=[];if(Array.isArray(X))X.forEach((V)=>C.conflicts(G,V));else Z[G].push(X)}},C.getConflicting=()=>Z,C.conflicting=function(G){if(Object.keys(G).forEach((X)=>{if(Z[X])Z[X].forEach((V)=>{if(V&&G[X]!==void 0&&G[V]!==void 0)F.fail(B("Arguments %s and %s are mutually exclusive",X,V))})}),D.getInternalMethods().getParserConfiguration()["strip-dashed"])Object.keys(Z).forEach((X)=>{Z[X].forEach((V)=>{if(V&&G[u.Parser.camelCase(X)]!==void 0&&G[u.Parser.camelCase(V)]!==void 0)F.fail(B("Arguments %s and %s are mutually exclusive",X,V))})})},C.recommendCommands=function(G,X){X=X.sort((j,N)=>N.length-j.length);let H=null,W=1/0;for(let j=0,N;(N=X[j])!==void 0;j++){let O=h8(G,N);if(O<=3&&O<W)W=O,H=N}if(H)F.fail(B("Did you mean %s?",H))},C.reset=function(G){return $=rD($,(X)=>!G[X]),Z=rD(Z,(X)=>!G[X]),C};let J=[];return C.freeze=function(){J.push({implied:$,conflicting:Z})},C.unfreeze=function(){let G=J.pop();KD(G,void 0,u),{implied:$,conflicting:Z}=G},C}var Ou=[],iF;function lF(D,F,u,B){iF=B;let E={};if(Object.prototype.hasOwnProperty.call(D,"extends")){if(typeof D.extends!=="string")return E;let C=/\.json|\..*rc$/.test(D.extends),$=null;if(!C)try{$=import.meta.resolve(D.extends)}catch(z){return D}else $=U7(F,D.extends);j7($),Ou.push($),E=C?JSON.parse(iF.readFileSync($,"utf8")):B.require(D.extends),delete D.extends,E=lF(E,iF.path.dirname($),u,iF)}return Ou=[],u?p8(E,D):Object.assign({},E,D)}function j7(D){if(Ou.indexOf(D)>-1)throw new ZD(`Circular extended configurations: '${D}'.`)}function U7(D,F){return iF.path.resolve(D,F)}function p8(D,F){let u={};function B(E){return E&&typeof E==="object"&&!Array.isArray(E)}Object.assign(u,D);for(let E of Object.keys(F))if(B(F[E])&&B(u[E]))u[E]=p8(D[E],F[E]);else u[E]=F[E];return u}var f=function(D,F,u,B,E){if(B==="m")throw TypeError("Private method is not writable");if(B==="a"&&!E)throw TypeError("Private accessor was defined without a setter");if(typeof F==="function"?D!==F||!E:!F.has(D))throw TypeError("Cannot write private member to an object whose class did not declare it");return B==="a"?E.call(D,u):E?E.value=u:F.set(D,u),u},Y=function(D,F,u,B){if(u==="a"&&!B)throw TypeError("Private accessor was defined without a getter");if(typeof F==="function"?D!==F||!B:!F.has(D))throw TypeError("Cannot read private member from an object whose class did not declare it");return u==="m"?B:u==="a"?B.call(D):B?B.value:F.get(D)},JD,QF,nF,MD,ND,V0,eD,XF,H0,wD,q0,xD,cD,LD,ID,j0,YF,WD,m,U0,K0,AD,WF,IF,VF,DF,O0,i,HF,qF,jF,n,M0,kD,CD;function C1(D){return(F=[],u=D.process.cwd(),B)=>{let E=new $1(F,u,B,D);return Object.defineProperty(E,"argv",{get:()=>{return E.parse()},enumerable:!0}),E.help(),E.version(),E}}var m8=Symbol("copyDoubleDash"),g8=Symbol("copyDoubleDash"),Mu=Symbol("deleteFromParserHintObject"),c8=Symbol("emitWarning"),k8=Symbol("freeze"),d8=Symbol("getDollarZero"),UF=Symbol("getParserConfiguration"),i8=Symbol("getUsageConfiguration"),_u=Symbol("guessLocale"),l8=Symbol("guessVersion"),n8=Symbol("parsePositionalNumbers"),Nu=Symbol("pkgUp"),FF=Symbol("populateParserHintArray"),bF=Symbol("populateParserHintSingleValueDictionary"),Lu=Symbol("populateParserHintArrayDictionary"),Au=Symbol("populateParserHintDictionary"),Pu=Symbol("sanitizeKey"),Tu=Symbol("setKey"),Ru=Symbol("unfreeze"),t8=Symbol("validateAsync"),o8=Symbol("getCommandInstance"),s8=Symbol("getContext"),r8=Symbol("getHasOutput"),a8=Symbol("getLoggerInstance"),e8=Symbol("getParseContext"),D1=Symbol("getUsageInstance"),F1=Symbol("getValidationInstance"),_0=Symbol("hasParseCallback"),u1=Symbol("isGlobalContext"),KF=Symbol("postProcess"),E1=Symbol("rebase"),Su=Symbol("reset"),tF=Symbol("runYargsParserAndExecuteCommands"),wu=Symbol("runValidation"),B1=Symbol("setHasOutput"),OF=Symbol("kTrackManuallySetKeys"),K7="en_US";class $1{constructor(D=[],F,u,B){this.customScriptName=!1,this.parsed=!1,JD.set(this,void 0),QF.set(this,void 0),nF.set(this,{commands:[],fullCommands:[]}),MD.set(this,null),ND.set(this,null),V0.set(this,"show-hidden"),eD.set(this,null),XF.set(this,!0),H0.set(this,{}),wD.set(this,!0),q0.set(this,[]),xD.set(this,void 0),cD.set(this,{}),LD.set(this,!1),ID.set(this,null),j0.set(this,!0),YF.set(this,void 0),WD.set(this,""),m.set(this,void 0),U0.set(this,void 0),K0.set(this,{}),AD.set(this,null),WF.set(this,null),IF.set(this,{}),VF.set(this,{}),DF.set(this,void 0),O0.set(this,!1),i.set(this,void 0),HF.set(this,!1),qF.set(this,!1),jF.set(this,!1),n.set(this,void 0),M0.set(this,{}),kD.set(this,null),CD.set(this,void 0),f(this,i,B,"f"),f(this,DF,D,"f"),f(this,QF,F,"f"),f(this,U0,u,"f"),f(this,xD,new Uu(this),"f"),this.$0=this[d8](),this[Su](),f(this,JD,Y(this,JD,"f"),"f"),f(this,n,Y(this,n,"f"),"f"),f(this,CD,Y(this,CD,"f"),"f"),f(this,m,Y(this,m,"f"),"f"),Y(this,m,"f").showHiddenOpt=Y(this,V0,"f"),f(this,YF,this[g8](),"f"),Y(this,i,"f").y18n.setLocale(K7)}addHelpOpt(D,F){if(b("[string|boolean] [string]",[D,F],arguments.length),Y(this,ID,"f"))this[Mu](Y(this,ID,"f")),f(this,ID,null,"f");if(D===!1&&F===void 0)return this;return f(this,ID,typeof D==="string"?D:"help","f"),this.boolean(Y(this,ID,"f")),this.describe(Y(this,ID,"f"),F||Y(this,n,"f").deferY18nLookup("Show help")),this}help(D,F){return this.addHelpOpt(D,F)}addShowHiddenOpt(D,F){if(b("[string|boolean] [string]",[D,F],arguments.length),D===!1&&F===void 0)return this;let u=typeof D==="string"?D:Y(this,V0,"f");return this.boolean(u),this.describe(u,F||Y(this,n,"f").deferY18nLookup("Show hidden options")),Y(this,m,"f").showHiddenOpt=u,this}showHidden(D,F){return this.addShowHiddenOpt(D,F)}alias(D,F){return b("<object|string|array> [string|array]",[D,F],arguments.length),this[Lu](this.alias.bind(this),"alias",D,F),this}array(D){return b("<array|string>",[D],arguments.length),this[FF]("array",D),this[OF](D),this}boolean(D){return b("<array|string>",[D],arguments.length),this[FF]("boolean",D),this[OF](D),this}check(D,F){return b("<function> [boolean]",[D,F],arguments.length),this.middleware((u,B)=>{return GF(()=>{return D(u,B.getOptions())},(E)=>{if(!E)Y(this,n,"f").fail(Y(this,i,"f").y18n.__("Argument check failed: %s",D.toString()));else if(typeof E==="string"||E instanceof Error)Y(this,n,"f").fail(E.toString(),E);return u},(E)=>{return Y(this,n,"f").fail(E.message?E.message:E.toString(),E),u})},!1,F),this}choices(D,F){return b("<object|string|array> [string|array]",[D,F],arguments.length),this[Lu](this.choices.bind(this),"choices",D,F),this}coerce(D,F){if(b("<object|string|array> [function]",[D,F],arguments.length),Array.isArray(D)){if(!F)throw new ZD("coerce callback must be provided");for(let B of D)this.coerce(B,F);return this}else if(typeof D==="object"){for(let B of Object.keys(D))this.coerce(B,D[B]);return this}if(!F)throw new ZD("coerce callback must be provided");let u=D;return Y(this,m,"f").key[u]=!0,Y(this,xD,"f").addCoerceMiddleware((B,E)=>{var C;let $=(C=E.getAliases()[u])!==null&&C!==void 0?C:[],z=[u,...$].filter((Z)=>Object.prototype.hasOwnProperty.call(B,Z));if(z.length===0)return B;return GF(()=>{return F(B[z[0]])},(Z)=>{return z.forEach((J)=>{B[J]=Z}),B},(Z)=>{throw new ZD(Z.message)})},u),this}conflicts(D,F){return b("<string|object> [string|array]",[D,F],arguments.length),Y(this,CD,"f").conflicts(D,F),this}config(D="config",F,u){if(b("[object|string] [string|function] [function]",[D,F,u],arguments.length),typeof D==="object"&&!Array.isArray(D))return D=lF(D,Y(this,QF,"f"),this[UF]()["deep-merge-config"]||!1,Y(this,i,"f")),Y(this,m,"f").configObjects=(Y(this,m,"f").configObjects||[]).concat(D),this;if(typeof F==="function")u=F,F=void 0;return this.describe(D,F||Y(this,n,"f").deferY18nLookup("Path to JSON config file")),(Array.isArray(D)?D:[D]).forEach((B)=>{Y(this,m,"f").config[B]=u||!0}),this}completion(D,F,u){if(b("[string] [string|boolean|function] [function]",[D,F,u],arguments.length),typeof F==="function")u=F,F=void 0;if(f(this,ND,D||Y(this,ND,"f")||"completion","f"),!F&&F!==!1)F="generate completion script";if(this.command(Y(this,ND,"f"),F),u)Y(this,MD,"f").registerFunction(u);return this}command(D,F,u,B,E,C){return b("<string|array|object> [string|boolean] [function|object] [function] [array] [boolean|string]",[D,F,u,B,E,C],arguments.length),Y(this,JD,"f").addHandler(D,F,u,B,E,C),this}commands(D,F,u,B,E,C){return this.command(D,F,u,B,E,C)}commandDir(D,F){b("<string> [object]",[D,F],arguments.length);let u=Y(this,U0,"f")||Y(this,i,"f").require;return Y(this,JD,"f").addDirectory(D,u,Y(this,i,"f").getCallerFile(),F),this}count(D){return b("<array|string>",[D],arguments.length),this[FF]("count",D),this[OF](D),this}default(D,F,u){if(b("<object|string|array> [*] [string]",[D,F,u],arguments.length),u)ju(D,Y(this,i,"f")),Y(this,m,"f").defaultDescription[D]=u;if(typeof F==="function"){if(ju(D,Y(this,i,"f")),!Y(this,m,"f").defaultDescription[D])Y(this,m,"f").defaultDescription[D]=Y(this,n,"f").functionDescription(F);F=F.call()}return this[bF](this.default.bind(this),"default",D,F),this}defaults(D,F,u){return this.default(D,F,u)}demandCommand(D=1,F,u,B){if(b("[number] [number|string] [string|null|undefined] [string|null|undefined]",[D,F,u,B],arguments.length),typeof F!=="number")u=F,F=1/0;return this.global("_",!1),Y(this,m,"f").demandedCommands._={min:D,max:F,minMsg:u,maxMsg:B},this}demand(D,F,u){if(Array.isArray(F))F.forEach((B)=>{KD(u,!0,Y(this,i,"f")),this.demandOption(B,u)}),F=1/0;else if(typeof F!=="number")u=F,F=1/0;if(typeof D==="number")KD(u,!0,Y(this,i,"f")),this.demandCommand(D,F,u,u);else if(Array.isArray(D))D.forEach((B)=>{KD(u,!0,Y(this,i,"f")),this.demandOption(B,u)});else if(typeof u==="string")this.demandOption(D,u);else if(u===!0||typeof u>"u")this.demandOption(D);return this}demandOption(D,F){return b("<object|string|array> [string]",[D,F],arguments.length),this[bF](this.demandOption.bind(this),"demandedOptions",D,F),this}deprecateOption(D,F){return b("<string> [string|boolean]",[D,F],arguments.length),Y(this,m,"f").deprecatedOptions[D]=F,this}describe(D,F){return b("<object|string|array> [string]",[D,F],arguments.length),this[Tu](D,!0),Y(this,n,"f").describe(D,F),this}detectLocale(D){return b("<boolean>",[D],arguments.length),f(this,XF,D,"f"),this}env(D){if(b("[string|boolean]",[D],arguments.length),D===!1)delete Y(this,m,"f").envPrefix;else Y(this,m,"f").envPrefix=D||"";return this}epilogue(D){return b("<string>",[D],arguments.length),Y(this,n,"f").epilog(D),this}epilog(D){return this.epilogue(D)}example(D,F){if(b("<string|array> [string]",[D,F],arguments.length),Array.isArray(D))D.forEach((u)=>this.example(...u));else Y(this,n,"f").example(D,F);return this}exit(D,F){if(f(this,LD,!0,"f"),f(this,eD,F,"f"),Y(this,wD,"f"))Y(this,i,"f").process.exit(D)}exitProcess(D=!0){return b("[boolean]",[D],arguments.length),f(this,wD,D,"f"),this}fail(D){if(b("<function|boolean>",[D],arguments.length),typeof D==="boolean"&&D!==!1)throw new ZD("Invalid first argument. Expected function or boolean 'false'");return Y(this,n,"f").failFn(D),this}getAliases(){return this.parsed?this.parsed.aliases:{}}async getCompletion(D,F){if(b("<array> [function]",[D,F],arguments.length),!F)return new Promise((u,B)=>{Y(this,MD,"f").getCompletion(D,(E,C)=>{if(E)B(E);else u(C)})});else return Y(this,MD,"f").getCompletion(D,F)}getDemandedOptions(){return b([],0),Y(this,m,"f").demandedOptions}getDemandedCommands(){return b([],0),Y(this,m,"f").demandedCommands}getDeprecatedOptions(){return b([],0),Y(this,m,"f").deprecatedOptions}getDetectLocale(){return Y(this,XF,"f")}getExitProcess(){return Y(this,wD,"f")}getGroups(){return Object.assign({},Y(this,cD,"f"),Y(this,VF,"f"))}getHelp(){if(f(this,LD,!0,"f"),!Y(this,n,"f").hasCachedHelpMessage()){if(!this.parsed){let F=this[tF](Y(this,DF,"f"),void 0,void 0,0,!0);if(DD(F))return F.then(()=>{return Y(this,n,"f").help()})}let D=Y(this,JD,"f").runDefaultBuilderOn(this);if(DD(D))return D.then(()=>{return Y(this,n,"f").help()})}return Promise.resolve(Y(this,n,"f").help())}getOptions(){return Y(this,m,"f")}getStrict(){return Y(this,HF,"f")}getStrictCommands(){return Y(this,qF,"f")}getStrictOptions(){return Y(this,jF,"f")}global(D,F){if(b("<string|array> [boolean]",[D,F],arguments.length),D=[].concat(D),F!==!1)Y(this,m,"f").local=Y(this,m,"f").local.filter((u)=>D.indexOf(u)===-1);else D.forEach((u)=>{if(!Y(this,m,"f").local.includes(u))Y(this,m,"f").local.push(u)});return this}group(D,F){b("<string|array> <string>",[D,F],arguments.length);let u=Y(this,VF,"f")[F]||Y(this,cD,"f")[F];if(Y(this,VF,"f")[F])delete Y(this,VF,"f")[F];let B={};return Y(this,cD,"f")[F]=(u||[]).concat(D).filter((E)=>{if(B[E])return!1;return B[E]=!0}),this}hide(D){return b("<string>",[D],arguments.length),Y(this,m,"f").hiddenOptions.push(D),this}implies(D,F){return b("<string|object> [number|string|array]",[D,F],arguments.length),Y(this,CD,"f").implies(D,F),this}locale(D){if(b("[string]",[D],arguments.length),D===void 0)return this[_u](),Y(this,i,"f").y18n.getLocale();return f(this,XF,!1,"f"),Y(this,i,"f").y18n.setLocale(D),this}middleware(D,F,u){return Y(this,xD,"f").addMiddleware(D,!!F,u)}nargs(D,F){return b("<string|object|array> [number]",[D,F],arguments.length),this[bF](this.nargs.bind(this),"narg",D,F),this}normalize(D){return b("<array|string>",[D],arguments.length),this[FF]("normalize",D),this}number(D){return b("<array|string>",[D],arguments.length),this[FF]("number",D),this[OF](D),this}option(D,F){if(b("<string|object> [object]",[D,F],arguments.length),typeof D==="object")Object.keys(D).forEach((u)=>{this.options(u,D[u])});else{if(typeof F!=="object")F={};if(this[OF](D),Y(this,kD,"f")&&(D==="version"||(F===null||F===void 0?void 0:F.alias)==="version"))this[c8](['"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(Y(this,m,"f").key[D]=!0,F.alias)this.alias(D,F.alias);let u=F.deprecate||F.deprecated;if(u)this.deprecateOption(D,u);let B=F.demand||F.required||F.require;if(B)this.demand(D,B);if(F.demandOption)this.demandOption(D,typeof F.demandOption==="string"?F.demandOption:void 0);if(F.conflicts)this.conflicts(D,F.conflicts);if("default"in F)this.default(D,F.default);if(F.implies!==void 0)this.implies(D,F.implies);if(F.nargs!==void 0)this.nargs(D,F.nargs);if(F.config)this.config(D,F.configParser);if(F.normalize)this.normalize(D);if(F.choices)this.choices(D,F.choices);if(F.coerce)this.coerce(D,F.coerce);if(F.group)this.group(D,F.group);if(F.boolean||F.type==="boolean"){if(this.boolean(D),F.alias)this.boolean(F.alias)}if(F.array||F.type==="array"){if(this.array(D),F.alias)this.array(F.alias)}if(F.number||F.type==="number"){if(this.number(D),F.alias)this.number(F.alias)}if(F.string||F.type==="string"){if(this.string(D),F.alias)this.string(F.alias)}if(F.count||F.type==="count")this.count(D);if(typeof F.global==="boolean")this.global(D,F.global);if(F.defaultDescription)Y(this,m,"f").defaultDescription[D]=F.defaultDescription;if(F.skipValidation)this.skipValidation(D);let E=F.describe||F.description||F.desc,C=Y(this,n,"f").getDescriptions();if(!Object.prototype.hasOwnProperty.call(C,D)||typeof E==="string")this.describe(D,E);if(F.hidden)this.hide(D);if(F.requiresArg)this.requiresArg(D)}return this}options(D,F){return this.option(D,F)}parse(D,F,u){if(b("[string|array] [function|boolean|object] [function]",[D,F,u],arguments.length),this[k8](),typeof D>"u")D=Y(this,DF,"f");if(typeof F==="object")f(this,WF,F,"f"),F=u;if(typeof F==="function")f(this,AD,F,"f"),F=!1;if(!F)f(this,DF,D,"f");if(Y(this,AD,"f"))f(this,wD,!1,"f");let B=this[tF](D,!!F),E=this.parsed;if(Y(this,MD,"f").setParsed(this.parsed),DD(B))return B.then((C)=>{if(Y(this,AD,"f"))Y(this,AD,"f").call(this,Y(this,eD,"f"),C,Y(this,WD,"f"));return C}).catch((C)=>{if(Y(this,AD,"f"))Y(this,AD,"f")(C,this.parsed.argv,Y(this,WD,"f"));throw C}).finally(()=>{this[Ru](),this.parsed=E});else{if(Y(this,AD,"f"))Y(this,AD,"f").call(this,Y(this,eD,"f"),B,Y(this,WD,"f"));this[Ru](),this.parsed=E}return B}parseAsync(D,F,u){let B=this.parse(D,F,u);return!DD(B)?Promise.resolve(B):B}parseSync(D,F,u){let B=this.parse(D,F,u);if(DD(B))throw new ZD(".parseSync() must not be used with asynchronous builders, handlers, or middleware");return B}parserConfiguration(D){return b("<object>",[D],arguments.length),f(this,K0,D,"f"),this}pkgConf(D,F){b("<string> [string]",[D,F],arguments.length);let u=null,B=this[Nu](F||Y(this,QF,"f"));if(B[D]&&typeof B[D]==="object")u=lF(B[D],F||Y(this,QF,"f"),this[UF]()["deep-merge-config"]||!1,Y(this,i,"f")),Y(this,m,"f").configObjects=(Y(this,m,"f").configObjects||[]).concat(u);return this}positional(D,F){b("<string> <object>",[D,F],arguments.length);let u=["default","defaultDescription","implies","normalize","choices","conflicts","coerce","type","describe","desc","description","alias"];F=rD(F,(C,$)=>{if(C==="type"&&!["string","number","boolean"].includes($))return!1;return u.includes(C)});let B=Y(this,nF,"f").fullCommands[Y(this,nF,"f").fullCommands.length-1],E=B?Y(this,JD,"f").cmdToParseOptions(B):{array:[],alias:{},default:{},demand:{}};return wF(E).forEach((C)=>{let $=E[C];if(Array.isArray($)){if($.indexOf(D)!==-1)F[C]=!0}else if($[D]&&!(C in F))F[C]=$[D]}),this.group(D,Y(this,n,"f").getPositionalGroupName()),this.option(D,F)}recommendCommands(D=!0){return b("[boolean]",[D],arguments.length),f(this,O0,D,"f"),this}required(D,F,u){return this.demand(D,F,u)}require(D,F,u){return this.demand(D,F,u)}requiresArg(D){if(b("<array|string|object> [number]",[D],arguments.length),typeof D==="string"&&Y(this,m,"f").narg[D])return this;else this[bF](this.requiresArg.bind(this),"narg",D,NaN);return this}showCompletionScript(D,F){return b("[string] [string]",[D,F],arguments.length),D=D||this.$0,Y(this,YF,"f").log(Y(this,MD,"f").generateCompletionScript(D,F||Y(this,ND,"f")||"completion")),this}showHelp(D){if(b("[string|function]",[D],arguments.length),f(this,LD,!0,"f"),!Y(this,n,"f").hasCachedHelpMessage()){if(!this.parsed){let u=this[tF](Y(this,DF,"f"),void 0,void 0,0,!0);if(DD(u))return u.then(()=>{Y(this,n,"f").showHelp(D)}),this}let F=Y(this,JD,"f").runDefaultBuilderOn(this);if(DD(F))return F.then(()=>{Y(this,n,"f").showHelp(D)}),this}return Y(this,n,"f").showHelp(D),this}scriptName(D){return this.customScriptName=!0,this.$0=D,this}showHelpOnFail(D,F){return b("[boolean|string] [string]",[D,F],arguments.length),Y(this,n,"f").showHelpOnFail(D,F),this}showVersion(D){return b("[string|function]",[D],arguments.length),Y(this,n,"f").showVersion(D),this}skipValidation(D){return b("<array|string>",[D],arguments.length),this[FF]("skipValidation",D),this}strict(D){return b("[boolean]",[D],arguments.length),f(this,HF,D!==!1,"f"),this}strictCommands(D){return b("[boolean]",[D],arguments.length),f(this,qF,D!==!1,"f"),this}strictOptions(D){return b("[boolean]",[D],arguments.length),f(this,jF,D!==!1,"f"),this}string(D){return b("<array|string>",[D],arguments.length),this[FF]("string",D),this[OF](D),this}terminalWidth(){return b([],0),Y(this,i,"f").process.stdColumns}updateLocale(D){return this.updateStrings(D)}updateStrings(D){return b("<object>",[D],arguments.length),f(this,XF,!1,"f"),Y(this,i,"f").y18n.updateLocale(D),this}usage(D,F,u,B){if(b("<string|null|undefined> [string|boolean] [function|object] [function]",[D,F,u,B],arguments.length),F!==void 0)if(KD(D,null,Y(this,i,"f")),(D||"").match(/^\$0( |$)/))return this.command(D,F,u,B);else throw new ZD(".usage() description must start with $0 if being used as alias for .command()");else return Y(this,n,"f").usage(D),this}usageConfiguration(D){return b("<object>",[D],arguments.length),f(this,M0,D,"f"),this}version(D,F,u){if(b("[boolean|string] [string] [string]",[D,F,u],arguments.length),Y(this,kD,"f"))this[Mu](Y(this,kD,"f")),Y(this,n,"f").version(void 0),f(this,kD,null,"f");if(arguments.length===0)u=this[l8](),D="version";else if(arguments.length===1){if(D===!1)return this;u=D,D="version"}else if(arguments.length===2)u=F,F=void 0;return f(this,kD,typeof D==="string"?D:"version","f"),F=F||Y(this,n,"f").deferY18nLookup("Show version number"),Y(this,n,"f").version(u||void 0),this.boolean(Y(this,kD,"f")),this.describe(Y(this,kD,"f"),F),this}wrap(D){return b("<number|null|undefined>",[D],arguments.length),Y(this,n,"f").wrap(D),this}[(JD=new WeakMap,QF=new WeakMap,nF=new WeakMap,MD=new WeakMap,ND=new WeakMap,V0=new WeakMap,eD=new WeakMap,XF=new WeakMap,H0=new WeakMap,wD=new WeakMap,q0=new WeakMap,xD=new WeakMap,cD=new WeakMap,LD=new WeakMap,ID=new WeakMap,j0=new WeakMap,YF=new WeakMap,WD=new WeakMap,m=new WeakMap,U0=new WeakMap,K0=new WeakMap,AD=new WeakMap,WF=new WeakMap,IF=new WeakMap,VF=new WeakMap,DF=new WeakMap,O0=new WeakMap,i=new WeakMap,HF=new WeakMap,qF=new WeakMap,jF=new WeakMap,n=new WeakMap,M0=new WeakMap,kD=new WeakMap,CD=new WeakMap,m8)](D){if(!D._||!D["--"])return D;D._.push.apply(D._,D["--"]);try{delete D["--"]}catch(F){}return D}[g8](){return{log:(...D)=>{if(!this[_0]())console.log(...D);if(f(this,LD,!0,"f"),Y(this,WD,"f").length)f(this,WD,Y(this,WD,"f")+`
80
- `,"f");f(this,WD,Y(this,WD,"f")+D.join(" "),"f")},error:(...D)=>{if(!this[_0]())console.error(...D);if(f(this,LD,!0,"f"),Y(this,WD,"f").length)f(this,WD,Y(this,WD,"f")+`
81
- `,"f");f(this,WD,Y(this,WD,"f")+D.join(" "),"f")}}}[Mu](D){wF(Y(this,m,"f")).forEach((F)=>{if(((B)=>B==="configObjects")(F))return;let u=Y(this,m,"f")[F];if(Array.isArray(u)){if(u.includes(D))u.splice(u.indexOf(D),1)}else if(typeof u==="object")delete u[D]}),delete Y(this,n,"f").getDescriptions()[D]}[c8](D,F,u){if(!Y(this,H0,"f")[u])Y(this,i,"f").process.emitWarning(D,F),Y(this,H0,"f")[u]=!0}[k8](){Y(this,q0,"f").push({options:Y(this,m,"f"),configObjects:Y(this,m,"f").configObjects.slice(0),exitProcess:Y(this,wD,"f"),groups:Y(this,cD,"f"),strict:Y(this,HF,"f"),strictCommands:Y(this,qF,"f"),strictOptions:Y(this,jF,"f"),completionCommand:Y(this,ND,"f"),output:Y(this,WD,"f"),exitError:Y(this,eD,"f"),hasOutput:Y(this,LD,"f"),parsed:this.parsed,parseFn:Y(this,AD,"f"),parseContext:Y(this,WF,"f")}),Y(this,n,"f").freeze(),Y(this,CD,"f").freeze(),Y(this,JD,"f").freeze(),Y(this,xD,"f").freeze()}[d8](){let D="",F;if(/\b(node|iojs|electron)(\.exe)?$/.test(Y(this,i,"f").process.argv()[0]))F=Y(this,i,"f").process.argv().slice(1,2);else F=Y(this,i,"f").process.argv().slice(0,1);if(D=F.map((u)=>{let B=this[E1](Y(this,QF,"f"),u);return u.match(/^(\/|([a-zA-Z]:)?\\)/)&&B.length<u.length?B:u}).join(" ").trim(),Y(this,i,"f").getEnv("_")&&Y(this,i,"f").getProcessArgvBin()===Y(this,i,"f").getEnv("_"))D=Y(this,i,"f").getEnv("_").replace(`${Y(this,i,"f").path.dirname(Y(this,i,"f").process.execPath())}/`,"");return D}[UF](){return Y(this,K0,"f")}[i8](){return Y(this,M0,"f")}[_u](){if(!Y(this,XF,"f"))return;let D=Y(this,i,"f").getEnv("LC_ALL")||Y(this,i,"f").getEnv("LC_MESSAGES")||Y(this,i,"f").getEnv("LANG")||Y(this,i,"f").getEnv("LANGUAGE")||"en_US";this.locale(D.replace(/[.:].*/,""))}[l8](){return this[Nu]().version||"unknown"}[n8](D){let F=D["--"]?D["--"]:D._;for(let u=0,B;(B=F[u])!==void 0;u++)if(Y(this,i,"f").Parser.looksLikeNumber(B)&&Number.isSafeInteger(Math.floor(parseFloat(`${B}`))))F[u]=Number(B);return D}[Nu](D){let F=D||"*";if(Y(this,IF,"f")[F])return Y(this,IF,"f")[F];let u={};try{let B=D||Y(this,i,"f").mainFilename;if(Y(this,i,"f").path.extname(B))B=Y(this,i,"f").path.dirname(B);let E=Y(this,i,"f").findUp(B,(C,$)=>{if($.includes("package.json"))return"package.json";else return});KD(E,void 0,Y(this,i,"f")),u=JSON.parse(Y(this,i,"f").readFileSync(E,"utf8"))}catch(B){}return Y(this,IF,"f")[F]=u||{},Y(this,IF,"f")[F]}[FF](D,F){F=[].concat(F),F.forEach((u)=>{u=this[Pu](u),Y(this,m,"f")[D].push(u)})}[bF](D,F,u,B){this[Au](D,F,u,B,(E,C,$)=>{Y(this,m,"f")[E][C]=$})}[Lu](D,F,u,B){this[Au](D,F,u,B,(E,C,$)=>{Y(this,m,"f")[E][C]=(Y(this,m,"f")[E][C]||[]).concat($)})}[Au](D,F,u,B,E){if(Array.isArray(u))u.forEach((C)=>{D(C,B)});else if(((C)=>typeof C==="object")(u))for(let C of wF(u))D(C,u[C]);else E(F,this[Pu](u),B)}[Pu](D){if(D==="__proto__")return"___proto___";return D}[Tu](D,F){return this[bF](this[Tu].bind(this),"key",D,F),this}[Ru](){var D,F,u,B,E,C,$,z,Z,J,Q,G;let X=Y(this,q0,"f").pop();KD(X,void 0,Y(this,i,"f"));let V;D=this,F=this,u=this,B=this,E=this,C=this,$=this,z=this,Z=this,J=this,Q=this,G=this,{options:{set value(H){f(D,m,H,"f")}}.value,configObjects:V,exitProcess:{set value(H){f(F,wD,H,"f")}}.value,groups:{set value(H){f(u,cD,H,"f")}}.value,output:{set value(H){f(B,WD,H,"f")}}.value,exitError:{set value(H){f(E,eD,H,"f")}}.value,hasOutput:{set value(H){f(C,LD,H,"f")}}.value,parsed:this.parsed,strict:{set value(H){f($,HF,H,"f")}}.value,strictCommands:{set value(H){f(z,qF,H,"f")}}.value,strictOptions:{set value(H){f(Z,jF,H,"f")}}.value,completionCommand:{set value(H){f(J,ND,H,"f")}}.value,parseFn:{set value(H){f(Q,AD,H,"f")}}.value,parseContext:{set value(H){f(G,WF,H,"f")}}.value}=X,Y(this,m,"f").configObjects=V,Y(this,n,"f").unfreeze(),Y(this,CD,"f").unfreeze(),Y(this,JD,"f").unfreeze(),Y(this,xD,"f").unfreeze()}[t8](D,F){return GF(F,(u)=>{return D(u),u})}getInternalMethods(){return{getCommandInstance:this[o8].bind(this),getContext:this[s8].bind(this),getHasOutput:this[r8].bind(this),getLoggerInstance:this[a8].bind(this),getParseContext:this[e8].bind(this),getParserConfiguration:this[UF].bind(this),getUsageConfiguration:this[i8].bind(this),getUsageInstance:this[D1].bind(this),getValidationInstance:this[F1].bind(this),hasParseCallback:this[_0].bind(this),isGlobalContext:this[u1].bind(this),postProcess:this[KF].bind(this),reset:this[Su].bind(this),runValidation:this[wu].bind(this),runYargsParserAndExecuteCommands:this[tF].bind(this),setHasOutput:this[B1].bind(this)}}[o8](){return Y(this,JD,"f")}[s8](){return Y(this,nF,"f")}[r8](){return Y(this,LD,"f")}[a8](){return Y(this,YF,"f")}[e8](){return Y(this,WF,"f")||{}}[D1](){return Y(this,n,"f")}[F1](){return Y(this,CD,"f")}[_0](){return!!Y(this,AD,"f")}[u1](){return Y(this,j0,"f")}[KF](D,F,u,B){if(u)return D;if(DD(D))return D;if(!F)D=this[m8](D);if(this[UF]()["parse-positional-numbers"]||this[UF]()["parse-positional-numbers"]===void 0)D=this[n8](D);if(B)D=JF(D,this,Y(this,xD,"f").getMiddleware(),!1);return D}[Su](D={}){f(this,m,Y(this,m,"f")||{},"f");let F={};F.local=Y(this,m,"f").local||[],F.configObjects=Y(this,m,"f").configObjects||[];let u={};F.local.forEach((C)=>{u[C]=!0,(D[C]||[]).forEach(($)=>{u[$]=!0})}),Object.assign(Y(this,VF,"f"),Object.keys(Y(this,cD,"f")).reduce((C,$)=>{let z=Y(this,cD,"f")[$].filter((Z)=>!(Z in u));if(z.length>0)C[$]=z;return C},{})),f(this,cD,{},"f");let B=["array","boolean","string","skipValidation","count","normalize","number","hiddenOptions"],E=["narg","key","alias","default","defaultDescription","config","choices","demandedOptions","demandedCommands","deprecatedOptions"];if(B.forEach((C)=>{F[C]=(Y(this,m,"f")[C]||[]).filter(($)=>!u[$])}),E.forEach((C)=>{F[C]=rD(Y(this,m,"f")[C],($)=>!u[$])}),F.envPrefix=Y(this,m,"f").envPrefix,f(this,m,F,"f"),f(this,n,Y(this,n,"f")?Y(this,n,"f").reset(u):w8(this,Y(this,i,"f")),"f"),f(this,CD,Y(this,CD,"f")?Y(this,CD,"f").reset(u):y8(this,Y(this,n,"f"),Y(this,i,"f")),"f"),f(this,JD,Y(this,JD,"f")?Y(this,JD,"f").reset():T8(Y(this,n,"f"),Y(this,CD,"f"),Y(this,xD,"f"),Y(this,i,"f")),"f"),!Y(this,MD,"f"))f(this,MD,f8(this,Y(this,n,"f"),Y(this,JD,"f"),Y(this,i,"f")),"f");return Y(this,xD,"f").reset(),f(this,ND,null,"f"),f(this,WD,"","f"),f(this,eD,null,"f"),f(this,LD,!1,"f"),this.parsed=!1,this}[E1](D,F){return Y(this,i,"f").path.relative(D,F)}[tF](D,F,u,B=0,E=!1){var C,$,z,Z;let J=!!u||E;D=D||Y(this,DF,"f"),Y(this,m,"f").__=Y(this,i,"f").y18n.__,Y(this,m,"f").configuration=this[UF]();let Q=!!Y(this,m,"f").configuration["populate--"],G=Object.assign({},Y(this,m,"f").configuration,{"populate--":!0}),X=Y(this,i,"f").Parser.detailed(D,Object.assign({},Y(this,m,"f"),{configuration:{"parse-positional-numbers":!1,...G}})),V=Object.assign(X.argv,Y(this,WF,"f")),H=void 0,W=X.aliases,j=!1,N=!1;if(Object.keys(V).forEach((O)=>{if(O===Y(this,ID,"f")&&V[O])j=!0;else if(O===Y(this,kD,"f")&&V[O])N=!0}),V.$0=this.$0,this.parsed=X,B===0)Y(this,n,"f").clearCachedHelpMessage();try{if(this[_u](),F)return this[KF](V,Q,!!u,!1);if(Y(this,ID,"f")){if([Y(this,ID,"f")].concat(W[Y(this,ID,"f")]||[]).filter((I)=>I.length>1).includes(""+V._[V._.length-1]))V._.pop(),j=!0}f(this,j0,!1,"f");let O=Y(this,JD,"f").getCommands(),T=((C=Y(this,MD,"f"))===null||C===void 0?void 0:C.completionKey)?[($=Y(this,MD,"f"))===null||$===void 0?void 0:$.completionKey,...(Z=this.getAliases()[(z=Y(this,MD,"f"))===null||z===void 0?void 0:z.completionKey])!==null&&Z!==void 0?Z:[]].some((R)=>Object.prototype.hasOwnProperty.call(V,R)):!1,M=j||T||E;if(V._.length){if(O.length){let R;for(let I=B||0,y;V._[I]!==void 0;I++)if(y=String(V._[I]),O.includes(y)&&y!==Y(this,ND,"f")){let l=Y(this,JD,"f").runCommand(y,this,X,I+1,E,j||N||E);return this[KF](l,Q,!!u,!1)}else if(!R&&y!==Y(this,ND,"f")){R=y;break}if(!Y(this,JD,"f").hasDefaultCommand()&&Y(this,O0,"f")&&R&&!M)Y(this,CD,"f").recommendCommands(R,O)}if(Y(this,ND,"f")&&V._.includes(Y(this,ND,"f"))&&!T){if(Y(this,wD,"f"))aD(!0);this.showCompletionScript(),this.exit(0)}}if(Y(this,JD,"f").hasDefaultCommand()&&!M){let R=Y(this,JD,"f").runCommand(null,this,X,0,E,j||N||E);return this[KF](R,Q,!!u,!1)}if(T){if(Y(this,wD,"f"))aD(!0);D=[].concat(D);let R=D.slice(D.indexOf(`--${Y(this,MD,"f").completionKey}`)+1);return Y(this,MD,"f").getCompletion(R,(I,y)=>{if(I)throw new ZD(I.message);(y||[]).forEach((l)=>{Y(this,YF,"f").log(l)}),this.exit(0)}),this[KF](V,!Q,!!u,!1)}if(!Y(this,LD,"f")){if(j){if(Y(this,wD,"f"))aD(!0);J=!0,this.showHelp((R)=>{Y(this,YF,"f").log(R),this.exit(0)})}else if(N){if(Y(this,wD,"f"))aD(!0);J=!0,Y(this,n,"f").showVersion("log"),this.exit(0)}}if(!J&&Y(this,m,"f").skipValidation.length>0)J=Object.keys(V).some((R)=>Y(this,m,"f").skipValidation.indexOf(R)>=0&&V[R]===!0);if(!J){if(X.error)throw new ZD(X.error.message);if(!T){let R=this[wu](W,{},X.error);if(!u)H=JF(V,this,Y(this,xD,"f").getMiddleware(),!0);if(H=this[t8](R,H!==null&&H!==void 0?H:V),DD(H)&&!u)H=H.then(()=>{return JF(V,this,Y(this,xD,"f").getMiddleware(),!1)})}}}catch(O){if(O instanceof ZD)Y(this,n,"f").fail(O.message,O);else throw O}return this[KF](H!==null&&H!==void 0?H:V,Q,!!u,!0)}[wu](D,F,u,B){let E={...this.getDemandedOptions()};return(C)=>{if(u)throw new ZD(u.message);Y(this,CD,"f").nonOptionCount(C),Y(this,CD,"f").requiredArguments(C,E);let $=!1;if(Y(this,qF,"f"))$=Y(this,CD,"f").unknownCommands(C);if(Y(this,HF,"f")&&!$)Y(this,CD,"f").unknownArguments(C,D,F,!!B);else if(Y(this,jF,"f"))Y(this,CD,"f").unknownArguments(C,D,{},!1,!1);Y(this,CD,"f").limitedChoices(C),Y(this,CD,"f").implications(C),Y(this,CD,"f").conflicting(C)}}[B1](){f(this,LD,!0,"f")}[OF](D){if(typeof D==="string")Y(this,m,"f").key[D]=!0;else for(let F of D)Y(this,m,"f").key[F]=!0}}function R8(D){return!!D&&typeof D.getInternalMethods==="function"}var O7=C1(qu),z1=O7;import{existsSync as N0,readFileSync as bu,writeFileSync as xu,mkdirSync as G1}from"node:fs";import{homedir as M7}from"node:os";import{join as MF,dirname as fu}from"node:path";function hu(){return process.env.HOME||M7()}function Q1(){return MF(hu(),".config","slack-cli","profiles.json")}function L0(){return MF(process.cwd(),".slack-cli","workspace")}function A0(){return MF(hu(),".slack-cli","workspace")}function oF(){let D=Q1();if(!N0(D))return{profiles:{}};return JSON.parse(bu(D,"utf8"))}function _7(D){let F=Q1();G1(fu(F),{recursive:!0}),xu(F,JSON.stringify(D,null,2)+`
82
- `)}function fF(D){if(!N0(D))return;return bu(D,"utf8").trim()||void 0}function Z1(D,F){let u=fu(D);G1(u,{recursive:!0});let B=MF(u,".gitignore");if(!N0(B))xu(B,`*
83
- `);xu(D,F+`
84
- `)}function N7(D){let F={};for(let u of D.split(`
85
- `)){let B=u.trim();if(!B||B.startsWith("#"))continue;let E=B.indexOf("=");if(E===-1)continue;let C=B.slice(0,E).trim(),$=B.slice(E+1).trim();if($.startsWith('"')&&$.endsWith('"')||$.startsWith("'")&&$.endsWith("'"))$=$.slice(1,-1);F[C]=$}return F}function J1(D){if(!N0(D))return{};try{return N7(bu(D,"utf8"))}catch{return{}}}function Iu(D,F){let u=hu(),B=D;while(!0){for(let $ of[MF(B,".slack-term",".env.local"),MF(B,".env.local")]){let z=J1($);for(let Z of F)if(z[Z])return z[Z]}if(B===u)break;let C=fu(B);if(C===B)break;B=C}let E=J1(MF(u,".slack-term",".env.local"));for(let C of F)if(E[C])return E[C];return}function vu(){let D=oF(),F=fF(L0()),u=fF(A0()),B=F??u;return Object.entries(D.profiles).map(([E,C])=>({name:E,profile:C,current:E===B}))}function X1(D){let F=oF();if(!(D in F.profiles))throw Error(`Profile not found: ${D}`);delete F.profiles[D],_7(F)}function Y1(D,F=!1){let u=oF();if(!(D in u.profiles))throw Error(`Profile not found: ${D}`);if(F)Z1(A0(),D);else Z1(L0(),D)}function yu(D){let u=oF().profiles,B=Object.keys(u);if(D){let J=u[D];if(!J)throw Error(`Workspace "${D}" not found. Available: ${B.join(", ")||"(none)"}`);return J.token}if(process.env.SLACK_TOKEN)return process.env.SLACK_TOKEN;let E=process.env.SLACK_BOT_TOKEN??process.env.SLACK_MCP_XOXP_TOKEN;if(E&&B.length===0)return E;if(E&&B.length>0){let J=Iu(process.cwd(),["SLACK_BOT_TOKEN","SLACK_MCP_XOXP_TOKEN"]);if(E!==J){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 C=Iu(process.cwd(),["SLACK_TOKEN"]);if(C)return C;let $=process.env.SLACK_WORKSPACE;if($){let J=u[$];if(!J)throw Error(`Workspace "${$}" not found. Available: ${B.join(", ")||"(none)"}`);return J.token}let z=fF(L0());if(z){let J=u[z];if(!J)throw Error(`Workspace "${z}" (from .slack-cli/workspace) not found in profiles.`);return J.token}let Z=fF(A0());if(Z){let J=u[Z];if(!J)throw Error(`Workspace "${Z}" (from ~/.slack-cli/workspace) not found in profiles.`);return J.token}if(B.length>0)throw Error(`Workspace not selected (${B.join(", ")} available).
74
+ `;class no{constructor(e,t,n,i){var s,r,o;this.yargs=e,this.usage=t,this.command=n,this.shim=i,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"))||((r=this.shim.getEnv("ZSH_NAME"))===null||r===void 0?void 0:r.includes("zsh")))!==null&&o!==void 0?o:!1}defaultCompletion(e,t,n,i){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(kn(c)){this.indexAfterLastReset=o+1;let u=this.yargs.getInternalMethods().reset();return c(u,!0),u.argv}}let r=[];this.commandCompletions(r,e,n),this.optionCompletions(r,e,t,n),this.choicesFromOptionsCompletions(r,e,t,n),this.choicesFromPositionalsCompletions(r,e,t,n),i(null,r)}commandCompletions(e,t,n){let i=this.yargs.getInternalMethods().getContext().commands;if(!n.match(/^-/)&&i[i.length-1]!==n&&!this.previousArgHasChoices(t))this.usage.getCommands().forEach((s)=>{let r=nt(s[0]).cmd;if(t.indexOf(r)===-1)if(!this.zshShell)e.push(r);else{let o=s[1]||"";e.push(r.replace(/:/g,"\\:")+":"+o)}})}optionCompletions(e,t,n,i){if((i.match(/^-/)||i===""&&e.length===0)&&!this.previousArgHasChoices(t)){let s=this.yargs.getOptions(),r=this.yargs.getGroups()[this.usage.getPositionalGroupName()]||[];Object.keys(s.key).forEach((o)=>{let a=!!s.configuration["boolean-negation"]&&s.boolean.includes(o);if(!r.includes(o)&&!s.hiddenOptions.includes(o)&&!this.argsContainKey(t,o,a))this.completeOptionKey(o,e,i,a&&!!s.default[o])})}}choicesFromOptionsCompletions(e,t,n,i){if(this.previousArgHasChoices(t)){let s=this.getPreviousArgChoices(t);if(s&&s.length>0)e.push(...s.map((r)=>r.replace(/:/g,"\\:")))}}choicesFromPositionalsCompletions(e,t,n,i){if(i===""&&e.length>0&&this.previousArgHasChoices(t))return;let s=this.yargs.getGroups()[this.usage.getPositionalGroupName()]||[],r=Math.max(this.indexAfterLastReset,this.yargs.getInternalMethods().getContext().commands.length+1),o=s[n._.length-r-1];if(!o)return;let a=this.yargs.getOptions().choices[o]||[];for(let c of a)if(c.startsWith(i))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 i=t.replace(/^-+/,""),s=this.yargs.getOptions(),r=[i,...this.yargs.getAliases()[i]||[]],o;for(let a of r)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 i=(s)=>e.indexOf((/^[^0-9]$/.test(s)?"-":"--")+s)!==-1;if(i(t))return!0;if(n&&i(`no-${t}`))return!0;if(this.aliases){for(let s of this.aliases[t])if(i(s))return!0}return!1}completeOptionKey(e,t,n,i){var s,r,o,a;let c=e;if(this.zshShell){let d=this.usage.getDescriptions(),h=(r=(s=this===null||this===void 0?void 0:this.aliases)===null||s===void 0?void 0:s[e])===null||r===void 0?void 0:r.find((y)=>{let E=d[y];return typeof E==="string"&&E.length>0}),m=h?d[h]:void 0,p=(a=(o=d[e])!==null&&o!==void 0?o:m)!==null&&a!==void 0?a:"";c=`${e.replace(/:/g,"\\:")}:${p.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),i)t.push(l+"no-"+c)}customCompletion(e,t,n,i){if(Fe(this.customCompletionFunction,null,this.shim),Vu(this.customCompletionFunction)){let s=this.customCompletionFunction(n,t);if(ne(s))return s.then((r)=>{this.shim.process.nextTick(()=>{i(null,r)})}).catch((r)=>{this.shim.process.nextTick(()=>{i(r,void 0)})});return i(null,s)}else if(Zu(this.customCompletionFunction))return this.customCompletionFunction(n,t,(s=i)=>this.defaultCompletion(e,t,n,s),(s)=>{i(null,s)});else return this.customCompletionFunction(n,t,(s)=>{i(null,s)})}getCompletion(e,t){let n=e.length?e[e.length-1]:"",i=this.yargs.parse(e,!0),s=this.customCompletionFunction?(r)=>this.customCompletion(e,r,n,t):(r)=>this.defaultCompletion(e,r,n,t);return ne(i)?i.then(s):s(i)}generateCompletionScript(e,t){let n=this.zshShell?to:eo,i=this.shim.path.basename(e);if(e.match(/\.js$/))e=`./${e}`;return n=n.replace(/{{app_name}}/g,i),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 so(e,t,n,i){return new no(e,t,n,i)}function Vu(e){return e.length<3}function Zu(e){return e.length>3}function io(e,t){if(e.length===0)return t.length;if(t.length===0)return e.length;let n=[],i;for(i=0;i<=t.length;i++)n[i]=[i];let s;for(s=0;s<=e.length;s++)n[0][s]=s;for(i=1;i<=t.length;i++)for(s=1;s<=e.length;s++)if(t.charAt(i-1)===e.charAt(s-1))n[i][s]=n[i-1][s-1];else if(i>1&&s>1&&t.charAt(i-2)===e.charAt(s-1)&&t.charAt(i-1)===e.charAt(s-2))n[i][s]=n[i-2][s-2]+1;else n[i][s]=Math.min(n[i-1][s-1]+1,Math.min(n[i][s-1]+1,n[i-1][s]+1));return n[t.length][e.length]}var ro=["$0","--","_"];function oo(e,t,n){let i=n.y18n.__,s=n.y18n.__n,r={};r.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()))}},r.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+""))},r.requiredArguments=function(l,d){let h=null;for(let m of Object.keys(d))if(!Object.prototype.hasOwnProperty.call(l,m)||typeof l[m]>"u")h=h||{},h[m]=d[m];if(h){let m=[];for(let y of Object.keys(h)){let E=h[y];if(E&&m.indexOf(E)<0)m.push(E)}let p=m.length?`
75
+ ${m.join(`
76
+ `)}`:"";t.fail(s("Missing required argument: %s","Missing required arguments: %s",Object.keys(h).length,Object.keys(h).join(", ")+p))}},r.unknownArguments=function(l,d,h,m,p=!0){var y;let E=e.getInternalMethods().getCommandInstance().getCommands(),F=[],k=e.getInternalMethods().getContext();if(Object.keys(l).forEach((C)=>{if(!ro.includes(C)&&!Object.prototype.hasOwnProperty.call(h,C)&&!Object.prototype.hasOwnProperty.call(e.getInternalMethods().getParseContext(),C)&&!r.isValidAndSomeAliasIsNotNew(C,d))F.push(C)}),p&&(k.commands.length>0||E.length>0||m))l._.slice(k.commands.length).forEach((C)=>{if(!E.includes(""+C))F.push(""+C)});if(p){let A=((y=e.getDemandedCommands()._)===null||y===void 0?void 0:y.max)||0,T=k.commands.length+A;if(T<l._.length)l._.slice(T).forEach((v)=>{if(v=String(v),!k.commands.includes(v)&&!F.includes(v))F.push(v)})}if(F.length)t.fail(s("Unknown argument: %s","Unknown arguments: %s",F.length,F.map((C)=>C.trim()?C:`"${C}"`).join(", ")))},r.unknownCommands=function(l){let d=e.getInternalMethods().getCommandInstance().getCommands(),h=[],m=e.getInternalMethods().getContext();if(m.commands.length>0||d.length>0)l._.slice(m.commands.length).forEach((p)=>{if(!d.includes(""+p))h.push(""+p)});if(h.length>0)return t.fail(s("Unknown command: %s","Unknown commands: %s",h.length,h.join(", "))),!0;else return!1},r.isValidAndSomeAliasIsNotNew=function(l,d){if(!Object.prototype.hasOwnProperty.call(d,l))return!1;let h=e.parsed.newAliases;return[l,...d[l]].some((m)=>!Object.prototype.hasOwnProperty.call(h,m)||!h[l])},r.limitedChoices=function(l){let d=e.getOptions(),h={};if(!Object.keys(d.choices).length)return;Object.keys(l).forEach((y)=>{if(ro.indexOf(y)===-1&&Object.prototype.hasOwnProperty.call(d.choices,y))[].concat(l[y]).forEach((E)=>{if(d.choices[y].indexOf(E)===-1&&E!==void 0)h[y]=(h[y]||[]).concat(E)})});let m=Object.keys(h);if(!m.length)return;let p=i("Invalid values:");m.forEach((y)=>{p+=`
77
+ ${i("Argument: %s, Given: %s, Choices: %s",y,t.stringifiedValues(h[y]),t.stringifiedValues(d.choices[y]))}`}),t.fail(p)};let o={};r.implies=function(l,d){if(B("<string|object> [array|number|string]",[l,d],arguments.length),typeof l==="object")Object.keys(l).forEach((h)=>{r.implies(h,l[h])});else{if(e.global(l),!o[l])o[l]=[];if(Array.isArray(d))d.forEach((h)=>r.implies(l,h));else Fe(d,void 0,n),o[l].push(d)}},r.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}r.implications=function(l){let d=[];if(Object.keys(o).forEach((h)=>{let m=h;(o[h]||[]).forEach((p)=>{let y=m,E=p;if(y=a(l,y),p=a(l,p),y&&!p)d.push(` ${m} -> ${E}`)})}),d.length){let h=`${i("Implications failed:")}
78
+ `;d.forEach((m)=>{h+=m}),t.fail(h)}};let c={};r.conflicts=function(l,d){if(B("<string|object> [array|string]",[l,d],arguments.length),typeof l==="object")Object.keys(l).forEach((h)=>{r.conflicts(h,l[h])});else{if(e.global(l),!c[l])c[l]=[];if(Array.isArray(d))d.forEach((h)=>r.conflicts(l,h));else c[l].push(d)}},r.getConflicting=()=>c,r.conflicting=function(l){if(Object.keys(l).forEach((d)=>{if(c[d])c[d].forEach((h)=>{if(h&&l[d]!==void 0&&l[h]!==void 0)t.fail(i("Arguments %s and %s are mutually exclusive",d,h))})}),e.getInternalMethods().getParserConfiguration()["strip-dashed"])Object.keys(c).forEach((d)=>{c[d].forEach((h)=>{if(h&&l[n.Parser.camelCase(d)]!==void 0&&l[n.Parser.camelCase(h)]!==void 0)t.fail(i("Arguments %s and %s are mutually exclusive",d,h))})})},r.recommendCommands=function(l,d){d=d.sort((y,E)=>E.length-y.length);let m=null,p=1/0;for(let y=0,E;(E=d[y])!==void 0;y++){let F=io(l,E);if(F<=3&&F<p)p=F,m=E}if(m)t.fail(i("Did you mean %s?",m))},r.reset=function(l){return o=st(o,(d)=>!l[d]),c=st(c,(d)=>!l[d]),r};let u=[];return r.freeze=function(){u.push({implied:o,conflicting:c})},r.unfreeze=function(){let l=u.pop();Fe(l,void 0,n),{implied:o,conflicting:c}=l},r}var Ns=[],Qt;function en(e,t,n,i){Qt=i;let s={};if(Object.prototype.hasOwnProperty.call(e,"extends")){if(typeof e.extends!=="string")return s;let r=/\.json|\..*rc$/.test(e.extends),o=null;if(!r)try{o=import.meta.resolve(e.extends)}catch(a){return e}else o=el(t,e.extends);Qu(o),Ns.push(o),s=r?JSON.parse(Qt.readFileSync(o,"utf8")):i.require(e.extends),delete e.extends,s=en(s,Qt.path.dirname(o),n,Qt)}return Ns=[],n?ao(s,e):Object.assign({},s,e)}function Qu(e){if(Ns.indexOf(e)>-1)throw new le(`Circular extended configurations: '${e}'.`)}function el(e,t){return Qt.path.resolve(e,t)}function ao(e,t){let n={};function i(s){return s&&typeof s==="object"&&!Array.isArray(s)}Object.assign(n,e);for(let s of Object.keys(t))if(i(t[s])&&i(n[s]))n[s]=ao(e[s],t[s]);else n[s]=t[s];return n}var N=function(e,t,n,i,s){if(i==="m")throw TypeError("Private method is not writable");if(i==="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 i==="a"?s.call(e,n):s?s.value=n:t.set(e,n),n},g=function(e,t,n,i){if(n==="a"&&!i)throw TypeError("Private accessor was defined without a getter");if(typeof t==="function"?e!==t||!i:!t.has(e))throw TypeError("Cannot read private member from an object whose class did not declare it");return n==="m"?i:n==="a"?i.call(e):i?i.value:t.get(e)},fe,mt,tn,Ee,_e,$n,rt,Dt,On,Pe,In,Te,Ye,Se,Re,Pn,yt,me,U,Tn,Rn,ke,wt,Wt,bt,ot,Mn,q,Ft,Ct,Et,Y,Bn,Xe,ce;function Ao(e){return(t=[],n=e.process.cwd(),i)=>{let s=new $o(t,n,i,e);return Object.defineProperty(s,"argv",{get:()=>s.parse(),enumerable:!0}),s.help(),s.version(),s}}var co=Symbol("copyDoubleDash"),uo=Symbol("copyDoubleDash"),vs=Symbol("deleteFromParserHintObject"),lo=Symbol("emitWarning"),fo=Symbol("freeze"),po=Symbol("getDollarZero"),xt=Symbol("getParserConfiguration"),ho=Symbol("getUsageConfiguration"),js=Symbol("guessLocale"),go=Symbol("guessVersion"),mo=Symbol("parsePositionalNumbers"),Ls=Symbol("pkgUp"),at=Symbol("populateParserHintArray"),Ut=Symbol("populateParserHintSingleValueDictionary"),Ws=Symbol("populateParserHintArrayDictionary"),Us=Symbol("populateParserHintDictionary"),Js=Symbol("sanitizeKey"),Ks=Symbol("setKey"),zs=Symbol("unfreeze"),Do=Symbol("validateAsync"),yo=Symbol("getCommandInstance"),wo=Symbol("getContext"),bo=Symbol("getHasOutput"),Fo=Symbol("getLoggerInstance"),Co=Symbol("getParseContext"),Eo=Symbol("getUsageInstance"),xo=Symbol("getValidationInstance"),Nn=Symbol("hasParseCallback"),_o=Symbol("isGlobalContext"),_t=Symbol("postProcess"),So=Symbol("rebase"),Hs=Symbol("reset"),nn=Symbol("runYargsParserAndExecuteCommands"),qs=Symbol("runValidation"),ko=Symbol("setHasOutput"),St=Symbol("kTrackManuallySetKeys"),tl="en_US";class $o{constructor(e=[],t,n,i){this.customScriptName=!1,this.parsed=!1,fe.set(this,void 0),mt.set(this,void 0),tn.set(this,{commands:[],fullCommands:[]}),Ee.set(this,null),_e.set(this,null),$n.set(this,"show-hidden"),rt.set(this,null),Dt.set(this,!0),On.set(this,{}),Pe.set(this,!0),In.set(this,[]),Te.set(this,void 0),Ye.set(this,{}),Se.set(this,!1),Re.set(this,null),Pn.set(this,!0),yt.set(this,void 0),me.set(this,""),U.set(this,void 0),Tn.set(this,void 0),Rn.set(this,{}),ke.set(this,null),wt.set(this,null),Wt.set(this,{}),bt.set(this,{}),ot.set(this,void 0),Mn.set(this,!1),q.set(this,void 0),Ft.set(this,!1),Ct.set(this,!1),Et.set(this,!1),Y.set(this,void 0),Bn.set(this,{}),Xe.set(this,null),ce.set(this,void 0),N(this,q,i,"f"),N(this,ot,e,"f"),N(this,mt,t,"f"),N(this,Tn,n,"f"),N(this,Te,new Ms(this),"f"),this.$0=this[po](),this[Hs](),N(this,fe,g(this,fe,"f"),"f"),N(this,Y,g(this,Y,"f"),"f"),N(this,ce,g(this,ce,"f"),"f"),N(this,U,g(this,U,"f"),"f"),g(this,U,"f").showHiddenOpt=g(this,$n,"f"),N(this,yt,this[uo](),"f"),g(this,q,"f").y18n.setLocale(tl)}addHelpOpt(e,t){if(B("[string|boolean] [string]",[e,t],arguments.length),g(this,Re,"f"))this[vs](g(this,Re,"f")),N(this,Re,null,"f");if(e===!1&&t===void 0)return this;return N(this,Re,typeof e==="string"?e:"help","f"),this.boolean(g(this,Re,"f")),this.describe(g(this,Re,"f"),t||g(this,Y,"f").deferY18nLookup("Show help")),this}help(e,t){return this.addHelpOpt(e,t)}addShowHiddenOpt(e,t){if(B("[string|boolean] [string]",[e,t],arguments.length),e===!1&&t===void 0)return this;let n=typeof e==="string"?e:g(this,$n,"f");return this.boolean(n),this.describe(n,t||g(this,Y,"f").deferY18nLookup("Show hidden options")),g(this,U,"f").showHiddenOpt=n,this}showHidden(e,t){return this.addShowHiddenOpt(e,t)}alias(e,t){return B("<object|string|array> [string|array]",[e,t],arguments.length),this[Ws](this.alias.bind(this),"alias",e,t),this}array(e){return B("<array|string>",[e],arguments.length),this[at]("array",e),this[St](e),this}boolean(e){return B("<array|string>",[e],arguments.length),this[at]("boolean",e),this[St](e),this}check(e,t){return B("<function> [boolean]",[e,t],arguments.length),this.middleware((n,i)=>gt(()=>e(n,i.getOptions()),(s)=>{if(!s)g(this,Y,"f").fail(g(this,q,"f").y18n.__("Argument check failed: %s",e.toString()));else if(typeof s==="string"||s instanceof Error)g(this,Y,"f").fail(s.toString(),s);return n},(s)=>(g(this,Y,"f").fail(s.message?s.message:s.toString(),s),n)),!1,t),this}choices(e,t){return B("<object|string|array> [string|array]",[e,t],arguments.length),this[Ws](this.choices.bind(this),"choices",e,t),this}coerce(e,t){if(B("<object|string|array> [function]",[e,t],arguments.length),Array.isArray(e)){if(!t)throw new le("coerce callback must be provided");for(let i of e)this.coerce(i,t);return this}else if(typeof e==="object"){for(let i of Object.keys(e))this.coerce(i,e[i]);return this}if(!t)throw new le("coerce callback must be provided");let n=e;return g(this,U,"f").key[n]=!0,g(this,Te,"f").addCoerceMiddleware((i,s)=>{var r;let o=(r=s.getAliases()[n])!==null&&r!==void 0?r:[],a=[n,...o].filter((c)=>Object.prototype.hasOwnProperty.call(i,c));if(a.length===0)return i;return gt(()=>t(i[a[0]]),(c)=>(a.forEach((u)=>{i[u]=c}),i),(c)=>{throw new le(c.message)})},n),this}conflicts(e,t){return B("<string|object> [string|array]",[e,t],arguments.length),g(this,ce,"f").conflicts(e,t),this}config(e="config",t,n){if(B("[object|string] [string|function] [function]",[e,t,n],arguments.length),typeof e==="object"&&!Array.isArray(e))return e=en(e,g(this,mt,"f"),this[xt]()["deep-merge-config"]||!1,g(this,q,"f")),g(this,U,"f").configObjects=(g(this,U,"f").configObjects||[]).concat(e),this;if(typeof t==="function")n=t,t=void 0;return this.describe(e,t||g(this,Y,"f").deferY18nLookup("Path to JSON config file")),(Array.isArray(e)?e:[e]).forEach((i)=>{g(this,U,"f").config[i]=n||!0}),this}completion(e,t,n){if(B("[string] [string|boolean|function] [function]",[e,t,n],arguments.length),typeof t==="function")n=t,t=void 0;if(N(this,_e,e||g(this,_e,"f")||"completion","f"),!t&&t!==!1)t="generate completion script";if(this.command(g(this,_e,"f"),t),n)g(this,Ee,"f").registerFunction(n);return this}command(e,t,n,i,s,r){return B("<string|array|object> [string|boolean] [function|object] [function] [array] [boolean|string]",[e,t,n,i,s,r],arguments.length),g(this,fe,"f").addHandler(e,t,n,i,s,r),this}commands(e,t,n,i,s,r){return this.command(e,t,n,i,s,r)}commandDir(e,t){B("<string> [object]",[e,t],arguments.length);let n=g(this,Tn,"f")||g(this,q,"f").require;return g(this,fe,"f").addDirectory(e,n,g(this,q,"f").getCallerFile(),t),this}count(e){return B("<array|string>",[e],arguments.length),this[at]("count",e),this[St](e),this}default(e,t,n){if(B("<object|string|array> [*] [string]",[e,t,n],arguments.length),n)Rs(e,g(this,q,"f")),g(this,U,"f").defaultDescription[e]=n;if(typeof t==="function"){if(Rs(e,g(this,q,"f")),!g(this,U,"f").defaultDescription[e])g(this,U,"f").defaultDescription[e]=g(this,Y,"f").functionDescription(t);t=t.call()}return this[Ut](this.default.bind(this),"default",e,t),this}defaults(e,t,n){return this.default(e,t,n)}demandCommand(e=1,t,n,i){if(B("[number] [number|string] [string|null|undefined] [string|null|undefined]",[e,t,n,i],arguments.length),typeof t!=="number")n=t,t=1/0;return this.global("_",!1),g(this,U,"f").demandedCommands._={min:e,max:t,minMsg:n,maxMsg:i},this}demand(e,t,n){if(Array.isArray(t))t.forEach((i)=>{Fe(n,!0,g(this,q,"f")),this.demandOption(i,n)}),t=1/0;else if(typeof t!=="number")n=t,t=1/0;if(typeof e==="number")Fe(n,!0,g(this,q,"f")),this.demandCommand(e,t,n,n);else if(Array.isArray(e))e.forEach((i)=>{Fe(n,!0,g(this,q,"f")),this.demandOption(i,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 B("<object|string|array> [string]",[e,t],arguments.length),this[Ut](this.demandOption.bind(this),"demandedOptions",e,t),this}deprecateOption(e,t){return B("<string> [string|boolean]",[e,t],arguments.length),g(this,U,"f").deprecatedOptions[e]=t,this}describe(e,t){return B("<object|string|array> [string]",[e,t],arguments.length),this[Ks](e,!0),g(this,Y,"f").describe(e,t),this}detectLocale(e){return B("<boolean>",[e],arguments.length),N(this,Dt,e,"f"),this}env(e){if(B("[string|boolean]",[e],arguments.length),e===!1)delete g(this,U,"f").envPrefix;else g(this,U,"f").envPrefix=e||"";return this}epilogue(e){return B("<string>",[e],arguments.length),g(this,Y,"f").epilog(e),this}epilog(e){return this.epilogue(e)}example(e,t){if(B("<string|array> [string]",[e,t],arguments.length),Array.isArray(e))e.forEach((n)=>this.example(...n));else g(this,Y,"f").example(e,t);return this}exit(e,t){if(N(this,Se,!0,"f"),N(this,rt,t,"f"),g(this,Pe,"f"))g(this,q,"f").process.exit(e)}exitProcess(e=!0){return B("[boolean]",[e],arguments.length),N(this,Pe,e,"f"),this}fail(e){if(B("<function|boolean>",[e],arguments.length),typeof e==="boolean"&&e!==!1)throw new le("Invalid first argument. Expected function or boolean 'false'");return g(this,Y,"f").failFn(e),this}getAliases(){return this.parsed?this.parsed.aliases:{}}async getCompletion(e,t){if(B("<array> [function]",[e,t],arguments.length),!t)return new Promise((n,i)=>{g(this,Ee,"f").getCompletion(e,(s,r)=>{if(s)i(s);else n(r)})});else return g(this,Ee,"f").getCompletion(e,t)}getDemandedOptions(){return B([],0),g(this,U,"f").demandedOptions}getDemandedCommands(){return B([],0),g(this,U,"f").demandedCommands}getDeprecatedOptions(){return B([],0),g(this,U,"f").deprecatedOptions}getDetectLocale(){return g(this,Dt,"f")}getExitProcess(){return g(this,Pe,"f")}getGroups(){return Object.assign({},g(this,Ye,"f"),g(this,bt,"f"))}getHelp(){if(N(this,Se,!0,"f"),!g(this,Y,"f").hasCachedHelpMessage()){if(!this.parsed){let t=this[nn](g(this,ot,"f"),void 0,void 0,0,!0);if(ne(t))return t.then(()=>g(this,Y,"f").help())}let e=g(this,fe,"f").runDefaultBuilderOn(this);if(ne(e))return e.then(()=>g(this,Y,"f").help())}return Promise.resolve(g(this,Y,"f").help())}getOptions(){return g(this,U,"f")}getStrict(){return g(this,Ft,"f")}getStrictCommands(){return g(this,Ct,"f")}getStrictOptions(){return g(this,Et,"f")}global(e,t){if(B("<string|array> [boolean]",[e,t],arguments.length),e=[].concat(e),t!==!1)g(this,U,"f").local=g(this,U,"f").local.filter((n)=>e.indexOf(n)===-1);else e.forEach((n)=>{if(!g(this,U,"f").local.includes(n))g(this,U,"f").local.push(n)});return this}group(e,t){B("<string|array> <string>",[e,t],arguments.length);let n=g(this,bt,"f")[t]||g(this,Ye,"f")[t];if(g(this,bt,"f")[t])delete g(this,bt,"f")[t];let i={};return g(this,Ye,"f")[t]=(n||[]).concat(e).filter((s)=>{if(i[s])return!1;return i[s]=!0}),this}hide(e){return B("<string>",[e],arguments.length),g(this,U,"f").hiddenOptions.push(e),this}implies(e,t){return B("<string|object> [number|string|array]",[e,t],arguments.length),g(this,ce,"f").implies(e,t),this}locale(e){if(B("[string]",[e],arguments.length),e===void 0)return this[js](),g(this,q,"f").y18n.getLocale();return N(this,Dt,!1,"f"),g(this,q,"f").y18n.setLocale(e),this}middleware(e,t,n){return g(this,Te,"f").addMiddleware(e,!!t,n)}nargs(e,t){return B("<string|object|array> [number]",[e,t],arguments.length),this[Ut](this.nargs.bind(this),"narg",e,t),this}normalize(e){return B("<array|string>",[e],arguments.length),this[at]("normalize",e),this}number(e){return B("<array|string>",[e],arguments.length),this[at]("number",e),this[St](e),this}option(e,t){if(B("<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),g(this,Xe,"f")&&(e==="version"||(t===null||t===void 0?void 0:t.alias)==="version"))this[lo](['"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(g(this,U,"f").key[e]=!0,t.alias)this.alias(e,t.alias);let n=t.deprecate||t.deprecated;if(n)this.deprecateOption(e,n);let i=t.demand||t.required||t.require;if(i)this.demand(e,i);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)g(this,U,"f").defaultDescription[e]=t.defaultDescription;if(t.skipValidation)this.skipValidation(e);let s=t.describe||t.description||t.desc,r=g(this,Y,"f").getDescriptions();if(!Object.prototype.hasOwnProperty.call(r,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(B("[string|array] [function|boolean|object] [function]",[e,t,n],arguments.length),this[fo](),typeof e>"u")e=g(this,ot,"f");if(typeof t==="object")N(this,wt,t,"f"),t=n;if(typeof t==="function")N(this,ke,t,"f"),t=!1;if(!t)N(this,ot,e,"f");if(g(this,ke,"f"))N(this,Pe,!1,"f");let i=this[nn](e,!!t),s=this.parsed;if(g(this,Ee,"f").setParsed(this.parsed),ne(i))return i.then((r)=>{if(g(this,ke,"f"))g(this,ke,"f").call(this,g(this,rt,"f"),r,g(this,me,"f"));return r}).catch((r)=>{if(g(this,ke,"f"))g(this,ke,"f")(r,this.parsed.argv,g(this,me,"f"));throw r}).finally(()=>{this[zs](),this.parsed=s});else{if(g(this,ke,"f"))g(this,ke,"f").call(this,g(this,rt,"f"),i,g(this,me,"f"));this[zs](),this.parsed=s}return i}parseAsync(e,t,n){let i=this.parse(e,t,n);return!ne(i)?Promise.resolve(i):i}parseSync(e,t,n){let i=this.parse(e,t,n);if(ne(i))throw new le(".parseSync() must not be used with asynchronous builders, handlers, or middleware");return i}parserConfiguration(e){return B("<object>",[e],arguments.length),N(this,Rn,e,"f"),this}pkgConf(e,t){B("<string> [string]",[e,t],arguments.length);let n=null,i=this[Ls](t||g(this,mt,"f"));if(i[e]&&typeof i[e]==="object")n=en(i[e],t||g(this,mt,"f"),this[xt]()["deep-merge-config"]||!1,g(this,q,"f")),g(this,U,"f").configObjects=(g(this,U,"f").configObjects||[]).concat(n);return this}positional(e,t){B("<string> <object>",[e,t],arguments.length);let n=["default","defaultDescription","implies","normalize","choices","conflicts","coerce","type","describe","desc","description","alias"];t=st(t,(r,o)=>{if(r==="type"&&!["string","number","boolean"].includes(o))return!1;return n.includes(r)});let i=g(this,tn,"f").fullCommands[g(this,tn,"f").fullCommands.length-1],s=i?g(this,fe,"f").cmdToParseOptions(i):{array:[],alias:{},default:{},demand:{}};return jt(s).forEach((r)=>{let o=s[r];if(Array.isArray(o)){if(o.indexOf(e)!==-1)t[r]=!0}else if(o[e]&&!(r in t))t[r]=o[e]}),this.group(e,g(this,Y,"f").getPositionalGroupName()),this.option(e,t)}recommendCommands(e=!0){return B("[boolean]",[e],arguments.length),N(this,Mn,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(B("<array|string|object> [number]",[e],arguments.length),typeof e==="string"&&g(this,U,"f").narg[e])return this;else this[Ut](this.requiresArg.bind(this),"narg",e,NaN);return this}showCompletionScript(e,t){return B("[string] [string]",[e,t],arguments.length),e=e||this.$0,g(this,yt,"f").log(g(this,Ee,"f").generateCompletionScript(e,t||g(this,_e,"f")||"completion")),this}showHelp(e){if(B("[string|function]",[e],arguments.length),N(this,Se,!0,"f"),!g(this,Y,"f").hasCachedHelpMessage()){if(!this.parsed){let n=this[nn](g(this,ot,"f"),void 0,void 0,0,!0);if(ne(n))return n.then(()=>{g(this,Y,"f").showHelp(e)}),this}let t=g(this,fe,"f").runDefaultBuilderOn(this);if(ne(t))return t.then(()=>{g(this,Y,"f").showHelp(e)}),this}return g(this,Y,"f").showHelp(e),this}scriptName(e){return this.customScriptName=!0,this.$0=e,this}showHelpOnFail(e,t){return B("[boolean|string] [string]",[e,t],arguments.length),g(this,Y,"f").showHelpOnFail(e,t),this}showVersion(e){return B("[string|function]",[e],arguments.length),g(this,Y,"f").showVersion(e),this}skipValidation(e){return B("<array|string>",[e],arguments.length),this[at]("skipValidation",e),this}strict(e){return B("[boolean]",[e],arguments.length),N(this,Ft,e!==!1,"f"),this}strictCommands(e){return B("[boolean]",[e],arguments.length),N(this,Ct,e!==!1,"f"),this}strictOptions(e){return B("[boolean]",[e],arguments.length),N(this,Et,e!==!1,"f"),this}string(e){return B("<array|string>",[e],arguments.length),this[at]("string",e),this[St](e),this}terminalWidth(){return B([],0),g(this,q,"f").process.stdColumns}updateLocale(e){return this.updateStrings(e)}updateStrings(e){return B("<object>",[e],arguments.length),N(this,Dt,!1,"f"),g(this,q,"f").y18n.updateLocale(e),this}usage(e,t,n,i){if(B("<string|null|undefined> [string|boolean] [function|object] [function]",[e,t,n,i],arguments.length),t!==void 0)if(Fe(e,null,g(this,q,"f")),(e||"").match(/^\$0( |$)/))return this.command(e,t,n,i);else throw new le(".usage() description must start with $0 if being used as alias for .command()");else return g(this,Y,"f").usage(e),this}usageConfiguration(e){return B("<object>",[e],arguments.length),N(this,Bn,e,"f"),this}version(e,t,n){if(B("[boolean|string] [string] [string]",[e,t,n],arguments.length),g(this,Xe,"f"))this[vs](g(this,Xe,"f")),g(this,Y,"f").version(void 0),N(this,Xe,null,"f");if(arguments.length===0)n=this[go](),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 N(this,Xe,typeof e==="string"?e:"version","f"),t=t||g(this,Y,"f").deferY18nLookup("Show version number"),g(this,Y,"f").version(n||void 0),this.boolean(g(this,Xe,"f")),this.describe(g(this,Xe,"f"),t),this}wrap(e){return B("<number|null|undefined>",[e],arguments.length),g(this,Y,"f").wrap(e),this}[(fe=new WeakMap,mt=new WeakMap,tn=new WeakMap,Ee=new WeakMap,_e=new WeakMap,$n=new WeakMap,rt=new WeakMap,Dt=new WeakMap,On=new WeakMap,Pe=new WeakMap,In=new WeakMap,Te=new WeakMap,Ye=new WeakMap,Se=new WeakMap,Re=new WeakMap,Pn=new WeakMap,yt=new WeakMap,me=new WeakMap,U=new WeakMap,Tn=new WeakMap,Rn=new WeakMap,ke=new WeakMap,wt=new WeakMap,Wt=new WeakMap,bt=new WeakMap,ot=new WeakMap,Mn=new WeakMap,q=new WeakMap,Ft=new WeakMap,Ct=new WeakMap,Et=new WeakMap,Y=new WeakMap,Bn=new WeakMap,Xe=new WeakMap,ce=new WeakMap,co)](e){if(!e._||!e["--"])return e;e._.push.apply(e._,e["--"]);try{delete e["--"]}catch(t){}return e}[uo](){return{log:(...e)=>{if(!this[Nn]())console.log(...e);if(N(this,Se,!0,"f"),g(this,me,"f").length)N(this,me,g(this,me,"f")+`
80
+ `,"f");N(this,me,g(this,me,"f")+e.join(" "),"f")},error:(...e)=>{if(!this[Nn]())console.error(...e);if(N(this,Se,!0,"f"),g(this,me,"f").length)N(this,me,g(this,me,"f")+`
81
+ `,"f");N(this,me,g(this,me,"f")+e.join(" "),"f")}}}[vs](e){jt(g(this,U,"f")).forEach((t)=>{if(((i)=>i==="configObjects")(t))return;let n=g(this,U,"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 g(this,Y,"f").getDescriptions()[e]}[lo](e,t,n){if(!g(this,On,"f")[n])g(this,q,"f").process.emitWarning(e,t),g(this,On,"f")[n]=!0}[fo](){g(this,In,"f").push({options:g(this,U,"f"),configObjects:g(this,U,"f").configObjects.slice(0),exitProcess:g(this,Pe,"f"),groups:g(this,Ye,"f"),strict:g(this,Ft,"f"),strictCommands:g(this,Ct,"f"),strictOptions:g(this,Et,"f"),completionCommand:g(this,_e,"f"),output:g(this,me,"f"),exitError:g(this,rt,"f"),hasOutput:g(this,Se,"f"),parsed:this.parsed,parseFn:g(this,ke,"f"),parseContext:g(this,wt,"f")}),g(this,Y,"f").freeze(),g(this,ce,"f").freeze(),g(this,fe,"f").freeze(),g(this,Te,"f").freeze()}[po](){let e="",t;if(/\b(node|iojs|electron)(\.exe)?$/.test(g(this,q,"f").process.argv()[0]))t=g(this,q,"f").process.argv().slice(1,2);else t=g(this,q,"f").process.argv().slice(0,1);if(e=t.map((n)=>{let i=this[So](g(this,mt,"f"),n);return n.match(/^(\/|([a-zA-Z]:)?\\)/)&&i.length<n.length?i:n}).join(" ").trim(),g(this,q,"f").getEnv("_")&&g(this,q,"f").getProcessArgvBin()===g(this,q,"f").getEnv("_"))e=g(this,q,"f").getEnv("_").replace(`${g(this,q,"f").path.dirname(g(this,q,"f").process.execPath())}/`,"");return e}[xt](){return g(this,Rn,"f")}[ho](){return g(this,Bn,"f")}[js](){if(!g(this,Dt,"f"))return;let e=g(this,q,"f").getEnv("LC_ALL")||g(this,q,"f").getEnv("LC_MESSAGES")||g(this,q,"f").getEnv("LANG")||g(this,q,"f").getEnv("LANGUAGE")||"en_US";this.locale(e.replace(/[.:].*/,""))}[go](){return this[Ls]().version||"unknown"}[mo](e){let t=e["--"]?e["--"]:e._;for(let n=0,i;(i=t[n])!==void 0;n++)if(g(this,q,"f").Parser.looksLikeNumber(i)&&Number.isSafeInteger(Math.floor(parseFloat(`${i}`))))t[n]=Number(i);return e}[Ls](e){let t=e||"*";if(g(this,Wt,"f")[t])return g(this,Wt,"f")[t];let n={};try{let i=e||g(this,q,"f").mainFilename;if(g(this,q,"f").path.extname(i))i=g(this,q,"f").path.dirname(i);let s=g(this,q,"f").findUp(i,(r,o)=>{if(o.includes("package.json"))return"package.json";else return});Fe(s,void 0,g(this,q,"f")),n=JSON.parse(g(this,q,"f").readFileSync(s,"utf8"))}catch(i){}return g(this,Wt,"f")[t]=n||{},g(this,Wt,"f")[t]}[at](e,t){t=[].concat(t),t.forEach((n)=>{n=this[Js](n),g(this,U,"f")[e].push(n)})}[Ut](e,t,n,i){this[Us](e,t,n,i,(s,r,o)=>{g(this,U,"f")[s][r]=o})}[Ws](e,t,n,i){this[Us](e,t,n,i,(s,r,o)=>{g(this,U,"f")[s][r]=(g(this,U,"f")[s][r]||[]).concat(o)})}[Us](e,t,n,i,s){if(Array.isArray(n))n.forEach((r)=>{e(r,i)});else if(((r)=>typeof r==="object")(n))for(let r of jt(n))e(r,n[r]);else s(t,this[Js](n),i)}[Js](e){if(e==="__proto__")return"___proto___";return e}[Ks](e,t){return this[Ut](this[Ks].bind(this),"key",e,t),this}[zs](){var e,t,n,i,s,r,o,a,c,u,f,l;let d=g(this,In,"f").pop();Fe(d,void 0,g(this,q,"f"));let h;e=this,t=this,n=this,i=this,s=this,r=this,o=this,a=this,c=this,u=this,f=this,l=this,{options:{set value(m){N(e,U,m,"f")}}.value,configObjects:h,exitProcess:{set value(m){N(t,Pe,m,"f")}}.value,groups:{set value(m){N(n,Ye,m,"f")}}.value,output:{set value(m){N(i,me,m,"f")}}.value,exitError:{set value(m){N(s,rt,m,"f")}}.value,hasOutput:{set value(m){N(r,Se,m,"f")}}.value,parsed:this.parsed,strict:{set value(m){N(o,Ft,m,"f")}}.value,strictCommands:{set value(m){N(a,Ct,m,"f")}}.value,strictOptions:{set value(m){N(c,Et,m,"f")}}.value,completionCommand:{set value(m){N(u,_e,m,"f")}}.value,parseFn:{set value(m){N(f,ke,m,"f")}}.value,parseContext:{set value(m){N(l,wt,m,"f")}}.value}=d,g(this,U,"f").configObjects=h,g(this,Y,"f").unfreeze(),g(this,ce,"f").unfreeze(),g(this,fe,"f").unfreeze(),g(this,Te,"f").unfreeze()}[Do](e,t){return gt(t,(n)=>(e(n),n))}getInternalMethods(){return{getCommandInstance:this[yo].bind(this),getContext:this[wo].bind(this),getHasOutput:this[bo].bind(this),getLoggerInstance:this[Fo].bind(this),getParseContext:this[Co].bind(this),getParserConfiguration:this[xt].bind(this),getUsageConfiguration:this[ho].bind(this),getUsageInstance:this[Eo].bind(this),getValidationInstance:this[xo].bind(this),hasParseCallback:this[Nn].bind(this),isGlobalContext:this[_o].bind(this),postProcess:this[_t].bind(this),reset:this[Hs].bind(this),runValidation:this[qs].bind(this),runYargsParserAndExecuteCommands:this[nn].bind(this),setHasOutput:this[ko].bind(this)}}[yo](){return g(this,fe,"f")}[wo](){return g(this,tn,"f")}[bo](){return g(this,Se,"f")}[Fo](){return g(this,yt,"f")}[Co](){return g(this,wt,"f")||{}}[Eo](){return g(this,Y,"f")}[xo](){return g(this,ce,"f")}[Nn](){return!!g(this,ke,"f")}[_o](){return g(this,Pn,"f")}[_t](e,t,n,i){if(n)return e;if(ne(e))return e;if(!t)e=this[co](e);if(this[xt]()["parse-positional-numbers"]||this[xt]()["parse-positional-numbers"]===void 0)e=this[mo](e);if(i)e=ht(e,this,g(this,Te,"f").getMiddleware(),!1);return e}[Hs](e={}){N(this,U,g(this,U,"f")||{},"f");let t={};t.local=g(this,U,"f").local||[],t.configObjects=g(this,U,"f").configObjects||[];let n={};t.local.forEach((r)=>{n[r]=!0,(e[r]||[]).forEach((o)=>{n[o]=!0})}),Object.assign(g(this,bt,"f"),Object.keys(g(this,Ye,"f")).reduce((r,o)=>{let a=g(this,Ye,"f")[o].filter((c)=>!(c in n));if(a.length>0)r[o]=a;return r},{})),N(this,Ye,{},"f");let i=["array","boolean","string","skipValidation","count","normalize","number","hiddenOptions"],s=["narg","key","alias","default","defaultDescription","config","choices","demandedOptions","demandedCommands","deprecatedOptions"];if(i.forEach((r)=>{t[r]=(g(this,U,"f")[r]||[]).filter((o)=>!n[o])}),s.forEach((r)=>{t[r]=st(g(this,U,"f")[r],(o)=>!n[o])}),t.envPrefix=g(this,U,"f").envPrefix,N(this,U,t,"f"),N(this,Y,g(this,Y,"f")?g(this,Y,"f").reset(n):Qr(this,g(this,q,"f")),"f"),N(this,ce,g(this,ce,"f")?g(this,ce,"f").reset(n):oo(this,g(this,Y,"f"),g(this,q,"f")),"f"),N(this,fe,g(this,fe,"f")?g(this,fe,"f").reset():Gr(g(this,Y,"f"),g(this,ce,"f"),g(this,Te,"f"),g(this,q,"f")),"f"),!g(this,Ee,"f"))N(this,Ee,so(this,g(this,Y,"f"),g(this,fe,"f"),g(this,q,"f")),"f");return g(this,Te,"f").reset(),N(this,_e,null,"f"),N(this,me,"","f"),N(this,rt,null,"f"),N(this,Se,!1,"f"),this.parsed=!1,this}[So](e,t){return g(this,q,"f").path.relative(e,t)}[nn](e,t,n,i=0,s=!1){var r,o,a,c;let u=!!n||s;e=e||g(this,ot,"f"),g(this,U,"f").__=g(this,q,"f").y18n.__,g(this,U,"f").configuration=this[xt]();let f=!!g(this,U,"f").configuration["populate--"],l=Object.assign({},g(this,U,"f").configuration,{"populate--":!0}),d=g(this,q,"f").Parser.detailed(e,Object.assign({},g(this,U,"f"),{configuration:{"parse-positional-numbers":!1,...l}})),h=Object.assign(d.argv,g(this,wt,"f")),m=void 0,p=d.aliases,y=!1,E=!1;if(Object.keys(h).forEach((F)=>{if(F===g(this,Re,"f")&&h[F])y=!0;else if(F===g(this,Xe,"f")&&h[F])E=!0}),h.$0=this.$0,this.parsed=d,i===0)g(this,Y,"f").clearCachedHelpMessage();try{if(this[js](),t)return this[_t](h,f,!!n,!1);if(g(this,Re,"f")){if([g(this,Re,"f")].concat(p[g(this,Re,"f")]||[]).filter((T)=>T.length>1).includes(""+h._[h._.length-1]))h._.pop(),y=!0}N(this,Pn,!1,"f");let F=g(this,fe,"f").getCommands(),k=((r=g(this,Ee,"f"))===null||r===void 0?void 0:r.completionKey)?[(o=g(this,Ee,"f"))===null||o===void 0?void 0:o.completionKey,...(c=this.getAliases()[(a=g(this,Ee,"f"))===null||a===void 0?void 0:a.completionKey])!==null&&c!==void 0?c:[]].some((A)=>Object.prototype.hasOwnProperty.call(h,A)):!1,C=y||k||s;if(h._.length){if(F.length){let A;for(let T=i||0,v;h._[T]!==void 0;T++)if(v=String(h._[T]),F.includes(v)&&v!==g(this,_e,"f")){let L=g(this,fe,"f").runCommand(v,this,d,T+1,s,y||E||s);return this[_t](L,f,!!n,!1)}else if(!A&&v!==g(this,_e,"f")){A=v;break}if(!g(this,fe,"f").hasDefaultCommand()&&g(this,Mn,"f")&&A&&!C)g(this,ce,"f").recommendCommands(A,F)}if(g(this,_e,"f")&&h._.includes(g(this,_e,"f"))&&!k){if(g(this,Pe,"f"))it(!0);this.showCompletionScript(),this.exit(0)}}if(g(this,fe,"f").hasDefaultCommand()&&!C){let A=g(this,fe,"f").runCommand(null,this,d,0,s,y||E||s);return this[_t](A,f,!!n,!1)}if(k){if(g(this,Pe,"f"))it(!0);e=[].concat(e);let A=e.slice(e.indexOf(`--${g(this,Ee,"f").completionKey}`)+1);return g(this,Ee,"f").getCompletion(A,(T,v)=>{if(T)throw new le(T.message);(v||[]).forEach((L)=>{g(this,yt,"f").log(L)}),this.exit(0)}),this[_t](h,!f,!!n,!1)}if(!g(this,Se,"f")){if(y){if(g(this,Pe,"f"))it(!0);u=!0,this.showHelp((A)=>{g(this,yt,"f").log(A),this.exit(0)})}else if(E){if(g(this,Pe,"f"))it(!0);u=!0,g(this,Y,"f").showVersion("log"),this.exit(0)}}if(!u&&g(this,U,"f").skipValidation.length>0)u=Object.keys(h).some((A)=>g(this,U,"f").skipValidation.indexOf(A)>=0&&h[A]===!0);if(!u){if(d.error)throw new le(d.error.message);if(!k){let A=this[qs](p,{},d.error);if(!n)m=ht(h,this,g(this,Te,"f").getMiddleware(),!0);if(m=this[Do](A,m!==null&&m!==void 0?m:h),ne(m)&&!n)m=m.then(()=>ht(h,this,g(this,Te,"f").getMiddleware(),!1))}}}catch(F){if(F instanceof le)g(this,Y,"f").fail(F.message,F);else throw F}return this[_t](m!==null&&m!==void 0?m:h,f,!!n,!0)}[qs](e,t,n,i){let s={...this.getDemandedOptions()};return(r)=>{if(n)throw new le(n.message);g(this,ce,"f").nonOptionCount(r),g(this,ce,"f").requiredArguments(r,s);let o=!1;if(g(this,Ct,"f"))o=g(this,ce,"f").unknownCommands(r);if(g(this,Ft,"f")&&!o)g(this,ce,"f").unknownArguments(r,e,t,!!i);else if(g(this,Et,"f"))g(this,ce,"f").unknownArguments(r,e,{},!1,!1);g(this,ce,"f").limitedChoices(r),g(this,ce,"f").implications(r),g(this,ce,"f").conflicting(r)}}[ko](){N(this,Se,!0,"f")}[St](e){if(typeof e==="string")g(this,U,"f").key[e]=!0;else for(let t of e)g(this,U,"f").key[t]=!0}}function Vr(e){return!!e&&typeof e.getInternalMethods==="function"}var nl=Ao(Ts),Oo=nl;import{existsSync as vn,readFileSync as Gs,writeFileSync as Ys,mkdirSync as To}from"node:fs";import{homedir as sl}from"node:os";import{join as kt,dirname as Vs}from"node:path";function Zs(){return process.env.HOME||sl()}function Ro(){return kt(Zs(),".config","slack-cli","profiles.json")}function jn(){return kt(process.cwd(),".slack-cli","workspace")}function Ln(){return kt(Zs(),".slack-cli","workspace")}function sn(){let e=Ro();if(!vn(e))return{profiles:{}};return JSON.parse(Gs(e,"utf8"))}function il(e){let t=Ro();To(Vs(t),{recursive:!0}),Ys(t,JSON.stringify(e,null,2)+`
82
+ `)}function Jt(e){if(!vn(e))return;return Gs(e,"utf8").trim()||void 0}function Io(e,t){let n=Vs(e);To(n,{recursive:!0});let i=kt(n,".gitignore");if(!vn(i))Ys(i,`*
83
+ `);Ys(e,t+`
84
+ `)}function rl(e){let t={};for(let n of e.split(`
85
+ `)){let i=n.trim();if(!i||i.startsWith("#"))continue;let s=i.indexOf("=");if(s===-1)continue;let r=i.slice(0,s).trim(),o=i.slice(s+1).trim();if(o.startsWith('"')&&o.endsWith('"')||o.startsWith("'")&&o.endsWith("'"))o=o.slice(1,-1);t[r]=o}return t}function Po(e){if(!vn(e))return{};try{return rl(Gs(e,"utf8"))}catch{return{}}}function Xs(e,t){let n=Zs(),i=e;while(!0){for(let o of[kt(i,".slack-term",".env.local"),kt(i,".env.local")]){let a=Po(o);for(let c of t)if(a[c])return a[c]}if(i===n)break;let r=Vs(i);if(r===i)break;i=r}let s=Po(kt(n,".slack-term",".env.local"));for(let r of t)if(s[r])return s[r];return}function Qs(){let e=sn(),t=Jt(jn()),n=Jt(Ln()),i=t??n;return Object.entries(e.profiles).map(([s,r])=>({name:s,profile:r,current:s===i}))}function Mo(e){let t=sn();if(!(e in t.profiles))throw Error(`Profile not found: ${e}`);delete t.profiles[e],il(t)}function Bo(e,t=!1){let n=sn();if(!(e in n.profiles))throw Error(`Profile not found: ${e}`);if(t)Io(Ln(),e);else Io(jn(),e)}function ei(e){let n=sn().profiles,i=Object.keys(n);if(e){let u=n[e];if(!u)throw Error(`Workspace "${e}" not found. Available: ${i.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&&i.length===0)return s;if(s&&i.length>0){let u=Xs(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 r=Xs(process.cwd(),["SLACK_TOKEN"]);if(r)return r;let o=process.env.SLACK_WORKSPACE;if(o){let u=n[o];if(!u)throw Error(`Workspace "${o}" not found. Available: ${i.join(", ")||"(none)"}`);return u.token}let a=Jt(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=Jt(Ln());if(c){let u=n[c];if(!u)throw Error(`Workspace "${c}" (from ~/.slack-cli/workspace) not found in profiles.`);return u.token}if(i.length>0)throw Error(`Workspace not selected (${i.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 sF(){let D=process.env.SLACK_BOT_TOKEN;return D&&D.startsWith("xoxb-")?D:void 0}function W1(D){let u=oF().profiles;if(D)return u[D]?.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(u).length===0)return process.env.SLACK_MCP_XOXD_COOKIE;let E=Iu(process.cwd(),["SLACK_COOKIE"]);if(E)return E;let C=process.env.SLACK_WORKSPACE;if(C)return u[C]?.cookie;let $=fF(L0());if($)return u[$]?.cookie;let z=fF(A0());if(z)return u[z]?.cookie;return}class dD extends Error{retryAfter;constructor(D){super(`Slack rate limited — retry after ${D}s`);this.name="RateLimitError",this.retryAfter=D}}function pu(){return(process.env.SLACK_API_BASE??"https://slack.com/api").replace(/\/$/,"")}async function V1(D,F,u,B){let E={};if(B)E.Cookie=`d=${B}`;let C=await fetch(`${pu()}/${F}`,{...u,headers:{...u.headers??{},Authorization:`Bearer ${D}`,...E}});if(C.status===429){let z=parseInt(C.headers.get("retry-after")??"60",10);throw new dD(isNaN(z)?60:z)}let $=await C.json();if($.ok!==!0){let z=$.error??"unknown";if(z==="ratelimited")throw new dD(60);if(z==="invalid_auth"&&D.startsWith("xoxc-")&&!B)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 Kt(){let e=process.env.SLACK_BOT_TOKEN;return e&&e.startsWith("xoxb-")?e:void 0}function No(e){let n=sn().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=Xs(process.cwd(),["SLACK_COOKIE"]);if(s)return s;let r=process.env.SLACK_WORKSPACE;if(r)return n[r]?.cookie;let o=Jt(jn());if(o)return n[o]?.cookie;let a=Jt(Ln());if(a)return n[a]?.cookie;return}class Ge extends Error{retryAfter;constructor(e){super(`Slack rate limited — retry after ${e}s`);this.name="RateLimitError",this.retryAfter=e}}function ti(){return(process.env.SLACK_API_BASE??"https://slack.com/api").replace(/\/$/,"")}async function jo(e,t,n,i){let s={};if(i)s.Cookie=`d=${i}`;let r=await fetch(`${ti()}/${t}`,{...n,headers:{...n.headers??{},Authorization:`Bearer ${e}`,...s}});if(r.status===429){let a=parseInt(r.headers.get("retry-after")??"60",10);throw new Ge(isNaN(a)?60:a)}let o=await r.json();if(o.ok!==!0){let a=o.error??"unknown";if(a==="ratelimited")throw new Ge(60);if(a==="invalid_auth"&&e.startsWith("xoxc-")&&!i)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
- slack auth token`);if((z==="missing_scope"||z==="cannot_dm_bot")&&D.startsWith("xoxb-"))throw Error(`Slack error on ${F}: ${z} — ${z==="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"}.
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 ${F}: ${z}`)}return $}async function L7(D,F,u,B){let E={};if(B)E.Cookie=`d=${B}`;let C=await fetch(`${pu()}/${F}`,{...u,headers:{...u.headers??{},Authorization:`Bearer ${D}`,...E}});if(C.status===429){let z=parseInt(C.headers.get("retry-after")??"60",10);throw new dD(isNaN(z)?60:z)}let $=await C.json();if($.ok!==!0){let z=$.error??"unknown";if(z==="ratelimited")throw new dD(60);if((z==="invalid_auth"||z==="not_authed")&&!D.startsWith("xoxc-"))throw Error(`The draft API requires a desktop app session token (xoxc-).
100
- Import from Slack desktop: slack auth login`);if((z==="invalid_auth"||z==="not_authed")&&!B)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 ${F}: ${z}`)}return $}function A7(D,F,u={},B){let E=new URLSearchParams({token:D,...u});return L7(D,F,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:E.toString()},B)}function jD(D,F,u,B){let E=new URLSearchParams(u).toString();return V1(D,`${F}?${E}`,{method:"GET"},B)}function mu(D,F,u,B){return V1(D,F,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(u)},B)}async function hF(D,F){let u=await jD(D,"auth.test",{},F);return{team:u.team??"",teamId:u.team_id??"",url:u.url??"",user:u.user??"",userId:u.user_id??""}}async function H1(D,F){let u={Authorization:`Bearer ${D}`};if(F)u.Cookie=`d=${F}`;let B=await fetch(`${pu()}/auth.test`,{method:"GET",headers:u});if(B.status===429){let $=parseInt(B.headers.get("retry-after")??"60",10);throw new dD(isNaN($)?60:$)}let E=B.headers.get("x-oauth-scopes")??"",C=await B.json();if(C.ok!==!0)throw Error(`Slack error on auth.test: ${C.error??"unknown"}`);return{userId:C.user_id??"",user:C.user??"",botId:C.bot_id??"",team:C.team??"",url:C.url??"",scopes:E.split(",").map(($)=>$.trim()).filter(Boolean)}}async function q1(D,F,u){let B=await jD(D,"bots.info",{bot:F},u);return{appId:B.bot?.app_id??"",userId:B.bot?.user_id??""}}async function aF(D,F,u=20,B,E,C,$){let z={channel:F,limit:String(u)};if(B!==void 0)z.oldest=B;if(E!==void 0)z.cursor=E;if($)z.inclusive="true";return jD(D,"conversations.history",z,C)}async function j1(D,F,u,B=50,E){return jD(D,"conversations.replies",{channel:F,ts:u,limit:String(B)},E)}async function P0(D,F,u,B,E){await mu(D,"reactions.add",{channel:F,timestamp:u,name:B},E)}async function U1(D,F,u,B){return((await jD(D,"reactions.get",{channel:F,timestamp:u,full:"true"},B)).message?.reactions??[]).map((C)=>({name:String(C.name??""),users:Array.isArray(C.users)?C.users.map(String):[]}))}async function T0(D,F,u,B,E){await mu(D,"reactions.remove",{channel:F,timestamp:u,name:B},E)}async function P7(D,F,u){let E=(await mu(D,"conversations.open",{users:F},u)).channel?.id;if(!E)throw Error(`Failed to open DM with user ${F}`);return E}function rF(D){return D.toLowerCase().replace(/[-_\s]/g,"")}function gu(D){let F=D.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(!F)return;let u=F[1],B=F[2]&&F[3]?`${F[2]}.${F[3]}`:void 0,E=D.indexOf("?"),C=E>=0?new URLSearchParams(D.slice(E)):void 0,$=C?.get("thread_ts")??void 0,J={channel:C?.get("cid")??void 0??u};if(B)J.ts=B;if($)J.threadTs=$;return J}function T7(D){return gu(D)?.channel}async function K1(D,F,u){let B=T7(F);if(B)return B;if(!F.startsWith("@")&&!F.startsWith("#")){if(/^[A-Za-z0-9]{9,}$/.test(F))return F;throw Error(`Target must start with # or @ (or be a Slack URL/ID), got: ${F}`)}let E=F.startsWith("@"),C=F.slice(1),$=rF(C);if(E){let J=await jD(D,"auth.test",{},u);if($==="you"||$==="me"||rF(J.user??"")===$){let H=J.user_id;if(!H)throw Error("auth.test did not return user_id");let j=((await jD(D,"conversations.list",{types:"im",limit:"200"},u)).channels??[]).find((N)=>N.user===H);if(j?.id)return String(j.id);return P7(D,H,u)}let G="",X="";while(!0){let H={limit:"200"};if(X)H.cursor=X;let W=await jD(D,"users.list",H,u);for(let j of W.members??[]){let N=rF(j.name??""),O=rF(j.real_name??""),T=rF(j.profile?.display_name??"");if(N===$||O===$||T&&T===$){G=j.id??"";break}}if(G)break;if(X=W.response_metadata?.next_cursor??"",!X)break}if(!G)throw Error(`User not found: ${F}`);let V="";while(!0){let H={types:"im",limit:"200"};if(V)H.cursor=V;let W=await jD(D,"conversations.list",H,u);for(let j of W.channels??[])if(j.user===G)return String(j.id??"");if(V=W.response_metadata?.next_cursor??"",!V)break}throw Error(`No existing DM with ${F} (${G}). Open it once in Slack first.`)}let z=C.toLowerCase(),Z="";while(!0){let J={limit:"200",types:"public_channel,private_channel",exclude_archived:"true"};if(Z)J.cursor=Z;let Q=await jD(D,"conversations.list",J,u);for(let G of Q.channels??[])if(String(G.name??"").toLowerCase()===z)return String(G.id??"");if(Z=Q.response_metadata?.next_cursor??"",!Z)break}throw Error(`channel not found: ${F}`)}async function R0(D,F,u){try{let B=await jD(D,"users.info",{user:F},u),E=B.user?.profile?.display_name,C=E&&E.length>0?E:B.user?.real_name??B.user?.name??F,$=B.user?.name??F;return[C,$]}catch{return[F,F]}}async function S0(D,F,u){try{let B=await jD(D,"users.info",{user:F},u),E=B.user?.profile?.display_name;if(E&&E.length>0)return E;return B.user?.real_name??B.user?.name??F}catch{return F}}async function w0(D,F){let u=[],B="";while(!0){let E={limit:"200"};if(B)E.cursor=B;let C=await jD(D,"users.list",E,F);if(u.push(...C.members??[]),B=C.response_metadata?.next_cursor??"",!B)break}return{members:u}}async function cu(D,F,u){let B=[],E="";while(!0){let C={channel:F,limit:"200"};if(E)C.cursor=E;let $=await jD(D,"conversations.members",C,u);if(B.push(...$.members??[]),E=$.response_metadata?.next_cursor??"",!E)break}return B}async function ku(D,F,u){return jD(D,"users.info",{user:F},u)}async function O1(D,F,u){return jD(D,"conversations.info",{channel:F},u)}async function M1(D,F){let u=await A7(D,"client.boot",{},F),B=typeof u.url==="string"?u.url:void 0;if(!B){let C=Object.keys(u).join(", ");throw Error(`client.boot did not return a WebSocket URL. Keys: ${C}`)}let E=u.self&&typeof u.self==="object"&&!Array.isArray(u.self)?u.self:{};return{wsUrl:B,selfId:typeof E.id==="string"?E.id:""}}var R7=["chat:write","im:write"],S7=["im:history","im:read"];async function du(D){let{userId:F,botId:u,team:B,scopes:E}=await H1(D),C="";if(u)try{C=(await q1(D,u)).appId}catch{C=""}let $=(J)=>E.includes(J),z=R7.filter((J)=>!$(J)),Z=S7.filter((J)=>!$(J));return{canSend:z.length===0,canReceiveReplies:Z.length===0,ok:z.length===0&&Z.length===0,botUserId:F,appId:C,team:B,grantedScopes:E,missingSendScopes:z,missingReplyScopes:Z}}function _1(D){return["",` Bot user: ${D.botUserId||"(unknown)"}`,` App ID: ${D.appId||"(unknown — bots.info unavailable)"}`,` Granted scopes: ${D.grantedScopes.join(", ")||"(none reported)"}`]}function iu(D,F=!1){let u=D.appId?`https://api.slack.com/apps/${D.appId}`:"https://api.slack.com/apps";if(D.ok){let E=["✓ 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:',` ${u} → App Home → "Messages Tab" ON + "Allow users to send messages".`];return F?E:[...E,..._1(D)]}let B=[];if(!D.canSend)B.push(`⚠ This bot CANNOT send DMs — missing scope(s): ${D.missingSendScopes.join(", ")}.`);else B.push("⚠ This bot can send DMs, but the user's replies will NOT be readable.");return B.push(" Make escalation DMs two-way:"),B.push(` 1. ${u} → App Home → enable "Messages Tab" and check`),B.push(' "Allow users to send Slash commands and messages".'),B.push(` 2. OAuth & Permissions → add Bot Token Scopes: ${[...D.missingSendScopes,...D.missingReplyScopes].join(", ")}`),B.push(" 3. Reinstall the app to apply the new scopes."),F?B:[...B,..._1(D)]}import{createInterface as NF}from"node:readline/promises";import{join as au}from"node:path";import{homedir as k7}from"node:os";import{existsSync as lu,readFileSync as nu,writeFileSync as L1,mkdirSync as A1}from"node:fs";import{homedir as w7}from"node:os";import{join as tu,dirname as P1}from"node:path";function T1(){return process.env.HOME||w7()}function R1(){return tu(T1(),".config","slack-cli","profiles.json")}function x7(){return tu(process.cwd(),".slack-cli","workspace")}function I7(){return tu(T1(),".slack-cli","workspace")}function ou(){let D=R1();if(!lu(D))return{profiles:{}};return JSON.parse(nu(D,"utf8"))}function S1(D){let F=R1();A1(P1(F),{recursive:!0}),L1(F,JSON.stringify(D,null,2)+`
102
- `)}function N1(D){if(!lu(D))return;return nu(D,"utf8").trim()||void 0}function w1(D,F){A1(P1(D),{recursive:!0});let u=lu(D)?nu(D,"utf8"):"",B=u?u.split(`
103
- `):[];for(let[E,C]of Object.entries(F)){let $=B.findIndex((Z)=>{let J=Z.trim();return J.startsWith(E+"=")||J.startsWith(E+" =")}),z=`${E}=${C}`;if($!==-1)B[$]=z;else B.push(z)}L1(D,B.join(`
99
+ Or import your Slack desktop session: slack auth login`);throw Error(`Slack error on ${t}: ${a}`)}return o}async function ol(e,t,n,i){let s={};if(i)s.Cookie=`d=${i}`;let r=await fetch(`${ti()}/${t}`,{...n,headers:{...n.headers??{},Authorization:`Bearer ${e}`,...s}});if(r.status===429){let a=parseInt(r.headers.get("retry-after")??"60",10);throw new Ge(isNaN(a)?60:a)}let o=await r.json();if(o.ok!==!0){let a=o.error??"unknown";if(a==="ratelimited")throw new Ge(60);if((a==="invalid_auth"||a==="not_authed")&&!e.startsWith("xoxc-"))throw Error(`The draft API requires a desktop app session token (xoxc-).
100
+ Import from Slack desktop: slack auth login`);if((a==="invalid_auth"||a==="not_authed")&&!i)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 al(e,t,n={},i){let s=new URLSearchParams({token:e,...n});return ol(e,t,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:s.toString()},i)}function we(e,t,n,i){let s=new URLSearchParams(n).toString();return jo(e,`${t}?${s}`,{method:"GET"},i)}function ni(e,t,n,i){return jo(e,t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)},i)}async function zt(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 Lo(e,t){let n={Authorization:`Bearer ${e}`};if(t)n.Cookie=`d=${t}`;let i=await fetch(`${ti()}/auth.test`,{method:"GET",headers:n});if(i.status===429){let o=parseInt(i.headers.get("retry-after")??"60",10);throw new Ge(isNaN(o)?60:o)}let s=i.headers.get("x-oauth-scopes")??"",r=await i.json();if(r.ok!==!0)throw Error(`Slack error on auth.test: ${r.error??"unknown"}`);return{userId:r.user_id??"",user:r.user??"",botId:r.bot_id??"",team:r.team??"",url:r.url??"",scopes:s.split(",").map((o)=>o.trim()).filter(Boolean)}}async function Wo(e,t,n){let i=await we(e,"bots.info",{bot:t},n);return{appId:i.bot?.app_id??"",userId:i.bot?.user_id??""}}async function on(e,t,n=20,i,s,r,o){let a={channel:t,limit:String(n)};if(i!==void 0)a.oldest=i;if(s!==void 0)a.cursor=s;if(o)a.inclusive="true";return we(e,"conversations.history",a,r)}async function Uo(e,t,n,i=50,s){return we(e,"conversations.replies",{channel:t,ts:n,limit:String(i)},s)}async function Wn(e,t,n,i,s){await ni(e,"reactions.add",{channel:t,timestamp:n,name:i},s)}async function Jo(e,t,n,i){return((await we(e,"reactions.get",{channel:t,timestamp:n,full:"true"},i)).message?.reactions??[]).map((r)=>({name:String(r.name??""),users:Array.isArray(r.users)?r.users.map(String):[]}))}async function Un(e,t,n,i,s){await ni(e,"reactions.remove",{channel:t,timestamp:n,name:i},s)}async function cl(e,t,n){let s=(await ni(e,"conversations.open",{users:t},n)).channel?.id;if(!s)throw Error(`Failed to open DM with user ${t}`);return s}function rn(e){return e.toLowerCase().replace(/[-_\s]/g,"")}function si(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],i=t[2]&&t[3]?`${t[2]}.${t[3]}`:void 0,s=e.indexOf("?"),r=s>=0?new URLSearchParams(e.slice(s)):void 0,o=r?.get("thread_ts")??void 0,u={channel:r?.get("cid")??void 0??n};if(i)u.ts=i;if(o)u.threadTs=o;return u}function ul(e){return si(e)?.channel}function vo(e){return/^[CDG][A-Z0-9]{8,}$/.test(e)}async function Ko(e,t,n){let i=ul(t);if(i)return i;if(!t.startsWith("@")&&!t.startsWith("#")){if(vo(t))return t;throw Error(`Target must start with # or @ (or be a Slack URL/ID), got: ${t}`)}if(t.startsWith("#")&&vo(t.slice(1)))return t.slice(1);let s=t.startsWith("@"),r=t.slice(1),o=rn(r);if(s){let u=await we(e,"auth.test",{},n);if(o==="you"||o==="me"||rn(u.user??"")===o){let m=u.user_id;if(!m)throw Error("auth.test did not return user_id");let y=((await we(e,"conversations.list",{types:"im",limit:"200"},n)).channels??[]).find((E)=>E.user===m);if(y?.id)return String(y.id);return cl(e,m,n)}let l="",d="";while(!0){let m={limit:"200"};if(d)m.cursor=d;let p=await we(e,"users.list",m,n);for(let y of p.members??[]){let E=rn(y.name??""),F=rn(y.real_name??""),k=rn(y.profile?.display_name??"");if(E===o||F===o||k&&k===o){l=y.id??"";break}}if(l)break;if(d=p.response_metadata?.next_cursor??"",!d)break}if(!l)throw Error(`User not found: ${t}`);let h="";while(!0){let m={types:"im",limit:"200"};if(h)m.cursor=h;let p=await we(e,"conversations.list",m,n);for(let y of p.channels??[])if(y.user===l)return String(y.id??"");if(h=p.response_metadata?.next_cursor??"",!h)break}throw Error(`No existing DM with ${t} (${l}). Open it once in Slack first.`)}let a=r.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 Jn(e,t,n){try{let i=await we(e,"users.info",{user:t},n),s=i.user?.profile?.display_name,r=s&&s.length>0?s:i.user?.real_name??i.user?.name??t,o=i.user?.name??t;return[r,o]}catch{return[t,t]}}async function Kn(e,t,n){try{let i=await we(e,"users.info",{user:t},n),s=i.user?.profile?.display_name;if(s&&s.length>0)return s;return i.user?.real_name??i.user?.name??t}catch{return t}}async function zn(e,t){let n=[],i="";while(!0){let s={limit:"200"};if(i)s.cursor=i;let r=await we(e,"users.list",s,t);if(n.push(...r.members??[]),i=r.response_metadata?.next_cursor??"",!i)break}return{members:n}}async function ii(e,t,n){let i=[],s="";while(!0){let r={channel:t,limit:"200"};if(s)r.cursor=s;let o=await we(e,"conversations.members",r,n);if(i.push(...o.members??[]),s=o.response_metadata?.next_cursor??"",!s)break}return i}async function ri(e,t,n){return we(e,"users.info",{user:t},n)}async function zo(e,t,n){return we(e,"conversations.info",{channel:t},n)}async function Ho(e,t){let n=await al(e,"client.boot",{},t),i=typeof n.url==="string"?n.url:void 0;if(!i){let r=Object.keys(n).join(", ");throw Error(`client.boot did not return a WebSocket URL. Keys: ${r}`)}let s=n.self&&typeof n.self==="object"&&!Array.isArray(n.self)?n.self:{};return{wsUrl:i,selfId:typeof s.id==="string"?s.id:""}}var ll=["chat:write","im:write"],fl=["im:history","im:read"];async function oi(e){let{userId:t,botId:n,team:i,scopes:s}=await Lo(e),r="";if(n)try{r=(await Wo(e,n)).appId}catch{r=""}let o=(u)=>s.includes(u),a=ll.filter((u)=>!o(u)),c=fl.filter((u)=>!o(u));return{canSend:a.length===0,canReceiveReplies:c.length===0,ok:a.length===0&&c.length===0,botUserId:t,appId:r,team:i,grantedScopes:s,missingSendScopes:a,missingReplyScopes:c}}function qo(e){return["",` Bot user: ${e.botUserId||"(unknown)"}`,` App ID: ${e.appId||"(unknown — bots.info unavailable)"}`,` Granted scopes: ${e.grantedScopes.join(", ")||"(none reported)"}`]}function ai(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,...qo(e)]}let i=[];if(!e.canSend)i.push(`⚠ This bot CANNOT send DMs — missing scope(s): ${e.missingSendScopes.join(", ")}.`);else i.push("⚠ This bot can send DMs, but the user's replies will NOT be readable.");return i.push(" Make escalation DMs two-way:"),i.push(` 1. ${n} → App Home → enable "Messages Tab" and check`),i.push(' "Allow users to send Slash commands and messages".'),i.push(` 2. OAuth & Permissions → add Bot Token Scopes: ${[...e.missingSendScopes,...e.missingReplyScopes].join(", ")}`),i.push(" 3. Reinstall the app to apply the new scopes."),t?i:[...i,...qo(e)]}import{createInterface as $t}from"node:readline/promises";import{join as hi}from"node:path";import{homedir as xl}from"node:os";import{existsSync as ci,readFileSync as ui,writeFileSync as Xo,mkdirSync as Go}from"node:fs";import{homedir as dl}from"node:os";import{join as li,dirname as Vo}from"node:path";function Zo(){return process.env.HOME||dl()}function Qo(){return li(Zo(),".config","slack-cli","profiles.json")}function pl(){return li(process.cwd(),".slack-cli","workspace")}function hl(){return li(Zo(),".slack-cli","workspace")}function fi(){let e=Qo();if(!ci(e))return{profiles:{}};return JSON.parse(ui(e,"utf8"))}function ea(e){let t=Qo();Go(Vo(t),{recursive:!0}),Xo(t,JSON.stringify(e,null,2)+`
102
+ `)}function Yo(e){if(!ci(e))return;return ui(e,"utf8").trim()||void 0}function ta(e,t){Go(Vo(e),{recursive:!0});let n=ci(e)?ui(e,"utf8"):"",i=n?n.split(`
103
+ `):[];for(let[s,r]of Object.entries(t)){let o=i.findIndex((c)=>{let u=c.trim();return u.startsWith(s+"=")||u.startsWith(s+" =")}),a=`${s}=${r}`;if(o!==-1)i[o]=a;else i.push(a)}Xo(e,i.join(`
104
104
  `).trimEnd()+`
105
- `)}function x0(){let D=ou(),F=N1(x7()),u=N1(I7()),B=F??u;return Object.entries(D.profiles).map(([E,C])=>({name:E,profile:C,current:E===B}))}function su(D,F){let u=ou();u.profiles[D]=F,S1(u)}function ru(D,F){let u=ou();if(!(D in u.profiles))throw Error(`Profile not found: ${D}`);u.profiles[D].cookie=F,S1(u)}import{readdirSync as I0,readFileSync as eF,existsSync as _F,copyFileSync as x1,unlinkSync as I1}from"node:fs";import{homedir as b0,tmpdir as b1}from"node:os";import{join as XD,dirname as b7}from"node:path";import{pbkdf2Sync as f1,createDecipheriv as h1}from"node:crypto";import{execSync as v1}from"node:child_process";function f7(){let D=b0();if(process.platform==="darwin")return XD(D,"Library","Application Support","Slack","Local Storage","leveldb");if(process.platform==="linux")return XD(D,".config","Slack","Local Storage","leveldb");if(process.platform==="win32"){let F=process.env.APPDATA??XD(D,"AppData","Roaming");return XD(F,"Slack","Local Storage","leveldb")}throw Error(`Unsupported platform: ${process.platform}`)}function h7(){let D=b0();if(process.platform==="darwin")return XD(D,"Library","Application Support","Slack","Cookies");return""}function v7(D,F){if(D.length<35||D.slice(0,3).toString()!=="v10")throw Error("Not a v10 encrypted cookie");let u=D.slice(19,35),B=D.slice(35),E=h1("aes-128-cbc",F,u);return E.setAutoPadding(!0),Buffer.concat([E.update(B),E.final()]).toString("utf8")}function y7(){if(process.platform!=="darwin")return;let D=h7();if(!_F(D))return;let F;try{F=v1('security find-generic-password -w -s "Slack Safe Storage" -a "Slack Key"',{encoding:"utf8",stdio:["ignore","pipe","ignore"]}).trimEnd()}catch{return}let u=f1(F,"saltysalt",1003,16,"sha1");try{let{default:B}=gD("bun:sqlite"),E=new B(D,{readonly:!0}),C=E.prepare("SELECT encrypted_value FROM cookies WHERE name='d' AND host_key LIKE '%slack%'").get();if(E.close(),!C)return;return v7(Buffer.from(C.encrypted_value),u)}catch{return}}async function y1(){let D=f7();if(!_F(D))throw Error(`Slack desktop app LevelDB not found at:
106
- ${D}
107
- Is Slack installed and opened at least once?`);let F=I0(D).filter((z)=>z.endsWith(".ldb")||z.endsWith(".log"));if(F.length===0)throw Error(`No LevelDB data files found in ${D}`);let u=new Map;for(let z of F){let Z;try{Z=eF(XD(D,z),"latin1")}catch{continue}if(z.endsWith(".log"))for(let J of Z.matchAll(/"token":"(xoxc-[^"]+)"/g)){let Q=J[1],G=Q.split("-")[1]??"";if(!G||Q.length<40)continue;let X=Math.max(0,J.index-2000),V=Math.min(Z.length,J.index+2000),H=Z.slice(X,V),W=H.match(/"url":"(https:\/\/[a-z0-9-]+\.slack\.com\/)"/),j=H.match(/"(?:team_name|name)":"([^"]{2,60})"/),N=u.get(G);if(!N||Q.length>N.token.length){let O={token:Q,teamId:G},T=W?.[1]??N?.url,M=j?.[1]??N?.teamName;if(T)O.url=T;if(M)O.teamName=M;u.set(G,O)}}else for(let J of Z.matchAll(/xoxc-(\d+)-(\d+)-(\d+)/g)){let Q=J[1];if(u.has(Q))continue;let G=J.index+J[0].length,X=Math.min(G+10,Z.length);while(G<X&&(Z.charCodeAt(G)<48||Z.charCodeAt(G)>57))G++;let V="";while(G<Z.length&&Z.charCodeAt(G)>=48&&Z.charCodeAt(G)<=57)V+=Z[G++];if(Z[G]!=="-")continue;G++;let H="";while(G<Z.length){let j=Z.charCodeAt(G);if(j>=48&&j<=57||j>=97&&j<=102)H+=Z[G++];else break}if(H.length<20)continue;let W=`${J[0]}${V}-${H}`;u.set(Q,{token:W,teamId:Q})}}let E=I0(D).filter((z)=>z.endsWith(".ldb")||z.endsWith(".log")).map((z)=>{try{return eF(XD(D,z),"latin1").replace(/[^\x20-\x7e]/g," ")}catch{return""}}).join(" ");for(let z of u.values()){if(z.teamName)continue;let Z=E.indexOf(z.teamId);if(Z!==-1){let J=Math.max(0,Z-500),Q=Math.min(E.length,Z+500),X=E.slice(J,Q).match(/"(?:team_name|name)":"([^"]{2,60})"/);if(X?.[1]){z.teamName=X[1];continue}}if(!z.teamName&&z.url){let J=z.url.match(/https:\/\/([a-z0-9-]+)\.slack\.com\//)?.[1];if(J){let Q=E.indexOf(J);if(Q!==-1){let G=Math.max(0,Q-500),X=Math.min(E.length,Q+500),H=E.slice(G,X).match(/"(?:team_name|name)":"([^"]{2,60})"/);if(H?.[1]){z.teamName=H[1];continue}}z.teamName=J.split("-").map((G)=>G.charAt(0).toUpperCase()+G.slice(1)).join(" ")}}}let C=y7(),$=[...u.values()];if(C)for(let z of $)z.cookie=C;return $}function p7(D,F){let u=(B,E)=>{try{let C=h1("aes-128-cbc",F,B);C.setAutoPadding(!0);let $=Buffer.concat([C.update(E),C.final()]).toString("utf8");return $.startsWith("xoxd-")?$:void 0}catch{return}};return u(Buffer.alloc(16,32),D.slice(3))??(D.length>=35?u(D.slice(19,35),D.slice(35)):void 0)}function m7(D,F){let u=(B,E)=>{if(B&&E)return`${B} (${E})`;return B||E||F};try{let E=JSON.parse(eF(XD(D,"Local State"),"utf8")).profile?.info_cache?.[F];if(E&&(E.name||E.user_name))return u(E.name??"",E.user_name??"")}catch{}try{let E=JSON.parse(eF(XD(D,F,"Preferences"),"utf8")).profile;return u(E?.name??"",E?.user_name??"")}catch{return F}}function p1(){if(process.platform!=="darwin")return{candidates:[],totalProfiles:0};let D=XD(b0(),"Library","Application Support","Google","Chrome");if(!_F(D))return{candidates:[],totalProfiles:0};let F;try{F=v1('security find-generic-password -a Chrome -s "Chrome Safe Storage" -w',{encoding:"utf8",stdio:["ignore","pipe","ignore"]}).trimEnd()}catch{return{candidates:[],totalProfiles:0}}if(!F)return{candidates:[],totalProfiles:0};let u=f1(F,"saltysalt",1003,16,"sha1"),B=["Default",...I0(D).filter((C)=>C.startsWith("Profile "))],E=[];for(let C of B){let $=XD(D,C,"Cookies");if(!_F($))continue;let z=XD(b1(),`slack-chrome-cookies-${Date.now()}-${C}.db`);try{x1($,z);let{default:Z}=gD("bun:sqlite"),J=new Z(z,{readonly:!0}),Q=J.prepare("SELECT encrypted_value FROM cookies WHERE name='d' AND host_key LIKE '%slack%'").get();if(J.close(),!Q)continue;let G=Buffer.from(Q.encrypted_value),X=G.slice(0,3).toString();if(X==="v10"){let V=p7(G,u);if(!V)continue;E.push({profileDir:C,profileName:m7(D,C),cookie:V})}else if(X==="v20")throw Error(`Chrome cookie uses v20 (app-bound AES-256-GCM) which is not supported yet. Prefix found: ${G.slice(0,4).toString("hex")}`);else throw Error(`Unknown cookie encryption prefix: ${G.slice(0,4).toString("hex")}`)}catch(Z){if(Z instanceof Error&&(Z.message.includes("app-bound")||Z.message.includes("Unknown cookie")))throw Z}finally{try{I1(z)}catch{}}}return{candidates:E,totalProfiles:B.length}}function g7(){let D=b0();if(process.platform==="darwin")return XD(D,"Library","Application Support","Firefox","Profiles");if(process.platform==="linux")return XD(D,".mozilla","firefox");if(process.platform==="win32")return XD(process.env.APPDATA??XD(D,"AppData","Roaming"),"Mozilla","Firefox","Profiles");return""}function c7(D){let F=XD(b7(D),"profiles.ini"),u={};if(!_F(F))return u;try{let B=eF(F,"utf8"),E="",C="";for(let $ of B.split(`
108
- `)){let z=$.trim();if(z.startsWith("[")){E="",C="";continue}let Z=z.indexOf("=");if(Z===-1)continue;let J=z.slice(0,Z).trim().toLowerCase(),Q=z.slice(Z+1).trim();if(J==="name")E=Q;if(J==="path")C=Q.split(/[\\/]/).pop()??Q;if(E&&C)u[C]=E,E="",C=""}}catch{}return u}function m1(){let D=g7();if(!D||!_F(D))return[];let F=c7(D),u=[],B;try{B=I0(D)}catch{return[]}for(let E of B){let C=XD(D,E,"cookies.sqlite");if(!_F(C))continue;let $=XD(b1(),`slack-firefox-cookies-${Date.now()}-${E}.db`);try{x1(C,$);let{default:z}=gD("bun:sqlite"),Z=new z($,{readonly:!0}),J=Z.prepare("SELECT value FROM moz_cookies WHERE name='d' AND host LIKE '%slack%' LIMIT 1").get();if(Z.close(),!J?.value||!J.value.startsWith("xoxd-"))continue;let Q=F[E]??E;u.push({profileDir:E,profileName:Q,cookie:J.value})}catch{}finally{try{I1($)}catch{}}}return u}var d7=["search:read","channels:history","groups:history","im:history","mpim:history","channels:read","groups:read","im:read","mpim:read","users:read","chat:write","files:write"],i7=["channels:history","groups:history","im:history","mpim:history","channels:read","groups:read","im:read","mpim:read","users:read","chat:write","files:write"];function f0(D){return D.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")}function l7(){return JSON.stringify({display_information:{name:"slack-term"},oauth_config:{scopes:{user:d7}},settings:{org_deploy_enabled:!1,socket_mode_enabled:!1,token_rotation_enabled:!1}},null,2)}function n7(){return JSON.stringify({display_information:{name:"slack-term"},features:{bot_user:{display_name:"slack-term",always_online:!1}},oauth_config:{scopes:{bot:i7}},settings:{org_deploy_enabled:!1,socket_mode_enabled:!1,token_rotation_enabled:!1}},null,2)}async function LF(D,F){return(await D.question(F)).trim()}async function AF(D,F,u,B){console.error("Verifying token...");let E=await hF(F),C=f0(E.team),$;if(u)$=u;else if(D)$=await LF(D,`Workspace name [${C}]: `)||C;else $=C;let z=null;if(D){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 Z=await LF(D,"Choice [1/2/3/4, Enter=1]: ");if(Z==="2")z=au(process.cwd(),".slack-term",".env.local");else if(Z==="3")z=au(k7(),".slack-term",".env.local");else if(Z==="4")z=null;else z=au(process.cwd(),".env.local")}if(z===null)if(su($,{token:F,...E,...B?{cookie:B}:{}}),console.log(`Saved workspace "${$}" to profiles.json: ${E.team} (${E.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 ${$}`);else{let Z={SLACK_TOKEN:F};if(B)Z.SLACK_COOKIE=B;w1(z,Z),console.log(`Saved token to ${z}`),console.log(" SLACK_TOKEN will be picked up automatically in this directory tree.")}return $}async function t7(D){console.error("Scanning Slack desktop app...");let F=await y1();if(F.length===0)console.error("No sessions found. Make sure Slack is installed and you have signed in at least once."),process.exit(1);if(F.length===1&&D){let u=F[0],B=u.teamName??u.teamId;console.log(`Found workspace: ${B}${u.cookie?" (+ xoxd cookie)":""}`),await AF(D,u.token,f0(B),u.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 u of F){let B=u.teamName??u.teamId,E=f0(B);su(E,{token:u.token,team:B,teamId:u.teamId,url:u.url??"",user:"",...u.cookie?{cookie:u.cookie}:{}}),console.log(`Added workspace "${E}": ${B}${u.cookie?" + xoxd cookie":""}`)}if(console.log(""),F.length===1){let u=f0(F[0].teamName??F[0].teamId);console.log(`Run: slack auth use -g ${u}`)}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 g1(D){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 u=await LF(D,"Choice [1/2]: ")==="2"?"bot":"user",B=u==="user"?"xoxp-":"xoxb-",E=u==="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 "${E}" (starts with ${B})`),console.log("");let C=await LF(D,"Paste your token: ");if(!C)console.error("No token provided."),process.exit(1);if(!C.startsWith(B))console.error(`Expected a ${B} token, got: ${C.slice(0,10)}...`),process.exit(1);await AF(D,C)}async function h0(D,F){let u=F==="user"?l7():n7(),B=F==="user"?"User OAuth Token (xoxp-...)":"Bot User OAuth Token (xoxb-...)",E=F==="user"?"xoxp-":"xoxb-";if(F==="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(u),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 -> ${B}`),console.log("");let C=await LF(D,"Paste your token: ");if(!C)console.error("No token provided."),process.exit(1);if(!C.startsWith(E))console.error(`Expected a ${E} token, got: ${C.slice(0,10)}...`),process.exit(1);await AF(D,C)}async function c1(D={}){if(process.platform!=="darwin")console.error("Chrome cookie extraction is only supported on macOS."),process.exit(1);let F=x0();if(F.length===0)console.error("No workspaces configured. Run: slack auth login"),process.exit(1);let u;if(D.workspace){if(!F.find((Z)=>Z.name===D.workspace))console.error(`Workspace "${D.workspace}" not found. Available: ${F.map((Z)=>Z.name).join(", ")}`),process.exit(1);u=D.workspace}else if(F.length===1)u=F[0].name;else{let z=F.find((Z)=>Z.current);if(z)u=z.name,console.log(`Using active workspace: ${u}`);else{console.log("Multiple workspaces found. Choose one:"),F.forEach((G,X)=>console.log(` ${X+1}) ${G.name} (${G.profile.team})`));let Z=NF({input:process.stdin,output:process.stdout}),J=(await Z.question("Choice: ")).trim();Z.close();let Q=parseInt(J,10)-1;if(isNaN(Q)||Q<0||Q>=F.length)console.error("Invalid choice."),process.exit(1);u=F[Q].name}}if(F.find((z)=>z.name===u).profile.token.startsWith("xoxb-")){console.error(`
109
- Workspace "${u}" uses a bot token (xoxb-). A Chrome session cookie only
105
+ `)}function Hn(){let e=fi(),t=Yo(pl()),n=Yo(hl()),i=t??n;return Object.entries(e.profiles).map(([s,r])=>({name:s,profile:r,current:s===i}))}function di(e,t){let n=fi();n.profiles[e]=t,ea(n)}function pi(e,t){let n=fi();if(!(e in n.profiles))throw Error(`Profile not found: ${e}`);n.profiles[e].cookie=t,ea(n)}import{readdirSync as qn,readFileSync as an,existsSync as At,copyFileSync as na,unlinkSync as sa}from"node:fs";import{homedir as Yn,tmpdir as ia}from"node:os";import{join as he,dirname as gl}from"node:path";import{pbkdf2Sync as ra,createDecipheriv as oa}from"node:crypto";import{execSync as aa}from"node:child_process";function ml(){let e=Yn();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 Dl(){let e=Yn();if(process.platform==="darwin")return he(e,"Library","Application Support","Slack","Cookies");return""}function yl(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),i=e.slice(35),s=oa("aes-128-cbc",t,n);return s.setAutoPadding(!0),Buffer.concat([s.update(i),s.final()]).toString("utf8")}function wl(){if(process.platform!=="darwin")return;let e=Dl();if(!At(e))return;let t;try{t=aa('security find-generic-password -w -s "Slack Safe Storage" -a "Slack Key"',{encoding:"utf8",stdio:["ignore","pipe","ignore"]}).trimEnd()}catch{return}let n=ra(t,"saltysalt",1003,16,"sha1");try{let{default:i}=qe("bun:sqlite"),s=new i(e,{readonly:!0}),r=s.prepare("SELECT encrypted_value FROM cookies WHERE name='d' AND host_key LIKE '%slack%'").get();if(s.close(),!r)return;return yl(Buffer.from(r.encrypted_value),n)}catch{return}}async function ca(){let e=ml();if(!At(e))throw Error(`Slack desktop app LevelDB not found at:
106
+ ${e}
107
+ Is Slack installed and opened at least once?`);let t=qn(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=an(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),h=Math.min(c.length,u.index+2000),m=c.slice(d,h),p=m.match(/"url":"(https:\/\/[a-z0-9-]+\.slack\.com\/)"/),y=m.match(/"(?:team_name|name)":"([^"]{2,60})"/),E=n.get(l);if(!E||f.length>E.token.length){let F={token:f,teamId:l},k=p?.[1]??E?.url,C=y?.[1]??E?.teamName;if(k)F.url=k;if(C)F.teamName=C;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 h="";while(l<c.length&&c.charCodeAt(l)>=48&&c.charCodeAt(l)<=57)h+=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 p=`${u[0]}${h}-${m}`;n.set(f,{token:p,teamId:f})}}let s=qn(e).filter((a)=>a.endsWith(".ldb")||a.endsWith(".log")).map((a)=>{try{return an(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 r=wl(),o=[...n.values()];if(r)for(let a of o)a.cookie=r;return o}function bl(e,t){let n=(i,s)=>{try{let r=oa("aes-128-cbc",t,i);r.setAutoPadding(!0);let o=Buffer.concat([r.update(s),r.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 Fl(e,t){let n=(i,s)=>{if(i&&s)return`${i} (${s})`;return i||s||t};try{let s=JSON.parse(an(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(an(he(e,t,"Preferences"),"utf8")).profile;return n(s?.name??"",s?.user_name??"")}catch{return t}}function ua(){if(process.platform!=="darwin")return{candidates:[],totalProfiles:0};let e=he(Yn(),"Library","Application Support","Google","Chrome");if(!At(e))return{candidates:[],totalProfiles:0};let t;try{t=aa('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=ra(t,"saltysalt",1003,16,"sha1"),i=["Default",...qn(e).filter((r)=>r.startsWith("Profile "))],s=[];for(let r of i){let o=he(e,r,"Cookies");if(!At(o))continue;let a=he(ia(),`slack-chrome-cookies-${Date.now()}-${r}.db`);try{na(o,a);let{default:c}=qe("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 h=bl(l,n);if(!h)continue;s.push({profileDir:r,profileName:Fl(e,r),cookie:h})}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{sa(a)}catch{}}}return{candidates:s,totalProfiles:i.length}}function Cl(){let e=Yn();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 El(e){let t=he(gl(e),"profiles.ini"),n={};if(!At(t))return n;try{let i=an(t,"utf8"),s="",r="";for(let o of i.split(`
108
+ `)){let a=o.trim();if(a.startsWith("[")){s="",r="";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")r=f.split(/[\\/]/).pop()??f;if(s&&r)n[r]=s,s="",r=""}}catch{}return n}function la(){let e=Cl();if(!e||!At(e))return[];let t=El(e),n=[],i;try{i=qn(e)}catch{return[]}for(let s of i){let r=he(e,s,"cookies.sqlite");if(!At(r))continue;let o=he(ia(),`slack-firefox-cookies-${Date.now()}-${s}.db`);try{na(r,o);let{default:a}=qe("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{sa(o)}catch{}}}return n}var _l=["search:read","channels:history","groups:history","im:history","mpim:history","channels:read","groups:read","im:read","mpim:read","users:read","chat:write","files:write"],Sl=["channels:history","groups:history","im:history","mpim:history","channels:read","groups:read","im:read","mpim:read","users:read","chat:write","files:write"];function Xn(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")}function kl(){return JSON.stringify({display_information:{name:"slack-term"},oauth_config:{scopes:{user:_l}},settings:{org_deploy_enabled:!1,socket_mode_enabled:!1,token_rotation_enabled:!1}},null,2)}function Al(){return JSON.stringify({display_information:{name:"slack-term"},features:{bot_user:{display_name:"slack-term",always_online:!1}},oauth_config:{scopes:{bot:Sl}},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,i){console.error("Verifying token...");let s=await zt(t),r=Xn(s.team),o;if(n)o=n;else if(e)o=await Ot(e,`Workspace name [${r}]: `)||r;else o=r;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=hi(process.cwd(),".slack-term",".env.local");else if(c==="3")a=hi(xl(),".slack-term",".env.local");else if(c==="4")a=null;else a=hi(process.cwd(),".env.local")}if(a===null)if(di(o,{token:t,...s,...i?{cookie:i}:{}}),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(i)c.SLACK_COOKIE=i;ta(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 $l(e){console.error("Scanning Slack desktop app...");let t=await ca();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],i=n.teamName??n.teamId;console.log(`Found workspace: ${i}${n.cookie?" (+ xoxd cookie)":""}`),await It(e,n.token,Xn(i),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 i=n.teamName??n.teamId,s=Xn(i);di(s,{token:n.token,team:i,teamId:n.teamId,url:n.url??"",user:"",...n.cookie?{cookie:n.cookie}:{}}),console.log(`Added workspace "${s}": ${i}${n.cookie?" + xoxd cookie":""}`)}if(console.log(""),t.length===1){let n=Xn(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 fa(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",i=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 ${i})`),console.log("");let r=await Ot(e,"Paste your token: ");if(!r)console.error("No token provided."),process.exit(1);if(!r.startsWith(i))console.error(`Expected a ${i} token, got: ${r.slice(0,10)}...`),process.exit(1);await It(e,r)}async function Gn(e,t){let n=t==="user"?kl():Al(),i=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 -> ${i}`),console.log("");let r=await Ot(e,"Paste your token: ");if(!r)console.error("No token provided."),process.exit(1);if(!r.startsWith(s))console.error(`Expected a ${s} token, got: ${r.slice(0,10)}...`),process.exit(1);await It(e,r)}async function da(e={}){if(process.platform!=="darwin")console.error("Chrome cookie extraction is only supported on macOS."),process.exit(1);let t=Hn();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(`
109
+ Workspace "${n}" uses a bot token (xoxb-). A Chrome session cookie only
110
110
  `+`augments a user session token (xoxc-) — it has no effect on a bot token, so user-level
111
- `+"actions (tail @user, DMs, listing users) would still fail.");let z=F.filter((Z)=>Z.profile.token.startsWith("xoxc-")||Z.profile.token.startsWith("xoxp-"));if(z.length>0)console.error(` Target a user-token workspace instead: ${z.map((Z)=>Z.name).join(", ")}`),console.error(` slack auth chrome -w ${z[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 E,C;try{({candidates:E,totalProfiles:C}=p1())}catch(z){console.error(`Failed: ${z instanceof Error?z.message:String(z)}`),process.exit(1)}if(E.length===0)console.error(`No Slack session found in Chrome (scanned ${C} profile${C!==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 $;if(E.length===1&&C<=1)$=E[0].cookie,console.log(`Found session in Chrome profile: ${E[0].profileName}`);else{let z=E.length===1?`Found 1 Slack session across ${C} Chrome profiles:`:`Found ${E.length} Slack sessions across ${C} Chrome profiles:`;console.log(z),E.forEach((X,V)=>console.log(` ${V+1}) ${X.profileName} [${X.profileDir}]`)),console.log("");let Z=NF({input:process.stdin,output:process.stdout}),J=E.length===1?" [Enter=1]":"",Q=(await Z.question(`Choice [1-${E.length}]${J}: `)).trim();Z.close();let G=Q===""&&E.length===1?0:parseInt(Q,10)-1;if(isNaN(G)||G<0||G>=E.length)console.error("Invalid choice."),process.exit(1);$=E[G].cookie}ru(u,$),console.log(`Saved xoxd cookie to workspace "${u}".`),console.log("RTM WebSocket mode is now available: slack tail @you")}async function k1(D={}){let F=x0();if(F.length===0)console.error("No workspaces configured. Run: slack auth token"),process.exit(1);let u;if(D.workspace){if(!F.find(($)=>$.name===D.workspace))console.error(`Workspace "${D.workspace}" not found. Available: ${F.map(($)=>$.name).join(", ")}`),process.exit(1);u=D.workspace}else if(F.length===1)u=F[0].name;else{let C=F.find(($)=>$.current);if(C)u=C.name,console.log(`Using active workspace: ${u}`);else{console.log("Multiple workspaces found. Choose one:"),F.forEach((J,Q)=>console.log(` ${Q+1}) ${J.name} (${J.profile.team})`));let $=NF({input:process.stdin,output:process.stdout}),z=(await $.question("Choice: ")).trim();$.close();let Z=parseInt(z,10)-1;if(isNaN(Z)||Z<0||Z>=F.length)console.error("Invalid choice."),process.exit(1);u=F[Z].name}}console.log("Scanning Firefox profiles for Slack session...");let B=m1();if(B.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 E;if(B.length===1)E=B[0].cookie,console.log(`Found session in Firefox profile: ${B[0].profileName}`);else{console.log("Multiple Firefox profiles have a Slack session. Choose one:"),B.forEach((Z,J)=>console.log(` ${J+1}) ${Z.profileName} [${Z.profileDir}]`));let C=NF({input:process.stdin,output:process.stdout}),$=(await C.question("Choice: ")).trim();C.close();let z=parseInt($,10)-1;if(isNaN(z)||z<0||z>=B.length)console.error("Invalid choice."),process.exit(1);E=B[z].cookie}ru(u,E),console.log(`Saved xoxd cookie to workspace "${u}".`),console.log("RTM WebSocket mode is now available: slack tail @you")}async function d1(D={}){if(D.token){await AF(null,D.token,D.name);return}if(!process.stdin.isTTY){let u=[];for await(let E of process.stdin)u.push(E);let B=Buffer.concat(u).toString("utf8").trim();if(!B)console.error("No token provided on stdin."),process.exit(1);await AF(null,B,D.name);return}let F=NF({input:process.stdin,output:process.stdout});try{await g1(F)}finally{F.close()}}async function i1(D={}){let F=NF({input:process.stdin,output:process.stdout});try{if(D.bot!==void 0){await h0(F,D.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 u=await LF(F,"Choice [1/2, Enter=1]: ");await h0(F,u==="2"?"bot":"user")}finally{F.close()}}async function v0(D={}){let F=x0();if(F.length>0){console.log("Currently logged in:");for(let{name:B,profile:E,current:C}of F)console.log(` ${C?"*":" "} ${B} ${E.team} (${E.user||"unknown"})`);console.log(""),console.log("Adding another workspace:"),console.log("")}if(D.token){await AF(null,D.token,D.name);return}if(!process.stdin.isTTY){let B=[];for await(let C of process.stdin)B.push(C);let E=Buffer.concat(B).toString("utf8").trim();if(!E)console.error("No token provided on stdin."),process.exit(1);await AF(null,E,D.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 u=NF({input:process.stdin,output:process.stdout});try{let B=await LF(u,"Choice [1/2/3/4]: ");if(console.log(""),B==="1")await t7(u);else if(B==="2")await g1(u);else if(B==="3")await h0(u,"user");else if(B==="4")await h0(u,"bot");else console.error(`Invalid choice: "${B}". Enter 1, 2, 3, or 4.`),process.exit(1)}finally{u.close()}}async function y0(D,F,u,B){let E=F,C=[],$=E,z=0;while(!0){let Z=$.indexOf("<@U",z);if(Z===-1)break;let J=$.slice(Z+2),Q=J.search(/[>|]/),G=Q===-1?J:J.slice(0,Q);if(G.length>=9)C.push(G);z=Z+1}for(let Z of C){if(!u.has(Z))u.set(Z,await S0(D,Z,B));let J=u.get(Z)??Z;E=E.replaceAll(`<@${Z}>`,`@${J}`),E=E.replace(new RegExp(`<@${Z}\\|[^>]*>`,"g"),`@${J}`)}return E}function p0(D){return D.replace(/<!date\^(\d+)\^[^|>]*(?:\|([^>]*))?>/g,(F,u,B)=>{let E=Number(u);if(!Number.isFinite(E))return B??"date";let C=new Date(E*1000);if(Number.isNaN(C.getTime()))return B??"date";let $=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],z=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],Z=$[C.getUTCDay()]??"",J=z[C.getUTCMonth()]??"";return`${Z}, ${J} ${String(C.getUTCDate()).padStart(2,"0")}, ${C.getUTCFullYear()}`})}function n1(D){let F=typeof D.ts==="string"?D.ts:"",u=typeof D.thread_ts==="string"?D.thread_ts:"";return u!==""&&u!==F}function o7(D){let[F,u="000000"]=D.split("."),B=new Date(Number(F)*1000),E=B.getUTCFullYear(),C=String(B.getUTCMonth()+1).padStart(2,"0"),$=String(B.getUTCDate()).padStart(2,"0"),z=String(B.getUTCHours()).padStart(2,"0"),Z=String(B.getUTCMinutes()).padStart(2,"0"),J=String(B.getUTCSeconds()).padStart(2,"0"),Q=u.padEnd(6,"0").slice(0,6);return`${E}-${C}-${$}T${z}:${Z}:${J}.${Q}`}async function s7(D,F,u){let B=typeof F.ts==="string"?F.ts:"0.000000",E=o7(B),C="?";if(typeof F.user==="string"){let G=F.user,X="@"+G;if(!u.has(X)){let[,V]=await R0(D,G);u.set(X,V)}C=u.get(X)??G}else if(typeof F.username==="string")C=F.username;let $=typeof F.text==="string"?F.text:"",Z=p0(await y0(D,$,u)).split(`
112
- `),J=Z[0]+(Z.length>1?`
113
- `+Z.slice(1).map((G)=>` ${G}`).join(`
114
- `):""),Q=n1(F)?"↳ ":"";return`${E} ${Q}@${C}: ${J}`}async function r7(D,F,u,B,E,C,$,z){if(z?.aborted)return;return new Promise((Z)=>{let J=new D(u);z?.addEventListener("abort",()=>{J.close(),Z()},{once:!0}),J.addEventListener("open",()=>{process.stderr.write(`Connected via RTM (experimental).
115
- `)}),J.addEventListener("close",()=>Z()),J.addEventListener("error",()=>Z()),J.addEventListener("message",(Q)=>{(async()=>{try{let G;try{G=JSON.parse(String(Q.data))}catch{return}let X=typeof G.type==="string"?G.type:"";if(X==="ping"){J.send(JSON.stringify({type:"pong",reply_to:G.id??0}));return}if(X!=="message")return;if((typeof G.channel==="string"?G.channel:"")!==B)return;let H=typeof G.ts==="string"?G.ts:"";if(!H||C.has(H))return;let W=typeof G.subtype==="string"?G.subtype:"";if(W==="message_changed"||W==="message_deleted")return;if(E.thread){if((typeof G.thread_ts==="string"?G.thread_ts:H)!==E.thread&&H!==E.thread)return}if(E.watchThread&&n1(G)){if((typeof G.thread_ts==="string"?G.thread_ts:"")!==E.watchThread)return}if(E.me&&E.myUserId){if(!(typeof G.text==="string"?G.text:"").includes(`<@${E.myUserId}>`))return}if(C.add(H),C.size>1000){let N=C.values().next().value;if(N!==void 0)C.delete(N)}let j=await s7(F,G,$);process.stdout.write(j+`
116
- `)}catch(G){process.stderr.write(`RTM message error: ${G instanceof Error?G.message:String(G)}
117
- `)}})()})})}var l1=3,a7=2000,eu={sleep:(D)=>new Promise((F)=>setTimeout(F,D)),clientBoot:M1,getWebSocket:()=>{let D=globalThis.WebSocket;return typeof D==="function"?D:void 0}};async function t1(D,F,u,B,E,C,$){let z=eu.getWebSocket();if(!z)return;for(let Z=0;Z<l1;Z++){if($?.aborted)return;try{let{wsUrl:J}=await eu.clientBoot(D,F);await r7(z,D,J,u,B,E,C,$)}catch{}if($?.aborted)return;if(Z<l1-1)await eu.sleep(a7)}}function o1(D){let F=D.match(/^(\d+(?:\.\d+)?)(s|m|h|d)$/);if(!F)throw Error(`Invalid --since format: "${D}" (expected e.g. 10m, 2h, 1d)`);let u=parseFloat(F[1]);switch(F[2]){case"s":return u;case"m":return u*60;case"h":return u*3600;case"d":return u*86400}}var vD={sleep:(D)=>new Promise((F)=>setTimeout(F,D)),now:()=>Date.now(),tailRTM:t1};function oD(D){return D&&typeof D==="object"&&!Array.isArray(D)?D:{}}function D2(D){return Array.isArray(D)?D:[]}function s1(D){return Number(D)||0}function r1(D){let F=typeof D.ts==="string"?D.ts:"",u=typeof D.thread_ts==="string"?D.thread_ts:"";return u!==""&&u!==F}function e7(D){let[F,u="000000"]=D.split("."),B=new Date(Number(F)*1000),E=B.getUTCFullYear(),C=String(B.getUTCMonth()+1).padStart(2,"0"),$=String(B.getUTCDate()).padStart(2,"0"),z=String(B.getUTCHours()).padStart(2,"0"),Z=String(B.getUTCMinutes()).padStart(2,"0"),J=String(B.getUTCSeconds()).padStart(2,"0"),Q=u.padEnd(6,"0").slice(0,6);return`${E}-${C}-${$}T${z}:${Z}:${J}.${Q}`}async function D9(D,F,u,B,E){let C=typeof F.ts==="string"?F.ts:"0.000000",$=e7(C),z="?";if(typeof F.user==="string"){let H=F.user,W="@"+H;if(!u.has(W)){let[,j]=await R0(D,H,E);u.set(W,j)}z=u.get(W)??H}else if(typeof F.username==="string")z=F.username;let Z=typeof F.text==="string"?F.text:"",Q=p0(await y0(D,Z,u,E)).split(`
118
- `),G=Q[0]+(Q.length>1?`
119
- `+Q.slice(1).map((H)=>` ${H}`).join(`
120
- `):""),X=r1(F)?"↳ ":"",V=B?`${B} @${z}`:`@${z}`;return`${$} ${X}${V}: ${G}`}async function F9(D,F,u,B,E,C,$){let z=oD(await aF(D,F,20,$?void 0:u||void 0,$,B.cookie)),Z=D2(z.messages).map(oD).reverse(),J=oD(z.response_metadata),Q=z.has_more===!0&&typeof J.next_cursor==="string"?J.next_cursor:void 0,G=[];if(B.watchThread&&!$){let j=oD(await j1(D,F,B.watchThread,50,B.cookie));G=D2(j.messages).map(oD).filter((N)=>(typeof N.ts==="string"?N.ts:"")!==B.watchThread)}let X=[...Z.map((j)=>({m:j,fromHistory:!0})),...G.map((j)=>({m:j,fromHistory:!1}))].sort((j,N)=>s1(typeof j.m.ts==="string"?j.m.ts:"")-s1(typeof N.m.ts==="string"?N.m.ts:"")),V=[],H=u,W=!1;for(let{m:j,fromHistory:N}of X){let O=typeof j.ts==="string"?j.ts:"";if(!O||E.has(O))continue;let T=typeof j.subtype==="string"?j.subtype:"";if(T==="message_changed"||T==="message_deleted")continue;if(B.thread){if((typeof j.thread_ts==="string"?j.thread_ts:O)!==B.thread&&O!==B.thread)continue}if(B.watchThread&&r1(j)){if((typeof j.thread_ts==="string"?j.thread_ts:"")!==B.watchThread)continue}if(B.me&&B.myUserId){if(!(typeof j.text==="string"?j.text:"").includes(`<@${B.myUserId}>`))continue}if(E.add(O),E.size>1000){let R=E.values().next().value;if(R!==void 0)E.delete(R)}if(V.push(await D9(D,j,C,void 0,B.cookie)),N)H=O;let M=typeof j.user==="string"?j.user:"";if(!B.myUserId||M!==B.myUserId)W=!0}return{newCursor:H,lines:V,hasMore:z.has_more===!0,nextPageCursor:Q,emittedOther:W}}function u9(D){if(D.includes("slack.com")){let F=gu(D),u=F?.threadTs??F?.ts;if(u)return u;throw Error(`--watch-thread: could not extract a timestamp from "${D}"`)}if(/^\d{10}\.\d{6}$/.test(D))return D;if(/^\d{16}$/.test(D))return`${D.slice(0,10)}.${D.slice(10)}`;throw Error(`--watch-thread: "${D}" is not a valid ts or permalink`)}async function a1(D,F,u={},B){if(u.me&&!F)console.error(`slack tail --me requires a <target> channel.
111
+ `+"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,r;try{({candidates:s,totalProfiles:r}=ua())}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 ${r} profile${r!==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&&r<=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 ${r} Chrome profiles:`:`Found ${s.length} Slack sessions across ${r} Chrome profiles:`;console.log(a),s.forEach((d,h)=>console.log(` ${h+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}pi(n,o),console.log(`Saved xoxd cookie to workspace "${n}".`),console.log("RTM WebSocket mode is now available: slack tail @you")}async function pa(e={}){let t=Hn();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 r=t.find((o)=>o.current);if(r)n=r.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 i=la();if(i.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(i.length===1)s=i[0].cookie,console.log(`Found session in Firefox profile: ${i[0].profileName}`);else{console.log("Multiple Firefox profiles have a Slack session. Choose one:"),i.forEach((c,u)=>console.log(` ${u+1}) ${c.profileName} [${c.profileDir}]`));let r=$t({input:process.stdin,output:process.stdout}),o=(await r.question("Choice: ")).trim();r.close();let a=parseInt(o,10)-1;if(isNaN(a)||a<0||a>=i.length)console.error("Invalid choice."),process.exit(1);s=i[a].cookie}pi(n,s),console.log(`Saved xoxd cookie to workspace "${n}".`),console.log("RTM WebSocket mode is now available: slack tail @you")}async function ha(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 i=Buffer.concat(n).toString("utf8").trim();if(!i)console.error("No token provided on stdin."),process.exit(1);await It(null,i,e.name);return}let t=$t({input:process.stdin,output:process.stdout});try{await fa(t)}finally{t.close()}}async function ga(e={}){let t=$t({input:process.stdin,output:process.stdout});try{if(e.bot!==void 0){await Gn(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 Gn(t,n==="2"?"bot":"user")}finally{t.close()}}async function Vn(e={}){let t=Hn();if(t.length>0){console.log("Currently logged in:");for(let{name:i,profile:s,current:r}of t)console.log(` ${r?"*":" "} ${i} ${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 i=[];for await(let r of process.stdin)i.push(r);let s=Buffer.concat(i).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 i=await Ot(n,"Choice [1/2/3/4]: ");if(console.log(""),i==="1")await $l(n);else if(i==="2")await fa(n);else if(i==="3")await Gn(n,"user");else if(i==="4")await Gn(n,"bot");else console.error(`Invalid choice: "${i}". Enter 1, 2, 3, or 4.`),process.exit(1)}finally{n.close()}}async function Zn(e,t,n,i){let s=t,r=[],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)r.push(l);a=c+1}for(let c of r){if(!n.has(c))n.set(c,await Kn(e,c,i));let u=n.get(c)??c;s=s.replaceAll(`<@${c}>`,`@${u}`),s=s.replace(new RegExp(`<@${c}\\|[^>]*>`,"g"),`@${u}`)}return s}function Qn(e){return e.replace(/<!date\^(\d+)\^[^|>]*(?:\|([^>]*))?>/g,(t,n,i)=>{let s=Number(n);if(!Number.isFinite(s))return i??"date";let r=new Date(s*1000);if(Number.isNaN(r.getTime()))return i??"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[r.getUTCDay()]??"",u=a[r.getUTCMonth()]??"";return`${c}, ${u} ${String(r.getUTCDate()).padStart(2,"0")}, ${r.getUTCFullYear()}`})}function Da(e){let t=typeof e.ts==="string"?e.ts:"",n=typeof e.thread_ts==="string"?e.thread_ts:"";return n!==""&&n!==t}function Ol(e){let[t,n="000000"]=e.split("."),i=new Date(Number(t)*1000),s=i.getUTCFullYear(),r=String(i.getUTCMonth()+1).padStart(2,"0"),o=String(i.getUTCDate()).padStart(2,"0"),a=String(i.getUTCHours()).padStart(2,"0"),c=String(i.getUTCMinutes()).padStart(2,"0"),u=String(i.getUTCSeconds()).padStart(2,"0"),f=n.padEnd(6,"0").slice(0,6);return`${s}-${r}-${o}T${a}:${c}:${u}.${f}`}async function Il(e,t,n){let i=typeof t.ts==="string"?t.ts:"0.000000",s=Ol(i),r="?";if(typeof t.user==="string"){let l=t.user,d="@"+l;if(!n.has(d)){let[,h]=await Jn(e,l);n.set(d,h)}r=n.get(d)??l}else if(typeof t.username==="string")r=t.username;let o=typeof t.text==="string"?t.text:"",c=Qn(await Zn(e,o,n)).split(`
112
+ `),u=c[0]+(c.length>1?`
113
+ `+c.slice(1).map((l)=>` ${l}`).join(`
114
+ `):""),f=Da(t)?"↳ ":"";return`${s} ${f}@${r}: ${u}`}async function Pl(e,t,n,i,s,r,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).
115
+ `)}),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:"")!==i)return;let m=typeof l.ts==="string"?l.ts:"";if(!m||r.has(m))return;let p=typeof l.subtype==="string"?l.subtype:"";if(p==="message_changed"||p==="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&&Da(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(r.add(m),r.size>1000){let E=r.values().next().value;if(E!==void 0)r.delete(E)}let y=await Il(t,l,o);process.stdout.write(y+`
116
+ `)}catch(l){process.stderr.write(`RTM message error: ${l instanceof Error?l.message:String(l)}
117
+ `)}})()})})}var ma=3,Tl=2000,gi={sleep:(e)=>new Promise((t)=>setTimeout(t,e)),clientBoot:Ho,getWebSocket:()=>{let e=globalThis.WebSocket;return typeof e==="function"?e:void 0}};async function ya(e,t,n,i,s,r,o){let a=gi.getWebSocket();if(!a)return;for(let c=0;c<ma;c++){if(o?.aborted)return;try{let{wsUrl:u}=await gi.clientBoot(e,t);await Pl(a,e,u,n,i,s,r,o)}catch{}if(o?.aborted)return;if(c<ma-1)await gi.sleep(Tl)}}function wa(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:ya};function et(e){return e&&typeof e==="object"&&!Array.isArray(e)?e:{}}function mi(e){return Array.isArray(e)?e:[]}function ba(e){return Number(e)||0}function Fa(e){let t=typeof e.ts==="string"?e.ts:"",n=typeof e.thread_ts==="string"?e.thread_ts:"";return n!==""&&n!==t}function Rl(e){let[t,n="000000"]=e.split("."),i=new Date(Number(t)*1000),s=i.getUTCFullYear(),r=String(i.getUTCMonth()+1).padStart(2,"0"),o=String(i.getUTCDate()).padStart(2,"0"),a=String(i.getUTCHours()).padStart(2,"0"),c=String(i.getUTCMinutes()).padStart(2,"0"),u=String(i.getUTCSeconds()).padStart(2,"0"),f=n.padEnd(6,"0").slice(0,6);return`${s}-${r}-${o}T${a}:${c}:${u}.${f}`}async function Ml(e,t,n,i,s){let r=typeof t.ts==="string"?t.ts:"0.000000",o=Rl(r),a="?";if(typeof t.user==="string"){let m=t.user,p="@"+m;if(!n.has(p)){let[,y]=await Jn(e,m,s);n.set(p,y)}a=n.get(p)??m}else if(typeof t.username==="string")a=t.username;let c=typeof t.text==="string"?t.text:"",f=Qn(await Zn(e,c,n,s)).split(`
118
+ `),l=f[0]+(f.length>1?`
119
+ `+f.slice(1).map((m)=>` ${m}`).join(`
120
+ `):""),d=Fa(t)?"↳ ":"",h=i?`${i} @${a}`:`@${a}`;return`${o} ${d}${h}: ${l}`}async function Bl(e,t,n,i,s,r,o){let a=et(await on(e,t,20,o?void 0:n||void 0,o,i.cookie)),c=mi(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(i.watchThread&&!o){let y=et(await Uo(e,t,i.watchThread,50,i.cookie));l=mi(y.messages).map(et).filter((E)=>(typeof E.ts==="string"?E.ts:"")!==i.watchThread)}let d=[...c.map((y)=>({m:y,fromHistory:!0})),...l.map((y)=>({m:y,fromHistory:!1}))].sort((y,E)=>ba(typeof y.m.ts==="string"?y.m.ts:"")-ba(typeof E.m.ts==="string"?E.m.ts:"")),h=[],m=n,p=!1;for(let{m:y,fromHistory:E}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(i.thread){if((typeof y.thread_ts==="string"?y.thread_ts:F)!==i.thread&&F!==i.thread)continue}if(i.watchThread&&Fa(y)){if((typeof y.thread_ts==="string"?y.thread_ts:"")!==i.watchThread)continue}if(i.me&&i.myUserId){if(!(typeof y.text==="string"?y.text:"").includes(`<@${i.myUserId}>`))continue}if(s.add(F),s.size>1000){let A=s.values().next().value;if(A!==void 0)s.delete(A)}if(h.push(await Ml(e,y,r,void 0,i.cookie)),E)m=F;let C=typeof y.user==="string"?y.user:"";if(!i.myUserId||C!==i.myUserId)p=!0}return{newCursor:m,lines:h,hasMore:a.has_more===!0,nextPageCursor:f,emittedOther:p}}function Nl(e){if(e.includes("slack.com")){let t=si(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 Ca(e,t,n={},i){if(n.me&&!t)console.error(`slack tail --me requires a <target> channel.
121
121
  Cross-channel mention streaming is not yet supported.
122
- Use: slack tail "#channel" --me`),process.exit(1);if(!F)console.error("Usage: slack tail <#channel|@user>\n Run `slack tail --help` for details."),process.exit(1);let E=await K1(D,F),C=u.interval??60000,$=u.timeout?vD.now()+o1(u.timeout)*1000:1/0,z=new Map,Z=new Set;try{let W=oD(await O1(D,E,u.cookie));if(oD(W.channel).is_archived===!0)console.error("Warning: this channel is archived — no new messages will arrive.")}catch(W){let j=W instanceof Error?W.message:String(W);if(j.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(j.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(j.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: ${j}`)}let J="";if(u.since){let W=o1(u.since);J=(vD.now()/1000-W).toFixed(6)}else{let W=oD(await aF(D,E,1,void 0,void 0,u.cookie)),j=D2(W.messages).map(oD);if(j.length>0&&typeof j[0]?.ts==="string")J=j[0].ts,Z.add(J);else J=(vD.now()/1000).toFixed(6)}let Q;if(u.me||u.exitOnMessage)Q=(await hF(D,u.cookie)).userId||void 0;let G;if(u.watchThread!==void 0)try{G=u9(u.watchThread)}catch(W){console.error(W instanceof Error?W.message:String(W)),process.exit(1)}let X={...u.thread!==void 0?{thread:u.thread}:{},...G!==void 0?{watchThread:G}:{},...u.me!==void 0?{me:u.me}:{},...Q!==void 0?{myUserId:Q}:{},...u.cookie!==void 0?{cookie:u.cookie}:{}};if(D.startsWith("xoxc-")&&u.cookie!==void 0&&u.noRtm!==!0&&u.since===void 0&&u.timeout===void 0&&u.exitOnMessage!==!0){if(await vD.tailRTM(D,u.cookie,E,X,Z,z,B),B?.aborted)return;console.error("RTM unavailable — switching to polling.")}let V=!0,H=vD.now();while(!B?.aborted){if(vD.now()>=$)return;let W=!1;try{let O=vD.now()-H,T=C>0&&O>C*5,M,R=!0;do{let{newCursor:I,lines:y,nextPageCursor:l,emittedOther:h}=await F9(D,E,J,X,Z,z,M);if(J=I,V&&R&&u.since&&y.length===0)process.stdout.write(`(no messages in the last ${u.since} — watching for new)
123
- `);R=!1;for(let a of y)process.stdout.write(a+`
124
- `);if(h)W=!0;M=T?l:void 0}while(M);V=!1}catch(N){if(N instanceof dD){console.error(`Warning: Slack rate limit hit — backing off for ${N.retryAfter}s`),await vD.sleep(N.retryAfter*1000);continue}throw N}if(u.exitOnMessage&&W)return;H=vD.now();let j=$-vD.now();if(j<=0)return;await vD.sleep(Math.min(C,j))}}var bD=[{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"}],m0=bD.length;function e1(D){return D.replace(/\s*\n\s*/g," ")}function D3(D,F,u,B,E){let C=[`*${D}*`];if(F)C.push("",F);if(u.length){if(C.push(""),C.push(...u.map(($,z)=>`${bD[z].glyph} ${e1($)}`)),B.length)C.push(""),C.push(...B.map(($,z)=>`(${z+11}) ${e1($)}`)),C.push("_11 番目以降はリアクションがないので、返信で答えてください。_");C.push(""),C.push(E?"_下のリアクションを 1 つ押すと回答になります。当てはまるものがなければ、このメッセージの *スレッド* で返信してください (チャンネルへの通常投稿は回答として拾いません)。_":"_下のリアクションを 1 つ押すと回答になります。当てはまるものがなければ、このメッセージに返信してください。_")}else C.push(""),C.push(E?"_このメッセージの *スレッド* で返信してください。本文がそのまま回答になります (チャンネルへの通常投稿は回答として拾いません)。_":"_このメッセージに返信してください。本文がそのまま回答になります。_");return C.join(`
125
- `)}function F3(D,F,u){let B=F.answer.split(`
126
- `).map((E)=>`> ${E}`).join(`
127
- `);return`:white_check_mark: *${D}*
128
- _${F.how}で回答済み${u?` (${u})`:""}_
122
+ 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 Ko(e,t),r=n.interval??60000,o=n.timeout?Ue.now()+wa(n.timeout)*1000:1/0,a=new Map,c=new Set;try{let p=et(await zo(e,s,n.cookie));if(et(p.channel).is_archived===!0)console.error("Warning: this channel is archived — no new messages will arrive.")}catch(p){let y=p instanceof Error?p.message:String(p);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 p=wa(n.since);u=(Ue.now()/1000-p).toFixed(6)}else{let p=et(await on(e,s,1,void 0,void 0,n.cookie)),y=mi(p.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 zt(e,n.cookie)).userId||void 0;let l;if(n.watchThread!==void 0)try{l=Nl(n.watchThread)}catch(p){console.error(p instanceof Error?p.message:String(p)),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,i),i?.aborted)return;console.error("RTM unavailable — switching to polling.")}let h=!0,m=Ue.now();while(!i?.aborted){if(Ue.now()>=o)return;let p=!1;try{let F=Ue.now()-m,k=r>0&&F>r*5,C,A=!0;do{let{newCursor:T,lines:v,nextPageCursor:L,emittedOther:R}=await Bl(e,s,u,d,c,a,C);if(u=T,h&&A&&n.since&&v.length===0)process.stdout.write(`(no messages in the last ${n.since} — watching for new)
123
+ `);A=!1;for(let G of v)process.stdout.write(G+`
124
+ `);if(R)p=!0;C=k?L:void 0}while(C);h=!1}catch(E){if(E instanceof Ge){console.error(`Warning: Slack rate limit hit — backing off for ${E.retryAfter}s`),await Ue.sleep(E.retryAfter*1000);continue}throw E}if(n.exitOnMessage&&p)return;m=Ue.now();let y=o-Ue.now();if(y<=0)return;await Ue.sleep(Math.min(r,y))}}var Me=[{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"}],es=Me.length,ts="question";function yi(e){let t=e.split(`
125
+ `),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((i)=>i[1])}function wi(e,t){let n=e.split(`
126
+ `);if(n.length<2)return e;if(yi(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 i=n.join(`
127
+ `);return i===e?e:i}function vl(e){return e!==void 0&&e.startsWith("_:warning: 同時に複数選ばれているため回答として数えていません — どれか 1 つだけ残してください: ")&&e.endsWith("_")}var bi="white_check_mark",Di=`:${bi}: `;function Ea(e){return e.replace(/\s*\n\s*/g," ")}function xa(e,t,n,i,s){let r=[`:question: *${e}*`];if(t)r.push("",t);if(n.length){if(r.push(""),r.push(...n.map((o,a)=>`${Me[a].glyph} ${Ea(o)}`)),i.length)r.push(""),r.push(...i.map((o,a)=>`(${a+11}) ${Ea(o)}`)),r.push("_11 番目以降はリアクションがないので、返信で答えてください。_");r.push(""),r.push(s?"_下のリアクションを 1 つ押すと回答になります。当てはまるものがなければ、このメッセージの *スレッド* で返信してください (チャンネルへの通常投稿は回答として拾いません)。_":"_下のリアクションを 1 つ押すと回答になります。当てはまるものがなければ、このメッセージに返信してください。_")}else r.push(""),r.push(s?"_このメッセージの *スレッド* で返信してください。本文がそのまま回答になります (チャンネルへの通常投稿は回答として拾いません)。_":"_このメッセージに返信してください。本文がそのまま回答になります。_");return r.join(`
128
+ `)}function _a(e,t,n){let i=t.answer.split(`
129
+ `).map((s)=>`> ${s}`).join(`
130
+ `);return`${Di}*${e}*
131
+ _${t.how}で回答済み${n?` (${n})`:""}_
129
132
 
130
- ${B}`}function u3(D){let F=D.split(`
131
- `);if(D.startsWith(":white_check_mark: ")){let Q=F[0].slice(19).replace(/^\*/,"").replace(/\*$/,""),G=F.filter((X)=>X.startsWith("> ")).map((X)=>X.slice(2)).join(`
132
- `);if(!G)return{kind:"other"};return{kind:"resolved",question:Q,answer:G}}let u=F[F.length-1]??"",B,E;switch(u){case"_下のリアクションを 1 つ押すと回答になります。当てはまるものがなければ、このメッセージの *スレッド* で返信してください (チャンネルへの通常投稿は回答として拾いません)。_":B=!0,E=!0;break;case"_下のリアクションを 1 つ押すと回答になります。当てはまるものがなければ、このメッセージに返信してください。_":B=!1,E=!0;break;case"_このメッセージの *スレッド* で返信してください。本文がそのまま回答になります (チャンネルへの通常投稿は回答として拾いません)。_":B=!0,E=!1;break;case"_このメッセージに返信してください。本文がそのまま回答になります。_":B=!1,E=!1;break;default:return{kind:"other"}}if(!F[0].startsWith("*"))return{kind:"other"};let C=0;while(C<F.length&&!(F[C].endsWith("*")&&(C>0||F[0].length>1)))C++;if(C>=F.length)return{kind:"other"};let $=F.slice(0,C+1).join(`
133
- `).replace(/^\*/,"").replace(/\*$/,""),z=[],Z=[];if(E){let J=F.length-2;if(F[J]!=="")return{kind:"other"};if(J--,F[J]==="_11 番目以降はリアクションがないので、返信で答えてください。_"){J--;while(J>=0&&/^\(\d+\) /.test(F[J]))Z.unshift(F[J].replace(/^\(\d+\) /,"")),J--;if(F[J]!=="")return{kind:"other"};J--}let Q=[];while(J>=0){let G=F[J];if(!bD.some((X)=>G.startsWith(`${X.glyph} `)||G===X.glyph))break;Q.unshift(G),J--}if(!Q.length||Q.length>m0)return{kind:"other"};for(let G=0;G<Q.length;G++){let X=bD[G].glyph;if(!(Q[G].startsWith(`${X} `)||Q[G]===X))return{kind:"other"};z.push(Q[G].slice(X.length+1))}if(F[J]!=="")return{kind:"other"};if(J<C+1)return{kind:"other"};for(let G=0;G<Z.length;G++)if(!F.includes(`(${G+11}) ${Z[G]}`))return{kind:"other"}}return{kind:"open",question:$,reactable:z,overflow:Z,threadOnly:B}}class vF extends Error{retryAfter;constructor(D){super(`Slack rate limited — retry after ${D}s`);this.name="RateLimitError",this.retryAfter=D}}function F2(){return(process.env.SLACK_API_BASE??"https://slack.com/api").replace(/\/$/,"")}async function E3(D,F,u,B){let E={};if(B)E.Cookie=`d=${B}`;let C=await fetch(`${F2()}/${F}`,{...u,headers:{...u.headers??{},Authorization:`Bearer ${D}`,...E}});if(C.status===429){let z=parseInt(C.headers.get("retry-after")??"60",10);throw new vF(isNaN(z)?60:z)}let $=await C.json();if($.ok!==!0){let z=$.error??"unknown";if(z==="ratelimited")throw new vF(60);if(z==="invalid_auth"&&D.startsWith("xoxc-")&&!B)throw Error(`Desktop app token (xoxc-) needs its session cookie to be accepted by the public Slack API.
133
+ ${i}`}function Sa(e){let t=e.split(`
134
+ `);if(e.startsWith(Di)){let l=t[0].slice(Di.length).replace(/^\*/,"").replace(/\*$/,""),d=t.filter((h)=>h.startsWith("> ")).map((h)=>h.slice(2)).join(`
135
+ `);if(!d)return{kind:"other"};return{kind:"resolved",question:l,answer:d}}let n=t[t.length-1]??"",i,s;switch(n){case"_下のリアクションを 1 つ押すと回答になります。当てはまるものがなければ、このメッセージの *スレッド* で返信してください (チャンネルへの通常投稿は回答として拾いません)。_":i=!0,s=!0;break;case"_下のリアクションを 1 つ押すと回答になります。当てはまるものがなければ、このメッセージに返信してください。_":i=!1,s=!0;break;case"_このメッセージの *スレッド* で返信してください。本文がそのまま回答になります (チャンネルへの通常投稿は回答として拾いません)。_":i=!0,s=!1;break;case"_このメッセージに返信してください。本文がそのまま回答になります。_":i=!1,s=!1;break;default:return{kind:"other"}}let r=t[0].startsWith(":question: ")?t[0].slice(11):t[0];if(t[0]=r,!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(`
136
+ `).replace(/^\*/,"").replace(/\*$/,""),c=[],u=[];if(s){let f=t.length-2;if(vl(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(!Me.some((h)=>d.startsWith(`${h.glyph} `)||d===h.glyph))break;l.unshift(d),f--}if(!l.length||l.length>es)return{kind:"other"};for(let d=0;d<l.length;d++){let h=Me[d].glyph;if(!(l[d].startsWith(`${h} `)||l[d]===h))return{kind:"other"};c.push(l[d].slice(h.length+1))}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:i}}var Fi=[{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"}],Sg=Fi.length;function Ci(e){let t=e.split(`
137
+ `),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((i)=>i[1])}function ka(e,t){let n=e.split(`
138
+ `);if(n.length<2)return e;if(Ci(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 i=n.join(`
139
+ `);return i===e?e:i}function Aa(e){return e!==void 0&&e.startsWith("_:warning: 同時に複数選ばれているため回答として数えていません — どれか 1 つだけ残してください: ")&&e.endsWith("_")}var jl="white_check_mark",kg=`:${jl}: `;var Be=Fi,Ht=Be.length,cn="ballot_box_with_ballot",Ei=`:${cn}: `,Oa="_下のリアクションで投票してください (1 人 1 票、押し直しで変更できます)。_",Ia="_下のリアクションで投票してください (当てはまるものを *いくつでも* 押せます)。_",ns="_締切: ",ss="_",Si="bar_chart",xi=`:${Si}: `;function is(e){return`:${Be[e].name}:`}function $a(e,t){for(let n of[is(t),Be[t].glyph])if(e.startsWith(`${n} `))return e.slice(n.length+1);return null}function Ll(e){return Be.some((t,n)=>e.startsWith(`${is(n)} `)||e.startsWith(`${t.glyph} `))}function _i(e){return e.replace(/\s*\n\s*/g," ")}function Pa(e,t,n,i={}){let s=!!i.multi,r=i.deadline??"",o=i.invalid??[];if(!n.length||n.length>Ht)throw Error(`poll needs 1..${Ht} choices, got ${n.length}`);let a=[`${Ei}*${e}*`];if(t)a.push("",t);if(a.push(""),a.push(...n.map((c,u)=>`${is(u)} ${_i(c)}`)),a.push(""),r)a.push(`${ns}${_i(r)}${ss}`);return a.push(s?Ia:Oa),ka(a.join(`
140
+ `),s?[]:o)}function Ta(e,t){let n=t.reduce((s,r)=>s+r.count,0),i=[`${xi}*${e}*`,`_投票終了 (計 ${n} 票)_`,""];return i.push(...t.map((s,r)=>`${is(r)} ×${s.count} ${_i(s.choice)}`)),i.join(`
141
+ `)}function Ra(e){let t=e.split(`
142
+ `);if(e.startsWith(xi)){let d=t[0].slice(xi.length).replace(/^\*/,"").replace(/\*$/,""),h=[];for(let m=0;m<Be.length;m++){let p=t.map((E)=>$a(E,m)).find((E)=>E!==null&&E.startsWith("×"));if(p===void 0)break;let y=/^×(\d+) (.*)$/.exec(p);if(!y)return{kind:"other"};h.push({choice:y[2],count:Number(y[1])})}if(!h.length)return{kind:"other"};return{kind:"closed",question:d,tallies:h}}let n=t[t.length-1]??"",i;if(n===Oa)i=!1;else if(n===Ia)i=!0;else return{kind:"other"};if(t[0].startsWith(Ei))t[0]=t[0].slice(Ei.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 r=t.slice(0,s+1).join(`
143
+ `).replace(/^\*/,"").replace(/\*$/,""),o=t.length-2,a=Ci(e);if(Aa(t[o]))o--;let c="",u=t[o];if(u!==void 0&&u.startsWith(ns)&&u.endsWith(ss)&&u.length>ns.length+ss.length)c=u.slice(ns.length,-ss.length),o--;if(t[o]!=="")return{kind:"other"};o--;let f=[];while(o>=0){let d=t[o];if(!Ll(d))break;f.unshift(d),o--}if(!f.length||f.length>Ht)return{kind:"other"};let l=[];for(let d=0;d<f.length;d++){let h=$a(f[d],d);if(h===null)return{kind:"other"};l.push(h)}if(t[o]!=="")return{kind:"other"};if(o<s+1)return{kind:"other"};return{kind:"open",question:r,choices:l,multi:i,deadline:c,invalid:a}}function Ma(e,t,n,i){let s=new Map(t.map((u)=>[u.name,u.users])),r=e.map((u,f)=>(s.get(Be[f].name)??[]).filter((l)=>!n.has(l))),o=[];if(!i){let u=new Map;for(let f of r)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=r.map((u)=>u.filter((f)=>!a.has(f)));return{tallies:e.map((u,f)=>({choice:u,count:c[f].length})),voters:c,ambiguous:o}}class qt extends Error{retryAfter;constructor(e){super(`Slack rate limited — retry after ${e}s`);this.name="RateLimitError",this.retryAfter=e}}function ki(){return(process.env.SLACK_API_BASE??"https://slack.com/api").replace(/\/$/,"")}async function Na(e,t,n,i){let s={};if(i)s.Cookie=`d=${i}`;let r=await fetch(`${ki()}/${t}`,{...n,headers:{...n.headers??{},Authorization:`Bearer ${e}`,...s}});if(r.status===429){let a=parseInt(r.headers.get("retry-after")??"60",10);throw new qt(isNaN(a)?60:a)}let o=await r.json();if(o.ok!==!0){let a=o.error??"unknown";if(a==="ratelimited")throw new qt(60);if(a==="invalid_auth"&&e.startsWith("xoxc-")&&!i)throw Error(`Desktop app token (xoxc-) needs its session cookie to be accepted by the public Slack API.
134
144
  Attach it: slack auth chrome (macOS) or slack auth firefox
135
145
  Or replace the token with an xoxp- user token:
136
- slack auth token`);if((z==="missing_scope"||z==="cannot_dm_bot")&&D.startsWith("xoxb-"))throw Error(`Slack error on ${F}: ${z} — ${z==="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"}.
146
+ 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"}.
137
147
  Tailing/DMing people and listing users need a user session, not a bot token.
138
148
  Switch workspace: slack auth ls then slack auth use <name>
139
- Or import your Slack desktop session: slack auth login`);throw Error(`Slack error on ${F}: ${z}`)}return $}async function E9(D,F,u,B){let E={};if(B)E.Cookie=`d=${B}`;let C=await fetch(`${F2()}/${F}`,{...u,headers:{...u.headers??{},Authorization:`Bearer ${D}`,...E}});if(C.status===429){let z=parseInt(C.headers.get("retry-after")??"60",10);throw new vF(isNaN(z)?60:z)}let $=await C.json();if($.ok!==!0){let z=$.error??"unknown";if(z==="ratelimited")throw new vF(60);if((z==="invalid_auth"||z==="not_authed")&&!D.startsWith("xoxc-"))throw Error(`The draft API requires a desktop app session token (xoxc-).
140
- Import from Slack desktop: slack auth login`);if((z==="invalid_auth"||z==="not_authed")&&!B)throw Error(`drafts.list also requires the xoxd session cookie.
141
- Attach it with: slack auth chrome (macOS) or slack auth firefox`);throw Error(`Slack error on ${F}: ${z}`)}return $}function PF(D,F,u={},B){let E=new URLSearchParams({token:D,...u});return E9(D,F,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:E.toString()},B)}function $D(D,F,u,B){let E=new URLSearchParams(u).toString();return E3(D,`${F}?${E}`,{method:"GET"},B)}function yD(D,F,u,B){return E3(D,F,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(u)},B)}async function B3(D,F){let u=await $D(D,"auth.test",{},F);return{team:u.team??"",teamId:u.team_id??"",url:u.url??"",user:u.user??"",userId:u.user_id??""}}async function C3(D,F){let u={Authorization:`Bearer ${D}`};if(F)u.Cookie=`d=${F}`;let B=await fetch(`${F2()}/auth.test`,{method:"GET",headers:u});if(B.status===429){let $=parseInt(B.headers.get("retry-after")??"60",10);throw new vF(isNaN($)?60:$)}let E=B.headers.get("x-oauth-scopes")??"",C=await B.json();if(C.ok!==!0)throw Error(`Slack error on auth.test: ${C.error??"unknown"}`);return{userId:C.user_id??"",user:C.user??"",botId:C.bot_id??"",team:C.team??"",url:C.url??"",scopes:E.split(",").map(($)=>$.trim()).filter(Boolean)}}async function uF(D,F,u=20,B,E,C,$){let z={channel:F,limit:String(u)};if(B!==void 0)z.oldest=B;if(E!==void 0)z.cursor=E;if($)z.inclusive="true";return $D(D,"conversations.history",z,C)}async function lD(D,F,u,B=50,E){return $D(D,"conversations.replies",{channel:F,ts:u,limit:String(B)},E)}async function $3(D,F,u){return $D(D,"files.info",{file:F},u)}async function z3(D,F={},u){let B={count:String(Math.min(Math.max(F.count??100,1),200)),page:String(Math.max(F.page??1,1))};if(F.types)B.types=F.types;if(F.channel)B.channel=F.channel;if(F.user)B.user=F.user;return $D(D,"files.list",B,u)}async function Z3(D,F,u={},B){let E={list_id:F};if(u.limit)E.limit=String(u.limit);if(u.cursor)E.cursor=u.cursor;return PF(D,"lists.records.list",E,B)}async function J3(D,F,u,B,E){return $D(D,"search.messages",{query:F,sort:"timestamp",sort_dir:"desc",count:String(Math.min(Math.max(u,1),100)),page:String(Math.max(B,1))},E)}async function G3(D,F,u){return J3(D,F,100,1,u)}async function u2(D,F,u,B){let C=1,$=[],z={ok:!0,messages:{}};while(!0){let J=await J3(D,F,100,C,B),Q=D0(J,["messages","matches"]),G=Array.isArray(Q)?Q:[];$.push(...G);let X=Number(D0(J,["messages","paging","pages"])??1);if(z=J,G.length===0||C>=X||$.length>=u)break;C+=1}let Z=z;if(!Z.messages)Z.messages={};return Z.messages.matches=$.slice(0,u),Z}async function g0(D,F,u,B,E,C){let $={channel:F,text:u,blocks:[{type:"markdown",text:u}]};if(B!==void 0)$.thread_ts=B;if(E&&B!==void 0)$.reply_broadcast=!0;return(await yD(D,"chat.postMessage",$,C)).ts??""}async function Q3(D,F,u,B,E,C){let $={channel:F,text:u,post_at:B,blocks:[{type:"markdown",text:u}]};if(E!==void 0)$.thread_ts=E;return(await yD(D,"chat.scheduleMessage",$,C)).scheduled_message_id??""}async function X3(D,F,u){let B={};if(F)B.channel=F;return $D(D,"chat.scheduledMessages.list",B,u)}async function Y3(D,F,u,B){await yD(D,"chat.deleteScheduledMessage",{channel:F,scheduled_message_id:u},B)}async function c0(D,F,u,B){return(await $D(D,"chat.getPermalink",{channel:F,message_ts:u},B)).permalink??""}async function E2(D,F,u,B,E){return(await yD(D,"chat.update",{channel:F,ts:u,text:B,blocks:[{type:"markdown",text:B}]},E)).ts??u}async function W3(D,F,u,B){await yD(D,"chat.delete",{channel:F,ts:u},B)}async function B2(D,F,u,B,E){await yD(D,"reactions.add",{channel:F,timestamp:u,name:B},E)}async function C2(D,F,u,B,E){await yD(D,"reactions.remove",{channel:F,timestamp:u,name:B},E)}async function V3(D,F,u=!1,B){let E=await yD(D,"conversations.create",{name:F,is_private:u},B);return{id:E.channel?.id??"",name:E.channel?.name??F}}async function H3(D,F,u,B){await yD(D,"conversations.invite",{channel:F,users:u.join(",")},B)}async function k0(D,F){let u=[],B="";while(!0){let E={limit:"200",types:"public_channel,private_channel,im,mpim"};if(B)E.cursor=B;let C=await $D(D,"conversations.list",E,F);if(u.push(...C.channels??[]),B=C.response_metadata?.next_cursor??"",!B)break}return{channels:u}}async function yF(D,F,u){let E=(await yD(D,"conversations.open",{users:F},u)).channel?.id;if(!E)throw Error(`Failed to open DM with user ${F}`);return E}function iD(D){return D.toLowerCase().replace(/[-_\s]/g,"")}async function d0(D,F,u){if(!F.startsWith("@")){if(/^[UW][A-Za-z0-9]{6,}$/.test(F))return F;throw Error(`Expected @user or a user ID, got: ${F}`)}let B=iD(F.slice(1)),E=await $D(D,"auth.test",{},u);if(B==="you"||B==="me"||iD(E.user??"")===B){if(!E.user_id)throw Error("auth.test did not return user_id");return E.user_id}let C="";while(!0){let $={limit:"200"};if(C)$.cursor=C;let z=await $D(D,"users.list",$,u);for(let Z of z.members??[]){let J=iD(Z.name??""),Q=iD(Z.real_name??""),G=iD(Z.profile?.display_name??"");if(J===B||Q===B||G&&G===B)return Z.id??""}if(C=z.response_metadata?.next_cursor??"",!C)break}throw Error(`User not found: ${F}`)}function pF(D){let F=D.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(!F)return;let u=F[1],B=F[2]&&F[3]?`${F[2]}.${F[3]}`:void 0,E=D.indexOf("?"),C=E>=0?new URLSearchParams(D.slice(E)):void 0,$=C?.get("thread_ts")??void 0,J={channel:C?.get("cid")??void 0??u};if(B)J.ts=B;if($)J.threadTs=$;return J}function B9(D){return pF(D)?.channel}async function qD(D,F,u){let B=B9(F);if(B)return B;if(!F.startsWith("@")&&!F.startsWith("#")){if(/^[A-Za-z0-9]{9,}$/.test(F))return F;throw Error(`Target must start with # or @ (or be a Slack URL/ID), got: ${F}`)}let E=F.startsWith("@"),C=F.slice(1),$=iD(C);if(E){let J=await $D(D,"auth.test",{},u);if($==="you"||$==="me"||iD(J.user??"")===$){let H=J.user_id;if(!H)throw Error("auth.test did not return user_id");let j=((await $D(D,"conversations.list",{types:"im",limit:"200"},u)).channels??[]).find((N)=>N.user===H);if(j?.id)return String(j.id);return yF(D,H,u)}let G="",X="";while(!0){let H={limit:"200"};if(X)H.cursor=X;let W=await $D(D,"users.list",H,u);for(let j of W.members??[]){let N=iD(j.name??""),O=iD(j.real_name??""),T=iD(j.profile?.display_name??"");if(N===$||O===$||T&&T===$){G=j.id??"";break}}if(G)break;if(X=W.response_metadata?.next_cursor??"",!X)break}if(!G)throw Error(`User not found: ${F}`);let V="";while(!0){let H={types:"im",limit:"200"};if(V)H.cursor=V;let W=await $D(D,"conversations.list",H,u);for(let j of W.channels??[])if(j.user===G)return String(j.id??"");if(V=W.response_metadata?.next_cursor??"",!V)break}throw Error(`No existing DM with ${F} (${G}). Open it once in Slack first.`)}let z=C.toLowerCase(),Z="";while(!0){let J={limit:"200",types:"public_channel,private_channel",exclude_archived:"true"};if(Z)J.cursor=Z;let Q=await $D(D,"conversations.list",J,u);for(let G of Q.channels??[])if(String(G.name??"").toLowerCase()===z)return String(G.id??"");if(Z=Q.response_metadata?.next_cursor??"",!Z)break}throw Error(`channel not found: ${F}`)}async function F0(D,F,u){try{let B=await $D(D,"users.info",{user:F},u),E=B.user?.profile?.display_name,C=E&&E.length>0?E:B.user?.real_name??B.user?.name??F,$=B.user?.name??F;return[C,$]}catch{return[F,F]}}async function EF(D,F,u){try{let B=await $D(D,"users.info",{user:F},u),E=B.user?.profile?.display_name;if(E&&E.length>0)return E;return B.user?.real_name??B.user?.name??F}catch{return F}}async function $2(D,F){let u=[],B="";while(!0){let E={limit:"200"};if(B)E.cursor=B;let C=await $D(D,"users.list",E,F);if(u.push(...C.members??[]),B=C.response_metadata?.next_cursor??"",!B)break}return{members:u}}async function u0(D,F){return PF(D,"drafts.list",{},F)}async function q3(D,F,u,B){let{randomUUID:E}=await import("node:crypto"),C=JSON.stringify([{type:"rich_text",elements:[{type:"rich_text_section",elements:[{type:"text",text:u}]}]}]);return PF(D,"drafts.create",{client_msg_id:E(),destinations:JSON.stringify([{channel_id:F}]),blocks:C,file_ids:JSON.stringify([]),is_from_composer:"true"},B)}async function j3(D,F,u,B,E){let C=JSON.stringify([{type:"rich_text",elements:[{type:"rich_text_section",elements:[{type:"text",text:B}]}]}]),$=(Date.now()/1000).toFixed(6);return PF(D,"drafts.update",{draft_id:F,client_last_updated_ts:$,destinations:JSON.stringify([{channel_id:u}]),blocks:C,file_ids:JSON.stringify([])},E)}async function U3(D,F,u){return PF(D,"conversations.info",{channel:F},u)}async function z2(D,F,u){return $D(D,"users.info",{user:F},u)}async function E0(D,F,u){return $D(D,"conversations.info",{channel:F},u)}async function K3(D,F,u){let B=(Date.now()/1000).toFixed(6);return PF(D,"drafts.delete",{draft_id:F,client_last_updated_ts:B},u)}async function Z2(D,F){let u=await PF(D,"auth.test",{},F);return{userId:String(u.user_id??""),teamId:String(u.team_id??"")}}async function O3(D,F,u,B={},E){let{statSync:C,readFileSync:$}=await import("node:fs"),{basename:z}=await import("node:path"),Z=C(u),J=z(u),Q=await $D(D,"files.getUploadURLExternal",{filename:J,length:String(Z.size)},E),G=Q.upload_url,X=Q.file_id;if(!G||!X)throw Error("files.getUploadURLExternal returned no upload_url/file_id");let V=$(u),H=await fetch(G,{method:"POST",headers:{"Content-Type":"application/octet-stream"},body:V});if(!H.ok)throw Error(`Upload PUT failed: ${H.status} ${H.statusText}`);let W={files:[{id:X,title:B.title??J}],channel_id:F};if(B.threadTs)W.thread_ts=B.threadTs;if(B.initialComment)W.initial_comment=B.initialComment;let j=await yD(D,"files.completeUploadExternal",W,E),N={fileId:X},O=j.files?.[0]?.permalink;if(O)N.permalink=O;return N}function D0(D,F){let u=D;for(let B of F){if(u===void 0||u===null)return;if(typeof B==="number"){if(!Array.isArray(u))return;u=u[B]??void 0}else{if(typeof u!=="object"||Array.isArray(u))return;u=u[B]}}return u}import{existsSync as W9,readFileSync as V9}from"node:fs";import{homedir as H9}from"node:os";import{join as q9}from"node:path";import{existsSync as C9,mkdirSync as $9,readFileSync as z9,writeFileSync as Z9}from"node:fs";import{homedir as J9}from"node:os";import{dirname as G9,join as Q9}from"node:path";var X9=3600000,i0={now:()=>Date.now(),path:()=>Q9(process.env.HOME||J9(),".config","slack-cli","cache.json")},l0=!0,BF;function M3(){return{channels:{},users:{}}}function J2(){if(BF)return BF;if(BF=M3(),!l0)return BF;try{let D=i0.path();if(!C9(D))return BF;let F=JSON.parse(z9(D,"utf8"));for(let u of["channels","users"]){let B=F?.[u];if(!B||typeof B!=="object"||Array.isArray(B))continue;for(let[E,C]of Object.entries(B))if(C&&typeof C==="object"&&typeof C.value==="string"&&typeof C.expires==="number")BF[u][E]={value:C.value,expires:C.expires}}}catch{BF=M3()}return BF}function Y9(D){if(!l0)return;try{let F=i0.path();$9(G9(F),{recursive:!0}),Z9(F,JSON.stringify(D,null,2)+`
142
- `)}catch{}}function _3(D,F){return D?`${D} ${F}`:void 0}function G2(D,F,u){if(!l0)return;let B=_3(F,u);if(!B)return;let E=J2()[D][B];if(!E)return;if(E.expires<=i0.now()){delete J2()[D][B];return}return E.value}function Q2(D,F,u,B,E=X9){if(!l0)return;let C=_3(F,u);if(!C)return;let $=J2();$[D][C]={value:B,expires:i0.now()+E},Y9($)}var X2={marker:"pushpin",progress:{done:"white_check_mark",dropped:"no_entry_sign",doing:"eyes",pending:"hourglass_flowing_sand"},flags:{alert:"exclamation","needs-discussion":"question",waiting:"speech_balloon",blocked:"lock"}},mF=["done","dropped","doing","pending"],A3=["alert","needs-discussion","waiting","blocked"];function j9(){return q9(process.env.HOME||H9(),".config","slack-cli","todo.json")}function n0(D){return D.replace(/^:+|:+$/g,"")}function B0(D=j9()){let F={marker:X2.marker,progress:{...X2.progress},flags:{...X2.flags}};try{if(!W9(D))return F;let u=JSON.parse(V9(D,"utf8"));if(typeof u.marker==="string"&&u.marker.trim())F.marker=n0(u.marker.trim());for(let B of mF){let E=u.progress?.[B];if(typeof E==="string"&&E.trim())F.progress[B]=n0(E.trim())}for(let B of A3){let E=u.flags?.[B];if(typeof E==="string"&&E.trim())F.flags[B]=n0(E.trim())}}catch{}return F}function N3(D,F,u=!1){return`${u?"-":""}${F?"has":"hasmy"}::${n0(D)}:`}function P3(D,F,u={}){let B=u.shared===!0,E=(z)=>N3(z,B),C=(z)=>N3(z,B,!0),$=[];if(D==="untriaged")$.push(E(F.marker),...mF.map((z)=>C(F.progress[z])));else if(D==="stuck")$.push(E(F.marker),C(F.progress.done),C(F.progress.dropped),`(${A3.map((z)=>E(F.flags[z])).join(" OR ")})`);else if(D==="open")$.push(E(F.marker),C(F.progress.done),C(F.progress.dropped));else{let z=mF.indexOf(D);$.push(E(F.progress[D]));for(let Z of mF.slice(0,z))$.push(C(F.progress[Z]))}if(u.in){let z=u.in.startsWith("#")||u.in.startsWith("@")?u.in:`#${u.in}`;$.push(`in:${z}`)}if(u.from){let z=u.from==="me"||u.from.startsWith("@")?u.from:`@${u.from}`;$.push(`from:${z}`)}return $.join(" ")}var U9=3,K9={sleep:(D)=>new Promise((F)=>setTimeout(F,D))};async function PD(D,F,u=U9){for(let B=0;;B++)try{return await F()}catch(E){if(!(E instanceof dD))throw E;if(B>=u)throw Error(`Slack rate limit hit on ${D} — gave up after ${u} retries. Try again in a minute.`);console.error(`Warning: Slack rate limit hit on ${D} — backing off for ${E.retryAfter}s`),await K9.sleep(E.retryAfter*1000)}}var L3=new Map;async function T3(D,F){let u=L3.get(D);if(u)return u;let B=await PD("auth.test",()=>hF(D,F)),E={userId:B.userId,teamId:B.teamId};return L3.set(D,E),E}async function R3(D,F){return(await T3(D,F)).userId}async function S3(D,F){try{return(await T3(D,F)).teamId}catch{return""}}async function Y2(D,F,u,B){if(!F.startsWith("#"))return u(D,F,B);let E=await S3(D,B),C=G2("channels",E,F);if(C)return C;let $=await PD("resolveChannel",()=>u(D,F,B));return Q2("channels",E,F,$),$}async function w3(D,F,u,B){let E=await S3(D,B),C=G2("users",E,F);if(C)return C;let $=await PD("users.info",()=>u(D,F,B));if($&&$!==F)Q2("users",E,F,$);return $}async function x3(D,F,u,B,E,C){let $=E.progress[B],z=await R3(D,C),Z=await PD("reactions.get",()=>U1(D,F,u,C)),J=new Set(Z.filter((V)=>V.users.includes(z)).map((V)=>V.name)),Q=mF.map((V)=>E.progress[V]).filter((V)=>J.has(V));if(Q.length===1&&Q[0]===$)return{noop:!0,removed:[],leftover:[]};if(!J.has($))await PD("reactions.add",()=>P0(D,F,u,$,C));let G=[],X=[];for(let V of Q){if(V===$)continue;try{await PD("reactions.remove",()=>T0(D,F,u,V,C)),G.push(V)}catch{X.push(V)}}return{noop:!1,added:B,removed:G,leftover:X}}async function I3(D,F,u,B,E,C,$){let z=E.flags[B];if(C)await PD("reactions.remove",()=>T0(D,F,u,z,$));else await PD("reactions.add",()=>P0(D,F,u,z,$));return z}var W2=1000;async function b3(D,F,u,B={}){let E=B.limit??W2,C=B.cookie,$=await R3(D,C),z=mF.map((X)=>u.progress[X]),Z=[],J=0,Q,G=!1;while(J<E){let X=Math.min(200,E-J),V=await PD("conversations.history",()=>aF(D,F,X,void 0,Q,C)),H=V.messages??[];J+=H.length;for(let W of H){let j=String(W.ts??"");if(!j)continue;let N=new Set((W.reactions??[]).filter((T)=>(T.users??[]).map(String).includes($)).map((T)=>String(T.name??""))),O=z.filter((T)=>N.has(T));if(O.length<2)continue;Z.push({ts:j,text:String(W.text??"").split(`
143
- `)[0]??"",emoji:O,keep:O[0]})}if(Q=V.response_metadata?.next_cursor||void 0,!Q||H.length===0)break;if(J>=E){G=!0;break}}if(B.fix)for(let X of Z)try{try{await PD("reactions.add",()=>P0(D,F,X.ts,X.keep,C))}catch(V){if(!(V instanceof Error)||!/already_reacted/.test(V.message))throw V}for(let V of X.emoji){if(V===X.keep)continue;await PD("reactions.remove",()=>T0(D,F,X.ts,V,C))}X.fixed=!0}catch(V){X.fixed=!1,X.error=V instanceof Error?V.message:String(V)}return{scanned:J,findings:Z,truncated:G}}var O9=!0,M9;function V2(D){if(O9=D,!D)M9=void 0}function TF(D){return D.toLowerCase().replace(/[-_\s]/g,"")}function CF(D){return D&&typeof D==="object"&&!Array.isArray(D)?D:{}}function _9(D,F){let u=TF(F),B=CF(D.profile);for(let C of[D.name,D.real_name,B.display_name,B.real_name])if(typeof C==="string"&&C&&TF(C)===u)return!0;let E=typeof B.email==="string"?B.email.toLowerCase():"";return E!==""&&E===F.toLowerCase()}function N9(D){let F=CF(D.profile),u=new Set;for(let B of[F.display_name,D.real_name,D.name,F.real_name])if(typeof B==="string"&&B){let E=TF(B);if(E.length>=2)u.add(E)}return[...u]}function L9(D,F){let u=TF(D),B,E=!1;for(let C of F){let $=typeof C.id==="string"?C.id:"";if(!$)continue;for(let z of N9(C)){let Z=-1;if(u===z)Z=D.length;else for(let J of h3)if(D.length>J.length&&D.endsWith(J)&&TF(D.slice(0,D.length-J.length))===z){Z=D.length-J.length;break}if(Z<0)continue;if(!B||z.length>B.formLen)B={userId:$,matchLen:Z,formLen:z.length,display:j2(C)},E=!1;else if(z.length===B.formLen&&B.userId!==$)E=!0}}if(!B)return;return E?"ambiguous":{userId:B.userId,matchLen:B.matchLen,display:B.display}}async function C0(D,F,u,B){let E=`[${v3}ー]+`,C=`${E}(?:[._-]+${E})*`,$=new RegExp(`(?<![A-Za-z0-9._@<-])@(${C})`,"gu"),z=new Set;for(let O of F.matchAll($))z.add(O[1]);if(z.size===0)return{text:F,resolved:[],unresolved:[]};let Z=new Map;for(let O of z)Z.set(O,{status:"pending"});let J=(O)=>{for(let T of z){if(Z.get(T).status!=="pending")continue;if(q2(T)){let M=L9(T,O);if(M==="ambiguous")Z.set(T,{status:"ambiguous"});else if(M)Z.set(T,{status:"resolved",userId:M.userId,matchLen:M.matchLen,display:M.display})}else{let M=O.filter((I)=>_9(I,T)),R=new Set(M.map((I)=>typeof I.id==="string"?I.id:"").filter(Boolean));if(R.size===1){let I=M.find((y)=>typeof y.id==="string");Z.set(T,{status:"resolved",userId:I.id,matchLen:T.length,display:j2(I)})}else if(R.size>1)Z.set(T,{status:"ambiguous"})}}},Q=!1;try{let O=await w0(D,B);J((O.members??[]).map(CF)),Q=!0}catch{Q=!1}let G=[...z].some((O)=>Z.get(O).status==="pending"),X=!1,V=!0;if(G&&u){X=!0;try{let O=await cu(D,u,B),T=[];for(let M of O){let R=CF(await ku(D,M,B)),I=CF(R.user);if(typeof I.id!=="string")I.id=M;T.push(I)}J(T)}catch{V=!1}}let H=Q&&(u?X&&V:!0),W=[],j=[];for(let O of z){let T=Z.get(O);if(T.status==="resolved")W.push({surface:`@${O.slice(0,T.matchLen)}`,display:T.display,userId:T.userId});else if(T.status==="ambiguous")j.push({surface:`@${O}`,reason:"ambiguous"});else j.push({surface:`@${O}`,reason:H?"no-match":"unavailable"})}return{text:F.replace($,(O,T)=>{let M=Z.get(T);if(M&&M.status==="resolved")return`<@${M.userId}>${T.slice(M.matchLen)}`;return O}),resolved:W,unresolved:j}}function t0(D){let F=[],u=!1;for(let B of D)if(B.reason==="ambiguous")F.push(`${B.surface} matches multiple people — not tagged, sent as plain text (use <@USERID> to tag)`);else if(B.reason==="unavailable"){if(u)continue;F.push("could not fetch the user list (users:read missing or an API/connection error) — @mentions not tagged, sent as plain text"),u=!0}else F.push(`${B.surface} matched no one — not tagged, sent as plain text`);return F}async function f3(D,F,u,B={}){let E=B.warn??(($)=>process.stderr.write(`${$}
144
- `)),C=await C0(D,F,u,B.cookie);for(let $ of t0(C.unresolved))E(`warn: ${$}`);return C.text}var h3=["さん","さま","様","君","くん","ちゃん","氏","先生","先輩","殿","老师","老師","兄","姐","哥","姐妹"],v3="\\p{Script=Han}\\p{Script=Hiragana}\\p{Script=Katakana}A-Za-z0-9";function q2(D){return/[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}]/u.test(D)}function A9(D){let F=[],u=new RegExp(`([${v3}]{1,12})(${h3.join("|")})`,"gu");for(let B of D.matchAll(u))F.push({ref:B[1],honorific:B[2]});for(let B of D.matchAll(/\b(?:dear|hi|hello|hey)\b[ \t]+([A-Z][A-Za-z'’-]{1,20})/gi))F.push({ref:B[1],honorific:""});for(let B of D.matchAll(/(?:^|\n)[ \t]*([A-Z][A-Za-z'’-]{1,20}),/g))F.push({ref:B[1],honorific:""});return F}function P9(D){let F=CF(D.profile),u=new Set;for(let B of[D.name,D.real_name,F.display_name,F.real_name]){if(typeof B!=="string"||!B)continue;for(let E of[B,...B.split(/\s+/)]){let C=TF(E);if(C.length>=2)u.add(C)}}return[...u]}function T9(D,F){let u=TF(D);if(u.length<2)return;for(let B of F)if(u===B)return B;if(q2(D)){for(let B of F)if(u.includes(B)||B.includes(u))return B}return}function j2(D){return[CF(D.profile).display_name,D.real_name,D.name].filter((B)=>typeof B==="string"&&B!=="")[0]??String(D.id??"?")}async function y3(D,F,u){let B=A9(F);if(B.length===0)return[];let E=new Set;for(let J of F.matchAll(/<@([A-Z0-9]+)(?:\|[^>]*)?>/g))E.add(J[1]);let $=((await w0(D,u)).members??[]).map(CF).filter((J)=>J.deleted!==!0&&J.is_bot!==!0&&J.id!=="USLACKBOT").map((J)=>({id:typeof J.id==="string"?J.id:"",forms:P9(J),display:j2(J)})).filter((J)=>J.id!==""),z=[],Z=new Set;for(let{ref:J,honorific:Q}of B)for(let G of $){let X=T9(J,G.forms);if(!X)continue;if(E.has(G.id)||Z.has(G.id))break;Z.add(G.id),z.push({surface:q2(J)?`${X}${Q}`:J,display:G.display,userId:G.id});break}return z}async function gF(D,F,u,B){let E=F,C=[],$=E,z=0;while(!0){let Z=$.indexOf("<@U",z);if(Z===-1)break;let J=$.slice(Z+2),Q=J.search(/[>|]/),G=Q===-1?J:J.slice(0,Q);if(G.length>=9)C.push(G);z=Z+1}for(let Z of C){if(!u.has(Z))u.set(Z,await S0(D,Z,B));let J=u.get(Z)??Z;E=E.replaceAll(`<@${Z}>`,`@${J}`),E=E.replace(new RegExp(`<@${Z}\\|[^>]*>`,"g"),`@${J}`)}return E}function $0(D){return D.replace(/<!date\^(\d+)\^[^|>]*(?:\|([^>]*))?>/g,(F,u,B)=>{let E=Number(u);if(!Number.isFinite(E))return B??"date";let C=new Date(E*1000);if(Number.isNaN(C.getTime()))return B??"date";let $=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],z=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],Z=$[C.getUTCDay()]??"",J=z[C.getUTCMonth()]??"";return`${Z}, ${J} ${String(C.getUTCDate()).padStart(2,"0")}, ${C.getUTCFullYear()}`})}function p3(D,F=new Date){let u=new Date(D*1000),B=H2(F),E=H2(new Date(F.getTime()-86400000)),C=H2(u);if(C===B)return"Today";if(C===E)return"Yesterday";let $=u.toLocaleDateString("en-US",{weekday:"long"}),z=u.toLocaleDateString("en-US",{month:"short"});return`${$}, ${z} ${String(u.getDate()).padStart(2,"0")}`}function H2(D){return`${D.getFullYear()}-${D.getMonth()}-${D.getDate()}`}function m3(D){let F=new Date(D*1000),u=F.getFullYear(),B=String(F.getMonth()+1).padStart(2,"0"),E=String(F.getDate()).padStart(2,"0"),C=String(F.getHours()).padStart(2,"0"),$=String(F.getMinutes()).padStart(2,"0");return`${u}-${B}-${E} ${C}:${$}`}function z0(D){if(!l3(D))return;let F=S9(D,"utf8");for(let u of F.split(`
145
- `)){let B=u.trim();if(!B||B.startsWith("#"))continue;let E=B.indexOf("=");if(E===-1)continue;let C=B.slice(0,E).trim(),$=B.slice(E+1).trim();if($.startsWith('"')&&$.endsWith('"')||$.startsWith("'")&&$.endsWith("'"))$=$.slice(1,-1);if(!(C in process.env))process.env[C]=$}}function x9(D){w9(D,{recursive:!0});let F=$F(D,".gitignore");if(!l3(F))n3(F,`*
146
- `)}function I9(){z0($F(g3(),".slack-cli",".env.local")),z0($F(g3(),".config/slack-cli",".env")),z0($F(process.cwd(),".slack-cli",".env.local")),z0($F(process.cwd(),".env.local")),z0($F(process.cwd(),".env"))}function b9(D){return R9("sha256").update(D).digest("hex")}function w(D){return D&&typeof D==="object"&&!Array.isArray(D)?D:{}}function o(D){return Array.isArray(D)?D:[]}function o0(D){return Number(D.ts??0)}async function t3(D,F,u){let B=F.user;if(typeof B==="string"){if(!u.has(B))u.set(B,await EF(D,B));return u.get(B)??B}return typeof F.username==="string"?F.username:"bot"}function U2(D){let F=new Date(D*1000),u=F.getUTCFullYear(),B=String(F.getUTCMonth()+1).padStart(2,"0"),E=String(F.getUTCDate()).padStart(2,"0"),C=String(F.getUTCHours()).padStart(2,"0"),$=String(F.getUTCMinutes()).padStart(2,"0"),z=String(F.getUTCSeconds()).padStart(2,"0");return`${u}-${B}-${E} ${C}:${$}:${z}`}function O2(D){let[F,u="000000"]=D.split("."),B=Number(F),E=new Date(B*1000),C=E.getUTCFullYear(),$=String(E.getUTCMonth()+1).padStart(2,"0"),z=String(E.getUTCDate()).padStart(2,"0"),Z=String(E.getUTCHours()).padStart(2,"0"),J=String(E.getUTCMinutes()).padStart(2,"0"),Q=String(E.getUTCSeconds()).padStart(2,"0"),G=u.padEnd(6,"0").slice(0,6);return`${C}-${$}-${z}T${Z}:${J}:${Q}.${G}`}function M2(D){let F=D.match(/^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2})\.(\d{6})$/);if(!F)throw Error(`Invalid message timestamp "${D}" \u2014 expected 2026-05-11T06:01:04.000100`);let u=Date.parse(F[1]+"Z");if(isNaN(u))throw Error(`Cannot parse date in "${D}"`);return`${Math.floor(u/1000)}.${F[2]}`}function f9(D){return/^\d{4}-\d{2}-\d{2}T/.test(D)?M2(D):D}async function r0(D,F,u,B,E){let C=typeof F.ts==="string"?F.ts:`${o0(F)}.000000`,$=O2(C),z="?";if(typeof F.user==="string"){let O=F.user,T="@"+O;if(!u.has(T)){let M=await w3(D,O,async(R,I,y)=>(await F0(R,I,y))[1],E);u.set(T,M)}z=u.get(T)??O}else if(typeof F.username==="string")z=F.username;let Z=typeof F.text==="string"?F.text:"",Q=$0(await gF(D,Z,u,E)).split(`
147
- `),G=Q[0]+(Q.length>1?`
148
- `+Q.slice(1).map((O)=>` ${O}`).join(`
149
- `):""),X=B?`${B} @${z}`:`@${z}`,V=o(F.reactions).map(w).map((O)=>{let T=typeof O.name==="string"?O.name:"",M=Number(O.count??o(O.users).length??0);return T?`:${T}:\xD7${M}`:""}).filter(Boolean).join(" "),H=o(F.files).map(w).map((O)=>{let T=typeof O.name==="string"?O.name:typeof O.title==="string"?O.title:"(file)",M=typeof O.size==="number"?` (${a0(O.size)})`:"",R=typeof O.id==="string"?` [${O.id}]`:"";return`
150
- \uD83D\uDCCE ${T}${M}${R}`}).join(""),W=Number(F.reply_count??0),j=W>0?` [+${W} ${W===1?"reply":"replies"}]`:"",N=(V?`
151
- ${V}`:"")+H;return`${$} ${X}: ${G}${j}${N}`}function a0(D){return D<1024?`${D} B`:D<1048576?`${(D/1024).toFixed(1)} KB`:`${(D/1048576).toFixed(1)} MB`}function h9(D){return o(D.files).map(w).map((F)=>({id:F.id??null,name:F.name??F.title??null,mimetype:F.mimetype??null,size:F.size??null,url_private_download:F.url_private_download??F.url_private??null,permalink:F.permalink??null}))}function o3(D){let F=h9(D);return{ts:D.ts??null,user:D.user??null,username:D.username??null,bot_id:D.bot_id??null,thread_ts:D.thread_ts??null,text:typeof D.text==="string"?D.text:"",...D.reply_count!==void 0?{reply_count:D.reply_count}:{},...D.reply_users_count!==void 0?{reply_users_count:D.reply_users_count}:{},...D.latest_reply!==void 0?{latest_reply:D.latest_reply}:{},...F.length>0?{files:F}:{}}}async function v9(D,F,u,B,E){let C=[];for(let $ of u){let z=$;if(Number($.reply_count??0)>0&&typeof $.ts==="string"){let Z=await lD(D,F,$.ts,200,E),J=o(Z.messages).map(w);z=J[J.length-1]??$}if(z.user!==B)C.push($)}return C}async function y9(D,F,u,B="text",E=!1,C){let $=pF(F),z=await qD(D,F,C),Z=new Map,Q=await(async()=>{if($?.threadTs){let X=await lD(D,z,$.threadTs,u,C);return o(X.messages).map(w)}let G=await uF(D,z,u,void 0,void 0,C);return o(G.messages).map(w).reverse()})();if(E){let{userId:G}=await B3(D,C);Q=await v9(D,z,Q,G,C)}if(B==="jsonl"){for(let G of Q)console.log(JSON.stringify(o3(G)));return}for(let G of Q)console.log(await r0(D,G,Z,void 0,C))}async function p9(D,F,u,B,E="text",C){let $=await qD(D,F,C),z=await lD(D,$,f9(u),B,C),Z=o(z.messages).map(w);if(E==="jsonl"){for(let Q of Z)console.log(JSON.stringify(o3(Q)));return}let J=new Map;for(let Q of Z)console.log(await r0(D,Q,J,void 0,C))}async function m9(D){let F=await k0(D),u=o(F.channels).map(w).filter((E)=>E.is_member===!0).sort((E,C)=>Number(C.updated??0)-Number(E.updated??0)).slice(0,10),B=new Map;for(let E of u){let C=String(E.id??""),$=typeof E.name==="string"?E.name:typeof E.user==="string"?E.user:C,z=await uF(D,C,5),Z=o(z.messages).map(w).filter((J)=>J.subtype===void 0||J.subtype===null).filter((J)=>{let Q=typeof J.text==="string"?J.text:"";return Q.length>0&&!Q.startsWith("<@")}).slice(0,3).reverse();if(Z.length===0)continue;console.log(`-- #${$} --------------------------------`);for(let J of Z){let Q=await t3(D,J,B),G=(typeof J.text==="string"?J.text:"").split(`
152
- `)[0]??"",X=await gF(D,G,B);console.log(` ${Q}: ${X}`)}}}async function g9(D,F){let u=await G3(D,"to:me"),B=o(D0(u,["messages","matches"])).map(w).slice(0,F),E=new Map,C=[];for(let $ of B){let z=p3(o0($)),Z=C[C.length-1];if(Z?.label===z)Z.msgs.push($);else C.push({label:z,msgs:[$]})}for(let $=0;$<C.length;$++){let{label:z,msgs:Z}=C[$];if($>0)console.log("");console.log(` ${z}`),console.log(" ----------------------------");for(let J of[...Z].reverse()){let Q=w(J.channel),G=Q.is_im===!0,X=typeof Q.name==="string"?Q.name:"dm",V;if(G&&X.startsWith("U")){let H="@"+X;if(!E.has(H)){let[,W]=await F0(D,X);E.set(H,W)}V=`@${E.get(H)??X}`}else if(G)V=`@${X}`;else V=`#${X}`;console.log(await r0(D,J,E,V))}}}async function c9(D,F,u,B,E="text"){let C=await k0(D),$=o(C.channels).map(w).filter((z)=>B||z.is_member===!0).filter((z)=>{if(!u)return!0;return(typeof z.name==="string"?z.name:"").toLowerCase().includes(u.toLowerCase())}).sort((z,Z)=>Number(Z.updated??0)-Number(z.updated??0)).slice(0,F);if(E==="jsonl"){for(let z of $)console.log(JSON.stringify(z));return}for(let z of $){let Z=String(z.id??""),J=typeof z.name==="string"?z.name:typeof z.user==="string"?z.user:Z,Q=z.is_im===!0,G=z.is_mpim===!0,X=Q||G?"@":"#",V=z.is_member===!0?"":" (not joined)",H=typeof w(z.purpose).value==="string"?String(w(z.purpose).value):"",W=H?` ${H.split(`
153
- `)[0]?.slice(0,60)}`:"";console.log(`${X}${J} ${Z}${V}${W}`)}}function k9(D){let F=(E)=>E.startsWith("xoxp-")||E.startsWith("xoxc-"),u=vu(),B=u.find((E)=>E.profile.token===D);if(!B)return;return u.find((E)=>F(E.profile.token)&&E.profile.teamId===B.profile.teamId)}async function s3(D,F,u,B,E){let C=D,$=E,z;try{z=await u2(C,F,u,$)}catch(Q){let G=Q instanceof Error?Q.message:String(Q);if(D.startsWith("xoxb-")&&G.includes("not_allowed_token_type")){let X=k9(D);if(X)console.error(`Note: search.messages needs a user token \u2014 the active profile is a bot token (xoxb-); falling back to profile "${X.name}".`),C=X.profile.token,$=X.profile.cookie,z=await u2(C,F,u,$);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.
149
+ Or import your Slack desktop session: slack auth login`);throw Error(`Slack error on ${t}: ${a}`)}return o}async function Wl(e,t,n,i){let s={};if(i)s.Cookie=`d=${i}`;let r=await fetch(`${ki()}/${t}`,{...n,headers:{...n.headers??{},Authorization:`Bearer ${e}`,...s}});if(r.status===429){let a=parseInt(r.headers.get("retry-after")??"60",10);throw new qt(isNaN(a)?60:a)}let o=await r.json();if(o.ok!==!0){let a=o.error??"unknown";if(a==="ratelimited")throw new qt(60);if((a==="invalid_auth"||a==="not_authed")&&!e.startsWith("xoxc-"))throw Error(`The draft API requires a desktop app session token (xoxc-).
150
+ Import from Slack desktop: slack auth login`);if((a==="invalid_auth"||a==="not_authed")&&!i)throw Error(`drafts.list also requires the xoxd session cookie.
151
+ Attach it with: slack auth chrome (macOS) or slack auth firefox`);throw Error(`Slack error on ${t}: ${a}`)}return o}function Pt(e,t,n={},i){let s=new URLSearchParams({token:e,...n});return Wl(e,t,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:s.toString()},i)}function ie(e,t,n,i){let s=new URLSearchParams(n).toString();return Na(e,`${t}?${s}`,{method:"GET"},i)}function Je(e,t,n,i){return Na(e,t,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n)},i)}async function va(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 ja(e,t){let n={Authorization:`Bearer ${e}`};if(t)n.Cookie=`d=${t}`;let i=await fetch(`${ki()}/auth.test`,{method:"GET",headers:n});if(i.status===429){let o=parseInt(i.headers.get("retry-after")??"60",10);throw new qt(isNaN(o)?60:o)}let s=i.headers.get("x-oauth-scopes")??"",r=await i.json();if(r.ok!==!0)throw Error(`Slack error on auth.test: ${r.error??"unknown"}`);return{userId:r.user_id??"",user:r.user??"",botId:r.bot_id??"",team:r.team??"",url:r.url??"",scopes:s.split(",").map((o)=>o.trim()).filter(Boolean)}}async function Ze(e,t,n=20,i,s,r,o){let a={channel:t,limit:String(n)};if(i!==void 0)a.oldest=i;if(s!==void 0)a.cursor=s;if(o)a.inclusive="true";return ie(e,"conversations.history",a,r)}async function Ke(e,t,n,i=50,s){return ie(e,"conversations.replies",{channel:t,ts:n,limit:String(i)},s)}async function La(e,t,n){return ie(e,"files.info",{file:t},n)}async function Wa(e,t={},n){let i={count:String(Math.min(Math.max(t.count??100,1),200)),page:String(Math.max(t.page??1,1))};if(t.types)i.types=t.types;if(t.channel)i.channel=t.channel;if(t.user)i.user=t.user;return ie(e,"files.list",i,n)}async function Ua(e,t,n={},i){let s={list_id:t};if(n.limit)s.limit=String(n.limit);if(n.cursor)s.cursor=n.cursor;return Pt(e,"lists.records.list",s,i)}async function Ja(e,t,n,i,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(i,1))},s)}async function Ka(e,t,n){return Ja(e,t,100,1,n)}async function Ai(e,t,n,i){let r=1,o=[],a={ok:!0,messages:{}};while(!0){let u=await Ja(e,t,100,r,i),f=un(u,["messages","matches"]),l=Array.isArray(f)?f:[];o.push(...l);let d=Number(un(u,["messages","paging","pages"])??1);if(a=u,l.length===0||r>=d||o.length>=n)break;r+=1}let c=a;if(!c.messages)c.messages={};return c.messages.matches=o.slice(0,n),c}async function rs(e,t,n,i,s,r,o){let a=o?{channel:t,text:n}:{channel:t,text:n,blocks:[{type:"markdown",text:n}]};if(i!==void 0)a.thread_ts=i;if(s&&i!==void 0)a.reply_broadcast=!0;return(await Je(e,"chat.postMessage",a,r)).ts??""}async function za(e,t,n,i,s,r){let o={channel:t,text:n,post_at:i,blocks:[{type:"markdown",text:n}]};if(s!==void 0)o.thread_ts=s;return(await Je(e,"chat.scheduleMessage",o,r)).scheduled_message_id??""}async function Ha(e,t,n){let i={};if(t)i.channel=t;return ie(e,"chat.scheduledMessages.list",i,n)}async function qa(e,t,n,i){await Je(e,"chat.deleteScheduledMessage",{channel:t,scheduled_message_id:n},i)}async function ln(e,t,n,i){return(await ie(e,"chat.getPermalink",{channel:t,message_ts:n},i)).permalink??""}async function Yt(e,t,n,i,s,r){return(await Je(e,"chat.update",r?{channel:t,ts:n,text:i}:{channel:t,ts:n,text:i,blocks:[{type:"markdown",text:i}]},s)).ts??n}async function Ya(e,t,n,i){await Je(e,"chat.delete",{channel:t,ts:n},i)}async function ct(e,t,n,i,s){await Je(e,"reactions.add",{channel:t,timestamp:n,name:i},s)}async function Xa(e,t,n,i){return((await ie(e,"reactions.get",{channel:t,timestamp:n,full:"true"},i)).message?.reactions??[]).map((r)=>({name:String(r.name??""),users:Array.isArray(r.users)?r.users.map(String):[]}))}async function fn(e,t,n,i,s){await Je(e,"reactions.remove",{channel:t,timestamp:n,name:i},s)}async function Ga(e,t,n=!1,i){let s=await Je(e,"conversations.create",{name:t,is_private:n},i);return{id:s.channel?.id??"",name:s.channel?.name??t}}async function Va(e,t,n,i){await Je(e,"conversations.invite",{channel:t,users:n.join(",")},i)}async function dn(e,t){let n=[],i="";while(!0){let s={limit:"200",types:"public_channel,private_channel,im,mpim"};if(i)s.cursor=i;let r=await ie(e,"conversations.list",s,t);if(n.push(...r.channels??[]),i=r.response_metadata?.next_cursor??"",!i)break}return{channels:n}}async function Tt(e,t,n){let s=(await Je(e,"conversations.open",{users:t},n)).channel?.id;if(!s)throw Error(`Failed to open DM with user ${t}`);return s}function Ve(e){return e.toLowerCase().replace(/[-_\s]/g,"")}async function pn(e,t,n){if(!t.startsWith("@")){if(/^[UW][A-Za-z0-9]{6,}$/.test(t))return t;throw Error(`Expected @user or a user ID, got: ${t}`)}let i=Ve(t.slice(1)),s=await ie(e,"auth.test",{},n);if(i==="you"||i==="me"||Ve(s.user??"")===i){if(!s.user_id)throw Error("auth.test did not return user_id");return s.user_id}let r="";while(!0){let o={limit:"200"};if(r)o.cursor=r;let a=await ie(e,"users.list",o,n);for(let c of a.members??[]){let u=Ve(c.name??""),f=Ve(c.real_name??""),l=Ve(c.profile?.display_name??"");if(u===i||f===i||l&&l===i)return c.id??""}if(r=a.response_metadata?.next_cursor??"",!r)break}throw Error(`User not found: ${t}`)}function Rt(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],i=t[2]&&t[3]?`${t[2]}.${t[3]}`:void 0,s=e.indexOf("?"),r=s>=0?new URLSearchParams(e.slice(s)):void 0,o=r?.get("thread_ts")??void 0,u={channel:r?.get("cid")??void 0??n};if(i)u.ts=i;if(o)u.threadTs=o;return u}function Ul(e){return Rt(e)?.channel}function Ba(e){return/^[CDG][A-Z0-9]{8,}$/.test(e)}async function De(e,t,n){let i=Ul(t);if(i)return i;if(!t.startsWith("@")&&!t.startsWith("#")){if(Ba(t))return t;throw Error(`Target must start with # or @ (or be a Slack URL/ID), got: ${t}`)}if(t.startsWith("#")&&Ba(t.slice(1)))return t.slice(1);let s=t.startsWith("@"),r=t.slice(1),o=Ve(r);if(s){let u=await ie(e,"auth.test",{},n);if(o==="you"||o==="me"||Ve(u.user??"")===o){let m=u.user_id;if(!m)throw Error("auth.test did not return user_id");let y=((await ie(e,"conversations.list",{types:"im",limit:"200"},n)).channels??[]).find((E)=>E.user===m);if(y?.id)return String(y.id);return Tt(e,m,n)}let l="",d="";while(!0){let m={limit:"200"};if(d)m.cursor=d;let p=await ie(e,"users.list",m,n);for(let y of p.members??[]){let E=Ve(y.name??""),F=Ve(y.real_name??""),k=Ve(y.profile?.display_name??"");if(E===o||F===o||k&&k===o){l=y.id??"";break}}if(l)break;if(d=p.response_metadata?.next_cursor??"",!d)break}if(!l)throw Error(`User not found: ${t}`);let h="";while(!0){let m={types:"im",limit:"200"};if(h)m.cursor=h;let p=await ie(e,"conversations.list",m,n);for(let y of p.channels??[])if(y.user===l)return String(y.id??"");if(h=p.response_metadata?.next_cursor??"",!h)break}throw Error(`No existing DM with ${t} (${l}). Open it once in Slack first.`)}let a=r.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 hn(e,t,n){try{let i=await ie(e,"users.info",{user:t},n),s=i.user?.profile?.display_name,r=s&&s.length>0?s:i.user?.real_name??i.user?.name??t,o=i.user?.name??t;return[r,o]}catch{return[t,t]}}async function ze(e,t,n){try{let i=await ie(e,"users.info",{user:t},n),s=i.user?.profile?.display_name;if(s&&s.length>0)return s;return i.user?.real_name??i.user?.name??t}catch{return t}}async function $i(e,t){let n=[],i="";while(!0){let s={limit:"200"};if(i)s.cursor=i;let r=await ie(e,"users.list",s,t);if(n.push(...r.members??[]),i=r.response_metadata?.next_cursor??"",!i)break}return{members:n}}async function Za(e,t,n){let i=[],s="";while(!0){let r={channel:t,limit:"200"};if(s)r.cursor=s;let o=await ie(e,"conversations.members",r,n);if(i.push(...o.members??[]),s=o.response_metadata?.next_cursor??"",!s)break}return i}async function gn(e,t){return Pt(e,"drafts.list",{},t)}async function Qa(e,t,n,i){let{randomUUID:s}=await import("node:crypto"),r=JSON.stringify([{type:"rich_text",elements:[{type:"rich_text_section",elements:[{type:"text",text:n}]}]}]);return Pt(e,"drafts.create",{client_msg_id:s(),destinations:JSON.stringify([{channel_id:t}]),blocks:r,file_ids:JSON.stringify([]),is_from_composer:"true"},i)}async function ec(e,t,n,i,s){let r=JSON.stringify([{type:"rich_text",elements:[{type:"rich_text_section",elements:[{type:"text",text:i}]}]}]),o=(Date.now()/1000).toFixed(6);return Pt(e,"drafts.update",{draft_id:t,client_last_updated_ts:o,destinations:JSON.stringify([{channel_id:n}]),blocks:r,file_ids:JSON.stringify([])},s)}async function tc(e,t,n){return Pt(e,"conversations.info",{channel:t},n)}async function os(e,t,n){return ie(e,"users.info",{user:t},n)}async function mn(e,t,n){return ie(e,"conversations.info",{channel:t},n)}async function nc(e,t,n){let i=(Date.now()/1000).toFixed(6);return Pt(e,"drafts.delete",{draft_id:t,client_last_updated_ts:i},n)}async function Oi(e,t){let n=await Pt(e,"auth.test",{},t);return{userId:String(n.user_id??""),teamId:String(n.team_id??"")}}async function sc(e,t,n,i={},s){let{statSync:r,readFileSync:o}=await import("node:fs"),{basename:a}=await import("node:path"),c=r(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 h=o(n),m=await fetch(l,{method:"POST",headers:{"Content-Type":"application/octet-stream"},body:h});if(!m.ok)throw Error(`Upload PUT failed: ${m.status} ${m.statusText}`);let p={files:[{id:d,title:i.title??u}],channel_id:t};if(i.threadTs)p.thread_ts=i.threadTs;if(i.initialComment)p.initial_comment=i.initialComment;let y=await Je(e,"files.completeUploadExternal",p,s),E={fileId:d},F=y.files?.[0]?.permalink;if(F)E.permalink=F;return E}function un(e,t){let n=e;for(let i of t){if(n===void 0||n===null)return;if(typeof i==="number"){if(!Array.isArray(n))return;n=n[i]??void 0}else{if(typeof n!=="object"||Array.isArray(n))return;n=n[i]}}return n}import{existsSync as Zl,readFileSync as Ql}from"node:fs";import{homedir as ef}from"node:os";import{join as tf}from"node:path";import{existsSync as Jl,mkdirSync as Kl,readFileSync as zl,writeFileSync as Hl}from"node:fs";import{homedir as ql}from"node:os";import{dirname as Yl,join as Xl}from"node:path";var Gl=3600000,as={now:()=>Date.now(),path:()=>Xl(process.env.HOME||ql(),".config","slack-cli","cache.json")},cs=!0,ut;function ic(){return{channels:{},users:{}}}function Ii(){if(ut)return ut;if(ut=ic(),!cs)return ut;try{let e=as.path();if(!Jl(e))return ut;let t=JSON.parse(zl(e,"utf8"));for(let n of["channels","users"]){let i=t?.[n];if(!i||typeof i!=="object"||Array.isArray(i))continue;for(let[s,r]of Object.entries(i))if(r&&typeof r==="object"&&typeof r.value==="string"&&typeof r.expires==="number")ut[n][s]={value:r.value,expires:r.expires}}}catch{ut=ic()}return ut}function Vl(e){if(!cs)return;try{let t=as.path();Kl(Yl(t),{recursive:!0}),Hl(t,JSON.stringify(e,null,2)+`
152
+ `)}catch{}}function rc(e,t){return e?`${e} ${t}`:void 0}function Pi(e,t,n){if(!cs)return;let i=rc(t,n);if(!i)return;let s=Ii()[e][i];if(!s)return;if(s.expires<=as.now()){delete Ii()[e][i];return}return s.value}function Ti(e,t,n,i,s=Gl){if(!cs)return;let r=rc(t,n);if(!r)return;let o=Ii();o[e][r]={value:i,expires:as.now()+s},Vl(o)}var Ri={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"}},Xt=["done","dropped","doing","pending"],cc=["alert","needs-discussion","waiting","blocked"];function nf(){return tf(process.env.HOME||ef(),".config","slack-cli","todo.json")}function us(e){return e.replace(/^:+|:+$/g,"")}function Dn(e=nf()){let t={marker:Ri.marker,progress:{...Ri.progress},flags:{...Ri.flags}};try{if(!Zl(e))return t;let n=JSON.parse(Ql(e,"utf8"));if(typeof n.marker==="string"&&n.marker.trim())t.marker=us(n.marker.trim());for(let i of Xt){let s=n.progress?.[i];if(typeof s==="string"&&s.trim())t.progress[i]=us(s.trim())}for(let i of cc){let s=n.flags?.[i];if(typeof s==="string"&&s.trim())t.flags[i]=us(s.trim())}}catch{}return t}function oc(e,t,n=!1){return`${n?"-":""}${t?"has":"hasmy"}::${us(e)}:`}function uc(e,t,n={}){let i=n.shared===!0,s=(a)=>oc(a,i),r=(a)=>oc(a,i,!0),o=[];if(e==="untriaged")o.push(s(t.marker),...Xt.map((a)=>r(t.progress[a])));else if(e==="stuck")o.push(s(t.marker),r(t.progress.done),r(t.progress.dropped),`(${cc.map((a)=>s(t.flags[a])).join(" OR ")})`);else if(e==="open")o.push(s(t.marker),r(t.progress.done),r(t.progress.dropped));else{let a=Xt.indexOf(e);o.push(s(t.progress[e]));for(let c of Xt.slice(0,a))o.push(r(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 sf=3,rf={sleep:(e)=>new Promise((t)=>setTimeout(t,e))};async function Ae(e,t,n=sf){for(let i=0;;i++)try{return await t()}catch(s){if(!(s instanceof Ge))throw s;if(i>=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 rf.sleep(s.retryAfter*1000)}}var ac=new Map;async function lc(e,t){let n=ac.get(e);if(n)return n;let i=await Ae("auth.test",()=>zt(e,t)),s={userId:i.userId,teamId:i.teamId};return ac.set(e,s),s}async function fc(e,t){return(await lc(e,t)).userId}async function dc(e,t){try{return(await lc(e,t)).teamId}catch{return""}}async function Mi(e,t,n,i){if(!t.startsWith("#"))return n(e,t,i);let s=await dc(e,i),r=Pi("channels",s,t);if(r)return r;let o=await Ae("resolveChannel",()=>n(e,t,i));return Ti("channels",s,t,o),o}async function pc(e,t,n,i){let s=await dc(e,i),r=Pi("users",s,t);if(r)return r;let o=await Ae("users.info",()=>n(e,t,i));if(o&&o!==t)Ti("users",s,t,o);return o}async function hc(e,t,n,i,s,r){let o=s.progress[i],a=await fc(e,r),c=await Ae("reactions.get",()=>Jo(e,t,n,r)),u=new Set(c.filter((h)=>h.users.includes(a)).map((h)=>h.name)),f=Xt.map((h)=>s.progress[h]).filter((h)=>u.has(h));if(f.length===1&&f[0]===o)return{noop:!0,removed:[],leftover:[]};if(!u.has(o))await Ae("reactions.add",()=>Wn(e,t,n,o,r));let l=[],d=[];for(let h of f){if(h===o)continue;try{await Ae("reactions.remove",()=>Un(e,t,n,h,r)),l.push(h)}catch{d.push(h)}}return{noop:!1,added:i,removed:l,leftover:d}}async function gc(e,t,n,i,s,r,o){let a=s.flags[i];if(r)await Ae("reactions.remove",()=>Un(e,t,n,a,o));else await Ae("reactions.add",()=>Wn(e,t,n,a,o));return a}var Bi=1000;async function mc(e,t,n,i={}){let s=i.limit??Bi,r=i.cookie,o=await fc(e,r),a=Xt.map((d)=>n.progress[d]),c=[],u=0,f,l=!1;while(u<s){let d=Math.min(200,s-u),h=await Ae("conversations.history",()=>on(e,t,d,void 0,f,r)),m=h.messages??[];u+=m.length;for(let p of m){let y=String(p.ts??"");if(!y)continue;let E=new Set((p.reactions??[]).filter((k)=>(k.users??[]).map(String).includes(o)).map((k)=>String(k.name??""))),F=a.filter((k)=>E.has(k));if(F.length<2)continue;c.push({ts:y,text:String(p.text??"").split(`
153
+ `)[0]??"",emoji:F,keep:F[0]})}if(f=h.response_metadata?.next_cursor||void 0,!f||m.length===0)break;if(u>=s){l=!0;break}}if(i.fix)for(let d of c)try{try{await Ae("reactions.add",()=>Wn(e,t,d.ts,d.keep,r))}catch(h){if(!(h instanceof Error)||!/already_reacted/.test(h.message))throw h}for(let h of d.emoji){if(h===d.keep)continue;await Ae("reactions.remove",()=>Un(e,t,d.ts,h,r))}d.fixed=!0}catch(h){d.fixed=!1,d.error=h instanceof Error?h.message:String(h)}return{scanned:u,findings:c,truncated:l}}var of=!0,af;function Ni(e){if(of=e,!e)af=void 0}function Mt(e){return e.toLowerCase().replace(/[-_\s]/g,"")}function lt(e){return e&&typeof e==="object"&&!Array.isArray(e)?e:{}}function cf(e,t){let n=Mt(t),i=lt(e.profile);for(let r of[e.name,e.real_name,i.display_name,i.real_name])if(typeof r==="string"&&r&&Mt(r)===n)return!0;let s=typeof i.email==="string"?i.email.toLowerCase():"";return s!==""&&s===t.toLowerCase()}function uf(e){let t=lt(e.profile),n=new Set;for(let i of[t.display_name,e.real_name,e.name,t.real_name])if(typeof i==="string"&&i){let s=Mt(i);if(s.length>=2)n.add(s)}return[...n]}function lf(e,t){let n=Mt(e),i,s=!1;for(let r of t){let o=typeof r.id==="string"?r.id:"";if(!o)continue;for(let a of uf(r)){let c=-1;if(n===a)c=e.length;else for(let u of yc)if(e.length>u.length&&e.endsWith(u)&&Mt(e.slice(0,e.length-u.length))===a){c=e.length-u.length;break}if(c<0)continue;if(!i||a.length>i.formLen)i={userId:o,matchLen:c,formLen:a.length,display:Li(r)},s=!1;else if(a.length===i.formLen&&i.userId!==o)s=!0}}if(!i)return;return s?"ambiguous":{userId:i.userId,matchLen:i.matchLen,display:i.display}}async function Bt(e,t,n,i){let s=`[${wc}ー]+`,r=`${s}(?:[._-]+${s})*`,o=new RegExp(`(?<![A-Za-z0-9._@<-])@(${r})`,"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(ji(k)){let C=lf(k,F);if(C==="ambiguous")c.set(k,{status:"ambiguous"});else if(C)c.set(k,{status:"resolved",userId:C.userId,matchLen:C.matchLen,display:C.display})}else{let C=F.filter((T)=>cf(T,k)),A=new Set(C.map((T)=>typeof T.id==="string"?T.id:"").filter(Boolean));if(A.size===1){let T=C.find((v)=>typeof v.id==="string");c.set(k,{status:"resolved",userId:T.id,matchLen:k.length,display:Li(T)})}else if(A.size>1)c.set(k,{status:"ambiguous"})}}},f=!1;try{let F=await zn(e,i);u((F.members??[]).map(lt)),f=!0}catch{f=!1}let l=[...a].some((F)=>c.get(F).status==="pending"),d=!1,h=!0;if(l&&n){d=!0;try{let F=await ii(e,n,i),k=[];for(let C of F){let A=lt(await ri(e,C,i)),T=lt(A.user);if(typeof T.id!=="string")T.id=C;k.push(T)}u(k)}catch{h=!1}}let m=f&&(n?d&&h:!0),p=[],y=[];for(let F of a){let k=c.get(F);if(k.status==="resolved")p.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 C=c.get(k);if(C&&C.status==="resolved")return`<@${C.userId}>${k.slice(C.matchLen)}`;return F}),resolved:p,unresolved:y}}function yn(e){let t=[],n=!1;for(let i of e)if(i.reason==="ambiguous")t.push(`${i.surface} matches multiple people — not tagged, sent as plain text (use <@USERID> to tag)`);else if(i.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(`${i.surface} matched no one — not tagged, sent as plain text`);return t}async function Dc(e,t,n,i={}){let s=i.warn??((o)=>process.stderr.write(`${o}
154
+ `)),r=await Bt(e,t,n,i.cookie);for(let o of yn(r.unresolved))s(`warn: ${o}`);return r.text}var yc=["さん","さま","様","君","くん","ちゃん","氏","先生","先輩","殿","老师","老師","兄","姐","哥","姐妹"],wc="\\p{Script=Han}\\p{Script=Hiragana}\\p{Script=Katakana}A-Za-z0-9";function ji(e){return/[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}]/u.test(e)}function ff(e){let t=[],n=new RegExp(`([${wc}]{1,12})(${yc.join("|")})`,"gu");for(let i of e.matchAll(n))t.push({ref:i[1],honorific:i[2]});for(let i of e.matchAll(/\b(?:dear|hi|hello|hey)\b[ \t]+([A-Z][A-Za-z'’-]{1,20})/gi))t.push({ref:i[1],honorific:""});for(let i of e.matchAll(/(?:^|\n)[ \t]*([A-Z][A-Za-z'’-]{1,20}),/g))t.push({ref:i[1],honorific:""});return t}function df(e){let t=lt(e.profile),n=new Set;for(let i of[e.name,e.real_name,t.display_name,t.real_name]){if(typeof i!=="string"||!i)continue;for(let s of[i,...i.split(/\s+/)]){let r=Mt(s);if(r.length>=2)n.add(r)}}return[...n]}function pf(e,t){let n=Mt(e);if(n.length<2)return;for(let i of t)if(n===i)return i;if(ji(e)){for(let i of t)if(n.includes(i)||i.includes(n))return i}return}function Li(e){return[lt(e.profile).display_name,e.real_name,e.name].filter((i)=>typeof i==="string"&&i!=="")[0]??String(e.id??"?")}async function bc(e,t,n){let i=ff(t);if(i.length===0)return[];let s=new Set;for(let u of t.matchAll(/<@([A-Z0-9]+)(?:\|[^>]*)?>/g))s.add(u[1]);let o=((await zn(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:df(u),display:Li(u)})).filter((u)=>u.id!==""),a=[],c=new Set;for(let{ref:u,honorific:f}of i)for(let l of o){let d=pf(u,l.forms);if(!d)continue;if(s.has(l.id)||c.has(l.id))break;c.add(l.id),a.push({surface:ji(u)?`${d}${f}`:u,display:l.display,userId:l.id});break}return a}async function Gt(e,t,n,i){let s=t,r=[],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)r.push(l);a=c+1}for(let c of r){if(!n.has(c))n.set(c,await Kn(e,c,i));let u=n.get(c)??c;s=s.replaceAll(`<@${c}>`,`@${u}`),s=s.replace(new RegExp(`<@${c}\\|[^>]*>`,"g"),`@${u}`)}return s}function wn(e){return e.replace(/<!date\^(\d+)\^[^|>]*(?:\|([^>]*))?>/g,(t,n,i)=>{let s=Number(n);if(!Number.isFinite(s))return i??"date";let r=new Date(s*1000);if(Number.isNaN(r.getTime()))return i??"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[r.getUTCDay()]??"",u=a[r.getUTCMonth()]??"";return`${c}, ${u} ${String(r.getUTCDate()).padStart(2,"0")}, ${r.getUTCFullYear()}`})}function Fc(e,t=new Date){let n=new Date(e*1000),i=vi(t),s=vi(new Date(t.getTime()-86400000)),r=vi(n);if(r===i)return"Today";if(r===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 vi(e){return`${e.getFullYear()}-${e.getMonth()}-${e.getDate()}`}function Cc(e){let t=new Date(e*1000),n=t.getFullYear(),i=String(t.getMonth()+1).padStart(2,"0"),s=String(t.getDate()).padStart(2,"0"),r=String(t.getHours()).padStart(2,"0"),o=String(t.getMinutes()).padStart(2,"0");return`${n}-${i}-${s} ${r}:${o}`}function bn(e){if(!Ac(e))return;let t=gf(e,"utf8");for(let n of t.split(`
155
+ `)){let i=n.trim();if(!i||i.startsWith("#"))continue;let s=i.indexOf("=");if(s===-1)continue;let r=i.slice(0,s).trim(),o=i.slice(s+1).trim();if(o.startsWith('"')&&o.endsWith('"')||o.startsWith("'")&&o.endsWith("'"))o=o.slice(1,-1);if(!(r in process.env))process.env[r]=o}}function Df(e){mf(e,{recursive:!0});let t=ft(e,".gitignore");if(!Ac(t))$c(t,`*
156
+ `)}function yf(){bn(ft(Ec(),".slack-cli",".env.local")),bn(ft(Ec(),".config/slack-cli",".env")),bn(ft(process.cwd(),".slack-cli",".env.local")),bn(ft(process.cwd(),".env.local")),bn(ft(process.cwd(),".env"))}function wf(e){return hf("sha256").update(e).digest("hex")}function P(e){return e&&typeof e==="object"&&!Array.isArray(e)?e:{}}function X(e){return Array.isArray(e)?e:[]}function ls(e){return Number(e.ts??0)}async function Oc(e,t,n){let i=t.user;if(typeof i==="string"){if(!n.has(i))n.set(i,await ze(e,i));return n.get(i)??i}return typeof t.username==="string"?t.username:"bot"}function Wi(e){let t=new Date(e*1000),n=t.getUTCFullYear(),i=String(t.getUTCMonth()+1).padStart(2,"0"),s=String(t.getUTCDate()).padStart(2,"0"),r=String(t.getUTCHours()).padStart(2,"0"),o=String(t.getUTCMinutes()).padStart(2,"0"),a=String(t.getUTCSeconds()).padStart(2,"0");return`${n}-${i}-${s} ${r}:${o}:${a}`}function Ji(e){let[t,n="000000"]=e.split("."),i=Number(t),s=new Date(i*1000),r=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`${r}-${o}-${a}T${c}:${u}:${f}.${l}`}function Ki(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 bf(e){return/^\d{4}-\d{2}-\d{2}T/.test(e)?Ki(e):e}async function ps(e,t,n,i,s){let r=typeof t.ts==="string"?t.ts:`${ls(t)}.000000`,o=Ji(r),a="?";if(typeof t.user==="string"){let F=t.user,k="@"+F;if(!n.has(k)){let C=await pc(e,F,async(A,T,v)=>(await hn(A,T,v))[1],s);n.set(k,C)}a=n.get(k)??F}else if(typeof t.username==="string")a=t.username;let c=typeof t.text==="string"?t.text:"",f=wn(await Gt(e,c,n,s)).split(`
157
+ `),l=f[0]+(f.length>1?`
158
+ `+f.slice(1).map((F)=>` ${F}`).join(`
159
+ `):""),d=i?`${i} @${a}`:`@${a}`,h=X(t.reactions).map(P).map((F)=>{let k=typeof F.name==="string"?F.name:"",C=Number(F.count??X(F.users).length??0);return k?`:${k}:\xD7${C}`:""}).filter(Boolean).join(" "),m=X(t.files).map(P).map((F)=>{let k=typeof F.name==="string"?F.name:typeof F.title==="string"?F.title:"(file)",C=typeof F.size==="number"?` (${hs(F.size)})`:"",A=typeof F.id==="string"?` [${F.id}]`:"";return`
160
+ \uD83D\uDCCE ${k}${C}${A}`}).join(""),p=Number(t.reply_count??0),y=p>0?` [+${p} ${p===1?"reply":"replies"}]`:"",E=(h?`
161
+ ${h}`:"")+m;return`${o} ${d}: ${l}${y}${E}`}function hs(e){return e<1024?`${e} B`:e<1048576?`${(e/1024).toFixed(1)} KB`:`${(e/1048576).toFixed(1)} MB`}function Ff(e){return X(e.files).map(P).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 Ic(e){let t=Ff(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:"",...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 Cf(e,t,n,i,s){let r=[];for(let o of n){let a=o;if(Number(o.reply_count??0)>0&&typeof o.ts==="string"){let c=await Ke(e,t,o.ts,200,s),u=X(c.messages).map(P);a=u[u.length-1]??o}if(a.user!==i)r.push(o)}return r}async function Ef(e,t,n,i="text",s=!1,r){let o=Rt(t),a=await De(e,t,r),c=new Map,f=await(async()=>{if(o?.threadTs){let d=await Ke(e,a,o.threadTs,n,r);return X(d.messages).map(P)}let l=await Ze(e,a,n,void 0,void 0,r);return X(l.messages).map(P).reverse()})();if(s){let{userId:l}=await va(e,r);f=await Cf(e,a,f,l,r)}if(i==="jsonl"){for(let l of f)console.log(JSON.stringify(Ic(l)));return}for(let l of f)console.log(await ps(e,l,c,void 0,r))}async function xf(e,t,n,i,s="text",r){let o=await De(e,t,r),a=await Ke(e,o,bf(n),i,r),c=X(a.messages).map(P);if(s==="jsonl"){for(let f of c)console.log(JSON.stringify(Ic(f)));return}let u=new Map;for(let f of c)console.log(await ps(e,f,u,void 0,r))}async function _f(e){let t=await dn(e),n=X(t.channels).map(P).filter((s)=>s.is_member===!0).sort((s,r)=>Number(r.updated??0)-Number(s.updated??0)).slice(0,10),i=new Map;for(let s of n){let r=String(s.id??""),o=typeof s.name==="string"?s.name:typeof s.user==="string"?s.user:r,a=await Ze(e,r,5),c=X(a.messages).map(P).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 Oc(e,u,i),l=(typeof u.text==="string"?u.text:"").split(`
162
+ `)[0]??"",d=await Gt(e,l,i);console.log(` ${f}: ${d}`)}}}async function Sf(e,t){let n=await Ka(e,"to:me"),i=X(un(n,["messages","matches"])).map(P).slice(0,t),s=new Map,r=[];for(let o of i){let a=Fc(ls(o)),c=r[r.length-1];if(c?.label===a)c.msgs.push(o);else r.push({label:a,msgs:[o]})}for(let o=0;o<r.length;o++){let{label:a,msgs:c}=r[o];if(o>0)console.log("");console.log(` ${a}`),console.log(" ----------------------------");for(let u of[...c].reverse()){let f=P(u.channel),l=f.is_im===!0,d=typeof f.name==="string"?f.name:"dm",h;if(l&&d.startsWith("U")){let m="@"+d;if(!s.has(m)){let[,p]=await hn(e,d);s.set(m,p)}h=`@${s.get(m)??d}`}else if(l)h=`@${d}`;else h=`#${d}`;console.log(await ps(e,u,s,h))}}}async function kf(e,t,n,i,s="text"){let r=await dn(e),o=X(r.channels).map(P).filter((a)=>i||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?"@":"#",h=a.is_member===!0?"":" (not joined)",m=typeof P(a.purpose).value==="string"?String(P(a.purpose).value):"",p=m?` ${m.split(`
163
+ `)[0]?.slice(0,60)}`:"";console.log(`${d}${u} ${c}${h}${p}`)}}function Af(e){let t=(s)=>s.startsWith("xoxp-")||s.startsWith("xoxc-"),n=Qs(),i=n.find((s)=>s.profile.token===e);if(!i)return;return n.find((s)=>t(s.profile.token)&&s.profile.teamId===i.profile.teamId)}async function Pc(e,t,n,i,s){let r=e,o=s,a;try{a=await Ai(r,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=Af(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}".`),r=d.profile.token,o=d.profile.cookie,a=await Ai(r,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.
154
164
  `+` Add a user-token profile: slack auth login (or slack auth token)
155
- Then select it: slack auth use <name> (or pass --workspace <name>)`),process.exit(1)}else throw Q}if(B){console.log(JSON.stringify(z,null,2));return}let Z=o(D0(z,["messages","matches"])).map(w),J=new Map;for(let Q of Z){let G=w(Q.channel),X=G.is_im===!0,V=typeof G.name==="string"?G.name:"dm",H;if(X&&V.startsWith("U")){let W="@"+V;if(!J.has(W)){let[,j]=await F0(C,V,$);J.set(W,j)}H=`@${J.get(W)??V}`}else if(X)H=`@${V}`;else H=`#${V}`;console.log(await r0(C,Q,J,H,$))}}async function r3(D,F,u,B){let{ref:E,ts:C}=e0(F);if(!C)console.error("Error: target must embed a message ts (e.g. #chan:1700000000.000100 or a Slack permalink URL)"),process.exit(2);return{channelId:u??await Y2(D,E,qD,B),ts:C}}async function d9(D,F){let u=B0(),B={};if(!F.mine)B.shared=!0;if(F.in)B.in=F.in;if(F.from)B.from=F.from;let E=P3(F.state,u,B);if(!F.json){let C=await cF(D,F.cookie),$=F.mine?"your reactions only [hasmy:]":"anyone's reactions [has:]";console.error(`(From: ${e3(C)} \xB7 matching ${$})`),console.error(`(query: ${E})`)}await PD("search.messages",()=>s3(D,E,F.count,F.json,F.cookie))}async function i9(D,F){let u=B0(),{channelId:B,ts:E}=await r3(D,F.target,F.channelId,F.cookie),C=await x3(D,B,E,F.state,u,F.cookie);if(C.noop){console.log(`= Already ${F.state} (ts: ${E})`);return}let $=C.removed.length?`, removed ${C.removed.map((z)=>`:${z}:`).join(" ")}`:"";if(console.log(`\u2713 ${F.state} :${u.progress[F.state]}: (ts: ${E})${$}`),C.leftover.length)console.error(`\u26A0 ${C.leftover.map((z)=>`:${z}:`).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 l9(D,F){let u=B0(),{channelId:B,ts:E}=await r3(D,F.target,F.channelId,F.cookie),C=await I3(D,B,E,F.flag,u,F.remove===!0,F.cookie);console.log(`\u2713 ${F.remove?"Cleared":"Flagged"} ${F.flag} :${C}: (ts: ${E})`)}async function n9(D,F){let u=B0(),B=F.channelId??await Y2(D,F.channel,qD,F.cookie),E={limit:F.limit};if(F.fix)E.fix=!0;if(F.cookie)E.cookie=F.cookie;let C=await b3(D,B,u,E);if(C.findings.length===0)console.log(`\u2713 No multi-state tasks in ${C.scanned} message(s).`);else{for(let $ of C.findings){let z=$.fixed===!0?"fixed":$.fixed===!1?`FAILED: ${$.error??"?"}`:"needs --fix";console.log(`${$.ts} ${$.emoji.map((Z)=>`:${Z}:`).join(" ")} \u2192 keep :${$.keep}: [${z}] ${VD($.text).slice(0,60)}`)}console.log(`${C.findings.length} multi-state task(s) in ${C.scanned} message(s).`)}if(C.truncated)console.error(`\u26A0 Scan limit reached (${F.limit} messages) \u2014 older history was NOT checked. Raise it with --limit N.`)}async function t9(D,F,u,B){let E=Math.floor(Date.now()/1000)-F*86400,C=await k0(D),$=o(C.channels).map(w).filter((Q)=>Q.is_member===!0&&Q.is_im!==!0&&Q.is_mpim!==!0).filter((Q)=>{if(!B)return!0;return(typeof Q.name==="string"?Q.name:"").toLowerCase().includes(B.toLowerCase())}).sort((Q,G)=>Number(G.updated??0)-Number(Q.updated??0)),z=new Map,Z=0,J=0;for(let Q of $){let G=String(Q.id??""),X=typeof Q.name==="string"?Q.name:G,V;try{V=await uF(D,G,u)}catch(W){console.error(` SKIP #${X}: ${W.message}`);continue}let H=o(V.messages).map(w).filter((W)=>(W.subtype===void 0||W.subtype===null)&&o0(W)>=E);if(H.length===0)continue;J+=1,Z+=H.length,console.log(`## #${X} (${H.length} msgs)
156
- `);for(let W of[...H].reverse()){let j=await t3(D,W,z),N=typeof W.text==="string"?W.text:"",T=$0(await gF(D,N,z)).split(`
157
- `).join(" \u21B5 ");console.log(`[${m3(o0(W))}] ${j}: ${T}`)}console.log("")}console.error(`Dumped ${Z} messages across ${J} channels (cutoff: ${F}d)`)}function o9(D){let F=[];function u(B){if(typeof B==="string"){F.push(B);return}if(Array.isArray(B)){for(let E of B)u(E);return}if(B&&typeof B==="object"){let E=B;if(typeof E.text==="string"){F.push(E.text);return}if(Array.isArray(E.elements))u(E.elements);else if(Array.isArray(E.content))u(E.content)}}for(let B of D)u(B);return F.join("").trim()}async function a3(D,F,u){let B=new Map;return async(E)=>{if(!E)return"(unknown)";if(B.has(E))return B.get(E);try{let C=await U3(D,E,F),$=w(C.channel),z;if($.is_im===!0){let Z=typeof $.user==="string"?$.user:"";if(!Z||Z===u)z="@self";else{let[J]=await F0(D,Z);z=`@${J}`}}else z=`#${typeof $.name==="string"?$.name:E}`;return B.set(E,z),z}catch{return E}}}function _2(D){let F=w(o(D.destinations)[0]);return String(F.channel_id??D.channel_id??D.channel??"")}function s0(D){return o9(o(D.blocks))||(typeof D.text==="string"?D.text:"(no text)")}async function s9(D,F,u=!1){let B=await u0(D,F),E=o(B.drafts??B.messages??[]).map(w).filter((J)=>J.is_deleted!==!0),C=u?E:E.filter((J)=>J.is_sent!==!0);if(C.length===0){console.log(u?"No drafts.":"No pending drafts. Run with --all to include sent.");return}let $="";try{({userId:$}=await Z2(D,F))}catch{}let z=await a3(D,F,$),Z=new Map;for(let J of C){let Q=_2(J),G=s0(J),X=Number(J.date_created??J.date_create??0),V=X?U2(X):"?",H=await z(Q),W=typeof J.id==="string"?J.id:"",j=J.is_sent===!0?" [SENT]":"",N=$0(await gF(D,G,Z));console.log(`-- ${W} ${H} [${V}]${j}`);for(let O of N.split(`
158
- `))console.log(` ${O}`)}}async function r9(D,F,u){let B=await u0(D,F),E=o(B.drafts).map(w).find((H)=>String(H.id)===u);if(!E)console.error(`Draft not found: ${u}`),process.exit(1);let C="";try{({userId:C}=await Z2(D,F))}catch{}let $=await a3(D,F,C),z=_2(E),Z=s0(E),J=Number(E.date_created??0),Q=String(E.last_updated_ts??"?"),G=await $(z),V=$0(await gF(D,Z,new Map));console.log(`id: ${E.id}`),console.log(`channel: ${G} (${z})`),console.log(`created: ${J?U2(J):"?"}`),console.log(`updated: ${U2(Number(Q.split(".")[0]))}`),console.log(`status: ${E.is_sent===!0?"sent":"pending"}`),console.log("---"),console.log(V)}function nD(...D){return b9(D.join(`
159
- `)).slice(0,4)}function VD(D){return D.replace(/\x1b\[[0-9;:?]*[ -/]*[@-~]/g,"").replace(/[\x00-\x1f\x7f-\x9f]/g,"").replace(/[\u061c\u200e\u200f\u202a-\u202e\u2066-\u2069]/g,"")}var a9={"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 RF(D){let F=D instanceof Error?D.message:String(D),u=F.match(/Slack error on (\S+): (\w+)/);if(!u)return F;let[,B,E]=u;switch(E){case"missing_scope":return`Error: token lacks the ${a9[B]??"the required"} scope (needed for ${B}). 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 F}}function pD(D,F,u){for(let B of u)console.log(B);if(D!==void 0)console.error(`Code mismatch (got ${D}, expected ${F})`);console.error(`Rerun with --code=${F}`),process.exit(1)}function e0(D){let F=pF(D);if(F)return F.ts?{ref:F.channel,ts:F.ts}:{ref:F.channel};if(D.startsWith("#")||D.startsWith("@")){let u=D.indexOf(":");if(u>0){let B=D.slice(u+1);if(/^\d{10}\.\d{6}$/.test(B))return{ref:D.slice(0,u),ts:B};if(/^\d{4}-\d{2}-\d{2}T/.test(B))return{ref:D.slice(0,u),ts:M2(B)}}}return{ref:D}}function Du(D){let F=pF(D);if(F){let B=F.threadTs??F.ts;return B?{ref:F.channel,threadTs:B}:{ref:F.channel}}let u=D.indexOf(":");if(u>0){let B=D.slice(u+1);if(/^\d{10}\.\d{6}$/.test(B))return{ref:D.slice(0,u),threadTs:B};if(/^\d{4}-\d{2}-\d{2}T/.test(B))return{ref:D.slice(0,u),threadTs:M2(B)}}return{ref:D}}async function N2(D,F,u,B){let E=u;if(!u.startsWith("#")&&!u.startsWith("@"))try{let C=w(await E0(D,F,B)),$=w(C.channel);if($.is_im===!0){let z=typeof $.user==="string"?$.user:"";E=z?`@${await EF(D,z,B)}`:F}else E=typeof $.name==="string"?`#${$.name}`:F}catch{E=F}return E===F?F:`${E} (${F})`}async function cF(D,F){try{return await C3(D,F)}catch{return null}}function kF(D,F){let u;return async()=>{if(u===void 0)u=await cF(D,F);return u}}function e3(D,F){let u=F?" [as bot]":"";if(!D)return`(unknown \u2014 auth.test failed)${u}`;let B=VD(D.user||D.userId||"?"),E=D.userId?` (${D.userId})`:"",C=D.team?` \u2014 ${VD(D.team)}`:"";return`@${B}${E}${C}${u}`}function mD(D,F={}){return` ${"From:".padEnd(F.pad??6)}${e3(D,F.asBot)}`}async function K2(D,F,u=60,B){let E=typeof F.user==="string"?await EF(D,F.user,B):typeof F.username==="string"?F.username:"?",C=(typeof F.text==="string"?F.text:"").split(`
160
- `)[0]??"",$=C.length>u?`${C.slice(0,u)}\u2026`:C,z=typeof F.ts==="string"?F.ts:"";return`${z?O2(z).slice(0,16).replace("T"," "):""} @${E}${$?`: ${$}`:""}`}async function e9(D,F,u,B){let E=u.find((C)=>String(C.ts)===F)??u[0];if(!E)return F;return K2(D,E,40,B)}function c3(D){return D.toLowerCase().replace(/<[@#!][^>]+>/g," ").replace(/[^\p{L}\p{N}\s]/gu," ").replace(/\s+/g," ").trim()}function D4(D,F){let u=c3(D),B=c3(F);if(!u||!B)return 0;if(u===B)return 1;let E=(J)=>{let Q=new Map;for(let G=0;G<J.length-1;G++){let X=J.slice(G,G+2);Q.set(X,(Q.get(X)??0)+1)}return Q},C=E(u),$=E(B);if(C.size===0||$.size===0)return 0;let z=0;for(let[J,Q]of C){let G=$.get(J);if(G)z+=Math.min(Q,G)}let Z=k3(C)+k3($);return Z===0?0:2*z/Z}function k3(D){let F=0;for(let u of D.values())F+=u;return F}async function F4(D,F){let u=kF(D,F.cookie),{ref:B,ts:E}=e0(F.target);if(!E)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 C;if(F.channelId)C=F.channelId;else C=await qD(D,B,F.cookie);let $=await lD(D,C,E,1,F.cookie),Z=o($.messages).map(w).find((H)=>String(H.ts)===E);if(!Z)console.error(`Message not found at ts=${E} in channel ${C}`),process.exit(1);let J=typeof Z.text==="string"?Z.text:"",Q=F.mentions?await f3(D,F.newText,C,F.cookie?{cookie:F.cookie}:{}):F.newText,G=await u(),X=nD(J,Q,G?.userId??"");if(F.code!==X)pD(F.code,X,["--- Editing as -------------------------------",mD(G),"--- Original message -------------------------",...J.split(`
161
- `).map((H)=>` ${H}`),"--- Replacing with ---------------------------",...Q.split(`
162
- `).map((H)=>` ${H}`),"--------------------------------\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"]);let V=await E2(D,C,E,Q,F.cookie);console.log(`\u2713 Edited (ts: ${V})`)}async function u4(D,F){let u=kF(D,F.cookie),{ref:B,ts:E}=e0(F.target);if(!E)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 C;if(F.channelId)C=F.channelId;else C=await qD(D,B,F.cookie);let $=await lD(D,C,E,1,F.cookie),Z=o($.messages).map(w).find((X)=>String(X.ts)===E);if(!Z)console.error(`Message not found at ts=${E} in channel ${C}`),process.exit(1);let J=typeof Z.text==="string"?Z.text:"",Q=await u(),G=nD(C,E,J,Q?.userId??"");if(F.code!==G){let X=await N2(D,C,B,F.cookie);pD(F.code,G,["--- Deleting message -------------------------",mD(Q),` \u2192 ${X} at ${O2(E)}`,...J.split(`
163
- `).map((V)=>` ${V}`),"---------------------------------------------"])}await W3(D,C,E,F.cookie),console.log(`\u2713 Deleted (ts: ${E})`)}async function E4(D,F){let{ref:u,ts:B}=e0(F.target);if(!B)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 E=F.emoji.replace(/^:|:$/g,""),C;if(F.channelId)C=F.channelId;else C=await qD(D,u,F.cookie);if(F.remove)await C2(D,C,B,E,F.cookie),console.log(`\u2713 Removed :${E}: (ts: ${B})`);else await B2(D,C,B,E,F.cookie),console.log(`\u2713 Reacted :${E}: (ts: ${B})`)}async function L2(D,F,u,B){if(!u||!F.startsWith("D"))return!1;try{let E=w(await E0(D,F,B)),C=w(E.channel);return C.is_im===!0&&C.user===u}catch{return!1}}async function B4(D,F){let{ref:u,threadTs:B}=Du(F.target),E=F.cookie,C=kF(D,E),$;if(F.channelId)$=F.channelId;else if(F.userId)$=await yF(D,F.userId,E);else $=await qD(D,u,E);if(!F.asBot&&await L2(D,$,(await C())?.userId,E))console.error(`Warning: "${F.target}" is a DM to yourself \u2014 Slack will NOT notify you of your own message.
164
- `+` To reach yourself with a notification, send as the bot: slack send '${F.target}' '...' --as-bot`);let z=F.message,Z=null;if(F.mentions){Z=await C0(F.mentionToken??D,F.message,$,F.mentionCookie),z=Z.text;for(let M of t0(Z.unresolved))console.error(`\u26A0 ${VD(M)}`)}try{for(let M of await y3(F.mentionToken??D,z,F.mentionCookie))console.error(`\u26A0 possible untagged mention: ${VD(M.surface)} \u2014 @${VD(M.display)} won't be notified (did you mean <@${M.userId}>?)`)}catch{}let J=[];if(Z&&(Z.resolved.length>0||Z.unresolved.length>0)){J.push("--- Mentions ---------------------------------");for(let M of Z.resolved)J.push(` \u2713 ${VD(M.surface)} \u2192 @${VD(M.display)} (${M.userId}) \u2014 will notify`);for(let M of Z.unresolved){let R=M.reason==="ambiguous"?"ambiguous":M.reason==="unavailable"?"lookup unavailable":"no match";J.push(` \u26A0 ${VD(M.surface)} \u2014 plain text, NOT notified (${R})`)}}let Q="",G="?",X=[],V,H,W;if(B)try{let M=await lD(D,$,B,100,E);X=o(M.messages).map(w);let R=X[X.length-1];Q=typeof R?.text==="string"?R.text:"",V=typeof R?.user==="string"?R.user:void 0,H=typeof R?.bot_id==="string"?R.bot_id:void 0,W=typeof R?.ts==="string"?R.ts:void 0}catch{}else try{let M=await uF(D,$,1,void 0,void 0,E),R=o(M.messages).map(w),I=R.filter((l)=>l.subtype===void 0||l.subtype===null)[0];Q=typeof I?.text==="string"?I.text:"",G=typeof I?.user==="string"?await EF(D,I.user,E):typeof I?.username==="string"?I.username:"?";let y=R[0];V=typeof y?.user==="string"?y.user:void 0,H=typeof y?.bot_id==="string"?y.bot_id:void 0,W=typeof y?.ts==="string"?y.ts:void 0}catch{}if(process.env.SLACK_UNREPLIED_WARN!=="0"&&W&&(V||H))try{let M=await C();if(!!M&&(!!V&&!!M.userId&&M.userId===V||!!H&&!!M.botId&&M.botId===H)){let I=`slack edit "#${$}:${W}" "<\u65B0\u3057\u3044\u672C\u6587>" --channel-id ${$}`;try{let y=await c0(D,$,W,E);if(y)I=`slack edit "${y}" "<\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(` ${I}`),console.error(" \u3053\u306E\u307E\u307E\u9001\u4FE1\u3059\u308B\u5834\u5408\u306F --code=XXXX \u3067\u78BA\u5B9A\u3002")}}catch{}if(B&&X.length){let M={sim:0,msg:null};for(let R of X){let I=typeof R.text==="string"?R.text:"";if(!I)continue;let y=D4(z,I);if(y>M.sim)M={sim:y,msg:R}}if(M.msg&&M.sim>=0.82){let R=Math.round(M.sim*100);console.error(`\u26A0 possible duplicate: ${R}% similar to an existing thread message \u2014 ${await K2(D,M.msg,60,E)}`)}}let j=await C(),N=nD($,B??"",Q,z,j?.userId??"");if(F.code!==N){let M=await N2(D,$,u,E),R=mD(j,{asBot:F.asBot});if(B){let I=await e9(D,B,X,E),y=X.slice(-3),l=y.length?await Promise.all(y.map(async(h)=>` ${await K2(D,h,60,E)}`)):[" (thread context unavailable)"];pD(F.code,N,["--- Recent messages in thread ----------------",...l,...J,"--- Sending ----------------------------------",R,` \u2192 ${M} thread of ${I} \u2014 THREAD REPLY`,` Message: ${z}`,"--------------------------------\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"])}else pD(F.code,N,["--- Last message in channel ------------------",` ${G}: ${Q.split(`
165
- `)[0]?.slice(0,100)??"(empty)"}`,...J,"--- Sending ----------------------------------",R,` \u2192 ${M} \u2014 NEW top-level message`,` Message: ${z}`,"--------------------------------\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"])}let O=await g0(D,$,z,B,F.broadcast,E),T="";try{T=await c0(D,$,O,E)}catch{}if(T)console.log(`\u2713 Sent: ${T}`);else console.log(`\u2713 Sent (ts: ${O})`);if(F.asBot&&$.startsWith("D"))try{let M=await du(D);if(!M.ok)for(let R of iu(M,!0))console.error(R);else{let R=M.appId?`https://api.slack.com/apps/${M.appId}`:"https://api.slack.com/apps";console.error(`Note: if ${F.target} can't reply (app messaging may be off), enable Messages Tab: ${R} \u2192 App Home.`)}}catch{}}var C4=2,OD=3,$4=1.618033988749895,z4=1000,Z4=5000,d3=8,J4=(D)=>new Promise((F)=>setTimeout(F,D)),G4=new Set(["thread_broadcast"]),Q4=/(?<![A-Za-z0-9._@<-])@(here|channel|everyone)(?![A-Za-z0-9._-])/giu;function i3(D){let F=new Set;return{text:D.replace(Q4,(B,E)=>{let C=E.toLowerCase();return F.add(C),`<!${C}>`}),kinds:F}}async function D6(D,F,u){if(!F.startsWith("D"))return;try{let B=w(await E0(D,F,u)),E=w(B.channel);return E.is_im===!0&&typeof E.user==="string"?E.user:void 0}catch{return}}async function F6(D,F){let{channelId:u,ts:B,question:E,reactable:C,threadOnly:$,audience:z,broadcast:Z,cookie:J,timeout:Q,shown:G}=F,X=F.askerUserId,V=F.askerBotId,H=(l)=>typeof l==="string"&&!!l&&l!==X&&(Z||z.has(l));function W(l){let h=o(l.reactions).map(w),a=[];for(let L=0;L<C.length;L++){let A=h.find((p)=>p.name===bD[L].name),S=A?o(A.users).filter(H):[];if(S.length)a.push({index:L,users:S})}return a}let j=!1;async function N(l){let h=W(l);if(!h.length)return null;if(h.length===1){let{index:L,users:A}=h[0];return{answer:C[L],how:`\u30EA\u30A2\u30AF\u30B7\u30E7\u30F3 ${bD[L].glyph}`,who:A[0]}}let a=h.map((L)=>bD[L.index].glyph).join(" / ");if(!j){j=!0,console.error(` (${a} \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)`);try{await g0(D,u,`${a} \u304C\u540C\u6642\u306B\u9078\u3070\u308C\u3066\u3044\u307E\u3059\u3002\u56DE\u7B54\u3092\u78BA\u5B9A\u3067\u304D\u306A\u3044\u306E\u3067\u30011 \u3064\u3060\u3051\u6B8B\u308B\u3088\u3046\u306B\u30EA\u30A2\u30AF\u30B7\u30E7\u30F3\u3092\u5916\u3059\u304B\u3001\u3053\u306E\u30B9\u30EC\u30C3\u30C9\u3067\u8FD4\u4FE1\u3057\u3066\u304F\u3060\u3055\u3044\u3002`,B,!1,J)}catch(L){console.error(` (\u78BA\u8A8D\u306E\u8FD4\u4FE1\u3092\u9001\u308C\u307E\u305B\u3093\u3067\u3057\u305F: ${L instanceof Error?L.message:String(L)})`)}}return null}function O(l,h=1/0){let a=[...l].sort((L,A)=>Number(L.ts)-Number(A.ts));for(let L of a){if(!(Number(L.ts)>Number(B)))continue;if(!H(L.user))continue;if(typeof L.subtype==="string"&&!G4.has(L.subtype))continue;if(Number(L.ts)>=h)break;let A=typeof L.text==="string"?L.text.trim():"";if(A)return{answer:A,how:"\u8FD4\u4FE1",who:L.user}}return null}async function T(){if(F.threadParentTs){let L=w(await lD(D,u,F.threadParentTs,100,J)),A=o(L.messages).map(w),S=A.find((p)=>p.ts===B);if(S){let p=await N(S);if(p)return p}return O(A)}let l=w(await uF(D,u,30,B,void 0,J,!0)),h=o(l.messages).map(w),a=h.find((L)=>L.ts===B);if(a){let L=await N(a);if(L)return L}if(!$){let L=h.filter((S)=>Number(S.ts)>Number(B)&&(V&&S.bot_id===V||X&&S.user===X)).reduce((S,p)=>Math.min(S,Number(p.ts)),1/0),A=O(h,L);if(A)return A}if(a&&Number(a.reply_count)>0){let L=w(await lD(D,u,B,30,J)),A=O(o(L.messages).map(w));if(A)return A}return null}async function M(l){for(let a=0;a<C.length;a++)try{await C2(D,u,B,bD[a].name,J)}catch{}let h="";if(l.who)try{h=await EF(D,l.who,J)}catch{h=l.who}if(h)console.error(` \u56DE\u7B54\u8005: ${VD(h)}`);try{await E2(D,u,B,F3(E,l,h),J)}catch(a){console.error(` (\u5143\u30E1\u30C3\u30BB\u30FC\u30B8\u306E\u66F4\u65B0\u306B\u5931\u6557: ${a instanceof Error?a.message:String(a)})`)}}let R=Date.now()+Q*1000,I=0,y=z4;for(;;){let l=null;try{l=await T(),I=0}catch(h){if(I++,I>=d3)console.error(`Error: Slack \u3078\u306E\u554F\u3044\u5408\u308F\u305B\u306B ${I} \u56DE\u9023\u7D9A\u3067\u5931\u6557\u3057\u307E\u3057\u305F: ${h instanceof Error?h.message:String(h)}`),process.exit(OD);console.error(` (Slack \u30A8\u30E9\u30FC ${I}/${d3}, \u518D\u8A66\u884C\u3057\u307E\u3059: ${h instanceof Error?h.message:String(h)})`)}if(l)await M(l),console.log(l.answer),process.exit(0);if(Date.now()>=R)break;await J4(Math.min(y,Math.max(0,R-Date.now()))),y=Math.min(y*$4,Z4)}if(Q===0)console.error(`\u307E\u3060\u56DE\u7B54\u304C\u3042\u308A\u307E\u305B\u3093: ${G}`);else console.error(`Error: ${Q}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(` ${G}`),console.error(` \u3042\u3068\u3067\u56DE\u53CE\u3059\u308B: ${u6(G,F.asBot)}`);process.exit(C4)}function u6(D,F){return`slack ask --waitFor='${D}'${F?" --as-bot":""}`}async function X4(D,F){let{ref:u,threadTs:B}=Du(F.target),E=F.cookie,C=kF(D,E),$;if(F.channelId)$=F.channelId;else if(F.userId)$=await yF(D,F.userId,E);else $=await qD(D,u,E);let z=(await C())?.userId??"",Z=await D6(D,$,E);if(!F.asBot&&!!z&&Z===z)console.error(`Warning: "${F.target}" is a DM to yourself \u2014 Slack will NOT notify you of your own message.
166
- `+` To reach yourself with a notification, ask as the bot: slack ask '${F.target}' '...' --as-bot`);let J=i3(F.question),Q=i3(F.body??""),G=new Set([...J.kinds,...Q.kinds]),X=F.mentionToken??D,V=await C0(X,J.text,$,F.mentionCookie),H=Q.text?await C0(X,Q.text,$,F.mentionCookie):{text:"",resolved:[],unresolved:[]},W=V.text,j=H.text,N=[...V.resolved,...H.resolved],O=[...V.unresolved,...H.unresolved];for(let k of t0(O))console.error(`\u26A0 ${VD(k)}`);let T=G.size>0,M=new Set(N.map((k)=>k.userId).filter((k)=>k!==z)),R=new Map(N.map((k)=>[k.userId,k.display])),I;if(T)I=`anyone in ${u} (${[...G].map((k)=>`@${k}`).join(", ")})`;else{if(!M.size&&Z&&Z!==z)M.add(Z),R.set(Z,await EF(D,Z,E));if(!M.size)console.error("Error: `ask` will not post a question nobody is addressed to \u2014 no one is tagged.\n"+(O.length?` (${O.map((k)=>VD(k.surface)).join(", ")} matched no one, so it names nobody.)
167
- `:"")+` Tag the person who should answer: slack ask '${F.target}' '@alice ${F.question}' ...
168
- Or open it to the whole channel: slack ask '${F.target}' '@here ${F.question}' ...
169
- (In a 1:1 DM the other person counts automatically.)`),process.exit(OD);I=[...M].map((k)=>`@${VD(R.get(k)??k)} (${k})`).join(", ")}let y=F.choices.slice(0,m0),l=F.choices.slice(m0),h=!$.startsWith("D")||!!B,a=D3(W,j,y,l,h),L="",A="?";try{let k=await uF(D,$,1,void 0,void 0,E),BD=o(k.messages).map(w).filter((RD)=>RD.subtype===void 0||RD.subtype===null)[0];L=typeof BD?.text==="string"?BD.text:"",A=typeof BD?.user==="string"?await EF(D,BD.user,E):typeof BD?.username==="string"?BD.username:"?"}catch{}let S=await C(),p=nD($,B??"",L,a,S?.userId??"");if(F.code!==p){let k=await N2(D,$,u,E),BD=y.length?["--- Choices (seeded as reactions) ------------",...y.map((RD,c)=>` ${bD[c].glyph} ${RD}`),...l.map((RD,c)=>` (${c+11}) ${RD} \u2014 text answer only`)]:["--- Choices ----------------------------------"," (none \u2014 free-text reply)"];pD(F.code,p,["--- Last message in channel ------------------",` ${A}: ${L.split(`
170
- `)[0]?.slice(0,100)??"(empty)"}`,...BD,"--- Asking -----------------------------------",mD(S,{asBot:F.asBot}),` \u2192 ${k}${B?" \u2014 THREAD REPLY":" \u2014 NEW top-level message"}`,` Question: ${W}`,` Answerable by: ${I}`,` Via: ${h?"reactions or thread replies":"reactions or replies in this DM"}`,"--------------------------------\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"])}let r=await g0(D,$,a,B,!1,E);for(let k=0;k<y.length;k++)try{await B2(D,$,r,bD[k].name,E)}catch(BD){console.error(` (\u30EA\u30A2\u30AF\u30B7\u30E7\u30F3 ${bD[k].name} \u3092\u4ED8\u3051\u3089\u308C\u307E\u305B\u3093\u3067\u3057\u305F: ${BD instanceof Error?BD.message:String(BD)})`)}let uD="";try{uD=await c0(D,$,r,E)}catch{}let s=uD||`${$}:${r}`;if(console.error(`\u2713 Asked: ${s}`),!F.wait){console.log(u6(s,!!F.asBot));return}let ED=F.timeout??3600;console.error(` \u56DE\u7B54\u3092\u5F85\u3063\u3066\u3044\u307E\u3059 (\u6700\u5927 ${ED}s)\u2026 Ctrl-C \u3067\u4E2D\u65AD`);let TD={channelId:$,ts:r,question:W,reactable:y,threadOnly:h,audience:M,broadcast:T,askerUserId:S?.userId??"",askerBotId:S?.botId??"",timeout:ED,shown:s,asBot:!!F.asBot};if(B)TD.threadParentTs=B;if(E)TD.cookie=E;await F6(D,TD)}async function Y4(D,F){let u=pF(F.link),B,E,C;if(u?.ts)B=u.channel,E=u.ts,C=u.threadTs&&u.threadTs!==u.ts?u.threadTs:void 0;else{let H=F.link.match(/^([A-Za-z0-9]+):(\d{10}\.\d{6})$/);if(!H)console.error(`Error: --waitFor needs the permalink of a question (or 'C\u2026:1700000000.000100').
171
- `+` Got: ${VD(F.link)}`),process.exit(OD);B=H[1],E=H[2]}let $;if(C){let H=w(await lD(D,B,C,100,F.cookie));$=o(H.messages).map(w).find((W)=>W.ts===E)}else{let H=w(await uF(D,B,1,E,void 0,F.cookie,!0));$=o(H.messages).map(w).find((W)=>W.ts===E)}if(!$)console.error(`Error: \u305D\u306E\u30E1\u30C3\u30BB\u30FC\u30B8\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093: ${VD(F.link)}`),process.exit(OD);let z=typeof $.text==="string"?$.text:"",Z=u3(z);if(Z.kind==="other")console.error("Error: \u3053\u308C\u306F `slack ask` \u306E\u8CEA\u554F\u3067\u306F\u3042\u308A\u307E\u305B\u3093 (\u56DE\u7B54\u306E\u8AAD\u307F\u53D6\u308A\u65B9\u304C\u5206\u304B\u308A\u307E\u305B\u3093)\u3002\n"+` ${VD(F.link)}`),process.exit(OD);if(Z.kind==="resolved"){console.error(`\u2713 \u56DE\u7B54\u6E08\u307F: ${VD(Z.question)}`),console.log(Z.answer);return}let J=typeof $.user==="string"?$.user:"",Q=typeof $.bot_id==="string"?$.bot_id:"",G=/<!(here|channel|everyone)(\^[^>]*)?(\|[^>]*)?>/.test(z),X=new Set;for(let H of z.matchAll(/<@([UW][A-Z0-9]+)>/g))if(H[1]!==J)X.add(H[1]);if(!X.size&&!G){let H=await D6(D,B,F.cookie);if(H&&H!==J)X.add(H)}if(!X.size&&!G)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: ${VD(F.link)}`),process.exit(OD);if(F.timeout>0)console.error(` \u56DE\u7B54\u3092\u5F85\u3063\u3066\u3044\u307E\u3059 (\u6700\u5927 ${F.timeout}s)\u2026 Ctrl-C \u3067\u4E2D\u65AD`);let V={channelId:B,ts:E,question:Z.question,reactable:Z.reactable,threadOnly:Z.threadOnly,audience:X,broadcast:G,askerUserId:J,askerBotId:Q,timeout:F.timeout,shown:F.link,asBot:F.asBot};if(C)V.threadParentTs=C;if(F.cookie)V.cookie=F.cookie;await F6(D,V)}async function W4(D){let F=await du(D);for(let u of iu(F,!1))console.log(u);if(!F.ok)process.exit(1)}function V4(D){if(/^\d{10,}$/.test(D))return parseInt(D,10);let F=new Date(D.replace(" ","T"));if(isNaN(F.getTime()))throw Error(`Cannot parse time: ${D}`);return Math.floor(F.getTime()/1000)}function H4(D){let F=new Date(D*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(F).replace(/\u2212/g,"-")} (local) / ${F.toISOString()} (Unix: ${D})`}async function q4(D,F){let u=kF(D,F.cookie),{ref:B,threadTs:E}=Du(F.target),C;if(F.channelId)C=F.channelId;else if(F.userId)C=await yF(D,F.userId,F.cookie);else C=await qD(D,B,F.cookie);let $=V4(F.at),z=new Date($*1000).toISOString(),Z=await u();if(await L2(D,C,Z?.userId,F.cookie))console.error(`Warning: "${F.target}" is a DM to yourself \u2014 Slack will NOT notify you when this fires.`);let J=nD(C,F.message,String($),Z?.userId??"");if(F.code!==J)pD(F.code,J,["--- Scheduling message -----------------------",mD(Z,{pad:9}),` To: ${B}${E?` (thread ${E})`:""}`,` At: ${H4($)}`,` Message: ${F.message}`,"---------------------------------------------"]);let Q=await Q3(D,C,F.message,$,E,F.cookie);console.log(`\u2713 Scheduled (id: ${Q}, at: ${z})`)}async function j4(D,F,u,B){let E;if(u)E=u;else if(F)E=await qD(D,F,B);let $=(await X3(D,E,B)).scheduled_messages??[];if($.length===0){console.log("(no scheduled messages)");return}for(let z of $){let Z=new Date(z.post_at*1000).toISOString();console.log(`${z.id} ${Z} [${z.channel_id}] ${z.text.split(`
172
- `)[0]?.slice(0,80)??""}`)}}async function U4(D,F){let u;if(F.channelId)u=F.channelId;else u=await qD(D,F.target,F.cookie);let B=await cF(D,F.cookie),E=nD(u,F.id,B?.userId??"");if(F.code!==E)pD(F.code,E,["--- Deleting scheduled message ---------------",mD(B,{pad:9}),` Channel: ${F.target}`,` ID: ${F.id}`,"---------------------------------------------"]);await Y3(D,u,F.id,F.cookie),console.log(`\u2713 Deleted scheduled message ${F.id}`)}async function K4(D,F){let u=kF(D,F.cookie),{statSync:B,existsSync:E}=await import("fs"),{basename:C}=await import("path");for(let H of F.filePaths)if(!E(H))console.error(`Error: file not found: ${H}`),process.exit(1);let{ref:$,threadTs:z}=Du(F.target),Z;if(F.channelId)Z=F.channelId;else if(F.userId)Z=await yF(D,F.userId,F.cookie);else Z=await qD(D,$,F.cookie);if(await L2(D,Z,(await u())?.userId,F.cookie))console.error(`Warning: "${F.target}" is a DM to yourself \u2014 Slack will NOT notify you of your own upload.`);let J=F.filePaths.length>1,Q=F.filePaths.map((H)=>{let W=C(H),j=J?W:F.title??W;return{fp:H,filename:W,title:j,sizeFmt:a0(B(H).size)}}),G=await u(),X=nD(Z,...Q.flatMap((H)=>[H.fp,H.title]),G?.userId??"");if(F.code!==X){let H=` To: ${$}${z?` (thread ${z})`:""}`,W=J?[`--- Uploading ${Q.length} files ------------------------`,mD(G,{pad:7}),H,...Q.map((j)=>` ${j.filename} (${j.sizeFmt})`),"--------------------------------\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"]:["--- Uploading file ---------------------------",mD(G,{pad:7}),H,` File: ${Q[0].fp}`,` Title: ${Q[0].title}`,` Size: ${Q[0].sizeFmt}`,"--------------------------------\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"];pD(F.code,X,W)}let V=Q.length;for(let H=0;H<V;H++){let W=Q[H],j={title:W.title};if(z!==void 0)j.threadTs=z;if(F.comment!==void 0&&H===0)j.initialComment=F.comment;let{fileId:N,permalink:O}=await O3(D,Z,W.fp,j,F.cookie),T=V>1?`[${H+1}/${V}] `:"";console.log(`${T}\u2713 Uploaded (file_id: ${N}${O?`, url: ${O}`:""})`)}}async function O4(D,F,u){let B=u.channel?await qD(D,u.channel,F):void 0,E=[],C=1,$=1;do{let Z={page:C,count:200};if(u.types)Z.types=u.types;if(B)Z.channel=B;if(u.user)Z.user=u.user;let J=w(await z3(D,Z,F));for(let Q of o(J.files))E.push(w(Q));$=Number(w(J.paging).pages??1),C++}while(E.length<u.limit&&C<=$);let z=E.slice(0,u.limit);if(u.format==="jsonl"){for(let Z of z)console.log(JSON.stringify({id:Z.id??null,name:Z.name??Z.title??null,filetype:Z.filetype??null,size:Z.size??null,user:Z.user??null,created:Z.created??null,permalink:Z.permalink??null}));return}for(let Z of z){let J=String(Z.id??""),Q=typeof Z.name==="string"?Z.name:typeof Z.title==="string"?Z.title:J,G=typeof Z.filetype==="string"?Z.filetype:"?",X=typeof Z.size==="number"?a0(Z.size):"";console.log(`${J} ${G.padEnd(7)} ${X.padStart(9)} ${Q}`)}}function M4(D){if(/^F[A-Z0-9]+$/i.test(D))return D;return D.match(/\/lists\/[A-Za-z0-9]+\/(F[A-Za-z0-9]+)/i)?.[1]??D.match(/\/lists\/(F[A-Za-z0-9]+)/i)?.[1]}function _4(D){if(typeof D.text==="string"&&D.text)return D.text;let F=D.value;if(typeof F==="string"||typeof F==="number"||typeof F==="boolean")return String(F);if(Array.isArray(F))return F.map((u)=>typeof u==="string"?u:String(w(u).text??w(u).name??w(u).value??"")).filter(Boolean).join(", ");for(let u of["rich_text","select","user","date","number","checkbox","email","phone"]){let B=D[u];if(B!=null)return typeof B==="object"?JSON.stringify(B):String(B)}return""}async function N4(D,F,u,B){let E=M4(u);if(!E)throw Error(`Not a list ID or list URL: ${u}
173
- `+"Expected F\u2026 or https://<ws>.slack.com/lists/<TEAM>/<F-id>");let C=[],$;do{let Z={limit:200};if($)Z.cursor=$;let J=w(await Z3(D,E,Z,F));for(let G of o(J.items??J.records))C.push(w(G));let Q=w(J.response_metadata).next_cursor;$=typeof Q==="string"&&Q?Q:void 0}while($&&C.length<B.limit);let z=C.slice(0,B.limit);if(B.format==="jsonl"){for(let Z of z)console.log(JSON.stringify(Z));return}for(let Z of z){let J=String(Z.id??""),Q=o(Z.fields).map(w).map((G)=>{let X=String(G.key??G.column_id??"?"),V=_4(G);return V?`${X}=${V}`:""}).filter(Boolean);console.log(`${J} ${Q.join(" | ")}`)}}function L4(D){if(/^F[A-Z0-9]+$/i.test(D))return D;return D.match(/\/files\/[A-Za-z0-9]+\/(F[A-Za-z0-9]+)/)?.[1]}async function A4(D,F,u,B){let E=L4(u);if(!E)throw Error(`Not a file ID or file permalink: ${u}
174
- `+"Expected F\u2026 or https://<ws>.slack.com/files/<UID>/<FID>/<name>");let C=w(await $3(D,E,F)),$=w(C.file),z=typeof $.name==="string"?$.name:typeof $.title==="string"?$.title:E,Z=typeof $.url_private_download==="string"?$.url_private_download:typeof $.url_private==="string"?$.url_private:"";if(!Z)throw Error(`files.info returned no download URL for ${E}`);let J={Authorization:`Bearer ${D}`};if(F)J.Cookie=`d=${F}`;let Q=await fetch(Z,{headers:J});if(!Q.ok)throw Error(`Download failed: HTTP ${Q.status} ${Q.statusText}`);let G=Buffer.from(await Q.arrayBuffer()),{statSync:X,existsSync:V}=await import("fs"),{basename:H}=await import("path"),W=B??z;if(B&&V(B)&&X(B).isDirectory())W=$F(B,H(z));n3(W,G),console.log(`\u2713 Downloaded ${z} (${a0(G.length)}) \u2192 ${W}`)}async function P4(){I9();let D=(E)=>yu(E.workspace),F=(E)=>W1(E.workspace),u={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}},B=async(E,C)=>{let $={state:E.state??"open",mine:C||E.mine===!0,count:E.n??50,json:E.json===!0};if(E.in)$.in=E.in;if(E.from)$.from=E.from;let z=F(E);if(z)$.cookie=z;await d9(D(E),$)};await z1(Vu(process.argv)).scriptName("slack").showHelpOnFail(!1).fail((E,C,$)=>{if(C)console.error(C.message),process.exit(1);console.error(E),console.error(""),$.showHelp(),process.exit(1)}).option("workspace",{alias:"w",type:"string",describe:"Workspace name"}).middleware(async(E)=>{let C=String((E._??[])[0]??"");if(!C||C==="auth"||C==="login")return;try{yu(E.workspace)}catch($){if(($ instanceof Error?$.message:String($)).startsWith("No profiles configured"))console.log(`No workspace configured. Let's set that up:
175
- `),await v0(),process.exit(0);throw $}},!0).command(["read [target]","msgs [target]"],"Browse messages",(E)=>E.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(E)=>{let C=D(E),$=E.json?"jsonl":E.format;if(E.target)await y9(C,E.target,E.limit,$,E.unreplied,F(E));else await m9(C)}).command("thread <target> <ts>","Show thread messages",(E)=>E.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(E)=>{let C=E.json?"jsonl":E.format;await p9(D(E),E.target,E.ts,E.limit,C,F(E))}).command(["channel","channels","ch"],"Channel commands",(E)=>E.command(["ls","list"],"List channels",(C)=>C.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(C)=>{await c9(D(C),C.limit,C.filter,C.all,C.json?"jsonl":C.format)}).command("get <channel>","Show channel details",(C)=>C.positional("channel",{type:"string",demandOption:!0,describe:"#name or channel ID"}),async(C)=>{let $=D(C),z=F(C),Z=C.channel,J=Z.startsWith("#")||Z.startsWith("@")||Z.startsWith("C")||Z.startsWith("G")||Z.startsWith("D")?Z:`#${Z}`,Q=await qD($,J,z),G=w(await E0($,Q,z)),X=w(G.channel),V=typeof X.name==="string"?X.name:Q,W=X.is_im===!0?"@":"#",j=String(w(X.purpose).value??""),N=String(w(X.topic).value??""),O=X.num_members??X.member_count??"";if(console.log(`${W}${V} ${Q}`),N)console.log(`topic: ${N}`);if(j)console.log(`purpose: ${j}`);if(O)console.log(`members: ${O}`);console.log(`private: ${X.is_private===!0}`)}).command(["create <name>","new <name>"],"Create a channel (confirm-hash safety gate)",(C)=>C.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(C)=>{let $=D(C),z=F(C),Z=C.name.replace(/^#/,"").toLowerCase(),J=C.private===!0,Q=C.invite.filter(Boolean),G=await cF($,z),X=nD(Z,String(J),Q.join(","),G?.userId??"");if(C.code!==X)pD(C.code,X,["--- Creating channel -------------------------",mD(G,{pad:9}),` name: ${J?"\uD83D\uDD12 ":"#"}${Z}`,` private: ${J}`,...Q.length?[` invite: ${Q.join(", ")}`]:[],"--------------------------------\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"]);let V;try{V=await V3($,Z,J,z)}catch(H){console.error(H instanceof Error?H.message:String(H)),process.exit(1)}if(console.log(`\u2713 Created ${J?"\uD83D\uDD12 ":"#"}${V.name} (${V.id})`),Q.length){let H=[];for(let W of Q)try{H.push(W.startsWith("U")||W.startsWith("W")?W:await d0($,W,z))}catch(j){console.error(` ! could not resolve ${W}: ${j instanceof Error?j.message:String(j)}`)}for(let W of H)try{let j=w(await z2($,W,z)),N=w(j.user);if(N.is_ultra_restricted===!0)console.error(`\u26A0 ${W} 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(N.is_restricted===!0)console.error(`\u26A0 ${W} is a multi-channel guest \u2014 double-check they were actually added (guest invites can silently no-op depending on workspace restrictions).`)}catch{}if(H.length)try{await H3($,V.id,H,z),console.log(`\u2713 Invited ${H.length} member${H.length===1?"":"s"}`)}catch(W){console.error(` ! invite failed: ${W instanceof Error?W.message:String(W)}`)}}}).demandCommand(1,"").showHelpOnFail(!0)).command(["user","usr"],"User commands",(E)=>E.command(["ls","list"],"List workspace members",(C)=>C.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"}),async(C)=>{let $=C.json?"jsonl":C.format,z=await $2(D(C)),Z=C.filter?.toLowerCase(),J=o(z.members).map(w).filter((G)=>G.deleted!==!0&&G.is_bot!==!0&&String(G.id)!=="USLACKBOT").filter((G)=>{if(!Z)return!0;let X=String(G.name??"").toLowerCase(),V=String(w(G.profile).real_name??"").toLowerCase(),H=String(w(G.profile).email??"").toLowerCase();return X.includes(Z)||V.includes(Z)||H.includes(Z)}).slice(0,C.limit);if($==="jsonl"){for(let G of J)console.log(JSON.stringify(G));return}if($==="yaml"){for(let G of J){let X=function(V,H=""){if(V===null)return"null";if(typeof V==="string")return V.includes(`
165
+ Then select it: slack auth use <name> (or pass --workspace <name>)`),process.exit(1)}else throw f}if(i){console.log(JSON.stringify(a,null,2));return}let c=X(un(a,["messages","matches"])).map(P),u=new Map;for(let f of c){let l=P(f.channel),d=l.is_im===!0,h=typeof l.name==="string"?l.name:"dm",m;if(d&&h.startsWith("U")){let p="@"+h;if(!u.has(p)){let[,y]=await hn(r,h,o);u.set(p,y)}m=`@${u.get(p)??h}`}else if(d)m=`@${h}`;else m=`#${h}`;console.log(await ps(r,f,u,m,o))}}async function Tc(e,t,n,i){let{ref:s,ts:r}=gs(t);if(!r)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 Mi(e,s,De,i),ts:r}}async function $f(e,t){let n=Dn(),i={};if(!t.mine)i.shared=!0;if(t.in)i.in=t.in;if(t.from)i.from=t.from;let s=uc(t.state,n,i);if(!t.json){let r=await Vt(e,t.cookie),o=t.mine?"your reactions only [hasmy:]":"anyone's reactions [has:]";console.error(`(From: ${Mc(r)} \xB7 matching ${o})`),console.error(`(query: ${s})`)}await Ae("search.messages",()=>Pc(e,s,t.count,t.json,t.cookie))}async function Of(e,t){let n=Dn(),{channelId:i,ts:s}=await Tc(e,t.target,t.channelId,t.cookie),r=await hc(e,i,s,t.state,n,t.cookie);if(r.noop){console.log(`= Already ${t.state} (ts: ${s})`);return}let o=r.removed.length?`, removed ${r.removed.map((a)=>`:${a}:`).join(" ")}`:"";if(console.log(`\u2713 ${t.state} :${n.progress[t.state]}: (ts: ${s})${o}`),r.leftover.length)console.error(`\u26A0 ${r.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 If(e,t){let n=Dn(),{channelId:i,ts:s}=await Tc(e,t.target,t.channelId,t.cookie),r=await gc(e,i,s,t.flag,n,t.remove===!0,t.cookie);console.log(`\u2713 ${t.remove?"Cleared":"Flagged"} ${t.flag} :${r}: (ts: ${s})`)}async function Pf(e,t){let n=Dn(),i=t.channelId??await Mi(e,t.channel,De,t.cookie),s={limit:t.limit};if(t.fix)s.fix=!0;if(t.cookie)s.cookie=t.cookie;let r=await mc(e,i,n,s);if(r.findings.length===0)console.log(`\u2713 No multi-state tasks in ${r.scanned} message(s).`);else{for(let o of r.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(`${r.findings.length} multi-state task(s) in ${r.scanned} message(s).`)}if(r.truncated)console.error(`\u26A0 Scan limit reached (${t.limit} messages) \u2014 older history was NOT checked. Raise it with --limit N.`)}async function Tf(e,t,n,i){let s=Math.floor(Date.now()/1000)-t*86400,r=await dn(e),o=X(r.channels).map(P).filter((f)=>f.is_member===!0&&f.is_im!==!0&&f.is_mpim!==!0).filter((f)=>{if(!i)return!0;return(typeof f.name==="string"?f.name:"").toLowerCase().includes(i.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,h;try{h=await Ze(e,l,n)}catch(p){console.error(` SKIP #${d}: ${p.message}`);continue}let m=X(h.messages).map(P).filter((p)=>(p.subtype===void 0||p.subtype===null)&&ls(p)>=s);if(m.length===0)continue;u+=1,c+=m.length,console.log(`## #${d} (${m.length} msgs)
166
+ `);for(let p of[...m].reverse()){let y=await Oc(e,p,a),E=typeof p.text==="string"?p.text:"",k=wn(await Gt(e,E,a)).split(`
167
+ `).join(" \u21B5 ");console.log(`[${Cc(ls(p))}] ${y}: ${k}`)}console.log("")}console.error(`Dumped ${c} messages across ${u} channels (cutoff: ${t}d)`)}function Rf(e){let t=[];function n(i){if(typeof i==="string"){t.push(i);return}if(Array.isArray(i)){for(let s of i)n(s);return}if(i&&typeof i==="object"){let s=i;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 i of e)n(i);return t.join("").trim()}async function Rc(e,t,n){let i=new Map;return async(s)=>{if(!s)return"(unknown)";if(i.has(s))return i.get(s);try{let r=await tc(e,s,t),o=P(r.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 hn(e,c);a=`@${u}`}}else a=`#${typeof o.name==="string"?o.name:s}`;return i.set(s,a),a}catch{return s}}}function zi(e){let t=P(X(e.destinations)[0]);return String(t.channel_id??e.channel_id??e.channel??"")}function fs(e){return Rf(X(e.blocks))||(typeof e.text==="string"?e.text:"(no text)")}async function Mf(e,t,n=!1){let i=await gn(e,t),s=X(i.drafts??i.messages??[]).map(P).filter((u)=>u.is_deleted!==!0),r=n?s:s.filter((u)=>u.is_sent!==!0);if(r.length===0){console.log(n?"No drafts.":"No pending drafts. Run with --all to include sent.");return}let o="";try{({userId:o}=await Oi(e,t))}catch{}let a=await Rc(e,t,o),c=new Map;for(let u of r){let f=zi(u),l=fs(u),d=Number(u.date_created??u.date_create??0),h=d?Wi(d):"?",m=await a(f),p=typeof u.id==="string"?u.id:"",y=u.is_sent===!0?" [SENT]":"",E=wn(await Gt(e,l,c));console.log(`-- ${p} ${m} [${h}]${y}`);for(let F of E.split(`
168
+ `))console.log(` ${F}`)}}async function Bf(e,t,n){let i=await gn(e,t),s=X(i.drafts).map(P).find((m)=>String(m.id)===n);if(!s)console.error(`Draft not found: ${n}`),process.exit(1);let r="";try{({userId:r}=await Oi(e,t))}catch{}let o=await Rc(e,t,r),a=zi(s),c=fs(s),u=Number(s.date_created??0),f=String(s.last_updated_ts??"?"),l=await o(a),h=wn(await Gt(e,c,new Map));console.log(`id: ${s.id}`),console.log(`channel: ${l} (${a})`),console.log(`created: ${u?Wi(u):"?"}`),console.log(`updated: ${Wi(Number(f.split(".")[0]))}`),console.log(`status: ${s.is_sent===!0?"sent":"pending"}`),console.log("---"),console.log(h)}function He(...e){return wf(e.join(`
169
+ `)).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 Nf={"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[,i,s]=n;switch(s){case"missing_scope":return`Error: token lacks the ${Nf[i]??"the required"} scope (needed for ${i}). 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}}function ve(e,t,n){for(let i of n)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 gs(e){let t=Rt(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 i=e.slice(n+1);if(/^\d{10}\.\d{6}$/.test(i))return{ref:e.slice(0,n),ts:i};if(/^\d{4}-\d{2}-\d{2}T/.test(i))return{ref:e.slice(0,n),ts:Ki(i)}}}return{ref:e}}function Fn(e,t=!0){let n=Rt(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 i=e.indexOf(":");if(i>0){let s=e.slice(i+1);if(/^\d{10}\.\d{6}$/.test(s))return{ref:e.slice(0,i),threadTs:s};if(/^\d{4}-\d{2}-\d{2}T/.test(s))return{ref:e.slice(0,i),threadTs:Ki(s)}}return{ref:e}}async function ms(e,t,n,i){let s=n;if(/^#?[CDG][A-Z0-9]{8,}$/.test(n)||!n.startsWith("#")&&!n.startsWith("@"))try{let o=P(await mn(e,t,i)),a=P(o.channel);if(a.is_im===!0){let c=typeof a.user==="string"?a.user:"";s=c?`@${await ze(e,c,i)}`:t}else s=typeof a.name==="string"?`#${a.name}`:t}catch{s=t}return s===t?t:`${s} (${t})`}async function Vt(e,t){try{return await ja(e,t)}catch{return null}}function Nt(e,t){let n;return async()=>{if(n===void 0)n=await Vt(e,t);return n}}function Mc(e,t){let n=t?" [as bot]":"";if(!e)return`(unknown \u2014 auth.test failed)${n}`;let i=te(e.user||e.userId||"?"),s=e.userId?` (${e.userId})`:"",r=e.team?` \u2014 ${te(e.team)}`:"";return`@${i}${s}${r}${n}`}function je(e,t={}){return` ${"From:".padEnd(t.pad??6)}${Mc(e,t.asBot)}`}async function Ui(e,t,n=60,i){let s=typeof t.user==="string"?await ze(e,t.user,i):typeof t.username==="string"?t.username:"?",r=(typeof t.text==="string"?t.text:"").split(`
170
+ `)[0]??"",o=r.length>n?`${r.slice(0,n)}\u2026`:r,a=typeof t.ts==="string"?t.ts:"";return`${a?Ji(a).slice(0,16).replace("T"," "):""} @${s}${o?`: ${o}`:""}`}async function vf(e,t,n,i){let s=n.find((r)=>String(r.ts)===t)??n[0];if(!s)return t;return Ui(e,s,40,i)}function xc(e){return e.toLowerCase().replace(/<[@#!][^>]+>/g," ").replace(/[^\p{L}\p{N}\s]/gu," ").replace(/\s+/g," ").trim()}function jf(e,t){let n=xc(e),i=xc(t);if(!n||!i)return 0;if(n===i)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},r=s(n),o=s(i);if(r.size===0||o.size===0)return 0;let a=0;for(let[u,f]of r){let l=o.get(u);if(l)a+=Math.min(f,l)}let c=_c(r)+_c(o);return c===0?0:2*a/c}function _c(e){let t=0;for(let n of e.values())t+=n;return t}async function Lf(e,t){let n=Nt(e,t.cookie),{ref:i,ts:s}=gs(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 r;if(t.channelId)r=t.channelId;else r=await De(e,i,t.cookie);let o=await Ke(e,r,s,1,t.cookie),c=X(o.messages).map(P).find((m)=>String(m.ts)===s);if(!c)console.error(`Message not found at ts=${s} in channel ${r}`),process.exit(1);let u=typeof c.text==="string"?c.text:"",f=t.mentions?await Dc(e,t.newText,r,t.cookie?{cookie:t.cookie}:{}):t.newText,l=await n(),d=He(u,f,l?.userId??"");if(t.code!==d)ve(t.code,d,["--- Editing as -------------------------------",je(l),"--- Original message -------------------------",...u.split(`
171
+ `).map((m)=>` ${m}`),"--- Replacing with ---------------------------",...f.split(`
172
+ `).map((m)=>` ${m}`),"--------------------------------\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"]);let h=await Yt(e,r,s,f,t.cookie);console.log(`\u2713 Edited (ts: ${h})`)}async function Wf(e,t){let n=Nt(e,t.cookie),{ref:i,ts:s}=gs(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 r;if(t.channelId)r=t.channelId;else r=await De(e,i,t.cookie);let o=await Ke(e,r,s,1,t.cookie),c=X(o.messages).map(P).find((d)=>String(d.ts)===s);if(!c)console.error(`Message not found at ts=${s} in channel ${r}`),process.exit(1);let u=typeof c.text==="string"?c.text:"",f=await n(),l=He(r,s,u,f?.userId??"");if(t.code!==l){let d=await ms(e,r,i,t.cookie);ve(t.code,l,["--- Deleting message -------------------------",je(f),` \u2192 ${d} at ${Ji(s)}`,...u.split(`
173
+ `).map((h)=>` ${h}`),"---------------------------------------------"])}await Ya(e,r,s,t.cookie),console.log(`\u2713 Deleted (ts: ${s})`)}async function Uf(e,t){let{ref:n,ts:i}=gs(t.target);if(!i)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,""),r;if(t.channelId)r=t.channelId;else r=await De(e,n,t.cookie);if(t.remove)await fn(e,r,i,s,t.cookie),console.log(`\u2713 Removed :${s}: (ts: ${i})`);else await ct(e,r,i,s,t.cookie),console.log(`\u2713 Reacted :${s}: (ts: ${i})`)}async function Hi(e,t,n,i){if(!n||!t.startsWith("D"))return!1;try{let s=P(await mn(e,t,i)),r=P(s.channel);return r.is_im===!0&&r.user===n}catch{return!1}}async function Jf(e,t){let{ref:n,threadTs:i}=Fn(t.target),s=t.cookie,r=Nt(e,s),o;if(t.channelId)o=t.channelId;else if(t.userId)o=await Tt(e,t.userId,s);else o=await De(e,n,s);if(!t.asBot&&await Hi(e,o,(await r())?.userId,s))console.error(`Warning: "${t.target}" is a DM to yourself \u2014 Slack will NOT notify you of your own message.
174
+ `+` To reach yourself with a notification, send as the bot: slack send '${t.target}' '...' --as-bot`);let a=t.message,c=null;if(t.mentions){c=await Bt(t.mentionToken??e,t.message,o,t.mentionCookie),a=c.text;for(let C of yn(c.unresolved))console.error(`\u26A0 ${te(C)}`)}try{for(let C of await bc(t.mentionToken??e,a,t.mentionCookie))console.error(`\u26A0 possible untagged mention: ${te(C.surface)} \u2014 @${te(C.display)} won't be notified (did you mean <@${C.userId}>?)`)}catch{}let u=[];if(c&&(c.resolved.length>0||c.unresolved.length>0)){u.push("--- Mentions ---------------------------------");for(let C of c.resolved)u.push(` \u2713 ${te(C.surface)} \u2192 @${te(C.display)} (${C.userId}) \u2014 will notify`);for(let C of c.unresolved){let A=C.reason==="ambiguous"?"ambiguous":C.reason==="unavailable"?"lookup unavailable":"no match";u.push(` \u26A0 ${te(C.surface)} \u2014 plain text, NOT notified (${A})`)}}let f="",l="?",d=[],h,m,p;if(i)try{let C=await Ke(e,o,i,100,s);d=X(C.messages).map(P);let A=d[d.length-1];f=typeof A?.text==="string"?A.text:"",h=typeof A?.user==="string"?A.user:void 0,m=typeof A?.bot_id==="string"?A.bot_id:void 0,p=typeof A?.ts==="string"?A.ts:void 0}catch{}else try{let C=await Ze(e,o,1,void 0,void 0,s),A=X(C.messages).map(P),T=A.filter((L)=>L.subtype===void 0||L.subtype===null)[0];f=typeof T?.text==="string"?T.text:"",l=typeof T?.user==="string"?await ze(e,T.user,s):typeof T?.username==="string"?T.username:"?";let v=A[0];h=typeof v?.user==="string"?v.user:void 0,m=typeof v?.bot_id==="string"?v.bot_id:void 0,p=typeof v?.ts==="string"?v.ts:void 0}catch{}if(process.env.SLACK_UNREPLIED_WARN!=="0"&&p&&(h||m))try{let C=await r();if(!!C&&(!!h&&!!C.userId&&C.userId===h||!!m&&!!C.botId&&C.botId===m)){let T=`slack edit "#${o}:${p}" "<\u65B0\u3057\u3044\u672C\u6587>" --channel-id ${o}`;try{let v=await ln(e,o,p,s);if(v)T=`slack edit "${v}" "<\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(` ${T}`),console.error(" \u3053\u306E\u307E\u307E\u9001\u4FE1\u3059\u308B\u5834\u5408\u306F --code=XXXX \u3067\u78BA\u5B9A\u3002")}}catch{}if(i&&d.length){let C={sim:0,msg:null};for(let A of d){let T=typeof A.text==="string"?A.text:"";if(!T)continue;let v=jf(a,T);if(v>C.sim)C={sim:v,msg:A}}if(C.msg&&C.sim>=0.82){let A=Math.round(C.sim*100);console.error(`\u26A0 possible duplicate: ${A}% similar to an existing thread message \u2014 ${await Ui(e,C.msg,60,s)}`)}}let y=await r(),E=He(o,i??"",f,a,y?.userId??"");if(t.code!==E){let C=await ms(e,o,n,s),A=je(y,{asBot:t.asBot});if(i){let T=await vf(e,i,d,s),v=d.slice(-3),L=v.length?await Promise.all(v.map(async(R)=>` ${await Ui(e,R,60,s)}`)):[" (thread context unavailable)"];ve(t.code,E,["--- Recent messages in thread ----------------",...L,...u,"--- Sending ----------------------------------",A,` \u2192 ${C} thread of ${T} \u2014 THREAD REPLY`,` Message: ${a}`,"--------------------------------\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"])}else ve(t.code,E,["--- Last message in channel ------------------",` ${l}: ${f.split(`
175
+ `)[0]?.slice(0,100)??"(empty)"}`,...u,"--- Sending ----------------------------------",A,` \u2192 ${C} \u2014 NEW top-level message`,` Message: ${a}`,"--------------------------------\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"])}let F=await rs(e,o,a,i,t.broadcast,s),k="";try{k=await ln(e,o,F,s)}catch{}if(k)console.log(`\u2713 Sent: ${k}`);else console.log(`\u2713 Sent (ts: ${F})`);if(t.asBot&&o.startsWith("D"))try{let C=await oi(e);if(!C.ok)for(let A of ai(C,!0))console.error(A);else{let A=C.appId?`https://api.slack.com/apps/${C.appId}`:"https://api.slack.com/apps";console.error(`Note: if ${t.target} can't reply (app messaging may be off), enable Messages Tab: ${A} \u2192 App Home.`)}}catch{}}var Kf=2,Ce=3,zf=1.618033988749895,Hf=1000,qf=5000,Sc=8,Yf=(e)=>new Promise((t)=>setTimeout(t,e)),Xf=new Set(["thread_broadcast"]),Gf=/(?<![A-Za-z0-9._@<-])@(here|channel|everyone)(?![A-Za-z0-9._-])/giu;function ds(e){let t=new Set;return{text:e.replace(Gf,(i,s)=>{let r=s.toLowerCase();return t.add(r),`<!${r}>`}),kinds:t}}async function qi(e,t,n){if(!t.startsWith("D"))return;try{let i=P(await mn(e,t,n)),s=P(i.channel);return s.is_im===!0&&typeof s.user==="string"?s.user:void 0}catch{return}}async function Bc(e,t){let{channelId:n,ts:i,question:s,reactable:r,threadOnly:o,audience:a,broadcast:c,cookie:u,timeout:f,shown:l}=t,d=t.askerUserId,h=t.askerBotId,m=(L)=>typeof L==="string"&&!!L&&L!==d&&(c||a.has(L));function p(L){let R=X(L.reactions).map(P),G=[];for(let S=0;S<r.length;S++){let x=R.find((W)=>W.name===Me[S].name),O=x?X(x.users).filter(m):[];if(O.length)G.push({index:S,users:O})}return G}async function y(L,R){let G=typeof L.text==="string"?L.text:"";if(!G)return;let S=wi(G,R);if(S===G)return;try{await Yt(e,n,i,S,u,!0)}catch(x){console.error(` (\u8CEA\u554F\u6587\u306B\u6CE8\u610F\u66F8\u304D\u3092\u5165\u308C\u3089\u308C\u307E\u305B\u3093\u3067\u3057\u305F: ${x instanceof Error?x.message:String(x)})`)}}async function E(L){let R=p(L);if(R.length<=1&&yi(typeof L.text==="string"?L.text:"").length)await y(L,[]);if(!R.length)return null;if(R.length===1){let{index:x,users:O}=R[0];return{answer:r[x],how:`\u30EA\u30A2\u30AF\u30B7\u30E7\u30F3 ${Me[x].glyph}`,who:O[0]}}let G=R.map((x)=>Me[x.index].glyph).join(" / ");console.error(` (${G} \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 S=[...new Set(R.flatMap((x)=>x.users))].sort();return await y(L,S),null}function F(L,R=1/0){let G=[...L].sort((S,x)=>Number(S.ts)-Number(x.ts));for(let S of G){if(!(Number(S.ts)>Number(i)))continue;if(!m(S.user))continue;if(typeof S.subtype==="string"&&!Xf.has(S.subtype))continue;if(Number(S.ts)>=R)break;let x=typeof S.text==="string"?S.text.trim():"";if(x)return{answer:x,how:"\u8FD4\u4FE1",who:S.user}}return null}async function k(){if(t.threadParentTs){let S=P(await Ke(e,n,t.threadParentTs,100,u)),x=X(S.messages).map(P),O=x.find((W)=>W.ts===i);if(O){let W=await E(O);if(W)return W}return F(x)}let L=P(await Ze(e,n,30,i,void 0,u,!0)),R=X(L.messages).map(P),G=R.find((S)=>S.ts===i);if(G){let S=await E(G);if(S)return S}if(!o){let S=R.filter((O)=>Number(O.ts)>Number(i)&&(h&&O.bot_id===h||d&&O.user===d)).reduce((O,W)=>Math.min(O,Number(W.ts)),1/0),x=F(R,S);if(x)return x}if(G&&Number(G.reply_count)>0){let S=P(await Ke(e,n,i,30,u)),x=F(X(S.messages).map(P));if(x)return x}return null}async function C(L){for(let G=0;G<r.length;G++)try{await fn(e,n,i,Me[G].name,u)}catch{}let R="";if(L.who)try{R=await ze(e,L.who,u)}catch{R=L.who}if(R)console.error(` \u56DE\u7B54\u8005: ${te(R)}`);try{await Yt(e,n,i,_a(s,L,R),u,!0);try{await ct(e,n,i,bi,u),await fn(e,n,i,ts,u)}catch{}}catch(G){console.error(` (\u5143\u30E1\u30C3\u30BB\u30FC\u30B8\u306E\u66F4\u65B0\u306B\u5931\u6557: ${G instanceof Error?G.message:String(G)})`)}}let A=Date.now()+f*1000,T=0,v=Hf;for(;;){let L=null;try{L=await k(),T=0}catch(R){if(T++,T>=Sc)console.error(`Error: Slack \u3078\u306E\u554F\u3044\u5408\u308F\u305B\u306B ${T} \u56DE\u9023\u7D9A\u3067\u5931\u6557\u3057\u307E\u3057\u305F: ${R instanceof Error?R.message:String(R)}`),process.exit(Ce);console.error(` (Slack \u30A8\u30E9\u30FC ${T}/${Sc}, \u518D\u8A66\u884C\u3057\u307E\u3059: ${R instanceof Error?R.message:String(R)})`)}if(L)await C(L),console.log(L.answer),process.exit(0);if(Date.now()>=A)break;await Yf(Math.min(v,Math.max(0,A-Date.now()))),v=Math.min(v*zf,qf)}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: ${Nc(l,t.asBot)}`);process.exit(Kf)}function Nc(e,t){return`slack ask --waitFor='${e}'${t?" --as-bot":""}`}async function Vf(e,t){let{ref:n,threadTs:i}=Fn(t.target,!1),s=t.cookie,r=Nt(e,s),o;if(t.channelId)o=t.channelId;else if(t.userId)o=await Tt(e,t.userId,s);else o=await De(e,n,s);let a=(await r())?.userId??"",c=await qi(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.
176
+ `+` To reach yourself with a notification, ask as the bot: slack ask '${t.target}' '...' --as-bot`);let u=ds(t.question),f=ds(t.body??""),l=new Set([...u.kinds,...f.kinds]),d=t.mentionToken??e,h=await Bt(d,u.text,o,t.mentionCookie),m=f.text?await Bt(d,f.text,o,t.mentionCookie):{text:"",resolved:[],unresolved:[]},p=h.text,y=m.text,E=[...h.resolved,...m.resolved],F=[...h.unresolved,...m.unresolved];for(let J of yn(F))console.error(`\u26A0 ${te(J)}`);let k=l.size>0,C=new Set(E.map((J)=>J.userId).filter((J)=>J!==a)),A=new Map(E.map((J)=>[J.userId,J.display])),T;if(k)T=`anyone in ${n} (${[...l].map((J)=>`@${J}`).join(", ")})`;else{if(!C.size&&c&&c!==a)C.add(c),A.set(c,await ze(e,c,s));if(!C.size)console.error("Error: `ask` will not post a question nobody is addressed to \u2014 no one is tagged.\n"+(F.length?` (${F.map((J)=>te(J.surface)).join(", ")} matched no one, so it names nobody.)
177
+ `:"")+` Tag the person who should answer: slack ask '${t.target}' '@alice ${t.question}' ...
178
+ Or open it to the whole channel: slack ask '${t.target}' '@here ${t.question}' ...
179
+ (In a 1:1 DM the other person counts automatically.)`),process.exit(Ce);T=[...C].map((J)=>`@${te(A.get(J)??J)} (${J})`).join(", ")}let v=t.choices.slice(0,es),L=t.choices.slice(es),R=!o.startsWith("D")||!!i,G=xa(p,y,v,L,R),S="",x="?";try{let J=await Ze(e,o,1,void 0,void 0,s),ae=X(J.messages).map(P).filter((Oe)=>Oe.subtype===void 0||Oe.subtype===null)[0];S=typeof ae?.text==="string"?ae.text:"",x=typeof ae?.user==="string"?await ze(e,ae.user,s):typeof ae?.username==="string"?ae.username:"?"}catch{}let O=await r(),W=He(o,i??"",S,G,O?.userId??"");if(t.code!==W){let J=await ms(e,o,n,s),ae=v.length?["--- Choices (seeded as reactions) ------------",...v.map((Oe,z)=>` ${Me[z].glyph} ${Oe}`),...L.map((Oe,z)=>` (${z+11}) ${Oe} \u2014 text answer only`)]:["--- Choices ----------------------------------"," (none \u2014 free-text reply)"];ve(t.code,W,["--- Last message in channel ------------------",` ${x}: ${S.split(`
180
+ `)[0]?.slice(0,100)??"(empty)"}`,...ae,"--- Asking -----------------------------------",je(O,{asBot:t.asBot}),` \u2192 ${J}${i?" \u2014 THREAD REPLY":" \u2014 NEW top-level message"}`,` Question: ${p}`,` Answerable by: ${T}`,` Via: ${R?"reactions or thread replies":"reactions or replies in this DM"}`,"--------------------------------\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"])}let Z=await rs(e,o,G,i,!1,s,!0);try{await ct(e,o,Z,ts,s)}catch(J){console.error(` (marker ${ts} \u3092\u4ED8\u3051\u3089\u308C\u307E\u305B\u3093\u3067\u3057\u305F: ${J instanceof Error?J.message:String(J)})`)}for(let J=0;J<v.length;J++)try{await ct(e,o,Z,Me[J].name,s)}catch(ae){console.error(` (\u30EA\u30A2\u30AF\u30B7\u30E7\u30F3 ${Me[J].name} \u3092\u4ED8\u3051\u3089\u308C\u307E\u305B\u3093\u3067\u3057\u305F: ${ae instanceof Error?ae.message:String(ae)})`)}let re="";try{re=await ln(e,o,Z,s)}catch{}let Q=re||`${o}:${Z}`;if(console.error(`\u2713 Asked: ${Q}`),!t.wait){console.log(Nc(Q,!!t.asBot));return}let oe=t.timeout??3600;console.error(` \u56DE\u7B54\u3092\u5F85\u3063\u3066\u3044\u307E\u3059 (\u6700\u5927 ${oe}s)\u2026 Ctrl-C \u3067\u4E2D\u65AD`);let $e={channelId:o,ts:Z,question:p,reactable:v,threadOnly:R,audience:C,broadcast:k,askerUserId:O?.userId??"",askerBotId:O?.botId??"",timeout:oe,shown:Q,asBot:!!t.asBot};if(i)$e.threadParentTs=i;if(s)$e.cookie=s;await Bc(e,$e)}async function Zf(e,t){let n=Rt(t.link),i,s,r;if(n?.ts)i=n.channel,s=n.ts,r=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').
181
+ `+` Got: ${te(t.link)}`),process.exit(Ce);i=m[1],s=m[2]}let o;if(r){let m=P(await Ke(e,i,r,100,t.cookie));o=X(m.messages).map(P).find((p)=>p.ts===s)}else{let m=P(await Ze(e,i,1,s,void 0,t.cookie,!0));o=X(m.messages).map(P).find((p)=>p.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(Ce);let a=typeof o.text==="string"?o.text:"",c=Sa(a);if(c.kind==="other")console.error("Error: \u3053\u308C\u306F `slack ask` \u306E\u8CEA\u554F\u3067\u306F\u3042\u308A\u307E\u305B\u3093 (\u56DE\u7B54\u306E\u8AAD\u307F\u53D6\u308A\u65B9\u304C\u5206\u304B\u308A\u307E\u305B\u3093)\u3002\n"+` ${te(t.link)}`),process.exit(Ce);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 qi(e,i,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(Ce);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 h={channelId:i,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(r)h.threadParentTs=r;if(t.cookie)h.cookie=t.cookie;await Bc(e,h)}var Ne=3;function Qf(e){return`slack poll --results='${e}'`}async function ed(e,t){let{ref:n,threadTs:i}=Fn(t.target,!1),s=t.cookie,r=Nt(e,s),o;if(t.channelId)o=t.channelId;else if(t.userId)o=await Tt(e,t.userId,s);else o=await De(e,n,s);let a=(await r())?.userId??"",c=await qi(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.
182
+ `+` To reach yourself with a notification, post as the bot: slack poll '${t.target}' '...' --as-bot`);let u=ds(t.question),f=ds(t.body??""),l=t.mentionToken??e,d=await Bt(l,u.text,o,t.mentionCookie),h=f.text?await Bt(l,f.text,o,t.mentionCookie):{text:"",resolved:[],unresolved:[]},m=d.text,p=h.text;for(let S of yn([...d.unresolved,...h.unresolved]))console.error(`\u26A0 ${te(S)}`);let y=t.choices,E=!!t.multi,F=t.until??"",k=Pa(m,p,y,{multi:E,deadline:F}),C="",A="?";try{let S=await Ze(e,o,1,void 0,void 0,s),x=X(S.messages).map(P).filter((O)=>O.subtype===void 0||O.subtype===null)[0];C=typeof x?.text==="string"?x.text:"",A=typeof x?.user==="string"?await ze(e,x.user,s):typeof x?.username==="string"?x.username:"?"}catch{}let T=await r(),v=He(o,i??"",C,k,T?.userId??"");if(t.code!==v){let S=await ms(e,o,n,s);ve(t.code,v,["--- Last message in channel ------------------",` ${A}: ${C.split(`
183
+ `)[0]?.slice(0,100)??"(empty)"}`,"--- Ballot (seeded as reactions) -------------",...y.map((x,O)=>` ${Be[O].glyph} ${x}`),"--- Posting ----------------------------------",je(T,{asBot:t.asBot}),` \u2192 ${S}${i?" \u2014 THREAD REPLY":" \u2014 NEW top-level message"}`,` Question: ${m}`,` Rule: ${E?"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"])}let L=await rs(e,o,k,i,!1,s,!0);try{await ct(e,o,L,cn,s)}catch(S){console.error(` (marker ${cn} \u3092\u4ED8\u3051\u3089\u308C\u307E\u305B\u3093\u3067\u3057\u305F: ${S instanceof Error?S.message:String(S)})`)}for(let S=0;S<y.length;S++)try{await ct(e,o,L,Be[S].name,s)}catch(x){console.error(` (\u30EA\u30A2\u30AF\u30B7\u30E7\u30F3 ${Be[S].name} \u3092\u4ED8\u3051\u3089\u308C\u307E\u305B\u3093\u3067\u3057\u305F: ${x instanceof Error?x.message:String(x)})`)}let R="";try{R=await ln(e,o,L,s)}catch{}let G=R||`${o}:${L}`;console.error(`\u2713 Posted: ${G}`),console.log(Qf(G)),console.error(` \u7DE0\u3081\u5207\u308B: slack poll --close='${G}'${t.asBot?" --as-bot":""}`)}async function td(e,t,n){let i=Rt(t),s,r,o;if(i?.ts)s=i.channel,r=i.ts,o=i.threadTs&&i.threadTs!==i.ts?i.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').
184
+ `+` Got: ${te(t)}`),process.exit(Ne);s=c[1],r=c[2]}let a;if(o){let c=P(await Ke(e,s,o,100,n));a=X(c.messages).map(P).find((u)=>u.ts===r)}else{let c=P(await Ze(e,s,1,r,void 0,n,!0));a=X(c.messages).map(P).find((u)=>u.ts===r)}if(!a)console.error(`Error: \u305D\u306E\u30E1\u30C3\u30BB\u30FC\u30B8\u304C\u898B\u3064\u304B\u308A\u307E\u305B\u3093: ${te(t)}`),process.exit(Ne);return{channelId:s,ts:r,msg:a}}function kc(e){let t=Math.max(1,...e.map((n)=>n.count));return e.map((n,i)=>`${Be[i].glyph} ${String(n.count).padStart(3)} ${"\u2588".repeat(Math.round(n.count/t*20))}${n.count?" ":""}${n.choice}`)}async function nd(e,t){let{channelId:n,ts:i,msg:s}=await td(e,t.link,t.cookie),r=typeof s.text==="string"?s.text:"",o=Ra(r);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(Ne);if(o.kind==="closed"){console.error(`\u2713 \u6295\u7968\u7D42\u4E86: ${te(o.question)}`);for(let h of kc(o.tallies))console.log(h);return}let a=new Set;if(typeof s.user==="string"&&s.user)a.add(s.user);let c=await Xa(e,n,i,t.cookie),u=Ma(o.choices,c,a,o.multi);console.error(`${te(o.question)}${o.deadline?` (\u7DE0\u5207 ${o.deadline})`:""}`);for(let h of kc(u.tallies))console.log(h);let f=u.tallies.reduce((h,m)=>h+m.count,0);if(console.error(` \u8A08 ${f} \u7968${o.multi?" (\u8907\u6570\u9078\u629E\u53EF)":""}`),t.names)for(let h=0;h<u.voters.length;h++){if(!u.voters[h].length)continue;let m=await Promise.all(u.voters[h].map((p)=>ze(e,p,t.cookie)));console.error(` ${Be[h].glyph} ${m.map((p)=>`@${te(p)}`).join(", ")}`)}let l=o.multi?[]:u.ambiguous,d=wi(r,l);if(d!==r&&!t.noNotify)try{await Yt(t.writeToken??e,n,i,d,t.writeToken?t.writeCookie:t.cookie,!0)}catch(h){console.error(` (\u6295\u7968\u6587\u306B\u6CE8\u610F\u66F8\u304D\u3092\u5165\u308C\u3089\u308C\u307E\u305B\u3093\u3067\u3057\u305F: ${h instanceof Error?h.message:String(h)})
185
+ `+" \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 h=await Promise.all(u.ambiguous.map((m)=>ze(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): ${h.map((m)=>`@${te(m)}`).join(", ")}`)}if(!t.close)return;await Yt(t.writeToken??e,n,i,Ta(o.question,u.tallies),t.writeToken?t.writeCookie:t.cookie,!0);try{await ct(t.writeToken??e,n,i,Si,t.writeToken?t.writeCookie:t.cookie),await fn(t.writeToken??e,n,i,cn,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 sd(e){let t=await oi(e);for(let n of ai(t,!1))console.log(n);if(!t.ok)process.exit(1)}function id(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 od(e,t){let n=Nt(e,t.cookie),{ref:i,threadTs:s}=Fn(t.target),r;if(t.channelId)r=t.channelId;else if(t.userId)r=await Tt(e,t.userId,t.cookie);else r=await De(e,i,t.cookie);let o=id(t.at),a=new Date(o*1000).toISOString(),c=await n();if(await Hi(e,r,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=He(r,t.message,String(o),c?.userId??"");if(t.code!==u)ve(t.code,u,["--- Scheduling message -----------------------",je(c,{pad:9}),` To: ${i}${s?` (thread ${s})`:""}`,` At: ${rd(o)}`,` Message: ${t.message}`,"---------------------------------------------"]);let f=await za(e,r,t.message,o,s,t.cookie);console.log(`\u2713 Scheduled (id: ${f}, at: ${a})`)}async function ad(e,t,n,i){let s;if(n)s=n;else if(t)s=await De(e,t,i);let o=(await Ha(e,s,i)).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(`
186
+ `)[0]?.slice(0,80)??""}`)}}async function cd(e,t){let n;if(t.channelId)n=t.channelId;else n=await De(e,t.target,t.cookie);let i=await Vt(e,t.cookie),s=He(n,t.id,i?.userId??"");if(t.code!==s)ve(t.code,s,["--- Deleting scheduled message ---------------",je(i,{pad:9}),` Channel: ${t.target}`,` ID: ${t.id}`,"---------------------------------------------"]);await qa(e,n,t.id,t.cookie),console.log(`\u2713 Deleted scheduled message ${t.id}`)}async function ud(e,t){let n=Nt(e,t.cookie),{statSync:i,existsSync:s}=await import("fs"),{basename:r}=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}=Fn(t.target),c;if(t.channelId)c=t.channelId;else if(t.userId)c=await Tt(e,t.userId,t.cookie);else c=await De(e,o,t.cookie);if(await Hi(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 p=r(m),y=u?p:t.title??p;return{fp:m,filename:p,title:y,sizeFmt:hs(i(m).size)}}),l=await n(),d=He(c,...f.flatMap((m)=>[m.fp,m.title]),l?.userId??"");if(t.code!==d){let m=` To: ${o}${a?` (thread ${a})`:""}`,p=u?[`--- Uploading ${f.length} files ------------------------`,je(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 ---------------------------",je(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"];ve(t.code,d,p)}let h=f.length;for(let m=0;m<h;m++){let p=f[m],y={title:p.title};if(a!==void 0)y.threadTs=a;if(t.comment!==void 0&&m===0)y.initialComment=t.comment;let{fileId:E,permalink:F}=await sc(e,c,p.fp,y,t.cookie),k=h>1?`[${m+1}/${h}] `:"";console.log(`${k}\u2713 Uploaded (file_id: ${E}${F?`, url: ${F}`:""})`)}}async function ld(e,t,n){let i=n.channel?await De(e,n.channel,t):void 0,s=[],r=1,o=1;do{let c={page:r,count:200};if(n.types)c.types=n.types;if(i)c.channel=i;if(n.user)c.user=n.user;let u=P(await Wa(e,c,t));for(let f of X(u.files))s.push(P(f));o=Number(P(u.paging).pages??1),r++}while(s.length<n.limit&&r<=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"?hs(c.size):"";console.log(`${u} ${l.padEnd(7)} ${d.padStart(9)} ${f}`)}}function fd(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 dd(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(P(n).text??P(n).name??P(n).value??"")).filter(Boolean).join(", ");for(let n of["rich_text","select","user","date","number","checkbox","email","phone"]){let i=e[n];if(i!=null)return typeof i==="object"?JSON.stringify(i):String(i)}return""}async function pd(e,t,n,i){let s=fd(n);if(!s)throw Error(`Not a list ID or list URL: ${n}
187
+ `+"Expected F\u2026 or https://<ws>.slack.com/lists/<TEAM>/<F-id>");let r=[],o;do{let c={limit:200};if(o)c.cursor=o;let u=P(await Ua(e,s,c,t));for(let l of X(u.items??u.records))r.push(P(l));let f=P(u.response_metadata).next_cursor;o=typeof f==="string"&&f?f:void 0}while(o&&r.length<i.limit);let a=r.slice(0,i.limit);if(i.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(P).map((l)=>{let d=String(l.key??l.column_id??"?"),h=dd(l);return h?`${d}=${h}`:""}).filter(Boolean);console.log(`${u} ${f.join(" | ")}`)}}function hd(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 gd(e,t,n,i){let s=hd(n);if(!s)throw Error(`Not a file ID or file permalink: ${n}
188
+ `+"Expected F\u2026 or https://<ws>.slack.com/files/<UID>/<FID>/<name>");let r=P(await La(e,s,t)),o=P(r.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:h}=await import("fs"),{basename:m}=await import("path"),p=i??a;if(i&&h(i)&&d(i).isDirectory())p=ft(i,m(a));$c(p,l),console.log(`\u2713 Downloaded ${a} (${hs(l.length)}) \u2192 ${p}`)}async function md(){yf();let e=(s)=>ei(s.workspace),t=(s)=>No(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}},i=async(s,r)=>{let o={state:s.state??"open",mine:r||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 $f(e(s),o)};await Oo(Is(process.argv)).scriptName("slack").showHelpOnFail(!1).fail((s,r,o)=>{if(r)console.error(r.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 r=String((s._??[])[0]??"");if(!r||r==="auth"||r==="login")return;try{ei(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:
189
+ `),await Vn(),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 r=e(s),o=s.json?"jsonl":s.format;if(s.target)await Ef(r,s.target,s.limit,o,s.unreplied,t(s));else await _f(r)}).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 r=s.json?"jsonl":s.format;await xf(e(s),s.target,s.ts,s.limit,r,t(s))}).command(["channel","channels","ch"],"Channel commands",(s)=>s.command(["ls","list"],"List channels",(r)=>r.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(r)=>{await kf(e(r),r.limit,r.filter,r.all,r.json?"jsonl":r.format)}).command("get <channel>","Show channel details",(r)=>r.positional("channel",{type:"string",demandOption:!0,describe:"#name or channel ID"}),async(r)=>{let o=e(r),a=t(r),c=r.channel,u=c.startsWith("#")||c.startsWith("@")||c.startsWith("C")||c.startsWith("G")||c.startsWith("D")?c:`#${c}`,f=await De(o,u,a),l=P(await mn(o,f,a)),d=P(l.channel),h=typeof d.name==="string"?d.name:f,p=d.is_im===!0?"@":"#",y=String(P(d.purpose).value??""),E=String(P(d.topic).value??""),F=d.num_members??d.member_count??"";if(console.log(`${p}${h} ${f}`),E)console.log(`topic: ${E}`);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)",(r)=>r.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(r)=>{let o=e(r),a=t(r),c=r.name.replace(/^#/,"").toLowerCase(),u=r.private===!0,f=r.invite.filter(Boolean),l=await Vt(o,a),d=He(c,String(u),f.join(","),l?.userId??"");if(r.code!==d)ve(r.code,d,["--- Creating channel -------------------------",je(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 h;try{h=await Ga(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 ":"#"}${h.name} (${h.id})`),f.length){let m=[];for(let p of f)try{m.push(p.startsWith("U")||p.startsWith("W")?p:await pn(o,p,a))}catch(y){console.error(` ! could not resolve ${p}: ${y instanceof Error?y.message:String(y)}`)}for(let p of m)try{let y=P(await os(o,p,a)),E=P(y.user);if(E.is_ultra_restricted===!0)console.error(`\u26A0 ${p} 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(E.is_restricted===!0)console.error(`\u26A0 ${p} 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 Va(o,h.id,m,a),console.log(`\u2713 Invited ${m.length} member${m.length===1?"":"s"}`)}catch(p){console.error(` ! invite failed: ${p instanceof Error?p.message:String(p)}`)}}}).demandCommand(1,"").showHelpOnFail(!0)).command(["user","usr"],"User commands",(s)=>s.command(["ls","list"],"List workspace members",(r)=>r.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(r)=>{let o=r.json?"jsonl":r.format,a=e(r),c=t(r),u=await $i(a,c),f=r.filter?.toLowerCase(),l=X(u.members).map(P);if(r.external){let p=new Set(l.map((k)=>String(k.id))),y=P(await dn(a,c)),E=X(y.channels).map(P).filter((k)=>k.is_ext_shared===!0&&!!k.name),F=new Set;for(let k of E)try{for(let C of await Za(a,String(k.id),c))if(!p.has(C))F.add(C)}catch{}for(let k of F)try{let C=P(await os(a,k,c)),A=P(C.user);if(A.id)l.push(A)}catch{}}let d=l.filter((p)=>p.deleted!==!0&&p.is_bot!==!0&&String(p.id)!=="USLACKBOT").filter((p)=>{if(!f)return!0;let y=String(p.name??"").toLowerCase(),E=String(P(p.profile).real_name??"").toLowerCase(),F=String(P(p.profile).email??"").toLowerCase();return y.includes(f)||E.includes(f)||F.includes(f)}).slice(0,r.limit);if(o==="jsonl"){for(let p of d)console.log(JSON.stringify(p));return}if(o==="yaml"){for(let p of d){let y=function(E,F=""){if(E===null)return"null";if(typeof E==="string")return E.includes(`
176
190
  `)?`|
177
- ${V.split(`
191
+ ${E.split(`
178
192
  `).join(`
179
- `)}`:V;if(typeof V!=="object")return String(V);if(Array.isArray(V))return V.map((W)=>`
180
- ${H} - ${X(W,H+" ")}`).join("");return Object.entries(V).map(([W,j])=>`
181
- ${H} ${W}: ${X(j,H+" ")}`).join("")};console.log("---");for(let[V,H]of Object.entries(G))console.log(`${V}: ${X(H)}`)}return}let Q=Intl.DateTimeFormat().resolvedOptions().timeZone;for(let G of J){let X=w(G.profile),V=String(G.name??G.id),H=String(G.id??""),W=String(X.display_name||""),j=String(X.real_name||""),N=String(X.email||""),O=String(G.tz??""),M=[...new Set([W,j].filter((y)=>y&&y!==V))].join(" / "),I=[N,O&&O!==Q?O:""].filter(Boolean).join(" ");console.log(`@${V} ${H} ${M}${I?" "+I:""}`)}}).command("get <user>","Show user details",(C)=>C.positional("user",{type:"string",demandOption:!0,describe:"@handle or user ID"}),async(C)=>{let $=D(C),z=C.user.startsWith("@")?C.user.slice(1):C.user,Z=z;if(!/^U[A-Z0-9]+$/.test(z)){let I=await $2($),y=o(I.members).map(w).find((l)=>String(l.name??"")===z);if(!y)console.error(`User not found: @${z}`),process.exit(1);Z=String(y.id)}let J=w(await z2($,Z)),Q=w(J.user),G=w(Q.profile),X=Intl.DateTimeFormat().resolvedOptions().timeZone,V=String(Q.name??Z),H=String(Q.id??Z),W=String(G.display_name||""),j=String(G.real_name||""),N=String(G.email||""),O=String(Q.tz??""),T=String(G.phone||""),M=String(G.title||"");console.log(`@${V} ${H}`);let R=[...new Set([W,j].filter((I)=>I&&I!==V))];if(R.length)console.log(`name: ${R.join(" / ")}`);if(N)console.log(`email: ${N}`);if(T)console.log(`phone: ${T}`);if(M)console.log(`title: ${M}`);if(O&&O!==X)console.log(`tz: ${O}`)}).demandCommand(1,"").showHelpOnFail(!0)).command("news","Activity feed (mentions to you)",(E)=>E.option("limit",{alias:"l",type:"number",default:20}),async(E)=>{await g9(D(E),E.limit)}).command("search <query>","Full-text search",(E)=>E.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(E)=>{await s3(D(E),E.query,E.count,E.json,F(E))}).command("send <target> <message>","Send a message (confirm-hash safety gate)",(E)=>E.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(E)=>{let C={target:E.target,message:E.message};if(E.code)C.code=E.code;if(E["channel-id"])C.channelId=E["channel-id"];if(E["user-id"])C.userId=E["user-id"];if(E.broadcast)C.broadcast=!0;if(E.mentions!==!1){C.mentions=!0,C.mentionToken=D(E);let z=F(E);if(z)C.mentionCookie=z}let $;if(E["as-bot"]){let z=sF();if(!z)console.error(`Error: --as-bot needs a bot token, but no xoxb- token was found.
182
- Set SLACK_BOT_TOKEN=xoxb-... in ~/.config/slack-cli/.env (or your shell).`),process.exit(1);if(!C.channelId&&!C.userId&&C.target.startsWith("@"))try{C.userId=await d0(D(E),C.target,F(E))}catch(Z){console.error(`Error: could not resolve ${C.target} to a user for the bot DM.
183
- ${Z instanceof Error?Z.message:String(Z)}
184
- Tip: pass --user-id <Uxxxx> to skip the lookup.`),process.exit(1)}$=z,C.asBot=!0}else{$=D(E);let z=F(E);if(z)C.cookie=z}try{await B4($,C)}catch(z){console.error(RF(z)),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)",(E)=>E.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(E)=>{let C=E.waitFor?String(E.waitFor):"",$=Number(E.timeout);if(!Number.isFinite($)||$<0||$===0&&!C)console.error("Error: --timeout must be a positive number of seconds"),process.exit(OD);if(C){if(E.target||E.question||E.choices?.length)console.error("Error: --waitFor collects an existing question \u2014 do not also pass a target/question/choices."),process.exit(OD);let G,X;if(E["as-bot"]){let V=sF();if(!V)console.error(`Error: --as-bot needs a bot token, but no xoxb- token was found.
185
- Set SLACK_BOT_TOKEN=xoxb-... in ~/.config/slack-cli/.env (or your shell).`),process.exit(OD);G=V}else G=D(E),X=F(E);try{let V={link:C,timeout:$,asBot:!!E["as-bot"]};if(X)V.cookie=X;await Y4(G,V)}catch(V){console.error(RF(V)),process.exit(OD)}return}if(!E.target)console.error("Error: target is required (or use --waitFor <permalink> to collect an answer)"),process.exit(OD);let z=String(E.question??"").trim();if(!z)console.error("Error: question is empty"),process.exit(OD);let Z={target:E.target,question:z,choices:(E.choices??[]).map((G)=>String(G).trim()).filter(Boolean),timeout:$};if(E.code)Z.code=E.code;if(E.body)Z.body=E.body;if(E.wait)Z.wait=!0;if(E["channel-id"])Z.channelId=E["channel-id"];if(E["user-id"])Z.userId=E["user-id"];Z.mentionToken=D(E);let J=F(E);if(J)Z.mentionCookie=J;let Q;if(E["as-bot"]){let G=sF();if(!G)console.error(`Error: --as-bot needs a bot token, but no xoxb- token was found.
186
- Set SLACK_BOT_TOKEN=xoxb-... in ~/.config/slack-cli/.env (or your shell).`),process.exit(OD);if(!Z.channelId&&!Z.userId&&Z.target.startsWith("@"))try{Z.userId=await d0(D(E),Z.target,F(E))}catch(X){console.error(`Error: could not resolve ${Z.target} to a user for the bot DM.
187
- ${X instanceof Error?X.message:String(X)}
188
- Tip: pass --user-id <Uxxxx> to skip the lookup.`),process.exit(OD)}Q=G,Z.asBot=!0}else{Q=D(E);let G=F(E);if(G)Z.cookie=G}try{await X4(Q,Z)}catch(G){console.error(RF(G)),process.exit(OD)}}).command("doctor","Check the bot token (xoxb) can carry a two-way DM (scopes + Messages Tab)",(E)=>E,async()=>{let E=sF();if(!E)console.error(`Error: slack doctor checks the bot token, but no xoxb- token was found.
189
- Set SLACK_BOT_TOKEN=xoxb-... in ~/.config/slack-cli/.env (or your shell).`),process.exit(1);await W4(E)}).command("schedule","Manage scheduled messages",(E)=>E.command("send <target> <message>","Schedule a message for later delivery",(C)=>C.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(C)=>{let $={target:C.target,message:C.message,at:C.at};if(C.code)$.code=C.code;if(C["channel-id"])$.channelId=C["channel-id"];if(C["user-id"])$.userId=C["user-id"];let z=F(C);if(z)$.cookie=z;await q4(D(C),$)}).command(["ls","list"],"List pending scheduled messages",(C)=>C.positional("target",{type:"string",describe:"#channel to filter by"}).option("channel-id",{type:"string",describe:"Raw channel ID"}),async(C)=>{await j4(D(C),C.target,C["channel-id"],F(C))}).command("rm <target> <id>","Delete a scheduled message",(C)=>C.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(C)=>{let $={target:C.target,id:C.id};if(C.code)$.code=C.code;let z=F(C);if(z)$.cookie=z;if(C["channel-id"])$.channelId=C["channel-id"];await U4(D(C),$)}).demandCommand(1,"").showHelpOnFail(!0),()=>{}).command("edit <target> <newText>","Edit a sent message",(E)=>E.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(E)=>{let C={target:E.target,newText:E.newText};if(E.code)C.code=E.code;if(E["channel-id"])C.channelId=E["channel-id"];if(E.mentions!==!1)C.mentions=!0;let $=F(E);if($)C.cookie=$;await F4(D(E),C)}).command("delete <target>","Delete a sent message (confirm-hash safety gate)",(E)=>E.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(E)=>{let C={target:E.target};if(E.code)C.code=E.code;if(E["channel-id"])C.channelId=E["channel-id"];let $=F(E);if($)C.cookie=$;await u4(D(E),C)}).command("react <target> <emoji>","Add (or --remove) an emoji reaction \u2014 a lightweight ack that doesn't grow the thread",(E)=>E.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(E)=>{let C={target:E.target,emoji:E.emoji};if(E.remove)C.remove=!0;if(E["channel-id"])C.channelId=E["channel-id"];let $=F(E);if($)C.cookie=$;try{await E4(D(E),C)}catch(z){console.error(RF(z)),process.exit(1)}}).command("todo","Reaction-backed task tracking (:pushpin: marks a task, progress lives in a second reaction)",(E)=>E.option("cache",{type:"boolean",default:!0,describe:"Use ~/.config/slack-cli/cache.json for channel/user lookups (--no-cache to bypass)"}).middleware((C)=>{if(C.cache===!1)V2(!1)}).command(["ls","list"],"List everyone's tasks (has: \u2014 read-only, one search per run)",(C)=>C.options(u).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(C)=>{await B(C,!1)}).command("set <target> <state>","Move a task to a progress state (adds the new reaction before removing the old one)",(C)=>C.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(C)=>{let $={target:C.target,state:C.state};if(C["channel-id"])$.channelId=C["channel-id"];let z=F(C);if(z)$.cookie=z;try{await i9(D(C),$)}catch(Z){console.error(RF(Z)),process.exit(1)}}).command("flag <target> <flag>","Add (or --remove) a reason flag (alert | needs-discussion | waiting | blocked) \u2014 flags stack, independent of progress",(C)=>C.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(C)=>{let $={target:C.target,flag:C.flag};if(C.remove)$.remove=!0;if(C["channel-id"])$.channelId=C["channel-id"];let z=F(C);if(z)$.cookie=z;try{await l9(D(C),$)}catch(Z){console.error(RF(Z)),process.exit(1)}}).command("doctor","Find messages carrying two or more progress reactions (--fix repairs them)",(C)=>C.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:W2,describe:"Max messages to scan"}).option("channel-id",{type:"string",describe:"Raw channel ID"}),async(C)=>{let $={channel:C.in,limit:C.limit};if(C.fix)$.fix=!0;if(C["channel-id"])$.channelId=C["channel-id"];let z=F(C);if(z)$.cookie=z;await n9(D(C),$)}).demandCommand(1,"Specify a todo subcommand (ls, set, flag, doctor)"),()=>{}).command("mytodo","Tasks carrying YOUR reactions (hasmy:) \u2014 the my-only half of `todo`",(E)=>E.option("cache",{type:"boolean",default:!0,describe:"Use ~/.config/slack-cli/cache.json for channel/user lookups (--no-cache to bypass)"}).middleware((C)=>{if(C.cache===!1)V2(!1)}).command(["ls","list"],"List tasks you have reacted to (hasmy: \u2014 read-only, one search per run)",(C)=>C.options(u),async(C)=>{await B(C,!0)}).demandCommand(1,"Specify a mytodo subcommand (ls)"),()=>{}).command("upload <target> <file..>","Upload one or more files to a channel or DM",(E)=>E.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(E)=>{let C={target:E.target,filePaths:E.file};if(E.title)C.title=E.title;if(E.comment)C.comment=E.comment;if(E.code)C.code=E.code;if(E["channel-id"])C.channelId=E["channel-id"];if(E["user-id"])C.userId=E["user-id"];let $=F(E);if($)C.cookie=$;await K4(D(E),C)}).command("files","File commands",(E)=>E.command(["ls","list"],"List files visible to you (files.list)",(C)=>C.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(C)=>{let $={limit:C.limit,format:C.json?"jsonl":C.format};if(C.type)$.types=C.type;if(C.channel)$.channel=C.channel;if(C.user)$.user=C.user;await O4(D(C),F(C),$)}).demandCommand(1,"").showHelpOnFail(!0),()=>{}).command("lists <ref>","Read a Slack List's rows (by list URL or F-id) \u2014 read-only",(E)=>E.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(E)=>{let C=E.json?"jsonl":E.format;try{await N4(D(E),F(E),E.ref,{limit:E.limit,format:C})}catch($){console.error(RF($)),process.exit(1)}}).command("download <ref> [dest]","Download a file attachment (by file ID or file permalink) to disk",(E)=>E.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(E)=>{await A4(D(E),F(E),E.ref,E.dest)}).command("dump","Bulk export channel history as markdown",(E)=>E.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(E)=>{await t9(D(E),E.days,E.limit,E.filter)}).command("drafts","Manage message drafts (requires xoxc desktop token)",(E)=>E.command(["$0","ls","list"],"List pending drafts",(C)=>C.option("all",{alias:"a",type:"boolean",default:!1,describe:"Include sent drafts"}),async(C)=>{await s9(D(C),F(C),C.all)}).command(["new <channel> [text..]","save <channel> [text..]"],"Create a draft",(C)=>C.positional("channel",{type:"string",demandOption:!0}).positional("text",{type:"string",array:!0,default:[]}),async(C)=>{let $=D(C),z=F(C),Z=C.text.join(" ");if(!Z)console.error("Usage: slack drafts new <#channel|@user> <text>"),process.exit(2);let J=await qD($,C.channel,z),Q=await q3($,J,Z,z);console.log(`\u2713 Draft created (id: ${w(Q.draft).id??"?"})`)}).command("get <id>","Show a draft",(C)=>C.positional("id",{type:"string",demandOption:!0}),async(C)=>{await r9(D(C),F(C),C.id)}).command(["edit <id> [text..]","update <id> [text..]"],"Edit a draft",(C)=>C.positional("id",{type:"string",demandOption:!0}).positional("text",{type:"string",array:!0,default:[]}).option("code",{type:"string"}),async(C)=>{let $=D(C),z=F(C),Z=C.text.join(" ");if(!Z)console.error("Usage: slack drafts edit <id> <new-text>"),process.exit(2);let J=await u0($,z),Q=o(J.drafts).map(w).find((W)=>String(W.id)===C.id);if(!Q)console.error(`Draft not found: ${C.id}`),process.exit(1);let G=s0(Q),X=await cF($,z),V=nD(G,Z,X?.userId??"");if(C.code!==V)pD(C.code,V,["--- Editing draft as -------------------------",mD(X),"--- Current draft ----------------------------",...G.split(`
190
- `).map((W)=>` ${W}`),"--- Replacing with ---------------------------",...Z.split(`
191
- `).map((W)=>` ${W}`),"--------------------------------\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"]);let H=await j3($,C.id,_2(Q),Z,z);console.log(`\u2713 Draft updated (id: ${w(H.draft).id??"?"})`)}).command(["delete <id>","rm <id>"],"Delete a draft",(C)=>C.positional("id",{type:"string",demandOption:!0}).option("code",{type:"string"}),async(C)=>{let $=D(C),z=F(C),Z=await u0($,z),J=o(Z.drafts).map(w).find((V)=>String(V.id)===C.id);if(!J)console.error(`Draft not found: ${C.id}`),process.exit(1);let Q=s0(J),G=await cF($,z),X=nD(C.id,Q,G?.userId??"");if(C.code!==X)pD(C.code,X,["\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",mD(G),` id: ${C.id}`,...Q.split(`
192
- `).map((V)=>` ${V}`),"--------------------------------\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"]);await K3($,C.id,z),console.log(`\u2713 Draft deleted (id: ${C.id})`)})).command("auth","Authentication and workspace management",(E)=>E.command("token","Add a workspace \u2014 paste an existing xoxp-/xoxb- token",(C)=>C.option("token",{type:"string",describe:"Token to save directly (non-interactive)"}).option("name",{type:"string",describe:"Workspace name (used with --token)"}),async(C)=>{await d1({...C.token!==void 0?{token:C.token}:{},...C.name!==void 0?{name:C.name}:{}})}).command("app","Create a new Slack app and obtain a token (guided wizard)",(C)=>C.option("bot",{type:"boolean",describe:"Create a bot token (xoxb-) instead of user (xoxp-)"}),async(C)=>{await i1({...C.bot!==void 0?{bot:C.bot}:{}})}).command("login","Interactive auth wizard (all auth methods: desktop app, token, new app)",(C)=>C.option("token",{type:"string",describe:"Token to save directly (non-interactive)"}).option("name",{type:"string",describe:"Workspace name (used with --token)"}),async(C)=>{await v0({...C.token!==void 0?{token:C.token}:{},...C.name!==void 0?{name:C.name}:{}})}).command(["ls","status"],"Show auth status",()=>{},()=>{let C=vu();if(C.length===0){console.log("No workspaces configured. Run: slack auth login");return}for(let{name:$,profile:z,current:Z}of C)console.log(`${Z?"* ":" "}${$} ${z.team} (${z.user}) ${z.url??""}`)}).command("use <name>","Switch active workspace",(C)=>C.positional("name",{type:"string",demandOption:!0}).option("g",{type:"boolean",default:!1,describe:"Write global lockfile (~/.slack-cli/workspace)"}),(C)=>{if(!C.g)x9($F(process.cwd(),".slack-cli"));Y1(C.name,C.g),console.log(`Switched to workspace "${C.name}" ${C.g?"globally":"locally"}`)}).command(["logout <name>","rm <name>","remove <name>"],"Remove a workspace",(C)=>C.positional("name",{type:"string",demandOption:!0}),(C)=>{X1(C.name),console.log(`Removed workspace "${C.name}"`)}).command(["chrome","cookie"],"Attach Chrome browser xoxd cookie to a workspace (macOS, interactive)",(C)=>C.option("workspace",{type:"string",alias:"w",describe:"Workspace name to update (default: active)"}),async(C)=>{await c1({...C.workspace!==void 0?{workspace:C.workspace}:{}})}).command("firefox","Attach Firefox browser xoxd cookie to a workspace (all platforms)",(C)=>C.option("workspace",{type:"string",alias:"w",describe:"Workspace name to update (default: active)"}),async(C)=>{await k1({...C.workspace!==void 0?{workspace:C.workspace}:{}})}).command("$0",!1,()=>{},()=>{E.showHelp(),process.exit(0)})).command("tail [target]","Stream new messages in real time (like tail -f)",(E)=>E.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(E)=>{let C=D(E),$=F(E),z=new AbortController;process.on("SIGINT",()=>{z.abort(),process.exit(0)}),await a1(C,E.target,{...E.since!==void 0?{since:E.since}:{},...E.thread!==void 0?{thread:E.thread}:{},...E["watch-thread"]!==void 0?{watchThread:E["watch-thread"]}:{},me:E.me,interval:E.interval,...E.timeout!==void 0?{timeout:E.timeout}:{},...E["exit-on-message"]===!0?{exitOnMessage:!0}:{},...$!==void 0?{cookie:$}:{},...E.rtm===!1?{noRtm:!0}:{}},z.signal)}).command("login",!1,(E)=>E.option("token",{type:"string"}).option("name",{type:"string"}),async(E)=>{await v0({...E.token!==void 0?{token:E.token}:{},...E.name!==void 0?{name:E.name}:{}})}).demandCommand(1,"Specify a command. Run with --help for usage.").strict().help().alias("help","h").parseAsync()}P4().catch((D)=>{console.error(D instanceof Error?D.message:String(D)),process.exit(1)});
193
+ `)}`:E;if(typeof E!=="object")return String(E);if(Array.isArray(E))return E.map((k)=>`
194
+ ${F} - ${y(k,F+" ")}`).join("");return Object.entries(E).map(([k,C])=>`
195
+ ${F} ${k}: ${y(C,F+" ")}`).join("")};console.log("---");for(let[E,F]of Object.entries(p))console.log(`${E}: ${y(F)}`)}return}let h=Intl.DateTimeFormat().resolvedOptions().timeZone,m=d.length?String(P(X(u.members).map(P)[0]??{}).team_id??""):"";for(let p of d){let y=P(p.profile),E=String(p.name??p.id),F=String(p.id??""),k=String(y.display_name||""),C=String(y.real_name||""),A=String(y.email||""),T=String(p.tz??""),L=[...new Set([k,C].filter((O)=>O&&O!==E))].join(" / "),R=T&&T!==h?T:"",G=String(p.team_id??""),S=p.is_stranger===!0||m&&G&&G!==m?`external:${G||"?"}`:p.is_ultra_restricted===!0?"single-channel guest":p.is_restricted===!0?"guest":"",x=[A,R].filter(Boolean).join(" ");console.log(`@${E} ${F} ${L}${x?" "+x:""}${S?` [${S}]`:""}`)}}).command("get <user>","Show user details",(r)=>r.positional("user",{type:"string",demandOption:!0,describe:"@handle or user ID"}),async(r)=>{let o=e(r),a=r.user.startsWith("@")?r.user.slice(1):r.user,c=a;if(!/^U[A-Z0-9]+$/.test(a)){let T=await $i(o,t(r)),v=X(T.members).map(P).find((L)=>String(L.name??"")===a);if(!v)console.error(`User not found: @${a}`),process.exit(1);c=String(v.id)}let u=P(await os(o,c)),f=P(u.user),l=P(f.profile),d=Intl.DateTimeFormat().resolvedOptions().timeZone,h=String(f.name??c),m=String(f.id??c),p=String(l.display_name||""),y=String(l.real_name||""),E=String(l.email||""),F=String(f.tz??""),k=String(l.phone||""),C=String(l.title||"");console.log(`@${h} ${m}`);let A=[...new Set([p,y].filter((T)=>T&&T!==h))];if(A.length)console.log(`name: ${A.join(" / ")}`);if(E)console.log(`email: ${E}`);if(k)console.log(`phone: ${k}`);if(C)console.log(`title: ${C}`);if(F&&F!==d)console.log(`tz: ${F}`)}).demandCommand(1,"").showHelpOnFail(!0)).command("news","Activity feed (mentions to you)",(s)=>s.option("limit",{alias:"l",type:"number",default:20}),async(s)=>{await Sf(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 Pc(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 r={target:s.target,message:s.message};if(s.code)r.code=s.code;if(s["channel-id"])r.channelId=s["channel-id"];if(s["user-id"])r.userId=s["user-id"];if(s.broadcast)r.broadcast=!0;if(s.mentions!==!1){r.mentions=!0,r.mentionToken=e(s);let a=t(s);if(a)r.mentionCookie=a}let o;if(s["as-bot"]){let a=Kt();if(!a)console.error(`Error: --as-bot needs a bot token, but no xoxb- token was found.
196
+ Set SLACK_BOT_TOKEN=xoxb-... in ~/.config/slack-cli/.env (or your shell).`),process.exit(1);if(!r.channelId&&!r.userId&&r.target.startsWith("@"))try{r.userId=await pn(e(s),r.target,t(s))}catch(c){console.error(`Error: could not resolve ${r.target} to a user for the bot DM.
197
+ ${c instanceof Error?c.message:String(c)}
198
+ Tip: pass --user-id <Uxxxx> to skip the lookup.`),process.exit(1)}o=a,r.asBot=!0}else{o=e(s);let a=t(s);if(a)r.cookie=a}try{await Jf(o,r)}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 r=s.waitFor?String(s.waitFor):"",o=Number(s.timeout);if(!Number.isFinite(o)||o<0||o===0&&!r)console.error("Error: --timeout must be a positive number of seconds"),process.exit(Ce);if(r){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(Ce);let l,d;if(s["as-bot"]){let h=Kt();if(!h)console.error(`Error: --as-bot needs a bot token, but no xoxb- token was found.
199
+ Set SLACK_BOT_TOKEN=xoxb-... in ~/.config/slack-cli/.env (or your shell).`),process.exit(Ce);l=h}else l=e(s),d=t(s);try{let h={link:r,timeout:o,asBot:!!s["as-bot"]};if(d)h.cookie=d;await Zf(l,h)}catch(h){console.error(tt(h)),process.exit(Ce)}return}if(!s.target)console.error("Error: target is required (or use --waitFor <permalink> to collect an answer)"),process.exit(Ce);let a=String(s.question??"").trim();if(!a)console.error("Error: question is empty"),process.exit(Ce);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=Kt();if(!l)console.error(`Error: --as-bot needs a bot token, but no xoxb- token was found.
200
+ Set SLACK_BOT_TOKEN=xoxb-... in ~/.config/slack-cli/.env (or your shell).`),process.exit(Ce);if(!c.channelId&&!c.userId&&c.target.startsWith("@"))try{c.userId=await pn(e(s),c.target,t(s))}catch(d){console.error(`Error: could not resolve ${c.target} to a user for the bot DM.
201
+ ${d instanceof Error?d.message:String(d)}
202
+ Tip: pass --user-id <Uxxxx> to skip the lookup.`),process.exit(Ce)}f=l,c.asBot=!0}else{f=e(s);let l=t(s);if(l)c.cookie=l}try{await Vf(f,c)}catch(l){console.error(tt(l)),process.exit(Ce)}}).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 r=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(Ne);let o=()=>{let d=Kt();if(!d)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(Ne);return d};if(r){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(Ne);let d=e(s),h=t(s);try{let m={link:r};if(s.close)m.close=!0;if(s.names)m.names=!0;if(s["no-notify"])m.noNotify=!0;if(h)m.cookie=h;if(s["as-bot"])m.writeToken=o();await nd(d,m)}catch(m){console.error(tt(m)),process.exit(Ne)}return}if(!s.target)console.error("Error: target is required (or use --results <permalink> to count a poll)"),process.exit(Ne);let a=String(s.question??"").trim();if(!a)console.error("Error: question is empty"),process.exit(Ne);let c=(s.choices??[]).map((d)=>String(d).trim()).filter(Boolean);if(c.length<2||c.length>Ht)console.error(`Error: poll needs 2..${Ht} choices (got ${c.length}). For a free-text question use \`slack ask\`.`),process.exit(Ne);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 pn(e(s),u.target,t(s))}catch(h){console.error(`Error: could not resolve ${u.target} to a user for the bot DM.
204
+ ${h instanceof Error?h.message:String(h)}
205
+ Tip: pass --user-id <Uxxxx> to skip the lookup.`),process.exit(Ne)}l=d,u.asBot=!0}else{l=e(s);let d=t(s);if(d)u.cookie=d}try{await ed(l,u)}catch(d){console.error(tt(d)),process.exit(Ne)}}).command("doctor","Check the bot token (xoxb) can carry a two-way DM (scopes + Messages Tab)",(s)=>s,async()=>{let s=Kt();if(!s)console.error(`Error: slack doctor checks the bot token, but no xoxb- token was found.
206
+ Set SLACK_BOT_TOKEN=xoxb-... in ~/.config/slack-cli/.env (or your shell).`),process.exit(1);await sd(s)}).command("schedule","Manage scheduled messages",(s)=>s.command("send <target> <message>","Schedule a message for later delivery",(r)=>r.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(r)=>{let o={target:r.target,message:r.message,at:r.at};if(r.code)o.code=r.code;if(r["channel-id"])o.channelId=r["channel-id"];if(r["user-id"])o.userId=r["user-id"];let a=t(r);if(a)o.cookie=a;await od(e(r),o)}).command(["ls","list"],"List pending scheduled messages",(r)=>r.positional("target",{type:"string",describe:"#channel to filter by"}).option("channel-id",{type:"string",describe:"Raw channel ID"}),async(r)=>{await ad(e(r),r.target,r["channel-id"],t(r))}).command("rm <target> <id>","Delete a scheduled message",(r)=>r.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(r)=>{let o={target:r.target,id:r.id};if(r.code)o.code=r.code;let a=t(r);if(a)o.cookie=a;if(r["channel-id"])o.channelId=r["channel-id"];await cd(e(r),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 r={target:s.target,newText:s.newText};if(s.code)r.code=s.code;if(s["channel-id"])r.channelId=s["channel-id"];if(s.mentions!==!1)r.mentions=!0;let o=t(s);if(o)r.cookie=o;await Lf(e(s),r)}).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 r={target:s.target};if(s.code)r.code=s.code;if(s["channel-id"])r.channelId=s["channel-id"];let o=t(s);if(o)r.cookie=o;await Wf(e(s),r)}).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 r={target:s.target,emoji:s.emoji};if(s.remove)r.remove=!0;if(s["channel-id"])r.channelId=s["channel-id"];let o=t(s);if(o)r.cookie=o;try{await Uf(e(s),r)}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((r)=>{if(r.cache===!1)Ni(!1)}).command(["ls","list"],"List everyone's tasks (has: \u2014 read-only, one search per run)",(r)=>r.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(r)=>{await i(r,!1)}).command("set <target> <state>","Move a task to a progress state (adds the new reaction before removing the old one)",(r)=>r.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(r)=>{let o={target:r.target,state:r.state};if(r["channel-id"])o.channelId=r["channel-id"];let a=t(r);if(a)o.cookie=a;try{await Of(e(r),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",(r)=>r.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(r)=>{let o={target:r.target,flag:r.flag};if(r.remove)o.remove=!0;if(r["channel-id"])o.channelId=r["channel-id"];let a=t(r);if(a)o.cookie=a;try{await If(e(r),o)}catch(c){console.error(tt(c)),process.exit(1)}}).command("doctor","Find messages carrying two or more progress reactions (--fix repairs them)",(r)=>r.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:Bi,describe:"Max messages to scan"}).option("channel-id",{type:"string",describe:"Raw channel ID"}),async(r)=>{let o={channel:r.in,limit:r.limit};if(r.fix)o.fix=!0;if(r["channel-id"])o.channelId=r["channel-id"];let a=t(r);if(a)o.cookie=a;await Pf(e(r),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((r)=>{if(r.cache===!1)Ni(!1)}).command(["ls","list"],"List tasks you have reacted to (hasmy: \u2014 read-only, one search per run)",(r)=>r.options(n),async(r)=>{await i(r,!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 r={target:s.target,filePaths:s.file};if(s.title)r.title=s.title;if(s.comment)r.comment=s.comment;if(s.code)r.code=s.code;if(s["channel-id"])r.channelId=s["channel-id"];if(s["user-id"])r.userId=s["user-id"];let o=t(s);if(o)r.cookie=o;await ud(e(s),r)}).command("files","File commands",(s)=>s.command(["ls","list"],"List files visible to you (files.list)",(r)=>r.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(r)=>{let o={limit:r.limit,format:r.json?"jsonl":r.format};if(r.type)o.types=r.type;if(r.channel)o.channel=r.channel;if(r.user)o.user=r.user;await ld(e(r),t(r),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 r=s.json?"jsonl":s.format;try{await pd(e(s),t(s),s.ref,{limit:s.limit,format:r})}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 gd(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 Tf(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",(r)=>r.option("all",{alias:"a",type:"boolean",default:!1,describe:"Include sent drafts"}),async(r)=>{await Mf(e(r),t(r),r.all)}).command(["new <channel> [text..]","save <channel> [text..]"],"Create a draft",(r)=>r.positional("channel",{type:"string",demandOption:!0}).positional("text",{type:"string",array:!0,default:[]}),async(r)=>{let o=e(r),a=t(r),c=r.text.join(" ");if(!c)console.error("Usage: slack drafts new <#channel|@user> <text>"),process.exit(2);let u=await De(o,r.channel,a),f=await Qa(o,u,c,a);console.log(`\u2713 Draft created (id: ${P(f.draft).id??"?"})`)}).command("get <id>","Show a draft",(r)=>r.positional("id",{type:"string",demandOption:!0}),async(r)=>{await Bf(e(r),t(r),r.id)}).command(["edit <id> [text..]","update <id> [text..]"],"Edit a draft",(r)=>r.positional("id",{type:"string",demandOption:!0}).positional("text",{type:"string",array:!0,default:[]}).option("code",{type:"string"}),async(r)=>{let o=e(r),a=t(r),c=r.text.join(" ");if(!c)console.error("Usage: slack drafts edit <id> <new-text>"),process.exit(2);let u=await gn(o,a),f=X(u.drafts).map(P).find((p)=>String(p.id)===r.id);if(!f)console.error(`Draft not found: ${r.id}`),process.exit(1);let l=fs(f),d=await Vt(o,a),h=He(l,c,d?.userId??"");if(r.code!==h)ve(r.code,h,["--- Editing draft as -------------------------",je(d),"--- Current draft ----------------------------",...l.split(`
207
+ `).map((p)=>` ${p}`),"--- Replacing with ---------------------------",...c.split(`
208
+ `).map((p)=>` ${p}`),"--------------------------------\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"]);let m=await ec(o,r.id,zi(f),c,a);console.log(`\u2713 Draft updated (id: ${P(m.draft).id??"?"})`)}).command(["delete <id>","rm <id>"],"Delete a draft",(r)=>r.positional("id",{type:"string",demandOption:!0}).option("code",{type:"string"}),async(r)=>{let o=e(r),a=t(r),c=await gn(o,a),u=X(c.drafts).map(P).find((h)=>String(h.id)===r.id);if(!u)console.error(`Draft not found: ${r.id}`),process.exit(1);let f=fs(u),l=await Vt(o,a),d=He(r.id,f,l?.userId??"");if(r.code!==d)ve(r.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",je(l),` id: ${r.id}`,...f.split(`
209
+ `).map((h)=>` ${h}`),"--------------------------------\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500"]);await nc(o,r.id,a),console.log(`\u2713 Draft deleted (id: ${r.id})`)})).command("auth","Authentication and workspace management",(s)=>s.command("token","Add a workspace \u2014 paste an existing xoxp-/xoxb- token",(r)=>r.option("token",{type:"string",describe:"Token to save directly (non-interactive)"}).option("name",{type:"string",describe:"Workspace name (used with --token)"}),async(r)=>{await ha({...r.token!==void 0?{token:r.token}:{},...r.name!==void 0?{name:r.name}:{}})}).command("app","Create a new Slack app and obtain a token (guided wizard)",(r)=>r.option("bot",{type:"boolean",describe:"Create a bot token (xoxb-) instead of user (xoxp-)"}),async(r)=>{await ga({...r.bot!==void 0?{bot:r.bot}:{}})}).command("login","Interactive auth wizard (all auth methods: desktop app, token, new app)",(r)=>r.option("token",{type:"string",describe:"Token to save directly (non-interactive)"}).option("name",{type:"string",describe:"Workspace name (used with --token)"}),async(r)=>{await Vn({...r.token!==void 0?{token:r.token}:{},...r.name!==void 0?{name:r.name}:{}})}).command(["ls","status"],"Show auth status",()=>{},()=>{let r=Qs();if(r.length===0){console.log("No workspaces configured. Run: slack auth login");return}for(let{name:o,profile:a,current:c}of r)console.log(`${c?"* ":" "}${o} ${a.team} (${a.user}) ${a.url??""}`)}).command("use <name>","Switch active workspace",(r)=>r.positional("name",{type:"string",demandOption:!0}).option("g",{type:"boolean",default:!1,describe:"Write global lockfile (~/.slack-cli/workspace)"}),(r)=>{if(!r.g)Df(ft(process.cwd(),".slack-cli"));Bo(r.name,r.g),console.log(`Switched to workspace "${r.name}" ${r.g?"globally":"locally"}`)}).command(["logout <name>","rm <name>","remove <name>"],"Remove a workspace",(r)=>r.positional("name",{type:"string",demandOption:!0}),(r)=>{Mo(r.name),console.log(`Removed workspace "${r.name}"`)}).command(["chrome","cookie"],"Attach Chrome browser xoxd cookie to a workspace (macOS, interactive)",(r)=>r.option("workspace",{type:"string",alias:"w",describe:"Workspace name to update (default: active)"}),async(r)=>{await da({...r.workspace!==void 0?{workspace:r.workspace}:{}})}).command("firefox","Attach Firefox browser xoxd cookie to a workspace (all platforms)",(r)=>r.option("workspace",{type:"string",alias:"w",describe:"Workspace name to update (default: active)"}),async(r)=>{await pa({...r.workspace!==void 0?{workspace:r.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 r=e(s),o=t(s),a=new AbortController;process.on("SIGINT",()=>{a.abort(),process.exit(0)}),await Ca(r,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 Vn({...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()}md().catch((e)=>{console.error(e instanceof Error?e.message:String(e)),process.exit(1)});