gemkit-cli 0.2.3 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (160) hide show
  1. package/README.md +141 -7
  2. package/dist/commands/agent/index.d.ts +9 -0
  3. package/dist/commands/agent/index.js +1329 -0
  4. package/dist/commands/cache/index.d.ts +5 -0
  5. package/dist/commands/cache/index.js +43 -0
  6. package/dist/commands/catalog/index.d.ts +2 -0
  7. package/dist/commands/catalog/index.js +57 -0
  8. package/dist/commands/config/index.d.ts +7 -0
  9. package/dist/commands/config/index.js +122 -0
  10. package/dist/commands/convert/index.d.ts +8 -0
  11. package/dist/commands/convert/index.js +391 -0
  12. package/dist/commands/doctor/index.d.ts +2 -0
  13. package/dist/commands/doctor/index.js +243 -0
  14. package/dist/commands/extension/index.d.ts +5 -0
  15. package/dist/commands/extension/index.js +52 -0
  16. package/dist/commands/index.d.ts +5 -0
  17. package/dist/commands/index.js +37 -0
  18. package/dist/commands/init/index.d.ts +6 -0
  19. package/dist/commands/init/index.js +345 -0
  20. package/dist/commands/new/index.d.ts +5 -0
  21. package/dist/commands/new/index.js +49 -0
  22. package/dist/commands/office/index.d.ts +5 -0
  23. package/dist/commands/office/index.js +283 -0
  24. package/dist/commands/paste/index.d.ts +10 -0
  25. package/dist/commands/paste/index.js +533 -0
  26. package/dist/commands/plan/index.d.ts +8 -0
  27. package/dist/commands/plan/index.js +247 -0
  28. package/dist/commands/session/index.d.ts +8 -0
  29. package/dist/commands/session/index.js +289 -0
  30. package/dist/commands/tokens/index.d.ts +6 -0
  31. package/dist/commands/tokens/index.js +148 -0
  32. package/dist/commands/update/index.d.ts +26 -0
  33. package/dist/commands/update/index.js +199 -0
  34. package/dist/commands/versions/index.d.ts +5 -0
  35. package/dist/commands/versions/index.js +39 -0
  36. package/dist/domains/agent/index.d.ts +8 -0
  37. package/dist/domains/agent/index.js +8 -0
  38. package/dist/domains/agent/mappings.d.ts +32 -0
  39. package/dist/domains/agent/mappings.js +164 -0
  40. package/dist/domains/agent/profile.d.ts +26 -0
  41. package/dist/domains/agent/profile.js +225 -0
  42. package/dist/domains/agent/pty-context.d.ts +11 -0
  43. package/dist/domains/agent/pty-context.js +83 -0
  44. package/dist/domains/agent/pty-providers.d.ts +18 -0
  45. package/dist/domains/agent/pty-providers.js +66 -0
  46. package/dist/domains/agent/pty-session.d.ts +33 -0
  47. package/dist/domains/agent/pty-session.js +82 -0
  48. package/dist/domains/agent/pty-types.d.ts +127 -0
  49. package/dist/domains/agent/pty-types.js +4 -0
  50. package/dist/domains/agent/search.d.ts +45 -0
  51. package/dist/domains/agent/search.js +614 -0
  52. package/dist/domains/agent/types.d.ts +78 -0
  53. package/dist/domains/agent/types.js +5 -0
  54. package/dist/domains/agent-office/documents-scanner.d.ts +9 -0
  55. package/dist/domains/agent-office/documents-scanner.js +143 -0
  56. package/dist/domains/agent-office/event-emitter.d.ts +43 -0
  57. package/dist/domains/agent-office/event-emitter.js +86 -0
  58. package/dist/domains/agent-office/file-watcher.d.ts +40 -0
  59. package/dist/domains/agent-office/file-watcher.js +173 -0
  60. package/dist/domains/agent-office/icons.d.ts +11 -0
  61. package/dist/domains/agent-office/icons.js +36 -0
  62. package/dist/domains/agent-office/index.d.ts +12 -0
  63. package/dist/domains/agent-office/index.js +20 -0
  64. package/dist/domains/agent-office/renderer/web/assets.d.ts +11 -0
  65. package/dist/domains/agent-office/renderer/web/assets.js +3419 -0
  66. package/dist/domains/agent-office/renderer/web/server.d.ts +42 -0
  67. package/dist/domains/agent-office/renderer/web/server.js +228 -0
  68. package/dist/domains/agent-office/renderer/web.d.ts +30 -0
  69. package/dist/domains/agent-office/renderer/web.js +111 -0
  70. package/dist/domains/agent-office/session-bridge.d.ts +23 -0
  71. package/dist/domains/agent-office/session-bridge.js +171 -0
  72. package/dist/domains/agent-office/state-machine.d.ts +5 -0
  73. package/dist/domains/agent-office/state-machine.js +82 -0
  74. package/dist/domains/agent-office/types.d.ts +91 -0
  75. package/dist/domains/agent-office/types.js +4 -0
  76. package/dist/domains/cache/index.d.ts +1 -0
  77. package/dist/domains/cache/index.js +1 -0
  78. package/dist/domains/cache/manager.d.ts +22 -0
  79. package/dist/domains/cache/manager.js +84 -0
  80. package/dist/domains/config/index.d.ts +5 -0
  81. package/dist/domains/config/index.js +5 -0
  82. package/dist/domains/config/manager.d.ts +24 -0
  83. package/dist/domains/config/manager.js +85 -0
  84. package/dist/domains/config/schema.d.ts +17 -0
  85. package/dist/domains/config/schema.js +96 -0
  86. package/dist/domains/convert/converter.d.ts +78 -0
  87. package/dist/domains/convert/converter.js +471 -0
  88. package/dist/domains/convert/index.d.ts +5 -0
  89. package/dist/domains/convert/index.js +5 -0
  90. package/dist/domains/convert/types.d.ts +88 -0
  91. package/dist/domains/convert/types.js +18 -0
  92. package/dist/domains/github/download.d.ts +12 -0
  93. package/dist/domains/github/download.js +51 -0
  94. package/dist/domains/github/index.d.ts +2 -0
  95. package/dist/domains/github/index.js +2 -0
  96. package/dist/domains/github/releases.d.ts +16 -0
  97. package/dist/domains/github/releases.js +68 -0
  98. package/dist/domains/installation/conflict.d.ts +13 -0
  99. package/dist/domains/installation/conflict.js +38 -0
  100. package/dist/domains/installation/file-sync.d.ts +16 -0
  101. package/dist/domains/installation/file-sync.js +77 -0
  102. package/dist/domains/installation/index.d.ts +3 -0
  103. package/dist/domains/installation/index.js +3 -0
  104. package/dist/domains/installation/metadata.d.ts +20 -0
  105. package/dist/domains/installation/metadata.js +52 -0
  106. package/dist/domains/plan/index.d.ts +2 -0
  107. package/dist/domains/plan/index.js +2 -0
  108. package/dist/domains/plan/resolver.d.ts +24 -0
  109. package/dist/domains/plan/resolver.js +164 -0
  110. package/dist/domains/plan/types.d.ts +13 -0
  111. package/dist/domains/plan/types.js +4 -0
  112. package/dist/domains/session/env.d.ts +51 -0
  113. package/dist/domains/session/env.js +118 -0
  114. package/dist/domains/session/index.d.ts +8 -0
  115. package/dist/domains/session/index.js +8 -0
  116. package/dist/domains/session/manager.d.ts +56 -0
  117. package/dist/domains/session/manager.js +205 -0
  118. package/dist/domains/session/paths.d.ts +6 -0
  119. package/dist/domains/session/paths.js +6 -0
  120. package/dist/domains/session/types.d.ts +121 -0
  121. package/dist/domains/session/types.js +5 -0
  122. package/dist/domains/session/writer.d.ts +82 -0
  123. package/dist/domains/session/writer.js +431 -0
  124. package/dist/domains/tokens/index.d.ts +5 -0
  125. package/dist/domains/tokens/index.js +5 -0
  126. package/dist/domains/tokens/pricing.d.ts +38 -0
  127. package/dist/domains/tokens/pricing.js +129 -0
  128. package/dist/domains/tokens/scanner.d.ts +42 -0
  129. package/dist/domains/tokens/scanner.js +168 -0
  130. package/dist/index.d.ts +5 -0
  131. package/dist/index.js +90 -59
  132. package/dist/services/aipty.d.ts +76 -0
  133. package/dist/services/aipty.js +276 -0
  134. package/dist/services/archive.d.ts +22 -0
  135. package/dist/services/archive.js +53 -0
  136. package/dist/services/auto-update.d.ts +26 -0
  137. package/dist/services/auto-update.js +117 -0
  138. package/dist/services/hash.d.ts +36 -0
  139. package/dist/services/hash.js +63 -0
  140. package/dist/services/logger.d.ts +28 -0
  141. package/dist/services/logger.js +102 -0
  142. package/dist/services/music.d.ts +67 -0
  143. package/dist/services/music.js +290 -0
  144. package/dist/services/npm.d.ts +22 -0
  145. package/dist/services/npm.js +65 -0
  146. package/dist/services/pty-client.d.ts +66 -0
  147. package/dist/services/pty-client.js +154 -0
  148. package/dist/services/pty-server.d.ts +102 -0
  149. package/dist/services/pty-server.js +613 -0
  150. package/dist/types/index.d.ts +155 -0
  151. package/dist/types/index.js +4 -0
  152. package/dist/utils/colors.d.ts +43 -0
  153. package/dist/utils/colors.js +98 -0
  154. package/dist/utils/errors.d.ts +24 -0
  155. package/dist/utils/errors.js +56 -0
  156. package/dist/utils/paths.d.ts +46 -0
  157. package/dist/utils/paths.js +89 -0
  158. package/dist/utils/platform.d.ts +11 -0
  159. package/dist/utils/platform.js +31 -0
  160. package/package.json +55 -54
package/dist/index.js CHANGED
@@ -1,53 +1,82 @@
1
1
  #!/usr/bin/env node
2
- var HA=Object.create;var $c=Object.defineProperty;var LA=Object.getOwnPropertyDescriptor;var _A=Object.getOwnPropertyNames;var $A=Object.getPrototypeOf,eu=Object.prototype.hasOwnProperty;var er=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var tu=(t,e,i,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of _A(e))!eu.call(t,r)&&r!==i&&$c(t,r,{get:()=>e[r],enumerable:!(n=LA(e,r))||n.enumerable});return t};var tr=(t,e,i)=>(i=t!=null?HA($A(t)):{},tu(e||!t||!t.__esModule?$c(i,"default",{value:t,enumerable:!0}):i,t));var gl=er((Qf,Qu)=>{Qu.exports={dots:{interval:80,frames:["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"]},dots2:{interval:80,frames:["\u28FE","\u28FD","\u28FB","\u28BF","\u287F","\u28DF","\u28EF","\u28F7"]},dots3:{interval:80,frames:["\u280B","\u2819","\u281A","\u281E","\u2816","\u2826","\u2834","\u2832","\u2833","\u2813"]},dots4:{interval:80,frames:["\u2804","\u2806","\u2807","\u280B","\u2819","\u2838","\u2830","\u2820","\u2830","\u2838","\u2819","\u280B","\u2807","\u2806"]},dots5:{interval:80,frames:["\u280B","\u2819","\u281A","\u2812","\u2802","\u2802","\u2812","\u2832","\u2834","\u2826","\u2816","\u2812","\u2810","\u2810","\u2812","\u2813","\u280B"]},dots6:{interval:80,frames:["\u2801","\u2809","\u2819","\u281A","\u2812","\u2802","\u2802","\u2812","\u2832","\u2834","\u2824","\u2804","\u2804","\u2824","\u2834","\u2832","\u2812","\u2802","\u2802","\u2812","\u281A","\u2819","\u2809","\u2801"]},dots7:{interval:80,frames:["\u2808","\u2809","\u280B","\u2813","\u2812","\u2810","\u2810","\u2812","\u2816","\u2826","\u2824","\u2820","\u2820","\u2824","\u2826","\u2816","\u2812","\u2810","\u2810","\u2812","\u2813","\u280B","\u2809","\u2808"]},dots8:{interval:80,frames:["\u2801","\u2801","\u2809","\u2819","\u281A","\u2812","\u2802","\u2802","\u2812","\u2832","\u2834","\u2824","\u2804","\u2804","\u2824","\u2820","\u2820","\u2824","\u2826","\u2816","\u2812","\u2810","\u2810","\u2812","\u2813","\u280B","\u2809","\u2808","\u2808"]},dots9:{interval:80,frames:["\u28B9","\u28BA","\u28BC","\u28F8","\u28C7","\u2867","\u2857","\u284F"]},dots10:{interval:80,frames:["\u2884","\u2882","\u2881","\u2841","\u2848","\u2850","\u2860"]},dots11:{interval:100,frames:["\u2801","\u2802","\u2804","\u2840","\u2880","\u2820","\u2810","\u2808"]},dots12:{interval:80,frames:["\u2880\u2800","\u2840\u2800","\u2804\u2800","\u2882\u2800","\u2842\u2800","\u2805\u2800","\u2883\u2800","\u2843\u2800","\u280D\u2800","\u288B\u2800","\u284B\u2800","\u280D\u2801","\u288B\u2801","\u284B\u2801","\u280D\u2809","\u280B\u2809","\u280B\u2809","\u2809\u2819","\u2809\u2819","\u2809\u2829","\u2808\u2899","\u2808\u2859","\u2888\u2829","\u2840\u2899","\u2804\u2859","\u2882\u2829","\u2842\u2898","\u2805\u2858","\u2883\u2828","\u2843\u2890","\u280D\u2850","\u288B\u2820","\u284B\u2880","\u280D\u2841","\u288B\u2801","\u284B\u2801","\u280D\u2809","\u280B\u2809","\u280B\u2809","\u2809\u2819","\u2809\u2819","\u2809\u2829","\u2808\u2899","\u2808\u2859","\u2808\u2829","\u2800\u2899","\u2800\u2859","\u2800\u2829","\u2800\u2898","\u2800\u2858","\u2800\u2828","\u2800\u2890","\u2800\u2850","\u2800\u2820","\u2800\u2880","\u2800\u2840"]},dots13:{interval:80,frames:["\u28FC","\u28F9","\u28BB","\u283F","\u285F","\u28CF","\u28E7","\u28F6"]},dots8Bit:{interval:80,frames:["\u2800","\u2801","\u2802","\u2803","\u2804","\u2805","\u2806","\u2807","\u2840","\u2841","\u2842","\u2843","\u2844","\u2845","\u2846","\u2847","\u2808","\u2809","\u280A","\u280B","\u280C","\u280D","\u280E","\u280F","\u2848","\u2849","\u284A","\u284B","\u284C","\u284D","\u284E","\u284F","\u2810","\u2811","\u2812","\u2813","\u2814","\u2815","\u2816","\u2817","\u2850","\u2851","\u2852","\u2853","\u2854","\u2855","\u2856","\u2857","\u2818","\u2819","\u281A","\u281B","\u281C","\u281D","\u281E","\u281F","\u2858","\u2859","\u285A","\u285B","\u285C","\u285D","\u285E","\u285F","\u2820","\u2821","\u2822","\u2823","\u2824","\u2825","\u2826","\u2827","\u2860","\u2861","\u2862","\u2863","\u2864","\u2865","\u2866","\u2867","\u2828","\u2829","\u282A","\u282B","\u282C","\u282D","\u282E","\u282F","\u2868","\u2869","\u286A","\u286B","\u286C","\u286D","\u286E","\u286F","\u2830","\u2831","\u2832","\u2833","\u2834","\u2835","\u2836","\u2837","\u2870","\u2871","\u2872","\u2873","\u2874","\u2875","\u2876","\u2877","\u2838","\u2839","\u283A","\u283B","\u283C","\u283D","\u283E","\u283F","\u2878","\u2879","\u287A","\u287B","\u287C","\u287D","\u287E","\u287F","\u2880","\u2881","\u2882","\u2883","\u2884","\u2885","\u2886","\u2887","\u28C0","\u28C1","\u28C2","\u28C3","\u28C4","\u28C5","\u28C6","\u28C7","\u2888","\u2889","\u288A","\u288B","\u288C","\u288D","\u288E","\u288F","\u28C8","\u28C9","\u28CA","\u28CB","\u28CC","\u28CD","\u28CE","\u28CF","\u2890","\u2891","\u2892","\u2893","\u2894","\u2895","\u2896","\u2897","\u28D0","\u28D1","\u28D2","\u28D3","\u28D4","\u28D5","\u28D6","\u28D7","\u2898","\u2899","\u289A","\u289B","\u289C","\u289D","\u289E","\u289F","\u28D8","\u28D9","\u28DA","\u28DB","\u28DC","\u28DD","\u28DE","\u28DF","\u28A0","\u28A1","\u28A2","\u28A3","\u28A4","\u28A5","\u28A6","\u28A7","\u28E0","\u28E1","\u28E2","\u28E3","\u28E4","\u28E5","\u28E6","\u28E7","\u28A8","\u28A9","\u28AA","\u28AB","\u28AC","\u28AD","\u28AE","\u28AF","\u28E8","\u28E9","\u28EA","\u28EB","\u28EC","\u28ED","\u28EE","\u28EF","\u28B0","\u28B1","\u28B2","\u28B3","\u28B4","\u28B5","\u28B6","\u28B7","\u28F0","\u28F1","\u28F2","\u28F3","\u28F4","\u28F5","\u28F6","\u28F7","\u28B8","\u28B9","\u28BA","\u28BB","\u28BC","\u28BD","\u28BE","\u28BF","\u28F8","\u28F9","\u28FA","\u28FB","\u28FC","\u28FD","\u28FE","\u28FF"]},sand:{interval:80,frames:["\u2801","\u2802","\u2804","\u2840","\u2848","\u2850","\u2860","\u28C0","\u28C1","\u28C2","\u28C4","\u28CC","\u28D4","\u28E4","\u28E5","\u28E6","\u28EE","\u28F6","\u28F7","\u28FF","\u287F","\u283F","\u289F","\u281F","\u285B","\u281B","\u282B","\u288B","\u280B","\u280D","\u2849","\u2809","\u2811","\u2821","\u2881"]},line:{interval:130,frames:["-","\\","|","/"]},line2:{interval:100,frames:["\u2802","-","\u2013","\u2014","\u2013","-"]},pipe:{interval:100,frames:["\u2524","\u2518","\u2534","\u2514","\u251C","\u250C","\u252C","\u2510"]},simpleDots:{interval:400,frames:[". ",".. ","..."," "]},simpleDotsScrolling:{interval:200,frames:[". ",".. ","..."," .."," ."," "]},star:{interval:70,frames:["\u2736","\u2738","\u2739","\u273A","\u2739","\u2737"]},star2:{interval:80,frames:["+","x","*"]},flip:{interval:70,frames:["_","_","_","-","`","`","'","\xB4","-","_","_","_"]},hamburger:{interval:100,frames:["\u2631","\u2632","\u2634"]},growVertical:{interval:120,frames:["\u2581","\u2583","\u2584","\u2585","\u2586","\u2587","\u2586","\u2585","\u2584","\u2583"]},growHorizontal:{interval:120,frames:["\u258F","\u258E","\u258D","\u258C","\u258B","\u258A","\u2589","\u258A","\u258B","\u258C","\u258D","\u258E"]},balloon:{interval:140,frames:[" ",".","o","O","@","*"," "]},balloon2:{interval:120,frames:[".","o","O","\xB0","O","o","."]},noise:{interval:100,frames:["\u2593","\u2592","\u2591"]},bounce:{interval:120,frames:["\u2801","\u2802","\u2804","\u2802"]},boxBounce:{interval:120,frames:["\u2596","\u2598","\u259D","\u2597"]},boxBounce2:{interval:100,frames:["\u258C","\u2580","\u2590","\u2584"]},triangle:{interval:50,frames:["\u25E2","\u25E3","\u25E4","\u25E5"]},binary:{interval:80,frames:["010010","001100","100101","111010","111101","010111","101011","111000","110011","110101"]},arc:{interval:100,frames:["\u25DC","\u25E0","\u25DD","\u25DE","\u25E1","\u25DF"]},circle:{interval:120,frames:["\u25E1","\u2299","\u25E0"]},squareCorners:{interval:180,frames:["\u25F0","\u25F3","\u25F2","\u25F1"]},circleQuarters:{interval:120,frames:["\u25F4","\u25F7","\u25F6","\u25F5"]},circleHalves:{interval:50,frames:["\u25D0","\u25D3","\u25D1","\u25D2"]},squish:{interval:100,frames:["\u256B","\u256A"]},toggle:{interval:250,frames:["\u22B6","\u22B7"]},toggle2:{interval:80,frames:["\u25AB","\u25AA"]},toggle3:{interval:120,frames:["\u25A1","\u25A0"]},toggle4:{interval:100,frames:["\u25A0","\u25A1","\u25AA","\u25AB"]},toggle5:{interval:100,frames:["\u25AE","\u25AF"]},toggle6:{interval:300,frames:["\u101D","\u1040"]},toggle7:{interval:80,frames:["\u29BE","\u29BF"]},toggle8:{interval:100,frames:["\u25CD","\u25CC"]},toggle9:{interval:100,frames:["\u25C9","\u25CE"]},toggle10:{interval:100,frames:["\u3282","\u3280","\u3281"]},toggle11:{interval:50,frames:["\u29C7","\u29C6"]},toggle12:{interval:120,frames:["\u2617","\u2616"]},toggle13:{interval:80,frames:["=","*","-"]},arrow:{interval:100,frames:["\u2190","\u2196","\u2191","\u2197","\u2192","\u2198","\u2193","\u2199"]},arrow2:{interval:80,frames:["\u2B06\uFE0F ","\u2197\uFE0F ","\u27A1\uFE0F ","\u2198\uFE0F ","\u2B07\uFE0F ","\u2199\uFE0F ","\u2B05\uFE0F ","\u2196\uFE0F "]},arrow3:{interval:120,frames:["\u25B9\u25B9\u25B9\u25B9\u25B9","\u25B8\u25B9\u25B9\u25B9\u25B9","\u25B9\u25B8\u25B9\u25B9\u25B9","\u25B9\u25B9\u25B8\u25B9\u25B9","\u25B9\u25B9\u25B9\u25B8\u25B9","\u25B9\u25B9\u25B9\u25B9\u25B8"]},bouncingBar:{interval:80,frames:["[ ]","[= ]","[== ]","[=== ]","[====]","[ ===]","[ ==]","[ =]","[ ]","[ =]","[ ==]","[ ===]","[====]","[=== ]","[== ]","[= ]"]},bouncingBall:{interval:80,frames:["( \u25CF )","( \u25CF )","( \u25CF )","( \u25CF )","( \u25CF)","( \u25CF )","( \u25CF )","( \u25CF )","( \u25CF )","(\u25CF )"]},smiley:{interval:200,frames:["\u{1F604} ","\u{1F61D} "]},monkey:{interval:300,frames:["\u{1F648} ","\u{1F648} ","\u{1F649} ","\u{1F64A} "]},hearts:{interval:100,frames:["\u{1F49B} ","\u{1F499} ","\u{1F49C} ","\u{1F49A} ","\u2764\uFE0F "]},clock:{interval:100,frames:["\u{1F55B} ","\u{1F550} ","\u{1F551} ","\u{1F552} ","\u{1F553} ","\u{1F554} ","\u{1F555} ","\u{1F556} ","\u{1F557} ","\u{1F558} ","\u{1F559} ","\u{1F55A} "]},earth:{interval:180,frames:["\u{1F30D} ","\u{1F30E} ","\u{1F30F} "]},material:{interval:17,frames:["\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581","\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581","\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581","\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581","\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581","\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581","\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581","\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581","\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581","\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581","\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581","\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581","\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588","\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588","\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588","\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588","\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588","\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588","\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588","\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588","\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581","\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581","\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581","\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581","\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581","\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581","\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581"]},moon:{interval:80,frames:["\u{1F311} ","\u{1F312} ","\u{1F313} ","\u{1F314} ","\u{1F315} ","\u{1F316} ","\u{1F317} ","\u{1F318} "]},runner:{interval:140,frames:["\u{1F6B6} ","\u{1F3C3} "]},pong:{interval:80,frames:["\u2590\u2802 \u258C","\u2590\u2808 \u258C","\u2590 \u2802 \u258C","\u2590 \u2820 \u258C","\u2590 \u2840 \u258C","\u2590 \u2820 \u258C","\u2590 \u2802 \u258C","\u2590 \u2808 \u258C","\u2590 \u2802 \u258C","\u2590 \u2820 \u258C","\u2590 \u2840 \u258C","\u2590 \u2820 \u258C","\u2590 \u2802 \u258C","\u2590 \u2808 \u258C","\u2590 \u2802\u258C","\u2590 \u2820\u258C","\u2590 \u2840\u258C","\u2590 \u2820 \u258C","\u2590 \u2802 \u258C","\u2590 \u2808 \u258C","\u2590 \u2802 \u258C","\u2590 \u2820 \u258C","\u2590 \u2840 \u258C","\u2590 \u2820 \u258C","\u2590 \u2802 \u258C","\u2590 \u2808 \u258C","\u2590 \u2802 \u258C","\u2590 \u2820 \u258C","\u2590 \u2840 \u258C","\u2590\u2820 \u258C"]},shark:{interval:120,frames:["\u2590|\\____________\u258C","\u2590_|\\___________\u258C","\u2590__|\\__________\u258C","\u2590___|\\_________\u258C","\u2590____|\\________\u258C","\u2590_____|\\_______\u258C","\u2590______|\\______\u258C","\u2590_______|\\_____\u258C","\u2590________|\\____\u258C","\u2590_________|\\___\u258C","\u2590__________|\\__\u258C","\u2590___________|\\_\u258C","\u2590____________|\\\u258C","\u2590____________/|\u258C","\u2590___________/|_\u258C","\u2590__________/|__\u258C","\u2590_________/|___\u258C","\u2590________/|____\u258C","\u2590_______/|_____\u258C","\u2590______/|______\u258C","\u2590_____/|_______\u258C","\u2590____/|________\u258C","\u2590___/|_________\u258C","\u2590__/|__________\u258C","\u2590_/|___________\u258C","\u2590/|____________\u258C"]},dqpb:{interval:100,frames:["d","q","p","b"]},weather:{interval:100,frames:["\u2600\uFE0F ","\u2600\uFE0F ","\u2600\uFE0F ","\u{1F324} ","\u26C5\uFE0F ","\u{1F325} ","\u2601\uFE0F ","\u{1F327} ","\u{1F328} ","\u{1F327} ","\u{1F328} ","\u{1F327} ","\u{1F328} ","\u26C8 ","\u{1F328} ","\u{1F327} ","\u{1F328} ","\u2601\uFE0F ","\u{1F325} ","\u26C5\uFE0F ","\u{1F324} ","\u2600\uFE0F ","\u2600\uFE0F "]},christmas:{interval:400,frames:["\u{1F332}","\u{1F384}"]},grenade:{interval:80,frames:["\u060C ","\u2032 "," \xB4 "," \u203E "," \u2E0C"," \u2E0A"," |"," \u204E"," \u2055"," \u0DF4 "," \u2053"," "," "," "]},point:{interval:125,frames:["\u2219\u2219\u2219","\u25CF\u2219\u2219","\u2219\u25CF\u2219","\u2219\u2219\u25CF","\u2219\u2219\u2219"]},layer:{interval:150,frames:["-","=","\u2261"]},betaWave:{interval:80,frames:["\u03C1\u03B2\u03B2\u03B2\u03B2\u03B2\u03B2","\u03B2\u03C1\u03B2\u03B2\u03B2\u03B2\u03B2","\u03B2\u03B2\u03C1\u03B2\u03B2\u03B2\u03B2","\u03B2\u03B2\u03B2\u03C1\u03B2\u03B2\u03B2","\u03B2\u03B2\u03B2\u03B2\u03C1\u03B2\u03B2","\u03B2\u03B2\u03B2\u03B2\u03B2\u03C1\u03B2","\u03B2\u03B2\u03B2\u03B2\u03B2\u03B2\u03C1"]},fingerDance:{interval:160,frames:["\u{1F918} ","\u{1F91F} ","\u{1F596} ","\u270B ","\u{1F91A} ","\u{1F446} "]},fistBump:{interval:80,frames:["\u{1F91C}\u3000\u3000\u3000\u3000\u{1F91B} ","\u{1F91C}\u3000\u3000\u3000\u3000\u{1F91B} ","\u{1F91C}\u3000\u3000\u3000\u3000\u{1F91B} ","\u3000\u{1F91C}\u3000\u3000\u{1F91B}\u3000 ","\u3000\u3000\u{1F91C}\u{1F91B}\u3000\u3000 ","\u3000\u{1F91C}\u2728\u{1F91B}\u3000\u3000 ","\u{1F91C}\u3000\u2728\u3000\u{1F91B}\u3000 "]},soccerHeader:{interval:80,frames:[" \u{1F9D1}\u26BD\uFE0F \u{1F9D1} ","\u{1F9D1} \u26BD\uFE0F \u{1F9D1} ","\u{1F9D1} \u26BD\uFE0F \u{1F9D1} ","\u{1F9D1} \u26BD\uFE0F \u{1F9D1} ","\u{1F9D1} \u26BD\uFE0F \u{1F9D1} ","\u{1F9D1} \u26BD\uFE0F \u{1F9D1} ","\u{1F9D1} \u26BD\uFE0F\u{1F9D1} ","\u{1F9D1} \u26BD\uFE0F \u{1F9D1} ","\u{1F9D1} \u26BD\uFE0F \u{1F9D1} ","\u{1F9D1} \u26BD\uFE0F \u{1F9D1} ","\u{1F9D1} \u26BD\uFE0F \u{1F9D1} ","\u{1F9D1} \u26BD\uFE0F \u{1F9D1} "]},mindblown:{interval:160,frames:["\u{1F610} ","\u{1F610} ","\u{1F62E} ","\u{1F62E} ","\u{1F626} ","\u{1F626} ","\u{1F627} ","\u{1F627} ","\u{1F92F} ","\u{1F4A5} ","\u2728 ","\u3000 ","\u3000 ","\u3000 "]},speaker:{interval:160,frames:["\u{1F508} ","\u{1F509} ","\u{1F50A} ","\u{1F509} "]},orangePulse:{interval:100,frames:["\u{1F538} ","\u{1F536} ","\u{1F7E0} ","\u{1F7E0} ","\u{1F536} "]},bluePulse:{interval:100,frames:["\u{1F539} ","\u{1F537} ","\u{1F535} ","\u{1F535} ","\u{1F537} "]},orangeBluePulse:{interval:100,frames:["\u{1F538} ","\u{1F536} ","\u{1F7E0} ","\u{1F7E0} ","\u{1F536} ","\u{1F539} ","\u{1F537} ","\u{1F535} ","\u{1F535} ","\u{1F537} "]},timeTravel:{interval:100,frames:["\u{1F55B} ","\u{1F55A} ","\u{1F559} ","\u{1F558} ","\u{1F557} ","\u{1F556} ","\u{1F555} ","\u{1F554} ","\u{1F553} ","\u{1F552} ","\u{1F551} ","\u{1F550} "]},aesthetic:{interval:80,frames:["\u25B0\u25B1\u25B1\u25B1\u25B1\u25B1\u25B1","\u25B0\u25B0\u25B1\u25B1\u25B1\u25B1\u25B1","\u25B0\u25B0\u25B0\u25B1\u25B1\u25B1\u25B1","\u25B0\u25B0\u25B0\u25B0\u25B1\u25B1\u25B1","\u25B0\u25B0\u25B0\u25B0\u25B0\u25B1\u25B1","\u25B0\u25B0\u25B0\u25B0\u25B0\u25B0\u25B1","\u25B0\u25B0\u25B0\u25B0\u25B0\u25B0\u25B0","\u25B0\u25B1\u25B1\u25B1\u25B1\u25B1\u25B1"]},dwarfFortress:{interval:80,frames:[" \u2588\u2588\u2588\u2588\u2588\u2588\xA3\xA3\xA3 ","\u263A\u2588\u2588\u2588\u2588\u2588\u2588\xA3\xA3\xA3 ","\u263A\u2588\u2588\u2588\u2588\u2588\u2588\xA3\xA3\xA3 ","\u263A\u2593\u2588\u2588\u2588\u2588\u2588\xA3\xA3\xA3 ","\u263A\u2593\u2588\u2588\u2588\u2588\u2588\xA3\xA3\xA3 ","\u263A\u2592\u2588\u2588\u2588\u2588\u2588\xA3\xA3\xA3 ","\u263A\u2592\u2588\u2588\u2588\u2588\u2588\xA3\xA3\xA3 ","\u263A\u2591\u2588\u2588\u2588\u2588\u2588\xA3\xA3\xA3 ","\u263A\u2591\u2588\u2588\u2588\u2588\u2588\xA3\xA3\xA3 ","\u263A \u2588\u2588\u2588\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2588\u2588\u2588\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2588\u2588\u2588\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2593\u2588\u2588\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2593\u2588\u2588\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2592\u2588\u2588\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2592\u2588\u2588\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2591\u2588\u2588\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2591\u2588\u2588\u2588\u2588\xA3\xA3\xA3 "," \u263A \u2588\u2588\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2588\u2588\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2588\u2588\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2593\u2588\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2593\u2588\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2592\u2588\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2592\u2588\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2591\u2588\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2591\u2588\u2588\u2588\xA3\xA3\xA3 "," \u263A \u2588\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2588\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2588\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2593\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2593\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2592\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2592\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2591\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2591\u2588\u2588\xA3\xA3\xA3 "," \u263A \u2588\u2588\xA3\xA3\xA3 "," \u263A\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2593\u2588\xA3\xA3\xA3 "," \u263A\u2593\u2588\xA3\xA3\xA3 "," \u263A\u2592\u2588\xA3\xA3\xA3 "," \u263A\u2592\u2588\xA3\xA3\xA3 "," \u263A\u2591\u2588\xA3\xA3\xA3 "," \u263A\u2591\u2588\xA3\xA3\xA3 "," \u263A \u2588\xA3\xA3\xA3 "," \u263A\u2588\xA3\xA3\xA3 "," \u263A\u2588\xA3\xA3\xA3 "," \u263A\u2593\xA3\xA3\xA3 "," \u263A\u2593\xA3\xA3\xA3 "," \u263A\u2592\xA3\xA3\xA3 "," \u263A\u2592\xA3\xA3\xA3 "," \u263A\u2591\xA3\xA3\xA3 "," \u263A\u2591\xA3\xA3\xA3 "," \u263A \xA3\xA3\xA3 "," \u263A\xA3\xA3\xA3 "," \u263A\xA3\xA3\xA3 "," \u263A\u2593\xA3\xA3 "," \u263A\u2593\xA3\xA3 "," \u263A\u2592\xA3\xA3 "," \u263A\u2592\xA3\xA3 "," \u263A\u2591\xA3\xA3 "," \u263A\u2591\xA3\xA3 "," \u263A \xA3\xA3 "," \u263A\xA3\xA3 "," \u263A\xA3\xA3 "," \u263A\u2593\xA3 "," \u263A\u2593\xA3 "," \u263A\u2592\xA3 "," \u263A\u2592\xA3 "," \u263A\u2591\xA3 "," \u263A\u2591\xA3 "," \u263A \xA3 "," \u263A\xA3 "," \u263A\xA3 "," \u263A\u2593 "," \u263A\u2593 "," \u263A\u2592 "," \u263A\u2592 "," \u263A\u2591 "," \u263A\u2591 "," \u263A "," \u263A &"," \u263A \u263C&"," \u263A \u263C &"," \u263A\u263C &"," \u263A\u263C & "," \u203C & "," \u263A & "," \u203C & "," \u263A & "," \u203C & "," \u263A & ","\u203C & "," & "," & "," & \u2591 "," & \u2592 "," & \u2593 "," & \xA3 "," & \u2591\xA3 "," & \u2592\xA3 "," & \u2593\xA3 "," & \xA3\xA3 "," & \u2591\xA3\xA3 "," & \u2592\xA3\xA3 ","& \u2593\xA3\xA3 ","& \xA3\xA3\xA3 "," \u2591\xA3\xA3\xA3 "," \u2592\xA3\xA3\xA3 "," \u2593\xA3\xA3\xA3 "," \u2588\xA3\xA3\xA3 "," \u2591\u2588\xA3\xA3\xA3 "," \u2592\u2588\xA3\xA3\xA3 "," \u2593\u2588\xA3\xA3\xA3 "," \u2588\u2588\xA3\xA3\xA3 "," \u2591\u2588\u2588\xA3\xA3\xA3 "," \u2592\u2588\u2588\xA3\xA3\xA3 "," \u2593\u2588\u2588\xA3\xA3\xA3 "," \u2588\u2588\u2588\xA3\xA3\xA3 "," \u2591\u2588\u2588\u2588\xA3\xA3\xA3 "," \u2592\u2588\u2588\u2588\xA3\xA3\xA3 "," \u2593\u2588\u2588\u2588\xA3\xA3\xA3 "," \u2588\u2588\u2588\u2588\xA3\xA3\xA3 "," \u2591\u2588\u2588\u2588\u2588\xA3\xA3\xA3 "," \u2592\u2588\u2588\u2588\u2588\xA3\xA3\xA3 "," \u2593\u2588\u2588\u2588\u2588\xA3\xA3\xA3 "," \u2588\u2588\u2588\u2588\u2588\xA3\xA3\xA3 "," \u2591\u2588\u2588\u2588\u2588\u2588\xA3\xA3\xA3 "," \u2592\u2588\u2588\u2588\u2588\u2588\xA3\xA3\xA3 "," \u2593\u2588\u2588\u2588\u2588\u2588\xA3\xA3\xA3 "," \u2588\u2588\u2588\u2588\u2588\u2588\xA3\xA3\xA3 "," \u2588\u2588\u2588\u2588\u2588\u2588\xA3\xA3\xA3 "]}}});var Os=er((bf,xl)=>{"use strict";var ur=Object.assign({},gl()),jl=Object.keys(ur);Object.defineProperty(ur,"random",{get(){let t=Math.floor(Math.random()*jl.length),e=jl[t];return ur[e]}});xl.exports=ur});var Cl=er((_f,Ml)=>{Ml.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 fv=er((Fz,lc)=>{var Wo=process||{},pv=Wo.argv||[],Yo=Wo.env||{},YE=!(Yo.NO_COLOR||pv.includes("--no-color"))&&(!!Yo.FORCE_COLOR||pv.includes("--color")||Wo.platform==="win32"||(Wo.stdout||{}).isTTY&&Yo.TERM!=="dumb"||!!Yo.CI),WE=(t,e,i=t)=>n=>{let r=""+n,o=r.indexOf(e,t.length);return~o?t+ME(r,e,i,o)+e:t+r+e},ME=(t,e,i,n)=>{let r="",o=0;do r+=t.substring(o,n)+i,o=n+e.length,n=t.indexOf(e,o);while(~n);return r+t.substring(o)},Iv=(t=YE)=>{let e=t?WE:()=>String;return{isColorSupported:t,reset:e("\x1B[0m","\x1B[0m"),bold:e("\x1B[1m","\x1B[22m","\x1B[22m\x1B[1m"),dim:e("\x1B[2m","\x1B[22m","\x1B[22m\x1B[2m"),italic:e("\x1B[3m","\x1B[23m"),underline:e("\x1B[4m","\x1B[24m"),inverse:e("\x1B[7m","\x1B[27m"),hidden:e("\x1B[8m","\x1B[28m"),strikethrough:e("\x1B[9m","\x1B[29m"),black:e("\x1B[30m","\x1B[39m"),red:e("\x1B[31m","\x1B[39m"),green:e("\x1B[32m","\x1B[39m"),yellow:e("\x1B[33m","\x1B[39m"),blue:e("\x1B[34m","\x1B[39m"),magenta:e("\x1B[35m","\x1B[39m"),cyan:e("\x1B[36m","\x1B[39m"),white:e("\x1B[37m","\x1B[39m"),gray:e("\x1B[90m","\x1B[39m"),bgBlack:e("\x1B[40m","\x1B[49m"),bgRed:e("\x1B[41m","\x1B[49m"),bgGreen:e("\x1B[42m","\x1B[49m"),bgYellow:e("\x1B[43m","\x1B[49m"),bgBlue:e("\x1B[44m","\x1B[49m"),bgMagenta:e("\x1B[45m","\x1B[49m"),bgCyan:e("\x1B[46m","\x1B[49m"),bgWhite:e("\x1B[47m","\x1B[49m"),blackBright:e("\x1B[90m","\x1B[39m"),redBright:e("\x1B[91m","\x1B[39m"),greenBright:e("\x1B[92m","\x1B[39m"),yellowBright:e("\x1B[93m","\x1B[39m"),blueBright:e("\x1B[94m","\x1B[39m"),magentaBright:e("\x1B[95m","\x1B[39m"),cyanBright:e("\x1B[96m","\x1B[39m"),whiteBright:e("\x1B[97m","\x1B[39m"),bgBlackBright:e("\x1B[100m","\x1B[49m"),bgRedBright:e("\x1B[101m","\x1B[49m"),bgGreenBright:e("\x1B[102m","\x1B[49m"),bgYellowBright:e("\x1B[103m","\x1B[49m"),bgBlueBright:e("\x1B[104m","\x1B[49m"),bgMagentaBright:e("\x1B[105m","\x1B[49m"),bgCyanBright:e("\x1B[106m","\x1B[49m"),bgWhiteBright:e("\x1B[107m","\x1B[49m")}};lc.exports=Iv();lc.exports.createColors=Iv});import{EventEmitter as iu}from"events";function Is(t){return t==null?[]:Array.isArray(t)?t:[t]}function nu(t,e,i,n){var r,o=t[e],a=~n.string.indexOf(e)?i==null||i===!0?"":String(i):typeof i=="boolean"?i:~n.boolean.indexOf(e)?i==="false"?!1:i==="true"||(t._.push((r=+i,r*0===0?r:i)),!!i):(r=+i,r*0===0?r:i);t[e]=o==null?a:Array.isArray(o)?o.concat(a):[o,a]}function ru(t,e){t=t||[],e=e||{};var i,n,r,o,a,c={_:[]},l=0,v=0,A=0,u=t.length;let p=e.alias!==void 0,E=e.unknown!==void 0,f=e.default!==void 0;if(e.alias=e.alias||{},e.string=Is(e.string),e.boolean=Is(e.boolean),p)for(i in e.alias)for(n=e.alias[i]=Is(e.alias[i]),l=0;l<n.length;l++)(e.alias[n[l]]=n.concat(i)).splice(l,1);for(l=e.boolean.length;l-- >0;)for(n=e.alias[e.boolean[l]]||[],v=n.length;v-- >0;)e.boolean.push(n[v]);for(l=e.string.length;l-- >0;)for(n=e.alias[e.string[l]]||[],v=n.length;v-- >0;)e.string.push(n[v]);if(f){for(i in e.default)if(o=typeof e.default[i],n=e.alias[i]=e.alias[i]||[],e[o]!==void 0)for(e[o].push(i),l=0;l<n.length;l++)e[o].push(n[l])}let d=E?Object.keys(e.alias):[];for(l=0;l<u;l++){if(r=t[l],r==="--"){c._=c._.concat(t.slice(++l));break}for(v=0;v<r.length&&r.charCodeAt(v)===45;v++);if(v===0)c._.push(r);else if(r.substring(v,v+3)==="no-"){if(o=r.substring(v+3),E&&!~d.indexOf(o))return e.unknown(r);c[o]=!1}else{for(A=v+1;A<r.length&&r.charCodeAt(A)!==61;A++);for(o=r.substring(v,A),a=r.substring(++A)||l+1===u||(""+t[l+1]).charCodeAt(0)===45||t[++l],n=v===2?[o]:o,A=0;A<n.length;A++){if(o=n[A],E&&!~d.indexOf(o))return e.unknown("-".repeat(v)+o);nu(c,o,A+1<n.length||a,e)}}}if(f)for(i in e.default)c[i]===void 0&&(c[i]=e.default[i]);if(p)for(i in c)for(n=e.alias[i]||[];n.length>0;)c[n.shift()]=c[i];return c}var il=t=>t.replace(/[<[].+/,"").trim(),ou=t=>{let e=/<([^>]+)>/g,i=/\[([^\]]+)\]/g,n=[],r=c=>{let l=!1,v=c[1];return v.startsWith("...")&&(v=v.slice(3),l=!0),{required:c[0].startsWith("<"),value:v,variadic:l}},o;for(;o=e.exec(t);)n.push(r(o));let a;for(;a=i.exec(t);)n.push(r(a));return n},su=t=>{let e={alias:{},boolean:[]};for(let[i,n]of t.entries())n.names.length>1&&(e.alias[n.names[0]]=n.names.slice(1)),n.isBoolean&&(n.negated&&t.some((o,a)=>a!==i&&o.names.some(c=>n.names.includes(c))&&typeof o.required=="boolean")||e.boolean.push(n.names[0]));return e},el=t=>t.sort((e,i)=>e.length>i.length?-1:1)[0],tl=(t,e)=>t.length>=e?t:`${t}${" ".repeat(e-t.length)}`,au=t=>t.replace(/([a-z])-([a-z])/g,(e,i,n)=>i+n.toUpperCase()),cu=(t,e,i)=>{let n=0,r=e.length,o=t,a;for(;n<r;++n)a=o[e[n]],o=o[e[n]]=n===r-1?i:a??(~e[n+1].indexOf(".")||!(+e[n+1]>-1)?{}:[])},lu=(t,e)=>{for(let i of Object.keys(e)){let n=e[i];n.shouldTransform&&(t[i]=Array.prototype.concat.call([],t[i]),typeof n.transformFunction=="function"&&(t[i]=t[i].map(n.transformFunction)))}},vu=t=>{let e=/([^\\\/]+)$/.exec(t);return e?e[1]:""},nl=t=>t.split(".").map((e,i)=>i===0?au(e):e).join("."),_i=class extends Error{constructor(e){super(e),this.name=this.constructor.name,typeof Error.captureStackTrace=="function"?Error.captureStackTrace(this,this.constructor):this.stack=new Error(e).stack}},fs=class{constructor(e,i,n){this.rawName=e,this.description=i,this.config=Object.assign({},n),e=e.replace(/\.\*/g,""),this.negated=!1,this.names=il(e).split(",").map(r=>{let o=r.trim().replace(/^-{1,2}/,"");return o.startsWith("no-")&&(this.negated=!0,o=o.replace(/^no-/,"")),nl(o)}).sort((r,o)=>r.length>o.length?1:-1),this.name=this.names[this.names.length-1],this.negated&&this.config.default==null&&(this.config.default=!0),e.includes("<")?this.required=!0:e.includes("[")?this.required=!1:this.isBoolean=!0}},Au=process.argv,uu=`${process.platform}-${process.arch} node-${process.version}`,nr=class{constructor(e,i,n={},r){this.rawName=e,this.description=i,this.config=n,this.cli=r,this.options=[],this.aliasNames=[],this.name=il(e),this.args=ou(e),this.examples=[]}usage(e){return this.usageText=e,this}allowUnknownOptions(){return this.config.allowUnknownOptions=!0,this}ignoreOptionDefaultValue(){return this.config.ignoreOptionDefaultValue=!0,this}version(e,i="-v, --version"){return this.versionNumber=e,this.option(i,"Display version number"),this}example(e){return this.examples.push(e),this}option(e,i,n){let r=new fs(e,i,n);return this.options.push(r),this}alias(e){return this.aliasNames.push(e),this}action(e){return this.commandAction=e,this}isMatched(e){return this.name===e||this.aliasNames.includes(e)}get isDefaultCommand(){return this.name===""||this.aliasNames.includes("!")}get isGlobalCommand(){return this instanceof rr}hasOption(e){return e=e.split(".")[0],this.options.find(i=>i.names.includes(e))}outputHelp(){let{name:e,commands:i}=this.cli,{versionNumber:n,options:r,helpCallback:o}=this.cli.globalCommand,a=[{body:`${e}${n?`/${n}`:""}`}];if(a.push({title:"Usage",body:` $ ${e} ${this.usageText||this.rawName}`}),(this.isGlobalCommand||this.isDefaultCommand)&&i.length>0){let v=el(i.map(A=>A.rawName));a.push({title:"Commands",body:i.map(A=>` ${tl(A.rawName,v.length)} ${A.description}`).join(`
3
- `)}),a.push({title:"For more info, run any command with the `--help` flag",body:i.map(A=>` $ ${e}${A.name===""?"":` ${A.name}`} --help`).join(`
4
- `)})}let l=this.isGlobalCommand?r:[...this.options,...r||[]];if(!this.isGlobalCommand&&!this.isDefaultCommand&&(l=l.filter(v=>v.name!=="version")),l.length>0){let v=el(l.map(A=>A.rawName));a.push({title:"Options",body:l.map(A=>` ${tl(A.rawName,v.length)} ${A.description} ${A.config.default===void 0?"":`(default: ${A.config.default})`}`).join(`
5
- `)})}this.examples.length>0&&a.push({title:"Examples",body:this.examples.map(v=>typeof v=="function"?v(e):v).join(`
6
- `)}),o&&(a=o(a)||a),console.log(a.map(v=>v.title?`${v.title}:
7
- ${v.body}`:v.body).join(`
8
-
9
- `))}outputVersion(){let{name:e}=this.cli,{versionNumber:i}=this.cli.globalCommand;i&&console.log(`${e}/${i} ${uu}`)}checkRequiredArgs(){let e=this.args.filter(i=>i.required).length;if(this.cli.args.length<e)throw new _i(`missing required args for command \`${this.rawName}\``)}checkUnknownOptions(){let{options:e,globalCommand:i}=this.cli;if(!this.config.allowUnknownOptions){for(let n of Object.keys(e))if(n!=="--"&&!this.hasOption(n)&&!i.hasOption(n))throw new _i(`Unknown option \`${n.length>1?`--${n}`:`-${n}`}\``)}}checkOptionValue(){let{options:e,globalCommand:i}=this.cli,n=[...i.options,...this.options];for(let r of n){let o=e[r.name.split(".")[0]];if(r.required){let a=n.some(c=>c.negated&&c.names.includes(r.name));if(o===!0||o===!1&&!a)throw new _i(`option \`${r.rawName}\` value is missing`)}}}},rr=class extends nr{constructor(e){super("@@global@@","",{},e)}},ir=Object.assign,hs=class extends iu{constructor(e=""){super(),this.name=e,this.commands=[],this.rawArgs=[],this.args=[],this.options={},this.globalCommand=new rr(this),this.globalCommand.usage("<command> [options]")}usage(e){return this.globalCommand.usage(e),this}command(e,i,n){let r=new nr(e,i||"",n,this);return r.globalCommand=this.globalCommand,this.commands.push(r),r}option(e,i,n){return this.globalCommand.option(e,i,n),this}help(e){return this.globalCommand.option("-h, --help","Display this message"),this.globalCommand.helpCallback=e,this.showHelpOnExit=!0,this}version(e,i="-v, --version"){return this.globalCommand.version(e,i),this.showVersionOnExit=!0,this}example(e){return this.globalCommand.example(e),this}outputHelp(){this.matchedCommand?this.matchedCommand.outputHelp():this.globalCommand.outputHelp()}outputVersion(){this.globalCommand.outputVersion()}setParsedInfo({args:e,options:i},n,r){return this.args=e,this.options=i,n&&(this.matchedCommand=n),r&&(this.matchedCommandName=r),this}unsetMatchedCommand(){this.matchedCommand=void 0,this.matchedCommandName=void 0}parse(e=Au,{run:i=!0}={}){this.rawArgs=e,this.name||(this.name=e[1]?vu(e[1]):"cli");let n=!0;for(let o of this.commands){let a=this.mri(e.slice(2),o),c=a.args[0];if(o.isMatched(c)){n=!1;let l=ir(ir({},a),{args:a.args.slice(1)});this.setParsedInfo(l,o,c),this.emit(`command:${c}`,o)}}if(n){for(let o of this.commands)if(o.name===""){n=!1;let a=this.mri(e.slice(2),o);this.setParsedInfo(a,o),this.emit("command:!",o)}}if(n){let o=this.mri(e.slice(2));this.setParsedInfo(o)}this.options.help&&this.showHelpOnExit&&(this.outputHelp(),i=!1,this.unsetMatchedCommand()),this.options.version&&this.showVersionOnExit&&this.matchedCommandName==null&&(this.outputVersion(),i=!1,this.unsetMatchedCommand());let r={args:this.args,options:this.options};return i&&this.runMatchedCommand(),!this.matchedCommand&&this.args[0]&&this.emit("command:*"),r}mri(e,i){let n=[...this.globalCommand.options,...i?i.options:[]],r=su(n),o=[],a=e.indexOf("--");a>-1&&(o=e.slice(a+1),e=e.slice(0,a));let c=ru(e,r);c=Object.keys(c).reduce((p,E)=>ir(ir({},p),{[nl(E)]:c[E]}),{_:[]});let l=c._,v={"--":o},A=i&&i.config.ignoreOptionDefaultValue?i.config.ignoreOptionDefaultValue:this.globalCommand.config.ignoreOptionDefaultValue,u=Object.create(null);for(let p of n){if(!A&&p.config.default!==void 0)for(let E of p.names)v[E]=p.config.default;Array.isArray(p.config.type)&&u[p.name]===void 0&&(u[p.name]=Object.create(null),u[p.name].shouldTransform=!0,u[p.name].transformFunction=p.config.type[0])}for(let p of Object.keys(c))if(p!=="_"){let E=p.split(".");cu(v,E,c[p]),lu(v,u)}return{args:l,options:v}}runMatchedCommand(){let{args:e,options:i,matchedCommand:n}=this;if(!n||!n.commandAction)return;n.checkUnknownOptions(),n.checkOptionValue(),n.checkRequiredArgs();let r=[];return n.args.forEach((o,a)=>{o.variadic?r.push(e.slice(a)):r.push(e[a])}),r.push(i),n.commandAction.apply(this,r)}},rl=(t="")=>new hs(t);import{existsSync as XE}from"fs";import{join as HE}from"path";import{spawn as LE,spawnSync as _E}from"child_process";import mr from"node:process";var ol=(t=0)=>e=>`\x1B[${e+t}m`,sl=(t=0)=>e=>`\x1B[${38+t};5;${e}m`,al=(t=0)=>(e,i,n)=>`\x1B[${38+t};2;${e};${i};${n}m`,S={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]}},vf=Object.keys(S.modifier),mu=Object.keys(S.color),Eu=Object.keys(S.bgColor),Af=[...mu,...Eu];function pu(){let t=new Map;for(let[e,i]of Object.entries(S)){for(let[n,r]of Object.entries(i))S[n]={open:`\x1B[${r[0]}m`,close:`\x1B[${r[1]}m`},i[n]=S[n],t.set(r[0],r[1]);Object.defineProperty(S,e,{value:i,enumerable:!1})}return Object.defineProperty(S,"codes",{value:t,enumerable:!1}),S.color.close="\x1B[39m",S.bgColor.close="\x1B[49m",S.color.ansi=ol(),S.color.ansi256=sl(),S.color.ansi16m=al(),S.bgColor.ansi=ol(10),S.bgColor.ansi256=sl(10),S.bgColor.ansi16m=al(10),Object.defineProperties(S,{rgbToAnsi256:{value(e,i,n){return e===i&&i===n?e<8?16:e>248?231:Math.round((e-8)/247*24)+232:16+36*Math.round(e/255*5)+6*Math.round(i/255*5)+Math.round(n/255*5)},enumerable:!1},hexToRgb:{value(e){let i=/[a-f\d]{6}|[a-f\d]{3}/i.exec(e.toString(16));if(!i)return[0,0,0];let[n]=i;n.length===3&&(n=[...n].map(o=>o+o).join(""));let r=Number.parseInt(n,16);return[r>>16&255,r>>8&255,r&255]},enumerable:!1},hexToAnsi256:{value:e=>S.rgbToAnsi256(...S.hexToRgb(e)),enumerable:!1},ansi256ToAnsi:{value(e){if(e<8)return 30+e;if(e<16)return 90+(e-8);let i,n,r;if(e>=232)i=((e-232)*10+8)/255,n=i,r=i;else{e-=16;let c=e%36;i=Math.floor(e/36)/5,n=Math.floor(c/6)/5,r=c%6/5}let o=Math.max(i,n,r)*2;if(o===0)return 30;let a=30+(Math.round(r)<<2|Math.round(n)<<1|Math.round(i));return o===2&&(a+=60),a},enumerable:!1},rgbToAnsi:{value:(e,i,n)=>S.ansi256ToAnsi(S.rgbToAnsi256(e,i,n)),enumerable:!1},hexToAnsi:{value:e=>S.ansi256ToAnsi(S.hexToAnsi256(e)),enumerable:!1}}),S}var Iu=pu(),Re=Iu;import ds from"node:process";import fu from"node:os";import cl from"node:tty";function ue(t,e=globalThis.Deno?globalThis.Deno.args:ds.argv){let i=t.startsWith("-")?"":t.length===1?"-":"--",n=e.indexOf(i+t),r=e.indexOf("--");return n!==-1&&(r===-1||n<r)}var{env:Y}=ds,or;ue("no-color")||ue("no-colors")||ue("color=false")||ue("color=never")?or=0:(ue("color")||ue("colors")||ue("color=true")||ue("color=always"))&&(or=1);function hu(){if("FORCE_COLOR"in Y)return Y.FORCE_COLOR==="true"?1:Y.FORCE_COLOR==="false"?0:Y.FORCE_COLOR.length===0?1:Math.min(Number.parseInt(Y.FORCE_COLOR,10),3)}function du(t){return t===0?!1:{level:t,hasBasic:!0,has256:t>=2,has16m:t>=3}}function Ru(t,{streamIsTTY:e,sniffFlags:i=!0}={}){let n=hu();n!==void 0&&(or=n);let r=i?or:n;if(r===0)return 0;if(i){if(ue("color=16m")||ue("color=full")||ue("color=truecolor"))return 3;if(ue("color=256"))return 2}if("TF_BUILD"in Y&&"AGENT_NAME"in Y)return 1;if(t&&!e&&r===void 0)return 0;let o=r||0;if(Y.TERM==="dumb")return o;if(ds.platform==="win32"){let a=fu.release().split(".");return Number(a[0])>=10&&Number(a[2])>=10586?Number(a[2])>=14931?3:2:1}if("CI"in Y)return["GITHUB_ACTIONS","GITEA_ACTIONS","CIRCLECI"].some(a=>a in Y)?3:["TRAVIS","APPVEYOR","GITLAB_CI","BUILDKITE","DRONE"].some(a=>a in Y)||Y.CI_NAME==="codeship"?1:o;if("TEAMCITY_VERSION"in Y)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(Y.TEAMCITY_VERSION)?1:0;if(Y.COLORTERM==="truecolor"||Y.TERM==="xterm-kitty"||Y.TERM==="xterm-ghostty"||Y.TERM==="wezterm")return 3;if("TERM_PROGRAM"in Y){let a=Number.parseInt((Y.TERM_PROGRAM_VERSION||"").split(".")[0],10);switch(Y.TERM_PROGRAM){case"iTerm.app":return a>=3?3:2;case"Apple_Terminal":return 2}}return/-256(color)?$/i.test(Y.TERM)?2:/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(Y.TERM)||"COLORTERM"in Y?1:o}function ll(t,e={}){let i=Ru(t,{streamIsTTY:t&&t.isTTY,...e});return du(i)}var zu={stdout:ll({isTTY:cl.isatty(1)}),stderr:ll({isTTY:cl.isatty(2)})},vl=zu;function Al(t,e,i){let n=t.indexOf(e);if(n===-1)return t;let r=e.length,o=0,a="";do a+=t.slice(o,n)+e+i,o=n+r,n=t.indexOf(e,o);while(n!==-1);return a+=t.slice(o),a}function ul(t,e,i,n){let r=0,o="";do{let a=t[n-1]==="\r";o+=t.slice(r,a?n-1:n)+e+(a?`\r
2
+ var PA=Object.create;var _a=Object.defineProperty;var QA=Object.getOwnPropertyDescriptor;var BA=Object.getOwnPropertyNames;var JA=Object.getPrototypeOf,ZA=Object.prototype.hasOwnProperty;var yA=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,i)=>(typeof require<"u"?require:e)[i]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var Y=(t,e)=>()=>(t&&(e=t(t=0)),e);var pr=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),sm=(t,e)=>{for(var i in e)_a(t,i,{get:e[i],enumerable:!0})},qA=(t,e,i,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of BA(e))!ZA.call(t,s)&&s!==i&&_a(t,s,{get:()=>e[s],enumerable:!(n=QA(e,s))||n.enumerable});return t};var Ar=(t,e,i)=>(i=t!=null?PA(JA(t)):{},qA(e||!t||!t.__esModule?_a(i,"default",{value:t,enumerable:!0}):i,t));var Mm=pr((ez,Yd)=>{Yd.exports={dots:{interval:80,frames:["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"]},dots2:{interval:80,frames:["\u28FE","\u28FD","\u28FB","\u28BF","\u287F","\u28DF","\u28EF","\u28F7"]},dots3:{interval:80,frames:["\u280B","\u2819","\u281A","\u281E","\u2816","\u2826","\u2834","\u2832","\u2833","\u2813"]},dots4:{interval:80,frames:["\u2804","\u2806","\u2807","\u280B","\u2819","\u2838","\u2830","\u2820","\u2830","\u2838","\u2819","\u280B","\u2807","\u2806"]},dots5:{interval:80,frames:["\u280B","\u2819","\u281A","\u2812","\u2802","\u2802","\u2812","\u2832","\u2834","\u2826","\u2816","\u2812","\u2810","\u2810","\u2812","\u2813","\u280B"]},dots6:{interval:80,frames:["\u2801","\u2809","\u2819","\u281A","\u2812","\u2802","\u2802","\u2812","\u2832","\u2834","\u2824","\u2804","\u2804","\u2824","\u2834","\u2832","\u2812","\u2802","\u2802","\u2812","\u281A","\u2819","\u2809","\u2801"]},dots7:{interval:80,frames:["\u2808","\u2809","\u280B","\u2813","\u2812","\u2810","\u2810","\u2812","\u2816","\u2826","\u2824","\u2820","\u2820","\u2824","\u2826","\u2816","\u2812","\u2810","\u2810","\u2812","\u2813","\u280B","\u2809","\u2808"]},dots8:{interval:80,frames:["\u2801","\u2801","\u2809","\u2819","\u281A","\u2812","\u2802","\u2802","\u2812","\u2832","\u2834","\u2824","\u2804","\u2804","\u2824","\u2820","\u2820","\u2824","\u2826","\u2816","\u2812","\u2810","\u2810","\u2812","\u2813","\u280B","\u2809","\u2808","\u2808"]},dots9:{interval:80,frames:["\u28B9","\u28BA","\u28BC","\u28F8","\u28C7","\u2867","\u2857","\u284F"]},dots10:{interval:80,frames:["\u2884","\u2882","\u2881","\u2841","\u2848","\u2850","\u2860"]},dots11:{interval:100,frames:["\u2801","\u2802","\u2804","\u2840","\u2880","\u2820","\u2810","\u2808"]},dots12:{interval:80,frames:["\u2880\u2800","\u2840\u2800","\u2804\u2800","\u2882\u2800","\u2842\u2800","\u2805\u2800","\u2883\u2800","\u2843\u2800","\u280D\u2800","\u288B\u2800","\u284B\u2800","\u280D\u2801","\u288B\u2801","\u284B\u2801","\u280D\u2809","\u280B\u2809","\u280B\u2809","\u2809\u2819","\u2809\u2819","\u2809\u2829","\u2808\u2899","\u2808\u2859","\u2888\u2829","\u2840\u2899","\u2804\u2859","\u2882\u2829","\u2842\u2898","\u2805\u2858","\u2883\u2828","\u2843\u2890","\u280D\u2850","\u288B\u2820","\u284B\u2880","\u280D\u2841","\u288B\u2801","\u284B\u2801","\u280D\u2809","\u280B\u2809","\u280B\u2809","\u2809\u2819","\u2809\u2819","\u2809\u2829","\u2808\u2899","\u2808\u2859","\u2808\u2829","\u2800\u2899","\u2800\u2859","\u2800\u2829","\u2800\u2898","\u2800\u2858","\u2800\u2828","\u2800\u2890","\u2800\u2850","\u2800\u2820","\u2800\u2880","\u2800\u2840"]},dots13:{interval:80,frames:["\u28FC","\u28F9","\u28BB","\u283F","\u285F","\u28CF","\u28E7","\u28F6"]},dots8Bit:{interval:80,frames:["\u2800","\u2801","\u2802","\u2803","\u2804","\u2805","\u2806","\u2807","\u2840","\u2841","\u2842","\u2843","\u2844","\u2845","\u2846","\u2847","\u2808","\u2809","\u280A","\u280B","\u280C","\u280D","\u280E","\u280F","\u2848","\u2849","\u284A","\u284B","\u284C","\u284D","\u284E","\u284F","\u2810","\u2811","\u2812","\u2813","\u2814","\u2815","\u2816","\u2817","\u2850","\u2851","\u2852","\u2853","\u2854","\u2855","\u2856","\u2857","\u2818","\u2819","\u281A","\u281B","\u281C","\u281D","\u281E","\u281F","\u2858","\u2859","\u285A","\u285B","\u285C","\u285D","\u285E","\u285F","\u2820","\u2821","\u2822","\u2823","\u2824","\u2825","\u2826","\u2827","\u2860","\u2861","\u2862","\u2863","\u2864","\u2865","\u2866","\u2867","\u2828","\u2829","\u282A","\u282B","\u282C","\u282D","\u282E","\u282F","\u2868","\u2869","\u286A","\u286B","\u286C","\u286D","\u286E","\u286F","\u2830","\u2831","\u2832","\u2833","\u2834","\u2835","\u2836","\u2837","\u2870","\u2871","\u2872","\u2873","\u2874","\u2875","\u2876","\u2877","\u2838","\u2839","\u283A","\u283B","\u283C","\u283D","\u283E","\u283F","\u2878","\u2879","\u287A","\u287B","\u287C","\u287D","\u287E","\u287F","\u2880","\u2881","\u2882","\u2883","\u2884","\u2885","\u2886","\u2887","\u28C0","\u28C1","\u28C2","\u28C3","\u28C4","\u28C5","\u28C6","\u28C7","\u2888","\u2889","\u288A","\u288B","\u288C","\u288D","\u288E","\u288F","\u28C8","\u28C9","\u28CA","\u28CB","\u28CC","\u28CD","\u28CE","\u28CF","\u2890","\u2891","\u2892","\u2893","\u2894","\u2895","\u2896","\u2897","\u28D0","\u28D1","\u28D2","\u28D3","\u28D4","\u28D5","\u28D6","\u28D7","\u2898","\u2899","\u289A","\u289B","\u289C","\u289D","\u289E","\u289F","\u28D8","\u28D9","\u28DA","\u28DB","\u28DC","\u28DD","\u28DE","\u28DF","\u28A0","\u28A1","\u28A2","\u28A3","\u28A4","\u28A5","\u28A6","\u28A7","\u28E0","\u28E1","\u28E2","\u28E3","\u28E4","\u28E5","\u28E6","\u28E7","\u28A8","\u28A9","\u28AA","\u28AB","\u28AC","\u28AD","\u28AE","\u28AF","\u28E8","\u28E9","\u28EA","\u28EB","\u28EC","\u28ED","\u28EE","\u28EF","\u28B0","\u28B1","\u28B2","\u28B3","\u28B4","\u28B5","\u28B6","\u28B7","\u28F0","\u28F1","\u28F2","\u28F3","\u28F4","\u28F5","\u28F6","\u28F7","\u28B8","\u28B9","\u28BA","\u28BB","\u28BC","\u28BD","\u28BE","\u28BF","\u28F8","\u28F9","\u28FA","\u28FB","\u28FC","\u28FD","\u28FE","\u28FF"]},sand:{interval:80,frames:["\u2801","\u2802","\u2804","\u2840","\u2848","\u2850","\u2860","\u28C0","\u28C1","\u28C2","\u28C4","\u28CC","\u28D4","\u28E4","\u28E5","\u28E6","\u28EE","\u28F6","\u28F7","\u28FF","\u287F","\u283F","\u289F","\u281F","\u285B","\u281B","\u282B","\u288B","\u280B","\u280D","\u2849","\u2809","\u2811","\u2821","\u2881"]},line:{interval:130,frames:["-","\\","|","/"]},line2:{interval:100,frames:["\u2802","-","\u2013","\u2014","\u2013","-"]},pipe:{interval:100,frames:["\u2524","\u2518","\u2534","\u2514","\u251C","\u250C","\u252C","\u2510"]},simpleDots:{interval:400,frames:[". ",".. ","..."," "]},simpleDotsScrolling:{interval:200,frames:[". ",".. ","..."," .."," ."," "]},star:{interval:70,frames:["\u2736","\u2738","\u2739","\u273A","\u2739","\u2737"]},star2:{interval:80,frames:["+","x","*"]},flip:{interval:70,frames:["_","_","_","-","`","`","'","\xB4","-","_","_","_"]},hamburger:{interval:100,frames:["\u2631","\u2632","\u2634"]},growVertical:{interval:120,frames:["\u2581","\u2583","\u2584","\u2585","\u2586","\u2587","\u2586","\u2585","\u2584","\u2583"]},growHorizontal:{interval:120,frames:["\u258F","\u258E","\u258D","\u258C","\u258B","\u258A","\u2589","\u258A","\u258B","\u258C","\u258D","\u258E"]},balloon:{interval:140,frames:[" ",".","o","O","@","*"," "]},balloon2:{interval:120,frames:[".","o","O","\xB0","O","o","."]},noise:{interval:100,frames:["\u2593","\u2592","\u2591"]},bounce:{interval:120,frames:["\u2801","\u2802","\u2804","\u2802"]},boxBounce:{interval:120,frames:["\u2596","\u2598","\u259D","\u2597"]},boxBounce2:{interval:100,frames:["\u258C","\u2580","\u2590","\u2584"]},triangle:{interval:50,frames:["\u25E2","\u25E3","\u25E4","\u25E5"]},binary:{interval:80,frames:["010010","001100","100101","111010","111101","010111","101011","111000","110011","110101"]},arc:{interval:100,frames:["\u25DC","\u25E0","\u25DD","\u25DE","\u25E1","\u25DF"]},circle:{interval:120,frames:["\u25E1","\u2299","\u25E0"]},squareCorners:{interval:180,frames:["\u25F0","\u25F3","\u25F2","\u25F1"]},circleQuarters:{interval:120,frames:["\u25F4","\u25F7","\u25F6","\u25F5"]},circleHalves:{interval:50,frames:["\u25D0","\u25D3","\u25D1","\u25D2"]},squish:{interval:100,frames:["\u256B","\u256A"]},toggle:{interval:250,frames:["\u22B6","\u22B7"]},toggle2:{interval:80,frames:["\u25AB","\u25AA"]},toggle3:{interval:120,frames:["\u25A1","\u25A0"]},toggle4:{interval:100,frames:["\u25A0","\u25A1","\u25AA","\u25AB"]},toggle5:{interval:100,frames:["\u25AE","\u25AF"]},toggle6:{interval:300,frames:["\u101D","\u1040"]},toggle7:{interval:80,frames:["\u29BE","\u29BF"]},toggle8:{interval:100,frames:["\u25CD","\u25CC"]},toggle9:{interval:100,frames:["\u25C9","\u25CE"]},toggle10:{interval:100,frames:["\u3282","\u3280","\u3281"]},toggle11:{interval:50,frames:["\u29C7","\u29C6"]},toggle12:{interval:120,frames:["\u2617","\u2616"]},toggle13:{interval:80,frames:["=","*","-"]},arrow:{interval:100,frames:["\u2190","\u2196","\u2191","\u2197","\u2192","\u2198","\u2193","\u2199"]},arrow2:{interval:80,frames:["\u2B06\uFE0F ","\u2197\uFE0F ","\u27A1\uFE0F ","\u2198\uFE0F ","\u2B07\uFE0F ","\u2199\uFE0F ","\u2B05\uFE0F ","\u2196\uFE0F "]},arrow3:{interval:120,frames:["\u25B9\u25B9\u25B9\u25B9\u25B9","\u25B8\u25B9\u25B9\u25B9\u25B9","\u25B9\u25B8\u25B9\u25B9\u25B9","\u25B9\u25B9\u25B8\u25B9\u25B9","\u25B9\u25B9\u25B9\u25B8\u25B9","\u25B9\u25B9\u25B9\u25B9\u25B8"]},bouncingBar:{interval:80,frames:["[ ]","[= ]","[== ]","[=== ]","[====]","[ ===]","[ ==]","[ =]","[ ]","[ =]","[ ==]","[ ===]","[====]","[=== ]","[== ]","[= ]"]},bouncingBall:{interval:80,frames:["( \u25CF )","( \u25CF )","( \u25CF )","( \u25CF )","( \u25CF)","( \u25CF )","( \u25CF )","( \u25CF )","( \u25CF )","(\u25CF )"]},smiley:{interval:200,frames:["\u{1F604} ","\u{1F61D} "]},monkey:{interval:300,frames:["\u{1F648} ","\u{1F648} ","\u{1F649} ","\u{1F64A} "]},hearts:{interval:100,frames:["\u{1F49B} ","\u{1F499} ","\u{1F49C} ","\u{1F49A} ","\u2764\uFE0F "]},clock:{interval:100,frames:["\u{1F55B} ","\u{1F550} ","\u{1F551} ","\u{1F552} ","\u{1F553} ","\u{1F554} ","\u{1F555} ","\u{1F556} ","\u{1F557} ","\u{1F558} ","\u{1F559} ","\u{1F55A} "]},earth:{interval:180,frames:["\u{1F30D} ","\u{1F30E} ","\u{1F30F} "]},material:{interval:17,frames:["\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581","\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581","\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581","\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581","\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581","\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581","\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581","\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581","\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581","\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581","\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581","\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581","\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588","\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588","\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588","\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588","\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588","\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588","\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588","\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588","\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581","\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581\u2581","\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581","\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581\u2581","\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581\u2581","\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581","\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581","\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581\u2581","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581\u2581","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2581","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2588","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581","\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581\u2581"]},moon:{interval:80,frames:["\u{1F311} ","\u{1F312} ","\u{1F313} ","\u{1F314} ","\u{1F315} ","\u{1F316} ","\u{1F317} ","\u{1F318} "]},runner:{interval:140,frames:["\u{1F6B6} ","\u{1F3C3} "]},pong:{interval:80,frames:["\u2590\u2802 \u258C","\u2590\u2808 \u258C","\u2590 \u2802 \u258C","\u2590 \u2820 \u258C","\u2590 \u2840 \u258C","\u2590 \u2820 \u258C","\u2590 \u2802 \u258C","\u2590 \u2808 \u258C","\u2590 \u2802 \u258C","\u2590 \u2820 \u258C","\u2590 \u2840 \u258C","\u2590 \u2820 \u258C","\u2590 \u2802 \u258C","\u2590 \u2808 \u258C","\u2590 \u2802\u258C","\u2590 \u2820\u258C","\u2590 \u2840\u258C","\u2590 \u2820 \u258C","\u2590 \u2802 \u258C","\u2590 \u2808 \u258C","\u2590 \u2802 \u258C","\u2590 \u2820 \u258C","\u2590 \u2840 \u258C","\u2590 \u2820 \u258C","\u2590 \u2802 \u258C","\u2590 \u2808 \u258C","\u2590 \u2802 \u258C","\u2590 \u2820 \u258C","\u2590 \u2840 \u258C","\u2590\u2820 \u258C"]},shark:{interval:120,frames:["\u2590|\\____________\u258C","\u2590_|\\___________\u258C","\u2590__|\\__________\u258C","\u2590___|\\_________\u258C","\u2590____|\\________\u258C","\u2590_____|\\_______\u258C","\u2590______|\\______\u258C","\u2590_______|\\_____\u258C","\u2590________|\\____\u258C","\u2590_________|\\___\u258C","\u2590__________|\\__\u258C","\u2590___________|\\_\u258C","\u2590____________|\\\u258C","\u2590____________/|\u258C","\u2590___________/|_\u258C","\u2590__________/|__\u258C","\u2590_________/|___\u258C","\u2590________/|____\u258C","\u2590_______/|_____\u258C","\u2590______/|______\u258C","\u2590_____/|_______\u258C","\u2590____/|________\u258C","\u2590___/|_________\u258C","\u2590__/|__________\u258C","\u2590_/|___________\u258C","\u2590/|____________\u258C"]},dqpb:{interval:100,frames:["d","q","p","b"]},weather:{interval:100,frames:["\u2600\uFE0F ","\u2600\uFE0F ","\u2600\uFE0F ","\u{1F324} ","\u26C5\uFE0F ","\u{1F325} ","\u2601\uFE0F ","\u{1F327} ","\u{1F328} ","\u{1F327} ","\u{1F328} ","\u{1F327} ","\u{1F328} ","\u26C8 ","\u{1F328} ","\u{1F327} ","\u{1F328} ","\u2601\uFE0F ","\u{1F325} ","\u26C5\uFE0F ","\u{1F324} ","\u2600\uFE0F ","\u2600\uFE0F "]},christmas:{interval:400,frames:["\u{1F332}","\u{1F384}"]},grenade:{interval:80,frames:["\u060C ","\u2032 "," \xB4 "," \u203E "," \u2E0C"," \u2E0A"," |"," \u204E"," \u2055"," \u0DF4 "," \u2053"," "," "," "]},point:{interval:125,frames:["\u2219\u2219\u2219","\u25CF\u2219\u2219","\u2219\u25CF\u2219","\u2219\u2219\u25CF","\u2219\u2219\u2219"]},layer:{interval:150,frames:["-","=","\u2261"]},betaWave:{interval:80,frames:["\u03C1\u03B2\u03B2\u03B2\u03B2\u03B2\u03B2","\u03B2\u03C1\u03B2\u03B2\u03B2\u03B2\u03B2","\u03B2\u03B2\u03C1\u03B2\u03B2\u03B2\u03B2","\u03B2\u03B2\u03B2\u03C1\u03B2\u03B2\u03B2","\u03B2\u03B2\u03B2\u03B2\u03C1\u03B2\u03B2","\u03B2\u03B2\u03B2\u03B2\u03B2\u03C1\u03B2","\u03B2\u03B2\u03B2\u03B2\u03B2\u03B2\u03C1"]},fingerDance:{interval:160,frames:["\u{1F918} ","\u{1F91F} ","\u{1F596} ","\u270B ","\u{1F91A} ","\u{1F446} "]},fistBump:{interval:80,frames:["\u{1F91C}\u3000\u3000\u3000\u3000\u{1F91B} ","\u{1F91C}\u3000\u3000\u3000\u3000\u{1F91B} ","\u{1F91C}\u3000\u3000\u3000\u3000\u{1F91B} ","\u3000\u{1F91C}\u3000\u3000\u{1F91B}\u3000 ","\u3000\u3000\u{1F91C}\u{1F91B}\u3000\u3000 ","\u3000\u{1F91C}\u2728\u{1F91B}\u3000\u3000 ","\u{1F91C}\u3000\u2728\u3000\u{1F91B}\u3000 "]},soccerHeader:{interval:80,frames:[" \u{1F9D1}\u26BD\uFE0F \u{1F9D1} ","\u{1F9D1} \u26BD\uFE0F \u{1F9D1} ","\u{1F9D1} \u26BD\uFE0F \u{1F9D1} ","\u{1F9D1} \u26BD\uFE0F \u{1F9D1} ","\u{1F9D1} \u26BD\uFE0F \u{1F9D1} ","\u{1F9D1} \u26BD\uFE0F \u{1F9D1} ","\u{1F9D1} \u26BD\uFE0F\u{1F9D1} ","\u{1F9D1} \u26BD\uFE0F \u{1F9D1} ","\u{1F9D1} \u26BD\uFE0F \u{1F9D1} ","\u{1F9D1} \u26BD\uFE0F \u{1F9D1} ","\u{1F9D1} \u26BD\uFE0F \u{1F9D1} ","\u{1F9D1} \u26BD\uFE0F \u{1F9D1} "]},mindblown:{interval:160,frames:["\u{1F610} ","\u{1F610} ","\u{1F62E} ","\u{1F62E} ","\u{1F626} ","\u{1F626} ","\u{1F627} ","\u{1F627} ","\u{1F92F} ","\u{1F4A5} ","\u2728 ","\u3000 ","\u3000 ","\u3000 "]},speaker:{interval:160,frames:["\u{1F508} ","\u{1F509} ","\u{1F50A} ","\u{1F509} "]},orangePulse:{interval:100,frames:["\u{1F538} ","\u{1F536} ","\u{1F7E0} ","\u{1F7E0} ","\u{1F536} "]},bluePulse:{interval:100,frames:["\u{1F539} ","\u{1F537} ","\u{1F535} ","\u{1F535} ","\u{1F537} "]},orangeBluePulse:{interval:100,frames:["\u{1F538} ","\u{1F536} ","\u{1F7E0} ","\u{1F7E0} ","\u{1F536} ","\u{1F539} ","\u{1F537} ","\u{1F535} ","\u{1F535} ","\u{1F537} "]},timeTravel:{interval:100,frames:["\u{1F55B} ","\u{1F55A} ","\u{1F559} ","\u{1F558} ","\u{1F557} ","\u{1F556} ","\u{1F555} ","\u{1F554} ","\u{1F553} ","\u{1F552} ","\u{1F551} ","\u{1F550} "]},aesthetic:{interval:80,frames:["\u25B0\u25B1\u25B1\u25B1\u25B1\u25B1\u25B1","\u25B0\u25B0\u25B1\u25B1\u25B1\u25B1\u25B1","\u25B0\u25B0\u25B0\u25B1\u25B1\u25B1\u25B1","\u25B0\u25B0\u25B0\u25B0\u25B1\u25B1\u25B1","\u25B0\u25B0\u25B0\u25B0\u25B0\u25B1\u25B1","\u25B0\u25B0\u25B0\u25B0\u25B0\u25B0\u25B1","\u25B0\u25B0\u25B0\u25B0\u25B0\u25B0\u25B0","\u25B0\u25B1\u25B1\u25B1\u25B1\u25B1\u25B1"]},dwarfFortress:{interval:80,frames:[" \u2588\u2588\u2588\u2588\u2588\u2588\xA3\xA3\xA3 ","\u263A\u2588\u2588\u2588\u2588\u2588\u2588\xA3\xA3\xA3 ","\u263A\u2588\u2588\u2588\u2588\u2588\u2588\xA3\xA3\xA3 ","\u263A\u2593\u2588\u2588\u2588\u2588\u2588\xA3\xA3\xA3 ","\u263A\u2593\u2588\u2588\u2588\u2588\u2588\xA3\xA3\xA3 ","\u263A\u2592\u2588\u2588\u2588\u2588\u2588\xA3\xA3\xA3 ","\u263A\u2592\u2588\u2588\u2588\u2588\u2588\xA3\xA3\xA3 ","\u263A\u2591\u2588\u2588\u2588\u2588\u2588\xA3\xA3\xA3 ","\u263A\u2591\u2588\u2588\u2588\u2588\u2588\xA3\xA3\xA3 ","\u263A \u2588\u2588\u2588\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2588\u2588\u2588\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2588\u2588\u2588\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2593\u2588\u2588\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2593\u2588\u2588\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2592\u2588\u2588\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2592\u2588\u2588\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2591\u2588\u2588\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2591\u2588\u2588\u2588\u2588\xA3\xA3\xA3 "," \u263A \u2588\u2588\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2588\u2588\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2588\u2588\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2593\u2588\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2593\u2588\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2592\u2588\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2592\u2588\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2591\u2588\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2591\u2588\u2588\u2588\xA3\xA3\xA3 "," \u263A \u2588\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2588\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2588\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2593\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2593\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2592\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2592\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2591\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2591\u2588\u2588\xA3\xA3\xA3 "," \u263A \u2588\u2588\xA3\xA3\xA3 "," \u263A\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2588\u2588\xA3\xA3\xA3 "," \u263A\u2593\u2588\xA3\xA3\xA3 "," \u263A\u2593\u2588\xA3\xA3\xA3 "," \u263A\u2592\u2588\xA3\xA3\xA3 "," \u263A\u2592\u2588\xA3\xA3\xA3 "," \u263A\u2591\u2588\xA3\xA3\xA3 "," \u263A\u2591\u2588\xA3\xA3\xA3 "," \u263A \u2588\xA3\xA3\xA3 "," \u263A\u2588\xA3\xA3\xA3 "," \u263A\u2588\xA3\xA3\xA3 "," \u263A\u2593\xA3\xA3\xA3 "," \u263A\u2593\xA3\xA3\xA3 "," \u263A\u2592\xA3\xA3\xA3 "," \u263A\u2592\xA3\xA3\xA3 "," \u263A\u2591\xA3\xA3\xA3 "," \u263A\u2591\xA3\xA3\xA3 "," \u263A \xA3\xA3\xA3 "," \u263A\xA3\xA3\xA3 "," \u263A\xA3\xA3\xA3 "," \u263A\u2593\xA3\xA3 "," \u263A\u2593\xA3\xA3 "," \u263A\u2592\xA3\xA3 "," \u263A\u2592\xA3\xA3 "," \u263A\u2591\xA3\xA3 "," \u263A\u2591\xA3\xA3 "," \u263A \xA3\xA3 "," \u263A\xA3\xA3 "," \u263A\xA3\xA3 "," \u263A\u2593\xA3 "," \u263A\u2593\xA3 "," \u263A\u2592\xA3 "," \u263A\u2592\xA3 "," \u263A\u2591\xA3 "," \u263A\u2591\xA3 "," \u263A \xA3 "," \u263A\xA3 "," \u263A\xA3 "," \u263A\u2593 "," \u263A\u2593 "," \u263A\u2592 "," \u263A\u2592 "," \u263A\u2591 "," \u263A\u2591 "," \u263A "," \u263A &"," \u263A \u263C&"," \u263A \u263C &"," \u263A\u263C &"," \u263A\u263C & "," \u203C & "," \u263A & "," \u203C & "," \u263A & "," \u203C & "," \u263A & ","\u203C & "," & "," & "," & \u2591 "," & \u2592 "," & \u2593 "," & \xA3 "," & \u2591\xA3 "," & \u2592\xA3 "," & \u2593\xA3 "," & \xA3\xA3 "," & \u2591\xA3\xA3 "," & \u2592\xA3\xA3 ","& \u2593\xA3\xA3 ","& \xA3\xA3\xA3 "," \u2591\xA3\xA3\xA3 "," \u2592\xA3\xA3\xA3 "," \u2593\xA3\xA3\xA3 "," \u2588\xA3\xA3\xA3 "," \u2591\u2588\xA3\xA3\xA3 "," \u2592\u2588\xA3\xA3\xA3 "," \u2593\u2588\xA3\xA3\xA3 "," \u2588\u2588\xA3\xA3\xA3 "," \u2591\u2588\u2588\xA3\xA3\xA3 "," \u2592\u2588\u2588\xA3\xA3\xA3 "," \u2593\u2588\u2588\xA3\xA3\xA3 "," \u2588\u2588\u2588\xA3\xA3\xA3 "," \u2591\u2588\u2588\u2588\xA3\xA3\xA3 "," \u2592\u2588\u2588\u2588\xA3\xA3\xA3 "," \u2593\u2588\u2588\u2588\xA3\xA3\xA3 "," \u2588\u2588\u2588\u2588\xA3\xA3\xA3 "," \u2591\u2588\u2588\u2588\u2588\xA3\xA3\xA3 "," \u2592\u2588\u2588\u2588\u2588\xA3\xA3\xA3 "," \u2593\u2588\u2588\u2588\u2588\xA3\xA3\xA3 "," \u2588\u2588\u2588\u2588\u2588\xA3\xA3\xA3 "," \u2591\u2588\u2588\u2588\u2588\u2588\xA3\xA3\xA3 "," \u2592\u2588\u2588\u2588\u2588\u2588\xA3\xA3\xA3 "," \u2593\u2588\u2588\u2588\u2588\u2588\xA3\xA3\xA3 "," \u2588\u2588\u2588\u2588\u2588\u2588\xA3\xA3\xA3 "," \u2588\u2588\u2588\u2588\u2588\u2588\xA3\xA3\xA3 "]}}});var Ac=pr((tz,Wm)=>{"use strict";var Sr=Object.assign({},Mm()),Ym=Object.keys(Sr);Object.defineProperty(Sr,"random",{get(){let t=Math.floor(Math.random()*Ym.length),e=Ym[t];return Sr[e]}});Wm.exports=Sr});var Vm=pr((Az,km)=>{km.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});import{homedir as bm}from"os";import{join as ne}from"path";function Mr(t=process.cwd()){return ne(t,mn)}function Sc(t=process.cwd()){return ne(t,mn,Bd)}function Gc(t=process.cwd()){return ne(t,mn,Jd)}function Wi(t=process.cwd()){return ne(t,mn,Zd)}function as(t=process.cwd()){return ne(t,mn,"agents")}function Ci(t=process.cwd()){return ne(t,mn,"extensions")}function vn(t=process.cwd()){return ne(t,Qd)}function ge(t){return t?t.replace(/^[A-Za-z]:/,e=>e.replace(":","")).replace(/[\\/]+/g,"-").replace(/[^a-zA-Z0-9-]/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,""):""}function xt(t){return ne(jc,t)}function Oi(t,e){return ne(xt(t),`gk-session-${e}.json`)}function cs(t,e){return ne(xt(t),`gk-project-${e}.json`)}var Pd,jc,xc,Vz,un,Nz,mn,Qd,Bd,Jd,Zd,k=Y(()=>{"use strict";Pd=ne(bm(),".gemkit"),jc=ne(Pd,"projects"),xc=ne(bm(),".gemini"),Vz=ne(xc,"config"),un=ne(xc,"cache"),Nz=ne(xc,"tmp"),mn=".gemini",Qd="plans",Bd=".gk.json",Jd="metadata.json",Zd=".env"});var zv=pr(($S,wl)=>{var Bo=process||{},Ev=Bo.argv||[],Qo=Bo.env||{},gh=!(Qo.NO_COLOR||Ev.includes("--no-color"))&&(!!Qo.FORCE_COLOR||Ev.includes("--color")||Bo.platform==="win32"||(Bo.stdout||{}).isTTY&&Qo.TERM!=="dumb"||!!Qo.CI),Ih=(t,e,i=t)=>n=>{let s=""+n,r=s.indexOf(e,t.length);return~r?t+Eh(s,e,i,r)+e:t+s+e},Eh=(t,e,i,n)=>{let s="",r=0;do s+=t.substring(r,n)+i,r=n+e.length,n=t.indexOf(e,r);while(~n);return s+t.substring(r)},Rv=(t=gh)=>{let e=t?Ih:()=>String;return{isColorSupported:t,reset:e("\x1B[0m","\x1B[0m"),bold:e("\x1B[1m","\x1B[22m","\x1B[22m\x1B[1m"),dim:e("\x1B[2m","\x1B[22m","\x1B[22m\x1B[2m"),italic:e("\x1B[3m","\x1B[23m"),underline:e("\x1B[4m","\x1B[24m"),inverse:e("\x1B[7m","\x1B[27m"),hidden:e("\x1B[8m","\x1B[28m"),strikethrough:e("\x1B[9m","\x1B[29m"),black:e("\x1B[30m","\x1B[39m"),red:e("\x1B[31m","\x1B[39m"),green:e("\x1B[32m","\x1B[39m"),yellow:e("\x1B[33m","\x1B[39m"),blue:e("\x1B[34m","\x1B[39m"),magenta:e("\x1B[35m","\x1B[39m"),cyan:e("\x1B[36m","\x1B[39m"),white:e("\x1B[37m","\x1B[39m"),gray:e("\x1B[90m","\x1B[39m"),bgBlack:e("\x1B[40m","\x1B[49m"),bgRed:e("\x1B[41m","\x1B[49m"),bgGreen:e("\x1B[42m","\x1B[49m"),bgYellow:e("\x1B[43m","\x1B[49m"),bgBlue:e("\x1B[44m","\x1B[49m"),bgMagenta:e("\x1B[45m","\x1B[49m"),bgCyan:e("\x1B[46m","\x1B[49m"),bgWhite:e("\x1B[47m","\x1B[49m"),blackBright:e("\x1B[90m","\x1B[39m"),redBright:e("\x1B[91m","\x1B[39m"),greenBright:e("\x1B[92m","\x1B[39m"),yellowBright:e("\x1B[93m","\x1B[39m"),blueBright:e("\x1B[94m","\x1B[39m"),magentaBright:e("\x1B[95m","\x1B[39m"),cyanBright:e("\x1B[96m","\x1B[39m"),whiteBright:e("\x1B[97m","\x1B[39m"),bgBlackBright:e("\x1B[100m","\x1B[49m"),bgRedBright:e("\x1B[101m","\x1B[49m"),bgGreenBright:e("\x1B[102m","\x1B[49m"),bgYellowBright:e("\x1B[103m","\x1B[49m"),bgBlueBright:e("\x1B[104m","\x1B[49m"),bgMagentaBright:e("\x1B[105m","\x1B[49m"),bgCyanBright:e("\x1B[106m","\x1B[49m"),bgWhiteBright:e("\x1B[107m","\x1B[49m")}};wl.exports=Rv();wl.exports.createColors=Rv});function mi(t,e){return e==="claude"?ug.includes(t)?t:cg[t]||"sonnet":t.startsWith("gemini-")?t:lg[t]||"gemini-3-flash-preview"}function pg(t){return/^[A-Z]/.test(t)}function Ag(t){return t.includes("_")||t.startsWith("gemini")}function dg(t,e){let i=t.match(/^([^(]+)(\(.*\))?$/),n=i?.[1]||t,s=i?.[2]||"";if(e==="claude"){if(pg(n))return t;let r=mg[n];return r?n==="run_shell_command"&&s==="(*)"?r:r+s:t}else{if(Ag(n))return t;let r=vg[n];return r?n==="Bash"&&!s?"run_shell_command(*)":r+s:t}}function vi(t,e){let i=t.map(n=>dg(n,e)).filter(Boolean);return[...new Set(i)]}function Vv(t){return t==="claude"?[".claude/agents",".gemini/agents"]:[".gemini/agents",".claude/agents"]}var cg,lg,ug,mg,vg,Nn=Y(()=>{"use strict";cg={"gemini-3-pro-preview":"opus","gemini-2.5-pro":"opus","gemini-3-flash-preview":"sonnet","gemini-2.5-flash":"sonnet","gemini-2.5-flash-lite":"haiku"},lg={opus:"gemini-3-pro-preview",sonnet:"gemini-3-flash-preview",haiku:"gemini-2.5-flash-lite"},ug=["haiku","sonnet","opus"];mg={list_directory:"Bash",read_file:"Read",write_file:"Write",glob:"Glob",search_file_content:"Grep",replace:"Edit",run_shell_command:"Bash",web_fetch:"WebFetch",google_web_search:"WebSearch",save_memory:"TodoWrite",write_todos:"TodoWrite"},vg={Read:"read_file",Write:"write_file",Edit:"replace",Bash:"run_shell_command",Glob:"glob",Grep:"search_file_content",WebFetch:"web_fetch",WebSearch:"google_web_search",TodoWrite:"write_todos",Task:""}});import{existsSync as yo,readFileSync as fg,readdirSync as hg}from"fs";import{join as Dl,basename as gg}from"path";function bv(t,e){let i=as(e),n=Dl(i,`${t}.md`);return yo(n)?Tl(n):null}function qo(t){let e=as(t);if(!yo(e))return[];let i=hg(e).filter(s=>s.endsWith(".md")),n=[];for(let s of i){let r=Dl(e,s),o=Tl(r);o&&n.push(o)}return n}function Ig(t){let e=t.match(/^---\r?\n([\s\S]*?)\r?\n---/);if(!e)return null;let i={};for(let n of e[1].split(/\r?\n/)){let s=n.indexOf(":");if(s===-1)continue;let r=n.slice(0,s).trim(),o=n.slice(s+1).trim();(o.startsWith('"')&&o.endsWith('"')||o.startsWith("'")&&o.endsWith("'"))&&(o=o.slice(1,-1)),i[r]=o}return i}function Nv(t){if(!t)return[];let e=t.trim();return e.startsWith("[")&&e.endsWith("]")&&(e=e.slice(1,-1)),e.split(",").map(i=>i.trim().replace(/['"]/g,"")).filter(Boolean)}function Fv(t){if(!t)return[];let e=t.trim();return e.startsWith("[")&&e.endsWith("]")&&(e=e.slice(1,-1)),e.split(",").map(i=>i.trim().replace(/['"]/g,"")).filter(Boolean)}function Tl(t){if(!yo(t))return null;let e=fg(t,"utf-8"),i=gg(t,".md"),n="",s="gemini-2.5-flash",r=[],o=[],c=Ig(e),l=e;if(c)c.description&&(n=c.description),c.model&&(s=c.model),r=Nv(c.skills),o=Fv(c.tools),l=e.replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/,"").trim();else{let u=e.split(`
3
+ `);for(let A of u){if(A.startsWith("# ")){n=A.substring(2).trim();break}if(A.trim()&&!A.startsWith("#")){n=A.trim();break}}let m=e.match(/model:\s*(.+)/i);m&&(s=m[1].trim());let p=e.match(/skills:\s*(.+)/i);p&&(r=Nv(p[1]));let d=e.match(/tools:\s*(.+)/i);d&&(o=Fv(d[1]))}return{name:i,description:n,model:s,skills:r,tools:o,content:l,filePath:t}}function Fn(t,e,i){let n=i||process.cwd(),s=Vv(e);for(let r of s){let o=Dl(n,r,`${t}.md`);if(yo(o)){let c=Tl(o);if(c)return r===s[0]||(c.model=mi(c.model,e),c.tools&&c.tools.length>0&&(c.tools=vi(c.tools,e))),c}}return null}var Xs=Y(()=>{"use strict";k();Nn()});import{existsSync as _i,readFileSync as Ll,readdirSync as Eg}from"fs";import{join as Hs}from"path";function jg(t){let e=[],i="",n=!1;for(let s=0;s<t.length;s++){let r=t[s];r==='"'?n=!n:r===","&&!n?(e.push(i),i=""):i+=r}return e.push(i),e}function $l(t){if(!_i(t))return[];let i=Ll(t,"utf-8").trim().split(`
4
+ `);if(i.length<2)return[];let n=i[0].split(",").map(r=>r.trim()),s=[];for(let r=1;r<i.length;r++){let o=jg(i[r]),c={};n.forEach((l,u)=>{c[l]=o[u]?.trim()||""}),s.push(c)}return s}function xg(t,e,i,n,s){if(!_i(t))return[];let r=$l(t),o=r.map(m=>e.map(p=>String(m[p]||"")).join(" ")),c=new wo;c.fit(o);let l=c.score(n),u=[];for(let[m,p]of l.slice(0,s))if(p>0){let d=r[m],A={};for(let f of i)f in d&&(A[f]=d[f]);A._score=Math.round(p*1e4)/1e4,u.push(A)}return u}function eu(){let t=Hs(_l,"synonyms.csv");if(!_i(t))return new Map;let e=$l(t),i=new Map;for(let n of e){let s=(n.word||"").toLowerCase().trim(),r=(n.synonyms||"").toLowerCase().trim();s&&r&&i.set(s,r.split(",").map(o=>o.trim()))}return i}function Bv(t,e){e||(e=eu());let i=t.toLowerCase().replace(/[^\w\s]/g," ").split(/\s+/),n=new Set(i);for(let s of i){let r=e.get(s);r&&r.forEach(o=>n.add(o))}return Array.from(n).join(" ")}function tu(t){let e=t.toLowerCase();for(let[i,n]of Object.entries(Rg))for(let s of n)if(e.includes(s))return i;return"standard"}function iu(t){let e=t.toLowerCase(),n=e.split(/\s+/)[0]||"",s=[[/system architecture/,"plan"],[/design.*architecture/,"plan"],[/architect.*system/,"plan"],[/create.*roadmap/,"plan"],[/build.*roadmap/,"plan"],[/create.*strategy/,"plan"],[/stunning/,"design"],[/gorgeous/,"design"],[/beautiful.*ui/,"design"],[/beautiful.*component/,"design"],[/beautiful.*page/,"design"],[/write.*documentation/,"docs"],[/write.*docs/,"docs"],[/create.*documentation/,"docs"],[/research.*codebase/,"research"],[/deep research/,"research"]];for(let[u,m]of s)if(typeof u=="string"?e.includes(u):u.test(e))return m;let r={implement:"execute",build:"execute",create:"execute",add:"execute",make:"execute",code:"execute",develop:"execute",write:"execute",setup:"execute",configure:"execute",test:"test",verify:"test",validate:"test",debug:"debug",fix:"debug",troubleshoot:"debug",review:"review",audit:"review",document:"docs",plan:"plan",design:"design",research:"research",analyze:"research",investigate:"research"};if(n in r)return r[n];let o=[["best practices","research"],["how does","research"],["how do","research"],["what is","research"],["why is","research"],["compare","research"],["investigate","research"],["research","research"],["understand","research"],["system architecture","plan"],["implementation plan","plan"],["roadmap","plan"],["strategy for","plan"],["blueprint","plan"],["fix the","debug"],["debug the","debug"],["not working","debug"],["is broken","debug"],["error in","debug"],["fix bug","debug"],["test the","test"],["run tests","test"],["verify the","test"],["review the","review"],["audit the","review"],["check code","review"],["document the","docs"],["write docs","docs"],["api documentation","docs"]];for(let[u,m]of o)if(e.includes(u))return m;let c={debug:["fix","debug","troubleshoot","error","issue","bug","broken","failing","crash"],review:["review","audit","assess","check code","pr review","security audit"],test:["test","verify","validate","qa","coverage","unit test","e2e test"],design:["beautiful","stunning","gorgeous","ui design","ux design","mockup","layout"],docs:["document","documentation","readme","api docs","technical writing"],git:["commit","push","pull","merge","branch","git","stage"],manage:["status","progress","track","milestone","sprint"],plan:["plan","architect","roadmap","strategy","architecture design"],execute:["implement","build","create","add","make","code","develop"],research:["research","investigate","explore","study","analyze","examine","learn"]},l={};for(let[u,m]of Object.entries(c)){let p=m.filter(d=>e.includes(d)).length;p>0&&(l[u]=p)}return Object.keys(l).length>0?Object.entries(l).sort((u,m)=>m[1]-u[1])[0][0]:"execute"}function nu(t){let e=t.toLowerCase(),i=[["flutter","mobile"],["react native","mobile"],["swift","mobile"],["kotlin","mobile"],["ios app","mobile"],["android app","mobile"],["next.js","fullstack"],["nextjs","fullstack"],["nuxt","fullstack"],["sveltekit","fullstack"],["remix","fullstack"],["server component","fullstack"],["openai","ai"],["anthropic","ai"],["claude","ai"],["langchain","ai"],["llm","ai"],["chatbot","ai"],["rag","ai"],["embedding","ai"],["gpt","ai"],["angular","frontend"],["react","frontend"],["vue","frontend"],["svelte","frontend"],["tailwind","frontend"],["nestjs","backend"],["express","backend"],["fastify","backend"],["hono","backend"],["fastapi","backend"],["websocket","backend"],["shopify","ecommerce"],["product catalog","ecommerce"],["checkout flow","ecommerce"],["stripe","payment"],["paypal","payment"],["subscription","payment"],["billing","payment"],["oauth","auth"],["authentication","auth"],["login","auth"],["signup","auth"],["prisma","database"],["drizzle","database"],["postgresql","database"],["mongodb","database"],["mysql","database"],["pdf","media"],["image","media"],["video","media"],["audio","media"],["codebase","codebase"],["repository","codebase"]];for(let[r,o]of i)if(e.includes(r))return o;let n={auth:["login","signup","authentication","oauth","jwt","session","password","2fa"],payment:["payment","checkout","billing","stripe","subscription","invoice","cart"],database:["database","sql","query","migration","schema","prisma","postgresql"],frontend:["ui","component","react","vue","css","tailwind","button","form","modal"],backend:["api","endpoint","server","service","route","rest","graphql","middleware"],mobile:["mobile","ios","android","react native","flutter","app","native"],fullstack:["fullstack","nextjs","next.js","nuxt","sveltekit","app router"],ecommerce:["ecommerce","shopify","store","product","cart","checkout","order"],media:["image","video","audio","media","upload","file","ocr"],ai:["ai","llm","gpt","claude","machine learning","embedding","vector","openai"],quality:["code review","lint","test","coverage","quality","refactor"],codebase:["codebase","repository","repo","project structure"],general:[]},s={};for(let[r,o]of Object.entries(n)){let c=o.filter(l=>e.includes(l)).length;c>0&&(s[r]=c)}return Object.keys(s).length>0?Object.entries(s).sort((r,o)=>o[1]-r[1])[0][0]:"general"}function Jv(t,e=Pv,i=!0){let n=Qv.combination,s=Hs(_l,n.file),r=t;if(i){let c=eu();r=Bv(t,c)}let o=xg(s,n.searchCols,n.outputCols,r,e);return{query:t,expandedQuery:i?r:void 0,detectedIntent:iu(t),detectedDomain:nu(t),detectedComplexity:tu(t),count:o.length,results:o}}function Hl(t,e,i,n=Pv,s=!0){let r=Qv.combination,o=Hs(_l,r.file);if(!_i(o))return{results:[],count:0};let c=$l(o);if(e&&(c=c.filter(A=>(A.intent||"").toLowerCase()===e.toLowerCase())),i&&(c=c.filter(A=>(A.domain||"").toLowerCase()===i.toLowerCase())),c.length===0)return{results:[],count:0};let l=t;if(s){let A=eu();l=Bv(t,A)}let u=c.map(A=>r.searchCols.map(f=>String(A[f]||"")).join(" ")),m=new wo;m.fit(u);let p=m.score(l),d=[];for(let[A,f]of p.slice(0,n))if(f>0){let g=c[A],E={};for(let J of r.outputCols)J in g&&(E[J]=g[J]);E._score=Math.round(f*1e4)/1e4,d.push(E)}return{results:d,count:d.length}}function Sg(t){let e=iu(t),i=nu(t),n=tu(t);if(["debug","review","test","design","docs","research","plan"].includes(e)){let m=Hl(t,e,void 0,1,!0);if(m.results.length>0){let p=m.results[0],A=(p.skills||"").split("|").map(f=>f.trim()).filter(Boolean);return{agent:Xl[e]||p.agent||"code-executor",skills:A,intent:e,domain:p.domain||i,complexity:p.complexity||n,score:p._score||0,fallback:!1,description:p.description||"",useWhen:p.use_when||""}}}if(e==="execute"&&["mobile","ai","payment","ecommerce","media","auth","database","fullstack"].includes(i)){let m=Hl(t,"execute",i,1,!0);if(m.results.length>0){let p=m.results[0];return{agent:"code-executor",skills:(p.skills||"").split("|").map(f=>f.trim()).filter(Boolean),intent:e,domain:i,complexity:p.complexity||n,score:p._score||0,fallback:!1,description:p.description||"",useWhen:p.use_when||""}}}let o=Jv(t,1,!0);if(o.count===0){let m=Xl[e]||"code-executor",p=zg[i]||["research"];return{agent:m,skills:p,intent:e,domain:i,complexity:n,score:0,fallback:!0,description:`Fallback combination based on detected intent (${e}) and domain (${i})`}}let c=o.results[0],u=(c.skills||"").split("|").map(m=>m.trim()).filter(Boolean);return{agent:c.agent||"code-executor",skills:u,intent:c.intent||e,domain:c.domain||i,complexity:c.complexity||n,score:c._score||0,fallback:!1,description:c.description||"",useWhen:c.use_when||""}}function su(t,e){let{top:i=5,forceIntent:n,forceDomain:s,maxSkills:r}=e||{};if(n||s)return Hl(t,n,s,i,!0).results.map(l=>{let m=(l.skills||"").split("|").map(p=>p.trim()).filter(Boolean);return r&&(m=m.slice(0,r)),{agent:n?Xl[n]:l.agent||"code-executor",skills:m,intent:l.intent||n||iu(t),domain:l.domain||s||nu(t),complexity:l.complexity||tu(t),score:l._score||0,fallback:!1,description:l.description||"",useWhen:l.use_when||""}});let o=Jv(t,i,!0);return o.count===0?[Sg(t)]:o.results.map(c=>{let u=(c.skills||"").split("|").map(m=>m.trim()).filter(Boolean);return r&&(u=u.slice(0,r)),{agent:c.agent||"code-executor",skills:u,intent:c.intent||o.detectedIntent,domain:c.domain||o.detectedDomain,complexity:c.complexity||o.detectedComplexity,score:c._score||0,fallback:!1,description:c.description||"",useWhen:c.use_when||""}})}function Zv(t){let e=Ci(t),i=[];if(!_i(e))return i;let n=Eg(e,{withFileTypes:!0}).filter(s=>s.isDirectory()).map(s=>s.name);for(let s of n){let r=Hs(e,s,"SKILL.md");if(_i(r)){let o=Ll(r,"utf-8");i.push({name:s,path:r,content:o})}}return i}function bn(t,e){let i=Ci(e),n=Hs(i,t,"SKILL.md");return _i(n)?Ll(n,"utf-8"):null}var _l,Pv,Qv,Rg,Xl,zg,wo,Ls=Y(()=>{"use strict";k();_l=".gemini/extensions/spawn-agent/data",Pv=3,Qv={combination:{file:"combinations.csv",searchCols:["keywords","description","use_when","agent","skills","intent","domain"],outputCols:["id","agent","skills","intent","domain","complexity","description","use_when"]},intent:{file:"intents.csv",searchCols:["primary_keywords","expanded_keywords","question_patterns"],outputCols:["intent","agent","primary_keywords","expanded_keywords","action_verbs"]},domain:{file:"domains.csv",searchCols:["keywords","frameworks","file_patterns","technical_terms"],outputCols:["domain","base_skills","enhanced_skills","keywords","frameworks"]},synonym:{file:"synonyms.csv",searchCols:["word","synonyms"],outputCols:["word","synonyms","category"]}},Rg={simple:["quick","simple","basic","small","minor","trivial","easy","straightforward"],standard:[],full:["comprehensive","full","complete","entire","thorough","detailed"],complex:["deep","extensive","advanced","complex","sophisticated","enterprise","production"]},Xl={research:"researcher",plan:"planner",execute:"code-executor",debug:"debugger",review:"code-reviewer",test:"tester",design:"ui-ux-designer",docs:"docs-manager",git:"git-manager",manage:"project-manager"},zg={frontend:["frontend-design"],backend:["backend-development"],auth:["better-auth","backend-development"],payment:["payment-integration"],database:["databases"],mobile:["mobile-development"],fullstack:["web-frameworks","backend-development"],ecommerce:["shopify"],media:["ai-multimodal"],ai:["ai-multimodal"],quality:["code-review"],codebase:["repomix"],general:["research"]},wo=class{k1;b;corpus=[];docLengths=[];avgdl=0;idf=new Map;docFreqs=new Map;N=0;constructor(e=1.5,i=.75){this.k1=e,this.b=i}tokenize(e){return String(e).toLowerCase().replace(/[^\w\s]/g," ").split(/\s+/).filter(n=>n.length>1)}fit(e){if(this.corpus=e.map(i=>this.tokenize(i)),this.N=this.corpus.length,this.N!==0){this.docLengths=this.corpus.map(i=>i.length),this.avgdl=this.docLengths.reduce((i,n)=>i+n,0)/this.N;for(let i of this.corpus){let n=new Set;for(let s of i)n.has(s)||(this.docFreqs.set(s,(this.docFreqs.get(s)||0)+1),n.add(s))}for(let[i,n]of this.docFreqs.entries())this.idf.set(i,Math.log((this.N-n+.5)/(n+.5)+1))}}score(e){let i=this.tokenize(e),n=[];for(let s=0;s<this.corpus.length;s++){let r=this.corpus[s],o=0,c=this.docLengths[s],l=new Map;for(let u of r)l.set(u,(l.get(u)||0)+1);for(let u of i){let m=this.idf.get(u);if(m!==void 0){let p=l.get(u)||0,d=p*(this.k1+1),A=p+this.k1*(1-this.b+this.b*c/this.avgdl);o+=m*d/A}}n.push([s,o])}return n.sort((s,r)=>r[1]-s[1])}}});import{existsSync as wv}from"fs";import{join as Dv}from"path";function Tv(t,e){let i=[],n=e.provider;if(i.push("<subagent-context>"),i.push("Agent Type: Interactive Session"),i.push(`Agent Role: ${e.context.agentName||"Assistant"}`),i.push(`Project: ${process.cwd()}`),i.push("</subagent-context>"),i.push(""),i.push("<task>"),i.push(t),i.push("</task>"),i.push(""),e.context.agentName){let s=ou(e.context.agentName,n);s&&(i.push("<agent>"),i.push(`Your role and responsibilities are defined in: @${s}`),i.push("</agent>"),i.push(""))}if(e.context.skills.length>0){i.push("<skills>"),i.push("You have access to the following skills and capabilities:");for(let s of e.context.skills){let r=au(s,n);r&&i.push(`- ${s}: @${r}`)}i.push("</skills>"),i.push("")}if(e.context.contextFiles.length>0){i.push("<context>"),i.push("The following documents provide additional context:");for(let s of e.context.contextFiles)s.path&&i.push(`- ${s.name}: @${s.path}`);i.push("</context>"),i.push("")}return i.join(`
5
+ `)}function ou(t,e){let i=process.cwd(),n=e==="claude"?[`.claude/agents/${t}.md`,`.gemini/agents/${t}.md`]:[`.gemini/agents/${t}.md`,`.claude/agents/${t}.md`];for(let s of n){let r=Dv(i,s);if(wv(r))return s}return n[0]}function au(t,e){let i=process.cwd(),n=e==="claude"?[`.claude/skills/${t}.md`,`.gemini/skills/${t}/SKILL.md`,`.gemini/extensions/${t}/SKILL.md`]:[`.gemini/skills/${t}/SKILL.md`,`.gemini/extensions/${t}/SKILL.md`,`.claude/skills/${t}.md`];for(let s of n){let r=Dv(i,s);if(wv(r))return s}return n[0]}var cu=Y(()=>{"use strict"});import Og from"net";var Ug,Kg,ee,Do=Y(()=>{"use strict";Ug=3377,Kg="127.0.0.1",ee=class{port;host;constructor(e=Ug,i=Kg){this.port=e,this.host=i}sendCommand(e){return new Promise((i,n)=>{let s=new Og.Socket,r="";s.setTimeout(1e4),s.connect(this.port,this.host,()=>{s.write(e+`
6
+ `)}),s.on("data",o=>{r+=o.toString(),s.destroy()}),s.on("close",()=>{i(r.trim())}),s.on("error",o=>{o.code==="ECONNREFUSED"?n(new Error('No server running. Use "gk agent start" first.')):n(o)}),s.on("timeout",()=>{s.destroy(),n(new Error("Connection timeout"))})})}async isServerRunning(){try{return await this.sendCommand("status"),!0}catch{return!1}}async status(){let e=await this.sendCommand("status");return JSON.parse(e)}async send(e){let i=await this.sendCommand("send "+e);return JSON.parse(i)}async waitForCompletion(e=120){let i=Date.now(),n=e*1e3;for(;Date.now()-i<n;){try{let s=await this.complete();if(s.complete)return!0;if(s.reason==="pending_tool")return!1}catch(s){throw s}await this.sleep(2e3)}return!1}async complete(){let e=await this.sendCommand("complete");return JSON.parse(e)}async exchange(){let e=await this.sendCommand("exchange");return JSON.parse(e)}async pending(){let e=await this.sendCommand("pending");return JSON.parse(e)}async read(e=200){return await this.sendCommand("read "+e)}async history(){let e=await this.sendCommand("history");return JSON.parse(e)}async clearHistory(){await this.sendCommand("history clear")}async stop(){try{await this.sendCommand("stop")}catch{}}sleep(e){return new Promise(i=>setTimeout(i,e))}}});var Xv,Hv=Y(()=>{"use strict";Xv={claude:{name:"Claude Code",command:"claude",package:"@anthropic-ai/claude-code",modelFlag:"--model",toolsFlag:"--allowedTools",toolsFormat:"csv",pipeFlag:void 0,readyIndicator:"\u276F",responseMarker:"\u25CF",exitCommand:"/exit\r"},gemini:{name:"Gemini CLI",command:"gemini",package:"@google/gemini-cli",modelFlag:"-m",toolsFlag:"--allowed-tools",toolsFormat:"json",pipeFlag:void 0,readyIndicator:">",responseMarker:"\u2726",exitCommand:"/exit\r"}}});import*as Lv from"node-pty";import{EventEmitter as kg}from"events";var To,_v=Y(()=>{"use strict";Hv();To=class extends kg{process=null;output="";outputBuffer=[];isReady=!1;provider;config;model;tools;cwd;debug;constructor(e){if(super(),this.provider=e.provider,this.config=Xv[e.provider],!this.config)throw new Error(`Unknown provider: ${e.provider}. Use 'claude' or 'gemini'`);this.model=e.model||"",this.tools=e.tools||[],this.cwd=e.cwd||process.cwd(),this.debug=e.debug||!1}start(){return new Promise((e,i)=>{if(this.process){i(new Error("Session already running"));return}let n=process.platform==="win32"?"npx.cmd":"npx",s=["-y",this.config.package];this.config.pipeFlag&&s.push(this.config.pipeFlag),this.model&&s.push(this.config.modelFlag,this.model),this.tools.length>0&&(this.config.toolsFormat==="json"?s.push(this.config.toolsFlag,JSON.stringify(this.tools)):s.push(this.config.toolsFlag,this.tools.join(","))),this.debug&&console.log(`[DEBUG] Spawning: ${n} ${s.join(" ")}`);try{this.process=Lv.spawn(n,s,{name:"xterm-256color",cols:120,rows:40,cwd:this.cwd,env:{...process.env,TERM:"xterm-256color"}})}catch(o){i(new Error(`Failed to spawn ${n}: ${o.message}`));return}this.output="",this.outputBuffer=[],this.process.onData(o=>{this.output+=o,this.outputBuffer.push({time:Date.now(),data:o}),this.debug&&process.stdout.write(o),this.emit("data",o),!this.isReady&&this.output.includes(this.config.readyIndicator)&&(this.isReady=!0,this.emit("ready"))}),this.process.onExit(({exitCode:o})=>{this.isReady=!1,this.process=null,this.emit("exit",o)});let r=setTimeout(()=>{this.isReady||(this.output.includes("Yes, I trust")?(this.write("1"),setTimeout(()=>{this.isReady?e():i(new Error(`Timeout waiting for ${this.config.name} to be ready`))},5e3)):i(new Error(`Timeout waiting for ${this.config.name} to start`)))},6e4);this.once("ready",()=>{clearTimeout(r),e()})})}write(e){if(!this.process)throw new Error("No active session");this.process.write(e)}send(e,i={}){return new Promise((n,s)=>{if(!this.process||!this.isReady){s(new Error("No active session or not ready"));return}let r=i.timeout||12e4,o=this.output.length;this.write(e),setTimeout(()=>{this.write("\r"),this.debug&&console.log(`
7
+ [DEBUG] Prompt sent, waiting for response...`)},500);let c=setInterval(()=>{let u=this.output.slice(o),m=!1;if(this.provider==="claude"){let p=u.includes("\u25CF"),d=u.lastIndexOf("\u276F")>u.lastIndexOf("\u25CF");m=p&&d}else this.provider==="gemini"&&(m=u.includes("\u2726")&&u.length>100);if(m){clearInterval(c),clearTimeout(l);let p=this.extractLastAnswer();n(p)}},500),l=setTimeout(()=>{clearInterval(c),s(new Error("Timeout waiting for response"))},r)})}extractLastAnswer(){let e=this.output.replace(/\x1b\[1C/g," ").replace(/\x1b\[[0-9;]*[A-Za-z]/g,"").replace(/\x1b\][^\x07]*\x07/g,"").replace(/\r/g,"");return this.provider==="claude"?this.extractAnswerClaude(e):this.provider==="gemini"?this.extractAnswerGemini(e):""}extractAnswerClaude(e){let i=e.match(/●\s*([\s\S]*?)(?=❯|$)/g);if(i&&i.length>0){let n=i[i.length-1];return n=n.replace(/^●\s*/,"").replace(/[─╭╰│┌┐└┘├┤┬┴┼]+/g,"").replace(/\? for shortcuts/g,"").replace(/esc to interrupt/g,"").replace(/Churning…/g,"").replace(/\(thinking\)/g,"").trim(),n.split(`
8
+ `).map(r=>r.trim()).filter(r=>!(r.length===0||r.match(/^[\s─╭╰│┌┐└┘├┤┬┴┼✢✶✻✽·*]+$/)||r.match(/Cascading|Churning|thinking|thought for/i)||r.match(/^\d+s\)$/))).join(`
9
+ `).trim()}return""}extractAnswerGemini(e){let i=e.split(`
10
+ `),n=!1,s=[];for(let r of i){let o=r.trim();o.match(/^[┃┏┓┗┛━─╭╮╯╰│]+$/)||o.match(/^Gemini/i)||o.match(/^Type .* to/i)||o.length>0&&!o.match(/^>/)&&s.push(o)}return s.join(`
11
+ `).trim()}getOutput(e=100){return this.output.split(`
12
+ `).slice(-e).join(`
13
+ `)}getFullOutput(){return this.output}isRunning(){return this.process!==null&&this.isReady}getIsReady(){return this.isReady}getProvider(){return this.provider}stop(){return new Promise(e=>{if(!this.process){e();return}this.once("exit",()=>e()),this.write(this.config.exitCommand),setTimeout(()=>{this.process&&this.process.kill(),e()},3e3)})}}});import{existsSync as _s,mkdirSync as Vg,writeFileSync as Ng,readFileSync as Fg,renameSync as bg,unlinkSync as Pg,readdirSync as Qg,rmSync as Bg}from"fs";import{join as Ai}from"path";import{homedir as Jg}from"os";function ce(t){let e=ge(t);return Ai(ep,e)}function di(t,e){return Ai(ce(t),`team-${e}.json`)}function Xo(t){return Ai(ce(t),"ports.json")}function $s(t){return Ai(ce(t),"tasks")}function tt(t,e){return Ai($s(t),`task-${e}.json`)}function er(t,e){return Ai(ce(t),`inbox-${e}.jsonl`)}function pi(t){_s(t)||Vg(t,{recursive:!0})}function ve(t,e){let i=`${t}.tmp`;try{let n=JSON.stringify(e,null,2);return Ng(i,n,"utf8"),bg(i,t),!0}catch{try{_s(i)&&Pg(i)}catch{}return!1}}function Pn(t){if(!_s(t))return null;try{let e=Fg(t,"utf8");return JSON.parse(e)}catch{return null}}function Ho(t,e,i){if(!_s(t))return[];try{return Qg(t).filter(s=>s.startsWith(e)&&s.endsWith(i))}catch{return[]}}function lu(t){if(!_s(t))return!0;try{return Bg(t,{recursive:!0,force:!0}),!0}catch{return!1}}function uu(t){pi(ce(t)),pi($s(t))}var $v,ep,Qn=Y(()=>{"use strict";k();$v=Ai(Jg(),".gemkit"),ep=Ai($v,"teams")});function Q(t,e){return Pn(di(t,e))}function It(t){let e=ce(t),i=Ho(e,"team-",".json"),n=[];for(let s of i){let r=s.replace("team-","").replace(".json",""),o=Q(t,r);o&&n.push(o)}return n}function P(t,e){return Pn(tt(t,e))}function mu(t){let e=$s(t),i=Ho(e,"task-",".json"),n=[];for(let s of i){let r=s.replace("task-","").replace(".json",""),o=P(t,r);o&&n.push(o)}return n.sort((s,r)=>new Date(s.createdAt).getTime()-new Date(r.createdAt).getTime())}function tr(t,e){return mu(t).filter(i=>i.teamId===e)}function fi(t,e){let n=tr(t,e).filter(p=>p.status!=="deleted"),s=n.filter(p=>p.status==="completed"),r=n.filter(p=>p.status==="in_progress"),o=n.filter(p=>p.status==="pending"),c=new Set(s.map(p=>p.taskId)),l=o.filter(p=>p.blockedBy.length>0&&p.blockedBy.some(d=>!c.has(d))),u=new Set(l.map(p=>p.taskId)),m=o.filter(p=>!u.has(p.taskId)&&!p.owner);return{tasks:n,available:m,blocked:l,inProgress:r,completed:s}}function vu(t,e){let i=P(t,e);if(!i||i.blockedBy.length===0)return!1;for(let n of i.blockedBy){let s=P(t,n);if(!s||s.status!=="completed")return!0}return!1}function pu(t,e){return mu(t).filter(n=>{if(n.status!=="pending"||!n.blockedBy.includes(e))return!1;let s=n.blockedBy.filter(r=>r!==e);for(let r of s){let o=P(t,r);if(!o||o.status!=="completed")return!1}return!0})}var hi=Y(()=>{"use strict";Qn()});import{createHash as Zg}from"crypto";function yg(t){return Zg("sha256").update(t).digest("hex")}function qg(t){return yg(t).substring(0,8)}function tp(t){let e=t.replace(/\\/g,"/").toLowerCase();return qg(e)}function Lo(t=""){let e=Date.now().toString(36),i=Math.random().toString(36).substring(2,8);return t?`${t}-${e}-${i}`:`${e}-${i}`}function Et(t,e){let i=Date.now().toString(36),n=Math.random().toString(36).substring(2,6);return`${t}-${e}-${i}-${n}`}var en=Y(()=>{"use strict"});function _o(t){let e=Lo("team");uu(t.projectDir);let i=new Date().toISOString(),n={teamId:e,teamName:t.teamName,description:t.description||"",projectDir:t.projectDir,leaderId:t.leaderId,leaderPort:t.leaderPort,members:[{agentId:t.leaderId,name:"leader",agentType:"leader",role:"leader",port:t.leaderPort,pid:process.pid,status:"ready",joinedAt:i,lastActiveAt:i}],status:"active",createdAt:i,updatedAt:i};return ve(di(t.projectDir,e),n)?n:null}function gi(t,e,i){let n=Q(t,e);if(!n)return!1;let s=n.members.findIndex(c=>c.agentId===i.agentId),r=new Date().toISOString(),o={...i,joinedAt:r,lastActiveAt:r};return s>=0?n.members[s]=o:n.members.push(o),n.updatedAt=r,!!ve(di(t,e),n)}function Z(t,e,i,n){let s=Q(t,e);if(!s)return!1;let r=s.members.find(o=>o.agentId===i);return r?(r.status=n,r.lastActiveAt=new Date().toISOString(),s.updatedAt=new Date().toISOString(),ve(di(t,e),s)):!1}function Au(t,e,i,n){let s=Q(t,e);if(!s)return!1;let r=s.members.find(o=>o.agentId===i);return r?(r.pid=n,r.lastActiveAt=new Date().toISOString(),s.updatedAt=new Date().toISOString(),ve(di(t,e),s)):!1}function du(t){return lu(ce(t))}function fu(t,e){let i=Lo("task"),n=new Date().toISOString(),s={taskId:i,teamId:e.teamId,subject:e.subject,description:e.description,activeForm:e.activeForm||`Working on: ${e.subject}`,status:"pending",owner:null,createdBy:e.createdBy,blockedBy:e.blockedBy||[],blocks:[],metadata:e.metadata||{},createdAt:n,updatedAt:n,completedAt:null};for(let r of s.blockedBy){let o=P(t,r);o&&!o.blocks.includes(i)&&(o.blocks.push(i),ve(tt(t,r),o))}return ve(tt(t,i),s)?s:null}function tn(t,e,i){let n=P(t,e);if(!n)return null;let s=new Date().toISOString();if(i.status!==void 0&&(n.status=i.status,i.status==="completed"&&(n.completedAt=s)),i.subject!==void 0&&(n.subject=i.subject),i.description!==void 0&&(n.description=i.description),i.activeForm!==void 0&&(n.activeForm=i.activeForm),i.owner!==void 0&&(n.owner=i.owner),i.metadata!==void 0&&(n.metadata={...n.metadata,...i.metadata}),i.addBlockedBy){for(let r of i.addBlockedBy)if(!n.blockedBy.includes(r)){n.blockedBy.push(r);let o=P(t,r);o&&!o.blocks.includes(e)&&(o.blocks.push(e),ve(tt(t,r),o))}}if(i.addBlocks){for(let r of i.addBlocks)if(!n.blocks.includes(r)){n.blocks.push(r);let o=P(t,r);o&&!o.blockedBy.includes(e)&&(o.blockedBy.push(e),ve(tt(t,r),o))}}if(i.removeBlockedBy)for(let r of i.removeBlockedBy){let o=n.blockedBy.indexOf(r);if(o!==-1){n.blockedBy.splice(o,1);let c=P(t,r);if(c){let l=c.blocks.indexOf(e);l!==-1&&(c.blocks.splice(l,1),ve(tt(t,r),c))}}}if(i.removeBlocks)for(let r of i.removeBlocks){let o=n.blocks.indexOf(r);if(o!==-1){n.blocks.splice(o,1);let c=P(t,r);if(c){let l=c.blockedBy.indexOf(e);l!==-1&&(c.blockedBy.splice(l,1),ve(tt(t,r),c))}}}return n.updatedAt=s,ve(tt(t,e),n)?n:null}var Pt=Y(()=>{"use strict";Qn();hi();en()});var ip=Y(()=>{"use strict"});var lp={};sm(lp,{createAgentRef:()=>Be,createLeaderRef:()=>pe,formatMessageForDisplay:()=>Jn,getAllPending:()=>op,getInboxMessage:()=>ir,getPendingApprovals:()=>$o,getPendingForAgent:()=>nr,readInbox:()=>Qt,updateInboxMessage:()=>Bt,writeApprovalRequest:()=>ta,writeApprovalResponse:()=>ap,writeBroadcast:()=>Bn,writeInbox:()=>Qe,writeMessage:()=>ea,writeShutdownRequest:()=>ra,writeShutdownResponse:()=>oa,writeStatusUpdate:()=>cp,writeTaskClaimed:()=>na,writeTaskCompleted:()=>sa,writeTaskCreated:()=>ia});import{existsSync as hu,appendFileSync as np,readFileSync as sp,writeFileSync as Dg}from"fs";import{randomUUID as rp}from"crypto";function Tg(t){let e=t.replace(/_/g,"-"),i=rp().slice(0,8);return`${e}-${i}`}function Xg(t,e){let i=ce(t);pi(i);let n=er(t,e);return hu(n)||np(n,""),n}function Qe(t,e,i){let n=Xg(t,e),s={id:Tg(i.type),timestamp:new Date().toISOString(),...i},r=JSON.stringify(s)+`
14
+ `;return np(n,r,"utf-8"),s}function Qt(t,e,i){let n=er(t,e);if(!hu(n))return[];let o=sp(n,"utf-8").trim().split(`
15
+ `).filter(c=>c.trim()).map(c=>{try{return JSON.parse(c)}catch{return null}}).filter(c=>c!==null);if(i){if(i.to&&(o=o.filter(c=>c.to==="all"||typeof c.to=="object"&&c.to.name===i.to)),i.from&&(o=o.filter(c=>c.from.name===i.from)),i.type){let c=Array.isArray(i.type)?i.type:[i.type];o=o.filter(l=>c.includes(l.type))}if(i.status){let c=Array.isArray(i.status)?i.status:[i.status];o=o.filter(l=>c.includes(l.status))}if(i.since){let c=new Date(i.since);o=o.filter(l=>new Date(l.timestamp)>=c)}i.limit&&i.limit>0&&(o=o.slice(-i.limit))}return o}function ir(t,e,i){return Qt(t,e).find(s=>s.id===i)||null}function Bt(t,e,i,n){let s=er(t,e);if(!hu(s))return!1;let o=sp(s,"utf-8").trim().split(`
16
+ `).filter(u=>u.trim()),c=!1,l=o.map(u=>{try{let m=JSON.parse(u);if(m.id===i){c=!0;let p={...m,...n,metadata:{...m.metadata,...n.metadata}};return JSON.stringify(p)}return u}catch{return u}});if(c){let u=l.join(`
17
+ `)+`
18
+ `;Dg(s,u,"utf-8")}return c}function nr(t,e,i){return Qt(t,e,{status:"pending"}).filter(n=>n.to==="all"||typeof n.to=="object"&&n.to.name===i)}function $o(t,e){return Qt(t,e,{type:"approval_request",status:"pending"})}function op(t,e){return Qt(t,e,{status:"pending"})}function Be(t,e,i="member"){return{id:t,name:e,role:i}}function pe(t="leader"){return{id:t,name:"leader",role:"leader"}}function ea(t,e,i,n,s,r){return Qe(t,e,{type:"message",from:i,to:n,content:s,summary:r,status:"pending"})}function Bn(t,e,i,n,s){return Qe(t,e,{type:"broadcast",from:i,to:"all",content:n,summary:s,status:"pending"})}function ta(t,e,i,n,s,r){return Qe(t,e,{type:"approval_request",from:i,to:pe(),content:`Tool approval needed: ${n}
19
+ ${s}`,summary:`${n}: ${s.slice(0,50)}`,status:"pending",metadata:{toolType:n,toolDetail:s,agentPort:r}})}function ap(t,e,i,n,s,r){return Qe(t,e,{type:"approval_response",from:pe(),to:i,content:s?"Approved":`Rejected: ${r||"No reason provided"}`,summary:s?"Approved":"Rejected",status:"processed",metadata:{requestId:n,approved:s,reason:r}})}function ia(t,e,i,n,s,r){return Qe(t,e,{type:"task_created",from:i,to:"all",content:`New task: ${s}`,summary:`Task created: ${s.slice(0,40)}`,status:"pending",metadata:{taskId:n,blockedBy:r}})}function na(t,e,i,n,s){return Qe(t,e,{type:"task_claimed",from:i,to:"all",content:`${i.name} claimed: ${s}`,summary:`${i.name} claimed task`,status:"pending",metadata:{taskId:n}})}function sa(t,e,i,n,s){return Qe(t,e,{type:"task_completed",from:i,to:"all",content:`${i.name} completed: ${s}`,summary:`${i.name} completed task`,status:"pending",metadata:{taskId:n}})}function cp(t,e,i,n,s){return Qe(t,e,{type:"status_update",from:i,to:pe(),content:`${i.name} status: ${n} \u2192 ${s}`,summary:`Status: ${s}`,status:"processed",metadata:{previousStatus:n,newStatus:s}})}function ra(t,e,i,n){let s=rp().slice(0,8);return Qe(t,e,{type:"shutdown_request",from:pe(),to:i,content:n||"Shutdown requested by leader",summary:"Shutdown request",status:"pending",metadata:{requestId:s}})}function oa(t,e,i,n,s,r){return Qe(t,e,{type:"shutdown_response",from:i,to:pe(),content:s?"Shutdown approved":`Shutdown declined: ${r}`,summary:s?"Shutdown approved":"Shutdown declined",status:"pending",metadata:{requestId:n,approved:s,reason:r}})}function Jn(t){let e=t.to==="all"?"all":t.to.name,i={pending:"\u23F3",delivered:"\u{1F4EC}",processed:"\u2705",failed:"\u274C",stale:"\u{1F550}"}[t.status]||"?",n={message:"\u{1F4AC}",broadcast:"\u{1F4E2}",approval_request:"\u{1F514}",approval_response:"\u2713",plan_approval_request:"\u{1F4CB}",plan_approval_response:"\u2705",task_created:"\u{1F4CB}",task_claimed:"\u{1F3C3}",task_completed:"\u{1F389}",status_update:"\u{1F4CA}",shutdown_request:"\u{1F534}",shutdown_response:"\u{1F7E2}"}[t.type]||"\u{1F4E8}";return`${i} ${n} [${t.id}] ${t.from.name} \u2192 ${e}: ${t.summary}`}var Ii=Y(()=>{"use strict";Qn()});import{existsSync as pp,writeFileSync as Hg,unlinkSync as Ap,readFileSync as Lg}from"fs";import{join as _g}from"path";function hp(t){return _g(ce(t),"ports.lock")}function $g(t){let e=hp(t),i=Date.now();for(pi(ce(t));Date.now()-i<up;)try{if(pp(e)){let n=Lg(e,"utf8"),s=parseInt(n,10);if(Date.now()-s>up)Ap(e);else{let r=mp+Math.random()*50,o=Date.now()+r;for(;Date.now()<o;);continue}}return Hg(e,Date.now().toString(),{flag:"wx"}),!0}catch(n){if(n.code==="EEXIST"){let s=mp+Math.random()*50,r=Date.now()+s;for(;Date.now()<r;);continue}continue}return!1}function eI(t){let e=hp(t);try{pp(e)&&Ap(e)}catch{}}function tI(t){if(!t||t<=0)return!1;try{return process.kill(t,0),!0}catch{return!1}}function sr(t){return Pn(Xo(t))||{allocations:[],lastUpdated:new Date().toISOString()}}function gu(t,e){return pi(ce(t)),e.lastUpdated=new Date().toISOString(),ve(Xo(t),e)}function Jt(t,e,i,n=null){if(!$g(t))return console.error("[PortManager] Failed to acquire lock"),null;try{let s=sr(t),r=s.allocations.find(c=>c.agentId===e);if(r)return r.port;let o=new Set(s.allocations.map(c=>c.port));for(let c=dp;c<=fp;c++)if(!o.has(c)){let l={port:c,agentId:e,teamId:i,pid:n,allocatedAt:new Date().toISOString()};return s.allocations.push(l),gu(t,s)?c:null}return null}finally{eI(t)}}function Me(t,e){let i=sr(t),n=i.allocations.findIndex(s=>s.agentId===e);return n===-1?!0:(i.allocations.splice(n,1),gu(t,i))}async function rr(t){let e=sr(t),i=e.allocations.length;e.allocations=e.allocations.filter(s=>s.pid?tI(s.pid):!0);let n=i-e.allocations.length;return n>0&&gu(t,e),n}function Iu(t){let e=sr(t),i={};for(let n of e.allocations)i[n.teamId]=(i[n.teamId]||0)+1;return{total:vp,used:e.allocations.length,available:vp-e.allocations.length,byTeam:i}}var up,mp,dp,fp,vp,Zn=Y(()=>{"use strict";Qn();up=5e3,mp=50,dp=3377,fp=3476,vp=fp-dp+1});async function aa(t,e,i){switch(i.type){case"approval_response":return iI(t,e,i);case"task_completed":return nI(t,e,i);case"shutdown_response":return sI(t,e,i);case"message":case"broadcast":return{success:!0,action:"Queued for delivery"};default:return{success:!0,action:"No hook action needed"}}}async function iI(t,e,i){let{requestId:n,approved:s}=i.metadata||{};if(!n)return{success:!1,error:"No requestId in approval response"};let r=ir(t,e,n);if(!r)return{success:!1,error:`Original request not found: ${n}`};let o=r.metadata?.agentPort;if(!o)return{success:!1,error:"No agent port in original request"};try{let c=new ee(o);return s?(await c.send("1"),Bt(t,e,n,{status:"processed",processedAt:new Date().toISOString()}),{success:!0,action:`Sent approval to PTY port ${o}`}):(await c.send("3"),Bt(t,e,n,{status:"processed",processedAt:new Date().toISOString()}),{success:!0,action:`Sent rejection to PTY port ${o}`})}catch(c){return{success:!1,error:`Failed to send to PTY: ${c.message}`}}}async function nI(t,e,i){let{taskId:n}=i.metadata||{};if(!n)return{success:!1,error:"No taskId in task_completed message"};let s=tr(t,e),r=[];for(let o of s)if(o.blockedBy&&o.blockedBy.includes(n)){tn(t,o.taskId,{removeBlockedBy:[n]});let c=P(t,o.taskId);c&&c.blockedBy.length===0&&c.status==="pending"&&r.push(o.taskId)}if(r.length>0){let o=r.map(c=>{let l=P(t,c);return l?`${c}: ${l.subject}`:c});return Bn(t,e,pe("system"),`Tasks now available:
20
+ ${o.join(`
21
+ `)}`,`${r.length} task(s) unblocked`),{success:!0,action:`Unblocked ${r.length} task(s): ${r.join(", ")}`}}return{success:!0,action:"No tasks to unblock"}}async function sI(t,e,i){let{approved:n}=i.metadata||{};if(!n)return{success:!0,action:"Shutdown declined by agent"};let s=i.from.name,r=Q(t,e);if(!r)return{success:!1,error:"Team not found"};let o=r.members.find(c=>c.name===s);if(!o)return{success:!1,error:`Member not found: ${s}`};if(o.pid)try{process.kill(o.pid)}catch{}return Z(t,e,o.agentId,"shutdown"),Me(t,o.agentId),{success:!0,action:`Shutdown ${s} (PID: ${o.pid})`}}async function gp(t,e,i){let n=ir(t,e,i);if(!n)return{valid:!1,error:`Request not found: ${i}`};if(n.type!=="approval_request")return{valid:!1,error:`Cannot approve: type is '${n.type}', not 'approval_request'`};if(n.status!=="pending")return{valid:!1,error:`Request already ${n.status}${n.processedAt?` at ${n.processedAt}`:""}`};let s=n.metadata?.agentPort;if(!s)return{valid:!1,error:"No agent port in request metadata"};try{if(!(await new ee(s).pending()).hasPending)return Bt(t,e,i,{status:"stale"}),{valid:!1,error:"Agent has no pending tool (request marked stale)"}}catch(r){return{valid:!1,error:`Cannot reach agent: ${r.message}`}}return{valid:!0,message:n}}async function ca(t,e,i,n,s){let r=await gp(t,e,i);if(!r.valid)return{success:!1,error:r.error};let o=r.message,{writeApprovalResponse:c}=await Promise.resolve().then(()=>(Ii(),lp)),l=c(t,e,o.from,i,n,s);return aa(t,e,l)}var Eu=Y(()=>{"use strict";Ii();hi();Pt();Pt();Zn();Do()});async function la(t,e,i,n,s,r,o,c,l={}){let u=n==="leader"?pe(i):Be(i,n,"member"),m=r==="leader"?pe(s):Be(s,r,"member"),p=l.type||"message";return p==="shutdown_request"?ra(t,e,m,o):p==="shutdown_response"?oa(t,e,u,l.requestId||"",l.approve||!1,o):ea(t,e,u,m,o,c)}async function ua(t,e,i,n,s,r){if(!Q(t,e))return[];let c=n==="leader"?pe(i):Be(i,n,"member");return[Bn(t,e,c,s,r).id]}var ma=Y(()=>{"use strict";hi();en();Ii()});function va(t,e,i,n,s,r={}){if(r.blockedBy){for(let l of r.blockedBy)if(!P(t,l))return console.error(`Task ${l} does not exist, cannot add as blocker`),null}let o={teamId:e,subject:i,description:n,activeForm:r.activeForm,createdBy:s,blockedBy:r.blockedBy,metadata:r.metadata},c=fu(t,o);if(c){let l=s==="leader"?pe():Be(s,s,"member");ia(t,e,l,c.taskId,i,r.blockedBy)}return c}function Ip(t,e,i){let n=tn(t,e,{status:i});if(!n)return null;let s=[];if(i==="completed"){let r=pu(t,e);s.push(...r)}return{task:n,unblocked:s}}function pa(t,e,i){let n=P(t,e);if(!n)return null;if(n.owner&&n.owner!==i)return console.error(`Task ${e} already claimed by ${n.owner}`),null;if(vu(t,e))return console.error(`Task ${e} is blocked by unfinished dependencies`),null;let s=tn(t,e,{owner:i,status:"in_progress"});if(s){let r=Be(i,i,"member");na(t,n.teamId,r,e,n.subject)}return s}async function Aa(t,e){let i=P(t,e);if(!i)return null;let n=Ip(t,e,"completed");if(!n)return null;let s=i.owner||"unknown",r=Be(s,s,"member"),o=sa(t,i.teamId,r,e,i.subject);return await aa(t,i.teamId,o),n}function da(t,e){let i=fi(t,e);return{total:i.tasks.length,pending:i.tasks.filter(n=>n.status==="pending").length,inProgress:i.inProgress.length,completed:i.completed.length,blocked:i.blocked.length,available:i.available.length}}var Ru=Y(()=>{"use strict";hi();Pt();Ii();Eu()});var Rp=Y(()=>{"use strict";hi();Pt();ma();Ii();Ru();Zn()});import{existsSync as mI,readFileSync as vI}from"fs";function B(t=process.cwd()){let e={ACTIVE_GK_SESSION_ID:"",GK_PROJECT_HASH:"",PROJECT_DIR:"",ACTIVE_GEMINI_SESSION_ID:"",GEMINI_PROJECT_HASH:"",GEMINI_PARENT_ID:"",ACTIVE_PLAN:"",SUGGESTED_PLAN:"",PLAN_DATE_FORMAT:""},i=Wi(t);if(!mI(i))return e;try{let n=vI(i,"utf-8"),s=n.match(/^ACTIVE_GK_SESSION_ID=(.*)$/m);s&&(e.ACTIVE_GK_SESSION_ID=s[1].trim());let r=n.match(/^GK_PROJECT_HASH=(.*)$/m);r&&(e.GK_PROJECT_HASH=r[1].trim());let o=n.match(/^PROJECT_DIR=(.*)$/m);o&&(e.PROJECT_DIR=o[1].trim());let c=n.match(/^ACTIVE_GEMINI_SESSION_ID=(.*)$/m);c&&(e.ACTIVE_GEMINI_SESSION_ID=c[1].trim());let l=n.match(/^GEMINI_PROJECT_HASH=(.*)$/m);l&&(e.GEMINI_PROJECT_HASH=l[1].trim());let u=n.match(/^GEMINI_PARENT_ID=(.*)$/m);u&&(e.GEMINI_PARENT_ID=u[1].trim());let m=n.match(/^ACTIVE_PLAN=(.*)$/m);m&&(e.ACTIVE_PLAN=m[1].trim());let p=n.match(/^SUGGESTED_PLAN=(.*)$/m);p&&(e.SUGGESTED_PLAN=p[1].trim());let d=n.match(/^PLAN_DATE_FORMAT=(.*)$/m);d&&(e.PLAN_DATE_FORMAT=d[1].trim())}catch{}return e}function nn(t=process.cwd()){return B(t).ACTIVE_GK_SESSION_ID||void 0}function Zt(t=process.cwd()){let e=B(t);return e.PROJECT_DIR?e.PROJECT_DIR:ge(t)}function fa(t=process.cwd()){return B(t).GEMINI_PROJECT_HASH||void 0}function or(t=process.cwd()){return B(t).ACTIVE_PLAN||void 0}var it=Y(()=>{"use strict";k()});var zp=Y(()=>{"use strict";Xs();Ls();Nn();Pt();Zn();en();it()});import{execSync as AI}from"child_process";function jp(t){if(!t||t<=0)return!1;try{return process.kill(t,0),!0}catch{return!1}}function dI(t){if(!t||t<=0)return!1;try{return process.platform==="win32"?AI(`cmd.exe /c taskkill /F /PID ${t}`,{stdio:["pipe","pipe","pipe"],timeout:5e3}):process.kill(t,"SIGKILL"),!0}catch{try{return process.kill(t,"SIGKILL"),!0}catch{return!1}}}async function zu(t){let e=It(t),i=0,n=0,s=0;for(let o of e)for(let c of o.members)i++,c.status!=="shutdown"&&c.pid&&!jp(c.pid)&&(n++,Z(t,o.teamId,c.agentId,"shutdown"),Me(t,c.agentId),s++);let r=await rr(t);return{teamsChecked:e.length,membersChecked:i,orphansFound:n,cleaned:s+r}}async function ha(t,e){let i=Q(t,e);if(!i)return{killed:0,cleaned:0};let n=0,s=0;for(let r of i.members)r.status!=="shutdown"&&(r.pid&&jp(r.pid)&&dI(r.pid)&&n++,Z(t,e,r.agentId,"shutdown"),Me(t,r.agentId),s++);return{killed:n,cleaned:s}}var xp=Y(()=>{"use strict";hi();Pt();ma();Zn();Ii()});var ga=Y(()=>{"use strict";ip();Qn();Ii();Eu();Zn();hi();Pt();ma();Ru();Rp();zp();xp()});var Gp={};sm(Gp,{PtyServer:()=>yn,startPtyServerProcess:()=>EI});import fI from"net";import ju from"crypto";async function EI(t){let e=new yn(t);await e.start(),process.on("SIGINT",async()=>{await e.stop(),process.exit(0)}),process.on("SIGTERM",async()=>{await e.stop(),process.exit(0)})}var hI,Sp,gI,II,yn,xu=Y(()=>{"use strict";_v();cu();Pt();ga();k();hI=3377,Sp="127.0.0.1",gI=2e3,II=1e3,yn=class{constructor(e){this.options=e;this.port=e.port||hI,this.debug=e.debug||!1,this.teamContext=this.loadTeamContext()}ai=null;server=null;outputHistory="";lastPromptIndex=0;lastSentPrompt="";lastDataReceivedTime=0;currentExchangeId=null;exchangeHistory=[];streamClients=[];port;debug;teamContext=null;isPollingMessages=!1;lastApprovalRequestId=null;lastApprovalToolDetail=null;pid=0;loadTeamContext(){let e=process.env.GK_TEAM_ID;return e?{teamId:e,teamName:process.env.GK_TEAM_NAME||"unknown",role:process.env.GK_TEAM_ROLE==="leader"?"leader":"member",agentId:process.env.GK_SUB_SESSION_ID||process.env.GK_PARENT_SESSION_ID||"",agentName:process.env.GK_AGENT_NAME||"agent",leaderPort:parseInt(process.env.GK_TEAM_LEADER_PORT||"3377",10),projectDir:ge(process.cwd())}:null}async start(){let{provider:e,model:i,tools:n,sessionState:s}=this.options;this.debug&&console.log(`[Server] Starting ${e} with model: ${i}`),this.ai=new To({provider:e,model:i,tools:n,debug:this.debug}),this.ai.on("data",r=>{if(this.outputHistory+=r,this.lastDataReceivedTime=Date.now(),this.streamClients.length>0){let o=this.parseOutputForEvents(r);for(let c of o)this.emitStreamEvent(c)}}),this.ai.on("ready",()=>{this.debug&&console.log(`[Server] ${e} is ready`)}),this.ai.on("exit",r=>{this.debug&&console.log(`[Server] ${e} exited with code: ${r}`),this.ai=null}),await this.ai.start(),await this.startTcpServer(),this.teamContext&&this.startTeamMessagePolling()}startTeamMessagePolling(){if(!this.teamContext||this.isPollingMessages)return;let{projectDir:e,agentId:i,teamId:n,agentName:s}=this.teamContext;this.debug&&console.log(`[Server] Starting team message polling for ${s} (${i})`),Z(e,n,i,"ready"),this.isPollingMessages=!0,this.startInboxPolling()}inboxPollingInterval=null;startInboxPolling(){if(!this.teamContext||this.inboxPollingInterval)return;let{projectDir:e,teamId:i,agentName:n}=this.teamContext;this.inboxPollingInterval=setInterval(()=>{let s=nr(e,i,n);for(let r of s)(r.type==="message"||r.type==="broadcast")&&(this.injectInboxMessage(r),Bt(e,i,r.id,{status:"delivered",deliveredAt:new Date().toISOString()}));this.checkAndWriteApprovalRequest()},II)}stopInboxPolling(){this.inboxPollingInterval&&(clearInterval(this.inboxPollingInterval),this.inboxPollingInterval=null)}checkAndWriteApprovalRequest(){if(!this.teamContext)return;let e=this.detectPendingTools();if(e.hasPending&&e.tools.length>0){let i=e.tools[0],n=i.command||i.path||"unknown";if(n!==this.lastApprovalToolDetail){let{projectDir:s,teamId:r,agentId:o,agentName:c}=this.teamContext,l=Be(o,c,"member"),u=ta(s,r,l,i.type,n,this.port);this.lastApprovalRequestId=u.id,this.lastApprovalToolDetail=n,this.debug&&console.log(`[Server] Wrote approval request to inbox: ${u.id}`)}}else this.lastApprovalToolDetail!==null&&(this.lastApprovalRequestId=null,this.lastApprovalToolDetail=null)}stopTeamMessagePolling(){if(!this.teamContext||!this.isPollingMessages)return;let{projectDir:e,agentId:i,teamId:n}=this.teamContext;this.debug&&console.log("[Server] Stopping team message polling"),this.stopInboxPolling(),this.isPollingMessages=!1,Z(e,n,i,"idle")}injectInboxMessage(e){if(!this.ai||!this.ai.getIsReady()){this.debug&&console.log("[Server] Cannot inject message - AI not ready");return}let i=this.formatInboxMessageForInjection(e);this.debug&&console.log(`[Server] Injecting message from ${e.from.name}: ${e.summary}`),this.teamContext&&Z(this.teamContext.projectDir,this.teamContext.teamId,this.teamContext.agentId,"busy"),this.lastPromptIndex=this.outputHistory.length,this.lastSentPrompt=i,this.currentExchangeId=ju.randomUUID(),this.lastDataReceivedTime=Date.now(),this.ai.write(i),setTimeout(()=>this.ai?.write("\r"),300),this.emitStreamEvent({type:"team_message_received",from:e.from.name,messageType:e.type,summary:e.summary})}formatInboxMessageForInjection(e){let i=[];if(i.push("<team-message>"),i.push(`From: ${e.from.name}`),i.push(`Type: ${e.type}`),e.metadata?.requestId&&i.push(`Request ID: ${e.metadata.requestId}`),i.push(""),i.push(e.content),i.push("</team-message>"),this.teamContext){let n=this.options.sessionState,s=this.options.provider,r=this.teamContext.agentName||"agent",c=n?.context?.agentName||r.replace(/-\d+$/,"");i.push(""),i.push("<agent-context>"),i.push(`You are: ${r}`),i.push(`Role: ${c}`),i.push(`Team: ${this.teamContext.teamName}`);let l=ou(c,s);if(l&&i.push(`Profile: @${l}`),n?.context?.skills&&n.context.skills.length>0){i.push("Skills:");for(let u of n.context.skills){let m=au(u,s);m&&i.push(` - ${u}: @${m}`)}}i.push("</agent-context>")}if(this.teamContext&&(e.type==="message"||e.type==="broadcast")){let n=fi(this.teamContext.projectDir,this.teamContext.teamId);if(i.push(""),i.push("<team-tasks>"),n.available.length>0){i.push("Available (ready to claim):");for(let s of n.available)i.push(` - ${s.taskId}: ${s.subject}`),s.description&&s.description!==s.subject&&i.push(` Description: ${s.description.slice(0,200)}`)}if(n.inProgress.length>0){i.push("In Progress:");for(let s of n.inProgress)i.push(` - ${s.taskId}: ${s.subject} [${s.owner}]`)}if(n.blocked.length>0){i.push("Blocked:");for(let s of n.blocked)i.push(` - ${s.taskId}: ${s.subject} (waiting on: ${s.blockedBy.join(", ")})`)}n.completed.length>0&&i.push(`Completed: ${n.completed.length} task(s)`),i.push("</team-tasks>")}switch(e.type){case"shutdown_request":i.push(""),i.push('Instructions: You have received a shutdown request. If you have completed your current task, respond with SendMessage(type: "shutdown_response", approve: true). If you need more time, respond with approve: false and explain why.');break;case"message":case"broadcast":i.push(""),i.push("<instructions>"),i.push("Process this message from your teammate. Use the task list above to understand the current state."),i.push(""),i.push("SHELL COMMANDS:"),i.push("- Claim a task: gk team task-claim <taskId> --as "+(this.teamContext?.agentName||"agent")),i.push("- Complete a task: gk team task-done <taskId>"),i.push('- Send message: gk team send <recipientName> "<message>"'),i.push("- List tasks: gk team tasks"),i.push(""),i.push("COMMUNICATION PROTOCOL:"),i.push("- You can send messages to any teammate (Main Agent or other sub-agents)"),i.push("- Request progress updates from upstream agents (tasks you depend on)"),i.push("- Provide progress updates to downstream agents (tasks blocked by yours)"),i.push(""),i.push("WHEN YOU COMPLETE A TASK:"),i.push("1. Run task-done command to mark it complete"),i.push("2. Send completion message to Main Agent (leader)"),i.push("3. Notify downstream agents who are blocked by your task"),i.push(' Example: "Task task-xxx completed. Results saved to plans/research.md. You can now proceed."'),i.push("</instructions>");break;case"plan_approval_request":i.push(""),i.push('Instructions: A teammate is requesting approval for their plan. Review it and respond with SendMessage(type: "plan_approval_response", approve: true/false).');break}return i.join(`
22
+ `)}startTcpServer(){return new Promise((e,i)=>{this.server=fI.createServer(n=>{let s=!1;n.on("data",r=>{let o=r.toString().trim(),[c,...l]=o.split(" "),u=l.join(" "),m=this.handleCommand(c,u);if(m==="__STREAM_MODE__"){s=!0,this.streamClients.push(n),n.write(JSON.stringify({type:"stream_started"})+`
23
+ `);return}n.write(m+`
24
+ `)}),n.on("error",()=>{}),n.on("close",()=>{s&&(this.streamClients=this.streamClients.filter(r=>r!==n))})}),this.server.listen(this.port,Sp,()=>{this.debug&&console.log(`[Server] Listening on ${Sp}:${this.port}`),e()}),this.server.on("error",n=>{n.code==="EADDRINUSE"?i(new Error(`Port ${this.port} is already in use`)):i(n)})})}handleCommand(e,i){switch(e){case"status":return JSON.stringify(this.getStatus());case"send":return this.handleSend(i);case"read":let n=parseInt(i)||200;return this.outputHistory.split(`
25
+ `).slice(-n).join(`
26
+ `);case"extract":return this.extractAnswer();case"exchange":return JSON.stringify(this.getStructuredExchange());case"pending":return JSON.stringify(this.detectPendingTools());case"complete":return JSON.stringify(this.isComplete());case"history":return i==="clear"?(this.exchangeHistory=[],JSON.stringify({ok:!0,message:"History cleared"})):JSON.stringify({provider:this.options.provider,count:this.exchangeHistory.length,exchanges:this.exchangeHistory});case"stop":return this.ai?(this.ai.stop().then(()=>{process.exit(0)}),JSON.stringify({ok:!0,message:"Stopping..."})):JSON.stringify({error:"Not running"});case"stream":return"__STREAM_MODE__";case"team":return JSON.stringify(this.getTeamStatus());default:return JSON.stringify({error:"Unknown command: "+e})}}handleSend(e){return!this.ai||!this.ai.getIsReady()?JSON.stringify({error:"Not ready"}):(this.lastPromptIndex=this.outputHistory.length,/^[123yn]$/i.test(e.trim())||(this.lastSentPrompt=e,this.currentExchangeId=ju.randomUUID()),this.lastDataReceivedTime=Date.now(),this.ai.write(e),setTimeout(()=>this.ai?.write("\r"),300),JSON.stringify({ok:!0,exchangeId:this.currentExchangeId}))}getStatus(){return{running:this.ai!==null,ready:this.ai?.getIsReady()||!1,provider:this.options.provider,outputLength:this.outputHistory.length}}cleanAnsi(e){return e.replace(/\x1b\[\?[0-9;]*[a-z]/gi,"").replace(/\x1b\[1C/g," ").replace(/\x1b\[[0-9;]*[A-Za-z]/g,"").replace(/\x1b\][^\x07]*\x07/g,"").replace(/\r/g,"")}extractAnswer(){return this.options.provider==="gemini"?this.extractAnswerGemini():this.extractAnswerClaude()}extractAnswerClaude(){let i=this.cleanAnsi(this.outputHistory).match(/●\s*([\s\S]*?)(?=❯|$)/g);if(i&&i.length>0){let n=i[i.length-1];return n=n.replace(/^●\s*/,"").replace(/[─╭╰│┌┐└┘├┤┬┴┼⎿⎾]+/g,"").replace(/\? for shortcuts/g,"").replace(/esc to interrupt/g,"").replace(/\w+ing…/g,"").replace(/\(thinking\)/g,"").replace(/·\s*/g,"").replace(/[✢✶✻✽*]/g,"").replace(/Tip:\s*Use\s+\/\w+[^.]*\./gi,"").trim(),n.split(`
27
+ `).map(r=>r.trim()).filter(r=>!(r.length===0||r.match(/^[\s─╭╰│┌┐└┘├┤┬┴┼⎿⎾✢✶✻✽·*]+$/)||r.match(/thinking|thought for/i)||r.match(/^\d+s\)$/)||r.match(/^IDE disconnected$/)||r.match(/^Tip:\s*Use\s+\/\w+/i))).join(`
28
+ `).trim()}return""}extractAnswerGemini(){let e=this.outputHistory.slice(this.lastPromptIndex),i=this.cleanAnsi(e),n=i.lastIndexOf("\u2726");if(n===-1)return"";let s=i.slice(n+1),r=s.match(/[✓⊶⊷x?]\s*(?:Shell|WriteFile|ReadFile|ReadFolder|GoogleSearch|Activate Skill)/i);r&&(s=s.slice(0,r.index));let o=s.match(/[⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏]|\(esc to cancel/);o&&(s=s.slice(0,o.index));let c=s.match(/╭─|│\s*\d+\s*│|│\s*\d+\s+[*#\-\w]/);c&&(s=s.slice(0,c.index));let l=s.match(/\n\s*>\s+(?!Type your message)[^\n]{10,}/);l&&(s=s.slice(0,l.index));let u=s.trim();u=u.replace(/[█▀▄░▓▒│┃╭╮╯╰┌┐└┘├┤┬┴┼─━╱╲]+/g,"").replace(/[⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏]/g,"").replace(/\d+s\)/g,"").replace(/\(esc to cancel[^)]*\)/g,"").replace(/Action Required[^\n]*/gi,"").replace(/Waiting for user confirmation[^\n]*/gi,"").replace(/\d+\.\s*Allow[^\n]*/gi,"").replace(/>\s+[^\n]+/g,"").replace(/Type your message[^\n]*/gi,"");let m=u.split(`
29
+ `),p=[],d=new Set;for(let A of m){let f=A.trim();f.length===0?(p.length===0||p[p.length-1].trim()!=="")&&p.push(A):d.has(f)||(d.add(f),p.push(A))}return p.join(`
30
+ `).trim()}detectPendingTools(){let i=this.cleanAnsi(this.outputHistory).slice(-8e3),n=[],s=i.includes("Waiting for user confirmation")||i.includes("Action Required")||i.includes("Allow once")||i.includes("Allow for this session")||i.match(/●\s*1\.\s*Allow/)||i.match(/Apply this change\?/i);if(this.options.provider==="gemini"){let r=[{regex:/\?\s*Shell\s+([^\n│\[]+)/gi,type:"shell",field:"command"},{regex:/\?\s*WriteFile\s+(?:Writing to\s+)?([^\n│]+)/gi,type:"write_file",field:"path"},{regex:/\?\s*ReadFile\s+(?:Reading\s+)?([^\n│]+)/gi,type:"read_file",field:"path"},{regex:/\?\s*ReadFolder\s+([^\n│]+)/gi,type:"read_folder",field:"path"}],o=new Set;for(let{regex:l,type:u,field:m}of r){let p=i.matchAll(l);for(let d of p){let A=this.cleanToolDetail(d[1]),f=`${u}:${A.slice(0,30)}`;if(A&&!o.has(f)&&s){o.add(f);let g={type:u,[m]:A,waiting:!0,options:["1. Allow once","2. Allow for this session","3. No, suggest changes"]};n.push(g)}}}i.match(/Apply this change\?/i)&&s&&n.push({type:"apply_change",waiting:!0,options:["1. Allow once","2. Allow for this session","3. No, suggest changes"]});let c=i.match(/Action Required\s*(\d+)\s*of\s*(\d+)/i);c&&n.forEach(l=>{l.actionRequired={current:parseInt(c[1]),total:parseInt(c[2])}})}if(this.options.provider==="claude"){let r=i.match(/Run\s+(.+?)\s*\?/i);r&&s&&n.push({type:"shell",command:r[1].trim(),waiting:!0});let o=i.match(/Write to\s+(.+?)\s*\?/i);o&&s&&n.push({type:"write_file",path:o[1].trim(),waiting:!0});let c=i.match(/Edit\s+(.+?)\s*\?/i);c&&s&&n.push({type:"edit_file",path:c[1].trim(),waiting:!0})}return{hasPending:n.length>0&&!!s,tools:n,hint:s?'Send "1" to allow once, "2" for session, "3" to suggest changes':void 0}}cleanToolDetail(e){return e.replace(/[│┃╭╮╯╰┌┐└┘├┤┬┴┼█▀▄░▓▒]+/g,"").replace(/[⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏]/g,"").replace(/\(esc to cancel[^)]*\)/g,"").replace(/\d+s\)/g,"").replace(/…\s*$/,"").replace(/\s+/g," ").trim()}extractToolResults(){let e=[],i=new Set;if(this.options.provider==="gemini"){let n=this.cleanAnsi(this.outputHistory),s=`> ${this.lastSentPrompt}`,r=n.lastIndexOf(s),o=r!==-1?n.slice(r):n.slice(-3e4),c=[{regex:/✓\s*Shell\s+([^\n│]+)/gi,type:"shell",status:"completed"},{regex:/✓\s*WriteFile\s+(?:Writing to\s+)?([^\n│]+)/gi,type:"write_file",status:"completed"},{regex:/✓\s*ReadFile\s+(?:Reading\s+)?([^\n│]+)/gi,type:"read_file",status:"completed"},{regex:/✓\s*ReadFolder\s+([^\n│]+)/gi,type:"read_folder",status:"completed"},{regex:/✓\s*GoogleSearch\s+([^\n│]+)/gi,type:"web_search",status:"completed"},{regex:/x\s*Shell\s+([^\n│]+)/gi,type:"shell",status:"failed"},{regex:/x\s*WriteFile\s+([^\n│]+)/gi,type:"write_file",status:"failed"}];for(let{regex:l,type:u,status:m}of c){let p=o.matchAll(l);for(let d of p){let A=this.cleanToolDetail(d[1]),f=`${u}:${A.slice(0,50)}`;A&&!i.has(f)&&(i.add(f),e.push({type:u,detail:A,status:m}))}}}if(this.options.provider==="claude"){let s=this.cleanAnsi(this.outputHistory).matchAll(/Ran\s+(\w+):\s*([^\n]+)/g);for(let r of s){let o=`${r[1]}:${r[2].slice(0,50)}`;i.has(o)||(i.add(o),e.push({type:r[1],detail:r[2].trim(),status:"completed"}))}}return e}getStructuredExchange(){let e=this.extractAnswer(),i=this.detectPendingTools(),n=this.extractToolResults();this.currentExchangeId||(this.currentExchangeId=ju.randomUUID());let s={id:this.currentExchangeId,timestamp:new Date().toISOString(),prompt:this.lastSentPrompt,answer:e,pending:i.hasPending?i.tools:[],toolResults:n,status:i.hasPending?"waiting_confirmation":"complete"};if(s.status==="complete"&&e.trim()){let r=this.exchangeHistory.findIndex(o=>o.id===this.currentExchangeId);r>=0?this.exchangeHistory[r]=s:this.exchangeHistory.push(s),this.currentExchangeId=null}return s}isComplete(){let e=this.outputHistory.slice(this.lastPromptIndex),i=this.cleanAnsi(e);if(this.options.provider==="claude"){let n=i.includes("\u25CF"),s=i.lastIndexOf("\u25CF"),r=i.lastIndexOf("\u276F");return n&&r>s?{complete:!0}:{complete:!1,reason:"streaming"}}else if(this.options.provider==="gemini"){if(!i.includes("\u2726"))return{complete:!1,reason:"no_response"};let s=i.slice(-3e3),r=s.includes("Waiting for user confirmation")||s.includes("Action Required")||s.includes("Allow once")&&s.includes("Allow for this session"),o=/\?\s*(Shell|WriteFile|ReadFile|ReadFolder)/i.test(s);if(r||o)return{complete:!1,reason:"pending_tool",hint:'Tool confirmation required. Use "gk agent send 1" to approve.'};if(Date.now()-this.lastDataReceivedTime<gI)return{complete:!1,reason:"streaming"};let u=i.lastIndexOf("\u2726");return i.slice(u+1).trim().length>50?{complete:!0}:{complete:!1,reason:"waiting_content"}}return{complete:!1,reason:"unknown"}}parseOutputForEvents(e){let i=this.cleanAnsi(e),n=[];if(i.match(/\?\s*(Shell|WriteFile|ReadFile|ReadFolder)/i)){let r=i.match(/\?\s*(Shell|WriteFile|ReadFile|ReadFolder)\s+([^\n\[]+)/i);n.push({type:"tool_confirmation_required",tool:r?r[1]:"unknown",detail:r?r[2].trim():null})}let s=i.match(/✓\s*(Shell|WriteFile|ReadFile|ReadFolder|GoogleSearch)\s+([^\n]+)/i);return s&&n.push({type:"tool_completed",tool:s[1],detail:s[2].trim()}),(i.includes("\u2726")||i.includes("\u25CF"))&&n.push({type:"response_chunk"}),(i.match(/[❯>]\s*$/)||i.includes("Type your message"))&&n.push({type:"prompt_ready"}),n}emitStreamEvent(e){let i=JSON.stringify(e)+`
31
+ `;for(let n of this.streamClients)try{n.write(i)}catch{}this.streamClients=this.streamClients.filter(n=>!n.destroyed)}async stop(){this.stopTeamMessagePolling(),this.teamContext&&Z(this.teamContext.projectDir,this.teamContext.teamId,this.teamContext.agentId,"shutdown"),this.server&&this.server.close(),this.ai&&await this.ai.stop()}getTeamContext(){return this.teamContext}isInTeamMode(){return this.teamContext!==null}getTeamStatus(){return this.teamContext?{inTeam:!0,teamId:this.teamContext.teamId,teamName:this.teamContext.teamName,role:this.teamContext.role,agentName:this.teamContext.agentName,isPolling:this.isPollingMessages}:{inTeam:!1}}}});import{EventEmitter as wA}from"events";function $a(t){return t==null?[]:Array.isArray(t)?t:[t]}function DA(t,e,i,n){var s,r=t[e],o=~n.string.indexOf(e)?i==null||i===!0?"":String(i):typeof i=="boolean"?i:~n.boolean.indexOf(e)?i==="false"?!1:i==="true"||(t._.push((s=+i,s*0===0?s:i)),!!i):(s=+i,s*0===0?s:i);t[e]=r==null?o:Array.isArray(r)?r.concat(o):[r,o]}function TA(t,e){t=t||[],e=e||{};var i,n,s,r,o,c={_:[]},l=0,u=0,m=0,p=t.length;let d=e.alias!==void 0,A=e.unknown!==void 0,f=e.default!==void 0;if(e.alias=e.alias||{},e.string=$a(e.string),e.boolean=$a(e.boolean),d)for(i in e.alias)for(n=e.alias[i]=$a(e.alias[i]),l=0;l<n.length;l++)(e.alias[n[l]]=n.concat(i)).splice(l,1);for(l=e.boolean.length;l-- >0;)for(n=e.alias[e.boolean[l]]||[],u=n.length;u-- >0;)e.boolean.push(n[u]);for(l=e.string.length;l-- >0;)for(n=e.alias[e.string[l]]||[],u=n.length;u-- >0;)e.string.push(n[u]);if(f){for(i in e.default)if(r=typeof e.default[i],n=e.alias[i]=e.alias[i]||[],e[r]!==void 0)for(e[r].push(i),l=0;l<n.length;l++)e[r].push(n[l])}let g=A?Object.keys(e.alias):[];for(l=0;l<p;l++){if(s=t[l],s==="--"){c._=c._.concat(t.slice(++l));break}for(u=0;u<s.length&&s.charCodeAt(u)===45;u++);if(u===0)c._.push(s);else if(s.substring(u,u+3)==="no-"){if(r=s.substring(u+3),A&&!~g.indexOf(r))return e.unknown(s);c[r]=!1}else{for(m=u+1;m<s.length&&s.charCodeAt(m)!==61;m++);for(r=s.substring(u,m),o=s.substring(++m)||l+1===p||(""+t[l+1]).charCodeAt(0)===45||t[++l],n=u===2?[r]:r,m=0;m<n.length;m++){if(r=n[m],A&&!~g.indexOf(r))return e.unknown("-".repeat(u)+r);DA(c,r,m+1<n.length||o,e)}}}if(f)for(i in e.default)c[i]===void 0&&(c[i]=e.default[i]);if(d)for(i in c)for(n=e.alias[i]||[];n.length>0;)c[n.shift()]=c[i];return c}var am=t=>t.replace(/[<[].+/,"").trim(),XA=t=>{let e=/<([^>]+)>/g,i=/\[([^\]]+)\]/g,n=[],s=c=>{let l=!1,u=c[1];return u.startsWith("...")&&(u=u.slice(3),l=!0),{required:c[0].startsWith("<"),value:u,variadic:l}},r;for(;r=e.exec(t);)n.push(s(r));let o;for(;o=i.exec(t);)n.push(s(o));return n},HA=t=>{let e={alias:{},boolean:[]};for(let[i,n]of t.entries())n.names.length>1&&(e.alias[n.names[0]]=n.names.slice(1)),n.isBoolean&&(n.negated&&t.some((r,o)=>o!==i&&r.names.some(c=>n.names.includes(c))&&typeof r.required=="boolean")||e.boolean.push(n.names[0]));return e},rm=t=>t.sort((e,i)=>e.length>i.length?-1:1)[0],om=(t,e)=>t.length>=e?t:`${t}${" ".repeat(e-t.length)}`,LA=t=>t.replace(/([a-z])-([a-z])/g,(e,i,n)=>i+n.toUpperCase()),_A=(t,e,i)=>{let n=0,s=e.length,r=t,o;for(;n<s;++n)o=r[e[n]],r=r[e[n]]=n===s-1?i:o??(~e[n+1].indexOf(".")||!(+e[n+1]>-1)?{}:[])},$A=(t,e)=>{for(let i of Object.keys(e)){let n=e[i];n.shouldTransform&&(t[i]=Array.prototype.concat.call([],t[i]),typeof n.transformFunction=="function"&&(t[i]=t[i].map(n.transformFunction)))}},ed=t=>{let e=/([^\\\/]+)$/.exec(t);return e?e[1]:""},cm=t=>t.split(".").map((e,i)=>i===0?LA(e):e).join("."),ts=class extends Error{constructor(e){super(e),this.name=this.constructor.name,typeof Error.captureStackTrace=="function"?Error.captureStackTrace(this,this.constructor):this.stack=new Error(e).stack}},ec=class{constructor(e,i,n){this.rawName=e,this.description=i,this.config=Object.assign({},n),e=e.replace(/\.\*/g,""),this.negated=!1,this.names=am(e).split(",").map(s=>{let r=s.trim().replace(/^-{1,2}/,"");return r.startsWith("no-")&&(this.negated=!0,r=r.replace(/^no-/,"")),cm(r)}).sort((s,r)=>s.length>r.length?1:-1),this.name=this.names[this.names.length-1],this.negated&&this.config.default==null&&(this.config.default=!0),e.includes("<")?this.required=!0:e.includes("[")?this.required=!1:this.isBoolean=!0}},td=process.argv,id=`${process.platform}-${process.arch} node-${process.version}`,fr=class{constructor(e,i,n={},s){this.rawName=e,this.description=i,this.config=n,this.cli=s,this.options=[],this.aliasNames=[],this.name=am(e),this.args=XA(e),this.examples=[]}usage(e){return this.usageText=e,this}allowUnknownOptions(){return this.config.allowUnknownOptions=!0,this}ignoreOptionDefaultValue(){return this.config.ignoreOptionDefaultValue=!0,this}version(e,i="-v, --version"){return this.versionNumber=e,this.option(i,"Display version number"),this}example(e){return this.examples.push(e),this}option(e,i,n){let s=new ec(e,i,n);return this.options.push(s),this}alias(e){return this.aliasNames.push(e),this}action(e){return this.commandAction=e,this}isMatched(e){return this.name===e||this.aliasNames.includes(e)}get isDefaultCommand(){return this.name===""||this.aliasNames.includes("!")}get isGlobalCommand(){return this instanceof hr}hasOption(e){return e=e.split(".")[0],this.options.find(i=>i.names.includes(e))}outputHelp(){let{name:e,commands:i}=this.cli,{versionNumber:n,options:s,helpCallback:r}=this.cli.globalCommand,o=[{body:`${e}${n?`/${n}`:""}`}];if(o.push({title:"Usage",body:` $ ${e} ${this.usageText||this.rawName}`}),(this.isGlobalCommand||this.isDefaultCommand)&&i.length>0){let u=rm(i.map(m=>m.rawName));o.push({title:"Commands",body:i.map(m=>` ${om(m.rawName,u.length)} ${m.description}`).join(`
32
+ `)}),o.push({title:"For more info, run any command with the `--help` flag",body:i.map(m=>` $ ${e}${m.name===""?"":` ${m.name}`} --help`).join(`
33
+ `)})}let l=this.isGlobalCommand?s:[...this.options,...s||[]];if(!this.isGlobalCommand&&!this.isDefaultCommand&&(l=l.filter(u=>u.name!=="version")),l.length>0){let u=rm(l.map(m=>m.rawName));o.push({title:"Options",body:l.map(m=>` ${om(m.rawName,u.length)} ${m.description} ${m.config.default===void 0?"":`(default: ${m.config.default})`}`).join(`
34
+ `)})}this.examples.length>0&&o.push({title:"Examples",body:this.examples.map(u=>typeof u=="function"?u(e):u).join(`
35
+ `)}),r&&(o=r(o)||o),console.log(o.map(u=>u.title?`${u.title}:
36
+ ${u.body}`:u.body).join(`
37
+
38
+ `))}outputVersion(){let{name:e}=this.cli,{versionNumber:i}=this.cli.globalCommand;i&&console.log(`${e}/${i} ${id}`)}checkRequiredArgs(){let e=this.args.filter(i=>i.required).length;if(this.cli.args.length<e)throw new ts(`missing required args for command \`${this.rawName}\``)}checkUnknownOptions(){let{options:e,globalCommand:i}=this.cli;if(!this.config.allowUnknownOptions){for(let n of Object.keys(e))if(n!=="--"&&!this.hasOption(n)&&!i.hasOption(n))throw new ts(`Unknown option \`${n.length>1?`--${n}`:`-${n}`}\``)}}checkOptionValue(){let{options:e,globalCommand:i}=this.cli,n=[...i.options,...this.options];for(let s of n){let r=e[s.name.split(".")[0]];if(s.required){let o=n.some(c=>c.negated&&c.names.includes(s.name));if(r===!0||r===!1&&!o)throw new ts(`option \`${s.rawName}\` value is missing`)}}}},hr=class extends fr{constructor(e){super("@@global@@","",{},e)}},dr=Object.assign,tc=class extends wA{constructor(e=""){super(),this.name=e,this.commands=[],this.rawArgs=[],this.args=[],this.options={},this.globalCommand=new hr(this),this.globalCommand.usage("<command> [options]")}usage(e){return this.globalCommand.usage(e),this}command(e,i,n){let s=new fr(e,i||"",n,this);return s.globalCommand=this.globalCommand,this.commands.push(s),s}option(e,i,n){return this.globalCommand.option(e,i,n),this}help(e){return this.globalCommand.option("-h, --help","Display this message"),this.globalCommand.helpCallback=e,this.showHelpOnExit=!0,this}version(e,i="-v, --version"){return this.globalCommand.version(e,i),this.showVersionOnExit=!0,this}example(e){return this.globalCommand.example(e),this}outputHelp(){this.matchedCommand?this.matchedCommand.outputHelp():this.globalCommand.outputHelp()}outputVersion(){this.globalCommand.outputVersion()}setParsedInfo({args:e,options:i},n,s){return this.args=e,this.options=i,n&&(this.matchedCommand=n),s&&(this.matchedCommandName=s),this}unsetMatchedCommand(){this.matchedCommand=void 0,this.matchedCommandName=void 0}parse(e=td,{run:i=!0}={}){this.rawArgs=e,this.name||(this.name=e[1]?ed(e[1]):"cli");let n=!0;for(let r of this.commands){let o=this.mri(e.slice(2),r),c=o.args[0];if(r.isMatched(c)){n=!1;let l=dr(dr({},o),{args:o.args.slice(1)});this.setParsedInfo(l,r,c),this.emit(`command:${c}`,r)}}if(n){for(let r of this.commands)if(r.name===""){n=!1;let o=this.mri(e.slice(2),r);this.setParsedInfo(o,r),this.emit("command:!",r)}}if(n){let r=this.mri(e.slice(2));this.setParsedInfo(r)}this.options.help&&this.showHelpOnExit&&(this.outputHelp(),i=!1,this.unsetMatchedCommand()),this.options.version&&this.showVersionOnExit&&this.matchedCommandName==null&&(this.outputVersion(),i=!1,this.unsetMatchedCommand());let s={args:this.args,options:this.options};return i&&this.runMatchedCommand(),!this.matchedCommand&&this.args[0]&&this.emit("command:*"),s}mri(e,i){let n=[...this.globalCommand.options,...i?i.options:[]],s=HA(n),r=[],o=e.indexOf("--");o>-1&&(r=e.slice(o+1),e=e.slice(0,o));let c=TA(e,s);c=Object.keys(c).reduce((d,A)=>dr(dr({},d),{[cm(A)]:c[A]}),{_:[]});let l=c._,u={"--":r},m=i&&i.config.ignoreOptionDefaultValue?i.config.ignoreOptionDefaultValue:this.globalCommand.config.ignoreOptionDefaultValue,p=Object.create(null);for(let d of n){if(!m&&d.config.default!==void 0)for(let A of d.names)u[A]=d.config.default;Array.isArray(d.config.type)&&p[d.name]===void 0&&(p[d.name]=Object.create(null),p[d.name].shouldTransform=!0,p[d.name].transformFunction=d.config.type[0])}for(let d of Object.keys(c))if(d!=="_"){let A=d.split(".");_A(u,A,c[d]),$A(u,p)}return{args:l,options:u}}runMatchedCommand(){let{args:e,options:i,matchedCommand:n}=this;if(!n||!n.commandAction)return;n.checkUnknownOptions(),n.checkOptionValue(),n.checkRequiredArgs();let s=[];return n.args.forEach((r,o)=>{r.variadic?s.push(e.slice(o)):s.push(e[o])}),s.push(i),n.commandAction.apply(this,s)}},lm=(t="")=>new tc(t);import{existsSync as Qh}from"fs";import{join as Bh}from"path";import{spawn as Jh,spawnSync as Zh}from"child_process";import Gr from"node:process";var um=(t=0)=>e=>`\x1B[${e+t}m`,mm=(t=0)=>e=>`\x1B[${38+t};5;${e}m`,vm=(t=0)=>(e,i,n)=>`\x1B[${38+t};2;${e};${i};${n}m`,W={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]}},GR=Object.keys(W.modifier),nd=Object.keys(W.color),sd=Object.keys(W.bgColor),MR=[...nd,...sd];function rd(){let t=new Map;for(let[e,i]of Object.entries(W)){for(let[n,s]of Object.entries(i))W[n]={open:`\x1B[${s[0]}m`,close:`\x1B[${s[1]}m`},i[n]=W[n],t.set(s[0],s[1]);Object.defineProperty(W,e,{value:i,enumerable:!1})}return Object.defineProperty(W,"codes",{value:t,enumerable:!1}),W.color.close="\x1B[39m",W.bgColor.close="\x1B[49m",W.color.ansi=um(),W.color.ansi256=mm(),W.color.ansi16m=vm(),W.bgColor.ansi=um(10),W.bgColor.ansi256=mm(10),W.bgColor.ansi16m=vm(10),Object.defineProperties(W,{rgbToAnsi256:{value(e,i,n){return e===i&&i===n?e<8?16:e>248?231:Math.round((e-8)/247*24)+232:16+36*Math.round(e/255*5)+6*Math.round(i/255*5)+Math.round(n/255*5)},enumerable:!1},hexToRgb:{value(e){let i=/[a-f\d]{6}|[a-f\d]{3}/i.exec(e.toString(16));if(!i)return[0,0,0];let[n]=i;n.length===3&&(n=[...n].map(r=>r+r).join(""));let s=Number.parseInt(n,16);return[s>>16&255,s>>8&255,s&255]},enumerable:!1},hexToAnsi256:{value:e=>W.rgbToAnsi256(...W.hexToRgb(e)),enumerable:!1},ansi256ToAnsi:{value(e){if(e<8)return 30+e;if(e<16)return 90+(e-8);let i,n,s;if(e>=232)i=((e-232)*10+8)/255,n=i,s=i;else{e-=16;let c=e%36;i=Math.floor(e/36)/5,n=Math.floor(c/6)/5,s=c%6/5}let r=Math.max(i,n,s)*2;if(r===0)return 30;let o=30+(Math.round(s)<<2|Math.round(n)<<1|Math.round(i));return r===2&&(o+=60),o},enumerable:!1},rgbToAnsi:{value:(e,i,n)=>W.ansi256ToAnsi(W.rgbToAnsi256(e,i,n)),enumerable:!1},hexToAnsi:{value:e=>W.ansi256ToAnsi(W.hexToAnsi256(e)),enumerable:!1}}),W}var od=rd(),ye=od;import ic from"node:process";import ad from"node:os";import pm from"node:tty";function Ue(t,e=globalThis.Deno?globalThis.Deno.args:ic.argv){let i=t.startsWith("-")?"":t.length===1?"-":"--",n=e.indexOf(i+t),s=e.indexOf("--");return n!==-1&&(s===-1||n<s)}var{env:C}=ic,gr;Ue("no-color")||Ue("no-colors")||Ue("color=false")||Ue("color=never")?gr=0:(Ue("color")||Ue("colors")||Ue("color=true")||Ue("color=always"))&&(gr=1);function cd(){if("FORCE_COLOR"in C)return C.FORCE_COLOR==="true"?1:C.FORCE_COLOR==="false"?0:C.FORCE_COLOR.length===0?1:Math.min(Number.parseInt(C.FORCE_COLOR,10),3)}function ld(t){return t===0?!1:{level:t,hasBasic:!0,has256:t>=2,has16m:t>=3}}function ud(t,{streamIsTTY:e,sniffFlags:i=!0}={}){let n=cd();n!==void 0&&(gr=n);let s=i?gr:n;if(s===0)return 0;if(i){if(Ue("color=16m")||Ue("color=full")||Ue("color=truecolor"))return 3;if(Ue("color=256"))return 2}if("TF_BUILD"in C&&"AGENT_NAME"in C)return 1;if(t&&!e&&s===void 0)return 0;let r=s||0;if(C.TERM==="dumb")return r;if(ic.platform==="win32"){let o=ad.release().split(".");return Number(o[0])>=10&&Number(o[2])>=10586?Number(o[2])>=14931?3:2:1}if("CI"in C)return["GITHUB_ACTIONS","GITEA_ACTIONS","CIRCLECI"].some(o=>o in C)?3:["TRAVIS","APPVEYOR","GITLAB_CI","BUILDKITE","DRONE"].some(o=>o in C)||C.CI_NAME==="codeship"?1:r;if("TEAMCITY_VERSION"in C)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(C.TEAMCITY_VERSION)?1:0;if(C.COLORTERM==="truecolor"||C.TERM==="xterm-kitty"||C.TERM==="xterm-ghostty"||C.TERM==="wezterm")return 3;if("TERM_PROGRAM"in C){let o=Number.parseInt((C.TERM_PROGRAM_VERSION||"").split(".")[0],10);switch(C.TERM_PROGRAM){case"iTerm.app":return o>=3?3:2;case"Apple_Terminal":return 2}}return/-256(color)?$/i.test(C.TERM)?2:/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(C.TERM)||"COLORTERM"in C?1:r}function Am(t,e={}){let i=ud(t,{streamIsTTY:t&&t.isTTY,...e});return ld(i)}var md={stdout:Am({isTTY:pm.isatty(1)}),stderr:Am({isTTY:pm.isatty(2)})},dm=md;function fm(t,e,i){let n=t.indexOf(e);if(n===-1)return t;let s=e.length,r=0,o="";do o+=t.slice(r,n)+e+i,r=n+s,n=t.indexOf(e,r);while(n!==-1);return o+=t.slice(r),o}function hm(t,e,i,n){let s=0,r="";do{let o=t[n-1]==="\r";r+=t.slice(s,o?n-1:n)+e+(o?`\r
10
39
  `:`
11
- `)+i,r=n+1,n=t.indexOf(`
12
- `,r)}while(n!==-1);return o+=t.slice(r),o}var{stdout:ml,stderr:El}=vl,Rs=Symbol("GENERATOR"),pi=Symbol("STYLER"),$i=Symbol("IS_EMPTY"),pl=["ansi","ansi","ansi256","ansi16m"],Ii=Object.create(null),gu=(t,e={})=>{if(e.level&&!(Number.isInteger(e.level)&&e.level>=0&&e.level<=3))throw new Error("The `level` option should be an integer from 0 to 3");let i=ml?ml.level:0;t.level=e.level===void 0?i:e.level};var ju=t=>{let e=(...i)=>i.join(" ");return gu(e,t),Object.setPrototypeOf(e,en.prototype),e};function en(t){return ju(t)}Object.setPrototypeOf(en.prototype,Function.prototype);for(let[t,e]of Object.entries(Re))Ii[t]={get(){let i=sr(this,gs(e.open,e.close,this[pi]),this[$i]);return Object.defineProperty(this,t,{value:i}),i}};Ii.visible={get(){let t=sr(this,this[pi],!0);return Object.defineProperty(this,"visible",{value:t}),t}};var zs=(t,e,i,...n)=>t==="rgb"?e==="ansi16m"?Re[i].ansi16m(...n):e==="ansi256"?Re[i].ansi256(Re.rgbToAnsi256(...n)):Re[i].ansi(Re.rgbToAnsi(...n)):t==="hex"?zs("rgb",e,i,...Re.hexToRgb(...n)):Re[i][t](...n),xu=["rgb","hex","ansi256"];for(let t of xu){Ii[t]={get(){let{level:i}=this;return function(...n){let r=gs(zs(t,pl[i],"color",...n),Re.color.close,this[pi]);return sr(this,r,this[$i])}}};let e="bg"+t[0].toUpperCase()+t.slice(1);Ii[e]={get(){let{level:i}=this;return function(...n){let r=gs(zs(t,pl[i],"bgColor",...n),Re.bgColor.close,this[pi]);return sr(this,r,this[$i])}}}}var Gu=Object.defineProperties(()=>{},{...Ii,level:{enumerable:!0,get(){return this[Rs].level},set(t){this[Rs].level=t}}}),gs=(t,e,i)=>{let n,r;return i===void 0?(n=t,r=e):(n=i.openAll+t,r=e+i.closeAll),{open:t,close:e,openAll:n,closeAll:r,parent:i}},sr=(t,e,i)=>{let n=(...r)=>Su(n,r.length===1?""+r[0]:r.join(" "));return Object.setPrototypeOf(n,Gu),n[Rs]=t,n[pi]=e,n[$i]=i,n},Su=(t,e)=>{if(t.level<=0||!e)return t[$i]?"":e;let i=t[pi];if(i===void 0)return e;let{openAll:n,closeAll:r}=i;if(e.includes("\x1B"))for(;i!==void 0;)e=Al(e,i.close,i.open),i=i.parent;let o=e.indexOf(`
13
- `);return o!==-1&&(e=ul(e,r,n,o)),n+e+r};Object.defineProperties(en.prototype,Ii);var Yu=en(),zf=en({level:El?El.level:0});var ze=Yu;import zl from"node:process";import vr from"node:process";var Wu=(t,e,i,n)=>{if(i==="length"||i==="prototype"||i==="arguments"||i==="caller")return;let r=Object.getOwnPropertyDescriptor(t,i),o=Object.getOwnPropertyDescriptor(e,i);!Mu(r,o)&&n||Object.defineProperty(t,i,o)},Mu=function(t,e){return t===void 0||t.configurable||t.writable===e.writable&&t.enumerable===e.enumerable&&t.configurable===e.configurable&&(t.writable||t.value===e.value)},Cu=(t,e)=>{let i=Object.getPrototypeOf(e);i!==Object.getPrototypeOf(t)&&Object.setPrototypeOf(t,i)},Ou=(t,e)=>`/* Wrapped ${t}*/
14
- ${e}`,Uu=Object.getOwnPropertyDescriptor(Function.prototype,"toString"),Ku=Object.getOwnPropertyDescriptor(Function.prototype.toString,"name"),Vu=(t,e,i)=>{let n=i===""?"":`with ${i.trim()}() `,r=Ou.bind(null,n,e.toString());Object.defineProperty(r,"name",Ku);let{writable:o,enumerable:a,configurable:c}=Uu;Object.defineProperty(t,"toString",{value:r,writable:o,enumerable:a,configurable:c})};function js(t,e,{ignoreNonConfigurable:i=!1}={}){let{name:n}=t;for(let r of Reflect.ownKeys(e))Wu(t,e,r,i);return Cu(t,e),Vu(t,e,n),t}var ar=new WeakMap,Il=(t,e={})=>{if(typeof t!="function")throw new TypeError("Expected a function");let i,n=0,r=t.displayName||t.name||"<anonymous>",o=function(...a){if(ar.set(o,++n),n===1)i=t.apply(this,a),t=void 0;else if(e.throw===!0)throw new Error(`Function \`${r}\` can only be called once`);return i};return js(o,t),ar.set(o,n),o};Il.callCount=t=>{if(!ar.has(t))throw new Error(`The given function \`${t.name}\` is not wrapped by the \`onetime\` package`);return ar.get(t)};var fl=Il;var bt=[];bt.push("SIGHUP","SIGINT","SIGTERM");process.platform!=="win32"&&bt.push("SIGALRM","SIGABRT","SIGVTALRM","SIGXCPU","SIGXFSZ","SIGUSR2","SIGTRAP","SIGSYS","SIGQUIT","SIGIOT");process.platform==="linux"&&bt.push("SIGIO","SIGPOLL","SIGPWR","SIGSTKFLT");var cr=t=>!!t&&typeof t=="object"&&typeof t.removeListener=="function"&&typeof t.emit=="function"&&typeof t.reallyExit=="function"&&typeof t.listeners=="function"&&typeof t.kill=="function"&&typeof t.pid=="number"&&typeof t.on=="function",xs=Symbol.for("signal-exit emitter"),Gs=globalThis,Nu=Object.defineProperty.bind(Object),Ss=class{emitted={afterExit:!1,exit:!1};listeners={afterExit:[],exit:[]};count=0;id=Math.random();constructor(){if(Gs[xs])return Gs[xs];Nu(Gs,xs,{value:this,writable:!1,enumerable:!1,configurable:!1})}on(e,i){this.listeners[e].push(i)}removeListener(e,i){let n=this.listeners[e],r=n.indexOf(i);r!==-1&&(r===0&&n.length===1?n.length=0:n.splice(r,1))}emit(e,i,n){if(this.emitted[e])return!1;this.emitted[e]=!0;let r=!1;for(let o of this.listeners[e])r=o(i,n)===!0||r;return e==="exit"&&(r=this.emit("afterExit",i,n)||r),r}},lr=class{},ku=t=>({onExit(e,i){return t.onExit(e,i)},load(){return t.load()},unload(){return t.unload()}}),Ys=class extends lr{onExit(){return()=>{}}load(){}unload(){}},Ws=class extends lr{#e=Ms.platform==="win32"?"SIGINT":"SIGHUP";#n=new Ss;#i;#r;#a;#t={};#o=!1;constructor(e){super(),this.#i=e,this.#t={};for(let i of bt)this.#t[i]=()=>{let n=this.#i.listeners(i),{count:r}=this.#n,o=e;if(typeof o.__signal_exit_emitter__=="object"&&typeof o.__signal_exit_emitter__.count=="number"&&(r+=o.__signal_exit_emitter__.count),n.length===r){this.unload();let a=this.#n.emit("exit",null,i),c=i==="SIGHUP"?this.#e:i;a||e.kill(e.pid,c)}};this.#a=e.reallyExit,this.#r=e.emit}onExit(e,i){if(!cr(this.#i))return()=>{};this.#o===!1&&this.load();let n=i?.alwaysLast?"afterExit":"exit";return this.#n.on(n,e),()=>{this.#n.removeListener(n,e),this.#n.listeners.exit.length===0&&this.#n.listeners.afterExit.length===0&&this.unload()}}load(){if(!this.#o){this.#o=!0,this.#n.count+=1;for(let e of bt)try{let i=this.#t[e];i&&this.#i.on(e,i)}catch{}this.#i.emit=(e,...i)=>this.#m(e,...i),this.#i.reallyExit=e=>this.#s(e)}}unload(){this.#o&&(this.#o=!1,bt.forEach(e=>{let i=this.#t[e];if(!i)throw new Error("Listener not defined for signal: "+e);try{this.#i.removeListener(e,i)}catch{}}),this.#i.emit=this.#r,this.#i.reallyExit=this.#a,this.#n.count-=1)}#s(e){return cr(this.#i)?(this.#i.exitCode=e||0,this.#n.emit("exit",this.#i.exitCode,null),this.#a.call(this.#i,this.#i.exitCode)):0}#m(e,...i){let n=this.#r;if(e==="exit"&&cr(this.#i)){typeof i[0]=="number"&&(this.#i.exitCode=i[0]);let r=n.call(this.#i,e,...i);return this.#n.emit("exit",this.#i.exitCode,null),r}else return n.call(this.#i,e,...i)}},Ms=globalThis.process,{onExit:hl,load:Wf,unload:Mf}=ku(cr(Ms)?new Ws(Ms):new Ys);var dl=vr.stderr.isTTY?vr.stderr:vr.stdout.isTTY?vr.stdout:void 0,Fu=dl?fl(()=>{hl(()=>{dl.write("\x1B[?25h")},{alwaysLast:!0})}):()=>{},Rl=Fu;var Ar=!1,fi={};fi.show=(t=zl.stderr)=>{t.isTTY&&(Ar=!1,t.write("\x1B[?25h"))};fi.hide=(t=zl.stderr)=>{t.isTTY&&(Rl(),Ar=!0,t.write("\x1B[?25l"))};fi.toggle=(t,e)=>{t!==void 0&&(Ar=t),Ar?fi.show(e):fi.hide(e)};var Cs=fi;var rn=tr(Os(),1);import ge from"node:process";function Us(){return ge.platform!=="win32"?ge.env.TERM!=="linux":!!ge.env.CI||!!ge.env.WT_SESSION||!!ge.env.TERMINUS_SUBLIME||ge.env.ConEmuTask==="{cmd::Cmder}"||ge.env.TERM_PROGRAM==="Terminus-Sublime"||ge.env.TERM_PROGRAM==="vscode"||ge.env.TERM==="xterm-256color"||ge.env.TERM==="alacritty"||ge.env.TERMINAL_EMULATOR==="JetBrains-JediTerm"}var bu={info:ze.blue("\u2139"),success:ze.green("\u2714"),warning:ze.yellow("\u26A0"),error:ze.red("\u2716")},Ju={info:ze.blue("i"),success:ze.green("\u221A"),warning:ze.yellow("\u203C"),error:ze.red("\xD7")},Bu=Us()?bu:Ju,tn=Bu;function Ks({onlyFirst:t=!1}={}){let r="(?:\\u001B\\][\\s\\S]*?(?:\\u0007|\\u001B\\u005C|\\u009C))|[\\u001B\\u009B][[\\]()#;?]*(?:\\d{1,4}(?:[;:]\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]";return new RegExp(r,t?void 0:"g")}var Zu=Ks();function nn(t){if(typeof t!="string")throw new TypeError(`Expected a \`string\`, got \`${typeof t}\``);return t.replace(Zu,"")}function Gl(t){return t===161||t===164||t===167||t===168||t===170||t===173||t===174||t>=176&&t<=180||t>=182&&t<=186||t>=188&&t<=191||t===198||t===208||t===215||t===216||t>=222&&t<=225||t===230||t>=232&&t<=234||t===236||t===237||t===240||t===242||t===243||t>=247&&t<=250||t===252||t===254||t===257||t===273||t===275||t===283||t===294||t===295||t===299||t>=305&&t<=307||t===312||t>=319&&t<=322||t===324||t>=328&&t<=331||t===333||t===338||t===339||t===358||t===359||t===363||t===462||t===464||t===466||t===468||t===470||t===472||t===474||t===476||t===593||t===609||t===708||t===711||t>=713&&t<=715||t===717||t===720||t>=728&&t<=731||t===733||t===735||t>=768&&t<=879||t>=913&&t<=929||t>=931&&t<=937||t>=945&&t<=961||t>=963&&t<=969||t===1025||t>=1040&&t<=1103||t===1105||t===8208||t>=8211&&t<=8214||t===8216||t===8217||t===8220||t===8221||t>=8224&&t<=8226||t>=8228&&t<=8231||t===8240||t===8242||t===8243||t===8245||t===8251||t===8254||t===8308||t===8319||t>=8321&&t<=8324||t===8364||t===8451||t===8453||t===8457||t===8467||t===8470||t===8481||t===8482||t===8486||t===8491||t===8531||t===8532||t>=8539&&t<=8542||t>=8544&&t<=8555||t>=8560&&t<=8569||t===8585||t>=8592&&t<=8601||t===8632||t===8633||t===8658||t===8660||t===8679||t===8704||t===8706||t===8707||t===8711||t===8712||t===8715||t===8719||t===8721||t===8725||t===8730||t>=8733&&t<=8736||t===8739||t===8741||t>=8743&&t<=8748||t===8750||t>=8756&&t<=8759||t===8764||t===8765||t===8776||t===8780||t===8786||t===8800||t===8801||t>=8804&&t<=8807||t===8810||t===8811||t===8814||t===8815||t===8834||t===8835||t===8838||t===8839||t===8853||t===8857||t===8869||t===8895||t===8978||t>=9312&&t<=9449||t>=9451&&t<=9547||t>=9552&&t<=9587||t>=9600&&t<=9615||t>=9618&&t<=9621||t===9632||t===9633||t>=9635&&t<=9641||t===9650||t===9651||t===9654||t===9655||t===9660||t===9661||t===9664||t===9665||t>=9670&&t<=9672||t===9675||t>=9678&&t<=9681||t>=9698&&t<=9701||t===9711||t===9733||t===9734||t===9737||t===9742||t===9743||t===9756||t===9758||t===9792||t===9794||t===9824||t===9825||t>=9827&&t<=9829||t>=9831&&t<=9834||t===9836||t===9837||t===9839||t===9886||t===9887||t===9919||t>=9926&&t<=9933||t>=9935&&t<=9939||t>=9941&&t<=9953||t===9955||t===9960||t===9961||t>=9963&&t<=9969||t===9972||t>=9974&&t<=9977||t===9979||t===9980||t===9982||t===9983||t===10045||t>=10102&&t<=10111||t>=11094&&t<=11097||t>=12872&&t<=12879||t>=57344&&t<=63743||t>=65024&&t<=65039||t===65533||t>=127232&&t<=127242||t>=127248&&t<=127277||t>=127280&&t<=127337||t>=127344&&t<=127373||t===127375||t===127376||t>=127387&&t<=127404||t>=917760&&t<=917999||t>=983040&&t<=1048573||t>=1048576&&t<=1114109}function Sl(t){return t===12288||t>=65281&&t<=65376||t>=65504&&t<=65510}function Yl(t){return t>=4352&&t<=4447||t===8986||t===8987||t===9001||t===9002||t>=9193&&t<=9196||t===9200||t===9203||t===9725||t===9726||t===9748||t===9749||t>=9776&&t<=9783||t>=9800&&t<=9811||t===9855||t>=9866&&t<=9871||t===9875||t===9889||t===9898||t===9899||t===9917||t===9918||t===9924||t===9925||t===9934||t===9940||t===9962||t===9970||t===9971||t===9973||t===9978||t===9981||t===9989||t===9994||t===9995||t===10024||t===10060||t===10062||t>=10067&&t<=10069||t===10071||t>=10133&&t<=10135||t===10160||t===10175||t===11035||t===11036||t===11088||t===11093||t>=11904&&t<=11929||t>=11931&&t<=12019||t>=12032&&t<=12245||t>=12272&&t<=12287||t>=12289&&t<=12350||t>=12353&&t<=12438||t>=12441&&t<=12543||t>=12549&&t<=12591||t>=12593&&t<=12686||t>=12688&&t<=12773||t>=12783&&t<=12830||t>=12832&&t<=12871||t>=12880&&t<=42124||t>=42128&&t<=42182||t>=43360&&t<=43388||t>=44032&&t<=55203||t>=63744&&t<=64255||t>=65040&&t<=65049||t>=65072&&t<=65106||t>=65108&&t<=65126||t>=65128&&t<=65131||t>=94176&&t<=94180||t>=94192&&t<=94198||t>=94208&&t<=101589||t>=101631&&t<=101662||t>=101760&&t<=101874||t>=110576&&t<=110579||t>=110581&&t<=110587||t===110589||t===110590||t>=110592&&t<=110882||t===110898||t>=110928&&t<=110930||t===110933||t>=110948&&t<=110951||t>=110960&&t<=111355||t>=119552&&t<=119638||t>=119648&&t<=119670||t===126980||t===127183||t===127374||t>=127377&&t<=127386||t>=127488&&t<=127490||t>=127504&&t<=127547||t>=127552&&t<=127560||t===127568||t===127569||t>=127584&&t<=127589||t>=127744&&t<=127776||t>=127789&&t<=127797||t>=127799&&t<=127868||t>=127870&&t<=127891||t>=127904&&t<=127946||t>=127951&&t<=127955||t>=127968&&t<=127984||t===127988||t>=127992&&t<=128062||t===128064||t>=128066&&t<=128252||t>=128255&&t<=128317||t>=128331&&t<=128334||t>=128336&&t<=128359||t===128378||t===128405||t===128406||t===128420||t>=128507&&t<=128591||t>=128640&&t<=128709||t===128716||t>=128720&&t<=128722||t>=128725&&t<=128728||t>=128732&&t<=128735||t===128747||t===128748||t>=128756&&t<=128764||t>=128992&&t<=129003||t===129008||t>=129292&&t<=129338||t>=129340&&t<=129349||t>=129351&&t<=129535||t>=129648&&t<=129660||t>=129664&&t<=129674||t>=129678&&t<=129734||t===129736||t>=129741&&t<=129756||t>=129759&&t<=129770||t>=129775&&t<=129784||t>=131072&&t<=196605||t>=196608&&t<=262141}function Pu(t){if(!Number.isSafeInteger(t))throw new TypeError(`Expected a code point, got \`${typeof t}\`.`)}function Wl(t,{ambiguousAsWide:e=!1}={}){return Pu(t),Sl(t)||Yl(t)||e&&Gl(t)?2:1}var Ol=tr(Cl(),1),qu=new Intl.Segmenter,yu=new RegExp("^\\p{Default_Ignorable_Code_Point}$","u");function Vs(t,e={}){if(typeof t!="string"||t.length===0)return 0;let{ambiguousIsNarrow:i=!0,countAnsiEscapeCodes:n=!1}=e;if(n||(t=nn(t)),t.length===0)return 0;let r=0,o={ambiguousAsWide:!i};for(let{segment:a}of qu.segment(t)){let c=a.codePointAt(0);if(!(c<=31||c>=127&&c<=159)&&!(c>=8203&&c<=8207||c===65279)&&!(c>=768&&c<=879||c>=6832&&c<=6911||c>=7616&&c<=7679||c>=8400&&c<=8447||c>=65056&&c<=65071)&&!(c>=55296&&c<=57343)&&!(c>=65024&&c<=65039)&&!yu.test(a)){if((0,Ol.default)().test(a)){r+=2;continue}r+=Wl(c,o)}}return r}function Ns({stream:t=process.stdout}={}){return!!(t&&t.isTTY&&process.env.TERM!=="dumb"&&!("CI"in process.env))}import Ul from"node:process";function ks(){let{env:t}=Ul,{TERM:e,TERM_PROGRAM:i}=t;return Ul.platform!=="win32"?e!=="linux":!!t.WT_SESSION||!!t.TERMINUS_SUBLIME||t.ConEmuTask==="{cmd::Cmder}"||i==="Terminus-Sublime"||i==="vscode"||e==="xterm-256color"||e==="alacritty"||e==="rxvt-unicode"||e==="rxvt-unicode-256color"||t.TERMINAL_EMULATOR==="JetBrains-JediTerm"}import Ue from"node:process";var Du=3,Fs=class{#e=0;start(){this.#e++,this.#e===1&&this.#n()}stop(){if(this.#e<=0)throw new Error("`stop` called more times than `start`");this.#e--,this.#e===0&&this.#i()}#n(){Ue.platform==="win32"||!Ue.stdin.isTTY||(Ue.stdin.setRawMode(!0),Ue.stdin.on("data",this.#r),Ue.stdin.resume())}#i(){Ue.stdin.isTTY&&(Ue.stdin.off("data",this.#r),Ue.stdin.pause(),Ue.stdin.setRawMode(!1))}#r(e){e[0]===Du&&Ue.emit("SIGINT")}},wu=new Fs,Qs=wu;var Tu=tr(Os(),1),bs=class{#e=0;#n=!1;#i=0;#r=-1;#a=0;#t;#o;#s;#m;#p;#v;#A;#u;#I;#c;#l;color;constructor(e){typeof e=="string"&&(e={text:e}),this.#t={color:"cyan",stream:mr.stderr,discardStdin:!0,hideCursor:!0,...e},this.color=this.#t.color,this.spinner=this.#t.spinner,this.#p=this.#t.interval,this.#s=this.#t.stream,this.#v=typeof this.#t.isEnabled=="boolean"?this.#t.isEnabled:Ns({stream:this.#s}),this.#A=typeof this.#t.isSilent=="boolean"?this.#t.isSilent:!1,this.text=this.#t.text,this.prefixText=this.#t.prefixText,this.suffixText=this.#t.suffixText,this.indent=this.#t.indent,mr.env.NODE_ENV==="test"&&(this._stream=this.#s,this._isEnabled=this.#v,Object.defineProperty(this,"_linesToClear",{get(){return this.#e},set(i){this.#e=i}}),Object.defineProperty(this,"_frameIndex",{get(){return this.#r}}),Object.defineProperty(this,"_lineCount",{get(){return this.#i}}))}get indent(){return this.#u}set indent(e=0){if(!(e>=0&&Number.isInteger(e)))throw new Error("The `indent` option must be an integer from 0 and up");this.#u=e,this.#E()}get interval(){return this.#p??this.#o.interval??100}get spinner(){return this.#o}set spinner(e){if(this.#r=-1,this.#p=void 0,typeof e=="object"){if(e.frames===void 0)throw new Error("The given spinner must have a `frames` property");this.#o=e}else if(!ks())this.#o=rn.default.line;else if(e===void 0)this.#o=rn.default.dots;else if(e!=="default"&&rn.default[e])this.#o=rn.default[e];else throw new Error(`There is no built-in spinner named '${e}'. See https://github.com/sindresorhus/cli-spinners/blob/main/spinners.json for a full list.`)}get text(){return this.#I}set text(e=""){this.#I=e,this.#E()}get prefixText(){return this.#c}set prefixText(e=""){this.#c=e,this.#E()}get suffixText(){return this.#l}set suffixText(e=""){this.#l=e,this.#E()}get isSpinning(){return this.#m!==void 0}#f(e=this.#c,i=" "){return typeof e=="string"&&e!==""?e+i:typeof e=="function"?e()+i:""}#h(e=this.#l,i=" "){return typeof e=="string"&&e!==""?i+e:typeof e=="function"?i+e():""}#E(){let e=this.#s.columns??80,i=this.#f(this.#c,"-"),n=this.#h(this.#l,"-"),r=" ".repeat(this.#u)+i+"--"+this.#I+"--"+n;this.#i=0;for(let o of nn(r).split(`
15
- `))this.#i+=Math.max(1,Math.ceil(Vs(o,{countAnsiEscapeCodes:!0})/e))}get isEnabled(){return this.#v&&!this.#A}set isEnabled(e){if(typeof e!="boolean")throw new TypeError("The `isEnabled` option must be a boolean");this.#v=e}get isSilent(){return this.#A}set isSilent(e){if(typeof e!="boolean")throw new TypeError("The `isSilent` option must be a boolean");this.#A=e}frame(){let e=Date.now();(this.#r===-1||e-this.#a>=this.interval)&&(this.#r=++this.#r%this.#o.frames.length,this.#a=e);let{frames:i}=this.#o,n=i[this.#r];this.color&&(n=ze[this.color](n));let r=typeof this.#c=="string"&&this.#c!==""?this.#c+" ":"",o=typeof this.text=="string"?" "+this.text:"",a=typeof this.#l=="string"&&this.#l!==""?" "+this.#l:"";return r+n+o+a}clear(){if(!this.#v||!this.#s.isTTY)return this;this.#s.cursorTo(0);for(let e=0;e<this.#e;e++)e>0&&this.#s.moveCursor(0,-1),this.#s.clearLine(1);return(this.#u||this.lastIndent!==this.#u)&&this.#s.cursorTo(this.#u),this.lastIndent=this.#u,this.#e=0,this}render(){return this.#A?this:(this.clear(),this.#s.write(this.frame()),this.#e=this.#i,this)}start(e){return e&&(this.text=e),this.#A?this:this.#v?this.isSpinning?this:(this.#t.hideCursor&&Cs.hide(this.#s),this.#t.discardStdin&&mr.stdin.isTTY&&(this.#n=!0,Qs.start()),this.render(),this.#m=setInterval(this.render.bind(this),this.interval),this):(this.text&&this.#s.write(`- ${this.text}
16
- `),this)}stop(){return this.#v?(clearInterval(this.#m),this.#m=void 0,this.#r=0,this.clear(),this.#t.hideCursor&&Cs.show(this.#s),this.#t.discardStdin&&mr.stdin.isTTY&&this.#n&&(Qs.stop(),this.#n=!1),this):this}succeed(e){return this.stopAndPersist({symbol:tn.success,text:e})}fail(e){return this.stopAndPersist({symbol:tn.error,text:e})}warn(e){return this.stopAndPersist({symbol:tn.warning,text:e})}info(e){return this.stopAndPersist({symbol:tn.info,text:e})}stopAndPersist(e={}){if(this.#A)return this;let i=e.prefixText??this.#c,n=this.#f(i," "),r=e.symbol??" ",o=e.text??this.text,c=typeof o=="string"?(r?" ":"")+o:"",l=e.suffixText??this.#l,v=this.#h(l," "),A=n+r+c+v+`
17
- `;return this.stop(),this.#s.write(A),this}};function Ke(t){return new bs(t)}import{existsSync as kl,readFileSync as e7,writeFileSync as t7,mkdirSync as i7}from"fs";import{dirname as n7}from"path";import{homedir as Kl}from"os";import{join as D}from"path";var Xu=D(Kl(),".gemkit"),Js=D(Xu,"projects"),Bs=D(Kl(),".gemini"),dh=D(Bs,"config"),hi=D(Bs,"cache"),Rh=D(Bs,"tmp"),di=".gemini";var Hu="plans",Lu=".gk.json",_u="metadata.json",$u=".env";function Er(t=process.cwd()){return D(t,di)}function Zs(t=process.cwd()){return D(t,di,Lu)}function Ps(t=process.cwd()){return D(t,di,_u)}function Jt(t=process.cwd()){return D(t,di,$u)}function on(t=process.cwd()){return D(t,di,"agents")}function Bt(t=process.cwd()){return D(t,di,"extensions")}function Ri(t=process.cwd()){return D(t,Hu)}function sn(t){return t?t.replace(/^[A-Za-z]:/,e=>e.replace(":","")).replace(/[\\/]+/g,"-").replace(/[^a-zA-Z0-9-]/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,""):""}function we(t){return D(Js,t)}function Zt(t,e){return D(we(t),`gk-session-${e}.json`)}function an(t,e){return D(we(t),`gk-project-${e}.json`)}var me={defaultScope:"local",github:{repo:"therichardngai-code/gemkit-kits-starter",apiUrl:"https://api.github.com"},cache:{enabled:!0,ttl:3600},installation:{excludePatterns:[],backupOnUpdate:!0},ui:{colors:!0,spinner:!0,verbose:!1},paths:{},spawn:{defaultModel:"gemini-2.5-flash",music:!1},office:{enabled:!0,mode:"web",port:3847,autoOpen:!0,sounds:!1,refreshRate:500},update:{autoCheck:!0,checkInterval:24,notifyOnly:!0}};function Vl(t){return!(!t||typeof t!="object")}function Nl(t){return{...me,...t,github:{...me.github,...t.github||{}},cache:{...me.cache,...t.cache||{}},installation:{...me.installation,...t.installation||{}},ui:{...me.ui,...t.ui||{}},paths:{...me.paths,...t.paths||{}},spawn:{...me.spawn,...t.spawn||{}},office:{...me.office,...t.office||{}},update:{...me.update,...t.update||{}}}}var pr=class extends Error{constructor(i,n="GEMKIT_ERROR",r){super(i);this.code=n;this.details=r;this.name="GemKitError"}},Pt=class extends pr{constructor(e,i){super(e,"CONFIG_ERROR",i),this.name="ConfigError"}};var Ee=class extends pr{constructor(e,i){super(e,"GITHUB_ERROR",i),this.name="GitHubError"}};function Ve(t){let e=Zs(t);if(!kl(e))return me;try{let i=e7(e,"utf-8"),n=JSON.parse(i);if(!Vl(n))throw new Pt("Invalid configuration format");return Nl(n)}catch(i){throw i instanceof Pt?i:new Pt(`Failed to load config: ${i}`)}}function Fl(t,e){let i=Zs(e),n=n7(i);kl(n)||i7(n,{recursive:!0}),t7(i,JSON.stringify(t,null,2))}function Ql(t,e){let i=Ve(e),n=t.split("."),r=i;for(let o of n)if(r&&typeof r=="object"&&o in r)r=r[o];else return;return r}function bl(t,e,i){let n=Ve(i),r=t.split("."),o=r.pop();if(!o)throw new Pt("Invalid config path");let a=n;for(let c of r)(!(c in a)||typeof a[c]!="object")&&(a[c]={}),a=a[c];a[o]=e,Fl(n,i)}function Jl(t){Fl(me,t)}import{existsSync as Bl,readFileSync as r7,writeFileSync as o7,mkdirSync as s7,readdirSync as Zl,unlinkSync as Pl,statSync as a7}from"fs";import{join as qs}from"path";function ys(){return Bl(hi)||s7(hi,{recursive:!0}),hi}function ql(t){let e=t.replace(/[^a-zA-Z0-9-_]/g,"_");return qs(ys(),`${e}.json`)}function Ir(t){let e=ql(t);if(!Bl(e))return null;try{let i=r7(e,"utf-8"),n=JSON.parse(i);return Date.now()-n.timestamp>n.ttl*1e3?(Pl(e),null):n.data}catch{return null}}function fr(t,e,i=3600){let n=ql(t),r={key:t,data:e,timestamp:Date.now(),ttl:i};o7(n,JSON.stringify(r,null,2))}function yl(){let t=ys(),e=Zl(t).filter(i=>i.endsWith(".json"));for(let i of e)Pl(qs(t,i));return e.length}function Dl(){let t=ys(),e=Zl(t).filter(n=>n.endsWith(".json")),i=0;for(let n of e){let r=a7(qs(t,n));i+=r.size}return{entries:e.length,size:i}}var wl="github-releases",c7=300;async function hr(t=10){let e=Ir(wl);if(e)return e.slice(0,t);let i=Ve(),{repo:n,apiUrl:r}=i.github,o=`${r}/repos/${n}/releases?per_page=${t}`;try{let a=await fetch(o,{headers:{Accept:"application/vnd.github.v3+json","User-Agent":"gemkit-cli"}});if(!a.ok)throw new Ee(`Failed to fetch releases: ${a.status}`);let l=(await a.json()).map(v=>({version:v.tag_name.replace(/^v/,""),tag:v.tag_name,publishedAt:v.published_at,prerelease:v.prerelease,assets:v.assets.map(A=>({name:A.name,url:A.url,size:A.size,downloadUrl:A.browser_download_url}))}));return fr(wl,l,c7),l}catch(a){throw a instanceof Ee?a:new Ee(`Failed to fetch releases: ${a}`)}}async function qt(){let t=await hr(1);return t.length>0?t[0]:null}async function Tl(t){return(await hr(50)).find(i=>i.version===t||i.tag===t)||null}import{createWriteStream as l7,existsSync as v7,mkdirSync as A7}from"fs";import{pipeline as u7}from"stream/promises";import{join as m7}from"path";async function E7(t,e=hi){v7(e)||A7(e,{recursive:!0});let i=m7(e,t.name);try{let n=await fetch(t.downloadUrl,{headers:{"User-Agent":"gemkit-cli"}});if(!n.ok)throw new Ee(`Failed to download asset: ${n.status}`);if(!n.body)throw new Ee("No response body");let r=l7(i);return await u7(n.body,r),i}catch(n){throw n instanceof Ee?n:new Ee(`Download failed: ${n}`)}}async function zi(t){let e=t.assets.find(i=>i.name.endsWith(".tar.gz")||i.name.endsWith(".tgz"));if(!e)throw new Ee("No tarball asset found in release");return E7(e)}import{createReadStream as dE,createWriteStream as Mz,existsSync as Av,mkdirSync as RE}from"fs";import{pipeline as zE}from"stream/promises";import{createGunzip as gE}from"zlib";import G7 from"events";import ee from"fs";import{EventEmitter as _s}from"node:events";import $l from"node:stream";import{StringDecoder as p7}from"node:string_decoder";var Xl=typeof process=="object"&&process?process:{stdout:null,stderr:null},I7=t=>!!t&&typeof t=="object"&&(t instanceof un||t instanceof $l||f7(t)||h7(t)),f7=t=>!!t&&typeof t=="object"&&t instanceof _s&&typeof t.pipe=="function"&&t.pipe!==$l.Writable.prototype.pipe,h7=t=>!!t&&typeof t=="object"&&t instanceof _s&&typeof t.write=="function"&&typeof t.end=="function",Te=Symbol("EOF"),Xe=Symbol("maybeEmitEnd"),Et=Symbol("emittedEnd"),dr=Symbol("emittingEnd"),cn=Symbol("emittedError"),Rr=Symbol("closed"),Hl=Symbol("read"),zr=Symbol("flush"),Ll=Symbol("flushChunk"),je=Symbol("encoding"),gi=Symbol("decoder"),F=Symbol("flowing"),ln=Symbol("paused"),ji=Symbol("resume"),Q=Symbol("buffer"),L=Symbol("pipes"),b=Symbol("bufferLength"),Ds=Symbol("bufferPush"),gr=Symbol("bufferShift"),w=Symbol("objectMode"),O=Symbol("destroyed"),ws=Symbol("error"),Ts=Symbol("emitData"),_l=Symbol("emitEnd"),Xs=Symbol("emitEnd2"),Ne=Symbol("async"),Hs=Symbol("abort"),jr=Symbol("aborted"),vn=Symbol("signal"),yt=Symbol("dataListeners"),te=Symbol("discarded"),An=t=>Promise.resolve().then(t),d7=t=>t(),R7=t=>t==="end"||t==="finish"||t==="prefinish",z7=t=>t instanceof ArrayBuffer||!!t&&typeof t=="object"&&t.constructor&&t.constructor.name==="ArrayBuffer"&&t.byteLength>=0,g7=t=>!Buffer.isBuffer(t)&&ArrayBuffer.isView(t),xr=class{src;dest;opts;ondrain;constructor(e,i,n){this.src=e,this.dest=i,this.opts=n,this.ondrain=()=>e[ji](),this.dest.on("drain",this.ondrain)}unpipe(){this.dest.removeListener("drain",this.ondrain)}proxyErrors(e){}end(){this.unpipe(),this.opts.end&&this.dest.end()}},Ls=class extends xr{unpipe(){this.src.removeListener("error",this.proxyErrors),super.unpipe()}constructor(e,i,n){super(e,i,n),this.proxyErrors=r=>i.emit("error",r),e.on("error",this.proxyErrors)}},j7=t=>!!t.objectMode,x7=t=>!t.objectMode&&!!t.encoding&&t.encoding!=="buffer",un=class extends _s{[F]=!1;[ln]=!1;[L]=[];[Q]=[];[w];[je];[Ne];[gi];[Te]=!1;[Et]=!1;[dr]=!1;[Rr]=!1;[cn]=null;[b]=0;[O]=!1;[vn];[jr]=!1;[yt]=0;[te]=!1;writable=!0;readable=!0;constructor(...e){let i=e[0]||{};if(super(),i.objectMode&&typeof i.encoding=="string")throw new TypeError("Encoding and objectMode may not be used together");j7(i)?(this[w]=!0,this[je]=null):x7(i)?(this[je]=i.encoding,this[w]=!1):(this[w]=!1,this[je]=null),this[Ne]=!!i.async,this[gi]=this[je]?new p7(this[je]):null,i&&i.debugExposeBuffer===!0&&Object.defineProperty(this,"buffer",{get:()=>this[Q]}),i&&i.debugExposePipes===!0&&Object.defineProperty(this,"pipes",{get:()=>this[L]});let{signal:n}=i;n&&(this[vn]=n,n.aborted?this[Hs]():n.addEventListener("abort",()=>this[Hs]()))}get bufferLength(){return this[b]}get encoding(){return this[je]}set encoding(e){throw new Error("Encoding must be set at instantiation time")}setEncoding(e){throw new Error("Encoding must be set at instantiation time")}get objectMode(){return this[w]}set objectMode(e){throw new Error("objectMode must be set at instantiation time")}get async(){return this[Ne]}set async(e){this[Ne]=this[Ne]||!!e}[Hs](){this[jr]=!0,this.emit("abort",this[vn]?.reason),this.destroy(this[vn]?.reason)}get aborted(){return this[jr]}set aborted(e){}write(e,i,n){if(this[jr])return!1;if(this[Te])throw new Error("write after end");if(this[O])return this.emit("error",Object.assign(new Error("Cannot call write after a stream was destroyed"),{code:"ERR_STREAM_DESTROYED"})),!0;typeof i=="function"&&(n=i,i="utf8"),i||(i="utf8");let r=this[Ne]?An:d7;if(!this[w]&&!Buffer.isBuffer(e)){if(g7(e))e=Buffer.from(e.buffer,e.byteOffset,e.byteLength);else if(z7(e))e=Buffer.from(e);else if(typeof e!="string")throw new Error("Non-contiguous data written to non-objectMode stream")}return this[w]?(this[F]&&this[b]!==0&&this[zr](!0),this[F]?this.emit("data",e):this[Ds](e),this[b]!==0&&this.emit("readable"),n&&r(n),this[F]):e.length?(typeof e=="string"&&!(i===this[je]&&!this[gi]?.lastNeed)&&(e=Buffer.from(e,i)),Buffer.isBuffer(e)&&this[je]&&(e=this[gi].write(e)),this[F]&&this[b]!==0&&this[zr](!0),this[F]?this.emit("data",e):this[Ds](e),this[b]!==0&&this.emit("readable"),n&&r(n),this[F]):(this[b]!==0&&this.emit("readable"),n&&r(n),this[F])}read(e){if(this[O])return null;if(this[te]=!1,this[b]===0||e===0||e&&e>this[b])return this[Xe](),null;this[w]&&(e=null),this[Q].length>1&&!this[w]&&(this[Q]=[this[je]?this[Q].join(""):Buffer.concat(this[Q],this[b])]);let i=this[Hl](e||null,this[Q][0]);return this[Xe](),i}[Hl](e,i){if(this[w])this[gr]();else{let n=i;e===n.length||e===null?this[gr]():typeof n=="string"?(this[Q][0]=n.slice(e),i=n.slice(0,e),this[b]-=e):(this[Q][0]=n.subarray(e),i=n.subarray(0,e),this[b]-=e)}return this.emit("data",i),!this[Q].length&&!this[Te]&&this.emit("drain"),i}end(e,i,n){return typeof e=="function"&&(n=e,e=void 0),typeof i=="function"&&(n=i,i="utf8"),e!==void 0&&this.write(e,i),n&&this.once("end",n),this[Te]=!0,this.writable=!1,(this[F]||!this[ln])&&this[Xe](),this}[ji](){this[O]||(!this[yt]&&!this[L].length&&(this[te]=!0),this[ln]=!1,this[F]=!0,this.emit("resume"),this[Q].length?this[zr]():this[Te]?this[Xe]():this.emit("drain"))}resume(){return this[ji]()}pause(){this[F]=!1,this[ln]=!0,this[te]=!1}get destroyed(){return this[O]}get flowing(){return this[F]}get paused(){return this[ln]}[Ds](e){this[w]?this[b]+=1:this[b]+=e.length,this[Q].push(e)}[gr](){return this[w]?this[b]-=1:this[b]-=this[Q][0].length,this[Q].shift()}[zr](e=!1){do;while(this[Ll](this[gr]())&&this[Q].length);!e&&!this[Q].length&&!this[Te]&&this.emit("drain")}[Ll](e){return this.emit("data",e),this[F]}pipe(e,i){if(this[O])return e;this[te]=!1;let n=this[Et];return i=i||{},e===Xl.stdout||e===Xl.stderr?i.end=!1:i.end=i.end!==!1,i.proxyErrors=!!i.proxyErrors,n?i.end&&e.end():(this[L].push(i.proxyErrors?new Ls(this,e,i):new xr(this,e,i)),this[Ne]?An(()=>this[ji]()):this[ji]()),e}unpipe(e){let i=this[L].find(n=>n.dest===e);i&&(this[L].length===1?(this[F]&&this[yt]===0&&(this[F]=!1),this[L]=[]):this[L].splice(this[L].indexOf(i),1),i.unpipe())}addListener(e,i){return this.on(e,i)}on(e,i){let n=super.on(e,i);if(e==="data")this[te]=!1,this[yt]++,!this[L].length&&!this[F]&&this[ji]();else if(e==="readable"&&this[b]!==0)super.emit("readable");else if(R7(e)&&this[Et])super.emit(e),this.removeAllListeners(e);else if(e==="error"&&this[cn]){let r=i;this[Ne]?An(()=>r.call(this,this[cn])):r.call(this,this[cn])}return n}removeListener(e,i){return this.off(e,i)}off(e,i){let n=super.off(e,i);return e==="data"&&(this[yt]=this.listeners("data").length,this[yt]===0&&!this[te]&&!this[L].length&&(this[F]=!1)),n}removeAllListeners(e){let i=super.removeAllListeners(e);return(e==="data"||e===void 0)&&(this[yt]=0,!this[te]&&!this[L].length&&(this[F]=!1)),i}get emittedEnd(){return this[Et]}[Xe](){!this[dr]&&!this[Et]&&!this[O]&&this[Q].length===0&&this[Te]&&(this[dr]=!0,this.emit("end"),this.emit("prefinish"),this.emit("finish"),this[Rr]&&this.emit("close"),this[dr]=!1)}emit(e,...i){let n=i[0];if(e!=="error"&&e!=="close"&&e!==O&&this[O])return!1;if(e==="data")return!this[w]&&!n?!1:this[Ne]?(An(()=>this[Ts](n)),!0):this[Ts](n);if(e==="end")return this[_l]();if(e==="close"){if(this[Rr]=!0,!this[Et]&&!this[O])return!1;let o=super.emit("close");return this.removeAllListeners("close"),o}else if(e==="error"){this[cn]=n,super.emit(ws,n);let o=!this[vn]||this.listeners("error").length?super.emit("error",n):!1;return this[Xe](),o}else if(e==="resume"){let o=super.emit("resume");return this[Xe](),o}else if(e==="finish"||e==="prefinish"){let o=super.emit(e);return this.removeAllListeners(e),o}let r=super.emit(e,...i);return this[Xe](),r}[Ts](e){for(let n of this[L])n.dest.write(e)===!1&&this.pause();let i=this[te]?!1:super.emit("data",e);return this[Xe](),i}[_l](){return this[Et]?!1:(this[Et]=!0,this.readable=!1,this[Ne]?(An(()=>this[Xs]()),!0):this[Xs]())}[Xs](){if(this[gi]){let i=this[gi].end();if(i){for(let n of this[L])n.dest.write(i);this[te]||super.emit("data",i)}}for(let i of this[L])i.end();let e=super.emit("end");return this.removeAllListeners("end"),e}async collect(){let e=Object.assign([],{dataLength:0});this[w]||(e.dataLength=0);let i=this.promise();return this.on("data",n=>{e.push(n),this[w]||(e.dataLength+=n.length)}),await i,e}async concat(){if(this[w])throw new Error("cannot concat in objectMode");let e=await this.collect();return this[je]?e.join(""):Buffer.concat(e,e.dataLength)}async promise(){return new Promise((e,i)=>{this.on(O,()=>i(new Error("stream destroyed"))),this.on("error",n=>i(n)),this.on("end",()=>e())})}[Symbol.asyncIterator](){this[te]=!1;let e=!1,i=async()=>(this.pause(),e=!0,{value:void 0,done:!0});return{next:()=>{if(e)return i();let r=this.read();if(r!==null)return Promise.resolve({done:!1,value:r});if(this[Te])return i();let o,a,c=u=>{this.off("data",l),this.off("end",v),this.off(O,A),i(),a(u)},l=u=>{this.off("error",c),this.off("end",v),this.off(O,A),this.pause(),o({value:u,done:!!this[Te]})},v=()=>{this.off("error",c),this.off("data",l),this.off(O,A),i(),o({done:!0,value:void 0})},A=()=>c(new Error("stream destroyed"));return new Promise((u,p)=>{a=p,o=u,this.once(O,A),this.once("error",c),this.once("end",v),this.once("data",l)})},throw:i,return:i,[Symbol.asyncIterator](){return this}}}[Symbol.iterator](){this[te]=!1;let e=!1,i=()=>(this.pause(),this.off(ws,i),this.off(O,i),this.off("end",i),e=!0,{done:!0,value:void 0}),n=()=>{if(e)return i();let r=this.read();return r===null?i():{done:!1,value:r}};return this.once("end",i),this.once(ws,i),this.once(O,i),{next:n,throw:i,return:i,[Symbol.iterator](){return this}}}destroy(e){if(this[O])return e?this.emit("error",e):this.emit(O),this;this[O]=!0,this[te]=!0,this[Q].length=0,this[b]=0;let i=this;return typeof i.close=="function"&&!this[Rr]&&i.close(),e?this.emit("error",e):this.emit(O),this}static get isStream(){return I7}};var S7=ee.writev,It=Symbol("_autoClose"),Ge=Symbol("_close"),mn=Symbol("_ended"),j=Symbol("_fd"),$s=Symbol("_finished"),Le=Symbol("_flags"),ea=Symbol("_flush"),ra=Symbol("_handleChunk"),oa=Symbol("_makeBuf"),pn=Symbol("_mode"),Gr=Symbol("_needDrain"),Si=Symbol("_onerror"),Yi=Symbol("_onopen"),ta=Symbol("_onread"),xi=Symbol("_onwrite"),ft=Symbol("_open"),xe=Symbol("_path"),pt=Symbol("_pos"),ke=Symbol("_queue"),Gi=Symbol("_read"),ia=Symbol("_readSize"),He=Symbol("_reading"),En=Symbol("_remain"),na=Symbol("_size"),Sr=Symbol("_write"),Dt=Symbol("_writing"),Yr=Symbol("_defaultFlag"),wt=Symbol("_errored"),Tt=class extends un{[wt]=!1;[j];[xe];[ia];[He]=!1;[na];[En];[It];constructor(e,i){if(i=i||{},super(i),this.readable=!0,this.writable=!1,typeof e!="string")throw new TypeError("path must be a string");this[wt]=!1,this[j]=typeof i.fd=="number"?i.fd:void 0,this[xe]=e,this[ia]=i.readSize||16*1024*1024,this[He]=!1,this[na]=typeof i.size=="number"?i.size:1/0,this[En]=this[na],this[It]=typeof i.autoClose=="boolean"?i.autoClose:!0,typeof this[j]=="number"?this[Gi]():this[ft]()}get fd(){return this[j]}get path(){return this[xe]}write(){throw new TypeError("this is a readable stream")}end(){throw new TypeError("this is a readable stream")}[ft](){ee.open(this[xe],"r",(e,i)=>this[Yi](e,i))}[Yi](e,i){e?this[Si](e):(this[j]=i,this.emit("open",i),this[Gi]())}[oa](){return Buffer.allocUnsafe(Math.min(this[ia],this[En]))}[Gi](){if(!this[He]){this[He]=!0;let e=this[oa]();if(e.length===0)return process.nextTick(()=>this[ta](null,0,e));ee.read(this[j],e,0,e.length,null,(i,n,r)=>this[ta](i,n,r))}}[ta](e,i,n){this[He]=!1,e?this[Si](e):this[ra](i,n)&&this[Gi]()}[Ge](){if(this[It]&&typeof this[j]=="number"){let e=this[j];this[j]=void 0,ee.close(e,i=>i?this.emit("error",i):this.emit("close"))}}[Si](e){this[He]=!0,this[Ge](),this.emit("error",e)}[ra](e,i){let n=!1;return this[En]-=e,e>0&&(n=super.write(e<i.length?i.subarray(0,e):i)),(e===0||this[En]<=0)&&(n=!1,this[Ge](),super.end()),n}emit(e,...i){switch(e){case"prefinish":case"finish":return!1;case"drain":return typeof this[j]=="number"&&this[Gi](),!1;case"error":return this[wt]?!1:(this[wt]=!0,super.emit(e,...i));default:return super.emit(e,...i)}}},Wr=class extends Tt{[ft](){let e=!0;try{this[Yi](null,ee.openSync(this[xe],"r")),e=!1}finally{e&&this[Ge]()}}[Gi](){let e=!0;try{if(!this[He]){this[He]=!0;do{let i=this[oa](),n=i.length===0?0:ee.readSync(this[j],i,0,i.length,null);if(!this[ra](n,i))break}while(!0);this[He]=!1}e=!1}finally{e&&this[Ge]()}}[Ge](){if(this[It]&&typeof this[j]=="number"){let e=this[j];this[j]=void 0,ee.closeSync(e),this.emit("close")}}},_e=class extends G7{readable=!1;writable=!0;[wt]=!1;[Dt]=!1;[mn]=!1;[ke]=[];[Gr]=!1;[xe];[pn];[It];[j];[Yr];[Le];[$s]=!1;[pt];constructor(e,i){i=i||{},super(i),this[xe]=e,this[j]=typeof i.fd=="number"?i.fd:void 0,this[pn]=i.mode===void 0?438:i.mode,this[pt]=typeof i.start=="number"?i.start:void 0,this[It]=typeof i.autoClose=="boolean"?i.autoClose:!0;let n=this[pt]!==void 0?"r+":"w";this[Yr]=i.flags===void 0,this[Le]=i.flags===void 0?n:i.flags,this[j]===void 0&&this[ft]()}emit(e,...i){if(e==="error"){if(this[wt])return!1;this[wt]=!0}return super.emit(e,...i)}get fd(){return this[j]}get path(){return this[xe]}[Si](e){this[Ge](),this[Dt]=!0,this.emit("error",e)}[ft](){ee.open(this[xe],this[Le],this[pn],(e,i)=>this[Yi](e,i))}[Yi](e,i){this[Yr]&&this[Le]==="r+"&&e&&e.code==="ENOENT"?(this[Le]="w",this[ft]()):e?this[Si](e):(this[j]=i,this.emit("open",i),this[Dt]||this[ea]())}end(e,i){return e&&this.write(e,i),this[mn]=!0,!this[Dt]&&!this[ke].length&&typeof this[j]=="number"&&this[xi](null,0),this}write(e,i){return typeof e=="string"&&(e=Buffer.from(e,i)),this[mn]?(this.emit("error",new Error("write() after end()")),!1):this[j]===void 0||this[Dt]||this[ke].length?(this[ke].push(e),this[Gr]=!0,!1):(this[Dt]=!0,this[Sr](e),!0)}[Sr](e){ee.write(this[j],e,0,e.length,this[pt],(i,n)=>this[xi](i,n))}[xi](e,i){e?this[Si](e):(this[pt]!==void 0&&typeof i=="number"&&(this[pt]+=i),this[ke].length?this[ea]():(this[Dt]=!1,this[mn]&&!this[$s]?(this[$s]=!0,this[Ge](),this.emit("finish")):this[Gr]&&(this[Gr]=!1,this.emit("drain"))))}[ea](){if(this[ke].length===0)this[mn]&&this[xi](null,0);else if(this[ke].length===1)this[Sr](this[ke].pop());else{let e=this[ke];this[ke]=[],S7(this[j],e,this[pt],(i,n)=>this[xi](i,n))}}[Ge](){if(this[It]&&typeof this[j]=="number"){let e=this[j];this[j]=void 0,ee.close(e,i=>i?this.emit("error",i):this.emit("close"))}}},Wi=class extends _e{[ft](){let e;if(this[Yr]&&this[Le]==="r+")try{e=ee.openSync(this[xe],this[Le],this[pn])}catch(i){if(i?.code==="ENOENT")return this[Le]="w",this[ft]();throw i}else e=ee.openSync(this[xe],this[Le],this[pn]);this[Yi](null,e)}[Ge](){if(this[It]&&typeof this[j]=="number"){let e=this[j];this[j]=void 0,ee.closeSync(e),this.emit("close")}}[Sr](e){let i=!0;try{this[xi](null,ee.writeSync(this[j],e,0,e.length,this[pt])),i=!1}finally{if(i)try{this[Ge]()}catch{}}}};import P3 from"node:path";import Fi from"node:fs";import{dirname as jm,parse as xm}from"path";var Y7=new Map([["C","cwd"],["f","file"],["z","gzip"],["P","preservePaths"],["U","unlink"],["strip-components","strip"],["stripComponents","strip"],["keep-newer","newer"],["keepNewer","newer"],["keep-newer-files","newer"],["keepNewerFiles","newer"],["k","keep"],["keep-existing","keep"],["keepExisting","keep"],["m","noMtime"],["no-mtime","noMtime"],["p","preserveOwner"],["L","follow"],["h","follow"],["onentry","onReadEntry"]]),e3=t=>!!t.sync&&!!t.file,t3=t=>!t.sync&&!!t.file,i3=t=>!!t.sync&&!t.file,n3=t=>!t.sync&&!t.file;var r3=t=>!!t.file;var W7=t=>{let e=Y7.get(t);return e||t},In=(t={})=>{if(!t)return{};let e={};for(let[i,n]of Object.entries(t)){let r=W7(i);e[r]=n}return e.chmod===void 0&&e.noChmod===!1&&(e.chmod=!0),delete e.noChmod,e};var Fe=(t,e,i,n,r)=>Object.assign((o=[],a,c)=>{Array.isArray(o)&&(a=o,o={}),typeof a=="function"&&(c=a,a=void 0),a?a=Array.from(a):a=[];let l=In(o);if(r?.(l,a),e3(l)){if(typeof c=="function")throw new TypeError("callback not supported for sync tar functions");return t(l,a)}else if(t3(l)){let v=e(l,a),A=c||void 0;return A?v.then(()=>A(),A):v}else if(i3(l)){if(typeof c=="function")throw new TypeError("callback not supported for sync tar functions");return i(l,a)}else if(n3(l)){if(typeof c=="function")throw new TypeError("callback only supported with file option");return n(l,a)}else throw new Error("impossible options??")},{syncFile:t,asyncFile:e,syncNoFile:i,asyncNoFile:n,validate:r});import{EventEmitter as dm}from"events";import Ia from"assert";import{Buffer as Ht}from"buffer";import{EventEmitter as ma}from"node:events";import l3 from"node:stream";import{StringDecoder as M7}from"node:string_decoder";var o3=typeof process=="object"&&process?process:{stdout:null,stderr:null},C7=t=>!!t&&typeof t=="object"&&(t instanceof zn||t instanceof l3||O7(t)||U7(t)),O7=t=>!!t&&typeof t=="object"&&t instanceof ma&&typeof t.pipe=="function"&&t.pipe!==l3.Writable.prototype.pipe,U7=t=>!!t&&typeof t=="object"&&t instanceof ma&&typeof t.write=="function"&&typeof t.end=="function",$e=Symbol("EOF"),et=Symbol("maybeEmitEnd"),ht=Symbol("emittedEnd"),Mr=Symbol("emittingEnd"),fn=Symbol("emittedError"),Cr=Symbol("closed"),s3=Symbol("read"),Or=Symbol("flush"),a3=Symbol("flushChunk"),Se=Symbol("encoding"),Mi=Symbol("decoder"),J=Symbol("flowing"),hn=Symbol("paused"),Ci=Symbol("resume"),B=Symbol("buffer"),_=Symbol("pipes"),Z=Symbol("bufferLength"),aa=Symbol("bufferPush"),Ur=Symbol("bufferShift"),T=Symbol("objectMode"),U=Symbol("destroyed"),ca=Symbol("error"),la=Symbol("emitData"),c3=Symbol("emitEnd"),va=Symbol("emitEnd2"),Qe=Symbol("async"),Aa=Symbol("abort"),Kr=Symbol("aborted"),dn=Symbol("signal"),Xt=Symbol("dataListeners"),ie=Symbol("discarded"),Rn=t=>Promise.resolve().then(t),K7=t=>t(),V7=t=>t==="end"||t==="finish"||t==="prefinish",N7=t=>t instanceof ArrayBuffer||!!t&&typeof t=="object"&&t.constructor&&t.constructor.name==="ArrayBuffer"&&t.byteLength>=0,k7=t=>!Buffer.isBuffer(t)&&ArrayBuffer.isView(t),Vr=class{src;dest;opts;ondrain;constructor(e,i,n){this.src=e,this.dest=i,this.opts=n,this.ondrain=()=>e[Ci](),this.dest.on("drain",this.ondrain)}unpipe(){this.dest.removeListener("drain",this.ondrain)}proxyErrors(e){}end(){this.unpipe(),this.opts.end&&this.dest.end()}},ua=class extends Vr{unpipe(){this.src.removeListener("error",this.proxyErrors),super.unpipe()}constructor(e,i,n){super(e,i,n),this.proxyErrors=r=>i.emit("error",r),e.on("error",this.proxyErrors)}},F7=t=>!!t.objectMode,Q7=t=>!t.objectMode&&!!t.encoding&&t.encoding!=="buffer",zn=class extends ma{[J]=!1;[hn]=!1;[_]=[];[B]=[];[T];[Se];[Qe];[Mi];[$e]=!1;[ht]=!1;[Mr]=!1;[Cr]=!1;[fn]=null;[Z]=0;[U]=!1;[dn];[Kr]=!1;[Xt]=0;[ie]=!1;writable=!0;readable=!0;constructor(...e){let i=e[0]||{};if(super(),i.objectMode&&typeof i.encoding=="string")throw new TypeError("Encoding and objectMode may not be used together");F7(i)?(this[T]=!0,this[Se]=null):Q7(i)?(this[Se]=i.encoding,this[T]=!1):(this[T]=!1,this[Se]=null),this[Qe]=!!i.async,this[Mi]=this[Se]?new M7(this[Se]):null,i&&i.debugExposeBuffer===!0&&Object.defineProperty(this,"buffer",{get:()=>this[B]}),i&&i.debugExposePipes===!0&&Object.defineProperty(this,"pipes",{get:()=>this[_]});let{signal:n}=i;n&&(this[dn]=n,n.aborted?this[Aa]():n.addEventListener("abort",()=>this[Aa]()))}get bufferLength(){return this[Z]}get encoding(){return this[Se]}set encoding(e){throw new Error("Encoding must be set at instantiation time")}setEncoding(e){throw new Error("Encoding must be set at instantiation time")}get objectMode(){return this[T]}set objectMode(e){throw new Error("objectMode must be set at instantiation time")}get async(){return this[Qe]}set async(e){this[Qe]=this[Qe]||!!e}[Aa](){this[Kr]=!0,this.emit("abort",this[dn]?.reason),this.destroy(this[dn]?.reason)}get aborted(){return this[Kr]}set aborted(e){}write(e,i,n){if(this[Kr])return!1;if(this[$e])throw new Error("write after end");if(this[U])return this.emit("error",Object.assign(new Error("Cannot call write after a stream was destroyed"),{code:"ERR_STREAM_DESTROYED"})),!0;typeof i=="function"&&(n=i,i="utf8"),i||(i="utf8");let r=this[Qe]?Rn:K7;if(!this[T]&&!Buffer.isBuffer(e)){if(k7(e))e=Buffer.from(e.buffer,e.byteOffset,e.byteLength);else if(N7(e))e=Buffer.from(e);else if(typeof e!="string")throw new Error("Non-contiguous data written to non-objectMode stream")}return this[T]?(this[J]&&this[Z]!==0&&this[Or](!0),this[J]?this.emit("data",e):this[aa](e),this[Z]!==0&&this.emit("readable"),n&&r(n),this[J]):e.length?(typeof e=="string"&&!(i===this[Se]&&!this[Mi]?.lastNeed)&&(e=Buffer.from(e,i)),Buffer.isBuffer(e)&&this[Se]&&(e=this[Mi].write(e)),this[J]&&this[Z]!==0&&this[Or](!0),this[J]?this.emit("data",e):this[aa](e),this[Z]!==0&&this.emit("readable"),n&&r(n),this[J]):(this[Z]!==0&&this.emit("readable"),n&&r(n),this[J])}read(e){if(this[U])return null;if(this[ie]=!1,this[Z]===0||e===0||e&&e>this[Z])return this[et](),null;this[T]&&(e=null),this[B].length>1&&!this[T]&&(this[B]=[this[Se]?this[B].join(""):Buffer.concat(this[B],this[Z])]);let i=this[s3](e||null,this[B][0]);return this[et](),i}[s3](e,i){if(this[T])this[Ur]();else{let n=i;e===n.length||e===null?this[Ur]():typeof n=="string"?(this[B][0]=n.slice(e),i=n.slice(0,e),this[Z]-=e):(this[B][0]=n.subarray(e),i=n.subarray(0,e),this[Z]-=e)}return this.emit("data",i),!this[B].length&&!this[$e]&&this.emit("drain"),i}end(e,i,n){return typeof e=="function"&&(n=e,e=void 0),typeof i=="function"&&(n=i,i="utf8"),e!==void 0&&this.write(e,i),n&&this.once("end",n),this[$e]=!0,this.writable=!1,(this[J]||!this[hn])&&this[et](),this}[Ci](){this[U]||(!this[Xt]&&!this[_].length&&(this[ie]=!0),this[hn]=!1,this[J]=!0,this.emit("resume"),this[B].length?this[Or]():this[$e]?this[et]():this.emit("drain"))}resume(){return this[Ci]()}pause(){this[J]=!1,this[hn]=!0,this[ie]=!1}get destroyed(){return this[U]}get flowing(){return this[J]}get paused(){return this[hn]}[aa](e){this[T]?this[Z]+=1:this[Z]+=e.length,this[B].push(e)}[Ur](){return this[T]?this[Z]-=1:this[Z]-=this[B][0].length,this[B].shift()}[Or](e=!1){do;while(this[a3](this[Ur]())&&this[B].length);!e&&!this[B].length&&!this[$e]&&this.emit("drain")}[a3](e){return this.emit("data",e),this[J]}pipe(e,i){if(this[U])return e;this[ie]=!1;let n=this[ht];return i=i||{},e===o3.stdout||e===o3.stderr?i.end=!1:i.end=i.end!==!1,i.proxyErrors=!!i.proxyErrors,n?i.end&&e.end():(this[_].push(i.proxyErrors?new ua(this,e,i):new Vr(this,e,i)),this[Qe]?Rn(()=>this[Ci]()):this[Ci]()),e}unpipe(e){let i=this[_].find(n=>n.dest===e);i&&(this[_].length===1?(this[J]&&this[Xt]===0&&(this[J]=!1),this[_]=[]):this[_].splice(this[_].indexOf(i),1),i.unpipe())}addListener(e,i){return this.on(e,i)}on(e,i){let n=super.on(e,i);if(e==="data")this[ie]=!1,this[Xt]++,!this[_].length&&!this[J]&&this[Ci]();else if(e==="readable"&&this[Z]!==0)super.emit("readable");else if(V7(e)&&this[ht])super.emit(e),this.removeAllListeners(e);else if(e==="error"&&this[fn]){let r=i;this[Qe]?Rn(()=>r.call(this,this[fn])):r.call(this,this[fn])}return n}removeListener(e,i){return this.off(e,i)}off(e,i){let n=super.off(e,i);return e==="data"&&(this[Xt]=this.listeners("data").length,this[Xt]===0&&!this[ie]&&!this[_].length&&(this[J]=!1)),n}removeAllListeners(e){let i=super.removeAllListeners(e);return(e==="data"||e===void 0)&&(this[Xt]=0,!this[ie]&&!this[_].length&&(this[J]=!1)),i}get emittedEnd(){return this[ht]}[et](){!this[Mr]&&!this[ht]&&!this[U]&&this[B].length===0&&this[$e]&&(this[Mr]=!0,this.emit("end"),this.emit("prefinish"),this.emit("finish"),this[Cr]&&this.emit("close"),this[Mr]=!1)}emit(e,...i){let n=i[0];if(e!=="error"&&e!=="close"&&e!==U&&this[U])return!1;if(e==="data")return!this[T]&&!n?!1:this[Qe]?(Rn(()=>this[la](n)),!0):this[la](n);if(e==="end")return this[c3]();if(e==="close"){if(this[Cr]=!0,!this[ht]&&!this[U])return!1;let o=super.emit("close");return this.removeAllListeners("close"),o}else if(e==="error"){this[fn]=n,super.emit(ca,n);let o=!this[dn]||this.listeners("error").length?super.emit("error",n):!1;return this[et](),o}else if(e==="resume"){let o=super.emit("resume");return this[et](),o}else if(e==="finish"||e==="prefinish"){let o=super.emit(e);return this.removeAllListeners(e),o}let r=super.emit(e,...i);return this[et](),r}[la](e){for(let n of this[_])n.dest.write(e)===!1&&this.pause();let i=this[ie]?!1:super.emit("data",e);return this[et](),i}[c3](){return this[ht]?!1:(this[ht]=!0,this.readable=!1,this[Qe]?(Rn(()=>this[va]()),!0):this[va]())}[va](){if(this[Mi]){let i=this[Mi].end();if(i){for(let n of this[_])n.dest.write(i);this[ie]||super.emit("data",i)}}for(let i of this[_])i.end();let e=super.emit("end");return this.removeAllListeners("end"),e}async collect(){let e=Object.assign([],{dataLength:0});this[T]||(e.dataLength=0);let i=this.promise();return this.on("data",n=>{e.push(n),this[T]||(e.dataLength+=n.length)}),await i,e}async concat(){if(this[T])throw new Error("cannot concat in objectMode");let e=await this.collect();return this[Se]?e.join(""):Buffer.concat(e,e.dataLength)}async promise(){return new Promise((e,i)=>{this.on(U,()=>i(new Error("stream destroyed"))),this.on("error",n=>i(n)),this.on("end",()=>e())})}[Symbol.asyncIterator](){this[ie]=!1;let e=!1,i=async()=>(this.pause(),e=!0,{value:void 0,done:!0});return{next:()=>{if(e)return i();let r=this.read();if(r!==null)return Promise.resolve({done:!1,value:r});if(this[$e])return i();let o,a,c=u=>{this.off("data",l),this.off("end",v),this.off(U,A),i(),a(u)},l=u=>{this.off("error",c),this.off("end",v),this.off(U,A),this.pause(),o({value:u,done:!!this[$e]})},v=()=>{this.off("error",c),this.off("data",l),this.off(U,A),i(),o({done:!0,value:void 0})},A=()=>c(new Error("stream destroyed"));return new Promise((u,p)=>{a=p,o=u,this.once(U,A),this.once("error",c),this.once("end",v),this.once("data",l)})},throw:i,return:i,[Symbol.asyncIterator](){return this}}}[Symbol.iterator](){this[ie]=!1;let e=!1,i=()=>(this.pause(),this.off(ca,i),this.off(U,i),this.off("end",i),e=!0,{done:!0,value:void 0}),n=()=>{if(e)return i();let r=this.read();return r===null?i():{done:!1,value:r}};return this.once("end",i),this.once(ca,i),this.once(U,i),{next:n,throw:i,return:i,[Symbol.iterator](){return this}}}destroy(e){if(this[U])return e?this.emit("error",e):this.emit(U),this;this[U]=!0,this[ie]=!0,this[B].length=0,this[Z]=0;let i=this;return typeof i.close=="function"&&!this[Cr]&&i.close(),e?this.emit("error",e):this.emit(U),this}static get isStream(){return C7}};import*as v3 from"zlib";import b7 from"zlib";var J7=b7.constants||{ZLIB_VERNUM:4736},pe=Object.freeze(Object.assign(Object.create(null),{Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_VERSION_ERROR:-6,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,DEFLATE:1,INFLATE:2,GZIP:3,GUNZIP:4,DEFLATERAW:5,INFLATERAW:6,UNZIP:7,BROTLI_DECODE:8,BROTLI_ENCODE:9,Z_MIN_WINDOWBITS:8,Z_MAX_WINDOWBITS:15,Z_DEFAULT_WINDOWBITS:15,Z_MIN_CHUNK:64,Z_MAX_CHUNK:1/0,Z_DEFAULT_CHUNK:16384,Z_MIN_MEMLEVEL:1,Z_MAX_MEMLEVEL:9,Z_DEFAULT_MEMLEVEL:8,Z_MIN_LEVEL:-1,Z_MAX_LEVEL:9,Z_DEFAULT_LEVEL:-1,BROTLI_OPERATION_PROCESS:0,BROTLI_OPERATION_FLUSH:1,BROTLI_OPERATION_FINISH:2,BROTLI_OPERATION_EMIT_METADATA:3,BROTLI_MODE_GENERIC:0,BROTLI_MODE_TEXT:1,BROTLI_MODE_FONT:2,BROTLI_DEFAULT_MODE:0,BROTLI_MIN_QUALITY:0,BROTLI_MAX_QUALITY:11,BROTLI_DEFAULT_QUALITY:11,BROTLI_MIN_WINDOW_BITS:10,BROTLI_MAX_WINDOW_BITS:24,BROTLI_LARGE_MAX_WINDOW_BITS:30,BROTLI_DEFAULT_WINDOW:22,BROTLI_MIN_INPUT_BLOCK_BITS:16,BROTLI_MAX_INPUT_BLOCK_BITS:24,BROTLI_PARAM_MODE:0,BROTLI_PARAM_QUALITY:1,BROTLI_PARAM_LGWIN:2,BROTLI_PARAM_LGBLOCK:3,BROTLI_PARAM_DISABLE_LITERAL_CONTEXT_MODELING:4,BROTLI_PARAM_SIZE_HINT:5,BROTLI_PARAM_LARGE_WINDOW:6,BROTLI_PARAM_NPOSTFIX:7,BROTLI_PARAM_NDIRECT:8,BROTLI_DECODER_RESULT_ERROR:0,BROTLI_DECODER_RESULT_SUCCESS:1,BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT:2,BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT:3,BROTLI_DECODER_PARAM_DISABLE_RING_BUFFER_REALLOCATION:0,BROTLI_DECODER_PARAM_LARGE_WINDOW:1,BROTLI_DECODER_NO_ERROR:0,BROTLI_DECODER_SUCCESS:1,BROTLI_DECODER_NEEDS_MORE_INPUT:2,BROTLI_DECODER_NEEDS_MORE_OUTPUT:3,BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_NIBBLE:-1,BROTLI_DECODER_ERROR_FORMAT_RESERVED:-2,BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_META_NIBBLE:-3,BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_ALPHABET:-4,BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_SAME:-5,BROTLI_DECODER_ERROR_FORMAT_CL_SPACE:-6,BROTLI_DECODER_ERROR_FORMAT_HUFFMAN_SPACE:-7,BROTLI_DECODER_ERROR_FORMAT_CONTEXT_MAP_REPEAT:-8,BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_1:-9,BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_2:-10,BROTLI_DECODER_ERROR_FORMAT_TRANSFORM:-11,BROTLI_DECODER_ERROR_FORMAT_DICTIONARY:-12,BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS:-13,BROTLI_DECODER_ERROR_FORMAT_PADDING_1:-14,BROTLI_DECODER_ERROR_FORMAT_PADDING_2:-15,BROTLI_DECODER_ERROR_FORMAT_DISTANCE:-16,BROTLI_DECODER_ERROR_DICTIONARY_NOT_SET:-19,BROTLI_DECODER_ERROR_INVALID_ARGUMENTS:-20,BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MODES:-21,BROTLI_DECODER_ERROR_ALLOC_TREE_GROUPS:-22,BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MAP:-25,BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_1:-26,BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_2:-27,BROTLI_DECODER_ERROR_ALLOC_BLOCK_TYPE_TREES:-30,BROTLI_DECODER_ERROR_UNREACHABLE:-31},J7));var B7=Ht.concat,A3=Object.getOwnPropertyDescriptor(Ht,"concat"),Z7=t=>t,Ea=A3?.writable===!0||A3?.set!==void 0?t=>{Ht.concat=t?Z7:B7}:t=>{},Lt=Symbol("_superWrite"),Oi=class extends Error{code;errno;constructor(e,i){super("zlib: "+e.message,{cause:e}),this.code=e.code,this.errno=e.errno,this.code||(this.code="ZLIB_ERROR"),this.message="zlib: "+e.message,Error.captureStackTrace(this,i??this.constructor)}get name(){return"ZlibError"}},pa=Symbol("flushFlag"),gn=class extends zn{#e=!1;#n=!1;#i;#r;#a;#t;#o;get sawError(){return this.#e}get handle(){return this.#t}get flushFlag(){return this.#i}constructor(e,i){if(!e||typeof e!="object")throw new TypeError("invalid options for ZlibBase constructor");if(super(e),this.#i=e.flush??0,this.#r=e.finishFlush??0,this.#a=e.fullFlushFlag??0,typeof v3[i]!="function")throw new TypeError("Compression method not supported: "+i);try{this.#t=new v3[i](e)}catch(n){throw new Oi(n,this.constructor)}this.#o=n=>{this.#e||(this.#e=!0,this.close(),this.emit("error",n))},this.#t?.on("error",n=>this.#o(new Oi(n))),this.once("end",()=>this.close)}close(){this.#t&&(this.#t.close(),this.#t=void 0,this.emit("close"))}reset(){if(!this.#e)return Ia(this.#t,"zlib binding closed"),this.#t.reset?.()}flush(e){this.ended||(typeof e!="number"&&(e=this.#a),this.write(Object.assign(Ht.alloc(0),{[pa]:e})))}end(e,i,n){return typeof e=="function"&&(n=e,i=void 0,e=void 0),typeof i=="function"&&(n=i,i=void 0),e&&(i?this.write(e,i):this.write(e)),this.flush(this.#r),this.#n=!0,super.end(n)}get ended(){return this.#n}[Lt](e){return super.write(e)}write(e,i,n){if(typeof i=="function"&&(n=i,i="utf8"),typeof e=="string"&&(e=Ht.from(e,i)),this.#e)return;Ia(this.#t,"zlib binding closed");let r=this.#t._handle,o=r.close;r.close=()=>{};let a=this.#t.close;this.#t.close=()=>{},Ea(!0);let c;try{let v=typeof e[pa]=="number"?e[pa]:this.#i;c=this.#t._processChunk(e,v),Ea(!1)}catch(v){Ea(!1),this.#o(new Oi(v,this.write))}finally{this.#t&&(this.#t._handle=r,r.close=o,this.#t.close=a,this.#t.removeAllListeners("error"))}this.#t&&this.#t.on("error",v=>this.#o(new Oi(v,this.write)));let l;if(c)if(Array.isArray(c)&&c.length>0){let v=c[0];l=this[Lt](Ht.from(v));for(let A=1;A<c.length;A++)l=this[Lt](c[A])}else l=this[Lt](Ht.from(c));return n&&n(),l}},Nr=class extends gn{#e;#n;constructor(e,i){e=e||{},e.flush=e.flush||pe.Z_NO_FLUSH,e.finishFlush=e.finishFlush||pe.Z_FINISH,e.fullFlushFlag=pe.Z_FULL_FLUSH,super(e,i),this.#e=e.level,this.#n=e.strategy}params(e,i){if(!this.sawError){if(!this.handle)throw new Error("cannot switch params when binding is closed");if(!this.handle.params)throw new Error("not supported in this implementation");if(this.#e!==e||this.#n!==i){this.flush(pe.Z_SYNC_FLUSH),Ia(this.handle,"zlib binding closed");let n=this.handle.flush;this.handle.flush=(r,o)=>{typeof r=="function"&&(o=r,r=this.flushFlag),this.flush(r),o?.()};try{this.handle.params(e,i)}finally{this.handle.flush=n}this.handle&&(this.#e=e,this.#n=i)}}}};var kr=class extends Nr{#e;constructor(e){super(e,"Gzip"),this.#e=e&&!!e.portable}[Lt](e){return this.#e?(this.#e=!1,e[9]=255,super[Lt](e)):super[Lt](e)}};var Fr=class extends Nr{constructor(e){super(e,"Unzip")}},Qr=class extends gn{constructor(e,i){e=e||{},e.flush=e.flush||pe.BROTLI_OPERATION_PROCESS,e.finishFlush=e.finishFlush||pe.BROTLI_OPERATION_FINISH,e.fullFlushFlag=pe.BROTLI_OPERATION_FLUSH,super(e,i)}},br=class extends Qr{constructor(e){super(e,"BrotliCompress")}},Jr=class extends Qr{constructor(e){super(e,"BrotliDecompress")}},Br=class extends gn{constructor(e,i){e=e||{},e.flush=e.flush||pe.ZSTD_e_continue,e.finishFlush=e.finishFlush||pe.ZSTD_e_end,e.fullFlushFlag=pe.ZSTD_e_flush,super(e,i)}},Zr=class extends Br{constructor(e){super(e,"ZstdCompress")}},Pr=class extends Br{constructor(e){super(e,"ZstdDecompress")}};import{posix as Ui}from"node:path";var u3=(t,e)=>{if(Number.isSafeInteger(t))t<0?y7(t,e):q7(t,e);else throw Error("cannot encode number outside of javascript safe integer range");return e},q7=(t,e)=>{e[0]=128;for(var i=e.length;i>1;i--)e[i-1]=t&255,t=Math.floor(t/256)},y7=(t,e)=>{e[0]=255;var i=!1;t=t*-1;for(var n=e.length;n>1;n--){var r=t&255;t=Math.floor(t/256),i?e[n-1]=E3(r):r===0?e[n-1]=0:(i=!0,e[n-1]=p3(r))}},m3=t=>{let e=t[0],i=e===128?w7(t.subarray(1,t.length)):e===255?D7(t):null;if(i===null)throw Error("invalid base256 encoding");if(!Number.isSafeInteger(i))throw Error("parsed number outside of javascript safe integer range");return i},D7=t=>{for(var e=t.length,i=0,n=!1,r=e-1;r>-1;r--){var o=Number(t[r]),a;n?a=E3(o):o===0?a=o:(n=!0,a=p3(o)),a!==0&&(i-=a*Math.pow(256,e-r-1))}return i},w7=t=>{for(var e=t.length,i=0,n=e-1;n>-1;n--){var r=Number(t[n]);r!==0&&(i+=r*Math.pow(256,e-n-1))}return i},E3=t=>(255^t)&255,p3=t=>(255^t)+1&255;var qr=t=>yr.has(t);var yr=new Map([["0","File"],["","OldFile"],["1","Link"],["2","SymbolicLink"],["3","CharacterDevice"],["4","BlockDevice"],["5","Directory"],["6","FIFO"],["7","ContiguousFile"],["g","GlobalExtendedHeader"],["x","ExtendedHeader"],["A","SolarisACL"],["D","GNUDumpDir"],["I","Inode"],["K","NextFileHasLongLinkpath"],["L","NextFileHasLongPath"],["M","ContinuationFile"],["N","OldGnuLongPath"],["S","SparseFile"],["V","TapeVolumeHeader"],["X","OldExtendedHeader"]]),I3=new Map(Array.from(yr).map(t=>[t[1],t[0]]));var ne=class{cksumValid=!1;needPax=!1;nullBlock=!1;block;path;mode;uid;gid;size;cksum;#e="Unsupported";linkpath;uname;gname;devmaj=0;devmin=0;atime;ctime;mtime;charset;comment;constructor(e,i=0,n,r){Buffer.isBuffer(e)?this.decode(e,i||0,n,r):e&&this.#n(e)}decode(e,i,n,r){if(i||(i=0),!e||!(e.length>=i+512))throw new Error("need 512 bytes for header");this.path=n?.path??_t(e,i,100),this.mode=n?.mode??r?.mode??dt(e,i+100,8),this.uid=n?.uid??r?.uid??dt(e,i+108,8),this.gid=n?.gid??r?.gid??dt(e,i+116,8),this.size=n?.size??r?.size??dt(e,i+124,12),this.mtime=n?.mtime??r?.mtime??fa(e,i+136,12),this.cksum=dt(e,i+148,12),r&&this.#n(r,!0),n&&this.#n(n);let o=_t(e,i+156,1);if(qr(o)&&(this.#e=o||"0"),this.#e==="0"&&this.path.slice(-1)==="/"&&(this.#e="5"),this.#e==="5"&&(this.size=0),this.linkpath=_t(e,i+157,100),e.subarray(i+257,i+265).toString()==="ustar\x0000")if(this.uname=n?.uname??r?.uname??_t(e,i+265,32),this.gname=n?.gname??r?.gname??_t(e,i+297,32),this.devmaj=n?.devmaj??r?.devmaj??dt(e,i+329,8)??0,this.devmin=n?.devmin??r?.devmin??dt(e,i+337,8)??0,e[i+475]!==0){let c=_t(e,i+345,155);this.path=c+"/"+this.path}else{let c=_t(e,i+345,130);c&&(this.path=c+"/"+this.path),this.atime=n?.atime??r?.atime??fa(e,i+476,12),this.ctime=n?.ctime??r?.ctime??fa(e,i+488,12)}let a=256;for(let c=i;c<i+148;c++)a+=e[c];for(let c=i+156;c<i+512;c++)a+=e[c];this.cksumValid=a===this.cksum,this.cksum===void 0&&a===256&&(this.nullBlock=!0)}#n(e,i=!1){Object.assign(this,Object.fromEntries(Object.entries(e).filter(([n,r])=>!(r==null||n==="path"&&i||n==="linkpath"&&i||n==="global"))))}encode(e,i=0){if(e||(e=this.block=Buffer.alloc(512)),this.#e==="Unsupported"&&(this.#e="0"),!(e.length>=i+512))throw new Error("need 512 bytes for header");let n=this.ctime||this.atime?130:155,r=X7(this.path||"",n),o=r[0],a=r[1];this.needPax=!!r[2],this.needPax=$t(e,i,100,o)||this.needPax,this.needPax=Rt(e,i+100,8,this.mode)||this.needPax,this.needPax=Rt(e,i+108,8,this.uid)||this.needPax,this.needPax=Rt(e,i+116,8,this.gid)||this.needPax,this.needPax=Rt(e,i+124,12,this.size)||this.needPax,this.needPax=ha(e,i+136,12,this.mtime)||this.needPax,e[i+156]=this.#e.charCodeAt(0),this.needPax=$t(e,i+157,100,this.linkpath)||this.needPax,e.write("ustar\x0000",i+257,8),this.needPax=$t(e,i+265,32,this.uname)||this.needPax,this.needPax=$t(e,i+297,32,this.gname)||this.needPax,this.needPax=Rt(e,i+329,8,this.devmaj)||this.needPax,this.needPax=Rt(e,i+337,8,this.devmin)||this.needPax,this.needPax=$t(e,i+345,n,a)||this.needPax,e[i+475]!==0?this.needPax=$t(e,i+345,155,a)||this.needPax:(this.needPax=$t(e,i+345,130,a)||this.needPax,this.needPax=ha(e,i+476,12,this.atime)||this.needPax,this.needPax=ha(e,i+488,12,this.ctime)||this.needPax);let c=256;for(let l=i;l<i+148;l++)c+=e[l];for(let l=i+156;l<i+512;l++)c+=e[l];return this.cksum=c,Rt(e,i+148,8,this.cksum),this.cksumValid=!0,this.needPax}get type(){return this.#e==="Unsupported"?this.#e:yr.get(this.#e)}get typeKey(){return this.#e}set type(e){let i=String(I3.get(e));if(qr(i)||i==="Unsupported")this.#e=i;else if(qr(e))this.#e=e;else throw new TypeError("invalid entry type: "+e)}},X7=(t,e)=>{let n=t,r="",o,a=Ui.parse(t).root||".";if(Buffer.byteLength(n)<100)o=[n,r,!1];else{r=Ui.dirname(n),n=Ui.basename(n);do Buffer.byteLength(n)<=100&&Buffer.byteLength(r)<=e?o=[n,r,!1]:Buffer.byteLength(n)>100&&Buffer.byteLength(r)<=e?o=[n.slice(0,99),r,!0]:(n=Ui.join(Ui.basename(r),n),r=Ui.dirname(r));while(r!==a&&o===void 0);o||(o=[t.slice(0,99),"",!0])}return o},_t=(t,e,i)=>t.subarray(e,e+i).toString("utf8").replace(/\0.*/,""),fa=(t,e,i)=>H7(dt(t,e,i)),H7=t=>t===void 0?void 0:new Date(t*1e3),dt=(t,e,i)=>Number(t[e])&128?m3(t.subarray(e,e+i)):_7(t,e,i),L7=t=>isNaN(t)?void 0:t,_7=(t,e,i)=>L7(parseInt(t.subarray(e,e+i).toString("utf8").replace(/\0.*$/,"").trim(),8)),$7={12:8589934591,8:2097151},Rt=(t,e,i,n)=>n===void 0?!1:n>$7[i]||n<0?(u3(n,t.subarray(e,e+i)),!0):(em(t,e,i,n),!1),em=(t,e,i,n)=>t.write(tm(n,i),e,i,"ascii"),tm=(t,e)=>im(Math.floor(t).toString(8),e),im=(t,e)=>(t.length===e-1?t:new Array(e-t.length-1).join("0")+t+" ")+"\0",ha=(t,e,i,n)=>n===void 0?!1:Rt(t,e,i,n.getTime()/1e3),nm=new Array(156).join("\0"),$t=(t,e,i,n)=>n===void 0?!1:(t.write(n+nm,e,i,"utf8"),n.length!==Buffer.byteLength(n)||n.length>i);import{basename as rm}from"node:path";var zt=class t{atime;mtime;ctime;charset;comment;gid;uid;gname;uname;linkpath;dev;ino;nlink;path;size;mode;global;constructor(e,i=!1){this.atime=e.atime,this.charset=e.charset,this.comment=e.comment,this.ctime=e.ctime,this.dev=e.dev,this.gid=e.gid,this.global=i,this.gname=e.gname,this.ino=e.ino,this.linkpath=e.linkpath,this.mtime=e.mtime,this.nlink=e.nlink,this.path=e.path,this.size=e.size,this.uid=e.uid,this.uname=e.uname}encode(){let e=this.encodeBody();if(e==="")return Buffer.allocUnsafe(0);let i=Buffer.byteLength(e),n=512*Math.ceil(1+i/512),r=Buffer.allocUnsafe(n);for(let o=0;o<512;o++)r[o]=0;new ne({path:("PaxHeader/"+rm(this.path??"")).slice(0,99),mode:this.mode||420,uid:this.uid,gid:this.gid,size:i,mtime:this.mtime,type:this.global?"GlobalExtendedHeader":"ExtendedHeader",linkpath:"",uname:this.uname||"",gname:this.gname||"",devmaj:0,devmin:0,atime:this.atime,ctime:this.ctime}).encode(r),r.write(e,512,i,"utf8");for(let o=i+512;o<r.length;o++)r[o]=0;return r}encodeBody(){return this.encodeField("path")+this.encodeField("ctime")+this.encodeField("atime")+this.encodeField("dev")+this.encodeField("ino")+this.encodeField("nlink")+this.encodeField("charset")+this.encodeField("comment")+this.encodeField("gid")+this.encodeField("gname")+this.encodeField("linkpath")+this.encodeField("mtime")+this.encodeField("size")+this.encodeField("uid")+this.encodeField("uname")}encodeField(e){if(this[e]===void 0)return"";let i=this[e],n=i instanceof Date?i.getTime()/1e3:i,r=" "+(e==="dev"||e==="ino"||e==="nlink"?"SCHILY.":"")+e+"="+n+`
18
- `,o=Buffer.byteLength(r),a=Math.floor(Math.log(o)/Math.log(10))+1;return o+a>=Math.pow(10,a)&&(a+=1),a+o+r}static parse(e,i,n=!1){return new t(om(sm(e),i),n)}},om=(t,e)=>e?Object.assign({},e,t):t,sm=t=>t.replace(/\n$/,"").split(`
19
- `).reduce(am,Object.create(null)),am=(t,e)=>{let i=parseInt(e,10);if(i!==Buffer.byteLength(e)+1)return t;e=e.slice((i+" ").length);let n=e.split("="),r=n.shift();if(!r)return t;let o=r.replace(/^SCHILY\.(dev|ino|nlink)/,"$1"),a=n.join("=");return t[o]=/^([A-Z]+\.)?([mac]|birth|creation)time$/.test(o)?new Date(Number(a)*1e3):/^[0-9]+$/.test(a)?+a:a,t};import{EventEmitter as Ga}from"node:events";import g3 from"node:stream";import{StringDecoder as cm}from"node:string_decoder";var h3=typeof process=="object"&&process?process:{stdout:null,stderr:null},lm=t=>!!t&&typeof t=="object"&&(t instanceof Je||t instanceof g3||vm(t)||Am(t)),vm=t=>!!t&&typeof t=="object"&&t instanceof Ga&&typeof t.pipe=="function"&&t.pipe!==g3.Writable.prototype.pipe,Am=t=>!!t&&typeof t=="object"&&t instanceof Ga&&typeof t.write=="function"&&typeof t.end=="function",tt=Symbol("EOF"),it=Symbol("maybeEmitEnd"),gt=Symbol("emittedEnd"),Dr=Symbol("emittingEnd"),jn=Symbol("emittedError"),wr=Symbol("closed"),d3=Symbol("read"),Tr=Symbol("flush"),R3=Symbol("flushChunk"),Ye=Symbol("encoding"),Ki=Symbol("decoder"),P=Symbol("flowing"),xn=Symbol("paused"),Vi=Symbol("resume"),q=Symbol("buffer"),$=Symbol("pipes"),y=Symbol("bufferLength"),da=Symbol("bufferPush"),Xr=Symbol("bufferShift"),X=Symbol("objectMode"),K=Symbol("destroyed"),Ra=Symbol("error"),za=Symbol("emitData"),z3=Symbol("emitEnd"),ga=Symbol("emitEnd2"),be=Symbol("async"),ja=Symbol("abort"),Hr=Symbol("aborted"),Gn=Symbol("signal"),ei=Symbol("dataListeners"),re=Symbol("discarded"),Sn=t=>Promise.resolve().then(t),um=t=>t(),mm=t=>t==="end"||t==="finish"||t==="prefinish",Em=t=>t instanceof ArrayBuffer||!!t&&typeof t=="object"&&t.constructor&&t.constructor.name==="ArrayBuffer"&&t.byteLength>=0,pm=t=>!Buffer.isBuffer(t)&&ArrayBuffer.isView(t),Lr=class{src;dest;opts;ondrain;constructor(e,i,n){this.src=e,this.dest=i,this.opts=n,this.ondrain=()=>e[Vi](),this.dest.on("drain",this.ondrain)}unpipe(){this.dest.removeListener("drain",this.ondrain)}proxyErrors(e){}end(){this.unpipe(),this.opts.end&&this.dest.end()}},xa=class extends Lr{unpipe(){this.src.removeListener("error",this.proxyErrors),super.unpipe()}constructor(e,i,n){super(e,i,n),this.proxyErrors=r=>i.emit("error",r),e.on("error",this.proxyErrors)}},Im=t=>!!t.objectMode,fm=t=>!t.objectMode&&!!t.encoding&&t.encoding!=="buffer",Je=class extends Ga{[P]=!1;[xn]=!1;[$]=[];[q]=[];[X];[Ye];[be];[Ki];[tt]=!1;[gt]=!1;[Dr]=!1;[wr]=!1;[jn]=null;[y]=0;[K]=!1;[Gn];[Hr]=!1;[ei]=0;[re]=!1;writable=!0;readable=!0;constructor(...e){let i=e[0]||{};if(super(),i.objectMode&&typeof i.encoding=="string")throw new TypeError("Encoding and objectMode may not be used together");Im(i)?(this[X]=!0,this[Ye]=null):fm(i)?(this[Ye]=i.encoding,this[X]=!1):(this[X]=!1,this[Ye]=null),this[be]=!!i.async,this[Ki]=this[Ye]?new cm(this[Ye]):null,i&&i.debugExposeBuffer===!0&&Object.defineProperty(this,"buffer",{get:()=>this[q]}),i&&i.debugExposePipes===!0&&Object.defineProperty(this,"pipes",{get:()=>this[$]});let{signal:n}=i;n&&(this[Gn]=n,n.aborted?this[ja]():n.addEventListener("abort",()=>this[ja]()))}get bufferLength(){return this[y]}get encoding(){return this[Ye]}set encoding(e){throw new Error("Encoding must be set at instantiation time")}setEncoding(e){throw new Error("Encoding must be set at instantiation time")}get objectMode(){return this[X]}set objectMode(e){throw new Error("objectMode must be set at instantiation time")}get async(){return this[be]}set async(e){this[be]=this[be]||!!e}[ja](){this[Hr]=!0,this.emit("abort",this[Gn]?.reason),this.destroy(this[Gn]?.reason)}get aborted(){return this[Hr]}set aborted(e){}write(e,i,n){if(this[Hr])return!1;if(this[tt])throw new Error("write after end");if(this[K])return this.emit("error",Object.assign(new Error("Cannot call write after a stream was destroyed"),{code:"ERR_STREAM_DESTROYED"})),!0;typeof i=="function"&&(n=i,i="utf8"),i||(i="utf8");let r=this[be]?Sn:um;if(!this[X]&&!Buffer.isBuffer(e)){if(pm(e))e=Buffer.from(e.buffer,e.byteOffset,e.byteLength);else if(Em(e))e=Buffer.from(e);else if(typeof e!="string")throw new Error("Non-contiguous data written to non-objectMode stream")}return this[X]?(this[P]&&this[y]!==0&&this[Tr](!0),this[P]?this.emit("data",e):this[da](e),this[y]!==0&&this.emit("readable"),n&&r(n),this[P]):e.length?(typeof e=="string"&&!(i===this[Ye]&&!this[Ki]?.lastNeed)&&(e=Buffer.from(e,i)),Buffer.isBuffer(e)&&this[Ye]&&(e=this[Ki].write(e)),this[P]&&this[y]!==0&&this[Tr](!0),this[P]?this.emit("data",e):this[da](e),this[y]!==0&&this.emit("readable"),n&&r(n),this[P]):(this[y]!==0&&this.emit("readable"),n&&r(n),this[P])}read(e){if(this[K])return null;if(this[re]=!1,this[y]===0||e===0||e&&e>this[y])return this[it](),null;this[X]&&(e=null),this[q].length>1&&!this[X]&&(this[q]=[this[Ye]?this[q].join(""):Buffer.concat(this[q],this[y])]);let i=this[d3](e||null,this[q][0]);return this[it](),i}[d3](e,i){if(this[X])this[Xr]();else{let n=i;e===n.length||e===null?this[Xr]():typeof n=="string"?(this[q][0]=n.slice(e),i=n.slice(0,e),this[y]-=e):(this[q][0]=n.subarray(e),i=n.subarray(0,e),this[y]-=e)}return this.emit("data",i),!this[q].length&&!this[tt]&&this.emit("drain"),i}end(e,i,n){return typeof e=="function"&&(n=e,e=void 0),typeof i=="function"&&(n=i,i="utf8"),e!==void 0&&this.write(e,i),n&&this.once("end",n),this[tt]=!0,this.writable=!1,(this[P]||!this[xn])&&this[it](),this}[Vi](){this[K]||(!this[ei]&&!this[$].length&&(this[re]=!0),this[xn]=!1,this[P]=!0,this.emit("resume"),this[q].length?this[Tr]():this[tt]?this[it]():this.emit("drain"))}resume(){return this[Vi]()}pause(){this[P]=!1,this[xn]=!0,this[re]=!1}get destroyed(){return this[K]}get flowing(){return this[P]}get paused(){return this[xn]}[da](e){this[X]?this[y]+=1:this[y]+=e.length,this[q].push(e)}[Xr](){return this[X]?this[y]-=1:this[y]-=this[q][0].length,this[q].shift()}[Tr](e=!1){do;while(this[R3](this[Xr]())&&this[q].length);!e&&!this[q].length&&!this[tt]&&this.emit("drain")}[R3](e){return this.emit("data",e),this[P]}pipe(e,i){if(this[K])return e;this[re]=!1;let n=this[gt];return i=i||{},e===h3.stdout||e===h3.stderr?i.end=!1:i.end=i.end!==!1,i.proxyErrors=!!i.proxyErrors,n?i.end&&e.end():(this[$].push(i.proxyErrors?new xa(this,e,i):new Lr(this,e,i)),this[be]?Sn(()=>this[Vi]()):this[Vi]()),e}unpipe(e){let i=this[$].find(n=>n.dest===e);i&&(this[$].length===1?(this[P]&&this[ei]===0&&(this[P]=!1),this[$]=[]):this[$].splice(this[$].indexOf(i),1),i.unpipe())}addListener(e,i){return this.on(e,i)}on(e,i){let n=super.on(e,i);if(e==="data")this[re]=!1,this[ei]++,!this[$].length&&!this[P]&&this[Vi]();else if(e==="readable"&&this[y]!==0)super.emit("readable");else if(mm(e)&&this[gt])super.emit(e),this.removeAllListeners(e);else if(e==="error"&&this[jn]){let r=i;this[be]?Sn(()=>r.call(this,this[jn])):r.call(this,this[jn])}return n}removeListener(e,i){return this.off(e,i)}off(e,i){let n=super.off(e,i);return e==="data"&&(this[ei]=this.listeners("data").length,this[ei]===0&&!this[re]&&!this[$].length&&(this[P]=!1)),n}removeAllListeners(e){let i=super.removeAllListeners(e);return(e==="data"||e===void 0)&&(this[ei]=0,!this[re]&&!this[$].length&&(this[P]=!1)),i}get emittedEnd(){return this[gt]}[it](){!this[Dr]&&!this[gt]&&!this[K]&&this[q].length===0&&this[tt]&&(this[Dr]=!0,this.emit("end"),this.emit("prefinish"),this.emit("finish"),this[wr]&&this.emit("close"),this[Dr]=!1)}emit(e,...i){let n=i[0];if(e!=="error"&&e!=="close"&&e!==K&&this[K])return!1;if(e==="data")return!this[X]&&!n?!1:this[be]?(Sn(()=>this[za](n)),!0):this[za](n);if(e==="end")return this[z3]();if(e==="close"){if(this[wr]=!0,!this[gt]&&!this[K])return!1;let o=super.emit("close");return this.removeAllListeners("close"),o}else if(e==="error"){this[jn]=n,super.emit(Ra,n);let o=!this[Gn]||this.listeners("error").length?super.emit("error",n):!1;return this[it](),o}else if(e==="resume"){let o=super.emit("resume");return this[it](),o}else if(e==="finish"||e==="prefinish"){let o=super.emit(e);return this.removeAllListeners(e),o}let r=super.emit(e,...i);return this[it](),r}[za](e){for(let n of this[$])n.dest.write(e)===!1&&this.pause();let i=this[re]?!1:super.emit("data",e);return this[it](),i}[z3](){return this[gt]?!1:(this[gt]=!0,this.readable=!1,this[be]?(Sn(()=>this[ga]()),!0):this[ga]())}[ga](){if(this[Ki]){let i=this[Ki].end();if(i){for(let n of this[$])n.dest.write(i);this[re]||super.emit("data",i)}}for(let i of this[$])i.end();let e=super.emit("end");return this.removeAllListeners("end"),e}async collect(){let e=Object.assign([],{dataLength:0});this[X]||(e.dataLength=0);let i=this.promise();return this.on("data",n=>{e.push(n),this[X]||(e.dataLength+=n.length)}),await i,e}async concat(){if(this[X])throw new Error("cannot concat in objectMode");let e=await this.collect();return this[Ye]?e.join(""):Buffer.concat(e,e.dataLength)}async promise(){return new Promise((e,i)=>{this.on(K,()=>i(new Error("stream destroyed"))),this.on("error",n=>i(n)),this.on("end",()=>e())})}[Symbol.asyncIterator](){this[re]=!1;let e=!1,i=async()=>(this.pause(),e=!0,{value:void 0,done:!0});return{next:()=>{if(e)return i();let r=this.read();if(r!==null)return Promise.resolve({done:!1,value:r});if(this[tt])return i();let o,a,c=u=>{this.off("data",l),this.off("end",v),this.off(K,A),i(),a(u)},l=u=>{this.off("error",c),this.off("end",v),this.off(K,A),this.pause(),o({value:u,done:!!this[tt]})},v=()=>{this.off("error",c),this.off("data",l),this.off(K,A),i(),o({done:!0,value:void 0})},A=()=>c(new Error("stream destroyed"));return new Promise((u,p)=>{a=p,o=u,this.once(K,A),this.once("error",c),this.once("end",v),this.once("data",l)})},throw:i,return:i,[Symbol.asyncIterator](){return this}}}[Symbol.iterator](){this[re]=!1;let e=!1,i=()=>(this.pause(),this.off(Ra,i),this.off(K,i),this.off("end",i),e=!0,{done:!0,value:void 0}),n=()=>{if(e)return i();let r=this.read();return r===null?i():{done:!1,value:r}};return this.once("end",i),this.once(Ra,i),this.once(K,i),{next:n,throw:i,return:i,[Symbol.iterator](){return this}}}destroy(e){if(this[K])return e?this.emit("error",e):this.emit(K),this;this[K]=!0,this[re]=!0,this[q].length=0,this[y]=0;let i=this;return typeof i.close=="function"&&!this[wr]&&i.close(),e?this.emit("error",e):this.emit(K),this}static get isStream(){return lm}};var hm=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,R=hm!=="win32"?t=>t:t=>t&&t.replace(/\\/g,"/");var Ni=class extends Je{extended;globalExtended;header;startBlockSize;blockRemain;remain;type;meta=!1;ignore=!1;path;mode;uid;gid;uname;gname;size=0;mtime;atime;ctime;linkpath;dev;ino;nlink;invalid=!1;absolute;unsupported=!1;constructor(e,i,n){switch(super({}),this.pause(),this.extended=i,this.globalExtended=n,this.header=e,this.remain=e.size??0,this.startBlockSize=512*Math.ceil(this.remain/512),this.blockRemain=this.startBlockSize,this.type=e.type,this.type){case"File":case"OldFile":case"Link":case"SymbolicLink":case"CharacterDevice":case"BlockDevice":case"Directory":case"FIFO":case"ContiguousFile":case"GNUDumpDir":break;case"NextFileHasLongLinkpath":case"NextFileHasLongPath":case"OldGnuLongPath":case"GlobalExtendedHeader":case"ExtendedHeader":case"OldExtendedHeader":this.meta=!0;break;default:this.ignore=!0}if(!e.path)throw new Error("no path provided for tar.ReadEntry");this.path=R(e.path),this.mode=e.mode,this.mode&&(this.mode=this.mode&4095),this.uid=e.uid,this.gid=e.gid,this.uname=e.uname,this.gname=e.gname,this.size=this.remain,this.mtime=e.mtime,this.atime=e.atime,this.ctime=e.ctime,this.linkpath=e.linkpath?R(e.linkpath):void 0,this.uname=e.uname,this.gname=e.gname,i&&this.#e(i),n&&this.#e(n,!0)}write(e){let i=e.length;if(i>this.blockRemain)throw new Error("writing more to entry than is appropriate");let n=this.remain,r=this.blockRemain;return this.remain=Math.max(0,n-i),this.blockRemain=Math.max(0,r-i),this.ignore?!0:n>=i?super.write(e):super.write(e.subarray(0,n))}#e(e,i=!1){e.path&&(e.path=R(e.path)),e.linkpath&&(e.linkpath=R(e.linkpath)),Object.assign(this,Object.fromEntries(Object.entries(e).filter(([n,r])=>!(r==null||n==="path"&&i))))}};var ti=(t,e,i,n={})=>{t.file&&(n.file=t.file),t.cwd&&(n.cwd=t.cwd),n.code=i instanceof Error&&i.code||e,n.tarCode=e,!t.strict&&n.recoverable!==!1?(i instanceof Error&&(n=Object.assign(i,n),i=i.message),t.emit("warn",e,i,n)):i instanceof Error?t.emit("error",Object.assign(i,n)):t.emit("error",Object.assign(new Error(`${e}: ${i}`),n))};var Rm=1024*1024,Ca=Buffer.from([31,139]),Oa=Buffer.from([40,181,47,253]),zm=Math.max(Ca.length,Oa.length),Ie=Symbol("state"),ii=Symbol("writeEntry"),nt=Symbol("readEntry"),Sa=Symbol("nextEntry"),j3=Symbol("processEntry"),Be=Symbol("extendedHeader"),Yn=Symbol("globalExtendedHeader"),jt=Symbol("meta"),x3=Symbol("emitMeta"),x=Symbol("buffer"),rt=Symbol("queue"),xt=Symbol("ended"),Ya=Symbol("emittedEnd"),ni=Symbol("emit"),V=Symbol("unzip"),_r=Symbol("consumeChunk"),$r=Symbol("consumeChunkSub"),Wa=Symbol("consumeBody"),G3=Symbol("consumeMeta"),S3=Symbol("consumeHeader"),Wn=Symbol("consuming"),Ma=Symbol("bufferConcat"),eo=Symbol("maybeEnd"),ki=Symbol("writing"),Gt=Symbol("aborted"),to=Symbol("onDone"),ri=Symbol("sawValidEntry"),io=Symbol("sawNullBlock"),no=Symbol("sawEOF"),Y3=Symbol("closeStream"),gm=()=>!0,ot=class extends dm{file;strict;maxMetaEntrySize;filter;brotli;zstd;writable=!0;readable=!1;[rt]=[];[x];[nt];[ii];[Ie]="begin";[jt]="";[Be];[Yn];[xt]=!1;[V];[Gt]=!1;[ri];[io]=!1;[no]=!1;[ki]=!1;[Wn]=!1;[Ya]=!1;constructor(e={}){super(),this.file=e.file||"",this.on(to,()=>{(this[Ie]==="begin"||this[ri]===!1)&&this.warn("TAR_BAD_ARCHIVE","Unrecognized archive format")}),e.ondone?this.on(to,e.ondone):this.on(to,()=>{this.emit("prefinish"),this.emit("finish"),this.emit("end")}),this.strict=!!e.strict,this.maxMetaEntrySize=e.maxMetaEntrySize||Rm,this.filter=typeof e.filter=="function"?e.filter:gm;let i=e.file&&(e.file.endsWith(".tar.br")||e.file.endsWith(".tbr"));this.brotli=!(e.gzip||e.zstd)&&e.brotli!==void 0?e.brotli:i?void 0:!1;let n=e.file&&(e.file.endsWith(".tar.zst")||e.file.endsWith(".tzst"));this.zstd=!(e.gzip||e.brotli)&&e.zstd!==void 0?e.zstd:n?!0:void 0,this.on("end",()=>this[Y3]()),typeof e.onwarn=="function"&&this.on("warn",e.onwarn),typeof e.onReadEntry=="function"&&this.on("entry",e.onReadEntry)}warn(e,i,n={}){ti(this,e,i,n)}[S3](e,i){this[ri]===void 0&&(this[ri]=!1);let n;try{n=new ne(e,i,this[Be],this[Yn])}catch(r){return this.warn("TAR_ENTRY_INVALID",r)}if(n.nullBlock)this[io]?(this[no]=!0,this[Ie]==="begin"&&(this[Ie]="header"),this[ni]("eof")):(this[io]=!0,this[ni]("nullBlock"));else if(this[io]=!1,!n.cksumValid)this.warn("TAR_ENTRY_INVALID","checksum failure",{header:n});else if(!n.path)this.warn("TAR_ENTRY_INVALID","path is required",{header:n});else{let r=n.type;if(/^(Symbolic)?Link$/.test(r)&&!n.linkpath)this.warn("TAR_ENTRY_INVALID","linkpath required",{header:n});else if(!/^(Symbolic)?Link$/.test(r)&&!/^(Global)?ExtendedHeader$/.test(r)&&n.linkpath)this.warn("TAR_ENTRY_INVALID","linkpath forbidden",{header:n});else{let o=this[ii]=new Ni(n,this[Be],this[Yn]);if(!this[ri])if(o.remain){let a=()=>{o.invalid||(this[ri]=!0)};o.on("end",a)}else this[ri]=!0;o.meta?o.size>this.maxMetaEntrySize?(o.ignore=!0,this[ni]("ignoredEntry",o),this[Ie]="ignore",o.resume()):o.size>0&&(this[jt]="",o.on("data",a=>this[jt]+=a),this[Ie]="meta"):(this[Be]=void 0,o.ignore=o.ignore||!this.filter(o.path,o),o.ignore?(this[ni]("ignoredEntry",o),this[Ie]=o.remain?"ignore":"header",o.resume()):(o.remain?this[Ie]="body":(this[Ie]="header",o.end()),this[nt]?this[rt].push(o):(this[rt].push(o),this[Sa]())))}}}[Y3](){queueMicrotask(()=>this.emit("close"))}[j3](e){let i=!0;if(!e)this[nt]=void 0,i=!1;else if(Array.isArray(e)){let[n,...r]=e;this.emit(n,...r)}else this[nt]=e,this.emit("entry",e),e.emittedEnd||(e.on("end",()=>this[Sa]()),i=!1);return i}[Sa](){do;while(this[j3](this[rt].shift()));if(!this[rt].length){let e=this[nt];!e||e.flowing||e.size===e.remain?this[ki]||this.emit("drain"):e.once("drain",()=>this.emit("drain"))}}[Wa](e,i){let n=this[ii];if(!n)throw new Error("attempt to consume body without entry??");let r=n.blockRemain??0,o=r>=e.length&&i===0?e:e.subarray(i,i+r);return n.write(o),n.blockRemain||(this[Ie]="header",this[ii]=void 0,n.end()),o.length}[G3](e,i){let n=this[ii],r=this[Wa](e,i);return!this[ii]&&n&&this[x3](n),r}[ni](e,i,n){!this[rt].length&&!this[nt]?this.emit(e,i,n):this[rt].push([e,i,n])}[x3](e){switch(this[ni]("meta",this[jt]),e.type){case"ExtendedHeader":case"OldExtendedHeader":this[Be]=zt.parse(this[jt],this[Be],!1);break;case"GlobalExtendedHeader":this[Yn]=zt.parse(this[jt],this[Yn],!0);break;case"NextFileHasLongPath":case"OldGnuLongPath":{let i=this[Be]??Object.create(null);this[Be]=i,i.path=this[jt].replace(/\0.*/,"");break}case"NextFileHasLongLinkpath":{let i=this[Be]||Object.create(null);this[Be]=i,i.linkpath=this[jt].replace(/\0.*/,"");break}default:throw new Error("unknown meta: "+e.type)}}abort(e){this[Gt]=!0,this.emit("abort",e),this.warn("TAR_ABORT",e,{recoverable:!1})}write(e,i,n){if(typeof i=="function"&&(n=i,i=void 0),typeof e=="string"&&(e=Buffer.from(e,typeof i=="string"?i:"utf8")),this[Gt])return n?.(),!1;if((this[V]===void 0||this.brotli===void 0&&this[V]===!1)&&e){if(this[x]&&(e=Buffer.concat([this[x],e]),this[x]=void 0),e.length<zm)return this[x]=e,n?.(),!0;for(let l=0;this[V]===void 0&&l<Ca.length;l++)e[l]!==Ca[l]&&(this[V]=!1);let a=!1;if(this[V]===!1&&this.zstd!==!1){a=!0;for(let l=0;l<Oa.length;l++)if(e[l]!==Oa[l]){a=!1;break}}let c=this.brotli===void 0&&!a;if(this[V]===!1&&c)if(e.length<512)if(this[xt])this.brotli=!0;else return this[x]=e,n?.(),!0;else try{new ne(e.subarray(0,512)),this.brotli=!1}catch{this.brotli=!0}if(this[V]===void 0||this[V]===!1&&(this.brotli||a)){let l=this[xt];this[xt]=!1,this[V]=this[V]===void 0?new Fr({}):a?new Pr({}):new Jr({}),this[V].on("data",A=>this[_r](A)),this[V].on("error",A=>this.abort(A)),this[V].on("end",()=>{this[xt]=!0,this[_r]()}),this[ki]=!0;let v=!!this[V][l?"end":"write"](e);return this[ki]=!1,n?.(),v}}this[ki]=!0,this[V]?this[V].write(e):this[_r](e),this[ki]=!1;let o=this[rt].length?!1:this[nt]?this[nt].flowing:!0;return!o&&!this[rt].length&&this[nt]?.once("drain",()=>this.emit("drain")),n?.(),o}[Ma](e){e&&!this[Gt]&&(this[x]=this[x]?Buffer.concat([this[x],e]):e)}[eo](){if(this[xt]&&!this[Ya]&&!this[Gt]&&!this[Wn]){this[Ya]=!0;let e=this[ii];if(e&&e.blockRemain){let i=this[x]?this[x].length:0;this.warn("TAR_BAD_ARCHIVE",`Truncated input (needed ${e.blockRemain} more bytes, only ${i} available)`,{entry:e}),this[x]&&e.write(this[x]),e.end()}this[ni](to)}}[_r](e){if(this[Wn]&&e)this[Ma](e);else if(!e&&!this[x])this[eo]();else if(e){if(this[Wn]=!0,this[x]){this[Ma](e);let i=this[x];this[x]=void 0,this[$r](i)}else this[$r](e);for(;this[x]&&this[x]?.length>=512&&!this[Gt]&&!this[no];){let i=this[x];this[x]=void 0,this[$r](i)}this[Wn]=!1}(!this[x]||this[xt])&&this[eo]()}[$r](e){let i=0,n=e.length;for(;i+512<=n&&!this[Gt]&&!this[no];)switch(this[Ie]){case"begin":case"header":this[S3](e,i),i+=512;break;case"ignore":case"body":i+=this[Wa](e,i);break;case"meta":i+=this[G3](e,i);break;default:throw new Error("invalid state: "+this[Ie])}i<n&&(this[x]?this[x]=Buffer.concat([e.subarray(i),this[x]]):this[x]=e.subarray(i))}end(e,i,n){return typeof e=="function"&&(n=e,i=void 0,e=void 0),typeof i=="function"&&(n=i,i=void 0),typeof e=="string"&&(e=Buffer.from(e,i)),n&&this.once("finish",n),this[Gt]||(this[V]?(e&&this[V].write(e),this[V].end()):(this[xt]=!0,(this.brotli===void 0||this.zstd===void 0)&&(e=e||Buffer.alloc(0)),e&&this.write(e),this[eo]())),this}};var St=t=>{let e=t.length-1,i=-1;for(;e>-1&&t.charAt(e)==="/";)i=e,e--;return i===-1?t:t.slice(0,i)};var Gm=t=>{let e=t.onReadEntry;t.onReadEntry=e?i=>{e(i),i.resume()}:i=>i.resume()},Ua=(t,e)=>{let i=new Map(e.map(o=>[St(o),!0])),n=t.filter,r=(o,a="")=>{let c=a||xm(o).root||".",l;if(o===c)l=!1;else{let v=i.get(o);v!==void 0?l=v:l=r(jm(o),c)}return i.set(o,l),l};t.filter=n?(o,a)=>n(o,a)&&r(St(o)):o=>r(St(o))},Sm=t=>{let e=new ot(t),i=t.file,n;try{n=Fi.openSync(i,"r");let r=Fi.fstatSync(n),o=t.maxReadSize||16*1024*1024;if(r.size<o){let a=Buffer.allocUnsafe(r.size),c=Fi.readSync(n,a,0,r.size,0);e.end(c===a.byteLength?a:a.subarray(0,c))}else{let a=0,c=Buffer.allocUnsafe(o);for(;a<r.size;){let l=Fi.readSync(n,c,0,o,a);if(l===0)break;a+=l,e.write(c.subarray(0,l))}e.end()}}finally{if(typeof n=="number")try{Fi.closeSync(n)}catch{}}},Ym=(t,e)=>{let i=new ot(t),n=t.maxReadSize||16*1024*1024,r=t.file;return new Promise((a,c)=>{i.on("error",c),i.on("end",a),Fi.stat(r,(l,v)=>{if(l)c(l);else{let A=new Tt(r,{readSize:n,size:v.size});A.on("error",c),A.pipe(i)}})})},oi=Fe(Sm,Ym,t=>new ot(t),t=>new ot(t),(t,e)=>{e?.length&&Ua(t,e),t.noResume||Gm(t)});import Io from"fs";import Ze from"fs";import O3 from"path";var Ka=(t,e,i)=>(t&=4095,i&&(t=(t|384)&-19),e&&(t&256&&(t|=64),t&32&&(t|=8),t&4&&(t|=1)),t);import{win32 as Wm}from"node:path";var{isAbsolute:Mm,parse:W3}=Wm,Mn=t=>{let e="",i=W3(t);for(;Mm(t)||i.root;){let n=t.charAt(0)==="/"&&t.slice(0,4)!=="//?/"?"/":i.root;t=t.slice(n.length),e+=n,i=W3(t)}return[e,t]};var ro=["|","<",">","?",":"],Va=ro.map(t=>String.fromCharCode(61440+t.charCodeAt(0))),Cm=new Map(ro.map((t,e)=>[t,Va[e]])),Om=new Map(Va.map((t,e)=>[t,ro[e]])),Na=t=>ro.reduce((e,i)=>e.split(i).join(Cm.get(i)),t),M3=t=>Va.reduce((e,i)=>e.split(i).join(Om.get(i)),t);var k3=(t,e)=>e?(t=R(t).replace(/^\.(\/|$)/,""),St(e)+"/"+t):R(t),Um=16*1024*1024,U3=Symbol("process"),K3=Symbol("file"),V3=Symbol("directory"),Fa=Symbol("symlink"),N3=Symbol("hardlink"),Cn=Symbol("header"),oo=Symbol("read"),Qa=Symbol("lstat"),so=Symbol("onlstat"),ba=Symbol("onread"),Ja=Symbol("onreadlink"),Ba=Symbol("openfile"),Za=Symbol("onopenfile"),Yt=Symbol("close"),ao=Symbol("mode"),Pa=Symbol("awaitDrain"),ka=Symbol("ondrain"),Pe=Symbol("prefix"),On=class extends Je{path;portable;myuid=process.getuid&&process.getuid()||0;myuser=process.env.USER||"";maxReadSize;linkCache;statCache;preservePaths;cwd;strict;mtime;noPax;noMtime;prefix;fd;blockLen=0;blockRemain=0;buf;pos=0;remain=0;length=0;offset=0;win32;absolute;header;type;linkpath;stat;onWriteEntry;#e=!1;constructor(e,i={}){let n=In(i);super(),this.path=R(e),this.portable=!!n.portable,this.maxReadSize=n.maxReadSize||Um,this.linkCache=n.linkCache||new Map,this.statCache=n.statCache||new Map,this.preservePaths=!!n.preservePaths,this.cwd=R(n.cwd||process.cwd()),this.strict=!!n.strict,this.noPax=!!n.noPax,this.noMtime=!!n.noMtime,this.mtime=n.mtime,this.prefix=n.prefix?R(n.prefix):void 0,this.onWriteEntry=n.onWriteEntry,typeof n.onwarn=="function"&&this.on("warn",n.onwarn);let r=!1;if(!this.preservePaths){let[a,c]=Mn(this.path);a&&typeof c=="string"&&(this.path=c,r=a)}this.win32=!!n.win32||process.platform==="win32",this.win32&&(this.path=M3(this.path.replace(/\\/g,"/")),e=e.replace(/\\/g,"/")),this.absolute=R(n.absolute||O3.resolve(this.cwd,e)),this.path===""&&(this.path="./"),r&&this.warn("TAR_ENTRY_INFO",`stripping ${r} from absolute path`,{entry:this,path:r+this.path});let o=this.statCache.get(this.absolute);o?this[so](o):this[Qa]()}warn(e,i,n={}){return ti(this,e,i,n)}emit(e,...i){return e==="error"&&(this.#e=!0),super.emit(e,...i)}[Qa](){Ze.lstat(this.absolute,(e,i)=>{if(e)return this.emit("error",e);this[so](i)})}[so](e){this.statCache.set(this.absolute,e),this.stat=e,e.isFile()||(e.size=0),this.type=Km(e),this.emit("stat",e),this[U3]()}[U3](){switch(this.type){case"File":return this[K3]();case"Directory":return this[V3]();case"SymbolicLink":return this[Fa]();default:return this.end()}}[ao](e){return Ka(e,this.type==="Directory",this.portable)}[Pe](e){return k3(e,this.prefix)}[Cn](){if(!this.stat)throw new Error("cannot write header before stat");this.type==="Directory"&&this.portable&&(this.noMtime=!0),this.onWriteEntry?.(this),this.header=new ne({path:this[Pe](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Pe](this.linkpath):this.linkpath,mode:this[ao](this.stat.mode),uid:this.portable?void 0:this.stat.uid,gid:this.portable?void 0:this.stat.gid,size:this.stat.size,mtime:this.noMtime?void 0:this.mtime||this.stat.mtime,type:this.type==="Unsupported"?void 0:this.type,uname:this.portable?void 0:this.stat.uid===this.myuid?this.myuser:"",atime:this.portable?void 0:this.stat.atime,ctime:this.portable?void 0:this.stat.ctime}),this.header.encode()&&!this.noPax&&super.write(new zt({atime:this.portable?void 0:this.header.atime,ctime:this.portable?void 0:this.header.ctime,gid:this.portable?void 0:this.header.gid,mtime:this.noMtime?void 0:this.mtime||this.header.mtime,path:this[Pe](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Pe](this.linkpath):this.linkpath,size:this.header.size,uid:this.portable?void 0:this.header.uid,uname:this.portable?void 0:this.header.uname,dev:this.portable?void 0:this.stat.dev,ino:this.portable?void 0:this.stat.ino,nlink:this.portable?void 0:this.stat.nlink}).encode());let e=this.header?.block;if(!e)throw new Error("failed to encode header");super.write(e)}[V3](){if(!this.stat)throw new Error("cannot create directory entry without stat");this.path.slice(-1)!=="/"&&(this.path+="/"),this.stat.size=0,this[Cn](),this.end()}[Fa](){Ze.readlink(this.absolute,(e,i)=>{if(e)return this.emit("error",e);this[Ja](i)})}[Ja](e){this.linkpath=R(e),this[Cn](),this.end()}[N3](e){if(!this.stat)throw new Error("cannot create link entry without stat");this.type="Link",this.linkpath=R(O3.relative(this.cwd,e)),this.stat.size=0,this[Cn](),this.end()}[K3](){if(!this.stat)throw new Error("cannot create file entry without stat");if(this.stat.nlink>1){let e=`${this.stat.dev}:${this.stat.ino}`,i=this.linkCache.get(e);if(i?.indexOf(this.cwd)===0)return this[N3](i);this.linkCache.set(e,this.absolute)}if(this[Cn](),this.stat.size===0)return this.end();this[Ba]()}[Ba](){Ze.open(this.absolute,"r",(e,i)=>{if(e)return this.emit("error",e);this[Za](i)})}[Za](e){if(this.fd=e,this.#e)return this[Yt]();if(!this.stat)throw new Error("should stat before calling onopenfile");this.blockLen=512*Math.ceil(this.stat.size/512),this.blockRemain=this.blockLen;let i=Math.min(this.blockLen,this.maxReadSize);this.buf=Buffer.allocUnsafe(i),this.offset=0,this.pos=0,this.remain=this.stat.size,this.length=this.buf.length,this[oo]()}[oo](){let{fd:e,buf:i,offset:n,length:r,pos:o}=this;if(e===void 0||i===void 0)throw new Error("cannot read file without first opening");Ze.read(e,i,n,r,o,(a,c)=>{if(a)return this[Yt](()=>this.emit("error",a));this[ba](c)})}[Yt](e=()=>{}){this.fd!==void 0&&Ze.close(this.fd,e)}[ba](e){if(e<=0&&this.remain>0){let r=Object.assign(new Error("encountered unexpected EOF"),{path:this.absolute,syscall:"read",code:"EOF"});return this[Yt](()=>this.emit("error",r))}if(e>this.remain){let r=Object.assign(new Error("did not encounter expected EOF"),{path:this.absolute,syscall:"read",code:"EOF"});return this[Yt](()=>this.emit("error",r))}if(!this.buf)throw new Error("should have created buffer prior to reading");if(e===this.remain)for(let r=e;r<this.length&&e<this.blockRemain;r++)this.buf[r+this.offset]=0,e++,this.remain++;let i=this.offset===0&&e===this.buf.length?this.buf:this.buf.subarray(this.offset,this.offset+e);this.write(i)?this[ka]():this[Pa](()=>this[ka]())}[Pa](e){this.once("drain",e)}write(e,i,n){if(typeof i=="function"&&(n=i,i=void 0),typeof e=="string"&&(e=Buffer.from(e,typeof i=="string"?i:"utf8")),this.blockRemain<e.length){let r=Object.assign(new Error("writing more data than expected"),{path:this.absolute});return this.emit("error",r)}return this.remain-=e.length,this.blockRemain-=e.length,this.pos+=e.length,this.offset+=e.length,super.write(e,null,n)}[ka](){if(!this.remain)return this.blockRemain&&super.write(Buffer.alloc(this.blockRemain)),this[Yt](e=>e?this.emit("error",e):this.end());if(!this.buf)throw new Error("buffer lost somehow in ONDRAIN");this.offset>=this.length&&(this.buf=Buffer.allocUnsafe(Math.min(this.blockRemain,this.buf.length)),this.offset=0),this.length=this.buf.length-this.offset,this[oo]()}},co=class extends On{sync=!0;[Qa](){this[so](Ze.lstatSync(this.absolute))}[Fa](){this[Ja](Ze.readlinkSync(this.absolute))}[Ba](){this[Za](Ze.openSync(this.absolute,"r"))}[oo](){let e=!0;try{let{fd:i,buf:n,offset:r,length:o,pos:a}=this;if(i===void 0||n===void 0)throw new Error("fd and buf must be set in READ method");let c=Ze.readSync(i,n,r,o,a);this[ba](c),e=!1}finally{if(e)try{this[Yt](()=>{})}catch{}}}[Pa](e){e()}[Yt](e=()=>{}){this.fd!==void 0&&Ze.closeSync(this.fd),e()}},lo=class extends Je{blockLen=0;blockRemain=0;buf=0;pos=0;remain=0;length=0;preservePaths;portable;strict;noPax;noMtime;readEntry;type;prefix;path;mode;uid;gid;uname;gname;header;mtime;atime;ctime;linkpath;size;onWriteEntry;warn(e,i,n={}){return ti(this,e,i,n)}constructor(e,i={}){let n=In(i);super(),this.preservePaths=!!n.preservePaths,this.portable=!!n.portable,this.strict=!!n.strict,this.noPax=!!n.noPax,this.noMtime=!!n.noMtime,this.onWriteEntry=n.onWriteEntry,this.readEntry=e;let{type:r}=e;if(r==="Unsupported")throw new Error("writing entry that should be ignored");this.type=r,this.type==="Directory"&&this.portable&&(this.noMtime=!0),this.prefix=n.prefix,this.path=R(e.path),this.mode=e.mode!==void 0?this[ao](e.mode):void 0,this.uid=this.portable?void 0:e.uid,this.gid=this.portable?void 0:e.gid,this.uname=this.portable?void 0:e.uname,this.gname=this.portable?void 0:e.gname,this.size=e.size,this.mtime=this.noMtime?void 0:n.mtime||e.mtime,this.atime=this.portable?void 0:e.atime,this.ctime=this.portable?void 0:e.ctime,this.linkpath=e.linkpath!==void 0?R(e.linkpath):void 0,typeof n.onwarn=="function"&&this.on("warn",n.onwarn);let o=!1;if(!this.preservePaths){let[c,l]=Mn(this.path);c&&typeof l=="string"&&(this.path=l,o=c)}this.remain=e.size,this.blockRemain=e.startBlockSize,this.onWriteEntry?.(this),this.header=new ne({path:this[Pe](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Pe](this.linkpath):this.linkpath,mode:this.mode,uid:this.portable?void 0:this.uid,gid:this.portable?void 0:this.gid,size:this.size,mtime:this.noMtime?void 0:this.mtime,type:this.type,uname:this.portable?void 0:this.uname,atime:this.portable?void 0:this.atime,ctime:this.portable?void 0:this.ctime}),o&&this.warn("TAR_ENTRY_INFO",`stripping ${o} from absolute path`,{entry:this,path:o+this.path}),this.header.encode()&&!this.noPax&&super.write(new zt({atime:this.portable?void 0:this.atime,ctime:this.portable?void 0:this.ctime,gid:this.portable?void 0:this.gid,mtime:this.noMtime?void 0:this.mtime,path:this[Pe](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[Pe](this.linkpath):this.linkpath,size:this.size,uid:this.portable?void 0:this.uid,uname:this.portable?void 0:this.uname,dev:this.portable?void 0:this.readEntry.dev,ino:this.portable?void 0:this.readEntry.ino,nlink:this.portable?void 0:this.readEntry.nlink}).encode());let a=this.header?.block;if(!a)throw new Error("failed to encode header");super.write(a),e.pipe(this)}[Pe](e){return k3(e,this.prefix)}[ao](e){return Ka(e,this.type==="Directory",this.portable)}write(e,i,n){typeof i=="function"&&(n=i,i=void 0),typeof e=="string"&&(e=Buffer.from(e,typeof i=="string"?i:"utf8"));let r=e.length;if(r>this.blockRemain)throw new Error("writing more to entry than is appropriate");return this.blockRemain-=r,super.write(e,n)}end(e,i,n){return this.blockRemain&&super.write(Buffer.alloc(this.blockRemain)),typeof e=="function"&&(n=e,i=void 0,e=void 0),typeof i=="function"&&(n=i,i=void 0),typeof e=="string"&&(e=Buffer.from(e,i??"utf8")),n&&this.once("finish",n),e?super.end(e,n):super.end(n),this}},Km=t=>t.isFile()?"File":t.isDirectory()?"Directory":t.isSymbolicLink()?"SymbolicLink":"Unsupported";var vo=class t{tail;head;length=0;static create(e=[]){return new t(e)}constructor(e=[]){for(let i of e)this.push(i)}*[Symbol.iterator](){for(let e=this.head;e;e=e.next)yield e.value}removeNode(e){if(e.list!==this)throw new Error("removing node which does not belong to this list");let i=e.next,n=e.prev;return i&&(i.prev=n),n&&(n.next=i),e===this.head&&(this.head=i),e===this.tail&&(this.tail=n),this.length--,e.next=void 0,e.prev=void 0,e.list=void 0,i}unshiftNode(e){if(e===this.head)return;e.list&&e.list.removeNode(e);let i=this.head;e.list=this,e.next=i,i&&(i.prev=e),this.head=e,this.tail||(this.tail=e),this.length++}pushNode(e){if(e===this.tail)return;e.list&&e.list.removeNode(e);let i=this.tail;e.list=this,e.prev=i,i&&(i.next=e),this.tail=e,this.head||(this.head=e),this.length++}push(...e){for(let i=0,n=e.length;i<n;i++)Nm(this,e[i]);return this.length}unshift(...e){for(var i=0,n=e.length;i<n;i++)km(this,e[i]);return this.length}pop(){if(!this.tail)return;let e=this.tail.value,i=this.tail;return this.tail=this.tail.prev,this.tail?this.tail.next=void 0:this.head=void 0,i.list=void 0,this.length--,e}shift(){if(!this.head)return;let e=this.head.value,i=this.head;return this.head=this.head.next,this.head?this.head.prev=void 0:this.tail=void 0,i.list=void 0,this.length--,e}forEach(e,i){i=i||this;for(let n=this.head,r=0;n;r++)e.call(i,n.value,r,this),n=n.next}forEachReverse(e,i){i=i||this;for(let n=this.tail,r=this.length-1;n;r--)e.call(i,n.value,r,this),n=n.prev}get(e){let i=0,n=this.head;for(;n&&i<e;i++)n=n.next;if(i===e&&n)return n.value}getReverse(e){let i=0,n=this.tail;for(;n&&i<e;i++)n=n.prev;if(i===e&&n)return n.value}map(e,i){i=i||this;let n=new t;for(let r=this.head;r;)n.push(e.call(i,r.value,this)),r=r.next;return n}mapReverse(e,i){i=i||this;var n=new t;for(let r=this.tail;r;)n.push(e.call(i,r.value,this)),r=r.prev;return n}reduce(e,i){let n,r=this.head;if(arguments.length>1)n=i;else if(this.head)r=this.head.next,n=this.head.value;else throw new TypeError("Reduce of empty list with no initial value");for(var o=0;r;o++)n=e(n,r.value,o),r=r.next;return n}reduceReverse(e,i){let n,r=this.tail;if(arguments.length>1)n=i;else if(this.tail)r=this.tail.prev,n=this.tail.value;else throw new TypeError("Reduce of empty list with no initial value");for(let o=this.length-1;r;o--)n=e(n,r.value,o),r=r.prev;return n}toArray(){let e=new Array(this.length);for(let i=0,n=this.head;n;i++)e[i]=n.value,n=n.next;return e}toArrayReverse(){let e=new Array(this.length);for(let i=0,n=this.tail;n;i++)e[i]=n.value,n=n.prev;return e}slice(e=0,i=this.length){i<0&&(i+=this.length),e<0&&(e+=this.length);let n=new t;if(i<e||i<0)return n;e<0&&(e=0),i>this.length&&(i=this.length);let r=this.head,o=0;for(o=0;r&&o<e;o++)r=r.next;for(;r&&o<i;o++,r=r.next)n.push(r.value);return n}sliceReverse(e=0,i=this.length){i<0&&(i+=this.length),e<0&&(e+=this.length);let n=new t;if(i<e||i<0)return n;e<0&&(e=0),i>this.length&&(i=this.length);let r=this.length,o=this.tail;for(;o&&r>i;r--)o=o.prev;for(;o&&r>e;r--,o=o.prev)n.push(o.value);return n}splice(e,i=0,...n){e>this.length&&(e=this.length-1),e<0&&(e=this.length+e);let r=this.head;for(let a=0;r&&a<e;a++)r=r.next;let o=[];for(let a=0;r&&a<i;a++)o.push(r.value),r=this.removeNode(r);r?r!==this.tail&&(r=r.prev):r=this.tail;for(let a of n)r=Vm(this,r,a);return o}reverse(){let e=this.head,i=this.tail;for(let n=e;n;n=n.prev){let r=n.prev;n.prev=n.next,n.next=r}return this.head=i,this.tail=e,this}};function Vm(t,e,i){let n=e,r=e?e.next:t.head,o=new Un(i,n,r,t);return o.next===void 0&&(t.tail=o),o.prev===void 0&&(t.head=o),t.length++,o}function Nm(t,e){t.tail=new Un(e,t.tail,void 0,t),t.head||(t.head=t.tail),t.length++}function km(t,e){t.head=new Un(e,void 0,t.head,t),t.tail||(t.tail=t.head),t.length++}var Un=class{list;next;prev;value;constructor(e,i,n,r){this.list=r,this.value=e,i?(i.next=this,this.prev=i):this.prev=void 0,n?(n.prev=this,this.next=n):this.next=void 0}};import B3 from"path";var fo=class{path;absolute;entry;stat;readdir;pending=!1;ignore=!1;piped=!1;constructor(e,i){this.path=e||"./",this.absolute=i}},F3=Buffer.alloc(1024),Ao=Symbol("onStat"),Kn=Symbol("ended"),We=Symbol("queue"),Qi=Symbol("current"),si=Symbol("process"),Vn=Symbol("processing"),Q3=Symbol("processJob"),Me=Symbol("jobs"),qa=Symbol("jobDone"),uo=Symbol("addFSEntry"),b3=Symbol("addTarEntry"),wa=Symbol("stat"),Ta=Symbol("readdir"),mo=Symbol("onreaddir"),Eo=Symbol("pipe"),J3=Symbol("entry"),ya=Symbol("entryOpt"),po=Symbol("writeEntryClass"),Z3=Symbol("write"),Da=Symbol("ondrain"),Wt=class extends Je{opt;cwd;maxReadSize;preservePaths;strict;noPax;prefix;linkCache;statCache;file;portable;zip;readdirCache;noDirRecurse;follow;noMtime;mtime;filter;jobs;[po];onWriteEntry;[We];[Me]=0;[Vn]=!1;[Kn]=!1;constructor(e={}){if(super(),this.opt=e,this.file=e.file||"",this.cwd=e.cwd||process.cwd(),this.maxReadSize=e.maxReadSize,this.preservePaths=!!e.preservePaths,this.strict=!!e.strict,this.noPax=!!e.noPax,this.prefix=R(e.prefix||""),this.linkCache=e.linkCache||new Map,this.statCache=e.statCache||new Map,this.readdirCache=e.readdirCache||new Map,this.onWriteEntry=e.onWriteEntry,this[po]=On,typeof e.onwarn=="function"&&this.on("warn",e.onwarn),this.portable=!!e.portable,e.gzip||e.brotli||e.zstd){if((e.gzip?1:0)+(e.brotli?1:0)+(e.zstd?1:0)>1)throw new TypeError("gzip, brotli, zstd are mutually exclusive");if(e.gzip&&(typeof e.gzip!="object"&&(e.gzip={}),this.portable&&(e.gzip.portable=!0),this.zip=new kr(e.gzip)),e.brotli&&(typeof e.brotli!="object"&&(e.brotli={}),this.zip=new br(e.brotli)),e.zstd&&(typeof e.zstd!="object"&&(e.zstd={}),this.zip=new Zr(e.zstd)),!this.zip)throw new Error("impossible");let i=this.zip;i.on("data",n=>super.write(n)),i.on("end",()=>super.end()),i.on("drain",()=>this[Da]()),this.on("resume",()=>i.resume())}else this.on("drain",this[Da]);this.noDirRecurse=!!e.noDirRecurse,this.follow=!!e.follow,this.noMtime=!!e.noMtime,e.mtime&&(this.mtime=e.mtime),this.filter=typeof e.filter=="function"?e.filter:()=>!0,this[We]=new vo,this[Me]=0,this.jobs=Number(e.jobs)||4,this[Vn]=!1,this[Kn]=!1}[Z3](e){return super.write(e)}add(e){return this.write(e),this}end(e,i,n){return typeof e=="function"&&(n=e,e=void 0),typeof i=="function"&&(n=i,i=void 0),e&&this.add(e),this[Kn]=!0,this[si](),n&&n(),this}write(e){if(this[Kn])throw new Error("write after end");return e instanceof Ni?this[b3](e):this[uo](e),this.flowing}[b3](e){let i=R(B3.resolve(this.cwd,e.path));if(!this.filter(e.path,e))e.resume();else{let n=new fo(e.path,i);n.entry=new lo(e,this[ya](n)),n.entry.on("end",()=>this[qa](n)),this[Me]+=1,this[We].push(n)}this[si]()}[uo](e){let i=R(B3.resolve(this.cwd,e));this[We].push(new fo(e,i)),this[si]()}[wa](e){e.pending=!0,this[Me]+=1;let i=this.follow?"stat":"lstat";Io[i](e.absolute,(n,r)=>{e.pending=!1,this[Me]-=1,n?this.emit("error",n):this[Ao](e,r)})}[Ao](e,i){this.statCache.set(e.absolute,i),e.stat=i,this.filter(e.path,i)||(e.ignore=!0),this[si]()}[Ta](e){e.pending=!0,this[Me]+=1,Io.readdir(e.absolute,(i,n)=>{if(e.pending=!1,this[Me]-=1,i)return this.emit("error",i);this[mo](e,n)})}[mo](e,i){this.readdirCache.set(e.absolute,i),e.readdir=i,this[si]()}[si](){if(!this[Vn]){this[Vn]=!0;for(let e=this[We].head;e&&this[Me]<this.jobs;e=e.next)if(this[Q3](e.value),e.value.ignore){let i=e.next;this[We].removeNode(e),e.next=i}this[Vn]=!1,this[Kn]&&!this[We].length&&this[Me]===0&&(this.zip?this.zip.end(F3):(super.write(F3),super.end()))}}get[Qi](){return this[We]&&this[We].head&&this[We].head.value}[qa](e){this[We].shift(),this[Me]-=1,this[si]()}[Q3](e){if(!e.pending){if(e.entry){e===this[Qi]&&!e.piped&&this[Eo](e);return}if(!e.stat){let i=this.statCache.get(e.absolute);i?this[Ao](e,i):this[wa](e)}if(e.stat&&!e.ignore){if(!this.noDirRecurse&&e.stat.isDirectory()&&!e.readdir){let i=this.readdirCache.get(e.absolute);if(i?this[mo](e,i):this[Ta](e),!e.readdir)return}if(e.entry=this[J3](e),!e.entry){e.ignore=!0;return}e===this[Qi]&&!e.piped&&this[Eo](e)}}}[ya](e){return{onwarn:(i,n,r)=>this.warn(i,n,r),noPax:this.noPax,cwd:this.cwd,absolute:e.absolute,preservePaths:this.preservePaths,maxReadSize:this.maxReadSize,strict:this.strict,portable:this.portable,linkCache:this.linkCache,statCache:this.statCache,noMtime:this.noMtime,mtime:this.mtime,prefix:this.prefix,onWriteEntry:this.onWriteEntry}}[J3](e){this[Me]+=1;try{return new this[po](e.path,this[ya](e)).on("end",()=>this[qa](e)).on("error",n=>this.emit("error",n))}catch(i){this.emit("error",i)}}[Da](){this[Qi]&&this[Qi].entry&&this[Qi].entry.resume()}[Eo](e){e.piped=!0,e.readdir&&e.readdir.forEach(r=>{let o=e.path,a=o==="./"?"":o.replace(/\/*$/,"/");this[uo](a+r)});let i=e.entry,n=this.zip;if(!i)throw new Error("cannot pipe without source");n?i.on("data",r=>{n.write(r)||i.pause()}):i.on("data",r=>{super.write(r)||i.pause()})}pause(){return this.zip&&this.zip.pause(),super.pause()}warn(e,i,n={}){ti(this,e,i,n)}},ai=class extends Wt{sync=!0;constructor(e){super(e),this[po]=co}pause(){}resume(){}[wa](e){let i=this.follow?"statSync":"lstatSync";this[Ao](e,Io[i](e.absolute))}[Ta](e){this[mo](e,Io.readdirSync(e.absolute))}[Eo](e){let i=e.entry,n=this.zip;if(e.readdir&&e.readdir.forEach(r=>{let o=e.path,a=o==="./"?"":o.replace(/\/*$/,"/");this[uo](a+r)}),!i)throw new Error("Cannot pipe without source");n?i.on("data",r=>{n.write(r)}):i.on("data",r=>{super[Z3](r)})}};var Fm=(t,e)=>{let i=new ai(t),n=new Wi(t.file,{mode:t.mode||438});i.pipe(n),q3(i,e)},Qm=(t,e)=>{let i=new Wt(t),n=new _e(t.file,{mode:t.mode||438});i.pipe(n);let r=new Promise((o,a)=>{n.on("error",a),n.on("close",o),i.on("error",a)});return y3(i,e),r},q3=(t,e)=>{e.forEach(i=>{i.charAt(0)==="@"?oi({file:P3.resolve(t.cwd,i.slice(1)),sync:!0,noResume:!0,onReadEntry:n=>t.add(n)}):t.add(i)}),t.end()},y3=async(t,e)=>{for(let i=0;i<e.length;i++){let n=String(e[i]);n.charAt(0)==="@"?await oi({file:P3.resolve(String(t.cwd),n.slice(1)),noResume:!0,onReadEntry:r=>{t.add(r)}}):t.add(n)}t.end()},bm=(t,e)=>{let i=new ai(t);return q3(i,e),i},Jm=(t,e)=>{let i=new Wt(t);return y3(i,e),i},Bm=Fe(Fm,Qm,bm,Jm,(t,e)=>{if(!e?.length)throw new TypeError("no paths specified to add to archive")});import lv from"node:fs";import rE from"node:assert";import{randomBytes as cv}from"node:crypto";import g from"node:fs";import st from"node:path";import D3 from"fs";var Zm=process.env.__FAKE_PLATFORM__||process.platform,Pm=Zm==="win32",{O_CREAT:qm,O_TRUNC:ym,O_WRONLY:Dm}=D3.constants,w3=Number(process.env.__FAKE_FS_O_FILENAME__)||D3.constants.UV_FS_O_FILEMAP||0,wm=Pm&&!!w3,Tm=512*1024,Xm=w3|ym|qm|Dm,Xa=wm?t=>t<Tm?Xm:"w":()=>"w";import Ro from"node:fs";import Nn from"node:path";var Ha=(t,e,i)=>{try{return Ro.lchownSync(t,e,i)}catch(n){if(n?.code!=="ENOENT")throw n}},ho=(t,e,i,n)=>{Ro.lchown(t,e,i,r=>{n(r&&r?.code!=="ENOENT"?r:null)})},Hm=(t,e,i,n,r)=>{if(e.isDirectory())La(Nn.resolve(t,e.name),i,n,o=>{if(o)return r(o);let a=Nn.resolve(t,e.name);ho(a,i,n,r)});else{let o=Nn.resolve(t,e.name);ho(o,i,n,r)}},La=(t,e,i,n)=>{Ro.readdir(t,{withFileTypes:!0},(r,o)=>{if(r){if(r.code==="ENOENT")return n();if(r.code!=="ENOTDIR"&&r.code!=="ENOTSUP")return n(r)}if(r||!o.length)return ho(t,e,i,n);let a=o.length,c=null,l=v=>{if(!c){if(v)return n(c=v);if(--a===0)return ho(t,e,i,n)}};for(let v of o)Hm(t,v,e,i,l)})},Lm=(t,e,i,n)=>{e.isDirectory()&&_a(Nn.resolve(t,e.name),i,n),Ha(Nn.resolve(t,e.name),i,n)},_a=(t,e,i)=>{let n;try{n=Ro.readdirSync(t,{withFileTypes:!0})}catch(r){let o=r;if(o?.code==="ENOENT")return;if(o?.code==="ENOTDIR"||o?.code==="ENOTSUP")return Ha(t,e,i);throw o}for(let r of n)Lm(t,r,e,i);return Ha(t,e,i)};import oe from"node:fs";import _m from"node:fs/promises";import zo from"node:path";var kn=class extends Error{path;code;syscall="chdir";constructor(e,i){super(`${i}: Cannot cd into '${e}'`),this.path=e,this.code=i}get name(){return"CwdError"}};var Fn=class extends Error{path;symlink;syscall="symlink";code="TAR_SYMLINK_ERROR";constructor(e,i){super("TAR_SYMLINK_ERROR: Cannot extract through symbolic link"),this.symlink=e,this.path=i}get name(){return"SymlinkError"}};var $m=(t,e)=>{oe.stat(t,(i,n)=>{(i||!n.isDirectory())&&(i=new kn(t,i?.code||"ENOTDIR")),e(i)})},T3=(t,e,i)=>{t=R(t);let n=e.umask??18,r=e.mode|448,o=(r&n)!==0,a=e.uid,c=e.gid,l=typeof a=="number"&&typeof c=="number"&&(a!==e.processUid||c!==e.processGid),v=e.preserve,A=e.unlink,u=R(e.cwd),p=(d,z)=>{d?i(d):z&&l?La(z,a,c,C=>p(C)):o?oe.chmod(t,r,i):i()};if(t===u)return $m(t,p);if(v)return _m.mkdir(t,{mode:r,recursive:!0}).then(d=>p(null,d??void 0),p);let f=R(zo.relative(u,t)).split("/");$a(u,f,r,A,u,void 0,p)},$a=(t,e,i,n,r,o,a)=>{if(!e.length)return a(null,o);let c=e.shift(),l=R(zo.resolve(t+"/"+c));oe.mkdir(l,i,X3(l,e,i,n,r,o,a))},X3=(t,e,i,n,r,o,a)=>c=>{c?oe.lstat(t,(l,v)=>{if(l)l.path=l.path&&R(l.path),a(l);else if(v.isDirectory())$a(t,e,i,n,r,o,a);else if(n)oe.unlink(t,A=>{if(A)return a(A);oe.mkdir(t,i,X3(t,e,i,n,r,o,a))});else{if(v.isSymbolicLink())return a(new Fn(t,t+"/"+e.join("/")));a(c)}}):(o=o||t,$a(t,e,i,n,r,o,a))},eE=t=>{let e=!1,i;try{e=oe.statSync(t).isDirectory()}catch(n){i=n?.code}finally{if(!e)throw new kn(t,i??"ENOTDIR")}},H3=(t,e)=>{t=R(t);let i=e.umask??18,n=e.mode|448,r=(n&i)!==0,o=e.uid,a=e.gid,c=typeof o=="number"&&typeof a=="number"&&(o!==e.processUid||a!==e.processGid),l=e.preserve,v=e.unlink,A=R(e.cwd),u=d=>{d&&c&&_a(d,o,a),r&&oe.chmodSync(t,n)};if(t===A)return eE(A),u();if(l)return u(oe.mkdirSync(t,{mode:n,recursive:!0})??void 0);let E=R(zo.relative(A,t)).split("/"),f;for(let d=E.shift(),z=A;d&&(z+="/"+d);d=E.shift()){z=R(zo.resolve(z));try{oe.mkdirSync(z,n),f=f||z}catch{let ve=oe.lstatSync(z);if(ve.isDirectory())continue;if(v){oe.unlinkSync(z),oe.mkdirSync(z,n),f=f||z;continue}else if(ve.isSymbolicLink())return new Fn(z,z+"/"+E.join("/"))}}return u(f)};import{join as $3}from"node:path";var ec=Object.create(null),L3=1e4,bi=new Set,_3=t=>{bi.has(t)?bi.delete(t):ec[t]=t.normalize("NFD"),bi.add(t);let e=ec[t],i=bi.size-L3;if(i>L3/10){for(let n of bi)if(bi.delete(n),delete ec[n],--i<=0)break}return e};var tE=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,iE=tE==="win32",nE=t=>t.split("/").slice(0,-1).reduce((i,n)=>{let r=i[i.length-1];return r!==void 0&&(n=$3(r,n)),i.push(n||"/"),i},[]),go=class{#e=new Map;#n=new Map;#i=new Set;reserve(e,i){e=iE?["win32 parallelization disabled"]:e.map(r=>St($3(_3(r))).toLowerCase());let n=new Set(e.map(r=>nE(r)).reduce((r,o)=>r.concat(o)));this.#n.set(i,{dirs:n,paths:e});for(let r of e){let o=this.#e.get(r);o?o.push(i):this.#e.set(r,[i])}for(let r of n){let o=this.#e.get(r);if(!o)this.#e.set(r,[new Set([i])]);else{let a=o[o.length-1];a instanceof Set?a.add(i):o.push(new Set([i]))}}return this.#a(i)}#r(e){let i=this.#n.get(e);if(!i)throw new Error("function does not have any path reservations");return{paths:i.paths.map(n=>this.#e.get(n)),dirs:[...i.dirs].map(n=>this.#e.get(n))}}check(e){let{paths:i,dirs:n}=this.#r(e);return i.every(r=>r&&r[0]===e)&&n.every(r=>r&&r[0]instanceof Set&&r[0].has(e))}#a(e){return this.#i.has(e)||!this.check(e)?!1:(this.#i.add(e),e(()=>this.#t(e)),!0)}#t(e){if(!this.#i.has(e))return!1;let i=this.#n.get(e);if(!i)throw new Error("invalid reservation");let{paths:n,dirs:r}=i,o=new Set;for(let a of n){let c=this.#e.get(a);if(!c||c?.[0]!==e)continue;let l=c[1];if(!l){this.#e.delete(a);continue}if(c.shift(),typeof l=="function")o.add(l);else for(let v of l)o.add(v)}for(let a of r){let c=this.#e.get(a),l=c?.[0];if(!(!c||!(l instanceof Set)))if(l.size===1&&c.length===1){this.#e.delete(a);continue}else if(l.size===1){c.shift();let v=c[0];typeof v=="function"&&o.add(v)}else l.delete(e)}return this.#i.delete(e),o.forEach(a=>this.#a(a)),!0}};var ev=Symbol("onEntry"),nc=Symbol("checkFs"),tv=Symbol("checkFs2"),rc=Symbol("isReusable"),fe=Symbol("makeFs"),oc=Symbol("file"),sc=Symbol("directory"),Go=Symbol("link"),iv=Symbol("symlink"),nv=Symbol("hardlink"),rv=Symbol("unsupported"),ov=Symbol("checkPath"),Mt=Symbol("mkdir"),H=Symbol("onError"),jo=Symbol("pending"),sv=Symbol("pend"),Ji=Symbol("unpend"),tc=Symbol("ended"),ic=Symbol("maybeClose"),ac=Symbol("skip"),Qn=Symbol("doChown"),bn=Symbol("uid"),Jn=Symbol("gid"),Bn=Symbol("checkedCwd"),oE=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,Zn=oE==="win32",sE=1024,aE=(t,e)=>{if(!Zn)return g.unlink(t,e);let i=t+".DELETE."+cv(16).toString("hex");g.rename(t,i,n=>{if(n)return e(n);g.unlink(i,e)})},cE=t=>{if(!Zn)return g.unlinkSync(t);let e=t+".DELETE."+cv(16).toString("hex");g.renameSync(t,e),g.unlinkSync(e)},av=(t,e,i)=>t!==void 0&&t===t>>>0?t:e!==void 0&&e===e>>>0?e:i,Bi=class extends ot{[tc]=!1;[Bn]=!1;[jo]=0;reservations=new go;transform;writable=!0;readable=!1;uid;gid;setOwner;preserveOwner;processGid;processUid;maxDepth;forceChown;win32;newer;keep;noMtime;preservePaths;unlink;cwd;strip;processUmask;umask;dmode;fmode;chmod;constructor(e={}){if(e.ondone=()=>{this[tc]=!0,this[ic]()},super(e),this.transform=e.transform,this.chmod=!!e.chmod,typeof e.uid=="number"||typeof e.gid=="number"){if(typeof e.uid!="number"||typeof e.gid!="number")throw new TypeError("cannot set owner without number uid and gid");if(e.preserveOwner)throw new TypeError("cannot preserve owner in archive and also set owner explicitly");this.uid=e.uid,this.gid=e.gid,this.setOwner=!0}else this.uid=void 0,this.gid=void 0,this.setOwner=!1;e.preserveOwner===void 0&&typeof e.uid!="number"?this.preserveOwner=!!(process.getuid&&process.getuid()===0):this.preserveOwner=!!e.preserveOwner,this.processUid=(this.preserveOwner||this.setOwner)&&process.getuid?process.getuid():void 0,this.processGid=(this.preserveOwner||this.setOwner)&&process.getgid?process.getgid():void 0,this.maxDepth=typeof e.maxDepth=="number"?e.maxDepth:sE,this.forceChown=e.forceChown===!0,this.win32=!!e.win32||Zn,this.newer=!!e.newer,this.keep=!!e.keep,this.noMtime=!!e.noMtime,this.preservePaths=!!e.preservePaths,this.unlink=!!e.unlink,this.cwd=R(st.resolve(e.cwd||process.cwd())),this.strip=Number(e.strip)||0,this.processUmask=this.chmod?typeof e.processUmask=="number"?e.processUmask:process.umask():0,this.umask=typeof e.umask=="number"?e.umask:this.processUmask,this.dmode=e.dmode||511&~this.umask,this.fmode=e.fmode||438&~this.umask,this.on("entry",i=>this[ev](i))}warn(e,i,n={}){return(e==="TAR_BAD_ARCHIVE"||e==="TAR_ABORT")&&(n.recoverable=!1),super.warn(e,i,n)}[ic](){this[tc]&&this[jo]===0&&(this.emit("prefinish"),this.emit("finish"),this.emit("end"))}[ov](e){let i=R(e.path),n=i.split("/");if(this.strip){if(n.length<this.strip)return!1;if(e.type==="Link"){let r=R(String(e.linkpath)).split("/");if(r.length>=this.strip)e.linkpath=r.slice(this.strip).join("/");else return!1}n.splice(0,this.strip),e.path=n.join("/")}if(isFinite(this.maxDepth)&&n.length>this.maxDepth)return this.warn("TAR_ENTRY_ERROR","path excessively deep",{entry:e,path:i,depth:n.length,maxDepth:this.maxDepth}),!1;if(!this.preservePaths){if(n.includes("..")||Zn&&/^[a-z]:\.\.$/i.test(n[0]??""))return this.warn("TAR_ENTRY_ERROR","path contains '..'",{entry:e,path:i}),!1;let[r,o]=Mn(i);r&&(e.path=String(o),this.warn("TAR_ENTRY_INFO",`stripping ${r} from absolute path`,{entry:e,path:i}))}if(st.isAbsolute(e.path)?e.absolute=R(st.resolve(e.path)):e.absolute=R(st.resolve(this.cwd,e.path)),!this.preservePaths&&typeof e.absolute=="string"&&e.absolute.indexOf(this.cwd+"/")!==0&&e.absolute!==this.cwd)return this.warn("TAR_ENTRY_ERROR","path escaped extraction target",{entry:e,path:R(e.path),resolvedPath:e.absolute,cwd:this.cwd}),!1;if(e.absolute===this.cwd&&e.type!=="Directory"&&e.type!=="GNUDumpDir")return!1;if(this.win32){let{root:r}=st.win32.parse(String(e.absolute));e.absolute=r+Na(String(e.absolute).slice(r.length));let{root:o}=st.win32.parse(e.path);e.path=o+Na(e.path.slice(o.length))}return!0}[ev](e){if(!this[ov](e))return e.resume();switch(rE.equal(typeof e.absolute,"string"),e.type){case"Directory":case"GNUDumpDir":e.mode&&(e.mode=e.mode|448);case"File":case"OldFile":case"ContiguousFile":case"Link":case"SymbolicLink":return this[nc](e);default:return this[rv](e)}}[H](e,i){e.name==="CwdError"?this.emit("error",e):(this.warn("TAR_ENTRY_ERROR",e,{entry:i}),this[Ji](),i.resume())}[Mt](e,i,n){T3(R(e),{uid:this.uid,gid:this.gid,processUid:this.processUid,processGid:this.processGid,umask:this.processUmask,preserve:this.preservePaths,unlink:this.unlink,cwd:this.cwd,mode:i},n)}[Qn](e){return this.forceChown||this.preserveOwner&&(typeof e.uid=="number"&&e.uid!==this.processUid||typeof e.gid=="number"&&e.gid!==this.processGid)||typeof this.uid=="number"&&this.uid!==this.processUid||typeof this.gid=="number"&&this.gid!==this.processGid}[bn](e){return av(this.uid,e.uid,this.processUid)}[Jn](e){return av(this.gid,e.gid,this.processGid)}[oc](e,i){let n=typeof e.mode=="number"?e.mode&4095:this.fmode,r=new _e(String(e.absolute),{flags:Xa(e.size),mode:n,autoClose:!1});r.on("error",l=>{r.fd&&g.close(r.fd,()=>{}),r.write=()=>!0,this[H](l,e),i()});let o=1,a=l=>{if(l){r.fd&&g.close(r.fd,()=>{}),this[H](l,e),i();return}--o===0&&r.fd!==void 0&&g.close(r.fd,v=>{v?this[H](v,e):this[Ji](),i()})};r.on("finish",()=>{let l=String(e.absolute),v=r.fd;if(typeof v=="number"&&e.mtime&&!this.noMtime){o++;let A=e.atime||new Date,u=e.mtime;g.futimes(v,A,u,p=>p?g.utimes(l,A,u,E=>a(E&&p)):a())}if(typeof v=="number"&&this[Qn](e)){o++;let A=this[bn](e),u=this[Jn](e);typeof A=="number"&&typeof u=="number"&&g.fchown(v,A,u,p=>p?g.chown(l,A,u,E=>a(E&&p)):a())}a()});let c=this.transform&&this.transform(e)||e;c!==e&&(c.on("error",l=>{this[H](l,e),i()}),e.pipe(c)),c.pipe(r)}[sc](e,i){let n=typeof e.mode=="number"?e.mode&4095:this.dmode;this[Mt](String(e.absolute),n,r=>{if(r){this[H](r,e),i();return}let o=1,a=()=>{--o===0&&(i(),this[Ji](),e.resume())};e.mtime&&!this.noMtime&&(o++,g.utimes(String(e.absolute),e.atime||new Date,e.mtime,a)),this[Qn](e)&&(o++,g.chown(String(e.absolute),Number(this[bn](e)),Number(this[Jn](e)),a)),a()})}[rv](e){e.unsupported=!0,this.warn("TAR_ENTRY_UNSUPPORTED",`unsupported entry type: ${e.type}`,{entry:e}),e.resume()}[iv](e,i){this[Go](e,String(e.linkpath),"symlink",i)}[nv](e,i){let n=R(st.resolve(this.cwd,String(e.linkpath)));this[Go](e,n,"link",i)}[sv](){this[jo]++}[Ji](){this[jo]--,this[ic]()}[ac](e){this[Ji](),e.resume()}[rc](e,i){return e.type==="File"&&!this.unlink&&i.isFile()&&i.nlink<=1&&!Zn}[nc](e){this[sv]();let i=[e.path];e.linkpath&&i.push(e.linkpath),this.reservations.reserve(i,n=>this[tv](e,n))}[tv](e,i){let n=c=>{i(c)},r=()=>{this[Mt](this.cwd,this.dmode,c=>{if(c){this[H](c,e),n();return}this[Bn]=!0,o()})},o=()=>{if(e.absolute!==this.cwd){let c=R(st.dirname(String(e.absolute)));if(c!==this.cwd)return this[Mt](c,this.dmode,l=>{if(l){this[H](l,e),n();return}a()})}a()},a=()=>{g.lstat(String(e.absolute),(c,l)=>{if(l&&(this.keep||this.newer&&l.mtime>(e.mtime??l.mtime))){this[ac](e),n();return}if(c||this[rc](e,l))return this[fe](null,e,n);if(l.isDirectory()){if(e.type==="Directory"){let v=this.chmod&&e.mode&&(l.mode&4095)!==e.mode,A=u=>this[fe](u??null,e,n);return v?g.chmod(String(e.absolute),Number(e.mode),A):A()}if(e.absolute!==this.cwd)return g.rmdir(String(e.absolute),v=>this[fe](v??null,e,n))}if(e.absolute===this.cwd)return this[fe](null,e,n);aE(String(e.absolute),v=>this[fe](v??null,e,n))})};this[Bn]?o():r()}[fe](e,i,n){if(e){this[H](e,i),n();return}switch(i.type){case"File":case"OldFile":case"ContiguousFile":return this[oc](i,n);case"Link":return this[nv](i,n);case"SymbolicLink":return this[iv](i,n);case"Directory":case"GNUDumpDir":return this[sc](i,n)}}[Go](e,i,n,r){g[n](i,String(e.absolute),o=>{o?this[H](o,e):(this[Ji](),e.resume()),r()})}},xo=t=>{try{return[null,t()]}catch(e){return[e,null]}},Pn=class extends Bi{sync=!0;[fe](e,i){return super[fe](e,i,()=>{})}[nc](e){if(!this[Bn]){let o=this[Mt](this.cwd,this.dmode);if(o)return this[H](o,e);this[Bn]=!0}if(e.absolute!==this.cwd){let o=R(st.dirname(String(e.absolute)));if(o!==this.cwd){let a=this[Mt](o,this.dmode);if(a)return this[H](a,e)}}let[i,n]=xo(()=>g.lstatSync(String(e.absolute)));if(n&&(this.keep||this.newer&&n.mtime>(e.mtime??n.mtime)))return this[ac](e);if(i||this[rc](e,n))return this[fe](null,e);if(n.isDirectory()){if(e.type==="Directory"){let a=this.chmod&&e.mode&&(n.mode&4095)!==e.mode,[c]=a?xo(()=>{g.chmodSync(String(e.absolute),Number(e.mode))}):[];return this[fe](c,e)}let[o]=xo(()=>g.rmdirSync(String(e.absolute)));this[fe](o,e)}let[r]=e.absolute===this.cwd?[]:xo(()=>cE(String(e.absolute)));this[fe](r,e)}[oc](e,i){let n=typeof e.mode=="number"?e.mode&4095:this.fmode,r=c=>{let l;try{g.closeSync(o)}catch(v){l=v}(c||l)&&this[H](c||l,e),i()},o;try{o=g.openSync(String(e.absolute),Xa(e.size),n)}catch(c){return r(c)}let a=this.transform&&this.transform(e)||e;a!==e&&(a.on("error",c=>this[H](c,e)),e.pipe(a)),a.on("data",c=>{try{g.writeSync(o,c,0,c.length)}catch(l){r(l)}}),a.on("end",()=>{let c=null;if(e.mtime&&!this.noMtime){let l=e.atime||new Date,v=e.mtime;try{g.futimesSync(o,l,v)}catch(A){try{g.utimesSync(String(e.absolute),l,v)}catch{c=A}}}if(this[Qn](e)){let l=this[bn](e),v=this[Jn](e);try{g.fchownSync(o,Number(l),Number(v))}catch(A){try{g.chownSync(String(e.absolute),Number(l),Number(v))}catch{c=c||A}}}r(c)})}[sc](e,i){let n=typeof e.mode=="number"?e.mode&4095:this.dmode,r=this[Mt](String(e.absolute),n);if(r){this[H](r,e),i();return}if(e.mtime&&!this.noMtime)try{g.utimesSync(String(e.absolute),e.atime||new Date,e.mtime)}catch{}if(this[Qn](e))try{g.chownSync(String(e.absolute),Number(this[bn](e)),Number(this[Jn](e)))}catch{}i(),e.resume()}[Mt](e,i){try{return H3(R(e),{uid:this.uid,gid:this.gid,processUid:this.processUid,processGid:this.processGid,umask:this.processUmask,preserve:this.preservePaths,unlink:this.unlink,cwd:this.cwd,mode:i})}catch(n){return n}}[Go](e,i,n,r){let o=`${n}Sync`;try{g[o](i,String(e.absolute)),r(),e.resume()}catch(a){return this[H](a,e)}}};var lE=t=>{let e=new Pn(t),i=t.file,n=lv.statSync(i),r=t.maxReadSize||16*1024*1024;new Wr(i,{readSize:r,size:n.size}).pipe(e)},vE=(t,e)=>{let i=new Bi(t),n=t.maxReadSize||16*1024*1024,r=t.file;return new Promise((a,c)=>{i.on("error",c),i.on("close",a),lv.stat(r,(l,v)=>{if(l)c(l);else{let A=new Tt(r,{readSize:n,size:v.size});A.on("error",c),A.pipe(i)}})})},cc=Fe(lE,vE,t=>new Pn(t),t=>new Bi(t),(t,e)=>{e?.length&&Ua(t,e)});import se from"node:fs";import vv from"node:path";var AE=(t,e)=>{let i=new ai(t),n=!0,r,o;try{try{r=se.openSync(t.file,"r+")}catch(l){if(l?.code==="ENOENT")r=se.openSync(t.file,"w+");else throw l}let a=se.fstatSync(r),c=Buffer.alloc(512);e:for(o=0;o<a.size;o+=512){for(let A=0,u=0;A<512;A+=u){if(u=se.readSync(r,c,A,c.length-A,o+A),o===0&&c[0]===31&&c[1]===139)throw new Error("cannot append to compressed archives");if(!u)break e}let l=new ne(c);if(!l.cksumValid)break;let v=512*Math.ceil((l.size||0)/512);if(o+v+512>a.size)break;o+=v,t.mtimeCache&&l.mtime&&t.mtimeCache.set(String(l.path),l.mtime)}n=!1,uE(t,i,o,r,e)}finally{if(n)try{se.closeSync(r)}catch{}}},uE=(t,e,i,n,r)=>{let o=new Wi(t.file,{fd:n,start:i});e.pipe(o),EE(e,r)},mE=(t,e)=>{e=Array.from(e);let i=new Wt(t),n=(o,a,c)=>{let l=(E,f)=>{E?se.close(o,d=>c(E)):c(null,f)},v=0;if(a===0)return l(null,0);let A=0,u=Buffer.alloc(512),p=(E,f)=>{if(E||typeof f>"u")return l(E);if(A+=f,A<512&&f)return se.read(o,u,A,u.length-A,v+A,p);if(v===0&&u[0]===31&&u[1]===139)return l(new Error("cannot append to compressed archives"));if(A<512)return l(null,v);let d=new ne(u);if(!d.cksumValid)return l(null,v);let z=512*Math.ceil((d.size??0)/512);if(v+z+512>a||(v+=z+512,v>=a))return l(null,v);t.mtimeCache&&d.mtime&&t.mtimeCache.set(String(d.path),d.mtime),A=0,se.read(o,u,0,512,v,p)};se.read(o,u,0,512,v,p)};return new Promise((o,a)=>{i.on("error",a);let c="r+",l=(v,A)=>{if(v&&v.code==="ENOENT"&&c==="r+")return c="w+",se.open(t.file,c,l);if(v||!A)return a(v);se.fstat(A,(u,p)=>{if(u)return se.close(A,()=>a(u));n(A,p.size,(E,f)=>{if(E)return a(E);let d=new _e(t.file,{fd:A,start:f});i.pipe(d),d.on("error",a),d.on("close",o),pE(i,e)})})};se.open(t.file,c,l)})},EE=(t,e)=>{e.forEach(i=>{i.charAt(0)==="@"?oi({file:vv.resolve(t.cwd,i.slice(1)),sync:!0,noResume:!0,onReadEntry:n=>t.add(n)}):t.add(i)}),t.end()},pE=async(t,e)=>{for(let i=0;i<e.length;i++){let n=String(e[i]);n.charAt(0)==="@"?await oi({file:vv.resolve(String(t.cwd),n.slice(1)),noResume:!0,onReadEntry:r=>t.add(r)}):t.add(n)}t.end()},ci=Fe(AE,mE,()=>{throw new TypeError("file is required")},()=>{throw new TypeError("file is required")},(t,e)=>{if(!r3(t))throw new TypeError("file is required");if(t.gzip||t.brotli||t.zstd||t.file.endsWith(".br")||t.file.endsWith(".tbr"))throw new TypeError("cannot append to compressed archives");if(!e?.length)throw new TypeError("no paths specified to add/replace")});var IE=Fe(ci.syncFile,ci.asyncFile,ci.syncNoFile,ci.asyncNoFile,(t,e=[])=>{ci.validate?.(t,e),fE(t)}),fE=t=>{let e=t.filter;t.mtimeCache||(t.mtimeCache=new Map),t.filter=e?(i,n)=>e(i,n)&&!((t.mtimeCache?.get(i)??n.mtime??0)>(n.mtime??0)):(i,n)=>!((t.mtimeCache?.get(i)??n.mtime??0)>(n.mtime??0))};async function Zi(t){let{source:e,destination:i,strip:n=1,filter:r}=t,o=[];if(!Av(e))return{success:!1,extractedFiles:[],error:`Source file not found: ${e}`};Av(i)||RE(i,{recursive:!0});try{return await zE(dE(e),gE(),cc({cwd:i,strip:n,filter:a=>r&&!r(a)?!1:(o.push(a),!0)})),{success:!0,extractedFiles:o}}catch(a){return{success:!1,extractedFiles:o,error:a instanceof Error?a.message:String(a)}}}import{existsSync as uv,readFileSync as jE,writeFileSync as xE,mkdirSync as GE}from"fs";import{dirname as SE}from"path";function Ct(t){let e=Ps(t);if(!uv(e))return null;try{let i=jE(e,"utf-8");return JSON.parse(i)}catch{return null}}function So(t,e){let i=Ps(e),n=SE(i);uv(n)||GE(n,{recursive:!0}),xE(i,JSON.stringify(t,null,2))}function mv(t,e,i){return{name:"gemkit",version:t,installedAt:new Date().toISOString(),scope:e,installedFiles:i,customizedFiles:[]}}function Ev(t){return Ct(t)!==null}var I=tr(fv(),1),CE=t=>{let e=parseInt(t.slice(1,3),16),i=parseInt(t.slice(3,5),16),n=parseInt(t.slice(5,7),16);return`\x1B[38;2;${e};${i};${n}m`},qn=t=>e=>I.default.isColorSupported?`${CE(t)}${e}\x1B[39m`:e,s={primary:qn("#4f46e5"),secondary:qn("#9333ea"),accent:qn("#06b6d4"),geminiBlue:qn("#1a73e8"),geminiPurple:qn("#8e24aa"),success:t=>I.default.green(t),error:t=>I.default.red(t),warn:t=>I.default.yellow(t),info:t=>I.default.cyan(t),dim:t=>I.default.dim(t)},M={line:(t=60)=>"\u2500".repeat(t),doubleLine:(t=60)=>"\u2550".repeat(t),statusIcon:t=>{switch(t){case"active":return s.success("\u25CF");case"completed":return s.dim("\u25CB");case"failed":return s.error("\u2717");default:return"?"}},checkIcon:(t,e=!1)=>t?s.success("\u2713"):e?s.warn("\u25CB"):s.error("\u2717"),header:t=>I.default.bold(s.geminiPurple(t)),section:(t,e=60)=>{console.log(),console.log("\u2500".repeat(e)),console.log(I.default.bold(s.geminiPurple(t))),console.log("\u2500".repeat(e)),console.log()}};var Qz={success:s.success,error:s.error,warning:s.warn,info:s.info,dim:s.dim,primary:s.primary,secondary:s.secondary,bold:I.default.bold};var hv={debug:0,info:1,warn:2,error:3,silent:4},he={level:"info",verbose:!1,json:!1};function Mo(t){he={...he,...t}}function yn(t){return hv[t]>=hv[he.level]}function OE(t,e){yn("debug")&&(he.json?console.log(JSON.stringify({level:"debug",message:t,data:e})):(console.log(s.dim(`[DEBUG] ${t}`)),e&&he.verbose&&console.log(s.dim(JSON.stringify(e,null,2)))))}function UE(t,e){yn("info")&&(he.json?console.log(JSON.stringify({level:"info",message:t,data:e})):(console.log(`${s.info("\u2139")} ${t}`),e&&he.verbose&&console.log(JSON.stringify(e,null,2))))}function KE(t,e){yn("info")&&(he.json?console.log(JSON.stringify({level:"success",message:t,data:e})):console.log(`${s.success("\u2713")} ${t}`))}function VE(t,e){yn("warn")&&(he.json?console.log(JSON.stringify({level:"warn",message:t,data:e})):console.log(`${s.warn("\u26A0")} ${t}`))}function NE(t,e){yn("error")&&(he.json?console.error(JSON.stringify({level:"error",message:t,data:e})):(console.error(`${s.error("\u2717")} ${t}`),e&&he.verbose&&console.error(JSON.stringify(e,null,2))))}function kE(t){he.json?console.log(JSON.stringify(t)):console.table(t)}function FE(t){console.log(JSON.stringify(t,null,2))}var m={debug:OE,info:UE,success:KE,warn:VE,error:NE,table:kE,json:FE,configure:Mo};import{spawnSync as ZE}from"child_process";var QE="https://registry.npmjs.org",bE="npm-version",JE=3600;async function Dn(t){let e=`${bE}-${t}`,i=Ir(e);if(i)return i;try{let n=await fetch(`${QE}/${t}/latest`,{headers:{Accept:"application/json","User-Agent":"gemkit-cli"}});if(!n.ok)return null;let r=await n.json(),o={name:r.name,version:r.version,description:r.description,publishedAt:r.time?.[r.version]};return fr(e,o,JE),o}catch{return null}}function BE(t,e){let i=t.replace(/^v/,"").split(".").map(Number),n=e.replace(/^v/,"").split(".").map(Number);for(let r=0;r<Math.max(i.length,n.length);r++){let o=i[r]||0,a=n[r]||0;if(o>a)return 1;if(o<a)return-1}return 0}function Pi(t,e){return BE(e,t)>0}import{readFileSync as PE}from"fs";import{join as dv,dirname as qE}from"path";import{fileURLToPath as yE}from"url";var wn="gemkit-cli";function DE(){try{let t=yE(import.meta.url),e=qE(t),i=[dv(e,"..","package.json"),dv(e,"..","..","..","package.json")];for(let n of i)try{let r=JSON.parse(PE(n,"utf-8"));if(r.name===wn&&r.version)return r.version}catch{}}catch{}return"0.0.0"}var de=DE();function Rv(t){t.command("update","Update GemKit CLI and/or Kits to latest version").option("-f, --force","Force update even if already up to date").option("--no-backup","Disable backup before kits update").option("--cli","Update CLI only (npm package)").option("--kits","Update Kits only (.gemini folder)").action(async e=>{let i=e.cli===!0||!e.cli&&!e.kits,n=e.kits===!0||!e.cli&&!e.kits,r=!1,o=!1;i&&(r=await wE(e.force)),n&&(o=await TE(e.force)),console.log(),r||o?m.success("Update complete!"):m.info("Everything is up to date.")})}async function wE(t){console.log(),m.info(`${s.primary("CLI")} Checking for updates...`);let e=await Dn(wn);if(!e)return m.warn("Failed to check npm registry for CLI updates."),!1;let i=de,n=e.version;return!Pi(i,n)&&!t?(m.success(`CLI is up to date (v${i})`),!1):(m.info(`Updating CLI: v${i} \u2192 v${n}`),ZE("npm",["install","-g",`${wn}@latest`],{encoding:"utf-8",stdio:"inherit",shell:!0}).status!==0?(m.error("CLI update failed. Try running manually:"),m.info(` npm install -g ${wn}@latest`),!1):(m.success(`CLI updated to v${n}`),!0))}async function TE(t){console.log(),m.info(`${s.primary("Kits")} Checking for updates...`);let e=Ct();if(!e)return m.warn('GemKit not initialized. Run "gk init" first to install kits.'),!1;let i=await qt();if(!i)return m.warn("Failed to check GitHub for kits updates."),!1;if(i.version===e.version&&!t)return m.success(`Kits are up to date (v${e.version})`),!1;m.info(`Updating Kits: v${e.version} \u2192 v${i.version}`);let n=await zi(i),r=Er(),o=await Zi({source:n,destination:r,strip:1});if(!o.success)return m.error(`Kits update failed: ${o.error}`),!1;let a={...e,version:i.version,installedAt:new Date().toISOString(),installedFiles:o.extractedFiles};return So(a),m.success(`Kits updated to v${i.version}`),!0}async function zv(){let t={cli:null,kits:null};try{let e=await Dn(wn);e&&(t.cli={current:de,latest:e.version,available:Pi(de,e.version)})}catch{}try{let e=Ct(),i=await qt();e&&i&&(t.kits={current:e.version,latest:i.version,available:Pi(e.version,i.version)})}catch{}return t}var gv="gemkit-cli";function $E(t){return _E("npm",["install","-g",`${gv}@${t}`],{encoding:"utf-8",stdio:"pipe",shell:!0}).status===0}function ep(t){switch(t){case"gemini":return[".claude",".claude/**",".agent",".agent/**"];case"claude":return[".agent",".agent/**"];case"antigravity":return[".claude",".claude/**"];default:return[]}}function tp(t){switch(t){case"gemini":return"Gemini CLI (excludes .claude, .agent)";case"claude":return"Claude Code (excludes .agent)";case"antigravity":return"Antigravity (excludes .claude)";default:return"Full (all files)"}}function ip(t,e){let i=t.replace(/\\/g,"/");for(let n of e)if(n.includes("*")){if(n.endsWith("/**")){let r=n.slice(0,-3);if(i.startsWith(r+"/"))return!0}}else if(i===n||i.startsWith(n+"/"))return!0;return!1}function np(t){if(t.length!==0)return e=>!ip(e,t)}async function rp(){let t=HE(".gemini","extensions","spawn-agent");return XE(t)?new Promise(e=>{let i=LE("gemini",["extensions","install",t],{stdio:["pipe","pipe","pipe"],shell:process.platform==="win32",cwd:process.cwd()}),n="",r="",o=!1,a=setTimeout(()=>{o||(o=!0,i.kill(),e({success:!1,error:"Extension installation timed out"}))},3e4);i.stdout?.on("data",c=>{n+=c.toString()}),i.stderr?.on("data",c=>{r+=c.toString()}),i.on("close",c=>{o||(o=!0,clearTimeout(a),e(c===0?{success:!0}:{success:!1,error:r||n||`Exit code: ${c}`}))}),i.on("error",c=>{o||(o=!0,clearTimeout(a),e({success:!1,error:`Failed to run gemini CLI: ${c.message}`}))})}):{success:!1,error:`Extension directory not found: ${t}`}}function jv(t){t.command("init","Initialize GemKit in project").option("--version <ver>","Specific version to install").option("-f, --force","Overwrite existing installation").option("--exclude <patterns...>","File patterns to exclude").option("--skip-extension","Skip spawn-agent extension installation").option("--full","Install all files (default)").option("--gemini","Gemini CLI mode (excludes .claude, .agent folders)").option("--claude","Claude Code mode (excludes .agent folder)").option("--antigravity","Antigravity mode (excludes .claude folder)").action(async e=>{let i="full";if(e.gemini?i="gemini":e.claude?i="claude":e.antigravity?i="antigravity":e.full&&(i="full"),Ev()&&!e.force){console.log(),m.warn("GemKit is already installed. Use --force to reinstall."),console.log();return}console.log(),console.log(I.default.bold(s.geminiPurple("Initializing GemKit"))),console.log(),console.log(` ${s.dim("Mode")} ${s.accent(tp(i))}`),console.log();let n=Ke({text:"Checking CLI version...",color:"magenta"}).start();try{let f=await Dn(gv);f&&Pi(de,f.version)?(n.text=`Updating CLI v${de} \u2192 v${f.version}...`,$E(f.version)?n.succeed(`CLI updated v${s.primary(de)} \u2192 v${s.primary(f.version)}`):n.warn(`CLI v${s.primary(de)} (update to v${f.version} failed)`)):n.succeed(`CLI v${s.primary(de)}`)}catch{n.succeed(`CLI v${s.primary(de)}`)}let r=Ke({text:"Fetching latest Kits release...",color:"magenta"}).start(),o=e.version?await Tl(e.version):await qt();o||(r.fail("No Kits release found"),console.log(),process.exit(1)),r.succeed(`Found Kits v${s.primary(o.version)}`);let a=Ke({text:"Downloading Kits...",color:"magenta"}).start(),c;try{c=await zi(o),a.succeed("Kits downloaded")}catch(f){a.fail(`Kits download failed: ${f instanceof Error?f.message:String(f)}`),console.log(),process.exit(1)}let l=ep(i),v=Ke({text:i==="full"?"Extracting Kits...":`Extracting Kits (${i} mode)...`,color:"magenta"}).start(),A=process.cwd(),u=await Zi({source:c,destination:A,strip:1,filter:np(l)});u.success||(v.fail(`Kits extraction failed: ${u.error}`),console.log(),process.exit(1)),v.succeed(`Extracted ${u.extractedFiles.length} files`);let p=mv(o.version,"local",u.extractedFiles);if(So(p),console.log(),m.success(`Kits v${s.primary(o.version)} installed successfully!`),!e.skipExtension&&(i==="full"||i==="gemini")){console.log();let f=Ke({text:"Installing spawn-agent extension...",color:"magenta"}).start(),d=await rp();d.success?f.succeed("spawn-agent extension installed in Gemini CLI"):(f.warn(`Could not install spawn-agent extension: ${d.error}`),m.info(`You can manually install it with: ${s.primary("gemini extensions install .gemini/extensions/spawn-agent")}`))}else(i==="claude"||i==="antigravity")&&(console.log(),m.info(`Skipped Gemini extension (${i} mode).`));console.log(),m.info(`Run ${s.primary("gk doctor")} to verify installation.`),console.log()})}function xv(t){t.command("versions","List available GemKit versions").alias("v").option("--json","Output as JSON").action(async e=>{let i=Ct(),n=await hr();if(e.json){console.log(JSON.stringify({current:i?.version||null,available:n},null,2));return}console.log(),console.log(I.default.bold(s.geminiPurple("GemKit Versions"))),console.log(),console.log(i?` ${s.dim("Current:")} ${s.success(i.version)}`:` ${s.dim("Current:")} ${s.dim("Not installed")}`),console.log(),console.log(` ${I.default.bold("Available Releases:")}`);for(let r of n){let o=r.version===i?.version?s.success(" (current)"):"";console.log(` - ${s.primary(r.version)}${o}`)}console.log()})}import{existsSync as Co}from"fs";import{join as op}from"path";import{spawn as Gv}from"child_process";async function sp(){return new Promise(t=>{let e=Gv("gemini",["extensions","list"],{stdio:["pipe","pipe","pipe"],shell:process.platform==="win32"}),i="",n="",r=!1,o=setTimeout(()=>{r||(r=!0,e.kill(),t({installed:!1,error:"Check timed out"}))},2e4);e.stdout?.on("data",a=>{i+=a.toString()}),e.stderr?.on("data",a=>{n+=a.toString()}),e.on("close",a=>{if(!r)if(r=!0,clearTimeout(o),a===0){let c=i.toLowerCase().includes("spawn-agent");t({installed:c})}else t({installed:!1,error:n||"Failed to check extensions"})}),e.on("error",a=>{r||(r=!0,clearTimeout(o),t({installed:!1,error:`Gemini CLI not available: ${a.message}`}))})})}async function ap(){return new Promise(t=>{let e=Gv("gemini",["--version"],{stdio:["pipe","pipe","pipe"],shell:process.platform==="win32"}),i="",n=!1,r=setTimeout(()=>{n||(n=!0,e.kill(),t({available:!1,error:"Timed out"}))},15e3);e.stdout?.on("data",o=>{i+=o.toString()}),e.on("close",o=>{if(!n)if(n=!0,clearTimeout(r),o===0){let a=i.trim().split(`
20
- `)[0]||"unknown";t({available:!0,version:a})}else t({available:!1,error:"Command failed"})}),e.on("error",o=>{n||(n=!0,clearTimeout(r),t({available:!1,error:o.message}))})})}function Sv(t){t.command("doctor","Check installation health").option("--fix","Attempt to fix issues").action(async e=>{console.log(),console.log(I.default.bold(s.geminiPurple("GemKit Health Check"))),console.log();let i=0,n=0,r=[],o=process.version;parseInt(o.slice(1).split(".")[0],10)>=18?r.push({icon:s.success("\u2713"),message:`Node.js ${o}`}):(r.push({icon:s.error("\u2717"),message:`Node.js ${o} ${s.error("(requires >= 18)")}`}),i++);let c=Ke({text:"Checking Gemini CLI...",color:"magenta"}).start(),l=await ap();c.stop(),l.available?r.push({icon:s.success("\u2713"),message:`Gemini CLI ${s.dim(`(${l.version})`)}`}):(r.push({icon:s.error("\u2717"),message:`Gemini CLI not found ${s.dim(`(${l.error})`)}`}),i++);let v=Er();Co(v)?r.push({icon:s.success("\u2713"),message:".gemini directory exists"}):(r.push({icon:s.error("\u2717"),message:".gemini directory missing"}),i++);let A=on();Co(A)?r.push({icon:s.success("\u2713"),message:"Agents directory exists"}):(r.push({icon:s.warn("\u25CB"),message:"Agents directory missing"}),n++);let u=Bt();Co(u)?r.push({icon:s.success("\u2713"),message:"Extensions directory exists"}):(r.push({icon:s.warn("\u25CB"),message:"Extensions directory missing"}),n++);let p=op(u,"spawn-agent");if(Co(p)?r.push({icon:s.success("\u2713"),message:"spawn-agent extension files present"}):(r.push({icon:s.warn("\u25CB"),message:"spawn-agent extension files missing"}),n++),l.available){let f=Ke({text:"Checking spawn-agent extension...",color:"magenta"}).start(),d=await sp();f.stop(),d.installed?r.push({icon:s.success("\u2713"),message:"spawn-agent extension installed in Gemini"}):(r.push({icon:s.error("\u2717"),message:"spawn-agent extension NOT installed in Gemini",hint:d.error?`${d.error}
21
- Run: gemini extensions install .gemini/extensions/spawn-agent`:"Run: gemini extensions install .gemini/extensions/spawn-agent"}),i++)}let E=Ct();E?r.push({icon:s.success("\u2713"),message:`Installation metadata ${s.primary(`(v${E.version})`)}`}):(r.push({icon:s.warn("\u25CB"),message:"Installation metadata missing"}),n++);for(let f of r)if(console.log(` ${f.icon} ${f.message}`),f.hint)for(let d of f.hint.split(`
22
- `))console.log(` ${s.dim(d)}`);console.log(),i===0&&n===0?console.log(s.success("All checks passed!")):i===0?console.log(s.success(`All critical checks passed! ${s.dim(`(${n} warning${n>1?"s":""})`)}`)):(console.log(s.error(`${i} issue(s) found.`)),n>0&&console.log(s.warn(`${n} warning(s).`)),console.log(),console.log("To fix issues:"),console.log(` ${s.dim("1.")} Run ${s.primary("gk init")} to install GemKit`),console.log(` ${s.dim("2.")} Run ${s.primary("gemini extensions install .gemini/extensions/spawn-agent")} to install extension`)),console.log()})}function cp(){console.log(),console.log(I.default.bold(s.geminiPurple("Configuration Management"))),console.log(),console.log("Usage:"),console.log(` ${s.primary("gk config")} <subcommand> [options]`),console.log(),console.log("Subcommands:"),console.log(` ${s.primary("list")} Show all config (default)`),console.log(` ${s.primary("get")} <key> Get config value`),console.log(` ${s.primary("set")} <key> <val> Set config value`),console.log(` ${s.primary("reset")} Reset to defaults`),console.log(),console.log("Options:"),console.log(` ${s.dim("--json")} [list] Output as JSON`),console.log(),console.log("Examples:"),console.log(` ${s.dim("gk config list")}`),console.log(` ${s.dim("gk config get spawn.defaultModel")}`),console.log(` ${s.dim("gk config set spawn.music true")}`),console.log(` ${s.dim("gk config reset")}`),console.log()}function Yv(t){t.command("config [subcommand] [key] [value]","Configuration management (list, get, set, reset)").alias("c").option("--json","[list] Output as JSON").action(async(e,i,n,r)=>{switch(e||"list"){case"list":await lp(r);break;case"get":i||(console.log(),m.error("Config key required"),console.log(s.dim("Usage: gk config get <key>")),console.log(),process.exit(1)),await vp(i);break;case"set":(!i||n===void 0)&&(console.log(),m.error("Config key and value required"),console.log(s.dim("Usage: gk config set <key> <value>")),console.log(),process.exit(1)),await Ap(i,n);break;case"reset":await up();break;default:cp()}})}async function lp(t){let e=Ve();if(t.json){console.log(JSON.stringify(e,null,2));return}console.log(),console.log(I.default.bold(s.geminiPurple("GemKit Configuration"))),console.log(),console.log(JSON.stringify(e,null,2)),console.log()}async function vp(t){let e=Ql(t);if(e===void 0){console.log(),m.error(`Config key not found: ${t}`),console.log();return}console.log(e)}async function Ap(t,e){let i=e;e==="true"?i=!0:e==="false"?i=!1:isNaN(Number(e))||(i=Number(e));try{bl(t,i),console.log(),m.success(`Config updated: ${s.primary(t)} = ${s.success(String(i))}`),console.log()}catch(n){console.log(),m.error(`Failed to set config: ${n instanceof Error?n.message:String(n)}`),console.log()}}async function up(){Jl(),console.log(),m.success("Configuration reset to defaults."),console.log()}function Wv(t){let e=t.command("cache <subcommand>","Cache management");e.example("gk cache stats # Show cache statistics"),e.example("gk cache clear # Clear all cache"),e.action(async i=>{let n=i||"stats";switch(n){case"stats":await mp();break;case"clear":await Ep();break;default:console.log(),m.error(`Unknown subcommand: ${n}`),console.log(),process.exit(1)}})}async function mp(){let t=Dl();console.log(),console.log(I.default.bold(s.geminiPurple("Cache Statistics"))),console.log(),console.log(` ${s.dim("Entries:")} ${s.primary(String(t.entries))}`),console.log(` ${s.dim("Size:")} ${s.primary((t.size/1024).toFixed(2))} KB`),console.log()}async function Ep(){let t=yl();console.log(),m.success(`Cleared ${s.success(String(t))} cache entries.`),console.log()}import{existsSync as pp}from"fs";import{join as Ip}from"path";function Mv(t){t.command("new <name>","Create a new project from starter kit").action(async e=>{let i=Ip(process.cwd(),e);pp(i)&&(console.log(),m.error(`Directory already exists: ${e}`),console.log(),process.exit(1)),console.log(),console.log(I.default.bold(s.geminiPurple("Creating New Project"))),console.log(),m.info(`Name: ${s.primary(e)}`);let n=await qt();n||(m.error("Failed to fetch latest starter kit."),console.log(),process.exit(1)),m.info(`Fetching latest starter kit (v${n.version})...`);let r=await zi(n),o=await Zi({source:r,destination:i,strip:1});o.success?(console.log(),m.success(`Project ${s.primary(e)} created successfully!`),console.log(`
40
+ `)+i,s=n+1,n=t.indexOf(`
41
+ `,s)}while(n!==-1);return r+=t.slice(s),r}var{stdout:gm,stderr:Im}=dm,nc=Symbol("GENERATOR"),an=Symbol("STYLER"),is=Symbol("IS_EMPTY"),Em=["ansi","ansi","ansi256","ansi16m"],cn=Object.create(null),vd=(t,e={})=>{if(e.level&&!(Number.isInteger(e.level)&&e.level>=0&&e.level<=3))throw new Error("The `level` option should be an integer from 0 to 3");let i=gm?gm.level:0;t.level=e.level===void 0?i:e.level};var pd=t=>{let e=(...i)=>i.join(" ");return vd(e,t),Object.setPrototypeOf(e,ns.prototype),e};function ns(t){return pd(t)}Object.setPrototypeOf(ns.prototype,Function.prototype);for(let[t,e]of Object.entries(ye))cn[t]={get(){let i=Ir(this,rc(e.open,e.close,this[an]),this[is]);return Object.defineProperty(this,t,{value:i}),i}};cn.visible={get(){let t=Ir(this,this[an],!0);return Object.defineProperty(this,"visible",{value:t}),t}};var sc=(t,e,i,...n)=>t==="rgb"?e==="ansi16m"?ye[i].ansi16m(...n):e==="ansi256"?ye[i].ansi256(ye.rgbToAnsi256(...n)):ye[i].ansi(ye.rgbToAnsi(...n)):t==="hex"?sc("rgb",e,i,...ye.hexToRgb(...n)):ye[i][t](...n),Ad=["rgb","hex","ansi256"];for(let t of Ad){cn[t]={get(){let{level:i}=this;return function(...n){let s=rc(sc(t,Em[i],"color",...n),ye.color.close,this[an]);return Ir(this,s,this[is])}}};let e="bg"+t[0].toUpperCase()+t.slice(1);cn[e]={get(){let{level:i}=this;return function(...n){let s=rc(sc(t,Em[i],"bgColor",...n),ye.bgColor.close,this[an]);return Ir(this,s,this[is])}}}}var dd=Object.defineProperties(()=>{},{...cn,level:{enumerable:!0,get(){return this[nc].level},set(t){this[nc].level=t}}}),rc=(t,e,i)=>{let n,s;return i===void 0?(n=t,s=e):(n=i.openAll+t,s=e+i.closeAll),{open:t,close:e,openAll:n,closeAll:s,parent:i}},Ir=(t,e,i)=>{let n=(...s)=>fd(n,s.length===1?""+s[0]:s.join(" "));return Object.setPrototypeOf(n,dd),n[nc]=t,n[an]=e,n[is]=i,n},fd=(t,e)=>{if(t.level<=0||!e)return t[is]?"":e;let i=t[an];if(i===void 0)return e;let{openAll:n,closeAll:s}=i;if(e.includes("\x1B"))for(;i!==void 0;)e=fm(e,i.close,i.open),i=i.parent;let r=e.indexOf(`
42
+ `);return r!==-1&&(e=hm(e,s,n,r)),n+e+s};Object.defineProperties(ns.prototype,cn);var hd=ns(),FR=ns({level:Im?Im.level:0});var qe=hd;import Gm from"node:process";import jr from"node:process";var gd=(t,e,i,n)=>{if(i==="length"||i==="prototype"||i==="arguments"||i==="caller")return;let s=Object.getOwnPropertyDescriptor(t,i),r=Object.getOwnPropertyDescriptor(e,i);!Id(s,r)&&n||Object.defineProperty(t,i,r)},Id=function(t,e){return t===void 0||t.configurable||t.writable===e.writable&&t.enumerable===e.enumerable&&t.configurable===e.configurable&&(t.writable||t.value===e.value)},Ed=(t,e)=>{let i=Object.getPrototypeOf(e);i!==Object.getPrototypeOf(t)&&Object.setPrototypeOf(t,i)},Rd=(t,e)=>`/* Wrapped ${t}*/
43
+ ${e}`,zd=Object.getOwnPropertyDescriptor(Function.prototype,"toString"),jd=Object.getOwnPropertyDescriptor(Function.prototype.toString,"name"),xd=(t,e,i)=>{let n=i===""?"":`with ${i.trim()}() `,s=Rd.bind(null,n,e.toString());Object.defineProperty(s,"name",jd);let{writable:r,enumerable:o,configurable:c}=zd;Object.defineProperty(t,"toString",{value:s,writable:r,enumerable:o,configurable:c})};function oc(t,e,{ignoreNonConfigurable:i=!1}={}){let{name:n}=t;for(let s of Reflect.ownKeys(e))gd(t,e,s,i);return Ed(t,e),xd(t,e,n),t}var Er=new WeakMap,Rm=(t,e={})=>{if(typeof t!="function")throw new TypeError("Expected a function");let i,n=0,s=t.displayName||t.name||"<anonymous>",r=function(...o){if(Er.set(r,++n),n===1)i=t.apply(this,o),t=void 0;else if(e.throw===!0)throw new Error(`Function \`${s}\` can only be called once`);return i};return oc(r,t),Er.set(r,n),r};Rm.callCount=t=>{if(!Er.has(t))throw new Error(`The given function \`${t.name}\` is not wrapped by the \`onetime\` package`);return Er.get(t)};var zm=Rm;var Yi=[];Yi.push("SIGHUP","SIGINT","SIGTERM");process.platform!=="win32"&&Yi.push("SIGALRM","SIGABRT","SIGVTALRM","SIGXCPU","SIGXFSZ","SIGUSR2","SIGTRAP","SIGSYS","SIGQUIT","SIGIOT");process.platform==="linux"&&Yi.push("SIGIO","SIGPOLL","SIGPWR","SIGSTKFLT");var Rr=t=>!!t&&typeof t=="object"&&typeof t.removeListener=="function"&&typeof t.emit=="function"&&typeof t.reallyExit=="function"&&typeof t.listeners=="function"&&typeof t.kill=="function"&&typeof t.pid=="number"&&typeof t.on=="function",ac=Symbol.for("signal-exit emitter"),cc=globalThis,Sd=Object.defineProperty.bind(Object),lc=class{emitted={afterExit:!1,exit:!1};listeners={afterExit:[],exit:[]};count=0;id=Math.random();constructor(){if(cc[ac])return cc[ac];Sd(cc,ac,{value:this,writable:!1,enumerable:!1,configurable:!1})}on(e,i){this.listeners[e].push(i)}removeListener(e,i){let n=this.listeners[e],s=n.indexOf(i);s!==-1&&(s===0&&n.length===1?n.length=0:n.splice(s,1))}emit(e,i,n){if(this.emitted[e])return!1;this.emitted[e]=!0;let s=!1;for(let r of this.listeners[e])s=r(i,n)===!0||s;return e==="exit"&&(s=this.emit("afterExit",i,n)||s),s}},zr=class{},Gd=t=>({onExit(e,i){return t.onExit(e,i)},load(){return t.load()},unload(){return t.unload()}}),uc=class extends zr{onExit(){return()=>{}}load(){}unload(){}},mc=class extends zr{#e=vc.platform==="win32"?"SIGINT":"SIGHUP";#n=new lc;#i;#s;#a;#t={};#r=!1;constructor(e){super(),this.#i=e,this.#t={};for(let i of Yi)this.#t[i]=()=>{let n=this.#i.listeners(i),{count:s}=this.#n,r=e;if(typeof r.__signal_exit_emitter__=="object"&&typeof r.__signal_exit_emitter__.count=="number"&&(s+=r.__signal_exit_emitter__.count),n.length===s){this.unload();let o=this.#n.emit("exit",null,i),c=i==="SIGHUP"?this.#e:i;o||e.kill(e.pid,c)}};this.#a=e.reallyExit,this.#s=e.emit}onExit(e,i){if(!Rr(this.#i))return()=>{};this.#r===!1&&this.load();let n=i?.alwaysLast?"afterExit":"exit";return this.#n.on(n,e),()=>{this.#n.removeListener(n,e),this.#n.listeners.exit.length===0&&this.#n.listeners.afterExit.length===0&&this.unload()}}load(){if(!this.#r){this.#r=!0,this.#n.count+=1;for(let e of Yi)try{let i=this.#t[e];i&&this.#i.on(e,i)}catch{}this.#i.emit=(e,...i)=>this.#p(e,...i),this.#i.reallyExit=e=>this.#o(e)}}unload(){this.#r&&(this.#r=!1,Yi.forEach(e=>{let i=this.#t[e];if(!i)throw new Error("Listener not defined for signal: "+e);try{this.#i.removeListener(e,i)}catch{}}),this.#i.emit=this.#s,this.#i.reallyExit=this.#a,this.#n.count-=1)}#o(e){return Rr(this.#i)?(this.#i.exitCode=e||0,this.#n.emit("exit",this.#i.exitCode,null),this.#a.call(this.#i,this.#i.exitCode)):0}#p(e,...i){let n=this.#s;if(e==="exit"&&Rr(this.#i)){typeof i[0]=="number"&&(this.#i.exitCode=i[0]);let s=n.call(this.#i,e,...i);return this.#n.emit("exit",this.#i.exitCode,null),s}else return n.call(this.#i,e,...i)}},vc=globalThis.process,{onExit:jm,load:yR,unload:qR}=Gd(Rr(vc)?new mc(vc):new uc);var xm=jr.stderr.isTTY?jr.stderr:jr.stdout.isTTY?jr.stdout:void 0,Md=xm?zm(()=>{jm(()=>{xm.write("\x1B[?25h")},{alwaysLast:!0})}):()=>{},Sm=Md;var xr=!1,ln={};ln.show=(t=Gm.stderr)=>{t.isTTY&&(xr=!1,t.write("\x1B[?25h"))};ln.hide=(t=Gm.stderr)=>{t.isTTY&&(Sm(),xr=!0,t.write("\x1B[?25l"))};ln.toggle=(t,e)=>{t!==void 0&&(xr=t),xr?ln.show(e):ln.hide(e)};var pc=ln;var os=Ar(Ac(),1);import we from"node:process";function dc(){return we.platform!=="win32"?we.env.TERM!=="linux":!!we.env.CI||!!we.env.WT_SESSION||!!we.env.TERMINUS_SUBLIME||we.env.ConEmuTask==="{cmd::Cmder}"||we.env.TERM_PROGRAM==="Terminus-Sublime"||we.env.TERM_PROGRAM==="vscode"||we.env.TERM==="xterm-256color"||we.env.TERM==="alacritty"||we.env.TERMINAL_EMULATOR==="JetBrains-JediTerm"}var Wd={info:qe.blue("\u2139"),success:qe.green("\u2714"),warning:qe.yellow("\u26A0"),error:qe.red("\u2716")},Cd={info:qe.blue("i"),success:qe.green("\u221A"),warning:qe.yellow("\u203C"),error:qe.red("\xD7")},Od=dc()?Wd:Cd,ss=Od;function fc({onlyFirst:t=!1}={}){let s="(?:\\u001B\\][\\s\\S]*?(?:\\u0007|\\u001B\\u005C|\\u009C))|[\\u001B\\u009B][[\\]()#;?]*(?:\\d{1,4}(?:[;:]\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]";return new RegExp(s,t?void 0:"g")}var Ud=fc();function rs(t){if(typeof t!="string")throw new TypeError(`Expected a \`string\`, got \`${typeof t}\``);return t.replace(Ud,"")}function Cm(t){return t===161||t===164||t===167||t===168||t===170||t===173||t===174||t>=176&&t<=180||t>=182&&t<=186||t>=188&&t<=191||t===198||t===208||t===215||t===216||t>=222&&t<=225||t===230||t>=232&&t<=234||t===236||t===237||t===240||t===242||t===243||t>=247&&t<=250||t===252||t===254||t===257||t===273||t===275||t===283||t===294||t===295||t===299||t>=305&&t<=307||t===312||t>=319&&t<=322||t===324||t>=328&&t<=331||t===333||t===338||t===339||t===358||t===359||t===363||t===462||t===464||t===466||t===468||t===470||t===472||t===474||t===476||t===593||t===609||t===708||t===711||t>=713&&t<=715||t===717||t===720||t>=728&&t<=731||t===733||t===735||t>=768&&t<=879||t>=913&&t<=929||t>=931&&t<=937||t>=945&&t<=961||t>=963&&t<=969||t===1025||t>=1040&&t<=1103||t===1105||t===8208||t>=8211&&t<=8214||t===8216||t===8217||t===8220||t===8221||t>=8224&&t<=8226||t>=8228&&t<=8231||t===8240||t===8242||t===8243||t===8245||t===8251||t===8254||t===8308||t===8319||t>=8321&&t<=8324||t===8364||t===8451||t===8453||t===8457||t===8467||t===8470||t===8481||t===8482||t===8486||t===8491||t===8531||t===8532||t>=8539&&t<=8542||t>=8544&&t<=8555||t>=8560&&t<=8569||t===8585||t>=8592&&t<=8601||t===8632||t===8633||t===8658||t===8660||t===8679||t===8704||t===8706||t===8707||t===8711||t===8712||t===8715||t===8719||t===8721||t===8725||t===8730||t>=8733&&t<=8736||t===8739||t===8741||t>=8743&&t<=8748||t===8750||t>=8756&&t<=8759||t===8764||t===8765||t===8776||t===8780||t===8786||t===8800||t===8801||t>=8804&&t<=8807||t===8810||t===8811||t===8814||t===8815||t===8834||t===8835||t===8838||t===8839||t===8853||t===8857||t===8869||t===8895||t===8978||t>=9312&&t<=9449||t>=9451&&t<=9547||t>=9552&&t<=9587||t>=9600&&t<=9615||t>=9618&&t<=9621||t===9632||t===9633||t>=9635&&t<=9641||t===9650||t===9651||t===9654||t===9655||t===9660||t===9661||t===9664||t===9665||t>=9670&&t<=9672||t===9675||t>=9678&&t<=9681||t>=9698&&t<=9701||t===9711||t===9733||t===9734||t===9737||t===9742||t===9743||t===9756||t===9758||t===9792||t===9794||t===9824||t===9825||t>=9827&&t<=9829||t>=9831&&t<=9834||t===9836||t===9837||t===9839||t===9886||t===9887||t===9919||t>=9926&&t<=9933||t>=9935&&t<=9939||t>=9941&&t<=9953||t===9955||t===9960||t===9961||t>=9963&&t<=9969||t===9972||t>=9974&&t<=9977||t===9979||t===9980||t===9982||t===9983||t===10045||t>=10102&&t<=10111||t>=11094&&t<=11097||t>=12872&&t<=12879||t>=57344&&t<=63743||t>=65024&&t<=65039||t===65533||t>=127232&&t<=127242||t>=127248&&t<=127277||t>=127280&&t<=127337||t>=127344&&t<=127373||t===127375||t===127376||t>=127387&&t<=127404||t>=917760&&t<=917999||t>=983040&&t<=1048573||t>=1048576&&t<=1114109}function Om(t){return t===12288||t>=65281&&t<=65376||t>=65504&&t<=65510}function Um(t){return t>=4352&&t<=4447||t===8986||t===8987||t===9001||t===9002||t>=9193&&t<=9196||t===9200||t===9203||t===9725||t===9726||t===9748||t===9749||t>=9776&&t<=9783||t>=9800&&t<=9811||t===9855||t>=9866&&t<=9871||t===9875||t===9889||t===9898||t===9899||t===9917||t===9918||t===9924||t===9925||t===9934||t===9940||t===9962||t===9970||t===9971||t===9973||t===9978||t===9981||t===9989||t===9994||t===9995||t===10024||t===10060||t===10062||t>=10067&&t<=10069||t===10071||t>=10133&&t<=10135||t===10160||t===10175||t===11035||t===11036||t===11088||t===11093||t>=11904&&t<=11929||t>=11931&&t<=12019||t>=12032&&t<=12245||t>=12272&&t<=12287||t>=12289&&t<=12350||t>=12353&&t<=12438||t>=12441&&t<=12543||t>=12549&&t<=12591||t>=12593&&t<=12686||t>=12688&&t<=12773||t>=12783&&t<=12830||t>=12832&&t<=12871||t>=12880&&t<=42124||t>=42128&&t<=42182||t>=43360&&t<=43388||t>=44032&&t<=55203||t>=63744&&t<=64255||t>=65040&&t<=65049||t>=65072&&t<=65106||t>=65108&&t<=65126||t>=65128&&t<=65131||t>=94176&&t<=94180||t>=94192&&t<=94198||t>=94208&&t<=101589||t>=101631&&t<=101662||t>=101760&&t<=101874||t>=110576&&t<=110579||t>=110581&&t<=110587||t===110589||t===110590||t>=110592&&t<=110882||t===110898||t>=110928&&t<=110930||t===110933||t>=110948&&t<=110951||t>=110960&&t<=111355||t>=119552&&t<=119638||t>=119648&&t<=119670||t===126980||t===127183||t===127374||t>=127377&&t<=127386||t>=127488&&t<=127490||t>=127504&&t<=127547||t>=127552&&t<=127560||t===127568||t===127569||t>=127584&&t<=127589||t>=127744&&t<=127776||t>=127789&&t<=127797||t>=127799&&t<=127868||t>=127870&&t<=127891||t>=127904&&t<=127946||t>=127951&&t<=127955||t>=127968&&t<=127984||t===127988||t>=127992&&t<=128062||t===128064||t>=128066&&t<=128252||t>=128255&&t<=128317||t>=128331&&t<=128334||t>=128336&&t<=128359||t===128378||t===128405||t===128406||t===128420||t>=128507&&t<=128591||t>=128640&&t<=128709||t===128716||t>=128720&&t<=128722||t>=128725&&t<=128728||t>=128732&&t<=128735||t===128747||t===128748||t>=128756&&t<=128764||t>=128992&&t<=129003||t===129008||t>=129292&&t<=129338||t>=129340&&t<=129349||t>=129351&&t<=129535||t>=129648&&t<=129660||t>=129664&&t<=129674||t>=129678&&t<=129734||t===129736||t>=129741&&t<=129756||t>=129759&&t<=129770||t>=129775&&t<=129784||t>=131072&&t<=196605||t>=196608&&t<=262141}function Kd(t){if(!Number.isSafeInteger(t))throw new TypeError(`Expected a code point, got \`${typeof t}\`.`)}function Km(t,{ambiguousAsWide:e=!1}={}){return Kd(t),Om(t)||Um(t)||e&&Cm(t)?2:1}var Nm=Ar(Vm(),1),kd=new Intl.Segmenter,Vd=new RegExp("^\\p{Default_Ignorable_Code_Point}$","u");function hc(t,e={}){if(typeof t!="string"||t.length===0)return 0;let{ambiguousIsNarrow:i=!0,countAnsiEscapeCodes:n=!1}=e;if(n||(t=rs(t)),t.length===0)return 0;let s=0,r={ambiguousAsWide:!i};for(let{segment:o}of kd.segment(t)){let c=o.codePointAt(0);if(!(c<=31||c>=127&&c<=159)&&!(c>=8203&&c<=8207||c===65279)&&!(c>=768&&c<=879||c>=6832&&c<=6911||c>=7616&&c<=7679||c>=8400&&c<=8447||c>=65056&&c<=65071)&&!(c>=55296&&c<=57343)&&!(c>=65024&&c<=65039)&&!Vd.test(o)){if((0,Nm.default)().test(o)){s+=2;continue}s+=Km(c,r)}}return s}function gc({stream:t=process.stdout}={}){return!!(t&&t.isTTY&&process.env.TERM!=="dumb"&&!("CI"in process.env))}import Fm from"node:process";function Ic(){let{env:t}=Fm,{TERM:e,TERM_PROGRAM:i}=t;return Fm.platform!=="win32"?e!=="linux":!!t.WT_SESSION||!!t.TERMINUS_SUBLIME||t.ConEmuTask==="{cmd::Cmder}"||i==="Terminus-Sublime"||i==="vscode"||e==="xterm-256color"||e==="alacritty"||e==="rxvt-unicode"||e==="rxvt-unicode-256color"||t.TERMINAL_EMULATOR==="JetBrains-JediTerm"}import ct from"node:process";var Nd=3,Ec=class{#e=0;start(){this.#e++,this.#e===1&&this.#n()}stop(){if(this.#e<=0)throw new Error("`stop` called more times than `start`");this.#e--,this.#e===0&&this.#i()}#n(){ct.platform==="win32"||!ct.stdin.isTTY||(ct.stdin.setRawMode(!0),ct.stdin.on("data",this.#s),ct.stdin.resume())}#i(){ct.stdin.isTTY&&(ct.stdin.off("data",this.#s),ct.stdin.pause(),ct.stdin.setRawMode(!1))}#s(e){e[0]===Nd&&ct.emit("SIGINT")}},Fd=new Ec,Rc=Fd;var bd=Ar(Ac(),1),zc=class{#e=0;#n=!1;#i=0;#s=-1;#a=0;#t;#r;#o;#p;#d;#u;#m;#v;#f;#c;#l;color;constructor(e){typeof e=="string"&&(e={text:e}),this.#t={color:"cyan",stream:Gr.stderr,discardStdin:!0,hideCursor:!0,...e},this.color=this.#t.color,this.spinner=this.#t.spinner,this.#d=this.#t.interval,this.#o=this.#t.stream,this.#u=typeof this.#t.isEnabled=="boolean"?this.#t.isEnabled:gc({stream:this.#o}),this.#m=typeof this.#t.isSilent=="boolean"?this.#t.isSilent:!1,this.text=this.#t.text,this.prefixText=this.#t.prefixText,this.suffixText=this.#t.suffixText,this.indent=this.#t.indent,Gr.env.NODE_ENV==="test"&&(this._stream=this.#o,this._isEnabled=this.#u,Object.defineProperty(this,"_linesToClear",{get(){return this.#e},set(i){this.#e=i}}),Object.defineProperty(this,"_frameIndex",{get(){return this.#s}}),Object.defineProperty(this,"_lineCount",{get(){return this.#i}}))}get indent(){return this.#v}set indent(e=0){if(!(e>=0&&Number.isInteger(e)))throw new Error("The `indent` option must be an integer from 0 and up");this.#v=e,this.#A()}get interval(){return this.#d??this.#r.interval??100}get spinner(){return this.#r}set spinner(e){if(this.#s=-1,this.#d=void 0,typeof e=="object"){if(e.frames===void 0)throw new Error("The given spinner must have a `frames` property");this.#r=e}else if(!Ic())this.#r=os.default.line;else if(e===void 0)this.#r=os.default.dots;else if(e!=="default"&&os.default[e])this.#r=os.default[e];else throw new Error(`There is no built-in spinner named '${e}'. See https://github.com/sindresorhus/cli-spinners/blob/main/spinners.json for a full list.`)}get text(){return this.#f}set text(e=""){this.#f=e,this.#A()}get prefixText(){return this.#c}set prefixText(e=""){this.#c=e,this.#A()}get suffixText(){return this.#l}set suffixText(e=""){this.#l=e,this.#A()}get isSpinning(){return this.#p!==void 0}#h(e=this.#c,i=" "){return typeof e=="string"&&e!==""?e+i:typeof e=="function"?e()+i:""}#g(e=this.#l,i=" "){return typeof e=="string"&&e!==""?i+e:typeof e=="function"?i+e():""}#A(){let e=this.#o.columns??80,i=this.#h(this.#c,"-"),n=this.#g(this.#l,"-"),s=" ".repeat(this.#v)+i+"--"+this.#f+"--"+n;this.#i=0;for(let r of rs(s).split(`
44
+ `))this.#i+=Math.max(1,Math.ceil(hc(r,{countAnsiEscapeCodes:!0})/e))}get isEnabled(){return this.#u&&!this.#m}set isEnabled(e){if(typeof e!="boolean")throw new TypeError("The `isEnabled` option must be a boolean");this.#u=e}get isSilent(){return this.#m}set isSilent(e){if(typeof e!="boolean")throw new TypeError("The `isSilent` option must be a boolean");this.#m=e}frame(){let e=Date.now();(this.#s===-1||e-this.#a>=this.interval)&&(this.#s=++this.#s%this.#r.frames.length,this.#a=e);let{frames:i}=this.#r,n=i[this.#s];this.color&&(n=qe[this.color](n));let s=typeof this.#c=="string"&&this.#c!==""?this.#c+" ":"",r=typeof this.text=="string"?" "+this.text:"",o=typeof this.#l=="string"&&this.#l!==""?" "+this.#l:"";return s+n+r+o}clear(){if(!this.#u||!this.#o.isTTY)return this;this.#o.cursorTo(0);for(let e=0;e<this.#e;e++)e>0&&this.#o.moveCursor(0,-1),this.#o.clearLine(1);return(this.#v||this.lastIndent!==this.#v)&&this.#o.cursorTo(this.#v),this.lastIndent=this.#v,this.#e=0,this}render(){return this.#m?this:(this.clear(),this.#o.write(this.frame()),this.#e=this.#i,this)}start(e){return e&&(this.text=e),this.#m?this:this.#u?this.isSpinning?this:(this.#t.hideCursor&&pc.hide(this.#o),this.#t.discardStdin&&Gr.stdin.isTTY&&(this.#n=!0,Rc.start()),this.render(),this.#p=setInterval(this.render.bind(this),this.interval),this):(this.text&&this.#o.write(`- ${this.text}
45
+ `),this)}stop(){return this.#u?(clearInterval(this.#p),this.#p=void 0,this.#s=0,this.clear(),this.#t.hideCursor&&pc.show(this.#o),this.#t.discardStdin&&Gr.stdin.isTTY&&this.#n&&(Rc.stop(),this.#n=!1),this):this}succeed(e){return this.stopAndPersist({symbol:ss.success,text:e})}fail(e){return this.stopAndPersist({symbol:ss.error,text:e})}warn(e){return this.stopAndPersist({symbol:ss.warning,text:e})}info(e){return this.stopAndPersist({symbol:ss.info,text:e})}stopAndPersist(e={}){if(this.#m)return this;let i=e.prefixText??this.#c,n=this.#h(i," "),s=e.symbol??" ",r=e.text??this.text,c=typeof r=="string"?(s?" ":"")+r:"",l=e.suffixText??this.#l,u=this.#g(l," "),m=n+s+c+u+`
46
+ `;return this.stop(),this.#o.write(m),this}};function lt(t){return new zc(t)}k();import{existsSync as Bm,readFileSync as yd,writeFileSync as qd,mkdirSync as wd}from"fs";import{dirname as Dd}from"path";var Ke={defaultScope:"local",github:{repo:"therichardngai-code/gemkit-kits-starter",apiUrl:"https://api.github.com"},cache:{enabled:!0,ttl:3600},installation:{excludePatterns:[],backupOnUpdate:!0},ui:{colors:!0,spinner:!0,verbose:!1},paths:{},spawn:{defaultModel:"gemini-3-flash-preview",music:!1},office:{enabled:!0,mode:"web",port:3847,autoOpen:!0,sounds:!1,refreshRate:500},update:{autoCheck:!0,checkInterval:24,notifyOnly:!0}};function Pm(t){return!(!t||typeof t!="object")}function Qm(t){return{...Ke,...t,github:{...Ke.github,...t.github||{}},cache:{...Ke.cache,...t.cache||{}},installation:{...Ke.installation,...t.installation||{}},ui:{...Ke.ui,...t.ui||{}},paths:{...Ke.paths,...t.paths||{}},spawn:{...Ke.spawn,...t.spawn||{}},office:{...Ke.office,...t.office||{}},update:{...Ke.update,...t.update||{}}}}var Yr=class extends Error{constructor(i,n="GEMKIT_ERROR",s){super(i);this.code=n;this.details=s;this.name="GemKitError"}},Ui=class extends Yr{constructor(e,i){super(e,"CONFIG_ERROR",i),this.name="ConfigError"}};var ke=class extends Yr{constructor(e,i){super(e,"GITHUB_ERROR",i),this.name="GitHubError"}};function Ie(t){let e=Sc(t);if(!Bm(e))return Ke;try{let i=yd(e,"utf-8"),n=JSON.parse(i);if(!Pm(n))throw new Ui("Invalid configuration format");return Qm(n)}catch(i){throw i instanceof Ui?i:new Ui(`Failed to load config: ${i}`)}}function Jm(t,e){let i=Sc(e),n=Dd(i);Bm(n)||wd(n,{recursive:!0}),qd(i,JSON.stringify(t,null,2))}function Zm(t,e){let i=Ie(e),n=t.split("."),s=i;for(let r of n)if(s&&typeof s=="object"&&r in s)s=s[r];else return;return s}function ym(t,e,i){let n=Ie(i),s=t.split("."),r=s.pop();if(!r)throw new Ui("Invalid config path");let o=n;for(let c of s)(!(c in o)||typeof o[c]!="object")&&(o[c]={}),o=o[c];o[r]=e,Jm(n,i)}function qm(t){Jm(Ke,t)}k();import{existsSync as wm,readFileSync as Td,writeFileSync as Xd,mkdirSync as Hd,readdirSync as Dm,unlinkSync as Tm,statSync as Ld}from"fs";import{join as Mc}from"path";function Yc(){return wm(un)||Hd(un,{recursive:!0}),un}function Xm(t){let e=t.replace(/[^a-zA-Z0-9-_]/g,"_");return Mc(Yc(),`${e}.json`)}function Wr(t){let e=Xm(t);if(!wm(e))return null;try{let i=Td(e,"utf-8"),n=JSON.parse(i);return Date.now()-n.timestamp>n.ttl*1e3?(Tm(e),null):n.data}catch{return null}}function Cr(t,e,i=3600){let n=Xm(t),s={key:t,data:e,timestamp:Date.now(),ttl:i};Xd(n,JSON.stringify(s,null,2))}function Hm(){let t=Yc(),e=Dm(t).filter(i=>i.endsWith(".json"));for(let i of e)Tm(Mc(t,i));return e.length}function Lm(){let t=Yc(),e=Dm(t).filter(n=>n.endsWith(".json")),i=0;for(let n of e){let s=Ld(Mc(t,n));i+=s.size}return{entries:e.length,size:i}}var _m="github-releases",_d=300;async function Or(t=10){let e=Wr(_m);if(e)return e.slice(0,t);let i=Ie(),{repo:n,apiUrl:s}=i.github,r=`${s}/repos/${n}/releases?per_page=${t}`;try{let o=await fetch(r,{headers:{Accept:"application/vnd.github.v3+json","User-Agent":"gemkit-cli"}});if(!o.ok)throw new ke(`Failed to fetch releases: ${o.status}`);let l=(await o.json()).map(u=>({version:u.tag_name.replace(/^v/,""),tag:u.tag_name,publishedAt:u.published_at,prerelease:u.prerelease,assets:u.assets.map(m=>({name:m.name,url:m.url,size:m.size,downloadUrl:m.browser_download_url}))}));return Cr(_m,l,_d),l}catch(o){throw o instanceof ke?o:new ke(`Failed to fetch releases: ${o}`)}}async function Ki(){let t=await Or(1);return t.length>0?t[0]:null}async function $m(t){return(await Or(50)).find(i=>i.version===t||i.tag===t)||null}k();import{createWriteStream as $d,existsSync as ef,mkdirSync as tf}from"fs";import{pipeline as nf}from"stream/promises";import{join as sf}from"path";async function rf(t,e=un){ef(e)||tf(e,{recursive:!0});let i=sf(e,t.name);try{let n=await fetch(t.downloadUrl,{headers:{"User-Agent":"gemkit-cli"}});if(!n.ok)throw new ke(`Failed to download asset: ${n.status}`);if(!n.body)throw new ke("No response body");let s=$d(i);return await nf(n.body,s),i}catch(n){throw n instanceof ke?n:new ke(`Download failed: ${n}`)}}async function pn(t){let e=t.assets.find(i=>i.name.endsWith(".tar.gz")||i.name.endsWith(".tgz"));if(!e)throw new ke("No tarball asset found in release");return rf(e)}import{createReadStream as uh,createWriteStream as qS,existsSync as fv,mkdirSync as mh}from"fs";import{pipeline as vh}from"stream/promises";import{createGunzip as ph}from"zlib";import ff from"events";import fe from"fs";import{EventEmitter as Vc}from"node:events";import s3 from"node:stream";import{StringDecoder as of}from"node:string_decoder";var e3=typeof process=="object"&&process?process:{stdout:null,stderr:null},af=t=>!!t&&typeof t=="object"&&(t instanceof ps||t instanceof s3||cf(t)||lf(t)),cf=t=>!!t&&typeof t=="object"&&t instanceof Vc&&typeof t.pipe=="function"&&t.pipe!==s3.Writable.prototype.pipe,lf=t=>!!t&&typeof t=="object"&&t instanceof Vc&&typeof t.write=="function"&&typeof t.end=="function",St=Symbol("EOF"),Gt=Symbol("maybeEmitEnd"),Tt=Symbol("emittedEnd"),Ur=Symbol("emittingEnd"),ls=Symbol("emittedError"),Kr=Symbol("closed"),t3=Symbol("read"),kr=Symbol("flush"),i3=Symbol("flushChunk"),De=Symbol("encoding"),An=Symbol("decoder"),q=Symbol("flowing"),us=Symbol("paused"),dn=Symbol("resume"),w=Symbol("buffer"),le=Symbol("pipes"),D=Symbol("bufferLength"),Wc=Symbol("bufferPush"),Vr=Symbol("bufferShift"),se=Symbol("objectMode"),V=Symbol("destroyed"),Cc=Symbol("error"),Oc=Symbol("emitData"),n3=Symbol("emitEnd"),Uc=Symbol("emitEnd2"),ut=Symbol("async"),Kc=Symbol("abort"),Nr=Symbol("aborted"),ms=Symbol("signal"),ki=Symbol("dataListeners"),Ee=Symbol("discarded"),vs=t=>Promise.resolve().then(t),uf=t=>t(),mf=t=>t==="end"||t==="finish"||t==="prefinish",vf=t=>t instanceof ArrayBuffer||!!t&&typeof t=="object"&&t.constructor&&t.constructor.name==="ArrayBuffer"&&t.byteLength>=0,pf=t=>!Buffer.isBuffer(t)&&ArrayBuffer.isView(t),Fr=class{src;dest;opts;ondrain;constructor(e,i,n){this.src=e,this.dest=i,this.opts=n,this.ondrain=()=>e[dn](),this.dest.on("drain",this.ondrain)}unpipe(){this.dest.removeListener("drain",this.ondrain)}proxyErrors(e){}end(){this.unpipe(),this.opts.end&&this.dest.end()}},kc=class extends Fr{unpipe(){this.src.removeListener("error",this.proxyErrors),super.unpipe()}constructor(e,i,n){super(e,i,n),this.proxyErrors=s=>i.emit("error",s),e.on("error",this.proxyErrors)}},Af=t=>!!t.objectMode,df=t=>!t.objectMode&&!!t.encoding&&t.encoding!=="buffer",ps=class extends Vc{[q]=!1;[us]=!1;[le]=[];[w]=[];[se];[De];[ut];[An];[St]=!1;[Tt]=!1;[Ur]=!1;[Kr]=!1;[ls]=null;[D]=0;[V]=!1;[ms];[Nr]=!1;[ki]=0;[Ee]=!1;writable=!0;readable=!0;constructor(...e){let i=e[0]||{};if(super(),i.objectMode&&typeof i.encoding=="string")throw new TypeError("Encoding and objectMode may not be used together");Af(i)?(this[se]=!0,this[De]=null):df(i)?(this[De]=i.encoding,this[se]=!1):(this[se]=!1,this[De]=null),this[ut]=!!i.async,this[An]=this[De]?new of(this[De]):null,i&&i.debugExposeBuffer===!0&&Object.defineProperty(this,"buffer",{get:()=>this[w]}),i&&i.debugExposePipes===!0&&Object.defineProperty(this,"pipes",{get:()=>this[le]});let{signal:n}=i;n&&(this[ms]=n,n.aborted?this[Kc]():n.addEventListener("abort",()=>this[Kc]()))}get bufferLength(){return this[D]}get encoding(){return this[De]}set encoding(e){throw new Error("Encoding must be set at instantiation time")}setEncoding(e){throw new Error("Encoding must be set at instantiation time")}get objectMode(){return this[se]}set objectMode(e){throw new Error("objectMode must be set at instantiation time")}get async(){return this[ut]}set async(e){this[ut]=this[ut]||!!e}[Kc](){this[Nr]=!0,this.emit("abort",this[ms]?.reason),this.destroy(this[ms]?.reason)}get aborted(){return this[Nr]}set aborted(e){}write(e,i,n){if(this[Nr])return!1;if(this[St])throw new Error("write after end");if(this[V])return this.emit("error",Object.assign(new Error("Cannot call write after a stream was destroyed"),{code:"ERR_STREAM_DESTROYED"})),!0;typeof i=="function"&&(n=i,i="utf8"),i||(i="utf8");let s=this[ut]?vs:uf;if(!this[se]&&!Buffer.isBuffer(e)){if(pf(e))e=Buffer.from(e.buffer,e.byteOffset,e.byteLength);else if(vf(e))e=Buffer.from(e);else if(typeof e!="string")throw new Error("Non-contiguous data written to non-objectMode stream")}return this[se]?(this[q]&&this[D]!==0&&this[kr](!0),this[q]?this.emit("data",e):this[Wc](e),this[D]!==0&&this.emit("readable"),n&&s(n),this[q]):e.length?(typeof e=="string"&&!(i===this[De]&&!this[An]?.lastNeed)&&(e=Buffer.from(e,i)),Buffer.isBuffer(e)&&this[De]&&(e=this[An].write(e)),this[q]&&this[D]!==0&&this[kr](!0),this[q]?this.emit("data",e):this[Wc](e),this[D]!==0&&this.emit("readable"),n&&s(n),this[q]):(this[D]!==0&&this.emit("readable"),n&&s(n),this[q])}read(e){if(this[V])return null;if(this[Ee]=!1,this[D]===0||e===0||e&&e>this[D])return this[Gt](),null;this[se]&&(e=null),this[w].length>1&&!this[se]&&(this[w]=[this[De]?this[w].join(""):Buffer.concat(this[w],this[D])]);let i=this[t3](e||null,this[w][0]);return this[Gt](),i}[t3](e,i){if(this[se])this[Vr]();else{let n=i;e===n.length||e===null?this[Vr]():typeof n=="string"?(this[w][0]=n.slice(e),i=n.slice(0,e),this[D]-=e):(this[w][0]=n.subarray(e),i=n.subarray(0,e),this[D]-=e)}return this.emit("data",i),!this[w].length&&!this[St]&&this.emit("drain"),i}end(e,i,n){return typeof e=="function"&&(n=e,e=void 0),typeof i=="function"&&(n=i,i="utf8"),e!==void 0&&this.write(e,i),n&&this.once("end",n),this[St]=!0,this.writable=!1,(this[q]||!this[us])&&this[Gt](),this}[dn](){this[V]||(!this[ki]&&!this[le].length&&(this[Ee]=!0),this[us]=!1,this[q]=!0,this.emit("resume"),this[w].length?this[kr]():this[St]?this[Gt]():this.emit("drain"))}resume(){return this[dn]()}pause(){this[q]=!1,this[us]=!0,this[Ee]=!1}get destroyed(){return this[V]}get flowing(){return this[q]}get paused(){return this[us]}[Wc](e){this[se]?this[D]+=1:this[D]+=e.length,this[w].push(e)}[Vr](){return this[se]?this[D]-=1:this[D]-=this[w][0].length,this[w].shift()}[kr](e=!1){do;while(this[i3](this[Vr]())&&this[w].length);!e&&!this[w].length&&!this[St]&&this.emit("drain")}[i3](e){return this.emit("data",e),this[q]}pipe(e,i){if(this[V])return e;this[Ee]=!1;let n=this[Tt];return i=i||{},e===e3.stdout||e===e3.stderr?i.end=!1:i.end=i.end!==!1,i.proxyErrors=!!i.proxyErrors,n?i.end&&e.end():(this[le].push(i.proxyErrors?new kc(this,e,i):new Fr(this,e,i)),this[ut]?vs(()=>this[dn]()):this[dn]()),e}unpipe(e){let i=this[le].find(n=>n.dest===e);i&&(this[le].length===1?(this[q]&&this[ki]===0&&(this[q]=!1),this[le]=[]):this[le].splice(this[le].indexOf(i),1),i.unpipe())}addListener(e,i){return this.on(e,i)}on(e,i){let n=super.on(e,i);if(e==="data")this[Ee]=!1,this[ki]++,!this[le].length&&!this[q]&&this[dn]();else if(e==="readable"&&this[D]!==0)super.emit("readable");else if(mf(e)&&this[Tt])super.emit(e),this.removeAllListeners(e);else if(e==="error"&&this[ls]){let s=i;this[ut]?vs(()=>s.call(this,this[ls])):s.call(this,this[ls])}return n}removeListener(e,i){return this.off(e,i)}off(e,i){let n=super.off(e,i);return e==="data"&&(this[ki]=this.listeners("data").length,this[ki]===0&&!this[Ee]&&!this[le].length&&(this[q]=!1)),n}removeAllListeners(e){let i=super.removeAllListeners(e);return(e==="data"||e===void 0)&&(this[ki]=0,!this[Ee]&&!this[le].length&&(this[q]=!1)),i}get emittedEnd(){return this[Tt]}[Gt](){!this[Ur]&&!this[Tt]&&!this[V]&&this[w].length===0&&this[St]&&(this[Ur]=!0,this.emit("end"),this.emit("prefinish"),this.emit("finish"),this[Kr]&&this.emit("close"),this[Ur]=!1)}emit(e,...i){let n=i[0];if(e!=="error"&&e!=="close"&&e!==V&&this[V])return!1;if(e==="data")return!this[se]&&!n?!1:this[ut]?(vs(()=>this[Oc](n)),!0):this[Oc](n);if(e==="end")return this[n3]();if(e==="close"){if(this[Kr]=!0,!this[Tt]&&!this[V])return!1;let r=super.emit("close");return this.removeAllListeners("close"),r}else if(e==="error"){this[ls]=n,super.emit(Cc,n);let r=!this[ms]||this.listeners("error").length?super.emit("error",n):!1;return this[Gt](),r}else if(e==="resume"){let r=super.emit("resume");return this[Gt](),r}else if(e==="finish"||e==="prefinish"){let r=super.emit(e);return this.removeAllListeners(e),r}let s=super.emit(e,...i);return this[Gt](),s}[Oc](e){for(let n of this[le])n.dest.write(e)===!1&&this.pause();let i=this[Ee]?!1:super.emit("data",e);return this[Gt](),i}[n3](){return this[Tt]?!1:(this[Tt]=!0,this.readable=!1,this[ut]?(vs(()=>this[Uc]()),!0):this[Uc]())}[Uc](){if(this[An]){let i=this[An].end();if(i){for(let n of this[le])n.dest.write(i);this[Ee]||super.emit("data",i)}}for(let i of this[le])i.end();let e=super.emit("end");return this.removeAllListeners("end"),e}async collect(){let e=Object.assign([],{dataLength:0});this[se]||(e.dataLength=0);let i=this.promise();return this.on("data",n=>{e.push(n),this[se]||(e.dataLength+=n.length)}),await i,e}async concat(){if(this[se])throw new Error("cannot concat in objectMode");let e=await this.collect();return this[De]?e.join(""):Buffer.concat(e,e.dataLength)}async promise(){return new Promise((e,i)=>{this.on(V,()=>i(new Error("stream destroyed"))),this.on("error",n=>i(n)),this.on("end",()=>e())})}[Symbol.asyncIterator](){this[Ee]=!1;let e=!1,i=async()=>(this.pause(),e=!0,{value:void 0,done:!0});return{next:()=>{if(e)return i();let s=this.read();if(s!==null)return Promise.resolve({done:!1,value:s});if(this[St])return i();let r,o,c=p=>{this.off("data",l),this.off("end",u),this.off(V,m),i(),o(p)},l=p=>{this.off("error",c),this.off("end",u),this.off(V,m),this.pause(),r({value:p,done:!!this[St]})},u=()=>{this.off("error",c),this.off("data",l),this.off(V,m),i(),r({done:!0,value:void 0})},m=()=>c(new Error("stream destroyed"));return new Promise((p,d)=>{o=d,r=p,this.once(V,m),this.once("error",c),this.once("end",u),this.once("data",l)})},throw:i,return:i,[Symbol.asyncIterator](){return this}}}[Symbol.iterator](){this[Ee]=!1;let e=!1,i=()=>(this.pause(),this.off(Cc,i),this.off(V,i),this.off("end",i),e=!0,{done:!0,value:void 0}),n=()=>{if(e)return i();let s=this.read();return s===null?i():{done:!1,value:s}};return this.once("end",i),this.once(Cc,i),this.once(V,i),{next:n,throw:i,return:i,[Symbol.iterator](){return this}}}destroy(e){if(this[V])return e?this.emit("error",e):this.emit(V),this;this[V]=!0,this[Ee]=!0,this[w].length=0,this[D]=0;let i=this;return typeof i.close=="function"&&!this[Kr]&&i.close(),e?this.emit("error",e):this.emit(V),this}static get isStream(){return af}};var hf=fe.writev,Ht=Symbol("_autoClose"),Xe=Symbol("_close"),As=Symbol("_ended"),x=Symbol("_fd"),Nc=Symbol("_finished"),Yt=Symbol("_flags"),Fc=Symbol("_flush"),Bc=Symbol("_handleChunk"),Jc=Symbol("_makeBuf"),fs=Symbol("_mode"),br=Symbol("_needDrain"),gn=Symbol("_onerror"),In=Symbol("_onopen"),bc=Symbol("_onread"),fn=Symbol("_onwrite"),Lt=Symbol("_open"),Te=Symbol("_path"),Xt=Symbol("_pos"),mt=Symbol("_queue"),hn=Symbol("_read"),Pc=Symbol("_readSize"),Mt=Symbol("_reading"),ds=Symbol("_remain"),Qc=Symbol("_size"),Pr=Symbol("_write"),Vi=Symbol("_writing"),Qr=Symbol("_defaultFlag"),Ni=Symbol("_errored"),Fi=class extends ps{[Ni]=!1;[x];[Te];[Pc];[Mt]=!1;[Qc];[ds];[Ht];constructor(e,i){if(i=i||{},super(i),this.readable=!0,this.writable=!1,typeof e!="string")throw new TypeError("path must be a string");this[Ni]=!1,this[x]=typeof i.fd=="number"?i.fd:void 0,this[Te]=e,this[Pc]=i.readSize||16*1024*1024,this[Mt]=!1,this[Qc]=typeof i.size=="number"?i.size:1/0,this[ds]=this[Qc],this[Ht]=typeof i.autoClose=="boolean"?i.autoClose:!0,typeof this[x]=="number"?this[hn]():this[Lt]()}get fd(){return this[x]}get path(){return this[Te]}write(){throw new TypeError("this is a readable stream")}end(){throw new TypeError("this is a readable stream")}[Lt](){fe.open(this[Te],"r",(e,i)=>this[In](e,i))}[In](e,i){e?this[gn](e):(this[x]=i,this.emit("open",i),this[hn]())}[Jc](){return Buffer.allocUnsafe(Math.min(this[Pc],this[ds]))}[hn](){if(!this[Mt]){this[Mt]=!0;let e=this[Jc]();if(e.length===0)return process.nextTick(()=>this[bc](null,0,e));fe.read(this[x],e,0,e.length,null,(i,n,s)=>this[bc](i,n,s))}}[bc](e,i,n){this[Mt]=!1,e?this[gn](e):this[Bc](i,n)&&this[hn]()}[Xe](){if(this[Ht]&&typeof this[x]=="number"){let e=this[x];this[x]=void 0,fe.close(e,i=>i?this.emit("error",i):this.emit("close"))}}[gn](e){this[Mt]=!0,this[Xe](),this.emit("error",e)}[Bc](e,i){let n=!1;return this[ds]-=e,e>0&&(n=super.write(e<i.length?i.subarray(0,e):i)),(e===0||this[ds]<=0)&&(n=!1,this[Xe](),super.end()),n}emit(e,...i){switch(e){case"prefinish":case"finish":return!1;case"drain":return typeof this[x]=="number"&&this[hn](),!1;case"error":return this[Ni]?!1:(this[Ni]=!0,super.emit(e,...i));default:return super.emit(e,...i)}}},Br=class extends Fi{[Lt](){let e=!0;try{this[In](null,fe.openSync(this[Te],"r")),e=!1}finally{e&&this[Xe]()}}[hn](){let e=!0;try{if(!this[Mt]){this[Mt]=!0;do{let i=this[Jc](),n=i.length===0?0:fe.readSync(this[x],i,0,i.length,null);if(!this[Bc](n,i))break}while(!0);this[Mt]=!1}e=!1}finally{e&&this[Xe]()}}[Xe](){if(this[Ht]&&typeof this[x]=="number"){let e=this[x];this[x]=void 0,fe.closeSync(e),this.emit("close")}}},Wt=class extends ff{readable=!1;writable=!0;[Ni]=!1;[Vi]=!1;[As]=!1;[mt]=[];[br]=!1;[Te];[fs];[Ht];[x];[Qr];[Yt];[Nc]=!1;[Xt];constructor(e,i){i=i||{},super(i),this[Te]=e,this[x]=typeof i.fd=="number"?i.fd:void 0,this[fs]=i.mode===void 0?438:i.mode,this[Xt]=typeof i.start=="number"?i.start:void 0,this[Ht]=typeof i.autoClose=="boolean"?i.autoClose:!0;let n=this[Xt]!==void 0?"r+":"w";this[Qr]=i.flags===void 0,this[Yt]=i.flags===void 0?n:i.flags,this[x]===void 0&&this[Lt]()}emit(e,...i){if(e==="error"){if(this[Ni])return!1;this[Ni]=!0}return super.emit(e,...i)}get fd(){return this[x]}get path(){return this[Te]}[gn](e){this[Xe](),this[Vi]=!0,this.emit("error",e)}[Lt](){fe.open(this[Te],this[Yt],this[fs],(e,i)=>this[In](e,i))}[In](e,i){this[Qr]&&this[Yt]==="r+"&&e&&e.code==="ENOENT"?(this[Yt]="w",this[Lt]()):e?this[gn](e):(this[x]=i,this.emit("open",i),this[Vi]||this[Fc]())}end(e,i){return e&&this.write(e,i),this[As]=!0,!this[Vi]&&!this[mt].length&&typeof this[x]=="number"&&this[fn](null,0),this}write(e,i){return typeof e=="string"&&(e=Buffer.from(e,i)),this[As]?(this.emit("error",new Error("write() after end()")),!1):this[x]===void 0||this[Vi]||this[mt].length?(this[mt].push(e),this[br]=!0,!1):(this[Vi]=!0,this[Pr](e),!0)}[Pr](e){fe.write(this[x],e,0,e.length,this[Xt],(i,n)=>this[fn](i,n))}[fn](e,i){e?this[gn](e):(this[Xt]!==void 0&&typeof i=="number"&&(this[Xt]+=i),this[mt].length?this[Fc]():(this[Vi]=!1,this[As]&&!this[Nc]?(this[Nc]=!0,this[Xe](),this.emit("finish")):this[br]&&(this[br]=!1,this.emit("drain"))))}[Fc](){if(this[mt].length===0)this[As]&&this[fn](null,0);else if(this[mt].length===1)this[Pr](this[mt].pop());else{let e=this[mt];this[mt]=[],hf(this[x],e,this[Xt],(i,n)=>this[fn](i,n))}}[Xe](){if(this[Ht]&&typeof this[x]=="number"){let e=this[x];this[x]=void 0,fe.close(e,i=>i?this.emit("error",i):this.emit("close"))}}},En=class extends Wt{[Lt](){let e;if(this[Qr]&&this[Yt]==="r+")try{e=fe.openSync(this[Te],this[Yt],this[fs])}catch(i){if(i?.code==="ENOENT")return this[Yt]="w",this[Lt]();throw i}else e=fe.openSync(this[Te],this[Yt],this[fs]);this[In](null,e)}[Xe](){if(this[Ht]&&typeof this[x]=="number"){let e=this[x];this[x]=void 0,fe.closeSync(e),this.emit("close")}}[Pr](e){let i=!0;try{this[fn](null,fe.writeSync(this[x],e,0,e.length,this[Xt])),i=!1}finally{if(i)try{this[Xe]()}catch{}}}};import T3 from"node:path";import Wn from"node:fs";import{dirname as A7,parse as d7}from"path";var gf=new Map([["C","cwd"],["f","file"],["z","gzip"],["P","preservePaths"],["U","unlink"],["strip-components","strip"],["stripComponents","strip"],["keep-newer","newer"],["keepNewer","newer"],["keep-newer-files","newer"],["keepNewerFiles","newer"],["k","keep"],["keep-existing","keep"],["keepExisting","keep"],["m","noMtime"],["no-mtime","noMtime"],["p","preserveOwner"],["L","follow"],["h","follow"],["onentry","onReadEntry"]]),r3=t=>!!t.sync&&!!t.file,o3=t=>!t.sync&&!!t.file,a3=t=>!!t.sync&&!t.file,c3=t=>!t.sync&&!t.file;var l3=t=>!!t.file;var If=t=>{let e=gf.get(t);return e||t},hs=(t={})=>{if(!t)return{};let e={};for(let[i,n]of Object.entries(t)){let s=If(i);e[s]=n}return e.chmod===void 0&&e.noChmod===!1&&(e.chmod=!0),delete e.noChmod,e};var vt=(t,e,i,n,s)=>Object.assign((r=[],o,c)=>{Array.isArray(r)&&(o=r,r={}),typeof o=="function"&&(c=o,o=void 0),o?o=Array.from(o):o=[];let l=hs(r);if(s?.(l,o),r3(l)){if(typeof c=="function")throw new TypeError("callback not supported for sync tar functions");return t(l,o)}else if(o3(l)){let u=e(l,o),m=c||void 0;return m?u.then(()=>m(),m):u}else if(a3(l)){if(typeof c=="function")throw new TypeError("callback not supported for sync tar functions");return i(l,o)}else if(c3(l)){if(typeof c=="function")throw new TypeError("callback only supported with file option");return n(l,o)}else throw new Error("impossible options??")},{syncFile:t,asyncFile:e,syncNoFile:i,asyncNoFile:n,validate:s});import{EventEmitter as u7}from"events";import $c from"assert";import{Buffer as Pi}from"buffer";import{EventEmitter as Hc}from"node:events";import A3 from"node:stream";import{StringDecoder as Ef}from"node:string_decoder";var u3=typeof process=="object"&&process?process:{stdout:null,stderr:null},Rf=t=>!!t&&typeof t=="object"&&(t instanceof zs||t instanceof A3||zf(t)||jf(t)),zf=t=>!!t&&typeof t=="object"&&t instanceof Hc&&typeof t.pipe=="function"&&t.pipe!==A3.Writable.prototype.pipe,jf=t=>!!t&&typeof t=="object"&&t instanceof Hc&&typeof t.write=="function"&&typeof t.end=="function",Ct=Symbol("EOF"),Ot=Symbol("maybeEmitEnd"),_t=Symbol("emittedEnd"),Jr=Symbol("emittingEnd"),gs=Symbol("emittedError"),Zr=Symbol("closed"),m3=Symbol("read"),yr=Symbol("flush"),v3=Symbol("flushChunk"),He=Symbol("encoding"),Rn=Symbol("decoder"),T=Symbol("flowing"),Is=Symbol("paused"),zn=Symbol("resume"),X=Symbol("buffer"),ue=Symbol("pipes"),H=Symbol("bufferLength"),yc=Symbol("bufferPush"),qr=Symbol("bufferShift"),re=Symbol("objectMode"),N=Symbol("destroyed"),qc=Symbol("error"),wc=Symbol("emitData"),p3=Symbol("emitEnd"),Dc=Symbol("emitEnd2"),pt=Symbol("async"),Tc=Symbol("abort"),wr=Symbol("aborted"),Es=Symbol("signal"),bi=Symbol("dataListeners"),Re=Symbol("discarded"),Rs=t=>Promise.resolve().then(t),xf=t=>t(),Sf=t=>t==="end"||t==="finish"||t==="prefinish",Gf=t=>t instanceof ArrayBuffer||!!t&&typeof t=="object"&&t.constructor&&t.constructor.name==="ArrayBuffer"&&t.byteLength>=0,Mf=t=>!Buffer.isBuffer(t)&&ArrayBuffer.isView(t),Dr=class{src;dest;opts;ondrain;constructor(e,i,n){this.src=e,this.dest=i,this.opts=n,this.ondrain=()=>e[zn](),this.dest.on("drain",this.ondrain)}unpipe(){this.dest.removeListener("drain",this.ondrain)}proxyErrors(e){}end(){this.unpipe(),this.opts.end&&this.dest.end()}},Xc=class extends Dr{unpipe(){this.src.removeListener("error",this.proxyErrors),super.unpipe()}constructor(e,i,n){super(e,i,n),this.proxyErrors=s=>i.emit("error",s),e.on("error",this.proxyErrors)}},Yf=t=>!!t.objectMode,Wf=t=>!t.objectMode&&!!t.encoding&&t.encoding!=="buffer",zs=class extends Hc{[T]=!1;[Is]=!1;[ue]=[];[X]=[];[re];[He];[pt];[Rn];[Ct]=!1;[_t]=!1;[Jr]=!1;[Zr]=!1;[gs]=null;[H]=0;[N]=!1;[Es];[wr]=!1;[bi]=0;[Re]=!1;writable=!0;readable=!0;constructor(...e){let i=e[0]||{};if(super(),i.objectMode&&typeof i.encoding=="string")throw new TypeError("Encoding and objectMode may not be used together");Yf(i)?(this[re]=!0,this[He]=null):Wf(i)?(this[He]=i.encoding,this[re]=!1):(this[re]=!1,this[He]=null),this[pt]=!!i.async,this[Rn]=this[He]?new Ef(this[He]):null,i&&i.debugExposeBuffer===!0&&Object.defineProperty(this,"buffer",{get:()=>this[X]}),i&&i.debugExposePipes===!0&&Object.defineProperty(this,"pipes",{get:()=>this[ue]});let{signal:n}=i;n&&(this[Es]=n,n.aborted?this[Tc]():n.addEventListener("abort",()=>this[Tc]()))}get bufferLength(){return this[H]}get encoding(){return this[He]}set encoding(e){throw new Error("Encoding must be set at instantiation time")}setEncoding(e){throw new Error("Encoding must be set at instantiation time")}get objectMode(){return this[re]}set objectMode(e){throw new Error("objectMode must be set at instantiation time")}get async(){return this[pt]}set async(e){this[pt]=this[pt]||!!e}[Tc](){this[wr]=!0,this.emit("abort",this[Es]?.reason),this.destroy(this[Es]?.reason)}get aborted(){return this[wr]}set aborted(e){}write(e,i,n){if(this[wr])return!1;if(this[Ct])throw new Error("write after end");if(this[N])return this.emit("error",Object.assign(new Error("Cannot call write after a stream was destroyed"),{code:"ERR_STREAM_DESTROYED"})),!0;typeof i=="function"&&(n=i,i="utf8"),i||(i="utf8");let s=this[pt]?Rs:xf;if(!this[re]&&!Buffer.isBuffer(e)){if(Mf(e))e=Buffer.from(e.buffer,e.byteOffset,e.byteLength);else if(Gf(e))e=Buffer.from(e);else if(typeof e!="string")throw new Error("Non-contiguous data written to non-objectMode stream")}return this[re]?(this[T]&&this[H]!==0&&this[yr](!0),this[T]?this.emit("data",e):this[yc](e),this[H]!==0&&this.emit("readable"),n&&s(n),this[T]):e.length?(typeof e=="string"&&!(i===this[He]&&!this[Rn]?.lastNeed)&&(e=Buffer.from(e,i)),Buffer.isBuffer(e)&&this[He]&&(e=this[Rn].write(e)),this[T]&&this[H]!==0&&this[yr](!0),this[T]?this.emit("data",e):this[yc](e),this[H]!==0&&this.emit("readable"),n&&s(n),this[T]):(this[H]!==0&&this.emit("readable"),n&&s(n),this[T])}read(e){if(this[N])return null;if(this[Re]=!1,this[H]===0||e===0||e&&e>this[H])return this[Ot](),null;this[re]&&(e=null),this[X].length>1&&!this[re]&&(this[X]=[this[He]?this[X].join(""):Buffer.concat(this[X],this[H])]);let i=this[m3](e||null,this[X][0]);return this[Ot](),i}[m3](e,i){if(this[re])this[qr]();else{let n=i;e===n.length||e===null?this[qr]():typeof n=="string"?(this[X][0]=n.slice(e),i=n.slice(0,e),this[H]-=e):(this[X][0]=n.subarray(e),i=n.subarray(0,e),this[H]-=e)}return this.emit("data",i),!this[X].length&&!this[Ct]&&this.emit("drain"),i}end(e,i,n){return typeof e=="function"&&(n=e,e=void 0),typeof i=="function"&&(n=i,i="utf8"),e!==void 0&&this.write(e,i),n&&this.once("end",n),this[Ct]=!0,this.writable=!1,(this[T]||!this[Is])&&this[Ot](),this}[zn](){this[N]||(!this[bi]&&!this[ue].length&&(this[Re]=!0),this[Is]=!1,this[T]=!0,this.emit("resume"),this[X].length?this[yr]():this[Ct]?this[Ot]():this.emit("drain"))}resume(){return this[zn]()}pause(){this[T]=!1,this[Is]=!0,this[Re]=!1}get destroyed(){return this[N]}get flowing(){return this[T]}get paused(){return this[Is]}[yc](e){this[re]?this[H]+=1:this[H]+=e.length,this[X].push(e)}[qr](){return this[re]?this[H]-=1:this[H]-=this[X][0].length,this[X].shift()}[yr](e=!1){do;while(this[v3](this[qr]())&&this[X].length);!e&&!this[X].length&&!this[Ct]&&this.emit("drain")}[v3](e){return this.emit("data",e),this[T]}pipe(e,i){if(this[N])return e;this[Re]=!1;let n=this[_t];return i=i||{},e===u3.stdout||e===u3.stderr?i.end=!1:i.end=i.end!==!1,i.proxyErrors=!!i.proxyErrors,n?i.end&&e.end():(this[ue].push(i.proxyErrors?new Xc(this,e,i):new Dr(this,e,i)),this[pt]?Rs(()=>this[zn]()):this[zn]()),e}unpipe(e){let i=this[ue].find(n=>n.dest===e);i&&(this[ue].length===1?(this[T]&&this[bi]===0&&(this[T]=!1),this[ue]=[]):this[ue].splice(this[ue].indexOf(i),1),i.unpipe())}addListener(e,i){return this.on(e,i)}on(e,i){let n=super.on(e,i);if(e==="data")this[Re]=!1,this[bi]++,!this[ue].length&&!this[T]&&this[zn]();else if(e==="readable"&&this[H]!==0)super.emit("readable");else if(Sf(e)&&this[_t])super.emit(e),this.removeAllListeners(e);else if(e==="error"&&this[gs]){let s=i;this[pt]?Rs(()=>s.call(this,this[gs])):s.call(this,this[gs])}return n}removeListener(e,i){return this.off(e,i)}off(e,i){let n=super.off(e,i);return e==="data"&&(this[bi]=this.listeners("data").length,this[bi]===0&&!this[Re]&&!this[ue].length&&(this[T]=!1)),n}removeAllListeners(e){let i=super.removeAllListeners(e);return(e==="data"||e===void 0)&&(this[bi]=0,!this[Re]&&!this[ue].length&&(this[T]=!1)),i}get emittedEnd(){return this[_t]}[Ot](){!this[Jr]&&!this[_t]&&!this[N]&&this[X].length===0&&this[Ct]&&(this[Jr]=!0,this.emit("end"),this.emit("prefinish"),this.emit("finish"),this[Zr]&&this.emit("close"),this[Jr]=!1)}emit(e,...i){let n=i[0];if(e!=="error"&&e!=="close"&&e!==N&&this[N])return!1;if(e==="data")return!this[re]&&!n?!1:this[pt]?(Rs(()=>this[wc](n)),!0):this[wc](n);if(e==="end")return this[p3]();if(e==="close"){if(this[Zr]=!0,!this[_t]&&!this[N])return!1;let r=super.emit("close");return this.removeAllListeners("close"),r}else if(e==="error"){this[gs]=n,super.emit(qc,n);let r=!this[Es]||this.listeners("error").length?super.emit("error",n):!1;return this[Ot](),r}else if(e==="resume"){let r=super.emit("resume");return this[Ot](),r}else if(e==="finish"||e==="prefinish"){let r=super.emit(e);return this.removeAllListeners(e),r}let s=super.emit(e,...i);return this[Ot](),s}[wc](e){for(let n of this[ue])n.dest.write(e)===!1&&this.pause();let i=this[Re]?!1:super.emit("data",e);return this[Ot](),i}[p3](){return this[_t]?!1:(this[_t]=!0,this.readable=!1,this[pt]?(Rs(()=>this[Dc]()),!0):this[Dc]())}[Dc](){if(this[Rn]){let i=this[Rn].end();if(i){for(let n of this[ue])n.dest.write(i);this[Re]||super.emit("data",i)}}for(let i of this[ue])i.end();let e=super.emit("end");return this.removeAllListeners("end"),e}async collect(){let e=Object.assign([],{dataLength:0});this[re]||(e.dataLength=0);let i=this.promise();return this.on("data",n=>{e.push(n),this[re]||(e.dataLength+=n.length)}),await i,e}async concat(){if(this[re])throw new Error("cannot concat in objectMode");let e=await this.collect();return this[He]?e.join(""):Buffer.concat(e,e.dataLength)}async promise(){return new Promise((e,i)=>{this.on(N,()=>i(new Error("stream destroyed"))),this.on("error",n=>i(n)),this.on("end",()=>e())})}[Symbol.asyncIterator](){this[Re]=!1;let e=!1,i=async()=>(this.pause(),e=!0,{value:void 0,done:!0});return{next:()=>{if(e)return i();let s=this.read();if(s!==null)return Promise.resolve({done:!1,value:s});if(this[Ct])return i();let r,o,c=p=>{this.off("data",l),this.off("end",u),this.off(N,m),i(),o(p)},l=p=>{this.off("error",c),this.off("end",u),this.off(N,m),this.pause(),r({value:p,done:!!this[Ct]})},u=()=>{this.off("error",c),this.off("data",l),this.off(N,m),i(),r({done:!0,value:void 0})},m=()=>c(new Error("stream destroyed"));return new Promise((p,d)=>{o=d,r=p,this.once(N,m),this.once("error",c),this.once("end",u),this.once("data",l)})},throw:i,return:i,[Symbol.asyncIterator](){return this}}}[Symbol.iterator](){this[Re]=!1;let e=!1,i=()=>(this.pause(),this.off(qc,i),this.off(N,i),this.off("end",i),e=!0,{done:!0,value:void 0}),n=()=>{if(e)return i();let s=this.read();return s===null?i():{done:!1,value:s}};return this.once("end",i),this.once(qc,i),this.once(N,i),{next:n,throw:i,return:i,[Symbol.iterator](){return this}}}destroy(e){if(this[N])return e?this.emit("error",e):this.emit(N),this;this[N]=!0,this[Re]=!0,this[X].length=0,this[H]=0;let i=this;return typeof i.close=="function"&&!this[Zr]&&i.close(),e?this.emit("error",e):this.emit(N),this}static get isStream(){return Rf}};import*as d3 from"zlib";import Cf from"zlib";var Of=Cf.constants||{ZLIB_VERNUM:4736},Ve=Object.freeze(Object.assign(Object.create(null),{Z_NO_FLUSH:0,Z_PARTIAL_FLUSH:1,Z_SYNC_FLUSH:2,Z_FULL_FLUSH:3,Z_FINISH:4,Z_BLOCK:5,Z_OK:0,Z_STREAM_END:1,Z_NEED_DICT:2,Z_ERRNO:-1,Z_STREAM_ERROR:-2,Z_DATA_ERROR:-3,Z_MEM_ERROR:-4,Z_BUF_ERROR:-5,Z_VERSION_ERROR:-6,Z_NO_COMPRESSION:0,Z_BEST_SPEED:1,Z_BEST_COMPRESSION:9,Z_DEFAULT_COMPRESSION:-1,Z_FILTERED:1,Z_HUFFMAN_ONLY:2,Z_RLE:3,Z_FIXED:4,Z_DEFAULT_STRATEGY:0,DEFLATE:1,INFLATE:2,GZIP:3,GUNZIP:4,DEFLATERAW:5,INFLATERAW:6,UNZIP:7,BROTLI_DECODE:8,BROTLI_ENCODE:9,Z_MIN_WINDOWBITS:8,Z_MAX_WINDOWBITS:15,Z_DEFAULT_WINDOWBITS:15,Z_MIN_CHUNK:64,Z_MAX_CHUNK:1/0,Z_DEFAULT_CHUNK:16384,Z_MIN_MEMLEVEL:1,Z_MAX_MEMLEVEL:9,Z_DEFAULT_MEMLEVEL:8,Z_MIN_LEVEL:-1,Z_MAX_LEVEL:9,Z_DEFAULT_LEVEL:-1,BROTLI_OPERATION_PROCESS:0,BROTLI_OPERATION_FLUSH:1,BROTLI_OPERATION_FINISH:2,BROTLI_OPERATION_EMIT_METADATA:3,BROTLI_MODE_GENERIC:0,BROTLI_MODE_TEXT:1,BROTLI_MODE_FONT:2,BROTLI_DEFAULT_MODE:0,BROTLI_MIN_QUALITY:0,BROTLI_MAX_QUALITY:11,BROTLI_DEFAULT_QUALITY:11,BROTLI_MIN_WINDOW_BITS:10,BROTLI_MAX_WINDOW_BITS:24,BROTLI_LARGE_MAX_WINDOW_BITS:30,BROTLI_DEFAULT_WINDOW:22,BROTLI_MIN_INPUT_BLOCK_BITS:16,BROTLI_MAX_INPUT_BLOCK_BITS:24,BROTLI_PARAM_MODE:0,BROTLI_PARAM_QUALITY:1,BROTLI_PARAM_LGWIN:2,BROTLI_PARAM_LGBLOCK:3,BROTLI_PARAM_DISABLE_LITERAL_CONTEXT_MODELING:4,BROTLI_PARAM_SIZE_HINT:5,BROTLI_PARAM_LARGE_WINDOW:6,BROTLI_PARAM_NPOSTFIX:7,BROTLI_PARAM_NDIRECT:8,BROTLI_DECODER_RESULT_ERROR:0,BROTLI_DECODER_RESULT_SUCCESS:1,BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT:2,BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT:3,BROTLI_DECODER_PARAM_DISABLE_RING_BUFFER_REALLOCATION:0,BROTLI_DECODER_PARAM_LARGE_WINDOW:1,BROTLI_DECODER_NO_ERROR:0,BROTLI_DECODER_SUCCESS:1,BROTLI_DECODER_NEEDS_MORE_INPUT:2,BROTLI_DECODER_NEEDS_MORE_OUTPUT:3,BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_NIBBLE:-1,BROTLI_DECODER_ERROR_FORMAT_RESERVED:-2,BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_META_NIBBLE:-3,BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_ALPHABET:-4,BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_SAME:-5,BROTLI_DECODER_ERROR_FORMAT_CL_SPACE:-6,BROTLI_DECODER_ERROR_FORMAT_HUFFMAN_SPACE:-7,BROTLI_DECODER_ERROR_FORMAT_CONTEXT_MAP_REPEAT:-8,BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_1:-9,BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_2:-10,BROTLI_DECODER_ERROR_FORMAT_TRANSFORM:-11,BROTLI_DECODER_ERROR_FORMAT_DICTIONARY:-12,BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS:-13,BROTLI_DECODER_ERROR_FORMAT_PADDING_1:-14,BROTLI_DECODER_ERROR_FORMAT_PADDING_2:-15,BROTLI_DECODER_ERROR_FORMAT_DISTANCE:-16,BROTLI_DECODER_ERROR_DICTIONARY_NOT_SET:-19,BROTLI_DECODER_ERROR_INVALID_ARGUMENTS:-20,BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MODES:-21,BROTLI_DECODER_ERROR_ALLOC_TREE_GROUPS:-22,BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MAP:-25,BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_1:-26,BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_2:-27,BROTLI_DECODER_ERROR_ALLOC_BLOCK_TYPE_TREES:-30,BROTLI_DECODER_ERROR_UNREACHABLE:-31},Of));var Uf=Pi.concat,f3=Object.getOwnPropertyDescriptor(Pi,"concat"),Kf=t=>t,Lc=f3?.writable===!0||f3?.set!==void 0?t=>{Pi.concat=t?Kf:Uf}:t=>{},Qi=Symbol("_superWrite"),jn=class extends Error{code;errno;constructor(e,i){super("zlib: "+e.message,{cause:e}),this.code=e.code,this.errno=e.errno,this.code||(this.code="ZLIB_ERROR"),this.message="zlib: "+e.message,Error.captureStackTrace(this,i??this.constructor)}get name(){return"ZlibError"}},_c=Symbol("flushFlag"),js=class extends zs{#e=!1;#n=!1;#i;#s;#a;#t;#r;get sawError(){return this.#e}get handle(){return this.#t}get flushFlag(){return this.#i}constructor(e,i){if(!e||typeof e!="object")throw new TypeError("invalid options for ZlibBase constructor");if(super(e),this.#i=e.flush??0,this.#s=e.finishFlush??0,this.#a=e.fullFlushFlag??0,typeof d3[i]!="function")throw new TypeError("Compression method not supported: "+i);try{this.#t=new d3[i](e)}catch(n){throw new jn(n,this.constructor)}this.#r=n=>{this.#e||(this.#e=!0,this.close(),this.emit("error",n))},this.#t?.on("error",n=>this.#r(new jn(n))),this.once("end",()=>this.close)}close(){this.#t&&(this.#t.close(),this.#t=void 0,this.emit("close"))}reset(){if(!this.#e)return $c(this.#t,"zlib binding closed"),this.#t.reset?.()}flush(e){this.ended||(typeof e!="number"&&(e=this.#a),this.write(Object.assign(Pi.alloc(0),{[_c]:e})))}end(e,i,n){return typeof e=="function"&&(n=e,i=void 0,e=void 0),typeof i=="function"&&(n=i,i=void 0),e&&(i?this.write(e,i):this.write(e)),this.flush(this.#s),this.#n=!0,super.end(n)}get ended(){return this.#n}[Qi](e){return super.write(e)}write(e,i,n){if(typeof i=="function"&&(n=i,i="utf8"),typeof e=="string"&&(e=Pi.from(e,i)),this.#e)return;$c(this.#t,"zlib binding closed");let s=this.#t._handle,r=s.close;s.close=()=>{};let o=this.#t.close;this.#t.close=()=>{},Lc(!0);let c;try{let u=typeof e[_c]=="number"?e[_c]:this.#i;c=this.#t._processChunk(e,u),Lc(!1)}catch(u){Lc(!1),this.#r(new jn(u,this.write))}finally{this.#t&&(this.#t._handle=s,s.close=r,this.#t.close=o,this.#t.removeAllListeners("error"))}this.#t&&this.#t.on("error",u=>this.#r(new jn(u,this.write)));let l;if(c)if(Array.isArray(c)&&c.length>0){let u=c[0];l=this[Qi](Pi.from(u));for(let m=1;m<c.length;m++)l=this[Qi](c[m])}else l=this[Qi](Pi.from(c));return n&&n(),l}},Tr=class extends js{#e;#n;constructor(e,i){e=e||{},e.flush=e.flush||Ve.Z_NO_FLUSH,e.finishFlush=e.finishFlush||Ve.Z_FINISH,e.fullFlushFlag=Ve.Z_FULL_FLUSH,super(e,i),this.#e=e.level,this.#n=e.strategy}params(e,i){if(!this.sawError){if(!this.handle)throw new Error("cannot switch params when binding is closed");if(!this.handle.params)throw new Error("not supported in this implementation");if(this.#e!==e||this.#n!==i){this.flush(Ve.Z_SYNC_FLUSH),$c(this.handle,"zlib binding closed");let n=this.handle.flush;this.handle.flush=(s,r)=>{typeof s=="function"&&(r=s,s=this.flushFlag),this.flush(s),r?.()};try{this.handle.params(e,i)}finally{this.handle.flush=n}this.handle&&(this.#e=e,this.#n=i)}}}};var Xr=class extends Tr{#e;constructor(e){super(e,"Gzip"),this.#e=e&&!!e.portable}[Qi](e){return this.#e?(this.#e=!1,e[9]=255,super[Qi](e)):super[Qi](e)}};var Hr=class extends Tr{constructor(e){super(e,"Unzip")}},Lr=class extends js{constructor(e,i){e=e||{},e.flush=e.flush||Ve.BROTLI_OPERATION_PROCESS,e.finishFlush=e.finishFlush||Ve.BROTLI_OPERATION_FINISH,e.fullFlushFlag=Ve.BROTLI_OPERATION_FLUSH,super(e,i)}},_r=class extends Lr{constructor(e){super(e,"BrotliCompress")}},$r=class extends Lr{constructor(e){super(e,"BrotliDecompress")}},eo=class extends js{constructor(e,i){e=e||{},e.flush=e.flush||Ve.ZSTD_e_continue,e.finishFlush=e.finishFlush||Ve.ZSTD_e_end,e.fullFlushFlag=Ve.ZSTD_e_flush,super(e,i)}},to=class extends eo{constructor(e){super(e,"ZstdCompress")}},io=class extends eo{constructor(e){super(e,"ZstdDecompress")}};import{posix as xn}from"node:path";var h3=(t,e)=>{if(Number.isSafeInteger(t))t<0?Nf(t,e):Vf(t,e);else throw Error("cannot encode number outside of javascript safe integer range");return e},Vf=(t,e)=>{e[0]=128;for(var i=e.length;i>1;i--)e[i-1]=t&255,t=Math.floor(t/256)},Nf=(t,e)=>{e[0]=255;var i=!1;t=t*-1;for(var n=e.length;n>1;n--){var s=t&255;t=Math.floor(t/256),i?e[n-1]=I3(s):s===0?e[n-1]=0:(i=!0,e[n-1]=E3(s))}},g3=t=>{let e=t[0],i=e===128?bf(t.subarray(1,t.length)):e===255?Ff(t):null;if(i===null)throw Error("invalid base256 encoding");if(!Number.isSafeInteger(i))throw Error("parsed number outside of javascript safe integer range");return i},Ff=t=>{for(var e=t.length,i=0,n=!1,s=e-1;s>-1;s--){var r=Number(t[s]),o;n?o=I3(r):r===0?o=r:(n=!0,o=E3(r)),o!==0&&(i-=o*Math.pow(256,e-s-1))}return i},bf=t=>{for(var e=t.length,i=0,n=e-1;n>-1;n--){var s=Number(t[n]);s!==0&&(i+=s*Math.pow(256,e-n-1))}return i},I3=t=>(255^t)&255,E3=t=>(255^t)+1&255;var no=t=>so.has(t);var so=new Map([["0","File"],["","OldFile"],["1","Link"],["2","SymbolicLink"],["3","CharacterDevice"],["4","BlockDevice"],["5","Directory"],["6","FIFO"],["7","ContiguousFile"],["g","GlobalExtendedHeader"],["x","ExtendedHeader"],["A","SolarisACL"],["D","GNUDumpDir"],["I","Inode"],["K","NextFileHasLongLinkpath"],["L","NextFileHasLongPath"],["M","ContinuationFile"],["N","OldGnuLongPath"],["S","SparseFile"],["V","TapeVolumeHeader"],["X","OldExtendedHeader"]]),R3=new Map(Array.from(so).map(t=>[t[1],t[0]]));var ze=class{cksumValid=!1;needPax=!1;nullBlock=!1;block;path;mode;uid;gid;size;cksum;#e="Unsupported";linkpath;uname;gname;devmaj=0;devmin=0;atime;ctime;mtime;charset;comment;constructor(e,i=0,n,s){Buffer.isBuffer(e)?this.decode(e,i||0,n,s):e&&this.#n(e)}decode(e,i,n,s){if(i||(i=0),!e||!(e.length>=i+512))throw new Error("need 512 bytes for header");this.path=n?.path??Bi(e,i,100),this.mode=n?.mode??s?.mode??$t(e,i+100,8),this.uid=n?.uid??s?.uid??$t(e,i+108,8),this.gid=n?.gid??s?.gid??$t(e,i+116,8),this.size=n?.size??s?.size??$t(e,i+124,12),this.mtime=n?.mtime??s?.mtime??el(e,i+136,12),this.cksum=$t(e,i+148,12),s&&this.#n(s,!0),n&&this.#n(n);let r=Bi(e,i+156,1);if(no(r)&&(this.#e=r||"0"),this.#e==="0"&&this.path.slice(-1)==="/"&&(this.#e="5"),this.#e==="5"&&(this.size=0),this.linkpath=Bi(e,i+157,100),e.subarray(i+257,i+265).toString()==="ustar\x0000")if(this.uname=n?.uname??s?.uname??Bi(e,i+265,32),this.gname=n?.gname??s?.gname??Bi(e,i+297,32),this.devmaj=n?.devmaj??s?.devmaj??$t(e,i+329,8)??0,this.devmin=n?.devmin??s?.devmin??$t(e,i+337,8)??0,e[i+475]!==0){let c=Bi(e,i+345,155);this.path=c+"/"+this.path}else{let c=Bi(e,i+345,130);c&&(this.path=c+"/"+this.path),this.atime=n?.atime??s?.atime??el(e,i+476,12),this.ctime=n?.ctime??s?.ctime??el(e,i+488,12)}let o=256;for(let c=i;c<i+148;c++)o+=e[c];for(let c=i+156;c<i+512;c++)o+=e[c];this.cksumValid=o===this.cksum,this.cksum===void 0&&o===256&&(this.nullBlock=!0)}#n(e,i=!1){Object.assign(this,Object.fromEntries(Object.entries(e).filter(([n,s])=>!(s==null||n==="path"&&i||n==="linkpath"&&i||n==="global"))))}encode(e,i=0){if(e||(e=this.block=Buffer.alloc(512)),this.#e==="Unsupported"&&(this.#e="0"),!(e.length>=i+512))throw new Error("need 512 bytes for header");let n=this.ctime||this.atime?130:155,s=Qf(this.path||"",n),r=s[0],o=s[1];this.needPax=!!s[2],this.needPax=Ji(e,i,100,r)||this.needPax,this.needPax=ei(e,i+100,8,this.mode)||this.needPax,this.needPax=ei(e,i+108,8,this.uid)||this.needPax,this.needPax=ei(e,i+116,8,this.gid)||this.needPax,this.needPax=ei(e,i+124,12,this.size)||this.needPax,this.needPax=tl(e,i+136,12,this.mtime)||this.needPax,e[i+156]=this.#e.charCodeAt(0),this.needPax=Ji(e,i+157,100,this.linkpath)||this.needPax,e.write("ustar\x0000",i+257,8),this.needPax=Ji(e,i+265,32,this.uname)||this.needPax,this.needPax=Ji(e,i+297,32,this.gname)||this.needPax,this.needPax=ei(e,i+329,8,this.devmaj)||this.needPax,this.needPax=ei(e,i+337,8,this.devmin)||this.needPax,this.needPax=Ji(e,i+345,n,o)||this.needPax,e[i+475]!==0?this.needPax=Ji(e,i+345,155,o)||this.needPax:(this.needPax=Ji(e,i+345,130,o)||this.needPax,this.needPax=tl(e,i+476,12,this.atime)||this.needPax,this.needPax=tl(e,i+488,12,this.ctime)||this.needPax);let c=256;for(let l=i;l<i+148;l++)c+=e[l];for(let l=i+156;l<i+512;l++)c+=e[l];return this.cksum=c,ei(e,i+148,8,this.cksum),this.cksumValid=!0,this.needPax}get type(){return this.#e==="Unsupported"?this.#e:so.get(this.#e)}get typeKey(){return this.#e}set type(e){let i=String(R3.get(e));if(no(i)||i==="Unsupported")this.#e=i;else if(no(e))this.#e=e;else throw new TypeError("invalid entry type: "+e)}},Qf=(t,e)=>{let n=t,s="",r,o=xn.parse(t).root||".";if(Buffer.byteLength(n)<100)r=[n,s,!1];else{s=xn.dirname(n),n=xn.basename(n);do Buffer.byteLength(n)<=100&&Buffer.byteLength(s)<=e?r=[n,s,!1]:Buffer.byteLength(n)>100&&Buffer.byteLength(s)<=e?r=[n.slice(0,99),s,!0]:(n=xn.join(xn.basename(s),n),s=xn.dirname(s));while(s!==o&&r===void 0);r||(r=[t.slice(0,99),"",!0])}return r},Bi=(t,e,i)=>t.subarray(e,e+i).toString("utf8").replace(/\0.*/,""),el=(t,e,i)=>Bf($t(t,e,i)),Bf=t=>t===void 0?void 0:new Date(t*1e3),$t=(t,e,i)=>Number(t[e])&128?g3(t.subarray(e,e+i)):Zf(t,e,i),Jf=t=>isNaN(t)?void 0:t,Zf=(t,e,i)=>Jf(parseInt(t.subarray(e,e+i).toString("utf8").replace(/\0.*$/,"").trim(),8)),yf={12:8589934591,8:2097151},ei=(t,e,i,n)=>n===void 0?!1:n>yf[i]||n<0?(h3(n,t.subarray(e,e+i)),!0):(qf(t,e,i,n),!1),qf=(t,e,i,n)=>t.write(wf(n,i),e,i,"ascii"),wf=(t,e)=>Df(Math.floor(t).toString(8),e),Df=(t,e)=>(t.length===e-1?t:new Array(e-t.length-1).join("0")+t+" ")+"\0",tl=(t,e,i,n)=>n===void 0?!1:ei(t,e,i,n.getTime()/1e3),Tf=new Array(156).join("\0"),Ji=(t,e,i,n)=>n===void 0?!1:(t.write(n+Tf,e,i,"utf8"),n.length!==Buffer.byteLength(n)||n.length>i);import{basename as Xf}from"node:path";var ti=class t{atime;mtime;ctime;charset;comment;gid;uid;gname;uname;linkpath;dev;ino;nlink;path;size;mode;global;constructor(e,i=!1){this.atime=e.atime,this.charset=e.charset,this.comment=e.comment,this.ctime=e.ctime,this.dev=e.dev,this.gid=e.gid,this.global=i,this.gname=e.gname,this.ino=e.ino,this.linkpath=e.linkpath,this.mtime=e.mtime,this.nlink=e.nlink,this.path=e.path,this.size=e.size,this.uid=e.uid,this.uname=e.uname}encode(){let e=this.encodeBody();if(e==="")return Buffer.allocUnsafe(0);let i=Buffer.byteLength(e),n=512*Math.ceil(1+i/512),s=Buffer.allocUnsafe(n);for(let r=0;r<512;r++)s[r]=0;new ze({path:("PaxHeader/"+Xf(this.path??"")).slice(0,99),mode:this.mode||420,uid:this.uid,gid:this.gid,size:i,mtime:this.mtime,type:this.global?"GlobalExtendedHeader":"ExtendedHeader",linkpath:"",uname:this.uname||"",gname:this.gname||"",devmaj:0,devmin:0,atime:this.atime,ctime:this.ctime}).encode(s),s.write(e,512,i,"utf8");for(let r=i+512;r<s.length;r++)s[r]=0;return s}encodeBody(){return this.encodeField("path")+this.encodeField("ctime")+this.encodeField("atime")+this.encodeField("dev")+this.encodeField("ino")+this.encodeField("nlink")+this.encodeField("charset")+this.encodeField("comment")+this.encodeField("gid")+this.encodeField("gname")+this.encodeField("linkpath")+this.encodeField("mtime")+this.encodeField("size")+this.encodeField("uid")+this.encodeField("uname")}encodeField(e){if(this[e]===void 0)return"";let i=this[e],n=i instanceof Date?i.getTime()/1e3:i,s=" "+(e==="dev"||e==="ino"||e==="nlink"?"SCHILY.":"")+e+"="+n+`
47
+ `,r=Buffer.byteLength(s),o=Math.floor(Math.log(r)/Math.log(10))+1;return r+o>=Math.pow(10,o)&&(o+=1),o+r+s}static parse(e,i,n=!1){return new t(Hf(Lf(e),i),n)}},Hf=(t,e)=>e?Object.assign({},e,t):t,Lf=t=>t.replace(/\n$/,"").split(`
48
+ `).reduce(_f,Object.create(null)),_f=(t,e)=>{let i=parseInt(e,10);if(i!==Buffer.byteLength(e)+1)return t;e=e.slice((i+" ").length);let n=e.split("="),s=n.shift();if(!s)return t;let r=s.replace(/^SCHILY\.(dev|ino|nlink)/,"$1"),o=n.join("=");return t[r]=/^([A-Z]+\.)?([mac]|birth|creation)time$/.test(r)?new Date(Number(o)*1e3):/^[0-9]+$/.test(o)?+o:o,t};import{EventEmitter as cl}from"node:events";import M3 from"node:stream";import{StringDecoder as $f}from"node:string_decoder";var j3=typeof process=="object"&&process?process:{stdout:null,stderr:null},e7=t=>!!t&&typeof t=="object"&&(t instanceof dt||t instanceof M3||t7(t)||i7(t)),t7=t=>!!t&&typeof t=="object"&&t instanceof cl&&typeof t.pipe=="function"&&t.pipe!==M3.Writable.prototype.pipe,i7=t=>!!t&&typeof t=="object"&&t instanceof cl&&typeof t.write=="function"&&typeof t.end=="function",Ut=Symbol("EOF"),Kt=Symbol("maybeEmitEnd"),ii=Symbol("emittedEnd"),ro=Symbol("emittingEnd"),xs=Symbol("emittedError"),oo=Symbol("closed"),x3=Symbol("read"),ao=Symbol("flush"),S3=Symbol("flushChunk"),Le=Symbol("encoding"),Sn=Symbol("decoder"),L=Symbol("flowing"),Ss=Symbol("paused"),Gn=Symbol("resume"),_=Symbol("buffer"),me=Symbol("pipes"),$=Symbol("bufferLength"),il=Symbol("bufferPush"),co=Symbol("bufferShift"),oe=Symbol("objectMode"),F=Symbol("destroyed"),nl=Symbol("error"),sl=Symbol("emitData"),G3=Symbol("emitEnd"),rl=Symbol("emitEnd2"),At=Symbol("async"),ol=Symbol("abort"),lo=Symbol("aborted"),Gs=Symbol("signal"),Zi=Symbol("dataListeners"),je=Symbol("discarded"),Ms=t=>Promise.resolve().then(t),n7=t=>t(),s7=t=>t==="end"||t==="finish"||t==="prefinish",r7=t=>t instanceof ArrayBuffer||!!t&&typeof t=="object"&&t.constructor&&t.constructor.name==="ArrayBuffer"&&t.byteLength>=0,o7=t=>!Buffer.isBuffer(t)&&ArrayBuffer.isView(t),uo=class{src;dest;opts;ondrain;constructor(e,i,n){this.src=e,this.dest=i,this.opts=n,this.ondrain=()=>e[Gn](),this.dest.on("drain",this.ondrain)}unpipe(){this.dest.removeListener("drain",this.ondrain)}proxyErrors(e){}end(){this.unpipe(),this.opts.end&&this.dest.end()}},al=class extends uo{unpipe(){this.src.removeListener("error",this.proxyErrors),super.unpipe()}constructor(e,i,n){super(e,i,n),this.proxyErrors=s=>i.emit("error",s),e.on("error",this.proxyErrors)}},a7=t=>!!t.objectMode,c7=t=>!t.objectMode&&!!t.encoding&&t.encoding!=="buffer",dt=class extends cl{[L]=!1;[Ss]=!1;[me]=[];[_]=[];[oe];[Le];[At];[Sn];[Ut]=!1;[ii]=!1;[ro]=!1;[oo]=!1;[xs]=null;[$]=0;[F]=!1;[Gs];[lo]=!1;[Zi]=0;[je]=!1;writable=!0;readable=!0;constructor(...e){let i=e[0]||{};if(super(),i.objectMode&&typeof i.encoding=="string")throw new TypeError("Encoding and objectMode may not be used together");a7(i)?(this[oe]=!0,this[Le]=null):c7(i)?(this[Le]=i.encoding,this[oe]=!1):(this[oe]=!1,this[Le]=null),this[At]=!!i.async,this[Sn]=this[Le]?new $f(this[Le]):null,i&&i.debugExposeBuffer===!0&&Object.defineProperty(this,"buffer",{get:()=>this[_]}),i&&i.debugExposePipes===!0&&Object.defineProperty(this,"pipes",{get:()=>this[me]});let{signal:n}=i;n&&(this[Gs]=n,n.aborted?this[ol]():n.addEventListener("abort",()=>this[ol]()))}get bufferLength(){return this[$]}get encoding(){return this[Le]}set encoding(e){throw new Error("Encoding must be set at instantiation time")}setEncoding(e){throw new Error("Encoding must be set at instantiation time")}get objectMode(){return this[oe]}set objectMode(e){throw new Error("objectMode must be set at instantiation time")}get async(){return this[At]}set async(e){this[At]=this[At]||!!e}[ol](){this[lo]=!0,this.emit("abort",this[Gs]?.reason),this.destroy(this[Gs]?.reason)}get aborted(){return this[lo]}set aborted(e){}write(e,i,n){if(this[lo])return!1;if(this[Ut])throw new Error("write after end");if(this[F])return this.emit("error",Object.assign(new Error("Cannot call write after a stream was destroyed"),{code:"ERR_STREAM_DESTROYED"})),!0;typeof i=="function"&&(n=i,i="utf8"),i||(i="utf8");let s=this[At]?Ms:n7;if(!this[oe]&&!Buffer.isBuffer(e)){if(o7(e))e=Buffer.from(e.buffer,e.byteOffset,e.byteLength);else if(r7(e))e=Buffer.from(e);else if(typeof e!="string")throw new Error("Non-contiguous data written to non-objectMode stream")}return this[oe]?(this[L]&&this[$]!==0&&this[ao](!0),this[L]?this.emit("data",e):this[il](e),this[$]!==0&&this.emit("readable"),n&&s(n),this[L]):e.length?(typeof e=="string"&&!(i===this[Le]&&!this[Sn]?.lastNeed)&&(e=Buffer.from(e,i)),Buffer.isBuffer(e)&&this[Le]&&(e=this[Sn].write(e)),this[L]&&this[$]!==0&&this[ao](!0),this[L]?this.emit("data",e):this[il](e),this[$]!==0&&this.emit("readable"),n&&s(n),this[L]):(this[$]!==0&&this.emit("readable"),n&&s(n),this[L])}read(e){if(this[F])return null;if(this[je]=!1,this[$]===0||e===0||e&&e>this[$])return this[Kt](),null;this[oe]&&(e=null),this[_].length>1&&!this[oe]&&(this[_]=[this[Le]?this[_].join(""):Buffer.concat(this[_],this[$])]);let i=this[x3](e||null,this[_][0]);return this[Kt](),i}[x3](e,i){if(this[oe])this[co]();else{let n=i;e===n.length||e===null?this[co]():typeof n=="string"?(this[_][0]=n.slice(e),i=n.slice(0,e),this[$]-=e):(this[_][0]=n.subarray(e),i=n.subarray(0,e),this[$]-=e)}return this.emit("data",i),!this[_].length&&!this[Ut]&&this.emit("drain"),i}end(e,i,n){return typeof e=="function"&&(n=e,e=void 0),typeof i=="function"&&(n=i,i="utf8"),e!==void 0&&this.write(e,i),n&&this.once("end",n),this[Ut]=!0,this.writable=!1,(this[L]||!this[Ss])&&this[Kt](),this}[Gn](){this[F]||(!this[Zi]&&!this[me].length&&(this[je]=!0),this[Ss]=!1,this[L]=!0,this.emit("resume"),this[_].length?this[ao]():this[Ut]?this[Kt]():this.emit("drain"))}resume(){return this[Gn]()}pause(){this[L]=!1,this[Ss]=!0,this[je]=!1}get destroyed(){return this[F]}get flowing(){return this[L]}get paused(){return this[Ss]}[il](e){this[oe]?this[$]+=1:this[$]+=e.length,this[_].push(e)}[co](){return this[oe]?this[$]-=1:this[$]-=this[_][0].length,this[_].shift()}[ao](e=!1){do;while(this[S3](this[co]())&&this[_].length);!e&&!this[_].length&&!this[Ut]&&this.emit("drain")}[S3](e){return this.emit("data",e),this[L]}pipe(e,i){if(this[F])return e;this[je]=!1;let n=this[ii];return i=i||{},e===j3.stdout||e===j3.stderr?i.end=!1:i.end=i.end!==!1,i.proxyErrors=!!i.proxyErrors,n?i.end&&e.end():(this[me].push(i.proxyErrors?new al(this,e,i):new uo(this,e,i)),this[At]?Ms(()=>this[Gn]()):this[Gn]()),e}unpipe(e){let i=this[me].find(n=>n.dest===e);i&&(this[me].length===1?(this[L]&&this[Zi]===0&&(this[L]=!1),this[me]=[]):this[me].splice(this[me].indexOf(i),1),i.unpipe())}addListener(e,i){return this.on(e,i)}on(e,i){let n=super.on(e,i);if(e==="data")this[je]=!1,this[Zi]++,!this[me].length&&!this[L]&&this[Gn]();else if(e==="readable"&&this[$]!==0)super.emit("readable");else if(s7(e)&&this[ii])super.emit(e),this.removeAllListeners(e);else if(e==="error"&&this[xs]){let s=i;this[At]?Ms(()=>s.call(this,this[xs])):s.call(this,this[xs])}return n}removeListener(e,i){return this.off(e,i)}off(e,i){let n=super.off(e,i);return e==="data"&&(this[Zi]=this.listeners("data").length,this[Zi]===0&&!this[je]&&!this[me].length&&(this[L]=!1)),n}removeAllListeners(e){let i=super.removeAllListeners(e);return(e==="data"||e===void 0)&&(this[Zi]=0,!this[je]&&!this[me].length&&(this[L]=!1)),i}get emittedEnd(){return this[ii]}[Kt](){!this[ro]&&!this[ii]&&!this[F]&&this[_].length===0&&this[Ut]&&(this[ro]=!0,this.emit("end"),this.emit("prefinish"),this.emit("finish"),this[oo]&&this.emit("close"),this[ro]=!1)}emit(e,...i){let n=i[0];if(e!=="error"&&e!=="close"&&e!==F&&this[F])return!1;if(e==="data")return!this[oe]&&!n?!1:this[At]?(Ms(()=>this[sl](n)),!0):this[sl](n);if(e==="end")return this[G3]();if(e==="close"){if(this[oo]=!0,!this[ii]&&!this[F])return!1;let r=super.emit("close");return this.removeAllListeners("close"),r}else if(e==="error"){this[xs]=n,super.emit(nl,n);let r=!this[Gs]||this.listeners("error").length?super.emit("error",n):!1;return this[Kt](),r}else if(e==="resume"){let r=super.emit("resume");return this[Kt](),r}else if(e==="finish"||e==="prefinish"){let r=super.emit(e);return this.removeAllListeners(e),r}let s=super.emit(e,...i);return this[Kt](),s}[sl](e){for(let n of this[me])n.dest.write(e)===!1&&this.pause();let i=this[je]?!1:super.emit("data",e);return this[Kt](),i}[G3](){return this[ii]?!1:(this[ii]=!0,this.readable=!1,this[At]?(Ms(()=>this[rl]()),!0):this[rl]())}[rl](){if(this[Sn]){let i=this[Sn].end();if(i){for(let n of this[me])n.dest.write(i);this[je]||super.emit("data",i)}}for(let i of this[me])i.end();let e=super.emit("end");return this.removeAllListeners("end"),e}async collect(){let e=Object.assign([],{dataLength:0});this[oe]||(e.dataLength=0);let i=this.promise();return this.on("data",n=>{e.push(n),this[oe]||(e.dataLength+=n.length)}),await i,e}async concat(){if(this[oe])throw new Error("cannot concat in objectMode");let e=await this.collect();return this[Le]?e.join(""):Buffer.concat(e,e.dataLength)}async promise(){return new Promise((e,i)=>{this.on(F,()=>i(new Error("stream destroyed"))),this.on("error",n=>i(n)),this.on("end",()=>e())})}[Symbol.asyncIterator](){this[je]=!1;let e=!1,i=async()=>(this.pause(),e=!0,{value:void 0,done:!0});return{next:()=>{if(e)return i();let s=this.read();if(s!==null)return Promise.resolve({done:!1,value:s});if(this[Ut])return i();let r,o,c=p=>{this.off("data",l),this.off("end",u),this.off(F,m),i(),o(p)},l=p=>{this.off("error",c),this.off("end",u),this.off(F,m),this.pause(),r({value:p,done:!!this[Ut]})},u=()=>{this.off("error",c),this.off("data",l),this.off(F,m),i(),r({done:!0,value:void 0})},m=()=>c(new Error("stream destroyed"));return new Promise((p,d)=>{o=d,r=p,this.once(F,m),this.once("error",c),this.once("end",u),this.once("data",l)})},throw:i,return:i,[Symbol.asyncIterator](){return this}}}[Symbol.iterator](){this[je]=!1;let e=!1,i=()=>(this.pause(),this.off(nl,i),this.off(F,i),this.off("end",i),e=!0,{done:!0,value:void 0}),n=()=>{if(e)return i();let s=this.read();return s===null?i():{done:!1,value:s}};return this.once("end",i),this.once(nl,i),this.once(F,i),{next:n,throw:i,return:i,[Symbol.iterator](){return this}}}destroy(e){if(this[F])return e?this.emit("error",e):this.emit(F),this;this[F]=!0,this[je]=!0,this[_].length=0,this[$]=0;let i=this;return typeof i.close=="function"&&!this[oo]&&i.close(),e?this.emit("error",e):this.emit(F),this}static get isStream(){return e7}};var l7=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,R=l7!=="win32"?t=>t:t=>t&&t.replace(/\\/g,"/");var Mn=class extends dt{extended;globalExtended;header;startBlockSize;blockRemain;remain;type;meta=!1;ignore=!1;path;mode;uid;gid;uname;gname;size=0;mtime;atime;ctime;linkpath;dev;ino;nlink;invalid=!1;absolute;unsupported=!1;constructor(e,i,n){switch(super({}),this.pause(),this.extended=i,this.globalExtended=n,this.header=e,this.remain=e.size??0,this.startBlockSize=512*Math.ceil(this.remain/512),this.blockRemain=this.startBlockSize,this.type=e.type,this.type){case"File":case"OldFile":case"Link":case"SymbolicLink":case"CharacterDevice":case"BlockDevice":case"Directory":case"FIFO":case"ContiguousFile":case"GNUDumpDir":break;case"NextFileHasLongLinkpath":case"NextFileHasLongPath":case"OldGnuLongPath":case"GlobalExtendedHeader":case"ExtendedHeader":case"OldExtendedHeader":this.meta=!0;break;default:this.ignore=!0}if(!e.path)throw new Error("no path provided for tar.ReadEntry");this.path=R(e.path),this.mode=e.mode,this.mode&&(this.mode=this.mode&4095),this.uid=e.uid,this.gid=e.gid,this.uname=e.uname,this.gname=e.gname,this.size=this.remain,this.mtime=e.mtime,this.atime=e.atime,this.ctime=e.ctime,this.linkpath=e.linkpath?R(e.linkpath):void 0,this.uname=e.uname,this.gname=e.gname,i&&this.#e(i),n&&this.#e(n,!0)}write(e){let i=e.length;if(i>this.blockRemain)throw new Error("writing more to entry than is appropriate");let n=this.remain,s=this.blockRemain;return this.remain=Math.max(0,n-i),this.blockRemain=Math.max(0,s-i),this.ignore?!0:n>=i?super.write(e):super.write(e.subarray(0,n))}#e(e,i=!1){e.path&&(e.path=R(e.path)),e.linkpath&&(e.linkpath=R(e.linkpath)),Object.assign(this,Object.fromEntries(Object.entries(e).filter(([n,s])=>!(s==null||n==="path"&&i))))}};var yi=(t,e,i,n={})=>{t.file&&(n.file=t.file),t.cwd&&(n.cwd=t.cwd),n.code=i instanceof Error&&i.code||e,n.tarCode=e,!t.strict&&n.recoverable!==!1?(i instanceof Error&&(n=Object.assign(i,n),i=i.message),t.emit("warn",e,i,n)):i instanceof Error?t.emit("error",Object.assign(i,n)):t.emit("error",Object.assign(new Error(`${e}: ${i}`),n))};var m7=1024*1024,pl=Buffer.from([31,139]),Al=Buffer.from([40,181,47,253]),v7=Math.max(pl.length,Al.length),Ne=Symbol("state"),qi=Symbol("writeEntry"),kt=Symbol("readEntry"),ll=Symbol("nextEntry"),Y3=Symbol("processEntry"),ft=Symbol("extendedHeader"),Ys=Symbol("globalExtendedHeader"),ni=Symbol("meta"),W3=Symbol("emitMeta"),S=Symbol("buffer"),Vt=Symbol("queue"),si=Symbol("ended"),ul=Symbol("emittedEnd"),wi=Symbol("emit"),b=Symbol("unzip"),mo=Symbol("consumeChunk"),vo=Symbol("consumeChunkSub"),ml=Symbol("consumeBody"),C3=Symbol("consumeMeta"),O3=Symbol("consumeHeader"),Ws=Symbol("consuming"),vl=Symbol("bufferConcat"),po=Symbol("maybeEnd"),Yn=Symbol("writing"),ri=Symbol("aborted"),Ao=Symbol("onDone"),Di=Symbol("sawValidEntry"),fo=Symbol("sawNullBlock"),ho=Symbol("sawEOF"),U3=Symbol("closeStream"),p7=()=>!0,Nt=class extends u7{file;strict;maxMetaEntrySize;filter;brotli;zstd;writable=!0;readable=!1;[Vt]=[];[S];[kt];[qi];[Ne]="begin";[ni]="";[ft];[Ys];[si]=!1;[b];[ri]=!1;[Di];[fo]=!1;[ho]=!1;[Yn]=!1;[Ws]=!1;[ul]=!1;constructor(e={}){super(),this.file=e.file||"",this.on(Ao,()=>{(this[Ne]==="begin"||this[Di]===!1)&&this.warn("TAR_BAD_ARCHIVE","Unrecognized archive format")}),e.ondone?this.on(Ao,e.ondone):this.on(Ao,()=>{this.emit("prefinish"),this.emit("finish"),this.emit("end")}),this.strict=!!e.strict,this.maxMetaEntrySize=e.maxMetaEntrySize||m7,this.filter=typeof e.filter=="function"?e.filter:p7;let i=e.file&&(e.file.endsWith(".tar.br")||e.file.endsWith(".tbr"));this.brotli=!(e.gzip||e.zstd)&&e.brotli!==void 0?e.brotli:i?void 0:!1;let n=e.file&&(e.file.endsWith(".tar.zst")||e.file.endsWith(".tzst"));this.zstd=!(e.gzip||e.brotli)&&e.zstd!==void 0?e.zstd:n?!0:void 0,this.on("end",()=>this[U3]()),typeof e.onwarn=="function"&&this.on("warn",e.onwarn),typeof e.onReadEntry=="function"&&this.on("entry",e.onReadEntry)}warn(e,i,n={}){yi(this,e,i,n)}[O3](e,i){this[Di]===void 0&&(this[Di]=!1);let n;try{n=new ze(e,i,this[ft],this[Ys])}catch(s){return this.warn("TAR_ENTRY_INVALID",s)}if(n.nullBlock)this[fo]?(this[ho]=!0,this[Ne]==="begin"&&(this[Ne]="header"),this[wi]("eof")):(this[fo]=!0,this[wi]("nullBlock"));else if(this[fo]=!1,!n.cksumValid)this.warn("TAR_ENTRY_INVALID","checksum failure",{header:n});else if(!n.path)this.warn("TAR_ENTRY_INVALID","path is required",{header:n});else{let s=n.type;if(/^(Symbolic)?Link$/.test(s)&&!n.linkpath)this.warn("TAR_ENTRY_INVALID","linkpath required",{header:n});else if(!/^(Symbolic)?Link$/.test(s)&&!/^(Global)?ExtendedHeader$/.test(s)&&n.linkpath)this.warn("TAR_ENTRY_INVALID","linkpath forbidden",{header:n});else{let r=this[qi]=new Mn(n,this[ft],this[Ys]);if(!this[Di])if(r.remain){let o=()=>{r.invalid||(this[Di]=!0)};r.on("end",o)}else this[Di]=!0;r.meta?r.size>this.maxMetaEntrySize?(r.ignore=!0,this[wi]("ignoredEntry",r),this[Ne]="ignore",r.resume()):r.size>0&&(this[ni]="",r.on("data",o=>this[ni]+=o),this[Ne]="meta"):(this[ft]=void 0,r.ignore=r.ignore||!this.filter(r.path,r),r.ignore?(this[wi]("ignoredEntry",r),this[Ne]=r.remain?"ignore":"header",r.resume()):(r.remain?this[Ne]="body":(this[Ne]="header",r.end()),this[kt]?this[Vt].push(r):(this[Vt].push(r),this[ll]())))}}}[U3](){queueMicrotask(()=>this.emit("close"))}[Y3](e){let i=!0;if(!e)this[kt]=void 0,i=!1;else if(Array.isArray(e)){let[n,...s]=e;this.emit(n,...s)}else this[kt]=e,this.emit("entry",e),e.emittedEnd||(e.on("end",()=>this[ll]()),i=!1);return i}[ll](){do;while(this[Y3](this[Vt].shift()));if(!this[Vt].length){let e=this[kt];!e||e.flowing||e.size===e.remain?this[Yn]||this.emit("drain"):e.once("drain",()=>this.emit("drain"))}}[ml](e,i){let n=this[qi];if(!n)throw new Error("attempt to consume body without entry??");let s=n.blockRemain??0,r=s>=e.length&&i===0?e:e.subarray(i,i+s);return n.write(r),n.blockRemain||(this[Ne]="header",this[qi]=void 0,n.end()),r.length}[C3](e,i){let n=this[qi],s=this[ml](e,i);return!this[qi]&&n&&this[W3](n),s}[wi](e,i,n){!this[Vt].length&&!this[kt]?this.emit(e,i,n):this[Vt].push([e,i,n])}[W3](e){switch(this[wi]("meta",this[ni]),e.type){case"ExtendedHeader":case"OldExtendedHeader":this[ft]=ti.parse(this[ni],this[ft],!1);break;case"GlobalExtendedHeader":this[Ys]=ti.parse(this[ni],this[Ys],!0);break;case"NextFileHasLongPath":case"OldGnuLongPath":{let i=this[ft]??Object.create(null);this[ft]=i,i.path=this[ni].replace(/\0.*/,"");break}case"NextFileHasLongLinkpath":{let i=this[ft]||Object.create(null);this[ft]=i,i.linkpath=this[ni].replace(/\0.*/,"");break}default:throw new Error("unknown meta: "+e.type)}}abort(e){this[ri]=!0,this.emit("abort",e),this.warn("TAR_ABORT",e,{recoverable:!1})}write(e,i,n){if(typeof i=="function"&&(n=i,i=void 0),typeof e=="string"&&(e=Buffer.from(e,typeof i=="string"?i:"utf8")),this[ri])return n?.(),!1;if((this[b]===void 0||this.brotli===void 0&&this[b]===!1)&&e){if(this[S]&&(e=Buffer.concat([this[S],e]),this[S]=void 0),e.length<v7)return this[S]=e,n?.(),!0;for(let l=0;this[b]===void 0&&l<pl.length;l++)e[l]!==pl[l]&&(this[b]=!1);let o=!1;if(this[b]===!1&&this.zstd!==!1){o=!0;for(let l=0;l<Al.length;l++)if(e[l]!==Al[l]){o=!1;break}}let c=this.brotli===void 0&&!o;if(this[b]===!1&&c)if(e.length<512)if(this[si])this.brotli=!0;else return this[S]=e,n?.(),!0;else try{new ze(e.subarray(0,512)),this.brotli=!1}catch{this.brotli=!0}if(this[b]===void 0||this[b]===!1&&(this.brotli||o)){let l=this[si];this[si]=!1,this[b]=this[b]===void 0?new Hr({}):o?new io({}):new $r({}),this[b].on("data",m=>this[mo](m)),this[b].on("error",m=>this.abort(m)),this[b].on("end",()=>{this[si]=!0,this[mo]()}),this[Yn]=!0;let u=!!this[b][l?"end":"write"](e);return this[Yn]=!1,n?.(),u}}this[Yn]=!0,this[b]?this[b].write(e):this[mo](e),this[Yn]=!1;let r=this[Vt].length?!1:this[kt]?this[kt].flowing:!0;return!r&&!this[Vt].length&&this[kt]?.once("drain",()=>this.emit("drain")),n?.(),r}[vl](e){e&&!this[ri]&&(this[S]=this[S]?Buffer.concat([this[S],e]):e)}[po](){if(this[si]&&!this[ul]&&!this[ri]&&!this[Ws]){this[ul]=!0;let e=this[qi];if(e&&e.blockRemain){let i=this[S]?this[S].length:0;this.warn("TAR_BAD_ARCHIVE",`Truncated input (needed ${e.blockRemain} more bytes, only ${i} available)`,{entry:e}),this[S]&&e.write(this[S]),e.end()}this[wi](Ao)}}[mo](e){if(this[Ws]&&e)this[vl](e);else if(!e&&!this[S])this[po]();else if(e){if(this[Ws]=!0,this[S]){this[vl](e);let i=this[S];this[S]=void 0,this[vo](i)}else this[vo](e);for(;this[S]&&this[S]?.length>=512&&!this[ri]&&!this[ho];){let i=this[S];this[S]=void 0,this[vo](i)}this[Ws]=!1}(!this[S]||this[si])&&this[po]()}[vo](e){let i=0,n=e.length;for(;i+512<=n&&!this[ri]&&!this[ho];)switch(this[Ne]){case"begin":case"header":this[O3](e,i),i+=512;break;case"ignore":case"body":i+=this[ml](e,i);break;case"meta":i+=this[C3](e,i);break;default:throw new Error("invalid state: "+this[Ne])}i<n&&(this[S]?this[S]=Buffer.concat([e.subarray(i),this[S]]):this[S]=e.subarray(i))}end(e,i,n){return typeof e=="function"&&(n=e,i=void 0,e=void 0),typeof i=="function"&&(n=i,i=void 0),typeof e=="string"&&(e=Buffer.from(e,i)),n&&this.once("finish",n),this[ri]||(this[b]?(e&&this[b].write(e),this[b].end()):(this[si]=!0,(this.brotli===void 0||this.zstd===void 0)&&(e=e||Buffer.alloc(0)),e&&this.write(e),this[po]())),this}};var oi=t=>{let e=t.length-1,i=-1;for(;e>-1&&t.charAt(e)==="/";)i=e,e--;return i===-1?t:t.slice(0,i)};var f7=t=>{let e=t.onReadEntry;t.onReadEntry=e?i=>{e(i),i.resume()}:i=>i.resume()},dl=(t,e)=>{let i=new Map(e.map(r=>[oi(r),!0])),n=t.filter,s=(r,o="")=>{let c=o||d7(r).root||".",l;if(r===c)l=!1;else{let u=i.get(r);u!==void 0?l=u:l=s(A7(r),c)}return i.set(r,l),l};t.filter=n?(r,o)=>n(r,o)&&s(oi(r)):r=>s(oi(r))},h7=t=>{let e=new Nt(t),i=t.file,n;try{n=Wn.openSync(i,"r");let s=Wn.fstatSync(n),r=t.maxReadSize||16*1024*1024;if(s.size<r){let o=Buffer.allocUnsafe(s.size),c=Wn.readSync(n,o,0,s.size,0);e.end(c===o.byteLength?o:o.subarray(0,c))}else{let o=0,c=Buffer.allocUnsafe(r);for(;o<s.size;){let l=Wn.readSync(n,c,0,r,o);if(l===0)break;o+=l,e.write(c.subarray(0,l))}e.end()}}finally{if(typeof n=="number")try{Wn.closeSync(n)}catch{}}},g7=(t,e)=>{let i=new Nt(t),n=t.maxReadSize||16*1024*1024,s=t.file;return new Promise((o,c)=>{i.on("error",c),i.on("end",o),Wn.stat(s,(l,u)=>{if(l)c(l);else{let m=new Fi(s,{readSize:n,size:u.size});m.on("error",c),m.pipe(i)}})})},Ti=vt(h7,g7,t=>new Nt(t),t=>new Nt(t),(t,e)=>{e?.length&&dl(t,e),t.noResume||f7(t)});import Co from"fs";import ht from"fs";import N3 from"path";var fl=(t,e,i)=>(t&=4095,i&&(t=(t|384)&-19),e&&(t&256&&(t|=64),t&32&&(t|=8),t&4&&(t|=1)),t);import{win32 as I7}from"node:path";var{isAbsolute:E7,parse:K3}=I7,Cs=t=>{let e="",i=K3(t);for(;E7(t)||i.root;){let n=t.charAt(0)==="/"&&t.slice(0,4)!=="//?/"?"/":i.root;t=t.slice(n.length),e+=n,i=K3(t)}return[e,t]};var go=["|","<",">","?",":"],hl=go.map(t=>String.fromCharCode(61440+t.charCodeAt(0))),R7=new Map(go.map((t,e)=>[t,hl[e]])),z7=new Map(hl.map((t,e)=>[t,go[e]])),gl=t=>go.reduce((e,i)=>e.split(i).join(R7.get(i)),t),k3=t=>hl.reduce((e,i)=>e.split(i).join(z7.get(i)),t);var B3=(t,e)=>e?(t=R(t).replace(/^\.(\/|$)/,""),oi(e)+"/"+t):R(t),j7=16*1024*1024,F3=Symbol("process"),b3=Symbol("file"),P3=Symbol("directory"),El=Symbol("symlink"),Q3=Symbol("hardlink"),Os=Symbol("header"),Io=Symbol("read"),Rl=Symbol("lstat"),Eo=Symbol("onlstat"),zl=Symbol("onread"),jl=Symbol("onreadlink"),xl=Symbol("openfile"),Sl=Symbol("onopenfile"),ai=Symbol("close"),Ro=Symbol("mode"),Gl=Symbol("awaitDrain"),Il=Symbol("ondrain"),gt=Symbol("prefix"),Us=class extends dt{path;portable;myuid=process.getuid&&process.getuid()||0;myuser=process.env.USER||"";maxReadSize;linkCache;statCache;preservePaths;cwd;strict;mtime;noPax;noMtime;prefix;fd;blockLen=0;blockRemain=0;buf;pos=0;remain=0;length=0;offset=0;win32;absolute;header;type;linkpath;stat;onWriteEntry;#e=!1;constructor(e,i={}){let n=hs(i);super(),this.path=R(e),this.portable=!!n.portable,this.maxReadSize=n.maxReadSize||j7,this.linkCache=n.linkCache||new Map,this.statCache=n.statCache||new Map,this.preservePaths=!!n.preservePaths,this.cwd=R(n.cwd||process.cwd()),this.strict=!!n.strict,this.noPax=!!n.noPax,this.noMtime=!!n.noMtime,this.mtime=n.mtime,this.prefix=n.prefix?R(n.prefix):void 0,this.onWriteEntry=n.onWriteEntry,typeof n.onwarn=="function"&&this.on("warn",n.onwarn);let s=!1;if(!this.preservePaths){let[o,c]=Cs(this.path);o&&typeof c=="string"&&(this.path=c,s=o)}this.win32=!!n.win32||process.platform==="win32",this.win32&&(this.path=k3(this.path.replace(/\\/g,"/")),e=e.replace(/\\/g,"/")),this.absolute=R(n.absolute||N3.resolve(this.cwd,e)),this.path===""&&(this.path="./"),s&&this.warn("TAR_ENTRY_INFO",`stripping ${s} from absolute path`,{entry:this,path:s+this.path});let r=this.statCache.get(this.absolute);r?this[Eo](r):this[Rl]()}warn(e,i,n={}){return yi(this,e,i,n)}emit(e,...i){return e==="error"&&(this.#e=!0),super.emit(e,...i)}[Rl](){ht.lstat(this.absolute,(e,i)=>{if(e)return this.emit("error",e);this[Eo](i)})}[Eo](e){this.statCache.set(this.absolute,e),this.stat=e,e.isFile()||(e.size=0),this.type=x7(e),this.emit("stat",e),this[F3]()}[F3](){switch(this.type){case"File":return this[b3]();case"Directory":return this[P3]();case"SymbolicLink":return this[El]();default:return this.end()}}[Ro](e){return fl(e,this.type==="Directory",this.portable)}[gt](e){return B3(e,this.prefix)}[Os](){if(!this.stat)throw new Error("cannot write header before stat");this.type==="Directory"&&this.portable&&(this.noMtime=!0),this.onWriteEntry?.(this),this.header=new ze({path:this[gt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[gt](this.linkpath):this.linkpath,mode:this[Ro](this.stat.mode),uid:this.portable?void 0:this.stat.uid,gid:this.portable?void 0:this.stat.gid,size:this.stat.size,mtime:this.noMtime?void 0:this.mtime||this.stat.mtime,type:this.type==="Unsupported"?void 0:this.type,uname:this.portable?void 0:this.stat.uid===this.myuid?this.myuser:"",atime:this.portable?void 0:this.stat.atime,ctime:this.portable?void 0:this.stat.ctime}),this.header.encode()&&!this.noPax&&super.write(new ti({atime:this.portable?void 0:this.header.atime,ctime:this.portable?void 0:this.header.ctime,gid:this.portable?void 0:this.header.gid,mtime:this.noMtime?void 0:this.mtime||this.header.mtime,path:this[gt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[gt](this.linkpath):this.linkpath,size:this.header.size,uid:this.portable?void 0:this.header.uid,uname:this.portable?void 0:this.header.uname,dev:this.portable?void 0:this.stat.dev,ino:this.portable?void 0:this.stat.ino,nlink:this.portable?void 0:this.stat.nlink}).encode());let e=this.header?.block;if(!e)throw new Error("failed to encode header");super.write(e)}[P3](){if(!this.stat)throw new Error("cannot create directory entry without stat");this.path.slice(-1)!=="/"&&(this.path+="/"),this.stat.size=0,this[Os](),this.end()}[El](){ht.readlink(this.absolute,(e,i)=>{if(e)return this.emit("error",e);this[jl](i)})}[jl](e){this.linkpath=R(e),this[Os](),this.end()}[Q3](e){if(!this.stat)throw new Error("cannot create link entry without stat");this.type="Link",this.linkpath=R(N3.relative(this.cwd,e)),this.stat.size=0,this[Os](),this.end()}[b3](){if(!this.stat)throw new Error("cannot create file entry without stat");if(this.stat.nlink>1){let e=`${this.stat.dev}:${this.stat.ino}`,i=this.linkCache.get(e);if(i?.indexOf(this.cwd)===0)return this[Q3](i);this.linkCache.set(e,this.absolute)}if(this[Os](),this.stat.size===0)return this.end();this[xl]()}[xl](){ht.open(this.absolute,"r",(e,i)=>{if(e)return this.emit("error",e);this[Sl](i)})}[Sl](e){if(this.fd=e,this.#e)return this[ai]();if(!this.stat)throw new Error("should stat before calling onopenfile");this.blockLen=512*Math.ceil(this.stat.size/512),this.blockRemain=this.blockLen;let i=Math.min(this.blockLen,this.maxReadSize);this.buf=Buffer.allocUnsafe(i),this.offset=0,this.pos=0,this.remain=this.stat.size,this.length=this.buf.length,this[Io]()}[Io](){let{fd:e,buf:i,offset:n,length:s,pos:r}=this;if(e===void 0||i===void 0)throw new Error("cannot read file without first opening");ht.read(e,i,n,s,r,(o,c)=>{if(o)return this[ai](()=>this.emit("error",o));this[zl](c)})}[ai](e=()=>{}){this.fd!==void 0&&ht.close(this.fd,e)}[zl](e){if(e<=0&&this.remain>0){let s=Object.assign(new Error("encountered unexpected EOF"),{path:this.absolute,syscall:"read",code:"EOF"});return this[ai](()=>this.emit("error",s))}if(e>this.remain){let s=Object.assign(new Error("did not encounter expected EOF"),{path:this.absolute,syscall:"read",code:"EOF"});return this[ai](()=>this.emit("error",s))}if(!this.buf)throw new Error("should have created buffer prior to reading");if(e===this.remain)for(let s=e;s<this.length&&e<this.blockRemain;s++)this.buf[s+this.offset]=0,e++,this.remain++;let i=this.offset===0&&e===this.buf.length?this.buf:this.buf.subarray(this.offset,this.offset+e);this.write(i)?this[Il]():this[Gl](()=>this[Il]())}[Gl](e){this.once("drain",e)}write(e,i,n){if(typeof i=="function"&&(n=i,i=void 0),typeof e=="string"&&(e=Buffer.from(e,typeof i=="string"?i:"utf8")),this.blockRemain<e.length){let s=Object.assign(new Error("writing more data than expected"),{path:this.absolute});return this.emit("error",s)}return this.remain-=e.length,this.blockRemain-=e.length,this.pos+=e.length,this.offset+=e.length,super.write(e,null,n)}[Il](){if(!this.remain)return this.blockRemain&&super.write(Buffer.alloc(this.blockRemain)),this[ai](e=>e?this.emit("error",e):this.end());if(!this.buf)throw new Error("buffer lost somehow in ONDRAIN");this.offset>=this.length&&(this.buf=Buffer.allocUnsafe(Math.min(this.blockRemain,this.buf.length)),this.offset=0),this.length=this.buf.length-this.offset,this[Io]()}},zo=class extends Us{sync=!0;[Rl](){this[Eo](ht.lstatSync(this.absolute))}[El](){this[jl](ht.readlinkSync(this.absolute))}[xl](){this[Sl](ht.openSync(this.absolute,"r"))}[Io](){let e=!0;try{let{fd:i,buf:n,offset:s,length:r,pos:o}=this;if(i===void 0||n===void 0)throw new Error("fd and buf must be set in READ method");let c=ht.readSync(i,n,s,r,o);this[zl](c),e=!1}finally{if(e)try{this[ai](()=>{})}catch{}}}[Gl](e){e()}[ai](e=()=>{}){this.fd!==void 0&&ht.closeSync(this.fd),e()}},jo=class extends dt{blockLen=0;blockRemain=0;buf=0;pos=0;remain=0;length=0;preservePaths;portable;strict;noPax;noMtime;readEntry;type;prefix;path;mode;uid;gid;uname;gname;header;mtime;atime;ctime;linkpath;size;onWriteEntry;warn(e,i,n={}){return yi(this,e,i,n)}constructor(e,i={}){let n=hs(i);super(),this.preservePaths=!!n.preservePaths,this.portable=!!n.portable,this.strict=!!n.strict,this.noPax=!!n.noPax,this.noMtime=!!n.noMtime,this.onWriteEntry=n.onWriteEntry,this.readEntry=e;let{type:s}=e;if(s==="Unsupported")throw new Error("writing entry that should be ignored");this.type=s,this.type==="Directory"&&this.portable&&(this.noMtime=!0),this.prefix=n.prefix,this.path=R(e.path),this.mode=e.mode!==void 0?this[Ro](e.mode):void 0,this.uid=this.portable?void 0:e.uid,this.gid=this.portable?void 0:e.gid,this.uname=this.portable?void 0:e.uname,this.gname=this.portable?void 0:e.gname,this.size=e.size,this.mtime=this.noMtime?void 0:n.mtime||e.mtime,this.atime=this.portable?void 0:e.atime,this.ctime=this.portable?void 0:e.ctime,this.linkpath=e.linkpath!==void 0?R(e.linkpath):void 0,typeof n.onwarn=="function"&&this.on("warn",n.onwarn);let r=!1;if(!this.preservePaths){let[c,l]=Cs(this.path);c&&typeof l=="string"&&(this.path=l,r=c)}this.remain=e.size,this.blockRemain=e.startBlockSize,this.onWriteEntry?.(this),this.header=new ze({path:this[gt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[gt](this.linkpath):this.linkpath,mode:this.mode,uid:this.portable?void 0:this.uid,gid:this.portable?void 0:this.gid,size:this.size,mtime:this.noMtime?void 0:this.mtime,type:this.type,uname:this.portable?void 0:this.uname,atime:this.portable?void 0:this.atime,ctime:this.portable?void 0:this.ctime}),r&&this.warn("TAR_ENTRY_INFO",`stripping ${r} from absolute path`,{entry:this,path:r+this.path}),this.header.encode()&&!this.noPax&&super.write(new ti({atime:this.portable?void 0:this.atime,ctime:this.portable?void 0:this.ctime,gid:this.portable?void 0:this.gid,mtime:this.noMtime?void 0:this.mtime,path:this[gt](this.path),linkpath:this.type==="Link"&&this.linkpath!==void 0?this[gt](this.linkpath):this.linkpath,size:this.size,uid:this.portable?void 0:this.uid,uname:this.portable?void 0:this.uname,dev:this.portable?void 0:this.readEntry.dev,ino:this.portable?void 0:this.readEntry.ino,nlink:this.portable?void 0:this.readEntry.nlink}).encode());let o=this.header?.block;if(!o)throw new Error("failed to encode header");super.write(o),e.pipe(this)}[gt](e){return B3(e,this.prefix)}[Ro](e){return fl(e,this.type==="Directory",this.portable)}write(e,i,n){typeof i=="function"&&(n=i,i=void 0),typeof e=="string"&&(e=Buffer.from(e,typeof i=="string"?i:"utf8"));let s=e.length;if(s>this.blockRemain)throw new Error("writing more to entry than is appropriate");return this.blockRemain-=s,super.write(e,n)}end(e,i,n){return this.blockRemain&&super.write(Buffer.alloc(this.blockRemain)),typeof e=="function"&&(n=e,i=void 0,e=void 0),typeof i=="function"&&(n=i,i=void 0),typeof e=="string"&&(e=Buffer.from(e,i??"utf8")),n&&this.once("finish",n),e?super.end(e,n):super.end(n),this}},x7=t=>t.isFile()?"File":t.isDirectory()?"Directory":t.isSymbolicLink()?"SymbolicLink":"Unsupported";var xo=class t{tail;head;length=0;static create(e=[]){return new t(e)}constructor(e=[]){for(let i of e)this.push(i)}*[Symbol.iterator](){for(let e=this.head;e;e=e.next)yield e.value}removeNode(e){if(e.list!==this)throw new Error("removing node which does not belong to this list");let i=e.next,n=e.prev;return i&&(i.prev=n),n&&(n.next=i),e===this.head&&(this.head=i),e===this.tail&&(this.tail=n),this.length--,e.next=void 0,e.prev=void 0,e.list=void 0,i}unshiftNode(e){if(e===this.head)return;e.list&&e.list.removeNode(e);let i=this.head;e.list=this,e.next=i,i&&(i.prev=e),this.head=e,this.tail||(this.tail=e),this.length++}pushNode(e){if(e===this.tail)return;e.list&&e.list.removeNode(e);let i=this.tail;e.list=this,e.prev=i,i&&(i.next=e),this.tail=e,this.head||(this.head=e),this.length++}push(...e){for(let i=0,n=e.length;i<n;i++)G7(this,e[i]);return this.length}unshift(...e){for(var i=0,n=e.length;i<n;i++)M7(this,e[i]);return this.length}pop(){if(!this.tail)return;let e=this.tail.value,i=this.tail;return this.tail=this.tail.prev,this.tail?this.tail.next=void 0:this.head=void 0,i.list=void 0,this.length--,e}shift(){if(!this.head)return;let e=this.head.value,i=this.head;return this.head=this.head.next,this.head?this.head.prev=void 0:this.tail=void 0,i.list=void 0,this.length--,e}forEach(e,i){i=i||this;for(let n=this.head,s=0;n;s++)e.call(i,n.value,s,this),n=n.next}forEachReverse(e,i){i=i||this;for(let n=this.tail,s=this.length-1;n;s--)e.call(i,n.value,s,this),n=n.prev}get(e){let i=0,n=this.head;for(;n&&i<e;i++)n=n.next;if(i===e&&n)return n.value}getReverse(e){let i=0,n=this.tail;for(;n&&i<e;i++)n=n.prev;if(i===e&&n)return n.value}map(e,i){i=i||this;let n=new t;for(let s=this.head;s;)n.push(e.call(i,s.value,this)),s=s.next;return n}mapReverse(e,i){i=i||this;var n=new t;for(let s=this.tail;s;)n.push(e.call(i,s.value,this)),s=s.prev;return n}reduce(e,i){let n,s=this.head;if(arguments.length>1)n=i;else if(this.head)s=this.head.next,n=this.head.value;else throw new TypeError("Reduce of empty list with no initial value");for(var r=0;s;r++)n=e(n,s.value,r),s=s.next;return n}reduceReverse(e,i){let n,s=this.tail;if(arguments.length>1)n=i;else if(this.tail)s=this.tail.prev,n=this.tail.value;else throw new TypeError("Reduce of empty list with no initial value");for(let r=this.length-1;s;r--)n=e(n,s.value,r),s=s.prev;return n}toArray(){let e=new Array(this.length);for(let i=0,n=this.head;n;i++)e[i]=n.value,n=n.next;return e}toArrayReverse(){let e=new Array(this.length);for(let i=0,n=this.tail;n;i++)e[i]=n.value,n=n.prev;return e}slice(e=0,i=this.length){i<0&&(i+=this.length),e<0&&(e+=this.length);let n=new t;if(i<e||i<0)return n;e<0&&(e=0),i>this.length&&(i=this.length);let s=this.head,r=0;for(r=0;s&&r<e;r++)s=s.next;for(;s&&r<i;r++,s=s.next)n.push(s.value);return n}sliceReverse(e=0,i=this.length){i<0&&(i+=this.length),e<0&&(e+=this.length);let n=new t;if(i<e||i<0)return n;e<0&&(e=0),i>this.length&&(i=this.length);let s=this.length,r=this.tail;for(;r&&s>i;s--)r=r.prev;for(;r&&s>e;s--,r=r.prev)n.push(r.value);return n}splice(e,i=0,...n){e>this.length&&(e=this.length-1),e<0&&(e=this.length+e);let s=this.head;for(let o=0;s&&o<e;o++)s=s.next;let r=[];for(let o=0;s&&o<i;o++)r.push(s.value),s=this.removeNode(s);s?s!==this.tail&&(s=s.prev):s=this.tail;for(let o of n)s=S7(this,s,o);return r}reverse(){let e=this.head,i=this.tail;for(let n=e;n;n=n.prev){let s=n.prev;n.prev=n.next,n.next=s}return this.head=i,this.tail=e,this}};function S7(t,e,i){let n=e,s=e?e.next:t.head,r=new Ks(i,n,s,t);return r.next===void 0&&(t.tail=r),r.prev===void 0&&(t.head=r),t.length++,r}function G7(t,e){t.tail=new Ks(e,t.tail,void 0,t),t.head||(t.head=t.tail),t.length++}function M7(t,e){t.head=new Ks(e,void 0,t.head,t),t.tail||(t.tail=t.head),t.length++}var Ks=class{list;next;prev;value;constructor(e,i,n,s){this.list=s,this.value=e,i?(i.next=this,this.prev=i):this.prev=void 0,n?(n.prev=this,this.next=n):this.next=void 0}};import w3 from"path";var Oo=class{path;absolute;entry;stat;readdir;pending=!1;ignore=!1;piped=!1;constructor(e,i){this.path=e||"./",this.absolute=i}},J3=Buffer.alloc(1024),So=Symbol("onStat"),ks=Symbol("ended"),_e=Symbol("queue"),Cn=Symbol("current"),Xi=Symbol("process"),Vs=Symbol("processing"),Z3=Symbol("processJob"),$e=Symbol("jobs"),Ml=Symbol("jobDone"),Go=Symbol("addFSEntry"),y3=Symbol("addTarEntry"),Cl=Symbol("stat"),Ol=Symbol("readdir"),Mo=Symbol("onreaddir"),Yo=Symbol("pipe"),q3=Symbol("entry"),Yl=Symbol("entryOpt"),Wo=Symbol("writeEntryClass"),D3=Symbol("write"),Wl=Symbol("ondrain"),ci=class extends dt{opt;cwd;maxReadSize;preservePaths;strict;noPax;prefix;linkCache;statCache;file;portable;zip;readdirCache;noDirRecurse;follow;noMtime;mtime;filter;jobs;[Wo];onWriteEntry;[_e];[$e]=0;[Vs]=!1;[ks]=!1;constructor(e={}){if(super(),this.opt=e,this.file=e.file||"",this.cwd=e.cwd||process.cwd(),this.maxReadSize=e.maxReadSize,this.preservePaths=!!e.preservePaths,this.strict=!!e.strict,this.noPax=!!e.noPax,this.prefix=R(e.prefix||""),this.linkCache=e.linkCache||new Map,this.statCache=e.statCache||new Map,this.readdirCache=e.readdirCache||new Map,this.onWriteEntry=e.onWriteEntry,this[Wo]=Us,typeof e.onwarn=="function"&&this.on("warn",e.onwarn),this.portable=!!e.portable,e.gzip||e.brotli||e.zstd){if((e.gzip?1:0)+(e.brotli?1:0)+(e.zstd?1:0)>1)throw new TypeError("gzip, brotli, zstd are mutually exclusive");if(e.gzip&&(typeof e.gzip!="object"&&(e.gzip={}),this.portable&&(e.gzip.portable=!0),this.zip=new Xr(e.gzip)),e.brotli&&(typeof e.brotli!="object"&&(e.brotli={}),this.zip=new _r(e.brotli)),e.zstd&&(typeof e.zstd!="object"&&(e.zstd={}),this.zip=new to(e.zstd)),!this.zip)throw new Error("impossible");let i=this.zip;i.on("data",n=>super.write(n)),i.on("end",()=>super.end()),i.on("drain",()=>this[Wl]()),this.on("resume",()=>i.resume())}else this.on("drain",this[Wl]);this.noDirRecurse=!!e.noDirRecurse,this.follow=!!e.follow,this.noMtime=!!e.noMtime,e.mtime&&(this.mtime=e.mtime),this.filter=typeof e.filter=="function"?e.filter:()=>!0,this[_e]=new xo,this[$e]=0,this.jobs=Number(e.jobs)||4,this[Vs]=!1,this[ks]=!1}[D3](e){return super.write(e)}add(e){return this.write(e),this}end(e,i,n){return typeof e=="function"&&(n=e,e=void 0),typeof i=="function"&&(n=i,i=void 0),e&&this.add(e),this[ks]=!0,this[Xi](),n&&n(),this}write(e){if(this[ks])throw new Error("write after end");return e instanceof Mn?this[y3](e):this[Go](e),this.flowing}[y3](e){let i=R(w3.resolve(this.cwd,e.path));if(!this.filter(e.path,e))e.resume();else{let n=new Oo(e.path,i);n.entry=new jo(e,this[Yl](n)),n.entry.on("end",()=>this[Ml](n)),this[$e]+=1,this[_e].push(n)}this[Xi]()}[Go](e){let i=R(w3.resolve(this.cwd,e));this[_e].push(new Oo(e,i)),this[Xi]()}[Cl](e){e.pending=!0,this[$e]+=1;let i=this.follow?"stat":"lstat";Co[i](e.absolute,(n,s)=>{e.pending=!1,this[$e]-=1,n?this.emit("error",n):this[So](e,s)})}[So](e,i){this.statCache.set(e.absolute,i),e.stat=i,this.filter(e.path,i)||(e.ignore=!0),this[Xi]()}[Ol](e){e.pending=!0,this[$e]+=1,Co.readdir(e.absolute,(i,n)=>{if(e.pending=!1,this[$e]-=1,i)return this.emit("error",i);this[Mo](e,n)})}[Mo](e,i){this.readdirCache.set(e.absolute,i),e.readdir=i,this[Xi]()}[Xi](){if(!this[Vs]){this[Vs]=!0;for(let e=this[_e].head;e&&this[$e]<this.jobs;e=e.next)if(this[Z3](e.value),e.value.ignore){let i=e.next;this[_e].removeNode(e),e.next=i}this[Vs]=!1,this[ks]&&!this[_e].length&&this[$e]===0&&(this.zip?this.zip.end(J3):(super.write(J3),super.end()))}}get[Cn](){return this[_e]&&this[_e].head&&this[_e].head.value}[Ml](e){this[_e].shift(),this[$e]-=1,this[Xi]()}[Z3](e){if(!e.pending){if(e.entry){e===this[Cn]&&!e.piped&&this[Yo](e);return}if(!e.stat){let i=this.statCache.get(e.absolute);i?this[So](e,i):this[Cl](e)}if(e.stat&&!e.ignore){if(!this.noDirRecurse&&e.stat.isDirectory()&&!e.readdir){let i=this.readdirCache.get(e.absolute);if(i?this[Mo](e,i):this[Ol](e),!e.readdir)return}if(e.entry=this[q3](e),!e.entry){e.ignore=!0;return}e===this[Cn]&&!e.piped&&this[Yo](e)}}}[Yl](e){return{onwarn:(i,n,s)=>this.warn(i,n,s),noPax:this.noPax,cwd:this.cwd,absolute:e.absolute,preservePaths:this.preservePaths,maxReadSize:this.maxReadSize,strict:this.strict,portable:this.portable,linkCache:this.linkCache,statCache:this.statCache,noMtime:this.noMtime,mtime:this.mtime,prefix:this.prefix,onWriteEntry:this.onWriteEntry}}[q3](e){this[$e]+=1;try{return new this[Wo](e.path,this[Yl](e)).on("end",()=>this[Ml](e)).on("error",n=>this.emit("error",n))}catch(i){this.emit("error",i)}}[Wl](){this[Cn]&&this[Cn].entry&&this[Cn].entry.resume()}[Yo](e){e.piped=!0,e.readdir&&e.readdir.forEach(s=>{let r=e.path,o=r==="./"?"":r.replace(/\/*$/,"/");this[Go](o+s)});let i=e.entry,n=this.zip;if(!i)throw new Error("cannot pipe without source");n?i.on("data",s=>{n.write(s)||i.pause()}):i.on("data",s=>{super.write(s)||i.pause()})}pause(){return this.zip&&this.zip.pause(),super.pause()}warn(e,i,n={}){yi(this,e,i,n)}},Hi=class extends ci{sync=!0;constructor(e){super(e),this[Wo]=zo}pause(){}resume(){}[Cl](e){let i=this.follow?"statSync":"lstatSync";this[So](e,Co[i](e.absolute))}[Ol](e){this[Mo](e,Co.readdirSync(e.absolute))}[Yo](e){let i=e.entry,n=this.zip;if(e.readdir&&e.readdir.forEach(s=>{let r=e.path,o=r==="./"?"":r.replace(/\/*$/,"/");this[Go](o+s)}),!i)throw new Error("Cannot pipe without source");n?i.on("data",s=>{n.write(s)}):i.on("data",s=>{super[D3](s)})}};var Y7=(t,e)=>{let i=new Hi(t),n=new En(t.file,{mode:t.mode||438});i.pipe(n),X3(i,e)},W7=(t,e)=>{let i=new ci(t),n=new Wt(t.file,{mode:t.mode||438});i.pipe(n);let s=new Promise((r,o)=>{n.on("error",o),n.on("close",r),i.on("error",o)});return H3(i,e),s},X3=(t,e)=>{e.forEach(i=>{i.charAt(0)==="@"?Ti({file:T3.resolve(t.cwd,i.slice(1)),sync:!0,noResume:!0,onReadEntry:n=>t.add(n)}):t.add(i)}),t.end()},H3=async(t,e)=>{for(let i=0;i<e.length;i++){let n=String(e[i]);n.charAt(0)==="@"?await Ti({file:T3.resolve(String(t.cwd),n.slice(1)),noResume:!0,onReadEntry:s=>{t.add(s)}}):t.add(n)}t.end()},C7=(t,e)=>{let i=new Hi(t);return X3(i,e),i},O7=(t,e)=>{let i=new ci(t);return H3(i,e),i},U7=vt(Y7,W7,C7,O7,(t,e)=>{if(!e?.length)throw new TypeError("no paths specified to add to archive")});import Av from"node:fs";import X7 from"node:assert";import{randomBytes as pv}from"node:crypto";import z from"node:fs";import Ft from"node:path";import L3 from"fs";var K7=process.env.__FAKE_PLATFORM__||process.platform,k7=K7==="win32",{O_CREAT:V7,O_TRUNC:N7,O_WRONLY:F7}=L3.constants,_3=Number(process.env.__FAKE_FS_O_FILENAME__)||L3.constants.UV_FS_O_FILEMAP||0,b7=k7&&!!_3,P7=512*1024,Q7=_3|N7|V7|F7,Ul=b7?t=>t<P7?Q7:"w":()=>"w";import Ko from"node:fs";import Ns from"node:path";var Kl=(t,e,i)=>{try{return Ko.lchownSync(t,e,i)}catch(n){if(n?.code!=="ENOENT")throw n}},Uo=(t,e,i,n)=>{Ko.lchown(t,e,i,s=>{n(s&&s?.code!=="ENOENT"?s:null)})},B7=(t,e,i,n,s)=>{if(e.isDirectory())kl(Ns.resolve(t,e.name),i,n,r=>{if(r)return s(r);let o=Ns.resolve(t,e.name);Uo(o,i,n,s)});else{let r=Ns.resolve(t,e.name);Uo(r,i,n,s)}},kl=(t,e,i,n)=>{Ko.readdir(t,{withFileTypes:!0},(s,r)=>{if(s){if(s.code==="ENOENT")return n();if(s.code!=="ENOTDIR"&&s.code!=="ENOTSUP")return n(s)}if(s||!r.length)return Uo(t,e,i,n);let o=r.length,c=null,l=u=>{if(!c){if(u)return n(c=u);if(--o===0)return Uo(t,e,i,n)}};for(let u of r)B7(t,u,e,i,l)})},J7=(t,e,i,n)=>{e.isDirectory()&&Vl(Ns.resolve(t,e.name),i,n),Kl(Ns.resolve(t,e.name),i,n)},Vl=(t,e,i)=>{let n;try{n=Ko.readdirSync(t,{withFileTypes:!0})}catch(s){let r=s;if(r?.code==="ENOENT")return;if(r?.code==="ENOTDIR"||r?.code==="ENOTSUP")return Kl(t,e,i);throw r}for(let s of n)J7(t,s,e,i);return Kl(t,e,i)};import xe from"node:fs";import Z7 from"node:fs/promises";import ko from"node:path";var Fs=class extends Error{path;code;syscall="chdir";constructor(e,i){super(`${i}: Cannot cd into '${e}'`),this.path=e,this.code=i}get name(){return"CwdError"}};var bs=class extends Error{path;symlink;syscall="symlink";code="TAR_SYMLINK_ERROR";constructor(e,i){super("TAR_SYMLINK_ERROR: Cannot extract through symbolic link"),this.symlink=e,this.path=i}get name(){return"SymlinkError"}};var y7=(t,e)=>{xe.stat(t,(i,n)=>{(i||!n.isDirectory())&&(i=new Fs(t,i?.code||"ENOTDIR")),e(i)})},$3=(t,e,i)=>{t=R(t);let n=e.umask??18,s=e.mode|448,r=(s&n)!==0,o=e.uid,c=e.gid,l=typeof o=="number"&&typeof c=="number"&&(o!==e.processUid||c!==e.processGid),u=e.preserve,m=e.unlink,p=R(e.cwd),d=(g,E)=>{g?i(g):E&&l?kl(E,o,c,J=>d(J)):r?xe.chmod(t,s,i):i()};if(t===p)return y7(t,d);if(u)return Z7.mkdir(t,{mode:s,recursive:!0}).then(g=>d(null,g??void 0),d);let f=R(ko.relative(p,t)).split("/");Nl(p,f,s,m,p,void 0,d)},Nl=(t,e,i,n,s,r,o)=>{if(!e.length)return o(null,r);let c=e.shift(),l=R(ko.resolve(t+"/"+c));xe.mkdir(l,i,ev(l,e,i,n,s,r,o))},ev=(t,e,i,n,s,r,o)=>c=>{c?xe.lstat(t,(l,u)=>{if(l)l.path=l.path&&R(l.path),o(l);else if(u.isDirectory())Nl(t,e,i,n,s,r,o);else if(n)xe.unlink(t,m=>{if(m)return o(m);xe.mkdir(t,i,ev(t,e,i,n,s,r,o))});else{if(u.isSymbolicLink())return o(new bs(t,t+"/"+e.join("/")));o(c)}}):(r=r||t,Nl(t,e,i,n,s,r,o))},q7=t=>{let e=!1,i;try{e=xe.statSync(t).isDirectory()}catch(n){i=n?.code}finally{if(!e)throw new Fs(t,i??"ENOTDIR")}},tv=(t,e)=>{t=R(t);let i=e.umask??18,n=e.mode|448,s=(n&i)!==0,r=e.uid,o=e.gid,c=typeof r=="number"&&typeof o=="number"&&(r!==e.processUid||o!==e.processGid),l=e.preserve,u=e.unlink,m=R(e.cwd),p=g=>{g&&c&&Vl(g,r,o),s&&xe.chmodSync(t,n)};if(t===m)return q7(m),p();if(l)return p(xe.mkdirSync(t,{mode:n,recursive:!0})??void 0);let A=R(ko.relative(m,t)).split("/"),f;for(let g=A.shift(),E=m;g&&(E+="/"+g);g=A.shift()){E=R(ko.resolve(E));try{xe.mkdirSync(E,n),f=f||E}catch{let M=xe.lstatSync(E);if(M.isDirectory())continue;if(u){xe.unlinkSync(E),xe.mkdirSync(E,n),f=f||E;continue}else if(M.isSymbolicLink())return new bs(E,E+"/"+A.join("/"))}}return p(f)};import{join as sv}from"node:path";var Fl=Object.create(null),iv=1e4,On=new Set,nv=t=>{On.has(t)?On.delete(t):Fl[t]=t.normalize("NFD"),On.add(t);let e=Fl[t],i=On.size-iv;if(i>iv/10){for(let n of On)if(On.delete(n),delete Fl[n],--i<=0)break}return e};var w7=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,D7=w7==="win32",T7=t=>t.split("/").slice(0,-1).reduce((i,n)=>{let s=i[i.length-1];return s!==void 0&&(n=sv(s,n)),i.push(n||"/"),i},[]),Vo=class{#e=new Map;#n=new Map;#i=new Set;reserve(e,i){e=D7?["win32 parallelization disabled"]:e.map(s=>oi(sv(nv(s))).toLowerCase());let n=new Set(e.map(s=>T7(s)).reduce((s,r)=>s.concat(r)));this.#n.set(i,{dirs:n,paths:e});for(let s of e){let r=this.#e.get(s);r?r.push(i):this.#e.set(s,[i])}for(let s of n){let r=this.#e.get(s);if(!r)this.#e.set(s,[new Set([i])]);else{let o=r[r.length-1];o instanceof Set?o.add(i):r.push(new Set([i]))}}return this.#a(i)}#s(e){let i=this.#n.get(e);if(!i)throw new Error("function does not have any path reservations");return{paths:i.paths.map(n=>this.#e.get(n)),dirs:[...i.dirs].map(n=>this.#e.get(n))}}check(e){let{paths:i,dirs:n}=this.#s(e);return i.every(s=>s&&s[0]===e)&&n.every(s=>s&&s[0]instanceof Set&&s[0].has(e))}#a(e){return this.#i.has(e)||!this.check(e)?!1:(this.#i.add(e),e(()=>this.#t(e)),!0)}#t(e){if(!this.#i.has(e))return!1;let i=this.#n.get(e);if(!i)throw new Error("invalid reservation");let{paths:n,dirs:s}=i,r=new Set;for(let o of n){let c=this.#e.get(o);if(!c||c?.[0]!==e)continue;let l=c[1];if(!l){this.#e.delete(o);continue}if(c.shift(),typeof l=="function")r.add(l);else for(let u of l)r.add(u)}for(let o of s){let c=this.#e.get(o),l=c?.[0];if(!(!c||!(l instanceof Set)))if(l.size===1&&c.length===1){this.#e.delete(o);continue}else if(l.size===1){c.shift();let u=c[0];typeof u=="function"&&r.add(u)}else l.delete(e)}return this.#i.delete(e),r.forEach(o=>this.#a(o)),!0}};var rv=Symbol("onEntry"),Ql=Symbol("checkFs"),ov=Symbol("checkFs2"),Bl=Symbol("isReusable"),Fe=Symbol("makeFs"),Jl=Symbol("file"),Zl=Symbol("directory"),bo=Symbol("link"),av=Symbol("symlink"),cv=Symbol("hardlink"),lv=Symbol("unsupported"),uv=Symbol("checkPath"),li=Symbol("mkdir"),ae=Symbol("onError"),No=Symbol("pending"),mv=Symbol("pend"),Un=Symbol("unpend"),bl=Symbol("ended"),Pl=Symbol("maybeClose"),yl=Symbol("skip"),Ps=Symbol("doChown"),Qs=Symbol("uid"),Bs=Symbol("gid"),Js=Symbol("checkedCwd"),H7=process.env.TESTING_TAR_FAKE_PLATFORM||process.platform,Zs=H7==="win32",L7=1024,_7=(t,e)=>{if(!Zs)return z.unlink(t,e);let i=t+".DELETE."+pv(16).toString("hex");z.rename(t,i,n=>{if(n)return e(n);z.unlink(i,e)})},$7=t=>{if(!Zs)return z.unlinkSync(t);let e=t+".DELETE."+pv(16).toString("hex");z.renameSync(t,e),z.unlinkSync(e)},vv=(t,e,i)=>t!==void 0&&t===t>>>0?t:e!==void 0&&e===e>>>0?e:i,Kn=class extends Nt{[bl]=!1;[Js]=!1;[No]=0;reservations=new Vo;transform;writable=!0;readable=!1;uid;gid;setOwner;preserveOwner;processGid;processUid;maxDepth;forceChown;win32;newer;keep;noMtime;preservePaths;unlink;cwd;strip;processUmask;umask;dmode;fmode;chmod;constructor(e={}){if(e.ondone=()=>{this[bl]=!0,this[Pl]()},super(e),this.transform=e.transform,this.chmod=!!e.chmod,typeof e.uid=="number"||typeof e.gid=="number"){if(typeof e.uid!="number"||typeof e.gid!="number")throw new TypeError("cannot set owner without number uid and gid");if(e.preserveOwner)throw new TypeError("cannot preserve owner in archive and also set owner explicitly");this.uid=e.uid,this.gid=e.gid,this.setOwner=!0}else this.uid=void 0,this.gid=void 0,this.setOwner=!1;e.preserveOwner===void 0&&typeof e.uid!="number"?this.preserveOwner=!!(process.getuid&&process.getuid()===0):this.preserveOwner=!!e.preserveOwner,this.processUid=(this.preserveOwner||this.setOwner)&&process.getuid?process.getuid():void 0,this.processGid=(this.preserveOwner||this.setOwner)&&process.getgid?process.getgid():void 0,this.maxDepth=typeof e.maxDepth=="number"?e.maxDepth:L7,this.forceChown=e.forceChown===!0,this.win32=!!e.win32||Zs,this.newer=!!e.newer,this.keep=!!e.keep,this.noMtime=!!e.noMtime,this.preservePaths=!!e.preservePaths,this.unlink=!!e.unlink,this.cwd=R(Ft.resolve(e.cwd||process.cwd())),this.strip=Number(e.strip)||0,this.processUmask=this.chmod?typeof e.processUmask=="number"?e.processUmask:process.umask():0,this.umask=typeof e.umask=="number"?e.umask:this.processUmask,this.dmode=e.dmode||511&~this.umask,this.fmode=e.fmode||438&~this.umask,this.on("entry",i=>this[rv](i))}warn(e,i,n={}){return(e==="TAR_BAD_ARCHIVE"||e==="TAR_ABORT")&&(n.recoverable=!1),super.warn(e,i,n)}[Pl](){this[bl]&&this[No]===0&&(this.emit("prefinish"),this.emit("finish"),this.emit("end"))}[uv](e){let i=R(e.path),n=i.split("/");if(this.strip){if(n.length<this.strip)return!1;if(e.type==="Link"){let s=R(String(e.linkpath)).split("/");if(s.length>=this.strip)e.linkpath=s.slice(this.strip).join("/");else return!1}n.splice(0,this.strip),e.path=n.join("/")}if(isFinite(this.maxDepth)&&n.length>this.maxDepth)return this.warn("TAR_ENTRY_ERROR","path excessively deep",{entry:e,path:i,depth:n.length,maxDepth:this.maxDepth}),!1;if(!this.preservePaths){if(n.includes("..")||Zs&&/^[a-z]:\.\.$/i.test(n[0]??""))return this.warn("TAR_ENTRY_ERROR","path contains '..'",{entry:e,path:i}),!1;let[s,r]=Cs(i);s&&(e.path=String(r),this.warn("TAR_ENTRY_INFO",`stripping ${s} from absolute path`,{entry:e,path:i}))}if(Ft.isAbsolute(e.path)?e.absolute=R(Ft.resolve(e.path)):e.absolute=R(Ft.resolve(this.cwd,e.path)),!this.preservePaths&&typeof e.absolute=="string"&&e.absolute.indexOf(this.cwd+"/")!==0&&e.absolute!==this.cwd)return this.warn("TAR_ENTRY_ERROR","path escaped extraction target",{entry:e,path:R(e.path),resolvedPath:e.absolute,cwd:this.cwd}),!1;if(e.absolute===this.cwd&&e.type!=="Directory"&&e.type!=="GNUDumpDir")return!1;if(this.win32){let{root:s}=Ft.win32.parse(String(e.absolute));e.absolute=s+gl(String(e.absolute).slice(s.length));let{root:r}=Ft.win32.parse(e.path);e.path=r+gl(e.path.slice(r.length))}return!0}[rv](e){if(!this[uv](e))return e.resume();switch(X7.equal(typeof e.absolute,"string"),e.type){case"Directory":case"GNUDumpDir":e.mode&&(e.mode=e.mode|448);case"File":case"OldFile":case"ContiguousFile":case"Link":case"SymbolicLink":return this[Ql](e);default:return this[lv](e)}}[ae](e,i){e.name==="CwdError"?this.emit("error",e):(this.warn("TAR_ENTRY_ERROR",e,{entry:i}),this[Un](),i.resume())}[li](e,i,n){$3(R(e),{uid:this.uid,gid:this.gid,processUid:this.processUid,processGid:this.processGid,umask:this.processUmask,preserve:this.preservePaths,unlink:this.unlink,cwd:this.cwd,mode:i},n)}[Ps](e){return this.forceChown||this.preserveOwner&&(typeof e.uid=="number"&&e.uid!==this.processUid||typeof e.gid=="number"&&e.gid!==this.processGid)||typeof this.uid=="number"&&this.uid!==this.processUid||typeof this.gid=="number"&&this.gid!==this.processGid}[Qs](e){return vv(this.uid,e.uid,this.processUid)}[Bs](e){return vv(this.gid,e.gid,this.processGid)}[Jl](e,i){let n=typeof e.mode=="number"?e.mode&4095:this.fmode,s=new Wt(String(e.absolute),{flags:Ul(e.size),mode:n,autoClose:!1});s.on("error",l=>{s.fd&&z.close(s.fd,()=>{}),s.write=()=>!0,this[ae](l,e),i()});let r=1,o=l=>{if(l){s.fd&&z.close(s.fd,()=>{}),this[ae](l,e),i();return}--r===0&&s.fd!==void 0&&z.close(s.fd,u=>{u?this[ae](u,e):this[Un](),i()})};s.on("finish",()=>{let l=String(e.absolute),u=s.fd;if(typeof u=="number"&&e.mtime&&!this.noMtime){r++;let m=e.atime||new Date,p=e.mtime;z.futimes(u,m,p,d=>d?z.utimes(l,m,p,A=>o(A&&d)):o())}if(typeof u=="number"&&this[Ps](e)){r++;let m=this[Qs](e),p=this[Bs](e);typeof m=="number"&&typeof p=="number"&&z.fchown(u,m,p,d=>d?z.chown(l,m,p,A=>o(A&&d)):o())}o()});let c=this.transform&&this.transform(e)||e;c!==e&&(c.on("error",l=>{this[ae](l,e),i()}),e.pipe(c)),c.pipe(s)}[Zl](e,i){let n=typeof e.mode=="number"?e.mode&4095:this.dmode;this[li](String(e.absolute),n,s=>{if(s){this[ae](s,e),i();return}let r=1,o=()=>{--r===0&&(i(),this[Un](),e.resume())};e.mtime&&!this.noMtime&&(r++,z.utimes(String(e.absolute),e.atime||new Date,e.mtime,o)),this[Ps](e)&&(r++,z.chown(String(e.absolute),Number(this[Qs](e)),Number(this[Bs](e)),o)),o()})}[lv](e){e.unsupported=!0,this.warn("TAR_ENTRY_UNSUPPORTED",`unsupported entry type: ${e.type}`,{entry:e}),e.resume()}[av](e,i){this[bo](e,String(e.linkpath),"symlink",i)}[cv](e,i){let n=R(Ft.resolve(this.cwd,String(e.linkpath)));this[bo](e,n,"link",i)}[mv](){this[No]++}[Un](){this[No]--,this[Pl]()}[yl](e){this[Un](),e.resume()}[Bl](e,i){return e.type==="File"&&!this.unlink&&i.isFile()&&i.nlink<=1&&!Zs}[Ql](e){this[mv]();let i=[e.path];e.linkpath&&i.push(e.linkpath),this.reservations.reserve(i,n=>this[ov](e,n))}[ov](e,i){let n=c=>{i(c)},s=()=>{this[li](this.cwd,this.dmode,c=>{if(c){this[ae](c,e),n();return}this[Js]=!0,r()})},r=()=>{if(e.absolute!==this.cwd){let c=R(Ft.dirname(String(e.absolute)));if(c!==this.cwd)return this[li](c,this.dmode,l=>{if(l){this[ae](l,e),n();return}o()})}o()},o=()=>{z.lstat(String(e.absolute),(c,l)=>{if(l&&(this.keep||this.newer&&l.mtime>(e.mtime??l.mtime))){this[yl](e),n();return}if(c||this[Bl](e,l))return this[Fe](null,e,n);if(l.isDirectory()){if(e.type==="Directory"){let u=this.chmod&&e.mode&&(l.mode&4095)!==e.mode,m=p=>this[Fe](p??null,e,n);return u?z.chmod(String(e.absolute),Number(e.mode),m):m()}if(e.absolute!==this.cwd)return z.rmdir(String(e.absolute),u=>this[Fe](u??null,e,n))}if(e.absolute===this.cwd)return this[Fe](null,e,n);_7(String(e.absolute),u=>this[Fe](u??null,e,n))})};this[Js]?r():s()}[Fe](e,i,n){if(e){this[ae](e,i),n();return}switch(i.type){case"File":case"OldFile":case"ContiguousFile":return this[Jl](i,n);case"Link":return this[cv](i,n);case"SymbolicLink":return this[av](i,n);case"Directory":case"GNUDumpDir":return this[Zl](i,n)}}[bo](e,i,n,s){z[n](i,String(e.absolute),r=>{r?this[ae](r,e):(this[Un](),e.resume()),s()})}},Fo=t=>{try{return[null,t()]}catch(e){return[e,null]}},ys=class extends Kn{sync=!0;[Fe](e,i){return super[Fe](e,i,()=>{})}[Ql](e){if(!this[Js]){let r=this[li](this.cwd,this.dmode);if(r)return this[ae](r,e);this[Js]=!0}if(e.absolute!==this.cwd){let r=R(Ft.dirname(String(e.absolute)));if(r!==this.cwd){let o=this[li](r,this.dmode);if(o)return this[ae](o,e)}}let[i,n]=Fo(()=>z.lstatSync(String(e.absolute)));if(n&&(this.keep||this.newer&&n.mtime>(e.mtime??n.mtime)))return this[yl](e);if(i||this[Bl](e,n))return this[Fe](null,e);if(n.isDirectory()){if(e.type==="Directory"){let o=this.chmod&&e.mode&&(n.mode&4095)!==e.mode,[c]=o?Fo(()=>{z.chmodSync(String(e.absolute),Number(e.mode))}):[];return this[Fe](c,e)}let[r]=Fo(()=>z.rmdirSync(String(e.absolute)));this[Fe](r,e)}let[s]=e.absolute===this.cwd?[]:Fo(()=>$7(String(e.absolute)));this[Fe](s,e)}[Jl](e,i){let n=typeof e.mode=="number"?e.mode&4095:this.fmode,s=c=>{let l;try{z.closeSync(r)}catch(u){l=u}(c||l)&&this[ae](c||l,e),i()},r;try{r=z.openSync(String(e.absolute),Ul(e.size),n)}catch(c){return s(c)}let o=this.transform&&this.transform(e)||e;o!==e&&(o.on("error",c=>this[ae](c,e)),e.pipe(o)),o.on("data",c=>{try{z.writeSync(r,c,0,c.length)}catch(l){s(l)}}),o.on("end",()=>{let c=null;if(e.mtime&&!this.noMtime){let l=e.atime||new Date,u=e.mtime;try{z.futimesSync(r,l,u)}catch(m){try{z.utimesSync(String(e.absolute),l,u)}catch{c=m}}}if(this[Ps](e)){let l=this[Qs](e),u=this[Bs](e);try{z.fchownSync(r,Number(l),Number(u))}catch(m){try{z.chownSync(String(e.absolute),Number(l),Number(u))}catch{c=c||m}}}s(c)})}[Zl](e,i){let n=typeof e.mode=="number"?e.mode&4095:this.dmode,s=this[li](String(e.absolute),n);if(s){this[ae](s,e),i();return}if(e.mtime&&!this.noMtime)try{z.utimesSync(String(e.absolute),e.atime||new Date,e.mtime)}catch{}if(this[Ps](e))try{z.chownSync(String(e.absolute),Number(this[Qs](e)),Number(this[Bs](e)))}catch{}i(),e.resume()}[li](e,i){try{return tv(R(e),{uid:this.uid,gid:this.gid,processUid:this.processUid,processGid:this.processGid,umask:this.processUmask,preserve:this.preservePaths,unlink:this.unlink,cwd:this.cwd,mode:i})}catch(n){return n}}[bo](e,i,n,s){let r=`${n}Sync`;try{z[r](i,String(e.absolute)),s(),e.resume()}catch(o){return this[ae](o,e)}}};var eh=t=>{let e=new ys(t),i=t.file,n=Av.statSync(i),s=t.maxReadSize||16*1024*1024;new Br(i,{readSize:s,size:n.size}).pipe(e)},th=(t,e)=>{let i=new Kn(t),n=t.maxReadSize||16*1024*1024,s=t.file;return new Promise((o,c)=>{i.on("error",c),i.on("close",o),Av.stat(s,(l,u)=>{if(l)c(l);else{let m=new Fi(s,{readSize:n,size:u.size});m.on("error",c),m.pipe(i)}})})},ql=vt(eh,th,t=>new ys(t),t=>new Kn(t),(t,e)=>{e?.length&&dl(t,e)});import Se from"node:fs";import dv from"node:path";var ih=(t,e)=>{let i=new Hi(t),n=!0,s,r;try{try{s=Se.openSync(t.file,"r+")}catch(l){if(l?.code==="ENOENT")s=Se.openSync(t.file,"w+");else throw l}let o=Se.fstatSync(s),c=Buffer.alloc(512);e:for(r=0;r<o.size;r+=512){for(let m=0,p=0;m<512;m+=p){if(p=Se.readSync(s,c,m,c.length-m,r+m),r===0&&c[0]===31&&c[1]===139)throw new Error("cannot append to compressed archives");if(!p)break e}let l=new ze(c);if(!l.cksumValid)break;let u=512*Math.ceil((l.size||0)/512);if(r+u+512>o.size)break;r+=u,t.mtimeCache&&l.mtime&&t.mtimeCache.set(String(l.path),l.mtime)}n=!1,nh(t,i,r,s,e)}finally{if(n)try{Se.closeSync(s)}catch{}}},nh=(t,e,i,n,s)=>{let r=new En(t.file,{fd:n,start:i});e.pipe(r),rh(e,s)},sh=(t,e)=>{e=Array.from(e);let i=new ci(t),n=(r,o,c)=>{let l=(A,f)=>{A?Se.close(r,g=>c(A)):c(null,f)},u=0;if(o===0)return l(null,0);let m=0,p=Buffer.alloc(512),d=(A,f)=>{if(A||typeof f>"u")return l(A);if(m+=f,m<512&&f)return Se.read(r,p,m,p.length-m,u+m,d);if(u===0&&p[0]===31&&p[1]===139)return l(new Error("cannot append to compressed archives"));if(m<512)return l(null,u);let g=new ze(p);if(!g.cksumValid)return l(null,u);let E=512*Math.ceil((g.size??0)/512);if(u+E+512>o||(u+=E+512,u>=o))return l(null,u);t.mtimeCache&&g.mtime&&t.mtimeCache.set(String(g.path),g.mtime),m=0,Se.read(r,p,0,512,u,d)};Se.read(r,p,0,512,u,d)};return new Promise((r,o)=>{i.on("error",o);let c="r+",l=(u,m)=>{if(u&&u.code==="ENOENT"&&c==="r+")return c="w+",Se.open(t.file,c,l);if(u||!m)return o(u);Se.fstat(m,(p,d)=>{if(p)return Se.close(m,()=>o(p));n(m,d.size,(A,f)=>{if(A)return o(A);let g=new Wt(t.file,{fd:m,start:f});i.pipe(g),g.on("error",o),g.on("close",r),oh(i,e)})})};Se.open(t.file,c,l)})},rh=(t,e)=>{e.forEach(i=>{i.charAt(0)==="@"?Ti({file:dv.resolve(t.cwd,i.slice(1)),sync:!0,noResume:!0,onReadEntry:n=>t.add(n)}):t.add(i)}),t.end()},oh=async(t,e)=>{for(let i=0;i<e.length;i++){let n=String(e[i]);n.charAt(0)==="@"?await Ti({file:dv.resolve(String(t.cwd),n.slice(1)),noResume:!0,onReadEntry:s=>t.add(s)}):t.add(n)}t.end()},Li=vt(ih,sh,()=>{throw new TypeError("file is required")},()=>{throw new TypeError("file is required")},(t,e)=>{if(!l3(t))throw new TypeError("file is required");if(t.gzip||t.brotli||t.zstd||t.file.endsWith(".br")||t.file.endsWith(".tbr"))throw new TypeError("cannot append to compressed archives");if(!e?.length)throw new TypeError("no paths specified to add/replace")});var ah=vt(Li.syncFile,Li.asyncFile,Li.syncNoFile,Li.asyncNoFile,(t,e=[])=>{Li.validate?.(t,e),ch(t)}),ch=t=>{let e=t.filter;t.mtimeCache||(t.mtimeCache=new Map),t.filter=e?(i,n)=>e(i,n)&&!((t.mtimeCache?.get(i)??n.mtime??0)>(n.mtime??0)):(i,n)=>!((t.mtimeCache?.get(i)??n.mtime??0)>(n.mtime??0))};async function kn(t){let{source:e,destination:i,strip:n=1,filter:s}=t,r=[];if(!fv(e))return{success:!1,extractedFiles:[],error:`Source file not found: ${e}`};fv(i)||mh(i,{recursive:!0});try{return await vh(uh(e),ph(),ql({cwd:i,strip:n,filter:o=>s&&!s(o)?!1:(r.push(o),!0)})),{success:!0,extractedFiles:r}}catch(o){return{success:!1,extractedFiles:r,error:o instanceof Error?o.message:String(o)}}}k();import{existsSync as hv,readFileSync as Ah,writeFileSync as dh,mkdirSync as fh}from"fs";import{dirname as hh}from"path";function ui(t){let e=Gc(t);if(!hv(e))return null;try{let i=Ah(e,"utf-8");return JSON.parse(i)}catch{return null}}function Po(t,e){let i=Gc(e),n=hh(i);hv(n)||fh(n,{recursive:!0}),dh(i,JSON.stringify(t,null,2))}function gv(t,e,i){return{name:"gemkit",version:t,installedAt:new Date().toISOString(),scope:e,installedFiles:i,customizedFiles:[]}}function Iv(t){return ui(t)!==null}var h=Ar(zv(),1),Rh=t=>{let e=parseInt(t.slice(1,3),16),i=parseInt(t.slice(3,5),16),n=parseInt(t.slice(5,7),16);return`\x1B[38;2;${e};${i};${n}m`},qs=t=>e=>h.default.isColorSupported?`${Rh(t)}${e}\x1B[39m`:e,a={primary:qs("#4f46e5"),secondary:qs("#9333ea"),accent:qs("#06b6d4"),geminiBlue:qs("#1a73e8"),geminiPurple:qs("#8e24aa"),success:t=>h.default.green(t),error:t=>h.default.red(t),warn:t=>h.default.yellow(t),info:t=>h.default.cyan(t),dim:t=>h.default.dim(t)},G={line:(t=60)=>"\u2500".repeat(t),doubleLine:(t=60)=>"\u2550".repeat(t),statusIcon:t=>{switch(t){case"active":return a.success("\u25CF");case"completed":return a.dim("\u25CB");case"failed":return a.error("\u2717");default:return"?"}},checkIcon:(t,e=!1)=>t?a.success("\u2713"):e?a.warn("\u25CB"):a.error("\u2717"),header:t=>h.default.bold(a.geminiPurple(t)),section:(t,e=60)=>{console.log(),console.log("\u2500".repeat(e)),console.log(h.default.bold(a.geminiPurple(t))),console.log("\u2500".repeat(e)),console.log()}};var eG={success:a.success,error:a.error,warning:a.warn,info:a.info,dim:a.dim,primary:a.primary,secondary:a.secondary,bold:h.default.bold};var jv={debug:0,info:1,warn:2,error:3,silent:4},be={level:"info",verbose:!1,json:!1};function Jo(t){be={...be,...t}}function ws(t){return jv[t]>=jv[be.level]}function zh(t,e){ws("debug")&&(be.json?console.log(JSON.stringify({level:"debug",message:t,data:e})):(console.log(a.dim(`[DEBUG] ${t}`)),e&&be.verbose&&console.log(a.dim(JSON.stringify(e,null,2)))))}function jh(t,e){ws("info")&&(be.json?console.log(JSON.stringify({level:"info",message:t,data:e})):(console.log(`${a.info("\u2139")} ${t}`),e&&be.verbose&&console.log(JSON.stringify(e,null,2))))}function xh(t,e){ws("info")&&(be.json?console.log(JSON.stringify({level:"success",message:t,data:e})):console.log(`${a.success("\u2713")} ${t}`))}function Sh(t,e){ws("warn")&&(be.json?console.log(JSON.stringify({level:"warn",message:t,data:e})):console.log(`${a.warn("\u26A0")} ${t}`))}function Gh(t,e){ws("error")&&(be.json?console.error(JSON.stringify({level:"error",message:t,data:e})):(console.error(`${a.error("\u2717")} ${t}`),e&&be.verbose&&console.error(JSON.stringify(e,null,2))))}function Mh(t){be.json?console.log(JSON.stringify(t)):console.table(t)}function Yh(t){console.log(JSON.stringify(t,null,2))}var v={debug:zh,info:jh,success:xh,warn:Sh,error:Gh,table:Mh,json:Yh,configure:Jo};import{spawnSync as Kh}from"child_process";k();var Wh="https://registry.npmjs.org",Ch="npm-version",Oh=3600;async function Ds(t){let e=`${Ch}-${t}`,i=Wr(e);if(i)return i;try{let n=await fetch(`${Wh}/${t}/latest`,{headers:{Accept:"application/json","User-Agent":"gemkit-cli"}});if(!n.ok)return null;let s=await n.json(),r={name:s.name,version:s.version,description:s.description,publishedAt:s.time?.[s.version]};return Cr(e,r,Oh),r}catch{return null}}function Uh(t,e){let i=t.replace(/^v/,"").split(".").map(Number),n=e.replace(/^v/,"").split(".").map(Number);for(let s=0;s<Math.max(i.length,n.length);s++){let r=i[s]||0,o=n[s]||0;if(r>o)return 1;if(r<o)return-1}return 0}function Vn(t,e){return Uh(e,t)>0}import{readFileSync as kh}from"fs";import{join as xv,dirname as Vh}from"path";import{fileURLToPath as Nh}from"url";var Ts="gemkit-cli";function Fh(){try{let t=Nh(import.meta.url),e=Vh(t),i=[xv(e,"..","package.json"),xv(e,"..","..","..","package.json")];for(let n of i)try{let s=JSON.parse(kh(n,"utf-8"));if(s.name===Ts&&s.version)return s.version}catch{}}catch{}return"0.0.0"}var Pe=Fh();function Sv(t){t.command("update","Update GemKit CLI and/or Kits to latest version").option("-f, --force","Force update even if already up to date").option("--no-backup","Disable backup before kits update").option("--cli","Update CLI only (npm package)").option("--kits","Update Kits only (.gemini folder)").action(async e=>{let i=e.cli===!0||!e.cli&&!e.kits,n=e.kits===!0||!e.cli&&!e.kits,s=!1,r=!1;i&&(s=await bh(e.force)),n&&(r=await Ph(e.force)),console.log(),s||r?v.success("Update complete!"):v.info("Everything is up to date.")})}async function bh(t){console.log(),v.info(`${a.primary("CLI")} Checking for updates...`);let e=await Ds(Ts);if(!e)return v.warn("Failed to check npm registry for CLI updates."),!1;let i=Pe,n=e.version;return!Vn(i,n)&&!t?(v.success(`CLI is up to date (v${i})`),!1):(v.info(`Updating CLI: v${i} \u2192 v${n}`),Kh("npm",["install","-g",`${Ts}@latest`],{encoding:"utf-8",stdio:"inherit",shell:!0}).status!==0?(v.error("CLI update failed. Try running manually:"),v.info(` npm install -g ${Ts}@latest`),!1):(v.success(`CLI updated to v${n}`),!0))}async function Ph(t){console.log(),v.info(`${a.primary("Kits")} Checking for updates...`);let e=ui();if(!e)return v.warn('GemKit not initialized. Run "gk init" first to install kits.'),!1;let i=await Ki();if(!i)return v.warn("Failed to check GitHub for kits updates."),!1;if(i.version===e.version&&!t)return v.success(`Kits are up to date (v${e.version})`),!1;v.info(`Updating Kits: v${e.version} \u2192 v${i.version}`);let n=await pn(i),s=Mr(),r=await kn({source:n,destination:s,strip:1});if(!r.success)return v.error(`Kits update failed: ${r.error}`),!1;let o={...e,version:i.version,installedAt:new Date().toISOString(),installedFiles:r.extractedFiles};return Po(o),v.success(`Kits updated to v${i.version}`),!0}async function Gv(){let t={cli:null,kits:null};try{let e=await Ds(Ts);e&&(t.cli={current:Pe,latest:e.version,available:Vn(Pe,e.version)})}catch{}try{let e=ui(),i=await Ki();e&&i&&(t.kits={current:e.version,latest:i.version,available:Vn(e.version,i.version)})}catch{}return t}var Mv="gemkit-cli";function yh(t){return Zh("npm",["install","-g",`${Mv}@${t}`],{encoding:"utf-8",stdio:"pipe",shell:!0}).status===0}function qh(t){switch(t){case"gemini":return[".claude",".claude/**",".agent",".agent/**"];case"claude":return[".agent",".agent/**"];case"antigravity":return[".claude",".claude/**"];default:return[]}}function wh(t){switch(t){case"gemini":return"Gemini CLI (excludes .claude, .agent)";case"claude":return"Claude Code (excludes .agent)";case"antigravity":return"Antigravity (excludes .claude)";default:return"Full (all files)"}}function Dh(t,e){let i=t.replace(/\\/g,"/");for(let n of e)if(n.includes("*")){if(n.endsWith("/**")){let s=n.slice(0,-3);if(i.startsWith(s+"/"))return!0}}else if(i===n||i.startsWith(n+"/"))return!0;return!1}function Th(t){if(t.length!==0)return e=>!Dh(e,t)}async function Xh(){let t=Bh(".gemini","extensions","spawn-agent");return Qh(t)?new Promise(e=>{let i=Jh("gemini",["extensions","install",t],{stdio:["pipe","pipe","pipe"],shell:process.platform==="win32",cwd:process.cwd()}),n="",s="",r=!1,o=setTimeout(()=>{r||(r=!0,i.kill(),e({success:!1,error:"Extension installation timed out"}))},3e4);i.stdout?.on("data",c=>{n+=c.toString()}),i.stderr?.on("data",c=>{s+=c.toString()}),i.on("close",c=>{r||(r=!0,clearTimeout(o),e(c===0?{success:!0}:{success:!1,error:s||n||`Exit code: ${c}`}))}),i.on("error",c=>{r||(r=!0,clearTimeout(o),e({success:!1,error:`Failed to run gemini CLI: ${c.message}`}))})}):{success:!1,error:`Extension directory not found: ${t}`}}function Yv(t){t.command("init","Initialize GemKit in project").option("--version <ver>","Specific version to install").option("-f, --force","Overwrite existing installation").option("--exclude <patterns...>","File patterns to exclude").option("--skip-extension","Skip spawn-agent extension installation").option("--full","Install all files (default)").option("--gemini","Gemini CLI mode (excludes .claude, .agent folders)").option("--claude","Claude Code mode (excludes .agent folder)").option("--antigravity","Antigravity mode (excludes .claude folder)").action(async e=>{let i="full";if(e.gemini?i="gemini":e.claude?i="claude":e.antigravity?i="antigravity":e.full&&(i="full"),Iv()&&!e.force){console.log(),v.warn("GemKit is already installed. Use --force to reinstall."),console.log();return}console.log(),console.log(h.default.bold(a.geminiPurple("Initializing GemKit"))),console.log(),console.log(` ${a.dim("Mode")} ${a.accent(wh(i))}`),console.log();let n=lt({text:"Checking CLI version...",color:"magenta"}).start();try{let f=await Ds(Mv);f&&Vn(Pe,f.version)?(n.text=`Updating CLI v${Pe} \u2192 v${f.version}...`,yh(f.version)?n.succeed(`CLI updated v${a.primary(Pe)} \u2192 v${a.primary(f.version)}`):n.warn(`CLI v${a.primary(Pe)} (update to v${f.version} failed)`)):n.succeed(`CLI v${a.primary(Pe)}`)}catch{n.succeed(`CLI v${a.primary(Pe)}`)}let s=lt({text:"Fetching latest Kits release...",color:"magenta"}).start(),r=e.version?await $m(e.version):await Ki();r||(s.fail("No Kits release found"),console.log(),process.exit(1)),s.succeed(`Found Kits v${a.primary(r.version)}`);let o=lt({text:"Downloading Kits...",color:"magenta"}).start(),c;try{c=await pn(r),o.succeed("Kits downloaded")}catch(f){o.fail(`Kits download failed: ${f instanceof Error?f.message:String(f)}`),console.log(),process.exit(1)}let l=qh(i),u=lt({text:i==="full"?"Extracting Kits...":`Extracting Kits (${i} mode)...`,color:"magenta"}).start(),m=process.cwd(),p=await kn({source:c,destination:m,strip:1,filter:Th(l)});p.success||(u.fail(`Kits extraction failed: ${p.error}`),console.log(),process.exit(1)),u.succeed(`Extracted ${p.extractedFiles.length} files`);let d=gv(r.version,"local",p.extractedFiles);if(Po(d),console.log(),v.success(`Kits v${a.primary(r.version)} installed successfully!`),!e.skipExtension&&(i==="full"||i==="gemini")){console.log();let f=lt({text:"Installing spawn-agent extension...",color:"magenta"}).start(),g=await Xh();g.success?f.succeed("spawn-agent extension installed in Gemini CLI"):(f.warn(`Could not install spawn-agent extension: ${g.error}`),v.info(`You can manually install it with: ${a.primary("gemini extensions install .gemini/extensions/spawn-agent")}`))}else(i==="claude"||i==="antigravity")&&(console.log(),v.info(`Skipped Gemini extension (${i} mode).`));console.log(),v.info(`Run ${a.primary("gk doctor")} to verify installation.`),console.log()})}function Wv(t){t.command("versions","List available GemKit versions").alias("v").option("--json","Output as JSON").action(async e=>{let i=ui(),n=await Or();if(e.json){console.log(JSON.stringify({current:i?.version||null,available:n},null,2));return}console.log(),console.log(h.default.bold(a.geminiPurple("GemKit Versions"))),console.log(),console.log(i?` ${a.dim("Current:")} ${a.success(i.version)}`:` ${a.dim("Current:")} ${a.dim("Not installed")}`),console.log(),console.log(` ${h.default.bold("Available Releases:")}`);for(let s of n){let r=s.version===i?.version?a.success(" (current)"):"";console.log(` - ${a.primary(s.version)}${r}`)}console.log()})}import{existsSync as Zo}from"fs";import{join as Hh}from"path";import{spawn as Cv}from"child_process";k();async function Lh(){return new Promise(t=>{let e=Cv("gemini",["extensions","list"],{stdio:["pipe","pipe","pipe"],shell:process.platform==="win32"}),i="",n="",s=!1,r=setTimeout(()=>{s||(s=!0,e.kill(),t({installed:!1,error:"Check timed out"}))},2e4);e.stdout?.on("data",o=>{i+=o.toString()}),e.stderr?.on("data",o=>{n+=o.toString()}),e.on("close",o=>{if(!s)if(s=!0,clearTimeout(r),o===0){let c=i.toLowerCase().includes("spawn-agent");t({installed:c})}else t({installed:!1,error:n||"Failed to check extensions"})}),e.on("error",o=>{s||(s=!0,clearTimeout(r),t({installed:!1,error:`Gemini CLI not available: ${o.message}`}))})})}async function _h(){return new Promise(t=>{let e=Cv("gemini",["--version"],{stdio:["pipe","pipe","pipe"],shell:process.platform==="win32"}),i="",n=!1,s=setTimeout(()=>{n||(n=!0,e.kill(),t({available:!1,error:"Timed out"}))},15e3);e.stdout?.on("data",r=>{i+=r.toString()}),e.on("close",r=>{if(!n)if(n=!0,clearTimeout(s),r===0){let o=i.trim().split(`
49
+ `)[0]||"unknown";t({available:!0,version:o})}else t({available:!1,error:"Command failed"})}),e.on("error",r=>{n||(n=!0,clearTimeout(s),t({available:!1,error:r.message}))})})}function Ov(t){t.command("doctor","Check installation health").option("--fix","Attempt to fix issues").action(async e=>{console.log(),console.log(h.default.bold(a.geminiPurple("GemKit Health Check"))),console.log();let i=0,n=0,s=[],r=process.version;parseInt(r.slice(1).split(".")[0],10)>=18?s.push({icon:a.success("\u2713"),message:`Node.js ${r}`}):(s.push({icon:a.error("\u2717"),message:`Node.js ${r} ${a.error("(requires >= 18)")}`}),i++);let c=lt({text:"Checking Gemini CLI...",color:"magenta"}).start(),l=await _h();c.stop(),l.available?s.push({icon:a.success("\u2713"),message:`Gemini CLI ${a.dim(`(${l.version})`)}`}):(s.push({icon:a.error("\u2717"),message:`Gemini CLI not found ${a.dim(`(${l.error})`)}`}),i++);let u=Mr();Zo(u)?s.push({icon:a.success("\u2713"),message:".gemini directory exists"}):(s.push({icon:a.error("\u2717"),message:".gemini directory missing"}),i++);let m=as();Zo(m)?s.push({icon:a.success("\u2713"),message:"Agents directory exists"}):(s.push({icon:a.warn("\u25CB"),message:"Agents directory missing"}),n++);let p=Ci();Zo(p)?s.push({icon:a.success("\u2713"),message:"Extensions directory exists"}):(s.push({icon:a.warn("\u25CB"),message:"Extensions directory missing"}),n++);let d=Hh(p,"spawn-agent");if(Zo(d)?s.push({icon:a.success("\u2713"),message:"spawn-agent extension files present"}):(s.push({icon:a.warn("\u25CB"),message:"spawn-agent extension files missing"}),n++),l.available){let f=lt({text:"Checking spawn-agent extension...",color:"magenta"}).start(),g=await Lh();f.stop(),g.installed?s.push({icon:a.success("\u2713"),message:"spawn-agent extension installed in Gemini"}):(s.push({icon:a.error("\u2717"),message:"spawn-agent extension NOT installed in Gemini",hint:g.error?`${g.error}
50
+ Run: gemini extensions install .gemini/extensions/spawn-agent`:"Run: gemini extensions install .gemini/extensions/spawn-agent"}),i++)}let A=ui();A?s.push({icon:a.success("\u2713"),message:`Installation metadata ${a.primary(`(v${A.version})`)}`}):(s.push({icon:a.warn("\u25CB"),message:"Installation metadata missing"}),n++);for(let f of s)if(console.log(` ${f.icon} ${f.message}`),f.hint)for(let g of f.hint.split(`
51
+ `))console.log(` ${a.dim(g)}`);console.log(),i===0&&n===0?console.log(a.success("All checks passed!")):i===0?console.log(a.success(`All critical checks passed! ${a.dim(`(${n} warning${n>1?"s":""})`)}`)):(console.log(a.error(`${i} issue(s) found.`)),n>0&&console.log(a.warn(`${n} warning(s).`)),console.log(),console.log("To fix issues:"),console.log(` ${a.dim("1.")} Run ${a.primary("gk init")} to install GemKit`),console.log(` ${a.dim("2.")} Run ${a.primary("gemini extensions install .gemini/extensions/spawn-agent")} to install extension`)),console.log()})}function $h(){console.log(),console.log(h.default.bold(a.geminiPurple("Configuration Management"))),console.log(),console.log("Usage:"),console.log(` ${a.primary("gk config")} <subcommand> [options]`),console.log(),console.log("Subcommands:"),console.log(` ${a.primary("list")} Show all config (default)`),console.log(` ${a.primary("get")} <key> Get config value`),console.log(` ${a.primary("set")} <key> <val> Set config value`),console.log(` ${a.primary("reset")} Reset to defaults`),console.log(),console.log("Options:"),console.log(` ${a.dim("--json")} [list] Output as JSON`),console.log(),console.log("Examples:"),console.log(` ${a.dim("gk config list")}`),console.log(` ${a.dim("gk config get spawn.defaultModel")}`),console.log(` ${a.dim("gk config set spawn.music true")}`),console.log(` ${a.dim("gk config reset")}`),console.log()}function Uv(t){t.command("config [subcommand] [key] [value]","Configuration management (list, get, set, reset)").alias("c").option("--json","[list] Output as JSON").action(async(e,i,n,s)=>{switch(e||"list"){case"list":await eg(s);break;case"get":i||(console.log(),v.error("Config key required"),console.log(a.dim("Usage: gk config get <key>")),console.log(),process.exit(1)),await tg(i);break;case"set":(!i||n===void 0)&&(console.log(),v.error("Config key and value required"),console.log(a.dim("Usage: gk config set <key> <value>")),console.log(),process.exit(1)),await ig(i,n);break;case"reset":await ng();break;default:$h()}})}async function eg(t){let e=Ie();if(t.json){console.log(JSON.stringify(e,null,2));return}console.log(),console.log(h.default.bold(a.geminiPurple("GemKit Configuration"))),console.log(),console.log(JSON.stringify(e,null,2)),console.log()}async function tg(t){let e=Zm(t);if(e===void 0){console.log(),v.error(`Config key not found: ${t}`),console.log();return}console.log(e)}async function ig(t,e){let i=e;e==="true"?i=!0:e==="false"?i=!1:isNaN(Number(e))||(i=Number(e));try{ym(t,i),console.log(),v.success(`Config updated: ${a.primary(t)} = ${a.success(String(i))}`),console.log()}catch(n){console.log(),v.error(`Failed to set config: ${n instanceof Error?n.message:String(n)}`),console.log()}}async function ng(){qm(),console.log(),v.success("Configuration reset to defaults."),console.log()}function Kv(t){let e=t.command("cache <subcommand>","Cache management");e.example("gk cache stats # Show cache statistics"),e.example("gk cache clear # Clear all cache"),e.action(async i=>{let n=i||"stats";switch(n){case"stats":await sg();break;case"clear":await rg();break;default:console.log(),v.error(`Unknown subcommand: ${n}`),console.log(),process.exit(1)}})}async function sg(){let t=Lm();console.log(),console.log(h.default.bold(a.geminiPurple("Cache Statistics"))),console.log(),console.log(` ${a.dim("Entries:")} ${a.primary(String(t.entries))}`),console.log(` ${a.dim("Size:")} ${a.primary((t.size/1024).toFixed(2))} KB`),console.log()}async function rg(){let t=Hm();console.log(),v.success(`Cleared ${a.success(String(t))} cache entries.`),console.log()}import{existsSync as og}from"fs";import{join as ag}from"path";function kv(t){t.command("new <name>","Create a new project from starter kit").action(async e=>{let i=ag(process.cwd(),e);og(i)&&(console.log(),v.error(`Directory already exists: ${e}`),console.log(),process.exit(1)),console.log(),console.log(h.default.bold(a.geminiPurple("Creating New Project"))),console.log(),v.info(`Name: ${a.primary(e)}`);let n=await Ki();n||(v.error("Failed to fetch latest starter kit."),console.log(),process.exit(1)),v.info(`Fetching latest starter kit (v${n.version})...`);let s=await pn(n),r=await kn({source:s,destination:i,strip:1});r.success?(console.log(),v.success(`Project ${a.primary(e)} created successfully!`),console.log(`
23
52
  Next steps:
24
- cd ${s.primary(e)}
53
+ cd ${a.primary(e)}
25
54
  gk init
26
- `)):(m.error(`Failed to create project: ${o.error}`),console.log())})}import{spawn as rI}from"child_process";import{access as oI,stat as sI,readdir as aI,readFile as iA}from"fs/promises";import{join as qi,basename as cI,extname as lI,relative as vI}from"path";import{existsSync as Ko,readFileSync as Gp,readdirSync as Sp}from"fs";import{join as vc,basename as Yp}from"path";var fp={"gemini-3-pro-preview":"opus","gemini-2.5-pro":"opus","gemini-3-flash-preview":"sonnet","gemini-2.5-flash":"sonnet","gemini-2.5-flash-lite":"haiku"},hp={opus:"gemini-2.5-pro",sonnet:"gemini-2.5-flash",haiku:"gemini-2.5-flash-lite"},dp=["haiku","sonnet","opus"];function Oo(t,e){return e==="claude"?dp.includes(t)?t:fp[t]||"sonnet":t.startsWith("gemini-")?t:hp[t]||"gemini-2.5-flash"}var Rp={list_directory:"Bash",read_file:"Read",write_file:"Write",glob:"Glob",search_file_content:"Grep",replace:"Edit",run_shell_command:"Bash",web_fetch:"WebFetch",google_web_search:"WebSearch",save_memory:"TodoWrite",write_todos:"TodoWrite"},zp={Read:"read_file",Write:"write_file",Edit:"replace",Bash:"run_shell_command",Glob:"glob",Grep:"search_file_content",WebFetch:"web_fetch",WebSearch:"google_web_search",TodoWrite:"write_todos",Task:""};function gp(t){return/^[A-Z]/.test(t)}function jp(t){return t.includes("_")||t.startsWith("gemini")}function xp(t,e){let i=t.match(/^([^(]+)(\(.*\))?$/),n=i?.[1]||t,r=i?.[2]||"";if(e==="claude"){if(gp(n))return t;let o=Rp[n];return o?n==="run_shell_command"&&r==="(*)"?o:o+r:t}else{if(jp(n))return t;let o=zp[n];return o?n==="Bash"&&!r?"run_shell_command(*)":o+r:t}}function Uo(t,e){let i=t.map(n=>xp(n,e)).filter(Boolean);return[...new Set(i)]}function Cv(t){return t==="claude"?[".claude/agents",".gemini/agents"]:[".gemini/agents",".claude/agents"]}function Kv(t,e){let i=on(e),n=vc(i,`${t}.md`);return Ko(n)?Ac(n):null}function Vo(t){let e=on(t);if(!Ko(e))return[];let i=Sp(e).filter(r=>r.endsWith(".md")),n=[];for(let r of i){let o=vc(e,r),a=Ac(o);a&&n.push(a)}return n}function Wp(t){let e=t.match(/^---\r?\n([\s\S]*?)\r?\n---/);if(!e)return null;let i={};for(let n of e[1].split(/\r?\n/)){let r=n.indexOf(":");if(r===-1)continue;let o=n.slice(0,r).trim(),a=n.slice(r+1).trim();(a.startsWith('"')&&a.endsWith('"')||a.startsWith("'")&&a.endsWith("'"))&&(a=a.slice(1,-1)),i[o]=a}return i}function Ov(t){if(!t)return[];let e=t.trim();return e.startsWith("[")&&e.endsWith("]")&&(e=e.slice(1,-1)),e.split(",").map(i=>i.trim().replace(/['"]/g,"")).filter(Boolean)}function Uv(t){if(!t)return[];let e=t.trim();return e.startsWith("[")&&e.endsWith("]")&&(e=e.slice(1,-1)),e.split(",").map(i=>i.trim().replace(/['"]/g,"")).filter(Boolean)}function Ac(t){if(!Ko(t))return null;let e=Gp(t,"utf-8"),i=Yp(t,".md"),n="",r="gemini-2.5-flash",o=[],a=[],c=Wp(e),l=e;if(c)c.description&&(n=c.description),c.model&&(r=c.model),o=Ov(c.skills),a=Uv(c.tools),l=e.replace(/^---\r?\n[\s\S]*?\r?\n---\r?\n?/,"").trim();else{let v=e.split(`
27
- `);for(let E of v){if(E.startsWith("# ")){n=E.substring(2).trim();break}if(E.trim()&&!E.startsWith("#")){n=E.trim();break}}let A=e.match(/model:\s*(.+)/i);A&&(r=A[1].trim());let u=e.match(/skills:\s*(.+)/i);u&&(o=Ov(u[1]));let p=e.match(/tools:\s*(.+)/i);p&&(a=Uv(p[1]))}return{name:i,description:n,model:r,skills:o,tools:a,content:l,filePath:t}}function Vv(t,e,i){let n=i||process.cwd(),r=Cv(e);for(let o of r){let a=vc(n,o,`${t}.md`);if(Ko(a)){let c=Ac(a);if(c)return o===r[0]||(c.model=Oo(c.model,e),c.tools&&c.tools.length>0&&(c.tools=Uo(c.tools,e))),c}}return null}import{existsSync as li,readFileSync as Ec,readdirSync as Mp}from"fs";import{join as Tn}from"path";var pc=".gemini/extensions/spawn-agent/data",Nv=3,kv={combination:{file:"combinations.csv",searchCols:["keywords","description","use_when","agent","skills","intent","domain"],outputCols:["id","agent","skills","intent","domain","complexity","description","use_when"]},intent:{file:"intents.csv",searchCols:["primary_keywords","expanded_keywords","question_patterns"],outputCols:["intent","agent","primary_keywords","expanded_keywords","action_verbs"]},domain:{file:"domains.csv",searchCols:["keywords","frameworks","file_patterns","technical_terms"],outputCols:["domain","base_skills","enhanced_skills","keywords","frameworks"]},synonym:{file:"synonyms.csv",searchCols:["word","synonyms"],outputCols:["word","synonyms","category"]}},Cp={simple:["quick","simple","basic","small","minor","trivial","easy","straightforward"],standard:[],full:["comprehensive","full","complete","entire","thorough","detailed"],complex:["deep","extensive","advanced","complex","sophisticated","enterprise","production"]};var uc={research:"researcher",plan:"planner",execute:"code-executor",debug:"debugger",review:"code-reviewer",test:"tester",design:"ui-ux-designer",docs:"docs-manager",git:"git-manager",manage:"project-manager"},Op={frontend:["frontend-design"],backend:["backend-development"],auth:["better-auth","backend-development"],payment:["payment-integration"],database:["databases"],mobile:["mobile-development"],fullstack:["web-frameworks","backend-development"],ecommerce:["shopify"],media:["ai-multimodal"],ai:["ai-multimodal"],quality:["code-review"],codebase:["repomix"],general:["research"]},No=class{k1;b;corpus=[];docLengths=[];avgdl=0;idf=new Map;docFreqs=new Map;N=0;constructor(e=1.5,i=.75){this.k1=e,this.b=i}tokenize(e){return String(e).toLowerCase().replace(/[^\w\s]/g," ").split(/\s+/).filter(n=>n.length>1)}fit(e){if(this.corpus=e.map(i=>this.tokenize(i)),this.N=this.corpus.length,this.N!==0){this.docLengths=this.corpus.map(i=>i.length),this.avgdl=this.docLengths.reduce((i,n)=>i+n,0)/this.N;for(let i of this.corpus){let n=new Set;for(let r of i)n.has(r)||(this.docFreqs.set(r,(this.docFreqs.get(r)||0)+1),n.add(r))}for(let[i,n]of this.docFreqs.entries())this.idf.set(i,Math.log((this.N-n+.5)/(n+.5)+1))}}score(e){let i=this.tokenize(e),n=[];for(let r=0;r<this.corpus.length;r++){let o=this.corpus[r],a=0,c=this.docLengths[r],l=new Map;for(let v of o)l.set(v,(l.get(v)||0)+1);for(let v of i){let A=this.idf.get(v);if(A!==void 0){let u=l.get(v)||0,p=u*(this.k1+1),E=u+this.k1*(1-this.b+this.b*c/this.avgdl);a+=A*p/E}}n.push([r,a])}return n.sort((r,o)=>o[1]-r[1])}};function Up(t){let e=[],i="",n=!1;for(let r=0;r<t.length;r++){let o=t[r];o==='"'?n=!n:o===","&&!n?(e.push(i),i=""):i+=o}return e.push(i),e}function Ic(t){if(!li(t))return[];let i=Ec(t,"utf-8").trim().split(`
28
- `);if(i.length<2)return[];let n=i[0].split(",").map(o=>o.trim()),r=[];for(let o=1;o<i.length;o++){let a=Up(i[o]),c={};n.forEach((l,v)=>{c[l]=a[v]?.trim()||""}),r.push(c)}return r}function Kp(t,e,i,n,r){if(!li(t))return[];let o=Ic(t),a=o.map(A=>e.map(u=>String(A[u]||"")).join(" ")),c=new No;c.fit(a);let l=c.score(n),v=[];for(let[A,u]of l.slice(0,r))if(u>0){let p=o[A],E={};for(let f of i)f in p&&(E[f]=p[f]);E._score=Math.round(u*1e4)/1e4,v.push(E)}return v}function fc(){let t=Tn(pc,"synonyms.csv");if(!li(t))return new Map;let e=Ic(t),i=new Map;for(let n of e){let r=(n.word||"").toLowerCase().trim(),o=(n.synonyms||"").toLowerCase().trim();r&&o&&i.set(r,o.split(",").map(a=>a.trim()))}return i}function Fv(t,e){e||(e=fc());let i=t.toLowerCase().replace(/[^\w\s]/g," ").split(/\s+/),n=new Set(i);for(let r of i){let o=e.get(r);o&&o.forEach(a=>n.add(a))}return Array.from(n).join(" ")}function hc(t){let e=t.toLowerCase();for(let[i,n]of Object.entries(Cp))for(let r of n)if(e.includes(r))return i;return"standard"}function dc(t){let e=t.toLowerCase(),n=e.split(/\s+/)[0]||"",r=[[/system architecture/,"plan"],[/design.*architecture/,"plan"],[/architect.*system/,"plan"],[/create.*roadmap/,"plan"],[/build.*roadmap/,"plan"],[/create.*strategy/,"plan"],[/stunning/,"design"],[/gorgeous/,"design"],[/beautiful.*ui/,"design"],[/beautiful.*component/,"design"],[/beautiful.*page/,"design"],[/write.*documentation/,"docs"],[/write.*docs/,"docs"],[/create.*documentation/,"docs"],[/research.*codebase/,"research"],[/deep research/,"research"]];for(let[v,A]of r)if(typeof v=="string"?e.includes(v):v.test(e))return A;let o={implement:"execute",build:"execute",create:"execute",add:"execute",make:"execute",code:"execute",develop:"execute",write:"execute",setup:"execute",configure:"execute",test:"test",verify:"test",validate:"test",debug:"debug",fix:"debug",troubleshoot:"debug",review:"review",audit:"review",document:"docs",plan:"plan",design:"design",research:"research",analyze:"research",investigate:"research"};if(n in o)return o[n];let a=[["best practices","research"],["how does","research"],["how do","research"],["what is","research"],["why is","research"],["compare","research"],["investigate","research"],["research","research"],["understand","research"],["system architecture","plan"],["implementation plan","plan"],["roadmap","plan"],["strategy for","plan"],["blueprint","plan"],["fix the","debug"],["debug the","debug"],["not working","debug"],["is broken","debug"],["error in","debug"],["fix bug","debug"],["test the","test"],["run tests","test"],["verify the","test"],["review the","review"],["audit the","review"],["check code","review"],["document the","docs"],["write docs","docs"],["api documentation","docs"]];for(let[v,A]of a)if(e.includes(v))return A;let c={debug:["fix","debug","troubleshoot","error","issue","bug","broken","failing","crash"],review:["review","audit","assess","check code","pr review","security audit"],test:["test","verify","validate","qa","coverage","unit test","e2e test"],design:["beautiful","stunning","gorgeous","ui design","ux design","mockup","layout"],docs:["document","documentation","readme","api docs","technical writing"],git:["commit","push","pull","merge","branch","git","stage"],manage:["status","progress","track","milestone","sprint"],plan:["plan","architect","roadmap","strategy","architecture design"],execute:["implement","build","create","add","make","code","develop"],research:["research","investigate","explore","study","analyze","examine","learn"]},l={};for(let[v,A]of Object.entries(c)){let u=A.filter(p=>e.includes(p)).length;u>0&&(l[v]=u)}return Object.keys(l).length>0?Object.entries(l).sort((v,A)=>A[1]-v[1])[0][0]:"execute"}function Rc(t){let e=t.toLowerCase(),i=[["flutter","mobile"],["react native","mobile"],["swift","mobile"],["kotlin","mobile"],["ios app","mobile"],["android app","mobile"],["next.js","fullstack"],["nextjs","fullstack"],["nuxt","fullstack"],["sveltekit","fullstack"],["remix","fullstack"],["server component","fullstack"],["openai","ai"],["anthropic","ai"],["claude","ai"],["langchain","ai"],["llm","ai"],["chatbot","ai"],["rag","ai"],["embedding","ai"],["gpt","ai"],["angular","frontend"],["react","frontend"],["vue","frontend"],["svelte","frontend"],["tailwind","frontend"],["nestjs","backend"],["express","backend"],["fastify","backend"],["hono","backend"],["fastapi","backend"],["websocket","backend"],["shopify","ecommerce"],["product catalog","ecommerce"],["checkout flow","ecommerce"],["stripe","payment"],["paypal","payment"],["subscription","payment"],["billing","payment"],["oauth","auth"],["authentication","auth"],["login","auth"],["signup","auth"],["prisma","database"],["drizzle","database"],["postgresql","database"],["mongodb","database"],["mysql","database"],["pdf","media"],["image","media"],["video","media"],["audio","media"],["codebase","codebase"],["repository","codebase"]];for(let[o,a]of i)if(e.includes(o))return a;let n={auth:["login","signup","authentication","oauth","jwt","session","password","2fa"],payment:["payment","checkout","billing","stripe","subscription","invoice","cart"],database:["database","sql","query","migration","schema","prisma","postgresql"],frontend:["ui","component","react","vue","css","tailwind","button","form","modal"],backend:["api","endpoint","server","service","route","rest","graphql","middleware"],mobile:["mobile","ios","android","react native","flutter","app","native"],fullstack:["fullstack","nextjs","next.js","nuxt","sveltekit","app router"],ecommerce:["ecommerce","shopify","store","product","cart","checkout","order"],media:["image","video","audio","media","upload","file","ocr"],ai:["ai","llm","gpt","claude","machine learning","embedding","vector","openai"],quality:["code review","lint","test","coverage","quality","refactor"],codebase:["codebase","repository","repo","project structure"],general:[]},r={};for(let[o,a]of Object.entries(n)){let c=a.filter(l=>e.includes(l)).length;c>0&&(r[o]=c)}return Object.keys(r).length>0?Object.entries(r).sort((o,a)=>a[1]-o[1])[0][0]:"general"}function Qv(t,e=Nv,i=!0){let n=kv.combination,r=Tn(pc,n.file),o=t;if(i){let c=fc();o=Fv(t,c)}let a=Kp(r,n.searchCols,n.outputCols,o,e);return{query:t,expandedQuery:i?o:void 0,detectedIntent:dc(t),detectedDomain:Rc(t),detectedComplexity:hc(t),count:a.length,results:a}}function mc(t,e,i,n=Nv,r=!0){let o=kv.combination,a=Tn(pc,o.file);if(!li(a))return{results:[],count:0};let c=Ic(a);if(e&&(c=c.filter(E=>(E.intent||"").toLowerCase()===e.toLowerCase())),i&&(c=c.filter(E=>(E.domain||"").toLowerCase()===i.toLowerCase())),c.length===0)return{results:[],count:0};let l=t;if(r){let E=fc();l=Fv(t,E)}let v=c.map(E=>o.searchCols.map(f=>String(E[f]||"")).join(" ")),A=new No;A.fit(v);let u=A.score(l),p=[];for(let[E,f]of u.slice(0,n))if(f>0){let d=c[E],z={};for(let C of o.outputCols)C in d&&(z[C]=d[C]);z._score=Math.round(f*1e4)/1e4,p.push(z)}return{results:p,count:p.length}}function Vp(t){let e=dc(t),i=Rc(t),n=hc(t);if(["debug","review","test","design","docs","research","plan"].includes(e)){let A=mc(t,e,void 0,1,!0);if(A.results.length>0){let u=A.results[0],E=(u.skills||"").split("|").map(f=>f.trim()).filter(Boolean);return{agent:uc[e]||u.agent||"code-executor",skills:E,intent:e,domain:u.domain||i,complexity:u.complexity||n,score:u._score||0,fallback:!1,description:u.description||"",useWhen:u.use_when||""}}}if(e==="execute"&&["mobile","ai","payment","ecommerce","media","auth","database","fullstack"].includes(i)){let A=mc(t,"execute",i,1,!0);if(A.results.length>0){let u=A.results[0];return{agent:"code-executor",skills:(u.skills||"").split("|").map(f=>f.trim()).filter(Boolean),intent:e,domain:i,complexity:u.complexity||n,score:u._score||0,fallback:!1,description:u.description||"",useWhen:u.use_when||""}}}let a=Qv(t,1,!0);if(a.count===0){let A=uc[e]||"code-executor",u=Op[i]||["research"];return{agent:A,skills:u,intent:e,domain:i,complexity:n,score:0,fallback:!0,description:`Fallback combination based on detected intent (${e}) and domain (${i})`}}let c=a.results[0],v=(c.skills||"").split("|").map(A=>A.trim()).filter(Boolean);return{agent:c.agent||"code-executor",skills:v,intent:c.intent||e,domain:c.domain||i,complexity:c.complexity||n,score:c._score||0,fallback:!1,description:c.description||"",useWhen:c.use_when||""}}function bv(t,e){let{top:i=5,forceIntent:n,forceDomain:r,maxSkills:o}=e||{};if(n||r)return mc(t,n,r,i,!0).results.map(l=>{let A=(l.skills||"").split("|").map(u=>u.trim()).filter(Boolean);return o&&(A=A.slice(0,o)),{agent:n?uc[n]:l.agent||"code-executor",skills:A,intent:l.intent||n||dc(t),domain:l.domain||r||Rc(t),complexity:l.complexity||hc(t),score:l._score||0,fallback:!1,description:l.description||"",useWhen:l.use_when||""}});let a=Qv(t,i,!0);return a.count===0?[Vp(t)]:a.results.map(c=>{let v=(c.skills||"").split("|").map(A=>A.trim()).filter(Boolean);return o&&(v=v.slice(0,o)),{agent:c.agent||"code-executor",skills:v,intent:c.intent||a.detectedIntent,domain:c.domain||a.detectedDomain,complexity:c.complexity||a.detectedComplexity,score:c._score||0,fallback:!1,description:c.description||"",useWhen:c.use_when||""}})}function Jv(t){let e=Bt(t),i=[];if(!li(e))return i;let n=Mp(e,{withFileTypes:!0}).filter(r=>r.isDirectory()).map(r=>r.name);for(let r of n){let o=Tn(e,r,"SKILL.md");if(li(o)){let a=Ec(o,"utf-8");i.push({name:r,path:o,content:a})}}return i}function Bv(t,e){let i=Bt(e),n=Tn(i,t,"SKILL.md");return li(n)?Ec(n,"utf-8"):null}import{existsSync as Np,readFileSync as kp}from"fs";function k(t=process.cwd()){let e={ACTIVE_GK_SESSION_ID:"",GK_PROJECT_HASH:"",PROJECT_DIR:"",ACTIVE_GEMINI_SESSION_ID:"",GEMINI_PROJECT_HASH:"",GEMINI_PARENT_ID:"",ACTIVE_PLAN:"",SUGGESTED_PLAN:"",PLAN_DATE_FORMAT:""},i=Jt(t);if(!Np(i))return e;try{let n=kp(i,"utf-8"),r=n.match(/^ACTIVE_GK_SESSION_ID=(.*)$/m);r&&(e.ACTIVE_GK_SESSION_ID=r[1].trim());let o=n.match(/^GK_PROJECT_HASH=(.*)$/m);o&&(e.GK_PROJECT_HASH=o[1].trim());let a=n.match(/^PROJECT_DIR=(.*)$/m);a&&(e.PROJECT_DIR=a[1].trim());let c=n.match(/^ACTIVE_GEMINI_SESSION_ID=(.*)$/m);c&&(e.ACTIVE_GEMINI_SESSION_ID=c[1].trim());let l=n.match(/^GEMINI_PROJECT_HASH=(.*)$/m);l&&(e.GEMINI_PROJECT_HASH=l[1].trim());let v=n.match(/^GEMINI_PARENT_ID=(.*)$/m);v&&(e.GEMINI_PARENT_ID=v[1].trim());let A=n.match(/^ACTIVE_PLAN=(.*)$/m);A&&(e.ACTIVE_PLAN=A[1].trim());let u=n.match(/^SUGGESTED_PLAN=(.*)$/m);u&&(e.SUGGESTED_PLAN=u[1].trim());let p=n.match(/^PLAN_DATE_FORMAT=(.*)$/m);p&&(e.PLAN_DATE_FORMAT=p[1].trim())}catch{}return e}function vi(t=process.cwd()){return k(t).ACTIVE_GK_SESSION_ID||void 0}function at(t=process.cwd()){let e=k(t);return e.PROJECT_DIR?e.PROJECT_DIR:sn(t)}function ko(t=process.cwd()){return k(t).GEMINI_PROJECT_HASH||void 0}function Xn(t=process.cwd()){return k(t).ACTIVE_PLAN||void 0}import{existsSync as wv,mkdirSync as Pp,writeFileSync as zc,readFileSync as qp,renameSync as yp,unlinkSync as Dp}from"fs";import{execSync as wp}from"child_process";import{join as Tp}from"path";import{createHash as Fp}from"crypto";function Qp(t){return Fp("sha256").update(t).digest("hex")}function bp(t){return Qp(t).substring(0,8)}function Zv(t){let e=t.replace(/\\/g,"/").toLowerCase();return bp(e)}function Fo(t,e){let i=Date.now().toString(36),n=Math.random().toString(36).substring(2,6);return`${t}-${e}-${i}-${n}`}import{existsSync as Pv,readFileSync as qv,readdirSync as Jp}from"fs";import{join as Bp}from"path";function Ce(t,e){if(!t||!e)return null;let i=Zt(t,e);if(!Pv(i))return null;try{let n=qv(i,"utf-8");return JSON.parse(n)}catch{return null}}function yv(t,e={}){let{limit:i=10,status:n="all"}=e,r=we(t);if(!Pv(r))return[];let o=[];try{let a=Jp(r).filter(c=>c.startsWith("gk-session-")&&c.endsWith(".json"));for(let c of a){let l=Bp(r,c),v=qv(l,"utf-8"),A=JSON.parse(v);n!=="all"&&(A.agents?.find(E=>E.agentType==="Main Agent")?.status||"active")!==n||o.push(A)}}catch{}return o.sort((a,c)=>new Date(c.initTimestamp).getTime()-new Date(a.initTimestamp).getTime()),o.slice(0,i)}function Zp(t,e,i={}){let n=Ce(t,e);if(!n||!n.agents)return[];let r=n.agents;return i.agentType&&(r=r.filter(o=>o.agentType===i.agentType)),i.status&&(r=r.filter(o=>o.status===i.status)),r}function Dv(t,e){let i=Zp(t,e),n={total:i.length,active:0,completed:0,failed:0,mainAgents:0,subAgents:0,totalDurationMs:0};return i.forEach(r=>{r.status==="active"?n.active++:r.status==="completed"?n.completed++:r.status==="failed"&&n.failed++,r.agentType==="Main Agent"?n.mainAgents++:n.subAgents++,r.startTime&&r.endTime&&(n.totalDurationMs+=new Date(r.endTime).getTime()-new Date(r.startTime).getTime())}),n}function Xp(t){try{let e=`powershell -Command "$p = Get-CimInstance Win32_Process -Filter 'ProcessId=${t}'; Write-Output $p.ParentProcessId; Write-Output $p.Name"`,n=wp(e,{encoding:"utf8",stdio:["pipe","pipe","pipe"]}).trim().split(/\r?\n/),r=parseInt(n[0],10),o=n[1]||null;return{parentPid:!isNaN(r)&&r>0?r:null,processName:o}}catch{return{parentPid:null,processName:null}}}function Hp(t){return t?["powershell.exe","pwsh.exe","cmd.exe","bash.exe","zsh.exe","sh.exe","fish.exe"].includes(t.toLowerCase()):!1}function Lp(t){if(!t)return!1;let e=t.toLowerCase();return["code.exe","code - insiders.exe","cursor.exe","windsurf.exe","positron.exe","idea64.exe","idea.exe","webstorm64.exe","webstorm.exe","pycharm64.exe","pycharm.exe","phpstorm64.exe","phpstorm.exe","goland64.exe","goland.exe","rustrover64.exe","rustrover.exe","rider64.exe","rider.exe","clion64.exe","clion.exe","datagrip64.exe","datagrip.exe","fleet.exe","windowsterminal.exe","sublime_text.exe","zed.exe","terminal.app"].includes(e)}function gc(){let t=process.ppid;try{if(process.platform==="win32"){let e=t,i=null;for(let n=0;n<10;n++){let{parentPid:r,processName:o}=Xp(e);if(Hp(o)&&(i=e),Lp(o)&&i)return i;if(!r||r<=4)break;e=r}return i||t}else return t}catch{}return t}function Qo(t){wv(t)||Pp(t,{recursive:!0})}function _p(t){let{agents:e,...i}=t;return{...i,agents:e||[]}}function jc(t,e,i){if(!t||!e)return!1;let n=we(t);Qo(n);let r=Zt(t,e),o=`${r}.tmp`;try{let a=_p(i);return zc(o,JSON.stringify(a,null,2),"utf8"),yp(o,r),!0}catch{try{Dp(o)}catch{}return!1}}function Tv(t){try{let e=Jt(),i=["# Auto-generated by gemkit-cli",`# Updated at: ${new Date().toISOString()}`,"","# GEMKIT IDs",`ACTIVE_GK_SESSION_ID=${t.gkSessionId||""}`,`GK_PROJECT_HASH=${t.gkProjectHash||""}`,`PROJECT_DIR=${t.projectDir||""}`,"","# GEMINI IDs (mapped)",`ACTIVE_GEMINI_SESSION_ID=${t.geminiSessionId||""}`,`GEMINI_PROJECT_HASH=${t.geminiProjectHash||""}`,"","# PLAN INFO",`ACTIVE_PLAN=${t.activePlan||""}`,`SUGGESTED_PLAN=${t.suggestedPlan||""}`,`PLAN_DATE_FORMAT=${t.planDateFormat||""}`,""].join(`
29
- `),n=Tp(process.cwd(),".gemini");return Qo(n),zc(e,i,"utf8"),!0}catch{return!1}}function $p(t,e){if(!t||!e)return null;let i=an(t,e);if(!wv(i))return null;try{let n=qp(i,"utf-8");return JSON.parse(n)}catch{return null}}function Xv(t,e,i){if(!t||!e)return!1;let n=we(t);Qo(n);let r=an(t,e);try{return zc(r,JSON.stringify(i,null,2),"utf8"),!0}catch{return!1}}function Hv(t,e,i){let n=$p(t,e);return n||(n={gkProjectHash:e,projectDir:t,projectPath:i||process.cwd(),geminiProjectHash:null,initialized:!0,initTimestamp:new Date().toISOString(),lastActiveTimestamp:new Date().toISOString(),activeGkSessionId:null,sessions:[]},Xv(t,e,n)),n}function eI(t,e,i){let n=Hv(t,e);n.activeGkSessionId=i.gkSessionId,n.lastActiveTimestamp=new Date().toISOString();let r=n.sessions.findIndex(o=>o.gkSessionId===i.gkSessionId);if(r>=0){let o=n.sessions[r];n.sessions[r]={gkSessionId:i.gkSessionId,pid:i.pid??o.pid,sessionType:i.sessionType||o.sessionType,appName:i.appName||o.appName,prompt:i.prompt??o.prompt??null,activePlan:i.activePlan??o.activePlan??null,startTime:i.startTime||o.startTime,endTime:i.endTime??o.endTime??null}}else n.sessions.push({gkSessionId:i.gkSessionId,pid:i.pid??null,sessionType:i.sessionType||"gemini",appName:i.appName||"gemini-main",prompt:i.prompt??null,activePlan:i.activePlan??null,startTime:i.startTime||new Date().toISOString(),endTime:i.endTime??null});return n.sessions.sort((o,a)=>{let c=new Date(o.startTime||0).getTime();return new Date(a.startTime||0).getTime()-c}),Xv(t,e,n)}function bo(t,e,i){let n=Ce(t,e);if(!n)return!1;let r=i.gkSessionId||e;n.agents=n.agents||[];let o=n.agents.findIndex(a=>a.gkSessionId===r);if(o>=0){let a=n.agents[o];n.agents[o]={...a,model:a.model||i.model||null,prompt:a.prompt||i.prompt||null}}else{let a={gkSessionId:r,pid:i.pid||null,geminiSessionId:i.geminiSessionId||null,geminiProjectHash:i.geminiProjectHash||null,parentGkSessionId:i.parentGkSessionId||null,agentType:i.parentGkSessionId?"Sub Agent":"Main Agent",agentRole:i.agentRole||"main",prompt:i.prompt||null,model:i.model||null,tokenUsage:i.tokenUsage||null,retryCount:i.retryCount||0,resumeCount:i.resumeCount||0,generation:i.generation||0,injected:i.injected||null,startTime:new Date().toISOString(),endTime:null,status:"active",exitCode:null,error:null};n.agents.push(a)}return jc(t,e,n)}function Lv(t,e={}){let i=e.cwd||process.cwd(),n=sn(i),r=Zv(i),o=gc(),a=Fo(t,o),c={gkSessionId:a,gkProjectHash:r,projectDir:n,geminiSessionId:null,geminiParentId:null,geminiProjectHash:null,initialized:!0,initTimestamp:new Date().toISOString(),sessionType:"non-gemini",appName:t,pid:o,activePlan:e.activePlan||null,suggestedPlan:e.suggestedPlan||null,agents:[]};Qo(we(n)),jc(n,a,c),Hv(n,r,i),eI(n,r,{gkSessionId:a,pid:o,sessionType:"non-gemini",appName:t,startTime:c.initTimestamp,activePlan:c.activePlan});let l=k(),A=l.PROJECT_DIR===n&&l.GEMINI_PROJECT_HASH||"";return Tv({gkSessionId:a,gkProjectHash:r,projectDir:n,geminiSessionId:"",geminiProjectHash:A,activePlan:c.activePlan||"",suggestedPlan:c.suggestedPlan||"",planDateFormat:""}),{session:c,gkSessionId:a,pid:o,projectDir:n,gkProjectHash:r}}function _v(t,e,i){let n=Ce(t,e);if(!n||(n.activePlan=i,n.suggestedPlan=null,!jc(t,e,n)))return!1;let r=k();return Tv({gkSessionId:e,gkProjectHash:n.gkProjectHash||r.GK_PROJECT_HASH,projectDir:t,geminiSessionId:n.geminiSessionId||r.ACTIVE_GEMINI_SESSION_ID,geminiProjectHash:n.geminiProjectHash||r.GEMINI_PROJECT_HASH,activePlan:i,suggestedPlan:"",planDateFormat:n.planDateFormat||r.PLAN_DATE_FORMAT})}function $v(t){if(!t)return null;let e=t.match(/^(.+)-(\d+)-([a-z0-9]+)-([a-z0-9]{4})$/);return e?{appName:e[1],pid:parseInt(e[2],10),timestamp:e[3],random:e[4]}:null}import{spawn as tI,exec as iI}from"child_process";import{existsSync as Jo,readFileSync as xc,writeFileSync as Gc,unlinkSync as eA}from"fs";import{join as Zo}from"path";import{tmpdir as nI,platform as tA}from"os";var qe=Zo(nI(),"elevator-music.lock"),Bo=3e4,Po=class{audioFile;loop;volume;process=null;isPlaying=!1;loopInterval=null;hasLock=!1;lockRefreshInterval=null;triedFallback=!1;constructor(e={}){this.audioFile=e.audioFile||this.getDefaultAudioFile(),this.loop=e.loop!==!1,this.volume=e.volume||.5}tryAcquireLock(){let e={pid:process.pid,timestamp:Date.now()};try{return Gc(qe,JSON.stringify(e),{flag:"wx"}),this.hasLock=!0,this.lockRefreshInterval=setInterval(()=>{this.refreshLock()},Bo/3),!0}catch(i){return i.code==="EEXIST"?this.tryTakeStaleLock(e):!1}}tryTakeStaleLock(e){try{let i=JSON.parse(xc(qe,"utf8"));if(Date.now()-i.timestamp<Bo&&i.pid!==process.pid)try{return process.kill(i.pid,0),!1}catch{}eA(qe);try{return Gc(qe,JSON.stringify(e),{flag:"wx"}),this.hasLock=!0,this.lockRefreshInterval=setInterval(()=>{this.refreshLock()},Bo/3),!0}catch{return!1}}catch{return!1}}refreshLock(){if(this.hasLock)try{let e={pid:process.pid,timestamp:Date.now()};Gc(qe,JSON.stringify(e),{flag:"w"})}catch{}}releaseLock(){if(this.lockRefreshInterval&&(clearInterval(this.lockRefreshInterval),this.lockRefreshInterval=null),!!this.hasLock){try{Jo(qe)&&JSON.parse(xc(qe,"utf8")).pid===process.pid&&eA(qe)}catch{}this.hasLock=!1}}getDefaultAudioFile(){let e=[Zo(process.cwd(),".gemini","extensions","spawn-agent","assets","golden-coast-melody.wav"),Zo(process.cwd(),".gemini","assets","elevator_music.wav"),Zo(process.cwd(),"assets","elevator_music.wav")];for(let i of e)if(Jo(i))return i;return null}getPlayCommand(){if(!this.audioFile)return null;switch(tA()){case"win32":return{command:"powershell",args:["-NoProfile","-Command",`$player = New-Object System.Media.SoundPlayer '${this.audioFile}'; $player.PlaySync()`],shell:!1};case"darwin":return{command:"afplay",args:["-v",String(this.volume),this.audioFile],shell:!1};case"linux":return{command:"paplay",args:["--volume",String(Math.round(this.volume*65536)),this.audioFile],shell:!1,fallback:{command:"aplay",args:["-q",this.audioFile],shell:!1}};default:return null}}start(e={}){if(!this.audioFile||!Jo(this.audioFile))return!1;if(this.isPlaying)return!0;if(!e.force&&!this.tryAcquireLock())return!1;let i=this.getPlayCommand();return i?(this.isPlaying=!0,this.playLoop(i),!0):(this.releaseLock(),!1)}playLoop(e){if(!this.isPlaying)return;let i=n=>{this.process=tI(n.command,n.args,{stdio:["ignore","ignore","pipe"],windowsHide:!0,shell:n.shell}),this.process.stderr?.on("data",()=>{n.fallback&&!this.triedFallback&&(this.triedFallback=!0,this.process?.kill(),i(n.fallback))}),this.process.on("close",()=>{this.isPlaying&&this.loop&&(this.loopInterval=setTimeout(()=>{this.playLoop(e)},100))}),this.process.on("error",()=>{n.fallback&&!this.triedFallback&&(this.triedFallback=!0,i(n.fallback))})};i(e)}stop(){this.isPlaying=!1,this.loopInterval&&(clearTimeout(this.loopInterval),this.loopInterval=null),this.process&&(tA()==="win32"?iI(`taskkill /pid ${this.process.pid} /T /F`,{windowsHide:!0}):this.process.kill("SIGTERM"),this.process=null),this.releaseLock()}get playing(){return this.isPlaying}static isAnyPlaying(){try{if(!Jo(qe))return!1;let e=JSON.parse(xc(qe,"utf8"));if(Date.now()-e.timestamp>=Bo)return!1;try{return process.kill(e.pid,0),!0}catch{return!1}}catch{return!1}}};var nA=[{icon:"\u{1F4A9}",action:"Pooping out some code"},{icon:"\u{1F373}",action:"Cooking up solutions"},{icon:"\u{1F9E0}",action:"Brain cells working overtime"},{icon:"\u26A1",action:"Neurons firing rapidly"},{icon:"\u{1F52E}",action:"Consulting the crystal ball"},{icon:"\u{1F3B0}",action:"Rolling the dice on this one"},{icon:"\u{1F680}",action:"Launching into hyperthink"},{icon:"\u{1F32A}\uFE0F",action:"Brainstorming intensifies"},{icon:"\u{1F3AA}",action:"Juggling multiple thoughts"},{icon:"\u{1F527}",action:"Tightening the logic bolts"},{icon:"\u{1F3A8}",action:"Painting the solution"},{icon:"\u{1F3D7}\uFE0F",action:"Building something awesome"},{icon:"\u{1F52C}",action:"Analyzing under the microscope"},{icon:"\u{1F9EA}",action:"Mixing the secret sauce"},{icon:"\u{1F3AF}",action:"Aiming for perfection"},{icon:"\u{1F9D9}",action:"Casting coding spells"},{icon:"\u{1F419}",action:"Multitasking like an octopus"},{icon:"\u{1F9BE}",action:"Flexing the AI muscles"},{icon:"\u{1F308}",action:"Finding the pot of gold"},{icon:"\u{1F3B8}",action:"Rocking out some logic"}],rA=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"];function AI(t){let e=0,i=0,n=0,r=process.stdout.isTTY,o=setInterval(()=>{n++,i++;let a=n%10===0;a&&e++;let c=nA[e%nA.length],v=`${rA[i%rA.length]} ${c.icon} ${c.action}... ${n}s`;r?process.stdout.write(`\r\x1B[K${v}`):(n===1||a)&&console.log(v)},1e3);return{interval:o,stop:()=>{clearInterval(o),r&&process.stdout.write("\r\x1B[K")}}}function uI(t){let{agentType:e="Sub Agent",agentRole:i="unknown",parentSessionId:n=null,activePlan:r=null,projectDir:o=null}=t,a=[`Agent Type: ${e}`,`Agent Role: ${i}`];return n&&a.push(`Parent Session: ${n.slice(0,8)}...`),o&&a.push(`Project: ${o}`),r&&a.push(`Active Plan: ${r}`),a.join(`
30
- `)}function oA(){console.log(),console.log(I.default.bold(s.geminiPurple("Agent Management"))),console.log(),console.log("Usage:"),console.log(` ${s.primary("gk agent")} <subcommand> [options]`),console.log(),console.log("Subcommands:"),console.log(` ${s.primary("list")} List all agent profiles`),console.log(` ${s.primary("info")} <name> Show agent profile details`),console.log(` ${s.primary("search")} "<task>" Find best agent+skills for a task`),console.log(` ${s.primary("spawn")} Spawn a sub-agent`),console.log(),console.log("Examples:"),console.log(` ${s.dim("gk agent list")}`),console.log(` ${s.dim("gk agent info researcher")}`),console.log(` ${s.dim('gk agent search "implement authentication"')}`),console.log(` ${s.dim('gk agent spawn -a researcher -p "research best practices"')}`),console.log(),console.log("Run with subcommand for specific help:"),console.log(` ${s.dim("gk agent list --help")}`),console.log(` ${s.dim("gk agent spawn --help")}`),console.log()}function mI(){console.log(),console.log(I.default.bold(s.geminiPurple("gk agent list"))),console.log(s.dim("List all available agent profiles")),console.log(),console.log("Usage:"),console.log(` ${s.primary("gk agent list")} [options]`),console.log(),console.log("Options:"),console.log(` ${s.dim("--json")} Output as JSON`),console.log()}function EI(){console.log(),console.log(I.default.bold(s.geminiPurple("gk agent info"))),console.log(s.dim("Show detailed information about an agent profile")),console.log(),console.log("Usage:"),console.log(` ${s.primary("gk agent info")} <name> [options]`),console.log(),console.log("Arguments:"),console.log(` ${s.dim("<name>")} Agent profile name (without .md extension)`),console.log(),console.log("Options:"),console.log(` ${s.dim("--json")} Output as JSON`),console.log(),console.log("Example:"),console.log(` ${s.dim("gk agent info researcher")}`),console.log()}function pI(){console.log(),console.log(I.default.bold(s.geminiPurple("gk agent search"))),console.log(s.dim("Find best agent+skills combination for a task using BM25 search")),console.log(),console.log("Usage:"),console.log(` ${s.primary("gk agent search")} "<task>" [options]`),console.log(),console.log("Arguments:"),console.log(` ${s.dim("<task>")} Task description to search for`),console.log(),console.log("Options:"),console.log(` ${s.dim("-n, --limit <n>")} Number of results (default: 5)`),console.log(` ${s.dim("-i, --intent <i>")} Force intent: research|plan|execute|debug|review|test|design|docs`),console.log(` ${s.dim("-d, --domain <d>")} Force domain: frontend|backend|auth|payment|database|mobile|ai|etc.`),console.log(` ${s.dim("--max-skills <n>")} Maximum skills to include`),console.log(` ${s.dim("--json")} Output as JSON`),console.log(),console.log("Examples:"),console.log(` ${s.dim('gk agent search "implement user authentication"')}`),console.log(` ${s.dim('gk agent search "debug the login form" -i debug')}`),console.log(` ${s.dim('gk agent search "build a payment page" -d payment')}`),console.log()}function sA(){console.log(),console.log(I.default.bold(s.geminiPurple("gk agent spawn"))),console.log(s.dim("Spawn a sub-agent with Gemini or Claude CLI")),console.log(),console.log("Usage:"),console.log(` ${s.primary("gk agent spawn")} -p "<prompt>" [options]`),console.log(),console.log("Required:"),console.log(` ${s.dim("-p, --prompt <text>")} Task prompt for the agent`),console.log(),console.log("Options:"),console.log(` ${s.dim("-a, --agent <name>")} Agent profile name`),console.log(` ${s.dim("-s, --skills <list>")} Comma-separated skill names to inject`),console.log(` ${s.dim("-c, --context <files>")} Context files (@file syntax)`),console.log(` ${s.dim("-m, --model <model>")} Model override (default: from config)`),console.log(` ${s.dim("-t, --tools <list>")} Comma-separated tools to auto-approve`),console.log(` ${s.dim("--cli <provider>")} CLI provider: gemini (default) or claude`),console.log(` ${s.dim("--music")} Play elevator music while waiting`),console.log(` ${s.dim("--no-music")} Disable elevator music`),console.log(` ${s.dim("--music-file <path>")} Custom music file path`),console.log(),console.log("CLI Providers:"),console.log(` ${s.dim("gemini")} Uses Gemini CLI (default). Loads from .gemini/agents/, falls back to .claude/agents/`),console.log(` ${s.dim("claude")} Uses Claude CLI. Loads from .claude/agents/, falls back to .gemini/agents/`),console.log(` ${s.dim("Models and tools are automatically mapped between providers when using fallback.")}`),console.log(),console.log("Examples:"),console.log(` ${s.dim('gk agent spawn -p "fix the login bug"')}`),console.log(` ${s.dim('gk agent spawn -a researcher -p "research React best practices"')}`),console.log(` ${s.dim('gk agent spawn -a code-executor -s "frontend-design" -p "build a dashboard"')}`),console.log(` ${s.dim('gk agent spawn -p "implement auth" -m gemini-2.5-pro --music')}`),console.log(` ${s.dim('gk agent spawn -a researcher -t "list_directory,read_file,glob" -p "analyze code"')}`),console.log(` ${s.dim('gk agent spawn --cli claude -a researcher -p "analyze codebase"')}`),console.log(),console.log("Allowed Tools:"),console.log(` ${s.dim("Tools can be defined in agent frontmatter (tools: tool1, tool2)")}`),console.log(` ${s.dim("or passed via CLI. Both sources are merged and deduplicated.")}`),console.log(` ${s.dim("Gemini tools: list_directory, read_file, write_file, glob, run_shell_command(*)")}`),console.log(` ${s.dim("Claude tools: Read, Write, Edit, Bash, Glob, Grep, WebFetch, WebSearch")}`),console.log()}function aA(t){t.command("agent [subcommand] [arg]","Agent management (list, info, search, spawn)").alias("a").option("--json","[all] Output as JSON").option("-n, --limit <n>","[search] Number of results (default: 5)",{default:5}).option("-i, --intent <intent>","[search] Force intent: research|plan|execute|debug|review|test|design|docs").option("-d, --domain <domain>","[search] Force domain: frontend|backend|auth|payment|database|mobile|ai").option("--max-skills <n>","[search] Maximum skills to include").option("-a, --agent <name>","[spawn] Agent profile name").option("-p, --prompt <text>","[spawn] Task prompt (required for spawn)").option("-s, --skills <list>","[spawn] Comma-separated skill names").option("-c, --context <files>","[spawn] Context files (@file syntax)").option("-m, --model <model>","[spawn] Model override").option("-t, --tools <list>","[spawn] Comma-separated tools to auto-approve").option("--cli <provider>","[spawn] CLI provider: gemini (default) or claude").option("--music","[spawn] Play elevator music while waiting").option("--no-music","[spawn] Disable elevator music").option("--music-file <path>","[spawn] Custom music file path").action(async(e,i,n)=>{if(n.help||n.h)switch(e){case"list":mI();return;case"info":EI();return;case"search":pI();return;case"spawn":sA();return;default:oA();return}switch(e){case"list":await II(n);break;case"info":i||(console.log(),m.error("Agent profile name required"),console.log(s.dim("Usage: gk agent info <name>")),console.log(),process.exit(1)),await fI(i,n);break;case"search":i||(console.log(),m.error("Search query required"),console.log(s.dim('Usage: gk agent search "<task>"')),console.log(),process.exit(1)),await hI(i,n);break;case"spawn":await dI(n);break;default:oA()}})}async function II(t){let e=Vo();if(t.json){console.log(JSON.stringify(e,null,2));return}if(console.log(),console.log(I.default.bold(s.geminiPurple("Available Agents"))),console.log(),e.length===0){m.warn('No agent profiles found. Run "gk init" first.'),console.log();return}for(let i of e)console.log(` ${s.primary(i.name)}`),console.log(` ${s.dim(i.description)}`),console.log(` ${s.dim("Model:")} ${i.model}`),i.skills&&i.skills.length>0&&console.log(` ${s.dim("Skills:")} ${i.skills.join(", ")}`),console.log("");console.log(s.dim(` Total: ${e.length} agents`)),console.log()}async function fI(t,e){let i=Kv(t);if(i||(console.log(),m.error(`Agent profile not found: ${t}`),console.log(),process.exit(1)),e.json){console.log(JSON.stringify(i,null,2));return}console.log(),console.log(M.doubleLine()),console.log(I.default.bold(s.geminiPurple(`Agent: ${i.name}`))),console.log(M.doubleLine()),console.log(),console.log(` ${s.dim("Description:")} ${i.description}`),console.log(` ${s.dim("Model:")} ${i.model}`),i.skills?.length&&console.log(` ${s.dim("Skills:")} ${i.skills.join(", ")}`),console.log(` ${s.dim("Path:")} ${i.filePath}`),console.log(),console.log(s.dim("--- Profile Content ---")),console.log(),console.log(s.dim(i.content)),console.log()}async function hI(t,e){let i=bv(t,{top:e.limit,forceIntent:e.intent,forceDomain:e.domain,maxSkills:e.maxSkills});if(e.json){console.log(JSON.stringify(i,null,2));return}if(console.log(),console.log(I.default.bold(s.geminiPurple(`Search results for: "${t}"`))),console.log(),i.length===0){m.warn("No matching agents found for task."),console.log();return}for(let n=0;n<i.length;n++){let r=i[n],o=r.fallback?s.warn(" [FALLBACK]"):"";console.log(` ${s.success(n+1+".")} ${s.primary(r.agent)}${o} ${s.dim(`(score: ${r.score})`)}`),console.log(` ${s.dim("Intent:")} ${r.intent} ${s.dim("Domain:")} ${r.domain} ${s.dim("Complexity:")} ${r.complexity}`),r.skills.length>0&&console.log(` ${s.dim("Skills:")} ${r.skills.join(" | ")}`),r.description&&console.log(` ${s.dim(r.description)}`),r.useWhen&&console.log(` ${s.dim("Use when:")} ${r.useWhen}`),console.log("")}if(i.length>0){let n=i[0],r=n.skills.length>0?` -s "${n.skills.join(",")}"`:"";console.log(s.dim(" Suggested command:")),console.log(` ${s.primary("gk")} agent spawn -a ${n.agent}${r} -p "${t}"`)}console.log()}async function dI(t){t.prompt||(console.log(),m.error("Prompt is required. Use -p or --prompt"),console.log(),sA(),process.exit(1));let e=t.cli==="claude"?"claude":"gemini",i=Ve(),n=k(),r=n.ACTIVE_GK_SESSION_ID||null,o=n.ACTIVE_GEMINI_SESSION_ID||null,a=n.ACTIVE_PLAN||null,c=n.SUGGESTED_PLAN||null,l=n.PLAN_DATE_FORMAT||null,v=n.PROJECT_DIR||null,A=null;t.agent&&(A=Vv(t.agent,e),A||(console.log(),m.error(`Agent profile not found: ${t.agent}`),console.log(s.dim(`Searched: .${e==="claude"?"claude":"gemini"}/agents/ and fallback folder`)),console.log(),process.exit(1)));let u=t.model||A?.model||i.spawn.defaultModel;u=Oo(u,e);let E=process.argv.includes("--music")||process.argv.includes("--no-music")?t.music:i.spawn.music,f=t.musicFile||i.spawn.musicFile,d=t.skills?.split(",").map(h=>h.trim()).filter(Boolean)||[],z=A?.skills||[],C=[...new Set([...z,...d])],ve=t.tools?.split(",").map(h=>h.trim()).filter(Boolean)||[],ss=A?.tools||[],as=[...new Set([...ss,...ve])],ui=Uo(as,e),cs=t.context?t.context.split(",").flatMap(h=>h.trim().split(/\s+/).filter(G=>G)).filter(h=>h):[];async function PA(h){let G=h,De=!1;if(h.startsWith("@")){let Ae=h.substring(1),ut=[qi(process.cwd(),".docs",Ae),qi(process.cwd(),".plans",Ae),qi(process.cwd(),"docs",Ae),qi(process.cwd(),"plans",Ae),qi(process.cwd(),Ae)];for(let mt of ut)try{await oI(mt),G=mt,De=!0;break}catch{continue}if(!De){let mt=ut.map(mi=>` - ${mi}`).join(`
31
- `);throw new Error(`Context file not found: ${h}
55
+ `)):(v.error(`Failed to create project: ${r.error}`),console.log())})}Xs();Ls();Nn();import{spawn as Zp}from"child_process";import{access as yp,stat as qp,readdir as wp,readFile as Sa}from"fs/promises";import{join as Je,basename as Dp,extname as Tp,relative as Cu}from"path";import{existsSync as yv,readFileSync as Gg,writeFileSync as Mg,unlinkSync as Yg}from"fs";import{join as Wg}from"path";var Cg=".gk-interactive-session.json";function ru(t,e){let i=e?`.gk-interactive-session-${e}.json`:Cg;return Wg(t||process.cwd(),i)}function Ge(t,e){let i=ru(t,e);if(!yv(i))return null;try{let n=Gg(i,"utf-8");return JSON.parse(n)}catch{return null}}function $i(t,e,i){let n=ru(e,i);Mg(n,JSON.stringify(t,null,2))}function et(t,e){let i=ru(t,e);yv(i)&&Yg(i)}function bt(t,e){let i=Ge(t,e);if(!i)return!1;try{return process.kill(i.pid,0),!0}catch{return et(t,e),!1}}function qv(t,e){let i=Ge(t,e);i&&(i.isFirstSend=!1,$i(i,t,e))}cu();Do();xu();it();k();en();it();import{existsSync as Op,mkdirSync as xI,writeFileSync as Su,readFileSync as SI,renameSync as GI,unlinkSync as MI}from"fs";import{execSync as YI}from"child_process";import{join as WI}from"path";k();it();import{existsSync as Mp,readFileSync as Yp,readdirSync as RI}from"fs";import{join as zI}from"path";function nt(t,e){if(!t||!e)return null;let i=Oi(t,e);if(!Mp(i))return null;try{let n=Yp(i,"utf-8");return JSON.parse(n)}catch{return null}}function Wp(t,e={}){let{limit:i=10,status:n="all"}=e,s=xt(t);if(!Mp(s))return[];let r=[];try{let o=RI(s).filter(c=>c.startsWith("gk-session-")&&c.endsWith(".json"));for(let c of o){let l=zI(s,c),u=Yp(l,"utf-8"),m=JSON.parse(u);n!=="all"&&(m.agents?.find(A=>A.agentType==="Main Agent")?.status||"active")!==n||r.push(m)}}catch{}return r.sort((o,c)=>new Date(c.initTimestamp).getTime()-new Date(o.initTimestamp).getTime()),r.slice(0,i)}function jI(t,e,i={}){let n=nt(t,e);if(!n||!n.agents)return[];let s=n.agents;return i.agentType&&(s=s.filter(r=>r.agentType===i.agentType)),i.status&&(s=s.filter(r=>r.status===i.status)),s}function Cp(t,e){let i=jI(t,e),n={total:i.length,active:0,completed:0,failed:0,mainAgents:0,subAgents:0,totalDurationMs:0};return i.forEach(s=>{s.status==="active"?n.active++:s.status==="completed"?n.completed++:s.status==="failed"&&n.failed++,s.agentType==="Main Agent"?n.mainAgents++:n.subAgents++,s.startTime&&s.endTime&&(n.totalDurationMs+=new Date(s.endTime).getTime()-new Date(s.startTime).getTime())}),n}function CI(t){try{let e=`powershell -Command "$p = Get-CimInstance Win32_Process -Filter 'ProcessId=${t}'; Write-Output $p.ParentProcessId; Write-Output $p.Name"`,n=YI(e,{encoding:"utf8",stdio:["pipe","pipe","pipe"]}).trim().split(/\r?\n/),s=parseInt(n[0],10),r=n[1]||null;return{parentPid:!isNaN(s)&&s>0?s:null,processName:r}}catch{return{parentPid:null,processName:null}}}function OI(t){return t?["powershell.exe","pwsh.exe","cmd.exe","bash.exe","zsh.exe","sh.exe","fish.exe"].includes(t.toLowerCase()):!1}function UI(t){if(!t)return!1;let e=t.toLowerCase();return["code.exe","code - insiders.exe","cursor.exe","windsurf.exe","positron.exe","idea64.exe","idea.exe","webstorm64.exe","webstorm.exe","pycharm64.exe","pycharm.exe","phpstorm64.exe","phpstorm.exe","goland64.exe","goland.exe","rustrover64.exe","rustrover.exe","rider64.exe","rider.exe","clion64.exe","clion.exe","datagrip64.exe","datagrip.exe","fleet.exe","windowsterminal.exe","sublime_text.exe","zed.exe","terminal.app"].includes(e)}function Gu(){let t=process.ppid;try{if(process.platform==="win32"){let e=t,i=null;for(let n=0;n<10;n++){let{parentPid:s,processName:r}=CI(e);if(OI(r)&&(i=e),UI(r)&&i)return i;if(!s||s<=4)break;e=s}return i||t}else return t}catch{}return t}function Ia(t){Op(t)||xI(t,{recursive:!0})}function KI(t){let{agents:e,...i}=t;return{...i,agents:e||[]}}function Mu(t,e,i){if(!t||!e)return!1;let n=xt(t);Ia(n);let s=Oi(t,e),r=`${s}.tmp`;try{let o=KI(i);return Su(r,JSON.stringify(o,null,2),"utf8"),GI(r,s),!0}catch{try{MI(r)}catch{}return!1}}function Up(t){try{let e=Wi(),i=["# Auto-generated by gemkit-cli",`# Updated at: ${new Date().toISOString()}`,"","# GEMKIT IDs",`ACTIVE_GK_SESSION_ID=${t.gkSessionId||""}`,`GK_PROJECT_HASH=${t.gkProjectHash||""}`,`PROJECT_DIR=${t.projectDir||""}`,"","# GEMINI IDs (mapped)",`ACTIVE_GEMINI_SESSION_ID=${t.geminiSessionId||""}`,`GEMINI_PROJECT_HASH=${t.geminiProjectHash||""}`,"","# PLAN INFO",`ACTIVE_PLAN=${t.activePlan||""}`,`SUGGESTED_PLAN=${t.suggestedPlan||""}`,`PLAN_DATE_FORMAT=${t.planDateFormat||""}`,""].join(`
56
+ `),n=WI(process.cwd(),".gemini");return Ia(n),Su(e,i,"utf8"),!0}catch{return!1}}function kI(t,e){if(!t||!e)return null;let i=cs(t,e);if(!Op(i))return null;try{let n=SI(i,"utf-8");return JSON.parse(n)}catch{return null}}function Kp(t,e,i){if(!t||!e)return!1;let n=xt(t);Ia(n);let s=cs(t,e);try{return Su(s,JSON.stringify(i,null,2),"utf8"),!0}catch{return!1}}function kp(t,e,i){let n=kI(t,e);return n||(n={gkProjectHash:e,projectDir:t,projectPath:i||process.cwd(),geminiProjectHash:null,initialized:!0,initTimestamp:new Date().toISOString(),lastActiveTimestamp:new Date().toISOString(),activeGkSessionId:null,sessions:[]},Kp(t,e,n)),n}function VI(t,e,i){let n=kp(t,e);n.activeGkSessionId=i.gkSessionId,n.lastActiveTimestamp=new Date().toISOString();let s=n.sessions.findIndex(r=>r.gkSessionId===i.gkSessionId);if(s>=0){let r=n.sessions[s];n.sessions[s]={gkSessionId:i.gkSessionId,pid:i.pid??r.pid,sessionType:i.sessionType||r.sessionType,appName:i.appName||r.appName,prompt:i.prompt??r.prompt??null,activePlan:i.activePlan??r.activePlan??null,startTime:i.startTime||r.startTime,endTime:i.endTime??r.endTime??null}}else n.sessions.push({gkSessionId:i.gkSessionId,pid:i.pid??null,sessionType:i.sessionType||"gemini",appName:i.appName||"gemini-main",prompt:i.prompt??null,activePlan:i.activePlan??null,startTime:i.startTime||new Date().toISOString(),endTime:i.endTime??null});return n.sessions.sort((r,o)=>{let c=new Date(r.startTime||0).getTime();return new Date(o.startTime||0).getTime()-c}),Kp(t,e,n)}function Ea(t,e,i){let n=nt(t,e);if(!n)return!1;let s=i.gkSessionId||e;n.agents=n.agents||[];let r=n.agents.findIndex(o=>o.gkSessionId===s);if(r>=0){let o=n.agents[r];n.agents[r]={...o,model:o.model||i.model||null,prompt:o.prompt||i.prompt||null}}else{let o={gkSessionId:s,pid:i.pid||null,geminiSessionId:i.geminiSessionId||null,geminiProjectHash:i.geminiProjectHash||null,parentGkSessionId:i.parentGkSessionId||null,agentType:i.parentGkSessionId?"Sub Agent":"Main Agent",agentRole:i.agentRole||"main",prompt:i.prompt||null,model:i.model||null,tokenUsage:i.tokenUsage||null,retryCount:i.retryCount||0,resumeCount:i.resumeCount||0,generation:i.generation||0,injected:i.injected||null,startTime:new Date().toISOString(),endTime:null,status:"active",exitCode:null,error:null};n.agents.push(o)}return Mu(t,e,n)}function Vp(t,e={}){let i=e.cwd||process.cwd(),n=ge(i),s=tp(i),r=Gu(),o=Et(t,r),c={gkSessionId:o,gkProjectHash:s,projectDir:n,geminiSessionId:null,geminiParentId:null,geminiProjectHash:null,initialized:!0,initTimestamp:new Date().toISOString(),sessionType:"non-gemini",appName:t,pid:r,activePlan:e.activePlan||null,suggestedPlan:e.suggestedPlan||null,agents:[]};Ia(xt(n)),Mu(n,o,c),kp(n,s,i),VI(n,s,{gkSessionId:o,pid:r,sessionType:"non-gemini",appName:t,startTime:c.initTimestamp,activePlan:c.activePlan});let l=B(),m=l.PROJECT_DIR===n&&l.GEMINI_PROJECT_HASH||"";return Up({gkSessionId:o,gkProjectHash:s,projectDir:n,geminiSessionId:"",geminiProjectHash:m,activePlan:c.activePlan||"",suggestedPlan:c.suggestedPlan||"",planDateFormat:""}),{session:c,gkSessionId:o,pid:r,projectDir:n,gkProjectHash:s}}function Np(t,e,i){let n=nt(t,e);if(!n||(n.activePlan=i,n.suggestedPlan=null,!Mu(t,e,n)))return!1;let s=B();return Up({gkSessionId:e,gkProjectHash:n.gkProjectHash||s.GK_PROJECT_HASH,projectDir:t,geminiSessionId:n.geminiSessionId||s.ACTIVE_GEMINI_SESSION_ID,geminiProjectHash:n.geminiProjectHash||s.GEMINI_PROJECT_HASH,activePlan:i,suggestedPlan:"",planDateFormat:n.planDateFormat||s.PLAN_DATE_FORMAT})}function Fp(t){if(!t)return null;let e=t.match(/^(.+)-(\d+)-([a-z0-9]+)-([a-z0-9]{4})$/);return e?{appName:e[1],pid:parseInt(e[2],10),timestamp:e[3],random:e[4]}:null}en();import{spawn as NI,exec as FI}from"child_process";import{existsSync as Ra,readFileSync as Yu,writeFileSync as Wu,unlinkSync as bp}from"fs";import{join as ja}from"path";import{tmpdir as bI,platform as Pp}from"os";var Rt=ja(bI(),"elevator-music.lock"),za=3e4,xa=class{audioFile;loop;volume;process=null;isPlaying=!1;loopInterval=null;hasLock=!1;lockRefreshInterval=null;triedFallback=!1;constructor(e={}){this.audioFile=e.audioFile||this.getDefaultAudioFile(),this.loop=e.loop!==!1,this.volume=e.volume||.5}tryAcquireLock(){let e={pid:process.pid,timestamp:Date.now()};try{return Wu(Rt,JSON.stringify(e),{flag:"wx"}),this.hasLock=!0,this.lockRefreshInterval=setInterval(()=>{this.refreshLock()},za/3),!0}catch(i){return i.code==="EEXIST"?this.tryTakeStaleLock(e):!1}}tryTakeStaleLock(e){try{let i=JSON.parse(Yu(Rt,"utf8"));if(Date.now()-i.timestamp<za&&i.pid!==process.pid)try{return process.kill(i.pid,0),!1}catch{}bp(Rt);try{return Wu(Rt,JSON.stringify(e),{flag:"wx"}),this.hasLock=!0,this.lockRefreshInterval=setInterval(()=>{this.refreshLock()},za/3),!0}catch{return!1}}catch{return!1}}refreshLock(){if(this.hasLock)try{let e={pid:process.pid,timestamp:Date.now()};Wu(Rt,JSON.stringify(e),{flag:"w"})}catch{}}releaseLock(){if(this.lockRefreshInterval&&(clearInterval(this.lockRefreshInterval),this.lockRefreshInterval=null),!!this.hasLock){try{Ra(Rt)&&JSON.parse(Yu(Rt,"utf8")).pid===process.pid&&bp(Rt)}catch{}this.hasLock=!1}}getDefaultAudioFile(){let e=[ja(process.cwd(),".gemini","extensions","spawn-agent","assets","golden-coast-melody.wav"),ja(process.cwd(),".gemini","assets","elevator_music.wav"),ja(process.cwd(),"assets","elevator_music.wav")];for(let i of e)if(Ra(i))return i;return null}getPlayCommand(){if(!this.audioFile)return null;switch(Pp()){case"win32":return{command:"powershell",args:["-NoProfile","-Command",`$player = New-Object System.Media.SoundPlayer '${this.audioFile}'; $player.PlaySync()`],shell:!1};case"darwin":return{command:"afplay",args:["-v",String(this.volume),this.audioFile],shell:!1};case"linux":return{command:"paplay",args:["--volume",String(Math.round(this.volume*65536)),this.audioFile],shell:!1,fallback:{command:"aplay",args:["-q",this.audioFile],shell:!1}};default:return null}}start(e={}){if(!this.audioFile||!Ra(this.audioFile))return!1;if(this.isPlaying)return!0;if(!e.force&&!this.tryAcquireLock())return!1;let i=this.getPlayCommand();return i?(this.isPlaying=!0,this.playLoop(i),!0):(this.releaseLock(),!1)}playLoop(e){if(!this.isPlaying)return;let i=n=>{this.process=NI(n.command,n.args,{stdio:["ignore","ignore","pipe"],windowsHide:!0,shell:n.shell}),this.process.stderr?.on("data",()=>{n.fallback&&!this.triedFallback&&(this.triedFallback=!0,this.process?.kill(),i(n.fallback))}),this.process.on("close",()=>{this.isPlaying&&this.loop&&(this.loopInterval=setTimeout(()=>{this.playLoop(e)},100))}),this.process.on("error",()=>{n.fallback&&!this.triedFallback&&(this.triedFallback=!0,i(n.fallback))})};i(e)}stop(){this.isPlaying=!1,this.loopInterval&&(clearTimeout(this.loopInterval),this.loopInterval=null),this.process&&(Pp()==="win32"?FI(`taskkill /pid ${this.process.pid} /T /F`,{windowsHide:!0}):this.process.kill("SIGTERM"),this.process=null),this.releaseLock()}get playing(){return this.isPlaying}static isAnyPlaying(){try{if(!Ra(Rt))return!1;let e=JSON.parse(Yu(Rt,"utf8"));if(Date.now()-e.timestamp>=za)return!1;try{return process.kill(e.pid,0),!0}catch{return!1}}catch{return!1}}};k();ga();var Qp=[{icon:"\u{1F4A9}",action:"Pooping out some code"},{icon:"\u{1F373}",action:"Cooking up solutions"},{icon:"\u{1F9E0}",action:"Brain cells working overtime"},{icon:"\u26A1",action:"Neurons firing rapidly"},{icon:"\u{1F52E}",action:"Consulting the crystal ball"},{icon:"\u{1F3B0}",action:"Rolling the dice on this one"},{icon:"\u{1F680}",action:"Launching into hyperthink"},{icon:"\u{1F32A}\uFE0F",action:"Brainstorming intensifies"},{icon:"\u{1F3AA}",action:"Juggling multiple thoughts"},{icon:"\u{1F527}",action:"Tightening the logic bolts"},{icon:"\u{1F3A8}",action:"Painting the solution"},{icon:"\u{1F3D7}\uFE0F",action:"Building something awesome"},{icon:"\u{1F52C}",action:"Analyzing under the microscope"},{icon:"\u{1F9EA}",action:"Mixing the secret sauce"},{icon:"\u{1F3AF}",action:"Aiming for perfection"},{icon:"\u{1F9D9}",action:"Casting coding spells"},{icon:"\u{1F419}",action:"Multitasking like an octopus"},{icon:"\u{1F9BE}",action:"Flexing the AI muscles"},{icon:"\u{1F308}",action:"Finding the pot of gold"},{icon:"\u{1F3B8}",action:"Rocking out some logic"}],Bp=["\u280B","\u2819","\u2839","\u2838","\u283C","\u2834","\u2826","\u2827","\u2807","\u280F"];function PI(t){let e=0,i=0,n=0,s=process.stdout.isTTY,r=setInterval(()=>{n++,i++;let o=n%10===0;o&&e++;let c=Qp[e%Qp.length],u=`${Bp[i%Bp.length]} ${c.icon} ${c.action}... ${n}s`;s?process.stdout.write(`\r\x1B[K${u}`):(n===1||o)&&console.log(u)},1e3);return{interval:r,stop:()=>{clearInterval(r),s&&process.stdout.write("\r\x1B[K")}}}function QI(t){let{agentType:e="Sub Agent",agentRole:i="unknown",parentSessionId:n=null,activePlan:s=null,projectDir:r=null}=t,o=[`Agent Type: ${e}`,`Agent Role: ${i}`];return n&&o.push(`Parent Session: ${n.slice(0,8)}...`),r&&o.push(`Project: ${r}`),s&&o.push(`Active Plan: ${s}`),o.join(`
57
+ `)}function Jp(){console.log(),console.log(h.default.bold(a.geminiPurple("Agent Management"))),console.log(),console.log("Usage:"),console.log(` ${a.primary("gk agent")} <subcommand> [options]`),console.log(),console.log("Subcommands:"),console.log(` ${a.primary("list")} List all agent profiles`),console.log(` ${a.primary("info")} <name> Show agent profile details`),console.log(` ${a.primary("search")} "<task>" Find best agent+skills for a task`),console.log(` ${a.primary("spawn")} Spawn a sub-agent (non-interactive)`),console.log(),console.log("Interactive Mode:"),console.log(` ${a.primary("start")} Start interactive session`),console.log(` ${a.primary("send")} "<prompt>" Send prompt to session`),console.log(` ${a.primary("wait")} [timeout] Wait for completion`),console.log(` ${a.primary("exchange")} Get structured output`),console.log(` ${a.primary("pending")} Check tool confirmations`),console.log(` ${a.primary("read")} [lines] Read raw output`),console.log(` ${a.primary("status")} Session status`),console.log(` ${a.primary("stop")} Stop session`),console.log(),console.log("Examples:"),console.log(` ${a.dim("gk agent list")}`),console.log(` ${a.dim('gk agent spawn -a researcher -p "research best practices"')}`),console.log(` ${a.dim("gk agent start -a researcher -s research")}`),console.log(` ${a.dim('gk agent send "analyze the codebase"')}`),console.log(),console.log("Run with subcommand for specific help:"),console.log(` ${a.dim("gk agent spawn --help")}`),console.log(` ${a.dim("gk agent start --help")}`),console.log()}function BI(){console.log(),console.log(h.default.bold(a.geminiPurple("gk agent list"))),console.log(a.dim("List all available agent profiles")),console.log(),console.log("Usage:"),console.log(` ${a.primary("gk agent list")} [options]`),console.log(),console.log("Options:"),console.log(` ${a.dim("--json")} Output as JSON`),console.log()}function JI(){console.log(),console.log(h.default.bold(a.geminiPurple("gk agent info"))),console.log(a.dim("Show detailed information about an agent profile")),console.log(),console.log("Usage:"),console.log(` ${a.primary("gk agent info")} <name> [options]`),console.log(),console.log("Arguments:"),console.log(` ${a.dim("<name>")} Agent profile name (without .md extension)`),console.log(),console.log("Options:"),console.log(` ${a.dim("--json")} Output as JSON`),console.log(),console.log("Example:"),console.log(` ${a.dim("gk agent info researcher")}`),console.log()}function ZI(){console.log(),console.log(h.default.bold(a.geminiPurple("gk agent search"))),console.log(a.dim("Find best agent+skills combination for a task using BM25 search")),console.log(),console.log("Usage:"),console.log(` ${a.primary("gk agent search")} "<task>" [options]`),console.log(),console.log("Arguments:"),console.log(` ${a.dim("<task>")} Task description to search for`),console.log(),console.log("Options:"),console.log(` ${a.dim("-n, --limit <n>")} Number of results (default: 5)`),console.log(` ${a.dim("-i, --intent <i>")} Force intent: research|plan|execute|debug|review|test|design|docs`),console.log(` ${a.dim("-d, --domain <d>")} Force domain: frontend|backend|auth|payment|database|mobile|ai|etc.`),console.log(` ${a.dim("--max-skills <n>")} Maximum skills to include`),console.log(` ${a.dim("--json")} Output as JSON`),console.log(),console.log("Examples:"),console.log(` ${a.dim('gk agent search "implement user authentication"')}`),console.log(` ${a.dim('gk agent search "debug the login form" -i debug')}`),console.log(` ${a.dim('gk agent search "build a payment page" -d payment')}`),console.log()}function Xp(){console.log(),console.log(h.default.bold(a.geminiPurple("gk agent spawn"))),console.log(a.dim("Spawn a sub-agent with Gemini or Claude CLI")),console.log(),console.log("Usage:"),console.log(` ${a.primary("gk agent spawn")} -p "<prompt>" [options]`),console.log(),console.log("Required:"),console.log(` ${a.dim("-p, --prompt <text>")} Task prompt for the agent`),console.log(),console.log("Options:"),console.log(` ${a.dim("-a, --agent <name>")} Agent profile name`),console.log(` ${a.dim("-s, --skills <list>")} Comma-separated skill names to inject`),console.log(` ${a.dim("-c, --context <files>")} Context files (@file syntax)`),console.log(` ${a.dim("-m, --model <model>")} Model override (default: from config)`),console.log(` ${a.dim("-t, --tools <list>")} Comma-separated tools to auto-approve`),console.log(` ${a.dim("--cli <provider>")} CLI provider: gemini (default) or claude`),console.log(` ${a.dim("--music")} Play elevator music while waiting`),console.log(` ${a.dim("--no-music")} Disable elevator music`),console.log(` ${a.dim("--music-file <path>")} Custom music file path`),console.log(),console.log("CLI Providers:"),console.log(` ${a.dim("gemini")} Uses Gemini CLI (default). Loads from .gemini/agents/, falls back to .claude/agents/`),console.log(` ${a.dim("claude")} Uses Claude CLI. Loads from .claude/agents/, falls back to .gemini/agents/`),console.log(` ${a.dim("Models and tools are automatically mapped between providers when using fallback.")}`),console.log(),console.log("Examples:"),console.log(` ${a.dim('gk agent spawn -p "fix the login bug"')}`),console.log(` ${a.dim('gk agent spawn -a researcher -p "research React best practices"')}`),console.log(` ${a.dim('gk agent spawn -a code-executor -s "frontend-design" -p "build a dashboard"')}`),console.log(` ${a.dim('gk agent spawn -p "implement auth" -m gemini-2.5-pro --music')}`),console.log(` ${a.dim('gk agent spawn -a researcher -t "list_directory,read_file,glob" -p "analyze code"')}`),console.log(` ${a.dim('gk agent spawn --cli claude -a researcher -p "analyze codebase"')}`),console.log(),console.log("Allowed Tools:"),console.log(` ${a.dim("Tools can be defined in agent frontmatter (tools: tool1, tool2)")}`),console.log(` ${a.dim("or passed via CLI. Both sources are merged and deduplicated.")}`),console.log(` ${a.dim("Gemini tools: list_directory, read_file, write_file, glob, run_shell_command(*)")}`),console.log(` ${a.dim("Claude tools: Read, Write, Edit, Bash, Glob, Grep, WebFetch, WebSearch")}`),console.log()}function yI(){console.log(),console.log(h.default.bold(a.geminiPurple("gk agent start"))),console.log(a.dim("Start a single interactive AI session")),console.log(),console.log("Usage:"),console.log(` ${a.primary("gk agent start")} [options]`),console.log(),console.log("Options:"),console.log(` ${a.dim("-a, --agent <name>")} Agent profile name`),console.log(` ${a.dim("-s, --skills <list>")} Comma-separated skill names`),console.log(` ${a.dim("-c, --context <files>")} Context files (@file syntax)`),console.log(` ${a.dim("-m, --model <model>")} Model override`),console.log(` ${a.dim("-t, --tools <list>")} Comma-separated tools to allow`),console.log(` ${a.dim("--cli <provider>")} CLI provider: gemini (default) or claude`),console.log(),console.log("Examples:"),console.log(` ${a.dim("gk agent start -a researcher -s research")}`),console.log(` ${a.dim("gk agent start --cli claude -a code-executor")}`),console.log(` ${a.dim('gk agent start -m gemini-2.5-pro -t "read_file,write_file"')}`),console.log(),console.log("After starting:"),console.log(` ${a.dim('gk agent send "your prompt"')}`),console.log(` ${a.dim("gk agent wait")}`),console.log(` ${a.dim("gk agent exchange")}`),console.log(` ${a.dim("gk agent stop")}`),console.log(),console.log("For team mode, use: gk team start --name <agent>"),console.log()}function qI(){console.log(),console.log(h.default.bold(a.geminiPurple("Interactive Mode Commands"))),console.log(),console.log("Session:"),console.log(` ${a.primary("start")} [options] Start interactive session`),console.log(` ${a.primary("stop")} Stop interactive session`),console.log(` ${a.primary("status")} Check session status`),console.log(),console.log("Interaction:"),console.log(` ${a.primary("send")} "<prompt>" Send prompt to session`),console.log(` ${a.primary("wait")} [timeout] Wait for response completion`),console.log(` ${a.primary("exchange")} Get structured JSON output`),console.log(` ${a.primary("pending")} Check pending tool confirmations`),console.log(` ${a.primary("read")} [lines] Read raw output (debugging)`),console.log(),console.log("Examples:"),console.log(` ${a.dim("gk agent start -a researcher -s research")}`),console.log(` ${a.dim('gk agent send "research JWT best practices"')}`),console.log(` ${a.dim("gk agent wait")}`),console.log(` ${a.dim("gk agent pending")}`),console.log(` ${a.dim('gk agent send "1"')} ${a.dim("# approve tool")}`),console.log(` ${a.dim("gk agent exchange")}`),console.log(` ${a.dim("gk agent stop")}`),console.log()}function Hp(t){t.command("agent [subcommand] [arg]","Agent management (list, info, search, spawn)").alias("a").option("--json","[all] Output as JSON").option("-n, --limit <n>","[search] Number of results (default: 5)",{default:5}).option("-i, --intent <intent>","[search] Force intent: research|plan|execute|debug|review|test|design|docs").option("-d, --domain <domain>","[search] Force domain: frontend|backend|auth|payment|database|mobile|ai").option("--max-skills <n>","[search] Maximum skills to include").option("-a, --agent <name>","[spawn] Agent profile name").option("-p, --prompt <text>","[spawn] Task prompt (required for spawn)").option("-s, --skills <list>","[spawn] Comma-separated skill names").option("-c, --context <files>","[spawn] Context files (@file syntax)").option("-m, --model <model>","[spawn] Model override").option("-t, --tools <list>","[spawn] Comma-separated tools to auto-approve").option("--cli <provider>","[spawn] CLI provider: gemini (default) or claude").option("--music","[spawn] Play elevator music while waiting").option("--no-music","[spawn] Disable elevator music").option("--music-file <path>","[spawn] Custom music file path").action(async(e,i,n)=>{if(n.help||n.h)switch(e){case"list":BI();return;case"info":JI();return;case"search":ZI();return;case"spawn":Xp();return;case"start":yI();return;case"send":case"wait":case"exchange":case"pending":case"read":case"status":case"stop":qI();return;default:Jp();return}switch(e){case"list":await wI(n);break;case"info":i||(console.log(),v.error("Agent profile name required"),console.log(a.dim("Usage: gk agent info <name>")),console.log(),process.exit(1)),await DI(i,n);break;case"search":i||(console.log(),v.error("Search query required"),console.log(a.dim('Usage: gk agent search "<task>"')),console.log(),process.exit(1)),await TI(i,n);break;case"spawn":await XI(n);break;case"start":await HI(n);break;case"send":i||(console.log(),v.error("Prompt required"),console.log(a.dim('Usage: gk agent send "your prompt"')),console.log(),process.exit(1)),await _I(i);break;case"wait":await $I(i?parseInt(i):120);break;case"exchange":await eE();break;case"pending":await tE();break;case"read":await iE(i?parseInt(i):200);break;case"status":await nE();break;case"stop":await oE();break;case"_server":await LI();break;default:Jp()}})}async function wI(t){let e=qo();if(t.json){console.log(JSON.stringify(e,null,2));return}if(console.log(),console.log(h.default.bold(a.geminiPurple("Available Agents"))),console.log(),e.length===0){v.warn('No agent profiles found. Run "gk init" first.'),console.log();return}for(let i of e)console.log(` ${a.primary(i.name)}`),console.log(` ${a.dim(i.description)}`),console.log(` ${a.dim("Model:")} ${i.model}`),i.skills&&i.skills.length>0&&console.log(` ${a.dim("Skills:")} ${i.skills.join(", ")}`),console.log("");console.log(a.dim(` Total: ${e.length} agents`)),console.log()}async function DI(t,e){let i=bv(t);if(i||(console.log(),v.error(`Agent profile not found: ${t}`),console.log(),process.exit(1)),e.json){console.log(JSON.stringify(i,null,2));return}console.log(),console.log(G.doubleLine()),console.log(h.default.bold(a.geminiPurple(`Agent: ${i.name}`))),console.log(G.doubleLine()),console.log(),console.log(` ${a.dim("Description:")} ${i.description}`),console.log(` ${a.dim("Model:")} ${i.model}`),i.skills?.length&&console.log(` ${a.dim("Skills:")} ${i.skills.join(", ")}`),console.log(` ${a.dim("Path:")} ${i.filePath}`),console.log(),console.log(a.dim("--- Profile Content ---")),console.log(),console.log(a.dim(i.content)),console.log()}async function TI(t,e){let i=su(t,{top:e.limit,forceIntent:e.intent,forceDomain:e.domain,maxSkills:e.maxSkills});if(e.json){console.log(JSON.stringify(i,null,2));return}if(console.log(),console.log(h.default.bold(a.geminiPurple(`Search results for: "${t}"`))),console.log(),i.length===0){v.warn("No matching agents found for task."),console.log();return}for(let n=0;n<i.length;n++){let s=i[n],r=s.fallback?a.warn(" [FALLBACK]"):"";console.log(` ${a.success(n+1+".")} ${a.primary(s.agent)}${r} ${a.dim(`(score: ${s.score})`)}`),console.log(` ${a.dim("Intent:")} ${s.intent} ${a.dim("Domain:")} ${s.domain} ${a.dim("Complexity:")} ${s.complexity}`),s.skills.length>0&&console.log(` ${a.dim("Skills:")} ${s.skills.join(" | ")}`),s.description&&console.log(` ${a.dim(s.description)}`),s.useWhen&&console.log(` ${a.dim("Use when:")} ${s.useWhen}`),console.log("")}if(i.length>0){let n=i[0],s=n.skills.length>0?` -s "${n.skills.join(",")}"`:"";console.log(a.dim(" Suggested command:")),console.log(` ${a.primary("gk")} agent spawn -a ${n.agent}${s} -p "${t}"`)}console.log()}async function XI(t){t.prompt||(console.log(),v.error("Prompt is required. Use -p or --prompt"),console.log(),Xp(),process.exit(1));let e=t.cli==="claude"?"claude":"gemini",i=Ie(),n=B(),s=n.ACTIVE_GK_SESSION_ID||null,r=n.ACTIVE_GEMINI_SESSION_ID||null,o=n.ACTIVE_PLAN||null,c=n.SUGGESTED_PLAN||null,l=n.PLAN_DATE_FORMAT||null,u=n.PROJECT_DIR||null,m=null;if(t.team){let I=ge(process.cwd()),j=Q(I,t.team);j||(console.log(),v.error(`Team not found: ${t.team}`),console.log(),process.exit(1));let he=t.name||t.agent||"agent",de=Et(`team-${he}`,process.pid),Oe=Jt(I,de,j.teamId,null);Oe||(console.log(),v.error("No ports available for team member"),console.log(),process.exit(1)),m={team:j,port:Oe,memberName:he,sanitizedProjectDir:I},v.info(`Spawning as team member: ${a.primary(he)}`),v.info(`Team: ${a.dim(j.teamName)} (${j.teamId.slice(0,12)}...)`),v.info(`Port: ${a.dim(Oe.toString())}`)}let p=null;t.agent&&(p=Fn(t.agent,e),p||(console.log(),v.error(`Agent profile not found: ${t.agent}`),console.log(a.dim(`Searched: .${e==="claude"?"claude":"gemini"}/agents/ and fallback folder`)),console.log(),process.exit(1)));let d=t.model||p?.model||i.spawn.defaultModel;d=mi(d,e);let f=process.argv.includes("--music")||process.argv.includes("--no-music")?t.music:i.spawn.music,g=t.musicFile||i.spawn.musicFile,E=t.skills?.split(",").map(I=>I.trim()).filter(Boolean)||[],J=p?.skills||[],M=[...new Set([...J,...E])],rt=t.tools?.split(",").map(I=>I.trim()).filter(Boolean)||[],y=p?.tools||[],te=[...new Set([...y,...rt])],U=vi(te,e),ur=t.context?t.context.split(",").flatMap(I=>I.trim().split(/\s+/).filter(j=>j)).filter(I=>I):[];async function Ln(I){let j=I,he=!1;if(I.startsWith("@")){let de=I.substring(1),Oe=[Je(process.cwd(),".docs",de),Je(process.cwd(),".plans",de),Je(process.cwd(),"docs",de),Je(process.cwd(),"plans",de),Je(process.cwd(),de)];for(let Dt of Oe)try{await yp(Dt),j=Dt,he=!0;break}catch{continue}if(!he){let Dt=Oe.map(rn=>` - ${rn}`).join(`
58
+ `);throw new Error(`Context file not found: ${I}
32
59
  Searched paths:
33
- ${mt}
34
- Tip: Place file in .docs/, .plans/, docs/, plans/, or project root`)}}try{if((await sI(G)).isDirectory())return await qA(G,h);let ut=await iA(G,"utf-8");return{type:"context",name:cI(G),path:G,content:ut.trim(),originalRef:h}}catch(Ae){throw new Error(`Failed to load context from ${h}: ${Ae.message}`)}}async function qA(h,G){let Ae=[".md",".txt",".json",".yaml",".yml"],ut=[];async function mt(mi,$n=0){if($n>3)return;let TA=await aI(mi,{withFileTypes:!0});for(let Ei of TA){let Li=qi(mi,Ei.name);if(!Ei.name.startsWith(".")){if(Ei.isDirectory())await mt(Li,$n+1);else if(Ei.isFile()){let XA=lI(Ei.name).toLowerCase();if(Ae.includes(XA))try{let ps=await iA(Li,"utf-8"),_c=vI(h,Li);ut.push({type:"context",name:Ei.name,path:Li,relativePath:_c,content:ps.trim(),originalRef:`${G}/${_c}`})}catch(ps){console.warn(`Warning: Could not read ${Li}: ${ps.message}`)}}}}}return await mt(h),ut.sort((mi,$n)=>(mi.relativePath||"").localeCompare($n.relativePath||"")),ut}function yA(h){if(!h||h.length===0)return"";let G=`<context>
35
- `;return G+=`The following documents provide additional context for this task:
36
-
37
- `,h.forEach((De,Ae)=>{G+=`## Document ${Ae+1}: ${De.name}
38
- `,G+=`Source: ${De.originalRef}
39
-
40
- `}),G+=`</context>
41
-
42
- `,G}let lt=[];if(cs&&cs.length>0)for(let h of cs)try{if(typeof h=="string"){let G=await PA(h);Array.isArray(G)?lt.push(...G):lt.push(G)}else lt.push(h)}catch(G){console.log(),m.error(G.message),console.log(),process.exit(1)}let vt=A?.name||t.agent||"Sub",N=[],DA=uI({agentType:"Sub Agent",agentRole:vt,parentSessionId:r,activePlan:a,projectDir:v});if(N.push("<subagent-context>"),N.push(DA),N.push(`</subagent-context>
43
- `),N.push("<task>"),N.push(t.prompt),N.push(`</task>
44
- `),A&&(N.push("<agent>"),N.push(`# Agent: ${A.name}
45
- `),N.push("## Role & Responsibilities"),N.push(A.content),N.push(`</agent>
46
- `)),C.length>0){N.push("<skills>"),N.push(`You have access to the following skills and capabilities:
47
- `);for(let h=0;h<C.length;h++){let G=C[h],De=Bv(G);De&&(N.push(`## Skill ${h+1}: ${G}`),N.push(De),N.push(`---
48
- `))}N.push(`</skills>
49
- `)}lt.length>0&&N.push(yA(lt));let wA=N.join(`
50
- `),Lc=t.prompt.length>150?t.prompt.substring(0,150):t.prompt;console.log(),m.info(`Spawning ${s.primary(vt)} agent with ${s.primary(e)} CLI`),m.info(`Model: ${s.primary(u)}`),r&&m.info(`Parent session: ${s.dim(r.slice(0,20)+"...")}`),a&&m.info(`Active plan: ${s.dim(a)}`),C.length>0&&m.info(`Injected skills: ${s.dim(C.join(", "))}`),lt.length>0&&m.info(`Injected context: ${s.dim(lt.map(h=>h.name).join(", "))}`),ui.length>0&&m.info(`Allowed tools: ${s.dim(ui.join(", "))}`),console.log(M.line()),console.log();let At=null;E&&(At=new Po({audioFile:f,loop:!0,volume:.3}),At.start()&&(console.log(s.dim("Playing elevator music while waiting...")),console.log()));let _n=lt.map(h=>h.path||h.name),ls=Fo("gemini-sub",process.pid);r&&v&&bo(v,r,{gkSessionId:ls,pid:process.pid,parentGkSessionId:r,agentRole:vt,prompt:t.prompt,model:u,injected:C.length>0||_n.length>0?{skills:C,context:_n}:null});let vs=AI(vt),As,Hi,us;e==="claude"?(As="claude",Hi=["-p","--model",u],ui.length>0&&Hi.push("--allowedTools",ui.join(",")),us={...process.env,CLAUDE_TYPE:"sub-agent",GK_PARENT_SESSION_ID:r||"",GK_SUB_SESSION_ID:ls,CLAUDE_AGENT_ROLE:vt,CLAUDE_AGENT_PROMPT:Lc,CLAUDE_AGENT_MODEL:u||"",CLAUDE_AGENT_SKILLS:C.join(","),CLAUDE_AGENT_CONTEXT:_n.join(","),GK_ACTIVE_PLAN:a||"",GK_SUGGESTED_PLAN:c||"",GK_PLAN_DATE_FORMAT:l||""}):(As="gemini",Hi=["-m",u],ui.length>0&&Hi.push("--allowed-tools",JSON.stringify(ui)),us={...process.env,GEMINI_TYPE:"sub-agent",GEMINI_PARENT_SESSION_ID:o||"",GK_PARENT_SESSION_ID:r||"",GK_SUB_SESSION_ID:ls,GEMINI_AGENT_ROLE:vt,GEMINI_AGENT_PROMPT:Lc,GEMINI_AGENT_MODEL:u||"",GEMINI_AGENT_SKILLS:C.join(","),GEMINI_AGENT_CONTEXT:_n.join(","),GK_ACTIVE_PLAN:a||"",GK_SUGGESTED_PLAN:c||"",GK_PLAN_DATE_FORMAT:l||""});let Qt=rI(As,Hi,{stdio:["pipe","pipe","pipe"],shell:process.platform==="win32",env:us}),ms="",Es="";Qt.stdout.on("data",h=>{ms+=h.toString()}),Qt.stderr.on("data",h=>{Es+=h.toString()}),Qt.stdin.write(wA),Qt.stdin.end(),Qt.on("close",h=>{vs.stop(),At&&(At.stop(),console.log(s.dim("Music stopped."))),console.log(),ms&&console.log(ms),Es&&console.error(Es),h===0?m.success(`${vt} agent completed successfully`):m.error(`${vt} agent exited with code: ${h}`),console.log(),process.exit(h||0)}),Qt.on("error",h=>{vs.stop(),At&&At.stop(),console.log(),m.error(`Failed to spawn agent: ${h.message}`),console.log(),process.exit(1)}),process.on("SIGINT",()=>{vs.stop(),At&&At.stop(),Qt.kill("SIGTERM"),process.exit(1)})}function RI(){console.log(),console.log(I.default.bold(s.geminiPurple("Session Management"))),console.log(),console.log("Usage:"),console.log(` ${s.primary("gk session")} <subcommand> [options]`),console.log(),console.log("Subcommands:"),console.log(` ${s.primary("status")} Show active session (default)`),console.log(` ${s.primary("list")} List recent sessions`),console.log(` ${s.primary("info")} <id> Show session details`),console.log(` ${s.primary("agents")} [id] List agents in session`),console.log(` ${s.primary("init")} [app] Initialize new session`),console.log(),console.log("Options:"),console.log(` ${s.dim("--json")} Output as JSON`),console.log(` ${s.dim("-n, --limit <n>")} Number of results for list (default: 10)`),console.log(),console.log("Examples:"),console.log(` ${s.dim("gk session status")}`),console.log(` ${s.dim("gk session list -n 20")}`),console.log(` ${s.dim("gk session info abc123")}`),console.log(` ${s.dim("gk session agents")}`),console.log(` ${s.dim("gk session init myapp")}`),console.log()}function cA(t){t.command("session [subcommand] [id]","Session management (status, list, info, agents, init)").alias("s").option("--json","[all] Output as JSON").option("-n, --limit <n>","[list] Number of results",{default:10}).action(async(e,i,n)=>{switch(e||"status"){case"status":await zI(n);break;case"list":await gI(n);break;case"info":i||(console.log(),m.error("Session ID required"),console.log(s.dim("Usage: gk session info <id>")),console.log(),process.exit(1)),await jI(i,n);break;case"agents":await xI(i,n);break;case"init":await GI(i||"app",n);break;default:RI()}})}async function zI(t){let e=k(),i=at(),n=e.ACTIVE_GK_SESSION_ID;if(!n){t.json?console.log(JSON.stringify({active:!1,projectDir:i},null,2)):(console.log(),m.info("No active GemKit session."),console.log(s.dim(` Project: ${i}`)),console.log());return}let r=Ce(i,n);if(t.json){console.log(JSON.stringify(r||{active:!1,gkSessionId:n},null,2));return}if(!r){console.log(),m.warn(`Session ID in .env but file not found: ${n}`),console.log(s.dim(` Project: ${i}`)),console.log();return}let o=Dv(i,n),c=r.agents?.find(l=>l.agentType==="Main Agent")?.status||"active";console.log(),console.log(I.default.bold(s.geminiPurple("Active Session"))),console.log(M.line()),console.log(),console.log(` ${s.dim("GK Session ID:")} ${s.primary(r.gkSessionId)}`),console.log(` ${s.dim("Gemini Session ID:")} ${r.geminiSessionId||s.dim("N/A")}`),console.log(` ${s.dim("Project Dir:")} ${r.projectDir}`),console.log(` ${s.dim("App Name:")} ${r.appName}`),console.log(` ${s.dim("PID:")} ${r.pid}`),console.log(` ${s.dim("Status:")} ${M.statusIcon(c)} ${c}`),console.log(` ${s.dim("Started:")} ${r.initTimestamp}`),r.activePlan&&console.log(` ${s.dim("Active Plan:")} ${s.primary(r.activePlan)}`),console.log(),console.log(` ${s.dim("Agents:")} ${o.total} total (${o.mainAgents} main, ${o.subAgents} sub)`),console.log(` ${s.success(String(o.completed))} completed, ${s.error(String(o.failed))} failed, ${o.active} active`),console.log()}async function gI(t){let e=at(),i=yv(e,{limit:t.limit});if(t.json){console.log(JSON.stringify(i,null,2));return}if(console.log(),console.log(I.default.bold(s.geminiPurple("Recent Sessions"))),console.log(s.dim(` Project: ${e}`)),console.log(),i.length===0){m.info(" No sessions found."),console.log();return}for(let n of i){let r=new Date(n.initTimestamp).toLocaleString(),a=n.agents?.find(l=>l.agentType==="Main Agent")?.status||"active",c=n.gkSessionId.length>25?n.gkSessionId.slice(0,25)+"...":n.gkSessionId;console.log(` ${M.statusIcon(a)} ${s.primary(c)} ${s.dim(r)}`),n.activePlan&&console.log(` ${s.dim("Plan:")} ${n.activePlan}`)}console.log(),console.log(s.dim(` Showing ${i.length} sessions (limit: ${t.limit})`)),console.log()}async function jI(t,e){let i=at(),n=Ce(i,t);if(n||(console.log(),m.error(`Session not found: ${t}`),console.log(s.dim(` Looked in: ~/.gemkit/projects/${i}/`)),console.log(),process.exit(1)),e.json){console.log(JSON.stringify(n,null,2));return}console.log(),console.log(I.default.bold(s.geminiPurple(`Session: ${n.gkSessionId}`))),console.log(M.line()),console.log(),console.log(JSON.stringify(n,null,2)),console.log()}async function xI(t,e){let i=at(),n=t||vi();n||(console.log(),m.error("No session ID provided and no active session found."),console.log(),process.exit(1));let r=Ce(i,n);r||(console.log(),m.error(`Session not found: ${n}`),console.log(),process.exit(1));let o=r.agents||[];if(e.json){console.log(JSON.stringify(o,null,2));return}let a=n.length>30?n.slice(0,30)+"...":n;if(console.log(),console.log(I.default.bold(s.geminiPurple("Agents in Session"))),console.log(s.dim(` ${a}`)),console.log(),o.length===0){m.info(" No agents in this session."),console.log();return}for(let c=0;c<o.length;c++){let l=o[c],v=l.agentRole||"unknown",A=l.model||"default",u=l.agentType==="Main Agent"?s.primary("MAIN"):s.dim("SUB");if(console.log(` ${M.statusIcon(l.status)} [${u}] ${s.primary(v)} ${s.dim(`(${A})`)}`),l.prompt){let p=l.prompt.length>60?l.prompt.slice(0,60)+"...":l.prompt;console.log(` ${s.dim("Prompt:")} ${p}`)}l.tokenUsage&&console.log(` ${s.dim("Tokens:")} ${l.tokenUsage.total.toLocaleString()} total`),l.geminiSessionId&&console.log(` ${s.dim("Gemini ID:")} ${l.geminiSessionId.slice(0,8)}...`)}console.log(),console.log(s.dim(` Total: ${o.length} agents`)),console.log()}async function GI(t,e){let n=k().ACTIVE_GK_SESSION_ID;if(n){let l=$v(n),v=at();if(l){let A=gc();if(Ce(v,n)&&l.pid===A){e.json?console.log(JSON.stringify({status:"existing",gkSessionId:n,pid:l.pid},null,2)):(console.log(),m.info(`GemKit session already active: ${s.primary(n.slice(0,30)+"...")}`),console.log(s.dim(` PID: ${l.pid}`)),console.log());return}}}let{session:r,gkSessionId:o,pid:a,projectDir:c}=Lv(t);bo(c,o,{gkSessionId:o,pid:a,geminiSessionId:null,parentGkSessionId:null,agentRole:"main",prompt:null,model:null}),e.json?console.log(JSON.stringify({status:"initialized",gkSessionId:o,pid:a,projectDir:c},null,2)):(console.log(),m.success(`GemKit session initialized: ${s.primary(o.slice(0,30)+"...")}`),console.log(s.dim(` PID: ${a}`)),console.log())}import{existsSync as Hn,readdirSync as SI,mkdirSync as qo,writeFileSync as Sc,statSync as YI}from"fs";import{join as Ai}from"path";function Yc(t){let e=Ri(t);if(!Hn(e))return[];let i=Xn();return SI(e,{withFileTypes:!0}).filter(r=>r.isDirectory()).map(r=>r.name).map(r=>{let o=Ai(e,r),a=Ai(o,"plan.md"),c="";return Hn(a)&&(c=YI(a).birthtime.toISOString()),{name:r,path:o,createdAt:c,isActive:r===i}})}function lA(t,e){let i=Ri(e),n=Ai(i,t);if(Hn(i)||qo(i,{recursive:!0}),Hn(n))throw new Error(`Plan already exists: ${t}`);qo(n,{recursive:!0}),qo(Ai(n,"research"),{recursive:!0}),qo(Ai(n,"artifacts"),{recursive:!0});let r=`# ${t}
60
+ ${Dt}
61
+ Tip: Place file in .docs/, .plans/, docs/, plans/, or project root`)}}try{if((await qp(j)).isDirectory())return await qa(j,I);let Oe=await Sa(j,"utf-8");return{type:"context",name:Dp(j),path:j,content:Oe.trim(),originalRef:I}}catch(de){throw new Error(`Failed to load context from ${I}: ${de.message}`)}}async function qa(I,j){let de=[".md",".txt",".json",".yaml",".yml"],Oe=[];async function Dt(rn,vr=0){if(vr>3)return;let FA=await wp(rn,{withFileTypes:!0});for(let on of FA){let es=Je(rn,on.name);if(!on.name.startsWith(".")){if(on.isDirectory())await Dt(es,vr+1);else if(on.isFile()){let bA=Tp(on.name).toLowerCase();if(de.includes(bA))try{let La=await Sa(es,"utf-8"),nm=Cu(I,es);Oe.push({type:"context",name:on.name,path:es,relativePath:nm,content:La.trim(),originalRef:`${j}/${nm}`})}catch(La){console.warn(`Warning: Could not read ${es}: ${La.message}`)}}}}}return await Dt(I),Oe.sort((rn,vr)=>(rn.relativePath||"").localeCompare(vr.relativePath||"")),Oe}function wa(I){if(!I||I.length===0)return"";let j=`<context>
62
+ `;return j+=`The following documents provide additional context for this task:
63
+
64
+ `,I.forEach((he,de)=>{j+=`## Document ${de+1}: ${he.name}
65
+ `,j+=`Source: ${he.originalRef}
66
+
67
+ `}),j+=`</context>
68
+
69
+ `,j}let Ae=[];if(ur&&ur.length>0)for(let I of ur)try{if(typeof I=="string"){let j=await Ln(I);Array.isArray(j)?Ae.push(...j):Ae.push(j)}else Ae.push(I)}catch(j){console.log(),v.error(j.message),console.log(),process.exit(1)}let ot=p?.name||t.agent||"Sub",K=[],ie=QI({agentType:"Sub Agent",agentRole:ot,parentSessionId:s,activePlan:o,projectDir:u});if(K.push("<subagent-context>"),K.push(ie),K.push(`</subagent-context>
70
+ `),K.push("<task>"),K.push(t.prompt),K.push(`</task>
71
+ `),p&&(K.push("<agent>"),K.push(`# Agent: ${p.name}
72
+ `),K.push("## Role & Responsibilities"),K.push(p.content),K.push(`</agent>
73
+ `)),M.length>0){K.push("<skills>"),K.push(`You have access to the following skills and capabilities:
74
+ `);for(let I=0;I<M.length;I++){let j=M[I],he=bn(j);he&&(K.push(`## Skill ${I+1}: ${j}`),K.push(he),K.push(`---
75
+ `))}K.push(`</skills>
76
+ `)}Ae.length>0&&K.push(wa(Ae));let Ze=K.join(`
77
+ `),at=t.prompt.length>150?t.prompt.substring(0,150):t.prompt;console.log(),v.info(`Spawning ${a.primary(ot)} agent with ${a.primary(e)} CLI`),v.info(`Model: ${a.primary(d)}`),s&&v.info(`Parent session: ${a.dim(s.slice(0,20)+"...")}`),o&&v.info(`Active plan: ${a.dim(o)}`),M.length>0&&v.info(`Injected skills: ${a.dim(M.join(", "))}`),Ae.length>0&&v.info(`Injected context: ${a.dim(Ae.map(I=>I.name).join(", "))}`),U.length>0&&v.info(`Allowed tools: ${a.dim(U.join(", "))}`),console.log(G.line()),console.log();let qt=null;f&&(qt=new xa({audioFile:g,loop:!0,volume:.3}),qt.start()&&(console.log(a.dim("Playing elevator music while waiting...")),console.log()));let mr=Ae.map(I=>I.path||I.name),jt=Et("gemini-sub",process.pid);s&&u&&Ea(u,s,{gkSessionId:jt,pid:process.pid,parentGkSessionId:s,agentRole:ot,prompt:t.prompt,model:d,injected:M.length>0||mr.length>0?{skills:M,context:mr}:null});let Da=PI(ot),Ta,_n,$n;e==="claude"?(Ta="claude",_n=["-p","--model",d],U.length>0&&_n.push("--allowedTools",U.join(",")),$n={...process.env,CLAUDE_TYPE:"sub-agent",GK_PARENT_SESSION_ID:s||"",GK_SUB_SESSION_ID:jt,CLAUDE_AGENT_ROLE:ot,CLAUDE_AGENT_PROMPT:at,CLAUDE_AGENT_MODEL:d||"",CLAUDE_AGENT_SKILLS:M.join(","),CLAUDE_AGENT_CONTEXT:mr.join(","),GK_ACTIVE_PLAN:o||"",GK_SUGGESTED_PLAN:c||"",GK_PLAN_DATE_FORMAT:l||""}):(Ta="gemini",_n=["-m",d],U.length>0&&_n.push("--allowed-tools",JSON.stringify(U)),$n={...process.env,GEMINI_TYPE:"sub-agent",GEMINI_PARENT_SESSION_ID:r||"",GK_PARENT_SESSION_ID:s||"",GK_SUB_SESSION_ID:jt,GEMINI_AGENT_ROLE:ot,GEMINI_AGENT_PROMPT:at,GEMINI_AGENT_MODEL:d||"",GEMINI_AGENT_SKILLS:M.join(","),GEMINI_AGENT_CONTEXT:mr.join(","),GK_ACTIVE_PLAN:o||"",GK_SUGGESTED_PLAN:c||"",GK_PLAN_DATE_FORMAT:l||""}),m&&($n={...$n,GK_TEAM_ID:m.team.teamId,GK_TEAM_NAME:m.team.teamName,GK_TEAM_ROLE:"member",GK_TEAM_PORT:m.port.toString(),GK_TEAM_LEADER_PORT:m.team.leaderPort.toString(),GK_AGENT_NAME:m.memberName},gi(m.sanitizedProjectDir,m.team.teamId,{agentId:jt,name:m.memberName,agentType:t.agent||"default",role:"member",port:m.port,pid:null,status:"starting"}));let wt=Zp(Ta,_n,{stdio:["pipe","pipe","pipe"],shell:process.platform==="win32",env:$n});m&&wt.pid&&Z(m.sanitizedProjectDir,m.team.teamId,jt,"ready");let Xa="",Ha="";wt.stdout.on("data",I=>{Xa+=I.toString()}),wt.stderr.on("data",I=>{Ha+=I.toString()}),wt.stdin.write(Ze),wt.stdin.end(),wt.on("close",I=>{Da.stop(),qt&&(qt.stop(),console.log(a.dim("Music stopped."))),m&&(Z(m.sanitizedProjectDir,m.team.teamId,jt,"shutdown"),Me(m.sanitizedProjectDir,jt)),console.log(),Xa&&console.log(Xa),Ha&&console.error(Ha),I===0?v.success(`${ot} agent completed successfully`):v.error(`${ot} agent exited with code: ${I}`),console.log(),process.exit(I||0)}),wt.on("error",I=>{Da.stop(),qt&&qt.stop(),m&&(Z(m.sanitizedProjectDir,m.team.teamId,jt,"shutdown"),Me(m.sanitizedProjectDir,jt)),console.log(),v.error(`Failed to spawn agent: ${I.message}`),console.log(),process.exit(1)}),process.on("SIGINT",()=>{Da.stop(),qt&&qt.stop(),wt.kill("SIGTERM"),process.exit(1)})}async function HI(t){bt()&&(console.log(),v.error('Session already running. Use "gk agent stop" first.'),console.log(),process.exit(1));let e=t.cli==="claude"?"claude":"gemini",i=Ie(),n=null;t.agent&&(n=Fn(t.agent,e),n||(console.log(),v.error(`Agent profile not found: ${t.agent}`),console.log(a.dim(`Searched: .${e==="claude"?"claude":"gemini"}/agents/ and fallback folder`)),console.log(),process.exit(1)));let s=t.model||n?.model||i.spawn.defaultModel;s=mi(s,e);let r=t.tools?.split(",").map(y=>y.trim()).filter(Boolean)||[],o=n?.tools||[],c=[...new Set([...o,...r])],l=vi(c,e),u=t.skills?.split(",").map(y=>y.trim()).filter(Boolean)||[],m=n?.skills||[],p=[...new Set([...m,...u])],d={};for(let y of p){let te=bn(y);te&&(d[y]=te)}let A=[];if(t.context){let y=t.context.split(",").flatMap(te=>te.trim().split(/\s+/).filter(U=>U)).filter(te=>te);for(let te of y)try{let U=await aE(te);Array.isArray(U)?A.push(...U):A.push(U)}catch(U){console.log(),v.error(U.message),console.log(),process.exit(1)}}let f=3377,g={provider:e,model:s,port:f,pid:0,isFirstSend:!0,context:{agentName:n?.name||null,agentContent:n?.content||null,skills:p,skillContents:d,contextFiles:A,tools:l},startedAt:new Date().toISOString()};$i(g),console.log(),v.info(`Starting ${a.primary(e)} interactive session...`),v.info(`Model: ${a.primary(s)}`),n&&v.info(`Agent: ${a.dim(n.name)}`),p.length>0&&v.info(`Skills: ${a.dim(p.join(", "))}`),l.length>0&&v.info(`Tools: ${a.dim(l.join(", "))}`),console.log();let E=process.argv[1],J=Zp(process.execPath,[E,"agent","_server"],{detached:!0,stdio:"ignore",windowsHide:!0,cwd:process.cwd(),env:process.env});J.unref(),g.pid=J.pid||0,$i(g),v.info(`Server started (PID: ${J.pid}, Port: ${f})`),v.info("Waiting for AI to initialize...");let M=new ee(g.port),rt=120;for(let y=0;y<rt;y++){await Ou(1e3);try{if((await M.status()).ready){console.log(),v.success("Session ready!"),console.log(),console.log("Usage:"),console.log(` ${a.dim('gk agent send "your prompt"')}`),console.log(` ${a.dim("gk agent wait")}`),console.log(` ${a.dim("gk agent exchange")}`),console.log(` ${a.dim("gk agent stop")}`),console.log();return}}catch{}process.stdout.write(".")}console.log(),v.warn("Server started but AI may still be initializing."),v.info("Check status with: gk agent status"),console.log()}async function LI(){let t=Ge();t||(console.error("[Server] No session state found"),process.exit(1));let e=new yn({provider:t.provider,model:t.model,tools:t.context.tools,sessionState:t,port:t.port,debug:!1});try{await e.start()}catch(i){console.error(`[Server] Failed to start: ${i.message}`),et(),process.exit(1)}process.on("SIGINT",async()=>{await e.stop(),et(),process.exit(0)}),process.on("SIGTERM",async()=>{await e.stop(),et(),process.exit(0)})}function Ou(t){return new Promise(e=>setTimeout(e,t))}async function _I(t){let e=Ge();(!e||!bt())&&(console.log(),v.error('No active session. Use "gk agent start" first.'),console.log(),process.exit(1));let i=new ee(e.port),n=t;e.isFirstSend&&(n=Tv(t,e),qv());try{let s=await i.send(n);s.ok?v.info(`Sent prompt${s.exchangeId?` (exchange: ${s.exchangeId.slice(0,8)}...)`:""}`):v.error(s.error||"Failed to send")}catch(s){v.error(`Failed to send: ${s.message}`),process.exit(1)}}async function $I(t){let e=Ge();(!e||!bt())&&(console.log(),v.error("No active session."),console.log(),process.exit(1));let i=new ee(e.port);console.log(`Waiting for completion (timeout: ${t}s)...`);let n=Date.now(),s=t*1e3;for(;Date.now()-n<s;){try{let r=await i.complete();if(r.complete){console.log(`
78
+ Complete!`);return}if(r.reason==="pending_tool"){console.log(`
79
+ `),v.warn("Tool confirmation required"),r.hint&&console.log(a.dim(r.hint)),console.log(a.dim("Use: gk agent pending"));return}}catch(r){v.error(r.message);return}await Ou(2e3),process.stdout.write(".")}console.log(""),v.warn("Timeout reached. AI may still be working.")}async function eE(){let t=Ge();(!t||!bt())&&(console.log(),v.error("No active session."),console.log(),process.exit(1));let e=new ee(t.port);try{let i=await e.exchange();console.log(JSON.stringify(i,null,2))}catch(i){v.error(i.message),process.exit(1)}}async function tE(){let t=Ge();(!t||!bt())&&(console.log(),v.error("No active session."),console.log(),process.exit(1));let e=new ee(t.port);try{let i=await e.pending();i.hasPending?(console.log(),v.warn("Tool confirmation required"),console.log(JSON.stringify(i,null,2)),console.log(),console.log("To approve: "+a.primary('gk agent send "1"')),console.log("To reject: "+a.primary('gk agent send "3"')),console.log()):console.log("No pending confirmations")}catch(i){v.error(i.message),process.exit(1)}}async function iE(t){let e=Ge();(!e||!bt())&&(console.log(),v.error("No active session."),console.log(),process.exit(1));let i=new ee(e.port);try{let n=await i.read(t);console.log(n)}catch(n){v.error(n.message),process.exit(1)}}async function nE(){let t=Ge();if(!t){console.log("No session file found.");return}if(!bt()){console.log("Session file exists but process not running."),console.log("Cleaning up..."),et();return}let e=new ee(t.port);try{let i=await e.status();console.log(),console.log(h.default.bold("Session: ")+a.success("ACTIVE")),console.log(`Provider: ${t.provider}`),console.log(`Model: ${t.model}`),console.log(`PID: ${t.pid}`),console.log(`Started: ${t.startedAt}`),console.log(`First send pending: ${t.isFirstSend}`),t.context.agentName&&console.log(`Agent: ${t.context.agentName}`),t.context.skills.length>0&&console.log(`Skills: ${t.context.skills.join(", ")}`),console.log(`Output buffer: ${i.outputLength} bytes`),console.log()}catch(i){v.error(i.message),process.exit(1)}}function sE(t){if(!t||t<=0)return!1;try{return process.kill(t,0),!0}catch{return!1}}function rE(t){if(!t||t<=0)return!1;try{if(process.platform==="win32"){let{execSync:e}=yA("child_process");e(`cmd.exe /c taskkill /F /T /PID ${t}`,{stdio:["pipe","pipe","pipe"],timeout:5e3})}else process.kill(t,"SIGKILL");return!0}catch{try{return process.kill(t,"SIGKILL"),!0}catch{return!1}}}async function oE(){let t=Ge();if(!t){console.log("No active session.");return}let e=t.pid;if(bt())try{await new ee(t.port).stop(),v.info("Sent stop command to server..."),await Ou(2e3)}catch{}e&&sE(e)&&(v.info(`Force killing server process (PID: ${e})...`),rE(e)?v.info(`Process ${e} killed.`):v.warn(`Could not kill process ${e} (may already be dead).`)),et(),v.success("Session stopped.")}async function aE(t){let e=t;if(t.startsWith("@")){let s=t.substring(1),r=[Je(process.cwd(),".docs",s),Je(process.cwd(),".plans",s),Je(process.cwd(),"docs",s),Je(process.cwd(),"plans",s),Je(process.cwd(),s)],o=!1;for(let c of r)try{await yp(c),e=c,o=!0;break}catch{continue}if(!o)throw new Error(`Context file not found: ${t}`)}if((await qp(e)).isDirectory()){let s=[],r=[".md",".txt",".json",".yaml",".yml"];async function o(c,l=0){if(l>3)return;let u=await wp(c,{withFileTypes:!0});for(let m of u){if(m.name.startsWith("."))continue;let p=Je(c,m.name);if(m.isDirectory())await o(p,l+1);else if(m.isFile()){let d=Tp(m.name).toLowerCase();if(r.includes(d)){let A=await Sa(p,"utf-8");s.push({type:"context",name:m.name,path:p,relativePath:Cu(e,p),content:A.trim(),originalRef:`${t}/${Cu(e,p)}`})}}}}return await o(e),s}let n=await Sa(e,"utf-8");return{type:"context",name:Dp(e),path:e,content:n.trim(),originalRef:t}}it();k();function cE(){console.log(),console.log(h.default.bold(a.geminiPurple("Session Management"))),console.log(),console.log("Usage:"),console.log(` ${a.primary("gk session")} <subcommand> [options]`),console.log(),console.log("Subcommands:"),console.log(` ${a.primary("status")} Show active session (default)`),console.log(` ${a.primary("list")} List recent sessions`),console.log(` ${a.primary("info")} <id> Show session details`),console.log(` ${a.primary("agents")} [id] List agents in session`),console.log(` ${a.primary("init")} [app] Initialize new session`),console.log(),console.log("Options:"),console.log(` ${a.dim("--json")} Output as JSON`),console.log(` ${a.dim("-n, --limit <n>")} Number of results for list (default: 10)`),console.log(),console.log("Examples:"),console.log(` ${a.dim("gk session status")}`),console.log(` ${a.dim("gk session list -n 20")}`),console.log(` ${a.dim("gk session info abc123")}`),console.log(` ${a.dim("gk session agents")}`),console.log(` ${a.dim("gk session init myapp")}`),console.log()}function Lp(t){t.command("session [subcommand] [id]","Session management (status, list, info, agents, init)").alias("s").option("--json","[all] Output as JSON").option("-n, --limit <n>","[list] Number of results",{default:10}).action(async(e,i,n)=>{switch(e||"status"){case"status":await lE(n);break;case"list":await uE(n);break;case"info":i||(console.log(),v.error("Session ID required"),console.log(a.dim("Usage: gk session info <id>")),console.log(),process.exit(1)),await mE(i,n);break;case"agents":await vE(i,n);break;case"init":await pE(i||"app",n);break;default:cE()}})}async function lE(t){let e=B(),i=Zt(),n=e.ACTIVE_GK_SESSION_ID;if(!n){t.json?console.log(JSON.stringify({active:!1,projectDir:i},null,2)):(console.log(),v.info("No active GemKit session."),console.log(a.dim(` Project: ${i}`)),console.log());return}let s=nt(i,n);if(t.json){console.log(JSON.stringify(s||{active:!1,gkSessionId:n},null,2));return}if(!s){console.log(),v.warn(`Session ID in .env but file not found: ${n}`),console.log(a.dim(` Project: ${i}`)),console.log();return}let r=Cp(i,n),c=s.agents?.find(l=>l.agentType==="Main Agent")?.status||"active";console.log(),console.log(h.default.bold(a.geminiPurple("Active Session"))),console.log(G.line()),console.log(),console.log(` ${a.dim("GK Session ID:")} ${a.primary(s.gkSessionId)}`),console.log(` ${a.dim("Gemini Session ID:")} ${s.geminiSessionId||a.dim("N/A")}`),console.log(` ${a.dim("Project Dir:")} ${s.projectDir}`),console.log(` ${a.dim("App Name:")} ${s.appName}`),console.log(` ${a.dim("PID:")} ${s.pid}`),console.log(` ${a.dim("Status:")} ${G.statusIcon(c)} ${c}`),console.log(` ${a.dim("Started:")} ${s.initTimestamp}`),s.activePlan&&console.log(` ${a.dim("Active Plan:")} ${a.primary(s.activePlan)}`),console.log(),console.log(` ${a.dim("Agents:")} ${r.total} total (${r.mainAgents} main, ${r.subAgents} sub)`),console.log(` ${a.success(String(r.completed))} completed, ${a.error(String(r.failed))} failed, ${r.active} active`),console.log()}async function uE(t){let e=Zt(),i=Wp(e,{limit:t.limit});if(t.json){console.log(JSON.stringify(i,null,2));return}if(console.log(),console.log(h.default.bold(a.geminiPurple("Recent Sessions"))),console.log(a.dim(` Project: ${e}`)),console.log(),i.length===0){v.info(" No sessions found."),console.log();return}for(let n of i){let s=new Date(n.initTimestamp).toLocaleString(),o=n.agents?.find(l=>l.agentType==="Main Agent")?.status||"active",c=n.gkSessionId.length>25?n.gkSessionId.slice(0,25)+"...":n.gkSessionId;console.log(` ${G.statusIcon(o)} ${a.primary(c)} ${a.dim(s)}`),n.activePlan&&console.log(` ${a.dim("Plan:")} ${n.activePlan}`)}console.log(),console.log(a.dim(` Showing ${i.length} sessions (limit: ${t.limit})`)),console.log()}async function mE(t,e){let i=Zt(),n=nt(i,t);if(n||(console.log(),v.error(`Session not found: ${t}`),console.log(a.dim(` Looked in: ~/.gemkit/projects/${i}/`)),console.log(),process.exit(1)),e.json){console.log(JSON.stringify(n,null,2));return}console.log(),console.log(h.default.bold(a.geminiPurple(`Session: ${n.gkSessionId}`))),console.log(G.line()),console.log(),console.log(JSON.stringify(n,null,2)),console.log()}async function vE(t,e){let i=Zt(),n=t||nn();n||(console.log(),v.error("No session ID provided and no active session found."),console.log(),process.exit(1));let s=nt(i,n);s||(console.log(),v.error(`Session not found: ${n}`),console.log(),process.exit(1));let r=s.agents||[];if(e.json){console.log(JSON.stringify(r,null,2));return}let o=n.length>30?n.slice(0,30)+"...":n;if(console.log(),console.log(h.default.bold(a.geminiPurple("Agents in Session"))),console.log(a.dim(` ${o}`)),console.log(),r.length===0){v.info(" No agents in this session."),console.log();return}for(let c=0;c<r.length;c++){let l=r[c],u=l.agentRole||"unknown",m=l.model||"default",p=l.agentType==="Main Agent"?a.primary("MAIN"):a.dim("SUB");if(console.log(` ${G.statusIcon(l.status)} [${p}] ${a.primary(u)} ${a.dim(`(${m})`)}`),l.prompt){let d=l.prompt.length>60?l.prompt.slice(0,60)+"...":l.prompt;console.log(` ${a.dim("Prompt:")} ${d}`)}l.tokenUsage&&console.log(` ${a.dim("Tokens:")} ${l.tokenUsage.total.toLocaleString()} total`),l.geminiSessionId&&console.log(` ${a.dim("Gemini ID:")} ${l.geminiSessionId.slice(0,8)}...`)}console.log(),console.log(a.dim(` Total: ${r.length} agents`)),console.log()}async function pE(t,e){let n=B().ACTIVE_GK_SESSION_ID;if(n){let l=Fp(n),u=Zt();if(l){let m=Gu();if(nt(u,n)&&l.pid===m){e.json?console.log(JSON.stringify({status:"existing",gkSessionId:n,pid:l.pid},null,2)):(console.log(),v.info(`GemKit session already active: ${a.primary(n.slice(0,30)+"...")}`),console.log(a.dim(` PID: ${l.pid}`)),console.log());return}}}let{session:s,gkSessionId:r,pid:o,projectDir:c}=Vp(t);Ea(c,r,{gkSessionId:r,pid:o,geminiSessionId:null,parentGkSessionId:null,agentRole:"main",prompt:null,model:null}),e.json?console.log(JSON.stringify({status:"initialized",gkSessionId:r,pid:o,projectDir:c},null,2)):(console.log(),v.success(`GemKit session initialized: ${a.primary(r.slice(0,30)+"...")}`),console.log(a.dim(` PID: ${o}`)),console.log())}k();it();import{existsSync as ar,readdirSync as AE,mkdirSync as Ga,writeFileSync as Uu,statSync as dE}from"fs";import{join as sn}from"path";function Ku(t){let e=vn(t);if(!ar(e))return[];let i=or();return AE(e,{withFileTypes:!0}).filter(s=>s.isDirectory()).map(s=>s.name).map(s=>{let r=sn(e,s),o=sn(r,"plan.md"),c="";return ar(o)&&(c=dE(o).birthtime.toISOString()),{name:s,path:r,createdAt:c,isActive:s===i}})}function _p(t,e){let i=vn(e),n=sn(i,t);if(ar(i)||Ga(i,{recursive:!0}),ar(n))throw new Error(`Plan already exists: ${t}`);Ga(n,{recursive:!0}),Ga(sn(n,"research"),{recursive:!0}),Ga(sn(n,"artifacts"),{recursive:!0});let s=`# ${t}
51
80
 
52
81
  ## Overview
53
82
 
@@ -61,14 +90,14 @@ Tip: Place file in .docs/, .plans/, docs/, plans/, or project root`)}}try{if((aw
61
90
 
62
91
  ## Notes
63
92
 
64
- `;return Sc(Ai(n,"plan.md"),r),{name:t,path:n,createdAt:new Date().toISOString(),isActive:!1}}function Wc(t,e){let i=vi();if(!i){let o=Jt(e),a=k(),c=["# Auto-generated by gemkit-cli",`# Updated at: ${new Date().toISOString()}`,"","# GEMKIT IDs",`ACTIVE_GK_SESSION_ID=${a.ACTIVE_GK_SESSION_ID||""}`,`GK_PROJECT_HASH=${a.GK_PROJECT_HASH||""}`,`PROJECT_DIR=${a.PROJECT_DIR||""}`,"","# GEMINI IDs (mapped)",`ACTIVE_GEMINI_SESSION_ID=${a.ACTIVE_GEMINI_SESSION_ID||""}`,`GEMINI_PROJECT_HASH=${a.GEMINI_PROJECT_HASH||""}`,"","# PLAN INFO",`ACTIVE_PLAN=${t}`,`SUGGESTED_PLAN=${a.SUGGESTED_PLAN||""}`,`PLAN_DATE_FORMAT=${a.PLAN_DATE_FORMAT||""}`,""].join(`
65
- `);return Sc(o,c),!0}let n=at(e);if(!Ce(n,i)){let o=Jt(e),a=k(),c=["# Auto-generated by gemkit-cli",`# Updated at: ${new Date().toISOString()}`,"","# GEMKIT IDs",`ACTIVE_GK_SESSION_ID=${a.ACTIVE_GK_SESSION_ID||""}`,`GK_PROJECT_HASH=${a.GK_PROJECT_HASH||""}`,`PROJECT_DIR=${a.PROJECT_DIR||""}`,"","# GEMINI IDs (mapped)",`ACTIVE_GEMINI_SESSION_ID=${a.ACTIVE_GEMINI_SESSION_ID||""}`,`GEMINI_PROJECT_HASH=${a.GEMINI_PROJECT_HASH||""}`,"","# PLAN INFO",`ACTIVE_PLAN=${t}`,`SUGGESTED_PLAN=${a.SUGGESTED_PLAN||""}`,`PLAN_DATE_FORMAT=${a.PLAN_DATE_FORMAT||""}`,""].join(`
66
- `);return Sc(o,c),!0}return _v(n,i,t)}function vA(t,e){let i=Ri(e),n=Ai(i,t);if(!Hn(n))return null;let r=Xn();return{name:t,path:n,createdAt:"",isActive:t===r}}function WI(){console.log(),console.log(I.default.bold(s.geminiPurple("Plan Management"))),console.log(),console.log("Usage:"),console.log(` ${s.primary("gk plan")} <subcommand> [options]`),console.log(),console.log("Subcommands:"),console.log(` ${s.primary("list")} List all plans (default)`),console.log(` ${s.primary("status")} Show active plan status`),console.log(` ${s.primary("create")} <name> Create new plan`),console.log(` ${s.primary("set")} <name> Set active plan`),console.log(` ${s.primary("info")} Get plan info from .env`),console.log(),console.log("Options:"),console.log(` ${s.dim("--json")} Output as JSON`),console.log(` ${s.dim("-a, --active")} [info] Show only ACTIVE_PLAN value`),console.log(` ${s.dim("-s, --suggested")} [info] Show only SUGGESTED_PLAN value`),console.log(` ${s.dim("-f, --format")} [info] Show only PLAN_DATE_FORMAT value`),console.log(),console.log("Examples:"),console.log(` ${s.dim("gk plan list")}`),console.log(` ${s.dim("gk plan create my-feature")}`),console.log(` ${s.dim("gk plan set my-feature")}`),console.log(` ${s.dim("gk plan info --active")}`),console.log()}function AA(t){t.command("plan [subcommand] [name]","Plan management (list, status, create, set, info)").alias("p").option("--json","[all] Output as JSON").option("-a, --active","[info] Show only ACTIVE_PLAN value").option("-s, --suggested","[info] Show only SUGGESTED_PLAN value").option("-f, --format","[info] Show only PLAN_DATE_FORMAT value").action(async(e,i,n)=>{switch(e||"list"){case"list":await MI(n);break;case"status":await CI(n);break;case"create":i||(console.log(),m.error("Plan name required"),console.log(s.dim("Usage: gk plan create <name>")),console.log(),process.exit(1)),await OI(i);break;case"set":i||(console.log(),m.error("Plan name required"),console.log(s.dim("Usage: gk plan set <name>")),console.log(),process.exit(1)),await UI(i);break;case"info":await KI(n);break;default:WI()}})}async function MI(t){let e=Yc();if(t.json){console.log(JSON.stringify(e,null,2));return}if(console.log(),console.log(I.default.bold(s.geminiPurple("Project Plans"))),console.log(),e.length===0){m.info('No plans found. Create one with "gk plan create <name>".'),console.log();return}for(let i of e){let n=i.isActive?s.success("\u2192"):s.dim("\u25CB"),r=i.isActive?s.success(" (active)"):"";console.log(` ${n} ${s.primary(i.name)}${r}`),console.log(` ${s.dim("Created:")} ${s.dim(new Date(i.createdAt).toLocaleDateString())}`)}console.log()}async function CI(t){let e=Xn();if(!e){t.json?console.log(JSON.stringify({active:!1},null,2)):(console.log(),m.info("No active plan set."),console.log());return}let i=vA(e);if(t.json){console.log(JSON.stringify(i,null,2));return}console.log(),console.log(M.line()),console.log(I.default.bold(s.geminiPurple("Active Plan"))),console.log(M.line()),console.log(),console.log(` ${s.primary(e)}`),console.log()}async function OI(t){try{let e=lA(t);console.log(),m.success(`Plan created: ${s.primary(t)}`),m.info(`Path: ${s.dim(e.path)}`),Wc(t),m.info("Set as active plan."),console.log()}catch(e){console.log(),m.error(`Failed to create plan: ${e instanceof Error?e.message:String(e)}`),console.log()}}async function UI(t){if(!Yc().some(o=>o.name===t)){console.log(),m.error(`Plan not found: ${t}`),console.log();return}if(!Wc(t)){console.log(),m.error("Failed to update session or env file"),console.log();return}let r=vi();console.log(),r&&m.success(`Session ${r.slice(0,20)}...: activePlan set to: ${s.primary(t)}`),m.info(`Environment updated: ACTIVE_PLAN = ${t}`),console.log(),m.success(`Active plan set to: ${s.primary(t)}`),console.log()}async function KI(t){let e=k(),i={activePlan:e.ACTIVE_PLAN||null,suggestedPlan:e.SUGGESTED_PLAN||null,planDateFormat:e.PLAN_DATE_FORMAT||null,gkSessionId:e.ACTIVE_GK_SESSION_ID||null,projectDir:e.PROJECT_DIR||null};if(t.active){t.json?console.log(JSON.stringify({activePlan:i.activePlan})):console.log(i.activePlan||"");return}if(t.suggested){t.json?console.log(JSON.stringify({suggestedPlan:i.suggestedPlan})):console.log(i.suggestedPlan||"");return}if(t.format){t.json?console.log(JSON.stringify({planDateFormat:i.planDateFormat})):console.log(i.planDateFormat||"");return}if(t.json)console.log(JSON.stringify({activePlan:i.activePlan,suggestedPlan:i.suggestedPlan,planDateFormat:i.planDateFormat,context:{gkSessionId:i.gkSessionId,projectDir:i.projectDir}},null,2));else{console.log(),console.log(M.line()),console.log(I.default.bold(s.geminiPurple("Plan Information"))),console.log(M.line()),console.log(),console.log(` ${s.dim("Active Plan:")} ${i.activePlan||s.dim("(not set)")}`),console.log(` ${s.dim("Suggested Plan:")} ${i.suggestedPlan||s.dim("(not set)")}`),console.log(` ${s.dim("Date Format:")} ${i.planDateFormat||s.dim("(not set)")}`),console.log(),console.log(M.line());let n=i.gkSessionId?i.gkSessionId.substring(0,25)+"...":s.dim("(no session)");console.log(` ${s.dim("Session:")} ${n}`),console.log(` ${s.dim("Project:")} ${i.projectDir||s.dim("(unknown)")}`),console.log()}}import{existsSync as VI,readFileSync as NI,readdirSync as kI}from"fs";import{join as uA}from"path";import{homedir as FI}from"os";async function mA(){let t=ko();return t?QI(t):null}function QI(t){let e=uA(FI(),".gemini","tmp",t,"chats");if(!VI(e))return null;let i=kI(e).filter(n=>n.startsWith("session-")&&n.endsWith(".json")).sort().reverse();if(i.length===0)return null;try{let n=uA(e,i[0]);return bI(n)}catch{return null}}function bI(t){try{let e=NI(t,"utf-8"),i=JSON.parse(e);if(!i.messages||i.messages.length===0)return null;let n=new Set,r=0,o=0,a=0,c,l=0;for(let z of i.messages)z.model&&n.add(z.model),z.tokens&&(r+=z.tokens.output||0,o+=z.tokens.thoughts||0,a+=z.tokens.tool||0,c=z.tokens,l++);if(!c||l===0)return null;let v=c.total||0,A=c.cached||0,u=v-r-o;u<0&&(u=0);let p={input:u,output:r,cached:A,thoughts:o,tool:a,total:v},E=null;if(i.startTime&&i.lastUpdated)try{let z=new Date(i.startTime),C=new Date(i.lastUpdated),ve=Math.floor((C.getTime()-z.getTime())/1e3),ss=Math.floor(ve/60),as=ve%60;E={seconds:ve,formatted:`${ss}m ${as}s`}}catch{}let f=Array.from(n),d=f[0]||"unknown";return{sessionId:i.sessionId,startTime:i.startTime||null,lastUpdated:i.lastUpdated||null,duration:E,model:d,modelsUsed:f,messageCount:l,tokens:p,averages:{outputPerMessage:l>0?Math.round(r/l):0,thoughtsPerMessage:l>0?Math.round(o/l):0,toolPerMessage:l>0?Math.round(a/l):0}}}catch{return null}}var Ln={"gemini-3-pro-preview":{input:2,output:12,cached:.2,thoughts:12},"gemini-3-flash-preview":{input:.5,output:3,cached:.05,thoughts:3},"gemini-2.5-pro":{input:1.25,output:10,cached:.125,thoughts:10},"gemini-2.5-pro-preview":{input:1.25,output:10,cached:.125,thoughts:10},"gemini-2.5-flash":{input:.3,output:2.5,cached:.03,thoughts:2.5},"gemini-2.5-flash-lite":{input:.1,output:.4,cached:.01,thoughts:.4},"gemini-2.0-flash":{input:.1,output:.4,cached:.01,thoughts:.4},"gemini-2.0-flash-exp":{input:.1,output:.4,cached:.01,thoughts:.4},default:{input:.5,output:3,cached:.05,thoughts:3}};function JI(t){if(Ln[t])return Ln[t];for(let e of Object.keys(Ln))if(e.includes(t)||t.includes(e))return Ln[e];return Ln.default}function Mc(t,e="default"){let i=JI(e),n=t.input-t.cached;n<0&&(n=0);let r=n/1e6*i.input,o=t.output/1e6*i.output,a=t.cached/1e6*i.cached,c=t.thoughts/1e6*i.thoughts;return{input:r,output:o,cached:a,thoughts:c,total:r+o+a+c,model:e,pricing:i}}function Ot(t){return t>=1?`$${t.toFixed(2)}`:t>=.01?`$${t.toFixed(3)}`:t>=.001?`$${t.toFixed(4)}`:`$${t.toFixed(6)}`}function Cc(t){return t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${(t/1e3).toFixed(1)}K`:String(t)}var Kt={topLeft:"\u256D",topRight:"\u256E",bottomLeft:"\u2570",bottomRight:"\u256F",horizontal:"\u2500",vertical:"\u2502",middleLeft:"\u251C",middleRight:"\u2524"};function BI(t=75){return s.dim(`${Kt.topLeft}${Kt.horizontal.repeat(t-2)}${Kt.topRight}`)}function ZI(t=75){return s.dim(`${Kt.bottomLeft}${Kt.horizontal.repeat(t-2)}${Kt.bottomRight}`)}function PI(t,e=75){let i=t.replace(/\x1b\[[0-9;]*m/g,"").length,n=Math.max(0,e-4-i);return`${s.dim(Kt.vertical)} ${t}${" ".repeat(n)} ${s.dim(Kt.vertical)}`}function Oc(t){return`
67
- ${I.default.bold(s.geminiPurple(`## ${t}`))}`}function Oe(t,e){let i=t.replace(/\x1b\[[0-9;]*m/g,"").length,n=Math.max(0,e-i);return" ".repeat(n)+t}function Ut(t,e){let i=t.replace(/\x1b\[[0-9;]*m/g,"").length,n=Math.max(0,e-i);return t+" ".repeat(n)}function qI(t){let e=[],i=t.length;for(let n=0;n<i;n++){let r=n/Math.max(i-1,1),o=Math.round(26+116*r),a=Math.round(115+-79*r),c=Math.round(232+-62*r);e.push(`\x1B[38;2;${o};${a};${c}m${t[n]}`)}return e.join("")+"\x1B[0m"}function yI(t){let e=Mc(t.tokens,t.model);console.log(),console.log(BI(75)),console.log(PI(`${qI("SESSION ANALYSIS")} ${s.dim("Cost:")} ${s.warn(Ot(e.total))}`,75)),console.log(ZI(75)),console.log(`
68
- ${s.dim("Session ID:")} ${s.accent(t.sessionId)}`),console.log(` ${s.dim("Start Time:")} ${t.startTime||"N/A"}`),console.log(` ${s.dim("Duration:")} ${s.accent(t.duration?.formatted||"N/A")}`),console.log(` ${s.dim("Model:")} ${s.geminiBlue(t.modelsUsed.join(", "))}`),console.log(` ${s.dim("Messages:")} ${s.accent(String(t.messageCount))}`),console.log(Oc("Token Breakdown")),console.log(`
69
- ${Ut("Category",10)} ${Oe("Count",14)} ${Oe("Formatted",10)}`),console.log(` ${s.dim("\u2500".repeat(10))} ${s.dim("\u2500".repeat(14))} ${s.dim("\u2500".repeat(10))}`);let i=["input","output","cached","thoughts","tool"];for(let o of i){let a=t.tokens[o],c=Oe(s.accent(a.toLocaleString()),14),l=Oe(s.accent(Cc(a)),10);console.log(` ${Ut(o,10)} ${c} ${l}`)}console.log(` ${s.dim("\u2500".repeat(10))} ${s.dim("\u2500".repeat(14))} ${s.dim("\u2500".repeat(10))}`);let n=Oe(s.success(t.tokens.total.toLocaleString()),14),r=Oe(s.success(Cc(t.tokens.total)),10);if(console.log(` ${Ut(I.default.bold("total"),10)} ${n} ${r}`),console.log(Oc("Estimated Cost")),console.log(`
70
- ${Ut("Input",12)} ${Oe(s.warn(Ot(e.input)),12)}`),console.log(` ${Ut("Output",12)} ${Oe(s.warn(Ot(e.output)),12)}`),console.log(` ${Ut("Cached",12)} ${Oe(s.warn(Ot(e.cached)),12)}`),console.log(` ${Ut("Thoughts",12)} ${Oe(s.warn(Ot(e.thoughts)),12)}`),console.log(` ${s.dim("\u2500".repeat(24))}`),console.log(` ${Ut(I.default.bold("TOTAL"),12)} ${Oe(I.default.bold(s.warn(Ot(e.total))),12)}`),t.messageCount>0){console.log(Oc("Averages"));let o=Math.round(t.tokens.total/t.messageCount),a=e.total/t.messageCount;console.log(`
71
- ${s.dim("Tokens/msg:")} ${s.accent(o.toLocaleString())}`),console.log(` ${s.dim("Cost/msg:")} ${s.warn(Ot(a))}`)}console.log()}function DI(t){let e=Mc(t.tokens,t.model);console.log(JSON.stringify({sessionId:t.sessionId,startTime:t.startTime,duration:t.duration,model:t.model,modelsUsed:t.modelsUsed,messageCount:t.messageCount,tokens:t.tokens,averages:t.averages,cost:{input:e.input,output:e.output,cached:e.cached,thoughts:e.thoughts,total:e.total}},null,2))}function EA(t){t.command("tokens","Show token usage for current session").alias("t").option("--json","Output as JSON").action(async e=>{let i=await mA();if(!i){e.json?console.log(JSON.stringify({found:!1},null,2)):(console.log(),m.info("No token usage found for current session."),console.log());return}if(e.json){DI(i);return}yI(i)})}import{existsSync as wI,readdirSync as TI}from"fs";function pA(t){let e=t.command("extension <subcommand>","Extension management").alias("ext");e.example("gk extension list # List installed extensions"),e.action(async i=>{let n=i||"list";n==="list"?await XI():(console.log(),m.error(`Unknown subcommand: ${n}`),console.log(),process.exit(1))})}async function XI(){let t=Bt();if(!wI(t)){console.log(),m.info("No extensions directory found."),console.log();return}let e=TI(t,{withFileTypes:!0}).filter(i=>i.isDirectory()).map(i=>i.name);if(e.length===0){console.log(),m.info("No extensions installed."),console.log();return}console.log(),console.log(I.default.bold(s.geminiPurple("Installed Extensions"))),console.log();for(let i of e)console.log(` ${s.success("\u2713")} ${s.primary(i)}`);console.log(),console.log(s.dim(` Total: ${e.length} extensions`)),console.log()}function IA(t){t.command("catalog [subcommand]","Catalog of skills and agents").action(async i=>{let n=i||"skills";switch(n){case"skills":await HI();break;case"agents":await LI();break;default:console.log(),m.error(`Unknown subcommand: ${n}`),console.log(),process.exit(1)}})}async function HI(){let t=Jv();if(console.log(),console.log(I.default.bold(s.geminiPurple("Available Skills"))),console.log(),t.length===0){m.info(" No skills found."),console.log();return}for(let e of t)console.log(` ${s.success("\u2713")} ${s.primary(e.name)}`);console.log(),console.log(s.dim(` Total: ${t.length} skills`)),console.log()}async function LI(){let t=Vo();if(console.log(),console.log(I.default.bold(s.geminiPurple("Available Agent Profiles"))),console.log(),t.length===0){m.info(" No agent profiles found."),console.log();return}for(let e of t)console.log(` ${s.success("\u25CF")} ${s.primary(e.name)}`),console.log(` ${s.dim(e.description)}`);console.log(),console.log(s.dim(` Total: ${t.length} profiles`)),console.log()}import{spawnSync as ye}from"child_process";import{existsSync as ce,mkdirSync as fA,writeFileSync as _I,statSync as Uc,copyFileSync as yo,readdirSync as $I}from"fs";import{join as ae,extname as Di}from"path";import{homedir as yi}from"os";var e9="clipboard-image",t9="clipboard-video",hA=[".mp4",".webm",".mov",".avi",".mkv",".gif"],i9=5;function dA(t){t.command("paste","Capture clipboard image or video for Gemini analysis").alias("p").option("--image","Capture image from clipboard (default)").option("--video","Capture video from clipboard or recent recordings").option("--format <fmt>","Image format (png, jpg)",{default:"png"}).option("--json","Output as JSON").action(async e=>{let i=e.video===!0,n=i?l9():r9(e),r=i?m9(n):c9(n);if(e.json)console.log(JSON.stringify(r,null,2));else{if(console.log(),r.success){let o=i?"Video":"Image";console.log(`${s.success("\u2713")} ${o} captured successfully`),console.log(),console.log(` ${s.dim("Path:")} ${s.primary(String(r.path))}`),console.log(` ${s.dim("Size:")} ${r.size}`),i&&r.format&&console.log(` ${s.dim("Format:")} ${r.format}`),r.sourceType&&r.sourceType!=="clipboard"&&console.log(` ${s.dim("Source:")} ${r.sourceType}`),console.log(` ${s.dim("Platform:")} ${r.platform}`)}else console.error(`${s.error("\u2717")} ${r.error}`),r.suggestion&&console.log(` ${s.dim("Hint:")} ${r.suggestion}`);console.log()}process.exit(n.success?0:1)})}function RA(){let t=ko();if(t){let i=ae(yi(),".gemini","tmp",t);return ce(i)||fA(i,{recursive:!0}),i}let e=ae(process.cwd(),".gemini","tmp","clipboard");return ce(e)||fA(e,{recursive:!0}),e}function n9(t="png"){let e=Date.now(),i=Math.random().toString(36).substring(2,8);return`${e9}-${e}-${i}.${t}`}function Do(t=".mp4"){let e=Date.now(),i=Math.random().toString(36).substring(2,8),n=hA.includes(t.toLowerCase())?t:".mp4";return`${t9}-${e}-${i}${n}`}function Kc(t){let e=Di(t).toLowerCase();return hA.includes(e)}function zA(t,e){for(let i of t)if(ce(i))try{let n=$I(i).filter(r=>Kc(r)).map(r=>{let o=ae(i,r);return{name:r,path:o,mtime:Uc(o).mtime}}).sort((r,o)=>o.mtime.getTime()-r.mtime.getTime());if(n.length>0){let r=n[0];if((Date.now()-r.mtime.getTime())/6e4<=i9){let a=Di(r.path),c=Do(a),l=ae(e,c);if(yo(r.path,l),ce(l))return{success:!0,path:l,sourcePath:r.path,sourceType:"recent-recording"}}}}catch{}return null}function r9(t){let e=t.format||"png",i=process.platform,n=RA(),r=n9(e),o=ae(n,r),a;switch(i){case"win32":a=o9(o);break;case"darwin":a=s9(o);break;case"linux":a=a9(o);break;default:a={success:!1,error:`Unsupported platform: ${i}`}}return a.platform=i,a.tempDir=n,a}function o9(t){let e=t.replace(/\\/g,"\\\\"),i=`
93
+ `;return Uu(sn(n,"plan.md"),s),{name:t,path:n,createdAt:new Date().toISOString(),isActive:!1}}function ku(t,e){let i=nn();if(!i){let r=Wi(e),o=B(),c=["# Auto-generated by gemkit-cli",`# Updated at: ${new Date().toISOString()}`,"","# GEMKIT IDs",`ACTIVE_GK_SESSION_ID=${o.ACTIVE_GK_SESSION_ID||""}`,`GK_PROJECT_HASH=${o.GK_PROJECT_HASH||""}`,`PROJECT_DIR=${o.PROJECT_DIR||""}`,"","# GEMINI IDs (mapped)",`ACTIVE_GEMINI_SESSION_ID=${o.ACTIVE_GEMINI_SESSION_ID||""}`,`GEMINI_PROJECT_HASH=${o.GEMINI_PROJECT_HASH||""}`,"","# PLAN INFO",`ACTIVE_PLAN=${t}`,`SUGGESTED_PLAN=${o.SUGGESTED_PLAN||""}`,`PLAN_DATE_FORMAT=${o.PLAN_DATE_FORMAT||""}`,""].join(`
94
+ `);return Uu(r,c),!0}let n=Zt(e);if(!nt(n,i)){let r=Wi(e),o=B(),c=["# Auto-generated by gemkit-cli",`# Updated at: ${new Date().toISOString()}`,"","# GEMKIT IDs",`ACTIVE_GK_SESSION_ID=${o.ACTIVE_GK_SESSION_ID||""}`,`GK_PROJECT_HASH=${o.GK_PROJECT_HASH||""}`,`PROJECT_DIR=${o.PROJECT_DIR||""}`,"","# GEMINI IDs (mapped)",`ACTIVE_GEMINI_SESSION_ID=${o.ACTIVE_GEMINI_SESSION_ID||""}`,`GEMINI_PROJECT_HASH=${o.GEMINI_PROJECT_HASH||""}`,"","# PLAN INFO",`ACTIVE_PLAN=${t}`,`SUGGESTED_PLAN=${o.SUGGESTED_PLAN||""}`,`PLAN_DATE_FORMAT=${o.PLAN_DATE_FORMAT||""}`,""].join(`
95
+ `);return Uu(r,c),!0}return Np(n,i,t)}function $p(t,e){let i=vn(e),n=sn(i,t);if(!ar(n))return null;let s=or();return{name:t,path:n,createdAt:"",isActive:t===s}}it();function fE(){console.log(),console.log(h.default.bold(a.geminiPurple("Plan Management"))),console.log(),console.log("Usage:"),console.log(` ${a.primary("gk plan")} <subcommand> [options]`),console.log(),console.log("Subcommands:"),console.log(` ${a.primary("list")} List all plans (default)`),console.log(` ${a.primary("status")} Show active plan status`),console.log(` ${a.primary("create")} <name> Create new plan`),console.log(` ${a.primary("set")} <name> Set active plan`),console.log(` ${a.primary("info")} Get plan info from .env`),console.log(),console.log("Options:"),console.log(` ${a.dim("--json")} Output as JSON`),console.log(` ${a.dim("-a, --active")} [info] Show only ACTIVE_PLAN value`),console.log(` ${a.dim("-s, --suggested")} [info] Show only SUGGESTED_PLAN value`),console.log(` ${a.dim("-f, --format")} [info] Show only PLAN_DATE_FORMAT value`),console.log(),console.log("Examples:"),console.log(` ${a.dim("gk plan list")}`),console.log(` ${a.dim("gk plan create my-feature")}`),console.log(` ${a.dim("gk plan set my-feature")}`),console.log(` ${a.dim("gk plan info --active")}`),console.log()}function eA(t){t.command("plan [subcommand] [name]","Plan management (list, status, create, set, info)").alias("p").option("--json","[all] Output as JSON").option("-a, --active","[info] Show only ACTIVE_PLAN value").option("-s, --suggested","[info] Show only SUGGESTED_PLAN value").option("-f, --format","[info] Show only PLAN_DATE_FORMAT value").action(async(e,i,n)=>{switch(e||"list"){case"list":await hE(n);break;case"status":await gE(n);break;case"create":i||(console.log(),v.error("Plan name required"),console.log(a.dim("Usage: gk plan create <name>")),console.log(),process.exit(1)),await IE(i);break;case"set":i||(console.log(),v.error("Plan name required"),console.log(a.dim("Usage: gk plan set <name>")),console.log(),process.exit(1)),await EE(i);break;case"info":await RE(n);break;default:fE()}})}async function hE(t){let e=Ku();if(t.json){console.log(JSON.stringify(e,null,2));return}if(console.log(),console.log(h.default.bold(a.geminiPurple("Project Plans"))),console.log(),e.length===0){v.info('No plans found. Create one with "gk plan create <name>".'),console.log();return}for(let i of e){let n=i.isActive?a.success("\u2192"):a.dim("\u25CB"),s=i.isActive?a.success(" (active)"):"";console.log(` ${n} ${a.primary(i.name)}${s}`),console.log(` ${a.dim("Created:")} ${a.dim(new Date(i.createdAt).toLocaleDateString())}`)}console.log()}async function gE(t){let e=or();if(!e){t.json?console.log(JSON.stringify({active:!1},null,2)):(console.log(),v.info("No active plan set."),console.log());return}let i=$p(e);if(t.json){console.log(JSON.stringify(i,null,2));return}console.log(),console.log(G.line()),console.log(h.default.bold(a.geminiPurple("Active Plan"))),console.log(G.line()),console.log(),console.log(` ${a.primary(e)}`),console.log()}async function IE(t){try{let e=_p(t);console.log(),v.success(`Plan created: ${a.primary(t)}`),v.info(`Path: ${a.dim(e.path)}`),ku(t),v.info("Set as active plan."),console.log()}catch(e){console.log(),v.error(`Failed to create plan: ${e instanceof Error?e.message:String(e)}`),console.log()}}async function EE(t){if(!Ku().some(r=>r.name===t)){console.log(),v.error(`Plan not found: ${t}`),console.log();return}if(!ku(t)){console.log(),v.error("Failed to update session or env file"),console.log();return}let s=nn();console.log(),s&&v.success(`Session ${s.slice(0,20)}...: activePlan set to: ${a.primary(t)}`),v.info(`Environment updated: ACTIVE_PLAN = ${t}`),console.log(),v.success(`Active plan set to: ${a.primary(t)}`),console.log()}async function RE(t){let e=B(),i={activePlan:e.ACTIVE_PLAN||null,suggestedPlan:e.SUGGESTED_PLAN||null,planDateFormat:e.PLAN_DATE_FORMAT||null,gkSessionId:e.ACTIVE_GK_SESSION_ID||null,projectDir:e.PROJECT_DIR||null};if(t.active){t.json?console.log(JSON.stringify({activePlan:i.activePlan})):console.log(i.activePlan||"");return}if(t.suggested){t.json?console.log(JSON.stringify({suggestedPlan:i.suggestedPlan})):console.log(i.suggestedPlan||"");return}if(t.format){t.json?console.log(JSON.stringify({planDateFormat:i.planDateFormat})):console.log(i.planDateFormat||"");return}if(t.json)console.log(JSON.stringify({activePlan:i.activePlan,suggestedPlan:i.suggestedPlan,planDateFormat:i.planDateFormat,context:{gkSessionId:i.gkSessionId,projectDir:i.projectDir}},null,2));else{console.log(),console.log(G.line()),console.log(h.default.bold(a.geminiPurple("Plan Information"))),console.log(G.line()),console.log(),console.log(` ${a.dim("Active Plan:")} ${i.activePlan||a.dim("(not set)")}`),console.log(` ${a.dim("Suggested Plan:")} ${i.suggestedPlan||a.dim("(not set)")}`),console.log(` ${a.dim("Date Format:")} ${i.planDateFormat||a.dim("(not set)")}`),console.log(),console.log(G.line());let n=i.gkSessionId?i.gkSessionId.substring(0,25)+"...":a.dim("(no session)");console.log(` ${a.dim("Session:")} ${n}`),console.log(` ${a.dim("Project:")} ${i.projectDir||a.dim("(unknown)")}`),console.log()}}it();import{existsSync as zE,readFileSync as jE,readdirSync as xE}from"fs";import{join as tA}from"path";import{homedir as SE}from"os";async function iA(){let t=fa();return t?GE(t):null}function GE(t){let e=tA(SE(),".gemini","tmp",t,"chats");if(!zE(e))return null;let i=xE(e).filter(n=>n.startsWith("session-")&&n.endsWith(".json")).sort().reverse();if(i.length===0)return null;try{let n=tA(e,i[0]);return ME(n)}catch{return null}}function ME(t){try{let e=jE(t,"utf-8"),i=JSON.parse(e);if(!i.messages||i.messages.length===0)return null;let n=new Set,s=0,r=0,o=0,c,l=0;for(let E of i.messages)E.model&&n.add(E.model),E.tokens&&(s+=E.tokens.output||0,r+=E.tokens.thoughts||0,o+=E.tokens.tool||0,c=E.tokens,l++);if(!c||l===0)return null;let u=c.total||0,m=c.cached||0,p=u-s-r;p<0&&(p=0);let d={input:p,output:s,cached:m,thoughts:r,tool:o,total:u},A=null;if(i.startTime&&i.lastUpdated)try{let E=new Date(i.startTime),J=new Date(i.lastUpdated),M=Math.floor((J.getTime()-E.getTime())/1e3),rt=Math.floor(M/60),y=M%60;A={seconds:M,formatted:`${rt}m ${y}s`}}catch{}let f=Array.from(n),g=f[0]||"unknown";return{sessionId:i.sessionId,startTime:i.startTime||null,lastUpdated:i.lastUpdated||null,duration:A,model:g,modelsUsed:f,messageCount:l,tokens:d,averages:{outputPerMessage:l>0?Math.round(s/l):0,thoughtsPerMessage:l>0?Math.round(r/l):0,toolPerMessage:l>0?Math.round(o/l):0}}}catch{return null}}var cr={"gemini-3-pro-preview":{input:2,output:12,cached:.2,thoughts:12},"gemini-3-flash-preview":{input:.5,output:3,cached:.05,thoughts:3},"gemini-2.5-pro":{input:1.25,output:10,cached:.125,thoughts:10},"gemini-2.5-pro-preview":{input:1.25,output:10,cached:.125,thoughts:10},"gemini-2.5-flash":{input:.3,output:2.5,cached:.03,thoughts:2.5},"gemini-2.5-flash-lite":{input:.1,output:.4,cached:.01,thoughts:.4},"gemini-2.0-flash":{input:.1,output:.4,cached:.01,thoughts:.4},"gemini-2.0-flash-exp":{input:.1,output:.4,cached:.01,thoughts:.4},default:{input:.5,output:3,cached:.05,thoughts:3}};function YE(t){if(cr[t])return cr[t];for(let e of Object.keys(cr))if(e.includes(t)||t.includes(e))return cr[e];return cr.default}function Vu(t,e="default"){let i=YE(e),n=t.input-t.cached;n<0&&(n=0);let s=n/1e6*i.input,r=t.output/1e6*i.output,o=t.cached/1e6*i.cached,c=t.thoughts/1e6*i.thoughts;return{input:s,output:r,cached:o,thoughts:c,total:s+r+o+c,model:e,pricing:i}}function Ei(t){return t>=1?`$${t.toFixed(2)}`:t>=.01?`$${t.toFixed(3)}`:t>=.001?`$${t.toFixed(4)}`:`$${t.toFixed(6)}`}function Nu(t){return t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${(t/1e3).toFixed(1)}K`:String(t)}var zi={topLeft:"\u256D",topRight:"\u256E",bottomLeft:"\u2570",bottomRight:"\u256F",horizontal:"\u2500",vertical:"\u2502",middleLeft:"\u251C",middleRight:"\u2524"};function WE(t=75){return a.dim(`${zi.topLeft}${zi.horizontal.repeat(t-2)}${zi.topRight}`)}function CE(t=75){return a.dim(`${zi.bottomLeft}${zi.horizontal.repeat(t-2)}${zi.bottomRight}`)}function OE(t,e=75){let i=t.replace(/\x1b\[[0-9;]*m/g,"").length,n=Math.max(0,e-4-i);return`${a.dim(zi.vertical)} ${t}${" ".repeat(n)} ${a.dim(zi.vertical)}`}function Fu(t){return`
96
+ ${h.default.bold(a.geminiPurple(`## ${t}`))}`}function st(t,e){let i=t.replace(/\x1b\[[0-9;]*m/g,"").length,n=Math.max(0,e-i);return" ".repeat(n)+t}function Ri(t,e){let i=t.replace(/\x1b\[[0-9;]*m/g,"").length,n=Math.max(0,e-i);return t+" ".repeat(n)}function UE(t){let e=[],i=t.length;for(let n=0;n<i;n++){let s=n/Math.max(i-1,1),r=Math.round(26+116*s),o=Math.round(115+-79*s),c=Math.round(232+-62*s);e.push(`\x1B[38;2;${r};${o};${c}m${t[n]}`)}return e.join("")+"\x1B[0m"}function KE(t){let e=Vu(t.tokens,t.model);console.log(),console.log(WE(75)),console.log(OE(`${UE("SESSION ANALYSIS")} ${a.dim("Cost:")} ${a.warn(Ei(e.total))}`,75)),console.log(CE(75)),console.log(`
97
+ ${a.dim("Session ID:")} ${a.accent(t.sessionId)}`),console.log(` ${a.dim("Start Time:")} ${t.startTime||"N/A"}`),console.log(` ${a.dim("Duration:")} ${a.accent(t.duration?.formatted||"N/A")}`),console.log(` ${a.dim("Model:")} ${a.geminiBlue(t.modelsUsed.join(", "))}`),console.log(` ${a.dim("Messages:")} ${a.accent(String(t.messageCount))}`),console.log(Fu("Token Breakdown")),console.log(`
98
+ ${Ri("Category",10)} ${st("Count",14)} ${st("Formatted",10)}`),console.log(` ${a.dim("\u2500".repeat(10))} ${a.dim("\u2500".repeat(14))} ${a.dim("\u2500".repeat(10))}`);let i=["input","output","cached","thoughts","tool"];for(let r of i){let o=t.tokens[r],c=st(a.accent(o.toLocaleString()),14),l=st(a.accent(Nu(o)),10);console.log(` ${Ri(r,10)} ${c} ${l}`)}console.log(` ${a.dim("\u2500".repeat(10))} ${a.dim("\u2500".repeat(14))} ${a.dim("\u2500".repeat(10))}`);let n=st(a.success(t.tokens.total.toLocaleString()),14),s=st(a.success(Nu(t.tokens.total)),10);if(console.log(` ${Ri(h.default.bold("total"),10)} ${n} ${s}`),console.log(Fu("Estimated Cost")),console.log(`
99
+ ${Ri("Input",12)} ${st(a.warn(Ei(e.input)),12)}`),console.log(` ${Ri("Output",12)} ${st(a.warn(Ei(e.output)),12)}`),console.log(` ${Ri("Cached",12)} ${st(a.warn(Ei(e.cached)),12)}`),console.log(` ${Ri("Thoughts",12)} ${st(a.warn(Ei(e.thoughts)),12)}`),console.log(` ${a.dim("\u2500".repeat(24))}`),console.log(` ${Ri(h.default.bold("TOTAL"),12)} ${st(h.default.bold(a.warn(Ei(e.total))),12)}`),t.messageCount>0){console.log(Fu("Averages"));let r=Math.round(t.tokens.total/t.messageCount),o=e.total/t.messageCount;console.log(`
100
+ ${a.dim("Tokens/msg:")} ${a.accent(r.toLocaleString())}`),console.log(` ${a.dim("Cost/msg:")} ${a.warn(Ei(o))}`)}console.log()}function kE(t){let e=Vu(t.tokens,t.model);console.log(JSON.stringify({sessionId:t.sessionId,startTime:t.startTime,duration:t.duration,model:t.model,modelsUsed:t.modelsUsed,messageCount:t.messageCount,tokens:t.tokens,averages:t.averages,cost:{input:e.input,output:e.output,cached:e.cached,thoughts:e.thoughts,total:e.total}},null,2))}function nA(t){t.command("tokens","Show token usage for current session").alias("t").option("--json","Output as JSON").action(async e=>{let i=await iA();if(!i){e.json?console.log(JSON.stringify({found:!1},null,2)):(console.log(),v.info("No token usage found for current session."),console.log());return}if(e.json){kE(i);return}KE(i)})}k();import{existsSync as VE,readdirSync as NE}from"fs";function sA(t){let e=t.command("extension <subcommand>","Extension management").alias("ext");e.example("gk extension list # List installed extensions"),e.action(async i=>{let n=i||"list";n==="list"?await FE():(console.log(),v.error(`Unknown subcommand: ${n}`),console.log(),process.exit(1))})}async function FE(){let t=Ci();if(!VE(t)){console.log(),v.info("No extensions directory found."),console.log();return}let e=NE(t,{withFileTypes:!0}).filter(i=>i.isDirectory()).map(i=>i.name);if(e.length===0){console.log(),v.info("No extensions installed."),console.log();return}console.log(),console.log(h.default.bold(a.geminiPurple("Installed Extensions"))),console.log();for(let i of e)console.log(` ${a.success("\u2713")} ${a.primary(i)}`);console.log(),console.log(a.dim(` Total: ${e.length} extensions`)),console.log()}Xs();Ls();Nn();function rA(t){t.command("catalog [subcommand]","Catalog of skills and agents").action(async i=>{let n=i||"skills";switch(n){case"skills":await bE();break;case"agents":await PE();break;default:console.log(),v.error(`Unknown subcommand: ${n}`),console.log(),process.exit(1)}})}async function bE(){let t=Zv();if(console.log(),console.log(h.default.bold(a.geminiPurple("Available Skills"))),console.log(),t.length===0){v.info(" No skills found."),console.log();return}for(let e of t)console.log(` ${a.success("\u2713")} ${a.primary(e.name)}`);console.log(),console.log(a.dim(` Total: ${t.length} skills`)),console.log()}async function PE(){let t=qo();if(console.log(),console.log(h.default.bold(a.geminiPurple("Available Agent Profiles"))),console.log(),t.length===0){v.info(" No agent profiles found."),console.log();return}for(let e of t)console.log(` ${a.success("\u25CF")} ${a.primary(e.name)}`),console.log(` ${a.dim(e.description)}`);console.log(),console.log(a.dim(` Total: ${t.length} profiles`)),console.log()}it();import{spawnSync as zt}from"child_process";import{existsSync as We,mkdirSync as oA,writeFileSync as QE,statSync as bu,copyFileSync as Ma,readdirSync as BE}from"fs";import{join as Ye,extname as wn}from"path";import{homedir as qn}from"os";var JE="clipboard-image",ZE="clipboard-video",aA=[".mp4",".webm",".mov",".avi",".mkv",".gif"],yE=5;function cA(t){t.command("paste","Capture clipboard image or video for Gemini analysis").alias("p").option("--image","Capture image from clipboard (default)").option("--video","Capture video from clipboard or recent recordings").option("--format <fmt>","Image format (png, jpg)",{default:"png"}).option("--json","Output as JSON").action(async e=>{let i=e.video===!0,n=i?LE():wE(e),s=i?t9(n):HE(n);if(e.json)console.log(JSON.stringify(s,null,2));else{if(console.log(),s.success){let r=i?"Video":"Image";console.log(`${a.success("\u2713")} ${r} captured successfully`),console.log(),console.log(` ${a.dim("Path:")} ${a.primary(String(s.path))}`),console.log(` ${a.dim("Size:")} ${s.size}`),i&&s.format&&console.log(` ${a.dim("Format:")} ${s.format}`),s.sourceType&&s.sourceType!=="clipboard"&&console.log(` ${a.dim("Source:")} ${s.sourceType}`),console.log(` ${a.dim("Platform:")} ${s.platform}`)}else console.error(`${a.error("\u2717")} ${s.error}`),s.suggestion&&console.log(` ${a.dim("Hint:")} ${s.suggestion}`);console.log()}process.exit(n.success?0:1)})}function lA(){let t=fa();if(t){let i=Ye(qn(),".gemini","tmp",t);return We(i)||oA(i,{recursive:!0}),i}let e=Ye(process.cwd(),".gemini","tmp","clipboard");return We(e)||oA(e,{recursive:!0}),e}function qE(t="png"){let e=Date.now(),i=Math.random().toString(36).substring(2,8);return`${JE}-${e}-${i}.${t}`}function Ya(t=".mp4"){let e=Date.now(),i=Math.random().toString(36).substring(2,8),n=aA.includes(t.toLowerCase())?t:".mp4";return`${ZE}-${e}-${i}${n}`}function Pu(t){let e=wn(t).toLowerCase();return aA.includes(e)}function uA(t,e){for(let i of t)if(We(i))try{let n=BE(i).filter(s=>Pu(s)).map(s=>{let r=Ye(i,s);return{name:s,path:r,mtime:bu(r).mtime}}).sort((s,r)=>r.mtime.getTime()-s.mtime.getTime());if(n.length>0){let s=n[0];if((Date.now()-s.mtime.getTime())/6e4<=yE){let o=wn(s.path),c=Ya(o),l=Ye(e,c);if(Ma(s.path,l),We(l))return{success:!0,path:l,sourcePath:s.path,sourceType:"recent-recording"}}}}catch{}return null}function wE(t){let e=t.format||"png",i=process.platform,n=lA(),s=qE(e),r=Ye(n,s),o;switch(i){case"win32":o=DE(r);break;case"darwin":o=TE(r);break;case"linux":o=XE(r);break;default:o={success:!1,error:`Unsupported platform: ${i}`}}return o.platform=i,o.tempDir=n,o}function DE(t){let e=t.replace(/\\/g,"\\\\"),i=`
72
101
  Add-Type -AssemblyName System.Windows.Forms
73
102
  Add-Type -AssemblyName System.Drawing
74
103
  $clipboard = [System.Windows.Forms.Clipboard]::GetImage()
@@ -78,7 +107,7 @@ if (-not (Test-Path $dir)) { New-Item -ItemType Directory -Path $dir -Force | Ou
78
107
  $clipboard.Save("${e}", [System.Drawing.Imaging.ImageFormat]::Png)
79
108
  $clipboard.Dispose()
80
109
  Write-Output "SUCCESS"
81
- `.trim(),n=ye("powershell",["-NoProfile","-NonInteractive","-Command",i],{encoding:"utf-8",windowsHide:!0});return n.stderr?.includes("NO_IMAGE")?{success:!1,error:"No image in clipboard. Copy an image first."}:n.status!==0?{success:!1,error:`Failed: ${n.stderr||n.stdout}`.trim()}:ce(t)?{success:!0,path:t}:{success:!1,error:"File not created"}}function s9(t){return ye("which",["pngpaste"],{encoding:"utf-8"}).status===0&&ye("pngpaste",[t],{encoding:"utf-8"}).status===0&&ce(t)?{success:!0,path:t}:{success:!1,error:"No image or pngpaste failed",suggestion:"brew install pngpaste"}}function a9(t){if(ye("which",["xclip"],{encoding:"utf-8"}).status!==0)return{success:!1,error:"xclip not installed",suggestion:"apt install xclip"};let i=ye("xclip",["-selection","clipboard","-t","TARGETS","-o"],{encoding:"utf-8"});if(!i.stdout?.includes("image/png")&&!i.stdout?.includes("image/jpeg"))return{success:!1,error:"No image in clipboard"};let n=i.stdout.includes("image/png")?"image/png":"image/jpeg",r=ye("xclip",["-selection","clipboard","-t",n,"-o"],{encoding:"buffer"});return r.status!==0||!r.stdout?.length?{success:!1,error:"Failed to read clipboard"}:(_I(t,r.stdout),ce(t)?{success:!0,path:t}:{success:!1,error:"Save failed"})}function c9(t){if(t.success&&t.path){let e=Uc(t.path);return{success:!0,message:"Image captured",path:t.path,size:`${(e.size/1024).toFixed(1)} KB`,platform:t.platform}}return{success:!1,error:t.error,suggestion:t.suggestion,platform:t.platform}}function l9(){let t=process.platform,e=RA(),i;switch(t){case"win32":i=v9(e);break;case"darwin":i=A9(e);break;case"linux":i=u9(e);break;default:i={success:!1,error:`Unsupported platform: ${t}`,suggestion:"This tool supports Windows, macOS, and Linux only"}}return i.platform=t,i.tempDir=e,i}function v9(t){let e=`
110
+ `.trim(),n=zt("powershell",["-NoProfile","-NonInteractive","-Command",i],{encoding:"utf-8",windowsHide:!0});return n.stderr?.includes("NO_IMAGE")?{success:!1,error:"No image in clipboard. Copy an image first."}:n.status!==0?{success:!1,error:`Failed: ${n.stderr||n.stdout}`.trim()}:We(t)?{success:!0,path:t}:{success:!1,error:"File not created"}}function TE(t){return zt("which",["pngpaste"],{encoding:"utf-8"}).status===0&&zt("pngpaste",[t],{encoding:"utf-8"}).status===0&&We(t)?{success:!0,path:t}:{success:!1,error:"No image or pngpaste failed",suggestion:"brew install pngpaste"}}function XE(t){if(zt("which",["xclip"],{encoding:"utf-8"}).status!==0)return{success:!1,error:"xclip not installed",suggestion:"apt install xclip"};let i=zt("xclip",["-selection","clipboard","-t","TARGETS","-o"],{encoding:"utf-8"});if(!i.stdout?.includes("image/png")&&!i.stdout?.includes("image/jpeg"))return{success:!1,error:"No image in clipboard"};let n=i.stdout.includes("image/png")?"image/png":"image/jpeg",s=zt("xclip",["-selection","clipboard","-t",n,"-o"],{encoding:"buffer"});return s.status!==0||!s.stdout?.length?{success:!1,error:"Failed to read clipboard"}:(QE(t,s.stdout),We(t)?{success:!0,path:t}:{success:!1,error:"Save failed"})}function HE(t){if(t.success&&t.path){let e=bu(t.path);return{success:!0,message:"Image captured",path:t.path,size:`${(e.size/1024).toFixed(1)} KB`,platform:t.platform}}return{success:!1,error:t.error,suggestion:t.suggestion,platform:t.platform}}function LE(){let t=process.platform,e=lA(),i;switch(t){case"win32":i=_E(e);break;case"darwin":i=$E(e);break;case"linux":i=e9(e);break;default:i={success:!1,error:`Unsupported platform: ${t}`,suggestion:"This tool supports Windows, macOS, and Linux only"}}return i.platform=t,i.tempDir=e,i}function _E(t){let e=`
82
111
  Add-Type -AssemblyName System.Windows.Forms
83
112
 
84
113
  # Try to get file drop list from clipboard (copied files)
@@ -145,7 +174,7 @@ if (Test-Path $videosFolder) {
145
174
 
146
175
  Write-Error "NO_VIDEO_FOUND"
147
176
  exit 1
148
- `.trim();try{let i=ye("powershell",["-NoProfile","-NonInteractive","-Command",e],{encoding:"utf-8",windowsHide:!0,timeout:1e4});if(i.error)return{success:!1,error:`PowerShell error: ${i.error.message}`};if(i.stderr?.includes("NO_VIDEO_FOUND"))return{success:!1,error:"No video found in clipboard or recent recordings.",suggestion:"Copy a video file or record with Snipping Tool (Win+Shift+R) first."};if(i.status!==0)return{success:!1,error:`Failed to capture: ${(i.stderr||i.stdout||"Unknown PowerShell error").trim()}`};let n=i.stdout.trim(),r=null,o="clipboard";if(n.startsWith("FILE:")?(r=n.substring(5),o="clipboard"):n.startsWith("SNIP:")&&(r=n.substring(5),o="snipping-tool"),!r||!ce(r))return{success:!1,error:"Video file not found or inaccessible"};let a=Di(r),c=Do(a),l=ae(t,c);return yo(r,l),ce(l)?{success:!0,path:l,sourcePath:r,sourceType:o}:{success:!1,error:"Failed to copy video file"}}catch(i){return{success:!1,error:`Windows video capture error: ${i instanceof Error?i.message:String(i)}`}}}function A9(t){let e=`
177
+ `.trim();try{let i=zt("powershell",["-NoProfile","-NonInteractive","-Command",e],{encoding:"utf-8",windowsHide:!0,timeout:1e4});if(i.error)return{success:!1,error:`PowerShell error: ${i.error.message}`};if(i.stderr?.includes("NO_VIDEO_FOUND"))return{success:!1,error:"No video found in clipboard or recent recordings.",suggestion:"Copy a video file or record with Snipping Tool (Win+Shift+R) first."};if(i.status!==0)return{success:!1,error:`Failed to capture: ${(i.stderr||i.stdout||"Unknown PowerShell error").trim()}`};let n=i.stdout.trim(),s=null,r="clipboard";if(n.startsWith("FILE:")?(s=n.substring(5),r="clipboard"):n.startsWith("SNIP:")&&(s=n.substring(5),r="snipping-tool"),!s||!We(s))return{success:!1,error:"Video file not found or inaccessible"};let o=wn(s),c=Ya(o),l=Ye(t,c);return Ma(s,l),We(l)?{success:!0,path:l,sourcePath:s,sourceType:r}:{success:!1,error:"Failed to copy video file"}}catch(i){return{success:!1,error:`Windows video capture error: ${i instanceof Error?i.message:String(i)}`}}}function $E(t){let e=`
149
178
  use scripting additions
150
179
 
151
180
  set thePath to ""
@@ -167,9 +196,9 @@ if thePath is not "" then
167
196
  else
168
197
  return "NO_FILE"
169
198
  end if
170
- `.trim();try{let i=ye("osascript",["-e",e],{encoding:"utf-8",timeout:5e3});if(i.stdout&&i.stdout.trim()!=="NO_FILE"){let r=i.stdout.trim();if(!Kc(r))return{success:!1,error:"Clipboard does not contain a video file",suggestion:"Copy a video file (.mp4, .mov, .webm) to clipboard first"};if(!ce(r))return{success:!1,error:"Video file not found"};let o=Di(r),a=Do(o),c=ae(t,a);if(yo(r,c),ce(c))return{success:!0,path:c,sourcePath:r,sourceType:"clipboard"}}let n=zA([ae(yi(),"Movies"),ae(yi(),"Desktop")],t);return n||{success:!1,error:"No video in clipboard or recent recordings",suggestion:"Copy a video file or use Cmd+Shift+5 to record screen"}}catch(i){return{success:!1,error:`macOS video capture error: ${i instanceof Error?i.message:String(i)}`}}}function u9(t){try{if(ye("which",["xclip"],{encoding:"utf-8"}).status!==0)return{success:!1,error:"xclip is not installed",suggestion:"Install with: sudo apt install xclip"};let i=ye("xclip",["-selection","clipboard","-t","text/uri-list","-o"],{encoding:"utf-8",timeout:5e3});if(i.status===0&&i.stdout){let r=i.stdout.trim(),o=r;if(r.startsWith("file://")&&(o=decodeURIComponent(r.replace("file://",""))),Kc(o)&&ce(o)){let a=Di(o),c=Do(a),l=ae(t,c);if(yo(o,l),ce(l))return{success:!0,path:l,sourcePath:o,sourceType:"clipboard"}}}let n=zA([ae(yi(),"Videos"),ae(yi(),"Screencasts"),ae(yi(),"Desktop")],t);return n||{success:!1,error:"No video in clipboard or recent recordings",suggestion:"Copy a video file or use a screen recorder first"}}catch(e){return{success:!1,error:`Linux video capture error: ${e instanceof Error?e.message:String(e)}`}}}function m9(t){if(t.success&&t.path){let i=(Uc(t.path).size/(1024*1024)).toFixed(2),n=Di(t.path).toLowerCase();return{success:!0,message:`Video captured from ${t.sourceType}`,path:t.path,sourcePath:t.sourcePath,sourceType:t.sourceType,size:`${i} MB`,format:n.substring(1).toUpperCase(),platform:t.platform}}return{success:!1,error:t.error,suggestion:t.suggestion||"Record a video with Snipping Tool (Win+Shift+R) or copy a video file to clipboard",platform:t.platform}}var gA={"claude-3-opus":"gemini-2.5-pro","claude-3-sonnet":"gemini-2.5-flash","claude-3-haiku":"gemini-2.5-flash","claude-3.5-sonnet":"gemini-2.5-pro","claude-3.5-haiku":"gemini-2.5-flash","gemini-2.5-pro":"gemini-2.5-pro","gemini-2.5-flash":"gemini-2.5-flash","gemini-3-flash-preview":"gemini-3-flash-preview"};import{existsSync as le,readFileSync as wo,readdirSync as To,mkdirSync as kc,writeFileSync as jA,copyFileSync as Vc,statSync as xA}from"fs";import{join as W}from"path";var E9=".claude/skills",p9=".gemini/extensions",I9=".claude/agents",f9=".gemini/agents";function Fc(t){let e=t.match(/^---\r?\n([\s\S]*?)\r?\n---/);if(!e)return null;let i={name:"",description:""},n=e[1].split(/\r?\n/);for(let r of n){let o=r.indexOf(":");if(o===-1)continue;let a=r.slice(0,o).trim(),c=r.slice(o+1).trim();(c.startsWith('"')&&c.endsWith('"')||c.startsWith("'")&&c.endsWith("'"))&&(c=c.slice(1,-1)),i[a]=c}return i}function Xo(t=process.cwd()){return W(t,E9)}function Ho(t=process.cwd()){return W(t,p9)}function Lo(t=process.cwd()){let e=Xo(t);if(!le(e))return[];let i=[];try{let n=To(e,{withFileTypes:!0}).filter(r=>r.isDirectory()).map(r=>r.name);for(let r of n){let o=W(e,r),a=W(o,"SKILL.md"),c=W(o,"references"),l=le(a),v=le(c)&&xA(c).isDirectory(),A;if(l)try{let u=wo(a,"utf-8");A=Fc(u)?.description}catch{}i.push({name:r,path:o,hasSkillMd:l,hasReferences:v,description:A})}}catch{}return i.sort((n,r)=>n.name.localeCompare(r.name))}function Qc(t,e=process.cwd()){let i=W(Ho(e),t);return le(i)}function h9(t,e){let i=["SKILL.md"];return e&&i.push("references/*.md"),{name:t.name||"",version:"1.0.0",description:t.description||"",license:"MIT",contextFileName:i}}function Nc(t,e,i){le(e)||(kc(e,{recursive:!0}),i.push(e));let n=To(t,{withFileTypes:!0});for(let r of n){let o=W(t,r.name),a=W(e,r.name);r.isDirectory()?Nc(o,a,i):(Vc(o,a),i.push(a))}}function bc(t,e={},i=process.cwd()){let n={skill:t,success:!1,created:[],skipped:[],errors:[]},r=Xo(i),o=Ho(i),a=W(r,t),c=W(o,t);if(!le(a))return n.errors.push(`Skill not found: ${t}`),n;let l=W(a,"SKILL.md");if(!le(l))return n.errors.push(`SKILL.md not found in ${t}`),n;if(Qc(t,i)&&!e.force)return n.skipped.push(`Extension already exists: ${t} (use --force to overwrite)`),n;let v=null;try{let E=wo(l,"utf-8");v=Fc(E)}catch(E){return n.errors.push(`Failed to read SKILL.md: ${E instanceof Error?E.message:String(E)}`),n}(!v||!v.name)&&(v={name:t,description:""});let A=W(a,"references"),u=le(A)&&xA(A).isDirectory(),p=h9(v,u);if(e.dryRun)return n.created.push(`[DRY RUN] Would create: ${c}`),n.created.push(`[DRY RUN] Would create: ${W(c,"gemini-extension.json")}`),n.created.push("[DRY RUN] Would copy: SKILL.md"),u&&n.created.push("[DRY RUN] Would copy: references/"),n.success=!0,n;try{le(c)||(kc(c,{recursive:!0}),n.created.push(c));let E=W(c,"gemini-extension.json");jA(E,JSON.stringify(p,null,2)+`
171
- `),n.created.push(E);let f=W(c,"SKILL.md");if(Vc(l,f),n.created.push(f),u){let z=W(c,"references");Nc(A,z,n.created)}let d=To(a,{withFileTypes:!0});for(let z of d){if(z.name==="SKILL.md"||z.name==="references")continue;let C=W(a,z.name),ve=W(c,z.name);z.isDirectory()?Nc(C,ve,n.created):(Vc(C,ve),n.created.push(ve))}n.success=!0}catch(E){n.errors.push(`Failed to convert: ${E instanceof Error?E.message:String(E)}`)}return n}function GA(t={},e=process.cwd()){let i=Lo(e),n=[];for(let r of i){let o=bc(r.name,t,e);n.push(o)}return n}function Jc(t){return{total:t.length,success:t.filter(e=>e.success&&e.errors.length===0&&e.skipped.length===0).length,skipped:t.filter(e=>e.skipped.length>0).length,failed:t.filter(e=>e.errors.length>0).length}}function _o(t=process.cwd()){return W(t,I9)}function $o(t=process.cwd()){return W(t,f9)}function SA(t){let e=Fc(t);return e?{name:e.name||"",description:e.description||"",model:e.model,skills:e.skills}:null}function es(t=process.cwd()){let e=_o(t);if(!le(e))return[];let i=[];try{let n=To(e,{withFileTypes:!0}).filter(r=>r.isFile()&&r.name.endsWith(".md")).map(r=>r.name);for(let r of n){let o=W(e,r),a=r.replace(/\.md$/,""),c,l,v;try{let A=wo(o,"utf-8"),u=SA(A);u&&(c=u.description,l=u.model,v=u.skills)}catch{}i.push({name:a,path:o,description:c,model:l,skills:v})}}catch{}return i.sort((n,r)=>n.name.localeCompare(r.name))}function Bc(t,e=process.cwd()){let i=W($o(e),`${t}.md`);return le(i)}function d9(t){if(t)return gA[t]||t}function R9(t,e){let i=t.match(/^(---\r?\n)([\s\S]*?)(\r?\n---)/);if(!i)return t;let[n,r,o,a]=i,c=o.split(/\r?\n/),l=[],v=new Set;for(let u of c){let p=u.indexOf(":");if(p===-1){l.push(u);continue}let E=u.slice(0,p).trim();E in e?(v.add(E),e[E]!==void 0&&l.push(`${E}: ${e[E]}`)):l.push(u)}for(let[u,p]of Object.entries(e))!v.has(u)&&p!==void 0&&l.push(`${u}: ${p}`);let A=r+l.join(`
172
- `)+a;return t.replace(n,A)}function Zc(t,e={},i=process.cwd()){let n={skill:t,success:!1,created:[],skipped:[],errors:[]},r=_o(i),o=$o(i),a=W(r,`${t}.md`),c=W(o,`${t}.md`);if(!le(a))return n.errors.push(`Agent not found: ${t}`),n;if(Bc(t,i)&&!e.force)return n.skipped.push(`Agent already exists in .gemini/agents: ${t} (use --force to overwrite)`),n;let l;try{l=wo(a,"utf-8")}catch(E){return n.errors.push(`Failed to read agent file: ${E instanceof Error?E.message:String(E)}`),n}let A=SA(l)?.model,u=d9(A),p=l;if(A&&u&&A!==u&&(p=R9(l,{model:u})),e.dryRun)return n.created.push(`[DRY RUN] Would create: ${c}`),A&&u&&A!==u&&n.created.push(`[DRY RUN] Would map model: ${A} -> ${u}`),n.success=!0,n;try{le(o)||kc(o,{recursive:!0}),jA(c,p),n.created.push(c),A&&u&&A!==u&&n.created.push(`Model mapped: ${A} -> ${u}`),n.success=!0}catch(E){n.errors.push(`Failed to convert: ${E instanceof Error?E.message:String(E)}`)}return n}function YA(t={},e=process.cwd()){let i=es(e),n=[];for(let r of i){let o=Zc(r.name,t,e);n.push(o)}return n}function WA(){console.log(),console.log(I.default.bold(s.geminiPurple("Convert .claude to .gemini"))),console.log(),console.log("Usage:"),console.log(` ${s.primary("gk convert")} <type> [name] [options]`),console.log(),console.log("Types:"),console.log(` ${s.primary("skill")} <name> Convert a single skill to extension`),console.log(` ${s.primary("skills")} Convert all skills to extensions`),console.log(` ${s.primary("agent")} <name> Convert a single agent`),console.log(` ${s.primary("agents")} Convert all agents`),console.log(),console.log("Options:"),console.log(` ${s.dim("--list")} List available items`),console.log(` ${s.dim("--force")} Overwrite existing items`),console.log(` ${s.dim("--dry-run")} Show what would be done without changes`),console.log(` ${s.dim("--json")} Output as JSON`),console.log(),console.log("Examples:"),console.log(` ${s.dim("gk convert skill --list")}`),console.log(` ${s.dim("gk convert skill my-skill")}`),console.log(` ${s.dim("gk convert skills --force")}`),console.log(` ${s.dim("gk convert agent --list")}`),console.log(` ${s.dim("gk convert agents --dry-run")}`),console.log()}function MA(t){t.command("convert [type] [name]","Convert .claude to .gemini resources").alias("cv").option("--all","[all] Convert all items").option("--list","[all] List available items").option("--force","[all] Overwrite existing items").option("--dry-run","[all] Show what would be done without making changes").option("--json","[all] Output as JSON").action(async(e,i,n)=>{if(!e){WA();return}if(e==="skill"||e==="skills"){if(n.list){await z9(n);return}if(n.all||e==="skills"){await j9(n);return}i||(console.log(),m.error("Skill name required"),console.log(s.dim("Usage: gk convert skill <name>")),console.log(s.dim(" gk convert skill --list (to see available skills)")),console.log(s.dim(" gk convert skills (to convert all)")),console.log(),process.exit(1)),await g9(i,n);return}if(e==="agent"||e==="agents"){if(n.list){await x9(n);return}if(n.all||e==="agents"){await S9(n);return}i||(console.log(),m.error("Agent name required"),console.log(s.dim("Usage: gk convert agent <name>")),console.log(s.dim(" gk convert agent --list (to see available agents)")),console.log(s.dim(" gk convert agents (to convert all)")),console.log(),process.exit(1)),await G9(i,n);return}WA()})}async function z9(t){let e=Lo();if(t.json){console.log(JSON.stringify(e,null,2));return}if(console.log(),console.log(I.default.bold(s.geminiPurple("Available Claude Skills"))),console.log(s.dim(` Source: ${Xo()}`)),console.log(),e.length===0){m.info("No skills found in .claude/skills/"),console.log();return}for(let i of e){let n=Qc(i.name),r=n?s.success("\u2713"):s.dim("\u25CB"),o=n?s.dim(" (converted)"):"";if(console.log(` ${r} ${s.primary(i.name)}${o}`),i.description){let a=i.description.length>70?i.description.slice(0,70)+"...":i.description;console.log(` ${s.dim(a)}`)}}console.log(),console.log(s.dim(` Total: ${e.length} skills`)),console.log()}async function g9(t,e){let i=bc(t,{force:e.force,dryRun:e.dryRun});if(e.json){console.log(JSON.stringify(i,null,2));return}if(console.log(),i.errors.length>0){m.error(`Failed to convert skill: ${t}`);for(let n of i.errors)console.log(` ${s.error("\u2717")} ${n}`);console.log(),process.exit(1)}if(i.skipped.length>0){m.warn(`Skipped skill: ${t}`);for(let n of i.skipped)console.log(` ${s.dim("\u25CB")} ${n}`);console.log();return}if(e.dryRun){m.info(`[DRY RUN] Would convert skill: ${t}`);for(let n of i.created)console.log(` ${s.dim("\u2192")} ${n}`);console.log();return}m.success(`Converted skill: ${s.primary(t)}`),console.log(),console.log(` ${s.dim("Created files:")}`);for(let n of i.created.slice(0,5)){let r=n.replace(process.cwd(),".");console.log(` ${s.success("+")} ${r}`)}i.created.length>5&&console.log(` ${s.dim(`... and ${i.created.length-5} more`)}`),console.log(),console.log(s.dim(` Extension created at: ${Ho()}/${t}`)),console.log()}async function j9(t){if(Lo().length===0){t.json?console.log(JSON.stringify({results:[],summary:{total:0,success:0,skipped:0,failed:0}},null,2)):(console.log(),m.info("No skills found in .claude/skills/"),console.log());return}let i=GA({force:t.force,dryRun:t.dryRun}),n=Jc(i);if(t.json){console.log(JSON.stringify({results:i,summary:n},null,2));return}console.log(),t.dryRun?console.log(I.default.bold(s.geminiPurple("[DRY RUN] Skill Conversion Preview"))):console.log(I.default.bold(s.geminiPurple("Skill Conversion Results"))),console.log(M.line()),console.log();for(let r of i)if(r.errors.length>0){console.log(` ${s.error("\u2717")} ${r.skill}`);for(let o of r.errors)console.log(` ${s.dim(o)}`)}else if(r.skipped.length>0)console.log(` ${s.dim("\u25CB")} ${r.skill} ${s.dim("(skipped)")}`);else if(r.success){let o=t.dryRun?s.dim("\u2192"):s.success("\u2713");console.log(` ${o} ${r.skill}`)}console.log(),console.log(M.line()),console.log(),t.dryRun?(console.log(` ${s.dim("Would convert:")} ${n.success} skills`),console.log(` ${s.dim("Would skip:")} ${n.skipped} skills`),console.log(` ${s.dim("Would fail:")} ${n.failed} skills`)):(console.log(` ${s.success("Converted:")} ${n.success}`),console.log(` ${s.dim("Skipped:")} ${n.skipped}`),console.log(` ${s.error("Failed:")} ${n.failed}`)),console.log(),n.skipped>0&&!t.force&&(m.info("Use --force to overwrite existing extensions"),console.log())}async function x9(t){let e=es();if(t.json){console.log(JSON.stringify(e,null,2));return}if(console.log(),console.log(I.default.bold(s.geminiPurple("Available Claude Agents"))),console.log(s.dim(` Source: ${_o()}`)),console.log(),e.length===0){m.info("No agents found in .claude/agents/"),console.log();return}for(let i of e){let n=Bc(i.name),r=n?s.success("\u2713"):s.dim("\u25CB"),o=n?s.dim(" (converted)"):"";if(console.log(` ${r} ${s.primary(i.name)}${o}`),i.model&&console.log(` ${s.dim("Model:")} ${i.model}`),i.description){let a=i.description.length>60?i.description.slice(0,60)+"...":i.description;console.log(` ${s.dim(a)}`)}}console.log(),console.log(s.dim(` Total: ${e.length} agents`)),console.log()}async function G9(t,e){let i=Zc(t,{force:e.force,dryRun:e.dryRun});if(e.json){console.log(JSON.stringify(i,null,2));return}if(console.log(),i.errors.length>0){m.error(`Failed to convert agent: ${t}`);for(let n of i.errors)console.log(` ${s.error("\u2717")} ${n}`);console.log(),process.exit(1)}if(i.skipped.length>0){m.warn(`Skipped agent: ${t}`);for(let n of i.skipped)console.log(` ${s.dim("\u25CB")} ${n}`);console.log();return}if(e.dryRun){m.info(`[DRY RUN] Would convert agent: ${t}`);for(let n of i.created)console.log(` ${s.dim("\u2192")} ${n}`);console.log();return}m.success(`Converted agent: ${s.primary(t)}`),console.log();for(let n of i.created){let r=n.replace(process.cwd(),".");console.log(` ${s.success("+")} ${r}`)}console.log(),console.log(s.dim(` Agent created at: ${$o()}/${t}.md`)),console.log()}async function S9(t){if(es().length===0){t.json?console.log(JSON.stringify({results:[],summary:{total:0,success:0,skipped:0,failed:0}},null,2)):(console.log(),m.info("No agents found in .claude/agents/"),console.log());return}let i=YA({force:t.force,dryRun:t.dryRun}),n=Jc(i);if(t.json){console.log(JSON.stringify({results:i,summary:n},null,2));return}console.log(),t.dryRun?console.log(I.default.bold(s.geminiPurple("[DRY RUN] Agent Conversion Preview"))):console.log(I.default.bold(s.geminiPurple("Agent Conversion Results"))),console.log(M.line()),console.log();for(let r of i)if(r.errors.length>0){console.log(` ${s.error("\u2717")} ${r.skill}`);for(let o of r.errors)console.log(` ${s.dim(o)}`)}else if(r.skipped.length>0)console.log(` ${s.dim("\u25CB")} ${r.skill} ${s.dim("(skipped)")}`);else if(r.success){let o=t.dryRun?s.dim("\u2192"):s.success("\u2713");console.log(` ${o} ${r.skill}`)}console.log(),console.log(M.line()),console.log(),t.dryRun?(console.log(` ${s.dim("Would convert:")} ${n.success} agents`),console.log(` ${s.dim("Would skip:")} ${n.skipped} agents`),console.log(` ${s.dim("Would fail:")} ${n.failed} agents`)):(console.log(` ${s.success("Converted:")} ${n.success}`),console.log(` ${s.dim("Skipped:")} ${n.skipped}`),console.log(` ${s.error("Failed:")} ${n.failed}`)),console.log(),n.skipped>0&&!t.force&&(m.info("Use --force to overwrite existing agents"),console.log())}function Vt(){return{orchestrator:null,agents:new Map,sessionId:null,projectDir:null,activePlan:null,appName:null,currentNotification:null,inbox:[],documents:[],isActive:!1}}var Y9=[[/research|search|analyze/i,"\u{1F50D}"],[/code|implement|execute|develop/i,"\u{1F4BB}"],[/plan|architect/i,"\u{1F4CB}"],[/debug|fix|troubleshoot/i,"\u{1F41B}"],[/test|qa|quality/i,"\u{1F9EA}"],[/design|ui|ux/i,"\u{1F3A8}"],[/review|audit|check/i,"\u2705"],[/doc|write|content/i,"\u{1F4DD}"]];function ts(t,e=!1){if(e)return"\u{1F451}";for(let[i,n]of Y9)if(i.test(t))return n;return"\u{1F916}"}function Pc(t){return t.replace(/-/g," ").replace(/\b\w/g,e=>e.toUpperCase())}function yc(t){let e=t.toLowerCase();return e.includes("main")?"orchestrator":e.includes("research")||e.includes("scout")?"researcher":e.includes("code")||e.includes("executor")||e.includes("debug")?"coder":e.includes("plan")?"planner":e.includes("test")?"tester":e.includes("design")||e.includes("ui")||e.includes("ux")||e.includes("artist")?"designer":e.includes("doc")||e.includes("writer")?"writer":e.includes("manager")||e.includes("git")?"manager":"other"}function qc(t,e){return t.agentType==="Main Agent"||t.parentGkSessionId===null||t.gkSessionId===e.gkSessionId}function W9(t,e){return t==="active"?"working":"idle"}function M9(t){if(t.status==="completed")return 100;if(t.status==="failed"||!t.startTime)return 0;let e=new Date(t.startTime).getTime(),n=Date.now()-e;return Math.min(100,Math.round(n/12e4*100))}function C9(t){return t.status==="completed"?"Task complete!":t.status==="failed"?"Task failed":t.injected?.skills?.length?`Working on ${t.injected.skills[0]}...`:null}function CA(t,e){let i=qc(t,e),n=!!(t.injected?.skills?.length&&t.status==="active"),r=t.agentRole||"unknown",o={id:t.gkSessionId,agentType:i?"orchestrator":"sub-agent",role:r,characterType:yc(r),icon:ts(r,i),state:W9(t.status,n),activeSkill:t.injected?.skills?.[0]||null,progress:M9(t),speechBubble:C9(t),hasFireEffect:n,gkSessionId:t.gkSessionId,parentSessionId:t.parentGkSessionId};if(i){let a=e.agents.filter(c=>!qc(c,e));return{...o,agentType:"orchestrator",delegatedTo:a.filter(c=>c.status==="active").map(c=>c.gkSessionId),totalSubAgents:a.length,completedSubAgents:a.filter(c=>c.status==="completed").length}}return o}function OA(t){let e=t.endTime&&t.startTime?new Date(t.endTime).getTime()-new Date(t.startTime).getTime():0;return{id:`inbox-${t.gkSessionId}`,agentId:t.gkSessionId,agentRole:t.agentRole||"unknown",agentIcon:ts(t.agentRole||""),timestamp:t.endTime?new Date(t.endTime).getTime():Date.now(),status:"unread",title:`${Pc(t.agentRole||"Agent")} completed`,preview:t.prompt?t.prompt.slice(0,100):"Task completed",fullContent:null,tokenUsage:t.tokenUsage?{input:t.tokenUsage.input,output:t.tokenUsage.output}:null,duration:e,skillsUsed:t.injected?.skills||[]}}function wi(t){let e=Vt();if(!t)return e;e.sessionId=t.gkSessionId,e.projectDir=t.projectDir,e.activePlan=t.activePlan,e.appName=t.appName||null,e.isActive=t.agents.some(i=>i.status==="active");for(let i of t.agents){let n=CA(i,t);n.agentType==="orchestrator"?e.orchestrator=n:e.agents.set(n.id,n),i.status==="completed"&&(e.inbox.find(o=>o.agentId===i.gkSessionId)||e.inbox.push(OA(i)))}return e.inbox.sort((i,n)=>n.timestamp-i.timestamp),e}import{existsSync as Ti,readdirSync as is,statSync as Dc}from"fs";import{join as ct,basename as O9,extname as UA,relative as U9}from"path";import{createHash as K9}from"crypto";function V9(t,e){let i={plan:"\u{1F4CB}",phase:"\u{1F4D1}",research:"\u{1F50D}",artifact:"\u{1F4E6}",report:"\u{1F4CA}",other:"\u{1F4C4}"};return t==="artifact"?{sql:"\u{1F5C4}\uFE0F",json:"\u{1F4E6}",png:"\u{1F5BC}\uFE0F",jpg:"\u{1F5BC}\uFE0F",ts:"\u{1F4BB}",js:"\u{1F4BB}"}[e]||i.artifact:i[t]}function KA(t){let e=t.match(/^phase-(\d+)/);return e?parseInt(e[1],10):null}function N9(t,e){if(e==="phase"){let i=KA(t),n=t.replace(/^phase-\d+-?/,"").replace(/-/g," ");return i!==null?`Phase ${i}: ${n}`:t}return t.replace(/-/g," ").replace(/\b\w/g,i=>i.toUpperCase())}function Xi(t,e,i){let n=Dc(t),r=O9(t,UA(t)),o=UA(t).slice(1);return{id:K9("md5").update(t).digest("hex").slice(0,8),name:r,displayName:N9(r,e),type:e,icon:V9(e,o),path:t,relativePath:U9(i,t),modifiedAt:n.mtimeMs,createdAt:n.birthtimeMs,size:n.size,extension:o,phaseNumber:KA(r)}}function wc(t){if(!Ti(t))return[];let e=[],i=ct(t,"plan.md");Ti(i)&&e.push(Xi(i,"plan",t));let n=is(t);for(let c of n){let l=ct(t,c),v=Dc(l);if(c.startsWith("phase-"))if(v.isDirectory()){let A=ct(l,"phase.md");Ti(A)&&e.push(Xi(A,"phase",t))}else c.endsWith(".md")&&e.push(Xi(l,"phase",t))}let r=ct(t,"research");if(Ti(r)){let c=is(r).filter(l=>l.endsWith(".md"));for(let l of c)e.push(Xi(ct(r,l),"research",t))}let o=ct(t,"artifacts");if(Ti(o)){let c=is(o);for(let l of c){let v=ct(o,l);Dc(v).isFile()&&e.push(Xi(v,"artifact",t))}}let a=ct(t,"reports");if(Ti(a)){let c=is(a).filter(l=>l.endsWith(".md"));for(let l of c)e.push(Xi(ct(a,l),"report",t))}return e.sort((c,l)=>l.modifiedAt-c.modifiedAt),e}var k9=1e3,Nt=class{state;stateListeners=new Set;eventListeners=new Set;eventHistory=[];constructor(e){this.state=e}onStateChange(e){return this.stateListeners.add(e),e(this.state),()=>this.stateListeners.delete(e)}onEvent(e){return this.eventListeners.add(e),()=>this.eventListeners.delete(e)}emit(e){this.eventHistory.push(e),this.eventHistory.length>k9&&this.eventHistory.shift();for(let i of this.eventListeners)try{i(e)}catch(n){console.error("Event listener error:",n)}}setState(e){this.state=e;for(let i of this.stateListeners)try{i(this.state)}catch(n){console.error("State listener error:",n)}}getState(){return this.state}getHistory(){return[...this.eventHistory]}replay(e){return this.eventHistory.filter(i=>i.timestamp>=e)}dispose(){this.stateListeners.clear(),this.eventListeners.clear(),this.eventHistory=[]}};import{existsSync as F9,readFileSync as Q9,statSync as VA}from"fs";var b9=200,kt=class{pollInterval=null;previousSession=null;previousMtime=0;options;sessionPath=null;constructor(e){this.options=e}start(){let e=k(),i=e.PROJECT_DIR,n=e.ACTIVE_GK_SESSION_ID;if(!i||!n)return this.options.onError(new Error("No active session found")),!1;if(this.sessionPath=Zt(i,n),!F9(this.sessionPath))return this.options.onError(new Error(`Session file not found: ${this.sessionPath}`)),!1;try{let r=VA(this.sessionPath);this.previousMtime=r.mtimeMs}catch{}return this.loadSession(),this.pollInterval=setInterval(()=>{this.checkForChanges()},b9),!0}stop(){this.pollInterval&&(clearInterval(this.pollInterval),this.pollInterval=null)}checkForChanges(){if(this.sessionPath)try{let i=VA(this.sessionPath).mtimeMs;i>this.previousMtime&&(this.previousMtime=i,this.loadSession())}catch{}}loadSession(){if(this.sessionPath)try{let e=Q9(this.sessionPath,"utf-8"),i=JSON.parse(e),n=this.previousSession?this.diffSessions(this.previousSession,i):[];this.previousSession=i,this.options.onSessionChange(i);for(let r of n)this.options.onEvent(r)}catch(e){this.options.onError(e)}}diffSessions(e,i){let n=[],r=Date.now(),o=new Map(e.agents.map(l=>[l.gkSessionId,l]));for(let l of i.agents){let v=o.get(l.gkSessionId);if(!v)n.push(this.createEvent("received_work",l,r)),l.injected?.skills?.length&&n.push(this.createEvent("skill_activated",l,r,l.injected.skills[0]));else{v.status==="active"&&l.status==="completed"&&(n.push(this.createEvent("task_complete",l,r)),n.push(this.createEvent("delivering",l,r)));let A=v.injected?.skills||[],p=(l.injected?.skills||[]).filter(E=>!A.includes(E));for(let E of p)n.push(this.createEvent("skill_activated",l,r,E))}}let a=i.agents.every(l=>l.status==="completed"||l.status==="failed"),c=e.agents.some(l=>l.status==="active");return a&&c&&i.agents.length>0&&n.push({type:"session_complete",agentId:i.gkSessionId,targetAgentId:null,skill:null,message:"All tasks completed",timestamp:r}),n}createEvent(e,i,n,r){let o={agent_idle:"Waiting for work",agent_working:"Working...",skill_activated:`Activated skill: ${r||"unknown"}`,handoff_start:"Passing work...",handoff_complete:"Handoff complete!",received_work:"Received work",delivering:"Delivering results...",task_complete:"Task complete!",session_complete:"All tasks completed"};return{type:e,agentId:i.gkSessionId,targetAgentId:i.parentGkSessionId,skill:r||i.injected?.skills?.[0]||null,message:o[e],timestamp:n,characterType:yc(i.agentRole||"coder")}}};import{exec as q9}from"child_process";import{join as y9}from"path";import{createServer as J9}from"http";import{WebSocketServer as B9,WebSocket as kA}from"ws";import{exec as Z9}from"child_process";import{existsSync as FA}from"fs";import{resolve as P9}from"path";function NA(){return`<!DOCTYPE html>
199
+ `.trim();try{let i=zt("osascript",["-e",e],{encoding:"utf-8",timeout:5e3});if(i.stdout&&i.stdout.trim()!=="NO_FILE"){let s=i.stdout.trim();if(!Pu(s))return{success:!1,error:"Clipboard does not contain a video file",suggestion:"Copy a video file (.mp4, .mov, .webm) to clipboard first"};if(!We(s))return{success:!1,error:"Video file not found"};let r=wn(s),o=Ya(r),c=Ye(t,o);if(Ma(s,c),We(c))return{success:!0,path:c,sourcePath:s,sourceType:"clipboard"}}let n=uA([Ye(qn(),"Movies"),Ye(qn(),"Desktop")],t);return n||{success:!1,error:"No video in clipboard or recent recordings",suggestion:"Copy a video file or use Cmd+Shift+5 to record screen"}}catch(i){return{success:!1,error:`macOS video capture error: ${i instanceof Error?i.message:String(i)}`}}}function e9(t){try{if(zt("which",["xclip"],{encoding:"utf-8"}).status!==0)return{success:!1,error:"xclip is not installed",suggestion:"Install with: sudo apt install xclip"};let i=zt("xclip",["-selection","clipboard","-t","text/uri-list","-o"],{encoding:"utf-8",timeout:5e3});if(i.status===0&&i.stdout){let s=i.stdout.trim(),r=s;if(s.startsWith("file://")&&(r=decodeURIComponent(s.replace("file://",""))),Pu(r)&&We(r)){let o=wn(r),c=Ya(o),l=Ye(t,c);if(Ma(r,l),We(l))return{success:!0,path:l,sourcePath:r,sourceType:"clipboard"}}}let n=uA([Ye(qn(),"Videos"),Ye(qn(),"Screencasts"),Ye(qn(),"Desktop")],t);return n||{success:!1,error:"No video in clipboard or recent recordings",suggestion:"Copy a video file or use a screen recorder first"}}catch(e){return{success:!1,error:`Linux video capture error: ${e instanceof Error?e.message:String(e)}`}}}function t9(t){if(t.success&&t.path){let i=(bu(t.path).size/(1024*1024)).toFixed(2),n=wn(t.path).toLowerCase();return{success:!0,message:`Video captured from ${t.sourceType}`,path:t.path,sourcePath:t.sourcePath,sourceType:t.sourceType,size:`${i} MB`,format:n.substring(1).toUpperCase(),platform:t.platform}}return{success:!1,error:t.error,suggestion:t.suggestion||"Record a video with Snipping Tool (Win+Shift+R) or copy a video file to clipboard",platform:t.platform}}var mA={"claude-3-opus":"gemini-2.5-pro","claude-3-sonnet":"gemini-2.5-flash","claude-3-haiku":"gemini-2.5-flash","claude-3.5-sonnet":"gemini-2.5-pro","claude-3.5-haiku":"gemini-2.5-flash","gemini-2.5-pro":"gemini-2.5-pro","gemini-2.5-flash":"gemini-2.5-flash","gemini-3-flash-preview":"gemini-3-flash-preview"};import{existsSync as Ce,readFileSync as Wa,readdirSync as Ca,mkdirSync as Ju,writeFileSync as vA,copyFileSync as Qu,statSync as pA}from"fs";import{join as O}from"path";var i9=".claude/skills",n9=".gemini/extensions",s9=".claude/agents",r9=".gemini/agents";function Zu(t){let e=t.match(/^---\r?\n([\s\S]*?)\r?\n---/);if(!e)return null;let i={name:"",description:""},n=e[1].split(/\r?\n/);for(let s of n){let r=s.indexOf(":");if(r===-1)continue;let o=s.slice(0,r).trim(),c=s.slice(r+1).trim();(c.startsWith('"')&&c.endsWith('"')||c.startsWith("'")&&c.endsWith("'"))&&(c=c.slice(1,-1)),i[o]=c}return i}function Oa(t=process.cwd()){return O(t,i9)}function Ua(t=process.cwd()){return O(t,n9)}function Ka(t=process.cwd()){let e=Oa(t);if(!Ce(e))return[];let i=[];try{let n=Ca(e,{withFileTypes:!0}).filter(s=>s.isDirectory()).map(s=>s.name);for(let s of n){let r=O(e,s),o=O(r,"SKILL.md"),c=O(r,"references"),l=Ce(o),u=Ce(c)&&pA(c).isDirectory(),m;if(l)try{let p=Wa(o,"utf-8");m=Zu(p)?.description}catch{}i.push({name:s,path:r,hasSkillMd:l,hasReferences:u,description:m})}}catch{}return i.sort((n,s)=>n.name.localeCompare(s.name))}function yu(t,e=process.cwd()){let i=O(Ua(e),t);return Ce(i)}function o9(t,e){let i=["SKILL.md"];return e&&i.push("references/*.md"),{name:t.name||"",version:"1.0.0",description:t.description||"",license:"MIT",contextFileName:i}}function Bu(t,e,i){Ce(e)||(Ju(e,{recursive:!0}),i.push(e));let n=Ca(t,{withFileTypes:!0});for(let s of n){let r=O(t,s.name),o=O(e,s.name);s.isDirectory()?Bu(r,o,i):(Qu(r,o),i.push(o))}}function qu(t,e={},i=process.cwd()){let n={skill:t,success:!1,created:[],skipped:[],errors:[]},s=Oa(i),r=Ua(i),o=O(s,t),c=O(r,t);if(!Ce(o))return n.errors.push(`Skill not found: ${t}`),n;let l=O(o,"SKILL.md");if(!Ce(l))return n.errors.push(`SKILL.md not found in ${t}`),n;if(yu(t,i)&&!e.force)return n.skipped.push(`Extension already exists: ${t} (use --force to overwrite)`),n;let u=null;try{let A=Wa(l,"utf-8");u=Zu(A)}catch(A){return n.errors.push(`Failed to read SKILL.md: ${A instanceof Error?A.message:String(A)}`),n}(!u||!u.name)&&(u={name:t,description:""});let m=O(o,"references"),p=Ce(m)&&pA(m).isDirectory(),d=o9(u,p);if(e.dryRun)return n.created.push(`[DRY RUN] Would create: ${c}`),n.created.push(`[DRY RUN] Would create: ${O(c,"gemini-extension.json")}`),n.created.push("[DRY RUN] Would copy: SKILL.md"),p&&n.created.push("[DRY RUN] Would copy: references/"),n.success=!0,n;try{Ce(c)||(Ju(c,{recursive:!0}),n.created.push(c));let A=O(c,"gemini-extension.json");vA(A,JSON.stringify(d,null,2)+`
200
+ `),n.created.push(A);let f=O(c,"SKILL.md");if(Qu(l,f),n.created.push(f),p){let E=O(c,"references");Bu(m,E,n.created)}let g=Ca(o,{withFileTypes:!0});for(let E of g){if(E.name==="SKILL.md"||E.name==="references")continue;let J=O(o,E.name),M=O(c,E.name);E.isDirectory()?Bu(J,M,n.created):(Qu(J,M),n.created.push(M))}n.success=!0}catch(A){n.errors.push(`Failed to convert: ${A instanceof Error?A.message:String(A)}`)}return n}function AA(t={},e=process.cwd()){let i=Ka(e),n=[];for(let s of i){let r=qu(s.name,t,e);n.push(r)}return n}function wu(t){return{total:t.length,success:t.filter(e=>e.success&&e.errors.length===0&&e.skipped.length===0).length,skipped:t.filter(e=>e.skipped.length>0).length,failed:t.filter(e=>e.errors.length>0).length}}function ka(t=process.cwd()){return O(t,s9)}function Va(t=process.cwd()){return O(t,r9)}function dA(t){let e=Zu(t);return e?{name:e.name||"",description:e.description||"",model:e.model,skills:e.skills}:null}function Na(t=process.cwd()){let e=ka(t);if(!Ce(e))return[];let i=[];try{let n=Ca(e,{withFileTypes:!0}).filter(s=>s.isFile()&&s.name.endsWith(".md")).map(s=>s.name);for(let s of n){let r=O(e,s),o=s.replace(/\.md$/,""),c,l,u;try{let m=Wa(r,"utf-8"),p=dA(m);p&&(c=p.description,l=p.model,u=p.skills)}catch{}i.push({name:o,path:r,description:c,model:l,skills:u})}}catch{}return i.sort((n,s)=>n.name.localeCompare(s.name))}function Du(t,e=process.cwd()){let i=O(Va(e),`${t}.md`);return Ce(i)}function a9(t){if(t)return mA[t]||t}function c9(t,e){let i=t.match(/^(---\r?\n)([\s\S]*?)(\r?\n---)/);if(!i)return t;let[n,s,r,o]=i,c=r.split(/\r?\n/),l=[],u=new Set;for(let p of c){let d=p.indexOf(":");if(d===-1){l.push(p);continue}let A=p.slice(0,d).trim();A in e?(u.add(A),e[A]!==void 0&&l.push(`${A}: ${e[A]}`)):l.push(p)}for(let[p,d]of Object.entries(e))!u.has(p)&&d!==void 0&&l.push(`${p}: ${d}`);let m=s+l.join(`
201
+ `)+o;return t.replace(n,m)}function Tu(t,e={},i=process.cwd()){let n={skill:t,success:!1,created:[],skipped:[],errors:[]},s=ka(i),r=Va(i),o=O(s,`${t}.md`),c=O(r,`${t}.md`);if(!Ce(o))return n.errors.push(`Agent not found: ${t}`),n;if(Du(t,i)&&!e.force)return n.skipped.push(`Agent already exists in .gemini/agents: ${t} (use --force to overwrite)`),n;let l;try{l=Wa(o,"utf-8")}catch(A){return n.errors.push(`Failed to read agent file: ${A instanceof Error?A.message:String(A)}`),n}let m=dA(l)?.model,p=a9(m),d=l;if(m&&p&&m!==p&&(d=c9(l,{model:p})),e.dryRun)return n.created.push(`[DRY RUN] Would create: ${c}`),m&&p&&m!==p&&n.created.push(`[DRY RUN] Would map model: ${m} -> ${p}`),n.success=!0,n;try{Ce(r)||Ju(r,{recursive:!0}),vA(c,d),n.created.push(c),m&&p&&m!==p&&n.created.push(`Model mapped: ${m} -> ${p}`),n.success=!0}catch(A){n.errors.push(`Failed to convert: ${A instanceof Error?A.message:String(A)}`)}return n}function fA(t={},e=process.cwd()){let i=Na(e),n=[];for(let s of i){let r=Tu(s.name,t,e);n.push(r)}return n}function hA(){console.log(),console.log(h.default.bold(a.geminiPurple("Convert .claude to .gemini"))),console.log(),console.log("Usage:"),console.log(` ${a.primary("gk convert")} <type> [name] [options]`),console.log(),console.log("Types:"),console.log(` ${a.primary("skill")} <name> Convert a single skill to extension`),console.log(` ${a.primary("skills")} Convert all skills to extensions`),console.log(` ${a.primary("agent")} <name> Convert a single agent`),console.log(` ${a.primary("agents")} Convert all agents`),console.log(),console.log("Options:"),console.log(` ${a.dim("--list")} List available items`),console.log(` ${a.dim("--force")} Overwrite existing items`),console.log(` ${a.dim("--dry-run")} Show what would be done without changes`),console.log(` ${a.dim("--json")} Output as JSON`),console.log(),console.log("Examples:"),console.log(` ${a.dim("gk convert skill --list")}`),console.log(` ${a.dim("gk convert skill my-skill")}`),console.log(` ${a.dim("gk convert skills --force")}`),console.log(` ${a.dim("gk convert agent --list")}`),console.log(` ${a.dim("gk convert agents --dry-run")}`),console.log()}function gA(t){t.command("convert [type] [name]","Convert .claude to .gemini resources").alias("cv").option("--all","[all] Convert all items").option("--list","[all] List available items").option("--force","[all] Overwrite existing items").option("--dry-run","[all] Show what would be done without making changes").option("--json","[all] Output as JSON").action(async(e,i,n)=>{if(!e){hA();return}if(e==="skill"||e==="skills"){if(n.list){await l9(n);return}if(n.all||e==="skills"){await m9(n);return}i||(console.log(),v.error("Skill name required"),console.log(a.dim("Usage: gk convert skill <name>")),console.log(a.dim(" gk convert skill --list (to see available skills)")),console.log(a.dim(" gk convert skills (to convert all)")),console.log(),process.exit(1)),await u9(i,n);return}if(e==="agent"||e==="agents"){if(n.list){await v9(n);return}if(n.all||e==="agents"){await A9(n);return}i||(console.log(),v.error("Agent name required"),console.log(a.dim("Usage: gk convert agent <name>")),console.log(a.dim(" gk convert agent --list (to see available agents)")),console.log(a.dim(" gk convert agents (to convert all)")),console.log(),process.exit(1)),await p9(i,n);return}hA()})}async function l9(t){let e=Ka();if(t.json){console.log(JSON.stringify(e,null,2));return}if(console.log(),console.log(h.default.bold(a.geminiPurple("Available Claude Skills"))),console.log(a.dim(` Source: ${Oa()}`)),console.log(),e.length===0){v.info("No skills found in .claude/skills/"),console.log();return}for(let i of e){let n=yu(i.name),s=n?a.success("\u2713"):a.dim("\u25CB"),r=n?a.dim(" (converted)"):"";if(console.log(` ${s} ${a.primary(i.name)}${r}`),i.description){let o=i.description.length>70?i.description.slice(0,70)+"...":i.description;console.log(` ${a.dim(o)}`)}}console.log(),console.log(a.dim(` Total: ${e.length} skills`)),console.log()}async function u9(t,e){let i=qu(t,{force:e.force,dryRun:e.dryRun});if(e.json){console.log(JSON.stringify(i,null,2));return}if(console.log(),i.errors.length>0){v.error(`Failed to convert skill: ${t}`);for(let n of i.errors)console.log(` ${a.error("\u2717")} ${n}`);console.log(),process.exit(1)}if(i.skipped.length>0){v.warn(`Skipped skill: ${t}`);for(let n of i.skipped)console.log(` ${a.dim("\u25CB")} ${n}`);console.log();return}if(e.dryRun){v.info(`[DRY RUN] Would convert skill: ${t}`);for(let n of i.created)console.log(` ${a.dim("\u2192")} ${n}`);console.log();return}v.success(`Converted skill: ${a.primary(t)}`),console.log(),console.log(` ${a.dim("Created files:")}`);for(let n of i.created.slice(0,5)){let s=n.replace(process.cwd(),".");console.log(` ${a.success("+")} ${s}`)}i.created.length>5&&console.log(` ${a.dim(`... and ${i.created.length-5} more`)}`),console.log(),console.log(a.dim(` Extension created at: ${Ua()}/${t}`)),console.log()}async function m9(t){if(Ka().length===0){t.json?console.log(JSON.stringify({results:[],summary:{total:0,success:0,skipped:0,failed:0}},null,2)):(console.log(),v.info("No skills found in .claude/skills/"),console.log());return}let i=AA({force:t.force,dryRun:t.dryRun}),n=wu(i);if(t.json){console.log(JSON.stringify({results:i,summary:n},null,2));return}console.log(),t.dryRun?console.log(h.default.bold(a.geminiPurple("[DRY RUN] Skill Conversion Preview"))):console.log(h.default.bold(a.geminiPurple("Skill Conversion Results"))),console.log(G.line()),console.log();for(let s of i)if(s.errors.length>0){console.log(` ${a.error("\u2717")} ${s.skill}`);for(let r of s.errors)console.log(` ${a.dim(r)}`)}else if(s.skipped.length>0)console.log(` ${a.dim("\u25CB")} ${s.skill} ${a.dim("(skipped)")}`);else if(s.success){let r=t.dryRun?a.dim("\u2192"):a.success("\u2713");console.log(` ${r} ${s.skill}`)}console.log(),console.log(G.line()),console.log(),t.dryRun?(console.log(` ${a.dim("Would convert:")} ${n.success} skills`),console.log(` ${a.dim("Would skip:")} ${n.skipped} skills`),console.log(` ${a.dim("Would fail:")} ${n.failed} skills`)):(console.log(` ${a.success("Converted:")} ${n.success}`),console.log(` ${a.dim("Skipped:")} ${n.skipped}`),console.log(` ${a.error("Failed:")} ${n.failed}`)),console.log(),n.skipped>0&&!t.force&&(v.info("Use --force to overwrite existing extensions"),console.log())}async function v9(t){let e=Na();if(t.json){console.log(JSON.stringify(e,null,2));return}if(console.log(),console.log(h.default.bold(a.geminiPurple("Available Claude Agents"))),console.log(a.dim(` Source: ${ka()}`)),console.log(),e.length===0){v.info("No agents found in .claude/agents/"),console.log();return}for(let i of e){let n=Du(i.name),s=n?a.success("\u2713"):a.dim("\u25CB"),r=n?a.dim(" (converted)"):"";if(console.log(` ${s} ${a.primary(i.name)}${r}`),i.model&&console.log(` ${a.dim("Model:")} ${i.model}`),i.description){let o=i.description.length>60?i.description.slice(0,60)+"...":i.description;console.log(` ${a.dim(o)}`)}}console.log(),console.log(a.dim(` Total: ${e.length} agents`)),console.log()}async function p9(t,e){let i=Tu(t,{force:e.force,dryRun:e.dryRun});if(e.json){console.log(JSON.stringify(i,null,2));return}if(console.log(),i.errors.length>0){v.error(`Failed to convert agent: ${t}`);for(let n of i.errors)console.log(` ${a.error("\u2717")} ${n}`);console.log(),process.exit(1)}if(i.skipped.length>0){v.warn(`Skipped agent: ${t}`);for(let n of i.skipped)console.log(` ${a.dim("\u25CB")} ${n}`);console.log();return}if(e.dryRun){v.info(`[DRY RUN] Would convert agent: ${t}`);for(let n of i.created)console.log(` ${a.dim("\u2192")} ${n}`);console.log();return}v.success(`Converted agent: ${a.primary(t)}`),console.log();for(let n of i.created){let s=n.replace(process.cwd(),".");console.log(` ${a.success("+")} ${s}`)}console.log(),console.log(a.dim(` Agent created at: ${Va()}/${t}.md`)),console.log()}async function A9(t){if(Na().length===0){t.json?console.log(JSON.stringify({results:[],summary:{total:0,success:0,skipped:0,failed:0}},null,2)):(console.log(),v.info("No agents found in .claude/agents/"),console.log());return}let i=fA({force:t.force,dryRun:t.dryRun}),n=wu(i);if(t.json){console.log(JSON.stringify({results:i,summary:n},null,2));return}console.log(),t.dryRun?console.log(h.default.bold(a.geminiPurple("[DRY RUN] Agent Conversion Preview"))):console.log(h.default.bold(a.geminiPurple("Agent Conversion Results"))),console.log(G.line()),console.log();for(let s of i)if(s.errors.length>0){console.log(` ${a.error("\u2717")} ${s.skill}`);for(let r of s.errors)console.log(` ${a.dim(r)}`)}else if(s.skipped.length>0)console.log(` ${a.dim("\u25CB")} ${s.skill} ${a.dim("(skipped)")}`);else if(s.success){let r=t.dryRun?a.dim("\u2192"):a.success("\u2713");console.log(` ${r} ${s.skill}`)}console.log(),console.log(G.line()),console.log(),t.dryRun?(console.log(` ${a.dim("Would convert:")} ${n.success} agents`),console.log(` ${a.dim("Would skip:")} ${n.skipped} agents`),console.log(` ${a.dim("Would fail:")} ${n.failed} agents`)):(console.log(` ${a.success("Converted:")} ${n.success}`),console.log(` ${a.dim("Skipped:")} ${n.skipped}`),console.log(` ${a.error("Failed:")} ${n.failed}`)),console.log(),n.skipped>0&&!t.force&&(v.info("Use --force to overwrite existing agents"),console.log())}function ji(){return{orchestrator:null,agents:new Map,sessionId:null,projectDir:null,activePlan:null,appName:null,currentNotification:null,inbox:[],documents:[],isActive:!1}}var d9=[[/research|search|analyze/i,"\u{1F50D}"],[/code|implement|execute|develop/i,"\u{1F4BB}"],[/plan|architect/i,"\u{1F4CB}"],[/debug|fix|troubleshoot/i,"\u{1F41B}"],[/test|qa|quality/i,"\u{1F9EA}"],[/design|ui|ux/i,"\u{1F3A8}"],[/review|audit|check/i,"\u2705"],[/doc|write|content/i,"\u{1F4DD}"]];function Fa(t,e=!1){if(e)return"\u{1F451}";for(let[i,n]of d9)if(i.test(t))return n;return"\u{1F916}"}function Xu(t){return t.replace(/-/g," ").replace(/\b\w/g,e=>e.toUpperCase())}function Lu(t){let e=t.toLowerCase();return e.includes("main")?"orchestrator":e.includes("research")||e.includes("scout")?"researcher":e.includes("code")||e.includes("executor")||e.includes("debug")?"coder":e.includes("plan")?"planner":e.includes("test")?"tester":e.includes("design")||e.includes("ui")||e.includes("ux")||e.includes("artist")?"designer":e.includes("doc")||e.includes("writer")?"writer":e.includes("manager")||e.includes("git")?"manager":"other"}function Hu(t,e){return t.agentType==="Main Agent"||t.parentGkSessionId===null||t.gkSessionId===e.gkSessionId}function f9(t,e){return t==="active"?"working":"idle"}function h9(t){if(t.status==="completed")return 100;if(t.status==="failed"||!t.startTime)return 0;let e=new Date(t.startTime).getTime(),n=Date.now()-e;return Math.min(100,Math.round(n/12e4*100))}function g9(t){return t.status==="completed"?"Task complete!":t.status==="failed"?"Task failed":t.injected?.skills?.length?`Working on ${t.injected.skills[0]}...`:null}function IA(t,e){let i=Hu(t,e),n=!!(t.injected?.skills?.length&&t.status==="active"),s=t.agentRole||"unknown",r={id:t.gkSessionId,agentType:i?"orchestrator":"sub-agent",role:s,characterType:Lu(s),icon:Fa(s,i),state:f9(t.status,n),activeSkill:t.injected?.skills?.[0]||null,progress:h9(t),speechBubble:g9(t),hasFireEffect:n,gkSessionId:t.gkSessionId,parentSessionId:t.parentGkSessionId};if(i){let o=e.agents.filter(c=>!Hu(c,e));return{...r,agentType:"orchestrator",delegatedTo:o.filter(c=>c.status==="active").map(c=>c.gkSessionId),totalSubAgents:o.length,completedSubAgents:o.filter(c=>c.status==="completed").length}}return r}function EA(t){let e=t.endTime&&t.startTime?new Date(t.endTime).getTime()-new Date(t.startTime).getTime():0;return{id:`inbox-${t.gkSessionId}`,agentId:t.gkSessionId,agentRole:t.agentRole||"unknown",agentIcon:Fa(t.agentRole||""),timestamp:t.endTime?new Date(t.endTime).getTime():Date.now(),status:"unread",title:`${Xu(t.agentRole||"Agent")} completed`,preview:t.prompt?t.prompt.slice(0,100):"Task completed",fullContent:null,tokenUsage:t.tokenUsage?{input:t.tokenUsage.input,output:t.tokenUsage.output}:null,duration:e,skillsUsed:t.injected?.skills||[]}}function Dn(t){let e=ji();if(!t)return e;e.sessionId=t.gkSessionId,e.projectDir=t.projectDir,e.activePlan=t.activePlan,e.appName=t.appName||null,e.isActive=t.agents.some(i=>i.status==="active");for(let i of t.agents){let n=IA(i,t);n.agentType==="orchestrator"?e.orchestrator=n:e.agents.set(n.id,n),i.status==="completed"&&(e.inbox.find(r=>r.agentId===i.gkSessionId)||e.inbox.push(EA(i)))}return e.inbox.sort((i,n)=>n.timestamp-i.timestamp),e}import{existsSync as Tn,readdirSync as ba,statSync as _u}from"fs";import{join as yt,basename as I9,extname as RA,relative as E9}from"path";import{createHash as R9}from"crypto";function z9(t,e){let i={plan:"\u{1F4CB}",phase:"\u{1F4D1}",research:"\u{1F50D}",artifact:"\u{1F4E6}",report:"\u{1F4CA}",other:"\u{1F4C4}"};return t==="artifact"?{sql:"\u{1F5C4}\uFE0F",json:"\u{1F4E6}",png:"\u{1F5BC}\uFE0F",jpg:"\u{1F5BC}\uFE0F",ts:"\u{1F4BB}",js:"\u{1F4BB}"}[e]||i.artifact:i[t]}function zA(t){let e=t.match(/^phase-(\d+)/);return e?parseInt(e[1],10):null}function j9(t,e){if(e==="phase"){let i=zA(t),n=t.replace(/^phase-\d+-?/,"").replace(/-/g," ");return i!==null?`Phase ${i}: ${n}`:t}return t.replace(/-/g," ").replace(/\b\w/g,i=>i.toUpperCase())}function Xn(t,e,i){let n=_u(t),s=I9(t,RA(t)),r=RA(t).slice(1);return{id:R9("md5").update(t).digest("hex").slice(0,8),name:s,displayName:j9(s,e),type:e,icon:z9(e,r),path:t,relativePath:E9(i,t),modifiedAt:n.mtimeMs,createdAt:n.birthtimeMs,size:n.size,extension:r,phaseNumber:zA(s)}}function $u(t){if(!Tn(t))return[];let e=[],i=yt(t,"plan.md");Tn(i)&&e.push(Xn(i,"plan",t));let n=ba(t);for(let c of n){let l=yt(t,c),u=_u(l);if(c.startsWith("phase-"))if(u.isDirectory()){let m=yt(l,"phase.md");Tn(m)&&e.push(Xn(m,"phase",t))}else c.endsWith(".md")&&e.push(Xn(l,"phase",t))}let s=yt(t,"research");if(Tn(s)){let c=ba(s).filter(l=>l.endsWith(".md"));for(let l of c)e.push(Xn(yt(s,l),"research",t))}let r=yt(t,"artifacts");if(Tn(r)){let c=ba(r);for(let l of c){let u=yt(r,l);_u(u).isFile()&&e.push(Xn(u,"artifact",t))}}let o=yt(t,"reports");if(Tn(o)){let c=ba(o).filter(l=>l.endsWith(".md"));for(let l of c)e.push(Xn(yt(o,l),"report",t))}return e.sort((c,l)=>l.modifiedAt-c.modifiedAt),e}var x9=1e3,xi=class{state;stateListeners=new Set;eventListeners=new Set;eventHistory=[];constructor(e){this.state=e}onStateChange(e){return this.stateListeners.add(e),e(this.state),()=>this.stateListeners.delete(e)}onEvent(e){return this.eventListeners.add(e),()=>this.eventListeners.delete(e)}emit(e){this.eventHistory.push(e),this.eventHistory.length>x9&&this.eventHistory.shift();for(let i of this.eventListeners)try{i(e)}catch(n){console.error("Event listener error:",n)}}setState(e){this.state=e;for(let i of this.stateListeners)try{i(this.state)}catch(n){console.error("State listener error:",n)}}getState(){return this.state}getHistory(){return[...this.eventHistory]}replay(e){return this.eventHistory.filter(i=>i.timestamp>=e)}dispose(){this.stateListeners.clear(),this.eventListeners.clear(),this.eventHistory=[]}};k();it();import{existsSync as S9,readFileSync as G9,statSync as jA}from"fs";var M9=200,Si=class{pollInterval=null;previousSession=null;previousMtime=0;options;sessionPath=null;constructor(e){this.options=e}start(){let e=B(),i=e.PROJECT_DIR,n=e.ACTIVE_GK_SESSION_ID;if(!i||!n)return this.options.onError(new Error("No active session found")),!1;if(this.sessionPath=Oi(i,n),!S9(this.sessionPath))return this.options.onError(new Error(`Session file not found: ${this.sessionPath}`)),!1;try{let s=jA(this.sessionPath);this.previousMtime=s.mtimeMs}catch{}return this.loadSession(),this.pollInterval=setInterval(()=>{this.checkForChanges()},M9),!0}stop(){this.pollInterval&&(clearInterval(this.pollInterval),this.pollInterval=null)}checkForChanges(){if(this.sessionPath)try{let i=jA(this.sessionPath).mtimeMs;i>this.previousMtime&&(this.previousMtime=i,this.loadSession())}catch{}}loadSession(){if(this.sessionPath)try{let e=G9(this.sessionPath,"utf-8"),i=JSON.parse(e),n=this.previousSession?this.diffSessions(this.previousSession,i):[];this.previousSession=i,this.options.onSessionChange(i);for(let s of n)this.options.onEvent(s)}catch(e){this.options.onError(e)}}diffSessions(e,i){let n=[],s=Date.now(),r=new Map(e.agents.map(l=>[l.gkSessionId,l]));for(let l of i.agents){let u=r.get(l.gkSessionId);if(!u)n.push(this.createEvent("received_work",l,s)),l.injected?.skills?.length&&n.push(this.createEvent("skill_activated",l,s,l.injected.skills[0]));else{u.status==="active"&&l.status==="completed"&&(n.push(this.createEvent("task_complete",l,s)),n.push(this.createEvent("delivering",l,s)));let m=u.injected?.skills||[],d=(l.injected?.skills||[]).filter(A=>!m.includes(A));for(let A of d)n.push(this.createEvent("skill_activated",l,s,A))}}let o=i.agents.every(l=>l.status==="completed"||l.status==="failed"),c=e.agents.some(l=>l.status==="active");return o&&c&&i.agents.length>0&&n.push({type:"session_complete",agentId:i.gkSessionId,targetAgentId:null,skill:null,message:"All tasks completed",timestamp:s}),n}createEvent(e,i,n,s){let r={agent_idle:"Waiting for work",agent_working:"Working...",skill_activated:`Activated skill: ${s||"unknown"}`,handoff_start:"Passing work...",handoff_complete:"Handoff complete!",received_work:"Received work",delivering:"Delivering results...",task_complete:"Task complete!",session_complete:"All tasks completed"};return{type:e,agentId:i.gkSessionId,targetAgentId:i.parentGkSessionId,skill:s||i.injected?.skills?.[0]||null,message:r[e],timestamp:n,characterType:Lu(i.agentRole||"coder")}}};import{exec as U9}from"child_process";import{join as K9}from"path";import{createServer as Y9}from"http";import{WebSocketServer as W9,WebSocket as SA}from"ws";import{exec as C9}from"child_process";import{existsSync as GA}from"fs";import{resolve as O9}from"path";function xA(){return`<!DOCTYPE html>
173
202
  <html lang="en">
174
203
  <head>
175
204
  <meta charset="UTF-8">
@@ -3575,4 +3604,6 @@ hookStopAgentAnimation();
3575
3604
 
3576
3605
  </script>
3577
3606
  </body>
3578
- </html>`}var ns=class{server=null;wss=null;options;clients=new Set;constructor(e){this.options=e}async start(){return new Promise((e,i)=>{let n=this.options.port,r=0,o=10,a=()=>{this.server=J9((c,l)=>this.handleRequest(c,l)),this.server.on("error",c=>{c.code==="EADDRINUSE"&&r<o?(r++,n++,a()):i(c)}),this.server.listen(n,this.options.host||"localhost",()=>{this.wss=new B9({server:this.server}),this.setupWebSocket(),this.options.emitter.onStateChange(c=>{this.broadcastState(c)}),this.options.emitter.onEvent(c=>{this.broadcastEvent(c)}),e(n)})};a()})}stop(){if(this.wss){for(let e of this.clients)e.close();this.wss.close(),this.wss=null}this.server&&(this.server.close(),this.server=null),this.clients.clear()}handleRequest(e,i){let n=e.url||"/";if(n==="/api/state"){i.writeHead(200,{"Content-Type":"application/json"}),i.end(JSON.stringify(this.serializeState(this.options.emitter.getState())));return}if(n==="/api/history"){i.writeHead(200,{"Content-Type":"application/json"}),i.end(JSON.stringify(this.options.emitter.getHistory()));return}if(n.startsWith("/api/open-doc")){let a=new URL(n,`http://${e.headers.host}`).searchParams.get("path");if(!a){i.writeHead(400,{"Content-Type":"application/json"}),i.end(JSON.stringify({success:!1,error:"No path provided"}));return}let c=a;if(FA(c)||(c=P9(process.cwd(),a)),!FA(c)){i.writeHead(404,{"Content-Type":"application/json"}),i.end(JSON.stringify({success:!1,error:`File not found: ${a}`}));return}let l=process.env.EDITOR||process.env.VISUAL,A=this.options.emitter.getState().appName?.toLowerCase()||"",p=["code","cursor","windsurf","zed","vim","nvim","nano","subl","atom","idea","webstorm","notepad++","antigravity"].some(f=>A.includes(f)),E;l?(E=`"${l}" "${c}"`,console.log(`[Agent Office] Using IDE from EDITOR env: ${l}`)):A&&p?(E=`${A} "${c}"`,console.log(`[Agent Office] Using IDE from session: ${A}`)):(E=`code "${c}"`,console.log("[Agent Office] No IDE detected, defaulting to VS Code")),Z9(E,f=>{f?(i.writeHead(500,{"Content-Type":"application/json"}),i.end(JSON.stringify({success:!1,error:f.message}))):(i.writeHead(200,{"Content-Type":"application/json"}),i.end(JSON.stringify({success:!0})))});return}let r=n.split("?")[0].split("#")[0];if(r==="/"||r==="/index.html"){i.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),i.end(NA());return}i.writeHead(404),i.end("Not Found")}setupWebSocket(){this.wss&&this.wss.on("connection",e=>{this.clients.add(e);let i=this.options.emitter.getState();try{e.send(JSON.stringify({type:"state",data:this.serializeState(i)}))}catch{}e.on("message",n=>{try{let r=JSON.parse(n.toString());if(r.type==="ping"&&e.send(JSON.stringify({type:"pong"})),r.type==="replay"){let o=this.options.emitter.replay(r.fromTimestamp);e.send(JSON.stringify({type:"replay",data:o}))}}catch{}}),e.on("close",()=>{this.clients.delete(e)})})}broadcastState(e){let i=JSON.stringify({type:"state",data:this.serializeState(e)});for(let n of this.clients)if(n.readyState===kA.OPEN)try{n.send(i)}catch{}}broadcastEvent(e){let i=JSON.stringify({type:"event",data:e});for(let n of this.clients)if(n.readyState===kA.OPEN)try{n.send(i)}catch{}}serializeState(e){return{...e,agents:Object.fromEntries(e.agents)}}};var rs=class{server=null;emitter;watcher;options;constructor(e={}){this.options={port:3847,host:"localhost",autoOpen:!0,...e},this.emitter=new Nt(Vt()),this.watcher=new kt({onSessionChange:i=>{let n=wi(i);if(n.activePlan)try{let r=Ri(),o=y9(r,n.activePlan);n.documents=wc(o)}catch{}this.emitter.setState(n)},onEvent:i=>{this.emitter.emit(i)},onError:i=>{this.options.onError&&this.options.onError(i)}})}async start(){if(!this.watcher.start())throw new Error("No active session found");this.server=new ns({port:this.options.port,host:this.options.host,emitter:this.emitter});let i=await this.server.start();return this.options.autoOpen&&this.openBrowser(`http://${this.options.host}:${i}`),this.options.onReady&&this.options.onReady(i),i}stop(){this.server&&(this.server.stop(),this.server=null),this.watcher.stop(),this.emitter.dispose()}openBrowser(e){let i=process.platform==="win32"?`start ${e}`:process.platform==="darwin"?`open ${e}`:`xdg-open ${e}`;q9(i,n=>{n&&console.log(`Open ${e} in your browser`)})}};async function Tc(t={}){let e=new rs(t);return await e.start(),e}function Xc(){console.log(),console.log(I.default.bold(s.geminiPurple("Agent Office"))),console.log(),console.log("Usage:"),console.log(` ${s.primary("gk office")} <subcommand> [options]`),console.log(),console.log("Subcommands:"),console.log(` ${s.primary("start")} Start the visualization`),console.log(` ${s.primary("status")} Show current office state`),console.log(` ${s.primary("watch")} Watch office state changes`),console.log(),console.log("Options:"),console.log(` ${s.dim("-p, --port <n>")} [start] Web server port (default: 3847)`),console.log(` ${s.dim("--no-open")} [start] Don't auto-open browser`),console.log(` ${s.dim("--json")} [status/watch] Output as JSON`),console.log(),console.log("Examples:"),console.log(` ${s.dim("gk office start")}`),console.log(` ${s.dim("gk office start --port 4000")}`),console.log(` ${s.dim("gk office status --json")}`),console.log(` ${s.dim("gk office watch")}`),console.log()}function D9(){console.log(),console.log(I.default.bold(s.geminiPurple("gk office start"))),console.log(s.dim("Start the Agent Office web dashboard")),console.log(),console.log("Usage:"),console.log(` ${s.primary("gk office start")} [options]`),console.log(),console.log("Options:"),console.log(` ${s.dim("-p, --port <n>")} Web server port (default: 3847)`),console.log(` ${s.dim("--no-open")} Don't auto-open browser`),console.log(),console.log("Examples:"),console.log(` ${s.dim("gk office start")}`),console.log(` ${s.dim("gk office start --port 4000")}`),console.log(` ${s.dim("gk office start --port 4000 --no-open")}`),console.log()}function w9(){console.log(),console.log(I.default.bold(s.geminiPurple("gk office status"))),console.log(s.dim("Show current Agent Office state")),console.log(),console.log("Usage:"),console.log(` ${s.primary("gk office status")} [options]`),console.log(),console.log("Options:"),console.log(` ${s.dim("--json")} Output as JSON`),console.log()}function T9(){console.log(),console.log(I.default.bold(s.geminiPurple("gk office watch"))),console.log(s.dim("Watch Agent Office state changes in real-time")),console.log(),console.log("Usage:"),console.log(` ${s.primary("gk office watch")} [options]`),console.log(),console.log("Options:"),console.log(` ${s.dim("--json")} Output as JSON`),console.log()}async function X9(t){console.log(),m.info("Starting Agent Office..."),console.log();try{let e=await Tc({port:t.port||3847,autoOpen:t.open!==!1,onReady:i=>{m.success(`Dashboard running at ${s.primary(`http://localhost:${i}`)}`),console.log(s.dim(" Press Ctrl+C to stop")),console.log()},onError:i=>{m.error(`Error: ${i.message}`)}});process.on("SIGINT",()=>{e.stop(),console.log(),m.info("Agent Office stopped."),console.log(),process.exit(0)})}catch(e){e instanceof Error&&(e.message==="No active session found"?(console.log(),m.warn("No active session found."),console.log(s.dim(" Start a GemKit session first with: gk agent")),console.log()):m.error(`Failed to start: ${e.message}`)),process.exit(1)}}function H9(t){let e=new Nt(Vt()),i=new kt({onSessionChange:r=>{let o=wi(r);if(t.json)console.log(JSON.stringify({...o,agents:Object.fromEntries(o.agents)},null,2));else{if(console.log(),console.log(I.default.bold(s.geminiPurple("Agent Office Status"))),console.log(M.line()),console.log(),console.log(` ${s.dim("Active Plan:")} ${o.activePlan?s.primary(o.activePlan):s.dim("(none)")}`),console.log(` ${s.dim("Agents:")} ${o.agents.size}`),console.log(` ${s.dim("Inbox Items:")} ${o.inbox.length}`),console.log(` ${s.dim("Documents:")} ${o.documents.length}`),o.agents.size>0){console.log(),console.log(s.dim(" Agents:"));for(let[a,c]of o.agents){let l=c.state==="working"?s.warn:c.state==="idle"?s.success:s.dim;console.log(` ${c.icon} ${s.primary(c.role)} ${l(`[${c.state}]`)}`)}}console.log()}i.stop(),e.dispose()},onEvent:()=>{},onError:r=>{console.log(),m.error(`Error: ${r.message}`),console.log(),process.exit(1)}});i.start()||(console.log(),m.warn("No active session found."),console.log(s.dim(" Start a GemKit session first with: gk agent")),console.log(),process.exit(1))}function L9(t){console.log(),m.info("Watching Agent Office state..."),console.log(s.dim(" Press Ctrl+C to stop")),console.log();let e=new Nt(Vt()),i=new kt({onSessionChange:r=>{let o=wi(r);if(t.json)console.log(JSON.stringify({timestamp:new Date().toISOString(),...o,agents:Object.fromEntries(o.agents)}));else{let a=new Date().toLocaleTimeString();console.log(`${s.dim(a)} ${s.info("State:")} ${o.agents.size} agents, ${o.inbox.length} inbox items`)}},onEvent:r=>{if(t.json)console.log(JSON.stringify({type:"event",event:r}));else{let o=new Date().toLocaleTimeString();console.log(`${s.dim(o)} ${s.secondary("Event:")} ${r.type}`)}},onError:r=>{m.error(`Error: ${r.message}`)}});i.start()||(console.log(),m.warn("No active session found."),console.log(s.dim(" Start a GemKit session first with: gk agent")),console.log(),process.exit(1)),process.on("SIGINT",()=>{i.stop(),e.dispose(),console.log(),m.info("Stopped watching."),console.log(),process.exit(0)})}function QA(t){t.command("office [subcommand]","Agent Office visualization (start, status, watch)").option("-p, --port <port>","[start] Web server port",{default:3847}).option("--no-open","[start] Don't auto-open browser").option("--json","[status/watch] Output as JSON").action(async(e,i)=>{if(i.port&&(i.port=parseInt(String(i.port),10)),i.help||i.h)switch(e){case"start":D9();return;case"status":w9();return;case"watch":T9();return;default:Xc();return}switch(e){case"start":await X9(i);break;case"status":H9(i);break;case"watch":L9(i);break;case void 0:case"help":Xc();break;default:console.log(),m.error(`Unknown subcommand: ${e}`),Xc(),process.exit(1)}})}function bA(t){jv(t),Rv(t),xv(t),Sv(t),Yv(t),Wv(t),Mv(t),aA(t),cA(t),AA(t),EA(t),pA(t),IA(t),dA(t),MA(t),QA(t)}import{existsSync as JA,readFileSync as _9,writeFileSync as $9,mkdirSync as ef}from"fs";import{join as tf,dirname as nf}from"path";import{homedir as rf}from"os";var os=tf(rf(),".gemkit","last-update-check.json");function BA(){try{return JA(os)?JSON.parse(_9(os,"utf-8")):null}catch{return null}}function of(t){try{let e=nf(os);JA(e)||ef(e,{recursive:!0}),$9(os,JSON.stringify(t,null,2))}catch{}}function sf(t){let e=BA();if(!e)return!0;let i=new Date(e.lastCheck);return(new Date().getTime()-i.getTime())/(1e3*60*60)>=t}async function ZA(){let e=Ve().update;if(e?.autoCheck&&sf(e.checkInterval))try{let i=await zv(),n=BA()||{lastCheck:""},r=[];i.cli?.available&&n.notifiedCli!==i.cli.latest&&(r.push(`${s.primary("CLI")} update available: v${i.cli.current} \u2192 v${i.cli.latest}`),n.notifiedCli=i.cli.latest),i.kits?.available&&n.notifiedKits!==i.kits.latest&&(r.push(`${s.primary("Kits")} update available: v${i.kits.current} \u2192 v${i.kits.latest}`),n.notifiedKits=i.kits.latest),r.length>0&&(console.log(),console.log(s.dim("\u2500".repeat(50))),console.log(`${s.warn("\u2B06")} Updates available:`),r.forEach(o=>console.log(` ${o}`)),console.log(` Run ${s.primary("gk update")} to update.`),console.log(s.dim("\u2500".repeat(50))),console.log()),n.lastCheck=new Date().toISOString(),of(n)}catch{}}var Ft=rl("gk");Ft.version(de);Ft.help();Ft.option("--verbose","Enable verbose output");Ft.option("--json","Output as JSON");Ft.option("--no-update-check","Skip auto-update check");var Hc=Ft.parse(process.argv,{run:!1});Hc.options.verbose&&Mo({level:"debug",verbose:!0});Hc.options.json&&Mo({json:!0});bA(Ft);Hc.options.updateCheck!==!1&&ZA().catch(()=>{});Ft.parse();
3607
+ </html>`}var Pa=class{server=null;wss=null;options;clients=new Set;constructor(e){this.options=e}async start(){return new Promise((e,i)=>{let n=this.options.port,s=0,r=10,o=()=>{this.server=Y9((c,l)=>this.handleRequest(c,l)),this.server.on("error",c=>{c.code==="EADDRINUSE"&&s<r?(s++,n++,o()):i(c)}),this.server.listen(n,this.options.host||"localhost",()=>{this.wss=new W9({server:this.server}),this.setupWebSocket(),this.options.emitter.onStateChange(c=>{this.broadcastState(c)}),this.options.emitter.onEvent(c=>{this.broadcastEvent(c)}),e(n)})};o()})}stop(){if(this.wss){for(let e of this.clients)e.close();this.wss.close(),this.wss=null}this.server&&(this.server.close(),this.server=null),this.clients.clear()}handleRequest(e,i){let n=e.url||"/";if(n==="/api/state"){i.writeHead(200,{"Content-Type":"application/json"}),i.end(JSON.stringify(this.serializeState(this.options.emitter.getState())));return}if(n==="/api/history"){i.writeHead(200,{"Content-Type":"application/json"}),i.end(JSON.stringify(this.options.emitter.getHistory()));return}if(n.startsWith("/api/open-doc")){let o=new URL(n,`http://${e.headers.host}`).searchParams.get("path");if(!o){i.writeHead(400,{"Content-Type":"application/json"}),i.end(JSON.stringify({success:!1,error:"No path provided"}));return}let c=o;if(GA(c)||(c=O9(process.cwd(),o)),!GA(c)){i.writeHead(404,{"Content-Type":"application/json"}),i.end(JSON.stringify({success:!1,error:`File not found: ${o}`}));return}let l=process.env.EDITOR||process.env.VISUAL,m=this.options.emitter.getState().appName?.toLowerCase()||"",d=["code","cursor","windsurf","zed","vim","nvim","nano","subl","atom","idea","webstorm","notepad++","antigravity"].some(f=>m.includes(f)),A;l?(A=`"${l}" "${c}"`,console.log(`[Agent Office] Using IDE from EDITOR env: ${l}`)):m&&d?(A=`${m} "${c}"`,console.log(`[Agent Office] Using IDE from session: ${m}`)):(A=`code "${c}"`,console.log("[Agent Office] No IDE detected, defaulting to VS Code")),C9(A,f=>{f?(i.writeHead(500,{"Content-Type":"application/json"}),i.end(JSON.stringify({success:!1,error:f.message}))):(i.writeHead(200,{"Content-Type":"application/json"}),i.end(JSON.stringify({success:!0})))});return}let s=n.split("?")[0].split("#")[0];if(s==="/"||s==="/index.html"){i.writeHead(200,{"Content-Type":"text/html; charset=utf-8"}),i.end(xA());return}i.writeHead(404),i.end("Not Found")}setupWebSocket(){this.wss&&this.wss.on("connection",e=>{this.clients.add(e);let i=this.options.emitter.getState();try{e.send(JSON.stringify({type:"state",data:this.serializeState(i)}))}catch{}e.on("message",n=>{try{let s=JSON.parse(n.toString());if(s.type==="ping"&&e.send(JSON.stringify({type:"pong"})),s.type==="replay"){let r=this.options.emitter.replay(s.fromTimestamp);e.send(JSON.stringify({type:"replay",data:r}))}}catch{}}),e.on("close",()=>{this.clients.delete(e)})})}broadcastState(e){let i=JSON.stringify({type:"state",data:this.serializeState(e)});for(let n of this.clients)if(n.readyState===SA.OPEN)try{n.send(i)}catch{}}broadcastEvent(e){let i=JSON.stringify({type:"event",data:e});for(let n of this.clients)if(n.readyState===SA.OPEN)try{n.send(i)}catch{}}serializeState(e){return{...e,agents:Object.fromEntries(e.agents)}}};k();var Qa=class{server=null;emitter;watcher;options;constructor(e={}){this.options={port:3847,host:"localhost",autoOpen:!0,...e},this.emitter=new xi(ji()),this.watcher=new Si({onSessionChange:i=>{let n=Dn(i);if(n.activePlan)try{let s=vn(),r=K9(s,n.activePlan);n.documents=$u(r)}catch{}this.emitter.setState(n)},onEvent:i=>{this.emitter.emit(i)},onError:i=>{this.options.onError&&this.options.onError(i)}})}async start(){if(!this.watcher.start())throw new Error("No active session found");this.server=new Pa({port:this.options.port,host:this.options.host,emitter:this.emitter});let i=await this.server.start();return this.options.autoOpen&&this.openBrowser(`http://${this.options.host}:${i}`),this.options.onReady&&this.options.onReady(i),i}stop(){this.server&&(this.server.stop(),this.server=null),this.watcher.stop(),this.emitter.dispose()}openBrowser(e){let i=process.platform==="win32"?`start ${e}`:process.platform==="darwin"?`open ${e}`:`xdg-open ${e}`;U9(i,n=>{n&&console.log(`Open ${e} in your browser`)})}};async function em(t={}){let e=new Qa(t);return await e.start(),e}function tm(){console.log(),console.log(h.default.bold(a.geminiPurple("Agent Office"))),console.log(),console.log("Usage:"),console.log(` ${a.primary("gk office")} <subcommand> [options]`),console.log(),console.log("Subcommands:"),console.log(` ${a.primary("start")} Start the visualization`),console.log(` ${a.primary("status")} Show current office state`),console.log(` ${a.primary("watch")} Watch office state changes`),console.log(),console.log("Options:"),console.log(` ${a.dim("-p, --port <n>")} [start] Web server port (default: 3847)`),console.log(` ${a.dim("--no-open")} [start] Don't auto-open browser`),console.log(` ${a.dim("--json")} [status/watch] Output as JSON`),console.log(),console.log("Examples:"),console.log(` ${a.dim("gk office start")}`),console.log(` ${a.dim("gk office start --port 4000")}`),console.log(` ${a.dim("gk office status --json")}`),console.log(` ${a.dim("gk office watch")}`),console.log()}function k9(){console.log(),console.log(h.default.bold(a.geminiPurple("gk office start"))),console.log(a.dim("Start the Agent Office web dashboard")),console.log(),console.log("Usage:"),console.log(` ${a.primary("gk office start")} [options]`),console.log(),console.log("Options:"),console.log(` ${a.dim("-p, --port <n>")} Web server port (default: 3847)`),console.log(` ${a.dim("--no-open")} Don't auto-open browser`),console.log(),console.log("Examples:"),console.log(` ${a.dim("gk office start")}`),console.log(` ${a.dim("gk office start --port 4000")}`),console.log(` ${a.dim("gk office start --port 4000 --no-open")}`),console.log()}function V9(){console.log(),console.log(h.default.bold(a.geminiPurple("gk office status"))),console.log(a.dim("Show current Agent Office state")),console.log(),console.log("Usage:"),console.log(` ${a.primary("gk office status")} [options]`),console.log(),console.log("Options:"),console.log(` ${a.dim("--json")} Output as JSON`),console.log()}function N9(){console.log(),console.log(h.default.bold(a.geminiPurple("gk office watch"))),console.log(a.dim("Watch Agent Office state changes in real-time")),console.log(),console.log("Usage:"),console.log(` ${a.primary("gk office watch")} [options]`),console.log(),console.log("Options:"),console.log(` ${a.dim("--json")} Output as JSON`),console.log()}async function F9(t){console.log(),v.info("Starting Agent Office..."),console.log();try{let e=await em({port:t.port||3847,autoOpen:t.open!==!1,onReady:i=>{v.success(`Dashboard running at ${a.primary(`http://localhost:${i}`)}`),console.log(a.dim(" Press Ctrl+C to stop")),console.log()},onError:i=>{v.error(`Error: ${i.message}`)}});process.on("SIGINT",()=>{e.stop(),console.log(),v.info("Agent Office stopped."),console.log(),process.exit(0)})}catch(e){e instanceof Error&&(e.message==="No active session found"?(console.log(),v.warn("No active session found."),console.log(a.dim(" Start a GemKit session first with: gk agent")),console.log()):v.error(`Failed to start: ${e.message}`)),process.exit(1)}}function b9(t){let e=new xi(ji()),i=new Si({onSessionChange:s=>{let r=Dn(s);if(t.json)console.log(JSON.stringify({...r,agents:Object.fromEntries(r.agents)},null,2));else{if(console.log(),console.log(h.default.bold(a.geminiPurple("Agent Office Status"))),console.log(G.line()),console.log(),console.log(` ${a.dim("Active Plan:")} ${r.activePlan?a.primary(r.activePlan):a.dim("(none)")}`),console.log(` ${a.dim("Agents:")} ${r.agents.size}`),console.log(` ${a.dim("Inbox Items:")} ${r.inbox.length}`),console.log(` ${a.dim("Documents:")} ${r.documents.length}`),r.agents.size>0){console.log(),console.log(a.dim(" Agents:"));for(let[o,c]of r.agents){let l=c.state==="working"?a.warn:c.state==="idle"?a.success:a.dim;console.log(` ${c.icon} ${a.primary(c.role)} ${l(`[${c.state}]`)}`)}}console.log()}i.stop(),e.dispose()},onEvent:()=>{},onError:s=>{console.log(),v.error(`Error: ${s.message}`),console.log(),process.exit(1)}});i.start()||(console.log(),v.warn("No active session found."),console.log(a.dim(" Start a GemKit session first with: gk agent")),console.log(),process.exit(1))}function P9(t){console.log(),v.info("Watching Agent Office state..."),console.log(a.dim(" Press Ctrl+C to stop")),console.log();let e=new xi(ji()),i=new Si({onSessionChange:s=>{let r=Dn(s);if(t.json)console.log(JSON.stringify({timestamp:new Date().toISOString(),...r,agents:Object.fromEntries(r.agents)}));else{let o=new Date().toLocaleTimeString();console.log(`${a.dim(o)} ${a.info("State:")} ${r.agents.size} agents, ${r.inbox.length} inbox items`)}},onEvent:s=>{if(t.json)console.log(JSON.stringify({type:"event",event:s}));else{let r=new Date().toLocaleTimeString();console.log(`${a.dim(r)} ${a.secondary("Event:")} ${s.type}`)}},onError:s=>{v.error(`Error: ${s.message}`)}});i.start()||(console.log(),v.warn("No active session found."),console.log(a.dim(" Start a GemKit session first with: gk agent")),console.log(),process.exit(1)),process.on("SIGINT",()=>{i.stop(),e.dispose(),console.log(),v.info("Stopped watching."),console.log(),process.exit(0)})}function MA(t){t.command("office [subcommand]","Agent Office visualization (start, status, watch)").option("-p, --port <port>","[start] Web server port",{default:3847}).option("--no-open","[start] Don't auto-open browser").option("--json","[status/watch] Output as JSON").action(async(e,i)=>{if(i.port&&(i.port=parseInt(String(i.port),10)),i.help||i.h)switch(e){case"start":k9();return;case"status":V9();return;case"watch":N9();return;default:tm();return}switch(e){case"start":await F9(i);break;case"status":b9(i);break;case"watch":P9(i);break;case void 0:case"help":tm();break;default:console.log(),v.error(`Unknown subcommand: ${e}`),tm(),process.exit(1)}})}k();ga();en();import{spawn as Q9,execSync as Ba}from"child_process";import{access as B9,stat as J9,readdir as Z9,readFile as YA}from"fs/promises";import{join as Hn,basename as y9,extname as q9,relative as WA}from"path";Do();Xs();Ls();Nn();function CA(){console.log(),console.log(h.default.bold(a.geminiPurple("Team Management"))),console.log(),console.log("Usage:"),console.log(` ${a.primary("gk team")} <subcommand> [options]`),console.log(),console.log("Team Operations:"),console.log(` ${a.primary("create")} <name> Create a new team`),console.log(` ${a.primary("list")} List all teams`),console.log(` ${a.primary("info")} [teamId] Show team details`),console.log(),console.log("Agent Spawning:"),console.log(` ${a.primary("start")} --name <agent> Start agent as team member`),console.log(` ${a.primary("add-member")} <name> Register member (no spawn)`),console.log(),console.log("Task Operations:"),console.log(` ${a.primary("task-create")} <subject> Create a task`),console.log(` ${a.primary("task-claim")} <taskId> Claim a task`),console.log(` ${a.primary("task-done")} <taskId> Mark task completed`),console.log(` ${a.primary("tasks")} [teamId] List all tasks`),console.log(),console.log("Messaging & Inbox:"),console.log(` ${a.primary("send")} <to> <message> Send message to member`),console.log(` ${a.primary("broadcast")} <message> Send to all members`),console.log(` ${a.primary("messages")} View central inbox (all activity)`),console.log(` ${a.primary("respond")} <msgId> Respond to approval request`),console.log(),console.log("Agent Interaction:"),console.log(` ${a.primary("exchange")} <agent> Get structured output from agent`),console.log(` ${a.primary("read")} <agent> Read raw output from agent`),console.log(),console.log("Maintenance:"),console.log(` ${a.primary("ports")} Show port allocations`),console.log(` ${a.primary("cleanup")} Clean up stale resources`),console.log(` ${a.primary("kill")} [teamId] Emergency shutdown`),console.log(` ${a.primary("reset")} Delete all team data`),console.log(),console.log("Examples:"),console.log(` ${a.dim("gk team create jwt-research")}`),console.log(` ${a.dim("gk team start --name researcher-1 -a researcher")}`),console.log(` ${a.dim("gk team start --name planner -a planner -c @plans/")}`),console.log(` ${a.dim('gk team task-create "Research JWT security"')}`),console.log(` ${a.dim('gk team send researcher-1 "Claim task X"')}`),console.log(` ${a.dim("gk team messages --pending")}`),console.log(` ${a.dim("gk team respond <msgId> --approve")}`),console.log()}function OA(t){t.command("team [subcommand] [arg] [arg2]","Team management (list, info, tasks)").option("--json","Output as JSON").option("--desc <description>","Description for team/task").option("--blocked-by <taskIds>","Comma-separated task IDs that block this task").option("--as <agentName>","Act as this agent (for testing)").option("--pending","[messages] Show only pending items").option("--type <type>","[messages] Filter by message type").option("--from <name>","[messages] Filter by sender name").option("--to <name>","[messages] Filter by recipient name").option("--limit <n>","[messages] Limit results").option("--approve","[respond] Approve the request").option("--reject <reason>","[respond] Reject with reason").option("--approve-all","[respond] Approve all pending requests").option("--name <memberName>","[start] Agent name in team (required)").option("--role <role>","[start] Role: leader or member (default: member)").option("-a, --agent <profile>","[start] Agent profile name").option("-s, --skills <list>","[start] Comma-separated skill names").option("-m, --model <model>","[start] Model override").option("-t, --tools <list>","[start] Comma-separated tools").option("-c, --context <files>","[start] Context files (@file syntax)").option("--cli <provider>","[start] CLI provider: gemini (default) or claude").action(async(e,i,n,s)=>{if(s.help||s.h){CA();return}let r=ge(process.cwd());switch(e){case"create":await eR(r,i,s);break;case"add-member":await tR(r,i,s);break;case"list":await w9(r,s);break;case"info":await D9(r,i,s);break;case"task-create":await iR(r,i,s);break;case"task-claim":await nR(r,i,s);break;case"task-done":await sR(r,i,s);break;case"tasks":await T9(r,i,s);break;case"send":await rR(r,i,n,s);break;case"broadcast":await oR(r,i,s);break;case"messages":await aR(r,s);break;case"respond":await cR(r,i,s);break;case"start":await lR(r,s);break;case"exchange":await mR(r,i,s);break;case"read":await vR(r,i);break;case"ports":await X9(r,s);break;case"cleanup":await H9(r);break;case"kill":await _9(r,i);break;case"reset":await $9(r);break;case"_server":await uR();break;default:CA()}})}async function w9(t,e){let i=It(t);if(e.json){console.log(JSON.stringify(i,null,2));return}if(console.log(),console.log(h.default.bold(a.geminiPurple("Teams"))),console.log(),i.length===0){console.log(a.dim(" No teams found in this project.")),console.log();return}for(let n of i){let s=n.status==="active"?a.success:a.dim;console.log(` ${a.primary(n.teamName)} ${a.dim(`(${n.teamId.slice(0,12)}...)`)}`),console.log(` Status: ${s(n.status)}`),console.log(` Members: ${n.members.length}`),console.log(` Created: ${n.createdAt}`),console.log()}}async function D9(t,e,i){if(!e){let s=It(t).filter(r=>r.status==="active");if(s.length===0){v.error("No active team found. Specify team ID.");return}e=s[0].teamId}let n=Q(t,e);if(!n){v.error(`Team not found: ${e}`);return}if(i.json){console.log(JSON.stringify(n,null,2));return}console.log(),console.log(G.doubleLine()),console.log(h.default.bold(a.geminiPurple(`Team: ${n.teamName}`))),console.log(G.doubleLine()),console.log(),console.log(` ${a.dim("ID:")} ${n.teamId}`),console.log(` ${a.dim("Status:")} ${n.status}`),console.log(` ${a.dim("Description:")} ${n.description||"(none)"}`),console.log(` ${a.dim("Leader:")} ${n.leaderId.slice(0,20)}...`),console.log(` ${a.dim("Leader Port:")} ${n.leaderPort}`),console.log(` ${a.dim("Created:")} ${n.createdAt}`),console.log(),console.log(a.dim(" --- Members ---")),console.log();for(let s of n.members){let r={ready:a.success("\u25CF"),busy:a.warn("\u25CF"),idle:a.dim("\u25CF"),shutdown:a.error("\u25CF"),starting:a.dim("\u25CB")}[s.status]||a.dim("?");console.log(` ${r} ${a.primary(s.name)} (${s.role})`),console.log(` Agent ID: ${s.agentId.slice(0,20)}...`),console.log(` Port: ${s.port}, PID: ${s.pid||"N/A"}`),console.log(` Status: ${s.status}`),console.log()}}async function T9(t,e,i){if(!e){let r=It(t).filter(o=>o.status==="active");if(r.length===0){v.error("No active team found. Specify team ID.");return}e=r[0].teamId}let n=fi(t,e),s=da(t,e);if(i.json){console.log(JSON.stringify({...n,summary:s},null,2));return}if(console.log(),console.log(h.default.bold(a.geminiPurple("Tasks"))),console.log(),console.log(` Total: ${s.total} | ${a.success("Completed:")} ${s.completed} | ${a.warn("In Progress:")} ${s.inProgress} | ${a.dim("Pending:")} ${s.pending} | ${a.error("Blocked:")} ${s.blocked}`),console.log(),n.tasks.length===0){console.log(a.dim(" No tasks.")),console.log();return}if(n.available.length>0){console.log(a.success(" Available (ready to claim):"));for(let r of n.available)console.log(` ${a.dim(r.taskId.slice(0,12))} ${r.subject}`);console.log()}if(n.inProgress.length>0){console.log(a.warn(" In Progress:"));for(let r of n.inProgress)console.log(` ${a.dim(r.taskId.slice(0,12))} ${r.subject} ${a.dim(`[${r.owner}]`)}`);console.log()}if(n.blocked.length>0){console.log(a.error(" Blocked:"));for(let r of n.blocked)console.log(` ${a.dim(r.taskId.slice(0,12))} ${r.subject}`),console.log(` ${a.dim("Waiting on:")} ${r.blockedBy.map(o=>o.slice(0,8)).join(", ")}`);console.log()}if(n.completed.length>0){console.log(a.success(" Completed:"));for(let r of n.completed.slice(-5))console.log(` ${a.dim(r.taskId.slice(0,12))} ${a.dim(r.subject)}`);n.completed.length>5&&console.log(a.dim(` ... and ${n.completed.length-5} more`)),console.log()}}async function X9(t,e){let i=Iu(t);if(e.json){console.log(JSON.stringify(i,null,2));return}if(console.log(),console.log(h.default.bold(a.geminiPurple("Port Allocations"))),console.log(),console.log(` Range: 3377-3476 (${i.total} ports)`),console.log(` Used: ${i.used}`),console.log(` Available: ${i.available}`),console.log(),Object.keys(i.byTeam).length>0){console.log(a.dim(" By Team:"));for(let[n,s]of Object.entries(i.byTeam))console.log(` ${n.slice(0,20)}...: ${s} ports`);console.log()}}async function H9(t){console.log(),v.info("Cleaning up stale ports and orphaned members...");let e=await zu(t);e.orphansFound>0&&v.success(`Found ${e.orphansFound} orphaned member(s), cleaned ${e.cleaned}.`);let i=await rr(t);i>0&&v.success(`Released ${i} additional stale port(s).`),e.orphansFound===0&&i===0&&v.info("No stale resources found."),console.log(),console.log(a.dim(` Teams checked: ${e.teamsChecked}`)),console.log(a.dim(` Members checked: ${e.membersChecked}`)),console.log()}async function L9(){let i=0,n=new Set;try{if(process.platform==="win32"){let s=Ba("netstat -ano",{encoding:"utf-8",timeout:15e3});for(let r of s.split(`
3608
+ `)){let o=r.match(/TCP\s+(?:127\.0\.0\.1|0\.0\.0\.0):(\d+)\s+\S+\s+LISTENING\s+(\d+)/i);if(o){let c=parseInt(o[1],10),l=parseInt(o[2],10);c>=3377&&c<=3476&&l>0&&n.add(l)}}}else{let s="";try{s=Ba("lsof -iTCP:3377-3476 -sTCP:LISTEN -t 2>/dev/null",{encoding:"utf-8",timeout:15e3})}catch{try{s=Ba("ss -tlnp 2>/dev/null | grep -E ':3[34][0-9]{2}\\s'",{encoding:"utf-8",timeout:15e3});let r=s.matchAll(/pid=(\d+)/g);for(let o of r){let c=parseInt(o[1],10);c>1&&n.add(c)}s=""}catch{}}if(s)for(let r of s.trim().split(`
3609
+ `)){let o=parseInt(r.trim(),10);o>1&&n.add(o)}}}catch{}for(let s of n)try{process.platform==="win32"?Ba(`taskkill /F /T /PID ${s}`,{stdio:["pipe","pipe","pipe"],timeout:5e3}):process.kill(s,"SIGKILL"),i++,v.info(` Killed orphaned process PID ${s}`)}catch{}return i}async function _9(t,e){if(!e){let s=It(t).filter(l=>l.status==="active"),r=0,o=0;if(s.length>0){console.log(),v.warn(`Emergency shutdown of ${s.length} team(s)...`);for(let l of s){let u=await ha(t,l.teamId);r+=u.killed,o+=u.cleaned,v.info(` ${l.teamName}: killed ${u.killed}, cleaned ${u.cleaned}`)}}console.log(),v.info("Scanning for orphaned processes on ports 3377-3476...");let c=await L9();r+=c,r===0&&o===0?v.info("No processes found to kill."):v.success(`Total: ${r} process(es) killed, ${o} member(s) cleaned up.`),console.log();return}let i=Q(t,e);if(!i){console.log(),v.error(`Team not found: ${e}`),console.log();return}console.log(),v.warn(`Emergency shutdown of team "${i.teamName}"...`);let n=await ha(t,e);v.success(`Killed ${n.killed} process(es), cleaned up ${n.cleaned} member(s).`),console.log()}async function $9(t){console.log(),v.warn("This will delete ALL team data for this project!"),v.warn("Teams, tasks, messages, and port allocations will be removed."),console.log(),du(t)?v.success("All team data deleted."):v.error("Failed to delete team data."),console.log()}var Ja=null,Za=null;function lr(t){return t.as?{agentId:`cli-${t.as}`,agentName:t.as}:Ja&&Za?{agentId:Ja,agentName:Za}:(Ja=`cli-leader-${Et("cli-leader",process.pid).slice(0,8)}`,Za="leader",{agentId:Ja,agentName:Za})}function Gi(t){let e=It(t).filter(i=>i.status==="active");return e.length>0?e[0].teamId:null}async function eR(t,e,i){if(!e){v.error("Team name required."),console.log(a.dim('Usage: gk team create <name> [--desc "description"]'));return}let{agentId:n,agentName:s}=lr({}),r=Jt(t,n,"pending");if(!r){v.error("No ports available");return}let o=_o({teamName:e,description:i.desc||"",leaderId:n,leaderPort:r,projectDir:t});o?(console.log(),v.success(`Team created: ${o.teamName}`),console.log(` Team ID: ${a.primary(o.teamId)}`),console.log(` Leader: ${s} (${n.slice(0,16)}...)`),console.log(` Port: ${r}`),console.log()):v.error("Failed to create team.")}async function tR(t,e,i){if(!e){v.error("Member name required."),console.log(a.dim("Usage: gk team add-member <name>"));return}let n=Gi(t);if(!n){v.error("No active team. Create one first with: gk team create <name>");return}let s=`cli-${e}-${Et("cli-member",process.pid).slice(0,8)}`,r=Jt(t,s,n);if(!r){v.error("No ports available");return}gi(t,n,{agentId:s,name:e,agentType:"cli-agent",role:"member",port:r,pid:null,status:"ready"})?(console.log(),v.success(`Added member: ${e}`),console.log(` Agent ID: ${s.slice(0,20)}...`),console.log(` Port: ${r}`),console.log()):v.error("Failed to add member.")}async function iR(t,e,i){if(!e){v.error("Task subject required."),console.log(a.dim('Usage: gk team task-create <subject> [--desc "..."] [--blocked-by "id1,id2"]'));return}let n=Gi(t);if(!n){v.error("No active team.");return}let{agentName:s}=lr({}),r=i.blockedBy?i.blockedBy.split(",").map(c=>c.trim()):void 0,o=va(t,n,e,i.desc||e,s,{blockedBy:r});o?(console.log(),v.success(`Task created: ${o.subject}`),console.log(` Task ID: ${a.primary(o.taskId)}`),r&&r.length>0&&console.log(` Blocked by: ${r.join(", ")}`),console.log()):v.error("Failed to create task.")}async function nR(t,e,i){if(!e){v.error("Task ID required."),console.log(a.dim("Usage: gk team task-claim <taskId> [--as <agentName>]"));return}let{agentName:n}=lr(i);pa(t,e,n)?v.success(`${n} claimed task: ${e}`):v.error(`Failed to claim task: ${e}`)}async function sR(t,e,i){if(!e){v.error("Task ID required."),console.log(a.dim("Usage: gk team task-done <taskId>"));return}await Aa(t,e)?v.success(`Task completed: ${e}`):v.error(`Failed to complete task: ${e}`)}async function rR(t,e,i,n){if(!e||!i){v.error("Recipient and message required."),console.log(a.dim("Usage: gk team send <to> <message> [--as <sender>]"));return}let s=Gi(t);if(!s){v.error("No active team.");return}let r=Q(t,s);if(!r){v.error("Team not found.");return}let o=r.members.find(m=>m.name===e);if(!o){v.error(`Member not found: ${e}`),console.log(` Available: ${r.members.map(m=>m.name).join(", ")}`);return}let{agentId:c,agentName:l}=lr(n);await la(t,s,c,l,o.agentId,o.name,i,i.slice(0,50))?v.success(`Message sent to ${e}`):v.error("Failed to send message.")}async function oR(t,e,i){if(!e){v.error("Message required."),console.log(a.dim("Usage: gk team broadcast <message> [--as <sender>]"));return}let n=Gi(t);if(!n){v.error("No active team.");return}let{agentId:s,agentName:r}=lr(i),o=await ua(t,n,s,r,e,e.slice(0,50));v.success(`Broadcast sent to ${o.length} member(s)`)}async function aR(t,e){let i=Gi(t);if(!i){v.error("No active team.");return}let n={};e.pending&&(n.status="pending"),e.type&&(n.type=e.type),e.from&&(n.from=e.from),e.to&&(n.to=e.to),e.limit&&(n.limit=parseInt(e.limit,10));let s=Qt(t,i,n);if(e.json){console.log(JSON.stringify(s,null,2));return}if(console.log(),console.log(h.default.bold(a.geminiPurple("Team Inbox"))),console.log(),s.length===0){console.log(a.dim(" No messages found.")),console.log();return}let r=s.filter(u=>u.status==="pending"),o=s.filter(u=>u.status==="delivered"),c=s.filter(u=>u.status==="processed");if(r.length>0){console.log(a.warn(` Pending (${r.length}):`));for(let u of r.slice(-10))console.log(` ${Jn(u)}`);console.log()}if(o.length>0&&!e.pending){console.log(a.primary(` Delivered (${o.length}):`));for(let u of o.slice(-5))console.log(` ${Jn(u)}`);console.log()}if(c.length>0&&!e.pending){console.log(a.success(` Processed (${c.length}):`));for(let u of c.slice(-5))console.log(` ${Jn(u)}`);console.log()}let l=s.filter(u=>u.type==="approval_request"&&u.status==="pending");l.length>0&&(console.log(a.warn(` \u{1F4A1} ${l.length} pending approval(s). Use:`)),console.log(a.dim(" gk team respond <msgId> --approve")),console.log())}async function cR(t,e,i){let n=Gi(t);if(!n){v.error("No active team.");return}if(i.approveAll){let c=$o(t,n);if(c.length===0){console.log(),v.info("No pending approval requests."),console.log();return}console.log(),v.info(`Processing ${c.length} pending approval(s)...`);let l=0,u=0;for(let m of c){let p=await ca(t,n,m.id,!0);p.success?(v.success(`Approved: ${m.summary}`),l++):(v.warn(`Failed: ${m.summary} - ${p.error}`),u++)}console.log(),v.info(`Results: ${l} approved, ${u} failed`),console.log();return}if(!e){console.log(),v.error("Message ID required."),console.log(a.dim("Usage: gk team respond <messageId> --approve")),console.log(a.dim(' gk team respond <messageId> --reject "reason"')),console.log(a.dim(" gk team respond --approve-all")),console.log();return}if(!i.approve&&!i.reject){console.log(),v.error('Must specify --approve or --reject "reason"'),console.log();return}let s=i.approve===!0,r=i.reject,o=await ca(t,n,e,s,r);console.log(),o.success?s?v.success(`Approved: ${o.action}`):v.info(`Rejected: ${o.action}`):v.error(o.error||"Failed to process response"),console.log()}async function lR(t,e){e.name||(console.log(),v.error("Agent name required. Use --name <agentName>"),console.log(a.dim("Usage: gk team start --name <agentName> [options]")),console.log(),process.exit(1));let i=Gi(t);i||(console.log(),v.error("No active team. Create one first: gk team create <name>"),console.log(),process.exit(1));let n=Q(t,i);n||(v.error("Team not found."),process.exit(1));let s=e.cli==="claude"?"claude":"gemini",r=Ie(),o=e.name,c=e.role==="leader"?"leader":"member",l=Et(`team-${o}`,process.pid),u=null,m=o.replace(/-\d+$/,""),p=e.agent||m;u=Fn(p,s),!u&&e.agent&&(console.log(),v.error(`Agent profile not found: ${e.agent}`),console.log(),process.exit(1));let d=e.model||u?.model||r.spawn.defaultModel;d=mi(d,s);let A=e.tools?.split(",").map(ie=>ie.trim()).filter(Boolean)||[],f=u?.tools||[],g=[...new Set([...f,...A])],E=vi(g,s),J=e.skills?.split(",").map(ie=>ie.trim()).filter(Boolean)||[],M=u?.skills||[],rt=[...new Set([...M,...J])],y={};for(let ie of rt){let Ze=bn(ie);Ze&&(y[ie]=Ze)}let te=[];if(e.context){let ie=e.context.split(",").flatMap(Ze=>Ze.trim().split(/\s+/).filter(at=>at)).filter(Ze=>Ze);for(let Ze of ie)try{let at=await AR(Ze);Array.isArray(at)?te.push(...at):te.push(at)}catch(at){console.log(),v.error(at.message),console.log(),process.exit(1)}}let U=Jt(t,l,i);U||(console.log(),v.error("No ports available for team member"),console.log(),process.exit(1)),gi(t,i,{agentId:l,name:o,agentType:e.agent||"default",role:c,port:U,pid:null,status:"starting"})||(Me(t,l),console.log(),v.error("Failed to register in team"),console.log(),process.exit(1));let Ln={provider:s,model:d,port:U,pid:0,isFirstSend:!0,context:{agentName:u?.name||null,agentContent:u?.content||null,skills:rt,skillContents:y,contextFiles:te,tools:E},team:{teamId:i,teamName:n.teamName,role:c,agentId:l,agentName:o,leaderPort:n.leaderPort,projectDir:t},startedAt:new Date().toISOString()};if($i(Ln,void 0,o),console.log(),v.info(`Starting ${a.primary(o)} in team ${a.dim(n.teamName)}...`),v.info(`Provider: ${a.primary(s)}, Model: ${a.primary(d)}`),v.info(`Port: ${a.dim(U.toString())}`),u){let ie=e.agent?"":" (auto-derived)";v.info(`Agent: ${a.dim(u.name)}${a.dim(ie)}`)}rt.length>0&&v.info(`Skills: ${a.dim(rt.join(", "))}`),te.length>0&&v.info(`Context: ${a.dim(te.map(ie=>ie.name).join(", "))}`),E.length>0&&v.info(`Tools: ${a.dim(E.join(", "))}`),console.log();let qa={...process.env,GK_TEAM_ID:i,GK_TEAM_NAME:n.teamName,GK_TEAM_ROLE:c,GK_TEAM_PORT:U.toString(),GK_TEAM_LEADER_PORT:n.leaderPort.toString(),GK_AGENT_NAME:o,GK_SUB_SESSION_ID:l},wa=process.argv[1],Ae=Q9(process.execPath,[wa,"team","_server"],{detached:!0,stdio:"ignore",windowsHide:!0,cwd:process.cwd(),env:qa});Ae.unref(),Ln.pid=Ae.pid||0,$i(Ln,void 0,o),Ae.pid&&(Au(t,i,l,Ae.pid),Z(t,i,l,"ready")),v.info(`Server started (PID: ${Ae.pid})`),v.info("Waiting for AI to initialize...");let ot=new ee(U),K=120;for(let ie=0;ie<K;ie++){await pR(1e3);try{if((await ot.status()).ready){console.log(),v.success(`${o} ready!`),console.log(),console.log("Monitor:"),console.log(` ${a.dim("gk team messages --pending")}`),console.log(` ${a.dim("gk team respond <msgId> --approve")}`),console.log(` ${a.dim("gk team respond --approve-all")}`),console.log(` ${a.dim(`gk team exchange ${o}`)}`),console.log(),console.log("Send messages:"),console.log(` ${a.dim(`gk team send ${o} "your message"`)}`),console.log();return}}catch{}process.stdout.write(".")}console.log(),v.warn("Server started but AI may still be initializing."),console.log()}async function uR(){let t=process.env.GK_AGENT_NAME;t||(console.error("[TeamServer] No agent name in environment"),process.exit(1));let e=Ge(void 0,t);e||(console.error("[TeamServer] No session state found"),process.exit(1));let{PtyServer:i}=await Promise.resolve().then(()=>(xu(),Gp)),n=new i({provider:e.provider,model:e.model,tools:e.context.tools,sessionState:e,port:e.port,debug:!1});try{await n.start()}catch(s){console.error(`[TeamServer] Failed to start: ${s.message}`),et(void 0,t),process.exit(1)}process.on("SIGINT",async()=>{await n.stop(),et(void 0,t),process.exit(0)}),process.on("SIGTERM",async()=>{await n.stop(),et(void 0,t),process.exit(0)})}async function mR(t,e,i){e||(console.log(),v.error("Agent name required."),console.log(a.dim("Usage: gk team exchange <agentName>")),console.log(),process.exit(1));let n=UA(t,e);n||(v.error(`Agent not found or not running: ${e}`),process.exit(1));let s=new ee(n);try{let r=await s.exchange();console.log(JSON.stringify(r,null,2))}catch(r){v.error(r.message),process.exit(1)}}async function vR(t,e){e||(console.log(),v.error("Agent name required."),console.log(a.dim("Usage: gk team read <agentName>")),console.log(),process.exit(1));let i=UA(t,e);i||(v.error(`Agent not found or not running: ${e}`),process.exit(1));let n=new ee(i);try{let s=await n.read(200);console.log(s)}catch(s){v.error(s.message),process.exit(1)}}function UA(t,e){let i=Gi(t);if(!i)return null;let n=Q(t,i);return n?n.members.find(r=>r.name===e)?.port??null:null}function pR(t){return new Promise(e=>setTimeout(e,t))}async function AR(t){let e=t;if(t.startsWith("@")){let s=t.substring(1),r=[Hn(process.cwd(),".docs",s),Hn(process.cwd(),".plans",s),Hn(process.cwd(),"docs",s),Hn(process.cwd(),"plans",s),Hn(process.cwd(),s)],o=!1;for(let c of r)try{await B9(c),e=c,o=!0;break}catch{continue}if(!o)throw new Error(`Context file not found: ${t}`)}if((await J9(e)).isDirectory()){let s=[],r=[".md",".txt",".json",".yaml",".yml"];async function o(c,l=0){if(l>3)return;let u=await Z9(c,{withFileTypes:!0});for(let m of u){if(m.name.startsWith("."))continue;let p=Hn(c,m.name);if(m.isDirectory())await o(p,l+1);else if(m.isFile()){let d=q9(m.name).toLowerCase();if(r.includes(d)){let A=await YA(p,"utf-8");s.push({type:"context",name:m.name,path:p,relativePath:WA(e,p),content:A.trim(),originalRef:`${t}/${WA(e,p)}`})}}}}return await o(e),s}let n=await YA(e,"utf-8");return{type:"context",name:y9(e),path:e,content:n.trim(),originalRef:t}}function KA(t){Yv(t),Sv(t),Wv(t),Ov(t),Uv(t),Kv(t),kv(t),Hp(t),Lp(t),eA(t),nA(t),sA(t),rA(t),cA(t),gA(t),MA(t),OA(t)}import{existsSync as kA,readFileSync as dR,writeFileSync as fR,mkdirSync as hR}from"fs";import{join as gR,dirname as IR}from"path";import{homedir as ER}from"os";var ya=gR(ER(),".gemkit","last-update-check.json");function VA(){try{return kA(ya)?JSON.parse(dR(ya,"utf-8")):null}catch{return null}}function RR(t){try{let e=IR(ya);kA(e)||hR(e,{recursive:!0}),fR(ya,JSON.stringify(t,null,2))}catch{}}function zR(t){let e=VA();if(!e)return!0;let i=new Date(e.lastCheck);return(new Date().getTime()-i.getTime())/(1e3*60*60)>=t}async function NA(){let e=Ie().update;if(e?.autoCheck&&zR(e.checkInterval))try{let i=await Gv(),n=VA()||{lastCheck:""},s=[];i.cli?.available&&n.notifiedCli!==i.cli.latest&&(s.push(`${a.primary("CLI")} update available: v${i.cli.current} \u2192 v${i.cli.latest}`),n.notifiedCli=i.cli.latest),i.kits?.available&&n.notifiedKits!==i.kits.latest&&(s.push(`${a.primary("Kits")} update available: v${i.kits.current} \u2192 v${i.kits.latest}`),n.notifiedKits=i.kits.latest),s.length>0&&(console.log(),console.log(a.dim("\u2500".repeat(50))),console.log(`${a.warn("\u2B06")} Updates available:`),s.forEach(r=>console.log(` ${r}`)),console.log(` Run ${a.primary("gk update")} to update.`),console.log(a.dim("\u2500".repeat(50))),console.log()),n.lastCheck=new Date().toISOString(),RR(n)}catch{}}var Mi=lm("gk");Mi.version(Pe);Mi.help();Mi.option("--verbose","Enable verbose output");Mi.option("--json","Output as JSON");Mi.option("--no-update-check","Skip auto-update check");var im=Mi.parse(process.argv,{run:!1});im.options.verbose&&Jo({level:"debug",verbose:!0});im.options.json&&Jo({json:!0});KA(Mi);im.options.updateCheck!==!1&&NA().catch(()=>{});Mi.parse();