just-bash 3.6.0 → 3.6.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 (887) hide show
  1. package/CHANGELOG.md +53 -0
  2. package/README.md +6 -0
  3. package/dist/bin/chunks/awk2-EPZ2CEQT.js +3 -0
  4. package/dist/bin/chunks/base64-D7ZXJQN6.js +3 -0
  5. package/dist/bin/chunks/bash-4Q4RMIZL.js +3 -0
  6. package/dist/bin/chunks/cat-AST5Y57Y.js +3 -0
  7. package/dist/bin/chunks/chmod-BFP7P5CD.js +3 -0
  8. package/dist/bin/chunks/chunk-26O2G5LX.js +34 -0
  9. package/dist/bin/chunks/chunk-2RDKEB6Z.js +15 -0
  10. package/dist/bin/chunks/chunk-35U2THFB.js +3 -0
  11. package/dist/bin/chunks/chunk-3F7UWBEM.js +17 -0
  12. package/dist/bin/chunks/chunk-3WLAERUX.js +3 -0
  13. package/dist/bin/chunks/chunk-3WZIZUMC.js +8 -0
  14. package/dist/bin/chunks/chunk-4ARWO6Y3.js +4 -0
  15. package/dist/bin/chunks/chunk-4HVMRZ5N.js +8 -0
  16. package/dist/bin/chunks/chunk-5AS7PRVN.js +34 -0
  17. package/dist/bin/chunks/chunk-5GYAEVIB.js +10 -0
  18. package/dist/bin/chunks/chunk-5IPYW47P.js +27 -0
  19. package/dist/bin/chunks/chunk-5ZTIV6TI.js +20 -0
  20. package/dist/bin/chunks/chunk-6C2YS7G6.js +14 -0
  21. package/dist/bin/chunks/chunk-74MYVPDY.js +3 -0
  22. package/dist/bin/chunks/chunk-74UP5NWP.js +3 -0
  23. package/dist/bin/chunks/chunk-7DPD5PK3.js +3 -0
  24. package/dist/bin/chunks/chunk-7LJGZPVP.js +18 -0
  25. package/dist/bin/chunks/chunk-7NEXHFSS.js +3 -0
  26. package/dist/bin/chunks/chunk-7XFMCB5C.js +21 -0
  27. package/dist/bin/chunks/chunk-A53Y4KDG.js +7 -0
  28. package/dist/bin/chunks/chunk-AALAYQ6J.js +17 -0
  29. package/dist/bin/chunks/chunk-AM4WIHAG.js +10 -0
  30. package/dist/bin/chunks/chunk-BC5OXEFJ.js +3 -0
  31. package/dist/bin/chunks/chunk-C5ABXV4P.js +15 -0
  32. package/dist/bin/chunks/chunk-CT6P7ILU.js +3 -0
  33. package/dist/bin/chunks/chunk-CYHG3NVG.js +9 -0
  34. package/dist/bin/chunks/chunk-D7PDAJWE.js +7 -0
  35. package/dist/bin/chunks/chunk-DB3G3UVZ.js +5 -0
  36. package/dist/bin/chunks/chunk-EIUU35ZP.js +37 -0
  37. package/dist/bin/chunks/chunk-EMHJNKV5.js +20 -0
  38. package/dist/bin/chunks/chunk-EPWMLTS6.js +9 -0
  39. package/dist/bin/chunks/chunk-F4QFFLWZ.js +8 -0
  40. package/dist/bin/chunks/chunk-F5R5O2Y6.js +9 -0
  41. package/dist/bin/chunks/chunk-FBEYY2HM.js +13 -0
  42. package/dist/bin/chunks/chunk-FIJBWMXU.js +12 -0
  43. package/dist/bin/chunks/chunk-FMVH4N2P.js +5 -0
  44. package/dist/bin/chunks/chunk-G6W2HMNY.js +7 -0
  45. package/dist/bin/chunks/chunk-GFI5BHZX.js +3 -0
  46. package/dist/bin/chunks/chunk-GJAVHEWO.js +143 -0
  47. package/dist/bin/chunks/chunk-GUVSOVQU.js +8 -0
  48. package/dist/bin/chunks/chunk-H22PAKR6.js +3 -0
  49. package/dist/bin/chunks/chunk-HXOJHK2Z.js +8 -0
  50. package/dist/bin/chunks/chunk-IAAYIH44.js +3 -0
  51. package/dist/bin/chunks/chunk-J7W2CRXT.js +7 -0
  52. package/dist/bin/chunks/chunk-JNWWOKCN.js +6 -0
  53. package/dist/bin/chunks/chunk-JQLGE4OW.js +22 -0
  54. package/dist/bin/chunks/chunk-K3U4M4MF.js +7 -0
  55. package/dist/bin/chunks/chunk-KRXYOWIP.js +12 -0
  56. package/dist/bin/chunks/chunk-L4L2QFS4.js +10 -0
  57. package/dist/bin/chunks/chunk-LU6ZEQNN.js +13 -0
  58. package/dist/bin/chunks/chunk-MLMKRR7L.js +12 -0
  59. package/dist/bin/chunks/chunk-MVN5WALS.js +7 -0
  60. package/dist/bin/chunks/chunk-MYOGTYIH.js +22 -0
  61. package/dist/bin/chunks/chunk-NF5LHCVV.js +275 -0
  62. package/dist/bin/chunks/chunk-OUGDZVL6.js +10 -0
  63. package/dist/bin/chunks/chunk-QCNQD6ME.js +11 -0
  64. package/dist/bin/chunks/chunk-QIDBJNMB.js +3 -0
  65. package/dist/bin/chunks/chunk-QKTQYL37.js +9 -0
  66. package/dist/bin/chunks/chunk-R6CMNMNX.js +22 -0
  67. package/dist/bin/chunks/chunk-RCP3WQND.js +7 -0
  68. package/dist/bin/chunks/chunk-RJG4JS32.js +6 -0
  69. package/dist/bin/chunks/chunk-SIMSIBUA.js +13 -0
  70. package/dist/bin/chunks/chunk-TNB7M24H.js +87 -0
  71. package/dist/bin/chunks/chunk-TU6P6AC2.js +4 -0
  72. package/dist/bin/chunks/chunk-TX4WSLXK.js +101 -0
  73. package/dist/bin/chunks/chunk-U4UY6P77.js +3 -0
  74. package/dist/bin/chunks/chunk-U5BNATW4.js +3 -0
  75. package/dist/bin/chunks/chunk-U7VJCJQR.js +16 -0
  76. package/dist/bin/chunks/chunk-VJE2PQW6.js +15 -0
  77. package/dist/bin/chunks/chunk-W4ENG3BR.js +44 -0
  78. package/dist/bin/chunks/chunk-XUFO4QPW.js +65 -0
  79. package/dist/bin/chunks/chunk-XVKL2UZA.js +4 -0
  80. package/dist/bin/chunks/chunk-YCUNLSHF.js +12 -0
  81. package/dist/bin/chunks/chunk-YDH7Q5WV.js +6 -0
  82. package/dist/bin/chunks/chunk-YDWLU56G.js +26 -0
  83. package/dist/bin/chunks/chunk-YILPYZYP.js +16 -0
  84. package/dist/bin/chunks/chunk-YZQ4SVJV.js +13 -0
  85. package/dist/bin/chunks/chunk-ZKLKNN6B.js +3 -0
  86. package/dist/bin/chunks/column-EGAQ7QMC.js +3 -0
  87. package/dist/bin/chunks/comm-JEJ6GWEA.js +3 -0
  88. package/dist/bin/chunks/cp-7AH7TSQ6.js +3 -0
  89. package/dist/bin/chunks/curl-7FCZQCFU.js +31 -0
  90. package/dist/bin/chunks/cut-OVTLUT2B.js +3 -0
  91. package/dist/bin/chunks/date-MKP5YWWY.js +3 -0
  92. package/dist/bin/chunks/diff-R6QTSWD2.js +3 -0
  93. package/dist/bin/chunks/du-M2PB5NUH.js +3 -0
  94. package/dist/bin/chunks/env-EUSAZGWO.js +3 -0
  95. package/dist/bin/chunks/expand-B4CPOZN5.js +3 -0
  96. package/dist/bin/chunks/expr-AQBMSEFL.js +3 -0
  97. package/dist/bin/chunks/file-22CVQBNS.js +3 -0
  98. package/dist/bin/chunks/find-QYLHUYOP.js +3 -0
  99. package/dist/bin/chunks/flag-coverage-CTPK5ZWJ.js +3 -0
  100. package/dist/bin/chunks/fold-E6A5I4DW.js +3 -0
  101. package/dist/bin/chunks/grep-HI55D7F7.js +3 -0
  102. package/dist/bin/chunks/gzip-2GJMVXCF.js +3 -0
  103. package/dist/bin/chunks/head-ZQIB2GSI.js +3 -0
  104. package/dist/bin/chunks/html-to-markdown-7ZNLM4SQ.js +3 -0
  105. package/dist/bin/chunks/join-KCYMLQ3V.js +3 -0
  106. package/dist/bin/chunks/jq-KNI4FJIL.js +3 -0
  107. package/dist/bin/chunks/js-exec-OWDAX677.js +1617 -0
  108. package/dist/bin/chunks/ls-QCAGDEDW.js +3 -0
  109. package/dist/bin/chunks/md5sum-OPJ77ZY7.js +3 -0
  110. package/dist/bin/chunks/mkdir-3XFSFVPC.js +3 -0
  111. package/dist/bin/chunks/mktemp-5FA55IJS.js +3 -0
  112. package/dist/bin/chunks/mv-UASF6NAX.js +3 -0
  113. package/dist/bin/chunks/nl-HUDE6DQC.js +3 -0
  114. package/dist/bin/chunks/od-CECQKF5P.js +3 -0
  115. package/dist/bin/chunks/paste-SH5RZ4ZO.js +3 -0
  116. package/dist/bin/chunks/printf-PQKUEWX5.js +3 -0
  117. package/dist/bin/chunks/python3-UE36ZXQT.js +23 -0
  118. package/dist/bin/chunks/readlink-4Z75K3AI.js +3 -0
  119. package/dist/bin/chunks/rev-6SA3VC3J.js +3 -0
  120. package/dist/bin/chunks/rg-ULWB5MQG.js +3 -0
  121. package/dist/bin/chunks/rm-NPIAQT6U.js +3 -0
  122. package/dist/bin/chunks/rmdir-57J3AGQU.js +3 -0
  123. package/dist/bin/chunks/sed-XV7BZPKI.js +3 -0
  124. package/dist/bin/chunks/seq-ZVBT2JEI.js +3 -0
  125. package/dist/bin/chunks/sha1sum-JGOB5K4J.js +3 -0
  126. package/dist/bin/chunks/sha256sum-S5DS6Q6N.js +3 -0
  127. package/dist/bin/chunks/sort-UOMFLGRW.js +3 -0
  128. package/dist/bin/chunks/split-IBL3NIVH.js +3 -0
  129. package/dist/bin/chunks/sqlite3-YIM3BYLS.js +3 -0
  130. package/dist/bin/chunks/stat-RKSIL4YV.js +3 -0
  131. package/dist/bin/chunks/strings-AL7T5GDQ.js +3 -0
  132. package/dist/bin/chunks/tac-36B6LBNS.js +3 -0
  133. package/dist/bin/chunks/tail-G4PLDIOK.js +3 -0
  134. package/dist/bin/chunks/tar-YG6SY2RU.js +3 -0
  135. package/dist/bin/chunks/tee-NP4ULCWD.js +3 -0
  136. package/dist/bin/chunks/time-ZMFJL7MD.js +3 -0
  137. package/dist/bin/chunks/timeout-EJIGKZUX.js +3 -0
  138. package/dist/bin/chunks/touch-YE5LMLLE.js +3 -0
  139. package/dist/bin/chunks/tr-7KFUMSUF.js +3 -0
  140. package/dist/bin/chunks/unexpand-67EBVEPB.js +3 -0
  141. package/dist/bin/chunks/uniq-SZDRNEYK.js +3 -0
  142. package/dist/bin/chunks/wc-VLOME6PL.js +3 -0
  143. package/dist/bin/chunks/xan-FVGJAHFV.js +3 -0
  144. package/dist/bin/chunks/xan-view-LYATQWQB.js +3 -0
  145. package/dist/bin/chunks/xargs-CLQL2WFV.js +3 -0
  146. package/dist/bin/chunks/yes-OOBLAITP.js +3 -0
  147. package/dist/bin/chunks/yq-YQ4YFM26.js +3 -0
  148. package/dist/bin/just-bash.js +347 -345
  149. package/dist/bin/shell/chunks/awk2-EPZ2CEQT.js +3 -0
  150. package/dist/bin/shell/chunks/base64-D7ZXJQN6.js +3 -0
  151. package/dist/bin/shell/chunks/bash-4Q4RMIZL.js +3 -0
  152. package/dist/bin/shell/chunks/cat-AST5Y57Y.js +3 -0
  153. package/dist/bin/shell/chunks/chmod-BFP7P5CD.js +3 -0
  154. package/dist/bin/shell/chunks/chunk-26O2G5LX.js +34 -0
  155. package/dist/bin/shell/chunks/chunk-2RDKEB6Z.js +15 -0
  156. package/dist/bin/shell/chunks/chunk-35U2THFB.js +3 -0
  157. package/dist/bin/shell/chunks/chunk-3F7UWBEM.js +17 -0
  158. package/dist/bin/shell/chunks/chunk-3WLAERUX.js +3 -0
  159. package/dist/bin/shell/chunks/chunk-3WZIZUMC.js +8 -0
  160. package/dist/bin/shell/chunks/chunk-4ARWO6Y3.js +4 -0
  161. package/dist/bin/shell/chunks/chunk-4HVMRZ5N.js +8 -0
  162. package/dist/bin/shell/chunks/chunk-5AS7PRVN.js +34 -0
  163. package/dist/bin/shell/chunks/chunk-5GYAEVIB.js +10 -0
  164. package/dist/bin/shell/chunks/chunk-5IPYW47P.js +27 -0
  165. package/dist/bin/shell/chunks/chunk-5ZTIV6TI.js +20 -0
  166. package/dist/bin/shell/chunks/chunk-6C2YS7G6.js +14 -0
  167. package/dist/bin/shell/chunks/chunk-74MYVPDY.js +3 -0
  168. package/dist/bin/shell/chunks/chunk-74UP5NWP.js +3 -0
  169. package/dist/bin/shell/chunks/chunk-7DPD5PK3.js +3 -0
  170. package/dist/bin/shell/chunks/chunk-7LJGZPVP.js +18 -0
  171. package/dist/bin/shell/chunks/chunk-7NEXHFSS.js +3 -0
  172. package/dist/bin/shell/chunks/chunk-7XFMCB5C.js +21 -0
  173. package/dist/bin/shell/chunks/chunk-A53Y4KDG.js +7 -0
  174. package/dist/bin/shell/chunks/chunk-AALAYQ6J.js +17 -0
  175. package/dist/bin/shell/chunks/chunk-AM4WIHAG.js +10 -0
  176. package/dist/bin/shell/chunks/chunk-BC5OXEFJ.js +3 -0
  177. package/dist/bin/shell/chunks/chunk-C5ABXV4P.js +15 -0
  178. package/dist/bin/shell/chunks/chunk-CT6P7ILU.js +3 -0
  179. package/dist/bin/shell/chunks/chunk-CYHG3NVG.js +9 -0
  180. package/dist/bin/shell/chunks/chunk-D7PDAJWE.js +7 -0
  181. package/dist/bin/shell/chunks/chunk-DB3G3UVZ.js +5 -0
  182. package/dist/bin/shell/chunks/chunk-EIUU35ZP.js +37 -0
  183. package/dist/bin/shell/chunks/chunk-EMHJNKV5.js +20 -0
  184. package/dist/bin/shell/chunks/chunk-EPWMLTS6.js +9 -0
  185. package/dist/bin/shell/chunks/chunk-F4QFFLWZ.js +8 -0
  186. package/dist/bin/shell/chunks/chunk-F5R5O2Y6.js +9 -0
  187. package/dist/bin/shell/chunks/chunk-FBEYY2HM.js +13 -0
  188. package/dist/bin/shell/chunks/chunk-FIJBWMXU.js +12 -0
  189. package/dist/bin/shell/chunks/chunk-FMVH4N2P.js +5 -0
  190. package/dist/bin/shell/chunks/chunk-G6W2HMNY.js +7 -0
  191. package/dist/bin/shell/chunks/chunk-GFI5BHZX.js +3 -0
  192. package/dist/bin/shell/chunks/chunk-GJAVHEWO.js +143 -0
  193. package/dist/bin/shell/chunks/chunk-GUVSOVQU.js +8 -0
  194. package/dist/bin/shell/chunks/chunk-H22PAKR6.js +3 -0
  195. package/dist/bin/shell/chunks/chunk-HXOJHK2Z.js +8 -0
  196. package/dist/bin/shell/chunks/chunk-IAAYIH44.js +3 -0
  197. package/dist/bin/shell/chunks/chunk-J7W2CRXT.js +7 -0
  198. package/dist/bin/shell/chunks/chunk-JNWWOKCN.js +6 -0
  199. package/dist/bin/shell/chunks/chunk-JQLGE4OW.js +22 -0
  200. package/dist/bin/shell/chunks/chunk-K3U4M4MF.js +7 -0
  201. package/dist/bin/shell/chunks/chunk-KRXYOWIP.js +12 -0
  202. package/dist/bin/shell/chunks/chunk-L4L2QFS4.js +10 -0
  203. package/dist/bin/shell/chunks/chunk-LU6ZEQNN.js +13 -0
  204. package/dist/bin/shell/chunks/chunk-MLMKRR7L.js +12 -0
  205. package/dist/bin/shell/chunks/chunk-MVN5WALS.js +7 -0
  206. package/dist/bin/shell/chunks/chunk-MYOGTYIH.js +22 -0
  207. package/dist/bin/shell/chunks/chunk-NF5LHCVV.js +275 -0
  208. package/dist/bin/shell/chunks/chunk-OUGDZVL6.js +10 -0
  209. package/dist/bin/shell/chunks/chunk-QCNQD6ME.js +11 -0
  210. package/dist/bin/shell/chunks/chunk-QIDBJNMB.js +3 -0
  211. package/dist/bin/shell/chunks/chunk-QKTQYL37.js +9 -0
  212. package/dist/bin/shell/chunks/chunk-R6CMNMNX.js +22 -0
  213. package/dist/bin/shell/chunks/chunk-RCP3WQND.js +7 -0
  214. package/dist/bin/shell/chunks/chunk-RJG4JS32.js +6 -0
  215. package/dist/bin/shell/chunks/chunk-SIMSIBUA.js +13 -0
  216. package/dist/bin/shell/chunks/chunk-TNB7M24H.js +87 -0
  217. package/dist/bin/shell/chunks/chunk-TU6P6AC2.js +4 -0
  218. package/dist/bin/shell/chunks/chunk-TX4WSLXK.js +101 -0
  219. package/dist/bin/shell/chunks/chunk-U4UY6P77.js +3 -0
  220. package/dist/bin/shell/chunks/chunk-U5BNATW4.js +3 -0
  221. package/dist/bin/shell/chunks/chunk-U7VJCJQR.js +16 -0
  222. package/dist/bin/shell/chunks/chunk-VJE2PQW6.js +15 -0
  223. package/dist/bin/shell/chunks/chunk-W4ENG3BR.js +44 -0
  224. package/dist/bin/shell/chunks/chunk-XUFO4QPW.js +65 -0
  225. package/dist/bin/shell/chunks/chunk-XVKL2UZA.js +4 -0
  226. package/dist/bin/shell/chunks/chunk-YCUNLSHF.js +12 -0
  227. package/dist/bin/shell/chunks/chunk-YDH7Q5WV.js +6 -0
  228. package/dist/bin/shell/chunks/chunk-YDWLU56G.js +26 -0
  229. package/dist/bin/shell/chunks/chunk-YILPYZYP.js +16 -0
  230. package/dist/bin/shell/chunks/chunk-YZQ4SVJV.js +13 -0
  231. package/dist/bin/shell/chunks/chunk-ZKLKNN6B.js +3 -0
  232. package/dist/bin/shell/chunks/column-EGAQ7QMC.js +3 -0
  233. package/dist/bin/shell/chunks/comm-JEJ6GWEA.js +3 -0
  234. package/dist/bin/shell/chunks/cp-7AH7TSQ6.js +3 -0
  235. package/dist/bin/shell/chunks/curl-7FCZQCFU.js +31 -0
  236. package/dist/bin/shell/chunks/cut-OVTLUT2B.js +3 -0
  237. package/dist/bin/shell/chunks/date-MKP5YWWY.js +3 -0
  238. package/dist/bin/shell/chunks/diff-R6QTSWD2.js +3 -0
  239. package/dist/bin/shell/chunks/du-M2PB5NUH.js +3 -0
  240. package/dist/bin/shell/chunks/env-EUSAZGWO.js +3 -0
  241. package/dist/bin/shell/chunks/expand-B4CPOZN5.js +3 -0
  242. package/dist/bin/shell/chunks/expr-AQBMSEFL.js +3 -0
  243. package/dist/bin/shell/chunks/file-22CVQBNS.js +3 -0
  244. package/dist/bin/shell/chunks/find-QYLHUYOP.js +3 -0
  245. package/dist/bin/shell/chunks/flag-coverage-CTPK5ZWJ.js +3 -0
  246. package/dist/bin/shell/chunks/fold-E6A5I4DW.js +3 -0
  247. package/dist/bin/shell/chunks/grep-HI55D7F7.js +3 -0
  248. package/dist/bin/shell/chunks/gzip-2GJMVXCF.js +3 -0
  249. package/dist/bin/shell/chunks/head-ZQIB2GSI.js +3 -0
  250. package/dist/bin/shell/chunks/html-to-markdown-7ZNLM4SQ.js +3 -0
  251. package/dist/bin/shell/chunks/join-KCYMLQ3V.js +3 -0
  252. package/dist/bin/shell/chunks/jq-KNI4FJIL.js +3 -0
  253. package/dist/bin/shell/chunks/js-exec-OWDAX677.js +1617 -0
  254. package/dist/bin/shell/chunks/ls-QCAGDEDW.js +3 -0
  255. package/dist/bin/shell/chunks/md5sum-OPJ77ZY7.js +3 -0
  256. package/dist/bin/shell/chunks/mkdir-3XFSFVPC.js +3 -0
  257. package/dist/bin/shell/chunks/mktemp-5FA55IJS.js +3 -0
  258. package/dist/bin/shell/chunks/mv-UASF6NAX.js +3 -0
  259. package/dist/bin/shell/chunks/nl-HUDE6DQC.js +3 -0
  260. package/dist/bin/shell/chunks/od-CECQKF5P.js +3 -0
  261. package/dist/bin/shell/chunks/paste-SH5RZ4ZO.js +3 -0
  262. package/dist/bin/shell/chunks/printf-PQKUEWX5.js +3 -0
  263. package/dist/bin/shell/chunks/python3-UE36ZXQT.js +23 -0
  264. package/dist/bin/shell/chunks/readlink-4Z75K3AI.js +3 -0
  265. package/dist/bin/shell/chunks/rev-6SA3VC3J.js +3 -0
  266. package/dist/bin/shell/chunks/rg-ULWB5MQG.js +3 -0
  267. package/dist/bin/shell/chunks/rm-NPIAQT6U.js +3 -0
  268. package/dist/bin/shell/chunks/rmdir-57J3AGQU.js +3 -0
  269. package/dist/bin/shell/chunks/sed-XV7BZPKI.js +3 -0
  270. package/dist/bin/shell/chunks/seq-ZVBT2JEI.js +3 -0
  271. package/dist/bin/shell/chunks/sha1sum-JGOB5K4J.js +3 -0
  272. package/dist/bin/shell/chunks/sha256sum-S5DS6Q6N.js +3 -0
  273. package/dist/bin/shell/chunks/sort-UOMFLGRW.js +3 -0
  274. package/dist/bin/shell/chunks/split-IBL3NIVH.js +3 -0
  275. package/dist/bin/shell/chunks/sqlite3-YIM3BYLS.js +3 -0
  276. package/dist/bin/shell/chunks/stat-RKSIL4YV.js +3 -0
  277. package/dist/bin/shell/chunks/strings-AL7T5GDQ.js +3 -0
  278. package/dist/bin/shell/chunks/tac-36B6LBNS.js +3 -0
  279. package/dist/bin/shell/chunks/tail-G4PLDIOK.js +3 -0
  280. package/dist/bin/shell/chunks/tar-YG6SY2RU.js +3 -0
  281. package/dist/bin/shell/chunks/tee-NP4ULCWD.js +3 -0
  282. package/dist/bin/shell/chunks/time-ZMFJL7MD.js +3 -0
  283. package/dist/bin/shell/chunks/timeout-EJIGKZUX.js +3 -0
  284. package/dist/bin/shell/chunks/touch-YE5LMLLE.js +3 -0
  285. package/dist/bin/shell/chunks/tr-7KFUMSUF.js +3 -0
  286. package/dist/bin/shell/chunks/unexpand-67EBVEPB.js +3 -0
  287. package/dist/bin/shell/chunks/uniq-SZDRNEYK.js +3 -0
  288. package/dist/bin/shell/chunks/wc-VLOME6PL.js +3 -0
  289. package/dist/bin/shell/chunks/xan-FVGJAHFV.js +3 -0
  290. package/dist/bin/shell/chunks/xan-view-LYATQWQB.js +3 -0
  291. package/dist/bin/shell/chunks/xargs-CLQL2WFV.js +3 -0
  292. package/dist/bin/shell/chunks/yes-OOBLAITP.js +3 -0
  293. package/dist/bin/shell/chunks/yq-YQ4YFM26.js +3 -0
  294. package/dist/bin/shell/shell.js +385 -383
  295. package/dist/bundle/browser.js +873 -863
  296. package/dist/bundle/chunks/awk2-LEEKKBPN.js +2 -0
  297. package/dist/bundle/chunks/base64-GBEVK7UP.js +2 -0
  298. package/dist/bundle/chunks/bash-QTX2IUM4.js +2 -0
  299. package/dist/bundle/chunks/cat-UBR2ABBH.js +2 -0
  300. package/dist/bundle/chunks/chmod-5VBARXGU.js +2 -0
  301. package/dist/bundle/chunks/chunk-2LOOLBWC.js +33 -0
  302. package/dist/bundle/chunks/chunk-34XJ6PLO.js +20 -0
  303. package/dist/bundle/chunks/chunk-3DUKINTI.js +7 -0
  304. package/dist/bundle/chunks/chunk-3VXY25LY.js +2 -0
  305. package/dist/bundle/chunks/chunk-5G2D2EZB.js +7 -0
  306. package/dist/bundle/chunks/chunk-5Q4R6KJE.js +4 -0
  307. package/dist/bundle/chunks/chunk-5ZVTEBKG.js +7 -0
  308. package/dist/bundle/chunks/chunk-77XFWF43.js +13 -0
  309. package/dist/bundle/chunks/chunk-B2EYYRZX.js +9 -0
  310. package/dist/bundle/chunks/chunk-BC3VKZCL.js +10 -0
  311. package/dist/bundle/chunks/chunk-BEIP3OYT.js +6 -0
  312. package/dist/bundle/chunks/chunk-BLTFJFWH.js +2 -0
  313. package/dist/bundle/chunks/chunk-C2GCPQ2D.js +15 -0
  314. package/dist/bundle/chunks/chunk-CGCA7SGA.js +25 -0
  315. package/dist/bundle/chunks/chunk-CIY4XCGA.js +2 -0
  316. package/dist/bundle/chunks/chunk-CXBOPNEG.js +11 -0
  317. package/dist/bundle/chunks/chunk-CYJQAYUX.js +142 -0
  318. package/dist/bundle/chunks/chunk-D55UUXDJ.js +100 -0
  319. package/dist/bundle/chunks/chunk-EOMWWW4L.js +33 -0
  320. package/dist/bundle/chunks/chunk-ER6ZGLPS.js +26 -0
  321. package/dist/bundle/chunks/chunk-EZHC6HLV.js +3 -0
  322. package/dist/bundle/chunks/chunk-FBRDM6EM.js +12 -0
  323. package/dist/bundle/chunks/chunk-FDAXSABU.js +11 -0
  324. package/dist/bundle/chunks/chunk-FEKEA5Y2.js +2 -0
  325. package/dist/bundle/chunks/chunk-GEANXVKK.js +15 -0
  326. package/dist/bundle/chunks/chunk-GIQ3LRFL.js +21 -0
  327. package/dist/bundle/chunks/chunk-HBIJBKHP.js +14 -0
  328. package/dist/bundle/chunks/chunk-IDYF47VD.js +11 -0
  329. package/dist/bundle/chunks/chunk-IH6MZAKK.js +6 -0
  330. package/dist/bundle/chunks/chunk-IIWAWB3H.js +274 -0
  331. package/dist/bundle/chunks/chunk-IQGNPH54.js +8 -0
  332. package/dist/bundle/chunks/chunk-IVYY6YFV.js +7 -0
  333. package/dist/bundle/chunks/chunk-IXOG2DXK.js +14 -0
  334. package/dist/bundle/chunks/chunk-J6QAN4PZ.js +6 -0
  335. package/dist/bundle/chunks/chunk-JMGGZYF2.js +2 -0
  336. package/dist/bundle/chunks/chunk-JU5GJH4X.js +9 -0
  337. package/dist/bundle/chunks/chunk-JWGTQTBU.js +16 -0
  338. package/dist/bundle/chunks/chunk-KQSMX4HM.js +11 -0
  339. package/dist/bundle/chunks/chunk-KZMK2KYL.js +43 -0
  340. package/dist/bundle/chunks/chunk-L4MC7WH4.js +14 -0
  341. package/dist/bundle/chunks/chunk-L5AKA7GO.js +5 -0
  342. package/dist/bundle/chunks/chunk-LBKOJW6K.js +2 -0
  343. package/dist/bundle/chunks/chunk-LNJ6EIKX.js +2 -0
  344. package/dist/bundle/chunks/chunk-LQXMSLW5.js +16 -0
  345. package/dist/bundle/chunks/chunk-MOOFDAFS.js +7 -0
  346. package/dist/bundle/chunks/chunk-N3VQQRLQ.js +8 -0
  347. package/dist/bundle/chunks/chunk-NJUHQKMR.js +3 -0
  348. package/dist/bundle/chunks/chunk-NOZTFL4F.js +12 -0
  349. package/dist/bundle/chunks/chunk-OEZKBUXP.js +8 -0
  350. package/dist/bundle/chunks/chunk-OZMQI3HV.js +17 -0
  351. package/dist/bundle/chunks/chunk-POI4XBDP.js +6 -0
  352. package/dist/bundle/chunks/chunk-PV2DCWLJ.js +6 -0
  353. package/dist/bundle/chunks/chunk-Q6ZH76O4.js +2 -0
  354. package/dist/bundle/chunks/chunk-QECDICRF.js +9 -0
  355. package/dist/bundle/chunks/chunk-QJTRVYQA.js +5 -0
  356. package/dist/bundle/chunks/chunk-QZPG6UCH.js +9 -0
  357. package/dist/bundle/chunks/chunk-R23EAHN5.js +2 -0
  358. package/dist/bundle/chunks/chunk-R3HY2GCO.js +3 -0
  359. package/dist/bundle/chunks/chunk-RQTEROQ5.js +6 -0
  360. package/dist/bundle/chunks/chunk-SAE7VUIM.js +21 -0
  361. package/dist/bundle/chunks/chunk-SBG7KYI4.js +12 -0
  362. package/dist/bundle/chunks/chunk-SRNYBHIU.js +21 -0
  363. package/dist/bundle/chunks/chunk-T7CFNHX6.js +2 -0
  364. package/dist/bundle/chunks/chunk-U3UTFNHI.js +2 -0
  365. package/dist/bundle/chunks/chunk-UQZ5HJXB.js +64 -0
  366. package/dist/bundle/chunks/chunk-US6XQQ6W.js +19 -0
  367. package/dist/bundle/chunks/chunk-UZ4TKNEJ.js +2 -0
  368. package/dist/bundle/chunks/chunk-VW6FDS6X.js +2 -0
  369. package/dist/bundle/chunks/chunk-W4A6TADR.js +36 -0
  370. package/dist/bundle/chunks/chunk-WAL3MOLR.js +6 -0
  371. package/dist/bundle/chunks/chunk-WFEUQRHM.js +2 -0
  372. package/dist/bundle/chunks/chunk-WNAEYQTE.js +8 -0
  373. package/dist/bundle/chunks/chunk-WOSSFIAE.js +12 -0
  374. package/dist/bundle/chunks/chunk-WTG3OCY4.js +5 -0
  375. package/dist/bundle/chunks/chunk-XIEMQVCO.js +19 -0
  376. package/dist/bundle/chunks/chunk-YFGP6M45.js +7 -0
  377. package/dist/bundle/chunks/chunk-ZARLSKBF.js +2 -0
  378. package/dist/bundle/chunks/chunk-ZVANIJV2.js +4 -0
  379. package/dist/bundle/chunks/column-46NX3HG3.js +2 -0
  380. package/dist/bundle/chunks/comm-QHEYSM4I.js +2 -0
  381. package/dist/bundle/chunks/cp-AQ4Y4WVV.js +2 -0
  382. package/dist/bundle/chunks/curl-LMCQFYWH.js +30 -0
  383. package/dist/bundle/chunks/cut-A6NXJGOH.js +2 -0
  384. package/dist/bundle/chunks/date-YMEJ62OQ.js +2 -0
  385. package/dist/bundle/chunks/diff-SECJC7CN.js +2 -0
  386. package/dist/bundle/chunks/du-JOLY42MC.js +2 -0
  387. package/dist/bundle/chunks/env-MI6QVNMM.js +2 -0
  388. package/dist/bundle/chunks/expand-YVEZTU7W.js +2 -0
  389. package/dist/bundle/chunks/expr-U7WETT5R.js +2 -0
  390. package/dist/bundle/chunks/file-6QDI3H7G.js +2 -0
  391. package/dist/bundle/chunks/find-UYQIFSZI.js +2 -0
  392. package/dist/bundle/chunks/flag-coverage-5YCE6ILG.js +2 -0
  393. package/dist/bundle/chunks/fold-A24KLKHY.js +2 -0
  394. package/dist/bundle/chunks/grep-ZELVZ7JB.js +2 -0
  395. package/dist/bundle/chunks/gzip-3IFADYVU.js +2 -0
  396. package/dist/bundle/chunks/head-5YWCKNNQ.js +2 -0
  397. package/dist/bundle/chunks/html-to-markdown-EOWI2I5J.js +2 -0
  398. package/dist/bundle/chunks/join-MSZXRLNV.js +2 -0
  399. package/dist/bundle/chunks/jq-MKA6BDYV.js +2 -0
  400. package/dist/bundle/chunks/js-exec-CNDWLKWB.js +1616 -0
  401. package/dist/bundle/chunks/ls-WMN4WCCI.js +2 -0
  402. package/dist/bundle/chunks/md5sum-OCX4NZ2Q.js +2 -0
  403. package/dist/bundle/chunks/mkdir-YJMG55FX.js +2 -0
  404. package/dist/bundle/chunks/mktemp-RA55VAN3.js +2 -0
  405. package/dist/bundle/chunks/mv-NTJL2AHI.js +2 -0
  406. package/dist/bundle/chunks/nl-Z5DVHZ3S.js +2 -0
  407. package/dist/bundle/chunks/od-TRWBMEIO.js +2 -0
  408. package/dist/bundle/chunks/paste-VPYCLIL6.js +2 -0
  409. package/dist/bundle/chunks/printf-BNADL4RX.js +2 -0
  410. package/dist/bundle/chunks/python3-TIKLWPZJ.js +22 -0
  411. package/dist/bundle/chunks/readlink-HGACDFRD.js +2 -0
  412. package/dist/bundle/chunks/rev-W57N4M5B.js +2 -0
  413. package/dist/bundle/chunks/rg-IN3KT335.js +2 -0
  414. package/dist/bundle/chunks/rm-CDVWO5CO.js +2 -0
  415. package/dist/bundle/chunks/rmdir-HI3UE4KQ.js +2 -0
  416. package/dist/bundle/chunks/sed-MXZDFQ7I.js +2 -0
  417. package/dist/bundle/chunks/seq-E3UP3G65.js +2 -0
  418. package/dist/bundle/chunks/sha1sum-QUWYL7G6.js +2 -0
  419. package/dist/bundle/chunks/sha256sum-FGHIABMA.js +2 -0
  420. package/dist/bundle/chunks/sort-ATCMEITA.js +2 -0
  421. package/dist/bundle/chunks/split-YZFCWIZI.js +2 -0
  422. package/dist/bundle/chunks/sqlite3-JL36RFBZ.js +2 -0
  423. package/dist/bundle/chunks/stat-APUQD6WQ.js +2 -0
  424. package/dist/bundle/chunks/strings-WA2ZGNUN.js +2 -0
  425. package/dist/bundle/chunks/tac-OCV6R4TG.js +2 -0
  426. package/dist/bundle/chunks/tail-IBKQAMFW.js +2 -0
  427. package/dist/bundle/chunks/tar-WJV4DGKA.js +2 -0
  428. package/dist/bundle/chunks/tee-VOXQ2UGV.js +2 -0
  429. package/dist/bundle/chunks/time-GOHAC6VO.js +2 -0
  430. package/dist/bundle/chunks/timeout-FVGYB3MD.js +2 -0
  431. package/dist/bundle/chunks/touch-57OKADDG.js +2 -0
  432. package/dist/bundle/chunks/tr-M4D6SICQ.js +2 -0
  433. package/dist/bundle/chunks/unexpand-SYZZ5ZBE.js +2 -0
  434. package/dist/bundle/chunks/uniq-TUUUYPVF.js +2 -0
  435. package/dist/bundle/chunks/wc-HQPGW3KR.js +2 -0
  436. package/dist/bundle/chunks/xan-CZJZCC57.js +2 -0
  437. package/dist/bundle/chunks/xan-view-HETEUD3G.js +2 -0
  438. package/dist/bundle/chunks/xargs-WFPZZ3FK.js +2 -0
  439. package/dist/bundle/chunks/yes-ACSNSE7T.js +2 -0
  440. package/dist/bundle/chunks/yq-XDJLIJPZ.js +2 -0
  441. package/dist/bundle/index.cjs +1042 -993
  442. package/dist/bundle/index.js +345 -343
  443. package/dist/commands/awk/interpreter/fields.d.ts +16 -0
  444. package/dist/commands/js-exec/module-shims.d.ts +1 -1
  445. package/dist/commands/rg/rg-options.d.ts +2 -0
  446. package/dist/commands/search-engine/matcher.d.ts +2 -0
  447. package/dist/interpreter/builtin-dispatch.d.ts +9 -3
  448. package/dist/interpreter/fd-table.d.ts +4 -1
  449. package/dist/interpreter/helpers/errors.d.ts +5 -0
  450. package/dist/interpreter/pipeline-execution.d.ts +1 -1
  451. package/dist/interpreter/redirections.d.ts +25 -10
  452. package/dist/interpreter/types.d.ts +2 -0
  453. package/dist/types.d.ts +15 -0
  454. package/dist/utils/string-builder.d.ts +9 -0
  455. package/package.json +1 -1
  456. package/dist/bin/chunks/awk2-U22OR5B5.js +0 -3
  457. package/dist/bin/chunks/base64-2KKH5BCT.js +0 -3
  458. package/dist/bin/chunks/bash-CFCBBWVH.js +0 -3
  459. package/dist/bin/chunks/cat-V45MVNBT.js +0 -3
  460. package/dist/bin/chunks/chmod-A54R4UUQ.js +0 -3
  461. package/dist/bin/chunks/chunk-2NJJXU4K.js +0 -27
  462. package/dist/bin/chunks/chunk-2YLY6FJA.js +0 -10
  463. package/dist/bin/chunks/chunk-3LKMI5IX.js +0 -34
  464. package/dist/bin/chunks/chunk-3VSWQCPN.js +0 -18
  465. package/dist/bin/chunks/chunk-44SKMHU6.js +0 -16
  466. package/dist/bin/chunks/chunk-5SKEZPTU.js +0 -12
  467. package/dist/bin/chunks/chunk-5SR55TXB.js +0 -16
  468. package/dist/bin/chunks/chunk-6D75E4LV.js +0 -3
  469. package/dist/bin/chunks/chunk-6DAR25KN.js +0 -12
  470. package/dist/bin/chunks/chunk-6SAZRW7E.js +0 -15
  471. package/dist/bin/chunks/chunk-723HNGID.js +0 -13
  472. package/dist/bin/chunks/chunk-7FGDUBSN.js +0 -14
  473. package/dist/bin/chunks/chunk-7X4QBCFW.js +0 -36
  474. package/dist/bin/chunks/chunk-AINNAQBQ.js +0 -6
  475. package/dist/bin/chunks/chunk-AL7RVSF4.js +0 -8
  476. package/dist/bin/chunks/chunk-ARYCSNJJ.js +0 -101
  477. package/dist/bin/chunks/chunk-BCJ42NCM.js +0 -15
  478. package/dist/bin/chunks/chunk-BJF6B4YW.js +0 -22
  479. package/dist/bin/chunks/chunk-BOXG6XBN.js +0 -143
  480. package/dist/bin/chunks/chunk-CPKBPQ2C.js +0 -3
  481. package/dist/bin/chunks/chunk-DA3RFNKK.js +0 -17
  482. package/dist/bin/chunks/chunk-DH7M46D3.js +0 -20
  483. package/dist/bin/chunks/chunk-DTGQQKI2.js +0 -87
  484. package/dist/bin/chunks/chunk-ECZAFQ22.js +0 -9
  485. package/dist/bin/chunks/chunk-ETWDDV6I.js +0 -10
  486. package/dist/bin/chunks/chunk-HFW2LXQV.js +0 -13
  487. package/dist/bin/chunks/chunk-HRKG3ZK2.js +0 -8
  488. package/dist/bin/chunks/chunk-I4IRHQDW.js +0 -3
  489. package/dist/bin/chunks/chunk-IKUY74NG.js +0 -3
  490. package/dist/bin/chunks/chunk-ILXMFIYG.js +0 -7
  491. package/dist/bin/chunks/chunk-IMVXTSPG.js +0 -275
  492. package/dist/bin/chunks/chunk-ISW2U76N.js +0 -17
  493. package/dist/bin/chunks/chunk-K5KT6DMM.js +0 -4
  494. package/dist/bin/chunks/chunk-KG2KXL4Y.js +0 -3
  495. package/dist/bin/chunks/chunk-LCP3IKI7.js +0 -9
  496. package/dist/bin/chunks/chunk-LG6IN6SW.js +0 -34
  497. package/dist/bin/chunks/chunk-LMFAALLO.js +0 -21
  498. package/dist/bin/chunks/chunk-LXFMIXGA.js +0 -3
  499. package/dist/bin/chunks/chunk-M5ZBECGM.js +0 -22
  500. package/dist/bin/chunks/chunk-MA6BMA4M.js +0 -3
  501. package/dist/bin/chunks/chunk-MPQMTLXN.js +0 -3
  502. package/dist/bin/chunks/chunk-MUIYG2RB.js +0 -65
  503. package/dist/bin/chunks/chunk-MYTNZ7MA.js +0 -7
  504. package/dist/bin/chunks/chunk-NGMFI3RH.js +0 -15
  505. package/dist/bin/chunks/chunk-NLMTGTSG.js +0 -11
  506. package/dist/bin/chunks/chunk-O74FSWB4.js +0 -4
  507. package/dist/bin/chunks/chunk-OBVTFHVP.js +0 -7
  508. package/dist/bin/chunks/chunk-OOKVPG5D.js +0 -6
  509. package/dist/bin/chunks/chunk-PL4EU7Y2.js +0 -3
  510. package/dist/bin/chunks/chunk-Q3LE3Y66.js +0 -13
  511. package/dist/bin/chunks/chunk-QCGH2ZOW.js +0 -13
  512. package/dist/bin/chunks/chunk-QKWMWSV3.js +0 -3
  513. package/dist/bin/chunks/chunk-QL33F2W6.js +0 -8
  514. package/dist/bin/chunks/chunk-S5Z7DMIE.js +0 -26
  515. package/dist/bin/chunks/chunk-SQ7SZZMW.js +0 -8
  516. package/dist/bin/chunks/chunk-SQUH76NP.js +0 -3
  517. package/dist/bin/chunks/chunk-TGRZ42DS.js +0 -12
  518. package/dist/bin/chunks/chunk-THTKNRO6.js +0 -7
  519. package/dist/bin/chunks/chunk-TQXLQEIT.js +0 -9
  520. package/dist/bin/chunks/chunk-TZ3S7MY6.js +0 -12
  521. package/dist/bin/chunks/chunk-U6BXPMLD.js +0 -7
  522. package/dist/bin/chunks/chunk-U6DBRMD5.js +0 -5
  523. package/dist/bin/chunks/chunk-URRH3GPG.js +0 -10
  524. package/dist/bin/chunks/chunk-VBU3UEG5.js +0 -7
  525. package/dist/bin/chunks/chunk-VLWZ6L7C.js +0 -4
  526. package/dist/bin/chunks/chunk-VTHA5UK5.js +0 -7
  527. package/dist/bin/chunks/chunk-WBST7XJW.js +0 -9
  528. package/dist/bin/chunks/chunk-WDV2ECOC.js +0 -3
  529. package/dist/bin/chunks/chunk-WEQ5WM2M.js +0 -20
  530. package/dist/bin/chunks/chunk-WFVCEB5T.js +0 -3
  531. package/dist/bin/chunks/chunk-WZ7MIBLR.js +0 -37
  532. package/dist/bin/chunks/chunk-X45GP3AQ.js +0 -3
  533. package/dist/bin/chunks/chunk-XEQ7KSRM.js +0 -5
  534. package/dist/bin/chunks/chunk-YIANER7Y.js +0 -8
  535. package/dist/bin/chunks/chunk-YYZSYLJO.js +0 -6
  536. package/dist/bin/chunks/chunk-Z3KAV6YJ.js +0 -10
  537. package/dist/bin/chunks/chunk-Z5KICK5X.js +0 -22
  538. package/dist/bin/chunks/column-LHHS4D3K.js +0 -3
  539. package/dist/bin/chunks/comm-URDMZCXL.js +0 -3
  540. package/dist/bin/chunks/cp-HPLQA35N.js +0 -3
  541. package/dist/bin/chunks/curl-FIRG3RB6.js +0 -31
  542. package/dist/bin/chunks/cut-KP3S36XS.js +0 -3
  543. package/dist/bin/chunks/date-FJUBX7TJ.js +0 -3
  544. package/dist/bin/chunks/diff-JSJ56EOK.js +0 -3
  545. package/dist/bin/chunks/du-WEF5YWQK.js +0 -3
  546. package/dist/bin/chunks/env-2TSVF4W7.js +0 -3
  547. package/dist/bin/chunks/expand-P6SNTBGZ.js +0 -3
  548. package/dist/bin/chunks/expr-FLWT4OCO.js +0 -3
  549. package/dist/bin/chunks/file-JLUCGBCB.js +0 -3
  550. package/dist/bin/chunks/find-XGVQ6N6L.js +0 -3
  551. package/dist/bin/chunks/flag-coverage-4JYKIAVV.js +0 -3
  552. package/dist/bin/chunks/fold-YEY7X54W.js +0 -3
  553. package/dist/bin/chunks/grep-DCPCPQOS.js +0 -3
  554. package/dist/bin/chunks/gzip-6DZIKNBW.js +0 -3
  555. package/dist/bin/chunks/head-TLFXMM2T.js +0 -3
  556. package/dist/bin/chunks/html-to-markdown-E22RLT2U.js +0 -3
  557. package/dist/bin/chunks/join-UQKXU2QP.js +0 -3
  558. package/dist/bin/chunks/jq-GDM3OBBK.js +0 -3
  559. package/dist/bin/chunks/js-exec-VU6F6WLS.js +0 -1578
  560. package/dist/bin/chunks/ls-67NUUIYT.js +0 -3
  561. package/dist/bin/chunks/md5sum-Z6KAYGDK.js +0 -3
  562. package/dist/bin/chunks/mkdir-AWDWRBKC.js +0 -3
  563. package/dist/bin/chunks/mktemp-L6OGMDUO.js +0 -3
  564. package/dist/bin/chunks/mv-4BJSOT4Y.js +0 -3
  565. package/dist/bin/chunks/nl-XHWFVVKH.js +0 -3
  566. package/dist/bin/chunks/od-SI75GLRE.js +0 -3
  567. package/dist/bin/chunks/paste-5TSIBDF7.js +0 -3
  568. package/dist/bin/chunks/printf-CNXNRQ3I.js +0 -3
  569. package/dist/bin/chunks/python3-GUWCSSDP.js +0 -23
  570. package/dist/bin/chunks/readlink-URO5XTBB.js +0 -3
  571. package/dist/bin/chunks/rev-CZTQCNOZ.js +0 -3
  572. package/dist/bin/chunks/rg-RVULUPDH.js +0 -3
  573. package/dist/bin/chunks/rm-UCUTHC3I.js +0 -3
  574. package/dist/bin/chunks/rmdir-J3HM7GGM.js +0 -3
  575. package/dist/bin/chunks/sed-MCLGHZOI.js +0 -3
  576. package/dist/bin/chunks/seq-I54NZE75.js +0 -3
  577. package/dist/bin/chunks/sha1sum-CATBXX76.js +0 -3
  578. package/dist/bin/chunks/sha256sum-YGSNBVY3.js +0 -3
  579. package/dist/bin/chunks/sort-M3DO25D5.js +0 -3
  580. package/dist/bin/chunks/split-VZO7223N.js +0 -3
  581. package/dist/bin/chunks/sqlite3-HXVFVP4Z.js +0 -3
  582. package/dist/bin/chunks/stat-UJ37RBMM.js +0 -3
  583. package/dist/bin/chunks/strings-J2X2Z6N2.js +0 -3
  584. package/dist/bin/chunks/tac-DG4BMYM5.js +0 -3
  585. package/dist/bin/chunks/tail-5TSF5YM4.js +0 -3
  586. package/dist/bin/chunks/tar-ZGZZDQXO.js +0 -3
  587. package/dist/bin/chunks/tee-L4HKV5PD.js +0 -3
  588. package/dist/bin/chunks/time-J2DAZUIN.js +0 -3
  589. package/dist/bin/chunks/timeout-ATTDYXLX.js +0 -3
  590. package/dist/bin/chunks/touch-TVQAUQOG.js +0 -3
  591. package/dist/bin/chunks/tr-6RPFASYV.js +0 -3
  592. package/dist/bin/chunks/unexpand-JPOQORZF.js +0 -3
  593. package/dist/bin/chunks/uniq-K5VRDP4Q.js +0 -3
  594. package/dist/bin/chunks/wc-VSQBRD6B.js +0 -3
  595. package/dist/bin/chunks/xan-CCS53B7D.js +0 -3
  596. package/dist/bin/chunks/xan-view-KOXASOEV.js +0 -3
  597. package/dist/bin/chunks/xargs-HMISWW4I.js +0 -3
  598. package/dist/bin/chunks/yes-ELH3XQWY.js +0 -3
  599. package/dist/bin/chunks/yq-GSCDUHGM.js +0 -3
  600. package/dist/bin/shell/chunks/awk2-U22OR5B5.js +0 -3
  601. package/dist/bin/shell/chunks/base64-2KKH5BCT.js +0 -3
  602. package/dist/bin/shell/chunks/bash-CFCBBWVH.js +0 -3
  603. package/dist/bin/shell/chunks/cat-V45MVNBT.js +0 -3
  604. package/dist/bin/shell/chunks/chmod-A54R4UUQ.js +0 -3
  605. package/dist/bin/shell/chunks/chunk-2NJJXU4K.js +0 -27
  606. package/dist/bin/shell/chunks/chunk-2YLY6FJA.js +0 -10
  607. package/dist/bin/shell/chunks/chunk-3LKMI5IX.js +0 -34
  608. package/dist/bin/shell/chunks/chunk-3VSWQCPN.js +0 -18
  609. package/dist/bin/shell/chunks/chunk-44SKMHU6.js +0 -16
  610. package/dist/bin/shell/chunks/chunk-5SKEZPTU.js +0 -12
  611. package/dist/bin/shell/chunks/chunk-5SR55TXB.js +0 -16
  612. package/dist/bin/shell/chunks/chunk-6D75E4LV.js +0 -3
  613. package/dist/bin/shell/chunks/chunk-6DAR25KN.js +0 -12
  614. package/dist/bin/shell/chunks/chunk-6SAZRW7E.js +0 -15
  615. package/dist/bin/shell/chunks/chunk-723HNGID.js +0 -13
  616. package/dist/bin/shell/chunks/chunk-7FGDUBSN.js +0 -14
  617. package/dist/bin/shell/chunks/chunk-7X4QBCFW.js +0 -36
  618. package/dist/bin/shell/chunks/chunk-AINNAQBQ.js +0 -6
  619. package/dist/bin/shell/chunks/chunk-AL7RVSF4.js +0 -8
  620. package/dist/bin/shell/chunks/chunk-ARYCSNJJ.js +0 -101
  621. package/dist/bin/shell/chunks/chunk-BCJ42NCM.js +0 -15
  622. package/dist/bin/shell/chunks/chunk-BJF6B4YW.js +0 -22
  623. package/dist/bin/shell/chunks/chunk-BOXG6XBN.js +0 -143
  624. package/dist/bin/shell/chunks/chunk-CPKBPQ2C.js +0 -3
  625. package/dist/bin/shell/chunks/chunk-DA3RFNKK.js +0 -17
  626. package/dist/bin/shell/chunks/chunk-DH7M46D3.js +0 -20
  627. package/dist/bin/shell/chunks/chunk-DTGQQKI2.js +0 -87
  628. package/dist/bin/shell/chunks/chunk-ECZAFQ22.js +0 -9
  629. package/dist/bin/shell/chunks/chunk-ETWDDV6I.js +0 -10
  630. package/dist/bin/shell/chunks/chunk-HFW2LXQV.js +0 -13
  631. package/dist/bin/shell/chunks/chunk-HRKG3ZK2.js +0 -8
  632. package/dist/bin/shell/chunks/chunk-I4IRHQDW.js +0 -3
  633. package/dist/bin/shell/chunks/chunk-IKUY74NG.js +0 -3
  634. package/dist/bin/shell/chunks/chunk-ILXMFIYG.js +0 -7
  635. package/dist/bin/shell/chunks/chunk-IMVXTSPG.js +0 -275
  636. package/dist/bin/shell/chunks/chunk-ISW2U76N.js +0 -17
  637. package/dist/bin/shell/chunks/chunk-K5KT6DMM.js +0 -4
  638. package/dist/bin/shell/chunks/chunk-KG2KXL4Y.js +0 -3
  639. package/dist/bin/shell/chunks/chunk-LCP3IKI7.js +0 -9
  640. package/dist/bin/shell/chunks/chunk-LG6IN6SW.js +0 -34
  641. package/dist/bin/shell/chunks/chunk-LMFAALLO.js +0 -21
  642. package/dist/bin/shell/chunks/chunk-LXFMIXGA.js +0 -3
  643. package/dist/bin/shell/chunks/chunk-M5ZBECGM.js +0 -22
  644. package/dist/bin/shell/chunks/chunk-MA6BMA4M.js +0 -3
  645. package/dist/bin/shell/chunks/chunk-MPQMTLXN.js +0 -3
  646. package/dist/bin/shell/chunks/chunk-MUIYG2RB.js +0 -65
  647. package/dist/bin/shell/chunks/chunk-MYTNZ7MA.js +0 -7
  648. package/dist/bin/shell/chunks/chunk-NGMFI3RH.js +0 -15
  649. package/dist/bin/shell/chunks/chunk-NLMTGTSG.js +0 -11
  650. package/dist/bin/shell/chunks/chunk-O74FSWB4.js +0 -4
  651. package/dist/bin/shell/chunks/chunk-OBVTFHVP.js +0 -7
  652. package/dist/bin/shell/chunks/chunk-OOKVPG5D.js +0 -6
  653. package/dist/bin/shell/chunks/chunk-PL4EU7Y2.js +0 -3
  654. package/dist/bin/shell/chunks/chunk-Q3LE3Y66.js +0 -13
  655. package/dist/bin/shell/chunks/chunk-QCGH2ZOW.js +0 -13
  656. package/dist/bin/shell/chunks/chunk-QKWMWSV3.js +0 -3
  657. package/dist/bin/shell/chunks/chunk-QL33F2W6.js +0 -8
  658. package/dist/bin/shell/chunks/chunk-S5Z7DMIE.js +0 -26
  659. package/dist/bin/shell/chunks/chunk-SQ7SZZMW.js +0 -8
  660. package/dist/bin/shell/chunks/chunk-SQUH76NP.js +0 -3
  661. package/dist/bin/shell/chunks/chunk-TGRZ42DS.js +0 -12
  662. package/dist/bin/shell/chunks/chunk-THTKNRO6.js +0 -7
  663. package/dist/bin/shell/chunks/chunk-TQXLQEIT.js +0 -9
  664. package/dist/bin/shell/chunks/chunk-TZ3S7MY6.js +0 -12
  665. package/dist/bin/shell/chunks/chunk-U6BXPMLD.js +0 -7
  666. package/dist/bin/shell/chunks/chunk-U6DBRMD5.js +0 -5
  667. package/dist/bin/shell/chunks/chunk-URRH3GPG.js +0 -10
  668. package/dist/bin/shell/chunks/chunk-VBU3UEG5.js +0 -7
  669. package/dist/bin/shell/chunks/chunk-VLWZ6L7C.js +0 -4
  670. package/dist/bin/shell/chunks/chunk-VTHA5UK5.js +0 -7
  671. package/dist/bin/shell/chunks/chunk-WBST7XJW.js +0 -9
  672. package/dist/bin/shell/chunks/chunk-WDV2ECOC.js +0 -3
  673. package/dist/bin/shell/chunks/chunk-WEQ5WM2M.js +0 -20
  674. package/dist/bin/shell/chunks/chunk-WFVCEB5T.js +0 -3
  675. package/dist/bin/shell/chunks/chunk-WZ7MIBLR.js +0 -37
  676. package/dist/bin/shell/chunks/chunk-X45GP3AQ.js +0 -3
  677. package/dist/bin/shell/chunks/chunk-XEQ7KSRM.js +0 -5
  678. package/dist/bin/shell/chunks/chunk-YIANER7Y.js +0 -8
  679. package/dist/bin/shell/chunks/chunk-YYZSYLJO.js +0 -6
  680. package/dist/bin/shell/chunks/chunk-Z3KAV6YJ.js +0 -10
  681. package/dist/bin/shell/chunks/chunk-Z5KICK5X.js +0 -22
  682. package/dist/bin/shell/chunks/column-LHHS4D3K.js +0 -3
  683. package/dist/bin/shell/chunks/comm-URDMZCXL.js +0 -3
  684. package/dist/bin/shell/chunks/cp-HPLQA35N.js +0 -3
  685. package/dist/bin/shell/chunks/curl-FIRG3RB6.js +0 -31
  686. package/dist/bin/shell/chunks/cut-KP3S36XS.js +0 -3
  687. package/dist/bin/shell/chunks/date-FJUBX7TJ.js +0 -3
  688. package/dist/bin/shell/chunks/diff-JSJ56EOK.js +0 -3
  689. package/dist/bin/shell/chunks/du-WEF5YWQK.js +0 -3
  690. package/dist/bin/shell/chunks/env-2TSVF4W7.js +0 -3
  691. package/dist/bin/shell/chunks/expand-P6SNTBGZ.js +0 -3
  692. package/dist/bin/shell/chunks/expr-FLWT4OCO.js +0 -3
  693. package/dist/bin/shell/chunks/file-JLUCGBCB.js +0 -3
  694. package/dist/bin/shell/chunks/find-XGVQ6N6L.js +0 -3
  695. package/dist/bin/shell/chunks/flag-coverage-4JYKIAVV.js +0 -3
  696. package/dist/bin/shell/chunks/fold-YEY7X54W.js +0 -3
  697. package/dist/bin/shell/chunks/grep-DCPCPQOS.js +0 -3
  698. package/dist/bin/shell/chunks/gzip-6DZIKNBW.js +0 -3
  699. package/dist/bin/shell/chunks/head-TLFXMM2T.js +0 -3
  700. package/dist/bin/shell/chunks/html-to-markdown-E22RLT2U.js +0 -3
  701. package/dist/bin/shell/chunks/join-UQKXU2QP.js +0 -3
  702. package/dist/bin/shell/chunks/jq-GDM3OBBK.js +0 -3
  703. package/dist/bin/shell/chunks/js-exec-VU6F6WLS.js +0 -1578
  704. package/dist/bin/shell/chunks/ls-67NUUIYT.js +0 -3
  705. package/dist/bin/shell/chunks/md5sum-Z6KAYGDK.js +0 -3
  706. package/dist/bin/shell/chunks/mkdir-AWDWRBKC.js +0 -3
  707. package/dist/bin/shell/chunks/mktemp-L6OGMDUO.js +0 -3
  708. package/dist/bin/shell/chunks/mv-4BJSOT4Y.js +0 -3
  709. package/dist/bin/shell/chunks/nl-XHWFVVKH.js +0 -3
  710. package/dist/bin/shell/chunks/od-SI75GLRE.js +0 -3
  711. package/dist/bin/shell/chunks/paste-5TSIBDF7.js +0 -3
  712. package/dist/bin/shell/chunks/printf-CNXNRQ3I.js +0 -3
  713. package/dist/bin/shell/chunks/python3-GUWCSSDP.js +0 -23
  714. package/dist/bin/shell/chunks/readlink-URO5XTBB.js +0 -3
  715. package/dist/bin/shell/chunks/rev-CZTQCNOZ.js +0 -3
  716. package/dist/bin/shell/chunks/rg-RVULUPDH.js +0 -3
  717. package/dist/bin/shell/chunks/rm-UCUTHC3I.js +0 -3
  718. package/dist/bin/shell/chunks/rmdir-J3HM7GGM.js +0 -3
  719. package/dist/bin/shell/chunks/sed-MCLGHZOI.js +0 -3
  720. package/dist/bin/shell/chunks/seq-I54NZE75.js +0 -3
  721. package/dist/bin/shell/chunks/sha1sum-CATBXX76.js +0 -3
  722. package/dist/bin/shell/chunks/sha256sum-YGSNBVY3.js +0 -3
  723. package/dist/bin/shell/chunks/sort-M3DO25D5.js +0 -3
  724. package/dist/bin/shell/chunks/split-VZO7223N.js +0 -3
  725. package/dist/bin/shell/chunks/sqlite3-HXVFVP4Z.js +0 -3
  726. package/dist/bin/shell/chunks/stat-UJ37RBMM.js +0 -3
  727. package/dist/bin/shell/chunks/strings-J2X2Z6N2.js +0 -3
  728. package/dist/bin/shell/chunks/tac-DG4BMYM5.js +0 -3
  729. package/dist/bin/shell/chunks/tail-5TSF5YM4.js +0 -3
  730. package/dist/bin/shell/chunks/tar-ZGZZDQXO.js +0 -3
  731. package/dist/bin/shell/chunks/tee-L4HKV5PD.js +0 -3
  732. package/dist/bin/shell/chunks/time-J2DAZUIN.js +0 -3
  733. package/dist/bin/shell/chunks/timeout-ATTDYXLX.js +0 -3
  734. package/dist/bin/shell/chunks/touch-TVQAUQOG.js +0 -3
  735. package/dist/bin/shell/chunks/tr-6RPFASYV.js +0 -3
  736. package/dist/bin/shell/chunks/unexpand-JPOQORZF.js +0 -3
  737. package/dist/bin/shell/chunks/uniq-K5VRDP4Q.js +0 -3
  738. package/dist/bin/shell/chunks/wc-VSQBRD6B.js +0 -3
  739. package/dist/bin/shell/chunks/xan-CCS53B7D.js +0 -3
  740. package/dist/bin/shell/chunks/xan-view-KOXASOEV.js +0 -3
  741. package/dist/bin/shell/chunks/xargs-HMISWW4I.js +0 -3
  742. package/dist/bin/shell/chunks/yes-ELH3XQWY.js +0 -3
  743. package/dist/bin/shell/chunks/yq-GSCDUHGM.js +0 -3
  744. package/dist/bundle/chunks/awk2-V7KYQWCD.js +0 -2
  745. package/dist/bundle/chunks/base64-QPSYZAAJ.js +0 -2
  746. package/dist/bundle/chunks/bash-HIEWVHJ2.js +0 -2
  747. package/dist/bundle/chunks/cat-54BXBS6X.js +0 -2
  748. package/dist/bundle/chunks/chmod-4OPV4QKK.js +0 -2
  749. package/dist/bundle/chunks/chunk-2KNTH3KH.js +0 -9
  750. package/dist/bundle/chunks/chunk-2VWG4LDT.js +0 -11
  751. package/dist/bundle/chunks/chunk-2WBUTDF5.js +0 -2
  752. package/dist/bundle/chunks/chunk-3HDTNUL3.js +0 -6
  753. package/dist/bundle/chunks/chunk-3KWM4FFA.js +0 -12
  754. package/dist/bundle/chunks/chunk-4AKAIZPW.js +0 -15
  755. package/dist/bundle/chunks/chunk-4IMUNIUJ.js +0 -21
  756. package/dist/bundle/chunks/chunk-5ATEFZLC.js +0 -4
  757. package/dist/bundle/chunks/chunk-5BMPT6SF.js +0 -19
  758. package/dist/bundle/chunks/chunk-5QWGR2WA.js +0 -21
  759. package/dist/bundle/chunks/chunk-5UTZMNI5.js +0 -64
  760. package/dist/bundle/chunks/chunk-5VCAQBXL.js +0 -17
  761. package/dist/bundle/chunks/chunk-65LVAUWW.js +0 -7
  762. package/dist/bundle/chunks/chunk-6D3WD6YU.js +0 -3
  763. package/dist/bundle/chunks/chunk-6R4OQQWP.js +0 -16
  764. package/dist/bundle/chunks/chunk-6WGIZV3E.js +0 -13
  765. package/dist/bundle/chunks/chunk-72JHTO7E.js +0 -2
  766. package/dist/bundle/chunks/chunk-7GA3QWJJ.js +0 -33
  767. package/dist/bundle/chunks/chunk-7M672HB6.js +0 -21
  768. package/dist/bundle/chunks/chunk-AFFAMSJT.js +0 -14
  769. package/dist/bundle/chunks/chunk-ANCQ4SCV.js +0 -2
  770. package/dist/bundle/chunks/chunk-B3NGH6KE.js +0 -5
  771. package/dist/bundle/chunks/chunk-B5Z5HTFY.js +0 -14
  772. package/dist/bundle/chunks/chunk-B6OSJB22.js +0 -26
  773. package/dist/bundle/chunks/chunk-BM3X75NC.js +0 -36
  774. package/dist/bundle/chunks/chunk-CGI6V2HW.js +0 -11
  775. package/dist/bundle/chunks/chunk-CHHWTPDH.js +0 -3
  776. package/dist/bundle/chunks/chunk-D5ZJISRS.js +0 -11
  777. package/dist/bundle/chunks/chunk-DIRWTBKE.js +0 -19
  778. package/dist/bundle/chunks/chunk-DIWMSSQY.js +0 -2
  779. package/dist/bundle/chunks/chunk-DPZVOEUP.js +0 -6
  780. package/dist/bundle/chunks/chunk-EFORKKSH.js +0 -8
  781. package/dist/bundle/chunks/chunk-EGTVQWAP.js +0 -20
  782. package/dist/bundle/chunks/chunk-EJFBIRMD.js +0 -6
  783. package/dist/bundle/chunks/chunk-EQQGPAXI.js +0 -9
  784. package/dist/bundle/chunks/chunk-EXXOLIVE.js +0 -35
  785. package/dist/bundle/chunks/chunk-FIMO5HLX.js +0 -2
  786. package/dist/bundle/chunks/chunk-FT6ODGOU.js +0 -2
  787. package/dist/bundle/chunks/chunk-FZRQOL3C.js +0 -7
  788. package/dist/bundle/chunks/chunk-GLAFXDZC.js +0 -4
  789. package/dist/bundle/chunks/chunk-GN6CQ3J4.js +0 -2
  790. package/dist/bundle/chunks/chunk-H42OAUJL.js +0 -12
  791. package/dist/bundle/chunks/chunk-H53EPEGD.js +0 -12
  792. package/dist/bundle/chunks/chunk-HDOXCDVK.js +0 -7
  793. package/dist/bundle/chunks/chunk-HIQEVPXM.js +0 -2
  794. package/dist/bundle/chunks/chunk-J2OBOJ64.js +0 -2
  795. package/dist/bundle/chunks/chunk-LVDUF74R.js +0 -7
  796. package/dist/bundle/chunks/chunk-M4LDT7V7.js +0 -6
  797. package/dist/bundle/chunks/chunk-MDE25PQK.js +0 -15
  798. package/dist/bundle/chunks/chunk-MHDZERK4.js +0 -6
  799. package/dist/bundle/chunks/chunk-MHZF23KB.js +0 -33
  800. package/dist/bundle/chunks/chunk-N6W6FM4N.js +0 -8
  801. package/dist/bundle/chunks/chunk-NRLE7KYI.js +0 -6
  802. package/dist/bundle/chunks/chunk-OB46N7Q7.js +0 -2
  803. package/dist/bundle/chunks/chunk-OQ7C4FYO.js +0 -2
  804. package/dist/bundle/chunks/chunk-P5BOIHWV.js +0 -6
  805. package/dist/bundle/chunks/chunk-PPDMRIJ7.js +0 -11
  806. package/dist/bundle/chunks/chunk-PPHGMG47.js +0 -142
  807. package/dist/bundle/chunks/chunk-R6ZGLVXI.js +0 -9
  808. package/dist/bundle/chunks/chunk-RCRHDT54.js +0 -274
  809. package/dist/bundle/chunks/chunk-RIIUVFUS.js +0 -7
  810. package/dist/bundle/chunks/chunk-SQX6WQXB.js +0 -7
  811. package/dist/bundle/chunks/chunk-SRB6FXRH.js +0 -2
  812. package/dist/bundle/chunks/chunk-T4INBNHX.js +0 -8
  813. package/dist/bundle/chunks/chunk-TUQG2YRH.js +0 -5
  814. package/dist/bundle/chunks/chunk-U7UNEMLJ.js +0 -2
  815. package/dist/bundle/chunks/chunk-UHHCL65P.js +0 -3
  816. package/dist/bundle/chunks/chunk-UK2K3DHN.js +0 -8
  817. package/dist/bundle/chunks/chunk-VDJ53ESK.js +0 -9
  818. package/dist/bundle/chunks/chunk-VGCXKMXN.js +0 -10
  819. package/dist/bundle/chunks/chunk-W5DWRFSU.js +0 -2
  820. package/dist/bundle/chunks/chunk-W5J5ADJF.js +0 -100
  821. package/dist/bundle/chunks/chunk-XHFP44Y4.js +0 -5
  822. package/dist/bundle/chunks/chunk-Y32R7EZP.js +0 -25
  823. package/dist/bundle/chunks/chunk-Y62SXZKJ.js +0 -12
  824. package/dist/bundle/chunks/chunk-YUFU7O6I.js +0 -16
  825. package/dist/bundle/chunks/chunk-YZH7FUSY.js +0 -14
  826. package/dist/bundle/chunks/column-F5JDBRV6.js +0 -2
  827. package/dist/bundle/chunks/comm-DTWKU2MC.js +0 -2
  828. package/dist/bundle/chunks/cp-LTFB4EUA.js +0 -2
  829. package/dist/bundle/chunks/curl-XCX2ZQEA.js +0 -30
  830. package/dist/bundle/chunks/cut-IRSHL3BB.js +0 -2
  831. package/dist/bundle/chunks/date-FN2DXAEE.js +0 -2
  832. package/dist/bundle/chunks/diff-VDB6RXHO.js +0 -2
  833. package/dist/bundle/chunks/du-DOWSRLXR.js +0 -2
  834. package/dist/bundle/chunks/env-VUUMB47B.js +0 -2
  835. package/dist/bundle/chunks/expand-2BPPGGSM.js +0 -2
  836. package/dist/bundle/chunks/expr-GZ4DABKB.js +0 -2
  837. package/dist/bundle/chunks/file-UI6QJAAU.js +0 -2
  838. package/dist/bundle/chunks/find-JTXDH3MR.js +0 -2
  839. package/dist/bundle/chunks/flag-coverage-EDO3VM43.js +0 -2
  840. package/dist/bundle/chunks/fold-QJBPHRFJ.js +0 -2
  841. package/dist/bundle/chunks/grep-OZCR76FT.js +0 -2
  842. package/dist/bundle/chunks/gzip-GQC6CWVL.js +0 -2
  843. package/dist/bundle/chunks/head-J6RVJFRS.js +0 -2
  844. package/dist/bundle/chunks/html-to-markdown-7OG5VWYG.js +0 -2
  845. package/dist/bundle/chunks/join-KQ4Z5OD4.js +0 -2
  846. package/dist/bundle/chunks/jq-FCG2IUBK.js +0 -2
  847. package/dist/bundle/chunks/js-exec-NDLXDUBN.js +0 -1577
  848. package/dist/bundle/chunks/ls-MQTYWW4T.js +0 -2
  849. package/dist/bundle/chunks/md5sum-JEDX55KS.js +0 -2
  850. package/dist/bundle/chunks/mkdir-4A5W3RXH.js +0 -2
  851. package/dist/bundle/chunks/mktemp-XKIE5N3X.js +0 -2
  852. package/dist/bundle/chunks/mv-ZPIATQJL.js +0 -2
  853. package/dist/bundle/chunks/nl-RFXH2GNX.js +0 -2
  854. package/dist/bundle/chunks/od-LUHOH7CG.js +0 -2
  855. package/dist/bundle/chunks/paste-U57ZU47S.js +0 -2
  856. package/dist/bundle/chunks/printf-V42QCPHL.js +0 -2
  857. package/dist/bundle/chunks/python3-SDFCGIU4.js +0 -22
  858. package/dist/bundle/chunks/readlink-YNNS6F7K.js +0 -2
  859. package/dist/bundle/chunks/rev-EPOS3MFH.js +0 -2
  860. package/dist/bundle/chunks/rg-F4SX2PHI.js +0 -2
  861. package/dist/bundle/chunks/rm-3XUUYAXQ.js +0 -2
  862. package/dist/bundle/chunks/rmdir-OGSEXEF4.js +0 -2
  863. package/dist/bundle/chunks/sed-MBB5SXGD.js +0 -2
  864. package/dist/bundle/chunks/seq-IN77HD3S.js +0 -2
  865. package/dist/bundle/chunks/sha1sum-BLPZJ6MP.js +0 -2
  866. package/dist/bundle/chunks/sha256sum-VJZ4PHQ4.js +0 -2
  867. package/dist/bundle/chunks/sort-PV2NEQHF.js +0 -2
  868. package/dist/bundle/chunks/split-6R2TSQY6.js +0 -2
  869. package/dist/bundle/chunks/sqlite3-7MBPFI6W.js +0 -2
  870. package/dist/bundle/chunks/stat-YLVJ4L67.js +0 -2
  871. package/dist/bundle/chunks/strings-WTD7Q2EF.js +0 -2
  872. package/dist/bundle/chunks/tac-YXC4HBTR.js +0 -2
  873. package/dist/bundle/chunks/tail-UGFWX3YY.js +0 -2
  874. package/dist/bundle/chunks/tar-BNHPWTOY.js +0 -2
  875. package/dist/bundle/chunks/tee-OOWSWHRQ.js +0 -2
  876. package/dist/bundle/chunks/time-N6J6DC6C.js +0 -2
  877. package/dist/bundle/chunks/timeout-ZHCL5KTP.js +0 -2
  878. package/dist/bundle/chunks/touch-W4DF6Z4T.js +0 -2
  879. package/dist/bundle/chunks/tr-4NGL47UU.js +0 -2
  880. package/dist/bundle/chunks/unexpand-YD5BWFH4.js +0 -2
  881. package/dist/bundle/chunks/uniq-OVOW532K.js +0 -2
  882. package/dist/bundle/chunks/wc-RUR7HE5O.js +0 -2
  883. package/dist/bundle/chunks/xan-7R3I2DJO.js +0 -2
  884. package/dist/bundle/chunks/xan-view-S4ZILLPU.js +0 -2
  885. package/dist/bundle/chunks/xargs-L7TJHOJT.js +0 -2
  886. package/dist/bundle/chunks/yes-I7SAR7XX.js +0 -2
  887. package/dist/bundle/chunks/yq-IOMBQYB2.js +0 -2
@@ -1,63 +1,63 @@
1
1
  #!/usr/bin/env node
2
2
  import{createRequire} from"node:module";const require=createRequire(import.meta.url);
3
- import{a as Cn,b as Nn,c as Wt}from"./chunks/chunk-PEJXCXSY.js";import{a as Cr,b as Yn}from"./chunks/chunk-MA6BMA4M.js";import{a as oa,b as aa,c as Kn,d as Xn}from"./chunks/chunk-EFS34UUR.js";import{c as Ws,e as ca,f as fa}from"./chunks/chunk-ENEHPI32.js";import{a as Bt}from"./chunks/chunk-6D75E4LV.js";import{a as Mt,b as Qe,c as Bs}from"./chunks/chunk-MROECM42.js";import{a as Jn,b as ua}from"./chunks/chunk-ABM5WFEO.js";import{a as me}from"./chunks/chunk-LG6IN6SW.js";import{a as An,b as _e}from"./chunks/chunk-VGSRQOLD.js";import"./chunks/chunk-VLWZ6L7C.js";import{d as Ft,e as $n}from"./chunks/chunk-QKWMWSV3.js";import"./chunks/chunk-7JZKVC3F.js";import{a as la}from"./chunks/chunk-UPUFWGHR.js";import{a as z,b as Dt,c as Q,d as ft,e as kn,f as nt,g as Pn}from"./chunks/chunk-43E7AR6A.js";import{a as xn,b as Ge,c as He,d as Ie,e as Me,f as Be,g as q,h as oe,i as Ze,j as Lt,k as kr,l as P,m as We,n as Tt,o as Pr,p as tt}from"./chunks/chunk-LCP3IKI7.js";import{a as F,c as un,e as vn,f as _t,g as Ms}from"./chunks/chunk-CPKBPQ2C.js";import{a as Rt}from"./chunks/chunk-I4IRHQDW.js";import{a as Ve}from"./chunks/chunk-PBOVSFTJ.js";import"./chunks/chunk-DN2YCFOR.js";import{resolve as Of}from"node:path";var Rn=[{name:"echo",load:async()=>(await import("./chunks/echo-NYDCCFWB.js")).echoCommand},{name:"cat",load:async()=>(await import("./chunks/cat-V45MVNBT.js")).catCommand},{name:"printf",load:async()=>(await import("./chunks/printf-CNXNRQ3I.js")).printfCommand},{name:"ls",load:async()=>(await import("./chunks/ls-67NUUIYT.js")).lsCommand},{name:"mkdir",load:async()=>(await import("./chunks/mkdir-AWDWRBKC.js")).mkdirCommand},{name:"mktemp",load:async()=>(await import("./chunks/mktemp-L6OGMDUO.js")).mktempCommand},{name:"rmdir",load:async()=>(await import("./chunks/rmdir-J3HM7GGM.js")).rmdirCommand},{name:"touch",load:async()=>(await import("./chunks/touch-TVQAUQOG.js")).touchCommand},{name:"rm",load:async()=>(await import("./chunks/rm-UCUTHC3I.js")).rmCommand},{name:"cp",load:async()=>(await import("./chunks/cp-HPLQA35N.js")).cpCommand},{name:"mv",load:async()=>(await import("./chunks/mv-4BJSOT4Y.js")).mvCommand},{name:"ln",load:async()=>(await import("./chunks/ln-B35EKC2Q.js")).lnCommand},{name:"chmod",load:async()=>(await import("./chunks/chmod-A54R4UUQ.js")).chmodCommand},{name:"pwd",load:async()=>(await import("./chunks/pwd-YKLNXWZI.js")).pwdCommand},{name:"readlink",load:async()=>(await import("./chunks/readlink-URO5XTBB.js")).readlinkCommand},{name:"head",load:async()=>(await import("./chunks/head-TLFXMM2T.js")).headCommand},{name:"tail",load:async()=>(await import("./chunks/tail-5TSF5YM4.js")).tailCommand},{name:"wc",load:async()=>(await import("./chunks/wc-VSQBRD6B.js")).wcCommand},{name:"stat",load:async()=>(await import("./chunks/stat-UJ37RBMM.js")).statCommand},{name:"grep",load:async()=>(await import("./chunks/grep-DCPCPQOS.js")).grepCommand},{name:"fgrep",load:async()=>(await import("./chunks/grep-DCPCPQOS.js")).fgrepCommand},{name:"egrep",load:async()=>(await import("./chunks/grep-DCPCPQOS.js")).egrepCommand},{name:"rg",load:async()=>(await import("./chunks/rg-RVULUPDH.js")).rgCommand},{name:"sed",load:async()=>(await import("./chunks/sed-MCLGHZOI.js")).sedCommand},{name:"awk",load:async()=>(await import("./chunks/awk2-U22OR5B5.js")).awkCommand2},{name:"sort",load:async()=>(await import("./chunks/sort-M3DO25D5.js")).sortCommand},{name:"uniq",load:async()=>(await import("./chunks/uniq-K5VRDP4Q.js")).uniqCommand},{name:"comm",load:async()=>(await import("./chunks/comm-URDMZCXL.js")).commCommand},{name:"cut",load:async()=>(await import("./chunks/cut-KP3S36XS.js")).cutCommand},{name:"paste",load:async()=>(await import("./chunks/paste-5TSIBDF7.js")).pasteCommand},{name:"tr",load:async()=>(await import("./chunks/tr-6RPFASYV.js")).trCommand},{name:"rev",load:async()=>(await import("./chunks/rev-CZTQCNOZ.js")).rev},{name:"nl",load:async()=>(await import("./chunks/nl-XHWFVVKH.js")).nl},{name:"fold",load:async()=>(await import("./chunks/fold-YEY7X54W.js")).fold},{name:"expand",load:async()=>(await import("./chunks/expand-P6SNTBGZ.js")).expand},{name:"unexpand",load:async()=>(await import("./chunks/unexpand-JPOQORZF.js")).unexpand},{name:"strings",load:async()=>(await import("./chunks/strings-J2X2Z6N2.js")).strings},{name:"split",load:async()=>(await import("./chunks/split-VZO7223N.js")).split},{name:"column",load:async()=>(await import("./chunks/column-LHHS4D3K.js")).column},{name:"join",load:async()=>(await import("./chunks/join-UQKXU2QP.js")).join},{name:"tee",load:async()=>(await import("./chunks/tee-L4HKV5PD.js")).teeCommand},{name:"find",load:async()=>(await import("./chunks/find-XGVQ6N6L.js")).findCommand},{name:"basename",load:async()=>(await import("./chunks/basename-C4CRGDXP.js")).basenameCommand},{name:"dirname",load:async()=>(await import("./chunks/dirname-TPUFCYF6.js")).dirnameCommand},{name:"tree",load:async()=>(await import("./chunks/tree-ZGP6NPGS.js")).treeCommand},{name:"du",load:async()=>(await import("./chunks/du-WEF5YWQK.js")).duCommand},{name:"env",load:async()=>(await import("./chunks/env-2TSVF4W7.js")).envCommand},{name:"printenv",load:async()=>(await import("./chunks/env-2TSVF4W7.js")).printenvCommand},{name:"alias",load:async()=>(await import("./chunks/alias-3R4G6HQY.js")).aliasCommand},{name:"unalias",load:async()=>(await import("./chunks/alias-3R4G6HQY.js")).unaliasCommand},{name:"history",load:async()=>(await import("./chunks/history-3HAU45KT.js")).historyCommand},{name:"xargs",load:async()=>(await import("./chunks/xargs-HMISWW4I.js")).xargsCommand},{name:"true",load:async()=>(await import("./chunks/true-KFTJGQLQ.js")).trueCommand},{name:"false",load:async()=>(await import("./chunks/true-KFTJGQLQ.js")).falseCommand},{name:"yes",load:async()=>(await import("./chunks/yes-ELH3XQWY.js")).yesCommand},{name:"clear",load:async()=>(await import("./chunks/clear-OE52K3TM.js")).clearCommand},{name:"bash",load:async()=>(await import("./chunks/bash-CFCBBWVH.js")).bashCommand},{name:"sh",load:async()=>(await import("./chunks/bash-CFCBBWVH.js")).shCommand},{name:"jq",load:async()=>(await import("./chunks/jq-GDM3OBBK.js")).jqCommand},{name:"base64",load:async()=>(await import("./chunks/base64-2KKH5BCT.js")).base64Command},{name:"diff",load:async()=>(await import("./chunks/diff-JSJ56EOK.js")).diffCommand},{name:"date",load:async()=>(await import("./chunks/date-FJUBX7TJ.js")).dateCommand},{name:"sleep",load:async()=>(await import("./chunks/sleep-CV6B4M6W.js")).sleepCommand},{name:"timeout",load:async()=>(await import("./chunks/timeout-ATTDYXLX.js")).timeoutCommand},{name:"time",load:async()=>(await import("./chunks/time-J2DAZUIN.js")).timeCommand},{name:"seq",load:async()=>(await import("./chunks/seq-I54NZE75.js")).seqCommand},{name:"expr",load:async()=>(await import("./chunks/expr-FLWT4OCO.js")).exprCommand},{name:"md5sum",load:async()=>(await import("./chunks/md5sum-Z6KAYGDK.js")).md5sumCommand},{name:"sha1sum",load:async()=>(await import("./chunks/sha1sum-CATBXX76.js")).sha1sumCommand},{name:"sha256sum",load:async()=>(await import("./chunks/sha256sum-YGSNBVY3.js")).sha256sumCommand},{name:"file",load:async()=>(await import("./chunks/file-JLUCGBCB.js")).fileCommand},{name:"html-to-markdown",load:async()=>(await import("./chunks/html-to-markdown-E22RLT2U.js")).htmlToMarkdownCommand},{name:"help",load:async()=>(await import("./chunks/help-EXVKU23F.js")).helpCommand},{name:"which",load:async()=>(await import("./chunks/which-4TPGVSBZ.js")).whichCommand},{name:"tac",load:async()=>(await import("./chunks/tac-DG4BMYM5.js")).tac},{name:"hostname",load:async()=>(await import("./chunks/hostname-2I76DUQL.js")).hostname},{name:"whoami",load:async()=>(await import("./chunks/whoami-B5HDVKW6.js")).whoami},{name:"od",load:async()=>(await import("./chunks/od-SI75GLRE.js")).od},{name:"gzip",load:async()=>(await import("./chunks/gzip-6DZIKNBW.js")).gzipCommand},{name:"gunzip",load:async()=>(await import("./chunks/gzip-6DZIKNBW.js")).gunzipCommand},{name:"zcat",load:async()=>(await import("./chunks/gzip-6DZIKNBW.js")).zcatCommand}];(typeof __BROWSER__>"u"||!__BROWSER__)&&(Rn.push({name:"tar",load:async()=>(await import("./chunks/tar-ZGZZDQXO.js")).tarCommand}),Rn.push({name:"yq",load:async()=>(await import("./chunks/yq-GSCDUHGM.js")).yqCommand}),Rn.push({name:"xan",load:async()=>(await import("./chunks/xan-CCS53B7D.js")).xanCommand}),Rn.push({name:"sqlite3",load:async()=>(await import("./chunks/sqlite3-HXVFVP4Z.js")).sqlite3Command}));var Vs=[];(typeof __BROWSER__>"u"||!__BROWSER__)&&(Vs.push({name:"python3",load:async()=>(await import("./chunks/python3-GUWCSSDP.js")).python3Command}),Vs.push({name:"python",load:async()=>(await import("./chunks/python3-GUWCSSDP.js")).pythonCommand}));var zs=[];(typeof __BROWSER__>"u"||!__BROWSER__)&&(zs.push({name:"js-exec",load:async()=>(await import("./chunks/js-exec-VU6F6WLS.js")).jsExecCommand}),zs.push({name:"node",load:async()=>(await import("./chunks/js-exec-VU6F6WLS.js")).nodeStubCommand}));var Tf=[{name:"curl",load:async()=>(await import("./chunks/curl-FIRG3RB6.js")).curlCommand}],da=new Map;function Nr(e){return{name:e.name,async execute(t,n){let r=da.get(e.name);if(r||(r=await _e.runTrustedAsync(()=>Yn(e.load(),n.signal,`bash: ${e.name} was cancelled before it started
4
- `)),da.set(e.name,r)),n.coverage&&(typeof __BROWSER__>"u"||!__BROWSER__)){let{emitFlagCoverage:s}=await Yn(import("./chunks/flag-coverage-4JYKIAVV.js"),n.signal,`bash: ${e.name} was cancelled before it started
5
- `);s(n.coverage,e.name,t)}return r.execute(t,n)}}}function pa(e){return(e?Rn.filter(n=>e.includes(n.name)):Rn).map(Nr)}function ha(){return Tf.map(Nr)}function ma(){return Vs.map(Nr)}function ya(){return zs.map(Nr)}var ga=new WeakMap,wa=new WeakSet;function qs(e){let t=ga.get(e);return t===void 0&&(t=Object.freeze(Object.create(null)),ga.set(e,t),wa.add(t)),t}function Ea(e){return wa.has(e)}var ba={maxSourceBytes:67108864,maxExecDepth:64,maxCallDepth:100,maxCommandCount:1e5,maxLoopIterations:1e5,maxAwkIterations:1e5,maxSedIterations:1e5,maxJqIterations:1e7,maxQueryTokens:1e5,maxQueryDepth:1e3,maxQueryElements:1e6,maxAwkParserTokens:1e5,maxAwkParserDepth:256,maxAwkParserOperations:1e6,maxCsvRows:1e6,maxCsvCells:1e7,maxWorkUnits:1e8,maxTraversalEntries:1e6,maxTraversalDepth:1e3,maxTraversalWork:1e6,maxLiveBytes:536870912,maxInputBytes:536870912,maxFileSystemBytes:1073741824,maxDatabaseBytes:1073741824,maxDatabaseResultBytes:268435456,maxArchiveBytes:1073741824,maxArchiveCompressedBytes:536870912,maxArchiveEntryBytes:536870912,maxArchiveEntries:1e6,maxWorkerMessageBytes:67108864,maxExecutionTimeMs:36e5,maxExtensionCleanupTimeMs:100,maxSqliteTimeoutMs:3e4,maxPythonTimeoutMs:3e4,maxJsTimeoutMs:3e4,maxJsBridgeRequests:1e6,maxGlobOperations:1e6,maxStringLength:67108864,maxArrayElements:1e6,maxHeredocSize:67108864,maxSubstitutionDepth:50,maxBraceExpansionResults:1e5,maxOutputSize:268435456,maxFileDescriptors:4096,maxSourceDepth:100},Ff={...ba,maxSourceBytes:8*1024*1024,maxCommandCount:1e4,maxLoopIterations:1e4,maxAwkIterations:1e4,maxSedIterations:1e4,maxJqIterations:1e4,maxSqliteTimeoutMs:5e3,maxPythonTimeoutMs:1e4,maxJsTimeoutMs:1e4,maxJsBridgeRequests:1e5,maxExtensionCleanupTimeMs:25,maxGlobOperations:1e5,maxStringLength:10*1024*1024,maxArrayElements:1e5,maxHeredocSize:10*1024*1024,maxBraceExpansionResults:1e4,maxOutputSize:10*1024*1024,maxFileDescriptors:1024,maxQueryTokens:25e3,maxQueryDepth:256,maxQueryElements:1e5,maxAwkParserTokens:25e3,maxAwkParserDepth:128,maxAwkParserOperations:1e5,maxCsvRows:1e5,maxCsvCells:1e6,maxWorkUnits:1e5,maxTraversalEntries:1e5,maxTraversalDepth:256,maxTraversalWork:1e5,maxLiveBytes:64*1024*1024,maxInputBytes:32*1024*1024,maxFileSystemBytes:128*1024*1024,maxDatabaseBytes:64*1024*1024,maxDatabaseResultBytes:16*1024*1024,maxArchiveBytes:128*1024*1024,maxArchiveCompressedBytes:64*1024*1024,maxArchiveEntryBytes:64*1024*1024,maxArchiveEntries:1e5,maxWorkerMessageBytes:16*1024*1024,maxExecutionTimeMs:3e4};function Us(e,t="normal"){if(t!=="normal"&&t!=="hardened")throw new RangeError('executionLimitProfile must be "normal" or "hardened"');let n=t==="hardened"?Ff:ba;if(!e)return{...n};let r={maxSourceBytes:e.maxSourceBytes??n.maxSourceBytes,maxExecDepth:e.maxExecDepth??n.maxExecDepth,maxCallDepth:e.maxCallDepth??n.maxCallDepth,maxCommandCount:e.maxCommandCount??n.maxCommandCount,maxLoopIterations:e.maxLoopIterations??n.maxLoopIterations,maxAwkIterations:e.maxAwkIterations??n.maxAwkIterations,maxSedIterations:e.maxSedIterations??n.maxSedIterations,maxJqIterations:e.maxJqIterations??n.maxJqIterations,maxQueryTokens:e.maxQueryTokens??n.maxQueryTokens,maxQueryDepth:e.maxQueryDepth??n.maxQueryDepth,maxQueryElements:e.maxQueryElements??n.maxQueryElements,maxAwkParserTokens:e.maxAwkParserTokens??n.maxAwkParserTokens,maxAwkParserDepth:e.maxAwkParserDepth??n.maxAwkParserDepth,maxAwkParserOperations:e.maxAwkParserOperations??n.maxAwkParserOperations,maxCsvRows:e.maxCsvRows??n.maxCsvRows,maxCsvCells:e.maxCsvCells??n.maxCsvCells,maxWorkUnits:e.maxWorkUnits??n.maxWorkUnits,maxTraversalEntries:e.maxTraversalEntries??n.maxTraversalEntries,maxTraversalDepth:e.maxTraversalDepth??n.maxTraversalDepth,maxTraversalWork:e.maxTraversalWork??n.maxTraversalWork,maxLiveBytes:e.maxLiveBytes??n.maxLiveBytes,maxInputBytes:e.maxInputBytes??n.maxInputBytes,maxFileSystemBytes:e.maxFileSystemBytes??n.maxFileSystemBytes,maxDatabaseBytes:e.maxDatabaseBytes??n.maxDatabaseBytes,maxDatabaseResultBytes:e.maxDatabaseResultBytes??n.maxDatabaseResultBytes,maxArchiveBytes:e.maxArchiveBytes??n.maxArchiveBytes,maxArchiveCompressedBytes:e.maxArchiveCompressedBytes??n.maxArchiveCompressedBytes,maxArchiveEntryBytes:e.maxArchiveEntryBytes??n.maxArchiveEntryBytes,maxArchiveEntries:e.maxArchiveEntries??n.maxArchiveEntries,maxWorkerMessageBytes:e.maxWorkerMessageBytes??n.maxWorkerMessageBytes,maxExecutionTimeMs:e.maxExecutionTimeMs??n.maxExecutionTimeMs,maxExtensionCleanupTimeMs:e.maxExtensionCleanupTimeMs??n.maxExtensionCleanupTimeMs,maxSqliteTimeoutMs:e.maxSqliteTimeoutMs??n.maxSqliteTimeoutMs,maxPythonTimeoutMs:e.maxPythonTimeoutMs??n.maxPythonTimeoutMs,maxJsTimeoutMs:e.maxJsTimeoutMs??n.maxJsTimeoutMs,maxJsBridgeRequests:e.maxJsBridgeRequests??n.maxJsBridgeRequests,maxGlobOperations:e.maxGlobOperations??n.maxGlobOperations,maxStringLength:e.maxStringLength??n.maxStringLength,maxArrayElements:e.maxArrayElements??n.maxArrayElements,maxHeredocSize:e.maxHeredocSize??n.maxHeredocSize,maxSubstitutionDepth:e.maxSubstitutionDepth??n.maxSubstitutionDepth,maxBraceExpansionResults:e.maxBraceExpansionResults??n.maxBraceExpansionResults,maxOutputSize:e.maxOutputSize??n.maxOutputSize,maxFileDescriptors:e.maxFileDescriptors??n.maxFileDescriptors,maxSourceDepth:e.maxSourceDepth??n.maxSourceDepth};for(let s of Object.keys(r)){let i=r[s];if(i!==Number.POSITIVE_INFINITY&&(!Number.isSafeInteger(i)||i<0))throw new RangeError(`${s} must be a non-negative safe integer or positive Infinity`)}return r}function Sa(e){return"load"in e&&typeof e.load=="function"}function Aa(e){let t=null,n=!1,r=new Set,s=a=>{t=a;for(let l of r)l.resolve(a);r.clear()},i=a=>{n=!1;for(let l of r)l.reject(a);r.clear()},o=()=>{n=!0;let a;try{a=Promise.resolve(e.load())}catch(l){i(l);return}fa.call(a,s,i)};return{name:e.name,trusted:e.trusted!==!1,async execute(a,l){if(!t){let c,f=new Promise((d,p)=>{c={resolve:d,reject:p},r.add(c)});n||o();try{t=await Yn(f,l.signal,`bash: ${e.name} was cancelled before it started
6
- `)}finally{c&&r.delete(c)}}let u=t;if(!u)throw new Error(`Failed to load command: ${e.name}`);return u.execute(a,l)}}}var va=Object.freeze(Object.create(null)),Rr=class{limits;signal;commandCount=0;workUnits=0;liveBytes=0;inputBytes=0;outputBytes=0;countersByKind=new Map;bytesByKind=new Map;depthByKind=new Map;cleanupCallbacks=[];poisoned;closed=!1;startedAt=Date.now();get remainingLiveBytes(){return Math.max(0,this.limits.maxLiveBytes-this.liveBytes)}get outputBytesUsed(){return this.outputBytes}constructor(t,n=void 0){this.limits=t,this.signal=n}fail(t){throw this.poisoned??=t,this.poisoned}poisonAfterAbort(t){this.poisoned??=t}assertUsable(){if(this.poisoned)throw this.poisoned;if(this.closed)throw new Error("execution budget is already closed");this.throwIfAborted()}chargeCommand(){return this.consume("commands",1,"execution")}consumeWork(t=1,n="execution"){return this.consume("work",t,n)}consumeLimited(t,n,r,s=t){this.assertUsable();let i=this.countersByKind.get(t)??0;return(!Number.isSafeInteger(n)||n<0||!Number.isSafeInteger(r)||r<0||n>r-i)&&this.fail(new P(`${s}: ${t} work limit exceeded (${r})`,"iterations")),n>this.limits.maxWorkUnits-this.workUnits&&this.fail(new P(`${s}: aggregate work limit exceeded (${this.limits.maxWorkUnits})`,"iterations")),this.countersByKind.set(t,i+n),this.workUnits+=n,i+n}consumeInput(t,n="execution"){return this.assertUsable(),(!Number.isSafeInteger(t)||t<0||t>this.limits.maxInputBytes-this.inputBytes)&&this.fail(new P(`${n}: aggregate input size limit exceeded (${this.limits.maxInputBytes} bytes)`,"string_length")),this.inputBytes+=t,this.inputBytes}consume(t,n=1,r=t){this.assertUsable();let s=this.countersByKind.get(t)??0,i=t==="commands"?this.commandCount:this.workUnits,o=t==="commands"?this.limits.maxCommandCount:this.limits.maxWorkUnits;(!Number.isSafeInteger(n)||n<0||n>o-i)&&this.fail(new P(t==="commands"?`too many commands executed (>${o}), increase executionLimits.maxCommandCount`:`${r}: ${t} work limit exceeded (${o})`,t==="commands"?"commands":"iterations"));let a=i+n;return t==="commands"?this.commandCount=a:this.workUnits=a,this.countersByKind.set(t,s+n),a}reserveBytes(t,n,r){this.assertUsable();let s=typeof t=="string"?t:"live",i=typeof t=="string"?n:t,o=typeof t=="string"?r??s:n??"execution";(!Number.isSafeInteger(i)||i<0||i>this.limits.maxLiveBytes-this.liveBytes)&&this.fail(new P(`${o}: live byte limit exceeded (${this.limits.maxLiveBytes} bytes)`,"string_length")),this.liveBytes+=i,this.bytesByKind.set(s,(this.bytesByKind.get(s)??0)+i);let a=!1;return{release:()=>{if(a)return;a=!0,this.liveBytes-=i;let l=(this.bytesByKind.get(s)??i)-i;l<=0?this.bytesByKind.delete(s):this.bytesByKind.set(s,l)}}}appendOutput(t,n,r="execution",s=0,i="text"){this.assertUsable();let o=i==="bytes"?n.length:F(n);(!Number.isSafeInteger(s)||s<0||s>o)&&this.fail(new P(`${r}: invalid ${t} accounting`,"output_size"));let a=o-s;return a>this.limits.maxOutputSize-this.outputBytes&&this.fail(new P(`${r}: total output size exceeded (>${this.limits.maxOutputSize} bytes), increase executionLimits.maxOutputSize`,"output_size")),this.outputBytes+=a,o}accountResult(t,n="execution",r=Number.POSITIVE_INFINITY){let s=t.internalOutputAccounting,i=Math.min(s?.stdout??0,r),o=Math.min(s?.stderr??0,Math.max(0,r-i)),a=this.appendOutput("stdout",t.stdout,n,i,t.stdoutKind==="bytes"||t.stdoutEncoding==="binary"?"bytes":"text"),l=this.appendOutput("stderr",t.stderr,n,o);return Object.isExtensible(t)?(t.internalOutputAccounting={stdout:a,stderr:l},t):a===0&&l===0?t:{...t,internalOutputAccounting:{stdout:a,stderr:l}}}relinquishOutput(t,n,r){this.assertUsable(),r!==va&&this.fail(new P(`${n}: unauthorized output accounting release`,"output_size")),(!Number.isSafeInteger(t)||t<0||t>this.outputBytes)&&this.fail(new P(`${n}: invalid output accounting release`,"output_size")),this.outputBytes-=t}enterDepth(t,n=this.limits.maxCallDepth,r){this.assertUsable();let s=typeof n=="number"?n:this.limits.maxCallDepth,i=typeof n=="string"?n:r??t,o=this.depthByKind.get(t)??0;o>=s&&this.fail(new P(`${i}: maximum depth (${s}) exceeded`,"recursion")),this.depthByKind.set(t,o+1);let a=!1;return{release:()=>{if(a)return;a=!0;let l=(this.depthByKind.get(t)??1)-1;l<=0?this.depthByKind.delete(t):this.depthByKind.set(t,l)}}}throwIfAborted(t="execution"){this.signal?.aborted&&this.fail(new We("",`bash: ${t} aborted
3
+ import{a as Nn,b as Rn,c as Wt}from"./chunks/chunk-PEJXCXSY.js";import{a as Rr,b as Jn}from"./chunks/chunk-BC5OXEFJ.js";import{a as ua,b as ca,c as Xn,d as Yn}from"./chunks/chunk-EFS34UUR.js";import{c as Us,e as ha,f as ma}from"./chunks/chunk-ENEHPI32.js";import{a as Bt}from"./chunks/chunk-7NEXHFSS.js";import{a as Mt,b as Qe,c as qs}from"./chunks/chunk-MROECM42.js";import{a as er,b as pa}from"./chunks/chunk-ABM5WFEO.js";import{a as me}from"./chunks/chunk-26O2G5LX.js";import{a as vn,b as _e}from"./chunks/chunk-VGSRQOLD.js";import"./chunks/chunk-XVKL2UZA.js";import{d as Ft,e as kn}from"./chunks/chunk-QIDBJNMB.js";import"./chunks/chunk-7JZKVC3F.js";import{a as da}from"./chunks/chunk-UPUFWGHR.js";import{a as q,b as Dt,c as Q,d as ct,e as Pn,f as tt,g as Cn}from"./chunks/chunk-43E7AR6A.js";import{a as $n,b as Ge,c as He,d as Ie,e as Me,f as Be,g as U,h as oe,i as Ze,j as Lt,k as Cr,l as C,m as We,n as Tt,o as Nr,p as et}from"./chunks/chunk-EPWMLTS6.js";import{a as W,c as un,e as xn,f as _t,g as zs}from"./chunks/chunk-GFI5BHZX.js";import{a as Rt,b as fa}from"./chunks/chunk-7DPD5PK3.js";import{a as Ve}from"./chunks/chunk-PBOVSFTJ.js";import"./chunks/chunk-DN2YCFOR.js";import{resolve as Bf}from"node:path";var Dn=[{name:"echo",load:async()=>(await import("./chunks/echo-NYDCCFWB.js")).echoCommand},{name:"cat",load:async()=>(await import("./chunks/cat-AST5Y57Y.js")).catCommand},{name:"printf",load:async()=>(await import("./chunks/printf-PQKUEWX5.js")).printfCommand},{name:"ls",load:async()=>(await import("./chunks/ls-QCAGDEDW.js")).lsCommand},{name:"mkdir",load:async()=>(await import("./chunks/mkdir-3XFSFVPC.js")).mkdirCommand},{name:"mktemp",load:async()=>(await import("./chunks/mktemp-5FA55IJS.js")).mktempCommand},{name:"rmdir",load:async()=>(await import("./chunks/rmdir-57J3AGQU.js")).rmdirCommand},{name:"touch",load:async()=>(await import("./chunks/touch-YE5LMLLE.js")).touchCommand},{name:"rm",load:async()=>(await import("./chunks/rm-NPIAQT6U.js")).rmCommand},{name:"cp",load:async()=>(await import("./chunks/cp-7AH7TSQ6.js")).cpCommand},{name:"mv",load:async()=>(await import("./chunks/mv-UASF6NAX.js")).mvCommand},{name:"ln",load:async()=>(await import("./chunks/ln-B35EKC2Q.js")).lnCommand},{name:"chmod",load:async()=>(await import("./chunks/chmod-BFP7P5CD.js")).chmodCommand},{name:"pwd",load:async()=>(await import("./chunks/pwd-YKLNXWZI.js")).pwdCommand},{name:"readlink",load:async()=>(await import("./chunks/readlink-4Z75K3AI.js")).readlinkCommand},{name:"head",load:async()=>(await import("./chunks/head-ZQIB2GSI.js")).headCommand},{name:"tail",load:async()=>(await import("./chunks/tail-G4PLDIOK.js")).tailCommand},{name:"wc",load:async()=>(await import("./chunks/wc-VLOME6PL.js")).wcCommand},{name:"stat",load:async()=>(await import("./chunks/stat-RKSIL4YV.js")).statCommand},{name:"grep",load:async()=>(await import("./chunks/grep-HI55D7F7.js")).grepCommand},{name:"fgrep",load:async()=>(await import("./chunks/grep-HI55D7F7.js")).fgrepCommand},{name:"egrep",load:async()=>(await import("./chunks/grep-HI55D7F7.js")).egrepCommand},{name:"rg",load:async()=>(await import("./chunks/rg-ULWB5MQG.js")).rgCommand},{name:"sed",load:async()=>(await import("./chunks/sed-XV7BZPKI.js")).sedCommand},{name:"awk",load:async()=>(await import("./chunks/awk2-EPZ2CEQT.js")).awkCommand2},{name:"sort",load:async()=>(await import("./chunks/sort-UOMFLGRW.js")).sortCommand},{name:"uniq",load:async()=>(await import("./chunks/uniq-SZDRNEYK.js")).uniqCommand},{name:"comm",load:async()=>(await import("./chunks/comm-JEJ6GWEA.js")).commCommand},{name:"cut",load:async()=>(await import("./chunks/cut-OVTLUT2B.js")).cutCommand},{name:"paste",load:async()=>(await import("./chunks/paste-SH5RZ4ZO.js")).pasteCommand},{name:"tr",load:async()=>(await import("./chunks/tr-7KFUMSUF.js")).trCommand},{name:"rev",load:async()=>(await import("./chunks/rev-6SA3VC3J.js")).rev},{name:"nl",load:async()=>(await import("./chunks/nl-HUDE6DQC.js")).nl},{name:"fold",load:async()=>(await import("./chunks/fold-E6A5I4DW.js")).fold},{name:"expand",load:async()=>(await import("./chunks/expand-B4CPOZN5.js")).expand},{name:"unexpand",load:async()=>(await import("./chunks/unexpand-67EBVEPB.js")).unexpand},{name:"strings",load:async()=>(await import("./chunks/strings-AL7T5GDQ.js")).strings},{name:"split",load:async()=>(await import("./chunks/split-IBL3NIVH.js")).split},{name:"column",load:async()=>(await import("./chunks/column-EGAQ7QMC.js")).column},{name:"join",load:async()=>(await import("./chunks/join-KCYMLQ3V.js")).join},{name:"tee",load:async()=>(await import("./chunks/tee-NP4ULCWD.js")).teeCommand},{name:"find",load:async()=>(await import("./chunks/find-QYLHUYOP.js")).findCommand},{name:"basename",load:async()=>(await import("./chunks/basename-C4CRGDXP.js")).basenameCommand},{name:"dirname",load:async()=>(await import("./chunks/dirname-TPUFCYF6.js")).dirnameCommand},{name:"tree",load:async()=>(await import("./chunks/tree-ZGP6NPGS.js")).treeCommand},{name:"du",load:async()=>(await import("./chunks/du-M2PB5NUH.js")).duCommand},{name:"env",load:async()=>(await import("./chunks/env-EUSAZGWO.js")).envCommand},{name:"printenv",load:async()=>(await import("./chunks/env-EUSAZGWO.js")).printenvCommand},{name:"alias",load:async()=>(await import("./chunks/alias-3R4G6HQY.js")).aliasCommand},{name:"unalias",load:async()=>(await import("./chunks/alias-3R4G6HQY.js")).unaliasCommand},{name:"history",load:async()=>(await import("./chunks/history-3HAU45KT.js")).historyCommand},{name:"xargs",load:async()=>(await import("./chunks/xargs-CLQL2WFV.js")).xargsCommand},{name:"true",load:async()=>(await import("./chunks/true-KFTJGQLQ.js")).trueCommand},{name:"false",load:async()=>(await import("./chunks/true-KFTJGQLQ.js")).falseCommand},{name:"yes",load:async()=>(await import("./chunks/yes-OOBLAITP.js")).yesCommand},{name:"clear",load:async()=>(await import("./chunks/clear-OE52K3TM.js")).clearCommand},{name:"bash",load:async()=>(await import("./chunks/bash-4Q4RMIZL.js")).bashCommand},{name:"sh",load:async()=>(await import("./chunks/bash-4Q4RMIZL.js")).shCommand},{name:"jq",load:async()=>(await import("./chunks/jq-KNI4FJIL.js")).jqCommand},{name:"base64",load:async()=>(await import("./chunks/base64-D7ZXJQN6.js")).base64Command},{name:"diff",load:async()=>(await import("./chunks/diff-R6QTSWD2.js")).diffCommand},{name:"date",load:async()=>(await import("./chunks/date-MKP5YWWY.js")).dateCommand},{name:"sleep",load:async()=>(await import("./chunks/sleep-CV6B4M6W.js")).sleepCommand},{name:"timeout",load:async()=>(await import("./chunks/timeout-EJIGKZUX.js")).timeoutCommand},{name:"time",load:async()=>(await import("./chunks/time-ZMFJL7MD.js")).timeCommand},{name:"seq",load:async()=>(await import("./chunks/seq-ZVBT2JEI.js")).seqCommand},{name:"expr",load:async()=>(await import("./chunks/expr-AQBMSEFL.js")).exprCommand},{name:"md5sum",load:async()=>(await import("./chunks/md5sum-OPJ77ZY7.js")).md5sumCommand},{name:"sha1sum",load:async()=>(await import("./chunks/sha1sum-JGOB5K4J.js")).sha1sumCommand},{name:"sha256sum",load:async()=>(await import("./chunks/sha256sum-S5DS6Q6N.js")).sha256sumCommand},{name:"file",load:async()=>(await import("./chunks/file-22CVQBNS.js")).fileCommand},{name:"html-to-markdown",load:async()=>(await import("./chunks/html-to-markdown-7ZNLM4SQ.js")).htmlToMarkdownCommand},{name:"help",load:async()=>(await import("./chunks/help-EXVKU23F.js")).helpCommand},{name:"which",load:async()=>(await import("./chunks/which-4TPGVSBZ.js")).whichCommand},{name:"tac",load:async()=>(await import("./chunks/tac-36B6LBNS.js")).tac},{name:"hostname",load:async()=>(await import("./chunks/hostname-2I76DUQL.js")).hostname},{name:"whoami",load:async()=>(await import("./chunks/whoami-B5HDVKW6.js")).whoami},{name:"od",load:async()=>(await import("./chunks/od-CECQKF5P.js")).od},{name:"gzip",load:async()=>(await import("./chunks/gzip-2GJMVXCF.js")).gzipCommand},{name:"gunzip",load:async()=>(await import("./chunks/gzip-2GJMVXCF.js")).gunzipCommand},{name:"zcat",load:async()=>(await import("./chunks/gzip-2GJMVXCF.js")).zcatCommand}];(typeof __BROWSER__>"u"||!__BROWSER__)&&(Dn.push({name:"tar",load:async()=>(await import("./chunks/tar-YG6SY2RU.js")).tarCommand}),Dn.push({name:"yq",load:async()=>(await import("./chunks/yq-YQ4YFM26.js")).yqCommand}),Dn.push({name:"xan",load:async()=>(await import("./chunks/xan-FVGJAHFV.js")).xanCommand}),Dn.push({name:"sqlite3",load:async()=>(await import("./chunks/sqlite3-YIM3BYLS.js")).sqlite3Command}));var js=[];(typeof __BROWSER__>"u"||!__BROWSER__)&&(js.push({name:"python3",load:async()=>(await import("./chunks/python3-UE36ZXQT.js")).python3Command}),js.push({name:"python",load:async()=>(await import("./chunks/python3-UE36ZXQT.js")).pythonCommand}));var Gs=[];(typeof __BROWSER__>"u"||!__BROWSER__)&&(Gs.push({name:"js-exec",load:async()=>(await import("./chunks/js-exec-OWDAX677.js")).jsExecCommand}),Gs.push({name:"node",load:async()=>(await import("./chunks/js-exec-OWDAX677.js")).nodeStubCommand}));var zf=[{name:"curl",load:async()=>(await import("./chunks/curl-7FCZQCFU.js")).curlCommand}],ya=new Map;function Dr(e){return{name:e.name,async execute(t,n){let r=ya.get(e.name);if(r||(r=await _e.runTrustedAsync(()=>Jn(e.load(),n.signal,`bash: ${e.name} was cancelled before it started
4
+ `)),ya.set(e.name,r)),n.coverage&&(typeof __BROWSER__>"u"||!__BROWSER__)){let{emitFlagCoverage:s}=await Jn(import("./chunks/flag-coverage-CTPK5ZWJ.js"),n.signal,`bash: ${e.name} was cancelled before it started
5
+ `);s(n.coverage,e.name,t)}return r.execute(t,n)}}}function ga(e){return(e?Dn.filter(n=>e.includes(n.name)):Dn).map(Dr)}function wa(){return zf.map(Dr)}function Ea(){return js.map(Dr)}function ba(){return Gs.map(Dr)}var Sa=new WeakMap,Aa=new WeakSet;function Hs(e){let t=Sa.get(e);return t===void 0&&(t=Object.freeze(Object.create(null)),Sa.set(e,t),Aa.add(t)),t}function va(e){return Aa.has(e)}var xa={maxSourceBytes:67108864,maxExecDepth:64,maxCallDepth:100,maxCommandCount:1e5,maxLoopIterations:1e5,maxAwkIterations:1e5,maxSedIterations:1e5,maxJqIterations:1e7,maxQueryTokens:1e5,maxQueryDepth:1e3,maxQueryElements:1e6,maxAwkParserTokens:1e5,maxAwkParserDepth:256,maxAwkParserOperations:1e6,maxCsvRows:1e6,maxCsvCells:1e7,maxWorkUnits:1e8,maxTraversalEntries:1e6,maxTraversalDepth:1e3,maxTraversalWork:1e6,maxLiveBytes:536870912,maxInputBytes:536870912,maxFileSystemBytes:1073741824,maxDatabaseBytes:1073741824,maxDatabaseResultBytes:268435456,maxArchiveBytes:1073741824,maxArchiveCompressedBytes:536870912,maxArchiveEntryBytes:536870912,maxArchiveEntries:1e6,maxWorkerMessageBytes:67108864,maxExecutionTimeMs:36e5,maxExtensionCleanupTimeMs:100,maxSqliteTimeoutMs:3e4,maxPythonTimeoutMs:3e4,maxJsTimeoutMs:3e4,maxJsBridgeRequests:1e6,maxGlobOperations:1e6,maxStringLength:67108864,maxArrayElements:1e6,maxHeredocSize:67108864,maxSubstitutionDepth:50,maxBraceExpansionResults:1e5,maxOutputSize:268435456,maxFileDescriptors:4096,maxSourceDepth:100},qf={...xa,maxSourceBytes:8*1024*1024,maxCommandCount:1e4,maxLoopIterations:1e4,maxAwkIterations:1e4,maxSedIterations:1e4,maxJqIterations:1e4,maxSqliteTimeoutMs:5e3,maxPythonTimeoutMs:1e4,maxJsTimeoutMs:1e4,maxJsBridgeRequests:1e5,maxExtensionCleanupTimeMs:25,maxGlobOperations:1e5,maxStringLength:10*1024*1024,maxArrayElements:1e5,maxHeredocSize:10*1024*1024,maxBraceExpansionResults:1e4,maxOutputSize:10*1024*1024,maxFileDescriptors:1024,maxQueryTokens:25e3,maxQueryDepth:256,maxQueryElements:1e5,maxAwkParserTokens:25e3,maxAwkParserDepth:128,maxAwkParserOperations:1e5,maxCsvRows:1e5,maxCsvCells:1e6,maxWorkUnits:1e5,maxTraversalEntries:1e5,maxTraversalDepth:256,maxTraversalWork:1e5,maxLiveBytes:64*1024*1024,maxInputBytes:32*1024*1024,maxFileSystemBytes:128*1024*1024,maxDatabaseBytes:64*1024*1024,maxDatabaseResultBytes:16*1024*1024,maxArchiveBytes:128*1024*1024,maxArchiveCompressedBytes:64*1024*1024,maxArchiveEntryBytes:64*1024*1024,maxArchiveEntries:1e5,maxWorkerMessageBytes:16*1024*1024,maxExecutionTimeMs:3e4};function Zs(e,t="normal"){if(t!=="normal"&&t!=="hardened")throw new RangeError('executionLimitProfile must be "normal" or "hardened"');let n=t==="hardened"?qf:xa;if(!e)return{...n};let r={maxSourceBytes:e.maxSourceBytes??n.maxSourceBytes,maxExecDepth:e.maxExecDepth??n.maxExecDepth,maxCallDepth:e.maxCallDepth??n.maxCallDepth,maxCommandCount:e.maxCommandCount??n.maxCommandCount,maxLoopIterations:e.maxLoopIterations??n.maxLoopIterations,maxAwkIterations:e.maxAwkIterations??n.maxAwkIterations,maxSedIterations:e.maxSedIterations??n.maxSedIterations,maxJqIterations:e.maxJqIterations??n.maxJqIterations,maxQueryTokens:e.maxQueryTokens??n.maxQueryTokens,maxQueryDepth:e.maxQueryDepth??n.maxQueryDepth,maxQueryElements:e.maxQueryElements??n.maxQueryElements,maxAwkParserTokens:e.maxAwkParserTokens??n.maxAwkParserTokens,maxAwkParserDepth:e.maxAwkParserDepth??n.maxAwkParserDepth,maxAwkParserOperations:e.maxAwkParserOperations??n.maxAwkParserOperations,maxCsvRows:e.maxCsvRows??n.maxCsvRows,maxCsvCells:e.maxCsvCells??n.maxCsvCells,maxWorkUnits:e.maxWorkUnits??n.maxWorkUnits,maxTraversalEntries:e.maxTraversalEntries??n.maxTraversalEntries,maxTraversalDepth:e.maxTraversalDepth??n.maxTraversalDepth,maxTraversalWork:e.maxTraversalWork??n.maxTraversalWork,maxLiveBytes:e.maxLiveBytes??n.maxLiveBytes,maxInputBytes:e.maxInputBytes??n.maxInputBytes,maxFileSystemBytes:e.maxFileSystemBytes??n.maxFileSystemBytes,maxDatabaseBytes:e.maxDatabaseBytes??n.maxDatabaseBytes,maxDatabaseResultBytes:e.maxDatabaseResultBytes??n.maxDatabaseResultBytes,maxArchiveBytes:e.maxArchiveBytes??n.maxArchiveBytes,maxArchiveCompressedBytes:e.maxArchiveCompressedBytes??n.maxArchiveCompressedBytes,maxArchiveEntryBytes:e.maxArchiveEntryBytes??n.maxArchiveEntryBytes,maxArchiveEntries:e.maxArchiveEntries??n.maxArchiveEntries,maxWorkerMessageBytes:e.maxWorkerMessageBytes??n.maxWorkerMessageBytes,maxExecutionTimeMs:e.maxExecutionTimeMs??n.maxExecutionTimeMs,maxExtensionCleanupTimeMs:e.maxExtensionCleanupTimeMs??n.maxExtensionCleanupTimeMs,maxSqliteTimeoutMs:e.maxSqliteTimeoutMs??n.maxSqliteTimeoutMs,maxPythonTimeoutMs:e.maxPythonTimeoutMs??n.maxPythonTimeoutMs,maxJsTimeoutMs:e.maxJsTimeoutMs??n.maxJsTimeoutMs,maxJsBridgeRequests:e.maxJsBridgeRequests??n.maxJsBridgeRequests,maxGlobOperations:e.maxGlobOperations??n.maxGlobOperations,maxStringLength:e.maxStringLength??n.maxStringLength,maxArrayElements:e.maxArrayElements??n.maxArrayElements,maxHeredocSize:e.maxHeredocSize??n.maxHeredocSize,maxSubstitutionDepth:e.maxSubstitutionDepth??n.maxSubstitutionDepth,maxBraceExpansionResults:e.maxBraceExpansionResults??n.maxBraceExpansionResults,maxOutputSize:e.maxOutputSize??n.maxOutputSize,maxFileDescriptors:e.maxFileDescriptors??n.maxFileDescriptors,maxSourceDepth:e.maxSourceDepth??n.maxSourceDepth};for(let s of Object.keys(r)){let i=r[s];if(i!==Number.POSITIVE_INFINITY&&(!Number.isSafeInteger(i)||i<0))throw new RangeError(`${s} must be a non-negative safe integer or positive Infinity`)}return r}function $a(e){return"load"in e&&typeof e.load=="function"}function ka(e){let t=null,n=!1,r=new Set,s=a=>{t=a;for(let l of r)l.resolve(a);r.clear()},i=a=>{n=!1;for(let l of r)l.reject(a);r.clear()},o=()=>{n=!0;let a;try{a=Promise.resolve(e.load())}catch(l){i(l);return}ma.call(a,s,i)};return{name:e.name,trusted:e.trusted!==!1,async execute(a,l){if(!t){let c,f=new Promise((d,p)=>{c={resolve:d,reject:p},r.add(c)});n||o();try{t=await Jn(f,l.signal,`bash: ${e.name} was cancelled before it started
6
+ `)}finally{c&&r.delete(c)}}let u=t;if(!u)throw new Error(`Failed to load command: ${e.name}`);return u.execute(a,l)}}}var Pa=Object.freeze(Object.create(null)),Ir=class{limits;signal;commandCount=0;workUnits=0;liveBytes=0;inputBytes=0;outputBytes=0;countersByKind=new Map;bytesByKind=new Map;depthByKind=new Map;cleanupCallbacks=[];poisoned;closed=!1;startedAt=Date.now();get remainingLiveBytes(){return Math.max(0,this.limits.maxLiveBytes-this.liveBytes)}get outputBytesUsed(){return this.outputBytes}constructor(t,n=void 0){this.limits=t,this.signal=n}fail(t){throw this.poisoned??=t,this.poisoned}poisonAfterAbort(t){this.poisoned??=t}assertUsable(){if(this.poisoned)throw this.poisoned;if(this.closed)throw new Error("execution budget is already closed");this.throwIfAborted()}chargeCommand(){return this.consume("commands",1,"execution")}consumeWork(t=1,n="execution"){return this.consume("work",t,n)}consumeLimited(t,n,r,s=t){this.assertUsable();let i=this.countersByKind.get(t)??0;return(!Number.isSafeInteger(n)||n<0||!Number.isSafeInteger(r)||r<0||n>r-i)&&this.fail(new C(`${s}: ${t} work limit exceeded (${r})`,"iterations")),n>this.limits.maxWorkUnits-this.workUnits&&this.fail(new C(`${s}: aggregate work limit exceeded (${this.limits.maxWorkUnits})`,"iterations")),this.countersByKind.set(t,i+n),this.workUnits+=n,i+n}consumeInput(t,n="execution"){return this.assertUsable(),(!Number.isSafeInteger(t)||t<0||t>this.limits.maxInputBytes-this.inputBytes)&&this.fail(new C(`${n}: aggregate input size limit exceeded (${this.limits.maxInputBytes} bytes)`,"string_length")),this.inputBytes+=t,this.inputBytes}consume(t,n=1,r=t){this.assertUsable();let s=this.countersByKind.get(t)??0,i=t==="commands"?this.commandCount:this.workUnits,o=t==="commands"?this.limits.maxCommandCount:this.limits.maxWorkUnits;(!Number.isSafeInteger(n)||n<0||n>o-i)&&this.fail(new C(t==="commands"?`too many commands executed (>${o}), increase executionLimits.maxCommandCount`:`${r}: ${t} work limit exceeded (${o})`,t==="commands"?"commands":"iterations"));let a=i+n;return t==="commands"?this.commandCount=a:this.workUnits=a,this.countersByKind.set(t,s+n),a}reserveBytes(t,n,r){this.assertUsable();let s=typeof t=="string"?t:"live",i=typeof t=="string"?n:t,o=typeof t=="string"?r??s:n??"execution";(!Number.isSafeInteger(i)||i<0||i>this.limits.maxLiveBytes-this.liveBytes)&&this.fail(new C(`${o}: live byte limit exceeded (${this.limits.maxLiveBytes} bytes)`,"string_length")),this.liveBytes+=i,this.bytesByKind.set(s,(this.bytesByKind.get(s)??0)+i);let a=!1;return{release:()=>{if(a)return;a=!0,this.liveBytes-=i;let l=(this.bytesByKind.get(s)??i)-i;l<=0?this.bytesByKind.delete(s):this.bytesByKind.set(s,l)}}}appendOutput(t,n,r="execution",s=0,i="text"){this.assertUsable();let o=i==="bytes"?n.length:W(n);(!Number.isSafeInteger(s)||s<0||s>o)&&this.fail(new C(`${r}: invalid ${t} accounting`,"output_size"));let a=o-s;return a>this.limits.maxOutputSize-this.outputBytes&&this.fail(new C(`${r}: total output size exceeded (>${this.limits.maxOutputSize} bytes), increase executionLimits.maxOutputSize`,"output_size")),this.outputBytes+=a,o}accountResult(t,n="execution",r=Number.POSITIVE_INFINITY){let s=t.internalOutputAccounting,i=Math.min(s?.stdout??0,r),o=Math.min(s?.stderr??0,Math.max(0,r-i)),a=this.appendOutput("stdout",t.stdout,n,i,t.stdoutKind==="bytes"||t.stdoutEncoding==="binary"?"bytes":"text"),l=this.appendOutput("stderr",t.stderr,n,o);return Object.isExtensible(t)?(t.internalOutputAccounting={stdout:a,stderr:l},t):a===0&&l===0?t:{...t,internalOutputAccounting:{stdout:a,stderr:l}}}relinquishOutput(t,n,r){this.assertUsable(),r!==Pa&&this.fail(new C(`${n}: unauthorized output accounting release`,"output_size")),(!Number.isSafeInteger(t)||t<0||t>this.outputBytes)&&this.fail(new C(`${n}: invalid output accounting release`,"output_size")),this.outputBytes-=t}enterDepth(t,n=this.limits.maxCallDepth,r){this.assertUsable();let s=typeof n=="number"?n:this.limits.maxCallDepth,i=typeof n=="string"?n:r??t,o=this.depthByKind.get(t)??0;o>=s&&this.fail(new C(`${i}: maximum depth (${s}) exceeded`,"recursion")),this.depthByKind.set(t,o+1);let a=!1;return{release:()=>{if(a)return;a=!0;let l=(this.depthByKind.get(t)??1)-1;l<=0?this.depthByKind.delete(t):this.depthByKind.set(t,l)}}}throwIfAborted(t="execution"){this.signal?.aborted&&this.fail(new We("",`bash: ${t} aborted
7
7
  `)),Date.now()-this.startedAt>this.limits.maxExecutionTimeMs&&this.fail(new We("",`bash: ${t} exceeded execution deadline (${this.limits.maxExecutionTimeMs}ms)
8
- `))}remainingTimeMs(){return Math.max(0,this.limits.maxExecutionTimeMs-(Date.now()-this.startedAt))}registerCleanup(t){this.assertUsable(),this.cleanupCallbacks.push(t);let n=!0;return()=>{if(!n)return;n=!1;let r=this.cleanupCallbacks.indexOf(t);r>=0&&this.cleanupCallbacks.splice(r,1)}}async close(){if(this.closed)return;this.closed=!0;let t=[],n=Date.now()+this.limits.maxExtensionCleanupTimeMs;for(let r=this.cleanupCallbacks.length-1;r>=0;r--)try{let s=n-Date.now();if(s<=0){t.push(new Error("execution cleanup grace period exceeded"));break}let i,o=await Promise.race([Promise.resolve().then(this.cleanupCallbacks[r]).then(()=>({ok:!0}),a=>({ok:!1,error:a})),new Promise(a=>{i=Kn(()=>a({ok:!1,error:new Error("execution cleanup grace period exceeded")}),s)})]);if(Xn(i),!o.ok&&(t.push(o.error),Date.now()>=n))break}catch(s){t.push(s)}if(this.cleanupCallbacks.length=0,this.depthByKind.clear(),this.bytesByKind.clear(),this.liveBytes=0,t.length>0)throw new AggregateError(t,"execution cleanup failed")}assertExecDepth(t){this.assertUsable(),t>this.limits.maxExecDepth&&this.fail(new P(`maximum nested execution depth (${this.limits.maxExecDepth}) exceeded`,"recursion"))}};function xa(e){let t=Object.create(null);return Object.defineProperties(t,{remainingLiveBytes:{enumerable:!0,get:()=>e.remainingLiveBytes},consumeWork:{enumerable:!0,value:e.consumeWork.bind(e)},consumeLimited:{enumerable:!0,value:e.consumeLimited.bind(e)},consumeInput:{enumerable:!0,value:e.consumeInput.bind(e)},reserveBytes:{enumerable:!0,value:e.reserveBytes.bind(e)},enterDepth:{enumerable:!0,value:e.enterDepth.bind(e)},throwIfAborted:{enumerable:!0,value:e.throwIfAborted.bind(e)},remainingTimeMs:{enumerable:!0,value:e.remainingTimeMs.bind(e)},registerCleanup:{enumerable:!0,value:e.registerCleanup.bind(e)}}),Object.freeze(t)}function $a(e,t,n="pipeline"){e.relinquishOutput(t,n,va)}var cn=new TextEncoder;function Mf(e){return typeof e=="object"&&e!==null&&!(e instanceof Uint8Array)&&"content"in e}var bt=class{data=new Map;entryIdentities=new WeakMap;nextEntryIdentity=1;maxTotalBytes;retainedBytes=0;contentReferences=new WeakMap;materializedContent(t){return t?.type==="file"&&"content"in t?t.content:null}storedByteLength(t){return t===null?0:t instanceof Uint8Array?t.byteLength:F(t)}wouldReleaseBytes(t){let n=this.materializedContent(t);return n===null?0:n instanceof Uint8Array?this.contentReferences.get(n)===1?n.byteLength:0:this.storedByteLength(n)}assertCanAllocate(t,n){let r=this.wouldReleaseBytes(this.data.get(t));if(!Number.isSafeInteger(n)||n<0||n>this.maxTotalBytes-this.retainedBytes+r)throw new Error(`ENOSPC: in-memory filesystem byte limit exceeded (${this.maxTotalBytes} bytes)`)}setEntry(t,n){let r=this.data.get(t),s=this.materializedContent(r),i=this.materializedContent(n);if(s===i){this.data.set(t,n);return}let o=this.wouldReleaseBytes(r),a=i instanceof Uint8Array?this.contentReferences.has(i)?0:i.byteLength:this.storedByteLength(i);if(a>this.maxTotalBytes-this.retainedBytes+o)throw new Error(`ENOSPC: in-memory filesystem byte limit exceeded (${this.maxTotalBytes} bytes)`);if(s instanceof Uint8Array){let l=this.contentReferences.get(s)??0;l<=1?this.contentReferences.delete(s):this.contentReferences.set(s,l-1)}i instanceof Uint8Array&&this.contentReferences.set(i,(this.contentReferences.get(i)??0)+1),this.retainedBytes+=a-o,this.data.set(t,n)}deleteEntry(t){let n=this.data.get(t);if(!n)return!1;let r=this.materializedContent(n),s=this.wouldReleaseBytes(n);if(r instanceof Uint8Array){let i=this.contentReferences.get(r)??0;i<=1?this.contentReferences.delete(r):this.contentReferences.set(r,i-1)}return this.retainedBytes-=s,this.data.delete(t)}contentByteLength(t,n){if(t instanceof Uint8Array)return t.byteLength;if(n==="hex")return Math.floor(t.length/2);if(n==="base64"){let r=t.endsWith("==")?2:t.endsWith("=")?1:0;return Math.max(0,Math.floor(t.length*3/4)-r)}return n==="binary"||n==="latin1"?t.length:F(t)}identityFor(t){let n=this.entryIdentities.get(t);return n||(n=`memfs:${this.nextEntryIdentity++}`,this.entryIdentities.set(t,n)),n}constructor(t,n={}){if(this.maxTotalBytes=n.maxTotalBytes??1024*1024*1024,!Number.isSafeInteger(this.maxTotalBytes)||this.maxTotalBytes<0)throw new Error("InMemoryFs: invalid maxTotalBytes");if(this.data.set("/",{type:"directory",mode:493,mtime:new Date}),t)for(let[r,s]of Object.entries(t))typeof s=="function"?this.writeFileLazy(r,s):Mf(s)?this.writeFileSync(r,s.content,void 0,{mode:s.mode,mtime:s.mtime}):this.writeFileSync(r,s)}ensureParentDirs(t){let n=ft(t);n!=="/"&&(this.data.has(n)||(this.ensureParentDirs(n),this.data.set(n,{type:"directory",mode:493,mtime:new Date})))}writeFileSync(t,n,r,s){Q(t,"write");let i=z(t);this.ensureParentDirs(i);let o=Wt(r);this.assertCanAllocate(i,this.contentByteLength(n,o));let a=Cn(n,o);this.setEntry(i,{type:"file",content:a,mode:s?.mode??420,mtime:s?.mtime??new Date})}writeFileLazy(t,n,r){Q(t,"write");let s=z(t);this.ensureParentDirs(s),this.setEntry(s,{type:"file",lazy:n,mode:r?.mode??420,mtime:r?.mtime??new Date})}async materializeLazy(t,n){let r=await _e.runTrustedAsync(async()=>n.lazy()),s=typeof r=="string"?cn.encode(r):r,i={type:"file",content:s,mode:n.mode,mtime:n.mtime};return this.assertCanAllocate(t,s.byteLength),this.setEntry(t,i),i}async readFile(t,n){let r=await this.readFileBuffer(t),s=Wt(n);return Nn(r,s)}async readFileBytes(t){let n=await this.readFileBuffer(t);return Nn(n,"binary")}async readFileBuffer(t){Q(t,"open");let n=this.resolvePathWithSymlinks(t),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, open '${t}'`);if(r.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);if("lazy"in r){let s=await this.materializeLazy(n,r);return s.content instanceof Uint8Array?s.content:cn.encode(s.content)}return r.content instanceof Uint8Array?r.content:cn.encode(r.content)}async writeFile(t,n,r){this.writeFileSync(t,n,r)}async appendFile(t,n,r){Q(t,"append");let s=z(t),i=this.data.get(s);if(i&&i.type==="directory")throw new Error(`EISDIR: illegal operation on a directory, write '${t}'`);let o=Wt(r),a=this.contentByteLength(n,o);if(i?.type==="file"){let l=i;"lazy"in l&&(l=await this.materializeLazy(s,l));let u="content"in l&&l.content instanceof Uint8Array?l.content:cn.encode("content"in l?l.content:"");this.assertCanAllocate(s,u.byteLength+a);let c=Cn(n,o),f=new Uint8Array(u.length+c.length);f.set(u),f.set(c,u.length),this.setEntry(s,{type:"file",content:f,mode:l.mode,mtime:new Date})}else this.writeFileSync(t,n,r)}async exists(t){if(t.includes("\0"))return!1;try{let n=this.resolvePathWithSymlinks(t);return this.data.has(n)}catch{return!1}}async stat(t){Q(t,"stat");let n=this.resolvePathWithSymlinks(t),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);r.type==="file"&&"lazy"in r&&(r=await this.materializeLazy(n,r));let s=0;return r.type==="file"&&"content"in r&&r.content&&(r.content instanceof Uint8Array?s=r.content.length:s=cn.encode(r.content).length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:s,mtime:r.mtime||new Date,identity:this.identityFor(r)}}async lstat(t){Q(t,"lstat");let n=this.resolveIntermediateSymlinks(t),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);if(r.type==="symlink")return{isFile:!1,isDirectory:!1,isSymbolicLink:!0,mode:r.mode,size:r.target.length,mtime:r.mtime||new Date};r.type==="file"&&"lazy"in r&&(r=await this.materializeLazy(n,r));let s=0;return r.type==="file"&&"content"in r&&r.content&&(r.content instanceof Uint8Array?s=r.content.length:s=cn.encode(r.content).length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:s,mtime:r.mtime||new Date,identity:this.identityFor(r)}}resolveIntermediateSymlinks(t){let n=z(t);if(n==="/")return"/";let r=n.slice(1).split("/");if(r.length<=1)return n;let s="",i=new Set;for(let o=0;o<r.length-1;o++){let a=r[o];s=`${s}/${a}`;let l=this.data.get(s),u=0,c=40;for(;l&&l.type==="symlink"&&u<c;){if(i.has(s))throw new Error(`ELOOP: too many levels of symbolic links, lstat '${t}'`);i.add(s),s=Pn(s,l.target),l=this.data.get(s),u++}if(u>=c)throw new Error(`ELOOP: too many levels of symbolic links, lstat '${t}'`)}return`${s}/${r[r.length-1]}`}resolvePathWithSymlinks(t){let n=z(t);if(n==="/")return"/";let r=n.slice(1).split("/"),s="",i=new Set;for(let o of r){s=`${s}/${o}`;let a=this.data.get(s),l=0,u=40;for(;a&&a.type==="symlink"&&l<u;){if(i.has(s))throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`);i.add(s),s=Pn(s,a.target),a=this.data.get(s),l++}if(l>=u)throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`)}return s}async mkdir(t,n){this.mkdirSync(t,n)}async createExclusive(t,n){let r=n.directory?"mkdir":"open";Q(t,n.directory?"mkdir":"write");let s=z(t),i=ft(s),o=i==="/"?"/":this.resolvePathWithSymlinks(i),a=nt(o,s.slice(s.lastIndexOf("/")+1));if(this.data.has(a))throw new Error(`EEXIST: file already exists, ${r} '${t}'`);if(o!=="/"){let l=this.data.get(o);if(!l)throw new Error(`ENOENT: no such file or directory, ${r} '${t}'`);if(l.type!=="directory")throw new Error(`ENOTDIR: not a directory, ${r} '${t}'`)}if(n.directory){this.setEntry(a,{type:"directory",mode:n.mode,mtime:new Date});return}this.assertCanAllocate(a,0),this.setEntry(a,{type:"file",content:new Uint8Array(0),mode:n.mode,mtime:new Date})}mkdirSync(t,n){Q(t,"mkdir");let r=z(t);if(this.data.has(r)){if(this.data.get(r)?.type==="file")throw new Error(`EEXIST: file already exists, mkdir '${t}'`);if(!n?.recursive)throw new Error(`EEXIST: directory already exists, mkdir '${t}'`);return}let s=ft(r);if(s!=="/"&&!this.data.has(s))if(n?.recursive)this.mkdirSync(s,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${t}'`);this.data.set(r,{type:"directory",mode:493,mtime:new Date})}async readdir(t){return(await this.readdirWithFileTypes(t)).map(r=>r.name)}async readdirWithFileTypes(t){Q(t,"scandir");let n=z(t),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);let s=new Set;for(;r&&r.type==="symlink";){if(s.has(n))throw new Error(`ELOOP: too many levels of symbolic links, scandir '${t}'`);s.add(n),n=Pn(n,r.target),r=this.data.get(n)}if(!r)throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);if(r.type!=="directory")throw new Error(`ENOTDIR: not a directory, scandir '${t}'`);let i=n==="/"?"/":`${n}/`,o=new Map;for(let[a,l]of this.data.entries())if(a!==n&&a.startsWith(i)){let u=a.slice(i.length),c=u.split("/")[0];c&&!u.includes("/",c.length)&&!o.has(c)&&o.set(c,{name:c,isFile:l.type==="file",isDirectory:l.type==="directory",isSymbolicLink:l.type==="symlink"})}return Array.from(o.values()).sort((a,l)=>a.name<l.name?-1:a.name>l.name?1:0)}async rm(t,n){Q(t,"rm");let r=z(t),s=this.data.get(r);if(!s){if(n?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${t}'`)}if(s.type==="directory"){let i=await this.readdir(r);if(i.length>0){if(!n?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${t}'`);for(let o of i){let a=nt(r,o);await this.rm(a,n)}}}this.deleteEntry(r)}async cp(t,n,r){Q(t,"cp"),Q(n,"cp");let s=z(t),i=z(n),o=this.data.get(s);if(!o)throw new Error(`ENOENT: no such file or directory, cp '${t}'`);if(o.type==="file")if(this.ensureParentDirs(i),"content"in o){let a=o.content instanceof Uint8Array?o.content.byteLength:cn.encode(o.content).byteLength;this.assertCanAllocate(i,a);let l=o.content instanceof Uint8Array?new Uint8Array(o.content):o.content;this.setEntry(i,{...o,content:l})}else this.setEntry(i,{...o});else if(o.type==="symlink")this.ensureParentDirs(i),this.data.set(i,{...o});else if(o.type==="directory"){if(!r?.recursive)throw new Error(`EISDIR: is a directory, cp '${t}'`);if(Dt(s,i))throw new Error(`EINVAL: cannot copy '${t}' into itself, '${n}'`);await this.mkdir(i,{recursive:!0});let a=await this.readdir(s);for(let l of a){let u=nt(s,l),c=nt(i,l);await this.cp(u,c,r)}}}async mv(t,n){Q(t,"mv"),Q(n,"mv");let r=z(t),s=z(n);if(r===s)return;let i=this.data.get(r);if(!i)throw new Error(`ENOENT: no such file or directory, mv '${t}'`);if(i.type==="directory"&&Dt(r,s))throw new Error(`EINVAL: cannot move '${t}' into itself, '${n}'`);if(i.type==="directory"){await this.mkdir(s,{recursive:!0});let o=await this.readdir(r);for(let a of o)await this.mv(nt(r,a),nt(s,a));this.deleteEntry(r);return}this.ensureParentDirs(s),this.setEntry(s,i),this.deleteEntry(r)}getAllPaths(){return Array.from(this.data.keys())}resolvePath(t,n){return kn(t,n)}async chmod(t,n){Q(t,"chmod");let r=z(t),s=this.data.get(r);if(!s)throw new Error(`ENOENT: no such file or directory, chmod '${t}'`);s.mode=n}async symlink(t,n){Q(n,"symlink");let r=z(n);if(this.data.has(r))throw new Error(`EEXIST: file already exists, symlink '${n}'`);this.ensureParentDirs(r),this.data.set(r,{type:"symlink",target:t,mode:511,mtime:new Date})}async link(t,n){Q(t,"link"),Q(n,"link");let r=z(t),s=z(n),i=this.data.get(r);if(!i)throw new Error(`ENOENT: no such file or directory, link '${t}'`);if(i.type!=="file")throw new Error(`EPERM: operation not permitted, link '${t}'`);if(this.data.has(s))throw new Error(`EEXIST: file already exists, link '${n}'`);let o=i;"lazy"in o&&(o=await this.materializeLazy(r,o)),this.ensureParentDirs(s);let a={type:"file",content:o.content,mode:o.mode,mtime:o.mtime};this.entryIdentities.set(a,this.identityFor(o)),this.setEntry(s,a)}async readlink(t){Q(t,"readlink");let n=z(t),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);if(r.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);return r.target}async realpath(t){Q(t,"realpath");let n=this.resolvePathWithSymlinks(t);if(!this.data.has(n))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);return n}async utimes(t,n,r){Q(t,"utimes");let s=z(t),i=this.resolvePathWithSymlinks(s),o=this.data.get(i);if(!o)throw new Error(`ENOENT: no such file or directory, utimes '${t}'`);o.mtime=r}};var Pa="5.1.0(1)-release",Ca="Linux version 5.15.0-generic (just-bash) #1 SMP PREEMPT";function Gs(e){let{pid:t,ppid:n,uid:r,gid:s}=e;return`Name: bash
8
+ `))}remainingTimeMs(){return Math.max(0,this.limits.maxExecutionTimeMs-(Date.now()-this.startedAt))}registerCleanup(t){this.assertUsable(),this.cleanupCallbacks.push(t);let n=!0;return()=>{if(!n)return;n=!1;let r=this.cleanupCallbacks.indexOf(t);r>=0&&this.cleanupCallbacks.splice(r,1)}}async close(){if(this.closed)return;this.closed=!0;let t=[],n=Date.now()+this.limits.maxExtensionCleanupTimeMs;for(let r=this.cleanupCallbacks.length-1;r>=0;r--)try{let s=n-Date.now();if(s<=0){t.push(new Error("execution cleanup grace period exceeded"));break}let i,o=await Promise.race([Promise.resolve().then(this.cleanupCallbacks[r]).then(()=>({ok:!0}),a=>({ok:!1,error:a})),new Promise(a=>{i=Xn(()=>a({ok:!1,error:new Error("execution cleanup grace period exceeded")}),s)})]);if(Yn(i),!o.ok&&(t.push(o.error),Date.now()>=n))break}catch(s){t.push(s)}if(this.cleanupCallbacks.length=0,this.depthByKind.clear(),this.bytesByKind.clear(),this.liveBytes=0,t.length>0)throw new AggregateError(t,"execution cleanup failed")}assertExecDepth(t){this.assertUsable(),t>this.limits.maxExecDepth&&this.fail(new C(`maximum nested execution depth (${this.limits.maxExecDepth}) exceeded`,"recursion"))}};function Ca(e){let t=Object.create(null);return Object.defineProperties(t,{remainingLiveBytes:{enumerable:!0,get:()=>e.remainingLiveBytes},consumeWork:{enumerable:!0,value:e.consumeWork.bind(e)},consumeLimited:{enumerable:!0,value:e.consumeLimited.bind(e)},consumeInput:{enumerable:!0,value:e.consumeInput.bind(e)},reserveBytes:{enumerable:!0,value:e.reserveBytes.bind(e)},enterDepth:{enumerable:!0,value:e.enterDepth.bind(e)},throwIfAborted:{enumerable:!0,value:e.throwIfAborted.bind(e)},remainingTimeMs:{enumerable:!0,value:e.remainingTimeMs.bind(e)},registerCleanup:{enumerable:!0,value:e.registerCleanup.bind(e)}}),Object.freeze(t)}function Na(e,t,n="pipeline"){e.relinquishOutput(t,n,Pa)}var cn=new TextEncoder;function Uf(e){return typeof e=="object"&&e!==null&&!(e instanceof Uint8Array)&&"content"in e}var bt=class{data=new Map;entryIdentities=new WeakMap;nextEntryIdentity=1;maxTotalBytes;retainedBytes=0;contentReferences=new WeakMap;materializedContent(t){return t?.type==="file"&&"content"in t?t.content:null}storedByteLength(t){return t===null?0:t instanceof Uint8Array?t.byteLength:W(t)}wouldReleaseBytes(t){let n=this.materializedContent(t);return n===null?0:n instanceof Uint8Array?this.contentReferences.get(n)===1?n.byteLength:0:this.storedByteLength(n)}assertCanAllocate(t,n){let r=this.wouldReleaseBytes(this.data.get(t));if(!Number.isSafeInteger(n)||n<0||n>this.maxTotalBytes-this.retainedBytes+r)throw new Error(`ENOSPC: in-memory filesystem byte limit exceeded (${this.maxTotalBytes} bytes)`)}setEntry(t,n){let r=this.data.get(t),s=this.materializedContent(r),i=this.materializedContent(n);if(s===i){this.data.set(t,n);return}let o=this.wouldReleaseBytes(r),a=i instanceof Uint8Array?this.contentReferences.has(i)?0:i.byteLength:this.storedByteLength(i);if(a>this.maxTotalBytes-this.retainedBytes+o)throw new Error(`ENOSPC: in-memory filesystem byte limit exceeded (${this.maxTotalBytes} bytes)`);if(s instanceof Uint8Array){let l=this.contentReferences.get(s)??0;l<=1?this.contentReferences.delete(s):this.contentReferences.set(s,l-1)}i instanceof Uint8Array&&this.contentReferences.set(i,(this.contentReferences.get(i)??0)+1),this.retainedBytes+=a-o,this.data.set(t,n)}deleteEntry(t){let n=this.data.get(t);if(!n)return!1;let r=this.materializedContent(n),s=this.wouldReleaseBytes(n);if(r instanceof Uint8Array){let i=this.contentReferences.get(r)??0;i<=1?this.contentReferences.delete(r):this.contentReferences.set(r,i-1)}return this.retainedBytes-=s,this.data.delete(t)}contentByteLength(t,n){if(t instanceof Uint8Array)return t.byteLength;if(n==="hex")return Math.floor(t.length/2);if(n==="base64"){let r=t.endsWith("==")?2:t.endsWith("=")?1:0;return Math.max(0,Math.floor(t.length*3/4)-r)}return n==="binary"||n==="latin1"?t.length:W(t)}identityFor(t){let n=this.entryIdentities.get(t);return n||(n=`memfs:${this.nextEntryIdentity++}`,this.entryIdentities.set(t,n)),n}constructor(t,n={}){if(this.maxTotalBytes=n.maxTotalBytes??1024*1024*1024,!Number.isSafeInteger(this.maxTotalBytes)||this.maxTotalBytes<0)throw new Error("InMemoryFs: invalid maxTotalBytes");if(this.data.set("/",{type:"directory",mode:493,mtime:new Date}),t)for(let[r,s]of Object.entries(t))typeof s=="function"?this.writeFileLazy(r,s):Uf(s)?this.writeFileSync(r,s.content,void 0,{mode:s.mode,mtime:s.mtime}):this.writeFileSync(r,s)}ensureParentDirs(t){let n=ct(t);n!=="/"&&(this.data.has(n)||(this.ensureParentDirs(n),this.data.set(n,{type:"directory",mode:493,mtime:new Date})))}writeFileSync(t,n,r,s){Q(t,"write");let i=q(t);this.ensureParentDirs(i);let o=Wt(r);this.assertCanAllocate(i,this.contentByteLength(n,o));let a=Nn(n,o);this.setEntry(i,{type:"file",content:a,mode:s?.mode??420,mtime:s?.mtime??new Date})}writeFileLazy(t,n,r){Q(t,"write");let s=q(t);this.ensureParentDirs(s),this.setEntry(s,{type:"file",lazy:n,mode:r?.mode??420,mtime:r?.mtime??new Date})}async materializeLazy(t,n){let r=await _e.runTrustedAsync(async()=>n.lazy()),s=typeof r=="string"?cn.encode(r):r,i={type:"file",content:s,mode:n.mode,mtime:n.mtime};return this.assertCanAllocate(t,s.byteLength),this.setEntry(t,i),i}async readFile(t,n){let r=await this.readFileBuffer(t),s=Wt(n);return Rn(r,s)}async readFileBytes(t){let n=await this.readFileBuffer(t);return Rn(n,"binary")}async readFileBuffer(t){Q(t,"open");let n=this.resolvePathWithSymlinks(t),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, open '${t}'`);if(r.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);if("lazy"in r){let s=await this.materializeLazy(n,r);return s.content instanceof Uint8Array?s.content:cn.encode(s.content)}return r.content instanceof Uint8Array?r.content:cn.encode(r.content)}async writeFile(t,n,r){this.writeFileSync(t,n,r)}async appendFile(t,n,r){Q(t,"append");let s=q(t),i=this.data.get(s);if(i&&i.type==="directory")throw new Error(`EISDIR: illegal operation on a directory, write '${t}'`);let o=Wt(r),a=this.contentByteLength(n,o);if(i?.type==="file"){let l=i;"lazy"in l&&(l=await this.materializeLazy(s,l));let u="content"in l&&l.content instanceof Uint8Array?l.content:cn.encode("content"in l?l.content:"");this.assertCanAllocate(s,u.byteLength+a);let c=Nn(n,o),f=new Uint8Array(u.length+c.length);f.set(u),f.set(c,u.length),this.setEntry(s,{type:"file",content:f,mode:l.mode,mtime:new Date})}else this.writeFileSync(t,n,r)}async exists(t){if(t.includes("\0"))return!1;try{let n=this.resolvePathWithSymlinks(t);return this.data.has(n)}catch{return!1}}async stat(t){Q(t,"stat");let n=this.resolvePathWithSymlinks(t),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);r.type==="file"&&"lazy"in r&&(r=await this.materializeLazy(n,r));let s=0;return r.type==="file"&&"content"in r&&r.content&&(r.content instanceof Uint8Array?s=r.content.length:s=cn.encode(r.content).length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:s,mtime:r.mtime||new Date,identity:this.identityFor(r)}}async lstat(t){Q(t,"lstat");let n=this.resolveIntermediateSymlinks(t),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);if(r.type==="symlink")return{isFile:!1,isDirectory:!1,isSymbolicLink:!0,mode:r.mode,size:r.target.length,mtime:r.mtime||new Date};r.type==="file"&&"lazy"in r&&(r=await this.materializeLazy(n,r));let s=0;return r.type==="file"&&"content"in r&&r.content&&(r.content instanceof Uint8Array?s=r.content.length:s=cn.encode(r.content).length),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:s,mtime:r.mtime||new Date,identity:this.identityFor(r)}}resolveIntermediateSymlinks(t){let n=q(t);if(n==="/")return"/";let r=n.slice(1).split("/");if(r.length<=1)return n;let s="",i=new Set;for(let o=0;o<r.length-1;o++){let a=r[o];s=`${s}/${a}`;let l=this.data.get(s),u=0,c=40;for(;l&&l.type==="symlink"&&u<c;){if(i.has(s))throw new Error(`ELOOP: too many levels of symbolic links, lstat '${t}'`);i.add(s),s=Cn(s,l.target),l=this.data.get(s),u++}if(u>=c)throw new Error(`ELOOP: too many levels of symbolic links, lstat '${t}'`)}return`${s}/${r[r.length-1]}`}resolvePathWithSymlinks(t){let n=q(t);if(n==="/")return"/";let r=n.slice(1).split("/"),s="",i=new Set;for(let o of r){s=`${s}/${o}`;let a=this.data.get(s),l=0,u=40;for(;a&&a.type==="symlink"&&l<u;){if(i.has(s))throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`);i.add(s),s=Cn(s,a.target),a=this.data.get(s),l++}if(l>=u)throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`)}return s}async mkdir(t,n){this.mkdirSync(t,n)}async createExclusive(t,n){let r=n.directory?"mkdir":"open";Q(t,n.directory?"mkdir":"write");let s=q(t),i=ct(s),o=i==="/"?"/":this.resolvePathWithSymlinks(i),a=tt(o,s.slice(s.lastIndexOf("/")+1));if(this.data.has(a))throw new Error(`EEXIST: file already exists, ${r} '${t}'`);if(o!=="/"){let l=this.data.get(o);if(!l)throw new Error(`ENOENT: no such file or directory, ${r} '${t}'`);if(l.type!=="directory")throw new Error(`ENOTDIR: not a directory, ${r} '${t}'`)}if(n.directory){this.setEntry(a,{type:"directory",mode:n.mode,mtime:new Date});return}this.assertCanAllocate(a,0),this.setEntry(a,{type:"file",content:new Uint8Array(0),mode:n.mode,mtime:new Date})}mkdirSync(t,n){Q(t,"mkdir");let r=q(t);if(this.data.has(r)){if(this.data.get(r)?.type==="file")throw new Error(`EEXIST: file already exists, mkdir '${t}'`);if(!n?.recursive)throw new Error(`EEXIST: directory already exists, mkdir '${t}'`);return}let s=ct(r);if(s!=="/"&&!this.data.has(s))if(n?.recursive)this.mkdirSync(s,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${t}'`);this.data.set(r,{type:"directory",mode:493,mtime:new Date})}async readdir(t){return(await this.readdirWithFileTypes(t)).map(r=>r.name)}async readdirWithFileTypes(t){Q(t,"scandir");let n=q(t),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);let s=new Set;for(;r&&r.type==="symlink";){if(s.has(n))throw new Error(`ELOOP: too many levels of symbolic links, scandir '${t}'`);s.add(n),n=Cn(n,r.target),r=this.data.get(n)}if(!r)throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);if(r.type!=="directory")throw new Error(`ENOTDIR: not a directory, scandir '${t}'`);let i=n==="/"?"/":`${n}/`,o=new Map;for(let[a,l]of this.data.entries())if(a!==n&&a.startsWith(i)){let u=a.slice(i.length),c=u.split("/")[0];c&&!u.includes("/",c.length)&&!o.has(c)&&o.set(c,{name:c,isFile:l.type==="file",isDirectory:l.type==="directory",isSymbolicLink:l.type==="symlink"})}return Array.from(o.values()).sort((a,l)=>a.name<l.name?-1:a.name>l.name?1:0)}async rm(t,n){Q(t,"rm");let r=q(t),s=this.data.get(r);if(!s){if(n?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${t}'`)}if(s.type==="directory"){let i=await this.readdir(r);if(i.length>0){if(!n?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${t}'`);for(let o of i){let a=tt(r,o);await this.rm(a,n)}}}this.deleteEntry(r)}async cp(t,n,r){Q(t,"cp"),Q(n,"cp");let s=q(t),i=q(n),o=this.data.get(s);if(!o)throw new Error(`ENOENT: no such file or directory, cp '${t}'`);if(o.type==="file")if(this.ensureParentDirs(i),"content"in o){let a=o.content instanceof Uint8Array?o.content.byteLength:cn.encode(o.content).byteLength;this.assertCanAllocate(i,a);let l=o.content instanceof Uint8Array?new Uint8Array(o.content):o.content;this.setEntry(i,{...o,content:l})}else this.setEntry(i,{...o});else if(o.type==="symlink")this.ensureParentDirs(i),this.data.set(i,{...o});else if(o.type==="directory"){if(!r?.recursive)throw new Error(`EISDIR: is a directory, cp '${t}'`);if(Dt(s,i))throw new Error(`EINVAL: cannot copy '${t}' into itself, '${n}'`);await this.mkdir(i,{recursive:!0});let a=await this.readdir(s);for(let l of a){let u=tt(s,l),c=tt(i,l);await this.cp(u,c,r)}}}async mv(t,n){Q(t,"mv"),Q(n,"mv");let r=q(t),s=q(n);if(r===s)return;let i=this.data.get(r);if(!i)throw new Error(`ENOENT: no such file or directory, mv '${t}'`);if(i.type==="directory"&&Dt(r,s))throw new Error(`EINVAL: cannot move '${t}' into itself, '${n}'`);if(i.type==="directory"){await this.mkdir(s,{recursive:!0});let o=await this.readdir(r);for(let a of o)await this.mv(tt(r,a),tt(s,a));this.deleteEntry(r);return}this.ensureParentDirs(s),this.setEntry(s,i),this.deleteEntry(r)}getAllPaths(){return Array.from(this.data.keys())}resolvePath(t,n){return Pn(t,n)}async chmod(t,n){Q(t,"chmod");let r=q(t),s=this.data.get(r);if(!s)throw new Error(`ENOENT: no such file or directory, chmod '${t}'`);s.mode=n}async symlink(t,n){Q(n,"symlink");let r=q(n);if(this.data.has(r))throw new Error(`EEXIST: file already exists, symlink '${n}'`);this.ensureParentDirs(r),this.data.set(r,{type:"symlink",target:t,mode:511,mtime:new Date})}async link(t,n){Q(t,"link"),Q(n,"link");let r=q(t),s=q(n),i=this.data.get(r);if(!i)throw new Error(`ENOENT: no such file or directory, link '${t}'`);if(i.type!=="file")throw new Error(`EPERM: operation not permitted, link '${t}'`);if(this.data.has(s))throw new Error(`EEXIST: file already exists, link '${n}'`);let o=i;"lazy"in o&&(o=await this.materializeLazy(r,o)),this.ensureParentDirs(s);let a={type:"file",content:o.content,mode:o.mode,mtime:o.mtime};this.entryIdentities.set(a,this.identityFor(o)),this.setEntry(s,a)}async readlink(t){Q(t,"readlink");let n=q(t),r=this.data.get(n);if(!r)throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);if(r.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);return r.target}async realpath(t){Q(t,"realpath");let n=this.resolvePathWithSymlinks(t);if(!this.data.has(n))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);return n}async utimes(t,n,r){Q(t,"utimes");let s=q(t),i=this.resolvePathWithSymlinks(s),o=this.data.get(i);if(!o)throw new Error(`ENOENT: no such file or directory, utimes '${t}'`);o.mtime=r}};var Da="5.1.0(1)-release",Ia="Linux version 5.15.0-generic (just-bash) #1 SMP PREEMPT";function Ks(e){let{pid:t,ppid:n,uid:r,gid:s}=e;return`Name: bash
9
9
  State: R (running)
10
10
  Pid: ${t}
11
11
  PPid: ${n}
12
12
  Uid: ${r} ${r} ${r} ${r}
13
13
  Gid: ${s} ${s} ${s} ${s}
14
- `}function Bf(e){let t=e;return typeof t.mkdirSync=="function"&&typeof t.writeFileSync=="function"}function Wf(e,t){e.mkdirSync("/bin",{recursive:!0}),e.mkdirSync("/usr/bin",{recursive:!0}),t&&(e.mkdirSync("/home/user",{recursive:!0}),e.mkdirSync("/tmp",{recursive:!0}))}function Vf(e){e.mkdirSync("/dev",{recursive:!0}),e.mkdirSync("/dev/fd",{recursive:!0}),e.writeFileSync("/dev/null",""),e.writeFileSync("/dev/zero",new Uint8Array(0)),e.writeFileSync("/dev/stdin",""),e.writeFileSync("/dev/stdout",""),e.writeFileSync("/dev/stderr","")}function zf(e,t){e.mkdirSync("/proc/self/fd",{recursive:!0}),e.writeFileSync("/proc/version",`${Ca}
14
+ `}function jf(e){let t=e;return typeof t.mkdirSync=="function"&&typeof t.writeFileSync=="function"}function Gf(e,t){e.mkdirSync("/bin",{recursive:!0}),e.mkdirSync("/usr/bin",{recursive:!0}),t&&(e.mkdirSync("/home/user",{recursive:!0}),e.mkdirSync("/tmp",{recursive:!0}))}function Hf(e){e.mkdirSync("/dev",{recursive:!0}),e.mkdirSync("/dev/fd",{recursive:!0}),e.writeFileSync("/dev/null",""),e.writeFileSync("/dev/zero",new Uint8Array(0)),e.writeFileSync("/dev/stdin",""),e.writeFileSync("/dev/stdout",""),e.writeFileSync("/dev/stderr","")}function Zf(e,t){e.mkdirSync("/proc/self/fd",{recursive:!0}),e.writeFileSync("/proc/version",`${Ia}
15
15
  `),e.writeFileSync("/proc/self/exe","/bin/bash"),e.writeFileSync("/proc/self/cmdline","bash\0"),e.writeFileSync("/proc/self/comm",`bash
16
- `),e.writeFileLazy?e.writeFileLazy("/proc/self/status",()=>Gs(t)):e.writeFileSync("/proc/self/status",Gs(t)),e.writeFileSync("/proc/self/fd/0","/dev/stdin"),e.writeFileSync("/proc/self/fd/1","/dev/stdout"),e.writeFileSync("/proc/self/fd/2","/dev/stderr")}function Na(e,t,n={pid:1,ppid:0,uid:1e3,gid:1e3}){if(Bf(e)){let r=qf(e);Wf(r,t),Vf(r),zf(r,n)}}function qf(e){let t=r=>{try{r()}catch(s){if(!(s instanceof Error&&s.message.startsWith("ENOSYS")))throw s}},n={mkdirSync:(r,s)=>t(()=>e.mkdirSync(r,s)),writeFileSync:(r,s)=>t(()=>e.writeFileSync(r,s))};return e.writeFileLazy&&(n.writeFileLazy=(r,s)=>t(()=>e.writeFileLazy?.(r,s))),n}var fn=class{baseFs;mounts=new Map;constructor(t){if(this.baseFs=t?.base??new bt,t?.mounts)for(let{mountPoint:n,filesystem:r}of t.mounts)this.mount(n,r)}mount(t,n){this.validateMountPath(t);let r=z(t);this.validateMount(r),this.mounts.set(r,n)}unmount(t){let n=z(t);if(!this.mounts.has(n))throw new Error(`No filesystem mounted at '${t}'`);this.mounts.delete(n)}getMounts(){return Array.from(this.mounts,([t,n])=>({mountPoint:t,filesystem:n}))}isMountPoint(t){let n=z(t);return this.mounts.has(n)}validateMountPath(t){let n=t.split("/");for(let r of n)if(r==="."||r==="..")throw new Error(`Invalid mount point '${t}': contains '.' or '..' segments`)}validateMount(t){if(t==="/")throw new Error("Cannot mount at root '/'");for(let n of this.mounts.keys())if(n!==t){if(t.startsWith(`${n}/`))throw new Error(`Cannot mount at '${t}': inside existing mount '${n}'`);if(n.startsWith(`${t}/`))throw new Error(`Cannot mount at '${t}': would contain existing mount '${n}'`)}}routePath(t){Q(t,"access");let n=z(t);for(let[r,s]of this.mounts){if(n===r)return{fs:s,relativePath:"/"};if(n.startsWith(`${r}/`))return{fs:s,relativePath:n.slice(r.length)}}return{fs:this.baseFs,relativePath:n}}getChildMountPoints(t){let n=z(t),r=n==="/"?"/":`${n}/`,s=[];for(let i of this.mounts.keys())if(i.startsWith(r)){let a=i.slice(r.length).split("/")[0];a&&!s.includes(a)&&s.push(a)}return s}async readFile(t,n){let{fs:r,relativePath:s}=this.routePath(t);return r.readFile(s,n)}async readFileBytes(t){let{fs:n,relativePath:r}=this.routePath(t);return vn(n,r)}async readFileBuffer(t){let{fs:n,relativePath:r}=this.routePath(t);return n.readFileBuffer(r)}async writeFile(t,n,r){let{fs:s,relativePath:i}=this.routePath(t);return s.writeFile(i,n,r)}async appendFile(t,n,r){let{fs:s,relativePath:i}=this.routePath(t);return s.appendFile(i,n,r)}async exists(t){let n=z(t);if(this.mounts.has(n)||this.getChildMountPoints(n).length>0)return!0;let{fs:s,relativePath:i}=this.routePath(t);return s.exists(i)}async stat(t){let n=z(t),r=this.mounts.get(n);if(r)try{return await r.stat("/")}catch{return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode:493,size:0,mtime:new Date}}if(this.getChildMountPoints(n).length>0)try{return await this.baseFs.stat(n)}catch{return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode:493,size:0,mtime:new Date}}let{fs:i,relativePath:o}=this.routePath(t);return i.stat(o)}async lstat(t){let n=z(t),r=this.mounts.get(n);if(r)try{return await r.lstat("/")}catch{return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode:493,size:0,mtime:new Date}}if(this.getChildMountPoints(n).length>0)try{return await this.baseFs.lstat(n)}catch{return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode:493,size:0,mtime:new Date}}let{fs:i,relativePath:o}=this.routePath(t);return i.lstat(o)}async mkdir(t,n){let r=z(t);if(this.mounts.has(r)){if(n?.recursive)return;throw new Error(`EEXIST: directory already exists, mkdir '${t}'`)}if(this.getChildMountPoints(r).length>0&&n?.recursive)return;let{fs:i,relativePath:o}=this.routePath(t);return i.mkdir(o,n)}async createExclusive(t,n){let r=z(t),s=n.directory?"mkdir":"open";if(this.mounts.has(r))throw new Error(`EEXIST: file already exists, ${s} '${t}'`);let{fs:i,relativePath:o}=this.routePath(t);if(!i.createExclusive)throw new la(t,s);let a=ft(o);return a!=="/"&&this.getChildMountPoints(ft(r)).length>0&&!await i.exists(a)&&await i.mkdir(a,{recursive:!0}),i.createExclusive(o,n)}mkdirSync(t,n){let{fs:r,relativePath:s}=this.routePath(t),i=r;if(!i.mkdirSync)throw new Error(`ENOSYS: function not implemented, mkdir '${t}'`);i.mkdirSync(s,n)}writeFileSync(t,n){let{fs:r,relativePath:s}=this.routePath(t),i=r;if(!i.writeFileSync)throw new Error(`ENOSYS: function not implemented, write '${t}'`);i.writeFileSync(s,n)}async readdir(t){let n=z(t),r=new Set,s=null,{fs:i,relativePath:o}=this.routePath(t);try{let l=await i.readdir(o);for(let u of l)r.add(u)}catch(l){let u=l.code,c=l.message||"";if(u!=="ENOENT"&&!c.includes("ENOENT"))throw l;s=l}let a=this.getChildMountPoints(n);for(let l of a)r.add(l);if(r.size===0&&s&&!this.mounts.has(n))throw s;return Array.from(r).sort()}async rm(t,n){let r=z(t);if(this.mounts.has(r))throw new Error(`EBUSY: mount point, cannot remove '${t}'`);if(this.getChildMountPoints(r).length>0)throw new Error(`EBUSY: contains mount points, cannot remove '${t}'`);let{fs:i,relativePath:o}=this.routePath(t);return i.rm(o,n)}async cp(t,n,r){if((await this.stat(t)).isDirectory&&Dt(t,n))throw new Error(`EINVAL: cannot copy '${t}' into itself, '${n}'`);let i=this.routePath(t),o=this.routePath(n);return i.fs===o.fs?i.fs.cp(i.relativePath,o.relativePath,r):this.crossMountCopy(t,n,r)}async mv(t,n){let r=z(t);if((await this.stat(t)).isDirectory&&Dt(t,n))throw new Error(`EINVAL: cannot move '${t}' into itself, '${n}'`);if(this.mounts.has(r))throw new Error(`EBUSY: mount point, cannot move '${t}'`);let i=this.routePath(t),o=this.routePath(n);if(i.fs===o.fs)return i.fs.mv(i.relativePath,o.relativePath);await this.cp(t,n,{recursive:!0}),await this.rm(t,{recursive:!0})}resolvePath(t,n){return kn(t,n)}getAllPaths(){let t=new Set;for(let n of this.baseFs.getAllPaths())t.add(n);for(let[n,r]of this.mounts){let s=n.split("/").filter(Boolean),i="";for(let o of s)i=`${i}/${o}`,t.add(i);for(let o of r.getAllPaths())o==="/"?t.add(n):t.add(`${n}${o}`)}return Array.from(t).sort()}async chmod(t,n){let r=z(t),s=this.mounts.get(r);if(s)return s.chmod("/",n);let{fs:i,relativePath:o}=this.routePath(t);return i.chmod(o,n)}async symlink(t,n){let{fs:r,relativePath:s}=this.routePath(n);return r.symlink(t,s)}async link(t,n){let r=this.routePath(t),s=this.routePath(n);if(r.fs!==s.fs)throw new Error(`EXDEV: cross-device link not permitted, link '${t}' -> '${n}'`);return r.fs.link(r.relativePath,s.relativePath)}async readlink(t){let{fs:n,relativePath:r}=this.routePath(t);return n.readlink(r)}async realpath(t){let n=z(t);if(this.mounts.has(n))return n;let{fs:r,relativePath:s}=this.routePath(t),i=await r.realpath(s);for(let o of this.mounts.keys())if(n===o||n.startsWith(`${o}/`))return i==="/"?o:`${o}${i}`;return i}async crossMountCopy(t,n,r){let s=await this.lstat(t);if(s.isFile){let i=await this.readFileBuffer(t);await this.writeFile(n,i),await this.chmod(n,s.mode)}else if(s.isDirectory){if(!r?.recursive)throw new Error(`cp: ${t} is a directory (not copied)`);await this.mkdir(n,{recursive:!0});let i=await this.readdir(t);for(let o of i){let a=nt(t,o),l=nt(n,o);await this.crossMountCopy(a,l,r)}}else if(s.isSymbolicLink){let i=await this.readlink(t);await this.symlink(i,n)}}async utimes(t,n,r){let{fs:s,relativePath:i}=this.routePath(t);return s.utimes(i,n,r)}};function Le(e){return{kind:e.kind,elements:new Map(e.elements)}}function rt(e){return new Map(Array.from(e??[],([t,n])=>[t,Le(n)]))}function ve(e,t){return e.state.arrays?.get(t)}function er(e,t,n="indexed"){e.state.arrays??=new Map;let r=e.state.arrays.get(t);return r||(r={kind:n,elements:new Map},e.state.arrays.set(t,r)),r}function Vt(e,t,n){let r=er(e,t,n);return r.kind=n,r}function ke(e,t){return e.state.arrays?.has(t)??!1}function ie(e,t,n){return ve(e,t)?.elements.get(String(n))}function zt(e,t,n){return ve(e,t)?.elements.has(String(n))??!1}function U(e,t,n,r,s){let i=er(e,t,s),o=String(n);if(!i.elements.has(o)&&i.elements.size>=e.limits.maxArrayElements)throw new P(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");if(F(r)>e.limits.maxStringLength)throw new P(`array value string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");i.elements.set(o,r)}function dn(e,t,n,r=!1){let s=new Set(r?[]:ve(e,t)?.elements.keys()??[]);for(let i of n)if(s.add(String(i)),s.size>e.limits.maxArrayElements)throw new P(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements")}function pn(e,t,n){return ve(e,t)?.elements.delete(String(n))??!1}function tr(e,t){e.state.arrays?.delete(t),e.state.associativeArrays?.delete(t)}function be(e,t){return Array.from(ve(e,t)?.elements.keys()??[]).filter(r=>/^(0|[1-9]\d*)$/.test(r)).map(Number).sort((r,s)=>r-s)}function ye(e,t){er(e,t,e.state.associativeArrays?.has(t)?"associative":"indexed").elements.clear()}function St(e,t){return Array.from(ve(e,t)?.elements.keys()??[]).sort()}function Ir(e){return e.startsWith("'")&&e.endsWith("'")||e.startsWith('"')&&e.endsWith('"')?e.slice(1,-1):e}function Hs(e){if(e.parts.length<2)return null;let t=e.parts[0],n=e.parts[1];if(t.type!=="Glob"||!t.pattern.startsWith("["))return null;let r,s=n,i=1;if(n.type==="Literal"&&n.value.startsWith("]")){let f=n.value.slice(1);if(f.startsWith("+=")||f.startsWith("="))r=t.pattern.slice(1);else if(f===""){if(e.parts.length<3)return null;let d=e.parts[2];if(d.type!=="Literal"||!d.value.startsWith("=")&&!d.value.startsWith("+="))return null;r=t.pattern.slice(1),s=d,i=2}else return null}else if(t.pattern==="["&&(n.type==="DoubleQuoted"||n.type==="SingleQuoted")){if(e.parts.length<3)return null;let f=e.parts[2];if(f.type!=="Literal"||!f.value.startsWith("]=")&&!f.value.startsWith("]+="))return null;if(n.type==="SingleQuoted")r=n.value;else{r="";for(let d of n.parts)(d.type==="Literal"||d.type==="Escaped")&&(r+=d.value)}s=f,i=2}else if(t.pattern.endsWith("]")){if(n.type!=="Literal"||!n.value.startsWith("=")&&!n.value.startsWith("+="))return null;r=t.pattern.slice(1,-1)}else return null;r=Ir(r);let o;if(s.type!=="Literal")return null;s.value.startsWith("]=")||s.value.startsWith("]+=")?o=s.value.slice(1):o=s.value;let a=o.startsWith("+=");if(!a&&!o.startsWith("="))return null;let l=[],u=a?2:1,c=o.slice(u);c&&l.push({type:"Literal",value:c});for(let f=i+1;f<e.parts.length;f++){let d=e.parts[f];d.type==="BraceExpansion"?l.push({type:"Literal",value:Uf(d)}):l.push(d)}return{key:r,valueParts:l,append:a}}function Uf(e){return`{${e.items.map(n=>{if(n.type==="Range"){let r=n.startStr??String(n.start),s=n.endStr??String(n.end),i=`${r}..${s}`;return n.step&&(i+=`..${n.step}`),i}return In(n.word)}).join(",")}}`}function In(e){let t="";for(let n of e.parts)switch(n.type){case"Literal":t+=n.value;break;case"Glob":t+=n.pattern;break;case"SingleQuoted":t+=n.value;break;case"DoubleQuoted":for(let r of n.parts)(r.type==="Literal"||r.type==="Escaped")&&(t+=r.value);break;case"Escaped":t+=n.value;break;case"BraceExpansion":t+="{",t+=n.items.map(r=>r.type==="Range"?`${r.startStr}..${r.endStr}${r.step?`..${r.step}`:""}`:In(r.word)).join(","),t+="}";break;case"TildeExpansion":t+="~",n.user&&(t+=n.user);break}return t}var jf=["allexport","errexit","noglob","noclobber","noexec","nounset","pipefail","posix","verbose","xtrace"],Gf=["braceexpand","hashall","interactive-comments"];function Zs(e){let t=[],n=[...Gf.map(r=>({name:r,enabled:!0})),...jf.map(r=>({name:r,enabled:e[r]}))].sort((r,s)=>r.name.localeCompare(s.name));for(let r of n)r.enabled&&t.push(r.name);return t.join(":")}function On(e){e.state.env.set("SHELLOPTS",Zs(e.state.options))}var Hf=["dotglob","expand_aliases","extglob","failglob","globskipdots","globstar","lastpipe","nocaseglob","nocasematch","nullglob","xpg_echo"];function Qs(e){let t=[];for(let n of Hf)e[n]&&t.push(n);return t.join(":")}function Ks(e){e.state.env.set("BASHOPTS",Qs(e.state.shoptOptions))}var T={script(e){return{type:"Script",statements:e}},statement(e,t=[],n=!1,r,s){let i={type:"Statement",pipelines:e,operators:t,background:n};return r&&(i.deferredError=r),s!==void 0&&(i.sourceText=s),i},pipeline(e,t=!1,n=!1,r=!1,s){return{type:"Pipeline",commands:e,negated:t,timed:n,timePosix:r,pipeStderr:s}},simpleCommand(e,t=[],n=[],r=[]){return{type:"SimpleCommand",name:e,args:t,assignments:n,redirections:r}},word(e){return{type:"Word",parts:e}},literal(e){return{type:"Literal",value:e}},singleQuoted(e){return{type:"SingleQuoted",value:e}},doubleQuoted(e){return{type:"DoubleQuoted",parts:e}},escaped(e){return{type:"Escaped",value:e}},parameterExpansion(e,t=null){return{type:"ParameterExpansion",parameter:e,operation:t}},commandSubstitution(e,t=!1){return{type:"CommandSubstitution",body:e,legacy:t}},arithmeticExpansion(e){return{type:"ArithmeticExpansion",expression:e}},processSubstitution(e,t){return{type:"ProcessSubstitution",body:e,direction:t}},assignment(e,t,n=!1,r=null){return{type:"Assignment",name:e,value:t,append:n,array:r}},redirection(e,t,n=null,r){let s={type:"Redirection",fd:n,operator:e,target:t};return r&&(s.fdVariable=r),s},hereDoc(e,t,n=!1,r=!1,s){let i={type:"HereDoc",delimiter:e,content:t,stripTabs:n,quoted:r};return s!==void 0&&(i.terminated=s),i},ifNode(e,t=null,n=[]){return{type:"If",clauses:e,elseBody:t,redirections:n}},forNode(e,t,n,r=[]){return{type:"For",variable:e,words:t,body:n,redirections:r}},whileNode(e,t,n=[]){return{type:"While",condition:e,body:t,redirections:n}},untilNode(e,t,n=[]){return{type:"Until",condition:e,body:t,redirections:n}},caseNode(e,t,n=[]){return{type:"Case",word:e,items:t,redirections:n}},caseItem(e,t,n=";;"){return{type:"CaseItem",patterns:e,body:t,terminator:n}},subshell(e,t=[]){return{type:"Subshell",body:e,redirections:t}},group(e,t=[]){return{type:"Group",body:e,redirections:t}},functionDef(e,t,n=[],r){return{type:"FunctionDef",name:e,body:t,redirections:n,sourceFile:r}},conditionalCommand(e,t=[],n){return{type:"ConditionalCommand",expression:e,redirections:t,line:n}},arithmeticCommand(e,t=[],n){return{type:"ArithmeticCommand",expression:e,redirections:t,line:n}}};function Ra(e,t){let n=e.length,r=t+3,s=2,i=!1,o=!1;for(;r<n&&s>0;){let a=e[r];if(i){a==="'"&&(i=!1),r++;continue}if(o){if(a==="\\"){r+=2;continue}a==='"'&&(o=!1),r++;continue}if(a==="'"){i=!0,r++;continue}if(a==='"'){o=!0,r++;continue}if(a==="\\"){r+=2;continue}if(a==="("){s++,r++;continue}if(a===")"){if(s--,s===1){let l=r+1;return!(l<n&&e[l]===")")}if(s===0)return!1;r++;continue}if(s===1&&(a==="|"&&r+1<n&&e[r+1]==="|"||a==="&"&&r+1<n&&e[r+1]==="&"||a==="|"&&r+1<n&&e[r+1]!=="|"))return!0;r++}return!1}function Or(e,t){let n="",r=t,s=0,i=!1,o,a=l=>l===" "||l===" "||l===`
16
+ `),e.writeFileLazy?e.writeFileLazy("/proc/self/status",()=>Ks(t)):e.writeFileSync("/proc/self/status",Ks(t)),e.writeFileSync("/proc/self/fd/0","/dev/stdin"),e.writeFileSync("/proc/self/fd/1","/dev/stdout"),e.writeFileSync("/proc/self/fd/2","/dev/stderr")}function Oa(e,t,n={pid:1,ppid:0,uid:1e3,gid:1e3}){if(jf(e)){let r=Qf(e);Gf(r,t),Hf(r),Zf(r,n)}}function Qf(e){let t=r=>{try{r()}catch(s){if(!(s instanceof Error&&s.message.startsWith("ENOSYS")))throw s}},n={mkdirSync:(r,s)=>t(()=>e.mkdirSync(r,s)),writeFileSync:(r,s)=>t(()=>e.writeFileSync(r,s))};return e.writeFileLazy&&(n.writeFileLazy=(r,s)=>t(()=>e.writeFileLazy?.(r,s))),n}var fn=class{baseFs;mounts=new Map;constructor(t){if(this.baseFs=t?.base??new bt,t?.mounts)for(let{mountPoint:n,filesystem:r}of t.mounts)this.mount(n,r)}mount(t,n){this.validateMountPath(t);let r=q(t);this.validateMount(r),this.mounts.set(r,n)}unmount(t){let n=q(t);if(!this.mounts.has(n))throw new Error(`No filesystem mounted at '${t}'`);this.mounts.delete(n)}getMounts(){return Array.from(this.mounts,([t,n])=>({mountPoint:t,filesystem:n}))}isMountPoint(t){let n=q(t);return this.mounts.has(n)}validateMountPath(t){let n=t.split("/");for(let r of n)if(r==="."||r==="..")throw new Error(`Invalid mount point '${t}': contains '.' or '..' segments`)}validateMount(t){if(t==="/")throw new Error("Cannot mount at root '/'");for(let n of this.mounts.keys())if(n!==t){if(t.startsWith(`${n}/`))throw new Error(`Cannot mount at '${t}': inside existing mount '${n}'`);if(n.startsWith(`${t}/`))throw new Error(`Cannot mount at '${t}': would contain existing mount '${n}'`)}}routePath(t){Q(t,"access");let n=q(t);for(let[r,s]of this.mounts){if(n===r)return{fs:s,relativePath:"/"};if(n.startsWith(`${r}/`))return{fs:s,relativePath:n.slice(r.length)}}return{fs:this.baseFs,relativePath:n}}getChildMountPoints(t){let n=q(t),r=n==="/"?"/":`${n}/`,s=[];for(let i of this.mounts.keys())if(i.startsWith(r)){let a=i.slice(r.length).split("/")[0];a&&!s.includes(a)&&s.push(a)}return s}async readFile(t,n){let{fs:r,relativePath:s}=this.routePath(t);return r.readFile(s,n)}async readFileBytes(t){let{fs:n,relativePath:r}=this.routePath(t);return xn(n,r)}async readFileBuffer(t){let{fs:n,relativePath:r}=this.routePath(t);return n.readFileBuffer(r)}async writeFile(t,n,r){let{fs:s,relativePath:i}=this.routePath(t);return s.writeFile(i,n,r)}async appendFile(t,n,r){let{fs:s,relativePath:i}=this.routePath(t);return s.appendFile(i,n,r)}async exists(t){let n=q(t);if(this.mounts.has(n)||this.getChildMountPoints(n).length>0)return!0;let{fs:s,relativePath:i}=this.routePath(t);return s.exists(i)}async stat(t){let n=q(t),r=this.mounts.get(n);if(r)try{return await r.stat("/")}catch{return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode:493,size:0,mtime:new Date}}if(this.getChildMountPoints(n).length>0)try{return await this.baseFs.stat(n)}catch{return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode:493,size:0,mtime:new Date}}let{fs:i,relativePath:o}=this.routePath(t);return i.stat(o)}async lstat(t){let n=q(t),r=this.mounts.get(n);if(r)try{return await r.lstat("/")}catch{return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode:493,size:0,mtime:new Date}}if(this.getChildMountPoints(n).length>0)try{return await this.baseFs.lstat(n)}catch{return{isFile:!1,isDirectory:!0,isSymbolicLink:!1,mode:493,size:0,mtime:new Date}}let{fs:i,relativePath:o}=this.routePath(t);return i.lstat(o)}async mkdir(t,n){let r=q(t);if(this.mounts.has(r)){if(n?.recursive)return;throw new Error(`EEXIST: directory already exists, mkdir '${t}'`)}if(this.getChildMountPoints(r).length>0&&n?.recursive)return;let{fs:i,relativePath:o}=this.routePath(t);return i.mkdir(o,n)}async createExclusive(t,n){let r=q(t),s=n.directory?"mkdir":"open";if(this.mounts.has(r))throw new Error(`EEXIST: file already exists, ${s} '${t}'`);let{fs:i,relativePath:o}=this.routePath(t);if(!i.createExclusive)throw new da(t,s);let a=ct(o);return a!=="/"&&this.getChildMountPoints(ct(r)).length>0&&!await i.exists(a)&&await i.mkdir(a,{recursive:!0}),i.createExclusive(o,n)}mkdirSync(t,n){let{fs:r,relativePath:s}=this.routePath(t),i=r;if(!i.mkdirSync)throw new Error(`ENOSYS: function not implemented, mkdir '${t}'`);i.mkdirSync(s,n)}writeFileSync(t,n){let{fs:r,relativePath:s}=this.routePath(t),i=r;if(!i.writeFileSync)throw new Error(`ENOSYS: function not implemented, write '${t}'`);i.writeFileSync(s,n)}async readdir(t){let n=q(t),r=new Set,s=null,{fs:i,relativePath:o}=this.routePath(t);try{let l=await i.readdir(o);for(let u of l)r.add(u)}catch(l){let u=l.code,c=l.message||"";if(u!=="ENOENT"&&!c.includes("ENOENT"))throw l;s=l}let a=this.getChildMountPoints(n);for(let l of a)r.add(l);if(r.size===0&&s&&!this.mounts.has(n))throw s;return Array.from(r).sort()}async rm(t,n){let r=q(t);if(this.mounts.has(r))throw new Error(`EBUSY: mount point, cannot remove '${t}'`);if(this.getChildMountPoints(r).length>0)throw new Error(`EBUSY: contains mount points, cannot remove '${t}'`);let{fs:i,relativePath:o}=this.routePath(t);return i.rm(o,n)}async cp(t,n,r){if((await this.stat(t)).isDirectory&&Dt(t,n))throw new Error(`EINVAL: cannot copy '${t}' into itself, '${n}'`);let i=this.routePath(t),o=this.routePath(n);return i.fs===o.fs?i.fs.cp(i.relativePath,o.relativePath,r):this.crossMountCopy(t,n,r)}async mv(t,n){let r=q(t);if((await this.stat(t)).isDirectory&&Dt(t,n))throw new Error(`EINVAL: cannot move '${t}' into itself, '${n}'`);if(this.mounts.has(r))throw new Error(`EBUSY: mount point, cannot move '${t}'`);let i=this.routePath(t),o=this.routePath(n);if(i.fs===o.fs)return i.fs.mv(i.relativePath,o.relativePath);await this.cp(t,n,{recursive:!0}),await this.rm(t,{recursive:!0})}resolvePath(t,n){return Pn(t,n)}getAllPaths(){let t=new Set;for(let n of this.baseFs.getAllPaths())t.add(n);for(let[n,r]of this.mounts){let s=n.split("/").filter(Boolean),i="";for(let o of s)i=`${i}/${o}`,t.add(i);for(let o of r.getAllPaths())o==="/"?t.add(n):t.add(`${n}${o}`)}return Array.from(t).sort()}async chmod(t,n){let r=q(t),s=this.mounts.get(r);if(s)return s.chmod("/",n);let{fs:i,relativePath:o}=this.routePath(t);return i.chmod(o,n)}async symlink(t,n){let{fs:r,relativePath:s}=this.routePath(n);return r.symlink(t,s)}async link(t,n){let r=this.routePath(t),s=this.routePath(n);if(r.fs!==s.fs)throw new Error(`EXDEV: cross-device link not permitted, link '${t}' -> '${n}'`);return r.fs.link(r.relativePath,s.relativePath)}async readlink(t){let{fs:n,relativePath:r}=this.routePath(t);return n.readlink(r)}async realpath(t){let n=q(t);if(this.mounts.has(n))return n;let{fs:r,relativePath:s}=this.routePath(t),i=await r.realpath(s);for(let o of this.mounts.keys())if(n===o||n.startsWith(`${o}/`))return i==="/"?o:`${o}${i}`;return i}async crossMountCopy(t,n,r){let s=await this.lstat(t);if(s.isFile){let i=await this.readFileBuffer(t);await this.writeFile(n,i),await this.chmod(n,s.mode)}else if(s.isDirectory){if(!r?.recursive)throw new Error(`cp: ${t} is a directory (not copied)`);await this.mkdir(n,{recursive:!0});let i=await this.readdir(t);for(let o of i){let a=tt(t,o),l=tt(n,o);await this.crossMountCopy(a,l,r)}}else if(s.isSymbolicLink){let i=await this.readlink(t);await this.symlink(i,n)}}async utimes(t,n,r){let{fs:s,relativePath:i}=this.routePath(t);return s.utimes(i,n,r)}};function Le(e){return{kind:e.kind,elements:new Map(e.elements)}}function nt(e){return new Map(Array.from(e??[],([t,n])=>[t,Le(n)]))}function Ae(e,t){return e.state.arrays?.get(t)}function tr(e,t,n="indexed"){e.state.arrays??=new Map;let r=e.state.arrays.get(t);return r||(r={kind:n,elements:new Map},e.state.arrays.set(t,r)),r}function Vt(e,t,n){let r=tr(e,t,n);return r.kind=n,r}function ke(e,t){return e.state.arrays?.has(t)??!1}function ie(e,t,n){return Ae(e,t)?.elements.get(String(n))}function zt(e,t,n){return Ae(e,t)?.elements.has(String(n))??!1}function j(e,t,n,r,s){let i=tr(e,t,s),o=String(n);if(!i.elements.has(o)&&i.elements.size>=e.limits.maxArrayElements)throw new C(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");if(W(r)>e.limits.maxStringLength)throw new C(`array value string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");i.elements.set(o,r)}function dn(e,t,n,r=!1){let s=new Set(r?[]:Ae(e,t)?.elements.keys()??[]);for(let i of n)if(s.add(String(i)),s.size>e.limits.maxArrayElements)throw new C(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements")}function pn(e,t,n){return Ae(e,t)?.elements.delete(String(n))??!1}function nr(e,t){e.state.arrays?.delete(t),e.state.associativeArrays?.delete(t)}function Ee(e,t){return Array.from(Ae(e,t)?.elements.keys()??[]).filter(r=>/^(0|[1-9]\d*)$/.test(r)).map(Number).sort((r,s)=>r-s)}function ye(e,t){tr(e,t,e.state.associativeArrays?.has(t)?"associative":"indexed").elements.clear()}function St(e,t){return Array.from(Ae(e,t)?.elements.keys()??[]).sort()}function _r(e){return e.startsWith("'")&&e.endsWith("'")||e.startsWith('"')&&e.endsWith('"')?e.slice(1,-1):e}function Xs(e){if(e.parts.length<2)return null;let t=e.parts[0],n=e.parts[1];if(t.type!=="Glob"||!t.pattern.startsWith("["))return null;let r,s=n,i=1;if(n.type==="Literal"&&n.value.startsWith("]")){let f=n.value.slice(1);if(f.startsWith("+=")||f.startsWith("="))r=t.pattern.slice(1);else if(f===""){if(e.parts.length<3)return null;let d=e.parts[2];if(d.type!=="Literal"||!d.value.startsWith("=")&&!d.value.startsWith("+="))return null;r=t.pattern.slice(1),s=d,i=2}else return null}else if(t.pattern==="["&&(n.type==="DoubleQuoted"||n.type==="SingleQuoted")){if(e.parts.length<3)return null;let f=e.parts[2];if(f.type!=="Literal"||!f.value.startsWith("]=")&&!f.value.startsWith("]+="))return null;if(n.type==="SingleQuoted")r=n.value;else{r="";for(let d of n.parts)(d.type==="Literal"||d.type==="Escaped")&&(r+=d.value)}s=f,i=2}else if(t.pattern.endsWith("]")){if(n.type!=="Literal"||!n.value.startsWith("=")&&!n.value.startsWith("+="))return null;r=t.pattern.slice(1,-1)}else return null;r=_r(r);let o;if(s.type!=="Literal")return null;s.value.startsWith("]=")||s.value.startsWith("]+=")?o=s.value.slice(1):o=s.value;let a=o.startsWith("+=");if(!a&&!o.startsWith("="))return null;let l=[],u=a?2:1,c=o.slice(u);c&&l.push({type:"Literal",value:c});for(let f=i+1;f<e.parts.length;f++){let d=e.parts[f];d.type==="BraceExpansion"?l.push({type:"Literal",value:Kf(d)}):l.push(d)}return{key:r,valueParts:l,append:a}}function Kf(e){return`{${e.items.map(n=>{if(n.type==="Range"){let r=n.startStr??String(n.start),s=n.endStr??String(n.end),i=`${r}..${s}`;return n.step&&(i+=`..${n.step}`),i}return On(n.word)}).join(",")}}`}function On(e){let t="";for(let n of e.parts)switch(n.type){case"Literal":t+=n.value;break;case"Glob":t+=n.pattern;break;case"SingleQuoted":t+=n.value;break;case"DoubleQuoted":for(let r of n.parts)(r.type==="Literal"||r.type==="Escaped")&&(t+=r.value);break;case"Escaped":t+=n.value;break;case"BraceExpansion":t+="{",t+=n.items.map(r=>r.type==="Range"?`${r.startStr}..${r.endStr}${r.step?`..${r.step}`:""}`:On(r.word)).join(","),t+="}";break;case"TildeExpansion":t+="~",n.user&&(t+=n.user);break}return t}var Xf=["allexport","errexit","noglob","noclobber","noexec","nounset","pipefail","posix","verbose","xtrace"],Yf=["braceexpand","hashall","interactive-comments"];function Lr(e){let t=[],n=[...Yf.map(r=>({name:r,enabled:!0})),...Xf.map(r=>({name:r,enabled:e[r]}))].sort((r,s)=>r.name.localeCompare(s.name));for(let r of n)r.enabled&&t.push(r.name);return t.join(":")}function _n(e){e.state.env.set("SHELLOPTS",Lr(e.state.options))}var Jf=["dotglob","expand_aliases","extglob","failglob","globskipdots","globstar","lastpipe","nocaseglob","nocasematch","nullglob","xpg_echo"];function Tr(e){let t=[];for(let n of Jf)e[n]&&t.push(n);return t.join(":")}function Ys(e){e.state.env.set("BASHOPTS",Tr(e.state.shoptOptions))}var F={script(e){return{type:"Script",statements:e}},statement(e,t=[],n=!1,r,s){let i={type:"Statement",pipelines:e,operators:t,background:n};return r&&(i.deferredError=r),s!==void 0&&(i.sourceText=s),i},pipeline(e,t=!1,n=!1,r=!1,s){return{type:"Pipeline",commands:e,negated:t,timed:n,timePosix:r,pipeStderr:s}},simpleCommand(e,t=[],n=[],r=[]){return{type:"SimpleCommand",name:e,args:t,assignments:n,redirections:r}},word(e){return{type:"Word",parts:e}},literal(e){return{type:"Literal",value:e}},singleQuoted(e){return{type:"SingleQuoted",value:e}},doubleQuoted(e){return{type:"DoubleQuoted",parts:e}},escaped(e){return{type:"Escaped",value:e}},parameterExpansion(e,t=null){return{type:"ParameterExpansion",parameter:e,operation:t}},commandSubstitution(e,t=!1){return{type:"CommandSubstitution",body:e,legacy:t}},arithmeticExpansion(e){return{type:"ArithmeticExpansion",expression:e}},processSubstitution(e,t){return{type:"ProcessSubstitution",body:e,direction:t}},assignment(e,t,n=!1,r=null){return{type:"Assignment",name:e,value:t,append:n,array:r}},redirection(e,t,n=null,r){let s={type:"Redirection",fd:n,operator:e,target:t};return r&&(s.fdVariable=r),s},hereDoc(e,t,n=!1,r=!1,s){let i={type:"HereDoc",delimiter:e,content:t,stripTabs:n,quoted:r};return s!==void 0&&(i.terminated=s),i},ifNode(e,t=null,n=[]){return{type:"If",clauses:e,elseBody:t,redirections:n}},forNode(e,t,n,r=[]){return{type:"For",variable:e,words:t,body:n,redirections:r}},whileNode(e,t,n=[]){return{type:"While",condition:e,body:t,redirections:n}},untilNode(e,t,n=[]){return{type:"Until",condition:e,body:t,redirections:n}},caseNode(e,t,n=[]){return{type:"Case",word:e,items:t,redirections:n}},caseItem(e,t,n=";;"){return{type:"CaseItem",patterns:e,body:t,terminator:n}},subshell(e,t=[]){return{type:"Subshell",body:e,redirections:t}},group(e,t=[]){return{type:"Group",body:e,redirections:t}},functionDef(e,t,n=[],r){return{type:"FunctionDef",name:e,body:t,redirections:n,sourceFile:r}},conditionalCommand(e,t=[],n){return{type:"ConditionalCommand",expression:e,redirections:t,line:n}},arithmeticCommand(e,t=[],n){return{type:"ArithmeticCommand",expression:e,redirections:t,line:n}}};function _a(e,t){let n=e.length,r=t+3,s=2,i=!1,o=!1;for(;r<n&&s>0;){let a=e[r];if(i){a==="'"&&(i=!1),r++;continue}if(o){if(a==="\\"){r+=2;continue}a==='"'&&(o=!1),r++;continue}if(a==="'"){i=!0,r++;continue}if(a==='"'){o=!0,r++;continue}if(a==="\\"){r+=2;continue}if(a==="("){s++,r++;continue}if(a===")"){if(s--,s===1){let l=r+1;return!(l<n&&e[l]===")")}if(s===0)return!1;r++;continue}if(s===1&&(a==="|"&&r+1<n&&e[r+1]==="|"||a==="&"&&r+1<n&&e[r+1]==="&"||a==="|"&&r+1<n&&e[r+1]!=="|"))return!0;r++}return!1}function Fr(e,t){let n="",r=t,s=0,i=!1,o,a=l=>l===" "||l===" "||l===`
17
17
  `||l===";"||l==="&"||l==="|"||l==="<"||l===">"||l==="("||l===")";for(;r<e.length;){let l=e[r];if(l==="'"){let u=s>0;for(u||(i=!0),u&&(n+=l),r++;r<e.length&&e[r]!=="'";)n+=e[r],r++;r<e.length?(u&&(n+=e[r]),r++):o=l;continue}if(l==='"'){let u=s>0;for(u||(i=!0),u&&(n+=l),r++;r<e.length&&e[r]!=='"';){if(e[r]==="\\"&&r+1<e.length){if(u){n+=e.slice(r,r+2),r+=2;continue}let c=e[r+1];if(c==="$"||c==="`"||c==='"'||c==="\\"||c===`
18
18
  `){r+=2,c!==`
19
19
  `&&(n+=c);continue}}n+=e[r],r++}r<e.length?(u&&(n+=e[r]),r++):o=l;continue}if(l==="\\"&&r+1<e.length){if(s>0){n+=e.slice(r,r+2),r+=2;continue}i=!0;let u=e[r+1];u!==`
20
- `&&(n+=u),r+=2;continue}if(s===0&&(l==="$"||l==="<"||l===">")&&e[r+1]==="("){n+=`${l}(`,s=1,r+=2;continue}if(s===0&&a(l))break;s>0&&(l==="("?s++:l===")"&&s--),n+=l,r++}return{delim:n,endPos:r,quoted:i,unclosedQuote:o,unclosedSubstitution:s>0}}function Zf(e,t,n){let r=t+1;for(let{delim:s,stripTabs:i}of n)for(;;){if(r>=e.length)return e.length;let o=e.indexOf(`
21
- `,r);o===-1&&(o=e.length);let a=e.slice(r,o);if(i&&(a=a.replace(/^\t+/,"")),a===s){r=o+1;break}if(o>=e.length)return e.length;r=o+1}return Math.min(r,e.length)}function Da(e,t,n){let r=1,s=t,i=!1,o=!1,a=0,l=!1,u="",c=[],f=0;for(;s<e.length&&r>0;){let d=e[s];if(i)d==="'"&&(i=!1);else if(o)d==="\\"&&s+1<e.length?s++:d==='"'&&(o=!1);else{if(d==="("&&e[s+1]==="("?f++:d===")"&&e[s+1]===")"&&f>0&&f--,f===0&&d==="<"&&e[s+1]==="<"&&e[s+2]!=="<"){let p=s+2,h=!1;for(e[p]==="-"&&(h=!0,p++);e[p]===" "||e[p]===" ";)p++;let{delim:m,endPos:E,unclosedQuote:S,unclosedSubstitution:y}=Or(e,p);if(S&&n(`unexpected EOF while looking for matching \`${S}'`),y&&n("unexpected EOF while looking for matching `)'"),m.length>0){c.push({delim:m,stripTabs:h}),u="",s=E;continue}}if(d===`
22
- `&&c.length>0){let p=Zf(e,s,c);c.length=0,u="",s=p;continue}d==="'"?(i=!0,u=""):d==='"'?(o=!0,u=""):d==="\\"&&s+1<e.length?(s++,u=""):/[a-zA-Z_]/.test(d)?u+=d:(u==="case"?(a++,l=!1):u==="in"&&a>0?l=!0:u==="esac"&&a>0&&(a--,l=!1),u="",d==="("?s>0&&e[s-1]==="$"?r++:l||r++:d===")"?l?l=!1:r--:d===";"&&a>0&&s+1<e.length&&e[s+1]===";"&&(l=!0))}r>0&&s++}return r>0&&n("unexpected EOF while looking for matching `)'"),s}function Ia(e,t,n,r){let s=t+2,i=Da(e,s,r),o=e.slice(s,i),l=n().parse(o);return{part:T.commandSubstitution(l,!1),endIndex:i+1}}function Oa(e,t,n,r){let s=e[t]==="<"?"input":"output",i=t+2,o=Da(e,i,r),a=n().parse(e.slice(i,o));return{part:T.processSubstitution(a,s),endIndex:o+1}}function _a(e,t,n,r,s){let o=t+1,a="";for(;o<e.length&&e[o]!=="`";)if(e[o]==="\\"){let c=e[o+1];c==="$"||c==="`"||c==="\\"||c===`
20
+ `&&(n+=u),r+=2;continue}if(s===0&&(l==="$"||l==="<"||l===">")&&e[r+1]==="("){n+=`${l}(`,s=1,r+=2;continue}if(s===0&&a(l))break;s>0&&(l==="("?s++:l===")"&&s--),n+=l,r++}return{delim:n,endPos:r,quoted:i,unclosedQuote:o,unclosedSubstitution:s>0}}function ed(e,t,n){let r=t+1;for(let{delim:s,stripTabs:i}of n)for(;;){if(r>=e.length)return e.length;let o=e.indexOf(`
21
+ `,r);o===-1&&(o=e.length);let a=e.slice(r,o);if(i&&(a=a.replace(/^\t+/,"")),a===s){r=o+1;break}if(o>=e.length)return e.length;r=o+1}return Math.min(r,e.length)}function La(e,t,n){let r=1,s=t,i=!1,o=!1,a=0,l=!1,u="",c=[],f=0;for(;s<e.length&&r>0;){let d=e[s];if(i)d==="'"&&(i=!1);else if(o)d==="\\"&&s+1<e.length?s++:d==='"'&&(o=!1);else{if(d==="("&&e[s+1]==="("?f++:d===")"&&e[s+1]===")"&&f>0&&f--,f===0&&d==="<"&&e[s+1]==="<"&&e[s+2]!=="<"){let p=s+2,h=!1;for(e[p]==="-"&&(h=!0,p++);e[p]===" "||e[p]===" ";)p++;let{delim:m,endPos:y,unclosedQuote:b,unclosedSubstitution:w}=Fr(e,p);if(b&&n(`unexpected EOF while looking for matching \`${b}'`),w&&n("unexpected EOF while looking for matching `)'"),m.length>0){c.push({delim:m,stripTabs:h}),u="",s=y;continue}}if(d===`
22
+ `&&c.length>0){let p=ed(e,s,c);c.length=0,u="",s=p;continue}d==="'"?(i=!0,u=""):d==='"'?(o=!0,u=""):d==="\\"&&s+1<e.length?(s++,u=""):/[a-zA-Z_]/.test(d)?u+=d:(u==="case"?(a++,l=!1):u==="in"&&a>0?l=!0:u==="esac"&&a>0&&(a--,l=!1),u="",d==="("?s>0&&e[s-1]==="$"?r++:l||r++:d===")"?l?l=!1:r--:d===";"&&a>0&&s+1<e.length&&e[s+1]===";"&&(l=!0))}r>0&&s++}return r>0&&n("unexpected EOF while looking for matching `)'"),s}function Ta(e,t,n,r){let s=t+2,i=La(e,s,r),o=e.slice(s,i),l=n().parse(o);return{part:F.commandSubstitution(l,!1),endIndex:i+1}}function Fa(e,t,n,r){let s=e[t]==="<"?"input":"output",i=t+2,o=La(e,i,r),a=n().parse(e.slice(i,o));return{part:F.processSubstitution(a,s),endIndex:o+1}}function Ma(e,t,n,r,s){let o=t+1,a="";for(;o<e.length&&e[o]!=="`";)if(e[o]==="\\"){let c=e[o+1];c==="$"||c==="`"||c==="\\"||c===`
23
23
  `||n&&c==='"'?(c!==`
24
- `&&(a+=c),o+=2):(a+=e[o],o++)}else a+=e[o],o++;o>=e.length&&s("unexpected EOF while looking for matching ``'");let u=r().parse(a);return{part:T.commandSubstitution(u,!0),endIndex:o+1}}var Qf=10485760,w;(function(e){e.EOF="EOF",e.NEWLINE="NEWLINE",e.SEMICOLON="SEMICOLON",e.AMP="AMP",e.PIPE="PIPE",e.PIPE_AMP="PIPE_AMP",e.AND_AND="AND_AND",e.OR_OR="OR_OR",e.BANG="BANG",e.LESS="LESS",e.GREAT="GREAT",e.DLESS="DLESS",e.DGREAT="DGREAT",e.LESSAND="LESSAND",e.GREATAND="GREATAND",e.LESSGREAT="LESSGREAT",e.DLESSDASH="DLESSDASH",e.CLOBBER="CLOBBER",e.TLESS="TLESS",e.AND_GREAT="AND_GREAT",e.AND_DGREAT="AND_DGREAT",e.LPAREN="LPAREN",e.RPAREN="RPAREN",e.LBRACE="LBRACE",e.RBRACE="RBRACE",e.DSEMI="DSEMI",e.SEMI_AND="SEMI_AND",e.SEMI_SEMI_AND="SEMI_SEMI_AND",e.DBRACK_START="DBRACK_START",e.DBRACK_END="DBRACK_END",e.DPAREN_START="DPAREN_START",e.DPAREN_END="DPAREN_END",e.IF="IF",e.THEN="THEN",e.ELSE="ELSE",e.ELIF="ELIF",e.FI="FI",e.FOR="FOR",e.WHILE="WHILE",e.UNTIL="UNTIL",e.DO="DO",e.DONE="DONE",e.CASE="CASE",e.ESAC="ESAC",e.IN="IN",e.FUNCTION="FUNCTION",e.SELECT="SELECT",e.TIME="TIME",e.COPROC="COPROC",e.WORD="WORD",e.NAME="NAME",e.NUMBER="NUMBER",e.ASSIGNMENT_WORD="ASSIGNMENT_WORD",e.FD_VARIABLE="FD_VARIABLE",e.COMMENT="COMMENT",e.HEREDOC_CONTENT="HEREDOC_CONTENT"})(w||(w={}));var Ke=class extends Error{line;column;constructor(t,n,r){super(`line ${n}: ${t}`),this.line=n,this.column=r,this.name="LexerError"}},Xs=new Map([["if",w.IF],["then",w.THEN],["else",w.ELSE],["elif",w.ELIF],["fi",w.FI],["for",w.FOR],["while",w.WHILE],["until",w.UNTIL],["do",w.DO],["done",w.DONE],["case",w.CASE],["esac",w.ESAC],["in",w.IN],["function",w.FUNCTION],["select",w.SELECT],["time",w.TIME],["coproc",w.COPROC]]),Kf=new Set(Xs.values());function Ys(e){return Kf.has(e)}function La(e){let t=e.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);if(!t)return!1;let n=e.slice(t[0].length);if(n===""||n==="+")return!0;if(n[0]==="["){let r=0,s=0;for(;s<n.length;s++)if(n[s]==="[")r++;else if(n[s]==="]"&&(r--,r===0))break;if(r!==0||s>=n.length)return!1;let i=n.slice(s+1);return i===""||i==="+"}return!1}function Ta(e){let t=0;for(let n=0;n<e.length;n++){let r=e[n];if(r==="[")t++;else if(r==="]")t--;else{if(t===0&&r==="=")return n;if(t===0&&r==="+"&&e[n+1]==="=")return n+1}}return-1}var Xf=[[";",";","&",w.SEMI_SEMI_AND],["<","<","<",w.TLESS],["&",">",">",w.AND_DGREAT]],Yf=[["[","[",w.DBRACK_START],["]","]",w.DBRACK_END],["(","(",w.DPAREN_START],[")",")",w.DPAREN_END],["&","&",w.AND_AND],["|","|",w.OR_OR],[";",";",w.DSEMI],[";","&",w.SEMI_AND],["|","&",w.PIPE_AMP],[">",">",w.DGREAT],["<","&",w.LESSAND],[">","&",w.GREATAND],["<",">",w.LESSGREAT],[">","|",w.CLOBBER],["&",">",w.AND_GREAT]],Jf=new Map([["|",w.PIPE],["&",w.AMP],[";",w.SEMICOLON],["(",w.LPAREN],[")",w.RPAREN],["<",w.LESS],[">",w.GREAT]]);function ed(e){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e)}function Fa(e){return e===" "||e===" "||e===`
25
- `||e===";"||e==="&"||e==="|"||e==="("||e===")"||e==="<"||e===">"}var _r=class{input;pos=0;line=1;column=1;tokens=[];pendingHeredocs=[];pendingHeredocDelimiterMode;dparenDepth=0;maxHeredocSize;constructor(t,n){this.input=t,this.maxHeredocSize=n?.maxHeredocSize??Qf}tokenize(){let n=this.input.length,r=this.tokens,s=this.pendingHeredocs;for(;this.pos<n;){if(s.length>0&&r.length>0&&r[r.length-1].type===w.NEWLINE){this.readHeredocContent();continue}if(this.skipWhitespace(),this.pos>=n)break;let i=this.nextToken();i&&r.push(i)}return s.length>0&&this.readHeredocContent(),r.push({type:w.EOF,value:"",start:this.pos,end:this.pos,line:this.line,column:this.column}),r}skipWhitespace(){let t=this.input,n=t.length,r=this.pos,s=this.column,i=this.line;for(;r<n;){let o=t[r];if(o===" "||o===" ")r++,s++;else if(o==="\\"&&t[r+1]===`
24
+ `&&(a+=c),o+=2):(a+=e[o],o++)}else a+=e[o],o++;o>=e.length&&s("unexpected EOF while looking for matching ``'");let u=r().parse(a);return{part:F.commandSubstitution(u,!0),endIndex:o+1}}var td=10485760,g;(function(e){e.EOF="EOF",e.NEWLINE="NEWLINE",e.SEMICOLON="SEMICOLON",e.AMP="AMP",e.PIPE="PIPE",e.PIPE_AMP="PIPE_AMP",e.AND_AND="AND_AND",e.OR_OR="OR_OR",e.BANG="BANG",e.LESS="LESS",e.GREAT="GREAT",e.DLESS="DLESS",e.DGREAT="DGREAT",e.LESSAND="LESSAND",e.GREATAND="GREATAND",e.LESSGREAT="LESSGREAT",e.DLESSDASH="DLESSDASH",e.CLOBBER="CLOBBER",e.TLESS="TLESS",e.AND_GREAT="AND_GREAT",e.AND_DGREAT="AND_DGREAT",e.LPAREN="LPAREN",e.RPAREN="RPAREN",e.LBRACE="LBRACE",e.RBRACE="RBRACE",e.DSEMI="DSEMI",e.SEMI_AND="SEMI_AND",e.SEMI_SEMI_AND="SEMI_SEMI_AND",e.DBRACK_START="DBRACK_START",e.DBRACK_END="DBRACK_END",e.DPAREN_START="DPAREN_START",e.DPAREN_END="DPAREN_END",e.IF="IF",e.THEN="THEN",e.ELSE="ELSE",e.ELIF="ELIF",e.FI="FI",e.FOR="FOR",e.WHILE="WHILE",e.UNTIL="UNTIL",e.DO="DO",e.DONE="DONE",e.CASE="CASE",e.ESAC="ESAC",e.IN="IN",e.FUNCTION="FUNCTION",e.SELECT="SELECT",e.TIME="TIME",e.COPROC="COPROC",e.WORD="WORD",e.NAME="NAME",e.NUMBER="NUMBER",e.ASSIGNMENT_WORD="ASSIGNMENT_WORD",e.FD_VARIABLE="FD_VARIABLE",e.COMMENT="COMMENT",e.HEREDOC_CONTENT="HEREDOC_CONTENT"})(g||(g={}));var Ke=class extends Error{line;column;constructor(t,n,r){super(`line ${n}: ${t}`),this.line=n,this.column=r,this.name="LexerError"}},Js=new Map([["if",g.IF],["then",g.THEN],["else",g.ELSE],["elif",g.ELIF],["fi",g.FI],["for",g.FOR],["while",g.WHILE],["until",g.UNTIL],["do",g.DO],["done",g.DONE],["case",g.CASE],["esac",g.ESAC],["in",g.IN],["function",g.FUNCTION],["select",g.SELECT],["time",g.TIME],["coproc",g.COPROC]]),nd=new Set(Js.values());function ei(e){return nd.has(e)}function Ba(e){let t=e.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);if(!t)return!1;let n=e.slice(t[0].length);if(n===""||n==="+")return!0;if(n[0]==="["){let r=0,s=0;for(;s<n.length;s++)if(n[s]==="[")r++;else if(n[s]==="]"&&(r--,r===0))break;if(r!==0||s>=n.length)return!1;let i=n.slice(s+1);return i===""||i==="+"}return!1}function Wa(e){let t=0;for(let n=0;n<e.length;n++){let r=e[n];if(r==="[")t++;else if(r==="]")t--;else{if(t===0&&r==="=")return n;if(t===0&&r==="+"&&e[n+1]==="=")return n+1}}return-1}var rd=[[";",";","&",g.SEMI_SEMI_AND],["<","<","<",g.TLESS],["&",">",">",g.AND_DGREAT]],sd=[["[","[",g.DBRACK_START],["]","]",g.DBRACK_END],["(","(",g.DPAREN_START],[")",")",g.DPAREN_END],["&","&",g.AND_AND],["|","|",g.OR_OR],[";",";",g.DSEMI],[";","&",g.SEMI_AND],["|","&",g.PIPE_AMP],[">",">",g.DGREAT],["<","&",g.LESSAND],[">","&",g.GREATAND],["<",">",g.LESSGREAT],[">","|",g.CLOBBER],["&",">",g.AND_GREAT]],id=new Map([["|",g.PIPE],["&",g.AMP],[";",g.SEMICOLON],["(",g.LPAREN],[")",g.RPAREN],["<",g.LESS],[">",g.GREAT]]);function od(e){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e)}function Va(e){return e===" "||e===" "||e===`
25
+ `||e===";"||e==="&"||e==="|"||e==="("||e===")"||e==="<"||e===">"}var Mr=class{input;pos=0;line=1;column=1;tokens=[];pendingHeredocs=[];pendingHeredocDelimiterMode;dparenDepth=0;maxHeredocSize;constructor(t,n){this.input=t,this.maxHeredocSize=n?.maxHeredocSize??td}tokenize(){let n=this.input.length,r=this.tokens,s=this.pendingHeredocs;for(;this.pos<n;){if(s.length>0&&r.length>0&&r[r.length-1].type===g.NEWLINE){this.readHeredocContent();continue}if(this.skipWhitespace(),this.pos>=n)break;let i=this.nextToken();i&&r.push(i)}return s.length>0&&this.readHeredocContent(),r.push({type:g.EOF,value:"",start:this.pos,end:this.pos,line:this.line,column:this.column}),r}skipWhitespace(){let t=this.input,n=t.length,r=this.pos,s=this.column,i=this.line;for(;r<n;){let o=t[r];if(o===" "||o===" ")r++,s++;else if(o==="\\"&&t[r+1]===`
26
26
  `)r+=2,i++,s=1;else break}this.pos=r,this.column=s,this.line=i}nextToken(){let t=this.input,n=this.pos,r=this.line,s=this.column,i=t[n],o=t[n+1],a=t[n+2],l=this.pendingHeredocDelimiterMode;if(this.pendingHeredocDelimiterMode=void 0,l!==void 0&&i!==`
27
27
  `&&!(i==="#"&&this.dparenDepth===0))return this.readHeredocDelimiterToken(n,r,s,l);if(i==="#"&&this.dparenDepth===0)return this.readComment(n,r,s);if(i===`
28
- `)return this.pos=n+1,this.line++,this.column=1,{type:w.NEWLINE,value:`
29
- `,start:n,end:n+1,line:r,column:s};if(i==="<"&&o==="<"&&a==="-")return this.pos=n+3,this.column=s+3,this.pendingHeredocDelimiterMode=!0,this.makeToken(w.DLESSDASH,"<<-",n,r,s);for(let[c,f,d,p]of Xf)if(i===c&&o===f&&a===d)return this.pos=n+3,this.column=s+3,this.makeToken(p,c+f+d,n,r,s);if(i==="<"&&o==="<")return this.pos=n+2,this.column=s+2,this.pendingHeredocDelimiterMode=!1,this.makeToken(w.DLESS,"<<",n,r,s);if(i==="("&&o==="("){let c=this.tokens[this.tokens.length-1];return this.dparenDepth===0&&c?.end===n&&(c.type===w.LESS||c.type===w.GREAT)?(this.pos=n+1,this.column=s+1,this.makeToken(w.LPAREN,"(",n,r,s)):this.dparenDepth>0?(this.pos=n+1,this.column=s+1,this.dparenDepth++,this.makeToken(w.LPAREN,"(",n,r,s)):this.looksLikeNestedSubshells(n+2)||this.dparenClosesWithSpacedParens(n+2)?(this.pos=n+1,this.column=s+1,this.makeToken(w.LPAREN,"(",n,r,s)):(this.pos=n+2,this.column=s+2,this.dparenDepth=1,this.makeToken(w.DPAREN_START,"((",n,r,s))}if(i===")"&&o===")")return this.dparenDepth===1?(this.pos=n+2,this.column=s+2,this.dparenDepth=0,this.makeToken(w.DPAREN_END,"))",n,r,s)):this.dparenDepth>1?(this.pos=n+1,this.column=s+1,this.dparenDepth--,this.makeToken(w.RPAREN,")",n,r,s)):(this.pos=n+1,this.column=s+1,this.makeToken(w.RPAREN,")",n,r,s));for(let[c,f,d]of Yf)if(!(c==="("&&f==="("||c===")"&&f===")")&&!(this.dparenDepth>0&&c===";"&&(d===w.DSEMI||d===w.SEMI_AND||d===w.SEMI_SEMI_AND))&&i===c&&o===f){if(d===w.DBRACK_START||d===w.DBRACK_END){let p=t[n+2];if(p!==void 0&&p!==" "&&p!==" "&&p!==`
30
- `&&p!==";"&&p!=="&"&&p!=="|"&&p!=="("&&p!==")"&&p!=="<"&&p!==">")break}return this.pos=n+2,this.column=s+2,this.makeToken(d,c+f,n,r,s)}if(i==="("&&this.dparenDepth>0)return this.pos=n+1,this.column=s+1,this.dparenDepth++,this.makeToken(w.LPAREN,"(",n,r,s);if(i===")"&&this.dparenDepth>1)return this.pos=n+1,this.column=s+1,this.dparenDepth--,this.makeToken(w.RPAREN,")",n,r,s);let u=Jf.get(i);if(u!==void 0)return this.pos=n+1,this.column=s+1,this.makeToken(u,i,n,r,s);if(i==="{"){let c=this.scanFdVariable(n);return c!==null?(this.pos=c.end,this.column=s+(c.end-n),{type:w.FD_VARIABLE,value:c.varname,start:n,end:c.end,line:r,column:s}):o==="}"?(this.pos=n+2,this.column=s+2,{type:w.WORD,value:"{}",start:n,end:n+2,line:r,column:s,quoted:!1,singleQuoted:!1}):this.scanBraceExpansion(n)!==null?this.readWordWithBraceExpansion(n,r,s):this.scanLiteralBraceWord(n)!==null?this.readWordWithBraceExpansion(n,r,s):o!==void 0&&o!==" "&&o!==" "&&o!==`
31
- `?this.readWord(n,r,s):(this.pos=n+1,this.column=s+1,this.makeToken(w.LBRACE,"{",n,r,s))}return i==="}"?this.isWordCharFollowing(n+1)?this.readWord(n,r,s):(this.pos=n+1,this.column=s+1,this.makeToken(w.RBRACE,"}",n,r,s)):i==="!"?o==="="?(this.pos=n+2,this.column=s+2,this.makeToken(w.WORD,"!=",n,r,s)):(this.pos=n+1,this.column=s+1,this.makeToken(w.BANG,"!",n,r,s)):this.readWord(n,r,s)}looksLikeNestedSubshells(t){let n=this.input,r=n.length,s=t;for(;s<r&&(n[s]===" "||n[s]===" ");)s++;if(s>=r)return!1;let i=n[s];if(i==="(")return this.looksLikeNestedSubshells(s+1);let o=/[a-zA-Z_]/.test(i),a=i==="!"||i==="[";if(!o&&!a)return!1;let l=s;for(;l<r&&/[a-zA-Z0-9_\-.]/.test(n[l]);)l++;if(l===s)return a;let u=l;for(;u<r&&(n[u]===" "||n[u]===" ");)u++;if(u>=r)return!1;let c=n[u];if(c==="="&&n[u+1]!=="="||c===`
28
+ `)return this.pos=n+1,this.line++,this.column=1,{type:g.NEWLINE,value:`
29
+ `,start:n,end:n+1,line:r,column:s};if(i==="<"&&o==="<"&&a==="-")return this.pos=n+3,this.column=s+3,this.pendingHeredocDelimiterMode=!0,this.makeToken(g.DLESSDASH,"<<-",n,r,s);for(let[c,f,d,p]of rd)if(i===c&&o===f&&a===d)return this.pos=n+3,this.column=s+3,this.makeToken(p,c+f+d,n,r,s);if(i==="<"&&o==="<")return this.pos=n+2,this.column=s+2,this.pendingHeredocDelimiterMode=!1,this.makeToken(g.DLESS,"<<",n,r,s);if(i==="("&&o==="("){let c=this.tokens[this.tokens.length-1];return this.dparenDepth===0&&c?.end===n&&(c.type===g.LESS||c.type===g.GREAT)?(this.pos=n+1,this.column=s+1,this.makeToken(g.LPAREN,"(",n,r,s)):this.dparenDepth>0?(this.pos=n+1,this.column=s+1,this.dparenDepth++,this.makeToken(g.LPAREN,"(",n,r,s)):this.looksLikeNestedSubshells(n+2)||this.dparenClosesWithSpacedParens(n+2)?(this.pos=n+1,this.column=s+1,this.makeToken(g.LPAREN,"(",n,r,s)):(this.pos=n+2,this.column=s+2,this.dparenDepth=1,this.makeToken(g.DPAREN_START,"((",n,r,s))}if(i===")"&&o===")")return this.dparenDepth===1?(this.pos=n+2,this.column=s+2,this.dparenDepth=0,this.makeToken(g.DPAREN_END,"))",n,r,s)):this.dparenDepth>1?(this.pos=n+1,this.column=s+1,this.dparenDepth--,this.makeToken(g.RPAREN,")",n,r,s)):(this.pos=n+1,this.column=s+1,this.makeToken(g.RPAREN,")",n,r,s));for(let[c,f,d]of sd)if(!(c==="("&&f==="("||c===")"&&f===")")&&!(this.dparenDepth>0&&c===";"&&(d===g.DSEMI||d===g.SEMI_AND||d===g.SEMI_SEMI_AND))&&i===c&&o===f){if(d===g.DBRACK_START||d===g.DBRACK_END){let p=t[n+2];if(p!==void 0&&p!==" "&&p!==" "&&p!==`
30
+ `&&p!==";"&&p!=="&"&&p!=="|"&&p!=="("&&p!==")"&&p!=="<"&&p!==">")break}return this.pos=n+2,this.column=s+2,this.makeToken(d,c+f,n,r,s)}if(i==="("&&this.dparenDepth>0)return this.pos=n+1,this.column=s+1,this.dparenDepth++,this.makeToken(g.LPAREN,"(",n,r,s);if(i===")"&&this.dparenDepth>1)return this.pos=n+1,this.column=s+1,this.dparenDepth--,this.makeToken(g.RPAREN,")",n,r,s);let u=id.get(i);if(u!==void 0)return this.pos=n+1,this.column=s+1,this.makeToken(u,i,n,r,s);if(i==="{"){let c=this.scanFdVariable(n);return c!==null?(this.pos=c.end,this.column=s+(c.end-n),{type:g.FD_VARIABLE,value:c.varname,start:n,end:c.end,line:r,column:s}):o==="}"?(this.pos=n+2,this.column=s+2,{type:g.WORD,value:"{}",start:n,end:n+2,line:r,column:s,quoted:!1,singleQuoted:!1}):this.scanBraceExpansion(n)!==null?this.readWordWithBraceExpansion(n,r,s):this.scanLiteralBraceWord(n)!==null?this.readWordWithBraceExpansion(n,r,s):o!==void 0&&o!==" "&&o!==" "&&o!==`
31
+ `?this.readWord(n,r,s):(this.pos=n+1,this.column=s+1,this.makeToken(g.LBRACE,"{",n,r,s))}return i==="}"?this.isWordCharFollowing(n+1)?this.readWord(n,r,s):(this.pos=n+1,this.column=s+1,this.makeToken(g.RBRACE,"}",n,r,s)):i==="!"?o==="="?(this.pos=n+2,this.column=s+2,this.makeToken(g.WORD,"!=",n,r,s)):(this.pos=n+1,this.column=s+1,this.makeToken(g.BANG,"!",n,r,s)):this.readWord(n,r,s)}looksLikeNestedSubshells(t){let n=this.input,r=n.length,s=t;for(;s<r&&(n[s]===" "||n[s]===" ");)s++;if(s>=r)return!1;let i=n[s];if(i==="(")return this.looksLikeNestedSubshells(s+1);let o=/[a-zA-Z_]/.test(i),a=i==="!"||i==="[";if(!o&&!a)return!1;let l=s;for(;l<r&&/[a-zA-Z0-9_\-.]/.test(n[l]);)l++;if(l===s)return a;let u=l;for(;u<r&&(n[u]===" "||n[u]===" ");)u++;if(u>=r)return!1;let c=n[u];if(c==="="&&n[u+1]!=="="||c===`
32
32
  `||l===u&&/[+\-*/%<>&|^!~?:]/.test(c)&&c!=="-"||c===")"&&n[u+1]===")")return!1;if(u>l&&(c==="-"||c==='"'||c==="'"||c==="$"||/[a-zA-Z_/.]/.test(c))){let f=u;for(;f<r&&n[f]!==`
33
33
  `;){if(n[f]===")")return!0;f++}return!1}if(c===")"){let f=u+1;for(;f<r&&(n[f]===" "||n[f]===" ");)f++;if(n[f]==="|"&&n[f+1]==="|"||n[f]==="&"&&n[f+1]==="&"||n[f]===";"||n[f]==="|"&&n[f+1]!=="|")return!0}return!1}makeToken(t,n,r,s,i){return{type:t,value:n,start:r,end:this.pos,line:s,column:i}}readComment(t,n,r){let s=this.input,i=s.length,o=this.pos;for(;o<i&&s[o]!==`
34
- `;)o++;let a=s.slice(t,o);return this.pos=o,this.column=r+(o-t),{type:w.COMMENT,value:a,start:t,end:o,line:n,column:r}}readWord(t,n,r){let s=this.input,i=s.length,o=this.pos,a=o;for(;o<i;){let g=s[o];if(g===" "||g===" "||g===`
35
- `||g===";"||g==="&"||g==="|"||g==="("||g===")"||g==="<"||g===">"||g==="'"||g==='"'||g==="\\"||g==="$"||g==="`"||g==="{"||g==="}"||g==="~"||g==="*"||g==="?"||g==="[")break;o++}if(o>a){let g=s[o];if(!(g==="("&&o>a&&"@*+?!".includes(s[o-1]))){if(o>=i||g===" "||g===" "||g===`
36
- `||g===";"||g==="&"||g==="|"||g==="("||g===")"||g==="<"||g===">"){let b=s.slice(a,o);this.pos=o,this.column=r+(o-a);let v=Xs.get(b);if(v!==void 0)return{type:v,value:b,start:t,end:o,line:n,column:r};let x=Ta(b);return x>0&&La(b.slice(0,x))?{type:w.ASSIGNMENT_WORD,value:b,start:t,end:o,line:n,column:r}:/^[0-9]+$/.test(b)?{type:w.NUMBER,value:b,start:t,end:o,line:n,column:r}:/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(b)?{type:w.NAME,value:b,start:t,end:o,line:n,column:r,quoted:!1,singleQuoted:!1}:{type:w.WORD,value:b,start:t,end:o,line:n,column:r,quoted:!1,singleQuoted:!1}}}}o=this.pos;let l=this.column,u=this.line,c="",f=!1,d=!1,p=!1,h=!1,m=s[o]==='"'||s[o]==="'",E=!1,S=0;for(;o<i;){let g=s[o];if(!p&&!h){if(g==="("&&c.length>0&&"@*+?!".includes(c[c.length-1])){let b=this.scanExtglobPattern(o);if(b!==null){c+=b.content,o=b.end,l+=b.content.length;continue}}if(g==="["&&S===0){if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(c)){let b=o+1<i?s[o+1]:"";if(b==="^"||b==="!"){c+=g,o++,l++;continue}S=1,c+=g,o++,l++;continue}}else if(g==="["&&S>0){c.length>0&&c[c.length-1]!=="\\"&&S++,c+=g,o++,l++;continue}else if(g==="]"&&S>0){c.length>0&&c[c.length-1]!=="\\"&&S--,c+=g,o++,l++;continue}if(S>0){if(g===`
37
- `)break;c+=g,o++,l++;continue}if(g===" "||g===" "||g===`
38
- `||g===";"||g==="&"||g==="|"||g==="("||g===")"||g==="<"||g===">")break}if(g==="$"&&o+1<i&&s[o+1]==="'"&&!p&&!h){for(c+="$'",o+=2,l+=2;o<i&&s[o]!=="'";)s[o]==="\\"&&o+1<i?(c+=s[o]+s[o+1],o+=2,l+=2):(c+=s[o],o++,l++);o<i&&(c+="'",o++,l++);continue}if(g==="$"&&o+1<i&&s[o+1]==='"'&&!p&&!h){o++,l++,h=!0,f=!0,c===""&&(m=!0),o++,l++;continue}if(g==="'"&&!h){if(p)if(p=!1,!m||E)c+=g;else{let b=o+1<i?s[o+1]:"";b&&!Fa(b)&&b!=="'"&&(b==='"'?(E=!0,c+=g,d=!1,f=!1):(E=!0,c+=g))}else p=!0,m&&!E?(d=!0,f=!0):c+=g;o++,l++;continue}if(g==='"'&&!p){if(h)if(h=!1,!m||E)c+=g;else{let b=o+1<i?s[o+1]:"";b&&!Fa(b)&&b!=='"'&&(b==="'"?(E=!0,c+=g,d=!1,f=!1):(E=!0,c+=g))}else h=!0,m&&!E?f=!0:c+=g;o++,l++;continue}if(g==="\\"&&!p&&o+1<i){let b=s[o+1];if(b===`
39
- `){o+=2,u++,l=1;continue}if(h){if(b==='"'||b==="\\"||b==="$"||b==="`"||b===`
40
- `){if(b===`
41
- `){o+=2,l=1,u++;continue}c+=g+b,o+=2,l+=2;continue}}else{c+=g+b,o+=2,l+=2;continue}}if(g==="$"&&o+1<i&&s[o+1]==="("&&!p){c+=g,o++,l++,c+=s[o],o++,l++;let b=1,v=!1,x=!1,A=0,k=!1,N="",$=[],C=s[o]==="("&&!this.dollarDparenIsSubshell(o),D=C?1:0;for(;b>0&&o<i;){let B=s[o];if(c+=B,v)B==="'"&&(v=!1);else if(x)B==="\\"&&o+1<i?(c+=s[o+1],o++,l++):B==='"'&&(x=!1);else{if(B==="("&&s[o+1]==="("?D++:B===")"&&s[o+1]===")"&&D>0&&D--,D===0&&B==="<"&&s[o+1]==="<"&&s[o+2]!=="<"){let H=o+2,R=!1;for(s[H]==="-"&&(R=!0,H++);s[H]===" "||s[H]===" ";)H++;let{delim:W,endPos:V,unclosedQuote:I,unclosedSubstitution:O}=Or(s,H);if(I)throw new Ke(`unexpected EOF while looking for matching \`${I}'`,u,l);if(O)throw new Ke("unexpected EOF while looking for matching `)'",u,l);if(W.length>0){c+=s.slice(o+1,V),l+=V-o,$.push({delim:W,stripTabs:R}),o=V;continue}}if(B===`
42
- `&&$.length>0){u++,l=0;let H=o+1;for(let{delim:R,stripTabs:W}of $)for(;!(H>=i);){let V=s.indexOf(`
43
- `,H);V===-1&&(V=i);let I=s.slice(H,V),O=W?I.replace(/^\t+/,""):I;c+=s.slice(H,Math.min(V+1,i)),V<i&&u++;let M=V>=i;if(H=V+1,O===R||M)break}$.length=0,l=0,o=Math.min(H,i);continue}if(B==="'")v=!0,N="";else if(B==='"')x=!0,N="";else if(B==="\\"&&o+1<i)c+=s[o+1],o++,l++,N="";else if(B==="$"&&o+1<i&&s[o+1]==="{"){o++,l++,c+=s[o],o++,l++;let H=1,R=!1,W=!1;for(;H>0&&o<i;){let V=s[o];if(V==="\\"&&o+1<i&&!R){c+=V,o++,l++,c+=s[o],o++,l++;continue}c+=V,R?V==="'"&&(R=!1):W?V==='"'&&(W=!1):V==="'"?R=!0:V==='"'?W=!0:V==="{"?H++:V==="}"&&H--,V===`
44
- `?(u++,l=0):l++,o++}N="";continue}else if(B==="#"&&!C&&(N===""||/\s/.test(s[o-1]||""))){for(;o+1<i&&s[o+1]!==`
45
- `;)o++,l++,c+=s[o];N=""}else/[a-zA-Z_]/.test(B)?N+=B:(N==="case"?(A++,k=!1):N==="in"&&A>0?k=!0:N==="esac"&&A>0&&(A--,k=!1),N="",B==="("?o>0&&s[o-1]==="$"?b++:k||b++:B===")"?k?k=!1:b--:B===";"&&A>0&&(o+1<i&&s[o+1]===";"||o+1<i&&s[o+1]==="&")&&(k=!0))}B===`
46
- `&&(u++,l=0,N=""),o++,l++}continue}if(g==="$"&&o+1<i&&s[o+1]==="["&&!p){c+=g,o++,l++,c+=s[o],o++,l++;let b=1;for(;b>0&&o<i;){let v=s[o];c+=v,v==="["?b++:v==="]"?b--:v===`
47
- `&&(u++,l=0),o++,l++}continue}if(g==="$"&&o+1<i&&s[o+1]==="{"&&!p){c+=g,o++,l++,c+=s[o],o++,l++;let b=1,v=!1,x=!1,A=u,k=l,N=u,$=l;for(;b>0&&o<i;){let C=s[o];if(C==="\\"&&o+1<i&&s[o+1]===`
48
- `){o+=2,u++,l=1;continue}if(C==="\\"&&o+1<i&&!v){c+=C,o++,l++,c+=s[o],o++,l++;continue}c+=C,v?C==="'"&&(v=!1):x?C==='"'&&(x=!1):C==="'"?(v=!0,A=u,k=l):C==='"'?(x=!0,N=u,$=l):C==="{"?b++:C==="}"&&b--,C===`
49
- `&&(u++,l=0),o++,l++}if(v)throw new Ke("unexpected EOF while looking for matching `''",A,k);if(x)throw new Ke("unexpected EOF while looking for matching `\"'",N,$);continue}if(g==="$"&&o+1<i&&!p){let b=s[o+1];if(b==="#"||b==="?"||b==="$"||b==="!"||b==="@"||b==="*"||b==="-"||b>="0"&&b<="9"){c+=g+b,o+=2,l+=2;continue}}if(g==="`"&&!p){for(c+=g,o++,l++;o<i&&s[o]!=="`";){let b=s[o];c+=b,b==="\\"&&o+1<i&&(c+=s[o+1],o++,l++),b===`
50
- `&&(u++,l=0),o++,l++}o<i&&(c+=s[o],o++,l++);continue}c+=g,o++,g===`
51
- `?(u++,l=1):l++}if(this.pos=o,this.column=l,this.line=u,E&&m&&(c=s[t]+c,f=!1,d=!1),p||h){let g=p?"'":'"';throw new Ke(`unexpected EOF while looking for matching \`${g}'`,n,r)}if(!m&&c.length>=2){if(c[0]==="'"&&c[c.length-1]==="'"){let g=c.slice(1,-1);!g.includes("'")&&!g.includes('"')&&(c=g,f=!0,d=!0)}else if(c[0]==='"'&&c[c.length-1]==='"'){let g=c.slice(1,-1),b=!1;for(let v=0;v<g.length;v++){if(g[v]==='"'){b=!0;break}g[v]==="\\"&&v+1<g.length&&v++}b||(c=g,f=!0,d=!1)}}if(c==="")return{type:w.WORD,value:"",start:t,end:o,line:n,column:r,quoted:f,singleQuoted:d};let y=Xs.get(c);if(!f&&y!==void 0)return{type:y,value:c,start:t,end:o,line:n,column:r};if(!m){let g=Ta(c);if(g>0&&La(c.slice(0,g)))return{type:w.ASSIGNMENT_WORD,value:c,start:t,end:o,line:n,column:r,quoted:f,singleQuoted:d}}return/^[0-9]+$/.test(c)?{type:w.NUMBER,value:c,start:t,end:o,line:n,column:r}:ed(c)?{type:w.NAME,value:c,start:t,end:o,line:n,column:r,quoted:f,singleQuoted:d}:{type:w.WORD,value:c,start:t,end:o,line:n,column:r,quoted:f,singleQuoted:d}}readHeredocContent(){for(;this.pendingHeredocs.length>0;){let t=this.pendingHeredocs.shift();if(!t)break;let n=this.pos,r=this.line,s=this.column,i="",o=!1;for(;this.pos<this.input.length;){let a="",l="",u="";for(;;){for(a="";this.pos<this.input.length&&this.input[this.pos]!==`
34
+ `;)o++;let a=s.slice(t,o);return this.pos=o,this.column=r+(o-t),{type:g.COMMENT,value:a,start:t,end:o,line:n,column:r}}readWord(t,n,r){let s=this.input,i=s.length,o=this.pos,a=o;for(;o<i;){let E=s[o];if(E===" "||E===" "||E===`
35
+ `||E===";"||E==="&"||E==="|"||E==="("||E===")"||E==="<"||E===">"||E==="'"||E==='"'||E==="\\"||E==="$"||E==="`"||E==="{"||E==="}"||E==="~"||E==="*"||E==="?"||E==="[")break;o++}if(o>a){let E=s[o];if(!(E==="("&&o>a&&"@*+?!".includes(s[o-1]))){if(o>=i||E===" "||E===" "||E===`
36
+ `||E===";"||E==="&"||E==="|"||E==="("||E===")"||E==="<"||E===">"){let S=s.slice(a,o);this.pos=o,this.column=r+(o-a);let v=Js.get(S);if(v!==void 0)return{type:v,value:S,start:t,end:o,line:n,column:r};let A=Wa(S);return A>0&&Ba(S.slice(0,A))?{type:g.ASSIGNMENT_WORD,value:S,start:t,end:o,line:n,column:r}:/^[0-9]+$/.test(S)?{type:g.NUMBER,value:S,start:t,end:o,line:n,column:r}:/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(S)?{type:g.NAME,value:S,start:t,end:o,line:n,column:r,quoted:!1,singleQuoted:!1}:{type:g.WORD,value:S,start:t,end:o,line:n,column:r,quoted:!1,singleQuoted:!1}}}}o=this.pos;let l=this.column,u=this.line,c="",f=!1,d=!1,p=!1,h=!1,m=s[o]==='"'||s[o]==="'",y=!1,b=0;for(;o<i;){let E=s[o];if(!p&&!h){if(E==="("&&c.length>0&&"@*+?!".includes(c[c.length-1])){let S=this.scanExtglobPattern(o);if(S!==null){c+=S.content,o=S.end,l+=S.content.length;continue}}if(E==="["&&b===0){if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(c)){let S=o+1<i?s[o+1]:"";if(S==="^"||S==="!"){c+=E,o++,l++;continue}b=1,c+=E,o++,l++;continue}}else if(E==="["&&b>0){c.length>0&&c[c.length-1]!=="\\"&&b++,c+=E,o++,l++;continue}else if(E==="]"&&b>0){c.length>0&&c[c.length-1]!=="\\"&&b--,c+=E,o++,l++;continue}if(b>0){if(E===`
37
+ `)break;c+=E,o++,l++;continue}if(E===" "||E===" "||E===`
38
+ `||E===";"||E==="&"||E==="|"||E==="("||E===")"||E==="<"||E===">")break}if(E==="$"&&o+1<i&&s[o+1]==="'"&&!p&&!h){for(c+="$'",o+=2,l+=2;o<i&&s[o]!=="'";)s[o]==="\\"&&o+1<i?(c+=s[o]+s[o+1],o+=2,l+=2):(c+=s[o],o++,l++);o<i&&(c+="'",o++,l++);continue}if(E==="$"&&o+1<i&&s[o+1]==='"'&&!p&&!h){o++,l++,h=!0,f=!0,c===""&&(m=!0),o++,l++;continue}if(E==="'"&&!h){if(p)if(p=!1,!m||y)c+=E;else{let S=o+1<i?s[o+1]:"";S&&!Va(S)&&S!=="'"&&(S==='"'?(y=!0,c+=E,d=!1,f=!1):(y=!0,c+=E))}else p=!0,m&&!y?(d=!0,f=!0):c+=E;o++,l++;continue}if(E==='"'&&!p){if(h)if(h=!1,!m||y)c+=E;else{let S=o+1<i?s[o+1]:"";S&&!Va(S)&&S!=='"'&&(S==="'"?(y=!0,c+=E,d=!1,f=!1):(y=!0,c+=E))}else h=!0,m&&!y?f=!0:c+=E;o++,l++;continue}if(E==="\\"&&!p&&o+1<i){let S=s[o+1];if(S===`
39
+ `){o+=2,u++,l=1;continue}if(h){if(S==='"'||S==="\\"||S==="$"||S==="`"||S===`
40
+ `){if(S===`
41
+ `){o+=2,l=1,u++;continue}c+=E+S,o+=2,l+=2;continue}}else{c+=E+S,o+=2,l+=2;continue}}if(E==="$"&&o+1<i&&s[o+1]==="("&&!p){c+=E,o++,l++,c+=s[o],o++,l++;let S=1,v=!1,A=!1,x=0,$=!1,I="",P=[],N=s[o]==="("&&!this.dollarDparenIsSubshell(o),D=N?1:0;for(;S>0&&o<i;){let R=s[o];if(c+=R,v)R==="'"&&(v=!1);else if(A)R==="\\"&&o+1<i?(c+=s[o+1],o++,l++):R==='"'&&(A=!1);else{if(R==="("&&s[o+1]==="("?D++:R===")"&&s[o+1]===")"&&D>0&&D--,D===0&&R==="<"&&s[o+1]==="<"&&s[o+2]!=="<"){let B=o+2,k=!1;for(s[B]==="-"&&(k=!0,B++);s[B]===" "||s[B]===" ";)B++;let{delim:M,endPos:z,unclosedQuote:O,unclosedSubstitution:_}=Fr(s,B);if(O)throw new Ke(`unexpected EOF while looking for matching \`${O}'`,u,l);if(_)throw new Ke("unexpected EOF while looking for matching `)'",u,l);if(M.length>0){c+=s.slice(o+1,z),l+=z-o,P.push({delim:M,stripTabs:k}),o=z;continue}}if(R===`
42
+ `&&P.length>0){u++,l=0;let B=o+1;for(let{delim:k,stripTabs:M}of P)for(;!(B>=i);){let z=s.indexOf(`
43
+ `,B);z===-1&&(z=i);let O=s.slice(B,z),_=M?O.replace(/^\t+/,""):O;c+=s.slice(B,Math.min(z+1,i)),z<i&&u++;let V=z>=i;if(B=z+1,_===k||V)break}P.length=0,l=0,o=Math.min(B,i);continue}if(R==="'")v=!0,I="";else if(R==='"')A=!0,I="";else if(R==="\\"&&o+1<i)c+=s[o+1],o++,l++,I="";else if(R==="$"&&o+1<i&&s[o+1]==="{"){o++,l++,c+=s[o],o++,l++;let B=1,k=!1,M=!1;for(;B>0&&o<i;){let z=s[o];if(z==="\\"&&o+1<i&&!k){c+=z,o++,l++,c+=s[o],o++,l++;continue}c+=z,k?z==="'"&&(k=!1):M?z==='"'&&(M=!1):z==="'"?k=!0:z==='"'?M=!0:z==="{"?B++:z==="}"&&B--,z===`
44
+ `?(u++,l=0):l++,o++}I="";continue}else if(R==="#"&&!N&&(I===""||/\s/.test(s[o-1]||""))){for(;o+1<i&&s[o+1]!==`
45
+ `;)o++,l++,c+=s[o];I=""}else/[a-zA-Z_]/.test(R)?I+=R:(I==="case"?(x++,$=!1):I==="in"&&x>0?$=!0:I==="esac"&&x>0&&(x--,$=!1),I="",R==="("?o>0&&s[o-1]==="$"?S++:$||S++:R===")"?$?$=!1:S--:R===";"&&x>0&&(o+1<i&&s[o+1]===";"||o+1<i&&s[o+1]==="&")&&($=!0))}R===`
46
+ `&&(u++,l=0,I=""),o++,l++}continue}if(E==="$"&&o+1<i&&s[o+1]==="["&&!p){c+=E,o++,l++,c+=s[o],o++,l++;let S=1;for(;S>0&&o<i;){let v=s[o];c+=v,v==="["?S++:v==="]"?S--:v===`
47
+ `&&(u++,l=0),o++,l++}continue}if(E==="$"&&o+1<i&&s[o+1]==="{"&&!p){c+=E,o++,l++,c+=s[o],o++,l++;let S=1,v=!1,A=!1,x=u,$=l,I=u,P=l;for(;S>0&&o<i;){let N=s[o];if(N==="\\"&&o+1<i&&s[o+1]===`
48
+ `){o+=2,u++,l=1;continue}if(N==="\\"&&o+1<i&&!v){c+=N,o++,l++,c+=s[o],o++,l++;continue}c+=N,v?N==="'"&&(v=!1):A?N==='"'&&(A=!1):N==="'"?(v=!0,x=u,$=l):N==='"'?(A=!0,I=u,P=l):N==="{"?S++:N==="}"&&S--,N===`
49
+ `&&(u++,l=0),o++,l++}if(v)throw new Ke("unexpected EOF while looking for matching `''",x,$);if(A)throw new Ke("unexpected EOF while looking for matching `\"'",I,P);continue}if(E==="$"&&o+1<i&&!p){let S=s[o+1];if(S==="#"||S==="?"||S==="$"||S==="!"||S==="@"||S==="*"||S==="-"||S>="0"&&S<="9"){c+=E+S,o+=2,l+=2;continue}}if(E==="`"&&!p){for(c+=E,o++,l++;o<i&&s[o]!=="`";){let S=s[o];c+=S,S==="\\"&&o+1<i&&(c+=s[o+1],o++,l++),S===`
50
+ `&&(u++,l=0),o++,l++}o<i&&(c+=s[o],o++,l++);continue}c+=E,o++,E===`
51
+ `?(u++,l=1):l++}if(this.pos=o,this.column=l,this.line=u,y&&m&&(c=s[t]+c,f=!1,d=!1),p||h){let E=p?"'":'"';throw new Ke(`unexpected EOF while looking for matching \`${E}'`,n,r)}if(!m&&c.length>=2){if(c[0]==="'"&&c[c.length-1]==="'"){let E=c.slice(1,-1);!E.includes("'")&&!E.includes('"')&&(c=E,f=!0,d=!0)}else if(c[0]==='"'&&c[c.length-1]==='"'){let E=c.slice(1,-1),S=!1;for(let v=0;v<E.length;v++){if(E[v]==='"'){S=!0;break}E[v]==="\\"&&v+1<E.length&&v++}S||(c=E,f=!0,d=!1)}}if(c==="")return{type:g.WORD,value:"",start:t,end:o,line:n,column:r,quoted:f,singleQuoted:d};let w=Js.get(c);if(!f&&w!==void 0)return{type:w,value:c,start:t,end:o,line:n,column:r};if(!m){let E=Wa(c);if(E>0&&Ba(c.slice(0,E)))return{type:g.ASSIGNMENT_WORD,value:c,start:t,end:o,line:n,column:r,quoted:f,singleQuoted:d}}return/^[0-9]+$/.test(c)?{type:g.NUMBER,value:c,start:t,end:o,line:n,column:r}:od(c)?{type:g.NAME,value:c,start:t,end:o,line:n,column:r,quoted:f,singleQuoted:d}:{type:g.WORD,value:c,start:t,end:o,line:n,column:r,quoted:f,singleQuoted:d}}readHeredocContent(){for(;this.pendingHeredocs.length>0;){let t=this.pendingHeredocs.shift();if(!t)break;let n=this.pos,r=this.line,s=this.column,i="",o=!1;for(;this.pos<this.input.length;){let a="",l="",u="";for(;;){for(a="";this.pos<this.input.length&&this.input[this.pos]!==`
52
52
  `;)a+=this.input[this.pos],this.pos++,this.column++;let f=0;for(let d=a.length-1;a[d]==="\\";d-=1)f+=1;if(u+=a,t.quoted||f%2===0||this.pos+1>=this.input.length)break;u=u.slice(0,-1),l+=`${a}
53
53
  `,this.pos++,this.line++,this.column=1}if((t.stripTabs?u.replace(/^\t+/,""):u)===t.delimiter){o=!0,this.pos<this.input.length&&this.input[this.pos]===`
54
54
  `&&(this.pos++,this.line++,this.column=1);break}if(i+=l,i+=a,this.pos<this.input.length&&this.input[this.pos]===`
55
55
  `?(i+=`
56
56
  `,this.pos++,this.line++,this.column=1):a.length>0&&(i+=`
57
- `),i.length>this.maxHeredocSize)throw new Ke(`Heredoc size limit exceeded (${this.maxHeredocSize} bytes)`,r,s)}this.tokens.push({type:w.HEREDOC_CONTENT,value:i,start:n,end:this.pos,line:r,column:s,heredocTerminated:o})}}readHeredocDelimiterToken(t,n,r,s){let i=this.input,{delim:o,endPos:a,quoted:l,unclosedQuote:u,unclosedSubstitution:c}=Or(i,t);if(u)throw new Ke(`unexpected EOF while looking for matching \`${u}'`,n,r);if(c)throw new Ke("unexpected EOF while looking for matching `)'",n,r);if(a===t)throw new Ke("Expected here-document delimiter",n,r);let f=n,d=r;for(let p=t;p<a;p++)i[p]===`
58
- `?(f+=1,d=1):d+=1;return this.pos=a,this.line=f,this.column=d,this.pendingHeredocs.push({delimiter:o,stripTabs:s,quoted:l}),{type:w.WORD,value:i.slice(t,a),start:t,end:a,line:n,column:r,quoted:l,heredocDelimiter:o}}isWordCharFollowing(t){if(t>=this.input.length)return!1;let n=this.input[t];return!(n===" "||n===" "||n===`
57
+ `),i.length>this.maxHeredocSize)throw new Ke(`Heredoc size limit exceeded (${this.maxHeredocSize} bytes)`,r,s)}this.tokens.push({type:g.HEREDOC_CONTENT,value:i,start:n,end:this.pos,line:r,column:s,heredocTerminated:o})}}readHeredocDelimiterToken(t,n,r,s){let i=this.input,{delim:o,endPos:a,quoted:l,unclosedQuote:u,unclosedSubstitution:c}=Fr(i,t);if(u)throw new Ke(`unexpected EOF while looking for matching \`${u}'`,n,r);if(c)throw new Ke("unexpected EOF while looking for matching `)'",n,r);if(a===t)throw new Ke("Expected here-document delimiter",n,r);let f=n,d=r;for(let p=t;p<a;p++)i[p]===`
58
+ `?(f+=1,d=1):d+=1;return this.pos=a,this.line=f,this.column=d,this.pendingHeredocs.push({delimiter:o,stripTabs:s,quoted:l}),{type:g.WORD,value:i.slice(t,a),start:t,end:a,line:n,column:r,quoted:l,heredocDelimiter:o}}isWordCharFollowing(t){if(t>=this.input.length)return!1;let n=this.input[t];return!(n===" "||n===" "||n===`
59
59
  `||n===";"||n==="&"||n==="|"||n==="("||n===")"||n==="<"||n===">")}readWordWithBraceExpansion(t,n,r){let s=this.input,i=s.length,o=t,a=r;for(;o<i;){let u=s[o];if(u===" "||u===" "||u===`
60
- `||u===";"||u==="&"||u==="|"||u==="("||u===")"||u==="<"||u===">")break;if(u==="{"){if(this.scanBraceExpansion(o)!==null){let f=1;for(o++,a++;o<i&&f>0;)s[o]==="{"?f++:s[o]==="}"&&f--,o++,a++;continue}o++,a++;continue}if(u==="}"){o++,a++;continue}if(u==="$"&&o+1<i&&s[o+1]==="("){o++,a++,o++,a++;let c=1;for(;c>0&&o<i;)s[o]==="("?c++:s[o]===")"&&c--,o++,a++;continue}if(u==="$"&&o+1<i&&s[o+1]==="{"){o++,a++,o++,a++;let c=1;for(;c>0&&o<i;)s[o]==="{"?c++:s[o]==="}"&&c--,o++,a++;continue}if(u==="`"){for(o++,a++;o<i&&s[o]!=="`";)s[o]==="\\"&&o+1<i?(o+=2,a+=2):(o++,a++);o<i&&(o++,a++);continue}o++,a++}let l=s.slice(t,o);return this.pos=o,this.column=a,{type:w.WORD,value:l,start:t,end:o,line:n,column:r,quoted:!1,singleQuoted:!1}}scanBraceExpansion(t){let n=this.input,r=n.length,s=t+1,i=1,o=!1,a=!1;for(;s<r&&i>0;){let l=n[s];if(l==="{")i++,s++;else if(l==="}")i--,s++;else if(l===","&&i===1)o=!0,s++;else if(l==="."&&s+1<r&&n[s+1]===".")a=!0,s+=2;else{if(l===" "||l===" "||l===`
60
+ `||u===";"||u==="&"||u==="|"||u==="("||u===")"||u==="<"||u===">")break;if(u==="{"){if(this.scanBraceExpansion(o)!==null){let f=1;for(o++,a++;o<i&&f>0;)s[o]==="{"?f++:s[o]==="}"&&f--,o++,a++;continue}o++,a++;continue}if(u==="}"){o++,a++;continue}if(u==="$"&&o+1<i&&s[o+1]==="("){o++,a++,o++,a++;let c=1;for(;c>0&&o<i;)s[o]==="("?c++:s[o]===")"&&c--,o++,a++;continue}if(u==="$"&&o+1<i&&s[o+1]==="{"){o++,a++,o++,a++;let c=1;for(;c>0&&o<i;)s[o]==="{"?c++:s[o]==="}"&&c--,o++,a++;continue}if(u==="`"){for(o++,a++;o<i&&s[o]!=="`";)s[o]==="\\"&&o+1<i?(o+=2,a+=2):(o++,a++);o<i&&(o++,a++);continue}o++,a++}let l=s.slice(t,o);return this.pos=o,this.column=a,{type:g.WORD,value:l,start:t,end:o,line:n,column:r,quoted:!1,singleQuoted:!1}}scanBraceExpansion(t){let n=this.input,r=n.length,s=t+1,i=1,o=!1,a=!1;for(;s<r&&i>0;){let l=n[s];if(l==="{")i++,s++;else if(l==="}")i--,s++;else if(l===","&&i===1)o=!0,s++;else if(l==="."&&s+1<r&&n[s+1]===".")a=!0,s+=2;else{if(l===" "||l===" "||l===`
61
61
  `||l===";"||l==="&"||l==="|")return null;s++}}return i===0&&(o||a)?n.slice(t,s):null}scanLiteralBraceWord(t){let n=this.input,r=n.length,s=t+1,i=1;for(;s<r&&i>0;){let o=n[s];if(o==="{")i++,s++;else if(o==="}"){if(i--,i===0)return n.slice(t,s+1);s++}else{if(o===" "||o===" "||o===`
62
62
  `||o===";"||o==="&"||o==="|")return null;s++}}return null}scanExtglobPattern(t){let n=this.input,r=n.length,s=t+1,i=1;for(;s<r&&i>0;){let o=n[s];if(o==="\\"&&s+1<r){s+=2;continue}if("@*+?!".includes(o)&&s+1<r&&n[s+1]==="("){s++,i++,s++;continue}if(o==="(")i++,s++;else if(o===")")i--,s++;else{if(o===`
63
63
  `)return null;s++}}return i===0?{content:n.slice(t,s),end:s}:null}scanFdVariable(t){let n=this.input,r=n.length,s=t+1,i=s;for(;s<r;){let c=n[s];if(s===i){if(!(c>="a"&&c<="z"||c>="A"&&c<="Z"||c==="_"))return null}else if(!(c>="a"&&c<="z"||c>="A"&&c<="Z"||c>="0"&&c<="9"||c==="_"))break;s++}if(s===i)return null;let o=n.slice(i,s);if(s>=r||n[s]!=="}"||(s++,s>=r))return null;let a=n[s],l=s+1<r?n[s+1]:"";return a===">"||a==="<"||a==="&"&&(l===">"||l==="<")?{varname:o,end:s}:null}dollarDparenIsSubshell(t){let n=this.input,r=n.length,s=t+1,i=2,o=!1,a=!1,l=!1;for(;s<r&&i>0;){let u=n[s];if(o){u==="'"&&(o=!1),u===`
@@ -65,215 +65,216 @@ Gid: ${s} ${s} ${s} ${s}
65
65
  `&&(l=!0),s++;continue}if(u==="'"){o=!0,s++;continue}if(u==='"'){a=!0,s++;continue}if(u==="\\"){s+=2;continue}if(u===`
66
66
  `&&(l=!0),u==="("){i++,s++;continue}if(u===")"){if(i--,i===1){let c=s+1;if(c<r&&n[c]===")")return!1;let f=c,d=!1;for(;f<r&&(n[f]===" "||n[f]===" "||n[f]===`
67
67
  `);)d=!0,f++;if(d&&f<r&&n[f]===")"||l)return!0}if(i===0)return!1;s++;continue}s++}return!1}dparenClosesWithSpacedParens(t){let n=this.input,r=n.length,s=t,i=2,o=!1,a=!1;for(;s<r&&i>0;){let l=n[s];if(o){l==="'"&&(o=!1),s++;continue}if(a){if(l==="\\"){s+=2;continue}l==='"'&&(a=!1),s++;continue}if(l==="'"){o=!0,s++;continue}if(l==='"'){a=!0,s++;continue}if(l==="\\"){s+=2;continue}if(l==="("){i++,s++;continue}if(l===")"){if(i--,i===1){let u=s+1;if(u<r&&n[u]===")")return!1;let c=u,f=!1;for(;c<r&&(n[c]===" "||n[c]===" "||n[c]===`
68
- `);)f=!0,c++;if(f&&c<r&&n[c]===")")return!0}if(i===0)return!1;s++;continue}if(i===1&&(l==="|"&&s+1<r&&n[s+1]==="|"||l==="&"&&s+1<r&&n[s+1]==="&"||l==="|"&&s+1<r&&n[s+1]!=="|"))return!0;s++}return!1}};var Js=1e6,nr=1e5,td=1e6,Ma=200,Pe;(function(e){e[e.Default=0]="Default",e[e.Assignment=1]="Assignment",e[e.NoBraceExpansion=2]="NoBraceExpansion",e[e.Regex=4]="Regex"})(Pe||(Pe={}));var Ba=new Set([w.LESS,w.GREAT,w.DLESS,w.DGREAT,w.LESSAND,w.GREATAND,w.LESSGREAT,w.DLESSDASH,w.CLOBBER,w.TLESS,w.AND_GREAT,w.AND_DGREAT]),Wa=new Set([w.LESS,w.GREAT,w.DLESS,w.DGREAT,w.LESSAND,w.GREATAND,w.LESSGREAT,w.DLESSDASH,w.CLOBBER,w.TLESS]),Va=new Set([w.LESS,w.GREAT,w.DLESS,w.DGREAT,w.LESSAND,w.GREATAND,w.LESSGREAT,w.DLESSDASH,w.CLOBBER,w.TLESS,w.AND_GREAT,w.AND_DGREAT]),xe=class extends Error{line;column;token;constructor(t,n,r,s=void 0){super(`Parse error at ${n}:${r}: ${t}`),this.line=n,this.column=r,this.token=s,this.name="ParseException"}},Lr=class{iterations=0;tokens=0;depth=0;reset(){this.iterations=0,this.tokens=0,this.depth=0}chargeIteration(t,n){if(this.iterations++,this.iterations>td)throw new xe("Maximum parse iterations exceeded (possible infinite loop)",t,n)}chargeTokens(t,n=1,r=1){if(this.tokens+=t,this.tokens>nr)throw new xe(`Too many tokens: cumulative count exceeds limit of ${nr}`,n,r)}enter(t,n){if(this.depth++,this.depth>Ma)throw this.depth--,new xe(`Maximum parser nesting depth exceeded (${Ma})`,t,n);let r=!0;return()=>{r&&(r=!1,this.depth--)}}};function he(e,t){for(;t<e.length;){if(e[t]==="\\"&&e[t+1]===`
69
- `){t+=2;continue}if(/\s/.test(e[t])){t++;continue}break}return t}var Tr=["=","+=","-=","*=","/=","%=","<<=",">>=","&=","|=","^="];function rr(e){if(e.includes("#")){let n=e.split("#");if(n.length!==2)return Number.NaN;let[r,s]=n;if(!/^\d+$/.test(r)||s.length===0)return Number.NaN;let i=Number.parseInt(r,10);if(i<2||i>64)return Number.NaN;let o=0;for(let a of s){let l;if(/[0-9]/.test(a))l=a.charCodeAt(0)-48;else if(/[a-z]/.test(a))l=a.charCodeAt(0)-97+10;else if(/[A-Z]/.test(a))l=a.charCodeAt(0)-65+(i<=36?10:36);else if(a==="@")l=62;else if(a==="_")l=63;else return Number.NaN;if(l>=i)return Number.NaN;if(o=o*i+l,o>Number.MAX_SAFE_INTEGER)return Number.MAX_SAFE_INTEGER}return o}if(e.startsWith("0x")||e.startsWith("0X")){let n=Number.parseInt(e.slice(2),16);return n>Number.MAX_SAFE_INTEGER?Number.MAX_SAFE_INTEGER:n}if(e.startsWith("0")&&e.length>1&&/^[0-9]+$/.test(e)){if(/[89]/.test(e))return Number.NaN;let n=Number.parseInt(e,8);return n>Number.MAX_SAFE_INTEGER?Number.MAX_SAFE_INTEGER:n}let t=Number.parseInt(e,10);return t>Number.MAX_SAFE_INTEGER?Number.MAX_SAFE_INTEGER:t}function za(e,t,n,r){if(n.slice(r,r+3)!=="$((")return null;let s=r+3,i=1,o=s;for(;s<n.length-1&&i>0;)n[s]==="("&&n[s+1]==="("?(i++,s+=2):n[s]===")"&&n[s+1]===")"?(i--,i>0&&(s+=2)):s++;let a=n.slice(o,s),{expr:l}=e(t,a,0);return s+=2,{expr:{type:"ArithNested",expression:l},pos:s}}function qa(e,t){if(e.slice(t,t+2)!=="$'")return null;let n=t+2,r="";for(;n<e.length&&e[n]!=="'";)if(e[n]==="\\"&&n+1<e.length){let i=e[n+1];switch(i){case"n":r+=`
70
- `;break;case"t":r+=" ";break;case"r":r+="\r";break;case"\\":r+="\\";break;case"'":r+="'";break;default:r+=i}n+=2}else r+=e[n],n++;e[n]==="'"&&n++;let s=Number.parseInt(r,10);return{expr:{type:"ArithNumber",value:Number.isNaN(s)?0:s},pos:n}}function Ua(e,t){if(e.slice(t,t+2)!=='$"')return null;let n=t+2,r="";for(;n<e.length&&e[n]!=='"';)e[n]==="\\"&&n+1<e.length?(r+=e[n+1],n+=2):(r+=e[n],n++);e[n]==='"'&&n++;let s=Number.parseInt(r,10);return{expr:{type:"ArithNumber",value:Number.isNaN(s)?0:s},pos:n}}function nd(e){let t="",n=0;for(;n<e.length;)if(e[n]==='"'){for(n++;n<e.length&&e[n]!=='"';)e[n]==="\\"&&n+1<e.length?(t+=e[n+1],n+=2):(t+=e[n],n++);n<e.length&&n++}else t+=e[n],n++;return t}function te(e,t){let n=nd(t),{expr:r,pos:s}=_n(e,n,0),i=he(n,s);if(i<n.length){let o=t.slice(i).trim();if(o)return{type:"ArithmeticExpression",originalText:t,expression:{type:"ArithSyntaxError",errorToken:o,message:`${o}: syntax error: invalid arithmetic operator (error token is "${o}")`}}}return{type:"ArithmeticExpression",expression:r,originalText:t}}function qe(e,t){return{expr:{type:"ArithSyntaxError",errorToken:e,message:`syntax error: operand expected (error token is "${e}")`},pos:t}}function Ue(e,t){return he(e,t)>=e.length}function _n(e,t,n){return rd(e,t,n)}function hn(e,t,n){return e.withDepth(()=>_n(e,t,n))}function rd(e,t,n){let{expr:r,pos:s}=sr(e,t,n);for(s=he(t,s);t[s]===",";){if(s++,Ue(t,s))return qe(",",s);let{expr:o,pos:a}=sr(e,t,s);r={type:"ArithBinary",operator:",",left:r,right:o},s=he(t,a)}return{expr:r,pos:s}}function sr(e,t,n){let{expr:r,pos:s}=sd(e,t,n);if(s=he(t,s),t[s]==="?"){s++;let{expr:i,pos:o}=hn(e,t,s);if(s=he(t,o),t[s]===":"){s++;let{expr:a,pos:l}=hn(e,t,s);return{expr:{type:"ArithTernary",condition:r,consequent:i,alternate:a},pos:l}}}return{expr:r,pos:s}}function sd(e,t,n){let{expr:r,pos:s}=ja(e,t,n);for(;s=he(t,s),t.slice(s,s+2)==="||";){if(s+=2,Ue(t,s))return qe("||",s);let{expr:o,pos:a}=ja(e,t,s);r={type:"ArithBinary",operator:"||",left:r,right:o},s=a}return{expr:r,pos:s}}function ja(e,t,n){let{expr:r,pos:s}=Ga(e,t,n);for(;s=he(t,s),t.slice(s,s+2)==="&&";){if(s+=2,Ue(t,s))return qe("&&",s);let{expr:o,pos:a}=Ga(e,t,s);r={type:"ArithBinary",operator:"&&",left:r,right:o},s=a}return{expr:r,pos:s}}function Ga(e,t,n){let{expr:r,pos:s}=Ha(e,t,n);for(;s=he(t,s),t[s]==="|"&&t[s+1]!=="|";){if(s++,Ue(t,s))return qe("|",s);let{expr:o,pos:a}=Ha(e,t,s);r={type:"ArithBinary",operator:"|",left:r,right:o},s=a}return{expr:r,pos:s}}function Ha(e,t,n){let{expr:r,pos:s}=Za(e,t,n);for(;s=he(t,s),t[s]==="^";){if(s++,Ue(t,s))return qe("^",s);let{expr:o,pos:a}=Za(e,t,s);r={type:"ArithBinary",operator:"^",left:r,right:o},s=a}return{expr:r,pos:s}}function Za(e,t,n){let{expr:r,pos:s}=Qa(e,t,n);for(;s=he(t,s),t[s]==="&"&&t[s+1]!=="&";){if(s++,Ue(t,s))return qe("&",s);let{expr:o,pos:a}=Qa(e,t,s);r={type:"ArithBinary",operator:"&",left:r,right:o},s=a}return{expr:r,pos:s}}function Qa(e,t,n){let{expr:r,pos:s}=Ka(e,t,n);for(;s=he(t,s),t.slice(s,s+2)==="=="||t.slice(s,s+2)==="!=";){let i=t.slice(s,s+2);if(s+=2,Ue(t,s))return qe(i,s);let{expr:o,pos:a}=Ka(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:o},s=a}return{expr:r,pos:s}}function Ka(e,t,n){let{expr:r,pos:s}=ei(e,t,n);for(;;)if(s=he(t,s),t.slice(s,s+2)==="<="||t.slice(s,s+2)===">="){let i=t.slice(s,s+2);if(s+=2,Ue(t,s))return qe(i,s);let{expr:o,pos:a}=ei(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:o},s=a}else if(t[s]==="<"||t[s]===">"){let i=t[s];if(s++,Ue(t,s))return qe(i,s);let{expr:o,pos:a}=ei(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:o},s=a}else break;return{expr:r,pos:s}}function ei(e,t,n){let{expr:r,pos:s}=Xa(e,t,n);for(;s=he(t,s),t.slice(s,s+2)==="<<"||t.slice(s,s+2)===">>";){let i=t.slice(s,s+2);if(s+=2,Ue(t,s))return qe(i,s);let{expr:o,pos:a}=Xa(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:o},s=a}return{expr:r,pos:s}}function Xa(e,t,n){let{expr:r,pos:s}=Ya(e,t,n);for(;s=he(t,s),(t[s]==="+"||t[s]==="-")&&t[s+1]!==t[s];){let i=t[s];if(s++,Ue(t,s))return qe(i,s);let{expr:o,pos:a}=Ya(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:o},s=a}return{expr:r,pos:s}}function Ya(e,t,n){let{expr:r,pos:s}=Fr(e,t,n);for(;;)if(s=he(t,s),t[s]==="*"&&t[s+1]!=="*"){if(s++,Ue(t,s))return qe("*",s);let{expr:o,pos:a}=Fr(e,t,s);r={type:"ArithBinary",operator:"*",left:r,right:o},s=a}else if(t[s]==="/"||t[s]==="%"){let i=t[s];if(s++,Ue(t,s))return qe(i,s);let{expr:o,pos:a}=Fr(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:o},s=a}else break;return{expr:r,pos:s}}function Fr(e,t,n){let{expr:r,pos:s}=ti(e,t,n),i=he(t,s);if(t.slice(i,i+2)==="**"){if(i+=2,Ue(t,i))return qe("**",i);let{expr:a,pos:l}=e.withDepth(()=>Fr(e,t,i));return{expr:{type:"ArithBinary",operator:"**",left:r,right:a},pos:l}}return{expr:r,pos:s}}function ti(e,t,n){let r=he(t,n);if(t.slice(r,r+2)==="++"||t.slice(r,r+2)==="--"){let s=t.slice(r,r+2);r+=2;let{expr:i,pos:o}=e.withDepth(()=>ti(e,t,r));return{expr:{type:"ArithUnary",operator:s,operand:i,prefix:!0},pos:o}}if(t[r]==="+"||t[r]==="-"||t[r]==="!"||t[r]==="~"){let s=t[r];r++;let{expr:i,pos:o}=e.withDepth(()=>ti(e,t,r));return{expr:{type:"ArithUnary",operator:s,operand:i,prefix:!0},pos:o}}return od(e,t,r)}function id(e,t){let n=e[t];return n==="$"||n==="`"}function od(e,t,n){let{expr:r,pos:s}=Ja(e,t,n,!1),i=[r];for(;id(t,s);){let{expr:a,pos:l}=Ja(e,t,s,!0);i.push(a),s=l}i.length>1&&(r={type:"ArithConcat",parts:i});let o;if(t[s]==="["&&r.type==="ArithConcat"){s++;let{expr:a,pos:l}=hn(e,t,s);o=a,s=l,t[s]==="]"&&s++}if(o&&r.type==="ArithConcat"&&(r={type:"ArithDynamicElement",nameExpr:r,subscript:o},o=void 0),s=he(t,s),r.type==="ArithConcat"||r.type==="ArithVariable"||r.type==="ArithDynamicElement"){for(let a of Tr)if(t.slice(s,s+a.length)===a&&t.slice(s,s+a.length+1)!=="=="){s+=a.length;let{expr:l,pos:u}=e.withDepth(()=>sr(e,t,s));return r.type==="ArithDynamicElement"?{expr:{type:"ArithDynamicAssignment",operator:a,target:r.nameExpr,subscript:r.subscript,value:l},pos:u}:r.type==="ArithConcat"?{expr:{type:"ArithDynamicAssignment",operator:a,target:r,value:l},pos:u}:{expr:{type:"ArithAssignment",operator:a,variable:r.name,value:l},pos:u}}}if(t.slice(s,s+2)==="++"||t.slice(s,s+2)==="--"){let a=t.slice(s,s+2);return s+=2,{expr:{type:"ArithUnary",operator:a,operand:r,prefix:!1},pos:s}}return{expr:r,pos:s}}function Ja(e,t,n,r=!1){let s=he(t,n),i=za(hn,e,t,s);if(i)return i;let o=qa(t,s);if(o)return o;let a=Ua(t,s);if(a)return a;if(t.slice(s,s+2)==="$("&&t[s+2]!=="("){s+=2;let u=1,c=s;for(;s<t.length&&u>0;)t[s]==="("?u++:t[s]===")"&&u--,u>0&&s++;let f=t.slice(c,s);return s++,{expr:{type:"ArithCommandSubst",command:f},pos:s}}if(t[s]==="`"){s++;let u=s;for(;s<t.length&&t[s]!=="`";)s++;let c=t.slice(u,s);return t[s]==="`"&&s++,{expr:{type:"ArithCommandSubst",command:c},pos:s}}if(t[s]==="("){s++;let{expr:u,pos:c}=hn(e,t,s);return s=he(t,c),t[s]===")"&&s++,{expr:{type:"ArithGroup",expression:u},pos:s}}if(t[s]==="'"){s++;let u="";for(;s<t.length&&t[s]!=="'";)u+=t[s],s++;t[s]==="'"&&s++;let c=Number.parseInt(u,10);return{expr:{type:"ArithSingleQuote",content:u,value:Number.isNaN(c)?0:c},pos:s}}if(t[s]==='"'){s++;let u="";for(;s<t.length&&t[s]!=='"';)t[s]==="\\"&&s+1<t.length?(u+=t[s+1],s+=2):(u+=t[s],s++);t[s]==='"'&&s++;let c=u.trim();if(!c)return{expr:{type:"ArithNumber",value:0},pos:s};let{expr:f}=hn(e,c,0);return{expr:f,pos:s}}if(/[0-9]/.test(t[s])){let u="",c=!1,f=!1;for(;s<t.length;){let p=t[s];if(c)if(/[0-9a-zA-Z@_]/.test(p))u+=p,s++;else break;else if(p==="#")c=!0,u+=p,s++;else if(u==="0"&&(p==="x"||p==="X")&&s+1<t.length&&/[0-9a-fA-F]/.test(t[s+1]))f=!0,u+=p,s++;else if(f&&/[0-9a-fA-F]/.test(p))u+=p,s++;else if(!f&&/[0-9]/.test(p))u+=p,s++;else break}if(s<t.length&&/[a-zA-Z_]/.test(t[s])){let p=u;for(;s<t.length&&/[a-zA-Z0-9_]/.test(t[s]);)p+=t[s],s++;return{expr:{type:"ArithSyntaxError",errorToken:p,message:`${p}: value too great for base (error token is "${p}")`},pos:s}}if(t[s]==="."&&/[0-9]/.test(t[s+1]))throw new oe(`${u}.${t[s+1]}...: syntax error: invalid arithmetic operator`);if(t[s]==="["){let p=t.slice(s).trim();return{expr:{type:"ArithNumberSubscript",number:u,errorToken:p},pos:t.length}}return{expr:{type:"ArithNumber",value:rr(u)},pos:s}}if(t[s]==="$"&&t[s+1]==="{"){let u=s+2,c=1,f=u;for(;f<t.length&&c>0;)t[f]==="{"?c++:t[f]==="}"&&c--,c>0&&f++;let d=t.slice(u,f),p=f+1;if(t[p]==="#"){let h=p+1;for(;h<t.length&&/[0-9a-zA-Z@_]/.test(t[h]);)h++;let m=t.slice(p+1,h);return{expr:{type:"ArithDynamicBase",baseExpr:d,value:m},pos:h}}if(/[0-9]/.test(t[p])||t[p]==="x"||t[p]==="X"){let h=p;if(t[p]==="x"||t[p]==="X")for(h++;h<t.length&&/[0-9a-fA-F]/.test(t[h]);)h++;else for(;h<t.length&&/[0-9]/.test(t[h]);)h++;let m=t.slice(p,h);return{expr:{type:"ArithDynamicNumber",prefix:d,suffix:m},pos:h}}return s=p,{expr:{type:"ArithBracedExpansion",content:d},pos:s}}if(t[s]==="$"&&s+1<t.length&&/[0-9]/.test(t[s+1])){s++;let u="";for(;s<t.length&&/[0-9]/.test(t[s]);)u+=t[s],s++;return{expr:{type:"ArithVariable",name:u,hasDollarPrefix:!0},pos:s}}if(t[s]==="$"&&s+1<t.length&&/[*@#?\-!$]/.test(t[s+1])){let u=t[s+1];return s+=2,{expr:{type:"ArithSpecialVar",name:u},pos:s}}let l=!1;if(t[s]==="$"&&s+1<t.length&&/[a-zA-Z_]/.test(t[s+1])&&(l=!0,s++),s<t.length&&/[a-zA-Z_]/.test(t[s])){let u="";for(;s<t.length&&/[a-zA-Z0-9_]/.test(t[s]);)u+=t[s],s++;if(t[s]==="["&&!r){s++;let c;if(t[s]==="'"||t[s]==='"'){let d=t[s];for(s++,c="";s<t.length&&t[s]!==d;)c+=t[s],s++;t[s]===d&&s++,s=he(t,s),t[s]==="]"&&s++}let f;if(c===void 0){let{expr:d,pos:p}=hn(e,t,s);f=d,s=p,t[s]==="]"&&s++}if(s=he(t,s),t[s]==="["&&f)return{expr:{type:"ArithDoubleSubscript",array:u,index:f},pos:s};if(!r){for(let d of Tr)if(t.slice(s,s+d.length)===d&&t.slice(s,s+d.length+1)!=="=="){s+=d.length;let{expr:p,pos:h}=e.withDepth(()=>sr(e,t,s));return{expr:{type:"ArithAssignment",operator:d,variable:u,subscript:f,stringKey:c,value:p},pos:h}}}return{expr:{type:"ArithArrayElement",array:u,index:f,stringKey:c},pos:s}}if(s=he(t,s),!r){for(let c of Tr)if(t.slice(s,s+c.length)===c&&t.slice(s,s+c.length+1)!=="=="){s+=c.length;let{expr:f,pos:d}=e.withDepth(()=>sr(e,t,s));return{expr:{type:"ArithAssignment",operator:c,variable:u,value:f},pos:d}}}return{expr:{type:"ArithVariable",name:u,hasDollarPrefix:l},pos:s}}if(t[s]==="#"){let u=s+1;for(;u<t.length&&t[u]!==`
71
- `;)u++;let c=t.slice(s,u).trim()||"#";return{expr:{type:"ArithSyntaxError",errorToken:c,message:`${c}: syntax error: invalid arithmetic operator (error token is "${c}")`},pos:t.length}}return{expr:{type:"ArithNumber",value:0},pos:s}}var Mr=e=>{let t,n="";for(let r=0;r<e.length;r++){let s=e[r];if(s==="\\"&&t==='"'&&r+1<e.length){n+=s+e[r+1],r+=1;continue}if(s==="'"||s==='"'){t===s?t=void 0:t||(t=s),n+=s;continue}if(s==="\\"&&!t&&r+1<e.length){let i=e[r+1];n+=i==="$"||i==="`"?`\\${i}`:i,r+=1;continue}n+=s}return n};function ad(e){let t="",n=0;for(;n<e.length;){let r=e[n];if(r<128){t+=String.fromCharCode(r),n++;continue}if((r&224)===192){if(n+1<e.length&&(e[n+1]&192)===128&&r>=194){let s=(r&31)<<6|e[n+1]&63;t+=String.fromCharCode(s),n+=2;continue}t+=String.fromCharCode(r),n++;continue}if((r&240)===224){if(n+2<e.length&&(e[n+1]&192)===128&&(e[n+2]&192)===128){if(r===224&&e[n+1]<160){t+=String.fromCharCode(r),n++;continue}let s=(r&15)<<12|(e[n+1]&63)<<6|e[n+2]&63;if(s>=55296&&s<=57343){t+=String.fromCharCode(r),n++;continue}t+=String.fromCharCode(s),n+=3;continue}t+=String.fromCharCode(r),n++;continue}if((r&248)===240&&r<=244){if(n+3<e.length&&(e[n+1]&192)===128&&(e[n+2]&192)===128&&(e[n+3]&192)===128){if(r===240&&e[n+1]<144){t+=String.fromCharCode(r),n++;continue}let s=(r&7)<<18|(e[n+1]&63)<<12|(e[n+2]&63)<<6|e[n+3]&63;if(s>1114111){t+=String.fromCharCode(r),n++;continue}t+=String.fromCodePoint(s),n+=4;continue}t+=String.fromCharCode(r),n++;continue}t+=String.fromCharCode(r),n++}return t}function nl(e,t,n){let r=n+1;for(;r<t.length&&/[a-zA-Z0-9_-]/.test(t[r]);)r++;return r}function ni(e,t,n,r,s){let i=1,o=n+1;for(;o<t.length&&i>0;)t[o]===r?i++:t[o]===s&&i--,i>0&&o++;return i===0?o:-1}function mn(e,t,n){let r=n,s=1;for(;r<t.length&&s>0;){let i=t[r];if(i==="\\"&&r+1<t.length){r+=2;continue}if(i==="'"){let o=t.indexOf("'",r+1);if(o!==-1){r=o+1;continue}}if(i==='"'){for(r++;r<t.length&&t[r]!=='"';)t[r]==="\\"&&r+1<t.length?r+=2:r++;r<t.length&&r++;continue}i==="{"?s++:i==="}"&&s--,s>0&&r++}return r}function rl(e,t,n){let r=n,s=!1;for(;r<t.length;){let i=t[r];if(i==="/"&&s||i==="}")break;if(i==="'"){let o=t.indexOf("'",r+1);if(o!==-1){r=o+1,s=!0;continue}}if(i==='"'){for(r++;r<t.length&&t[r]!=='"';)t[r]==="\\"&&r+1<t.length?r+=2:r++;r<t.length&&r++,s=!0;continue}i==="\\"?(r+=2,s=!0):(r++,s=!0)}return r}function sl(e,t,n){let r=n,s="";for(;r<t.length;){let i=t[r];if(i==="*"||i==="?")s+=i,r++;else if(i==="["){let o=ld(t,r);o===-1?(s+=i,r++):(s+=t.slice(r,o+1),r=o+1)}else break}return{pattern:s,endIndex:r}}function ld(e,t){let n=t+1;for(n<e.length&&e[n]==="^"&&n++,n<e.length&&e[n]==="]"&&n++;n<e.length;){let r=e[n];if(r==="\\"&&n+1<e.length){let s=e[n+1];if(s==='"'||s==="'")return-1;n+=2;continue}if(r==="]")return n;if(r==='"'||r==="$"||r==="`")return-1;if(r==="'"){let s=e.indexOf("'",n+1);if(s!==-1){n=s+1;continue}}if(r==="["&&n+1<e.length&&e[n+1]===":"){let s=e.indexOf(":]",n+2);if(s!==-1){n=s+2;continue}}if(r==="["&&n+1<e.length&&(e[n+1]==="."||e[n+1]==="=")){let i=`${e[n+1]}]`,o=e.indexOf(i,n+2);if(o!==-1){n=o+2;continue}}n++}return-1}function il(e,t,n){let r="",s=n;for(;s<t.length&&t[s]!=="'";){let i=t[s];if(i==="\\"&&s+1<t.length)switch(t[s+1]){case"n":r+=`
72
- `,s+=2;break;case"t":r+=" ",s+=2;break;case"r":r+="\r",s+=2;break;case"\\":r+="\\",s+=2;break;case"'":r+="'",s+=2;break;case'"':r+='"',s+=2;break;case"a":r+="\x07",s+=2;break;case"b":r+="\b",s+=2;break;case"e":case"E":r+="\x1B",s+=2;break;case"f":r+="\f",s+=2;break;case"v":r+="\v",s+=2;break;case"x":{let a=[],l=s;for(;l+1<t.length&&t[l]==="\\"&&t[l+1]==="x";){let u=t.slice(l+2,l+4),c=parseInt(u,16);if(!Number.isNaN(c)&&u.length>0)a.push(c),l+=2+u.length;else break}a.length>0?(r+=ad(a),s=l):(r+="\\x",s+=2);break}case"u":{let a=t.slice(s+2,s+6),l=parseInt(a,16);Number.isNaN(l)?(r+="\\u",s+=2):(r+=String.fromCharCode(l),s+=6);break}case"c":{if(s+2<t.length){let l=t[s+2].charCodeAt(0)&31;r+=String.fromCharCode(l),s+=3}else r+="\\c",s+=2;break}case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":{let a="",l=s+1;for(;l<t.length&&l<s+4&&/[0-7]/.test(t[l]);)a+=t[l],l++;let u=parseInt(a,8);r+=String.fromCharCode(u),s=l;break}default:r+=i,s++}else r+=i,s++}return s<t.length&&t[s]==="'"&&s++,{part:T.literal(r),endIndex:s}}function ri(e,t){let n=t.trim();return n===""?{type:"ArithmeticExpression",expression:{type:"ArithNumber",value:0}}:te(e,n)}function tl(e){let t=[],n="",r=0;for(let s=0;s<e.length;s++){let i=e[s];i==="{"?(r++,n+=i):i==="}"?(r--,n+=i):i===","&&r===0?(t.push(n),n=""):n+=i}return t.push(n),t}function ol(e,t,n,r){let s=ni(e,t,n,"{","}");if(s===-1)return null;let i=t.slice(n+1,s),o=i.match(/^(-?\d+)\.\.(-?\d+)(?:\.\.(-?\d+))?$/);if(o)return{part:{type:"BraceExpansion",items:[{type:"Range",start:Number.parseInt(o[1],10),end:Number.parseInt(o[2],10),step:o[3]?Number.parseInt(o[3],10):void 0,startStr:o[1],endStr:o[2]}]},endIndex:s+1};let a=i.match(/^([a-zA-Z])\.\.([a-zA-Z])(?:\.\.(-?\d+))?$/);return a?{part:{type:"BraceExpansion",items:[{type:"Range",start:a[1],end:a[2],step:a[3]?Number.parseInt(a[3],10):void 0}]},endIndex:s+1}:i.includes(",")&&r?{part:{type:"BraceExpansion",items:tl(i).map(c=>e.withDepth(()=>({type:"Word",word:T.word(r(e,c,!1,!1,!1))})))},endIndex:s+1}:i.includes(",")?{part:{type:"BraceExpansion",items:tl(i).map(c=>({type:"Word",word:T.word([T.literal(c)])}))},endIndex:s+1}:null}function si(e,t){let n="";for(let r of t.parts)switch(r.type){case"Literal":n+=r.value;break;case"SingleQuoted":n+=`'${r.value}'`;break;case"Escaped":n+=r.value;break;case"DoubleQuoted":n+='"';for(let s of r.parts)s.type==="Literal"||s.type==="Escaped"?n+=s.value:s.type==="ParameterExpansion"&&(n+=`\${${s.parameter}}`);n+='"';break;case"ParameterExpansion":n+=`\${${r.parameter}}`;break;case"Glob":n+=r.pattern;break;case"TildeExpansion":n+="~",r.user&&(n+=r.user);break;case"BraceExpansion":{n+="{";let s=[];for(let i of r.items)if(i.type==="Range"){let o=i.startStr??String(i.start),a=i.endStr??String(i.end);i.step!==void 0?s.push(`${o}..${a}..${i.step}`):s.push(`${o}..${a}`)}else s.push(si(e,i.word));s.length===1&&r.items[0].type==="Range"?n+=s[0]:n+=s.join(","),n+="}";break}default:n+=r.type}return n}function al(e,t){return{[w.LESS]:"<",[w.GREAT]:">",[w.DGREAT]:">>",[w.LESSAND]:"<&",[w.GREATAND]:">&",[w.LESSGREAT]:"<>",[w.CLOBBER]:">|",[w.TLESS]:"<<<",[w.AND_GREAT]:"&>",[w.AND_DGREAT]:"&>>",[w.DLESS]:"<",[w.DLESSDASH]:"<"}[t]||">"}function ir(e){let t=e.current(),n=t.type;if(n===w.NUMBER){let r=e.peek(1);return t.end!==r.start||e.isProcessSubstitutionStart(1)?!1:Wa.has(r.type)}if(n===w.FD_VARIABLE){let r=e.peek(1);return t.end!==r.start||e.isProcessSubstitutionStart(1)?!1:Va.has(r.type)}return!e.isProcessSubstitutionStart()&&Ba.has(n)}function Br(e){let t=null,n;e.check(w.NUMBER)?t=Number.parseInt(e.advance().value,10):e.check(w.FD_VARIABLE)&&(n=e.advance().value);let r=e.advance(),s=al(e,r.type);if(r.type===w.DLESS||r.type===w.DLESSDASH)return ud(e,t,n,r.type===w.DLESSDASH);e.isWord()||e.error("Expected redirection target");let i=e.parseWord();return T.redirection(s,i,t,n)}function ud(e,t,n,r){e.isWord()||e.error("Expected here-document delimiter");let s=e.advance(),i=s.heredocDelimiter??s.value,o=s.quoted||!1,a=T.redirection(r?"<<-":"<<",T.hereDoc(i,T.word([]),r,o),t,n);return e.addPendingHeredoc(a,i,r,o),a}function oi(e){let t=e.getSourceLine(),n=[],r=null,s=[],i=[];for(;e.check(w.ASSIGNMENT_WORD)||ir(e);)e.checkIterationLimit(),e.check(w.ASSIGNMENT_WORD)?n.push(cd(e)):i.push(Br(e));if(e.isWord())r=e.parseWord();else if(n.length>0&&(e.check(w.DBRACK_START)||e.check(w.DPAREN_START))){let a=e.advance();r=T.word([T.literal(a.value)])}for(;(!e.isStatementEnd()||e.check(w.RBRACE))&&!e.check(w.PIPE,w.PIPE_AMP);)if(e.checkIterationLimit(),ir(e))i.push(Br(e));else if(e.check(w.ASSIGNMENT_WORD)){let a=e.advance(),l=a.value,u=l.endsWith("="),c=l.endsWith("=(");if((u||c)&&(c||e.check(w.LPAREN))){let f=c?l.slice(0,-2):l.slice(0,-1);c||e.expect(w.LPAREN);let d=ii(e);e.expect(w.RPAREN);let p=d.map(m=>si(e,m)),h=`${f}=(${p.join(" ")})`;s.push(e.parseWordFromString(h,!1,!1,!0))}else{let f=e.parseWordFromString(l,a.quoted,a.singleQuoted,!0);s.push(e.parseAdjacentWordParts(f.parts,a.end,Pe.Assignment))}}else if(e.isWord())s.push(e.parseWord());else if(e.check(w.RBRACE)){let a=e.advance();s.push(e.parseWordFromString(a.value,!1,!1))}else if(e.check(w.LBRACE)){let a=e.advance();s.push(e.parseWordFromString(a.value,!1,!1))}else if(e.check(w.DBRACK_END)){let a=e.advance();s.push(e.parseWordFromString(a.value,!1,!1))}else if(e.check(w.LPAREN))e.error("syntax error near unexpected token `('");else break;let o=T.simpleCommand(r,s,n,i);return o.line=t,o}function cd(e){let t=e.expect(w.ASSIGNMENT_WORD),n=t.value,r=n.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);r||e.error(`Invalid assignment: ${n}`);let s=r[0],i,o=s.length;if(n[o]==="["){let f=0,d=o+1;for(;o<n.length;o++)if(n[o]==="[")f++;else if(n[o]==="]"&&(f--,f===0))break;f!==0&&e.error(`Invalid assignment: ${n}`),i=Mr(n.slice(d,o)),o++}let a=n[o]==="+";a&&o++,n[o]!=="="&&e.error(`Invalid assignment: ${n}`),o++;let l=n.slice(o);if(l==="("){let f=ii(e);e.expect(w.RPAREN);let d=i!==void 0?`${s}[${i}]`:s;return T.assignment(d,null,a,f)}if(l===""&&e.check(w.LPAREN)){let f=e.current();if(t.end===f.start){e.advance();let d=ii(e);e.expect(w.RPAREN);let p=i!==void 0?`${s}[${i}]`:s;return T.assignment(p,null,a,d)}}let u=l?e.parseWordFromString(l,t.quoted,t.singleQuoted,!0):null;t.end===e.current().start&&e.isProcessSubstitutionStart()&&(u=e.parseAdjacentWordParts(u?.parts??[],t.end,Pe.Assignment));let c=i!==void 0?`${s}[${i}]`:s;return T.assignment(c,u,a,null)}var fd=new Set([w.AMP,w.PIPE,w.PIPE_AMP,w.SEMICOLON,w.AND_AND,w.OR_OR,w.DSEMI,w.SEMI_AND,w.SEMI_SEMI_AND]);function ii(e){let t=[];for(e.skipNewlines();!e.check(w.RPAREN,w.EOF);)e.checkIterationLimit(),e.isWord()?t.push(e.parseWord()):fd.has(e.current().type)?e.error(`syntax error near unexpected token \`${e.current().value}'`):e.advance(),e.skipNewlines();return t}function ai(e,t){e.expect(w.IF);let n=[],r=e.parseCompoundList();e.expect(w.THEN);let s=e.parseCompoundList();if(s.length===0){let a=e.check(w.FI)?"fi":e.check(w.ELSE)?"else":e.check(w.ELIF)?"elif":"fi";e.error(`syntax error near unexpected token \`${a}'`)}for(n.push({condition:r,body:s});e.check(w.ELIF);){e.advance();let a=e.parseCompoundList();e.expect(w.THEN);let l=e.parseCompoundList();if(l.length===0){let u=e.check(w.FI)?"fi":e.check(w.ELSE)?"else":e.check(w.ELIF)?"elif":"fi";e.error(`syntax error near unexpected token \`${u}'`)}n.push({condition:a,body:l})}let i=null;e.check(w.ELSE)&&(e.advance(),i=e.parseCompoundList(),i.length===0&&e.error("syntax error near unexpected token `fi'")),e.expect(w.FI);let o=t?.skipRedirections?[]:e.parseOptionalRedirections();return T.ifNode(n,i,o)}function li(e,t){let n=e.expect(w.FOR);if(e.check(w.DPAREN_START))return pd(e,t,e.getSourceLine(n));e.isWord()||e.error("Expected variable name in for loop");let s=e.advance().value,i=null;if(e.skipNewlines(),e.check(w.IN))for(e.advance(),i=[];!e.check(w.SEMICOLON,w.NEWLINE,w.DO,w.EOF)&&e.isWord();)i.push(e.parseWord());e.check(w.SEMICOLON)&&e.advance(),e.skipNewlines(),e.expect(w.DO);let o=e.parseCompoundList();e.expect(w.DONE);let a=t?.skipRedirections?[]:e.parseOptionalRedirections();return T.forNode(s,i,o,a)}function pd(e,t,n){e.expect(w.DPAREN_START);let r=null,s=null,i=null,o=["","",""],a=0,l=0;for(;!e.check(w.DPAREN_END,w.EOF);){let f=e.advance();if(f.type===w.SEMICOLON&&l===0){if(a++,a>2)break}else f.value==="("&&l++,f.value===")"&&l--,o[a]+=f.value}e.expect(w.DPAREN_END),o[0].trim()&&(r=te(e,o[0].trim())),o[1].trim()&&(s=te(e,o[1].trim())),o[2].trim()&&(i=te(e,o[2].trim())),e.skipNewlines(),e.check(w.SEMICOLON)&&e.advance(),e.skipNewlines();let u;e.check(w.LBRACE)?(e.advance(),u=e.parseCompoundList(),e.expect(w.RBRACE)):(e.expect(w.DO),u=e.parseCompoundList(),e.expect(w.DONE));let c=t?.skipRedirections?[]:e.parseOptionalRedirections();return{type:"CStyleFor",init:r,condition:s,update:i,body:u,redirections:c,line:n}}function ui(e,t){e.expect(w.WHILE);let n=e.parseCompoundList();e.expect(w.DO);let r=e.parseCompoundList();r.length===0&&e.error("syntax error near unexpected token `done'"),e.expect(w.DONE);let s=t?.skipRedirections?[]:e.parseOptionalRedirections();return T.whileNode(n,r,s)}function ci(e,t){e.expect(w.UNTIL);let n=e.parseCompoundList();e.expect(w.DO);let r=e.parseCompoundList();r.length===0&&e.error("syntax error near unexpected token `done'"),e.expect(w.DONE);let s=t?.skipRedirections?[]:e.parseOptionalRedirections();return T.untilNode(n,r,s)}function fi(e,t){e.expect(w.CASE),e.isWord()||e.error("Expected word after 'case'");let n=e.parseWord();e.skipNewlines(),e.expect(w.IN),e.skipNewlines();let r=[];for(;!e.check(w.ESAC,w.EOF);){e.checkIterationLimit();let i=e.getPos(),o=hd(e);if(o&&r.push(o),e.skipNewlines(),e.getPos()===i&&!o)break}e.expect(w.ESAC);let s=t?.skipRedirections?[]:e.parseOptionalRedirections();return T.caseNode(n,r,s)}function hd(e){e.check(w.LPAREN)&&e.advance();let t=[];for(;e.isWord()&&(t.push(e.parseWord()),e.check(w.PIPE));)e.advance();if(t.length===0)return null;e.expect(w.RPAREN),e.skipNewlines();let n=[];for(;!e.check(w.DSEMI,w.SEMI_AND,w.SEMI_SEMI_AND,w.ESAC,w.EOF);){e.checkIterationLimit(),e.isWord()&&e.peek(1).type===w.RPAREN&&e.error("syntax error near unexpected token `)'"),e.check(w.LPAREN)&&e.peek(1).type===w.WORD&&e.error(`syntax error near unexpected token \`${e.peek(1).value}'`);let s=e.getPos(),i=e.parseStatement();if(i&&n.push(i),e.skipSeparators(!1),e.getPos()===s&&!i)break}let r=";;";return e.check(w.DSEMI)?(e.advance(),r=";;"):e.check(w.SEMI_AND)?(e.advance(),r=";&"):e.check(w.SEMI_SEMI_AND)&&(e.advance(),r=";;&"),T.caseItem(t,n,r)}function di(e,t){e.expect(w.LPAREN);let n=e.parseCompoundList();e.expect(w.RPAREN);let r=t?.skipRedirections?[]:e.parseOptionalRedirections();return T.subshell(n,r)}function pi(e,t){e.expect(w.LBRACE);let n=e.parseCompoundList();e.expect(w.RBRACE);let r=t?.skipRedirections?[]:e.parseOptionalRedirections();return T.group(n,r)}var yd=["-a","-b","-c","-d","-e","-f","-g","-h","-k","-p","-r","-s","-t","-u","-w","-x","-G","-L","-N","-O","-S","-z","-n","-o","-v","-R"],gd=["==","!=","=~","<",">","-eq","-ne","-lt","-le","-gt","-ge","-nt","-ot","-ef"];function ul(e){return e.isWord()||e.check(w.LBRACE)||e.check(w.RBRACE)||e.check(w.ASSIGNMENT_WORD)}function cl(e){if(e.check(w.BANG)&&e.peek(1).type===w.LPAREN){e.advance(),e.advance();let t=1,n="!(";for(;t>0&&!e.check(w.EOF);)if(e.check(w.LPAREN))t++,n+="(",e.advance();else if(e.check(w.RPAREN))t--,t>0&&(n+=")"),e.advance();else if(e.isWord())n+=e.advance().value;else if(e.check(w.PIPE))n+="|",e.advance();else break;return n+=")",e.parseWordFromString(n,!1,!1,!1,!1,!0)}return e.parseWordNoBraceExpansion()}function mi(e){return e.skipNewlines(),wd(e)}function wd(e){let t=fl(e);for(e.skipNewlines();e.check(w.OR_OR);){e.advance(),e.skipNewlines();let n=fl(e);t={type:"CondOr",left:t,right:n},e.skipNewlines()}return t}function fl(e){let t=hi(e);for(e.skipNewlines();e.check(w.AND_AND);){e.advance(),e.skipNewlines();let n=hi(e);t={type:"CondAnd",left:t,right:n},e.skipNewlines()}return t}function hi(e){return e.skipNewlines(),e.check(w.BANG)?(e.advance(),e.skipNewlines(),{type:"CondNot",operand:e.withDepth(()=>hi(e))}):Ed(e)}function Ed(e){if(e.check(w.LPAREN)){e.advance();let t=e.withDepth(()=>mi(e));return e.expect(w.RPAREN),{type:"CondGroup",expression:t}}if(ul(e)){let t=e.current(),n=t.value;if(yd.includes(n)&&!t.quoted){if(e.advance(),e.check(w.DBRACK_END)&&e.error(`Expected operand after ${n}`),ul(e)){let i=e.parseWordNoBraceExpansion();return{type:"CondUnary",operator:n,operand:i}}let s=e.current();e.error(`unexpected argument \`${s.value}' to conditional unary operator`)}let r=e.parseWordNoBraceExpansion();if(e.isWord()&&gd.includes(e.current().value)){let s=e.advance().value,i;return s==="=~"?i=bd(e):s==="=="||s==="!="?i=cl(e):i=e.parseWordNoBraceExpansion(),{type:"CondBinary",operator:s,left:r,right:i}}if(e.check(w.LESS)){e.advance();let s=e.parseWordNoBraceExpansion();return{type:"CondBinary",operator:"<",left:r,right:s}}if(e.check(w.GREAT)){e.advance();let s=e.parseWordNoBraceExpansion();return{type:"CondBinary",operator:">",left:r,right:s}}if(e.isWord()&&e.current().value==="="){e.advance();let s=cl(e);return{type:"CondBinary",operator:"==",left:r,right:s}}return{type:"CondWord",word:r}}e.error("Expected conditional expression")}function bd(e){let t=[],n=0,r=-1,s=e.getInput(),i=()=>e.check(w.DBRACK_END)||e.check(w.AND_AND)||e.check(w.OR_OR)||e.check(w.NEWLINE)||e.check(w.EOF);for(;!i();){let o=e.current(),a=r>=0&&o.start>r;if(n===0&&a)break;if(n>0&&a){let l=s.slice(r,o.start);t.push({type:"Literal",value:l})}if(e.isWord()||e.check(w.ASSIGNMENT_WORD)){let l=e.parseWordForRegex();t.push(...l.parts),r=e.peek(-1).end}else if(e.check(w.LPAREN)){let l=e.advance();t.push({type:"Literal",value:"("}),n++,r=l.end}else if(e.check(w.DPAREN_START)){let l=e.advance();t.push({type:"Literal",value:"(("}),n+=2,r=l.end}else if(e.check(w.DPAREN_END))if(n>=2){let l=e.advance();t.push({type:"Literal",value:"))"}),n-=2,r=l.end}else{if(n===1)break;break}else if(e.check(w.RPAREN))if(n>0){let l=e.advance();t.push({type:"Literal",value:")"}),n--,r=l.end}else break;else if(e.check(w.PIPE)){let l=e.advance();t.push({type:"Literal",value:"|"}),r=l.end}else if(e.check(w.SEMICOLON))if(n>0){let l=e.advance();t.push({type:"Literal",value:";"}),r=l.end}else break;else if(n>0&&e.check(w.LESS)){let l=e.advance();t.push({type:"Literal",value:"<"}),r=l.end}else if(n>0&&e.check(w.GREAT)){let l=e.advance();t.push({type:"Literal",value:">"}),r=l.end}else if(n>0&&e.check(w.DGREAT)){let l=e.advance();t.push({type:"Literal",value:">>"}),r=l.end}else if(n>0&&e.check(w.DLESS)){let l=e.advance();t.push({type:"Literal",value:"<<"}),r=l.end}else if(n>0&&e.check(w.LESSAND)){let l=e.advance();t.push({type:"Literal",value:"<&"}),r=l.end}else if(n>0&&e.check(w.GREATAND)){let l=e.advance();t.push({type:"Literal",value:">&"}),r=l.end}else if(n>0&&e.check(w.LESSGREAT)){let l=e.advance();t.push({type:"Literal",value:"<>"}),r=l.end}else if(n>0&&e.check(w.CLOBBER)){let l=e.advance();t.push({type:"Literal",value:">|"}),r=l.end}else if(n>0&&e.check(w.TLESS)){let l=e.advance();t.push({type:"Literal",value:"<<<"}),r=l.end}else if(n>0&&e.check(w.AMP)){let l=e.advance();t.push({type:"Literal",value:"&"}),r=l.end}else if(n>0&&e.check(w.LBRACE)){let l=e.advance();t.push({type:"Literal",value:"{"}),r=l.end}else if(n>0&&e.check(w.RBRACE)){let l=e.advance();t.push({type:"Literal",value:"}"}),r=l.end}else break}return t.length===0&&e.error("Expected regex pattern after =~"),{type:"Word",parts:t}}function Ad(e){let t="";for(let n=0;n<e.length;n++){let r=e[n],s=e[n+1];if(r!=="\\"||s===void 0){t+=r;continue}"\\[]^-".includes(s)&&(t+="\\"),t+=s,n++}return t}function or(e){return e.length>0?e:[T.literal("")]}function vd(e,t){let n=1,r=t+1;for(;r<e.length&&n>0;){let s=e[r];if(s==="\\"){r+=2;continue}if("@*+?!".includes(s)&&r+1<e.length&&e[r+1]==="("){r++,n++,r++;continue}if(s==="(")n++;else if(s===")"&&(n--,n===0))return r;r++}return-1}function xd(e,t,n){let r=n+1,s=t[r];if("@*#?$!-0123456789".includes(s))return{part:T.parameterExpansion(s),endIndex:r+1};let i="";for(;r<t.length&&/[a-zA-Z0-9_]/.test(t[r]);)i+=t[r],r++;return{part:T.parameterExpansion(i),endIndex:r}}function $d(e,t,n,r=!1){let s=n+2,i=!1;t[s]==="!"&&(i=!0,s++);let o=!1;t[s]==="#"&&!/[}:#%/^,]/.test(t[s+1]||"}")&&(o=!0,s++);let a="",l=t[s];if(/[@*#?$!-]/.test(l)&&!/[a-zA-Z0-9_]/.test(t[s+1]||""))a=l,s++;else for(;s<t.length&&/[a-zA-Z0-9_]/.test(t[s]);)a+=t[s],s++;if(t[s]==="["){let c=ni(e,t,s,"[","]");if(a+=`[${Mr(t.slice(s+1,c))}]`,s=c+1,t[s]==="["){let f=1,d=s;for(;d<t.length&&f>0;)t[d]==="{"?f++:t[d]==="}"&&f--,f>0&&d++;let p=t.slice(n+2,d);return{part:T.parameterExpansion("",{type:"BadSubstitution",text:p}),endIndex:d+1}}}if(a===""&&!i&&!o&&t[s]!=="}"){let c=1,f=s;for(;f<t.length&&c>0;)t[f]==="{"?c++:t[f]==="}"&&c--,c>0&&f++;if(c>0)throw new xe("unexpected EOF while looking for matching '}'",0,0);let d=t.slice(n+2,f);return{part:T.parameterExpansion("",{type:"BadSubstitution",text:d}),endIndex:f+1}}let u=null;if(i){let c=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(c)if(s<t.length&&t[s]!=="}"&&/[:=\-+?#%/^,@]/.test(t[s])){let f=yi(e,t,s,a,r);f.operation?(u={type:"Indirection",innerOp:f.operation},s=f.endIndex):(u={type:"ArrayKeys",array:c[1],star:c[2]==="*"},a="")}else u={type:"ArrayKeys",array:c[1],star:c[2]==="*"},a="";else if(t[s]==="*"||t[s]==="@"&&!/[QPaAEKkuUL]/.test(t[s+1]||"")){let f=t[s];s++,u={type:"VarNamePrefix",prefix:a,star:f==="*"},a=""}else if(s<t.length&&t[s]!=="}"&&/[:=\-+?#%/^,@]/.test(t[s])){let f=yi(e,t,s,a,r);f.operation?(u={type:"Indirection",innerOp:f.operation},s=f.endIndex):u={type:"Indirection"}}else u={type:"Indirection"}}else if(o)if(t[s]===":")for(u={type:"LengthSliceError"};s<t.length&&t[s]!=="}";)s++;else t[s]!=="}"&&/[-+=?]/.test(t[s])?e.error(`\${#${a}${t.slice(s,t.indexOf("}",s))}}: bad substitution`):t[s]==="/"?e.error(`\${#${a}${t.slice(s,t.indexOf("}",s))}}: bad substitution`):u={type:"Length"};if(!u&&s<t.length&&t[s]!=="}"){let c=yi(e,t,s,a,r);u=c.operation,s=c.endIndex}if(s<t.length&&t[s]!=="}"){let c=t[s];if(!/[:\-+=?#%/^,@[]/.test(c)){let f=s;for(;f<t.length&&t[f]!=="}";)f++;let d=t.slice(n,f+1);e.error(`\${${d.slice(2,-1)}}: bad substitution`)}}for(;s<t.length&&t[s]!=="}";)s++;if(s>=t.length)throw new xe("unexpected EOF while looking for matching '}'",0,0);return{part:T.parameterExpansion(a,u),endIndex:s+1}}function yi(e,t,n,r,s=!1){let i=n,o=t[i],a=t[i+1]||"";if(o===":"){let l=a;if("-=?+".includes(l)){i+=2;let S=mn(e,t,i),y=t.slice(i,S),g=e.withDepth(()=>qt(e,y,!1,!1,!0,!1,s,!1,!1,!0)),b=T.word(or(g));if(l==="-")return{operation:{type:"DefaultValue",word:b,checkEmpty:!0},endIndex:S};if(l==="=")return{operation:{type:"AssignDefault",word:b,checkEmpty:!0},endIndex:S};if(l==="?")return{operation:{type:"ErrorIfUnset",word:b,checkEmpty:!0},endIndex:S};if(l==="+")return{operation:{type:"UseAlternative",word:b,checkEmpty:!0},endIndex:S}}i++;let u=mn(e,t,i),c=t.slice(i,u),f=-1,d=0,p=0;for(let E=0;E<c.length;E++){let S=c[E];if(S==="("||S==="[")d++;else if(S===")"||S==="]")d--;else if(S==="?"&&d===0)p++;else if(S===":"&&d===0)if(p>0)p--;else{f=E;break}}let h=f>=0?c.slice(0,f):c,m=f>=0?c.slice(f+1):null;return{operation:{type:"Substring",offset:ri(e,h),length:m!==null?ri(e,m):null},endIndex:u}}if("-=?+".includes(o)){i++;let l=mn(e,t,i),u=t.slice(i,l),c=e.withDepth(()=>qt(e,u,!1,!1,!0,!1,s,!1,!1,!0)),f=T.word(or(c));if(o==="-")return{operation:{type:"DefaultValue",word:f,checkEmpty:!1},endIndex:l};if(o==="=")return{operation:{type:"AssignDefault",word:f,checkEmpty:!1},endIndex:l};if(o==="?")return{operation:{type:"ErrorIfUnset",word:u?f:null,checkEmpty:!1},endIndex:l};if(o==="+")return{operation:{type:"UseAlternative",word:f,checkEmpty:!1},endIndex:l}}if(o==="#"||o==="%"){let l=a===o,u=o==="#"?"prefix":"suffix";i+=l?2:1;let c=mn(e,t,i),f=t.slice(i,c),d=e.withDepth(()=>qt(e,f,!1,!1,!1));return{operation:{type:"PatternRemoval",pattern:T.word(or(d)),side:u,greedy:l},endIndex:c}}if(o==="/"){let l=a==="/";i+=l?2:1;let u=null;t[i]==="#"?(u="start",i++):t[i]==="%"&&(u="end",i++);let c;u!==null&&(t[i]==="/"||t[i]==="}")?c=i:c=rl(e,t,i);let f=t.slice(i,c),d=e.withDepth(()=>qt(e,f,!1,!1,!1)),p=T.word(or(d)),h=null,m=c;if(t[c]==="/"){let E=c+1,S=mn(e,t,E),y=t.slice(E,S),g=e.withDepth(()=>qt(e,y,!1,!1,!1));h=T.word(or(g)),m=S}return{operation:{type:"PatternReplacement",pattern:p,replacement:h,all:l,anchor:u},endIndex:m}}if(o==="^"||o===","){let l=a===o,u=o==="^"?"upper":"lower";i+=l?2:1;let c=mn(e,t,i),f=t.slice(i,c),d=f?T.word([T.literal(f)]):null;return{operation:{type:"CaseModification",direction:u,all:l,pattern:d},endIndex:c}}return o==="@"&&/[QPaAEKkuUL]/.test(a)?{operation:{type:"Transform",operator:a},endIndex:i+2}:{operation:null,endIndex:i}}function gi(e,t,n,r=!1){let s=n+1;if(s>=t.length)return{part:T.literal("$"),endIndex:s};let i=t[s];if(i==="("&&t[s+1]==="(")return e.isDollarDparenSubshell(t,n)?e.parseCommandSubstitution(t,n):e.parseArithmeticExpansion(t,n);if(i==="["){let o=1,a=s+1;for(;a<t.length&&o>0;)t[a]==="["?o++:t[a]==="]"&&o--,o>0&&a++;if(o===0){let l=t.slice(s+1,a),u=te(e,l);return{part:T.arithmeticExpansion(u),endIndex:a+1}}}return i==="("?e.parseCommandSubstitution(t,n):i==="{"?$d(e,t,n,r):/[a-zA-Z_0-9@*#?$!-]/.test(i)?xd(e,t,n):{part:T.literal("$"),endIndex:s}}function dl(e,t){let n=[],r=0,s="",i=()=>{s&&(n.push(T.literal(s)),s="")};for(;r<t.length;){let o=t[r];if(o==="\\"&&r+1<t.length){let a=t[r+1];if(a==="$"||a==="`"||a==='"'||a==="\\"){s+=a,r+=2;continue}s+=o,r++;continue}if(o==="$"){i();let{part:a,endIndex:l}=gi(e,t,r,!0);a&&n.push(a),r=l;continue}if(o==="`"){i();let{part:a,endIndex:l}=e.parseBacktickSubstitution(t,r,!0);n.push(a),r=l;continue}s+=o,r++}return i(),n}function kd(e,t,n){let r=[],s=n,i="",o=()=>{i&&(r.push(T.literal(i)),i="")};for(;s<t.length&&t[s]!=='"';){let a=t[s];if(a==="\\"&&s+1<t.length){let l=t[s+1];if('"\\$`\n'.includes(l)){i+=l,s+=2;continue}i+=a,s++;continue}if(a==="$"){o();let{part:l,endIndex:u}=gi(e,t,s,!0);l&&r.push(l),s=u;continue}if(a==="`"){o();let{part:l,endIndex:u}=e.parseBacktickSubstitution(t,s,!0);r.push(l),s=u;continue}i+=a,s++}return o(),{part:T.doubleQuoted(r),endIndex:s}}function qt(e,t,n=!1,r=!1,s=!1,i=!1,o=!1,a=!1,l=!1,u=!1,c=!0){if(r)return[T.singleQuoted(t)];if(n){let m=dl(e,t);return[T.doubleQuoted(m)]}if(t.length>=2&&t[0]==='"'&&t[t.length-1]==='"'){let m=t.slice(1,-1),E=!1;for(let S=0;S<m.length;S++){if(m[S]==='"'){E=!0;break}m[S]==="\\"&&S+1<m.length&&S++}if(!E){let S=dl(e,m);return[T.doubleQuoted(S)]}}let f=[],d=0,p="",h=()=>{p&&(f.push(T.literal(p)),p="")};for(;d<t.length;){let m=t[d];if(m==="\\"&&d+1<t.length){let E=t[d+1];if(l){h(),f.push(T.escaped(E)),d+=2;continue}if(!i&&!o){E!==`
73
- `&&(h(),f.push(T.escaped(E))),d+=2;continue}let S=i?E==="$"||E==="`"||E===`
74
- `:E==="$"||E==="`"||E==='"'||E==="'"||E===`
75
- `||u&&E==="}",y=o?"*?[]\\".includes(E):"*?[]\\(){}.^+".includes(E);S?E!==`
76
- `&&(p+=E):y?(h(),f.push(T.escaped(E))):p+=`\\${E}`,d+=2;continue}if(m==="'"&&!o&&!i){h();let E=t.indexOf("'",d+1);if(E===-1){p+=t.slice(d);break}f.push(T.singleQuoted(t.slice(d+1,E))),d=E+1;continue}if(m==='"'&&!i){h();let{part:E,endIndex:S}=kd(e,t,d+1);f.push(E),d=S+1;continue}if(m==="$"&&t[d+1]==="'"){h();let{part:E,endIndex:S}=il(e,t,d+2);f.push(E),d=S;continue}if(m==="$"){h();let{part:E,endIndex:S}=gi(e,t,d);E&&f.push(E),d=S;continue}if(m==="`"){h();let{part:E,endIndex:S}=e.parseBacktickSubstitution(t,d);f.push(E),d=S;continue}if((m==="<"||m===">")&&t[d+1]==="("&&!i&&!o){h();let{part:E,endIndex:S}=e.parseProcessSubstitutionFromString(t,d);f.push(E),d=S;continue}if(m==="~"){let E=d>0?t[d-1]:"";if(d===0&&c||E==="="||s&&E===":"){let y=nl(e,t,d),g=t[y];if(g===void 0||g==="/"||g===":"){h();let b=t.slice(d+1,y)||null;f.push({type:"TildeExpansion",user:b}),d=y;continue}}}if("@*+?!".includes(m)&&d+1<t.length&&t[d+1]==="("){let E=vd(t,d+1);if(E!==-1){h();let S=t.slice(d,E+1);f.push({type:"Glob",pattern:S}),d=E+1;continue}}if(m==="*"||m==="?"||m==="["){h();let{pattern:E,endIndex:S}=sl(e,t,d);f.push({type:"Glob",pattern:l?Ad(E):E}),d=S;continue}if(m==="{"&&!s&&!a&&!i){let E=ol(e,t,d,qt);if(E){h(),f.push(E.part),d=E.endIndex;continue}}p+=m,d++}return h(),f}var j=class e{tokens=[];pos=0;pendingHeredocs=[];parseBudget;ownsParseBudget;_input="";processLineState;constructor(t){this.parseBudget=t??new Lr,this.ownsParseBudget=t===void 0}getInput(){return this._input}checkIterationLimit(){let t=this.current();this.parseBudget.chargeIteration(t?.line??1,t?.column??1)}enterDepth(){let t=this.current();return this.parseBudget.enter(t?.line??1,t?.column??1)}withDepth(t){let n=this.enterDepth();try{return t()}finally{n()}}parse(t,n){this.ownsParseBudget&&this.parseBudget.reset();let r=this.ownsParseBudget?void 0:this.enterDepth();try{if(t.length>Js)throw new xe(`Input too large: ${t.length} bytes exceeds limit of ${Js}`,1,1);this._input=t,this.processLineState=void 0;let s=new _r(t,n);if(this.tokens=s.tokenize(),this.tokens.length>nr)throw new xe(`Too many tokens: ${this.tokens.length} exceeds limit of ${nr}`,1,1);return this.pos=0,this.pendingHeredocs=[],this.parseBudget.chargeTokens(this.tokens.length),this.parseScript()}finally{r?.()}}parseTokens(t){this.ownsParseBudget&&this.parseBudget.reset();let n=this.ownsParseBudget?void 0:this.enterDepth();try{return this.tokens=t,this.pos=0,this.pendingHeredocs=[],this.processLineState=void 0,this.parseBudget.chargeTokens(t.length),this.parseScript()}finally{n?.()}}current(){return this.tokens[this.pos]||this.tokens[this.tokens.length-1]}peek(t=0){return this.tokens[this.pos+t]||this.tokens[this.tokens.length-1]}advance(){let t=this.current();return this.pos<this.tokens.length-1&&this.pos++,t}getPos(){return this.pos}getSourceLine(t=this.current()){let n=this.processLineState;return n?(n.currentPhysicalLine===void 0?n.currentPhysicalLine=t.line:t.line>n.currentPhysicalLine&&(n.currentPhysicalLine=t.line,n.currentLogicalLine+=1),n.currentLogicalLine):t.line}check(t,n,r,s,...i){let o=this.tokens[this.pos]?.type;return o===t||n!==void 0&&o===n||r!==void 0&&o===r||s!==void 0&&o===s?!0:i.length>0?i.includes(o):!1}expect(t,n){if(this.check(t))return this.advance();let r=this.current();throw new xe(n||`Expected ${t}, got ${r.type}`,r.line,r.column,r)}error(t){let n=this.current();throw new xe(t,n.line,n.column,n)}skipNewlines(){for(;this.check(w.NEWLINE,w.COMMENT);)this.check(w.NEWLINE)?(this.advance(),this.processHeredocs()):this.advance()}skipSeparators(t=!0){for(;;){if(this.check(w.NEWLINE)){this.advance(),this.processHeredocs();continue}if(this.check(w.SEMICOLON,w.COMMENT)){this.advance();continue}if(t&&this.check(w.DSEMI,w.SEMI_AND,w.SEMI_SEMI_AND)){this.advance();continue}break}}addPendingHeredoc(t,n,r,s){this.pendingHeredocs.push({redirect:t,delimiter:n,stripTabs:r,quoted:s})}processHeredocs(){for(let t of this.pendingHeredocs)if(this.check(w.HEREDOC_CONTENT)){let n=this.advance(),r;t.quoted?r=T.word([T.literal(n.value)]):r=this.parseWordFromString(n.value,!1,!1,!1,!0),t.redirect.target=T.hereDoc(t.delimiter,r,t.stripTabs,t.quoted,n.heredocTerminated??!1)}this.pendingHeredocs=[]}isStatementEnd(){return this.check(w.EOF,w.NEWLINE,w.SEMICOLON,w.AMP,w.AND_AND,w.OR_OR,w.RPAREN,w.RBRACE,w.DSEMI,w.SEMI_AND,w.SEMI_SEMI_AND)}isCommandStart(){let t=this.current().type;return this.isWord()||t===w.ASSIGNMENT_WORD||t===w.FD_VARIABLE||t===w.LPAREN||t===w.LBRACE||t===w.DPAREN_START||t===w.DBRACK_START||ir(this)}parseScript(){let t=[],r=0;for(this.skipNewlines();!this.check(w.EOF);){r++,r>1e4&&this.error("Parser stuck: too many iterations (>10000)");let s=this.checkUnexpectedToken();if(s){t.push(s),this.skipSeparators(!1);continue}let i=this.pos,o=this.parseStatement();o&&t.push(o),this.check(w.HEREDOC_CONTENT)&&this.processHeredocs(),this.skipSeparators(!1),this.check(w.DSEMI,w.SEMI_AND,w.SEMI_SEMI_AND)&&this.error(`syntax error near unexpected token \`${this.current().value}'`),this.pos===i&&!this.check(w.EOF)&&this.error(`syntax error near unexpected token \`${this.current().value}'`)}return T.script(t)}checkUnexpectedToken(){let t=this.current().type,n=this.current().value;if(this.currentTokenJoinsProcessSubstitution())return null;if((t===w.DO||t===w.DONE||t===w.THEN||t===w.ELSE||t===w.ELIF||t===w.FI||t===w.ESAC)&&this.error(`syntax error near unexpected token \`${n}'`),t===w.RBRACE||t===w.RPAREN){let r=`syntax error near unexpected token \`${n}'`;return this.advance(),T.statement([T.pipeline([T.simpleCommand(null,[],[],[])])],[],!1,{message:r,token:n})}return(t===w.DSEMI||t===w.SEMI_AND||t===w.SEMI_SEMI_AND)&&this.error(`syntax error near unexpected token \`${n}'`),t===w.SEMICOLON&&this.error(`syntax error near unexpected token \`${n}'`),(t===w.AMP||t===w.AND_AND||t===w.OR_OR||t===w.PIPE||t===w.PIPE_AMP)&&this.error(`syntax error near unexpected token \`${n}'`),null}parseStatement(){if(this.skipNewlines(),!this.isCommandStart())return null;let t=this.current().start,n=[],r=[],s=!1,i=this.parsePipeline();for(n.push(i);this.check(w.AND_AND,w.OR_OR);){let l=this.advance();r.push(l.type===w.AND_AND?"&&":"||"),this.skipNewlines();let u=this.parsePipeline();n.push(u)}this.check(w.AMP)&&(this.advance(),s=!0);let o=this.pos>0?this.tokens[this.pos-1].end:t,a=this._input.slice(t,o);return T.statement(n,r,s,void 0,a)}parseTimePrefix(){if(!this.check(w.TIME)||this.currentTokenJoinsProcessSubstitution())return;this.advance();let t=!1;return this.check(w.WORD,w.NAME)&&this.current().value==="-p"&&(this.advance(),t=!0),t}parsePipeline(){let t=!1,n=!1,r=0;for(;this.check(w.BANG)&&!this.currentTokenJoinsProcessSubstitution();)this.advance(),r++;if(r===0){let l=this.parseTimePrefix();if(l!==void 0)for(t=!0,n=l;this.check(w.BANG)&&!this.currentTokenJoinsProcessSubstitution();)this.advance(),r++}let s=r%2===1,i=[],o=[],a=this.parseCommand();for(i.push(a);this.check(w.PIPE,w.PIPE_AMP);){let l=this.advance();this.skipNewlines(),o.push(l.type===w.PIPE_AMP);let u=this.parseCommand();i.push(u)}return T.pipeline(i,s,t,n,o.length>0?o:void 0)}parseCommand(){if(this.currentTokenJoinsProcessSubstitution())return oi(this);let t=this.current();switch(t.type){case w.IF:return ai(this);case w.FOR:return li(this);case w.WHILE:return ui(this);case w.UNTIL:return ci(this);case w.CASE:return fi(this);case w.LPAREN:return di(this);case w.LBRACE:return pi(this);case w.DPAREN_START:return this.dparenClosesWithSpacedParens()?this.parseNestedSubshellsFromDparen():this.parseArithmeticCommand();case w.DBRACK_START:return this.parseConditionalCommand();case w.FUNCTION:return this.parseFunctionDef();case w.TIME:break;case w.BANG:this.error(`syntax error near unexpected token \`${t.value}'`);break;default:Ys(t.type)&&this.error(`syntax error near unexpected token \`${t.value}'`)}return this.check(w.NAME,w.WORD)&&this.peek(1).type===w.LPAREN&&this.peek(2).type===w.RPAREN?this.parseFunctionDef():oi(this)}dparenClosesWithSpacedParens(){let t=1,n=1;for(;n<this.tokens.length-this.pos;){let r=this.peek(n);if(r.type===w.EOF)return!1;if(r.type===w.DPAREN_START||r.type===w.LPAREN)t++;else if(r.type===w.DPAREN_END){if(t-=2,t<=0)return!1}else if(r.type===w.RPAREN&&(t--,t===0&&this.peek(n+1).type===w.RPAREN))return!0;n++}return!1}parseNestedSubshellsFromDparen(){this.advance();let t=this.parseCompoundList();this.expect(w.RPAREN),this.expect(w.RPAREN);let n=this.parseOptionalRedirections(),r=T.subshell(t,[]);return T.subshell([T.statement([T.pipeline([r],!1,!1,!1)])],n)}isWord(){return this.isWordToken(Pe.Default)||this.isProcessSubstitutionStart()||this.currentTokenJoinsProcessSubstitution()}isWordToken(t){let n=this.current().type;return n===w.WORD||n===w.NAME||n===w.NUMBER||Ys(n)||n===w.BANG||n===w.ASSIGNMENT_WORD&&(t&Pe.Regex)!==0}isProcessSubstitutionStart(t=0){let n=this.peek(t),r=this.peek(t+1);return(n.type===w.LESS||n.type===w.GREAT)&&r.type===w.LPAREN&&n.end===r.start}currentTokenJoinsProcessSubstitution(){return this.current().type===w.COMMENT||!this.isAdjacentWordToken(Pe.Default)?!1:this.current().end===this.peek(1).start&&this.isProcessSubstitutionStart(1)}isAdjacentWordToken(t){let n=this.current().type;return this.isWordToken(t)||n===w.ASSIGNMENT_WORD||n===w.COMMENT||n===w.LBRACE||n===w.RBRACE||n===w.DBRACK_START||n===w.DBRACK_END||n===w.FD_VARIABLE}parseWord(t=Pe.Default){if(this.isProcessSubstitutionStart())return this.parseAdjacentWordParts([],this.current().start,t);let n=this.advance(),r=this.parseWordToken(n,t);return this.parseAdjacentWordParts(r.parts,n.end,t)}parseAdjacentWordParts(t,n,r=Pe.Default){for(;n===this.current().start;){if(this.isProcessSubstitutionStart()){t.push(this.parseProcessSubstitution()),n=this.tokens[this.pos-1].end;continue}if(!this.isAdjacentWordToken(r))break;let s=this.advance();t.push(...this.parseWordToken(s,r,t.length===0).parts),n=s.end}return T.word(t)}parseWordNoBraceExpansion(){return this.parseWord(Pe.NoBraceExpansion)}parseWordForRegex(){return this.parseWord(Pe.NoBraceExpansion|Pe.Regex)}parseWordToken(t,n,r=!0){return t.type===w.LBRACE||t.type===w.RBRACE||t.type===w.DBRACK_START||t.type===w.DBRACK_END||t.type===w.FD_VARIABLE?T.word([T.literal(t.type===w.FD_VARIABLE?`{${t.value}}`:t.value)]):this.parseWordFromString(t.value,t.quoted,t.singleQuoted,(n&Pe.Assignment)!==0,!1,(n&Pe.NoBraceExpansion)!==0,(n&Pe.Regex)!==0,r)}parseWordFromString(t,n=!1,r=!1,s=!1,i=!1,o=!1,a=!1,l=!0){let u=qt(this,t,n,r,s,i,!1,o,a,!1,l);return T.word(u)}parseCommandSubstitution(t,n){return Ia(t,n,()=>new e(this.parseBudget),r=>this.error(r))}parseProcessSubstitutionFromString(t,n){return Oa(t,n,()=>new e(this.parseBudget),r=>this.error(r))}parseProcessSubstitution(){let t=this.advance();this.expect(w.LPAREN);let n=this.processLineState,r=this.getSourceLine(t);this.processLineState={currentLogicalLine:r};let s;try{s=T.script(this.parseCompoundList())}finally{this.processLineState=n}return this.check(w.EOF)&&this.error("unexpected EOF while looking for matching `)'"),this.expect(w.RPAREN),T.processSubstitution(s,t.type===w.LESS?"input":"output")}parseBacktickSubstitution(t,n,r=!1){return _a(t,n,r,()=>new e(this.parseBudget),s=>this.error(s))}isDollarDparenSubshell(t,n){return Ra(t,n)}parseArithmeticExpansion(t,n){let r=n+3,s=1,i=0,o=r;for(;o<t.length-1&&s>0;)t[o]==="$"&&t[o+1]==="("?t[o+2]==="("?(s++,o+=3):(i++,o+=2):t[o]==="("&&t[o+1]==="("?(s++,o+=2):t[o]===")"&&t[o+1]===")"?i>0?(i--,o++):(s--,s>0&&(o+=2)):t[o]==="("?(i++,o++):(t[o]===")"&&i>0&&i--,o++);let a=t.slice(r,o),l=this.parseArithmeticExpression(a);return{part:T.arithmeticExpansion(l),endIndex:o+2}}parseArithmeticCommand(){let t=this.expect(w.DPAREN_START),n="",r=1,s=0,i=!1,o=!1;for(;r>0&&!this.check(w.EOF);){if(i){if(i=!1,s>0){s--,n+=")";continue}if(this.check(w.RPAREN)){r--,o=!0,this.advance();continue}if(this.check(w.DPAREN_END)){r--,o=!0;continue}n+=")";continue}if(this.check(w.DPAREN_START))r++,n+="((",this.advance();else if(this.check(w.DPAREN_END))s>=2?(s-=2,n+="))",this.advance()):s===1?(s--,n+=")",i=!0,this.advance()):(r--,o=!0,r>0&&(n+="))"),this.advance());else if(this.check(w.LPAREN))s++,n+="(",this.advance();else if(this.check(w.RPAREN))s>0&&s--,n+=")",this.advance();else{let u=this.current().value,c=n.length>0?n[n.length-1]:"";n.length>0&&!n.endsWith(" ")&&!(u==="="&&/[|&^+\-*/%<>]$/.test(n))&&!(u==="<"&&c==="<")&&!(u===">"&&c===">")&&(n+=" "),n+=u,this.advance()}}o||this.expect(w.DPAREN_END);let a=this.parseArithmeticExpression(n.trim()),l=this.parseOptionalRedirections();return T.arithmeticCommand(a,l,this.getSourceLine(t))}parseConditionalCommand(){let t=this.expect(w.DBRACK_START),n=mi(this);this.expect(w.DBRACK_END);let r=this.parseOptionalRedirections();return T.conditionalCommand(n,r,this.getSourceLine(t))}parseFunctionDef(){let t;if(this.check(w.FUNCTION)){if(this.advance(),this.check(w.NAME)||this.check(w.WORD))t=this.advance().value;else{let s=this.current();throw new xe("Expected function name",s.line,s.column,s)}this.check(w.LPAREN)&&(this.advance(),this.expect(w.RPAREN))}else t=this.advance().value,t.includes("$")&&this.error(`\`${t}': not a valid identifier`),this.expect(w.LPAREN),this.expect(w.RPAREN);this.skipNewlines();let n=this.parseCompoundCommandBody({forFunctionBody:!0}),r=this.parseOptionalRedirections();return T.functionDef(t,n,r)}parseCompoundCommandBody(t){let n=t?.forFunctionBody;if(this.check(w.LBRACE))return pi(this,{skipRedirections:n});if(this.check(w.LPAREN))return di(this,{skipRedirections:n});if(this.check(w.IF))return ai(this,{skipRedirections:n});if(this.check(w.FOR))return li(this,{skipRedirections:n});if(this.check(w.WHILE))return ui(this,{skipRedirections:n});if(this.check(w.UNTIL))return ci(this,{skipRedirections:n});if(this.check(w.CASE))return fi(this,{skipRedirections:n});this.error("Expected compound command for function body")}parseCompoundList(){let t=this.enterDepth();try{let n=[];for(this.skipNewlines();(this.currentTokenJoinsProcessSubstitution()||!this.check(w.EOF,w.FI,w.ELSE,w.ELIF,w.THEN,w.DO,w.DONE,w.ESAC,w.RPAREN,w.RBRACE,w.DSEMI,w.SEMI_AND,w.SEMI_SEMI_AND))&&this.isCommandStart();){this.checkIterationLimit();let r=this.pos,s=this.parseStatement();if(s&&n.push(s),this.skipSeparators(),this.pos===r&&!s)break}return n}finally{t()}}parseOptionalRedirections(){let t=[];for(;ir(this);){this.checkIterationLimit();let n=this.pos;if(t.push(Br(this)),this.pos===n)break}return t}parseArithmeticExpression(t){return te(this,t)}};function dt(e,t){return new j().parse(e,t)}function pl(e){return gn(e)}function gn(e){return e.statements.map(hl).join(`
77
- `)}function hl(e){let t=[];for(let r=0;r<e.pipelines.length;r++)t.push(Cd(e.pipelines[r])),r<e.operators.length&&t.push(e.operators[r]);let n=t.join(" ");return e.background&&(n+=" &"),n}function Cd(e){let t=[];e.timed&&t.push(e.timePosix?"time -p":"time"),e.negated&&t.push("!");let n=[];for(let s=0;s<e.commands.length;s++)if(n.push(ml(e.commands[s])),s<e.commands.length-1){let i=e.pipeStderr?.[s];n.push(i?"|&":"|")}return(t.length>0?`${t.join(" ")} `:"")+n.join(" ")}function ml(e){switch(e.type){case"SimpleCommand":return Nd(e);case"If":return Md(e);case"For":return Bd(e);case"CStyleFor":return Wd(e);case"While":return Vd(e);case"Until":return zd(e);case"Case":return qd(e);case"Subshell":return jd(e);case"Group":return Gd(e);case"ArithmeticCommand":return Hd(e);case"ConditionalCommand":return Zd(e);case"FunctionDef":return Qd(e);default:{let t=e;throw new Error(`Unsupported command type: ${t.type}`)}}}function Nd(e){let t=[];for(let n of e.assignments)t.push(Rd(n));e.name&&t.push(Se(e.name));for(let n of e.args)t.push(Se(n));for(let n of e.redirections)t.push(wl(n));return t.join(" ")}function Rd(e){let t=e.append?"+=":"=";if(e.array){let n=e.array.map(Se).join(" ");return`${e.name}${t}(${n})`}return e.value?`${e.name}${t}${Se(e.value)}`:`${e.name}${t}`}function Se(e){return e.parts.map(t=>Wr(t,!1)).join("")}function Ut(e){return e.parts.map(t=>Wr(t,!0)).join("")}function Wr(e,t){switch(e.type){case"Literal":return t?Id(e.value):Dd(e.value);case"SingleQuoted":return`'${e.value}'`;case"DoubleQuoted":return`"${e.parts.map(n=>Wr(n,!0)).join("")}"`;case"Escaped":return`\\${e.value}`;case"ParameterExpansion":return yl(e);case"CommandSubstitution":return e.legacy?`\`${gn(e.body)}\``:`$(${gn(e.body)})`;case"ArithmeticExpansion":return`$((${fe(e.expression.expression)}))`;case"ProcessSubstitution":return e.direction==="input"?`<(${gn(e.body)})`:`>(${gn(e.body)})`;case"BraceExpansion":return Td(e);case"TildeExpansion":return e.user!==null?`~${e.user}`:"~";case"Glob":return e.pattern;default:{let n=e;throw new Error(`Unsupported word part type: ${n.type}`)}}}function Dd(e){return e.replace(/[\s\\'"`!|&;()<>{}[\]*?~#]/g,"\\$&")}function Id(e){return e.replace(/[$`"\\]/g,"\\$&")}function Od(e,t){return e.parts.map(n=>_d(n,t)).join("")}function _d(e,t){switch(e.type){case"Literal":return t?e.value:e.value.replace(/[$`]/g,"\\$&");case"Escaped":return`\\${e.value}`;case"ParameterExpansion":return yl(e);case"CommandSubstitution":return e.legacy?`\`${gn(e.body)}\``:`$(${gn(e.body)})`;case"ArithmeticExpansion":return`$((${fe(e.expression.expression)}))`;default:return Wr(e,!1)}}function yl(e){return e.operation?`\${${gl(e.parameter,e.operation)}}`:Ld(e.parameter)?`\${${e.parameter}}`:`$${e.parameter}`}function Ld(e){return!(/^[?#@*$!\-0-9]$/.test(e)||/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e))}function gl(e,t){switch(t.type){case"Length":return`#${e}`;case"LengthSliceError":return`#${e}:`;case"BadSubstitution":return t.text;case"DefaultValue":return`${e}${t.checkEmpty?":":""}-${Ut(t.word)}`;case"AssignDefault":return`${e}${t.checkEmpty?":":""}=${Ut(t.word)}`;case"ErrorIfUnset":return`${e}${t.checkEmpty?":":""}?${t.word?Ut(t.word):""}`;case"UseAlternative":return`${e}${t.checkEmpty?":":""}+${Ut(t.word)}`;case"Substring":{let n=fe(t.offset.expression);return t.length?`${e}:${n}:${fe(t.length.expression)}`:`${e}:${n}`}case"PatternRemoval":{let n=t.side==="prefix"?"#":"%",r=t.greedy?`${n}${n}`:n;return`${e}${r}${Ut(t.pattern)}`}case"PatternReplacement":{let n="/";t.all?n="//":t.anchor==="start"?n="/#":t.anchor==="end"&&(n="/%");let r=t.replacement?`/${Ut(t.replacement)}`:"";return`${e}${n}${Ut(t.pattern)}${r}`}case"CaseModification":{let n=t.direction==="upper"?"^":",",r=t.all?`${n}${n}`:n,s=t.pattern?Ut(t.pattern):"";return`${e}${r}${s}`}case"Transform":return`${e}@${t.operator}`;case"Indirection":return t.innerOp?`!${gl(e,t.innerOp)}`:`!${e}`;case"ArrayKeys":return`!${t.array}[${t.star?"*":"@"}]`;case"VarNamePrefix":return`!${t.prefix}${t.star?"*":"@"}`;default:{let n=t;throw new Error(`Unsupported parameter operation type: ${n.type}`)}}}function Td(e){return`{${e.items.map(Fd).join(",")}}`}function Fd(e){if(e.type==="Word")return Se(e.word);let t=e.startStr??String(e.start),n=e.endStr??String(e.end);return e.step!==void 0?`${t}..${n}..${e.step}`:`${t}..${n}`}function wl(e){let t=e.fdVariable?`{${e.fdVariable}}`:e.fd!==null?String(e.fd):"";if(e.operator==="<<"||e.operator==="<<-"){let n=e.target;if(n.terminated===!1)throw new Error("Cannot serialize an unterminated here-document");let r=n.quoted?`'${n.delimiter}'`:n.delimiter,s=Od(n.content,n.quoted);return`${t}${e.operator}${r}
78
- ${s}${n.delimiter}`}return e.operator==="<<<"?`${t}<<< ${Se(e.target)}`:e.operator==="&>"||e.operator==="&>>"?`${e.operator} ${Se(e.target)}`:`${t}${e.operator} ${Se(e.target)}`}function pt(e){return e.length===0?"":` ${e.map(wl).join(" ")}`}function st(e){return e.map(hl).join(`
79
- `)}function Md(e){let t=[];for(let n=0;n<e.clauses.length;n++){let r=e.clauses[n],s=n===0?"if":"elif";t.push(`${s} ${st(r.condition)}; then
80
- ${st(r.body)}`)}return e.elseBody&&t.push(`else
81
- ${st(e.elseBody)}`),`${t.join(`
68
+ `);)f=!0,c++;if(f&&c<r&&n[c]===")")return!0}if(i===0)return!1;s++;continue}if(i===1&&(l==="|"&&s+1<r&&n[s+1]==="|"||l==="&"&&s+1<r&&n[s+1]==="&"||l==="|"&&s+1<r&&n[s+1]!=="|"))return!0;s++}return!1}};var ti=1e6,rr=1e5,ad=1e6,za=200,Pe;(function(e){e[e.Default=0]="Default",e[e.Assignment=1]="Assignment",e[e.NoBraceExpansion=2]="NoBraceExpansion",e[e.Regex=4]="Regex"})(Pe||(Pe={}));var qa=new Set([g.LESS,g.GREAT,g.DLESS,g.DGREAT,g.LESSAND,g.GREATAND,g.LESSGREAT,g.DLESSDASH,g.CLOBBER,g.TLESS,g.AND_GREAT,g.AND_DGREAT]),Ua=new Set([g.LESS,g.GREAT,g.DLESS,g.DGREAT,g.LESSAND,g.GREATAND,g.LESSGREAT,g.DLESSDASH,g.CLOBBER,g.TLESS]),ja=new Set([g.LESS,g.GREAT,g.DLESS,g.DGREAT,g.LESSAND,g.GREATAND,g.LESSGREAT,g.DLESSDASH,g.CLOBBER,g.TLESS,g.AND_GREAT,g.AND_DGREAT]),ve=class extends Error{line;column;token;constructor(t,n,r,s=void 0){super(`Parse error at ${n}:${r}: ${t}`),this.line=n,this.column=r,this.token=s,this.name="ParseException"}},Br=class{iterations=0;tokens=0;depth=0;reset(){this.iterations=0,this.tokens=0,this.depth=0}chargeIteration(t,n){if(this.iterations++,this.iterations>ad)throw new ve("Maximum parse iterations exceeded (possible infinite loop)",t,n)}chargeTokens(t,n=1,r=1){if(this.tokens+=t,this.tokens>rr)throw new ve(`Too many tokens: cumulative count exceeds limit of ${rr}`,n,r)}enter(t,n){if(this.depth++,this.depth>za)throw this.depth--,new ve(`Maximum parser nesting depth exceeded (${za})`,t,n);let r=!0;return()=>{r&&(r=!1,this.depth--)}}};function he(e,t){for(;t<e.length;){if(e[t]==="\\"&&e[t+1]===`
69
+ `){t+=2;continue}if(/\s/.test(e[t])){t++;continue}break}return t}var Wr=["=","+=","-=","*=","/=","%=","<<=",">>=","&=","|=","^="];function sr(e){if(e.includes("#")){let n=e.split("#");if(n.length!==2)return Number.NaN;let[r,s]=n;if(!/^\d+$/.test(r)||s.length===0)return Number.NaN;let i=Number.parseInt(r,10);if(i<2||i>64)return Number.NaN;let o=0;for(let a of s){let l;if(/[0-9]/.test(a))l=a.charCodeAt(0)-48;else if(/[a-z]/.test(a))l=a.charCodeAt(0)-97+10;else if(/[A-Z]/.test(a))l=a.charCodeAt(0)-65+(i<=36?10:36);else if(a==="@")l=62;else if(a==="_")l=63;else return Number.NaN;if(l>=i)return Number.NaN;if(o=o*i+l,o>Number.MAX_SAFE_INTEGER)return Number.MAX_SAFE_INTEGER}return o}if(e.startsWith("0x")||e.startsWith("0X")){let n=Number.parseInt(e.slice(2),16);return n>Number.MAX_SAFE_INTEGER?Number.MAX_SAFE_INTEGER:n}if(e.startsWith("0")&&e.length>1&&/^[0-9]+$/.test(e)){if(/[89]/.test(e))return Number.NaN;let n=Number.parseInt(e,8);return n>Number.MAX_SAFE_INTEGER?Number.MAX_SAFE_INTEGER:n}let t=Number.parseInt(e,10);return t>Number.MAX_SAFE_INTEGER?Number.MAX_SAFE_INTEGER:t}function Ga(e,t,n,r){if(n.slice(r,r+3)!=="$((")return null;let s=r+3,i=1,o=s;for(;s<n.length-1&&i>0;)n[s]==="("&&n[s+1]==="("?(i++,s+=2):n[s]===")"&&n[s+1]===")"?(i--,i>0&&(s+=2)):s++;let a=n.slice(o,s),{expr:l}=e(t,a,0);return s+=2,{expr:{type:"ArithNested",expression:l},pos:s}}function Ha(e,t){if(e.slice(t,t+2)!=="$'")return null;let n=t+2,r="";for(;n<e.length&&e[n]!=="'";)if(e[n]==="\\"&&n+1<e.length){let i=e[n+1];switch(i){case"n":r+=`
70
+ `;break;case"t":r+=" ";break;case"r":r+="\r";break;case"\\":r+="\\";break;case"'":r+="'";break;default:r+=i}n+=2}else r+=e[n],n++;e[n]==="'"&&n++;let s=Number.parseInt(r,10);return{expr:{type:"ArithNumber",value:Number.isNaN(s)?0:s},pos:n}}function Za(e,t){if(e.slice(t,t+2)!=='$"')return null;let n=t+2,r="";for(;n<e.length&&e[n]!=='"';)e[n]==="\\"&&n+1<e.length?(r+=e[n+1],n+=2):(r+=e[n],n++);e[n]==='"'&&n++;let s=Number.parseInt(r,10);return{expr:{type:"ArithNumber",value:Number.isNaN(s)?0:s},pos:n}}function ld(e){let t="",n=0;for(;n<e.length;)if(e[n]==='"'){for(n++;n<e.length&&e[n]!=='"';)e[n]==="\\"&&n+1<e.length?(t+=e[n+1],n+=2):(t+=e[n],n++);n<e.length&&n++}else t+=e[n],n++;return t}function te(e,t){let n=ld(t),{expr:r,pos:s}=Ln(e,n,0),i=he(n,s);if(i<n.length){let o=t.slice(i).trim();if(o)return{type:"ArithmeticExpression",originalText:t,expression:{type:"ArithSyntaxError",errorToken:o,message:`${o}: syntax error: invalid arithmetic operator (error token is "${o}")`}}}return{type:"ArithmeticExpression",expression:r,originalText:t}}function qe(e,t){return{expr:{type:"ArithSyntaxError",errorToken:e,message:`syntax error: operand expected (error token is "${e}")`},pos:t}}function Ue(e,t){return he(e,t)>=e.length}function Ln(e,t,n){return ud(e,t,n)}function hn(e,t,n){return e.withDepth(()=>Ln(e,t,n))}function ud(e,t,n){let{expr:r,pos:s}=ir(e,t,n);for(s=he(t,s);t[s]===",";){if(s++,Ue(t,s))return qe(",",s);let{expr:o,pos:a}=ir(e,t,s);r={type:"ArithBinary",operator:",",left:r,right:o},s=he(t,a)}return{expr:r,pos:s}}function ir(e,t,n){let{expr:r,pos:s}=cd(e,t,n);if(s=he(t,s),t[s]==="?"){s++;let{expr:i,pos:o}=hn(e,t,s);if(s=he(t,o),t[s]===":"){s++;let{expr:a,pos:l}=hn(e,t,s);return{expr:{type:"ArithTernary",condition:r,consequent:i,alternate:a},pos:l}}}return{expr:r,pos:s}}function cd(e,t,n){let{expr:r,pos:s}=Qa(e,t,n);for(;s=he(t,s),t.slice(s,s+2)==="||";){if(s+=2,Ue(t,s))return qe("||",s);let{expr:o,pos:a}=Qa(e,t,s);r={type:"ArithBinary",operator:"||",left:r,right:o},s=a}return{expr:r,pos:s}}function Qa(e,t,n){let{expr:r,pos:s}=Ka(e,t,n);for(;s=he(t,s),t.slice(s,s+2)==="&&";){if(s+=2,Ue(t,s))return qe("&&",s);let{expr:o,pos:a}=Ka(e,t,s);r={type:"ArithBinary",operator:"&&",left:r,right:o},s=a}return{expr:r,pos:s}}function Ka(e,t,n){let{expr:r,pos:s}=Xa(e,t,n);for(;s=he(t,s),t[s]==="|"&&t[s+1]!=="|";){if(s++,Ue(t,s))return qe("|",s);let{expr:o,pos:a}=Xa(e,t,s);r={type:"ArithBinary",operator:"|",left:r,right:o},s=a}return{expr:r,pos:s}}function Xa(e,t,n){let{expr:r,pos:s}=Ya(e,t,n);for(;s=he(t,s),t[s]==="^";){if(s++,Ue(t,s))return qe("^",s);let{expr:o,pos:a}=Ya(e,t,s);r={type:"ArithBinary",operator:"^",left:r,right:o},s=a}return{expr:r,pos:s}}function Ya(e,t,n){let{expr:r,pos:s}=Ja(e,t,n);for(;s=he(t,s),t[s]==="&"&&t[s+1]!=="&";){if(s++,Ue(t,s))return qe("&",s);let{expr:o,pos:a}=Ja(e,t,s);r={type:"ArithBinary",operator:"&",left:r,right:o},s=a}return{expr:r,pos:s}}function Ja(e,t,n){let{expr:r,pos:s}=el(e,t,n);for(;s=he(t,s),t.slice(s,s+2)==="=="||t.slice(s,s+2)==="!=";){let i=t.slice(s,s+2);if(s+=2,Ue(t,s))return qe(i,s);let{expr:o,pos:a}=el(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:o},s=a}return{expr:r,pos:s}}function el(e,t,n){let{expr:r,pos:s}=ni(e,t,n);for(;;)if(s=he(t,s),t.slice(s,s+2)==="<="||t.slice(s,s+2)===">="){let i=t.slice(s,s+2);if(s+=2,Ue(t,s))return qe(i,s);let{expr:o,pos:a}=ni(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:o},s=a}else if(t[s]==="<"||t[s]===">"){let i=t[s];if(s++,Ue(t,s))return qe(i,s);let{expr:o,pos:a}=ni(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:o},s=a}else break;return{expr:r,pos:s}}function ni(e,t,n){let{expr:r,pos:s}=tl(e,t,n);for(;s=he(t,s),t.slice(s,s+2)==="<<"||t.slice(s,s+2)===">>";){let i=t.slice(s,s+2);if(s+=2,Ue(t,s))return qe(i,s);let{expr:o,pos:a}=tl(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:o},s=a}return{expr:r,pos:s}}function tl(e,t,n){let{expr:r,pos:s}=nl(e,t,n);for(;s=he(t,s),(t[s]==="+"||t[s]==="-")&&t[s+1]!==t[s];){let i=t[s];if(s++,Ue(t,s))return qe(i,s);let{expr:o,pos:a}=nl(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:o},s=a}return{expr:r,pos:s}}function nl(e,t,n){let{expr:r,pos:s}=Vr(e,t,n);for(;;)if(s=he(t,s),t[s]==="*"&&t[s+1]!=="*"){if(s++,Ue(t,s))return qe("*",s);let{expr:o,pos:a}=Vr(e,t,s);r={type:"ArithBinary",operator:"*",left:r,right:o},s=a}else if(t[s]==="/"||t[s]==="%"){let i=t[s];if(s++,Ue(t,s))return qe(i,s);let{expr:o,pos:a}=Vr(e,t,s);r={type:"ArithBinary",operator:i,left:r,right:o},s=a}else break;return{expr:r,pos:s}}function Vr(e,t,n){let{expr:r,pos:s}=ri(e,t,n),i=he(t,s);if(t.slice(i,i+2)==="**"){if(i+=2,Ue(t,i))return qe("**",i);let{expr:a,pos:l}=e.withDepth(()=>Vr(e,t,i));return{expr:{type:"ArithBinary",operator:"**",left:r,right:a},pos:l}}return{expr:r,pos:s}}function ri(e,t,n){let r=he(t,n);if(t.slice(r,r+2)==="++"||t.slice(r,r+2)==="--"){let s=t.slice(r,r+2);r+=2;let{expr:i,pos:o}=e.withDepth(()=>ri(e,t,r));return{expr:{type:"ArithUnary",operator:s,operand:i,prefix:!0},pos:o}}if(t[r]==="+"||t[r]==="-"||t[r]==="!"||t[r]==="~"){let s=t[r];r++;let{expr:i,pos:o}=e.withDepth(()=>ri(e,t,r));return{expr:{type:"ArithUnary",operator:s,operand:i,prefix:!0},pos:o}}return dd(e,t,r)}function fd(e,t){let n=e[t];return n==="$"||n==="`"}function dd(e,t,n){let{expr:r,pos:s}=rl(e,t,n,!1),i=[r];for(;fd(t,s);){let{expr:a,pos:l}=rl(e,t,s,!0);i.push(a),s=l}i.length>1&&(r={type:"ArithConcat",parts:i});let o;if(t[s]==="["&&r.type==="ArithConcat"){s++;let{expr:a,pos:l}=hn(e,t,s);o=a,s=l,t[s]==="]"&&s++}if(o&&r.type==="ArithConcat"&&(r={type:"ArithDynamicElement",nameExpr:r,subscript:o},o=void 0),s=he(t,s),r.type==="ArithConcat"||r.type==="ArithVariable"||r.type==="ArithDynamicElement"){for(let a of Wr)if(t.slice(s,s+a.length)===a&&t.slice(s,s+a.length+1)!=="=="){s+=a.length;let{expr:l,pos:u}=e.withDepth(()=>ir(e,t,s));return r.type==="ArithDynamicElement"?{expr:{type:"ArithDynamicAssignment",operator:a,target:r.nameExpr,subscript:r.subscript,value:l},pos:u}:r.type==="ArithConcat"?{expr:{type:"ArithDynamicAssignment",operator:a,target:r,value:l},pos:u}:{expr:{type:"ArithAssignment",operator:a,variable:r.name,value:l},pos:u}}}if(t.slice(s,s+2)==="++"||t.slice(s,s+2)==="--"){let a=t.slice(s,s+2);return s+=2,{expr:{type:"ArithUnary",operator:a,operand:r,prefix:!1},pos:s}}return{expr:r,pos:s}}function rl(e,t,n,r=!1){let s=he(t,n),i=Ga(hn,e,t,s);if(i)return i;let o=Ha(t,s);if(o)return o;let a=Za(t,s);if(a)return a;if(t.slice(s,s+2)==="$("&&t[s+2]!=="("){s+=2;let u=1,c=s;for(;s<t.length&&u>0;)t[s]==="("?u++:t[s]===")"&&u--,u>0&&s++;let f=t.slice(c,s);return s++,{expr:{type:"ArithCommandSubst",command:f},pos:s}}if(t[s]==="`"){s++;let u=s;for(;s<t.length&&t[s]!=="`";)s++;let c=t.slice(u,s);return t[s]==="`"&&s++,{expr:{type:"ArithCommandSubst",command:c},pos:s}}if(t[s]==="("){s++;let{expr:u,pos:c}=hn(e,t,s);return s=he(t,c),t[s]===")"&&s++,{expr:{type:"ArithGroup",expression:u},pos:s}}if(t[s]==="'"){s++;let u="";for(;s<t.length&&t[s]!=="'";)u+=t[s],s++;t[s]==="'"&&s++;let c=Number.parseInt(u,10);return{expr:{type:"ArithSingleQuote",content:u,value:Number.isNaN(c)?0:c},pos:s}}if(t[s]==='"'){s++;let u="";for(;s<t.length&&t[s]!=='"';)t[s]==="\\"&&s+1<t.length?(u+=t[s+1],s+=2):(u+=t[s],s++);t[s]==='"'&&s++;let c=u.trim();if(!c)return{expr:{type:"ArithNumber",value:0},pos:s};let{expr:f}=hn(e,c,0);return{expr:f,pos:s}}if(/[0-9]/.test(t[s])){let u="",c=!1,f=!1;for(;s<t.length;){let p=t[s];if(c)if(/[0-9a-zA-Z@_]/.test(p))u+=p,s++;else break;else if(p==="#")c=!0,u+=p,s++;else if(u==="0"&&(p==="x"||p==="X")&&s+1<t.length&&/[0-9a-fA-F]/.test(t[s+1]))f=!0,u+=p,s++;else if(f&&/[0-9a-fA-F]/.test(p))u+=p,s++;else if(!f&&/[0-9]/.test(p))u+=p,s++;else break}if(s<t.length&&/[a-zA-Z_]/.test(t[s])){let p=u;for(;s<t.length&&/[a-zA-Z0-9_]/.test(t[s]);)p+=t[s],s++;return{expr:{type:"ArithSyntaxError",errorToken:p,message:`${p}: value too great for base (error token is "${p}")`},pos:s}}if(t[s]==="."&&/[0-9]/.test(t[s+1]))throw new oe(`${u}.${t[s+1]}...: syntax error: invalid arithmetic operator`);if(t[s]==="["){let p=t.slice(s).trim();return{expr:{type:"ArithNumberSubscript",number:u,errorToken:p},pos:t.length}}return{expr:{type:"ArithNumber",value:sr(u)},pos:s}}if(t[s]==="$"&&t[s+1]==="{"){let u=s+2,c=1,f=u;for(;f<t.length&&c>0;)t[f]==="{"?c++:t[f]==="}"&&c--,c>0&&f++;let d=t.slice(u,f),p=f+1;if(t[p]==="#"){let h=p+1;for(;h<t.length&&/[0-9a-zA-Z@_]/.test(t[h]);)h++;let m=t.slice(p+1,h);return{expr:{type:"ArithDynamicBase",baseExpr:d,value:m},pos:h}}if(/[0-9]/.test(t[p])||t[p]==="x"||t[p]==="X"){let h=p;if(t[p]==="x"||t[p]==="X")for(h++;h<t.length&&/[0-9a-fA-F]/.test(t[h]);)h++;else for(;h<t.length&&/[0-9]/.test(t[h]);)h++;let m=t.slice(p,h);return{expr:{type:"ArithDynamicNumber",prefix:d,suffix:m},pos:h}}return s=p,{expr:{type:"ArithBracedExpansion",content:d},pos:s}}if(t[s]==="$"&&s+1<t.length&&/[0-9]/.test(t[s+1])){s++;let u="";for(;s<t.length&&/[0-9]/.test(t[s]);)u+=t[s],s++;return{expr:{type:"ArithVariable",name:u,hasDollarPrefix:!0},pos:s}}if(t[s]==="$"&&s+1<t.length&&/[*@#?\-!$]/.test(t[s+1])){let u=t[s+1];return s+=2,{expr:{type:"ArithSpecialVar",name:u},pos:s}}let l=!1;if(t[s]==="$"&&s+1<t.length&&/[a-zA-Z_]/.test(t[s+1])&&(l=!0,s++),s<t.length&&/[a-zA-Z_]/.test(t[s])){let u="";for(;s<t.length&&/[a-zA-Z0-9_]/.test(t[s]);)u+=t[s],s++;if(t[s]==="["&&!r){s++;let c;if(t[s]==="'"||t[s]==='"'){let d=t[s];for(s++,c="";s<t.length&&t[s]!==d;)c+=t[s],s++;t[s]===d&&s++,s=he(t,s),t[s]==="]"&&s++}let f;if(c===void 0){let{expr:d,pos:p}=hn(e,t,s);f=d,s=p,t[s]==="]"&&s++}if(s=he(t,s),t[s]==="["&&f)return{expr:{type:"ArithDoubleSubscript",array:u,index:f},pos:s};if(!r){for(let d of Wr)if(t.slice(s,s+d.length)===d&&t.slice(s,s+d.length+1)!=="=="){s+=d.length;let{expr:p,pos:h}=e.withDepth(()=>ir(e,t,s));return{expr:{type:"ArithAssignment",operator:d,variable:u,subscript:f,stringKey:c,value:p},pos:h}}}return{expr:{type:"ArithArrayElement",array:u,index:f,stringKey:c},pos:s}}if(s=he(t,s),!r){for(let c of Wr)if(t.slice(s,s+c.length)===c&&t.slice(s,s+c.length+1)!=="=="){s+=c.length;let{expr:f,pos:d}=e.withDepth(()=>ir(e,t,s));return{expr:{type:"ArithAssignment",operator:c,variable:u,value:f},pos:d}}}return{expr:{type:"ArithVariable",name:u,hasDollarPrefix:l},pos:s}}if(t[s]==="#"){let u=s+1;for(;u<t.length&&t[u]!==`
71
+ `;)u++;let c=t.slice(s,u).trim()||"#";return{expr:{type:"ArithSyntaxError",errorToken:c,message:`${c}: syntax error: invalid arithmetic operator (error token is "${c}")`},pos:t.length}}return{expr:{type:"ArithNumber",value:0},pos:s}}var zr=e=>{let t,n="";for(let r=0;r<e.length;r++){let s=e[r];if(s==="\\"&&t==='"'&&r+1<e.length){n+=s+e[r+1],r+=1;continue}if(s==="'"||s==='"'){t===s?t=void 0:t||(t=s),n+=s;continue}if(s==="\\"&&!t&&r+1<e.length){let i=e[r+1];n+=i==="$"||i==="`"?`\\${i}`:i,r+=1;continue}n+=s}return n};function pd(e){let t="",n=0;for(;n<e.length;){let r=e[n];if(r<128){t+=String.fromCharCode(r),n++;continue}if((r&224)===192){if(n+1<e.length&&(e[n+1]&192)===128&&r>=194){let s=(r&31)<<6|e[n+1]&63;t+=String.fromCharCode(s),n+=2;continue}t+=String.fromCharCode(r),n++;continue}if((r&240)===224){if(n+2<e.length&&(e[n+1]&192)===128&&(e[n+2]&192)===128){if(r===224&&e[n+1]<160){t+=String.fromCharCode(r),n++;continue}let s=(r&15)<<12|(e[n+1]&63)<<6|e[n+2]&63;if(s>=55296&&s<=57343){t+=String.fromCharCode(r),n++;continue}t+=String.fromCharCode(s),n+=3;continue}t+=String.fromCharCode(r),n++;continue}if((r&248)===240&&r<=244){if(n+3<e.length&&(e[n+1]&192)===128&&(e[n+2]&192)===128&&(e[n+3]&192)===128){if(r===240&&e[n+1]<144){t+=String.fromCharCode(r),n++;continue}let s=(r&7)<<18|(e[n+1]&63)<<12|(e[n+2]&63)<<6|e[n+3]&63;if(s>1114111){t+=String.fromCharCode(r),n++;continue}t+=String.fromCodePoint(s),n+=4;continue}t+=String.fromCharCode(r),n++;continue}t+=String.fromCharCode(r),n++}return t}function ol(e,t,n){let r=n+1;for(;r<t.length&&/[a-zA-Z0-9_-]/.test(t[r]);)r++;return r}function si(e,t,n,r,s){let i=1,o=n+1;for(;o<t.length&&i>0;)t[o]===r?i++:t[o]===s&&i--,i>0&&o++;return i===0?o:-1}function mn(e,t,n){let r=n,s=1;for(;r<t.length&&s>0;){let i=t[r];if(i==="\\"&&r+1<t.length){r+=2;continue}if(i==="'"){let o=t.indexOf("'",r+1);if(o!==-1){r=o+1;continue}}if(i==='"'){for(r++;r<t.length&&t[r]!=='"';)t[r]==="\\"&&r+1<t.length?r+=2:r++;r<t.length&&r++;continue}i==="{"?s++:i==="}"&&s--,s>0&&r++}return r}function al(e,t,n){let r=n,s=!1;for(;r<t.length;){let i=t[r];if(i==="/"&&s||i==="}")break;if(i==="'"){let o=t.indexOf("'",r+1);if(o!==-1){r=o+1,s=!0;continue}}if(i==='"'){for(r++;r<t.length&&t[r]!=='"';)t[r]==="\\"&&r+1<t.length?r+=2:r++;r<t.length&&r++,s=!0;continue}i==="\\"?(r+=2,s=!0):(r++,s=!0)}return r}function ll(e,t,n){let r=n,s="";for(;r<t.length;){let i=t[r];if(i==="*"||i==="?")s+=i,r++;else if(i==="["){let o=hd(t,r);o===-1?(s+=i,r++):(s+=t.slice(r,o+1),r=o+1)}else break}return{pattern:s,endIndex:r}}function hd(e,t){let n=t+1;for(n<e.length&&e[n]==="^"&&n++,n<e.length&&e[n]==="]"&&n++;n<e.length;){let r=e[n];if(r==="\\"&&n+1<e.length){let s=e[n+1];if(s==='"'||s==="'")return-1;n+=2;continue}if(r==="]")return n;if(r==='"'||r==="$"||r==="`")return-1;if(r==="'"){let s=e.indexOf("'",n+1);if(s!==-1){n=s+1;continue}}if(r==="["&&n+1<e.length&&e[n+1]===":"){let s=e.indexOf(":]",n+2);if(s!==-1){n=s+2;continue}}if(r==="["&&n+1<e.length&&(e[n+1]==="."||e[n+1]==="=")){let i=`${e[n+1]}]`,o=e.indexOf(i,n+2);if(o!==-1){n=o+2;continue}}n++}return-1}function ul(e,t,n){let r="",s=n;for(;s<t.length&&t[s]!=="'";){let i=t[s];if(i==="\\"&&s+1<t.length)switch(t[s+1]){case"n":r+=`
72
+ `,s+=2;break;case"t":r+=" ",s+=2;break;case"r":r+="\r",s+=2;break;case"\\":r+="\\",s+=2;break;case"'":r+="'",s+=2;break;case'"':r+='"',s+=2;break;case"a":r+="\x07",s+=2;break;case"b":r+="\b",s+=2;break;case"e":case"E":r+="\x1B",s+=2;break;case"f":r+="\f",s+=2;break;case"v":r+="\v",s+=2;break;case"x":{let a=[],l=s;for(;l+1<t.length&&t[l]==="\\"&&t[l+1]==="x";){let u=t.slice(l+2,l+4),c=parseInt(u,16);if(!Number.isNaN(c)&&u.length>0)a.push(c),l+=2+u.length;else break}a.length>0?(r+=pd(a),s=l):(r+="\\x",s+=2);break}case"u":{let a=t.slice(s+2,s+6),l=parseInt(a,16);Number.isNaN(l)?(r+="\\u",s+=2):(r+=String.fromCharCode(l),s+=6);break}case"c":{if(s+2<t.length){let l=t[s+2].charCodeAt(0)&31;r+=String.fromCharCode(l),s+=3}else r+="\\c",s+=2;break}case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":{let a="",l=s+1;for(;l<t.length&&l<s+4&&/[0-7]/.test(t[l]);)a+=t[l],l++;let u=parseInt(a,8);r+=String.fromCharCode(u),s=l;break}default:r+=i,s++}else r+=i,s++}return s<t.length&&t[s]==="'"&&s++,{part:F.literal(r),endIndex:s}}function ii(e,t){let n=t.trim();return n===""?{type:"ArithmeticExpression",expression:{type:"ArithNumber",value:0}}:te(e,n)}function il(e){let t=[],n="",r=0;for(let s=0;s<e.length;s++){let i=e[s];i==="{"?(r++,n+=i):i==="}"?(r--,n+=i):i===","&&r===0?(t.push(n),n=""):n+=i}return t.push(n),t}function cl(e,t,n,r){let s=si(e,t,n,"{","}");if(s===-1)return null;let i=t.slice(n+1,s),o=i.match(/^(-?\d+)\.\.(-?\d+)(?:\.\.(-?\d+))?$/);if(o)return{part:{type:"BraceExpansion",items:[{type:"Range",start:Number.parseInt(o[1],10),end:Number.parseInt(o[2],10),step:o[3]?Number.parseInt(o[3],10):void 0,startStr:o[1],endStr:o[2]}]},endIndex:s+1};let a=i.match(/^([a-zA-Z])\.\.([a-zA-Z])(?:\.\.(-?\d+))?$/);return a?{part:{type:"BraceExpansion",items:[{type:"Range",start:a[1],end:a[2],step:a[3]?Number.parseInt(a[3],10):void 0}]},endIndex:s+1}:i.includes(",")&&r?{part:{type:"BraceExpansion",items:il(i).map(c=>e.withDepth(()=>({type:"Word",word:F.word(r(e,c,!1,!1,!1))})))},endIndex:s+1}:i.includes(",")?{part:{type:"BraceExpansion",items:il(i).map(c=>({type:"Word",word:F.word([F.literal(c)])}))},endIndex:s+1}:null}function oi(e,t){let n="";for(let r of t.parts)switch(r.type){case"Literal":n+=r.value;break;case"SingleQuoted":n+=`'${r.value}'`;break;case"Escaped":n+=r.value;break;case"DoubleQuoted":n+='"';for(let s of r.parts)s.type==="Literal"||s.type==="Escaped"?n+=s.value:s.type==="ParameterExpansion"&&(n+=`\${${s.parameter}}`);n+='"';break;case"ParameterExpansion":n+=`\${${r.parameter}}`;break;case"Glob":n+=r.pattern;break;case"TildeExpansion":n+="~",r.user&&(n+=r.user);break;case"BraceExpansion":{n+="{";let s=[];for(let i of r.items)if(i.type==="Range"){let o=i.startStr??String(i.start),a=i.endStr??String(i.end);i.step!==void 0?s.push(`${o}..${a}..${i.step}`):s.push(`${o}..${a}`)}else s.push(oi(e,i.word));s.length===1&&r.items[0].type==="Range"?n+=s[0]:n+=s.join(","),n+="}";break}default:n+=r.type}return n}function fl(e,t){return{[g.LESS]:"<",[g.GREAT]:">",[g.DGREAT]:">>",[g.LESSAND]:"<&",[g.GREATAND]:">&",[g.LESSGREAT]:"<>",[g.CLOBBER]:">|",[g.TLESS]:"<<<",[g.AND_GREAT]:"&>",[g.AND_DGREAT]:"&>>",[g.DLESS]:"<",[g.DLESSDASH]:"<"}[t]||">"}function or(e){let t=e.current(),n=t.type;if(n===g.NUMBER){let r=e.peek(1);return t.end!==r.start||e.isProcessSubstitutionStart(1)?!1:Ua.has(r.type)}if(n===g.FD_VARIABLE){let r=e.peek(1);return t.end!==r.start||e.isProcessSubstitutionStart(1)?!1:ja.has(r.type)}return!e.isProcessSubstitutionStart()&&qa.has(n)}function qr(e){let t=null,n;e.check(g.NUMBER)?t=Number.parseInt(e.advance().value,10):e.check(g.FD_VARIABLE)&&(n=e.advance().value);let r=e.advance(),s=fl(e,r.type);if(r.type===g.DLESS||r.type===g.DLESSDASH)return md(e,t,n,r.type===g.DLESSDASH);e.isWord()||e.error("Expected redirection target");let i=e.parseWord();return F.redirection(s,i,t,n)}function md(e,t,n,r){e.isWord()||e.error("Expected here-document delimiter");let s=e.advance(),i=s.heredocDelimiter??s.value,o=s.quoted||!1,a=F.redirection(r?"<<-":"<<",F.hereDoc(i,F.word([]),r,o),t,n);return e.addPendingHeredoc(a,i,r,o),a}function li(e){let t=e.getSourceLine(),n=[],r=null,s=[],i=[];for(;e.check(g.ASSIGNMENT_WORD)||or(e);)e.checkIterationLimit(),e.check(g.ASSIGNMENT_WORD)?n.push(yd(e)):i.push(qr(e));if(e.isWord())r=e.parseWord();else if(n.length>0&&(e.check(g.DBRACK_START)||e.check(g.DPAREN_START))){let a=e.advance();r=F.word([F.literal(a.value)])}for(;(!e.isStatementEnd()||e.check(g.RBRACE))&&!e.check(g.PIPE,g.PIPE_AMP);)if(e.checkIterationLimit(),or(e))i.push(qr(e));else if(e.check(g.ASSIGNMENT_WORD)){let a=e.advance(),l=a.value,u=l.endsWith("="),c=l.endsWith("=(");if((u||c)&&(c||e.check(g.LPAREN))){let f=c?l.slice(0,-2):l.slice(0,-1);c||e.expect(g.LPAREN);let d=ai(e);e.expect(g.RPAREN);let p=d.map(m=>oi(e,m)),h=`${f}=(${p.join(" ")})`;s.push(e.parseWordFromString(h,!1,!1,!0))}else{let f=e.parseWordFromString(l,a.quoted,a.singleQuoted,!0);s.push(e.parseAdjacentWordParts(f.parts,a.end,Pe.Assignment))}}else if(e.isWord())s.push(e.parseWord());else if(e.check(g.RBRACE)){let a=e.advance();s.push(e.parseWordFromString(a.value,!1,!1))}else if(e.check(g.LBRACE)){let a=e.advance();s.push(e.parseWordFromString(a.value,!1,!1))}else if(e.check(g.DBRACK_END)){let a=e.advance();s.push(e.parseWordFromString(a.value,!1,!1))}else if(e.check(g.LPAREN))e.error("syntax error near unexpected token `('");else break;let o=F.simpleCommand(r,s,n,i);return o.line=t,o}function yd(e){let t=e.expect(g.ASSIGNMENT_WORD),n=t.value,r=n.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);r||e.error(`Invalid assignment: ${n}`);let s=r[0],i,o=s.length;if(n[o]==="["){let f=0,d=o+1;for(;o<n.length;o++)if(n[o]==="[")f++;else if(n[o]==="]"&&(f--,f===0))break;f!==0&&e.error(`Invalid assignment: ${n}`),i=zr(n.slice(d,o)),o++}let a=n[o]==="+";a&&o++,n[o]!=="="&&e.error(`Invalid assignment: ${n}`),o++;let l=n.slice(o);if(l==="("){let f=ai(e);e.expect(g.RPAREN);let d=i!==void 0?`${s}[${i}]`:s;return F.assignment(d,null,a,f)}if(l===""&&e.check(g.LPAREN)){let f=e.current();if(t.end===f.start){e.advance();let d=ai(e);e.expect(g.RPAREN);let p=i!==void 0?`${s}[${i}]`:s;return F.assignment(p,null,a,d)}}let u=l?e.parseWordFromString(l,t.quoted,t.singleQuoted,!0):null;t.end===e.current().start&&e.isProcessSubstitutionStart()&&(u=e.parseAdjacentWordParts(u?.parts??[],t.end,Pe.Assignment));let c=i!==void 0?`${s}[${i}]`:s;return F.assignment(c,u,a,null)}var gd=new Set([g.AMP,g.PIPE,g.PIPE_AMP,g.SEMICOLON,g.AND_AND,g.OR_OR,g.DSEMI,g.SEMI_AND,g.SEMI_SEMI_AND]);function ai(e){let t=[];for(e.skipNewlines();!e.check(g.RPAREN,g.EOF);)e.checkIterationLimit(),e.isWord()?t.push(e.parseWord()):gd.has(e.current().type)?e.error(`syntax error near unexpected token \`${e.current().value}'`):e.advance(),e.skipNewlines();return t}function ui(e,t){e.expect(g.IF);let n=[],r=e.parseCompoundList();e.expect(g.THEN);let s=e.parseCompoundList();if(s.length===0){let a=e.check(g.FI)?"fi":e.check(g.ELSE)?"else":e.check(g.ELIF)?"elif":"fi";e.error(`syntax error near unexpected token \`${a}'`)}for(n.push({condition:r,body:s});e.check(g.ELIF);){e.advance();let a=e.parseCompoundList();e.expect(g.THEN);let l=e.parseCompoundList();if(l.length===0){let u=e.check(g.FI)?"fi":e.check(g.ELSE)?"else":e.check(g.ELIF)?"elif":"fi";e.error(`syntax error near unexpected token \`${u}'`)}n.push({condition:a,body:l})}let i=null;e.check(g.ELSE)&&(e.advance(),i=e.parseCompoundList(),i.length===0&&e.error("syntax error near unexpected token `fi'")),e.expect(g.FI);let o=t?.skipRedirections?[]:e.parseOptionalRedirections();return F.ifNode(n,i,o)}function ci(e,t){let n=e.expect(g.FOR);if(e.check(g.DPAREN_START))return Ed(e,t,e.getSourceLine(n));e.isWord()||e.error("Expected variable name in for loop");let s=e.advance().value,i=null;if(e.skipNewlines(),e.check(g.IN))for(e.advance(),i=[];!e.check(g.SEMICOLON,g.NEWLINE,g.DO,g.EOF)&&e.isWord();)i.push(e.parseWord());e.check(g.SEMICOLON)&&e.advance(),e.skipNewlines(),e.expect(g.DO);let o=e.parseCompoundList();e.expect(g.DONE);let a=t?.skipRedirections?[]:e.parseOptionalRedirections();return F.forNode(s,i,o,a)}function Ed(e,t,n){e.expect(g.DPAREN_START);let r=null,s=null,i=null,o=["","",""],a=0,l=0;for(;!e.check(g.DPAREN_END,g.EOF);){let f=e.advance();if(f.type===g.SEMICOLON&&l===0){if(a++,a>2)break}else f.value==="("&&l++,f.value===")"&&l--,o[a]+=f.value}e.expect(g.DPAREN_END),o[0].trim()&&(r=te(e,o[0].trim())),o[1].trim()&&(s=te(e,o[1].trim())),o[2].trim()&&(i=te(e,o[2].trim())),e.skipNewlines(),e.check(g.SEMICOLON)&&e.advance(),e.skipNewlines();let u;e.check(g.LBRACE)?(e.advance(),u=e.parseCompoundList(),e.expect(g.RBRACE)):(e.expect(g.DO),u=e.parseCompoundList(),e.expect(g.DONE));let c=t?.skipRedirections?[]:e.parseOptionalRedirections();return{type:"CStyleFor",init:r,condition:s,update:i,body:u,redirections:c,line:n}}function fi(e,t){e.expect(g.WHILE);let n=e.parseCompoundList();e.expect(g.DO);let r=e.parseCompoundList();r.length===0&&e.error("syntax error near unexpected token `done'"),e.expect(g.DONE);let s=t?.skipRedirections?[]:e.parseOptionalRedirections();return F.whileNode(n,r,s)}function di(e,t){e.expect(g.UNTIL);let n=e.parseCompoundList();e.expect(g.DO);let r=e.parseCompoundList();r.length===0&&e.error("syntax error near unexpected token `done'"),e.expect(g.DONE);let s=t?.skipRedirections?[]:e.parseOptionalRedirections();return F.untilNode(n,r,s)}function pi(e,t){e.expect(g.CASE),e.isWord()||e.error("Expected word after 'case'");let n=e.parseWord();e.skipNewlines(),e.expect(g.IN),e.skipNewlines();let r=[];for(;!e.check(g.ESAC,g.EOF);){e.checkIterationLimit();let i=e.getPos(),o=bd(e);if(o&&r.push(o),e.skipNewlines(),e.getPos()===i&&!o)break}e.expect(g.ESAC);let s=t?.skipRedirections?[]:e.parseOptionalRedirections();return F.caseNode(n,r,s)}function bd(e){e.check(g.LPAREN)&&e.advance();let t=[];for(;e.isWord()&&(t.push(e.parseWord()),e.check(g.PIPE));)e.advance();if(t.length===0)return null;e.expect(g.RPAREN),e.skipNewlines();let n=[];for(;!e.check(g.DSEMI,g.SEMI_AND,g.SEMI_SEMI_AND,g.ESAC,g.EOF);){e.checkIterationLimit(),e.isWord()&&e.peek(1).type===g.RPAREN&&e.error("syntax error near unexpected token `)'"),e.check(g.LPAREN)&&e.peek(1).type===g.WORD&&e.error(`syntax error near unexpected token \`${e.peek(1).value}'`);let s=e.getPos(),i=e.parseStatement();if(i&&n.push(i),e.skipSeparators(!1),e.getPos()===s&&!i)break}let r=";;";return e.check(g.DSEMI)?(e.advance(),r=";;"):e.check(g.SEMI_AND)?(e.advance(),r=";&"):e.check(g.SEMI_SEMI_AND)&&(e.advance(),r=";;&"),F.caseItem(t,n,r)}function hi(e,t){e.expect(g.LPAREN);let n=e.parseCompoundList();e.expect(g.RPAREN);let r=t?.skipRedirections?[]:e.parseOptionalRedirections();return F.subshell(n,r)}function mi(e,t){e.expect(g.LBRACE);let n=e.parseCompoundList();e.expect(g.RBRACE);let r=t?.skipRedirections?[]:e.parseOptionalRedirections();return F.group(n,r)}var Ad=["-a","-b","-c","-d","-e","-f","-g","-h","-k","-p","-r","-s","-t","-u","-w","-x","-G","-L","-N","-O","-S","-z","-n","-o","-v","-R"],vd=["==","!=","=~","<",">","-eq","-ne","-lt","-le","-gt","-ge","-nt","-ot","-ef"];function pl(e){return e.isWord()||e.check(g.LBRACE)||e.check(g.RBRACE)||e.check(g.ASSIGNMENT_WORD)}function hl(e){if(e.check(g.BANG)&&e.peek(1).type===g.LPAREN){e.advance(),e.advance();let t=1,n="!(";for(;t>0&&!e.check(g.EOF);)if(e.check(g.LPAREN))t++,n+="(",e.advance();else if(e.check(g.RPAREN))t--,t>0&&(n+=")"),e.advance();else if(e.isWord())n+=e.advance().value;else if(e.check(g.PIPE))n+="|",e.advance();else break;return n+=")",e.parseWordFromString(n,!1,!1,!1,!1,!0)}return e.parseWordNoBraceExpansion()}function gi(e){return e.skipNewlines(),xd(e)}function xd(e){let t=ml(e);for(e.skipNewlines();e.check(g.OR_OR);){e.advance(),e.skipNewlines();let n=ml(e);t={type:"CondOr",left:t,right:n},e.skipNewlines()}return t}function ml(e){let t=yi(e);for(e.skipNewlines();e.check(g.AND_AND);){e.advance(),e.skipNewlines();let n=yi(e);t={type:"CondAnd",left:t,right:n},e.skipNewlines()}return t}function yi(e){return e.skipNewlines(),e.check(g.BANG)?(e.advance(),e.skipNewlines(),{type:"CondNot",operand:e.withDepth(()=>yi(e))}):$d(e)}function $d(e){if(e.check(g.LPAREN)){e.advance();let t=e.withDepth(()=>gi(e));return e.expect(g.RPAREN),{type:"CondGroup",expression:t}}if(pl(e)){let t=e.current(),n=t.value;if(Ad.includes(n)&&!t.quoted){if(e.advance(),e.check(g.DBRACK_END)&&e.error(`Expected operand after ${n}`),pl(e)){let i=e.parseWordNoBraceExpansion();return{type:"CondUnary",operator:n,operand:i}}let s=e.current();e.error(`unexpected argument \`${s.value}' to conditional unary operator`)}let r=e.parseWordNoBraceExpansion();if(e.isWord()&&vd.includes(e.current().value)){let s=e.advance().value,i;return s==="=~"?i=kd(e):s==="=="||s==="!="?i=hl(e):i=e.parseWordNoBraceExpansion(),{type:"CondBinary",operator:s,left:r,right:i}}if(e.check(g.LESS)){e.advance();let s=e.parseWordNoBraceExpansion();return{type:"CondBinary",operator:"<",left:r,right:s}}if(e.check(g.GREAT)){e.advance();let s=e.parseWordNoBraceExpansion();return{type:"CondBinary",operator:">",left:r,right:s}}if(e.isWord()&&e.current().value==="="){e.advance();let s=hl(e);return{type:"CondBinary",operator:"==",left:r,right:s}}return{type:"CondWord",word:r}}e.error("Expected conditional expression")}function kd(e){let t=[],n=0,r=-1,s=e.getInput(),i=()=>e.check(g.DBRACK_END)||e.check(g.AND_AND)||e.check(g.OR_OR)||e.check(g.NEWLINE)||e.check(g.EOF);for(;!i();){let o=e.current(),a=r>=0&&o.start>r;if(n===0&&a)break;if(n>0&&a){let l=s.slice(r,o.start);t.push({type:"Literal",value:l})}if(e.isWord()||e.check(g.ASSIGNMENT_WORD)){let l=e.parseWordForRegex();t.push(...l.parts),r=e.peek(-1).end}else if(e.check(g.LPAREN)){let l=e.advance();t.push({type:"Literal",value:"("}),n++,r=l.end}else if(e.check(g.DPAREN_START)){let l=e.advance();t.push({type:"Literal",value:"(("}),n+=2,r=l.end}else if(e.check(g.DPAREN_END))if(n>=2){let l=e.advance();t.push({type:"Literal",value:"))"}),n-=2,r=l.end}else{if(n===1)break;break}else if(e.check(g.RPAREN))if(n>0){let l=e.advance();t.push({type:"Literal",value:")"}),n--,r=l.end}else break;else if(e.check(g.PIPE)){let l=e.advance();t.push({type:"Literal",value:"|"}),r=l.end}else if(e.check(g.SEMICOLON))if(n>0){let l=e.advance();t.push({type:"Literal",value:";"}),r=l.end}else break;else if(n>0&&e.check(g.LESS)){let l=e.advance();t.push({type:"Literal",value:"<"}),r=l.end}else if(n>0&&e.check(g.GREAT)){let l=e.advance();t.push({type:"Literal",value:">"}),r=l.end}else if(n>0&&e.check(g.DGREAT)){let l=e.advance();t.push({type:"Literal",value:">>"}),r=l.end}else if(n>0&&e.check(g.DLESS)){let l=e.advance();t.push({type:"Literal",value:"<<"}),r=l.end}else if(n>0&&e.check(g.LESSAND)){let l=e.advance();t.push({type:"Literal",value:"<&"}),r=l.end}else if(n>0&&e.check(g.GREATAND)){let l=e.advance();t.push({type:"Literal",value:">&"}),r=l.end}else if(n>0&&e.check(g.LESSGREAT)){let l=e.advance();t.push({type:"Literal",value:"<>"}),r=l.end}else if(n>0&&e.check(g.CLOBBER)){let l=e.advance();t.push({type:"Literal",value:">|"}),r=l.end}else if(n>0&&e.check(g.TLESS)){let l=e.advance();t.push({type:"Literal",value:"<<<"}),r=l.end}else if(n>0&&e.check(g.AMP)){let l=e.advance();t.push({type:"Literal",value:"&"}),r=l.end}else if(n>0&&e.check(g.LBRACE)){let l=e.advance();t.push({type:"Literal",value:"{"}),r=l.end}else if(n>0&&e.check(g.RBRACE)){let l=e.advance();t.push({type:"Literal",value:"}"}),r=l.end}else break}return t.length===0&&e.error("Expected regex pattern after =~"),{type:"Word",parts:t}}function Cd(e){let t="";for(let n=0;n<e.length;n++){let r=e[n],s=e[n+1];if(r!=="\\"||s===void 0){t+=r;continue}"\\[]^-".includes(s)&&(t+="\\"),t+=s,n++}return t}function ar(e){return e.length>0?e:[F.literal("")]}function Nd(e,t){let n=1,r=t+1;for(;r<e.length&&n>0;){let s=e[r];if(s==="\\"){r+=2;continue}if("@*+?!".includes(s)&&r+1<e.length&&e[r+1]==="("){r++,n++,r++;continue}if(s==="(")n++;else if(s===")"&&(n--,n===0))return r;r++}return-1}function Rd(e,t,n){let r=n+1,s=t[r];if("@*#?$!-0123456789".includes(s))return{part:F.parameterExpansion(s),endIndex:r+1};let i="";for(;r<t.length&&/[a-zA-Z0-9_]/.test(t[r]);)i+=t[r],r++;return{part:F.parameterExpansion(i),endIndex:r}}function Dd(e,t,n,r=!1){let s=n+2,i=!1;t[s]==="!"&&(i=!0,s++);let o=!1;t[s]==="#"&&!/[}:#%/^,]/.test(t[s+1]||"}")&&(o=!0,s++);let a="",l=t[s];if(/[@*#?$!-]/.test(l)&&!/[a-zA-Z0-9_]/.test(t[s+1]||""))a=l,s++;else for(;s<t.length&&/[a-zA-Z0-9_]/.test(t[s]);)a+=t[s],s++;if(t[s]==="["){let c=si(e,t,s,"[","]");if(a+=`[${zr(t.slice(s+1,c))}]`,s=c+1,t[s]==="["){let f=1,d=s;for(;d<t.length&&f>0;)t[d]==="{"?f++:t[d]==="}"&&f--,f>0&&d++;let p=t.slice(n+2,d);return{part:F.parameterExpansion("",{type:"BadSubstitution",text:p}),endIndex:d+1}}}if(a===""&&!i&&!o&&t[s]!=="}"){let c=1,f=s;for(;f<t.length&&c>0;)t[f]==="{"?c++:t[f]==="}"&&c--,c>0&&f++;if(c>0)throw new ve("unexpected EOF while looking for matching '}'",0,0);let d=t.slice(n+2,f);return{part:F.parameterExpansion("",{type:"BadSubstitution",text:d}),endIndex:f+1}}let u=null;if(i){let c=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(c)if(s<t.length&&t[s]!=="}"&&/[:=\-+?#%/^,@]/.test(t[s])){let f=wi(e,t,s,a,r);f.operation?(u={type:"Indirection",innerOp:f.operation},s=f.endIndex):(u={type:"ArrayKeys",array:c[1],star:c[2]==="*"},a="")}else u={type:"ArrayKeys",array:c[1],star:c[2]==="*"},a="";else if(t[s]==="*"||t[s]==="@"&&!/[QPaAEKkuUL]/.test(t[s+1]||"")){let f=t[s];s++,u={type:"VarNamePrefix",prefix:a,star:f==="*"},a=""}else if(s<t.length&&t[s]!=="}"&&/[:=\-+?#%/^,@]/.test(t[s])){let f=wi(e,t,s,a,r);f.operation?(u={type:"Indirection",innerOp:f.operation},s=f.endIndex):u={type:"Indirection"}}else u={type:"Indirection"}}else if(o)if(t[s]===":")for(u={type:"LengthSliceError"};s<t.length&&t[s]!=="}";)s++;else t[s]!=="}"&&/[-+=?]/.test(t[s])?e.error(`\${#${a}${t.slice(s,t.indexOf("}",s))}}: bad substitution`):t[s]==="/"?e.error(`\${#${a}${t.slice(s,t.indexOf("}",s))}}: bad substitution`):u={type:"Length"};if(!u&&s<t.length&&t[s]!=="}"){let c=wi(e,t,s,a,r);u=c.operation,s=c.endIndex}if(s<t.length&&t[s]!=="}"){let c=t[s];if(!/[:\-+=?#%/^,@[]/.test(c)){let f=s;for(;f<t.length&&t[f]!=="}";)f++;let d=t.slice(n,f+1);e.error(`\${${d.slice(2,-1)}}: bad substitution`)}}for(;s<t.length&&t[s]!=="}";)s++;if(s>=t.length)throw new ve("unexpected EOF while looking for matching '}'",0,0);return{part:F.parameterExpansion(a,u),endIndex:s+1}}function wi(e,t,n,r,s=!1){let i=n,o=t[i],a=t[i+1]||"";if(o===":"){let l=a;if("-=?+".includes(l)){i+=2;let b=mn(e,t,i),w=t.slice(i,b),E=e.withDepth(()=>qt(e,w,!1,!1,!0,!1,s,!1,!1,!0)),S=F.word(ar(E));if(l==="-")return{operation:{type:"DefaultValue",word:S,checkEmpty:!0},endIndex:b};if(l==="=")return{operation:{type:"AssignDefault",word:S,checkEmpty:!0},endIndex:b};if(l==="?")return{operation:{type:"ErrorIfUnset",word:S,checkEmpty:!0},endIndex:b};if(l==="+")return{operation:{type:"UseAlternative",word:S,checkEmpty:!0},endIndex:b}}i++;let u=mn(e,t,i),c=t.slice(i,u),f=-1,d=0,p=0;for(let y=0;y<c.length;y++){let b=c[y];if(b==="("||b==="[")d++;else if(b===")"||b==="]")d--;else if(b==="?"&&d===0)p++;else if(b===":"&&d===0)if(p>0)p--;else{f=y;break}}let h=f>=0?c.slice(0,f):c,m=f>=0?c.slice(f+1):null;return{operation:{type:"Substring",offset:ii(e,h),length:m!==null?ii(e,m):null},endIndex:u}}if("-=?+".includes(o)){i++;let l=mn(e,t,i),u=t.slice(i,l),c=e.withDepth(()=>qt(e,u,!1,!1,!0,!1,s,!1,!1,!0)),f=F.word(ar(c));if(o==="-")return{operation:{type:"DefaultValue",word:f,checkEmpty:!1},endIndex:l};if(o==="=")return{operation:{type:"AssignDefault",word:f,checkEmpty:!1},endIndex:l};if(o==="?")return{operation:{type:"ErrorIfUnset",word:u?f:null,checkEmpty:!1},endIndex:l};if(o==="+")return{operation:{type:"UseAlternative",word:f,checkEmpty:!1},endIndex:l}}if(o==="#"||o==="%"){let l=a===o,u=o==="#"?"prefix":"suffix";i+=l?2:1;let c=mn(e,t,i),f=t.slice(i,c),d=e.withDepth(()=>qt(e,f,!1,!1,!1));return{operation:{type:"PatternRemoval",pattern:F.word(ar(d)),side:u,greedy:l},endIndex:c}}if(o==="/"){let l=a==="/";i+=l?2:1;let u=null;t[i]==="#"?(u="start",i++):t[i]==="%"&&(u="end",i++);let c;u!==null&&(t[i]==="/"||t[i]==="}")?c=i:c=al(e,t,i);let f=t.slice(i,c),d=e.withDepth(()=>qt(e,f,!1,!1,!1)),p=F.word(ar(d)),h=null,m=c;if(t[c]==="/"){let y=c+1,b=mn(e,t,y),w=t.slice(y,b),E=e.withDepth(()=>qt(e,w,!1,!1,!1));h=F.word(ar(E)),m=b}return{operation:{type:"PatternReplacement",pattern:p,replacement:h,all:l,anchor:u},endIndex:m}}if(o==="^"||o===","){let l=a===o,u=o==="^"?"upper":"lower";i+=l?2:1;let c=mn(e,t,i),f=t.slice(i,c),d=f?F.word([F.literal(f)]):null;return{operation:{type:"CaseModification",direction:u,all:l,pattern:d},endIndex:c}}return o==="@"&&/[QPaAEKkuUL]/.test(a)?{operation:{type:"Transform",operator:a},endIndex:i+2}:{operation:null,endIndex:i}}function Ei(e,t,n,r=!1){let s=n+1;if(s>=t.length)return{part:F.literal("$"),endIndex:s};let i=t[s];if(i==="("&&t[s+1]==="(")return e.isDollarDparenSubshell(t,n)?e.parseCommandSubstitution(t,n):e.parseArithmeticExpansion(t,n);if(i==="["){let o=1,a=s+1;for(;a<t.length&&o>0;)t[a]==="["?o++:t[a]==="]"&&o--,o>0&&a++;if(o===0){let l=t.slice(s+1,a),u=te(e,l);return{part:F.arithmeticExpansion(u),endIndex:a+1}}}return i==="("?e.parseCommandSubstitution(t,n):i==="{"?Dd(e,t,n,r):/[a-zA-Z_0-9@*#?$!-]/.test(i)?Rd(e,t,n):{part:F.literal("$"),endIndex:s}}function yl(e,t){let n=[],r=0,s="",i=()=>{s&&(n.push(F.literal(s)),s="")};for(;r<t.length;){let o=t[r];if(o==="\\"&&r+1<t.length){let a=t[r+1];if(a==="$"||a==="`"||a==='"'||a==="\\"){s+=a,r+=2;continue}s+=o,r++;continue}if(o==="$"){i();let{part:a,endIndex:l}=Ei(e,t,r,!0);a&&n.push(a),r=l;continue}if(o==="`"){i();let{part:a,endIndex:l}=e.parseBacktickSubstitution(t,r,!0);n.push(a),r=l;continue}s+=o,r++}return i(),n}function Id(e,t,n){let r=[],s=n,i="",o=()=>{i&&(r.push(F.literal(i)),i="")};for(;s<t.length&&t[s]!=='"';){let a=t[s];if(a==="\\"&&s+1<t.length){let l=t[s+1];if('"\\$`\n'.includes(l)){i+=l,s+=2;continue}i+=a,s++;continue}if(a==="$"){o();let{part:l,endIndex:u}=Ei(e,t,s,!0);l&&r.push(l),s=u;continue}if(a==="`"){o();let{part:l,endIndex:u}=e.parseBacktickSubstitution(t,s,!0);r.push(l),s=u;continue}i+=a,s++}return o(),{part:F.doubleQuoted(r),endIndex:s}}function qt(e,t,n=!1,r=!1,s=!1,i=!1,o=!1,a=!1,l=!1,u=!1,c=!0){if(r)return[F.singleQuoted(t)];if(n){let m=yl(e,t);return[F.doubleQuoted(m)]}if(t.length>=2&&t[0]==='"'&&t[t.length-1]==='"'){let m=t.slice(1,-1),y=!1;for(let b=0;b<m.length;b++){if(m[b]==='"'){y=!0;break}m[b]==="\\"&&b+1<m.length&&b++}if(!y){let b=yl(e,m);return[F.doubleQuoted(b)]}}let f=[],d=0,p="",h=()=>{p&&(f.push(F.literal(p)),p="")};for(;d<t.length;){let m=t[d];if(m==="\\"&&d+1<t.length){let y=t[d+1];if(l){h(),f.push(F.escaped(y)),d+=2;continue}if(!i&&!o){y!==`
73
+ `&&(h(),f.push(F.escaped(y))),d+=2;continue}let b=i?y==="$"||y==="`"||y===`
74
+ `:y==="$"||y==="`"||y==='"'||y==="'"||y===`
75
+ `||u&&y==="}",w=o?"*?[]\\".includes(y):"*?[]\\(){}.^+".includes(y);b?y!==`
76
+ `&&(p+=y):w?(h(),f.push(F.escaped(y))):p+=`\\${y}`,d+=2;continue}if(m==="'"&&!o&&!i){h();let y=t.indexOf("'",d+1);if(y===-1){p+=t.slice(d);break}f.push(F.singleQuoted(t.slice(d+1,y))),d=y+1;continue}if(m==='"'&&!i){h();let{part:y,endIndex:b}=Id(e,t,d+1);f.push(y),d=b+1;continue}if(m==="$"&&t[d+1]==="'"){h();let{part:y,endIndex:b}=ul(e,t,d+2);f.push(y),d=b;continue}if(m==="$"){h();let{part:y,endIndex:b}=Ei(e,t,d);y&&f.push(y),d=b;continue}if(m==="`"){h();let{part:y,endIndex:b}=e.parseBacktickSubstitution(t,d);f.push(y),d=b;continue}if((m==="<"||m===">")&&t[d+1]==="("&&!i&&!o){h();let{part:y,endIndex:b}=e.parseProcessSubstitutionFromString(t,d);f.push(y),d=b;continue}if(m==="~"){let y=d>0?t[d-1]:"";if(d===0&&c||y==="="||s&&y===":"){let w=ol(e,t,d),E=t[w];if(E===void 0||E==="/"||E===":"){h();let S=t.slice(d+1,w)||null;f.push({type:"TildeExpansion",user:S}),d=w;continue}}}if("@*+?!".includes(m)&&d+1<t.length&&t[d+1]==="("){let y=Nd(t,d+1);if(y!==-1){h();let b=t.slice(d,y+1);f.push({type:"Glob",pattern:b}),d=y+1;continue}}if(m==="*"||m==="?"||m==="["){h();let{pattern:y,endIndex:b}=ll(e,t,d);f.push({type:"Glob",pattern:l?Cd(y):y}),d=b;continue}if(m==="{"&&!s&&!a&&!i){let y=cl(e,t,d,qt);if(y){h(),f.push(y.part),d=y.endIndex;continue}}p+=m,d++}return h(),f}var G=class e{tokens=[];pos=0;pendingHeredocs=[];parseBudget;ownsParseBudget;_input="";processLineState;constructor(t){this.parseBudget=t??new Br,this.ownsParseBudget=t===void 0}getInput(){return this._input}checkIterationLimit(){let t=this.current();this.parseBudget.chargeIteration(t?.line??1,t?.column??1)}enterDepth(){let t=this.current();return this.parseBudget.enter(t?.line??1,t?.column??1)}withDepth(t){let n=this.enterDepth();try{return t()}finally{n()}}parse(t,n){this.ownsParseBudget&&this.parseBudget.reset();let r=this.ownsParseBudget?void 0:this.enterDepth();try{if(t.length>ti)throw new ve(`Input too large: ${t.length} bytes exceeds limit of ${ti}`,1,1);this._input=t,this.processLineState=void 0;let s=new Mr(t,n);if(this.tokens=s.tokenize(),this.tokens.length>rr)throw new ve(`Too many tokens: ${this.tokens.length} exceeds limit of ${rr}`,1,1);return this.pos=0,this.pendingHeredocs=[],this.parseBudget.chargeTokens(this.tokens.length),this.parseScript()}finally{r?.()}}parseTokens(t){this.ownsParseBudget&&this.parseBudget.reset();let n=this.ownsParseBudget?void 0:this.enterDepth();try{return this.tokens=t,this.pos=0,this.pendingHeredocs=[],this.processLineState=void 0,this.parseBudget.chargeTokens(t.length),this.parseScript()}finally{n?.()}}current(){return this.tokens[this.pos]||this.tokens[this.tokens.length-1]}peek(t=0){return this.tokens[this.pos+t]||this.tokens[this.tokens.length-1]}advance(){let t=this.current();return this.pos<this.tokens.length-1&&this.pos++,t}getPos(){return this.pos}getSourceLine(t=this.current()){let n=this.processLineState;return n?(n.currentPhysicalLine===void 0?n.currentPhysicalLine=t.line:t.line>n.currentPhysicalLine&&(n.currentPhysicalLine=t.line,n.currentLogicalLine+=1),n.currentLogicalLine):t.line}check(t,n,r,s,...i){let o=this.tokens[this.pos]?.type;return o===t||n!==void 0&&o===n||r!==void 0&&o===r||s!==void 0&&o===s?!0:i.length>0?i.includes(o):!1}expect(t,n){if(this.check(t))return this.advance();let r=this.current();throw new ve(n||`Expected ${t}, got ${r.type}`,r.line,r.column,r)}error(t){let n=this.current();throw new ve(t,n.line,n.column,n)}skipNewlines(){for(;this.check(g.NEWLINE,g.COMMENT);)this.check(g.NEWLINE)?(this.advance(),this.processHeredocs()):this.advance()}skipSeparators(t=!0){for(;;){if(this.check(g.NEWLINE)){this.advance(),this.processHeredocs();continue}if(this.check(g.SEMICOLON,g.COMMENT)){this.advance();continue}if(t&&this.check(g.DSEMI,g.SEMI_AND,g.SEMI_SEMI_AND)){this.advance();continue}break}}addPendingHeredoc(t,n,r,s){this.pendingHeredocs.push({redirect:t,delimiter:n,stripTabs:r,quoted:s})}processHeredocs(){for(let t of this.pendingHeredocs)if(this.check(g.HEREDOC_CONTENT)){let n=this.advance(),r;t.quoted?r=F.word([F.literal(n.value)]):r=this.parseWordFromString(n.value,!1,!1,!1,!0),t.redirect.target=F.hereDoc(t.delimiter,r,t.stripTabs,t.quoted,n.heredocTerminated??!1)}this.pendingHeredocs=[]}isStatementEnd(){return this.check(g.EOF,g.NEWLINE,g.SEMICOLON,g.AMP,g.AND_AND,g.OR_OR,g.RPAREN,g.RBRACE,g.DSEMI,g.SEMI_AND,g.SEMI_SEMI_AND)}isCommandStart(){let t=this.current().type;return this.isWord()||t===g.ASSIGNMENT_WORD||t===g.FD_VARIABLE||t===g.LPAREN||t===g.LBRACE||t===g.DPAREN_START||t===g.DBRACK_START||or(this)}parseScript(){let t=[],r=0;for(this.skipNewlines();!this.check(g.EOF);){r++,r>1e4&&this.error("Parser stuck: too many iterations (>10000)");let s=this.checkUnexpectedToken();if(s){t.push(s),this.skipSeparators(!1);continue}let i=this.pos,o=this.parseStatement();o&&t.push(o),this.check(g.HEREDOC_CONTENT)&&this.processHeredocs(),this.skipSeparators(!1),this.check(g.DSEMI,g.SEMI_AND,g.SEMI_SEMI_AND)&&this.error(`syntax error near unexpected token \`${this.current().value}'`),this.pos===i&&!this.check(g.EOF)&&this.error(`syntax error near unexpected token \`${this.current().value}'`)}return F.script(t)}checkUnexpectedToken(){let t=this.current().type,n=this.current().value;if(this.currentTokenJoinsProcessSubstitution())return null;if((t===g.DO||t===g.DONE||t===g.THEN||t===g.ELSE||t===g.ELIF||t===g.FI||t===g.ESAC)&&this.error(`syntax error near unexpected token \`${n}'`),t===g.RBRACE||t===g.RPAREN){let r=`syntax error near unexpected token \`${n}'`;return this.advance(),F.statement([F.pipeline([F.simpleCommand(null,[],[],[])])],[],!1,{message:r,token:n})}return(t===g.DSEMI||t===g.SEMI_AND||t===g.SEMI_SEMI_AND)&&this.error(`syntax error near unexpected token \`${n}'`),t===g.SEMICOLON&&this.error(`syntax error near unexpected token \`${n}'`),(t===g.AMP||t===g.AND_AND||t===g.OR_OR||t===g.PIPE||t===g.PIPE_AMP)&&this.error(`syntax error near unexpected token \`${n}'`),null}parseStatement(){if(this.skipNewlines(),!this.isCommandStart())return null;let t=this.current().start,n=[],r=[],s=!1,i=this.parsePipeline();for(n.push(i);this.check(g.AND_AND,g.OR_OR);){let l=this.advance();r.push(l.type===g.AND_AND?"&&":"||"),this.skipNewlines();let u=this.parsePipeline();n.push(u)}this.check(g.AMP)&&(this.advance(),s=!0);let o=this.pos>0?this.tokens[this.pos-1].end:t,a=this._input.slice(t,o);return F.statement(n,r,s,void 0,a)}parseTimePrefix(){if(!this.check(g.TIME)||this.currentTokenJoinsProcessSubstitution())return;this.advance();let t=!1;return this.check(g.WORD,g.NAME)&&this.current().value==="-p"&&(this.advance(),t=!0),t}parsePipeline(){let t=!1,n=!1,r=0;for(;this.check(g.BANG)&&!this.currentTokenJoinsProcessSubstitution();)this.advance(),r++;if(r===0){let l=this.parseTimePrefix();if(l!==void 0)for(t=!0,n=l;this.check(g.BANG)&&!this.currentTokenJoinsProcessSubstitution();)this.advance(),r++}let s=r%2===1,i=[],o=[],a=this.parseCommand();for(i.push(a);this.check(g.PIPE,g.PIPE_AMP);){let l=this.advance();this.skipNewlines(),o.push(l.type===g.PIPE_AMP);let u=this.parseCommand();i.push(u)}return F.pipeline(i,s,t,n,o.length>0?o:void 0)}parseCommand(){if(this.currentTokenJoinsProcessSubstitution())return li(this);let t=this.current();switch(t.type){case g.IF:return ui(this);case g.FOR:return ci(this);case g.WHILE:return fi(this);case g.UNTIL:return di(this);case g.CASE:return pi(this);case g.LPAREN:return hi(this);case g.LBRACE:return mi(this);case g.DPAREN_START:return this.dparenClosesWithSpacedParens()?this.parseNestedSubshellsFromDparen():this.parseArithmeticCommand();case g.DBRACK_START:return this.parseConditionalCommand();case g.FUNCTION:return this.parseFunctionDef();case g.TIME:break;case g.BANG:this.error(`syntax error near unexpected token \`${t.value}'`);break;default:ei(t.type)&&this.error(`syntax error near unexpected token \`${t.value}'`)}return this.check(g.NAME,g.WORD)&&this.peek(1).type===g.LPAREN&&this.peek(2).type===g.RPAREN?this.parseFunctionDef():li(this)}dparenClosesWithSpacedParens(){let t=1,n=1;for(;n<this.tokens.length-this.pos;){let r=this.peek(n);if(r.type===g.EOF)return!1;if(r.type===g.DPAREN_START||r.type===g.LPAREN)t++;else if(r.type===g.DPAREN_END){if(t-=2,t<=0)return!1}else if(r.type===g.RPAREN&&(t--,t===0&&this.peek(n+1).type===g.RPAREN))return!0;n++}return!1}parseNestedSubshellsFromDparen(){this.advance();let t=this.parseCompoundList();this.expect(g.RPAREN),this.expect(g.RPAREN);let n=this.parseOptionalRedirections(),r=F.subshell(t,[]);return F.subshell([F.statement([F.pipeline([r],!1,!1,!1)])],n)}isWord(){return this.isWordToken(Pe.Default)||this.isProcessSubstitutionStart()||this.currentTokenJoinsProcessSubstitution()}isWordToken(t){let n=this.current().type;return n===g.WORD||n===g.NAME||n===g.NUMBER||ei(n)||n===g.BANG||n===g.ASSIGNMENT_WORD&&(t&Pe.Regex)!==0}isProcessSubstitutionStart(t=0){let n=this.peek(t),r=this.peek(t+1);return(n.type===g.LESS||n.type===g.GREAT)&&r.type===g.LPAREN&&n.end===r.start}currentTokenJoinsProcessSubstitution(){return this.current().type===g.COMMENT||!this.isAdjacentWordToken(Pe.Default)?!1:this.current().end===this.peek(1).start&&this.isProcessSubstitutionStart(1)}isAdjacentWordToken(t){let n=this.current().type;return this.isWordToken(t)||n===g.ASSIGNMENT_WORD||n===g.COMMENT||n===g.LBRACE||n===g.RBRACE||n===g.DBRACK_START||n===g.DBRACK_END||n===g.FD_VARIABLE}parseWord(t=Pe.Default){if(this.isProcessSubstitutionStart())return this.parseAdjacentWordParts([],this.current().start,t);let n=this.advance(),r=this.parseWordToken(n,t);return this.parseAdjacentWordParts(r.parts,n.end,t)}parseAdjacentWordParts(t,n,r=Pe.Default){for(;n===this.current().start;){if(this.isProcessSubstitutionStart()){t.push(this.parseProcessSubstitution()),n=this.tokens[this.pos-1].end;continue}if(!this.isAdjacentWordToken(r))break;let s=this.advance();t.push(...this.parseWordToken(s,r,t.length===0).parts),n=s.end}return F.word(t)}parseWordNoBraceExpansion(){return this.parseWord(Pe.NoBraceExpansion)}parseWordForRegex(){return this.parseWord(Pe.NoBraceExpansion|Pe.Regex)}parseWordToken(t,n,r=!0){return t.type===g.LBRACE||t.type===g.RBRACE||t.type===g.DBRACK_START||t.type===g.DBRACK_END||t.type===g.FD_VARIABLE?F.word([F.literal(t.type===g.FD_VARIABLE?`{${t.value}}`:t.value)]):this.parseWordFromString(t.value,t.quoted,t.singleQuoted,(n&Pe.Assignment)!==0,!1,(n&Pe.NoBraceExpansion)!==0,(n&Pe.Regex)!==0,r)}parseWordFromString(t,n=!1,r=!1,s=!1,i=!1,o=!1,a=!1,l=!0){let u=qt(this,t,n,r,s,i,!1,o,a,!1,l);return F.word(u)}parseCommandSubstitution(t,n){return Ta(t,n,()=>new e(this.parseBudget),r=>this.error(r))}parseProcessSubstitutionFromString(t,n){return Fa(t,n,()=>new e(this.parseBudget),r=>this.error(r))}parseProcessSubstitution(){let t=this.advance();this.expect(g.LPAREN);let n=this.processLineState,r=this.getSourceLine(t);this.processLineState={currentLogicalLine:r};let s;try{s=F.script(this.parseCompoundList())}finally{this.processLineState=n}return this.check(g.EOF)&&this.error("unexpected EOF while looking for matching `)'"),this.expect(g.RPAREN),F.processSubstitution(s,t.type===g.LESS?"input":"output")}parseBacktickSubstitution(t,n,r=!1){return Ma(t,n,r,()=>new e(this.parseBudget),s=>this.error(s))}isDollarDparenSubshell(t,n){return _a(t,n)}parseArithmeticExpansion(t,n){let r=n+3,s=1,i=0,o=r;for(;o<t.length-1&&s>0;)t[o]==="$"&&t[o+1]==="("?t[o+2]==="("?(s++,o+=3):(i++,o+=2):t[o]==="("&&t[o+1]==="("?(s++,o+=2):t[o]===")"&&t[o+1]===")"?i>0?(i--,o++):(s--,s>0&&(o+=2)):t[o]==="("?(i++,o++):(t[o]===")"&&i>0&&i--,o++);let a=t.slice(r,o),l=this.parseArithmeticExpression(a);return{part:F.arithmeticExpansion(l),endIndex:o+2}}parseArithmeticCommand(){let t=this.expect(g.DPAREN_START),n="",r=1,s=0,i=!1,o=!1;for(;r>0&&!this.check(g.EOF);){if(i){if(i=!1,s>0){s--,n+=")";continue}if(this.check(g.RPAREN)){r--,o=!0,this.advance();continue}if(this.check(g.DPAREN_END)){r--,o=!0;continue}n+=")";continue}if(this.check(g.DPAREN_START))r++,n+="((",this.advance();else if(this.check(g.DPAREN_END))s>=2?(s-=2,n+="))",this.advance()):s===1?(s--,n+=")",i=!0,this.advance()):(r--,o=!0,r>0&&(n+="))"),this.advance());else if(this.check(g.LPAREN))s++,n+="(",this.advance();else if(this.check(g.RPAREN))s>0&&s--,n+=")",this.advance();else{let u=this.current().value,c=n.length>0?n[n.length-1]:"";n.length>0&&!n.endsWith(" ")&&!(u==="="&&/[|&^+\-*/%<>]$/.test(n))&&!(u==="<"&&c==="<")&&!(u===">"&&c===">")&&(n+=" "),n+=u,this.advance()}}o||this.expect(g.DPAREN_END);let a=this.parseArithmeticExpression(n.trim()),l=this.parseOptionalRedirections();return F.arithmeticCommand(a,l,this.getSourceLine(t))}parseConditionalCommand(){let t=this.expect(g.DBRACK_START),n=gi(this);this.expect(g.DBRACK_END);let r=this.parseOptionalRedirections();return F.conditionalCommand(n,r,this.getSourceLine(t))}parseFunctionDef(){let t;if(this.check(g.FUNCTION)){if(this.advance(),this.check(g.NAME)||this.check(g.WORD))t=this.advance().value;else{let s=this.current();throw new ve("Expected function name",s.line,s.column,s)}this.check(g.LPAREN)&&(this.advance(),this.expect(g.RPAREN))}else t=this.advance().value,t.includes("$")&&this.error(`\`${t}': not a valid identifier`),this.expect(g.LPAREN),this.expect(g.RPAREN);this.skipNewlines();let n=this.parseCompoundCommandBody({forFunctionBody:!0}),r=this.parseOptionalRedirections();return F.functionDef(t,n,r)}parseCompoundCommandBody(t){let n=t?.forFunctionBody;if(this.check(g.LBRACE))return mi(this,{skipRedirections:n});if(this.check(g.LPAREN))return hi(this,{skipRedirections:n});if(this.check(g.IF))return ui(this,{skipRedirections:n});if(this.check(g.FOR))return ci(this,{skipRedirections:n});if(this.check(g.WHILE))return fi(this,{skipRedirections:n});if(this.check(g.UNTIL))return di(this,{skipRedirections:n});if(this.check(g.CASE))return pi(this,{skipRedirections:n});this.error("Expected compound command for function body")}parseCompoundList(){let t=this.enterDepth();try{let n=[];for(this.skipNewlines();(this.currentTokenJoinsProcessSubstitution()||!this.check(g.EOF,g.FI,g.ELSE,g.ELIF,g.THEN,g.DO,g.DONE,g.ESAC,g.RPAREN,g.RBRACE,g.DSEMI,g.SEMI_AND,g.SEMI_SEMI_AND))&&this.isCommandStart();){this.checkIterationLimit();let r=this.pos,s=this.parseStatement();if(s&&n.push(s),this.skipSeparators(),this.pos===r&&!s)break}return n}finally{t()}}parseOptionalRedirections(){let t=[];for(;or(this);){this.checkIterationLimit();let n=this.pos;if(t.push(qr(this)),this.pos===n)break}return t}parseArithmeticExpression(t){return te(this,t)}};function ft(e,t){return new G().parse(e,t)}function gl(e){return gn(e)}function gn(e){return e.statements.map(wl).join(`
77
+ `)}function wl(e){let t=[];for(let r=0;r<e.pipelines.length;r++)t.push(_d(e.pipelines[r])),r<e.operators.length&&t.push(e.operators[r]);let n=t.join(" ");return e.background&&(n+=" &"),n}function _d(e){let t=[];e.timed&&t.push(e.timePosix?"time -p":"time"),e.negated&&t.push("!");let n=[];for(let s=0;s<e.commands.length;s++)if(n.push(El(e.commands[s])),s<e.commands.length-1){let i=e.pipeStderr?.[s];n.push(i?"|&":"|")}return(t.length>0?`${t.join(" ")} `:"")+n.join(" ")}function El(e){switch(e.type){case"SimpleCommand":return Ld(e);case"If":return Ud(e);case"For":return jd(e);case"CStyleFor":return Gd(e);case"While":return Hd(e);case"Until":return Zd(e);case"Case":return Qd(e);case"Subshell":return Xd(e);case"Group":return Yd(e);case"ArithmeticCommand":return Jd(e);case"ConditionalCommand":return ep(e);case"FunctionDef":return tp(e);default:{let t=e;throw new Error(`Unsupported command type: ${t.type}`)}}}function Ld(e){let t=[];for(let n of e.assignments)t.push(Td(n));e.name&&t.push(be(e.name));for(let n of e.args)t.push(be(n));for(let n of e.redirections)t.push(Al(n));return t.join(" ")}function Td(e){let t=e.append?"+=":"=";if(e.array){let n=e.array.map(be).join(" ");return`${e.name}${t}(${n})`}return e.value?`${e.name}${t}${be(e.value)}`:`${e.name}${t}`}function be(e){return e.parts.map(t=>Ur(t,!1)).join("")}function Ut(e){return e.parts.map(t=>Ur(t,!0)).join("")}function Ur(e,t){switch(e.type){case"Literal":return t?Md(e.value):Fd(e.value);case"SingleQuoted":return`'${e.value}'`;case"DoubleQuoted":return`"${e.parts.map(n=>Ur(n,!0)).join("")}"`;case"Escaped":return`\\${e.value}`;case"ParameterExpansion":return bl(e);case"CommandSubstitution":return e.legacy?`\`${gn(e.body)}\``:`$(${gn(e.body)})`;case"ArithmeticExpansion":return`$((${fe(e.expression.expression)}))`;case"ProcessSubstitution":return e.direction==="input"?`<(${gn(e.body)})`:`>(${gn(e.body)})`;case"BraceExpansion":return zd(e);case"TildeExpansion":return e.user!==null?`~${e.user}`:"~";case"Glob":return e.pattern;default:{let n=e;throw new Error(`Unsupported word part type: ${n.type}`)}}}function Fd(e){return e.replace(/[\s\\'"`!|&;()<>{}[\]*?~#]/g,"\\$&")}function Md(e){return e.replace(/[$`"\\]/g,"\\$&")}function Bd(e,t){return e.parts.map(n=>Wd(n,t)).join("")}function Wd(e,t){switch(e.type){case"Literal":return t?e.value:e.value.replace(/[$`]/g,"\\$&");case"Escaped":return`\\${e.value}`;case"ParameterExpansion":return bl(e);case"CommandSubstitution":return e.legacy?`\`${gn(e.body)}\``:`$(${gn(e.body)})`;case"ArithmeticExpansion":return`$((${fe(e.expression.expression)}))`;default:return Ur(e,!1)}}function bl(e){return e.operation?`\${${Sl(e.parameter,e.operation)}}`:Vd(e.parameter)?`\${${e.parameter}}`:`$${e.parameter}`}function Vd(e){return!(/^[?#@*$!\-0-9]$/.test(e)||/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e))}function Sl(e,t){switch(t.type){case"Length":return`#${e}`;case"LengthSliceError":return`#${e}:`;case"BadSubstitution":return t.text;case"DefaultValue":return`${e}${t.checkEmpty?":":""}-${Ut(t.word)}`;case"AssignDefault":return`${e}${t.checkEmpty?":":""}=${Ut(t.word)}`;case"ErrorIfUnset":return`${e}${t.checkEmpty?":":""}?${t.word?Ut(t.word):""}`;case"UseAlternative":return`${e}${t.checkEmpty?":":""}+${Ut(t.word)}`;case"Substring":{let n=fe(t.offset.expression);return t.length?`${e}:${n}:${fe(t.length.expression)}`:`${e}:${n}`}case"PatternRemoval":{let n=t.side==="prefix"?"#":"%",r=t.greedy?`${n}${n}`:n;return`${e}${r}${Ut(t.pattern)}`}case"PatternReplacement":{let n="/";t.all?n="//":t.anchor==="start"?n="/#":t.anchor==="end"&&(n="/%");let r=t.replacement?`/${Ut(t.replacement)}`:"";return`${e}${n}${Ut(t.pattern)}${r}`}case"CaseModification":{let n=t.direction==="upper"?"^":",",r=t.all?`${n}${n}`:n,s=t.pattern?Ut(t.pattern):"";return`${e}${r}${s}`}case"Transform":return`${e}@${t.operator}`;case"Indirection":return t.innerOp?`!${Sl(e,t.innerOp)}`:`!${e}`;case"ArrayKeys":return`!${t.array}[${t.star?"*":"@"}]`;case"VarNamePrefix":return`!${t.prefix}${t.star?"*":"@"}`;default:{let n=t;throw new Error(`Unsupported parameter operation type: ${n.type}`)}}}function zd(e){return`{${e.items.map(qd).join(",")}}`}function qd(e){if(e.type==="Word")return be(e.word);let t=e.startStr??String(e.start),n=e.endStr??String(e.end);return e.step!==void 0?`${t}..${n}..${e.step}`:`${t}..${n}`}function Al(e){let t=e.fdVariable?`{${e.fdVariable}}`:e.fd!==null?String(e.fd):"";if(e.operator==="<<"||e.operator==="<<-"){let n=e.target;if(n.terminated===!1)throw new Error("Cannot serialize an unterminated here-document");let r=n.quoted?`'${n.delimiter}'`:n.delimiter,s=Bd(n.content,n.quoted);return`${t}${e.operator}${r}
78
+ ${s}${n.delimiter}`}return e.operator==="<<<"?`${t}<<< ${be(e.target)}`:e.operator==="&>"||e.operator==="&>>"?`${e.operator} ${be(e.target)}`:`${t}${e.operator} ${be(e.target)}`}function dt(e){return e.length===0?"":` ${e.map(Al).join(" ")}`}function rt(e){return e.map(wl).join(`
79
+ `)}function Ud(e){let t=[];for(let n=0;n<e.clauses.length;n++){let r=e.clauses[n],s=n===0?"if":"elif";t.push(`${s} ${rt(r.condition)}; then
80
+ ${rt(r.body)}`)}return e.elseBody&&t.push(`else
81
+ ${rt(e.elseBody)}`),`${t.join(`
82
82
  `)}
83
- fi${pt(e.redirections)}`}function Bd(e){let t;if(e.words===null)t=`for ${e.variable}`;else{let n=e.words.map(Se).join(" ");t=`for ${e.variable} in ${n}`}return`${t}; do
84
- ${st(e.body)}
85
- done${pt(e.redirections)}`}function Wd(e){let t=e.init?fe(e.init.expression):"",n=e.condition?fe(e.condition.expression):"",r=e.update?fe(e.update.expression):"";return`for ((${t}; ${n}; ${r})); do
86
- ${st(e.body)}
87
- done${pt(e.redirections)}`}function Vd(e){return`while ${st(e.condition)}; do
88
- ${st(e.body)}
89
- done${pt(e.redirections)}`}function zd(e){return`until ${st(e.condition)}; do
90
- ${st(e.body)}
91
- done${pt(e.redirections)}`}function qd(e){let t=e.items.map(Ud).join(`
92
- `);return`case ${Se(e.word)} in
83
+ fi${dt(e.redirections)}`}function jd(e){let t;if(e.words===null)t=`for ${e.variable}`;else{let n=e.words.map(be).join(" ");t=`for ${e.variable} in ${n}`}return`${t}; do
84
+ ${rt(e.body)}
85
+ done${dt(e.redirections)}`}function Gd(e){let t=e.init?fe(e.init.expression):"",n=e.condition?fe(e.condition.expression):"",r=e.update?fe(e.update.expression):"";return`for ((${t}; ${n}; ${r})); do
86
+ ${rt(e.body)}
87
+ done${dt(e.redirections)}`}function Hd(e){return`while ${rt(e.condition)}; do
88
+ ${rt(e.body)}
89
+ done${dt(e.redirections)}`}function Zd(e){return`until ${rt(e.condition)}; do
90
+ ${rt(e.body)}
91
+ done${dt(e.redirections)}`}function Qd(e){let t=e.items.map(Kd).join(`
92
+ `);return`case ${be(e.word)} in
93
93
  ${t}
94
- esac${pt(e.redirections)}`}function Ud(e){let t=e.patterns.map(Se).join(" | "),n=st(e.body);return n?`${t})
94
+ esac${dt(e.redirections)}`}function Kd(e){let t=e.patterns.map(be).join(" | "),n=rt(e.body);return n?`${t})
95
95
  ${n}
96
96
  ${e.terminator}`:`${t})
97
- ${e.terminator}`}function jd(e){return`(${st(e.body)})${pt(e.redirections)}`}function Gd(e){return`{ ${st(e.body)}; }${pt(e.redirections)}`}function Hd(e){return`((${fe(e.expression.expression)}))${pt(e.redirections)}`}function Zd(e){return`[[ ${yn(e.expression)} ]]${pt(e.redirections)}`}function Qd(e){let t=ml(e.body);return`${e.name}() ${t}${pt(e.redirections)}`}function fe(e){switch(e.type){case"ArithNumber":return String(e.value);case"ArithVariable":return e.hasDollarPrefix?`$${e.name}`:e.name;case"ArithSpecialVar":return`$${e.name}`;case"ArithBinary":return`${fe(e.left)} ${e.operator} ${fe(e.right)}`;case"ArithUnary":return e.prefix?`${e.operator}${fe(e.operand)}`:`${fe(e.operand)}${e.operator}`;case"ArithTernary":return`${fe(e.condition)} ? ${fe(e.consequent)} : ${fe(e.alternate)}`;case"ArithAssignment":return`${e.subscript?`${e.variable}[${fe(e.subscript)}]`:e.stringKey!==void 0?`${e.variable}[${e.stringKey}]`:e.variable} ${e.operator} ${fe(e.value)}`;case"ArithDynamicAssignment":return`${e.subscript?`${fe(e.target)}[${fe(e.subscript)}]`:fe(e.target)} ${e.operator} ${fe(e.value)}`;case"ArithDynamicElement":return`${fe(e.nameExpr)}[${fe(e.subscript)}]`;case"ArithGroup":return`(${fe(e.expression)})`;case"ArithNested":return`$((${fe(e.expression)}))`;case"ArithCommandSubst":return`$(${e.command})`;case"ArithBracedExpansion":return`\${${e.content}}`;case"ArithArrayElement":return e.stringKey!==void 0?`${e.array}[${e.stringKey}]`:e.index?`${e.array}[${fe(e.index)}]`:e.array;case"ArithDynamicBase":return`\${${e.baseExpr}}#${e.value}`;case"ArithDynamicNumber":return`\${${e.prefix}}${e.suffix}`;case"ArithConcat":return e.parts.map(fe).join("");case"ArithDoubleSubscript":return`${e.array}[${fe(e.index)}]`;case"ArithNumberSubscript":return`${e.number}[${e.errorToken}]`;case"ArithSyntaxError":return e.errorToken;case"ArithSingleQuote":return`'${e.content}'`;default:{let t=e;throw new Error(`Unsupported arithmetic expression type: ${t.type}`)}}}function yn(e){switch(e.type){case"CondBinary":return`${Se(e.left)} ${e.operator} ${Se(e.right)}`;case"CondUnary":return`${e.operator} ${Se(e.operand)}`;case"CondNot":return`! ${yn(e.operand)}`;case"CondAnd":return`${yn(e.left)} && ${yn(e.right)}`;case"CondOr":return`${yn(e.left)} || ${yn(e.right)}`;case"CondGroup":return`( ${yn(e.expression)} )`;case"CondWord":return Se(e.word);default:{let t=e;throw new Error(`Unsupported conditional expression type: ${t.type}`)}}}var Kd="BASH_ALIAS_";function Vr(e,t,n,r){let s=F(t);if(s>n-r.value)throw new P(`alias expansion exceeds string length limit (${n} bytes)`,"string_length");return r.value+=s,e+t}function El(e){return e.parts.length!==1?!1:e.parts[0].type==="Literal"}function bl(e){if(e.parts.length!==1)return null;let t=e.parts[0];return t.type==="Literal"?t.value:null}function Sl(e,t){return e.env.get(`${Kd}${t}`)}function vl(e,t,n){return xl(e,t,n)}function xl(e,t,n,r=!0){if(!t.name||!El(t.name))return t;let s=bl(t.name);if(!s)return t;let i=Sl(e,s);if(!i||n.has(s))return t;try{n.add(s);let o=new j,a={value:0},l=Vr("",i,e.limits.maxStringLength,a),u=i.endsWith(" ");if(!u)for(let p of t.args){let h=Se(p);l=Vr(l,` ${h}`,e.limits.maxStringLength,a)}let c;try{c=o.parse(l)}catch(p){if(p instanceof xe)throw p;return t}if(c.statements.length!==1||c.statements[0].pipelines.length!==1||c.statements[0].pipelines[0].commands.length!==1)return Al(e,t,i);let f=c.statements[0].pipelines[0].commands[0];if(f.type!=="SimpleCommand")return Al(e,t,i);let d={...f,assignments:[...t.assignments,...f.assignments],redirections:[...f.redirections,...t.redirections],line:t.line};if(u&&t.args.length>0){d={...d,args:[...d.args,...t.args]};let p=1;for(;r&&d.args.length>0;){let h=d.args[0];if(!El(h))break;let m=bl(h),E=m?Sl(e,m):null;if(!E)break;if(p>=e.limits.maxCallDepth)throw new P(`alias expansion depth limit exceeded (${e.limits.maxCallDepth})`,"recursion");p++;let S={type:"SimpleCommand",name:h,args:d.args.slice(1),assignments:[],redirections:[]},y=xl(e,S,n,!1);if(y===S||(d={...d,name:y.name,args:[...y.args]},!E.endsWith(" ")))break}}return d}catch(o){throw n.delete(s),o}}function Al(e,t,n){let r={value:0},s=Vr("",n,e.limits.maxStringLength,r);for(let u of t.args){let c=Se(u);s=Vr(s,` ${c}`,e.limits.maxStringLength,r)}let i=new j,o=i.parseWordFromString("eval",!1,!1),a=0;for(let u of s)u==="'"&&a++;if(r.value+2+a*3>e.limits.maxStringLength)throw new P(`alias expansion exceeds string length limit (${e.limits.maxStringLength} bytes)`,"string_length");let l=i.parseWordFromString(`'${s.replace(/'/g,"'\\''")}'`,!1,!1);return{type:"SimpleCommand",name:o,args:[l],assignments:t.assignments,redirections:t.redirections,line:t.line}}var Xd=new Map([["alnum","a-zA-Z0-9"],["alpha","a-zA-Z"],["ascii","\\x00-\\x7F"],["blank"," \\t"],["cntrl","\\x00-\\x1F\\x7F"],["digit","0-9"],["graph","!-~"],["lower","a-z"],["print"," -~"],["punct","!-/:-@\\[-`{-~"],["space"," \\t\\n\\r\\f\\v"],["upper","A-Z"],["word","a-zA-Z0-9_"],["xdigit","0-9a-fA-F"]]);function wi(e){return Xd.get(e)??""}function $l(e){let t=[],n="",r=0;for(;r<e.length;){let s=e[r];if(s==="["){for(n+=s,r++,r<e.length&&(e[r]==="!"||e[r]==="^")&&(n+=e[r],r++),r<e.length&&e[r]==="]"&&(n+=e[r],r++);r<e.length&&e[r]!=="]";){if(e[r]==="["&&r+1<e.length&&e[r+1]===":"){let i=e.indexOf(":]",r+2);if(i!==-1){n+=e.slice(r,i+2),r=i+2;continue}}if(e[r]==="\\"&&r+1<e.length){n+=e[r]+e[r+1],r+=2;continue}n+=e[r],r++}r<e.length&&e[r]==="]"&&(n+=e[r],r++)}else s===":"?(n!==""&&t.push(n),n="",r++):s==="\\"&&r+1<e.length?(n+=s+e[r+1],r+=2):(n+=s,r++)}return n!==""&&t.push(n),t}function kl(e){let t="^";for(let n=0;n<e.length;n++){let r=e[n];if(r==="*")t+="[^/]*";else if(r==="?")t+="[^/]";else if(r==="["){let s=n+1,i="[";s<e.length&&(e[s]==="^"||e[s]==="!")&&(i+="^",s++),s<e.length&&e[s]==="]"&&(i+="\\]",s++);let o=s;for(;o<e.length;){if(e[o]==="\\"&&o+1<e.length){o+=2;continue}if(e[o]==="["&&o+1<e.length&&e[o+1]===":"){let l=e.indexOf(":]",o+2);if(l!==-1){o=l+2;continue}}if(e[o]==="]")break;o++}let a=s;for(;s<e.length&&e[s]!=="]";){if(e[s]==="["&&s+1<e.length&&e[s+1]===":"){let l=e.indexOf(":]",s+2);if(l!==-1){let u=e.slice(s+2,l),c=wi(u);i+=c,s=l+2;continue}}if(e[s]==="\\"&&s+1<e.length){i+=`\\${e[s+1]}`,s+=2;continue}if(e[s]==="-"){let l=s===a,u=s+1===o;l||u?i+="\\-":i+="-"}else i+=e[s];s++}i+="]",t+=i,n=s}else if(r==="\\"&&n+1<e.length){let s=e[n+1];/[.+^${}()|\\*?[\]]/.test(s)?t+=`\\${s}`:t+=s,n++}else/[.+^${}()|]/.test(r)?t+=`\\${r}`:t+=r}return t+="$",me(t)}function Ei(e,t){let n=1,r=t+1;for(;r<e.length&&n>0;){let s=e[r];if(s==="\\"){r+=2;continue}if(s==="(")n++;else if(s===")"&&(n--,n===0))return r;r++}return-1}function bi(e){let t=[],n="",r=0,s=!1,i=0;for(;i<e.length;){let o=e[i];if(o==="'"&&!s){s=!0,n+="\0QUOTE_START\0",i++;continue}if(o==="'"&&s){s=!1,n+="\0QUOTE_END\0",i++;continue}if(s){n+=o,i++;continue}if(o==="\\"){n+=o,i+1<e.length?(n+=e[i+1],i+=2):i++;continue}o==="("?(r++,n+=o):o===")"?(r--,n+=o):o==="|"&&r===0?(t.push(n),n=""):n+=o,i++}return t.push(n),t}var Pl=5,jt=class{fs;cwd;globignorePatterns=[];hasGlobignore=!1;globstar=!1;nullglob=!1;failglob=!1;dotglob=!1;extglob=!1;globskipdots=!0;ops={count:0};maxOps;consumeOperation;constructor(t,n,r,s){this.fs=t,this.cwd=n,typeof s=="boolean"?(this.globstar=s,this.maxOps=1e5):s?(this.globstar=s.globstar??!1,this.nullglob=s.nullglob??!1,this.failglob=s.failglob??!1,this.dotglob=s.dotglob??!1,this.extglob=s.extglob??!1,this.globskipdots=s.globskipdots??!0,this.maxOps=s.maxGlobOperations??1e5,this.consumeOperation=s.consumeOperation):this.maxOps=1e5;let i=r?.get("GLOBIGNORE");i!==void 0&&i!==""&&(this.hasGlobignore=!0,this.globignorePatterns=$l(i))}checkOpsLimit(){if(++this.ops.count>this.maxOps)throw new P(`Glob operation limit exceeded (${this.maxOps})`,"glob_operations");this.consumeOperation?.()}hasNullglob(){return this.nullglob}hasFailglob(){return this.failglob}filterGlobignore(t){return!this.hasGlobignore&&!this.globskipdots?t:t.filter(n=>{let r=n.split("/").pop()||n;if((this.hasGlobignore||this.globskipdots)&&(r==="."||r===".."))return!1;if(this.hasGlobignore){for(let s of this.globignorePatterns)if(this.matchGlobignorePattern(n,s))return!1}return!0})}matchGlobignorePattern(t,n){return kl(n).test(t)}isGlobPattern(t){return!!(t.includes("*")||t.includes("?")||/\[.*\]/.test(t)||this.extglob&&/[@*+?!]\(/.test(t))}async expandArgs(t,n){let r=t.map((o,a)=>(n?.[a]??!1)||!this.isGlobPattern(o)?null:this.expand(o)),s=await Promise.all(r.map(o=>o||Promise.resolve(null))),i=[];for(let o=0;o<t.length;o++){let a=s[o];a===null?i.push(t[o]):a.length>0?i.push(...a):i.push(t[o])}return i}async expand(t){if(this.globstar){let r=t.split("/"),s=0;for(let i of r)if(i==="**"&&(s++,s>Pl))throw new P(`Glob pattern has too many ** segments (max ${Pl})`,"glob_operations")}let n;if(t.includes("**")&&this.globstar&&this.isGlobstarValid(t))n=await this.expandRecursive(t);else{let r=t.replace(/\*\*+/g,"*");n=await this.expandSimple(r)}return this.filterGlobignore(n)}isGlobstarValid(t){let n=t.split("/");for(let r of n)if(r.includes("**")&&r!=="**")return!1;return!0}hasGlobChars(t){return!!(t.includes("*")||t.includes("?")||/\[.*\]/.test(t)||this.extglob&&/[@*+?!]\(/.test(t))}async expandSimple(t){let n=t.startsWith("/"),r=t.split("/").filter(u=>u!==""),s=-1;for(let u=0;u<r.length;u++)if(this.hasGlobChars(r[u])){s=u;break}if(s===-1)return[t];let i,o;if(s===0)n?(i="/",o="/"):(i=this.cwd,o="");else{let u=r.slice(0,s);n?(i=`/${u.join("/")}`,o=`/${u.join("/")}`):(i=this.fs.resolvePath(this.cwd,u.join("/")),o=u.join("/"))}let a=r.slice(s);return(await this.expandSegments(i,o,a)).sort()}async expandSegments(t,n,r){if(this.checkOpsLimit(),r.length===0)return[n];let[s,...i]=r,o=[];try{if(this.fs.readdirWithFileTypes){this.checkOpsLimit();let a=await this.fs.readdirWithFileTypes(t),l=[],u=[...a],c=this.dotglob||this.hasGlobignore;if(s.startsWith(".")||this.dotglob){let d=a.some(h=>h.name==="."),p=a.some(h=>h.name==="..");d||u.push({name:".",isFile:!1,isDirectory:!0,isSymbolicLink:!1}),p||u.push({name:"..",isFile:!1,isDirectory:!0,isSymbolicLink:!1})}for(let d of u)if(!(d.name.startsWith(".")&&!s.startsWith(".")&&!c)&&this.matchPattern(d.name,s)){let p=t==="/"?`/${d.name}`:`${t}/${d.name}`,h;n===""?h=d.name:n==="/"?h=`/${d.name}`:h=`${n}/${d.name}`,i.length===0?l.push(Promise.resolve([h])):d.isDirectory&&l.push(this.expandSegments(p,h,i))}let f=await Promise.all(l);for(let d of f)o.push(...d)}else{this.checkOpsLimit();let a=await this.fs.readdir(t),l=[],u=[...a],c=this.dotglob||this.hasGlobignore;(s.startsWith(".")||this.dotglob)&&(a.includes(".")||u.push("."),a.includes("..")||u.push(".."));for(let d of u)if(!(d.startsWith(".")&&!s.startsWith(".")&&!c)&&this.matchPattern(d,s)){let p=t==="/"?`/${d}`:`${t}/${d}`,h;n===""?h=d:n==="/"?h=`/${d}`:h=`${n}/${d}`,i.length===0?l.push(Promise.resolve([h])):l.push((async()=>{try{if(this.checkOpsLimit(),(await this.fs.stat(p)).isDirectory)return this.expandSegments(p,h,i)}catch(m){if(m instanceof P)throw m}return[]})())}let f=await Promise.all(l);for(let d of f)o.push(...d)}}catch(a){if(a instanceof P)throw a}return o}async expandRecursive(t){let n=[],r=t.indexOf("**"),s=t.slice(0,r).replace(/\/$/,"")||".",o=t.slice(r+2).replace(/^\//,"");return o.includes("**")&&this.isGlobstarValid(o)?(await this.walkDirectoryMultiGlobstar(s,o,n),[...new Set(n)].sort()):(await this.walkDirectory(s,o,n),n.sort())}async walkDirectoryMultiGlobstar(t,n,r){this.checkOpsLimit();let s=this.fs.resolvePath(this.cwd,t);try{this.checkOpsLimit();let i=this.fs.readdirWithFileTypes?await this.fs.readdirWithFileTypes(s):null;if(i){let o=[];for(let u of i){let c=t==="."?u.name:`${t}/${u.name}`;u.isDirectory&&o.push(c)}let a=t==="."?n:`${t}/${n}`,l=await this.expandRecursive(a);r.push(...l);for(let u=0;u<o.length;u+=100){let c=o.slice(u,u+100);await Promise.all(c.map(f=>this.walkDirectoryMultiGlobstar(f,n,r)))}}else{this.checkOpsLimit();let o=await this.fs.readdir(s),a=[];for(let c of o){let f=t==="."?c:`${t}/${c}`,d=this.fs.resolvePath(this.cwd,f);try{this.checkOpsLimit(),(await this.fs.stat(d)).isDirectory&&a.push(f)}catch(p){if(p instanceof P)throw p}}let l=t==="."?n:`${t}/${n}`,u=await this.expandRecursive(l);r.push(...u);for(let c=0;c<a.length;c+=100){let f=a.slice(c,c+100);await Promise.all(f.map(d=>this.walkDirectoryMultiGlobstar(d,n,r)))}}}catch(i){if(i instanceof P)throw i}}async walkDirectory(t,n,r){this.checkOpsLimit();let s=this.fs.resolvePath(this.cwd,t);try{if(this.fs.readdirWithFileTypes){this.checkOpsLimit();let i=await this.fs.readdirWithFileTypes(s),o=[],a=[];for(let l of i){let u=t==="."?l.name:`${t}/${l.name}`;l.isDirectory?a.push(u):n&&this.matchPattern(l.name,n)&&o.push(u)}r.push(...o);for(let l=0;l<a.length;l+=100){let u=a.slice(l,l+100);await Promise.all(u.map(c=>this.walkDirectory(c,n,r)))}}else{this.checkOpsLimit();let i=await this.fs.readdir(s),o=[];for(let l=0;l<i.length;l+=100){let u=i.slice(l,l+100),c=await Promise.all(u.map(async f=>{let d=t==="."?f:`${t}/${f}`,p=this.fs.resolvePath(this.cwd,d);try{this.checkOpsLimit();let h=await this.fs.stat(p);return{name:f,path:d,isDirectory:h.isDirectory}}catch(h){if(h instanceof P)throw h;return null}}));o.push(...c.filter(f=>f!==null))}for(let l of o)!l.isDirectory&&n&&this.matchPattern(l.name,n)&&r.push(l.path);let a=o.filter(l=>l.isDirectory);for(let l=0;l<a.length;l+=100){let u=a.slice(l,l+100);await Promise.all(u.map(c=>this.walkDirectory(c.path,n,r)))}}}catch(i){if(i instanceof P)throw i}}matchPattern(t,n){return this.patternToRegex(n).test(t)}patternToRegex(t){let n=this.patternToRegexStr(t);return me(`^${n}$`)}patternToRegexStr(t){let n="",r=!1;for(let s=0;s<t.length;s++){if(t.slice(s,s+13)==="\0QUOTE_START\0"){r=!0,s+=12;continue}if(t.slice(s,s+11)==="\0QUOTE_END\0"){r=!1,s+=10;continue}let i=t[s];if(r){/[.+^${}()|\\*?[\]]/.test(i)?n+=`\\${i}`:n+=i;continue}if(this.extglob&&(i==="@"||i==="*"||i==="+"||i==="?"||i==="!")&&s+1<t.length&&t[s+1]==="("){let o=Ei(t,s+1);if(o!==-1){let a=t.slice(s+2,o),l=bi(a),u=l.map(f=>this.patternToRegexStr(f)),c=u.length>0?u.join("|"):"(?:)";if(i==="@")n+=`(?:${c})`;else if(i==="*")n+=`(?:${c})*`;else if(i==="+")n+=`(?:${c})+`;else if(i==="?")n+=`(?:${c})?`;else if(i==="!")if(o<t.length-1){let d=l.map(h=>this.computePatternLength(h));if(d.every(h=>h!==null)&&d.every(h=>h===d[0])&&d[0]!==null){let h=d[0];if(h===0)n+="(?:.+)";else{let m=[];h>0&&m.push(`.{0,${h-1}}`),m.push(`.{${h+1},}`),m.push(`(?!(?:${c})).{${h}}`),n+=`(?:${m.join("|")})`}}else n+=`(?:(?!(?:${c})).)*?`}else n+=`(?!(?:${c})$).*`;s=o;continue}}if(i==="*")n+=".*";else if(i==="?")n+=".";else if(i==="["){let o=s+1,a="[";o<t.length&&(t[o]==="^"||t[o]==="!")&&(a+="^",o++),o<t.length&&t[o]==="]"&&(a+="\\]",o++);let l=o;for(;l<t.length;){if(t[l]==="\\"&&l+1<t.length){l+=2;continue}if(t[l]==="["&&l+1<t.length&&t[l+1]===":"){let c=t.indexOf(":]",l+2);if(c!==-1){l=c+2;continue}}if(t[l]==="]")break;l++}let u=o;for(;o<t.length&&t[o]!=="]";){if(t[o]==="["&&o+1<t.length&&t[o+1]===":"){let c=t.indexOf(":]",o+2);if(c!==-1){let f=t.slice(o+2,c),d=wi(f);a+=d,o=c+2;continue}}if(t[o]==="\\"&&o+1<t.length){a+=`\\${t[o+1]}`,o+=2;continue}if(t[o]==="-"){let c=o===u,f=o+1===l;c||f?a+="\\-":a+="-"}else a+=t[o];o++}a+="]",n+=a,s=o}else if(i==="\\"&&s+1<t.length){let o=t[s+1];/[.+^${}()|\\*?[\]]/.test(o)?n+=`\\${o}`:n+=o,s++}else/[.+^${}()|]/.test(i)?n+=`\\${i}`:n+=i}return n}computePatternLength(t){let n=0,r=0,s=!1;for(;r<t.length;){if(t.slice(r,r+13)==="\0QUOTE_START\0"){s=!0,r+=13;continue}if(t.slice(r,r+11)==="\0QUOTE_END\0"){s=!1,r+=11;continue}let i=t[r];if(s){n+=1,r++;continue}if((i==="@"||i==="*"||i==="+"||i==="?"||i==="!")&&r+1<t.length&&t[r+1]==="("){let o=Ei(t,r+1);if(o!==-1){if(i==="@"){let a=t.slice(r+2,o),u=bi(a).map(c=>this.computePatternLength(c));if(u.every(c=>c!==null)&&u.every(c=>c===u[0])){n+=u[0],r=o+1;continue}return null}return null}}if(i==="*")return null;if(i==="?"){n+=1,r++;continue}if(i==="["){let o=t.indexOf("]",r+1);if(o!==-1){n+=1,r=o+1;continue}n+=1,r++;continue}if(i==="\\"){n+=1,r+=2;continue}n+=1,r++}return n}};function Si(e){for(let t=0;t<e.length;t++){if(e[t]==="\\"){t++;continue}if(e[t]==="$"){let n=e[t+1];if(n==="{"||n&&/[a-zA-Z_]/.test(n))return!0}}return!1}function Yd(e){if(!e.operation)return!1;let t=e.operation,n;if((t.type==="DefaultValue"||t.type==="AssignDefault"||t.type==="UseAlternative"||t.type==="ErrorIfUnset")&&(n=t.word?.parts),!n)return!1;for(let r of n)if(r.type==="DoubleQuoted"||r.type==="SingleQuoted")return!0;return!1}function Cl(e){if(!e.operation)return!1;let t=e.operation,n;if((t.type==="DefaultValue"||t.type==="AssignDefault"||t.type==="UseAlternative"||t.type==="ErrorIfUnset")&&(n=t.word?.parts),!n||n.length===0)return!1;for(let r of n)if(r.type!=="DoubleQuoted"&&r.type!=="SingleQuoted")return!1;return!0}function ar(e){let t=!1,n=!1,r=!1,s=!1,i=!1,o=!1,a=!1;for(let l of e){if((l.type==="SingleQuoted"||l.type==="DoubleQuoted")&&(t=!0,l.type==="DoubleQuoted"))for(let u of l.parts)u.type==="ParameterExpansion"&&(u.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/)&&(!u.operation||u.operation.type==="PatternRemoval"||u.operation.type==="PatternReplacement")&&(s=!0),(u.operation?.type==="VarNamePrefix"||u.operation?.type==="ArrayKeys")&&(o=!0),u.operation?.type==="Indirection"&&(a=!0));l.type==="CommandSubstitution"&&(n=!0),l.type==="ParameterExpansion"&&(i=!0,(l.parameter==="@"||l.parameter==="*")&&(r=!0),Yd(l)&&(t=!0),(l.operation?.type==="VarNamePrefix"||l.operation?.type==="ArrayKeys")&&(o=!0),l.operation?.type==="Indirection"&&(a=!0)),l.type==="Glob"&&Si(l.pattern)&&(i=!0)}return{hasQuoted:t,hasCommandSub:n,hasArrayVar:r,hasArrayAtExpansion:s,hasParamExpansion:i,hasVarNamePrefixExpansion:o,hasIndirection:a}}var Jd=`
98
- `;function wn(e,t){if(e>=t)throw new P(`array element limit exceeded (${t})`,"array_elements")}function Ai(e,t,n,r,s){wn(e.length,s),wn(t.length,s),e.push(n),t.push(r)}function Ae(e){return e.get("IFS")??Jd}function Ce(e){return e.get("IFS")===""}function zr(e){let t=Ae(e);if(t==="")return!0;for(let n of t)if(n!==" "&&n!==" "&&n!==`
99
- `)return!1;return!0}function Nl(e){let t=!1,n=[];for(let r of e.split(""))r==="-"?t=!0:/[\\^$.*+?()[\]{}|]/.test(r)?n.push(`\\${r}`):r===" "?n.push("\\t"):r===`
100
- `?n.push("\\n"):n.push(r);return t&&n.push("\\-"),n.join("")}function Z(e){let t=e.get("IFS");if(t===void 0)return" ";let n=t.codePointAt(0);return n===void 0?"":String.fromCodePoint(n)}var ep=`
101
- `;function tp(e){return ep.includes(e)}function vi(e){let t=new Set,n=new Set;for(let r of e)tp(r)?t.add(r):n.add(r);return{whitespace:t,nonWhitespace:n}}function xi(e,t,n,r,s){if(t==="")return e===""?{words:[],wordStarts:[]}:(wn(0,n),{words:[e],wordStarts:[0]});let{whitespace:i,nonWhitespace:o}=vi(t),a=[],l=[],u=0;for(;u<e.length&&i.has(e[u]);)u++;if(u>=e.length)return{words:[],wordStarts:[]};if(o.has(e[u]))for(Ai(a,l,"",u,n),u++;u<e.length&&i.has(e[u]);)u++;for(;u<e.length&&!(r!==void 0&&a.length>=r);){let c=u;for(;u<e.length;){let f=e[u];if(!s&&f==="\\"){u++,u<e.length&&u++;continue}if(i.has(f)||o.has(f))break;u++}if(Ai(a,l,e.substring(c,u),c,n),u>=e.length)break;for(;u<e.length&&i.has(e[u]);)u++;if(u<e.length&&o.has(e[u])){for(u++;u<e.length&&i.has(e[u]);)u++;for(;u<e.length&&o.has(e[u])&&!(r!==void 0&&a.length>=r);)for(Ai(a,l,"",u,n),u++;u<e.length&&i.has(e[u]);)u++}}return{words:a,wordStarts:l}}function qr(e,t,n){if(t==="")return e&&wn(0,n),{words:e?[e]:[],hadLeadingDelimiter:!1,hadTrailingDelimiter:!1};if(e==="")return{words:[],hadLeadingDelimiter:!1,hadTrailingDelimiter:!1};let{whitespace:r,nonWhitespace:s}=vi(t),i=[],o=0,a=!1,l=!1,u=o;for(;o<e.length&&r.has(e[o]);)o++;if(o>u&&(a=!0),o>=e.length)return{words:[],hadLeadingDelimiter:!0,hadTrailingDelimiter:!0};if(s.has(e[o]))for(wn(i.length,n),i.push(""),o++;o<e.length&&r.has(e[o]);)o++;for(;o<e.length;){let c=o;for(;o<e.length;){let d=e[o];if(r.has(d)||s.has(d))break;o++}if(wn(i.length,n),i.push(e.substring(c,o)),o>=e.length){l=!1;break}let f=o;for(;o<e.length&&r.has(e[o]);)o++;if(o<e.length&&s.has(e[o])){for(o++;o<e.length&&r.has(e[o]);)o++;for(;o<e.length&&s.has(e[o]);)for(wn(i.length,n),i.push(""),o++;o<e.length&&r.has(e[o]);)o++}o>=e.length&&o>f&&(l=!0)}return{words:i,hadLeadingDelimiter:a,hadTrailingDelimiter:l}}function ce(e,t,n){return qr(e,t,n).words}function np(e,t){for(let n of e)if(t.has(n))return!0;return!1}function Rl(e,t,n){if(t==="")return e;let{whitespace:r,nonWhitespace:s}=vi(t),i=e.length;for(;i>0&&r.has(e[i-1]);){if(!n&&i>=2){let a=0,l=i-2;for(;l>=0&&e[l]==="\\";)a++,l--;if(a%2===1)break}i--}let o=e.substring(0,i);if(o.length>=1&&s.has(o[o.length-1])){if(!n&&o.length>=2){let l=0,u=o.length-2;for(;u>=0&&o[u]==="\\";)l++,u--;if(l%2===1)return o}let a=o.substring(0,o.length-1);if(!np(a,s))return a}return o}function le(e,t){return e.state.namerefs?.has(t)??!1}function It(e,t){e.state.namerefs??=new Set,e.state.namerefs.add(t)}function Dl(e,t){e.state.namerefs?.delete(t),e.state.boundNamerefs?.delete(t),e.state.invalidNamerefs?.delete(t)}function Il(e,t){e.state.invalidNamerefs??=new Set,e.state.invalidNamerefs.add(t)}function Ol(e,t){return e.state.invalidNamerefs?.has(t)??!1}function $i(e,t){e.state.boundNamerefs??=new Set,e.state.boundNamerefs.add(t)}function Ur(e,t){let n=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(n){let s=n[1],i=ke(e,s),o=e.state.associativeArrays?.has(s)??!1;return i||o}return ke(e,t)?!0:e.state.env.has(t)}function Te(e,t,n=100){if(!le(e,t)||Ol(e,t))return t;let r=new Set,s=t;for(;n-- >0;){if(r.has(s))return;if(r.add(s),!le(e,s))return s;let i=e.state.env.get(s);if(i===void 0||i===""||!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(i))return s;s=i}}function En(e,t){if(le(e,t))return e.state.env.get(t)}function jr(e,t,n,r=100){if(!le(e,t)||Ol(e,t))return t;let s=new Set,i=t;for(;r-- >0;){if(s.has(i))return;if(s.add(i),!le(e,i))return i;let o=e.state.env.get(i);if(o===void 0||o==="")return n!==void 0?/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n)&&Ur(e,n)?i:null:i;if(!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(o))return i;i=o}}function _l(e,t){let n=t.replace(/\$\{([a-zA-Z_][a-zA-Z0-9_]*)\}/g,(r,s)=>e.state.env.get(s)??"");return n=n.replace(/\$([a-zA-Z_][a-zA-Z0-9_]*)/g,(r,s)=>e.state.env.get(s)??""),n}function G(e,t){return t==="FUNCNAME"?(e.state.funcNameStack??[]).map((i,o)=>[o,i]):t==="BASH_LINENO"?(e.state.callLineStack??[]).map((i,o)=>[o,String(i)]):t==="BASH_SOURCE"?(e.state.sourceStack??[]).map((i,o)=>[o,i]):e.state.associativeArrays?.has(t)?St(e,t).map(i=>[i,ie(e,t,i)??""]):be(e,t).map(s=>[s,ie(e,t,s)??""])}function ht(e,t){return t==="FUNCNAME"?(e.state.funcNameStack?.length??0)>0:t==="BASH_LINENO"?(e.state.callLineStack?.length??0)>0:t==="BASH_SOURCE"?(e.state.sourceStack?.length??0)>0:e.state.associativeArrays?.has(t)?ke(e,t):ke(e,t)}async function re(e,t,n=!0){switch(t){case"?":return String(e.state.lastExitCode);case"$":return String(e.state.virtualPid);case"#":return e.state.env.get("#")||"0";case"@":return e.state.env.get("@")||"";case"_":return e.state.lastArg;case"-":{let i="";return i+="h",e.state.options.errexit&&(i+="e"),e.state.options.noglob&&(i+="f"),e.state.options.nounset&&(i+="u"),e.state.options.verbose&&(i+="v"),e.state.options.xtrace&&(i+="x"),i+="B",e.state.options.noclobber&&(i+="C"),i+="s",i}case"*":{let i=Number.parseInt(e.state.env.get("#")||"0",10);if(i===0)return"";let o=[];for(let a=1;a<=i;a++)o.push(e.state.env.get(String(a))||"");return o.join(Z(e.state.env))}case"0":return e.state.env.get("0")||"bash";case"PWD":return e.state.env.get("PWD")??"";case"OLDPWD":return e.state.env.get("OLDPWD")??"";case"PPID":return String(e.state.virtualPpid);case"UID":return String(e.state.virtualUid);case"EUID":return String(e.state.virtualUid);case"RANDOM":return String(Math.floor(Math.random()*32768));case"SECONDS":return String(Math.floor((Date.now()-e.state.startTime)/1e3));case"BASH_VERSION":return Pa;case"!":return String(e.state.lastBackgroundPid);case"BASHPID":return String(e.state.bashPid);case"LINENO":return String(e.state.currentLine);case"FUNCNAME":{let i=e.state.funcNameStack?.[0];if(i!==void 0)return i;if(n&&e.state.options.nounset)throw new Be("FUNCNAME");return""}case"BASH_LINENO":{let i=e.state.callLineStack?.[0];if(i!==void 0)return String(i);if(n&&e.state.options.nounset)throw new Be("BASH_LINENO");return""}case"BASH_SOURCE":{let i=e.state.sourceStack?.[0];if(i!==void 0)return i;if(n&&e.state.options.nounset)throw new Be("BASH_SOURCE");return""}}if(/^[a-zA-Z_][a-zA-Z0-9_]*\[\]$/.test(t))throw new Ze(`\${${t}}`);let r=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(r){let i=r[1],o=r[2];if(le(e,i)){let c=Te(e,i);if(c&&c!==i){if(c.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/))return"";i=c}}if(o==="@"||o==="*"){let c=G(e,i);if(c.length>0){let d=o==="*"?Z(e.state.env):" ",p=F(d)*(c.length-1);for(let[,h]of c)if(p+=F(h),p>e.limits.maxStringLength)throw new P(`array expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return c.map(([,h])=>h).join(d)}let f=e.state.env.get(i);return f!==void 0?f:""}if(i==="FUNCNAME"){let c=Number.parseInt(o,10);return!Number.isNaN(c)&&c>=0?e.state.funcNameStack?.[c]??"":""}if(i==="BASH_LINENO"){let c=Number.parseInt(o,10);if(!Number.isNaN(c)&&c>=0){let f=e.state.callLineStack?.[c];return f!==void 0?String(f):""}return""}if(i==="BASH_SOURCE"){let c=Number.parseInt(o,10);return!Number.isNaN(c)&&c>=0?e.state.sourceStack?.[c]??"":""}if(e.state.associativeArrays?.has(i)){let c=Ir(o);c=_l(e,c);let f=ie(e,i,c);if(f===void 0&&n&&e.state.options.nounset)throw new Be(`${i}[${o}]`);return f||""}let l;if(/^-?\d+$/.test(o))l=Number.parseInt(o,10);else try{let c=new j,f=te(c,o);l=await X(e,f.expression)}catch{let c=e.state.env.get(o);l=c?Number.parseInt(c,10):0,Number.isNaN(l)&&(l=0)}if(l<0){let c=G(e,i),f=e.state.currentLine;if(c.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${f}: ${i}: bad array subscript
97
+ ${e.terminator}`}function Xd(e){return`(${rt(e.body)})${dt(e.redirections)}`}function Yd(e){return`{ ${rt(e.body)}; }${dt(e.redirections)}`}function Jd(e){return`((${fe(e.expression.expression)}))${dt(e.redirections)}`}function ep(e){return`[[ ${yn(e.expression)} ]]${dt(e.redirections)}`}function tp(e){let t=El(e.body);return`${e.name}() ${t}${dt(e.redirections)}`}function fe(e){switch(e.type){case"ArithNumber":return String(e.value);case"ArithVariable":return e.hasDollarPrefix?`$${e.name}`:e.name;case"ArithSpecialVar":return`$${e.name}`;case"ArithBinary":return`${fe(e.left)} ${e.operator} ${fe(e.right)}`;case"ArithUnary":return e.prefix?`${e.operator}${fe(e.operand)}`:`${fe(e.operand)}${e.operator}`;case"ArithTernary":return`${fe(e.condition)} ? ${fe(e.consequent)} : ${fe(e.alternate)}`;case"ArithAssignment":return`${e.subscript?`${e.variable}[${fe(e.subscript)}]`:e.stringKey!==void 0?`${e.variable}[${e.stringKey}]`:e.variable} ${e.operator} ${fe(e.value)}`;case"ArithDynamicAssignment":return`${e.subscript?`${fe(e.target)}[${fe(e.subscript)}]`:fe(e.target)} ${e.operator} ${fe(e.value)}`;case"ArithDynamicElement":return`${fe(e.nameExpr)}[${fe(e.subscript)}]`;case"ArithGroup":return`(${fe(e.expression)})`;case"ArithNested":return`$((${fe(e.expression)}))`;case"ArithCommandSubst":return`$(${e.command})`;case"ArithBracedExpansion":return`\${${e.content}}`;case"ArithArrayElement":return e.stringKey!==void 0?`${e.array}[${e.stringKey}]`:e.index?`${e.array}[${fe(e.index)}]`:e.array;case"ArithDynamicBase":return`\${${e.baseExpr}}#${e.value}`;case"ArithDynamicNumber":return`\${${e.prefix}}${e.suffix}`;case"ArithConcat":return e.parts.map(fe).join("");case"ArithDoubleSubscript":return`${e.array}[${fe(e.index)}]`;case"ArithNumberSubscript":return`${e.number}[${e.errorToken}]`;case"ArithSyntaxError":return e.errorToken;case"ArithSingleQuote":return`'${e.content}'`;default:{let t=e;throw new Error(`Unsupported arithmetic expression type: ${t.type}`)}}}function yn(e){switch(e.type){case"CondBinary":return`${be(e.left)} ${e.operator} ${be(e.right)}`;case"CondUnary":return`${e.operator} ${be(e.operand)}`;case"CondNot":return`! ${yn(e.operand)}`;case"CondAnd":return`${yn(e.left)} && ${yn(e.right)}`;case"CondOr":return`${yn(e.left)} || ${yn(e.right)}`;case"CondGroup":return`( ${yn(e.expression)} )`;case"CondWord":return be(e.word);default:{let t=e;throw new Error(`Unsupported conditional expression type: ${t.type}`)}}}var np="BASH_ALIAS_";function jr(e,t,n,r){let s=W(t);if(s>n-r.value)throw new C(`alias expansion exceeds string length limit (${n} bytes)`,"string_length");return r.value+=s,e+t}function vl(e){return e.parts.length!==1?!1:e.parts[0].type==="Literal"}function xl(e){if(e.parts.length!==1)return null;let t=e.parts[0];return t.type==="Literal"?t.value:null}function $l(e,t){return e.env.get(`${np}${t}`)}function Pl(e,t,n){return Cl(e,t,n)}function Cl(e,t,n,r=!0){if(!t.name||!vl(t.name))return t;let s=xl(t.name);if(!s)return t;let i=$l(e,s);if(!i||n.has(s))return t;try{n.add(s);let o=new G,a={value:0},l=jr("",i,e.limits.maxStringLength,a),u=i.endsWith(" ");if(!u)for(let p of t.args){let h=be(p);l=jr(l,` ${h}`,e.limits.maxStringLength,a)}let c;try{c=o.parse(l)}catch(p){if(p instanceof ve)throw p;return t}if(c.statements.length!==1||c.statements[0].pipelines.length!==1||c.statements[0].pipelines[0].commands.length!==1)return kl(e,t,i);let f=c.statements[0].pipelines[0].commands[0];if(f.type!=="SimpleCommand")return kl(e,t,i);let d={...f,assignments:[...t.assignments,...f.assignments],redirections:[...f.redirections,...t.redirections],line:t.line};if(u&&t.args.length>0){d={...d,args:[...d.args,...t.args]};let p=1;for(;r&&d.args.length>0;){let h=d.args[0];if(!vl(h))break;let m=xl(h),y=m?$l(e,m):null;if(!y)break;if(p>=e.limits.maxCallDepth)throw new C(`alias expansion depth limit exceeded (${e.limits.maxCallDepth})`,"recursion");p++;let b={type:"SimpleCommand",name:h,args:d.args.slice(1),assignments:[],redirections:[]},w=Cl(e,b,n,!1);if(w===b||(d={...d,name:w.name,args:[...w.args]},!y.endsWith(" ")))break}}return d}catch(o){throw n.delete(s),o}}function kl(e,t,n){let r={value:0},s=jr("",n,e.limits.maxStringLength,r);for(let u of t.args){let c=be(u);s=jr(s,` ${c}`,e.limits.maxStringLength,r)}let i=new G,o=i.parseWordFromString("eval",!1,!1),a=0;for(let u of s)u==="'"&&a++;if(r.value+2+a*3>e.limits.maxStringLength)throw new C(`alias expansion exceeds string length limit (${e.limits.maxStringLength} bytes)`,"string_length");let l=i.parseWordFromString(`'${s.replace(/'/g,"'\\''")}'`,!1,!1);return{type:"SimpleCommand",name:o,args:[l],assignments:t.assignments,redirections:t.redirections,line:t.line}}var rp=new Map([["alnum","a-zA-Z0-9"],["alpha","a-zA-Z"],["ascii","\\x00-\\x7F"],["blank"," \\t"],["cntrl","\\x00-\\x1F\\x7F"],["digit","0-9"],["graph","!-~"],["lower","a-z"],["print"," -~"],["punct","!-/:-@\\[-`{-~"],["space"," \\t\\n\\r\\f\\v"],["upper","A-Z"],["word","a-zA-Z0-9_"],["xdigit","0-9a-fA-F"]]);function bi(e){return rp.get(e)??""}function Nl(e){let t=[],n="",r=0;for(;r<e.length;){let s=e[r];if(s==="["){for(n+=s,r++,r<e.length&&(e[r]==="!"||e[r]==="^")&&(n+=e[r],r++),r<e.length&&e[r]==="]"&&(n+=e[r],r++);r<e.length&&e[r]!=="]";){if(e[r]==="["&&r+1<e.length&&e[r+1]===":"){let i=e.indexOf(":]",r+2);if(i!==-1){n+=e.slice(r,i+2),r=i+2;continue}}if(e[r]==="\\"&&r+1<e.length){n+=e[r]+e[r+1],r+=2;continue}n+=e[r],r++}r<e.length&&e[r]==="]"&&(n+=e[r],r++)}else s===":"?(n!==""&&t.push(n),n="",r++):s==="\\"&&r+1<e.length?(n+=s+e[r+1],r+=2):(n+=s,r++)}return n!==""&&t.push(n),t}function Rl(e){let t="^";for(let n=0;n<e.length;n++){let r=e[n];if(r==="*")t+="[^/]*";else if(r==="?")t+="[^/]";else if(r==="["){let s=n+1,i="[";s<e.length&&(e[s]==="^"||e[s]==="!")&&(i+="^",s++),s<e.length&&e[s]==="]"&&(i+="\\]",s++);let o=s;for(;o<e.length;){if(e[o]==="\\"&&o+1<e.length){o+=2;continue}if(e[o]==="["&&o+1<e.length&&e[o+1]===":"){let l=e.indexOf(":]",o+2);if(l!==-1){o=l+2;continue}}if(e[o]==="]")break;o++}let a=s;for(;s<e.length&&e[s]!=="]";){if(e[s]==="["&&s+1<e.length&&e[s+1]===":"){let l=e.indexOf(":]",s+2);if(l!==-1){let u=e.slice(s+2,l),c=bi(u);i+=c,s=l+2;continue}}if(e[s]==="\\"&&s+1<e.length){i+=`\\${e[s+1]}`,s+=2;continue}if(e[s]==="-"){let l=s===a,u=s+1===o;l||u?i+="\\-":i+="-"}else i+=e[s];s++}i+="]",t+=i,n=s}else if(r==="\\"&&n+1<e.length){let s=e[n+1];/[.+^${}()|\\*?[\]]/.test(s)?t+=`\\${s}`:t+=s,n++}else/[.+^${}()|]/.test(r)?t+=`\\${r}`:t+=r}return t+="$",me(t)}function Si(e,t){let n=1,r=t+1;for(;r<e.length&&n>0;){let s=e[r];if(s==="\\"){r+=2;continue}if(s==="(")n++;else if(s===")"&&(n--,n===0))return r;r++}return-1}function Ai(e){let t=[],n="",r=0,s=!1,i=0;for(;i<e.length;){let o=e[i];if(o==="'"&&!s){s=!0,n+="\0QUOTE_START\0",i++;continue}if(o==="'"&&s){s=!1,n+="\0QUOTE_END\0",i++;continue}if(s){n+=o,i++;continue}if(o==="\\"){n+=o,i+1<e.length?(n+=e[i+1],i+=2):i++;continue}o==="("?(r++,n+=o):o===")"?(r--,n+=o):o==="|"&&r===0?(t.push(n),n=""):n+=o,i++}return t.push(n),t}var Dl=5,jt=class{fs;cwd;globignorePatterns=[];hasGlobignore=!1;globstar=!1;nullglob=!1;failglob=!1;dotglob=!1;extglob=!1;globskipdots=!0;ops={count:0};maxOps;consumeOperation;constructor(t,n,r,s){this.fs=t,this.cwd=n,typeof s=="boolean"?(this.globstar=s,this.maxOps=1e5):s?(this.globstar=s.globstar??!1,this.nullglob=s.nullglob??!1,this.failglob=s.failglob??!1,this.dotglob=s.dotglob??!1,this.extglob=s.extglob??!1,this.globskipdots=s.globskipdots??!0,this.maxOps=s.maxGlobOperations??1e5,this.consumeOperation=s.consumeOperation):this.maxOps=1e5;let i=r?.get("GLOBIGNORE");i!==void 0&&i!==""&&(this.hasGlobignore=!0,this.globignorePatterns=Nl(i))}checkOpsLimit(){if(++this.ops.count>this.maxOps)throw new C(`Glob operation limit exceeded (${this.maxOps})`,"glob_operations");this.consumeOperation?.()}hasNullglob(){return this.nullglob}hasFailglob(){return this.failglob}filterGlobignore(t){return!this.hasGlobignore&&!this.globskipdots?t:t.filter(n=>{let r=n.split("/").pop()||n;if((this.hasGlobignore||this.globskipdots)&&(r==="."||r===".."))return!1;if(this.hasGlobignore){for(let s of this.globignorePatterns)if(this.matchGlobignorePattern(n,s))return!1}return!0})}matchGlobignorePattern(t,n){return Rl(n).test(t)}isGlobPattern(t){return!!(t.includes("*")||t.includes("?")||/\[.*\]/.test(t)||this.extglob&&/[@*+?!]\(/.test(t))}async expandArgs(t,n){let r=t.map((o,a)=>(n?.[a]??!1)||!this.isGlobPattern(o)?null:this.expand(o)),s=await Promise.all(r.map(o=>o||Promise.resolve(null))),i=[];for(let o=0;o<t.length;o++){let a=s[o];a===null?i.push(t[o]):a.length>0?i.push(...a):i.push(t[o])}return i}async expand(t){if(this.globstar){let r=t.split("/"),s=0;for(let i of r)if(i==="**"&&(s++,s>Dl))throw new C(`Glob pattern has too many ** segments (max ${Dl})`,"glob_operations")}let n;if(t.includes("**")&&this.globstar&&this.isGlobstarValid(t))n=await this.expandRecursive(t);else{let r=t.replace(/\*\*+/g,"*");n=await this.expandSimple(r)}return this.filterGlobignore(n)}isGlobstarValid(t){let n=t.split("/");for(let r of n)if(r.includes("**")&&r!=="**")return!1;return!0}hasGlobChars(t){return!!(t.includes("*")||t.includes("?")||/\[.*\]/.test(t)||this.extglob&&/[@*+?!]\(/.test(t))}async expandSimple(t){let n=t.startsWith("/"),r=t.split("/").filter(u=>u!==""),s=-1;for(let u=0;u<r.length;u++)if(this.hasGlobChars(r[u])){s=u;break}if(s===-1)return[t];let i,o;if(s===0)n?(i="/",o="/"):(i=this.cwd,o="");else{let u=r.slice(0,s);n?(i=`/${u.join("/")}`,o=`/${u.join("/")}`):(i=this.fs.resolvePath(this.cwd,u.join("/")),o=u.join("/"))}let a=r.slice(s);return(await this.expandSegments(i,o,a)).sort()}async expandSegments(t,n,r){if(this.checkOpsLimit(),r.length===0)return[n];let[s,...i]=r,o=[];try{if(this.fs.readdirWithFileTypes){this.checkOpsLimit();let a=await this.fs.readdirWithFileTypes(t),l=[],u=[...a],c=this.dotglob||this.hasGlobignore;if(s.startsWith(".")||this.dotglob){let d=a.some(h=>h.name==="."),p=a.some(h=>h.name==="..");d||u.push({name:".",isFile:!1,isDirectory:!0,isSymbolicLink:!1}),p||u.push({name:"..",isFile:!1,isDirectory:!0,isSymbolicLink:!1})}for(let d of u)if(!(d.name.startsWith(".")&&!s.startsWith(".")&&!c)&&this.matchPattern(d.name,s)){let p=t==="/"?`/${d.name}`:`${t}/${d.name}`,h;n===""?h=d.name:n==="/"?h=`/${d.name}`:h=`${n}/${d.name}`,i.length===0?l.push(Promise.resolve([h])):d.isDirectory&&l.push(this.expandSegments(p,h,i))}let f=await Promise.all(l);for(let d of f)o.push(...d)}else{this.checkOpsLimit();let a=await this.fs.readdir(t),l=[],u=[...a],c=this.dotglob||this.hasGlobignore;(s.startsWith(".")||this.dotglob)&&(a.includes(".")||u.push("."),a.includes("..")||u.push(".."));for(let d of u)if(!(d.startsWith(".")&&!s.startsWith(".")&&!c)&&this.matchPattern(d,s)){let p=t==="/"?`/${d}`:`${t}/${d}`,h;n===""?h=d:n==="/"?h=`/${d}`:h=`${n}/${d}`,i.length===0?l.push(Promise.resolve([h])):l.push((async()=>{try{if(this.checkOpsLimit(),(await this.fs.stat(p)).isDirectory)return this.expandSegments(p,h,i)}catch(m){if(m instanceof C)throw m}return[]})())}let f=await Promise.all(l);for(let d of f)o.push(...d)}}catch(a){if(a instanceof C)throw a}return o}async expandRecursive(t){let n=[],r=t.indexOf("**"),s=t.slice(0,r).replace(/\/$/,"")||".",o=t.slice(r+2).replace(/^\//,"");return o.includes("**")&&this.isGlobstarValid(o)?(await this.walkDirectoryMultiGlobstar(s,o,n),[...new Set(n)].sort()):(await this.walkDirectory(s,o,n),n.sort())}async walkDirectoryMultiGlobstar(t,n,r){this.checkOpsLimit();let s=this.fs.resolvePath(this.cwd,t);try{this.checkOpsLimit();let i=this.fs.readdirWithFileTypes?await this.fs.readdirWithFileTypes(s):null;if(i){let o=[];for(let u of i){let c=t==="."?u.name:`${t}/${u.name}`;u.isDirectory&&o.push(c)}let a=t==="."?n:`${t}/${n}`,l=await this.expandRecursive(a);r.push(...l);for(let u=0;u<o.length;u+=100){let c=o.slice(u,u+100);await Promise.all(c.map(f=>this.walkDirectoryMultiGlobstar(f,n,r)))}}else{this.checkOpsLimit();let o=await this.fs.readdir(s),a=[];for(let c of o){let f=t==="."?c:`${t}/${c}`,d=this.fs.resolvePath(this.cwd,f);try{this.checkOpsLimit(),(await this.fs.stat(d)).isDirectory&&a.push(f)}catch(p){if(p instanceof C)throw p}}let l=t==="."?n:`${t}/${n}`,u=await this.expandRecursive(l);r.push(...u);for(let c=0;c<a.length;c+=100){let f=a.slice(c,c+100);await Promise.all(f.map(d=>this.walkDirectoryMultiGlobstar(d,n,r)))}}}catch(i){if(i instanceof C)throw i}}async walkDirectory(t,n,r){this.checkOpsLimit();let s=this.fs.resolvePath(this.cwd,t);try{if(this.fs.readdirWithFileTypes){this.checkOpsLimit();let i=await this.fs.readdirWithFileTypes(s),o=[],a=[];for(let l of i){let u=t==="."?l.name:`${t}/${l.name}`;l.isDirectory?a.push(u):n&&this.matchPattern(l.name,n)&&o.push(u)}r.push(...o);for(let l=0;l<a.length;l+=100){let u=a.slice(l,l+100);await Promise.all(u.map(c=>this.walkDirectory(c,n,r)))}}else{this.checkOpsLimit();let i=await this.fs.readdir(s),o=[];for(let l=0;l<i.length;l+=100){let u=i.slice(l,l+100),c=await Promise.all(u.map(async f=>{let d=t==="."?f:`${t}/${f}`,p=this.fs.resolvePath(this.cwd,d);try{this.checkOpsLimit();let h=await this.fs.stat(p);return{name:f,path:d,isDirectory:h.isDirectory}}catch(h){if(h instanceof C)throw h;return null}}));o.push(...c.filter(f=>f!==null))}for(let l of o)!l.isDirectory&&n&&this.matchPattern(l.name,n)&&r.push(l.path);let a=o.filter(l=>l.isDirectory);for(let l=0;l<a.length;l+=100){let u=a.slice(l,l+100);await Promise.all(u.map(c=>this.walkDirectory(c.path,n,r)))}}}catch(i){if(i instanceof C)throw i}}matchPattern(t,n){return this.patternToRegex(n).test(t)}patternToRegex(t){let n=this.patternToRegexStr(t);return me(`^${n}$`)}patternToRegexStr(t){let n="",r=!1;for(let s=0;s<t.length;s++){if(t.slice(s,s+13)==="\0QUOTE_START\0"){r=!0,s+=12;continue}if(t.slice(s,s+11)==="\0QUOTE_END\0"){r=!1,s+=10;continue}let i=t[s];if(r){/[.+^${}()|\\*?[\]]/.test(i)?n+=`\\${i}`:n+=i;continue}if(this.extglob&&(i==="@"||i==="*"||i==="+"||i==="?"||i==="!")&&s+1<t.length&&t[s+1]==="("){let o=Si(t,s+1);if(o!==-1){let a=t.slice(s+2,o),l=Ai(a),u=l.map(f=>this.patternToRegexStr(f)),c=u.length>0?u.join("|"):"(?:)";if(i==="@")n+=`(?:${c})`;else if(i==="*")n+=`(?:${c})*`;else if(i==="+")n+=`(?:${c})+`;else if(i==="?")n+=`(?:${c})?`;else if(i==="!")if(o<t.length-1){let d=l.map(h=>this.computePatternLength(h));if(d.every(h=>h!==null)&&d.every(h=>h===d[0])&&d[0]!==null){let h=d[0];if(h===0)n+="(?:.+)";else{let m=[];h>0&&m.push(`.{0,${h-1}}`),m.push(`.{${h+1},}`),m.push(`(?!(?:${c})).{${h}}`),n+=`(?:${m.join("|")})`}}else n+=`(?:(?!(?:${c})).)*?`}else n+=`(?!(?:${c})$).*`;s=o;continue}}if(i==="*")n+=".*";else if(i==="?")n+=".";else if(i==="["){let o=s+1,a="[";o<t.length&&(t[o]==="^"||t[o]==="!")&&(a+="^",o++),o<t.length&&t[o]==="]"&&(a+="\\]",o++);let l=o;for(;l<t.length;){if(t[l]==="\\"&&l+1<t.length){l+=2;continue}if(t[l]==="["&&l+1<t.length&&t[l+1]===":"){let c=t.indexOf(":]",l+2);if(c!==-1){l=c+2;continue}}if(t[l]==="]")break;l++}let u=o;for(;o<t.length&&t[o]!=="]";){if(t[o]==="["&&o+1<t.length&&t[o+1]===":"){let c=t.indexOf(":]",o+2);if(c!==-1){let f=t.slice(o+2,c),d=bi(f);a+=d,o=c+2;continue}}if(t[o]==="\\"&&o+1<t.length){a+=`\\${t[o+1]}`,o+=2;continue}if(t[o]==="-"){let c=o===u,f=o+1===l;c||f?a+="\\-":a+="-"}else a+=t[o];o++}a+="]",n+=a,s=o}else if(i==="\\"&&s+1<t.length){let o=t[s+1];/[.+^${}()|\\*?[\]]/.test(o)?n+=`\\${o}`:n+=o,s++}else/[.+^${}()|]/.test(i)?n+=`\\${i}`:n+=i}return n}computePatternLength(t){let n=0,r=0,s=!1;for(;r<t.length;){if(t.slice(r,r+13)==="\0QUOTE_START\0"){s=!0,r+=13;continue}if(t.slice(r,r+11)==="\0QUOTE_END\0"){s=!1,r+=11;continue}let i=t[r];if(s){n+=1,r++;continue}if((i==="@"||i==="*"||i==="+"||i==="?"||i==="!")&&r+1<t.length&&t[r+1]==="("){let o=Si(t,r+1);if(o!==-1){if(i==="@"){let a=t.slice(r+2,o),u=Ai(a).map(c=>this.computePatternLength(c));if(u.every(c=>c!==null)&&u.every(c=>c===u[0])){n+=u[0],r=o+1;continue}return null}return null}}if(i==="*")return null;if(i==="?"){n+=1,r++;continue}if(i==="["){let o=t.indexOf("]",r+1);if(o!==-1){n+=1,r=o+1;continue}n+=1,r++;continue}if(i==="\\"){n+=1,r+=2;continue}n+=1,r++}return n}};function vi(e){for(let t=0;t<e.length;t++){if(e[t]==="\\"){t++;continue}if(e[t]==="$"){let n=e[t+1];if(n==="{"||n&&/[a-zA-Z_]/.test(n))return!0}}return!1}function sp(e){if(!e.operation)return!1;let t=e.operation,n;if((t.type==="DefaultValue"||t.type==="AssignDefault"||t.type==="UseAlternative"||t.type==="ErrorIfUnset")&&(n=t.word?.parts),!n)return!1;for(let r of n)if(r.type==="DoubleQuoted"||r.type==="SingleQuoted")return!0;return!1}function Il(e){if(!e.operation)return!1;let t=e.operation,n;if((t.type==="DefaultValue"||t.type==="AssignDefault"||t.type==="UseAlternative"||t.type==="ErrorIfUnset")&&(n=t.word?.parts),!n||n.length===0)return!1;for(let r of n)if(r.type!=="DoubleQuoted"&&r.type!=="SingleQuoted")return!1;return!0}function lr(e){let t=!1,n=!1,r=!1,s=!1,i=!1,o=!1,a=!1;for(let l of e){if((l.type==="SingleQuoted"||l.type==="DoubleQuoted")&&(t=!0,l.type==="DoubleQuoted"))for(let u of l.parts)u.type==="ParameterExpansion"&&(u.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/)&&(!u.operation||u.operation.type==="PatternRemoval"||u.operation.type==="PatternReplacement")&&(s=!0),(u.operation?.type==="VarNamePrefix"||u.operation?.type==="ArrayKeys")&&(o=!0),u.operation?.type==="Indirection"&&(a=!0));l.type==="CommandSubstitution"&&(n=!0),l.type==="ParameterExpansion"&&(i=!0,(l.parameter==="@"||l.parameter==="*")&&(r=!0),sp(l)&&(t=!0),(l.operation?.type==="VarNamePrefix"||l.operation?.type==="ArrayKeys")&&(o=!0),l.operation?.type==="Indirection"&&(a=!0)),l.type==="Glob"&&vi(l.pattern)&&(i=!0)}return{hasQuoted:t,hasCommandSub:n,hasArrayVar:r,hasArrayAtExpansion:s,hasParamExpansion:i,hasVarNamePrefixExpansion:o,hasIndirection:a}}var ip=`
98
+ `;function wn(e,t){if(e>=t)throw new C(`array element limit exceeded (${t})`,"array_elements")}function xi(e,t,n,r,s){wn(e.length,s),wn(t.length,s),e.push(n),t.push(r)}function Se(e){return e.get("IFS")??ip}function Ce(e){return e.get("IFS")===""}function Gr(e){let t=Se(e);if(t==="")return!0;for(let n of t)if(n!==" "&&n!==" "&&n!==`
99
+ `)return!1;return!0}function Ol(e){let t=!1,n=[];for(let r of e.split(""))r==="-"?t=!0:/[\\^$.*+?()[\]{}|]/.test(r)?n.push(`\\${r}`):r===" "?n.push("\\t"):r===`
100
+ `?n.push("\\n"):n.push(r);return t&&n.push("\\-"),n.join("")}function Z(e){let t=e.get("IFS");if(t===void 0)return" ";let n=t.codePointAt(0);return n===void 0?"":String.fromCodePoint(n)}var op=`
101
+ `;function ap(e){return op.includes(e)}function $i(e){let t=new Set,n=new Set;for(let r of e)ap(r)?t.add(r):n.add(r);return{whitespace:t,nonWhitespace:n}}function ki(e,t,n,r,s){if(t==="")return e===""?{words:[],wordStarts:[]}:(wn(0,n),{words:[e],wordStarts:[0]});let{whitespace:i,nonWhitespace:o}=$i(t),a=[],l=[],u=0;for(;u<e.length&&i.has(e[u]);)u++;if(u>=e.length)return{words:[],wordStarts:[]};if(o.has(e[u]))for(xi(a,l,"",u,n),u++;u<e.length&&i.has(e[u]);)u++;for(;u<e.length&&!(r!==void 0&&a.length>=r);){let c=u;for(;u<e.length;){let f=e[u];if(!s&&f==="\\"){u++,u<e.length&&u++;continue}if(i.has(f)||o.has(f))break;u++}if(xi(a,l,e.substring(c,u),c,n),u>=e.length)break;for(;u<e.length&&i.has(e[u]);)u++;if(u<e.length&&o.has(e[u])){for(u++;u<e.length&&i.has(e[u]);)u++;for(;u<e.length&&o.has(e[u])&&!(r!==void 0&&a.length>=r);)for(xi(a,l,"",u,n),u++;u<e.length&&i.has(e[u]);)u++}}return{words:a,wordStarts:l}}function Hr(e,t,n){if(t==="")return e&&wn(0,n),{words:e?[e]:[],hadLeadingDelimiter:!1,hadTrailingDelimiter:!1};if(e==="")return{words:[],hadLeadingDelimiter:!1,hadTrailingDelimiter:!1};let{whitespace:r,nonWhitespace:s}=$i(t),i=[],o=0,a=!1,l=!1,u=o;for(;o<e.length&&r.has(e[o]);)o++;if(o>u&&(a=!0),o>=e.length)return{words:[],hadLeadingDelimiter:!0,hadTrailingDelimiter:!0};if(s.has(e[o]))for(wn(i.length,n),i.push(""),o++;o<e.length&&r.has(e[o]);)o++;for(;o<e.length;){let c=o;for(;o<e.length;){let d=e[o];if(r.has(d)||s.has(d))break;o++}if(wn(i.length,n),i.push(e.substring(c,o)),o>=e.length){l=!1;break}let f=o;for(;o<e.length&&r.has(e[o]);)o++;if(o<e.length&&s.has(e[o])){for(o++;o<e.length&&r.has(e[o]);)o++;for(;o<e.length&&s.has(e[o]);)for(wn(i.length,n),i.push(""),o++;o<e.length&&r.has(e[o]);)o++}o>=e.length&&o>f&&(l=!0)}return{words:i,hadLeadingDelimiter:a,hadTrailingDelimiter:l}}function ce(e,t,n){return Hr(e,t,n).words}function lp(e,t){for(let n of e)if(t.has(n))return!0;return!1}function _l(e,t,n){if(t==="")return e;let{whitespace:r,nonWhitespace:s}=$i(t),i=e.length;for(;i>0&&r.has(e[i-1]);){if(!n&&i>=2){let a=0,l=i-2;for(;l>=0&&e[l]==="\\";)a++,l--;if(a%2===1)break}i--}let o=e.substring(0,i);if(o.length>=1&&s.has(o[o.length-1])){if(!n&&o.length>=2){let l=0,u=o.length-2;for(;u>=0&&o[u]==="\\";)l++,u--;if(l%2===1)return o}let a=o.substring(0,o.length-1);if(!lp(a,s))return a}return o}function le(e,t){return e.state.namerefs?.has(t)??!1}function It(e,t){e.state.namerefs??=new Set,e.state.namerefs.add(t)}function Ll(e,t){e.state.namerefs?.delete(t),e.state.boundNamerefs?.delete(t),e.state.invalidNamerefs?.delete(t)}function Tl(e,t){e.state.invalidNamerefs??=new Set,e.state.invalidNamerefs.add(t)}function Fl(e,t){return e.state.invalidNamerefs?.has(t)??!1}function Pi(e,t){e.state.boundNamerefs??=new Set,e.state.boundNamerefs.add(t)}function Zr(e,t){let n=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(n){let s=n[1],i=ke(e,s),o=e.state.associativeArrays?.has(s)??!1;return i||o}return ke(e,t)?!0:e.state.env.has(t)}function Te(e,t,n=100){if(!le(e,t)||Fl(e,t))return t;let r=new Set,s=t;for(;n-- >0;){if(r.has(s))return;if(r.add(s),!le(e,s))return s;let i=e.state.env.get(s);if(i===void 0||i===""||!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(i))return s;s=i}}function En(e,t){if(le(e,t))return e.state.env.get(t)}function Qr(e,t,n,r=100){if(!le(e,t)||Fl(e,t))return t;let s=new Set,i=t;for(;r-- >0;){if(s.has(i))return;if(s.add(i),!le(e,i))return i;let o=e.state.env.get(i);if(o===void 0||o==="")return n!==void 0?/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(n)&&Zr(e,n)?i:null:i;if(!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(o))return i;i=o}}function Ml(e,t){let n=t.replace(/\$\{([a-zA-Z_][a-zA-Z0-9_]*)\}/g,(r,s)=>e.state.env.get(s)??"");return n=n.replace(/\$([a-zA-Z_][a-zA-Z0-9_]*)/g,(r,s)=>e.state.env.get(s)??""),n}function H(e,t){return t==="FUNCNAME"?(e.state.funcNameStack??[]).map((i,o)=>[o,i]):t==="BASH_LINENO"?(e.state.callLineStack??[]).map((i,o)=>[o,String(i)]):t==="BASH_SOURCE"?(e.state.sourceStack??[]).map((i,o)=>[o,i]):e.state.associativeArrays?.has(t)?St(e,t).map(i=>[i,ie(e,t,i)??""]):Ee(e,t).map(s=>[s,ie(e,t,s)??""])}function pt(e,t){return t==="FUNCNAME"?(e.state.funcNameStack?.length??0)>0:t==="BASH_LINENO"?(e.state.callLineStack?.length??0)>0:t==="BASH_SOURCE"?(e.state.sourceStack?.length??0)>0:e.state.associativeArrays?.has(t)?ke(e,t):ke(e,t)}async function re(e,t,n=!0){switch(t){case"?":return String(e.state.lastExitCode);case"$":return String(e.state.virtualPid);case"#":return e.state.env.get("#")||"0";case"@":return e.state.env.get("@")||"";case"_":return e.state.lastArg;case"-":{let i="";return i+="h",e.state.options.errexit&&(i+="e"),e.state.options.noglob&&(i+="f"),e.state.options.nounset&&(i+="u"),e.state.options.verbose&&(i+="v"),e.state.options.xtrace&&(i+="x"),i+="B",e.state.options.noclobber&&(i+="C"),i+="s",i}case"*":{let i=Number.parseInt(e.state.env.get("#")||"0",10);if(i===0)return"";let o=[];for(let a=1;a<=i;a++)o.push(e.state.env.get(String(a))||"");return o.join(Z(e.state.env))}case"0":return e.state.env.get("0")||"bash";case"PWD":return e.state.env.get("PWD")??"";case"OLDPWD":return e.state.env.get("OLDPWD")??"";case"PPID":return String(e.state.virtualPpid);case"UID":return String(e.state.virtualUid);case"EUID":return String(e.state.virtualUid);case"RANDOM":return String(Math.floor(Math.random()*32768));case"SECONDS":return String(Math.floor((Date.now()-e.state.startTime)/1e3));case"BASH_VERSION":return Da;case"!":return String(e.state.lastBackgroundPid);case"BASHPID":return String(e.state.bashPid);case"LINENO":return String(e.state.currentLine);case"FUNCNAME":{let i=e.state.funcNameStack?.[0];if(i!==void 0)return i;if(n&&e.state.options.nounset)throw new Be("FUNCNAME");return""}case"BASH_LINENO":{let i=e.state.callLineStack?.[0];if(i!==void 0)return String(i);if(n&&e.state.options.nounset)throw new Be("BASH_LINENO");return""}case"BASH_SOURCE":{let i=e.state.sourceStack?.[0];if(i!==void 0)return i;if(n&&e.state.options.nounset)throw new Be("BASH_SOURCE");return""}}if(/^[a-zA-Z_][a-zA-Z0-9_]*\[\]$/.test(t))throw new Ze(`\${${t}}`);let r=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(r){let i=r[1],o=r[2];if(le(e,i)){let c=Te(e,i);if(c&&c!==i){if(c.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/))return"";i=c}}if(o==="@"||o==="*"){let c=H(e,i);if(c.length>0){let d=o==="*"?Z(e.state.env):" ",p=W(d)*(c.length-1);for(let[,h]of c)if(p+=W(h),p>e.limits.maxStringLength)throw new C(`array expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return c.map(([,h])=>h).join(d)}let f=e.state.env.get(i);return f!==void 0?f:""}if(i==="FUNCNAME"){let c=Number.parseInt(o,10);return!Number.isNaN(c)&&c>=0?e.state.funcNameStack?.[c]??"":""}if(i==="BASH_LINENO"){let c=Number.parseInt(o,10);if(!Number.isNaN(c)&&c>=0){let f=e.state.callLineStack?.[c];return f!==void 0?String(f):""}return""}if(i==="BASH_SOURCE"){let c=Number.parseInt(o,10);return!Number.isNaN(c)&&c>=0?e.state.sourceStack?.[c]??"":""}if(e.state.associativeArrays?.has(i)){let c=_r(o);c=Ml(e,c);let f=ie(e,i,c);if(f===void 0&&n&&e.state.options.nounset)throw new Be(`${i}[${o}]`);return f||""}let l;if(/^-?\d+$/.test(o))l=Number.parseInt(o,10);else try{let c=new G,f=te(c,o);l=await X(e,f.expression)}catch{let c=e.state.env.get(o);l=c?Number.parseInt(c,10):0,Number.isNaN(l)&&(l=0)}if(l<0){let c=H(e,i),f=e.state.currentLine;if(c.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${f}: ${i}: bad array subscript
102
102
  `,"";let p=Math.max(...c.map(([m])=>typeof m=="number"?m:0))+1+l;return p<0?(e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${f}: ${i}: bad array subscript
103
- `,""):ie(e,i,p)||""}let u=ie(e,i,l);if(u!==void 0)return u;if(l===0){let c=e.state.env.get(i);if(c!==void 0)return c}if(n&&e.state.options.nounset)throw new Be(`${i}[${l}]`);return""}if(/^[1-9][0-9]*$/.test(t)){let i=e.state.env.get(t);if(i===void 0&&n&&e.state.options.nounset)throw new Be(t);return i||""}if(le(e,t)){let i=Te(e,t);if(i===void 0)return"";if(i!==t)return await re(e,i,n);let o=e.state.env.get(t);if((o===void 0||o==="")&&n&&e.state.options.nounset)throw new Be(t);return o||""}let s=e.state.env.get(t);if(s!==void 0)return e.state.tempEnvBindings?.some(i=>i.has(t))&&(e.state.accessedTempEnvVars=e.state.accessedTempEnvVars||new Set,e.state.accessedTempEnvVars.add(t)),s;if(ht(e,t)){let i=ie(e,t,0);if(i!==void 0)return i;if(n&&e.state.options.nounset)throw new Be(t);return""}if(n&&e.state.options.nounset)throw new Be(t);return""}async function vt(e,t){if(new Set(["?","$","#","_","-","0","PPID","UID","EUID","RANDOM","SECONDS","BASH_VERSION","!","BASHPID","LINENO"]).has(t))return!0;if(t==="@"||t==="*")return Number.parseInt(e.state.env.get("#")||"0",10)>0;if(t==="PWD"||t==="OLDPWD")return e.state.env.has(t);let r=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(r){let s=r[1],i=r[2];if(le(e,s)){let l=Te(e,s);if(l&&l!==s){if(l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/))return!1;s=l}}if(i==="@"||i==="*")return G(e,s).length>0?!0:e.state.env.has(s);if(e.state.associativeArrays?.has(s)){let l=_l(e,Ir(i));return zt(e,s,l)}let a;if(/^-?\d+$/.test(i))a=Number.parseInt(i,10);else try{let l=new j,u=te(l,i);a=await X(e,u.expression)}catch{let l=e.state.env.get(i);a=l?Number.parseInt(l,10):0,Number.isNaN(a)&&(a=0)}if(a<0){let l=G(e,s);if(l.length===0)return!1;let c=Math.max(...l.map(([f])=>typeof f=="number"?f:0))+1+a;return c<0?!1:zt(e,s,c)}return zt(e,s,a)}if(le(e,t)){let s=Te(e,t);return s===void 0||s===t?e.state.env.has(t):vt(e,s)}return e.state.env.has(t)?!0:ht(e,t)?zt(e,t,0):!1}async function Ll(e,t){let n="",r=0;for(;r<t.length;){if(t[r]==="$"){if(t[r+1]==="{"){let s=1,i=r+2;for(;i<t.length&&s>0;)t[i]==="{"?s++:t[i]==="}"&&s--,i++;n+=t.slice(r,i),r=i;continue}if(t[r+1]==="("){let s=1,i=r+2;for(;i<t.length&&s>0;)t[i]==="("?s++:t[i]===")"&&s--,i++;n+=t.slice(r,i),r=i;continue}if(/[a-zA-Z_]/.test(t[r+1]||"")){let s=r+1;for(;s<t.length&&/[a-zA-Z0-9_]/.test(t[s]);)s++;let i=t.slice(r+1,s),o=await re(e,i);n+=o,r=s;continue}if(/[0-9]/.test(t[r+1]||"")){let s=r+1;for(;s<t.length&&/[0-9]/.test(t[s]);)s++;let i=t.slice(r+1,s),o=await re(e,i);n+=o,r=s;continue}if(/[*@#?\-!$]/.test(t[r+1]||"")){let s=t[r+1],i=await re(e,s);n+=i,r+=2;continue}}if(t[r]==='"'){for(n+='"',r++;r<t.length&&t[r]!=='"';)if(t[r]==="$"&&/[a-zA-Z_]/.test(t[r+1]||"")){let s=r+1;for(;s<t.length&&/[a-zA-Z0-9_]/.test(t[s]);)s++;let i=t.slice(r+1,s),o=await re(e,i);n+=o,r=s}else t[r]==="\\"?(n+=t[r],r++,r<t.length&&(n+=t[r],r++)):(n+=t[r],r++);r<t.length&&(n+='"',r++);continue}n+=t[r],r++}return n}async function ki(e,t){let n=t,r=t.startsWith('"')&&t.endsWith('"'),s=t.startsWith("'")&&t.endsWith("'");if((r||s)&&(n=t.slice(1,-1)),s)return n;let i="",o=0;for(;o<n.length;)if(n[o]==="$")if(n[o+1]==="("){let a=1,l=o+2;for(;l<n.length&&a>0;)n[l]==="("&&n[l-1]==="$"||n[l]==="("?a++:n[l]===")"&&a--,l++;let u=n.slice(o+2,l-1);if(e.execFn){let c=await e.execFn(u,{signal:e.state.signal});i+=c.stdout.replace(/\n+$/,""),c.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+c.stderr)}o=l}else if(n[o+1]==="{"){let a=1,l=o+2;for(;l<n.length&&a>0;)n[l]==="{"?a++:n[l]==="}"&&a--,l++;let u=n.slice(o+2,l-1),c=await re(e,u);i+=c,o=l}else if(/[a-zA-Z_]/.test(n[o+1]||"")){let a=o+1;for(;a<n.length&&/[a-zA-Z0-9_]/.test(n[a]);)a++;let l=n.slice(o+1,a),u=await re(e,l);i+=u,o=a}else i+=n[o],o++;else if(n[o]==="`"){let a=o+1;for(;a<n.length&&n[a]!=="`";)a++;let l=n.slice(o+1,a);if(e.execFn){let u=await e.execFn(l,{signal:e.state.signal});i+=u.stdout.replace(/\n+$/,""),u.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+u.stderr)}o=a+1}else i+=n[o],o++;return i}var lr=1e4,Pi={maxResults:lr,maxStringBytes:10*1024*1024};function Gr(e,t,n,r){if(e.length>=n.maxResults)return!1;let s=F(t);if(s>n.maxStringBytes-r.value)throw new P(`brace expansion string limit exceeded (${n.maxStringBytes} bytes)`,"string_length");return e.push(t),r.value+=s,!0}function rp(e,t,n,r,s,i=Pi){let o=n??1;o===0&&(o=1);let a=Math.abs(o),l=[],u=0;if(r?.match(/^-?0\d/)&&(u=Math.max(u,r.replace(/^-/,"").length)),s?.match(/^-?0\d/)&&(u=Math.max(u,s.replace(/^-/,"").length)),u>i.maxStringBytes)throw new P(`brace expansion padding limit exceeded (${i.maxStringBytes} bytes)`,"string_length");let c={value:0},f=d=>{if(u>0){let p=d<0,h=String(Math.abs(d)).padStart(u,"0");return p?`-${h}`:h}return String(d)};if(e<=t)for(let d=e,p=0;d<=t&&p<lr&&Gr(l,f(d),i,c);d+=a,p++);else for(let d=e,p=0;d>=t&&p<lr&&Gr(l,f(d),i,c);d-=a,p++);return l}function sp(e,t,n,r=Pi){let s=n??1;s===0&&(s=1);let i=e.charCodeAt(0),o=t.charCodeAt(0),a=Math.abs(s),l=e>="A"&&e<="Z",u=e>="a"&&e<="z",c=t>="A"&&t<="Z",f=t>="a"&&t<="z";if(l&&f||u&&c){let h=n!==void 0?`..${n}`:"";throw new kr(`{${e}..${t}${h}}: invalid sequence`)}let d=[],p={value:0};if(i<=o)for(let h=i,m=0;h<=o&&m<lr&&Gr(d,String.fromCharCode(h),r,p);h+=a,m++);else for(let h=i,m=0;h>=o&&m<lr&&Gr(d,String.fromCharCode(h),r,p);h-=a,m++);return d}function Ci(e,t,n,r,s,i=Pi){let o=n!==void 0?`..${n}`:"";return typeof e=="number"&&typeof t=="number"?{expanded:rp(e,t,n,r,s,i),literal:`{${e}..${t}${o}}`}:typeof e=="string"&&typeof t=="string"?{expanded:sp(e,t,n,i),literal:`{${e}..${t}${o}}`}:{expanded:null,literal:`{${e}..${t}${o}}`}}function Tl(e){if(e.statements.length!==1)return null;let t=e.statements[0];if(t.operators.length!==0||t.pipelines.length!==1)return null;let n=t.pipelines[0];if(n.negated||n.commands.length!==1)return null;let r=n.commands[0];if(r.type!=="SimpleCommand")return null;let s=r;if(s.name!==null||s.args.length!==0||s.assignments.length!==0||s.redirections.length!==1)return null;let i=s.redirections[0];return i.operator!=="<"||i.target.type!=="Word"?null:{target:i.target}}function xt(e,t){return!!(/[*?[]/.test(e)||t&&/[@*+?!]\(/.test(e))}function Ni(e){let t="",n=0;for(;n<e.length;)e[n]==="\\"&&n+1<e.length?(t+=e[n+1],n+=2):(t+=e[n],n++);return t}function Xe(e){return e.replace(/([*?[\]\\()|])/g,"\\$1")}function Ln(e){return e.replace(/[\\^$.*+?()[\]{}|]/g,"\\$&")}function ae(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function se(e,t,n=!1){let r="",s=0;for(;s<e.length;){let i=e[s];if(n&&(i==="@"||i==="*"||i==="+"||i==="?"||i==="!")&&s+1<e.length&&e[s+1]==="("){let o=ip(e,s+1);if(o!==-1){let a=e.slice(s+2,o),u=op(a).map(f=>se(f,t,n)),c=u.length>0?u.join("|"):"(?:)";i==="@"?r+=`(?:${c})`:i==="*"?r+=`(?:${c})*`:i==="+"?r+=`(?:${c})+`:i==="?"?r+=`(?:${c})?`:i==="!"&&(r+=`(?!(?:${c})$).*`),s=o+1;continue}}if(i==="\\")if(s+1<e.length){let o=e[s+1];/[\\^$.|+(){}[\]*?]/.test(o)?r+=`\\${o}`:r+=o,s+=2}else r+="\\\\",s++;else if(i==="*")r+=t?".*":".*?",s++;else if(i==="?")r+=".",s++;else if(i==="["){let o=ap(e,s);if(o===-1)r+="\\[",s++;else{let a=e.slice(s+1,o);r+=lp(a),s=o+1}}else/[\^$.|+(){}]/.test(i)?(r+=`\\${i}`,s++):(r+=i,s++)}return r}function ip(e,t){let n=1,r=t+1;for(;r<e.length&&n>0;){let s=e[r];if(s==="\\"){r+=2;continue}if(s==="(")n++;else if(s===")"&&(n--,n===0))return r;r++}return-1}function op(e){let t=[],n="",r=0,s=0;for(;s<e.length;){let i=e[s];if(i==="\\"){n+=i,s+1<e.length?(n+=e[s+1],s+=2):s++;continue}i==="("?(r++,n+=i):i===")"?(r--,n+=i):i==="|"&&r===0?(t.push(n),n=""):n+=i,s++}return t.push(n),t}function ap(e,t){let n=t+1;for(n<e.length&&e[n]==="^"&&n++,n<e.length&&e[n]==="]"&&n++;n<e.length;){if(e[n]==="\\"&&n+1<e.length){n+=2;continue}if(e[n]==="]")return n;if(e[n]==="'"){let r=e.indexOf("'",n+1);if(r!==-1){n=r+1;continue}}if(e[n]==="["&&n+1<e.length&&e[n+1]===":"){let r=e.indexOf(":]",n+2);if(r!==-1){n=r+2;continue}}n++}return-1}function lp(e){let t="[",n=0;for((e[0]==="^"||e[0]==="!")&&(t+="^",n++);n<e.length;){if(e[n]==="'"){let s=e.indexOf("'",n+1);if(s!==-1){let i=e.slice(n+1,s);for(let o of i)o==="\\"?t+="\\\\":o==="]"?t+="\\]":o==="^"&&t==="["?t+="\\^":t+=o;n=s+1;continue}}if(e[n]==="["&&n+1<e.length&&e[n+1]===":"){let s=e.indexOf(":]",n+2);if(s!==-1){let i=e.slice(n+2,s);t+=cp(i),n=s+2;continue}}let r=e[n];r==="\\"?n+1<e.length?(t+=`\\${e[n+1]}`,n+=2):(t+="\\\\",n++):r==="-"&&n>0&&n<e.length-1?(t+="-",n++):r==="^"&&n===0?(t+="^",n++):(r==="]"&&n===0?t+="\\]":t+=r,n++)}return t+="]",t}var up=new Map([["alnum","a-zA-Z0-9"],["alpha","a-zA-Z"],["ascii","\\x00-\\x7F"],["blank"," \\t"],["cntrl","\\x00-\\x1F\\x7F"],["digit","0-9"],["graph","!-~"],["lower","a-z"],["print"," -~"],["punct","!-/:-@\\[-`{-~"],["space"," \\t\\n\\r\\f\\v"],["upper","A-Z"],["word","a-zA-Z0-9_"],["xdigit","0-9A-Fa-f"]]);function cp(e){return up.get(e)??""}async function Gt(e,t,n,r,s){let i="",o=e.state.shoptOptions.extglob;for(let a of t.parts)if(a.type==="Glob")i+=se(a.pattern,n,o);else if(a.type==="Literal")i+=se(a.value,n,o);else if(a.type==="SingleQuoted"||a.type==="Escaped")i+=ae(a.value);else if(a.type==="DoubleQuoted"){let l=await r(e,a.parts);i+=ae(l)}else if(a.type==="ParameterExpansion"){let l=await s(e,a);i+=se(l,n,o)}else{let l=await s(e,a);i+=ae(l)}return i}function mt(e,t,n,r,s){if(r==="prefix")return e.executionScope.consumeLimited("pattern-removal",Math.max(1,t.length),e.limits.maxGlobOperations,"pattern removal"),me(`^${n}`,"s").replace(t,"");let i=me(`${n}$`,"s");if(s)return e.executionScope.consumeLimited("pattern-removal",Math.max(1,t.length),e.limits.maxGlobOperations,"pattern removal"),i.replace(t,"");e.executionScope.consumeLimited("pattern-removal",Math.max(1,t.length),e.limits.maxGlobOperations,"pattern removal");let o=me(`^(?:.*)(${n})$`,"s").exec(t);if(!o)return t;let a=o[1]??"";return t.slice(0,t.length-a.length)}function Tn(e,t){let n=new Set;for(let r of e.state.env.keys())r.startsWith(t)&&n.add(r);for(let r of e.state.arrays?.keys()??[])r.startsWith(t)&&n.add(r);return[...n].sort()}function Hr(e,t,n,r,s){let i=new $n(e.limits.maxStringLength,"pattern replacement",()=>new P(`pattern replacement: string length limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length"));n.lastIndex=0;let o=0,a=n.exec(t);for(;a!==null&&(e.executionScope.consumeLimited("pattern_operations",1,e.limits.maxGlobOperations,"pattern replacement"),!(s&&a[0].length===0&&a.index===t.length||(i.append(t.slice(o,a.index)),i.append(r),o=a.index+a[0].length,!s)));)a[0].length===0&&(o++,n.lastIndex<=a.index&&(n.lastIndex=a.index+1)),a=n.exec(t);return i.append(t.slice(o)),n.lastIndex=0,i.build()}function Fl(e){let t=[],n=0;return{append(r){let s=F(r);if(s>e-n)throw new P(`prompt expansion exceeds string length limit (${e} bytes)`,"string_length");r&&t.push(r),n+=s},build:()=>t.join("")}}function fp(e,t,n){let r=(o,a=2)=>String(o).padStart(a,"0");if(e===""){let o=r(t.getHours()),a=r(t.getMinutes()),l=r(t.getSeconds());return`${o}:${a}:${l}`}let s=Fl(n),i=0;for(;i<e.length;)if(e[i]==="%"){if(i+1>=e.length){s.append("%"),i++;continue}let o=e[i+1];switch(o){case"H":s.append(r(t.getHours()));break;case"M":s.append(r(t.getMinutes()));break;case"S":s.append(r(t.getSeconds()));break;case"d":s.append(r(t.getDate()));break;case"m":s.append(r(t.getMonth()+1));break;case"Y":s.append(String(t.getFullYear()));break;case"y":s.append(r(t.getFullYear()%100));break;case"I":{let a=t.getHours()%12;a===0&&(a=12),s.append(r(a));break}case"p":s.append(t.getHours()<12?"AM":"PM");break;case"P":s.append(t.getHours()<12?"am":"pm");break;case"%":s.append("%");break;case"a":{let a=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];s.append(a[t.getDay()]);break}case"b":{let a=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];s.append(a[t.getMonth()]);break}default:s.append(`%${o}`)}i+=2}else s.append(e[i]),i++;return s.build()}function ur(e,t){let n=Fl(e.limits.maxStringLength),r=0,s=e.state.env.get("USER")||e.state.env.get("LOGNAME")||"user",i=e.state.env.get("HOSTNAME")||"localhost",o=i.split(".")[0],a=e.state.env.get("PWD")||"/",l=e.state.env.get("HOME")||"/",u=a.startsWith(l)?`~${a.slice(l.length)}`:a,c=a.split("/").pop()||a,f=new Date,d=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],p=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],h=e.state.env.get("__COMMAND_NUMBER")||"1";for(;r<t.length;){let m=t[r];if(m==="\\"){if(r+1>=t.length){n.append("\\"),r++;continue}let E=t[r+1];if(E>="0"&&E<="7"){let S="",y=r+1;for(;y<t.length&&y<r+4&&t[y]>="0"&&t[y]<="7";)S+=t[y],y++;let g=Number.parseInt(S,8)%256;n.append(String.fromCharCode(g)),r=y;continue}switch(E){case"\\":n.append("\\"),r+=2;break;case"a":n.append("\x07"),r+=2;break;case"e":n.append("\x1B"),r+=2;break;case"n":n.append(`
104
- `),r+=2;break;case"r":n.append("\r"),r+=2;break;case"$":n.append("$"),r+=2;break;case"[":case"]":r+=2;break;case"u":n.append(s),r+=2;break;case"h":n.append(o),r+=2;break;case"H":n.append(i),r+=2;break;case"w":n.append(u),r+=2;break;case"W":n.append(c),r+=2;break;case"d":{let S=String(f.getDate()).padStart(2," ");n.append(`${d[f.getDay()]} ${p[f.getMonth()]} ${S}`),r+=2;break}case"t":{let S=String(f.getHours()).padStart(2,"0"),y=String(f.getMinutes()).padStart(2,"0"),g=String(f.getSeconds()).padStart(2,"0");n.append(`${S}:${y}:${g}`),r+=2;break}case"T":{let S=f.getHours()%12;S===0&&(S=12);let y=String(S).padStart(2,"0"),g=String(f.getMinutes()).padStart(2,"0"),b=String(f.getSeconds()).padStart(2,"0");n.append(`${y}:${g}:${b}`),r+=2;break}case"@":{let S=f.getHours()%12;S===0&&(S=12);let y=String(S).padStart(2,"0"),g=String(f.getMinutes()).padStart(2,"0"),b=f.getHours()<12?"AM":"PM";n.append(`${y}:${g} ${b}`),r+=2;break}case"A":{let S=String(f.getHours()).padStart(2,"0"),y=String(f.getMinutes()).padStart(2,"0");n.append(`${S}:${y}`),r+=2;break}case"D":if(r+2<t.length&&t[r+2]==="{"){let S=t.indexOf("}",r+3);if(S!==-1){let y=t.slice(r+3,S);n.append(fp(y,f,e.limits.maxStringLength)),r=S+1}else n.append("\\D"),r+=2}else n.append("\\D"),r+=2;break;case"s":n.append("bash"),r+=2;break;case"v":n.append("5.0"),r+=2;break;case"V":n.append("5.0.0"),r+=2;break;case"j":n.append("0"),r+=2;break;case"l":n.append("tty"),r+=2;break;case"#":n.append(h),r+=2;break;case"!":n.append(h),r+=2;break;case"x":n.append("\\x"),r+=2;break;default:n.append(`\\${E}`),r+=2}}else n.append(m),r++}return n.build()}function Ht(e){if(e==="")return"''";if(/[\n\r\t\x00-\x1f\x7f']/.test(e)){let n="$'";for(let r of e)switch(r){case"'":n+="\\'";break;case"\\":n+="\\\\";break;case`
103
+ `,""):ie(e,i,p)||""}let u=ie(e,i,l);if(u!==void 0)return u;if(l===0){let c=e.state.env.get(i);if(c!==void 0)return c}if(n&&e.state.options.nounset)throw new Be(`${i}[${l}]`);return""}if(/^[1-9][0-9]*$/.test(t)){let i=e.state.env.get(t);if(i===void 0&&n&&e.state.options.nounset)throw new Be(t);return i||""}if(le(e,t)){let i=Te(e,t);if(i===void 0)return"";if(i!==t)return await re(e,i,n);let o=e.state.env.get(t);if((o===void 0||o==="")&&n&&e.state.options.nounset)throw new Be(t);return o||""}let s=e.state.env.get(t);if(s!==void 0)return e.state.tempEnvBindings?.some(i=>i.has(t))&&(e.state.accessedTempEnvVars=e.state.accessedTempEnvVars||new Set,e.state.accessedTempEnvVars.add(t)),s;if(pt(e,t)){let i=ie(e,t,0);if(i!==void 0)return i;if(n&&e.state.options.nounset)throw new Be(t);return""}if(n&&e.state.options.nounset)throw new Be(t);return""}async function vt(e,t){if(new Set(["?","$","#","_","-","0","PPID","UID","EUID","RANDOM","SECONDS","BASH_VERSION","!","BASHPID","LINENO"]).has(t))return!0;if(t==="@"||t==="*")return Number.parseInt(e.state.env.get("#")||"0",10)>0;if(t==="PWD"||t==="OLDPWD")return e.state.env.has(t);let r=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(r){let s=r[1],i=r[2];if(le(e,s)){let l=Te(e,s);if(l&&l!==s){if(l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/))return!1;s=l}}if(i==="@"||i==="*")return H(e,s).length>0?!0:e.state.env.has(s);if(e.state.associativeArrays?.has(s)){let l=Ml(e,_r(i));return zt(e,s,l)}let a;if(/^-?\d+$/.test(i))a=Number.parseInt(i,10);else try{let l=new G,u=te(l,i);a=await X(e,u.expression)}catch{let l=e.state.env.get(i);a=l?Number.parseInt(l,10):0,Number.isNaN(a)&&(a=0)}if(a<0){let l=H(e,s);if(l.length===0)return!1;let c=Math.max(...l.map(([f])=>typeof f=="number"?f:0))+1+a;return c<0?!1:zt(e,s,c)}return zt(e,s,a)}if(le(e,t)){let s=Te(e,t);return s===void 0||s===t?e.state.env.has(t):vt(e,s)}return e.state.env.has(t)?!0:pt(e,t)?zt(e,t,0):!1}async function Bl(e,t){let n="",r=0;for(;r<t.length;){if(t[r]==="$"){if(t[r+1]==="{"){let s=1,i=r+2;for(;i<t.length&&s>0;)t[i]==="{"?s++:t[i]==="}"&&s--,i++;n+=t.slice(r,i),r=i;continue}if(t[r+1]==="("){let s=1,i=r+2;for(;i<t.length&&s>0;)t[i]==="("?s++:t[i]===")"&&s--,i++;n+=t.slice(r,i),r=i;continue}if(/[a-zA-Z_]/.test(t[r+1]||"")){let s=r+1;for(;s<t.length&&/[a-zA-Z0-9_]/.test(t[s]);)s++;let i=t.slice(r+1,s),o=await re(e,i);n+=o,r=s;continue}if(/[0-9]/.test(t[r+1]||"")){let s=r+1;for(;s<t.length&&/[0-9]/.test(t[s]);)s++;let i=t.slice(r+1,s),o=await re(e,i);n+=o,r=s;continue}if(/[*@#?\-!$]/.test(t[r+1]||"")){let s=t[r+1],i=await re(e,s);n+=i,r+=2;continue}}if(t[r]==='"'){for(n+='"',r++;r<t.length&&t[r]!=='"';)if(t[r]==="$"&&/[a-zA-Z_]/.test(t[r+1]||"")){let s=r+1;for(;s<t.length&&/[a-zA-Z0-9_]/.test(t[s]);)s++;let i=t.slice(r+1,s),o=await re(e,i);n+=o,r=s}else t[r]==="\\"?(n+=t[r],r++,r<t.length&&(n+=t[r],r++)):(n+=t[r],r++);r<t.length&&(n+='"',r++);continue}n+=t[r],r++}return n}async function Ci(e,t){let n=t,r=t.startsWith('"')&&t.endsWith('"'),s=t.startsWith("'")&&t.endsWith("'");if((r||s)&&(n=t.slice(1,-1)),s)return n;let i="",o=0;for(;o<n.length;)if(n[o]==="$")if(n[o+1]==="("){let a=1,l=o+2;for(;l<n.length&&a>0;)n[l]==="("&&n[l-1]==="$"||n[l]==="("?a++:n[l]===")"&&a--,l++;let u=n.slice(o+2,l-1);if(e.execFn){let c=await e.execFn(u,{signal:e.state.signal});i+=c.stdout.replace(/\n+$/,""),c.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+c.stderr)}o=l}else if(n[o+1]==="{"){let a=1,l=o+2;for(;l<n.length&&a>0;)n[l]==="{"?a++:n[l]==="}"&&a--,l++;let u=n.slice(o+2,l-1),c=await re(e,u);i+=c,o=l}else if(/[a-zA-Z_]/.test(n[o+1]||"")){let a=o+1;for(;a<n.length&&/[a-zA-Z0-9_]/.test(n[a]);)a++;let l=n.slice(o+1,a),u=await re(e,l);i+=u,o=a}else i+=n[o],o++;else if(n[o]==="`"){let a=o+1;for(;a<n.length&&n[a]!=="`";)a++;let l=n.slice(o+1,a);if(e.execFn){let u=await e.execFn(l,{signal:e.state.signal});i+=u.stdout.replace(/\n+$/,""),u.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+u.stderr)}o=a+1}else i+=n[o],o++;return i}var ur=1e4,Ni={maxResults:ur,maxStringBytes:10*1024*1024};function Kr(e,t,n,r){if(e.length>=n.maxResults)return!1;let s=W(t);if(s>n.maxStringBytes-r.value)throw new C(`brace expansion string limit exceeded (${n.maxStringBytes} bytes)`,"string_length");return e.push(t),r.value+=s,!0}function up(e,t,n,r,s,i=Ni){let o=n??1;o===0&&(o=1);let a=Math.abs(o),l=[],u=0;if(r?.match(/^-?0\d/)&&(u=Math.max(u,r.replace(/^-/,"").length)),s?.match(/^-?0\d/)&&(u=Math.max(u,s.replace(/^-/,"").length)),u>i.maxStringBytes)throw new C(`brace expansion padding limit exceeded (${i.maxStringBytes} bytes)`,"string_length");let c={value:0},f=d=>{if(u>0){let p=d<0,h=String(Math.abs(d)).padStart(u,"0");return p?`-${h}`:h}return String(d)};if(e<=t)for(let d=e,p=0;d<=t&&p<ur&&Kr(l,f(d),i,c);d+=a,p++);else for(let d=e,p=0;d>=t&&p<ur&&Kr(l,f(d),i,c);d-=a,p++);return l}function cp(e,t,n,r=Ni){let s=n??1;s===0&&(s=1);let i=e.charCodeAt(0),o=t.charCodeAt(0),a=Math.abs(s),l=e>="A"&&e<="Z",u=e>="a"&&e<="z",c=t>="A"&&t<="Z",f=t>="a"&&t<="z";if(l&&f||u&&c){let h=n!==void 0?`..${n}`:"";throw new Cr(`{${e}..${t}${h}}: invalid sequence`)}let d=[],p={value:0};if(i<=o)for(let h=i,m=0;h<=o&&m<ur&&Kr(d,String.fromCharCode(h),r,p);h+=a,m++);else for(let h=i,m=0;h>=o&&m<ur&&Kr(d,String.fromCharCode(h),r,p);h-=a,m++);return d}function Ri(e,t,n,r,s,i=Ni){let o=n!==void 0?`..${n}`:"";return typeof e=="number"&&typeof t=="number"?{expanded:up(e,t,n,r,s,i),literal:`{${e}..${t}${o}}`}:typeof e=="string"&&typeof t=="string"?{expanded:cp(e,t,n,i),literal:`{${e}..${t}${o}}`}:{expanded:null,literal:`{${e}..${t}${o}}`}}function Wl(e){if(e.statements.length!==1)return null;let t=e.statements[0];if(t.operators.length!==0||t.pipelines.length!==1)return null;let n=t.pipelines[0];if(n.negated||n.commands.length!==1)return null;let r=n.commands[0];if(r.type!=="SimpleCommand")return null;let s=r;if(s.name!==null||s.args.length!==0||s.assignments.length!==0||s.redirections.length!==1)return null;let i=s.redirections[0];return i.operator!=="<"||i.target.type!=="Word"?null:{target:i.target}}function xt(e,t){return!!(/[*?[]/.test(e)||t&&/[@*+?!]\(/.test(e))}function Di(e){let t="",n=0;for(;n<e.length;)e[n]==="\\"&&n+1<e.length?(t+=e[n+1],n+=2):(t+=e[n],n++);return t}function Xe(e){return e.replace(/([*?[\]\\()|])/g,"\\$1")}function Tn(e){return e.replace(/[\\^$.*+?()[\]{}|]/g,"\\$&")}function ae(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function se(e,t,n=!1){let r="",s=0;for(;s<e.length;){let i=e[s];if(n&&(i==="@"||i==="*"||i==="+"||i==="?"||i==="!")&&s+1<e.length&&e[s+1]==="("){let o=fp(e,s+1);if(o!==-1){let a=e.slice(s+2,o),u=dp(a).map(f=>se(f,t,n)),c=u.length>0?u.join("|"):"(?:)";i==="@"?r+=`(?:${c})`:i==="*"?r+=`(?:${c})*`:i==="+"?r+=`(?:${c})+`:i==="?"?r+=`(?:${c})?`:i==="!"&&(r+=`(?!(?:${c})$).*`),s=o+1;continue}}if(i==="\\")if(s+1<e.length){let o=e[s+1];/[\\^$.|+(){}[\]*?]/.test(o)?r+=`\\${o}`:r+=o,s+=2}else r+="\\\\",s++;else if(i==="*")r+=t?".*":".*?",s++;else if(i==="?")r+=".",s++;else if(i==="["){let o=pp(e,s);if(o===-1)r+="\\[",s++;else{let a=e.slice(s+1,o);r+=hp(a),s=o+1}}else/[\^$.|+(){}]/.test(i)?(r+=`\\${i}`,s++):(r+=i,s++)}return r}function fp(e,t){let n=1,r=t+1;for(;r<e.length&&n>0;){let s=e[r];if(s==="\\"){r+=2;continue}if(s==="(")n++;else if(s===")"&&(n--,n===0))return r;r++}return-1}function dp(e){let t=[],n="",r=0,s=0;for(;s<e.length;){let i=e[s];if(i==="\\"){n+=i,s+1<e.length?(n+=e[s+1],s+=2):s++;continue}i==="("?(r++,n+=i):i===")"?(r--,n+=i):i==="|"&&r===0?(t.push(n),n=""):n+=i,s++}return t.push(n),t}function pp(e,t){let n=t+1;for(n<e.length&&e[n]==="^"&&n++,n<e.length&&e[n]==="]"&&n++;n<e.length;){if(e[n]==="\\"&&n+1<e.length){n+=2;continue}if(e[n]==="]")return n;if(e[n]==="'"){let r=e.indexOf("'",n+1);if(r!==-1){n=r+1;continue}}if(e[n]==="["&&n+1<e.length&&e[n+1]===":"){let r=e.indexOf(":]",n+2);if(r!==-1){n=r+2;continue}}n++}return-1}function hp(e){let t="[",n=0;for((e[0]==="^"||e[0]==="!")&&(t+="^",n++);n<e.length;){if(e[n]==="'"){let s=e.indexOf("'",n+1);if(s!==-1){let i=e.slice(n+1,s);for(let o of i)o==="\\"?t+="\\\\":o==="]"?t+="\\]":o==="^"&&t==="["?t+="\\^":t+=o;n=s+1;continue}}if(e[n]==="["&&n+1<e.length&&e[n+1]===":"){let s=e.indexOf(":]",n+2);if(s!==-1){let i=e.slice(n+2,s);t+=yp(i),n=s+2;continue}}let r=e[n];r==="\\"?n+1<e.length?(t+=`\\${e[n+1]}`,n+=2):(t+="\\\\",n++):r==="-"&&n>0&&n<e.length-1?(t+="-",n++):r==="^"&&n===0?(t+="^",n++):(r==="]"&&n===0?t+="\\]":t+=r,n++)}return t+="]",t}var mp=new Map([["alnum","a-zA-Z0-9"],["alpha","a-zA-Z"],["ascii","\\x00-\\x7F"],["blank"," \\t"],["cntrl","\\x00-\\x1F\\x7F"],["digit","0-9"],["graph","!-~"],["lower","a-z"],["print"," -~"],["punct","!-/:-@\\[-`{-~"],["space"," \\t\\n\\r\\f\\v"],["upper","A-Z"],["word","a-zA-Z0-9_"],["xdigit","0-9A-Fa-f"]]);function yp(e){return mp.get(e)??""}async function Gt(e,t,n,r,s){let i="",o=e.state.shoptOptions.extglob;for(let a of t.parts)if(a.type==="Glob")i+=se(a.pattern,n,o);else if(a.type==="Literal")i+=se(a.value,n,o);else if(a.type==="SingleQuoted"||a.type==="Escaped")i+=ae(a.value);else if(a.type==="DoubleQuoted"){let l=await r(e,a.parts);i+=ae(l)}else if(a.type==="ParameterExpansion"){let l=await s(e,a);i+=se(l,n,o)}else{let l=await s(e,a);i+=ae(l)}return i}function ht(e,t,n,r,s){if(r==="prefix")return e.executionScope.consumeLimited("pattern-removal",Math.max(1,t.length),e.limits.maxGlobOperations,"pattern removal"),me(`^${n}`,"s").replace(t,"");let i=me(`${n}$`,"s");if(s)return e.executionScope.consumeLimited("pattern-removal",Math.max(1,t.length),e.limits.maxGlobOperations,"pattern removal"),i.replace(t,"");e.executionScope.consumeLimited("pattern-removal",Math.max(1,t.length),e.limits.maxGlobOperations,"pattern removal");let o=me(`^(?:.*)(${n})$`,"s").exec(t);if(!o)return t;let a=o[1]??"";return t.slice(0,t.length-a.length)}function Fn(e,t){let n=new Set;for(let r of e.state.env.keys())r.startsWith(t)&&n.add(r);for(let r of e.state.arrays?.keys()??[])r.startsWith(t)&&n.add(r);return[...n].sort()}function Xr(e,t,n,r,s){let i=new kn(e.limits.maxStringLength,"pattern replacement",()=>new C(`pattern replacement: string length limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length"));n.lastIndex=0;let o=0,a=n.exec(t);for(;a!==null&&(e.executionScope.consumeLimited("pattern_operations",1,e.limits.maxGlobOperations,"pattern replacement"),!(s&&a[0].length===0&&a.index===t.length||(i.append(t.slice(o,a.index)),i.append(r),o=a.index+a[0].length,!s)));)a[0].length===0&&(o++,n.lastIndex<=a.index&&(n.lastIndex=a.index+1)),a=n.exec(t);return i.append(t.slice(o)),n.lastIndex=0,i.build()}function Vl(e){let t=[],n=0;return{append(r){let s=W(r);if(s>e-n)throw new C(`prompt expansion exceeds string length limit (${e} bytes)`,"string_length");r&&t.push(r),n+=s},build:()=>t.join("")}}function gp(e,t,n){let r=(o,a=2)=>String(o).padStart(a,"0");if(e===""){let o=r(t.getHours()),a=r(t.getMinutes()),l=r(t.getSeconds());return`${o}:${a}:${l}`}let s=Vl(n),i=0;for(;i<e.length;)if(e[i]==="%"){if(i+1>=e.length){s.append("%"),i++;continue}let o=e[i+1];switch(o){case"H":s.append(r(t.getHours()));break;case"M":s.append(r(t.getMinutes()));break;case"S":s.append(r(t.getSeconds()));break;case"d":s.append(r(t.getDate()));break;case"m":s.append(r(t.getMonth()+1));break;case"Y":s.append(String(t.getFullYear()));break;case"y":s.append(r(t.getFullYear()%100));break;case"I":{let a=t.getHours()%12;a===0&&(a=12),s.append(r(a));break}case"p":s.append(t.getHours()<12?"AM":"PM");break;case"P":s.append(t.getHours()<12?"am":"pm");break;case"%":s.append("%");break;case"a":{let a=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];s.append(a[t.getDay()]);break}case"b":{let a=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];s.append(a[t.getMonth()]);break}default:s.append(`%${o}`)}i+=2}else s.append(e[i]),i++;return s.build()}function cr(e,t){let n=Vl(e.limits.maxStringLength),r=0,s=e.state.env.get("USER")||e.state.env.get("LOGNAME")||"user",i=e.state.env.get("HOSTNAME")||"localhost",o=i.split(".")[0],a=e.state.env.get("PWD")||"/",l=e.state.env.get("HOME")||"/",u=a.startsWith(l)?`~${a.slice(l.length)}`:a,c=a.split("/").pop()||a,f=new Date,d=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],p=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],h=e.state.env.get("__COMMAND_NUMBER")||"1";for(;r<t.length;){let m=t[r];if(m==="\\"){if(r+1>=t.length){n.append("\\"),r++;continue}let y=t[r+1];if(y>="0"&&y<="7"){let b="",w=r+1;for(;w<t.length&&w<r+4&&t[w]>="0"&&t[w]<="7";)b+=t[w],w++;let E=Number.parseInt(b,8)%256;n.append(String.fromCharCode(E)),r=w;continue}switch(y){case"\\":n.append("\\"),r+=2;break;case"a":n.append("\x07"),r+=2;break;case"e":n.append("\x1B"),r+=2;break;case"n":n.append(`
104
+ `),r+=2;break;case"r":n.append("\r"),r+=2;break;case"$":n.append("$"),r+=2;break;case"[":case"]":r+=2;break;case"u":n.append(s),r+=2;break;case"h":n.append(o),r+=2;break;case"H":n.append(i),r+=2;break;case"w":n.append(u),r+=2;break;case"W":n.append(c),r+=2;break;case"d":{let b=String(f.getDate()).padStart(2," ");n.append(`${d[f.getDay()]} ${p[f.getMonth()]} ${b}`),r+=2;break}case"t":{let b=String(f.getHours()).padStart(2,"0"),w=String(f.getMinutes()).padStart(2,"0"),E=String(f.getSeconds()).padStart(2,"0");n.append(`${b}:${w}:${E}`),r+=2;break}case"T":{let b=f.getHours()%12;b===0&&(b=12);let w=String(b).padStart(2,"0"),E=String(f.getMinutes()).padStart(2,"0"),S=String(f.getSeconds()).padStart(2,"0");n.append(`${w}:${E}:${S}`),r+=2;break}case"@":{let b=f.getHours()%12;b===0&&(b=12);let w=String(b).padStart(2,"0"),E=String(f.getMinutes()).padStart(2,"0"),S=f.getHours()<12?"AM":"PM";n.append(`${w}:${E} ${S}`),r+=2;break}case"A":{let b=String(f.getHours()).padStart(2,"0"),w=String(f.getMinutes()).padStart(2,"0");n.append(`${b}:${w}`),r+=2;break}case"D":if(r+2<t.length&&t[r+2]==="{"){let b=t.indexOf("}",r+3);if(b!==-1){let w=t.slice(r+3,b);n.append(gp(w,f,e.limits.maxStringLength)),r=b+1}else n.append("\\D"),r+=2}else n.append("\\D"),r+=2;break;case"s":n.append("bash"),r+=2;break;case"v":n.append("5.0"),r+=2;break;case"V":n.append("5.0.0"),r+=2;break;case"j":n.append("0"),r+=2;break;case"l":n.append("tty"),r+=2;break;case"#":n.append(h),r+=2;break;case"!":n.append(h),r+=2;break;case"x":n.append("\\x"),r+=2;break;default:n.append(`\\${y}`),r+=2}}else n.append(m),r++}return n.build()}function Ht(e){if(e==="")return"''";if(/[\n\r\t\x00-\x1f\x7f']/.test(e)){let n="$'";for(let r of e)switch(r){case"'":n+="\\'";break;case"\\":n+="\\\\";break;case`
105
105
  `:n+="\\n";break;case"\r":n+="\\r";break;case" ":n+="\\t";break;default:{let s=r.charCodeAt(0);s<32||s===127?n+=`\\${s.toString(8).padStart(3,"0")}`:n+=r}}return`${n}'`}return`'${e}'`}function je(e,t){e.state.readonlyVars=e.state.readonlyVars||new Set,e.state.readonlyVars.add(t)}function Fe(e,t){return e.state.readonlyVars?.has(t)??!1}function ue(e,t,n="bash"){if(Fe(e,t)){let r=`${n}: ${t}: readonly variable
106
- `;throw new q(1,"",r)}return null}function yt(e,t){let n=e.state.exportedVars?.has(t)??!1;if(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(t),e.state.localScopes.length>0&&e.state.localScopes[e.state.localScopes.length-1].has(t)&&!n){for(e.state.localExportedVars||(e.state.localExportedVars=[]);e.state.localExportedVars.length<e.state.localScopes.length;)e.state.localExportedVars.push(new Set);e.state.localExportedVars[e.state.localExportedVars.length-1].add(t)}}function Zr(e,t){e.state.exportedVars?.delete(t)}function Zt(e,t){if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t))return"";let n="",r=ve(e,t)?.kind==="indexed",s=e.state.associativeArrays?.has(t)??!1;return r&&!s&&(n+="a"),s&&(n+="A"),e.state.integerVars?.has(t)&&(n+="i"),le(e,t)&&(n+="n"),Fe(e,t)&&(n+="r"),e.state.exportedVars?.has(t)&&(n+="x"),n}async function Ml(e,t,n,r){return e.coverage?.hit("bash:expansion:default_value"),(n.isUnset||t.checkEmpty&&n.isEmpty)&&t.word?r(e,t.word.parts,n.inDoubleQuotes):n.effectiveValue}function Ri(e){if(/^(?:\d+|[@*#?$!-])$/.test(e))throw new q(1,"",`bash: $${e}: cannot assign in this way
107
- `)}async function Bl(e,t,n,r,s){e.coverage?.hit("bash:expansion:assign_default");let i=r.isUnset||n.checkEmpty&&r.isEmpty;if(i&&Ri(t),i&&n.word){let o=await s(e,n.word.parts,r.inDoubleQuotes),a=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(a){let[,l,u]=a;if(u==="@"||u==="*")throw new q(1,"",`${e.state.expansionStderr||""}bash: ${t}: bad array subscript
108
- `);let c;if(/^\d+$/.test(u))c=Number.parseInt(u,10);else{try{let f=new j,d=te(f,u);c=await X(e,d.expression)}catch{let f=e.state.env.get(u);c=f?Number.parseInt(f,10):0}Number.isNaN(c)&&(c=0)}U(e,l,c,o)}else e.state.env.set(t,o);return o}return r.effectiveValue}async function Wl(e,t,n,r,s){if(e.coverage?.hit("bash:expansion:error_if_unset"),r.isUnset||n.checkEmpty&&r.isEmpty){let o=n.word?await s(e,n.word.parts,r.inDoubleQuotes):`${t}: parameter null or not set`;throw new q(1,"",`bash: ${o}
109
- `)}return r.effectiveValue}async function Vl(e,t,n,r){return e.coverage?.hit("bash:expansion:use_alternative"),!(n.isUnset||t.checkEmpty&&n.isEmpty)&&t.word?r(e,t.word.parts,n.inDoubleQuotes):""}async function zl(e,t,n,r,s){e.coverage?.hit("bash:expansion:pattern_removal");let i=n.pattern?await Gt(e,n.pattern,n.greedy,r,s):"";return mt(e,t,i,n.side,n.greedy)}async function ql(e,t,n,r,s){e.coverage?.hit("bash:expansion:pattern_replacement");let i="",o=e.state.shoptOptions.extglob;if(n.pattern)for(let u of n.pattern.parts)if(u.type==="Glob")i+=se(u.pattern,!0,o);else if(u.type==="Literal")i+=se(u.value,!0,o);else if(u.type==="SingleQuoted"||u.type==="Escaped")i+=ae(u.value);else if(u.type==="DoubleQuoted"){let c=await r(e,u.parts);i+=ae(c)}else if(u.type==="ParameterExpansion"){let c=await s(e,u);i+=se(c,!0,o)}else{let c=await s(e,u);i+=ae(c)}let a=n.replacement?await r(e,n.replacement.parts):"";if(n.anchor==="start"?i=`^${i}`:n.anchor==="end"&&(i=`${i}$`),i==="")return t;let l=n.all?"gs":"s";try{let u=me(i,l);return Hr(e,t,u,a,n.all)}catch(u){if(u instanceof P)throw u;return t}}function Di(e,t,n){e.coverage?.hit("bash:expansion:length");let r=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(r){let s=r[1],i=G(e,s);return i.length>0?String(i.length):e.state.env.get(s)!==void 0?"1":"0"}if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t)&&ht(e,t)){if(t==="FUNCNAME"){let i=e.state.funcNameStack?.[0]||"";return String([...i].length)}if(t==="BASH_LINENO"){let i=e.state.callLineStack?.[0];return String(i!==void 0?[...String(i)].length:0)}let s=ie(e,t,0)||"";return String([...s].length)}return String([...n].length)}async function Ul(e,t,n,r){e.coverage?.hit("bash:expansion:substring");let s=await X(e,r.offset.expression),i=r.length?await X(e,r.length.expression):void 0;if(t==="@"||t==="*"){let u=Number.parseInt(e.state.env.get("#")||"0",10),c=[];for(let h=1;h<=u;h++)c.push(e.state.env.get(String(h))||"");let f=e.state.env.get("0")||"bash",d,p;if(s<=0)if(d=[f,...c],s<0){if(p=d.length+s,p<0)return""}else p=0;else d=c,p=s-1;if(p<0||p>=d.length)return"";if(i!==void 0){let h=i<0?d.length+i:p+i;return d.slice(p,Math.max(p,h)).join(" ")}return d.slice(p).join(" ")}let o=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(o){let u=o[1];if(e.state.associativeArrays?.has(u))throw new q(1,"",`bash: \${${u}[@]: 0: 3}: bad substitution
110
- `);let c=G(e,u),f=0;if(s<0){if(c.length>0){let d=c[c.length-1][0],h=(typeof d=="number"?d:0)+1+s;if(h<0||(f=c.findIndex(([m])=>typeof m=="number"&&m>=h),f<0))return""}}else if(f=c.findIndex(([d])=>typeof d=="number"&&d>=s),f<0)return"";if(i!==void 0){if(i<0)throw new oe(`${o[1]}[@]: substring expression < 0`);return c.slice(f,f+i).map(([,d])=>d).join(" ")}return c.slice(f).map(([,d])=>d).join(" ")}let a=[...n],l=s;if(l<0&&(l=Math.max(0,a.length+l)),i!==void 0){if(i<0){let u=a.length+i;return a.slice(l,Math.max(l,u)).join("")}return a.slice(l,l+i).join("")}return a.slice(l).join("")}async function jl(e,t,n,r,s){if(e.coverage?.hit("bash:expansion:case_modification"),n.pattern){let i=e.state.shoptOptions.extglob,o="";for(let f of n.pattern.parts)if(f.type==="Glob")o+=se(f.pattern,!0,i);else if(f.type==="Literal")o+=se(f.value,!0,i);else if(f.type==="SingleQuoted"||f.type==="Escaped")o+=ae(f.value);else if(f.type==="DoubleQuoted"){let d=await r(e,f.parts);o+=ae(d)}else if(f.type==="ParameterExpansion"){let d=await s(e,f);o+=se(d,!0,i)}let a=me(`^(?:${o})$`),l=n.direction==="upper"?f=>f.toUpperCase():f=>f.toLowerCase(),u="",c=!1;for(let f of t)!n.all&&c?u+=f:a.test(f)?(u+=l(f),c=!0):u+=f;return u}return n.direction==="upper"?n.all?t.toUpperCase():t.charAt(0).toUpperCase()+t.slice(1):n.all?t.toLowerCase():t.charAt(0).toLowerCase()+t.slice(1)}function Gl(e,t,n,r,s){e.coverage?.hit("bash:expansion:transform");let i=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(i&&s.operator==="Q")return G(e,i[1]).map(([,u])=>Ht(u)).join(" ");if(i&&s.operator==="a")return Zt(e,i[1]);let o=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[.+\]$/);if(o&&s.operator==="a")return Zt(e,o[1]);switch(s.operator){case"Q":return r?"":Ht(n);case"P":return ur(e,n);case"a":return Zt(e,t);case"A":return r?"":`${t}=${Ht(n)}`;case"E":return n.replace(/\\([\\abefnrtv'"?])/g,(a,l)=>{switch(l){case"\\":return"\\";case"a":return"\x07";case"b":return"\b";case"e":return"\x1B";case"f":return"\f";case"n":return`
111
- `;case"r":return"\r";case"t":return" ";case"v":return"\v";case"'":return"'";case'"':return'"';case"?":return"?";default:return l}});case"K":case"k":return r?"":Ht(n);case"u":return n.charAt(0).toUpperCase()+n.slice(1);case"U":return n.toUpperCase();case"L":return n.toLowerCase();default:return n}}async function Hl(e,t,n,r,s,i,o=!1){if(e.coverage?.hit("bash:expansion:indirection"),le(e,t))return En(e,t)||"";let a=/^[a-zA-Z_][a-zA-Z0-9_]*\[([@*])\]$/.test(t);if(r){if(s.innerOp?.type==="UseAlternative")return"";throw new Ze(`\${!${t}}`)}let l=n;if(a&&(l===""||l.includes(" ")))throw new Ze(`\${!${t}}`);let u=l.match(/^[a-zA-Z_][a-zA-Z0-9_]*\[(.+)\]$/);if(u&&u[1].includes("~"))throw new Ze(`\${!${t}}`);if(s.innerOp){let c={type:"ParameterExpansion",parameter:l,operation:s.innerOp};return i(e,c,o)}return await re(e,l)}function Zl(e,t){e.coverage?.hit("bash:expansion:array_keys");let r=G(e,t.array).map(([s])=>String(s));return t.star?r.join(Z(e.state.env)):r.join(" ")}function Ql(e,t){e.coverage?.hit("bash:expansion:var_name_prefix");let n=Tn(e,t.prefix);return t.star?n.join(Z(e.state.env)):n.join(" ")}function Kl(e,t,n,r){let s=Number.parseInt(e.state.env.get("#")||"0",10),i=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(t==="*")return{isEmpty:s===0,effectiveValue:n};if(t==="@")return{isEmpty:s===0||s===1&&e.state.env.get("1")==="",effectiveValue:n};if(i){let[,o,a]=i,l=G(e,o);return l.length===0?{isEmpty:!0,effectiveValue:""}:a==="*"?{isEmpty:r?n==="":!1,effectiveValue:n}:{isEmpty:l.length===1&&l.every(([,u])=>u===""),effectiveValue:n}}return{isEmpty:n==="",effectiveValue:n}}function Qt(e,t){e.lastExitCode=t,e.env.set("?",String(t)),e.lastSubstitutionExitCode=t}function dp(e){switch(e.operator){case"<":case"<&":case"<<":case"<<-":case"<<<":case"<>":return e.fd===null||e.fd===0;default:return!1}}function Qr(e,t){return t.some(dp)?0:e.lastSubstitutionExitCode??0}function Xl(e){let t=0;for(;t<e.length;){let n=e[t];if(n==="\\"&&t+1<e.length){t+=2;continue}if(n==="'"){let r=e.indexOf("'",t+1);if(r!==-1){t=r+1;continue}}if(n==="$"&&t+1<e.length&&e[t+1]==="("||n==="`")return!0;t++}return!1}function Yl(e,t){let n=1,r=t,s=!1,i=!1;for(;r<e.length&&n>0;){let o=e[r];if(o==="\\"&&!s&&r+1<e.length){r+=2;continue}if(o==="'"&&!i){s=!s,r++;continue}if(o==='"'&&!s){i=!i,r++;continue}if(!s&&!i){if(o==="(")n++;else if(o===")"&&(n--,n===0))return r}r++}return-1}async function Kr(e,t){let n=new j,r;try{r=n.parse(t)}catch{return""}let s=e.state.bashPid;e.state.bashPid=e.state.nextVirtualPid++;let i=new Map(e.state.env),o=rt(e.state.arrays),a=e.state.cwd,l=e.state.suppressVerbose;e.state.suppressVerbose=!0;try{let u=await e.executeScript(r),c=u.exitCode;return e.state.env=i,e.state.arrays=o,e.state.cwd=a,e.state.suppressVerbose=l,Qt(e.state,c),u.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+u.stderr),e.state.bashPid=s,u.stdout.replace(/\n+$/,"")}catch(u){if(e.state.env=i,e.state.arrays=o,e.state.cwd=a,e.state.bashPid=s,e.state.suppressVerbose=l,u instanceof P)throw u;return u instanceof q?(Qt(e.state,u.exitCode),u.stdout?.replace(/\n+$/,"")??""):""}}function Ii(e,t){let n="",r=0;for(;r<t.length;){let s=t[r];if(s==="'"){let i=t.indexOf("'",r+1);if(i!==-1){let o=t.slice(r+1,i);n+=Xe(o),r=i+1;continue}}if(s==='"'){let i=-1,o=r+1;for(;o<t.length;){if(t[o]==="\\"){o+=2;continue}if(t[o]==='"'){i=o;break}o++}if(i!==-1){let a=t.slice(r+1,i),l=pp(e,a);n+=Xe(l),r=i+1;continue}}if(s==="$"&&r+1<t.length){let i=t[r+1];if(i==="{"){let o=t.indexOf("}",r+2);if(o!==-1){let a=t.slice(r+2,o);n+=e.state.env.get(a)??"",r=o+1;continue}}else if(/[a-zA-Z_]/.test(i)){let o=r+1;for(;o<t.length&&/[a-zA-Z0-9_]/.test(t[o]);)o++;let a=t.slice(r+1,o);n+=e.state.env.get(a)??"",r=o;continue}}if(s==="\\"&&r+1<t.length){n+=s+t[r+1],r+=2;continue}n+=s,r++}return n}function pp(e,t){let n="",r=0;for(;r<t.length;){let s=t[r];if(s==="\\"&&r+1<t.length){let i=t[r+1];if(i==="$"||i==="`"||i==="\\"||i==='"'){n+=i,r+=2;continue}n+=s,r++;continue}if(s==="$"&&r+1<t.length){let i=t[r+1];if(i==="{"){let o=t.indexOf("}",r+2);if(o!==-1){let a=t.slice(r+2,o);n+=e.state.env.get(a)??"",r=o+1;continue}}else if(/[a-zA-Z_]/.test(i)){let o=r+1;for(;o<t.length&&/[a-zA-Z0-9_]/.test(t[o]);)o++;let a=t.slice(r+1,o);n+=e.state.env.get(a)??"",r=o;continue}}n+=s,r++}return n}async function Jl(e,t){let n="",r=0;for(;r<t.length;){let s=t[r];if(s==="'"){let i=t.indexOf("'",r+1);if(i!==-1){let o=t.slice(r+1,i);n+=Xe(o),r=i+1;continue}}if(s==='"'){let i=-1,o=r+1;for(;o<t.length;){if(t[o]==="\\"){o+=2;continue}if(t[o]==='"'){i=o;break}o++}if(i!==-1){let a=t.slice(r+1,i),l=await hp(e,a);n+=Xe(l),r=i+1;continue}}if(s==="$"&&r+1<t.length&&t[r+1]==="("){let i=Yl(t,r+2);if(i!==-1){let o=t.slice(r+2,i),a=await Kr(e,o);n+=a,r=i+1;continue}}if(s==="`"){let i=t.indexOf("`",r+1);if(i!==-1){let o=t.slice(r+1,i),a=await Kr(e,o);n+=a,r=i+1;continue}}if(s==="$"&&r+1<t.length){let i=t[r+1];if(i==="{"){let o=t.indexOf("}",r+2);if(o!==-1){let a=t.slice(r+2,o);n+=e.state.env.get(a)??"",r=o+1;continue}}else if(/[a-zA-Z_]/.test(i)){let o=r+1;for(;o<t.length&&/[a-zA-Z0-9_]/.test(t[o]);)o++;let a=t.slice(r+1,o);n+=e.state.env.get(a)??"",r=o;continue}}if(s==="\\"&&r+1<t.length){n+=s+t[r+1],r+=2;continue}n+=s,r++}return n}async function hp(e,t){let n="",r=0;for(;r<t.length;){let s=t[r];if(s==="\\"&&r+1<t.length){let i=t[r+1];if(i==="$"||i==="`"||i==="\\"||i==='"'){n+=i,r+=2;continue}n+=s,r++;continue}if(s==="$"&&r+1<t.length&&t[r+1]==="("){let i=Yl(t,r+2);if(i!==-1){let o=t.slice(r+2,i),a=await Kr(e,o);n+=a,r=i+1;continue}}if(s==="`"){let i=t.indexOf("`",r+1);if(i!==-1){let o=t.slice(r+1,i),a=await Kr(e,o);n+=a,r=i+1;continue}}if(s==="$"&&r+1<t.length){let i=t[r+1];if(i==="{"){let o=t.indexOf("}",r+2);if(o!==-1){let a=t.slice(r+2,o);n+=e.state.env.get(a)??"",r=o+1;continue}}else if(/[a-zA-Z_]/.test(i)){let o=r+1;for(;o<t.length&&/[a-zA-Z0-9_]/.test(t[o]);)o++;let a=t.slice(r+1,o);n+=e.state.env.get(a)??"",r=o;continue}}n+=s,r++}return n}function Oi(e,t){if(!t.startsWith("~"))return t;e.coverage?.hit("bash:expansion:tilde");let n=e.state.env.get("HOME")!==void 0?e.state.env.get("HOME"):"/home/user";if(t==="~"||t.startsWith("~/"))return n+t.slice(1);let r=1;for(;r<t.length&&/[a-zA-Z0-9_-]/.test(t[r]);)r++;let s=t.slice(1,r),i=t.slice(r);return i!==""&&!i.startsWith("/")?t:s==="root"?`/root${i}`:t}function Kt(e,t){return t.split(":").map(n=>Oi(e,n)).join(":")}function Ne(e,t,n,r){if(e.length>n-t.length)throw new P(`${r} element limit exceeded (${n})`,"array_elements");for(let s of t)e.push(s)}async function mp(e,t,n,r){let s="";for(let i of t.parts)if(i.type==="Glob")s+=se(i.pattern,!0,e.state.shoptOptions.extglob);else if(i.type==="Literal")s+=se(i.value,!0,e.state.shoptOptions.extglob);else if(i.type==="SingleQuoted"||i.type==="Escaped")s+=ae(i.value);else if(i.type==="DoubleQuoted"){let o=await n(e,i.parts);s+=ae(o)}else if(i.type==="ParameterExpansion"){let o=await r(e,i);s+=se(o,!0,e.state.shoptOptions.extglob)}else{let o=await r(e,i);s+=ae(o)}return s}async function eu(e,t,n,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0];if(s.parts.length!==1||s.parts[0].type!=="ParameterExpansion"||s.parts[0].operation?.type!=="PatternReplacement")return null;let i=s.parts[0],o=i.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!o)return null;let a=o[1],l=o[2]==="*",u=i.operation,c=G(e,a),f=c.map(([,E])=>E);if(c.length===0){let E=e.state.env.get(a);E!==void 0&&f.push(E)}if(f.length===0)return{values:[],quoted:!0};let d="";u.pattern&&(d=await mp(e,u.pattern,n,r));let p=u.replacement?await n(e,u.replacement.parts):"",h=d;u.anchor==="start"?h=`^${d}`:u.anchor==="end"&&(h=`${d}$`);let m=[];try{let E=me(h,u.all?"g":"");for(let S of f)m.push(E.replace(S,p))}catch{m.push(...f)}if(l){let E=Z(e.state.env);return{values:[m.join(E)],quoted:!0}}return{values:m,quoted:!0}}async function tu(e,t,n,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0];if(s.parts.length!==1||s.parts[0].type!=="ParameterExpansion"||s.parts[0].operation?.type!=="PatternRemoval")return null;let i=s.parts[0],o=i.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!o)return null;let a=o[1],l=o[2]==="*",u=i.operation,c=G(e,a),f=c.map(([,h])=>h);if(c.length===0){let h=e.state.env.get(a);h!==void 0&&f.push(h)}if(f.length===0)return{values:[],quoted:!0};let d=u.pattern?await Gt(e,u.pattern,u.greedy,n,r):"",p=[];for(let h of f)p.push(mt(e,h,d,u.side,u.greedy));if(l){let h=Z(e.state.env);return{values:[p.join(h)],quoted:!0}}return{values:p,quoted:!0}}async function nu(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0];if(n.parts.length!==1||n.parts[0].type!=="ParameterExpansion"||n.parts[0].operation?.type!=="DefaultValue"&&n.parts[0].operation?.type!=="UseAlternative"&&n.parts[0].operation?.type!=="AssignDefault")return null;let r=n.parts[0];if(r.operation?.type==="AssignDefault"&&/^(?:\d+|[@*#?$!-])$/.test(r.parameter))return null;let s=r.operation,i=r.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(s.type==="AssignDefault"&&(!i||i[2]==="*"))return null;let o,a=!1;if(i){let l=i[1];a=i[2]==="*";let u=G(e,l),c=u.length>0||e.state.env.has(l),f=u.length===0||u.length===1&&u.every(([,p])=>p===""),d=s.checkEmpty??!1;if(s.type==="UseAlternative"?o=c&&!(d&&f):o=!c||d&&f,!o){if(u.length>0){let h=u.map(([,m])=>m);if(a){let m=Z(e.state.env);return{values:[h.join(m)],quoted:!0}}return{values:h,quoted:!0}}let p=e.state.env.get(l);return p!==void 0?{values:[p],quoted:!0}:{values:[],quoted:!0}}}else{let l=r.parameter,u=await vt(e,l),c=await re(e,l,!1),f=c==="",d=s.checkEmpty??!1;if(s.type==="UseAlternative"?o=u&&!(d&&f):o=!u||d&&f,!o)return{values:[c],quoted:!0}}if(s.type==="AssignDefault")return null;if(o&&s.word){let l=s.word.parts,u=null,c=!1;for(let f of l)if(f.type==="ParameterExpansion"&&!f.operation){let d=f.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(d){u=d[1],c=d[2]==="*";break}}if(u){let f=G(e,u);if(f.length>0){let p=f.map(([,h])=>h);if(c||a){let h=Z(e.state.env);return{values:[p.join(h)],quoted:!0}}return{values:p,quoted:!0}}let d=e.state.env.get(u);return d!==void 0?{values:[d],quoted:!0}:{values:[],quoted:!0}}}return null}async function ru(e,t,n,r,s){if(!n||t.length!==1||t[0].type!=="DoubleQuoted")return null;let i=t[0],o=-1,a="",l=!1,u=null;for(let m=0;m<i.parts.length;m++){let E=i.parts[m];if(E.type==="ParameterExpansion"&&(E.operation?.type==="PatternRemoval"||E.operation?.type==="PatternReplacement")){let S=E.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(S){o=m,a=S[1],l=S[2]==="*",u=E.operation;break}}}if(o===-1||o===0&&o===i.parts.length-1)return null;let c="";for(let m=0;m<o;m++)c+=await r(e,i.parts[m]);let f="";for(let m=o+1;m<i.parts.length;m++)f+=await r(e,i.parts[m]);let d=G(e,a),p=d.map(([,m])=>m);if(d.length===0){let m=e.state.env.get(a);if(m!==void 0)p=[m];else{if(l)return{values:[c+f],quoted:!0};let E=c+f;return{values:E?[E]:[],quoted:!0}}}if(u?.type==="PatternRemoval"){let m=u,E=m.pattern?await Gt(e,m.pattern,m.greedy,s,r):"";p=p.map(S=>mt(e,S,E,m.side,m.greedy))}else if(u?.type==="PatternReplacement"){let m=u,E="";if(m.pattern)for(let g of m.pattern.parts)if(g.type==="Glob")E+=se(g.pattern,!0,e.state.shoptOptions.extglob);else if(g.type==="Literal")E+=se(g.value,!0,e.state.shoptOptions.extglob);else if(g.type==="SingleQuoted"||g.type==="Escaped")E+=ae(g.value);else if(g.type==="DoubleQuoted"){let b=await s(e,g.parts);E+=ae(b)}else if(g.type==="ParameterExpansion"){let b=await r(e,g);E+=se(b,!0,e.state.shoptOptions.extglob)}else{let b=await r(e,g);E+=ae(b)}let S=m.replacement?await s(e,m.replacement.parts):"",y=E;m.anchor==="start"?y=`^${E}`:m.anchor==="end"&&(y=`${E}$`);try{let g=me(y,m.all?"g":"");p=p.map(b=>g.replace(b,S))}catch{}}if(l){let m=Z(e.state.env);return{values:[c+p.join(m)+f],quoted:!0}}return p.length===1?{values:[c+p[0]+f],quoted:!0}:{values:[c+p[0],...p.slice(1,-1),p[p.length-1]+f],quoted:!0}}async function su(e,t,n,r){if(!n||t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0],i=-1,o="",a=!1;for(let p=0;p<s.parts.length;p++){let h=s.parts[p];if(h.type==="ParameterExpansion"&&!h.operation){let m=h.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(m){i=p,o=m[1],a=m[2]==="*";break}}}if(i===-1)return null;let l="";for(let p=0;p<i;p++)l+=await r(e,s.parts[p]);let u="";for(let p=i+1;p<s.parts.length;p++)u+=await r(e,s.parts[p]);let c=G(e,o),f=c.map(([,p])=>p);if(c.length===0){let p=e.state.env.get(o);if(p!==void 0)return{values:[l+p+u],quoted:!0};if(a)return{values:[l+u],quoted:!0};let h=l+u;return{values:h?[h]:[],quoted:!0}}if(a){let p=Z(e.state.env);return{values:[l+f.join(p)+u],quoted:!0}}return f.length===1?{values:[l+f[0]+u],quoted:!0}:{values:[l+f[0],...f.slice(1,-1),f[f.length-1]+u],quoted:!0}}async function iu(e,t,n){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let r=t[0];if(r.parts.length!==1||r.parts[0].type!=="ParameterExpansion"||r.parts[0].operation?.type!=="Substring")return null;let s=r.parts[0],i=s.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!i)return null;let o=i[1],a=i[2]==="*",l=s.operation;if(e.state.associativeArrays?.has(o))throw new q(1,"",`bash: \${${o}[@]: 0: 3}: bad substitution
112
- `);let u=l.offset?await n(e,l.offset.expression):0,c=l.length?await n(e,l.length.expression):void 0,f=G(e,o);if(f.length>e.limits.maxArrayElements)throw new P(`array transform element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");let d=0;if(u<0){if(f.length>0){let h=f[f.length-1][0],E=(typeof h=="number"?h:0)+1+u;if(E<0)return{values:[],quoted:!0};d=f.findIndex(([S])=>typeof S=="number"&&S>=E),d<0&&(d=f.length)}}else d=f.findIndex(([h])=>typeof h=="number"&&h>=u),d<0&&(d=f.length);let p;if(c!==void 0){if(c<0)throw new oe(`${o}[@]: substring expression < 0`);p=f.slice(d,d+c).map(([,h])=>h)}else p=f.slice(d).map(([,h])=>h);if(p.length===0)return{values:[],quoted:!0};if(a){let h=Z(e.state.env);return{values:[p.join(h)],quoted:!0}}return{values:p,quoted:!0}}function ou(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0];if(n.parts.length!==1||n.parts[0].type!=="ParameterExpansion"||n.parts[0].operation?.type!=="Transform")return null;let r=n.parts[0],s=r.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!s)return null;let i=s[1],o=s[2]==="*",a=r.operation,l=G(e,i);if(l.length===0){let d=e.state.env.get(i);if(d!==void 0){let p;switch(a.operator){case"a":p="";break;case"P":p=ur(e,d);break;case"Q":p=Ht(d);break;default:p=d}if(F(p)>e.limits.maxStringLength)throw new P(`array transform string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return{values:[p],quoted:!0}}return o?{values:[""],quoted:!0}:{values:[],quoted:!0}}let u=Zt(e,i),c=[],f=0;for(let[,d]of l){let p;switch(a.operator){case"a":p=u;break;case"P":p=ur(e,d);break;case"Q":p=Ht(d);break;case"u":p=d.charAt(0).toUpperCase()+d.slice(1);break;case"U":p=d.toUpperCase();break;case"L":p=d.toLowerCase();break;default:p=d}let h=F(p);if(h>e.limits.maxStringLength-f)throw new P(`array transform string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");c.push(p),f+=h}if(o){let d=Z(e.state.env);if(Math.max(0,c.length-1)*F(d)>e.limits.maxStringLength-f)throw new P(`array transform string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return{values:[c.join(d)],quoted:!0}}return{values:c,quoted:!0}}function au(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0];if(n.parts.length!==1||n.parts[0].type!=="ParameterExpansion")return null;let r=n.parts[0];if(r.operation)return null;let s=r.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(@)\]$/);if(!s)return null;let i=s[1];if(le(e,i)){let l=En(e,i);if(l?.endsWith("[@]")||l?.endsWith("[*]"))return{values:[],quoted:!0}}let o=G(e,i);if(o.length>0)return{values:o.map(([,l])=>l),quoted:!0};let a=e.state.env.get(i);return a!==void 0?{values:[a],quoted:!0}:{values:[],quoted:!0}}function lu(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0];if(n.parts.length!==1||n.parts[0].type!=="ParameterExpansion"||n.parts[0].operation)return null;let s=n.parts[0].parameter;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(s)||!le(e,s))return null;let i=En(e,s);if(!i)return null;let o=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(@)\]$/);if(!o)return null;let a=o[1],l=G(e,a);if(l.length>0)return{values:l.map(([,c])=>c),quoted:!0};let u=e.state.env.get(a);return u!==void 0?{values:[u],quoted:!0}:{values:[],quoted:!0}}async function uu(e,t,n,r,s){if(!n||t.length!==1||t[0].type!=="DoubleQuoted")return null;let i=t[0];if(i.parts.length!==1||i.parts[0].type!=="ParameterExpansion"||i.parts[0].operation?.type!=="Indirection")return null;let o=i.parts[0],a=o.operation,l=await re(e,o.parameter),u=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!u){if(!a.innerOp&&(l==="@"||l==="*")){let h=Number.parseInt(e.state.env.get("#")||"0",10),m=[];for(let E=1;E<=h;E++)m.push(e.state.env.get(String(E))||"");return l==="*"?{values:[m.join(Z(e.state.env))],quoted:!0}:{values:m,quoted:!0}}return null}let c=u[1],f=u[2]==="*",d=G(e,c);if(a.innerOp){if(a.innerOp.type==="Substring")return yp(e,d,c,f,a.innerOp);if(a.innerOp.type==="DefaultValue"||a.innerOp.type==="UseAlternative"||a.innerOp.type==="AssignDefault"||a.innerOp.type==="ErrorIfUnset")return gp(e,d,c,f,a.innerOp,s);if(a.innerOp.type==="Transform"&&a.innerOp.operator==="a"){let m=Zt(e,c),E=d.map(()=>m);return f?{values:[E.join(Z(e.state.env))],quoted:!0}:{values:E,quoted:!0}}let h=[];for(let[,m]of d){let E={type:"ParameterExpansion",parameter:"_indirect_elem_",operation:a.innerOp},S=e.state.env.get("_indirect_elem_");e.state.env.set("_indirect_elem_",m);try{let y=await r(e,E,!0);h.push(y)}finally{S!==void 0?e.state.env.set("_indirect_elem_",S):e.state.env.delete("_indirect_elem_")}}return f?{values:[h.join(Z(e.state.env))],quoted:!0}:{values:h,quoted:!0}}if(d.length>0){let h=d.map(([,m])=>m);return f?{values:[h.join(Z(e.state.env))],quoted:!0}:{values:h,quoted:!0}}let p=e.state.env.get(c);return p!==void 0?{values:[p],quoted:!0}:{values:[],quoted:!0}}async function yp(e,t,n,r,s){let i=s.offset?await X(e,s.offset.expression):0,o=s.length?await X(e,s.length.expression):void 0,a=0;if(i<0){if(t.length>0){let c=t[t.length-1][0],d=(typeof c=="number"?c:0)+1+i;if(d<0)return{values:[],quoted:!0};if(a=t.findIndex(([p])=>typeof p=="number"&&p>=d),a<0)return{values:[],quoted:!0}}}else if(a=t.findIndex(([c])=>typeof c=="number"&&c>=i),a<0)return{values:[],quoted:!0};let l;if(o!==void 0){if(o<0)throw new oe(`${n}[@]: substring expression < 0`);l=t.slice(a,a+o)}else l=t.slice(a);let u=l.map(([,c])=>c);return r?{values:[u.join(Z(e.state.env))],quoted:!0}:{values:u,quoted:!0}}async function gp(e,t,n,r,s,i){let o=s.checkEmpty??!1,a=t.map(([,c])=>c),l=t.length===0,u=t.length===0;if(s.type==="UseAlternative")return!u&&!(o&&l)&&s.word?{values:[await i(e,s.word.parts,!0)],quoted:!0}:{values:[],quoted:!0};if(s.type==="DefaultValue")return(u||o&&l)&&s.word?{values:[await i(e,s.word.parts,!0)],quoted:!0}:r?{values:[a.join(Z(e.state.env))],quoted:!0}:{values:a,quoted:!0};if(s.type==="AssignDefault"){if((u||o&&l)&&s.word){let f=await i(e,s.word.parts,!0);return U(e,n,0,f),{values:[f],quoted:!0}}return r?{values:[a.join(Z(e.state.env))],quoted:!0}:{values:a,quoted:!0}}return r?{values:[a.join(Z(e.state.env))],quoted:!0}:{values:a,quoted:!0}}async function cu(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="UseAlternative"&&t[0].operation?.type!=="DefaultValue")return null;let n=t[0],r=n.operation,s=r?.word;if(!s||s.parts.length!==1||s.parts[0].type!=="DoubleQuoted")return null;let i=s.parts[0];if(i.parts.length!==1||i.parts[0].type!=="ParameterExpansion"||i.parts[0].operation?.type!=="Indirection")return null;let o=i.parts[0],l=(await re(e,o.parameter)).match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!l)return null;let u=await vt(e,n.parameter),c=await re(e,n.parameter)==="",f=r.checkEmpty??!1,d;if(r.type==="UseAlternative"?d=u&&!(f&&c):d=!u||f&&c,d){let p=l[1],h=l[2]==="*",m=G(e,p);if(m.length>0){let S=m.map(([,y])=>y);return h?{values:[S.join(Z(e.state.env))],quoted:!0}:{values:S,quoted:!0}}let E=e.state.env.get(p);return E!==void 0?{values:[E],quoted:!0}:{values:[],quoted:!0}}return{values:[],quoted:!1}}async function fu(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="Indirection")return null;let n=t[0],s=n.operation.innerOp;if(!s||s.type!=="UseAlternative"&&s.type!=="DefaultValue")return null;let i=s.word;if(!i||i.parts.length!==1||i.parts[0].type!=="DoubleQuoted")return null;let o=i.parts[0];if(o.parts.length!==1||o.parts[0].type!=="ParameterExpansion"||o.parts[0].operation?.type!=="Indirection")return null;let a=o.parts[0],u=(await re(e,a.parameter)).match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!u)return null;let c=await re(e,n.parameter),f=await vt(e,n.parameter),d=c==="",p=s.checkEmpty??!1,h;if(s.type==="UseAlternative"?h=f&&!(p&&d):h=!f||p&&d,h){let m=u[1],E=u[2]==="*",S=G(e,m);if(S.length>0){let g=S.map(([,b])=>b);return E?{values:[g.join(Z(e.state.env))],quoted:!0}:{values:g,quoted:!0}}let y=e.state.env.get(m);return y!==void 0?{values:[y],quoted:!0}:{values:[],quoted:!0}}return{values:[],quoted:!1}}function du(e){let t=Number.parseInt(e.state.env.get("#")||"0",10);if(t>e.limits.maxArrayElements)throw new P(`positional parameter element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");let n=[],r=0;for(let s=1;s<=t;s++){let i=e.state.env.get(String(s))||"",o=F(i);if(o>e.limits.maxStringLength-r)throw new P(`positional parameter string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");n.push(i),r+=o}return n}function Xr(e,t,n){if(F(t)>n-F(e))throw new P(`positional expansion string limit exceeded (${n} bytes)`,"string_length");return e+t}function _i(e,t,n,r){if(e.length>=r.limits.maxArrayElements)throw new P(`positional expansion element limit exceeded (${r.limits.maxArrayElements})`,"array_elements");let s=F(t);if(s>r.limits.maxStringLength-n.value)throw new P(`positional expansion string limit exceeded (${r.limits.maxStringLength} bytes)`,"string_length");e.push(t),n.value+=s}async function pu(e,t,n,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0],i=-1,o=!1;for(let y=0;y<s.parts.length;y++){let g=s.parts[y];if(g.type==="ParameterExpansion"&&(g.parameter==="@"||g.parameter==="*")&&g.operation?.type==="Substring"){i=y,o=g.parameter==="*";break}}if(i===-1)return null;let l=s.parts[i].operation,u=l.offset?await n(e,l.offset.expression):0,c=l.length?await n(e,l.length.expression):void 0,f=Number.parseInt(e.state.env.get("#")||"0",10),d=[];for(let y=1;y<=f;y++)d.push(e.state.env.get(String(y))||"");let p=e.state.env.get("0")||"bash",h;if(u<=0){let y=[p,...d],g=y.length+u;if(g<0)h=[];else{let b=u<0?g:0;if(c!==void 0){let v=c<0?y.length+c:b+c;h=y.slice(b,Math.max(b,v))}else h=y.slice(b)}}else{let y=u-1;if(y>=d.length)h=[];else if(c!==void 0){let g=c<0?d.length+c:y+c;h=d.slice(y,Math.max(y,g))}else h=d.slice(y)}let m="";for(let y=0;y<i;y++)m+=await r(e,s.parts[y]);let E="";for(let y=i+1;y<s.parts.length;y++)E+=await r(e,s.parts[y]);if(h.length===0){let y=m+E;return{values:y?[y]:[],quoted:!0}}if(o){let y=Z(e.state.env);return{values:[m+h.join(y)+E],quoted:!0}}return h.length===1?{values:[m+h[0]+E],quoted:!0}:{values:[m+h[0],...h.slice(1,-1),h[h.length-1]+E],quoted:!0}}async function hu(e,t,n,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0],i=-1,o=!1;for(let y=0;y<s.parts.length;y++){let g=s.parts[y];if(g.type==="ParameterExpansion"&&(g.parameter==="@"||g.parameter==="*")&&g.operation?.type==="PatternReplacement"){i=y,o=g.parameter==="*";break}}if(i===-1)return null;let l=s.parts[i].operation,u=du(e),c="";for(let y=0;y<i;y++)c=Xr(c,await n(e,s.parts[y]),e.limits.maxStringLength);let f="";for(let y=i+1;y<s.parts.length;y++)f=Xr(f,await n(e,s.parts[y]),e.limits.maxStringLength);if(u.length===0){let y=c+f;return{values:y?[y]:[],quoted:!0}}let d="";if(l.pattern)for(let y of l.pattern.parts)if(y.type==="Glob")d+=se(y.pattern,!0,e.state.shoptOptions.extglob);else if(y.type==="Literal")d+=se(y.value,!0,e.state.shoptOptions.extglob);else if(y.type==="SingleQuoted"||y.type==="Escaped")d+=ae(y.value);else if(y.type==="DoubleQuoted"){let g=await r(e,y.parts);d+=ae(g)}else if(y.type==="ParameterExpansion"){let g=await n(e,y);d+=se(g,!0,e.state.shoptOptions.extglob)}else{let g=await n(e,y);d+=ae(g)}let p=l.replacement?await r(e,l.replacement.parts):"",h=d;l.anchor==="start"?h=`^${d}`:l.anchor==="end"&&(h=`${d}$`);let m=[],E={value:0};try{let y=me(h,l.all?"g":"");for(let g of u){let b=0;y.lastIndex=0;for(let $=y.exec(g);$&&(b++,!!l.all);$=y.exec(g))$[0].length===0&&y.lastIndex++;let v=F(g),x=F(p),A=0,k=/\$(?:\$|&|\d+|<[^>]+>|`|')/g;for(;k.exec(p)!==null;)A++;if(v+b*x+b*A*v>e.limits.maxStringLength-E.value)throw new P(`positional expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");_i(m,y.replace(g,p),E,e)}}catch(y){if(y instanceof P)throw y;for(let g of u)_i(m,g,E,e)}if(o){let y=Z(e.state.env);if(E.value+Math.max(0,m.length-1)*F(y)+F(c)+F(f)>e.limits.maxStringLength)throw new P(`positional expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return{values:[c+m.join(y)+f],quoted:!0}}if(F(c)+E.value+F(f)>e.limits.maxStringLength)throw new P(`positional expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return m.length===1?{values:[c+m[0]+f],quoted:!0}:{values:[c+m[0],...m.slice(1,-1),m[m.length-1]+f],quoted:!0}}async function mu(e,t,n,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0],i=-1,o=!1;for(let S=0;S<s.parts.length;S++){let y=s.parts[S];if(y.type==="ParameterExpansion"&&(y.parameter==="@"||y.parameter==="*")&&y.operation?.type==="PatternRemoval"){i=S,o=y.parameter==="*";break}}if(i===-1)return null;let l=s.parts[i].operation,u=du(e),c="";for(let S=0;S<i;S++)c=Xr(c,await n(e,s.parts[S]),e.limits.maxStringLength);let f="";for(let S=i+1;S<s.parts.length;S++)f=Xr(f,await n(e,s.parts[S]),e.limits.maxStringLength);if(u.length===0){let S=c+f;return{values:S?[S]:[],quoted:!0}}let d="",p=e.state.shoptOptions.extglob;if(l.pattern)for(let S of l.pattern.parts)if(S.type==="Glob")d+=se(S.pattern,l.greedy,p);else if(S.type==="Literal")d+=se(S.value,l.greedy,p);else if(S.type==="SingleQuoted"||S.type==="Escaped")d+=ae(S.value);else if(S.type==="DoubleQuoted"){let y=await r(e,S.parts);d+=ae(y)}else if(S.type==="ParameterExpansion"){let y=await n(e,S);d+=se(y,l.greedy,p)}else{let y=await n(e,S);d+=ae(y)}let h=[],m={value:0};for(let S of u)_i(h,mt(e,S,d,l.side,l.greedy),m,e);if(o){let S=Z(e.state.env);if(m.value+Math.max(0,h.length-1)*F(S)+F(c)+F(f)>e.limits.maxStringLength)throw new P(`positional expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return{values:[c+h.join(S)+f],quoted:!0}}if(F(c)+m.value+F(f)>e.limits.maxStringLength)throw new P(`positional expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return h.length===1?{values:[c+h[0]+f],quoted:!0}:{values:[c+h[0],...h.slice(1,-1),h[h.length-1]+f],quoted:!0}}async function yu(e,t,n){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let r=t[0],s=-1,i=!1;for(let d=0;d<r.parts.length;d++){let p=r.parts[d];if(p.type==="ParameterExpansion"&&(p.parameter==="@"||p.parameter==="*")){s=d,i=p.parameter==="*";break}}if(s===-1)return null;let o=r.parts[s];if(o.type==="ParameterExpansion"&&o.operation)return null;let a=Number.parseInt(e.state.env.get("#")||"0",10),l="";for(let d=0;d<s;d++)l+=await n(e,r.parts[d]);let u="";for(let d=s+1;d<r.parts.length;d++)u+=await n(e,r.parts[d]);if(a===0){if(i)return{values:[l+u],quoted:!0};let d=l+u;return{values:d?[d]:[],quoted:!0}}let c=[];for(let d=1;d<=a;d++)c.push(e.state.env.get(String(d))||"");if(i){let d=Z(e.state.env);return{values:[l+c.join(d)+u],quoted:!0}}return c.length===1?{values:[l+c[0]+u],quoted:!0}:{values:[l+c[0],...c.slice(1,-1),c[c.length-1]+u],quoted:!0}}function $t(e,t,n,r){if(t.length>=e.limits.maxArrayElements)throw new P(`unquoted expansion element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");let s=F(n);if(s>e.limits.maxStringLength-r.value)throw new P(`unquoted expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");t.push(n),r.value+=s}function Li(e,t,n,r){let s=F(n),i=Math.max(0,t.length-1);if(s>0&&i>Math.floor((e.limits.maxStringLength-r)/s))throw new P(`unquoted expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return t.join(n)}function wp(e){return new jt(e.fs,e.state.cwd,e.state.env,{globstar:e.state.shoptOptions.globstar,nullglob:e.state.shoptOptions.nullglob,failglob:e.state.shoptOptions.failglob,dotglob:e.state.shoptOptions.dotglob,extglob:e.state.shoptOptions.extglob,globskipdots:e.state.shoptOptions.globskipdots,maxGlobOperations:e.limits.maxGlobOperations,consumeOperation:()=>e.executionScope.consumeLimited("glob_operations",1,e.limits.maxGlobOperations,"glob expansion")})}async function Yr(e,t){if(e.state.options.noglob)return t;let n=wp(e),r=[];for(let s of t)if(xt(s,e.state.shoptOptions.extglob)){let i=await n.expand(s);if(i.length>0)Ne(r,i,e.limits.maxArrayElements,"unquoted glob expansion");else{if(n.hasFailglob())throw new Lt(s);n.hasNullglob()||r.push(s)}}else r.push(s);return r}async function gu(e,t,n,r){let s=-1,i="",o=!1;for(let b=0;b<t.length;b++){let v=t[b];if(v.type==="ParameterExpansion"&&v.operation?.type==="PatternReplacement"){let x=v.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(x){s=b,i=x[1],o=x[2]==="*";break}}}if(s===-1)return null;let l=t[s].operation,u=G(e,i),c=u.map(([,b])=>b);if(u.length===0){let b=e.state.env.get(i);b!==void 0&&(c=[b])}if(c.length===0)return{values:[],quoted:!1};let f="";if(l.pattern)for(let b of l.pattern.parts)if(b.type==="Glob")f+=se(b.pattern,!0,e.state.shoptOptions.extglob);else if(b.type==="Literal")f+=se(b.value,!0,e.state.shoptOptions.extglob);else if(b.type==="SingleQuoted"||b.type==="Escaped")f+=ae(b.value);else if(b.type==="DoubleQuoted"){let v=await n(e,b.parts);f+=ae(v)}else if(b.type==="ParameterExpansion"){let v=await r(e,b);f+=se(v,!0,e.state.shoptOptions.extglob)}else{let v=await r(e,b);f+=ae(v)}let d=l.replacement?await n(e,l.replacement.parts):"",p=f;l.anchor==="start"?p=`^${f}`:l.anchor==="end"&&(p=`${f}$`);let h=[],m={value:0};try{let b=me(p,l.all?"g":"");for(let v of c)$t(e,h,Hr(e,v,b,d,l.all),m)}catch(b){if(b instanceof P)throw b;for(let v of c)$t(e,h,v,m)}let E=Ae(e.state.env),S=Ce(e.state.env);if(o){let b=Z(e.state.env),v=Li(e,h,b,m.value);return S?{values:v?[v]:[],quoted:!1}:{values:ce(v,E,e.limits.maxArrayElements),quoted:!1}}if(S)return{values:h,quoted:!1};let y=[],g={value:0};for(let b of h)if(b==="")$t(e,y,"",g);else for(let v of ce(b,E,e.limits.maxArrayElements))$t(e,y,v,g);return{values:y,quoted:!1}}async function wu(e,t,n,r){let s=-1,i="",o=!1;for(let y=0;y<t.length;y++){let g=t[y];if(g.type==="ParameterExpansion"&&g.operation?.type==="PatternRemoval"){let b=g.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(b){s=y,i=b[1],o=b[2]==="*";break}}}if(s===-1)return null;let l=t[s].operation,u=G(e,i),c=u.map(([,y])=>y);if(u.length===0){let y=e.state.env.get(i);y!==void 0&&(c=[y])}if(c.length===0)return{values:[],quoted:!1};let f=l.pattern?await Gt(e,l.pattern,l.greedy,n,r):"",d=[],p={value:0};for(let y of c)$t(e,d,mt(e,y,f,l.side,l.greedy),p);let h=Ae(e.state.env),m=Ce(e.state.env);if(o){let y=Z(e.state.env),g=Li(e,d,y,p.value);return m?{values:g?[g]:[],quoted:!1}:{values:ce(g,h,e.limits.maxArrayElements),quoted:!1}}if(m)return{values:d,quoted:!1};let E=[],S={value:0};for(let y of d)if(y==="")$t(e,E,"",S);else for(let g of ce(y,h,e.limits.maxArrayElements))$t(e,E,g,S);return{values:E,quoted:!1}}async function Eu(e,t,n,r){let s=-1,i=!1;for(let y=0;y<t.length;y++){let g=t[y];if(g.type==="ParameterExpansion"&&(g.parameter==="@"||g.parameter==="*")&&g.operation?.type==="PatternRemoval"){s=y,i=g.parameter==="*";break}}if(s===-1)return null;let a=t[s].operation,l=Number.parseInt(e.state.env.get("#")||"0",10),u=[];for(let y=1;y<=l;y++)u.push(e.state.env.get(String(y))||"");if(u.length===0)return{values:[],quoted:!1};let c="",f=e.state.shoptOptions.extglob;if(a.pattern)for(let y of a.pattern.parts)if(y.type==="Glob")c+=se(y.pattern,a.greedy,f);else if(y.type==="Literal")c+=se(y.value,a.greedy,f);else if(y.type==="SingleQuoted"||y.type==="Escaped")c+=ae(y.value);else if(y.type==="DoubleQuoted"){let g=await n(e,y.parts);c+=ae(g)}else if(y.type==="ParameterExpansion"){let g=await r(e,y);c+=se(g,a.greedy,f)}else{let g=await r(e,y);c+=ae(g)}let d=[],p={value:0};for(let y of u)$t(e,d,mt(e,y,c,a.side,a.greedy),p);let h=Ae(e.state.env),m=Ce(e.state.env);if(i){let y=Z(e.state.env),g=Li(e,d,y,p.value);return m?{values:g?[g]:[],quoted:!1}:{values:ce(g,h,e.limits.maxArrayElements),quoted:!1}}if(m)return{values:d,quoted:!1};let E=[],S={value:0};for(let y of d)if(y==="")$t(e,E,"",S);else for(let g of ce(y,h,e.limits.maxArrayElements))$t(e,E,g,S);return{values:E,quoted:!1}}async function bu(e,t,n,r){let s=-1,i=!1;for(let g=0;g<t.length;g++){let b=t[g];if(b.type==="ParameterExpansion"&&(b.parameter==="@"||b.parameter==="*")&&b.operation?.type==="Substring"){s=g,i=b.parameter==="*";break}}if(s===-1)return null;let a=t[s].operation,l=a.offset?await n(e,a.offset.expression):0,u=a.length?await n(e,a.length.expression):void 0,c=Number.parseInt(e.state.env.get("#")||"0",10),f=[];for(let g=1;g<=c;g++)f.push(e.state.env.get(String(g))||"");let d=e.state.env.get("0")||"bash",p;if(l<=0){let g=[d,...f],b=g.length+l;if(b<0)p=[];else{let v=l<0?b:0;if(u!==void 0){let x=u<0?g.length+u:v+u;p=g.slice(v,Math.max(v,x))}else p=g.slice(v)}}else{let g=l-1;if(g>=f.length)p=[];else if(u!==void 0){let b=u<0?f.length+u:g+u;p=f.slice(g,Math.max(g,b))}else p=f.slice(g)}let h="";for(let g=0;g<s;g++)h+=await r(e,t[g]);let m="";for(let g=s+1;g<t.length;g++)m+=await r(e,t[g]);let E=Ae(e.state.env),S=Ce(e.state.env);if(p.length===0){let g=h+m;return g?S?{values:[g],quoted:!1}:{values:ce(g,E,e.limits.maxArrayElements),quoted:!1}:{values:[],quoted:!1}}let y;if(i){let g=Z(e.state.env),b=h+p.join(g)+m;S?y=b?[b]:[]:y=ce(b,E,e.limits.maxArrayElements)}else if(S)p.length===1?y=[h+p[0]+m]:y=[h+p[0],...p.slice(1,-1),p[p.length-1]+m];else{y=[];for(let g=0;g<p.length;g++){let b=p[g];if(g===0&&(b=h+b),g===p.length-1&&(b=b+m),b==="")y.push("");else{let v=ce(b,E,e.limits.maxArrayElements);Ne(y,v,e.limits.maxArrayElements,"unquoted expansion")}}}return{values:await Yr(e,y),quoted:!1}}async function Su(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].parameter!=="@"&&t[0].parameter!=="*"||t[0].operation)return null;let n=t[0].parameter==="*",r=Number.parseInt(e.state.env.get("#")||"0",10);if(r===0)return{values:[],quoted:!1};let s=[];for(let u=1;u<=r;u++)s.push(e.state.env.get(String(u))||"");let i=Ae(e.state.env),o=Ce(e.state.env),a=zr(e.state.env),l;if(n)if(o)l=s.filter(u=>u!=="");else{let u=Z(e.state.env),c=s.join(u);l=ce(c,i,e.limits.maxArrayElements)}else if(o)l=s.filter(u=>u!=="");else if(a){l=[];for(let u of s){if(u==="")continue;let c=ce(u,i,e.limits.maxArrayElements);Ne(l,c,e.limits.maxArrayElements,"unquoted expansion")}}else{l=[];for(let u of s)if(u==="")l.push("");else{let c=ce(u,i,e.limits.maxArrayElements);Ne(l,c,e.limits.maxArrayElements,"unquoted expansion")}for(;l.length>0&&l[l.length-1]==="";)l.pop()}return{values:await Yr(e,l),quoted:!1}}async function Au(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation)return null;let n=t[0].parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!n)return null;let r=n[1],s=n[2]==="*",i=G(e,r),o;if(i.length===0){let f=e.state.env.get(r);if(f!==void 0)o=[f];else return{values:[],quoted:!1}}else o=i.map(([,f])=>f);let a=Ae(e.state.env),l=Ce(e.state.env),u=zr(e.state.env),c;if(s)if(l)c=o.filter(f=>f!=="");else{let f=Z(e.state.env),d=o.join(f);c=ce(d,a,e.limits.maxArrayElements)}else if(l)c=o.filter(f=>f!=="");else if(u){c=[];for(let f of o){if(f==="")continue;let d=ce(f,a,e.limits.maxArrayElements);Ne(c,d,e.limits.maxArrayElements,"unquoted expansion")}}else{c=[];for(let f of o)if(f==="")c.push("");else{let d=ce(f,a,e.limits.maxArrayElements);Ne(c,d,e.limits.maxArrayElements,"unquoted expansion")}for(;c.length>0&&c[c.length-1]==="";)c.pop()}return{values:await Yr(e,c),quoted:!1}}function vu(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="VarNamePrefix")return null;let n=t[0].operation,r=Tn(e,n.prefix);if(r.length===0)return{values:[],quoted:!1};let s=Ae(e.state.env),i=Ce(e.state.env),o;if(n.star)if(i)o=r;else{let a=Z(e.state.env),l=r.join(a);o=ce(l,s,e.limits.maxArrayElements)}else if(i)o=r;else{o=[];for(let a of r){let l=ce(a,s,e.limits.maxArrayElements);Ne(o,l,e.limits.maxArrayElements,"unquoted expansion")}}return{values:o,quoted:!1}}function xu(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="ArrayKeys")return null;let n=t[0].operation,s=G(e,n.array).map(([l])=>String(l));if(s.length===0)return{values:[],quoted:!1};let i=Ae(e.state.env),o=Ce(e.state.env),a;if(n.star)if(o)a=s;else{let l=Z(e.state.env),u=s.join(l);a=ce(u,i,e.limits.maxArrayElements)}else if(o)a=s;else{a=[];for(let l of s){let u=ce(l,i,e.limits.maxArrayElements);Ne(a,u,e.limits.maxArrayElements,"unquoted expansion")}}return{values:a,quoted:!1}}async function $u(e,t,n){let r=-1;for(let d=0;d<t.length;d++){let p=t[d];if(p.type==="ParameterExpansion"&&(p.parameter==="@"||p.parameter==="*")&&!p.operation){r=d;break}}if(r===-1||t.length<=1)return null;let s=Number.parseInt(e.state.env.get("#")||"0",10),i=[];for(let d=1;d<=s;d++)i.push(e.state.env.get(String(d))||"");let o="";for(let d=0;d<r;d++)o+=await n(e,t[d]);let a="";for(let d=r+1;d<t.length;d++)a+=await n(e,t[d]);let l=Ae(e.state.env),u=Ce(e.state.env),c=zr(e.state.env);if(s===0){let d=o+a;return{values:d?[d]:[],quoted:!1}}let f;{let d=[];for(let p=0;p<i.length;p++){let h=i[p];p===0&&(h=o+h),p===i.length-1&&(h=h+a),d.push(h)}if(u)f=d.filter(p=>p!=="");else if(c){f=[];for(let p of d){if(p==="")continue;let h=ce(p,l,e.limits.maxArrayElements);Ne(f,h,e.limits.maxArrayElements,"unquoted expansion")}}else{f=[];for(let p of d)if(p==="")f.push("");else{let h=ce(p,l,e.limits.maxArrayElements);Ne(f,h,e.limits.maxArrayElements,"unquoted expansion")}for(;f.length>0&&f[f.length-1]==="";)f.pop()}}return f.length===0?{values:[],quoted:!1}:{values:await Yr(e,f),quoted:!1}}async function Cu(e,t,n){e.coverage?.hit("bash:expansion:word_glob");let r=t.parts,{hasQuoted:s,hasCommandSub:i,hasArrayVar:o,hasArrayAtExpansion:a,hasParamExpansion:l,hasVarNamePrefixExpansion:u,hasIndirection:c}=ar(r),d=n.hasBraceExpansion(r)?await n.expandWordWithBracesAsync(e,t):null;if(d&&d.length>1)return Ep(e,d,s);let p=await bp(e,r,a,u,c,n);if(p!==null)return p;let h=await Ap(e,r,n);if(h!==null)return h;let m=await vp(e,r,n);if(m!==null)return m;let E=await $p(e,r,n.expandPart);if(E!==null)return Pu(e,E);if((i||o||l)&&!Ce(e.state.env)){let y=Ae(e.state.env),g=n.buildIfsCharClassPattern(y),b=await n.smartWordSplit(e,r,y,g,n.expandPart);return Pu(e,b)}let S=await n.expandWordAsync(e,t);return kp(e,t,r,S,s,n.expandWordForGlobbing)}async function Ep(e,t,n){let r=[];for(let s of t)if(!(!n&&s===""))if(!n&&!e.state.options.noglob&&xt(s,e.state.shoptOptions.extglob)){let i=await Jr(e,s);Ne(r,i,e.limits.maxArrayElements,"brace/glob expansion")}else r.push(s);return{values:r,quoted:!1}}async function bp(e,t,n,r,s,i){if(n){let o=au(e,t);if(o!==null)return o}{let o=lu(e,t);if(o!==null)return o}{let o=await nu(e,t);if(o!==null)return o}{let o=await ru(e,t,n,i.expandPart,i.expandWordPartsAsync);if(o!==null)return o}{let o=await su(e,t,n,i.expandPart);if(o!==null)return o}{let o=await iu(e,t,i.evaluateArithmetic);if(o!==null)return o}{let o=ou(e,t);if(o!==null)return o}{let o=await eu(e,t,i.expandWordPartsAsync,i.expandPart);if(o!==null)return o}{let o=await tu(e,t,i.expandWordPartsAsync,i.expandPart);if(o!==null)return o}if(r&&t.length===1&&t[0].type==="DoubleQuoted"){let o=Sp(e,t);if(o!==null)return o}{let o=await uu(e,t,s,i.expandParameterAsync,i.expandWordPartsAsync);if(o!==null)return o}{let o=await cu(e,t);if(o!==null)return o}{let o=await fu(e,t);if(o!==null)return o}return null}function Sp(e,t){let n=t[0];if(n.type!=="DoubleQuoted")return null;if(n.parts.length===1&&n.parts[0].type==="ParameterExpansion"&&n.parts[0].operation?.type==="VarNamePrefix"){let r=n.parts[0].operation,s=Tn(e,r.prefix);return r.star?{values:[s.join(Z(e.state.env))],quoted:!0}:{values:s,quoted:!0}}if(n.parts.length===1&&n.parts[0].type==="ParameterExpansion"&&n.parts[0].operation?.type==="ArrayKeys"){let r=n.parts[0].operation,i=G(e,r.array).map(([o])=>String(o));return r.star?{values:[i.join(Z(e.state.env))],quoted:!0}:{values:i,quoted:!0}}return null}async function Ap(e,t,n){{let r=await pu(e,t,n.evaluateArithmetic,n.expandPart);if(r!==null)return r}{let r=await hu(e,t,n.expandPart,n.expandWordPartsAsync);if(r!==null)return r}{let r=await mu(e,t,n.expandPart,n.expandWordPartsAsync);if(r!==null)return r}{let r=await yu(e,t,n.expandPart);if(r!==null)return r}return null}async function vp(e,t,n){{let r=await gu(e,t,n.expandWordPartsAsync,n.expandPart);if(r!==null)return r}{let r=await wu(e,t,n.expandWordPartsAsync,n.expandPart);if(r!==null)return r}{let r=await Eu(e,t,n.expandWordPartsAsync,n.expandPart);if(r!==null)return r}{let r=await bu(e,t,n.evaluateArithmetic,n.expandPart);if(r!==null)return r}{let r=await Su(e,t);if(r!==null)return r}{let r=await Au(e,t);if(r!==null)return r}{let r=vu(e,t);if(r!==null)return r}{let r=xu(e,t);if(r!==null)return r}{let r=await $u(e,t,n.expandPart);if(r!==null)return r}return null}function ku(e){if(e.type!=="DoubleQuoted")return null;for(let t=0;t<e.parts.length;t++){let n=e.parts[t];if(n.type!=="ParameterExpansion"||n.operation)continue;let r=n.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(r)return{type:"array",name:r[1],atIndex:t,isStar:r[2]==="*"};if(n.parameter==="@"||n.parameter==="*")return{type:"positional",atIndex:t,isStar:n.parameter==="*"}}return null}async function xp(e,t,n,r){let s="";for(let a=0;a<n.atIndex;a++)s+=await r(e,t.parts[a]);let i="";for(let a=n.atIndex+1;a<t.parts.length;a++)i+=await r(e,t.parts[a]);let o;if(n.type==="array"){if(o=G(e,n.name).map(([,l])=>l),o.length===0){let l=e.state.env.get(n.name);l!==void 0&&(o=[l])}}else{let a=Number.parseInt(e.state.env.get("#")||"0",10);o=[];for(let l=1;l<=a;l++)o.push(e.state.env.get(String(l))||"")}if(n.isStar){let a=Z(e.state.env),l=o.join(a);return[s+l+i]}if(o.length===0){let a=s+i;return a?[a]:[]}return o.length===1?[s+o[0]+i]:[s+o[0],...o.slice(1,-1),o[o.length-1]+i]}async function $p(e,t,n){if(t.length<2)return null;let r=!1;for(let l of t)if(ku(l)){r=!0;break}if(!r)return null;let s=Ae(e.state.env),i=Ce(e.state.env),o=[];for(let l of t){let u=ku(l);if(u&&l.type==="DoubleQuoted"){let c=await xp(e,l,u,n);o.push(c)}else if(l.type==="DoubleQuoted"||l.type==="SingleQuoted"){let c=await n(e,l);o.push([c])}else if(l.type==="Literal")o.push([l.value]);else if(l.type==="ParameterExpansion"){let c=await n(e,l);if(i)o.push(c?[c]:[]);else{let f=ce(c,s,e.limits.maxArrayElements);o.push(f)}}else{let c=await n(e,l);if(i)o.push(c?[c]:[]);else{let f=ce(c,s,e.limits.maxArrayElements);o.push(f)}}}let a=[];for(let l of o)if(l.length!==0)if(a.length===0)Ne(a,l,e.limits.maxArrayElements,"word expansion");else{let u=a.length-1;a[u]=a[u]+l[0];for(let c=1;c<l.length;c++)a.push(l[c])}return a}async function Pu(e,t){if(e.state.options.noglob)return{values:t,quoted:!1};let n=[];for(let r of t)if(xt(r,e.state.shoptOptions.extglob)){let s=await Jr(e,r);Ne(n,s,e.limits.maxArrayElements,"glob expansion")}else n.push(r);return{values:n,quoted:!1}}async function Jr(e,t){let n=new jt(e.fs,e.state.cwd,e.state.env,{globstar:e.state.shoptOptions.globstar,nullglob:e.state.shoptOptions.nullglob,failglob:e.state.shoptOptions.failglob,dotglob:e.state.shoptOptions.dotglob,extglob:e.state.shoptOptions.extglob,globskipdots:e.state.shoptOptions.globskipdots,maxGlobOperations:e.limits.maxGlobOperations,consumeOperation:()=>e.executionScope.consumeLimited("glob_operations",1,e.limits.maxGlobOperations,"glob expansion")}),r=await n.expand(t);if(r.length>0)return r;if(n.hasFailglob())throw new Lt(t);return n.hasNullglob()?[]:[t]}async function kp(e,t,n,r,s,i){let o=n.some(a=>a.type==="Glob");if(!e.state.options.noglob&&o){let a=await i(e,t);if(xt(a,e.state.shoptOptions.extglob)){let u=await Jr(e,a);if(u.length>0&&u[0]!==a)return{values:u,quoted:!1};if(u.length===0)return{values:[],quoted:!1}}let l=Ni(r);if(!Ce(e.state.env)){let u=Ae(e.state.env);return{values:ce(l,u,e.limits.maxArrayElements),quoted:!1}}return{values:[l],quoted:!1}}if(!s&&!e.state.options.noglob&&xt(r,e.state.shoptOptions.extglob)){let a=await i(e,t);if(xt(a,e.state.shoptOptions.extglob)){let l=await Jr(e,a);if(l.length>0&&l[0]!==a)return{values:l,quoted:!1}}}if(r===""&&!s)return{values:[],quoted:!1};if(o&&!s){let a=Ni(r);if(!Ce(e.state.env)){let l=Ae(e.state.env);return{values:ce(a,l,e.limits.maxArrayElements),quoted:!1}}return{values:[a],quoted:!1}}return{values:[r],quoted:s}}function Oe(e,t,n){if(t.length>=e.limits.maxArrayElements)throw new P(`word splitting element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");t.push(n)}async function Ru(e,t){let n=t.operation;if(!n||n.type!=="DefaultValue"&&n.type!=="AssignDefault"&&n.type!=="UseAlternative")return null;let r=n.word;if(!r||r.parts.length===0)return null;let s=await vt(e,t.parameter),o=await re(e,t.parameter,!1)==="",a=n.checkEmpty??!1,l;return n.type==="UseAlternative"?l=s&&!(a&&o):l=!s||a&&o,l?(n.type==="AssignDefault"&&Ri(t.parameter),r.parts):null}function Pp(e){return e.type==="SingleQuoted"?!0:e.type==="DoubleQuoted"?e.parts.every(n=>n.type==="Literal"):!1}async function Cp(e,t){if(t.type!=="ParameterExpansion")return null;let n=await Ru(e,t);if(!n||n.length<=1)return null;let r=n.some(i=>Pp(i)),s=n.some(i=>i.type==="Literal"||i.type==="ParameterExpansion"||i.type==="CommandSubstitution"||i.type==="ArithmeticExpansion");return r&&s?n:null}function Np(e){return e.type==="DoubleQuoted"||e.type==="SingleQuoted"||e.type==="Literal"?!1:e.type==="Glob"?Si(e.pattern):!(!(e.type==="ParameterExpansion"||e.type==="CommandSubstitution"||e.type==="ArithmeticExpansion")||e.type==="ParameterExpansion"&&Cl(e))}async function Du(e,t,n,r,s){if(e.coverage?.hit("bash:expansion:word_split"),t.length===1&&t[0].type==="ParameterExpansion"){let d=t[0],p=await Ru(e,d);if(p&&p.length>0&&p.length>1&&p.some(m=>m.type==="DoubleQuoted"||m.type==="SingleQuoted")&&p.some(m=>m.type==="Literal"||m.type==="ParameterExpansion"||m.type==="CommandSubstitution"||m.type==="ArithmeticExpansion"))return Nu(e,p,n,r,s)}let i=[],o=!1;for(let d of t){let p=Np(d),h=d.type==="DoubleQuoted"||d.type==="SingleQuoted",m=p?await Cp(e,d):null,E=await s(e,d);i.push({value:E,isSplittable:p,isQuoted:h,mixedDefaultParts:m??void 0}),p&&(o=!0)}if(!o){let d=i.map(p=>p.value).join("");return d?[d]:[]}let a=[],l="",u=!1,c=!1,f=!1;for(let d of i)if(!d.isSplittable)c?d.isQuoted&&d.value===""?(l!==""&&Oe(e,a,l),Oe(e,a,""),u=!0,l="",c=!1,f=!0):d.value!==""?(l!==""&&Oe(e,a,l),l=d.value,c=!1,f=!1):(l+=d.value,f=!1):(l+=d.value,f=d.isQuoted&&d.value==="");else if(d.mixedDefaultParts){let p=await Nu(e,d.mixedDefaultParts,n,r,s);if(p.length!==0)if(p.length===1)l+=p[0],u=!0;else{l+=p[0],Oe(e,a,l),u=!0;for(let h=1;h<p.length-1;h++)Oe(e,a,p[h]);l=p[p.length-1]}c=!1,f=!1}else{let{words:p,hadLeadingDelimiter:h,hadTrailingDelimiter:m}=qr(d.value,n,e.limits.maxArrayElements);if(f&&h&&l===""&&(Oe(e,a,""),u=!0),p.length===0)m&&(c=!0);else if(p.length===1)l+=p[0],u=!0,c=m;else{l+=p[0],Oe(e,a,l),u=!0;for(let E=1;E<p.length-1;E++)Oe(e,a,p[E]);l=p[p.length-1],c=m}f=!1}return l!==""?Oe(e,a,l):a.length===0&&u&&Oe(e,a,""),a}function Rp(e,t){return e.length>0&&t.includes(e[0])}async function Nu(e,t,n,r,s){let i=[];for(let c of t){let d=!(c.type==="DoubleQuoted"||c.type==="SingleQuoted"),p=await s(e,c);i.push({value:p,isSplittable:d})}let o=[],a="",l=!1,u=!1;for(let c of i)if(!c.isSplittable)u&&c.value!==""?(a!==""&&Oe(e,o,a),a=c.value,u=!1):a+=c.value;else{Rp(c.value,n)&&a!==""&&(Oe(e,o,a),a="",l=!0);let{words:d,hadTrailingDelimiter:p}=qr(c.value,n,e.limits.maxArrayElements);if(d.length===0)p&&(u=!0);else if(d.length===1)a+=d[0],l=!0,u=p;else{a+=d[0],Oe(e,o,a),l=!0;for(let h=1;h<d.length-1;h++)Oe(e,o,d[h]);a=d[d.length-1],u=p}}return a!==""?Oe(e,o,a):o.length===0&&l&&Oe(e,o,""),o}function Iu(e){switch(e.type){case"Literal":return e.value;case"SingleQuoted":return e.value;case"Escaped":return e.value;default:return null}}function Ou(e){switch(e.type){case"SingleQuoted":case"Escaped":case"DoubleQuoted":return!0;case"Literal":return e.value==="";default:return!1}}var es="/dev/fd",Lu=63,Dp=10,_u=Lu-Dp+1,Ti=class extends bt{isLiveDescriptor;constructor(t){super(),this.isLiveDescriptor=t}assertLiveDescriptor(t,n){this.isLiveDescriptor(t)||this.refuse(t,n)}refuse(t,n){throw new Error(`EROFS: read-only file system, ${n} '${es}${t}'`)}async writeFile(t,n,r){return this.assertLiveDescriptor(t,"write"),super.writeFile(t,n,r)}async appendFile(t,n,r){return this.assertLiveDescriptor(t,"append"),super.appendFile(t,n,r)}async rm(t,n){return this.assertLiveDescriptor(t,"rm"),super.rm(t,n)}async mkdir(t,n){this.refuse(t,"mkdir")}async cp(t,n){this.refuse(n,"cp")}async mv(t,n){this.refuse(n,"mv")}async symlink(t,n){this.refuse(n,"symlink")}async link(t,n){this.refuse(n,"link")}async chmod(t,n){this.refuse(t,"chmod")}async utimes(t,n,r){this.refuse(t,"utimes")}};function Ip(e){let t=new Ti(n=>Tu(e).some(r=>r.path===`${es}${n}`));e.fs=new fn({base:e.fs,mounts:[{mountPoint:es,filesystem:t}]}),e.state.processSubstitutionFsMounted=!0}async function Op(e,t,n){try{await e.fs.writeFile(t,n,"binary");return}catch(r){if(e.state.processSubstitutionFsMounted)throw r;Ip(e)}await e.fs.writeFile(t,n,"binary")}async function _p(e,t){try{await e.fs.rm(t,{force:!0})}catch{}}function Tu(e){let t=e.state.processSubstitutions;if(t)return t;let n=[];return e.state.processSubstitutions=n,n}async function Fu(e,t,n){let r=e.substitutionDepth??0,s=e.limits.maxSubstitutionDepth;if(r>=s)throw new P(`Process substitution nesting limit exceeded (${s})`,"substitution_depth");let i=e.substitutionDepth,o=new Map(e.state.env),a=rt(e.state.arrays),l=e.state.cwd,u=e.state.bashPid,c=e.state.suppressVerbose,f=e.state.groupStdin,d=e.state.lastExitCode,p=e.state.env.get("?"),h=e.state.lastSubstitutionExitCode;e.substitutionDepth=r+1,e.state.bashPid=e.state.nextVirtualPid++,e.state.suppressVerbose=!0,n!==void 0&&(e.state.groupStdin=n);let m;try{m=await e.executeScript(t)}catch(E){if(E instanceof P)throw E;if(E instanceof q)return{stdout:E.stdout,stderr:E.stderr,exitCode:E.exitCode};throw E}finally{e.substitutionDepth=i,e.state.env=o,e.state.arrays=a,e.state.cwd=l,e.state.bashPid=u,e.state.suppressVerbose=c,e.state.groupStdin=f,e.state.lastExitCode=d,e.state.lastSubstitutionExitCode=h,p!==void 0?e.state.env.set("?",p):e.state.env.delete("?")}return m}async function Mu(e,t){let n=Tu(e);if(n.length>=_u)throw new P(`Process substitution limit exceeded (${_u} concurrent)`,"file_descriptors");let r="";if(t.direction==="input"){let o=await Fu(e,t.body,void 0);if(o.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+o.stderr),r=_t(o),r.length>e.limits.maxStringLength)throw new P(`process substitution: string length limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length")}let s=Lu-n.length,i=`${es}/${s}`;n.push({fd:s,path:i,direction:t.direction,body:t.body});try{await Op(e,i,r)}catch(o){throw n.pop(),o}return i}function Bu(e){return e.state.processSubstitutions?.length??0}var Lp={stdout:"",stderr:""};async function Fi(e,t){let n=e.state.processSubstitutions;if(!n||n.length<=t)return Lp;let r="",s="";for(;n.length>t;){let i=n[n.length-1],o="";if(i.direction==="output")try{o=await vn(e.fs,i.path)}catch{}if(await _p(e,i.path),n.pop(),i.direction==="output"){let a=await Fu(e,i.body,o);r+=_t(a),s+=a.stderr}}return{stdout:r,stderr:s}}function Xt(e,t,n){if(e.length>t)throw new P(`${n}: string length limit exceeded (${t} bytes)`,"string_length")}async function gt(e,t,n=!1){let r=[],s=0;for(let i of t){let o=await Ye(e,i,n);if(s+=F(o),s>e.limits.maxStringLength)throw new P(`parameter word string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");r.push(o)}return r.join("")}function Tp(e){return Ou(e)}function Vu(e){if(e.parts.length===0)return!0;for(let t of e.parts)if(!Tp(t))return!1;return!0}function Fp(e,t,n=!1){let r=Iu(t);if(r!==null)return r;switch(t.type){case"TildeExpansion":return n?t.user===null?"~":`~${t.user}`:(e.coverage?.hit("bash:expansion:tilde"),t.user===null?e.state.env.get("HOME")??"/home/user":t.user==="root"?"/root":`~${t.user}`);case"Glob":return Ii(e,t.pattern);default:return null}}async function ne(e,t){return Bi(e,t)}async function zu(e,t){let n=[];for(let r of t.parts)if(r.type==="Escaped")n.push(Ln(r.value));else if(r.type==="SingleQuoted")n.push(r.value);else if(r.type==="DoubleQuoted"){let s=await gt(e,r.parts);n.push(s)}else if(r.type==="TildeExpansion"){let s=await Ye(e,r);n.push(Ln(s))}else n.push(await Ye(e,r));return n.join("")}async function qu(e,t){let n=[];for(let r of t.parts)if(r.type==="Escaped"){let s=r.value;"()|*?[]".includes(s)?n.push(`\\${s}`):n.push(s)}else if(r.type==="SingleQuoted")n.push(Xe(r.value));else if(r.type==="DoubleQuoted"){let s=await gt(e,r.parts);n.push(Xe(s))}else n.push(await Ye(e,r));return n.join("")}async function Uu(e,t){let n=[];for(let r of t.parts)if(r.type==="SingleQuoted")n.push(Xe(r.value));else if(r.type==="Escaped"){let s=r.value;"*?[]\\()|".includes(s)?n.push(`\\${s}`):n.push(s)}else if(r.type==="DoubleQuoted"){let s=await gt(e,r.parts);n.push(Xe(s))}else r.type==="Glob"?Xl(r.pattern)?n.push(await Jl(e,r.pattern)):n.push(Ii(e,r.pattern)):r.type==="Literal"?n.push(r.value):n.push(await Ye(e,r));return n.join("")}function ns(e){for(let t of e)if(t.type==="BraceExpansion"||t.type==="DoubleQuoted"&&ns(t.parts))return!0;return!1}var Wu=1e5;async function ju(e,t,n={count:0}){let r=()=>{n.count++,e.executionScope.consumeLimited("brace_operations",1,Math.min(Wu,e.limits.maxBraceExpansionResults),"brace expansion")},s=(o,a)=>{if(o.length>=e.limits.maxBraceExpansionResults)throw new P(`brace expansion result limit exceeded (${e.limits.maxBraceExpansionResults})`,"array_elements");r(),o.push(a)},i=[[]];for(let o of t)if(o.type==="BraceExpansion"){let a=[],l=!1,u="";for(let d of o.items)if(d.type==="Range"){let p=Ci(d.start,d.end,d.step,d.startStr,d.endStr,{maxResults:e.limits.maxBraceExpansionResults,maxStringBytes:e.limits.maxStringLength});if(p.expanded)for(let h of p.expanded)s(a,h);else{l=!0,u=p.literal;break}}else{let p=await ju(e,d.word.parts,n);for(let h of p){let m=[];for(let E of h)typeof E=="string"?m.push(E):m.push(await Ye(e,E));s(a,m.join(""))}}if(l){for(let d of i)r(),d.push(u);continue}if(i.length*a.length>e.limits.maxBraceExpansionResults||n.count>Wu)throw new P(`brace expansion result limit exceeded (${e.limits.maxBraceExpansionResults})`,"array_elements");let f=[];for(let d of i)for(let p of a){if(f.length>=e.limits.maxBraceExpansionResults)throw new P(`brace expansion result limit exceeded (${e.limits.maxBraceExpansionResults})`,"array_elements");r(),f.push([...d,p])}i=f}else for(let a of i)r(),a.push(o);return i}async function Gu(e,t){let n=t.parts;if(!ns(n))return[await ne(e,t)];let r=await ju(e,n),s=[];for(let i of r){let o=[];for(let a of i)typeof a=="string"?o.push(a):o.push(await Ye(e,a));s.push(Oi(e,o.join("")))}return s}function Mp(){return{expandWordAsync:Bi,expandWordForGlobbing:Uu,expandWordWithBracesAsync:Gu,expandWordPartsAsync:gt,expandPart:Ye,expandParameterAsync:ts,hasBraceExpansion:ns,evaluateArithmetic:X,buildIfsCharClassPattern:Nl,smartWordSplit:Du}}async function wt(e,t){return Cu(e,t,Mp())}function Bp(e){for(let t of e){if(t.type==="ParameterExpansion")return t.parameter;if(t.type==="Literal")return t.value}return""}function Mi(e,t){if(Number.parseInt(e.state.env.get("#")||"0",10)<2)return!1;function r(s){for(let i of s)if(i.type==="DoubleQuoted"){for(let o of i.parts)if(o.type==="ParameterExpansion"&&o.parameter==="@"&&!o.operation)return!0}return!1}return r(t.parts)}async function Hu(e,t){if(Mi(e,t))return{error:`bash: $@: ambiguous redirect
113
- `};let n=t.parts,{hasQuoted:r}=ar(n);if(ns(n)&&(await Gu(e,t)).length>1)return{error:`bash: ${n.map(p=>p.type==="Literal"?p.value:p.type==="BraceExpansion"?`{${p.items.map(m=>{if(m.type==="Range"){let E=m.step?`..${m.step}`:"";return`${m.startStr??m.start}..${m.endStr??m.end}${E}`}return m.word.parts.map(E=>E.type==="Literal"?E.value:"").join("")}).join(",")}}`:"").join("")}: ambiguous redirect
114
- `};let s=await Bi(e,t),{hasParamExpansion:i,hasCommandSub:o}=ar(n);if((i||o)&&!r&&!Ce(e.state.env)){let f=Ae(e.state.env);if(ce(s,f,e.limits.maxArrayElements).length>1)return{error:`bash: $${Bp(n)}: ambiguous redirect
115
- `}}if(r||e.state.options.noglob||n.some(f=>f.type==="ProcessSubstitution"))return{target:s};let l=await Uu(e,t);if(!xt(l,e.state.shoptOptions.extglob))return{target:s};let u=new jt(e.fs,e.state.cwd,e.state.env,{globstar:e.state.shoptOptions.globstar,nullglob:e.state.shoptOptions.nullglob,failglob:e.state.shoptOptions.failglob,dotglob:e.state.shoptOptions.dotglob,extglob:e.state.shoptOptions.extglob,globskipdots:e.state.shoptOptions.globskipdots,maxGlobOperations:e.limits.maxGlobOperations,consumeOperation:()=>e.executionScope.consumeLimited("glob_operations",1,e.limits.maxGlobOperations,"glob expansion")}),c=await u.expand(l);return c.length===0?u.hasFailglob()?{error:`bash: no match: ${s}
106
+ `;throw new U(1,"",r)}return null}function mt(e,t){let n=e.state.exportedVars?.has(t)??!1;if(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(t),e.state.localScopes.length>0&&e.state.localScopes[e.state.localScopes.length-1].has(t)&&!n){for(e.state.localExportedVars||(e.state.localExportedVars=[]);e.state.localExportedVars.length<e.state.localScopes.length;)e.state.localExportedVars.push(new Set);e.state.localExportedVars[e.state.localExportedVars.length-1].add(t)}}function Yr(e,t){e.state.exportedVars?.delete(t)}function Zt(e,t){if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t))return"";let n="",r=Ae(e,t)?.kind==="indexed",s=e.state.associativeArrays?.has(t)??!1;return r&&!s&&(n+="a"),s&&(n+="A"),e.state.integerVars?.has(t)&&(n+="i"),le(e,t)&&(n+="n"),Fe(e,t)&&(n+="r"),e.state.exportedVars?.has(t)&&(n+="x"),n}async function zl(e,t,n,r){return e.coverage?.hit("bash:expansion:default_value"),(n.isUnset||t.checkEmpty&&n.isEmpty)&&t.word?r(e,t.word.parts,n.inDoubleQuotes):n.effectiveValue}function Ii(e){if(/^(?:\d+|[@*#?$!-])$/.test(e))throw new U(1,"",`bash: $${e}: cannot assign in this way
107
+ `)}async function ql(e,t,n,r,s){e.coverage?.hit("bash:expansion:assign_default");let i=r.isUnset||n.checkEmpty&&r.isEmpty;if(i&&Ii(t),i&&n.word){let o=await s(e,n.word.parts,r.inDoubleQuotes),a=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(a){let[,l,u]=a;if(u==="@"||u==="*")throw new U(1,"",`${e.state.expansionStderr||""}bash: ${t}: bad array subscript
108
+ `);let c;if(/^\d+$/.test(u))c=Number.parseInt(u,10);else{try{let f=new G,d=te(f,u);c=await X(e,d.expression)}catch{let f=e.state.env.get(u);c=f?Number.parseInt(f,10):0}Number.isNaN(c)&&(c=0)}j(e,l,c,o)}else e.state.env.set(t,o);return o}return r.effectiveValue}async function Ul(e,t,n,r,s){if(e.coverage?.hit("bash:expansion:error_if_unset"),r.isUnset||n.checkEmpty&&r.isEmpty){let o=n.word?await s(e,n.word.parts,r.inDoubleQuotes):`${t}: parameter null or not set`;throw new U(1,"",`bash: ${o}
109
+ `)}return r.effectiveValue}async function jl(e,t,n,r){return e.coverage?.hit("bash:expansion:use_alternative"),!(n.isUnset||t.checkEmpty&&n.isEmpty)&&t.word?r(e,t.word.parts,n.inDoubleQuotes):""}async function Gl(e,t,n,r,s){e.coverage?.hit("bash:expansion:pattern_removal");let i=n.pattern?await Gt(e,n.pattern,n.greedy,r,s):"";return ht(e,t,i,n.side,n.greedy)}async function Hl(e,t,n,r,s){e.coverage?.hit("bash:expansion:pattern_replacement");let i="",o=e.state.shoptOptions.extglob;if(n.pattern)for(let u of n.pattern.parts)if(u.type==="Glob")i+=se(u.pattern,!0,o);else if(u.type==="Literal")i+=se(u.value,!0,o);else if(u.type==="SingleQuoted"||u.type==="Escaped")i+=ae(u.value);else if(u.type==="DoubleQuoted"){let c=await r(e,u.parts);i+=ae(c)}else if(u.type==="ParameterExpansion"){let c=await s(e,u);i+=se(c,!0,o)}else{let c=await s(e,u);i+=ae(c)}let a=n.replacement?await r(e,n.replacement.parts):"";if(n.anchor==="start"?i=`^${i}`:n.anchor==="end"&&(i=`${i}$`),i==="")return t;let l=n.all?"gs":"s";try{let u=me(i,l);return Xr(e,t,u,a,n.all)}catch(u){if(u instanceof C)throw u;return t}}function Oi(e,t,n){e.coverage?.hit("bash:expansion:length");let r=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(r){let s=r[1],i=H(e,s);return i.length>0?String(i.length):e.state.env.get(s)!==void 0?"1":"0"}if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t)&&pt(e,t)){if(t==="FUNCNAME"){let i=e.state.funcNameStack?.[0]||"";return String([...i].length)}if(t==="BASH_LINENO"){let i=e.state.callLineStack?.[0];return String(i!==void 0?[...String(i)].length:0)}let s=ie(e,t,0)||"";return String([...s].length)}return String([...n].length)}async function Zl(e,t,n,r){e.coverage?.hit("bash:expansion:substring");let s=await X(e,r.offset.expression),i=r.length?await X(e,r.length.expression):void 0;if(t==="@"||t==="*"){let u=Number.parseInt(e.state.env.get("#")||"0",10),c=[];for(let h=1;h<=u;h++)c.push(e.state.env.get(String(h))||"");let f=e.state.env.get("0")||"bash",d,p;if(s<=0)if(d=[f,...c],s<0){if(p=d.length+s,p<0)return""}else p=0;else d=c,p=s-1;if(p<0||p>=d.length)return"";if(i!==void 0){let h=i<0?d.length+i:p+i;return d.slice(p,Math.max(p,h)).join(" ")}return d.slice(p).join(" ")}let o=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(o){let u=o[1];if(e.state.associativeArrays?.has(u))throw new U(1,"",`bash: \${${u}[@]: 0: 3}: bad substitution
110
+ `);let c=H(e,u),f=0;if(s<0){if(c.length>0){let d=c[c.length-1][0],h=(typeof d=="number"?d:0)+1+s;if(h<0||(f=c.findIndex(([m])=>typeof m=="number"&&m>=h),f<0))return""}}else if(f=c.findIndex(([d])=>typeof d=="number"&&d>=s),f<0)return"";if(i!==void 0){if(i<0)throw new oe(`${o[1]}[@]: substring expression < 0`);return c.slice(f,f+i).map(([,d])=>d).join(" ")}return c.slice(f).map(([,d])=>d).join(" ")}let a=[...n],l=s;if(l<0&&(l=Math.max(0,a.length+l)),i!==void 0){if(i<0){let u=a.length+i;return a.slice(l,Math.max(l,u)).join("")}return a.slice(l,l+i).join("")}return a.slice(l).join("")}async function Ql(e,t,n,r,s){if(e.coverage?.hit("bash:expansion:case_modification"),n.pattern){let i=e.state.shoptOptions.extglob,o="";for(let f of n.pattern.parts)if(f.type==="Glob")o+=se(f.pattern,!0,i);else if(f.type==="Literal")o+=se(f.value,!0,i);else if(f.type==="SingleQuoted"||f.type==="Escaped")o+=ae(f.value);else if(f.type==="DoubleQuoted"){let d=await r(e,f.parts);o+=ae(d)}else if(f.type==="ParameterExpansion"){let d=await s(e,f);o+=se(d,!0,i)}let a=me(`^(?:${o})$`),l=n.direction==="upper"?f=>f.toUpperCase():f=>f.toLowerCase(),u="",c=!1;for(let f of t)!n.all&&c?u+=f:a.test(f)?(u+=l(f),c=!0):u+=f;return u}return n.direction==="upper"?n.all?t.toUpperCase():t.charAt(0).toUpperCase()+t.slice(1):n.all?t.toLowerCase():t.charAt(0).toLowerCase()+t.slice(1)}function Kl(e,t,n,r,s){e.coverage?.hit("bash:expansion:transform");let i=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(i&&s.operator==="Q")return H(e,i[1]).map(([,u])=>Ht(u)).join(" ");if(i&&s.operator==="a")return Zt(e,i[1]);let o=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[.+\]$/);if(o&&s.operator==="a")return Zt(e,o[1]);switch(s.operator){case"Q":return r?"":Ht(n);case"P":return cr(e,n);case"a":return Zt(e,t);case"A":return r?"":`${t}=${Ht(n)}`;case"E":return n.replace(/\\([\\abefnrtv'"?])/g,(a,l)=>{switch(l){case"\\":return"\\";case"a":return"\x07";case"b":return"\b";case"e":return"\x1B";case"f":return"\f";case"n":return`
111
+ `;case"r":return"\r";case"t":return" ";case"v":return"\v";case"'":return"'";case'"':return'"';case"?":return"?";default:return l}});case"K":case"k":return r?"":Ht(n);case"u":return n.charAt(0).toUpperCase()+n.slice(1);case"U":return n.toUpperCase();case"L":return n.toLowerCase();default:return n}}async function Xl(e,t,n,r,s,i,o=!1){if(e.coverage?.hit("bash:expansion:indirection"),le(e,t))return En(e,t)||"";let a=/^[a-zA-Z_][a-zA-Z0-9_]*\[([@*])\]$/.test(t);if(r){if(s.innerOp?.type==="UseAlternative")return"";throw new Ze(`\${!${t}}`)}let l=n;if(a&&(l===""||l.includes(" ")))throw new Ze(`\${!${t}}`);let u=l.match(/^[a-zA-Z_][a-zA-Z0-9_]*\[(.+)\]$/);if(u&&u[1].includes("~"))throw new Ze(`\${!${t}}`);if(s.innerOp){let c={type:"ParameterExpansion",parameter:l,operation:s.innerOp};return i(e,c,o)}return await re(e,l)}function Yl(e,t){e.coverage?.hit("bash:expansion:array_keys");let r=H(e,t.array).map(([s])=>String(s));return t.star?r.join(Z(e.state.env)):r.join(" ")}function Jl(e,t){e.coverage?.hit("bash:expansion:var_name_prefix");let n=Fn(e,t.prefix);return t.star?n.join(Z(e.state.env)):n.join(" ")}function eu(e,t,n,r){let s=Number.parseInt(e.state.env.get("#")||"0",10),i=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(t==="*")return{isEmpty:s===0,effectiveValue:n};if(t==="@")return{isEmpty:s===0||s===1&&e.state.env.get("1")==="",effectiveValue:n};if(i){let[,o,a]=i,l=H(e,o);return l.length===0?{isEmpty:!0,effectiveValue:""}:a==="*"?{isEmpty:r?n==="":!1,effectiveValue:n}:{isEmpty:l.length===1&&l.every(([,u])=>u===""),effectiveValue:n}}return{isEmpty:n==="",effectiveValue:n}}function Qt(e,t){e.lastExitCode=t,e.env.set("?",String(t)),e.lastSubstitutionExitCode=t}function wp(e){switch(e.operator){case"<":case"<&":case"<<":case"<<-":case"<<<":case"<>":return e.fd===null||e.fd===0;default:return!1}}function Jr(e,t){return t.some(wp)?0:e.lastSubstitutionExitCode??0}function tu(e){let t=0;for(;t<e.length;){let n=e[t];if(n==="\\"&&t+1<e.length){t+=2;continue}if(n==="'"){let r=e.indexOf("'",t+1);if(r!==-1){t=r+1;continue}}if(n==="$"&&t+1<e.length&&e[t+1]==="("||n==="`")return!0;t++}return!1}function nu(e,t){let n=1,r=t,s=!1,i=!1;for(;r<e.length&&n>0;){let o=e[r];if(o==="\\"&&!s&&r+1<e.length){r+=2;continue}if(o==="'"&&!i){s=!s,r++;continue}if(o==='"'&&!s){i=!i,r++;continue}if(!s&&!i){if(o==="(")n++;else if(o===")"&&(n--,n===0))return r}r++}return-1}async function es(e,t){let n=new G,r;try{r=n.parse(t)}catch{return""}let s=e.state.bashPid;e.state.bashPid=e.state.nextVirtualPid++;let i=new Map(e.state.env),o=nt(e.state.arrays),a=e.state.cwd,l=e.state.suppressVerbose;e.state.suppressVerbose=!0;try{let u=await e.executeScript(r),c=u.exitCode;return e.state.env=i,e.state.arrays=o,e.state.cwd=a,e.state.suppressVerbose=l,Qt(e.state,c),u.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+u.stderr),e.state.bashPid=s,u.stdout.replace(/\n+$/,"")}catch(u){if(e.state.env=i,e.state.arrays=o,e.state.cwd=a,e.state.bashPid=s,e.state.suppressVerbose=l,u instanceof C)throw u;return u instanceof U?(Qt(e.state,u.exitCode),u.stdout?.replace(/\n+$/,"")??""):""}}function _i(e,t){let n="",r=0;for(;r<t.length;){let s=t[r];if(s==="'"){let i=t.indexOf("'",r+1);if(i!==-1){let o=t.slice(r+1,i);n+=Xe(o),r=i+1;continue}}if(s==='"'){let i=-1,o=r+1;for(;o<t.length;){if(t[o]==="\\"){o+=2;continue}if(t[o]==='"'){i=o;break}o++}if(i!==-1){let a=t.slice(r+1,i),l=Ep(e,a);n+=Xe(l),r=i+1;continue}}if(s==="$"&&r+1<t.length){let i=t[r+1];if(i==="{"){let o=t.indexOf("}",r+2);if(o!==-1){let a=t.slice(r+2,o);n+=e.state.env.get(a)??"",r=o+1;continue}}else if(/[a-zA-Z_]/.test(i)){let o=r+1;for(;o<t.length&&/[a-zA-Z0-9_]/.test(t[o]);)o++;let a=t.slice(r+1,o);n+=e.state.env.get(a)??"",r=o;continue}}if(s==="\\"&&r+1<t.length){n+=s+t[r+1],r+=2;continue}n+=s,r++}return n}function Ep(e,t){let n="",r=0;for(;r<t.length;){let s=t[r];if(s==="\\"&&r+1<t.length){let i=t[r+1];if(i==="$"||i==="`"||i==="\\"||i==='"'){n+=i,r+=2;continue}n+=s,r++;continue}if(s==="$"&&r+1<t.length){let i=t[r+1];if(i==="{"){let o=t.indexOf("}",r+2);if(o!==-1){let a=t.slice(r+2,o);n+=e.state.env.get(a)??"",r=o+1;continue}}else if(/[a-zA-Z_]/.test(i)){let o=r+1;for(;o<t.length&&/[a-zA-Z0-9_]/.test(t[o]);)o++;let a=t.slice(r+1,o);n+=e.state.env.get(a)??"",r=o;continue}}n+=s,r++}return n}async function ru(e,t){let n="",r=0;for(;r<t.length;){let s=t[r];if(s==="'"){let i=t.indexOf("'",r+1);if(i!==-1){let o=t.slice(r+1,i);n+=Xe(o),r=i+1;continue}}if(s==='"'){let i=-1,o=r+1;for(;o<t.length;){if(t[o]==="\\"){o+=2;continue}if(t[o]==='"'){i=o;break}o++}if(i!==-1){let a=t.slice(r+1,i),l=await bp(e,a);n+=Xe(l),r=i+1;continue}}if(s==="$"&&r+1<t.length&&t[r+1]==="("){let i=nu(t,r+2);if(i!==-1){let o=t.slice(r+2,i),a=await es(e,o);n+=a,r=i+1;continue}}if(s==="`"){let i=t.indexOf("`",r+1);if(i!==-1){let o=t.slice(r+1,i),a=await es(e,o);n+=a,r=i+1;continue}}if(s==="$"&&r+1<t.length){let i=t[r+1];if(i==="{"){let o=t.indexOf("}",r+2);if(o!==-1){let a=t.slice(r+2,o);n+=e.state.env.get(a)??"",r=o+1;continue}}else if(/[a-zA-Z_]/.test(i)){let o=r+1;for(;o<t.length&&/[a-zA-Z0-9_]/.test(t[o]);)o++;let a=t.slice(r+1,o);n+=e.state.env.get(a)??"",r=o;continue}}if(s==="\\"&&r+1<t.length){n+=s+t[r+1],r+=2;continue}n+=s,r++}return n}async function bp(e,t){let n="",r=0;for(;r<t.length;){let s=t[r];if(s==="\\"&&r+1<t.length){let i=t[r+1];if(i==="$"||i==="`"||i==="\\"||i==='"'){n+=i,r+=2;continue}n+=s,r++;continue}if(s==="$"&&r+1<t.length&&t[r+1]==="("){let i=nu(t,r+2);if(i!==-1){let o=t.slice(r+2,i),a=await es(e,o);n+=a,r=i+1;continue}}if(s==="`"){let i=t.indexOf("`",r+1);if(i!==-1){let o=t.slice(r+1,i),a=await es(e,o);n+=a,r=i+1;continue}}if(s==="$"&&r+1<t.length){let i=t[r+1];if(i==="{"){let o=t.indexOf("}",r+2);if(o!==-1){let a=t.slice(r+2,o);n+=e.state.env.get(a)??"",r=o+1;continue}}else if(/[a-zA-Z_]/.test(i)){let o=r+1;for(;o<t.length&&/[a-zA-Z0-9_]/.test(t[o]);)o++;let a=t.slice(r+1,o);n+=e.state.env.get(a)??"",r=o;continue}}n+=s,r++}return n}function Li(e,t){if(!t.startsWith("~"))return t;e.coverage?.hit("bash:expansion:tilde");let n=e.state.env.get("HOME")!==void 0?e.state.env.get("HOME"):"/home/user";if(t==="~"||t.startsWith("~/"))return n+t.slice(1);let r=1;for(;r<t.length&&/[a-zA-Z0-9_-]/.test(t[r]);)r++;let s=t.slice(1,r),i=t.slice(r);return i!==""&&!i.startsWith("/")?t:s==="root"?`/root${i}`:t}function Kt(e,t){return t.split(":").map(n=>Li(e,n)).join(":")}function Ne(e,t,n,r){if(e.length>n-t.length)throw new C(`${r} element limit exceeded (${n})`,"array_elements");for(let s of t)e.push(s)}async function Sp(e,t,n,r){let s="";for(let i of t.parts)if(i.type==="Glob")s+=se(i.pattern,!0,e.state.shoptOptions.extglob);else if(i.type==="Literal")s+=se(i.value,!0,e.state.shoptOptions.extglob);else if(i.type==="SingleQuoted"||i.type==="Escaped")s+=ae(i.value);else if(i.type==="DoubleQuoted"){let o=await n(e,i.parts);s+=ae(o)}else if(i.type==="ParameterExpansion"){let o=await r(e,i);s+=se(o,!0,e.state.shoptOptions.extglob)}else{let o=await r(e,i);s+=ae(o)}return s}async function su(e,t,n,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0];if(s.parts.length!==1||s.parts[0].type!=="ParameterExpansion"||s.parts[0].operation?.type!=="PatternReplacement")return null;let i=s.parts[0],o=i.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!o)return null;let a=o[1],l=o[2]==="*",u=i.operation,c=H(e,a),f=c.map(([,y])=>y);if(c.length===0){let y=e.state.env.get(a);y!==void 0&&f.push(y)}if(f.length===0)return{values:[],quoted:!0};let d="";u.pattern&&(d=await Sp(e,u.pattern,n,r));let p=u.replacement?await n(e,u.replacement.parts):"",h=d;u.anchor==="start"?h=`^${d}`:u.anchor==="end"&&(h=`${d}$`);let m=[];try{let y=me(h,u.all?"g":"");for(let b of f)m.push(y.replace(b,p))}catch{m.push(...f)}if(l){let y=Z(e.state.env);return{values:[m.join(y)],quoted:!0}}return{values:m,quoted:!0}}async function iu(e,t,n,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0];if(s.parts.length!==1||s.parts[0].type!=="ParameterExpansion"||s.parts[0].operation?.type!=="PatternRemoval")return null;let i=s.parts[0],o=i.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!o)return null;let a=o[1],l=o[2]==="*",u=i.operation,c=H(e,a),f=c.map(([,h])=>h);if(c.length===0){let h=e.state.env.get(a);h!==void 0&&f.push(h)}if(f.length===0)return{values:[],quoted:!0};let d=u.pattern?await Gt(e,u.pattern,u.greedy,n,r):"",p=[];for(let h of f)p.push(ht(e,h,d,u.side,u.greedy));if(l){let h=Z(e.state.env);return{values:[p.join(h)],quoted:!0}}return{values:p,quoted:!0}}async function ou(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0];if(n.parts.length!==1||n.parts[0].type!=="ParameterExpansion"||n.parts[0].operation?.type!=="DefaultValue"&&n.parts[0].operation?.type!=="UseAlternative"&&n.parts[0].operation?.type!=="AssignDefault")return null;let r=n.parts[0];if(r.operation?.type==="AssignDefault"&&/^(?:\d+|[@*#?$!-])$/.test(r.parameter))return null;let s=r.operation,i=r.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(s.type==="AssignDefault"&&(!i||i[2]==="*"))return null;let o,a=!1;if(i){let l=i[1];a=i[2]==="*";let u=H(e,l),c=u.length>0||e.state.env.has(l),f=u.length===0||u.length===1&&u.every(([,p])=>p===""),d=s.checkEmpty??!1;if(s.type==="UseAlternative"?o=c&&!(d&&f):o=!c||d&&f,!o){if(u.length>0){let h=u.map(([,m])=>m);if(a){let m=Z(e.state.env);return{values:[h.join(m)],quoted:!0}}return{values:h,quoted:!0}}let p=e.state.env.get(l);return p!==void 0?{values:[p],quoted:!0}:{values:[],quoted:!0}}}else{let l=r.parameter,u=await vt(e,l),c=await re(e,l,!1),f=c==="",d=s.checkEmpty??!1;if(s.type==="UseAlternative"?o=u&&!(d&&f):o=!u||d&&f,!o)return{values:[c],quoted:!0}}if(s.type==="AssignDefault")return null;if(o&&s.word){let l=s.word.parts,u=null,c=!1;for(let f of l)if(f.type==="ParameterExpansion"&&!f.operation){let d=f.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(d){u=d[1],c=d[2]==="*";break}}if(u){let f=H(e,u);if(f.length>0){let p=f.map(([,h])=>h);if(c||a){let h=Z(e.state.env);return{values:[p.join(h)],quoted:!0}}return{values:p,quoted:!0}}let d=e.state.env.get(u);return d!==void 0?{values:[d],quoted:!0}:{values:[],quoted:!0}}}return null}async function au(e,t,n,r,s){if(!n||t.length!==1||t[0].type!=="DoubleQuoted")return null;let i=t[0],o=-1,a="",l=!1,u=null;for(let m=0;m<i.parts.length;m++){let y=i.parts[m];if(y.type==="ParameterExpansion"&&(y.operation?.type==="PatternRemoval"||y.operation?.type==="PatternReplacement")){let b=y.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(b){o=m,a=b[1],l=b[2]==="*",u=y.operation;break}}}if(o===-1||o===0&&o===i.parts.length-1)return null;let c="";for(let m=0;m<o;m++)c+=await r(e,i.parts[m]);let f="";for(let m=o+1;m<i.parts.length;m++)f+=await r(e,i.parts[m]);let d=H(e,a),p=d.map(([,m])=>m);if(d.length===0){let m=e.state.env.get(a);if(m!==void 0)p=[m];else{if(l)return{values:[c+f],quoted:!0};let y=c+f;return{values:y?[y]:[],quoted:!0}}}if(u?.type==="PatternRemoval"){let m=u,y=m.pattern?await Gt(e,m.pattern,m.greedy,s,r):"";p=p.map(b=>ht(e,b,y,m.side,m.greedy))}else if(u?.type==="PatternReplacement"){let m=u,y="";if(m.pattern)for(let E of m.pattern.parts)if(E.type==="Glob")y+=se(E.pattern,!0,e.state.shoptOptions.extglob);else if(E.type==="Literal")y+=se(E.value,!0,e.state.shoptOptions.extglob);else if(E.type==="SingleQuoted"||E.type==="Escaped")y+=ae(E.value);else if(E.type==="DoubleQuoted"){let S=await s(e,E.parts);y+=ae(S)}else if(E.type==="ParameterExpansion"){let S=await r(e,E);y+=se(S,!0,e.state.shoptOptions.extglob)}else{let S=await r(e,E);y+=ae(S)}let b=m.replacement?await s(e,m.replacement.parts):"",w=y;m.anchor==="start"?w=`^${y}`:m.anchor==="end"&&(w=`${y}$`);try{let E=me(w,m.all?"g":"");p=p.map(S=>E.replace(S,b))}catch{}}if(l){let m=Z(e.state.env);return{values:[c+p.join(m)+f],quoted:!0}}return p.length===1?{values:[c+p[0]+f],quoted:!0}:{values:[c+p[0],...p.slice(1,-1),p[p.length-1]+f],quoted:!0}}async function lu(e,t,n,r){if(!n||t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0],i=-1,o="",a=!1;for(let p=0;p<s.parts.length;p++){let h=s.parts[p];if(h.type==="ParameterExpansion"&&!h.operation){let m=h.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(m){i=p,o=m[1],a=m[2]==="*";break}}}if(i===-1)return null;let l="";for(let p=0;p<i;p++)l+=await r(e,s.parts[p]);let u="";for(let p=i+1;p<s.parts.length;p++)u+=await r(e,s.parts[p]);let c=H(e,o),f=c.map(([,p])=>p);if(c.length===0){let p=e.state.env.get(o);if(p!==void 0)return{values:[l+p+u],quoted:!0};if(a)return{values:[l+u],quoted:!0};let h=l+u;return{values:h?[h]:[],quoted:!0}}if(a){let p=Z(e.state.env);return{values:[l+f.join(p)+u],quoted:!0}}return f.length===1?{values:[l+f[0]+u],quoted:!0}:{values:[l+f[0],...f.slice(1,-1),f[f.length-1]+u],quoted:!0}}async function uu(e,t,n){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let r=t[0];if(r.parts.length!==1||r.parts[0].type!=="ParameterExpansion"||r.parts[0].operation?.type!=="Substring")return null;let s=r.parts[0],i=s.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!i)return null;let o=i[1],a=i[2]==="*",l=s.operation;if(e.state.associativeArrays?.has(o))throw new U(1,"",`bash: \${${o}[@]: 0: 3}: bad substitution
112
+ `);let u=l.offset?await n(e,l.offset.expression):0,c=l.length?await n(e,l.length.expression):void 0,f=H(e,o);if(f.length>e.limits.maxArrayElements)throw new C(`array transform element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");let d=0;if(u<0){if(f.length>0){let h=f[f.length-1][0],y=(typeof h=="number"?h:0)+1+u;if(y<0)return{values:[],quoted:!0};d=f.findIndex(([b])=>typeof b=="number"&&b>=y),d<0&&(d=f.length)}}else d=f.findIndex(([h])=>typeof h=="number"&&h>=u),d<0&&(d=f.length);let p;if(c!==void 0){if(c<0)throw new oe(`${o}[@]: substring expression < 0`);p=f.slice(d,d+c).map(([,h])=>h)}else p=f.slice(d).map(([,h])=>h);if(p.length===0)return{values:[],quoted:!0};if(a){let h=Z(e.state.env);return{values:[p.join(h)],quoted:!0}}return{values:p,quoted:!0}}function cu(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0];if(n.parts.length!==1||n.parts[0].type!=="ParameterExpansion"||n.parts[0].operation?.type!=="Transform")return null;let r=n.parts[0],s=r.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!s)return null;let i=s[1],o=s[2]==="*",a=r.operation,l=H(e,i);if(l.length===0){let d=e.state.env.get(i);if(d!==void 0){let p;switch(a.operator){case"a":p="";break;case"P":p=cr(e,d);break;case"Q":p=Ht(d);break;default:p=d}if(W(p)>e.limits.maxStringLength)throw new C(`array transform string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return{values:[p],quoted:!0}}return o?{values:[""],quoted:!0}:{values:[],quoted:!0}}let u=Zt(e,i),c=[],f=0;for(let[,d]of l){let p;switch(a.operator){case"a":p=u;break;case"P":p=cr(e,d);break;case"Q":p=Ht(d);break;case"u":p=d.charAt(0).toUpperCase()+d.slice(1);break;case"U":p=d.toUpperCase();break;case"L":p=d.toLowerCase();break;default:p=d}let h=W(p);if(h>e.limits.maxStringLength-f)throw new C(`array transform string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");c.push(p),f+=h}if(o){let d=Z(e.state.env);if(Math.max(0,c.length-1)*W(d)>e.limits.maxStringLength-f)throw new C(`array transform string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return{values:[c.join(d)],quoted:!0}}return{values:c,quoted:!0}}function fu(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0];if(n.parts.length!==1||n.parts[0].type!=="ParameterExpansion")return null;let r=n.parts[0];if(r.operation)return null;let s=r.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(@)\]$/);if(!s)return null;let i=s[1];if(le(e,i)){let l=En(e,i);if(l?.endsWith("[@]")||l?.endsWith("[*]"))return{values:[],quoted:!0}}let o=H(e,i);if(o.length>0)return{values:o.map(([,l])=>l),quoted:!0};let a=e.state.env.get(i);return a!==void 0?{values:[a],quoted:!0}:{values:[],quoted:!0}}function du(e,t){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let n=t[0];if(n.parts.length!==1||n.parts[0].type!=="ParameterExpansion"||n.parts[0].operation)return null;let s=n.parts[0].parameter;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(s)||!le(e,s))return null;let i=En(e,s);if(!i)return null;let o=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(@)\]$/);if(!o)return null;let a=o[1],l=H(e,a);if(l.length>0)return{values:l.map(([,c])=>c),quoted:!0};let u=e.state.env.get(a);return u!==void 0?{values:[u],quoted:!0}:{values:[],quoted:!0}}async function pu(e,t,n,r,s){if(!n||t.length!==1||t[0].type!=="DoubleQuoted")return null;let i=t[0];if(i.parts.length!==1||i.parts[0].type!=="ParameterExpansion"||i.parts[0].operation?.type!=="Indirection")return null;let o=i.parts[0],a=o.operation,l=await re(e,o.parameter),u=l.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!u){if(!a.innerOp&&(l==="@"||l==="*")){let h=Number.parseInt(e.state.env.get("#")||"0",10),m=[];for(let y=1;y<=h;y++)m.push(e.state.env.get(String(y))||"");return l==="*"?{values:[m.join(Z(e.state.env))],quoted:!0}:{values:m,quoted:!0}}return null}let c=u[1],f=u[2]==="*",d=H(e,c);if(a.innerOp){if(a.innerOp.type==="Substring")return Ap(e,d,c,f,a.innerOp);if(a.innerOp.type==="DefaultValue"||a.innerOp.type==="UseAlternative"||a.innerOp.type==="AssignDefault"||a.innerOp.type==="ErrorIfUnset")return vp(e,d,c,f,a.innerOp,s);if(a.innerOp.type==="Transform"&&a.innerOp.operator==="a"){let m=Zt(e,c),y=d.map(()=>m);return f?{values:[y.join(Z(e.state.env))],quoted:!0}:{values:y,quoted:!0}}let h=[];for(let[,m]of d){let y={type:"ParameterExpansion",parameter:"_indirect_elem_",operation:a.innerOp},b=e.state.env.get("_indirect_elem_");e.state.env.set("_indirect_elem_",m);try{let w=await r(e,y,!0);h.push(w)}finally{b!==void 0?e.state.env.set("_indirect_elem_",b):e.state.env.delete("_indirect_elem_")}}return f?{values:[h.join(Z(e.state.env))],quoted:!0}:{values:h,quoted:!0}}if(d.length>0){let h=d.map(([,m])=>m);return f?{values:[h.join(Z(e.state.env))],quoted:!0}:{values:h,quoted:!0}}let p=e.state.env.get(c);return p!==void 0?{values:[p],quoted:!0}:{values:[],quoted:!0}}async function Ap(e,t,n,r,s){let i=s.offset?await X(e,s.offset.expression):0,o=s.length?await X(e,s.length.expression):void 0,a=0;if(i<0){if(t.length>0){let c=t[t.length-1][0],d=(typeof c=="number"?c:0)+1+i;if(d<0)return{values:[],quoted:!0};if(a=t.findIndex(([p])=>typeof p=="number"&&p>=d),a<0)return{values:[],quoted:!0}}}else if(a=t.findIndex(([c])=>typeof c=="number"&&c>=i),a<0)return{values:[],quoted:!0};let l;if(o!==void 0){if(o<0)throw new oe(`${n}[@]: substring expression < 0`);l=t.slice(a,a+o)}else l=t.slice(a);let u=l.map(([,c])=>c);return r?{values:[u.join(Z(e.state.env))],quoted:!0}:{values:u,quoted:!0}}async function vp(e,t,n,r,s,i){let o=s.checkEmpty??!1,a=t.map(([,c])=>c),l=t.length===0,u=t.length===0;if(s.type==="UseAlternative")return!u&&!(o&&l)&&s.word?{values:[await i(e,s.word.parts,!0)],quoted:!0}:{values:[],quoted:!0};if(s.type==="DefaultValue")return(u||o&&l)&&s.word?{values:[await i(e,s.word.parts,!0)],quoted:!0}:r?{values:[a.join(Z(e.state.env))],quoted:!0}:{values:a,quoted:!0};if(s.type==="AssignDefault"){if((u||o&&l)&&s.word){let f=await i(e,s.word.parts,!0);return j(e,n,0,f),{values:[f],quoted:!0}}return r?{values:[a.join(Z(e.state.env))],quoted:!0}:{values:a,quoted:!0}}return r?{values:[a.join(Z(e.state.env))],quoted:!0}:{values:a,quoted:!0}}async function hu(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="UseAlternative"&&t[0].operation?.type!=="DefaultValue")return null;let n=t[0],r=n.operation,s=r?.word;if(!s||s.parts.length!==1||s.parts[0].type!=="DoubleQuoted")return null;let i=s.parts[0];if(i.parts.length!==1||i.parts[0].type!=="ParameterExpansion"||i.parts[0].operation?.type!=="Indirection")return null;let o=i.parts[0],l=(await re(e,o.parameter)).match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!l)return null;let u=await vt(e,n.parameter),c=await re(e,n.parameter)==="",f=r.checkEmpty??!1,d;if(r.type==="UseAlternative"?d=u&&!(f&&c):d=!u||f&&c,d){let p=l[1],h=l[2]==="*",m=H(e,p);if(m.length>0){let b=m.map(([,w])=>w);return h?{values:[b.join(Z(e.state.env))],quoted:!0}:{values:b,quoted:!0}}let y=e.state.env.get(p);return y!==void 0?{values:[y],quoted:!0}:{values:[],quoted:!0}}return{values:[],quoted:!1}}async function mu(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="Indirection")return null;let n=t[0],s=n.operation.innerOp;if(!s||s.type!=="UseAlternative"&&s.type!=="DefaultValue")return null;let i=s.word;if(!i||i.parts.length!==1||i.parts[0].type!=="DoubleQuoted")return null;let o=i.parts[0];if(o.parts.length!==1||o.parts[0].type!=="ParameterExpansion"||o.parts[0].operation?.type!=="Indirection")return null;let a=o.parts[0],u=(await re(e,a.parameter)).match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!u)return null;let c=await re(e,n.parameter),f=await vt(e,n.parameter),d=c==="",p=s.checkEmpty??!1,h;if(s.type==="UseAlternative"?h=f&&!(p&&d):h=!f||p&&d,h){let m=u[1],y=u[2]==="*",b=H(e,m);if(b.length>0){let E=b.map(([,S])=>S);return y?{values:[E.join(Z(e.state.env))],quoted:!0}:{values:E,quoted:!0}}let w=e.state.env.get(m);return w!==void 0?{values:[w],quoted:!0}:{values:[],quoted:!0}}return{values:[],quoted:!1}}function yu(e){let t=Number.parseInt(e.state.env.get("#")||"0",10);if(t>e.limits.maxArrayElements)throw new C(`positional parameter element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");let n=[],r=0;for(let s=1;s<=t;s++){let i=e.state.env.get(String(s))||"",o=W(i);if(o>e.limits.maxStringLength-r)throw new C(`positional parameter string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");n.push(i),r+=o}return n}function ts(e,t,n){if(W(t)>n-W(e))throw new C(`positional expansion string limit exceeded (${n} bytes)`,"string_length");return e+t}function Ti(e,t,n,r){if(e.length>=r.limits.maxArrayElements)throw new C(`positional expansion element limit exceeded (${r.limits.maxArrayElements})`,"array_elements");let s=W(t);if(s>r.limits.maxStringLength-n.value)throw new C(`positional expansion string limit exceeded (${r.limits.maxStringLength} bytes)`,"string_length");e.push(t),n.value+=s}async function gu(e,t,n,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0],i=-1,o=!1;for(let w=0;w<s.parts.length;w++){let E=s.parts[w];if(E.type==="ParameterExpansion"&&(E.parameter==="@"||E.parameter==="*")&&E.operation?.type==="Substring"){i=w,o=E.parameter==="*";break}}if(i===-1)return null;let l=s.parts[i].operation,u=l.offset?await n(e,l.offset.expression):0,c=l.length?await n(e,l.length.expression):void 0,f=Number.parseInt(e.state.env.get("#")||"0",10),d=[];for(let w=1;w<=f;w++)d.push(e.state.env.get(String(w))||"");let p=e.state.env.get("0")||"bash",h;if(u<=0){let w=[p,...d],E=w.length+u;if(E<0)h=[];else{let S=u<0?E:0;if(c!==void 0){let v=c<0?w.length+c:S+c;h=w.slice(S,Math.max(S,v))}else h=w.slice(S)}}else{let w=u-1;if(w>=d.length)h=[];else if(c!==void 0){let E=c<0?d.length+c:w+c;h=d.slice(w,Math.max(w,E))}else h=d.slice(w)}let m="";for(let w=0;w<i;w++)m+=await r(e,s.parts[w]);let y="";for(let w=i+1;w<s.parts.length;w++)y+=await r(e,s.parts[w]);if(h.length===0){let w=m+y;return{values:w?[w]:[],quoted:!0}}if(o){let w=Z(e.state.env);return{values:[m+h.join(w)+y],quoted:!0}}return h.length===1?{values:[m+h[0]+y],quoted:!0}:{values:[m+h[0],...h.slice(1,-1),h[h.length-1]+y],quoted:!0}}async function wu(e,t,n,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0],i=-1,o=!1;for(let w=0;w<s.parts.length;w++){let E=s.parts[w];if(E.type==="ParameterExpansion"&&(E.parameter==="@"||E.parameter==="*")&&E.operation?.type==="PatternReplacement"){i=w,o=E.parameter==="*";break}}if(i===-1)return null;let l=s.parts[i].operation,u=yu(e),c="";for(let w=0;w<i;w++)c=ts(c,await n(e,s.parts[w]),e.limits.maxStringLength);let f="";for(let w=i+1;w<s.parts.length;w++)f=ts(f,await n(e,s.parts[w]),e.limits.maxStringLength);if(u.length===0){let w=c+f;return{values:w?[w]:[],quoted:!0}}let d="";if(l.pattern)for(let w of l.pattern.parts)if(w.type==="Glob")d+=se(w.pattern,!0,e.state.shoptOptions.extglob);else if(w.type==="Literal")d+=se(w.value,!0,e.state.shoptOptions.extglob);else if(w.type==="SingleQuoted"||w.type==="Escaped")d+=ae(w.value);else if(w.type==="DoubleQuoted"){let E=await r(e,w.parts);d+=ae(E)}else if(w.type==="ParameterExpansion"){let E=await n(e,w);d+=se(E,!0,e.state.shoptOptions.extglob)}else{let E=await n(e,w);d+=ae(E)}let p=l.replacement?await r(e,l.replacement.parts):"",h=d;l.anchor==="start"?h=`^${d}`:l.anchor==="end"&&(h=`${d}$`);let m=[],y={value:0};try{let w=me(h,l.all?"g":"");for(let E of u){let S=0;w.lastIndex=0;for(let P=w.exec(E);P&&(S++,!!l.all);P=w.exec(E))P[0].length===0&&w.lastIndex++;let v=W(E),A=W(p),x=0,$=/\$(?:\$|&|\d+|<[^>]+>|`|')/g;for(;$.exec(p)!==null;)x++;if(v+S*A+S*x*v>e.limits.maxStringLength-y.value)throw new C(`positional expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");Ti(m,w.replace(E,p),y,e)}}catch(w){if(w instanceof C)throw w;for(let E of u)Ti(m,E,y,e)}if(o){let w=Z(e.state.env);if(y.value+Math.max(0,m.length-1)*W(w)+W(c)+W(f)>e.limits.maxStringLength)throw new C(`positional expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return{values:[c+m.join(w)+f],quoted:!0}}if(W(c)+y.value+W(f)>e.limits.maxStringLength)throw new C(`positional expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return m.length===1?{values:[c+m[0]+f],quoted:!0}:{values:[c+m[0],...m.slice(1,-1),m[m.length-1]+f],quoted:!0}}async function Eu(e,t,n,r){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let s=t[0],i=-1,o=!1;for(let b=0;b<s.parts.length;b++){let w=s.parts[b];if(w.type==="ParameterExpansion"&&(w.parameter==="@"||w.parameter==="*")&&w.operation?.type==="PatternRemoval"){i=b,o=w.parameter==="*";break}}if(i===-1)return null;let l=s.parts[i].operation,u=yu(e),c="";for(let b=0;b<i;b++)c=ts(c,await n(e,s.parts[b]),e.limits.maxStringLength);let f="";for(let b=i+1;b<s.parts.length;b++)f=ts(f,await n(e,s.parts[b]),e.limits.maxStringLength);if(u.length===0){let b=c+f;return{values:b?[b]:[],quoted:!0}}let d="",p=e.state.shoptOptions.extglob;if(l.pattern)for(let b of l.pattern.parts)if(b.type==="Glob")d+=se(b.pattern,l.greedy,p);else if(b.type==="Literal")d+=se(b.value,l.greedy,p);else if(b.type==="SingleQuoted"||b.type==="Escaped")d+=ae(b.value);else if(b.type==="DoubleQuoted"){let w=await r(e,b.parts);d+=ae(w)}else if(b.type==="ParameterExpansion"){let w=await n(e,b);d+=se(w,l.greedy,p)}else{let w=await n(e,b);d+=ae(w)}let h=[],m={value:0};for(let b of u)Ti(h,ht(e,b,d,l.side,l.greedy),m,e);if(o){let b=Z(e.state.env);if(m.value+Math.max(0,h.length-1)*W(b)+W(c)+W(f)>e.limits.maxStringLength)throw new C(`positional expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return{values:[c+h.join(b)+f],quoted:!0}}if(W(c)+m.value+W(f)>e.limits.maxStringLength)throw new C(`positional expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return h.length===1?{values:[c+h[0]+f],quoted:!0}:{values:[c+h[0],...h.slice(1,-1),h[h.length-1]+f],quoted:!0}}async function bu(e,t,n){if(t.length!==1||t[0].type!=="DoubleQuoted")return null;let r=t[0],s=-1,i=!1;for(let d=0;d<r.parts.length;d++){let p=r.parts[d];if(p.type==="ParameterExpansion"&&(p.parameter==="@"||p.parameter==="*")){s=d,i=p.parameter==="*";break}}if(s===-1)return null;let o=r.parts[s];if(o.type==="ParameterExpansion"&&o.operation)return null;let a=Number.parseInt(e.state.env.get("#")||"0",10),l="";for(let d=0;d<s;d++)l+=await n(e,r.parts[d]);let u="";for(let d=s+1;d<r.parts.length;d++)u+=await n(e,r.parts[d]);if(a===0){if(i)return{values:[l+u],quoted:!0};let d=l+u;return{values:d?[d]:[],quoted:!0}}let c=[];for(let d=1;d<=a;d++)c.push(e.state.env.get(String(d))||"");if(i){let d=Z(e.state.env);return{values:[l+c.join(d)+u],quoted:!0}}return c.length===1?{values:[l+c[0]+u],quoted:!0}:{values:[l+c[0],...c.slice(1,-1),c[c.length-1]+u],quoted:!0}}function $t(e,t,n,r){if(t.length>=e.limits.maxArrayElements)throw new C(`unquoted expansion element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");let s=W(n);if(s>e.limits.maxStringLength-r.value)throw new C(`unquoted expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");t.push(n),r.value+=s}function Fi(e,t,n,r){let s=W(n),i=Math.max(0,t.length-1);if(s>0&&i>Math.floor((e.limits.maxStringLength-r)/s))throw new C(`unquoted expansion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");return t.join(n)}function xp(e){return new jt(e.fs,e.state.cwd,e.state.env,{globstar:e.state.shoptOptions.globstar,nullglob:e.state.shoptOptions.nullglob,failglob:e.state.shoptOptions.failglob,dotglob:e.state.shoptOptions.dotglob,extglob:e.state.shoptOptions.extglob,globskipdots:e.state.shoptOptions.globskipdots,maxGlobOperations:e.limits.maxGlobOperations,consumeOperation:()=>e.executionScope.consumeLimited("glob_operations",1,e.limits.maxGlobOperations,"glob expansion")})}async function ns(e,t){if(e.state.options.noglob)return t;let n=xp(e),r=[];for(let s of t)if(xt(s,e.state.shoptOptions.extglob)){let i=await n.expand(s);if(i.length>0)Ne(r,i,e.limits.maxArrayElements,"unquoted glob expansion");else{if(n.hasFailglob())throw new Lt(s);n.hasNullglob()||r.push(s)}}else r.push(s);return r}async function Su(e,t,n,r){let s=-1,i="",o=!1;for(let S=0;S<t.length;S++){let v=t[S];if(v.type==="ParameterExpansion"&&v.operation?.type==="PatternReplacement"){let A=v.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(A){s=S,i=A[1],o=A[2]==="*";break}}}if(s===-1)return null;let l=t[s].operation,u=H(e,i),c=u.map(([,S])=>S);if(u.length===0){let S=e.state.env.get(i);S!==void 0&&(c=[S])}if(c.length===0)return{values:[],quoted:!1};let f="";if(l.pattern)for(let S of l.pattern.parts)if(S.type==="Glob")f+=se(S.pattern,!0,e.state.shoptOptions.extglob);else if(S.type==="Literal")f+=se(S.value,!0,e.state.shoptOptions.extglob);else if(S.type==="SingleQuoted"||S.type==="Escaped")f+=ae(S.value);else if(S.type==="DoubleQuoted"){let v=await n(e,S.parts);f+=ae(v)}else if(S.type==="ParameterExpansion"){let v=await r(e,S);f+=se(v,!0,e.state.shoptOptions.extglob)}else{let v=await r(e,S);f+=ae(v)}let d=l.replacement?await n(e,l.replacement.parts):"",p=f;l.anchor==="start"?p=`^${f}`:l.anchor==="end"&&(p=`${f}$`);let h=[],m={value:0};try{let S=me(p,l.all?"g":"");for(let v of c)$t(e,h,Xr(e,v,S,d,l.all),m)}catch(S){if(S instanceof C)throw S;for(let v of c)$t(e,h,v,m)}let y=Se(e.state.env),b=Ce(e.state.env);if(o){let S=Z(e.state.env),v=Fi(e,h,S,m.value);return b?{values:v?[v]:[],quoted:!1}:{values:ce(v,y,e.limits.maxArrayElements),quoted:!1}}if(b)return{values:h,quoted:!1};let w=[],E={value:0};for(let S of h)if(S==="")$t(e,w,"",E);else for(let v of ce(S,y,e.limits.maxArrayElements))$t(e,w,v,E);return{values:w,quoted:!1}}async function Au(e,t,n,r){let s=-1,i="",o=!1;for(let w=0;w<t.length;w++){let E=t[w];if(E.type==="ParameterExpansion"&&E.operation?.type==="PatternRemoval"){let S=E.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(S){s=w,i=S[1],o=S[2]==="*";break}}}if(s===-1)return null;let l=t[s].operation,u=H(e,i),c=u.map(([,w])=>w);if(u.length===0){let w=e.state.env.get(i);w!==void 0&&(c=[w])}if(c.length===0)return{values:[],quoted:!1};let f=l.pattern?await Gt(e,l.pattern,l.greedy,n,r):"",d=[],p={value:0};for(let w of c)$t(e,d,ht(e,w,f,l.side,l.greedy),p);let h=Se(e.state.env),m=Ce(e.state.env);if(o){let w=Z(e.state.env),E=Fi(e,d,w,p.value);return m?{values:E?[E]:[],quoted:!1}:{values:ce(E,h,e.limits.maxArrayElements),quoted:!1}}if(m)return{values:d,quoted:!1};let y=[],b={value:0};for(let w of d)if(w==="")$t(e,y,"",b);else for(let E of ce(w,h,e.limits.maxArrayElements))$t(e,y,E,b);return{values:y,quoted:!1}}async function vu(e,t,n,r){let s=-1,i=!1;for(let w=0;w<t.length;w++){let E=t[w];if(E.type==="ParameterExpansion"&&(E.parameter==="@"||E.parameter==="*")&&E.operation?.type==="PatternRemoval"){s=w,i=E.parameter==="*";break}}if(s===-1)return null;let a=t[s].operation,l=Number.parseInt(e.state.env.get("#")||"0",10),u=[];for(let w=1;w<=l;w++)u.push(e.state.env.get(String(w))||"");if(u.length===0)return{values:[],quoted:!1};let c="",f=e.state.shoptOptions.extglob;if(a.pattern)for(let w of a.pattern.parts)if(w.type==="Glob")c+=se(w.pattern,a.greedy,f);else if(w.type==="Literal")c+=se(w.value,a.greedy,f);else if(w.type==="SingleQuoted"||w.type==="Escaped")c+=ae(w.value);else if(w.type==="DoubleQuoted"){let E=await n(e,w.parts);c+=ae(E)}else if(w.type==="ParameterExpansion"){let E=await r(e,w);c+=se(E,a.greedy,f)}else{let E=await r(e,w);c+=ae(E)}let d=[],p={value:0};for(let w of u)$t(e,d,ht(e,w,c,a.side,a.greedy),p);let h=Se(e.state.env),m=Ce(e.state.env);if(i){let w=Z(e.state.env),E=Fi(e,d,w,p.value);return m?{values:E?[E]:[],quoted:!1}:{values:ce(E,h,e.limits.maxArrayElements),quoted:!1}}if(m)return{values:d,quoted:!1};let y=[],b={value:0};for(let w of d)if(w==="")$t(e,y,"",b);else for(let E of ce(w,h,e.limits.maxArrayElements))$t(e,y,E,b);return{values:y,quoted:!1}}async function xu(e,t,n,r){let s=-1,i=!1;for(let E=0;E<t.length;E++){let S=t[E];if(S.type==="ParameterExpansion"&&(S.parameter==="@"||S.parameter==="*")&&S.operation?.type==="Substring"){s=E,i=S.parameter==="*";break}}if(s===-1)return null;let a=t[s].operation,l=a.offset?await n(e,a.offset.expression):0,u=a.length?await n(e,a.length.expression):void 0,c=Number.parseInt(e.state.env.get("#")||"0",10),f=[];for(let E=1;E<=c;E++)f.push(e.state.env.get(String(E))||"");let d=e.state.env.get("0")||"bash",p;if(l<=0){let E=[d,...f],S=E.length+l;if(S<0)p=[];else{let v=l<0?S:0;if(u!==void 0){let A=u<0?E.length+u:v+u;p=E.slice(v,Math.max(v,A))}else p=E.slice(v)}}else{let E=l-1;if(E>=f.length)p=[];else if(u!==void 0){let S=u<0?f.length+u:E+u;p=f.slice(E,Math.max(E,S))}else p=f.slice(E)}let h="";for(let E=0;E<s;E++)h+=await r(e,t[E]);let m="";for(let E=s+1;E<t.length;E++)m+=await r(e,t[E]);let y=Se(e.state.env),b=Ce(e.state.env);if(p.length===0){let E=h+m;return E?b?{values:[E],quoted:!1}:{values:ce(E,y,e.limits.maxArrayElements),quoted:!1}:{values:[],quoted:!1}}let w;if(i){let E=Z(e.state.env),S=h+p.join(E)+m;b?w=S?[S]:[]:w=ce(S,y,e.limits.maxArrayElements)}else if(b)p.length===1?w=[h+p[0]+m]:w=[h+p[0],...p.slice(1,-1),p[p.length-1]+m];else{w=[];for(let E=0;E<p.length;E++){let S=p[E];if(E===0&&(S=h+S),E===p.length-1&&(S=S+m),S==="")w.push("");else{let v=ce(S,y,e.limits.maxArrayElements);Ne(w,v,e.limits.maxArrayElements,"unquoted expansion")}}}return{values:await ns(e,w),quoted:!1}}async function $u(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].parameter!=="@"&&t[0].parameter!=="*"||t[0].operation)return null;let n=t[0].parameter==="*",r=Number.parseInt(e.state.env.get("#")||"0",10);if(r===0)return{values:[],quoted:!1};let s=[];for(let u=1;u<=r;u++)s.push(e.state.env.get(String(u))||"");let i=Se(e.state.env),o=Ce(e.state.env),a=Gr(e.state.env),l;if(n)if(o)l=s.filter(u=>u!=="");else{let u=Z(e.state.env),c=s.join(u);l=ce(c,i,e.limits.maxArrayElements)}else if(o)l=s.filter(u=>u!=="");else if(a){l=[];for(let u of s){if(u==="")continue;let c=ce(u,i,e.limits.maxArrayElements);Ne(l,c,e.limits.maxArrayElements,"unquoted expansion")}}else{l=[];for(let u of s)if(u==="")l.push("");else{let c=ce(u,i,e.limits.maxArrayElements);Ne(l,c,e.limits.maxArrayElements,"unquoted expansion")}for(;l.length>0&&l[l.length-1]==="";)l.pop()}return{values:await ns(e,l),quoted:!1}}async function ku(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation)return null;let n=t[0].parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(!n)return null;let r=n[1],s=n[2]==="*",i=H(e,r),o;if(i.length===0){let f=e.state.env.get(r);if(f!==void 0)o=[f];else return{values:[],quoted:!1}}else o=i.map(([,f])=>f);let a=Se(e.state.env),l=Ce(e.state.env),u=Gr(e.state.env),c;if(s)if(l)c=o.filter(f=>f!=="");else{let f=Z(e.state.env),d=o.join(f);c=ce(d,a,e.limits.maxArrayElements)}else if(l)c=o.filter(f=>f!=="");else if(u){c=[];for(let f of o){if(f==="")continue;let d=ce(f,a,e.limits.maxArrayElements);Ne(c,d,e.limits.maxArrayElements,"unquoted expansion")}}else{c=[];for(let f of o)if(f==="")c.push("");else{let d=ce(f,a,e.limits.maxArrayElements);Ne(c,d,e.limits.maxArrayElements,"unquoted expansion")}for(;c.length>0&&c[c.length-1]==="";)c.pop()}return{values:await ns(e,c),quoted:!1}}function Pu(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="VarNamePrefix")return null;let n=t[0].operation,r=Fn(e,n.prefix);if(r.length===0)return{values:[],quoted:!1};let s=Se(e.state.env),i=Ce(e.state.env),o;if(n.star)if(i)o=r;else{let a=Z(e.state.env),l=r.join(a);o=ce(l,s,e.limits.maxArrayElements)}else if(i)o=r;else{o=[];for(let a of r){let l=ce(a,s,e.limits.maxArrayElements);Ne(o,l,e.limits.maxArrayElements,"unquoted expansion")}}return{values:o,quoted:!1}}function Cu(e,t){if(t.length!==1||t[0].type!=="ParameterExpansion"||t[0].operation?.type!=="ArrayKeys")return null;let n=t[0].operation,s=H(e,n.array).map(([l])=>String(l));if(s.length===0)return{values:[],quoted:!1};let i=Se(e.state.env),o=Ce(e.state.env),a;if(n.star)if(o)a=s;else{let l=Z(e.state.env),u=s.join(l);a=ce(u,i,e.limits.maxArrayElements)}else if(o)a=s;else{a=[];for(let l of s){let u=ce(l,i,e.limits.maxArrayElements);Ne(a,u,e.limits.maxArrayElements,"unquoted expansion")}}return{values:a,quoted:!1}}async function Nu(e,t,n){let r=-1;for(let d=0;d<t.length;d++){let p=t[d];if(p.type==="ParameterExpansion"&&(p.parameter==="@"||p.parameter==="*")&&!p.operation){r=d;break}}if(r===-1||t.length<=1)return null;let s=Number.parseInt(e.state.env.get("#")||"0",10),i=[];for(let d=1;d<=s;d++)i.push(e.state.env.get(String(d))||"");let o="";for(let d=0;d<r;d++)o+=await n(e,t[d]);let a="";for(let d=r+1;d<t.length;d++)a+=await n(e,t[d]);let l=Se(e.state.env),u=Ce(e.state.env),c=Gr(e.state.env);if(s===0){let d=o+a;return{values:d?[d]:[],quoted:!1}}let f;{let d=[];for(let p=0;p<i.length;p++){let h=i[p];p===0&&(h=o+h),p===i.length-1&&(h=h+a),d.push(h)}if(u)f=d.filter(p=>p!=="");else if(c){f=[];for(let p of d){if(p==="")continue;let h=ce(p,l,e.limits.maxArrayElements);Ne(f,h,e.limits.maxArrayElements,"unquoted expansion")}}else{f=[];for(let p of d)if(p==="")f.push("");else{let h=ce(p,l,e.limits.maxArrayElements);Ne(f,h,e.limits.maxArrayElements,"unquoted expansion")}for(;f.length>0&&f[f.length-1]==="";)f.pop()}}return f.length===0?{values:[],quoted:!1}:{values:await ns(e,f),quoted:!1}}async function Iu(e,t,n){e.coverage?.hit("bash:expansion:word_glob");let r=t.parts,{hasQuoted:s,hasCommandSub:i,hasArrayVar:o,hasArrayAtExpansion:a,hasParamExpansion:l,hasVarNamePrefixExpansion:u,hasIndirection:c}=lr(r),d=n.hasBraceExpansion(r)?await n.expandWordWithBracesAsync(e,t):null;if(d&&d.length>1)return $p(e,d,s);let p=await kp(e,r,a,u,c,n);if(p!==null)return p;let h=await Cp(e,r,n);if(h!==null)return h;let m=await Np(e,r,n);if(m!==null)return m;let y=await Dp(e,r,n.expandPart);if(y!==null)return Du(e,y);if((i||o||l)&&!Ce(e.state.env)){let w=Se(e.state.env),E=n.buildIfsCharClassPattern(w),S=await n.smartWordSplit(e,r,w,E,n.expandPart);return Du(e,S)}let b=await n.expandWordAsync(e,t);return Ip(e,t,r,b,s,n.expandWordForGlobbing)}async function $p(e,t,n){let r=[];for(let s of t)if(!(!n&&s===""))if(!n&&!e.state.options.noglob&&xt(s,e.state.shoptOptions.extglob)){let i=await rs(e,s);Ne(r,i,e.limits.maxArrayElements,"brace/glob expansion")}else r.push(s);return{values:r,quoted:!1}}async function kp(e,t,n,r,s,i){if(n){let o=fu(e,t);if(o!==null)return o}{let o=du(e,t);if(o!==null)return o}{let o=await ou(e,t);if(o!==null)return o}{let o=await au(e,t,n,i.expandPart,i.expandWordPartsAsync);if(o!==null)return o}{let o=await lu(e,t,n,i.expandPart);if(o!==null)return o}{let o=await uu(e,t,i.evaluateArithmetic);if(o!==null)return o}{let o=cu(e,t);if(o!==null)return o}{let o=await su(e,t,i.expandWordPartsAsync,i.expandPart);if(o!==null)return o}{let o=await iu(e,t,i.expandWordPartsAsync,i.expandPart);if(o!==null)return o}if(r&&t.length===1&&t[0].type==="DoubleQuoted"){let o=Pp(e,t);if(o!==null)return o}{let o=await pu(e,t,s,i.expandParameterAsync,i.expandWordPartsAsync);if(o!==null)return o}{let o=await hu(e,t);if(o!==null)return o}{let o=await mu(e,t);if(o!==null)return o}return null}function Pp(e,t){let n=t[0];if(n.type!=="DoubleQuoted")return null;if(n.parts.length===1&&n.parts[0].type==="ParameterExpansion"&&n.parts[0].operation?.type==="VarNamePrefix"){let r=n.parts[0].operation,s=Fn(e,r.prefix);return r.star?{values:[s.join(Z(e.state.env))],quoted:!0}:{values:s,quoted:!0}}if(n.parts.length===1&&n.parts[0].type==="ParameterExpansion"&&n.parts[0].operation?.type==="ArrayKeys"){let r=n.parts[0].operation,i=H(e,r.array).map(([o])=>String(o));return r.star?{values:[i.join(Z(e.state.env))],quoted:!0}:{values:i,quoted:!0}}return null}async function Cp(e,t,n){{let r=await gu(e,t,n.evaluateArithmetic,n.expandPart);if(r!==null)return r}{let r=await wu(e,t,n.expandPart,n.expandWordPartsAsync);if(r!==null)return r}{let r=await Eu(e,t,n.expandPart,n.expandWordPartsAsync);if(r!==null)return r}{let r=await bu(e,t,n.expandPart);if(r!==null)return r}return null}async function Np(e,t,n){{let r=await Su(e,t,n.expandWordPartsAsync,n.expandPart);if(r!==null)return r}{let r=await Au(e,t,n.expandWordPartsAsync,n.expandPart);if(r!==null)return r}{let r=await vu(e,t,n.expandWordPartsAsync,n.expandPart);if(r!==null)return r}{let r=await xu(e,t,n.evaluateArithmetic,n.expandPart);if(r!==null)return r}{let r=await $u(e,t);if(r!==null)return r}{let r=await ku(e,t);if(r!==null)return r}{let r=Pu(e,t);if(r!==null)return r}{let r=Cu(e,t);if(r!==null)return r}{let r=await Nu(e,t,n.expandPart);if(r!==null)return r}return null}function Ru(e){if(e.type!=="DoubleQuoted")return null;for(let t=0;t<e.parts.length;t++){let n=e.parts[t];if(n.type!=="ParameterExpansion"||n.operation)continue;let r=n.parameter.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([@*])\]$/);if(r)return{type:"array",name:r[1],atIndex:t,isStar:r[2]==="*"};if(n.parameter==="@"||n.parameter==="*")return{type:"positional",atIndex:t,isStar:n.parameter==="*"}}return null}async function Rp(e,t,n,r){let s="";for(let a=0;a<n.atIndex;a++)s+=await r(e,t.parts[a]);let i="";for(let a=n.atIndex+1;a<t.parts.length;a++)i+=await r(e,t.parts[a]);let o;if(n.type==="array"){if(o=H(e,n.name).map(([,l])=>l),o.length===0){let l=e.state.env.get(n.name);l!==void 0&&(o=[l])}}else{let a=Number.parseInt(e.state.env.get("#")||"0",10);o=[];for(let l=1;l<=a;l++)o.push(e.state.env.get(String(l))||"")}if(n.isStar){let a=Z(e.state.env),l=o.join(a);return[s+l+i]}if(o.length===0){let a=s+i;return a?[a]:[]}return o.length===1?[s+o[0]+i]:[s+o[0],...o.slice(1,-1),o[o.length-1]+i]}async function Dp(e,t,n){if(t.length<2)return null;let r=!1;for(let l of t)if(Ru(l)){r=!0;break}if(!r)return null;let s=Se(e.state.env),i=Ce(e.state.env),o=[];for(let l of t){let u=Ru(l);if(u&&l.type==="DoubleQuoted"){let c=await Rp(e,l,u,n);o.push(c)}else if(l.type==="DoubleQuoted"||l.type==="SingleQuoted"){let c=await n(e,l);o.push([c])}else if(l.type==="Literal")o.push([l.value]);else if(l.type==="ParameterExpansion"){let c=await n(e,l);if(i)o.push(c?[c]:[]);else{let f=ce(c,s,e.limits.maxArrayElements);o.push(f)}}else{let c=await n(e,l);if(i)o.push(c?[c]:[]);else{let f=ce(c,s,e.limits.maxArrayElements);o.push(f)}}}let a=[];for(let l of o)if(l.length!==0)if(a.length===0)Ne(a,l,e.limits.maxArrayElements,"word expansion");else{let u=a.length-1;a[u]=a[u]+l[0];for(let c=1;c<l.length;c++)a.push(l[c])}return a}async function Du(e,t){if(e.state.options.noglob)return{values:t,quoted:!1};let n=[];for(let r of t)if(xt(r,e.state.shoptOptions.extglob)){let s=await rs(e,r);Ne(n,s,e.limits.maxArrayElements,"glob expansion")}else n.push(r);return{values:n,quoted:!1}}async function rs(e,t){let n=new jt(e.fs,e.state.cwd,e.state.env,{globstar:e.state.shoptOptions.globstar,nullglob:e.state.shoptOptions.nullglob,failglob:e.state.shoptOptions.failglob,dotglob:e.state.shoptOptions.dotglob,extglob:e.state.shoptOptions.extglob,globskipdots:e.state.shoptOptions.globskipdots,maxGlobOperations:e.limits.maxGlobOperations,consumeOperation:()=>e.executionScope.consumeLimited("glob_operations",1,e.limits.maxGlobOperations,"glob expansion")}),r=await n.expand(t);if(r.length>0)return r;if(n.hasFailglob())throw new Lt(t);return n.hasNullglob()?[]:[t]}async function Ip(e,t,n,r,s,i){let o=n.some(a=>a.type==="Glob");if(!e.state.options.noglob&&o){let a=await i(e,t);if(xt(a,e.state.shoptOptions.extglob)){let u=await rs(e,a);if(u.length>0&&u[0]!==a)return{values:u,quoted:!1};if(u.length===0)return{values:[],quoted:!1}}let l=Di(r);if(!Ce(e.state.env)){let u=Se(e.state.env);return{values:ce(l,u,e.limits.maxArrayElements),quoted:!1}}return{values:[l],quoted:!1}}if(!s&&!e.state.options.noglob&&xt(r,e.state.shoptOptions.extglob)){let a=await i(e,t);if(xt(a,e.state.shoptOptions.extglob)){let l=await rs(e,a);if(l.length>0&&l[0]!==a)return{values:l,quoted:!1}}}if(r===""&&!s)return{values:[],quoted:!1};if(o&&!s){let a=Di(r);if(!Ce(e.state.env)){let l=Se(e.state.env);return{values:ce(a,l,e.limits.maxArrayElements),quoted:!1}}return{values:[a],quoted:!1}}return{values:[r],quoted:s}}function Oe(e,t,n){if(t.length>=e.limits.maxArrayElements)throw new C(`word splitting element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");t.push(n)}async function _u(e,t){let n=t.operation;if(!n||n.type!=="DefaultValue"&&n.type!=="AssignDefault"&&n.type!=="UseAlternative")return null;let r=n.word;if(!r||r.parts.length===0)return null;let s=await vt(e,t.parameter),o=await re(e,t.parameter,!1)==="",a=n.checkEmpty??!1,l;return n.type==="UseAlternative"?l=s&&!(a&&o):l=!s||a&&o,l?(n.type==="AssignDefault"&&Ii(t.parameter),r.parts):null}function Op(e){return e.type==="SingleQuoted"?!0:e.type==="DoubleQuoted"?e.parts.every(n=>n.type==="Literal"):!1}async function _p(e,t){if(t.type!=="ParameterExpansion")return null;let n=await _u(e,t);if(!n||n.length<=1)return null;let r=n.some(i=>Op(i)),s=n.some(i=>i.type==="Literal"||i.type==="ParameterExpansion"||i.type==="CommandSubstitution"||i.type==="ArithmeticExpansion");return r&&s?n:null}function Lp(e){return e.type==="DoubleQuoted"||e.type==="SingleQuoted"||e.type==="Literal"?!1:e.type==="Glob"?vi(e.pattern):!(!(e.type==="ParameterExpansion"||e.type==="CommandSubstitution"||e.type==="ArithmeticExpansion")||e.type==="ParameterExpansion"&&Il(e))}async function Lu(e,t,n,r,s){if(e.coverage?.hit("bash:expansion:word_split"),t.length===1&&t[0].type==="ParameterExpansion"){let d=t[0],p=await _u(e,d);if(p&&p.length>0&&p.length>1&&p.some(m=>m.type==="DoubleQuoted"||m.type==="SingleQuoted")&&p.some(m=>m.type==="Literal"||m.type==="ParameterExpansion"||m.type==="CommandSubstitution"||m.type==="ArithmeticExpansion"))return Ou(e,p,n,r,s)}let i=[],o=!1;for(let d of t){let p=Lp(d),h=d.type==="DoubleQuoted"||d.type==="SingleQuoted",m=p?await _p(e,d):null,y=await s(e,d);i.push({value:y,isSplittable:p,isQuoted:h,mixedDefaultParts:m??void 0}),p&&(o=!0)}if(!o){let d=i.map(p=>p.value).join("");return d?[d]:[]}let a=[],l="",u=!1,c=!1,f=!1;for(let d of i)if(!d.isSplittable)c?d.isQuoted&&d.value===""?(l!==""&&Oe(e,a,l),Oe(e,a,""),u=!0,l="",c=!1,f=!0):d.value!==""?(l!==""&&Oe(e,a,l),l=d.value,c=!1,f=!1):(l+=d.value,f=!1):(l+=d.value,f=d.isQuoted&&d.value==="");else if(d.mixedDefaultParts){let p=await Ou(e,d.mixedDefaultParts,n,r,s);if(p.length!==0)if(p.length===1)l+=p[0],u=!0;else{l+=p[0],Oe(e,a,l),u=!0;for(let h=1;h<p.length-1;h++)Oe(e,a,p[h]);l=p[p.length-1]}c=!1,f=!1}else{let{words:p,hadLeadingDelimiter:h,hadTrailingDelimiter:m}=Hr(d.value,n,e.limits.maxArrayElements);if(f&&h&&l===""&&(Oe(e,a,""),u=!0),p.length===0)m&&(c=!0);else if(p.length===1)l+=p[0],u=!0,c=m;else{l+=p[0],Oe(e,a,l),u=!0;for(let y=1;y<p.length-1;y++)Oe(e,a,p[y]);l=p[p.length-1],c=m}f=!1}return l!==""?Oe(e,a,l):a.length===0&&u&&Oe(e,a,""),a}function Tp(e,t){return e.length>0&&t.includes(e[0])}async function Ou(e,t,n,r,s){let i=[];for(let c of t){let d=!(c.type==="DoubleQuoted"||c.type==="SingleQuoted"),p=await s(e,c);i.push({value:p,isSplittable:d})}let o=[],a="",l=!1,u=!1;for(let c of i)if(!c.isSplittable)u&&c.value!==""?(a!==""&&Oe(e,o,a),a=c.value,u=!1):a+=c.value;else{Tp(c.value,n)&&a!==""&&(Oe(e,o,a),a="",l=!0);let{words:d,hadTrailingDelimiter:p}=Hr(c.value,n,e.limits.maxArrayElements);if(d.length===0)p&&(u=!0);else if(d.length===1)a+=d[0],l=!0,u=p;else{a+=d[0],Oe(e,o,a),l=!0;for(let h=1;h<d.length-1;h++)Oe(e,o,d[h]);a=d[d.length-1],u=p}}return a!==""?Oe(e,o,a):o.length===0&&l&&Oe(e,o,""),o}function Tu(e){switch(e.type){case"Literal":return e.value;case"SingleQuoted":return e.value;case"Escaped":return e.value;default:return null}}function Fu(e){switch(e.type){case"SingleQuoted":case"Escaped":case"DoubleQuoted":return!0;case"Literal":return e.value==="";default:return!1}}var ss="/dev/fd",Bu=63,Fp=10,Mu=Bu-Fp+1,Mi=class extends bt{isLiveDescriptor;constructor(t){super(),this.isLiveDescriptor=t}assertLiveDescriptor(t,n){this.isLiveDescriptor(t)||this.refuse(t,n)}refuse(t,n){throw new Error(`EROFS: read-only file system, ${n} '${ss}${t}'`)}async writeFile(t,n,r){return this.assertLiveDescriptor(t,"write"),super.writeFile(t,n,r)}async appendFile(t,n,r){return this.assertLiveDescriptor(t,"append"),super.appendFile(t,n,r)}async rm(t,n){return this.assertLiveDescriptor(t,"rm"),super.rm(t,n)}async mkdir(t,n){this.refuse(t,"mkdir")}async cp(t,n){this.refuse(n,"cp")}async mv(t,n){this.refuse(n,"mv")}async symlink(t,n){this.refuse(n,"symlink")}async link(t,n){this.refuse(n,"link")}async chmod(t,n){this.refuse(t,"chmod")}async utimes(t,n,r){this.refuse(t,"utimes")}};function Mp(e){let t=new Mi(n=>Wu(e).some(r=>r.path===`${ss}${n}`));e.fs=new fn({base:e.fs,mounts:[{mountPoint:ss,filesystem:t}]}),e.state.processSubstitutionFsMounted=!0}async function Bp(e,t,n){try{await e.fs.writeFile(t,n,"binary");return}catch(r){if(e.state.processSubstitutionFsMounted)throw r;Mp(e)}await e.fs.writeFile(t,n,"binary")}async function Wp(e,t){try{await e.fs.rm(t,{force:!0})}catch{}}function Wu(e){let t=e.state.processSubstitutions;if(t)return t;let n=[];return e.state.processSubstitutions=n,n}async function Vu(e,t,n){let r=e.substitutionDepth??0,s=e.limits.maxSubstitutionDepth;if(r>=s)throw new C(`Process substitution nesting limit exceeded (${s})`,"substitution_depth");let i=e.substitutionDepth,o=new Map(e.state.env),a=nt(e.state.arrays),l=e.state.cwd,u=e.state.bashPid,c=e.state.suppressVerbose,f=e.state.groupStdin,d=e.state.lastExitCode,p=e.state.env.get("?"),h=e.state.lastSubstitutionExitCode;e.substitutionDepth=r+1,e.state.bashPid=e.state.nextVirtualPid++,e.state.suppressVerbose=!0,n!==void 0&&(e.state.groupStdin=n);let m;try{m=await e.executeScript(t)}catch(y){if(y instanceof C)throw y;if(y instanceof U)return{stdout:y.stdout,stderr:y.stderr,exitCode:y.exitCode};throw y}finally{e.substitutionDepth=i,e.state.env=o,e.state.arrays=a,e.state.cwd=l,e.state.bashPid=u,e.state.suppressVerbose=c,e.state.groupStdin=f,e.state.lastExitCode=d,e.state.lastSubstitutionExitCode=h,p!==void 0?e.state.env.set("?",p):e.state.env.delete("?")}return m}async function zu(e,t){let n=Wu(e);if(n.length>=Mu)throw new C(`Process substitution limit exceeded (${Mu} concurrent)`,"file_descriptors");let r="";if(t.direction==="input"){let o=await Vu(e,t.body,void 0);if(o.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+o.stderr),r=_t(o),r.length>e.limits.maxStringLength)throw new C(`process substitution: string length limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length")}let s=Bu-n.length,i=`${ss}/${s}`;n.push({fd:s,path:i,direction:t.direction,body:t.body});try{await Bp(e,i,r)}catch(o){throw n.pop(),o}return i}function qu(e){return e.state.processSubstitutions?.length??0}var Vp={stdout:"",stderr:""};async function Bi(e,t){let n=e.state.processSubstitutions;if(!n||n.length<=t)return Vp;let r="",s="";for(;n.length>t;){let i=n[n.length-1],o="";if(i.direction==="output")try{o=await xn(e.fs,i.path)}catch{}if(await Wp(e,i.path),n.pop(),i.direction==="output"){let a=await Vu(e,i.body,o);r+=_t(a),s+=a.stderr}}return{stdout:r,stderr:s}}function Xt(e,t,n){if(e.length>t)throw new C(`${n}: string length limit exceeded (${t} bytes)`,"string_length")}async function yt(e,t,n=!1){let r=[],s=0;for(let i of t){let o=await Ye(e,i,n);if(s+=W(o),s>e.limits.maxStringLength)throw new C(`parameter word string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");r.push(o)}return r.join("")}function zp(e){return Fu(e)}function ju(e){if(e.parts.length===0)return!0;for(let t of e.parts)if(!zp(t))return!1;return!0}function qp(e,t,n=!1){let r=Tu(t);if(r!==null)return r;switch(t.type){case"TildeExpansion":return n?t.user===null?"~":`~${t.user}`:(e.coverage?.hit("bash:expansion:tilde"),t.user===null?e.state.env.get("HOME")??"/home/user":t.user==="root"?"/root":`~${t.user}`);case"Glob":return _i(e,t.pattern);default:return null}}async function ne(e,t){return Vi(e,t)}async function Gu(e,t){let n=[];for(let r of t.parts)if(r.type==="Escaped")n.push(Tn(r.value));else if(r.type==="SingleQuoted")n.push(r.value);else if(r.type==="DoubleQuoted"){let s=await yt(e,r.parts);n.push(s)}else if(r.type==="TildeExpansion"){let s=await Ye(e,r);n.push(Tn(s))}else n.push(await Ye(e,r));return n.join("")}async function Hu(e,t){let n=[];for(let r of t.parts)if(r.type==="Escaped"){let s=r.value;"()|*?[]".includes(s)?n.push(`\\${s}`):n.push(s)}else if(r.type==="SingleQuoted")n.push(Xe(r.value));else if(r.type==="DoubleQuoted"){let s=await yt(e,r.parts);n.push(Xe(s))}else n.push(await Ye(e,r));return n.join("")}async function Zu(e,t){let n=[];for(let r of t.parts)if(r.type==="SingleQuoted")n.push(Xe(r.value));else if(r.type==="Escaped"){let s=r.value;"*?[]\\()|".includes(s)?n.push(`\\${s}`):n.push(s)}else if(r.type==="DoubleQuoted"){let s=await yt(e,r.parts);n.push(Xe(s))}else r.type==="Glob"?tu(r.pattern)?n.push(await ru(e,r.pattern)):n.push(_i(e,r.pattern)):r.type==="Literal"?n.push(r.value):n.push(await Ye(e,r));return n.join("")}function os(e){for(let t of e)if(t.type==="BraceExpansion"||t.type==="DoubleQuoted"&&os(t.parts))return!0;return!1}var Uu=1e5;async function Qu(e,t,n={count:0}){let r=()=>{n.count++,e.executionScope.consumeLimited("brace_operations",1,Math.min(Uu,e.limits.maxBraceExpansionResults),"brace expansion")},s=(o,a)=>{if(o.length>=e.limits.maxBraceExpansionResults)throw new C(`brace expansion result limit exceeded (${e.limits.maxBraceExpansionResults})`,"array_elements");r(),o.push(a)},i=[[]];for(let o of t)if(o.type==="BraceExpansion"){let a=[],l=!1,u="";for(let d of o.items)if(d.type==="Range"){let p=Ri(d.start,d.end,d.step,d.startStr,d.endStr,{maxResults:e.limits.maxBraceExpansionResults,maxStringBytes:e.limits.maxStringLength});if(p.expanded)for(let h of p.expanded)s(a,h);else{l=!0,u=p.literal;break}}else{let p=await Qu(e,d.word.parts,n);for(let h of p){let m=[];for(let y of h)typeof y=="string"?m.push(y):m.push(await Ye(e,y));s(a,m.join(""))}}if(l){for(let d of i)r(),d.push(u);continue}if(i.length*a.length>e.limits.maxBraceExpansionResults||n.count>Uu)throw new C(`brace expansion result limit exceeded (${e.limits.maxBraceExpansionResults})`,"array_elements");let f=[];for(let d of i)for(let p of a){if(f.length>=e.limits.maxBraceExpansionResults)throw new C(`brace expansion result limit exceeded (${e.limits.maxBraceExpansionResults})`,"array_elements");r(),f.push([...d,p])}i=f}else for(let a of i)r(),a.push(o);return i}async function Ku(e,t){let n=t.parts;if(!os(n))return[await ne(e,t)];let r=await Qu(e,n),s=[];for(let i of r){let o=[];for(let a of i)typeof a=="string"?o.push(a):o.push(await Ye(e,a));s.push(Li(e,o.join("")))}return s}function Up(){return{expandWordAsync:Vi,expandWordForGlobbing:Zu,expandWordWithBracesAsync:Ku,expandWordPartsAsync:yt,expandPart:Ye,expandParameterAsync:is,hasBraceExpansion:os,evaluateArithmetic:X,buildIfsCharClassPattern:Ol,smartWordSplit:Lu}}async function gt(e,t){return Iu(e,t,Up())}function jp(e){for(let t of e){if(t.type==="ParameterExpansion")return t.parameter;if(t.type==="Literal")return t.value}return""}function Wi(e,t){if(Number.parseInt(e.state.env.get("#")||"0",10)<2)return!1;function r(s){for(let i of s)if(i.type==="DoubleQuoted"){for(let o of i.parts)if(o.type==="ParameterExpansion"&&o.parameter==="@"&&!o.operation)return!0}return!1}return r(t.parts)}async function Xu(e,t){if(Wi(e,t))return{error:`bash: $@: ambiguous redirect
113
+ `};let n=t.parts,{hasQuoted:r}=lr(n);if(os(n)&&(await Ku(e,t)).length>1)return{error:`bash: ${n.map(p=>p.type==="Literal"?p.value:p.type==="BraceExpansion"?`{${p.items.map(m=>{if(m.type==="Range"){let y=m.step?`..${m.step}`:"";return`${m.startStr??m.start}..${m.endStr??m.end}${y}`}return m.word.parts.map(y=>y.type==="Literal"?y.value:"").join("")}).join(",")}}`:"").join("")}: ambiguous redirect
114
+ `};let s=await Vi(e,t),{hasParamExpansion:i,hasCommandSub:o}=lr(n);if((i||o)&&!r&&!Ce(e.state.env)){let f=Se(e.state.env);if(ce(s,f,e.limits.maxArrayElements).length>1)return{error:`bash: $${jp(n)}: ambiguous redirect
115
+ `}}if(r||e.state.options.noglob||n.some(f=>f.type==="ProcessSubstitution"))return{target:s};let l=await Zu(e,t);if(!xt(l,e.state.shoptOptions.extglob))return{target:s};let u=new jt(e.fs,e.state.cwd,e.state.env,{globstar:e.state.shoptOptions.globstar,nullglob:e.state.shoptOptions.nullglob,failglob:e.state.shoptOptions.failglob,dotglob:e.state.shoptOptions.dotglob,extglob:e.state.shoptOptions.extglob,globskipdots:e.state.shoptOptions.globskipdots,maxGlobOperations:e.limits.maxGlobOperations,consumeOperation:()=>e.executionScope.consumeLimited("glob_operations",1,e.limits.maxGlobOperations,"glob expansion")}),c=await u.expand(l);return c.length===0?u.hasFailglob()?{error:`bash: no match: ${s}
116
116
  `}:{target:s}:c.length===1?{target:c[0]}:{error:`bash: ${s}: ambiguous redirect
117
- `}}async function Bi(e,t){let n=t.parts,r=n.length;if(r===1){let o=await Ye(e,n[0]);return Xt(o,e.limits.maxStringLength,"word expansion"),o}let s=[];for(let o=0;o<r;o++)s.push(await Ye(e,n[o]));let i=s.join("");return Xt(i,e.limits.maxStringLength,"word expansion"),i}async function Ye(e,t,n=!1){if(t.type==="ParameterExpansion")return ts(e,t,n);let r=Fp(e,t,n);if(r!==null)return r;switch(t.type){case"DoubleQuoted":{let s=[];for(let i of t.parts)s.push(await Ye(e,i,!0));return s.join("")}case"CommandSubstitution":{let s=Tl(t.body);if(s)try{let p=await ne(e,s.target),h=p.startsWith("/")?p:`${e.state.cwd}/${p}`,m=await e.fs.readFile(h);Qt(e.state,0);let E=m.replace(/\n+$/,"");return Xt(E,e.limits.maxStringLength,"command substitution"),E}catch(p){if(p instanceof P)throw p;return Qt(e.state,1),""}let i=e.substitutionDepth??0,o=e.limits.maxSubstitutionDepth;if(i>=o)throw new P(`Command substitution nesting limit exceeded (${o})`,"substitution_depth");let a=e.substitutionDepth;e.substitutionDepth=i+1;let l=e.state.bashPid;e.state.bashPid=e.state.nextVirtualPid++;let u=new Map(e.state.env),c=rt(e.state.arrays),f=e.state.cwd,d=e.state.suppressVerbose;e.state.suppressVerbose=!0;try{let p=await e.executeScript(t.body),h=p.exitCode;e.state.env=u,e.state.arrays=c,e.state.cwd=f,e.state.suppressVerbose=d,Qt(e.state,h),p.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+p.stderr),e.state.bashPid=l,e.substitutionDepth=a;let m=p.stdout.replace(/\n+$/,"");return Xt(m,e.limits.maxStringLength,"command substitution"),m}catch(p){if(e.state.env=u,e.state.arrays=c,e.state.cwd=f,e.state.bashPid=l,e.substitutionDepth=a,e.state.suppressVerbose=d,p instanceof P)throw p;if(p instanceof q){Qt(e.state,p.exitCode),p.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+p.stderr);let h=p.stdout.replace(/\n+$/,"");return Xt(h,e.limits.maxStringLength,"command substitution"),h}throw p}}case"ProcessSubstitution":return Mu(e,t);case"ArithmeticExpansion":{let s=t.expression.originalText;if(s&&/\$[a-zA-Z_][a-zA-Z0-9_]*(?![{[(])/.test(s)){let o=await Ll(e,s),a=new j,l=te(a,o);return String(await X(e,l.expression,!0))}return String(await X(e,t.expression.expression,!0))}case"BraceExpansion":{let s=[];for(let i of t.items)if(i.type==="Range"){let o=Ci(i.start,i.end,i.step,i.startStr,i.endStr,{maxResults:e.limits.maxBraceExpansionResults,maxStringBytes:e.limits.maxStringLength});if(o.expanded)s.push(...o.expanded);else return o.literal}else s.push(await ne(e,i.word));return s.join(" ")}default:return""}}async function ts(e,t,n=!1){let{parameter:r}=t,{operation:s}=t,i=r.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(i){let[,d,p]=i;if(e.state.associativeArrays?.has(d)||p.includes("$(")||p.includes("`")||p.includes("${")){let m=await ki(e,p);r=`${d}[${m}]`}}else if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(r)&&le(e,r)){let d=Te(e,r);if(d&&d!==r){let p=d.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(p){let[,h,m]=p;if(e.state.associativeArrays?.has(h)||m.includes("$(")||m.includes("`")||m.includes("${")){let S=await ki(e,m);r=`${h}[${S}]`}}}}if(s?.type==="Length"&&/^[a-zA-Z_][a-zA-Z0-9_]*\[[@*]\]$/.test(r))return Di(e,r,"");let o=s&&(s.type==="DefaultValue"||s.type==="AssignDefault"||s.type==="UseAlternative"||s.type==="ErrorIfUnset"),a=await re(e,r,!o);if(!s)return a;let l=!await vt(e,r),{isEmpty:u,effectiveValue:c}=Kl(e,r,a,n),f={value:a,isUnset:l,isEmpty:u,effectiveValue:c,inDoubleQuotes:n};switch(s.type){case"DefaultValue":return Ml(e,s,f,gt);case"AssignDefault":return Bl(e,r,s,f,gt);case"ErrorIfUnset":return Wl(e,r,s,f,gt);case"UseAlternative":return Vl(e,s,f,gt);case"PatternRemoval":{let d=await zl(e,a,s,gt,Ye);return Xt(d,e.limits.maxStringLength,"pattern removal"),d}case"PatternReplacement":{let d=await ql(e,a,s,gt,Ye);return Xt(d,e.limits.maxStringLength,"pattern replacement"),d}case"Length":return Di(e,r,a);case"LengthSliceError":throw new Ze(r);case"BadSubstitution":throw new Ze(s.text);case"Substring":return Ul(e,r,a,s);case"CaseModification":{let d=await jl(e,a,s,gt,ts);return Xt(d,e.limits.maxStringLength,"case modification"),d}case"Transform":return Gl(e,r,a,l,s);case"Indirection":return Hl(e,r,a,l,s,ts,n);case"ArrayKeys":return Zl(e,s);case"VarNamePrefix":return Ql(e,s);default:return a}}function Qu(){return{visited:new Set,depth:0}}function Wp(e,t,n){switch(n){case"+":return e+t;case"-":return e-t;case"*":return e*t;case"/":if(t===0)throw new oe("division by 0");return Math.trunc(e/t);case"%":if(t===0)throw new oe("division by 0");return e%t;case"**":if(t<0)throw new oe("exponent less than 0");return e**t;case"<<":return e<<t;case">>":return e>>t;case"<":return e<t?1:0;case"<=":return e<=t?1:0;case">":return e>t?1:0;case">=":return e>=t?1:0;case"==":return e===t?1:0;case"!=":return e!==t?1:0;case"&":return e&t;case"|":return e|t;case"^":return e^t;case",":return t;default:return 0}}function Zu(e,t,n){switch(n){case"=":return t;case"+=":return e+t;case"-=":return e-t;case"*=":return e*t;case"/=":return t!==0?Math.trunc(e/t):0;case"%=":return t!==0?e%t:0;case"<<=":return e<<t;case">>=":return e>>t;case"&=":return e&t;case"|=":return e|t;case"^=":return e^t;default:return t}}function Vp(e,t){switch(t){case"-":return-e;case"+":return+e;case"!":return e===0?1:0;case"~":return~e;default:return e}}async function zp(e,t){let n=e.state.env.get(t);if(n!==void 0)return n;let r=ie(e,t,0);return r!==void 0?r:await re(e,t)}async function qp(e,t,n){if(!t)return 0;let r=Number.parseInt(t,10);if(!Number.isNaN(r)&&/^-?\d+$/.test(t.trim()))return r;let s=t.trim();if(!s)return 0;let i=new j,{expr:o,pos:a}=_n(i,s,0);if(a<s.length){let l=s.slice(a).trim(),u=l.split(/\s+/)[0]||l;throw new oe(`syntax error in expression (error token is "${u}")`,"","")}return await Mn(e,o,!1,n)}async function rs(e,t,n,r){if(r.depth>100)throw new oe("maximum variable indirection depth exceeded");if(r.visited.has(t))throw new oe(`arithmetic variable cycle detected at ${t}`);r.visited.add(t),r.depth++;try{return await qp(e,n,r)}finally{r.depth--,r.visited.delete(t)}}async function Wi(e,t,n){if(n.depth>100)throw new oe("maximum variable indirection depth exceeded");if(n.visited.has(t))throw new oe(`arithmetic variable cycle detected at ${t}`);n.visited.add(t),n.depth++;try{let r=await zp(e,t);if(!r)return 0;let s=Number.parseInt(r,10);if(!Number.isNaN(s)&&/^-?\d+$/.test(r.trim()))return s;let i=r.trim();if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(i))return await Wi(e,i,n);let o=new j,{expr:a,pos:l}=_n(o,i,0);if(l<i.length){let u=i.slice(l).trim(),c=u.split(/\s+/)[0]||u;throw new oe(`${i}: syntax error in expression (error token is "${c}")`)}return await Mn(e,a,!1,n)}finally{n.depth--,n.visited.delete(t)}}async function ss(e,t){if(t.startsWith("#")){let f=t.slice(1),d=f.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(d){let h=d[1],m=G(e,h);return String(m.length)}let p=e.state.env.get(f)||"";return String(p.length)}if(t.startsWith("!")){let f=t.slice(1),d=e.state.env.get(f)||"";return e.state.env.get(d)||""}let n=[":-",":=",":?",":+","-","=","?","+"],r=-1,s="";for(let f of n){let d=t.indexOf(f);d>0&&(r===-1||d<r)&&(r=d,s=f)}if(r===-1)return await re(e,t);let i=t.slice(0,r),o=t.slice(r+s.length),a=e.state.env.get(i),l=a===void 0,u=a==="",c=s.startsWith(":");switch(s){case":-":case"-":return l||c&&u?o:a||"";case":=":case"=":return l||c&&u?(e.state.env.set(i,o),o):a||"";case":+":case"+":return!(l||c&&u)?o:"";case":?":case"?":{if(l||c&&u)throw new Error(o||`${i}: parameter null or not set`);return a||""}default:return a||""}}async function X(e,t,n=!1){return Mn(e,t,n,Qu())}async function Mn(e,t,n,r){let s=(i,o=n)=>Mn(e,i,o,r);switch(t.type){case"ArithNumber":if(Number.isNaN(t.value))throw new oe("value too great for base");return t.value;case"ArithVariable":return await Wi(e,t.name,r);case"ArithSpecialVar":{let o=(await re(e,t.name)).trim();if(!o)return 0;let a=Number.parseInt(o,10);if(!Number.isNaN(a)&&/^-?\d+$/.test(o))return a;let l=new j,{expr:u}=_n(l,o,0);return await s(u)}case"ArithNested":return await s(t.expression);case"ArithCommandSubst":{if(e.execFn){let i=await e.execFn(t.command,{signal:e.state.signal});i.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+i.stderr);let o=i.stdout.trim();return Number.parseInt(o,10)||0}return 0}case"ArithBracedExpansion":{let i=await ss(e,t.content);return Number.parseInt(i,10)||0}case"ArithDynamicBase":{let i=await ss(e,t.baseExpr),o=Number.parseInt(i,10);if(o<2||o>64)return 0;let a=`${o}#${t.value}`;return rr(a)}case"ArithDynamicNumber":{let o=await ss(e,t.prefix)+t.suffix;return rr(o)}case"ArithArrayElement":{let i=e.state.associativeArrays?.has(t.array),o=async a=>{let l=ie(e,t.array,a);return l!==void 0?await rs(e,`${t.array}[${a}]`,l,r):0};if(t.stringKey!==void 0)return await o(t.stringKey);if(i&&t.index?.type==="ArithVariable"&&!t.index.hasDollarPrefix)return await o(t.index.name);if(i&&t.index?.type==="ArithVariable"&&t.index.hasDollarPrefix){let a=await re(e,t.index.name);return await o(a)}if(t.index){let a=await s(t.index);if(a<0){let c=G(e,t.array),f=e.state.currentLine;if(c.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${f}: ${t.array}: bad array subscript
117
+ `}}async function Vi(e,t){let n=t.parts,r=n.length;if(r===1){let o=await Ye(e,n[0]);return Xt(o,e.limits.maxStringLength,"word expansion"),o}let s=[];for(let o=0;o<r;o++)s.push(await Ye(e,n[o]));let i=s.join("");return Xt(i,e.limits.maxStringLength,"word expansion"),i}async function Ye(e,t,n=!1){if(t.type==="ParameterExpansion")return is(e,t,n);let r=qp(e,t,n);if(r!==null)return r;switch(t.type){case"DoubleQuoted":{let s=[];for(let i of t.parts)s.push(await Ye(e,i,!0));return s.join("")}case"CommandSubstitution":{let s=Wl(t.body);if(s)try{let p=await ne(e,s.target),h=p.startsWith("/")?p:`${e.state.cwd}/${p}`,m=await e.fs.readFile(h);Qt(e.state,0);let y=m.replace(/\n+$/,"");return Xt(y,e.limits.maxStringLength,"command substitution"),y}catch(p){if(p instanceof C)throw p;return Qt(e.state,1),""}let i=e.substitutionDepth??0,o=e.limits.maxSubstitutionDepth;if(i>=o)throw new C(`Command substitution nesting limit exceeded (${o})`,"substitution_depth");let a=e.substitutionDepth;e.substitutionDepth=i+1;let l=e.state.bashPid;e.state.bashPid=e.state.nextVirtualPid++;let u=new Map(e.state.env),c=nt(e.state.arrays),f=e.state.cwd,d=e.state.suppressVerbose;e.state.suppressVerbose=!0;try{let p=await e.executeScript(t.body),h=p.exitCode;e.state.env=u,e.state.arrays=c,e.state.cwd=f,e.state.suppressVerbose=d,Qt(e.state,h),p.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+p.stderr),e.state.bashPid=l,e.substitutionDepth=a;let m=p.stdout.replace(/\n+$/,"");return Xt(m,e.limits.maxStringLength,"command substitution"),m}catch(p){if(e.state.env=u,e.state.arrays=c,e.state.cwd=f,e.state.bashPid=l,e.substitutionDepth=a,e.state.suppressVerbose=d,p instanceof C)throw p;if(p instanceof U){Qt(e.state,p.exitCode),p.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+p.stderr);let h=p.stdout.replace(/\n+$/,"");return Xt(h,e.limits.maxStringLength,"command substitution"),h}throw p}}case"ProcessSubstitution":return zu(e,t);case"ArithmeticExpansion":{let s=t.expression.originalText;if(s&&/\$[a-zA-Z_][a-zA-Z0-9_]*(?![{[(])/.test(s)){let o=await Bl(e,s),a=new G,l=te(a,o);return String(await X(e,l.expression,!0))}return String(await X(e,t.expression.expression,!0))}case"BraceExpansion":{let s=[];for(let i of t.items)if(i.type==="Range"){let o=Ri(i.start,i.end,i.step,i.startStr,i.endStr,{maxResults:e.limits.maxBraceExpansionResults,maxStringBytes:e.limits.maxStringLength});if(o.expanded)s.push(...o.expanded);else return o.literal}else s.push(await ne(e,i.word));return s.join(" ")}default:return""}}async function is(e,t,n=!1){let{parameter:r}=t,{operation:s}=t,i=r.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(i){let[,d,p]=i;if(e.state.associativeArrays?.has(d)||p.includes("$(")||p.includes("`")||p.includes("${")){let m=await Ci(e,p);r=`${d}[${m}]`}}else if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(r)&&le(e,r)){let d=Te(e,r);if(d&&d!==r){let p=d.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(p){let[,h,m]=p;if(e.state.associativeArrays?.has(h)||m.includes("$(")||m.includes("`")||m.includes("${")){let b=await Ci(e,m);r=`${h}[${b}]`}}}}if(s?.type==="Length"&&/^[a-zA-Z_][a-zA-Z0-9_]*\[[@*]\]$/.test(r))return Oi(e,r,"");let o=s&&(s.type==="DefaultValue"||s.type==="AssignDefault"||s.type==="UseAlternative"||s.type==="ErrorIfUnset"),a=await re(e,r,!o);if(!s)return a;let l=!await vt(e,r),{isEmpty:u,effectiveValue:c}=eu(e,r,a,n),f={value:a,isUnset:l,isEmpty:u,effectiveValue:c,inDoubleQuotes:n};switch(s.type){case"DefaultValue":return zl(e,s,f,yt);case"AssignDefault":return ql(e,r,s,f,yt);case"ErrorIfUnset":return Ul(e,r,s,f,yt);case"UseAlternative":return jl(e,s,f,yt);case"PatternRemoval":{let d=await Gl(e,a,s,yt,Ye);return Xt(d,e.limits.maxStringLength,"pattern removal"),d}case"PatternReplacement":{let d=await Hl(e,a,s,yt,Ye);return Xt(d,e.limits.maxStringLength,"pattern replacement"),d}case"Length":return Oi(e,r,a);case"LengthSliceError":throw new Ze(r);case"BadSubstitution":throw new Ze(s.text);case"Substring":return Zl(e,r,a,s);case"CaseModification":{let d=await Ql(e,a,s,yt,is);return Xt(d,e.limits.maxStringLength,"case modification"),d}case"Transform":return Kl(e,r,a,l,s);case"Indirection":return Xl(e,r,a,l,s,is,n);case"ArrayKeys":return Yl(e,s);case"VarNamePrefix":return Jl(e,s);default:return a}}function Ju(){return{visited:new Set,depth:0}}function Gp(e,t,n){switch(n){case"+":return e+t;case"-":return e-t;case"*":return e*t;case"/":if(t===0)throw new oe("division by 0");return Math.trunc(e/t);case"%":if(t===0)throw new oe("division by 0");return e%t;case"**":if(t<0)throw new oe("exponent less than 0");return e**t;case"<<":return e<<t;case">>":return e>>t;case"<":return e<t?1:0;case"<=":return e<=t?1:0;case">":return e>t?1:0;case">=":return e>=t?1:0;case"==":return e===t?1:0;case"!=":return e!==t?1:0;case"&":return e&t;case"|":return e|t;case"^":return e^t;case",":return t;default:return 0}}function Yu(e,t,n){switch(n){case"=":return t;case"+=":return e+t;case"-=":return e-t;case"*=":return e*t;case"/=":return t!==0?Math.trunc(e/t):0;case"%=":return t!==0?e%t:0;case"<<=":return e<<t;case">>=":return e>>t;case"&=":return e&t;case"|=":return e|t;case"^=":return e^t;default:return t}}function Hp(e,t){switch(t){case"-":return-e;case"+":return+e;case"!":return e===0?1:0;case"~":return~e;default:return e}}async function Zp(e,t){let n=e.state.env.get(t);if(n!==void 0)return n;let r=ie(e,t,0);return r!==void 0?r:await re(e,t)}async function Qp(e,t,n){if(!t)return 0;let r=Number.parseInt(t,10);if(!Number.isNaN(r)&&/^-?\d+$/.test(t.trim()))return r;let s=t.trim();if(!s)return 0;let i=new G,{expr:o,pos:a}=Ln(i,s,0);if(a<s.length){let l=s.slice(a).trim(),u=l.split(/\s+/)[0]||l;throw new oe(`syntax error in expression (error token is "${u}")`,"","")}return await Bn(e,o,!1,n)}async function as(e,t,n,r){if(r.depth>100)throw new oe("maximum variable indirection depth exceeded");if(r.visited.has(t))throw new oe(`arithmetic variable cycle detected at ${t}`);r.visited.add(t),r.depth++;try{return await Qp(e,n,r)}finally{r.depth--,r.visited.delete(t)}}async function zi(e,t,n){if(n.depth>100)throw new oe("maximum variable indirection depth exceeded");if(n.visited.has(t))throw new oe(`arithmetic variable cycle detected at ${t}`);n.visited.add(t),n.depth++;try{let r=await Zp(e,t);if(!r)return 0;let s=Number.parseInt(r,10);if(!Number.isNaN(s)&&/^-?\d+$/.test(r.trim()))return s;let i=r.trim();if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(i))return await zi(e,i,n);let o=new G,{expr:a,pos:l}=Ln(o,i,0);if(l<i.length){let u=i.slice(l).trim(),c=u.split(/\s+/)[0]||u;throw new oe(`${i}: syntax error in expression (error token is "${c}")`)}return await Bn(e,a,!1,n)}finally{n.depth--,n.visited.delete(t)}}async function ls(e,t){if(t.startsWith("#")){let f=t.slice(1),d=f.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[[@*]\]$/);if(d){let h=d[1],m=H(e,h);return String(m.length)}let p=e.state.env.get(f)||"";return String(p.length)}if(t.startsWith("!")){let f=t.slice(1),d=e.state.env.get(f)||"";return e.state.env.get(d)||""}let n=[":-",":=",":?",":+","-","=","?","+"],r=-1,s="";for(let f of n){let d=t.indexOf(f);d>0&&(r===-1||d<r)&&(r=d,s=f)}if(r===-1)return await re(e,t);let i=t.slice(0,r),o=t.slice(r+s.length),a=e.state.env.get(i),l=a===void 0,u=a==="",c=s.startsWith(":");switch(s){case":-":case"-":return l||c&&u?o:a||"";case":=":case"=":return l||c&&u?(e.state.env.set(i,o),o):a||"";case":+":case"+":return!(l||c&&u)?o:"";case":?":case"?":{if(l||c&&u)throw new Error(o||`${i}: parameter null or not set`);return a||""}default:return a||""}}async function X(e,t,n=!1){return Bn(e,t,n,Ju())}async function Bn(e,t,n,r){let s=(i,o=n)=>Bn(e,i,o,r);switch(t.type){case"ArithNumber":if(Number.isNaN(t.value))throw new oe("value too great for base");return t.value;case"ArithVariable":return await zi(e,t.name,r);case"ArithSpecialVar":{let o=(await re(e,t.name)).trim();if(!o)return 0;let a=Number.parseInt(o,10);if(!Number.isNaN(a)&&/^-?\d+$/.test(o))return a;let l=new G,{expr:u}=Ln(l,o,0);return await s(u)}case"ArithNested":return await s(t.expression);case"ArithCommandSubst":{if(e.execFn){let i=await e.execFn(t.command,{signal:e.state.signal});i.stderr&&(e.state.expansionStderr=(e.state.expansionStderr||"")+i.stderr);let o=i.stdout.trim();return Number.parseInt(o,10)||0}return 0}case"ArithBracedExpansion":{let i=await ls(e,t.content);return Number.parseInt(i,10)||0}case"ArithDynamicBase":{let i=await ls(e,t.baseExpr),o=Number.parseInt(i,10);if(o<2||o>64)return 0;let a=`${o}#${t.value}`;return sr(a)}case"ArithDynamicNumber":{let o=await ls(e,t.prefix)+t.suffix;return sr(o)}case"ArithArrayElement":{let i=e.state.associativeArrays?.has(t.array),o=async a=>{let l=ie(e,t.array,a);return l!==void 0?await as(e,`${t.array}[${a}]`,l,r):0};if(t.stringKey!==void 0)return await o(t.stringKey);if(i&&t.index?.type==="ArithVariable"&&!t.index.hasDollarPrefix)return await o(t.index.name);if(i&&t.index?.type==="ArithVariable"&&t.index.hasDollarPrefix){let a=await re(e,t.index.name);return await o(a)}if(t.index){let a=await s(t.index);if(a<0){let c=H(e,t.array),f=e.state.currentLine;if(c.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${f}: ${t.array}: bad array subscript
118
118
  `,0;let p=Math.max(...c.map(([h])=>typeof h=="number"?h:0))+1+a;if(p<0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${f}: ${t.array}: bad array subscript
119
- `,0;a=p}let l=`${t.array}[${a}]`,u=ie(e,t.array,a);if(u!==void 0)return rs(e,l,u,r);if(a===0){let c=e.state.env.get(t.array);if(c!==void 0)return rs(e,t.array,c,r)}if(e.state.options.nounset&&!(e.state.env.has(t.array)||ke(e,t.array)))throw new Be(`${t.array}[${a}]`);return 0}return 0}case"ArithDoubleSubscript":throw new oe("double subscript","","");case"ArithNumberSubscript":throw new oe(`${t.number}${t.errorToken}: syntax error: invalid arithmetic operator (error token is "${t.errorToken}")`);case"ArithSyntaxError":throw new oe(t.message,"","",!0);case"ArithSingleQuote":{if(n)throw new oe(`syntax error: operand expected (error token is "'${t.content}'")`);return t.value}case"ArithBinary":{if(t.operator==="||")return await s(t.left)||await s(t.right)?1:0;if(t.operator==="&&")return await s(t.left)&&await s(t.right)?1:0;let i=await s(t.left),o=await s(t.right);return Wp(i,o,t.operator)}case"ArithUnary":{let i=await s(t.operand);if(t.operator==="++"||t.operator==="--"){if(t.operand.type==="ArithVariable"){let o=t.operand.name,a=Number.parseInt(await re(e,o),10)||0,l=t.operator==="++"?a+1:a-1;return e.state.env.set(o,String(l)),t.prefix?l:a}if(t.operand.type==="ArithArrayElement"){let o=t.operand.array,a=e.state.associativeArrays?.has(o),l;if(t.operand.stringKey!==void 0)l=t.operand.stringKey;else if(a&&t.operand.index?.type==="ArithVariable"&&!t.operand.index.hasDollarPrefix)l=t.operand.index.name;else if(a&&t.operand.index?.type==="ArithVariable"&&t.operand.index.hasDollarPrefix)l=await re(e,t.operand.index.name);else if(t.operand.index){let f=await s(t.operand.index);l=String(f)}else return i;let u=Number.parseInt(ie(e,o,l)||"0",10)||0,c=t.operator==="++"?u+1:u-1;return U(e,o,l,String(c),a?"associative":"indexed"),t.prefix?c:u}if(t.operand.type==="ArithConcat"){let o="";for(let a of t.operand.parts)o+=await Fn(e,a,n,r);if(o&&/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(o)){let a=Number.parseInt(e.state.env.get(o)||"0",10)||0,l=t.operator==="++"?a+1:a-1;return e.state.env.set(o,String(l)),t.prefix?l:a}}if(t.operand.type==="ArithDynamicElement"){let o="";if(t.operand.nameExpr.type==="ArithConcat")for(let a of t.operand.nameExpr.parts)o+=await Fn(e,a,n,r);else t.operand.nameExpr.type==="ArithVariable"&&(o=t.operand.nameExpr.hasDollarPrefix?await re(e,t.operand.nameExpr.name):t.operand.nameExpr.name);if(o&&/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(o)){let a=await s(t.operand.subscript),l=Number.parseInt(ie(e,o,a)||"0",10)||0,u=t.operator==="++"?l+1:l-1;return U(e,o,a,String(u)),t.prefix?u:l}}return i}return Vp(i,t.operator)}case"ArithTernary":return await s(t.condition)?await s(t.consequent):await s(t.alternate);case"ArithAssignment":{let i=t.variable,o=i,a;if(t.stringKey!==void 0)a=t.stringKey;else if(t.subscript){let d=e.state.associativeArrays?.has(i);if(d&&t.subscript.type==="ArithVariable"&&!t.subscript.hasDollarPrefix)a=t.subscript.name;else if(d&&t.subscript.type==="ArithVariable"&&t.subscript.hasDollarPrefix)a=await re(e,t.subscript.name)||"\\";else if(d){let p=await s(t.subscript);a=String(p)}else{let p=await s(t.subscript);if(p<0){let h=G(e,i);h.length>0&&(p=Math.max(...h.map(([E])=>typeof E=="number"?E:0))+1+p)}a=String(p)}}let l=a===void 0?e.state.env.get(o):ie(e,i,a),u=Number.parseInt(l||"0",10)||0,c=await s(t.value),f=Zu(u,c,t.operator);return a===void 0?e.state.env.set(o,String(f)):U(e,i,a,String(f),e.state.associativeArrays?.has(i)?"associative":"indexed"),f}case"ArithGroup":return await s(t.expression);case"ArithConcat":{let i="";for(let o of t.parts)i+=await Fn(e,o,n,r);return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(i)?await Wi(e,i,r):Number.parseInt(i,10)||0}case"ArithDynamicAssignment":{let i="";if(t.target.type==="ArithConcat")for(let c of t.target.parts)i+=await Fn(e,c,n,r);else t.target.type==="ArithVariable"&&(i=t.target.hasDollarPrefix?await re(e,t.target.name):t.target.name);if(!i||!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(i))return 0;let o=i;if(t.subscript){let c=await s(t.subscript);o=`${i}_${c}`}let a=Number.parseInt(e.state.env.get(o)||"0",10)||0,l=await s(t.value),u=Zu(a,l,t.operator);return e.state.env.set(o,String(u)),u}case"ArithDynamicElement":{let i="";if(t.nameExpr.type==="ArithConcat")for(let u of t.nameExpr.parts)i+=await Fn(e,u,n,r);else t.nameExpr.type==="ArithVariable"&&(i=t.nameExpr.hasDollarPrefix?await re(e,t.nameExpr.name):t.nameExpr.name);if(!i||!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(i))return 0;let o=await s(t.subscript),a=`${i}_${o}`,l=e.state.env.get(a);return l!==void 0?rs(e,a,l,r):0}default:return 0}}async function Fn(e,t,n=!1,r=Qu()){switch(t.type){case"ArithNumber":return String(t.value);case"ArithSingleQuote":return String(await Mn(e,t,n,r));case"ArithVariable":return t.hasDollarPrefix?await re(e,t.name):t.name;case"ArithSpecialVar":return await re(e,t.name);case"ArithBracedExpansion":return await ss(e,t.content);case"ArithCommandSubst":return e.execFn?(await e.execFn(t.command,{signal:e.state.signal})).stdout.trim():"0";case"ArithConcat":{let s="";for(let i of t.parts)s+=await Fn(e,i,n,r);return s}default:return String(await Mn(e,t,n,r))}}async function Ku(e,t){let n="",r=0;for(let x of t.parts){let A=x.type==="Literal"?x.value:"\0",k=F(A);if(k>e.limits.maxStringLength-r)throw new P(`array assignment string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");n+=A,r+=k}let s=n.match(/^([a-zA-Z_][a-zA-Z0-9_]*)(\+?=)\(/);if(!s||!n.endsWith(")"))return null;let i=s[1],o=s[2],a=[],l=[],u=!1,c="",f=0,d=0,p=!1,h=!0,m=x=>{let A=F(x);if(A>e.limits.maxStringLength-d-f)throw new P(`array assignment string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");c+=x,f+=A},E=(x,A=!1)=>{if(a.length>=e.limits.maxArrayElements)throw new P(`array assignment element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");let k=F(x);if(k>e.limits.maxStringLength-d)throw new P(`array assignment string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");a.push(x),l.push(A),d+=k},S=()=>{E(c,h),c="",f=0,p=!1,h=!0};for(let x of t.parts)if(x.type==="Literal"){let A=x.value;if(!u){let k=A.indexOf("=(");k!==-1&&(u=!0,A=A.slice(k+2))}if(u){A.endsWith(")")&&(A=A.slice(0,-1));for(let k of A)/\s/.test(k)?(c||p)&&S():m(k)}}else if(u)if(x.type==="BraceExpansion")if(/^\[.+\]=/.test(c))m(In({type:"Word",parts:[x]}));else{(c||p)&&S();let k=await wt(e,{type:"Word",parts:[x]});for(let N of k.values)E(N)}else{(x.type==="SingleQuoted"||x.type==="DoubleQuoted"||x.type==="Escaped")&&(p=!0),h=!1;let A=await ne(e,{type:"Word",parts:[x]});m(A)}(c||p)&&S();let y=a.splice(0),g=l.splice(0);d=0;for(let x=0;x<y.length;x++){let A=y[x];if(!g[x]){E(A);continue}let k=A.match(/^(\[[^\]]+\]=)(.*)$/s);if(k){let N=Kt(e,k[2]);A=k[1]+N}if(A.includes("{")&&A.includes("}")){let N=new j().parseWordFromString(A,!1,!1);if(N.parts.some($=>$.type==="BraceExpansion")){let $=await wt(e,N);for(let C of $.values)E(C);continue}}E(A)}let b=[`${i}${o}(`],v=F(b[0]);for(let x=0;x<a.length;x++){let A=a[x],k,N=A.match(/^(\[[^\]]+\]=)(.*)$/s);if(N){let D=N[2].replace(/\\/g,"\\\\").replace(/"/g,'\\"');k=`${N[1]}"${D}"`}else A===""?k="''":/[\s"'\\$`!*?[\]{}|&;<>()]/.test(A)&&!A.startsWith("'")&&!A.startsWith('"')?k=`'${A.replace(/'/g,"'\\''")}'`:k=A;let $=`${x>0?" ":""}${k}`,C=F($);if(C+1>e.limits.maxStringLength-v)throw new P(`array assignment string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");b.push($),v+=C}return b.push(")"),b.join("")}async function Xu(e,t){let n=-1,r=-1,s=!1;for(let m=0;m<t.parts.length;m++){let E=t.parts[m];if(E.type==="Literal"){let S=E.value.indexOf("+=");if(S!==-1){let g=E.value.slice(0,S);if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(g)){n=m,r=S,s=!0;break}if(/^[a-zA-Z_][a-zA-Z0-9_]*\[[^\]]+\]$/.test(g)){n=m,r=S,s=!0;break}}let y=E.value.indexOf("=");if(y!==-1&&(y===0||E.value[y-1]!=="+")){let g=E.value.slice(0,y);if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(g)||/^[a-zA-Z_][a-zA-Z0-9_]*\[[^\]]+\]$/.test(g)){n=m,r=y;break}}}}if(n===-1)return null;let i=t.parts.slice(0,n),o=t.parts[n];if(o.type!=="Literal")return null;let a=s?2:1,l=o.value.slice(0,r),u=o.value.slice(r+a),c=t.parts.slice(n+1),f="";for(let m of i)f+=await ne(e,{type:"Word",parts:[m]});f+=l;let d={type:"Word",parts:u!==""?[{type:"Literal",value:u},...c]:c},p=d.parts.length>0?await ne(e,d):"";return`${f}${s?"+=":"="}${p}`}var Up=["tar","yq","xan","sqlite3","python3","python"];function Yu(e){return Up.includes(e)}var J=Object.freeze({stdout:"",stderr:"",exitCode:0,internalStdinConsumed:0});function Y(e=""){return{stdout:e,stderr:"",exitCode:0}}function _(e,t=1){return{stdout:"",stderr:e,exitCode:t}}function L(e,t,n){return{stdout:e,stderr:t,exitCode:n}}function ge(e){return{stdout:"",stderr:"",exitCode:e?0:1,internalStdinConsumed:0}}function Yt(e,t,n="",r=""){throw new P(e,t,n,r)}function Ju(e){let t=e.state.fileDescriptors;if(t&&t.size>=e.limits.maxFileDescriptors)throw new P(`too many open file descriptors (max ${e.limits.maxFileDescriptors})`,"file_descriptors")}function Vi(e,t){if(e.state.loopDepth===0){if(e.state.parentHasLoopContext)throw new Tt;return J}if(t.length>1)throw new q(1,"",`bash: break: too many arguments
120
- `);let n=1;if(t.length>0){let r=Number.parseInt(t[0],10);if(Number.isNaN(r)||r<1)throw new q(128,"",`bash: break: ${t[0]}: numeric argument required
121
- `);n=r}throw new Ge(n)}async function zi(e,t){let n,r=!1,s=!1,i=0;for(;i<t.length;)if(t[i]==="--"){i++;break}else if(t[i]==="-L")s=!1,i++;else if(t[i]==="-P")s=!0,i++;else if(t[i].startsWith("-")&&t[i]!=="-")i++;else break;let o=t.slice(i);if(o.length===0||o[0]==="~"?n=e.state.env.get("HOME")||"/":o[0]==="-"?(n=e.state.previousDir,r=!0):n=o[0],!n.startsWith("/")&&!n.startsWith("./")&&!n.startsWith("../")&&n!=="."&&n!==".."){let f=e.state.env.get("CDPATH");if(f){let d=f.split(":").filter(p=>p);for(let p of d){let h=p.startsWith("/")?`${p}/${n}`:`${e.state.cwd}/${p}/${n}`;try{if((await e.fs.stat(h)).isDirectory){n=h,r=!0;break}}catch{}}}}let l=(n.startsWith("/")?n:`${e.state.cwd}/${n}`).split("/").filter(f=>f&&f!=="."),u="";for(let f of l)if(f==="..")u=u.split("/").slice(0,-1).join("/")||"/";else{u=u?`${u}/${f}`:`/${f}`;try{if(!(await e.fs.stat(u)).isDirectory)return _(`bash: cd: ${n}: Not a directory
122
- `)}catch{return _(`bash: cd: ${n}: No such file or directory
123
- `)}}let c=u||"/";if(s)try{c=await e.fs.realpath(c)}catch{}return e.state.previousDir=e.state.cwd,e.state.cwd=c,e.state.env.set("PWD",e.state.cwd),e.state.env.set("OLDPWD",e.state.previousDir),Y(r?`${c}
124
- `:"")}function qi(e,t){return e.fs.resolvePath(e.state.cwd,t)}var jp=["-e","-a","-f","-d","-r","-w","-x","-s","-L","-h","-k","-g","-u","-G","-O","-b","-c","-p","-S","-t","-N"];function is(e){return jp.includes(e)}async function os(e,t,n){let r=qi(e,n);switch(t){case"-e":case"-a":return e.fs.exists(r);case"-f":return await e.fs.exists(r)?(await e.fs.stat(r)).isFile:!1;case"-d":return await e.fs.exists(r)?(await e.fs.stat(r)).isDirectory:!1;case"-r":return await e.fs.exists(r)?((await e.fs.stat(r)).mode&256)!==0:!1;case"-w":return await e.fs.exists(r)?((await e.fs.stat(r)).mode&128)!==0:!1;case"-x":return await e.fs.exists(r)?((await e.fs.stat(r)).mode&64)!==0:!1;case"-s":return await e.fs.exists(r)?(await e.fs.stat(r)).size>0:!1;case"-L":case"-h":try{return(await e.fs.lstat(r)).isSymbolicLink}catch{return!1}case"-k":return await e.fs.exists(r)?((await e.fs.stat(r)).mode&512)!==0:!1;case"-g":return await e.fs.exists(r)?((await e.fs.stat(r)).mode&1024)!==0:!1;case"-u":return await e.fs.exists(r)?((await e.fs.stat(r)).mode&2048)!==0:!1;case"-G":case"-O":return e.fs.exists(r);case"-b":return!1;case"-c":return["/dev/null","/dev/zero","/dev/random","/dev/urandom","/dev/tty","/dev/stdin","/dev/stdout","/dev/stderr"].includes(r);case"-p":return!1;case"-S":return!1;case"-t":return!1;case"-N":return e.fs.exists(r);default:return!1}}var Gp=["-nt","-ot","-ef"];function as(e){return Gp.includes(e)}async function ls(e,t,n,r){let s=qi(e,n),i=qi(e,r);switch(t){case"-nt":{let[o,a]=await Promise.all([e.fs.stat(s).catch(()=>null),e.fs.stat(i).catch(()=>null)]);return o!==null&&(a===null||o.mtime>a.mtime)}case"-ot":{let[o,a]=await Promise.all([e.fs.stat(s).catch(()=>null),e.fs.stat(i).catch(()=>null)]);return a!==null&&(o===null||o.mtime<a.mtime)}case"-ef":try{let[o,a]=await Promise.all([e.fs.realpath(s),e.fs.realpath(i)]);if(o===a)return!0;let[l,u]=await Promise.all([e.fs.stat(s),e.fs.stat(i)]);return l.dev!==void 0&&l.ino!==void 0&&u.dev!==void 0&&u.ino!==void 0?l.dev===u.dev&&l.ino===u.ino:l.identity&&u.identity?l.identity===u.identity:!1}catch{return!1}default:return!1}}var Hp=new Set(["-eq","-ne","-lt","-le","-gt","-ge"]);function us(e){return Hp.has(e)}function cs(e,t,n){switch(e){case"-eq":return t===n;case"-ne":return t!==n;case"-lt":return t<n;case"-le":return t<=n;case"-gt":return t>n;case"-ge":return t>=n}}function fr(e){return e==="="||e==="=="||e==="!="}function fs(e,t,n,r=!1,s=!1,i=!1,o=256){if(r){let l=Bn(t,n,s,i,o);return e==="!="?!l:l}if(s){let l=t.toLowerCase()===n.toLowerCase();return e==="!="?!l:l}let a=t===n;return e==="!="?!a:a}var Zp=new Set(["-z","-n"]);function ds(e){return Zp.has(e)}function ps(e,t){switch(e){case"-z":return t==="";case"-n":return t!==""}}async function hs(e,t){let n=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(n){let r=n[1],s=n[2];if(e.state.associativeArrays?.has(r)){let a=s;return(a.startsWith("'")&&a.endsWith("'")||a.startsWith('"')&&a.endsWith('"'))&&(a=a.slice(1,-1)),a=a.replace(/\$([a-zA-Z_][a-zA-Z0-9_]*)/g,(l,u)=>e.state.env.get(u)||""),zt(e,r,a)}let o;try{let a=new j,l=te(a,s);o=await X(e,l.expression)}catch{if(/^-?\d+$/.test(s))o=Number.parseInt(s,10);else{let a=e.state.env.get(s);o=a?Number.parseInt(a,10):0}}if(o<0){let a=be(e,r),l=e.state.currentLine;if(a.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${l}: ${r}: bad array subscript
119
+ `,0;a=p}let l=`${t.array}[${a}]`,u=ie(e,t.array,a);if(u!==void 0)return as(e,l,u,r);if(a===0){let c=e.state.env.get(t.array);if(c!==void 0)return as(e,t.array,c,r)}if(e.state.options.nounset&&!(e.state.env.has(t.array)||ke(e,t.array)))throw new Be(`${t.array}[${a}]`);return 0}return 0}case"ArithDoubleSubscript":throw new oe("double subscript","","");case"ArithNumberSubscript":throw new oe(`${t.number}${t.errorToken}: syntax error: invalid arithmetic operator (error token is "${t.errorToken}")`);case"ArithSyntaxError":throw new oe(t.message,"","",!0);case"ArithSingleQuote":{if(n)throw new oe(`syntax error: operand expected (error token is "'${t.content}'")`);return t.value}case"ArithBinary":{if(t.operator==="||")return await s(t.left)||await s(t.right)?1:0;if(t.operator==="&&")return await s(t.left)&&await s(t.right)?1:0;let i=await s(t.left),o=await s(t.right);return Gp(i,o,t.operator)}case"ArithUnary":{let i=await s(t.operand);if(t.operator==="++"||t.operator==="--"){if(t.operand.type==="ArithVariable"){let o=t.operand.name,a=Number.parseInt(await re(e,o),10)||0,l=t.operator==="++"?a+1:a-1;return e.state.env.set(o,String(l)),t.prefix?l:a}if(t.operand.type==="ArithArrayElement"){let o=t.operand.array,a=e.state.associativeArrays?.has(o),l;if(t.operand.stringKey!==void 0)l=t.operand.stringKey;else if(a&&t.operand.index?.type==="ArithVariable"&&!t.operand.index.hasDollarPrefix)l=t.operand.index.name;else if(a&&t.operand.index?.type==="ArithVariable"&&t.operand.index.hasDollarPrefix)l=await re(e,t.operand.index.name);else if(t.operand.index){let f=await s(t.operand.index);l=String(f)}else return i;let u=Number.parseInt(ie(e,o,l)||"0",10)||0,c=t.operator==="++"?u+1:u-1;return j(e,o,l,String(c),a?"associative":"indexed"),t.prefix?c:u}if(t.operand.type==="ArithConcat"){let o="";for(let a of t.operand.parts)o+=await Mn(e,a,n,r);if(o&&/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(o)){let a=Number.parseInt(e.state.env.get(o)||"0",10)||0,l=t.operator==="++"?a+1:a-1;return e.state.env.set(o,String(l)),t.prefix?l:a}}if(t.operand.type==="ArithDynamicElement"){let o="";if(t.operand.nameExpr.type==="ArithConcat")for(let a of t.operand.nameExpr.parts)o+=await Mn(e,a,n,r);else t.operand.nameExpr.type==="ArithVariable"&&(o=t.operand.nameExpr.hasDollarPrefix?await re(e,t.operand.nameExpr.name):t.operand.nameExpr.name);if(o&&/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(o)){let a=await s(t.operand.subscript),l=Number.parseInt(ie(e,o,a)||"0",10)||0,u=t.operator==="++"?l+1:l-1;return j(e,o,a,String(u)),t.prefix?u:l}}return i}return Hp(i,t.operator)}case"ArithTernary":return await s(t.condition)?await s(t.consequent):await s(t.alternate);case"ArithAssignment":{let i=t.variable,o=i,a;if(t.stringKey!==void 0)a=t.stringKey;else if(t.subscript){let d=e.state.associativeArrays?.has(i);if(d&&t.subscript.type==="ArithVariable"&&!t.subscript.hasDollarPrefix)a=t.subscript.name;else if(d&&t.subscript.type==="ArithVariable"&&t.subscript.hasDollarPrefix)a=await re(e,t.subscript.name)||"\\";else if(d){let p=await s(t.subscript);a=String(p)}else{let p=await s(t.subscript);if(p<0){let h=H(e,i);h.length>0&&(p=Math.max(...h.map(([y])=>typeof y=="number"?y:0))+1+p)}a=String(p)}}let l=a===void 0?e.state.env.get(o):ie(e,i,a),u=Number.parseInt(l||"0",10)||0,c=await s(t.value),f=Yu(u,c,t.operator);return a===void 0?e.state.env.set(o,String(f)):j(e,i,a,String(f),e.state.associativeArrays?.has(i)?"associative":"indexed"),f}case"ArithGroup":return await s(t.expression);case"ArithConcat":{let i="";for(let o of t.parts)i+=await Mn(e,o,n,r);return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(i)?await zi(e,i,r):Number.parseInt(i,10)||0}case"ArithDynamicAssignment":{let i="";if(t.target.type==="ArithConcat")for(let c of t.target.parts)i+=await Mn(e,c,n,r);else t.target.type==="ArithVariable"&&(i=t.target.hasDollarPrefix?await re(e,t.target.name):t.target.name);if(!i||!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(i))return 0;let o=i;if(t.subscript){let c=await s(t.subscript);o=`${i}_${c}`}let a=Number.parseInt(e.state.env.get(o)||"0",10)||0,l=await s(t.value),u=Yu(a,l,t.operator);return e.state.env.set(o,String(u)),u}case"ArithDynamicElement":{let i="";if(t.nameExpr.type==="ArithConcat")for(let u of t.nameExpr.parts)i+=await Mn(e,u,n,r);else t.nameExpr.type==="ArithVariable"&&(i=t.nameExpr.hasDollarPrefix?await re(e,t.nameExpr.name):t.nameExpr.name);if(!i||!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(i))return 0;let o=await s(t.subscript),a=`${i}_${o}`,l=e.state.env.get(a);return l!==void 0?as(e,a,l,r):0}default:return 0}}async function Mn(e,t,n=!1,r=Ju()){switch(t.type){case"ArithNumber":return String(t.value);case"ArithSingleQuote":return String(await Bn(e,t,n,r));case"ArithVariable":return t.hasDollarPrefix?await re(e,t.name):t.name;case"ArithSpecialVar":return await re(e,t.name);case"ArithBracedExpansion":return await ls(e,t.content);case"ArithCommandSubst":return e.execFn?(await e.execFn(t.command,{signal:e.state.signal})).stdout.trim():"0";case"ArithConcat":{let s="";for(let i of t.parts)s+=await Mn(e,i,n,r);return s}default:return String(await Bn(e,t,n,r))}}async function ec(e,t){let n="",r=0;for(let A of t.parts){let x=A.type==="Literal"?A.value:"\0",$=W(x);if($>e.limits.maxStringLength-r)throw new C(`array assignment string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");n+=x,r+=$}let s=n.match(/^([a-zA-Z_][a-zA-Z0-9_]*)(\+?=)\(/);if(!s||!n.endsWith(")"))return null;let i=s[1],o=s[2],a=[],l=[],u=!1,c="",f=0,d=0,p=!1,h=!0,m=A=>{let x=W(A);if(x>e.limits.maxStringLength-d-f)throw new C(`array assignment string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");c+=A,f+=x},y=(A,x=!1)=>{if(a.length>=e.limits.maxArrayElements)throw new C(`array assignment element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");let $=W(A);if($>e.limits.maxStringLength-d)throw new C(`array assignment string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");a.push(A),l.push(x),d+=$},b=()=>{y(c,h),c="",f=0,p=!1,h=!0};for(let A of t.parts)if(A.type==="Literal"){let x=A.value;if(!u){let $=x.indexOf("=(");$!==-1&&(u=!0,x=x.slice($+2))}if(u){x.endsWith(")")&&(x=x.slice(0,-1));for(let $ of x)/\s/.test($)?(c||p)&&b():m($)}}else if(u)if(A.type==="BraceExpansion")if(/^\[.+\]=/.test(c))m(On({type:"Word",parts:[A]}));else{(c||p)&&b();let $=await gt(e,{type:"Word",parts:[A]});for(let I of $.values)y(I)}else{(A.type==="SingleQuoted"||A.type==="DoubleQuoted"||A.type==="Escaped")&&(p=!0),h=!1;let x=await ne(e,{type:"Word",parts:[A]});m(x)}(c||p)&&b();let w=a.splice(0),E=l.splice(0);d=0;for(let A=0;A<w.length;A++){let x=w[A];if(!E[A]){y(x);continue}let $=x.match(/^(\[[^\]]+\]=)(.*)$/s);if($){let I=Kt(e,$[2]);x=$[1]+I}if(x.includes("{")&&x.includes("}")){let I=new G().parseWordFromString(x,!1,!1);if(I.parts.some(P=>P.type==="BraceExpansion")){let P=await gt(e,I);for(let N of P.values)y(N);continue}}y(x)}let S=[`${i}${o}(`],v=W(S[0]);for(let A=0;A<a.length;A++){let x=a[A],$,I=x.match(/^(\[[^\]]+\]=)(.*)$/s);if(I){let D=I[2].replace(/\\/g,"\\\\").replace(/"/g,'\\"');$=`${I[1]}"${D}"`}else x===""?$="''":/[\s"'\\$`!*?[\]{}|&;<>()]/.test(x)&&!x.startsWith("'")&&!x.startsWith('"')?$=`'${x.replace(/'/g,"'\\''")}'`:$=x;let P=`${A>0?" ":""}${$}`,N=W(P);if(N+1>e.limits.maxStringLength-v)throw new C(`array assignment string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");S.push(P),v+=N}return S.push(")"),S.join("")}async function tc(e,t){let n=-1,r=-1,s=!1;for(let m=0;m<t.parts.length;m++){let y=t.parts[m];if(y.type==="Literal"){let b=y.value.indexOf("+=");if(b!==-1){let E=y.value.slice(0,b);if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(E)){n=m,r=b,s=!0;break}if(/^[a-zA-Z_][a-zA-Z0-9_]*\[[^\]]+\]$/.test(E)){n=m,r=b,s=!0;break}}let w=y.value.indexOf("=");if(w!==-1&&(w===0||y.value[w-1]!=="+")){let E=y.value.slice(0,w);if(/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(E)||/^[a-zA-Z_][a-zA-Z0-9_]*\[[^\]]+\]$/.test(E)){n=m,r=w;break}}}}if(n===-1)return null;let i=t.parts.slice(0,n),o=t.parts[n];if(o.type!=="Literal")return null;let a=s?2:1,l=o.value.slice(0,r),u=o.value.slice(r+a),c=t.parts.slice(n+1),f="";for(let m of i)f+=await ne(e,{type:"Word",parts:[m]});f+=l;let d={type:"Word",parts:u!==""?[{type:"Literal",value:u},...c]:c},p=d.parts.length>0?await ne(e,d):"";return`${f}${s?"+=":"="}${p}`}var Kp=["tar","yq","xan","sqlite3","python3","python"];function nc(e){return Kp.includes(e)}var J=Object.freeze({stdout:"",stderr:"",exitCode:0,internalStdinConsumed:0});function Y(e=""){return{stdout:e,stderr:"",exitCode:0}}function L(e,t=1){return{stdout:"",stderr:e,exitCode:t}}function T(e,t,n){return{stdout:e,stderr:t,exitCode:n}}function ge(e){return{stdout:"",stderr:"",exitCode:e?0:1,internalStdinConsumed:0}}function Yt(e,t,n="",r=""){throw new C(e,t,n,r)}function rc(e){let t=e.state.fileDescriptors;if(t&&t.size>=e.limits.maxFileDescriptors)throw new C(`too many open file descriptors (max ${e.limits.maxFileDescriptors})`,"file_descriptors")}function qi(e,t){if(e.state.loopDepth===0){if(e.state.parentHasLoopContext)throw new Tt;return J}if(t.length>1)throw new U(1,"",`bash: break: too many arguments
120
+ `);let n=1;if(t.length>0){let r=Number.parseInt(t[0],10);if(Number.isNaN(r)||r<1)throw new U(128,"",`bash: break: ${t[0]}: numeric argument required
121
+ `);n=r}throw new Ge(n)}async function Ui(e,t){let n,r=!1,s=!1,i=0;for(;i<t.length;)if(t[i]==="--"){i++;break}else if(t[i]==="-L")s=!1,i++;else if(t[i]==="-P")s=!0,i++;else if(t[i].startsWith("-")&&t[i]!=="-")i++;else break;let o=t.slice(i);if(o.length===0)n=e.state.env.get("HOME")||"/";else if(o[0]==="~")n=e.state.env.get("HOME")||"/";else if(o[0]==="-"){let f=e.state.env.get("OLDPWD");if(f===void 0)return L(`bash: cd: OLDPWD not set
122
+ `);n=f,r=!0}else n=o[0];if(n!==""&&!n.startsWith("/")&&!n.startsWith("./")&&!n.startsWith("../")&&n!=="."&&n!==".."){let f=e.state.env.get("CDPATH");if(f){let d=f.split(":").filter(p=>p);for(let p of d){let h=p.startsWith("/")?`${p}/${n}`:`${e.state.cwd}/${p}/${n}`;try{if((await e.fs.stat(h)).isDirectory){n=h,r=!0;break}}catch{}}}}let l=(n.startsWith("/")?n:`${e.state.cwd}/${n}`).split("/").filter(f=>f&&f!=="."),u="";for(let f of l)if(f==="..")u=u.split("/").slice(0,-1).join("/")||"/";else{u=u?`${u}/${f}`:`/${f}`;try{if(!(await e.fs.stat(u)).isDirectory)return L(`bash: cd: ${n}: Not a directory
123
+ `)}catch{return L(`bash: cd: ${n}: No such file or directory
124
+ `)}}let c=u||"/";if(s)try{c=await e.fs.realpath(c)}catch{}return e.state.previousDir=e.state.cwd,e.state.cwd=c,e.state.env.set("PWD",e.state.cwd),e.state.env.set("OLDPWD",e.state.previousDir),Y(r?`${n===""?"":c}
125
+ `:"")}function ji(e,t){return e.fs.resolvePath(e.state.cwd,t)}var Xp=["-e","-a","-f","-d","-r","-w","-x","-s","-L","-h","-k","-g","-u","-G","-O","-b","-c","-p","-S","-t","-N"];function us(e){return Xp.includes(e)}async function cs(e,t,n){let r=ji(e,n);switch(t){case"-e":case"-a":return e.fs.exists(r);case"-f":return await e.fs.exists(r)?(await e.fs.stat(r)).isFile:!1;case"-d":return await e.fs.exists(r)?(await e.fs.stat(r)).isDirectory:!1;case"-r":return await e.fs.exists(r)?((await e.fs.stat(r)).mode&256)!==0:!1;case"-w":return await e.fs.exists(r)?((await e.fs.stat(r)).mode&128)!==0:!1;case"-x":return await e.fs.exists(r)?((await e.fs.stat(r)).mode&64)!==0:!1;case"-s":return await e.fs.exists(r)?(await e.fs.stat(r)).size>0:!1;case"-L":case"-h":try{return(await e.fs.lstat(r)).isSymbolicLink}catch{return!1}case"-k":return await e.fs.exists(r)?((await e.fs.stat(r)).mode&512)!==0:!1;case"-g":return await e.fs.exists(r)?((await e.fs.stat(r)).mode&1024)!==0:!1;case"-u":return await e.fs.exists(r)?((await e.fs.stat(r)).mode&2048)!==0:!1;case"-G":case"-O":return e.fs.exists(r);case"-b":return!1;case"-c":return["/dev/null","/dev/zero","/dev/random","/dev/urandom","/dev/tty","/dev/stdin","/dev/stdout","/dev/stderr"].includes(r);case"-p":return!1;case"-S":return!1;case"-t":return!1;case"-N":return e.fs.exists(r);default:return!1}}var Yp=["-nt","-ot","-ef"];function fs(e){return Yp.includes(e)}async function ds(e,t,n,r){let s=ji(e,n),i=ji(e,r);switch(t){case"-nt":{let[o,a]=await Promise.all([e.fs.stat(s).catch(()=>null),e.fs.stat(i).catch(()=>null)]);return o!==null&&(a===null||o.mtime>a.mtime)}case"-ot":{let[o,a]=await Promise.all([e.fs.stat(s).catch(()=>null),e.fs.stat(i).catch(()=>null)]);return a!==null&&(o===null||o.mtime<a.mtime)}case"-ef":try{let[o,a]=await Promise.all([e.fs.realpath(s),e.fs.realpath(i)]);if(o===a)return!0;let[l,u]=await Promise.all([e.fs.stat(s),e.fs.stat(i)]);return l.dev!==void 0&&l.ino!==void 0&&u.dev!==void 0&&u.ino!==void 0?l.dev===u.dev&&l.ino===u.ino:l.identity&&u.identity?l.identity===u.identity:!1}catch{return!1}default:return!1}}var Jp=new Set(["-eq","-ne","-lt","-le","-gt","-ge"]);function ps(e){return Jp.has(e)}function hs(e,t,n){switch(e){case"-eq":return t===n;case"-ne":return t!==n;case"-lt":return t<n;case"-le":return t<=n;case"-gt":return t>n;case"-ge":return t>=n}}function dr(e){return e==="="||e==="=="||e==="!="}function ms(e,t,n,r=!1,s=!1,i=!1,o=256){if(r){let l=Wn(t,n,s,i,o);return e==="!="?!l:l}if(s){let l=t.toLowerCase()===n.toLowerCase();return e==="!="?!l:l}let a=t===n;return e==="!="?!a:a}var eh=new Set(["-z","-n"]);function ys(e){return eh.has(e)}function gs(e,t){switch(e){case"-z":return t==="";case"-n":return t!==""}}async function ws(e,t){let n=t.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(n){let r=n[1],s=n[2];if(e.state.associativeArrays?.has(r)){let a=s;return(a.startsWith("'")&&a.endsWith("'")||a.startsWith('"')&&a.endsWith('"'))&&(a=a.slice(1,-1)),a=a.replace(/\$([a-zA-Z_][a-zA-Z0-9_]*)/g,(l,u)=>e.state.env.get(u)||""),zt(e,r,a)}let o;try{let a=new G,l=te(a,s);o=await X(e,l.expression)}catch{if(/^-?\d+$/.test(s))o=Number.parseInt(s,10);else{let a=e.state.env.get(s);o=a?Number.parseInt(a,10):0}}if(o<0){let a=Ee(e,r),l=e.state.currentLine;if(a.length===0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${l}: ${r}: bad array subscript
125
126
  `,!1;if(o=Math.max(...a)+1+o,o<0)return e.state.expansionStderr=(e.state.expansionStderr||"")+`bash: line ${l}: ${r}: bad array subscript
126
- `,!1}return zt(e,r,o)}return e.state.env.has(t)?!0:e.state.associativeArrays?.has(t)?St(e,t).length>0:be(e,t).length>0}async function Jt(e,t){switch(t.type){case"CondBinary":{let n=await ne(e,t.left),r=t.right.parts.length>0&&t.right.parts.every(i=>i.type==="SingleQuoted"||i.type==="DoubleQuoted"||i.type==="Escaped"&&t.operator!=="=~"),s;if(t.operator==="=~")if(r){let i=await ne(e,t.right);s=Ln(i)}else s=await zu(e,t.right);else fr(t.operator)&&!r?s=await qu(e,t.right):s=await ne(e,t.right);if(fr(t.operator)){let i=e.state.shoptOptions.nocasematch;return fs(t.operator,n,s,!r,i,!0,e.limits.maxCallDepth)}if(us(t.operator))return cs(t.operator,await tc(e,n),await tc(e,s));if(as(t.operator))return ls(e,t.operator,n,s);switch(t.operator){case"=~":try{let i=e.state.shoptOptions.nocasematch,o=Jp(s),l=me(o,i?"i":"").match(n);if(ye(e,"BASH_REMATCH"),l)for(let u=0;u<l.length;u++)U(e,"BASH_REMATCH",u,l[u]||"");return l!==null}catch{throw new Error("syntax error in regular expression")}case"<":return n<s;case">":return n>s;default:return!1}}case"CondUnary":{let n=await ne(e,t.operand);return is(t.operator)?os(e,t.operator,n):ds(t.operator)?ps(t.operator,n):t.operator==="-v"?await hs(e,n):t.operator==="-o"?ji(e,n):!1}case"CondNot":return e.state.shoptOptions.extglob&&t.operand.type==="CondGroup"&&t.operand.expression.type==="CondWord"?`!(${await ne(e,t.operand.expression.word)})`!=="":!await Jt(e,t.operand);case"CondAnd":return await Jt(e,t.left)?await Jt(e,t.right):!1;case"CondOr":return await Jt(e,t.left)?!0:await Jt(e,t.right);case"CondGroup":return await Jt(e,t.expression);case"CondWord":return await ne(e,t.word)!=="";default:return!1}}async function dr(e,t){if(t.length===0)return L("","",1);if(t.length===1)return ge(!!t[0]);if(t.length===2){let r=t[0],s=t[1];return r==="("?_(`test: '(' without matching ')'
127
- `,2):is(r)?ge(await os(e,r,s)):ds(r)?ge(ps(r,s)):r==="!"?ge(!s):r==="-v"?ge(await hs(e,s)):r==="-o"?ge(ji(e,s)):r==="="||r==="=="||r==="!="||r==="<"||r===">"||r==="-eq"||r==="-ne"||r==="-lt"||r==="-le"||r==="-gt"||r==="-ge"||r==="-nt"||r==="-ot"||r==="-ef"?_(`test: ${r}: unary operator expected
128
- `,2):L("","",1)}if(t.length===3){let r=t[0],s=t[1],i=t[2];if(fr(s))return ge(fs(s,r,i));if(us(s)){let o=ms(r),a=ms(i);return!o.valid||!a.valid?L("","",2):ge(cs(s,o.value,a.value))}if(as(s))return ge(await ls(e,s,r,i));switch(s){case"-a":return ge(r!==""&&i!=="");case"-o":return ge(r!==""||i!=="");case">":return ge(r>i);case"<":return ge(r<i)}if(r==="!"){let o=await dr(e,[s,i]);return L("",o.stderr,o.exitCode===0?1:o.exitCode===1?0:o.exitCode)}if(r==="("&&i===")")return ge(s!=="")}if(t.length===4){if(t[0]==="!"){let r=await dr(e,t.slice(1));return L("",r.stderr,r.exitCode===0?1:r.exitCode===1?0:r.exitCode)}if(t[0]==="("&&t[3]===")")return dr(e,[t[1],t[2]])}let n=await rc(e,t,0);return n.pos<t.length?_(`test: too many arguments
129
- `,2):ge(n.value)}async function rc(e,t,n){return Qp(e,t,n)}async function Qp(e,t,n){let{value:r,pos:s}=await ec(e,t,n);for(;t[s]==="-o";){let i=await ec(e,t,s+1);r=r||i.value,s=i.pos}return{value:r,pos:s}}async function ec(e,t,n){let{value:r,pos:s}=await Ui(e,t,n);for(;t[s]==="-a";){let i=await Ui(e,t,s+1);r=r&&i.value,s=i.pos}return{value:r,pos:s}}async function Ui(e,t,n){let r=e.executionScope.enterDepth("test_expression",e.limits.maxCallDepth,"test expression");try{if(t[n]==="!"){let{value:s,pos:i}=await Ui(e,t,n+1);return{value:!s,pos:i}}return Kp(e,t,n)}finally{r.release()}}async function Kp(e,t,n){let r=t[n];if(r==="("){let{value:i,pos:o}=await rc(e,t,n+1);return{value:i,pos:t[o]===")"?o+1:o}}let s=t[n+1];if(fr(s)){let i=r,o=t[n+2]??"";return{value:fs(s,i,o),pos:n+3}}if(us(s)){let i=ms(r),o=ms(t[n+2]??"0");return!i.valid||!o.valid?{value:!1,pos:n+3}:{value:cs(s,i.value,o.value),pos:n+3}}if(as(s)){let i=r,o=t[n+2]??"";return{value:await ls(e,s,i,o),pos:n+3}}if(is(r)){let i=t[n+1]??"";return{value:await os(e,r,i),pos:n+2}}if(ds(r)){let i=t[n+1]??"";return{value:ps(r,i),pos:n+2}}if(r==="-v"){let i=t[n+1]??"";return{value:await hs(e,i),pos:n+2}}if(r==="-o"){let i=t[n+1]??"";return{value:ji(e,i),pos:n+2}}return{value:r!==void 0&&r!=="",pos:n+1}}function Bn(e,t,n=!1,r=!1,s=256){r&&Xp(t,s);let i=`^${sc(t,r)}$`;return me(i,n?"is":"s").test(e)}function Xp(e,t){let n=0,r=[];for(let s=0;s<e.length;s++){if(e[s]==="\\"){s++;continue}if(e[s]==="("){let i=s>0&&"@*+?!".includes(e[s-1]);if(r.push(i),i&&n++,n>t)throw new P(`extglob maximum depth (${t}) exceeded`,"recursion")}else e[s]===")"&&r.length>0&&r.pop()&&n--}}function sc(e,t){let n="";for(let r=0;r<e.length;r++){let s=e[r];if(t&&(s==="@"||s==="*"||s==="+"||s==="?"||s==="!")&&r+1<e.length&&e[r+1]==="("){let i=ic(e,r+1);if(i!==-1){let o=e.slice(r+2,i),a=oc(o),l=a.map(c=>sc(c,t)),u=l.length>0?l.join("|"):"(?:)";if(s==="@")n+=`(?:${u})`;else if(s==="*")n+=`(?:${u})*`;else if(s==="+")n+=`(?:${u})+`;else if(s==="?")n+=`(?:${u})?`;else if(s==="!")if(i<e.length-1){let f=a.map(p=>ac(p,t));if(f.every(p=>p!==null)&&f.every(p=>p===f[0])&&f[0]!==null){let p=f[0];if(p===0)n+="(?:.+)";else{let h=[];p>0&&h.push(`.{0,${p-1}}`),h.push(`.{${p+1},}`),h.push(`(?!(?:${u})).{${p}}`),n+=`(?:${h.join("|")})`}}else n+=`(?:(?!(?:${u})).)*?`}else n+=`(?!(?:${u})$).*`;r=i;continue}}if(s==="\\")if(r+1<e.length){let i=e[r+1];/[\\^$.|+(){}[\]*?]/.test(i)?n+=`\\${i}`:n+=i,r++}else n+="\\\\";else if(s==="*")n+=".*";else if(s==="?")n+=".";else if(s==="["){let i=e.indexOf("]",r+1);i!==-1?(n+=e.slice(r,i+1),r=i):n+="\\["}else/[\\^$.|+(){}]/.test(s)?n+=`\\${s}`:n+=s}return n}function ic(e,t){let n=1,r=t+1;for(;r<e.length&&n>0;){let s=e[r];if(s==="\\"){r+=2;continue}if(s==="(")n++;else if(s===")"&&(n--,n===0))return r;r++}return-1}function oc(e){let t=[],n="",r=0,s=0;for(;s<e.length;){let i=e[s];if(i==="\\"){n+=i,s+1<e.length?(n+=e[s+1],s+=2):s++;continue}i==="("?(r++,n+=i):i===")"?(r--,n+=i):i==="|"&&r===0?(t.push(n),n=""):n+=i,s++}return t.push(n),t}function ac(e,t){let n=0,r=0;for(;r<e.length;){let s=e[r];if(t&&(s==="@"||s==="*"||s==="+"||s==="?"||s==="!")&&r+1<e.length&&e[r+1]==="("){let i=ic(e,r+1);if(i!==-1){if(s==="@"){let o=e.slice(r+2,i),l=oc(o).map(u=>ac(u,t));if(l.every(u=>u!==null)&&l.every(u=>u===l[0])){n+=l[0],r=i+1;continue}return null}return null}}if(s==="*")return null;if(s==="?"){n+=1,r++;continue}if(s==="["){let i=e.indexOf("]",r+1);if(i!==-1){n+=1,r=i+1;continue}n+=1,r++;continue}if(s==="\\"){n+=1,r+=2;continue}n+=1,r++}return n}function ji(e,t){let r=new Map([["errexit",()=>e.state.options.errexit===!0],["nounset",()=>e.state.options.nounset===!0],["pipefail",()=>e.state.options.pipefail===!0],["xtrace",()=>e.state.options.xtrace===!0],["e",()=>e.state.options.errexit===!0],["u",()=>e.state.options.nounset===!0],["x",()=>e.state.options.xtrace===!0]]).get(t);return r?r():!1}async function tc(e,t){if(t=t.trim(),t==="")return 0;if(/^[+-]?(\d+#[a-zA-Z0-9@_]+|0[xX][0-9a-fA-F]+|0[0-7]+|\d+)$/.test(t))return nc(t);try{let n=new j,r=te(n,t);return await X(e,r.expression)}catch{return nc(t)}}function Yp(e,t){let n=0;for(let r of e){let s;if(r>="0"&&r<="9")s=r.charCodeAt(0)-48;else if(r>="a"&&r<="z")s=r.charCodeAt(0)-97+10;else if(r>="A"&&r<="Z")s=r.charCodeAt(0)-65+36;else if(r==="@")s=62;else if(r==="_")s=63;else return Number.NaN;if(s>=t)return Number.NaN;n=n*t+s}return n}function nc(e){if(e=e.trim(),e==="")return 0;let t=!1;e.startsWith("-")?(t=!0,e=e.slice(1)):e.startsWith("+")&&(e=e.slice(1));let n,r=e.match(/^(\d+)#([a-zA-Z0-9@_]+)$/);if(r){let s=Number.parseInt(r[1],10);s>=2&&s<=64?n=Yp(r[2],s):n=0}else/^0[xX][0-9a-fA-F]+$/.test(e)?n=Number.parseInt(e,16):/^0[0-7]+$/.test(e)?n=Number.parseInt(e,8):n=Number.parseInt(e,10);return Number.isNaN(n)&&(n=0),t?-n:n}function ms(e){if(e=e.trim(),e==="")return{value:0,valid:!0};let t=!1;if(e.startsWith("-")?(t=!0,e=e.slice(1)):e.startsWith("+")&&(e=e.slice(1)),!/^\d+$/.test(e))return{value:0,valid:!1};let n=Number.parseInt(e,10);return Number.isNaN(n)?{value:0,valid:!1}:{value:t?-n:n,valid:!0}}function Jp(e){let t="",n=0;for(;n<e.length;)if(e[n]==="\\"&&n+1<e.length)t+=e[n]+e[n+1],n+=2;else if(e[n]==="["){let r=eh(e,n);t+=r.converted,n=r.endIndex}else t+=e[n],n++;return t}function eh(e,t){let n=t+1,r="[";n<e.length&&(e[n]==="^"||e[n]==="!")&&(r+="^",n++);let s=!1;n<e.length&&e[n]==="]"&&(s=!0,n++);let i=!1;n<e.length&&e[n]==="["&&n+1<e.length&&e[n+1]!==":"&&(i=!0,n++);let o="",a=!1;for(;n<e.length;){let l=e[n];if(l==="]"){a=!0,n++;break}if(l==="["&&n+1<e.length&&e[n+1]===":"){let u=e.indexOf(":]",n+2);if(u!==-1){let c=e.slice(n+2,u);o+=th(c),n=u+2;continue}}if(l==="["&&n+1<e.length){let u=e[n+1];if(u==="."||u==="="){let c=`${u}]`,f=e.indexOf(c,n+2);if(f!==-1){let d=e.slice(n+2,f);o+=d,n=f+2;continue}}}if(l==="\\"&&n+1<e.length){o+=l+e[n+1],n+=2;continue}o+=l,n++}return a?(s&&(r+="\\]"),i&&(r+="\\["),r+=o,r+="]",{converted:r,endIndex:n}):{converted:"\\[",endIndex:t+1}}function th(e){return new Map([["alnum","a-zA-Z0-9"],["alpha","a-zA-Z"],["ascii","\\x00-\\x7F"],["blank"," \\t"],["cntrl","\\x00-\\x1F\\x7F"],["digit","0-9"],["graph","!-~"],["lower","a-z"],["print"," -~"],["punct","!-/:-@\\[-`{-~"],["space"," \\t\\n\\r\\f\\v"],["upper","A-Z"],["word","a-zA-Z0-9_"],["xdigit","0-9A-Fa-f"]]).get(e)??""}function Gi(e,t,n){if(n&&e.length>=n.maxElements)throw new P(`array element limit exceeded (${n.maxElements})`,"array_elements");e.push(t)}function Ot(e,t){if(t&&F(e)>t.maxStringBytes)throw new P(`array assignment string limit exceeded (${t.maxStringBytes} bytes)`,"string_length");let n=[],r="",s=!1,i=!1,o=!1,a=!1;for(let l of e){if(o){r+=l,o=!1,a=!0;continue}if(l==="\\"){o=!0;continue}if(l==="'"&&!i){s||(a=!0),s=!s;continue}if(l==='"'&&!s){i||(a=!0),i=!i;continue}if((l===" "||l===" "||l===`
130
- `)&&!s&&!i){a&&(Gi(n,r,t),r="",a=!1);continue}r+=l,a=!0}return a&&Gi(n,r,t),n}function ys(e,t){if(t&&F(e)>t.maxStringBytes)throw new P(`array assignment string limit exceeded (${t.maxStringBytes} bytes)`,"string_length");let n=[],r=0;for(;r<e.length;){for(;r<e.length&&/\s/.test(e[r]);)r++;if(r>=e.length)break;if(e[r]!=="["){r++;continue}r++;let s="";if(e[r]==="'"||e[r]==='"'){let o=e[r];for(r++;r<e.length&&e[r]!==o;)s+=e[r],r++;e[r]===o&&r++}else for(;r<e.length&&e[r]!=="]"&&e[r]!=="=";)s+=e[r],r++;for(;r<e.length&&e[r]!=="]";)r++;if(e[r]==="]"&&r++,e[r]!=="=")continue;r++;let i="";if(e[r]==="'"||e[r]==='"'){let o=e[r];for(r++;r<e.length&&e[r]!==o;)e[r]==="\\"&&r+1<e.length&&r++,i+=e[r],r++;e[r]===o&&r++}else for(;r<e.length&&!/\s/.test(e[r]);)i+=e[r],r++;Gi(n,[s,i],t)}return n}function lc(e,t){let n=e.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(n)return{name:n[1],isArray:!0,arrayElements:Ot(n[2],t)};let r=e.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([^\]]+)\]=(.*)$/s);if(r)return{name:r[1],isArray:!1,arrayIndex:r[2],value:r[3]};if(e.includes("=")){let s=e.indexOf("=");return{name:e.slice(0,s),isArray:!1,value:e.slice(s+1)}}return{name:e,isArray:!1}}async function nh(e,t){try{let n=new j,r=te(n,t);return await X(e,r.expression)}catch{let n=parseInt(t,10);return Number.isNaN(n)?0:n}}async function uc(e,t,n={}){let{name:r,isArray:s,arrayElements:i,value:o,arrayIndex:a}=t,{makeReadonly:l=!1,checkReadonly:u=!0}=n;if(u){let c=ue(e,r);if(c)return c}if(s&&i){e.executionScope.consumeWork(i.length,"array assignment");let c=ve(e,r),f=c?Le(c):void 0,d=e.state.env.get(r);try{ye(e,r);for(let p=0;p<i.length;p++)U(e,r,p,i[p]);e.state.env.delete(r)}catch(p){throw e.state.arrays??=new Map,f?e.state.arrays.set(r,f):e.state.arrays.delete(r),d===void 0?e.state.env.delete(r):e.state.env.set(r,d),p}}else if(a!==void 0&&o!==void 0){let c=await nh(e,a);U(e,r,c,o)}else o!==void 0&&e.state.env.set(r,o);return l&&je(e,r),null}function en(e,t){e.state.localVarDepth=e.state.localVarDepth||new Map,e.state.localVarDepth.set(t,e.state.callDepth)}function Hi(e,t){return e.state.localVarDepth?.get(t)}function gs(e,t){e.state.localVarDepth?.delete(t)}function cc(e,t,n){e.state.localVarStack=e.state.localVarStack||new Map;let r=e.state.localVarStack.get(t)||[];r.push({value:n,scopeIndex:e.state.localScopes.length-1}),e.state.localVarStack.set(t,r)}function ws(e,t){let n=e.state.localVarStack?.get(t);if(!(!n||n.length===0))return n.pop()}function fc(e,t){if(e.state.localVarStack)for(let[n,r]of e.state.localVarStack.entries()){for(;r.length>0&&r[r.length-1].scopeIndex===t;)r.pop();r.length===0&&e.state.localVarStack.delete(n)}}var Zi=new Set([":",".","break","continue","eval","exec","exit","export","readonly","return","set","shift","trap","unset"]);function dc(e){return Zi.has(e)}var Qi=new Set(["if","then","else","elif","fi","case","esac","for","select","while","until","do","done","in","function","{","}","time","[[","]]","!"]),Wn=new Set([":","true","false","cd","export","unset","exit","local","set","break","continue","return","eval","shift","getopts","compgen","complete","compopt","pushd","popd","dirs","source",".","read","mapfile","readarray","declare","typeset","readonly","let","command","shopt","exec","test","[","echo","printf","pwd","alias","unalias","type","hash","ulimit","umask","trap","times","wait","kill","jobs","fg","bg","disown","suspend","fc","history","help","enable","builtin","caller"]);var Ki="__file__:",Xi="__file_append__:",eo="__rw__:",Yi="__dupout__:",Ji="__dupin__:",we=3;function rh(e){let t=e.slice(eo.length),n=t.indexOf(":");if(n===-1)return null;let r=Number.parseInt(t.slice(0,n),10);if(Number.isNaN(r)||r<0)return null;let s=n+1,i=t.slice(s,s+r),o=t.slice(s+r+1),a=o.indexOf(":");if(a===-1)return null;let l=Number.parseInt(o.slice(0,a),10);return Number.isNaN(l)||l<0?null:{path:i,position:l,content:o.slice(a+1)}}function pc(e,t){let n=Number.parseInt(e.slice(t.length),10);return Number.isNaN(n)?null:n}function sh(e){if(e.startsWith(Ki))return{kind:"output",path:e.slice(Ki.length),append:!1};if(e.startsWith(Xi))return{kind:"output",path:e.slice(Xi.length),append:!0};if(e.startsWith(eo)){let t=rh(e);if(t)return{kind:"readwrite",...t}}if(e.startsWith(Yi)){let t=pc(e,Yi);if(t!==null)return{kind:"dup-out",sourceFd:t}}if(e.startsWith(Ji)){let t=pc(e,Ji);if(t!==null)return{kind:"dup-in",sourceFd:t}}return{kind:"input",content:e}}function to(e){switch(e.kind){case"input":return e.content;case"output":return`${e.append?Xi:Ki}${e.path}`;case"readwrite":return`${eo}${e.path.length}:${e.path}:${e.position}:${e.content}`;case"dup-out":return`${Yi}${e.sourceFd}`;case"dup-in":return`${Ji}${e.sourceFd}`;case"closed":throw new Error("Closed descriptors have no table encoding")}}function ih(e){return e.state.fileDescriptors??=new Map,e.state.fileDescriptors}function oh(e,t,n){n?(e.state.inputFds??=new Set,e.state.inputFds.add(t)):e.state.inputFds?.delete(t)}function Vn(e,t){return e.state.fdAliases?.get(t)}function tn(e,t){return[...Vn(e,t)??[t]]}function hc(e,t){let n=Vn(e,t);if(n&&(n.delete(t),e.state.fdAliases?.delete(t),n.size<2))for(let r of n)e.state.fdAliases?.delete(r)}function no(e,t,n){if(t===n)return;e.state.fdAliases??=new Map;let r=Vn(e,n)??new Set([n]);r.add(t);for(let s of r)e.state.fdAliases.set(s,r)}function Es(e,t){return e.state.fileDescriptors?.get(t)}function Je(e,t){let n=Es(e,t);if(n!==void 0)return e.state.inputFds?.has(t)?{kind:"input",content:n}:sh(n)}function bn(e,t){return e.state.fileDescriptors?.has(t)===!0}function ro(e,t,n,r){let s=ih(e);s.has(t)||Ju(e),s.set(t,n),oh(e,t,r)}function bs(e,t,n,r=!1){hc(e,t),ro(e,t,n,r)}function it(e,t,n){bs(e,t,to(n),n.kind==="input")}function kt(e,t){e.state.fileDescriptors?.delete(t),e.state.inputFds?.delete(t),hc(e,t)}function Ss(e,t,n){let r=Es(e,n);return r===void 0?!1:(bs(e,t,r,e.state.inputFds?.has(n)===!0),no(e,t,n),!0)}function so(e,t,n){let r=Es(e,n);if(r===void 0)return!1;if(t===n)return!0;let s=e.state.inputFds?.has(n)===!0,i=[...Vn(e,n)??[]].filter(a=>a!==n);kt(e,n),bs(e,t,r,s);let o=i.find(a=>bn(e,a));return o!==void 0&&no(e,t,o),!0}function As(e,t){let n=Je(e,t);if(n===void 0)return{error:"not-open"};switch(n.kind){case"input":return{content:n.content};case"readwrite":return{content:n.content.slice(n.position)};case"output":case"dup-out":return{error:"write-only"};case"dup-in":return{error:"not-open"};case"closed":return{error:"not-open"}}}function nn(e,t,n){let r=Je(e,t);if(r===void 0)return;let s;if(r.kind==="input")s={kind:"input",content:r.content.slice(n)};else if(r.kind==="readwrite")s={...r,position:r.position+n};else return;let i=to(s),o=s.kind==="input";for(let a of Vn(e,t)??[t])ro(e,a,i,o)}async function io(e,t,n,r,s){if(t.kind==="output")return await e.fs.appendFile(t.path,r,s),!0;let o=n.map(c=>Je(e,c)).find(c=>c?.kind==="readwrite")??t;if(o.kind!=="readwrite")return!1;let a=o.content.slice(0,o.position)+r+o.content.slice(o.position+r.length),l={...o,position:o.position+r.length,content:a};await e.fs.writeFile(o.path,a,s);let u=to(l);for(let c of n)bn(e,c)&&ro(e,c,u,!1);return!0}function rn(e,t,n){if(t.has(n))return;let r=Vn(e,n);t.set(n,{raw:Es(e,n),isInput:e.state.inputFds?.has(n)===!0,aliases:r?[...r].filter(s=>s!==n):[]})}function vs(e,t){let n=e.state.fileDescriptors;if(n)for(let[r,{raw:s,isInput:i,aliases:o}]of t){if(s===void 0){kt(e,r);continue}bs(e,r,s,i);let a=o.find(l=>n.has(l));a!==void 0&&no(e,r,a)}}function oo(e){switch(e.operator){case"<":case"<>":case"<<":case"<<-":case"<<<":case"<&":return e.fd??0;case">":case">>":case">|":case">&":return e.fd??1;default:return null}}function mc(e){if(e.fdVariable)return!1;let t=oo(e);return t!==null&&t>=we}async function ah(e,t,n,r){try{if(!await e.fs.exists(t))return null;if((await e.fs.stat(t)).isDirectory)return`bash: ${n}: Is a directory
127
+ `,!1}return zt(e,r,o)}return e.state.env.has(t)?!0:e.state.associativeArrays?.has(t)?St(e,t).length>0:Ee(e,t).length>0}async function Jt(e,t){switch(t.type){case"CondBinary":{let n=await ne(e,t.left),r=t.right.parts.length>0&&t.right.parts.every(i=>i.type==="SingleQuoted"||i.type==="DoubleQuoted"||i.type==="Escaped"&&t.operator!=="=~"),s;if(t.operator==="=~")if(r){let i=await ne(e,t.right);s=Tn(i)}else s=await Gu(e,t.right);else dr(t.operator)&&!r?s=await Hu(e,t.right):s=await ne(e,t.right);if(dr(t.operator)){let i=e.state.shoptOptions.nocasematch;return ms(t.operator,n,s,!r,i,!0,e.limits.maxCallDepth)}if(ps(t.operator))return hs(t.operator,await ic(e,n),await ic(e,s));if(fs(t.operator))return ds(e,t.operator,n,s);switch(t.operator){case"=~":try{let i=e.state.shoptOptions.nocasematch,o=ih(s),l=me(o,i?"i":"").match(n);if(ye(e,"BASH_REMATCH"),l)for(let u=0;u<l.length;u++)j(e,"BASH_REMATCH",u,l[u]||"");return l!==null}catch{throw new Error("syntax error in regular expression")}case"<":return n<s;case">":return n>s;default:return!1}}case"CondUnary":{let n=await ne(e,t.operand);return us(t.operator)?cs(e,t.operator,n):ys(t.operator)?gs(t.operator,n):t.operator==="-v"?await ws(e,n):t.operator==="-o"?Hi(e,n):!1}case"CondNot":return e.state.shoptOptions.extglob&&t.operand.type==="CondGroup"&&t.operand.expression.type==="CondWord"?`!(${await ne(e,t.operand.expression.word)})`!=="":!await Jt(e,t.operand);case"CondAnd":return await Jt(e,t.left)?await Jt(e,t.right):!1;case"CondOr":return await Jt(e,t.left)?!0:await Jt(e,t.right);case"CondGroup":return await Jt(e,t.expression);case"CondWord":return await ne(e,t.word)!=="";default:return!1}}async function pr(e,t){if(t.length===0)return T("","",1);if(t.length===1)return ge(!!t[0]);if(t.length===2){let r=t[0],s=t[1];return r==="("?L(`test: '(' without matching ')'
128
+ `,2):us(r)?ge(await cs(e,r,s)):ys(r)?ge(gs(r,s)):r==="!"?ge(!s):r==="-v"?ge(await ws(e,s)):r==="-o"?ge(Hi(e,s)):r==="="||r==="=="||r==="!="||r==="<"||r===">"||r==="-eq"||r==="-ne"||r==="-lt"||r==="-le"||r==="-gt"||r==="-ge"||r==="-nt"||r==="-ot"||r==="-ef"?L(`test: ${r}: unary operator expected
129
+ `,2):T("","",1)}if(t.length===3){let r=t[0],s=t[1],i=t[2];if(dr(s))return ge(ms(s,r,i));if(ps(s)){let o=Es(r),a=Es(i);return!o.valid||!a.valid?T("","",2):ge(hs(s,o.value,a.value))}if(fs(s))return ge(await ds(e,s,r,i));switch(s){case"-a":return ge(r!==""&&i!=="");case"-o":return ge(r!==""||i!=="");case">":return ge(r>i);case"<":return ge(r<i)}if(r==="!"){let o=await pr(e,[s,i]);return T("",o.stderr,o.exitCode===0?1:o.exitCode===1?0:o.exitCode)}if(r==="("&&i===")")return ge(s!=="")}if(t.length===4){if(t[0]==="!"){let r=await pr(e,t.slice(1));return T("",r.stderr,r.exitCode===0?1:r.exitCode===1?0:r.exitCode)}if(t[0]==="("&&t[3]===")")return pr(e,[t[1],t[2]])}let n=await ac(e,t,0);return n.pos<t.length?L(`test: too many arguments
130
+ `,2):ge(n.value)}async function ac(e,t,n){return th(e,t,n)}async function th(e,t,n){let{value:r,pos:s}=await sc(e,t,n);for(;t[s]==="-o";){let i=await sc(e,t,s+1);r=r||i.value,s=i.pos}return{value:r,pos:s}}async function sc(e,t,n){let{value:r,pos:s}=await Gi(e,t,n);for(;t[s]==="-a";){let i=await Gi(e,t,s+1);r=r&&i.value,s=i.pos}return{value:r,pos:s}}async function Gi(e,t,n){let r=e.executionScope.enterDepth("test_expression",e.limits.maxCallDepth,"test expression");try{if(t[n]==="!"){let{value:s,pos:i}=await Gi(e,t,n+1);return{value:!s,pos:i}}return nh(e,t,n)}finally{r.release()}}async function nh(e,t,n){let r=t[n];if(r==="("){let{value:i,pos:o}=await ac(e,t,n+1);return{value:i,pos:t[o]===")"?o+1:o}}let s=t[n+1];if(dr(s)){let i=r,o=t[n+2]??"";return{value:ms(s,i,o),pos:n+3}}if(ps(s)){let i=Es(r),o=Es(t[n+2]??"0");return!i.valid||!o.valid?{value:!1,pos:n+3}:{value:hs(s,i.value,o.value),pos:n+3}}if(fs(s)){let i=r,o=t[n+2]??"";return{value:await ds(e,s,i,o),pos:n+3}}if(us(r)){let i=t[n+1]??"";return{value:await cs(e,r,i),pos:n+2}}if(ys(r)){let i=t[n+1]??"";return{value:gs(r,i),pos:n+2}}if(r==="-v"){let i=t[n+1]??"";return{value:await ws(e,i),pos:n+2}}if(r==="-o"){let i=t[n+1]??"";return{value:Hi(e,i),pos:n+2}}return{value:r!==void 0&&r!=="",pos:n+1}}function Wn(e,t,n=!1,r=!1,s=256){r&&rh(t,s);let i=`^${lc(t,r)}$`;return me(i,n?"is":"s").test(e)}function rh(e,t){let n=0,r=[];for(let s=0;s<e.length;s++){if(e[s]==="\\"){s++;continue}if(e[s]==="("){let i=s>0&&"@*+?!".includes(e[s-1]);if(r.push(i),i&&n++,n>t)throw new C(`extglob maximum depth (${t}) exceeded`,"recursion")}else e[s]===")"&&r.length>0&&r.pop()&&n--}}function lc(e,t){let n="";for(let r=0;r<e.length;r++){let s=e[r];if(t&&(s==="@"||s==="*"||s==="+"||s==="?"||s==="!")&&r+1<e.length&&e[r+1]==="("){let i=uc(e,r+1);if(i!==-1){let o=e.slice(r+2,i),a=cc(o),l=a.map(c=>lc(c,t)),u=l.length>0?l.join("|"):"(?:)";if(s==="@")n+=`(?:${u})`;else if(s==="*")n+=`(?:${u})*`;else if(s==="+")n+=`(?:${u})+`;else if(s==="?")n+=`(?:${u})?`;else if(s==="!")if(i<e.length-1){let f=a.map(p=>fc(p,t));if(f.every(p=>p!==null)&&f.every(p=>p===f[0])&&f[0]!==null){let p=f[0];if(p===0)n+="(?:.+)";else{let h=[];p>0&&h.push(`.{0,${p-1}}`),h.push(`.{${p+1},}`),h.push(`(?!(?:${u})).{${p}}`),n+=`(?:${h.join("|")})`}}else n+=`(?:(?!(?:${u})).)*?`}else n+=`(?!(?:${u})$).*`;r=i;continue}}if(s==="\\")if(r+1<e.length){let i=e[r+1];/[\\^$.|+(){}[\]*?]/.test(i)?n+=`\\${i}`:n+=i,r++}else n+="\\\\";else if(s==="*")n+=".*";else if(s==="?")n+=".";else if(s==="["){let i=e.indexOf("]",r+1);i!==-1?(n+=e.slice(r,i+1),r=i):n+="\\["}else/[\\^$.|+(){}]/.test(s)?n+=`\\${s}`:n+=s}return n}function uc(e,t){let n=1,r=t+1;for(;r<e.length&&n>0;){let s=e[r];if(s==="\\"){r+=2;continue}if(s==="(")n++;else if(s===")"&&(n--,n===0))return r;r++}return-1}function cc(e){let t=[],n="",r=0,s=0;for(;s<e.length;){let i=e[s];if(i==="\\"){n+=i,s+1<e.length?(n+=e[s+1],s+=2):s++;continue}i==="("?(r++,n+=i):i===")"?(r--,n+=i):i==="|"&&r===0?(t.push(n),n=""):n+=i,s++}return t.push(n),t}function fc(e,t){let n=0,r=0;for(;r<e.length;){let s=e[r];if(t&&(s==="@"||s==="*"||s==="+"||s==="?"||s==="!")&&r+1<e.length&&e[r+1]==="("){let i=uc(e,r+1);if(i!==-1){if(s==="@"){let o=e.slice(r+2,i),l=cc(o).map(u=>fc(u,t));if(l.every(u=>u!==null)&&l.every(u=>u===l[0])){n+=l[0],r=i+1;continue}return null}return null}}if(s==="*")return null;if(s==="?"){n+=1,r++;continue}if(s==="["){let i=e.indexOf("]",r+1);if(i!==-1){n+=1,r=i+1;continue}n+=1,r++;continue}if(s==="\\"){n+=1,r+=2;continue}n+=1,r++}return n}function Hi(e,t){let r=new Map([["errexit",()=>e.state.options.errexit===!0],["nounset",()=>e.state.options.nounset===!0],["pipefail",()=>e.state.options.pipefail===!0],["xtrace",()=>e.state.options.xtrace===!0],["e",()=>e.state.options.errexit===!0],["u",()=>e.state.options.nounset===!0],["x",()=>e.state.options.xtrace===!0]]).get(t);return r?r():!1}async function ic(e,t){if(t=t.trim(),t==="")return 0;if(/^[+-]?(\d+#[a-zA-Z0-9@_]+|0[xX][0-9a-fA-F]+|0[0-7]+|\d+)$/.test(t))return oc(t);try{let n=new G,r=te(n,t);return await X(e,r.expression)}catch{return oc(t)}}function sh(e,t){let n=0;for(let r of e){let s;if(r>="0"&&r<="9")s=r.charCodeAt(0)-48;else if(r>="a"&&r<="z")s=r.charCodeAt(0)-97+10;else if(r>="A"&&r<="Z")s=r.charCodeAt(0)-65+36;else if(r==="@")s=62;else if(r==="_")s=63;else return Number.NaN;if(s>=t)return Number.NaN;n=n*t+s}return n}function oc(e){if(e=e.trim(),e==="")return 0;let t=!1;e.startsWith("-")?(t=!0,e=e.slice(1)):e.startsWith("+")&&(e=e.slice(1));let n,r=e.match(/^(\d+)#([a-zA-Z0-9@_]+)$/);if(r){let s=Number.parseInt(r[1],10);s>=2&&s<=64?n=sh(r[2],s):n=0}else/^0[xX][0-9a-fA-F]+$/.test(e)?n=Number.parseInt(e,16):/^0[0-7]+$/.test(e)?n=Number.parseInt(e,8):n=Number.parseInt(e,10);return Number.isNaN(n)&&(n=0),t?-n:n}function Es(e){if(e=e.trim(),e==="")return{value:0,valid:!0};let t=!1;if(e.startsWith("-")?(t=!0,e=e.slice(1)):e.startsWith("+")&&(e=e.slice(1)),!/^\d+$/.test(e))return{value:0,valid:!1};let n=Number.parseInt(e,10);return Number.isNaN(n)?{value:0,valid:!1}:{value:t?-n:n,valid:!0}}function ih(e){let t="",n=0;for(;n<e.length;)if(e[n]==="\\"&&n+1<e.length)t+=e[n]+e[n+1],n+=2;else if(e[n]==="["){let r=oh(e,n);t+=r.converted,n=r.endIndex}else t+=e[n],n++;return t}function oh(e,t){let n=t+1,r="[";n<e.length&&(e[n]==="^"||e[n]==="!")&&(r+="^",n++);let s=!1;n<e.length&&e[n]==="]"&&(s=!0,n++);let i=!1;n<e.length&&e[n]==="["&&n+1<e.length&&e[n+1]!==":"&&(i=!0,n++);let o="",a=!1;for(;n<e.length;){let l=e[n];if(l==="]"){a=!0,n++;break}if(l==="["&&n+1<e.length&&e[n+1]===":"){let u=e.indexOf(":]",n+2);if(u!==-1){let c=e.slice(n+2,u);o+=ah(c),n=u+2;continue}}if(l==="["&&n+1<e.length){let u=e[n+1];if(u==="."||u==="="){let c=`${u}]`,f=e.indexOf(c,n+2);if(f!==-1){let d=e.slice(n+2,f);o+=d,n=f+2;continue}}}if(l==="\\"&&n+1<e.length){o+=l+e[n+1],n+=2;continue}o+=l,n++}return a?(s&&(r+="\\]"),i&&(r+="\\["),r+=o,r+="]",{converted:r,endIndex:n}):{converted:"\\[",endIndex:t+1}}function ah(e){return new Map([["alnum","a-zA-Z0-9"],["alpha","a-zA-Z"],["ascii","\\x00-\\x7F"],["blank"," \\t"],["cntrl","\\x00-\\x1F\\x7F"],["digit","0-9"],["graph","!-~"],["lower","a-z"],["print"," -~"],["punct","!-/:-@\\[-`{-~"],["space"," \\t\\n\\r\\f\\v"],["upper","A-Z"],["word","a-zA-Z0-9_"],["xdigit","0-9A-Fa-f"]]).get(e)??""}function Zi(e,t,n){if(n&&e.length>=n.maxElements)throw new C(`array element limit exceeded (${n.maxElements})`,"array_elements");e.push(t)}function Ot(e,t){if(t&&W(e)>t.maxStringBytes)throw new C(`array assignment string limit exceeded (${t.maxStringBytes} bytes)`,"string_length");let n=[],r="",s=!1,i=!1,o=!1,a=!1;for(let l of e){if(o){r+=l,o=!1,a=!0;continue}if(l==="\\"){o=!0;continue}if(l==="'"&&!i){s||(a=!0),s=!s;continue}if(l==='"'&&!s){i||(a=!0),i=!i;continue}if((l===" "||l===" "||l===`
131
+ `)&&!s&&!i){a&&(Zi(n,r,t),r="",a=!1);continue}r+=l,a=!0}return a&&Zi(n,r,t),n}function bs(e,t){if(t&&W(e)>t.maxStringBytes)throw new C(`array assignment string limit exceeded (${t.maxStringBytes} bytes)`,"string_length");let n=[],r=0;for(;r<e.length;){for(;r<e.length&&/\s/.test(e[r]);)r++;if(r>=e.length)break;if(e[r]!=="["){r++;continue}r++;let s="";if(e[r]==="'"||e[r]==='"'){let o=e[r];for(r++;r<e.length&&e[r]!==o;)s+=e[r],r++;e[r]===o&&r++}else for(;r<e.length&&e[r]!=="]"&&e[r]!=="=";)s+=e[r],r++;for(;r<e.length&&e[r]!=="]";)r++;if(e[r]==="]"&&r++,e[r]!=="=")continue;r++;let i="";if(e[r]==="'"||e[r]==='"'){let o=e[r];for(r++;r<e.length&&e[r]!==o;)e[r]==="\\"&&r+1<e.length&&r++,i+=e[r],r++;e[r]===o&&r++}else for(;r<e.length&&!/\s/.test(e[r]);)i+=e[r],r++;Zi(n,[s,i],t)}return n}function dc(e,t){let n=e.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(n)return{name:n[1],isArray:!0,arrayElements:Ot(n[2],t)};let r=e.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([^\]]+)\]=(.*)$/s);if(r)return{name:r[1],isArray:!1,arrayIndex:r[2],value:r[3]};if(e.includes("=")){let s=e.indexOf("=");return{name:e.slice(0,s),isArray:!1,value:e.slice(s+1)}}return{name:e,isArray:!1}}async function lh(e,t){try{let n=new G,r=te(n,t);return await X(e,r.expression)}catch{let n=parseInt(t,10);return Number.isNaN(n)?0:n}}async function pc(e,t,n={}){let{name:r,isArray:s,arrayElements:i,value:o,arrayIndex:a}=t,{makeReadonly:l=!1,checkReadonly:u=!0}=n;if(u){let c=ue(e,r);if(c)return c}if(s&&i){e.executionScope.consumeWork(i.length,"array assignment");let c=Ae(e,r),f=c?Le(c):void 0,d=e.state.env.get(r);try{ye(e,r);for(let p=0;p<i.length;p++)j(e,r,p,i[p]);e.state.env.delete(r)}catch(p){throw e.state.arrays??=new Map,f?e.state.arrays.set(r,f):e.state.arrays.delete(r),d===void 0?e.state.env.delete(r):e.state.env.set(r,d),p}}else if(a!==void 0&&o!==void 0){let c=await lh(e,a);j(e,r,c,o)}else o!==void 0&&e.state.env.set(r,o);return l&&je(e,r),null}function en(e,t){e.state.localVarDepth=e.state.localVarDepth||new Map,e.state.localVarDepth.set(t,e.state.callDepth)}function Qi(e,t){return e.state.localVarDepth?.get(t)}function Ss(e,t){e.state.localVarDepth?.delete(t)}function hc(e,t,n){e.state.localVarStack=e.state.localVarStack||new Map;let r=e.state.localVarStack.get(t)||[];r.push({value:n,scopeIndex:e.state.localScopes.length-1}),e.state.localVarStack.set(t,r)}function As(e,t){let n=e.state.localVarStack?.get(t);if(!(!n||n.length===0))return n.pop()}function mc(e,t){if(e.state.localVarStack)for(let[n,r]of e.state.localVarStack.entries()){for(;r.length>0&&r[r.length-1].scopeIndex===t;)r.pop();r.length===0&&e.state.localVarStack.delete(n)}}var Ki=new Set([":",".","break","continue","eval","exec","exit","export","readonly","return","set","shift","trap","unset"]);function yc(e){return Ki.has(e)}var Xi=new Set(["if","then","else","elif","fi","case","esac","for","select","while","until","do","done","in","function","{","}","time","[[","]]","!"]),Vn=new Set([":","true","false","cd","export","unset","exit","local","set","break","continue","return","eval","shift","getopts","compgen","complete","compopt","pushd","popd","dirs","source",".","read","mapfile","readarray","declare","typeset","readonly","let","command","shopt","exec","test","[","echo","printf","pwd","alias","unalias","type","hash","ulimit","umask","trap","times","wait","kill","jobs","fg","bg","disown","suspend","fc","history","help","enable","builtin","caller"]);var Yi="__file__:",Ji="__file_append__:",no="__rw__:",eo="__dupout__:",to="__dupin__:",xe=3;function uh(e){let t=e.slice(no.length),n=t.indexOf(":");if(n===-1)return null;let r=Number.parseInt(t.slice(0,n),10);if(Number.isNaN(r)||r<0)return null;let s=n+1,i=t.slice(s,s+r),o=t.slice(s+r+1),a=o.indexOf(":");if(a===-1)return null;let l=Number.parseInt(o.slice(0,a),10);return Number.isNaN(l)||l<0?null:{path:i,position:l,content:o.slice(a+1)}}function gc(e,t){let n=Number.parseInt(e.slice(t.length),10);return Number.isNaN(n)?null:n}function ch(e){if(e.startsWith(Yi))return{kind:"output",path:e.slice(Yi.length),append:!1};if(e.startsWith(Ji))return{kind:"output",path:e.slice(Ji.length),append:!0};if(e.startsWith(no)){let t=uh(e);if(t)return{kind:"readwrite",...t}}if(e.startsWith(eo)){let t=gc(e,eo);if(t!==null)return{kind:"dup-out",sourceFd:t}}if(e.startsWith(to)){let t=gc(e,to);if(t!==null)return{kind:"dup-in",sourceFd:t}}return{kind:"input",content:e}}function ro(e){switch(e.kind){case"input":return e.content;case"output":return`${e.append?Ji:Yi}${e.path}`;case"readwrite":return`${no}${e.path.length}:${e.path}:${e.position}:${e.content}`;case"dup-out":return`${eo}${e.sourceFd}`;case"dup-in":return`${to}${e.sourceFd}`;case"closed":throw new Error("Closed descriptors have no table encoding")}}function fh(e){return e.state.fileDescriptors??=new Map,e.state.fileDescriptors}function dh(e,t,n){n?(e.state.inputFds??=new Set,e.state.inputFds.add(t)):e.state.inputFds?.delete(t)}function zn(e,t){return e.state.fdAliases?.get(t)}function tn(e,t){return[...zn(e,t)??[t]]}function wc(e,t){let n=zn(e,t);if(n&&(n.delete(t),e.state.fdAliases?.delete(t),n.size<2))for(let r of n)e.state.fdAliases?.delete(r)}function so(e,t,n){if(t===n)return;e.state.fdAliases??=new Map;let r=zn(e,n)??new Set([n]);r.add(t);for(let s of r)e.state.fdAliases.set(s,r)}function vs(e,t){return e.state.fileDescriptors?.get(t)}function st(e,t){let n=vs(e,t);if(n===void 0)return;let r=e.state.inputFds?.has(t)?{kind:"input",content:n}:ch(n);return e.state.deviceFds?.has(t)&&(r.kind==="input"||r.kind==="readwrite")?{...r,device:!0}:r}function bn(e,t){return e.state.fileDescriptors?.has(t)===!0}function io(e,t,n,r,s=!1){let i=fh(e);i.has(t)||rc(e),i.set(t,n),dh(e,t,r),s?(e.state.deviceFds??=new Set,e.state.deviceFds.add(t)):e.state.deviceFds?.delete(t)}function xs(e,t,n,r=!1,s=!1){wc(e,t),io(e,t,n,r,s)}function wt(e,t,n){xs(e,t,ro(n),n.kind==="input",(n.kind==="input"||n.kind==="readwrite")&&n.device===!0)}function kt(e,t){e.state.fileDescriptors?.delete(t),e.state.inputFds?.delete(t),e.state.deviceFds?.delete(t),wc(e,t)}function $s(e,t,n){let r=vs(e,n);return r===void 0?!1:(xs(e,t,r,e.state.inputFds?.has(n)===!0,e.state.deviceFds?.has(n)===!0),so(e,t,n),!0)}function oo(e,t,n){let r=vs(e,n);if(r===void 0)return!1;if(t===n)return!0;let s=e.state.inputFds?.has(n)===!0,i=e.state.deviceFds?.has(n)===!0,o=[...zn(e,n)??[]].filter(l=>l!==n);kt(e,n),xs(e,t,r,s,i);let a=o.find(l=>bn(e,l));return a!==void 0&&so(e,t,a),!0}function ks(e,t){let n=st(e,t);if(n===void 0)return{error:"not-open"};switch(n.kind){case"input":return{content:n.content};case"readwrite":return{content:n.content.slice(n.position)};case"output":case"dup-out":return{error:"write-only"};case"dup-in":return{error:"not-open"};case"closed":return{error:"not-open"}}}function nn(e,t,n){let r=st(e,t);if(r===void 0)return;let s;if(r.kind==="input")s={...r,content:r.content.slice(n)};else if(r.kind==="readwrite")s={...r,position:r.position+n};else return;let i=ro(s),o=s.kind==="input";for(let a of zn(e,t)??[t])io(e,a,i,o,s.device===!0)}async function ao(e,t,n,r,s){if(t.kind==="output")return await e.fs.appendFile(t.path,r,s),!0;let o=n.map(c=>st(e,c)).find(c=>c?.kind==="readwrite")??t;if(o.kind!=="readwrite")return!1;let a=o.content.slice(0,o.position)+r+o.content.slice(o.position+r.length),l={...o,position:o.position+r.length,content:a};await e.fs.writeFile(o.path,a,s);let u=ro(l);for(let c of n)bn(e,c)&&io(e,c,u,!1,l.device===!0);return!0}function rn(e,t,n){if(t.has(n))return;let r=zn(e,n);t.set(n,{raw:vs(e,n),isInput:e.state.inputFds?.has(n)===!0,isDevice:e.state.deviceFds?.has(n)===!0,aliases:r?[...r].filter(s=>s!==n):[]})}function Ps(e,t){let n=e.state.fileDescriptors;if(n)for(let[r,{raw:s,isInput:i,isDevice:o,aliases:a}]of t){if(s===void 0){kt(e,r);continue}xs(e,r,s,i,o);let l=a.find(u=>n.has(u));l!==void 0&&so(e,r,l)}}function lo(e){switch(e.operator){case"<":case"<>":case"<<":case"<<-":case"<<<":case"<&":return e.fd??0;case">":case">>":case">|":case">&":return e.fd??1;default:return null}}function Ec(e){if(e.fdVariable)return!1;let t=lo(e);return t!==null&&t>=xe}async function ph(e,t,n,r){try{if(!await e.fs.exists(t))return null;if((await e.fs.stat(t)).isDirectory)return`bash: ${n}: Is a directory
131
132
  `;if(r.checkNoclobber&&e.state.options.noclobber&&!r.isClobber&&n!=="/dev/null")return`bash: ${n}: cannot overwrite existing file
132
133
  `}catch{return`bash: ${n}: cannot open redirect target
133
- `}return null}function yc(e){let n=Math.min(e.length,8192);for(let r=0;r<n;r++)if(e.charCodeAt(r)>127)return"utf8";return"binary"}var pr="scoped",wc="bare",Ec="persistent",lh=e=>new P(`too many open file descriptors (max ${e.limits.maxFileDescriptors})`,"file_descriptors"),uh=(e,t)=>bn(e,t)||(e.state.fileDescriptors?.size??0)<e.limits.maxFileDescriptors,gc=e=>{let t=Math.max(e.state.nextFd??10,10);for(;bn(e,t);)t+=1;return t},xs=e=>{let t=e.endsWith("-"),n=t?e.slice(0,-1):e;return/^\d+$/.test(n)?{sourceFd:Number.parseInt(n,10),move:t}:null},ch=(e,t,n)=>{let r=Je(e,t);return t<we?r?{kind:"entry",entry:r,descriptors:tn(e,t)}:{kind:"standard",fd:t}:r?n?r.kind==="input"||r.kind==="readwrite"||r.kind==="dup-in"?{kind:"entry",entry:r,descriptors:tn(e,t)}:null:r.kind==="output"||r.kind==="readwrite"||r.kind==="dup-out"?{kind:"entry",entry:r,descriptors:tn(e,t)}:null:null};async function zn(e,t,n,r,s=!0){let i=e.fs.resolvePath(e.state.cwd,t),o=await ah(e,i,t,{checkNoclobber:!n,isClobber:r});if(o)return{error:L("",o,1)};if(t==="/dev/full")return{error:L("",`bash: /dev/full: No space left on device
134
- `,1)};if(t==="/dev/stdout")return{entry:{kind:"dup-out",sourceFd:1}};if(t==="/dev/stderr")return{entry:{kind:"dup-out",sourceFd:2}};try{n?await e.fs.appendFile(i,"","binary"):await e.fs.writeFile(i,"","binary")}catch(a){if(!s)throw a;return{error:L("",`bash: ${t}: cannot open redirect target
135
- `,1)}}return{entry:{kind:"output",path:i,append:n}}}async function ao(e,t,n){let r=e.fs.resolvePath(e.state.cwd,t);try{let s=await e.fs.readFile(r);return n?{entry:{kind:"readwrite",path:r,position:0,content:s}}:{entry:{kind:"input",content:s}}}catch{if(!n)return{error:L("",`bash: ${t}: No such file or directory
136
- `,1)};try{return await e.fs.writeFile(r,"","binary"),{entry:{kind:"readwrite",path:r,position:0,content:""}}}catch{return{error:L("",`bash: ${t}: No such file or directory
137
- `,1)}}}}var fh=async(e,t)=>{let n=await ne(e,t.content);return t.stripTabs?n.split(`
134
+ `}return null}var Sn="/dev/null",Cs=new Set([Sn,"/dev/zero","/dev/random","/dev/urandom"]);function bc(e){let n=Math.min(e.length,8192);for(let r=0;r<n;r++)if(e.charCodeAt(r)>127)return"utf8";return"binary"}function hr(e,t){let{entry:n}=e;if(n.kind==="dup-out"){if(n.sourceFd===1)return{kind:"live-stdout"};if(n.sourceFd===2)return{kind:"live-stderr"}}return n.kind==="output"||n.kind==="readwrite"?n.path===Sn?{kind:"discard"}:{kind:"descriptor",source:e}:{kind:"invalid-output",fd:t}}var mr="scoped",Ac="bare",vc="persistent",hh=e=>new C(`too many open file descriptors (max ${e.limits.maxFileDescriptors})`,"file_descriptors"),mh=(e,t)=>bn(e,t)||(e.state.fileDescriptors?.size??0)<e.limits.maxFileDescriptors,Sc=e=>{let t=Math.max(e.state.nextFd??10,10);for(;bn(e,t);)t+=1;return t},uo=e=>{let t=e.endsWith("-"),n=t?e.slice(0,-1):e;return/^\d+$/.test(n)?{sourceFd:Number.parseInt(n,10),move:t}:null},yh=(e,t,n)=>{let r=st(e,t);return r?n?r.kind==="input"||r.kind==="readwrite"||r.kind==="dup-in"?{kind:"entry",entry:r,descriptors:tn(e,t)}:null:r.kind==="output"||r.kind==="readwrite"||r.kind==="dup-out"?{kind:"entry",entry:r,descriptors:tn(e,t)}:null:null},gh=new Map([["ENOENT","No such file or directory"],["ENOTDIR","Not a directory"]]);async function qn(e,t,n,r,s=!0){let i=e.fs.resolvePath(e.state.cwd,t);if(i===Sn)return{entry:{kind:"output",path:Sn,append:n}};let o=await ph(e,i,t,{checkNoclobber:!n,isClobber:r});if(o)return{error:T("",o,1)};if(t==="/dev/full")return{error:T("",`bash: /dev/full: No space left on device
135
+ `,1)};if(t==="/dev/stdout")return{entry:{kind:"dup-out",sourceFd:1}};if(t==="/dev/stderr")return{entry:{kind:"dup-out",sourceFd:2}};try{n?await e.fs.appendFile(i,"","binary"):await e.fs.writeFile(i,"","binary")}catch(a){let l=fa(a),u=l&&gh.get(l);if(u)return{error:T("",`bash: ${t}: ${u}
136
+ `,1)};if(!s)throw a;return{error:T("",`bash: ${t}: cannot open redirect target
137
+ `,1)}}return{entry:{kind:"output",path:i,append:n}}}async function co(e,t,n){let r=e.fs.resolvePath(e.state.cwd,t);try{let s=r===Sn?"":await e.fs.readFile(r);return n?{entry:{kind:"readwrite",path:r,position:0,content:s,device:Cs.has(r)}}:{entry:{kind:"input",content:s,device:Cs.has(r)}}}catch{if(!n)return{error:T("",`bash: ${t}: No such file or directory
138
+ `,1)};try{return await e.fs.writeFile(r,"","binary"),{entry:{kind:"readwrite",path:r,position:0,content:"",device:Cs.has(r)}}}catch{return{error:T("",`bash: ${t}: No such file or directory
139
+ `,1)}}}}var wh=async(e,t)=>{let n=await ne(e,t.content);return t.stripTabs?n.split(`
138
140
  `).map(r=>r.replace(/^\t+/,"")).join(`
139
- `):n};async function dh(e,t,n,r){let s=new Map,i=new Map,o=(y,g)=>e.state.closedStandardFds?.has(y)?{kind:"closed"}:Je(e,y)??g,a=new Map([[0,o(0,{kind:"dup-in",sourceFd:0})],[1,o(1,{kind:"dup-out",sourceFd:1})],[2,o(2,{kind:"dup-out",sourceFd:2})]]),l=r.numericSnapshot,u,c=-1,f=a.get(0);f?.kind==="input"?(u=f.content,c=0):f?.kind==="readwrite"&&(u=f.content.slice(f.position),c=0);let d=()=>({targets:s,dupSources:i,standardRoutes:a,stdin:u,stdinSourceFd:c,error:null}),p=async(y,g,b)=>{let v={...d(),error:await sn(e,y,t.slice(0,g),s,i,a)};return b?{...v,errorCause:b}:v},h=async(y,g)=>{if(uh(e,y))return null;let b=lh(e);return p(L("",b.stderr,P.EXIT_CODE),g,b)},m=(y,g)=>{y!==null&&y<we&&a.set(y,g),r.policy==="persistent"&&y!==null&&y<we&&(e.state.closedStandardFds?.delete(y),it(e,y,g))},E=(y,g)=>{a.set(y,g),rn(e,r.standardSnapshot,y),r.standardClosedSnapshot.has(y)||r.standardClosedSnapshot.set(y,e.state.closedStandardFds?.has(y)===!0),e.state.closedStandardFds?.delete(y),it(e,y,g)},S=(y,g)=>{if(y<we){let b=a.get(y);return b?.kind==="closed"?null:b?{kind:"entry",entry:b,descriptors:tn(e,y)}:{kind:"standard",fd:y}}return ch(e,y,g)};for(let y=0;y<t.length;y++){let g=t[y],b=oo(g);if(g.target.type==="HereDoc"){let A=await fh(e,g.target);if(g.fdVariable){try{ue(e,g.fdVariable)}catch($){if(!($ instanceof q))throw $;return p(L($.stdout,$.stderr,$.exitCode),y,$)}let k=gc(e),N=await h(k,y);if(N)return N;rn(e,r.fdVariableSnapshot,k),r.fdVariableEnv.has(g.fdVariable)||r.fdVariableEnv.set(g.fdVariable,e.state.env.get(g.fdVariable)),it(e,k,{kind:"input",content:A}),e.state.env.set(g.fdVariable,String(k)),e.state.nextFd=k+1}else if(b!==null&&b>=we){let k=await h(b,y);if(k)return k;rn(e,l,b),it(e,b,{kind:"input",content:A})}else if(b===0||b===null)u=un(A),c=-1,m(b,{kind:"input",content:u});else{let k={kind:"input",content:A};r.policy==="persistent"?m(b,k):E(b,k)}continue}let v,x=g.operator===">&"||g.operator==="<&";if(x){if(Mi(e,g.target))return p(L("",`bash: $@: ambiguous redirect
140
- `,1),y);v=await ne(e,g.target)}else if(g.operator==="<<<")v=await ne(e,g.target);else{let A=await Hu(e,g.target);if("error"in A)return p(L("",A.error,1),y);v=A.target}if(s.set(y,v),v.includes("\0"))return p(L("",`bash: ${v.replace(/\0/g,"")}: No such file or directory
141
- `,1),y);if(g.fdVariable){try{ue(e,g.fdVariable)}catch(D){if(!(D instanceof q))throw D;return p(L(D.stdout,D.stderr,D.exitCode),y,D)}if(x&&v==="-"){let D=Number.parseInt(e.state.env.get(g.fdVariable)??"",10);Number.isNaN(D)||(rn(e,r.fdVariableSnapshot,D),kt(e,D));continue}let A=gc(e),k=x?xs(v):null;if(k&&!S(k.sourceFd,g.operator==="<&"))return p(L("",`bash: ${k.sourceFd}: Bad file descriptor
142
- `,1),y);if(!(k?.move===!0&&k.sourceFd>=we)){let D=await h(A,y);if(D)return D}rn(e,r.fdVariableSnapshot,A),r.fdVariableEnv.has(g.fdVariable)||r.fdVariableEnv.set(g.fdVariable,e.state.env.get(g.fdVariable));let $,C;if(x){let D=k;if(D){let B=S(D.sourceFd,g.operator==="<&");if(!B)return p(L("",`bash: ${D.sourceFd}: Bad file descriptor
143
- `,1),y);C=D,B.kind==="standard"?$={kind:g.operator==="<&"?"dup-in":"dup-out",sourceFd:B.fd}:D.sourceFd<we&&($=B.entry)}else{if(g.operator==="<&")return p(L("",`bash: ${v}: ambiguous redirect
144
- `,1),y);let B=await zn(e,v,!1,!1);if(B.error)return p(B.error,y);$=B.entry}}else if(g.operator===">"||g.operator===">|"||g.operator===">>"||g.operator==="&>"||g.operator==="&>>"){let D=g.operator===">>"||g.operator==="&>>",B=await zn(e,v,D,g.operator===">|");if(B.error)return p(B.error,y);$=B.entry}else if(g.operator==="<<<")$={kind:"input",content:`${v}
145
- `};else if(g.operator==="<"||g.operator==="<>"){let D=await ao(e,v,g.operator==="<>");if(D.error)return p(D.error,y);$=D.entry}if(C&&C.sourceFd>=we){if(!(C.move?so(e,A,C.sourceFd):Ss(e,A,C.sourceFd)))return p(L("",`bash: ${C.sourceFd}: Bad file descriptor
146
- `,1),y)}else $&&it(e,A,$);C?.move&&C.sourceFd!==A&&C.sourceFd<we&&kt(e,C.sourceFd),e.state.env.set(g.fdVariable,String(A)),e.state.nextFd=A+1;continue}if(mc(g)){let A=b;if(x&&v==="-"){rn(e,l,A),kt(e,A);continue}let k=x?xs(v):null;if(k&&!S(k.sourceFd,g.operator==="<&"))return p(L("",`bash: ${k.sourceFd}: Bad file descriptor
147
- `,1),y);if(!(k?.move===!0&&k.sourceFd>=we)){let $=await h(A,y);if($)return $}if(rn(e,l,A),x){let $=k;if(!$){if(g.operator==="<&")return p(L("",`bash: ${v}: ambiguous redirect
148
- `,1),y);let D=await zn(e,v,!1,!1);if(D.error)return p(D.error,y);it(e,A,D.entry);continue}let C=S($.sourceFd,g.operator==="<&");if(!C)return p(L("",`bash: ${$.sourceFd}: Bad file descriptor
149
- `,1),y);if(C.kind==="standard")it(e,A,{kind:g.operator==="<&"?"dup-in":"dup-out",sourceFd:C.fd});else if($.sourceFd<we)it(e,A,C.entry);else if(!($.move?so(e,A,$.sourceFd):Ss(e,A,$.sourceFd)))return p(L("",`bash: ${$.sourceFd}: Bad file descriptor
150
- `,1),y);$.move&&$.sourceFd!==A&&$.sourceFd<we&&kt(e,$.sourceFd);continue}if(g.operator===">"||g.operator===">|"||g.operator===">>"){let $=await zn(e,v,g.operator===">>",g.operator===">|");if($.error)return p($.error,y);it(e,A,$.entry)}else if(g.operator==="<<<")it(e,A,{kind:"input",content:`${v}
151
- `});else if(g.operator==="<"||g.operator==="<>"){let $=await ao(e,v,g.operator==="<>");if($.error)return p($.error,y);it(e,A,$.entry)}continue}if(x){if(v==="-"){b===0&&(u="",c=-1),b!==null&&b<we&&(a.set(b,{kind:"closed"}),r.policy==="persistent"&&(kt(e,b),e.state.closedStandardFds??=new Set,e.state.closedStandardFds.add(b)));continue}let A=xs(v);if(!A){if(g.operator==="<&")return p(L("",`bash: ${v}: ambiguous redirect
152
- `,1),y);let N=await zn(e,v,!1,!1,!1);if(N.error)return p(N.error,y);let $=N.entry;i.set(y,{kind:"entry",entry:$,descriptors:[]}),g.fd==null?(m(1,$),m(2,$)):m(b,$);continue}let k=S(A.sourceFd,g.operator==="<&");if(!k)return p(L("",`bash: ${A.sourceFd}: Bad file descriptor
153
- `,1),y);if(i.set(y,k),k.kind==="entry"&&r.policy==="persistent"&&b!==null&&b<we&&A.sourceFd>=we){if(!Ss(e,b,A.sourceFd))return p(L("",`bash: ${A.sourceFd}: Bad file descriptor
154
- `,1),y);a.set(b,Je(e,b)),e.state.closedStandardFds?.delete(b)}else k.kind==="standard"?m(b,{kind:g.operator==="<&"?"dup-in":"dup-out",sourceFd:k.fd}):m(b,k.entry);if(g.operator==="<&"&&b===0)if(k.kind==="standard")u=k.fd===0?n:"",c=-1;else if(k.entry.kind==="input"||k.entry.kind==="readwrite"){let N=A.sourceFd<we&&!bn(e,A.sourceFd)?{content:k.entry.kind==="input"?k.entry.content:k.entry.content.slice(k.entry.position)}:As(e,A.sourceFd);if("error"in N)return p(L("",`bash: ${A.sourceFd}: Bad file descriptor
155
- `,1),y);u=N.content,c=bn(e,A.sourceFd)?A.sourceFd:-1}else u=n,c=-1;A.move&&(A.sourceFd>=we?kt(e,A.sourceFd):(a.set(A.sourceFd,{kind:"closed"}),r.policy==="persistent"&&(kt(e,A.sourceFd),e.state.closedStandardFds??=new Set,e.state.closedStandardFds.add(A.sourceFd))));continue}if(g.operator===">"||g.operator===">|"||g.operator===">>"||g.operator==="&>"||g.operator==="&>>"){let A=await zn(e,v,g.operator===">>"||g.operator==="&>>",g.operator===">|",!1);if(A.error)return p(A.error,y);let k=A.entry;g.operator==="&>"||g.operator==="&>>"?(m(1,k),m(2,k)):m(b,k);continue}if(g.operator==="<<<")u=un(`${v}
156
- `),c=-1,m(b,{kind:"input",content:u});else if(g.operator==="<"){let A=e.fs.resolvePath(e.state.cwd,v);try{u=await vn(e.fs,A),c=-1,m(b,{kind:"input",content:u})}catch{return p(L("",`bash: ${v}: No such file or directory
157
- `,1),y)}}else if(g.operator==="<>"){let A=await ao(e,v,!0);if(A.error)return p(A.error,y);let k=A.entry;m(b,k),b===0&&k.kind==="readwrite"&&(u=k.content,c=-1)}}return d()}function qn(e,t,n){let r={numericSnapshot:new Map,fdVariableSnapshot:new Map,standardSnapshot:new Map,standardClosedSnapshot:new Map,fdVariableEnv:new Map,nextFd:e.state.nextFd,policy:n},s=!1;return{prepare:(i="")=>dh(e,t,i,r),finish:()=>{if(!s){if(s=!0,n!=="persistent"&&vs(e,r.numericSnapshot),n!=="persistent"){vs(e,r.standardSnapshot);for(let[i,o]of r.standardClosedSnapshot)o?(e.state.closedStandardFds??=new Set,e.state.closedStandardFds.add(i)):e.state.closedStandardFds?.delete(i)}if(n==="bare"){vs(e,r.fdVariableSnapshot);for(let[i,o]of r.fdVariableEnv)o===void 0?e.state.env.delete(i):e.state.env.set(i,o);e.state.nextFd=r.nextFd}}}}}function Un(e){if(!e.error)throw new Error("Expected a redirection error");if(e.errorCause)throw e.errorCause.stdout=e.error.stdout,e.errorCause.stderr=e.error.stderr,e.errorCause;return e.error}async function lo(e,t,n,r){let s=t instanceof q||t instanceof Ie||t instanceof Me?t.exitCode:t instanceof P?P.EXIT_CODE:0,i=await sn(e,L(t.stdout,t.stderr,s),n,r.targets,r.dupSources,r.standardRoutes);t.stdout=i.stdout,t.stderr=i.stderr,t.internalOutputAccounting=i.internalOutputAccounting??{stdout:F(i.stdout),stderr:F(i.stderr)}}async function et(e,t,n,r){let s=qn(e,t,pr),i;try{if(i=await s.prepare(n),i.error)return Un(i);let o=e.state.groupStdin,a=e.state.groupStdinSourceFd;i.stdin!==void 0&&(e.state.groupStdin=i.stdin,e.state.groupStdinSourceFd=i.stdinSourceFd);try{let l=await r(i);return await sn(e,l,t,i.targets,i.dupSources,i.standardRoutes)}finally{i.stdin!==void 0&&(e.state.groupStdin=o,e.state.groupStdinSourceFd=a)}}catch(o){throw!(o instanceof xn)||!i||await lo(e,o,t,i),o}finally{s.finish()}}async function sn(e,t,n,r,s=new Map,i=new Map,o="bash",a=!1){n.length>0&&(t=e.executionScope.accountResult(t,"redirection"));let{stdout:l,stderr:u,exitCode:c}=t,d=t.stdoutKind==="bytes"||t.stdoutKind===void 0&&t.stdoutEncoding==="binary"?"binary":"utf8",p=b=>d,h={kind:"live-stdout"},m={kind:"live-stderr"},E=b=>{if(!b)return null;if(b.kind==="entry"){if(b.entry.kind==="dup-out"){if(b.entry.sourceFd===1)return{kind:"live-stdout"};if(b.entry.sourceFd===2)return{kind:"live-stderr"}}return b.entry.kind==="output"||b.entry.kind==="readwrite"?{kind:"descriptor",source:b}:null}return b.fd===1?h:b.fd===2?m:null},S=b=>{let v=i.get(b)??Je(e,b);return v?v.kind==="closed"?{kind:"invalid-output",fd:b}:v.kind==="input"||v.kind==="dup-in"?{kind:"invalid-output",fd:b}:v.kind==="dup-out"?v.sourceFd===1?{kind:"live-stdout"}:v.sourceFd===2?{kind:"live-stderr"}:null:v.kind==="output"||v.kind==="readwrite"?{kind:"descriptor",source:{kind:"entry",entry:v,descriptors:tn(e,b)}}:null:null};h=S(1)??h,m=S(2)??m;for(let b=0;b<n.length;b++){let v=n[b];if(v.target.type==="HereDoc"||v.fdVariable)continue;let x=r.get(b);if(x!==void 0)switch(v.operator){case">":case">|":case">>":{let A=v.fd??1;if(A!==1&&A!==2)break;let k=v.operator===">>";if(x==="/dev/stdout"){A===2&&(m=h);break}if(x==="/dev/stderr"){A===1&&(h=m);break}if(x==="/dev/full"){u+=`bash: echo: write error: No space left on device
158
- `,c=1,A===1&&(l="");break}if(x==="/dev/null"&&A===2){m={kind:"discard"};break}let N=e.fs.resolvePath(e.state.cwd,x);A===1?h={kind:"file",path:N,append:k}:m={kind:"file",path:N,append:k};break}case">&":case"<&":{let A=v.fd??(v.operator==="<&"?0:1);if(A>=we||A===0)break;if(x==="-"){A===1?h={kind:"discard"}:m={kind:"discard"};break}let k=E(s.get(b));if(!k)break;v.fd==null&&xs(x)===null?(h=k,m=k):A===1?h=k:A===2&&(m=k);break}case"&>":{h={kind:"file",path:e.fs.resolvePath(e.state.cwd,x),append:!1},m=h;break}case"&>>":{h={kind:"file",path:e.fs.resolvePath(e.state.cwd,x),append:!0},m=h;break}}}if(l!==""||u!==""){let b=l,v=u;l="",u="",h.kind==="invalid-output"&&b!==""&&(b="",v+=`${a?"":"bash: "}${o}: write error: Bad file descriptor
159
- `,c=1),m.kind==="invalid-output"&&(v="");let x=async(A,k,N)=>{A.append?await e.fs.appendFile(A.path,k,N):await e.fs.writeFile(A.path,k,N)};if(h===m&&(h.kind==="file"||h.kind==="descriptor")){let A=b+v;A!==""&&(h.kind==="file"?await x(h,A,p(A)):await io(e,h.source.entry,h.source.descriptors,A,p(A)))}else for(let[A,k,N]of[[b,h,!0],[v,m,!1]])if(A!=="")switch(k.kind){case"live-stdout":l+=A;break;case"live-stderr":u+=A;break;case"file":await x(k,A,N?p(A):yc(A));break;case"descriptor":await io(e,k.source.entry,k.source.descriptors,A,N?p(A):yc(A));break;case"invalid-output":break;case"discard":break}}let y=L(l,u,c);if(t.stdoutKind&&(y.stdoutKind=t.stdoutKind),t.stdoutEncoding==="binary"&&(y.stdoutEncoding="binary"),t.internalPipeStatusOverride&&(y.internalPipeStatusOverride=t.internalPipeStatusOverride),n.length>0||e.state.fileDescriptors?.has(1)===!0||e.state.fileDescriptors?.has(2)===!0){let b=(t.internalOutputAccounting?.stdout??0)+(t.internalOutputAccounting?.stderr??0),v=F(y.stdout),x=F(y.stderr),A=Math.min(v,b);y.internalOutputAccounting={stdout:A,stderr:Math.min(x,b-A)},e.executionScope.accountResult(y,"redirection")}else t.internalOutputAccounting&&(y.internalOutputAccounting=t.internalOutputAccounting);return y}function bc(e,t){if(e.state.options.posix&&Zi.has(t.name)){let r=`bash: line ${e.state.currentLine}: \`${t.name}': is a special builtin
160
- `;throw new q(2,"",r)}let n={...t,sourceFile:t.sourceFile??e.state.currentSource??"main"};return e.state.functions.set(t.name,n),J}async function $s(e,t,n,r="",s,i=!1){e.state.callDepth++,e.state.callDepth>e.limits.maxCallDepth&&(e.state.callDepth--,Yt(`${t.name}: maximum recursion depth (${e.limits.maxCallDepth}) exceeded, increase executionLimits.maxCallDepth`,"recursion")),e.state.funcNameStack||(e.state.funcNameStack=[]),e.state.callLineStack||(e.state.callLineStack=[]),e.state.sourceStack||(e.state.sourceStack=[]),e.state.funcNameStack.unshift(t.name),e.state.callLineStack.unshift(s??e.state.currentLine),e.state.sourceStack.unshift(t.sourceFile??"main"),e.state.localScopes.push(new Map),e.state.localArrayScopes??=[],e.state.localArrayScopes.push(new Map),e.state.localExportedVars||(e.state.localExportedVars=[]),e.state.localExportedVars.push(new Set);let o=new Map,a=Number.parseInt(e.state.env.get("#")??"0",10),l=Math.max(n.length,a);for(let p=0;p<l;p++){let h=String(p+1);o.set(h,e.state.env.get(h)),p<n.length?e.state.env.set(h,n[p]):e.state.env.delete(h)}o.set("@",e.state.env.get("@")),o.set("#",e.state.env.get("#")),e.state.env.set("@",n.join(" ")),e.state.env.set("#",String(n.length));let u=!1,c=()=>{if(u)return;u=!0;let p=e.state.localScopes.length-1,h=e.state.localScopes.pop(),m=e.state.localArrayScopes?.pop();if(h)for(let[E,S]of h)S===void 0?e.state.env.delete(E):e.state.env.set(E,S);if(m){e.state.arrays??=new Map;for(let[E,S]of m)S===void 0?(e.state.arrays.delete(E),e.state.associativeArrays?.delete(E)):(e.state.arrays.set(E,Le(S)),e.state.associativeArrays??=new Set,S.kind==="associative"?e.state.associativeArrays.add(E):e.state.associativeArrays.delete(E))}if(fc(e,p),e.state.fullyUnsetLocals)for(let[E,S]of e.state.fullyUnsetLocals.entries())S===p&&e.state.fullyUnsetLocals.delete(E);if(e.state.localExportedVars&&e.state.localExportedVars.length>0){let E=e.state.localExportedVars.pop();if(E)for(let S of E)e.state.exportedVars?.delete(S)}for(let[E,S]of o)S===void 0?e.state.env.delete(E):e.state.env.set(E,S);e.state.funcNameStack?.shift(),e.state.callLineStack?.shift(),e.state.sourceStack?.shift(),e.state.callDepth--},f=null,d=qn(e,t.redirections,pr);try{if(f=await d.prepare(r),f.error)return Un(f);let p=f.stdin??r,h=i||f.stdin!==void 0||r!=="",m=await e.executeCommand(t.body,p,h);return sn(e,m,t.redirections,f.targets,f.dupSources,f.standardRoutes)}catch(p){if(p instanceof xn&&f&&(await lo(e,p,t.redirections,f),p instanceof Ie))return L(p.stdout,p.stderr,p.exitCode);throw p}finally{d.finish(),c()}}var Ac=e=>e.type==="Escaped"?T.literal(`\\${e.value}`):e.type==="DoubleQuoted"?{...e,parts:e.parts.map(Ac)}:e,vc=["!","[[","]]","case","do","done","elif","else","esac","fi","for","function","if","in","then","time","until","while","{","}"],fo=[".",":","[","alias","bg","bind","break","builtin","caller","cd","command","compgen","complete","compopt","continue","declare","dirs","disown","echo","enable","eval","exec","exit","export","false","fc","fg","getopts","hash","help","history","jobs","kill","let","local","logout","mapfile","popd","printf","pushd","pwd","read","readarray","readonly","return","set","shift","shopt","source","suspend","test","times","trap","true","type","typeset","ulimit","umask","unalias","unset","wait"],ph=["autocd","assoc_expand_once","cdable_vars","cdspell","checkhash","checkjobs","checkwinsize","cmdhist","compat31","compat32","compat40","compat41","compat42","compat43","compat44","complete_fullquote","direxpand","dirspell","dotglob","execfail","expand_aliases","extdebug","extglob","extquote","failglob","force_fignore","globasciiranges","globstar","gnu_errfmt","histappend","histreedit","histverify","hostcomplete","huponexit","inherit_errexit","interactive_comments","lastpipe","lithist","localvar_inherit","localvar_unset","login_shell","mailwarn","no_empty_cmd_completion","nocaseglob","nocasematch","nullglob","progcomp","progcomp_alias","promptvars","restricted_shell","shift_verbose","sourcepath","xpg_echo"],hh=fo;async function po(e,t){let n=[],r=null,s="",i="",o=null,a=!1,l=!1,u=!1,c=null,f=null,d=null,p=[],h=["alias","arrayvar","binding","builtin","command","directory","disabled","enabled","export","file","function","group","helptopic","hostname","job","keyword","running","service","setopt","shopt","signal","stopped","user","variable"];for(let x=0;x<t.length;x++){let A=t[x];if(A==="-v")n.push("variable");else if(A==="-e")n.push("export");else if(A==="-f")n.push("file");else if(A==="-d")n.push("directory");else if(A==="-k")n.push("keyword");else if(A==="-A"){if(x++,x>=t.length)return _(`compgen: -A: option requires an argument
161
- `,2);let k=t[x];if(!h.includes(k))return _(`compgen: ${k}: invalid action name
162
- `,2);n.push(k)}else if(A==="-W"){if(x++,x>=t.length)return _(`compgen: -W: option requires an argument
163
- `,2);r=t[x]}else if(A==="-P"){if(x++,x>=t.length)return _(`compgen: -P: option requires an argument
164
- `,2);s=t[x]}else if(A==="-S"){if(x++,x>=t.length)return _(`compgen: -S: option requires an argument
165
- `,2);i=t[x]}else if(A==="-o"){if(x++,x>=t.length)return _(`compgen: -o: option requires an argument
166
- `,2);let k=t[x];if(k==="plusdirs")a=!0;else if(k==="dirnames")l=!0;else if(k==="default")u=!0;else if(!(k==="filenames"||k==="nospace"||k==="bashdefault"||k==="noquote"))return _(`compgen: ${k}: invalid option name
167
- `,2)}else if(A==="-F"){if(x++,x>=t.length)return _(`compgen: -F: option requires an argument
168
- `,2);f=t[x]}else if(A==="-C"){if(x++,x>=t.length)return _(`compgen: -C: option requires an argument
169
- `,2);d=t[x]}else if(A==="-X"){if(x++,x>=t.length)return _(`compgen: -X: option requires an argument
170
- `,2);c=t[x]}else if(A==="-G"){if(x++,x>=t.length)return _(`compgen: -G: option requires an argument
171
- `,2)}else if(A==="--"){p.push(...t.slice(x+1));break}else A.startsWith("-")||p.push(A)}o=p[0]??null;let m=[],E=new Set,S=()=>e.limits.maxArrayElements-m.length,y=x=>{for(let A of x){if(m.length>=e.limits.maxArrayElements)throw new P(`compgen: completion element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");if(F(A)>e.limits.maxStringLength)throw new P(`compgen: completion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");e.executionScope.consumeWork(1,"compgen completion"),m.push(A),E.add(A)}};if(l){let x=await uo(e,o,S());y(x)}if(u){let x=await Sc(e,o,S());y(x)}for(let x of n)if(x==="variable"){let A=mh(e,o,S());y(A)}else if(x==="export"){let A=yh(e,o,S());y(A)}else if(x==="function"){let A=gh(e,o,S());y(A)}else if(x==="builtin"){let A=wh(e,o,S());y(A)}else if(x==="keyword"){let A=Eh(e,o,S());y(A)}else if(x==="alias"){let A=bh(e,o,S());y(A)}else if(x==="shopt"){let A=Sh(e,o,S());y(A)}else if(x==="helptopic"){let A=Ah(e,o,S());y(A)}else if(x==="directory"){let A=await uo(e,o,S());y(A)}else if(x==="file"){let A=await Sc(e,o,S());y(A)}else if(x==="user"){let A=vh(e,o,S());y(A)}else if(x==="command"){let A=await xh(e,o,S());y(A)}if(r!==null)try{let x=await $h(e,r),A=kh(e,x,S(),o);for(let k of A)y([k])}catch(x){if(x instanceof P)throw x;return L("","",1)}if(a){let x=await uo(e,o,S(),E);for(let A of x)E.has(A)||y([A])}let g="";if(f!==null){let x=e.state.functions.get(f);if(x){let A=new Map,k=ve(e,"COMP_WORDS"),N=k?Le(k):void 0;ye(e,"COMP_WORDS"),er(e,"COMP_WORDS"),A.set("COMP_CWORD",e.state.env.get("COMP_CWORD")),e.state.env.set("COMP_CWORD","-1"),A.set("COMP_LINE",e.state.env.get("COMP_LINE")),e.state.env.set("COMP_LINE",""),A.set("COMP_POINT",e.state.env.get("COMP_POINT")),e.state.env.set("COMP_POINT","0");let $=ve(e,"COMPREPLY"),C=$?Le($):void 0,D=e.state.env.get("COMPREPLY");ye(e,"COMPREPLY"),e.state.env.delete("COMPREPLY");let B=["compgen",p[0]??"",""];try{let H=await $s(e,x,B,"");if(H.exitCode!==0)return co(e,A),jn(e,"COMP_WORDS",N),jn(e,"COMPREPLY",C),D!==void 0&&e.state.env.set("COMPREPLY",D),L("",H.stderr,1);g=H.stdout;let R=Ph(e,S());y(R)}catch(H){if(H instanceof P)throw H;return co(e,A),jn(e,"COMP_WORDS",N),jn(e,"COMPREPLY",C),D!==void 0&&e.state.env.set("COMPREPLY",D),L("","",1)}co(e,A),jn(e,"COMP_WORDS",N),jn(e,"COMPREPLY",C),D!==void 0&&e.state.env.set("COMPREPLY",D)}}if(d!==null)try{let x=dt(d),A=await e.executeScript(x);if(A.exitCode!==0)return L("",A.stderr,A.exitCode);if(A.stdout)for(let k of Ch(A.stdout))k.length>0&&y([k])}catch(x){if(x.name==="ParseException")return _(`compgen: -C: ${x.message}
172
- `,2);throw x}let b=m;if(c!==null){let x=c.startsWith("!"),A=x?c.slice(1):c;b=m.filter(k=>{let N=Bn(k,A,!1,!0,e.limits.maxCallDepth);return x?N:!N})}if(b.length===0&&o!==null)return L(g,"",1);let v=new $n(e.limits.maxOutputSize,"compgen");v.append(g);for(let x of b)v.append(s).append(x).append(i).append(`
173
- `);return Y(v.build())}function mh(e,t,n){let r=ot(e,t,n);for(let s of e.state.env.keys())/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(s)&&r.add(s);for(let s of e.state.arrays?.keys()??[])r.add(s);return r.build()}function yh(e,t,n){let r=ot(e,t,n),s=e.state.exportedVars??new Set;for(let i of s)e.state.env.has(i)&&r.add(i);return r.build()}function gh(e,t,n){let r=ot(e,t,n);for(let s of e.state.functions.keys())r.add(s);return r.build()}function wh(e,t,n){let r=ot(e,t,n);for(let s of fo)r.add(s);return r.build()}function Eh(e,t,n){let r=ot(e,t,n);for(let s of vc)r.add(s);return r.build()}function bh(e,t,n){let r=ot(e,t,n);for(let s of e.state.env.keys())if(s.startsWith("BASH_ALIAS_")){let i=s.slice(11);r.add(i)}return r.build()}function Sh(e,t,n){let r=ot(e,t,n);for(let s of ph)r.add(s);return r.build()}function Ah(e,t,n){let r=ot(e,t,n);for(let s of hh)r.add(s);return r.build()}async function uo(e,t,n=e.limits.maxArrayElements,r){let s=ot(e,null,n,r);try{let i=e.state.cwd,o=t??"";if(t){let l=t.lastIndexOf("/");if(l!==-1){let u=t.slice(0,l)||"/";o=t.slice(l+1),u.startsWith("/")?i=u:i=`${e.state.cwd}/${u}`}}let a=await e.fs.readdir(i);for(let l of a){e.executionScope.consumeWork(1,"compgen directory scan");let u=`${i}/${l}`;try{if((await e.fs.stat(u)).isDirectory&&(!o||l.startsWith(o)))if(t?.includes("/")){let f=t.lastIndexOf("/"),d=t.slice(0,f+1);s.add(d+l)}else s.add(l)}catch(c){if(c instanceof P)throw c}}}catch(i){if(i instanceof P)throw i}return s.build()}async function Sc(e,t,n=e.limits.maxArrayElements){let r=ot(e,null,n);try{let s=e.state.cwd,i=t??"";if(t){let a=t.lastIndexOf("/");if(a!==-1){let l=t.slice(0,a)||"/";i=t.slice(a+1),l.startsWith("/")?s=l:s=`${e.state.cwd}/${l}`}}let o=await e.fs.readdir(s);for(let a of o)if(e.executionScope.consumeWork(1,"compgen file scan"),!i||a.startsWith(i))if(t?.includes("/")){let l=t.lastIndexOf("/"),u=t.slice(0,l+1);r.add(u+a)}else r.add(a)}catch(s){if(s instanceof P)throw s}return r.build()}function vh(e,t,n){let r=ot(e,t,n);return r.add("root"),r.add("nobody"),r.build()}async function xh(e,t,n){let r=ot(e,t,n);for(let i of fo)r.add(i);for(let i of e.state.functions.keys())r.add(i);for(let i of e.state.env.keys())i.startsWith("BASH_ALIAS_")&&r.add(i.slice(11));for(let i of vc)r.add(i);let s=e.state.env.get("PATH")??"/usr/bin:/bin";for(let i of s.split(":"))if(i)try{let o=await e.fs.readdir(i);for(let a of o)r.add(a)}catch(o){if(o instanceof P)throw o}return r.build()}function ot(e,t,n,r){let s=new Set;return{add(i){if(e.executionScope.consumeWork(1,"compgen candidate collection"),!(t!==null&&!i.startsWith(t))&&!r?.has(i)&&!s.has(i)){if(s.size>=n)throw new P(`compgen: completion element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");if(F(i)>e.limits.maxStringLength)throw new P(`compgen: completion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");s.add(i)}},build(){return Array.from(s).sort()}}}async function $h(e,t){let r=new j().parseWordFromString(t,!1,!1);return await ne(e,T.word(r.parts.map(Ac)))}function kh(e,t,n,r){let s=e.state.env.get("IFS")??`
174
- `;if(s.length===0){if(r!==null&&!t.startsWith(r))return[];if(n===0)throw new P(`compgen: completion element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");return[t]}let i=new Set(s.split("")),o=[],a=c=>{if(!(r!==null&&!c.startsWith(r))){if(o.length>=n)throw new P(`compgen: completion element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");o.push(c)}},l="",u=0;for(;u<t.length;){let c=t[u];if(c==="\\"&&u+1<t.length){let f=t[u+1];l+=f,u+=2}else i.has(c)?(l.length>0&&(a(l),l=""),u++):(l+=c,u++)}return l.length>0&&a(l),o}function co(e,t){for(let[n,r]of t)r===void 0?e.state.env.delete(n):e.state.env.set(n,r)}function jn(e,t,n){e.state.arrays??=new Map,n?e.state.arrays.set(t,Le(n)):e.state.arrays.delete(t)}function Ph(e,t){let n=[],r=s=>{if(n.length>=t)throw new P(`compgen: completion element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");n.push(s)};if(ke(e,"COMPREPLY")){let s=G(e,"COMPREPLY");for(let[,i]of s)r(i)}else{let s=e.state.env.get("COMPREPLY");s!==void 0&&r(s)}return n}function*Ch(e){let t=0;for(;t<=e.length;){let n=e.indexOf(`
175
- `,t),r=n===-1?e.length:n;if(r>t&&(yield e.slice(t,r)),n===-1)return;t=n+1}}function hr(e){for(let t=0;t<e.length;t++){let n=e.charCodeAt(t);if(n<32||n===127)return!0}return!1}function ho(e){let t="$'";for(let n=0;n<e.length;n++){let r=e[n],s=e.charCodeAt(n);s===7?t+="\\a":s===8?t+="\\b":s===9?t+="\\t":s===10?t+="\\n":s===11?t+="\\v":s===12?t+="\\f":s===13?t+="\\r":s===27?t+="\\e":s===39?t+="\\'":s===92?t+="\\\\":s<32||s===127?t+=`\\${s.toString(8).padStart(3,"0")}`:t+=r}return t+="'",t}function xc(e){if(hr(e))return $c(e);if(e==="")return 2;if(/^[a-zA-Z0-9_/.:\-@%+,=]+$/.test(e))return F(e);let t=F(e)+2;for(let n of e)n==="'"&&(t+=3);return t}function Ee(e){return hr(e)?ho(e):e===""?"''":/^[a-zA-Z0-9_/.:\-@%+,=]+$/.test(e)?e:`'${e.replace(/'/g,"'\\''")}'`}function ks(e){if(hr(e))return $c(e);let t=F(e)+2;for(let n of e)(n==="\\"||n==='"'||n==="$"||n==="`")&&t++;return t}function on(e){return hr(e)?ho(e):`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\$/g,"\\$").replace(/`/g,"\\`")}"`}function $c(e){let t=3;for(let n of e){let r=n.codePointAt(0)??0;r===7||r===8||r===9||r===10||r===11||r===12||r===13||r===27||r===39||r===92?t+=2:r<32||r===127?t+=4:t+=F(n)}return t}function mr(e){return hr(e)?ho(e):`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\$/g,"\\$").replace(/`/g,"\\`")}"`}var Nh=["bashdefault","default","dirnames","filenames","noquote","nosort","nospace","plusdirs"];function yo(e,t){e.state.completionSpecs||(e.state.completionSpecs=new Map);let n=!1,r=!1,s=!1,i,o,a,l=[],u=[],c=[];for(let f=0;f<t.length;f++){let d=t[f];if(d==="-p")n=!0;else if(d==="-r")r=!0;else if(d==="-D")s=!0;else if(d==="-W"){if(f++,f>=t.length)return _(`complete: -W: option requires an argument
176
- `,2);i=t[f]}else if(d==="-F"){if(f++,f>=t.length)return _(`complete: -F: option requires an argument
177
- `,2);o=t[f]}else if(d==="-o"){if(f++,f>=t.length)return _(`complete: -o: option requires an argument
178
- `,2);let p=t[f];if(!Nh.includes(p))return _(`complete: ${p}: invalid option name
179
- `,2);l.push(p)}else if(d==="-A"){if(f++,f>=t.length)return _(`complete: -A: option requires an argument
180
- `,2);u.push(t[f])}else if(d==="-C"){if(f++,f>=t.length)return _(`complete: -C: option requires an argument
181
- `,2);a=t[f]}else if(d==="-G"){if(f++,f>=t.length)return _(`complete: -G: option requires an argument
182
- `,2)}else if(d==="-P"){if(f++,f>=t.length)return _(`complete: -P: option requires an argument
183
- `,2)}else if(d==="-S"){if(f++,f>=t.length)return _(`complete: -S: option requires an argument
184
- `,2)}else if(d==="-X"){if(f++,f>=t.length)return _(`complete: -X: option requires an argument
185
- `,2)}else if(d==="--"){c.push(...t.slice(f+1));break}else d.startsWith("-")||c.push(d)}if(r){if(c.length===0)return e.state.completionSpecs.clear(),e.state.defaultCompletionSpec=void 0,e.state.emptyCompletionSpec=void 0,Y("");for(let f of c)e.state.completionSpecs.delete(f);return Y("")}if(n)return c.length===0?mo(e):mo(e,c);if(t.length===0||c.length===0&&!i&&!o&&!a&&l.length===0&&u.length===0&&!s)return mo(e);if(o&&c.length===0&&!s)return _(`complete: -F: option requires a command name
186
- `,2);if(s){let f={isDefault:!0};return i!==void 0&&(f.wordlist=i),o!==void 0&&(f.function=o),a!==void 0&&(f.command=a),l.length>0&&(f.options=l),u.length>0&&(f.actions=u),e.state.defaultCompletionSpec=f,Y("")}for(let f of c){let d=Object.create(null);i!==void 0&&(d.wordlist=i),o!==void 0&&(d.function=o),a!==void 0&&(d.command=a),l.length>0&&(d.options=l),u.length>0&&(d.actions=u),e.state.completionSpecs.set(f,d)}return Y("")}function mo(e,t){let n=e.state.completionSpecs??new Map;if(n.size===0&&!e.state.defaultCompletionSpec){if(t&&t.length>0){let i="";for(let o of t)i+=`complete: ${o}: no completion specification
187
- `;return L("",i,1)}return Y("")}let r=[],s=t||Array.from(n.keys());for(let i of s){let o=n.get(i);if(!o){if(t)return L(r.join(`
141
+ `):n};async function Eh(e,t,n,r){let s=(v,A)=>e.state.closedStandardFds?.has(v)?{kind:"closed"}:st(e,v)??A,i=new Map([[0,s(0,{kind:"dup-in",sourceFd:0})],[1,s(1,{kind:"dup-out",sourceFd:1})],[2,s(2,{kind:"dup-out",sourceFd:2})]]),o={stdout:hr({kind:"entry",entry:i.get(1),descriptors:tn(e,1)},1),stderr:hr({kind:"entry",entry:i.get(2),descriptors:tn(e,2)},2)},a=(v,A)=>{v===1?o.stdout=A:v===2&&(o.stderr=A)},l=v=>v.kind==="dup-out"?v.sourceFd===1?o.stdout:o.stderr:v.path===Sn?{kind:"discard"}:{kind:"file",path:v.path,append:v.append},u=r.numericSnapshot,c,f=-1,d=!1,p=!1,h=i.get(0);h?.kind==="input"?(c=h.content,f=0,p=h.device===!0):h?.kind==="readwrite"?(c=h.content.slice(h.position),f=0,p=h.device===!0):h?.kind==="closed"&&(c="",p=!0);let m=()=>({outputRoutes:o,stdin:c,stdinSourceFd:f,stdinReplaced:d,stdinUnavailable:p,error:null}),y=async(v,A,x)=>{let $={...m(),error:await sn(e,v,A>0,o)};return x?{...$,errorCause:x}:$},b=async(v,A)=>{if(mh(e,v))return null;let x=hh(e);return y(T("",x.stderr,C.EXIT_CODE),A,x)},w=(v,A,x)=>{v!==null&&v<xe&&i.set(v,A),(v===1||v===2)&&a(v,x??hr({kind:"entry",entry:A,descriptors:r.policy==="persistent"?[v]:[]},v)),r.policy==="persistent"&&v!==null&&v<xe&&(e.state.closedStandardFds?.delete(v),wt(e,v,A))},E=(v,A)=>{i.set(v,A),(v===1||v===2)&&a(v,hr({kind:"entry",entry:A,descriptors:[]},v)),rn(e,r.standardSnapshot,v),r.standardClosedSnapshot.has(v)||r.standardClosedSnapshot.set(v,e.state.closedStandardFds?.has(v)===!0),e.state.closedStandardFds?.delete(v),wt(e,v,A)},S=(v,A)=>{if(v<xe){let x=i.get(v);return x?.kind==="closed"?null:{kind:"entry",entry:x,descriptors:tn(e,v)}}return yh(e,v,A)};for(let v=0;v<t.length;v++){let A=t[v],x=lo(A);if(A.target.type==="HereDoc"){let P=await wh(e,A.target);if(A.fdVariable){try{ue(e,A.fdVariable)}catch(R){if(!(R instanceof U))throw R;return y(T(R.stdout,R.stderr,R.exitCode),v,R)}let N=Sc(e),D=await b(N,v);if(D)return D;rn(e,r.fdVariableSnapshot,N),r.fdVariableEnv.has(A.fdVariable)||r.fdVariableEnv.set(A.fdVariable,e.state.env.get(A.fdVariable)),wt(e,N,{kind:"input",content:P}),e.state.env.set(A.fdVariable,String(N)),e.state.nextFd=N+1}else if(x!==null&&x>=xe){let N=await b(x,v);if(N)return N;rn(e,u,x),wt(e,x,{kind:"input",content:P})}else if(x===0||x===null)c=un(P),f=-1,w(x,{kind:"input",content:c}),d=!0,p=!1;else{let N={kind:"input",content:P};r.policy==="persistent"?w(x,N):E(x,N)}continue}let $,I=A.operator===">&"||A.operator==="<&";if(I){if(Wi(e,A.target))return y(T("",`bash: $@: ambiguous redirect
142
+ `,1),v);$=await ne(e,A.target)}else if(A.operator==="<<<")$=await ne(e,A.target);else{let P=await Xu(e,A.target);if("error"in P)return y(T("",P.error,1),v);$=P.target}if($.includes("\0"))return y(T("",`bash: ${$.replace(/\0/g,"")}: No such file or directory
143
+ `,1),v);if(A.fdVariable){try{ue(e,A.fdVariable)}catch(k){if(!(k instanceof U))throw k;return y(T(k.stdout,k.stderr,k.exitCode),v,k)}if(I&&$==="-"){let k=Number.parseInt(e.state.env.get(A.fdVariable)??"",10);Number.isNaN(k)||(rn(e,r.fdVariableSnapshot,k),kt(e,k));continue}let P=Sc(e),N=I?uo($):null;if(N&&!S(N.sourceFd,A.operator==="<&"))return y(T("",`bash: ${N.sourceFd}: Bad file descriptor
144
+ `,1),v);if(!(N?.move===!0&&N.sourceFd>=xe)){let k=await b(P,v);if(k)return k}rn(e,r.fdVariableSnapshot,P),r.fdVariableEnv.has(A.fdVariable)||r.fdVariableEnv.set(A.fdVariable,e.state.env.get(A.fdVariable));let R,B;if(I){let k=N;if(k){let M=S(k.sourceFd,A.operator==="<&");if(!M)return y(T("",`bash: ${k.sourceFd}: Bad file descriptor
145
+ `,1),v);B=k,k.sourceFd<xe&&(R=M.entry)}else{if(A.operator==="<&")return y(T("",`bash: ${$}: ambiguous redirect
146
+ `,1),v);let M=await qn(e,$,!1,!1);if(M.error)return y(M.error,v);R=M.entry}}else if(A.operator===">"||A.operator===">|"||A.operator===">>"||A.operator==="&>"||A.operator==="&>>"){let k=A.operator===">>"||A.operator==="&>>",M=await qn(e,$,k,A.operator===">|");if(M.error)return y(M.error,v);R=M.entry}else if(A.operator==="<<<")R={kind:"input",content:`${$}
147
+ `};else if(A.operator==="<"||A.operator==="<>"){let k=await co(e,$,A.operator==="<>");if(k.error)return y(k.error,v);R=k.entry}if(B&&B.sourceFd>=xe){if(!(B.move?oo(e,P,B.sourceFd):$s(e,P,B.sourceFd)))return y(T("",`bash: ${B.sourceFd}: Bad file descriptor
148
+ `,1),v)}else R&&wt(e,P,R);B?.move&&B.sourceFd!==P&&B.sourceFd<xe&&kt(e,B.sourceFd),e.state.env.set(A.fdVariable,String(P)),e.state.nextFd=P+1;continue}if(Ec(A)){let P=x;if(I&&$==="-"){rn(e,u,P),kt(e,P);continue}let N=I?uo($):null;if(N&&!S(N.sourceFd,A.operator==="<&"))return y(T("",`bash: ${N.sourceFd}: Bad file descriptor
149
+ `,1),v);if(!(N?.move===!0&&N.sourceFd>=xe)){let R=await b(P,v);if(R)return R}if(rn(e,u,P),I){let R=N;if(!R){if(A.operator==="<&")return y(T("",`bash: ${$}: ambiguous redirect
150
+ `,1),v);let k=await qn(e,$,!1,!1);if(k.error)return y(k.error,v);wt(e,P,k.entry);continue}let B=S(R.sourceFd,A.operator==="<&");if(!B)return y(T("",`bash: ${R.sourceFd}: Bad file descriptor
151
+ `,1),v);if(R.sourceFd<xe)wt(e,P,B.entry);else if(!(R.move?oo(e,P,R.sourceFd):$s(e,P,R.sourceFd)))return y(T("",`bash: ${R.sourceFd}: Bad file descriptor
152
+ `,1),v);R.move&&R.sourceFd!==P&&R.sourceFd<xe&&kt(e,R.sourceFd);continue}if(A.operator===">"||A.operator===">|"||A.operator===">>"){let R=await qn(e,$,A.operator===">>",A.operator===">|");if(R.error)return y(R.error,v);wt(e,P,R.entry)}else if(A.operator==="<<<")wt(e,P,{kind:"input",content:`${$}
153
+ `});else if(A.operator==="<"||A.operator==="<>"){let R=await co(e,$,A.operator==="<>");if(R.error)return y(R.error,v);wt(e,P,R.entry)}continue}if(I){if($==="-"){x===0&&(c="",f=-1,d=!0,p=!0),x!==null&&x<xe&&(i.set(x,{kind:"closed"}),(x===1||x===2)&&a(x,{kind:"invalid-output",fd:x}),r.policy==="persistent"&&(kt(e,x),e.state.closedStandardFds??=new Set,e.state.closedStandardFds.add(x)));continue}let P=uo($);if(!P){if(A.operator==="<&")return y(T("",`bash: ${$}: ambiguous redirect
154
+ `,1),v);let R=await qn(e,$,!1,!1,!1);if(R.error)return y(R.error,v);let B=R.entry,k=l(B);A.fd==null?(w(1,B,k),w(2,B,k)):w(x,B,k);continue}let N=S(P.sourceFd,A.operator==="<&");if(!N)return y(T("",`bash: ${P.sourceFd}: Bad file descriptor
155
+ `,1),v);let D=P.sourceFd===1?o.stdout:P.sourceFd===2?o.stderr:hr(N,x===2?2:1);if(r.policy==="persistent"&&x!==null&&x<xe&&P.sourceFd>=xe){if(!$s(e,x,P.sourceFd))return y(T("",`bash: ${P.sourceFd}: Bad file descriptor
156
+ `,1),v);i.set(x,st(e,x)),e.state.closedStandardFds?.delete(x),a(x,D)}else w(x,N.entry,D);if(A.operator==="<&"&&x===0)if(N.entry.kind==="input"||N.entry.kind==="readwrite"){let R=P.sourceFd<xe&&!bn(e,P.sourceFd)?{content:N.entry.kind==="input"?N.entry.content:N.entry.content.slice(N.entry.position)}:ks(e,P.sourceFd);if("error"in R)return y(T("",`bash: ${P.sourceFd}: Bad file descriptor
157
+ `,1),v);c=R.content,f=bn(e,P.sourceFd)?P.sourceFd:-1,d=!0,p=N.entry.device===!0}else c=n,f=-1,d=!1,p=!1;P.move&&(P.sourceFd>=xe?kt(e,P.sourceFd):(i.set(P.sourceFd,{kind:"closed"}),(P.sourceFd===1||P.sourceFd===2)&&a(P.sourceFd,{kind:"invalid-output",fd:P.sourceFd}),r.policy==="persistent"&&(kt(e,P.sourceFd),e.state.closedStandardFds??=new Set,e.state.closedStandardFds.add(P.sourceFd))));continue}if(A.operator===">"||A.operator===">|"||A.operator===">>"||A.operator==="&>"||A.operator==="&>>"){let P=await qn(e,$,A.operator===">>"||A.operator==="&>>",A.operator===">|",!1);if(P.error)return y(P.error,v);let N=P.entry,D=l(N);A.operator==="&>"||A.operator==="&>>"?(w(1,N,D),w(2,N,D)):w(x,N,D);continue}if(A.operator==="<<<"){let P=un(`${$}
158
+ `);w(x,{kind:"input",content:P}),x===0&&(c=P,f=-1,d=!0,p=!1)}else if(A.operator==="<"){let P=e.fs.resolvePath(e.state.cwd,$);try{let N=P===Sn?"":await xn(e.fs,P),D=Cs.has(P);w(x,{kind:"input",content:N,device:D}),x===0&&(c=N,f=-1,d=!0,p=D)}catch{return y(T("",`bash: ${$}: No such file or directory
159
+ `,1),v)}}else if(A.operator==="<>"){let P=await co(e,$,!0);if(P.error)return y(P.error,v);let N=P.entry;w(x,N),x===0&&N.kind==="readwrite"&&(c=N.content,f=-1,d=!0,p=N.device===!0)}}return m()}function Un(e,t,n){let r={numericSnapshot:new Map,fdVariableSnapshot:new Map,standardSnapshot:new Map,standardClosedSnapshot:new Map,fdVariableEnv:new Map,nextFd:e.state.nextFd,policy:n},s=!1;return{prepare:(i="")=>Eh(e,t,i,r),finish:()=>{if(!s){if(s=!0,n!=="persistent"&&Ps(e,r.numericSnapshot),n!=="persistent"){Ps(e,r.standardSnapshot);for(let[i,o]of r.standardClosedSnapshot)o?(e.state.closedStandardFds??=new Set,e.state.closedStandardFds.add(i)):e.state.closedStandardFds?.delete(i)}if(n==="bare"){Ps(e,r.fdVariableSnapshot);for(let[i,o]of r.fdVariableEnv)o===void 0?e.state.env.delete(i):e.state.env.set(i,o);e.state.nextFd=r.nextFd}}}}}function jn(e){if(!e.error)throw new Error("Expected a redirection error");if(e.errorCause)throw e.errorCause.stdout=e.error.stdout,e.errorCause.stderr=e.error.stderr,e.errorCause;return e.error}async function fo(e,t,n,r){let s=t instanceof U||t instanceof Ie||t instanceof Me?t.exitCode:t instanceof C?C.EXIT_CODE:0,i=await sn(e,T(t.stdout,t.stderr,s),n.length>0,r.outputRoutes);t.stdout=i.stdout,t.stderr=i.stderr,t.internalOutputAccounting=i.internalOutputAccounting??{stdout:W(i.stdout),stderr:W(i.stderr)}}async function Je(e,t,n,r){let s=Un(e,t,mr),i;try{if(i=await s.prepare(n),i.error)return jn(i);let o=e.state.groupStdin,a=e.state.groupStdinSourceFd;i.stdin!==void 0&&(e.state.groupStdin=i.stdin,e.state.groupStdinSourceFd=i.stdinSourceFd);try{let l=await r(i);return await sn(e,l,t.length>0,i.outputRoutes)}finally{i.stdin!==void 0&&(e.state.groupStdin=o,e.state.groupStdinSourceFd=a)}}catch(o){throw!(o instanceof $n)||!i||await fo(e,o,t,i),o}finally{s.finish()}}async function sn(e,t,n,r,s="bash",i=!1){n&&(t=e.executionScope.accountResult(t,"redirection"));let{stdout:o,stderr:a,exitCode:l}=t,c=t.stdoutKind==="bytes"||t.stdoutKind===void 0&&t.stdoutEncoding==="binary"?"binary":"utf8",f=y=>c,{stdout:d,stderr:p}=r;if(o!==""||a!==""){let y=o,b=a;o="",a="",d.kind==="invalid-output"&&y!==""&&(y="",b+=`${i?"":"bash: "}${s}: write error: Bad file descriptor
160
+ `,l=1),p.kind==="invalid-output"&&b!==""&&(b="",l===0&&(l=1));let w=async(E,S,v)=>{E.append?await e.fs.appendFile(E.path,S,v):await e.fs.writeFile(E.path,S,v)};if(d===p&&(d.kind==="file"||d.kind==="descriptor")){let E=y+b;E!==""&&(d.kind==="file"?await w(d,E,f(E)):await ao(e,d.source.entry,d.source.descriptors,E,f(E)))}else for(let[E,S,v]of[[y,d,!0],[b,p,!1]])if(E!=="")switch(S.kind){case"live-stdout":o+=E;break;case"live-stderr":a+=E;break;case"file":await w(S,E,v?f(E):bc(E));break;case"descriptor":await ao(e,S.source.entry,S.source.descriptors,E,v?f(E):bc(E));break;case"invalid-output":break;case"discard":break}}let h=T(o,a,l);if(t.stdoutKind&&(h.stdoutKind=t.stdoutKind),t.stdoutEncoding==="binary"&&(h.stdoutEncoding="binary"),t.internalPipeStatusOverride&&(h.internalPipeStatusOverride=t.internalPipeStatusOverride),n||e.state.fileDescriptors?.has(1)===!0||e.state.fileDescriptors?.has(2)===!0){let y=(t.internalOutputAccounting?.stdout??0)+(t.internalOutputAccounting?.stderr??0),b=W(h.stdout),w=W(h.stderr),E=Math.min(b,y);h.internalOutputAccounting={stdout:E,stderr:Math.min(w,y-E)},e.executionScope.accountResult(h,"redirection")}else t.internalOutputAccounting&&(h.internalOutputAccounting=t.internalOutputAccounting);return h}function xc(e,t){if(e.state.options.posix&&Ki.has(t.name)){let r=`bash: line ${e.state.currentLine}: \`${t.name}': is a special builtin
161
+ `;throw new U(2,"",r)}let n={...t,sourceFile:t.sourceFile??e.state.currentSource??"main"};return e.state.functions.set(t.name,n),J}async function Ns(e,t,n,r="",s,i=!1){e.state.callDepth++,e.state.callDepth>e.limits.maxCallDepth&&(e.state.callDepth--,Yt(`${t.name}: maximum recursion depth (${e.limits.maxCallDepth}) exceeded, increase executionLimits.maxCallDepth`,"recursion")),e.state.funcNameStack||(e.state.funcNameStack=[]),e.state.callLineStack||(e.state.callLineStack=[]),e.state.sourceStack||(e.state.sourceStack=[]),e.state.funcNameStack.unshift(t.name),e.state.callLineStack.unshift(s??e.state.currentLine),e.state.sourceStack.unshift(t.sourceFile??"main"),e.state.localScopes.push(new Map),e.state.localArrayScopes??=[],e.state.localArrayScopes.push(new Map),e.state.localExportedVars||(e.state.localExportedVars=[]),e.state.localExportedVars.push(new Set);let o=new Map,a=Number.parseInt(e.state.env.get("#")??"0",10),l=Math.max(n.length,a);for(let p=0;p<l;p++){let h=String(p+1);o.set(h,e.state.env.get(h)),p<n.length?e.state.env.set(h,n[p]):e.state.env.delete(h)}o.set("@",e.state.env.get("@")),o.set("#",e.state.env.get("#")),e.state.env.set("@",n.join(" ")),e.state.env.set("#",String(n.length));let u=!1,c=()=>{if(u)return;u=!0;let p=e.state.localScopes.length-1,h=e.state.localScopes.pop(),m=e.state.localArrayScopes?.pop();if(h)for(let[y,b]of h)b===void 0?e.state.env.delete(y):e.state.env.set(y,b);if(m){e.state.arrays??=new Map;for(let[y,b]of m)b===void 0?(e.state.arrays.delete(y),e.state.associativeArrays?.delete(y)):(e.state.arrays.set(y,Le(b)),e.state.associativeArrays??=new Set,b.kind==="associative"?e.state.associativeArrays.add(y):e.state.associativeArrays.delete(y))}if(mc(e,p),e.state.fullyUnsetLocals)for(let[y,b]of e.state.fullyUnsetLocals.entries())b===p&&e.state.fullyUnsetLocals.delete(y);if(e.state.localExportedVars&&e.state.localExportedVars.length>0){let y=e.state.localExportedVars.pop();if(y)for(let b of y)e.state.exportedVars?.delete(b)}for(let[y,b]of o)b===void 0?e.state.env.delete(y):e.state.env.set(y,b);e.state.funcNameStack?.shift(),e.state.callLineStack?.shift(),e.state.sourceStack?.shift(),e.state.callDepth--},f=null,d=Un(e,t.redirections,mr);try{if(f=await d.prepare(r),f.error)return jn(f);let p=f.stdin??r,h=i||f.stdin!==void 0||r!=="",m=await e.executeCommand(t.body,p,h);return sn(e,m,t.redirections.length>0,f.outputRoutes)}catch(p){if(p instanceof $n&&f&&(await fo(e,p,t.redirections,f),p instanceof Ie))return T(p.stdout,p.stderr,p.exitCode);throw p}finally{d.finish(),c()}}var kc=e=>e.type==="Escaped"?F.literal(`\\${e.value}`):e.type==="DoubleQuoted"?{...e,parts:e.parts.map(kc)}:e,Pc=["!","[[","]]","case","do","done","elif","else","esac","fi","for","function","if","in","then","time","until","while","{","}"],mo=[".",":","[","alias","bg","bind","break","builtin","caller","cd","command","compgen","complete","compopt","continue","declare","dirs","disown","echo","enable","eval","exec","exit","export","false","fc","fg","getopts","hash","help","history","jobs","kill","let","local","logout","mapfile","popd","printf","pushd","pwd","read","readarray","readonly","return","set","shift","shopt","source","suspend","test","times","trap","true","type","typeset","ulimit","umask","unalias","unset","wait"],bh=["autocd","assoc_expand_once","cdable_vars","cdspell","checkhash","checkjobs","checkwinsize","cmdhist","compat31","compat32","compat40","compat41","compat42","compat43","compat44","complete_fullquote","direxpand","dirspell","dotglob","execfail","expand_aliases","extdebug","extglob","extquote","failglob","force_fignore","globasciiranges","globstar","gnu_errfmt","histappend","histreedit","histverify","hostcomplete","huponexit","inherit_errexit","interactive_comments","lastpipe","lithist","localvar_inherit","localvar_unset","login_shell","mailwarn","no_empty_cmd_completion","nocaseglob","nocasematch","nullglob","progcomp","progcomp_alias","promptvars","restricted_shell","shift_verbose","sourcepath","xpg_echo"],Sh=mo;async function yo(e,t){let n=[],r=null,s="",i="",o=null,a=!1,l=!1,u=!1,c=null,f=null,d=null,p=[],h=["alias","arrayvar","binding","builtin","command","directory","disabled","enabled","export","file","function","group","helptopic","hostname","job","keyword","running","service","setopt","shopt","signal","stopped","user","variable"];for(let A=0;A<t.length;A++){let x=t[A];if(x==="-v")n.push("variable");else if(x==="-e")n.push("export");else if(x==="-f")n.push("file");else if(x==="-d")n.push("directory");else if(x==="-k")n.push("keyword");else if(x==="-A"){if(A++,A>=t.length)return L(`compgen: -A: option requires an argument
162
+ `,2);let $=t[A];if(!h.includes($))return L(`compgen: ${$}: invalid action name
163
+ `,2);n.push($)}else if(x==="-W"){if(A++,A>=t.length)return L(`compgen: -W: option requires an argument
164
+ `,2);r=t[A]}else if(x==="-P"){if(A++,A>=t.length)return L(`compgen: -P: option requires an argument
165
+ `,2);s=t[A]}else if(x==="-S"){if(A++,A>=t.length)return L(`compgen: -S: option requires an argument
166
+ `,2);i=t[A]}else if(x==="-o"){if(A++,A>=t.length)return L(`compgen: -o: option requires an argument
167
+ `,2);let $=t[A];if($==="plusdirs")a=!0;else if($==="dirnames")l=!0;else if($==="default")u=!0;else if(!($==="filenames"||$==="nospace"||$==="bashdefault"||$==="noquote"))return L(`compgen: ${$}: invalid option name
168
+ `,2)}else if(x==="-F"){if(A++,A>=t.length)return L(`compgen: -F: option requires an argument
169
+ `,2);f=t[A]}else if(x==="-C"){if(A++,A>=t.length)return L(`compgen: -C: option requires an argument
170
+ `,2);d=t[A]}else if(x==="-X"){if(A++,A>=t.length)return L(`compgen: -X: option requires an argument
171
+ `,2);c=t[A]}else if(x==="-G"){if(A++,A>=t.length)return L(`compgen: -G: option requires an argument
172
+ `,2)}else if(x==="--"){p.push(...t.slice(A+1));break}else x.startsWith("-")||p.push(x)}o=p[0]??null;let m=[],y=new Set,b=()=>e.limits.maxArrayElements-m.length,w=A=>{for(let x of A){if(m.length>=e.limits.maxArrayElements)throw new C(`compgen: completion element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");if(W(x)>e.limits.maxStringLength)throw new C(`compgen: completion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");e.executionScope.consumeWork(1,"compgen completion"),m.push(x),y.add(x)}};if(l){let A=await po(e,o,b());w(A)}if(u){let A=await $c(e,o,b());w(A)}for(let A of n)if(A==="variable"){let x=Ah(e,o,b());w(x)}else if(A==="export"){let x=vh(e,o,b());w(x)}else if(A==="function"){let x=xh(e,o,b());w(x)}else if(A==="builtin"){let x=$h(e,o,b());w(x)}else if(A==="keyword"){let x=kh(e,o,b());w(x)}else if(A==="alias"){let x=Ph(e,o,b());w(x)}else if(A==="shopt"){let x=Ch(e,o,b());w(x)}else if(A==="helptopic"){let x=Nh(e,o,b());w(x)}else if(A==="directory"){let x=await po(e,o,b());w(x)}else if(A==="file"){let x=await $c(e,o,b());w(x)}else if(A==="user"){let x=Rh(e,o,b());w(x)}else if(A==="command"){let x=await Dh(e,o,b());w(x)}if(r!==null)try{let A=await Ih(e,r),x=Oh(e,A,b(),o);for(let $ of x)w([$])}catch(A){if(A instanceof C)throw A;return T("","",1)}if(a){let A=await po(e,o,b(),y);for(let x of A)y.has(x)||w([x])}let E="";if(f!==null){let A=e.state.functions.get(f);if(A){let x=new Map,$=Ae(e,"COMP_WORDS"),I=$?Le($):void 0;ye(e,"COMP_WORDS"),tr(e,"COMP_WORDS"),x.set("COMP_CWORD",e.state.env.get("COMP_CWORD")),e.state.env.set("COMP_CWORD","-1"),x.set("COMP_LINE",e.state.env.get("COMP_LINE")),e.state.env.set("COMP_LINE",""),x.set("COMP_POINT",e.state.env.get("COMP_POINT")),e.state.env.set("COMP_POINT","0");let P=Ae(e,"COMPREPLY"),N=P?Le(P):void 0,D=e.state.env.get("COMPREPLY");ye(e,"COMPREPLY"),e.state.env.delete("COMPREPLY");let R=["compgen",p[0]??"",""];try{let B=await Ns(e,A,R,"");if(B.exitCode!==0)return ho(e,x),Gn(e,"COMP_WORDS",I),Gn(e,"COMPREPLY",N),D!==void 0&&e.state.env.set("COMPREPLY",D),T("",B.stderr,1);E=B.stdout;let k=_h(e,b());w(k)}catch(B){if(B instanceof C)throw B;return ho(e,x),Gn(e,"COMP_WORDS",I),Gn(e,"COMPREPLY",N),D!==void 0&&e.state.env.set("COMPREPLY",D),T("","",1)}ho(e,x),Gn(e,"COMP_WORDS",I),Gn(e,"COMPREPLY",N),D!==void 0&&e.state.env.set("COMPREPLY",D)}}if(d!==null)try{let A=ft(d),x=await e.executeScript(A);if(x.exitCode!==0)return T("",x.stderr,x.exitCode);if(x.stdout)for(let $ of Lh(x.stdout))$.length>0&&w([$])}catch(A){if(A.name==="ParseException")return L(`compgen: -C: ${A.message}
173
+ `,2);throw A}let S=m;if(c!==null){let A=c.startsWith("!"),x=A?c.slice(1):c;S=m.filter($=>{let I=Wn($,x,!1,!0,e.limits.maxCallDepth);return A?I:!I})}if(S.length===0&&o!==null)return T(E,"",1);let v=new kn(e.limits.maxOutputSize,"compgen");v.append(E);for(let A of S)v.append(s).append(A).append(i).append(`
174
+ `);return Y(v.build())}function Ah(e,t,n){let r=it(e,t,n);for(let s of e.state.env.keys())/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(s)&&r.add(s);for(let s of e.state.arrays?.keys()??[])r.add(s);return r.build()}function vh(e,t,n){let r=it(e,t,n),s=e.state.exportedVars??new Set;for(let i of s)e.state.env.has(i)&&r.add(i);return r.build()}function xh(e,t,n){let r=it(e,t,n);for(let s of e.state.functions.keys())r.add(s);return r.build()}function $h(e,t,n){let r=it(e,t,n);for(let s of mo)r.add(s);return r.build()}function kh(e,t,n){let r=it(e,t,n);for(let s of Pc)r.add(s);return r.build()}function Ph(e,t,n){let r=it(e,t,n);for(let s of e.state.env.keys())if(s.startsWith("BASH_ALIAS_")){let i=s.slice(11);r.add(i)}return r.build()}function Ch(e,t,n){let r=it(e,t,n);for(let s of bh)r.add(s);return r.build()}function Nh(e,t,n){let r=it(e,t,n);for(let s of Sh)r.add(s);return r.build()}async function po(e,t,n=e.limits.maxArrayElements,r){let s=it(e,null,n,r);try{let i=e.state.cwd,o=t??"";if(t){let l=t.lastIndexOf("/");if(l!==-1){let u=t.slice(0,l)||"/";o=t.slice(l+1),u.startsWith("/")?i=u:i=`${e.state.cwd}/${u}`}}let a=await e.fs.readdir(i);for(let l of a){e.executionScope.consumeWork(1,"compgen directory scan");let u=`${i}/${l}`;try{if((await e.fs.stat(u)).isDirectory&&(!o||l.startsWith(o)))if(t?.includes("/")){let f=t.lastIndexOf("/"),d=t.slice(0,f+1);s.add(d+l)}else s.add(l)}catch(c){if(c instanceof C)throw c}}}catch(i){if(i instanceof C)throw i}return s.build()}async function $c(e,t,n=e.limits.maxArrayElements){let r=it(e,null,n);try{let s=e.state.cwd,i=t??"";if(t){let a=t.lastIndexOf("/");if(a!==-1){let l=t.slice(0,a)||"/";i=t.slice(a+1),l.startsWith("/")?s=l:s=`${e.state.cwd}/${l}`}}let o=await e.fs.readdir(s);for(let a of o)if(e.executionScope.consumeWork(1,"compgen file scan"),!i||a.startsWith(i))if(t?.includes("/")){let l=t.lastIndexOf("/"),u=t.slice(0,l+1);r.add(u+a)}else r.add(a)}catch(s){if(s instanceof C)throw s}return r.build()}function Rh(e,t,n){let r=it(e,t,n);return r.add("root"),r.add("nobody"),r.build()}async function Dh(e,t,n){let r=it(e,t,n);for(let i of mo)r.add(i);for(let i of e.state.functions.keys())r.add(i);for(let i of e.state.env.keys())i.startsWith("BASH_ALIAS_")&&r.add(i.slice(11));for(let i of Pc)r.add(i);let s=e.state.env.get("PATH")??"/usr/bin:/bin";for(let i of s.split(":"))if(i)try{let o=await e.fs.readdir(i);for(let a of o)r.add(a)}catch(o){if(o instanceof C)throw o}return r.build()}function it(e,t,n,r){let s=new Set;return{add(i){if(e.executionScope.consumeWork(1,"compgen candidate collection"),!(t!==null&&!i.startsWith(t))&&!r?.has(i)&&!s.has(i)){if(s.size>=n)throw new C(`compgen: completion element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");if(W(i)>e.limits.maxStringLength)throw new C(`compgen: completion string limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");s.add(i)}},build(){return Array.from(s).sort()}}}async function Ih(e,t){let r=new G().parseWordFromString(t,!1,!1);return await ne(e,F.word(r.parts.map(kc)))}function Oh(e,t,n,r){let s=e.state.env.get("IFS")??`
175
+ `;if(s.length===0){if(r!==null&&!t.startsWith(r))return[];if(n===0)throw new C(`compgen: completion element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");return[t]}let i=new Set(s.split("")),o=[],a=c=>{if(!(r!==null&&!c.startsWith(r))){if(o.length>=n)throw new C(`compgen: completion element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");o.push(c)}},l="",u=0;for(;u<t.length;){let c=t[u];if(c==="\\"&&u+1<t.length){let f=t[u+1];l+=f,u+=2}else i.has(c)?(l.length>0&&(a(l),l=""),u++):(l+=c,u++)}return l.length>0&&a(l),o}function ho(e,t){for(let[n,r]of t)r===void 0?e.state.env.delete(n):e.state.env.set(n,r)}function Gn(e,t,n){e.state.arrays??=new Map,n?e.state.arrays.set(t,Le(n)):e.state.arrays.delete(t)}function _h(e,t){let n=[],r=s=>{if(n.length>=t)throw new C(`compgen: completion element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");n.push(s)};if(ke(e,"COMPREPLY")){let s=H(e,"COMPREPLY");for(let[,i]of s)r(i)}else{let s=e.state.env.get("COMPREPLY");s!==void 0&&r(s)}return n}function*Lh(e){let t=0;for(;t<=e.length;){let n=e.indexOf(`
176
+ `,t),r=n===-1?e.length:n;if(r>t&&(yield e.slice(t,r)),n===-1)return;t=n+1}}function yr(e){for(let t=0;t<e.length;t++){let n=e.charCodeAt(t);if(n<32||n===127)return!0}return!1}function go(e){let t="$'";for(let n=0;n<e.length;n++){let r=e[n],s=e.charCodeAt(n);s===7?t+="\\a":s===8?t+="\\b":s===9?t+="\\t":s===10?t+="\\n":s===11?t+="\\v":s===12?t+="\\f":s===13?t+="\\r":s===27?t+="\\e":s===39?t+="\\'":s===92?t+="\\\\":s<32||s===127?t+=`\\${s.toString(8).padStart(3,"0")}`:t+=r}return t+="'",t}function Cc(e){if(yr(e))return Nc(e);if(e==="")return 2;if(/^[a-zA-Z0-9_/.:\-@%+,=]+$/.test(e))return W(e);let t=W(e)+2;for(let n of e)n==="'"&&(t+=3);return t}function we(e){return yr(e)?go(e):e===""?"''":/^[a-zA-Z0-9_/.:\-@%+,=]+$/.test(e)?e:`'${e.replace(/'/g,"'\\''")}'`}function Rs(e){if(yr(e))return Nc(e);let t=W(e)+2;for(let n of e)(n==="\\"||n==='"'||n==="$"||n==="`")&&t++;return t}function on(e){return yr(e)?go(e):`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\$/g,"\\$").replace(/`/g,"\\`")}"`}function Nc(e){let t=3;for(let n of e){let r=n.codePointAt(0)??0;r===7||r===8||r===9||r===10||r===11||r===12||r===13||r===27||r===39||r===92?t+=2:r<32||r===127?t+=4:t+=W(n)}return t}function gr(e){return yr(e)?go(e):`"${e.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\$/g,"\\$").replace(/`/g,"\\`")}"`}var Th=["bashdefault","default","dirnames","filenames","noquote","nosort","nospace","plusdirs"];function Eo(e,t){e.state.completionSpecs||(e.state.completionSpecs=new Map);let n=!1,r=!1,s=!1,i,o,a,l=[],u=[],c=[];for(let f=0;f<t.length;f++){let d=t[f];if(d==="-p")n=!0;else if(d==="-r")r=!0;else if(d==="-D")s=!0;else if(d==="-W"){if(f++,f>=t.length)return L(`complete: -W: option requires an argument
177
+ `,2);i=t[f]}else if(d==="-F"){if(f++,f>=t.length)return L(`complete: -F: option requires an argument
178
+ `,2);o=t[f]}else if(d==="-o"){if(f++,f>=t.length)return L(`complete: -o: option requires an argument
179
+ `,2);let p=t[f];if(!Th.includes(p))return L(`complete: ${p}: invalid option name
180
+ `,2);l.push(p)}else if(d==="-A"){if(f++,f>=t.length)return L(`complete: -A: option requires an argument
181
+ `,2);u.push(t[f])}else if(d==="-C"){if(f++,f>=t.length)return L(`complete: -C: option requires an argument
182
+ `,2);a=t[f]}else if(d==="-G"){if(f++,f>=t.length)return L(`complete: -G: option requires an argument
183
+ `,2)}else if(d==="-P"){if(f++,f>=t.length)return L(`complete: -P: option requires an argument
184
+ `,2)}else if(d==="-S"){if(f++,f>=t.length)return L(`complete: -S: option requires an argument
185
+ `,2)}else if(d==="-X"){if(f++,f>=t.length)return L(`complete: -X: option requires an argument
186
+ `,2)}else if(d==="--"){c.push(...t.slice(f+1));break}else d.startsWith("-")||c.push(d)}if(r){if(c.length===0)return e.state.completionSpecs.clear(),e.state.defaultCompletionSpec=void 0,e.state.emptyCompletionSpec=void 0,Y("");for(let f of c)e.state.completionSpecs.delete(f);return Y("")}if(n)return c.length===0?wo(e):wo(e,c);if(t.length===0||c.length===0&&!i&&!o&&!a&&l.length===0&&u.length===0&&!s)return wo(e);if(o&&c.length===0&&!s)return L(`complete: -F: option requires a command name
187
+ `,2);if(s){let f={isDefault:!0};return i!==void 0&&(f.wordlist=i),o!==void 0&&(f.function=o),a!==void 0&&(f.command=a),l.length>0&&(f.options=l),u.length>0&&(f.actions=u),e.state.defaultCompletionSpec=f,Y("")}for(let f of c){let d=Object.create(null);i!==void 0&&(d.wordlist=i),o!==void 0&&(d.function=o),a!==void 0&&(d.command=a),l.length>0&&(d.options=l),u.length>0&&(d.actions=u),e.state.completionSpecs.set(f,d)}return Y("")}function wo(e,t){let n=e.state.completionSpecs??new Map;if(n.size===0&&!e.state.defaultCompletionSpec){if(t&&t.length>0){let i="";for(let o of t)i+=`complete: ${o}: no completion specification
188
+ `;return T("",i,1)}return Y("")}let r=[],s=t||Array.from(n.keys());for(let i of s){let o=n.get(i);if(!o){if(t)return T(r.join(`
188
189
  `)+(r.length>0?`
189
190
  `:""),`complete: ${i}: no completion specification
190
- `,1);continue}let a="complete";if(o.options)for(let l of o.options)a+=` -o ${Ee(l)}`;if(o.actions)for(let l of o.actions)a+=` -A ${Ee(l)}`;o.wordlist!==void 0&&(o.wordlist.includes(" ")||o.wordlist.includes("'")?a+=` -W ${Ee(o.wordlist)}`:a+=` -W ${Ee(o.wordlist)}`),o.function!==void 0&&(a+=` -F ${Ee(o.function)}`),o.command!==void 0&&(a+=` -C ${Ee(o.command)}`),o.isDefault&&(a+=" -D"),a+=`${i.startsWith("-")?" -- ":" "}${Ee(i)}`,r.push(a)}if(!t&&e.state.defaultCompletionSpec){let i=e.state.defaultCompletionSpec,o="complete";for(let a of i.options??[])o+=` -o ${Ee(a)}`;for(let a of i.actions??[])o+=` -A ${Ee(a)}`;i.wordlist!==void 0&&(o+=` -W ${Ee(i.wordlist)}`),i.function!==void 0&&(o+=` -F ${Ee(i.function)}`),i.command!==void 0&&(o+=` -C ${Ee(i.command)}`),o+=" -D",r.push(o)}return r.length===0?Y(""):Y(`${r.join(`
191
+ `,1);continue}let a="complete";if(o.options)for(let l of o.options)a+=` -o ${we(l)}`;if(o.actions)for(let l of o.actions)a+=` -A ${we(l)}`;o.wordlist!==void 0&&(o.wordlist.includes(" ")||o.wordlist.includes("'")?a+=` -W ${we(o.wordlist)}`:a+=` -W ${we(o.wordlist)}`),o.function!==void 0&&(a+=` -F ${we(o.function)}`),o.command!==void 0&&(a+=` -C ${we(o.command)}`),o.isDefault&&(a+=" -D"),a+=`${i.startsWith("-")?" -- ":" "}${we(i)}`,r.push(a)}if(!t&&e.state.defaultCompletionSpec){let i=e.state.defaultCompletionSpec,o="complete";for(let a of i.options??[])o+=` -o ${we(a)}`;for(let a of i.actions??[])o+=` -A ${we(a)}`;i.wordlist!==void 0&&(o+=` -W ${we(i.wordlist)}`),i.function!==void 0&&(o+=` -F ${we(i.function)}`),i.command!==void 0&&(o+=` -C ${we(i.command)}`),o+=" -D",r.push(o)}return r.length===0?Y(""):Y(`${r.join(`
191
192
  `)}
192
- `)}var kc=["bashdefault","default","dirnames","filenames","noquote","nosort","nospace","plusdirs"];function go(e,t){e.state.completionSpecs||(e.state.completionSpecs=new Map);let n=!1,r=!1,s=[],i=[],o=[];for(let a=0;a<t.length;a++){let l=t[a];if(l==="-D")n=!0;else if(l==="-E")r=!0;else if(l==="-o"){if(a++,a>=t.length)return _(`compopt: -o: option requires an argument
193
- `,2);let u=t[a];if(!kc.includes(u))return _(`compopt: ${u}: invalid option name
194
- `,2);s.push(u)}else if(l==="+o"){if(a++,a>=t.length)return _(`compopt: +o: option requires an argument
195
- `,2);let u=t[a];if(!kc.includes(u))return _(`compopt: ${u}: invalid option name
196
- `,2);i.push(u)}else if(l==="--"){o.push(...t.slice(a+1));break}else!l.startsWith("-")&&!l.startsWith("+")&&o.push(l)}if(n){let a=e.state.defaultCompletionSpec??{isDefault:!0},l=new Set(a.options??[]);for(let u of s)l.add(u);for(let u of i)l.delete(u);return a.options=l.size>0?Array.from(l):void 0,e.state.defaultCompletionSpec=a,Y("")}if(r){let a=e.state.emptyCompletionSpec??Object.create(null),l=new Set(a.options??[]);for(let u of s)l.add(u);for(let u of i)l.delete(u);return a.options=l.size>0?Array.from(l):void 0,e.state.emptyCompletionSpec=a,Y("")}if(o.length>0){for(let a of o){let l=e.state.completionSpecs.get(a)??{},u=new Set(l.options??[]);for(let c of s)u.add(c);for(let c of i)u.delete(c);l.options=u.size>0?Array.from(u):void 0,e.state.completionSpecs.set(a,l)}return Y("")}return _(`compopt: not currently executing completion function
197
- `,1)}function wo(e,t){if(e.state.loopDepth===0){if(e.state.parentHasLoopContext)throw new Tt;return J}if(t.length>1)throw new q(1,"",`bash: continue: too many arguments
198
- `);let n=1;if(t.length>0){let r=Number.parseInt(t[0],10);if(Number.isNaN(r)||r<1)throw new q(1,"",`bash: continue: ${t[0]}: numeric argument required
199
- `);n=r}throw new He(n)}function Pc(e,t){let n="";return e.state.integerVars?.has(t)&&(n+="i"),e.state.lowercaseVars?.has(t)&&(n+="l"),le(e,t)&&(n+="n"),e.state.readonlyVars?.has(t)&&(n+="r"),e.state.uppercaseVars?.has(t)&&(n+="u"),e.state.exportedVars?.has(t)&&(n+="x"),n===""?"--":`-${n}`}function Eo(e){return Ee(e)}function bo(e){return`'${e.replace(/'/g,"'\\''")}'`}function Cc(e,t){let n="",r="",s=!1;for(let i of t){let o=Pc(e,i);if(e.state.associativeArrays?.has(i)){let c=St(e,i);if(c.length===0)n+=`declare -A ${i}=()
200
- `;else{let f=c.map(d=>{let p=ie(e,i,d)??"",h=Eo(p);return`[${bo(d)}]=${h}`});n+=`declare -A ${i}=(${f.join(" ")})
201
- `}continue}let l=be(e,i);if(l.length>0){let c=l.map(f=>{let d=ie(e,i,f)??"";return`[${f}]=${on(d)}`});n+=`declare -a ${i}=(${c.join(" ")})
193
+ `)}var Rc=["bashdefault","default","dirnames","filenames","noquote","nosort","nospace","plusdirs"];function bo(e,t){e.state.completionSpecs||(e.state.completionSpecs=new Map);let n=!1,r=!1,s=[],i=[],o=[];for(let a=0;a<t.length;a++){let l=t[a];if(l==="-D")n=!0;else if(l==="-E")r=!0;else if(l==="-o"){if(a++,a>=t.length)return L(`compopt: -o: option requires an argument
194
+ `,2);let u=t[a];if(!Rc.includes(u))return L(`compopt: ${u}: invalid option name
195
+ `,2);s.push(u)}else if(l==="+o"){if(a++,a>=t.length)return L(`compopt: +o: option requires an argument
196
+ `,2);let u=t[a];if(!Rc.includes(u))return L(`compopt: ${u}: invalid option name
197
+ `,2);i.push(u)}else if(l==="--"){o.push(...t.slice(a+1));break}else!l.startsWith("-")&&!l.startsWith("+")&&o.push(l)}if(n){let a=e.state.defaultCompletionSpec??{isDefault:!0},l=new Set(a.options??[]);for(let u of s)l.add(u);for(let u of i)l.delete(u);return a.options=l.size>0?Array.from(l):void 0,e.state.defaultCompletionSpec=a,Y("")}if(r){let a=e.state.emptyCompletionSpec??Object.create(null),l=new Set(a.options??[]);for(let u of s)l.add(u);for(let u of i)l.delete(u);return a.options=l.size>0?Array.from(l):void 0,e.state.emptyCompletionSpec=a,Y("")}if(o.length>0){for(let a of o){let l=e.state.completionSpecs.get(a)??{},u=new Set(l.options??[]);for(let c of s)u.add(c);for(let c of i)u.delete(c);l.options=u.size>0?Array.from(u):void 0,e.state.completionSpecs.set(a,l)}return Y("")}return L(`compopt: not currently executing completion function
198
+ `,1)}function So(e,t){if(e.state.loopDepth===0){if(e.state.parentHasLoopContext)throw new Tt;return J}if(t.length>1)throw new U(1,"",`bash: continue: too many arguments
199
+ `);let n=1;if(t.length>0){let r=Number.parseInt(t[0],10);if(Number.isNaN(r)||r<1)throw new U(1,"",`bash: continue: ${t[0]}: numeric argument required
200
+ `);n=r}throw new He(n)}function Dc(e,t){let n="";return e.state.integerVars?.has(t)&&(n+="i"),e.state.lowercaseVars?.has(t)&&(n+="l"),le(e,t)&&(n+="n"),e.state.readonlyVars?.has(t)&&(n+="r"),e.state.uppercaseVars?.has(t)&&(n+="u"),e.state.exportedVars?.has(t)&&(n+="x"),n===""?"--":`-${n}`}function Ao(e){return we(e)}function vo(e){return`'${e.replace(/'/g,"'\\''")}'`}function Ic(e,t){let n="",r="",s=!1;for(let i of t){let o=Dc(e,i);if(e.state.associativeArrays?.has(i)){let c=St(e,i);if(c.length===0)n+=`declare -A ${i}=()
201
+ `;else{let f=c.map(d=>{let p=ie(e,i,d)??"",h=Ao(p);return`[${vo(d)}]=${h}`});n+=`declare -A ${i}=(${f.join(" ")})
202
+ `}continue}let l=Ee(e,i);if(l.length>0){let c=l.map(f=>{let d=ie(e,i,f)??"";return`[${f}]=${on(d)}`});n+=`declare -a ${i}=(${c.join(" ")})
202
203
  `;continue}if(ke(e,i)){n+=`declare -a ${i}=()
203
- `;continue}let u=e.state.env.get(i);if(u!==void 0)n+=`declare ${o} ${i}=${mr(u)}
204
+ `;continue}let u=e.state.env.get(i);if(u!==void 0)n+=`declare ${o} ${i}=${gr(u)}
204
205
  `;else{let c=e.state.declaredVars?.has(i),f=e.state.localVarDepth?.has(i);c||f?n+=`declare ${o} ${i}
205
206
  `:(r+=`bash: declare: ${i}: not found
206
- `,s=!0)}}return L(n,r,s?1:0)}function Nc(e,t){let{filterExport:n,filterReadonly:r,filterNameref:s,filterIndexedArray:i,filterAssocArray:o}=t,a=n||r||s||i||o,l="",u=new Set;for(let f of e.state.env.keys())f.startsWith("BASH_")||u.add(f);for(let f of e.state.arrays?.keys()??[])u.add(f);if(e.state.localVarDepth)for(let f of e.state.localVarDepth.keys())u.add(f);if(e.state.associativeArrays)for(let f of e.state.associativeArrays)u.add(f);let c=Array.from(u).sort();for(let f of c){let d=Pc(e,f),p=e.state.associativeArrays?.has(f),h=be(e,f),m=!p&&ke(e,f);if(a&&(o&&!p||i&&!m||n&&!e.state.exportedVars?.has(f)||r&&!e.state.readonlyVars?.has(f)||s&&!le(e,f)))continue;if(p){let S=St(e,f);if(S.length===0)l+=`declare -A ${f}=()
207
- `;else{let y=S.map(g=>{let b=ie(e,f,g)??"",v=Eo(b);return`[${bo(g)}]=${v}`});l+=`declare -A ${f}=(${y.join(" ")})
208
- `}continue}if(h.length>0){let S=h.map(y=>{let g=ie(e,f,y)??"";return`[${y}]=${on(g)}`});l+=`declare -a ${f}=(${S.join(" ")})
207
+ `,s=!0)}}return T(n,r,s?1:0)}function Oc(e,t){let{filterExport:n,filterReadonly:r,filterNameref:s,filterIndexedArray:i,filterAssocArray:o}=t,a=n||r||s||i||o,l="",u=new Set;for(let f of e.state.env.keys())f.startsWith("BASH_")||u.add(f);for(let f of e.state.arrays?.keys()??[])u.add(f);if(e.state.localVarDepth)for(let f of e.state.localVarDepth.keys())u.add(f);if(e.state.associativeArrays)for(let f of e.state.associativeArrays)u.add(f);let c=Array.from(u).sort();for(let f of c){let d=Dc(e,f),p=e.state.associativeArrays?.has(f),h=Ee(e,f),m=!p&&ke(e,f);if(a&&(o&&!p||i&&!m||n&&!e.state.exportedVars?.has(f)||r&&!e.state.readonlyVars?.has(f)||s&&!le(e,f)))continue;if(p){let b=St(e,f);if(b.length===0)l+=`declare -A ${f}=()
208
+ `;else{let w=b.map(E=>{let S=ie(e,f,E)??"",v=Ao(S);return`[${vo(E)}]=${v}`});l+=`declare -A ${f}=(${w.join(" ")})
209
+ `}continue}if(h.length>0){let b=h.map(w=>{let E=ie(e,f,w)??"";return`[${w}]=${on(E)}`});l+=`declare -a ${f}=(${b.join(" ")})
209
210
  `;continue}if(ke(e,f)){l+=`declare -a ${f}=()
210
- `;continue}let E=e.state.env.get(f);E!==void 0&&(l+=`declare ${d} ${f}=${mr(E)}
211
- `)}return Y(l)}function Rc(e){let t="",n=Array.from(e.state.associativeArrays??[]).sort();for(let r of n){let s=St(e,r);if(s.length===0)t+=`declare -A ${r}=()
212
- `;else{let i=s.map(o=>{let a=ie(e,r,o)??"",l=Eo(a);return`[${bo(o)}]=${l}`});t+=`declare -A ${r}=(${i.join(" ")})
213
- `}}return Y(t)}function Dc(e){let t="",n=new Set(Array.from(e.state.arrays??[]).filter(([,s])=>s.kind==="indexed").map(([s])=>s)),r=Array.from(n).sort();for(let s of r){let i=be(e,s);if(i.length===0)t+=`declare -a ${s}=()
211
+ `;continue}let y=e.state.env.get(f);y!==void 0&&(l+=`declare ${d} ${f}=${gr(y)}
212
+ `)}return Y(l)}function _c(e){let t="",n=Array.from(e.state.associativeArrays??[]).sort();for(let r of n){let s=St(e,r);if(s.length===0)t+=`declare -A ${r}=()
213
+ `;else{let i=s.map(o=>{let a=ie(e,r,o)??"",l=Ao(a);return`[${vo(o)}]=${l}`});t+=`declare -A ${r}=(${i.join(" ")})
214
+ `}}return Y(t)}function Lc(e){let t="",n=new Set(Array.from(e.state.arrays??[]).filter(([,s])=>s.kind==="indexed").map(([s])=>s)),r=Array.from(n).sort();for(let s of r){let i=Ee(e,s);if(i.length===0)t+=`declare -a ${s}=()
214
215
  `;else{let o=i.map(a=>{let l=ie(e,s,a)??"";return`[${a}]=${on(l)}`});t+=`declare -a ${s}=(${o.join(" ")})
215
- `}}return Y(t)}function Ic(e){let t="",n=new Set;for(let s of e.state.env.keys())s.startsWith("BASH_")||n.add(s);let r=Array.from(n).sort();for(let s of r){if(e.state.associativeArrays?.has(s)||be(e,s).length>0||ke(e,s))continue;let a=e.state.env.get(s);a!==void 0&&(t+=`${s}=${Ee(a)}
216
- `)}return Y(t)}function So(e,t){e.state.integerVars??=new Set,e.state.integerVars.add(t)}function yr(e,t){return e.state.integerVars?.has(t)??!1}function Ao(e,t){e.state.lowercaseVars??=new Set,e.state.lowercaseVars.add(t),e.state.uppercaseVars?.delete(t)}function Rh(e,t){return e.state.lowercaseVars?.has(t)??!1}function vo(e,t){e.state.uppercaseVars??=new Set,e.state.uppercaseVars.add(t),e.state.lowercaseVars?.delete(t)}function Dh(e,t){return e.state.uppercaseVars?.has(t)??!1}function Gn(e,t,n){return Rh(e,t)?n.toLowerCase():Dh(e,t)?n.toUpperCase():n}async function Oc(e,t){try{let n=new j,r=te(n,t),s=await X(e,r.expression);return String(s)}catch{return"0"}}function Ih(e){let t=e.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);if(!t)return null;let n=t[0],r=n.length;if(e[r]!=="[")return null;let s=0,i=r+1;for(;r<e.length;r++)if(e[r]==="[")s++;else if(e[r]==="]"&&(s--,s===0))break;if(s!==0)return null;let o=e.slice(i,r);if(r++,e[r]!=="=")return null;r++;let a=e.slice(r);return{name:n,indexExpr:o,value:a}}async function xo(e,t){let n={maxElements:e.limits.maxArrayElements,maxStringBytes:e.limits.maxStringLength},r=!1,s=!1,i=!1,o=!1,a=!1,l=!1,u=!1,c=!1,f=!1,d=!1,p=!1,h=!1,m=!1,E=!1,S=!1,y=[];for(let $=0;$<t.length;$++){let C=t[$];if(C==="-a")r=!0;else if(C==="-A")s=!0;else if(C==="-r")i=!0;else if(C==="-x")o=!0;else if(C==="-p")a=!0;else if(C==="-n")l=!0;else if(C==="+n")u=!0;else if(C==="+a")c=!0;else if(C==="+x")f=!0;else if(C==="--"){y.push(...t.slice($+1));break}else if(C.startsWith("+")){for(let D of C.slice(1))if(D==="n")u=!0;else if(D==="a")c=!0;else if(D==="x")f=!0;else if(D!=="r"){if(D!=="i"){if(!(D==="f"||D==="F"))return L("",`bash: typeset: +${D}: invalid option
217
- `,2)}}}else if(C==="-i")d=!0;else if(C==="-l")p=!0;else if(C==="-u")h=!0;else if(C==="-f")m=!0;else if(C==="-F")E=!0;else if(C==="-g")S=!0;else if(C.startsWith("-"))for(let D of C.slice(1))if(D==="a")r=!0;else if(D==="A")s=!0;else if(D==="r")i=!0;else if(D==="x")o=!0;else if(D==="p")a=!0;else if(D==="n")l=!0;else if(D==="i")d=!0;else if(D==="l")p=!0;else if(D==="u")h=!0;else if(D==="f")m=!0;else if(D==="F")E=!0;else if(D==="g")S=!0;else return L("",`bash: typeset: -${D}: invalid option
218
- `,2);else y.push(C)}let b=e.state.localScopes.length>0&&!S,v=$=>{if(!b)return;let C=e.state.localScopes[e.state.localScopes.length-1];C.has($)||C.set($,e.state.env.get($))},x=$=>{if(!b)return;let C=e.state.localScopes[e.state.localScopes.length-1];for(C.has($)||C.set($,e.state.env.get($)),e.state.localArrayScopes??=[];e.state.localArrayScopes.length<e.state.localScopes.length;)e.state.localArrayScopes.push(new Map);let D=e.state.localArrayScopes.at(-1);if(D&&!D.has($)){let B=ve(e,$);D.set($,B?Le(B):void 0)}},A=$=>{b&&en(e,$)};if(E){if(y.length===0){let D=Array.from(e.state.functions.keys()).sort(),B="";for(let H of D)B+=`declare -f ${H}
219
- `;return Y(B)}let $=!0,C="";for(let D of y)e.state.functions.has(D)?C+=`${D}
220
- `:$=!1;return L(C,"",$?0:1)}if(m){if(y.length===0){let C="",D=Array.from(e.state.functions.keys()).sort();for(let B of D)C+=`${B} ()
216
+ `}}return Y(t)}function Tc(e){let t="",n=new Set;for(let s of e.state.env.keys())s.startsWith("BASH_")||n.add(s);let r=Array.from(n).sort();for(let s of r){if(e.state.associativeArrays?.has(s)||Ee(e,s).length>0||ke(e,s))continue;let a=e.state.env.get(s);a!==void 0&&(t+=`${s}=${we(a)}
217
+ `)}return Y(t)}function xo(e,t){e.state.integerVars??=new Set,e.state.integerVars.add(t)}function wr(e,t){return e.state.integerVars?.has(t)??!1}function $o(e,t){e.state.lowercaseVars??=new Set,e.state.lowercaseVars.add(t),e.state.uppercaseVars?.delete(t)}function Fh(e,t){return e.state.lowercaseVars?.has(t)??!1}function ko(e,t){e.state.uppercaseVars??=new Set,e.state.uppercaseVars.add(t),e.state.lowercaseVars?.delete(t)}function Mh(e,t){return e.state.uppercaseVars?.has(t)??!1}function Hn(e,t,n){return Fh(e,t)?n.toLowerCase():Mh(e,t)?n.toUpperCase():n}async function Fc(e,t){try{let n=new G,r=te(n,t),s=await X(e,r.expression);return String(s)}catch{return"0"}}function Bh(e){let t=e.match(/^[a-zA-Z_][a-zA-Z0-9_]*/);if(!t)return null;let n=t[0],r=n.length;if(e[r]!=="[")return null;let s=0,i=r+1;for(;r<e.length;r++)if(e[r]==="[")s++;else if(e[r]==="]"&&(s--,s===0))break;if(s!==0)return null;let o=e.slice(i,r);if(r++,e[r]!=="=")return null;r++;let a=e.slice(r);return{name:n,indexExpr:o,value:a}}async function Po(e,t){let n={maxElements:e.limits.maxArrayElements,maxStringBytes:e.limits.maxStringLength},r=!1,s=!1,i=!1,o=!1,a=!1,l=!1,u=!1,c=!1,f=!1,d=!1,p=!1,h=!1,m=!1,y=!1,b=!1,w=[];for(let P=0;P<t.length;P++){let N=t[P];if(N==="-a")r=!0;else if(N==="-A")s=!0;else if(N==="-r")i=!0;else if(N==="-x")o=!0;else if(N==="-p")a=!0;else if(N==="-n")l=!0;else if(N==="+n")u=!0;else if(N==="+a")c=!0;else if(N==="+x")f=!0;else if(N==="--"){w.push(...t.slice(P+1));break}else if(N.startsWith("+")){for(let D of N.slice(1))if(D==="n")u=!0;else if(D==="a")c=!0;else if(D==="x")f=!0;else if(D!=="r"){if(D!=="i"){if(!(D==="f"||D==="F"))return T("",`bash: typeset: +${D}: invalid option
218
+ `,2)}}}else if(N==="-i")d=!0;else if(N==="-l")p=!0;else if(N==="-u")h=!0;else if(N==="-f")m=!0;else if(N==="-F")y=!0;else if(N==="-g")b=!0;else if(N.startsWith("-"))for(let D of N.slice(1))if(D==="a")r=!0;else if(D==="A")s=!0;else if(D==="r")i=!0;else if(D==="x")o=!0;else if(D==="p")a=!0;else if(D==="n")l=!0;else if(D==="i")d=!0;else if(D==="l")p=!0;else if(D==="u")h=!0;else if(D==="f")m=!0;else if(D==="F")y=!0;else if(D==="g")b=!0;else return T("",`bash: typeset: -${D}: invalid option
219
+ `,2);else w.push(N)}let S=e.state.localScopes.length>0&&!b,v=P=>{if(!S)return;let N=e.state.localScopes[e.state.localScopes.length-1];N.has(P)||N.set(P,e.state.env.get(P))},A=P=>{if(!S)return;let N=e.state.localScopes[e.state.localScopes.length-1];for(N.has(P)||N.set(P,e.state.env.get(P)),e.state.localArrayScopes??=[];e.state.localArrayScopes.length<e.state.localScopes.length;)e.state.localArrayScopes.push(new Map);let D=e.state.localArrayScopes.at(-1);if(D&&!D.has(P)){let R=Ae(e,P);D.set(P,R?Le(R):void 0)}},x=P=>{S&&en(e,P)};if(y){if(w.length===0){let D=Array.from(e.state.functions.keys()).sort(),R="";for(let B of D)R+=`declare -f ${B}
220
+ `;return Y(R)}let P=!0,N="";for(let D of w)e.state.functions.has(D)?N+=`${D}
221
+ `:P=!1;return T(N,"",P?0:1)}if(m){if(w.length===0){let N="",D=Array.from(e.state.functions.keys()).sort();for(let R of D)N+=`${R} ()
221
222
  {
222
223
  # function body
223
224
  }
224
- `;return Y(C)}let $=!0;for(let C of y)e.state.functions.has(C)||($=!1);return L("","",$?0:1)}if(a&&y.length>0)return Cc(e,y);if(a&&y.length===0)return Nc(e,{filterExport:o,filterReadonly:i,filterNameref:l,filterIndexedArray:r,filterAssocArray:s});if(y.length===0&&s&&!a)return Rc(e);if(y.length===0&&r&&!a)return Dc(e);if(y.length===0&&!a)return Ic(e);let k="",N=0;for(let $ of y){let C=$.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(C&&!c){let R=C[1],W=C[2],V=ue(e,R);if(V)return V;if(s&&be(e,R).length>0){k+=`bash: declare: ${R}: cannot convert indexed to associative array
225
- `,N=1;continue}if((r||!s&&!r)&&e.state.associativeArrays?.has(R)){k+=`bash: declare: ${R}: cannot convert associative to indexed array
226
- `,N=1;continue}let I=s&&W.includes("[")?ys(W,n):void 0,O=I===void 0?Ot(W,{...n,maxElements:s?n.maxElements*2:n.maxElements}):void 0;if(e.executionScope.consumeWork(I?.length??O?.length??0,"declare array assignment"),x(R),s?(e.state.associativeArrays??=new Set,e.state.associativeArrays.add(R),Vt(e,R,"associative")):Vt(e,R,"indexed"),ye(e,R),e.state.env.delete(R),s&&W.includes("["))for(let[M,ee]of I??[])U(e,R,M,Kt(e,ee),"associative");else if(s){let M=O??[];for(let ee=0;ee<M.length;ee+=2){let K=M[ee],De=ee+1<M.length?M[ee+1]:"";U(e,R,K,De,"associative")}}else{let M=O??[];if(M.some(K=>/^\[[^\]]+\]=/.test(K))){let K=0;for(let De of M){let lt=De.match(/^\[([^\]]+)\]=(.*)$/);if(lt){let Ct=lt[1],ut=lt[2],ct;if(/^-?\d+$/.test(Ct))ct=Number.parseInt(Ct,10);else try{let Nt=new j,Lf=te(Nt,Ct);ct=await X(e,Lf.expression)}catch{ct=0}U(e,R,ct,Kt(e,ut)),K=ct+1}else U(e,R,K,De),K++}}else for(let K=0;K<M.length;K++)U(e,R,K,M[K])}A(R),i&&je(e,R),o&&yt(e,R);continue}if(u){let R=$.includes("=")?$.slice(0,$.indexOf("=")):$;if(Dl(e,R),!$.includes("="))continue}if(f){let R=$.includes("=")?$.slice(0,$.indexOf("=")):$;if(Zr(e,R),!$.includes("="))continue}let D=Ih($);if(D){let{name:R,indexExpr:W,value:V}=D,I=ue(e,R);if(I)return I;x(R);let O;try{let M=new j,ee=te(M,W);O=await X(e,ee.expression)}catch{let M=parseInt(W,10);O=Number.isNaN(M)?0:M}U(e,R,O,V),A(R),i&&je(e,R),o&&yt(e,R);continue}let B=$.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(B&&!c){let R=B[1],W=B[2],V=ue(e,R);if(V)return V;x(R);let I=Ot(W,n);if(e.state.associativeArrays?.has(R)){let O=ys(W,n);e.executionScope.consumeWork(O.length,"declare array append"),dn(e,R,O.map(([M])=>M));for(let[M,ee]of O)U(e,R,M,ee,"associative")}else{e.executionScope.consumeWork(I.length,"declare array append");let O=be(e,R),M=0,ee=e.state.env.get(R);O.length===0&&ee!==void 0?(U(e,R,0,ee),e.state.env.delete(R),M=1):O.length>0&&(M=Math.max(...O)+1),dn(e,R,Array.from({length:I.length},(K,De)=>M+De));for(let K=0;K<I.length;K++)U(e,R,M+K,I[K])}A(R),i&&je(e,R),o&&yt(e,R);continue}let H=$.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(H){let R=H[1],W=H[2],V=ue(e,R);if(V)return V;v(R),d&&So(e,R),p&&Ao(e,R),h&&vo(e,R);let O=be(e,R).length>0||e.state.associativeArrays?.has(R);if(yr(e,R)){let M=e.state.env.get(R)??"0",ee=parseInt(M,10)||0,K=parseInt(await Oc(e,W),10)||0;W=String(ee+K),e.state.env.set(R,W)}else if(O){W=Gn(e,R,W);let M=ie(e,R,0)??"";U(e,R,0,Ft([M,W],"",e.limits.maxStringLength,"declare append"))}else{W=Gn(e,R,W);let M=e.state.env.get(R)??"";e.state.env.set(R,Ft([M,W],"",e.limits.maxStringLength,"declare append"))}A(R),i&&je(e,R),o&&yt(e,R),e.state.options.allexport&&!f&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(R));continue}if($.includes("=")){let R=$.indexOf("="),W=$.slice(0,R),V=$.slice(R+1);if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(W)){k+=`bash: typeset: \`${W}': not a valid identifier
227
- `,N=1;continue}let I=ue(e,W);if(I)return I;if(v(W),l){if(V!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(V)){k+=`bash: declare: \`${V}': invalid variable name for name reference
228
- `,N=1;continue}e.state.env.set(W,V),It(e,W),V!==""&&Ur(e,V)&&$i(e,W),A(W),i&&je(e,W),o&&yt(e,W);continue}if(d&&So(e,W),p&&Ao(e,W),h&&vo(e,W),yr(e,W)&&(V=await Oc(e,V)),V=Gn(e,W,V),le(e,W)){let O=Te(e,W);O&&O!==W?e.state.env.set(O,V):e.state.env.set(W,V)}else e.state.env.set(W,V);A(W),i&&je(e,W),o&&yt(e,W),e.state.options.allexport&&!f&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(W))}else{let R=$;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(R)){k+=`bash: typeset: \`${R}': not a valid identifier
229
- `,N=1;continue}if(r||s?x(R):v(R),l){It(e,R);let V=e.state.env.get(R);V!==void 0&&V!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(V)?Il(e,R):V&&Ur(e,V)&&$i(e,R),A(R),i&&je(e,R),o&&yt(e,R);continue}if(d&&So(e,R),p&&Ao(e,R),h&&vo(e,R),s){if(be(e,R).length>0){k+=`bash: declare: ${R}: cannot convert indexed to associative array
230
- `,N=1;continue}e.state.associativeArrays??=new Set,e.state.associativeArrays.add(R),Vt(e,R,"associative")}let W=ke(e,R);!e.state.env.has(R)&&!W&&(r||s?Vt(e,R,s?"associative":"indexed"):(e.state.declaredVars??=new Set,e.state.declaredVars.add(R))),A(R),i&&je(e,R),o&&yt(e,R)}}return L("",k,N)}async function $o(e,t){let n={maxElements:e.limits.maxArrayElements,maxStringBytes:e.limits.maxStringLength},r=!1,s=!1,i=!1,o=[];for(let a=0;a<t.length;a++){let l=t[a];if(l==="-a")r=!0;else if(l==="-A")s=!0;else if(l==="-p")i=!0;else if(l==="--"){o.push(...t.slice(a+1));break}else l.startsWith("-")||o.push(l)}if(o.length===0){let a="",l=Array.from(e.state.readonlyVars||[]).sort();for(let u of l){let c=e.state.env.get(u);if(c!==void 0){let f=c.replace(/\\/g,"\\\\").replace(/"/g,'\\"');a+=`declare -r ${u}="${f}"
231
- `}}return Y(a)}for(let a of o){let l=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(l){let d=l[1],p=l[2],h=ue(e,d);if(h)return h;let m=Ot(p,n);if(e.state.associativeArrays?.has(d)){let E=ys(p,n);e.executionScope.consumeWork(E.length,"readonly array append"),dn(e,d,E.map(([S])=>S));for(let[S,y]of E)U(e,d,S,y,"associative")}else{e.executionScope.consumeWork(m.length,"readonly array append");let E=be(e,d),S=0,y=e.state.env.get(d);E.length===0&&y!==void 0?(U(e,d,0,y),e.state.env.delete(d),S=1):E.length>0&&(S=Math.max(...E)+1),dn(e,d,Array.from({length:m.length},(g,b)=>S+b));for(let g=0;g<m.length;g++)U(e,d,S+g,m[g])}je(e,d);continue}let u=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(u){let d=u[1],p=u[2],h=ue(e,d);if(h)return h;let m=e.state.env.get(d)??"";e.state.env.set(d,Ft([m,p],"",e.limits.maxStringLength,"readonly append")),je(e,d);continue}let c=lc(a,n);if(c.value===void 0&&!c.isArray){je(e,c.name);continue}let f=await uc(e,c,{makeReadonly:!0});if(f)return f}return J}function ko(e){return e.state.directoryStack??=[],e.state.directoryStack}function gr(e,t){return t&&e===t?"~":t&&e.startsWith(`${t}/`)?`~${e.slice(t.length)}`:e}function Oh(e){let t=e.split("/").filter(r=>r&&r!=="."),n=[];for(let r of t)r===".."?n.pop():n.push(r);return`/${n.join("/")}`}async function Po(e,t){let n=ko(e),r;for(let a=0;a<t.length;a++){let l=t[a];if(l==="--"){if(a+1<t.length){if(r!==void 0)return _(`bash: pushd: too many arguments
232
- `,2);r=t[a+1],a++}}else{if(l.startsWith("-")&&l!=="-")return _(`bash: pushd: ${l}: invalid option
233
- `,2);if(r!==void 0)return _(`bash: pushd: too many arguments
234
- `,2);r=l}}if(r===void 0){if(n.length<2)return _(`bash: pushd: no other directory
235
- `,1);let a=n[0];n[0]=n[1],n[1]=a,r=n[0]}let s;if(r.startsWith("/"))s=r;else if(r===".."){let a=e.state.cwd.split("/").filter(l=>l);a.pop(),s=`/${a.join("/")}`}else r==="."?s=e.state.cwd:r.startsWith("~")?s=(e.state.env.get("HOME")||"/")+r.slice(1):s=`${e.state.cwd}/${r}`;s=Oh(s);try{if(!(await e.fs.stat(s)).isDirectory)return _(`bash: pushd: ${r}: Not a directory
236
- `,1)}catch{return _(`bash: pushd: ${r}: No such file or directory
237
- `,1)}n.unshift(e.state.cwd),e.state.previousDir=e.state.cwd,e.state.cwd=s,e.state.env.set("PWD",s),e.state.env.set("OLDPWD",e.state.previousDir);let i=e.state.env.get("HOME")||"",o=`${[s,...n].map(a=>gr(a,i)).join(" ")}
238
- `;return Y(o)}function Co(e,t){let n=ko(e);for(let o of t)if(o!=="--")return o.startsWith("-")&&o!=="-"?_(`bash: popd: ${o}: invalid option
239
- `,2):_(`bash: popd: too many arguments
240
- `,2);if(n.length===0)return _(`bash: popd: directory stack empty
241
- `,1);let r=n.shift();if(!r)return _(`bash: popd: directory stack empty
242
- `,1);e.state.previousDir=e.state.cwd,e.state.cwd=r,e.state.env.set("PWD",r),e.state.env.set("OLDPWD",e.state.previousDir);let s=e.state.env.get("HOME")||"",i=`${[r,...n].map(o=>gr(o,s)).join(" ")}
243
- `;return Y(i)}function No(e,t){let n=ko(e),r=!1,s=!1,i=!1,o=!1;for(let c of t)if(c!=="--")if(c.startsWith("-"))for(let f of c.slice(1))if(f==="c")r=!0;else if(f==="l")s=!0;else if(f==="p")i=!0;else if(f==="v")i=!0,o=!0;else return _(`bash: dirs: -${f}: invalid option
244
- `,2);else return _(`bash: dirs: too many arguments
245
- `,1);if(r)return e.state.directoryStack=[],J;let a=[e.state.cwd,...n],l=e.state.env.get("HOME")||"",u;return o?(u=a.map((c,f)=>{let d=s?c:gr(c,l);return` ${f} ${d}`}).join(`
225
+ `;return Y(N)}let P=!0;for(let N of w)e.state.functions.has(N)||(P=!1);return T("","",P?0:1)}if(a&&w.length>0)return Ic(e,w);if(a&&w.length===0)return Oc(e,{filterExport:o,filterReadonly:i,filterNameref:l,filterIndexedArray:r,filterAssocArray:s});if(w.length===0&&s&&!a)return _c(e);if(w.length===0&&r&&!a)return Lc(e);if(w.length===0&&!a)return Tc(e);let $="",I=0;for(let P of w){let N=P.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(N&&!c){let k=N[1],M=N[2],z=ue(e,k);if(z)return z;if(s&&Ee(e,k).length>0){$+=`bash: declare: ${k}: cannot convert indexed to associative array
226
+ `,I=1;continue}if((r||!s&&!r)&&e.state.associativeArrays?.has(k)){$+=`bash: declare: ${k}: cannot convert associative to indexed array
227
+ `,I=1;continue}let O=s&&M.includes("[")?bs(M,n):void 0,_=O===void 0?Ot(M,{...n,maxElements:s?n.maxElements*2:n.maxElements}):void 0;if(e.executionScope.consumeWork(O?.length??_?.length??0,"declare array assignment"),A(k),s?(e.state.associativeArrays??=new Set,e.state.associativeArrays.add(k),Vt(e,k,"associative")):Vt(e,k,"indexed"),ye(e,k),e.state.env.delete(k),s&&M.includes("["))for(let[V,ee]of O??[])j(e,k,V,Kt(e,ee),"associative");else if(s){let V=_??[];for(let ee=0;ee<V.length;ee+=2){let K=V[ee],De=ee+1<V.length?V[ee+1]:"";j(e,k,K,De,"associative")}}else{let V=_??[];if(V.some(K=>/^\[[^\]]+\]=/.test(K))){let K=0;for(let De of V){let at=De.match(/^\[([^\]]+)\]=(.*)$/);if(at){let Ct=at[1],lt=at[2],ut;if(/^-?\d+$/.test(Ct))ut=Number.parseInt(Ct,10);else try{let Nt=new G,Vf=te(Nt,Ct);ut=await X(e,Vf.expression)}catch{ut=0}j(e,k,ut,Kt(e,lt)),K=ut+1}else j(e,k,K,De),K++}}else for(let K=0;K<V.length;K++)j(e,k,K,V[K])}x(k),i&&je(e,k),o&&mt(e,k);continue}if(u){let k=P.includes("=")?P.slice(0,P.indexOf("=")):P;if(Ll(e,k),!P.includes("="))continue}if(f){let k=P.includes("=")?P.slice(0,P.indexOf("=")):P;if(Yr(e,k),!P.includes("="))continue}let D=Bh(P);if(D){let{name:k,indexExpr:M,value:z}=D,O=ue(e,k);if(O)return O;A(k);let _;try{let V=new G,ee=te(V,M);_=await X(e,ee.expression)}catch{let V=parseInt(M,10);_=Number.isNaN(V)?0:V}j(e,k,_,z),x(k),i&&je(e,k),o&&mt(e,k);continue}let R=P.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(R&&!c){let k=R[1],M=R[2],z=ue(e,k);if(z)return z;A(k);let O=Ot(M,n);if(e.state.associativeArrays?.has(k)){let _=bs(M,n);e.executionScope.consumeWork(_.length,"declare array append"),dn(e,k,_.map(([V])=>V));for(let[V,ee]of _)j(e,k,V,ee,"associative")}else{e.executionScope.consumeWork(O.length,"declare array append");let _=Ee(e,k),V=0,ee=e.state.env.get(k);_.length===0&&ee!==void 0?(j(e,k,0,ee),e.state.env.delete(k),V=1):_.length>0&&(V=Math.max(..._)+1),dn(e,k,Array.from({length:O.length},(K,De)=>V+De));for(let K=0;K<O.length;K++)j(e,k,V+K,O[K])}x(k),i&&je(e,k),o&&mt(e,k);continue}let B=P.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(B){let k=B[1],M=B[2],z=ue(e,k);if(z)return z;v(k),d&&xo(e,k),p&&$o(e,k),h&&ko(e,k);let _=Ee(e,k).length>0||e.state.associativeArrays?.has(k);if(wr(e,k)){let V=e.state.env.get(k)??"0",ee=parseInt(V,10)||0,K=parseInt(await Fc(e,M),10)||0;M=String(ee+K),e.state.env.set(k,M)}else if(_){M=Hn(e,k,M);let V=ie(e,k,0)??"";j(e,k,0,Ft([V,M],"",e.limits.maxStringLength,"declare append"))}else{M=Hn(e,k,M);let V=e.state.env.get(k)??"";e.state.env.set(k,Ft([V,M],"",e.limits.maxStringLength,"declare append"))}x(k),i&&je(e,k),o&&mt(e,k),e.state.options.allexport&&!f&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(k));continue}if(P.includes("=")){let k=P.indexOf("="),M=P.slice(0,k),z=P.slice(k+1);if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(M)){$+=`bash: typeset: \`${M}': not a valid identifier
228
+ `,I=1;continue}let O=ue(e,M);if(O)return O;if(v(M),l){if(z!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(z)){$+=`bash: declare: \`${z}': invalid variable name for name reference
229
+ `,I=1;continue}e.state.env.set(M,z),It(e,M),z!==""&&Zr(e,z)&&Pi(e,M),x(M),i&&je(e,M),o&&mt(e,M);continue}if(d&&xo(e,M),p&&$o(e,M),h&&ko(e,M),wr(e,M)&&(z=await Fc(e,z)),z=Hn(e,M,z),le(e,M)){let _=Te(e,M);_&&_!==M?e.state.env.set(_,z):e.state.env.set(M,z)}else e.state.env.set(M,z);x(M),i&&je(e,M),o&&mt(e,M),e.state.options.allexport&&!f&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(M))}else{let k=P;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(k)){$+=`bash: typeset: \`${k}': not a valid identifier
230
+ `,I=1;continue}if(r||s?A(k):v(k),l){It(e,k);let z=e.state.env.get(k);z!==void 0&&z!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(z)?Tl(e,k):z&&Zr(e,z)&&Pi(e,k),x(k),i&&je(e,k),o&&mt(e,k);continue}if(d&&xo(e,k),p&&$o(e,k),h&&ko(e,k),s){if(Ee(e,k).length>0){$+=`bash: declare: ${k}: cannot convert indexed to associative array
231
+ `,I=1;continue}e.state.associativeArrays??=new Set,e.state.associativeArrays.add(k),Vt(e,k,"associative")}let M=ke(e,k);!e.state.env.has(k)&&!M&&(r||s?Vt(e,k,s?"associative":"indexed"):(e.state.declaredVars??=new Set,e.state.declaredVars.add(k))),x(k),i&&je(e,k),o&&mt(e,k)}}return T("",$,I)}async function Co(e,t){let n={maxElements:e.limits.maxArrayElements,maxStringBytes:e.limits.maxStringLength},r=!1,s=!1,i=!1,o=[];for(let a=0;a<t.length;a++){let l=t[a];if(l==="-a")r=!0;else if(l==="-A")s=!0;else if(l==="-p")i=!0;else if(l==="--"){o.push(...t.slice(a+1));break}else l.startsWith("-")||o.push(l)}if(o.length===0){let a="",l=Array.from(e.state.readonlyVars||[]).sort();for(let u of l){let c=e.state.env.get(u);if(c!==void 0){let f=c.replace(/\\/g,"\\\\").replace(/"/g,'\\"');a+=`declare -r ${u}="${f}"
232
+ `}}return Y(a)}for(let a of o){let l=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(l){let d=l[1],p=l[2],h=ue(e,d);if(h)return h;let m=Ot(p,n);if(e.state.associativeArrays?.has(d)){let y=bs(p,n);e.executionScope.consumeWork(y.length,"readonly array append"),dn(e,d,y.map(([b])=>b));for(let[b,w]of y)j(e,d,b,w,"associative")}else{e.executionScope.consumeWork(m.length,"readonly array append");let y=Ee(e,d),b=0,w=e.state.env.get(d);y.length===0&&w!==void 0?(j(e,d,0,w),e.state.env.delete(d),b=1):y.length>0&&(b=Math.max(...y)+1),dn(e,d,Array.from({length:m.length},(E,S)=>b+S));for(let E=0;E<m.length;E++)j(e,d,b+E,m[E])}je(e,d);continue}let u=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(u){let d=u[1],p=u[2],h=ue(e,d);if(h)return h;let m=e.state.env.get(d)??"";e.state.env.set(d,Ft([m,p],"",e.limits.maxStringLength,"readonly append")),je(e,d);continue}let c=dc(a,n);if(c.value===void 0&&!c.isArray){je(e,c.name);continue}let f=await pc(e,c,{makeReadonly:!0});if(f)return f}return J}function No(e){return e.state.directoryStack??=[],e.state.directoryStack}function Er(e,t){return t&&e===t?"~":t&&e.startsWith(`${t}/`)?`~${e.slice(t.length)}`:e}function Wh(e){let t=e.split("/").filter(r=>r&&r!=="."),n=[];for(let r of t)r===".."?n.pop():n.push(r);return`/${n.join("/")}`}async function Ro(e,t){let n=No(e),r;for(let a=0;a<t.length;a++){let l=t[a];if(l==="--"){if(a+1<t.length){if(r!==void 0)return L(`bash: pushd: too many arguments
233
+ `,2);r=t[a+1],a++}}else{if(l.startsWith("-")&&l!=="-")return L(`bash: pushd: ${l}: invalid option
234
+ `,2);if(r!==void 0)return L(`bash: pushd: too many arguments
235
+ `,2);r=l}}if(r===void 0){if(n.length<2)return L(`bash: pushd: no other directory
236
+ `,1);let a=n[0];n[0]=n[1],n[1]=a,r=n[0]}let s;if(r.startsWith("/"))s=r;else if(r===".."){let a=e.state.cwd.split("/").filter(l=>l);a.pop(),s=`/${a.join("/")}`}else r==="."?s=e.state.cwd:r.startsWith("~")?s=(e.state.env.get("HOME")||"/")+r.slice(1):s=`${e.state.cwd}/${r}`;s=Wh(s);try{if(!(await e.fs.stat(s)).isDirectory)return L(`bash: pushd: ${r}: Not a directory
237
+ `,1)}catch{return L(`bash: pushd: ${r}: No such file or directory
238
+ `,1)}n.unshift(e.state.cwd),e.state.previousDir=e.state.cwd,e.state.cwd=s,e.state.env.set("PWD",s),e.state.env.set("OLDPWD",e.state.previousDir);let i=e.state.env.get("HOME")||"",o=`${[s,...n].map(a=>Er(a,i)).join(" ")}
239
+ `;return Y(o)}function Do(e,t){let n=No(e);for(let o of t)if(o!=="--")return o.startsWith("-")&&o!=="-"?L(`bash: popd: ${o}: invalid option
240
+ `,2):L(`bash: popd: too many arguments
241
+ `,2);if(n.length===0)return L(`bash: popd: directory stack empty
242
+ `,1);let r=n.shift();if(!r)return L(`bash: popd: directory stack empty
243
+ `,1);e.state.previousDir=e.state.cwd,e.state.cwd=r,e.state.env.set("PWD",r),e.state.env.set("OLDPWD",e.state.previousDir);let s=e.state.env.get("HOME")||"",i=`${[r,...n].map(o=>Er(o,s)).join(" ")}
244
+ `;return Y(i)}function Io(e,t){let n=No(e),r=!1,s=!1,i=!1,o=!1;for(let c of t)if(c!=="--")if(c.startsWith("-"))for(let f of c.slice(1))if(f==="c")r=!0;else if(f==="l")s=!0;else if(f==="p")i=!0;else if(f==="v")i=!0,o=!0;else return L(`bash: dirs: -${f}: invalid option
245
+ `,2);else return L(`bash: dirs: too many arguments
246
+ `,1);if(r)return e.state.directoryStack=[],J;let a=[e.state.cwd,...n],l=e.state.env.get("HOME")||"",u;return o?(u=a.map((c,f)=>{let d=s?c:Er(c,l);return` ${f} ${d}`}).join(`
246
247
  `),u+=`
247
- `):i?u=a.map(c=>s?c:gr(c,l)).join(`
248
+ `):i?u=a.map(c=>s?c:Er(c,l)).join(`
248
249
  `)+`
249
- `:u=a.map(c=>s?c:gr(c,l)).join(" ")+`
250
- `,Y(u)}async function Ps(e,t,n,r=!1){let s=t;if(s.length>0){let l=s[0];if(l==="--")s=s.slice(1);else if(l.startsWith("-")&&l!=="-"&&l.length>1)return _(`bash: eval: ${l}: invalid option
250
+ `:u=a.map(c=>s?c:Er(c,l)).join(" ")+`
251
+ `,Y(u)}async function Ds(e,t,n,r=!1){let s=t;if(s.length>0){let l=s[0];if(l==="--")s=s.slice(1);else if(l.startsWith("-")&&l!=="-"&&l.length>1)return L(`bash: eval: ${l}: invalid option
251
252
  eval: usage: eval [arg ...]
252
- `,2)}if(s.length===0)return J;let i=s.join(" ");if(i.trim()==="")return J;let o=e.state.groupStdin,a=r||n!==void 0&&n!=="";a&&(e.state.groupStdin=n??"");try{let l=dt(i);return await e.executeScript(l)}catch(l){if(l instanceof Ge||l instanceof He||l instanceof Ie||l instanceof q)throw l;if(l.name==="ParseException")return _(`bash: eval: ${l.message}
253
- `);throw l}finally{(a||o!==void 0&&e.state.groupStdin===void 0)&&(e.state.groupStdin=o)}}function Ro(e,t){let n,r="";if(t.length===0)n=e.state.lastExitCode;else{let s=t[0];if(s===""||!/^-?\d+$/.test(s))r=`bash: exit: ${s}: numeric argument required
254
- `,n=2;else{let i=BigInt(s);n=Number((i%256n+256n)%256n)}}throw new q(n,"",r)}function Do(e,t){let n=!1,r=[];for(let o of t)o==="-n"?n=!0:o==="-p"||o==="--"||r.push(o);if(r.length===0&&!n){let o="",a=e.state.exportedVars??new Set,l=Array.from(a).sort();for(let u of l){let c=e.state.env.get(u);c!==void 0&&(o+=`declare -x ${u}=${mr(c)}
255
- `)}return Y(o)}if(n){for(let o of r){let a,l;if(o.includes("=")){let u=o.indexOf("=");a=o.slice(0,u),l=o.slice(u+1)}else a=o;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(a))return L("",`bash: export: \`${o}': not a valid identifier
256
- `,1);l!==void 0&&(ue(e,a),e.state.env.set(a,l)),Zr(e,a)}return J}let s="",i=0;for(let o of r){let a,l,u=!1,c=o.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(c)a=c[1],l=c[2],u=!0;else if(o.includes("=")){let f=o.indexOf("=");a=o.slice(0,f),l=o.slice(f+1)}else a=o;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(a)){s+=`bash: export: \`${o}': not a valid identifier
257
- `,i=1;continue}if(l!==void 0)if(ue(e,a),u){let f=e.state.env.get(a)??"";e.state.env.set(a,f+l)}else e.state.env.set(a,l);else e.state.env.has(a)||e.state.env.set(a,"");yt(e,a)}return L("",s,i)}function Cs(e,t){if(t.length<2)return _(`bash: getopts: usage: getopts optstring name [arg ...]
258
- `);let n=t[0],r=t[1],s=!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(r),i=n.startsWith(":"),o=i?n.slice(1):n,a;if(t.length>2)a=t.slice(2);else{let m=Number.parseInt(e.state.env.get("#")||"0",10);a=[];for(let E=1;E<=m;E++)a.push(e.state.env.get(String(E))||"")}let l=Number.parseInt(e.state.env.get("OPTIND")||"1",10);l<1&&(l=1);let u=Number.parseInt(e.state.env.get("__GETOPTS_CHARINDEX")||"0",10);if(e.state.env.set("OPTARG",""),l>a.length)return s||e.state.env.set(r,"?"),e.state.env.set("OPTIND",String(a.length+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),{exitCode:s?2:1,stdout:"",stderr:""};let c=a[l-1];if(!c||c==="-"||!c.startsWith("-"))return s||e.state.env.set(r,"?"),{exitCode:s?2:1,stdout:"",stderr:""};if(c==="--")return e.state.env.set("OPTIND",String(l+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),s||e.state.env.set(r,"?"),{exitCode:s?2:1,stdout:"",stderr:""};let f=u===0?1:u,d=c[f];if(!d)return e.state.env.set("OPTIND",String(l+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),Cs(e,t);let p=o.indexOf(d);if(p===-1){let m="";return i?e.state.env.set("OPTARG",d):m=`bash: illegal option -- ${d}
253
+ `,2)}if(s.length===0)return J;let i=s.join(" ");if(i.trim()==="")return J;let o=e.state.groupStdin,a=r||n!==void 0&&n!=="";a&&(e.state.groupStdin=n??"");try{let l=ft(i);return await e.executeScript(l)}catch(l){if(l instanceof Ge||l instanceof He||l instanceof Ie||l instanceof U)throw l;if(l.name==="ParseException")return L(`bash: eval: ${l.message}
254
+ `);throw l}finally{(a||o!==void 0&&e.state.groupStdin===void 0)&&(e.state.groupStdin=o)}}function Oo(e,t){let n,r="";if(t.length===0)n=e.state.lastExitCode;else{let s=t[0];if(s===""||!/^-?\d+$/.test(s))r=`bash: exit: ${s}: numeric argument required
255
+ `,n=2;else{let i=BigInt(s);n=Number((i%256n+256n)%256n)}}throw new U(n,"",r)}function _o(e,t){let n=!1,r=[];for(let o of t)o==="-n"?n=!0:o==="-p"||o==="--"||r.push(o);if(r.length===0&&!n){let o="",a=e.state.exportedVars??new Set,l=Array.from(a).sort();for(let u of l){let c=e.state.env.get(u);c!==void 0&&(o+=`declare -x ${u}=${gr(c)}
256
+ `)}return Y(o)}if(n){for(let o of r){let a,l;if(o.includes("=")){let u=o.indexOf("=");a=o.slice(0,u),l=o.slice(u+1)}else a=o;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(a))return T("",`bash: export: \`${o}': not a valid identifier
257
+ `,1);l!==void 0&&(ue(e,a),e.state.env.set(a,l)),Yr(e,a)}return J}let s="",i=0;for(let o of r){let a,l,u=!1,c=o.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(c)a=c[1],l=c[2],u=!0;else if(o.includes("=")){let f=o.indexOf("=");a=o.slice(0,f),l=o.slice(f+1)}else a=o;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(a)){s+=`bash: export: \`${o}': not a valid identifier
258
+ `,i=1;continue}if(l!==void 0)if(ue(e,a),u){let f=e.state.env.get(a)??"";e.state.env.set(a,f+l)}else e.state.env.set(a,l);else e.state.env.has(a)||e.state.env.set(a,"");mt(e,a)}return T("",s,i)}function Is(e,t){if(t.length<2)return L(`bash: getopts: usage: getopts optstring name [arg ...]
259
+ `);let n=t[0],r=t[1],s=!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(r),i=n.startsWith(":"),o=i?n.slice(1):n,a;if(t.length>2)a=t.slice(2);else{let m=Number.parseInt(e.state.env.get("#")||"0",10);a=[];for(let y=1;y<=m;y++)a.push(e.state.env.get(String(y))||"")}let l=Number.parseInt(e.state.env.get("OPTIND")||"1",10);l<1&&(l=1);let u=Number.parseInt(e.state.env.get("__GETOPTS_CHARINDEX")||"0",10);if(e.state.env.set("OPTARG",""),l>a.length)return s||e.state.env.set(r,"?"),e.state.env.set("OPTIND",String(a.length+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),{exitCode:s?2:1,stdout:"",stderr:""};let c=a[l-1];if(!c||c==="-"||!c.startsWith("-"))return s||e.state.env.set(r,"?"),{exitCode:s?2:1,stdout:"",stderr:""};if(c==="--")return e.state.env.set("OPTIND",String(l+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),s||e.state.env.set(r,"?"),{exitCode:s?2:1,stdout:"",stderr:""};let f=u===0?1:u,d=c[f];if(!d)return e.state.env.set("OPTIND",String(l+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),Is(e,t);let p=o.indexOf(d);if(p===-1){let m="";return i?e.state.env.set("OPTARG",d):m=`bash: illegal option -- ${d}
259
260
  `,s||e.state.env.set(r,"?"),f+1<c.length?(e.state.env.set("__GETOPTS_CHARINDEX",String(f+1)),e.state.env.set("OPTIND",String(l))):(e.state.env.set("OPTIND",String(l+1)),e.state.env.set("__GETOPTS_CHARINDEX","0")),{exitCode:s?2:0,stdout:"",stderr:m}}if(p+1<o.length&&o[p+1]===":")if(f+1<c.length)e.state.env.set("OPTARG",c.slice(f+1)),e.state.env.set("OPTIND",String(l+1)),e.state.env.set("__GETOPTS_CHARINDEX","0");else{if(l>=a.length){let m="";return i?(e.state.env.set("OPTARG",d),s||e.state.env.set(r,":")):(m=`bash: option requires an argument -- ${d}
260
- `,s||e.state.env.set(r,"?")),e.state.env.set("OPTIND",String(l+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),{exitCode:s?2:0,stdout:"",stderr:m}}e.state.env.set("OPTARG",a[l]),e.state.env.set("OPTIND",String(l+2)),e.state.env.set("__GETOPTS_CHARINDEX","0")}else f+1<c.length?(e.state.env.set("__GETOPTS_CHARINDEX",String(f+1)),e.state.env.set("OPTIND",String(l))):(e.state.env.set("OPTIND",String(l+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"));return s||e.state.env.set(r,d),{exitCode:s?2:0,stdout:"",stderr:""}}async function Io(e,t){e.state.hashTable||(e.state.hashTable=new Map);let n=!1,r=!1,s=!1,i=!1,o=!1,a="",l=[],u=0;for(;u<t.length;){let h=t[u];if(h==="--"){u++,l.push(...t.slice(u));break}if(h==="-r")n=!0,u++;else if(h==="-d")r=!0,u++;else if(h==="-l")s=!0,u++;else if(h==="-t")o=!0,u++;else if(h==="-p"){if(i=!0,u++,u>=t.length)return _(`bash: hash: -p: option requires an argument
261
- `,1);a=t[u],u++}else if(h.startsWith("-")&&h.length>1){for(let m of h.slice(1))if(m==="r")n=!0;else if(m==="d")r=!0;else if(m==="l")s=!0;else if(m==="t")o=!0;else return m==="p"?_(`bash: hash: -p: option requires an argument
262
- `,1):_(`bash: hash: -${m}: invalid option
263
- `,1);u++}else l.push(h),u++}if(n)return e.state.hashTable.clear(),J;if(r){if(l.length===0)return _(`bash: hash: -d: option requires an argument
264
- `,1);let h=!1,m="";for(let E of l)e.state.hashTable.has(E)?e.state.hashTable.delete(E):(m+=`bash: hash: ${E}: not found
265
- `,h=!0);return h?_(m,1):J}if(o){if(l.length===0)return _(`bash: hash: -t: option requires an argument
266
- `,1);let h="",m=!1,E="";for(let S of l){let y=e.state.hashTable.get(S);y?l.length>1?h+=`${S} ${y}
267
- `:h+=`${y}
268
- `:(E+=`bash: hash: ${S}: not found
269
- `,m=!0)}return m?{exitCode:1,stdout:h,stderr:E}:Y(h)}if(i){if(l.length===0)return _(`bash: hash: usage: hash [-lr] [-p pathname] [-dt] [name ...]
261
+ `,s||e.state.env.set(r,"?")),e.state.env.set("OPTIND",String(l+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"),{exitCode:s?2:0,stdout:"",stderr:m}}e.state.env.set("OPTARG",a[l]),e.state.env.set("OPTIND",String(l+2)),e.state.env.set("__GETOPTS_CHARINDEX","0")}else f+1<c.length?(e.state.env.set("__GETOPTS_CHARINDEX",String(f+1)),e.state.env.set("OPTIND",String(l))):(e.state.env.set("OPTIND",String(l+1)),e.state.env.set("__GETOPTS_CHARINDEX","0"));return s||e.state.env.set(r,d),{exitCode:s?2:0,stdout:"",stderr:""}}async function Lo(e,t){e.state.hashTable||(e.state.hashTable=new Map);let n=!1,r=!1,s=!1,i=!1,o=!1,a="",l=[],u=0;for(;u<t.length;){let h=t[u];if(h==="--"){u++,l.push(...t.slice(u));break}if(h==="-r")n=!0,u++;else if(h==="-d")r=!0,u++;else if(h==="-l")s=!0,u++;else if(h==="-t")o=!0,u++;else if(h==="-p"){if(i=!0,u++,u>=t.length)return L(`bash: hash: -p: option requires an argument
262
+ `,1);a=t[u],u++}else if(h.startsWith("-")&&h.length>1){for(let m of h.slice(1))if(m==="r")n=!0;else if(m==="d")r=!0;else if(m==="l")s=!0;else if(m==="t")o=!0;else return m==="p"?L(`bash: hash: -p: option requires an argument
263
+ `,1):L(`bash: hash: -${m}: invalid option
264
+ `,1);u++}else l.push(h),u++}if(n)return e.state.hashTable.clear(),J;if(r){if(l.length===0)return L(`bash: hash: -d: option requires an argument
265
+ `,1);let h=!1,m="";for(let y of l)e.state.hashTable.has(y)?e.state.hashTable.delete(y):(m+=`bash: hash: ${y}: not found
266
+ `,h=!0);return h?L(m,1):J}if(o){if(l.length===0)return L(`bash: hash: -t: option requires an argument
267
+ `,1);let h="",m=!1,y="";for(let b of l){let w=e.state.hashTable.get(b);w?l.length>1?h+=`${b} ${w}
268
+ `:h+=`${w}
269
+ `:(y+=`bash: hash: ${b}: not found
270
+ `,m=!0)}return m?{exitCode:1,stdout:h,stderr:y}:Y(h)}if(i){if(l.length===0)return L(`bash: hash: usage: hash [-lr] [-p pathname] [-dt] [name ...]
270
271
  `,1);let h=l[0];return e.state.hashTable.set(h,a),J}if(l.length===0){if(e.state.hashTable.size===0)return Y(`hash: hash table empty
271
- `);let h="";if(s)for(let[m,E]of e.state.hashTable){let S=m.startsWith("-")?" --":"";h+=`builtin hash -p ${Ee(E)}${S} ${Ee(m)}
272
+ `);let h="";if(s)for(let[m,y]of e.state.hashTable){let b=m.startsWith("-")?" --":"";h+=`builtin hash -p ${we(y)}${b} ${we(m)}
272
273
  `}else{h=`hits command
273
274
  `;for(let[,m]of e.state.hashTable)h+=` 1 ${m}
274
275
  `}return Y(h)}let c=!1,f="",p=(e.state.env.get("PATH")||"/usr/bin:/bin").split(":");for(let h of l){if(h.includes("/")){f+=`bash: hash: ${h}: cannot use / in name
275
- `,c=!0;continue}let m=!1;for(let E of p){if(!E)continue;let S=`${E}/${h}`;if(await e.fs.exists(S)){e.state.hashTable.set(h,S),m=!0;break}}m||(f+=`bash: hash: ${h}: not found
276
- `,c=!0)}return c?_(f,1):J}var _c=new Map([[":",[": [arguments]",`Null command.
276
+ `,c=!0;continue}let m=!1;for(let y of p){if(!y)continue;let b=`${y}/${h}`;if(await e.fs.exists(b)){e.state.hashTable.set(h,b),m=!0;break}}m||(f+=`bash: hash: ${h}: not found
277
+ `,c=!0)}return c?L(f,1):J}var Mc=new Map([[":",[": [arguments]",`Null command.
277
278
  No effect; the command does nothing.
278
279
  Exit Status:
279
280
  Always succeeds.`]],[".",[". filename [arguments]",`Execute commands from a file in the current shell.
@@ -618,37 +619,37 @@ eval: usage: eval [arg ...]
618
619
  job specification, and reports its termination status.
619
620
  Exit Status:
620
621
  Returns the status of the last ID; fails if ID is invalid or an invalid
621
- option is given.`]]]),Lc=[..._c.keys()].sort();function Oo(e,t){let n=!1,r=[],s=0;for(;s<t.length;){let l=t[s];if(l==="--"){for(s++;s<t.length;)r.push(t[s]),s++;break}if(l.startsWith("-")&&l.length>1){for(let u=1;u<l.length;u++){let c=l[u];if(c==="s")n=!0;else return _(`bash: help: -${c}: invalid option
622
- `,2)}s++}else r.push(l),s++}if(r.length===0)return Lh();let i="",o=!1,a="";for(let l of r){let u=_h(l);if(u.length===0){a+=`bash: help: no help topics match \`${l}'. Try \`help help' or \`man -k ${l}' or \`info ${l}'.
623
- `,o=!0;continue}for(let c of u){let f=_c.get(c);if(!f)continue;let[d,p]=f;n?i+=`${c}: ${d}
622
+ option is given.`]]]),Bc=[...Mc.keys()].sort();function To(e,t){let n=!1,r=[],s=0;for(;s<t.length;){let l=t[s];if(l==="--"){for(s++;s<t.length;)r.push(t[s]),s++;break}if(l.startsWith("-")&&l.length>1){for(let u=1;u<l.length;u++){let c=l[u];if(c==="s")n=!0;else return L(`bash: help: -${c}: invalid option
623
+ `,2)}s++}else r.push(l),s++}if(r.length===0)return zh();let i="",o=!1,a="";for(let l of r){let u=Vh(l);if(u.length===0){a+=`bash: help: no help topics match \`${l}'. Try \`help help' or \`man -k ${l}' or \`info ${l}'.
624
+ `,o=!0;continue}for(let c of u){let f=Mc.get(c);if(!f)continue;let[d,p]=f;n?i+=`${c}: ${d}
624
625
  `:i+=`${c}: ${d}
625
626
  ${p}
626
- `}}return{exitCode:o?1:0,stdout:i,stderr:a}}function _h(e){let t=e.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*").replace(/\?/g,"."),n=me(`^${t}$`);return Lc.filter(r=>n.test(r))}function Lh(){let e=[];e.push("just-bash shell builtins"),e.push("These shell commands are defined internally. Type `help' to see this list."),e.push("Type `help name' to find out more about the function `name'."),e.push("");let t=36,n=Lc.slice(),r=Math.ceil(n.length/2);for(let s=0;s<r;s++){let i=n[s]||"",o=n[s+r]||"",a=i.padEnd(t);e.push(o?`${a}${o}`:i)}return Y(`${e.join(`
627
+ `}}return{exitCode:o?1:0,stdout:i,stderr:a}}function Vh(e){let t=e.replace(/[.+^${}()|[\]\\]/g,"\\$&").replace(/\*/g,".*").replace(/\?/g,"."),n=me(`^${t}$`);return Bc.filter(r=>n.test(r))}function zh(){let e=[];e.push("just-bash shell builtins"),e.push("These shell commands are defined internally. Type `help' to see this list."),e.push("Type `help name' to find out more about the function `name'."),e.push("");let t=36,n=Bc.slice(),r=Math.ceil(n.length/2);for(let s=0;s<r;s++){let i=n[s]||"",o=n[s+r]||"",a=i.padEnd(t);e.push(o?`${a}${o}`:i)}return Y(`${e.join(`
627
628
  `)}
628
- `)}function Th(e){let t=[],n="",r=0;for(let s of e){for(let i of s)i==="("?r++:i===")"&&r--;n?n+=` ${s}`:n=s,r===0&&(t.push(n),n="")}return n&&t.push(n),t}async function _o(e,t){if(t.length===0)return _(`bash: let: expression expected
629
- `);let n=Th(t),r=0;for(let s of n)try{let o=dt(`(( ${s} ))`).statements[0];if(o&&o.pipelines.length>0&&o.pipelines[0].commands.length>0){let a=o.pipelines[0].commands[0];a.type==="ArithmeticCommand"&&(r=await X(e,a.expression.expression))}}catch(i){return _(`bash: let: ${s}: ${i.message}
630
- `)}return L("","",r===0?1:0)}async function Lo(e,t){let n={maxElements:e.limits.maxArrayElements,maxStringBytes:e.limits.maxStringLength};if(e.state.localScopes.length===0)return _(`bash: local: can only be used in a function
631
- `);let r=e.state.localScopes[e.state.localScopes.length-1];for(e.state.localArrayScopes??=[];e.state.localArrayScopes.length<e.state.localScopes.length;)e.state.localArrayScopes.push(new Map);let s=e.state.localArrayScopes.at(-1),i=d=>{if(r.has(d)||r.set(d,e.state.env.get(d)),s&&!s.has(d)){let p=ve(e,d);s.set(d,p?Le(p):void 0)}},o="",a=0,l=!1,u=!1,c=!1,f=[];for(let d of t)if(d==="-n")l=!0;else if(d==="-a")u=!0;else if(d==="-p")c=!0;else if(d.startsWith("-")&&!d.includes("="))for(let p of d.slice(1))p==="n"?l=!0:p==="a"?u=!0:p==="p"&&(c=!0);else f.push(d);if(f.length===0){let d="",p=Array.from(r.keys()).sort();for(let h of p){let m=e.state.env.get(h);m!==void 0&&(d+=`${h}=${m}
632
- `)}return L(d,"",0)}for(let d of f){let p,h,m=d.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(m){p=m[1];let b=m[2];if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(p)){o+=`bash: local: \`${d}': not a valid identifier
633
- `,a=1;continue}ue(e,p,"bash");let v=Ot(b,n);e.executionScope.consumeWork(v.length,"local array assignment"),i(p),ye(e,p),Vt(e,p,"indexed");for(let x=0;x<v.length;x++)U(e,p,x,v[x]);en(e,p),l&&It(e,p);continue}let E=d.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(E){p=E[1];let b=E[2];ue(e,p,"bash"),i(p);let v=Ot(b,n);e.executionScope.consumeWork(v.length,"local array append");let x=be(e,p),A=0,k=e.state.env.get(p);x.length===0&&k!==void 0?(U(e,p,0,k),e.state.env.delete(p),A=1):x.length>0&&(A=Math.max(...x)+1),dn(e,p,Array.from({length:v.length},(N,$)=>A+$));for(let N=0;N<v.length;N++)U(e,p,A+N,v[N]);en(e,p),l&&It(e,p);continue}let S=d.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(S){p=S[1];let b=S[2];ue(e,p,"bash"),r.has(p)||r.set(p,e.state.env.get(p));let v=e.state.env.get(p)??"";e.state.env.set(p,Ft([v,b],"",e.limits.maxStringLength,"local append")),en(e,p),l&&It(e,p);continue}let y=d.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([^\]]+)\]=(.*)$/s);if(y){p=y[1];let b=y[2],v=y[3];ue(e,p,"bash"),i(p);let x;try{let A=new j,k=te(A,b);x=await X(e,k.expression)}catch{let A=parseInt(b,10);x=Number.isNaN(A)?0:A}U(e,p,x,v),en(e,p),l&&It(e,p);continue}if(d.includes("=")){let b=d.indexOf("=");p=d.slice(0,b),h=d.slice(b+1)}else p=d;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(p)){o+=`bash: local: \`${d}': not a valid identifier
634
- `,a=1;continue}let g=r.has(p);if(h!==void 0){let b=e.state.env.get(p);if(e.state.tempEnvBindings){let v=e.state.accessedTempEnvVars?.has(p),x=e.state.mutatedTempEnvVars?.has(p);if(!v&&!x)for(let A=e.state.tempEnvBindings.length-1;A>=0;A--){let k=e.state.tempEnvBindings[A];if(k.has(p)){b=k.get(p);break}}}cc(e,p,b)}if(!g){let b=e.state.env.get(p);if(e.state.tempEnvBindings)for(let v=e.state.tempEnvBindings.length-1;v>=0;v--){let x=e.state.tempEnvBindings[v];if(x.has(p)){b=x.get(p);break}}r.set(p,b),u&&i(p)}if(u&&h===void 0)ye(e,p),Vt(e,p,"indexed");else if(h!==void 0){if(ue(e,p,"bash"),l&&h!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(h)){o+=`bash: local: \`${h}': invalid variable name for name reference
635
- `,a=1;continue}e.state.env.set(p,h),e.state.options.allexport&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(p))}else{let b=e.state.tempEnvBindings?.some(v=>v.has(p));!g&&!b&&e.state.env.delete(p)}en(e,p),l&&It(e,p)}return L("",o,a)}function To(e,t,n){let r=`
636
- `,s=0,i=0,o=0,a=!1,l="MAPFILE",u=0;for(;u<t.length;){let y=t[u];y==="-d"&&u+1<t.length?(r=t[u+1]===""?"\0":t[u+1]||`
637
- `,u+=2):y==="-n"&&u+1<t.length?(s=Number.parseInt(t[u+1],10)||0,u+=2):y==="-O"&&u+1<t.length?(i=Number.parseInt(t[u+1],10)||0,u+=2):y==="-s"&&u+1<t.length?(o=Number.parseInt(t[u+1],10)||0,u+=2):y==="-t"?(a=!0,u++):y==="-u"||y==="-C"||y==="-c"?u+=2:(y.startsWith("-")||(l=y),u++)}if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(l))return L("",`mapfile: ${l}: not a valid identifier
638
- `,1);if(!Number.isSafeInteger(i)||i<0)return L("",`mapfile: invalid array origin
639
- `,1);ue(e,l,"mapfile");let c=n;!c&&e.state.groupStdin!==void 0&&(c=e.state.groupStdin);let f=[],d=0,p=0,h=0,m=e.limits.maxArrayElements,E=y=>{if(F(y)>e.limits.maxStringLength)throw new P(`mapfile: string length limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");f.push(y)};for(;d<c.length;){e.executionScope.consumeWork(1,"mapfile input");let y=c.indexOf(r,d);if(y===-1){if(d<c.length){if(h<o)h++;else if(s===0||p<s){let v=c.slice(d),x=v.indexOf("\0");if(x!==-1&&(v=v.substring(0,x)),f.length>=m)return L("",`mapfile: array element limit exceeded (${m})
640
- `,1);E(v),p++}}break}let g=c.slice(d,y),b=g.indexOf("\0");if(b!==-1&&(g=g.substring(0,b)),!a&&r!=="\0"&&(g+=r),d=y+r.length,h<o){h++;continue}if(s>0&&p>=s)break;if(f.length>=m)return L("",`mapfile: array element limit exceeded (${m})
641
- `,1);E(g),p++}let S=new Set(i===0?[]:e.state.arrays?.get(l)?.elements.keys()??[]);for(let y=0;y<f.length;y++)if(S.add(String(i+y)),S.size>m)return L("",`mapfile: array element limit exceeded (${m})
642
- `,1);i===0&&ye(e,l);for(let y=0;y<f.length;y++)U(e,l,i+y,f[y]);return e.state.groupStdin!==void 0&&!n&&(e.state.groupStdin=""),{...L("","",0),internalStdinConsumed:c.length}}function Fo(e,t,n,r=-1){let s=!1,i=`
643
- `,o="",a=-1,l=-1,u=null,c=-1,f=-1,d=[],p=0,h=!1,m=(I,O)=>{let M=1;for(;M<I.length;){let ee=I[M];if(ee==="r")s=!0,M++;else if(ee==="s")M++;else{if(ee==="d")return M+1<I.length?(i=I.substring(M+1),{nextArgIndex:O+1}):O+1<t.length?(i=t[O+1],{nextArgIndex:O+2}):{nextArgIndex:O+1};if(ee==="n"){if(M+1<I.length){let K=I.substring(M+1);return a=Number.parseInt(K,10),(Number.isNaN(a)||a<0)&&(h=!0,a=0),{nextArgIndex:O+1}}else if(O+1<t.length)return a=Number.parseInt(t[O+1],10),(Number.isNaN(a)||a<0)&&(h=!0,a=0),{nextArgIndex:O+2};return{nextArgIndex:O+1}}else if(ee==="N"){if(M+1<I.length){let K=I.substring(M+1);return l=Number.parseInt(K,10),(Number.isNaN(l)||l<0)&&(h=!0,l=0),{nextArgIndex:O+1}}else if(O+1<t.length)return l=Number.parseInt(t[O+1],10),(Number.isNaN(l)||l<0)&&(h=!0,l=0),{nextArgIndex:O+2};return{nextArgIndex:O+1}}else{if(ee==="a")return M+1<I.length?(u=I.substring(M+1),{nextArgIndex:O+1}):O+1<t.length?(u=t[O+1],{nextArgIndex:O+2}):{nextArgIndex:O+1};if(ee==="p")return M+1<I.length?(o=I.substring(M+1),{nextArgIndex:O+1}):O+1<t.length?(o=t[O+1],{nextArgIndex:O+2}):{nextArgIndex:O+1};if(ee==="u"){if(M+1<I.length){let K=I.substring(M+1);return c=Number.parseInt(K,10),Number.isNaN(c)||c<0?{nextArgIndex:-2}:{nextArgIndex:O+1}}else if(O+1<t.length)return c=Number.parseInt(t[O+1],10),Number.isNaN(c)||c<0?{nextArgIndex:-2}:{nextArgIndex:O+2};return{nextArgIndex:O+1}}else if(ee==="t"){if(M+1<I.length){let K=I.substring(M+1);return f=Number.parseFloat(K),Number.isNaN(f)&&(f=0),{nextArgIndex:O+1}}else if(O+1<t.length)return f=Number.parseFloat(t[O+1]),Number.isNaN(f)&&(f=0),{nextArgIndex:O+2};return{nextArgIndex:O+1}}else if(ee==="e"||ee==="i"||ee==="P"){if(ee==="i"&&O+1<t.length)return{nextArgIndex:O+2};M++}else M++}}}return{nextArgIndex:O+1}};for(;p<t.length;){let I=t[p];if(I.startsWith("-")&&I.length>1&&I!=="--"){let O=m(I,p);if(O.nextArgIndex===-1)return{stdout:"",stderr:"",exitCode:2};if(O.nextArgIndex===-2)return{stdout:"",stderr:"",exitCode:1};p=O.nextArgIndex}else if(I==="--")for(p++;p<t.length;)d.push(t[p]),p++;else d.push(I),p++}if(h)return L("","",1);d.length===0&&u===null&&d.push("REPLY");let E=new Set;u&&E.add(u);for(let I of d)E.add(I);l>=0&&d.length===0&&E.add("REPLY");for(let I of E){if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(I))return L("",`bash: read: \`${I}': not a valid identifier
644
- `,1);ue(e,I,"bash")}if(f===0){if(u)ye(e,u);else{for(let I of d)e.state.env.set(I,"");d.length===0&&e.state.env.set("REPLY","")}return L("","",0)}if(f<0&&f!==-1)return L("","",1);let S=n,y=Je(e,c),g=c>0&&!(y?.kind==="dup-in"&&y.sourceFd===0);if(g){let I=As(e,c);if("error"in I){let M=I.error==="write-only"||c===1||c===2?`bash: read: read error: ${c}: Bad file descriptor
629
+ `)}function qh(e){let t=[],n="",r=0;for(let s of e){for(let i of s)i==="("?r++:i===")"&&r--;n?n+=` ${s}`:n=s,r===0&&(t.push(n),n="")}return n&&t.push(n),t}async function Fo(e,t){if(t.length===0)return L(`bash: let: expression expected
630
+ `);let n=qh(t),r=0;for(let s of n)try{let o=ft(`(( ${s} ))`).statements[0];if(o&&o.pipelines.length>0&&o.pipelines[0].commands.length>0){let a=o.pipelines[0].commands[0];a.type==="ArithmeticCommand"&&(r=await X(e,a.expression.expression))}}catch(i){return L(`bash: let: ${s}: ${i.message}
631
+ `)}return T("","",r===0?1:0)}async function Mo(e,t){let n={maxElements:e.limits.maxArrayElements,maxStringBytes:e.limits.maxStringLength};if(e.state.localScopes.length===0)return L(`bash: local: can only be used in a function
632
+ `);let r=e.state.localScopes[e.state.localScopes.length-1];for(e.state.localArrayScopes??=[];e.state.localArrayScopes.length<e.state.localScopes.length;)e.state.localArrayScopes.push(new Map);let s=e.state.localArrayScopes.at(-1),i=d=>{if(r.has(d)||r.set(d,e.state.env.get(d)),s&&!s.has(d)){let p=Ae(e,d);s.set(d,p?Le(p):void 0)}},o="",a=0,l=!1,u=!1,c=!1,f=[];for(let d of t)if(d==="-n")l=!0;else if(d==="-a")u=!0;else if(d==="-p")c=!0;else if(d.startsWith("-")&&!d.includes("="))for(let p of d.slice(1))p==="n"?l=!0:p==="a"?u=!0:p==="p"&&(c=!0);else f.push(d);if(f.length===0){let d="",p=Array.from(r.keys()).sort();for(let h of p){let m=e.state.env.get(h);m!==void 0&&(d+=`${h}=${m}
633
+ `)}return T(d,"",0)}for(let d of f){let p,h,m=d.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\((.*)\)$/s);if(m){p=m[1];let S=m[2];if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(p)){o+=`bash: local: \`${d}': not a valid identifier
634
+ `,a=1;continue}ue(e,p,"bash");let v=Ot(S,n);e.executionScope.consumeWork(v.length,"local array assignment"),i(p),ye(e,p),Vt(e,p,"indexed");for(let A=0;A<v.length;A++)j(e,p,A,v[A]);en(e,p),l&&It(e,p);continue}let y=d.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=\((.*)\)$/s);if(y){p=y[1];let S=y[2];ue(e,p,"bash"),i(p);let v=Ot(S,n);e.executionScope.consumeWork(v.length,"local array append");let A=Ee(e,p),x=0,$=e.state.env.get(p);A.length===0&&$!==void 0?(j(e,p,0,$),e.state.env.delete(p),x=1):A.length>0&&(x=Math.max(...A)+1),dn(e,p,Array.from({length:v.length},(I,P)=>x+P));for(let I=0;I<v.length;I++)j(e,p,x+I,v[I]);en(e,p),l&&It(e,p);continue}let b=d.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\+=(.*)$/);if(b){p=b[1];let S=b[2];ue(e,p,"bash"),r.has(p)||r.set(p,e.state.env.get(p));let v=e.state.env.get(p)??"";e.state.env.set(p,Ft([v,S],"",e.limits.maxStringLength,"local append")),en(e,p),l&&It(e,p);continue}let w=d.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[([^\]]+)\]=(.*)$/s);if(w){p=w[1];let S=w[2],v=w[3];ue(e,p,"bash"),i(p);let A;try{let x=new G,$=te(x,S);A=await X(e,$.expression)}catch{let x=parseInt(S,10);A=Number.isNaN(x)?0:x}j(e,p,A,v),en(e,p),l&&It(e,p);continue}if(d.includes("=")){let S=d.indexOf("=");p=d.slice(0,S),h=d.slice(S+1)}else p=d;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(p)){o+=`bash: local: \`${d}': not a valid identifier
635
+ `,a=1;continue}let E=r.has(p);if(h!==void 0){let S=e.state.env.get(p);if(e.state.tempEnvBindings){let v=e.state.accessedTempEnvVars?.has(p),A=e.state.mutatedTempEnvVars?.has(p);if(!v&&!A)for(let x=e.state.tempEnvBindings.length-1;x>=0;x--){let $=e.state.tempEnvBindings[x];if($.has(p)){S=$.get(p);break}}}hc(e,p,S)}if(!E){let S=e.state.env.get(p);if(e.state.tempEnvBindings)for(let v=e.state.tempEnvBindings.length-1;v>=0;v--){let A=e.state.tempEnvBindings[v];if(A.has(p)){S=A.get(p);break}}r.set(p,S),u&&i(p)}if(u&&h===void 0)ye(e,p),Vt(e,p,"indexed");else if(h!==void 0){if(ue(e,p,"bash"),l&&h!==""&&!/^[a-zA-Z_][a-zA-Z0-9_]*(\[.+\])?$/.test(h)){o+=`bash: local: \`${h}': invalid variable name for name reference
636
+ `,a=1;continue}e.state.env.set(p,h),e.state.options.allexport&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(p))}else{let S=e.state.tempEnvBindings?.some(v=>v.has(p));!E&&!S&&e.state.env.delete(p)}en(e,p),l&&It(e,p)}return T("",o,a)}function Bo(e,t,n){let r=`
637
+ `,s=0,i=0,o=0,a=!1,l="MAPFILE",u=0;for(;u<t.length;){let w=t[u];w==="-d"&&u+1<t.length?(r=t[u+1]===""?"\0":t[u+1]||`
638
+ `,u+=2):w==="-n"&&u+1<t.length?(s=Number.parseInt(t[u+1],10)||0,u+=2):w==="-O"&&u+1<t.length?(i=Number.parseInt(t[u+1],10)||0,u+=2):w==="-s"&&u+1<t.length?(o=Number.parseInt(t[u+1],10)||0,u+=2):w==="-t"?(a=!0,u++):w==="-u"||w==="-C"||w==="-c"?u+=2:(w.startsWith("-")||(l=w),u++)}if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(l))return T("",`mapfile: ${l}: not a valid identifier
639
+ `,1);if(!Number.isSafeInteger(i)||i<0)return T("",`mapfile: invalid array origin
640
+ `,1);ue(e,l,"mapfile");let c=n;!c&&e.state.groupStdin!==void 0&&(c=e.state.groupStdin);let f=[],d=0,p=0,h=0,m=e.limits.maxArrayElements,y=w=>{if(W(w)>e.limits.maxStringLength)throw new C(`mapfile: string length limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");f.push(w)};for(;d<c.length;){e.executionScope.consumeWork(1,"mapfile input");let w=c.indexOf(r,d);if(w===-1){if(d<c.length){if(h<o)h++;else if(s===0||p<s){let v=c.slice(d),A=v.indexOf("\0");if(A!==-1&&(v=v.substring(0,A)),f.length>=m)return T("",`mapfile: array element limit exceeded (${m})
641
+ `,1);y(v),p++}}break}let E=c.slice(d,w),S=E.indexOf("\0");if(S!==-1&&(E=E.substring(0,S)),!a&&r!=="\0"&&(E+=r),d=w+r.length,h<o){h++;continue}if(s>0&&p>=s)break;if(f.length>=m)return T("",`mapfile: array element limit exceeded (${m})
642
+ `,1);y(E),p++}let b=new Set(i===0?[]:e.state.arrays?.get(l)?.elements.keys()??[]);for(let w=0;w<f.length;w++)if(b.add(String(i+w)),b.size>m)return T("",`mapfile: array element limit exceeded (${m})
643
+ `,1);i===0&&ye(e,l);for(let w=0;w<f.length;w++)j(e,l,i+w,f[w]);return e.state.groupStdin!==void 0&&!n&&(e.state.groupStdin=""),{...T("","",0),internalStdinConsumed:c.length}}function Wo(e,t,n,r=-1){let s=!1,i=`
644
+ `,o="",a=-1,l=-1,u=null,c=-1,f=-1,d=[],p=0,h=!1,m=(O,_)=>{let V=1;for(;V<O.length;){let ee=O[V];if(ee==="r")s=!0,V++;else if(ee==="s")V++;else{if(ee==="d")return V+1<O.length?(i=O.substring(V+1),{nextArgIndex:_+1}):_+1<t.length?(i=t[_+1],{nextArgIndex:_+2}):{nextArgIndex:_+1};if(ee==="n"){if(V+1<O.length){let K=O.substring(V+1);return a=Number.parseInt(K,10),(Number.isNaN(a)||a<0)&&(h=!0,a=0),{nextArgIndex:_+1}}else if(_+1<t.length)return a=Number.parseInt(t[_+1],10),(Number.isNaN(a)||a<0)&&(h=!0,a=0),{nextArgIndex:_+2};return{nextArgIndex:_+1}}else if(ee==="N"){if(V+1<O.length){let K=O.substring(V+1);return l=Number.parseInt(K,10),(Number.isNaN(l)||l<0)&&(h=!0,l=0),{nextArgIndex:_+1}}else if(_+1<t.length)return l=Number.parseInt(t[_+1],10),(Number.isNaN(l)||l<0)&&(h=!0,l=0),{nextArgIndex:_+2};return{nextArgIndex:_+1}}else{if(ee==="a")return V+1<O.length?(u=O.substring(V+1),{nextArgIndex:_+1}):_+1<t.length?(u=t[_+1],{nextArgIndex:_+2}):{nextArgIndex:_+1};if(ee==="p")return V+1<O.length?(o=O.substring(V+1),{nextArgIndex:_+1}):_+1<t.length?(o=t[_+1],{nextArgIndex:_+2}):{nextArgIndex:_+1};if(ee==="u"){if(V+1<O.length){let K=O.substring(V+1);return c=Number.parseInt(K,10),Number.isNaN(c)||c<0?{nextArgIndex:-2}:{nextArgIndex:_+1}}else if(_+1<t.length)return c=Number.parseInt(t[_+1],10),Number.isNaN(c)||c<0?{nextArgIndex:-2}:{nextArgIndex:_+2};return{nextArgIndex:_+1}}else if(ee==="t"){if(V+1<O.length){let K=O.substring(V+1);return f=Number.parseFloat(K),Number.isNaN(f)&&(f=0),{nextArgIndex:_+1}}else if(_+1<t.length)return f=Number.parseFloat(t[_+1]),Number.isNaN(f)&&(f=0),{nextArgIndex:_+2};return{nextArgIndex:_+1}}else if(ee==="e"||ee==="i"||ee==="P"){if(ee==="i"&&_+1<t.length)return{nextArgIndex:_+2};V++}else V++}}}return{nextArgIndex:_+1}};for(;p<t.length;){let O=t[p];if(O.startsWith("-")&&O.length>1&&O!=="--"){let _=m(O,p);if(_.nextArgIndex===-1)return{stdout:"",stderr:"",exitCode:2};if(_.nextArgIndex===-2)return{stdout:"",stderr:"",exitCode:1};p=_.nextArgIndex}else if(O==="--")for(p++;p<t.length;)d.push(t[p]),p++;else d.push(O),p++}if(h)return T("","",1);d.length===0&&u===null&&d.push("REPLY");let y=new Set;u&&y.add(u);for(let O of d)y.add(O);l>=0&&d.length===0&&y.add("REPLY");for(let O of y){if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(O))return T("",`bash: read: \`${O}': not a valid identifier
645
+ `,1);ue(e,O,"bash")}if(f===0){if(u)ye(e,u);else{for(let O of d)e.state.env.set(O,"");d.length===0&&e.state.env.set("REPLY","")}return T("","",0)}if(f<0&&f!==-1)return T("","",1);let b=n,w=st(e,c),E=c>0&&!(w?.kind==="dup-in"&&w.sourceFd===0);if(E){let O=ks(e,c);if("error"in O){let V=O.error==="write-only"||c===1||c===2?`bash: read: read error: ${c}: Bad file descriptor
645
646
  `:`bash: read: ${c}: invalid file descriptor: Bad file descriptor
646
- `;return L("",M,1)}S=I.content}else!S&&e.state.groupStdin!==void 0&&(S=e.state.groupStdin);let b=i===""?"\0":i,v="",x=0,A=I=>{let O=F(I);if(O>e.limits.maxStringLength-x)throw new P(`read: string length limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");v+=I,x+=O},k=I=>{if(F(I)>e.limits.maxStringLength)throw new P(`read: string length limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length")},N=0,$=!0,C=I=>{g?nn(e,c,I):r>=0?nn(e,r,I):e.state.groupStdin!==void 0&&!n&&(e.state.groupStdin=S.substring(I),e.state.groupStdinSourceFd!==void 0&&nn(e,e.state.groupStdinSourceFd,I))};if(l>=0){let I=Math.min(l,S.length);v=S.substring(0,I),k(v),N=I,$=I>=l,C(N);let O=d[0]||"REPLY";e.state.env.set(O,v);for(let M=1;M<d.length;M++)e.state.env.set(d[M],"");return L("","",$?0:1)}else if(a>=0){let I=0,O=0,M=!1;for(;O<S.length&&I<a;){let ee=S[O];if(ee===b){N=O+1,M=!0;break}if(!s&&ee==="\\"&&O+1<S.length){let K=S[O+1];if(K===b&&b===`
647
- `){O+=2,N=O;continue}if(K===b){O+=2,I++,A(K),N=O;continue}A(K),O+=2,I++,N=O}else A(ee),O++,I++,N=O}$=I>=a||M,C(N)}else{N=0;let I=0;for(;I<S.length;){let O=S[I];if(O===b){N=I+b.length,$=!0;break}if(!s&&O==="\\"&&I+1<S.length){let M=S[I+1];if(M===`
648
- `){I+=2;continue}if(M===b){A(M),I+=2;continue}A(O),A(M),I+=2;continue}A(O),I++}if(I>=S.length&&($=!1,N=I,v.length===0&&S.length===0)){for(let O of d)e.state.env.set(O,"");return u&&ye(e,u),L("","",1)}C(N)}b===`
647
+ `;return T("",V,1)}b=O.content}else!b&&e.state.groupStdin!==void 0&&(b=e.state.groupStdin);let S=i===""?"\0":i,v="",A=0,x=O=>{let _=W(O);if(_>e.limits.maxStringLength-A)throw new C(`read: string length limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length");v+=O,A+=_},$=O=>{if(W(O)>e.limits.maxStringLength)throw new C(`read: string length limit exceeded (${e.limits.maxStringLength} bytes)`,"string_length")},I=0,P=!0,N=O=>{E?nn(e,c,O):r>=0?nn(e,r,O):e.state.groupStdin!==void 0&&!n&&(e.state.groupStdin=b.substring(O),e.state.groupStdinSourceFd!==void 0&&nn(e,e.state.groupStdinSourceFd,O))};if(l>=0){let O=Math.min(l,b.length);v=b.substring(0,O),$(v),I=O,P=O>=l,N(I);let _=d[0]||"REPLY";e.state.env.set(_,v);for(let V=1;V<d.length;V++)e.state.env.set(d[V],"");return T("","",P?0:1)}else if(a>=0){let O=0,_=0,V=!1;for(;_<b.length&&O<a;){let ee=b[_];if(ee===S){I=_+1,V=!0;break}if(!s&&ee==="\\"&&_+1<b.length){let K=b[_+1];if(K===S&&S===`
648
+ `){_+=2,I=_;continue}if(K===S){_+=2,O++,x(K),I=_;continue}x(K),_+=2,O++,I=_}else x(ee),_++,O++,I=_}P=O>=a||V,N(I)}else{I=0;let O=0;for(;O<b.length;){let _=b[O];if(_===S){I=O+S.length,P=!0;break}if(!s&&_==="\\"&&O+1<b.length){let V=b[O+1];if(V===`
649
+ `){O+=2;continue}if(V===S){x(V),O+=2;continue}x(_),x(V),O+=2;continue}x(_),O++}if(O>=b.length&&(P=!1,I=O,v.length===0&&b.length===0)){for(let _ of d)e.state.env.set(_,"");return u&&ye(e,u),T("","",1)}N(I)}S===`
649
650
  `&&v.endsWith(`
650
- `)&&(v=v.slice(0,-1));let D=I=>s?I:I.replace(/\\(.)/g,"$1");if(d.length===1&&d[0]==="REPLY")return e.state.env.set("REPLY",D(v)),L("","",$?0:1);let B=Ae(e.state.env),H=e.limits.maxArrayElements;if(u){let{words:I}=xi(v,B,H,void 0,s);ye(e,u);for(let O=0;O<I.length;O++)U(e,u,O,D(I[O]));return L("","",$?0:1)}let R=d.length,{words:W,wordStarts:V}=xi(v,B,H,R,s);for(let I=0;I<d.length;I++){let O=d[I];if(I<d.length-1)e.state.env.set(O,D(W[I]??""));else if(I<V.length){let M=v.substring(V[I]);M=Rl(M,B,s),M=D(M),e.state.env.set(O,M)}else e.state.env.set(O,"")}return L("","",$?0:1)}function Mo(e,t){if(e.state.callDepth===0&&e.state.sourceDepth===0)return _("bash: return: can only `return' from a function or sourced script\n");let n=e.state.lastExitCode;if(t.length>0){let r=t[0],s=Number.parseInt(r,10);if(r===""||Number.isNaN(s)||!/^-?\d+$/.test(r))return _(`bash: return: ${r}: numeric argument required
651
- `,2);n=(s%256+256)%256}throw new Ie(n)}var wr=`set: usage: set [-eux] [+eux] [-o option] [+o option]
651
+ `)&&(v=v.slice(0,-1));let D=O=>s?O:O.replace(/\\(.)/g,"$1");if(d.length===1&&d[0]==="REPLY")return e.state.env.set("REPLY",D(v)),T("","",P?0:1);let R=Se(e.state.env),B=e.limits.maxArrayElements;if(u){let{words:O}=ki(v,R,B,void 0,s);ye(e,u);for(let _=0;_<O.length;_++)j(e,u,_,D(O[_]));return T("","",P?0:1)}let k=d.length,{words:M,wordStarts:z}=ki(v,R,B,k,s);for(let O=0;O<d.length;O++){let _=d[O];if(O<d.length-1)e.state.env.set(_,D(M[O]??""));else if(O<z.length){let V=v.substring(z[O]);V=_l(V,R,s),V=D(V),e.state.env.set(_,V)}else e.state.env.set(_,"")}return T("","",P?0:1)}function Vo(e,t){if(e.state.callDepth===0&&e.state.sourceDepth===0)return L("bash: return: can only `return' from a function or sourced script\n");let n=e.state.lastExitCode;if(t.length>0){let r=t[0],s=Number.parseInt(r,10);if(r===""||Number.isNaN(s)||!/^-?\d+$/.test(r))return L(`bash: return: ${r}: numeric argument required
652
+ `,2);n=(s%256+256)%256}throw new Ie(n)}var br=`set: usage: set [-eux] [+eux] [-o option] [+o option]
652
653
  Options:
653
654
  -e Exit immediately if a command exits with non-zero status
654
655
  +e Disable -e
@@ -664,96 +665,96 @@ Options:
664
665
  +o pipefail Disable pipefail
665
666
  -o xtrace Same as -x
666
667
  +o xtrace Disable xtrace
667
- `,Tc=new Map([["e","errexit"],["u","nounset"],["x","xtrace"],["v","verbose"],["f","noglob"],["C","noclobber"],["a","allexport"],["n","noexec"],["h",null],["b",null],["m",null],["B",null],["H",null],["P",null],["T",null],["E",null],["p",null]]),Ns=new Map([["errexit","errexit"],["pipefail","pipefail"],["nounset","nounset"],["xtrace","xtrace"],["verbose","verbose"],["noclobber","noclobber"],["noglob","noglob"],["allexport","allexport"],["noexec","noexec"],["posix","posix"],["vi","vi"],["emacs","emacs"],["notify",null],["monitor",null],["braceexpand",null],["histexpand",null],["physical",null],["functrace",null],["errtrace",null],["privileged",null],["hashall",null],["ignoreeof",null],["interactive-comments",null],["keyword",null],["onecmd",null]]),Bc=["errexit","nounset","pipefail","verbose","xtrace","posix","allexport","noclobber","noglob","noexec","vi","emacs"],Wc=["braceexpand","errtrace","functrace","hashall","histexpand","history","ignoreeof","interactive-comments","keyword","monitor","nolog","notify","onecmd","physical","privileged"];function Bo(e,t,n){t!==null&&(n&&(t==="vi"?e.state.options.emacs=!1:t==="emacs"&&(e.state.options.vi=!1)),e.state.options[t]=n,On(e))}function Fh(e,t){return t+1<e.length&&!e[t+1].startsWith("-")&&!e[t+1].startsWith("+")}function Mh(e,t,n){let r=be(e,n);if(r.length===0){t.append(n).append("=()");return}t.append(n).append("=(");for(let s=0;s<r.length;s++){let i=r[s],o=ie(e,n,i)??"";s>0&&t.append(" "),t.append(`[${i}]=`),t.reserve(ks(o)),t.append(on(o))}t.append(")")}function Bh(e,t){if(/^[a-zA-Z0-9_]+$/.test(t)){e.append(t);return}e.reserve(ks(t)),e.append(on(t))}function Wh(e,t,n){let r=St(e,n);if(r.length===0){t.append(n).append("=()");return}t.append(n).append("=(");for(let s=0;s<r.length;s++){let i=r[s],o=ie(e,n,i)??"";s>0&&t.append(" "),t.append("["),Bh(t,i),t.append("]="),t.reserve(ks(o)),t.append(on(o))}t.append(" )")}function Vh(e){let t=new Set,n=e.state.associativeArrays??new Set;for(let[r,s]of e.state.arrays??[])s.kind==="indexed"&&!n.has(r)&&t.add(r);return t}function zh(e){return e.state.associativeArrays??new Set}function Fc(e){let t=Bc.map(r=>`${r.padEnd(16)}${e.state.options[r]?"on":"off"}`),n=Wc.map(r=>`${r.padEnd(16)}off`);return`${[...t,...n].sort().join(`
668
+ `,Wc=new Map([["e","errexit"],["u","nounset"],["x","xtrace"],["v","verbose"],["f","noglob"],["C","noclobber"],["a","allexport"],["n","noexec"],["h",null],["b",null],["m",null],["B",null],["H",null],["P",null],["T",null],["E",null],["p",null]]),Os=new Map([["errexit","errexit"],["pipefail","pipefail"],["nounset","nounset"],["xtrace","xtrace"],["verbose","verbose"],["noclobber","noclobber"],["noglob","noglob"],["allexport","allexport"],["noexec","noexec"],["posix","posix"],["vi","vi"],["emacs","emacs"],["notify",null],["monitor",null],["braceexpand",null],["histexpand",null],["physical",null],["functrace",null],["errtrace",null],["privileged",null],["hashall",null],["ignoreeof",null],["interactive-comments",null],["keyword",null],["onecmd",null]]),qc=["errexit","nounset","pipefail","verbose","xtrace","posix","allexport","noclobber","noglob","noexec","vi","emacs"],Uc=["braceexpand","errtrace","functrace","hashall","histexpand","history","ignoreeof","interactive-comments","keyword","monitor","nolog","notify","onecmd","physical","privileged"];function zo(e,t,n){t!==null&&(n&&(t==="vi"?e.state.options.emacs=!1:t==="emacs"&&(e.state.options.vi=!1)),e.state.options[t]=n,_n(e))}function Uh(e,t){return t+1<e.length&&!e[t+1].startsWith("-")&&!e[t+1].startsWith("+")}function jh(e,t,n){let r=Ee(e,n);if(r.length===0){t.append(n).append("=()");return}t.append(n).append("=(");for(let s=0;s<r.length;s++){let i=r[s],o=ie(e,n,i)??"";s>0&&t.append(" "),t.append(`[${i}]=`),t.reserve(Rs(o)),t.append(on(o))}t.append(")")}function Gh(e,t){if(/^[a-zA-Z0-9_]+$/.test(t)){e.append(t);return}e.reserve(Rs(t)),e.append(on(t))}function Hh(e,t,n){let r=St(e,n);if(r.length===0){t.append(n).append("=()");return}t.append(n).append("=(");for(let s=0;s<r.length;s++){let i=r[s],o=ie(e,n,i)??"";s>0&&t.append(" "),t.append("["),Gh(t,i),t.append("]="),t.reserve(Rs(o)),t.append(on(o))}t.append(" )")}function Zh(e){let t=new Set,n=e.state.associativeArrays??new Set;for(let[r,s]of e.state.arrays??[])s.kind==="indexed"&&!n.has(r)&&t.add(r);return t}function Qh(e){return e.state.associativeArrays??new Set}function Vc(e){let t=qc.map(r=>`${r.padEnd(16)}${e.state.options[r]?"on":"off"}`),n=Uc.map(r=>`${r.padEnd(16)}off`);return`${[...t,...n].sort().join(`
668
669
  `)}
669
- `}function Mc(e){let t=Bc.map(r=>`set ${e.state.options[r]?"-o":"+o"} ${r}`),n=Wc.map(r=>`set +o ${r}`);return`${[...t,...n].sort().join(`
670
+ `}function zc(e){let t=qc.map(r=>`set ${e.state.options[r]?"-o":"+o"} ${r}`),n=Uc.map(r=>`set +o ${r}`);return`${[...t,...n].sort().join(`
670
671
  `)}
671
- `}function Vo(e,t){if(t.includes("--help"))return Y(wr);if(t.length===0){let i=Vh(e),o=zh(e),a=[];for(let[c,f]of e.state.env)/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(c)&&(i.has(c)||o.has(c)||a.push([c,f]));let l=[...a.map(([c,f])=>({kind:"scalar",name:c,value:f})),...Array.from(i,c=>({kind:"indexed",name:c})),...Array.from(o,c=>({kind:"associative",name:c}))];l.sort((c,f)=>c.name<f.name?-1:c.name>f.name?1:0);let u=new $n(e.limits.maxOutputSize,"set");for(let c of l)e.executionScope.consumeWork(1,"set variable listing"),c.kind==="scalar"?(u.append(c.name).append("="),u.reserve(xc(c.value)),u.append(Ee(c.value))):c.kind==="indexed"?Mh(e,u,c.name):Wh(e,u,c.name),u.append(`
672
- `);return Y(u.build())}let n=[],r=()=>n.length>0?Y(n.join("")):J,s=0;for(;s<t.length;){let i=t[s];if((i==="-o"||i==="+o")&&Fh(t,s)){let o=t[s+1];if(!Ns.has(o)){let a=`bash: set: ${o}: invalid option name
673
- ${wr}`;if(e.state.options.posix)throw new tt(1,"",a);return _(a)}Bo(e,Ns.get(o)??null,i==="-o"),s+=2;continue}if(i==="-o"){n.push(Fc(e)),s++;continue}if(i==="+o"){n.push(Mc(e)),s++;continue}if(i.length>1&&(i[0]==="-"||i[0]==="+")&&i[1]!=="-"){let o=i[0]==="-",a=0;for(let l=1;l<i.length;l++){let u=i[l];if(u==="o"){let c=s+1+a;if(c<t.length&&!t[c].startsWith("-")&&!t[c].startsWith("+")){let d=t[c];if(!Ns.has(d)){let p=`bash: set: ${d}: invalid option name
674
- ${wr}`;if(e.state.options.posix)throw new tt(1,"",p);return _(p)}Bo(e,Ns.get(d)??null,o),a++;continue}n.push(o?Fc(e):Mc(e));continue}if(!Tc.has(u)){let c=`bash: set: ${i[0]}${u}: invalid option
675
- ${wr}`;if(e.state.options.posix)throw new tt(1,"",c);return _(c)}Bo(e,Tc.get(u)??null,o)}s+=1+a;continue}if(i==="--")return Wo(e,t.slice(s+1)),r();if(i==="-"){if(e.state.options.xtrace=!1,e.state.options.verbose=!1,On(e),s+1<t.length)return Wo(e,t.slice(s+1)),r();s++;continue}if(i==="+"){s++;continue}if(i.startsWith("-")||i.startsWith("+")){let o=`bash: set: ${i}: invalid option
676
- ${wr}`;if(e.state.options.posix)throw new tt(1,"",o);return _(o)}return Wo(e,t.slice(s)),r()}return r()}function Wo(e,t){let n=1;for(;e.state.env.has(String(n));)e.state.env.delete(String(n)),n++;for(let r=0;r<t.length;r++)e.state.env.set(String(r+1),t[r]);e.state.env.set("#",String(t.length)),e.state.env.set("@",t.join(" ")),e.state.env.set("*",t.join(" "))}function zo(e,t){let n=1;if(t.length>0){let o=Number.parseInt(t[0],10);if(Number.isNaN(o)||o<0){let a=`bash: shift: ${t[0]}: numeric argument required
677
- `;if(e.state.options.posix)throw new tt(1,"",a);return _(a)}n=o}let r=Number.parseInt(e.state.env.get("#")||"0",10);if(n>r){let o=`bash: shift: shift count out of range
678
- `;if(e.state.options.posix)throw new tt(1,"",o);return _(o)}if(n===0)return J;let s=[];for(let o=1;o<=r;o++)s.push(e.state.env.get(String(o))||"");let i=s.slice(n);for(let o=1;o<=r;o++)e.state.env.delete(String(o));for(let o=0;o<i.length;o++)e.state.env.set(String(o+1),i[o]);return e.state.env.set("#",String(i.length)),e.state.env.set("@",i.join(" ")),J}async function qo(e,t){let n=t;if(n.length>0&&n[0]==="--"&&(n=n.slice(1)),n.length===0)return L("",`bash: source: filename argument required
679
- `,2);let r=n[0],s=null,i=null;if(r.includes("/")){let u=e.fs.resolvePath(e.state.cwd,r);try{i=await e.fs.readFile(u),s=u}catch{}}else{let c=(e.state.env.get("PATH")||"").split(":").filter(f=>f);for(let f of c){let d=e.fs.resolvePath(e.state.cwd,`${f}/${r}`);try{if((await e.fs.stat(d)).isDirectory)continue;i=await e.fs.readFile(d),s=d;break}catch{}}if(i===null){let f=e.fs.resolvePath(e.state.cwd,r);try{i=await e.fs.readFile(f),s=f}catch{}}}if(i===null)return _(`bash: ${r}: No such file or directory
680
- `);let o=new Map;if(n.length>1){for(let c=1;c<=9;c++)o.set(String(c),e.state.env.get(String(c)));o.set("#",e.state.env.get("#")),o.set("@",e.state.env.get("@"));let u=n.slice(1);e.state.env.set("#",String(u.length)),e.state.env.set("@",u.join(" "));for(let c=0;c<u.length&&c<9;c++)e.state.env.set(String(c+1),u[c]);for(let c=u.length+1;c<=9;c++)e.state.env.delete(String(c))}let a=e.state.currentSource,l=()=>{if(e.state.sourceDepth--,e.state.currentSource=a,n.length>1)for(let[u,c]of o)c===void 0?e.state.env.delete(u):e.state.env.set(u,c)};if(e.state.sourceDepth++,e.state.sourceDepth>e.limits.maxSourceDepth)throw e.state.sourceDepth--,new P(`source: maximum nesting depth (${e.limits.maxSourceDepth}) exceeded, increase executionLimits.maxSourceDepth`,"recursion");e.state.currentSource=r;try{let u=dt(i),c=await e.executeScript(u);return l(),c}catch(u){if(l(),u instanceof q)throw u;if(u instanceof Ie)return L(u.stdout,u.stderr,u.exitCode);if(u.name==="ParseException")return _(`bash: ${r}: ${u.message}
681
- `);throw u}}function Vc(e){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e)}function qh(e){return e.startsWith("'")&&e.endsWith("'")||e.startsWith('"')&&e.endsWith('"')}async function zc(e,t){if(qh(t))return null;try{let n=new j,r=te(n,t);return await X(e,r.expression)}catch{let n=parseInt(t,10);return Number.isNaN(n)?0:n}}function qc(e,t){if(e.state.localVarStack?.has(t)){let r=ws(e,t);if(r){r.value===void 0?e.state.env.delete(t):e.state.env.set(t,r.value);let s=e.state.localVarStack?.get(t);if(!s||s.length===0)gs(e,t),e.state.localVarStack?.delete(t),e.state.fullyUnsetLocals=e.state.fullyUnsetLocals||new Map,e.state.fullyUnsetLocals.set(t,r.scopeIndex),Uo(e,t);else{let i=s[s.length-1];e.state.localVarDepth=e.state.localVarDepth||new Map,e.state.localVarDepth.set(t,i.scopeIndex+1)}return!0}return e.state.env.delete(t),gs(e,t),e.state.localVarStack?.delete(t),e.state.fullyUnsetLocals=e.state.fullyUnsetLocals||new Map,e.state.fullyUnsetLocals.set(t,0),!0}for(let r=e.state.localScopes.length-1;r>=0;r--){let s=e.state.localScopes[r];if(s.has(t)){let i=s.get(t);i===void 0?e.state.env.delete(t):e.state.env.set(t,i),s.delete(t);let o=!1;for(let a=r-1;a>=0;a--)if(e.state.localScopes[a].has(t)){e.state.localVarDepth&&e.state.localVarDepth.set(t,a+1),o=!0;break}return o||gs(e,t),!0}}return!1}function Uo(e,t){if(!e.state.tempEnvBindings||e.state.tempEnvBindings.length===0)return!1;for(let n=e.state.tempEnvBindings.length-1;n>=0;n--){let r=e.state.tempEnvBindings[n];if(r.has(t)){let s=r.get(t);return s===void 0?e.state.env.delete(t):e.state.env.set(t,s),r.delete(t),!0}}return!1}async function Uc(e,t){if(t.startsWith("'")&&t.endsWith("'"))return t.slice(1,-1);if(t.startsWith('"')&&t.endsWith('"')){let n=t.slice(1,-1),s=new j().parseWordFromString(n,!0,!1);return ne(e,s)}if(t.includes("$")){let r=new j().parseWordFromString(t,!1,!1);return ne(e,r)}return t}async function jo(e,t){let n="both",r="",s=0;for(let i of t){if(i==="-v"){n="variable";continue}if(i==="-f"){n="function";continue}if(n==="function"){e.state.functions.delete(i);continue}if(n==="variable"){let u=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(u){let d=u[1],p=u[2];if(Fe(e,d)){r+=`bash: unset: ${d}: cannot unset: readonly variable
682
- `,s=1;continue}if(p==="@"||p==="*"){tr(e,d),e.state.env.delete(d);continue}let h=e.state.associativeArrays?.has(d);if(h){let g=await Uc(e,p);pn(e,d,g);continue}let m=ht(e,d),E=e.state.declaredVars?.has(d);if((e.state.env.has(d)||E)&&!m&&!h){r+=`bash: unset: ${d}: not an array variable
683
- `,s=1;continue}let y=await zc(e,p);if(y===null&&m){r+=`bash: unset: ${p}: not a valid identifier
684
- `,s=1;continue}if(y===null)continue;if(y<0){let g=G(e,d),b=g.length,v=e.state.currentLine;if(b===0){r+=`bash: line ${v}: unset: [${y}]: bad array subscript
685
- `,s=1;continue}let x=b+y;if(x<0){r+=`bash: line ${v}: unset: [${y}]: bad array subscript
686
- `,s=1;continue}let A=g[x][0];pn(e,d,A);continue}pn(e,d,y);continue}if(!Vc(i)){r+=`bash: unset: \`${i}': not a valid identifier
672
+ `}function Uo(e,t){if(t.includes("--help"))return Y(br);if(t.length===0){let i=Zh(e),o=Qh(e),a=[];for(let[c,f]of e.state.env)/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(c)&&(i.has(c)||o.has(c)||a.push([c,f]));let l=[...a.map(([c,f])=>({kind:"scalar",name:c,value:f})),...Array.from(i,c=>({kind:"indexed",name:c})),...Array.from(o,c=>({kind:"associative",name:c}))];l.sort((c,f)=>c.name<f.name?-1:c.name>f.name?1:0);let u=new kn(e.limits.maxOutputSize,"set");for(let c of l)e.executionScope.consumeWork(1,"set variable listing"),c.kind==="scalar"?(u.append(c.name).append("="),u.reserve(Cc(c.value)),u.append(we(c.value))):c.kind==="indexed"?jh(e,u,c.name):Hh(e,u,c.name),u.append(`
673
+ `);return Y(u.build())}let n=[],r=()=>n.length>0?Y(n.join("")):J,s=0;for(;s<t.length;){let i=t[s];if((i==="-o"||i==="+o")&&Uh(t,s)){let o=t[s+1];if(!Os.has(o)){let a=`bash: set: ${o}: invalid option name
674
+ ${br}`;if(e.state.options.posix)throw new et(1,"",a);return L(a)}zo(e,Os.get(o)??null,i==="-o"),s+=2;continue}if(i==="-o"){n.push(Vc(e)),s++;continue}if(i==="+o"){n.push(zc(e)),s++;continue}if(i.length>1&&(i[0]==="-"||i[0]==="+")&&i[1]!=="-"){let o=i[0]==="-",a=0;for(let l=1;l<i.length;l++){let u=i[l];if(u==="o"){let c=s+1+a;if(c<t.length&&!t[c].startsWith("-")&&!t[c].startsWith("+")){let d=t[c];if(!Os.has(d)){let p=`bash: set: ${d}: invalid option name
675
+ ${br}`;if(e.state.options.posix)throw new et(1,"",p);return L(p)}zo(e,Os.get(d)??null,o),a++;continue}n.push(o?Vc(e):zc(e));continue}if(!Wc.has(u)){let c=`bash: set: ${i[0]}${u}: invalid option
676
+ ${br}`;if(e.state.options.posix)throw new et(1,"",c);return L(c)}zo(e,Wc.get(u)??null,o)}s+=1+a;continue}if(i==="--")return qo(e,t.slice(s+1)),r();if(i==="-"){if(e.state.options.xtrace=!1,e.state.options.verbose=!1,_n(e),s+1<t.length)return qo(e,t.slice(s+1)),r();s++;continue}if(i==="+"){s++;continue}if(i.startsWith("-")||i.startsWith("+")){let o=`bash: set: ${i}: invalid option
677
+ ${br}`;if(e.state.options.posix)throw new et(1,"",o);return L(o)}return qo(e,t.slice(s)),r()}return r()}function qo(e,t){let n=1;for(;e.state.env.has(String(n));)e.state.env.delete(String(n)),n++;for(let r=0;r<t.length;r++)e.state.env.set(String(r+1),t[r]);e.state.env.set("#",String(t.length)),e.state.env.set("@",t.join(" ")),e.state.env.set("*",t.join(" "))}function jo(e,t){let n=1;if(t.length>0){let o=Number.parseInt(t[0],10);if(Number.isNaN(o)||o<0){let a=`bash: shift: ${t[0]}: numeric argument required
678
+ `;if(e.state.options.posix)throw new et(1,"",a);return L(a)}n=o}let r=Number.parseInt(e.state.env.get("#")||"0",10);if(n>r){let o=`bash: shift: shift count out of range
679
+ `;if(e.state.options.posix)throw new et(1,"",o);return L(o)}if(n===0)return J;let s=[];for(let o=1;o<=r;o++)s.push(e.state.env.get(String(o))||"");let i=s.slice(n);for(let o=1;o<=r;o++)e.state.env.delete(String(o));for(let o=0;o<i.length;o++)e.state.env.set(String(o+1),i[o]);return e.state.env.set("#",String(i.length)),e.state.env.set("@",i.join(" ")),J}async function Go(e,t){let n=t;if(n.length>0&&n[0]==="--"&&(n=n.slice(1)),n.length===0)return T("",`bash: source: filename argument required
680
+ `,2);let r=n[0],s=null,i=null;if(r.includes("/")){let u=e.fs.resolvePath(e.state.cwd,r);try{i=await e.fs.readFile(u),s=u}catch{}}else{let c=(e.state.env.get("PATH")||"").split(":").filter(f=>f);for(let f of c){let d=e.fs.resolvePath(e.state.cwd,`${f}/${r}`);try{if((await e.fs.stat(d)).isDirectory)continue;i=await e.fs.readFile(d),s=d;break}catch{}}if(i===null){let f=e.fs.resolvePath(e.state.cwd,r);try{i=await e.fs.readFile(f),s=f}catch{}}}if(i===null)return L(`bash: ${r}: No such file or directory
681
+ `);let o=new Map;if(n.length>1){for(let c=1;c<=9;c++)o.set(String(c),e.state.env.get(String(c)));o.set("#",e.state.env.get("#")),o.set("@",e.state.env.get("@"));let u=n.slice(1);e.state.env.set("#",String(u.length)),e.state.env.set("@",u.join(" "));for(let c=0;c<u.length&&c<9;c++)e.state.env.set(String(c+1),u[c]);for(let c=u.length+1;c<=9;c++)e.state.env.delete(String(c))}let a=e.state.currentSource,l=()=>{if(e.state.sourceDepth--,e.state.currentSource=a,n.length>1)for(let[u,c]of o)c===void 0?e.state.env.delete(u):e.state.env.set(u,c)};if(e.state.sourceDepth++,e.state.sourceDepth>e.limits.maxSourceDepth)throw e.state.sourceDepth--,new C(`source: maximum nesting depth (${e.limits.maxSourceDepth}) exceeded, increase executionLimits.maxSourceDepth`,"recursion");e.state.currentSource=r;try{let u=ft(i),c=await e.executeScript(u);return l(),c}catch(u){if(l(),u instanceof U)throw u;if(u instanceof Ie)return T(u.stdout,u.stderr,u.exitCode);if(u.name==="ParseException")return L(`bash: ${r}: ${u.message}
682
+ `);throw u}}function jc(e){return/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e)}function Kh(e){return e.startsWith("'")&&e.endsWith("'")||e.startsWith('"')&&e.endsWith('"')}async function Gc(e,t){if(Kh(t))return null;try{let n=new G,r=te(n,t);return await X(e,r.expression)}catch{let n=parseInt(t,10);return Number.isNaN(n)?0:n}}function Hc(e,t){if(e.state.localVarStack?.has(t)){let r=As(e,t);if(r){r.value===void 0?e.state.env.delete(t):e.state.env.set(t,r.value);let s=e.state.localVarStack?.get(t);if(!s||s.length===0)Ss(e,t),e.state.localVarStack?.delete(t),e.state.fullyUnsetLocals=e.state.fullyUnsetLocals||new Map,e.state.fullyUnsetLocals.set(t,r.scopeIndex),Ho(e,t);else{let i=s[s.length-1];e.state.localVarDepth=e.state.localVarDepth||new Map,e.state.localVarDepth.set(t,i.scopeIndex+1)}return!0}return e.state.env.delete(t),Ss(e,t),e.state.localVarStack?.delete(t),e.state.fullyUnsetLocals=e.state.fullyUnsetLocals||new Map,e.state.fullyUnsetLocals.set(t,0),!0}for(let r=e.state.localScopes.length-1;r>=0;r--){let s=e.state.localScopes[r];if(s.has(t)){let i=s.get(t);i===void 0?e.state.env.delete(t):e.state.env.set(t,i),s.delete(t);let o=!1;for(let a=r-1;a>=0;a--)if(e.state.localScopes[a].has(t)){e.state.localVarDepth&&e.state.localVarDepth.set(t,a+1),o=!0;break}return o||Ss(e,t),!0}}return!1}function Ho(e,t){if(!e.state.tempEnvBindings||e.state.tempEnvBindings.length===0)return!1;for(let n=e.state.tempEnvBindings.length-1;n>=0;n--){let r=e.state.tempEnvBindings[n];if(r.has(t)){let s=r.get(t);return s===void 0?e.state.env.delete(t):e.state.env.set(t,s),r.delete(t),!0}}return!1}async function Zc(e,t){if(t.startsWith("'")&&t.endsWith("'"))return t.slice(1,-1);if(t.startsWith('"')&&t.endsWith('"')){let n=t.slice(1,-1),s=new G().parseWordFromString(n,!0,!1);return ne(e,s)}if(t.includes("$")){let r=new G().parseWordFromString(t,!1,!1);return ne(e,r)}return t}async function Zo(e,t){let n="both",r="",s=0;for(let i of t){if(i==="-v"){n="variable";continue}if(i==="-f"){n="function";continue}if(n==="function"){e.state.functions.delete(i);continue}if(n==="variable"){let u=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(u){let d=u[1],p=u[2];if(Fe(e,d)){r+=`bash: unset: ${d}: cannot unset: readonly variable
683
+ `,s=1;continue}if(p==="@"||p==="*"){nr(e,d),e.state.env.delete(d);continue}let h=e.state.associativeArrays?.has(d);if(h){let E=await Zc(e,p);pn(e,d,E);continue}let m=pt(e,d),y=e.state.declaredVars?.has(d);if((e.state.env.has(d)||y)&&!m&&!h){r+=`bash: unset: ${d}: not an array variable
684
+ `,s=1;continue}let w=await Gc(e,p);if(w===null&&m){r+=`bash: unset: ${p}: not a valid identifier
685
+ `,s=1;continue}if(w===null)continue;if(w<0){let E=H(e,d),S=E.length,v=e.state.currentLine;if(S===0){r+=`bash: line ${v}: unset: [${w}]: bad array subscript
686
+ `,s=1;continue}let A=S+w;if(A<0){r+=`bash: line ${v}: unset: [${w}]: bad array subscript
687
+ `,s=1;continue}let x=E[A][0];pn(e,d,x);continue}pn(e,d,w);continue}if(!jc(i)){r+=`bash: unset: \`${i}': not a valid identifier
687
688
  `,s=1;continue}let c=i;if(le(e,i)){let d=Te(e,i);d&&d!==i&&(c=d)}if(Fe(e,c)){r+=`bash: unset: ${c}: cannot unset: readonly variable
688
- `,s=1;continue}tr(e,c);let f=Hi(e,c);if(f!==void 0&&f!==e.state.callDepth)qc(e,c);else if(e.state.fullyUnsetLocals?.has(c))e.state.env.delete(c);else if(f!==void 0){let d=e.state.accessedTempEnvVars?.has(c),p=e.state.mutatedTempEnvVars?.has(c);if((d||p)&&e.state.localVarStack?.has(c)){let h=ws(e,c);h?h.value===void 0?e.state.env.delete(c):e.state.env.set(c,h.value):e.state.env.delete(c)}else e.state.env.delete(c)}else Uo(e,c)||e.state.env.delete(c);e.state.exportedVars?.delete(c);continue}let o=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(o){let u=o[1],c=o[2];if(Fe(e,u)){r+=`bash: unset: ${u}: cannot unset: readonly variable
689
- `,s=1;continue}if(c==="@"||c==="*"){tr(e,u),e.state.env.delete(u);continue}let f=e.state.associativeArrays?.has(u);if(f){let m=await Uc(e,c);pn(e,u,m);continue}let d=ht(e,u);if(e.state.env.has(u)&&!d&&!f){r+=`bash: unset: ${u}: not an array variable
690
- `,s=1;continue}let h=await zc(e,c);if(h===null&&d){r+=`bash: unset: ${c}: not a valid identifier
691
- `,s=1;continue}if(h===null)continue;if(h<0){let m=G(e,u),E=m.length,S=e.state.currentLine;if(E===0){r+=`bash: line ${S}: unset: [${h}]: bad array subscript
692
- `,s=1;continue}let y=E+h;if(y<0){r+=`bash: line ${S}: unset: [${h}]: bad array subscript
693
- `,s=1;continue}let g=m[y][0];pn(e,u,g);continue}pn(e,u,h);continue}if(!Vc(i)){r+=`bash: unset: \`${i}': not a valid identifier
689
+ `,s=1;continue}nr(e,c);let f=Qi(e,c);if(f!==void 0&&f!==e.state.callDepth)Hc(e,c);else if(e.state.fullyUnsetLocals?.has(c))e.state.env.delete(c);else if(f!==void 0){let d=e.state.accessedTempEnvVars?.has(c),p=e.state.mutatedTempEnvVars?.has(c);if((d||p)&&e.state.localVarStack?.has(c)){let h=As(e,c);h?h.value===void 0?e.state.env.delete(c):e.state.env.set(c,h.value):e.state.env.delete(c)}else e.state.env.delete(c)}else Ho(e,c)||e.state.env.delete(c);e.state.exportedVars?.delete(c);continue}let o=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(o){let u=o[1],c=o[2];if(Fe(e,u)){r+=`bash: unset: ${u}: cannot unset: readonly variable
690
+ `,s=1;continue}if(c==="@"||c==="*"){nr(e,u),e.state.env.delete(u);continue}let f=e.state.associativeArrays?.has(u);if(f){let m=await Zc(e,c);pn(e,u,m);continue}let d=pt(e,u);if(e.state.env.has(u)&&!d&&!f){r+=`bash: unset: ${u}: not an array variable
691
+ `,s=1;continue}let h=await Gc(e,c);if(h===null&&d){r+=`bash: unset: ${c}: not a valid identifier
692
+ `,s=1;continue}if(h===null)continue;if(h<0){let m=H(e,u),y=m.length,b=e.state.currentLine;if(y===0){r+=`bash: line ${b}: unset: [${h}]: bad array subscript
693
+ `,s=1;continue}let w=y+h;if(w<0){r+=`bash: line ${b}: unset: [${h}]: bad array subscript
694
+ `,s=1;continue}let E=m[w][0];pn(e,u,E);continue}pn(e,u,h);continue}if(!jc(i)){r+=`bash: unset: \`${i}': not a valid identifier
694
695
  `,s=1;continue}let a=i;if(le(e,i)){let u=Te(e,i);u&&u!==i&&(a=u)}if(Fe(e,a)){r+=`bash: unset: ${a}: cannot unset: readonly variable
695
- `,s=1;continue}tr(e,a);let l=Hi(e,a);if(l!==void 0&&l!==e.state.callDepth)qc(e,a);else if(e.state.fullyUnsetLocals?.has(a))e.state.env.delete(a);else if(l!==void 0){let u=e.state.accessedTempEnvVars?.has(a),c=e.state.mutatedTempEnvVars?.has(a);if((u||c)&&e.state.localVarStack?.has(a)){let f=ws(e,a);f?f.value===void 0?e.state.env.delete(a):e.state.env.set(a,f.value):e.state.env.delete(a)}else e.state.env.delete(a)}else Uo(e,a)||e.state.env.delete(a);e.state.exportedVars?.delete(a),e.state.functions.delete(i)}return L("",r,s)}function Pt(e,t,n,r){let s=n+F(t)+1;if(s>r)throw new P(`shopt: output size limit exceeded (${r} bytes)`,"output_size");return e.push(t),s}var Go=["extglob","dotglob","nullglob","failglob","globstar","globskipdots","nocaseglob","nocasematch","expand_aliases","lastpipe","xpg_echo"],Uh=["autocd","cdable_vars","cdspell","checkhash","checkjobs","checkwinsize","cmdhist","compat31","compat32","compat40","compat41","compat42","compat43","compat44","complete_fullquote","direxpand","dirspell","execfail","extdebug","extquote","force_fignore","globasciiranges","gnu_errfmt","histappend","histreedit","histverify","hostcomplete","huponexit","inherit_errexit","interactive_comments","lithist","localvar_inherit","localvar_unset","login_shell","mailwarn","no_empty_cmd_completion","progcomp","progcomp_alias","promptvars","restricted_shell","shift_verbose","sourcepath"];function Rs(e){return Go.includes(e)}function jh(e){return Uh.includes(e)}function jc(e,t){let n=e.limits.maxArrayElements;if(t.length>n)throw new P(`shopt: argument limit exceeded (${n})`,"array_elements");let r=Math.min(e.limits.maxOutputSize,e.limits.maxStringLength),s=!1,i=!1,o=!1,a=!1,l=!1,u=[],c=0;for(;c<t.length;){let E=t[c];if(E==="--"){c++;break}if(E.startsWith("-")&&E.length>1){for(let S=1;S<E.length;S++){let y=E[S];switch(y){case"s":s=!0;break;case"u":i=!0;break;case"p":o=!0;break;case"q":a=!0;break;case"o":l=!0;break;default:return{exitCode:2,stdout:"",stderr:`shopt: -${y}: invalid option
696
- `}}}c++}else break}for(;c<t.length;)u.push(t[c]),c++;if(l)return Gh(e,u,s,i,o,a);if(s&&i)return{exitCode:1,stdout:"",stderr:`shopt: cannot set and unset shell options simultaneously
697
- `};if(u.length===0){if(s||i){let S=[];for(let y of Go){let g=e.state.shoptOptions[y];s&&g?S.push(o?`shopt -s ${y}`:`${y} on`):i&&!g&&S.push(o?`shopt -u ${y}`:`${y} off`)}return{exitCode:0,stdout:S.length>0?`${S.join(`
696
+ `,s=1;continue}nr(e,a);let l=Qi(e,a);if(l!==void 0&&l!==e.state.callDepth)Hc(e,a);else if(e.state.fullyUnsetLocals?.has(a))e.state.env.delete(a);else if(l!==void 0){let u=e.state.accessedTempEnvVars?.has(a),c=e.state.mutatedTempEnvVars?.has(a);if((u||c)&&e.state.localVarStack?.has(a)){let f=As(e,a);f?f.value===void 0?e.state.env.delete(a):e.state.env.set(a,f.value):e.state.env.delete(a)}else e.state.env.delete(a)}else Ho(e,a)||e.state.env.delete(a);e.state.exportedVars?.delete(a),e.state.functions.delete(i)}return T("",r,s)}function Pt(e,t,n,r){let s=n+W(t)+1;if(s>r)throw new C(`shopt: output size limit exceeded (${r} bytes)`,"output_size");return e.push(t),s}var Qo=["extglob","dotglob","nullglob","failglob","globstar","globskipdots","nocaseglob","nocasematch","expand_aliases","lastpipe","xpg_echo"],Xh=["autocd","cdable_vars","cdspell","checkhash","checkjobs","checkwinsize","cmdhist","compat31","compat32","compat40","compat41","compat42","compat43","compat44","complete_fullquote","direxpand","dirspell","execfail","extdebug","extquote","force_fignore","globasciiranges","gnu_errfmt","histappend","histreedit","histverify","hostcomplete","huponexit","inherit_errexit","interactive_comments","lithist","localvar_inherit","localvar_unset","login_shell","mailwarn","no_empty_cmd_completion","progcomp","progcomp_alias","promptvars","restricted_shell","shift_verbose","sourcepath"];function _s(e){return Qo.includes(e)}function Yh(e){return Xh.includes(e)}function Qc(e,t){let n=e.limits.maxArrayElements;if(t.length>n)throw new C(`shopt: argument limit exceeded (${n})`,"array_elements");let r=Math.min(e.limits.maxOutputSize,e.limits.maxStringLength),s=!1,i=!1,o=!1,a=!1,l=!1,u=[],c=0;for(;c<t.length;){let y=t[c];if(y==="--"){c++;break}if(y.startsWith("-")&&y.length>1){for(let b=1;b<y.length;b++){let w=y[b];switch(w){case"s":s=!0;break;case"u":i=!0;break;case"p":o=!0;break;case"q":a=!0;break;case"o":l=!0;break;default:return{exitCode:2,stdout:"",stderr:`shopt: -${w}: invalid option
697
+ `}}}c++}else break}for(;c<t.length;)u.push(t[c]),c++;if(l)return Jh(e,u,s,i,o,a);if(s&&i)return{exitCode:1,stdout:"",stderr:`shopt: cannot set and unset shell options simultaneously
698
+ `};if(u.length===0){if(s||i){let b=[];for(let w of Qo){let E=e.state.shoptOptions[w];s&&E?b.push(o?`shopt -s ${w}`:`${w} on`):i&&!E&&b.push(o?`shopt -u ${w}`:`${w} off`)}return{exitCode:0,stdout:b.length>0?`${b.join(`
698
699
  `)}
699
- `:"",stderr:""}}let E=[];for(let S of Go){let y=e.state.shoptOptions[S];E.push(o?`shopt ${y?"-s":"-u"} ${S}`:`${S} ${y?"on":"off"}`)}return{exitCode:0,stdout:`${E.join(`
700
+ `:"",stderr:""}}let y=[];for(let b of Qo){let w=e.state.shoptOptions[b];y.push(o?`shopt ${w?"-s":"-u"} ${b}`:`${b} ${w?"on":"off"}`)}return{exitCode:0,stdout:`${y.join(`
700
701
  `)}
701
- `,stderr:""}}let f=!1,d=[],p=0,h=[],m=0;for(let E of u){if(!Rs(E)&&!jh(E)){p=Pt(d,`shopt: ${E}: invalid shell option name`,p,r),f=!0;continue}if(s)Rs(E)&&(e.state.shoptOptions[E]=!0,Ks(e));else if(i)Rs(E)&&(e.state.shoptOptions[E]=!1,Ks(e));else if(Rs(E)){let S=e.state.shoptOptions[E];a?S||(f=!0):o?(m=Pt(h,`shopt ${S?"-s":"-u"} ${E}`,m,r),S||(f=!0)):(m=Pt(h,`${E} ${S?"on":"off"}`,m,r),S||(f=!0))}else a?f=!0:o?(m=Pt(h,`shopt -u ${E}`,m,r),f=!0):(m=Pt(h,`${E} off`,m,r),f=!0)}return{exitCode:f?1:0,stdout:h.length>0?`${h.join(`
702
+ `,stderr:""}}let f=!1,d=[],p=0,h=[],m=0;for(let y of u){if(!_s(y)&&!Yh(y)){p=Pt(d,`shopt: ${y}: invalid shell option name`,p,r),f=!0;continue}if(s)_s(y)&&(e.state.shoptOptions[y]=!0,Ys(e));else if(i)_s(y)&&(e.state.shoptOptions[y]=!1,Ys(e));else if(_s(y)){let b=e.state.shoptOptions[y];a?b||(f=!0):o?(m=Pt(h,`shopt ${b?"-s":"-u"} ${y}`,m,r),b||(f=!0)):(m=Pt(h,`${y} ${b?"on":"off"}`,m,r),b||(f=!0))}else a?f=!0:o?(m=Pt(h,`shopt -u ${y}`,m,r),f=!0):(m=Pt(h,`${y} off`,m,r),f=!0)}return{exitCode:f?1:0,stdout:h.length>0?`${h.join(`
702
703
  `)}
703
704
  `:"",stderr:d.length>0?`${d.join(`
704
705
  `)}
705
- `:""}}function Gh(e,t,n,r,s,i){let o=Math.min(e.limits.maxOutputSize,e.limits.maxStringLength),a=new Map([["errexit","errexit"],["pipefail","pipefail"],["nounset","nounset"],["xtrace","xtrace"],["verbose","verbose"],["posix","posix"],["allexport","allexport"],["noclobber","noclobber"],["noglob","noglob"],["noexec","noexec"],["vi","vi"],["emacs","emacs"]]),l=["braceexpand","errtrace","functrace","hashall","histexpand","history","ignoreeof","interactive-comments","keyword","monitor","nolog","notify","onecmd","physical","privileged"],u=[...a.keys(),...l].sort();if(t.length===0){let m=[];for(let E of u){let S=l.includes(E),y=a.get(E),g=S||!y?!1:e.state.options[y];n&&!g||r&&g||m.push(s?`set ${g?"-o":"+o"} ${E}`:`${E} ${g?"on":"off"}`)}return{exitCode:0,stdout:m.length>0?`${m.join(`
706
+ `:""}}function Jh(e,t,n,r,s,i){let o=Math.min(e.limits.maxOutputSize,e.limits.maxStringLength),a=new Map([["errexit","errexit"],["pipefail","pipefail"],["nounset","nounset"],["xtrace","xtrace"],["verbose","verbose"],["posix","posix"],["allexport","allexport"],["noclobber","noclobber"],["noglob","noglob"],["noexec","noexec"],["vi","vi"],["emacs","emacs"]]),l=["braceexpand","errtrace","functrace","hashall","histexpand","history","ignoreeof","interactive-comments","keyword","monitor","nolog","notify","onecmd","physical","privileged"],u=[...a.keys(),...l].sort();if(t.length===0){let m=[];for(let y of u){let b=l.includes(y),w=a.get(y),E=b||!w?!1:e.state.options[w];n&&!E||r&&E||m.push(s?`set ${E?"-o":"+o"} ${y}`:`${y} ${E?"on":"off"}`)}return{exitCode:0,stdout:m.length>0?`${m.join(`
706
707
  `)}
707
- `:"",stderr:""}}let c=!1,f=[],d=0,p=[],h=0;for(let m of t){let E=a.has(m),S=l.includes(m);if(!E&&!S){d=Pt(f,`shopt: ${m}: invalid option name`,d,o),c=!0;continue}if(S){n||r||(i?c=!0:s?(h=Pt(p,`set +o ${m}`,h,o),c=!0):(h=Pt(p,`${m} off`,h,o),c=!0));continue}let y=a.get(m);if(y)if(n)y==="vi"?e.state.options.emacs=!1:y==="emacs"&&(e.state.options.vi=!1),e.state.options[y]=!0,On(e);else if(r)e.state.options[y]=!1,On(e);else{let g=e.state.options[y];i?g||(c=!0):s?(h=Pt(p,`set ${g?"-o":"+o"} ${m}`,h,o),g||(c=!0)):(h=Pt(p,`${m} ${g?"on":"off"}`,h,o),g||(c=!0))}}return{exitCode:c?1:0,stdout:p.length>0?`${p.join(`
708
+ `:"",stderr:""}}let c=!1,f=[],d=0,p=[],h=0;for(let m of t){let y=a.has(m),b=l.includes(m);if(!y&&!b){d=Pt(f,`shopt: ${m}: invalid option name`,d,o),c=!0;continue}if(b){n||r||(i?c=!0:s?(h=Pt(p,`set +o ${m}`,h,o),c=!0):(h=Pt(p,`${m} off`,h,o),c=!0));continue}let w=a.get(m);if(w)if(n)w==="vi"?e.state.options.emacs=!1:w==="emacs"&&(e.state.options.vi=!1),e.state.options[w]=!0,_n(e);else if(r)e.state.options[w]=!1,_n(e);else{let E=e.state.options[w];i?E||(c=!0):s?(h=Pt(p,`set ${E?"-o":"+o"} ${m}`,h,o),E||(c=!0)):(h=Pt(p,`${m} ${E?"on":"off"}`,h,o),E||(c=!0))}}return{exitCode:c?1:0,stdout:p.length>0?`${p.join(`
708
709
  `)}
709
710
  `:"",stderr:f.length>0?`${f.join(`
710
711
  `)}
711
- `:""}}function Ds(e,t){return e===`/bin/${t}`||e===`/usr/bin/${t}`}async function Gc(e,t,n){if(t.includes("/")){let o=e.fs.resolvePath(e.state.cwd,t);if(!await e.fs.exists(o))return{error:"not_found",path:o};try{let a=await e.fs.stat(o);if(a.isDirectory)return{error:"permission_denied",path:o};let l=o.split("/").pop()||t,u=e.commands.get(l);return u&&Ds(o,l)?{cmd:u,path:o}:(a.mode&73)!==0?{script:!0,path:o}:{error:"permission_denied",path:o}}catch{return{error:"not_found",path:o}}}if(!n&&e.state.hashTable){let o=e.state.hashTable.get(t);if(o){try{let a=await e.fs.stat(o);if(!a.isDirectory){let l=e.commands.get(t);if(l&&Ds(o,t))return{cmd:l,path:o};if((a.mode&73)!==0)return{script:!0,path:o}}}catch{}e.state.hashTable.delete(t)}}let s=(n??e.state.env.get("PATH")??"/usr/bin:/bin").split(":");for(let o of s){if(!o)continue;let l=`${o.startsWith("/")?o:e.fs.resolvePath(e.state.cwd,o)}/${t}`;if(await e.fs.exists(l))try{let u=await e.fs.stat(l);if(u.isDirectory)continue;let c=(u.mode&73)!==0,f=e.commands.get(t),d=Ds(l,t);if(f&&d)return{cmd:f,path:l};if(c){if(f&&!d)return{script:!0,path:l};if(!f)return{script:!0,path:l}}}catch{}}if(!await e.fs.exists("/usr/bin")){let o=e.commands.get(t);if(o)return{cmd:o,path:`/usr/bin/${t}`}}return null}async function Is(e,t){let n=[];if(t.includes("/")){let i=e.fs.resolvePath(e.state.cwd,t);if(await e.fs.exists(i))try{let o=await e.fs.stat(i);o.isDirectory||(o.mode&73)!==0&&n.push(t)}catch{}return n}let s=(e.state.env.get("PATH")||"/usr/bin:/bin").split(":");for(let i of s){if(!i)continue;let a=`${i.startsWith("/")?i:e.fs.resolvePath(e.state.cwd,i)}/${t}`;if(Ds(a,t)&&e.commands.has(t)){n.push(a);continue}if(await e.fs.exists(a)){try{let l=await e.fs.stat(a);if(l.isDirectory||(l.mode&73)===0)continue}catch{continue}n.push(i.startsWith("/")?a:`${i}/${t}`)}}return n}function Hh(e){return e!==null&&typeof e=="object"&&"then"in e&&typeof e.then=="function"}function de(e,t,n,r){return((...s)=>{Jn(t,n,`${r} call`);let i=e(...s);return Hh(i)?i.then(o=>(Jn(t,n,`${r} post-await`),o),o=>{throw Jn(t,n,`${r} post-await`),o}):(Jn(t,n,`${r} return`),i)})}function Zh(e,t,n){let r={readFile:de(e.readFile.bind(e),t,n,"fs.readFile"),...typeof e.readFileBytes=="function"?{readFileBytes:de(e.readFileBytes.bind(e),t,n,"fs.readFileBytes")}:Object.create(null),readFileBuffer:de(e.readFileBuffer.bind(e),t,n,"fs.readFileBuffer"),writeFile:de(e.writeFile.bind(e),t,n,"fs.writeFile"),appendFile:de(e.appendFile.bind(e),t,n,"fs.appendFile"),exists:de(e.exists.bind(e),t,n,"fs.exists"),stat:de(e.stat.bind(e),t,n,"fs.stat"),mkdir:de(e.mkdir.bind(e),t,n,"fs.mkdir"),readdir:de(e.readdir.bind(e),t,n,"fs.readdir"),rm:de(e.rm.bind(e),t,n,"fs.rm"),cp:de(e.cp.bind(e),t,n,"fs.cp"),mv:de(e.mv.bind(e),t,n,"fs.mv"),resolvePath:de(e.resolvePath.bind(e),t,n,"fs.resolvePath"),getAllPaths:de(e.getAllPaths.bind(e),t,n,"fs.getAllPaths"),chmod:de(e.chmod.bind(e),t,n,"fs.chmod"),symlink:de(e.symlink.bind(e),t,n,"fs.symlink"),link:de(e.link.bind(e),t,n,"fs.link"),readlink:de(e.readlink.bind(e),t,n,"fs.readlink"),lstat:de(e.lstat.bind(e),t,n,"fs.lstat"),realpath:de(e.realpath.bind(e),t,n,"fs.realpath"),utimes:de(e.utimes.bind(e),t,n,"fs.utimes")};return e.readdirWithFileTypes&&(r.readdirWithFileTypes=de(e.readdirWithFileTypes.bind(e),t,n,"fs.readdirWithFileTypes")),e.createExclusive&&(r.createExclusive=de(e.createExclusive.bind(e),t,n,"fs.createExclusive")),r}function Ho(e,t){if(!e.requireDefenseContext)return e;let n=`command:${t}`,r=Object.getOwnPropertyDescriptors(e);r.fs={value:Zh(e.fs,e.requireDefenseContext,n),enumerable:!0,configurable:!0,writable:!0};let s=Object.defineProperties(Object.create(Object.getPrototypeOf(e)),r);return e.exec&&(s.exec=de(e.exec,e.requireDefenseContext,n,"exec")),e.origCommand&&(s.origCommand=de(e.origCommand,e.requireDefenseContext,n,"origCommand")),e.fetch&&(s.fetch=de(e.fetch,e.requireDefenseContext,n,"fetch")),e.sleep&&(s.sleep=de(e.sleep,e.requireDefenseContext,n,"sleep")),e.getRegisteredCommands&&(s.getRegisteredCommands=de(e.getRegisteredCommands,e.requireDefenseContext,n,"getRegisteredCommands")),s}var Hc="+ ";async function Zc(e){let t=e.state.env.get("PS4");if(t===void 0)return Hc;if(t==="")return"";let n=e.state.options.xtrace;e.state.options.xtrace=!1;let r=e.state.lastExitCode,s=e.state.env.get("?"),i=e.state.lastSubstitutionExitCode;try{let a=new j().parseWordFromString(t,!1,!1);return await ne(e,a)}catch(o){if(o instanceof oe&&!o.fatal)return t;if(o instanceof xn||o instanceof Error&&o.name==="AbortError")throw o;return e.state.expansionStderr=`${e.state.expansionStderr||""}bash: ${t}: bad substitution
712
- `,t||Hc}finally{e.state.options.xtrace=n,e.state.lastExitCode=r,e.state.lastSubstitutionExitCode=i,s===void 0?e.state.env.delete("?"):e.state.env.set("?",s)}}function Qh(e){return e.map(t=>Kh(t)).join(" ")}function Kh(e){if(e==="")return"''";if(!/[\s'"\\$`!*?[\]{}|&;<>()~#\n\t]/.test(e))return e;let n=/[\x00-\x1f\x7f]/.test(e),r=e.includes(`
712
+ `:""}}function Ls(e,t){return e===`/bin/${t}`||e===`/usr/bin/${t}`}async function Kc(e,t,n){if(t.includes("/")){let o=e.fs.resolvePath(e.state.cwd,t);if(!await e.fs.exists(o))return{error:"not_found",path:o};try{let a=await e.fs.stat(o);if(a.isDirectory)return{error:"permission_denied",path:o};let l=o.split("/").pop()||t,u=e.commands.get(l);return u&&Ls(o,l)?{cmd:u,path:o}:(a.mode&73)!==0?{script:!0,path:o}:{error:"permission_denied",path:o}}catch{return{error:"not_found",path:o}}}if(!n&&e.state.hashTable){let o=e.state.hashTable.get(t);if(o){try{let a=await e.fs.stat(o);if(!a.isDirectory){let l=e.commands.get(t);if(l&&Ls(o,t))return{cmd:l,path:o};if((a.mode&73)!==0)return{script:!0,path:o}}}catch{}e.state.hashTable.delete(t)}}let s=(n??e.state.env.get("PATH")??"/usr/bin:/bin").split(":");for(let o of s){if(!o)continue;let l=`${o.startsWith("/")?o:e.fs.resolvePath(e.state.cwd,o)}/${t}`;if(await e.fs.exists(l))try{let u=await e.fs.stat(l);if(u.isDirectory)continue;let c=(u.mode&73)!==0,f=e.commands.get(t),d=Ls(l,t);if(f&&d)return{cmd:f,path:l};if(c){if(f&&!d)return{script:!0,path:l};if(!f)return{script:!0,path:l}}}catch{}}if(!await e.fs.exists("/usr/bin")){let o=e.commands.get(t);if(o)return{cmd:o,path:`/usr/bin/${t}`}}return null}async function Ts(e,t){let n=[];if(t.includes("/")){let i=e.fs.resolvePath(e.state.cwd,t);if(await e.fs.exists(i))try{let o=await e.fs.stat(i);o.isDirectory||(o.mode&73)!==0&&n.push(t)}catch{}return n}let s=(e.state.env.get("PATH")||"/usr/bin:/bin").split(":");for(let i of s){if(!i)continue;let a=`${i.startsWith("/")?i:e.fs.resolvePath(e.state.cwd,i)}/${t}`;if(Ls(a,t)&&e.commands.has(t)){n.push(a);continue}if(await e.fs.exists(a)){try{let l=await e.fs.stat(a);if(l.isDirectory||(l.mode&73)===0)continue}catch{continue}n.push(i.startsWith("/")?a:`${i}/${t}`)}}return n}function em(e){return e!==null&&typeof e=="object"&&"then"in e&&typeof e.then=="function"}function de(e,t,n,r){return((...s)=>{er(t,n,`${r} call`);let i=e(...s);return em(i)?i.then(o=>(er(t,n,`${r} post-await`),o),o=>{throw er(t,n,`${r} post-await`),o}):(er(t,n,`${r} return`),i)})}function tm(e,t,n){let r={readFile:de(e.readFile.bind(e),t,n,"fs.readFile"),...typeof e.readFileBytes=="function"?{readFileBytes:de(e.readFileBytes.bind(e),t,n,"fs.readFileBytes")}:Object.create(null),readFileBuffer:de(e.readFileBuffer.bind(e),t,n,"fs.readFileBuffer"),writeFile:de(e.writeFile.bind(e),t,n,"fs.writeFile"),appendFile:de(e.appendFile.bind(e),t,n,"fs.appendFile"),exists:de(e.exists.bind(e),t,n,"fs.exists"),stat:de(e.stat.bind(e),t,n,"fs.stat"),mkdir:de(e.mkdir.bind(e),t,n,"fs.mkdir"),readdir:de(e.readdir.bind(e),t,n,"fs.readdir"),rm:de(e.rm.bind(e),t,n,"fs.rm"),cp:de(e.cp.bind(e),t,n,"fs.cp"),mv:de(e.mv.bind(e),t,n,"fs.mv"),resolvePath:de(e.resolvePath.bind(e),t,n,"fs.resolvePath"),getAllPaths:de(e.getAllPaths.bind(e),t,n,"fs.getAllPaths"),chmod:de(e.chmod.bind(e),t,n,"fs.chmod"),symlink:de(e.symlink.bind(e),t,n,"fs.symlink"),link:de(e.link.bind(e),t,n,"fs.link"),readlink:de(e.readlink.bind(e),t,n,"fs.readlink"),lstat:de(e.lstat.bind(e),t,n,"fs.lstat"),realpath:de(e.realpath.bind(e),t,n,"fs.realpath"),utimes:de(e.utimes.bind(e),t,n,"fs.utimes")};return e.readdirWithFileTypes&&(r.readdirWithFileTypes=de(e.readdirWithFileTypes.bind(e),t,n,"fs.readdirWithFileTypes")),e.createExclusive&&(r.createExclusive=de(e.createExclusive.bind(e),t,n,"fs.createExclusive")),r}function Ko(e,t){if(!e.requireDefenseContext)return e;let n=`command:${t}`,r=Object.getOwnPropertyDescriptors(e);r.fs={value:tm(e.fs,e.requireDefenseContext,n),enumerable:!0,configurable:!0,writable:!0};let s=Object.defineProperties(Object.create(Object.getPrototypeOf(e)),r);return e.exec&&(s.exec=de(e.exec,e.requireDefenseContext,n,"exec")),e.origCommand&&(s.origCommand=de(e.origCommand,e.requireDefenseContext,n,"origCommand")),e.fetch&&(s.fetch=de(e.fetch,e.requireDefenseContext,n,"fetch")),e.sleep&&(s.sleep=de(e.sleep,e.requireDefenseContext,n,"sleep")),e.getRegisteredCommands&&(s.getRegisteredCommands=de(e.getRegisteredCommands,e.requireDefenseContext,n,"getRegisteredCommands")),s}var Xc="+ ";async function Yc(e){let t=e.state.env.get("PS4");if(t===void 0)return Xc;if(t==="")return"";let n=e.state.options.xtrace;e.state.options.xtrace=!1;let r=e.state.lastExitCode,s=e.state.env.get("?"),i=e.state.lastSubstitutionExitCode;try{let a=new G().parseWordFromString(t,!1,!1);return await ne(e,a)}catch(o){if(o instanceof oe&&!o.fatal)return t;if(o instanceof $n||o instanceof Error&&o.name==="AbortError")throw o;return e.state.expansionStderr=`${e.state.expansionStderr||""}bash: ${t}: bad substitution
713
+ `,t||Xc}finally{e.state.options.xtrace=n,e.state.lastExitCode=r,e.state.lastSubstitutionExitCode=i,s===void 0?e.state.env.delete("?"):e.state.env.set("?",s)}}function nm(e){return e.map(t=>rm(t)).join(" ")}function rm(e){if(e==="")return"''";if(!/[\s'"\\$`!*?[\]{}|&;<>()~#\n\t]/.test(e))return e;let n=/[\x00-\x1f\x7f]/.test(e),r=e.includes(`
713
714
  `),s=e.includes(" "),i=e.includes("\\"),o=e.includes("'");if(n||r||s||i){let l="";for(let u of e){let c=u.charCodeAt(0);u===`
714
- `?l+="\\n":u===" "?l+="\\t":u==="\\"?l+="\\\\":u==="'"?l+="'":u==='"'?l+='"':c<32||c===127?c<256?l+=`\\x${c.toString(16).padStart(2,"0")}`:l+=`\\u${c.toString(16).padStart(4,"0")}`:l+=u}return`$'${l}'`}return o?`"${e.replace(/([\\$`"])/g,"\\$1")}"`:`'${e}'`}async function Qc(e,t,n){if(!e.state.options.xtrace)return"";let r=await Zc(e),s=[t,...n],i=Qh(s);return`${r}${i}
715
- `}async function Kc(e,t,n){return e.state.options.xtrace?`${await Zc(e)}${t}=${n}
716
- `:""}function Os(e,t,n){return Ft([t,n],"",e.limits.maxStringLength,"array assignment")}async function Xc(e,t){let n=new Map,r="";for(let s of t.assignments){let i=s.name;if(s.array){let c=await Xh(e,t,i,s.array,s.append,n);if(c.error)return{continueToNext:!1,xtraceOutput:r,tempAssignments:n,error:c.error};if(r+=c.xtraceOutput,c.continueToNext)continue}let o=s.value?await ne(e,s.value):"";if(i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[\]$/))return{continueToNext:!1,xtraceOutput:r,tempAssignments:n,error:L("",`bash: ${i}: bad array subscript
717
- `,1)};let l=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(l){let c=await nm(e,t,l[1],l[2],o,s.append,n);if(c.error)return{continueToNext:!1,xtraceOutput:r,tempAssignments:n,error:c.error};if(c.continueToNext)continue}let u=await rm(e,t,i,o,s.append,n);if(u.error)return{continueToNext:!1,xtraceOutput:r,tempAssignments:n,error:u.error};r+=u.xtraceOutput,u.continueToNext}return{continueToNext:!1,xtraceOutput:r,tempAssignments:n}}async function Xh(e,t,n,r,s,i){let o="";if(/\[.+\]$/.test(n))return{continueToNext:!1,xtraceOutput:"",error:L("",`bash: ${n}: cannot assign list to array member
718
- `,1)};if(le(e,n)){let h=En(e,n);if(h===void 0||h==="")throw new q(1,"","");let m=Te(e,n);if(m&&/^[a-zA-Z_][a-zA-Z0-9_]*\[@\]$/.test(m))return{continueToNext:!1,xtraceOutput:"",error:L("",`bash: ${n}: cannot assign list to array member
715
+ `?l+="\\n":u===" "?l+="\\t":u==="\\"?l+="\\\\":u==="'"?l+="'":u==='"'?l+='"':c<32||c===127?c<256?l+=`\\x${c.toString(16).padStart(2,"0")}`:l+=`\\u${c.toString(16).padStart(4,"0")}`:l+=u}return`$'${l}'`}return o?`"${e.replace(/([\\$`"])/g,"\\$1")}"`:`'${e}'`}async function Jc(e,t,n){if(!e.state.options.xtrace)return"";let r=await Yc(e),s=[t,...n],i=nm(s);return`${r}${i}
716
+ `}async function ef(e,t,n){return e.state.options.xtrace?`${await Yc(e)}${t}=${n}
717
+ `:""}function Fs(e,t,n){return Ft([t,n],"",e.limits.maxStringLength,"array assignment")}async function tf(e,t){let n=new Map,r="";for(let s of t.assignments){let i=s.name;if(s.array){let c=await sm(e,t,i,s.array,s.append,n);if(c.error)return{continueToNext:!1,xtraceOutput:r,tempAssignments:n,error:c.error};if(r+=c.xtraceOutput,c.continueToNext)continue}let o=s.value?await ne(e,s.value):"";if(i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[\]$/))return{continueToNext:!1,xtraceOutput:r,tempAssignments:n,error:T("",`bash: ${i}: bad array subscript
718
+ `,1)};let l=i.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);if(l){let c=await um(e,t,l[1],l[2],o,s.append,n);if(c.error)return{continueToNext:!1,xtraceOutput:r,tempAssignments:n,error:c.error};if(c.continueToNext)continue}let u=await cm(e,t,i,o,s.append,n);if(u.error)return{continueToNext:!1,xtraceOutput:r,tempAssignments:n,error:u.error};r+=u.xtraceOutput,u.continueToNext}return{continueToNext:!1,xtraceOutput:r,tempAssignments:n}}async function sm(e,t,n,r,s,i){let o="";if(/\[.+\]$/.test(n))return{continueToNext:!1,xtraceOutput:"",error:T("",`bash: ${n}: cannot assign list to array member
719
+ `,1)};if(le(e,n)){let h=En(e,n);if(h===void 0||h==="")throw new U(1,"","");let m=Te(e,n);if(m&&/^[a-zA-Z_][a-zA-Z0-9_]*\[@\]$/.test(m))return{continueToNext:!1,xtraceOutput:"",error:T("",`bash: ${n}: cannot assign list to array member
719
720
  `,1)}}if(Fe(e,n)){if(t.name)return o+=`bash: ${n}: readonly variable
720
- `,{continueToNext:!0,xtraceOutput:o};let h=ue(e,n);if(h)return{continueToNext:!1,xtraceOutput:"",error:h}}let a=e.state.associativeArrays?.has(n),l=ve(e,n),u=l?Le(l):void 0,c=e.state.env.get(n),f=()=>{e.state.arrays??=new Map,u?e.state.arrays.set(n,u):e.state.arrays.delete(n),c===void 0?e.state.env.delete(n):e.state.env.set(n,c)},d=Yh(r),p=()=>{ye(e,n),e.state.env.delete(n)};try{a&&d?await Jh(e,t,n,r,s,p,h=>{o+=h}):d?await em(e,n,r,s,p):await tm(e,n,r,s,p)}catch(h){throw f(),h}if(t.name){i.set(n,e.state.env.get(n));let m=`(${r.map(E=>In(E)).join(" ")})`;e.state.env.set(n,m)}return{continueToNext:!0,xtraceOutput:o}}function Yh(e){return e.some(t=>{if(t.parts.length>=2){let n=t.parts[0],r=t.parts[1];if(n.type!=="Glob"||!n.pattern.startsWith("["))return!1;if(n.pattern==="["&&(r.type==="DoubleQuoted"||r.type==="SingleQuoted")){if(t.parts.length<3)return!1;let s=t.parts[2];return s.type!=="Literal"?!1:s.value.startsWith("]=")||s.value.startsWith("]+=")}return r.type!=="Literal"?!1:r.value.startsWith("]")?r.value.startsWith("]=")||r.value.startsWith("]+="):n.pattern.endsWith("]")?r.value.startsWith("=")||r.value.startsWith("+="):!1}return!1})}async function Jh(e,t,n,r,s,i,o){let a=[];for(let l of r){if(a.length>=e.limits.maxArrayElements)throw new P(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");let u=Hs(l);if(u){let{key:c,valueParts:f,append:d}=u,p;f.length>0?(p=await ne(e,{type:"Word",parts:f}),f.every(m=>m.type==="Literal"||m.type==="TildeExpansion")&&(p=Kt(e,p))):p="",a.push({type:"keyed",key:c,value:p,append:d})}else{let c=await ne(e,l);a.push({type:"invalid",expandedValue:c})}}e.executionScope.consumeWork(a.length,"associative array assignment"),s||i();for(let l of a)if(l.type==="keyed")if(l.append){let u=ie(e,n,l.key)??"";U(e,n,l.key,Os(e,u,l.value),"associative")}else U(e,n,l.key,l.value,"associative");else{let u=t.line??e.state.currentLine??1;o(`bash: line ${u}: ${n}: ${l.expandedValue}: must use subscript when assigning associative array
721
- `)}}async function em(e,t,n,r,s){let i=[],o=0;for(let l of n){let u=Hs(l);if(u){if(o>=e.limits.maxArrayElements)throw new P(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");let{key:c,valueParts:f,append:d}=u,p;f.length>0?(p=await ne(e,{type:"Word",parts:f}),f.every(m=>m.type==="Literal"||m.type==="TildeExpansion")&&(p=Kt(e,p))):p="",i.push({type:"keyed",indexExpr:c,value:p,append:d}),o++}else{let c=await wt(e,l);if(c.values.length>e.limits.maxArrayElements-o)throw new P(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");i.push({type:"non-keyed",values:c.values}),o+=c.values.length}}e.executionScope.consumeWork(o,"indexed array assignment"),r||s();let a=0;for(let l of i)if(l.type==="keyed"){let u;try{let c=new j,f=te(c,l.indexExpr);u=await X(e,f.expression,!1)}catch{if(/^-?\d+$/.test(l.indexExpr))u=Number.parseInt(l.indexExpr,10);else{let c=e.state.env.get(l.indexExpr);u=c?Number.parseInt(c,10):0,Number.isNaN(u)&&(u=0)}}if(l.append){let c=ie(e,t,u)??"";U(e,t,u,Os(e,c,l.value))}else U(e,t,u,l.value);a=u+1}else for(let u of l.values)U(e,t,a++,u)}async function tm(e,t,n,r,s){let i=[];for(let a of n){let l=await wt(e,a);for(let u of l.values){if(i.length>=e.limits.maxArrayElements)throw new P(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");i.push(u)}}let o=0;if(e.executionScope.consumeWork(i.length,"indexed array assignment"),r){let a=G(e,t);if(a.length>0)o=Math.max(...a.map(([u])=>typeof u=="number"?u:0))+1;else{let l=e.state.env.get(t);l!==void 0&&(U(e,t,0,l),e.state.env.delete(t),o=1)}}else s();for(let a=0;a<i.length;a++)U(e,t,o+a,i[a])}async function nm(e,t,n,r,s,i,o){let a=n;if(le(e,n)){let f=Te(e,n);if(f&&f!==n){if(f.includes("["))return{continueToNext:!1,xtraceOutput:"",error:L("",`bash: \`${f}': not a valid identifier
722
- `,1)};a=f}}if(Fe(e,a)){if(t.name)return{continueToNext:!0,xtraceOutput:""};let f=ue(e,a);if(f)return{continueToNext:!1,xtraceOutput:"",error:f}}let l=e.state.associativeArrays?.has(a),u;if(l)u=await Yc(e,r);else{let f=await Zo(e,a,r);if(f.error)return{continueToNext:!1,xtraceOutput:"",error:f.error};u=String(f.index)}let c=i?Os(e,ie(e,a,u)||"",s):s;return t.name||U(e,a,u,c,l?"associative":"indexed"),{continueToNext:!0,xtraceOutput:""}}async function Yc(e,t){let n;if(t.startsWith("'")&&t.endsWith("'"))n=t.slice(1,-1);else if(t.startsWith('"')&&t.endsWith('"')){let r=t.slice(1,-1),i=new j().parseWordFromString(r,!0,!1);n=await ne(e,i)}else if(t.includes("$")){let s=new j().parseWordFromString(t,!1,!1);n=await ne(e,s)}else n=t;return n}async function Zo(e,t,n){let r=n;n.startsWith('"')&&n.endsWith('"')&&n.length>=2&&(r=n.slice(1,-1));let s;if(/^-?\d+$/.test(r))s=Number.parseInt(r,10);else{try{let i=new j,o=te(i,r);s=await X(e,o.expression,!1)}catch(i){if(i instanceof q)throw i;if(i instanceof oe){let l=`bash: line ${e.state.currentLine}: ${n}: ${i.message}
723
- `;if(i.fatal)throw new q(1,"",l);return{index:0,error:L("",l,1)}}let o=e.state.currentLine;return{index:0,error:L("",`bash: line ${o}: ${t}[${n}]: bad array subscript
724
- `,1)}}Number.isNaN(s)&&(s=0)}if(s<0){let i=G(e,t);if(i.length===0){let a=e.state.currentLine;return{index:0,error:L("",`bash: line ${a}: ${t}[${n}]: bad array subscript
725
- `,1)}}if(s=Math.max(...i.map(([a])=>typeof a=="number"?a:0))+1+s,s<0){let a=e.state.currentLine;return{index:0,error:L("",`bash: line ${a}: ${t}[${n}]: bad array subscript
726
- `,1)}}}return{index:s}}async function rm(e,t,n,r,s,i){let o="",a=n,l=null;if(le(e,n)){let f=jr(e,n,r);if(f===void 0)return{continueToNext:!1,xtraceOutput:"",error:L("",`bash: ${n}: circular name reference
721
+ `,{continueToNext:!0,xtraceOutput:o};let h=ue(e,n);if(h)return{continueToNext:!1,xtraceOutput:"",error:h}}let a=e.state.associativeArrays?.has(n),l=Ae(e,n),u=l?Le(l):void 0,c=e.state.env.get(n),f=()=>{e.state.arrays??=new Map,u?e.state.arrays.set(n,u):e.state.arrays.delete(n),c===void 0?e.state.env.delete(n):e.state.env.set(n,c)},d=im(r),p=()=>{ye(e,n),e.state.env.delete(n)};try{a&&d?await om(e,t,n,r,s,p,h=>{o+=h}):d?await am(e,n,r,s,p):await lm(e,n,r,s,p)}catch(h){throw f(),h}if(t.name){i.set(n,e.state.env.get(n));let m=`(${r.map(y=>On(y)).join(" ")})`;e.state.env.set(n,m)}return{continueToNext:!0,xtraceOutput:o}}function im(e){return e.some(t=>{if(t.parts.length>=2){let n=t.parts[0],r=t.parts[1];if(n.type!=="Glob"||!n.pattern.startsWith("["))return!1;if(n.pattern==="["&&(r.type==="DoubleQuoted"||r.type==="SingleQuoted")){if(t.parts.length<3)return!1;let s=t.parts[2];return s.type!=="Literal"?!1:s.value.startsWith("]=")||s.value.startsWith("]+=")}return r.type!=="Literal"?!1:r.value.startsWith("]")?r.value.startsWith("]=")||r.value.startsWith("]+="):n.pattern.endsWith("]")?r.value.startsWith("=")||r.value.startsWith("+="):!1}return!1})}async function om(e,t,n,r,s,i,o){let a=[];for(let l of r){if(a.length>=e.limits.maxArrayElements)throw new C(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");let u=Xs(l);if(u){let{key:c,valueParts:f,append:d}=u,p;f.length>0?(p=await ne(e,{type:"Word",parts:f}),f.every(m=>m.type==="Literal"||m.type==="TildeExpansion")&&(p=Kt(e,p))):p="",a.push({type:"keyed",key:c,value:p,append:d})}else{let c=await ne(e,l);a.push({type:"invalid",expandedValue:c})}}e.executionScope.consumeWork(a.length,"associative array assignment"),s||i();for(let l of a)if(l.type==="keyed")if(l.append){let u=ie(e,n,l.key)??"";j(e,n,l.key,Fs(e,u,l.value),"associative")}else j(e,n,l.key,l.value,"associative");else{let u=t.line??e.state.currentLine??1;o(`bash: line ${u}: ${n}: ${l.expandedValue}: must use subscript when assigning associative array
722
+ `)}}async function am(e,t,n,r,s){let i=[],o=0;for(let l of n){let u=Xs(l);if(u){if(o>=e.limits.maxArrayElements)throw new C(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");let{key:c,valueParts:f,append:d}=u,p;f.length>0?(p=await ne(e,{type:"Word",parts:f}),f.every(m=>m.type==="Literal"||m.type==="TildeExpansion")&&(p=Kt(e,p))):p="",i.push({type:"keyed",indexExpr:c,value:p,append:d}),o++}else{let c=await gt(e,l);if(c.values.length>e.limits.maxArrayElements-o)throw new C(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");i.push({type:"non-keyed",values:c.values}),o+=c.values.length}}e.executionScope.consumeWork(o,"indexed array assignment"),r||s();let a=0;for(let l of i)if(l.type==="keyed"){let u;try{let c=new G,f=te(c,l.indexExpr);u=await X(e,f.expression,!1)}catch{if(/^-?\d+$/.test(l.indexExpr))u=Number.parseInt(l.indexExpr,10);else{let c=e.state.env.get(l.indexExpr);u=c?Number.parseInt(c,10):0,Number.isNaN(u)&&(u=0)}}if(l.append){let c=ie(e,t,u)??"";j(e,t,u,Fs(e,c,l.value))}else j(e,t,u,l.value);a=u+1}else for(let u of l.values)j(e,t,a++,u)}async function lm(e,t,n,r,s){let i=[];for(let a of n){let l=await gt(e,a);for(let u of l.values){if(i.length>=e.limits.maxArrayElements)throw new C(`array element limit exceeded (${e.limits.maxArrayElements})`,"array_elements");i.push(u)}}let o=0;if(e.executionScope.consumeWork(i.length,"indexed array assignment"),r){let a=H(e,t);if(a.length>0)o=Math.max(...a.map(([u])=>typeof u=="number"?u:0))+1;else{let l=e.state.env.get(t);l!==void 0&&(j(e,t,0,l),e.state.env.delete(t),o=1)}}else s();for(let a=0;a<i.length;a++)j(e,t,o+a,i[a])}async function um(e,t,n,r,s,i,o){let a=n;if(le(e,n)){let f=Te(e,n);if(f&&f!==n){if(f.includes("["))return{continueToNext:!1,xtraceOutput:"",error:T("",`bash: \`${f}': not a valid identifier
723
+ `,1)};a=f}}if(Fe(e,a)){if(t.name)return{continueToNext:!0,xtraceOutput:""};let f=ue(e,a);if(f)return{continueToNext:!1,xtraceOutput:"",error:f}}let l=e.state.associativeArrays?.has(a),u;if(l)u=await nf(e,r);else{let f=await Xo(e,a,r);if(f.error)return{continueToNext:!1,xtraceOutput:"",error:f.error};u=String(f.index)}let c=i?Fs(e,ie(e,a,u)||"",s):s;return t.name||j(e,a,u,c,l?"associative":"indexed"),{continueToNext:!0,xtraceOutput:""}}async function nf(e,t){let n;if(t.startsWith("'")&&t.endsWith("'"))n=t.slice(1,-1);else if(t.startsWith('"')&&t.endsWith('"')){let r=t.slice(1,-1),i=new G().parseWordFromString(r,!0,!1);n=await ne(e,i)}else if(t.includes("$")){let s=new G().parseWordFromString(t,!1,!1);n=await ne(e,s)}else n=t;return n}async function Xo(e,t,n){let r=n;n.startsWith('"')&&n.endsWith('"')&&n.length>=2&&(r=n.slice(1,-1));let s;if(/^-?\d+$/.test(r))s=Number.parseInt(r,10);else{try{let i=new G,o=te(i,r);s=await X(e,o.expression,!1)}catch(i){if(i instanceof U)throw i;if(i instanceof oe){let l=`bash: line ${e.state.currentLine}: ${n}: ${i.message}
724
+ `;if(i.fatal)throw new U(1,"",l);return{index:0,error:T("",l,1)}}let o=e.state.currentLine;return{index:0,error:T("",`bash: line ${o}: ${t}[${n}]: bad array subscript
725
+ `,1)}}Number.isNaN(s)&&(s=0)}if(s<0){let i=H(e,t);if(i.length===0){let a=e.state.currentLine;return{index:0,error:T("",`bash: line ${a}: ${t}[${n}]: bad array subscript
726
+ `,1)}}if(s=Math.max(...i.map(([a])=>typeof a=="number"?a:0))+1+s,s<0){let a=e.state.currentLine;return{index:0,error:T("",`bash: line ${a}: ${t}[${n}]: bad array subscript
727
+ `,1)}}}return{index:s}}async function cm(e,t,n,r,s,i){let o="",a=n,l=null;if(le(e,n)){let f=Qr(e,n,r);if(f===void 0)return{continueToNext:!1,xtraceOutput:"",error:T("",`bash: ${n}: circular name reference
727
728
  `,1)};if(f===null)return{continueToNext:!0,xtraceOutput:""};a=f;let d=a.match(/^([a-zA-Z_][a-zA-Z0-9_]*)\[(.+)\]$/);d&&(l={arrayName:d[1],subscriptExpr:d[2]},a=d[1])}if(Fe(e,a)){if(t.name)return o+=`bash: ${a}: readonly variable
728
- `,{continueToNext:!0,xtraceOutput:o};let f=ue(e,a);if(f)return{continueToNext:!1,xtraceOutput:"",error:f}}let u;if(yr(e,a))try{let f=new j;if(s){let p=`(${e.state.env.get(a)||"0"}) + (${r})`,h=te(f,p);u=String(await X(e,h.expression))}else{let d=te(f,r);u=String(await X(e,d.expression))}}catch{u="0"}else{let f=ht(e,a)?ie(e,a,0):e.state.env.get(a);u=s?Os(e,f||"",r):r}u=Gn(e,a,u),o+=await Kc(e,a,u);let c;return l?c=await sm(e,l):ht(e,a)&&(c="0"),t.name?c===void 0&&(i.set(a,e.state.env.get(a)),e.state.env.set(a,u)):(c===void 0?e.state.env.set(a,u):U(e,a,c,u),e.state.options.allexport&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(a)),e.state.tempEnvBindings?.some(f=>f.has(a))&&(e.state.mutatedTempEnvVars=e.state.mutatedTempEnvVars||new Set,e.state.mutatedTempEnvVars.add(a))),{continueToNext:!1,xtraceOutput:o}}async function sm(e,t){let{arrayName:n,subscriptExpr:r}=t;if(e.state.associativeArrays?.has(n))return Yc(e,r);let i;if(/^-?\d+$/.test(r))i=Number.parseInt(r,10);else{try{let o=new j,a=te(o,r);i=await X(e,a.expression,!1)}catch{let o=e.state.env.get(r);i=o?Number.parseInt(o,10):0}Number.isNaN(i)&&(i=0)}if(i<0){let o=G(e,n);o.length>0&&(i=Math.max(...o.map(l=>l[0]))+1+i)}return String(i)}async function tf(e,t,n,r){let s=!1,i=!1,o=!1,a=!1,l=!1,u=[];for(let m of t)if(m.startsWith("-")&&m.length>1)for(let E of m.slice(1))E==="t"?s=!0:E==="p"?i=!0:E==="P"?o=!0:E==="a"?a=!0:E==="f"&&(l=!0);else u.push(m);let c="",f="",d=0,p=!1,h=!1;for(let m of u){let E=!1;if(o){if(a){let x=await r(m);if(x.length>0){for(let A of x)c+=`${A}
729
- `;p=!0,E=!0}}else{let x=await n(m);x&&(c+=`${x}
730
- `,p=!0,E=!0)}E||(h=!0);continue}let S=!l&&e.state.functions.has(m);if(a&&S){if(!i)if(s)c+=`function
731
- `;else{let x=e.state.functions.get(m),A=x?Jc(m,x):`${m} is a function
732
- `;c+=A}E=!0}let y=e.state.env.get(`BASH_ALIAS_${m}`);if(y!==void 0&&(a||!E)&&(i||(s?c+=`alias
733
- `:c+=`${m} is aliased to \`${y}'
734
- `),E=!0,!a)||Qi.has(m)&&(a||!E)&&(i||(s?c+=`keyword
729
+ `,{continueToNext:!0,xtraceOutput:o};let f=ue(e,a);if(f)return{continueToNext:!1,xtraceOutput:"",error:f}}let u;if(wr(e,a))try{let f=new G;if(s){let p=`(${e.state.env.get(a)||"0"}) + (${r})`,h=te(f,p);u=String(await X(e,h.expression))}else{let d=te(f,r);u=String(await X(e,d.expression))}}catch{u="0"}else{let f=pt(e,a)?ie(e,a,0):e.state.env.get(a);u=s?Fs(e,f||"",r):r}u=Hn(e,a,u),o+=await ef(e,a,u);let c;return l?c=await fm(e,l):pt(e,a)&&(c="0"),t.name?c===void 0&&(i.set(a,e.state.env.get(a)),e.state.env.set(a,u)):(c===void 0?e.state.env.set(a,u):j(e,a,c,u),e.state.options.allexport&&(e.state.exportedVars=e.state.exportedVars||new Set,e.state.exportedVars.add(a)),e.state.tempEnvBindings?.some(f=>f.has(a))&&(e.state.mutatedTempEnvVars=e.state.mutatedTempEnvVars||new Set,e.state.mutatedTempEnvVars.add(a))),{continueToNext:!1,xtraceOutput:o}}async function fm(e,t){let{arrayName:n,subscriptExpr:r}=t;if(e.state.associativeArrays?.has(n))return nf(e,r);let i;if(/^-?\d+$/.test(r))i=Number.parseInt(r,10);else{try{let o=new G,a=te(o,r);i=await X(e,a.expression,!1)}catch{let o=e.state.env.get(r);i=o?Number.parseInt(o,10):0}Number.isNaN(i)&&(i=0)}if(i<0){let o=H(e,n);o.length>0&&(i=Math.max(...o.map(l=>l[0]))+1+i)}return String(i)}async function of(e,t,n,r){let s=!1,i=!1,o=!1,a=!1,l=!1,u=[];for(let m of t)if(m.startsWith("-")&&m.length>1)for(let y of m.slice(1))y==="t"?s=!0:y==="p"?i=!0:y==="P"?o=!0:y==="a"?a=!0:y==="f"&&(l=!0);else u.push(m);let c="",f="",d=0,p=!1,h=!1;for(let m of u){let y=!1;if(o){if(a){let A=await r(m);if(A.length>0){for(let x of A)c+=`${x}
730
+ `;p=!0,y=!0}}else{let A=await n(m);A&&(c+=`${A}
731
+ `,p=!0,y=!0)}y||(h=!0);continue}let b=!l&&e.state.functions.has(m);if(a&&b){if(!i)if(s)c+=`function
732
+ `;else{let A=e.state.functions.get(m),x=A?rf(m,A):`${m} is a function
733
+ `;c+=x}y=!0}let w=e.state.env.get(`BASH_ALIAS_${m}`);if(w!==void 0&&(a||!y)&&(i||(s?c+=`alias
734
+ `:c+=`${m} is aliased to \`${w}'
735
+ `),y=!0,!a)||Xi.has(m)&&(a||!y)&&(i||(s?c+=`keyword
735
736
  `:c+=`${m} is a shell keyword
736
- `),E=!0,!a))continue;if(!a&&S&&!E){if(!i)if(s)c+=`function
737
- `;else{let x=e.state.functions.get(m),A=x?Jc(m,x):`${m} is a function
738
- `;c+=A}E=!0;continue}if(!(Wn.has(m)&&(a||!E)&&(i||(s?c+=`builtin
737
+ `),y=!0,!a))continue;if(!a&&b&&!y){if(!i)if(s)c+=`function
738
+ `;else{let A=e.state.functions.get(m),x=A?rf(m,A):`${m} is a function
739
+ `;c+=x}y=!0;continue}if(!(Vn.has(m)&&(a||!y)&&(i||(s?c+=`builtin
739
740
  `:c+=`${m} is a shell builtin
740
- `),E=!0,!a))){if(a){let x=await r(m);for(let A of x)i?c+=`${A}
741
- `:s?c+=`file
742
- `:c+=`${m} is ${A}
743
- `,p=!0,E=!0}else if(!E){let x=await n(m);x&&(i?c+=`${x}
741
+ `),y=!0,!a))){if(a){let A=await r(m);for(let x of A)i?c+=`${x}
744
742
  `:s?c+=`file
745
743
  `:c+=`${m} is ${x}
746
- `,p=!0,E=!0)}if(!E&&(h=!0,!s&&!i)){let x=!0;if(m.includes("/")){let A=e.fs.resolvePath(e.state.cwd,m);await e.fs.exists(A)&&(x=!1)}x&&(f+=`bash: type: ${m}: not found
747
- `)}}}return i?d=h&&!p?1:0:d=h?1:0,L(c,f,d)}function Jc(e,t){let n;return t.body.type==="Group"?n=t.body.body.map(s=>Er(s)).join("; "):n=Er(t.body),`${e} is a function
744
+ `,p=!0,y=!0}else if(!y){let A=await n(m);A&&(i?c+=`${A}
745
+ `:s?c+=`file
746
+ `:c+=`${m} is ${A}
747
+ `,p=!0,y=!0)}if(!y&&(h=!0,!s&&!i)){let A=!0;if(m.includes("/")){let x=e.fs.resolvePath(e.state.cwd,m);await e.fs.exists(x)&&(A=!1)}A&&(f+=`bash: type: ${m}: not found
748
+ `)}}}return i?d=h&&!p?1:0:d=h?1:0,T(c,f,d)}function rf(e,t){let n;return t.body.type==="Group"?n=t.body.body.map(s=>Sr(s)).join("; "):n=Sr(t.body),`${e} is a function
748
749
  ${e} ()
749
750
  {
750
751
  ${n}
751
752
  }
752
- `}function Er(e){if(Array.isArray(e))return e.map(t=>Er(t)).join("; ");if(e.type==="Statement"){let t=[];for(let n=0;n<e.pipelines.length;n++){let r=e.pipelines[n];t.push(im(r)),e.operators[n]&&t.push(e.operators[n])}return t.join(" ")}if(e.type==="SimpleCommand"){let t=e,n=[];t.name&&n.push(ef(t.name));for(let r of t.args)n.push(ef(r));return n.join(" ")}return e.type==="Group"?`{ ${e.body.map(r=>Er(r)).join("; ")}; }`:"..."}function ef(e){return e.parts.map(nf).join("")}function nf(e){switch(e.type){case"Literal":return e.value;case"Escaped":return`\\${e.value}`;case"SingleQuoted":return`'${e.value}'`;case"DoubleQuoted":return`"${e.parts.map(nf).join("")}"`;default:return Se(T.word([e]))}}function im(e){let t=e.commands.map(n=>Er(n));return(e.negated?"! ":"")+t.join(" | ")}async function rf(e,t,n,r){let s="",i="",o=0;for(let a of t){if(!a){o=1;continue}let l=e.state.env.get(`BASH_ALIAS_${a}`);if(l!==void 0)r?s+=`${a} is an alias for "${l}"
753
+ `}function Sr(e){if(Array.isArray(e))return e.map(t=>Sr(t)).join("; ");if(e.type==="Statement"){let t=[];for(let n=0;n<e.pipelines.length;n++){let r=e.pipelines[n];t.push(dm(r)),e.operators[n]&&t.push(e.operators[n])}return t.join(" ")}if(e.type==="SimpleCommand"){let t=e,n=[];t.name&&n.push(sf(t.name));for(let r of t.args)n.push(sf(r));return n.join(" ")}return e.type==="Group"?`{ ${e.body.map(r=>Sr(r)).join("; ")}; }`:"..."}function sf(e){return e.parts.map(af).join("")}function af(e){switch(e.type){case"Literal":return e.value;case"Escaped":return`\\${e.value}`;case"SingleQuoted":return`'${e.value}'`;case"DoubleQuoted":return`"${e.parts.map(af).join("")}"`;default:return be(F.word([e]))}}function dm(e){let t=e.commands.map(n=>Sr(n));return(e.negated?"! ":"")+t.join(" | ")}async function lf(e,t,n,r){let s="",i="",o=0;for(let a of t){if(!a){o=1;continue}let l=e.state.env.get(`BASH_ALIAS_${a}`);if(l!==void 0)r?s+=`${a} is an alias for "${l}"
753
754
  `:s+=`alias ${a}='${l}'
754
- `;else if(Qi.has(a))r?s+=`${a} is a shell keyword
755
+ `;else if(Xi.has(a))r?s+=`${a} is a shell keyword
755
756
  `:s+=`${a}
756
- `;else if(Wn.has(a))r?s+=`${a} is a shell builtin
757
+ `;else if(Vn.has(a))r?s+=`${a} is a shell builtin
757
758
  `:s+=`${a}
758
759
  `;else if(e.state.functions.has(a))r?s+=`${a} is a function
759
760
  `:s+=`${a}
@@ -763,51 +764,52 @@ ${e} ()
763
764
  `),o=1)}else if(e.commands.has(a)){let c=(e.state.env.get("PATH")??"/usr/bin:/bin").split(":"),f=null;for(let d of c){if(!d)continue;let p=`${d}/${a}`;try{let h=await e.fs.stat(p);if(!h.isDirectory&&(h.mode&73)!==0){f=p;break}}catch{}}f||(f=`/usr/bin/${a}`),r?s+=`${a} is ${f}
764
765
  `:s+=`${f}
765
766
  `}else r&&(i+=`${a}: not found
766
- `),o=1}return L(s,i,o)}async function sf(e,t){if(t.includes("/")){let s=e.fs.resolvePath(e.state.cwd,t);if(await e.fs.exists(s)){try{let i=await e.fs.stat(s);if(i.isDirectory||!((i.mode&73)!==0))return null}catch{return null}return t}return null}let r=(e.state.env.get("PATH")??"/usr/bin:/bin").split(":");for(let s of r){if(!s)continue;let o=`${s.startsWith("/")?s:e.fs.resolvePath(e.state.cwd,s)}/${t}`;if(await e.fs.exists(o)){try{let a=await e.fs.stat(o);if(a.isDirectory||(a.mode&73)===0)continue}catch{continue}return`${s}/${t}`}}if(e.commands.has(t)){for(let s of r)if(s==="/usr/bin"||s==="/bin")return`${s}/${t}`;return`/usr/bin/${t}`}return null}function of(e,t){let n=!0,r=e.signal?new AbortController:void 0,s=new WeakMap,i=()=>{if(!n)throw new We("",`bash: ${t} used its context after cancellation
767
- `)},o=f=>{if(f===null||typeof f!="object"&&typeof f!="function")return f;let d=s.get(f);if(d!==void 0)return d;if(typeof f=="object"&&Ea(f))return f;if(f instanceof Uint8Array){let E=new Uint8Array(f);return s.set(f,E),E}if(f instanceof ArrayBuffer){let E=f.slice(0);return s.set(f,E),E}if(f instanceof Promise){let E=f.then(S=>(i(),o(S)));return s.set(f,E),E}if(typeof f=="function"){let E=function(...S){return i(),o(Reflect.apply(f,this,S))};return s.set(f,E),E}let p=Object.getPrototypeOf(f);if(Array.isArray(f)||p===Object.prototype||p===null){let E=Array.isArray(f)?[]:Object.create(p);s.set(f,E);let S=Object.getOwnPropertyDescriptors(f);for(let y of Object.values(S)){if("value"in y){let g=y.value;y.value=typeof g=="function"?(...b)=>(i(),o(Reflect.apply(g,f,b))):o(g)}if(y.get){let g=y.get;y.get=()=>(i(),o(Reflect.apply(g,f,[])))}if(y.set){let g=y.set;y.set=b=>{i(),Reflect.apply(g,f,[b])}}}return Object.defineProperties(E,S),E}let h=new Map,m=new ca(f,{get(E,S){if(i(),S==="constructor"||S==="prototype"||S==="__proto__")throw new Error(`${t}: unsafe context property access`);let y=Reflect.get(E,S,E);if(typeof y!="function")return o(y);if(h.has(S))return h.get(S);let g=(...b)=>(i(),o(Reflect.apply(y,E,b)));return h.set(S,g),g},set(E,S,y){if(i(),S==="constructor"||S==="prototype"||S==="__proto__")throw new Error(`${t}: unsafe context property access`);return Reflect.set(E,S,y,E)}});return s.set(f,m),m},a=f=>o(f),l=f=>f&&((...d)=>(i(),o(f(...d)))),u=f=>({value:f,enumerable:!0,configurable:!0,writable:!0}),c=Object.getOwnPropertyDescriptors(e);return Object.assign(c,{fs:u(a(e.fs)),env:u(a(e.env)),limits:u(Object.freeze({...e.limits})),exportedEnv:u(e.exportedEnv?Object.freeze({...e.exportedEnv}):void 0),executionScope:u(e.executionScope?a(e.executionScope):void 0),fileDescriptors:u(e.fileDescriptors?a(e.fileDescriptors):void 0),coverage:u(e.coverage?a(e.coverage):void 0),assignShellVariable:u(l(e.assignShellVariable)),exec:u(l(e.exec)),origCommand:u(l(e.origCommand)),execWithInheritedStdin:u(l(e.execWithInheritedStdin)),fetch:u(l(e.fetch)),getRegisteredCommands:u(l(e.getRegisteredCommands)),sleep:u(l(e.sleep)),trace:u(l(e.trace)),invokeTool:u(l(e.invokeTool)),signal:u(r?.signal)}),{context:Object.defineProperties(Object.create(Object.getPrototypeOf(e)),c),revoke(){n=!1,r?.signal.aborted||r?.abort(new We("",`bash: ${t} context revoked
768
- `))}}}async function om(e,t,n,r,s,i){let o=s.remainingTimeMs()??t.limits.maxExecutionTimeMs,a=t.limits.maxExtensionCleanupTimeMs,l,u,c,d=Promise.resolve().then(e).then(h=>({kind:"result",result:h}),h=>({kind:"error",error:h})),p=new Promise(h=>{let m=()=>{n(),h({kind:"abort"})};u=m,i?.addEventListener("abort",m,{once:!0}),i?.aborted&&m(),l=Kn(()=>{n(),h({kind:"deadline"})},o)});try{let h=await Promise.race([d,p]);if(h.kind==="result")return h.result;if(h.kind==="error")throw h.error;n();let m=await Promise.race([d.then(()=>!0),new Promise(S=>{c=Kn(()=>S(!1),a)})]),E=h.kind==="deadline"?new We("",`bash: ${r} exceeded its execution deadline
767
+ `),o=1}return T(s,i,o)}async function uf(e,t){if(t.includes("/")){let s=e.fs.resolvePath(e.state.cwd,t);if(await e.fs.exists(s)){try{let i=await e.fs.stat(s);if(i.isDirectory||!((i.mode&73)!==0))return null}catch{return null}return t}return null}let r=(e.state.env.get("PATH")??"/usr/bin:/bin").split(":");for(let s of r){if(!s)continue;let o=`${s.startsWith("/")?s:e.fs.resolvePath(e.state.cwd,s)}/${t}`;if(await e.fs.exists(o)){try{let a=await e.fs.stat(o);if(a.isDirectory||(a.mode&73)===0)continue}catch{continue}return`${s}/${t}`}}if(e.commands.has(t)){for(let s of r)if(s==="/usr/bin"||s==="/bin")return`${s}/${t}`;return`/usr/bin/${t}`}return null}function cf(e,t){let n=!0,r=e.signal?new AbortController:void 0,s=new WeakMap,i=()=>{if(!n)throw new We("",`bash: ${t} used its context after cancellation
768
+ `)},o=f=>{if(f===null||typeof f!="object"&&typeof f!="function")return f;let d=s.get(f);if(d!==void 0)return d;if(typeof f=="object"&&va(f))return f;if(f instanceof Uint8Array){let y=new Uint8Array(f);return s.set(f,y),y}if(f instanceof ArrayBuffer){let y=f.slice(0);return s.set(f,y),y}if(f instanceof Promise){let y=f.then(b=>(i(),o(b)));return s.set(f,y),y}if(typeof f=="function"){let y=function(...b){return i(),o(Reflect.apply(f,this,b))};return s.set(f,y),y}let p=Object.getPrototypeOf(f);if(Array.isArray(f)||p===Object.prototype||p===null){let y=Array.isArray(f)?[]:Object.create(p);s.set(f,y);let b=Object.getOwnPropertyDescriptors(f);for(let w of Object.values(b)){if("value"in w){let E=w.value;w.value=typeof E=="function"?(...S)=>(i(),o(Reflect.apply(E,f,S))):o(E)}if(w.get){let E=w.get;w.get=()=>(i(),o(Reflect.apply(E,f,[])))}if(w.set){let E=w.set;w.set=S=>{i(),Reflect.apply(E,f,[S])}}}return Object.defineProperties(y,b),y}let h=new Map,m=new ha(f,{get(y,b){if(i(),b==="constructor"||b==="prototype"||b==="__proto__")throw new Error(`${t}: unsafe context property access`);let w=Reflect.get(y,b,y);if(typeof w!="function")return o(w);if(h.has(b))return h.get(b);let E=(...S)=>(i(),o(Reflect.apply(w,y,S)));return h.set(b,E),E},set(y,b,w){if(i(),b==="constructor"||b==="prototype"||b==="__proto__")throw new Error(`${t}: unsafe context property access`);return Reflect.set(y,b,w,y)}});return s.set(f,m),m},a=f=>o(f),l=f=>f&&((...d)=>(i(),o(f(...d)))),u=f=>({value:f,enumerable:!0,configurable:!0,writable:!0}),c=Object.getOwnPropertyDescriptors(e);return Object.assign(c,{fs:u(a(e.fs)),env:u(a(e.env)),limits:u(Object.freeze({...e.limits})),exportedEnv:u(e.exportedEnv?Object.freeze({...e.exportedEnv}):void 0),executionScope:u(e.executionScope?a(e.executionScope):void 0),fileDescriptors:u(e.fileDescriptors?a(e.fileDescriptors):void 0),coverage:u(e.coverage?a(e.coverage):void 0),assignShellVariable:u(l(e.assignShellVariable)),exec:u(l(e.exec)),origCommand:u(l(e.origCommand)),execWithInheritedStdin:u(l(e.execWithInheritedStdin)),fetch:u(l(e.fetch)),getRegisteredCommands:u(l(e.getRegisteredCommands)),sleep:u(l(e.sleep)),trace:u(l(e.trace)),invokeTool:u(l(e.invokeTool)),signal:u(r?.signal)}),{context:Object.defineProperties(Object.create(Object.getPrototypeOf(e)),c),revoke(){n=!1,r?.signal.aborted||r?.abort(new We("",`bash: ${t} context revoked
769
+ `))}}}async function pm(e,t,n,r,s,i){let o=s.remainingTimeMs()??t.limits.maxExecutionTimeMs,a=t.limits.maxExtensionCleanupTimeMs,l,u,c,d=Promise.resolve().then(e).then(h=>({kind:"result",result:h}),h=>({kind:"error",error:h})),p=new Promise(h=>{let m=()=>{n(),h({kind:"abort"})};u=m,i?.addEventListener("abort",m,{once:!0}),i?.aborted&&m(),l=Xn(()=>{n(),h({kind:"deadline"})},o)});try{let h=await Promise.race([d,p]);if(h.kind==="result")return h.result;if(h.kind==="error")throw h.error;n();let m=await Promise.race([d.then(()=>!0),new Promise(b=>{c=Xn(()=>b(!1),a)})]),y=h.kind==="deadline"?new We("",`bash: ${r} exceeded its execution deadline
769
770
  `):new We("",`bash: execution aborted
770
- `);throw m||s.poisonAfterAbort(E),E}finally{n(),Xn(l),Xn(c),u&&i?.removeEventListener("abort",u)}}async function af(e,t,n,r,s,i,o,a,l=!1){let{ctx:u,runCommand:c}=e;if(u.coverage&&Wn.has(t)&&u.coverage.hit(`bash:builtin:${t}`),t==="export")return Do(u,n);if(t==="unset")return jo(u,n);if(t==="exit")return Ro(u,n);if(t==="local")return Lo(u,n);if(t==="set")return Vo(u,n);if(t==="break")return Vi(u,n);if(t==="continue")return wo(u,n);if(t==="return")return Mo(u,n);if(t==="eval"&&u.state.options.posix)return Ps(u,n,s,l);if(t==="shift")return zo(u,n);if(t==="getopts")return Cs(u,n);if(t==="compgen")return po(u,n);if(t==="complete")return yo(u,n);if(t==="compopt")return go(u,n);if(t==="pushd")return await Po(u,n);if(t==="popd")return Co(u,n);if(t==="dirs")return No(u,n);if(t==="source"||t===".")return qo(u,n);if(t==="read")return Fo(u,n,s,a);if(t==="mapfile"||t==="readarray")return To(u,n,s);if(t==="declare"||t==="typeset")return xo(u,n);if(t==="readonly")return $o(u,n);if(!i){let f=u.state.functions.get(t);if(f)return $s(u,f,n,s,void 0,l)}if(t==="__just_bash_tee_restore"){if(n.length===0||n.length>u.limits.maxArrayElements)return _(`bash: invalid internal pipeline status restore
771
- `,2);let f=[];for(let h of n){if(!/^(?:0|[1-9][0-9]{0,2})$/.test(h))return _(`bash: invalid internal pipeline status restore
772
- `,2);let m=Number(h);if(!Number.isSafeInteger(m)||m>255)return _(`bash: invalid internal pipeline status restore
773
- `,2);f.push(m)}let d=f[f.length-1]??0,p=[...f].reverse().find(h=>h!==0);return{stdout:"",stderr:"",exitCode:u.state.options.pipefail&&p!==void 0?p:d,internalPipeStatusOverride:f}}if(t==="eval")return Ps(u,n,s,l);if(t==="cd")return await zi(u,n);if(t===":"||t==="true")return J;if(t==="false")return ge(!1);if(t==="let")return _o(u,n);if(t==="command")return am(e,n,s,l);if(t==="builtin")return lm(e,n,s,l);if(t==="shopt")return jc(u,n);if(t==="exec"){if(n.length===0)return J;let[f,...d]=n;return{...await c(f,d,[],s,!1,!1,-1,l),internalProducerOmitsShellPrefix:!0}}if(t==="wait")return J;if(t==="type")return await tf(u,n,f=>sf(u,f),f=>Is(u,f));if(t==="hash")return Io(u,n);if(t==="help")return Oo(u,n);if(t==="["||t==="test"){let f=n;if(t==="["){if(n[n.length-1]!=="]")return _("[: missing `]'\n",2);f=n.slice(0,-1)}return dr(u,f)}return null}async function am(e,t,n,r=!1){let{ctx:s,runCommand:i}=e;if(t.length===0)return J;let o=!1,a=!1,l=!1,u=t;for(;u.length>0&&u[0].startsWith("-");){let d=u[0];if(d==="--"){u=u.slice(1);break}for(let p of d.slice(1))p==="p"?o=!0:p==="V"?a=!0:p==="v"&&(l=!0);u=u.slice(1)}if(u.length===0)return J;if(l||a)return await rf(s,u,l,a);let[c,...f]=u;return i(c,f,[],n,!0,o,-1,r)}async function lm(e,t,n,r=!1){let{runCommand:s}=e;if(t.length===0)return J;let i=t;if(i[0]==="--"&&(i=i.slice(1),i.length===0))return J;let o=i[0];if(o!=="__just_bash_tee_restore"&&!Wn.has(o))return _(`bash: builtin: ${o}: not a shell builtin
774
- `);let[,...a]=i;return s(o,a,[],n,!0,!1,-1,r)}async function lf(e,t,n,r,s){let{ctx:i,buildExportedEnv:o,executeUserScript:a}=e,u=await Gc(i,t,s?"/usr/bin:/bin":void 0);if(!u)return Yu(t)?_(`bash: ${t}: command not available in browser environments. Exclude '${t}' from your commands or use the Node.js bundle.
775
- `,127):_(`bash: ${t}: command not found
776
- `,127);if("error"in u)return u.error==="permission_denied"?_(`bash: ${t}: Permission denied
777
- `,126):_(`bash: ${t}: No such file or directory
778
- `,127);if("script"in u)return t.includes("/")||(i.state.hashTable||(i.state.hashTable=new Map),i.state.hashTable.set(t,u.path)),await a(u.path,n,r);let{cmd:c,path:f}=u;t.includes("/")||(i.state.hashTable||(i.state.hashTable=new Map),i.state.hashTable.set(t,f));let d=r||i.state.groupStdin||"",p=!1,h=o();i.state.fileDescriptors??=new Map;let m={fs:i.fs,fsIdentity:qs(i.fs),cwd:i.state.cwd,env:i.state.env,assignShellVariable:async(v,x,A)=>{if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(v))throw new Error(`${v}: not a valid identifier`);let k=A===void 0?v:`${v}[${A}]`,N=jr(i,v,x);if(N===void 0)throw new Error(`${v}: circular name reference`);if(N===null)return;let $=N.match(/^([a-zA-Z_][a-zA-Z0-9_]*)(?:\[(.*)\])?$/);if(!$)throw new Error(`${k}: not a valid identifier`);let C=$[1],D=$[2]??A;if(Fe(i,v)||Fe(i,C))throw new Error(`${C}: readonly variable`);if(D===void 0)i.state.env.set(C,x);else{let B=i.state.associativeArrays?.has(C)?"associative":"indexed";if(B==="associative"){U(i,C,D,x,B);return}let H=await Zo(i,C,D);if(H.error)throw new q(H.error.exitCode,H.error.stdout,H.error.stderr);U(i,C,H.index,x,B)}},exportedEnv:h,get stdin(){return p=!0,d},limits:i.limits,executionScope:c.internalIsExtension?xa(i.executionScope):i.executionScope,exec:(v,x)=>i.execFn(v,x,!1),execWithInheritedStdin:(v,x)=>i.execFn(v,{...x,stdin:d,stdinKind:"bytes"},!0),fetch:i.fetch,getRegisteredCommands:()=>Array.from(i.commands.keys()),sleep:i.sleep,trace:i.trace,fileDescriptors:i.state.fileDescriptors,xpgEcho:i.state.shoptOptions.xpg_echo,coverage:i.coverage,signal:i.state.signal,requireDefenseContext:i.requireDefenseContext,jsBootstrapCode:i.jsBootstrapCode,invokeTool:i.invokeTool},E=c.internalOriginalCommand,S=()=>{};if(E){let v=Object.getOwnPropertyDescriptors(m);v.executionScope={value:i.executionScope,enumerable:!0,configurable:!0,writable:!0};let x=Object.defineProperties(Object.create(Object.getPrototypeOf(m)),v),A=of(x,E.name),k=Ho(A.context,E.name);S=A.revoke,m.origCommand=N=>{let $=()=>E.execute(N,k);return E.trusted?_e.runTrustedAsync($):_e.runUntrustedAsync($)}}let y=of(m,t),g=Ho(y.context,t),b=()=>{y.revoke(),S()};try{let v=()=>ua(i.requireDefenseContext,"command",`${t} execution`,()=>c.execute(n,g)),x=()=>om(v,g,b,t,i.executionScope,i.state.signal),A=c.trusted?await _e.runTrustedAsync(x):await x();return{...A,internalStdinConsumed:A.internalStdinConsumed??(p?r.length:0)}}catch(v){if(v instanceof P||v instanceof We||v instanceof An)throw v;return _(`${t}: ${Ve(Rt(v))}
779
- `)}}async function Qo(e,t){let n=e.state.inCondition;e.state.inCondition=!0;let r=new Bt(e.executionScope,"condition"),s=0;try{for(let i of t){let o=await e.executeStatement(i);r.appendResult(o),s=o.exitCode}}catch(i){throw r.prependTo(i),i}finally{e.state.inCondition=n}return r.build(s)}var _s=0;function Hn(e,t){return e.state.lastExitCode=t,e.state.env.set("?",String(t)),t}function br(e,t,n,r){if(e instanceof Ge)return t+=e.stdout,n+=e.stderr,e.levels>1&&r>1?(e.levels--,e.stdout=t,e.stderr=n,{action:"rethrow",stdout:t,stderr:n,error:e}):{action:"break",stdout:t,stderr:n,exitCode:_s};if(e instanceof He)return t+=e.stdout,n+=e.stderr,e.levels>1&&r>1?(e.levels--,e.stdout=t,e.stderr=n,{action:"rethrow",stdout:t,stderr:n,error:e}):{action:"continue",stdout:t,stderr:n,exitCode:_s};if(e instanceof Ie||e instanceof Me||e instanceof q||e instanceof P)return e.prependOutput(t,n),{action:"rethrow",stdout:t,stderr:n,error:e};let s=Rt(e);return{action:"error",stdout:t,stderr:`${n}${s}
780
- `,exitCode:1}}function uf(e,t){return e!==void 0?{owns:!0,stdin:e}:t!==""?{owns:!0,stdin:t}:{owns:!1}}var an=class{ctx;stdoutChunks=[];stderrChunks=[];totalBytes=0;constructor(t){this.ctx=t}append(t,n){let r=F(t)+F(n);r>this.ctx.limits.maxOutputSize-this.totalBytes&&Yt(`total output size exceeded (>${this.ctx.limits.maxOutputSize} bytes), increase executionLimits.maxOutputSize`,"output_size"),t&&this.stdoutChunks.push(t),n&&this.stderrChunks.push(n),this.totalBytes+=r}appendUnaccounted(t,n){this.ctx.executionScope.appendOutput("stdout",t,"control-flow"),this.ctx.executionScope.appendOutput("stderr",n,"control-flow"),this.append(t,n)}replace(t,n){this.stdoutChunks=[],this.stderrChunks=[],this.totalBytes=0,this.append(t,n)}get stdout(){return this.stdoutChunks.join("")}get stderr(){return this.stderrChunks.join("")}build(t){let n=this.stdout,r=this.stderr;return{stdout:n,stderr:r,exitCode:t,internalOutputAccounting:{stdout:F(n),stderr:F(r)}}}};async function Ko(e,t,n){let r=0;try{for(let s of t){let i=await e.executeStatement(s);n.append(i.stdout,i.stderr),r=i.exitCode}}catch(s){if(Pr(s)||s instanceof Me||s instanceof q||s instanceof P||s instanceof Tt)throw s.prependOutput(n.stdout,n.stderr),s;return n.appendUnaccounted("",`${Rt(s)}
781
- `),n.build(1)}return n.build(r)}async function cf(e,t){return et(e,t.redirections,"",()=>um(e,t))}async function um(e,t){let n=new an(e);for(let r of t.clauses){let s=await Qo(e,r.condition);if(n.append(s.stdout,s.stderr),s.exitCode===0)return Ko(e,r.body,n)}return t.elseBody?Ko(e,t.elseBody,n):n.build(0)}async function ff(e,t){return et(e,t.redirections,"",()=>cm(e,t))}async function cm(e,t){let n=new an(e),r=0,s=0;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t.variable))return _(`bash: \`${t.variable}': not a valid identifier
782
- `);let i=[];if(t.words===null)i=(e.state.env.get("@")||"").split(" ").filter(Boolean);else if(t.words.length===0)i=[];else try{for(let o of t.words){let a=await wt(e,o);Ne(i,a.values,e.limits.maxArrayElements,"for-loop expansion")}}catch(o){if(o instanceof Lt)return{stdout:"",stderr:o.stderr,exitCode:1};throw o}e.state.loopDepth++;try{for(let o of i){s++,s>e.limits.maxLoopIterations&&Yt(`for loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",n.stdout,n.stderr),e.state.env.set(t.variable,o);try{for(let a of t.body){let l=await e.executeStatement(a);n.append(l.stdout,l.stderr),r=l.exitCode}}catch(a){let l=br(a,n.stdout,n.stderr,e.state.loopDepth);if(n.replace(l.stdout,l.stderr),l.exitCode!==void 0&&(r=Hn(e,l.exitCode)),l.action==="break")break;if(l.action==="continue")continue;if(l.action==="error")return n.build(l.exitCode??1);throw l.error}}}finally{e.state.loopDepth--}return n.build(r)}async function df(e,t){return et(e,t.redirections,"",()=>fm(e,t))}async function fm(e,t){let n=t.line;n!==void 0&&(e.state.currentLine=n);let r=new an(e),s=0,i=0;t.init&&await X(e,t.init.expression),e.state.loopDepth++;try{for(;i++,i>e.limits.maxLoopIterations&&Yt(`for loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",r.stdout,r.stderr),!(t.condition&&(n!==void 0&&(e.state.currentLine=n),await X(e,t.condition.expression)===0));){try{for(let o of t.body){let a=await e.executeStatement(o);r.append(a.stdout,a.stderr),s=a.exitCode}}catch(o){let a=br(o,r.stdout,r.stderr,e.state.loopDepth);if(r.replace(a.stdout,a.stderr),a.exitCode!==void 0&&(s=Hn(e,a.exitCode)),a.action==="break")break;if(a.action==="continue"){t.update&&await X(e,t.update.expression);continue}if(a.action==="error")return r.build(a.exitCode??1);throw a.error}t.update&&await X(e,t.update.expression)}}finally{e.state.loopDepth--}return r.build(s)}async function pf(e,t,n=""){return et(e,t.redirections,n,r=>dm(e,t,n,r))}async function dm(e,t,n,r){let s=new an(e),i=0,o=0,a=uf(r.stdin,n),l=e.state.groupStdin;a.owns&&(e.state.groupStdin=a.stdin),e.state.loopDepth++;try{for(;;){o++,o>e.limits.maxLoopIterations&&Yt(`while loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",s.stdout,s.stderr);let u=0,c=!1,f=!1,d=e.state.inCondition;e.state.inCondition=!0;try{for(let p of t.condition){let h=await e.executeStatement(p);s.append(h.stdout,h.stderr),u=h.exitCode}}catch(p){if(p instanceof Ge){if(s.append(p.stdout,p.stderr),p.levels>1&&e.state.loopDepth>1)throw p.levels--,p.stdout=s.stdout,p.stderr=s.stderr,e.state.inCondition=d,p;c=!0}else if(p instanceof He){if(s.append(p.stdout,p.stderr),p.levels>1&&e.state.loopDepth>1)throw p.levels--,p.stdout=s.stdout,p.stderr=s.stderr,e.state.inCondition=d,p;f=!0}else throw e.state.inCondition=d,p}finally{e.state.inCondition=d}if((c||f)&&(i=Hn(e,_s)),c)break;if(!f){if(u!==0)break;try{for(let p of t.body){let h=await e.executeStatement(p);s.append(h.stdout,h.stderr),i=h.exitCode}}catch(p){let h=br(p,s.stdout,s.stderr,e.state.loopDepth);if(s.replace(h.stdout,h.stderr),h.exitCode!==void 0&&(i=Hn(e,h.exitCode)),h.action==="break")break;if(h.action==="continue")continue;if(h.action==="error")return s.build(h.exitCode??1);throw h.error}}}}finally{e.state.loopDepth--,a.owns&&(e.state.groupStdin=l)}return s.build(i)}async function hf(e,t,n=""){return et(e,t.redirections,n,r=>pm(e,t,n,r))}async function pm(e,t,n,r){let s=new an(e),i=0,o=0,a=uf(r.stdin,n),l=e.state.groupStdin;a.owns&&(e.state.groupStdin=a.stdin),e.state.loopDepth++;try{for(;;){o++,o>e.limits.maxLoopIterations&&Yt(`until loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",s.stdout,s.stderr);let u=await Qo(e,t.condition);if(s.append(u.stdout,u.stderr),u.exitCode===0)break;try{for(let c of t.body){let f=await e.executeStatement(c);s.append(f.stdout,f.stderr),i=f.exitCode}}catch(c){let f=br(c,s.stdout,s.stderr,e.state.loopDepth);if(s.replace(f.stdout,f.stderr),f.exitCode!==void 0&&(i=Hn(e,f.exitCode)),f.action==="break")break;if(f.action==="continue")continue;if(f.action==="error")return s.build(f.exitCode??1);throw f.error}}}finally{e.state.loopDepth--,a.owns&&(e.state.groupStdin=l)}return s.build(i)}async function mf(e,t){return et(e,t.redirections,"",()=>hm(e,t))}async function hm(e,t){let n=new an(e),r=0,s=await ne(e,t.word),i=!1;for(let o=0;o<t.items.length;o++){let a=t.items[o],l=i;if(!i)for(let u of a.patterns){let c=await ne(e,u);Vu(u)&&(c=Xe(c));let f=e.state.shoptOptions.nocasematch,d=e.state.shoptOptions.extglob;if(Bn(s,c,f,d,e.limits.maxCallDepth)){l=!0;break}}if(l){let u=await Ko(e,a.body,n);if(n.replace(u.stdout,u.stderr),r=u.exitCode,a.terminator===";;")break;a.terminator===";&"?i=!0:i=!1}else i=!1}return n.build(r)}function Xo(e,t){if(e.parts.length!==1)return!1;let n=e.parts[0];return n.type!=="Literal"?!1:t.includes(n.value)}async function yf(e,t,n){let r=t.timed?Ws():0,s="",i=J,o=0,a=[],l="",u=0,c=t.commands.length>1,f=e.state.lastArg,d=e.state.groupStdin,p=e.state.groupStdinSourceFd;for(let y=0;y<t.commands.length;y++){let g=t.commands[y],b=y===t.commands.length-1,v=y===0;c&&(e.state.lastArg="",e.state.groupStdin=v?d:void 0,e.state.groupStdinSourceFd=v?p:void 0);let x=c&&(!b||!e.state.shoptOptions.lastpipe),A=x?new Map(e.state.env):null,k=x?rt(e.state.arrays):null,N,$=e.executionScope.outputBytesUsed;try{e.state.commandCount=e.executionScope.chargeCommand(),N=await n(g,s)}catch(C){if(C instanceof Ze)N={stdout:C.stdout,stderr:C.stderr,exitCode:1};else if(C instanceof q&&t.commands.length>1)N={stdout:C.stdout,stderr:C.stderr,exitCode:C.exitCode};else if(C instanceof Me&&t.commands.length>1)N={stdout:C.stdout,stderr:C.stderr,exitCode:C.exitCode};else throw A&&(e.state.env=A,e.state.arrays=k??new Map),C}finally{c&&(v&&(d=e.state.groupStdin,p=e.state.groupStdinSourceFd),e.state.groupStdin=d,e.state.groupStdinSourceFd=p)}if(A&&(e.state.env=A,e.state.arrays=k??new Map),N=e.executionScope.accountResult(N,"pipeline",e.executionScope.outputBytesUsed-$),!b){let C=t.pipeStderr?.[y]??!1,D=N.internalOutputAccounting?.stdout??0,B=C?N.internalOutputAccounting?.stderr??0:0;$a(e.executionScope,D+B,"pipeline"),N={...N,internalOutputAccounting:{stdout:0,stderr:C?0:N.internalOutputAccounting?.stderr??0}}}a.push(N.exitCode),N.exitCode!==0&&(o=N.exitCode),b?i=N:(t.pipeStderr?.[y]??!1?s=un(N.stderr)+_t(N):(s=_t(N),l+=N.stderr,u+=N.internalOutputAccounting?.stderr??0),i={stdout:"",stderr:"",exitCode:N.exitCode})}l&&(i={...i,stderr:l+i.stderr,internalOutputAccounting:{stdout:i.internalOutputAccounting?.stdout??0,stderr:u+(i.internalOutputAccounting?.stderr??0)}});let h=t.commands.length>1||t.commands.length===1&&t.commands[0].type==="SimpleCommand",m=i.internalPipeStatusOverride??a;if(h){ye(e,"PIPESTATUS");for(let y=0;y<m.length;y++)U(e,"PIPESTATUS",y,String(m[y]))}if(e.state.options.pipefail&&o!==0&&(i={...i,exitCode:o}),t.negated&&(i={...i,exitCode:i.exitCode===0?1:0}),t.timed){let g=(Ws()-r)/1e3,b=Math.floor(g/60),v=g%60,x;t.timePosix?x=`real ${g.toFixed(2)}
771
+ `);throw m||s.poisonAfterAbort(y),y}finally{n(),Yn(l),Yn(c),u&&i?.removeEventListener("abort",u)}}async function ff(e,t,n,r,s,i,o,a,l=!1,u=!1,c=!1){let{ctx:f,runCommand:d}=e;if(f.coverage&&Vn.has(t)&&f.coverage.hit(`bash:builtin:${t}`),t==="export")return _o(f,n);if(t==="unset")return Zo(f,n);if(t==="exit")return Oo(f,n);if(t==="local")return Mo(f,n);if(t==="set")return Uo(f,n);if(t==="break")return qi(f,n);if(t==="continue")return So(f,n);if(t==="return")return Vo(f,n);if(t==="eval"&&f.state.options.posix)return Ds(f,n,s,l);if(t==="shift")return jo(f,n);if(t==="getopts")return Is(f,n);if(t==="compgen")return yo(f,n);if(t==="complete")return Eo(f,n);if(t==="compopt")return bo(f,n);if(t==="pushd")return await Ro(f,n);if(t==="popd")return Do(f,n);if(t==="dirs")return Io(f,n);if(t==="source"||t===".")return Go(f,n);if(t==="read")return Wo(f,n,s,a);if(t==="mapfile"||t==="readarray")return Bo(f,n,s);if(t==="declare"||t==="typeset")return Po(f,n);if(t==="readonly")return Co(f,n);if(!i){let p=f.state.functions.get(t);if(p)return Ns(f,p,n,s,void 0,l)}if(t==="__just_bash_tee_restore"){if(n.length===0||n.length>f.limits.maxArrayElements)return L(`bash: invalid internal pipeline status restore
772
+ `,2);let p=[];for(let y of n){if(!/^(?:0|[1-9][0-9]{0,2})$/.test(y))return L(`bash: invalid internal pipeline status restore
773
+ `,2);let b=Number(y);if(!Number.isSafeInteger(b)||b>255)return L(`bash: invalid internal pipeline status restore
774
+ `,2);p.push(b)}let h=p[p.length-1]??0,m=[...p].reverse().find(y=>y!==0);return{stdout:"",stderr:"",exitCode:f.state.options.pipefail&&m!==void 0?m:h,internalPipeStatusOverride:p}}if(t==="eval")return Ds(f,n,s,l);if(t==="cd")return await Ui(f,n);if(t===":"||t==="true")return J;if(t==="false")return ge(!1);if(t==="let")return Fo(f,n);if(t==="command")return hm(e,n,s,l,u,c);if(t==="builtin")return mm(e,n,s,l,u,c);if(t==="shopt")return Qc(f,n);if(t==="exec"){if(n.length===0)return J;let[p,...h]=n;return{...await d(p,h,[],s,!1,!1,-1,l,u,c),internalProducerOmitsShellPrefix:!0}}if(t==="wait")return J;if(t==="type")return await of(f,n,p=>uf(f,p),p=>Ts(f,p));if(t==="hash")return Lo(f,n);if(t==="help")return To(f,n);if(t==="["||t==="test"){let p=n;if(t==="["){if(n[n.length-1]!=="]")return L("[: missing `]'\n",2);p=n.slice(0,-1)}return pr(f,p)}return null}async function hm(e,t,n,r=!1,s=!1,i=!1){let{ctx:o,runCommand:a}=e;if(t.length===0)return J;let l=!1,u=!1,c=!1,f=t;for(;f.length>0&&f[0].startsWith("-");){let h=f[0];if(h==="--"){f=f.slice(1);break}for(let m of h.slice(1))m==="p"?l=!0:m==="V"?u=!0:m==="v"&&(c=!0);f=f.slice(1)}if(f.length===0)return J;if(c||u)return await lf(o,f,c,u);let[d,...p]=f;return a(d,p,[],n,!0,l,-1,r,s,i)}async function mm(e,t,n,r=!1,s=!1,i=!1){let{runCommand:o}=e;if(t.length===0)return J;let a=t;if(a[0]==="--"&&(a=a.slice(1),a.length===0))return J;let l=a[0];if(l!=="__just_bash_tee_restore"&&!Vn.has(l))return L(`bash: builtin: ${l}: not a shell builtin
775
+ `);let[,...u]=a;return o(l,u,[],n,!0,!1,-1,r,s,i)}async function df(e,t,n,r,s,i=!1,o=!1){let{ctx:a,buildExportedEnv:l,executeUserScript:u}=e,f=await Kc(a,t,s?"/usr/bin:/bin":void 0);if(!f)return nc(t)?L(`bash: ${t}: command not available in browser environments. Exclude '${t}' from your commands or use the Node.js bundle.
776
+ `,127):L(`bash: ${t}: command not found
777
+ `,127);if("error"in f)return f.error==="permission_denied"?L(`bash: ${t}: Permission denied
778
+ `,126):L(`bash: ${t}: No such file or directory
779
+ `,127);if("script"in f)return t.includes("/")||(a.state.hashTable||(a.state.hashTable=new Map),a.state.hashTable.set(t,f.path)),await u(f.path,n,r);let{cmd:d,path:p}=f;t.includes("/")||(a.state.hashTable||(a.state.hashTable=new Map),a.state.hashTable.set(t,p));let h=i||o||r.length>0,m=h?r:a.state.groupStdin||"",y=!1,b=l();a.state.fileDescriptors??=new Map;let w={fs:a.fs,fsIdentity:Hs(a.fs),cwd:a.state.cwd,env:a.state.env,assignShellVariable:async($,I,P)=>{if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test($))throw new Error(`${$}: not a valid identifier`);let N=P===void 0?$:`${$}[${P}]`,D=Qr(a,$,I);if(D===void 0)throw new Error(`${$}: circular name reference`);if(D===null)return;let R=D.match(/^([a-zA-Z_][a-zA-Z0-9_]*)(?:\[(.*)\])?$/);if(!R)throw new Error(`${N}: not a valid identifier`);let B=R[1],k=R[2]??P;if(Fe(a,$)||Fe(a,B))throw new Error(`${B}: readonly variable`);if(k===void 0)a.state.env.set(B,I);else{let M=a.state.associativeArrays?.has(B)?"associative":"indexed";if(M==="associative"){j(a,B,k,I,M);return}let z=await Xo(a,B,k);if(z.error)throw new U(z.error.exitCode,z.error.stdout,z.error.stderr);j(a,B,z.index,I,M)}},exportedEnv:b,get stdin(){return y=!0,m},stdinProvided:h,stdinUnavailable:o,limits:a.limits,executionScope:d.internalIsExtension?Ca(a.executionScope):a.executionScope,exec:($,I)=>a.execFn($,I,!1),execWithInheritedStdin:($,I)=>a.execFn($,{...I,stdin:m,stdinKind:"bytes"},!0),fetch:a.fetch,getRegisteredCommands:()=>Array.from(a.commands.keys()),sleep:a.sleep,trace:a.trace,fileDescriptors:a.state.fileDescriptors,xpgEcho:a.state.shoptOptions.xpg_echo,coverage:a.coverage,signal:a.state.signal,requireDefenseContext:a.requireDefenseContext,jsBootstrapCode:a.jsBootstrapCode,invokeTool:a.invokeTool},E=d.internalOriginalCommand,S=()=>{};if(E){let $=Object.getOwnPropertyDescriptors(w);$.executionScope={value:a.executionScope,enumerable:!0,configurable:!0,writable:!0};let I=Object.defineProperties(Object.create(Object.getPrototypeOf(w)),$),P=cf(I,E.name),N=Ko(P.context,E.name);S=P.revoke,w.origCommand=D=>{let R=()=>E.execute(D,N);return E.trusted?_e.runTrustedAsync(R):_e.runUntrustedAsync(R)}}let v=cf(w,t),A=Ko(v.context,t),x=()=>{v.revoke(),S()};try{let $=()=>pa(a.requireDefenseContext,"command",`${t} execution`,()=>d.execute(n,A)),I=()=>pm($,A,x,t,a.executionScope,a.state.signal),P=d.trusted?await _e.runTrustedAsync(I):await I();return{...P,internalStdinConsumed:P.internalStdinConsumed??(y?r.length:0)}}catch($){if($ instanceof C||$ instanceof We||$ instanceof vn)throw $;return L(`${t}: ${Ve(Rt($))}
780
+ `)}}async function Yo(e,t){let n=e.state.inCondition;e.state.inCondition=!0;let r=new Bt(e.executionScope,"condition"),s=0;try{for(let i of t){let o=await e.executeStatement(i);r.appendResult(o),s=o.exitCode}}catch(i){throw r.prependTo(i),i}finally{e.state.inCondition=n}return r.build(s)}var Ms=0;function Zn(e,t){return e.state.lastExitCode=t,e.state.env.set("?",String(t)),t}function Ar(e,t,n,r){if(e instanceof Ge)return t+=e.stdout,n+=e.stderr,e.levels>1&&r>1?(e.levels--,e.stdout=t,e.stderr=n,{action:"rethrow",stdout:t,stderr:n,error:e}):{action:"break",stdout:t,stderr:n,exitCode:Ms};if(e instanceof He)return t+=e.stdout,n+=e.stderr,e.levels>1&&r>1?(e.levels--,e.stdout=t,e.stderr=n,{action:"rethrow",stdout:t,stderr:n,error:e}):{action:"continue",stdout:t,stderr:n,exitCode:Ms};if(e instanceof Ie||e instanceof Me||e instanceof U||e instanceof C)return e.prependOutput(t,n),{action:"rethrow",stdout:t,stderr:n,error:e};let s=Rt(e);return{action:"error",stdout:t,stderr:`${n}${s}
781
+ `,exitCode:1}}function pf(e,t){return e!==void 0?{owns:!0,stdin:e}:t!==""?{owns:!0,stdin:t}:{owns:!1}}var an=class{ctx;stdoutChunks=[];stderrChunks=[];totalBytes=0;constructor(t){this.ctx=t}append(t,n){let r=W(t)+W(n);r>this.ctx.limits.maxOutputSize-this.totalBytes&&Yt(`total output size exceeded (>${this.ctx.limits.maxOutputSize} bytes), increase executionLimits.maxOutputSize`,"output_size"),t&&this.stdoutChunks.push(t),n&&this.stderrChunks.push(n),this.totalBytes+=r}appendUnaccounted(t,n){this.ctx.executionScope.appendOutput("stdout",t,"control-flow"),this.ctx.executionScope.appendOutput("stderr",n,"control-flow"),this.append(t,n)}replace(t,n){this.stdoutChunks=[],this.stderrChunks=[],this.totalBytes=0,this.append(t,n)}get stdout(){return this.stdoutChunks.join("")}get stderr(){return this.stderrChunks.join("")}build(t){let n=this.stdout,r=this.stderr;return{stdout:n,stderr:r,exitCode:t,internalOutputAccounting:{stdout:W(n),stderr:W(r)}}}};async function Jo(e,t,n){let r=0;try{for(let s of t){let i=await e.executeStatement(s);n.append(i.stdout,i.stderr),r=i.exitCode}}catch(s){if(Nr(s)||s instanceof Me||s instanceof U||s instanceof C||s instanceof Tt)throw s.prependOutput(n.stdout,n.stderr),s;return n.appendUnaccounted("",`${Rt(s)}
782
+ `),n.build(1)}return n.build(r)}async function hf(e,t){return Je(e,t.redirections,"",()=>ym(e,t))}async function ym(e,t){let n=new an(e);for(let r of t.clauses){let s=await Yo(e,r.condition);if(n.append(s.stdout,s.stderr),s.exitCode===0)return Jo(e,r.body,n)}return t.elseBody?Jo(e,t.elseBody,n):n.build(0)}async function mf(e,t){return Je(e,t.redirections,"",()=>gm(e,t))}async function gm(e,t){let n=new an(e),r=0,s=0;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(t.variable))return L(`bash: \`${t.variable}': not a valid identifier
783
+ `);let i=[];if(t.words===null)i=(e.state.env.get("@")||"").split(" ").filter(Boolean);else if(t.words.length===0)i=[];else try{for(let o of t.words){let a=await gt(e,o);Ne(i,a.values,e.limits.maxArrayElements,"for-loop expansion")}}catch(o){if(o instanceof Lt)return{stdout:"",stderr:o.stderr,exitCode:1};throw o}e.state.loopDepth++;try{for(let o of i){s++,s>e.limits.maxLoopIterations&&Yt(`for loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",n.stdout,n.stderr),e.state.env.set(t.variable,o);try{for(let a of t.body){let l=await e.executeStatement(a);n.append(l.stdout,l.stderr),r=l.exitCode}}catch(a){let l=Ar(a,n.stdout,n.stderr,e.state.loopDepth);if(n.replace(l.stdout,l.stderr),l.exitCode!==void 0&&(r=Zn(e,l.exitCode)),l.action==="break")break;if(l.action==="continue")continue;if(l.action==="error")return n.build(l.exitCode??1);throw l.error}}}finally{e.state.loopDepth--}return n.build(r)}async function yf(e,t){return Je(e,t.redirections,"",()=>wm(e,t))}async function wm(e,t){let n=t.line;n!==void 0&&(e.state.currentLine=n);let r=new an(e),s=0,i=0;t.init&&await X(e,t.init.expression),e.state.loopDepth++;try{for(;i++,i>e.limits.maxLoopIterations&&Yt(`for loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",r.stdout,r.stderr),!(t.condition&&(n!==void 0&&(e.state.currentLine=n),await X(e,t.condition.expression)===0));){try{for(let o of t.body){let a=await e.executeStatement(o);r.append(a.stdout,a.stderr),s=a.exitCode}}catch(o){let a=Ar(o,r.stdout,r.stderr,e.state.loopDepth);if(r.replace(a.stdout,a.stderr),a.exitCode!==void 0&&(s=Zn(e,a.exitCode)),a.action==="break")break;if(a.action==="continue"){t.update&&await X(e,t.update.expression);continue}if(a.action==="error")return r.build(a.exitCode??1);throw a.error}t.update&&await X(e,t.update.expression)}}finally{e.state.loopDepth--}return r.build(s)}async function gf(e,t,n=""){return Je(e,t.redirections,n,r=>Em(e,t,n,r))}async function Em(e,t,n,r){let s=new an(e),i=0,o=0,a=pf(r.stdin,n),l=e.state.groupStdin;a.owns&&(e.state.groupStdin=a.stdin),e.state.loopDepth++;try{for(;;){o++,o>e.limits.maxLoopIterations&&Yt(`while loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",s.stdout,s.stderr);let u=0,c=!1,f=!1,d=e.state.inCondition;e.state.inCondition=!0;try{for(let p of t.condition){let h=await e.executeStatement(p);s.append(h.stdout,h.stderr),u=h.exitCode}}catch(p){if(p instanceof Ge){if(s.append(p.stdout,p.stderr),p.levels>1&&e.state.loopDepth>1)throw p.levels--,p.stdout=s.stdout,p.stderr=s.stderr,e.state.inCondition=d,p;c=!0}else if(p instanceof He){if(s.append(p.stdout,p.stderr),p.levels>1&&e.state.loopDepth>1)throw p.levels--,p.stdout=s.stdout,p.stderr=s.stderr,e.state.inCondition=d,p;f=!0}else throw e.state.inCondition=d,p}finally{e.state.inCondition=d}if((c||f)&&(i=Zn(e,Ms)),c)break;if(!f){if(u!==0)break;try{for(let p of t.body){let h=await e.executeStatement(p);s.append(h.stdout,h.stderr),i=h.exitCode}}catch(p){let h=Ar(p,s.stdout,s.stderr,e.state.loopDepth);if(s.replace(h.stdout,h.stderr),h.exitCode!==void 0&&(i=Zn(e,h.exitCode)),h.action==="break")break;if(h.action==="continue")continue;if(h.action==="error")return s.build(h.exitCode??1);throw h.error}}}}finally{e.state.loopDepth--,a.owns&&(e.state.groupStdin=l)}return s.build(i)}async function wf(e,t,n=""){return Je(e,t.redirections,n,r=>bm(e,t,n,r))}async function bm(e,t,n,r){let s=new an(e),i=0,o=0,a=pf(r.stdin,n),l=e.state.groupStdin;a.owns&&(e.state.groupStdin=a.stdin),e.state.loopDepth++;try{for(;;){o++,o>e.limits.maxLoopIterations&&Yt(`until loop: too many iterations (${e.limits.maxLoopIterations}), increase executionLimits.maxLoopIterations`,"iterations",s.stdout,s.stderr);let u=await Yo(e,t.condition);if(s.append(u.stdout,u.stderr),u.exitCode===0)break;try{for(let c of t.body){let f=await e.executeStatement(c);s.append(f.stdout,f.stderr),i=f.exitCode}}catch(c){let f=Ar(c,s.stdout,s.stderr,e.state.loopDepth);if(s.replace(f.stdout,f.stderr),f.exitCode!==void 0&&(i=Zn(e,f.exitCode)),f.action==="break")break;if(f.action==="continue")continue;if(f.action==="error")return s.build(f.exitCode??1);throw f.error}}}finally{e.state.loopDepth--,a.owns&&(e.state.groupStdin=l)}return s.build(i)}async function Ef(e,t){return Je(e,t.redirections,"",()=>Sm(e,t))}async function Sm(e,t){let n=new an(e),r=0,s=await ne(e,t.word),i=!1;for(let o=0;o<t.items.length;o++){let a=t.items[o],l=i;if(!i)for(let u of a.patterns){let c=await ne(e,u);ju(u)&&(c=Xe(c));let f=e.state.shoptOptions.nocasematch,d=e.state.shoptOptions.extglob;if(Wn(s,c,f,d,e.limits.maxCallDepth)){l=!0;break}}if(l){let u=await Jo(e,a.body,n);if(n.replace(u.stdout,u.stderr),r=u.exitCode,a.terminator===";;")break;a.terminator===";&"?i=!0:i=!1}else i=!1}return n.build(r)}function ea(e,t){if(e.parts.length!==1)return!1;let n=e.parts[0];return n.type!=="Literal"?!1:t.includes(n.value)}async function bf(e,t,n){let r=t.timed?Us():0,s="",i=J,o=0,a=[],l="",u=0,c=t.commands.length>1,f=e.state.lastArg,d=e.state.groupStdin,p=e.state.groupStdinSourceFd;for(let w=0;w<t.commands.length;w++){let E=t.commands[w],S=w===t.commands.length-1,v=w===0;c&&(e.state.lastArg="",e.state.groupStdin=v?d:void 0,e.state.groupStdinSourceFd=v?p:void 0);let A=c&&(!S||!e.state.shoptOptions.lastpipe),x=A?new Map(e.state.env):null,$=A?nt(e.state.arrays):null,I,P=e.executionScope.outputBytesUsed;try{e.state.commandCount=e.executionScope.chargeCommand(),I=await n(E,s,!v)}catch(N){if(N instanceof Ze)I={stdout:N.stdout,stderr:N.stderr,exitCode:1};else if(N instanceof U&&t.commands.length>1)I={stdout:N.stdout,stderr:N.stderr,exitCode:N.exitCode};else if(N instanceof Me&&t.commands.length>1)I={stdout:N.stdout,stderr:N.stderr,exitCode:N.exitCode};else throw x&&(e.state.env=x,e.state.arrays=$??new Map),N}finally{c&&(v&&(d=e.state.groupStdin,p=e.state.groupStdinSourceFd),e.state.groupStdin=d,e.state.groupStdinSourceFd=p)}if(x&&(e.state.env=x,e.state.arrays=$??new Map),I=e.executionScope.accountResult(I,"pipeline",e.executionScope.outputBytesUsed-P),!S){let N=t.pipeStderr?.[w]??!1,D=I.internalOutputAccounting?.stdout??0,R=N?I.internalOutputAccounting?.stderr??0:0;Na(e.executionScope,D+R,"pipeline"),I={...I,internalOutputAccounting:{stdout:0,stderr:N?0:I.internalOutputAccounting?.stderr??0}}}a.push(I.exitCode),I.exitCode!==0&&(o=I.exitCode),S?i=I:(t.pipeStderr?.[w]??!1?s=un(I.stderr)+_t(I):(s=_t(I),l+=I.stderr,u+=I.internalOutputAccounting?.stderr??0),i={stdout:"",stderr:"",exitCode:I.exitCode})}l&&(i={...i,stderr:l+i.stderr,internalOutputAccounting:{stdout:i.internalOutputAccounting?.stdout??0,stderr:u+(i.internalOutputAccounting?.stderr??0)}});let h=t.commands.length>1||t.commands.length===1&&t.commands[0].type==="SimpleCommand",m=i.internalPipeStatusOverride??a;if(h){ye(e,"PIPESTATUS");for(let w=0;w<m.length;w++)j(e,"PIPESTATUS",w,String(m[w]))}if(e.state.options.pipefail&&o!==0&&(i={...i,exitCode:o}),t.negated&&(i={...i,exitCode:i.exitCode===0?1:0}),t.timed){let E=(Us()-r)/1e3,S=Math.floor(E/60),v=E%60,A;t.timePosix?A=`real ${E.toFixed(2)}
783
784
  user 0.00
784
785
  sys 0.00
785
- `:x=`
786
- real ${`${b}m${v.toFixed(3)}s`}
786
+ `:A=`
787
+ real ${`${S}m${v.toFixed(3)}s`}
787
788
  user 0m0.000s
788
789
  sys 0m0.000s
789
- `,i={...i,stderr:i.stderr+x}}c&&!e.state.shoptOptions.lastpipe&&(e.state.lastArg=f),i=e.executionScope.accountResult(i,"pipeline");let{internalPipeStatusOverride:E,...S}=i;return S}function Yo(e){return e?{...e,options:e.options?[...e.options]:void 0,actions:e.actions?[...e.actions]:void 0}:void 0}function mm(e){return e?new Map(Array.from(e,([t,n])=>[t,Yo(n)])):void 0}function ym(e){if(!e)return;let t=new Map,n=new Map;for(let[r,s]of e){let i=t.get(s);i||(i=new Set(s),t.set(s,i)),n.set(r,i)}return n}function gm(e){return e?.map(t=>new Map(Array.from(t,([n,r])=>[n,r?{kind:r.kind,elements:new Map(r.elements)}:void 0])))}function wm(e){return e?new Map(Array.from(e,([t,n])=>[t,n.map(r=>({...r}))])):void 0}function Jo(e){let t={env:e.env,arrays:e.arrays,cwd:e.cwd,previousDir:e.previousDir,lastExitCode:e.lastExitCode,lastArg:e.lastArg,currentLine:e.currentLine,options:e.options,shoptOptions:e.shoptOptions,fileDescriptors:e.fileDescriptors,inputFds:e.inputFds,fdAliases:e.fdAliases,closedStandardFds:e.closedStandardFds,nextFd:e.nextFd,readonlyVars:e.readonlyVars,associativeArrays:e.associativeArrays,namerefs:e.namerefs,boundNamerefs:e.boundNamerefs,invalidNamerefs:e.invalidNamerefs,integerVars:e.integerVars,lowercaseVars:e.lowercaseVars,uppercaseVars:e.uppercaseVars,exportedVars:e.exportedVars,tempExportedVars:e.tempExportedVars,localExportedVars:e.localExportedVars,declaredVars:e.declaredVars,localScopes:e.localScopes,localArrayScopes:e.localArrayScopes,localVarDepth:e.localVarDepth,localVarStack:e.localVarStack,fullyUnsetLocals:e.fullyUnsetLocals,tempEnvBindings:e.tempEnvBindings,mutatedTempEnvVars:e.mutatedTempEnvVars,accessedTempEnvVars:e.accessedTempEnvVars,functions:e.functions,callDepth:e.callDepth,sourceDepth:e.sourceDepth,callLineStack:e.callLineStack,funcNameStack:e.funcNameStack,sourceStack:e.sourceStack,currentSource:e.currentSource,inCondition:e.inCondition,loopDepth:e.loopDepth,parentHasLoopContext:e.parentHasLoopContext,errexitSafe:e.errexitSafe,directoryStack:e.directoryStack,hashTable:e.hashTable,completionSpecs:e.completionSpecs,defaultCompletionSpec:e.defaultCompletionSpec,emptyCompletionSpec:e.emptyCompletionSpec,groupStdin:e.groupStdin,groupStdinSourceFd:e.groupStdinSourceFd,bashPid:e.bashPid,expansionExitCode:e.expansionExitCode,expansionStderr:e.expansionStderr};e.env=new Map(e.env),e.arrays=rt(e.arrays),e.options={...e.options},e.shoptOptions={...e.shoptOptions},e.fileDescriptors=e.fileDescriptors?new Map(e.fileDescriptors):void 0,e.inputFds=e.inputFds?new Set(e.inputFds):void 0,e.fdAliases=ym(e.fdAliases),e.closedStandardFds=e.closedStandardFds?new Set(e.closedStandardFds):void 0,e.readonlyVars=new Set(e.readonlyVars),e.associativeArrays=new Set(e.associativeArrays),e.namerefs=new Set(e.namerefs),e.boundNamerefs=new Set(e.boundNamerefs),e.invalidNamerefs=new Set(e.invalidNamerefs),e.integerVars=new Set(e.integerVars),e.lowercaseVars=new Set(e.lowercaseVars),e.uppercaseVars=new Set(e.uppercaseVars),e.exportedVars=new Set(e.exportedVars),e.tempExportedVars=new Set(e.tempExportedVars),e.localExportedVars=e.localExportedVars?.map(r=>new Set(r)),e.declaredVars=new Set(e.declaredVars),e.localScopes=e.localScopes.map(r=>new Map(r)),e.localArrayScopes=gm(e.localArrayScopes),e.localVarDepth=e.localVarDepth?new Map(e.localVarDepth):void 0,e.localVarStack=wm(e.localVarStack),e.fullyUnsetLocals=e.fullyUnsetLocals?new Map(e.fullyUnsetLocals):void 0,e.tempEnvBindings=e.tempEnvBindings?.map(r=>new Map(r)),e.mutatedTempEnvVars=e.mutatedTempEnvVars?new Set(e.mutatedTempEnvVars):void 0,e.accessedTempEnvVars=e.accessedTempEnvVars?new Set(e.accessedTempEnvVars):void 0,e.functions=new Map(e.functions),e.callLineStack=e.callLineStack?[...e.callLineStack]:void 0,e.funcNameStack=e.funcNameStack?[...e.funcNameStack]:void 0,e.sourceStack=e.sourceStack?[...e.sourceStack]:void 0,e.directoryStack=e.directoryStack?[...e.directoryStack]:void 0,e.hashTable=e.hashTable?new Map(e.hashTable):void 0,e.completionSpecs=mm(e.completionSpecs),e.defaultCompletionSpec=Yo(e.defaultCompletionSpec),e.emptyCompletionSpec=Yo(e.emptyCompletionSpec);let n=!1;return()=>{n||(n=!0,Object.assign(e,t))}}async function gf(e,t,n,r,s=!1){let i=e.state.loopDepth,o=new Map;for(let l of e.state.fileDescriptors?.keys()??[]){let u=Je(e,l);u&&o.set(l,u)}let a=Jo(e.state);e.state.parentHasLoopContext=i>0,e.state.loopDepth=0,e.state.bashPid=e.state.nextVirtualPid++;try{return await et(e,t.redirections,n,l=>Em(e,t,l.stdin??n,r,s||l.stdin!==void 0))}finally{let l=new Map;for(let[u,c]of o){let f=Je(e,u),d=c.kind==="input"&&f?.kind==="input"?c.content.length-f.content.length:c.kind==="readwrite"&&f?.kind==="readwrite"&&c.path===f.path?f.position-c.position:0;if(d<=0)continue;let p=Math.min(...tn(e,u));l.set(p,Math.max(l.get(p)??0,d))}a();for(let[u,c]of l)nn(e,u,c)}}async function Em(e,t,n,r,s){(s||n)&&(e.state.groupStdin=n);let i=new Bt(e.executionScope,"subshell"),o=0;try{for(let a of t.body){let l=await r(a);i.appendResult(l),o=l.exitCode}}catch(a){if(a instanceof P)throw i.prependTo(a),a;return a instanceof Tt||a instanceof Ge||a instanceof He?(i.append("stdout",a.stdout,a.internalOutputAccounting.stdout),i.append("stderr",a.stderr,a.internalOutputAccounting.stderr),i.build(0)):a instanceof q||a instanceof Ie||a instanceof Me?(i.append("stdout",a.stdout,a.internalOutputAccounting.stdout),i.append("stderr",a.stderr,a.internalOutputAccounting.stderr),i.build(a.exitCode)):(i.append("stderr",`${Rt(a)}
790
- `),i.build(1))}return i.build(o)}async function wf(e,t,n,r,s=!1){return et(e,t.redirections,n,i=>bm(e,t,n,r,s,i))}async function bm(e,t,n,r,s,i){let o=new Bt(e.executionScope,"group"),a=0,l=i.stdin??n,u=s||n!==""||i.stdin!==void 0,c=e.state.groupStdin;u&&(e.state.groupStdin=l);let f=()=>{(u||c!==void 0&&e.state.groupStdin===void 0)&&(e.state.groupStdin=c)};try{for(let d of t.body){let p=await r(d);o.appendResult(p),a=p.exitCode}}catch(d){if(f(),d instanceof P)throw o.prependTo(d),d;if(Pr(d)||d instanceof Me||d instanceof q)throw d.prependOutput(o.stdout,o.stderr),d;return o.append("stderr",`${Rt(d)}
791
- `),o.build(1)}return f(),o.build(a)}async function Ef(e,t,n,r,s){let i;try{i=await e.fs.readFile(t)}catch{return _(`bash: ${t}: No such file or directory
790
+ `,i={...i,stderr:i.stderr+A}}c&&!e.state.shoptOptions.lastpipe&&(e.state.lastArg=f),i=e.executionScope.accountResult(i,"pipeline");let{internalPipeStatusOverride:y,...b}=i;return b}function ta(e){return e?{...e,options:e.options?[...e.options]:void 0,actions:e.actions?[...e.actions]:void 0}:void 0}function Am(e){return e?new Map(Array.from(e,([t,n])=>[t,ta(n)])):void 0}function vm(e){if(!e)return;let t=new Map,n=new Map;for(let[r,s]of e){let i=t.get(s);i||(i=new Set(s),t.set(s,i)),n.set(r,i)}return n}function xm(e){return e?.map(t=>new Map(Array.from(t,([n,r])=>[n,r?{kind:r.kind,elements:new Map(r.elements)}:void 0])))}function $m(e){return e?new Map(Array.from(e,([t,n])=>[t,n.map(r=>({...r}))])):void 0}function na(e){let t={env:e.env,arrays:e.arrays,cwd:e.cwd,previousDir:e.previousDir,lastExitCode:e.lastExitCode,lastArg:e.lastArg,currentLine:e.currentLine,options:e.options,shoptOptions:e.shoptOptions,fileDescriptors:e.fileDescriptors,inputFds:e.inputFds,deviceFds:e.deviceFds,fdAliases:e.fdAliases,closedStandardFds:e.closedStandardFds,nextFd:e.nextFd,readonlyVars:e.readonlyVars,associativeArrays:e.associativeArrays,namerefs:e.namerefs,boundNamerefs:e.boundNamerefs,invalidNamerefs:e.invalidNamerefs,integerVars:e.integerVars,lowercaseVars:e.lowercaseVars,uppercaseVars:e.uppercaseVars,exportedVars:e.exportedVars,tempExportedVars:e.tempExportedVars,localExportedVars:e.localExportedVars,declaredVars:e.declaredVars,localScopes:e.localScopes,localArrayScopes:e.localArrayScopes,localVarDepth:e.localVarDepth,localVarStack:e.localVarStack,fullyUnsetLocals:e.fullyUnsetLocals,tempEnvBindings:e.tempEnvBindings,mutatedTempEnvVars:e.mutatedTempEnvVars,accessedTempEnvVars:e.accessedTempEnvVars,functions:e.functions,callDepth:e.callDepth,sourceDepth:e.sourceDepth,callLineStack:e.callLineStack,funcNameStack:e.funcNameStack,sourceStack:e.sourceStack,currentSource:e.currentSource,inCondition:e.inCondition,loopDepth:e.loopDepth,parentHasLoopContext:e.parentHasLoopContext,errexitSafe:e.errexitSafe,directoryStack:e.directoryStack,hashTable:e.hashTable,completionSpecs:e.completionSpecs,defaultCompletionSpec:e.defaultCompletionSpec,emptyCompletionSpec:e.emptyCompletionSpec,groupStdin:e.groupStdin,groupStdinSourceFd:e.groupStdinSourceFd,bashPid:e.bashPid,expansionExitCode:e.expansionExitCode,expansionStderr:e.expansionStderr};e.env=new Map(e.env),e.arrays=nt(e.arrays),e.options={...e.options},e.shoptOptions={...e.shoptOptions},e.fileDescriptors=e.fileDescriptors?new Map(e.fileDescriptors):void 0,e.inputFds=e.inputFds?new Set(e.inputFds):void 0,e.deviceFds=e.deviceFds?new Set(e.deviceFds):void 0,e.fdAliases=vm(e.fdAliases),e.closedStandardFds=e.closedStandardFds?new Set(e.closedStandardFds):void 0,e.readonlyVars=new Set(e.readonlyVars),e.associativeArrays=new Set(e.associativeArrays),e.namerefs=new Set(e.namerefs),e.boundNamerefs=new Set(e.boundNamerefs),e.invalidNamerefs=new Set(e.invalidNamerefs),e.integerVars=new Set(e.integerVars),e.lowercaseVars=new Set(e.lowercaseVars),e.uppercaseVars=new Set(e.uppercaseVars),e.exportedVars=new Set(e.exportedVars),e.tempExportedVars=new Set(e.tempExportedVars),e.localExportedVars=e.localExportedVars?.map(r=>new Set(r)),e.declaredVars=new Set(e.declaredVars),e.localScopes=e.localScopes.map(r=>new Map(r)),e.localArrayScopes=xm(e.localArrayScopes),e.localVarDepth=e.localVarDepth?new Map(e.localVarDepth):void 0,e.localVarStack=$m(e.localVarStack),e.fullyUnsetLocals=e.fullyUnsetLocals?new Map(e.fullyUnsetLocals):void 0,e.tempEnvBindings=e.tempEnvBindings?.map(r=>new Map(r)),e.mutatedTempEnvVars=e.mutatedTempEnvVars?new Set(e.mutatedTempEnvVars):void 0,e.accessedTempEnvVars=e.accessedTempEnvVars?new Set(e.accessedTempEnvVars):void 0,e.functions=new Map(e.functions),e.callLineStack=e.callLineStack?[...e.callLineStack]:void 0,e.funcNameStack=e.funcNameStack?[...e.funcNameStack]:void 0,e.sourceStack=e.sourceStack?[...e.sourceStack]:void 0,e.directoryStack=e.directoryStack?[...e.directoryStack]:void 0,e.hashTable=e.hashTable?new Map(e.hashTable):void 0,e.completionSpecs=Am(e.completionSpecs),e.defaultCompletionSpec=ta(e.defaultCompletionSpec),e.emptyCompletionSpec=ta(e.emptyCompletionSpec);let n=!1;return()=>{n||(n=!0,Object.assign(e,t))}}async function Sf(e,t,n,r,s=!1){let i=e.state.loopDepth,o=new Map;for(let l of e.state.fileDescriptors?.keys()??[]){let u=st(e,l);u&&o.set(l,u)}let a=na(e.state);e.state.parentHasLoopContext=i>0,e.state.loopDepth=0,e.state.bashPid=e.state.nextVirtualPid++;try{return await Je(e,t.redirections,n,l=>km(e,t,l.stdin??n,r,s||l.stdin!==void 0))}finally{let l=new Map;for(let[u,c]of o){let f=st(e,u),d=c.kind==="input"&&f?.kind==="input"?c.content.length-f.content.length:c.kind==="readwrite"&&f?.kind==="readwrite"&&c.path===f.path?f.position-c.position:0;if(d<=0)continue;let p=Math.min(...tn(e,u));l.set(p,Math.max(l.get(p)??0,d))}a();for(let[u,c]of l)nn(e,u,c)}}async function km(e,t,n,r,s){(s||n)&&(e.state.groupStdin=n);let i=new Bt(e.executionScope,"subshell"),o=0;try{for(let a of t.body){let l=await r(a);i.appendResult(l),o=l.exitCode}}catch(a){if(a instanceof C)throw i.prependTo(a),a;return a instanceof Tt||a instanceof Ge||a instanceof He?(i.append("stdout",a.stdout,a.internalOutputAccounting.stdout),i.append("stderr",a.stderr,a.internalOutputAccounting.stderr),i.build(0)):a instanceof U||a instanceof Ie||a instanceof Me?(i.append("stdout",a.stdout,a.internalOutputAccounting.stdout),i.append("stderr",a.stderr,a.internalOutputAccounting.stderr),i.build(a.exitCode)):(i.append("stderr",`${Rt(a)}
791
+ `),i.build(1))}return i.build(o)}async function Af(e,t,n,r,s=!1){return Je(e,t.redirections,n,i=>Pm(e,t,n,r,s,i))}async function Pm(e,t,n,r,s,i){let o=new Bt(e.executionScope,"group"),a=0,l=i.stdin??n,u=s||n!==""||i.stdin!==void 0,c=e.state.groupStdin;u&&(e.state.groupStdin=l);let f=()=>{(u||c!==void 0&&e.state.groupStdin===void 0)&&(e.state.groupStdin=c)};try{for(let d of t.body){let p=await r(d);o.appendResult(p),a=p.exitCode}}catch(d){if(f(),d instanceof C)throw o.prependTo(d),d;if(Nr(d)||d instanceof Me||d instanceof U)throw d.prependOutput(o.stdout,o.stderr),d;return o.append("stderr",`${Rt(d)}
792
+ `),o.build(1)}return f(),o.build(a)}async function vf(e,t,n,r,s){let i;try{i=await e.fs.readFile(t)}catch{return L(`bash: ${t}: No such file or directory
792
793
  `,127)}if(i.startsWith("#!")){let l=i.indexOf(`
793
- `);l!==-1&&(i=i.slice(l+1))}let o=e.state.loopDepth,a=Jo(e.state);e.state.parentHasLoopContext=o>0,e.state.loopDepth=0,e.state.bashPid=e.state.nextVirtualPid++,r&&(e.state.groupStdin=r),e.state.currentSource=t,e.state.env.set("0",t),e.state.env.set("#",String(n.length)),e.state.env.set("@",n.join(" ")),e.state.env.set("*",n.join(" "));for(let l=0;l<n.length&&l<9;l++)e.state.env.set(String(l+1),n[l]);for(let l=n.length+1;l<=9;l++)e.state.env.delete(String(l));try{let u=new j().parse(i),c=await s(u);return a(),c}catch(l){if(a(),l instanceof q)return L(l.stdout,l.stderr,l.exitCode);if(l instanceof P)throw l;if(l.name==="ParseException")return _(`bash: ${t}: ${l.message}
794
- `);throw l}}function Sm(e){throw new TypeError(`Unsupported command node: ${JSON.stringify(e)}`)}var Sr=class{ctx;constructor(t,n){this.ctx={state:n,fs:t.fs,commands:t.commands,limits:t.limits,executionScope:t.executionScope,execFn:t.exec,executeScript:this.executeScript.bind(this),executeStatement:this.executeStatement.bind(this),executeCommand:this.executeCommand.bind(this),fetch:t.fetch,sleep:t.sleep,trace:t.trace,coverage:t.coverage,requireDefenseContext:t.requireDefenseContext??!1,jsBootstrapCode:t.jsBootstrapCode,invokeTool:t.invokeTool}}assertDefenseContext(t){if(!this.ctx.requireDefenseContext||_e.isInSandboxedContext())return;let n=`interpreter ${t} attempted outside defense context`;throw new An(n,{timestamp:Date.now(),type:"missing_defense_context",message:n,path:"DefenseInDepthBox.context",stack:new Error().stack,executionId:_e.getCurrentExecutionId()})}buildExportedEnv(){let t=this.ctx.state.exportedVars,n=this.ctx.state.tempExportedVars,r=new Set;if(t)for(let i of t)r.add(i);if(n)for(let i of n)r.add(i);if(r.size===0)return Object.create(null);let s=Object.create(null);for(let i of r){let o=this.ctx.state.env.get(i);o!==void 0&&(s[i]=o)}return s}async executeScript(t){this.assertDefenseContext("execution");let n=0,r=new Bt(this.ctx.executionScope,"script");for(let s of t.statements)try{let i=await this.executeStatement(s);r.appendResult(i,Ms(i)),n=i.exitCode,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n))}catch(i){if(i instanceof q)throw i.prependOutput(r.stdout,r.stderr),i;if(i instanceof tt)return r.append("stdout",i.stdout,i.internalOutputAccounting.stdout),r.append("stderr",i.stderr,i.internalOutputAccounting.stderr),n=i.exitCode,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n)),{...r.build(n),exitCode:n,env:Mt(this.ctx.state.env)};if(i instanceof P)throw r.prependTo(i),i;if(i instanceof Me)return r.append("stdout",i.stdout,i.internalOutputAccounting.stdout),r.append("stderr",i.stderr,i.internalOutputAccounting.stderr),n=i.exitCode,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n)),{...r.build(n),exitCode:n,env:Mt(this.ctx.state.env)};if(i instanceof Be)return r.append("stdout",i.stdout,i.internalOutputAccounting.stdout),r.append("stderr",i.stderr,i.internalOutputAccounting.stderr),n=1,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n)),{...r.build(n),exitCode:n,env:Mt(this.ctx.state.env)};if(i instanceof Ze)return r.append("stdout",i.stdout,i.internalOutputAccounting.stdout),r.append("stderr",i.stderr,i.internalOutputAccounting.stderr),n=1,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n)),{...r.build(n),exitCode:n,env:Mt(this.ctx.state.env)};if(i instanceof oe){r.append("stdout",i.stdout,i.internalOutputAccounting.stdout),r.append("stderr",i.stderr,i.internalOutputAccounting.stderr),n=1,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n));continue}if(i instanceof kr){r.append("stdout",i.stdout,i.internalOutputAccounting.stdout),r.append("stderr",i.stderr,i.internalOutputAccounting.stderr),n=1,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n));continue}if(i instanceof Ge||i instanceof He){if(this.ctx.state.loopDepth>0)throw i.prependOutput(r.stdout,r.stderr),i;r.append("stdout",i.stdout),r.append("stderr",i.stderr);continue}throw i instanceof Ie&&i.prependOutput(r.stdout,r.stderr),i}return{...r.build(n),env:Mt(this.ctx.state.env)}}async executeUserScript(t,n,r=""){return Ef(this.ctx,t,n,r,s=>this.executeScript(s))}async executeStatement(t){if(this.assertDefenseContext("statement"),this.ctx.state.signal?.aborted)throw new We;if(t.deferredError)throw new xe(t.deferredError.message,t.line??1,1);if(this.ctx.state.options.noexec)return J;this.ctx.state.errexitSafe=!1;let n=new Bt(this.ctx.executionScope,"statement");this.ctx.state.options.verbose&&!this.ctx.state.suppressVerbose&&t.sourceText&&n.append("stderr",`${t.sourceText}
795
- `);let r=0,s=-1,i=!1;try{for(let l=0;l<t.pipelines.length;l++){let u=t.pipelines[l],c=l>0?t.operators[l-1]:null;if(c==="&&"&&r!==0||c==="||"&&r===0)continue;let f=await this.executePipeline(u);n.appendResult(f,Ms(f)),r=f.exitCode,s=l,i=u.negated,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r))}}catch(l){throw n.prependTo(l),l}let o=s<t.pipelines.length-1,a=this.ctx.state.errexitSafe;if(this.ctx.state.errexitSafe=o||i||a,this.ctx.state.options.errexit&&r!==0&&s===t.pipelines.length-1&&!i&&!this.ctx.state.inCondition&&!a){let l=new Me(r);throw l.prependOutput(n.stdout,n.stderr),l}return n.build(r)}async executePipeline(t){return yf(this.ctx,t,(n,r)=>this.executeCommand(n,r))}async executeCommand(t,n,r=!1){let s=Bu(this.ctx),i;try{i=await this.executeCommandInner(t,n,r)}catch(a){throw await Fi(this.ctx,s).catch(()=>{}),a}let o=await Fi(this.ctx,s);return!o.stdout&&!o.stderr?i:{...i,stdout:o.stdout?_t(i)+o.stdout:i.stdout,stdoutKind:o.stdout?"bytes":i.stdoutKind,stderr:i.stderr+o.stderr}}async executeCommandInner(t,n,r){switch(this.assertDefenseContext("command"),this.ctx.coverage?.hit(`bash:cmd:${t.type}`),t.type){case"SimpleCommand":return this.executeSimpleCommand(t,n);case"If":return cf(this.ctx,t);case"For":return ff(this.ctx,t);case"CStyleFor":return df(this.ctx,t);case"While":return pf(this.ctx,t,n);case"Until":return hf(this.ctx,t,n);case"Case":return mf(this.ctx,t);case"Subshell":return this.executeSubshell(t,n,r);case"Group":return this.executeGroup(t,n,r);case"FunctionDef":return bc(this.ctx,t);case"ArithmeticCommand":return this.executeArithmeticCommand(t);case"ConditionalCommand":return this.executeConditionalCommand(t);default:return Sm(t)}}async executeSimpleCommand(t,n){let r;try{return await this.executeSimpleCommandInner(t,n,s=>{r=s})}catch(s){if(r?.finish(),s instanceof Lt)return _(s.stderr);throw s}}async executeSimpleCommandInner(t,n,r){if(t.line!==void 0&&(this.ctx.state.currentLine=t.line),this.ctx.state.shoptOptions.expand_aliases&&t.name){let $=t,C=0;for(;;){let D=this.expandAlias($);if(D===$)break;if(C>=this.ctx.limits.maxCallDepth)throw new P(`alias expansion depth limit exceeded (${this.ctx.limits.maxCallDepth})`,"recursion");C++,$=D}this.aliasExpansionStack.clear(),$!==t&&(t=$)}this.ctx.state.expansionStderr="",this.ctx.state.lastSubstitutionExitCode=null;let s=await Xc(this.ctx,t);if(s.error)return s.error;let i=s.tempAssignments,o=s.xtraceOutput,a=()=>{for(let[$,C]of i)C===void 0?this.ctx.state.env.delete($):this.ctx.state.env.set($,C)};if(!t.name){if(t.redirections.length>0){let C=qn(this.ctx,t.redirections,wc);r(C);let D=await C.prepare(n);if(D.error){if(a(),!D.errorCause)return C.finish(),D.error;try{return Un(D)}finally{C.finish()}}let B=L("",o,Qr(this.ctx.state,t.redirections)),H=await sn(this.ctx,B,t.redirections,D.targets,D.dupSources,D.standardRoutes);return C.finish(),H}this.ctx.state.lastArg="";let $=(this.ctx.state.expansionStderr||"")+o;return this.ctx.state.expansionStderr="",L("",$,Qr(this.ctx.state,[]))}let l=t.name&&Xo(t.name,["local","declare","typeset","export","readonly"]),u=Array.from(i.keys());if(u.length>0&&!l){this.ctx.state.tempExportedVars=this.ctx.state.tempExportedVars||new Set;for(let $ of u)this.ctx.state.tempExportedVars.add($)}let c=await ne(this.ctx,t.name),f=[],d=[],p=($,C)=>{if(f.length>=this.ctx.limits.maxArrayElements)throw new P(`expanded argument element limit exceeded (${this.ctx.limits.maxArrayElements})`,"array_elements");f.push($),d.push(C)};if(Xo(t.name,["local","declare","typeset","export","readonly"])&&(c==="local"||c==="declare"||c==="typeset"||c==="export"||c==="readonly"))for(let $ of t.args){let C=await Ku(this.ctx,$);if(C)p(C,!0);else{let D=await Xu(this.ctx,$);if(D!==null)p(D,!0);else{let B=await wt(this.ctx,$);for(let H of B.values)p(H,B.quoted)}}}else for(let $ of t.args){let C=await wt(this.ctx,$);for(let D of C.values)p(D,C.quoted)}let m=t.name.parts.every($=>$.type==="CommandSubstitution"||$.type==="ParameterExpansion"||$.type==="ArithmeticExpansion");!c&&m&&f.length>0&&(c=f.shift(),d.shift());let E=qn(this.ctx,t.redirections,c==="exec"?Ec:pr);r(E);let S=await E.prepare(n);if(S.error)return a(),S.errorCause?Un(S):(E.finish(),S.error);let y=S.stdinSourceFd,g=S.stdin!==void 0;if(S.stdin!==void 0&&(n=S.stdin),!c)return m?(E.finish(),L("","",Qr(this.ctx.state,t.redirections))):(E.finish(),_(`bash: : command not found
796
- `,127));if(c==="exec"&&(f.length===0||f[0]==="--")){for(let[$,C]of i)C===void 0?this.ctx.state.env.delete($):this.ctx.state.env.set($,C);if(this.ctx.state.tempExportedVars)for(let $ of i.keys())this.ctx.state.tempExportedVars.delete($);return E.finish(),J}if(this.ctx.state.extraArgs){let $=this.ctx.state.extraArgs;this.ctx.state.extraArgs=void 0;for(let C of $)p(C,!0)}let b=await Qc(this.ctx,c,f);i.size>0&&(this.ctx.state.tempEnvBindings=this.ctx.state.tempEnvBindings||[],this.ctx.state.tempEnvBindings.push(new Map(i)));let v,x=null;try{v=await this.runCommand(c,f,d,n,!1,!1,y,g)}catch($){if($ instanceof Ge||$ instanceof He)x=$,v=J;else throw $}y>=0&&c!=="read"&&nn(this.ctx,y,v.internalStdinConsumed??0);let A=o+b;if(A&&(v={...v,stderr:A+v.stderr}),v=await sn(this.ctx,v,t.redirections,S.targets,S.dupSources,S.standardRoutes,v.internalProducerCommand??c,v.internalProducerOmitsShellPrefix),E.finish(),x)throw x;if(f.length>0){let $=f[f.length-1];if((c==="declare"||c==="local"||c==="typeset")&&/^[a-zA-Z_][a-zA-Z0-9_]*=\(/.test($)){let C=$.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\(/);C&&($=C[1])}this.ctx.state.lastArg=$}else this.ctx.state.lastArg=c;let k=dc(c)&&c!=="unset"&&c!=="eval";if(!this.ctx.state.options.posix||!k)for(let[$,C]of i)this.ctx.state.fullyUnsetLocals?.has($)||(C===void 0?this.ctx.state.env.delete($):this.ctx.state.env.set($,C));if(this.ctx.state.tempExportedVars)for(let $ of i.keys())this.ctx.state.tempExportedVars.delete($);return i.size>0&&this.ctx.state.tempEnvBindings&&this.ctx.state.tempEnvBindings.pop(),this.ctx.state.expansionStderr&&(v={...v,stderr:this.ctx.state.expansionStderr+v.stderr},this.ctx.state.expansionStderr=""),v}async runCommand(t,n,r,s,i=!1,o=!1,a=-1,l=!1){let u={ctx:this.ctx,runCommand:(d,p,h,m,E,S,y,g)=>this.runCommand(d,p,h,m,E,S,y,g),buildExportedEnv:()=>this.buildExportedEnv(),executeUserScript:(d,p,h)=>this.executeUserScript(d,p,h)},c=await af(u,t,n,r,s,i,o,a,l);return c!==null?c.internalProducerCommand===void 0?{...c,internalProducerCommand:t}:c:{...await lf(u,t,n,s,o),internalProducerCommand:t}}aliasExpansionStack=new Set;expandAlias(t){return vl({env:this.ctx.state.env,limits:this.ctx.limits},t,this.aliasExpansionStack)}async findCommandInPath(t){return Is(this.ctx,t)}async executeSubshell(t,n="",r=!1){return gf(this.ctx,t,n,s=>this.executeStatement(s),r)}async executeGroup(t,n="",r=!1){return wf(this.ctx,t,n,s=>this.executeStatement(s),r)}async executeArithmeticCommand(t){return t.line!==void 0&&(this.ctx.state.currentLine=t.line),et(this.ctx,t.redirections,"",async()=>{try{let n=await X(this.ctx,t.expression.expression),r=ge(n!==0);return this.ctx.state.expansionStderr&&(r={...r,stderr:this.ctx.state.expansionStderr+r.stderr},this.ctx.state.expansionStderr=""),r}catch(n){return _(`bash: arithmetic expression: ${n.message}
797
- `)}})}async executeConditionalCommand(t){return t.line!==void 0&&(this.ctx.state.currentLine=t.line),et(this.ctx,t.redirections,"",async()=>{try{let n=await Jt(this.ctx,t.expression),r=ge(n);return this.ctx.state.expansionStderr&&(r={...r,stderr:this.ctx.state.expansionStderr+r.stderr},this.ctx.state.expansionStderr=""),r}catch(n){let r=n instanceof oe?1:2;return _(`bash: conditional expression: ${n.message}
798
- `,r)}})}};function ea(e){try{let t=new URL(e);return{origin:t.origin,pathname:t.pathname,href:t.href}}catch{return null}}function Am(e){let t=ea(e);return t?{origin:t.origin,pathPrefix:t.pathname}:null}var vm=3;function bf(e){let t=e;for(let n=0;n<vm;n++){if(t.includes("\\")||t.includes(";")||/%(?![0-9a-f]{2})/i.test(t))return!0;let r=t.toLowerCase();if(r.includes("%2f")||r.includes("%2e")||r.includes("%5c")||r.includes("%3b"))return!0;let s;try{s=decodeURIComponent(t)}catch{return!0}if(s===t)return!1;t=s}return t.includes("%")}function xm(e,t){return t==="/"||t===""?!0:t.endsWith("/")?e.startsWith(t):e===t||e.startsWith(`${t}/`)}function ta(e,t){let n=ea(e);if(!n)return!1;let r=Am(t);return!r||n.origin!==r.origin||r.pathPrefix!=="/"&&r.pathPrefix!==""&&bf(n.pathname)?!1:xm(n.pathname,r.pathPrefix)}function Sf(e){return typeof e=="string"?e:e.url}function Af(e,t){return!t||t.length===0?!1:t.some(n=>ta(e,Sf(n)))}function na(e){let t=$m(e);if(t==="localhost"||t.endsWith(".localhost"))return!0;let n=vf(t);if(n)return Ls(n);let r=Pm(t);return r?Cm(r):!1}function $m(e){let t=e.trim().toLowerCase();return t.startsWith("[")&&t.endsWith("]")?t.slice(1,-1):t}function km(e){if(!e)return null;let t=10,n=e;if(n.startsWith("0x")||n.startsWith("0X")?(t=16,n=n.slice(2)):n.length>1&&n.startsWith("0")&&(t=8),!n||t===16&&!/^[0-9a-fA-F]+$/.test(n)||t===10&&!/^\d+$/.test(n)||t===8&&!/^[0-7]+$/.test(n))return null;let r=Number.parseInt(n,t);return!Number.isFinite(r)||r<0?null:r}function vf(e){let t=e.split(".");if(t.length===0||t.length>4)return null;let n=t.map(l=>km(l));if(n.some(l=>l===null))return null;let r=n;if(t.length===1){let l=r[0];return l>4294967295?null:[l>>>24&255,l>>>16&255,l>>>8&255,l&255]}if(t.length===2){let[l,u]=r;return l>255||u>16777215?null:[l,u>>>16&255,u>>>8&255,u&255]}if(t.length===3){let[l,u,c]=r;return l>255||u>255||c>65535?null:[l,u,c>>>8&255,c&255]}let[s,i,o,a]=r;return s>255||i>255||o>255||a>255?null:[s,i,o,a]}function Pm(e){let t=e,n=null;if(t.includes(".")){let m=t.lastIndexOf(":");if(m<0)return null;let E=t.slice(m+1),S=vf(E);if(!S)return null;n=S,t=t.slice(0,m)}let r=t.includes("::")?t.split("::").length-1:0;if(r>1)return null;let[s,i]=t.split("::"),o=s?s.split(":").filter(Boolean):[],a=i?i.split(":").filter(Boolean):[],l=m=>/^[0-9a-f]{1,4}$/i.test(m)?Number.parseInt(m,16):null,u=o.map(l),c=a.map(l);if(u.some(m=>m===null)||c.some(m=>m===null))return null;let f=n?2:0,d=u.length+c.length+f,p=0;if(r===1){if(p=8-d,p<0)return null}else if(d!==8)return null;let h=[...u,...new Array(p).fill(0),...c];return n&&(h.push(n[0]<<8|n[1]),h.push(n[2]<<8|n[3])),h.length===8?h:null}function Ls(e){let[t,n]=e;return t===127||t===10||t===172&&n>=16&&n<=31||t===192&&n===168||t===169&&n===254||t===0||t===100&&n>=64&&n<=127||t===198&&(n===18||n===19)||t===192&&n===0&&e[2]===0||t===192&&n===0&&e[2]===2||t===198&&n===51&&e[2]===100||t===203&&n===0&&e[2]===113||t>=240}function Cm(e){if(e.every(s=>s===0)||e.slice(0,7).every(s=>s===0)&&e[7]===1||(e[0]&65472)===65152||(e[0]&65024)===64512)return!0;if(e[0]===0&&e[1]===0&&e[2]===0&&e[3]===0&&e[4]===0&&e[5]===65535){let s=[e[6]>>>8&255,e[6]&255,e[7]>>>8&255,e[7]&255];return Ls(s)}if(e[0]===8193&&e[1]===3512)return!0;if(e[0]===100&&e[1]===65435&&e[2]===0&&e[3]===0&&e[4]===0&&e[5]===0){let s=[e[6]>>>8&255,e[6]&255,e[7]>>>8&255,e[7]&255];return Ls(s)}if(e[0]===100&&e[1]===65435&&e[2]===1)return!0;if(e[0]===8194){let s=[e[1]>>>8&255,e[1]&255,e[2]>>>8&255,e[2]&255];return Ls(s)}return!1}function xf(e){let t=[];for(let n of e){if(typeof n!="string"&&(n===null||typeof n!="object"||!("url"in n)||typeof n.url!="string")){t.push('Invalid allow-list entry: must be a string URL or an object with a "url" string property');continue}let r=Sf(n);if(!ea(r)){t.push(`Invalid URL in allow-list: "${r}" - must be a valid URL with scheme and host (e.g., "https://example.com")`);continue}let i=new URL(r);if(i.protocol!=="http:"&&i.protocol!=="https:"){t.push(`Only http and https URLs are allowed in allow-list: "${r}"`);continue}if(!i.hostname){t.push(`Allow-list entry must include a hostname: "${r}"`);continue}if(i.pathname!=="/"&&i.pathname!==""&&bf(i.pathname)){t.push(`Allow-list entry contains ambiguous path separators: "${r}"`);continue}(i.search||i.hash)&&t.push(`Query strings and fragments are ignored in allow-list entries: "${r}"`)}return t}var Et=class extends Error{constructor(t,n){let r=n??"URL not in allow-list";super(`Network access denied: ${r}: ${t}`),this.name="NetworkAccessDeniedError"}},Zn=class extends Error{constructor(t){super(`Too many redirects (max: ${t})`),this.name="TooManyRedirectsError"}},ln=class extends Error{constructor(t){super(`Redirect target not in allow-list: ${t}`),this.name="RedirectNotAllowedError"}},Ts=class extends Error{constructor(t,n){super(`HTTP method '${t}' not allowed. Allowed methods: ${n.join(", ")}`),this.name="MethodNotAllowedError"}},Sn=class extends Error{constructor(t){super(`Response body too large (max: ${t} bytes)`),this.name="ResponseTooLargeError"}};var Nm=20,Rm=3e4,Dm=10485760,Im=["GET","HEAD"],Ar;typeof __BROWSER__<"u"&&__BROWSER__?Ar=null:(Ar=import("./chunks/dist-4NZ74CRE.js"),Ar.catch(()=>{}));var Om=new Set(["GET","HEAD","OPTIONS"]),_m=new Set([301,302,303,307,308]);function vr(e){return e.reason instanceof Error?e.reason:new DOMException("The operation was aborted","AbortError")}function Lm(e){if(e?.aborted)throw vr(e)}function sa(e){let t=e.allowedUrlPrefixes??[];if(e._dnsResolve)throw new Error("NetworkConfig._dnsResolve is no longer supported: DNS resolution is performed by guarded-fetch and cannot be overridden");if(e._createConnectionOwner)throw new Error("NetworkConfig._createConnectionOwner is no longer supported: connect-time IP pinning is performed by guarded-fetch and cannot be overridden");let n=e._fetch;if(!e.dangerouslyAllowFullInternetAccess){let b=xf(t);if(b.length>0)throw new Error(`Invalid network allow-list:
799
- ${b.join(`
800
- `)}`)}let r=[];for(let b of t)typeof b=="object"&&b.transform&&b.transform.length>0&&r.push(b);function s(b){if(r.length===0)return null;let v=null;for(let x of r)if(ta(b,x.url)&&x.transform){v||(v=new Headers);for(let A of x.transform)for(let[k,N]of Object.entries(A.headers))v.set(k,N)}return v}if(e.maxRedirects!==void 0&&(!Number.isSafeInteger(e.maxRedirects)||e.maxRedirects<0))throw new RangeError("maxRedirects must be a non-negative safe integer");let i=e.maxRedirects??Nm,o=e.timeoutMs??Rm,a=e.maxResponseSize??Dm,l=e.dangerouslyAllowFullInternetAccess?["GET","HEAD","POST","PUT","DELETE","PATCH","OPTIONS"]:e.allowedMethods??Im,u=e.denyPrivateRanges??(typeof process<"u"&&process.env?.NODE_ENV==="production"),c=[];for(let b of t){let v=typeof b=="string"?b:b.url;try{c.push(new URL(v).hostname)}catch{}}function f(b){try{return new URL(b).hostname||"localhost.invalid"}catch{return"localhost.invalid"}}function d(b){return e.dangerouslyAllowFullInternetAccess?u?{allowedHosts:void 0,skipSsrfCheckForAllowedHosts:void 0}:{allowedHosts:[f(b)],skipSsrfCheckForAllowedHosts:!0}:{allowedHosts:c,skipSsrfCheckForAllowedHosts:!u}}function p(b){try{return na(new URL(b).hostname)}catch{return!1}}async function h(b,v){let x={method:v.method,headers:v.headers,signal:v.signal,redirect:"manual"};return v.body!==void 0&&(x.body=v.body),await(n??globalThis.fetch)(b,x)}function m(b){if(!e.dangerouslyAllowFullInternetAccess&&!Af(b,t))throw new Et(b)}function E(b){if(!u)return;let v;try{v=new URL(b)}catch{throw new Et(b,"invalid URL")}if(na(v.hostname))throw new Et(b,"private/loopback IP address blocked")}function S(b){if(e.dangerouslyAllowFullInternetAccess)return;let v=b.toUpperCase();if(!l.includes(v))throw new Ts(v,l)}function y(b,v,x,A){if(!x.isGuardedFetchError(b))return b;let k=b,{onRedirectHop:N,subReason:$}=A;switch(k.code){case"host_not_allowed":case"protocol_not_allowed":return N?new ln(v):new Et(v);case"hostname_unsafe":return N?new ln(v):new Et(v,$==="dns_resolution_failed"?"DNS resolution failed for private IP check":"hostname resolves to private/loopback IP address");case"redirect_to_unsafe_host":return new ln(v);case"too_many_redirects":return new Zn(i);case"response_too_large":return new Sn(a);default:return b}}async function g(b,v={}){let x=v.method?.toUpperCase()??"GET",A=v.followRedirects??!0;if(v.maxRedirects!==void 0&&(!Number.isSafeInteger(v.maxRedirects)||v.maxRedirects<0))throw new RangeError("maxRedirects must be a non-negative safe integer");let k=v.maxRedirects??i,N=Math.min(i,k),$=v.timeoutMs!==void 0?Math.min(v.timeoutMs,o):o,C=new AbortController,D=oa(()=>C.abort(new DOMException("The operation was aborted","AbortError")),$),B=Cr(v.signal,C.signal);try{m(b),E(b),S(x);let H=Ar?await Ar:null,R=b,W=0,V=[],I=x,O=v.body,M=v.headers,ee=!1;for(;;){Lm(B.signal);let K=await _e.runTrustedAsync(async()=>{let De=M;if(ee&&De){let Nt=De instanceof Headers?new Headers(De):new Headers(De);Nt.delete("authorization"),Nt.delete("cookie"),De=Nt}let lt=s(R),Ct=Fm(De,lt),ut={method:I,headers:Ct,signal:B.signal,followRedirects:!1,timeoutMs:$,sanitizeHeaders:!1};if(O&&!Om.has(I)&&(ut.body=O),Object.assign(ut,d(R)),!H||p(R)){if(u)throw new Et(R,"DNS pinning unavailable for private IP enforcement");return await h(R,ut)}u?n&&(ut.fetch=n):(ut.fetch=n??globalThis.fetch,ut.dispatcher=null);let ct;ut.onUrlBlocked=Nt=>{ct=Nt.subReason};try{return await H.guardedFetch(R,ut)}catch(Nt){throw y(Nt,R,H,{onRedirectHop:W>0,subReason:ct})}});if(_m.has(K.status)&&A){let De=K.headers.get("location");if(!De)return await $f(K,R,a,B.signal,V);V.push({status:K.status,statusText:K.statusText,headers:kf(K.headers)});let lt=new URL(De,R).href;await ra(Tm(K),B.signal);try{m(lt),E(lt)}catch(ct){throw B.signal?.aborted?vr(B.signal):ct instanceof Et?new ln(lt):ct}let Ct=K.status;if(((Ct===301||Ct===302)&&I==="POST"||Ct===303&&I!=="GET"&&I!=="HEAD")&&(I="GET",O=void 0,S(I)),new URL(lt).origin!==new URL(R).origin&&(ee=!0),W++,W>N)throw new Zn(N);R=lt;continue}return await $f(K,R,a,B.signal,V)}}finally{aa(D),B.cleanup()}}return g}async function ra(e,t){if(!t)return e;if(t.aborted)throw e.catch(()=>{}),vr(t);let n,r=new Promise((s,i)=>{n=()=>i(vr(t)),t.addEventListener("abort",n,{once:!0})});try{return await Promise.race([e,r])}finally{n&&t.removeEventListener("abort",n)}}async function Tm(e){e.body&&!e.body.locked&&await e.body.cancel()}function Fm(e,t){if(!e&&!t)return;if(!t)return e;let n=e instanceof Headers?new Headers(e):new Headers(e);for(let[r,s]of t)n.set(r,s);return n}function kf(e){let t=Object.create(null);return e.forEach((n,r)=>{t[r.toLowerCase()]=n}),t}async function $f(e,t,n,r,s){let i=kf(e.headers);if(n>0){let l=e.headers.get("content-length");if(l){let u=parseInt(l,10);if(!Number.isNaN(u)&&u>n)throw new Sn(n)}}let o;if(n>0&&e.body){let l=e.body.getReader(),u=[],c=0;try{for(;;){let{done:d,value:p}=await ra(l.read(),r);if(d)break;if(p){if(c+=p.byteLength,c>n)throw await l.cancel(),new Sn(n);u.push(p)}}}catch(d){throw r?.aborted&&await l.cancel(vr(r)).catch(()=>{}),d}o=new Uint8Array(c);let f=0;for(let d of u)o.set(d,f),f+=d.byteLength}else{let l=await ra(e.arrayBuffer(),r);if(n>0&&l.byteLength>n)throw new Sn(n);o=new Uint8Array(l)}let a={status:e.status,statusText:e.statusText,headers:i,body:o,url:t};return s&&s.length>0&&(a.redirectChain=s),a}function ia(e,t){if(e.length>t||F(e)>t)throw new P(`script input size limit exceeded (${t} bytes)`,"string_length")}var Fs=class{fs;commands=new Map;useDefaultLayout=!1;limits;secureFetch;sleepFn;traceFn;logger;defenseInDepthConfig;coverageWriter;jsBootstrapCode;invokeToolFn;transformPlugins=[];state;constructor(t={}){this.limits=Us({...t.executionLimits,...t.maxCallDepth!==void 0&&{maxCallDepth:t.maxCallDepth},...t.maxCommandCount!==void 0&&{maxCommandCount:t.maxCommandCount},...t.maxLoopIterations!==void 0&&{maxLoopIterations:t.maxLoopIterations}},t.executionLimitProfile);let n=t.fs??new bt(t.files,{maxTotalBytes:this.limits.maxFileSystemBytes});this.fs=n,this.useDefaultLayout=!t.cwd&&!t.files;let r=t.cwd||(this.useDefaultLayout?"/home/user":"/"),s=new Map([["HOME",this.useDefaultLayout?"/home/user":"/"],["PATH","/usr/bin:/bin"],["IFS",`
801
- `],["OSTYPE","linux-gnu"],["MACHTYPE","x86_64-pc-linux-gnu"],["HOSTTYPE","x86_64"],["HOSTNAME","localhost"],["PWD",r],["OLDPWD",r],["OPTIND","1"],...Object.entries(t.env??{})]);if(t.fetch?this.secureFetch=t.fetch:t.network&&(this.secureFetch=sa(t.network)),this.sleepFn=t.sleep,this.traceFn=t.trace,this.logger=t.logger,this.defenseInDepthConfig=t.defenseInDepth??!0,this.coverageWriter=t.coverage,this.state={env:s,arrays:new Map,cwd:r,previousDir:"/home/user",functions:new Map,localScopes:[],callDepth:0,sourceDepth:0,commandCount:0,lastExitCode:0,lastSubstitutionExitCode:null,lastArg:"",startTime:Date.now(),lastBackgroundPid:0,virtualPid:t.processInfo?.pid??1,virtualPpid:t.processInfo?.ppid??0,virtualUid:t.processInfo?.uid??1e3,virtualGid:t.processInfo?.gid??1e3,bashPid:t.processInfo?.pid??1,nextVirtualPid:(t.processInfo?.pid??1)+1,currentLine:1,options:{errexit:!1,pipefail:!1,nounset:!1,xtrace:!1,verbose:!1,posix:!1,allexport:!1,noclobber:!1,noglob:!1,noexec:!1,vi:!1,emacs:!1},shoptOptions:{extglob:!1,dotglob:!1,nullglob:!1,failglob:!1,globstar:!1,globskipdots:!0,nocaseglob:!1,nocasematch:!1,expand_aliases:!1,lastpipe:!1,xpg_echo:!1},inCondition:!1,loopDepth:0,exportedVars:new Set(["HOME","PATH","PWD","OLDPWD",...Object.keys(t.env||{})]),readonlyVars:new Set(["SHELLOPTS","BASHOPTS"]),hashTable:new Map},this.state.env.set("SHELLOPTS",Zs(this.state.options)),this.state.env.set("BASHOPTS",Qs(this.state.shoptOptions)),Na(n,this.useDefaultLayout,{pid:this.state.virtualPid,ppid:this.state.virtualPpid,uid:this.state.virtualUid,gid:this.state.virtualGid}),r!=="/"&&(n instanceof bt||n instanceof fn))try{n.mkdirSync(r,{recursive:!0})}catch{}for(let o of pa(t.commands))this.registerBundledCommand(o);if(t.fetch||t.network)for(let o of ha())this.registerBundledCommand(o);if(t.python)for(let o of ma())this.registerBundledCommand(o);let i=typeof t.javascript=="object"?t.javascript:Object.create(null);if(t.javascript||i.invokeTool){for(let o of ya())this.registerBundledCommand(o);i.bootstrap&&(this.jsBootstrapCode=i.bootstrap),i.invokeTool&&(this.invokeToolFn=i.invokeTool)}if(t.customCommands)for(let o of t.customCommands)if(Sa(o)){let a=Aa(o);this.registerCommandInternal(a,!0)}else this.registerCommandInternal(o,!0)}registerCommand(t){this.registerCommandInternal(t,!0)}registerBundledCommand(t){this.registerCommandInternal(t,!1)}registerCommandInternal(t,n,r=n?t.trusted??!0:t.trusted){let s=this.commands.get(t.name),i=n?s?.internalOriginalCommand??(s&&!s.internalIsExtension?s:void 0):void 0,o={name:t.name,trusted:r,internalIsExtension:n,internalOriginalCommand:i,execute:(l,u)=>t.execute(l,u)};this.commands.set(t.name,o);let a=this.fs;if(typeof a.writeFileSync=="function"){let l=`#!/bin/bash
794
+ `);l!==-1&&(i=i.slice(l+1))}let o=e.state.loopDepth,a=na(e.state);e.state.parentHasLoopContext=o>0,e.state.loopDepth=0,e.state.bashPid=e.state.nextVirtualPid++,r&&(e.state.groupStdin=r),e.state.currentSource=t,e.state.env.set("0",t),e.state.env.set("#",String(n.length)),e.state.env.set("@",n.join(" ")),e.state.env.set("*",n.join(" "));for(let l=0;l<n.length&&l<9;l++)e.state.env.set(String(l+1),n[l]);for(let l=n.length+1;l<=9;l++)e.state.env.delete(String(l));try{let u=new G().parse(i),c=await s(u);return a(),c}catch(l){if(a(),l instanceof U)return T(l.stdout,l.stderr,l.exitCode);if(l instanceof C)throw l;if(l.name==="ParseException")return L(`bash: ${t}: ${l.message}
795
+ `);throw l}}function Cm(e){throw new TypeError(`Unsupported command node: ${JSON.stringify(e)}`)}var vr=class{ctx;constructor(t,n){this.ctx={state:n,fs:t.fs,commands:t.commands,limits:t.limits,executionScope:t.executionScope,execFn:t.exec,executeScript:this.executeScript.bind(this),executeStatement:this.executeStatement.bind(this),executeCommand:this.executeCommand.bind(this),fetch:t.fetch,sleep:t.sleep,trace:t.trace,coverage:t.coverage,requireDefenseContext:t.requireDefenseContext??!1,jsBootstrapCode:t.jsBootstrapCode,invokeTool:t.invokeTool}}assertDefenseContext(t){if(!this.ctx.requireDefenseContext||_e.isInSandboxedContext())return;let n=`interpreter ${t} attempted outside defense context`;throw new vn(n,{timestamp:Date.now(),type:"missing_defense_context",message:n,path:"DefenseInDepthBox.context",stack:new Error().stack,executionId:_e.getCurrentExecutionId()})}buildExportedEnv(){let t=this.ctx.state.exportedVars,n=this.ctx.state.tempExportedVars,r=new Set;if(t)for(let i of t)r.add(i);if(n)for(let i of n)r.add(i);if(r.size===0)return Object.create(null);let s=Object.create(null);for(let i of r){let o=this.ctx.state.env.get(i);o!==void 0&&(s[i]=o)}return s}async executeScript(t){this.assertDefenseContext("execution");let n=0,r=new Bt(this.ctx.executionScope,"script");for(let s of t.statements)try{let i=await this.executeStatement(s);r.appendResult(i,zs(i)),n=i.exitCode,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n))}catch(i){if(i instanceof U)throw i.prependOutput(r.stdout,r.stderr),i;if(i instanceof et)return r.append("stdout",i.stdout,i.internalOutputAccounting.stdout),r.append("stderr",i.stderr,i.internalOutputAccounting.stderr),n=i.exitCode,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n)),{...r.build(n),exitCode:n,env:Mt(this.ctx.state.env)};if(i instanceof C)throw r.prependTo(i),i;if(i instanceof Me)return r.append("stdout",i.stdout,i.internalOutputAccounting.stdout),r.append("stderr",i.stderr,i.internalOutputAccounting.stderr),n=i.exitCode,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n)),{...r.build(n),exitCode:n,env:Mt(this.ctx.state.env)};if(i instanceof Be)return r.append("stdout",i.stdout,i.internalOutputAccounting.stdout),r.append("stderr",i.stderr,i.internalOutputAccounting.stderr),n=1,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n)),{...r.build(n),exitCode:n,env:Mt(this.ctx.state.env)};if(i instanceof Ze)return r.append("stdout",i.stdout,i.internalOutputAccounting.stdout),r.append("stderr",i.stderr,i.internalOutputAccounting.stderr),n=1,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n)),{...r.build(n),exitCode:n,env:Mt(this.ctx.state.env)};if(i instanceof oe){r.append("stdout",i.stdout,i.internalOutputAccounting.stdout),r.append("stderr",i.stderr,i.internalOutputAccounting.stderr),n=1,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n));continue}if(i instanceof Cr){r.append("stdout",i.stdout,i.internalOutputAccounting.stdout),r.append("stderr",i.stderr,i.internalOutputAccounting.stderr),n=1,this.ctx.state.lastExitCode=n,this.ctx.state.env.set("?",String(n));continue}if(i instanceof Ge||i instanceof He){if(this.ctx.state.loopDepth>0)throw i.prependOutput(r.stdout,r.stderr),i;r.append("stdout",i.stdout),r.append("stderr",i.stderr);continue}throw i instanceof Ie&&i.prependOutput(r.stdout,r.stderr),i}return{...r.build(n),env:Mt(this.ctx.state.env)}}async executeUserScript(t,n,r=""){return vf(this.ctx,t,n,r,s=>this.executeScript(s))}async executeStatement(t){if(this.assertDefenseContext("statement"),this.ctx.state.signal?.aborted)throw new We;if(t.deferredError)throw new ve(t.deferredError.message,t.line??1,1);if(this.ctx.state.options.noexec)return J;this.ctx.state.errexitSafe=!1;let n=new Bt(this.ctx.executionScope,"statement");this.ctx.state.options.verbose&&!this.ctx.state.suppressVerbose&&t.sourceText&&n.append("stderr",`${t.sourceText}
796
+ `);let r=0,s=-1,i=!1;try{for(let l=0;l<t.pipelines.length;l++){let u=t.pipelines[l],c=l>0?t.operators[l-1]:null;if(c==="&&"&&r!==0||c==="||"&&r===0)continue;let f=await this.executePipeline(u);n.appendResult(f,zs(f)),r=f.exitCode,s=l,i=u.negated,this.ctx.state.lastExitCode=r,this.ctx.state.env.set("?",String(r))}}catch(l){throw n.prependTo(l),l}let o=s<t.pipelines.length-1,a=this.ctx.state.errexitSafe;if(this.ctx.state.errexitSafe=o||i||a,this.ctx.state.options.errexit&&r!==0&&s===t.pipelines.length-1&&!i&&!this.ctx.state.inCondition&&!a){let l=new Me(r);throw l.prependOutput(n.stdout,n.stderr),l}return n.build(r)}async executePipeline(t){return bf(this.ctx,t,(n,r,s)=>this.executeCommand(n,r,s))}async executeCommand(t,n,r=!1){let s=qu(this.ctx),i;try{i=await this.executeCommandInner(t,n,r)}catch(a){throw await Bi(this.ctx,s).catch(()=>{}),a}let o=await Bi(this.ctx,s);return!o.stdout&&!o.stderr?i:{...i,stdout:o.stdout?_t(i)+o.stdout:i.stdout,stdoutKind:o.stdout?"bytes":i.stdoutKind,stderr:i.stderr+o.stderr}}async executeCommandInner(t,n,r){switch(this.assertDefenseContext("command"),this.ctx.coverage?.hit(`bash:cmd:${t.type}`),t.type){case"SimpleCommand":return this.executeSimpleCommand(t,n,r);case"If":return hf(this.ctx,t);case"For":return mf(this.ctx,t);case"CStyleFor":return yf(this.ctx,t);case"While":return gf(this.ctx,t,n);case"Until":return wf(this.ctx,t,n);case"Case":return Ef(this.ctx,t);case"Subshell":return this.executeSubshell(t,n,r);case"Group":return this.executeGroup(t,n,r);case"FunctionDef":return xc(this.ctx,t);case"ArithmeticCommand":return this.executeArithmeticCommand(t);case"ConditionalCommand":return this.executeConditionalCommand(t);default:return Cm(t)}}async executeSimpleCommand(t,n,r){let s;try{return await this.executeSimpleCommandInner(t,n,r,i=>{s=i})}catch(i){if(s?.finish(),i instanceof Lt)return L(i.stderr);throw i}}async executeSimpleCommandInner(t,n,r,s){if(t.line!==void 0&&(this.ctx.state.currentLine=t.line),this.ctx.state.shoptOptions.expand_aliases&&t.name){let D=t,R=0;for(;;){let B=this.expandAlias(D);if(B===D)break;if(R>=this.ctx.limits.maxCallDepth)throw new C(`alias expansion depth limit exceeded (${this.ctx.limits.maxCallDepth})`,"recursion");R++,D=B}this.aliasExpansionStack.clear(),D!==t&&(t=D)}this.ctx.state.expansionStderr="",this.ctx.state.lastSubstitutionExitCode=null;let i=await tf(this.ctx,t);if(i.error)return i.error;let o=i.tempAssignments,a=i.xtraceOutput,l=()=>{for(let[D,R]of o)R===void 0?this.ctx.state.env.delete(D):this.ctx.state.env.set(D,R)};if(!t.name){if(t.redirections.length>0){let R=Un(this.ctx,t.redirections,Ac);s(R);let B=await R.prepare(n);if(B.error){if(l(),!B.errorCause)return R.finish(),B.error;try{return jn(B)}finally{R.finish()}}let k=T("",a,Jr(this.ctx.state,t.redirections)),M=await sn(this.ctx,k,t.redirections.length>0,B.outputRoutes);return R.finish(),M}this.ctx.state.lastArg="";let D=(this.ctx.state.expansionStderr||"")+a;return this.ctx.state.expansionStderr="",T("",D,Jr(this.ctx.state,[]))}let u=t.name&&ea(t.name,["local","declare","typeset","export","readonly"]),c=Array.from(o.keys());if(c.length>0&&!u){this.ctx.state.tempExportedVars=this.ctx.state.tempExportedVars||new Set;for(let D of c)this.ctx.state.tempExportedVars.add(D)}let f=await ne(this.ctx,t.name),d=[],p=[],h=(D,R)=>{if(d.length>=this.ctx.limits.maxArrayElements)throw new C(`expanded argument element limit exceeded (${this.ctx.limits.maxArrayElements})`,"array_elements");d.push(D),p.push(R)};if(ea(t.name,["local","declare","typeset","export","readonly"])&&(f==="local"||f==="declare"||f==="typeset"||f==="export"||f==="readonly"))for(let D of t.args){let R=await ec(this.ctx,D);if(R)h(R,!0);else{let B=await tc(this.ctx,D);if(B!==null)h(B,!0);else{let k=await gt(this.ctx,D);for(let M of k.values)h(M,k.quoted)}}}else for(let D of t.args){let R=await gt(this.ctx,D);for(let B of R.values)h(B,R.quoted)}let y=t.name.parts.every(D=>D.type==="CommandSubstitution"||D.type==="ParameterExpansion"||D.type==="ArithmeticExpansion");!f&&y&&d.length>0&&(f=d.shift(),p.shift());let b=Un(this.ctx,t.redirections,f==="exec"?vc:mr);s(b);let w=await b.prepare(n);if(w.error)return l(),w.errorCause?jn(w):(b.finish(),w.error);let E=w.stdinSourceFd,S=w.stdin!==void 0,v=r||w.stdinReplaced;if(w.stdin!==void 0&&(n=w.stdin),!f)return y?(b.finish(),T("","",Jr(this.ctx.state,t.redirections))):(b.finish(),L(`bash: : command not found
797
+ `,127));if(f==="exec"&&(d.length===0||d[0]==="--")){for(let[D,R]of o)R===void 0?this.ctx.state.env.delete(D):this.ctx.state.env.set(D,R);if(this.ctx.state.tempExportedVars)for(let D of o.keys())this.ctx.state.tempExportedVars.delete(D);return b.finish(),J}if(this.ctx.state.extraArgs){let D=this.ctx.state.extraArgs;this.ctx.state.extraArgs=void 0;for(let R of D)h(R,!0)}let A=await Jc(this.ctx,f,d);o.size>0&&(this.ctx.state.tempEnvBindings=this.ctx.state.tempEnvBindings||[],this.ctx.state.tempEnvBindings.push(new Map(o)));let x,$=null;try{x=await this.runCommand(f,d,p,n,!1,!1,E,S,v,w.stdinUnavailable)}catch(D){if(D instanceof Ge||D instanceof He)$=D,x=J;else throw D}E>=0&&f!=="read"&&nn(this.ctx,E,x.internalStdinConsumed??0);let I=a+A;if(I&&(x={...x,stderr:I+x.stderr}),x=await sn(this.ctx,x,t.redirections.length>0,w.outputRoutes,x.internalProducerCommand??f,x.internalProducerOmitsShellPrefix),b.finish(),$)throw $;if(d.length>0){let D=d[d.length-1];if((f==="declare"||f==="local"||f==="typeset")&&/^[a-zA-Z_][a-zA-Z0-9_]*=\(/.test(D)){let R=D.match(/^([a-zA-Z_][a-zA-Z0-9_]*)=\(/);R&&(D=R[1])}this.ctx.state.lastArg=D}else this.ctx.state.lastArg=f;let P=yc(f)&&f!=="unset"&&f!=="eval";if(!this.ctx.state.options.posix||!P)for(let[D,R]of o)this.ctx.state.fullyUnsetLocals?.has(D)||(R===void 0?this.ctx.state.env.delete(D):this.ctx.state.env.set(D,R));if(this.ctx.state.tempExportedVars)for(let D of o.keys())this.ctx.state.tempExportedVars.delete(D);return o.size>0&&this.ctx.state.tempEnvBindings&&this.ctx.state.tempEnvBindings.pop(),this.ctx.state.expansionStderr&&(x={...x,stderr:this.ctx.state.expansionStderr+x.stderr},this.ctx.state.expansionStderr=""),x}async runCommand(t,n,r,s,i=!1,o=!1,a=-1,l=!1,u=!1,c=!1){let f={ctx:this.ctx,runCommand:(h,m,y,b,w,E,S,v,A,x)=>this.runCommand(h,m,y,b,w,E,S,v,A,x),buildExportedEnv:()=>this.buildExportedEnv(),executeUserScript:(h,m,y)=>this.executeUserScript(h,m,y)},d=await ff(f,t,n,r,s,i,o,a,l,u,c);return d!==null?d.internalProducerCommand===void 0?{...d,internalProducerCommand:t}:d:{...await df(f,t,n,s,o,u,c),internalProducerCommand:t}}aliasExpansionStack=new Set;expandAlias(t){return Pl({env:this.ctx.state.env,limits:this.ctx.limits},t,this.aliasExpansionStack)}async findCommandInPath(t){return Ts(this.ctx,t)}async executeSubshell(t,n="",r=!1){return Sf(this.ctx,t,n,s=>this.executeStatement(s),r)}async executeGroup(t,n="",r=!1){return Af(this.ctx,t,n,s=>this.executeStatement(s),r)}async executeArithmeticCommand(t){return t.line!==void 0&&(this.ctx.state.currentLine=t.line),Je(this.ctx,t.redirections,"",async()=>{try{let n=await X(this.ctx,t.expression.expression),r=ge(n!==0);return this.ctx.state.expansionStderr&&(r={...r,stderr:this.ctx.state.expansionStderr+r.stderr},this.ctx.state.expansionStderr=""),r}catch(n){return L(`bash: arithmetic expression: ${n.message}
798
+ `)}})}async executeConditionalCommand(t){return t.line!==void 0&&(this.ctx.state.currentLine=t.line),Je(this.ctx,t.redirections,"",async()=>{try{let n=await Jt(this.ctx,t.expression),r=ge(n);return this.ctx.state.expansionStderr&&(r={...r,stderr:this.ctx.state.expansionStderr+r.stderr},this.ctx.state.expansionStderr=""),r}catch(n){let r=n instanceof oe?1:2;return L(`bash: conditional expression: ${n.message}
799
+ `,r)}})}};function ra(e){try{let t=new URL(e);return{origin:t.origin,pathname:t.pathname,href:t.href}}catch{return null}}function Nm(e){let t=ra(e);return t?{origin:t.origin,pathPrefix:t.pathname}:null}var Rm=3;function xf(e){let t=e;for(let n=0;n<Rm;n++){if(t.includes("\\")||t.includes(";")||/%(?![0-9a-f]{2})/i.test(t))return!0;let r=t.toLowerCase();if(r.includes("%2f")||r.includes("%2e")||r.includes("%5c")||r.includes("%3b"))return!0;let s;try{s=decodeURIComponent(t)}catch{return!0}if(s===t)return!1;t=s}return t.includes("%")}function Dm(e,t){return t==="/"||t===""?!0:t.endsWith("/")?e.startsWith(t):e===t||e.startsWith(`${t}/`)}function sa(e,t){let n=ra(e);if(!n)return!1;let r=Nm(t);return!r||n.origin!==r.origin||r.pathPrefix!=="/"&&r.pathPrefix!==""&&xf(n.pathname)?!1:Dm(n.pathname,r.pathPrefix)}function $f(e){return typeof e=="string"?e:e.url}function kf(e,t){return!t||t.length===0?!1:t.some(n=>sa(e,$f(n)))}function ia(e){let t=Im(e);if(t==="localhost"||t.endsWith(".localhost"))return!0;let n=Pf(t);if(n)return Bs(n);let r=_m(t);return r?Lm(r):!1}function Im(e){let t=e.trim().toLowerCase();return t.startsWith("[")&&t.endsWith("]")?t.slice(1,-1):t}function Om(e){if(!e)return null;let t=10,n=e;if(n.startsWith("0x")||n.startsWith("0X")?(t=16,n=n.slice(2)):n.length>1&&n.startsWith("0")&&(t=8),!n||t===16&&!/^[0-9a-fA-F]+$/.test(n)||t===10&&!/^\d+$/.test(n)||t===8&&!/^[0-7]+$/.test(n))return null;let r=Number.parseInt(n,t);return!Number.isFinite(r)||r<0?null:r}function Pf(e){let t=e.split(".");if(t.length===0||t.length>4)return null;let n=t.map(l=>Om(l));if(n.some(l=>l===null))return null;let r=n;if(t.length===1){let l=r[0];return l>4294967295?null:[l>>>24&255,l>>>16&255,l>>>8&255,l&255]}if(t.length===2){let[l,u]=r;return l>255||u>16777215?null:[l,u>>>16&255,u>>>8&255,u&255]}if(t.length===3){let[l,u,c]=r;return l>255||u>255||c>65535?null:[l,u,c>>>8&255,c&255]}let[s,i,o,a]=r;return s>255||i>255||o>255||a>255?null:[s,i,o,a]}function _m(e){let t=e,n=null;if(t.includes(".")){let m=t.lastIndexOf(":");if(m<0)return null;let y=t.slice(m+1),b=Pf(y);if(!b)return null;n=b,t=t.slice(0,m)}let r=t.includes("::")?t.split("::").length-1:0;if(r>1)return null;let[s,i]=t.split("::"),o=s?s.split(":").filter(Boolean):[],a=i?i.split(":").filter(Boolean):[],l=m=>/^[0-9a-f]{1,4}$/i.test(m)?Number.parseInt(m,16):null,u=o.map(l),c=a.map(l);if(u.some(m=>m===null)||c.some(m=>m===null))return null;let f=n?2:0,d=u.length+c.length+f,p=0;if(r===1){if(p=8-d,p<0)return null}else if(d!==8)return null;let h=[...u,...new Array(p).fill(0),...c];return n&&(h.push(n[0]<<8|n[1]),h.push(n[2]<<8|n[3])),h.length===8?h:null}function Bs(e){let[t,n]=e;return t===127||t===10||t===172&&n>=16&&n<=31||t===192&&n===168||t===169&&n===254||t===0||t===100&&n>=64&&n<=127||t===198&&(n===18||n===19)||t===192&&n===0&&e[2]===0||t===192&&n===0&&e[2]===2||t===198&&n===51&&e[2]===100||t===203&&n===0&&e[2]===113||t>=240}function Lm(e){if(e.every(s=>s===0)||e.slice(0,7).every(s=>s===0)&&e[7]===1||(e[0]&65472)===65152||(e[0]&65024)===64512)return!0;if(e[0]===0&&e[1]===0&&e[2]===0&&e[3]===0&&e[4]===0&&e[5]===65535){let s=[e[6]>>>8&255,e[6]&255,e[7]>>>8&255,e[7]&255];return Bs(s)}if(e[0]===8193&&e[1]===3512)return!0;if(e[0]===100&&e[1]===65435&&e[2]===0&&e[3]===0&&e[4]===0&&e[5]===0){let s=[e[6]>>>8&255,e[6]&255,e[7]>>>8&255,e[7]&255];return Bs(s)}if(e[0]===100&&e[1]===65435&&e[2]===1)return!0;if(e[0]===8194){let s=[e[1]>>>8&255,e[1]&255,e[2]>>>8&255,e[2]&255];return Bs(s)}return!1}function Cf(e){let t=[];for(let n of e){if(typeof n!="string"&&(n===null||typeof n!="object"||!("url"in n)||typeof n.url!="string")){t.push('Invalid allow-list entry: must be a string URL or an object with a "url" string property');continue}let r=$f(n);if(!ra(r)){t.push(`Invalid URL in allow-list: "${r}" - must be a valid URL with scheme and host (e.g., "https://example.com")`);continue}let i=new URL(r);if(i.protocol!=="http:"&&i.protocol!=="https:"){t.push(`Only http and https URLs are allowed in allow-list: "${r}"`);continue}if(!i.hostname){t.push(`Allow-list entry must include a hostname: "${r}"`);continue}if(i.pathname!=="/"&&i.pathname!==""&&xf(i.pathname)){t.push(`Allow-list entry contains ambiguous path separators: "${r}"`);continue}(i.search||i.hash)&&t.push(`Query strings and fragments are ignored in allow-list entries: "${r}"`)}return t}var Et=class extends Error{constructor(t,n){let r=n??"URL not in allow-list";super(`Network access denied: ${r}: ${t}`),this.name="NetworkAccessDeniedError"}},Qn=class extends Error{constructor(t){super(`Too many redirects (max: ${t})`),this.name="TooManyRedirectsError"}},ln=class extends Error{constructor(t){super(`Redirect target not in allow-list: ${t}`),this.name="RedirectNotAllowedError"}},Ws=class extends Error{constructor(t,n){super(`HTTP method '${t}' not allowed. Allowed methods: ${n.join(", ")}`),this.name="MethodNotAllowedError"}},An=class extends Error{constructor(t){super(`Response body too large (max: ${t} bytes)`),this.name="ResponseTooLargeError"}};var Tm=20,Fm=3e4,Mm=10485760,Bm=["GET","HEAD"],xr;typeof __BROWSER__<"u"&&__BROWSER__?xr=null:(xr=import("./chunks/dist-4NZ74CRE.js"),xr.catch(()=>{}));var Wm=new Set(["GET","HEAD","OPTIONS"]),Vm=new Set([301,302,303,307,308]);function $r(e){return e.reason instanceof Error?e.reason:new DOMException("The operation was aborted","AbortError")}function zm(e){if(e?.aborted)throw $r(e)}function aa(e){let t=e.allowedUrlPrefixes??[];if(e._dnsResolve)throw new Error("NetworkConfig._dnsResolve is no longer supported: DNS resolution is performed by guarded-fetch and cannot be overridden");if(e._createConnectionOwner)throw new Error("NetworkConfig._createConnectionOwner is no longer supported: connect-time IP pinning is performed by guarded-fetch and cannot be overridden");let n=e._fetch;if(!e.dangerouslyAllowFullInternetAccess){let S=Cf(t);if(S.length>0)throw new Error(`Invalid network allow-list:
800
+ ${S.join(`
801
+ `)}`)}let r=[];for(let S of t)typeof S=="object"&&S.transform&&S.transform.length>0&&r.push(S);function s(S){if(r.length===0)return null;let v=null;for(let A of r)if(sa(S,A.url)&&A.transform){v||(v=new Headers);for(let x of A.transform)for(let[$,I]of Object.entries(x.headers))v.set($,I)}return v}if(e.maxRedirects!==void 0&&(!Number.isSafeInteger(e.maxRedirects)||e.maxRedirects<0))throw new RangeError("maxRedirects must be a non-negative safe integer");let i=e.maxRedirects??Tm,o=e.timeoutMs??Fm,a=e.maxResponseSize??Mm,l=e.dangerouslyAllowFullInternetAccess?["GET","HEAD","POST","PUT","DELETE","PATCH","OPTIONS"]:e.allowedMethods??Bm,u=e.denyPrivateRanges??(typeof process<"u"&&process.env?.NODE_ENV==="production"),c=[];for(let S of t){let v=typeof S=="string"?S:S.url;try{c.push(new URL(v).hostname)}catch{}}function f(S){try{return new URL(S).hostname||"localhost.invalid"}catch{return"localhost.invalid"}}function d(S){return e.dangerouslyAllowFullInternetAccess?u?{allowedHosts:void 0,skipSsrfCheckForAllowedHosts:void 0}:{allowedHosts:[f(S)],skipSsrfCheckForAllowedHosts:!0}:{allowedHosts:c,skipSsrfCheckForAllowedHosts:!u}}function p(S){try{return ia(new URL(S).hostname)}catch{return!1}}async function h(S,v){let A={method:v.method,headers:v.headers,signal:v.signal,redirect:"manual"};return v.body!==void 0&&(A.body=v.body),await(n??globalThis.fetch)(S,A)}function m(S){if(!e.dangerouslyAllowFullInternetAccess&&!kf(S,t))throw new Et(S)}function y(S){if(!u)return;let v;try{v=new URL(S)}catch{throw new Et(S,"invalid URL")}if(ia(v.hostname))throw new Et(S,"private/loopback IP address blocked")}function b(S){if(e.dangerouslyAllowFullInternetAccess)return;let v=S.toUpperCase();if(!l.includes(v))throw new Ws(v,l)}function w(S,v,A,x){if(!A.isGuardedFetchError(S))return S;let $=S,{onRedirectHop:I,subReason:P}=x;switch($.code){case"host_not_allowed":case"protocol_not_allowed":return I?new ln(v):new Et(v);case"hostname_unsafe":return I?new ln(v):new Et(v,P==="dns_resolution_failed"?"DNS resolution failed for private IP check":"hostname resolves to private/loopback IP address");case"redirect_to_unsafe_host":return new ln(v);case"too_many_redirects":return new Qn(i);case"response_too_large":return new An(a);default:return S}}async function E(S,v={}){let A=v.method?.toUpperCase()??"GET",x=v.followRedirects??!0;if(v.maxRedirects!==void 0&&(!Number.isSafeInteger(v.maxRedirects)||v.maxRedirects<0))throw new RangeError("maxRedirects must be a non-negative safe integer");let $=v.maxRedirects??i,I=Math.min(i,$),P=v.timeoutMs!==void 0?Math.min(v.timeoutMs,o):o,N=new AbortController,D=ua(()=>N.abort(new DOMException("The operation was aborted","AbortError")),P),R=Rr(v.signal,N.signal);try{m(S),y(S),b(A);let B=xr?await xr:null,k=S,M=0,z=[],O=A,_=v.body,V=v.headers,ee=!1;for(;;){zm(R.signal);let K=await _e.runTrustedAsync(async()=>{let De=V;if(ee&&De){let Nt=De instanceof Headers?new Headers(De):new Headers(De);Nt.delete("authorization"),Nt.delete("cookie"),De=Nt}let at=s(k),Ct=Um(De,at),lt={method:O,headers:Ct,signal:R.signal,followRedirects:!1,timeoutMs:P,sanitizeHeaders:!1};if(_&&!Wm.has(O)&&(lt.body=_),Object.assign(lt,d(k)),!B||p(k)){if(u)throw new Et(k,"DNS pinning unavailable for private IP enforcement");return await h(k,lt)}u?n&&(lt.fetch=n):(lt.fetch=n??globalThis.fetch,lt.dispatcher=null);let ut;lt.onUrlBlocked=Nt=>{ut=Nt.subReason};try{return await B.guardedFetch(k,lt)}catch(Nt){throw w(Nt,k,B,{onRedirectHop:M>0,subReason:ut})}});if(Vm.has(K.status)&&x){let De=K.headers.get("location");if(!De)return await Nf(K,k,a,R.signal,z);z.push({status:K.status,statusText:K.statusText,headers:Rf(K.headers)});let at=new URL(De,k).href;await oa(qm(K),R.signal);try{m(at),y(at)}catch(ut){throw R.signal?.aborted?$r(R.signal):ut instanceof Et?new ln(at):ut}let Ct=K.status;if(((Ct===301||Ct===302)&&O==="POST"||Ct===303&&O!=="GET"&&O!=="HEAD")&&(O="GET",_=void 0,b(O)),new URL(at).origin!==new URL(k).origin&&(ee=!0),M++,M>I)throw new Qn(I);k=at;continue}return await Nf(K,k,a,R.signal,z)}}finally{ca(D),R.cleanup()}}return E}async function oa(e,t){if(!t)return e;if(t.aborted)throw e.catch(()=>{}),$r(t);let n,r=new Promise((s,i)=>{n=()=>i($r(t)),t.addEventListener("abort",n,{once:!0})});try{return await Promise.race([e,r])}finally{n&&t.removeEventListener("abort",n)}}async function qm(e){e.body&&!e.body.locked&&await e.body.cancel()}function Um(e,t){if(!e&&!t)return;if(!t)return e;let n=e instanceof Headers?new Headers(e):new Headers(e);for(let[r,s]of t)n.set(r,s);return n}function Rf(e){let t=Object.create(null);return e.forEach((n,r)=>{t[r.toLowerCase()]=n}),t}async function Nf(e,t,n,r,s){let i=Rf(e.headers);if(n>0){let l=e.headers.get("content-length");if(l){let u=parseInt(l,10);if(!Number.isNaN(u)&&u>n)throw new An(n)}}let o;if(n>0&&e.body){let l=e.body.getReader(),u=[],c=0;try{for(;;){let{done:d,value:p}=await oa(l.read(),r);if(d)break;if(p){if(c+=p.byteLength,c>n)throw await l.cancel(),new An(n);u.push(p)}}}catch(d){throw r?.aborted&&await l.cancel($r(r)).catch(()=>{}),d}o=new Uint8Array(c);let f=0;for(let d of u)o.set(d,f),f+=d.byteLength}else{let l=await oa(e.arrayBuffer(),r);if(n>0&&l.byteLength>n)throw new An(n);o=new Uint8Array(l)}let a={status:e.status,statusText:e.statusText,headers:i,body:o,url:t};return s&&s.length>0&&(a.redirectChain=s),a}function la(e,t){if(e.length>t||W(e)>t)throw new C(`script input size limit exceeded (${t} bytes)`,"string_length")}var Df="/usr/bin:/bin",If=[["OSTYPE","linux-gnu"],["MACHTYPE","x86_64-pc-linux-gnu"],["HOSTTYPE","x86_64"],["HOSTNAME","localhost"]],Vs=class{fs;commands=new Map;useDefaultLayout=!1;limits;secureFetch;sleepFn;traceFn;logger;defenseInDepthConfig;coverageWriter;jsBootstrapCode;invokeToolFn;transformPlugins=[];state;constructor(t={}){this.limits=Zs({...t.executionLimits,...t.maxCallDepth!==void 0&&{maxCallDepth:t.maxCallDepth},...t.maxCommandCount!==void 0&&{maxCommandCount:t.maxCommandCount},...t.maxLoopIterations!==void 0&&{maxLoopIterations:t.maxLoopIterations}},t.executionLimitProfile);let n=t.fs??new bt(t.files,{maxTotalBytes:this.limits.maxFileSystemBytes});this.fs=n,this.useDefaultLayout=!t.cwd&&!t.files;let r=t.cwd||(this.useDefaultLayout?"/home/user":"/"),s=new Map([["HOME",this.useDefaultLayout?"/home/user":"/"],["PATH",Df],["IFS",`
802
+ `],...If,["PWD",r],["OLDPWD",r],["OPTIND","1"],...Object.entries(t.env??{})]);if(t.fetch?this.secureFetch=t.fetch:t.network&&(this.secureFetch=aa(t.network)),this.sleepFn=t.sleep,this.traceFn=t.trace,this.logger=t.logger,this.defenseInDepthConfig=t.defenseInDepth??!0,this.coverageWriter=t.coverage,this.state={env:s,arrays:new Map,cwd:r,previousDir:"/home/user",functions:new Map,localScopes:[],callDepth:0,sourceDepth:0,commandCount:0,lastExitCode:0,lastSubstitutionExitCode:null,lastArg:"",startTime:Date.now(),lastBackgroundPid:0,virtualPid:t.processInfo?.pid??1,virtualPpid:t.processInfo?.ppid??0,virtualUid:t.processInfo?.uid??1e3,virtualGid:t.processInfo?.gid??1e3,bashPid:t.processInfo?.pid??1,nextVirtualPid:(t.processInfo?.pid??1)+1,currentLine:1,options:{errexit:!1,pipefail:!1,nounset:!1,xtrace:!1,verbose:!1,posix:!1,allexport:!1,noclobber:!1,noglob:!1,noexec:!1,vi:!1,emacs:!1},shoptOptions:{extglob:!1,dotglob:!1,nullglob:!1,failglob:!1,globstar:!1,globskipdots:!0,nocaseglob:!1,nocasematch:!1,expand_aliases:!1,lastpipe:!1,xpg_echo:!1},inCondition:!1,loopDepth:0,exportedVars:new Set(["HOME","PATH","PWD","OLDPWD",...Object.keys(t.env||{})]),readonlyVars:new Set(["SHELLOPTS","BASHOPTS"]),hashTable:new Map},this.state.env.set("SHELLOPTS",Lr(this.state.options)),this.state.env.set("BASHOPTS",Tr(this.state.shoptOptions)),Oa(n,this.useDefaultLayout,{pid:this.state.virtualPid,ppid:this.state.virtualPpid,uid:this.state.virtualUid,gid:this.state.virtualGid}),r!=="/"&&(n instanceof bt||n instanceof fn))try{n.mkdirSync(r,{recursive:!0})}catch{}for(let o of ga(t.commands))this.registerBundledCommand(o);if(t.fetch||t.network)for(let o of wa())this.registerBundledCommand(o);if(t.python)for(let o of Ea())this.registerBundledCommand(o);let i=typeof t.javascript=="object"?t.javascript:Object.create(null);if(t.javascript||i.invokeTool){for(let o of ba())this.registerBundledCommand(o);i.bootstrap&&(this.jsBootstrapCode=i.bootstrap),i.invokeTool&&(this.invokeToolFn=i.invokeTool)}if(t.customCommands)for(let o of t.customCommands)if($a(o)){let a=ka(o);this.registerCommandInternal(a,!0)}else this.registerCommandInternal(o,!0)}registerCommand(t){this.registerCommandInternal(t,!0)}registerBundledCommand(t){this.registerCommandInternal(t,!1)}registerCommandInternal(t,n,r=n?t.trusted??!0:t.trusted){let s=this.commands.get(t.name),i=n?s?.internalOriginalCommand??(s&&!s.internalIsExtension?s:void 0):void 0,o={name:t.name,trusted:r,internalIsExtension:n,internalOriginalCommand:i,execute:(l,u)=>t.execute(l,u)};this.commands.set(t.name,o);let a=this.fs;if(typeof a.writeFileSync=="function"){let l=`#!/bin/bash
802
803
  # Built-in command: ${t.name}
803
- `;try{a.writeFileSync(`/bin/${t.name}`,l)}catch{}try{a.writeFileSync(`/usr/bin/${t.name}`,l)}catch{}}}logResult(t){return this.logger&&(t.stdout&&this.logger.debug("stdout",{output:t.stdout}),t.stderr&&this.logger.info("stderr",{output:t.stderr}),this.logger.info("exit",{exitCode:t.exitCode})),t.stdout=Cf(t.stdout),t.stderr=Cf(t.stderr),t}async exec(t,n){let r=new Rr(this.limits,n?.signal),s;try{s=await this.execInScope(t,n,r,0,n?.signal,!1,!1)}catch(o){try{await r.close()}catch{}throw o}let i=s;try{await r.close()}catch{i={...s,stderr:`${s.stderr}bash: execution cleanup failed
804
- `,exitCode:126}}return t.trim()?this.logResult(i):i}async execInScope(t,n,r,s,i,o=!1,a=!0){let l=f=>a?this.logResult(f):f,u=Cr(i,n?.signal),c=n?{...n,signal:u.signal}:{signal:u.signal};try{if(r.assertExecDepth(s),ia(t,this.limits.maxSourceBytes),!t.trim())return{stdout:"",stderr:"",exitCode:0,env:Qe(this.state.env,c.env)};this.logger?.info("exec",{command:t});let f=c.cwd??this.state.cwd,d,p=f;if(c.cwd)if(c.env&&"PWD"in c.env)d=c.env.PWD;else if(c.env&&!("PWD"in c.env))try{d=await this.fs.realpath(f),p=d}catch{d=f}else d=f;let h=c.replaceEnv?new Map:new Map(this.state.env);if(c.env)for(let[g,b]of Object.entries(c.env))h.set(g,b);d!==void 0&&h.set("PWD",d);let m={...this.state,env:h,arrays:c.replaceEnv?new Map:rt(this.state.arrays),cwd:p,previousDir:c.env?.OLDPWD??this.state.previousDir,functions:new Map(this.state.functions),localScopes:[...this.state.localScopes],options:{...this.state.options},hashTable:this.state.hashTable,groupStdin:Wm(c.stdin,c.stdinKind,this.limits.maxInputBytes,this.limits.maxStringLength,r,o),signal:c.signal,extraArgs:c.args},E=t;c.rawScript||(E=Pf(t));let S=this.defenseInDepthConfig?_e.getInstance(this.defenseInDepthConfig):null,y=S?.activate();try{let g=async()=>{let b=dt(E,{maxHeredocSize:this.limits.maxHeredocSize}),v;if(this.transformPlugins.length>0){let $=Object.create(null);for(let C of this.transformPlugins){let D=C.transform({ast:b,metadata:$});b=D.ast,D.metadata&&($=Bs($,D.metadata))}v=$}let x={fs:this.fs,commands:this.commands,limits:this.limits,executionScope:r,exec:($,C,D=!1)=>this.execInScope($,C,r,s+1,c.signal,D),fetch:this.secureFetch,sleep:this.sleepFn,trace:this.traceFn,coverage:this.coverageWriter,requireDefenseContext:S?.isEnabled()===!0,jsBootstrapCode:this.jsBootstrapCode,invokeTool:this.invokeToolFn},N=await new Sr(x,m).executeScript(b);return v&&(N.metadata=v),l(N)};return y?await y.run(g):await g()}catch(g){if(g instanceof q)return l({stdout:g.stdout,stderr:g.stderr,exitCode:g.exitCode,internalOutputAccounting:g.internalOutputAccounting,env:Qe(this.state.env,c.env)});if(g instanceof tt)return l({stdout:g.stdout,stderr:g.stderr,exitCode:g.exitCode,env:Qe(this.state.env,c.env)});if(g instanceof oe)return l({stdout:g.stdout,stderr:g.stderr,exitCode:1,env:Qe(this.state.env,c.env)});if(g instanceof We)return l({stdout:g.stdout,stderr:g.stderr,exitCode:124,env:Qe(this.state.env,c.env)});if(g instanceof P)return l({stdout:g.stdout,stderr:Ve(g.stderr),exitCode:P.EXIT_CODE,internalOutputAccounting:g.internalOutputAccounting,env:Qe(this.state.env,c.env)});if(g instanceof An)return l({stdout:"",stderr:`bash: security violation: ${Ve(g.message)}
805
- `,exitCode:1,env:Qe(this.state.env,c.env)});if(g.name==="ParseException")return l({stdout:"",stderr:`bash: syntax error: ${Ve(g.message)}
806
- `,exitCode:2,env:Qe(this.state.env,c.env)});if(g instanceof Ke)return l({stdout:"",stderr:`bash: ${Ve(g.message)}
807
- `,exitCode:2,env:Qe(this.state.env,c.env)});if(g instanceof RangeError)return l({stdout:"",stderr:`bash: ${Ve(g.message)}
808
- `,exitCode:1,env:Qe(this.state.env,c.env)});throw g}finally{y?.deactivate()}}catch(f){if(f instanceof We)return l({stdout:f.stdout,stderr:f.stderr,exitCode:124,env:Qe(this.state.env,c.env)});if(f instanceof P)return l({stdout:f.stdout,stderr:Ve(f.stderr),exitCode:P.EXIT_CODE,internalOutputAccounting:f.internalOutputAccounting,env:Qe(this.state.env,c.env)});throw f}finally{u.cleanup()}}async readFile(t){return this.fs.readFile(this.fs.resolvePath(this.state.cwd,t))}async writeFile(t,n){return this.fs.writeFile(this.fs.resolvePath(this.state.cwd,t),n)}getCwd(){return this.state.cwd}getEnv(){return Mt(this.state.env)}registerTransformPlugin(t){this.transformPlugins.push(t)}transform(t){ia(t,this.limits.maxSourceBytes);let n=Pf(t),r=dt(n,{maxHeredocSize:this.limits.maxHeredocSize}),s=Object.create(null);for(let i of this.transformPlugins){let o=i.transform({ast:r,metadata:s});r=o.ast,o.metadata&&(s=Bs(s,o.metadata))}return{script:pl(r),ast:r,metadata:s}}};function Mm(e,t){let n=t;for(let r=0;r<e.length;r++){let s=e[r];if(n==="single")s==="'"&&(n="none");else if(n==="double")s==="\\"?r++:s==='"'&&(n="none");else if(s==="'")n="single";else if(s==='"')n="double";else if(s==="\\")r++;else if(s==="#"&&(r===0||/\s/.test(e[r-1])))break}return n}function Pf(e){let t=e.split(`
809
- `),n=[],r=[],s="none";for(let i=0;i<t.length;i++){let o=t[i];if(r.length>0){let c=r[r.length-1];if((c.stripTabs?o.replace(/^\t+/,""):o)===c.delimiter){n.push(o.trimStart()),r.pop();continue}n.push(o);continue}let a=s,l=a==="none"?o.trimStart():o;if(n.push(l),s=Mm(o,a),a!=="none")continue;let u=/<<(-?)\s*(['"]?)([\w-]+)\2/g;for(let c of l.matchAll(u)){let f=c[1]==="-",d=c[3];r.push({delimiter:d,stripTabs:f})}}return n.join(`
810
- `)}var Bm=new TextDecoder("utf-8",{fatal:!0});function Cf(e){if(!e)return e;let t=!1;for(let r=0;r<e.length;r++){let s=e.charCodeAt(r);if(s>255)return e;s>127&&(t=!0)}if(!t)return e;let n=new Uint8Array(e.length);for(let r=0;r<e.length;r++)n[r]=e.charCodeAt(r);try{return Bm.decode(n)}catch{return e}}function Wm(e,t,n,r,s,i){if(e===void 0)return;let o=t==="bytes"?e.length:F(e);if(o>n||o>r)throw new P(`stdin size limit exceeded (${Math.min(n,r)} bytes)`,"string_length");return i||s.consumeInput(o,"stdin"),t==="bytes"?e:un(e)}import*as pe from"node:fs";import*as Re from"node:path";import*as at from"node:fs";import*as $e from"node:path";function $r(e,t){let n=/^[A-Za-z]:[\\/]/.test(t)?$e.win32:$e.posix,r=n.relative(t,e);return r===""||r!==".."&&!r.startsWith(`..${n.sep}`)&&!n.isAbsolute(r)}function xr(e,t){try{let n=at.realpathSync(e);return $r(n,t)?n:null}catch(n){if(n.code==="ENOENT"){let r=$e.dirname(e);if(r===e)return null;let s=xr(r,t);if(s===null)return null;try{if(at.lstatSync(e).isSymbolicLink()){let o=at.readlinkSync(e),a=$e.isAbsolute(o)?o:$e.resolve($e.dirname(e),o),l=xr(a,t);return l===null?null:l}}catch{}return $e.join(s,$e.basename(e))}return null}}function Nf(e,t,n){let r=xr(e,n);if(r===null)return null;let s=$e.resolve(e),i=s.slice(t.length),o=r.slice(n.length);if(i!==o)return null;try{if(at.lstatSync(s).isSymbolicLink())return null}catch{}return r}function Rf(e,t){if(!at.existsSync(e))throw new Error(`${t} root does not exist`);if(!at.statSync(e).isDirectory())throw new Error(`${t} root is not a directory`)}function Df(e,t){if(!$e.isAbsolute(e))return{withinRoot:!0,relativePath:e};let n;try{n=at.realpathSync(e)}catch{n=$e.resolve(e)}return $r(n,t)?{withinRoot:!0,relativePath:n.slice(t.length).replace(/\\/g,"/")||"/"}:{withinRoot:!1,safeName:$e.basename(e)}}function If(e,t,n,r){let s=e;if(s.path===void 0){for(let o of r)if(s.message?.includes(o))throw e}let i=s.code||"EIO";throw new Error(`${i}: ${n} '${t}'`)}var Vm=["ELOOP","EFBIG","EPERM"],zm="/home/user/project",Qn=class{root;canonicalRoot;mountPoint;readOnly;maxFileReadSize;maxMemoryBytes;allowSymlinks;memory=new Map;deleted=new Set;nextMemoryIdentity=1;retainedMemoryBytes=0;memoryEntryBytes(t){if(!t||t.type!=="file")return 0;let n=t.content.byteLength;for(let r of t.appendChunks??[])n+=r.byteLength;return n}assertMemoryCapacity(t,n=0){if(!Number.isSafeInteger(t)||t<0||t>this.maxMemoryBytes-this.retainedMemoryBytes+n)throw new Error(`ENOSPC: overlay memory byte limit exceeded (${this.maxMemoryBytes} bytes)`)}setMemoryEntry(t,n){let r=this.memoryEntryBytes(this.memory.get(t)),s=this.memoryEntryBytes(n);this.assertMemoryCapacity(s,r),this.memory.set(t,n),this.retainedMemoryBytes+=s-r}deleteMemoryEntry(t){let n=this.memory.get(t);n&&(this.retainedMemoryBytes-=this.memoryEntryBytes(n),this.memory.delete(t))}identityFor(t){return t.type==="symlink"?"":(t.identity||(t.identity=`overlay:${this.nextMemoryIdentity++}`),t.identity)}constructor(t){this.root=Re.resolve(t.root);let n=t.mountPoint??zm;if(this.mountPoint=n==="/"?"/":n.replace(/\/+$/,""),!this.mountPoint.startsWith("/"))throw new Error(`Mount point must be an absolute path: ${n}`);if(this.readOnly=t.readOnly??!1,this.maxFileReadSize=t.maxFileReadSize??10485760,this.maxMemoryBytes=t.maxMemoryBytes??1024*1024*1024,!Number.isSafeInteger(this.maxMemoryBytes)||this.maxMemoryBytes<0)throw new Error("OverlayFs: invalid maxMemoryBytes");this.allowSymlinks=t.allowSymlinks??!1,Rf(this.root,"OverlayFs"),this.canonicalRoot=pe.realpathSync(this.root),this.createMountPointDirs()}assertWritable(t){if(this.readOnly)throw new Error(`EROFS: read-only file system, ${t}`)}createMountPointDirs(){let t=this.mountPoint.split("/").filter(Boolean),n="";for(let r of t)n+=`/${r}`,this.memory.has(n)||this.setMemoryEntry(n,{type:"directory",mode:493,mtime:new Date});this.memory.has("/")||this.setMemoryEntry("/",{type:"directory",mode:493,mtime:new Date})}getMountPoint(){return this.mountPoint}mkdirSync(t,n){let s=z(t).split("/").filter(Boolean),i="";for(let o of s)i+=`/${o}`,this.memory.has(i)||this.setMemoryEntry(i,{type:"directory",mode:493,mtime:new Date})}writeFileSync(t,n){let r=z(t),s=this.getDirname(r);s!=="/"&&this.mkdirSync(s);let i=n instanceof Uint8Array?n:new TextEncoder().encode(n);this.setMemoryEntry(r,{type:"file",content:i,mode:420,mtime:new Date})}getDirname(t){let n=t.lastIndexOf("/");return n===0?"/":t.slice(0,n)}getRelativeToMount(t){return this.mountPoint==="/"?t:t===this.mountPoint?"/":t.startsWith(`${this.mountPoint}/`)?t.slice(this.mountPoint.length):null}toRealPath(t){let n=z(t),r=this.getRelativeToMount(n);if(r===null)return null;let s=Re.join(this.root,r),i=Re.resolve(s);return $r(i,this.root)?i:null}resolveRealPath_(t){return t?this.allowSymlinks?xr(t,this.canonicalRoot):Nf(t,this.root,this.canonicalRoot):null}resolveRealPathParent_(t){if(!t)return null;let n=Re.dirname(t),r=this.resolveRealPath_(n);return r===null?null:Re.join(r,Re.basename(t))}sanitizeError(t,n,r){If(t,n,r,Vm)}ensureParentDirs(t){let n=ft(t);n!=="/"&&(this.memory.has(n)||(this.ensureParentDirs(n),this.setMemoryEntry(n,{type:"directory",mode:493,mtime:new Date})),this.deleted.delete(n))}async existsInOverlay(t){let n=z(t);if(this.deleted.has(n))return!1;if(this.memory.has(n))return!0;let r=this.resolveRealPathParent_(this.toRealPath(n));if(!r)return!1;try{return await pe.promises.lstat(r),!0}catch{return!1}}async readFile(t,n){let r=await this.readFileBuffer(t),s=Wt(n);return Nn(r,s)}async readFileBytes(t){let n=await this.readFileBuffer(t);return Nn(n,"binary")}async readFileBuffer(t,n=new Set){Q(t,"open");let r=z(t);if(n.has(r))throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`);if(n.add(r),this.deleted.has(r))throw new Error(`ENOENT: no such file or directory, open '${t}'`);let s=this.memory.get(r);if(s){if(s.type==="symlink"){let u=this.resolveSymlink(r,s.target);return this.readFileBuffer(u,n)}if(s.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);if(!s.appendChunks||s.appendChunks.length===0)return s.content;let o=s.appendChunks.reduce((u,c)=>u+c.byteLength,s.content.byteLength);if(!Number.isSafeInteger(o))throw new Error(`EFBIG: file too large, read '${t}'`);let a=new Uint8Array(o);a.set(s.content);let l=s.content.byteLength;for(let u of s.appendChunks)a.set(u,l),l+=u.byteLength;return s.content=a,s.appendChunks=void 0,a}let i=this.resolveRealPath_(this.toRealPath(r));if(!i)throw new Error(`ENOENT: no such file or directory, open '${t}'`);try{let o=await pe.promises.lstat(i);if(o.isSymbolicLink()){if(!this.allowSymlinks)throw new Error(`ENOENT: no such file or directory, open '${t}'`);let u=await pe.promises.readlink(i),c=this.realTargetToVirtual(r,u),f=this.resolveSymlink(r,c);return this.readFileBuffer(f,n)}if(o.isDirectory())throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);if(this.maxFileReadSize>0&&o.size>this.maxFileReadSize)throw new Error(`EFBIG: file too large, read '${t}' (${o.size} bytes, max ${this.maxFileReadSize})`);let a=this.allowSymlinks?pe.constants.O_RDONLY:pe.constants.O_RDONLY|pe.constants.O_NOFOLLOW,l=await pe.promises.open(i,a);try{let u=await l.readFile();return new Uint8Array(u)}finally{await l.close()}}catch(o){let a=o.code;if(a==="ENOENT")throw new Error(`ENOENT: no such file or directory, open '${t}'`);if(a==="ELOOP")throw new Error(`ENOENT: no such file or directory, open '${t}'`);this.sanitizeError(o,t,"open")}}async writeFile(t,n,r){Q(t,"write"),this.assertWritable(`write '${t}'`);let s=z(t);this.ensureParentDirs(s);let i=Wt(r),o=Cn(n,i);this.setMemoryEntry(s,{type:"file",content:o,mode:420,mtime:new Date}),this.deleted.delete(s)}async appendFile(t,n,r){Q(t,"append"),this.assertWritable(`append '${t}'`);let s=z(t),i=Wt(r),o=Cn(n,i),a=this.memory.get(s);if(a?.type==="file"){this.assertMemoryCapacity(o.byteLength),a.appendChunks||(a.appendChunks=[]),a.appendChunks.push(o),this.retainedMemoryBytes+=o.byteLength,a.mtime=new Date,this.deleted.delete(s);return}let l;try{l=await this.readFileBuffer(s)}catch{l=new Uint8Array(0)}this.ensureParentDirs(s),this.setMemoryEntry(s,{type:"file",content:l,appendChunks:[o],mode:420,mtime:new Date}),this.deleted.delete(s)}async exists(t){return t.includes("\0")?!1:this.existsInOverlay(t)}async stat(t,n=new Set){Q(t,"stat");let r=z(t);if(n.has(r))throw new Error(`ELOOP: too many levels of symbolic links, stat '${t}'`);if(n.add(r),this.deleted.has(r))throw new Error(`ENOENT: no such file or directory, stat '${t}'`);let s=this.memory.get(r);if(s){if(s.type==="symlink"){let a=this.resolveSymlink(r,s.target);return this.stat(a,n)}let o=0;return s.type==="file"&&(o=s.content.length+(s.appendChunks?.reduce((a,l)=>a+l.byteLength,0)??0)),{isFile:s.type==="file",isDirectory:s.type==="directory",isSymbolicLink:!1,mode:s.mode,size:o,mtime:s.mtime,identity:this.identityFor(s)}}let i=this.resolveRealPath_(this.toRealPath(r));if(!i)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);try{let o=await pe.promises.lstat(i);if(o.isSymbolicLink()){if(!this.allowSymlinks)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);let a=await pe.promises.readlink(i),l=this.realTargetToVirtual(r,a),u=this.resolveSymlink(r,l);return this.stat(u,n)}return{isFile:o.isFile(),isDirectory:o.isDirectory(),isSymbolicLink:!1,mode:o.mode,size:o.size,mtime:o.mtime,dev:o.dev,ino:o.ino}}catch(o){if(o.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, stat '${t}'`);this.sanitizeError(o,t,"stat")}}async lstat(t){Q(t,"lstat");let n=z(t);if(this.deleted.has(n))throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);let r=this.memory.get(n);if(r){if(r.type==="symlink")return{isFile:!1,isDirectory:!1,isSymbolicLink:!0,mode:r.mode,size:r.target.length,mtime:r.mtime};let i=0;return r.type==="file"&&(i=r.content.length+(r.appendChunks?.reduce((o,a)=>o+a.byteLength,0)??0)),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:i,mtime:r.mtime,identity:this.identityFor(r)}}let s=this.resolveRealPathParent_(this.toRealPath(n));if(!s)throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);try{let i=await pe.promises.lstat(s);return{isFile:i.isFile(),isDirectory:i.isDirectory(),isSymbolicLink:i.isSymbolicLink(),mode:i.mode,size:i.size,mtime:i.mtime,dev:i.dev,ino:i.ino}}catch(i){if(i.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);this.sanitizeError(i,t,"lstat")}}resolveSymlink(t,n){return Pn(t,n)}realTargetToVirtual(t,n){let r=Df(n,this.canonicalRoot);if(r.withinRoot){if(!Re.isAbsolute(n))return n;let s=r.relativePath;return this.mountPoint==="/"?s:`${this.mountPoint}${s}`}return r.safeName}async mkdir(t,n){Q(t,"mkdir"),this.assertWritable(`mkdir '${t}'`);let r=z(t);if(await this.existsInOverlay(r)){if(!n?.recursive)throw new Error(`EEXIST: file already exists, mkdir '${t}'`);return}let i=ft(r);if(i!=="/"&&!await this.existsInOverlay(i))if(n?.recursive)await this.mkdir(i,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${t}'`);this.setMemoryEntry(r,{type:"directory",mode:493,mtime:new Date}),this.deleted.delete(r)}async readdirCore(t,n){if(this.deleted.has(n))throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);let r=new Map,s=new Set,i=n==="/"?"/":`${n}/`;for(let a of this.deleted)if(a.startsWith(i)){let l=a.slice(i.length),u=l.split("/")[0];u&&!l.includes("/",u.length)&&s.add(u)}for(let[a,l]of this.memory)if(a!==n&&a.startsWith(i)){let u=a.slice(i.length),c=u.split("/")[0];c&&!s.has(c)&&!u.includes("/",1)&&r.set(c,{name:c,isFile:l.type==="file",isDirectory:l.type==="directory",isSymbolicLink:l.type==="symlink"})}let o=this.resolveRealPath_(this.toRealPath(n));if(o)try{if(!this.allowSymlinks&&(await pe.promises.lstat(o)).isSymbolicLink()){if(!this.memory.has(n))throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);return r}let a=await pe.promises.readdir(o,{withFileTypes:!0});for(let l of a)!s.has(l.name)&&!r.has(l.name)&&r.set(l.name,{name:l.name,isFile:l.isFile(),isDirectory:l.isDirectory(),isSymbolicLink:l.isSymbolicLink()})}catch(a){if(a.code==="ENOENT"){if(!this.memory.has(n))throw new Error(`ENOENT: no such file or directory, scandir '${t}'`)}else a.code!=="ENOTDIR"&&this.sanitizeError(a,t,"scandir")}return r}async resolveForReaddir(t,n=!1){let r=z(t),s=new Set,i=n,o=this.memory.get(r);for(;o&&o.type==="symlink";){if(s.has(r))throw new Error(`ELOOP: too many levels of symbolic links, scandir '${t}'`);s.add(r),i=!0,r=this.resolveSymlink(r,o.target),o=this.memory.get(r)}if(o)return{normalized:r,outsideOverlay:!1};if(this.getRelativeToMount(r)===null)return{normalized:r,outsideOverlay:!0};let l=this.resolveRealPath_(this.toRealPath(r));if(!l)return{normalized:r,outsideOverlay:!0};try{if((await pe.promises.lstat(l)).isSymbolicLink()){if(!this.allowSymlinks)return{normalized:r,outsideOverlay:!0};let c=await pe.promises.readlink(l),f=this.realTargetToVirtual(r,c),d=this.resolveSymlink(r,f);return this.resolveForReaddir(d,!0)}return{normalized:r,outsideOverlay:!1}}catch{return i?{normalized:r,outsideOverlay:!0}:{normalized:r,outsideOverlay:!1}}}async createExclusive(t,n){let r=n.directory?"mkdir":"open";Q(t,r),this.assertWritable(`${r} '${t}'`);let s=z(t);if(await this.existsInOverlay(s))throw new Error(`EEXIST: file already exists, ${r} '${t}'`);let i=ft(s),o=s;if(i!=="/"){let a;try{a=await this.realpath(i)}catch{throw new Error(`ENOENT: no such file or directory, ${r} '${t}'`)}let l=await this.stat(a).catch(()=>null);if(!l)throw new Error(`ENOENT: no such file or directory, ${r} '${t}'`);if(!l.isDirectory)throw new Error(`ENOTDIR: not a directory, ${r} '${t}'`);if(o=nt(a,s.slice(s.lastIndexOf("/")+1)),o!==s&&await this.existsInOverlay(o))throw new Error(`EEXIST: file already exists, ${r} '${t}'`)}if(this.memory.has(o))throw new Error(`EEXIST: file already exists, ${r} '${t}'`);this.setMemoryEntry(o,n.directory?{type:"directory",mode:n.mode,mtime:new Date}:{type:"file",content:new Uint8Array(0),mode:n.mode,mtime:new Date}),this.deleted.delete(o)}async readdir(t){Q(t,"scandir");let{normalized:n,outsideOverlay:r}=await this.resolveForReaddir(t);if(r)return[];let s=await this.readdirCore(t,n);return Array.from(s.keys()).sort((i,o)=>i<o?-1:i>o?1:0)}async readdirWithFileTypes(t){Q(t,"scandir");let{normalized:n,outsideOverlay:r}=await this.resolveForReaddir(t);if(r)return[];let s=await this.readdirCore(t,n);return Array.from(s.values()).sort((i,o)=>i.name<o.name?-1:i.name>o.name?1:0)}async rm(t,n){Q(t,"rm"),this.assertWritable(`rm '${t}'`);let r=z(t);if(!await this.existsInOverlay(r)){if(n?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${t}'`)}try{if((await this.stat(r)).isDirectory){let o=await this.readdir(r);if(o.length>0){if(!n?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${t}'`);for(let a of o){let l=r==="/"?`/${a}`:`${r}/${a}`;await this.rm(l,n)}}}}catch(i){if(i instanceof Error&&(i.message.includes("ENOTEMPTY")||i.message.includes("EISDIR")))throw i}this.deleteMemoryEntry(r),this.existsOnRealFs(r)&&this.deleted.add(r)}existsOnRealFs(t){let n=this.toRealPath(t),r=this.resolveRealPathParent_(n);if(!r)return!1;try{return pe.lstatSync(r),!0}catch{return!1}}async cp(t,n,r){Q(t,"cp"),Q(n,"cp"),this.assertWritable(`cp '${n}'`);let s=z(t),i=z(n);if(!await this.existsInOverlay(s))throw new Error(`ENOENT: no such file or directory, cp '${t}'`);let a=await this.stat(s);if(a.isFile){let l=await this.readFileBuffer(s);await this.writeFile(i,l)}else if(a.isDirectory){if(!r?.recursive)throw new Error(`EISDIR: is a directory, cp '${t}'`);if(Dt(s,i))throw new Error(`EINVAL: cannot copy '${t}' into itself, '${n}'`);await this.mkdir(i,{recursive:!0});let l=await this.readdir(s);for(let u of l){let c=s==="/"?`/${u}`:`${s}/${u}`,f=i==="/"?`/${u}`:`${i}/${u}`;await this.cp(c,f,r)}}}async mv(t,n){this.assertWritable(`mv '${n}'`),await this.cp(t,n,{recursive:!0}),await this.rm(t,{recursive:!0})}resolvePath(t,n){return kn(t,n)}getAllPaths(){let t=new Set(this.memory.keys());for(let n of this.deleted)t.delete(n);return this.scanRealFs("/",t),Array.from(t)}scanRealFs(t,n){if(this.deleted.has(t))return;let r=this.resolveRealPath_(this.toRealPath(t));if(r)try{let s=pe.readdirSync(r);for(let i of s){let o=t==="/"?`/${i}`:`${t}/${i}`;if(this.deleted.has(o))continue;n.add(o);let a=Re.join(r,i);pe.lstatSync(a).isDirectory()&&this.scanRealFs(o,n)}}catch{}}async chmod(t,n){Q(t,"chmod"),this.assertWritable(`chmod '${t}'`);let r=z(t);if(!await this.existsInOverlay(r))throw new Error(`ENOENT: no such file or directory, chmod '${t}'`);let i=this.memory.get(r);if(i){i.mode=n;return}let o=await this.stat(r);if(o.isFile){let a=await this.readFileBuffer(r);this.setMemoryEntry(r,{type:"file",content:a,mode:n,mtime:new Date})}else o.isDirectory&&this.setMemoryEntry(r,{type:"directory",mode:n,mtime:new Date})}async symlink(t,n){if(!this.allowSymlinks)throw new Error(`EPERM: operation not permitted, symlink '${n}'`);Q(n,"symlink"),this.assertWritable(`symlink '${n}'`);let r=z(n);if(await this.existsInOverlay(r))throw new Error(`EEXIST: file already exists, symlink '${n}'`);this.ensureParentDirs(r),this.setMemoryEntry(r,{type:"symlink",target:t,mode:511,mtime:new Date}),this.deleted.delete(r)}async link(t,n){Q(t,"link"),Q(n,"link"),this.assertWritable(`link '${n}'`);let r=z(t),s=z(n);if(!await this.existsInOverlay(r))throw new Error(`ENOENT: no such file or directory, link '${t}'`);let o=await this.stat(r);if(!o.isFile)throw new Error(`EPERM: operation not permitted, link '${t}'`);if(await this.existsInOverlay(s))throw new Error(`EEXIST: file already exists, link '${n}'`);let l=await this.readFileBuffer(r);this.ensureParentDirs(s),this.setMemoryEntry(s,{type:"file",content:l,mode:o.mode,mtime:new Date,identity:o.identity??`overlay:${this.nextMemoryIdentity++}`}),this.deleted.delete(s)}async readlink(t){Q(t,"readlink");let n=z(t);if(this.deleted.has(n))throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);let r=this.memory.get(n);if(r){if(r.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);return r.target}let s=this.resolveRealPathParent_(this.toRealPath(n));if(!s)throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);try{let i=await pe.promises.readlink(s);if(!Re.isAbsolute(i)){let o=Re.resolve(Re.dirname(s),i),a;try{a=pe.realpathSync(o)}catch{a=o}if(!$r(a,this.canonicalRoot))return Re.basename(i)}return this.realTargetToVirtual(n,i)}catch(i){if(i.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);if(i.code==="EINVAL")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);this.sanitizeError(i,t,"readlink")}}async realpath(t){Q(t,"realpath");let n=z(t),r=new Set,s=async a=>{let l=a==="/"?[]:a.slice(1).split("/"),u="";for(let c of l){if(u=`${u}/${c}`,r.has(u))throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(this.deleted.has(u))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);let f=this.memory.get(u),d=0,p=40;for(;f&&f.type==="symlink"&&d<p;){if(r.add(u),u=this.resolveSymlink(u,f.target),d++,r.has(u))throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(this.deleted.has(u))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);f=this.memory.get(u)}if(d>=p)throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(!f){let h=this.toRealPath(u),m=this.resolveRealPath_(h);if(m)try{if((await pe.promises.lstat(m)).isSymbolicLink()){if(!this.allowSymlinks)throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);let S=await pe.promises.readlink(m),y=this.realTargetToVirtual(u,S);return r.add(u),u=this.resolveSymlink(u,y),s(u)}}catch(E){if(E.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);this.sanitizeError(E,t,"realpath")}else if(!this.allowSymlinks){let E=this.resolveRealPathParent_(h);if(E)try{if((await pe.promises.lstat(E)).isSymbolicLink())throw new Error(`ENOENT: no such file or directory, realpath '${t}'`)}catch(S){if(S.message?.includes("ENOENT")||S.message?.includes("ELOOP"))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);this.sanitizeError(S,t,"realpath")}}}}return u||"/"},i=await s(n);if(!await this.existsInOverlay(i))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);return i}async utimes(t,n,r){Q(t,"utimes"),this.assertWritable(`utimes '${t}'`);let s=z(t);if(!await this.existsInOverlay(s))throw new Error(`ENOENT: no such file or directory, utimes '${t}'`);let o=this.memory.get(s);if(o){o.mtime=r;return}let a=await this.stat(s);if(a.isFile){let l=await this.readFileBuffer(s);this.setMemoryEntry(s,{type:"file",content:l,mode:a.mode,mtime:r})}else a.isDirectory&&this.setMemoryEntry(s,{type:"directory",mode:a.mode,mtime:r})}};function _f(){console.log(`just-bash - A secure bash environment for AI agents
804
+ `;try{a.writeFileSync(`/bin/${t.name}`,l)}catch{}try{a.writeFileSync(`/usr/bin/${t.name}`,l)}catch{}}}logResult(t){return this.logger&&(t.stdout&&this.logger.debug("stdout",{output:t.stdout}),t.stderr&&this.logger.info("stderr",{output:t.stderr}),this.logger.info("exit",{exitCode:t.exitCode})),t.stdout=_f(t.stdout),t.stderr=_f(t.stderr),t}async exec(t,n){let r=new Ir(this.limits,n?.signal),s;try{s=await this.execInScope(t,n,r,0,n?.signal,!1,!1)}catch(o){try{await r.close()}catch{}throw o}let i=s;try{await r.close()}catch{i={...s,stderr:`${s.stderr}bash: execution cleanup failed
805
+ `,exitCode:126}}return t.trim()?this.logResult(i):i}async execInScope(t,n,r,s,i,o=!1,a=!0,l){let u=d=>a?this.logResult(d):d,c=Rr(i,n?.signal),f=n?{...n,signal:c.signal}:{signal:c.signal};try{if(r.assertExecDepth(s),la(t,this.limits.maxSourceBytes),!t.trim())return{stdout:"",stderr:"",exitCode:0,env:Qe(this.state.env,f.env)};this.logger?.info("exec",{command:t});let d=f.cwd??this.state.cwd,p,h=d;if(f.cwd)if(f.env&&"PWD"in f.env)p=f.env.PWD;else if(f.env&&!("PWD"in f.env))try{p=await this.fs.realpath(d),h=p}catch{p=d}else p=d;let m=f.replaceEnv||f.newShell,y=m?new Map:new Map((l??this.state).env);if(f.env)for(let[$,I]of Object.entries(f.env))y.set($,I);p!==void 0&&y.set("PWD",p);let b=!l||f.newShell,w=m&&b?new Set:l?new Set([...l.exportedVars??[],...l.tempExportedVars??[]]):new Set(this.state.exportedVars);if(b){for(let $ of Object.keys(f.env??{}))/^[a-zA-Z_][a-zA-Z0-9_]*$/.test($)&&w.add($);p!==void 0&&w.add("PWD")}if(f.newShell){y.has("PATH")||y.set("PATH",Df);for(let[$,I]of If)y.has($)||y.set($,I);y.set("IFS",`
806
+ `),y.set("OPTIND","1"),y.set("SHELLOPTS",Lr(this.state.options)),y.set("BASHOPTS",Tr(this.state.shoptOptions))}let E=l&&!f.newShell?l:this.state,S={...this.state,env:y,exportedVars:w,arrays:m?new Map:nt(this.state.arrays),cwd:h,previousDir:f.env?.OLDPWD??(m?"":this.state.previousDir),functions:new Map(this.state.functions),localScopes:[...this.state.localScopes],options:{...this.state.options},shoptOptions:{...E.shoptOptions},readonlyVars:new Set(E.readonlyVars),hashTable:new Map(E.hashTable),groupStdin:Hm(f.stdin,f.stdinKind,this.limits.maxInputBytes,this.limits.maxStringLength,r,o),signal:f.signal,extraArgs:f.args},v=t;f.rawScript||(v=Of(t));let A=this.defenseInDepthConfig?_e.getInstance(this.defenseInDepthConfig):null,x=A?.activate();try{let $=async()=>{let I=ft(v,{maxHeredocSize:this.limits.maxHeredocSize}),P;if(this.transformPlugins.length>0){let k=Object.create(null);for(let M of this.transformPlugins){let z=M.transform({ast:I,metadata:k});I=z.ast,z.metadata&&(k=qs(k,z.metadata))}P=k}let N={fs:this.fs,commands:this.commands,limits:this.limits,executionScope:r,exec:(k,M,z=!1)=>this.execInScope(k,M,r,s+1,f.signal,z,!0,S),fetch:this.secureFetch,sleep:this.sleepFn,trace:this.traceFn,coverage:this.coverageWriter,requireDefenseContext:A?.isEnabled()===!0,jsBootstrapCode:this.jsBootstrapCode,invokeTool:this.invokeToolFn},B=await new vr(N,S).executeScript(I);return P&&(B.metadata=P),u(B)};return x?await x.run($):await $()}catch($){if($ instanceof U)return u({stdout:$.stdout,stderr:$.stderr,exitCode:$.exitCode,internalOutputAccounting:$.internalOutputAccounting,env:Qe(this.state.env,f.env)});if($ instanceof et)return u({stdout:$.stdout,stderr:$.stderr,exitCode:$.exitCode,env:Qe(this.state.env,f.env)});if($ instanceof oe)return u({stdout:$.stdout,stderr:$.stderr,exitCode:1,env:Qe(this.state.env,f.env)});if($ instanceof We)return u({stdout:$.stdout,stderr:$.stderr,exitCode:124,env:Qe(this.state.env,f.env)});if($ instanceof C)return u({stdout:$.stdout,stderr:Ve($.stderr),exitCode:C.EXIT_CODE,internalOutputAccounting:$.internalOutputAccounting,env:Qe(this.state.env,f.env)});if($ instanceof vn)return u({stdout:"",stderr:`bash: security violation: ${Ve($.message)}
807
+ `,exitCode:1,env:Qe(this.state.env,f.env)});if($.name==="ParseException")return u({stdout:"",stderr:`bash: syntax error: ${Ve($.message)}
808
+ `,exitCode:2,env:Qe(this.state.env,f.env)});if($ instanceof Ke)return u({stdout:"",stderr:`bash: ${Ve($.message)}
809
+ `,exitCode:2,env:Qe(this.state.env,f.env)});if($ instanceof RangeError)return u({stdout:"",stderr:`bash: ${Ve($.message)}
810
+ `,exitCode:1,env:Qe(this.state.env,f.env)});throw $}finally{x?.deactivate()}}catch(d){if(d instanceof We)return u({stdout:d.stdout,stderr:d.stderr,exitCode:124,env:Qe(this.state.env,f.env)});if(d instanceof C)return u({stdout:d.stdout,stderr:Ve(d.stderr),exitCode:C.EXIT_CODE,internalOutputAccounting:d.internalOutputAccounting,env:Qe(this.state.env,f.env)});throw d}finally{c.cleanup()}}async readFile(t){return this.fs.readFile(this.fs.resolvePath(this.state.cwd,t))}async writeFile(t,n){return this.fs.writeFile(this.fs.resolvePath(this.state.cwd,t),n)}getCwd(){return this.state.cwd}getEnv(){return Mt(this.state.env)}registerTransformPlugin(t){this.transformPlugins.push(t)}transform(t){la(t,this.limits.maxSourceBytes);let n=Of(t),r=ft(n,{maxHeredocSize:this.limits.maxHeredocSize}),s=Object.create(null);for(let i of this.transformPlugins){let o=i.transform({ast:r,metadata:s});r=o.ast,o.metadata&&(s=qs(s,o.metadata))}return{script:gl(r),ast:r,metadata:s}}};function jm(e,t){let n=t;for(let r=0;r<e.length;r++){let s=e[r];if(n==="single")s==="'"&&(n="none");else if(n==="double")s==="\\"?r++:s==='"'&&(n="none");else if(s==="'")n="single";else if(s==='"')n="double";else if(s==="\\")r++;else if(s==="#"&&(r===0||/\s/.test(e[r-1])))break}return n}function Of(e){let t=e.split(`
811
+ `),n=[],r=[],s="none";for(let i=0;i<t.length;i++){let o=t[i];if(r.length>0){let c=r[r.length-1];if((c.stripTabs?o.replace(/^\t+/,""):o)===c.delimiter){n.push(o.trimStart()),r.pop();continue}n.push(o);continue}let a=s,l=a==="none"?o.trimStart():o;if(n.push(l),s=jm(o,a),a!=="none")continue;let u=/<<(-?)\s*(['"]?)([\w-]+)\2/g;for(let c of l.matchAll(u)){let f=c[1]==="-",d=c[3];r.push({delimiter:d,stripTabs:f})}}return n.join(`
812
+ `)}var Gm=new TextDecoder("utf-8",{fatal:!0});function _f(e){if(!e)return e;let t=!1;for(let r=0;r<e.length;r++){let s=e.charCodeAt(r);if(s>255)return e;s>127&&(t=!0)}if(!t)return e;let n=new Uint8Array(e.length);for(let r=0;r<e.length;r++)n[r]=e.charCodeAt(r);try{return Gm.decode(n)}catch{return e}}function Hm(e,t,n,r,s,i){if(e===void 0)return;let o=t==="bytes"?e.length:W(e);if(o>n||o>r)throw new C(`stdin size limit exceeded (${Math.min(n,r)} bytes)`,"string_length");return i||s.consumeInput(o,"stdin"),t==="bytes"?e:un(e)}import*as pe from"node:fs";import*as Re from"node:path";import*as ot from"node:fs";import*as $e from"node:path";function Pr(e,t){let n=/^[A-Za-z]:[\\/]/.test(t)?$e.win32:$e.posix,r=n.relative(t,e);return r===""||r!==".."&&!r.startsWith(`..${n.sep}`)&&!n.isAbsolute(r)}function kr(e,t){try{let n=ot.realpathSync(e);return Pr(n,t)?n:null}catch(n){if(n.code==="ENOENT"){let r=$e.dirname(e);if(r===e)return null;let s=kr(r,t);if(s===null)return null;try{if(ot.lstatSync(e).isSymbolicLink()){let o=ot.readlinkSync(e),a=$e.isAbsolute(o)?o:$e.resolve($e.dirname(e),o),l=kr(a,t);return l===null?null:l}}catch{}return $e.join(s,$e.basename(e))}return null}}function Lf(e,t,n){let r=kr(e,n);if(r===null)return null;let s=$e.resolve(e),i=s.slice(t.length),o=r.slice(n.length);if(i!==o)return null;try{if(ot.lstatSync(s).isSymbolicLink())return null}catch{}return r}function Tf(e,t){if(!ot.existsSync(e))throw new Error(`${t} root does not exist`);if(!ot.statSync(e).isDirectory())throw new Error(`${t} root is not a directory`)}function Ff(e,t){if(!$e.isAbsolute(e))return{withinRoot:!0,relativePath:e};let n;try{n=ot.realpathSync(e)}catch{n=$e.resolve(e)}return Pr(n,t)?{withinRoot:!0,relativePath:n.slice(t.length).replace(/\\/g,"/")||"/"}:{withinRoot:!1,safeName:$e.basename(e)}}function Mf(e,t,n,r){let s=e;if(s.path===void 0){for(let o of r)if(s.message?.includes(o))throw e}let i=s.code||"EIO";throw new Error(`${i}: ${n} '${t}'`)}var Zm=["ELOOP","EFBIG","EPERM"],Qm="/home/user/project",Kn=class{root;canonicalRoot;mountPoint;readOnly;maxFileReadSize;maxMemoryBytes;allowSymlinks;memory=new Map;deleted=new Set;nextMemoryIdentity=1;retainedMemoryBytes=0;memoryEntryBytes(t){if(!t||t.type!=="file")return 0;let n=t.content.byteLength;for(let r of t.appendChunks??[])n+=r.byteLength;return n}assertMemoryCapacity(t,n=0){if(!Number.isSafeInteger(t)||t<0||t>this.maxMemoryBytes-this.retainedMemoryBytes+n)throw new Error(`ENOSPC: overlay memory byte limit exceeded (${this.maxMemoryBytes} bytes)`)}setMemoryEntry(t,n){let r=this.memoryEntryBytes(this.memory.get(t)),s=this.memoryEntryBytes(n);this.assertMemoryCapacity(s,r),this.memory.set(t,n),this.retainedMemoryBytes+=s-r}deleteMemoryEntry(t){let n=this.memory.get(t);n&&(this.retainedMemoryBytes-=this.memoryEntryBytes(n),this.memory.delete(t))}identityFor(t){return t.type==="symlink"?"":(t.identity||(t.identity=`overlay:${this.nextMemoryIdentity++}`),t.identity)}constructor(t){this.root=Re.resolve(t.root);let n=t.mountPoint??Qm;if(this.mountPoint=n==="/"?"/":n.replace(/\/+$/,""),!this.mountPoint.startsWith("/"))throw new Error(`Mount point must be an absolute path: ${n}`);if(this.readOnly=t.readOnly??!1,this.maxFileReadSize=t.maxFileReadSize??10485760,this.maxMemoryBytes=t.maxMemoryBytes??1024*1024*1024,!Number.isSafeInteger(this.maxMemoryBytes)||this.maxMemoryBytes<0)throw new Error("OverlayFs: invalid maxMemoryBytes");this.allowSymlinks=t.allowSymlinks??!1,Tf(this.root,"OverlayFs"),this.canonicalRoot=pe.realpathSync(this.root),this.createMountPointDirs()}assertWritable(t){if(this.readOnly)throw new Error(`EROFS: read-only file system, ${t}`)}createMountPointDirs(){let t=this.mountPoint.split("/").filter(Boolean),n="";for(let r of t)n+=`/${r}`,this.memory.has(n)||this.setMemoryEntry(n,{type:"directory",mode:493,mtime:new Date});this.memory.has("/")||this.setMemoryEntry("/",{type:"directory",mode:493,mtime:new Date})}getMountPoint(){return this.mountPoint}mkdirSync(t,n){let s=q(t).split("/").filter(Boolean),i="";for(let o of s)i+=`/${o}`,this.memory.has(i)||this.setMemoryEntry(i,{type:"directory",mode:493,mtime:new Date})}writeFileSync(t,n){let r=q(t),s=this.getDirname(r);s!=="/"&&this.mkdirSync(s);let i=n instanceof Uint8Array?n:new TextEncoder().encode(n);this.setMemoryEntry(r,{type:"file",content:i,mode:420,mtime:new Date})}getDirname(t){let n=t.lastIndexOf("/");return n===0?"/":t.slice(0,n)}getRelativeToMount(t){return this.mountPoint==="/"?t:t===this.mountPoint?"/":t.startsWith(`${this.mountPoint}/`)?t.slice(this.mountPoint.length):null}toRealPath(t){let n=q(t),r=this.getRelativeToMount(n);if(r===null)return null;let s=Re.join(this.root,r),i=Re.resolve(s);return Pr(i,this.root)?i:null}resolveRealPath_(t){return t?this.allowSymlinks?kr(t,this.canonicalRoot):Lf(t,this.root,this.canonicalRoot):null}resolveRealPathParent_(t){if(!t)return null;let n=Re.dirname(t),r=this.resolveRealPath_(n);return r===null?null:Re.join(r,Re.basename(t))}sanitizeError(t,n,r){Mf(t,n,r,Zm)}ensureParentDirs(t){let n=ct(t);n!=="/"&&(this.memory.has(n)||(this.ensureParentDirs(n),this.setMemoryEntry(n,{type:"directory",mode:493,mtime:new Date})),this.deleted.delete(n))}async existsInOverlay(t){let n=q(t);if(this.deleted.has(n))return!1;if(this.memory.has(n))return!0;let r=this.resolveRealPathParent_(this.toRealPath(n));if(!r)return!1;try{return await pe.promises.lstat(r),!0}catch{return!1}}async readFile(t,n){let r=await this.readFileBuffer(t),s=Wt(n);return Rn(r,s)}async readFileBytes(t){let n=await this.readFileBuffer(t);return Rn(n,"binary")}async readFileBuffer(t,n=new Set){Q(t,"open");let r=q(t);if(n.has(r))throw new Error(`ELOOP: too many levels of symbolic links, open '${t}'`);if(n.add(r),this.deleted.has(r))throw new Error(`ENOENT: no such file or directory, open '${t}'`);let s=this.memory.get(r);if(s){if(s.type==="symlink"){let u=this.resolveSymlink(r,s.target);return this.readFileBuffer(u,n)}if(s.type!=="file")throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);if(!s.appendChunks||s.appendChunks.length===0)return s.content;let o=s.appendChunks.reduce((u,c)=>u+c.byteLength,s.content.byteLength);if(!Number.isSafeInteger(o))throw new Error(`EFBIG: file too large, read '${t}'`);let a=new Uint8Array(o);a.set(s.content);let l=s.content.byteLength;for(let u of s.appendChunks)a.set(u,l),l+=u.byteLength;return s.content=a,s.appendChunks=void 0,a}let i=this.resolveRealPath_(this.toRealPath(r));if(!i)throw new Error(`ENOENT: no such file or directory, open '${t}'`);try{let o=await pe.promises.lstat(i);if(o.isSymbolicLink()){if(!this.allowSymlinks)throw new Error(`ENOENT: no such file or directory, open '${t}'`);let u=await pe.promises.readlink(i),c=this.realTargetToVirtual(r,u),f=this.resolveSymlink(r,c);return this.readFileBuffer(f,n)}if(o.isDirectory())throw new Error(`EISDIR: illegal operation on a directory, read '${t}'`);if(this.maxFileReadSize>0&&o.size>this.maxFileReadSize)throw new Error(`EFBIG: file too large, read '${t}' (${o.size} bytes, max ${this.maxFileReadSize})`);let a=this.allowSymlinks?pe.constants.O_RDONLY:pe.constants.O_RDONLY|pe.constants.O_NOFOLLOW,l=await pe.promises.open(i,a);try{let u=await l.readFile();return new Uint8Array(u)}finally{await l.close()}}catch(o){let a=o.code;if(a==="ENOENT")throw new Error(`ENOENT: no such file or directory, open '${t}'`);if(a==="ELOOP")throw new Error(`ENOENT: no such file or directory, open '${t}'`);this.sanitizeError(o,t,"open")}}async writeFile(t,n,r){Q(t,"write"),this.assertWritable(`write '${t}'`);let s=q(t);this.ensureParentDirs(s);let i=Wt(r),o=Nn(n,i);this.setMemoryEntry(s,{type:"file",content:o,mode:420,mtime:new Date}),this.deleted.delete(s)}async appendFile(t,n,r){Q(t,"append"),this.assertWritable(`append '${t}'`);let s=q(t),i=Wt(r),o=Nn(n,i),a=this.memory.get(s);if(a?.type==="file"){this.assertMemoryCapacity(o.byteLength),a.appendChunks||(a.appendChunks=[]),a.appendChunks.push(o),this.retainedMemoryBytes+=o.byteLength,a.mtime=new Date,this.deleted.delete(s);return}let l;try{l=await this.readFileBuffer(s)}catch{l=new Uint8Array(0)}this.ensureParentDirs(s),this.setMemoryEntry(s,{type:"file",content:l,appendChunks:[o],mode:420,mtime:new Date}),this.deleted.delete(s)}async exists(t){return t.includes("\0")?!1:this.existsInOverlay(t)}async stat(t,n=new Set){Q(t,"stat");let r=q(t);if(n.has(r))throw new Error(`ELOOP: too many levels of symbolic links, stat '${t}'`);if(n.add(r),this.deleted.has(r))throw new Error(`ENOENT: no such file or directory, stat '${t}'`);let s=this.memory.get(r);if(s){if(s.type==="symlink"){let a=this.resolveSymlink(r,s.target);return this.stat(a,n)}let o=0;return s.type==="file"&&(o=s.content.length+(s.appendChunks?.reduce((a,l)=>a+l.byteLength,0)??0)),{isFile:s.type==="file",isDirectory:s.type==="directory",isSymbolicLink:!1,mode:s.mode,size:o,mtime:s.mtime,identity:this.identityFor(s)}}let i=this.resolveRealPath_(this.toRealPath(r));if(!i)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);try{let o=await pe.promises.lstat(i);if(o.isSymbolicLink()){if(!this.allowSymlinks)throw new Error(`ENOENT: no such file or directory, stat '${t}'`);let a=await pe.promises.readlink(i),l=this.realTargetToVirtual(r,a),u=this.resolveSymlink(r,l);return this.stat(u,n)}return{isFile:o.isFile(),isDirectory:o.isDirectory(),isSymbolicLink:!1,mode:o.mode,size:o.size,mtime:o.mtime,dev:o.dev,ino:o.ino}}catch(o){if(o.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, stat '${t}'`);this.sanitizeError(o,t,"stat")}}async lstat(t){Q(t,"lstat");let n=q(t);if(this.deleted.has(n))throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);let r=this.memory.get(n);if(r){if(r.type==="symlink")return{isFile:!1,isDirectory:!1,isSymbolicLink:!0,mode:r.mode,size:r.target.length,mtime:r.mtime};let i=0;return r.type==="file"&&(i=r.content.length+(r.appendChunks?.reduce((o,a)=>o+a.byteLength,0)??0)),{isFile:r.type==="file",isDirectory:r.type==="directory",isSymbolicLink:!1,mode:r.mode,size:i,mtime:r.mtime,identity:this.identityFor(r)}}let s=this.resolveRealPathParent_(this.toRealPath(n));if(!s)throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);try{let i=await pe.promises.lstat(s);return{isFile:i.isFile(),isDirectory:i.isDirectory(),isSymbolicLink:i.isSymbolicLink(),mode:i.mode,size:i.size,mtime:i.mtime,dev:i.dev,ino:i.ino}}catch(i){if(i.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, lstat '${t}'`);this.sanitizeError(i,t,"lstat")}}resolveSymlink(t,n){return Cn(t,n)}realTargetToVirtual(t,n){let r=Ff(n,this.canonicalRoot);if(r.withinRoot){if(!Re.isAbsolute(n))return n;let s=r.relativePath;return this.mountPoint==="/"?s:`${this.mountPoint}${s}`}return r.safeName}async mkdir(t,n){Q(t,"mkdir"),this.assertWritable(`mkdir '${t}'`);let r=q(t);if(await this.existsInOverlay(r)){if(!n?.recursive)throw new Error(`EEXIST: file already exists, mkdir '${t}'`);return}let i=ct(r);if(i!=="/"&&!await this.existsInOverlay(i))if(n?.recursive)await this.mkdir(i,{recursive:!0});else throw new Error(`ENOENT: no such file or directory, mkdir '${t}'`);this.setMemoryEntry(r,{type:"directory",mode:493,mtime:new Date}),this.deleted.delete(r)}async readdirCore(t,n){if(this.deleted.has(n))throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);let r=new Map,s=new Set,i=n==="/"?"/":`${n}/`;for(let a of this.deleted)if(a.startsWith(i)){let l=a.slice(i.length),u=l.split("/")[0];u&&!l.includes("/",u.length)&&s.add(u)}for(let[a,l]of this.memory)if(a!==n&&a.startsWith(i)){let u=a.slice(i.length),c=u.split("/")[0];c&&!s.has(c)&&!u.includes("/",1)&&r.set(c,{name:c,isFile:l.type==="file",isDirectory:l.type==="directory",isSymbolicLink:l.type==="symlink"})}let o=this.resolveRealPath_(this.toRealPath(n));if(o)try{if(!this.allowSymlinks&&(await pe.promises.lstat(o)).isSymbolicLink()){if(!this.memory.has(n))throw new Error(`ENOENT: no such file or directory, scandir '${t}'`);return r}let a=await pe.promises.readdir(o,{withFileTypes:!0});for(let l of a)!s.has(l.name)&&!r.has(l.name)&&r.set(l.name,{name:l.name,isFile:l.isFile(),isDirectory:l.isDirectory(),isSymbolicLink:l.isSymbolicLink()})}catch(a){if(a.code==="ENOENT"){if(!this.memory.has(n))throw new Error(`ENOENT: no such file or directory, scandir '${t}'`)}else a.code!=="ENOTDIR"&&this.sanitizeError(a,t,"scandir")}return r}async resolveForReaddir(t,n=!1){let r=q(t),s=new Set,i=n,o=this.memory.get(r);for(;o&&o.type==="symlink";){if(s.has(r))throw new Error(`ELOOP: too many levels of symbolic links, scandir '${t}'`);s.add(r),i=!0,r=this.resolveSymlink(r,o.target),o=this.memory.get(r)}if(o)return{normalized:r,outsideOverlay:!1};if(this.getRelativeToMount(r)===null)return{normalized:r,outsideOverlay:!0};let l=this.resolveRealPath_(this.toRealPath(r));if(!l)return{normalized:r,outsideOverlay:!0};try{if((await pe.promises.lstat(l)).isSymbolicLink()){if(!this.allowSymlinks)return{normalized:r,outsideOverlay:!0};let c=await pe.promises.readlink(l),f=this.realTargetToVirtual(r,c),d=this.resolveSymlink(r,f);return this.resolveForReaddir(d,!0)}return{normalized:r,outsideOverlay:!1}}catch{return i?{normalized:r,outsideOverlay:!0}:{normalized:r,outsideOverlay:!1}}}async createExclusive(t,n){let r=n.directory?"mkdir":"open";Q(t,r),this.assertWritable(`${r} '${t}'`);let s=q(t);if(await this.existsInOverlay(s))throw new Error(`EEXIST: file already exists, ${r} '${t}'`);let i=ct(s),o=s;if(i!=="/"){let a;try{a=await this.realpath(i)}catch{throw new Error(`ENOENT: no such file or directory, ${r} '${t}'`)}let l=await this.stat(a).catch(()=>null);if(!l)throw new Error(`ENOENT: no such file or directory, ${r} '${t}'`);if(!l.isDirectory)throw new Error(`ENOTDIR: not a directory, ${r} '${t}'`);if(o=tt(a,s.slice(s.lastIndexOf("/")+1)),o!==s&&await this.existsInOverlay(o))throw new Error(`EEXIST: file already exists, ${r} '${t}'`)}if(this.memory.has(o))throw new Error(`EEXIST: file already exists, ${r} '${t}'`);this.setMemoryEntry(o,n.directory?{type:"directory",mode:n.mode,mtime:new Date}:{type:"file",content:new Uint8Array(0),mode:n.mode,mtime:new Date}),this.deleted.delete(o)}async readdir(t){Q(t,"scandir");let{normalized:n,outsideOverlay:r}=await this.resolveForReaddir(t);if(r)return[];let s=await this.readdirCore(t,n);return Array.from(s.keys()).sort((i,o)=>i<o?-1:i>o?1:0)}async readdirWithFileTypes(t){Q(t,"scandir");let{normalized:n,outsideOverlay:r}=await this.resolveForReaddir(t);if(r)return[];let s=await this.readdirCore(t,n);return Array.from(s.values()).sort((i,o)=>i.name<o.name?-1:i.name>o.name?1:0)}async rm(t,n){Q(t,"rm"),this.assertWritable(`rm '${t}'`);let r=q(t);if(!await this.existsInOverlay(r)){if(n?.force)return;throw new Error(`ENOENT: no such file or directory, rm '${t}'`)}try{if((await this.stat(r)).isDirectory){let o=await this.readdir(r);if(o.length>0){if(!n?.recursive)throw new Error(`ENOTEMPTY: directory not empty, rm '${t}'`);for(let a of o){let l=r==="/"?`/${a}`:`${r}/${a}`;await this.rm(l,n)}}}}catch(i){if(i instanceof Error&&(i.message.includes("ENOTEMPTY")||i.message.includes("EISDIR")))throw i}this.deleteMemoryEntry(r),this.existsOnRealFs(r)&&this.deleted.add(r)}existsOnRealFs(t){let n=this.toRealPath(t),r=this.resolveRealPathParent_(n);if(!r)return!1;try{return pe.lstatSync(r),!0}catch{return!1}}async cp(t,n,r){Q(t,"cp"),Q(n,"cp"),this.assertWritable(`cp '${n}'`);let s=q(t),i=q(n);if(!await this.existsInOverlay(s))throw new Error(`ENOENT: no such file or directory, cp '${t}'`);let a=await this.stat(s);if(a.isFile){let l=await this.readFileBuffer(s);await this.writeFile(i,l)}else if(a.isDirectory){if(!r?.recursive)throw new Error(`EISDIR: is a directory, cp '${t}'`);if(Dt(s,i))throw new Error(`EINVAL: cannot copy '${t}' into itself, '${n}'`);await this.mkdir(i,{recursive:!0});let l=await this.readdir(s);for(let u of l){let c=s==="/"?`/${u}`:`${s}/${u}`,f=i==="/"?`/${u}`:`${i}/${u}`;await this.cp(c,f,r)}}}async mv(t,n){this.assertWritable(`mv '${n}'`),await this.cp(t,n,{recursive:!0}),await this.rm(t,{recursive:!0})}resolvePath(t,n){return Pn(t,n)}getAllPaths(){let t=new Set(this.memory.keys());for(let n of this.deleted)t.delete(n);return this.scanRealFs("/",t),Array.from(t)}scanRealFs(t,n){if(this.deleted.has(t))return;let r=this.resolveRealPath_(this.toRealPath(t));if(r)try{let s=pe.readdirSync(r);for(let i of s){let o=t==="/"?`/${i}`:`${t}/${i}`;if(this.deleted.has(o))continue;n.add(o);let a=Re.join(r,i);pe.lstatSync(a).isDirectory()&&this.scanRealFs(o,n)}}catch{}}async chmod(t,n){Q(t,"chmod"),this.assertWritable(`chmod '${t}'`);let r=q(t);if(!await this.existsInOverlay(r))throw new Error(`ENOENT: no such file or directory, chmod '${t}'`);let i=this.memory.get(r);if(i){i.mode=n;return}let o=await this.stat(r);if(o.isFile){let a=await this.readFileBuffer(r);this.setMemoryEntry(r,{type:"file",content:a,mode:n,mtime:new Date})}else o.isDirectory&&this.setMemoryEntry(r,{type:"directory",mode:n,mtime:new Date})}async symlink(t,n){if(!this.allowSymlinks)throw new Error(`EPERM: operation not permitted, symlink '${n}'`);Q(n,"symlink"),this.assertWritable(`symlink '${n}'`);let r=q(n);if(await this.existsInOverlay(r))throw new Error(`EEXIST: file already exists, symlink '${n}'`);this.ensureParentDirs(r),this.setMemoryEntry(r,{type:"symlink",target:t,mode:511,mtime:new Date}),this.deleted.delete(r)}async link(t,n){Q(t,"link"),Q(n,"link"),this.assertWritable(`link '${n}'`);let r=q(t),s=q(n);if(!await this.existsInOverlay(r))throw new Error(`ENOENT: no such file or directory, link '${t}'`);let o=await this.stat(r);if(!o.isFile)throw new Error(`EPERM: operation not permitted, link '${t}'`);if(await this.existsInOverlay(s))throw new Error(`EEXIST: file already exists, link '${n}'`);let l=await this.readFileBuffer(r);this.ensureParentDirs(s),this.setMemoryEntry(s,{type:"file",content:l,mode:o.mode,mtime:new Date,identity:o.identity??`overlay:${this.nextMemoryIdentity++}`}),this.deleted.delete(s)}async readlink(t){Q(t,"readlink");let n=q(t);if(this.deleted.has(n))throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);let r=this.memory.get(n);if(r){if(r.type!=="symlink")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);return r.target}let s=this.resolveRealPathParent_(this.toRealPath(n));if(!s)throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);try{let i=await pe.promises.readlink(s);if(!Re.isAbsolute(i)){let o=Re.resolve(Re.dirname(s),i),a;try{a=pe.realpathSync(o)}catch{a=o}if(!Pr(a,this.canonicalRoot))return Re.basename(i)}return this.realTargetToVirtual(n,i)}catch(i){if(i.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, readlink '${t}'`);if(i.code==="EINVAL")throw new Error(`EINVAL: invalid argument, readlink '${t}'`);this.sanitizeError(i,t,"readlink")}}async realpath(t){Q(t,"realpath");let n=q(t),r=new Set,s=async a=>{let l=a==="/"?[]:a.slice(1).split("/"),u="";for(let c of l){if(u=`${u}/${c}`,r.has(u))throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(this.deleted.has(u))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);let f=this.memory.get(u),d=0,p=40;for(;f&&f.type==="symlink"&&d<p;){if(r.add(u),u=this.resolveSymlink(u,f.target),d++,r.has(u))throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(this.deleted.has(u))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);f=this.memory.get(u)}if(d>=p)throw new Error(`ELOOP: too many levels of symbolic links, realpath '${t}'`);if(!f){let h=this.toRealPath(u),m=this.resolveRealPath_(h);if(m)try{if((await pe.promises.lstat(m)).isSymbolicLink()){if(!this.allowSymlinks)throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);let b=await pe.promises.readlink(m),w=this.realTargetToVirtual(u,b);return r.add(u),u=this.resolveSymlink(u,w),s(u)}}catch(y){if(y.code==="ENOENT")throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);this.sanitizeError(y,t,"realpath")}else if(!this.allowSymlinks){let y=this.resolveRealPathParent_(h);if(y)try{if((await pe.promises.lstat(y)).isSymbolicLink())throw new Error(`ENOENT: no such file or directory, realpath '${t}'`)}catch(b){if(b.message?.includes("ENOENT")||b.message?.includes("ELOOP"))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);this.sanitizeError(b,t,"realpath")}}}}return u||"/"},i=await s(n);if(!await this.existsInOverlay(i))throw new Error(`ENOENT: no such file or directory, realpath '${t}'`);return i}async utimes(t,n,r){Q(t,"utimes"),this.assertWritable(`utimes '${t}'`);let s=q(t);if(!await this.existsInOverlay(s))throw new Error(`ENOENT: no such file or directory, utimes '${t}'`);let o=this.memory.get(s);if(o){o.mtime=r;return}let a=await this.stat(s);if(a.isFile){let l=await this.readFileBuffer(s);this.setMemoryEntry(s,{type:"file",content:l,mode:a.mode,mtime:r})}else a.isDirectory&&this.setMemoryEntry(s,{type:"directory",mode:a.mode,mtime:r})}};function Wf(){console.log(`just-bash - A secure bash environment for AI agents
811
813
 
812
814
  Usage:
813
815
  just-bash [options] [script-file] [root]
@@ -858,5 +860,5 @@ Examples:
858
860
 
859
861
  # Allow write operations (writes stay in memory)
860
862
  just-bash -c 'echo test > /tmp/file.txt && cat /tmp/file.txt' --allow-write
861
- `)}function qm(){console.log("just-bash 1.0.0")}function Um(e){let t={root:process.cwd(),cwd:"/",cwdOverridden:!1,errexit:!1,allowWrite:!1,python:!1,javascript:!1,json:!1,help:!1,version:!1},n=0,r=[],s=!1;for(;n<e.length;){let o=e[n];if(o==="--"){r.push(...e.slice(n+1));break}else if(o==="-h"||o==="--help")t.help=!0,n++;else if(o==="-v"||o==="--version")t.version=!0,n++;else if(o==="-c")n+1>=e.length&&(console.error("Error: -c requires a script argument"),process.exit(1)),t.script=e[n+1],n+=2;else if(o==="-e"||o==="--errexit")t.errexit=!0,n++;else if(o==="--root")n+1>=e.length&&(console.error("Error: --root requires a path argument"),process.exit(1)),t.root=Of(e[n+1]),s=!0,n+=2;else if(o==="--cwd")n+1>=e.length&&(console.error("Error: --cwd requires a path argument"),process.exit(1)),t.cwd=e[n+1],t.cwdOverridden=!0,n+=2;else if(o==="--json")t.json=!0,n++;else if(o==="--allow-write")t.allowWrite=!0,n++;else if(o==="--python")t.python=!0,n++;else if(o==="--javascript")t.javascript=!0,n++;else if(o.startsWith("-"))if(o.length>2&&!o.startsWith("--")){let a=o.slice(1);for(let l of a)if(l==="e")t.errexit=!0;else if(l==="h")t.help=!0;else if(l==="v")t.version=!0;else if(l==="c"){n+1>=e.length&&(console.error("Error: -c requires a script argument"),process.exit(1)),t.script=e[n+1],n++;break}else console.error(`Error: Unknown option: -${l}`),process.exit(1);n++}else console.error(`Error: Unknown option: ${o}`),process.exit(1);else r.push(o),n++}let i=o=>{console.error(`Error: ${o}`),process.exit(1)};if(t.script&&r.length>0&&i("script file cannot be combined with -c"),r.length>2&&i("unexpected extra positional argument"),r.length>=1&&(t.scriptFile=r[0]),r.length===2){let o=Of(r[1]);s&&o!==t.root&&i("conflicting positional root and --root"),t.root=o}return t}function jm(e){if(!e||e==="/")return"/";let t=e.endsWith("/")&&e!=="/"?e.slice(0,-1):e;t.startsWith("/")||(t=`/${t}`);let n=t.split("/").filter(s=>s&&s!=="."),r=[];for(let s of n)s===".."?r.pop():r.push(s);return`/${r.join("/")}`||"/"}async function Gm(){let e=[];for await(let t of process.stdin)e.push(t);return Buffer.concat(e).toString("utf-8")}async function Hm(){let e=process.argv.slice(2),t=Um(e);t.help&&(_f(),process.exit(0)),t.version&&(qm(),process.exit(0));let n;if(t.script)n=t.script;else if(t.scriptFile){let a=new Qn({root:t.root}),l=a.getMountPoint();try{let u=t.scriptFile.startsWith("/")?t.scriptFile:`${l}/${t.scriptFile}`;n=await a.readFile(u,"utf-8")}catch(u){console.error(`Error: Cannot read script file: ${t.scriptFile}`),console.error(Ve(u instanceof Error?u.message:String(u))),process.exit(1)}}else process.stdin.isTTY?(_f(),process.exit(1)):n=await Gm();n.trim()||(t.json&&console.log(JSON.stringify({stdout:"",stderr:"",exitCode:0})),process.exit(0));let r=new Qn({root:t.root,readOnly:!t.allowWrite}),s=r.getMountPoint(),i=t.cwdOverridden?jm(t.cwd):s,o=new Fs({fs:r,cwd:i,python:t.python,javascript:t.javascript});t.errexit&&(n=`set -e
862
- ${n}`);try{let a=await o.exec(n);t.json?console.log(JSON.stringify({stdout:a.stdout,stderr:a.stderr,exitCode:a.exitCode})):(a.stdout&&process.stdout.write(a.stdout),a.stderr&&process.stderr.write(a.stderr)),process.exit(a.exitCode)}catch(a){let l=Ve(a instanceof Error?a.message:String(a));t.json?console.log(JSON.stringify({stdout:"",stderr:l,exitCode:1})):console.error(l),process.exit(1)}}Hm().catch(e=>{console.error("Fatal error:",Ve(e instanceof Error?e.message:String(e))),process.exit(1)});
863
+ `)}function Km(){console.log("just-bash 1.0.0")}function Xm(e){let t={root:process.cwd(),cwd:"/",cwdOverridden:!1,errexit:!1,allowWrite:!1,python:!1,javascript:!1,json:!1,help:!1,version:!1},n=0,r=[],s=!1;for(;n<e.length;){let o=e[n];if(o==="--"){r.push(...e.slice(n+1));break}else if(o==="-h"||o==="--help")t.help=!0,n++;else if(o==="-v"||o==="--version")t.version=!0,n++;else if(o==="-c")n+1>=e.length&&(console.error("Error: -c requires a script argument"),process.exit(1)),t.script=e[n+1],n+=2;else if(o==="-e"||o==="--errexit")t.errexit=!0,n++;else if(o==="--root")n+1>=e.length&&(console.error("Error: --root requires a path argument"),process.exit(1)),t.root=Bf(e[n+1]),s=!0,n+=2;else if(o==="--cwd")n+1>=e.length&&(console.error("Error: --cwd requires a path argument"),process.exit(1)),t.cwd=e[n+1],t.cwdOverridden=!0,n+=2;else if(o==="--json")t.json=!0,n++;else if(o==="--allow-write")t.allowWrite=!0,n++;else if(o==="--python")t.python=!0,n++;else if(o==="--javascript")t.javascript=!0,n++;else if(o.startsWith("-"))if(o.length>2&&!o.startsWith("--")){let a=o.slice(1);for(let l of a)if(l==="e")t.errexit=!0;else if(l==="h")t.help=!0;else if(l==="v")t.version=!0;else if(l==="c"){n+1>=e.length&&(console.error("Error: -c requires a script argument"),process.exit(1)),t.script=e[n+1],n++;break}else console.error(`Error: Unknown option: -${l}`),process.exit(1);n++}else console.error(`Error: Unknown option: ${o}`),process.exit(1);else r.push(o),n++}let i=o=>{console.error(`Error: ${o}`),process.exit(1)};if(t.script&&r.length>0&&i("script file cannot be combined with -c"),r.length>2&&i("unexpected extra positional argument"),r.length>=1&&(t.scriptFile=r[0]),r.length===2){let o=Bf(r[1]);s&&o!==t.root&&i("conflicting positional root and --root"),t.root=o}return t}function Ym(e){if(!e||e==="/")return"/";let t=e.endsWith("/")&&e!=="/"?e.slice(0,-1):e;t.startsWith("/")||(t=`/${t}`);let n=t.split("/").filter(s=>s&&s!=="."),r=[];for(let s of n)s===".."?r.pop():r.push(s);return`/${r.join("/")}`||"/"}async function Jm(){let e=[];for await(let t of process.stdin)e.push(t);return Buffer.concat(e).toString("utf-8")}async function ey(){let e=process.argv.slice(2),t=Xm(e);t.help&&(Wf(),process.exit(0)),t.version&&(Km(),process.exit(0));let n;if(t.script)n=t.script;else if(t.scriptFile){let a=new Kn({root:t.root}),l=a.getMountPoint();try{let u=t.scriptFile.startsWith("/")?t.scriptFile:`${l}/${t.scriptFile}`;n=await a.readFile(u,"utf-8")}catch(u){console.error(`Error: Cannot read script file: ${t.scriptFile}`),console.error(Ve(u instanceof Error?u.message:String(u))),process.exit(1)}}else process.stdin.isTTY?(Wf(),process.exit(1)):n=await Jm();n.trim()||(t.json&&console.log(JSON.stringify({stdout:"",stderr:"",exitCode:0})),process.exit(0));let r=new Kn({root:t.root,readOnly:!t.allowWrite}),s=r.getMountPoint(),i=t.cwdOverridden?Ym(t.cwd):s,o=new Vs({fs:r,cwd:i,python:t.python,javascript:t.javascript});t.errexit&&(n=`set -e
864
+ ${n}`);try{let a=await o.exec(n);t.json?console.log(JSON.stringify({stdout:a.stdout,stderr:a.stderr,exitCode:a.exitCode})):(a.stdout&&process.stdout.write(a.stdout),a.stderr&&process.stderr.write(a.stderr)),process.exit(a.exitCode)}catch(a){let l=Ve(a instanceof Error?a.message:String(a));t.json?console.log(JSON.stringify({stdout:"",stderr:l,exitCode:1})):console.error(l),process.exit(1)}}ey().catch(e=>{console.error("Fatal error:",Ve(e instanceof Error?e.message:String(e))),process.exit(1)});